Skip to content

Commit 9808631

Browse files
rvolosatovsdicej
andauthored
feat: add support for stream with no <T> (#1130)
* feat: add support for `stream` with no `<T>` Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net> test: return `future` in future return test WIT Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net> build: update wasm-tools Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net> avoid divide-by-zero in `StreamReader::poll_next` I hit this when testing "unit streams" (i.e. streams with no payload type) end-to-end. BTW, I can't wait to get some runtime tests going in this repo so we can catch this kind of thing in CI. Signed-off-by: Joel Dice <joel.dice@fermyon.com> * update to latest wasm-tools Signed-off-by: Joel Dice <joel.dice@fermyon.com> --------- Signed-off-by: Joel Dice <joel.dice@fermyon.com> Co-authored-by: Joel Dice <joel.dice@fermyon.com>
1 parent 967d075 commit 9808631

File tree

15 files changed

+113
-82
lines changed

15 files changed

+113
-82
lines changed

Cargo.lock

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ prettyplease = "0.2.20"
3333
syn = { version = "2.0.89", features = ["printing"] }
3434
futures = "0.3.31"
3535

36-
wasmparser = "0.223.0"
37-
wasm-encoder = "0.223.0"
38-
wasm-metadata = "0.223.0"
39-
wit-parser = "0.223.0"
40-
wit-component = "0.223.0"
36+
wasmparser = "0.224.0"
37+
wasm-encoder = "0.224.0"
38+
wasm-metadata = "0.224.0"
39+
wit-parser = "0.224.0"
40+
wit-component = "0.224.0"
4141

4242
wit-bindgen-core = { path = 'crates/core', version = '0.37.0' }
4343
wit-bindgen-c = { path = 'crates/c', version = '0.37.0' }

crates/c/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ void __wasm_export_{ns}_{snake}_dtor({ns}_{snake}_t* arg) {{
13521352
todo!()
13531353
}
13541354

1355-
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs) {
1355+
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
13561356
_ = (id, name, ty, docs);
13571357
todo!()
13581358
}
@@ -1450,7 +1450,7 @@ impl<'a> wit_bindgen_core::AnonymousTypeGenerator<'a> for InterfaceGenerator<'a>
14501450
todo!("print_anonymous_type for future");
14511451
}
14521452

1453-
fn anonymous_type_stream(&mut self, _id: TypeId, _ty: &Type, _docs: &Docs) {
1453+
fn anonymous_type_stream(&mut self, _id: TypeId, _ty: &Option<Type>, _docs: &Docs) {
14541454
todo!("print_anonymous_type for stream");
14551455
}
14561456

crates/core/src/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,13 @@ def_instruction! {
364364

365365
/// Create an `i32` from a stream.
366366
StreamLower {
367-
payload: &'a Type,
367+
payload: &'a Option<Type>,
368368
ty: TypeId,
369369
} : [1] => [1],
370370

371371
/// Create a stream from an `i32`.
372372
StreamLift {
373-
payload: &'a Type,
373+
payload: &'a Option<Type>,
374374
ty: TypeId,
375375
} : [1] => [1],
376376

crates/core/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub trait InterfaceGenerator<'a> {
155155
fn type_list(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs);
156156
fn type_builtin(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs);
157157
fn type_future(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs);
158-
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs);
158+
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs);
159159
fn type_error_context(&mut self, id: TypeId, name: &str, docs: &Docs);
160160
fn types(&mut self, iface: InterfaceId) {
161161
let iface = &self.resolve().interfaces[iface];
@@ -195,7 +195,7 @@ pub trait AnonymousTypeGenerator<'a> {
195195
fn anonymous_type_result(&mut self, id: TypeId, ty: &Result_, docs: &Docs);
196196
fn anonymous_type_list(&mut self, id: TypeId, ty: &Type, docs: &Docs);
197197
fn anonymous_type_future(&mut self, id: TypeId, ty: &Option<Type>, docs: &Docs);
198-
fn anonymous_type_stream(&mut self, id: TypeId, ty: &Type, docs: &Docs);
198+
fn anonymous_type_stream(&mut self, id: TypeId, ty: &Option<Type>, docs: &Docs);
199199
fn anonymous_type_type(&mut self, id: TypeId, ty: &Type, docs: &Docs);
200200
fn anonymous_type_error_context(&mut self);
201201

crates/csharp/src/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ impl<'a> CoreInterfaceGenerator<'a> for InterfaceGenerator<'a> {
11691169
todo!()
11701170
}
11711171

1172-
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs) {
1172+
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
11731173
_ = (id, name, ty, docs);
11741174
todo!()
11751175
}

crates/go/src/interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl InterfaceGenerator<'_> {
322322
TypeDefKind::Stream(t) => {
323323
let mut src = String::new();
324324
src.push_str("Stream");
325-
src.push_str(&self.ty_name(t));
325+
src.push_str(&self.optional_ty_name(t.as_ref()));
326326
src.push('T');
327327
src
328328
}
@@ -1271,7 +1271,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
12711271
todo!()
12721272
}
12731273

1274-
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs) {
1274+
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
12751275
_ = (id, name, ty, docs);
12761276
todo!()
12771277
}

crates/guest-rust/rt/src/async_support/stream_support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl<T> Stream for StreamReader<T> {
342342
};
343343
Box::pin(async move {
344344
let mut buffer = iter::repeat_with(MaybeUninit::uninit)
345-
.take(ceiling(64 * 1024, mem::size_of::<T>()))
345+
.take(ceiling(64 * 1024, mem::size_of::<T>().max(1)))
346346
.collect::<Vec<_>>();
347347

348348
let result =

crates/markdown/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,16 @@ impl InterfaceGenerator<'_> {
413413
self.push_str("future");
414414
}
415415
},
416-
TypeDefKind::Stream(t) => {
417-
self.push_str("stream<");
418-
self.print_ty(t);
419-
self.push_str(">");
420-
}
416+
TypeDefKind::Stream(t) => match t {
417+
Some(t) => {
418+
self.push_str("stream<");
419+
self.print_ty(t);
420+
self.push_str(">");
421+
}
422+
None => {
423+
self.push_str("stream");
424+
}
425+
},
421426
TypeDefKind::ErrorContext => {
422427
self.push_str("error-context");
423428
}
@@ -661,7 +666,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
661666
todo!()
662667
}
663668

664-
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs) {
669+
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
665670
_ = (id, name, ty, docs);
666671
todo!()
667672
}

crates/moonbit/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
15041504
todo!()
15051505
}
15061506

1507-
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Type, docs: &Docs) {
1507+
fn type_stream(&mut self, id: TypeId, name: &str, ty: &Option<Type>, docs: &Docs) {
15081508
_ = (id, name, ty, docs);
15091509
todo!()
15101510
}

0 commit comments

Comments
 (0)