Skip to content

Commit 6f601b0

Browse files
cknittclaude
andcommitted
Connect nested modules of an applied functor to their declarations
Codex review on #9084: uses of a module path such as `M.Nested` were recorded only under the renamed stamp. They are now also recorded under the original, like value uses. The originals are taken from the functor's result signature: when the argument is a path, the application's signature was already renamed by the compiler and doesn't carry the body's stamps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gLMawVgtmiKy3TMBc3 Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent cdb76c0 commit 6f601b0

4 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎analysis/src/process_cmt.ml‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,15 @@ and for_module ~env (mod_expr : Typedtree.module_expr) module_name =
719719
if Ident.current_time () < renamed_stamp_floor then
720720
Ident.set_current_time renamed_stamp_floor;
721721
let renamed = Subst.modtype Subst.identity mod_expr.mod_type in
722-
record_renamed_stamps env.renamed_stamps mod_expr.mod_type renamed;
722+
(* The functor's result signature has the identifiers of the body's
723+
declarations; the application's has them only when the argument is
724+
not a path, else the compiler already renamed them. *)
725+
let functor_result =
726+
match functor_.mod_type with
727+
| Mty_functor (_, _, result) -> result
728+
| mty -> mty
729+
in
730+
record_renamed_stamps env.renamed_stamps functor_result renamed;
723731
for_type_module ~name:module_name ~env renamed
724732
| Tmod_unpack (_expr, module_type) ->
725733
let env = env |> Env.add_module ~name:module_name in

‎analysis/src/process_extra.ml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ let add_for_path_parent ~env ~extra path loc =
176176
add_file_reference ~extra module_name loc;
177177
TopLevelModule module_name
178178
| Stamp stamp ->
179-
add_reference ~extra stamp loc;
179+
add_reference_with_original ~env ~extra stamp loc;
180180
LModule (LocalReference (stamp, Module))
181181
| NotFound -> LModule NotFound
182182
| Global (module_name, path) ->
@@ -185,7 +185,7 @@ let add_for_path_parent ~env ~extra path loc =
185185
| Exported (env, name) -> (
186186
match Exported.find env.exported Exported.Module name with
187187
| Some stamp ->
188-
add_reference ~extra stamp loc;
188+
add_reference_with_original ~env ~extra stamp loc;
189189
LModule (LocalReference (stamp, Module))
190190
| None -> LModule NotFound)
191191
in

‎tests/analysis_tests/tests/src/AppliedFunctor.res‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,20 @@ let t: IntSet.t = []
2828

2929
// let s2 = IntSet.
3030
// ^com
31+
32+
module WithNested = (O: Ord) => {
33+
module Nested = {
34+
// ^ref
35+
let value = 1
36+
}
37+
}
38+
39+
module IntOrd = {
40+
type t = int
41+
let compare = (a: int, b) => a - b
42+
}
43+
44+
module N = WithNested(IntOrd)
45+
46+
let n = N.Nested.value
47+
// ^ref

‎tests/analysis_tests/tests/src/expected/AppliedFunctor.res.txt‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,39 @@ Path IntSet.
132132
}
133133
]
134134

135+
References src/AppliedFunctor.res 32:11
136+
[
137+
{
138+
"range": {
139+
"end": { "character": 15, "line": 32 },
140+
"start": { "character": 9, "line": 32 }
141+
},
142+
"uri": "file:///AppliedFunctor.res"
143+
},
144+
{
145+
"range": {
146+
"end": { "character": 16, "line": 45 },
147+
"start": { "character": 10, "line": 45 }
148+
},
149+
"uri": "file:///AppliedFunctor.res"
150+
}
151+
]
152+
153+
References src/AppliedFunctor.res 45:10
154+
[
155+
{
156+
"range": {
157+
"end": { "character": 15, "line": 32 },
158+
"start": { "character": 9, "line": 32 }
159+
},
160+
"uri": "file:///AppliedFunctor.res"
161+
},
162+
{
163+
"range": {
164+
"end": { "character": 16, "line": 45 },
165+
"start": { "character": 10, "line": 45 }
166+
},
167+
"uri": "file:///AppliedFunctor.res"
168+
}
169+
]
170+

0 commit comments

Comments
 (0)