You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Symbol-form use of a prelude-closure module alongside c_import drops an unrelated root fn decl #754
Repro (fails on the CURRENT SEED v0.15.1 as well as post-#750 stage1 — pre-existing, latent until D29's import gate made explicit closure imports common):
test/spec/spec_ss16_ffi_and_c_import.w at commit 283d09e with use std.builtins.write added anywhere in the header: test_c_import_raw_pointer_calls_require_unsafe (an ordinary root fn, unique name) becomes undefined variable at its call site. with analyze shows ZERO facts for the fn — the declaration is gone from the merged pool, i.e. a frontend import-merge decl drop, not a Sema issue. A "large Copy type" warning also anchors at the wrong span (the fn's decl line), consistent with decl-index/bucket misalignment.
Facts established:
Module-form use std.builtins does NOT reproduce (the spec test now uses it as a workaround).
Symbol-form use std.builtins.write DOES, but only with this file's larger c_import cluster — a 2-c_import minimal (incl. the colliding fake-unistd write decl) passes, so it is scale/order-dependent in the phase-1/2 bucketing of Frontend.process_imports (after_prelude / user_start index ranges vs c_import-generated decls).
The seed reproduces byte-identically, so this predates the D29 batch.
Reduction note: with reduce --contains "undefined variable" drifts to trivially-undefined names; the predicate needs to require the source-echo line test_c_import_raw_pointer_calls_require_unsafe() in stderr as well.
Suspected area: Frontend.process_imports_frontend phase-2 symbol-form use handling (resolve_module_path_frontend on a 3-segment symbol path) re-parsing or re-bucketing against the pre-expanded prelude prefix, misaligning user_import_ordered/root_ordered so a root fn is classified into a tier whose shadow rules drop it (a misbucketed root fn is "shadowed" by its own entry in root_fn_names).
Cause (SemaDecl.impl_node_for_method_decl, the span-containment fallback): c_import expansion records synthesized decls under the importing file's id while their spans index the synthetic generated source. decls_share_source_file compared file ids only, so a generated C-type impl whose synthetic-space byte range happened to contain a root fn's real-file range adopted that fn as its method — owner became the C type, method_decl_base_symbol returned 0 (the dotted name was never interned), the effective fn name became symbol 0, and collect_fn_decl registered the signature under nothing. Offset-dependent, hence the one-use-line trigger and the seed reproducing.
Fix: decls_share_source_file returns false when the two decls' c_import origin flags differ — byte-range reasoning across the two coordinate spaces is meaningless. Generated impls still adopt generated fns (both flags set); the clause-group check inherits the same correction.
Verification: the ss16 symbol-form repro builds and runs; spec_ss16 restored to use std.builtins.write as a live pin; c_import behavior lanes (auto-constructor's generated-impl adoption included), shadow/gate fixtures all green. Same disease family as #753 (span-window reasoning across incompatible coordinate spaces); the remaining #753 tail still wants per-node file identity.
Activity
ehartford commentedon Aug 1, 2026
Root-caused to the exact lines and fixed.
Cause (
SemaDecl.impl_node_for_method_decl, the span-containment fallback): c_import expansion records synthesized decls under the importing file's id while their spans index the synthetic generated source.decls_share_source_filecompared file ids only, so a generated C-type impl whose synthetic-space byte range happened to contain a root fn's real-file range adopted that fn as its method — owner became the C type,method_decl_base_symbolreturned 0 (the dotted name was never interned), the effective fn name became symbol 0, andcollect_fn_declregistered the signature under nothing. Offset-dependent, hence the one-use-line trigger and the seed reproducing.Fix:
decls_share_source_filereturns false when the two decls' c_import origin flags differ — byte-range reasoning across the two coordinate spaces is meaningless. Generated impls still adopt generated fns (both flags set); the clause-group check inherits the same correction.Verification: the ss16 symbol-form repro builds and runs; spec_ss16 restored to
use std.builtins.writeas a live pin; c_import behavior lanes (auto-constructor's generated-impl adoption included), shadow/gate fixtures all green. Same disease family as #753 (span-window reasoning across incompatible coordinate spaces); the remaining #753 tail still wants per-node file identity.docs: handoff records #754 root-cause chain so far
sema: c_import-synthesized decls never share a source file with real …
docs: handoff records the #754 fix
docs: dedupe handoff next-steps; battery 4 required after the #754 se…
sema: stop pretty-name extraction from slicing the wrong source file
sema: method adoption and dump attribution require same-file spans (#756