Skip to content

Commit fcfab9c

Browse files
Merge pull request #6046 from dotty-staging/remove-compiletime-methods-from-expr-an-type
Move quoted.{Expr|Type}.apply to scala.internal
2 parents 9475bda + b1d637b commit fcfab9c

File tree

18 files changed

+73
-31
lines changed

18 files changed

+73
-31
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,11 +704,15 @@ class Definitions {
704704

705705
lazy val QuotedExprType: TypeRef = ctx.requiredClassRef("scala.quoted.Expr")
706706
def QuotedExprClass(implicit ctx: Context): ClassSymbol = QuotedExprType.symbol.asClass
707-
def QuotedExprModule(implicit ctx: Context): Symbol = QuotedExprClass.companionModule
708-
lazy val QuotedExpr_applyR: TermRef = QuotedExprModule.requiredMethodRef(nme.apply)
709-
def QuotedExpr_apply(implicit ctx: Context): Symbol = QuotedExpr_applyR.symbol
710707
lazy val QuotedExpr_splice : TermSymbol = QuotedExprClass.requiredMethod(nme.splice)
711708

709+
lazy val InternalQuotedModule: TermRef = ctx.requiredModuleRef("scala.internal.Quoted")
710+
def InternalQuotedModuleClass: Symbol = InternalQuotedModule.symbol
711+
lazy val InternalQuoted_exprQuoteR: TermRef = InternalQuotedModuleClass.requiredMethodRef("exprQuote".toTermName)
712+
def InternalQuoted_exprQuote(implicit ctx: Context): Symbol = InternalQuoted_exprQuoteR.symbol
713+
lazy val InternalQuoted_typeQuoteR: TermRef = InternalQuotedModuleClass.requiredMethodRef("typeQuote".toTermName)
714+
def InternalQuoted_typeQuote(implicit ctx: Context): Symbol = InternalQuoted_typeQuoteR.symbol
715+
712716
lazy val QuotedExprsModule: TermSymbol = ctx.requiredModule("scala.quoted.Exprs")
713717
def QuotedExprsClass(implicit ctx: Context): ClassSymbol = QuotedExprsModule.asClass
714718

@@ -720,8 +724,6 @@ class Definitions {
720724

721725
lazy val QuotedTypeModuleType: TermRef = ctx.requiredModuleRef("scala.quoted.Type")
722726
def QuotedTypeModule(implicit ctx: Context): Symbol = QuotedTypeModuleType.symbol
723-
lazy val QuotedType_applyR: TermRef = QuotedTypeModule.requiredMethodRef(nme.apply)
724-
def QuotedType_apply(implicit ctx: Context): Symbol = QuotedType_applyR.symbol
725727

726728
lazy val QuotedLiftableModule: TermSymbol = ctx.requiredModule("scala.quoted.Liftable")
727729
def QuotedLiftableModuleClass(implicit ctx: Context): ClassSymbol = QuotedLiftableModule.asClass

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
7474
}
7575

7676
override protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = {
77-
if (tree.symbol eq defn.QuotedExpr_apply) "'"
78-
else if (tree.symbol eq defn.QuotedType_apply) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]"
77+
if (tree.symbol eq defn.InternalQuoted_exprQuote) "'"
78+
else if (tree.symbol eq defn.InternalQuoted_typeQuote) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]"
7979
else super.typeApplyText(tree)
8080
}
8181
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
252252
("{" ~ toText(trees, "\n") ~ "}").close
253253

254254
protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = {
255-
val isQuote = tree.fun.hasType && tree.fun.symbol == defn.QuotedType_apply
255+
val isQuote = tree.fun.hasType && tree.fun.symbol == defn.InternalQuoted_typeQuote
256256
val (open, close) = if (isQuote) (keywordStr("'["), keywordStr("]")) else ("[", "]")
257257
toTextLocal(tree.fun).provided(!isQuote) ~ open ~ toTextGlobal(tree.args, ", ") ~ close
258258
}
@@ -341,7 +341,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
341341
changePrec (GlobalPrec) {
342342
keywordStr("throw ") ~ toText(args.head)
343343
}
344-
else if (fun.hasType && fun.symbol == defn.QuotedExpr_apply)
344+
else if (fun.hasType && fun.symbol == defn.InternalQuoted_exprQuote)
345345
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
346346
else
347347
toTextLocal(fun) ~ "(" ~ toTextGlobal(args, ", ") ~ ")"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class ReifyQuotes extends MacroTransform {
169169
* core and splices as arguments.
170170
*/
171171
override protected def transformQuotation(body: Tree, quote: Tree)(implicit ctx: Context): Tree = {
172-
val isType = quote.symbol eq defn.QuotedType_apply
172+
val isType = quote.symbol eq defn.InternalQuoted_typeQuote
173173
assert(!body.symbol.isSplice)
174174
if (level > 0) {
175175
val body1 = nested(isQuote = true).transform(body)(quoteContext)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ object Splicer {
307307
protected def unexpectedTree(tree: Tree)(implicit env: Env): Result
308308

309309
protected final def interpretTree(tree: Tree)(implicit env: Env): Result = tree match {
310-
case Apply(TypeApply(fn, _), quoted :: Nil) if fn.symbol == defn.QuotedExpr_apply =>
310+
case Apply(TypeApply(fn, _), quoted :: Nil) if fn.symbol == defn.InternalQuoted_exprQuote =>
311311
val quoted1 = quoted match {
312312
case quoted: Ident if quoted.symbol.is(InlineByNameProxy) =>
313313
// inline proxy for by-name parameter
@@ -317,7 +317,7 @@ object Splicer {
317317
}
318318
interpretQuote(quoted1)
319319

320-
case TypeApply(fn, quoted :: Nil) if fn.symbol == defn.QuotedType_apply =>
320+
case TypeApply(fn, quoted :: Nil) if fn.symbol == defn.InternalQuoted_typeQuote =>
321321
interpretTypeQuote(quoted)
322322

323323
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
@@ -153,7 +153,7 @@ class SymUtils(val self: Symbol) extends AnyVal {
153153

154154
/** Is symbol a quote operation? */
155155
def isQuote(implicit ctx: Context): Boolean =
156-
self == defn.QuotedExpr_apply || self == defn.QuotedType_apply
156+
self == defn.InternalQuoted_exprQuote || self == defn.InternalQuoted_typeQuote
157157

158158
/** Is symbol a splice operation? */
159159
def isSplice(implicit ctx: Context): Boolean =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,10 @@ trait Implicits { self: Typer =>
678678
}
679679
}
680680
val tag = bindFreeVars(arg)
681-
if (bindFreeVars.ok) ref(defn.QuotedType_apply).appliedToType(tag)
681+
if (bindFreeVars.ok) ref(defn.InternalQuoted_typeQuote).appliedToType(tag)
682682
else EmptyTree
683683
case arg :: Nil if ctx.inInlineMethod =>
684-
ref(defn.QuotedType_apply).appliedToType(arg)
684+
ref(defn.InternalQuoted_typeQuote).appliedToType(arg)
685685
case _ =>
686686
EmptyTree
687687
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,9 +1935,9 @@ class Typer extends Namer
19351935
def typedQuote(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = track("typedQuote") {
19361936
val tree1 =
19371937
if (tree.t.isType)
1938-
typedTypeApply(untpd.TypeApply(untpd.ref(defn.QuotedType_applyR), List(tree.t)), pt)(quoteContext)
1938+
typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), List(tree.t)), pt)(quoteContext)
19391939
else
1940-
typedApply(untpd.Apply(untpd.ref(defn.QuotedExpr_applyR), tree.t), pt)(quoteContext)
1940+
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuoteR), tree.t), pt)(quoteContext)
19411941
tree1.withSpan(tree.span)
19421942
}
19431943

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala.internal
2+
3+
import scala.quoted._
4+
5+
object Quoted {
6+
7+
/** A term quote is desugared by the compiler into a call to this method */
8+
def exprQuote[T](x: T): Expr[T] =
9+
throw new Error("Internal error: this method call should have been replaced by the compiler")
10+
11+
/** A type quote is desugared by the compiler into a call to this method */
12+
def typeQuote[T <: AnyKind]: Type[T] =
13+
throw new Error("Internal error: this method call should have been replaced by the compiler")
14+
15+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ sealed abstract class Type[T <: AnyKind] {
1010

1111
/** Some basic type tags, currently incomplete */
1212
object Type {
13-
/** A term quote is desugared by the compiler into a call to this method */
14-
def apply[T <: AnyKind]: Type[T] =
15-
throw new Error("Internal error: this method call should have been replaced by the compiler")
1613

1714
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
1815
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala.internal
2+
3+
import scala.quoted._
4+
5+
object Quoted {
6+
7+
/** A term quote is desugared by the compiler into a call to this method */
8+
def exprQuote[T](x: T): Expr[T] =
9+
throw new Error("Internal error: this method call should have been replaced by the compiler")
10+
11+
/** A type quote is desugared by the compiler into a call to this method */
12+
def typeQuote[T/* <: AnyKind */]: Type[T] =
13+
throw new Error("Internal error: this method call should have been replaced by the compiler")
14+
15+
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ sealed abstract class Type[T] {
1010

1111
/** Some basic type tags, currently incomplete */
1212
object Type {
13-
/** A term quote is desugared by the compiler into a call to this method */
14-
def apply[T]: Type[T] =
15-
throw new Error("Internal error: this method call should have been replaced by the compiler")
16-
1713
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
1814
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
1915
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]

library/src/scala/quoted/Expr.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ sealed abstract class Expr[+T] {
1818
}
1919

2020
object Expr {
21-
/** A term quote is desugared by the compiler into a call to this method */
22-
def apply[T](x: T): Expr[T] =
23-
throw new Error("Internal error: this method call should have been replaced by the compiler")
2421

2522
// TODO simplify using new extension methods
2623

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,26 @@ trait Printers
784784
this += "throw "
785785
printTree(expr)
786786

787+
case Term.Apply(fn, args) if fn.symbol.fullName == "scala.internal.Quoted$.exprQuote" =>
788+
args.head match {
789+
case Term.Block(stats, expr) =>
790+
this += "'{"
791+
indented {
792+
this += lineBreak()
793+
printFlatBlock(stats, expr)
794+
}
795+
this += lineBreak() += "}"
796+
case _ =>
797+
this += "'{"
798+
printTree(args.head)
799+
this += "}"
800+
}
801+
802+
case Term.TypeApply(fn, args) if fn.symbol.fullName == "scala.internal.Quoted$.typeQuote" =>
803+
this += "'["
804+
printTypeTree(args.head)
805+
this += "]"
806+
787807
case Term.Apply(fn, args) =>
788808
fn match {
789809
case Term.Select(Term.This(_), "<init>") => this += "this" // call to constructor inside a constructor
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
scala.quoted.Expr.apply[scala.Int](3)
1+
'{3}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4)
2+
val a: scala.quoted.Expr[scala.Int] = '{4}
33
a
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
val t: scala.quoted.Type[scala.Predef.String] = scala.quoted.Type.apply[scala.Predef.String]
2+
val t: scala.quoted.Type[scala.Predef.String] = '[scala.Predef.String]
33

44
(t: scala.quoted.Type[scala.Predef.String])
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
val a: scala.quoted.Expr[scala.Int] = scala.quoted.Expr.apply[scala.Int](4)
2+
val a: scala.quoted.Expr[scala.Int] = '{4}
33
a
44
}

0 commit comments

Comments
 (0)