Repository navigation
Description
Restated 2026-10-25. The manual emit-C lane (emit-c-test, emit-c-fixpoint, emit-c-roundtrip, package-bootstrap-c) cannot build a compiler from C. Option (a) below is what the lane does now: build/emit_c.w passes --bundle-corpus std/engines/pcre2 so the corpus is emitted in-unit. Today emission stops before any C is written, because emit-C has no hash and equality functions for a tuple map key. The last measured C (comment of 2026-10, after #2033) had 165 C errors of five classes.
Original report
Found in batch C4 (wo-c4) while retiring rt/regex_runtime.w (D30). Three facts about the emit-C bootstrap lane (build/emit_c.w, build/package.w, emit-c-test/emit-c-roundtrip, package-bootstrap-c):
-
The bootstrap C package has not been self-contained since C3.4 (81dbec8).
pkg_emit_c(... "rt/regex_runtime.w" ...)compiled the shim with a compiler that embeds the pcre2 interface, soregex_runtime.c(74 KB, 2744 lines at 5465144) contains bare calls such aspcre2_compile_8(...)and no definitions — the corpus resolved to the.wi. Nothing in the package defined pcre2. (C4.4 deletes that emission; the compiler's own C now needs pcre2 the same way.) -
The C backend has no separate-compilation story for a bundle corpus. With
--emit-c --bundle-corpus std/re,lib/std/re/bundle.wemits 632k lines of C in 30 s, but every function is named with a per-unit symbol suffix (int32_t pcre2_get_error_message_8__7587(...)) and every global isstaticwith a mangled name (static pcre2_real_compile_context_8 __with_global__pcre2_default_compile_context_8__2861), while a consumer compiled against the interface emits a bare, undeclared callpcre2_get_error_message_8(1, _1, 256)(no prototype:CCodegenemits prototypes forextern fn, not for interface-bodied functions) and defines its own zeroed copy of the interface-provided global (static ... __with_global__pcre2_default_compile_context_8__7 = {0}) instead of anexternreference. Two C units cannot meet;src/CCodegen.whas nopath_uses_module_link_names/InterfaceBody/InterfaceProvidedhandling (the LLVM backend's D38 rule,src/Codegen.w:4188). -
The corpus's C is not valid C even alone.
cc -std=gnu11 -O1 -c -I runtime -include runtime/with_runtime.h pcre2.c(macOS 26.5, Apple clang) fails with three classes:redeclaration of '__stdinp' with a different type: 'void *' vs 'FILE *'(also__stdoutp,__stderrp—defs.w's migratedextern letfor the stdio globals conflicts with<stdio.h>, which the emitted C includes);conflicting types for 'strchr'(defs.w:36 pub extern fn strchr(s: *const i8, c: i32) -> *mut i8emitted asint8_t*/const int8_t*against<string.h>'schar*); and sixcall to undeclared function 'with_libc_{open,read,write,close,lseek,unlink}'(referenced from the std modules the corpus pulls, prototypes never emitted under--no-prelude).
Consequence for C4. With the shim gone, with_compiler.c (prelude on) references pcre2_* bare and undeclared, so the manual emit-c-test lane cannot compile the C compiler until one of these lands:
- (a) the compiler's emit-C passes
--bundle-corpus std/reand the corpus is emitted in-unit intowith_compiler.c(the design in docs/wo_bundles.md "Retiring the shim": "in the emit-C lane the corpus compiles in-unit as C, no bundle involved") — needs only (3) fixed; +14 MB of C, +30 s Sema, and the roundtrip lane migrates the corpus back to With; or - (b) a C-side module-link-name rule mirroring the LLVM backend (stable unsuffixed names for bundle-owned definitions,
externprototypes and globals for interface declarations) so the corpus is a separate C unit — needs (2) and (3).
emit-c-smoke (test/hello.w, --no-prelude) is unaffected and stays green; emit-c-test, emit-c-fixpoint, emit-c-roundtrip and package-bootstrap-c are the manual lanes (docs/with-release-runbook.md:17).
Activity
emit-c: a libc name the included headers declare is never redeclared;…
emit-c: the compiler's C carries the pcre2 corpus in-unit (--bundle-c…
emit-c: the lane compiles every embedded bundle's corpus in-unit — no…
abort is Never; the 29 dead fallbacks after phase-bug aborts are gone…
Sema: a bundle corpus compiled in-unit keeps its body-only imports to…
ehartford commentedon Oct 3, 2026
With #2033 (fix-2017) the compiler's C emits again and the bridge prototypes match it;
cc -fsyntax-only -ferror-limit=0 -x c out/emit-c-test/main.c -I runtime -include out/gen/wl_decls.hleaves 165 errors: 131 member references through an int32_t-typed local (Analysis, SemaVector, MirVector, ReceiverMigration, ...), 23&strarguments passed aswith_str *(CiMigrate, CiPrint, CImport), 3 void results assigned to bool (CImport:1391/1404/3397), zlib's ct_data_s arrays before its definition, one ComptimeValue.w:516 view assignment, and with_cimport_is_cxx / with_cimport_record_is_class, whose inferred return type emit_c.w's line scanner takes as void.emit-C: multi-field enum payloads, collection literals, declared Resu…
[-]emit-C lane after the pcre2 bundle: the corpus's emitted C is not valid C, and the bootstrap C package has carried no pcre2 definitions since C3.4[/-][+]emit-C lane cannot build a compiler from C: emission stops at a tuple map key, and the in-unit pcre2 C had 165 errors[/+]ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced. The lane's own emission command fails loudly:post-release: emit-C is a manual bootstrap lane, not on any user path, and getting it green is a multi-PR campaign (tuple keys first, then the 165 C errors).
ehartford commentedon Oct 25, 2026
Triage 2026-10-25: carried over from #1043, closed as a duplicate of this issue. When the compiler's C last reached
cc(after #1038), it had four errors of two classes:array type 'int16_t[75]' is not assignabletwice (a global array's MIR proxy local zeroed as__with_global_escapes__4903 = 0;, pcre2'spub let escapes: [75]i16), and astrfield reset through a const receiver after a borrowing concat. Both should be rechecked once emission gets past the tuple map key.ehartford commentedon Nov 23, 2026
State 2026-11-23, after #3565:
:emit-c-testand:emit-c-fixpointare green on main (the compiler emits itself as C, that C compiles withwith cc, and the C-built compiler emits itself to the same bytes), and:release-checksnow runs the fixpoint. #2409 and #1192 are closed. What this issue still names beyond that (the in-unit pcre2 C, building a compiler from C with no LLVM-built compiler at hand) is what remains to measure.ehartford commentedon Nov 23, 2026
Measured
:emit-c-roundtripon main after #3565 (1181 s; the lane emits the compiler as C, migrates that C back to With, and builds it). It stops in the migrate step, on two gaps inwith migrate:__atomic_exchange_n,__atomic_store_n,__atomic_load_nand the rest, which the C backend emits forAtomic[T]. clang presents each as an atomic expression, not a call, andCImportbails on it by design today (ci_bail_unsupported_unexposed). The ordering argument is a constant conditional ((1) == 0 ? __ATOMIC_RELAXED : …) clang can evaluate. A translation needs the operation on raw memory:(*(p as *mut Atomic[T])).swap(v, .Acquire)underunsafe, sinceAtomic[T]is oneT.unsupported assignment rhs in goto CFG (kind=121)in one function (Compilation.bundle_contract_rows, src/compiler/Compilation.with:1642).Both are migrator work in their own right (any C that uses
<stdatomic.h>or the builtins hits the first), so they are next on this issue.package-bootstrap-cis not yet measured.ehartford commentedon Nov 23, 2026
Correction and update (2026-11-23).
Correction. My last comment said a translation of the atomic builtins would serve "any C that uses
<stdatomic.h>or the builtins". What is written (branchmigrate-atomics, not merged) covers the GCC__atomic_*spellings only.<stdatomic.h>(atomic_load(&g), a macro over__c11_atomic_load) is still refused, loudly: "C expressionatomic_load(&g)has no translation".A defect found beside it, older than this work.
with migratedrops_Atomicsilently:static _Atomic int g; g++; g += 2;comes out asg = g + 1onvar g: i32. The clang bridge maps an atomic type to its value type (ClangBridge,CXType_Atomic), so a header import does the same to an_Atomicfield. In C those operations are atomic; the output is a plausible wrong program (Law 7). The fix the laws point to: present_Atomic TasAtomic[T](same layout) and lower reads, writes and compound operations on such a place toload,storeandfetch_*; the<stdatomic.h>forms follow from the same expression node.Roundtrip after the atomics. Rerun: the 14 atomic stops are gone. One function remains untranslatable,
Compilation.bundle_contract_rows: a closure construction the C backend emits as a GNU statement expression used as a value,inside a function lowered with gotos. The migrator lowers a statement expression only where its value is discarded (and one comparison form); as a value it needs its statements hoisted before the use and its last expression taken as the value, with the locals it declares kept apart from others of the same name in the function.
with migrate translates the GCC atomic builtins to std.sync's Atomic …
with migrate lowers a GNU statement expression used as a value: its s…
ehartford commentedon Nov 23, 2026
After #3567 (atomic builtins) and #3569 (statement expressions as values): the roundtrip lane's remaining stop in the migrate step is
__builtin_alloca(unsupported compiler builtin '__builtin_alloca': no structural lowering). The C backend emits it on purpose for a closure created in a loop (CCodegen.closure_value_text: one environment per evaluation; a function-level slot otherwise). With has no stack-allocation primitive, so whatwith migrateshould make ofallocais a language decision (refuse as today; a local where provably not in a loop; heap with a free at every return; a stack-allocation primitive). Waiting on that ruling; not worked around.Also waiting on a ruling:
_Atomic Tpresented asAtomic[T](brief given to Eric 2026-11-23). Verified today: a header import presents an_Atomic intfield as a plaini32that safe code writes non-atomically, and translates an inlinec->refs++as a plain add.A C body that reads or writes an _Atomic object with plain operators …