Skip to content

feat: cross-module @rt_safe/@lifetime summaries (#765) - #1342

Merged
godofecht merged 4 commits into
mainfrom
cursor/rt-lifetime-import-summaries-64d0
Oct 4, 2026
Merged

godofecht merged 4 commits into
mainfrom
cursor/rt-lifetime-import-summaries-64d0

Conversation

@godofecht

@godofecht godofecht commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Linked issue: #765

First useful slice of modular RT-safety / lifetime-domain contracts: emit and import a compact effect/lifetime summary for public functions, and consult it during type checking so @rt_safe / @lifetime compose across modules.

The summary is a may-effect bitset plus declared domain plus one provenance edge:

  • callback-safe / frame-safe (derived)
  • may allocate / free
  • may block / lock
  • may do device / file / network I/O
  • declared @lifetime domain
  • unknown for unprovable externs (recorded; not yet a hard error)

Local summaries are the least fixed point E_f = L_f ∪ ⋃ E_callee. Imported $fname entries are leaves. Diagnostics keep the existing call-chain wording (because it calls 'malloc'). No runtime metadata; summaries ride in the compile-time effect table and are erased before codegen.

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:

Lifetime-domain docs listed cross-module domains as unchecked. Imported helpers were only as sound as the whole-program body walk; there was no serialized public contract.

Targeted proof that exercises the changed behaviour:

  • test_rt_summary in compiler/src/main.flow: rt_summary_n=57 helper_bits=1 process_bits=1 tick_dom=0 ok=1 then flowc: PASS (also type_id_ok=1).
  • tests/scripts/rt_summary.flow (3/3):
    • imported heap_touch → malloc rejected from @rt_safe with the existing chain wording
    • imported @lifetime(session) reload_preset rejected from @lifetime(callback)
    • imported stack helper accepted
  • Diagnostics captured:
    • RT-safety violation: 'process' is marked '@rt_safe' but calls 'heap_touch', which is not RT-safe because it calls 'malloc'
    • lifetime domain violation: 'process' is in the \callback` domain but calls 'reload_preset', which is in the `session` domain`

Why that proof would detect the old failure or regression:

The script fixtures are two-module programs. A checker that does not seed or consult summaries cannot name the imported helper's heap/domain contract. The selftest fails if the worklist does not fold malloc through helper into process.

Repository gate(s) run after rebase onto 7b2dccb2:

  • env -u FLOWC_IN -u FLOWC_OUT "$(./flow tool compiler/scripts/flowc_host.flow)" → flowc: PASS (type_id_ok=1, rt_summary_ok=1)
  • ./flow tool compiler/scripts/typecheck_rules.flow → 125 passed, 0 failed
  • ./flow test-lang tests/lang/test_lifetime_domains.flow tests/lang/test_rt_safe_indirect.flow → both passed
  • ./flow tool tests/scripts/rt_summary.flow → 3 passed
  • FLOWC_PHASE_A_ONLY=1 ./flow tool compiler/scripts/roundtrip.flow → PASS flowc Phase-A roundtrip (includes compile_module rt_summary / typecheck / sem_check and #747 strcat)
  • ./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:

compiler/bootstrap/flowc_stage_a.c regenerated in a separate commit after the rebase. Verify matches compiler/src.

Risk

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

  • Checking still rejects only the known unsafe names from @rt_safe / callback. The new unknown bit is recorded on unclassified externs but is not a hard error in this slice (existing @rt_safe + print / math externs stay accepted).

  • Summaries are compile-time only; C output is unchanged when programs typecheck.

  • Worklist is bounded by 5|F| bit insertions.

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

Documented as new checking, not a break: CHANGELOG notes the summary contract and that unknown is not yet rejected.

Agent handoff

Agent/provider/session: Cursor cloud agent, first slice of #765. Rebased onto #1337 (7b2dccb2) after #1340. Head: 6168c2c79be6b91960756cd84ba9c7635b8ecd9a.

Remaining gaps (not this PR):

  • Reject unknown from @rt_safe once a known-safe extern allow-list exists.
  • Closure / function-pointer / method call-graph holes (same as today; feat: first-class RT-safe callable contracts for function pointers #1310 covers explicit with rt_safe bindings).
  • Incremental cache keyed on public summaries (refinement theorem from the issue).
  • Escape through struct fields, heap, or calls (lifetime-domains v0 gaps).

Any remaining blocker is recorded in GitHub rather than only in local/session state.

Open in Web Open in Cursor 

@godofecht
godofecht marked this pull request as ready for review October 4, 2026 20:18
@cursor
cursor Bot force-pushed the cursor/rt-lifetime-import-summaries-64d0 branch from 109a0a8 to 9e2ef6a Compare October 4, 2026 20:41
cursoragent and others added 3 commits October 4, 2026 21:23
Add a compact $fname effect/lifetime summary for public functions
(callback/frame safety, alloc/free, block/lock, I/O, declared domain,
one provenance edge) and consult it during type checking so imported
calls compose. Summaries ride in the module effect table and are
erased before codegen.

Co-authored-by: Abhishek Shivakumar <[email protected]>
The edited compiler rejected immutable reassignment and a bare null
string in the new summary worklist and selftest.

Co-authored-by: Abhishek Shivakumar <[email protected]>
typecheck and sem_check import the new module, so per-module compile
and the frontend link need its object. The overload-integration lang
test imports typecheck.flow, so its recorded MLIR digest picks up
the new module.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@cursor
cursor Bot force-pushed the cursor/rt-lifetime-import-summaries-64d0 branch from fd69831 to b308094 Compare October 4, 2026 21:23
Rebased onto #1337 string/IO (7b2dccb). Bootstrap C is the fixed
point of compiler/src including concatn lowering and the
cross-module RT/lifetime summary slice.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht merged commit ee7432b into main Oct 4, 2026
40 checks passed
@cursor cursor Bot mentioned this pull request Oct 4, 2026
8 tasks done
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Rebased onto ee7432b (#1342). Source keeps FLOWC_PROFILE plus
rt_summary/type_id selftests. Regen fixed point at gen2; --verify
matches compiler/src.

Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Fixed-point C after rebasing onto #1342 and linking noalias into
the stage-A frontend. bootstrap_from_c.sh --regen (FIXED POINT at
gen3) then --verify PASS.

Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot pushed a commit that referenced this pull request Oct 5, 2026
{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]>
cursor Bot pushed a commit that referenced this pull request Oct 5, 2026
{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]>
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/rt-lifetime-import-summaries-64d0 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