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.
Consider the program:
The three->way chain is required, because this bug is about collapsing POI scopes.
Basically, by POI, this program resolves:
a(...)is resolved in the scope ofb(…), which is resolved in the scope ofc(…), which has aprivate use Lib. Thus,a(…)has access tooutermost(…).However, we try to avoid building up long chains of POI scopes (a-in-scope-of-b-in-scope-of-c). As an optimization, if one module uses another, and both are in the POI chain, we remove the usee from the POI chain, since anything in its scope will be found via the use. In this case,
BusesC, so we removeCfrom the POI scope lookup chain. Unfortunately, this is not sound, asChas private use ofLib, which does not propagate throughuse C. As a result, the call toamissesoutermost.This PR adjusts the logic of
isWholeScopeVisibleFromScope, which is what used to implement the optimization. In particular, I found it to have two odd behaviorsprivate useissue outlined above: not caring about definitions brought in privately (and thus, not re-exported)use MParent.MChild, whereMParenthad apublic use Lib, was treated as findingLib. However, I don't believe this is accurate. See:This PR reimplements
isWholeScopeVisibleFromScopefrom first principles. I consider two ways for one scope to be wholly visible from another:use Mcan see all ofMbut only ifMdoesn't have private definitions. For example, ifMhas aprivate proc,use Mwill not bring that in, and thus, it's not true that the scope ofMis "fully visible" from the user.use Mcan be transitive; either there's ause Mright in the scope, OR there's ause Intermediate, whereIntermediatehas apublic use M, ORIntermediatehas apublic use OtherIntermediatewhich has apublic use M.... Note that except for the firstuse, all uses must bepublic.To help reduce the impact of this method, I kept it conservative. As a result, I expect
isWholeScopeVisibleFromScopeto now be stricter than it used to be (certainly it is in the buggy case). This technically expanded existing POI chains in some cases and might've affected caching of instantiations. However, I observed no noticeable performance impact from that, either.Testing