Skip to content

[#694] Local region inference and automated non-aliasing proofs - #1360

Closed
godofecht wants to merge 3 commits into
mainfrom
cursor/region-inference-694-316b
Closed

godofecht wants to merge 3 commits into
mainfrom
cursor/region-inference-694-316b

Conversation

@godofecht

@godofecht godofecht commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #694

Intent

Linked issue or roadmap item: #694 (epic #679). Archive tag archive/feat/694-region-inference.

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

flowc infers abstract storage regions inside one function body and proves a conservative set of non-aliasing facts with no annotations. Distinct owned locals occupy distinct storage; a fresh local is disjoint from every parameter; pointer arithmetic inherits its base. Two parameters, a reassignment, a call result, and two views of the same identity stay may-alias. Proven-disjoint unit-stride copies lower to memcpy instead of memmove. FLOWC_REGION_CHECK=1 diagnoses overlapping pointer arguments; FLOWC_REGION_REPORT=1 writes per-binding remarks. Restrict / {llvm.noalias} emission remains #731.

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 own #684 (lifetime domains through fields), #690 (arena domains), #696 (move inference), and #731 (restrict/noalias emission). This PR adds compiler/src/region.flow and consumes the proofs only for memcpy-vs-memmove and diagnostics. It does not change noalias.flow.

Evidence

Baseline before this change: flowc had no region-inference module; contiguous copies always used memmove. The Python prototype lived only at archive/feat/694-region-inference.

Targeted proof that exercises the changed behaviour:

  • flowc selftest region_ok=1 (distinct locals, local vs param, two params, reassignment, call result, restrict candidates, pointer arithmetic)
  • ./flow test-lang tests/lang/test_region_inference.flow
  • ./flow tool tests/cgen/run.flow region_inference region_unproven noalias_restrict for_simd_hot_loops for_simd_carried (5 passed)
  • ./compiler/scripts/bootstrap_from_c.sh --regen (fixed point at gen2) and --verify (PASS)

Why that proof would detect the old failure or regression: the selftest asserts the Python prototype's soundness contract; the cgen golden fails if disjoint copies stay memmove or if parameters incorrectly become memcpy; the reject golden fails if the overlapping-borrow diagnostic is missing.

Repository gate(s) run: flowc selftest; targeted tests/cgen goldens including #731 noalias and SIMD copy goldens; test-lang for the new file; bootstrap --regen and --verify.

Generated/bootstrap state: compiler/bootstrap/flowc_stage_a.c regenerated in a separate commit; --verify reports the bootstrap C matches compiler/src.

Risk

Compatibility, performance, security, lifetime, backend, or release implications: fail-closed analysis; default programs still compile. Contiguous copies of proven-disjoint locals now use memcpy (defined for non-overlapping objects). Opt-in diagnostics only under FLOWC_REGION_CHECK=1. Documented gaps (interprocedural parameter disjointness, constant-slice intervals) stay fail-closed and are owned by #731.

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

(Default language behaviour is unchanged; the memcpy lowering and opt-in flags are documented in CHANGELOG.)

Agent handoff

Agent/provider/session: Cursor cloud agent.

Any remaining blocker is recorded in GitHub rather than only in local/session state: none. Do not merge; this PR is ready for review.

Open in Web Open in Cursor 

cursoragent and others added 3 commits October 5, 2026 11:50
Add a fail-closed intraprocedural region analysis in flowc: distinct owned
locals occupy distinct storage, a fresh local is disjoint from every
parameter, and pointer arithmetic inherits its base. Two parameters, a
reassignment, a call result, and two views of the same identity stay
may-alias.

Proven-disjoint unit-stride copies lower to memcpy instead of memmove.
FLOWC_REGION_CHECK diagnoses overlapping pointer arguments; FLOWC_REGION_REPORT
names each binding's region. Restrict emission remains #731.

Co-authored-by: Abhishek Shivakumar <[email protected]>
Keep compiler/bootstrap/flowc_stage_a.c byte-identical to flowc's bundle
emit of compiler/src/main.flow. Fixed point at gen2.

Co-authored-by: Abhishek Shivakumar <[email protected]>
GitHub never started the main CI workflow for this PR despite an open
pull_request targeting main; bpfel/wasm32 only ran on push. Empty commit
to fire the pull_request synchronize event.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht

Copy link
Copy Markdown
Contributor Author

Superseded by #1390 (merged as 38f3b79), which landed this PR's compiler/src/region.flow, the cgen/main/sem_check changes and tests/lang/test_region_inference.flow. #1390 did not bring the docs and C goldens. They are listed for a docs-and-goldens salvage PR in the merge queue: docs/language/region-inference.md, tests/cgen/region_inference.{flow,expect}, tests/cgen/region_unproven.{flow,expect}, and the LANGUAGE_SPEC.md, book chapter 10, spans.md, lifetime-domains.md, spec-index.md and CHANGELOG lines. Closing during PR triage; the branch is kept.

@godofecht godofecht closed this Oct 7, 2026
godofecht added a commit that referenced this pull request Oct 7, 2026
…om closed PRs

Salvaged from closed pull requests whose code already landed:

- #1360 (region inference, code merged as #1390): region-inference.md,
  the tests/cgen region_inference and region_unproven goldens, and the
  spec, book, spans, lifetime-domains, README, spec-index, nav and
  CHANGELOG lines.
- #1368 (noalias, code merged as #1388): the spans.md paragraph on
  restrict .data temporaries and its noalias.md link.
- #1380 (tail-resumptive effects, code merged as #1349): the spec-index
  row for effects-continuations.md.

#1417 landed after #1360 and keeps an unproven forward copy as an
ordered element loop. The region_inference golden and the docs now say
that, in place of the memmove the closed branch expected. The golden
fails on the pre-#1417 compiler, which emitted memmove.
godofecht added a commit that referenced this pull request Oct 7, 2026
…om closed PRs (#1425)

Salvaged from closed #1360 (region-inference.md, region_inference and region_unproven goldens, spec/book/index lines), #1368 (spans.md restrict .data paragraph) and #1380 (spec-index row for effects-continuations.md). The region_inference golden and docs follow #1417: an unproven parameter copy stays an ordered loop.
@godofecht
godofecht deleted the cursor/region-inference-694-316b 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] Local region inference and automated non-aliasing proofs

2 participants