Skip to content

Commit c2ef180

Browse files
Emil Ejbyfeldteejbyfeldt
authored andcommitted
Remove seen from TypeSizeAccumulator
This fixes #15692 and does not seem to break an existing compilation tests. The problem with seen when it comes #15692 is that seen means that type that has repeated types will get a lower size and this incorrectly triggers the divergence check since some of the steps involved less repeated types. The seen logic was introduced in #6329 and the motivation was to deal with F-bounds. Since not tests fail it not clear if this logic is still needed to deal with F-bounds? If it is still needed we can add a test and instead of removing the seen logic we can make it track only types the appear as a bound and could cause infinite recursion instead of tracking all.
1 parent dc08b6b commit c2ef180

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7044,25 +7044,20 @@ object Types extends TypeUtils {
70447044
}
70457045

70467046
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
7047-
var seen = util.HashSet[Type](initialCapacity = 8)
70487047
def apply(n: Int, tp: Type): Int =
7049-
if seen.contains(tp) then n
7050-
else {
7051-
seen += tp
7052-
tp match {
7053-
case tp: AppliedType =>
7054-
val tpNorm = tp.tryNormalize
7055-
if tpNorm.exists then apply(n, tpNorm)
7056-
else foldOver(n + 1, tp)
7057-
case tp: RefinedType =>
7058-
foldOver(n + 1, tp)
7059-
case tp: TypeRef if tp.info.isTypeAlias =>
7060-
apply(n, tp.superType)
7061-
case tp: TypeParamRef =>
7062-
apply(n, TypeComparer.bounds(tp))
7063-
case _ =>
7064-
foldOver(n, tp)
7065-
}
7048+
tp match {
7049+
case tp: AppliedType =>
7050+
val tpNorm = tp.tryNormalize
7051+
if tpNorm.exists then apply(n, tpNorm)
7052+
else foldOver(n + 1, tp)
7053+
case tp: RefinedType =>
7054+
foldOver(n + 1, tp)
7055+
case tp: TypeRef if tp.info.isTypeAlias =>
7056+
apply(n, tp.superType)
7057+
case tp: TypeParamRef =>
7058+
apply(n, TypeComparer.bounds(tp))
7059+
case _ =>
7060+
foldOver(n, tp)
70667061
}
70677062
}
70687063

tests/pos/i15692.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sealed trait Nat
2+
sealed trait Succ[Prev <: Nat] extends Nat
3+
sealed trait Zero extends Nat
4+
5+
class Sum[M <: Nat, N <: Nat] {
6+
type Out <: Nat
7+
}
8+
9+
object Sum {
10+
type Aux[M <: Nat, N <: Nat, R <: Nat] = Sum[M, N] { type Out = R }
11+
12+
implicit def sum0[N <: Nat]: Sum.Aux[Zero, N, N] = new Sum[Zero, N] { type Out = N }
13+
implicit def sum1[M <: Nat, N <: Nat, R <: Nat](implicit sum: Sum.Aux[M, Succ[N], R]): Sum.Aux[Succ[M], N, R] =
14+
new Sum[Succ[M], N] { type Out = R }
15+
}
16+
17+
object Test {
18+
def main(args: Array[String]): Unit = {
19+
type _3 = Succ[Succ[Succ[Zero]]]
20+
type _5 = Succ[Succ[_3]]
21+
22+
implicitly[Sum[_3, _5]]
23+
}
24+
}

0 commit comments

Comments
 (0)