Skip to main content

Module abi

Module abi 

Source
Expand description

Driving the Swift runtime directly: the ABI this crate speaks.

Nothing here goes through a Swift source file. A SwiftUI view is built by finding a mangled symbol with dlsym, arranging registers the way the Swift compiler would have, and branching to it. That works because Swift’s arm64 convention is stable and documented — but three of its registers have no counterpart in a Rust signature, so every call has to be written out:

registerrole
x0–x7integer and pointer arguments, then any generic metadata, then any witness tables
d0–d7floating-point arguments
x8address of an indirect (@out) result
x20the self register: a receiver, or a type’s metadata for an initialiser or static
x21the error register, which nothing here throws through and everything clobbers

Whether a value travels in a register or by address is the question that decides whether a call works, and it is not visible in the symbol name. A @frozen type of at most four registers is passed directly; a resilient one is passed by address, because the caller is not allowed to know its size. Two traps follow from that and both cost real time here:

  • An Optional’s payload is not destructured. Optional<UnitPoint> is two CGFloats and a tag, and it arrives as three integer registers — a Double inside an optional reaches the callee in x0, not d0.
  • Getting a return convention wrong rarely faults at the call. A function that writes through x8 while the caller reads x0 hands back a stale register, which SwiftUI stores and dereferences much later.

call holds the primitives that make those choices explicit, and the rest of this module is built on them:

  • value — enum tags, optionals, strings and arrays
  • metadata — type metadata, witness tables and layout queries
  • modifier — applying a View modifier and wrapping the result
  • closure — Rust functions Swift can call back into

Re-exports§

pub use call::call_f64;
pub use call::call_out;
pub use call::call_regs;
pub use call::call_spilled;
pub use call::ints;
pub use call::static_out;
pub use call::static_regs;
pub use call::Floats;
pub use call::Ints;

Modules§

call
Calling into Swift: the two shapes every call takes.

Macros§

type_by_name
Resolve a Swift type from its mangled name string.

Structs§

ClosureCtx
Context for a Swift () -> T closure implemented in Rust.
FloatClosureCtx
Context for a Swift closure returning a Double.
IndexClosureCtx
Context for a Swift (Int) -> T closure implemented in Rust.
IsolatedContext
The context an @isolated(any) async closure carries.
Pair
Two words, laid out so the ABI returns them in x0 and x1.
PairClosureCtx
Context for a Swift (A, A) -> () closure implemented in Rust.
PairReturnClosureCtx
Context for a Swift closure returning two words.
ValueClosureCtx
Context for a Swift (Value) -> () closure implemented in Rust.
WideClosureCtx
Context for a Swift (V) -> () closure where V may span three registers.
WordClosureCtx
Context for a Swift closure returning a single word.

Functions§

anyview_wrap⚠
Wrap any view value in AnyView.
array_parts⚠
The elements and count of a Swift Array.
call_modifier⚠
Apply a View modifier that takes only plain arguments.
call_modifier_d0⚠
Call a generic View modifier on an AnyView.
call_modifier_generic⚠
Call a View modifier whose integer arguments are given in full.
copy_value⚠
Copy a Swift value into uninitialised memory, at +1.
enum_argument⚠
A no-payload enum’s case, ready to pass in a register.
enum_case_index⚠
The tag of a payload enum case, by name.
enum_tag⚠
Which case a multi-payload enum holds.
field_type_metadata⚠
The metadata of meta’s indexth stored field.
float_closure_thunk⚠
Address to hand to Swift for a closure returning a Double.
generic_key_argument_count⚠
How many key arguments a type’s metadata accessor expects.
generic_metadata1⚠
Call a generic type’s metadata accessor with one key argument.
generic_metadata2⚠
Call a generic type’s metadata accessor with two key arguments.
generic_metadata_from⚠
Safety
generic_metadata_from_descriptor⚠
Instantiate a generic type that exports no metadata accessor.
get_view_wt⚠
Get the View witness table for a type from the runtime.
get_view_wt_for_proto⚠
Get a protocol witness table for a type via swift_conformsToProtocol.
index_closure_thunk⚠
Address to hand to Swift for a one-argument closure.
inject_enum_tag⚠
Create a Swift.String from a Rust &str, copying the bytes.
mangled_type_name⚠
The mangled name of whatever meta describes.
metadata0⚠
Call a metadata accessor that takes no key arguments (a non-generic but resilient type, whose layout is only known at runtime).
pair_closure_thunk⚠
Address to hand to Swift for a two-argument, no-result closure.
pair_return_closure_thunk⚠
Address to hand to Swift for a () -> (word, word) closure.
read_enum_tag⚠
Which case of an enum a value holds.
read_optional_tag⚠
Which case an Optional<T> holds.
read_swift_string⚠
Read a Swift String value back into a Rust one.
resolve_type_by_mangled_name⚠
Safety
set_count⚠
How many elements a Swift Set holds.
store_optional_tag⚠
Write Optional<T>’s discriminator into buf.
store_optional_tag_at⚠
store_optional_tag writing through a raw pointer rather than a slice.
struct_field_offsets⚠
Where a struct keeps each of its stored properties.
swift_array⚠
Build a Swift.Array of count elements from raw bytes laid out at the element type’s stride.
swift_closure_thunk⚠
Address to hand to Swift as the closure function pointer.
swift_set⚠
Build a Swift Set holding count elements laid out in bytes.
swift_string⚠
Safety
tuple_element_offsets⚠
Where each element of a tuple sits inside it.
tuple_metadata⚠
Build metadata for a tuple of elements.
type_bytes⚠
How many bytes to allocate for a value of this type.
type_destroy⚠
Destroy a value in place, through its type’s value witness.
type_size⚠
Size in bytes of a type, from its value witness table.
type_stride⚠
Stride in bytes of a type — the spacing between consecutive array elements, which is not the same as its size once alignment padding is involved.
value_closure_thunk⚠
Address to hand to Swift for a one-argument, no-result closure.
wide_closure_thunk⚠
Address to hand to Swift for a one-argument, no-result closure whose argument may not fit in a single register.
word_closure_thunk⚠
Address to hand to Swift for a closure returning one word.