Skip to content

Commit

Permalink
add async-streams-and-futures test to wit-component
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
  • Loading branch information
dicej committed Nov 18, 2024
1 parent ec67b25 commit 27bb59a
Show file tree
Hide file tree
Showing 6 changed files with 791 additions and 7 deletions.
16 changes: 12 additions & 4 deletions crates/wit-component/src/printing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,19 @@ impl WitPrinter {
self.output.push_str(">");
}
TypeDefKind::Type(ty) => self.print_type_name(resolve, ty)?,
TypeDefKind::Future(_) => {
todo!("document has an unnamed future type")
TypeDefKind::Future(ty) => {
if let Some(ty) = ty {
self.output.push_str("future<");
self.print_type_name(resolve, ty)?;
self.output.push_str(">");
} else {
self.output.push_str("future");
}
}
TypeDefKind::Stream(_) => {
todo!("document has an unnamed stream type")
TypeDefKind::Stream(ty) => {
self.output.push_str("stream<");
self.print_type_name(resolve, ty)?;
self.output.push_str(">");
}
TypeDefKind::ErrorContext => self.output.push_str("error-context"),
TypeDefKind::Unknown => unreachable!(),
Expand Down
14 changes: 11 additions & 3 deletions crates/wit-component/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ impl NameMangling for Legacy {
if let Some((suffix, imported)) = module
.strip_prefix("[import-payload]")
.map(|v| (v, true))
.or_else(|| name.strip_prefix("[export-payload]").map(|v| (v, false)))
.or_else(|| module.strip_prefix("[export-payload]").map(|v| (v, false)))
{
let (key, interface) = if suffix == self.import_root() {
(WorldKey::Name(name.to_string()), None)
Expand Down Expand Up @@ -1469,7 +1469,11 @@ impl NameMangling for Legacy {
ty: info(key)?.ty,
}
} else if let Some(key) = match_payload_prefix(name, "[future-cancel-read-") {
validate_func_sig(name, &FuncType::new([ValType::I32], []), ty)?;
validate_func_sig(
name,
&FuncType::new([ValType::I32], [ValType::I32]),
ty,
)?;
Import::FutureCancelRead {
async_,
ty: info(key)?.ty,
Expand Down Expand Up @@ -1525,7 +1529,11 @@ impl NameMangling for Legacy {
ty: info(key)?.ty,
}
} else if let Some(key) = match_payload_prefix(name, "[stream-cancel-read-") {
validate_func_sig(name, &FuncType::new([ValType::I32], []), ty)?;
validate_func_sig(
name,
&FuncType::new([ValType::I32], [ValType::I32]),
ty,
)?;
Import::StreamCancelRead {
async_,
ty: info(key)?.ty,
Expand Down
Loading

0 comments on commit 27bb59a

Please sign in to comment.