MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / definition

Method definition

crates/wasmtime/src/runtime/component/matching.rs:39–121  ·  view source on GitHub ↗
(
        &mut self,
        expected: &TypeDef,
        actual: Option<&Definition>,
    )

Source from the content-addressed store, hash-verified

37
38impl TypeChecker<'_> {
39 pub(crate) fn definition(
40 &mut self,
41 expected: &TypeDef,
42 actual: Option<&Definition>,
43 ) -> Result<()> {
44 match *expected {
45 TypeDef::Module(t) => match actual {
46 Some(Definition::Module(actual)) => self.module(&self.types[t], actual),
47 Some(actual) => bail!("expected module found {}", actual.desc()),
48 None => bail!("module implementation is missing"),
49 },
50 TypeDef::ComponentInstance(t) => match actual {
51 Some(Definition::Instance(actual)) => self.instance(&self.types[t], Some(actual)),
52 None => self.instance(&self.types[t], None),
53 Some(actual) => bail!("expected instance found {}", actual.desc()),
54 },
55 TypeDef::ComponentFunc(t) => match actual {
56 Some(Definition::Func(actual)) => self.func(t, actual),
57 Some(actual) => bail!("expected function found {}", actual.desc()),
58 None => bail!("function implementation is missing"),
59 },
60 TypeDef::Component(_) => match actual {
61 Some(actual) => bail!("expected component found {}", actual.desc()),
62 None => bail!("component implementation is missing"),
63 },
64 TypeDef::Interface(_) => match actual {
65 Some(actual) => bail!("expected type found {}", actual.desc()),
66 None => bail!("type implementation is missing"),
67 },
68
69 TypeDef::Resource(i) => {
70 let i = self.types[i].unwrap_concrete_ty();
71 let actual = match actual {
72 Some(Definition::Resource(actual, _dtor)) => actual,
73
74 // If a resource is imported yet nothing was supplied then
75 // that's only successful if the resource has itself
76 // already been defined. If it's already defined then that
77 // means that this is an `(eq ...)` import which is not
78 // required to be satisfied via `Linker` definitions in the
79 // Wasmtime API.
80 None if self.imported_resources.get(i).is_some() => return Ok(()),
81
82 Some(actual) => bail!("expected resource found {}", actual.desc()),
83 None => bail!("resource implementation is missing"),
84 };
85
86 match self.imported_resources.get(i) {
87 // If `i` hasn't been pushed onto `imported_resources` yet
88 // then that means that it's the first time a new resource
89 // was introduced, so record the type of this resource. It
90 // should always be the case that the next index assigned
91 // is equal to `i` since types should be checked in the
92 // same order they were assigned into the `Component` type.
93 //
94 // Note the `get_mut` here which is expected to always
95 // succeed since `imported_resources` has not yet been
96 // cloned.

Callers 3

assert_type_matchesMethod · 0.45
instanceMethod · 0.45
typecheckMethod · 0.45

Calls 10

OkFunction · 0.85
get_mutFunction · 0.85
unwrap_concrete_tyMethod · 0.80
moduleMethod · 0.45
instanceMethod · 0.45
funcMethod · 0.45
is_someMethod · 0.45
getMethod · 0.45
unwrapMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected