-
Notifications
You must be signed in to change notification settings - Fork 746
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
Ensure symmetric results in PossibleConstantValues #4662
Conversation
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.
LGTM, although I guess we will have to update this code somehow if we remove func <: any
and end up with multiple unrelated nulls.
Is |
auto type = getConstantLiteral().type.getHeapType(); | ||
auto otherType = other.getConstantLiteral().type.getHeapType(); | ||
auto lub = HeapType::getLeastUpperBound(type, otherType); |
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.
Can we directly use Type::getLeastUpperBound
?
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.
We can, but I think the clearer thing is to LUB on the heap type, because nullability is not relevant here... but maybe the real issue here is that makeNull
gets a type and not a heap type - if it got a heap type then we wouldn't have two options here, which seems better. Let me look into that as a refactor PR.
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.
Both of the types are null at this point. Doesn't that mean both types are nullable anyway here?
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.
Yes, exactly, the types must be nullable anyhow. So we really just need the least upper bound of the heap type, which is the only thing that can be different between them.
After #4664 the code here will be something like this, which I think is good:
auto lub = HeapType::getLeastUpperBound(type, otherType)
if (lub != type) {
value = Literal::makeNull(lub);
return true;
}
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.
Updated after that PR landed.
Yep, we decided to make |
Previously we could return different results depending on the order we
noted things:
This is correct, as nulls are equal anyhow, and any could be used in
the location we are optimizing. However, it can lead to nondeterminism
if the caller's order of notes is nondeterministic. That is the case in
DeadArgumentElimination, where we scan functions in parallel, then
merge them without special ordering.
To fix this, make the note operation symmetric. That seems simplest and
least likely to be confusing. We can use the LUB to do that.
To avoid duplicating the null logic, refactor
note()
to usecombine()
.