Skip to content

Remove support for symbol literal singleton types #6764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,9 @@ object desugar {
case PolyFunction(targs, body) =>
makePolyFunction(targs, body) orElse tree
case SymbolLit(str) =>
Literal(Constant(scala.Symbol(str)))
Apply(
ref(defn.ScalaSymbolClass.companionModule.termRef),
Literal(Constant(str)) :: Nil)
case InterpolatedString(id, segments) =>
val strs = segments map {
case ts: Thicket => ts.trees.head
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ object Constants {
final val ClazzTag = 12
// For supporting java enumerations inside java annotations (see ClassfileParser)
final val EnumTag = 13
final val ScalaSymbolTag = 14

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

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

def typeValue: Type = value.asInstanceOf[Type]
def symbolValue: Symbol = value.asInstanceOf[Symbol]
def scalaSymbolValue: scala.Symbol = value.asInstanceOf[scala.Symbol]

/**
* Consider two `NaN`s to be identical, despite non-equality
Expand Down Expand Up @@ -241,7 +238,6 @@ object Constants {
def apply(x: Char): Constant = new Constant(x, CharTag)
def apply(x: Type): Constant = new Constant(x, ClazzTag)
def apply(x: Symbol): Constant = new Constant(x, EnumTag)
def apply(x: scala.Symbol): Constant = new Constant(x, ScalaSymbolTag)
def apply(value: Any): Constant =
new Constant(value,
value match {
Expand All @@ -258,7 +254,6 @@ object Constants {
case x: Char => CharTag
case x: Type => ClazzTag
case x: Symbol => EnumTag
case x: scala.Symbol => ScalaSymbolTag
}
)

Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,6 @@ class Definitions {

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

@threadUnsafe lazy val DynamicType: TypeRef = ctx.requiredClassRef("scala.Dynamic")
def DynamicClass(implicit ctx: Context): ClassSymbol = DynamicType.symbol.asClass
Expand Down
7 changes: 2 additions & 5 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ Standard-Section: "ASTs" TopLevelStat*
NULLconst -- null
CLASSconst Type -- classOf[Type]
ENUMconst Path -- An enum constant
SYMBOLconst NameRef -- A symbol literal (todo: drop?)

Type = Path -- Paths represent both types and terms
TYPEREFdirect sym_ASTRef -- A reference to a local symbol (without a prefix). Reference is to definition node of symbol.
Expand Down Expand Up @@ -250,7 +249,7 @@ Standard Section: "Comments" Comment*
object TastyFormat {

final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion: Int = 14
val MajorVersion: Int = 15
val MinorVersion: Int = 0

/** Tags used to serialize names */
Expand Down Expand Up @@ -352,7 +351,6 @@ object TastyFormat {
final val STRINGconst = 64
final val IMPORTED = 65
final val RENAMED = 66
final val SYMBOLconst = 67

// Cat. 3: tag AST

Expand Down Expand Up @@ -462,7 +460,7 @@ object TastyFormat {
/** Useful for debugging */
def isLegalTag(tag: Int): Boolean =
firstSimpleTreeTag <= tag && tag <= EXPORTED ||
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
firstNatTreeTag <= tag && tag <= RENAMED ||
firstASTTreeTag <= tag && tag <= BOUNDED ||
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
firstLengthTreeTag <= tag && tag <= MATCHtpt ||
Expand Down Expand Up @@ -636,7 +634,6 @@ object TastyFormat {
case SUPER => "SUPER"
case CLASSconst => "CLASSconst"
case ENUMconst => "ENUMconst"
case SYMBOLconst => "SYMBOLconst"
case SINGLETONtpt => "SINGLETONtpt"
case SUPERtype => "SUPERtype"
case TERMREFin => "TERMREFin"
Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ class TreePickler(pickler: TastyPickler) {
case EnumTag =>
writeByte(ENUMconst)
pickleType(c.symbolValue.termRef)
case ScalaSymbolTag =>
writeByte(SYMBOLconst)
pickleName(c.scalaSymbolValue.name.toTermName)
}

def pickleType(tpe0: Type, richTypes: Boolean = false)(implicit ctx: Context): Unit = {
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ class TreeUnpickler(reader: TastyReader,
Constant(readType())
case ENUMconst =>
Constant(readTermRef().termSymbol)
case SYMBOLconst =>
Constant(scala.Symbol(readName().toString))
}

/** Read a type */
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ object Tokens extends TokensCommon {
final val allTokens: TokenSet = tokenRange(minToken, maxToken)

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

final val atomicExprTokens: TokenSet = literalTokens | identifierTokens | BitSet(
USCORE, NULL, THIS, SUPER, TRUE, FALSE, RETURN, QUOTEID, XMLSTART)
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ class PlainPrinter(_ctx: Context) extends Printer {
case CharTag => literalText(s"'${escapedChar(const.charValue)}'")
case LongTag => literalText(const.longValue.toString + "L")
case EnumTag => literalText(const.symbolValue.name.toString)
case ScalaSymbolTag => literalText("'" + const.scalaSymbolValue.name.toString)
case _ => literalText(String.valueOf(const.value))
}

Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,6 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
if (x.tag == Constants.StringTag) Some(x.stringValue) else None
def matchConstant_ClassTag(x: Constant): Option[Type] =
if (x.tag == Constants.ClazzTag) Some(x.typeValue) else None
def matchConstant_Symbol(x: Constant): Option[scala.Symbol] =
if (x.tag == Constants.ScalaSymbolTag) Some(x.scalaSymbolValue) else None

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

//
// SYMBOLS
Expand Down
4 changes: 0 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,6 @@ object Erasure {
tree.withType(tree.typeOpt)
else if (tree.const.tag == Constants.ClazzTag)
Literal(Constant(erasure(tree.const.typeValue)))
else if (tree.const.tag == Constants.ScalaSymbolTag)
ref(defn.ScalaSymbolModule)
.select(defn.ScalaSymbolModule_apply)
.appliedTo(Literal(Constant(tree.const.scalaSymbolValue.name)))
else
super.typedLiteral(tree)

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ SimpleLiteral ::= [‘-’] integerLiteral
| booleanLiteral
| characterLiteral
| stringLiteral
| symbolLiteral
Literal ::= SimpleLiteral
| processedStringLiteral
| symbolLiteral
| ‘null’

QualId ::= id {‘.’ id}
Expand Down
11 changes: 0 additions & 11 deletions library/src/scala/tasty/reflect/ConstantOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,5 @@ trait ConstantOps extends Core {
def unapply(constant: Constant): Option[Type] =
kernel.matchConstant_ClassTag(constant)
}

/** Module of scala.Symbol literals */
object Symbol {
/** scala.Symbol literal */
def apply(x: scala.Symbol): Constant =
kernel.Constant_Symbol_apply(x)

/** Extractor for scala.Symbol literals */
def unapply(constant: Constant): Option[scala.Symbol] =
kernel.matchConstant_Symbol(constant)
}
}
}
2 changes: 0 additions & 2 deletions library/src/scala/tasty/reflect/Kernel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,6 @@ trait Kernel {
def matchConstant_Double(constant: Constant): Option[Double]
def matchConstant_String(constant: Constant): Option[String]
def matchConstant_ClassTag(constant: Constant): Option[Type]
def matchConstant_Symbol(constant: Constant): Option[scala.Symbol]

def Constant_Unit_apply(): Constant
def Constant_Null_apply(): Constant
Expand All @@ -1198,7 +1197,6 @@ trait Kernel {
def Constant_Double_apply(x: Double): Constant
def Constant_String_apply(x: String): Constant
def Constant_ClassTag_apply(x: scala.reflect.ClassTag[_]): Constant
def Constant_Symbol_apply(x: scala.Symbol): Constant

//
// SYMBOLS
Expand Down
3 changes: 0 additions & 3 deletions library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ trait Printers
case Constant.Double(value) => this += "Constant.Double(" += value += ")"
case Constant.String(value) => this += "Constant.String(\"" += value += "\")"
case Constant.ClassTag(value) => this += "Constant.ClassTag(" += value += ")"
case Constant.Symbol(value) => this += "Constant.Symbol('" += value.name += ")"
}

def visitType(x: TypeOrBounds): Buffer = x match {
Expand Down Expand Up @@ -1390,8 +1389,6 @@ trait Printers
case Constant.ClassTag(v) =>
this += "classOf"
inSquare(printType(v))
case Constant.Symbol(v) =>
this += highlightLiteral("'" + v.name)
}

def printTypeOrBoundsTree(tpt: Tree)(implicit elideThis: Option[Symbol] = None): Buffer = tpt match {
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/singletons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ object Test {

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

val sym: 'sym = 'sym // error: an identifier expected, but quoted identifier found

val foo: s"abc" = "abc" // error: not a legal singleton type
}
25 changes: 0 additions & 25 deletions tests/neg/sip23-symbols.scala

This file was deleted.