Skip to content

Commit

Permalink
Simplifications from review
Browse files Browse the repository at this point in the history
  • Loading branch information
milessabin committed Jan 24, 2019
1 parent cfaf6f0 commit 98a4f14
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import core._
import util.Spans._, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._
import Symbols._, StdNames._, Annotations._, Trees._, Symbols._
import Decorators._, DenotTransformers._
import collection.mutable
import collection.{immutable, mutable}
import util.{Property, SourceFile, NoSource}
import NameKinds.{TempResultName, OuterSelectName}
import typer.ConstFold
Expand Down Expand Up @@ -734,21 +734,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
* Set the owner of every definition in this tree which is not itself contained in this
* tree to be `newowner`
*/
def changeNonLocalOwners(newowner: Symbol)(implicit ctx: Context): Tree = {
val localOwners = mutable.HashSet[Symbol]()
val traverser = new TreeTraverser {

def traverse(tree: Tree)(implicit ctx: Context): Unit = {
tree match {
case _: DefTree => if(tree.symbol ne NoSymbol) localOwners += tree.symbol
case _ => traverseChildren(tree)
}
def changeNonLocalOwners(newOwner: Symbol)(implicit ctx: Context): Tree = {
val ownerAcc = new TreeAccumulator[immutable.Set[Symbol]] {
def apply(ss: immutable.Set[Symbol], tree: Tree)(implicit ctx: Context) = tree match {
case tree: DefTree =>
if (tree.symbol.exists) ss + tree.symbol.owner
else ss
case _ =>
foldOver(ss, tree)
}
}
traverser.traverse(tree)
val nonLocalOwners = localOwners.filter(sym => !localOwners.contains(sym.owner)).toList.map(_.owner)
val newOwners = nonLocalOwners.map(_ => newowner)
new TreeTypeMap(oldOwners = nonLocalOwners, newOwners = newOwners).apply(tree)
val owners = ownerAcc(immutable.Set.empty[Symbol], tree).toList
val newOwners = List.fill(owners.size)(newOwner)
new TreeTypeMap(oldOwners = owners, newOwners = newOwners).apply(tree)
}

/** After phase `trans`, set the owner of every definition in this tree that was formerly
Expand Down

0 comments on commit 98a4f14

Please sign in to comment.