@@ -25,8 +25,10 @@ class Simd128;
2525// For every two types connected by a line, the top type is a
2626// (direct) subtype of the bottom type.
2727//
28- // AnyRef
29- // / | \
28+ // AnyRef
29+ // / \
30+ // / EqRef
31+ // / / \
3032// FuncRef ExnRef OptRef(S)
3133// \ | / \
3234// I32 I64 F32 F64 NullRef Ref(S)
@@ -38,7 +40,7 @@ class Simd128;
3840// - "ref" types per https://github.com/WebAssembly/function-references
3941// - "optref"/"eqref" per https://github.com/WebAssembly/gc
4042//
41- // TODO(7748): Extend this with eqref, struct and function subtyping.
43+ // TODO(7748): Extend this with struct and function subtyping.
4244// Keep up to date with funcref vs. anyref subtyping.
4345#define FOREACH_VALUE_TYPE (V ) \
4446 V (Stmt, -1 , Void, None, ' v' , " <stmt>" ) \
@@ -71,11 +73,15 @@ class ValueType {
7173 constexpr ValueType () : bit_field_(KindField::encode(kStmt )) {}
7274 explicit constexpr ValueType (Kind kind)
7375 : bit_field_(KindField::encode(kind)) {
76+ #if V8_HAS_CXX14_CONSTEXPR
7477 DCHECK (!has_immediate ());
78+ #endif
7579 }
7680 constexpr ValueType (Kind kind, uint32_t ref_index)
7781 : bit_field_(KindField::encode(kind) | RefIndexField::encode(ref_index)) {
82+ #if V8_HAS_CXX14_CONSTEXPR
7883 DCHECK (has_immediate ());
84+ #endif
7985 }
8086
8187 constexpr Kind kind () const { return KindField::decode (bit_field_); }
@@ -110,27 +116,25 @@ class ValueType {
110116 return bit_field_ != other.bit_field_ ;
111117 }
112118
113- // TODO(7748): Extend this with eqref, struct and function subtyping.
119+ // TODO(7748): Extend this with struct and function subtyping.
114120 // Keep up to date with funcref vs. anyref subtyping.
115- bool IsSubTypeOf (ValueType other) const {
116- return (*this == other) ||
117- (kind () == kNullRef &&
118- (other.kind () == kAnyRef || other.kind () == kFuncRef ||
119- other.kind () == kExnRef || other.kind () == kOptRef )) ||
120- (other.kind () == kAnyRef &&
121- (kind () == kFuncRef || kind () == kExnRef || kind () == kOptRef ||
122- kind () == kRef )) ||
121+ constexpr bool IsSubTypeOf (ValueType other) const {
122+ return (*this == other) || (other.kind () == kAnyRef && IsReferenceType ()) ||
123+ (kind () == kNullRef && other.kind () != kRef &&
124+ other.IsReferenceType ()) ||
125+ (other.kind () == kEqRef &&
126+ (kind () == kExnRef || kind () == kOptRef || kind () == kRef )) ||
123127 (kind () == kRef && other.kind () == kOptRef &&
124128 ref_index () == other.ref_index ());
125129 }
126130
127- bool IsReferenceType () const {
131+ constexpr bool IsReferenceType () const {
128132 return kind () == kAnyRef || kind () == kFuncRef || kind () == kNullRef ||
129133 kind () == kExnRef || kind () == kRef || kind () == kOptRef ||
130134 kind () == kEqRef ;
131135 }
132136
133- // TODO(7748): Extend this with eqref, struct and function subtyping.
137+ // TODO(7748): Extend this with struct and function subtyping.
134138 // Keep up to date with funcref vs. anyref subtyping.
135139 static ValueType CommonSubType (ValueType a, ValueType b) {
136140 if (a == b) return a;
@@ -143,12 +147,14 @@ class ValueType {
143147 // {a} and {b} are not each other's subtype.
144148 // If one of them is not nullable, their greatest subtype is bottom,
145149 // otherwise null.
146- return (a.kind () == kRef || b.kind () == kRef ) ? ValueType (kBottom )
147- : ValueType (kNullRef );
150+ if (a.kind () == kRef || b.kind () == kRef ) return ValueType (kBottom );
151+ return ValueType (kNullRef );
148152 }
149153
150- ValueTypeCode value_type_code () const {
154+ constexpr ValueTypeCode value_type_code () const {
155+ #if V8_HAS_CXX14_CONSTEXPR
151156 DCHECK_NE (kBottom , kind ());
157+ #endif
152158
153159 constexpr ValueTypeCode kValueTypeCode [] = {
154160#define TYPE_CODE (kind, log2Size, code, ...) kLocal ##code,
@@ -159,8 +165,10 @@ class ValueType {
159165 return kValueTypeCode [kind ()];
160166 }
161167
162- MachineType machine_type () const {
168+ constexpr MachineType machine_type () const {
169+ #if V8_HAS_CXX14_CONSTEXPR
163170 DCHECK_NE (kBottom , kind ());
171+ #endif
164172
165173 constexpr MachineType kMachineType [] = {
166174#define MACH_TYPE (kind, log2Size, code, machineType, ...) \
@@ -172,7 +180,7 @@ class ValueType {
172180 return kMachineType [kind ()];
173181 }
174182
175- MachineRepresentation machine_representation () {
183+ constexpr MachineRepresentation machine_representation () const {
176184 return machine_type ().representation ();
177185 }
178186
0 commit comments