Skip to content

Commit 7a94718

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 c0bdc56 commit 7a94718

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
@@ -6974,25 +6974,20 @@ object Types extends TypeUtils {
69746974
}
69756975

69766976
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
6977-
var seen = util.HashSet[Type](initialCapacity = 8)
69786977
def apply(n: Int, tp: Type): Int =
6979-
if seen.contains(tp) then n
6980-
else {
6981-
seen += tp
6982-
tp match {
6983-
case tp: AppliedType =>
6984-
val tpNorm = tp.tryNormalize
6985-
if tpNorm.exists then apply(n, tpNorm)
6986-
else foldOver(n + 1, tp)
6987-
case tp: RefinedType =>
6988-
foldOver(n + 1, tp)
6989-
case tp: TypeRef if tp.info.isTypeAlias =>
6990-
apply(n, tp.superType)
6991-
case tp: TypeParamRef =>
6992-
apply(n, TypeComparer.bounds(tp))
6993-
case _ =>
6994-
foldOver(n, tp)
6995-
}
6978+
tp match {
6979+
case tp: AppliedType =>
6980+
val tpNorm = tp.tryNormalize
6981+
if tpNorm.exists then apply(n, tpNorm)
6982+
else foldOver(n + 1, tp)
6983+
case tp: RefinedType =>
6984+
foldOver(n + 1, tp)
6985+
case tp: TypeRef if tp.info.isTypeAlias =>
6986+
apply(n, tp.superType)
6987+
case tp: TypeParamRef =>
6988+
apply(n, TypeComparer.bounds(tp))
6989+
case _ =>
6990+
foldOver(n, tp)
69966991
}
69976992
}
69986993

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)