Skip to content

Commit 48ed3c6

Browse files
committed
WIP
1 parent 0baeed8 commit 48ed3c6

10 files changed

+62
-18
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

+1-6
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,8 @@ class Compiler {
117117
runId += 1; runId
118118
}
119119

120-
def reset()(implicit ctx: Context): Unit = {
121-
ctx.base.reset()
122-
ctx.runInfo.clear()
123-
}
124-
125120
def newRun(implicit ctx: Context): Run = {
126-
reset()
121+
ctx.base.reset()
127122
new Run(this, ctx)
128123
}
129124
}

compiler/src/dotty/tools/dotc/FromTasty.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object FromTasty extends Driver {
4444
}
4545

4646
override def newRun(implicit ctx: Context): Run = {
47-
reset()
47+
ctx.base.reset()
4848
new TASTYRun(this, ctx)
4949
}
5050
}

compiler/src/dotty/tools/dotc/Run.scala

+9-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ class Run(comp: Compiler, ictx: Context) {
6060
protected[this] implicit val ctx: Context = rootContext(ictx)
6161
assert(ctx.runId <= Periods.MaxPossibleRunId)
6262

63+
if (ctx.runId > 3) {
64+
// we are in resident mode; invalidate caches to reduce memory presssure
65+
println("invalidating caches...")
66+
defn.RootClass.invalidateCaches()
67+
println("done")
68+
}
69+
6370
def getSource(fileName: String): SourceFile = {
6471
val f = new PlainFile(fileName)
6572
if (f.isDirectory) {
@@ -177,9 +184,10 @@ class Run(comp: Compiler, ictx: Context) {
177184
/** The context created for this run */
178185
def runContext = ctx
179186

180-
/** Print summary; return # of errors encountered */
187+
/** Print summary ; return reporter */
181188
def printSummary(): Reporter = {
182189
ctx.runInfo.printMaxConstraint()
190+
ctx.runInfo.clear()
183191
val r = ctx.reporter
184192
r.printSummary
185193
r

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

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ trait ConstraintRunInfo { self: RunInfo =>
1414
}
1515
def printMaxConstraint()(implicit ctx: Context) =
1616
if (maxSize > 0) typr.println(s"max constraint = ${maxConstraint.show}")
17+
def clearMaxConstraint() =
18+
maxConstraint = null
1719
}

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ object Contexts {
591591
def squashed(p: Phase): Phase = {
592592
allPhases.find(_.period.containsPhaseId(p.id)).getOrElse(NoPhase)
593593
}
594+
595+
def reset() = {
596+
for ((_, set) <- uniqueSets) set.clear()
597+
cleanPhaseCache()
598+
errorTypeMsg.clear()
599+
}
594600
}
595601

596602
/** The essential mutable state of a context base, collected into a common class */
@@ -615,7 +621,7 @@ object Contexts {
615621
/** A table for hash consing unique named types */
616622
private[core] val uniqueNamedTypes = new NamedTypeUniques
617623

618-
private def uniqueSets = Map(
624+
protected def uniqueSets = Map(
619625
"uniques" -> uniques,
620626
"uniqueAppliedTypes" -> uniqueAppliedTypes,
621627
"uniqueNamedTypes" -> uniqueNamedTypes)
@@ -662,11 +668,6 @@ object Contexts {
662668

663669
protected[dotc] val indentTab = " "
664670

665-
def reset() = {
666-
for ((_, set) <- uniqueSets) set.clear()
667-
errorTypeMsg.clear()
668-
}
669-
670671
// Test that access is single threaded
671672

672673
/** The thread on which `checkSingleThreaded was invoked last */
@@ -692,6 +693,11 @@ object Contexts {
692693
/** Info that changes on each compiler run */
693694
class RunInfo(initctx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
694695
implicit val ctx: Context = initctx
696+
697+
def clear() = {
698+
clearImplicits()
699+
clearMaxConstraint()
700+
}
695701
}
696702

697703
class GADTMap(initBounds: SimpleMap[Symbol, TypeBounds]) extends util.DotClass {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ object Denotations {
685685
* 2) the union of all validity periods is a contiguous
686686
* interval.
687687
*/
688-
protected var nextInRun: SingleDenotation = this
688+
private[core] var nextInRun: SingleDenotation = this
689689

690690
/** The version of this SingleDenotation that was valid in the first phase
691691
* of this run.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ object Phases {
214214
def phaseOfClass(pclass: Class[_]) = phases.find(pclass.isInstance).getOrElse(NoPhase)
215215

216216
private val cachedPhases = collection.mutable.Set[PhaseCache]()
217-
private def cleanPhaseCache = cachedPhases.foreach(_.myPhase = NoPhase)
217+
protected def cleanPhaseCache() = cachedPhases.foreach(_.myPhase = NoPhase)
218218

219219
/** A cache to compute the phase with given name, which
220220
* stores the phase as soon as phaseNamed returns something

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ trait SymDenotations { this: Context =>
3535
val result =
3636
if (symbol.isClass)
3737
if (initFlags is Package) new PackageClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, ctx.runId)
38-
else if (name.toString == "AndType") new ClassXDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, ctx.runId)
38+
else if (name.toString == "AndType" && ctx.runId == 3) {
39+
new ClassXDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, ctx.runId)
40+
}
3941
else new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin, ctx.runId)
4042
else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin)
4143
result.validFor = stablePeriod
@@ -1207,6 +1209,8 @@ object SymDenotations {
12071209
*/
12081210
def copyCaches(from: SymDenotation, phase: Phase)(implicit ctx: Context): this.type = this
12091211

1212+
private[core] def invalidateCaches()(implicit ctx: Context): Unit = ()
1213+
12101214
/** Are `info1` and `info2` ClassInfo types with different parents?
12111215
* @param completersMatter if `true`, consider parents changed if `info1` or `info2 `is a type completer
12121216
*/
@@ -1323,6 +1327,24 @@ object SymDenotations {
13231327
this
13241328
}
13251329

1330+
override private[core] def invalidateCaches()(implicit ctx: Context): Unit = {
1331+
println(i"invalidate: $name")
1332+
invalidateBaseDataCache()
1333+
invalidateMemberNamesCache()
1334+
invalidateBaseTypeCache()
1335+
myMemberCache = null
1336+
myMemberCachePeriod = Nowhere
1337+
fullNameCache = SimpleMap.Empty
1338+
myTypeParams = null
1339+
val invalidated = new java.util.IdentityHashMap[Symbol, Symbol]
1340+
info.decls.foreach { sym =>
1341+
if (invalidated.get(sym) == null) {
1342+
invalidated.put(sym, sym)
1343+
sym.invalidateCaches()
1344+
}
1345+
}
1346+
}
1347+
13261348
// ----- denotation fields and accessors ------------------------------
13271349

13281350
if (initFlags is (Module, butNot = Package))

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

+11
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,17 @@ object Symbols {
578578
def showFullName(implicit ctx: Context): String = ctx.fullNameString(this)
579579

580580
override def hashCode() = id // for debugging.
581+
582+
def invalidateCaches()(implicit ctx: Context): Unit = {
583+
val cur = lastDenot
584+
if (cur != null) {
585+
var d = cur
586+
do {
587+
d.invalidateCaches()
588+
d = d.nextInRun.asInstanceOf[SymDenotation]
589+
} while (d ne cur)
590+
}
591+
}
581592
}
582593

583594
type TermSymbol = Symbol { type ThisName = TermName }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ trait ImplicitRunInfo { self: RunInfo =>
491491
override def default(key: TermRef) = 0
492492
}
493493

494-
def clear() = {
494+
protected def clearImplicits() = {
495495
implicitScopeCache.clear()
496496
useCount.clear()
497497
}

0 commit comments

Comments
 (0)