Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ struct TypeBuilder {
InvalidFuncType,
// A shared type with shared-everything disabled.
InvalidSharedType,
// A string type with strings disabled.
InvalidStringType,
// A non-shared field of a shared heap type.
InvalidUnsharedField,
// A describes clause on a non-struct type.
Expand Down
5 changes: 5 additions & 0 deletions src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,8 @@ std::ostream& operator<<(std::ostream& os, TypeBuilder::ErrorReason reason) {
return os << "Continuation has invalid function type";
case TypeBuilder::ErrorReason::InvalidSharedType:
return os << "Shared types require shared-everything";
case TypeBuilder::ErrorReason::InvalidStringType:
return os << "String types require strings feature";
case TypeBuilder::ErrorReason::InvalidUnsharedField:
return os << "Heap type has an invalid unshared field";
case TypeBuilder::ErrorReason::NonStructDescribes:
Expand Down Expand Up @@ -2435,6 +2437,9 @@ validateType(Type type, FeatureSet feats, bool isShared) {
if (heapType.isShared() && !feats.hasSharedEverything()) {
return TypeBuilder::ErrorReason::InvalidSharedType;
}
if (heapType.isString() && !feats.hasStrings()) {
return TypeBuilder::ErrorReason::InvalidStringType;
}
}
return std::nullopt;
}
Expand Down
32 changes: 0 additions & 32 deletions test/lit/passes/gto-jsinterop.wast
Original file line number Diff line number Diff line change
Expand Up @@ -206,38 +206,6 @@
)
)

(module
(rec
;; CHECK: (rec
;; CHECK-NEXT: (type $struct (descriptor $desc) (struct))
(type $struct (descriptor $desc) (struct))
;; Strings cannot be prototypes. If the prototype field holds a string, it
;; will appear as a null prototype. That is the default prototype value, so
;; we can optimize out prototype fields if we know they will be strings.
;; CHECK: (type $desc (describes $struct) (struct))
(type $desc (describes $struct) (struct (field stringref)))
)

;; CHECK: (type $2 (func))

;; CHECK: (func $externalize (type $2)
;; CHECK-NEXT: (local $struct (ref null $struct))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (extern.convert_any
;; CHECK-NEXT: (local.get $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $externalize
(local $struct (ref null $struct))
(drop
(extern.convert_any
(local.get $struct)
)
)
)
)

(module
(rec
;; CHECK: (rec
Expand Down
35 changes: 35 additions & 0 deletions test/lit/passes/gto-strings-jsinterop.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt -all --closed-world --gto --preserve-type-order -S -o - | filecheck %s

(module
(rec
;; CHECK: (rec
;; CHECK-NEXT: (type $struct (descriptor $desc) (struct))
(type $struct (descriptor $desc) (struct))
;; Strings cannot be prototypes. If the prototype field holds a string, it
;; will appear as a null prototype. That is the default prototype value, so
;; we can optimize out prototype fields if we know they will be strings.
;; CHECK: (type $desc (describes $struct) (struct))
(type $desc (describes $struct) (struct (field stringref)))
)

;; CHECK: (type $2 (func))

;; CHECK: (func $externalize (type $2)
;; CHECK-NEXT: (local $struct (ref null $struct))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (extern.convert_any
;; CHECK-NEXT: (local.get $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $externalize
(local $struct (ref null $struct))
(drop
(extern.convert_any
(local.get $struct)
)
)
)
)
12 changes: 12 additions & 0 deletions test/lit/validation/strings-in-types.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; Test that string heap types require strings to be enabled.

;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-STRINGS
;; RUN: wasm-opt %s --enable-reference-types --enable-strings -o - -S | filecheck %s --check-prefix STRINGS

;; NO-STRINGS: invalid type: String types require strings feature
;; STRINGS: (type $s (func (param stringref)))

(module
(type $s (func (param stringref)))
(global $g (ref null $s) (ref.null nofunc))
)
Loading