Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

tweak CM async trap messages to match spec tests (#14367)

Joel Dice423da9bcb681
diff --git a/crates/environ/src/trap_encoding.rs b/crates/environ/src/trap_encoding.rs
index c3573938e8..feae63c0f8 100644
--- a/crates/environ/src/trap_encoding.rs
+++ b/crates/environ/src/trap_encoding.rs
@@ -289,7 +289,7 @@ generate_trap_type! {
/// Guest attempted to write to a future after being notified that the
/// readable end was dropped.
- WriteToDroppedFuture = "cannot write to stream after previous write succeded or readable end dropped",
+ WriteToDroppedFuture = "cannot write to future after previous write succeeded or readable end dropped",
/// Guest attempted to lift a stream after being notified that the
/// writable end was dropped.
diff --git a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs
index 74d278652d..0ada3a391a 100644
--- a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs
+++ b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs
@@ -3509,10 +3509,6 @@ impl Instance {
bail!(Trap::ConcurrentFutureStreamOp);
};
- if done {
- bail!("cannot write after being notified that the readable end dropped");
- }
-
*state = TransmitLocalState::Busy;
let transmit_handle = TableId::<TransmitHandle>::new(rep);
let concurrent_state = store.0.concurrent_state_mut()?;
@@ -3523,8 +3519,11 @@ impl Instance {
transmit.read
);
- if transmit.done {
- bail!("cannot write to future after previous write succeeded or readable end dropped");
+ if done || transmit.done {
+ bail!(match ty {
+ TransmitIndex::Future(_) => Trap::WriteToDroppedFuture,
+ TransmitIndex::Stream(_) => Trap::WriteToDroppedStream,
+ });
}
let new_state = if let ReadState::Dropped = &transmit.read {
@@ -3723,10 +3722,6 @@ impl Instance {
..
},
) => {}
- None => bail!(match ty {
- TransmitIndex::Future(_) => Trap::WriteToDroppedFuture,
- TransmitIndex::Stream(_) => Trap::WriteToDroppedStream,
- }),
event => bail_bug!("expected pending dropped event for writer; got {event:?}"),
}
@@ -3773,10 +3768,6 @@ impl Instance {
bail!(Trap::ConcurrentFutureStreamOp);
};
- if done {
- bail!("cannot read after being notified that the writable end dropped");
- }
-
*state = TransmitLocalState::Busy;
let transmit_handle = TableId::<TransmitHandle>::new(rep);
let caller_thread = store.0.current_guest_thread()?;
@@ -3788,8 +3779,13 @@ impl Instance {
transmit.write
);
- if transmit.done {
- bail!("cannot read from future after previous read succeeded");
+ if done || transmit.done {
+ match ty {
+ TransmitIndex::Future(_) => {
+ bail!("cannot read from future after previous read succeeded")
+ }
+ TransmitIndex::Stream(_) => bail!(Trap::ReadFromDroppedStream),
+ }
}
let new_state = if let WriteState::Dropped = &transmit.write {
@@ -3968,7 +3964,6 @@ impl Instance {
code: ReturnCode::Dropped(ItemCount::ZERO),
..
}) => {}
- None => bail!(Trap::ReadFromDroppedStream),
event => bail_bug!("expected pending dropped event for reader; got {event:?}"),
}
diff --git a/crates/wast/src/wast.rs b/crates/wast/src/wast.rs
index 5e5fdeafc8..7462a36cc5 100644
--- a/crates/wast/src/wast.rs
+++ b/crates/wast/src/wast.rs
@@ -548,10 +548,6 @@ impl WastContext {
|| (expected.contains("null function") && (actual.contains("uninitialized element") || actual.contains("null reference")))
// GC tests say "null $kind reference" but we just say "null reference".
|| (expected.contains("null") && expected.contains("reference") && actual.contains("null reference"))
- // upstream component model tests expect slightly different error
- // messages than we generate.
- || (expected.contains("cannot write") && actual.contains("cannot write"))
- || (expected.contains("cannot read") && actual.contains("cannot read"))
{
return Ok(());
}
diff --git a/tests/misc_testsuite/component-model/async/stream-cancel-finished-op.wast b/tests/misc_testsuite/component-model/async/stream-cancel-finished-op.wast
index 5c2dbe4097..3b05e3b328 100644
--- a/tests/misc_testsuite/component-model/async/stream-cancel-finished-op.wast
+++ b/tests/misc_testsuite/component-model/async/stream-cancel-finished-op.wast
@@ -229,23 +229,23 @@
)
(component instance $A $A)
-(assert_trap (invoke "test-cancel-read" (u32.const 0)) "cannot read after being notified that the writable end dropped")
+(assert_trap (invoke "test-cancel-read" (u32.const 0)) "cannot read from stream after being notified that the writable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-read" (u32.const 2)) "cannot read after being notified that the writable end dropped")
+(assert_trap (invoke "test-cancel-read" (u32.const 2)) "cannot read from stream after being notified that the writable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-read" (u32.const 3)) "cannot read after being notified that the writable end dropped")
+(assert_trap (invoke "test-cancel-read" (u32.const 3)) "cannot read from stream after being notified that the writable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-write" (u32.const 1)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "test-cancel-write" (u32.const 1)) "cannot write to stream after being notified that the readable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-write" (u32.const 2)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "test-cancel-write" (u32.const 2)) "cannot write to stream after being notified that the readable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-write" (u32.const 3)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "test-cancel-write" (u32.const 3)) "cannot write to stream after being notified that the readable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-future-write" (u32.const 2)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "test-cancel-future-write" (u32.const 2)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-future-write" (u32.const 3)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "test-cancel-future-write" (u32.const 3)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $A $A)
-(assert_trap (invoke "test-cancel-future-write" (u32.const 4)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "test-cancel-future-write" (u32.const 4)) "cannot write to future after previous write succeeded or readable end dropped")
diff --git a/tests/misc_testsuite/component-model/async/trap-if-done.wast b/tests/misc_testsuite/component-model/async/trap-if-done.wast
index d9812e14f2..0da1562c56 100644
--- a/tests/misc_testsuite/component-model/async/trap-if-done.wast
+++ b/tests/misc_testsuite/component-model/async/trap-if-done.wast
@@ -596,22 +596,22 @@
(assert_trap (invoke "trap-after-future-async-write" (u8.const 3)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i3.0 $Tester)
-(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 0)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 0)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i3.1 $Tester)
-(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 1)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 1)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i3.2 $Tester)
-(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 2)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 2)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i3.3 $Tester)
-(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 3)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-dropped" (u8.const 3)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i $Tester)
-(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 0)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 0)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i $Tester)
-(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 1)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 1)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i $Tester)
-(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 2)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 2)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i $Tester)
-(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 3)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-future-reader-async-dropped" (u8.const 3)) "cannot write to future after previous write succeeded or readable end dropped")
(component instance $i4.0 $Tester)
(assert_trap (invoke "trap-after-future-eager-read" (u8.const 0x00)) "cannot read from future after previous read succeeded")
@@ -640,24 +640,24 @@
(assert_trap (invoke "trap-after-future-async-read" (u8.const 0x12)) "cannot lift future after previous read succeeded")
(component instance $i6.0 $Tester)
-(assert_trap (invoke "trap-after-stream-reader-eager-dropped" (u8.const 0)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-stream-reader-eager-dropped" (u8.const 0)) "cannot write to stream after being notified that the readable end dropped")
(component instance $i6.1 $Tester)
-(assert_trap (invoke "trap-after-stream-reader-eager-dropped" (u8.const 1)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-stream-reader-eager-dropped" (u8.const 1)) "cannot write to stream after being notified that the readable end dropped")
(component instance $i7.0 $Tester)
-(assert_trap (invoke "trap-after-stream-reader-async-dropped" (u8.const 0)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-stream-reader-async-dropped" (u8.const 0)) "cannot write to stream after being notified that the readable end dropped")
(component instance $i7.1 $Tester)
-(assert_trap (invoke "trap-after-stream-reader-async-dropped" (u8.const 1)) "cannot write after being notified that the readable end dropped")
+(assert_trap (invoke "trap-after-stream-reader-async-dropped" (u8.const 1)) "cannot write to stream after being notified that the readable end dropped")
(component instance $i8.0 $Tester)
-(assert_trap (invoke "trap-after-stream-writer-eager-dropped" (u8.const 0)) "cannot read after being notified that the writable end dropped")
+(assert_trap (invoke "trap-after-stream-writer-eager-dropped" (u8.const 0)) "cannot read from stream after being notified that the writable end dropped")
(component instance $i8.1 $Tester)
-(assert_trap (invoke "trap-after-stream-writer-eager-dropped" (u8.const 1)) "cannot read after being notified that the writable end dropped")
+(assert_trap (invoke "trap-after-stream-writer-eager-dropped" (u8.const 1)) "cannot read from stream after being notified that the writable end dropped")
(component instance $i8.2 $Tester)
(assert_trap (invoke "trap-after-stream-writer-eager-dropped" (u8.const 2)) "cannot lift stream after being notified that the writable end dropped")
(component instance $i9.0 $Tester)
-(assert_trap (invoke "trap-after-stream-writer-async-dropped" (u8.const 0)) "cannot read after being notified that the writable end dropped")
+(assert_trap (invoke "trap-after-stream-writer-async-dropped" (u8.const 0)) "cannot read from stream after being notified that the writable end dropped")
(component instance $i9.1 $Tester)
-(assert_trap (invoke "trap-after-stream-writer-async-dropped" (u8.const 1)) "cannot read after being notified that the writable end dropped")
+(assert_trap (invoke "trap-after-stream-writer-async-dropped" (u8.const 1)) "cannot read from stream after being notified that the writable end dropped")
(component instance $i9.2 $Tester)
(assert_trap (invoke "trap-after-stream-writer-async-dropped" (u8.const 2)) "cannot lift stream after being notified that the writable end dropped")