Skip to content

Use List for quote arguments as is done with quote pickled strings #3910

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
Jan 25, 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
10 changes: 3 additions & 7 deletions compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ object PickledQuotes {
import tpd._

/** Pickle the quote into strings */
def pickleQuote(tree: Tree)(implicit ctx: Context): Tree = {
if (ctx.reporter.hasErrors) Literal(Constant("<error>"))
def pickleQuote(tree: Tree)(implicit ctx: Context): scala.runtime.quoted.Unpickler.Pickled = {
if (ctx.reporter.hasErrors) Nil
else {
val encapsulated = encapsulateQuote(tree)
val pickled = pickle(encapsulated)
TastyString.pickle(pickled).foldRight[Tree](ref(defn.NilModule)) { (x, acc) =>
acc.select("::".toTermName)
.appliedToType(defn.StringType)
.appliedTo(Literal(Constant(x)))
}
TastyString.pickle(pickled)
}
}

Expand Down
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,17 @@ class ReifyQuotes extends MacroTransform {
if (inSplice)
makeHole(body1, splices, quote.tpe)
else {
def liftList(list: List[Tree], tpe: Type): Tree = {
list.foldRight[Tree](ref(defn.NilModule)) { (x, acc) =>
acc.select("::".toTermName).appliedToType(tpe).appliedTo(x)
}
}
val isType = quote.tpe.isRef(defn.QuotedTypeClass)
ref(if (isType) defn.Unpickler_unpickleType else defn.Unpickler_unpickleExpr)
.appliedToType(if (isType) body1.tpe else body1.tpe.widen)
.appliedTo(
PickledQuotes.pickleQuote(body1),
SeqLiteral(splices, TypeTree(defn.AnyType)))
liftList(PickledQuotes.pickleQuote(body1).map(x => Literal(Constant(x))), defn.StringType),
liftList(splices, defn.AnyType))
}
}.withPos(quote.pos)

Expand Down