Repository navigation
Merged
Conversation
An error occurred while trying to automatically change base from
fix-2017
to
impl-1903
October 3, 2026 15:13
added 2 commits
October 3, 2026 08:17
A Vec of an `@[align(N)]` element (§16.4) kept its elements in the allocator's 16-aligned payload: `v[i].b` of a Vec[Al] (`@[align(32)] b`) sat at 16 mod 32, and a 128-aligned element at no 128 boundary at all. The header carries only the element size (with-abi.md §3), and TypeLayout rounds every size up to its alignment (§2), so the largest power of two dividing the size, at most §16.4's 65536, is at least the element's alignment. vec_buffer_alloc places a buffer that needs more than 16 at that alignment inside a block `align` bytes larger, the block's start in the word below the buffer; vec_grow, with_vec_new_with_capacity_out and both with_vec_free_buffer forms allocate and free through it. Elements whose size is a multiple of 32 but whose alignment is lower take the same path and pay up to `align` bytes per buffer. behav_2022_vec_over_aligned_elements: Vec[Al] past three regrowths, a 128-aligned element, with_capacity, and a Drop-holding 64-aligned element; the seed's compiler printed `aligned 0` for three of the four rows.
…sert; unions are unions (#2022) `type Al { a: i8, @[align(32)] b: i64 }` was emitted `struct Al { int8_t a; int64_t b; }`: 16 bytes against the model's 64, so `o.al.b` of `Outer { c: u8, al: Al }` sat at offset 16 where the LLVM backend and every TypeLayout constant put it at 64. - A field with a declared alignment is emitted `_Alignas(N)`. - The D72 hidden liveness byte (§2.5.1) is emitted after the last field of a record that has one. - Every emitted struct, union and tuple is followed by _Static_asserts that its sizeof, _Alignof and each field's offsetof equal TypeLayout's: a difference is a C compile error naming the type and field. - The asserts found a second divergence at once: a §16.4 union was emitted as a struct, its members end to end (pcre2's class_bits_storage 64 bytes for the model's 32, moving every later field of compile_block_8). Union types are now emitted `union`. - Records holding a nullable-pointer Option are not yet asserted: this backend's Option[&T]/Option[Box[T]] is a tagged struct, not with-abi §3's pointer (#2036, filed). test/emit_c/aligned_fields.w: the C program printed `outer offset 16 aligned false` and `vec aligned 1`; it now prints the LLVM backend's lines.
ehartford
marked this pull request as ready for review
October 3, 2026 16:32
This was referenced Oct 3, 2026
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.
Fixes #2022. Stacked on #2033.
Vec buffers (
37feebe4, rt/rt_core.w): a Vec of an@[align(N)]element now gets an N-aligned buffer. The header stores only the element size, and TypeLayout rounds every size up to its alignment, so the largest power of two dividing the size (capped at §16.4's 65536) is at least the element's alignment. When that is more than 16,vec_buffer_allocplaces the buffer at that alignment inside a larger block and keeps the block's start in the word just below the buffer.vec_grow,with_capacityand both free forms go through it. Trade-off: an element whose size is a multiple of 32 but whose alignment is lower also takes this path, at a cost of up toalignextra bytes per buffer.emit-C layout (
7cc85779, src/CCodegen.w):_Alignas(N).union. They had been structs: pcre2'sclass_bits_storagewas 64 bytes against the model's 32, which shifted every later field ofcompile_block_8._Static_asserts that its sizeof, _Alignof and each field's offset equal TypeLayout's.Tests (each failed before the change):
test/behavior/behav_2022_vec_over_aligned_elements.w: the old compiler printedaligned 0for 3 of 4 rows.test/emit_c/aligned_fields.w: the old C output printedouter offset 16,vec aligned 1.Verification:
:dev,:emit-c-smoke(27 cases),:drop-audit(254 cells, 0 regressions), andsrc/main build :gateare all green. The Vec fixture under--debug-allocreports leak count 0.Not covered:
Box[T],Mutex[T]and other stdlibwith_alloc(sizeof[T])paths are still 16-aligned for over-aligned T.