-
Notifications
You must be signed in to change notification settings - Fork 873
Initial support for exact heap types #7396
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
Changes from all commits
6fc7741
f3e6b27
1817627
fd709ed
0f46cad
a475c44
35aa881
e23dc6a
91155ad
c3a12b2
5e343e0
6382e0d
dcf0a17
d48547c
c594874
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,7 +228,7 @@ namespace { | |
|
|
||
| HeapTypeInfo* getHeapTypeInfo(HeapType ht) { | ||
| assert(!ht.isBasic()); | ||
| return (HeapTypeInfo*)ht.getID(); | ||
| return (HeapTypeInfo*)(ht.getRawID()); | ||
|
Member
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. I don't feel strongly but
Member
Author
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. What do you think about
Member
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. Hmm, no real preference between those. Current name is fine. |
||
| } | ||
|
|
||
| HeapType asHeapType(std::unique_ptr<HeapTypeInfo>& info) { | ||
|
|
@@ -1247,7 +1247,7 @@ RecGroup HeapType::getRecGroup() const { | |
| } else { | ||
| // Mark the low bit to signify that this is a trivial recursion group and | ||
| // points to a heap type info rather than a vector of heap types. | ||
| return RecGroup(id | 1); | ||
| return RecGroup(getRawID() | 1); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1608,14 +1608,20 @@ bool SubTyper::isSubType(const Array& a, const Array& b) { | |
| } | ||
|
|
||
| void TypePrinter::printHeapTypeName(HeapType type) { | ||
| if (type.isExact()) { | ||
| os << "(exact "; | ||
| } | ||
| if (type.isBasic()) { | ||
| print(type); | ||
| return; | ||
| } | ||
| generator(type).name.print(os); | ||
| } else { | ||
| generator(type).name.print(os); | ||
| #if TRACE_CANONICALIZATION | ||
| os << "(;" << ((type.getID() >> 4) % 1000) << ";) "; | ||
| os << "(;" << ((type.getID() >> 4) % 1000) << ";) "; | ||
| #endif | ||
| } | ||
| if (type.isExact()) { | ||
| os << ')'; | ||
| } | ||
| } | ||
|
|
||
| std::ostream& TypePrinter::print(Type type) { | ||
|
|
@@ -1942,8 +1948,10 @@ size_t RecGroupHasher::hash(HeapType type) const { | |
| wasm::rehash(digest, type.getID()); | ||
| return digest; | ||
| } | ||
| wasm::rehash(digest, type.isExact()); | ||
| wasm::rehash(digest, type.getRecGroupIndex()); | ||
| auto currGroup = type.getRecGroup(); | ||
| wasm::rehash(digest, currGroup != group); | ||
| if (currGroup != group) { | ||
| wasm::rehash(digest, currGroup.getID()); | ||
| } | ||
|
|
@@ -2073,6 +2081,9 @@ bool RecGroupEquator::eq(HeapType a, HeapType b) const { | |
| if (a.isBasic() || b.isBasic()) { | ||
| return a == b; | ||
| } | ||
| if (a.getExactness() != b.getExactness()) { | ||
| return false; | ||
| } | ||
| if (a.getRecGroupIndex() != b.getRecGroupIndex()) { | ||
| return false; | ||
| } | ||
|
|
@@ -2456,15 +2467,18 @@ void updateReferencedHeapTypes( | |
| isTopLevel = false; | ||
| if (type->isRef()) { | ||
| auto ht = type->getHeapType(); | ||
| auto exact = ht.getExactness(); | ||
| ht = ht.with(Inexact); | ||
| if (auto it = canonicalized.find(ht); it != canonicalized.end()) { | ||
| *type = Type(it->second, type->getNullability()); | ||
| *type = Type(it->second.with(exact), type->getNullability()); | ||
|
Member
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. But if exactness is part of the heap type, why do we want this behavior?
Member
Author
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. This is replacing non-canonical heap types with canonical heap types. If
Member
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. I see, thanks. Why does Shared not need to be handled similarly here? Because for non-basic types we store it on HeapTypeInfo?
Member
Author
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. Right. Sharedness is actually part of the type definition, unlike exactness. |
||
| } | ||
| } else if (type->isTuple()) { | ||
| TypeGraphWalkerBase<ChildUpdater>::scanType(type); | ||
| } | ||
| } | ||
|
|
||
| void scanHeapType(HeapType* type) { | ||
| assert(!type->isExact() && "unexpected exact type in definition"); | ||
| if (isTopLevel) { | ||
| isTopLevel = false; | ||
| TypeGraphWalkerBase<ChildUpdater>::scanHeapType(type); | ||
|
|
@@ -2529,7 +2543,8 @@ buildRecGroup(std::unique_ptr<RecGroupInfo>&& groupInfo, | |
| for (size_t i = 0; i < typeInfos.size(); ++i) { | ||
| auto type = asHeapType(typeInfos[i]); | ||
| for (auto child : type.getHeapTypeChildren()) { | ||
| if (isTemp(child) && !seenTypes.count(child)) { | ||
| HeapType rawChild(child.getRawID()); | ||
| if (isTemp(rawChild) && !seenTypes.count(rawChild)) { | ||
| return {TypeBuilder::Error{ | ||
| i, TypeBuilder::ErrorReason::ForwardChildReference}}; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment explaining the difference.
And, in particular - when would
getID()still be used?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example when hashing a type or in the C API to convert the type to an integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the comment.