Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 4ba7f3f

Browse files
authored
Disallow type recursion (#56)
1 parent bdee0c7 commit 4ba7f3f

File tree

3 files changed

+36
-349
lines changed

3 files changed

+36
-349
lines changed

interpreter/valid/valid.ml

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ let check_def_type (c : context) (dt : def_type) at =
125125
| FuncDefType ft -> check_func_type c ft at
126126

127127

128-
let check_type (c : context) (t : type_) =
129-
check_def_type c t.it t.at
130-
131-
132-
133128

134129
(* Stack typing *)
135130

@@ -795,7 +790,11 @@ let check_start (c : context) (start : idx option) =
795790
"start function must not have parameters or results"
796791
) start
797792

798-
let check_import (im : import) (c : context) : context =
793+
let check_type (c : context) (ty : type_) : context =
794+
check_def_type c ty.it ty.at;
795+
{c with types = c.types @ [ty.it]}
796+
797+
let check_import (c : context) (im : import) : context =
799798
let {module_name = _; item_name = _; idesc} = im.it in
800799
match idesc.it with
801800
| FuncImport x ->
@@ -830,31 +829,26 @@ let check_module (m : module_) =
830829
{ types; imports; tables; memories; globals; funcs; start; elems; datas;
831830
exports } = m.it
832831
in
833-
let c0 =
834-
List.fold_right check_import imports
835-
{ empty_context with
836-
refs = Free.module_ ({m.it with funcs = []; start = None} @@ m.at);
837-
types = List.map (fun ty -> ty.it) types;
838-
}
839-
in
840-
let c1 =
841-
{ c0 with
842-
funcs = c0.funcs @ List.map (fun f -> func_type c0 f.it.ftype) funcs;
843-
tables = c0.tables @ List.map (fun tab -> tab.it.ttype) tables;
844-
memories = c0.memories @ List.map (fun mem -> mem.it.mtype) memories;
832+
let c0 = List.fold_left check_type empty_context types in
833+
let c1 = List.fold_left check_import c0 imports in
834+
let c2 =
835+
{ c1 with
836+
funcs = c1.funcs @ List.map (fun f -> func_type c1 f.it.ftype) funcs;
837+
tables = c1.tables @ List.map (fun tab -> tab.it.ttype) tables;
838+
memories = c1.memories @ List.map (fun mem -> mem.it.mtype) memories;
845839
elems = List.map (fun elem -> elem.it.etype) elems;
846840
datas = List.map (fun _data -> ()) datas;
841+
refs = Free.module_ ({m.it with funcs = []; start = None} @@ m.at);
847842
}
848843
in
849844
let c =
850-
{ c1 with globals = c1.globals @ List.map (fun g -> g.it.gtype) globals }
845+
{ c2 with globals = c1.globals @ List.map (fun g -> g.it.gtype) globals }
851846
in
852-
List.iter (check_type c1) types;
853-
List.iter (check_global c1) globals;
854-
List.iter (check_table c1) tables;
855-
List.iter (check_memory c1) memories;
856-
List.iter (check_elem c1) elems;
857-
List.iter (check_data c1) datas;
847+
List.iter (check_global c2) globals;
848+
List.iter (check_table c2) tables;
849+
List.iter (check_memory c2) memories;
850+
List.iter (check_elem c2) elems;
851+
List.iter (check_data c2) datas;
858852
List.iter (check_func c) funcs;
859853
check_start c start;
860854
ignore (List.fold_left (check_export c) NameSet.empty exports);

proposals/function-references/Overview.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ A *reference type* denotes the type of a reference to some data. It may either i
150150
- the opcodes for `funcref` and `externref` continue to exist as shorthands as described above
151151

152152

153+
#### Type Definitions
154+
155+
* Type definitions are validated in sequence and without allowing recursion
156+
- `functype* ok`
157+
- iff `functype* = epsilon`
158+
- or `functype* = functype'* functype''`and `functype'* ok` and `functype'' ok` using only type indices up to `|functype'*|-1`
159+
160+
153161
#### Subtyping
154162

155163
The following rules, now defined in terms of heap types, replace and extend the rules for [basic reference types](https://github.com/WebAssembly/reference-types/proposals/reference-types/Overview.md#subtyping).

0 commit comments

Comments
 (0)