Skip to content

Commit 86a92e4

Browse files
Merge pull request #9448 from dotty-staging/move-staging-phase
Remove quoted.Type synthesization
2 parents 63b84cb + 7c4fa0c commit 86a92e4

File tree

17 files changed

+30
-59
lines changed

17 files changed

+30
-59
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class Compiler {
3838
protected def frontendPhases: List[List[Phase]] =
3939
List(new FrontEnd) :: // Compiler frontend: scanner, parser, namer, typer
4040
List(new YCheckPositions) :: // YCheck positions
41-
List(new Staging) :: // Check PCP, heal quoted types and expand macros
4241
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
4342
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files
4443
List(new PostTyper) :: // Additional checks and cleanups after type checking
44+
List(new Staging) :: // Check PCP, heal quoted types and expand macros
4545
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
4646
List(new SetRootTree) :: // Set the `rootTreeOrProvider` on class symbols
4747
Nil

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
397397
case New(_) | Closure(_, _, _) =>
398398
Pure
399399
case TypeApply(fn, _) =>
400-
if (fn.symbol.is(Erased) || fn.symbol == defn.InternalQuoted_typeQuote || fn.symbol == defn.Predef_classOf) Pure else exprPurity(fn)
400+
if (fn.symbol.is(Erased) || fn.symbol == defn.QuotedTypeModule_apply || fn.symbol == defn.Predef_classOf) Pure else exprPurity(fn)
401401
case Apply(fn, args) =>
402402
def isKnownPureOp(sym: Symbol) =
403403
sym.owner.isPrimitiveValueClass

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,6 @@ class Definitions {
699699
@tu lazy val InternalQuoted_exprQuote : Symbol = InternalQuotedModule.requiredMethod("exprQuote")
700700
@tu lazy val InternalQuoted_exprSplice : Symbol = InternalQuotedModule.requiredMethod("exprSplice")
701701
@tu lazy val InternalQuoted_exprNestedSplice : Symbol = InternalQuotedModule.requiredMethod("exprNestedSplice")
702-
@tu lazy val InternalQuoted_typeQuote : Symbol = InternalQuotedModule.requiredMethod("typeQuote")
703702
@tu lazy val InternalQuoted_QuoteTypeTagAnnot: ClassSymbol = InternalQuotedModule.requiredClass("quoteTypeTag")
704703

705704
@tu lazy val InternalQuotedMatcher: Symbol = requiredModule("scala.internal.quoted.Matcher")
@@ -719,6 +718,7 @@ class Definitions {
719718
@tu lazy val QuotedType_splice: Symbol = QuotedTypeClass.requiredType(tpnme.spliceType)
720719

721720
@tu lazy val QuotedTypeModule: Symbol = QuotedTypeClass.companionModule
721+
@tu lazy val QuotedTypeModule_apply: Symbol = QuotedTypeModule.requiredMethod("apply")
722722

723723
@tu lazy val TastyReflectionClass: ClassSymbol = requiredClass("scala.tasty.Reflection")
724724

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,5 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
7575

7676
override protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text =
7777
if (tree.symbol eq defn.InternalQuoted_exprQuote) "'"
78-
else if (tree.symbol eq defn.InternalQuoted_typeQuote) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]"
7978
else super.typeApplyText(tree)
8079
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
266266
("{" ~ toText(trees, "\n") ~ "}").close
267267

268268
protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = {
269-
val isQuote = !printDebug && tree.fun.hasType && tree.fun.symbol == defn.InternalQuoted_typeQuote
270-
val (open, close) = if (isQuote) (keywordStr("'["), keywordStr("]")) else ("[", "]")
271-
val funText = toTextLocal(tree.fun).provided(!isQuote)
269+
val funText = toTextLocal(tree.fun)
272270
tree.fun match {
273271
case Select(New(tpt), nme.CONSTRUCTOR) if tpt.typeOpt.dealias.isInstanceOf[AppliedType] =>
274272
funText // type was already printed by toText(new)
275273
case _ =>
276-
funText ~ open ~ toTextGlobal(tree.args, ", ") ~ close
274+
funText ~ "[" ~ toTextGlobal(tree.args, ", ") ~ "]"
277275
}
278276
}
279277

@@ -632,9 +630,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
632630
}
633631
case Number(digits, kind) =>
634632
digits
635-
case Quote(tree) =>
636-
if (tree.isType) keywordStr("'[") ~ toTextGlobal(dropBlock(tree)) ~ keywordStr("]")
637-
else keywordStr("'{") ~ toTextGlobal(dropBlock(tree)) ~ keywordStr("}")
633+
case Quote(tree) if tree.isTerm =>
634+
keywordStr("'{") ~ toTextGlobal(dropBlock(tree)) ~ keywordStr("}")
638635
case Splice(tree) =>
639636
keywordStr("${") ~ toTextGlobal(dropBlock(tree)) ~ keywordStr("}")
640637
case TypSplice(tree) =>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
175175
tp match
176176
case tp: TypeRef =>
177177
tp.prefix match
178-
case NoPrefix if level > levelOf(tp.symbol) =>
179-
tryHeal(tp.symbol, tp, pos)
178+
case NoPrefix if level > levelOf(tp.symbol) && !tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) =>
179+
val tp1 = tp.dealias
180+
if tp1 != tp then apply(tp1)
181+
else tryHeal(tp.symbol, tp, pos)
180182
case prefix: ThisType if !tp.symbol.isStatic && level > levelOf(prefix.cls) =>
181183
tryHeal(tp.symbol, tp, pos)
182184
case prefix: TermRef if tp.symbol.isTypeSplice =>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
273273
val patterns1 = transform(patterns)
274274
cpy.UnApply(tree)(transform(fun), transform(implicits), patterns1)
275275
case tree: TypeApply =>
276+
if tree.symbol.isQuote then
277+
ctx.compilationUnit.needsStaging = true
276278
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
277279
args.foreach(checkInferredWellFormed)
278280
if (fn.symbol != defn.ChildAnnot.primaryConstructor)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ReifyQuotes extends MacroTransform {
127127
* core and splices as arguments.
128128
*/
129129
override protected def transformQuotation(body: Tree, quote: Tree)(using Context): Tree = {
130-
val isType = quote.symbol eq defn.InternalQuoted_typeQuote
130+
val isType = quote.symbol eq defn.QuotedTypeModule_apply
131131
if (level > 0) {
132132
val body1 = nested(isQuote = true).transform(body)(using quoteContext)
133133
super.transformQuotation(body1, quote)
@@ -364,7 +364,7 @@ class ReifyQuotes extends MacroTransform {
364364
transform(tree)(using ctx.withSource(tree.source))
365365
else reporting.trace(i"Reifier.transform $tree at $level", show = true) {
366366
tree match {
367-
case Apply(Select(TypeApply(fn, (body: RefTree) :: Nil), _), _) if fn.symbol == defn.InternalQuoted_typeQuote && isCaptured(body.symbol, level + 1) =>
367+
case Apply(Select(TypeApply(fn, (body: RefTree) :: Nil), _), _) if fn.symbol == defn.QuotedTypeModule_apply && isCaptured(body.symbol, level + 1) =>
368368
// Optimization: avoid the full conversion when capturing `x`
369369
// in '{ x } to '{ ${x$1} } and go directly to `x$1`
370370
capturers(body.symbol)(body)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ object Splicer {
141141
case Apply(Select(Apply(fn, quoted :: Nil), nme.apply), _) if fn.symbol == defn.InternalQuoted_exprQuote =>
142142
// OK
143143

144-
case TypeApply(fn, quoted :: Nil) if fn.symbol == defn.InternalQuoted_typeQuote =>
144+
case TypeApply(fn, quoted :: Nil) if fn.symbol == defn.QuotedTypeModule_apply =>
145145
// OK
146146

147147
case Literal(Constant(value)) =>
@@ -231,7 +231,7 @@ object Splicer {
231231
}
232232
interpretQuote(quoted1)
233233

234-
case Apply(Select(TypeApply(fn, quoted :: Nil), _), _) if fn.symbol == defn.InternalQuoted_typeQuote =>
234+
case Apply(Select(TypeApply(fn, quoted :: Nil), _), _) if fn.symbol == defn.QuotedTypeModule_apply =>
235235
interpretTypeQuote(quoted)
236236

237237
case Literal(Constant(value)) =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ object SymUtils {
203203

204204
/** Is symbol a quote operation? */
205205
def isQuote(using Context): Boolean =
206-
self == defn.InternalQuoted_exprQuote || self == defn.InternalQuoted_typeQuote
206+
self == defn.InternalQuoted_exprQuote || self == defn.QuotedTypeModule_apply
207207

208208
/** Is symbol a term splice operation? */
209209
def isExprSplice(using Context): Boolean =

0 commit comments

Comments
 (0)