Skip to content

feat: FFI Python/native audit, #728 rows, and break-even (#737) - #1352

Merged
godofecht merged 5 commits into
mainfrom
cursor/ffi-boundary-audit-737-f969
Oct 5, 2026
Merged

godofecht merged 5 commits into
mainfrom
cursor/ffi-boundary-audit-737-f969

Conversation

@godofecht

@godofecht godofecht commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #737

Intent

Linked issue or roadmap item: #737 (remaining slice after merged #1347).

Implement the leftover acceptance work: a Python/native-library boundary audit, #728 harness rows for FFI crossings, and break-even measurements on real C crossings. The stable zero-copy buffer ABI from #1347 is unchanged.

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:

#1347 already landed the C FlowFfiBuffer ABI. Open PRs (#1348, #1346, #1345, #1332–#1325, #1268, #1267, #1265) are RT-safe/codegen/cache/affine/startup work and do not implement this audit.

Evidence

Baseline before this change:

On a1b62114, docs/language/ffi-buffer.md marked the Python/native audit and #728 suite out of scope. bench_harness had no FFI workload directories. Break-even guidance was a guessed “fewer than 1000 elements” comment.

Targeted proof that exercises the changed behaviour:

./flow test-lang tests/lang/test_ffi_boundary_audit.flow
# All 1 language tests passed

./flow run benchmarks/micro/ffi_breakeven.flow
# zero-copy identity: PASS copied_bytes=0
# c_buffer_zero_copy copied_bytes=0 vs c_buffer_copy copied_bytes=262144000
# breakeven_batch= printed from live crossings

./flow run benchmarks/cross_harness/runtime/ffi_buffer/ffi_buffer.flow
# exit 0

./flow tool tests/scripts/ffi_boundary.flow
# 4 passed, 0 failed, 0 skipped

Why that proof would detect the old failure or regression:

The catalog test fails if a compatible C/Python/native handoff is classified as an O(n) copy, or if pywheel silently accepts a buffer. The break-even program fails if try_borrow copies the pointer or the explicit copy path does not move payload bytes. The scripts test fails if the audit page is missing from docs/nav.json or a #728 row is absent.

Repository gate(s) run:

  • ./flow test-lang tests/lang/test_ffi_boundary_audit.flow — pass
  • ./flow test-lang tests/lang/test_ffi_buffer.flow — pass
  • ./flow run of the five new harness rows — pass
  • ./flow tool tests/scripts/ffi_boundary.flow — pass
  • ./flow tool wiki_nav — pass
  • ./flow tool python_ratchet — pass
  • ./flow tool scripts/check_pkg_parity.flow — ffi cases pass after golden refresh; remaining install-git-bad-tag is an unrelated git warning on this host

Generated/bootstrap state, if any:

None. compiler/src was not edited.

Risk

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

Additive ffi package exports (ffi_crossing_class, PEP 3118 mapping, ffi_breakeven_batch). No compiler or bootstrap C change. No new Python files.

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

flow python still refuses pointer/span/array; that is documented, not changed. Zero-copy Python arrays continue to use the C ABI through ctypes / PEP 3118.

Agent handoff

Cursor cloud agent. flow python buffer-protocol export remains future work (documented in the audit); it is not required for the #737 acceptance criteria.

Open in Web Open in Cursor 

cursoragent and others added 5 commits October 5, 2026 11:47
Add the remaining #737 slice on top of the stable buffer ABI: an
executable C/Python/native crossing catalog, harness rows for scalar,
batched, and zero-copy crossings, and live break-even measurements.

Co-authored-by: Abhishek Shivakumar <[email protected]>
boundary_audit.flow must list before buffer_handoff.flow so the
package snapshot walker matches the recorded expect files.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht merged commit 12340a1 into main Oct 5, 2026
33 checks passed
godofecht added a commit that referenced this pull request Oct 7, 2026
main gained runtime/ffi_scalar, ffi_batch and ffi_buffer (#1352) after
this branch was cut, so --check-runtime-natives failed on the rebase.
Each twin makes the same noinline call from C, so flow_vs_native is the
cost of the Flow side of the crossing. Also rewords four sentences in
runtime-primitive-attribution.md that the prose lint rejects.
godofecht added a commit that referenced this pull request Oct 7, 2026
main gained runtime/ffi_scalar, ffi_batch and ffi_buffer (#1352) after
this branch was cut, so --check-runtime-natives failed on the rebase.
Each twin makes the same noinline call from C, so flow_vs_native is the
cost of the Flow side of the crossing. Also rewords four sentences in
runtime-primitive-attribution.md that the prose lint rejects.
@godofecht
godofecht deleted the cursor/ffi-boundary-audit-737-f969 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.

[Performance #727] Define zero-copy FFI/buffer handoff contracts and benchmark boundary overhead

2 participants