Skip to content

Commit 5ae7861

Browse files
committed
Remove tpt from Quote
1 parent 1f62049 commit 5ae7861

22 files changed

+69
-67
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ object CompilationUnit {
157157
if tree.symbol.is(Flags.Inline) then
158158
containsInline = true
159159
tree match
160-
case tpd.Quote(_, _) =>
160+
case tpd.Quote(_) =>
161161
containsQuote = true
162162
case tree: tpd.Apply if tree.symbol == defn.QuotedTypeModule_of =>
163163
containsQuote = true

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,7 +1986,7 @@ object desugar {
19861986
trees foreach collect
19871987
case Block(Nil, expr) =>
19881988
collect(expr)
1989-
case Quote(expr, _) =>
1989+
case Quote(expr) =>
19901990
new UntypedTreeTraverser {
19911991
def traverse(tree: untpd.Tree)(using Context): Unit = tree match {
19921992
case Splice(expr, _) => collect(expr)

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -678,23 +678,33 @@ object Trees {
678678
}
679679

680680
/** A tree representing a quote `'{ expr }`
681-
* `Quote`s are created by the `Parser` with an empty `tpt`. In typer
682-
* they can be typed as a `Quote` with a known `tpt` or desugared and
683-
* typed as a quote pattern.
681+
* `Quote`s are created by the `Parser`. In typer they can be typed as a
682+
* `Quote` with a known `tpt` or desugared and typed as a quote pattern.
684683
*
685684
* `Quotes` are checked and transformed in the `staging`, `splicing` and `pickleQuotes`
686685
* phases. After `pickleQuotes` phase, the only quotes that exist are in `inline`
687686
* methods. These are dropped when we remove the inline method implementations.
688687
*
689-
* The `tpt` will be transformed in `staging` and used in `pickleQuotes` to create the
690-
* pickled representation of the quote.
691-
*
692688
* @param expr The tree that was quoted
693-
* @param tpt The type of the tree that was quoted
694689
*/
695-
case class Quote[+T <: Untyped] private[ast] (expr: Tree[T], tpt: Tree[T])(implicit @constructorOnly src: SourceFile)
690+
case class Quote[+T <: Untyped] private[ast] (expr: Tree[T])(implicit @constructorOnly src: SourceFile)
696691
extends TermTree[T] {
697692
type ThisTree[+T <: Untyped] = Quote[T]
693+
694+
/** Type of the quoted expression as seen from outside the quote */
695+
def exprType(using Context): Type =
696+
val quoteType = typeOpt // Quotes ?=> Expr[T]
697+
val exprType = quoteType.argInfos.last // Expr[T]
698+
exprType.argInfos.head // T
699+
700+
/** Set the type of the quoted expression as seen from outside the quote */
701+
def withExprType(tpe: Type)(using Context): Quote[Type] =
702+
val exprType = // Expr[T]
703+
defn.QuotedExprClass.typeRef.appliedTo(tpe)
704+
val quoteType = // Quotes ?=> Expr[T]
705+
defn.FunctionType(1, isContextual = true)
706+
.appliedTo(defn.QuotesClass.typeRef, exprType)
707+
withType(quoteType)
698708
}
699709

700710
/** A tree representing a splice `${ expr }`
@@ -1299,9 +1309,9 @@ object Trees {
12991309
case tree: Inlined if (call eq tree.call) && (bindings eq tree.bindings) && (expansion eq tree.expansion) => tree
13001310
case _ => finalize(tree, untpd.Inlined(call, bindings, expansion)(sourceFile(tree)))
13011311
}
1302-
def Quote(tree: Tree)(expr: Tree, tpt: Tree)(using Context): Quote = tree match {
1303-
case tree: Quote if (expr eq tree.expr) && (tpt eq tree.tpt) => tree
1304-
case _ => finalize(tree, untpd.Quote(expr, tpt)(sourceFile(tree)))
1312+
def Quote(tree: Tree)(expr: Tree)(using Context): Quote = tree match {
1313+
case tree: Quote if (expr eq tree.expr) => tree
1314+
case _ => finalize(tree, untpd.Quote(expr)(sourceFile(tree)))
13051315
}
13061316
def Splice(tree: Tree)(expr: Tree, tpt: Tree)(using Context): Splice = tree match {
13071317
case tree: Splice if (expr eq tree.expr) && (tpt eq tree.tpt) => tree
@@ -1546,8 +1556,8 @@ object Trees {
15461556
case Thicket(trees) =>
15471557
val trees1 = transform(trees)
15481558
if (trees1 eq trees) tree else Thicket(trees1)
1549-
case tree @ Quote(expr, tpt) =>
1550-
cpy.Quote(tree)(transform(expr), transform(tpt))
1559+
case tree @ Quote(expr) =>
1560+
cpy.Quote(tree)(transform(expr))
15511561
case tree @ Splice(expr, tpt) =>
15521562
cpy.Splice(tree)(transform(expr), transform(tpt))
15531563
case tree @ Hole(_, _, args, content, tpt) =>
@@ -1691,8 +1701,8 @@ object Trees {
16911701
this(this(x, arg), annot)
16921702
case Thicket(ts) =>
16931703
this(x, ts)
1694-
case Quote(expr, tpt) =>
1695-
this(this(x, expr), tpt)
1704+
case Quote(expr) =>
1705+
this(x, expr)
16961706
case Splice(expr, tpt) =>
16971707
this(this(x, expr), tpt)
16981708
case Hole(_, _, args, content, tpt) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
170170
def Inlined(call: Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined =
171171
ta.assignType(untpd.Inlined(call, bindings, expansion), bindings, expansion)
172172

173-
def Quote(expr: Tree, tpt: Tree)(using Context): Quote =
174-
ta.assignType(untpd.Quote(expr, tpt), tpt)
173+
def Quote(expr: Tree, tpe: Type)(using Context): Quote =
174+
untpd.Quote(expr).withExprType(tpe)
175175

176176
def Splice(expr: Tree, tpt: Tree)(using Context): Splice =
177177
ta.assignType(untpd.Splice(expr, tpt), tpt)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
397397
def SeqLiteral(elems: List[Tree], elemtpt: Tree)(implicit src: SourceFile): SeqLiteral = new SeqLiteral(elems, elemtpt)
398398
def JavaSeqLiteral(elems: List[Tree], elemtpt: Tree)(implicit src: SourceFile): JavaSeqLiteral = new JavaSeqLiteral(elems, elemtpt)
399399
def Inlined(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(implicit src: SourceFile): Inlined = new Inlined(call, bindings, expansion)
400-
def Quote(expr: Tree, tpt: Tree)(implicit src: SourceFile): Quote = new Quote(expr, tpt)
400+
def Quote(expr: Tree)(implicit src: SourceFile): Quote = new Quote(expr)
401401
def Splice(expr: Tree, tpt: Tree)(implicit src: SourceFile): Splice = new Splice(expr, tpt)
402402
def TypeTree()(implicit src: SourceFile): TypeTree = new TypeTree()
403403
def InferredTypeTree()(implicit src: SourceFile): TypeTree = new InferredTypeTree()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,11 @@ class TreePickler(pickler: TastyPickler) {
665665
pickleTree(hi)
666666
pickleTree(alias)
667667
}
668-
case Quote(expr, tpt) =>
668+
case tree @ Quote(expr) =>
669669
pickleTree(
670-
// scala.quoted.runtime.Expr.quoted[<tpt>](<expr>)
670+
// scala.quoted.runtime.Expr.quoted[<exprType>](<expr>)
671671
ref(defn.QuotedRuntime_exprQuote)
672-
.appliedToTypeTree(tpt)
672+
.appliedToType(tree.exprType)
673673
.appliedTo(expr)
674674
.withSpan(tree.span)
675675
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ class TreeUnpickler(reader: TastyReader,
12691269

12701270
def quotedExpr(fn: Tree, args: List[Tree]): Tree =
12711271
val TypeApply(_, targs) = fn: @unchecked
1272-
Quote(args.head, targs.head)
1272+
Quote(args.head, targs.head.tpe)
12731273

12741274
def splicedExpr(fn: Tree, args: List[Tree]): Tree =
12751275
val TypeApply(_, targs) = fn: @unchecked

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ class Inliner(val call: tpd.Tree)(using Context):
827827

828828
override def typedQuote(tree: untpd.Quote, pt: Type)(using Context): Tree =
829829
super.typedQuote(tree, pt) match
830-
case Quote(Splice(inner, _), _) => inner
830+
case Quote(Splice(inner, _)) => inner
831831
case tree1 =>
832832
ctx.compilationUnit.needsStaging = true
833833
tree1
@@ -1070,7 +1070,7 @@ class Inliner(val call: tpd.Tree)(using Context):
10701070
else tree match {
10711071
case tree: RefTree if tree.isTerm && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
10721072
foldOver(tree.symbol :: syms, tree)
1073-
case Quote(body, _) =>
1073+
case Quote(body) =>
10741074
level += 1
10751075
try apply(syms, body)
10761076
finally level -= 1

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,7 @@ object Parsers {
12621262
}
12631263
}
12641264
in.nextToken()
1265-
Quote(t, EmptyTree)
1265+
Quote(t)
12661266
}
12671267
else
12681268
if !in.featureEnabled(Feature.symbolLiterals) then
@@ -2497,7 +2497,7 @@ object Parsers {
24972497
val expr =
24982498
if (in.token == LBRACKET) inBrackets(typ())
24992499
else stagedBlock()
2500-
Quote(expr, EmptyTree)
2500+
Quote(expr)
25012501
}
25022502
}
25032503
case NEW =>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
716716
"Thicket {" ~~ toTextGlobal(trees, "\n") ~~ "}"
717717
case MacroTree(call) =>
718718
keywordStr("macro ") ~ toTextGlobal(call)
719-
case Quote(expr, tpt) =>
720-
val tptText = (keywordStr("[") ~ toTextGlobal(tpt) ~ keywordStr("]")).provided(!tpt.isEmpty && printDebug)
721-
keywordStr("'") ~ tptText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")
719+
case tree @ Quote(expr) =>
720+
val exprTypeText = (keywordStr("[") ~ toTextGlobal(tree.exprType) ~ keywordStr("]")).provided(printDebug)
721+
keywordStr("'") ~ exprTypeText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")
722722
case Splice(expr, tpt) =>
723723
val tptText = (keywordStr("[") ~ toTextGlobal(tpt) ~ keywordStr("]")).provided(!tpt.isEmpty && printDebug)
724724
keywordStr("$") ~ tptText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")

0 commit comments

Comments
 (0)