Skip to content

Commit

Permalink
Bring back devalify phase. Fix bug reported in #3.
Browse files Browse the repository at this point in the history
Devalify runs before constructors and memoize, so constructor arguments
 are not yet assigned to fields and remain unused.
They should not be eliminated before memoire and constructors has run.
  • Loading branch information
DarkDimius committed Jun 24, 2016
1 parent 1527712 commit 7d10e52
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/dotty/tools/dotc/transform/linker/Simplify.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
type Transformer = () => (Tree => Tree)
type Optimization = (Context) => (String, ErasureCompatibility, Visitor, Transformer)

private lazy val _optimizations = Seq(inlineCaseIntrinsics, inlineLabelsCalledOnce,/* devalify,*/ dropNoEffects, inlineLocalObjects/*, varify*/)
private lazy val _optimizations = Seq(inlineCaseIntrinsics, inlineLabelsCalledOnce, devalify, dropNoEffects, inlineLocalObjects/*, varify*/)
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
if (!tree.symbol.is(Flags.Label)) {
var rhs0 = tree.rhs
Expand Down Expand Up @@ -396,16 +396,17 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
val defined = collection.mutable.HashSet[Symbol]()
val copies = collection.mutable.HashMap[Symbol, Tree]() // either a duplicate or a read through series of immutable fields
val visitor: Visitor = {
case valdef: ValDef if !valdef.symbol.is(Flags.Param) && !valdef.symbol.is(Flags.Mutable) =>
case valdef: ValDef if !valdef.symbol.is(Flags.Param) && !valdef.symbol.is(Flags.Mutable) && (valdef.symbol.exists && !valdef.symbol.owner.isClass) =>
defined += valdef.symbol

dropCasts(valdef.rhs) match {
case t: Tree if readingOnlyVals(t) =>
copies.put(valdef.symbol, valdef.rhs)
case _ =>
}
case t: ValDef =>
defined += t.symbol
case valdef: ValDef if valdef.symbol.exists && !valdef.symbol.owner.isClass && !valdef.symbol.is(Flags.Param) =>
//todo: handle params after constructors. Start changing public signatures by eliminating unused arguments.
defined += valdef.symbol

case t: RefTree =>
val b4 = timesUsed.getOrElseUpdate(t.symbol, 0)
Expand Down Expand Up @@ -434,8 +435,10 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {

val transformation: Tree => Tree = {
case t: ValDef if valsToDrop.contains(t.symbol) =>
// println(s"droping definition of ${t.symbol.showFullName} as not used")
t.rhs
case t: ValDef if replacements.contains(t.symbol) =>
// println(s"droping definition of ${t.symbol.showFullName} as an alias")
EmptyTree
case t: Block => // drop non-side-effecting stats
t
Expand Down

0 comments on commit 7d10e52

Please sign in to comment.