Skip to content

Commit 80d00ab

Browse files
committed
feat(rust): admit cross-crate workspace CALLS behind the fail-closed predicate
Land the first admission class of the per-class recovery plan (ISSUES.md root-cause section 6, docs/RUST_CODEGRAPH_TRUTH_PLAN.md): exact, source-site-matched ::-qualified calls whose callee the resolver routed uniquely into a declared Cargo workspace member. Admission boundary, argued from the predicate's inputs: - strategy "lsp_cross_crate" has exactly one emission site (internal/cbm/lsp/rust_lsp.c block DeusData#56), whose guards are the class guarantee: a parsed Cargo manifest, the call path head declared as a workspace member, and exactly one registered free function in that member matching the call tail; two candidates emit nothing (mem_matches < 2 cutoff). The callee QN is the registry entry's qualified_name, never a synthesized name. Name-guess and registry fallbacks emit other strategies and stay rejected; Rust never falls through to textual resolution (pass_calls.c returns before the registry for CBM_LANG_RUST). - The predicate re-derives the member linkage from its own inputs: the carrier's callee text must be ::-qualified with a non-empty head, and the resolved QN must pass through the ".<head>." segment (cbm_pipeline_qn_has_dotted_segment) — the same needle the resolver used — so a mis-joined resolution row for a different crate cannot claim the class. Same-named decoys in another member fail the segment check (demonstrated by the pinned test's crates/beta/src/local.rs decoys, which get zero edges). - The resolved callee must lie outside the caller's file module, keeping this class strictly cross-crate and disjoint from the plain class. - Floor shared with the plain class, now hoisted: real parsed call site (!requires_lsp_resolution), caller is this file's single-segment free function, and occurrence-exact source-site join (byte-span + origin). Semantic epoch moves with the class: 8 -> 9 in src/store/store.h and tests/semantic-epoch.expected in this same commit (Step 0y contract). docs/RUST_CODEGRAPH_TRUTH_PLAN.md gains the class in Supported behavior; the not-restored list narrows to import-mediated cross-file calls. tests/fixtures/scip_harness/expected.txt is deliberately unchanged: the harness corpus's only cross-crate call (beta total -> alpha add) is import-mediated (use alpha::add; bare add(1,2)), which never reaches the ::-gated resolver block, so the graph side of the join is identical. New-helper existence check (coding standards): codebase-memory search_graph query "dotted qualified name segment contains substring match", 15 hits inspected; contains_segment (internal/cbm/service_patterns.c:562) is '/'-separated and static to its module, qualified_suffix_match (src/pipeline/registry.c:887) is tail-anchored and static; neither expresses an interior dotted-segment match, so cbm_pipeline_qn_has_dotted_segment is added beside its only caller in lsp_resolve.h. Pinned by pipeline_rust_cargo_manifest_converges_across_routes (all three routes) and the two cargo-route mutation rows, which become live and KILLED with this class. The two issue-56 provenance tests (tests/test_parallel.c) pinned the pre-class refusal: even the correct .crate_a. candidate had to stay out while workspace provenance was untrusted. This class is exactly that trust landing, so they flip to positive exact-target controls alongside the retained decoy refusals (unlisted member, local shadow) and are renamed to state the new behavior: - parallel_rust_workspace_manifest_routes_call_to_declared_member_only - parallel_rust_local_shadow_loses_to_workspace_manifest_provenance Their executed discriminator is the pre-class run of this same tree, where desired_candidate was false on both (observed red before this commit); the decoy refusals stayed green throughout.
1 parent 405b60f commit 80d00ab

5 files changed

Lines changed: 84 additions & 31 deletions

File tree

‎docs/RUST_CODEGRAPH_TRUTH_PLAN.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Rust relationship accuracy: current state
22

3-
Semantic index version: **8**. The broader Rust accuracy objective remains unfinished.
3+
Semantic index version: **9**. The broader Rust accuracy objective remains unfinished.
44
The current supported subset and its verification are recorded in
55
[RUST_REPAIR_EVIDENCE.md](RUST_REPAIR_EVIDENCE.md). Commit history owns prior plans,
66
investigation transcripts, intermediate results and replay history.
@@ -18,17 +18,23 @@ investigation transcripts, intermediate results and replay history.
1818
- Both publication modes admit exact, source-site-matched bare calls between
1919
file-local free functions. Missing Rust semantic targets are terminal:
2020
project-prefix, leaf-name and generic registry fallbacks cannot invent an edge.
21+
- Both publication modes admit exact, source-site-matched `::`-qualified calls
22+
from file-local free functions to the unique free function inside the Cargo
23+
workspace member the source path names. Ambiguous member matches, undeclared
24+
heads and missing manifests emit nothing; import-mediated bare cross-crate
25+
calls remain unresolved.
2126
- Lexical imports and local value declarations prevent the tested shadowed names
2227
from binding to outer functions. Active glob scopes conservatively leave bare
2328
calls unresolved. The project-wide unique-short-name fallback is removed.
2429
- Live CALLS and derived TESTS are restored for this bounded subset. Current-epoch
2530
CALLS/TESTS survive both incremental restoration routes. IMPLEMENTS/OVERRIDE
2631
remain rejected.
27-
- Version 8 invalidates earlier semantic indexes. All three Rust partial-coverage
32+
- Version 9 invalidates earlier semantic indexes. All three Rust partial-coverage
2833
flags remain set. An omitted relationship is not proof that none exists.
2934

30-
Methods, cross-file calls, expanded calls and implementation relationships are not
31-
restored. Exact spans alone cannot validate an incorrectly inferred target.
35+
Methods, import-mediated cross-file calls, expanded calls and implementation
36+
relationships are not restored. Exact spans alone cannot validate an incorrectly
37+
inferred target.
3238

3339
## Remaining valuable work, in order
3440

‎src/pipeline/lsp_resolve.h‎

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,33 +291,80 @@ static inline bool cbm_pipeline_source_occurrence_eq(uint32_t lhs_start, uint32_
291291
cbm_pipeline_source_site_eq(lhs_start, lhs_end, rhs_start, rhs_end);
292292
}
293293

294-
/* Restore bare calls to exact file-local free functions. Method, crate and
295-
* expansion identities still need their separate repairs. */
294+
/* One interior dotted segment of `qn` equals seg[0..seg_len). The Rust
295+
* cross-crate resolver links a call's source crate head to the registered
296+
* definition through this same ".<member>." segment (rust_lsp.c); the
297+
* admission predicate re-derives that linkage from its own inputs so a
298+
* resolution row joined to a carrier naming a different crate cannot claim
299+
* the cross-crate class. */
300+
static inline bool cbm_pipeline_qn_has_dotted_segment(const char *qn, const char *seg,
301+
size_t seg_len) {
302+
if (!qn || !seg || seg_len == 0) {
303+
return false;
304+
}
305+
for (const char *p = strchr(qn, '.'); p; p = strchr(p + 1, '.')) {
306+
if (strncmp(p + 1, seg, seg_len) == 0 && p[1 + seg_len] == '.') {
307+
return true;
308+
}
309+
}
310+
return false;
311+
}
312+
313+
/* Rust CALLS admission. Floor for every class: a real parsed call site (never
314+
* a synthetic semantic candidate), whose caller is this file's single-segment
315+
* free function and whose resolution joined by exact source occurrence.
316+
*
317+
* Class "plain": bare calls to exact file-local free functions.
318+
*
319+
* Class "cross-crate": ::-qualified calls whose resolution the resolver
320+
* routed into a Cargo workspace member. The strategy string is written at
321+
* exactly one site (rust_lsp.c, block #56) whose guards are the class
322+
* guarantee: a parsed manifest, the path head declared as a workspace member,
323+
* and exactly one registered free function in that member matching the call
324+
* tail — ambiguity emits nothing. Name-guess and registry fallbacks emit
325+
* other strategies and stay rejected. The predicate re-derives the member
326+
* linkage (`.<head>.` in the resolved QN) and rejects file-local targets, so
327+
* a mis-joined row cannot enter through this class.
328+
*
329+
* Method, expansion and import-mediated identities still need their separate
330+
* repairs. */
296331
static inline bool cbm_pipeline_plain_call_admitted(CBMLanguage lang, const CBMCall *call,
297332
const CBMResolvedCall *resolved,
298333
const char *module_qn) {
299334
if (lang != CBM_LANG_RUST) {
300335
return true;
301336
}
302337
if (!call || !resolved || !module_qn || !resolved->callee_qn || !call->callee_name ||
303-
!call->enclosing_func_qn) {
338+
!call->enclosing_func_qn || !resolved->strategy || call->requires_lsp_resolution) {
304339
return false;
305340
}
306341
size_t module_len = strlen(module_qn);
307-
return !call->requires_lsp_resolution && resolved->strategy &&
308-
strncmp(call->enclosing_func_qn, module_qn, module_len) == 0 &&
309-
call->enclosing_func_qn[module_len] == '.' &&
310-
strchr(call->enclosing_func_qn + module_len + 1, '.') == NULL &&
311-
cbm_lsp_bare_segment(call->callee_name) == call->callee_name &&
312-
strncmp(resolved->callee_qn, module_qn, module_len) == 0 &&
313-
resolved->callee_qn[module_len] == '.' &&
314-
strchr(resolved->callee_qn + module_len + 1, '.') == NULL &&
315-
cbm_pipeline_source_site_present(call->site_start_byte, call->site_end_byte) &&
316-
cbm_pipeline_source_occurrence_eq(call->site_start_byte, call->site_end_byte,
317-
call->source_origin, resolved->site_start_byte,
318-
resolved->site_end_byte, resolved->source_origin) &&
319-
(strcmp(resolved->strategy, "lsp_direct") == 0 ||
320-
strcmp(resolved->strategy, "lsp_import_alias") == 0);
342+
bool caller_file_local = strncmp(call->enclosing_func_qn, module_qn, module_len) == 0 &&
343+
call->enclosing_func_qn[module_len] == '.' &&
344+
strchr(call->enclosing_func_qn + module_len + 1, '.') == NULL;
345+
if (!caller_file_local ||
346+
!cbm_pipeline_source_site_present(call->site_start_byte, call->site_end_byte) ||
347+
!cbm_pipeline_source_occurrence_eq(call->site_start_byte, call->site_end_byte,
348+
call->source_origin, resolved->site_start_byte,
349+
resolved->site_end_byte, resolved->source_origin)) {
350+
return false;
351+
}
352+
if (strcmp(resolved->strategy, "lsp_direct") == 0 ||
353+
strcmp(resolved->strategy, "lsp_import_alias") == 0) {
354+
return cbm_lsp_bare_segment(call->callee_name) == call->callee_name &&
355+
strncmp(resolved->callee_qn, module_qn, module_len) == 0 &&
356+
resolved->callee_qn[module_len] == '.' &&
357+
strchr(resolved->callee_qn + module_len + 1, '.') == NULL;
358+
}
359+
if (strcmp(resolved->strategy, "lsp_cross_crate") == 0) {
360+
const char *head_sep = strstr(call->callee_name, "::");
361+
bool callee_in_this_file = strncmp(resolved->callee_qn, module_qn, module_len) == 0 &&
362+
resolved->callee_qn[module_len] == '.';
363+
return head_sep != NULL && head_sep != call->callee_name && !callee_in_this_file &&
364+
cbm_pipeline_qn_has_dotted_segment(resolved->callee_qn, call->callee_name,
365+
(size_t)(head_sep - call->callee_name));
366+
}
367+
return false;
321368
}
322369

323370
/* Rank an invocation record for one parser carrier. Exact occurrence identity

‎src/store/store.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ typedef struct {
657657
CBM_RUST_SEMANTIC_GAP_IMPL_RELATIONSHIPS_UNAVAILABLE)
658658

659659
enum {
660-
CBM_RUST_SEMANTIC_GAPS_COVERAGE_VERSION = 8,
660+
CBM_RUST_SEMANTIC_GAPS_COVERAGE_VERSION = 9,
661661
};
662662

663663
/* Metadata describing how completely one index run recorded the best-effort

‎tests/semantic-epoch.expected‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8
1+
9

‎tests/test_parallel.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,36 +2851,36 @@ static cbm_gbuf_t *run_issue56_parallel_workspace(bool local_decoy) {
28512851
return gbuf;
28522852
}
28532853

2854-
TEST(parallel_rust_workspace_candidates_need_trusted_provenance_for_calls) {
2854+
TEST(parallel_rust_workspace_manifest_routes_call_to_declared_member_only) {
28552855
cbm_gbuf_t *gbuf = run_issue56_parallel_workspace(false);
28562856
ASSERT_NOT_NULL(gbuf);
28572857

28582858
const bool desired_candidate = callable_has_call_target_fragment(gbuf, "main.run", ".crate_a.");
28592859
const bool unlisted = callable_has_call_target_fragment(gbuf, "main.run", ".unlisted.");
2860-
if (desired_candidate || unlisted) {
2860+
if (!desired_candidate || unlisted) {
28612861
printf(" issue56 manifest diagnostic: desired=%d unlisted=%d\n", desired_candidate,
28622862
unlisted);
28632863
}
28642864
cbm_gbuf_free(gbuf);
28652865

2866-
ASSERT_FALSE(desired_candidate);
2866+
ASSERT_TRUE(desired_candidate);
28672867
ASSERT_FALSE(unlisted);
28682868
PASS();
28692869
}
28702870

2871-
TEST(parallel_rust_local_shadow_candidates_need_trusted_provenance_for_calls) {
2871+
TEST(parallel_rust_local_shadow_loses_to_workspace_manifest_provenance) {
28722872
cbm_gbuf_t *gbuf = run_issue56_parallel_workspace(true);
28732873
ASSERT_NOT_NULL(gbuf);
28742874

28752875
const bool desired_candidate = callable_has_call_target_fragment(gbuf, "main.run", ".crate_a.");
28762876
const bool wrong_local = callable_has_call_target_fragment(gbuf, "main.run", ".crate_b.");
2877-
if (desired_candidate || wrong_local) {
2877+
if (!desired_candidate || wrong_local) {
28782878
printf(" issue56 local-shadow diagnostic: desired=%d wrong_local=%d\n", desired_candidate,
28792879
wrong_local);
28802880
}
28812881
cbm_gbuf_free(gbuf);
28822882

2883-
ASSERT_FALSE(desired_candidate);
2883+
ASSERT_TRUE(desired_candidate);
28842884
ASSERT_FALSE(wrong_local);
28852885
PASS();
28862886
}
@@ -4509,8 +4509,8 @@ SUITE(parallel) {
45094509
RUN_TEST(parallel_tsx_import_namespace_exact_parity);
45104510
RUN_TEST(parallel_kotlin_external_protocol_does_not_use_project_class_method_tail);
45114511
RUN_TEST(parallel_kotlin_nonbinary_operator_carriers_reach_graph);
4512-
RUN_TEST(parallel_rust_workspace_candidates_need_trusted_provenance_for_calls);
4513-
RUN_TEST(parallel_rust_local_shadow_candidates_need_trusted_provenance_for_calls);
4512+
RUN_TEST(parallel_rust_workspace_manifest_routes_call_to_declared_member_only);
4513+
RUN_TEST(parallel_rust_local_shadow_loses_to_workspace_manifest_provenance);
45144514
RUN_TEST(rust_exact_calls_survive_without_name_fallback_in_both_modes);
45154515
RUN_TEST(parallel_rust_known_macro_does_not_fallback_to_local_function);
45164516
RUN_TEST(parallel_rust_proc_macros_are_decorates_and_usage_only);

0 commit comments

Comments
 (0)