-
Notifications
You must be signed in to change notification settings - Fork 443
Fix PoI + forwarding candidate order #28342
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
Open
DanilaFe
wants to merge
11
commits into
chapel-lang:main
Choose a base branch
from
DanilaFe:poi-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Danila Fedorin <[email protected]>
This helps make the data flow more explicit and bundle repeated arguments. Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Signed-off-by: Danila Fedorin <[email protected]>
Suppose there's a forwarding chain A -> B -> C. Previously, because only a 'considerPoi' flag was used, the search pattern was roughly like this: * Search for type A candidates (non-POI) * Search for type B candidates (non-POI) * Search tor type C candidates (non-POI) * Search for type A POI candidates * Search for type B candidates (non-POI, because POI search entails non-POI search) * Search for type A candidates (non-POI) * Search for type B POI candidates * Search for type A candidates (non-POI, because POI search entails non-POI search) * Search for Type A POI candidates Basically, because 'considerPoi' entailed a superset of work that '!considerPoi' did, we often duplicated effort. I suspect that this duplication is exponential in the length of the forwarding chain. To fix this, adjust 'considerPoi' to instead be tri-state: default (poi and non-poi), non-poi-only, and poi-only. This way, we can proceed as: * Search for type A candidates (non-POI) * Search for type B candidates (non-POI) * Search tor type C candidates (non-POI) * Search for type A POI candidates * Search for type B POI candidates (because POI-only is set) * Search for Type C POI candidates (because POI-only is set) This is exactly the search set we desire, without repetition. Signed-off-by: Danila Fedorin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #28246 by untangling forwarding from POI.
Closes #28354 by making speculatively resolved calls still count for POI caching.
Consider the program from that issue:
While previously, forwarding and POI would be interleaved as follows:
Old Ordering:
Outermost.Outermost.Outer.Outer.InnerInner.After this PR, they will be interleaved as follows:
New Ordering:
Outermost.Outer.InnerOutermost.Outer.Inner.This ensures that user code cannot "hijack" library procedures by defining POI overloads for types like
Outermost, where previously the type forwarded this method fromInner. It also ensures that POI scopes are attempted only if the call would not have otherwise resolved, since this is required for caching instantiations.There are effectively 4 phases to the new resolution strategy:
Outermost(`searchOnePoiLevelOutermost(resolveForwardedCall(considerPOI=false))Outermost(findVisibleFunctionsAndCandidates)Outermost(resolveForwardedCall(considerPOI=true))When implementing this, I noticed that we had several functions that threaded through much state. These functions had to be split and interleaved with forwarding handling, which would've required more state to be lifted to the top-level
resolveNormalCallfunction and threaded through. Instead of doing so, I consolidated all the shared state into a new struct,CandidateSearchState. I also tried to improve the comments in the affected code, since I found it somewhat difficult to follow at first.The implementation details are as follows. Since
resolveForwardedCallcan recurse (implementing the step fromOutertoInnerabove, allowing for transitive forwards), which it does by callingresolveNormalCall, and since in phase 2 it is too early to consult POIs, I needed to adjustresolveNormalCallto enable it to ignore POI when needed. Furthermore, since we did want a POI candidate search for forwards eventually (phase 4), I also needed to allowresolveForwardedCallto request POI candidates after all. This led to me threading throughconsiderPoiboolean arguments to both of these functions.