Skip to content

feat: sound lifetime domain propagation through struct fields (#684) - #1358

Closed
godofecht wants to merge 4 commits into
cursor/request-persistent-domains-11adfrom
cursor/domain-fields-684-7916
Closed

godofecht wants to merge 4 commits into
cursor/request-persistent-domains-11adfrom
cursor/domain-fields-684-7916

Conversation

@godofecht

@godofecht godofecht commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Linked issue or roadmap item: #684 (epic #679). Archive reference: archive/feat/684-domain-fields.

What changed, and why is this the smallest useful change?

The v0 lifetime-domain checker tracked direct locals and module statics. This extends domain representation to struct fields and collections so a shorter-lived reference stored through a field path, array element, or struct/array literal is an escape (LD1), and a field may declare @lifetime(D) as a contract (LD5).

Closes #684

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:

Sibling agents are on #690 (arena domain binding), #694 (region/alias inference), #696 (move defaults), and #765 (cross-module @rt_safe/@lifetime summaries). This PR does not touch those. Open PRs reviewed: #1342 is #765, #1328 is MLIR static-memory ranges, #1348 is #766 closures. No live implementation of #684.

Evidence

Baseline before this change:

holder[0].view = &scratch into an application static, table[0][0] = &scratch, and @lifetime(application) on a field all compiled.

Targeted proof that exercises the changed behaviour:

compiler/fixtures/typecheck_rules/domain_field_*.flow, domain_array_*.flow, domain_ld5_*.flow, domain_return_struct.flow, domain_struct_lit_static.flow; accepted program tests/lang/test_domain_fields.flow; C erasure tests/cgen/domain_fields_no_trace.flow.

Why that proof would detect the old failure or regression:

Each negative fixture demands the exact domain-escape diagnostic. The accepted program would fail to typecheck if LD5 grew false positives. A new regression test fails on the old behaviour: the old checker did not parse @lifetime on fields and did not walk struct/array literals for domain roots.

Repository gate(s) run:

  • Host selftest: env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)" → flowc: PASS
  • ./flow tool compiler/scripts/typecheck_rules.flow → 144 passed, 0 failed (host and new bootstrap)
  • ./flow test-lang tests/lang/test_domain_fields.flow tests/lang/test_lifetime_domains.flow → both pass
  • ./flow tool tests/cgen/run.flow domain_fields_no_trace lifetime_domains_no_trace → both PASS
  • ./compiler/scripts/bootstrap_from_c.sh --verify → PASS bootstrap C matches compiler/src (self-reproducing)

Generated/bootstrap state, if any:

compiler/bootstrap/flowc_stage_a.c regenerated in a separate commit after source edits. --verify passed (fixed point at gen2).

Risk

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

Opt-in extension of @lifetime to struct fields. Existing unannotated programs are unchanged. Annotation is erased before codegen.

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

@lifetime(D) is now accepted on struct fields. New hard errors only fire when both the writer and the target opt in (or the target is a longer-lived static). Module statics that hold a composite remain ptr<T> (struct-typed module statics are still rejected).

Agent handoff

Acceptance criteria are met: field domains are recorded, shorter-lived stores into longer-lived fields/collections are rejected, tests cover nested structs and containers, docs are registered in docs/nav.json. Not merging.

Open in Web Open in Cursor 

@godofecht

Copy link
Copy Markdown
Contributor Author

Design decision, 2026-10-07, decided by the project owner: accepted.

@lifetime(D) is allowed on struct fields as a contract, together with rule LD5. This PR merges after #1369 (both edit the lifetime checker and docs/language/lifetime-domains.md), so it needs a rebase on main once #1369 lands, and a bootstrap C regeneration in its own commit. Recorded in docs/project/Questions.md by #1422.

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.
The lattice is callback < frame < request < session < application <
persistent, as accepted on 2026-10-07 (docs/project/Questions.md).
LD1-LD4 apply to both. request may allocate and is not @rt_safe.
persistent is the outermost domain: an application pointer may not be
stored in a persistent static, and an @Lifetime(application) function
may not call a persistent one. Compact summaries encode unannotated
callables as domain rank 6.

Rebased from PR #1369 onto current main; doc conflicts with region
inference (#1390) and the arena-domain rows (#690) kept both sides.
Whether persistent values must be TransportSafe is #1421.

The #690 arena-domain check hard-coded application as 3, which is
session once request is inserted; it now uses FLOWC_RT_DOM_APPLICATION
(domain_arena_ok_unannotated failed without this).
…ains

Fixed point at gen2; bootstrap_from_c.sh --verify passes.
LD1 now follows stores through struct fields, nested fields and array
elements of a static, so a shorter-lived reference parked inside
composite storage is an escape. @Lifetime(D) on a struct field is a
contract (rule LD5): the field may only hold D-domain or longer
references, wherever the instance lives. Accepted in the 2026-10-07
decision; merges after #1369.

Rebased from PR #1358 onto #1369 (request/persistent) and current main.
The assignment-check conflict with main keeps the local_storage guard on
"span outlives borrowed storage"; doc conflicts keep both sides.
Fixed point at gen2; bootstrap_from_c.sh --verify passes.
@godofecht
godofecht force-pushed the cursor/domain-fields-684-7916 branch from 87a8622 to 58d13fd Compare October 7, 2026 16:03
@godofecht
godofecht changed the base branch from main to cursor/request-persistent-domains-11ad October 7, 2026 16:03
@godofecht

Copy link
Copy Markdown
Contributor Author

Prepared for merge, stacked on #1369 as the 2026-10-07 decision requires ("#1358 merges after #1369"). The base branch is now cursor/request-persistent-domains-11ad; after #1369 merges, rebase onto main and regenerate the bootstrap.

  • Source 824941a2 and bootstrap 58d13fde on top of Lifetime domains and type reflection train: #1369, #1437, #1358, #1365 #1369 (89827b62, itself on main e2205a79).
  • Conflict in sem_check_assignment with main: kept this PR's field-escape flow and main's sem_sv_has(c.local_storage, origin) guard on "span outlives borrowed storage". Doc conflicts (LANGUAGE_SPEC, lifetime-domains, README, spec-index, nav, CHANGELOG) keep both sides, including request/persistent, region inference and arena domains.
  • One em dash in docs/language/domain-fields.md replaced (the prose check blocks it).

Gates on the stack: flowc selftest PASS; --regen fixed point gen2; --verify PASS; typecheck_rules 164/0 (19 new fixtures); parity_typecheck clean; test-lang pass; test-runtime pass; tests/cgen pass; parse_coverage --check pass; self_host_full ALL PASS; roundtrip ALL PASS; doc_links, doc_coverage, doc_examples --check-ledger clean.

@godofecht
godofecht force-pushed the cursor/request-persistent-domains-11ad branch from 82bf008 to b729c62 Compare October 7, 2026 17:57
godofecht added a commit that referenced this pull request Oct 7, 2026
LD1 now follows stores through struct fields, nested fields and array
elements of a static, so a shorter-lived reference parked inside
composite storage is an escape. @Lifetime(D) on a struct field is a
contract (rule LD5): the field may only hold D-domain or longer
references, wherever the instance lives. Accepted in the 2026-10-07
decision; merges after #1369.

Rebased from PR #1358 onto #1369 (request/persistent) and current main.
The assignment-check conflict with main keeps the local_storage guard on
"span outlives borrowed storage"; doc conflicts keep both sides.
@godofecht
godofecht force-pushed the cursor/request-persistent-domains-11ad branch from b729c62 to 64daee6 Compare October 7, 2026 23:09
godofecht added a commit that referenced this pull request Oct 7, 2026
LD1 now follows stores through struct fields, nested fields and array
elements of a static, so a shorter-lived reference parked inside
composite storage is an escape. @Lifetime(D) on a struct field is a
contract (rule LD5): the field may only hold D-domain or longer
references, wherever the instance lives. Accepted in the 2026-10-07
decision; merges after #1369.

Rebased from PR #1358 onto #1369 (request/persistent) and current main.
The assignment-check conflict with main keeps the local_storage guard on
"span outlives borrowed storage"; doc conflicts keep both sides.
@godofecht

Copy link
Copy Markdown
Contributor Author

Landed in #1369 as 32401c7 (lane A train). The #684 source change was carried as its own commit and the bootstrap C regenerated once for the train.

@godofecht godofecht closed this Oct 7, 2026
@godofecht
godofecht deleted the cursor/domain-fields-684-7916 branch October 12, 2026 23:25
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] Sound lifetime domain propagation through struct fields and collections

1 participant