You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bootstrap stage1 mistranslates system headers: <stdio.h> __sbuf and <stdlib.h> div_t come out opaque (stage2 is fine) #1273
Seen on main 478b264 with the checkout's own out/bootstrap/bin/with-stage1 (built 2026-09-22 06:59 from the pinned seed) and reproduced in an independent worktree build of the same commit. out/stage/bin/with-stage2 from the same build is correct.
Repro
use c_import("<stdio.h>")
fn main:
print("ok")
$ out/bootstrap/bin/with-stage1 check stdio.w
error: opaque types cannot be stored in struct fields; use a pointer or reference
--> <c_import <stdio.h>>:67:112
67 | type __sFILE { ..., _bf: __sbuf, ... }
error: type '__sFILE' cannot implement Copy: field '_bf' is not Copy
$ out/stage/bin/with-stage2 check stdio.w
ok
Same with use c_import("stdlib.h"):
error: opaque types cannot be returned by value; use a pointer or reference
--> <c_import stdlib.h>:217:40
217 | extern fn div(p0: c_int, p1: c_int) -> div_t
__sbuf and div_t are plain structs in the SDK headers; the stage1 translation demotes them to opaque.
Consequences
test/compile_errors/err_c_import_raw_call_requires_unsafe.w (imports stdlib.h) fails under stage1 — the expected "raw c_import function call requires unsafe context" never appears because the translation dies first — and passes under stage2. Any test that imports a real system header is invisible to the :dev iterate tier.
A c_import string with #include <stdlib.h> trips it too, so behavior tests that want libc bodies must spell prototypes (the stage-4a facade tests do).
Route
Seed → stage1 miscompile class (the seed's codegen of CImport's struct-translation path), not a source bug: the same source compiled by stage1 (= stage2) translates correctly. Bisect the seed-built CImport path with with reduce over the header and compare WITH_TRACE_CIMPORT_CACHE=1 output of stage1 vs stage2 for the first divergent line; then lldb on stage1 at the struct-field translation for __sbuf.
Fixed on main 1688728. Verified on a seed-built bootstrap stage1 (with build :dev, pinned seed) on two hosts:
darwin-aarch64 (out/bootstrap/bin/with-stage1 --version = with v0.15.3.0-g168872857):
$ out/bootstrap/bin/with-stage1 check stdio.w # use c_import("<stdio.h>")
ok
$ out/bootstrap/bin/with-stage1 check stdlib.w # use c_import("stdlib.h")
ok
$ out/bootstrap/bin/with-stage1 check test/compile_errors/err_c_import_raw_call_requires_unsafe.w
error: raw c_import function call requires unsafe context
--> test/compile_errors/err_c_import_raw_call_requires_unsafe.w:6:5
linux-x86_64 (eric-5090, fresh clone ~/with-ladder/verify, pinned seed nightly-20260926-local-1-2e8defaa18ef, dev rc=0): identical output for all three commands (ok, ok, the expected requires unsafe context diagnostic).
__sbuf / div_t translate as plain structs under stage1; the compile_errors fixture reaches its expected diagnostic.
Activity
Modeled C stage 4a: facade resources rendered with Drop, destroys as …
ehartford commentedon Oct 2, 2026
Fixed on main 1688728. Verified on a seed-built bootstrap stage1 (
with build :dev, pinned seed) on two hosts:darwin-aarch64 (
out/bootstrap/bin/with-stage1 --version=with v0.15.3.0-g168872857):linux-x86_64 (eric-5090, fresh clone
~/with-ladder/verify, pinned seed nightly-20260926-local-1-2e8defaa18ef,dev rc=0): identical output for all three commands (ok,ok, the expectedrequires unsafe contextdiagnostic).__sbuf/div_ttranslate as plain structs under stage1; the compile_errors fixture reaches its expected diagnostic.