Skip to content

Commit 41e4831

Browse files
committed
Add 'bool' and 'char' to the allow-list of same-instance future/stream copies
1 parent 7479890 commit 41e4831

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

design/mvp/CanonicalABI.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ remains blocked:
14481448
self.set_pending(inst, dst_buffer, on_copy, on_copy_done)
14491449
else:
14501450
assert(self.t == dst_buffer.t == self.pending_buffer.t)
1451-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
1451+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
14521452
if self.pending_buffer.remain() > 0:
14531453
if dst_buffer.remain() > 0:
14541454
n = min(dst_buffer.remain(), self.pending_buffer.remain())
@@ -1460,7 +1460,7 @@ remains blocked:
14601460
self.set_pending(inst, dst_buffer, on_copy, on_copy_done)
14611461
```
14621462
Currently, there is a trap when both the `read` and `write` come from the same
1463-
component instance and there is a non-empty, non-number element type. This trap
1463+
component instance and there is a non-empty, non-primitive element type. This trap
14641464
will be removed in a subsequent release; the reason for the trap is that when
14651465
lifting and lowering can alias the same memory, interleavings can be complex
14661466
and must be handled carefully. Future improvements to the Canonical ABI ([lazy
@@ -1482,7 +1482,7 @@ pending:
14821482
self.set_pending(inst, src_buffer, on_copy, on_copy_done)
14831483
else:
14841484
assert(self.t == src_buffer.t == self.pending_buffer.t)
1485-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
1485+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
14861486
if self.pending_buffer.remain() > 0:
14871487
if src_buffer.remain() > 0:
14881488
n = min(src_buffer.remain(), self.pending_buffer.remain())
@@ -1505,13 +1505,14 @@ notifying the reader end and allowing it to rendezvous with a non-zero-length
15051505
`read` and make progress. See the [stream readiness] section in the async
15061506
explainer for more background on purpose of zero-length reads and writes.
15071507

1508-
The `none_or_number_type` predicate used above includes both the integer and
1508+
The `none_or_primitive_type` predicate used above includes both the integer and
15091509
floating point number types:
15101510
```python
1511-
def none_or_number_type(t):
1511+
def none_or_primitive_type(t):
15121512
return t is None or isinstance(t, U8Type | U16Type | U32Type | U64Type |
15131513
S8Type | S16Type | S32Type | S64Type |
1514-
F32Type | F64Type)
1514+
F32Type | F64Type |
1515+
BoolType | CharType)
15151516
```
15161517

15171518
The two ends of a stream are stored as separate elements in the component
@@ -1657,7 +1658,7 @@ end was dropped before receiving a value.
16571658
if not self.pending_buffer:
16581659
self.set_pending(inst, dst_buffer, on_copy_done)
16591660
else:
1660-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
1661+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
16611662
dst_buffer.write(self.pending_buffer.read(1))
16621663
self.reset_and_notify_pending(CopyResult.COMPLETED)
16631664
on_copy_done(CopyResult.COMPLETED)
@@ -1669,7 +1670,7 @@ end was dropped before receiving a value.
16691670
elif not self.pending_buffer:
16701671
self.set_pending(inst, src_buffer, on_copy_done)
16711672
else:
1672-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
1673+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
16731674
self.pending_buffer.write(src_buffer.read(1))
16741675
self.reset_and_notify_pending(CopyResult.COMPLETED)
16751676
on_copy_done(CopyResult.COMPLETED)

design/mvp/canonical-abi/definitions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def read(self, inst, dst_buffer, on_copy, on_copy_done):
847847
self.set_pending(inst, dst_buffer, on_copy, on_copy_done)
848848
else:
849849
assert(self.t == dst_buffer.t == self.pending_buffer.t)
850-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
850+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
851851
if self.pending_buffer.remain() > 0:
852852
if dst_buffer.remain() > 0:
853853
n = min(dst_buffer.remain(), self.pending_buffer.remain())
@@ -865,7 +865,7 @@ def write(self, inst, src_buffer, on_copy, on_copy_done):
865865
self.set_pending(inst, src_buffer, on_copy, on_copy_done)
866866
else:
867867
assert(self.t == src_buffer.t == self.pending_buffer.t)
868-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
868+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
869869
if self.pending_buffer.remain() > 0:
870870
if src_buffer.remain() > 0:
871871
n = min(src_buffer.remain(), self.pending_buffer.remain())
@@ -878,10 +878,11 @@ def write(self, inst, src_buffer, on_copy, on_copy_done):
878878
self.reset_and_notify_pending(CopyResult.COMPLETED)
879879
self.set_pending(inst, src_buffer, on_copy, on_copy_done)
880880

881-
def none_or_number_type(t):
881+
def none_or_primitive_type(t):
882882
return t is None or isinstance(t, U8Type | U16Type | U32Type | U64Type |
883883
S8Type | S16Type | S32Type | S64Type |
884-
F32Type | F64Type)
884+
F32Type | F64Type |
885+
BoolType | CharType)
885886

886887
class CopyState(Enum):
887888
IDLE = 1
@@ -984,7 +985,7 @@ def read(self, inst, dst_buffer, on_copy_done):
984985
if not self.pending_buffer:
985986
self.set_pending(inst, dst_buffer, on_copy_done)
986987
else:
987-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
988+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
988989
dst_buffer.write(self.pending_buffer.read(1))
989990
self.reset_and_notify_pending(CopyResult.COMPLETED)
990991
on_copy_done(CopyResult.COMPLETED)
@@ -996,7 +997,7 @@ def write(self, inst, src_buffer, on_copy_done):
996997
elif not self.pending_buffer:
997998
self.set_pending(inst, src_buffer, on_copy_done)
998999
else:
999-
trap_if(inst is self.pending_inst and not none_or_number_type(self.t)) # temporary
1000+
trap_if(inst is self.pending_inst and not none_or_primitive_type(self.t)) # temporary
10001001
self.pending_buffer.write(src_buffer.read(1))
10011002
self.reset_and_notify_pending(CopyResult.COMPLETED)
10021003
on_copy_done(CopyResult.COMPLETED)

design/mvp/canonical-abi/run_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,8 @@ def core_consumer(thread, args):
27792779
test_self_copy(None)
27802780
test_self_copy(U8Type())
27812781
test_self_copy(F64Type())
2782+
test_self_copy(BoolType())
2783+
test_self_copy(CharType())
27822784
test_async_flat_params()
27832785
test_threads()
27842786
test_thread_cancel_callback()

0 commit comments

Comments
 (0)