Skip to content

fix(mlir): store to a field reached through a pointer field - #1559

Closed
godofecht wants to merge 6 commits into
mainfrom
fix/mlir-field-store-through-pointer
Closed

godofecht wants to merge 6 commits into
mainfrom
fix/mlir-field-store-through-pointer

Conversation

@godofecht

@godofecht godofecht commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Cause

o.cfg.n = v with cfg: ptr<Inner> is C's o->cfg->n = v. mlirgen's struct-address walk (mlg_struct_addr0) gave up on a field of type ptr<S>. The assignment then took the fallback inherited from the Python generator, which drops the store and leaves the comment // Unsupported assignment target expression. The program kept running with the old value, with no diagnostic.

Corpus programs that hit it: tests/lang/test_store_after_call.flow and tests/cgen/store_after_call.flow (exit 3 under MLIR, 0 under C) and tests/lang/test_import_field_chain.flow (2 against 0).

Fix

When the field is ptr<S> for a known struct S, the walk loads the field's pointer and continues in S. Reads already handled pointer fields; stores now match them.

Regression test

compiler/fixtures/mlir/field_store_ptr.flow stores through one and two pointer fields. The old backend printed 1 2 3 and exited 1; the recorded run is 9 42 5, exit 0, as C prints.

Counts (mlir_vs_c, full corpus, --jobs 8, macOS arm64, LLVM 22.1.7)

  • baseline main 7bbb4b3: same 1163
  • this branch alone: same 1166

Now same: the two store_after_call tests, test_import_field_chain, and the new fixture. tests/cgen/for_variable_step.flow (c-fail-mlir) is also same in this run, which is build timing. examples/concurrency/work_steal.flow and tests/lang/test_c_import_string_time.flow went from same to nondet (scheduler and clock output, also seen on the other branches). No program that was same now fails.

Gates

  • flowc selftest: PASS
  • bootstrap_from_c.sh --regen, then --verify: PASS
  • self_host_full, roundtrip: PASS
  • parity_mlir: PASS
  • tests/cgen: 152 passed
  • test-lang: 309 passed
  • tests/mlir_commands: 89 passed
  • test-scripts: one failure, mlir_math_override, in its C backend half. It fails the same way with a flowc built from main's bootstrap C.

Regenerated state

  • compiler/bootstrap/flowc_stage_a.c and flowc_stage_a, in their own last commit.
  • New fixture goldens field_store_ptr.mlir and .out.
  • compiler/fixtures/mlir/corpus.txt: 6 digests move, for the programs whose MLIR now has the store (the two store_after_call tests, lib/stdlib/gpu_graph_reference.flow and the three programs that import it). The 11 programs main never recorded are left out.

The floor in compiler/mlir_vs_c/floor.txt is not changed.

Risk

Low. Only stores that were silently dropped change. lib/stdlib/gpu_graph_reference.flow was among them, so programs using it under MLIR now keep those writes.

`o.cfg.n = v` with cfg: ptr<Inner> is C's o->cfg->n = v. mlirgen's
struct-address walk gave up on a ptr<S> field, and the assignment then
took the Python fallback that drops the store and leaves a comment. The
program kept running with the old value: tests/lang/test_store_after_call
and tests/cgen/store_after_call exited 3 and test_import_field_chain 2,
where C exits 0.

The walk now loads the field's pointer and continues in the pointee
struct. compiler/fixtures/mlir/field_store_ptr.flow stores through one
and two pointer fields; the old backend printed 1 2 3 and exited 1.
Corpus digests moved for the programs that make such a store.
@godofecht
godofecht added this pull request to the merge queue Oct 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 14, 2026
@godofecht
godofecht enabled auto-merge October 15, 2026 16:01
godofecht and others added 2 commits October 20, 2026 12:34
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: godofecht <[email protected]>

Copy link
Copy Markdown
Contributor Author

Resolved current-main merge conflict in 38be234c161136c8517e3c3465971e80caed67f0. Retained the mlg_struct_addr0 pointer-through-field lowering fix in both Flow source and generated bootstrap C, plus all three field_store_ptr regression fixtures. Excluded stale unrelated generated variable renumbering and unrelated historical bundle changes. CI must pass before merge.

Copy link
Copy Markdown
Contributor Author

CI repair triage on current head 6cea5c30 (2026-11-02). The self-host roundtrip job fails compiler/bootstrap/flowc_stage_a.c != flowc emit of compiler/src. Separately, the MLIR recorded corpus job reports eight changed outputs: examples/gpu/vgpu/graph_device.flow, lib/stdlib/gpu_graph_reference.flow, lib/stdlib/regex.flow, tests/cgen/store_after_call.flow, tests/lang/test_gpu_graph_reference.flow, tests/lang/test_stdlib_regex.flow, tests/lang/test_store_after_call.flow, and tests/runtime/test_gpu_graph_exec.flow (2716 programs, 8 mismatches). Preserve the pointer-through-field lowering and its field_store_ptr fixtures; regenerate compiler/bootstrap/flowc_stage_a.c from compiler source and re-record the affected corpus outputs using the repository's normal tooling. Do not bypass bootstrap/golden gates. Fresh full CI and platform/target qualification are required before merge.

Copy link
Copy Markdown
Contributor Author

Superseded by merged #1666, which explicitly migrates this pointer-field MLIR store fix onto current main, preserving backend source and fixture while regenerating bootstrap and affected corpus digests. #1666 passed full compiler CI and Linux/macOS qualification before merging. Closing this historical PR to avoid duplicate integration; its branch and history remain available.

@godofecht godofecht closed this Nov 4, 2026
auto-merge was automatically disabled November 4, 2026 06:33

Pull request was closed

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