Skip to content

Commit 6c26344

Browse files
committed
HK reduction: Remove special-case for typerefs
The special case: case stripped: TypeRef => stripped.symbol.is(BaseTypeArg) is wrong because you might still want to reduce applications involving TypeRefs which are not base class parameters, like in: class Foo[A] type Alias[X] = Foo[X] val x: Alias[Int] = ??? `Alias` is a TypeRef so before this commit `Alias[Int]` was never reduced to `Foo[Int]`. It should have been: case stripped: TypeRef if stripped.symbol.is(BaseTypeArg) => true But even this is incorrect: it assumes that we can always safely reduce HK applications involving base class parameters, this is not the case when the parameter kind is different from the rhs kind as illustrated by `i1181c.scala`. We fix this by simply dropping the special case.
1 parent 8375e3a commit 6c26344

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/dotty/tools/dotc/config/Config.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ object Config {
9898
final val splitProjections = false
9999

100100
/** If this flag is on, always rewrite an application `S[Ts]` where `S` is an alias for
101-
* `[Xs] -> U` to `[Xs := Ts]U`. If this flag is off, the rewriting is only done if `S` is a
102-
* reference to an instantiated parameter. Turning this flag on was observed to
103-
* give a ~6% speedup on the JUnit test suite.
101+
* `[Xs] -> U` to `[Xs := Ts]U`.
102+
* Turning this flag on was observed to give a ~6% speedup on the JUnit test suite.
104103
*/
105104
final val simplifyApplications = true
106105

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,13 @@ class TypeApplications(val self: Type) extends AnyVal {
470470
case dealiased: TypeLambda =>
471471
def tryReduce =
472472
if (!args.exists(_.isInstanceOf[TypeBounds])) {
473-
val followAlias = stripped match {
474-
case stripped: TypeRef =>
475-
stripped.symbol.is(BaseTypeArg)
476-
case _ =>
477-
Config.simplifyApplications && {
478-
dealiased.resType match {
479-
case AppliedType(tyconBody, _) =>
480-
variancesConform(typParams, tyconBody.typeParams)
481-
// Reducing is safe for type inference, as kind of type constructor does not change
482-
case _ => false
483-
}
484-
}
473+
val followAlias = Config.simplifyApplications && {
474+
dealiased.resType match {
475+
case AppliedType(tyconBody, _) =>
476+
variancesConform(typParams, tyconBody.typeParams)
477+
// Reducing is safe for type inference, as kind of type constructor does not change
478+
case _ => false
479+
}
485480
}
486481
if ((dealiased eq stripped) || followAlias) dealiased.instantiate(args)
487482
else HKApply(self, args)

tests/pos/i1181c.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Foo[A]
2+
3+
trait Bar[DD[_,_]] {
4+
val x: DD[Int, Int]
5+
}
6+
7+
trait Baz extends Bar[[X,Y] -> Foo[X]] {
8+
def foo[M[_,_]](x: M[Int, Int]) = x
9+
10+
foo(x)
11+
}

0 commit comments

Comments
 (0)