Skip to content

fix(mlir): accept opaque extern types - #1560

Merged
godofecht merged 8 commits into
mainfrom
fix/mlir-extern-type
Nov 6, 2026
Merged

godofecht merged 8 commits into
mainfrom
fix/mlir-extern-type

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Cause

extern type X made the MLIR emitter refuse the whole program with
"unsupported: extern type". The top-level form fell through to the
generic declaration refusal, and the form inside an extern { } block hit
the "not a function" check. 3 corpus programs stopped there
(tests/lang/test_extern_type.flow, tests/lang/test_dlopen.flow,
tests/cgen/c_import_no_redeclare_extern_type.flow), plus
tests/lang/test_extern_const.flow, whose extern const items were
reported under the same label.

Fix

An opaque C type is only reached through ptr<X>, which already lowers to
!llvm.ptr without looking at X. Both forms of the declaration are now
accepted and emit nothing. Any other non-function item in an extern block
is still refused, now as "extern const", so the diagnostic names the real
gap.

Regression fixture: compiler/fixtures/mlir/extern_type.flow (both forms,
ptr<FILE> / ptr<DIR> through fopen and opendir). On main it fails with
"unsupported: extern type at line 4".

Counts

mlir_vs_c --only on the 4 affected programs:

same mlir-emit mlir-link
main 7bbb4b3 0 4 0
this branch 1 2 1

c_import_no_redeclare_extern_type is now same. The other three move to
their next, separate causes: test_extern_type calls static inline
functions from its helper header, which only the C backend can see
(link error); test_dlopen needs cfn(...) function-pointer types;
test_extern_const needs extern const values from C headers.

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 (fixed point at gen2)
  • 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/extern_type.mlir and .out, recorded with
    parity_mlir.flow --record.
  • compiler/fixtures/mlir/corpus.txt: two digests added, for
    tests/cgen/c_import_no_redeclare_extern_type.flow and
    tests/lang/test_extern_type.flow, which flowc now accepts. --record
    also wanted to add 11 programs this change does not affect (corpus drift
    on main: safety_flight_*, fsm, rtos and others); those lines are left out.

Risk

Low. The change only removes a refusal for a declaration that has no code.
A value of an opaque type (let x: X) still meets "unknown type name".

Needs review by a CODEOWNER (touches compiler/).

An `extern type X`, at the top level or inside an extern block, made the
MLIR emitter refuse the program ("extern type"). An opaque C type is
only reached through ptr<X>, which is !llvm.ptr whatever X is, so the
declaration needs no lowering. A non-function item left in an extern
block (an extern const) is still refused, now under its own name.

The fixture compiler/fixtures/mlir/extern_type.flow uses both forms.
@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

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflict with current main via merge commit 5450df897ebb55397b5fddc46f6f99d907d363f1. Reapplied the two mlirgen.flow hunks, the three matching generated C hunks, and both corpus manifest additions; retained five original regression/fixture blobs. Omitted two unrelated, now-stale generated temporary-variable renamings in GPU code and retained the current-main bootstrap binary. Await CI qualification before merging.

@godofecht
godofecht added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 2, 2026
@godofecht
godofecht enabled auto-merge November 2, 2026 16:05

Copy link
Copy Markdown
Contributor Author

Merge-blocker audit (2026-11-06): this is an old 8-file MLIR migration still conflicting with main. The semantic delta in compiler/src/mlirgen.flow is narrow: ignore opaque AST_EXTERN_TYPE declarations inside/outside extern blocks while continuing to refuse unsupported extern const items. Recreate that delta against current main, preserve the extern-type fixture, then regenerate compiler/bootstrap/flowc_stage_a.c and relevant corpus.d digests using current compiler (do not merge the stale generated C wholesale). Qualify exact-head CI including MLIR-vs-C parity before merging.

@godofecht
godofecht added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 83476e1 Nov 6, 2026
29 of 30 checks passed
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