Skip to content

Find references written through another module path - #9329

Open
cknitt wants to merge 1 commit into
masterfrom
fix-9321-references-other-paths
Open

cknitt wants to merge 1 commit into
masterfrom
fix-9321-references-other-paths

Conversation

@cknitt

@cknitt cknitt commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

A use in another file is recorded under the path it is written with. Find References looks only under the declaration's own path, so it misses some uses:

  • uses through the file that applies a functor (Use.S.add)
  • uses through a partial application (Fn.First(Fn.IntOrd))
  • uses of a namespaced dependency's values

Rename leaves these uses unchanged, and the code no longer compiles.

With this change, Find References also resolves the recorded paths that end in the declaration's name, and keeps those that lead to the declaration. It also keeps those that lead to the declaration's .res/.resi counterpart, if that counterpart sits at the same path. With module N: S in the .resi, the counterpart of N.s is the module type's S.s. Other modules constrained by S share it, so uses that lead there are not uses of N.s.

Cost. Each path is resolved once per search. Resolving loads the referenced module through the analysis cache, so the first search in a session loads those modules once. On 400 files that all export t, make and map, three searches take 0.42 s against 0.16 s before. After that, a search costs the same as before.

Tests. PathRefs.res, PathRefsUse.res and PathRefsFar.res cover references and rename through a functor application in another file, a functor alias, a partial application and a module alias, for values, types, record fields and constructors. They also check that a same-named value in a sibling module is not found. PathRefsIntf.res/.resi checks that a module constrained by a module type in the .resi doesn't pick up a sibling's uses. A new namespaced dependency in tests-sourcedirs-dependency covers a namespaced dependency's values, written directly and through a module alias.

Not covered here. These problems already exist on master:

Fixes #9321

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gGUP7SAjW77BvdfhQD

@cknitt
cknitt added this pull request to stack #9330 November 19, 2026 06:20
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Find References and Rename in the editor now also find uses written through another module path, such as a functor application in another file, a local alias of a functor, or a namespaced dependency.

Semantic Diff

1 commit · Full page

Find references written through another module path

c18b5a2 · cknitt + Claude · Nov 19, 2026, 06:14 UTC

Why

A use in another file is recorded under the path it is written with, such as Use.S.add for a functor application S in Use.res. Find References looks only under the declaration's own path (Fn.MakeSet.add), so it misses uses through the file that applies a functor, through a partial application, and uses of a namespaced dependency's values. Rename leaves these uses unchanged, and the code no longer compiles.

Find References now also resolves the recorded paths that end in the declaration's name, and keeps those that lead to the declaration or to its .res/.resi counterpart at the same path.

References modified (functor application used from another file)

// Fn.res
module type Ord = {
  type t
}
module IntOrd = {
  type t = int
}
module MakeSet = (O: Ord) => {
  let add = (x: O.t) => [x]
}
module MakeTwo = (A: Ord, B: Ord) => {
  let pair = 1
}
module First = MakeTwo(IntOrd)

// Use.res
module S = Fn.MakeSet(Fn.IntOrd)
let s = S.add(1)
module Make = Fn.MakeSet
module Aliased = Make(Fn.IntOrd)
let a = Aliased.add(1)
module Fin = Fn.First(Fn.IntOrd)
let p = Fin.pair

// Far.res
let f = Use.S.add(2)

text · 1-based line:column, references of add in Fn.res

 Fn.res   8:7   let add
 Use.res  2:11  S.add
 Use.res  5:17  Aliased.add
+Far.res  1:15  Use.S.add

text · 1-based line:column, references of pair in Fn.res

 Fn.res   11:7  let pair
+Use.res  7:13  Fin.pair

text · 1-based line:column, references of Use.S.add in Far.res

 Fn.res   8:7   let add
 Use.res  2:11  S.add
 Use.res  5:17  Aliased.add
+Far.res  1:15  Use.S.add

Rename modified (functor application used from another file)

text · rename Use.S.add in Far.res to plus

 Fn.res   let add      ⇝  let plus
 Use.res  S.add        ⇝  S.plus
 Use.res  Aliased.add  ⇝  Aliased.plus
+Far.res  Use.S.add    ⇝  Use.S.plus

References modified (value of a namespaced dependency)

// NsUtils.res in a dependency with namespace NsDep
module Plain = {
  let plain = 1
}

// Main.res
let p = NsDep.NsUtils.Plain.plain
module P = NsDep.NsUtils.Plain
let q = P.plain

text · 1-based line:column, references of plain in Main.res

-NsUtils.res  2:7  let plain
+NsUtils.res  2:7   let plain
+Main.res     1:29  NsDep.NsUtils.Plain.plain
+Main.res     3:11  P.plain

References modified (value of a module type, used through a module constrained by it in a .resi):

// SignatureItemsIntf.resi
module type S = {
  let s: int
}
module N: S

// SignatureItemsUse.res
let s = SignatureItemsIntf.N.s

text · 1-based line:column, references of s in SignatureItemsIntf.resi

-SignatureItemsIntf.res   2:7  let s
-SignatureItemsIntf.resi  2:7  let s
+SignatureItemsUse.res    4:30  SignatureItemsIntf.N.s
+SignatureItemsIntf.res   2:7   let s
+SignatureItemsIntf.resi  2:7   let s

Review

  • Why not record each use under its declaration's key? Recording happens per file, without access to the other files a path goes through. Resolving at search time needs no change to the recorded data.
  • Why only a counterpart at the same path? With module N: S in the .resi, the counterpart of N.s in the .res is S.s in the .resi. Other modules share S.s: uses of I.M.s for module M: S resolve to it too. Keeping them would list I.M.s as a reference of N.s, and Rename would change it.
  • Does this slow down Find References on large projects? Only recorded paths that end in the declaration's name are resolved, each distinct path once per search. Resolving loads the referenced module through the analysis cache, so the first search in a session pays for loading these modules once. On 400 files that all export t, make and map, three searches take 0.42 s against 0.16 s before. After that, a search costs the same as before, about 15 ms.
  • Why keep the exact match on the declaration's own path? It is the common case and needs no resolution, and it keeps every result the old search found.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.57%. Comparing base (af21a60) to head (c18b5a2).

Files with missing lines Patch % Lines
analysis/src/references.ml 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9329      +/-   ##
==========================================
+ Coverage   82.56%   82.57%   +0.01%     
==========================================
  Files         468      468              
  Lines       66228    66249      +21     
==========================================
+ Hits        54678    54702      +24     
+ Misses      11550    11547       -3     
Files with missing lines Coverage Δ
analysis/src/references.ml 73.78% <93.10%> (+2.57%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

✅ Compiler benchmarks

Allocated words

In total: 653,160,677 → 653,160,792 (±0.00%).

Generated projects: 627,282,135 → 627,282,410 (±0.00%).

None of the 265 benchmarks changed by 0.1% or more.

Instructions

In total: 8,966,802,932 → 8,966,802,932 (±0.00%).

None of the 33 benchmarks changed by 0.1% or more.

Output size

In total: 27,449,924 → 27,449,924 (±0.00%).

None of the 13 benchmarks changed by 0.1% or more.

Pull request c18b5a2 compared with base af21a60 in this run.

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@9329

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@9329

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@9329

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@9329

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@9329

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@9329

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@9329

commit: 0b6ebf7

@cknitt

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T06:12:35.487826Z 0b6ebf7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 464c187d7d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch 2 times, most recently from 0d4b271 to 4f7a8e1 Compare November 19, 2026 18:57
@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch from 4f7a8e1 to 3263625 Compare November 19, 2026 20:14
Base automatically changed from fix-9322-definition-file to master November 19, 2026 21:18
@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch from 3263625 to a9d05e5 Compare November 19, 2026 21:18
@github-actions

Copy link
Copy Markdown

@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch 2 times, most recently from 6dfad2a to b14c9d4 Compare November 23, 2026 06:47
@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch 2 times, most recently from 068e9c8 to c0d0f9d Compare December 3, 2026 05:43
@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch from c0d0f9d to 0b6ebf7 Compare December 3, 2026 05:58
@cknitt

cknitt commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 0b6ebf7308

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cknitt
cknitt marked this pull request as ready for review December 3, 2026 20:08
@cknitt
cknitt requested a review from cristianoc December 3, 2026 20:08

@cristianoc cristianoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the same-name candidate resolution, including the explicit interface-counterpart path check and the negative sibling-module case. The documented include and functor-signature limitations remain follow-ups.

Why:
    A use in another file is recorded under the path it is written with,
    such as `Use.S.add` for a functor application `S` in Use.res. Find
    References looks only under the declaration's own path
    (`Fn.MakeSet.add`), so it misses uses through the file that applies a
    functor, through a partial application, and uses of a namespaced
    dependency's values. Rename leaves these uses unchanged, and the code
    no longer compiles.

    Find References now also resolves the recorded paths that end in the
    declaration's name, and keeps those that lead to the declaration or
    to its .res/.resi counterpart at the same path.

References modified (functor application used from another file):
Example:
    // Fn.res
    module type Ord = {
      type t
    }
    module IntOrd = {
      type t = int
    }
    module MakeSet = (O: Ord) => {
      let add = (x: O.t) => [x]
    }
    module MakeTwo = (A: Ord, B: Ord) => {
      let pair = 1
    }
    module First = MakeTwo(IntOrd)

    // Use.res
    module S = Fn.MakeSet(Fn.IntOrd)
    let s = S.add(1)
    module Make = Fn.MakeSet
    module Aliased = Make(Fn.IntOrd)
    let a = Aliased.add(1)
    module Fin = Fn.First(Fn.IntOrd)
    let p = Fin.pair

    // Far.res
    let f = Use.S.add(2)
Before (text): 1-based line:column, references of add in Fn.res
    Fn.res   8:7   let add
    Use.res  2:11  S.add
    Use.res  5:17  Aliased.add
After (text): 1-based line:column, references of add in Fn.res
    Fn.res   8:7   let add
    Use.res  2:11  S.add
    Use.res  5:17  Aliased.add
    Far.res  1:15  Use.S.add
Before (text): 1-based line:column, references of pair in Fn.res
    Fn.res   11:7  let pair
After (text): 1-based line:column, references of pair in Fn.res
    Fn.res   11:7  let pair
    Use.res  7:13  Fin.pair
Before (text): 1-based line:column, references of Use.S.add in Far.res
    Fn.res   8:7   let add
    Use.res  2:11  S.add
    Use.res  5:17  Aliased.add
After (text): 1-based line:column, references of Use.S.add in Far.res
    Fn.res   8:7   let add
    Use.res  2:11  S.add
    Use.res  5:17  Aliased.add
    Far.res  1:15  Use.S.add

Rename modified (functor application used from another file):
Before (text): rename Use.S.add in Far.res to plus
    Fn.res   let add      ⇝  let plus
    Use.res  S.add        ⇝  S.plus
    Use.res  Aliased.add  ⇝  Aliased.plus
After (text): rename Use.S.add in Far.res to plus
    Fn.res   let add      ⇝  let plus
    Use.res  S.add        ⇝  S.plus
    Use.res  Aliased.add  ⇝  Aliased.plus
    Far.res  Use.S.add    ⇝  Use.S.plus

References modified (value of a namespaced dependency):
Example:
    // NsUtils.res in a dependency with namespace NsDep
    module Plain = {
      let plain = 1
    }

    // Main.res
    let p = NsDep.NsUtils.Plain.plain
    module P = NsDep.NsUtils.Plain
    let q = P.plain
Before (text): 1-based line:column, references of plain in Main.res
    NsUtils.res  2:7  let plain
After (text): 1-based line:column, references of plain in Main.res
    NsUtils.res  2:7   let plain
    Main.res     1:29  NsDep.NsUtils.Plain.plain
    Main.res     3:11  P.plain

References modified (value of a module type, used through a module
constrained by it in a .resi):
Example:
    // SignatureItemsIntf.resi
    module type S = {
      let s: int
    }
    module N: S

    // SignatureItemsUse.res
    let s = SignatureItemsIntf.N.s
Before (text): 1-based line:column, references of s in SignatureItemsIntf.resi
    SignatureItemsIntf.res   2:7  let s
    SignatureItemsIntf.resi  2:7  let s
After (text): 1-based line:column, references of s in SignatureItemsIntf.resi
    SignatureItemsUse.res    4:30  SignatureItemsIntf.N.s
    SignatureItemsIntf.res   2:7   let s
    SignatureItemsIntf.resi  2:7   let s

Review: Why not record each use under its declaration's key? Recording
happens per file, without access to the other files a path goes through.
Resolving at search time needs no change to the recorded data.

Review: Why only a counterpart at the same path? With `module N: S` in
the .resi, the counterpart of `N.s` in the .res is `S.s` in the .resi.
Other modules share `S.s`: uses of `I.M.s` for `module M: S` resolve to
it too. Keeping them would list `I.M.s` as a reference of `N.s`, and
Rename would change it.

Review: Does this slow down Find References on large projects? Only
recorded paths that end in the declaration's name are resolved, each
distinct path once per search. Resolving loads the referenced module
through the analysis cache, so the first search in a session pays for
loading these modules once. On 400 files that all export `t`, `make` and
`map`, three searches take 0.42 s against 0.16 s before. After that, a
search costs the same as before, about 15 ms.

Review: Why keep the exact match on the declaration's own path? It is
the common case and needs no resolution, and it keeps every result the
old search found.

Fixes: #9321
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGUP7SAjW77BvdfhQD
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch from 0b6ebf7 to c18b5a2 Compare December 4, 2026 06:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find References misses uses written through another module path

2 participants