Skip to content

Commit

Permalink
Devalify: also visitType for New nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBlanvillain committed May 30, 2017
1 parent de4dd2c commit 07a5d89
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/linker/Simplify.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
case _ => fun
}
val constructor = a.symbol.owner.companionClass.primaryConstructor.asTerm
evalReciever(a, rollInArgs(argss.tail, New(a.tpe.widenDealias, constructor, argss.head)))
rollInArgs(argss.tail, New(a.tpe.widenDealias, constructor, argss.head))

// For synthetic dotty unapplies on case classes:
// - CC.unapply(arg): CC → arg
Expand Down Expand Up @@ -1226,9 +1226,11 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
}
visitType(valdef.symbol.info)
case t: New =>
val symIfExists = t.tpt.tpe.normalizedPrefix.termSymbol
val normalized = t.tpt.tpe.normalizedPrefix
val symIfExists = normalized.termSymbol
val b4 = used.getOrElseUpdate(symIfExists, 0)
used.put(symIfExists, b4 + 1)
visitType(normalized)

case valdef: ValDef if valdef.symbol.exists && !valdef.symbol.owner.isClass &&
!valdef.symbol.is(Param | Module | Lazy) =>
Expand Down Expand Up @@ -1279,8 +1281,8 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
// TODO: if a non-synthetic val is duplicate of a synthetic one, rename a synthetic one and drop synthetic flag?

val copiesToReplaceAsUsedOnce =
timesUsed.filter(x => x._2 == 1).
flatMap(x => copies.get(x._1) match {
timesUsed.filter(x => x._2 == 1)
.flatMap(x => copies.get(x._1) match {
case Some(tr) => List((x._1, tr))
case None => Nil
}) -- timesUsedAsType.keySet
Expand All @@ -1289,7 +1291,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {

val deepReplacer = new TreeMap() {
override def transform(tree: Tree)(implicit ctx: Context): Tree = {
def loop(tree: Tree):Tree =
def loop(tree: Tree): Tree =
tree match {
case t: RefTree if replacements.contains(t.symbol) =>
loop(replacements(t.symbol))
Expand Down

0 comments on commit 07a5d89

Please sign in to comment.