Skip to content

Canonical ABI Lifting and Lowering Support - #32

Open
jeremyg484 wants to merge 3 commits into
roastedroot:mainfrom
jeremyg484:extract-canonical-abi-for-pr
Open

Canonical ABI Lifting and Lowering Support#32
jeremyg484 wants to merge 3 commits into
roastedroot:mainfrom
jeremyg484:extract-canonical-abi-for-pr

Conversation

@jeremyg484

@jeremyg484 jeremyg484 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

A canonical-abi module is added that provides all of the low-level
operations needed for the runtime to lift and lower to the Component
Model's Canonical ABI.

See https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md
for reference.

CanonicalAbi.java provides the main API surface for consumers, with
public methods for lifting and lowering function arguments and results.
The semantics defined by the spec for loading from and storing to core
wasm memory, as well as the "flattening" of arguments and results to
avoid the memory reading and writing when possible, are implemented
therein. The methods implemented largely mirror those of the spec's
Canonical ABI Python reference definitions, with idioms converted to
Java as appropriate.

A third "direct transfer" path is added as an optimization to
potentially be used in component-to-component calls where the lifting
and lowering is connecting the functions of two embedded core wasm
modules. This path bypasses conversion to higher-level Java types in
favor of either passing core wasm values and results directly (in the
simplest cases) or by copying data directly between the modules'
memories. This path still handles necessary work such as conversion
between different string encodings, working at the byte level without
intermediary conversion to Java Strings. Not all lift/lower pairs can
be connected this way (for example, when resources are involved), so
methods are provided to check eligibility.

A suite of tests are implemented that verify the functionality of all
three paths and ensure symmetry between them.

Note that Records are currently converted from/to Java Maps as a
starting point to keep things simple. Support for conversion from/to
higher-level strongly-typed objects should be able to be layered on top
of this later.

Also note that no attempt has been made yet to support the async ABI,
though care has been taken to ensure that such support can be added
at a later time.

A canonical-abi module is added that provides all of the low-level
operations needed for the runtime to lift and lower to the Component
Model's Canonical ABI.

CanonicalAbi.java provides the main API surface for consumers, with
public methods for lifting and lowering function arguments and results.
The semantics defined by the spec for loading from and storing to core
wasm memory, as well as the "flattening" of arguments and results to
avoid the memory reading and writing when possible. The methods
implemented largely mirror those of the spec's Canonical ABI Python
reference definitions, with idioms converted to Java as appropriate.

A third "direct transfer" path is added as an optimization to
potentially be used in component-to-component calls where the lifting
and lowering is connecting the functions of two embedded core wasm
modules. This path bypasses conversion to higher-level Java types in
favor of either passing core wasm values and results directly (in the
simplest cases) or by copying data directly between the modules'
memories. This path still handles necessary work such as conversion
between different string encodings, working at the byte level without
intermediary conversion to Java Strings. Not all lift/lower pairs can
be connected this way (for example, when resources are involved), so
methods are provided to check eligibility.

A suite of tests are implemented that verify the functionality of all
three paths and ensure symmetry between them.
@jeremyg484
jeremyg484 marked this pull request as ready for review August 12, 2026 11:48
@jeremyg484
jeremyg484 requested a review from andreaTP August 12, 2026 15:15
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.

1 participant