Skip to content

Commit 18767e0

Browse files
authored
Merge pull request #3639 from dotty-staging/refresh-pkgs
Remove obsolete package members in new runs
2 parents cb758bd + bb7a6e6 commit 18767e0

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,12 @@ object Scopes {
333333
}
334334

335335
/** remove symbol from this scope if it is present */
336-
final def unlink(sym: Symbol)(implicit ctx: Context): Unit = {
337-
var e = lookupEntry(sym.name)
336+
final def unlink(sym: Symbol)(implicit ctx: Context): Unit =
337+
unlink(sym, sym.name)
338+
339+
/** remove symbol from this scope if it is present under the given name */
340+
final def unlink(sym: Symbol, name: Name)(implicit ctx: Context): Unit = {
341+
var e = lookupEntry(name)
338342
while (e ne null) {
339343
if (e.sym == sym) unlink(e)
340344
e = lookupNextEntry(e)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,17 @@ object SymDenotations {
18531853
}
18541854
true
18551855
}
1856+
1857+
/** Unlink all package members defined in `file` in a previous run. */
1858+
def unlinkFromFile(file: AbstractFile)(implicit ctx: Context): Unit = {
1859+
val scope = unforcedDecls.openForMutations
1860+
for (sym <- scope.toList.iterator) {
1861+
// We need to be careful to not force the denotation of `sym` here,
1862+
// otherwise it will be brought forward to the current run.
1863+
if (sym.defRunId != ctx.runId && sym.isClass && sym.asClass.assocFile == file)
1864+
scope.unlink(sym, sym.lastKnownDenotation.name)
1865+
}
1866+
}
18561867
}
18571868

18581869
@sharable object NoDenotation

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,16 @@ class Namer { typer: Typer =>
349349
}
350350
val existing = pkgOwner.info.decls.lookup(pid.name)
351351

352-
if ((existing is Package) && (pkgOwner eq existing.owner)) existing
352+
if ((existing is Package) && (pkgOwner eq existing.owner)) {
353+
existing.moduleClass.denot match {
354+
case d: PackageClassDenotation =>
355+
// Remove existing members coming from a previous compilation of this file,
356+
// they are obsolete.
357+
d.unlinkFromFile(ctx.source.file)
358+
case _ =>
359+
}
360+
existing
361+
}
353362
else {
354363
/** If there's already an existing type, then the package is a dup of this type */
355364
val existingType = pkgOwner.info.decls.lookup(pid.name.toTypeName)

0 commit comments

Comments
 (0)