Skip to content

emitc 983 - #2812

Merged
ehartford merged 5 commits into
mir-tail-movefrom
emitc-983
Oct 29, 2026
Merged

ehartford merged 5 commits into
mir-tail-movefrom
emitc-983

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Stack created with GitHub Stacks CLI • Give Feedback 💬

Eric Hartford added 5 commits October 29, 2026 12:03
… retain (D111)

`a ++ a` over a List[List[str]] appended the inner Lists by their bits:
two holders of each inner buffer with no count, freed twice (debug
allocator: DOUBLE FREE origin=List, first and second drop both
__drop_struct_760). mir_emit_list_extend_from now runs the element copy
glue over the appended range when the element has glue and is not a str
(the runtime's extend retains strs).
The C backend emitted every drop as a comment, copied every value by its
bits and never blanked a move's source, so a C program ran no Drop impl
and freed nothing. It now follows the LLVM backend shape for shape:

- per-type drop and copy glue (__with_drop_<tid>, __with_copy_<tid>),
  declared before every body: a type's Drop impl then its fields in
  reverse, an enum's live payloads, Box, Rc/Arc, List, HashMap/HashSet,
  SlotMap, channel endpoints, closure cells; members guarded by the
  reset-on-move sentinel (§2.5.1)
- `drop(place)` and DropAndGoto call the glue, guarded when the local
  was ever moved (§2.5.2); the reset blank is a memset (padding included)
- MIR's operand holds (D111): a retained copy takes the copy glue, a
  taken copy hands the value over and blanks the source
- a Drop.drop receiver is the owner's place (FnAbi owned_place)
- a struct's hidden liveness byte is set when it is built (D72)
- make-unique copies take element glue (D120); clear, an overwriting
  insert, map remove and clear, ListSlot set drop what they end;
  ListSlot get and a map slot read take a hold; `++` holds its elements

Found on the way: List.remove's result was never written (typed as
returning nothing), `a ++ b`'s result was never stored, and the map
slot read's dead-slot panic was overwritten by the read.

The emit-C harness runs a fixture with an `//! expect-debug-alloc:` line
under the debug allocator; six new fixtures do, each at leak count=0.

Fixes #983
The C backend had no lowering for the generic `new` an `Atomic.new(v)`
call is, and typed its result by another type's `new` (StringBuilder).
#985 made std.random's state an Atomic in a global's initializer, so
emit-c-test (the compiler emitted as C) stopped emitting: "emit-c does
not support generic intrinsic new" in __with_init_global_rng_state.
…rts (#2180)

The C backend refused every map key but an integer, a bool, a pointer and
a str, so the compiler itself could not be emitted (Sema keeps a
HashMap[(i32, i32), _]). Per key type it now generates the hash and the
equality the runtime map calls (with_hashmap_new_keyed kind 2), part by
part in the LLVM backend's order (mir_emit_hash_ptrs, mir_emit_eq_ptrs):
tuples, arrays, structs, enums and Options by variant, Lists, Boxes, str;
a type with its own eq (derived or written) compares by it. A key
projection is refused, not compared by its parts.

The glue's two `insert(…, name)` then `name` sites are routed through
an observing helper, seed-bound: every pinned seed returns the blank a
last-use take left (fixed in this stack's MIR layer).
…not a failure

The stub generator scanned LlvmBridge.w and ClangBridge.w for
`pub fn wl_*` and failed with "found no bridge exports" when there were
none. The D100 pub sweep (#2463) made every bridge function
package-internal: the emitted unit defines each wl_* itself. The scan now
reports whether it read and parsed every source, apart from what it
found, and an empty list writes a header and stubs that declare nothing.
@ehartford
ehartford added this pull request to stack #2813 October 29, 2026 16:09
@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery GREEN on the stack top 99d6360fe (with run tools/battery.w, 730 s). Also green before it: :gate, :deep-debug-tool-tests, :drop-audit; all 35 test/emit_c fixtures through C at debug-allocator leak count 0.

@ehartford
ehartford marked this pull request as ready for review October 29, 2026 16:36
@ehartford
ehartford merged commit 8decfa6 into main Oct 29, 2026
@ehartford
ehartford deleted the emitc-983 branch October 29, 2026 16:36
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