Skip to content

Sema cluster B: #1476 #1588 #1590 #1499 #1520 #1609 #1561 #1530 - #1716

Merged
ehartford merged 34 commits into
mainfrom
sema-cluster-b
Sep 26, 2026
Merged

ehartford merged 34 commits into
mainfrom
sema-cluster-b

Conversation

@ehartford

@ehartford ehartford commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Nine issues, one commit each; each names the root cause and pins it with a test. No battery run yet — draft until it is posted.

Skipped: #1473 (returned-view origins need a pre-body summary / fixpoint across declaration order — its own isolated batch) and #1221 (c_import-vs-module name collisions reported only at an ambiguous use needs a ruling on §18.2's wording).

Verified on a stage1 of this branch: each new test, the let-else/field-view/move/privacy/global samples of test/behavior and test/compile_errors, with check of src/main.w, build.w, lib/std/build.w, rt/rt_core.w.

@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery on 2a5ba41: build rc=1 at stage2 (stage1 enforces #1520 privacy on the compiler's own sources: ~9000 private-symbol errors; #1530's field-view check rejects sibling-field mutation in Lexer.w; 152 'missing return'). Repair in progress; stays draft.

@ehartford

Copy link
Copy Markdown
Contributor Author

Battery on c1333e0: build and :fixpoint green; :test red at reseed-check-build-w — the release binary reports 'use of moved value' at build.w:2478/2494 on a const str global passed to a borrowing &str fn inside a consuming method argument (#1588 check regression; §9.1c). Repair in progress; stays draft.

@ehartford

Copy link
Copy Markdown
Contributor Author

Battery on f963783: build and :fixpoint green; :test red on 4 behavior tests (behav_std_compiler_project_info, behav_mut_recv_disjoint_args, behav_c_facade_buffer_elements, behav_rt_in_unit_check_lane) and 1 phase test (dump_mir_str_field_concat_saved_alias_copy pins the pre-D27 saved-alias copy; becomes an err test per §3.8). Repair in progress; stays draft.

@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery green on c663e9d (host darwin-aarch64, seed per seed.lock):

sema-b build  rc=0
sema-b build :fixpoint rc=0
sema-b build :test rc=0
sema-b build :test-green rc=0
sema-b build :last-green rc=0
sema-b build :user-programs-safe rc=0

Stays DRAFT pending Eric's ruling on commit c663e9d: examples/nebula and examples/service used non-pub declarations across their own modules (accepted only by the #1520 entry-directory waiver) and one D32 field move; spec §18.3 says no pub = module-private. The example edits land only if the examples, not the compiler, were the non-conforming side.

Eric Hartford added 23 commits September 26, 2026 12:26
…mes (#1476)

check_let_else bound the pattern's names into the enclosing scope with
check_pattern and only then checked the else body, so the body resolved a
name that does not exist on its path (`else: return v.len()`); `with check`
said ok and MIR lowering failed. The else branch runs only when the pattern
did not match, so it is checked first, before anything is bound (§9.7).

Fixes #1476
…ee-call path does (#1588)

propagate_method_call_param_effects recorded the consume site for a plain
non-Copy argument bound to an owned parameter but never marked the binding
moved — the #714 mark landed only in check_call's free-function loop. So
`T.make(p)` and `x.m(p)` transferred `p` in MIR while Sema still held it
live, and a later `{p}` compiled and read the moved-from str.

Fixes #1588
…ss, and skips <c_import> translations (#1590)

validate_global_data_race_accesses runs after every body and emitted the
warning through emit_warning, which reads local_file_id — whatever file was
checked last (the root, or a rendered `<facade …>` file) — at the access
node's offsets, an empty line of the wrong file. The pass already keeps
each access's file id (global_race_access_files, as the error path uses);
the warning now carries that span. A `<c_import …>` translation is not a
user lint source: nobody can edit the `unsafe` blocks the translator wrote.

Fixes #1590
…ever truncated to the repr (#1499)

gen_disc_enum_from_int_val narrowed the argument to the enum's repr with
coerce_int before the switch, so an integer outside the repr's range that
shared low bits with a discriminant matched it: Tiny.from_int(456) was
Some(Hi = 200), K.from_int(2^32 + 1) was Some(A), Tiny.from_int(-56) was
Some(Hi). The switch now runs at i64 (or the argument's own wider type),
the argument extended by its own signedness (mir_operand_sema_type) and
each discriminant by the repr's (a new per-enum disc_enum_repr_unsigned
row), so an out-of-range value reaches the None default (§4.4a).

Fixes #1499
…1520)

decl_visible_from_current waived §18.3 whenever both the current and the
target module path lay under a `src/`, `build/`, `rt/` or `out/gen/`
directory (sema_paths_share_internal_implementation_boundary) — a guess at
"the compiler's own tree" from the directory name. A user project laid out
as `src/a.w`, `src/b.w` therefore had privacy only when checked from inside
`src/` (`check p1.w` rejected the private type, `check src/p1.w` and an
absolute path accepted it), and a module saw another module's private C
declarations the same way. The waiver is gone; the std tier keeps reading
its own private declarations (one implementation, D39 corpora). The
compiler's cross-module types that the waiver had covered are declared
`pub`, which is what they are.

Fixes #1520
…#1609)

The generic call paths (check_call with sig_idx < 0, check_method_call_parts
for a generic method) bind the type parameters from every argument at once
and gave a bare fn argument no expected type, so §12.4's coercion to an
`extern "C" fn` parameter never ran and `g2(1, my)` was "wrong argument
type". null_arg_expected_type's rule — the template parameter's type when
it names no type parameter — is now fixed_param_expected_type, shared with
extern_fn_arg_expected_type, and an identifier argument takes that type
when it is an extern fn type. The SQLite facade's typed-local workaround is
no longer needed.

Fixes #1609
infer_for_element_type knew HashMap but not BTreeMap, so a BTreeMap loop
fell to the generic next() protocol, found no `next` and typed the element
i32 — "tuple pattern requires tuple subject", and in a generic body the
bindings came back undefined. Sema now types the traversal as the traversal
of the map's `Vec[(K, V)]` storage (a Drop-class pair binds as a `&(K, V)`
view whose pattern projects `&K`/`&V`, a Copy pair by value), and
MirLower lowers it as the Vec loop over the `entries` field place — the
two Vec loops are split into place-based cores (lower_for_iter_ref_place,
lower_for_vec_place) that lower_for_btreemap shares. A `&BTreeMap` binding
and `for … in &bt` traverse the same way; the map stays whole after.

Fixes #1561
…under live views (#1530)

`let p = x.s` binds a view of the field (D22, field_let_binds_as_view) but
registered no borrow: the binding was never view-bound and
record_view_binding_from_expr's owned-root fallback covered only index
places. So neither `x.s = …` nor `move x.s` under the live view was
refused, and `p` read the blank or the freed string. A non-Copy field view
is now view-bound and borrows its root exactly as an element view does,
and the NK_MOVE_ARG branches run check_mutation_against_views (a vacate is
a write, §2.2 D32; a move under a live view is refused, §21.1 Rule 2) as
the assignment path already did.

Fixes #1530
…r * (#1589)

The marshalling landed with D66 (main prints 5 5 and the debug allocator is
clean); this pins the three spellings — a literal `str`, a `&str` view and
an owned `str` — against a translated `static inline` callee.

Fixes #1589
…llout)

With the method path marking plain owned arguments moved, the build layer's
uses after `target.arg(asset)` / `.input(prefix)` / `diagnostics().error(result.stderr)`
and ProcessRunner.run_spec's field moves are reported. Each is a real
second use of a consumed value; the reads become explicit clones
(build_owned_text / .clone() / with_str_clone_ref), and run_spec vacates
the spec's env explicitly before threading it.
…build log reports as private

A saved build/check log names every cross-module reference of a private
declaration ("symbol 'X' is private to module 'src/Y.w'", "symbol 'X' is not
visible from this module") and every published signature naming a private
type (§18.1). The tool collects the (module, symbol) pairs, prefixes `pub `
to the one top-level declaration of each in its owning module, and changes
nothing without --apply. Written for #1520's fallout: module privacy is no
longer waived under src/, and the compiler's own modules relied on it
(~9000 errors, visible only when stage1 compiles stage2).
… waiver had covered (#1520 fallout)

Applied by tools/publish_private_symbols.w over the stage2 build log and the
stage1 check logs that followed (types, enums, fns, consts, lets, vars;
`pub unsafe fn` for the comptime entry points; the take_* partners and
Codegen itself, whose `impl Codegen:` blocks live in CodegenDispatch.w and
CodegenTraits.w). Five `use` lines make the modules that reach SemaCheck.w,
SemaDecl.w and CImport.w helpers import them ("not visible from this
module"). The rule (b8c1edf) is right; the compiler's tree now conforms to
§18.3 like any project.
… impl header (#1520)

collect_impl_decl attached the block to nothing when the target type was
private to another module, so every method's `self` was an error type and
each use surfaced as "unknown method 'm' for type '&<error>'" far from the
cause (`impl Codegen:` in CodegenDispatch.w: 300 such lines). The impl
header now reports "symbol 'T' is private to module 'src/X.w'" through
emit_private_symbol_error; behav_module_privacy_under_src_dir pins it.
…follow-up, §3.8/D22)

b5bd597 registered `let src = self.source` as a borrow of `self` with an
empty path, so every sibling write — `self.pos = self.pos + 1` in the
Lexer, the Sema save/restore pairs, 210 sites of the compiler's own sources
— was refused as invalidating the view. A write to a disjoint field leaves
the viewed value where it is. register_view_binding_borrows now records the
initializer's projection path (root-to-leaf, stopping at an index — an
element's storage can move under any write to its collection, #887), so
are_borrows_disjoint_paths admits sibling writes and still refuses a write
to the viewed path or an ancestor of it.

behav_sibling_field_mutation_under_field_view pins the accepted shapes
(sibling, sibling of an ancestor, element view with sibling writes);
err_assign_field_under_live_field_view and
err_assign_parent_under_live_field_view pin the refused ones.
… value are not consumed

Both are plain discriminants read at several call sites in one function
(skip_member_separators(form) per member; exh_constructor_of(…, cls, …) per
constructor). Without the Copy impl the method-path move check (#1588) marks
the first pass a move and the next a use of a moved value.
…eck now see in the compiler's own sources (#1530, #1588 fallout)

A `let saved = self.f` before `self.f = …; …; self.f = saved` is a transfer,
not a view: the seed aliased it, #1530 registers the view and refuses the
reassignment, and consuming the view binding at the restore is refused too.
Every such save/restore pair is now `let saved = move self.f` (139 sites,
rewritten from the check log). The comptime evaluator's signal values are
moved into the calls that take them by value, cloned where the value is
still read after (update_slot_value, write_back_mut_receiver); a builder's
finished body is moved out; a path that is read after the call is cloned; a
Copy element read across a write to its collection is an owned `: i32` /
`: StackifyTarget` value. The hot-path comptime call moves the module path
out only when it switches context, so a same-file call keeps it in place
(#679). main.w vacates the parsed build options from a `var`.
… place (D52, §9.1c)

mark_moved_if_consumed set the symbol of a `const` to MOVED when it fed a
consuming parameter, so `take(C); take(C)` reported "use of moved value"
at the second use — the seed's free-call path did this already, and the
method path (#1588) now did it too, which refused build.w: line 2400's
`.extra_output(FIXPOINT_STAGE2_UNITS)` marked the const moved and lines
2478 and 2494 read it. D52: every use of a `const` materializes it, so a
transfer from one moves nothing; a non-local const symbol is now exempt
from the mark (reject_move_out_of_global already skips it through
global_value_ident_nodes). A `global`'s move stays "cannot move out of
global" at the consuming use, on the method path too
(err_move_out_of_global_method_arg).
… position (#1609 follow-up, #604)

fixed_param_expected_type resolved the template parameter's type node as a
bare type expression, so `[]mut T` there hit #604's "can only be a function
parameter type" — the argument check refused every facade whose generic
helper takes an element buffer (behav_c_facade_buffer_elements). Reached
only for null literals before; #1609 widened the path to identifier
arguments. The node is a signature parameter, so it resolves through
resolve_parameter_type_expr, as declaration and specialization do.
…ded-rt>/ to rt/ (#1520 fallout)

With the runtime parsed into the unit (WITH_RT_IN_UNIT=1,
behav_rt_in_unit_check_lane) module privacy now applies across rt/*.w too,
and rt_core.w calls panic_runtime.w's str_data and fiber_runtime.w's
make_str. publish_private_symbols reads the lane's `<embedded-rt>/rt/…`
module names as the tree's rt/*.w.
… cloned, a saved field view refuses the mutation

behav_mut_recv_disjoint_args passed `b.buf` and a `let piece = a.buf` view
to `Acc.add(mut self, piece: str)`, which consumes: a field never moves out
implicitly (§2.2, D32) and an unannotated field let is a view (§3.8, D22),
so both are `.clone()` — the independent value the parameter takes.

dump_mir_str_field_concat_saved_alias_copy pinned `let saved = a.buf;
a.buf = a.buf ++ "x"; saved ++ a.buf` reading through the alias — the
pre-D27 behavior. Under §3.8 the mutation of a viewed field while its
view is live is refused; err_assign_field_under_saved_field_view pins the
diagnostic and behav_str_field_concat_saved_clone the accepted spelling
(`let saved = a.buf.clone()`).
…he location it attaches twice

FunctionInfo.new and TypeInfo.new retain their SourceLocation through a
plain `T` parameter, which consumes (§3.8); behav_std_compiler_project_info
passed one `loc` to both and only compiled because the assoc-call path
never marked the move (#1588). A location attached to several records is
cloned, and a std value type that callers retain is Clone.
…nternals tests use from test/internals (#1520 fallout, tools/publish_private_symbols.w over the internals lane)
…S RULING — examples are contracts)

Spec §18.3: "`pub` exports names. No `pub` = module-private." Both
examples used non-pub declarations across their own modules
(session.handle_session; domain's User, UserId, UserProfile, Role,
CreateUserRequest, Notification), accepted only by the entry-directory
privacy waiver #1520 removes. §2.2/D32: a field never moves out
implicitly; Database.open retains its path, so the call site clones.

Prepared so the branch's battery can run; lands only if Eric rules that
the examples, not the compiler, were the non-conforming side.
Eric Hartford added 9 commits September 26, 2026 12:36
…sitive (#1708) and src/ has no privacy waiver (#1520), so a module that named MirCore, InternPool, SemaTypes or compiler.* types through another module's import now says so
… of every name a log reports unresolved

Imports are not transitive (§18.2, #1708) and src/ has no privacy waiver
(§18.3, #1520), so a compiler module that named a declaration through a
third module's import fails with "undefined variable" (the name is read at
the caret), "unknown type 'X'" or "symbol 'X' is not visible from this
module". For each such name that exactly one module under the source roots
declares at top level, the referencing module gets `use <owner>` after its
header's last `use` and the owner's declaration gets `pub ` when it lacks
it. A name with no owner, several owners, or its own module as owner is
reported and left alone. The compiler's own "add: use M.n" fix-it is
applied verbatim. Nothing changes without --apply.
…declares an extension `m` (#1708 fallout)

check_qualified_extension_call claimed every `pkg.m(...)` whose `pkg` was a
directly imported module alias, before asking whether that module declares
any extension method `m`. Once imports stopped being transitive (§18.2,
#1708), `use Compilation` (a shim that only imported compiler.Compilation)
bound the alias `Compilation` and nothing else, and `Compilation.init()` in
Lsp.w was reported five times as "qualified extension method
'Compilation.init' requires a receiver argument" — a method no module
declares. The call now falls through when the module has no such extension
method, and the ordinary path names the unresolved `Compilation`
("undefined variable"). behav_module_alias_named_like_type pins both the
refused alias spelling and the accepted direct import.
…ler.Compilation

The shim existed so `use Compilation` kept working after the orchestration
root moved to src/compiler/Compilation.w: it imported that module and relied
on the import carrying through. Imports are not transitive (§18.2, #1708),
so the shim re-exports nothing; main.w, Lsp.w and bootstrap_main.w import
compiler.Compilation directly (main.w already did).
…1520 layer

Applied by tools/import_unresolved_symbols.w over the stage2 build log of
the rebased branch (1320 "undefined variable", "unknown type 'TypeId'",
"not visible from this module", the std sha256 fix-its) and the stage1
check that followed (TargetSpec in SemaCheck.w): 42 `use` lines in 27
modules, each naming the one module that declares the symbol. SemaFacade.w
takes `use Span` by hand — Span is declared by src/Span.w and by
src/compiler/foundation/Span.w, and the facade builds the Diagnostic span.
…as with no such type keeps "unknown qualified extension method"

5e266cb let every `alias.m()` whose module declares no extension `m` fall
through, which also dropped err_extension_method_unknown_qualified's
diagnostic for a plain module alias (`slug.missing(t)`). The fall-through
is now limited to its cause: the module declares no extension `m` and a
type of the alias's name exists that this module cannot see
(`use Compilation; Compilation.init()` after #1708). That case reports
"symbol 'Compilation' is not visible from this module" at the alias; every
other alias keeps the qualified-extension diagnostics.
…y (§18.1, #1708)

With non-transitive imports the release binary refuses build.w: "'arch'
requires an explicit import; add: use std.sysinfo.arch" and the same for
std.process.env. The pinned seed predates #1708 and accepted them, so the
battery's build layer (evaluated by the seed) never saw it; the fresh
binary's `check build.w` did. Applied the compiler's fix-its.
…sts lane)

src/MirValidationTests.w is compiled only by test/internals, so the stage2
log never showed it; its TypeKind reads failed as "undefined variable" in
all 15 internals tests. Applied by tools/import_unresolved_symbols.w.
…aTypes` (imports are not transitive, #1708); the ABI convention is unchanged, so WITH_ABI_VERSION stays
…ader's address, whose low bytes are usually five non-zero bytes), so #1589 is not fixed here; it moves to its own PR
@ehartford ehartford changed the title Sema cluster B: #1476 #1588 #1590 #1499 #1520 #1609 #1561 #1530 #1589 Sema cluster B: #1476 #1588 #1590 #1499 #1520 #1609 #1561 #1530 Sep 26, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery green on 3e8dea5 (host darwin-aarch64, seed per seed.lock):

sema-b build  rc=0
sema-b build :fixpoint rc=0
sema-b build :test rc=0
sema-b build :test-green rc=0
sema-b build :last-green rc=0
sema-b build :user-programs-safe rc=0

#1589 is removed from this PR (its test passed by coincidence) and fixed in its own PR.

@ehartford
ehartford marked this pull request as ready for review September 26, 2026 18:38
@ehartford
ehartford merged commit 23cd688 into main Sep 26, 2026
@ehartford
ehartford deleted the sema-cluster-b branch September 26, 2026 19:18
ehartford added a commit that referenced this pull request Sep 26, 2026
The release stamp's ABI key is sha256(docs/with-abi.sha256). A stale
record (an edit to src/FnAbi.w or src/TypeLayout.w, even a `use` line,
without re-recording) stamped the compiler with a key its sources no
longer had, and only :test's abi-hash-check noticed — an hour into a
battery (#1716). The 4-second check now gates `with build` itself; the
iterate tier (:dev) is unaffected.

Co-authored-by: Eric Hartford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant