Skip to content

feat(adr7): static-PIC data/element-offset fold — inc 4 (#353)#365

Open
avrabe wants to merge 3 commits into
mainfrom
feat/adr7-inc4-pic-topology
Open

feat(adr7): static-PIC data/element-offset fold — inc 4 (#353)#365
avrabe wants to merge 3 commits into
mainfrom
feat/adr7-inc4-pic-topology

Conversation

@avrabe

@avrabe avrabe commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Implements ADR-7 path-H, increment 4 — static-PIC data/element-offset folding
(#353) — reproduced and fixed in one branch.

The bug (reproduced)

A data/element segment offset const-expr may global.get only an imported
global. In a PIC dylib, (data (global.get $__memory_base) …) is valid because
__memory_base is imported. But when meld fuses a shared-everything graph, a
$main module provides __memory_base, so after merge it becomes a defined
global — and meld emitted (data (global.get $base) …) verbatim. wasm-tools
validates it (lenient); wasmtime rejects it at instantiation ("constant
expression required: global.get of locally defined global") → silent invalid
output from valid input.

(The spike's original "2 memories / new topology modeling" premise did not
reproduce on current meld — see the earlier #353 comments; the real residual was
this offset fold.)

The fix

Fold a global.get of a defined constant-i32 global to i32.const <value>
in offset emission. Imported globals stay a verbatim global.get, preserving
#338.

  • segments.rsconst_i32_init_value extracts a global init's constant
    i32; ParsedConstExpr::reindex folds GlobalGet(defined-const)I32Const.
    This sits in reindex, so both data and element offsets are covered.
  • merger.rsMergedModule.defined_global_i32_const records defined
    constant-i32 globals at global-merge; copied into IndexMaps for the reindex.
  • rewriter.rsIndexMaps.defined_global_i32_consts (empty default → no
    fold, so every other caller is unaffected).

Verification

Tier-5 (merger/segments/adapter) → Mythos delta-pass below.

Refs #353 (ADR-7 path-H inc 4), #338

…ry premise does not reproduce (inc 4 / #353)

Grounding for ADR-7 path-H inc 4 (static PIC / shared-everything flattening).
Built a real PIC shared-everything fixture (clang --target=wasm32 -fPIC +
wasm-ld --experimental-pic -shared + wasm-tools component link; a dylib with
`(data (global.get $__memory_base) …)`) and probed current meld.

FINDING: current meld (post inc 1–3) already
  - models the instance-level memory sharing → the fused core has ONE memory,
    NOT the two the #353 spike observed, and
  - folds `global.get $__memory_base` → `i32.const <base>` in globals/data (the
    #338 extended-const machinery), producing a VALID single core module.
So the spike's "mints 2 memories / needs new topology modeling" premise does
not reproduce on this fixture. What is NOT yet asserted is end-to-end address
*correctness* — the linked component lifts no exports, so there is nothing to
execute (the exact gap the spike flagged as "the one remaining verification").
Closing it needs a WIT-lifted executable PIC fixture.

- tests/pic-fixtures/shared_everything_linked.wasm: the real fixture.
- shared_everything_topology.rs: baseline guard (fuse → 1 memory + base-folded
  data at 0x100000 + validates), catching any regression to 2 memories/invalid.

Refs #353 (ADR-7 path-H inc 4), #338

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

LS-N verification gate

59/59 approved LS entries verified

count
Passed (≥1 test, all green) 59
Failed (≥1 test failure) 0
Missing (no ls_*_NN_* test found) 0

Approved loss-scenarios.yaml entries are expected to have a
regression test named ls_<letter>_<num>_* (e.g. LS-A-11
ls_a_11_*). The gate runs each prefix via cargo test --lib --no-fail-fast and aggregates pass/fail/missing.

Failed LS entries

(none)

Missing regression tests

(none)

Updated automatically by tools/post_verification_comment.py.
Source of truth: safety/stpa/loss-scenarios.yaml.

… oracle

The 'build wit' half of inc 4 found the real gap: a hand-written PIC-pattern
component (base-relative (data (global.get $__memory_base) …) + a lifted read,
no toolchain) fuses 'successfully' but the output FAILS wasmtime instantiation —
'constant expression required: global.get of locally defined global'. meld emits
the fused data-segment offset as global.get of the (constant-valued) merged
__memory_base global verbatim, instead of folding it to i32.const. wasm-tools
validates it (lenient); wasmtime rejects it (strict) → silent invalid output.

Root cause: segments.rs keeps global.get-first data offsets verbatim as
'runtime-dependent' (the #338 note), but a CONSTANT global must be folded in a
data const-expr. Committed as an #[ignore]d reproducing oracle (CI-green,
un-ignore on fix). This is the concrete inc-4 correctness gap — the spike's
'fold, not redefine' constraint, now reproduced minimally.

Refs #353 (ADR-7 path-H inc 4), #338

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@avrabe avrabe changed the title test(adr7): shared-everything PIC baseline + finding — spike premise doesn't reproduce (inc 4 / #353) test(adr7): reproduce inc-4 static-PIC data-offset fold bug + baseline (#353) Jul 22, 2026
…atic PIC, #353)

Implements the inc-4 fix for the bug reproduced in this branch's oracle. A
data/element segment offset const-expr may `global.get` only an IMPORTED global;
after fusion a `__memory_base`-style base (imported by a PIC dylib, defined by a
`$main` module) becomes DEFINED, so meld emitted `(data (global.get $base) …)`
verbatim — valid under wasm-tools but REJECTED by wasmtime ("constant expression
required: global.get of locally defined global"). Silent invalid output from
valid input.

Fix: fold a `global.get` of a DEFINED constant-i32 global to `i32.const <value>`
in offset emission. Imported globals stay verbatim, preserving #338.

- segments.rs: `const_i32_init_value` extracts a global init's constant i32 (bare
  or extended-const, no embedded global.get); `ParsedConstExpr::reindex` folds a
  `GlobalGet` of a defined-const global to `I32Const` (covers BOTH data and
  element offsets, which both go through `reindex`).
- merger.rs: `MergedModule.defined_global_i32_const` records defined constant-i32
  globals at global-merge; copied into `IndexMaps` for the offset reindex.
- rewriter.rs: `IndexMaps.defined_global_i32_consts` (empty default → no fold, so
  every other caller is unaffected).

Verified: `shared_everything_topology::pic_base_relative_data_reads_correctly_
after_fold` — a hand-written PIC-pattern component (base-relative data + a lifted
`read`) now fuses, VALIDATES, and executes on wasmtime with the data read back
correctly (0xddccbbaa) at the folded base. The #338 imported-base oracle
(`const_expr_globalget`, 4 tests) still passes (imported globals verbatim). Full
meld-core suite green (0 failures); fmt + clippy clean.

Tier-5 (merger/segments/adapter) → Mythos delta-pass to follow.

Refs #353 (ADR-7 path-H inc 4), #338

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Mythos delta-pass required

This PR modifies one or more Tier-5 source files (per
scripts/mythos/rank.md):

meld-core/src/adapter/fact.rs
meld-core/src/merger.rs
meld-core/src/rewriter.rs
meld-core/src/segments.rs

Before merge, run the Mythos discover protocol on the
modified Tier-5 files:

  1. Follow scripts/mythos/discover.md
    — one fresh agent session per touched Tier-5 file.
  2. For each finding, the agent must produce both a Kani
    harness and a failing PoC test (per the protocol's
    "if you cannot produce both, do not report" rule).
  3. Attach a comment on this PR with either the findings
    (formatted per discover.md's output schema) or
    NO FINDINGS.
  4. Add the mythos-pass-done label to this PR.

Why this gate exists: LS-A-10
(CABI alignment padding in async-lift retptr writeback) was
found by the v0.8.0 pre-release Mythos pass — but it had
lived in the callback emitter since #128, across six
releases. A PR-time gate would have caught it at review
time instead of at the release boundary.

The gate check on this PR will pass once the label is
applied.

@avrabe avrabe changed the title test(adr7): reproduce inc-4 static-PIC data-offset fold bug + baseline (#353) feat(adr7): static-PIC data/element-offset fold — inc 4 (#353) Jul 22, 2026
@github-actions

Copy link
Copy Markdown

Mythos delta-pass (auto)

NO FINDINGS across 4 Tier-5 file(s)

File Verdict Hypothesis
`` ✅ NO FINDINGS
`` ✅ NO FINDINGS
`` ✅ NO FINDINGS
`` ✅ NO FINDINGS

Auto-run via anthropics/claude-code-action@v1
(SHA-pinned) on the touched Tier-5 files, using the
maintainer's Max-plan OAuth token. See
.github/workflows/mythos-auto.yml and
scripts/mythos/discover.md.

@github-actions github-actions Bot added the mythos-pass-done Mythos delta-pass completed on Tier-5 file changes; findings (or NO FINDINGS) attached to PR label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mythos-pass-done Mythos delta-pass completed on Tier-5 file changes; findings (or NO FINDINGS) attached to PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant