Skip to content

Eliminate newNakedSymbol methods #11122

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

Closed
wants to merge 13 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
*/
private def makeStatifiedDefDef(dd: DefDef): DefDef =
val origSym = dd.symbol.asTerm
val newSym = makeStatifiedDefSymbol(origSym, origSym.name)
val newSym = makeStatifiedDefSymbol(origSym, origSym.symName)
tpd.DefDef(newSym, { paramRefss =>
val selfParamRef :: regularParamRefs = paramRefss.head
val enclosingClass = origSym.owner.asClass
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ final class JSDefinitions()(using Context) {

/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
private def scalajsClassName(cls: Symbol)(using Context): TypeName =
if (cls.isClass && cls.owner == ScalaJSJSPackageClass) cls.asClass.name
if (cls.isClass && cls.owner == ScalaJSJSPackageClass) cls.name.asTypeName
else EmptyTypeName

/** Is the given `cls` a class of the form `scala.scalajs.js.prefixN` where
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object desugar {
/** A derived type definition watching `sym` */
def derivedTypeParamWithVariance(sym: TypeSymbol)(using Context): TypeDef =
val variance = VarianceFlags & sym.flags
TypeDef(sym.name, DerivedFromParamTree().watching(sym)).withFlags(TypeParam | Synthetic | variance)
TypeDef(sym.symName, DerivedFromParamTree().watching(sym)).withFlags(TypeParam | Synthetic | variance)

/** A value definition copied from `vdef` with a tpt typetree derived from it */
def derivedTermParam(vdef: ValDef)(using Context): ValDef =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TreeTypeMap(
private val mapOwnerThis = new TypeMap {
private def mapPrefix(from: List[Symbol], to: List[Symbol], tp: Type): Type = from match {
case Nil => tp
case (cls: ClassSymbol) :: from1 => mapPrefix(from1, to.tail, tp.substThis(cls, to.head.thisType))
case (cls: ClassSymbol @unchecked) :: from1 => mapPrefix(from1, to.tail, tp.substThis(cls, to.head.thisType))
case _ :: from1 => mapPrefix(from1, to.tail, tp)
}
def apply(tp: Type): Type = tp match {
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}

def ValDef(sym: TermSymbol, rhs: LazyTree = EmptyTree)(using Context): ValDef =
ta.assignType(untpd.ValDef(sym.name, TypeTree(sym.info), rhs), sym)
ta.assignType(untpd.ValDef(sym.symName, TypeTree(sym.info), rhs), sym)

def SyntheticValDef(name: TermName, rhs: Tree)(using Context): ValDef =
ValDef(newSymbol(ctx.owner, name, Synthetic, rhs.tpe.widen, coord = rhs.span), rhs)
Expand All @@ -211,7 +211,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
sym.setParamss(paramss)
ta.assignType(
untpd.DefDef(
sym.name,
sym.symName,
paramss.map {
case TypeSymbols(params) => params.map(param => TypeDef(param).withSpan(param.span))
case TermSymbols(params) => params.map(param => ValDef(param).withSpan(param.span))
Expand Down Expand Up @@ -284,7 +284,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
end DefDef

def TypeDef(sym: TypeSymbol)(using Context): TypeDef =
ta.assignType(untpd.TypeDef(sym.name, TypeTree(sym.info)), sym)
ta.assignType(untpd.TypeDef(sym.symName, TypeTree(sym.info)), sym)

def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(using Context): TypeDef = {
val firstParent :: otherParents = cls.info.parents
Expand Down Expand Up @@ -320,7 +320,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
.orElse(newLocalDummy(cls))
val impl = untpd.Template(constr, parents, Nil, selfType, newTypeParams ++ body)
.withType(localDummy.termRef)
ta.assignType(untpd.TypeDef(cls.name, impl), cls)
ta.assignType(untpd.TypeDef(cls.symName, impl), cls)
}

/** An anonymous class
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object Annotations {
// seems to be enough to ensure this (note that after erasure, `ctx.typer`
// will be the Erasure typer, but that doesn't seem to affect the annotation
// trees we create, so we leave it as is)
case sym: Symbol if sym.defRunId != parentCtx.runId =>
case sym: Symbol @unchecked if sym.defRunId != parentCtx.runId =>
mySym = sym.denot.current.symbol
case _ =>
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/ContextOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object ContextOps:
*/
def enter(sym: Symbol): Symbol = inContext(ctx) {
ctx.owner match
case cls: ClassSymbol => cls.classDenot.enter(sym)
case cls: ClassSymbol @unchecked => cls.classDenot.enter(sym)
case _ => ctx.scope.openForMutations.enter(sym)
sym
}
Expand Down Expand Up @@ -63,7 +63,7 @@ object ContextOps:
def inClassContext(selfInfo: TypeOrSymbol): Context = inContext(ctx) {
val localCtx: Context = ctx.fresh.setNewScope
selfInfo match {
case sym: Symbol if sym.exists && sym.name != nme.WILDCARD => localCtx.scope.openForMutations.enter(sym)
case sym: Symbol @unchecked if sym.exists && sym.name != nme.WILDCARD => localCtx.scope.openForMutations.enter(sym)
case _ =>
}
localCtx
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ class Definitions {
def isValueSubType(tref1: TypeRef, tref2: TypeRef)(using Context): Boolean =
valueTypeEnc(tref2.name) % valueTypeEnc(tref1.name) == 0
def isValueSubClass(sym1: Symbol, sym2: Symbol): Boolean =
valueTypeEnc(sym2.asClass.name) % valueTypeEnc(sym1.asClass.name) == 0
valueTypeEnc(sym2.name.asTypeName) % valueTypeEnc(sym1.name.asTypeName) == 0

@tu lazy val specialErasure: SimpleIdentityMap[Symbol, ClassSymbol] =
SimpleIdentityMap.empty[Symbol]
Expand Down
32 changes: 18 additions & 14 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ object Denotations {
*
* @param symbol The referencing symbol, or NoSymbol is none exists
*/
abstract class Denotation(val symbol: Symbol, protected var myInfo: Type) extends PreDenotation with printing.Showable {
abstract class Denotation(_symbol: SymbolImpl, protected var myInfo: Type) extends PreDenotation with printing.Showable {
type AsSeenFromResult <: Denotation

val symbol: Symbol =
if _symbol == null then this.asInstanceOf[Symbol]
else _symbol.fromSymbolImpl

/** The type info.
* The info is an instance of TypeType iff this is a type denotation
* Uncompleted denotations set myInfo to a LazyType.
Expand Down Expand Up @@ -477,7 +481,7 @@ object Denotations {
val jointInfo = infoMeet(info1, info2, safeIntersection)
if jointInfo.exists then
val sym = if symScore >= 0 then sym1 else sym2
JointRefDenotation(sym, jointInfo, denot1.validFor & denot2.validFor, pre)
JointRefDenotation(sym.toSymbolImpl, jointInfo, denot1.validFor & denot2.validFor, pre)
else if symScore == 2 then denot1
else if symScore == -2 then denot2
else
Expand Down Expand Up @@ -568,10 +572,10 @@ object Denotations {
end infoMeet

/** A non-overloaded denotation */
abstract class SingleDenotation(symbol: Symbol, initInfo: Type) extends Denotation(symbol, initInfo) {
abstract class SingleDenotation(_symbol: SymbolImpl, initInfo: Type) extends Denotation(_symbol, initInfo) {
protected def newLikeThis(symbol: Symbol, info: Type, pre: Type): SingleDenotation

final def name(using Context): Name = symbol.name
def name(using Context): Name = symbol.name

/** If this is not a SymDenotation: The prefix under which the denotation was constructed.
* NoPrefix for SymDenotations.
Expand Down Expand Up @@ -771,7 +775,7 @@ object Denotations {
assert(!d.is(Package), s"illegal transformation of package denotation by transformer $transformer")
case _ =>

def escapeToNext = nextDefined.ensuring(_.validFor != Nowhere)
def escapeToNext = nextDefined.ensuring(_.validFor != Nowhere, name)

def toNewRun =
util.Stats.record("current.bringForward")
Expand Down Expand Up @@ -1077,34 +1081,34 @@ object Denotations {
}
}

abstract class NonSymSingleDenotation(symbol: Symbol, initInfo: Type, override val prefix: Type) extends SingleDenotation(symbol, initInfo) {
abstract class NonSymSingleDenotation(_symbol: SymbolImpl, initInfo: Type, override val prefix: Type) extends SingleDenotation(_symbol, initInfo) {
def infoOrCompleter: Type = initInfo
def isType: Boolean = infoOrCompleter.isInstanceOf[TypeType]
}

class UniqueRefDenotation(
symbol: Symbol,
_symbol: SymbolImpl,
initInfo: Type,
initValidFor: Period,
prefix: Type) extends NonSymSingleDenotation(symbol, initInfo, prefix) {
prefix: Type) extends NonSymSingleDenotation(_symbol, initInfo, prefix) {
validFor = initValidFor
override def hasUniqueSym: Boolean = true
protected def newLikeThis(s: Symbol, i: Type, pre: Type): SingleDenotation =
new UniqueRefDenotation(s, i, validFor, pre)
new UniqueRefDenotation(s.toSymbolImpl, i, validFor, pre)
}

class JointRefDenotation(
symbol: Symbol,
_symbol: SymbolImpl,
initInfo: Type,
initValidFor: Period,
prefix: Type) extends NonSymSingleDenotation(symbol, initInfo, prefix) {
prefix: Type) extends NonSymSingleDenotation(_symbol, initInfo, prefix) {
validFor = initValidFor
override def hasUniqueSym: Boolean = false
protected def newLikeThis(s: Symbol, i: Type, pre: Type): SingleDenotation =
new JointRefDenotation(s, i, validFor, pre)
new JointRefDenotation(s.toSymbolImpl, i, validFor, pre)
}

class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol, NoType, NoType) {
class ErrorDenotation(using Context) extends NonSymSingleDenotation(NoSymbol.toSymbolImpl, NoType, NoType) {
override def exists: Boolean = false
override def hasUniqueSym: Boolean = false
validFor = Period.allInRun(ctx.runId)
Expand Down Expand Up @@ -1171,7 +1175,7 @@ object Denotations {

/** An overloaded denotation consisting of the alternatives of both given denotations.
*/
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol.toSymbolImpl, NoType) with MultiPreDenotation {
final def infoOrCompleter: Type = multiHasNot("info")
final def validFor: Period = denot1.validFor & denot2.validFor
final def isType: Boolean = false
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ final class ProperGadtConstraint private(

private def externalize(param: TypeParamRef)(using Context): Type =
reverseMapping(param) match {
case sym: Symbol => sym.typeRef
case sym: Symbol @unchecked => sym.typeRef
case null => param
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Names {
/** A common superclass of Name and Symbol. After bootstrap, this should be
* just the type alias Name | Symbol
*/
abstract class Designator
trait Designator

/** A name if either a term name or a type name. Term names can be simple
* or derived. A simple term name is essentially an interned string stored
Expand Down
Loading