Skip to content

Commit b53d3ff

Browse files
committed
Encode quotes into List[String]
1 parent aa4bc71 commit b53d3ff

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ import scala.runtime.quoted.Unpickler.Pickled
1616
object PickledQuotes {
1717
import tpd._
1818

19-
/** Pickle the quote into a TASTY string */
20-
def pickleQuote(tree: Tree)(implicit ctx: Context): Pickled = {
21-
if (ctx.reporter.hasErrors) List("<error>")
19+
/** Pickle the quote into strings */
20+
def pickleQuote(tree: Tree)(implicit ctx: Context): Tree = {
21+
if (ctx.reporter.hasErrors) Literal(Constant("<error>"))
2222
else {
2323
val encapsulated = encapsulateQuote(tree)
2424
val pickled = pickle(encapsulated)
25-
TastyString.pickle(pickled)
25+
TastyString.pickle(pickled).foldRight[Tree](ref(defn.NilModule)) { (x, acc) =>
26+
acc.select("::".toTermName)
27+
.appliedToType(defn.StringType)
28+
.appliedTo(Literal(Constant(x)))
29+
}
2630
}
2731
}
2832

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,10 @@ class ReifyQuotes extends MacroTransform {
266266
makeHole(body1, splices, quote.tpe)
267267
else {
268268
val isType = quote.tpe.isRef(defn.QuotedTypeClass)
269-
val strings = PickledQuotes.pickleQuote(body1).map(x => Literal(Constant(x)))
270269
ref(if (isType) defn.Unpickler_unpickleType else defn.Unpickler_unpickleExpr)
271270
.appliedToType(if (isType) body1.tpe else body1.tpe.widen)
272271
.appliedTo(
273-
SeqLiteral(strings.toList, TypeTree(defn.StringType)),
272+
PickledQuotes.pickleQuote(body1),
274273
SeqLiteral(splices, TypeTree(defn.AnyType)))
275274
}
276275
}.withPos(quote.pos)

library/src/scala/runtime/quoted/Unpickler.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import scala.quoted._
55
/** Provides methods to unpickle `Expr` and `Type` trees. */
66
object Unpickler {
77

8-
/** Representation of pickled trees. For now it's String, but it
9-
* should be changed to some kind of TASTY bundle.
8+
/** Representation of pickled trees. For now a List[String],
9+
* but it should be changed to some kind of TASTY bundle.
1010
*/
11-
type Pickled = Seq[String]
11+
type Pickled = List[String]
1212

1313
/** Unpickle `repr` which represents a pickled `Expr` tree,
1414
* replacing splice nodes with `args`

0 commit comments

Comments
 (0)