Skip to content

Commit 95f36d2

Browse files
authored
update future.{write,read} ABIs (#2222)
* update `future.{write,read}` ABIs This implements WebAssembly/component-model#524 insofar as it affects validation, componentization, etc. - `future.write` now accepts its payload value as up to 4 flat parameters before spilling to linear memory. - `future.read` takes no payload pointer when it has no payload type - `{stream,future}.close-{readable,writable}` have been renamed to `{stream,future}.drop-{readable,writable}` Signed-off-by: Joel Dice <[email protected]> * address CI issues Signed-off-by: Joel Dice <[email protected]> * address review feedback Signed-off-by: Joel Dice <[email protected]> * add WAST tests for various `future.{write,read}` payload sizes Signed-off-by: Joel Dice <[email protected]> * revert lint allow Signed-off-by: Joel Dice <[email protected]> * add test output Signed-off-by: Joel Dice <[email protected]> --------- Signed-off-by: Joel Dice <[email protected]>
1 parent 83d6c69 commit 95f36d2

File tree

38 files changed

+702
-444
lines changed

38 files changed

+702
-444
lines changed

crates/wasm-encoder/src/component/builder.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,15 @@ impl ComponentBuilder {
481481
inc(&mut self.core_funcs)
482482
}
483483

484-
/// Declares a new `stream.close-readable` intrinsic.
485-
pub fn stream_close_readable(&mut self, ty: u32) -> u32 {
486-
self.canonical_functions().stream_close_readable(ty);
484+
/// Declares a new `stream.drop-readable` intrinsic.
485+
pub fn stream_drop_readable(&mut self, ty: u32) -> u32 {
486+
self.canonical_functions().stream_drop_readable(ty);
487487
inc(&mut self.core_funcs)
488488
}
489489

490-
/// Declares a new `stream.close-writable` intrinsic.
491-
pub fn stream_close_writable(&mut self, ty: u32) -> u32 {
492-
self.canonical_functions().stream_close_writable(ty);
490+
/// Declares a new `stream.drop-writable` intrinsic.
491+
pub fn stream_drop_writable(&mut self, ty: u32) -> u32 {
492+
self.canonical_functions().stream_drop_writable(ty);
493493
inc(&mut self.core_funcs)
494494
}
495495

@@ -531,15 +531,15 @@ impl ComponentBuilder {
531531
inc(&mut self.core_funcs)
532532
}
533533

534-
/// Declares a new `future.close-readable` intrinsic.
535-
pub fn future_close_readable(&mut self, ty: u32) -> u32 {
536-
self.canonical_functions().future_close_readable(ty);
534+
/// Declares a new `future.drop-readable` intrinsic.
535+
pub fn future_drop_readable(&mut self, ty: u32) -> u32 {
536+
self.canonical_functions().future_drop_readable(ty);
537537
inc(&mut self.core_funcs)
538538
}
539539

540-
/// Declares a new `future.close-writable` intrinsic.
541-
pub fn future_close_writable(&mut self, ty: u32) -> u32 {
542-
self.canonical_functions().future_close_writable(ty);
540+
/// Declares a new `future.drop-writable` intrinsic.
541+
pub fn future_drop_writable(&mut self, ty: u32) -> u32 {
542+
self.canonical_functions().future_drop_writable(ty);
543543
inc(&mut self.core_funcs)
544544
}
545545

crates/wasm-encoder/src/component/canonicals.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,18 @@ impl CanonicalFunctionSection {
327327
self
328328
}
329329

330-
/// Defines a function to close the readable end of a `stream` of the
330+
/// Defines a function to drop the readable end of a `stream` of the
331331
/// specified type.
332-
pub fn stream_close_readable(&mut self, ty: u32) -> &mut Self {
332+
pub fn stream_drop_readable(&mut self, ty: u32) -> &mut Self {
333333
self.bytes.push(0x13);
334334
ty.encode(&mut self.bytes);
335335
self.num_added += 1;
336336
self
337337
}
338338

339-
/// Defines a function to close the writable end of a `stream` of the
339+
/// Defines a function to drop the writable end of a `stream` of the
340340
/// specified type.
341-
pub fn stream_close_writable(&mut self, ty: u32) -> &mut Self {
341+
pub fn stream_drop_writable(&mut self, ty: u32) -> &mut Self {
342342
self.bytes.push(0x14);
343343
ty.encode(&mut self.bytes);
344344
self.num_added += 1;
@@ -400,18 +400,18 @@ impl CanonicalFunctionSection {
400400
self
401401
}
402402

403-
/// Defines a function to close the readable end of a `future` of the
403+
/// Defines a function to drop the readable end of a `future` of the
404404
/// specified type.
405-
pub fn future_close_readable(&mut self, ty: u32) -> &mut Self {
405+
pub fn future_drop_readable(&mut self, ty: u32) -> &mut Self {
406406
self.bytes.push(0x1a);
407407
ty.encode(&mut self.bytes);
408408
self.num_added += 1;
409409
self
410410
}
411411

412-
/// Defines a function to close the writable end of a `future` of the
412+
/// Defines a function to drop the writable end of a `future` of the
413413
/// specified type.
414-
pub fn future_close_writable(&mut self, ty: u32) -> &mut Self {
414+
pub fn future_drop_writable(&mut self, ty: u32) -> &mut Self {
415415
self.bytes.push(0x1b);
416416
ty.encode(&mut self.bytes);
417417
self.num_added += 1;

crates/wasm-encoder/src/reencode/component.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ pub mod component_utils {
436436
..
437437
} => (),
438438
wasmparser::Payload::Version { .. } => {
439-
return Err(Error::UnexpectedNonComponentSection)
439+
return Err(Error::UnexpectedNonComponentSection);
440440
}
441441
wasmparser::Payload::TypeSection(_)
442442
| wasmparser::Payload::ImportSection(_)
@@ -452,7 +452,7 @@ pub mod component_utils {
452452
| wasmparser::Payload::DataSection(_)
453453
| wasmparser::Payload::CodeSectionStart { .. }
454454
| wasmparser::Payload::CodeSectionEntry(_) => {
455-
return Err(Error::UnexpectedNonComponentSection)
455+
return Err(Error::UnexpectedNonComponentSection);
456456
}
457457
wasmparser::Payload::ComponentTypeSection(section) => {
458458
let mut types = crate::ComponentTypeSection::new();
@@ -1027,11 +1027,11 @@ pub mod component_utils {
10271027
wasmparser::CanonicalFunction::StreamCancelWrite { ty, async_ } => {
10281028
section.stream_cancel_write(ty, async_);
10291029
}
1030-
wasmparser::CanonicalFunction::StreamCloseReadable { ty } => {
1031-
section.stream_close_readable(reencoder.component_type_index(ty));
1030+
wasmparser::CanonicalFunction::StreamDropReadable { ty } => {
1031+
section.stream_drop_readable(reencoder.component_type_index(ty));
10321032
}
1033-
wasmparser::CanonicalFunction::StreamCloseWritable { ty } => {
1034-
section.stream_close_writable(reencoder.component_type_index(ty));
1033+
wasmparser::CanonicalFunction::StreamDropWritable { ty } => {
1034+
section.stream_drop_writable(reencoder.component_type_index(ty));
10351035
}
10361036
wasmparser::CanonicalFunction::FutureNew { ty } => {
10371037
section.future_new(reencoder.component_type_index(ty));
@@ -1056,11 +1056,11 @@ pub mod component_utils {
10561056
wasmparser::CanonicalFunction::FutureCancelWrite { ty, async_ } => {
10571057
section.future_cancel_write(ty, async_);
10581058
}
1059-
wasmparser::CanonicalFunction::FutureCloseReadable { ty } => {
1060-
section.future_close_readable(reencoder.component_type_index(ty));
1059+
wasmparser::CanonicalFunction::FutureDropReadable { ty } => {
1060+
section.future_drop_readable(reencoder.component_type_index(ty));
10611061
}
1062-
wasmparser::CanonicalFunction::FutureCloseWritable { ty } => {
1063-
section.future_close_writable(reencoder.component_type_index(ty));
1062+
wasmparser::CanonicalFunction::FutureDropWritable { ty } => {
1063+
section.future_drop_writable(reencoder.component_type_index(ty));
10641064
}
10651065
wasmparser::CanonicalFunction::ErrorContextNew { options } => {
10661066
let options = options

crates/wasm-wave/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ categories = ["wasm", "encoding", "parser-implementations"]
1111
repository = "https://github.com/bytecodealliance/wasm-tools/tree/main/crates/wasm-wave"
1212
readme = "README.md"
1313

14+
[lints]
15+
workspace = true
16+
1417
[features]
1518
default = ["wit"]
1619
wit = ["dep:wit-parser"]

crates/wasmparser/src/readers/component/canonicals.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ pub enum CanonicalFunction {
161161
/// `BLOCKED`.
162162
async_: bool,
163163
},
164-
/// A function to close the readable end of a `stream` of the specified
164+
/// A function to drop the readable end of a `stream` of the specified
165165
/// type.
166-
StreamCloseReadable {
166+
StreamDropReadable {
167167
/// The `stream` type to expect.
168168
ty: u32,
169169
},
170-
/// A function to close the writable end of a `stream` of the specified
170+
/// A function to drop the writable end of a `stream` of the specified
171171
/// type.
172-
StreamCloseWritable {
172+
StreamDropWritable {
173173
/// The `stream` type to expect.
174174
ty: u32,
175175
},
@@ -212,15 +212,15 @@ pub enum CanonicalFunction {
212212
/// `BLOCKED`.
213213
async_: bool,
214214
},
215-
/// A function to close the readable end of a `future` of the specified
215+
/// A function to drop the readable end of a `future` of the specified
216216
/// type.
217-
FutureCloseReadable {
217+
FutureDropReadable {
218218
/// The `future` type to expect.
219219
ty: u32,
220220
},
221-
/// A function to close the writable end of a `future` of the specified
221+
/// A function to drop the writable end of a `future` of the specified
222222
/// type.
223-
FutureCloseWritable {
223+
FutureDropWritable {
224224
/// The `future` type to expect.
225225
ty: u32,
226226
},
@@ -331,8 +331,8 @@ impl<'a> FromReader<'a> for CanonicalFunction {
331331
ty: reader.read()?,
332332
async_: reader.read()?,
333333
},
334-
0x13 => CanonicalFunction::StreamCloseReadable { ty: reader.read()? },
335-
0x14 => CanonicalFunction::StreamCloseWritable { ty: reader.read()? },
334+
0x13 => CanonicalFunction::StreamDropReadable { ty: reader.read()? },
335+
0x14 => CanonicalFunction::StreamDropWritable { ty: reader.read()? },
336336
0x15 => CanonicalFunction::FutureNew { ty: reader.read()? },
337337
0x16 => CanonicalFunction::FutureRead {
338338
ty: reader.read()?,
@@ -350,8 +350,8 @@ impl<'a> FromReader<'a> for CanonicalFunction {
350350
ty: reader.read()?,
351351
async_: reader.read()?,
352352
},
353-
0x1a => CanonicalFunction::FutureCloseReadable { ty: reader.read()? },
354-
0x1b => CanonicalFunction::FutureCloseWritable { ty: reader.read()? },
353+
0x1a => CanonicalFunction::FutureDropReadable { ty: reader.read()? },
354+
0x1b => CanonicalFunction::FutureDropWritable { ty: reader.read()? },
355355
0x1c => CanonicalFunction::ErrorContextNew {
356356
options: read_opts(reader)?,
357357
},

0 commit comments

Comments
 (0)