-
Notifications
You must be signed in to change notification settings - Fork 420
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
dyno: Support non-local receivers and improve resolution of type queries #26038
dyno: Support non-local receivers and improve resolution of type queries #26038
Conversation
d9228b5
to
2b9ea9c
Compare
2b9ea9c
to
6f7a8bc
Compare
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.
My only concern is that, perhaps, we can get the resolver to work more with ReceiverScopeTypedHelper / TypedMethodLookupHelper. The scope resolution process works with these so that it doesn't even need to think about the "closest" method receiver. That should not be relevant to the process.
That said, I think this PR has some good cleanups and gets some more cases working, so we can proceed with it.
// TODO: Is it even legal to reference fields from two different | ||
// receivers? Shouldn't we run into a 'NestedClassFieldRef' error? | ||
// Also, if they were two different instantiations of the same | ||
// composite then this check would be insufficient. |
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 consider making this a full-on error for now. Would that break tests in production?
frontend/lib/resolution/Resolver.cpp
Outdated
ReceiverScopeTypedHelper(fn->id(), std::move(receiverType)); | ||
receiverScopeHelper = &receiverScopeTypedHelper; | ||
} | ||
// barrier to only compute the receiver scopes once |
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.
fwiw, I wouldn't use the term "barrier" here since it means something specific (and different) in parallel computing. IMO the comment could just be "only compute the receiver scopes once".
frontend/lib/resolution/Resolver.cpp
Outdated
@@ -775,39 +712,100 @@ const MethodLookupHelper* Resolver::getFieldDeclarationLookupHelper() { | |||
return nullptr; | |||
} | |||
|
|||
if (!methodHelperComputed) { | |||
methodLookupHelper = nullptr; | |||
// barrier to only compute the lookup helper once |
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.
ditto
Do you mean that maybe we can have those types themselves compute the closest method receiver? I think something will have to walk the stack in some way at some point to get at the types, but I'm not picky about what does it. |
It's more that even the idea of whether or not the "closest method receiver" is relevant (vs all method receivers) should be up to the scope lookup code (according to |
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
Signed-off-by: David Longnecker <[email protected]>
6f7a8bc
to
d39f2ed
Compare
This PR adds support for non-local receivers to dyno and fixes a bug affecting the resolution of type queries. It adds support for programs like the following:
Refactor the
Resolver::methodReceiverType()
method to make use of a new methodclosestMethodReceiverInfo()
. RemovegetMethodReceiver
and streamline how receiver information is computed. When resolving, try to compute a local method receiver using whatever means are available. If that fails, consult stack frames for the first method that lexically encloses the current symbol and use its receiver instead.In
getMethodReceiverScopeHelper()
and friend, flatten out the branches used to make the function idempotent and to handlescopeResolveOnly
. This makes the typed path for setting up the helper easier to digest.Fix a bug in type query resolution that caused every call to be treated as though it were a type constructor for a composite type. To do this, compute if type queries are present in children in
Resolver::resolveTypeQueries
and do nothing if they are not. Secondly, rely on theResolver::signatureOnly
flag to avoid emitting errors unless we are resolving a signature and have access to the types of sub-expressions.Reviewed by @mppf. Thanks!