Repository navigation
Merged
Conversation
added 6 commits
October 22, 2026 12:07
`const check: Unit = f()` and `let check: Unit = g()` trapped codegen (`LLVMAddGlobal` of a void type; `getTypeSizeInBits` on it). A `Unit` binding now gets no global: a comptime-evaluated one (the transform's empty block) emits nothing, a runtime one runs its initializer before main for its effects and stores nothing. The first one written was D147's layout assertion (`const __ci_layout_R_check: Unit = …`). Fixture: test/behavior/behav_unit_global_binding.w.
`with migrate` no longer demotes a bitfield record to opaque. Its bitfield members group into storage units — an unsigned integer of the unit's size, `__bits_<k>`, at clang's offset under `@[repr(C)]` — with a getter and a setter per named member; member reads lower to the getter, assignments, compound assignments and `++`/`--` to the setter, which masks the value to the width (a signed member two's-complement truncates, so `dist++` at 1023 is 0, as C stores it). A designated init builds the record and runs the setters. Unnamed and zero-width members are padding; an enum-typed member's getter returns its integer alias; a `_Bool` member is its bit. One layout for every target or a loud refusal (ruling point 1): a unit holding members of differing declared size (Itanium packs across, MSVC starts a new unit), a unit that is not a whole aligned integer (a packed record), a volatile member, and a bitfield in a local or member record are refused naming the record and the reason. A `comptime` assertion of the record's size and every unit's offset is emitted beside it: `sizeof`, `alignof` and `offsetof` are now comptime-evaluable (ComptimeEval reads Sema's TypeLayout; the field is resolved by name when the body is evaluated before its check). `c_import` keeps §16.9's demotion; the spec notes the migrator's representation is the intended one for both (point 5). Also in the migrator: a compound assignment whose left operand is promoted (a bitfield narrower than int, a small integer) computes in int — the right operand is no longer cast to the unsigned result type (`c_int +% c_uint` did not compile). Fixtures: bs_check_migrate_stc_expression_forms gains the positive record set and the three refusals. STC's stc_core unit and hmap_test program join their lanes. Decision log: docs/meetings/2026-10-22-D147-bitfield-records-in-with-migrate.md.
A `__FILE__` a translation unit bakes (stc_core's coroutine.h diagnostics, ctest's assertion sites) spells the path clang saw, which named each test program's staging directory (`source-<program>/../include/...`), so the engine module differed per program and the shared engine/ layout refused the promotion. `with migrate --macro-prefix-map OLD=NEW` forwards clang's -fmacro-prefix-map (a further clang argument beside the include paths, `with_cimport_add_clang_arg`); the STC test lane maps each program's staging directory to "", so every program spells the header `../include/stc/coroutine.h`. The test promotion assembles beside the tree and publishes whole once every program's engine copy agreed: a refused promotion had deleted every program's defs.w before refusing.
…per data model The layout assertion is guarded on the migrating target's data model (`sizeof[*const u8]() == 8`): a migrated corpus is compiled once per target (D38), and a pointer-sized member before a unit moves the unit on wasm32 legitimately (`cco_task_state`, 40 bytes with its unit at 31 on arm64) while the unit itself sits where C puts a whole integer member on every target. A member record with a bitfield is refused where it would render, not in the demotion predicate that scans every declaration the headers bring in (sys/wait.h's `union wait`). An accessor's receiver prints as the place with its own `unsafe` (`(unsafe m.meta[i]).dist()`), parenthesized unless it is a name or a field. The STC corpus is re-promoted with stc_core (the coroutine runtime) and the test corpus with hmap_test: 8 of 8 upstream programs pass, fresh and promoted.
The spec inventory lists `--macro-prefix-map` with the corpus migrations' other build-passed flags (build/stc.w's); the migrator's option function drops its explicit Unit return (unit-return-review). The stdlib sourcing plan records D147's close of the pipeline half: 8 of 8 STC test programs.
Contributor
Author
|
Battery GREEN on 4017f94 (seed-driven, |
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.
D147: a migrated record with bitfields keeps C's layout (#2553)
Eric's ruling on #2553 ("Bless it", five points), implemented:
with migrateno longer demotes a bitfield record to opaque. Its bitfield members group into storage units — an unsigned integer of the unit's size,__bits_<k>, at clang's offset under@[repr(C)]— with a getter and a setter per named member (pub fn dist() -> c_uint,pub mut fn set_dist(v: c_uint)). Member reads lower to the getter; assignments, compound assignments and++/--to the setter; a designated init builds the record and runs the setters. Unnamed and zero-width members are padding; an enum-typed member's getter returns the enum's integer alias; a_Boolmember is its bit; a volatile member is refused.m->dist++at 1023 stores 0 whatever the project's overflow setting.comptimeassertion of the record's size and every unit's offset is emitted beside it, guarded on the migrating target's data model (sizeof[*const u8]() == 8): a corpus is compiled once per target (D38) and a pointer-sized member before a unit moves it on wasm32 legitimately (STC'scco_task_statewas the first).sizeof,alignofandoffsetofare comptime-evaluable now (ComptimeEval reads Sema's TypeLayout).c_import(point 5). Keeps §16.9's demotion; the spec notes the migrator's representation is the intended one for both.STC's
stc_core(the coroutine runtime,cco_group { int32_t spawn_count:24; … }) joins the engine corpus andhmap_test(hmap_meta { uint16_t hashx:6, dist:10; }) the test corpus: 8 of 8 upstream STC programs pass, fresh and promoted, with no hand edits.Also in this PR
Unitmodule binding has no storage.const x: Unit = f()andlet x: Unit = g()trapped LLVM (a void global). A comptime-evaluated one emits nothing; a runtime one runs its initializer before main for its effects. Fixturebehav_unit_global_binding.w.int.uint32_t x:14; x += 5lowered toc_int +% c_uint, which does not compile; it is((x as c_int) +% 5) as c_uint.--macro-prefix-map OLD=NEW(clang's-fmacro-prefix-map), so a__FILE__a unit bakes names no staging directory; the STC test lane uses it, which keeps the engine modules shared across programs. The test promotion is atomic (a refused one had deleted every program'sdefs.w).___closurein the multi-unit build #2558:Option.map(it as i64)inside a compiler method links to an undefined bare___closurein the multi-unit build (worked around with a plainif).Decision log:
docs/meetings/2026-10-22-D147-bitfield-records-in-with-migrate.md. Fixtures:bs_check_migrate_stc_expression_forms(the positive record set and three refusals).Evidence
Gate and battery: below.