Skip to content

fix(mlir): lower a field through a module-level ptr<Struct> - #1567

Merged
godofecht merged 3 commits into
fix/mlir-bundle-dup-symbolsfrom
fix/mlir-pointer-static-field
Oct 14, 2026
Merged

godofecht merged 3 commits into
fix/mlir-bundle-dup-symbolsfrom
fix/mlir-pointer-static-field

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Stacked on #1563, which is stacked on #1557. Merge those first. This PR's own commits are the last three.

Cause

mlg_struct_addr0 in compiler/src/mlirgen.flow refused s.f when s is a module static of type ptr<Struct>, with field through a pointer static. The pointer-local case and the struct-static case were handled; the pointer-static case was not.

tools/flow_cli/sys.flow keeps its string lists in statics like that. So 40 programs that import it stopped there: tools/, scripts/, benchmarks/* and packaging/homebrew/*. So did tests/lang/test_static_ptr_field.flow (#1078). The C backend has handled this case since #1078.

Fix

For a ptr<Struct> static, the struct's address is the static's current value. The emitter now takes llvm.mlir.addressof @s, loads the pointer, and uses it as the base, the same way it treats a pointer local. A static that points to something other than a struct is still refused.

Regression test

compiler/fixtures/mlir/static_ptr_field.flow reads and stores fields through let mut tab: ptr<Table>. The old backend refuses it at line 13. The new one emits it, and it runs with 3 / 10 / 4, exit 0, as C does.

Baseline and after (mlir_vs_c, macOS arm64, LLVM 22.1.7, --jobs 8)

baseline (main 7bbb4b3) #1563 this PR
programs 1864 1866 1869 (main added 3, this PR 1)
MLIR builds 1269 1310 1314
same 1163 1203 1203 (1205 without flakes)

"same" stays at 1203. This PR adds two programs to it: tests/lang/test_static_ptr_field.flow and the new fixture. Load flakes in this full run took away the same number; the load average was about 100. Every program that was "same" on #1563 and not here was re-run with --only:

  • http_middleware, lotka_volterra, traffic_lights and test_for_variable_step were "same" again. test_for_variable_step was a C-build flake; its baseline status is c-fail-mlir.
  • diode_iv.flow was run-stdout at baseline. Its MLIR is byte-identical to fix(mlir): declare each runtime helper symbol once #1563's, so the change comes from the run.
  • test_c_import_string_time.flow is clock nondet.

With the flakes removed, "same" is 1205 against #1563's 1203.

All 41 affected programs now emit and lower (--only):

  • tests/lang/test_static_ptr_field.flow is now "same".
  • 39 fail to link the C-embed side file with variable has incomplete type. That is a separate cause, handled by the runtime/link work.
  • benchmarks/micro/transform_tuning_benchmark.flow stops at a different emitter refusal, index into a pointer of unknown element type.

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

Gates

Regenerated state

Risk

  • The change is limited to the pointer-static branch of mlg_struct_addr0, which was a refusal before. No program that emitted before takes the new path.
  • A field access through a null static faults at run time, as it does in C.

This touches compiler/, so it needs review by a human CODEOWNER. Please do not enqueue it.

mlg_struct_addr0 refused `s.f` when s is a module static of type
ptr<Struct> ("field through a pointer static"). tools/flow_cli/sys.flow
keeps its string lists in such statics, so 40 programs that import it,
and tests/lang/test_static_ptr_field.flow, stopped there.

The address of the field's struct is the static's current value: load
the pointer from @s and use it, as the pointer-local case does. A static
pointer to a non-struct is still refused.

The fixture compiler/fixtures/mlir/static_ptr_field.flow reads and stores
fields through such a static; the old backend refuses it.
…'s digest

parity_mlir --record, kept to the fixture and tests/lang/test_static_ptr_field.flow,
which the previous flowc refused. No digest moved.
@godofecht
godofecht merged commit 2b96423 into fix/mlir-bundle-dup-symbols Oct 14, 2026
4 checks passed
godofecht added a commit that referenced this pull request Oct 16, 2026
* fix(mlir): declare each runtime helper symbol once

The #740 memory profiler (mlg_put_mem_profile) declared getenv and atexit
unconditionally and defined flow_mem_note_arena and its siblings, while a
program's own extern of the same name was declared as well. mlir-opt
rejected the module with "redefinition of symbol named 'getenv'" (or
'flow_mem_note_arena', which lib/stdlib/memory.flow declares as an extern).
54 programs the C backend builds failed in mlir-lower this way.

The profiler now declares getenv and atexit only when the program does
not (mlg_lc_declared, as for calloc and realloc), and an extern of a
profiler hook declares nothing and pulls the profiler in, as the C prelude
provides those hooks.

The fixture compiler/fixtures/mlir/extern_runtime_names.flow declares both;
the old backend's MLIR does not lower.

* test(mlir): record extern_runtime_names goldens and the digests it moves

parity_mlir --record, kept to the fixture and the 33 corpus digests whose
MLIR held a duplicate getenv, atexit or flow_mem_note_* declaration. No
other digest moved.

* fix: regenerate bootstrap C after the runtime helper symbol change

* fix(mlir): lower a field through a module-level ptr<Struct> (#1567)

* fix(mlir): lower a field through a module-level ptr<Struct>

mlg_struct_addr0 refused `s.f` when s is a module static of type
ptr<Struct> ("field through a pointer static"). tools/flow_cli/sys.flow
keeps its string lists in such statics, so 40 programs that import it,
and tests/lang/test_static_ptr_field.flow, stopped there.

The address of the field's struct is the static's current value: load
the pointer from @s and use it, as the pointer-local case does. A static
pointer to a non-struct is still refused.

The fixture compiler/fixtures/mlir/static_ptr_field.flow reads and stores
fields through such a static; the old backend refuses it.

* test(mlir): record static_ptr_field goldens and test_static_ptr_field's digest

parity_mlir --record, kept to the fixture and tests/lang/test_static_ptr_field.flow,
which the previous flowc refused. No digest moved.

* fix: regenerate bootstrap C after the pointer static field change

* chore(mlir): stage scoped corpus goldens for manifest modularization

* chore(mlir): stage additional scoped golden entries
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