-
Notifications
You must be signed in to change notification settings - Fork 787
Add new compound Rtt type #3076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
99198d4
Add new compound Rtt type
dcodeIO 2b41dad
document nullability
dcodeIO 813a458
construct with depth (whoops)
dcodeIO 35bd8a1
refactor to use HeapType in both TypeInfo and Rtt
dcodeIO afda206
basic tests
dcodeIO 74bb40d
actually test Rtt (heh)
dcodeIO 6eba0fd
more
dcodeIO 1cb2737
update diagram
dcodeIO deb082c
Merge branch 'master' into gc-rtt
dcodeIO 28745e9
move less trivial methods into the .cpp file
dcodeIO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,13 +31,6 @@ | |
|
||
namespace wasm { | ||
|
||
struct Tuple; | ||
struct Signature; | ||
struct Struct; | ||
struct Array; | ||
|
||
typedef std::vector<class Type> TypeList; | ||
|
||
class Type { | ||
// The `id` uniquely represents each type, so type equality is just a | ||
// comparison of the ids. For basic types the `id` is just the `BasicID` | ||
|
@@ -73,16 +66,14 @@ class Type { | |
Type(std::initializer_list<Type>); | ||
|
||
// Construct from tuple description | ||
explicit Type(const Tuple&); | ||
|
||
// Construct from signature description | ||
explicit Type(const Signature, bool nullable); | ||
explicit Type(const struct Tuple&); | ||
|
||
// Construct from struct description | ||
explicit Type(const Struct&, bool nullable); | ||
// Construct from a heap type description. Also covers construction from | ||
// Signature, Struct or Array via implicit conversion to HeapType. | ||
explicit Type(const struct HeapType&, bool nullable); | ||
|
||
// Construct from array description | ||
explicit Type(const Array&, bool nullable); | ||
// Construct from rtt description | ||
explicit Type(const struct Rtt&); | ||
|
||
// Predicates | ||
// Compound Concrete | ||
|
@@ -96,16 +87,18 @@ class Type { | |
// │ f32 ║ x │ │ x │ x │ F │ │ F_loat | ||
// │ f64 ║ x │ │ x │ x │ F │ │ V_ector | ||
// │ v128 ║ x │ │ x │ x │ V │ ┘ | ||
// ├─────────────╫───┼───┼───┼───┤───────┤ | ||
// │ funcref ║ x │ │ x │ x │ f │ ┐ Ref | ||
// │ externref ║ x │ │ x │ x │ │ │ f_unc | ||
// │ nullref ║ x │ │ x │ x │ │ │ | ||
// │ exnref ║ x │ │ x │ x │ │ │ | ||
// ├─────────────╫───┼───┼───┼───┤───────┤ │ | ||
// │ Signature ║ │ x │ x │ x │ f │ │ | ||
// │ Struct ║ │ x │ x │ x │ │ │ | ||
// │ Array ║ │ x │ x │ x │ │ ┘ | ||
// ├─ Aliases ───╫───┼───┼───┼───┤───────┤ | ||
// │ funcref ║ x │ │ x │ x │ f n │ ┐ Ref | ||
// │ externref ║ x │ │ x │ x │ f? n │ │ f_unc, n_ullable | ||
// │ anyref ║ x │ │ x │ x │ f? n │ │ ┐ | ||
// │ eqref ║ x │ │ x │ x │ n │ │ │ TODO (GC) | ||
// │ i31ref ║ x │ │ x │ x │ │ │ ┘ | ||
dcodeIO marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// │ nullref ║ x │ │ x │ x │ f? n │ │ ◄ TODO (removed) | ||
// │ exnref ║ x │ │ x │ x │ n │ │ | ||
// ├─ Compound ──╫───┼───┼───┼───┤───────┤ │ | ||
// │ Ref ║ │ x │ x │ x │ f? n? │◄┘ | ||
// │ Tuple ║ │ x │ │ x │ │ | ||
// │ Rtt ║ │ x │ x │ x │ │ | ||
// └─────────────╨───┴───┴───┴───┴───────┘ | ||
constexpr bool isBasic() const { return id <= _last_basic_id; } | ||
constexpr bool isCompound() const { return id > _last_basic_id; } | ||
|
@@ -118,6 +111,7 @@ class Type { | |
bool isSingle() const { return isConcrete() && !isTuple(); } | ||
bool isRef() const; | ||
bool isNullable() const; | ||
bool isRtt() const; | ||
|
||
private: | ||
template<bool (Type::*pred)() const> bool hasPredicate() { | ||
|
@@ -227,6 +221,8 @@ struct ResultType { | |
std::string toString() const; | ||
}; | ||
|
||
typedef std::vector<Type> TypeList; | ||
|
||
struct Tuple { | ||
TypeList types; | ||
Tuple() : types() {} | ||
|
@@ -303,6 +299,72 @@ struct Array { | |
std::string toString() const; | ||
}; | ||
|
||
struct HeapType { | ||
enum Kind { | ||
FuncKind, | ||
ExternKind, | ||
AnyKind, | ||
EqKind, | ||
I31Kind, | ||
ExnKind, | ||
_last_basic_kind = ExnKind, | ||
SignatureKind, | ||
StructKind, | ||
ArrayKind, | ||
} kind; | ||
union { | ||
Signature signature; | ||
Struct struct_; | ||
Array array; | ||
}; | ||
HeapType(Kind kind) : kind(kind) { assert(kind <= _last_basic_kind); } | ||
HeapType(const Signature& signature) | ||
: kind(SignatureKind), signature(signature) {} | ||
HeapType(Signature&& signature) | ||
: kind(SignatureKind), signature(std::move(signature)) {} | ||
HeapType(const Struct& struct_) : kind(StructKind), struct_(struct_) {} | ||
HeapType(Struct&& struct_) : kind(StructKind), struct_(std::move(struct_)) {} | ||
HeapType(const Array& array) : kind(ArrayKind), array(array) {} | ||
HeapType(Array&& array) : kind(ArrayKind), array(std::move(array)) {} | ||
HeapType(const HeapType& other); | ||
~HeapType(); | ||
|
||
bool isSignature() const { return kind == SignatureKind; } | ||
Signature getSignature() const { | ||
assert(isSignature() && "Not a signature"); | ||
return signature; | ||
} | ||
bool isStruct() const { return kind == StructKind; } | ||
Struct getStruct() const { | ||
assert(isStruct() && "Not a struct"); | ||
return struct_; | ||
} | ||
bool isArray() const { return kind == ArrayKind; } | ||
Array getArray() const { | ||
assert(isArray() && "Not an array"); | ||
return array; | ||
} | ||
|
||
bool operator==(const HeapType& other) const; | ||
bool operator!=(const HeapType& other) const { return !(*this == other); } | ||
HeapType& operator=(const HeapType& other); | ||
std::string toString() const; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to move the less trivial methods into the .cpp file. I'm thinking roughly anything with a switch in it. My goal there would be consistency with where the |
||
|
||
struct Rtt { | ||
uint32_t depth; | ||
HeapType heapType; | ||
Rtt(uint32_t depth, const HeapType& heapType) | ||
: depth(depth), heapType(heapType) {} | ||
Rtt(uint32_t depth, HeapType&& heapType) | ||
: depth(depth), heapType(std::move(heapType)) {} | ||
bool operator==(const Rtt& other) const { | ||
return depth == other.depth && heapType == other.heapType; | ||
} | ||
bool operator!=(const Rtt& other) const { return !(*this == other); } | ||
std::string toString() const; | ||
}; | ||
|
||
std::ostream& operator<<(std::ostream&, Type); | ||
std::ostream& operator<<(std::ostream&, ParamType); | ||
std::ostream& operator<<(std::ostream&, ResultType); | ||
|
@@ -311,6 +373,8 @@ std::ostream& operator<<(std::ostream&, Signature); | |
std::ostream& operator<<(std::ostream&, Field); | ||
std::ostream& operator<<(std::ostream&, Struct); | ||
std::ostream& operator<<(std::ostream&, Array); | ||
std::ostream& operator<<(std::ostream&, HeapType); | ||
std::ostream& operator<<(std::ostream&, Rtt); | ||
|
||
} // namespace wasm | ||
|
||
|
@@ -340,6 +404,14 @@ template<> class hash<wasm::Array> { | |
public: | ||
size_t operator()(const wasm::Array&) const; | ||
}; | ||
template<> class hash<wasm::HeapType> { | ||
public: | ||
size_t operator()(const wasm::HeapType&) const; | ||
}; | ||
template<> class hash<wasm::Rtt> { | ||
public: | ||
size_t operator()(const wasm::Rtt&) const; | ||
}; | ||
|
||
} // namespace std | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.