From bce17679f5f061ecb00f034a0bfe8ff57ec94ff1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 13 Jul 2020 19:15:36 +0200 Subject: [PATCH] Move atPhase/atPeriod and related to Phases and Periods --- .../tools/backend/jvm/BCodeBodyBuilder.scala | 1 - .../tools/backend/jvm/BCodeHelpers.scala | 2 +- .../tools/backend/jvm/BTypesFromSymbols.scala | 1 - compiler/src/dotty/tools/dotc/ast/tpd.scala | 2 +- .../src/dotty/tools/dotc/core/Contexts.scala | 18 ----------------- .../dotty/tools/dotc/core/Denotations.scala | 2 +- .../src/dotty/tools/dotc/core/Periods.scala | 4 ++++ .../src/dotty/tools/dotc/core/Phases.scala | 20 ++++++++++++++++--- .../tools/dotc/transform/CapturedVars.scala | 1 + .../tools/dotc/transform/ElimByName.scala | 1 + .../tools/dotc/transform/ElimRepeated.scala | 1 + .../tools/dotc/transform/FirstTransform.scala | 1 + .../tools/dotc/transform/LambdaLift.scala | 1 + .../dotty/tools/dotc/transform/Mixin.scala | 3 ++- .../dotty/tools/dotc/transform/MixinOps.scala | 2 +- .../dotc/transform/ParamForwarding.scala | 2 +- .../tools/dotc/transform/SuperAccessors.scala | 2 +- .../dotc/transform/TransformByNameApply.scala | 2 +- .../src/dotty/tools/repl/ReplDriver.scala | 2 +- 19 files changed, 36 insertions(+), 32 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala index 4bdf069891e1..3e36d0ebccf3 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala @@ -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._ /* diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala index 6601642ad9f4..7a579e42d296 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala @@ -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._ diff --git a/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala b/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala index 8b1abe032249..1daa539bf4dc 100644 --- a/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala +++ b/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 14f84bb9ee3b..b632d957d403 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 6f299cfe0099..f2516576089d 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index e6e2eb7c68c9..8e8a5e1cf7de 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/Periods.scala b/compiler/src/dotty/tools/dotc/core/Periods.scala index 2e706329fcfb..10671bf48c7e 100644 --- a/compiler/src/dotty/tools/dotc/core/Periods.scala +++ b/compiler/src/dotty/tools/dotc/core/Periods.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index 30157476ed66..194baa3b6715 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -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 => diff --git a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala index 279fec86190a..591f3b840bd9 100644 --- a/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala +++ b/compiler/src/dotty/tools/dotc/transform/CapturedVars.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala index bdc57529d2ce..fbe59f890548 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala @@ -3,6 +3,7 @@ package transform import core._ import DenotTransformers.InfoTransformer +import Phases.atPhase import Symbols._ import Contexts._ import Types._ diff --git a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala index c2effb6fc7b0..e1077169833c 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala index 085fea1a2d0b..939b25938e0b 100644 --- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -10,6 +10,7 @@ import Flags._ import Types._ import Constants.Constant import Contexts._ +import Phases.atPhase import Symbols._ import Decorators._ import scala.collection.mutable diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 01d88eb07592..9b97f0ba86f8 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -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._ diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index ca264e96146b..8450063c75d7 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -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._ diff --git a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala index 345840f9dfa0..3adc11df735c 100644 --- a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala +++ b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala @@ -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._ diff --git a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala index 0bac0f073398..c031dbfeb75a 100644 --- a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala +++ b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala @@ -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 diff --git a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala index a6775d40380a..a605ab4b66e6 100644 --- a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -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._ diff --git a/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala b/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala index 6bf4ed09b0fe..d7be86c07d22 100644 --- a/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala +++ b/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala @@ -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 diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 679c5531b574..78254c4fc66e 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -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