Repository navigation
Conversation
added 3 commits
October 3, 2026 08:17
…ery record's layout is asserted (#2036) with-abi.md §3: Option[&T], Option[*T], Option[extern fn] and Option[Box[T]] lower to the payload's pointer, null being None (TypeLayout's type_layout_option_is_nullable). The C backend emitted them as `{int32_t tag; union {...}}`: Option[Box[Node]] was 16 bytes against the model's 8, so `Node { v: i32, next: Option[Box[Node]] }` had a 24-byte stride in C and 16 in the LLVM backend, and #2022's layout asserts had to skip every record holding one. - c_type of such an Option is its payload's C type; it has no record of its own (collection, readiness and definition skip it). - One place for each representation fact: enum_tag_text (the null test for these Options, `.tag` otherwise), enum_payload_member (the value itself for these Options), payload_enum_literal (the payload, or a null of the type). The discriminant rvalue, place projections, Display, is_some/is_none and unwrap/expect read them. - The #2036 exemption in layout_static_asserts is gone: every emitted struct, union and tuple is asserted. test/emit_c/option_nullable_pointer.w: a Box list, HashMap.get, a returned Option[&i32] and a raw-pointer Option in a record; fix-2022's C printed `stride 24 24` for the model's 16.
…nof reads the model for every kind (#2039) Box.new, Mutex.new, RwLock.new and generator cores allocated `with_alloc(sizeof[T])`, whose payloads are 16-aligned: `b.v` of a Box[Al] (`@[align(32)] v`) landed at 16 mod 32 half the time and a 128-aligned value at no 128 boundary. - Runtime: with_alloc_aligned(size, align) places the value at `align` inside a larger block. The two words below it describe the placement ([p-16] = align ^ RT_PLACED_TAG, [p-8] = the block), and the free path recognizes a placement by that description, checked against the allocator's tables. So with_free (Box's drop and into_inner, Mutex, RwLock, Pulled, Box[dyn] drop glue) takes the block back with no alignment argument. Vec buffers use the same placement. - std: Box.new, Mutex.new, RwLock.new and the generator core pass alignof[T]; LLVM's Box.new intercept passes the payload's TypeLayout alignment; the C backend's closure cells pass _Alignof of their cell. - alignof: CodegenDispatch.gen_sizeof_alignof read the model only for a struct or enum and LLVM's ABI alignment otherwise, so `alignof[(Al, i8)]` was 8 for the model's 32. Every kind now reads TypeLayout for Sema's type argument, and a missing Sema type is a loud internal error. Vec keeps its size-derived alignment: its header (with-abi.md §3) has no word for the element's alignment, and grow/free run with only the header. behav_2039_heap_cells_over_aligned: alignof in a generic body (record, Option, tuple), Box of 32- and 128-aligned values, eight Boxes in a row, Mutex, RwLock, into_inner; the fix-2022 compiler printed `alignof 32 8 8 32 8`, `box128 false`, `boxes aligned 4`, `mutex false`. LLVM closure cells are #2042.
…lo the width, never a shift by the width (#1006) The C backend lowered rotate_left/rotate_right for every integer type as the 32-bit `(v << n) | (v >> (32 - n))`: a u8, u16 or u64 rotated as a u32, and a count of 0 (or any multiple of 32) shifted by 32, undefined in C. The LLVM backend's llvm.fshl/fshr (9475185) and comptime_rotate_bits take the count modulo the width and leave the value at a count of 0. rotate_text emits that at W = 8/16/32/64/128: the count masked to W - 1 (its unsigned modulo, so -1 is W - 1), a zero count yielding the value, the shifts on the unsigned type of the value's width. Any other width refuses loudly. test/emit_c/rotate_widths.w: u8, i8, u16, u32, i32, u64 and i64 at counts 1 (right), 0, W, W + 1 and -1; the pre-9475185a LLVM build printed garbage for every count of 0 or W.
…ls are allocated at its alignment (#2042) A `move` closure's environment and its heap cell {drop_fn, clone_fn, env} were the literal LLVM structs of their members, so an `@[align(32)]` capture (§16.4) sat where LLVM's 8-byte view of its i8-padded body put it: the environment at offset 16 of a 16-aligned cell. `(&raw const held.v) % 32` was false for a capture after another, for every closure made in a loop, and for a 64-aligned str record. - closure_env_llvm_type places the captures by TypeLayout's tuple rule: a by-value capture at its Sema type's model size and alignment, a by-place capture as a pointer. tuple_type_from_layout materializes it (padded when LLVM's placement differs), for closures and async blocks. - closure_cell_llvm_type puts the environment at its own alignment after the two function pointers. - Every capture and cell slot is reached through tuple_elem_ptr (creation, the closure prologue, the env drop and clone fns, async blocks). - The cell, its clone and an async environment are allocated with with_alloc_aligned at the model alignment; a closure built in a loop aligns its stack environment as an entry slot is. behav_2042_closure_env_over_aligned: a capture alone, after a byte, two over-aligned captures, closures built in a loop, a Drop-holding 64-aligned capture; the previous stage1 printed `after byte false`, `loop 0`, `drop misaligned`. The behavior corpus's closure and async tests pass on the new stage1.
This was referenced Oct 3, 2026
ehartford
marked this pull request as ready for review
October 3, 2026 16:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2037 (fix-2022).
e607ab3b): with-abi.md §3. In emitted C,Option[&T],Option[*T],Option[extern fn]andOption[Box[T]]are now the payload's pointer, null meaning None, instead of{tag; union}. One helper each for the tag test, the payload member and the literal. emit-C ignores @[align(N)] (§16.4): a record's C struct is C's natural layout, not TypeLayout's (Al is 16 bytes in C, 64 in the model) #2022's exemption is gone: every emitted struct, union and tuple carries its TypeLayout_Static_asserts. Fixturetest/emit_c/option_nullable_pointer.wfailed first: the C stride was 24 where the model says 16.c80d078b):with_alloc_alignedplaces an over-aligned value inside a larger block. Two words below the pointer describe the placement, and the free path recognizes it after checking against the allocator's tables, sowith_freetakes the block back with no alignment argument.Box.new,Mutex.new,RwLock.new, the generator core and LLVM'sBox.newintercept now pass the model alignment.alignofnow reads TypeLayout for every kind. It had used LLVM's value for tuples and generic instances (alignof[(Al, i8)]was 8).behav_2039_heap_cells_over_aligned.0577d565): closure and async environments now take TypeLayout's tuple placement, and the owned cell puts the environment at its own alignment. The cell, its clone and async environments are allocated at that alignment. All slots are reached throughtuple_elem_ptr. Fixturebehav_2042_closure_env_over_alignedfailed first (after byte false,loop 0,drop misaligned). The closure and async behavior tests pass on stage1.e54f0b82): emit-Crotate_left/rotate_rightnow work at every width W, with the count taken modulo W, and a count of 0 returns the value unchanged, so there is never a shift by W. This matches the LLVM backend's fshl/fshr. Fixturetest/emit_c/rotate_widths.w.Verification on the top commit, rebased onto main 74e3001:
:devgreen;:emit-c-smoke30 cases;:drop-audit254 cells, 0 regressions;src/main build :gategreen (fixed list).