Skip to content

Commit fca51d3

Browse files
dwijnandtgodzik
authored andcommitted
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. [Cherry-picked 28b8c55]
1 parent 308aaef commit fca51d3

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
@@ -917,7 +917,9 @@ object TypeOps:
917917
}
918918

919919
val inferThisMap = new InferPrefixMap
920-
val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds, DepParamName.fresh(tparam.paramName)) }
920+
val tvars = tp1.etaExpand match
921+
case eta: TypeLambda => constrained(eta)
922+
case _ => Nil
921923
val protoTp1 = inferThisMap.apply(tp1).appliedTo(tvars)
922924

923925
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
@@ -4319,9 +4319,11 @@ object Types extends TypeUtils {
43194319

43204320
/** Distributes Lambda inside type bounds. Examples:
43214321
*
4322-
* type T[X] = U becomes type T = [X] -> U
4323-
* type T[X] <: U becomes type T >: Nothing <: ([X] -> U)
4324-
* type T[X] >: L <: U becomes type T >: ([X] -> L) <: ([X] -> U)
4322+
* {{{
4323+
* type T[X] = U becomes type T = [X] =>> U
4324+
* type T[X] <: U becomes type T >: Nothing <: ([X] =>> U)
4325+
* type T[X] >: L <: U becomes type T >: ([X] =>> L) <: ([X] =>> U)
4326+
* }}}
43254327
*
43264328
* The variances of regular TypeBounds types, as well as of match aliases
43274329
* and of opaque aliases are always determined from the given parameters
@@ -4333,13 +4335,15 @@ object Types extends TypeUtils {
43334335
*
43344336
* Examples:
43354337
*
4338+
* {{{
43364339
* type T[X] >: A // X is invariant
43374340
* type T[X] <: List[X] // X is invariant
43384341
* type T[X] = List[X] // X is covariant (determined structurally)
43394342
* opaque type T[X] = List[X] // X is invariant
43404343
* opaque type T[+X] = List[X] // X is covariant
43414344
* type T[A, B] = A => B // A is contravariant, B is covariant (determined structurally)
43424345
* type T[A, +B] = A => B // A is invariant, B is covariant
4346+
* }}}
43434347
*/
43444348
def boundsFromParams[PI <: ParamInfo.Of[TypeName]](params: List[PI], bounds: TypeBounds)(using Context): TypeBounds = {
43454349
def expand(tp: Type, useVariances: Boolean) =

0 commit comments

Comments
 (0)