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
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.
sourcepub fn call(
&self,
variant: AbiVariant,
lift_lower: LiftLower,
func: &Function,
bindgen: &mut impl Bindgen
)
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.
sourcepub fn guest_export_needs_post_return(&self, func: &Function) -> bool
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.
sourcepub fn post_return(&self, func: &Function, bindgen: &mut impl Bindgen)
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
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.
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.
sourcepub fn push(
&mut self,
unresolved: UnresolvedPackage,
deps: &HashMap<String, PackageId>
) -> Result<PackageId>
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.
pub fn all_bits_valid(&self, ty: &Type) -> bool
sourcepub fn merge(&mut self, resolve: Resolve) -> Remap
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
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 url_of(&self, interface: InterfaceId) -> Option<String>
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.
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 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.