Skip to content

Commit 2193100

Browse files
authored
Merge pull request #1400 from dotty-staging/fix/hk-reduce-typerefs
HK reduction: Remove special-case for typerefs
2 parents 5d6c102 + 6c26344 commit 2193100

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-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/i1181b.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+
object Test {
4+
def foo[M[_,_]](x: M[Int,Int]) = x
5+
6+
type Alias[X,Y] = Foo[X]
7+
val x: Alias[Int,Int] = new Foo[Int]
8+
9+
foo[Alias](x) // ok
10+
foo(x)
11+
}

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)