Repository navigation
fix(mlir): lower a field through a module-level ptr<Struct> - #1567
Merged
godofecht merged 3 commits intoOct 14, 2026
Merged
Conversation
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
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
Open
19 of 37 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1563, which is stacked on #1557. Merge those first. This PR's own commits are the last three.
Cause
mlg_struct_addr0incompiler/src/mlirgen.flowrefuseds.fwhensis a module static of typeptr<Struct>, withfield 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.flowkeeps its string lists in statics like that. So 40 programs that import it stopped there: tools/, scripts/, benchmarks/* and packaging/homebrew/*. So didtests/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 takesllvm.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.flowreads and stores fields throughlet mut tab: ptr<Table>. The old backend refuses it at line 13. The new one emits it, and it runs with3 / 10 / 4, exit 0, as C does.Baseline and after (mlir_vs_c, macOS arm64, LLVM 22.1.7, --jobs 8)
"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:With the flakes removed, "same" is 1205 against #1563's 1203.
All 41 affected programs now emit and lower (
--only):variable has incomplete type. That is a separate cause, handled by the runtime/link work.index into a pointer of unknown element type.The floor in compiler/mlir_vs_c/floor.txt is not raised.
Gates
flowc: PASSbootstrap_from_c.sh --regen(fixed point at gen2), then--verify: ALL PASSRegenerated state
compiler/bootstrap/flowc_stage_a.candflowc_stage_a, in their own last commit.parity_mlir --record, trimmed by hand to the new fixture's goldens and 1 new corpus digest, for tests/lang/test_static_ptr_field.flow, which the fix(mlir): declare each runtime helper symbol once #1563 flowc refused. No digest moved. 14 additions that the fix(mlir): declare each runtime helper symbol once #1563 flowc already accepted are left out: main drift, including the new examples/music programs.Risk
mlg_struct_addr0, which was a refusal before. No program that emitted before takes the new path.This touches compiler/, so it needs review by a human CODEOWNER. Please do not enqueue it.