From f1137a0847650536b9a44fb826549a8f3aff4654 Mon Sep 17 00:00:00 2001 From: Brian Hardock Date: Fri, 3 Apr 2026 11:49:33 -0600 Subject: [PATCH] Add missing async/sync function type checking Signed-off-by: Brian Hardock --- crates/wac-graph/src/encoding.rs | 1 + crates/wac-parser/src/resolution.rs | 9 +++++---- crates/wac-types/src/aggregator.rs | 2 ++ crates/wac-types/src/checker.rs | 9 +++++++++ crates/wac-types/src/component.rs | 2 ++ crates/wac-types/src/package.rs | 6 +++++- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/crates/wac-graph/src/encoding.rs b/crates/wac-graph/src/encoding.rs index a120b3e..54aaba5 100644 --- a/crates/wac-graph/src/encoding.rs +++ b/crates/wac-graph/src/encoding.rs @@ -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); diff --git a/crates/wac-parser/src/resolution.rs b/crates/wac-parser/src/resolution.rs index 984d241..80694e2 100644 --- a/crates/wac-parser/src/resolution.rs +++ b/crates/wac-parser/src/resolution.rs @@ -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( diff --git a/crates/wac-types/src/aggregator.rs b/crates/wac-types/src/aggregator.rs index b3f8d0d..1b14421 100644 --- a/crates/wac-types/src/aggregator.rs +++ b/crates/wac-types/src/aggregator.rs @@ -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); @@ -958,6 +959,7 @@ mod tests { types.add_func_type(FuncType { params: IndexMap::new(), result: None, + is_async: false, }) } diff --git a/crates/wac-types/src/checker.rs b/crates/wac-types/src/checker.rs index 83d09ae..9ce5432 100644 --- a/crates/wac-types/src/checker.rs +++ b/crates/wac-types/src/checker.rs @@ -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!( diff --git a/crates/wac-types/src/component.rs b/crates/wac-types/src/component.rs index f62038b..126f29a 100644 --- a/crates/wac-types/src/component.rs +++ b/crates/wac-types/src/component.rs @@ -873,6 +873,8 @@ pub struct FuncType { pub params: IndexMap, /// The result of the function. pub result: Option, + /// Whether or not this is an async function. + pub is_async: bool, } impl FuncType { diff --git a/crates/wac-types/src/package.rs b/crates/wac-types/src/package.rs index da062e3..6ca479c 100644 --- a/crates/wac-types/src/package.rs +++ b/crates/wac-types/src/package.rs @@ -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) }