Skip to content

Commit 23e4361

Browse files
committed
Dedupe/refactor in SpecializeTuples
1 parent 49e9d67 commit 23e4361

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

compiler/src/dotty/tools/dotc/transform/SpecializeTuples.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ class SpecializeTuples extends MiniPhase:
2424
override def transformApply(tree: Apply)(using Context): Tree = tree match
2525
case Apply(TypeApply(fun: NameTree, targs), args)
2626
if fun.name == nme.apply && fun.symbol.exists && defn.isSpecializableTuple(fun.symbol.owner.companionClass, targs.map(_.tpe)) =>
27-
Apply(Select(New(defn.SpecialisedTuple(fun.symbol.owner.companionClass, targs.map(_.tpe)).typeRef), nme.CONSTRUCTOR), args).withType(tree.tpe)
27+
cpy.Apply(tree)(Select(New(defn.SpecialisedTuple(fun.symbol.owner.companionClass, targs.map(_.tpe)).typeRef), nme.CONSTRUCTOR), args).withType(tree.tpe)
2828
case Apply(TypeApply(fun: NameTree, targs), args)
2929
if fun.name == nme.CONSTRUCTOR && fun.symbol.exists && defn.isSpecializableTuple(fun.symbol.owner, targs.map(_.tpe)) =>
30-
Apply(Select(New(defn.SpecialisedTuple(fun.symbol.owner, targs.map(_.tpe)).typeRef), nme.CONSTRUCTOR), args).withType(tree.tpe)
30+
cpy.Apply(tree)(Select(New(defn.SpecialisedTuple(fun.symbol.owner, targs.map(_.tpe)).typeRef), nme.CONSTRUCTOR), args).withType(tree.tpe)
3131
case _ => tree
3232
end transformApply
3333

3434
override def transformSelect(tree: Select)(using Context): Tree = tree match
35-
case Select(qual, nme._1) if qual.tpe.widen.match
36-
case AppliedType(tycon, args) => defn.isSpecializableTuple(tycon.classSymbol, args)
37-
case _ => false
35+
case Select(qual, nme._1) if isAppliedSpecializableTuple(qual.tpe.widen)
3836
=> Select(qual, nme._1.specializedName(qual.tpe.widen.argInfos.slice(0, 1)))
39-
case Select(qual, nme._2) if qual.tpe.widen.match
40-
case AppliedType(tycon, args) => defn.isSpecializableTuple(tycon.classSymbol, args)
41-
case _ => false
37+
case Select(qual, nme._2) if isAppliedSpecializableTuple(qual.tpe.widen)
4238
=> Select(qual, nme._2.specializedName(qual.tpe.widen.argInfos.slice(1, 2)))
4339
case _ => tree
40+
41+
private def isAppliedSpecializableTuple(tp: Type)(using Context) = tp match
42+
case AppliedType(tycon, args) => defn.isSpecializableTuple(tycon.classSymbol, args)
43+
case _ => false
4444
end SpecializeTuples
4545

4646
object SpecializeTuples:

0 commit comments

Comments
 (0)