Skip to content

Added elimLocals miniphase #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions src/dotty/tools/dotc/ElimLocals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 12 additions & 1 deletion src/dotty/tools/dotc/core/DenotTransformers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/dotty/tools/dotc/transform/Companions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down
2 changes: 2 additions & 0 deletions src/dotty/tools/dotc/typer/ReTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) = ()
}
5 changes: 4 additions & 1 deletion src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down