Repository navigation
Conversation
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.
References modified (from the declaration):
Example:
// Lib.res
let x = 1
module Make = (X: {}) => {
let made = 1
}
// Main.res
include Lib
include Lib.Make({})
// Use.res
let a = Main.x
let d = Main.made
Before (text): line:column, from 0
x in Lib Lib 0:4
made in Lib Lib 2:6
After (text):
x in Lib Lib 0:4, Use 0:13
made in Lib Lib 2:6, Use 1:13
References modified (copies of one member):
Example:
// Lib.res
module MakeMore = (X: {}) => {
type lr = {lf: int}
}
// A.res
include Lib.MakeMore({})
let a = {lf: 1}
// B.res
module M = {
include Lib.MakeMore({})
}
let b = {M.lf: 1}
Before (text): lf in A, line:column, from 0
A 1:9, Lib 1:13
After (text):
A 1:9, Lib 1:13, B 3:11
References modified (module type of):
Example:
// Lib.res
let x = 1
// Main.res
module TypeOf: module type of Lib = Lib
// Use.res
let e = Main.TypeOf.x
Before (text): Main.TypeOf.x in Use, line:column, from 0
Use 0:20, Main 0:4
After (text):
Use 0:20, Lib 0:4
References modified (alias in the implementation):
Example:
// A.res
module N = {
let s = 1
}
module X = N
// A.resi
module N: {
let s: int
}
module X: {
let s: int
}
// Use.res
let u = A.X.s
Before (text): s in A.res, line:column, from 0
A.res 1:6, A.resi 1:6
After (text):
A.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.
Review: 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.
Review: Why does a snapshot of tests-namespaced-references change? It logs
the .cmt files read, and the pass now reads them in another order.
Fixes: #9524
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGgQuXy1xmZbjATZsB
Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Find references from the declaration a member stands for6fb9d6c · cknitt + Claude · Dec 04, 2026, 13:43 UTC
References modified (from the declaration) // Lib.res
let x = 1
module Make = (X: {}) => {
let made = 1
}
// Main.res
include Lib
include Lib.Make({})
// Use.res
let a = Main.x
let d = Main.made
-x in Lib Lib 0:4
-made in Lib Lib 2:6
+x in Lib Lib 0:4, Use 0:13
+made in Lib Lib 2:6, Use 1:13References modified (copies of one member) // Lib.res
module MakeMore = (X: {}) => {
type lr = {lf: int}
}
// A.res
include Lib.MakeMore({})
let a = {lf: 1}
// B.res
module M = {
include Lib.MakeMore({})
}
let b = {M.lf: 1}
-A 1:9, Lib 1:13
+A 1:9, Lib 1:13, B 3:11References modified (module type of) // Lib.res
let x = 1
// Main.res
module TypeOf: module type of Lib = Lib
// Use.res
let e = Main.TypeOf.x
-Use 0:20, Main 0:4
+Use 0:20, Lib 0:4References modified (alias in the implementation) // A.res
module N = {
let s = 1
}
module X = N
// A.resi
module N: {
let s: int
}
module X: {
let s: int
}
// Use.res
let u = A.X.s
-A.res 1:6, A.resi 1:6
+A.res 1:6, A.resi 1:6, A.resi 4:6, Use 0:12Every 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 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 This replaces the walk over families of copies, the recursion across files and its visited set. Review
|
✅ Compiler benchmarksAllocated wordsIn total: 656,879,538 → 656,880,184 (±0.00%). Generated projects: 629,104,946 → 629,104,116 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 8,976,934,188 → 8,976,934,188 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,594,641 → 27,594,641 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 6fb9d6c compared with base 4375d6e in this run. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9525 +/- ##
==========================================
- Coverage 82.67% 82.66% -0.01%
==========================================
Files 469 469
Lines 66553 66599 +46
==========================================
+ Hits 55023 55057 +34
- Misses 11530 11542 +12
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9525 |
Fixes #9524, the follow-up to #9331.
Find References now starts from the declaration a member stands for, then gathers everything that stands for the same declaration in one pass over the project. Before, it walked from the queried member to its copies, but never back. So:
Main.xforinclude Lib.module type of Mconnects toM's members. Before, their uses pointed to a wrong location in the file that usedmodule type of. The module still keeps its own definition, hover and completion.module X = N) connects toN's member.This replaces the walk over families of copies, its recursion across files and its visited set.
Some details for review:
.res/.resipair is read from the same.cmtas the pass, including the incremental one, so stamps agree. Reading the.cmton disk could match a different binding of a file that's being edited.New tests:
IncludeDeclarationsRoot*.res, and alias cases inPathRefsIntf. The other snapshot changes are gains (sibling copies of a field now connect) or order only.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gGgQuXy1xmZbjATZsB