Skip to content

Commit b99ab2d

Browse files
authored
Allow table.copy between tables with different index types (#58)
See #7, #6
1 parent 26816ef commit b99ab2d

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

interpreter/syntax/types.ml

-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ let match_extern_type et1 et2 =
106106
| ExternGlobalType gt1, ExternGlobalType gt2 -> match_global_type gt1 gt2
107107
| _, _ -> false
108108

109-
110109
(* String conversion *)
111110

112111
let string_of_num_type = function

interpreter/valid/valid.ml

+2-4
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,11 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : op_type
340340
| TableCopy (x, y) ->
341341
let TableType (_lim1, it1, t1) = table c x in
342342
let TableType (_lim2, it2, t2) = table c y in
343+
let it3 = min it1 it2 in
343344
require (t1 = t2) x.at
344345
("type mismatch: source element type " ^ string_of_ref_type t1 ^
345346
" does not match destination element type " ^ string_of_ref_type t2);
346-
require (it1 = it2) x.at
347-
("type mismatch: source index type " ^ string_of_index_type it1 ^
348-
" does not match destination index type " ^ string_of_index_type it2);
349-
[value_type_of_index_type it1; value_type_of_index_type it1; value_type_of_index_type it1] --> []
347+
[value_type_of_index_type it1; value_type_of_index_type it2; value_type_of_index_type it3] --> []
350348

351349
| TableInit (x, y) ->
352350
let TableType (_lim, it, t1) = table c x in

proposals/memory64/Overview.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ have to support 32-bit memory addresses in their ABI.
203203
```
204204
- table.copy x y
205205
- ```
206-
C.tables[x] = it limits t
207-
----------------------------------
208-
C ⊦ table.copy x : [it it it] → []
206+
C.tables[d] = iN limits t C.tables[s] = iM limits t K = min {N, M}
207+
-----------------------------------------------------------------------------
208+
C ⊦ table.copy d s : [iN iM iK] → []
209209
```
210210
- table.init x y
211211
- ```

test/core/table_copy_mixed.wast

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
;; Valid cases
2+
(module
3+
(table $t32 30 30 funcref)
4+
(table $t64 i64 30 30 funcref)
5+
6+
(func (export "test32")
7+
(table.copy $t32 $t32 (i32.const 13) (i32.const 2) (i32.const 3)))
8+
9+
(func (export "test64")
10+
(table.copy $t64 $t64 (i64.const 13) (i64.const 2) (i64.const 3)))
11+
12+
(func (export "test_64to32")
13+
(table.copy $t32 $t64 (i32.const 13) (i64.const 2) (i32.const 3)))
14+
15+
(func (export "test_32to64")
16+
(table.copy $t64 $t32 (i64.const 13) (i32.const 2) (i32.const 3)))
17+
)
18+
19+
;; Invalid cases
20+
(assert_invalid (module
21+
(table $t32 30 30 funcref)
22+
(table $t64 i64 30 30 funcref)
23+
24+
(func (export "bad_size_arg")
25+
(table.copy $t32 $t64 (i32.const 13) (i64.const 2) (i64.const 3)))
26+
)
27+
"type mismatch"
28+
)
29+
30+
(assert_invalid (module
31+
(table $t32 30 30 funcref)
32+
(table $t64 i64 30 30 funcref)
33+
34+
(func (export "bad_src_idx")
35+
(table.copy $t32 $t64 (i32.const 13) (i32.const 2) (i32.const 3)))
36+
)
37+
"type mismatch"
38+
)
39+
40+
(assert_invalid (module
41+
(table $t32 30 30 funcref)
42+
(table $t64 i64 30 30 funcref)
43+
44+
(func (export "bad_dst_idx")
45+
(table.copy $t32 $t64 (i64.const 13) (i64.const 2) (i32.const 3)))
46+
)
47+
"type mismatch"
48+
)

0 commit comments

Comments
 (0)