Semantic Diff

#9525 Find references from the declaration a member stands for

1 commit

2796a446117a261c37df1766640dabc473626473..pr-9525

6fb9d6c01 · cknitt + Claude · Dec 04, 2026, 13:43 UTC

Find references from the declaration a member stands for

Why

Find References on a member started from the member and walked to its copies: the copies in its file, the other file of a .res/.resi pair, and the files the copies come from. It never walked the other way, so from a declaration it missed the uses through every module that includes it, and from one copy it missed the uses of another copy of the same member. module type of M registered M's members as declarations of the module it typed, with M's stamps from another compilation, so their uses were not connected to M.

modifiedReferences from the declaration

// Lib.reslet x = 1module Make = (X: {}) => {  let made = 1} // Main.resinclude Libinclude Lib.Make({}) // Use.reslet a = Main.xlet d = Main.made
text
Before line:column, from 0
After
x in Lib Lib 0:4made in Lib Lib 2:6x in Lib Lib 0:4, Use 0:13made in Lib Lib 2:6, Use 1:13

modifiedReferences copies of one member

// Lib.resmodule MakeMore = (X: {}) => {  type lr = {lf: int}} // A.resinclude Lib.MakeMore({})let a = {lf: 1} // B.resmodule M = {  include Lib.MakeMore({})}let b = {M.lf: 1}
text
Before lf in A, line:column, from 0
After
A 1:9, Lib 1:13A 1:9, Lib 1:13, B 3:11

modifiedReferences module type of

// Lib.reslet x = 1 // Main.resmodule TypeOf: module type of Lib = Lib // Use.reslet e = Main.TypeOf.x
text
Before Main.TypeOf.x in Use, line:column, from 0
After
Use 0:20, Main 0:4Use 0:20, Lib 0:4

modifiedReferences alias in the implementation

// A.resmodule N = {  let s = 1}module X = N // A.resimodule N: {  let s: int}module X: {  let s: int} // Use.reslet u = A.X.s
text
Before s in A.res, line:column, from 0
After
A.res 1:6, A.resi 1:6A.res 1:6, A.resi 1:6, A.resi 4:6, Use 0:12

Every member now leads to its root declaration: through its chain of includes, across files, and for a member of an interface, to the same declaration in the implementation, also through a module alias. One pass gathers the references of every member with that root, the uses recorded under their paths, and the uses whose paths resolve to one of them. A member of the other file that is a member of a module type, such as S.s for N.s in module N: S, is shared with every module of that type and only adds its own references, as before.

The pass reads the project and the root's module. For a declaration that is not visible outside its module, it reads only that module.

The members of module type of M, for a module path M, are recorded as copies of M's members, as for include M. The module stays a module of its own for definition, hover and completion.

This replaces the walk over families of copies, the recursion across files and its visited set.

Review

  • Which .cmt is the other file of a pair read from? The one the pass reads: the incremental .cmt when the editor wrote one. Stamps depend on the .cmt, so the root found through the interface matches the members the pass finds. Reading the .cmt on disk instead would match another binding of the edited file by stamp.
  • What does a query cost? On the analysis test project (157 files), best of 9 with both binaries in one directory: a local binding 12–14 ms, an exported member 45–50 ms, both within 1–3 ms of master. The cache of roots holds booleans, not files. Holding the root's file for each same-named member kept every scanned file alive and cost 5–8 ms in garbage collection.
  • Why does a snapshot of tests-namespaced-references change? It logs the .cmt files read, and the pass now reads them in another order.