Repository navigation
Description
Summary
The with migrate preamble is the source of the largest remaining
decl/def divergence class found by tools/rt_decl_audit.w (D30 R2c, #761):
src/CiMigrate.w:647 extern fn with_realloc(ptr: *i8, old_size: i64, new_size: i64) -> *i8
src/CiMigrate.w:648 extern fn with_free(ptr: *i8) -> Unit
src/CiMigrate.w:649 extern fn with_memcpy(dst: *i8, src: *i8, n: i64) -> *i8
src/CiMigrate.w:650 extern fn with_memmove(dst: *i8, src: *i8, n: i64) -> *i8
src/CiMigrate.w:651 extern fn with_memset(ptr: *i8, c: i32, n: i64) -> *i8
src/CiMigrate.w:652 extern fn with_memcmp(a: *i8, b: *i8, n: i64) -> i32
against the rt definitions, all *mut u8 / *const u8:
rt/rt_core.w:1402 pub fn with_realloc(ptr: *mut u8, old_size: i64, new_size: i64) -> *mut u8
rt/rt_core.w:1405 pub fn with_free(ptr: *mut u8) -> Unit
rt/rt_core.w:1417 pub fn with_memcpy(dst: *mut u8, src: *const u8, n: i64) -> *mut u8
rt/rt_core.w:1421 pub fn with_memmove(dst: *mut u8, src: *const u8, n: i64) -> *mut u8
rt/rt_core.w:1430 pub fn with_memset(dst: *mut u8, c: i32, n: i64) -> *mut u8
rt/rt_core.w:1434 pub fn with_memcmp(a: *const u8, b: *const u8, n: i64) -> i32
Every migrated library inherits the wrong shape: lib/std/re/defs.w:99-105
(pcre2) carries these decls verbatim, and ~217 call sites across 15
lib/std/re/pcre2_*.w files cast as *i8 to match. lib/std/zlib/defs.w
has the same preamble. Also in the same preamble: with_bswap16/32/64
declared u16/u32/u64 against i16/i32/i64 defs
(rt/rt_core.w:3603-3605).
Why it is a migrator bug, not a sweep
Per the C-library-migration methodology the fix goes in the migrator and the
libraries are re-migrated; hand-editing 217 generated call sites is the
anti-pattern. And the migrator itself already disagrees with itself — three
paths derive the shape independently:
| path | free shape |
|---|---|
preamble src/CiMigrate.w:648 |
*i8 |
structural lowering src/CImport.w:15921-15925 |
casts arg as *i8 |
text mapper ci_map_libc_call src/CImport.w:15943 |
as *mut u8 |
That is a per-path ABI derivation inside the migrator — the same shape D6
forbids in codegen (FnAbi is the one source of truth). The preamble should
be the one place the runtime-extern shapes live, spelled from the rt defs, and
both lowering paths should read it.
Interaction with #761
#839's declare/define unification reconciles these at LLVM level today, so
nothing fails at link. But the contracts are still derived twice, which is
#761's corruption class, and the *i8/*mut u8 mismatch will be a §16.3e
error once R4 lands (an extern fn whose declared pointee type disagrees
with the def's). tools/rt_decl_audit.w is the exit gate: this issue closes
when it reports zero divergences for the alloc/mem/bswap families.
Fix shape
- Correct the preamble strings in
src/CiMigrate.wto the rt shapes. - Make the structural
free/malloclowering (CImport.w:15880-15930)
andci_map_libc_callemit*mut u8/*const u8casts (memcpy/memcmp
srcargs are*const). - Re-migrate pcre2 and zlib (
with migrate), validate via each library's
own migrated test suite (pcre2test, zlibexample). - Re-run
tools/rt_decl_audit.w— the alloc/mem/bswap rows must be gone.
Activity
src/lib/rt/tools: align the remaining non-migrator with_* decls with …
lib/test: hand-written files drop the migrator's old *i8 alloc/mem sh…
ehartford commentedon Aug 21, 2026
Migrator half landed (a12ea56 + 0120a80, battery in flight)
ci_rt_ptr_mut()/ci_rt_ptr_const()insrc/CiMigrate.ware the onespelling; preamble, both structural IR paths, the text-mapper helpers, and
CiPrint's struct init/copy read them. No literal
*i8emission remains.with_bswap16/32/64rt defs flipped to unsigned (zero callers; the bodiesconverted on entry anyway), so the preamble's
u16/u32/u64is now truth.g_ci_translate_migrate_modewasset only on the single-file CLI path.
migrate_c_directory— what thepcre2/zlib build targets use — ran every mode-gated rule with the flag OFF.
That's what produced the "untranslatable
adler32_combine: callsnon-emitted
adler32_combine_" failure (the c_import-only Windows: c_import behavior tests fail on MSVC headers #799 filter).Flag now owned by
ci_migrate_file_innerfor every caller.c-migrator-basic-tests+c-migrator-core-testsgreen under stage1; theregenerated
direct_runtime_memory_calls.wcarries*mut u8/*const u8and runs to exit 0.
pcre2-migrate → pcre2-build → pcre2-testproducer edges (zlib's chain had them); added.
Re-migration of the libraries is blocked — two pre-existing bugs
deflate.c(ClangBridge.w:2574,MacroSession.names[idx]=0x2b). adler32/compress/crc32 now migrate clean with the flag fix; deflate is the first unit with a large macro surface. Reproduces on the installed seed.std.tlshandshake fails against every host (bisected to before today), sopcre2-referencecannot fetch the tarball. The action framework scrubs its scratch dir before each run, so hand-seeding the archive is not a lever.Until those land,
lib/std/re/defs.w(10 rows) andlib/std/zlib/defs.w(3 rows) keep the old shape and
tools/rt_decl_audit.wstays at 13. Whenpcre2 is re-migrated,
rt/regex_runtime.whas fivewith_free(x as *i8)casts that must flip to
*mut u8in the same commit (they currently satisfythe old decl; I tried flipping them early and backed it out for that reason).
Steps 3–4 of the fix shape in the description remain open; this issue stays
open until the audit reads zero for the alloc/mem/bswap families.
migrate: one source for the alloc/mem pointer spellings; migrate mode…
std/zlib: re-migrate with the anon-union init fix (#880, #885, #886)
ehartford commentedon Aug 23, 2026
zlib half done (ca91e09)
lib/std/zlibis re-migrated with the current migrator and validated::zlib-testpasses andbehav_zlib_std.wpasses at -O0 and -O1. The threemigrator bugs that blocked it are fixed — #882 (SIGSEGV), #884
(prelude-collision libc calls), #886 (anon-union init).
tools/rt_decl_audit.wis at 7 divergences, all
lib/std/re/defs.w(pcre2).Remaining: the pcre2 half is blocked on #883 (std.tls P-256 ECDH — the
handshake can't fetch the tarball). Once #883 lands, re-migrate pcre2 the same
way and the audit should reach 0.
ehartford commentedon Aug 29, 2026
Migration-correctness campaign COMPLETE: upstream RunTest fully green
with build :pcre2-testnow reportsVERIFIED: migrated pcre2test passes upstream RunTest for the 8-bit corpus— all groups 0–29 plusheap(was 14 failing groups when the RunTest gate was first run properly).Five migrator fixes, every one a variant of a single defect family — the migrator recovers a C string from the wrong libclang text form and keeps only part of it:
adfbcc94pso_listverb namesea8b20a7#-stringize token (XSTRING(PCRE2_CODE_UNIT_WIDTH)) dropped by the plain literal joinUTF-8→UTF-)d735f80b/* */comment →pcre2_get_error_message= −298e0daae0STRING_UTFn_RIGHTPAR="<concat>, <length>"macro form; peel the trailing, <n>and expand the string part(*UTF8))b60edabcPUTCHARS(STR_STAR_NUL)) — the cursor extent maps to the macro definition sites in the header, so token/source text is a slice of pcre2_internal.h's#definelines; prefer the invocation-argument expansion(*NUL),:])Method note: the breakthrough (d735f80, ten tests at once) came from a one-shot pipeline dump — one instrumented migrate printing every string-pipeline stage's length — after blind print-rebuild cycles had failed; the truncation was a post-expansion clobber, invisible to any single-stage read.
Battery (build/:fixpoint/:test) for the 5-commit batch in progress; then reseed →
:pcre2-promote→ rt_decl_audit → 0.ehartford commentedon Aug 30, 2026
#880 COMPLETE — all acceptance criteria met
VERIFIED: migrated pcre2test passes upstream RunTest for the 8-bit corpus— all groups 0–29 plusheap(from 14 failing groups at the campaign's start).87df3b31replaces the 2026-05-19lib/std/rewith the re-migrated zone; the embedded regex runtime (:regex-runtime-ir) builds from it andstd.regexworks end-to-end.0 divergent decls / 524 rt defs / 829 extern with_* decls.The promote also surfaced and fixed two latent compiler-side issues:
f5355773/963abb56: the regex zone is compiled--no-preludefor the embedded runtime — the zone's shared defs now carry self-containedc_void/unreachable, andtry_eval_const_llvmgained the missingTY_EXTERN_FN/TY_FNcase (onecallout: nullfield was silently demoting whole global initializers to runtime-init — BSS zeros in a standalone object, so everystd.regexmatch returnedPCRE2_ERROR_HEAPLIMITwhile the identical code worked in-unit).1cbcece3: object-symbol fixtures adapted to the promoted API's honestunsafe fncontracts.ehartford commentedon Aug 30, 2026
All criteria verified above; closing.
migrate: resolve #if/#ifndef conditionals inside string-literal initi…
migrate/std.libc: bind vfprintf and vprintf as known libc functions
migrate: translate offsetof as a struct field value (pcre2test modlist)
migrate: drop the hardcoded pcre2 STRING_* pointer block (dup/shadowing)
migrate: a macro defined as a bare macro reference inherits its type
5 remaining items
sema: a parenthesized null keeps its pointer context through a cast
migrate: fix the pcre2 tail — uninit libc struct, return coercion, na…
build/pcre2: replace the isolated synthetic check with a cohesive com…
migrate: scope the two broad tail fixes to where they are correct
migrate: recover full macro-expanded string concatenation (#880)
migrate: expand a #-stringize token inside a concatenated string (#880)
migrate: don't mistake message text for an unexpanded macro (#880)
migrate: recover the string part of a "<concat>, <length>" macro (#880)
migrate: recover a fn-like macro's string argument at definition-site…
migrate: gate macro-arg string recovery on definition-site extents (#880
migrate: self-contained c_void and unreachable for the regex zone (#880)
std/re: promote the re-migrated pcre2; adapt the embedded regex runti…
codegen: const-fold function-typed global initializer fields (#880)
build/selfhost: adapt the pcre2 object-symbol fixture to the unsafe A…
codegen: a module-level global folds to data or initializes at runtim…