Skip to content

Commit 212b8af

Browse files
authored
Merge pull request #9608 from dotty-staging/optimize-basedata
Optimize basetype caches
2 parents f2a2dfc + 6729e1c commit 212b8af

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object DenotTransformers {
3737

3838
def transform(ref: SingleDenotation)(using Context): SingleDenotation = {
3939
val sym = ref.symbol
40-
if (sym.exists && !mayChange(sym)) ref
40+
if (sym.exists && !infoMayChange(sym)) ref
4141
else {
4242
val info1 = transformInfo(ref.info, ref.symbol)
4343
if (info1 eq ref.info) ref
@@ -50,11 +50,11 @@ object DenotTransformers {
5050
}
5151
}
5252

53-
/** Denotations with a symbol where `mayChange` is false are guaranteed to be
53+
/** Denotations with a symbol where `infoMayChange` is false are guaranteed to be
5454
* unaffected by this transform, so `transformInfo` need not be run. This
5555
* can save time, and more importantly, can help avoid forcing symbol completers.
5656
*/
57-
protected def mayChange(sym: Symbol)(using Context): Boolean = true
57+
protected def infoMayChange(sym: Symbol)(using Context): Boolean = true
5858
}
5959

6060
/** A transformer that only transforms SymDenotations.

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,11 @@ object SymDenotations {
26392639
private var locked = false
26402640
private var provisional = false
26412641

2642-
final def isValid(using Context): Boolean = valid && isValidAt(ctx.phase)
2642+
final def isValid(using Context): Boolean =
2643+
valid && createdAt.runId == ctx.runId
2644+
// Note: We rely on the fact that whenever base types of classes change,
2645+
// the affected classes will get new denotations with new basedata caches.
2646+
// So basedata caches can become invalid only if the run changes.
26432647

26442648
def invalidate(): Unit =
26452649
if (valid && !locked) {

compiler/src/dotty/tools/dotc/transform/ElimByName.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ElimByName extends TransformByNameApply with InfoTransformer {
7272
case _ => tp
7373
}
7474

75-
override def mayChange(sym: Symbol)(using Context): Boolean = sym.isTerm && exprBecomesFunction(sym)
75+
override def infoMayChange(sym: Symbol)(using Context): Boolean = sym.isTerm && exprBecomesFunction(sym)
7676
}
7777

7878
object ElimByName {

compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
7373
case ref1 =>
7474
ref1
7575

76-
override def mayChange(sym: Symbol)(using Context): Boolean = sym.is(Method)
76+
override def infoMayChange(sym: Symbol)(using Context): Boolean = sym.is(Method)
7777

7878
private def overridesJava(sym: Symbol)(using Context) = sym.allOverriddenSymbols.exists(_.is(JavaDefined))
7979

compiler/src/dotty/tools/dotc/transform/Erasure.scala

+8-7
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,17 @@ class Erasure extends Phase with DenotTransformer {
9090
newFlags = newFlags &~ Flags.Inline
9191
newAnnotations = newAnnotations.filterConserve(!_.isInstanceOf[BodyAnnotation])
9292
// TODO: define derivedSymDenotation?
93-
if (oldSymbol eq newSymbol)
94-
&& (oldOwner eq newOwner)
95-
&& (oldName eq newName)
96-
&& (oldInfo eq newInfo)
97-
&& (oldFlags == newFlags)
98-
&& (oldAnnotations eq newAnnotations)
93+
if ref.is(Flags.PackageClass)
94+
|| !ref.isClass // non-package classes are always copied since their base types change
95+
&& (oldSymbol eq newSymbol)
96+
&& (oldOwner eq newOwner)
97+
&& (oldName eq newName)
98+
&& (oldInfo eq newInfo)
99+
&& (oldFlags == newFlags)
100+
&& (oldAnnotations eq newAnnotations)
99101
then
100102
ref
101103
else
102-
assert(!ref.is(Flags.PackageClass), s"trans $ref @ ${ctx.phase} oldOwner = $oldOwner, newOwner = $newOwner, oldInfo = $oldInfo, newInfo = $newInfo ${oldOwner eq newOwner} ${oldInfo eq newInfo}")
103104
ref.copySymDenotation(
104105
symbol = newSymbol,
105106
owner = newOwner,

compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ExplicitOuter extends MiniPhase with InfoTransformer { thisPhase =>
5757
tp
5858
}
5959

60-
override def mayChange(sym: Symbol)(using Context): Boolean = sym.isClass && !sym.is(JavaDefined)
60+
override def infoMayChange(sym: Symbol)(using Context): Boolean = sym.isClass && !sym.is(JavaDefined)
6161

6262
/** First, add outer accessors if a class does not have them yet and it references an outer this.
6363
* If the class has outer accessors, implement them.

compiler/src/dotty/tools/dotc/transform/FirstTransform.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
4646
tp
4747
}
4848

49-
override protected def mayChange(sym: Symbol)(using Context): Boolean = sym.isClass
49+
override protected def infoMayChange(sym: Symbol)(using Context): Boolean = sym.isClass
5050

5151
override def checkPostCondition(tree: Tree)(using Context): Unit =
5252
tree match {

0 commit comments

Comments
 (0)