Skip to content

Commit 1efa224

Browse files
committed
WIP Extract quote reification from Staging
1 parent 4c5ca04 commit 1efa224

File tree

37 files changed

+889
-291
lines changed

37 files changed

+889
-291
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ class Compiler {
4545

4646
/** Phases dealing with TASTY tree pickling and unpickling */
4747
protected def picklerPhases: List[List[Phase]] =
48+
List(new Staging) :: // Check levels and expand macros
4849
List(new Pickler) :: // Generate TASTY info
49-
List(new Staging) :: // Expand macros and turn quoted trees into explicit run-time data structures
50+
List(new ReifyQuotes) :: // Turn quoted trees into explicit run-time data structures
5051
Nil
5152

5253
/** Phases dealing with the transformation from pickled trees to backend trees */

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class TreeTypeMap(
162162
assert(!to.exists(substFrom contains _))
163163
assert(!from.exists(newOwners contains _))
164164
assert(!to.exists(oldOwners contains _))
165-
new TreeTypeMap(
165+
newTreeTypeMap(
166166
typeMap,
167167
treeMap,
168168
from ++ oldOwners,
@@ -171,6 +171,11 @@ class TreeTypeMap(
171171
to ++ substTo)
172172
}
173173

174+
protected def newTreeTypeMap(typeMap: Type => Type, treeMap: tpd.Tree => tpd.Tree,
175+
oldOwners: List[Symbol], newOwners: List[Symbol], substFrom: List[Symbol], substTo: List[Symbol]) = {
176+
new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
177+
}
178+
174179
/** Apply `typeMap` and `ownerMap` to given symbols `syms`
175180
* and return a treemap that contains the substitution
176181
* between original and mapped symbols.

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
249249
protected def blockText[T >: Untyped](trees: List[Tree[T]]): Text =
250250
("{" ~ toText(trees, "\n") ~ "}").close
251251

252-
protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text =
253-
toTextLocal(tree.fun) ~ "[" ~ toTextGlobal(tree.args, ", ") ~ "]"
252+
protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = {
253+
if (tree.fun.hasType && tree.fun.symbol == defn.QuotedType_apply)
254+
keywordStr("'[") ~ toTextGlobal(tree.args, ", ") ~ keywordStr("]")
255+
else
256+
toTextLocal(tree.fun) ~ "[" ~ toTextGlobal(tree.args, ", ") ~ "]"
257+
}
254258

255259
protected def toTextCore[T >: Untyped](tree: Tree[T]): Text = {
256260
import untpd.{modsDeco => _, _}
@@ -318,7 +322,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
318322
if (name.isTypeName) typeText(txt)
319323
else txt
320324
case tree @ Select(qual, name) =>
321-
if (tree.hasType && tree.symbol == defn.QuotedExpr_~ || tree.symbol == defn.QuotedType_~) keywordStr("~(") ~ toTextLocal(qual) ~ keywordStr(")")
325+
if (tree.hasType && tree.symbol == defn.QuotedExpr_~) keywordStr("~(") ~ toTextLocal(qual) ~ keywordStr(")")
326+
else if (tree.hasType && tree.symbol == defn.QuotedType_~) typeText("~(") ~ toTextLocal(qual) ~ typeText(")")
322327
else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
323328
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided name != nme.CONSTRUCTOR)
324329
case tree: This =>
@@ -332,8 +337,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
332337
}
333338
else if (fun.hasType && fun.symbol == defn.QuotedExpr_apply)
334339
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
335-
else if (fun.hasType && fun.symbol == defn.QuotedType_apply)
336-
keywordStr("'[") ~ toTextGlobal(args, ", ") ~ keywordStr("]")
337340
else
338341
toTextLocal(fun) ~ "(" ~ toTextGlobal(args, ", ") ~ ")"
339342
case tree: TypeApply =>

compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
776776
tpd.Return(expr, ctx.owner)
777777

778778
def copy(original: Tree)(expr: Term)(implicit ctx: Context): Return =
779-
tpd.cpy.Return(original)(expr, tpd.EmptyTree)
779+
tpd.cpy.Return(original)(expr, tpd.ref(ctx.owner))
780780

781781
def unapply(x: Term)(implicit ctx: Context): Option[Term] = x match {
782782
case x: tpd.Return => Some(x.expr)

0 commit comments

Comments
 (0)