Skip to content

Slots need a writable receiver (D172); iter_place writes the list it iterates; the C backend emits the compiler again (#2409) - #3565

Merged
ehartford merged 1 commit into
mainfrom
emit-c-composite-key
Nov 23, 2026
Merged

ehartford merged 1 commit into
mainfrom
emit-c-composite-key

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #2409.

#2409 said the no-LLVM bootstrap stopped at a tuple map key. That stop was already fixed on main; the lane (:emit-c-test) was in no battery and had since broken further along. Following it found four defects, two of them outside the C backend.

1. A safety hole (D172 item 1). xs.slot(i), xs.iter_place() and xs.get_disjoint(i, j) were read-mode built-ins, so a plain fn, or a function taking &T, could overwrite an element through the slot:

impl Roster:
    fn rename(i: i32, name: str):
        with self.names.slot(i) as mut slot:
            slot.set(name)      // drops the old string under a caller's view

D172 rules that a fn receiver is read-only for every write through it, and push was already refused here. A slot is the handle an element is written through, so making one is the write: the three are now Mut-mode built-ins. The C backend found it: the emitted C passed a const list to with_vec_make_unique_bits.

  • 21 methods of the compiler itself were declared fn and wrote through a slot (Sema, ComptimeEval, Lsp, MirCore); they are mut fn now, rewritten from the compiler's own diagnostics.
  • Nothing in lib, tools, build, tests, examples or UAT is refused by the rule.
  • A built-in write through a &T parameter now gets the message a user mut fn gets (it names the mut parameter). Three compile-error tests expected the old generic text and now expect the specific one.

2. Wrong output on main. for slot in xs.iter_place(): slot.set(v) never changed xs. lower_for_iter_place lowered the list as a value, a retained copy since lists share their buffer (D120), made the copy unique and wrote into it. It now iterates the list's own place. test/mut_iter_place.with has failed since; no lane ran it.

3. C backend: ListIter[T]. std declares it as a struct since #2526, but the C backend still listed it as a built-in with a hand-written layout nobody wrote, so its fields came from the instance's argument list (_Alignas(23646) const int32_t* string;).

4. C backend: a copy out of a view passed const T* to the copy glue. A hold reads the record (the holder count is in the buffer), so the call casts.

So this cannot rot again

  • :release-checks now depends on emit-c-fixpoint (the compiler emitted as C, compiled, and emitting itself to the same bytes). It adds about eight minutes there; the battery is unchanged.
  • The eleven top-level test/mut_*.with files, run by no lane, move to test/behavior/behav_mut_*.with.

Tests (each shown failing before its fix): err_d172_fn_receiver_writes_through_slot, err_d172_ref_param_writes_through_slot, behav_iter_place_writes_the_list (leak 0), test/emit_c/list_iter_declared_struct.

:emit-c-test and :emit-c-fixpoint green. Battery green (530 s); self-audit and :release-checks green (583 s).

…iterates; the C backend emits the compiler again (#2409)
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.

emit-c: no hash and equality functions for a composite map key, so emit-c-test (the no-LLVM bootstrap) is red: sema_empty_state's (i32, i32) key

1 participant