Skip to content

Commit dc1fc60

Browse files
committed
Change global enabling scheme for cc
The aim is to have an efficient test whether a phase or denot transformer should be run.
1 parent 64c3138 commit dc1fc60

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
168168
*/
169169
var pureFunsImportEncountered = false
170170

171-
/** Will be set to true if any of the compiled compilation units contains
172-
* a captureChecking language import.
171+
/** Will be set to true if experimental.captureChecking is enabled
172+
* or any of the compiled compilation units contains a captureChecking language import.
173173
*/
174-
var ccImportEncountered = false
174+
var ccEnabledSomewhere = Feature.enabledBySetting(Feature.captureChecking)(using ictx)
175175

176176
private var myEnrichedErrorMessage = false
177177

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object CheckCaptures:
2929

3030
class Pre extends PreRecheck, SymTransformer:
3131

32-
override def isEnabled(using Context) = true
32+
override def isRunnable(using Context) = super.isRunnable && Feature.ccEnabledSomewhere
3333

3434
/** - Reset `private` flags of parameter accessors so that we can refine them
3535
* in Setup if they have non-empty capture sets.
@@ -190,7 +190,8 @@ class CheckCaptures extends Recheck, SymTransformer:
190190
import CheckCaptures.*
191191

192192
def phaseName: String = "cc"
193-
override def isEnabled(using Context) = true
193+
194+
override def isRunnable(using Context) = super.isRunnable && Feature.ccEnabledSomewhere
194195

195196
def newRechecker()(using Context) = CaptureChecker(ctx)
196197

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ object Feature:
103103

104104
/** Is captureChecking enabled for any of the currently compiled compilation units? */
105105
def ccEnabledSomewhere(using Context) =
106-
enabledBySetting(captureChecking)
107-
|| ctx.run != null && ctx.run.nn.ccImportEncountered
106+
if ctx.run != null then ctx.run.nn.ccEnabledSomewhere
107+
else enabledBySetting(captureChecking)
108108

109109
def sourceVersionSetting(using Context): SourceVersion =
110110
SourceVersion.valueOf(ctx.settings.source.value)
@@ -174,7 +174,7 @@ object Feature:
174174
true
175175
else if fullFeatureName == captureChecking then
176176
ctx.compilationUnit.needsCaptureChecking = true
177-
if ctx.run != null then ctx.run.nn.ccImportEncountered = true
177+
if ctx.run != null then ctx.run.nn.ccEnabledSomewhere = true
178178
true
179179
else
180180
false

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,24 @@ object Phases {
299299
*/
300300
def phaseName: String
301301

302+
/** This property is queried when phases are first assembled.
303+
* If it is false, the phase will be dropped from the set of phases to traverse.
304+
*/
305+
def isEnabled(using Context): Boolean = true
306+
307+
/** This property is queried before a phase is run.
308+
* If it is false, the phase is skipped.
309+
*/
302310
def isRunnable(using Context): Boolean =
303311
!ctx.reporter.hasErrors
304312
// TODO: This might test an unintended condition.
305313
// To find out whether any errors have been reported during this
306314
// run one calls `errorsReported`, not `hasErrors`.
307315
// But maybe changing this would prevent useful phases from running?
308316

317+
/** True for all phases except NoPhase */
318+
def exists: Boolean = true
319+
309320
/** If set, allow missing or superfluous arguments in applications
310321
* and type applications.
311322
*/
@@ -360,10 +371,6 @@ object Phases {
360371
/** Can this transform change the base types of a type? */
361372
def changesBaseTypes: Boolean = changesParents
362373

363-
def isEnabled(using Context): Boolean = true
364-
365-
def exists: Boolean = true
366-
367374
def initContext(ctx: FreshContext): Unit = ()
368375

369376
/** A hook that allows to transform the usual context passed to the function

0 commit comments

Comments
 (0)