Skip to content

Commit 7528ec0

Browse files
committed
test(pipeline): bind the Go selector guard on the parallel resolver
Review follow-up for DeusData#1907 (asks from the 2026-09-28 review): - pipeline_go_receiver_parallel_suppresses_weak_method_edge: parallel twin of pipeline_go_receiver_suppresses_weak_method_edge. The guard is wired into pass_parallel.c as well as pass_calls.c, but the four-file fixture only runs the sequential resolver, so the parallel hunk was bound by no test. The fixture is shared (write_go_receiver_fixture) and padded with 52 Go files past MIN_FILES_FOR_PARALLEL, with CBM_WORKERS=4, in the shape of the Python parallel twin. - registry.c: cbm_go_suppress_weak_method_match builds on the shared weak_short_name_strategy list and narrows it in two places only (field_type_hint kept, unique_name only when penalized). Behaviour is unchanged; weak_call_guards_share_one_drop_list now binds the Go guard to the shared list too. - test_extraction.c: the flag-exempt comment names the current flag set (Perl, Python, TS/JS/TSX and Go) and Rust as the exempt language. Refs DeusData#1906 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 285d21c commit 7528ec0

4 files changed

Lines changed: 97 additions & 19 deletions

File tree

‎src/pipeline/registry.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -750,19 +750,23 @@ bool cbm_suppress_weak_local_binding_call(bool enabled, bool callee_is_locally_b
750750

751751
bool cbm_go_suppress_weak_method_match(bool is_go, bool is_method, const char *strategy,
752752
double confidence) {
753-
if (!is_go || !is_method || !strategy || !strategy[0]) {
754-
return false;
755-
}
756753
/* Go analog of the TS/JS guard above, same failure class: a selector call
757754
* whose receiver the Go LSP could not type reaches the registry and a bare
758755
* short-name strategy binds it to an arbitrary same-named project symbol
759756
* (`f.Close()` on an os.File -> a project `Close`, suffix_match over 15
760-
* candidates). Unlike the TS/JS list, field_type_hint is KEPT: a Go struct
761-
* field carries a declared type, so the parallel resolver's field-type
762-
* hint is receiver-aware for Go (lrp_go_s8_field_type_hint), not a
763-
* heuristic. */
764-
if (strcmp(strategy, "suffix_match") == 0 || strcmp(strategy, "fuzzy") == 0) {
765-
return true;
757+
* candidates). Built on the shared drop-list so "weak" means one thing
758+
* for every guard; Go narrows it in two places only. */
759+
if (!is_go || !is_method || !weak_short_name_strategy(strategy)) {
760+
return false;
761+
}
762+
/* field_type_hint is KEPT for Go: a Go struct field carries a declared
763+
* type, so the parallel resolver's field-type hint is receiver-aware for
764+
* Go (lrp_go_s8_field_type_hint), not a heuristic. */
765+
if (strcmp(strategy, "field_type_hint") == 0) {
766+
return false;
767+
}
768+
if (strcmp(strategy, "unique_name") != 0) {
769+
return true; /* suffix_match, fuzzy */
766770
}
767771
/* unique_name is dropped only when PENALIZED: resolve_name_lookup scales
768772
* CONF_UNIQUE_NAME by DEFAULT_CONFIDENCE exactly when the lone candidate
@@ -772,7 +776,7 @@ bool cbm_go_suppress_weak_method_match(bool is_go, bool is_method, const char *s
772776
* file has no imports, e.g. a same-package call) and must be kept —
773777
* dropping it kills genuinely-typed lone-candidate calls that never
774778
* enter the field-type-hint upgrade (candidate_count == 1). */
775-
return strcmp(strategy, "unique_name") == 0 && confidence < CONF_UNIQUE_NAME;
779+
return confidence < CONF_UNIQUE_NAME;
776780
}
777781

778782
/* Import-binding counterpart of the parameter guard above (#2127). An import

‎tests/test_extraction.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6886,8 +6886,8 @@ TEST(extract_perl_method_call_flags_is_method) {
68866886
PASS();
68876887
}
68886888

6889-
/* Languages OUTSIDE the is_method flag set (only Perl and TS/JS/TSX set it) must
6890-
* be unaffected: a Go method call never sets is_method. */
6889+
/* Languages OUTSIDE the is_method flag set (Perl, Python, TS/JS/TSX and Go set
6890+
* it) must be unaffected: a Rust method call never sets is_method. */
68916891
TEST(extract_flag_exempt_method_call_not_flagged_is_method) {
68926892
/* Rust is flag-exempt: only Perl, Python, TS/JS and Go set is_method.
68936893
* Guards the blast radius of the receiver-aware flags for every other

‎tests/test_pipeline.c‎

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8650,13 +8650,11 @@ TEST(pipeline_html_embedded_member_call_stays_unbound) {
86508650
PASS();
86518651
}
86528652

8653-
TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
8654-
char tmp[256];
8655-
snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_XXXXXX");
8656-
if (!cbm_mkdtemp(tmp)) {
8657-
FAIL("tmpdir");
8658-
}
8659-
8653+
/* Fixture for the #1906 Go selector-guard probes (sequential and parallel
8654+
* twins). pad_files > 0 adds filler Go files to push the index over
8655+
* MIN_FILES_FOR_PARALLEL, because the guard is wired into both resolvers
8656+
* (pass_calls.c and pass_parallel.c) and each needs its own probe. */
8657+
static void write_go_receiver_fixture(const char *tmp, int pad_files) {
86608658
/* go.mod makes project imports resolvable — real Go repos always have one,
86618659
* and import reachability (the unique_name penalty) depends on it. */
86628660
write_temp_file(tmp, "go.mod", "module example.com/myapp\n\ngo 1.22\n");
@@ -8715,6 +8713,22 @@ TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
87158713
"func CallsLocal() int { return localHelper() }\n"
87168714
"\n"
87178715
"func UsesUtil() string { return util.Tag() }\n");
8716+
for (int i = 0; i < pad_files; i++) {
8717+
char name[64];
8718+
char body[128];
8719+
snprintf(name, sizeof(name), "filler/filler%d.go", i);
8720+
snprintf(body, sizeof(body), "package filler\n\nfunc Filler%d() int { return %d }\n", i, i);
8721+
write_temp_file(tmp, name, body);
8722+
}
8723+
}
8724+
8725+
TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
8726+
char tmp[256];
8727+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_XXXXXX");
8728+
if (!cbm_mkdtemp(tmp)) {
8729+
FAIL("tmpdir");
8730+
}
8731+
write_go_receiver_fixture(tmp, 0);
87188732

87198733
char db_path[512];
87208734
snprintf(db_path, sizeof(db_path), "%s/go_recv.db", tmp);
@@ -8743,6 +8757,55 @@ TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
87438757
PASS();
87448758
}
87458759

8760+
/* Parallel twin of the test above. The guard is wired into pass_parallel.c as
8761+
* well as pass_calls.c, but the four-file fixture only ever runs the
8762+
* sequential resolver, so the parallel hunk was bound by no test. Real
8763+
* repositories take the parallel path: >= MIN_FILES_FOR_PARALLEL (50) files
8764+
* plus CBM_WORKERS=4 force it, the shape of
8765+
* pipeline_python_receiver_parallel_suppresses_weak_method_edges. Same
8766+
* both-directions pin as the sequential test. */
8767+
TEST(pipeline_go_receiver_parallel_suppresses_weak_method_edge) {
8768+
char tmp[256];
8769+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_par_XXXXXX");
8770+
if (!cbm_mkdtemp(tmp)) {
8771+
FAIL("tmpdir");
8772+
}
8773+
write_go_receiver_fixture(tmp, 52);
8774+
8775+
char *old_workers = getenv("CBM_WORKERS");
8776+
char *saved = old_workers ? strdup(old_workers) : NULL;
8777+
cbm_setenv("CBM_WORKERS", "4", 1);
8778+
8779+
char db_path[512];
8780+
snprintf(db_path, sizeof(db_path), "%s/go_recv_par.db", tmp);
8781+
cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
8782+
ASSERT_NOT_NULL(p);
8783+
ASSERT_EQ(cbm_pipeline_run(p), 0);
8784+
const char *project = cbm_pipeline_project_name(p);
8785+
8786+
cbm_store_t *s = cbm_store_open_path(db_path);
8787+
ASSERT_NOT_NULL(s);
8788+
8789+
/* NEGATIVE: the stdlib *os.File Close must not bind the project method. */
8790+
ASSERT_FALSE(cross_file_call_exists(s, project, "FileLen", "Close"));
8791+
/* POSITIVE: typed same-package, bare local and import-qualified calls
8792+
* survive the parallel resolver too. */
8793+
ASSERT_TRUE(cross_file_call_exists(s, project, "Boot", "Close"));
8794+
ASSERT_TRUE(cross_file_call_exists(s, project, "CallsLocal", "localHelper"));
8795+
ASSERT_TRUE(cross_file_call_exists(s, project, "UsesUtil", "Tag"));
8796+
8797+
cbm_store_close(s);
8798+
cbm_pipeline_free(p);
8799+
if (saved) {
8800+
cbm_setenv("CBM_WORKERS", saved, 1);
8801+
free(saved);
8802+
} else {
8803+
cbm_unsetenv("CBM_WORKERS");
8804+
}
8805+
th_rmtree(tmp);
8806+
PASS();
8807+
}
8808+
87468809
/* Fixture for the #1928 cross-language reference-guard probes (sequential and
87478810
* parallel twins). pad_files > 0 adds filler files to push the index over the
87488811
* parallel-pipeline threshold, since USAGE/WRITES/READS have one resolver per
@@ -23707,6 +23770,7 @@ SUITE(pipeline) {
2370723770
RUN_TEST(pipeline_python_receiver_keeps_specific_unique_name_member_call);
2370823771
RUN_TEST(pipeline_html_embedded_member_call_stays_unbound);
2370923772
RUN_TEST(pipeline_go_receiver_suppresses_weak_method_edge);
23773+
RUN_TEST(pipeline_go_receiver_parallel_suppresses_weak_method_edge);
2371023774
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c);
2371123775
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c_parallel);
2371223776
RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method);

‎tests/test_registry.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,16 @@ TEST(weak_call_guards_share_one_drop_list) {
16731673
strategies[i], member, binding);
16741674
}
16751675
ASSERT_EQ(member, binding);
1676+
/* The Go selector guard builds on the same list and narrows it in
1677+
* exactly one place at a penalized confidence (0.75 * 0.5): it keeps
1678+
* field_type_hint. Any other drift from the shared list fails here. */
1679+
bool go = cbm_go_suppress_weak_method_match(true, true, strategies[i], 0.375);
1680+
bool go_expected = member && strcmp(strategies[i], "field_type_hint") != 0;
1681+
if (go != go_expected) {
1682+
printf(" Go drop-list divergence on strategy \"%s\": go=%d expected=%d\n",
1683+
strategies[i], go, go_expected);
1684+
}
1685+
ASSERT_EQ(go, go_expected);
16761686
}
16771687
PASS();
16781688
}

0 commit comments

Comments
 (0)