2929#include " wabt/opcode.h"
3030#include " wabt/type-checker.h"
3131
32- #include " wabt/binary-reader.h" // For TypeMut.
33-
3432namespace wabt {
3533
3634struct ValidateOptions {
@@ -43,7 +41,11 @@ struct ValidateOptions {
4341class SharedValidator {
4442 public:
4543 WABT_DISALLOW_COPY_AND_ASSIGN (SharedValidator);
44+ using TypeEntry = TypeChecker::TypeEntry;
4645 using FuncType = TypeChecker::FuncType;
46+ using StructType = TypeChecker::StructType;
47+ using ArrayType = TypeChecker::ArrayType;
48+ using RecursiveRange = TypeChecker::RecursiveRange;
4749 SharedValidator (Errors*, const ValidateOptions& options);
4850
4951 // TODO: Move into SharedValidator?
@@ -65,14 +67,21 @@ class SharedValidator {
6567
6668 Result EndModule ();
6769
70+ Result OnRecursiveType (Index first_type_index, Index type_count);
6871 Result OnFuncType (const Location&,
6972 Index param_count,
7073 const Type* param_types,
7174 Index result_count,
7275 const Type* result_types,
73- Index type_index);
74- Result OnStructType (const Location&, Index field_count, TypeMut* fields);
75- Result OnArrayType (const Location&, TypeMut field);
76+ Index type_index,
77+ GCTypeExtension* gc_ext);
78+ Result OnStructType (const Location&,
79+ Index field_count,
80+ TypeMut* fields,
81+ GCTypeExtension* gc_ext);
82+ Result OnArrayType (const Location&,
83+ TypeMut field,
84+ GCTypeExtension* gc_ext);
7685
7786 Result OnFunction (const Location&, Var sig_var);
7887 Result OnTable (const Location&, Type elem_type, const Limits&, bool , bool );
@@ -225,20 +234,6 @@ class SharedValidator {
225234 Result OnUnreachable (const Location&);
226235
227236 private:
228- struct StructType {
229- StructType () = default ;
230- StructType (const TypeMutVector& fields) : fields(fields) {}
231-
232- TypeMutVector fields;
233- };
234-
235- struct ArrayType {
236- ArrayType () = default ;
237- ArrayType (TypeMut field) : field(field) {}
238-
239- TypeMut field;
240- };
241-
242237 struct TableType {
243238 TableType () = default ;
244239 TableType (Type element, Limits limits) : element(element), limits(limits) {}
@@ -292,7 +287,11 @@ class SharedValidator {
292287 Type actual,
293288 Type expected,
294289 const char * desc);
295- Result CheckReferenceType (const Location&, Type type, const char * desc);
290+ Result CheckReferenceType (const Location&,
291+ Type type,
292+ Index end_index,
293+ const char * desc);
294+ Result CheckGCTypeExtension (const Location&, GCTypeExtension* gc_ext);
296295 Result CheckLimits (const Location&,
297296 const Limits&,
298297 uint64_t absolute_max,
@@ -337,17 +336,16 @@ class SharedValidator {
337336 void RestoreLocalRefs (Result result);
338337 void IgnoreLocalRefs ();
339338
339+ Index GetEndIndex ();
340+
340341 ValidateOptions options_;
341342 Errors* errors_;
342343 TypeChecker typechecker_; // TODO: Move into SharedValidator.
343344 // Cached for access by OnTypecheckerError.
344345 Location expr_loc_ = Location(kInvalidOffset );
345346 bool in_init_expr_ = false ;
346347
347- Index num_types_ = 0 ;
348- std::map<Index, FuncType> func_types_;
349- std::map<Index, StructType> struct_types_;
350- std::map<Index, ArrayType> array_types_;
348+ TypeChecker::TypeFields type_fields_;
351349
352350 std::vector<FuncType> funcs_; // Includes imported and defined.
353351 std::vector<TableType> tables_; // Includes imported and defined.
@@ -358,6 +356,9 @@ class SharedValidator {
358356 Index starts_ = 0 ;
359357 Index num_imported_globals_ = 0 ;
360358 Index data_segments_ = 0 ;
359+ Index last_rec_type_end_ = 0 ;
360+ // Recursive type checks may enter to infinite loop for invalid values.
361+ Result type_validation_result_ = Result::Ok;
361362
362363 // Includes parameters, since this is only used for validating
363364 // local.{get,set,tee} instructions.
0 commit comments