Skip to content

Commit 6c1edfa

Browse files
committed
Add quoted.Type.apply constructor
Just as `$t` is equivalent to `t.T`, `'[T]` is equivalent to `Type[T]`
1 parent 7d2c1cc commit 6c1edfa

File tree

12 files changed

+18
-17
lines changed

12 files changed

+18
-17
lines changed

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
@@ -693,7 +693,6 @@ class Definitions {
693693
@tu lazy val InternalQuoted_exprQuote : Symbol = InternalQuotedModule.requiredMethod("exprQuote")
694694
@tu lazy val InternalQuoted_exprSplice : Symbol = InternalQuotedModule.requiredMethod("exprSplice")
695695
@tu lazy val InternalQuoted_exprNestedSplice : Symbol = InternalQuotedModule.requiredMethod("exprNestedSplice")
696-
@tu lazy val InternalQuoted_typeQuote : Symbol = InternalQuotedModule.requiredMethod("typeQuote")
697696
@tu lazy val InternalQuoted_QuoteTypeTagAnnot: ClassSymbol = InternalQuotedModule.requiredClass("quoteTypeTag")
698697

699698
@tu lazy val InternalQuotedMatcher: Symbol = requiredModule("scala.internal.quoted.Matcher")
@@ -713,6 +712,7 @@ class Definitions {
713712
@tu lazy val QuotedType_splice: Symbol = QuotedTypeClass.requiredType(tpnme.spliceType)
714713

715714
@tu lazy val QuotedTypeModule: Symbol = QuotedTypeClass.companionModule
715+
@tu lazy val QuotedTypeModule_apply: Symbol = QuotedTypeModule.requiredMethod("apply")
716716

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ 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, ", ") ~ "]"
78+
else if (tree.symbol eq defn.QuotedTypeModule_apply) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]"
7979
else super.typeApplyText(tree)
8080
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ 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
269+
val isQuote = !printDebug && tree.fun.hasType && tree.fun.symbol == defn.QuotedTypeModule_apply
270270
val (open, close) = if (isQuote) (keywordStr("'["), keywordStr("]")) else ("[", "]")
271271
val funText = toTextLocal(tree.fun).provided(!isQuote)
272272
tree.fun match {

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 =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
528528
case New(_) | Closure(_, _, _) =>
529529
true
530530
case TypeApply(fn, _) =>
531-
if (fn.symbol.is(Erased) || fn.symbol == defn.InternalQuoted_typeQuote) true else apply(fn)
531+
if (fn.symbol.is(Erased) || fn.symbol == defn.QuotedTypeModule_apply) true else apply(fn)
532532
case Apply(fn, args) =>
533533
def isKnownPureOp(sym: Symbol) =
534534
sym.owner.isPrimitiveValueClass

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ trait QuotesAndSplices {
5858
if ctx.mode.is(Mode.Pattern) then
5959
typedQuotePattern(tree, pt, qctx)
6060
else if (tree.quoted.isType)
61-
typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuote.termRef), tree.quoted :: Nil), pt)(using quoteContext).select(nme.apply).appliedTo(qctx)
61+
typedTypeApply(untpd.TypeApply(untpd.ref(defn.QuotedTypeModule_apply.termRef), tree.quoted :: Nil), pt)(using quoteContext).select(nme.apply).appliedTo(qctx)
6262
else
6363
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuote.termRef), tree.quoted), pt)(using pushQuoteContext(qctx)).select(nme.apply).appliedTo(qctx)
6464
tree1.withSpan(tree.span)
@@ -439,7 +439,7 @@ trait QuotesAndSplices {
439439
val quoteClass = if (tree.quoted.isTerm) defn.QuotedExprClass else defn.QuotedTypeClass
440440
val quotedPattern =
441441
if (tree.quoted.isTerm) ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(defn.AnyType).appliedTo(shape).select(nme.apply).appliedTo(qctx)
442-
else ref(defn.InternalQuoted_typeQuote.termRef).appliedToTypeTree(shape).select(nme.apply).appliedTo(qctx)
442+
else ref(defn.QuotedTypeModule_apply.termRef).appliedToTypeTree(shape).select(nme.apply).appliedTo(qctx)
443443
UnApply(
444444
fun = ref(unapplySym.termRef).appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
445445
implicits = quotedPattern :: Literal(Constant(typeBindings.nonEmpty)) :: qctx :: Nil,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
5757
qctx.tpe match
5858
case tpe: Implicits.SearchFailureType => report.error(tpe.msg, ctx.source.atSpan(span))
5959
case _ =>
60-
ref(defn.InternalQuoted_typeQuote).appliedToType(t).select(nme.apply).appliedTo(qctx)
60+
ref(defn.QuotedTypeModule_apply).appliedToType(t).select(nme.apply).appliedTo(qctx)
6161
formal.argInfos match
6262
case arg :: Nil =>
6363
val deepDealias = new TypeMap:

library/src-bootstrapped/scala/internal/quoted/CompileTime.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ object CompileTime {
2020
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.exprNestedSplice`")
2121
def exprNestedSplice[T](ctx: QuoteContext)(x: ctx.Nested ?=> Expr[T]): T = ???
2222

23-
/** A type quote is desugared by the compiler into a call to this method */
24-
@compileTimeOnly("Illegal reference to `scala.internal.quoted.CompileTime.typeQuote`")
25-
def typeQuote[T <: AnyKind]: QuoteContext ?=> Type[T] = ???
26-
2723
/** Artifact of pickled type splices
2824
*
2925
* During quote reification a quote `'{ ... F[$t] ... }` will be transformed into

library/src-bootstrapped/scala/quoted/Type.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package scala.quoted
22

3+
import scala.annotation.compileTimeOnly
34
import scala.quoted.show.SyntaxHighlight
45

56
/** Quoted type (or kind) `T` */
@@ -22,6 +23,10 @@ abstract class Type[X <: AnyKind] private[scala] {
2223
/** Some basic type tags, currently incomplete */
2324
object Type {
2425

26+
/** Return a quoted.Type with the given type */
27+
@compileTimeOnly("Reference to `scala.quoted.Type.apply` was not handled by ReifyQuotes")
28+
def apply[T <: AnyKind]: QuoteContext ?=> Type[T] = ???
29+
2530
def UnitTag: QuoteContext ?=> Type[Unit] =
2631
qctx.tasty.defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]
2732

0 commit comments

Comments
 (0)