Skip to content

Commit 90b6e7a

Browse files
committed
Move isBasic() checks in common Type::is*() to the header
1 parent 1a2d26f commit 90b6e7a

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

src/wasm-type.h

+45-6
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,58 @@ class Type {
150150
constexpr bool isFloat() const { return id == f32 || id == f64; }
151151
constexpr bool isVector() const { return id == v128; };
152152
constexpr bool isNumber() const { return id >= i32 && id <= v128; }
153-
bool isTuple() const;
154153
bool isSingle() const { return isConcrete() && !isTuple(); }
155-
bool isRef() const;
156-
bool isFunction() const;
157-
// See literal.h.
158-
bool isData() const;
154+
155+
// Tuples, refs, etc. are quickly handled using isBasic(), leaving the non-
156+
// basic case for the underlying implementation.
157+
158+
bool isTuple() const {
159+
if (isBasic()) {
160+
return false;
161+
} else {
162+
return isNonBasicTuple();
163+
}
164+
}
165+
166+
bool isRef() const {
167+
if (isBasic()) {
168+
return false;
169+
} else {
170+
return isNonBasicRef();
171+
}
172+
}
173+
174+
bool isFunction() const {
175+
if (isBasic()) {
176+
return false;
177+
} else {
178+
return isNonBasicFunction();
179+
}
180+
}
181+
182+
bool isData() const {
183+
if (isBasic()) {
184+
return false;
185+
} else {
186+
return isNonBasicData();
187+
}
188+
}
189+
159190
// Checks whether a type is a reference and is nullable. This returns false
160191
// for a value that is not a reference, that is, for which nullability is
161192
// irrelevant.
162193
bool isNullable() const;
194+
163195
// Checks whether a type is a reference and is non-nullable. This returns
164196
// false for a value that is not a reference, that is, for which nullability
165197
// is irrelevant. (For that reason, this is only the negation of isNullable()
166198
// on references, but both return false on non-references.)
167199
bool isNonNullable() const;
200+
201+
bool isSignature() const;
202+
168203
// Whether this type is only inhabited by null values.
169204
bool isNull() const;
170-
bool isSignature() const;
171205
bool isStruct() const;
172206
bool isArray() const;
173207
bool isExn() const;
@@ -177,6 +211,11 @@ class Type {
177211
Nullability getNullability() const;
178212

179213
private:
214+
bool isNonBasicTuple() const;
215+
bool isNonBasicRef() const;
216+
bool isNonBasicFunction() const;
217+
bool isNonBasicData() const;
218+
180219
template<bool (Type::*pred)() const> bool hasPredicate() {
181220
for (const auto& type : *this) {
182221
if ((type.*pred)()) {

src/wasm/wasm-type.cpp

+8-20
Original file line numberDiff line numberDiff line change
@@ -756,39 +756,27 @@ Type::Type(HeapType heapType, Nullability nullable) {
756756
new (this) Type(globalTypeStore.insert(TypeInfo(heapType, nullable)));
757757
}
758758

759-
bool Type::isTuple() const {
760-
if (isBasic()) {
761-
return false;
762-
} else {
759+
bool Type::isNonBasicTuple() const {
760+
assert(!isBasic());
763761
return getTypeInfo(*this)->isTuple();
764762
}
765-
}
766763

767-
bool Type::isRef() const {
768-
if (isBasic()) {
769-
return false;
770-
} else {
764+
bool Type::isNonBasicRef() const {
765+
assert(!isBasic());
771766
return getTypeInfo(*this)->isRef();
772767
}
773-
}
774768

775-
bool Type::isFunction() const {
776-
if (isBasic()) {
777-
return false;
778-
} else {
769+
bool Type::isNonBasicFunction() const {
770+
assert(!isBasic());
779771
auto* info = getTypeInfo(*this);
780772
return info->isRef() && info->ref.heapType.isFunction();
781773
}
782-
}
783774

784-
bool Type::isData() const {
785-
if (isBasic()) {
786-
return false;
787-
} else {
775+
bool Type::isNonBasicData() const {
776+
assert(!isBasic());
788777
auto* info = getTypeInfo(*this);
789778
return info->isRef() && info->ref.heapType.isData();
790779
}
791-
}
792780

793781
bool Type::isNullable() const {
794782
if (isRef()) {

0 commit comments

Comments
 (0)