Skip to content

Commit 1ec7fe5

Browse files
committed
Use a general criterion for when to refer to symbols symbolically
Also - rename Fresh flag to NonMember - update criterion for phases where refs are symbolic. This used to be just before erasure (at resolveSuper) but then other phases were inserted after resolveSuper and the test became outdated. It's more robust now.
1 parent df0057c commit 1ec7fe5

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ object Flags {
359359

360360
// Flags following this one are not pickled
361361

362-
/** Symbol always defines a fresh named type */
363-
final val Fresh = commonFlag(45, "<fresh>")
362+
/** Symbol is not a member of its owner */
363+
final val NonMember = commonFlag(45, "<non-member>")
364364

365365
/** Denotation is in train of being loaded and completed, used to catch cyclic dependencies */
366366
final val Touched = commonFlag(48, "<touched>")
@@ -446,7 +446,7 @@ object Flags {
446446
Module | Package | Deferred | MethodOrHKCommon | Param | ParamAccessor.toCommonFlags |
447447
Scala2ExistentialCommon | Mutable.toCommonFlags | Touched | JavaStatic |
448448
CovariantOrOuter | ContravariantOrLabel | CaseAccessor.toCommonFlags |
449-
Fresh | Erroneous | ImplicitCommon | Permanent | Synthetic |
449+
NonMember | Erroneous | ImplicitCommon | Permanent | Synthetic |
450450
SuperAccessorOrScala2x | Inline
451451

452452
/** Flags guaranteed to be set upon symbol creation, or, if symbol is a top-level

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ object Phases {
359359
myErasedTypes = prev.getClass == classOf[Erasure] || prev.erasedTypes
360360
myFlatClasses = prev.getClass == classOf[Flatten] || prev.flatClasses
361361
myRefChecked = prev.getClass == classOf[RefChecks] || prev.refChecked
362-
mySymbolicRefs = prev.getClass == classOf[ResolveSuper] || prev.symbolicRefs
362+
mySymbolicRefs = getClass == classOf[Erasure] || prev.symbolicRefs
363363
myLabelsReordered = prev.getClass == classOf[LabelDefs] || prev.labelsReordered
364364
mySameMembersStartId = if (changesMembers) id else prev.sameMembersStartId
365365
mySameParentsStartId = if (changesParents) id else prev.sameMembersStartId

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ trait Symbols { this: Context =>
246246
* would be `fld2`. There is a single local dummy per template.
247247
*/
248248
def newLocalDummy(cls: Symbol, coord: Coord = NoCoord) =
249-
newSymbol(cls, nme.localDummyName(cls), Fresh, NoType)
249+
newSymbol(cls, nme.localDummyName(cls), NonMember, NoType)
250250

251251
/** Create an import symbol pointing back to given qualifier `expr`. */
252252
def newImportSymbol(owner: Symbol, expr: Tree, coord: Coord = NoCoord): TermSymbol =
253253
newImportSymbol(owner, ImportType(expr), coord = coord)
254254

255255
/** Create an import symbol with given `info`. */
256256
def newImportSymbol(owner: Symbol, info: Type, coord: Coord): TermSymbol =
257-
newSymbol(owner, nme.IMPORT, Synthetic | Fresh, info, coord = coord)
257+
newSymbol(owner, nme.IMPORT, Synthetic | NonMember, info, coord = coord)
258258

259259
/** Create a class constructor symbol for given class `cls`. */
260260
def newConstructor(cls: ClassSymbol, flags: FlagSet, paramNames: List[TermName], paramTypes: List[Type], privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
@@ -348,7 +348,7 @@ trait Symbols { this: Context =>
348348
copy.denot = odenot.copySymDenotation(
349349
symbol = copy,
350350
owner = ttmap1.mapOwner(odenot.owner),
351-
initFlags = odenot.flags &~ Touched,// | Fresh,
351+
initFlags = odenot.flags &~ Touched,
352352
info = completer,
353353
privateWithin = ttmap1.mapOwner(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here.
354354
annotations = odenot.annotations)
@@ -447,8 +447,14 @@ object Symbols {
447447
final def isClass: Boolean = isInstanceOf[ClassSymbol]
448448
final def asClass: ClassSymbol = asInstanceOf[ClassSymbol]
449449

450-
final def isFresh(implicit ctx: Context) =
451-
lastDenot != null && (lastDenot is Fresh)
450+
final def isReferencedSymbolically(implicit ctx: Context) = {
451+
val sym = lastDenot
452+
sym != null && (
453+
(sym is NonMember)
454+
|| sym.isClass && sym.is(Scala2x) && !sym.owner.is(Package)
455+
|| sym.isTerm && ctx.phase.symbolicRefs
456+
)
457+
}
452458

453459
/** Special cased here, because it may be used on naked symbols in substituters */
454460
final def isStatic(implicit ctx: Context): Boolean =

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,6 @@ object Types {
11231123
loop(this)
11241124
}
11251125

1126-
private def isReferencedSymbolically(sym: Symbol)(implicit ctx: Context) =
1127-
sym.isFresh ||
1128-
sym.isClass && sym.is(Scala2x) && !sym.owner.is(Package) ||
1129-
ctx.phase.symbolicRefs
1130-
11311126
/** The type <this . name> , reduced if possible */
11321127
def select(name: Name)(implicit ctx: Context): Type = name match {
11331128
case name: TermName => TermRef(this, name)
@@ -2066,7 +2061,7 @@ object Types {
20662061
* signature, if denotation is not yet completed.
20672062
*/
20682063
def apply(prefix: Type, designator: TermName, denot: Denotation)(implicit ctx: Context): TermRef = {
2069-
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
2064+
if ((prefix eq NoPrefix) || denot.symbol.isReferencedSymbolically || symbolicRefs)
20702065
withSym(prefix, denot.symbol.asTerm)
20712066
else denot match {
20722067
case denot: SymDenotation if denot.isCompleted => withSig(prefix, designator, denot.signature)
@@ -2082,7 +2077,7 @@ object Types {
20822077
* (2) The name in the term ref need not be the same as the name of the Symbol.
20832078
*/
20842079
def withSymAndName(prefix: Type, sym: TermSymbol, name: TermName)(implicit ctx: Context): TermRef =
2085-
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs)
2080+
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically|| symbolicRefs)
20862081
apply(prefix, sym)
20872082
else if (sym.defRunId != NoRunId && sym.isCompleted)
20882083
withSig(prefix, name, sym.signature).withSym(sym)
@@ -2097,7 +2092,7 @@ object Types {
20972092
* (which must be completed).
20982093
*/
20992094
def withSig(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2100-
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs) apply(prefix, sym)
2095+
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically || symbolicRefs) apply(prefix, sym)
21012096
else withSig(prefix, sym.name, sym.signature).withSym(sym)
21022097

21032098
/** Create a term ref with given prefix, name and signature */
@@ -2106,7 +2101,7 @@ object Types {
21062101

21072102
/** Create a term ref with given prefix, name, signature, and initial denotation */
21082103
def withSigAndDenot(prefix: Type, name: TermName, sig: Signature, denot: Denotation)(implicit ctx: Context): TermRef = {
2109-
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
2104+
if ((prefix eq NoPrefix) || denot.symbol.isReferencedSymbolically || symbolicRefs)
21102105
apply(prefix, denot.symbol.asTerm)
21112106
else
21122107
withSig(prefix, name, sig)
@@ -2129,12 +2124,12 @@ object Types {
21292124
* (2) The name in the type ref need not be the same as the name of the Symbol.
21302125
*/
21312126
def withSymAndName(prefix: Type, sym: TypeSymbol, name: TypeName)(implicit ctx: Context): TypeRef =
2132-
if ((prefix eq NoPrefix) || sym.isFresh) apply(prefix, sym)
2127+
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically) apply(prefix, sym)
21332128
else apply(prefix, name).withSym(sym)
21342129

21352130
/** Create a type ref with given name and initial denotation */
21362131
def apply(prefix: Type, name: TypeName, denot: Denotation)(implicit ctx: Context): TypeRef = {
2137-
if ((prefix eq NoPrefix) || denot.symbol.isFresh) withSym(prefix, denot.symbol.asType)
2132+
if ((prefix eq NoPrefix) || denot.symbol.isReferencedSymbolically) withSym(prefix, denot.symbol.asType)
21382133
else apply(prefix, name)
21392134
} withDenot denot
21402135
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
981981
UnApply(fn, implicitArgs, argPats, patType)
982982
case REFINEDtpt =>
983983
val refineCls = ctx.newCompleteClassSymbol(
984-
ctx.owner, tpnme.REFINE_CLASS, Fresh, parents = Nil)
984+
ctx.owner, tpnme.REFINE_CLASS, NonMember, parents = Nil)
985985
typeAtAddr(start) = refineCls.typeRef
986986
val parent = readTpt()
987987
val refinements = readStats(refineCls, end)(localContext(refineCls))

0 commit comments

Comments
 (0)