Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local optimisations #2513

Merged
merged 88 commits into from
May 30, 2017
Merged
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
098036a
Simplify: initial structure and first optimizations
DarkDimius Aug 29, 2016
968f478
Simplify: add inlineOptions fixes to inlineCaseIntrinsics
DarkDimius Aug 29, 2016
e592460
Simplify: implement constant folding.
DarkDimius Jun 27, 2016
fa75463
Simplify: do not generate blocks with empty stats.
DarkDimius Jun 27, 2016
fc9c60d
Simplify: devalify now also performs constant propagation
DarkDimius Jun 27, 2016
ff0a888
Simplify: fix bug in bubbleUpNothing. Definitions should not be skipped.
DarkDimius Jun 27, 2016
0e6de0a
Simplify: improve constant folding & leave breadcrumbs for contributors
DarkDimius Jun 28, 2016
e024e86
Add PatternFactorization
DarkDimius Aug 29, 2016
b44e796
Simplify: fix owner corruption when inlining LabelDefs.
DarkDimius Aug 30, 2016
a1c1f7f
Simplify: Start getting rid from Scala2 options and tupples in patterns
DarkDimius Aug 30, 2016
5974a80
Simplify: Don't alias lazy vals
DarkDimius Aug 30, 2016
626488a
Simplify: Don't create empty DefDefs if they should do nothing.
DarkDimius Aug 30, 2016
f66ac7f
Simplify: Fix bug with elimination of side-effects.
DarkDimius Aug 30, 2016
9cdc557
Simplify: Don't partials-evaluate case-defs.
DarkDimius Aug 30, 2016
f521d86
Simplify: make object inlining robust against Nothing.
DarkDimius Aug 30, 2016
e111da9
Simplify: Fix several infinite cycles.
DarkDimius Aug 30, 2016
c3f518a
Simplify: Don't drop lazy val reads.
DarkDimius Aug 31, 2016
315728d
Simplify: jump jump: optimise label-defs that are themselves forwarders
DarkDimius Aug 31, 2016
a9930f4
Simplify: start joining ifs if branches are similar.
DarkDimius Aug 31, 2016
e4d36ea
Simplify: String+ isn't symmetric
DarkDimius Aug 31, 2016
cc1b78f
Simplify: fix a bug inside isSimilar
DarkDimius Aug 31, 2016
05c2afd
Simplify: don't remove by-name calls
DarkDimius Aug 31, 2016
9d288e1
Simplify: don't remove infinite cycles :-)
DarkDimius Aug 31, 2016
5e70a0b
Got tired of fixing Pattern*Factorization.
DarkDimius Aug 31, 2016
d16ad9a
simplify: Reading vals through successful casts should be allowed
DarkDimius Sep 2, 2016
b236b04
simplify: Playing with optimising if expressions.
DarkDimius Sep 2, 2016
dc75bd4
simplify: fixes to inlineLocalObjects.
DarkDimius Sep 2, 2016
aa854ec
Simplify: add vilify transformation
DarkDimius Sep 2, 2016
ae35fb7
Simplify: add dropGoodCasts that drops good casts in stat position.
DarkDimius Sep 2, 2016
646f11a
Simplify: fix the fix of handling by-name arguments.
DarkDimius Sep 2, 2016
a1ad54c
Simplify: dropNoEffects now flattens blocks.
DarkDimius Sep 2, 2016
c6f0e8d
Simplify: inline case-defs that have literal in rhs.
DarkDimius Sep 2, 2016
05a5382
Simplify: Somes\options can be null :-(
DarkDimius Sep 2, 2016
e93dd61
Make optimisation optional.
DarkDimius Sep 6, 2016
ae9a562
Simplify:inlineLocalObjects: don't inline mutable fields.
DarkDimius Sep 6, 2016
14bc530
Simplify: DropGoodCasts: Don't accumulate cast on garbage.
DarkDimius Sep 6, 2016
a8c9e94
Simplify: devalify: correctly rebase New when prefix changes.
DarkDimius Sep 6, 2016
6536d8f
Simplify:inlineLocalObjects: make more robust against complex labels.
DarkDimius Sep 6, 2016
2b3d0d2
Simplify: NullCheck: as proposed by @jvican
DarkDimius Sep 6, 2016
8fb9554
Simplify: fix and enable removeUnnecessaryNullChecks.
DarkDimius Sep 6, 2016
9314e91
Add missing NamedType import
jvican Sep 7, 2016
02be44b
Simplify: devalify: don't kick in on by-name params
jvican Sep 7, 2016
1b6074c
Simplify: fix infinite recursion in followCases
DarkDimius Sep 20, 2016
d25a221
Simplify: remove duplicate null tests.
DarkDimius Sep 20, 2016
f79f06f
Simplify: this can be dropped inside a block.
DarkDimius Sep 20, 2016
6cc53c7
Finish rebase over dotty upstream
DarkDimius Mar 1, 2017
232761c
Document Simplify optimizations
OlivierBlanvillain Mar 2, 2017
76af6c5
Fix Erasure of uniqueRefDenotations with different underlying type.
DarkDimius Apr 11, 2017
aaca2b1
Rewrite labelDefs phase
DarkDimius Apr 26, 2017
b7596ef
Soften Ycheck scoping rules for local jumps after LabelDefs
DarkDimius Apr 27, 2017
a5b688d
Fix compilation after rebase
OlivierBlanvillain Apr 28, 2017
4ea9a84
Restore tests moved to disabled
OlivierBlanvillain Apr 28, 2017
8f470f0
Remove PatternConstantsFactorization & PatternTypeFactorization for now
OlivierBlanvillain Apr 28, 2017
b4af143
Run all tests with -optimise
OlivierBlanvillain Apr 28, 2017
f775345
Formating / refactoring
OlivierBlanvillain Apr 28, 2017
c42a944
Remove usage of -optimise in ClassfileParser
OlivierBlanvillain Apr 28, 2017
ef2d967
Fix a few bugs in Simplify
OlivierBlanvillain Apr 28, 2017
d255b32
Expose tpd problem, temporary .toString hack
OlivierBlanvillain Apr 28, 2017
4763a36
Work in progress
OlivierBlanvillain May 11, 2017
2f22230
Add missing `.ensureApplied` in `constantFold`
OlivierBlanvillain May 11, 2017
cad5515
bubbleUpNothing: do we want it? It breaks the last 4 failing tests
OlivierBlanvillain May 11, 2017
520e347
Kinda fix toString hack: testPicking w/o -optimise + tpd swtich
OlivierBlanvillain May 11, 2017
ecaa6e9
Reimplement TypeErasure#erasedLub with the documented algorithm
OlivierBlanvillain May 22, 2017
3d4cdd7
Clean up Simplify
OlivierBlanvillain May 22, 2017
a2bead9
Partially fix pickling tests failing with smarter tpd
OlivierBlanvillain May 22, 2017
dec2766
Add byte code SimplifyTests
OlivierBlanvillain May 22, 2017
a2465b1
Refactor the temporary tpd fix
OlivierBlanvillain May 22, 2017
bb0e5b2
Import Flags._
OlivierBlanvillain May 22, 2017
92ffff7
Add null check and evalOnce to inlineCaseIntrinsics
OlivierBlanvillain May 22, 2017
0e8cbae
Don't run problematic optimisations AfterErasure
OlivierBlanvillain May 22, 2017
c516fb3
Move to pending t7126.scala (could also be run without -optimise)
OlivierBlanvillain May 22, 2017
123a02d
Isolate the two failing tests in run-not-optimised
OlivierBlanvillain May 22, 2017
e92c40f
Fix ShallowFolder
OlivierBlanvillain May 23, 2017
8a51d32
Do not inline val across class boundaries
OlivierBlanvillain May 23, 2017
f564340
Minor reformatting
OlivierBlanvillain May 23, 2017
3cc3121
Add time travelling copies
odersky May 26, 2017
8a66a25
Simplify: do not drop complex prefixes to case-class apply & unapply.
DarkDimius May 29, 2017
65265e6
Simplify: fix build
DarkDimius May 29, 2017
7740db5
tpd: handle closures with less copying + use sameTypes
DarkDimius May 26, 2017
4d54f3d
Allow redefining tree-copier per phase.
DarkDimius May 29, 2017
ea7a578
Simplify: use a better tree copier.
DarkDimius May 29, 2017
d09dbd6
Fix SimplifyTests
OlivierBlanvillain May 29, 2017
8220305
Simplify: drop more stuff in dropNoEffects.
DarkDimius May 29, 2017
9c68552
Simplify: run devalify before erasure.
DarkDimius May 29, 2017
ce50cfe
Refactoring and comments
OlivierBlanvillain May 29, 2017
de4dd2c
Fix t4859
OlivierBlanvillain May 30, 2017
fba0d51
Devalify: also visitType for New nodes
OlivierBlanvillain May 30, 2017
b7149c9
Simpler class hiararchy in SimplifyTests to please JUnit
OlivierBlanvillain May 30, 2017
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
25 changes: 14 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/linker/Simplify.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
private var symmetricOperations: Set[Symbol] = null
var optimize = false


override val cpy = tpd.cpy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need both this val and an explicitly tpd.cpy everywhere?


override def prepareForUnit(tree: Tree)(implicit ctx: Context): TreeTransform = {
SeqFactoryClass = ctx.requiredClass("scala.collection.generic.SeqFactory")
symmetricOperations = Set(defn.Boolean_&&, defn.Boolean_||, defn.Int_+, defn.Int_*, defn.Long_+, defn.Long_*)
Expand Down Expand Up @@ -118,7 +121,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
transformers = transformers.tail
}
}
if (rhs0 ne tree.rhs) cpy.DefDef(tree)(rhs = rhs0)
if (rhs0 ne tree.rhs) tpd.cpy.DefDef(tree)(rhs = rhs0)
else tree
} else tree
}
Expand Down Expand Up @@ -539,8 +542,8 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {

def splitWrites(t: Tree, target: Symbol): Tree = {
t match {
case tree@ Block(stats, expr) => cpy.Block(tree)(stats, splitWrites(expr, target))
case tree@ If(_, thenp, elsep) => cpy.If(tree)(thenp = splitWrites(thenp, target), elsep = splitWrites(elsep, target))
case tree@ Block(stats, expr) => tpd.cpy.Block(tree)(stats, splitWrites(expr, target))
case tree@ If(_, thenp, elsep) => tpd.cpy.If(tree)(thenp = splitWrites(thenp, target), elsep = splitWrites(elsep, target))
case Apply(sel , args) if sel.symbol.isConstructor && t.tpe.widenDealias == target.info.widenDealias.finalResultType.widenDealias =>
val fieldsByAccessors = newMappings(target)
var accessors = target.info.classSymbol.caseAccessors.filter(_.isGetter) // TODO: when is this filter needed?
Expand Down Expand Up @@ -588,7 +591,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
case ddef: DefDef if ddef.symbol.is(Label) =>
newMappings.get(followCases(ddef.symbol)) match {
case Some(mappings) =>
cpy.DefDef(ddef)(rhs = splitWrites(ddef.rhs, followCases(ddef.symbol)))
tpd.cpy.DefDef(ddef)(rhs = splitWrites(ddef.rhs, followCases(ddef.symbol)))
case _ => ddef
}
case a: ValDef if toSplit.contains(a.symbol) =>
Expand All @@ -597,7 +600,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
val newFields = newMappings(a.symbol).values.toSet
Thicket(
newFields.map(x => ValDef(x.asTerm, defaultValue(x.symbol.info.widenDealias))).toList :::
List(cpy.ValDef(a)(rhs = splitWrites(a.rhs, a.symbol))))
List(tpd.cpy.ValDef(a)(rhs = splitWrites(a.rhs, a.symbol))))
case ass: Assign =>
newMappings.get(ass.lhs.symbol) match {
case None => ass
Expand Down Expand Up @@ -685,7 +688,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
}
val nthenp = dropGoodCastsInStats.transform(thenp)

cpy.If(t)(thenp = nthenp, elsep = elsep)
tpd.cpy.If(t)(thenp = nthenp, elsep = elsep)
case t => t
}
("dropGoodCasts", BeforeAndAfterErasure, NoVisitor, transformer)
Expand Down Expand Up @@ -824,7 +827,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
val nthenp = keepOnlySideEffects(thenp)
val nelsep = keepOnlySideEffects(elsep)
if (thenp.isEmpty && elsep.isEmpty) keepOnlySideEffects(cond)
else cpy.If(t)(
else tpd.cpy.If(t)(
thenp = nthenp.orElse(if (thenp.isInstanceOf[Literal]) thenp else unitLiteral),
elsep = nelsep.orElse(if (elsep.isInstanceOf[Literal]) elsep else unitLiteral))
case Select(rec, _) if
Expand All @@ -845,7 +848,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
case t: Literal if t.tpe.derivesFrom(defn.UnitClass) => expr
case _ => keepOnlySideEffects(expr).orElse(unitLiteral)
}
cpy.Block(bl)(stats2, expr2)
tpd.cpy.Block(bl)(stats2, expr2)
case t: Ident if !t.symbol.is(Method | Lazy) && !t.symbol.info.isInstanceOf[ExprType] =>
desugarIdent(t) match {
case Some(t) => t
Expand Down Expand Up @@ -914,7 +917,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
case _ => (newStats1, a.expr)
}
if (newStats2.nonEmpty)
cpy.Block(a)(stats = newStats2, newExpr)
tpd.cpy.Block(a)(stats = newStats2, newExpr)
else newExpr
case a: DefDef =>
if (a.symbol.info.finalResultType.derivesFrom(defn.UnitClass) &&
Expand All @@ -924,7 +927,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
if (!t.tpe.derivesFrom(defn.UnitClass)) Block(t :: Nil, unitLiteral)
else t
}
cpy.DefDef(a)(rhs = insertUnit(keepOnlySideEffects(a.rhs)), tpt = TypeTree(defn.UnitType))
tpd.cpy.DefDef(a)(rhs = insertUnit(keepOnlySideEffects(a.rhs)), tpt = TypeTree(defn.UnitType))
} else a
case t => t
}
Expand Down Expand Up @@ -1120,7 +1123,7 @@ class Simplify extends MiniPhaseTransform with IdentityDenotTransformer {
}

if (newStats eq t.stats) t
else cpy.Block(t)(newStats, t.expr)
else tpd.cpy.Block(t)(newStats, t.expr)
case tree => tree
}

Expand Down