Skip to content

Commit

Permalink
Change global enabling scheme for cc
Browse files Browse the repository at this point in the history
The aim is to have an efficient test whether a phase or denot transformer should
be run.

[Cherry-picked dc1fc60]
  • Loading branch information
odersky authored and WojciechMazur committed Jun 21, 2024
1 parent f08cd3c commit 97a414b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
*/
var pureFunsImportEncountered = false

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

private var myEnrichedErrorMessage = false

Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object CheckCaptures:

class Pre extends PreRecheck, SymTransformer:

override def isEnabled(using Context) = true
override def isRunnable(using Context) = super.isRunnable && Feature.ccEnabledSomewhere

/** Reset `private` flags of parameter accessors so that we can refine them
* in Setup if they have non-empty capture sets. Special handling of some
Expand Down Expand Up @@ -156,7 +156,8 @@ class CheckCaptures extends Recheck, SymTransformer:
import CheckCaptures.*

def phaseName: String = "cc"
override def isEnabled(using Context) = true

override def isRunnable(using Context) = super.isRunnable && Feature.ccEnabledSomewhere

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

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ object Feature:

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

def sourceVersionSetting(using Context): SourceVersion =
SourceVersion.valueOf(ctx.settings.source.value)
Expand Down Expand Up @@ -169,7 +169,7 @@ object Feature:
true
else if fullFeatureName == captureChecking then
ctx.compilationUnit.needsCaptureChecking = true
if ctx.run != null then ctx.run.nn.ccImportEncountered = true
if ctx.run != null then ctx.run.nn.ccEnabledSomewhere = true
true
else
false
Expand Down
15 changes: 11 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,24 @@ object Phases {
*/
def phaseName: String

/** This property is queried when phases are first assembled.
* If it is false, the phase will be dropped from the set of phases to traverse.
*/
def isEnabled(using Context): Boolean = true

/** This property is queried before a phase is run.
* If it is false, the phase is skipped.
*/
def isRunnable(using Context): Boolean =
!ctx.reporter.hasErrors
// TODO: This might test an unintended condition.
// To find out whether any errors have been reported during this
// run one calls `errorsReported`, not `hasErrors`.
// But maybe changing this would prevent useful phases from running?

/** True for all phases except NoPhase */
def exists: Boolean = true

/** If set, allow missing or superfluous arguments in applications
* and type applications.
*/
Expand Down Expand Up @@ -360,10 +371,6 @@ object Phases {
/** Can this transform change the base types of a type? */
def changesBaseTypes: Boolean = changesParents

def isEnabled(using Context): Boolean = true

def exists: Boolean = true

def initContext(ctx: FreshContext): Unit = ()

private var myPeriod: Period = Periods.InvalidPeriod
Expand Down

0 comments on commit 97a414b

Please sign in to comment.