fix(353): fold extended-const (base+N) data/element offsets — completes inc-4 fold#368
Conversation
…st bare global.get Completes the inc-4 static-PIC offset fold (#365). That fold handled the BARE `(data (global.get $base) …)` shape but left the extended-const `(data (i32.add (global.get $base) (i32.const N)) …)` shape as a verbatim `global.get`. But `wasm-tools component link` emits the extended-const form for EVERY N > 0 data segment (only N == 0 is bare) — so the common PIC case was still emitted as `global.get <defined base>; i32.const N; i32.add`, which wasm-tools accepts (lenient) but wasmtime REJECTS ("constant expression required: global.get of locally defined global"). Silent invalid output. Found by the inc-4 Mythos discover agent (which then died on a session-limit) and left the reproducing oracle behind. Fix: `ParsedConstExpr::reindex`'s `ExtendedGlobalGet` arm now folds the whole `base ± N` expression to a single `i32.const` when the leading global is a DEFINED constant-i32 (the `defined_global_i32_consts` map from #365), via a small stack evaluator `eval_ext_const_i32_with_base`. It declines (leaves verbatim) when the base is imported (#338), when a non-leading `global.get` appears, on any i64 op, or on an unbalanced sequence. - segments.rs: `eval_ext_const_i32_with_base` + the ExtendedGlobalGet fold; unit test covering base±N/*N, bare, and all three decline cases. - pic_extended_const_353.rs: execution oracle — a PIC-pattern component with an extended-const `base + N` data offset fuses, VALIDATES for wasmtime, and reads the data back correctly (was FAILING on main before this fix). Full meld-core suite green (0 failures); fmt + clippy clean. Refs #353 (ADR-7 path-H inc 4), #365, #338. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Mythos discover pass (extended-const offset fold) — NO FINDINGSSelf-conducted (backed by the execution oracle + a unit test on the evaluator's decline cases) + CI auto-Mythos as the independent second check. Hypotheses examined against the diff (
Empty-default |
Mythos delta-pass requiredThis PR modifies one or more Tier-5 source files (per Before merge, run the Mythos discover protocol on the
Why this gate exists: LS-A-10 The gate check on this PR will pass once the label is |
LS-N verification gate✅ 59/59 approved LS entries verified
Approved Failed LS entries(none) Missing regression tests(none) Updated automatically by |
Mythos delta-pass (auto)✅ NO FINDINGS across 1 Tier-5 file(s)
Auto-run via |
…s + static-PIC + same-memory transcoding (#369) Ships the full ADR-7 path-H arc (address-strategy seam #359, call-lowering seam #360, multiply-instantiated modules #362/#363, static-PIC fold #365, ADR record #354) plus the extended-const fold completion (#368), the #364 safety fix (#366), and same-memory string transcoding (#367). New capabilities: multiply-instantiated module support (RFC-46 Q1, MultiMemory, SR-55), static-PIC data/element offset folding (#353), same-memory string transcoding (#361). Safety: multiply-instantiated gated to the execution- verified MultiMemory case (#364); the sync same-memory cross-encoding miscompile closed (#360/#361). Falsification statements in CHANGELOG. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Completes the inc-4 static-PIC offset fold (#365) — which had a real gap found
by the inc-4 Mythos discover agent (it died on a session-limit but left the
reproducing oracle behind).
The gap
#365 folded the bare
(data (global.get $base) …)shape but left theextended-const
(data (i32.add (global.get $base) (i32.const N)) …)shape asa verbatim
global.get. Butwasm-tools component linkemits the extended-constform for every N > 0 data segment (only N == 0 is bare) — so the common PIC
case was still emitted as
global.get <defined base>; i32.const N; i32.add,which wasm-tools accepts (lenient) but wasmtime rejects ("constant expression
required: global.get of locally defined global"). Silent invalid output.
The fix
ParsedConstExpr::reindex'sExtendedGlobalGetarm now folds the wholebase ± Nexpression to a singlei32.constwhen the leading global is adefined constant-i32 (reusing the
defined_global_i32_constsmap from #365),via a small stack evaluator
eval_ext_const_i32_with_base. It declines (andleaves the expression verbatim) when:
global.get),global.getappears (value depends on a 2nd global),Verification
pic_extended_const_data_offset_valid_for_wasmtime_353—a PIC-pattern component with an extended-const
base + Ndata offset fuses,validates for wasmtime, and reads the data back correctly. Was FAILING
on main before this fix.
base±N/base*N/ bare, plus all three decline cases.meld-coresuite green (0failures); fmt + clippy clean.
Tier-5 (
segments.rs) → Mythos delta-pass below.Refs #353 (ADR-7 path-H inc 4), #365, #338.