Skip to content

Commit

Permalink
[table64] Fix validation rules for table.fill/copy/size/grow (#54)
Browse files Browse the repository at this point in the history
Also, add more tests.
  • Loading branch information
sbc100 authored May 2, 2024
1 parent dc4d236 commit 5cc08ad
Show file tree
Hide file tree
Showing 10 changed files with 949 additions and 134 deletions.
2 changes: 2 additions & 0 deletions interpreter/syntax/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ let string_of_value_types = function
| [t] -> string_of_value_type t
| ts -> "[" ^ String.concat " " (List.map string_of_value_type ts) ^ "]"

let string_of_index_type t =
string_of_value_type (value_type_of_index_type t)

let string_of_limits to_string {min; max} =
to_string min ^
Expand Down
25 changes: 14 additions & 11 deletions interpreter/valid/valid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -326,32 +326,35 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : op_type
[value_type_of_index_type it; RefType t] --> []

| TableSize x ->
let _tt = table c x in
[] --> [NumType I32Type]
let TableType (_lim, it, _t) = table c x in
[] --> [value_type_of_index_type it]

| TableGrow x ->
let TableType (_lim, _it, t) = table c x in
[RefType t; NumType I32Type] --> [NumType I32Type]
let TableType (_lim, it, t) = table c x in
[RefType t; value_type_of_index_type it] --> [value_type_of_index_type it]

| TableFill x ->
let TableType (_lim, _it, t) = table c x in
[NumType I32Type; RefType t; NumType I32Type] --> []
let TableType (_lim, it, t) = table c x in
[value_type_of_index_type it; RefType t; value_type_of_index_type it] --> []

| TableCopy (x, y) ->
let TableType (_lim1, _it, t1) = table c x in
let TableType (_lim2, _it, t2) = table c y in
let TableType (_lim1, it1, t1) = table c x in
let TableType (_lim2, it2, t2) = table c y in
require (t1 = t2) x.at
("type mismatch: source element type " ^ string_of_ref_type t1 ^
" does not match destination element type " ^ string_of_ref_type t2);
[NumType I32Type; NumType I32Type; NumType I32Type] --> []
require (it1 = it2) x.at
("type mismatch: source index type " ^ string_of_index_type it1 ^
" does not match destination index type " ^ string_of_index_type it2);
[value_type_of_index_type it1; value_type_of_index_type it1; value_type_of_index_type it1] --> []

| TableInit (x, y) ->
let TableType (_lim1, _it, t1) = table c x in
let TableType (_lim, it, t1) = table c x in
let t2 = elem c y in
require (t1 = t2) x.at
("type mismatch: element segment's type " ^ string_of_ref_type t1 ^
" does not match table's element type " ^ string_of_ref_type t2);
[NumType I32Type; NumType I32Type; NumType I32Type] --> []
[value_type_of_index_type it; NumType I32Type; NumType I32Type] --> []

| ElemDrop x ->
ignore (elem c x);
Expand Down
Loading

0 comments on commit 5cc08ad

Please sign in to comment.