Skip to content

Commit 195d5e6

Browse files
Clean up
1 parent ff91037 commit 195d5e6

11 files changed

+41
-43
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/BubbleUpNothing.scala

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import core.Symbols._
66
import ast.Trees._
77
import dotty.tools.dotc.ast.tpd
88

9-
/**
10-
* If a block has a statement that evaluates to Nothing:
11-
* - Every pure statement dirrectly preceding an expression that returns Nothing can be removed,
12-
* - as every statement after an expression that returns Nothing can be removed
9+
/** If a block has a statement that evaluates to Nothing:
10+
* - Every pure statement dirrectly preceding an expression that returns Nothing can be removed,
11+
* - as every statement after an expression that returns Nothing can be removed
1312
*
14-
* If an If condition evalutates to Nothing, the entire If can be replaced by condition
15-
* If an argument evaluates to Nothing, the entire call can be replaced by evaluation of arguments.
13+
* If an If condition evalutates to Nothing, the entire If can be replaced by condition
14+
* If an argument evaluates to Nothing, the entire call can be replaced by evaluation of arguments.
1615
*
1716
* This optimisation makes it rather tricky to write meaningful examples
1817
* since the compiler will often be able to reduce them to a single main
@@ -25,11 +24,7 @@ class BubbleUpNothing extends Optimisation {
2524

2625
def visitor(implicit ctx: Context) = NoVisitor
2726

28-
29-
/** Does the actual Tree => Tree transformation, possibly using a different
30-
* context from the one used in Optimisation.
31-
*/
32-
def transformer(implicit ctx: Context): (tpd.Tree) => tpd.Tree = {
27+
def transformer(implicit ctx: Context): Tree => Tree = {
3328
case t @ Apply(Select(Notathing(qual), _), args) =>
3429
Typed(qual, TypeTree(t.tpe))
3530
// This case leads to complications with multiple argument lists,

compiler/src/dotty/tools/dotc/transform/localopt/ConstantFold.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ import Simplify.desugarIdent
1111
/** Various constant folding.
1212
*
1313
* - Starts/ends with the constant folding implemented in typer (ConstFold).
14+
*
1415
* - Join branches if they are "similar"
15-
* - regularize arithmetic and boolean expressions to have constants on the left, ie. 6 * 2 * a * 5 => 60 * a
16+
*
17+
* - regularize arithmetic and boolean expressions to have constants on the
18+
* left, ie. 6 * 2 * a * 5 => 60 * a
19+
*
1620
* - (if) specific optimisation that propagate booleans, negation, and factor
17-
* out (nested) if with equivalent branches wrt to isSimilar (using &&,||). Dark: ping @OlivierBlanvillain, I didn't understand this
21+
* out (nested) if with equivalent branches wrt to isSimilar. For example:
22+
* - if (b) exp else exp → b; exp
23+
* - if (b1) e1 else if (b2) e1 else e2 → if (b1 || b2) e1 else e2
1824
*
1925
* - Constant propagation over pattern matching.
2026
*
@@ -209,7 +215,7 @@ import Simplify.desugarIdent
209215
case _ => false
210216
}
211217

212-
def isBool(tpe: Type)(implicit ctx: Context): Boolean = tpe.derivesFrom(defn.BooleanClass)
218+
def isBool(tpe: Type)(implicit ctx: Context): Boolean = tpe.derivesFrom(defn.BooleanClass)
213219
def isConst(tpe: Type)(implicit ctx: Context): Boolean = tpe.isInstanceOf[ConstantType]
214220
def asConst(tpe: Type)(implicit ctx: Context): ConstantType = tpe.asInstanceOf[ConstantType]
215221
}

compiler/src/dotty/tools/dotc/transform/localopt/Devalify.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import transform.SymUtils._
1515

1616
/** Inline vals and remove vals that are aliases to other vals
1717
*
18-
* Notion of alias is a by-value notion, so "good" casts are ignored.
18+
* Notion of alias is a by-value notion, so "good" casts are ignored.
1919
*
20-
* This phase has to be careful not to eliminate vals that are parts of other types
21-
* @author DarkDimius, OlivierBlanvillain
22-
* */
20+
* This phase has to be careful not to eliminate vals that are parts of other types
21+
*
22+
* @author DarkDimius, OlivierBlanvillain
23+
*/
2324
class Devalify extends Optimisation {
2425
import ast.tpd._
2526

@@ -98,7 +99,7 @@ class Devalify extends Optimisation {
9899
doVisit(tree, timesUsed)
99100
}
100101

101-
override def transformer(implicit ctx: Context): Tree => Tree = {
102+
def transformer(implicit ctx: Context): Tree => Tree = {
102103
val valsToDrop = defined -- timesUsed.keySet -- timesUsedAsType.keySet
103104
val copiesToReplaceAsDuplicates = copies.filter { x =>
104105
val rhs = dropCasts(x._2)

compiler/src/dotty/tools/dotc/transform/localopt/DropNoEffects.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ast.Trees._
1111
import Simplify.desugarIdent
1212

1313
/** Removes side effect free statements in blocks and Defdef.
14-
* Flattens blocks(except Closure-blocks)
14+
* Flattens blocks (except Closure-blocks)
1515
* Note: BoxedUnit currently messes up this phase when run after erasure
1616
*
1717
* @author DarkDimius, OlivierBlanvillain
@@ -59,7 +59,7 @@ class DropNoEffects(val simplifyPhase: Simplify) extends Optimisation {
5959
case t => t
6060
}
6161

62-
def keepOnlySideEffects(t: Tree)(implicit ctx: Context): Tree = t match {
62+
def keepOnlySideEffects(t: Tree)(implicit ctx: Context): Tree = t match {
6363
case l: Literal =>
6464
EmptyTree
6565

compiler/src/dotty/tools/dotc/transform/localopt/InlineCaseIntrinsics.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import dotty.tools.dotc.ast.tpd
2323
class InlineCaseIntrinsics extends Optimisation {
2424
import ast.tpd._
2525

26-
def visitor(implicit ctx: Context): (tpd.Tree) => Unit = NoVisitor
26+
def visitor(implicit ctx: Context): Tree => Unit = NoVisitor
2727

28-
def transformer(implicit localCtx: Context): Tree => Tree = {
28+
def transformer(implicit ctx: Context): Tree => Tree = {
2929
// For synthetic applies on case classes (both dotty/scalac)
3030
// - CC.apply(args) → new CC(args)
3131
case a: Apply

compiler/src/dotty/tools/dotc/transform/localopt/InlineLabelsCalledOnce.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import config.Printers.simplify
1010

1111
/** Inlines LabelDef which are used exactly once.
1212
*
13-
* @author DarkDimius, OlivierBlanvillain
14-
*
15-
* */
13+
* @author DarkDimius, OlivierBlanvillain
14+
*/
1615
class InlineLabelsCalledOnce extends Optimisation {
1716
import ast.tpd._
1817

compiler/src/dotty/tools/dotc/transform/localopt/Jumpjump.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import core.Flags._
1313

1414
/** Rewrites pairs of consecutive LabelDef jumps by jumping directly to the target.
1515
*
16-
* @author DarkDimius, OlivierBlanvillain
17-
* */
16+
* @author DarkDimius, OlivierBlanvillain
17+
*/
1818
class Jumpjump extends Optimisation {
1919
import ast.tpd._
2020

compiler/src/dotty/tools/dotc/transform/localopt/Optimisation.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ trait Optimisation {
99
/** Run first to gather information on Trees (using mutation) */
1010
def visitor(implicit ctx: Context): Tree => Unit
1111

12-
/** Does the actual Tree => Tree transformation, possibly using a different
13-
* context from the one used in Optimisation.
14-
*/
12+
/** Does the actual Tree => Tree transformation. */
1513
def transformer(implicit ctx: Context): Tree => Tree
1614

1715
def name: String = this.getClass.getSimpleName

compiler/src/dotty/tools/dotc/transform/localopt/RemoveUnnecessaryNullChecks.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import scala.collection.mutable
1717
* - fallsback to `tpe.isNotNull`, which will eventually be true for non nullable types.
1818
* - in (a.call; a == null), the first call throws a NPE if a is null; the test can be removed.
1919
*
20-
*
2120
* @author DarkDimius, Jvican, OlivierBlanvillain
2221
*/
2322
class RemoveUnnecessaryNullChecks extends Optimisation {
@@ -78,7 +77,7 @@ import scala.collection.mutable
7877
}
7978

8079

81-
def transformer(implicit localCtx: Context): Tree => Tree = {
80+
def transformer(implicit ctx: Context): Tree => Tree = {
8281
def isNullLiteral(tree: Tree) = tree match {
8382
case literal: Literal =>
8483
literal.const.tag == NullTag

compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
2727
override val cpy = tpd.cpy
2828

2929
/** The original intention is to run most optimizations both before and after erasure.
30-
* Erasure creates new inefficiencies as well as new optimization opportunities.
30+
* Erasure creates new inefficiencies as well as new optimization opportunities.
3131
*
32-
* The order of optimizations is tuned to converge faster.
33-
* Reordering them may require quadratically more rounds to finish.
32+
* The order of optimizations is tuned to converge faster.
33+
* Reordering them may require quadratically more rounds to finish.
3434
*/
3535
private val beforeErasure: List[Optimisation] =
3636
new InlineCaseIntrinsics ::
@@ -48,7 +48,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
4848
new ConstantFold ::
4949
Nil
5050

51-
/** see comment on beforeErasure */
51+
/** See comment on beforeErasure */
5252
private val afterErasure: List[Optimisation] =
5353
new Valify(this) ::
5454
new Devalify ::
@@ -68,8 +68,8 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
6868
var fuel: Int = -1
6969

7070

71-
/** using fuel stops any inlining and prevents optimizations from triggering.
72-
* on my tests it gives 20% slowdown, so it is going to be disabled in public builds.
71+
/** Using fuel stops any inlining and prevents optimizations from triggering.
72+
* on my tests it gives 20% slowdown, so it is going to be disabled in public builds.
7373
*/
7474
private final val useFuel = false
7575

@@ -95,7 +95,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
9595
val ctx0 = ctx
9696
if (ctx.settings.optimise.value && !tree.symbol.is(Label)) {
9797
implicit val ctx: Context = ctx0.withOwner(tree.symbol(ctx0))
98-
98+
9999
var rhs0 = tree.rhs
100100
var rhs1: Tree = null
101101
while (rhs1 ne rhs0) {

compiler/src/dotty/tools/dotc/transform/localopt/Valify.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import scala.collection.mutable
1010

1111
/** Rewrite vars with exactly one assignment as vals.
1212
*
13-
* @author DarkDimius, OlivierBlanvillain
14-
* */
13+
* @author DarkDimius, OlivierBlanvillain
14+
*/
1515
class Valify(val simplifyPhase: Simplify) extends Optimisation {
1616
import ast.tpd._
1717

@@ -24,7 +24,7 @@ class Valify(val simplifyPhase: Simplify) extends Optimisation {
2424

2525
val secondWrite: mutable.Map[Symbol, Assign] = mutable.Map()
2626

27-
def visitor(implicit localCtx: Context): Tree => Unit = {
27+
def visitor(implicit ctx: Context): Tree => Unit = {
2828
case t: ValDef if t.symbol.is(Mutable, Lazy) && !t.symbol.is(Method) && !t.symbol.owner.isClass =>
2929
if (isPureExpr(t.rhs))
3030
defined(t.symbol) = t

0 commit comments

Comments
 (0)