Rust: field-receiver method calls falling to the registry's name fallback bind an arbitrary same-named method (trait stub wins; Session.push_daily shows 0 callers)
Summary
For Rust, a method call through a field receiver whose type the LSP layer cannot infer never produced an LSP row, and the textual registry fallback then resolved by short name only, binding the call to whichever same-named method ranked/sorted first. In a real workspace this bound entry.session.push_daily (crates/spine_ffi/src/store_ffi.rs:120) to the trait-declaration stub Analytic.push_daily instead of Session.push_daily, so trace_call_path reported 0 callers for Session.push_daily while the stub gained phantom callers, and filters.DailyStore.push showed in-degree 0.
Demo (a real workspace, v0.11.0 fast index)
trace_call_path(inbound) on<project>.crates.spine.src.session.Session.push_daily→ 0 callers; the absorber iscrates.spine.src.analytic.Analytic.push_daily(in=9..12), swallowing every field-receiver call site:crates/spine_ffi/src/store_ffi.rs:120entry.session.push_daily(conf 0.09, suffix_match, 9 candidates — no import rescue)crates/spine_ffi/src/lib.rs:553entry.session.push_daily(0.18 — rescued only because that file importsspine::session::Session; import reachability beats the tie)crates/nautilus_ib/src/host.rs:273-274andcrates/nautilus_ib/src/restart.rs:390self.session.push_daily- four
r.strategy_mut().push_dailysites incrates/spine/tests/registry_daily.rs
crates/spine_data::nyse::is_session(called atstore_ffi.rs:162byprior_session_day) showed only Python callers; the Rust caller was missing.crates/spine/src/filters.rsDailyStore.push: in_degree 0 (its callers'self.bank.daily.pushchains unresolvable cross-file).- Same-file field chains (
self.bank.daily.pushatfilters.rs:1391/1492) DO resolve vialsp_method_dispatch— isolating the gap to cross-file fields + receiver typing.
Root cause chain
- The receiver is untypable: (a) the Tier-2 shared Rust registry never materializes
field_defs(pxc_fold_struct_fieldsruns for Go/Python/C/C++ only, andrust_populate_cross_registrycopiesfield_defswithout reading it), and (b) std-container chains (HashMap::get_mut→Some(entry)match arms) are not modeled.rust_eval_expr_typereturns unknown →rust_emit_unresolved_call(..., "unknown_receiver_type", 0.0). - The unresolved row dies at
CBM_LSP_CONFIDENCE_FLOOR(0.6); the textual registry resolvessimple_name("entry.session.push_daily") == "push_daily"over the by-name bucket (9 candidates here). - Decisive stage —
resolve_multi_with_imports'fcount == 1early return:is_import_reachable(bidirectional substring over the file's import-map values) matches exactly one candidate — the trait stub, becauseuse alpha::{…}placed its full QN in the import map — returning it immediately at penalty-by-arr->count(0.55), never consulting the receiver evidence. - When NO candidate is import-reachable (store_ffi.rs imports
spine::filtersbut notspine::session), the no-filter fallback ranks by test-penalty + longest common dotted prefix and breaks ties purely lexicographically (candidate_outranks_on_tie's finalstrcmp) —analyticsorts beforesession, so the stub still wins. receiver_chain_admitshard-guards only uppercase roots ("names a type"); lowercase value roots pass unconditionally, so nothing stops the mis-bind.
Fix (attached patch, 5 files)
src/pipeline/pass_lsp_cross.c— fold Rust "Struct" fields like Go's (pxc_fold_struct_fields(..., "Struct")forCBM_LANG_RUST); the extractor already emits flatFieldCBMDefinitions withparent_class/return_typefor Rust.internal/cbm/lsp/rust_lsp.c—rust_populate_cross_registrymaterializesfield_defsintofield_names/field_types(types are registered first, so field-type texts resolve cross-module), with a short-name probe fallback;- new
rust_short_probe_type— the unique registered type with QN suffix.<name>, via the registry's owncbm_registry_types_by_short_name_chainiterator (bucketed post-finalize, full-scan within an unfinalized overlay, chain-walked); used when the resolved form of a baretype_identifieris not registered (per-file memo ≤48 names, arena-backed, zeroed by init). This liftsentry: &mut Entrythrough braceduseimports tolsp_method_dispatch(0.95).
internal/cbm/lsp/rust_lsp.h— probe memo fields +RustProbeEntry/RUST_PROBE_MEMO_MAX.internal/cbm/lsp/type_registry.c— harden four pre-finalize linear scans (lookup_type_selfno-bucket path,lookup_func_selftail scan, two overload-match scanners) with the samequalified_name != NULLguard their post-finalize bucket paths already carry. Found while landing the field materialization: a populate-timecbm_registry_lookup_typeon a stdlib-seededNULL-qualified_nametype crashed (0xC0000005, 5/5 deterministic).src/pipeline/registry.c— two changes:- the
fcount == 1early return now consults the receiver-field hint: when the import-reachable candidate is not the one whose type segment matches the receiver's field, and exactly one Rust Method candidate is, that candidate wins at the halved no-filter confidence (0.28 at count 3). Rust-gated via the by-namelang_flags; cross-language picks still die in the name-guess veto; - the no-filter and multi paths get the same hint as a tiebreak ahead of the lexicographic fallback (
receiver_field_hint+rust_hint_matches_type, threaded throughbest_by_import_distance/resolve_multi_with_imports; the fuzzy defensive path passesNULLand is unchanged). A tiebreak among equal evidence — never a hard admit/refuse.
- the
Acceptance (verified in this session, both a 3-file repro workspace and the real workspace's crates/ tree on a fast index)
- Repro: all 4 field-receiver sites →
Session.push_daily(lsp_method_dispatchfor typed params; hint-suffix_match0.28 for theget_mutchain);AnalyticV.push_daily(stub) in=0 (was 4). - Real crates tree:
trace_call_pathonsession.Session.push_daily= 7 caller functions includingdaily_from_store_at(store_ffi.rs:120 →Session.push_daily0.09) and the nautilus_ib sites;prior_session_day → spine_data.src.nyse.is_session=lsp_short_name_unique;DailyStore.pushin-degree 190 (was 0 — the typed fields unlocked the test suites'bank.daily.pushchains); controls unchanged (spine_prior_session_day → prior_session_day=lsp_direct;ladder_for_day → filters.DailyStore.prior=unique_name→lsp_method_dispatch).
Patch
https://gist.github.com/vinay-veerappa/43fb5f46abd3f85d8c95a25bc14f2c49 (applies to 4d9592b5; a v0.11.0 backport variant at https://gist.github.com/vinay-veerappa/5321c0967424c9674416c2ecf79396d7)
Residuals intentionally out of scope: chained method-call receivers (r.strategy_mut().push_daily) still have no hint (the last segment is a method name — needs std-container/Option receiver modeling); dyn-trait-object calls still correctly reach the stub via the other strategies.
Thank you, @vinay-veerappa — this is an unusually thorough report. You traced the whole chain, from the untypable field receiver through the CBM_LSP_CONFIDENCE_FLOOR drop to the fcount == 1 early return and the lexicographic tie-break. You also measured the effect on a real workspace before and after, and that is exactly the evidence we need. We checked the diagnosis against current main and it holds:
pass_lsp_cross.cfolds struct fields only for Go and C/C++, although Rust structs carry the sameStructlabel;rust_populate_cross_registrynever readsfield_defs, so only same-file field chains can be typed;resolve_multi_with_importsreturns the single import-reachable candidate without consulting the receiver, and the final tie-break is lexicographic.
Would you be willing to open this as a pull request? We would much rather land it under your name than re-type it from a gist: a PR keeps your authorship and credit, and it runs CI and the DCO check. It also lets us review the exact diff line by line (we do not apply patches from gists directly). Some notes up front, to save you a round trip:
- Two PRs if possible. The LSP-side part is (a) folding Rust struct fields, (b) materialising
field_defsin the shared Rust registry, and (c) thequalified_name != NULLhardening intype_registry.c. It is self-contained and is the part we would like to land first. Theregistry.creceiver-field hint touches the resolver that every language shares, so we want to measure it on its own across our Rust corpus once the LSP side is in. - Tests on both resolver paths. Please cover the sequential resolver and a parallel twin padded past 50 files (the Rust shared registry is built only on the parallel path). Pin both directions:
Session.push_dailygains the field-receiver caller, and the trait stub does not. - Determinism. Any tie-break has to stay a pure function of the candidate set. The current lexicographic last step exists to keep graphs byte-identical across runs.
- Every commit needs a sign-off (
git commit -s).
If you would rather not open a PR, that is completely fine — just say so. We will then carry the change ourselves with credit to you for the diagnosis and the patch. Either way, thank you for the careful work.
Both halves are up, as separate PRs, because they touch disjoint files and each is green on main alone:
-
#2770 — LSP side. Folds the extractor's flat
Fielddefinitions into the owning RustStruct(the fold ran for Go/C/C++ but not Rust, so the Tier-2 registry had zero Rust fields), materialises the foldedfield_defsinto registered types on both the per-file and shared registry, adds a short-name probe for cross-module type spellings (use alpha::{Entry, Session};produced a crate-rooted QN no registry entry matched), and NULL-guardsqualified_nameon the two lookup paths that now run against partially built registries. Evidence:rust_lsp525, a newrust_field_receiversuite over a 62-file fixture indexed both sequentially and in parallel (pastMIN_FILES_FOR_PARALLEL) asserting the inherent method gains the caller, the trait stub does not, and the two graphs are byte-identical, pluspipeline412. -
#2771 — resolver side. The receiver-field tie-break you identified, including the
fcount == 1early return: it now overrides only when exactly one callable Rust candidate matches the field, at the no-filter confidence (0.275 at two candidates), so the import verdict is overridden rather than confirmed. Evidence:registry110.
Each new test set was reverse-checked rather than merely passing: reverting #2770's three source changes fails 2 of its 3 LSP tests and the pipeline test (the control test correctly stays green); reverting #2771's registry.c fails exactly its three hint tests while both controls pass.
Two things worth your judgement:
- #2770's
type_registry.cguards are hardening without a dedicated test. A registered func carrying a NULLqualified_nameis not constructible through the public API, so I did not invent one to pin it — say the word if you want that covered via a test seam. - Merge order does not matter (disjoint files, both green alone). #2770 carries
Fixes, #2771Part of, so the issue closes when the LSP half lands; easy to swap if you would rather it close on both.
One environment note, in case the Windows lane surprises anyone: on MSYS2 UCRT64 _msize compiles to a __imp__msize thunk, so -Wl,--wrap=_msize never redirects and mem_core.c must be built with -DCBM_BIND_TS_ALLOCATOR=1 (the production define) for any local test binary to get past the first arena test. It looks exactly like heap corruption in unrelated tests. Not a source issue and CI is unaffected, but it cost me an hour and may cost the next person one too.
Thank you for opening #2770 and #2771 separately and documenting the reverse checks and Windows build note. The test-seam question and issue-closing boundary need maintainer review; no further reproduction is needed from you now. Sorry for the delay—I’ll follow up soon.