Skip to content

Fix #3721: Roll back SubstMap functionality into general TreeTypeMap #3868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Types._, Contexts._, Constants._, Names._, Flags._
import SymDenotations._, Symbols._, Annotations._, Trees._, Symbols._
import Denotations._, Decorators._
import dotty.tools.dotc.transform.SymUtils._
import core.tasty.TreePickler.Hole

/** A map that applies three functions and a substitution together to a tree and
* makes sure they are coordinated so that the result is well-typed. The functions are
Expand Down Expand Up @@ -115,6 +116,8 @@ class TreeTypeMap(
val guard1 = tmap.transform(guard)
val rhs1 = tmap.transform(rhs)
cpy.CaseDef(cdef)(pat1, guard1, rhs1)
case Hole(n, args) =>
Hole(n, args.mapConserve(transform)).withPos(tree.pos).withType(mapType(tree.tpe))
case tree1 =>
super.transform(tree1)
}
Expand Down Expand Up @@ -154,7 +157,7 @@ class TreeTypeMap(
assert(!to.exists(substFrom contains _))
assert(!from.exists(newOwners contains _))
assert(!to.exists(oldOwners contains _))
newMap(
new TreeTypeMap(
typeMap,
treeMap,
from ++ oldOwners,
Expand All @@ -163,16 +166,6 @@ class TreeTypeMap(
to ++ substTo)
}

/** A new map of the same class this one */
protected def newMap(
typeMap: Type => Type,
treeMap: Tree => Tree,
oldOwners: List[Symbol],
newOwners: List[Symbol],
substFrom: List[Symbol],
substTo: List[Symbol])(implicit ctx: Context) =
new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)

/** Apply `typeMap` and `ownerMap` to given symbols `syms`
* and return a treemap that contains the substitution
* between original and mapped symbols.
Expand Down
29 changes: 1 addition & 28 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
var enteredSyms: List[Symbol] = Nil
}

/** A tree substituter that also works for holes */
class SubstMap(
typeMap: Type => Type = IdentityTypeMap,
treeMap: Tree => Tree = identity _,
oldOwners: List[Symbol] = Nil,
newOwners: List[Symbol] = Nil,
substFrom: List[Symbol],
substTo: List[Symbol])(implicit ctx: Context)
extends TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo) {

override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
case Hole(n, args) =>
Hole(n, args.mapConserve(transform)).withPos(tree.pos).withType(mapType(tree.tpe))
case _ =>
super.transform(tree)
}

override def newMap(
typeMap: Type => Type,
treeMap: Tree => Tree,
oldOwners: List[Symbol],
newOwners: List[Symbol],
substFrom: List[Symbol],
substTo: List[Symbol])(implicit ctx: Context) =
new SubstMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
}

/** Requiring that `paramRefs` consists of a single reference `seq` to a Seq[Any],
* a tree map that replaces each hole with index `n` with `seq(n)`, applied
* to any arguments in the hole.
Expand Down Expand Up @@ -148,7 +121,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
}
importedTags.clear()
Block(typeDefs,
new SubstMap(substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
new TreeTypeMap(substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
.apply(expr))
}

Expand Down