Skip to content

Avoid errors in Type::with(HeapType) #7551

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 4 commits into from
Apr 29, 2025
Merged

Avoid errors in Type::with(HeapType) #7551

merged 4 commits into from
Apr 29, 2025

Conversation

tlively
Copy link
Member

@tlively tlively commented Apr 25, 2025

Previously doing e.g. type.with(HeapType::none) would cause an
assertion failure if type was exact because .with() would only
replace the heap type and exact references to basic heap types are
disallowed.

Rather than checking for and avoiding this error in all the callers,
simply drop exactness when .with() is called with a basic heap type.
This is reasonable behavior because the only alternative is never
correct.

Add a test that hits an assertion failure without this fix.
AbstractTypeRefining replaces a defined type with none and the type
updating utility does not check whether the new heap type is basic
before doing the replacement.

tlively added 2 commits April 24, 2025 18:52
Use the standard utility rather than reimplementing type intersection.
The new code is simpler, shorter, and properly supports exactness,
avoiding an assertion failure in the added test case. The other
functional change is that when one of the intersected heap types is
bottom and the type GLB is a non-nullable reference to bottom, the
result of the intersection is `None` where it was previously a `Cone`.
Previously doing e.g. `type.with(HeapType::none)` would cause an
assertion failure if `type` was exact because `.with()` would only
replace the heap type and exact references to basic heap types are
disallowed.

Rather than checking for and avoiding this error in all the callers,
simply drop exactness when `.with()` is called with a basic heap type.
This is reasonable behavior because the only alternative is never
correct.

Add a test that hits an assertion failure without this fix.
AbstractTypeRefining replaces a defined type with `none` and the type
updating utility does not check whether the new heap type is basic
before doing the replacement.
@tlively tlively requested a review from kripken April 25, 2025 04:46
@@ -419,7 +419,9 @@ class Type {

// Return a new reference type with some part updated to the specified value.
Type with(HeapType heapType) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a comment about basic types and exactness here I think.

Base automatically changed from gufa-intersect-glb to main April 28, 2025 22:13
@tlively tlively enabled auto-merge (squash) April 29, 2025 19:07
@tlively tlively merged commit ad4672e into main Apr 29, 2025
14 checks passed
@tlively tlively deleted the with-basic-inexact branch April 29, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants