Skip to content

Commit 759af1e

Browse files
committed
Adress reviewers comments
Major changes - Drop -Yupdate-stale and simplify bringForward accordingly - Make designator a private field of TypeRef and TermRef
1 parent 2524788 commit 759af1e

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class ScalaSettings extends Settings.SettingGroup {
106106
val YkeepComments = BooleanSetting("-Ykeep-comments", "Keep comments when scanning source files.")
107107
val YforceSbtPhases = BooleanSetting("-Yforce-sbt-phases", "Run the phases used by sbt for incremental compilation (ExtractDependencies and ExtractAPI) even if the compiler is ran outside of sbt, for debugging.")
108108
val YdumpSbtInc = BooleanSetting("-Ydump-sbt-inc", "For every compiled foo.scala, output the API representation and dependencies used for sbt incremental compilation in foo.inc, implies -Yforce-sbt-phases.")
109-
val YupdateStale = BooleanSetting("-Yupdate-stale", "Automically update stale top-level classes and objects to latest version")
110109
val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)")
111110
val YretainTrees = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
112111
val YshowTreeIds = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,7 @@ object Denotations {
776776
* if denotation is no longer valid.
777777
* However, StaleSymbol error is not thrown in the following situations:
778778
*
779-
* - If the symbol is a toplevel class or object and -Yupdate-stale is set.
780-
* update the denotation to the new symbol with the same name instead.
781-
* - If ctx.acceptStale returns true (because we are in the IDE),
779+
* - If ctx.acceptStale returns true (e.g. because we are in the IDE),
782780
* update the symbol to the new version if it exists, or return
783781
* the old version otherwise.
784782
* - If the symbol did not have a denotation that was defined at the current phase
@@ -788,11 +786,9 @@ object Denotations {
788786
this match {
789787
case symd: SymDenotation =>
790788
if (ctx.stillValid(symd)) return updateValidity()
791-
lazy val staleOK = ctx.acceptStale(symd)
792-
if (ctx.settings.YupdateStale.value && symd.owner.is(Package) || staleOK) {
789+
if (ctx.acceptStale(symd)) {
793790
val newd = symd.owner.info.decls.lookup(symd.name)
794-
if (newd.exists) return (newd.denot: SingleDenotation).updateValidity()
795-
else if (staleOK) return updateValidity()
791+
return (newd.denot: SingleDenotation).orElse(symd).updateValidity()
796792
}
797793
case _ =>
798794
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ trait SymDenotations { this: Context =>
102102
}
103103

104104
/** Configurable: Accept stale symbol with warning if in IDE */
105+
def staleOK = Config.ignoreStaleInIDE && mode.is(Mode.Interactive)
106+
107+
/** Possibly accept stale symbol with warning if in IDE */
105108
def acceptStale(denot: SingleDenotation): Boolean =
106-
mode.is(Mode.Interactive) && Config.ignoreStaleInIDE && {
109+
staleOK && {
107110
ctx.echo(denot.staleSymbolMsg)
108111
true
109112
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ object Symbols {
451451
final def isValidInCurrentRun(implicit ctx: Context): Boolean =
452452
(lastDenot.validFor.runId == ctx.runId || ctx.stillValid(lastDenot)) &&
453453
(lastDenot.symbol eq this)
454-
// the last condition is needed because under option -Yupdate-stale overwritten
455-
// package members keep denotations pointing to the new symbol, so the validity
454+
// the last condition is needed because under ctx.staleOK overwritten
455+
// members keep denotations pointing to the new symbol, so the validity
456456
// periods check out OK. But once a package member is overridden it is not longer
457457
// valid. If the option would be removed, the check would be no longer needed.
458458

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,8 @@ object Types {
16951695

16961696
private def memberDenot(name: Name, allowPrivate: Boolean)(implicit ctx: Context): Denotation = {
16971697
var d = memberDenot(prefix, name, allowPrivate)
1698-
if (!d.exists && ctx.mode.is(Mode.Interactive))
1698+
if (!d.exists && !allowPrivate && ctx.mode.is(Mode.Interactive))
1699+
// In the IDE we might change a public symbol to private, and would still expect to find it.
16991700
d = memberDenot(prefix, name, true)
17001701
if (!d.exists && ctx.phaseId > FirstPhaseId && lastDenotation.isInstanceOf[SymDenotation])
17011702
// name has changed; try load in earlier phase and make current
@@ -1900,7 +1901,10 @@ object Types {
19001901
if ((designator ne sym) && sym.exists) NamedType(prefix, sym).asInstanceOf[ThisType]
19011902
else this
19021903

1903-
/** A reference like this one, but with the given denotation, if it exists */
1904+
/** A reference like this one, but with the given denotation, if it exists.
1905+
* If the symbol of `denot` is the same as the current symbol, the denotation
1906+
* is re-used, otherwise a new one is created.
1907+
*/
19041908
final def withDenot(denot: Denotation)(implicit ctx: Context): ThisType =
19051909
if (denot.exists) {
19061910
val adapted = withSym(denot.symbol)
@@ -1965,12 +1969,16 @@ object Types {
19651969
def underlyingRef: TermRef
19661970
}
19671971

1968-
abstract case class TermRef(override val prefix: Type, var designator: Designator)
1969-
extends NamedType with SingletonType with ImplicitRef {
1972+
abstract case class TermRef(override val prefix: Type,
1973+
private var myDesignator: Designator)
1974+
extends NamedType with SingletonType with ImplicitRef {
19701975

19711976
type ThisType = TermRef
19721977
type ThisName = TermName
19731978

1979+
override def designator = myDesignator
1980+
override protected def designator_=(d: Designator) = myDesignator = d
1981+
19741982
//assert(name.toString != "<local Coder>")
19751983
override def underlying(implicit ctx: Context): Type = {
19761984
val d = denot
@@ -1989,11 +1997,16 @@ object Types {
19891997
def underlyingRef = this
19901998
}
19911999

1992-
abstract case class TypeRef(override val prefix: Type, var designator: Designator) extends NamedType {
2000+
abstract case class TypeRef(override val prefix: Type,
2001+
private var myDesignator: Designator)
2002+
extends NamedType {
19932003

19942004
type ThisType = TypeRef
19952005
type ThisName = TypeName
19962006

2007+
override def designator = myDesignator
2008+
override protected def designator_=(d: Designator) = myDesignator = d
2009+
19972010
override def underlying(implicit ctx: Context): Type = info
19982011
}
19992012

0 commit comments

Comments
 (0)