Skip to content

Commit 2b34272

Browse files
authored
Merge pull request #2425 from dotty-staging/fix-inherited-caches
Fix caches of info that depends on inherited classes
2 parents 2ba509d + effaca1 commit 2b34272

28 files changed

+410
-351
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ object Config {
44

55
final val cacheMembersNamed = true
66
final val cacheAsSeenFrom = true
7-
final val useFingerPrints = true // note: it currently seems to be slightly faster not to use them! my junit test: 548s without, 560s with.
87
final val cacheMemberNames = true
98
final val cacheImplicitScopes = true
109

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -597,26 +597,6 @@ object Contexts {
597597

598598
def nextId = { _nextId += 1; _nextId }
599599

600-
/** A map from a superclass id to the typeref of the class that has it */
601-
private[core] var classOfId = new Array[ClassSymbol](Config.InitialSuperIdsSize)
602-
603-
/** A map from a the typeref of a class to its superclass id */
604-
private[core] val superIdOfClass = new mutable.AnyRefMap[ClassSymbol, Int]
605-
606-
/** The last allocated superclass id */
607-
private[core] var lastSuperId = -1
608-
609-
/** Allocate and return next free superclass id */
610-
private[core] def nextSuperId: Int = {
611-
lastSuperId += 1
612-
if (lastSuperId >= classOfId.length) {
613-
val tmp = new Array[ClassSymbol](classOfId.length * 2)
614-
classOfId.copyToArray(tmp)
615-
classOfId = tmp
616-
}
617-
lastSuperId
618-
}
619-
620600
// Types state
621601
/** A table for hash consing unique types */
622602
private[core] val uniques = new util.HashSet[Type](Config.initialUniquesCapacity) {
@@ -682,9 +662,6 @@ object Contexts {
682662

683663
def reset() = {
684664
for ((_, set) <- uniqueSets) set.clear()
685-
for (i <- 0 until classOfId.length) classOfId(i) = null
686-
superIdOfClass.clear()
687-
lastSuperId = -1
688665
}
689666

690667
// Test that access is single threaded

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ object DenotTransformers {
4444
val info1 = transformInfo(ref.info, ref.symbol)
4545
if (info1 eq ref.info) ref
4646
else ref match {
47-
case ref: SymDenotation => ref.copySymDenotation(info = info1)
48-
case _ => ref.derivedSingleDenotation(ref.symbol, info1)
47+
case ref: SymDenotation =>
48+
ref.copySymDenotation(info = info1).copyCaches(ref, ctx.phase.next)
49+
case _ =>
50+
ref.derivedSingleDenotation(ref.symbol, info1)
4951
}
5052
}
5153
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ object Denotations {
805805
val transformer = ctx.denotTransformers(nextTransformerId)
806806
//println(s"transforming $this with $transformer")
807807
try {
808-
next = transformer.transform(cur)(ctx.withPhase(transformer)).syncWithParents
808+
next = transformer.transform(cur)(ctx.withPhase(transformer))
809809
} catch {
810810
case ex: CyclicReference =>
811811
println(s"error while transforming $this") // DEBUG
@@ -817,7 +817,6 @@ object Denotations {
817817
next match {
818818
case next: ClassDenotation =>
819819
assert(!next.is(Package), s"illegal transformation of package denotation by transformer ${ctx.withPhase(transformer).phase}")
820-
next.resetFlag(Frozen)
821820
case _ =>
822821
}
823822
next.insertAfter(cur)

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,6 @@ object Flags {
349349
/** A bridge method. Set by Erasure */
350350
final val Bridge = termFlag(34, "<bridge>")
351351

352-
/** All class attributes are fully defined */
353-
final val FullyCompleted = typeFlag(34, "<fully-completed>")
354-
355352
/** Symbol is a Java varargs bridge */ // (needed?)
356353
final val VBridge = termFlag(35, "<vbridge>") // TODO remove
357354

@@ -375,9 +372,6 @@ object Flags {
375372
/** Denotation is in train of being loaded and completed, used to catch cyclic dependencies */
376373
final val Touched = commonFlag(48, "<touched>")
377374

378-
/** Class is not allowed to accept new members because fingerprint of subclass has been taken */
379-
final val Frozen = commonFlag(49, "<frozen>")
380-
381375
/** An error symbol */
382376
final val Erroneous = commonFlag(50, "<is-error>")
383377

@@ -450,7 +444,7 @@ object Flags {
450444
Module | Package | Deferred | MethodOrHKCommon | Param | ParamAccessor |
451445
Scala2ExistentialCommon | Mutable.toCommonFlags | Touched | JavaStatic |
452446
CovariantOrOuter | ContravariantOrLabel | CaseAccessorOrBaseTypeArg |
453-
Fresh | Frozen | Erroneous | ImplicitCommon | Permanent | Synthetic |
447+
Fresh | Erroneous | ImplicitCommon | Permanent | Synthetic |
454448
SuperAccessorOrScala2x | Inline
455449

456450
/** Flags guaranteed to be set upon symbol creation, or, if symbol is a top-level
@@ -558,6 +552,9 @@ object Flags {
558552
/** A lazy or deferred value */
559553
final val LazyOrDeferred = Lazy | Deferred
560554

555+
/** An accessor or label */
556+
final val AccessorOrLabel = Accessor | Label
557+
561558
/** A synthetic or private definition */
562559
final val SyntheticOrPrivate = Synthetic | Private
563560

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ object Phases {
305305
*/
306306
def isTyper = false
307307

308+
/** Can this transform create or delete non-private members? */
309+
def changesMembers: Boolean = false
310+
311+
/** Can this transform change the parents of a class? */
312+
def changesParents: Boolean = false
313+
308314
def exists: Boolean = true
309315

310316
private var myPeriod: Period = Periods.InvalidPeriod
@@ -315,6 +321,8 @@ object Phases {
315321
private var mySymbolicRefs = false
316322
private var myLabelsReordered = false
317323

324+
private var mySameMembersStartId = NoPhaseId
325+
private var mySameParentsStartId = NoPhaseId
318326

319327
/** The sequence position of this phase in the given context where 0
320328
* is reserved for NoPhase and the first real phase is at position 1.
@@ -332,6 +340,11 @@ object Phases {
332340
final def symbolicRefs = mySymbolicRefs // Phase is after ResolveSuper, newly generated TermRefs should be symbolic
333341
final def labelsReordered = myLabelsReordered // Phase is after LabelDefs, labels are flattened and owner chains don't mirror this
334342

343+
final def sameMembersStartId = mySameMembersStartId
344+
// id of first phase where all symbols are guaranteed to have the same members as in this phase
345+
final def sameParentsStartId = mySameParentsStartId
346+
// id of first phase where all symbols are guaranteed to have the same parents as in this phase
347+
335348
protected[Phases] def init(base: ContextBase, start: Int, end:Int): Unit = {
336349
if (start >= FirstPhaseId)
337350
assert(myPeriod == Periods.InvalidPeriod, s"phase $this has already been used once; cannot be reused")
@@ -342,6 +355,8 @@ object Phases {
342355
myRefChecked = prev.getClass == classOf[RefChecks] || prev.refChecked
343356
mySymbolicRefs = prev.getClass == classOf[ResolveSuper] || prev.symbolicRefs
344357
myLabelsReordered = prev.getClass == classOf[LabelDefs] || prev.labelsReordered
358+
mySameMembersStartId = if (changesMembers) id else prev.sameMembersStartId
359+
mySameParentsStartId = if (changesParents) id else prev.sameMembersStartId
345360
}
346361

347362
protected[Phases] def init(base: ContextBase, id: Int): Unit = init(base, id, id)

0 commit comments

Comments
 (0)