From d42301effb84347cf60aae0b1a249ca2f4c826d7 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 17 Jul 2023 22:42:38 +0100 Subject: [PATCH] Move comment for stripLazyRef usage --- .../src/dotty/tools/dotc/core/TypeComparer.scala | 13 ------------- compiler/src/dotty/tools/dotc/core/Types.scala | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 0d2307cd8178..db1bf85ade93 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -3248,19 +3248,6 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { MatchTypeTrace.noInstance(scrut, cas, fails) NoType case MatchResult.Reduced(tp) => - // A recursive match type will have the recursive call - // wrapped in a LazyRef. For example in i18175, the recursive calls - // to IsPiped within the definition of IsPiped are all wrapped in LazyRefs. - // In addition to that, TypeMaps, such as the one that backs TypeOps.simplify, - // by default will rewrap a LazyRef when applying its function. - // The result of those two things means that given a big enough input - // that recursive enough times through one or multiple match types, - // reducing and simplifying the result of the case bodies, - // can end up with a large stack of directly-nested lazy refs. - // And if that nesting level breaches `Config.LogPendingSubTypesThreshold`, - // then TypeComparer will eventually start returning `false` for `isSubType`. - // Or, under -Yno-deep-subtypes, start throwing AssertionErrors. - // So, we eagerly strip that lazy ref here to avoid the stacking. tp.simplified case Nil => val casesText = MatchTypeTrace.noMatchesText(scrut, cases) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 47c44d0786a0..50ef65b3327a 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1985,8 +1985,19 @@ object Types { * except for replacing type parameters with associated type variables. */ def simplified(using Context): Type = - // stripping LazyRef is important for the reduction of applied match types - // see the comment in matchCases/recur for more details + // A recursive match type will have the recursive call + // wrapped in a LazyRef. For example in i18175, the recursive calls + // to IsPiped within the definition of IsPiped are all wrapped in LazyRefs. + // In addition to that, TypeMaps, such as the one that backs TypeOps.simplify, + // by default will rewrap a LazyRef when applying its function. + // The result of those two things means that given a big enough input + // that recursive enough times through one or multiple match types, + // reducing and simplifying the result of the case bodies, + // can end up with a large stack of directly-nested lazy refs. + // And if that nesting level breaches `Config.LogPendingSubTypesThreshold`, + // then TypeComparer will eventually start returning `false` for `isSubType`. + // Or, under -Yno-deep-subtypes, start throwing AssertionErrors. + // So, we eagerly strip that lazy ref here to avoid the stacking. val tp = stripLazyRef TypeOps.simplify(tp, null)