core: make abi::cast and abi::flat_types public#1597
Open
ejrgilbert wants to merge 1 commit intobytecodealliance:mainfrom
Open
core: make abi::cast and abi::flat_types public#1597ejrgilbert wants to merge 1 commit intobytecodealliance:mainfrom
abi::cast and abi::flat_types public#1597ejrgilbert wants to merge 1 commit intobytecodealliance:mainfrom
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.
First, thanks so much for this crate, it's really simplified the implementation of my tool! I think you kept me from aging about 20 years over the course of a month :)
Motivation
The Generator emits
Instruction::Bitcastsautomatically during lowering of heterogeneous-arm variants (lower_variant_arms), but never during lifting. Rather,read_variant_arms_from_memoryreads each arm in its natural flat shape, then fires VariantLift without any widening in between.That asymmetry is fine for language backends whose
Operandis source text (since the variant-arm widening is deferred until the value is next lowered or pattern-matched, and the source-level type system handles it).However, it's a problem for
Bindgenimplementations that emit wasm directly. For any variant whose arms join to a wider type (e.g.result<string, u64>, where[Pointer, Length]and[I64]unify to[PointerOrI64, Length]), the wasm stack after each arm block has to converge on the joined-flat signature before the block ends...otherwise the module fails validation with "expected i64, found i32". The backend must emit the casts itself.The Fix
Enabling the backend to emit the casts just requires access to two things the upstream owns:
cast(WasmType, WasmType) -> Bitcast: the canonical-ABI bitcast-selection table.flat_types(&Resolve, &Type, Option<usize>) -> Option<Vec<WasmType>>: the joined flat shape to target.We can simply flip both to pub (they currently reference only already-public types: WasmType, Bitcast, Resolve, Type). No behavioral change; existing private callers are unaffected.
Discovering Use Case
I'm currently leveraging this crate to offload the canonical ABI lifting/lowering in my
splicertool that performs interface-agnostic component interposition by generating component adapters in pure Wasm. Right now, I have verbatim copies of these two functions. This PR would let me delete those copies and depend on your upstream implementation.