Skip to content

Stack #1969 bottom — A module's imports are not transitive (§18.1, §18.2); 18 sources import what they use (#1955) - #1966

Merged
ehartford merged 4 commits into
mainfrom
fix-1955
Oct 2, 2026
Merged

ehartford merged 4 commits into
mainfrom
fix-1955

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1955. Supersedes #1957 (its commit is included).

Root cause (lldb on stage1): Sema.module_visible_no_prelude (Sema.w ~3992–4035) followed every module's import edges, so an importer saw whatever its imports imported; its sibling module_is_visible_from_current already stops at user modules. The named_tid fallback the issue named is not the leak: a breakpoint across check src/main.w (148k stops) and rt/rt_core.w fires only for scoped bindings (Self, generic params), which are inserted into named_types directly with no candidate record; removing it breaks impl str: bodies. Renamed scoped_type_binding with a comment.

Fix: the walk continues only from the start module, through std-tier modules (§18.2 tier 5), and inside a bundle corpus (D39 §3.4) — the same rule as the sibling. Fixture err_1955_import_gated_name_not_transitive.w: ok in both body orders before, §18.1 error in both after; sema-order-check 0 of 1608. Fallout swept over 4,228 roots with tools/insert_std_uses.w: 15 files (+3 from #1957) gained an explicit import; build.w, lib/std/build.w, tools, examples, UAT: none. Gate green (54 targets).

Caveat: the win10 check src\main.w vs check W:/… disagreement is path spelling, not body order (seven shapes agree in both orders on macOS); likely the strict path-key branch at ~3992–3995 — unverified on win10.

Eric Hartford added 3 commits October 2, 2026 10:13
…1955)

src/main.w, src/CodegenDispatch.w and src/compiler/Frontend.w use
StringBuilder with no import. They compile only through the order-dependent
leak #1955 describes (a bare `use compiler.Link` exposes Link's own
`use std.string.StringBuilder` to the importer when Link's bodies are
checked first). On win10 the leak does not happen for the backslash
spelling of the path:

    > out\bootstrap\bin\with-stage1.exe check src\main.w
    error: 'StringBuilder' requires an explicit import (§18.1); add: use std.string.StringBuilder
     --> src\main.w:547:15
    > out\bootstrap\bin\with-stage1.exe check W:/verify-2/src/main.w
    ok

The explicit import is what §18.1 requires; the leak itself is #1955.
`module_visible_no_prelude` followed every module's import edges, so a
bare `use compiler.Link` let Link's `use std.string.StringBuilder`
resolve `StringBuilder` in the importer with no import of its own.
lldb on `check leak.w` (stage1, fix-1955 tree): the walk for
`noprelude|leak.w-><embedded-std>/std/string.w` pushed edges at
Sema.w:4035 from current = 2 (leakmod/helper.w: neither the start
module nor std) and returned 1 at Sema.w:4012 into
decl_visible_from_current_gated (Sema.w:3903) from
lookup_named_type_filtered (Sema.w:4293). The walk now continues only
from the start module, through the std tier (§18.2 tier 5), and inside
a bundle corpus (D39 §3.4), as module_is_visible_from_current already
does.

The issue named the `named_tid` return at the end of
lookup_named_type_filtered. It is not the leak: lldb over
`check src/main.w` (148k stops) and `check rt/rt_core.w` (38k calls)
takes it only for sym 42, `Self`, with saw_recorded = 0, and deleting
it made the stage1 compiler reject rt/rt_core.w (`impl str:` bodies
saw `&<error>`). It is the scoped-binding tier: `Self` and generic
type parameters are written straight into `named_types` (SemaCheck.w
bind/restore of syms.self_type and tp_sym, SemaDecl.w, ComptimeEval.w,
MirLower.w) with no candidate record, so "a tid no candidate carries"
is exactly a scoped binding and never an unimported declaration. Named
scoped_type_binding and documented; its inputs are arguments so -O1
keeps them readable in lldb.

Fixture: err_1955_import_gated_name_not_transitive.w with
lib/issue1955/uses_string_builder.w; `ok` on the unfixed stage1 in
both body orders, red in both after the fix (sema-order-check covers
it both ways).
With the import walk closed, every root in the tree was checked with
the fixed stage1 and the unfixed compiler; the §18.1 diagnostics that
appeared only with the fix were applied by tools/insert_std_uses.w
from the compiler's own `; add: use M.N` contract, looping until
`check src/main.w` is clean: HashMap in Codegen, CodegenTraits,
Analysis, AnalysisResolution, Lsp, compiler/Compilation and the
issue61_queries orchestrator; StringBuilder in two c_import behavior
tests; int_to_string in six d_acceptance tests. build.w,
lib/std/build.w, tools/*.w, examples/ and uat/fixtures needed none.
@ehartford
ehartford added this pull request to stack #1969 October 2, 2026 18:53
@ehartford ehartford changed the title A module's imports are not transitive: visibility walks stop at user modules (§18.1, §18.2); 18 sources import what they use (#1955) Stack #1969 bottom — A module's imports are not transitive (§18.1, §18.2); 18 sources import what they use (#1955) Oct 2, 2026
…1955)

native-phase-tests ran this root only in the battery, after the sweep: it
reached print_i32 through compiler.Frontend's imports, which §18.1 no
longer leaks. The same fix the sweep applied everywhere.
@ehartford
ehartford removed this pull request from stack #1969 October 2, 2026 22:15
@ehartford
ehartford added this pull request to stack #1972 October 2, 2026 22:15
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on stack top 7bdd704 (seed-driven, with run tools/battery.w, stack #1972 = #1966 → #1956 → #1961 → #1968 → #1959 → #1971 → #1970, on main 30f89aa): gate rc=0 wall=489s, battery-checks rc=0 wall=379s — fixpoint, drop and move audits, every corpus. Earlier reds on this stack were (a) #1239/#1955 fallout in fixtures the sweeps did not compile, fixed in-layer and in #1970, and (b) a stage2≠stage3 'self-miscompile' that turned out to be cross-worktree contamination through a shared out/gen symlink, root-caused with lldb and guarded in #1971; the bisect-reverted commit was innocent and is restored. Run from a worktree with its own out/gen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant