From b2d1e87059a097809285803c3ec123ec36d4a4aa Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 14 Mar 2016 14:52:02 +0100 Subject: Move Mode to core Mode is used from a lot of low-level code, does not just reflect Typer info. So it makes more sense top to place it in the core package. --- src/dotty/tools/dotc/Compiler.scala | 2 +- src/dotty/tools/dotc/ast/Desugar.scala | 1 - src/dotty/tools/dotc/ast/tpd.scala | 1 - src/dotty/tools/dotc/core/Annotations.scala | 1 - src/dotty/tools/dotc/core/Contexts.scala | 2 +- src/dotty/tools/dotc/core/Decorators.scala | 1 - src/dotty/tools/dotc/core/Denotations.scala | 1 - src/dotty/tools/dotc/core/Mode.scala | 85 +++++++++++++++++++++ src/dotty/tools/dotc/core/SymDenotations.scala | 1 - src/dotty/tools/dotc/core/TypeApplications.scala | 1 - src/dotty/tools/dotc/core/TypeComparer.scala | 1 - src/dotty/tools/dotc/core/TypeErasure.scala | 1 - src/dotty/tools/dotc/core/Types.scala | 3 +- .../dotc/core/classfile/ClassfileParser.scala | 1 - .../tools/dotc/core/tasty/TreeUnpickler.scala | 1 - .../dotc/core/unpickleScala2/Scala2Unpickler.scala | 1 - src/dotty/tools/dotc/printing/PlainPrinter.scala | 1 - src/dotty/tools/dotc/reporting/Reporter.scala | 2 +- src/dotty/tools/dotc/transform/Erasure.scala | 2 +- src/dotty/tools/dotc/transform/LazyVals.scala | 1 - .../tools/dotc/transform/PatternMatcher.scala | 2 +- src/dotty/tools/dotc/transform/RestoreScopes.scala | 1 - src/dotty/tools/dotc/transform/TreeChecker.scala | 1 + src/dotty/tools/dotc/transform/TreeTransform.scala | 2 +- src/dotty/tools/dotc/typer/Mode.scala | 86 ---------------------- 25 files changed, 93 insertions(+), 109 deletions(-) create mode 100644 src/dotty/tools/dotc/core/Mode.scala delete mode 100644 src/dotty/tools/dotc/typer/Mode.scala (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index fe16243bb..13c98a8fe 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -7,7 +7,7 @@ import Periods._ import Symbols._ import Types._ import Scopes._ -import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks} +import typer.{FrontEnd, Typer, ImportInfo, RefChecks} import reporting.{Reporter, ConsoleReporter} import Phases.Phase import transform._ diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 2ab33a120..719f3d036 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -9,7 +9,6 @@ import Decorators._ import language.higherKinds import collection.mutable.ListBuffer import config.Printers._ -import typer.Mode object desugar { diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index a6d97478b..8d21953ae 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -10,7 +10,6 @@ import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._ import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._ import Denotations._, Decorators._, DenotTransformers._ import config.Printers._ -import typer.Mode import collection.mutable import typer.ErrorReporting._ diff --git a/src/dotty/tools/dotc/core/Annotations.scala b/src/dotty/tools/dotc/core/Annotations.scala index 2b27b5e01..dc4897233 100644 --- a/src/dotty/tools/dotc/core/Annotations.scala +++ b/src/dotty/tools/dotc/core/Annotations.scala @@ -5,7 +5,6 @@ import Symbols._, Types._, util.Positions._, Contexts._, Constants._, ast.tpd._ import config.ScalaVersion import StdNames._ import dotty.tools.dotc.ast.{tpd, untpd} -import dotty.tools.dotc.typer.ProtoTypes.FunProtoTyped object Annotations { diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index fd0cff94e..a0bb03e50 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -18,7 +18,7 @@ import util.Positions._ import ast.Trees._ import ast.untpd import util.{FreshNameCreator, SimpleMap, SourceFile, NoSource} -import typer._ +import typer.{Implicits, ImplicitRunInfo, ImportInfo, NamerContextOps, SearchHistory, TypeAssigner, Typer} import Implicits.ContextualImplicits import config.Settings._ import config.Config diff --git a/src/dotty/tools/dotc/core/Decorators.scala b/src/dotty/tools/dotc/core/Decorators.scala index 60c019bce..7d108a459 100644 --- a/src/dotty/tools/dotc/core/Decorators.scala +++ b/src/dotty/tools/dotc/core/Decorators.scala @@ -7,7 +7,6 @@ import Contexts._, Names._, Phases._, printing.Texts._, printing.Printer, printi import util.Positions.Position, util.SourcePosition import collection.mutable.ListBuffer import dotty.tools.dotc.transform.TreeTransforms._ -import typer.Mode import scala.language.implicitConversions /** This object provides useful implicit decorators for types defined elsewhere */ diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index b52c11201..218fb8561 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -18,7 +18,6 @@ import printing.Texts._ import printing.Printer import io.AbstractFile import config.Config -import typer.Mode import util.common._ import collection.mutable.ListBuffer import Decorators.SymbolIteratorDecorator diff --git a/src/dotty/tools/dotc/core/Mode.scala b/src/dotty/tools/dotc/core/Mode.scala new file mode 100644 index 000000000..5b3dbc872 --- /dev/null +++ b/src/dotty/tools/dotc/core/Mode.scala @@ -0,0 +1,85 @@ +package dotty.tools.dotc.core + +/** A collection of mode bits that are part of a context */ +case class Mode(val bits: Int) extends AnyVal { + import Mode._ + def | (that: Mode) = Mode(bits | that.bits) + def & (that: Mode) = Mode(bits & that.bits) + def &~ (that: Mode) = Mode(bits & ~that.bits) + def is (that: Mode) = (bits & that.bits) == that.bits + + def isExpr = (this & PatternOrType) == None + + override def toString = + (0 until 31).filter(i => (bits & (1 << i)) != 0).map(modeName).mkString("Mode(", ",", ")") +} + +object Mode { + val None = Mode(0) + + private val modeName = new Array[String](32) + + def newMode(bit: Int, name: String): Mode = { + modeName(bit) = name + Mode(1 << bit) + } + + val Pattern = newMode(0, "Pattern") + val Type = newMode(1, "Type") + + val ImplicitsEnabled = newMode(2, "ImplicitsEnabled") + val InferringReturnType = newMode(3, "InferringReturnType") + + /** This mode bit is set if we collect information without reference to a valid + * context with typerstate and constraint. This is typically done when we + * cache the eligibility of implicits. Caching needs to be done across different constraints. + * Therefore, if TypevarsMissContext is set, subtyping becomes looser, and assumes + * that PolyParams can be sub- and supertypes of anything. See TypeComparer. + */ + val TypevarsMissContext = newMode(4, "TypevarsMissContext") + val CheckCyclic = newMode(5, "CheckCyclic") + + val InSuperCall = newMode(6, "InSuperCall") + + /** This mode bit is set if we want to allow accessing a symbol's denotation + * at a period before that symbol is first valid. An example where this is + * the case is if we want to examine the environment where an access is made. + * The computation might take place at an earlier phase (e.g. it is part of + * some completion such as unpickling), but the environment might contain + * synbols that are not yet defined in that phase. + * If the mode bit is set, getting the denotation of a symbol at a phase + * before the symbol is defined will return the symbol's denotation at the + * first phase where it is valid, instead of throwing a NotDefinedHere error. + */ + val FutureDefsOK = newMode(7, "FutureDefsOK") + + /** Allow GADTFlexType labelled types to have their bounds adjusted */ + val GADTflexible = newMode(8, "GADTflexible") + + /** Allow dependent functions. This is currently necessary for unpickling, because + * some dependent functions are passed through from the front end(s?), even though they + * are technically speaking illegal. + */ + val AllowDependentFunctions = newMode(9, "AllowDependentFunctions") + + /** We are currently printing something: avoid to produce more logs about + * the printing + */ + val Printing = newMode(10, "Printing") + + /** We are currently typechecking an ident to determine whether some implicit + * is shadowed - don't do any other shadowing tests. + */ + val ImplicitShadowing = newMode(11, "ImplicitShadowing") + + /** We are currently in a `viewExists` check. In that case, ambiguous + * implicits checks are disabled and we succeed with the first implicit + * found. + */ + val ImplicitExploration = newMode(12, "ImplicitExploration") + + /** We are currently unpickling Scala2 info */ + val Scala2Unpickling = newMode(13, "Scala2Unpickling") + + val PatternOrType = Pattern | Type +} diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index a83e7726a..28932b691 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -13,7 +13,6 @@ import Decorators.SymbolIteratorDecorator import ast._ import annotation.tailrec import CheckRealizable._ -import typer.Mode import util.SimpleMap import util.Stats import config.Config diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 8f8a7dbdd..26ffefec4 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -12,7 +12,6 @@ import Names._ import NameOps._ import Flags._ import StdNames.tpnme -import typer.Mode import util.Positions.Position import config.Printers._ import collection.mutable diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 4e7a4a75d..c846737b6 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -3,7 +3,6 @@ package dotc package core import Types._, Contexts._, Symbols._, Flags._, Names._, NameOps._, Denotations._ -import typer.Mode import Decorators._ import StdNames.{nme, tpnme} import collection.mutable diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 26cac4f72..a7d825131 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -6,7 +6,6 @@ import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Decorators. import Uniques.unique import dotc.transform.ExplicitOuter._ import dotc.transform.ValueClasses._ -import typer.Mode import util.DotClass /** Erased types are: diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 3801f1914..5dfe3a4f1 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -31,7 +31,6 @@ import config.Config import config.Printers._ import annotation.tailrec import Flags.FlagSet -import typer.Mode import language.implicitConversions import scala.util.hashing.{ MurmurHash3 => hashing } @@ -3446,7 +3445,7 @@ object Types { object CyclicReference { def apply(denot: SymDenotation)(implicit ctx: Context): CyclicReference = { val ex = new CyclicReference(denot) - if (!(ctx.mode is typer.Mode.CheckCyclic)) { + if (!(ctx.mode is Mode.CheckCyclic)) { cyclicErrors.println(ex.getMessage) for (elem <- ex.getStackTrace take 200) cyclicErrors.println(elem.toString) diff --git a/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 25558a79a..f7a69aa53 100644 --- a/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -12,7 +12,6 @@ import scala.collection.{ mutable, immutable } import scala.collection.mutable.{ ListBuffer, ArrayBuffer } import scala.annotation.switch import typer.Checking.checkNonCyclic -import typer.Mode import io.AbstractFile import scala.util.control.NonFatal diff --git a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index eb3369184..b547862b4 100644 --- a/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -13,7 +13,6 @@ import TastyUnpickler._, TastyBuffer._, PositionPickler._ import scala.annotation.{tailrec, switch} import scala.collection.mutable.ListBuffer import scala.collection.{ mutable, immutable } -import typer.Mode import config.Printers.pickling /** Unpickler for typed trees diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 2831de3e0..e4c8d7d13 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -17,7 +17,6 @@ import printing.Printer import io.AbstractFile import util.common._ import typer.Checking.checkNonCyclic -import typer.Mode import PickleBuffer._ import scala.reflect.internal.pickling.PickleFormat._ import Decorators._ diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index 6d026dde7..3fb220afe 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -8,7 +8,6 @@ import StdNames.{nme, tpnme} import ast.Trees._, ast._ import java.lang.Integer.toOctalString import config.Config.summarizeDepth -import typer.Mode import scala.annotation.switch class PlainPrinter(_ctx: Context) extends Printer { diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index 8236f93ef..44defa6b1 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -10,7 +10,7 @@ import collection.mutable import config.Settings.Setting import config.Printers import java.lang.System.currentTimeMillis -import typer.Mode +import core.Mode import interfaces.Diagnostic.{ERROR, WARNING, INFO} object Reporter { diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index 8d890902e..b4beaab88 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -25,7 +25,7 @@ import dotty.tools.dotc.core.Flags import ValueClasses._ import TypeUtils._ import ExplicitOuter._ -import typer.Mode +import core.Mode class Erasure extends Phase with DenotTransformer { thisTransformer => diff --git a/src/dotty/tools/dotc/transform/LazyVals.scala b/src/dotty/tools/dotc/transform/LazyVals.scala index fc02e68cc..e42c7bae9 100644 --- a/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/src/dotty/tools/dotc/transform/LazyVals.scala @@ -3,7 +3,6 @@ package transform import dotty.tools.dotc.core.Annotations.Annotation import dotty.tools.dotc.core.Phases.NeedsCompanions -import dotty.tools.dotc.typer.Mode import scala.collection.mutable import core._ diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index a7f654780..35e772cd1 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -21,7 +21,7 @@ import ast.Trees._ import Applications._ import TypeApplications._ import SymUtils._, core.NameOps._ -import typer.Mode +import core.Mode import dotty.tools.dotc.util.Positions.Position import dotty.tools.dotc.core.Decorators._ diff --git a/src/dotty/tools/dotc/transform/RestoreScopes.scala b/src/dotty/tools/dotc/transform/RestoreScopes.scala index 41da05691..8b9d2be0d 100644 --- a/src/dotty/tools/dotc/transform/RestoreScopes.scala +++ b/src/dotty/tools/dotc/transform/RestoreScopes.scala @@ -11,7 +11,6 @@ import TreeTransforms.MiniPhaseTransform import SymDenotations._ import ast.Trees._ import NameOps._ -import typer.Mode import TreeTransforms.TransformerInfo import StdNames._ diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala index a260963e9..dadaf52e2 100644 --- a/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -15,6 +15,7 @@ import core.StdNames._ import core.Decorators._ import core.TypeErasure.isErasedType import core.Phases.Phase +import core.Mode import typer._ import typer.ErrorReporting._ import reporting.ThrowingReporter diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala index 7fe003388..67bd2f160 100644 --- a/src/dotty/tools/dotc/transform/TreeTransform.scala +++ b/src/dotty/tools/dotc/transform/TreeTransform.scala @@ -11,7 +11,7 @@ import dotty.tools.dotc.core.Phases.Phase import dotty.tools.dotc.core.SymDenotations.SymDenotation import dotty.tools.dotc.core.Symbols.Symbol import dotty.tools.dotc.core.Flags.PackageVal -import dotty.tools.dotc.typer.Mode +import dotty.tools.dotc.core.Mode import dotty.tools.dotc.ast.Trees._ import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.util.DotClass diff --git a/src/dotty/tools/dotc/typer/Mode.scala b/src/dotty/tools/dotc/typer/Mode.scala deleted file mode 100644 index 55d44ad7a..000000000 --- a/src/dotty/tools/dotc/typer/Mode.scala +++ /dev/null @@ -1,86 +0,0 @@ -package dotty.tools.dotc.typer - -import collection.mutable - -case class Mode(val bits: Int) extends AnyVal { - import Mode._ - def | (that: Mode) = Mode(bits | that.bits) - def & (that: Mode) = Mode(bits & that.bits) - def &~ (that: Mode) = Mode(bits & ~that.bits) - def is (that: Mode) = (bits & that.bits) == that.bits - - def isExpr = (this & PatternOrType) == None - - override def toString = - (0 until 31).filter(i => (bits & (1 << i)) != 0).map(modeName).mkString("Mode(", ",", ")") -} - -object Mode { - val None = Mode(0) - - private val modeName = new Array[String](32) - - def newMode(bit: Int, name: String): Mode = { - modeName(bit) = name - Mode(1 << bit) - } - - val Pattern = newMode(0, "Pattern") - val Type = newMode(1, "Type") - - val ImplicitsEnabled = newMode(2, "ImplicitsEnabled") - val InferringReturnType = newMode(3, "InferringReturnType") - - /** This mode bit is set if we collect information without reference to a valid - * context with typerstate and constraint. This is typically done when we - * cache the eligibility of implicits. Caching needs to be done across different constraints. - * Therefore, if TypevarsMissContext is set, subtyping becomes looser, and assumes - * that PolyParams can be sub- and supertypes of anything. See TypeComparer. - */ - val TypevarsMissContext = newMode(4, "TypevarsMissContext") - val CheckCyclic = newMode(5, "CheckCyclic") - - val InSuperCall = newMode(6, "InSuperCall") - - /** This mode bit is set if we want to allow accessing a symbol's denotation - * at a period before that symbol is first valid. An example where this is - * the case is if we want to examine the environment where an access is made. - * The computation might take place at an earlier phase (e.g. it is part of - * some completion such as unpickling), but the environment might contain - * synbols that are not yet defined in that phase. - * If the mode bit is set, getting the denotation of a symbol at a phase - * before the symbol is defined will return the symbol's denotation at the - * first phase where it is valid, instead of throwing a NotDefinedHere error. - */ - val FutureDefsOK = newMode(7, "FutureDefsOK") - - /** Allow GADTFlexType labelled types to have their bounds adjusted */ - val GADTflexible = newMode(8, "GADTflexible") - - /** Allow dependent functions. This is currently necessary for unpickling, because - * some dependent functions are passed through from the front end(s?), even though they - * are technically speaking illegal. - */ - val AllowDependentFunctions = newMode(9, "AllowDependentFunctions") - - /** We are currently printing something: avoid to produce more logs about - * the printing - */ - val Printing = newMode(10, "Printing") - - /** We are currently typechecking an ident to determine whether some implicit - * is shadowed - don't do any other shadowing tests. - */ - val ImplicitShadowing = newMode(11, "ImplicitShadowing") - - /** We are currently in a `viewExists` check. In that case, ambiguous - * implicits checks are disabled and we succeed with the first implicit - * found. - */ - val ImplicitExploration = newMode(12, "ImplicitExploration") - - /** We are currently unpickling Scala2 info */ - val Scala2Unpickling = newMode(13, "Scala2Unpickling") - - val PatternOrType = Pattern | Type -} -- cgit v1.2.3