Skip to content

Commit d40f8e6

Browse files
committed
test(pipeline): generic Rust impl methods source their own calls (both resolvers)
Sequential and parallel pipeline twin of extract_rust_generic_impl_call_scope_matches_def: the calls in a type-generic and a lifetime-generic impl method are sourced from the method, not from the File node. Refs DeusData#763 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 09c4885 commit d40f8e6

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

‎tests/test_pipeline.c‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8757,6 +8757,79 @@ TEST(pipeline_go_rw_usage_never_cross_into_c) {
87578757
PASS();
87588758
}
87598759

8760+
/* F-R4 (#763, Rust): calls inside a method of a generic impl (`impl<T> Gen<T>`,
8761+
* `impl<'a> Life<'a>`) were sourced from the File node: the call scope kept the
8762+
* generic arguments the def side strips. Each method must be the source of its
8763+
* own call. pad_files > 0 forces the parallel resolver. */
8764+
static int rust_generic_impl_attribution_case(int pad_files) {
8765+
char tmp[256];
8766+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_gimpl_XXXXXX");
8767+
if (!cbm_mkdtemp(tmp)) {
8768+
FAIL("tmpdir");
8769+
}
8770+
write_temp_file(tmp, "Cargo.toml", "[package]\nname = \"fx\"\nversion = \"0.1.0\"\n");
8771+
write_temp_file(tmp, "src/lib.rs",
8772+
"pub struct Gen<T> { v: T }\n"
8773+
"impl<T> Gen<T> {\n"
8774+
" pub fn in_generic(&self) -> u32 { helper_a() }\n"
8775+
"}\n"
8776+
"pub struct Life<'a> { s: &'a str }\n"
8777+
"impl<'a> Life<'a> {\n"
8778+
" pub fn in_lifetime(&self) -> u32 { helper_b() }\n"
8779+
"}\n"
8780+
"pub fn helper_a() -> u32 { 1 }\n"
8781+
"pub fn helper_b() -> u32 { 2 }\n");
8782+
for (int i = 0; i < pad_files; i++) {
8783+
char name[64];
8784+
char body[128];
8785+
snprintf(name, sizeof(name), "src/filler%d.rs", i);
8786+
snprintf(body, sizeof(body), "pub fn filler%d() -> u32 {\n %d\n}\n", i, i);
8787+
write_temp_file(tmp, name, body);
8788+
}
8789+
8790+
char *saved = NULL;
8791+
if (pad_files > 0) {
8792+
char *old_workers = getenv("CBM_WORKERS");
8793+
saved = old_workers ? strdup(old_workers) : NULL;
8794+
cbm_setenv("CBM_WORKERS", "4", 1);
8795+
}
8796+
char db_path[512];
8797+
snprintf(db_path, sizeof(db_path), "%s/rust_gimpl.db", tmp);
8798+
cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
8799+
ASSERT_NOT_NULL(p);
8800+
ASSERT_EQ(cbm_pipeline_run(p), 0);
8801+
const char *project = cbm_pipeline_project_name(p);
8802+
cbm_store_t *s = cbm_store_open_path(db_path);
8803+
ASSERT_NOT_NULL(s);
8804+
8805+
ASSERT_TRUE(cross_file_call_exists(s, project, "in_generic", "helper_a"));
8806+
ASSERT_TRUE(cross_file_call_exists(s, project, "in_lifetime", "helper_b"));
8807+
/* ... and not from the file. */
8808+
ASSERT_FALSE(cross_file_call_exists(s, project, "lib.rs", "helper_a"));
8809+
ASSERT_FALSE(cross_file_call_exists(s, project, "lib.rs", "helper_b"));
8810+
8811+
cbm_store_close(s);
8812+
cbm_pipeline_free(p);
8813+
if (pad_files > 0) {
8814+
if (saved) {
8815+
cbm_setenv("CBM_WORKERS", saved, 1);
8816+
free(saved);
8817+
} else {
8818+
cbm_unsetenv("CBM_WORKERS");
8819+
}
8820+
}
8821+
th_rmtree(tmp);
8822+
PASS();
8823+
}
8824+
8825+
TEST(pipeline_rust_generic_impl_method_sources_its_calls) {
8826+
return rust_generic_impl_attribution_case(0);
8827+
}
8828+
8829+
TEST(pipeline_rust_generic_impl_method_sources_its_calls_parallel) {
8830+
return rust_generic_impl_attribution_case(52);
8831+
}
8832+
87608833
TEST(pipeline_go_rw_usage_never_cross_into_c_parallel) {
87618834
/* Parallel twin of the test above: USAGE and WRITES/READS each have a
87628835
* second, independent resolver in pass_parallel.c (resolve_file_usages /
@@ -23615,6 +23688,8 @@ SUITE(pipeline) {
2361523688
RUN_TEST(pipeline_html_embedded_member_call_stays_unbound);
2361623689
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c);
2361723690
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c_parallel);
23691+
RUN_TEST(pipeline_rust_generic_impl_method_sources_its_calls);
23692+
RUN_TEST(pipeline_rust_generic_impl_method_sources_its_calls_parallel);
2361823693
RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method);
2361923694
RUN_TEST(pipeline_rust_std_receiver_never_binds_project_method_parallel);
2362023695
RUN_TEST(pipeline_go_bare_ref_never_binds_field);

0 commit comments

Comments
 (0)