Skip to content

Commit 0d59239

Browse files
committed
Refactor use of Quote
1 parent 825529e commit 0d59239

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ class PickleQuotes extends MacroTransform {
104104
val (contents, codeWithHoles) = makeHoles(quote.body)
105105
val sourceRef = Inlines.inlineCallTrace(ctx.owner, tree.sourcePos)
106106
val bodyWithHoles2 =
107-
if quote.body.isType then codeWithHoles
107+
if quote.isTypeQuote then codeWithHoles
108108
else Inlined(sourceRef, Nil, codeWithHoles)
109-
val pickled = PickleQuotes.pickle(quotes, bodyWithHoles2, contents, quote.bodyType)
109+
val quote1 = cpy.Quote(quote)(body = bodyWithHoles2)
110+
val pickled = PickleQuotes.pickle(quote1, quotes, contents)
110111
transform(pickled) // pickle quotes that are in the contents
111112
case tree: DefDef if !tree.rhs.isEmpty && tree.symbol.isInlineMethod =>
112113
// Shrink size of the tree. The methods have already been inlined.
@@ -202,7 +203,10 @@ object PickleQuotes {
202203
val name: String = "pickleQuotes"
203204
val description: String = "turn quoted trees into explicit run-time data structures"
204205

205-
def pickle(quotes: Tree, body: Tree, contents: List[Tree], originalTp: Type)(using Context) = {
206+
def pickle(quote: Quote, quotes: Tree, contents: List[Tree])(using Context) = {
207+
val body = quote.body
208+
val bodyType = quote.bodyType
209+
206210
/** Helper methods to construct trees calling methods in `Quotes.reflect` based on the current `quotes` tree */
207211
object reflect extends ReifiedReflect {
208212
val quotesTree = quotes
@@ -256,7 +260,7 @@ object PickleQuotes {
256260
*/
257261
def liftedValue(lit: Literal, lifter: Symbol) =
258262
val exprType = defn.QuotedExprClass.typeRef.appliedTo(body.tpe)
259-
ref(lifter).appliedToType(originalTp).select(nme.apply).appliedTo(lit).appliedTo(quotes)
263+
ref(lifter).appliedToType(bodyType).select(nme.apply).appliedTo(lit).appliedTo(quotes)
260264

261265
def pickleAsValue(lit: Literal) = {
262266
// TODO should all constants be pickled as Literals?
@@ -334,18 +338,18 @@ object PickleQuotes {
334338
case _ => Match(args(0).annotated(New(ref(defn.UncheckedAnnot.typeRef))), cases)
335339
)
336340

337-
val quoteClass = if body.isType then defn.QuotedTypeClass else defn.QuotedExprClass
338-
val quotedType = quoteClass.typeRef.appliedTo(originalTp)
341+
val quoteClass = if quote.isTypeQuote then defn.QuotedTypeClass else defn.QuotedExprClass
342+
val quotedType = quoteClass.typeRef.appliedTo(bodyType)
339343
val lambdaTpe = MethodType(defn.QuotesClass.typeRef :: Nil, quotedType)
340344
val unpickleMeth =
341-
if body.isType then defn.QuoteUnpickler_unpickleTypeV2
345+
if quote.isTypeQuote then defn.QuoteUnpickler_unpickleTypeV2
342346
else defn.QuoteUnpickler_unpickleExprV2
343347
val unpickleArgs =
344-
if body.isType then List(pickledQuoteStrings, types)
348+
if quote.isTypeQuote then List(pickledQuoteStrings, types)
345349
else List(pickledQuoteStrings, types, termHoles)
346350
quotes
347351
.asInstance(defn.QuoteUnpicklerClass.typeRef)
348-
.select(unpickleMeth).appliedToType(originalTp)
352+
.select(unpickleMeth).appliedToType(bodyType)
349353
.appliedToArgs(unpickleArgs).withSpan(body.span)
350354
}
351355

compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ trait QuotesAndSplices {
5050

5151
if ctx.mode.is(Mode.Pattern) then
5252
typedQuotePattern(tree, pt, quotes).withSpan(tree.span)
53-
else if tree.body.isType then
53+
else if tree.isTypeQuote then
5454
val msg = em"""Quoted types `'[..]` can only be used in patterns.
5555
|
5656
|Hint: To get a scala.quoted.Type[T] use scala.quoted.Type.of[T] instead.

0 commit comments

Comments
 (0)