Skip to content

Commit 1e9430a

Browse files
authored
Merge pull request #4366 from dotty-staging/tasty/no-specialops
Remove references to the magic package <special-ops> from TASTY
2 parents 747c2ae + 72b5b57 commit 1e9430a

File tree

14 files changed

+49
-51
lines changed

14 files changed

+49
-51
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,11 @@ object desugar {
10931093
val desugared = tree match {
10941094
case SymbolLit(str) =>
10951095
Literal(Constant(scala.Symbol(str)))
1096+
case Quote(expr) =>
1097+
if (expr.isType)
1098+
TypeApply(ref(defn.QuotedType_applyR), List(expr))
1099+
else
1100+
Apply(ref(defn.QuotedExpr_applyR), expr)
10961101
case InterpolatedString(id, segments) =>
10971102
val strs = segments map {
10981103
case ts: Thicket => ts.trees.head

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

-1
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,6 @@ object Trees {
908908
* so that they selectively retype themselves. Retyping needs a context.
909909
*/
910910
abstract class TreeCopier {
911-
912911
def postProcess(tree: Tree, copied: untpd.Tree): copied.ThisTree[T]
913912
def postProcess(tree: Tree, copied: untpd.MemberDef): copied.ThisTree[T]
914913

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

+8-12
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,6 @@ class Definitions {
324324
lazy val throwMethod = enterMethod(OpsPackageClass, nme.THROWkw,
325325
MethodType(List(ThrowableType), NothingType))
326326

327-
/** Method representing a term quote */
328-
lazy val quoteMethod = enterPolyMethod(OpsPackageClass, nme.QUOTE, 1,
329-
pt => MethodType(pt.paramRefs(0) :: Nil, QuotedExprType.appliedTo(pt.paramRefs(0) :: Nil)),
330-
useCompleter = true)
331-
332-
/** Method representing a type quote */
333-
lazy val typeQuoteMethod = enterPolyMethod(OpsPackageClass, nme.TYPE_QUOTE, 1,
334-
pt => QuotedTypeType.appliedTo(pt.paramRefs(0) :: Nil),
335-
useCompleter = true)
336-
337327
lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol(
338328
ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef))
339329
def NothingType = NothingClass.typeRef
@@ -630,6 +620,11 @@ class Definitions {
630620
lazy val QuotedExprType = ctx.requiredClassRef("scala.quoted.Expr")
631621
def QuotedExprClass(implicit ctx: Context) = QuotedExprType.symbol.asClass
632622

623+
lazy val QuotedExprModuleType = ctx.requiredModuleRef("scala.quoted.Expr")
624+
def QuotedExprModule(implicit ctx: Context) = QuotedExprModuleType.symbol
625+
lazy val QuotedExpr_applyR = QuotedExprModule.requiredMethodRef(nme.apply)
626+
def QuotedExpr_apply(implicit ctx: Context) = QuotedExpr_applyR.symbol
627+
633628
lazy val QuotedExpr_spliceR = QuotedExprClass.requiredMethod(nme.UNARY_~)
634629
def QuotedExpr_~(implicit ctx: Context) = QuotedExpr_spliceR.symbol
635630
lazy val QuotedExpr_runR = QuotedExprClass.requiredMethodRef(nme.run)
@@ -644,7 +639,8 @@ class Definitions {
644639
lazy val QuotedType_spliceR = QuotedTypeClass.requiredType(tpnme.UNARY_~).typeRef
645640
def QuotedType_~ = QuotedType_spliceR.symbol
646641

647-
lazy val QuotedTypeModule = QuotedTypeClass.companionModule
642+
lazy val QuotedTypeModuleType = ctx.requiredModuleRef("scala.quoted.Type")
643+
def QuotedTypeModule(implicit ctx: Context) = QuotedTypeModuleType.symbol
648644
lazy val QuotedType_applyR = QuotedTypeModule.requiredMethodRef(nme.apply)
649645
def QuotedType_apply(implicit ctx: Context) = QuotedType_applyR.symbol
650646

@@ -1183,7 +1179,7 @@ class Definitions {
11831179

11841180
/** Lists core methods that don't have underlying bytecode, but are synthesized on-the-fly in every reflection universe */
11851181
lazy val syntheticCoreMethods =
1186-
AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod, quoteMethod, typeQuoteMethod)
1182+
AnyMethods ++ ObjectMethods ++ List(String_+, throwMethod)
11871183

11881184
lazy val reservedScalaClassNames: Set[Name] = syntheticScalaClasses.map(_.name).toSet
11891185

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Standard-Section: "ASTs" TopLevelStat*
7777
SELECT possiblySigned_NameRef qual_Term
7878
QUALTHIS typeIdent_Tree
7979
NEW clsType_Term
80+
THROW throwableExpr_Term
8081
NAMEDARG paramName_NameRef arg_Term
8182
APPLY Length fn_Term arg_Term*
8283
TYPEAPPLY Length fn_Term arg_Type*
@@ -225,7 +226,7 @@ Standard Section: "Positions" Assoc*
225226
object TastyFormat {
226227

227228
final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
228-
val MajorVersion = 6
229+
val MajorVersion = 7
229230
val MinorVersion = 0
230231

231232
/** Tags used to serialize names */
@@ -332,12 +333,13 @@ object TastyFormat {
332333
final val BYNAMEtype = 84
333334
final val BYNAMEtpt = 85
334335
final val NEW = 86
335-
final val IMPLICITarg = 87
336-
final val PRIVATEqualified = 88
337-
final val PROTECTEDqualified = 89
338-
final val RECtype = 90
339-
final val TYPEALIAS = 91
340-
final val SINGLETONtpt = 92
336+
final val THROW = 87
337+
final val IMPLICITarg = 88
338+
final val PRIVATEqualified = 89
339+
final val PROTECTEDqualified = 90
340+
final val RECtype = 91
341+
final val TYPEALIAS = 92
342+
final val SINGLETONtpt = 93
341343

342344
// Cat. 4: tag Nat AST
343345

@@ -560,6 +562,7 @@ object TastyFormat {
560562
case APPLY => "APPLY"
561563
case TYPEAPPLY => "TYPEAPPLY"
562564
case NEW => "NEW"
565+
case THROW => "THROW"
563566
case TYPED => "TYPED"
564567
case NAMEDARG => "NAMEDARG"
565568
case ASSIGN => "ASSIGN"

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,15 @@ class TreePickler(pickler: TastyPickler) {
361361
pickleTree(qual)
362362
}
363363
case Apply(fun, args) =>
364-
writeByte(APPLY)
365-
withLength {
366-
pickleTree(fun)
367-
args.foreach(pickleTree)
364+
if (fun.symbol eq defn.throwMethod) {
365+
writeByte(THROW)
366+
pickleTree(args.head)
367+
} else {
368+
writeByte(APPLY)
369+
withLength {
370+
pickleTree(fun)
371+
args.foreach(pickleTree)
372+
}
368373
}
369374
case TypeApply(fun, args) =>
370375
writeByte(TYPEAPPLY)

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

+2
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@ class TreeUnpickler(reader: TastyReader,
974974
untpd.This(qual).withType(ThisType.raw(tref))
975975
case NEW =>
976976
New(readTpt())
977+
case THROW =>
978+
Throw(readTerm())
977979
case SINGLETONtpt =>
978980
SingletonTypeTree(readTerm())
979981
case BYNAMEtpt =>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) {
6060
}
6161

6262
override protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = {
63-
if (tree.symbol eq defn.quoteMethod) "'"
64-
else if (tree.symbol eq defn.typeQuoteMethod) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]"
63+
if (tree.symbol eq defn.QuotedExpr_apply) "'"
64+
else if (tree.symbol eq defn.QuotedType_apply) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]"
6565
else super.typeApplyText(tree)
6666
}
6767
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
357357
* core and splices as arguments.
358358
*/
359359
private def quotation(body: Tree, quote: Tree)(implicit ctx: Context): Tree = {
360-
val isType = quote.symbol eq defn.typeQuoteMethod
360+
val isType = quote.symbol eq defn.QuotedType_apply
361361
if (body.symbol.isSplice) {
362362
// simplify `'(~x)` to `x` and then transform it
363363
val Select(splice, _) = body
@@ -366,8 +366,8 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
366366
else if (level > 0) {
367367
val body1 = nested(isQuote = true).transform(body)
368368
// Keep quotes as trees to reduce pickled size and have a Expr.show without pickled quotes
369-
if (isType) ref(defn.typeQuoteMethod).appliedToType(body1.tpe.widen)
370-
else ref(defn.quoteMethod).appliedToType(body1.tpe.widen).appliedTo(body1)
369+
if (isType) ref(defn.QuotedType_apply).appliedToType(body1.tpe.widen)
370+
else ref(defn.QuotedExpr_apply).appliedToType(body1.tpe.widen).appliedTo(body1)
371371
}
372372
else body match {
373373
case body: RefTree if isCaptured(body, level + 1) =>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class SymUtils(val self: Symbol) extends AnyVal {
175175

176176
/** Is symbol a quote operation? */
177177
def isQuote(implicit ctx: Context): Boolean =
178-
self == defn.quoteMethod || self == defn.typeQuoteMethod
178+
self == defn.QuotedExpr_apply || self == defn.QuotedType_apply
179179

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ trait Implicits { self: Typer =>
587587
}
588588
}
589589
val tag = bindFreeVars(arg)
590-
if (bindFreeVars.ok) ref(defn.typeQuoteMethod).appliedToType(tag)
590+
if (bindFreeVars.ok) ref(defn.QuotedType_apply).appliedToType(tag)
591591
else EmptyTree
592592
case _ =>
593593
EmptyTree

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

-20
Original file line numberDiff line numberDiff line change
@@ -1106,25 +1106,6 @@ class Typer extends Namer
11061106
Throw(expr1).withPos(tree.pos)
11071107
}
11081108

1109-
def typedQuote(tree: untpd.Quote, pt: Type)(implicit ctx: Context): Tree = track("typedQuote") {
1110-
val untpd.Quote(body) = tree
1111-
val isType = body.isType
1112-
val resultClass = if (isType) defn.QuotedTypeClass else defn.QuotedExprClass
1113-
val proto1 = pt.baseType(resultClass) match {
1114-
case AppliedType(_, argType :: Nil) => argType
1115-
case _ => WildcardType
1116-
}
1117-
val nestedCtx = ctx.fresh.setTree(tree)
1118-
if (isType) {
1119-
val body1 = typedType(body, proto1)(nestedCtx)
1120-
ref(defn.typeQuoteMethod).appliedToTypeTrees(body1 :: Nil)
1121-
}
1122-
else {
1123-
val body1 = typed(body, proto1)(nestedCtx)
1124-
ref(defn.quoteMethod).appliedToType(body1.tpe.widen).appliedTo(body1)
1125-
}
1126-
}
1127-
11281109
def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(implicit ctx: Context): SeqLiteral = track("typedSeqLiteral") {
11291110
val elemProto = pt.elemType match {
11301111
case NoType => WildcardType
@@ -1805,7 +1786,6 @@ class Typer extends Namer
18051786
case tree: untpd.Super => typedSuper(tree, pt)
18061787
case tree: untpd.SeqLiteral => typedSeqLiteral(tree, pt)
18071788
case tree: untpd.Inlined => typedInlined(tree, pt)
1808-
case tree: untpd.Quote => typedQuote(tree, pt)
18091789
case tree: untpd.TypeTree => typedTypeTree(tree, pt)
18101790
case tree: untpd.SingletonTypeTree => typedSingletonTypeTree(tree)
18111791
case tree: untpd.AndTypeTree => typedAndTypeTree(tree)

library/src/scala/quoted/Expr.scala

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ sealed abstract class Expr[T] {
1010
}
1111

1212
object Expr {
13+
/** A term quote is desugared by the compiler into a call to this method */
14+
def apply[T](x: T): Expr[T] =
15+
throw new Error("Internal error: this method call should have been replaced by the compiler")
1316

1417
implicit class AsFunction[T, U](private val f: Expr[T => U]) extends AnyVal {
1518
def apply(x: Expr[T]): Expr[U] = new Exprs.FunctionAppliedTo[T, U](f, x)

library/src/scala/quoted/Type.scala

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ 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+
1317
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
1418
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
1519
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]

tests/pos/tasty/definitions.scala

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ object definitions {
7373
case Literal(value: Constant)
7474
case This(id: Option[Id])
7575
case New(tpt: TypeTree)
76+
case Throw(expr: Term)
7677
case NamedArg(name: TermName, arg: Term)
7778
case Apply(fn: Term, args: List[Term])
7879
case TypeApply(fn: Term, args: List[TypeTree])

0 commit comments

Comments
 (0)