Skip to content

feat: profile compiler phases and compile-to-result (#735) - #1343

Merged
godofecht merged 3 commits into
mainfrom
cursor/compile-phase-timing-ce23
Oct 5, 2026
Merged

godofecht merged 3 commits into
mainfrom
cursor/compile-phase-timing-ce23

Conversation

@godofecht

@godofecht godofecht commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Linked issue: #735 (parent #727).

First useful slice of compile-to-result phase profiling. FLOWC_PROFILE=1|json makes flowc emit machine-readable per-phase timings, and compile_bench records cold/warm compile-to-result for tiny/medium/large programs, including self-hosted flowc with no Python on PATH.

This is additive instrumentation plus harness rows, not a pipeline rewrite.

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:

Evidence

Baseline before this change:

  • compile_bench reported only emit/cc/run process times.
  • flowc had no FLOWC_PROFILE report. FLOW_PROFILE remains the safety-profile switch.

Targeted proof that exercises the changed behaviour (re-run after rebase onto #1341):

env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)"
# type_id_ok=1 rt_summary_ok=1 profile_ok=1 / flowc: PASS

./flow tool tests/scripts/compile_profile.flow
# 4 passed (profile JSON, off by default, compile_bench phases, no Python)

Repository gate(s) run after rebase onto #1341:

  • Host compiler selftest (flowc: PASS, type_id_ok=1, rt_summary_ok=1, profile_ok=1)
  • ./flow tool tests/scripts/compile_profile.flow (4 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)

Generated/bootstrap state, if any:

  • Rebased onto main (feat: opt-in runtime memory profiler (#740) #1341). Stale bootstrap commit dropped; compiler/bootstrap/flowc_stage_a.c regenerated to a fixed point and committed separately (fix: regenerate bootstrap C after rebase onto mem profiler).

Risk

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

  • Opt-in only. Unset/0/false/off is a cached no-op besides one getenv.

  • No language or public CLI syntax change. New env: FLOWC_PROFILE (not FLOW_PROFILE safety/flight, and not FLOW_MEM_PROFILE runtime heap).

  • compile_bench default output gains fields; existing keys stay.

  • 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.

Additive FLOWC_PROFILE and extra compile_bench JSON fields are noted under Unreleased.

Remaining gaps (not this slice)

  • monomorphize and lowering report 0; they still run inside codegen.
  • Bundle typecheck and emit each gather/parse, so those phases accumulate honest double work.
  • No linked optimization issues yet for >10% bottlenecks (import gather on tiny jobs; cc on compile-to-result; codegen on large modules).
  • Incremental AST cache hits are inside parse, not a separate phase.
  • MLIR/JIT path is not split beyond the existing codegen bucket ([MLIR Performance #727] Bound MLIR/JIT compile latency and time-to-first-result #748 covers JIT).
  • Tier-1 matrix beyond this Linux host is not recorded here.

Agent handoff

Agent/provider/session: Cursor cloud agent, branch cursor/compile-phase-timing-ce23.

Head: abff37e2f04250ec4626138605350b3f82f5898f. Rebased onto d0e2a8a8 (#1341). FLOWC_PROFILE / compile_bench / roundtrip profile wiring intact. Do not merge unless asked.

Open in Web Open in Cursor 

@godofecht
godofecht marked this pull request as ready for review October 4, 2026 20:19
@cursor
cursor Bot force-pushed the cursor/compile-phase-timing-ce23 branch 4 times, most recently from 532e15e to 85d9533 Compare October 4, 2026 22:28
cursoragent and others added 3 commits October 4, 2026 23:09
Instrument parse, import resolution, typecheck and codegen behind
FLOWC_PROFILE, and teach compile_bench to record cold/warm
compile-to-result plus the top fixed vs scaling cost.

Co-authored-by: Abhishek Shivakumar <[email protected]>
resolve.flow imports .profile for FLOWC_PROFILE spans. Roundtrip
compiled resolve without emitting profile first, so cc failed on
implicit flowc_prof_span_begin / FLOWC_PROF_* undeclared.

Add profile to roundtrip, gate_lib frontend/self-emit, and g2
fixed-point modules. Scripts only; no bootstrap regen.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Rebased onto d0e2a8a (#1341). Source keeps FLOWC_PROFILE plus
FLOW_MEM_PROFILE cgen checks. Regen fixed point at gen2; --verify
matches compiler/src.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@cursor
cursor Bot force-pushed the cursor/compile-phase-timing-ce23 branch from 85d9533 to abff37e Compare October 4, 2026 23:21
@godofecht
godofecht merged commit c5332d7 into main Oct 5, 2026
40 checks passed
cursor Bot pushed a commit that referenced this pull request Oct 5, 2026
Fixed-point C after rebasing onto phase timing (#1343 / c5332d7).
bootstrap_from_c.sh --regen (FIXED POINT at gen3) then --verify PASS.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 5, 2026
* perf: emit proven restrict/noalias in C and MLIR backends (#731)

Add a fail-closed provenance certificate for local arrays and constant
slices, then mark only proven-disjoint internal pointer parameters and
unique local pointers with C restrict and MLIR {llvm.noalias}.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: link noalias into stage-A frontend (#731)

cgen calls flowc_noalias_* but the module was missing from
frontend_modules, the self-emit plan, roundtrip compile_module, and
the g2 fixed-point list. Same inventory pattern as type_id / rt_summary.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* test: re-record parity_mlir corpus after noalias metadata (#731)

{llvm.noalias} and // flowc.noalias comments change normalized MLIR
digests. Refresh via parity_mlir.flow --record (also records newly
accepted programs from #1341/#1342 and the noalias fixtures).

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: regenerate bootstrap C after noalias rebase onto #1343

Fixed-point C after rebasing onto phase timing (#1343 / c5332d7).
bootstrap_from_c.sh --regen (FIXED POINT at gen3) then --verify PASS.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* test: retarget mlir_defer_addr golden for flowc.noalias (#731)

flowc now emits // flowc.noalias on proven-local MLIR allocas. Re-record
the mlir_commands expected text so the check matches without weakening
noalias/restrict emission.

Co-authored-by: Abhishek Shivakumar <[email protected]>

---------

Co-authored-by: Cursor Agent <[email protected]>
@godofecht
godofecht deleted the cursor/compile-phase-timing-ce23 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