Skip to content

Commit 3ef98eb

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 71d58e9 commit 3ef98eb

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)
@@ -444,8 +444,14 @@ object Symbols {
444444
final def isClass: Boolean = isInstanceOf[ClassSymbol]
445445
final def asClass: ClassSymbol = asInstanceOf[ClassSymbol]
446446

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

450456
/** Special cased here, because it may be used on naked symbols in substituters */
451457
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
@@ -1127,11 +1127,6 @@ object Types {
11271127
loop(this)
11281128
}
11291129

1130-
private def isReferencedSymbolically(sym: Symbol)(implicit ctx: Context) =
1131-
sym.isFresh ||
1132-
sym.isClass && sym.is(Scala2x) && !sym.owner.is(Package) ||
1133-
ctx.phase.symbolicRefs
1134-
11351130
/** The type <this . name> , reduced if possible */
11361131
def select(name: Name)(implicit ctx: Context): Type = name match {
11371132
case name: TermName => TermRef(this, name)
@@ -2071,7 +2066,7 @@ object Types {
20712066
* signature, if denotation is not yet completed.
20722067
*/
20732068
def apply(prefix: Type, designator: TermName, denot: Denotation)(implicit ctx: Context): TermRef = {
2074-
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
2069+
if ((prefix eq NoPrefix) || denot.symbol.isReferencedSymbolically || symbolicRefs)
20752070
withSym(prefix, denot.symbol.asTerm)
20762071
else denot match {
20772072
case denot: SymDenotation if denot.isCompleted => withSig(prefix, designator, denot.signature)
@@ -2087,7 +2082,7 @@ object Types {
20872082
* (2) The name in the term ref need not be the same as the name of the Symbol.
20882083
*/
20892084
def withSymAndName(prefix: Type, sym: TermSymbol, name: TermName)(implicit ctx: Context): TermRef =
2090-
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs)
2085+
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically|| symbolicRefs)
20912086
apply(prefix, sym)
20922087
else if (sym.defRunId != NoRunId && sym.isCompleted)
20932088
withSig(prefix, name, sym.signature).withSym(sym)
@@ -2102,7 +2097,7 @@ object Types {
21022097
* (which must be completed).
21032098
*/
21042099
def withSig(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef =
2105-
if ((prefix eq NoPrefix) || sym.isFresh || symbolicRefs) apply(prefix, sym)
2100+
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically || symbolicRefs) apply(prefix, sym)
21062101
else withSig(prefix, sym.name, sym.signature).withSym(sym)
21072102

21082103
/** Create a term ref with given prefix, name and signature */
@@ -2111,7 +2106,7 @@ object Types {
21112106

21122107
/** Create a term ref with given prefix, name, signature, and initial denotation */
21132108
def withSigAndDenot(prefix: Type, name: TermName, sig: Signature, denot: Denotation)(implicit ctx: Context): TermRef = {
2114-
if ((prefix eq NoPrefix) || denot.symbol.isFresh || symbolicRefs)
2109+
if ((prefix eq NoPrefix) || denot.symbol.isReferencedSymbolically || symbolicRefs)
21152110
apply(prefix, denot.symbol.asTerm)
21162111
else
21172112
withSig(prefix, name, sig)
@@ -2134,12 +2129,12 @@ object Types {
21342129
* (2) The name in the type ref need not be the same as the name of the Symbol.
21352130
*/
21362131
def withSymAndName(prefix: Type, sym: TypeSymbol, name: TypeName)(implicit ctx: Context): TypeRef =
2137-
if ((prefix eq NoPrefix) || sym.isFresh) apply(prefix, sym)
2132+
if ((prefix eq NoPrefix) || sym.isReferencedSymbolically) apply(prefix, sym)
21382133
else apply(prefix, name).withSym(sym)
21392134

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

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)