Skip to content

D155/D156: the C aliases are the target's builtins; a corpus is compiled against one data model, explicit in its text - #2596

Merged
ehartford merged 14 commits into
mainfrom
d155
Oct 24, 2026
Merged

ehartford merged 14 commits into
mainfrom
d155

Conversation

@ehartford

@ehartford ehartford commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Implements Eric's rulings D155 and D156 (docs/meetings/2026-10-23-D155-…, …-D156-…, §16.1), squash-merged as one change.

D155. The C aliases c_char … c_longdouble are Sema builtins resolved from the target spec (c_char u8 on AArch64 Linux and wasm; c_long 32 bits on Windows and wasm32; c_longdouble f64 everywhere), ambient like c_void. No c_import prelude or migration emits a type c_*. c"…".ptr is *const c_char. std and the runtime spell every C string c_char; with_free takes *mut c_void, so freeing a C-string buffer carries no cast. Last, the D65 pointer rule: a pointer to one integer type is not a pointer to another (pointer_pointees_compatible and its frozen twin); the fix-it names p as *const c_char. Fixtures: behav_d155_c_aliases_are_the_targets, err_d155_integer_pointer_pointees.

D156. A corpus is compiled against one data model, explicit in its text: the migrator spells every C integer type at the parsed model's fixed width (i32, u64, …); only char stays c_char; the model is recorded (// data model: LP64 (arm64-apple-macosx11.0), pub const C_DATA_MODEL), not enforced; Sema's narrowing diagnostic names the model at a seam. The hex-literal and suffix typing rules key on fixed names (the ulong_max_width selfhost case asserts a high hex macro is u32, 0x10U is 0x10u32, 0x20L is 0x20i64). The migrator's defs prelude spells libc's string externs c_char. Fixture: err_d156_seam_names_the_model (two modules, so the #1703 displacement of C_DATA_MODEL is exercised; the bundle interface emitter prints the undisplaced name).

Corpora. All six re-promoted under WITH_CORPUS_PROMOTE=ruling:D155: no c_int/c_uint/c_ulong remains, every wasm32 bundle builds under the pointer rule.

Interim. Compiler sources are compiled by the pinned seed, which has no c_char builtin, so src/ComptimeEval.w, src/compiler/FrameworkStubs.w, src/compiler/LlvmBridge.w and src/compiler/ClangBridge.w keep i8/u8 casts at their runtime seams until a D155 seed is cut (the i8 ones hold on i8-char hosts; the linux-aarch64 leg follows the seed). Tracked in handoff.md §3.

Gate green on the pre-rebase tree (out/d155-gate3.log); the battery runs on the rebased top commit and its verdict is posted below before this leaves draft.

Eric Hartford added 10 commits October 23, 2026 22:00
… migration emits one (D155)

`c_char`, `c_short`, `c_ushort`, `c_int`, `c_uint`, `c_long`, `c_ulong`,
`c_longlong`, `c_ulonglong` and, where C's `long double` is a double,
`c_longdouble` are registered by Sema from the target spec, ambient like
`c_void` and `c_va_list`: `char` is unsigned on AArch64 Linux and on wasm,
`long` is 32 bits on Windows and wasm32. A C string literal's bytes are
`c_char`s: `c"…".ptr` is `*const c_char` on every target. The c_import
unit prelude and the migrator's defs prelude emit no `type c_*` line (a
migrated corpus never contains a concrete value for one); the names stay
marked as emitted so a declaration's reference to one is known. Ruled by
Eric 2026-10-23 (D155, #2585, #2582): three owners of what `char` is on an
unsigned-char target disagreed (the c_import prelude, the corpora's baked
`c_char = i8`, the literal's `*const i8`), and the aarch64 seed leg found
them. §16.1 carries the ruling; the fixture pins the widths and signs per
target.
std.libc, std.string (CStr), std.zip, std.fs and the build layer spelled C
strings `*const i8` / `*mut i8`. On a signed-char target that is the same
type as `*const c_char`; on AArch64 Linux and wasm it is not, and a fresh
migration there (`*mut c_char`, u8) could not bind std.libc's `realpath`
(#2585). The runtime's byte parameters (`*const u8`) are unchanged.
…widths; only char stays c_char; the model is recorded; the seam diagnostic names it

Ruled by Eric 2026-10-23 (D156, amending D155). Done here: the clang
bridge and the migrator's textual paths spell every C integer type at the
parsed model's width (clang's own sizes; `long` by ci_model_long_bits,
`size_t` by ci_model_size_type, literal suffixes and promotions likewise);
plain `char` stays `c_char`, `signed char` is `i8` (its pointer too);
`long double` is `f64` where it is a double. The defs prelude records the
model (`// data model: LP64 (arm64-apple-macosx11.0)` and
`pub let C_DATA_MODEL`); Sema's narrowing diagnostic appends the model of
the module it fires in (SemaCheck.current_module_data_model), pinned by
test/compile_errors/err_d156_seam_names_the_model.w. std's seams to the
LP64 corpora are spelled at the corpora's widths (algorithms, regex, zip);
the runtime's C-string seams (strtol/strtoul/strtold, open, unlink,
mkstemp, realpath) are `c_char`. The migrator selfhost expectations are
swept to the fixed spellings. §16.1 and D156's file carry the ruling.

NOT DONE (handoff.md): the re-promotion is red on three corpora and the
wasm32 bundles; see the handoff's "D156: where it stopped".
…n; regenerate with `WITH_CORPUS_PROMOTE=ruling:D155` once the migrator is green (see handoff.md)
…nstant survives displacement

The hex-literal and suffix rules that typed a macro constant compared alias
names ("c_uint") after the fixed-width sweep had stopped producing them, so
a high-bit 8-digit hex constant (zlib's POLY, c_algorithms' MALLOC_PATTERN)
came out `i32` and did not fit. The rank, width and suffix tables now key on
the fixed names, and the ulong_max_width selfhost case asserts the three
shapes (a high hex macro is u32, `0x10U` is `0x10u32`, `0x20L` is `0x20i64`).

C_DATA_MODEL is a `pub const` again: the bundle interface emitter prints a
displaced global's own name (the `$in$` suffix is #1703's flat-namespace
rename, not the declaration's), and Sema's seam note finds the emitting
module's constant under either spelling. The seam fixture is two modules so
the displacement is exercised. The clang bridge spells an unknown atomic's
value type i32, not c_int.
…a model recorded

`WITH_CORPUS_PROMOTE=ruling:D155` for zlib, pcre2, tommyds, c_algorithms,
mlib and stc with the fixed-width migrator: every macro constant is spelled
at the LP64 model's width (`Z_OK: i32`, `MALLOC_PATTERN: u32`), no `c_int`,
`c_uint` or `c_ulong` remains in a corpus, each defs.w carries
`// data model: LP64 (arm64-apple-macosx11.0)` and `pub const C_DATA_MODEL`,
and every corpus's wasm32 bundle builds (the 32-bit `long` of wasm32 no
longer re-types an LP64 crc table).
…(D155 step 5)

Every C-string seam in the native runtime (paths, environment names and
values, argv, dirent names, realpath and mkstemp buffers, the C-string
producers str_to_cstr and posix_str_to_c_buf) is `*const c_char`/`*mut
c_char`, so a `c"…".ptr` literal and a built C string pass without a cast
and the D65 pointer rule has nothing to refuse. Byte buffers stay `*mut u8`
and convert once at the C-string boundary. `with_free` takes `*mut c_void`:
freeing a C-string buffer is not a reinterpretation, and the cast every such
free would otherwise carry was the ceremony the rule would have forced.

std.libc's assertion text and std.fs's strerror message read their
`*const c_char` directly. WASI's path imports stay byte pointers with
lengths; wasm's c_char is u8 and nothing there changes meaning.
… the last step)

`pointer_pointees_compatible` and its frozen twin refuse an integer pointee
of a different width or signedness; a `c_void` pointee still accepts any
pointer. The fix-it names the cast: `p as *const c_char` (SemaDiag's
integer_pointer_cast_help). Fixture: err_d155_integer_pointer_pointees.

Compiler sources are compiled by the pinned seed, which has no `c_char`
builtin, so their three runtime seams and the LLVM bridge's C-string
literals carry an `i8`/`u8` cast until a D155 seed is cut; the facade
renderer, whose output the new compiler compiles, emits `as *const c_char`.
…e-promoted

strlen, strcmp, strncmp and strchr in the defs prelude were written out with
`*const i8`, a Darwin spelling of `char`: under the D65 pointer rule the
wasm32 bundles, where `c_char` is u8, refused every `strlen(path)` in zlib
and its siblings. The prelude is the one place a C string's type was still
hand-spelled; it says `c_char` like every migrated declaration. All six
corpora re-promoted (`WITH_CORPUS_PROMOTE=ruling:D155`); every wasm32
bundle builds under the rule.
…t Unit; D119's array case reads D156

pre_d_build_runner's own view of with_str_from_cstr matches the runtime's
(`*const c_char`), so the deep-debug provenance case compiles under the
pointer rule. The platform files' extern views of with_free and std.libc's
perror no longer spell `-> Unit` (unit-return-review). The D119 array case
asserted that a 5000000000 element of an `unsigned long` table keeps its
`as u64` cast "on every target"; under D156 the table is the model's
`List[u64]` and the literal fits, which is what the case now asserts.
@ehartford ehartford changed the title D155/D156: the C aliases are the target's builtins; a corpus is compiled against one data model, explicit in its text (WIP) D155/D156: the C aliases are the target's builtins; a corpus is compiled against one data model, explicit in its text Oct 24, 2026
Eric Hartford added 4 commits October 23, 2026 23:00
… spells the C aliases

Under the pointer rule `run(&raw mut c)` with `fn run(s: *mut i32)` and
`var c = 0` refused `*mut isize` where the program meant `c: i32`. D126's
recheck already retypes a literal-typed local from a demand, and D128
carried `&name` to a `&i32` parameter; the same hook now carries `&raw
const`/`&raw mut`, a pointer (not only a reference) parameter, an
`Option[*const i32]` parameter through its payload, and one hop through an
unannotated pointer binding (`let target = &raw const value`). The first
pass records the demand instead of an error, so the body's second check
sees `c` at the pointee's type. The ~90 drop and debug-allocator fixtures
that wrote this shape compile unchanged.

The C alias table (`c_char` u8 on AArch64 Linux and wasm, `c_long` 32 bits
on Windows and wasm32, `c_longdouble` f64) lives once, in
TargetSpec.c_alias_fixed_spelling: Sema registers the builtins from it
(`c_schar` and `c_uchar` included) and the facade renderer compares a
facade's `wraps c_int` with c_import's `i32` through it, `c_char` alone
staying symbolic so a help prints the spelling both sides use. The
toolchain libc facade's CHeapStr wraps `*mut c_char`, which is what
c_import now says `strdup` returns.
…trings or alias names

The fiber, channel and wasm runtime files' views of with_free match its
definition (`*mut c_void`; rt-decl-audit). Fixtures with their own extern
views of C strings spell them `c_char` (link_name_extern, float_unsigned_cast,
fstring_float_sweep's format, spec §16's atoi, the #1919 owner lib); the two
privacy tests probe c_import visibility with `FILE`, since `c_uint` is a
builtin now; the five migrate tests expect `i32` where the migrator spelled
`c_int` (D156); the deprecated-owns help names `*mut c_char`; the
debug-allocator root-filter fixture hands its reason as bytes.
…ote; candidates list in name order

`print(M_MIN)` where this unit's c_import omitted `M_MIN` and std.engines.mlib
also has one said "requires an explicit import" instead of naming the
omission; emit_private_symbol_error asks the omitted table first. The
"candidates: use …" list of a gated std name is sorted, not in module load
order, so the message is the same whichever corpus loaded first.
…e agree with the runtime

The wasm backend's `pub fn rt_*` path definitions spell `*const c_char` like
the native backends (the WASI imports they call keep bytes with lengths;
wasm's c_char is u8). The two compiler sources that declared their own
`rt_open` view read it from rt.rt_core instead. Fifty-odd debug-allocator
and behavior fixtures that declared `extern fn with_free(ptr: *mut u8)`
declare `*mut c_void`, its definition's type.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on a0eeda7 (seed-driven, with run tools/battery.w, third run; out/battery/status.txt: green). Runs one and two were red for the pointer rule meeting literal-typed locals (now a demand, D126/D128), the facade renderer's alias text, fixtures with their own u8 C-string views, and rt-decl-audit (wasm path definitions, test views of with_free); each is a commit on the branch.

@ehartford
ehartford marked this pull request as ready for review October 24, 2026 04:28
@ehartford
ehartford merged commit f36cf4f into main Oct 24, 2026
@ehartford
ehartford deleted the d155 branch October 24, 2026 04:28
ehartford added a commit that referenced this pull request Oct 24, 2026
…assertions (other-host seams of #2596) (#2597)

* std.zlib speaks the corpus's widths: uLong is u64, not the host's c_ulong (D156)

The zlib engine is migrated against LP64, so its `uLong` parameters and the
stream's `total_out` are `u64` in every build. std.zlib still passed its
lengths as the host's `c_ulong`: on Windows (LLP64) that is u32, so
`&raw mut out_len` no longer met `compress2`'s `*mut u64` under the pointer
rule and `*dest_len = stream.total_out` narrowed, and stage2 refused
(win10, 2026-10-24). The facade over a corpus spells the corpus's width; the
seam to the host is std.zlib's own `len()` conversions, which already widen.

* The stc test harness spells its C strings c_char (the pointer rule refused its u8 cast on every host; stc-test, eric-5090 2026-10-24)

* c-migrator-core-tests: the D156 array assertions read what the migrator emits (clang's folded literal, D119)

---------

Co-authored-by: Eric Hartford <[email protected]>
ehartford added a commit that referenced this pull request Oct 24, 2026
…(first with the D155 builtins) (#2598)

Cut from main c1ea1de on the laptop: `:release-checks` green (fixpoint,
the Sema regression rebuilds, the migrator tests, every corpus migrated
afresh, wo-drift), the asset stamped and published with its sha256 and
provenance. The other platforms keep their `.version=` pins (linux-x86_64
and windows-x86_64 on local-2 from the bridge; linux-aarch64 on local-3
until its leg). Workflow pins follow the lock (tools/bump_seed_pins.w).
With this seed compiler sources may spell `c_char`; the interim `i8` casts
of #2596 go in the next change, never this one.

Co-authored-by: Eric Hartford <[email protected]>
ehartford added a commit that referenced this pull request Oct 24, 2026
…#2596 retire) (#2599)

With the D155 seed pinned, src/ may name the builtin: ComptimeEval's strerror
and strtod views and its rt_open seam, FrameworkStubs' rt_open seam, the
LLVM bridge's target-machine cpu/features (`c"generic".ptr`, `c"".ptr`) and
the clang bridge's mkstemp/realpath seams (`*mut c_char` through to the
runtime's with_libc_* bodies) say `c_char`, which is right on every host
including the unsigned-char ones the i8 spellings were wrong for. The #1919
fixture passes its `c"…".ptr` without the cast D155's fix-it would name.
LLVMGetEnumAttributeKindForName keeps a byte-string view: its other callers
hand it to_cstr's bytes.

Co-authored-by: Eric Hartford <[email protected]>
ehartford added a commit that referenced this pull request Oct 24, 2026
…ias block displaced std.libc's c_char on u8 hosts) (#2601)

* The corpus test programs re-promoted under D155/D156 (WITH_CORPUS_PROMOTE=ruling:D155)

The promoted programs under test/corpora/{c_algorithms,stc,mlib} were left out of #2596's re-promotion and still carried the pre-D155 alias block (`pub type c_char = i8`, `c_int = i32`, ...). Assembled under lib/std/engines/<x>_testing they are std-tier modules, so std.libc read their `c_char` as i8 while the runtime interface spelled the target's u8: on linux-aarch64 every std.libc wrapper failed MIR validation (realpath first; the rung compiler has no strict pointer rule, so Sema was silent). A fresh migration never emits the block; the promoted programs now match it: fixed widths, `c_char` symbolic, the data model recorded.

* c_algorithms and stc corpus stamps: the promote covers the re-promoted test programs (corpus-integrity)

---------

Co-authored-by: Eric Hartford <[email protected]>
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