Skip to content

perf: first slice of numerical codegen taxes (#729) - #1346

Merged
godofecht merged 8 commits into
mainfrom
cursor/codegen-taxes-729-9496
Oct 6, 2026
Merged

godofecht merged 8 commits into
mainfrom
cursor/codegen-taxes-729-9496

Conversation

@godofecht

@godofecht godofecht commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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-range to get vectorizable elementwise code.

What changed:

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

  • I searched open pull requests and recent commits for overlapping work.
  • This does not duplicate another active implementation, or the relationship is explained below.

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) emitted z * ((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 literal span<T, N> index did not.

Targeted proof that exercises the changed behaviour:

  • tests/cgen/complex_real_scale — elementwise xs[i] * c64(c1, 0.0) contains crealf/cimagf/cabsf, no __mulsc3, no in-loop span-fault branch; program exits 0. Compiled binary has no __mulsc3/__muldc3 at -O0 or -O2.
  • tests/cgen/span_bounds_elision — canonical span-length loop has xs.data[i] and no span index fault path (exit 15).
  • tests/cgen/span_bounds_retained — unproven xs[k] keeps the default check.
  • tests/cgen/span_static_extent — span<i32, 4> literal indexes xs[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 no crealf( scale. An unelided span check contains span 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.flow for complex_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.c is 2704321 bytes.

Risk

Compatibility, performance, security, lifetime, backend, or release implications:

Finite real scaling is bitwise-identical to the typed z * r form. z * (a+bi) with non-zero imag, and -0.0 imag, 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.

  • No unresolved language/API design decision is being implemented implicitly.
  • No unrelated generated artifacts or local state are included.
  • Docs changed when user-visible behaviour or syntax changed.
  • docs/project/Questions.md updated if this needs a language-design decision.

Compatibility

  • No user-visible compatibility change.
  • Compatibility change is documented in 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:

Open in Web Open in Cursor 

cursoragent and others added 2 commits October 5, 2026 02:03
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]>
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.
@godofecht
godofecht merged commit 0d20ab7 into main Oct 6, 2026
39 checks passed
@godofecht
godofecht deleted the cursor/codegen-taxes-729-9496 branch October 12, 2026 23:02
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.

2 participants