Repository navigation
feat: stable zero-copy FFI buffer ABI (#737) - #1347
Merged
Merged
Conversation
Define a pointer/span/array handoff contract with borrowed vs owned lifetime, fail-closed layout checks that never silently copy, a pointer-identity lang test, and a microbenchmark identity row. Co-authored-by: Abhishek Shivakumar <[email protected]>
Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht
marked this pull request as ready for review
October 5, 2026 02:06
The wiki builder requires every page under docs/ to appear in docs/nav.json. Put the zero-copy FFI buffer contract next to the export ABI under Language → Targets & interop. Co-authored-by: Abhishek Shivakumar <[email protected]>
This was referenced Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Linked issue: #737 (first useful slice only).
Define a stable zero-copy buffer ABI for compatible contiguous pointer/span/array data, with explicit borrowed vs owned lifetime, fail-closed layout checks, a structural no-copy proof, and a short contract note. This does not include the full Python/native-library audit or the #728 end-to-end suite.
#1277 already landed constructors and timing rows. Those did not check layout, did not fail closed, and did not prove the pointer was reused. This slice fills that gap instead of opening a second ABI.
Overlap check
Overlap / dependency notes:
Open PRs #1332, #1331, #1330, #1329, #1328, #1326, #1325, #1268, #1267, #1265 are affine/AoSoA/async-copy/opt-level/register-tile/startup/I-O/baseline work. None of them implement the #737 buffer contract. Merged #1277 is the stub this change extends.
Evidence
Baseline before this change:
On
9a278876,FFIBufferwas a Flow struct with borrowed/owned flags and optional instrumentation.tests/lang/test_ffi_buffer.flowonly checked those fields.flow_ffi.hhad no buffer type. Incompatible layout had no status and no refusal to copy.Targeted proof that exercises the changed behaviour:
Why that proof would detect the old failure or regression:
The old test passed if the struct fields were set, even if the implementation copied bytes. The new test fails unless
buf.datais the caller's pointer and a write through the view mutates the original storage. The C helper intests/lang/ffi_buffer_abi_helper.hincludesruntime/flow_ffi_buffer.hand must return the same address. A silent copy path would also fail the incompatible-layout cases (null view, unchanged source, zero copy-bytes).Repository gate(s) run:
./flow test-lang tests/lang/test_ffi_buffer.flow— pass./flow run benchmarks/micro/ffi_boundary_benchmark.flow— identity row pass./flow tool scripts/check_pkg_parity.flow— ffi goldens updated and passingruntime/flow_ffi_buffer.h— passGenerated/bootstrap state, if any:
None. Compiler sources that feed bootstrap C were not edited.
Risk
Compatibility, performance, security, lifetime, backend, or release implications:
FFIBuffergainsitem_align,dealloc, anddealloc_ctx(replacingdeallocator). That is a package 0.1.0 layout change, documented in the changelog. The C header is additive. No compiler lowering change: spans/arrays still lower as today; callers form the view explicitly.docs/project/Questions.mdupdated if this needs a language-design decision.Compatibility
docs/project/CHANGELOG.md.FFIBufferfield layout changed; existingffi_buffer_borrowed/ffi_buffer_ownedsignatures are unchanged.Agent handoff
Cursor cloud agent. Remaining #737 work (Python/native audit, #728 harness rows, break-even measurements on real crossings) stays on the issue.