-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make polymorphic functions more efficient and expressive #17548
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9af339b
Fix pretty-printing of renamed lambda params
smarter 871e23f
Drop vestigial support for parameterless contextual functions
smarter 9d08db1
Support inferring dependent polymorphic lambdas from the expected type
smarter dbe1831
Implement polymorphic lambdas using Closure nodes for efficiency
smarter 47aed44
Use the same compilation flags in non-bootstrapped and bootstrapped b…
smarter b8adb72
Polymorphic closures cannot have dependencies between value params
smarter d436bd1
Fix meaning of `this` in a polymorphic function type
smarter d7a345f
Fix incorrect "self reference in refinement is deprecated" warning
smarter 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -1692,15 +1692,17 @@ class Namer { typer: Typer => | |
def valOrDefDefSig(mdef: ValOrDefDef, sym: Symbol, paramss: List[List[Symbol]], paramFn: Type => Type)(using Context): Type = { | ||
|
||
def inferredType = inferredResultType(mdef, sym, paramss, paramFn, WildcardType) | ||
lazy val termParamss = paramss.collect { case TermSymbols(vparams) => vparams } | ||
|
||
val tptProto = mdef.tpt match { | ||
case _: untpd.DerivedTypeTree => | ||
WildcardType | ||
case TypeTree() => | ||
checkMembersOK(inferredType, mdef.srcPos) | ||
case DependentTypeTree(tpFun) => | ||
val tpe = tpFun(termParamss.head) | ||
// A lambda has at most one type parameter list followed by exactly one term parameter list. | ||
val tpe = (paramss: @unchecked) match | ||
case TypeSymbols(tparams) :: TermSymbols(vparams) :: Nil => tpFun(tparams, vparams) | ||
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. If we simplify case TypeSymbols(tparams) :: TermSymbols(vparams) :: Nil => tpFun(tparams ++ vparams)
case TermSymbols(vparams) :: Nil => tpFun(vparams) |
||
case TermSymbols(vparams) :: Nil => tpFun(Nil, vparams) | ||
if (isFullyDefined(tpe, ForceDegree.none)) tpe | ||
else typedAheadExpr(mdef.rhs, tpe).tpe | ||
case TypedSplice(tpt: TypeTree) if !isFullyDefined(tpt.tpe, ForceDegree.none) => | ||
|
@@ -1724,7 +1726,8 @@ class Namer { typer: Typer => | |
// So fixing levels at instantiation avoids the soundness problem but apparently leads | ||
// to type inference problems since it comes too late. | ||
if !Config.checkLevelsOnConstraints then | ||
val hygienicType = TypeOps.avoid(rhsType, termParamss.flatten) | ||
val termParams = paramss.collect { case TermSymbols(vparams) => vparams }.flatten | ||
val hygienicType = TypeOps.avoid(rhsType, termParams) | ||
if (!hygienicType.isValueType || !(hygienicType <:< tpt.tpe)) | ||
report.error( | ||
em"""return type ${tpt.tpe} of lambda cannot be made hygienic | ||
|
This file contains 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.
Maybe we simplify this so that a DependentTypeTree just takes a
(tp: List[Symbol] => Type)
?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.
Using a List[Symbol] means that we need to spend extra time concatenating and partitioning the parameters, and we need to document this behavior, so I'm not sure it's really more simple, but I'm happy to do the change if you prefer it that way.
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 agree, in the end it does not seem to be a simplification. So OK to keep as is.
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.
When I started my comment stream I thought it would come out simpler than it did 😄