Skip to content

Commit 4f5855b

Browse files
committed
Fail on all stale references by default
Update stale references only if -Yupdate-state is set, fail with a StaleSymbol error otherwise. This required some fixes to the way ScalaShadowing was treated. If we compile a ScalaShadowing (as is done in tasty-bootstrap) we need to also overwrite the mirrored symbol in the scala package. Otherwise we would get a stale reference when looking up the latter.
1 parent 5539600 commit 4f5855b

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ object Config {
144144
*/
145145
final val simplifyApplications = true
146146

147-
/** If this flag is on, automatically being forward no-longer valid package members.
148-
* If it is off, raise a StaleSymbol error instead.
149-
*/
150-
final val autoUpdatePackageMembers = true
151-
152147
/** If set, prints a trace of all symbol completions */
153148
final val showCompletions = false
154149

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class ScalaSettings extends Settings.SettingGroup {
102102
val YkeepComments = BooleanSetting("-Ykeep-comments", "Keep comments when scanning source files.")
103103
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.")
104104
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.")
105+
val YupdateStale = BooleanSetting("-Yupdate-stale", "Automically update stale top-level classes and objects to latest version")
105106
val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)")
106107
val YretainTrees = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
107108
val YshowTreeIds = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Definitions {
209209
* members at runtime.
210210
*/
211211
lazy val ScalaShadowingPackageVal = ctx.requiredPackage(nme.scalaShadowing)
212-
lazy val ScalaShadowingPackageClass = ScalaShadowingPackageVal.moduleClass.asClass
212+
def ScalaShadowingPackageClass(implicit ctx: Context) = ScalaShadowingPackageVal.moduleClass.asClass
213213

214214
/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)
215215
* because after erasure the Any and AnyVal references get remapped to the Object methods
@@ -828,6 +828,9 @@ class Definitions {
828828
def isTupleClass(cls: Symbol) = isVarArityClass(cls, str.Tuple)
829829
def isProductClass(cls: Symbol) = isVarArityClass(cls, str.Product)
830830

831+
def isScalaShadowingPackageClass(cls: Symbol) =
832+
cls.name == tpnme.scalaShadowing && cls.owner == RootClass
833+
831834
/** Returns the erased class of the function class `cls`
832835
* - FunctionN for N > 22 becomes FunctionXXL
833836
* - FunctionN for 22 > N >= 0 remains as FunctionN

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,16 +774,26 @@ object Denotations {
774774

775775
/** Move validity period of this denotation to a new run. Throw a StaleSymbol error
776776
* if denotation is no longer valid.
777+
* However, StaleSymbol error is not thrown in the following situations:
778+
*
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),
782+
* update the symbol to the new version if it exists, or return
783+
* the old version otherwise.
784+
* - If the symbol did not have a denotation that was defined at the current phase
785+
* return a NoDenotation instead.
777786
*/
778787
private def bringForward()(implicit ctx: Context): SingleDenotation = {
779788
this match {
780789
case symd: SymDenotation =>
781790
if (ctx.stillValid(symd)) return updateValidity()
782-
if (Config.autoUpdatePackageMembers && symd.owner.is(Package)) {
791+
lazy val staleOK = ctx.acceptStale(symd)
792+
if (ctx.settings.YupdateStale.value && symd.owner.is(Package) || staleOK) {
783793
val newd = symd.owner.info.decls.lookup(symd.name)
784794
if (newd.exists) return newd
795+
else if (staleOK) return updateValidity()
785796
}
786-
if (ctx.acceptStale(symd)) return updateValidity()
787797
case _ =>
788798
}
789799
if (!symbol.exists) return updateValidity()

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,8 @@ object SymDenotations {
14861486
if (nxt.validFor.code > this.validFor.code) {
14871487
this.nextInRun.asSymDenotation.asClass.enter(sym)
14881488
}
1489+
if (defn.isScalaShadowingPackageClass(sym.owner))
1490+
defn.ScalaPackageClass.enter(sym) // ScalaShadowing members are mirrored in ScalaPackage
14891491
}
14901492
}
14911493

@@ -1843,6 +1845,7 @@ object SymDenotations {
18431845
if (entry != null) {
18441846
if (entry.sym == sym) return false
18451847
mscope.unlink(entry)
1848+
if (sym.owner == defn.ScalaShadowingPackageClass)
18461849
if (sym.name == nme.PACKAGE) packageObjRunId = NoRunId
18471850
}
18481851
true

0 commit comments

Comments
 (0)