Skip to content

Commit 4be324e

Browse files
Revert moving definitions to Definitions
1 parent 45232ba commit 4be324e

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,6 @@ class Definitions {
372372
def Seq_apply(implicit ctx: Context) = Seq_applyR.symbol
373373
lazy val Seq_headR = SeqClass.requiredMethodRef(nme.head)
374374
def Seq_head(implicit ctx: Context) = Seq_headR.symbol
375-
lazy val SeqFactoryType: TypeRef = ctx.requiredClassRef("scala.collection.generic.SeqFactory")
376-
def SeqFactoryClass(implicit ctx: Context) = SeqFactoryType.symbol.asClass
377375

378376
lazy val ArrayType: TypeRef = ctx.requiredClassRef("scala.Array")
379377
def ArrayClass(implicit ctx: Context) = ArrayType.symbol.asClass
@@ -448,8 +446,6 @@ class Definitions {
448446
def Long_* = Long_mulR.symbol
449447
lazy val Long_divR = LongClass.requiredMethodRef(nme.DIV, List(LongType))
450448
def Long_/ = Long_divR.symbol
451-
val CommutativePrimitiveOperations = new PerRun[collection.Set[Symbol]](implicit ctx =>
452-
Set(defn.Boolean_&&, defn.Boolean_||, defn.Int_+, defn.Int_*, defn.Long_+, defn.Long_*))
453449

454450
lazy val FloatType: TypeRef = valueTypeRef("scala.Float", BoxedFloatType, java.lang.Float.TYPE, FloatEnc)
455451
def FloatClass(implicit ctx: Context) = FloatType.symbol.asClass

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Simplify.desugarIdent
2626
*
2727
* @author DarkDimius, OlivierBlanvillain
2828
*/
29-
class ConstantFold extends Optimisation {
29+
class ConstantFold(val simplifyPhase: Simplify) extends Optimisation {
3030
import ast.tpd._
3131

3232
def visitor(implicit ctx: Context) = NoVisitor
@@ -94,7 +94,7 @@ import Simplify.desugarIdent
9494
case t @ Apply(Select(lhs, _), List(rhs)) =>
9595
val sym = t.symbol
9696
(lhs, rhs) match {
97-
case (lhs, Literal(_)) if !lhs.isInstanceOf[Literal] && defn.CommutativePrimitiveOperations().contains(sym) =>
97+
case (lhs, Literal(_)) if !lhs.isInstanceOf[Literal] && simplifyPhase.CommutativePrimitiveOperations.contains(sym) =>
9898
rhs.select(sym).appliedTo(lhs)
9999

100100
case (l, _) if (sym == defn.Boolean_&&) && isConst(l.tpe) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import dotty.tools.dotc.ast.tpd
2020
*
2121
* @author DarkDimius, OlivierBlanvillain
2222
*/
23-
class InlineCaseIntrinsics extends Optimisation {
23+
class InlineCaseIntrinsics(val simplifyPhase: Simplify) extends Optimisation {
2424
import ast.tpd._
2525

2626
def visitor(implicit ctx: Context): Tree => Unit = NoVisitor
@@ -100,7 +100,7 @@ class InlineCaseIntrinsics extends Optimisation {
100100
// Where Seq is any companion of type <: SeqFactoryClass
101101
case a: Apply
102102
if a.symbol.name == nme.unapplySeq &&
103-
a.symbol.owner.derivesFrom(defn.SeqFactoryClass) &&
103+
a.symbol.owner.derivesFrom(simplifyPhase.SeqFactoryClass) &&
104104
a.symbol.extendedOverriddenSymbols.isEmpty &&
105105
(isPureExpr(a.fun) || a.fun.symbol.is(Synthetic)) =>
106106

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package transform.localopt
33

44
import core.Contexts.Context
55
import core.DenotTransformers.IdentityDenotTransformer
6+
import core.Symbols._
67
import core.Types._
8+
import core.Flags._
9+
import core.Decorators._
710
import transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
811
import config.Printers.simplify
9-
import core.Flags._
1012
import ast.tpd
1113

1214
/** This phase consists of a series of small, simple, local optimisations
@@ -26,14 +28,17 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
2628
override def phaseName: String = "simplify"
2729
override val cpy = tpd.cpy
2830

31+
private[localopt] var SeqFactoryClass: Symbol = null
32+
private[localopt] var CommutativePrimitiveOperations: Set[Symbol] = null
33+
2934
/** The original intention is to run most optimizations both before and after erasure.
3035
* Erasure creates new inefficiencies as well as new optimization opportunities.
3136
*
3237
* The order of optimizations is tuned to converge faster.
3338
* Reordering them may require quadratically more rounds to finish.
3439
*/
3540
private def beforeErasure: List[Optimisation] =
36-
new InlineCaseIntrinsics ::
41+
new InlineCaseIntrinsics(this) ::
3742
new RemoveUnnecessaryNullChecks ::
3843
new InlineOptions ::
3944
new InlineLabelsCalledOnce ::
@@ -45,7 +50,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
4550
// new InlineLocalObjects :: // followCases needs to be fixed, see ./tests/pos/rbtree.scala
4651
// new Varify :: // varify could stop other transformations from being applied. postponed.
4752
// new BubbleUpNothing ::
48-
new ConstantFold ::
53+
new ConstantFold(this) ::
4954
Nil
5055

5156
/** See comment on beforeErasure */
@@ -54,7 +59,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
5459
new Devalify ::
5560
new Jumpjump ::
5661
new DropGoodCasts ::
57-
new ConstantFold ::
62+
new ConstantFold(this) ::
5863
Nil
5964

6065
/** Optimisation fuel, for debugging. Decremented every time Simplify
@@ -68,6 +73,8 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
6873
var fuel: Int = -1
6974

7075
override def prepareForUnit(tree: Tree)(implicit ctx: Context) = {
76+
SeqFactoryClass = ctx.requiredClass("scala.collection.generic.SeqFactory")
77+
CommutativePrimitiveOperations = Set(defn.Boolean_&&, defn.Boolean_||, defn.Int_+, defn.Int_*, defn.Long_+, defn.Long_*)
7178
val maxFuel = ctx.settings.YoptFuel.value
7279
if (fuel < 0 && maxFuel > 0) // Both defaults are at -1
7380
fuel = maxFuel

0 commit comments

Comments
 (0)