Skip to content

Commit

Permalink
add stream/future/error-context to wit-smith
Browse files Browse the repository at this point in the history
I had to tweak fuzz/src/wit64.rs because otherwise the old version of
`wit-component` it was using choked on these new types.  Now we just return
early when that happens.

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Dec 18, 2024
1 parent 30eb222 commit 4483389
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
28 changes: 28 additions & 0 deletions crates/wit-smith/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ impl<'a> InterfaceGenerator<'a> {
Option,
Result,
List,
Stream,
Future,
ErrorContext,
}

*fuel = match fuel.checked_sub(1) {
Expand Down Expand Up @@ -823,6 +826,31 @@ impl<'a> InterfaceGenerator<'a> {
(false, false) => {}
}
}
Kind::Stream => {
*fuel = match fuel.checked_sub(1) {
Some(fuel) => fuel,
None => continue,
};
dst.push_str("stream<");
self.gen_type(u, fuel, dst)?;
dst.push_str(">");
}
Kind::Future => {
*fuel = match fuel.checked_sub(1) {
Some(fuel) => fuel,
None => continue,
};
if u.arbitrary()? {
dst.push_str("future<");
self.gen_type(u, fuel, dst)?;
dst.push_str(">");
} else {
dst.push_str("future");
}
}
Kind::ErrorContext => {
dst.push_str("error-context");
}
};
}

Expand Down
7 changes: 6 additions & 1 deletion fuzz/src/wit64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ pub fn run(u: &mut Unstructured<'_>) -> Result<()> {
wit_smith::smith(&config, u)
})?;
write_file("doc.wasm", &wasm);
let r1 = wit_component_old::decode(&wasm).unwrap();
let Ok(r1) = wit_component_old::decode(&wasm) else {
// Presumably this is because the old version of `wit-component` doesn't
// understand the new `stream`, `future`, or `error-context` types, in
// which case there's no point in continuing, so we just return early.
return Ok(());
};
let r1 = r1.resolve();
let r2 = wit_component_new::decode(&wasm).unwrap();
let r2 = r2.resolve();
Expand Down

0 comments on commit 4483389

Please sign in to comment.