Skip to content

Commit

Permalink
Move atPhase/atPeriod and related to Phases and Periods
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 13, 2020
1 parent 8a477c7 commit bce1767
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.transform.SymUtils._
import dotty.tools.dotc.util.Spans._
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
import dotty.tools.dotc.core.Phases._

/*
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.Trees
import dotty.tools.dotc.core.Annotations._
import dotty.tools.dotc.core.Constants._
import dotty.tools.dotc.core.Contexts.{Context, atPhase}
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.Flags._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import scala.collection.mutable
import scala.collection.generic.Clearable

import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Phases.Phase
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Decorators.{given _}, DenotTransformers._
import collection.{immutable, mutable}
import util.{Property, SourceFile, NoSource}
import NameKinds.{TempResultName, OuterSelectName}
import Phases.{currentPhase, currentlyAfterErasure}
import Phases._
import typer.ConstFold

import scala.annotation.tailrec
Expand Down
18 changes: 0 additions & 18 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,6 @@ object Contexts {
inline def inContext[T](c: Context)(inline op: Context ?=> T): T =
op(using c)

/** Execute `op` at given period */
inline def atPeriod[T](pd: Period)(inline op: Context ?=> T)(using Context): T =
op(using ctx.fresh.setPeriod(pd))

/** Execute `op` at given phase id */
inline def atPhase[T](pid: PhaseId)(inline op: Context ?=> T)(using Context): T =
op(using ctx.withPhase(pid))

/** Execute `op` at given phase */
inline def atPhase[T](phase: Phase)(inline op: Context ?=> T)(using Context): T =
atPhase(phase.id)(op)

inline def atNextPhase[T](inline op: Context ?=> T)(using Context): T =
atPhase(currentPhase.next)(op)

inline def atPhaseNotLaterThan[T](limit: Phase)(inline op: Context ?=> T)(using Context): T =
op(using if !limit.exists || currentPhase <= limit then ctx else ctx.withPhase(limit))

/** A context is passed basically everywhere in dotc.
* This is convenient but carries the risk of captured contexts in
* objects that turn into space leaks. To combat this risk, here are some
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Flags._
import DenotTransformers._
import Decorators._
import Signature.MatchDegree._
import Phases.{currentPhase, currentlyAfterErasure}
import Phases._
import printing.Texts._
import printing.Printer
import io.AbstractFile
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Periods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ object Periods {

inline def currentPhaseId(using ctx: Context): PhaseId = ctx.period.phaseId

/** Execute `op` at given period */
inline def atPeriod[T](pd: Period)(inline op: Context ?=> T)(using Context): T =
op(using ctx.fresh.setPeriod(pd))

/** The period containing the current period where denotations do not change.
* We compute this by taking as first phase the first phase less or equal to
* the current phase that has the same "nextTransformerId". As last phase
Expand Down
20 changes: 17 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,27 @@ object Phases {

inline def currentPhase(using ctx: Context): Phase = ctx.base.phases(ctx.period.firstPhaseId)

inline def phaseOf(id: PhaseId)(using Context): Phase =
ctx.base.phases(id)

def currentlyAfterTyper(using Context): Boolean = ctx.base.isAfterTyper(currentPhase)

def currentlyAfterErasure(using Context): Boolean = currentPhase.erasedTypes

/** Execute `op` at given phase id */
inline def atPhase[T](pid: PhaseId)(inline op: Context ?=> T)(using Context): T =
op(using ctx.withPhase(pid))

/** Execute `op` at given phase */
inline def atPhase[T](phase: Phase)(inline op: Context ?=> T)(using Context): T =
atPhase(phase.id)(op)

inline def atNextPhase[T](inline op: Context ?=> T)(using Context): T =
atPhase(currentPhase.next)(op)

inline def atPhaseNotLaterThan[T](limit: Phase)(inline op: Context ?=> T)(using Context): T =
op(using if !limit.exists || currentPhase <= limit then ctx else ctx.withPhase(limit))

inline def phaseOf(id: PhaseId)(using Context): Phase =
ctx.base.phases(id)

trait PhasesBase {
this: ContextBase =>

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/CapturedVars.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import MegaPhase._
import core.DenotTransformers._
import core.Symbols._
import core.Contexts._
import core.Phases.atPhase
import core.Flags._
import core.Decorators._
import core.StdNames.nme
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/ElimByName.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package transform

import core._
import DenotTransformers.InfoTransformer
import Phases.atPhase
import Symbols._
import Contexts._
import Types._
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Contexts._
import Symbols._
import Constants._
import Decorators._
import Phases._
import Denotations._, SymDenotations._
import dotty.tools.dotc.ast.tpd
import TypeErasure.erasure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Flags._
import Types._
import Constants.Constant
import Contexts._
import Phases.atPhase
import Symbols._
import Decorators._
import scala.collection.mutable
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import MegaPhase._
import core.DenotTransformers._
import core.Symbols._
import core.Contexts._
import core.Phases._
import core.Types._
import core.Flags._
import core.Decorators._
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package transform

import core._
import MegaPhase._
import Contexts.{Context, ctx, atPhase}
import Contexts.{Context, ctx}
import Phases.atPhase
import Flags._
import SymUtils._
import Symbols._
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/MixinOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools.dotc
package transform

import core._
import Symbols._, Types._, Contexts._, DenotTransformers._, Flags._
import Symbols._, Types._, Contexts._, DenotTransformers._, Flags._, Phases._
import util.Spans._
import SymUtils._
import StdNames._, NameOps._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package transform
import core._
import ast.Trees._
import Contexts._, Types._, Symbols._, Flags._, TypeUtils._, DenotTransformers._, StdNames._
import Decorators._
import Decorators._, Phases._
import MegaPhase._
import NameKinds.ParamAccessorName
import config.Printers.typr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.collection.mutable
import ValueClasses.isMethodWithExtension
import core._
import Contexts._, Flags._, Symbols._, NameOps._, Trees._
import TypeUtils._, SymUtils._
import TypeUtils._, SymUtils._, Phases._
import DenotTransformers.DenotTransformer
import Symbols._
import util.Spans._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Types._
import Flags._
import Decorators._
import DenotTransformers._
import Phases.currentPhase
import Phases._
import core.StdNames.nme
import ast.Trees._
import reporting.trace
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.{File => JFile, PrintStream}
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.ast.{tpd, untpd}
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.core.Phases.{curPhases, typerPhase}
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Denotations.Denotation
import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Mode
Expand Down

0 comments on commit bce1767

Please sign in to comment.