Dyno: implement field access promotion #26945
Merged
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.
Closes https://github.com/Cray/chapel-private/issues/7227.
This PR implements field access promotion; that is, we can now resolve code like this:
I ran into issues implementing this naively, and took a look at how production does this. However, as I discovered in #26938, production doesn't implement this feature properly, either!
In both Dyno and production, fields are accessed using their "getters". From there, promotion works the same as it does with anything else (by finding methods that apply to the element type, and creating wrappers). The crux of the issue is that we need to "discover" the getters in the current scope. Production does this incorrectly: it searches the scope in which the promotion would occur, and it searches the scope of the receiver. However, it does not search the scopes of the scalar elements. This leads to the bug discoveed in 26938.
The proper way to handle this situation is to find and check the scopes of the scalar types. However, to do this, we need to know the scalar types! This requires us to resole
chpl__promotionType
. The PR does just that: if we can't find regular candidates, and if we can't find forwarded methods, for parenless method calls, it computes the receiver's scalar type and searches it for receiver scopes.This leads to problem with recursion. In general, we always try to firs resolve code like
x.foo()
as(x.foo)()
, which means we try to findfoo
as a field. This often does not succeed (particularly ifx.foo
is a function). However,x.foo
matches all the conditions in the preceding paragraph. This means that, naively, we end up with recursion as follows;chpl__promotionType
methodthis.isRectangular()
)this.isRectangular
as a field, and we don't find it.this.isRectangular
in the scalar types, which requires resolvingchpl__promotionType
.This PR takes the "naive" approach that we take elsewhere: using
isQueryRunning
. Notably, there is an open concern withisQueryRunning
as a whole, well-documented in #26459. However, a "proper" resolution to this issue would be very involved or very performance-heavy.Reviewed by @benharsh -- thanks!
Testing