Skip to content

Retire the regex runtime shim and complete the bundle-backed compiler bootstrap - #1101

Merged
ehartford merged 42 commits into
mainfrom
wo-c4
Sep 10, 2026
Merged

ehartford merged 42 commits into
mainfrom
wo-c4

Conversation

@ehartford

@ehartford ehartford commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Retire the with_regex_* runtime shim. std.regex, compiler regex validation, and regex-literal codegen call the migrated PCRE2 engine through its .wo interface. The emitted-C bootstrap includes each bundle's corpus as source, so its compiler contains the engine it uses.

Bundle interfaces are parsed and collected on demand. Attributes, headers, and indented bodies remain one declaration; inherent impls are demanded by their target. Interface imports stay out of the ambient prelude, source declarations take precedence, and indexed name/signature lookups avoid repeated full-table scans.

Validation exposed ownership defects fixed in this batch: re-reading a moved binding's original AST could clear a borrowed string field; Regex destruction was an inherent method instead of Drop; compiled patterns borrowed leaked character tables; captures needed to retain their code; and function/closure cleanup left stale borrow rows. LLDB and allocator evidence are recorded in the fix commits and docs/wo_bundles.md. The drop auditor now uses the public allocation API and preserves candidate/baseline diagnostics separately.

A fresh macOS build also exposed an embedding dependency missing from the stage chain. The bootstrap embedding object deliberately has empty bundle slots, and stage2 had linked that object even after the real PCRE2 bundle existed. Warm release artifacts hid the defect. Stage2 and stage3 now explicitly depend on and link a separate embedding object containing the completed bundle. A missing selected object fails loudly. docs/macos-stage-bundle-debug.md records the cold reproduction, empty symbol ranges, and LLDB's false embedded_bundle_present return at the interface-registration branch. The cold compiler reproduced both CI failures; rebuilt stage2 and stage3 pass selfcheck, and the scratch-directory CLI test passes.

Latest local validation is on 2d68367, Darwin arm64, in a fresh worktree using the pinned published seed and the project's static LLVM SDK:

Gate Result
Full build Pass, 188.0 s
Fixpoint Identical stage2/stage3 compiler objects, 417.8 s
Compiler audit 2,505,974 facts, zero violations
Full test suite All targets green, 1,225.6 s; all 987 behavior files ran uncached
Stage3 executable Built; compiler selfcheck passes
Seed compatibility Published v0.15.2.0 builds stage1, 181.0 s
Test-green / last-green Current commit and compiler hash verified; seed archived

Verified release SHA256: f721b300fed3fe93d060eb30aad8946ac15fecda8ac904d97836cfad9c719895. CI for this commit is tracked by the PR checks; local evidence is not a claim that pending CI lanes have passed.

The earlier C4 ownership battery passed 15 move-audit cells and 115 drop-audit cells with no unexpected verdicts or baseline regressions, plus the full emitted-C compiler bootstrap. The subsequent cold-build correction changes build/link artifact selection. The accepted local interleaved C4/baseline performance ratios were 1.018 and 1.032; exact commits and measurement conditions are in docs/wo_bundles.md.

Refs #955, #1036, #1038, #1043, #1098, #1099. Tool gaps found during validation are tracked in #1096, #1097, and #1100. No release is published by this PR.

Eric Hartford added 30 commits September 7, 2026 19:13
…ce (C4.1)

lib/std/regex.w imports std.re.* — resolved to the embedded pcre2
interface (D39) — and calls pcre2_compile_8, pcre2_match_8,
pcre2_substitute_8 and the rest itself, as std.zlib calls its engine.
The ten with_regex_* externs are gone; the shim's helper bodies
(general context, C-string copies, error messages, the match ovector,
substitution) are private functions here. The Regex struct keeps its
ten-field order (codegen builds a literal's value field by field), and
Regex.__capture_count joins Regex.__literal_code as the second
regex-literal entry point so codegen never names a runtime symbol.

Verified against the seed's embedded bundle as a renamed user copy
(compile, errors, captures, names, find_all, replace/replace_all with
$n/${name}, split, clone, captures_all, flags): identical output and
the same debug-allocator verdict as the shim path (8 pre-existing
leaks — a per-compile tables block and a 256-byte block — follow the
shim's regex_runtime_malloc into the facade unchanged; separate fix).
…ations

warn_large_copy_type fired for every impl Copy in scope, so once the
prelude's std.regex reaches pcre2's interface (C4.1) hello world would
print eight warnings about pcre2_real_match_data_8 and friends — types
the user cannot change. Gate it on sema_path_is_user_lint_source, the
rule every other style/perf lint already follows.
validate_regex_literal compiles the literal with Regex.compile_flags and
reads num_captures/capture_names, like any program; the six with_regex_*
externs are deleted. The compiler is one more user of the facade, and
its own link selects the embedded pcre2 bundle on demand (D30, D38).
The flag check and both diagnostics ("invalid regex flag", "invalid
regex literal: <pcre2 message>") are unchanged: the facade's message is
the same pcre2_get_error_message_8 text the shim returned.
…t replaces with_regex_capture_count (C4.3)

gen_regex_literal_value resolved Regex.__literal_code through the
unit's generated functions but declared with_regex_capture_count as a
fresh C-ABI symbol per path (ensure_regex_runtime_fn). Both entry
points now resolve the same way (regex_facade_fn): the facade's
generated function, else its link name, else a loud error — never a
declaration codegen invents. test/codegen/regex_literal_code_abi.w
pins both entry points as the facade declares them and checks a
literal agrees with them.
… without the prelude (#954)

A corpus is migrated C; rt/regex_runtime.w was always compiled
--no-prelude and the bundle build inherits that. With the prelude on,
std.regex (C4.1) reaches std.re.* from the prelude closure, and the
frontend records the corpus modules under two spellings — the closure's
tree-relative one in decl_source_paths, the root's absolute one in the
resolver's module graph — so the interface emitter reports every
declaring module as missing from Sema's module graph (#954, exact
lines there). Verified with stage1: the object and the interface built
--no-prelude are byte-identical to the seed's, and both fingerprint
passes agree (0257a06a…).
…(C4.4, D30)

rt/regex_runtime.w is gone: std.regex calls the pcre2 bundle itself
(C4.1), the compiler's regex-literal validation and codegen go through
the facade (C4.2, C4.3), so nothing references a with_regex_* symbol.
Retired with it: the five regex-runtime-ir/-object lane pairs and the
with_ir_target helpers in build.w; the regex_runtime_o blob in every
embedded-objects set (native, bootstrap, cross darwin/linux, cross
windows x86_64/aarch64) and the empty-blob symbols in the Linux and
Windows bootstrap shims; install-regex-runtime; Link.w's
with_embedded_regex_runtime_o externs, name-to-slice entry,
link_stage_undefined_symbols_need_regex_runtime, its five consumers
and the transitive probe (25f4f58) — the shim was the only on-demand
object that referenced a bundle, so the probe has no subject left and
selection reads the program's own undefined symbols; build/runtime.w's
stale-object entry; CCodegen's ten C prototypes; CiMigrate's
borrowed-str mask entries; build/emit_c.w's with_regex_ harvest, the
"found no runtime exports" check that existed for it, and
regex_runtime.o on the C links; build/package.w's regex_runtime.c
emission and README lines; the regex_runtime.a archiving in the two
selfhost emit-C link paths; the bootstrap runbook's Windows file lists.

Cross lanes: per-target bundles (#946) already link a cross program's
regex through the embedded bundle for its target; the D38 refusal
stands when no bundle matches.
…ling command; the ABI fixture's slot global no longer shadows the facade's parameter

test_command_collect_targets had its own value-flag list, so
`with-stage1 test --link-bundle out/wo/pcre2 f.w` tried to open the
bundle prefix as a test file — and stage1 (no embedded bundle) needs
the flag for every program now that the prelude's std.regex reaches
the interface. It defers to cli_option_takes_value. The `ir` command's
comment stops naming the retired shim.

test/codegen/regex_literal_code_abi.w: a module-level `var slot`
trips "shadowing is not allowed for 'slot'" against
Regex.__literal_code's parameter of that name; renamed, and the raw
pointer is taken outside the unsafe blocks so the single-thread-proof
note about unsafe global access stays silent.
…odules it names, not their transitive closure

init_module_graph marked every module reachable from std.prelude as
globally visible. With std.regex reaching std.re.* (C4.1) that made the
pcre2 interface — 33 modules — and, through pcre2_maketables' own
`use std.libc`, std.libc's stdio globals ambient in every program:
stage2 failed on src/main.w's `let stdout` ("shadowing is not allowed
for 'stdout'"). The prelude tier is the enumerated list (§18.2, D29):
the prelude modules and the modules they name are ambient; what those
modules import for themselves stays theirs. For the previous prelude
the closure and the direct imports were the same twelve modules, so
nothing that resolved before resolves differently now.
…d, never a body's

The emitter printed every `use` line of the module. A corpus module's
`use std.libc` is implementation (its body calls malloc and the ctype
functions); through the prelude's std.regex it put std.libc's stdin,
stdout and stderr globals into every program's flat global scope, where a
local named stdout is a shadowing error (Sema's binding model allows no
shadowing at all — D29 campaign B is where module identity for globals
lands). A section now imports its corpus siblings, and a module outside
the corpus only when one of the section's declarations names a type it
declares (the emitter records, per module, the type symbols its printed
declarations named, and every type declaration's canonical module).
pcre2's interface loses exactly one line (`use std.libc` in
pcre2_maketables); its fingerprint is unchanged (0257a06a…) and both
passes agree, so the declaration graph never needed it.
… with_libc_* prototypes come from std.libc's declarations (#955)

The C backend declared `extern int8_t* strchr(const int8_t*, int32_t)`
against <string.h>'s char* signature and `extern void* __stdinp` against
<stdio.h>'s FILE*, and skipped every with_* prototype on the assumption
that with_runtime.h declares it — which it does not for the libc
bindings rt_core.w exports (with_libc_open and friends), so a
--no-prelude unit calling them was undeclared. Now: a function the
migrator's libc knowledge names (ci_libc_symbol_allowed_as,
ci_libc_simple_rename, ci_migrate_preamble_name_is_modeled_libc) gets
no prototype — the header's declaration is the truth and a With spelling
never disagrees with it; an extern var the headers own (stdin/stdout/
stderr and the Darwin __std*p) is not redeclared, the emitted reads
convert implicitly; with_libc_* externs are emitted from their std.libc
declarations, prelude or not.
…orpus std/re), emitted by the release compiler (C4.5, #955 option a)

With the shim gone the compiler's C references pcre2 through std.regex;
the emit-C lane links no bundle, so the corpus compiles into the same
unit: emitc_build_compiler_c passes --bundle-corpus std/re, and both
lanes that emitted the compiler through the in-process workspace (the
build driver's seed — the #761 mixed-world class) now run the release
compiler as a subprocess: bootstrap-c-emit-sources takes the release
binary as its argument and depends on build; emit-c-roundtrip uses its
compiler input. emitc_build_compiler_c_workspace is gone.
…s before the first import resolves

compile_source_text, compile_source_text_with_config and
compile_entry_source_texts — the entries behind `with test`, the build.w
runner and workspace compiles — never called load_link_bundles, so a
program reaching std.re.* through the prelude's std.regex (C4.1) resolved
the corpus to the checkout's source (six seconds of Sema per test, three
corpus warnings per compile, behavior-tests 373 s instead of 144 s) and
outside a checkout found no module at all. They load the bundles like
compile_file does.
…hrough an import, never from the flat global scope (D39, D29)

The pcre2 interface exports 3,057 storage globals and constants — its
config and libc macros among them: PACKAGE, NULL, BUFSIZ, CHAR_MAX —
and every program now reaches it through the prelude's std.regex. Sema
registered them all in the one flat global scope, so a program's own
`const PACKAGE` merged with pcre2's (behav_comptime_aggregate_freeze:
main read PACKAGE as a zero-sized value and codegen emitted
`with_hashmap_get_ptr(i32 undef, …)`), a c_import's NULL was a
shadowing error, and a top-level `let ptr` collided with a facade
parameter. Interface-provided globals now live beside the scope:
register_top_level_global_decl records them in interface_global_index /
interface_global_paths (a binding index and the declaring module) and
scope_lookup consults that table only when the current module can see
the declaring one (decl_visible_from_current). MIR and codegen never
read the flat scope, and the facade's own reads (std.regex imports its
engine) resolve as before. std.regex's regex_engine_free parameter is
`block`, not `ptr`, which a fixture declares at top level.
…module cannot see (§18.1)

scope_put_at treated every flat-scope global as in scope, so a prelude
function's local or parameter collided with any program's top-level
global of the same name — pcre2test's `buffer` and a migrated C
program's `table` against std.regex's locals (pcre2-wo-drift and the
c-migrator ir-global-init-list case), and the class is older than C4:
every local name in a prelude module was a landmine for user globals.
A local now shadows a global only when decl_visible_from_current says
the current module cannot see the global's module (recorded per symbol
in global_value_decl_paths at registration); pop_scope hands the
global its scope-map slot back when the local's scope ends. A collision
with a visible global, or with another local, is shadowing as before.
std.regex's substitution buffer is `out_bytes`/`out_len`.
… interface is registered under --emit-c (C4.5, #955)

emit-c-smoke's prelude case emitted a program whose std.regex referenced
pcre2_real_convert_context_8 and friends as interface declarations —
types the C unit never defined, since no bundle object joins a C link.
Compilation.emit_c now sets emit_c_in_unit before its compile and
register_embedded_bundle_interfaces registers nothing under it, so
every use of a bundle-provided module resolves to the corpus source (in
a checkout; outside one it is a loud missing-module error) and the
corpus is emitted into the same C unit. --bundle-corpus std/re on the
compiler's own emission stays as the explicit spelling.
The rebase onto the least-ceremony sweep (c25e844, 2bb9a3f) left eight
added lines in the old spelling; the facade's C-string copy now stores
the byte s[i] yields directly.
…cit import; a program's own declaration wins everywhere

Three more consumers of the flat namespace surfaced once every program
carries pcre2's 3,057 interface globals through the prelude:

- the var-rebind binder (scope_put_consuming_rebind_at) reported
  "shadowing is not allowed" for std.regex's `var table` against a
  program's top-level `table` — the same rule scope_put_at got, now one
  helper (binding_is_unseen_global / shadow_unseen_global) used by both,
  keyed on the global's recorded binding index rather than the first
  scope start (which is 0: a module scope is pushed before globals);
- visibility: decl_visible_from_current walks every import edge
  transitively, so from any program the prelude's closure reaches
  std.regex's engine and pcre2's PACKAGE was 'visible' — both rules now
  use module_visible_no_prelude, the explicit-import walk (§18.1), and
  the interface fallback in scope_lookup requires a known module;
- MIR's ensure_global_local scanned the pool for the first declaration
  of the name and found the interface's `pub let PACKAGE: str` ahead of
  the program's `const PACKAGE: Package` (behav_comptime_aggregate_freeze:
  main read a str where a struct was expected and codegen emitted
  with_hashmap_get_ptr(i32 undef, …)); it scans source declarations
  first and interface storage only when no source declares the name,
  Sema's own order.

An unimported interface global is now an undefined variable (D29's
fallback tier is not implemented; nothing else offered it before C4).
…pus exposed; measurements (C4.6)

docs/wo_bundles.md gains "Shim retired (batch C4)": what went, how the
emit-C lane compiles the corpus in-unit, the flat-namespace defects the
prelude→interface reach exposed and what landed for each, and the
measured costs — release binary −534,096 B, hello-world check 0.03 s →
0.23 s (Sema over the 4.4k-line interface, not parsing), behavior-tests
144 s → 414 s, clean builds 251.8 s → 295.8 s under a concurrent
battery. decisions.md D30 records the regex seam as retired.
…; the test runner's stdout/stderr locals are out_text/err_text

The compiler declared `extern fn abort() -> Unit` (Ast.w, CiIR.w, Sema.w,
LlvmBridge.w), so every *_phase_bug helper looked like it returned and
its callers carried a fallback the checker could not see was dead
(`return 0`, `0`, `1`, sema_deref_info_none(), empty_cstr()…). With
the corpus compiled in-unit for the emit-C lane (#955 option a) the
declaration also collided with pcre2's `__ci_unreachable() -> Never:
abort()` ("return type does not implement Default"). abort is Never;
the checker flagged 29 statements unreachable and they are deleted
(`with -n` over the sites, `with check src/main.w` as the oracle, one
round). The two test-runner locals named stdout/stderr in main.w are
out_text/err_text: std.libc's `extern var stdout` reaches main.w by an
explicit import (CiMigrate) and, in the one-unit emit-C compile, defs.w
declares it too.
…th_runtime.h follows the runtime; a str constant argument is its own addressable literal (#1038)

CCodegen skipped every with_* prototype on the assumption that the
header declared it, and the header still spelled the fs/exec/env
wrappers by value (with_str) although the runtime and the compiler's
externs have taken &str since 7d8d085 — 20 "passing 'const with_str *'
to parameter of incompatible type 'with_str'" errors in the compiler's
C. Now: a with_* extern outside the fixed block (prelude_block_declares:
the str, fmt, memory, fiber and sysinfo entry points the backend writes
itself) gets its prototype from the With declaration; the header's 30
stale prototypes follow the runtime (const with_str * for &str,
with_scope_track's result_buf, with_channel_create's drop_fn) plus five
whose pointer spellings differed from the backend's (uint8_t * for
*mut u8), audited by a With script against rt/*.w: 200 checked, 0 stale.
call_arg_address_text no longer wraps a WITH_STR_LIT compound literal in
a second one (12 "initializing 'const char *' with … 'with_str'").
The compiler's C now compiles down to four errors in two further C-backend
defects (a global's proxy local zeroed as `global = 0` for an array
global; a str field reset through a const receiver after a borrowing
concat) — filed separately.
… itself — the emit-C lane sees the surface the .wi carries (#955, D39 §3.4)

Under --emit-c the pcre2 corpus is compiled in-unit (#955 option a), so its
`use std.libc` put std.libc's `stderr` global on the explicit-import walk
from every module that reaches std.regex, and main.w's new
`let stderr = with_fs_read_file(err_path)` (reduce --test) was refused as
shadowing — in that lane only; the .wi carries no std.libc, so the normal
lane compiled it. The walk now stops at a corpus module's non-corpus
imports (its siblings still propagate), which is the surface the interface
emitter renders. Sema learns the corpus from the Zcu when it is configured.
The fixture is check-only: the runner's native run path applies only the
header args it knows, `check` takes them all.
…by the mark, never by the local's name

MirLower's ensure_global_local creates a local named after the module
global it stands for, and both backends recognised it by that name alone:
CCodegen.local_global_sym, the LLVM "pre-populate mir_local_ptrs" loops
(function, closure, drop-table and module-init bodies) and
mir_try_init_const_local. That was safe only while Sema refused every
local that shared a global's name; the §18.1 unseen-global shadow
(0bbf38a7) made it ambiguous, and the in-unit emit-C lane emitted main.w's
`let stderr` (reduce --test) as the bare libc global — five "use of
undeclared identifier 'stderr'" from cc. MirBody.local_is_global is set by
ensure_global_local, copied by the body cloner, validated for length,
shown as [global] by --dump-mir and exported as flag bit 2 to analyze;
every proxy lookup requires it.

Evidence (release binary built from this tree): the check-only fixture
passes; `build --emit-c --bundle-corpus std/re` of the five-line repro
emits C with no bare `stderr`; --dump-mir marks the nine interface-global
proxies of the repro and not the local; the package lane
(bootstrap-c-emit-sources through LLVM stage2) is green.
…rm and check_module into its phases ([profile] sema.<phase>)
…ompile that names nothing from the bundle pays only the lex (D39)

Every Sema (the comptime pre-pass, the transform's, the frontend's) ran
collect_declarations over the 3,828 declarations of the embedded pcre2
interface — 97 ms each, three times per compile — and then checked the
87 types' field defaults (70 ms) and scanned 4k-entry visibility vectors
per identifier in check_bodies (46 ms): hello-world `with check` had gone
from 0.03 s to 0.23-0.46 s and the behavior lane from 144 s to 414 s.

Now SemaDecl.prepare_interface_demand runs first: S is every symbol a
non-interface node carries (identifiers, member and type names, struct,
variant and use names — every node records its file, so a .wi section's
nodes are told apart by file id); an interface declaration whose name is
in S — a method by its bare name too, an impl by its target type — is
demanded and its own subtree's symbols join S, to a fixpoint. The three
collection passes, cycle/deferred/derive/generic validation, no-std and
c-export checks, check_bodies, the comptime transform's per-declaration
loops and codegen's per-declaration emission loops skip an undemanded
interface declaration (decl_is_lazy_skipped); field defaults skip every
interface type (its bundle build checked them). Over-approximation only
reproduces the eager state for that declaration; a compiler-synthesized
name outside S would meet the uncollected declaration as a phase bug,
never a silent miss. astpool_clone_deep now keeps each node's file id —
it re-stamped every clone with file 0, which left the two Semas after the
transform eager.

Hello-world check, stage1 on this box: collect_declarations 97 → 2.8 ms
per Sema, field defaults 70 → 0.4 ms, bodies 46 → 3.2 ms; wall 0.46 →
0.07 s (parse 17 + resolve 15 + imports 6 + comptime 17 + sema 7 ms;
decls=4771, the bundled path). The regex programs, the ABI fixture and
the compiler's own check pass.
…on — the emitter, the fingerprint and the check-wi pass read the full tables

compile_bundle_interface_root registers the .wi's sections and compiles a
root that imports them; lazy collection then skipped them and the
emitted-interface check reported every global as "has no finalized type"
(pcre2-wo-build red). Zcu.interface_eager is set there and implied by
--bundle-corpus; configure_tracked_input_sema hands it to every Sema and
the transform's Sema copies it (with bundle_corpus, which it never
carried). :pcre2-wo is green again; hello-world stays 0.07 s, decls=4771.
… indexed, never a scan of every declaration per identifier

symbol_visible_from_current, decl_node_visible_from_current,
private_symbol_path_from_current, get_visible_sig and
has_extern_var_decl walked decl_visibility_syms / sig_names / every
declaration from the end on each call — check_ident runs two of them per
identifier, so the cost grew with the unit (46 ms of hello-world's
check_bodies while the interface's 4k entries were collected). Each is
now a map from the symbol (the node; the resolved name text for
signatures, which get_visible_sig compares) to the newest record, older
records chained newest-first — the exact order the scans walked — built
where the records are pushed (record_decl_visibility, add_sig,
collect_extern_var).

Behavior lane on this box (release compiler, 980 files, decls=4771 —
the bundled path): 177.7 s before, 177.0 s after — with lazy interface
collection already in, the vectors hold only the source's entries and
hello-world's check_bodies is 2.9 ms either way; the index is for the
large unit. Hello-world check 0.07 s before and after.
…laration order; an interface declaration of the same name never displaces it (D39)

pcre2's interface declares is_alpha, is_digit, to_upper… beside
std.string's, and `pub extern fn abort` beside every module's own. The
flat global scope (D29-B pending) resolved each collision by declaration
order — later wins — and the order happened to put the interface first,
so the source definition kept fn_decl_nodes, fn_decl_source_paths and the
LLVM function. Once interface declarations are merged after every source
module the order flips: the source body is skipped as shadowed and its
function left declared without a body ("Global is external, but doesn't
have external or weak linkage: @is_alpha"), and an extern's source path
moves into the migrated-C zone so `unsafe: abort()` becomes a block with
no unsafe operation. Three rules make the outcome order-independent:
collect_fn_decl and collect_extern_fn let an interface declaration yield
to a source one (its visibility record stays, its signature does not), and
declare_function_at_inner never lets a declared-only declaration displace
a source-defined function value.
…ile that names nothing from the bundle pays only for the section's use lines

The 4.4k-line .wi was lexed and parsed twice per compile (Resolve for
its imports, then the import worklist), 13 + 16 ms on hello-world and
~35 s over the 980-file behavior lane, with lazy collection leaving
nothing else. Now Resolve reads an interface section's imports from its
`use` lines (they head every section, so their spans hold), the worklist
parses only those lines too, and once every source module is in the pool
merge_interface_sections_on_demand parses declaration lines by demand: S
is every symbol the source's nodes carry; a line whose name is in S — a
method by its bare name, an impl by its target type, a line the
classifier cannot name always — is parsed as a chunk with its own file
id, its nodes extend S, to a fixpoint. A .wi root and a bundle build
(interface_eager) still parse everything; Sema's lazy collection then
sees only these declarations. InternPool.lookup_symbol answers without
interning.

Hello-world check, stage1 on an idle box (first cold run excluded):
0.07 → 0.05 s; `[profile] frontend.interface 3.4 ms sections=32 lines=59
of 3405`, parse decls 4771 → 1366. The regex programs, the abort/unsafe
repro, the compiler's own check, the ABI and emit-C fixtures and the
regex behavior tests pass.
…fallbacks (abort is Never); FnAbi.w is main's
…tions — is_local_decl takes the pool's tail

After the import merge the pool is prelude → imports → root and
Sema.is_local_decl counts the last root_local_decl_count entries as the
root's; chunks appended behind them made every root type imported:
derives were not generated, sealed-trait impls were foreign, `copy` had
no Copy — 14 behavior tests. The merge now rotates the root tail back to
the end (decl list and the per-declaration path, file-id and c_import
vectors together). The 14 pass; hello-world stays 0.05 s, decls=1366.
Eric Hartford added 10 commits September 8, 2026 00:03
…ines as text — no use declaration of a section enters the pool

The 32 sections' 937 `use` lines were still lexed and parsed twice
(Resolve, then the import worklist), each resolved to a module path on
its own, and carried through the comptime transform's clone before the
strip: on a behavior test that is parse 9.7 vs 3.5 ms, resolve 9.9 vs 3.8,
imports 4.2 vs 0.3, decls 1368 vs 447. Resolve now writes a section's
import edges straight from the text (process_interface_module,
resolve_use_file_dotted — the same records a parsed module gets); the
worklist enqueues a section's imports from the same lines with a
per-compile name→path memo (35 distinct modules); a section's path and
text enter the pending lists together, before its imports recurse (an
interleaved pair had attributed pcre2_compile_8 to pcre2_compile_cgroup.w,
so its link name hashed the wrong module and the bundle went unlinked).

behav_derive_clone check: 48 → 40 ms (parse 5.5, resolve 10.3, imports
0.5, interface 4.7; decls 463); hello-world 0.04 s; the regex programs,
the abort/unsafe repro, the compiler's own check, the fixtures and the
regression set pass.
resource_prelude generated private with_alloc/with_free declarations with
obsolete *i8 signatures. C4 exposed those replacements as argument errors
inside std.regex before 113 of 115 probes could reach the allocator.
Use std.mem.alloc/free_mem and remove the unnecessary constructor unsafe
block. Keep every shape, destructor-count expectation, and leak check.

Keep candidate and baseline probes in separate per-run directories so a
baseline run cannot overwrite the candidate's failure diagnostics.

Root proof: LLDB Sema.add_sig breakpoint, called by
Sema.collect_extern_fn, observed w1=32 (with_alloc), first w3=81 and then
w3=20 in the same Sema instance. The generated root extern replaced the
imported return signature. The three-line repro reports *const i8 at
std/regex.w:117 where pcre2_get_error_message_8 expects *mut u8.

Validation: check tools/drop_audit.w passed; corrected drop audit reports
115 cells, 0 non-PASS, 0 regressions vs pinned v0.15.2.0, wall 102.6s.
The public-API probe also passes both compilers with WITH_ALLOC_NO_REUSE=1
and --debug-alloc: destructor sum 1, leak count 0.
The interface merge treated every physical line independently. LLDB on
the reduced consumer `use std.wi_demo` observed interface_line_name with
kind=2 and text `impl Pair:` returning a zero-length string (x1=0).
The at<0 branch incorrectly required a trait ` for ` clause. The live
Zcu.parse_interface_chunk argument then contained 282 bytes including
orphaned move/mut/read methods, without their impl header.

Demand inherent impls by their target and group canonical emitted headers
with leading attributes and indented bodies before the demand fixpoint.
Extend the bundle fixture with an unused attributed type, a demanded
packed type, and a consumer that demands no bundle types.

Proof: out/c4-validation/interface-name-lldb.log and
interface-chunk-lldb-confirmed.log (only the first 282 chunk bytes).
Verification: seed check src/main.w; :dev (78.9 s); reduced import;
original consumer output; emitted interface byte comparison; source and
interface fingerprints identical; packed consumer output ends `42 5`.
Full release battery follows this commit.
LLDB observed lower_let_binding restore expected_type to Unit (14) before cancel_scheduled_value_drop_for_receiver_expr queued a reset for borrowed field place 7. assign_operand_to_place already consumes the actual lowered operand; remove the redundant AST cancellation that clears a source after a borrowing str_concat_n.

The regression aborts before the fix and passes with stage1; the minimal native repro now prints abc twice and its emitted C passes cc syntax checking. Stage1 build: 86.5 s. Silent read-only-store audit gap filed as #1096; documented but ignored IR flag filed as #1097. Refs #1043.
Register Regex and Captures destructors through Drop. Compile using temporary locale tables, copy the code with PCRE2-managed tables, and free the temporary code/tables on all return paths. Captures retain their own code copy for named lookup after the original Regex dies.

Allocator address traps identify maketables (2048 bytes) and compiled code (256 bytes). LLDB observed detect_drop_functions skip the inherent Regex impl (trait 0 versus Drop 78); it also observed pcre2_code_free_8 and subsequent named lookup receive the same 0x1000c4870 pointer. New lifetime fixture changes from 16 leaks to zero with and without allocator reuse. Stage1 build 109.5 s; both regex behavior suites pass. Refs #1036, #1098.
Function setup and closure rollback popped six columns but retained scope depths and creation sites. LLDB observed refs/depth/site counts 1/1/1 become 0/1/1 at check_fn_body_with_sig_at+880. expire_dead_borrows_in_block then compared stale depth 2 with current depth 3 and skipped the dead view, rejecting owner consumption.

Use remove_borrow_at in both cleanup paths and validate column lengths before removal/expiration. Stage1 build: 95.4 s. Original D27 regression, NLL scoping, closure capture, dangling-view rejection, and baseline-preserving reduced check pass. Fixes #1099; reducer comparison gap tracked as #1100.
…tage2 binary when the battery fails

Both macOS attempts of #1101 failed behav_cli_test_command_args (1 of
987; passes locally with the same commit's compiler) and the selfcheck
corpus test, and the log showed only the capture file paths: the seed
that drives 'build :test' predates the runner's stderr tail, and the
files stay on the runner. The step dumps them on failure and runs the
out/stage/bin/with-stage2 binary — which p7 tests and selfcheck prefer
over the release binary, and which the Fixpoint step rewrites in place
right before the battery — so the next failure names its cause.
ehartford pushed a commit that referenced this pull request Sep 9, 2026
… includes out/command; handoff records #1104 and the Windows fcntl fix

#1103's linux x86_64 lane died in zlib-wo-drift with 'harness linked
against the stored bundle failed with exit code 139' and nothing else:
the harness's stderr sits in out/command/zlib-wo-drift and the seed
that drives the battery predates the runner's stderr tail. The linux
job gets the same Failure diagnostics step the macOS job got in
7910cf9, and both dump out/command captures. (Windows already uploads
its captures as artifacts.) docs/handoff.md: the fcntl seam, the probe
warning, and #1104 — va_list is an 8-byte pointer on every target, so a
variadic definition corrupts its stack on SysV x86_64; an ABI batch of
its own, landing between #1101 and #1103.
A cold pinned-seed build reproduced both macOS failures in PR #1101. LLDB stopped at Compilation.register_embedded_bundle_interfaces+136 with w0=0, w20=1, w21=0: its tbz skips slot zero because stage2 inherited bootstrap-lib/embedded_objects.o with empty manifest/interface blobs. nm placed all four boundaries at 0x1043aa4a0. --link-bundle links code but does not embed consumer data.

Give stage2/stage3 a separately produced embedding object with bootstrap runtime blobs and the tree bundle, and pass it explicitly through the build action to Link. Missing selected embedding objects fail loudly. The pinned seed accepts the graph; rebuilt stage2 passes selfcheck and behav_cli_test_command_args. Full batch verification follows this commit. See docs/macos-stage-bundle-debug.md for the preserved compiler, commands, and LLDB output.
@ehartford
ehartford merged commit d799c3b into main Sep 10, 2026
5 checks passed
@ehartford
ehartford deleted the wo-c4 branch September 24, 2026 16:58
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