-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement avoid in terms of AproximatingTypeMap #2945
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1f04bba
Factor out variance manipulation in TypeMap and TypeAccumulator
odersky 104516b
Fix derivedRefinedType in ApproximatingTypeMap
odersky 8d17f57
Add comment explaining approximating derivedAppliedType
odersky 6e08737
Polishings and more comments
odersky 826c96f
Fix review comments re homogenizedArg
odersky 46a462b
Address reviewers comments
odersky dbd2e2c
Drop unused field `unsafeNonvariant`
odersky bc5cbb0
Fix typo
odersky b27dadc
Fix derivedSelect in avoid
odersky 491fe97
Avoid double avoidance when typing blocks
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ trait TypeAssigner { | |
val parentType = info.parentsWithArgs.reduceLeft(ctx.typeComparer.andType(_, _)) | ||
def addRefinement(parent: Type, decl: Symbol) = { | ||
val inherited = | ||
parentType.findMember(decl.name, info.cls.thisType, Private) | ||
parentType.findMember(decl.name, info.cls.thisType, excluded = Private) | ||
.suchThat(decl.matches(_)) | ||
val inheritedInfo = inherited.info | ||
if (inheritedInfo.exists && decl.info <:< inheritedInfo && !(inheritedInfo <:< decl.info)) { | ||
|
@@ -88,7 +88,7 @@ trait TypeAssigner { | |
case info => range(tp.info.bottomType, apply(info)) | ||
} | ||
case tp: TypeRef if toAvoid(tp.symbol) => | ||
val avoided = tp.info match { | ||
tp.info match { | ||
case TypeAlias(alias) => | ||
apply(alias) | ||
case TypeBounds(lo, hi) => | ||
|
@@ -98,7 +98,6 @@ trait TypeAssigner { | |
case _ => | ||
range(tp.bottomType, tp.topType) // should happen only in error cases | ||
} | ||
avoided | ||
case tp: ThisType if toAvoid(tp.cls) => | ||
range(tp.bottomType, apply(classBound(tp.cls.classInfo))) | ||
case tp: TypeVar if ctx.typerState.constraint.contains(tp) => | ||
|
@@ -109,18 +108,26 @@ trait TypeAssigner { | |
mapOver(tp) | ||
} | ||
|
||
/** Two deviations from standard derivedSelect: | ||
* 1. The teh approximation result is a singleton references C#x.type, we | ||
/** Three deviations from standard derivedSelect: | ||
* 1. We first try a widening conversion to the type's info with | ||
* the original prefix. Since the original prefix is known to | ||
* be a subtype of the returned prefix, this can improve results. | ||
* 2. IThen, if the approximation result is a singleton reference C#x.type, we | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: IThen -> Then |
||
* replace by the widened type, which is usually more natural. | ||
* 2. We need to handle the case where the prefix type does not have a member | ||
* named `tp.name` anymmore. | ||
* 3. Finally, we need to handle the case where the prefix type does not have a member | ||
* named `tp.name` anymmore. In that case, we need to fall back to Bot..Top. | ||
*/ | ||
override def derivedSelect(tp: NamedType, pre: Type) = | ||
if (pre eq tp.prefix) tp | ||
else if (tp.isTerm && variance > 0 && !pre.isInstanceOf[SingletonType]) | ||
apply(tp.info.widenExpr) | ||
else if (upper(pre).member(tp.name).exists) super.derivedSelect(tp, pre) | ||
else range(tp.bottomType, tp.topType) | ||
if (pre eq tp.prefix) | ||
tp | ||
else tryWiden(tp, tp.prefix) { | ||
if (tp.isTerm && variance > 0 && !pre.isInstanceOf[SingletonType]) | ||
apply(tp.info.widenExpr) | ||
else if (upper(pre).member(tp.name).exists) | ||
super.derivedSelect(tp, pre) | ||
else | ||
range(tp.bottomType, tp.topType) | ||
} | ||
} | ||
|
||
widenMap(tp) | ||
|
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
Oops, something went wrong.
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.
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.
Could
parent
be used instead oftp.topType
?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.
I added a comment explaining why not:
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.
Would it?
TypeApplications#isHK
only returns true forHKTypeLambda
, and before this PRavoid
used to return the parent for refinement types and it worked fine.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.
Alternatively we could return derivedRefinedType(tp, parent, WildcardType) I think