Skip to content

Find references written through another module path - #9329

Draft
cknitt wants to merge 1 commit into
fix-9322-definition-filefrom
fix-9321-references-other-paths
Draft

cknitt wants to merge 1 commit into
fix-9322-definition-filefrom
fix-9321-references-other-paths

Conversation

@cknitt

@cknitt cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member

Find References and Rename missed uses in other files written through a different module path than the declaration's: through the file that applies a functor (Use.S.add), through a partial application (Fn.First(Fn.IntOrd)), and plain values of a namespaced dependency. Rename left these uses unchanged, so the code stopped compiling.

Find References now resolves the paths recorded in other files when they end in the declaration's name, and keeps those that lead to the declaration. Each path is resolved once per search; on a 305-file project the time is unchanged.

Stacked on #9328, which reads a functor alias under the type checker's implicit constraint as the alias, so uses through Aliased = Make(...) are recorded under the functor's own path.

New 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 constructors. A new namespaced dependency in tests-sourcedirs-dependency covers references to a value of a namespaced dependency, written directly and through a module alias.

Fixes #9321

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gGbYDy2DBe5YmGdHTL

@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

0d4b271 · 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 looked only under the declaration's own path (Fn.MakeSet.add), so it missed uses through the file that applies a functor, through a partial application, and plain values of a namespaced dependency. Rename then left these uses unchanged and the code stopped compiling.

Find References now also takes a recorded path that ends in the declaration's name and resolves it, and keeps it when it resolves to the declaration or its .res/.resi counterpart.

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 · 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 · references of pair in Fn.res

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

text · 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 · 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

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.
  • 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. On a 305-file project, references on a value of Big.res take 0.27 s before and after.
  • 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 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.17%. Comparing base (a6ea24e) to head (0d4b271).

Files with missing lines Patch % Lines
analysis/src/references.ml 92.59% 2 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           fix-9322-definition-file    #9329   +/-   ##
=========================================================
  Coverage                     82.16%   82.17%           
=========================================================
  Files                           456      456           
  Lines                         65664    65683   +19     
=========================================================
+ Hits                          53953    53974   +21     
+ Misses                        11711    11709    -2     
Files with missing lines Coverage Δ
analysis/src/references.ml 72.77% <92.59%> (+2.17%) ⬆️
🚀 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: 639,844,209 → 639,843,205 (±0.00%).

Generated projects: 629,805,995 → 629,805,044 (±0.00%).

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

Instructions

In total: 9,210,459,675 → 9,210,459,675 (±0.00%).

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

Output size

In total: 25,919,386 → 25,919,386 (±0.00%).

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

Pull request 0d4b271 compared with base 39b1a9e 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: 0d4b271

@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-11-19T08:03:01.552180Z 464c187 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".

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 looked only under the declaration's own path
    (Fn.MakeSet.add), so it missed uses through the file that applies a
    functor, through a partial application, and plain values of a
    namespaced dependency. Rename then left these uses unchanged and the
    code stopped compiling.

    Find References now also takes a recorded path that ends in the
    declaration's name and resolves it, and keeps it when it resolves to
    the declaration or its .res/.resi counterpart.

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): 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): 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): references of pair in Fn.res
    Fn.res   11:7  let pair
After (text): references of pair in Fn.res
    Fn.res   11:7  let pair
    Use.res  7:13  Fin.pair
Before (text): 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): 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): references of plain in Main.res
    NsUtils.res  2:7  let plain
After (text): 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

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: 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. On a 305-file project, references on a value of
Big.res take 0.27 s before and after.

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_01Kbf3gGbYDy2DBe5YmGdHTL
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the fix-9321-references-other-paths branch from 464c187 to 0d4b271 Compare November 19, 2026 08:10

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

1 participant