Skip to content

Commit 1bfd25b

Browse files
authored
Merge pull request #6764 from dotty-staging/remove-symlits
Remove support for symbol literal singleton types
2 parents 907f516 + c8e5397 commit 1bfd25b

File tree

16 files changed

+10
-71
lines changed

16 files changed

+10
-71
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,9 @@ object desugar {
14611461
case PolyFunction(targs, body) =>
14621462
makePolyFunction(targs, body) orElse tree
14631463
case SymbolLit(str) =>
1464-
Literal(Constant(scala.Symbol(str)))
1464+
Apply(
1465+
ref(defn.ScalaSymbolClass.companionModule.termRef),
1466+
Literal(Constant(str)) :: Nil)
14651467
case InterpolatedString(id, segments) =>
14661468
val strs = segments map {
14671469
case ts: Thicket => ts.trees.head

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ object Constants {
2222
final val ClazzTag = 12
2323
// For supporting java enumerations inside java annotations (see ClassfileParser)
2424
final val EnumTag = 13
25-
final val ScalaSymbolTag = 14
2625

2726
class Constant(val value: Any, val tag: Int) extends printing.Showable with Product1[Any] {
2827
import java.lang.Double.doubleToRawLongBits
@@ -52,7 +51,6 @@ object Constants {
5251
case NullTag => defn.NullType
5352
case ClazzTag => defn.ClassType(typeValue)
5453
case EnumTag => defn.EnumType(symbolValue)
55-
case ScalaSymbolTag => defn.ScalaSymbolType
5654
}
5755

5856
/** We need the equals method to take account of tags as well as values.
@@ -193,7 +191,6 @@ object Constants {
193191

194192
def typeValue: Type = value.asInstanceOf[Type]
195193
def symbolValue: Symbol = value.asInstanceOf[Symbol]
196-
def scalaSymbolValue: scala.Symbol = value.asInstanceOf[scala.Symbol]
197194

198195
/**
199196
* Consider two `NaN`s to be identical, despite non-equality
@@ -241,7 +238,6 @@ object Constants {
241238
def apply(x: Char): Constant = new Constant(x, CharTag)
242239
def apply(x: Type): Constant = new Constant(x, ClazzTag)
243240
def apply(x: Symbol): Constant = new Constant(x, EnumTag)
244-
def apply(x: scala.Symbol): Constant = new Constant(x, ScalaSymbolTag)
245241
def apply(value: Any): Constant =
246242
new Constant(value,
247243
value match {
@@ -258,7 +254,6 @@ object Constants {
258254
case x: Char => CharTag
259255
case x: Type => ClazzTag
260256
case x: Symbol => EnumTag
261-
case x: scala.Symbol => ScalaSymbolTag
262257
}
263258
)
264259

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,6 @@ class Definitions {
694694

695695
@threadUnsafe lazy val ScalaSymbolType: TypeRef = ctx.requiredClassRef("scala.Symbol")
696696
def ScalaSymbolClass(implicit ctx: Context): ClassSymbol = ScalaSymbolType.symbol.asClass
697-
def ScalaSymbolModule(implicit ctx: Context): Symbol = ScalaSymbolClass.companionModule
698-
@threadUnsafe lazy val ScalaSymbolModule_applyR: TermRef = ScalaSymbolModule.requiredMethodRef(nme.apply, List(StringType))
699-
def ScalaSymbolModule_apply(implicit ctx: Context): Symbol = ScalaSymbolModule_applyR.symbol
700697

701698
@threadUnsafe lazy val DynamicType: TypeRef = ctx.requiredClassRef("scala.Dynamic")
702699
def DynamicClass(implicit ctx: Context): ClassSymbol = DynamicType.symbol.asClass

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ Standard-Section: "ASTs" TopLevelStat*
140140
NULLconst -- null
141141
CLASSconst Type -- classOf[Type]
142142
ENUMconst Path -- An enum constant
143-
SYMBOLconst NameRef -- A symbol literal (todo: drop?)
144143
145144
Type = Path -- Paths represent both types and terms
146145
TYPEREFdirect sym_ASTRef -- A reference to a local symbol (without a prefix). Reference is to definition node of symbol.
@@ -250,7 +249,7 @@ Standard Section: "Comments" Comment*
250249
object TastyFormat {
251250

252251
final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
253-
val MajorVersion: Int = 14
252+
val MajorVersion: Int = 15
254253
val MinorVersion: Int = 0
255254

256255
/** Tags used to serialize names */
@@ -352,7 +351,6 @@ object TastyFormat {
352351
final val STRINGconst = 64
353352
final val IMPORTED = 65
354353
final val RENAMED = 66
355-
final val SYMBOLconst = 67
356354

357355
// Cat. 3: tag AST
358356

@@ -462,7 +460,7 @@ object TastyFormat {
462460
/** Useful for debugging */
463461
def isLegalTag(tag: Int): Boolean =
464462
firstSimpleTreeTag <= tag && tag <= EXPORTED ||
465-
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
463+
firstNatTreeTag <= tag && tag <= RENAMED ||
466464
firstASTTreeTag <= tag && tag <= BOUNDED ||
467465
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
468466
firstLengthTreeTag <= tag && tag <= MATCHtpt ||
@@ -636,7 +634,6 @@ object TastyFormat {
636634
case SUPER => "SUPER"
637635
case CLASSconst => "CLASSconst"
638636
case ENUMconst => "ENUMconst"
639-
case SYMBOLconst => "SYMBOLconst"
640637
case SINGLETONtpt => "SINGLETONtpt"
641638
case SUPERtype => "SUPERtype"
642639
case TERMREFin => "TERMREFin"

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ class TreePickler(pickler: TastyPickler) {
130130
case EnumTag =>
131131
writeByte(ENUMconst)
132132
pickleType(c.symbolValue.termRef)
133-
case ScalaSymbolTag =>
134-
writeByte(SYMBOLconst)
135-
pickleName(c.scalaSymbolValue.name.toTermName)
136133
}
137134

138135
def pickleType(tpe0: Type, richTypes: Boolean = false)(implicit ctx: Context): Unit = {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ class TreeUnpickler(reader: TastyReader,
266266
Constant(readType())
267267
case ENUMconst =>
268268
Constant(readTermRef().termSymbol)
269-
case SYMBOLconst =>
270-
Constant(scala.Symbol(readName().toString))
271269
}
272270

273271
/** Read a type */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ object Tokens extends TokensCommon {
209209
final val allTokens: TokenSet = tokenRange(minToken, maxToken)
210210

211211
final val simpleLiteralTokens: TokenSet =
212-
tokenRange(CHARLIT, STRINGLIT) | BitSet(TRUE, FALSE, QUOTEID) // TODO: drop QUOTEID when symbol literals are gone
213-
final val literalTokens: TokenSet = simpleLiteralTokens | BitSet(INTERPOLATIONID, NULL)
212+
tokenRange(CHARLIT, STRINGLIT) | BitSet(TRUE, FALSE)
213+
final val literalTokens: TokenSet = simpleLiteralTokens | BitSet(INTERPOLATIONID, QUOTEID, NULL) // TODO: drop QUOTEID when symbol literals are gone
214214

215215
final val atomicExprTokens: TokenSet = literalTokens | identifierTokens | BitSet(
216216
USCORE, NULL, THIS, SUPER, TRUE, FALSE, RETURN, QUOTEID, XMLSTART)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
490490
case CharTag => literalText(s"'${escapedChar(const.charValue)}'")
491491
case LongTag => literalText(const.longValue.toString + "L")
492492
case EnumTag => literalText(const.symbolValue.name.toString)
493-
case ScalaSymbolTag => literalText("'" + const.scalaSymbolValue.name.toString)
494493
case _ => literalText(String.valueOf(const.value))
495494
}
496495

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,8 +1444,6 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
14441444
if (x.tag == Constants.StringTag) Some(x.stringValue) else None
14451445
def matchConstant_ClassTag(x: Constant): Option[Type] =
14461446
if (x.tag == Constants.ClazzTag) Some(x.typeValue) else None
1447-
def matchConstant_Symbol(x: Constant): Option[scala.Symbol] =
1448-
if (x.tag == Constants.ScalaSymbolTag) Some(x.scalaSymbolValue) else None
14491447

14501448
def Constant_Unit_apply(): Constant = Constants.Constant(())
14511449
def Constant_Null_apply(): Constant = Constants.Constant(null)
@@ -1459,7 +1457,6 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
14591457
def Constant_Double_apply(x: Double): Constant = Constants.Constant(x)
14601458
def Constant_String_apply(x: String): Constant = Constants.Constant(x)
14611459
def Constant_ClassTag_apply(x: scala.reflect.ClassTag[_]): Constant = Constants.Constant(x)
1462-
def Constant_Symbol_apply(x: scala.Symbol): Constant = Constants.Constant(x)
14631460

14641461
//
14651462
// SYMBOLS

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,6 @@ object Erasure {
386386
tree.withType(tree.typeOpt)
387387
else if (tree.const.tag == Constants.ClazzTag)
388388
Literal(Constant(erasure(tree.const.typeValue)))
389-
else if (tree.const.tag == Constants.ScalaSymbolTag)
390-
ref(defn.ScalaSymbolModule)
391-
.select(defn.ScalaSymbolModule_apply)
392-
.appliedTo(Literal(Constant(tree.const.scalaSymbolValue.name)))
393389
else
394390
super.typedLiteral(tree)
395391

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ SimpleLiteral ::= [‘-’] integerLiteral
121121
| booleanLiteral
122122
| characterLiteral
123123
| stringLiteral
124-
| symbolLiteral
125124
Literal ::= SimpleLiteral
126125
| processedStringLiteral
126+
| symbolLiteral
127127
| ‘null’
128128
129129
QualId ::= id {‘.’ id}

library/src/scala/tasty/reflect/ConstantOps.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,5 @@ trait ConstantOps extends Core {
141141
def unapply(constant: Constant): Option[Type] =
142142
kernel.matchConstant_ClassTag(constant)
143143
}
144-
145-
/** Module of scala.Symbol literals */
146-
object Symbol {
147-
/** scala.Symbol literal */
148-
def apply(x: scala.Symbol): Constant =
149-
kernel.Constant_Symbol_apply(x)
150-
151-
/** Extractor for scala.Symbol literals */
152-
def unapply(constant: Constant): Option[scala.Symbol] =
153-
kernel.matchConstant_Symbol(constant)
154-
}
155144
}
156145
}

library/src/scala/tasty/reflect/Kernel.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,6 @@ trait Kernel {
11841184
def matchConstant_Double(constant: Constant): Option[Double]
11851185
def matchConstant_String(constant: Constant): Option[String]
11861186
def matchConstant_ClassTag(constant: Constant): Option[Type]
1187-
def matchConstant_Symbol(constant: Constant): Option[scala.Symbol]
11881187

11891188
def Constant_Unit_apply(): Constant
11901189
def Constant_Null_apply(): Constant
@@ -1198,7 +1197,6 @@ trait Kernel {
11981197
def Constant_Double_apply(x: Double): Constant
11991198
def Constant_String_apply(x: String): Constant
12001199
def Constant_ClassTag_apply(x: scala.reflect.ClassTag[_]): Constant
1201-
def Constant_Symbol_apply(x: scala.Symbol): Constant
12021200

12031201
//
12041202
// SYMBOLS

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ trait Printers
301301
case Constant.Double(value) => this += "Constant.Double(" += value += ")"
302302
case Constant.String(value) => this += "Constant.String(\"" += value += "\")"
303303
case Constant.ClassTag(value) => this += "Constant.ClassTag(" += value += ")"
304-
case Constant.Symbol(value) => this += "Constant.Symbol('" += value.name += ")"
305304
}
306305

307306
def visitType(x: TypeOrBounds): Buffer = x match {
@@ -1390,8 +1389,6 @@ trait Printers
13901389
case Constant.ClassTag(v) =>
13911390
this += "classOf"
13921391
inSquare(printType(v))
1393-
case Constant.Symbol(v) =>
1394-
this += highlightLiteral("'" + v.name)
13951392
}
13961393

13971394
def printTypeOrBoundsTree(tpt: Tree)(implicit elideThis: Option[Symbol] = None): Buffer = tpt match {

tests/neg/singletons.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ object Test {
55

66
val n: null = null // error: Null is not a legal singleton type
77

8+
val sym: 'sym = 'sym // error: an identifier expected, but quoted identifier found
9+
810
val foo: s"abc" = "abc" // error: not a legal singleton type
911
}

tests/neg/sip23-symbols.scala

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)