From b7e51dbd464acdf284dc59bca7c36909865db15e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 6 Apr 2018 11:45:30 +0200 Subject: [PATCH 1/3] Do not initialize the Simplifier if it will not transform --- .../dotc/transform/localopt/Simplify.scala | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala index 385ae5f085bc..8f0ca36c1a01 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala @@ -79,17 +79,19 @@ class Simplify extends MiniPhase with IdentityDenotTransformer { var fuel: Int = -1 override def prepareForUnit(tree: Tree)(implicit ctx: Context) = { - SeqFactoryClass = ctx.requiredClass("scala.collection.generic.SeqFactory") - CommutativePrimitiveOperations = Set(defn.Boolean_&&, defn.Boolean_||, defn.Int_+, defn.Int_*, defn.Long_+, defn.Long_*) - - val maxFuel = ctx.settings.YoptFuel.value - if (fuel < 0 && maxFuel > 0) // Both defaults are at -1 - fuel = maxFuel - - optimisations = { - val o = if (ctx.erasedTypes) afterErasure else beforeErasure - val p = ctx.settings.YoptPhases.value - if (p.isEmpty) o else o.filter(x => p.contains(x.name)) + if (ctx.settings.optimise.value) { + SeqFactoryClass = ctx.requiredClass("scala.collection.generic.SeqFactory") + CommutativePrimitiveOperations = Set(defn.Boolean_&&, defn.Boolean_||, defn.Int_+, defn.Int_*, defn.Long_+, defn.Long_*) + + val maxFuel = ctx.settings.YoptFuel.value + if (fuel < 0 && maxFuel > 0) // Both defaults are at -1 + fuel = maxFuel + + optimisations = { + val o = if (ctx.erasedTypes) afterErasure else beforeErasure + val p = ctx.settings.YoptPhases.value + if (p.isEmpty) o else o.filter(x => p.contains(x.name)) + } } ctx From 686292a0bfe78eaf9cd6905a1f71db311478a8c8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 6 Apr 2018 12:07:16 +0200 Subject: [PATCH 2/3] Avoid computing set of value classes getClass methods --- .../src/dotty/tools/dotc/transform/InterceptedMethods.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala b/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala index 04f9b3fbce55..9f513086e9ee 100644 --- a/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala @@ -44,11 +44,11 @@ class InterceptedMethods extends MiniPhase { override def phaseName: String = InterceptedMethods.name - private[this] var primitiveGetClassMethods: Set[Symbol] = _ + private[this] var scalaValueClasses: scala.collection.Set[Symbol] = _ /** perform context-dependant initialization */ override def prepareForUnit(tree: Tree)(implicit ctx: Context) = { - primitiveGetClassMethods = Set[Symbol]() ++ defn.ScalaValueClasses().map(x => x.requiredMethod(nme.getClass_)) + scalaValueClasses = defn.ScalaValueClasses() ctx } @@ -105,7 +105,7 @@ class InterceptedMethods extends MiniPhase { List(qual, typer.resolveClassTag(tree.pos, qual.tpe.widen)))) }*/ */ - case t if primitiveGetClassMethods.contains(t) => + case t if t.name == nme.getClass_ && scalaValueClasses.contains(t.owner) => // if we got here then we're trying to send a primitive getClass method to either // a) an Any, in which cage Object_getClass works because Any erases to object. Or // From 39de3a58b6892ac5d51f17c070b6af2fe3961755 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 6 Apr 2018 17:52:06 +0200 Subject: [PATCH 3/3] Remove ScalaValueClasses cache --- .../tools/dotc/transform/InterceptedMethods.scala | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala b/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala index 9f513086e9ee..c01139e4dda7 100644 --- a/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala @@ -44,14 +44,6 @@ class InterceptedMethods extends MiniPhase { override def phaseName: String = InterceptedMethods.name - private[this] var scalaValueClasses: scala.collection.Set[Symbol] = _ - - /** perform context-dependant initialization */ - override def prepareForUnit(tree: Tree)(implicit ctx: Context) = { - scalaValueClasses = defn.ScalaValueClasses() - ctx - } - // this should be removed if we have guarantee that ## will get Apply node override def transformSelect(tree: tpd.Select)(implicit ctx: Context): Tree = { if (tree.symbol.isTerm && (defn.Any_## eq tree.symbol.asTerm)) { @@ -105,7 +97,7 @@ class InterceptedMethods extends MiniPhase { List(qual, typer.resolveClassTag(tree.pos, qual.tpe.widen)))) }*/ */ - case t if t.name == nme.getClass_ && scalaValueClasses.contains(t.owner) => + case t if t.name == nme.getClass_ && defn.ScalaValueClasses().contains(t.owner) => // if we got here then we're trying to send a primitive getClass method to either // a) an Any, in which cage Object_getClass works because Any erases to object. Or //