Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/wac-graph/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl<'a> TypeEncoder<'a> {
let result = ty.result.map(|ty| self.value_type(state, ty));
let index = state.current.encodable.type_count();
let mut encoder = state.current.encodable.ty().function();
encoder.async_(ty.is_async);
encoder.params(params);
encoder.result(result);

Expand Down
9 changes: 5 additions & 4 deletions crates/wac-parser/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,10 +2130,11 @@ impl<'a> AstResolver<'a> {
}
};

Ok(state
.graph
.types_mut()
.add_func_type(FuncType { params, result }))
Ok(state.graph.types_mut().add_func_type(FuncType {
params,
result,
is_async: false,
}))
}

fn expr(
Expand Down
2 changes: 2 additions & 0 deletions crates/wac-types/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ impl TypeAggregator {
.result
.map(|ty| self.remap_value_type(types, ty, checker))
.transpose()?,
is_async: ty.is_async,
};

let remapped_id = self.types.add_func_type(remapped);
Expand Down Expand Up @@ -958,6 +959,7 @@ mod tests {
types.add_func_type(FuncType {
params: IndexMap::new(),
result: None,
is_async: false,
})
}

Expand Down
9 changes: 9 additions & 0 deletions crates/wac-types/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ impl<'a> SubtypeChecker<'a> {
// rather than actual subtyping; the reason for this is that implementing
// runtimes don't yet support more complex subtyping rules.

if a.is_async != b.is_async {
let (expected, _, found, _) = self.expected_found(a, at, b, bt);
bail!(
"expected {} function, found {} function",
if expected.is_async { "async" } else { "sync" },
if found.is_async { "async" } else { "sync" },
);
}

if a.params.len() != b.params.len() {
let (expected, _, found, _) = self.expected_found(a, at, b, bt);
bail!(
Expand Down
2 changes: 2 additions & 0 deletions crates/wac-types/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ pub struct FuncType {
pub params: IndexMap<String, ValueType>,
/// The result of the function.
pub result: Option<ValueType>,
/// Whether or not this is an async function.
pub is_async: bool,
}

impl FuncType {
Expand Down
6 changes: 5 additions & 1 deletion crates/wac-types/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,11 @@ impl<'a> TypeConverter<'a> {
None => None,
};

let id = self.types.add_func_type(FuncType { params, result });
let id = self.types.add_func_type(FuncType {
params,
result,
is_async: func_ty.async_,
});
self.cache.insert(key, Entity::Type(Type::Func(id)));
Ok(id)
}
Expand Down
Loading