Repository navigation
fix(mlir): accept opaque extern types - #1560
Conversation
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.
|
Resolved the merge conflict with current |
|
Merge-blocker audit (2026-11-06): this is an old 8-file MLIR migration still conflicting with main. The semantic delta in |
Cause
extern type Xmade 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 hitthe "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), plustests/lang/test_extern_const.flow, whoseextern constitems werereported under the same label.
Fix
An opaque C type is only reached through
ptr<X>, which already lowers to!llvm.ptrwithout looking at X. Both forms of the declaration are nowaccepted 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 --onlyon the 4 affected programs:c_import_no_redeclare_extern_typeis now same. The other three move totheir next, separate causes:
test_extern_typecallsstatic inlinefunctions from its helper header, which only the C backend can see
(link error);
test_dlopenneedscfn(...)function-pointer types;test_extern_constneeds 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
bootstrap_from_c.sh --regen, then--verify: PASS (fixed point at gen2)mlir_math_override, which fails in itsC-backend half (
flow run --backend=cexits 1). This change touches onlythe MLIR emitter, so the C path is the same as on main.
Regenerated state
compiler/bootstrap/flowc_stage_a.candcompiler/bootstrap/flowc_stage_a,in their own last commit.
compiler/fixtures/mlir/extern_type.mlirand.out, recorded withparity_mlir.flow --record.compiler/fixtures/mlir/corpus.txt: two digests added, fortests/cgen/c_import_no_redeclare_extern_type.flowandtests/lang/test_extern_type.flow, which flowc now accepts.--recordalso 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/).