Skip to content

Commit 952fef5

Browse files
committed
go
1 parent 6b06b59 commit 952fef5

2 files changed

Lines changed: 98 additions & 87 deletions

File tree

src/wasm-type.h

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,17 @@ class HeapType {
151151
HeapTypeKind getKind() const;
152152

153153
constexpr bool isBasic() const { return id <= _last_basic_type; }
154-
bool isFunction() const {
155-
return isMaybeShared(func) || getKind() == HeapTypeKind::Func;
156-
}
157-
bool isData() const {
158-
auto kind = getKind();
159-
return isMaybeShared(string) || kind == HeapTypeKind::Struct ||
160-
kind == HeapTypeKind::Array;
161-
}
162-
bool isSignature() const { return getKind() == HeapTypeKind::Func; }
163-
bool isContinuation() const { return getKind() == HeapTypeKind::Cont; }
164-
bool isStruct() const { return getKind() == HeapTypeKind::Struct; }
165-
bool isArray() const { return getKind() == HeapTypeKind::Array; }
154+
bool isFunction() const;
155+
bool isData() const;
156+
bool isSignature() const;
157+
bool isContinuation() const;
158+
bool isStruct() const;
159+
bool isArray() const;
166160
bool isExn() const { return isMaybeShared(HeapType::exn); }
167161
bool isString() const { return isMaybeShared(HeapType::string); }
168162
bool isBottom() const;
169163
bool isOpen() const;
170-
bool isShared() const { return getShared() == Shared; }
164+
bool isShared() const;
171165

172166
Shareability getShared() const;
173167

@@ -1117,6 +1111,97 @@ std::ostream& operator<<(std::ostream&, const TypeBuilder::ErrorReason&);
11171111

11181112
// Inline some nontrivial methods here for performance reasons.
11191113

1114+
using RecGroupInfo = std::vector<HeapType>;
1115+
1116+
struct HeapTypeInfo {
1117+
using type_t = HeapType;
1118+
bool isTemp = false;
1119+
bool isOpen = false;
1120+
Shareability share = Unshared;
1121+
HeapTypeInfo* supertype = nullptr;
1122+
HeapTypeInfo* descriptor = nullptr;
1123+
HeapTypeInfo* described = nullptr;
1124+
RecGroupInfo* recGroup = nullptr;
1125+
size_t recGroupIndex = 0;
1126+
HeapTypeKind kind;
1127+
union {
1128+
Signature signature;
1129+
Continuation continuation;
1130+
Struct struct_;
1131+
Array array;
1132+
};
1133+
1134+
HeapTypeInfo(Signature sig) : kind(HeapTypeKind::Func), signature(sig) {}
1135+
HeapTypeInfo(Continuation continuation)
1136+
: kind(HeapTypeKind::Cont), continuation(continuation) {}
1137+
HeapTypeInfo(const Struct& struct_)
1138+
: kind(HeapTypeKind::Struct), struct_(struct_) {}
1139+
HeapTypeInfo(Struct&& struct_)
1140+
: kind(HeapTypeKind::Struct), struct_(std::move(struct_)) {}
1141+
HeapTypeInfo(Array array) : kind(HeapTypeKind::Array), array(array) {}
1142+
~HeapTypeInfo();
1143+
1144+
constexpr bool isSignature() const { return kind == HeapTypeKind::Func; }
1145+
constexpr bool isContinuation() const { return kind == HeapTypeKind::Cont; }
1146+
constexpr bool isStruct() const { return kind == HeapTypeKind::Struct; }
1147+
constexpr bool isArray() const { return kind == HeapTypeKind::Array; }
1148+
constexpr bool isData() const { return isStruct() || isArray(); }
1149+
};
1150+
1151+
inline HeapTypeInfo* getHeapTypeInfo(HeapType ht) {
1152+
assert(!ht.isBasic());
1153+
return (HeapTypeInfo*)ht.getID();
1154+
}
1155+
1156+
inline HeapTypeKind HeapType::getKind() const {
1157+
if (isBasic()) {
1158+
return HeapTypeKind::Basic;
1159+
}
1160+
return getHeapTypeInfo(*this)->kind;
1161+
}
1162+
1163+
inline bool HeapType::isFunction() const {
1164+
return isMaybeShared(func) || getKind() == HeapTypeKind::Func;
1165+
}
1166+
1167+
inline bool HeapType::isData() const {
1168+
auto kind = getKind();
1169+
return isMaybeShared(string) || kind == HeapTypeKind::Struct ||
1170+
kind == HeapTypeKind::Array;
1171+
}
1172+
1173+
inline bool HeapType::isSignature() const {
1174+
return getKind() == HeapTypeKind::Func;
1175+
}
1176+
1177+
inline bool HeapType::isContinuation() const {
1178+
return getKind() == HeapTypeKind::Cont;
1179+
}
1180+
1181+
inline bool HeapType::isStruct() const {
1182+
return getKind() == HeapTypeKind::Struct;
1183+
}
1184+
1185+
inline bool HeapType::isArray() const {
1186+
return getKind() == HeapTypeKind::Array;
1187+
}
1188+
1189+
inline bool HeapType::isOpen() const {
1190+
if (isBasic()) {
1191+
return false;
1192+
}
1193+
return getHeapTypeInfo(*this)->isOpen;
1194+
}
1195+
1196+
inline bool HeapType::isShared() const { return getShared() == Shared; }
1197+
1198+
inline Shareability HeapType::getShared() const {
1199+
if (isBasic()) {
1200+
return (getID() & SharedMask) != 0 ? Shared : Unshared;
1201+
}
1202+
return getHeapTypeInfo(*this)->share;
1203+
}
1204+
11201205
inline bool HeapType::isBottom() const {
11211206
if (isBasic()) {
11221207
switch (getBasic(Unshared)) {

src/wasm/wasm-type.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,6 @@ namespace wasm {
3838

3939
namespace {
4040

41-
using RecGroupInfo = std::vector<HeapType>;
42-
43-
struct HeapTypeInfo {
44-
using type_t = HeapType;
45-
// Used in assertions to ensure that temporary types don't leak into the
46-
// global store.
47-
bool isTemp = false;
48-
bool isOpen = false;
49-
Shareability share = Unshared;
50-
// The supertype of this HeapType, if it exists.
51-
HeapTypeInfo* supertype = nullptr;
52-
// The descriptor of this HeapType, if it exists.
53-
HeapTypeInfo* descriptor = nullptr;
54-
// The HeapType described by this one, if it exists.
55-
HeapTypeInfo* described = nullptr;
56-
// The recursion group of this type or null if the recursion group is trivial
57-
// (i.e. contains only this type).
58-
RecGroupInfo* recGroup = nullptr;
59-
size_t recGroupIndex = 0;
60-
HeapTypeKind kind;
61-
union {
62-
Signature signature;
63-
Continuation continuation;
64-
Struct struct_;
65-
Array array;
66-
};
67-
68-
HeapTypeInfo(Signature sig) : kind(HeapTypeKind::Func), signature(sig) {}
69-
HeapTypeInfo(Continuation continuation)
70-
: kind(HeapTypeKind::Cont), continuation(continuation) {}
71-
HeapTypeInfo(const Struct& struct_)
72-
: kind(HeapTypeKind::Struct), struct_(struct_) {}
73-
HeapTypeInfo(Struct&& struct_)
74-
: kind(HeapTypeKind::Struct), struct_(std::move(struct_)) {}
75-
HeapTypeInfo(Array array) : kind(HeapTypeKind::Array), array(array) {}
76-
~HeapTypeInfo();
77-
78-
constexpr bool isSignature() const { return kind == HeapTypeKind::Func; }
79-
constexpr bool isContinuation() const { return kind == HeapTypeKind::Cont; }
80-
constexpr bool isStruct() const { return kind == HeapTypeKind::Struct; }
81-
constexpr bool isArray() const { return kind == HeapTypeKind::Array; }
82-
constexpr bool isData() const { return isStruct() || isArray(); }
83-
};
84-
85-
// Helper for finding the equirecursive least upper bound of two types.
86-
// Helper for printing types.
8741
struct TypePrinter {
8842
// The stream we are printing to.
8943
std::ostream& os;
@@ -210,11 +164,6 @@ template<typename T> class equal_to<reference_wrapper<const T>> {
210164
namespace wasm {
211165
namespace {
212166

213-
HeapTypeInfo* getHeapTypeInfo(HeapType ht) {
214-
assert(!ht.isBasic());
215-
return (HeapTypeInfo*)ht.getID();
216-
}
217-
218167
HeapType asHeapType(std::unique_ptr<HeapTypeInfo>& info) {
219168
return HeapType(uintptr_t(info.get()));
220169
}
@@ -881,29 +830,6 @@ HeapType::HeapType(Array array) {
881830
HeapType(globalRecGroupStore.insert(std::make_unique<HeapTypeInfo>(array)));
882831
}
883832

884-
HeapTypeKind HeapType::getKind() const {
885-
if (isBasic()) {
886-
return HeapTypeKind::Basic;
887-
}
888-
return getHeapTypeInfo(*this)->kind;
889-
}
890-
891-
bool HeapType::isOpen() const {
892-
if (isBasic()) {
893-
return false;
894-
} else {
895-
return getHeapTypeInfo(*this)->isOpen;
896-
}
897-
}
898-
899-
Shareability HeapType::getShared() const {
900-
if (isBasic()) {
901-
return (id & SharedMask) != 0 ? Shared : Unshared;
902-
} else {
903-
return getHeapTypeInfo(*this)->share;
904-
}
905-
}
906-
907833
bool HeapType::isCastable() {
908834
return !isContinuation() && !isMaybeShared(HeapType::cont) &&
909835
!isMaybeShared(HeapType::nocont);

0 commit comments

Comments
 (0)