Skip to content

Commit 28b8c55

Browse files
committed
Optimise refineUsingParent to use constrained
Using `constrained` on a TypeLambda means adding one TypeLambda for all the type parameters in tp1, while newTypeVar creates a TypeLambda for each type parameter.
1 parent 8d612de commit 28b8c55

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,9 @@ object TypeOps:
902902
}
903903

904904
val inferThisMap = new InferPrefixMap
905-
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds, DepParamName.fresh(tparam.paramName)) }
905+
val tvars = tp1.etaExpand match
906+
case eta: TypeLambda => constrained(eta)
907+
case _ => Nil
906908
val protoTp1 = inferThisMap.apply(tp1).appliedTo(tvars)
907909

908910
if gadtSyms.nonEmpty then

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4395,9 +4395,11 @@ object Types extends TypeUtils {
43954395

43964396
/** Distributes Lambda inside type bounds. Examples:
43974397
*
4398-
* type T[X] = U becomes type T = [X] -> U
4399-
* type T[X] <: U becomes type T >: Nothing <: ([X] -> U)
4400-
* type T[X] >: L <: U becomes type T >: ([X] -> L) <: ([X] -> U)
4398+
* {{{
4399+
* type T[X] = U becomes type T = [X] =>> U
4400+
* type T[X] <: U becomes type T >: Nothing <: ([X] =>> U)
4401+
* type T[X] >: L <: U becomes type T >: ([X] =>> L) <: ([X] =>> U)
4402+
* }}}
44014403
*
44024404
* The variances of regular TypeBounds types, as well as of match aliases
44034405
* and of opaque aliases are always determined from the given parameters
@@ -4409,13 +4411,15 @@ object Types extends TypeUtils {
44094411
*
44104412
* Examples:
44114413
*
4414+
* {{{
44124415
* type T[X] >: A // X is invariant
44134416
* type T[X] <: List[X] // X is invariant
44144417
* type T[X] = List[X] // X is covariant (determined structurally)
44154418
* opaque type T[X] = List[X] // X is invariant
44164419
* opaque type T[+X] = List[X] // X is covariant
44174420
* type T[A, B] = A => B // A is contravariant, B is covariant (determined structurally)
44184421
* type T[A, +B] = A => B // A is invariant, B is covariant
4422+
* }}}
44194423
*/
44204424
def boundsFromParams[PI <: ParamInfo.Of[TypeName]](params: List[PI], bounds: TypeBounds)(using Context): TypeBounds = {
44214425
def expand(tp: Type, useVariances: Boolean) =

0 commit comments

Comments
 (0)