diff options
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/ElimLocals.scala | 17 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/DenotTransformers.scala | 13 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/Companions.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ReTyper.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 5 |
6 files changed, 33 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index 28b340eb4..fff4b517b 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -22,7 +22,7 @@ class Compiler { List(new Companions), List(new SuperAccessors), // pickling and refchecks goes here - List(new ElimRepeated/*, new ElimLocals*/), + List(new ElimRepeated, new ElimLocals), List(new ExtensionMethods), List(new TailRec), List(new PatternMatcher, diff --git a/src/dotty/tools/dotc/ElimLocals.scala b/src/dotty/tools/dotc/ElimLocals.scala index 878783ffc..cc971f05c 100644 --- a/src/dotty/tools/dotc/ElimLocals.scala +++ b/src/dotty/tools/dotc/ElimLocals.scala @@ -2,12 +2,21 @@ package dotty.tools.dotc package transform import core._ -import TreeTransforms.{TransformerInfo, TreeTransform, TreeTransformer} -import DenotTransformers._ +import DenotTransformers.SymTransformer +import Phases.Phase +import Contexts.Context +import SymDenotations.SymDenotation +import TreeTransforms.TreeTransform +import Flags.Local /** Widens all private[this] and protected[this] qualifiers to just private/protected */ -abstract class ElimLocals extends TreeTransform with InfoTransformer { thisTransformer => +class ElimLocals extends TreeTransform with SymTransformer { thisTransformer => + override def name = "elimlocals" - // TODO complete + def transformSym(ref: SymDenotation)(implicit ctx: Context) = + dropLocal(ref) + private def dropLocal(ref: SymDenotation)(implicit ctx: Context) = + if (ref.flags is Local) ref.copySymDenotation(initFlags = ref.flags &~ Local) + else ref }
\ No newline at end of file diff --git a/src/dotty/tools/dotc/core/DenotTransformers.scala b/src/dotty/tools/dotc/core/DenotTransformers.scala index e052a07ea..0e31d87e6 100644 --- a/src/dotty/tools/dotc/core/DenotTransformers.scala +++ b/src/dotty/tools/dotc/core/DenotTransformers.scala @@ -32,11 +32,11 @@ object DenotTransformers { def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation } + /** A transformer that only transforms the info field of denotations */ trait InfoTransformer extends DenotTransformer { def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type - /** The transformation method */ def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = { val info1 = transformInfo(ref.info, ref.symbol) if (info1 eq ref.info) ref @@ -47,6 +47,17 @@ object DenotTransformers { } } + /** A transformer that only transforms SymDenotations */ + trait SymTransformer extends DenotTransformer { + + def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation + + def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = ref match { + case ref: SymDenotation => transformSym(ref) + case _ => ref + } + } + /** A `DenotTransformer` trait that has the identity as its `transform` method. * You might want to inherit from this trait so that new denotations can be * installed using `installAfter` and `enteredAfter` at the end of the phase. diff --git a/src/dotty/tools/dotc/transform/Companions.scala b/src/dotty/tools/dotc/transform/Companions.scala index 0e31b511d..f6e3dbfdc 100644 --- a/src/dotty/tools/dotc/transform/Companions.scala +++ b/src/dotty/tools/dotc/transform/Companions.scala @@ -14,8 +14,7 @@ import Names.Name import NameOps._ -/** A transformer that provides a convenient way to create companion objects - */ +/** A transformer that creates companion objects for all classes except module classes. */ class Companions extends TreeTransform with IdentityDenotTransformer { thisTransformer => import ast.tpd._ diff --git a/src/dotty/tools/dotc/typer/ReTyper.scala b/src/dotty/tools/dotc/typer/ReTyper.scala index 6adfa3052..392b8dca1 100644 --- a/src/dotty/tools/dotc/typer/ReTyper.scala +++ b/src/dotty/tools/dotc/typer/ReTyper.scala @@ -66,4 +66,6 @@ class ReTyper extends Typer { override def addTypedModifiersAnnotations(mods: untpd.Modifiers, sym: Symbol)(implicit ctx: Context): Modifiers = typedModifiers(mods, sym) + + override def checkVariance(tree: Tree)(implicit ctx: Context) = () }
\ No newline at end of file diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 0ce02d198..d5153bf13 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -844,7 +844,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit checkNoDoubleDefs(cls) val impl1 = cpy.Template(impl, constr1, parents1, self1, body1) .withType(dummy.termRef) - VarianceChecker.check(impl1) + checkVariance(impl1) assignType(cpy.TypeDef(cdef, mods1, name, impl1), cls) // todo later: check that @@ -856,6 +856,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit // 4. Polymorphic type defs override nothing. } + /** Overridden in retyper */ + def checkVariance(tree: Tree)(implicit ctx: Context) = VarianceChecker.check(tree) + def localDummy(cls: ClassSymbol, impl: untpd.Template)(implicit ctx: Context): Symbol = ctx.newLocalDummy(cls, impl.pos) |