Skip to content

#696: value semantics with compiler-inferred move defaults - #1354

Merged
godofecht merged 2 commits into
mainfrom
cursor/value-semantics-move-defaults-60af
Oct 8, 2026
Merged

godofecht merged 2 commits into
mainfrom
cursor/value-semantics-move-defaults-60af

Conversation

@godofecht

@godofecht godofecht commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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_sl whenever the update sat in expression position (a call argument). A last use of a uniquely owned function-scoped let or by-value parameter is now a move: the listed fields are written onto the dead base and that base is yielded. No move keyword. Destination-passing into a let, assignment, or returned local stays on the existing #732 path.

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:

Expression-position foo(Name { ..p, f: v }) always built __flowc_sl even when p was dead after the call. A last-use update in if cond { return foo(Name { ..p }) } was also kept as a copy because the sibling return p.x mentioned p.

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 — PASS

Why that proof would detect the old failure or regression:

The C golden requires consume(({ p.x = 9; p; })) on the last-use argument path and consume(({ p.x = 7; p; })) on a returning if branch, and still requires __flowc_sl when 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 --regen then --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/src edits. --verify confirms it matches a self-emit of compiler/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, pending defer, same-statement other mentions, unknown statement forms).

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

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 move keyword are deliberately not part of this slice (Questions.md, Option 1). #732 remains the place for NRVO/sret/copy-count of remaining aggregates.

Open in Web Open in Cursor 

@godofecht

Copy link
Copy Markdown
Contributor Author

Design decision, 2026-10-07, decided by the project owner: accepted as option 1 of the Questions.md entry.

  • No move keyword.
  • No copy-on-write and no implicit sharing.
  • A move is inferred only at a proven last use of a uniquely owned function-scoped local or by-value parameter.
  • Observable value semantics are unchanged. The move is a pure optimisation.

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.

godofecht added a commit that referenced this pull request Oct 7, 2026
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.
godofecht added a commit that referenced this pull request Oct 7, 2026
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.
godofecht added a commit that referenced this pull request Oct 7, 2026
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.
godofecht added a commit that referenced this pull request Oct 7, 2026
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.
@godofecht
godofecht force-pushed the cursor/value-semantics-move-defaults-60af branch from b675253 to 6b2eb5e Compare October 7, 2026 18:42
@godofecht
godofecht changed the base branch from main to cursor/copy-elision-732-remaining-ebae October 7, 2026 18:42
@godofecht

Copy link
Copy Markdown
Contributor Author

Prepared for merge, stacked on #1367 as the 2026-10-07 decision requires ("#1354 merges after #1367"). Base branch is now cursor/copy-elision-732-remaining-ebae; after #1367 merges, rebase onto main and regenerate the bootstrap.

Gates on the stack: --regen fixed point gen2; --verify PASS; tests/cgen pass after the golden update; test-lang pass; test-runtime pass; roundtrip ALL PASS; self_host_full ALL PASS; parity_mlir PASS; parity_lowering pass; doc_links, doc_coverage, doc_examples --check-ledger clean; tests/cli 152/2 (jit_hello, test_mlir: drift on main).

godofecht added a commit that referenced this pull request Oct 7, 2026
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.
@godofecht
godofecht force-pushed the cursor/value-semantics-move-defaults-60af branch from 6b2eb5e to a12e170 Compare October 7, 2026 23:19
@godofecht
godofecht changed the base branch from cursor/copy-elision-732-remaining-ebae to cursor/rt-safe-callable-contracts-7ce9 October 7, 2026 23:19
@godofecht

Copy link
Copy Markdown
Contributor Author

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 ./flow test --tier2 --strict and hit clang errors in test_production_features (void function 'use_try' should not return a value), test_dual_operator_sugar (too few arguments) and test_lowered_forms. Those came from the earlier #1367 sret ABI. The train fixes them in 8306ee1 and ce430fd, so the fix here is to sit on the train.

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: ./flow test --tier2 --strict 978/978, test-lang 279/0, test-runtime 34/0, tests/cgen 141/0, parity_mlir PASS, parity_lowering PASS, roundtrip PASS, self_host_full PASS, doc_links PASS. tests/cli shows only the known jit_hello and test_mlir local drift.

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.

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.
@godofecht
godofecht force-pushed the cursor/value-semantics-move-defaults-60af branch from a12e170 to a698bbd Compare October 8, 2026 15:18
@godofecht
godofecht changed the base branch from cursor/rt-safe-callable-contracts-7ce9 to main October 8, 2026 15:18
@godofecht
godofecht enabled auto-merge October 8, 2026 15:18
@godofecht
godofecht added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit 4f247a5 Oct 8, 2026
35 checks passed
@godofecht
godofecht deleted the cursor/value-semantics-move-defaults-60af 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.

[Flow 2.0] Value semantics with compiler-inferred move defaults

1 participant