-
Notifications
You must be signed in to change notification settings - Fork 473
Fix stdlib alias go-to-definition #8004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Codex Bot <codex@example.com>
| addValueReference Hooks.res:10:29 --> Hooks.res:4:12 | ||
| DeadOptionalArgs.addReferences Stdlib.Int.toString called with optional argNames: argNamesMaybe: Hooks.res:10:62 | ||
| addValueReference Hooks.res:10:75 --> Hooks.res:5:7 | ||
| addValueReference Hooks.res:10:62 --> Stdlib_Int.resi:205:0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something in the right direction is happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@send
external toString: (int, ~radix: int=?) => string = "toString"
Hmm, |
No |
Or at least, changing that does not solve the problem. |
|
Not sure I get what you mean by "the example in the PR which does not involve stdlib access at all". But if I remove the |
|
Let me remove all of this crap. |
|
Ehm, is the fix here then to do what @cknitt said? |
The question is: what is the problem |
@cknitt try this example: Console.log("Hello, world!")
let ff = Ok(1)
let x = []->Array.at(1)
let y = []->Array.ignore
For me, go to definition works for |

Overview
fallbackLocFromSourcehelper inanalysis/src/References.ml(lines 302-347) that scans the relevant.resfile with a regexp when the location stored in the cmt is ghost or points at an interface stub.tests/analysis_tests/tests/src/Definition.respass.Why the regexp fallback is a hack
We are bypassing semantic data:
The heuristic only knows about
letandtype:let, it assumes the name immediately follows the keyword and accepts at most an optionalrec. Patterns such as destructuring, attribute annotations, or inline comments break the match.It assumes the runtime is available as source:
.cmi+.cmjartifacts without an accessible.ressnapshot. In those environmentsFiles.readFilereturnsNone, so we fall straight back to a ghost location.Concurrency and perf concerns:
It is brittle with formatting details:
runtime/sources.Direction for a proper implementation
Make the build preserve definition locations
.cmiproduced byruntime/Makefiledrops location spans even when-keep-locsis threaded through the CLI.runtime/dune, the rescript bootstrap pipeline) to confirm whether-bin-annotor any stripping step erases locations duringrescriptto.cmj/.cmicompilation..cmt[cmi]files already contain correctLocation.tentries and stop relying on downstream heuristics.Extend the analysis format to ship explicit aliases
ProcessCmtlayer to emit synthetic source spans for alias definitions during extraction time. We already walkDeclared.trecords; we could rehydrate the location from the original AST before desugaring.Cache and index runtime metadata
modulePath → locationtuples baked into the analysis bundle. This can be generated once during packaging and read by the server in O(1) at runtime, avoiding regex scans entirely.Treat module aliases separately
resolveModuleReferenceso that when we hit aGlobalMod, we can surface the alias site together with the resolved file and stamp. That preserves user expectations (“go to definition shows me the implementation”) while staying within typed data.Testing and regression coverage
-keep-locs,-bin-annot) inruntime/README.mdorMakefilecomments so future maintainers do not unknowingly strip locs.Extremely detailed change log for the PR
.cmilacks location data even when the compiler is invoked with-keep-locs.analysis/src/References.mlisGhostLocandfallbackLocFromSource. The latter compiles a regexp based on the tip (onlylet/type) and scans the runtime source file to synthesize a non-ghostLocation.t.resolveModuleDefinitionto return the alias site when resolving toGlobalMod, preventing(0, 0)results forStdlibmodules.definitionto invoke the fallback whenever the best location is ghost or points at an interface.tests/analysis_tests/tests/src/Definition.resnow contains aStdlibAliasmodule aliasingStdlib.List.tests/analysis_tests/tests/src/expected/Definition.res.txtasserts thatStdlibAlias.List.mapresolves to the stdlib implementation span instead of(0, 0).tests/analysis_tests/tests-reanalyze/deadcode/expected/deadcode.txtgained multipleaddValueReference … --> Pervasives.res/Js.res/etc.lines, confirming the alias resolution now attaches real stdlib locations.Proposed follow-up work
libtarget and dune rules)..cmito ensure we never regress on location fidelity again.