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
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
modifiedReferences module type of
// Lib.reslet x = 1 // Main.resmodule TypeOf: module type of Lib = Lib // Use.reslet e = Main.TypeOf.x
text
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
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.