Repository navigation
#696: value semantics with compiler-inferred move defaults - #1354
Conversation
|
Design decision, 2026-10-07, decided by the project owner: accepted as option 1 of the Questions.md entry.
This PR merges after #1367 (both edit record-update lowering in cgen.flow). #1422 records the answer in the Questions.md archive, so on rebase drop this PR's open Questions.md entry for the same question. |
The project owner decided six open design questions on 2026-10-07: orchestration starts as a std.orchestrate library (#723, #1393 closed), request and persistent lifetime domains (#1369), @Lifetime on struct fields with LD5 (#1358), last-use moves without a move keyword or COW (#1354), the type reflection API at Experimental stability (#1365), and the Linux release qualification policy (#1399). Questions.md archives each one. The Flow 3.0 tracker records the library-first rule for orchestration. Follow-up on persistent and TransportSafe is #1421.
The project owner decided six open design questions on 2026-10-07: orchestration starts as a std.orchestrate library (#723, #1393 closed), request and persistent lifetime domains (#1369), @Lifetime on struct fields with LD5 (#1358), last-use moves without a move keyword or COW (#1354), the type reflection API at Experimental stability (#1365), and the Linux release qualification policy (#1399). Questions.md archives each one. The Flow 3.0 tracker records the library-first rule for orchestration. Follow-up on persistent and TransportSafe is #1421.
The project owner decided six open design questions on 2026-10-07: orchestration starts as a std.orchestrate library (#723, #1393 closed), request and persistent lifetime domains (#1369), @Lifetime on struct fields with LD5 (#1358), last-use moves without a move keyword or COW (#1354), the type reflection API at Experimental stability (#1365), and the Linux release qualification policy (#1399). Questions.md archives each one. The Flow 3.0 tracker records the library-first rule for orchestration. Follow-up on persistent and TransportSafe is #1421.
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.
b675253 to
6b2eb5e
Compare
|
Prepared for merge, stacked on #1367 as the 2026-10-07 decision requires ("#1354 merges after #1367"). Base branch is now
Gates on the stack: |
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.
6b2eb5e to
a12e170
Compare
|
Restacked on the lane B train (#1348, head 5a1bcdb) so this PR no longer carries the old #1367 commits. Failing checks before: Tier 1 (ubuntu and macos) and FLOW tier-2. All three ran New head: bfbf550 (source, CHANGELOG conflict resolved by keeping both entries) plus the regenerated bootstrap C as its own commit (fixed point at gen2, verify PASS). Local gates on this head: Base is now cursor/rt-safe-callable-contracts-7ce9. Once #1348 merges, this needs one rebase onto main and a regen, then it can merge. |
5a1bcdb to
75d990b
Compare
e91f723 to
2d8c1ce
Compare
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.
a12e170 to
a698bbd
Compare
Intent
Linked issue or roadmap item: #696 (epic #679). Sibling agents own #684, #690, #694, and #732; this PR is last-use analysis and inferred-move lowering only.
What changed, and why is this the smallest useful change?
Flow structs already have value semantics. The C backend copied a record-update base into
__flowc_slwhenever the update sat in expression position (a call argument). A last use of a uniquely owned function-scopedletor by-value parameter is now a move: the listed fields are written onto the dead base and that base is yielded. Nomovekeyword. Destination-passing into alet, assignment, or returned local stays on the existing #732 path.Overlap check
Overlap / dependency notes:
ifbranches).docs/project/Questions.md.Evidence
Baseline before this change:
Expression-position
foo(Name { ..p, f: v })always built__flowc_sleven whenpwas dead after the call. A last-use update inif cond { return foo(Name { ..p }) }was also kept as a copy because the siblingreturn p.xmentionedp.Targeted proof that exercises the changed behaviour:
./flow tool tests/cgen/run.flow move_inference— PASS./flow test-lang tests/lang/test_move_inference.flow— PASS./flow tool tests/cgen/run.flow copy_elision— PASS./flow test-lang tests/lang/test_copy_elision.flow— PASSWhy that proof would detect the old failure or regression:
The C golden requires
consume(({ p.x = 9; p; }))on the last-use argument path andconsume(({ p.x = 7; p; }))on a returningifbranch, and still requires__flowc_slwhen the update reads the base, sits in a repeating loop, or follows a later mention. The language test fails if a move clobbers a later mention, a loop iteration, or an address-taken alias.Repository gate(s) run:
env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)"—flowc: PASS./compiler/scripts/bootstrap_from_c.sh --regenthen--verify—ALL PASS bootstrap_from_c(self-reproducing)./flow tool tests/cgen/run.flow move_inference copy_elision— 2 passed./flow test-lang tests/lang/test_move_inference.flow tests/lang/test_copy_elision.flow— 2 passed./flow tool wiki_nav— nav is consistent with docs/Generated/bootstrap state, if any:
Bootstrap C regenerated in a separate commit after the
compiler/srcedits.--verifyconfirms it matches a self-emit ofcompiler/src.Risk
Compatibility, performance, security, lifetime, backend, or release implications:
Observable value semantics are unchanged: a move is applied only when the binding is dead on that path. A missed last-use keeps a copy (performance only). A wrong last-use would be a correctness bug; the analysis fails closed (loops,
&p, captures, pendingdefer, same-statement other mentions, unknown statement forms).docs/project/Questions.mdupdated if this needs a language-design decision.Compatibility
docs/project/CHANGELOG.md.The changelog notes the new lowering. Source programs do not need to change.
Agent handoff
Agent/provider/session, when applicable: Cursor cloud agent.
Any remaining blocker is recorded in GitHub rather than only in local/session state:
Closes #696
Copy-on-write / implicit sharing and a
movekeyword are deliberately not part of this slice (Questions.md, Option 1). #732 remains the place for NRVO/sret/copy-count of remaining aggregates.