Semantic Diff

#9331 Fix editor references for members brought in by include

1 commit

0b2246c4185d068520d3708f84cab8c73ea5f7d7..pr-9331

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

Treat included members as copies of their original declarations in editor 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.

modifiedReferences include

// Lib.resmodule type T = {  type t}module Make = (X: T) => {  type shape = Dot | Box(X.t)} // Main.resinclude Lib.Make({  type t = int})let v0 = 0let v1 = 1let v2 = 2module type T = {  type t}module F = (X: T) => {  let fv = 1}include F({  type t = int})let u = fv // Other.reslet w = Main.v0 + Main.v1
text
Before line:column, from 0
After
v0 in Main Main 3:4, Main 0:-1, Main 3:4fv in F Main 10:6v0 in Main Main 3:4, Other 0:13fv in F Main 10:6, Main 15:8fv after include Main 10:6, Main 15:8fv after include Main 10:6, Main 15:8

modifiedReferences constructor of an included type

// Main.res, with Lib.res as aboveinclude Lib.Make({  type t = int})let v0 = 0let v1 = 1let dot = Dotlet box = Box(1)
text
Before line:column, from 0
After
Dot in Main Main 3:4, Main 0:-1, Main 3:4, Main 5:10definition of Box nullDot in Main Main 5:10, Lib 4:15definition 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.