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
118 changes: 105 additions & 13 deletions src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,17 @@ class HeapType {
HeapTypeKind getKind() const;

constexpr bool isBasic() const { return id <= _last_basic_type; }
bool isFunction() const {
return isMaybeShared(func) || getKind() == HeapTypeKind::Func;
}
bool isData() const {
auto kind = getKind();
return isMaybeShared(string) || kind == HeapTypeKind::Struct ||
kind == HeapTypeKind::Array;
}
bool isSignature() const { return getKind() == HeapTypeKind::Func; }
bool isContinuation() const { return getKind() == HeapTypeKind::Cont; }
bool isStruct() const { return getKind() == HeapTypeKind::Struct; }
bool isArray() const { return getKind() == HeapTypeKind::Array; }
bool isFunction() const;
bool isData() const;
bool isSignature() const;
bool isContinuation() const;
bool isStruct() const;
bool isArray() const;
bool isExn() const { return isMaybeShared(HeapType::exn); }
bool isString() const { return isMaybeShared(HeapType::string); }
bool isBottom() const;
bool isOpen() const;
bool isShared() const { return getShared() == Shared; }
bool isShared() const;

Shareability getShared() const;

Expand Down Expand Up @@ -1117,6 +1111,104 @@ std::ostream& operator<<(std::ostream&, const TypeBuilder::ErrorReason&);

// Inline some nontrivial methods here for performance reasons.

using RecGroupInfo = std::vector<HeapType>;

struct HeapTypeInfo {
using type_t = HeapType;
// Used in assertions to ensure that temporary types don't leak into the
// global store.
bool isTemp = false;
bool isOpen = false;
Shareability share = Unshared;
// The supertype of this HeapType, if it exists.
HeapTypeInfo* supertype = nullptr;
// The descriptor of this HeapType, if it exists.
HeapTypeInfo* descriptor = nullptr;
// The HeapType described by this one, if it exists.
HeapTypeInfo* described = nullptr;
// The recursion group of this type or null if the recursion group is trivial
// (i.e. contains only this type).
RecGroupInfo* recGroup = nullptr;
size_t recGroupIndex = 0;
HeapTypeKind kind;
union {
Signature signature;
Continuation continuation;
Struct struct_;
Array array;
};

HeapTypeInfo(Signature sig) : kind(HeapTypeKind::Func), signature(sig) {}
HeapTypeInfo(Continuation continuation)
: kind(HeapTypeKind::Cont), continuation(continuation) {}
HeapTypeInfo(const Struct& struct_)
: kind(HeapTypeKind::Struct), struct_(struct_) {}
HeapTypeInfo(Struct&& struct_)
: kind(HeapTypeKind::Struct), struct_(std::move(struct_)) {}
HeapTypeInfo(Array array) : kind(HeapTypeKind::Array), array(array) {}
~HeapTypeInfo();

constexpr bool isSignature() const { return kind == HeapTypeKind::Func; }
constexpr bool isContinuation() const { return kind == HeapTypeKind::Cont; }
constexpr bool isStruct() const { return kind == HeapTypeKind::Struct; }
constexpr bool isArray() const { return kind == HeapTypeKind::Array; }
constexpr bool isData() const { return isStruct() || isArray(); }
};

inline HeapTypeInfo* getHeapTypeInfo(HeapType ht) {
assert(!ht.isBasic());
return (HeapTypeInfo*)ht.getID();
}

inline HeapTypeKind HeapType::getKind() const {
if (isBasic()) {
return HeapTypeKind::Basic;
}
return getHeapTypeInfo(*this)->kind;
}

inline bool HeapType::isFunction() const {
return isMaybeShared(func) || getKind() == HeapTypeKind::Func;
}

inline bool HeapType::isData() const {
auto kind = getKind();
return isMaybeShared(string) || kind == HeapTypeKind::Struct ||
kind == HeapTypeKind::Array;
}

inline bool HeapType::isSignature() const {
return getKind() == HeapTypeKind::Func;
}

inline bool HeapType::isContinuation() const {
return getKind() == HeapTypeKind::Cont;
}

inline bool HeapType::isStruct() const {
return getKind() == HeapTypeKind::Struct;
}

inline bool HeapType::isArray() const {
return getKind() == HeapTypeKind::Array;
}

inline bool HeapType::isOpen() const {
if (isBasic()) {
return false;
}
return getHeapTypeInfo(*this)->isOpen;
}

inline bool HeapType::isShared() const { return getShared() == Shared; }

inline Shareability HeapType::getShared() const {
if (isBasic()) {
return (getID() & SharedMask) != 0 ? Shared : Unshared;
}
return getHeapTypeInfo(*this)->share;
}

inline bool HeapType::isBottom() const {
if (isBasic()) {
switch (getBasic(Unshared)) {
Expand Down
72 changes: 0 additions & 72 deletions src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,6 @@ namespace wasm {

namespace {

using RecGroupInfo = std::vector<HeapType>;

struct HeapTypeInfo {
using type_t = HeapType;
// Used in assertions to ensure that temporary types don't leak into the
// global store.
bool isTemp = false;
bool isOpen = false;
Shareability share = Unshared;
// The supertype of this HeapType, if it exists.
HeapTypeInfo* supertype = nullptr;
// The descriptor of this HeapType, if it exists.
HeapTypeInfo* descriptor = nullptr;
// The HeapType described by this one, if it exists.
HeapTypeInfo* described = nullptr;
// The recursion group of this type or null if the recursion group is trivial
// (i.e. contains only this type).
RecGroupInfo* recGroup = nullptr;
size_t recGroupIndex = 0;
HeapTypeKind kind;
union {
Signature signature;
Continuation continuation;
Struct struct_;
Array array;
};

HeapTypeInfo(Signature sig) : kind(HeapTypeKind::Func), signature(sig) {}
HeapTypeInfo(Continuation continuation)
: kind(HeapTypeKind::Cont), continuation(continuation) {}
HeapTypeInfo(const Struct& struct_)
: kind(HeapTypeKind::Struct), struct_(struct_) {}
HeapTypeInfo(Struct&& struct_)
: kind(HeapTypeKind::Struct), struct_(std::move(struct_)) {}
HeapTypeInfo(Array array) : kind(HeapTypeKind::Array), array(array) {}
~HeapTypeInfo();

constexpr bool isSignature() const { return kind == HeapTypeKind::Func; }
constexpr bool isContinuation() const { return kind == HeapTypeKind::Cont; }
constexpr bool isStruct() const { return kind == HeapTypeKind::Struct; }
constexpr bool isArray() const { return kind == HeapTypeKind::Array; }
constexpr bool isData() const { return isStruct() || isArray(); }
};

// Helper for finding the equirecursive least upper bound of two types.
// Helper for printing types.
struct TypePrinter {
Expand Down Expand Up @@ -210,11 +166,6 @@ template<typename T> class equal_to<reference_wrapper<const T>> {
namespace wasm {
namespace {

HeapTypeInfo* getHeapTypeInfo(HeapType ht) {
assert(!ht.isBasic());
return (HeapTypeInfo*)ht.getID();
}

HeapType asHeapType(std::unique_ptr<HeapTypeInfo>& info) {
return HeapType(uintptr_t(info.get()));
}
Expand Down Expand Up @@ -881,29 +832,6 @@ HeapType::HeapType(Array array) {
HeapType(globalRecGroupStore.insert(std::make_unique<HeapTypeInfo>(array)));
}

HeapTypeKind HeapType::getKind() const {
if (isBasic()) {
return HeapTypeKind::Basic;
}
return getHeapTypeInfo(*this)->kind;
}

bool HeapType::isOpen() const {
if (isBasic()) {
return false;
} else {
return getHeapTypeInfo(*this)->isOpen;
}
}

Shareability HeapType::getShared() const {
if (isBasic()) {
return (id & SharedMask) != 0 ? Shared : Unshared;
} else {
return getHeapTypeInfo(*this)->share;
}
}

bool HeapType::isCastable() {
return !isContinuation() && !isMaybeShared(HeapType::cont) &&
!isMaybeShared(HeapType::nocont);
Expand Down
Loading