Skip to content

fix(mlir): expand impl blocks on the MLIR path - #1564

Closed
godofecht wants to merge 5 commits into
mainfrom
fix/mlir-impl-blocks
Closed

godofecht wants to merge 5 commits into
mainfrom
fix/mlir-impl-blocks

Conversation

@godofecht

@godofecht godofecht commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Cause

impl Trait for Type { function m(self, ...) } defines the top-level
function Type_Trait_m on the C path: flowc_expand_all_in_place runs
flowc_impl_expand_in_place before parsing. The MLIR path's
flowc_expand_for_mlir_in_place left impl blocks out, following the
retired Python MLIR generator, which emitted nothing for them. Every call
to Type_Trait_m was then a call to an undeclared function, refused with
"argument of this type to an undeclared function" (a struct argument). 3
corpus programs failed this way: tests/lang/test_trait_impl.flow,
tests/lang/test_rt_safe_trait.flow, examples/generics_traits/traits_demo.flow.

Fix

flowc_expand_for_mlir_in_place runs the impl expansion after the DSL
stages, as the C path does. The generic struct literal inference stays C
only, as before. The change is two lines in compiler/src/resolve.flow
and its comment.

Regression fixture: compiler/fixtures/mlir/trait_impl.flow (two impls of
one trait, a method calling another through Type_Trait_m). On main it
fails with "argument of this type to an undeclared function".

Counts

mlir_vs_c --only 'trait|lib/stdlib/audio/processor.flow', over the 17 programs on main that the C backend builds:

same mlir-emit mlir-link
main 7bbb4b3 13 3 1
this branch 16 0 1

The new fixture is same as well. The mlir-link program (compiler/fixtures/dynamics_dsl/ok_portrait.flow) fails the same way on main.

Full corpus run (mlir_vs_c --jobs 8): queued behind the machine-wide corpus lock; the before and after counts will be added here.

Gates

  • selftest: flowc: PASS
  • bootstrap_from_c.sh --regen, then --verify: PASS
  • self_host_full, roundtrip: PASS
  • parity_mlir: PASS (25 fixtures, 2721 corpus programs)
  • tests/cgen: 152 passed, 0 failed
  • test-lang: all 309 passed
  • test-scripts: all pass except mlir_math_override, which fails in its
    C-backend half (flow run --backend=c exits 1). This change touches only
    the MLIR emitter, so the C path is the same as on main.

Regenerated state

  • compiler/bootstrap/flowc_stage_a.c and compiler/bootstrap/flowc_stage_a,
    in their own last commit.
  • compiler/fixtures/mlir/trait_impl.mlir and .out, recorded with
    parity_mlir.flow --record.
  • compiler/fixtures/mlir/corpus.txt: three digests added (examples/generics_traits/traits_demo.flow, tests/lang/test_rt_safe_trait.flow, tests/lang/test_trait_impl.flow, now accepted) and three moved (compiler/fixtures/typecheck_rules/rt_safe_trait_impl_bad.flow, lib/stdlib/audio/processor.flow, tests/lang/test_trait.flow), because their impl methods are now emitted. No other digest moved. --record also wanted to add 11 programs this change does not affect (corpus drift on main); those lines are left out.

Risk

Low to moderate. Every MLIR emit of a program with an impl block now
contains its methods. Before, those programs either did not call them
(the methods were dead) or were refused. Lane A works on imports and
bundling in resolve.flow and mlir_bundle.flow; this touches only
flowc_expand_for_mlir_in_place.

Needs review by a CODEOWNER (touches compiler/).

The C path turns each method of `impl Trait for Type` into the top-level
function Type_Trait_method before parsing. The MLIR path left impl
blocks out, as the retired Python MLIR generator did, so every call to
Type_Trait_method was a call to an undeclared function and was refused.
flowc_expand_for_mlir_in_place now runs the impl expansion too.

Fixture: compiler/fixtures/mlir/trait_impl.flow.
@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:07
- Resolves conflicts in `compiler/src/resolve.flow` and `compiler/src/mlir_bundle.flow`
- Updates `docs/demos/overview.md`
- Regenerates MLIR corpus
- Regenerates `compiler/bootstrap/flowc_stage_a.c`

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

Superseded by #1676 (migration onto current main; CI green). Closing this historical PR.

@godofecht godofecht closed this Nov 5, 2026
auto-merge was automatically disabled November 5, 2026 08:10

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