Struct wit_parser::Resolve

source ·
pub struct Resolve {
    pub worlds: Arena<World>,
    pub interfaces: Arena<Interface>,
    pub types: Arena<TypeDef>,
    pub documents: Arena<Document>,
    pub packages: Arena<Package>,
}
Expand description

Representation of a fully resolved set of WIT packages.

This structure contains a graph of WIT packages and all of their contents merged together into the contained arenas. All items are sorted topologically and everything here is fully resolved, so with a Resolve no name lookups are necessary and instead everything is index-based.

Working with a WIT package requires inserting it into a Resolve to ensure that all of its dependencies are satisfied. This will give the full picture of that package’s types and such.

Each item in a Resolve has a parent link to trace it back to the original package as necessary.

Fields§

§worlds: Arena<World>§interfaces: Arena<Interface>§types: Arena<TypeDef>§documents: Arena<Document>§packages: Arena<Package>

Implementations§

source§

impl Resolve

source

pub fn wasm_signature( &self, variant: AbiVariant, func: &Function ) -> WasmSignature

Get the WebAssembly type signature for this interface function

The first entry returned is the list of parameters and the second entry is the list of results for the wasm function signature.

source

pub fn call( &self, variant: AbiVariant, lift_lower: LiftLower, func: &Function, bindgen: &mut impl Bindgen )

Generates an abstract sequence of instructions which represents this function being adapted as an imported function.

The instructions here, when executed, will emulate a language with interface types calling the concrete wasm implementation. The parameters for the returned instruction sequence are the language’s own interface-types parameters. One instruction in the instruction stream will be a Call which represents calling the actual raw wasm function signature.

This function is useful, for example, if you’re building a language generator for WASI bindings. This will document how to translate language-specific values into the wasm types to call a WASI function, and it will also automatically convert the results of the WASI function back to a language-specific value.

source

pub fn guest_export_needs_post_return(&self, func: &Function) -> bool

Returns whether the Function specified needs a post-return function to be generated in guest code.

This is used when the return value contains a memory allocation such as a list or a string primarily.

source

pub fn post_return(&self, func: &Function, bindgen: &mut impl Bindgen)

Used in a similar manner as the Interface::call function except is used to generate the post-return callback for func.

This is only intended to be used in guest generators for exported functions and will primarily generate GuestDeallocate* instructions, plus others used as input to those instructions.

source§

impl Resolve

source

pub fn new() -> Resolve

Creates a new Resolve with no packages/items inside of it.

source

pub fn push_dir(&mut self, path: &Path) -> Result<(PackageId, Vec<PathBuf>)>

Parses the filesystem directory at path as a WIT package and returns the fully resolved PackageId as a result.

This method is intended for testing and convenience for now and isn’t the only way to push packages into this Resolve. This will interpret path as a directory where all *.wit files in that directory are members of the package.

Dependencies referenced by the WIT package at path will be loaded from a deps/$name directory under path where $name is the name of the dependency loaded. If deps/$name does not exist then an error will be returned indicating that the dependency is not defined. All dependencies are listed in a flat namespace under $path/deps so they can refer to each other.

This function returns the PackageId of the root parsed package at path, along with a list of all paths that were consumed during parsing for the root package and all dependency packages.

source

pub fn push( &mut self, unresolved: UnresolvedPackage, deps: &HashMap<String, PackageId> ) -> Result<PackageId>

Appends a new UnresolvedPackage to this Resolve, creating a fully resolved package with no dangling references.

The deps argument indicates that the named dependencies in unresolved to packages are resolved by the mapping specified.

Any dependency resolution error or otherwise world-elaboration error will be returned here. If successful a package identifier is returned.

source

pub fn all_bits_valid(&self, ty: &Type) -> bool

source

pub fn merge(&mut self, resolve: Resolve) -> Remap

Merges all the contents of a different Resolve into this one. The Remap structure returned provides a mapping from all old indices to new indices

source

pub fn merge_worlds(&mut self, from: WorldId, into: WorldId) -> Result<()>

Merges the world from into the world into.

This will attempt to merge one world into another, unioning all of its imports and exports together. This is an operation performed by wit-component, for example where two different worlds from two different libraries were linked into the same core wasm file and are producing a singular world that will be the final component’s interface.

This operation can fail if the imports/exports overlap.

source

pub fn url_of(&self, interface: InterfaceId) -> Option<String>

Returns the URL of the specified interface, if available.

This currently creates a URL based on the URL of the package that interface resides in. If the package owner of interface does not specify a URL then None will be returned.

If the interface specified does not have a name then None will be returned as well.

source

pub fn select_world(&self, pkg: PackageId, world: Option<&str>) -> Result<WorldId>

Attempts to locate a default world for the pkg specified within this Resolve. Optionally takes a string-based world “specifier” to resolve the world.

This is intended for use by bindings generators and such as the default logic for locating a world within a package used for binding. The world argument is typically a user-specified argument (which again is optional and not required) where the pkg is determined ambiently by the integration.

If world is None (e.g. not specified by a user) then the package must have exactly one default world within its documents, otherwise an error will be returned. If world is Some then it’s a .-separated name where the first element is the name of the document and the second, optional, element is the name of the world. For example the name foo would mean the default world of the foo document. The name foo.bar would mean the world named bar in the foo document.

Trait Implementations§

source§

impl Clone for Resolve

source§

fn clone(&self) -> Resolve

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Resolve

source§

fn default() -> Resolve

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.