Skip to content

Commit 73f8482

Browse files
committed
Cache captureSets of CaptureRefs only at phase cc
Before they are empty.
1 parent c95d942 commit 73f8482

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import dotty.tools.dotc.transform._
1515
import Periods._
1616
import parsing.Parser
1717
import printing.XprintMode
18-
import typer.{TyperPhase, RefChecks}
18+
import typer.{TyperPhase, RefChecks, CheckCaptures}
1919
import typer.ImportInfo.withRootImports
2020
import ast.{tpd, untpd}
2121
import scala.annotation.internal.sharable
@@ -217,6 +217,7 @@ object Phases {
217217
private var myCountOuterAccessesPhase: Phase = _
218218
private var myFlattenPhase: Phase = _
219219
private var myGenBCodePhase: Phase = _
220+
private var myCheckCapturesPhase: Phase = _
220221

221222
final def parserPhase: Phase = myParserPhase
222223
final def typerPhase: Phase = myTyperPhase
@@ -239,6 +240,7 @@ object Phases {
239240
final def countOuterAccessesPhase = myCountOuterAccessesPhase
240241
final def flattenPhase: Phase = myFlattenPhase
241242
final def genBCodePhase: Phase = myGenBCodePhase
243+
final def checkCapturesPhase: Phase = myCheckCapturesPhase
242244

243245
private def setSpecificPhases() = {
244246
def phaseOfClass(pclass: Class[?]) = phases.find(pclass.isInstance).getOrElse(NoPhase)
@@ -263,7 +265,8 @@ object Phases {
263265
myFlattenPhase = phaseOfClass(classOf[Flatten])
264266
myExplicitOuterPhase = phaseOfClass(classOf[ExplicitOuter])
265267
myGettersPhase = phaseOfClass(classOf[Getters])
266-
myGenBCodePhase = phaseOfClass(classOf[GenBCode])
268+
myGenBCodePhase = phaseOfClass(classOf[GenBCode])
269+
myCheckCapturesPhase = phaseOfClass(classOf[CheckCaptures])
267270
}
268271

269272
final def isAfterTyper(phase: Phase): Boolean = phase.id > typerPhase.id
@@ -443,6 +446,7 @@ object Phases {
443446
def lambdaLiftPhase(using Context): Phase = ctx.base.lambdaLiftPhase
444447
def flattenPhase(using Context): Phase = ctx.base.flattenPhase
445448
def genBCodePhase(using Context): Phase = ctx.base.genBCodePhase
449+
def checkCapturesPhase(using Context): Phase = ctx.base.checkCapturesPhase
446450

447451
def unfusedPhases(using Context): Array[Phase] = ctx.base.phases
448452

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,8 @@ object Types {
20522052

20532053
def captureSetOfInfo(using Context): CaptureSet =
20542054
if ctx.runId == myCaptureSetRunId then myCaptureSet
2055-
else if myCaptureSet eq CaptureSet.Pending then CaptureSet.empty
2055+
else if (myCaptureSet eq CaptureSet.Pending)
2056+
|| ctx.phase != Phases.checkCapturesPhase then CaptureSet.empty
20562057
else
20572058
myCaptureSet = CaptureSet.Pending
20582059
val computed =

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
6767

6868
def enterDef(stat: Tree)(using Context): Unit =
6969
val sym = stat.symbol
70-
var newInfo = transformType(sym.info)
71-
stat match
70+
val transInfo = transformType(sym.info)
71+
val newInfo = stat match
7272
case stat: ValOrDefDef if stat.tpt.isInstanceOf[InferredTypeTree] =>
73-
newInfo = reinferResult(sym.info)
73+
reinferResult(transInfo)
7474
case stat: Bind =>
75-
newInfo = reinferResult(sym.info)
75+
reinferResult(transInfo)
7676
case _ =>
77+
transInfo
78+
//println(i"update info $sym: ${sym.info} --> $transInfo --> $newInfo")
7779
sym.updateInfo(newInfo)
7880

7981
def constFold(tree: Tree, tp: Type)(using Context): Type =

0 commit comments

Comments
 (0)