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>
§interfaces: Arena<Interface>
§types: Arena<TypeDef>
§packages: Arena<Package>
§package_names: IndexMap<PackageName, PackageId>
Implementations§
source§impl Resolve
impl Resolve
sourcepub fn wasm_signature(
&self,
variant: AbiVariant,
func: &Function
) -> WasmSignature
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§impl Resolve
impl Resolve
sourcepub fn push_dir(&mut self, path: &Path) -> Result<(PackageId, Vec<PathBuf>)>
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.
sourcepub fn push(&mut self, unresolved: UnresolvedPackage) -> Result<PackageId>
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.
pub fn all_bits_valid(&self, ty: &Type) -> bool
sourcepub fn merge(&mut self, resolve: Resolve) -> Result<Remap>
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.
sourcepub fn merge_worlds(&mut self, from: WorldId, into: WorldId) -> Result<()>
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.
sourcepub fn id_of(&self, interface: InterfaceId) -> Option<String>
pub fn id_of(&self, interface: InterfaceId) -> Option<String>
Returns the ID of the specified interface
.
Returns None
for unnamed interfaces.
sourcepub fn id_of_name(&self, pkg: PackageId, name: &str) -> String
pub fn id_of_name(&self, pkg: PackageId, name: &str) -> String
Returns the ID of the specified name
within the pkg
.
sourcepub fn select_world(
&self,
pkg: PackageId,
world: Option<&str>
) -> Result<WorldId>
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
, ignoringpkg
. For example"wasi:http/proxy"
.
If successful the corresponding WorldId
is returned, otherwise an
error is returned.
sourcepub fn name_world_key(&self, key: &WorldKey) -> String
pub fn name_world_key(&self, key: &WorldKey) -> String
Assigns a human readable name to the WorldKey
specified.
sourcepub fn interface_direct_deps(
&self,
id: InterfaceId
) -> impl Iterator<Item = InterfaceId> + '_
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 iterate may yield the same interface as a
dependency multiple times. Additionally only direct dependencies of id
are yielded, not transitive dependencies.