Skip to content

Commit 37f0bff

Browse files
committed
Wip
1 parent 43c46e3 commit 37f0bff

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,5 @@ object Printers {
6060
// tests/run-staging/shonan-hmm failed
6161
// tests/run-staging/staged-tuples failed
6262
// tests/run-staging/staged-streams_1.scala failed
63-
// tests/run-staging/quote-nested-3.scala failed
6463
// tests/run-staging/quote-lib.scala failed
6564
// tests/run-staging/shonan-hmm-simple.scala failed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,25 @@ object PickledQuotes {
7171

7272
val evaluateHoles = new TreeMap {
7373
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
74-
case Hole(isType, idx, args) =>
75-
assert(!isType)
76-
val splice = splices(idx)
77-
def wrap(arg: Tree) =
74+
case Hole(isTerm, idx, args) =>
75+
val reifiedArgs = args.map { arg =>
7876
if (arg.isTerm) (qctx: scala.quoted.QuoteContext) ?=> new TastyTreeExpr(arg, QuoteContext.scopeId)
7977
else new TreeType(arg, QuoteContext.scopeId)
80-
val reifiedArgs = args.map(wrap)
78+
}
79+
val splice = splices(idx)
8180

82-
val splice1 = splice.asInstanceOf[Seq[Any] => scala.quoted.QuoteContext ?=> quoted.Expr[?]]
83-
val quotedExpr = splice1(reifiedArgs)(using dotty.tools.dotc.quoted.QuoteContext())
84-
val filled = PickledQuotes.quotedExprToTree(quotedExpr)
81+
if isTerm then
82+
val splice1 = splice.asInstanceOf[Seq[Any] => scala.quoted.QuoteContext ?=> quoted.Expr[?]]
83+
val quotedExpr = splice1(reifiedArgs)(using dotty.tools.dotc.quoted.QuoteContext())
84+
val filled = PickledQuotes.quotedExprToTree(quotedExpr)
8585

86-
// We need to make sure a hole is created with the source file of the surrounding context, even if
87-
// it filled with contents a different source file.
88-
if filled.source == ctx.source then filled
89-
else filled.cloneIn(ctx.source).withSpan(tree.span)
86+
// We need to make sure a hole is created with the source file of the surrounding context, even if
87+
// it filled with contents a different source file.
88+
if filled.source == ctx.source then filled
89+
else filled.cloneIn(ctx.source).withSpan(tree.span)
90+
else
91+
val quotedType = splice.asInstanceOf[Seq[Any] => quoted.Type[?]](reifiedArgs)
92+
PickledQuotes.quotedTypeToTree(quotedType)
9093

9194
case tree =>
9295
if tree.isDef then
@@ -125,8 +128,10 @@ object PickledQuotes {
125128
class ReplaceSplicedTyped(typeSpliceMap: Map[Symbol, Type]) extends TypeMap() {
126129
override def apply(tp: Type): Type = {
127130
val tp1 = tp match {
128-
case tp: TypeRef if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) =>
129-
typeSpliceMap(tp.symbol)
131+
case tp: TypeRef =>
132+
typeSpliceMap.get(tp.symbol) match
133+
case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => t
134+
case None => tp
130135
case _ => tp
131136
}
132137
mapOver(tp1)

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ object TreePickler {
2626
override def isTerm: Boolean = isTermHole
2727
override def isType: Boolean = !isTermHole
2828
override def fallbackToText(printer: Printer): Text =
29-
s"[[$idx|" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
29+
if isTermHole then s"{{{ $idx |" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "}}}"
30+
else s"[[[ $idx |" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]]"
3031
}
3132
}
3233

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ class TreeUnpickler(reader: TastyReader,
12161216
val idx = readNat()
12171217
val tpe = readType()
12181218
val args = until(end)(readTerm())
1219-
TreePickler.Hole(false, idx, args).withType(tpe)
1219+
TreePickler.Hole(true, idx, args).withType(tpe)
12201220
case _ =>
12211221
readPathTerm()
12221222
}
@@ -1252,7 +1252,7 @@ class TreeUnpickler(reader: TastyReader,
12521252
val idx = readNat()
12531253
val tpe = readType()
12541254
val args = until(end)(readTerm())
1255-
TreePickler.Hole(true, idx, args).withType(tpe)
1255+
TreePickler.Hole(false, idx, args).withType(tpe)
12561256
case _ =>
12571257
if (isTypeTreeTag(nextByte)) readTerm()
12581258
else {
@@ -1294,13 +1294,6 @@ class TreeUnpickler(reader: TastyReader,
12941294
owner => new LazyReader(localReader, owner, ctx.mode, ctx.source, op)
12951295
}
12961296

1297-
def readHole(end: Addr, isType: Boolean)(implicit ctx: Context): Tree = { // TODO inline by hand
1298-
val idx = readNat()
1299-
val tpe = readType()
1300-
val args = until(end)(readTerm())
1301-
TreePickler.Hole(isType, idx, args).withType(tpe)
1302-
}
1303-
13041297
// ------ Setting positions ------------------------------------------------
13051298

13061299
/** Pickled span for `addr`. */

0 commit comments

Comments
 (0)