Repository navigation
Conversation
The MLIR emitter had no lowering for c64 and c128 and refused every program naming them. A complex value is now !llvm.struct<(f32, f32)> or (f64, f64), C's layout, under a synthesized struct name, so arrays, pointers, fields, parameters and returns use the struct paths. On top: the constructors; + - * / with C's complex and complex-by-real rules and the wider part type; unary minus, == and !=; creal, cimag, crealf, cimagf, cabs, conj and cexp from their real formulas; conversion between the widths and from a real number; and print as (re + im j). Fixture: compiler/fixtures/mlir/complex.flow.
|
Merge-blocker audit (2026-11-06): complex |
Reapply the complex-number emitter to current main, preserving current native bootstrap binary. Update generated C with conflict-aware identifier mapping for newer MLIR code; retain parity fixture and scoped corpus digests. Exact-head CI must validate generated goldens.
Regenerate scoped normalized-MLIR SHA-256 expectations for complex real scaling, complex arithmetic and language scaling. Retain all coverage; 33/33 fixture execution tests passed.
|
Superseded by merged #1684 (main commit 337599f). Verified against both PR patches: all 17 non-bootstrap-C changed paths have identical added lines, including |
Pull request was closed
Cause
The MLIR emitter had no lowering for
c64andc128(C's float complexand double complex), so it refused every program that names them with
"unknown type name", directly or through
lib/stdlib/rf.flow(whoseIQis
c64) andlib/stdlib/complex_linalg.flow. 15 corpus programs stoppedthere:
tests/lang/test_complex_builtins.flow,test_complex_scaling,test_print_complex_multi,test_field_named_capital_i,test_hardware_cdc,tests/cgen/complex_types_arith.flow,complex_real_scale,rf_types_signal,tests/stdlib/test_complex_linalg.flow,examples/rf/*and others.Fix
A complex value is
!llvm.struct<(f32, f32)>or!llvm.struct<(f64, f64)>,real part first, which is C's layout. The struct is synthesized under a
name a program cannot spell (
#c64,#c128), so arrays, pointers,struct fields, parameters and returns of complex type use the existing
struct paths. On top of that, with C's semantics:
c64(re, im),c64(x),c128(...); a complex argument converts.+ - * /between complex values, and against a real operand part bypart (C's complex-by-real arithmetic); the result has the wider part
type, so a
f64operand widens ac64. Unary minus,==and!=.crealandcimag(double, as in C),crealfandcimagf,cabs(float for a
c64, ascabsf),conj,cexp, each from its realformula with
math.sqrt,math.exp,math.sin,math.cos.c64andc128, and from a real number, inmlg_cast.print/printlnwrite(re + im j), as the C backend's__flowc_pr_c64does.Regression fixture:
compiler/fixtures/mlir/complex.flow. On main it failswith "unknown type name". Its output equals the C backend's line for line.
Counts
mlir_vs_c --onlyon the 15 programs that stopped at a complex type, plus the new fixture:The 4 left (
examples/rf/dft.flow,examples/rf/iq_mixer.flow,benchmarks/micro/codegen_taxes.flow,benchmarks/micro/complex_vectorization.flow)declare
array<c64, N>without an initializer; that lowering, and thereturn of such an array, is the separate PR fix/mlir-aggregate-arrays.
With both applied all 15 build and dft and iq_mixer print what the C
backend prints.
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: PASSmlir_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/complex.mlirand.out, recorded withparity_mlir.flow --record.compiler/fixtures/mlir/corpus.txt: 13 digests added, for the programs flowc now accepts (examples/hardware/blink.flow,examples/rf/sdr_receiver.flow,lib/stdlib/complex_linalg.flow,lib/stdlib/rf.flow,tests/cgen/complex_real_scale.flow,complex_types_arith.flow,rf_types_signal.flow,tests/lang/test_complex_builtins.flow,test_complex_scaling.flow,test_field_named_capital_i.flow,test_hardware_cdc.flow,test_print_complex_multi.flow,tests/stdlib/test_complex_linalg.flow). No existing digest moved.--recordalso wanted to add 12 programs this change does not affect (corpus drift on main); those lines are left out.Risk
Moderate.
__divsc3/__divdc3, which scale the operands by a power of two first; theresults agree except near overflow or underflow.
cabsof ac128issqrt(re*re + im*im), where C callshypot; theycan differ in the last bit. For a
c64the sum is formed in double,which is exact.
clog,csqrt,cpowandcargare still refused.c128(z)of a complexzto(double)z, whichdrops the imaginary part; the MLIR backend converts both parts. No
corpus program relies on either (examples/rf/dft.flow passes a value
with a zero imaginary part).
Needs review by a CODEOWNER (touches compiler/).