Optimize MoonBit canonical list arguments with typed borrows - #1672
Draft
peter-jerry-ye wants to merge 2 commits into
Draft
Optimize MoonBit canonical list arguments with typed borrows#1672peter-jerry-ye wants to merge 2 commits into
peter-jerry-ye wants to merge 2 commits into
Conversation
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.
Why
MoonBit imports currently lower canonical lists through untyped integer pointers. This obscures the call-scoped lifetime of argument storage and causes
list<u16>andlist<s16>to allocate staging memory and lower every element because their public element types are widened.What changed
u16ands16asUInt16andInt16.bool, asFixedArray[T].#borrowFFI parameters, with the paired length defaulting toarray.length().cabi_realloc; returned lists are not treated as borrows.Why this is correct
The optimized path is limited to element types whose MoonBit array storage matches the Canonical ABI element size and alignment. It is only selected for synchronous imports with direct parameters, so the backing array remains alive for the complete host call. Async, indirect, nested resource-bearing, and non-compatible payloads continue to use their existing lowering behavior.
Regression coverage checks direct and record-flattened parameters, Boolean byte layout, compatible result lifting, and preservation of generic list lowering.
Scope
This change does not alter stream or future runtime behavior, resource ownership,
FixedArraysemantics, or canonical return allocation. Stream-specific bulk-copy work remains separate.