Skip to content

Commit 1a5a8b3

Browse files
committed
Revert "remove normalize and rely on stackoverflow" because test slowdown
This reverts commit 2f03f86.
1 parent 2f03f86 commit 1a5a8b3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,22 @@ class TypeUtils:
127127
case Some(types) => TypeOps.nestedPairs(types)
128128
case None => throw new AssertionError("not a tuple")
129129

130-
def namedTupleElementTypesUpTo(bound: Int, derived: Boolean)(using Context): List[(TermName, Type)] =
131-
self.normalized.dealias match
132-
// for desugaring, ignore derived types to avoid infinite recursion in NamedTuple.unapply
130+
def namedTupleElementTypesUpTo(bound: Int, derived: Boolean, normalize: Boolean = true)(using Context): List[(TermName, Type)] =
131+
(if normalize then self.normalized else self).dealias match
132+
// for desugaring and printer, ignore derived types to avoid infinite recursion in NamedTuple.unapply
133133
case AppliedType(tycon, nmes :: vals :: Nil) if !derived && tycon.typeSymbol == defn.NamedTupleTypeRef.symbol =>
134-
val names = nmes.tupleElementTypesUpTo(bound).getOrElse(Nil).map(_.dealias).map:
134+
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map(_.dealias).map:
135135
case ConstantType(Constant(str: String)) => str.toTermName
136136
case t => throw TypeError(em"Malformed NamedTuple: names must be string types, but $t was found.")
137-
val values = vals.tupleElementTypesUpTo(bound, true).getOrElse(Nil)
137+
val values = vals.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil)
138138
names.zip(values)
139+
case t if !derived => Nil
139140
// default cause, used for post-typing
140-
case defn.NamedTuple(nmes, vals) if derived =>
141-
val names = nmes.tupleElementTypesUpTo(bound).getOrElse(Nil).map(_.dealias).map:
141+
case defn.NamedTuple(nmes, vals) =>
142+
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map(_.dealias).map:
142143
case ConstantType(Constant(str: String)) => str.toTermName
143144
case t => throw TypeError(em"Malformed NamedTuple: names must be string types, but $t was found.")
144-
val values = vals.tupleElementTypesUpTo(bound, derived).getOrElse(Nil)
145+
val values = vals.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil)
145146
names.zip(values)
146147
case t =>
147148
Nil

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
248248
def appliedText(tp: Type): Text = tp match
249249
case tp @ AppliedType(tycon, args) =>
250250
val namedElems =
251-
try tp.namedTupleElementTypesUpTo(200, true)
251+
try tp.namedTupleElementTypesUpTo(200, false, normalize = false)
252252
catch
253253
case ex: TypeError => Nil
254-
case ex: StackOverflowError => Nil
255254
if namedElems.nonEmpty then
256255
toTextNamedTuple(namedElems)
257256
else tp.tupleElementTypesUpTo(200, normalize = false) match

0 commit comments

Comments
 (0)