Repository navigation
perf: first slice of numerical codegen taxes (#729) - #1346
Merged
Merged
Conversation
Recognize c64(re, 0)/c128(re, 0) as a real-scalar operand so ordinary elementwise scaling does not emit a C99 complex multiply. Literal indexes on span<T, N> are proven in range. Structural cgen tests lock both #630 and #615 patterns for #729. Co-authored-by: Abhishek Shivakumar <[email protected]>
Fixed point of compiler/src after the #729 first-slice cgen lowering. Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht
marked this pull request as ready for review
October 5, 2026 02:12
This was referenced Oct 5, 2026
Squash-merge Jules conflict-fix side PR into #1346's branch (merge main + regenerate bootstrap).
…ootstrap Only compiler/bootstrap conflicted. Took main's bootstrap and ran bootstrap_from_c.sh --regen (fixed point at gen2, also on Linux x86-64); the checked-in flowc_stage_a is rebuilt for Linux x86-64 like main's. Guided by Jules session 11235954443391244798; its requirements.txt deletion and its early return in flowc_cgen_is_proven_span_index were left out.
…ootstrap Only compiler/bootstrap/flowc_stage_a conflicted (binary). Took main's bootstrap C/binary, then ran bootstrap_from_c.sh --regen (fixed point at gen2; --verify ALL PASS). Rebuilt the checked-in flowc_stage_a as Linux x86-64 ELF on the box (gcc 14 -O2), matching main's convention. Source auto-merge kept #1375 MLIR work alongside #729 cgen changes.
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.
Intent
Linked issue: #729 (blockers #630 and #615).
First useful slice of the numerical codegen-tax workstream. Safe idiomatic Flow should not need
ptr, hand-written C, or global-fcx-limited-rangeto get vectorizable elementwise code.What changed:
c64 * f32/c128 * f64already lowered to componentwise real/imag scaling. This slice also recognizes the known source formz * c64(r, 0.0)/c64(r)(literal-zero imag, not-0.0) and emits two real multiplies so clang does not insert__mulsc3. Precision-correctcabsf/cabsis unchanged. Generalc64 * c64stays a strict C99 complex multiply.for i in 0 to xs.len { xs[i] }already elided the span bounds check. This slice also proves a literal index on a static-extentspan<T, N>/&[T; N]. An unproven index keeps the default fault path.This is the smallest slice that lands both named patterns with structural generated-code tests. The follow-on audit (copies, length reloads, scalar fallbacks, MLIR) is left for later.
Overlap check
Overlap / dependency notes:
Open Codex/Devin PRs #1332 #1331 #1330 #1329 #1328 #1326 #1325 #1268 #1267 #1265 do not touch this lowering. #630/#615 C-backend work already landed via #878, #1181, and #1278; those left the constructor form
z * c64(r, 0.0)as a C99 complex multiply and did not lock the structural goldens this issue asks for.Evidence
Baseline before this change:
On
9a278876,z * c64(c1, 0.0)emittedz * ((float)(c1) + (float)(0.0) * _Complex_I), which clang lowers to__mulsc3.for i in 0 to xs.len { xs[i] }already omitted the bounds ternary; a literalspan<T, N>index did not.Targeted proof that exercises the changed behaviour:
tests/cgen/complex_real_scale— elementwisexs[i] * c64(c1, 0.0)containscrealf/cimagf/cabsf, no__mulsc3, no in-loop span-fault branch; program exits 0. Compiled binary has no__mulsc3/__muldc3at-O0or-O2.tests/cgen/span_bounds_elision— canonical span-length loop hasxs.data[i]and nospan indexfault path (exit 15).tests/cgen/span_bounds_retained— unprovenxs[k]keeps the default check.tests/cgen/span_static_extent—span<i32, 4>literal indexesxs[0]/xs[3]have no fault path.tests/lang/test_complex_scaling— finite-value numerical parity for typed and constructor real-scale forms.Why that proof would detect the old failure or regression:
The old constructor form contained
* ((float)(c1)and nocrealf(scale. An unelided span check containsspan index/flow_fault_handler("span index out of bounds").Repository gate(s) run:
env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)"→flowc: PASS./flow tool tests/cgen/run.flowforcomplex_real_scale,span_bounds_elision,span_bounds_retained,span_static_extent,complex_types_arith,span_len_hoisting,spans_lowering— 7 passed./flow test-lang tests/lang/test_complex_scaling.flow tests/lang/test_complex_builtins.flow tests/lang/test_bounds_elision.flow— 3 passed./compiler/scripts/bootstrap_from_c.sh --regen— fixed point at gen2./compiler/scripts/bootstrap_from_c.sh --verify—PASS bootstrap C matches compiler/src (self-reproducing)Generated/bootstrap state, if any:
Bootstrap C regenerated in a separate commit after the source edit. Fixed point at gen2.
compiler/bootstrap/flowc_stage_a.cis 2704321 bytes.Risk
Compatibility, performance, security, lifetime, backend, or release implications:
Finite real scaling is bitwise-identical to the typed
z * rform.z * (a+bi)with non-zero imag, and-0.0imag, stay strict C99 complex multiply (Inf/NaN recovery preserved there). Componentwise scale of a literal-zero imag constructor matches the plain real-scalar form from #630, including on Inf inputs where C99 recovery would contaminate. No global-fcx-limited-range. MLIR is unchanged.docs/project/Questions.mdupdated if this needs a language-design decision.Compatibility
docs/project/CHANGELOG.md.Agent handoff
Cursor cloud agent. Remaining #729 follow-on (copies, length reloads, scalar fallbacks, MLIR) stays on the issue.
Any remaining blocker is recorded in GitHub rather than only in local/session state: