Skip to content

Fix editor references for members brought in by include - #9331

Draft
cknitt wants to merge 1 commit into
masterfrom
fix-9323-include-declarations
Draft

cknitt wants to merge 1 commit into
masterfrom
fix-9323-include-declarations

Conversation

@cknitt

@cknitt cknitt commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Editor analysis treats each member copied by an include as a declaration of its own, at the position of the original declaration. This causes two problems:

  • Find References on a member of a local module or functor that is included elsewhere splits into two sets: the declaration with its direct uses, and the uses of the included copy.
  • An include does not rename constructors and record fields, so constructors and fields of an included type keep the stamps of their original declaration, possibly from another compilation. These stamps can equal stamps of values in the including file. Find References on such a value then shows duplicates and 0:-1 locations, and misses uses in other files.

With this change:

  • A copy whose original member is found is no longer a declaration. Find References on a member gathers the original and all its copies, in this file, in the other file of a .res/.resi pair, and, for a member included from another file, in that file too.
  • This also holds in a module that shadows an included member, which the type checker constrains to its own signature, and for include module type of M in a signature.
  • Constructors and record fields read from a signature get stamps of their own, numbered per file, so they can't collide with the file's values. Go to definition on them follows the copy to the type it comes from.
  • References at ghost locations, such as members read from a signature, are dropped, so there are no more 0:-1 entries.
  • Find References reads the other files of the project once per query, whatever the number of copies. On a 310-file project, a member with eight copies takes the same time as on master.

New tests: IncludeDeclarations.res, IncludeDeclarationsLib.res and IncludeDeclarationsUse.res cover colliding stamps, includes of local functors and modules, nested includes, includes inside a module, several copies of one member, constructors and fields from another file's functor, and uses from another file. IncludeDeclarationsParam.res, IncludeDeclarationsSig.res and IncludeDeclarationsUnpack.res cover include of a functor parameter and include unpack(...). IncludeDeclarationsOverride.res covers includes with a shadowed member, also from another file. IncludeDeclarationsIntf.res(i) with IncludeDeclarationsIntfUse.res, and IncludeDeclarationsTypeOf.res(i), cover a module with an interface and include module type of.

Not found: uses through the including file's path when Find References starts from the original declaration in another file, and constructors and fields of a module type used through another module type that includes it.

Fixes #9323

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kbf3gGbYDy2DBe5YmGdHTL

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Changelog

🐛 Bug fix

  • Editor: find references, definition and rename handle members brought in by include correctly, without duplicate or wrong locations.

Semantic Diff

1 commit · Full page

✏️ Treat included members as copies of their declarations in editor analysis

63fe1e1 · cknitt + Claude · Dec 03, 2026, 20:04 UTC · edited

Why

An include copies the members of a module under new stamps, at the positions of the original declarations. Analysis registers each copy as a declaration of the including file, so Find References on a member splits into the declaration with its direct uses and the uses of the copy (fv below).

Constructors and record fields keep their identifiers through an include. When they come from another file's compilation, their stamps can equal stamps of values in the including file (Dot and Box below have the stamps of v0 and v1). Find References on such a value then lists wrong and 0:-1 locations and misses its uses in other files.

References modified (include)

// Lib.res
module type T = {
  type t
}
module Make = (X: T) => {
  type shape = Dot | Box(X.t)
}

// Main.res
include Lib.Make({
  type t = int
})
let v0 = 0
let v1 = 1
let v2 = 2
module type T = {
  type t
}
module F = (X: T) => {
  let fv = 1
}
include F({
  type t = int
})
let u = fv

// Other.res
let w = Main.v0 + Main.v1

text · Before: line:column, from 0

-v0 in Main         Main 3:4, Main 0:-1, Main 3:4
-fv in F            Main 10:6
+v0 in Main         Main 3:4, Other 0:13
+fv in F            Main 10:6, Main 15:8
 fv after include   Main 10:6, Main 15:8

References modified (constructor of an included type)

// Main.res, with Lib.res as above
include Lib.Make({
  type t = int
})
let v0 = 0
let v1 = 1
let dot = Dot
let box = Box(1)

text · Before: line:column, from 0

-Dot in Main        Main 3:4, Main 0:-1, Main 3:4, Main 5:10
-definition of Box  null
+Dot in Main        Main 5:10, Lib 4:15
+definition of Box  Lib 4:21

References modified (include with a shadowed member)

module Base = {
  type t = A | B
  type r = {f: int}
  let bv = 1
  let other = 2
}
module Over = {
  include Base
  let other = 3
}
let a = Over.A
let f = (x: Over.r) => x.f
let b = Over.bv + Base.bv
let o = Over.other

text · Before: line:column, from 0

-Over.A       1:11, 0:-1, 0:-1, 10:13
-x.f          2:12, 0:-1, 0:-1, 11:25
-Over.bv      3:6, 3:6, 3:6, 12:13
-Over.other   8:6, 8:6, 8:6, 13:13
+Over.A       1:11, 10:13
+x.f          2:12, 11:25
+Over.bv      3:6, 12:13, 12:23
+Over.other   8:6, 13:13

References modified (include module type of)

// M.res
module Base = {
  let bv = 1
}
include Base

// M.resi
module Base: {
  let bv: int
}
include module type of Base

text · Before: bv in Base, line:column, from 0

-M.resi 1:2 (all of `let bv: int`), M.res 1:6
+M.resi 1:6, M.res 1:6

A copy whose original member is found is not a declaration of the including file: it has no definition item and no declaration reference. The original is found from the copy's module path, which names the included module source and the modules a nested copy sits in: the copy of x in a nested Inner resolves to source.Inner.x. Other files reach that copy under its full path, such as Main.Inner.x.

Find References on a value, type or module gathers the original member and all its copies in the file and in the other file of a .res/.resi pair, and the original's references in its own file when it is in another one. Constructors and fields go through their type. The uses that other files record for all of them are collected in one pass over the project. Go to definition on a constructor or field of a copied type goes to the one it copies.

A module that shadows a member it includes gets an implicit constraint to its own signature. Its members, read again from that signature, keep what the structure gave them, so its copies stay copies, and each member is declared once. include module type of M in a signature is an include of M.

Constructors and record fields read from a signature (an include, a module type, a functor parameter) get stamps of their own. References at ghost locations, such as those of members read from a signature, are dropped, so there are no 0:-1 entries.

Review

  • Why fresh stamps for constructors and fields of signatures? An include or a module type keeps their identifiers, and a signature from another file brings that compilation's stamps, which can equal stamps of this one. Fresh stamps avoid that wherever the signature comes from, also for include unpack(...) and for a functor parameter, where no original can be resolved. They count down from -2, because 0 marks a persistent identifier and -1 a hidden one. The numbering restarts for each file, so reading a file twice gives the same stamps.
  • What does the project scan cost? Find References reads each file of the project, and the other file of a .res/.resi pair, once per query, whatever the number of copies.
  • Why does the Hover snapshot change? @react.component adds a second make, so the module was read twice and x was declared twice. With one declaration, the JSX heuristic no longer runs; the hover text is the same.
  • What is not found? From the declaration in another file, uses through the including file's copy, such as Main.Dot or Main.made, are not found, as on master. Constructors and fields of a module type S used through another module type that includes it, as with module type S2 = { include S }, module M: S and a parameter X: S2, are not connected. On master they were, only through shared stamps and with 0:-1 entries. Values already behave this way.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.26519% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.59%. Comparing base (5e5a3a7) to head (63fe1e1).
⚠️ Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
analysis/src/references.ml 92.17% 9 Missing ⚠️
analysis/src/process_cmt.ml 86.95% 3 Missing ⚠️
analysis/src/process_extra.ml 94.44% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9331      +/-   ##
==========================================
+ Coverage   82.47%   82.59%   +0.11%     
==========================================
  Files         466      468       +2     
  Lines       66070    66285     +215     
==========================================
+ Hits        54493    54746     +253     
+ Misses      11577    11539      -38     
Files with missing lines Coverage Δ
analysis/src/shared_types.ml 84.32% <100.00%> (+0.74%) ⬆️
analysis/src/process_extra.ml 87.50% <94.44%> (+0.15%) ⬆️
analysis/src/process_cmt.ml 87.30% <86.95%> (+2.30%) ⬆️
analysis/src/references.ml 76.94% <92.17%> (+5.73%) ⬆️

... and 45 files with indirect coverage changes

🚀 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,172,926 → 653,173,043 (±0.00%).

Generated projects: 627,288,369 → 627,288,475 (±0.00%).

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

Instructions

In total: 8,966,821,151 → 8,966,821,151 (±0.00%).

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

Output size

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

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

Pull request 63fe1e1 compared with base 7968a96 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@9331

@rescript/belt

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

@rescript/darwin-arm64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 63fe1e1

@github-actions

Copy link
Copy Markdown

@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-19T19:56:32.726864Z f00fc1e 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73f322a215

ℹ️ 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".

Comment thread analysis/src/process_extra.ml Resolved
@cknitt
cknitt force-pushed the fix-9323-include-declarations branch from 73f322a to 610362c Compare November 19, 2026 08:09
@cknitt

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 610362c9da

ℹ️ 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".

Comment thread analysis/src/references.ml Resolved
@cknitt
cknitt force-pushed the fix-9323-include-declarations branch from 610362c to 5bc3c31 Compare November 19, 2026 10:22
@cknitt

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bc3c3186f

ℹ️ 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".

Comment thread analysis/src/process_extra.ml Resolved
@cknitt
cknitt force-pushed the fix-9323-include-declarations branch from 5bc3c31 to 16f3ab8 Compare November 19, 2026 10:45
@cknitt

cknitt commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 16f3ab84c3

ℹ️ 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 commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: f00fc1e421

ℹ️ 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-9323-include-declarations branch 2 times, most recently from bfe8b5e to 8745394 Compare November 23, 2026 06:47
@cknitt
cknitt force-pushed the fix-9323-include-declarations branch from 8745394 to 74c7fef Compare November 30, 2026 09:44
…ysis

Why:
    An `include` copies the members of a module under new stamps, at the
    positions of the original declarations. Analysis registers each copy
    as a declaration of the including file, so Find References on a member
    splits into the declaration with its direct uses and the uses of the
    copy (`fv` below).

    Constructors and record fields keep their identifiers through an
    include. When they come from another file's compilation, their stamps
    can equal stamps of values in the including file (`Dot` and `Box`
    below have the stamps of `v0` and `v1`). Find References on such a
    value then lists wrong and `0:-1` locations and misses its uses in
    other files.

References modified (include):
Example:
    // Lib.res
    module type T = {
      type t
    }
    module Make = (X: T) => {
      type shape = Dot | Box(X.t)
    }

    // Main.res
    include Lib.Make({
      type t = int
    })
    let v0 = 0
    let v1 = 1
    let v2 = 2
    module type T = {
      type t
    }
    module F = (X: T) => {
      let fv = 1
    }
    include F({
      type t = int
    })
    let u = fv

    // Other.res
    let w = Main.v0 + Main.v1
Before (text): line:column, from 0
    v0 in Main         Main 3:4, Main 0:-1, Main 3:4
    fv in F            Main 10:6
    fv after include   Main 10:6, Main 15:8
After (text):
    v0 in Main         Main 3:4, Other 0:13
    fv in F            Main 10:6, Main 15:8
    fv after include   Main 10:6, Main 15:8

References modified (constructor of an included type):
Example:
    // Main.res, with Lib.res as above
    include Lib.Make({
      type t = int
    })
    let v0 = 0
    let v1 = 1
    let dot = Dot
    let box = Box(1)
Before (text): line:column, from 0
    Dot in Main        Main 3:4, Main 0:-1, Main 3:4, Main 5:10
    definition of Box  null
After (text):
    Dot in Main        Main 5:10, Lib 4:15
    definition of Box  Lib 4:21

References modified (include with a shadowed member):
Example:
    module Base = {
      type t = A | B
      type r = {f: int}
      let bv = 1
      let other = 2
    }
    module Over = {
      include Base
      let other = 3
    }
    let a = Over.A
    let f = (x: Over.r) => x.f
    let b = Over.bv + Base.bv
    let o = Over.other
Before (text): line:column, from 0
    Over.A       1:11, 0:-1, 0:-1, 10:13
    x.f          2:12, 0:-1, 0:-1, 11:25
    Over.bv      3:6, 3:6, 3:6, 12:13
    Over.other   8:6, 8:6, 8:6, 13:13
After (text):
    Over.A       1:11, 10:13
    x.f          2:12, 11:25
    Over.bv      3:6, 12:13, 12:23
    Over.other   8:6, 13:13

References modified (include module type of):
Example:
    // M.res
    module Base = {
      let bv = 1
    }
    include Base

    // M.resi
    module Base: {
      let bv: int
    }
    include module type of Base
Before (text): bv in Base, line:column, from 0
    M.resi 1:2 (all of `let bv: int`), M.res 1:6
After (text):
    M.resi 1:6, M.res 1:6

A copy whose original member is found is not a declaration of the
including file: it has no definition item and no declaration reference.
The original is found from the copy's module path, which names the
included module `source` and the modules a nested copy sits in: the copy of
`x` in a nested `Inner` resolves to `source.Inner.x`. Other files reach
that copy under its full path, such as `Main.Inner.x`.

Find References on a value, type or module gathers the original member and
all its copies in the file and in the other file of a .res/.resi pair, and
the original's references in its own file when it is in another one. Constructors and fields go through their type.
The uses that other files record for all of them are collected in one pass
over the project. Go to definition on a constructor or field of a copied
type goes to the one it copies.

A module that shadows a member it includes gets an implicit constraint to
its own signature. Its members, read again from that signature, keep what
the structure gave them, so its copies stay copies, and each member is
declared once. `include module type of M` in a signature is an include of
`M`.

Constructors and record fields read from a signature (an include, a module
type, a functor parameter) get stamps of their own. References at ghost
locations, such as those of members read from a signature, are dropped, so
there are no `0:-1` entries.

Review: Why fresh stamps for constructors and fields of signatures? An
include or a module type keeps their identifiers, and a signature from
another file brings that compilation's stamps, which can equal stamps of
this one. Fresh stamps avoid that wherever the signature comes from, also
for `include unpack(...)` and for a functor parameter, where no original
can be resolved. They count down from -2, because 0 marks a persistent
identifier and -1 a hidden one. The numbering restarts for each file, so
reading a file twice gives the same stamps.

Review: What does the project scan cost? Find References reads each file of
the project, and the other file of a .res/.resi pair, once per query,
whatever the number of copies.

Review: Why does the Hover snapshot change? `@react.component` adds a second
`make`, so the module was read twice and `x` was declared twice. With one
declaration, the JSX heuristic no longer runs; the hover text is the same.

Review: What is not found? From the declaration in another file, uses
through the including file's copy, such as `Main.Dot` or `Main.made`, are
not found, as on master. Constructors and fields of a module type `S` used
through another module type that includes it, as with
`module type S2 = { include S }`, `module M: S` and a parameter `X: S2`,
are not connected. On master they were, only through shared stamps and
with `0:-1` entries. Values already behave this way.

Fixes: #9323
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGbYDy2DBe5YmGdHTL
Claude-Session: https://claude.ai/code/session_01Kbf3gGgQuXy1xmZbjATZsB
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the fix-9323-include-declarations branch from 3c61679 to 63fe1e1 Compare December 3, 2026 20:05

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.

Editor analysis registers included members as separate declarations

1 participant