Skip to content

Commit da2d014

Browse files
committed
Add missing async/sync function type checking
Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
1 parent 7e93052 commit da2d014

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

crates/wac-graph/src/encoding.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ impl<'a> TypeEncoder<'a> {
231231
let result = ty.result.map(|ty| self.value_type(state, ty));
232232
let index = state.current.encodable.type_count();
233233
let mut encoder = state.current.encodable.ty().function();
234+
encoder.async_(ty.is_async);
234235
encoder.params(params);
235236
encoder.result(result);
236237

crates/wac-parser/src/resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@ impl<'a> AstResolver<'a> {
21332133
Ok(state
21342134
.graph
21352135
.types_mut()
2136-
.add_func_type(FuncType { params, result }))
2136+
.add_func_type(FuncType { params, result, is_async: false }))
21372137
}
21382138

21392139
fn expr(

crates/wac-types/src/aggregator.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ impl TypeAggregator {
678678
.result
679679
.map(|ty| self.remap_value_type(types, ty, checker))
680680
.transpose()?,
681+
is_async: ty.is_async,
681682
};
682683

683684
let remapped_id = self.types.add_func_type(remapped);
@@ -958,6 +959,7 @@ mod tests {
958959
types.add_func_type(FuncType {
959960
params: IndexMap::new(),
960961
result: None,
962+
is_async: false,
961963
})
962964
}
963965

crates/wac-types/src/checker.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ impl<'a> SubtypeChecker<'a> {
171171
// rather than actual subtyping; the reason for this is that implementing
172172
// runtimes don't yet support more complex subtyping rules.
173173

174+
if a.is_async != b.is_async {
175+
let (expected, _, found, _) = self.expected_found(a, at, b, bt);
176+
bail!(
177+
"expected {} function, found {} function",
178+
if expected.is_async { "async" } else { "sync" },
179+
if found.is_async { "async" } else { "sync" },
180+
);
181+
}
182+
174183
if a.params.len() != b.params.len() {
175184
let (expected, _, found, _) = self.expected_found(a, at, b, bt);
176185
bail!(

crates/wac-types/src/component.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,8 @@ pub struct FuncType {
873873
pub params: IndexMap<String, ValueType>,
874874
/// The result of the function.
875875
pub result: Option<ValueType>,
876+
/// Whether or not this is an async function.
877+
pub is_async: bool,
876878
}
877879

878880
impl FuncType {

crates/wac-types/src/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl<'a> TypeConverter<'a> {
443443
None => None,
444444
};
445445

446-
let id = self.types.add_func_type(FuncType { params, result });
446+
let id = self.types.add_func_type(FuncType { params, result, is_async: func_ty.async_ });
447447
self.cache.insert(key, Entity::Type(Type::Func(id)));
448448
Ok(id)
449449
}

0 commit comments

Comments
 (0)