Skip to content

Commit 551b464

Browse files
Emil EjbyfeldtWojciechMazur
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. [Cherry-picked c2ef180]
1 parent 503232a commit 551b464

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
@@ -7022,25 +7022,20 @@ object Types extends TypeUtils {
70227022
}
70237023

70247024
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
7025-
var seen = util.HashSet[Type](initialCapacity = 8)
70267025
def apply(n: Int, tp: Type): Int =
7027-
if seen.contains(tp) then n
7028-
else {
7029-
seen += tp
7030-
tp match {
7031-
case tp: AppliedType =>
7032-
val tpNorm = tp.tryNormalize
7033-
if tpNorm.exists then apply(n, tpNorm)
7034-
else foldOver(n + 1, tp)
7035-
case tp: RefinedType =>
7036-
foldOver(n + 1, tp)
7037-
case tp: TypeRef if tp.info.isTypeAlias =>
7038-
apply(n, tp.superType)
7039-
case tp: TypeParamRef =>
7040-
apply(n, TypeComparer.bounds(tp))
7041-
case _ =>
7042-
foldOver(n, tp)
7043-
}
7026+
tp match {
7027+
case tp: AppliedType =>
7028+
val tpNorm = tp.tryNormalize
7029+
if tpNorm.exists then apply(n, tpNorm)
7030+
else foldOver(n + 1, tp)
7031+
case tp: RefinedType =>
7032+
foldOver(n + 1, tp)
7033+
case tp: TypeRef if tp.info.isTypeAlias =>
7034+
apply(n, tp.superType)
7035+
case tp: TypeParamRef =>
7036+
apply(n, TypeComparer.bounds(tp))
7037+
case _ =>
7038+
foldOver(n, tp)
70447039
}
70457040
}
70467041

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)