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:
| register | role |
|---|---|
x0–x7 | integer and pointer arguments, then any generic metadata, then any witness tables |
d0–d7 | floating-point arguments |
x8 | address of an indirect (@out) result |
x20 | the self register: a receiver, or a type’s metadata for an initialiser or static |
x21 | the 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 twoCGFloats and a tag, and it arrives as three integer registers — aDoubleinside 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 arraysmetadata— type metadata, witness tables and layout queriesmodifier— applying aViewmodifier and wrapping the resultclosure— 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§
- Closure
Ctx - Context for a Swift
() -> Tclosure implemented in Rust. - Float
Closure Ctx - Context for a Swift closure returning a
Double. - Index
Closure Ctx - Context for a Swift
(Int) -> Tclosure implemented in Rust. - Isolated
Context - The context an
@isolated(any)async closure carries. - Pair
- Two words, laid out so the ABI returns them in x0 and x1.
- Pair
Closure Ctx - Context for a Swift
(A, A) -> ()closure implemented in Rust. - Pair
Return Closure Ctx - Context for a Swift closure returning two words.
- Value
Closure Ctx - Context for a Swift
(Value) -> ()closure implemented in Rust. - Wide
Closure Ctx - Context for a Swift
(V) -> ()closure whereVmay span three registers. - Word
Closure Ctx - 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
Viewmodifier that takes only plain arguments. - call_
modifier_ ⚠d0 - Call a generic View modifier on an AnyView.
- call_
modifier_ ⚠generic - Call a
Viewmodifier 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’sindexth 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
metadescribes. - 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
Stringvalue back into a Rust one. - resolve_
type_ ⚠by_ mangled_ name - Safety
- set_
count ⚠ - How many elements a Swift
Setholds. - store_
optional_ ⚠tag - Write
Optional<T>’s discriminator intobuf. - store_
optional_ ⚠tag_ at store_optional_tagwriting 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.Arrayofcountelements 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
Setholdingcountelements laid out inbytes. - 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.