@@ -1655,7 +1655,6 @@ def lift_async_value(ReadableHandleT, WritableHandleT, cx, i, t):
1655
1655
cx.inst.waitables.remove(i)
1656
1656
case WritableHandleT():
1657
1657
trap_if(h.paired)
1658
- assert (not h.copying_buffer)
1659
1658
h.paired = True
1660
1659
if contains_borrow(t):
1661
1660
h.borrow_scope = cx.borrow_scope
@@ -3118,14 +3117,14 @@ async def async_copy(HandleT, BufferT, t, opts, event_code, task, i, ptr, n):
3118
3117
h = task.inst.waitables.get(i)
3119
3118
trap_if(not isinstance (h, HandleT))
3120
3119
trap_if(h.t != t)
3121
- trap_if(not h.paired)
3122
3120
trap_if(h.copying_buffer)
3123
3121
cx = LiftLowerContext(opts, task.inst, h.borrow_scope)
3124
3122
buffer = BufferT(cx, t, ptr, n)
3125
3123
if h.stream.closed():
3126
3124
flat_results = [pack_async_copy_result(task, buffer, h)]
3127
3125
else :
3128
3126
if opts.sync:
3127
+ trap_if(not h.paired)
3129
3128
await task.call_sync(h.copy, buffer)
3130
3129
flat_results = [pack_async_copy_result(task, buffer, h)]
3131
3130
else :
@@ -3147,12 +3146,11 @@ async def async_copy(HandleT, BufferT, t, opts, event_code, task, i, ptr, n):
3147
3146
flat_results = [pack_async_copy_result(task, buffer, h)]
3148
3147
return flat_results
3149
3148
```
3150
- The trap if ` not h.paired ` prevents ` write ` s on the writable end of streams or
3151
- futures that have not yet been lifted. The ` copying_buffer ` field serves as a
3152
- boolean indication of whether an async ` read ` or ` write ` is already in
3153
- progress, preventing multiple overlapping calls to ` read ` or ` write ` . (This
3154
- restriction could be relaxed [ in the future] ( Async.md#TODO ) to allow greater
3155
- pipeline parallelism.)
3149
+ The ` trap_if(h.copying_buffer) ` trap prevents multiple overlapping calls to
3150
+ ` read ` or ` write ` . (This restriction could be relaxed [ in the
3151
+ future] ( Async.md#TODO ) to allow greater pipeline parallelism.) The
3152
+ ` trap_if(not h.paired) ` in the synchronous case prevents what would otherwise
3153
+ be a deadlock, performing a blocking write when there is no reader.
3156
3154
3157
3155
One subtle corner case handled by this code that is worth pointing out is that,
3158
3156
between calling ` h.copy() ` and ` h.copy() ` returning, wasm guest code can call
0 commit comments