Repository navigation
fix(go-lsp): follow a type alias declared in another file of the package - #2769
Conversation
`CBMRegisteredType.alias_of` is followed by the method lookup (go_lookup_field_or_method_depth), but only the per-file AST scan ever set it, and that scan only sees the file it walks. The def-driven registration that builds the cross-file registries had no alias target to copy, because neither CBMDefinition nor CBMLSPDef carried one. So a `type FeatureSet = bitmap` in one file was invisible to `reqs.Set()` in another. Since receiver-qualified method QNs (DeusData#1913), the call no longer resolves by name coincidence either, and it got no CALLS edge at all. The Go extractor now records the aliased type text of a `type A = B` (CBMDefinition.alias_target). pass_lsp_cross copies it into CBMLSPDef, and both cross-file registrars (cbm_run_go_lsp_cross and cbm_go_build_cross_registry) qualify it against the def's module and set alias_of. Only a bare identifier target is qualified, which is a type in the same package. A qualified, pointer, composite or generic target is left unset rather than guessed. A defined type `type A B` is a type_spec, so it never gets an alias target and keeps its own method set. The persisted LSP surface carries the new field ("al"), so SURFACE_CODEC_VERSION goes from 3 to 4: existing caches re-extract once, and an incremental run sees the same alias as a full one. The literal version-3 surfaces in the codec tests move to 4. Tests: golsp_crossfile_type_alias_method (+_prebuilt) check both registries, with a same-named decoy and a defined-type negative. pipeline_go_crossfile_type_alias_method (+_parallel) index the three-file package from the issue. Before the fix, Use had no CALLS edge to Set. Fixes DeusData#2033 Signed-off-by: Gaurav Dubey <gauravdubey0107@gmail.com>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thank you, Gaurav - this is exactly the fix #2033 asked for, carried through both cross-file registries, with identity aliases kept strictly apart from defined types. The red ci-ok on the previous run was an aggregation-timing hiccup in our CI (it read two jobs as still running a few seconds after they had finished green); all ten selected lanes, including your new go_lsp and pipeline tests, passed. Main has also changed two of the files you touch, so we merged current main into your branch (one signed-off merge commit, f8b2f36; your commit is unchanged) for a fresh run. Please pull before pushing again. We will merge once the checks are green. |
|
Thanks for the review and for merging main in. I'll pull f8b2f36 before pushing anything else to this branch. |
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thanks again, @gaurav0107. Several other pull requests landed on main this evening, including changes in files this one also touches, so we merged current main into your branch once more (one signed-off merge commit, a2feed8; your changes are untouched). That keeps the required checks honest against today's tree; we will merge once they are green. Please pull before pushing again. |
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thank you for your patience, @gaurav0107. CI went green on this branch, but tonight's merges on main touched tests/test_pipeline.c, which this pull request also changes, so that green no longer covered today's main. We merged current main into the branch once more (one merge commit, 1306c27; your changes are untouched) and will merge once the fresh checks are green. Please pull before pushing again. |
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
|
Thank you for your patience, @gaurav0107. CI went green on this branch, but this evening's merges on main touched files this pull request also changes, so that green no longer covered today's main. We merged current main into the branch once more (one merge commit, ba246da; your changes are untouched) and will merge once the fresh checks are green. Please pull before pushing again. |
|
Merged as 7b398de - thank you, @gaurav0107! The Go LSP now follows a type alias declared in another file of the same package, so calls through the alias resolve to the aliased type's methods. Thank you for the focused fix and for your patience through the branch refreshes. |
test_pipeline.c: kept the main version and re-applied this branch diff; its three Go init RUN_TESTs precede the DeusData#2769 alias tests. test_go_lsp.c: the two DeusData#2769 alias tests pass NULL for the new rel_path parameter. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
What does this PR do?
Fixes #2033. A Go identity alias declared in one file of a package is now followed when a method is called through it from another file.
alias_ofwas only set by the per-file AST scan ingo_lsp.c, and that scan only sees the file it walks. The def-driven registration that builds the cross-file registries had nothing to copy, because neitherCBMDefinitionnorCBMLSPDefcarried an alias target. With receiver-qualified method QNs (#1913), the issue's shape now drops the edge entirely. I reproduced it onmainwith a three-file package:On
main,Usehas a CALLS edge toNewFeatureSetand none toSet. On this branch it also hasUse -> fs.bitmap.Set, confidence 0.95. A same-package decoyother.Setgets no edge.Changes:
extract_defs.c: a Gotype_aliasdef records itstypefield text in the new tail fieldCBMDefinition.alias_target. A defined typetype A Bis atype_spec, so it never gets one and keeps its own method set.pass_lsp_cross.ccopies it into the newCBMLSPDef.alias_target.result_compact.cand the memory census inpipeline.ccover the new string.go_lsp.c: both cross-file registrars (cbm_run_go_lsp_crossandcbm_go_build_cross_registry) setrt.alias_ofthroughgo_alias_target_qn. Only a bare identifier target is qualified, as<def module>.<name>, which is a type in the same package. Apkg.T,*T, composite or generic target stays unset rather than guessed. The same-file scan is unchanged.lsp_surface.c: the persisted surface carries the field as"al", soSURFACE_CODEC_VERSIONgoes from 3 to 4. Existing caches re-extract once, and an incremental run sees the same alias as a full one. This follows the precedent of 36bce46. The literal version-3 surfaces in the codec tests move to 4.Something you may want to know: the resolved call is reported as
lsp_embed_dispatch, because the method's receiver (bitmap) differs from the variable's type (FeatureSet). A same-file alias gets the same label onmaintoday (I checked with a one-file fixture). I left that labelling alone to keep this PR to the issue.Out of scope: cross-package alias targets (
type A = other.B). Qualifying those needs the defining file's import map, which the def-driven registries don't have.Tests
golsp_crossfile_type_alias_methodandgolsp_crossfile_type_alias_method_prebuilt(tests/test_go_lsp.c) cover the per-file cross registry and the prebuilt one the parallel resolver shares. Each checks thatreqs.Setbinds exactlytest.main.bitmap.Setwith a typedlsp_*strategy despite a same-namedother.Set. A defined typeDefined(no alias target) must not bindbitmap.Set.pipeline_go_crossfile_type_alias_methodand_parallel(tests/test_pipeline.c, next topipeline_go_multi_return_receiver_is_typed) index the three-file package above. They expect exactly one CALLS edgeUse -> Setintofs/bitmap.gowith anlsp_strategy, and none into the decoy's file.Evidence
Machine: Amazon Linux 2023, x86_64, clang 15.0.7 (ASan+UBSan via the default
scripts/test.shflags).I also built the binary (
make -f Makefile.cbm cbm), indexed the fixture, then appended a line tofs/framework.goand indexed again. The second run takes the incremental path, where the alias comes from the persisted surface. Both runs returnUse -> fs.bitmap.Set (lsp_embed_dispatch, 0.95).Not verified locally
scripts/lint.sh --ci: cppcheck and clang-format-20 aren't installed here.git diff -U0 upstream/main..HEAD | clang-format-diff -p1(clang-format 15) is empty.scripts/test.shvenue run (about 2h on this machine). I ran only the suites listed above.Checklist
git commit -s):scripts/check-dco.sh upstream/main..HEADOKmake -f Makefile.cbm test): the suites listed above pass; the full venue run was not run locallymake -f Makefile.cbm lint-ci): not run locally (see above)🤖 Opened with Superhuman, an open-source contribution agent.