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 treated each member copied by an include as a declaration of its own, at the position of the original declaration. Constructors keep their original stamps through an include. When they came from another file, those stamps could equal stamps of values in the including file. Find References on such a value then showed duplicates and a 0:-1 location, and missed the uses in other files. Copies of members from a local functor or module split references between the declaration and the uses.

Now a copy whose original member is found is no longer registered as a declaration. Find References gathers the original and all its copies. Constructors and fields of an included type are looked up in the type they come from, so references and go-to-definition reach the declaration in the other file.

New fixtures IncludeDeclarations.res, IncludeDeclarationsLib.res and IncludeDeclarationsUse.res cover the issue's cases: references on values whose stamps collide, local functor and module includes, nested includes, includes inside a module, constructors from another file's functor, and uses from another file.

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 original declarations in editor analysis

16f3ab8 · cknitt + Claude · Nov 19, 2026, 06:19 UTC · edited

Why

An include copies the members of a module under new stamps, at the positions of the original declarations. Analysis registered each copy as a declaration of the including file. An include does not rename constructors, so the copied Dot and Box below keep their stamps from Lib's compilation, which are the stamps of v0 and v1 in Main. That hid v0 and v1, listed bogus locations and lost their uses in other files. The copy of fv was a second declaration at the position of let fv, so references from the declaration and from the use split.

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

A copy whose original member is found is no longer a declaration of the including file: it gets no definition item and no declaration reference, and the constructors of an included type are not put in the stamp table. Find References on a value, type or module collects the original member and all its copies in the file. Constructors and record fields of an included type are looked up in the type they were copied from, which links them to their declaration in the other file.

Review

  • How is the original member found? The copy's module path is IncludedModule (source, _), so source.name is resolved like any other path. In this file that gives the original stamp.
  • And when the member is in another file? Find References on the copy adds the references of the original member, found in its file, to the copy's own: the uses of the copy in this file and the uses other files record under this file's path. For a constructor or field the copy has the other file's stamps, so its uses here are recorded under the other file and the stamp is not looked up in this file. Going the other way, from a use linked to the other file, the copies included into this file add the uses recorded under this file's path. From the declaration in the other file, uses through this file's path are still not found, as on master.
  • What about members of a module nested in the included one? A nested module copied by an include now records itself in its members' module path, as ExportedModule under the IncludedModule, and Module_path.included_path rebuilds source.Nested.name. Without that, the copy of Nested.x would resolve to source.x and merge the references of the two values.
  • Why do constructor and field references also go through the family of their type? Other files reference a constructor of an included type by the copy's path (Main.L1), while uses in the file are linked to the original type. Each type in the family contributes the references under its own path. The constructors of a type and of its copies share stamps, so a location found twice is reported once; a lone stamp is handled as before.
  • What if the source can't be resolved, such as a module type included in a .resi, which analysis does not register? Then the copy stays a declaration, as before.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.22556% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.17%. Comparing base (0b2246c) to head (16f3ab8).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
analysis/src/references.ml 87.65% 10 Missing ⚠️
analysis/src/process_extra.ml 92.30% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9331      +/-   ##
==========================================
+ Coverage   82.12%   82.17%   +0.05%     
==========================================
  Files         456      456              
  Lines       65661    65723      +62     
==========================================
+ Hits        53926    54011      +85     
+ Misses      11735    11712      -23     
Files with missing lines Coverage Δ
analysis/src/process_cmt.ml 85.48% <100.00%> (+1.11%) ⬆️
analysis/src/shared_types.ml 84.32% <100.00%> (+0.63%) ⬆️
analysis/src/process_extra.ml 87.31% <92.30%> (-0.04%) ⬇️
analysis/src/references.ml 74.93% <87.65%> (+4.41%) ⬆️

... and 27 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: 639,846,772 → 639,846,625 (±0.00%).

Generated projects: 629,813,365 → 629,811,987 (±0.00%).

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

Instructions

In total: 9,210,478,378 → 9,210,478,378 (±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 16f3ab8 compared with base 91d74a0 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: 16f3ab8

@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-19T11:01:41.376432Z 16f3ab8 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
…itor analysis

Why:
    An `include` copies the members of a module under new stamps, at the
    positions of the original declarations. Analysis registered each copy
    as a declaration of the including file. An include does not rename
    constructors, so the copied `Dot` and `Box` below keep their stamps
    from Lib's compilation, which are the stamps of `v0` and `v1` in Main.
    That hid `v0` and `v1`, listed bogus locations and lost their uses in
    other files. The copy of `fv` was a second declaration at the position
    of `let fv`, so references from the declaration and from the use split.

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

A copy whose original member is found is no longer a declaration of the
including file: it gets no definition item and no declaration reference,
and the constructors of an included type are not put in the stamp table.
Find References on a value, type or module collects the original member
and all its copies in the file. Constructors and record fields of an
included type are looked up in the type they were copied from, which links
them to their declaration in the other file.

Review: How is the original member found? The copy's module path is
`IncludedModule (source, _)`, so `source.name` is resolved like any other
path. In this file that gives the original stamp.

Review: And when the member is in another file? Find References on the copy
adds the references of the original member, found in its file, to the
copy's own: the uses of the copy in this file and the uses other files
record under this file's path. For a constructor or field the copy has the
other file's stamps, so its uses here are recorded under the other file and
the stamp is not looked up in this file. Going the other way, from a use
linked to the other file, the copies included into this file add the uses
recorded under this file's path. From the declaration in the other file,
uses through this file's path are still not found, as on master.

Review: What about members of a module nested in the included one? A
nested module copied by an include now records itself in its members'
module path, as `ExportedModule` under the `IncludedModule`, and
`Module_path.included_path` rebuilds `source.Nested.name`. Without that,
the copy of `Nested.x` would resolve to `source.x` and merge the
references of the two values.

Review: Why do constructor and field references also go through the
family of their type? Other files reference a constructor of an included
type by the copy's path (`Main.L1`), while uses in the file are linked to
the original type. Each type in the family contributes the references
under its own path. The constructors of a type and of its copies share
stamps, so a location found twice is reported once; a lone stamp is
handled as before.

Review: What if the source can't be resolved, such as a module type
included in a `.resi`, which analysis does not register? Then the copy
stays a declaration, as before.

Fixes: #9323
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-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".

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