Skip to content

Commit

Permalink
Revert "remove normalize and rely on stackoverflow" because test slow…
Browse files Browse the repository at this point in the history
…down

This reverts commit 2f03f86.
  • Loading branch information
aherlihy committed Jan 13, 2025
1 parent be88246 commit f54f5d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/dotc/core/TypeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,22 @@ class TypeUtils:
case Some(types) => TypeOps.nestedPairs(types)
case None => throw new AssertionError("not a tuple")

def namedTupleElementTypesUpTo(bound: Int, derived: Boolean)(using Context): List[(TermName, Type)] =
self.normalized.dealias match
// for desugaring, ignore derived types to avoid infinite recursion in NamedTuple.unapply
def namedTupleElementTypesUpTo(bound: Int, derived: Boolean, normalize: Boolean = true)(using Context): List[(TermName, Type)] =
(if normalize then self.normalized else self).dealias match
// for desugaring and printer, ignore derived types to avoid infinite recursion in NamedTuple.unapply
case AppliedType(tycon, nmes :: vals :: Nil) if !derived && tycon.typeSymbol == defn.NamedTupleTypeRef.symbol =>
val names = nmes.tupleElementTypesUpTo(bound).getOrElse(Nil).map(_.dealias).map:
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map(_.dealias).map:
case ConstantType(Constant(str: String)) => str.toTermName
case t => throw TypeError(em"Malformed NamedTuple: names must be string types, but $t was found.")
val values = vals.tupleElementTypesUpTo(bound, true).getOrElse(Nil)
val values = vals.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil)
names.zip(values)
case t if !derived => Nil
// default cause, used for post-typing
case defn.NamedTuple(nmes, vals) if derived =>
val names = nmes.tupleElementTypesUpTo(bound).getOrElse(Nil).map(_.dealias).map:
case defn.NamedTuple(nmes, vals) =>
val names = nmes.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil).map(_.dealias).map:
case ConstantType(Constant(str: String)) => str.toTermName
case t => throw TypeError(em"Malformed NamedTuple: names must be string types, but $t was found.")
val values = vals.tupleElementTypesUpTo(bound, derived).getOrElse(Nil)
val values = vals.tupleElementTypesUpTo(bound, normalize).getOrElse(Nil)
names.zip(values)
case t =>
Nil
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
def appliedText(tp: Type): Text = tp match
case tp @ AppliedType(tycon, args) =>
val namedElems =
try tp.namedTupleElementTypesUpTo(200, true)
try tp.namedTupleElementTypesUpTo(200, false, normalize = false)
catch
case ex: TypeError => Nil
case ex: StackOverflowError => Nil
if namedElems.nonEmpty then
toTextNamedTuple(namedElems)
else tp.tupleElementTypesUpTo(200, normalize = false) match
Expand Down

0 comments on commit f54f5d3

Please sign in to comment.