Struct wit_parser::Resolve

source ·
pub struct Resolve {
    pub worlds: Arena<World>,
    pub interfaces: Arena<Interface>,
    pub types: Arena<TypeDef>,
    pub packages: Arena<Package>,
    pub package_names: IndexMap<PackageName, PackageId>,
}
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>

All knowns worlds within this Resolve.

Each world points at a PackageId which is stored below. No ordering is guaranteed between this list of worlds.

§interfaces: Arena<Interface>

All knowns interfaces within this Resolve.

Each interface points at a PackageId which is stored below. No ordering is guaranteed between this list of interfaces.

§types: Arena<TypeDef>

All knowns types within this Resolve.

Types are topologically sorted such that any type referenced from one type is guaranteed to be defined previously. Otherwise though these are not sorted by interface for example.

§packages: Arena<Package>

All knowns packages within this Resolve.

This list of packages is not sorted. Sorted packages can be queried through Resolve::topological_packages.

§package_names: IndexMap<PackageName, PackageId>

A map of package names to the ID of the package with that name.

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 push_flat(&self, ty: &Type, result: &mut Vec<WasmType>)

Appends the flat wasm types representing ty onto the result list provided.

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.

Dependencies referenced by the WIT package at path will be loaded from a deps/.. directory under path. All directories under deps/ will be parsed as a WIT package. The directory name containing each package is not used as each package is otherwise self-identifying.

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) -> 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) -> Result<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

This operation can fail if resolve disagrees with self about the packages being inserted. Otherwise though this will additionally attempt to “union” packages found in resolve with those found in self. Unioning packages is keyed on the name/url of packages for those with URLs present. If found then it’s assumed that both Resolve instances were originally created from the same contents and are two views of the same package.

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 id_of(&self, interface: InterfaceId) -> Option<String>

Returns the ID of the specified interface.

Returns None for unnamed interfaces.

source

pub fn id_of_name(&self, pkg: PackageId, name: &str) -> String

Returns the ID of the specified name within the pkg.

source

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

Attempts to locate a world given the “default” package pkg and the optional string specifier world.

This method is intended to be used by bindings generation tools to select a world from either pkg or a package in this Resolve.

If world is None then pkg must have precisely one world which will be returned.

If world is Some then it can either be:

  • A kebab-name of a world contained within pkg which is being selected, such as "the-world".

  • An ID-based form of a world which is selected within this Resolve, ignoring pkg. For example "wasi:http/proxy".

If successful the corresponding WorldId is returned, otherwise an error is returned.

source

pub fn name_world_key(&self, key: &WorldKey) -> String

Assigns a human readable name to the WorldKey specified.

source

pub fn type_interface_dep(&self, id: TypeId) -> Option<InterfaceId>

Returns the interface that id uses a type from, if it uses a type from a different interface than id is defined within.

If id is not a use-of-a-type or it’s using a type in the same interface then None is returned.

source

pub fn interface_direct_deps( &self, id: InterfaceId ) -> impl Iterator<Item = InterfaceId> + '_

Returns an iterator of all interfaces that the interface id depends on.

Interfaces may depend on others for type information to resolve type imports.

Note that the returned iterator may yield the same interface as a dependency multiple times. Additionally only direct dependencies of id are yielded, not transitive dependencies.

source

pub fn package_direct_deps( &self, id: PackageId ) -> impl Iterator<Item = PackageId> + '_

Returns an iterator of all packages that the package id depends on.

Packages may depend on others for type information to resolve type imports or interfaces to resolve worlds.

Note that the returned iterator may yield the same package as a dependency multiple times. Additionally only direct dependencies of id are yielded, not transitive dependencies.

source

pub fn topological_packages(&self) -> Vec<PackageId>

Returns a topological ordering of packages contained in this Resolve.

This returns a list of PackageId such that when visited in order it’s guaranteed that all dependencies will have been defined by prior items in the list.

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 Debug for Resolve

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Resolve

source§

fn default() -> Resolve

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

impl Serialize for Resolve

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where 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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.