Repository navigation
Conversation
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s, functions with a forward declaration or an overload, keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass. The pointer ABI no longer depends on w.sigs_len, which grows during emission and let a prototype and its definition disagree.
Fixed point at gen2; bootstrap_from_c.sh --verify passes.
19814a5 to
dbbbb5b
Compare
|
Prepared for merge on main Rebase conflicts in cgen.flow with the span data temps (#729/#1383) and the noalias clone flag (#731): the prologue now emits the sret slot, then the span temps, then the body; Bugs found and fixed while qualifying (the PR as written failed
Goldens re-recorded on top of #1418 (which also changed record-update MLIR): Gates: selftest PASS; |
A record update `Name { ..p, f: v }` in expression position whose base
`p` is a uniquely owned function-scoped let or by-value parameter, at
its last use, mutates the dead binding and yields it instead of copying
into a temporary. Uniqueness and last use fail closed (captures, taken
addresses, loops that may iterate again, pending defers, unknown
statement forms all keep the copy). Observable value semantics do not
change. No move keyword and no copy-on-write, per the 2026-10-07
decision; this merges after #1367.
Rebased from PR #1354 onto #1367. The cgen block conflicts were resolved
by inserting this PR's three hunks at their anchors in the #1367 file
(the textual 3-way merge misaligned the two new function blocks). The
PR's open question in Questions.md is dropped because main records the
decision; value-semantics.md links to that entry.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
A record update `Name { ..p, f: v }` in expression position whose base
`p` is a uniquely owned function-scoped let or by-value parameter, at
its last use, mutates the dead binding and yields it instead of copying
into a temporary. Uniqueness and last use fail closed (captures, taken
addresses, loops that may iterate again, pending defers, unknown
statement forms all keep the copy). Observable value semantics do not
change. No move keyword and no copy-on-write, per the 2026-10-07
decision; this merges after #1367.
Rebased from PR #1354 onto #1367. The cgen block conflicts were resolved
by inserting this PR's three hunks at their anchors in the #1367 file
(the textual 3-way merge misaligned the two new function blocks). The
PR's open question in Questions.md is dropped because main records the
decision; value-semantics.md links to that entry.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
Single-module functions that return a named struct take a hidden `T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the callee keeps a local sret slot so the pointer ABI is not exposed across modules. Record updates whose destination overlaps a source read go through a temporary (overwrite dependence); others build in place. The runtime profile and the #728 harness report copy_count (aggregate copy operations) next to copies (bytes). Rebased from PR #1367 onto current main. cgen conflicts with the span data temps (#729/#1383) and the noalias clone flag (#731): the function prologue emits the sret slot, then the span temps, then the body; the buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment conflicts keep both sides. On rebase: `export function`s keep the value-return C signature (no pointer sret), because a module compiled on its own (roundtrip.flow, stage_a_self_emit) only sees that declaration; the PR as written failed roundtrip with "too few arguments" in lexer_flowc.c. The record-update MLIR goldens (fixture, corpus digests for the three copy-elision programs, mlir_commands) are re-recorded on top of #1418; parity_mlir runs all 24 fixtures through MLIR and they pass.
A record update `Name { ..p, f: v }` in expression position whose base
`p` is a uniquely owned function-scoped let or by-value parameter, at
its last use, mutates the dead binding and yields it instead of copying
into a temporary. Uniqueness and last use fail closed (captures, taken
addresses, loops that may iterate again, pending defers, unknown
statement forms all keep the copy). Observable value semantics do not
change. No move keyword and no copy-on-write, per the 2026-10-07
decision; this merges after #1367.
Rebased from PR #1354 onto #1367. The cgen block conflicts were resolved
by inserting this PR's three hunks at their anchors in the #1367 file
(the textual 3-way merge misaligned the two new function blocks). The
PR's open question in Questions.md is dropped because main records the
decision; value-semantics.md links to that entry.
Intent
Linked issue or roadmap item: #732 (parent #727; first slice landed in #1338).
What changed, and why is this the smallest useful change?
The remaining #732 lowering after record-update construction: single-module functions that return a named struct write through a hidden
T* __flowc_sret(bundles keep the C return type and a callee-local slot); same-storage updates run overwrite-dependence certification before in-place writes; compiler-emitted aggregate copies incrementcopy_countin the #740 profile and the #728 harness records that metric; the MLIR emitter skips a second field-by-field materialize on record-update lets and returns. Coverage for arrays, closures, and a 2×2 matrix record. No source-level move syntax.Pointer-ABI sret is withheld whenever
FLOWC_BUNDLE=1, not only when a later module has already filled the signature table. The first module of a bundle hassigs_len == 0; applying pointer ABI there broke compiler self-host (flowc_make_tokvs later call sites).Closes #732
Overlap check
Overlap / dependency notes: #1338 (merged first slice) is the base. #1354 (value-semantics / move defaults) is adjacent but does not implement destination-passing or overwrite-dependence. #728 harness already existed; this only adds
copy_count.Evidence
Baseline before this change: #1338 constructed
Name { ..base, f: v }into a let, a distinct assignment, or a last-use return, but still used a C value-return ABI, wrote same-storage fields in source order (unsound for swaps), counted only copy bytes, re-materialized record updates in MLIR, and had no matrix/closure structural cases.Targeted proof that exercises the changed behaviour:
cc+ run:copy_elision,copy_elision_dep,copy_elision_matrix,record_update,test_copy_elision— all exit 0.FLOWC_BIN=<host> ./flow tool tests/cgen/run.flowon those cases plusmem_profile,dual_ops_sugar: all PASS.FLOWC_BUNDLE=1emit ofcopy_elision.flowkeepsVec8 move_return(Vec8 p)and__flowc_sret_slot; single-module keepsvoid move_return(Vec8* __flowc_sret, ...)../flow tool tests/bench_harness/run.flow: pass=47 fail=0../flow tool tests/scripts/mem_profile.flow: 4 passed.// flowc.copy_elision record-update.Why that proof would detect the old failure or regression: a value-return ABI would miss
void move_return(Vec8* __flowc_sret; a naïve same-storage write order would failassign_same_swap/cyclic_swap; a missingcopy_countwould failmem_profile.expectand the harness JSON key; pointer ABI inside a bundle would fail bootstrap regen (gen2 C does not compile).Repository gate(s) run:
--verifyin a follow-up commitGenerated/bootstrap state, if any: source commits only so far.
compiler/bootstrap/flowc_stage_a.cis regenerated in a separate commit.Risk
Compatibility, performance, security, lifetime, backend, or release implications:
Pointer-ABI sret is withheld for
main, exported /@flow_apifunctions,FLOWC_LIBRARY=1,FLOWC_BUNDLE=1, functions taken as values, and externs. Cyclic overwrite graphs keep a temporary. By-value struct parameters still copy (C ABI). Expression-position updates still materialize when there is no destination.docs/project/Questions.mdupdated if this needs a language-design decision.Compatibility
docs/project/CHANGELOG.md.Single-module C ABI for functions that return a named user struct becomes
void foo(T* __flowc_sret, args). Exported / library / bundle / value-taken functions keep the previous value-return signature.Agent handoff
Agent/provider/session: Cursor cloud agent.
Any remaining blocker is recorded in GitHub rather than only in local/session state: none. Acceptance from #732 is met for representative matrix/record pipelines (zero avoidable full-object copies on let/sret paths),
copy_countis a tracked #728 metric, and no source-level move syntax is required.