aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Inliner.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-02 13:39:48 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-02 16:11:21 +0200
commit729815bec8035f2d6132fde0eb928e877dd21a64 (patch)
tree27b8efddae77f9d3a9e28ddd1dea72186096ff66 /src/dotty/tools/dotc/typer/Inliner.scala
parent617be516b261524c2f0762de10f2bde376043ad7 (diff)
downloaddotty-729815bec8035f2d6132fde0eb928e877dd21a64.tar.gz
dotty-729815bec8035f2d6132fde0eb928e877dd21a64.tar.bz2
dotty-729815bec8035f2d6132fde0eb928e877dd21a64.zip
Implement inline if
Inline conditionals with constant conditions
Diffstat (limited to 'src/dotty/tools/dotc/typer/Inliner.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Inliner.scala13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/Inliner.scala b/src/dotty/tools/dotc/typer/Inliner.scala
index 8d25e3250..8d9b5bf30 100644
--- a/src/dotty/tools/dotc/typer/Inliner.scala
+++ b/src/dotty/tools/dotc/typer/Inliner.scala
@@ -10,6 +10,7 @@ import Flags._
import Symbols._
import Types._
import Decorators._
+import Constants._
import StdNames.nme
import Contexts.Context
import Names.Name
@@ -56,6 +57,18 @@ object Inliner {
case res => res
}
}
+ override def typedIf(tree: untpd.If, pt: Type)(implicit ctx: Context) = {
+ val cond1 = typed(tree.cond, defn.BooleanType)
+ cond1.tpe.widenTermRefExpr match {
+ case ConstantType(Constant(condVal: Boolean)) =>
+ val selected = typed(if (condVal) tree.thenp else tree.elsep, pt)
+ if (isIdempotentExpr(cond1)) selected
+ else Block(cond1 :: Nil, selected)
+ case _ =>
+ val if1 = untpd.cpy.If(tree)(cond = untpd.TypedSplice(cond1))
+ super.typedIf(if1, pt)
+ }
+ }
}
def inlineCall(tree: Tree, pt: Type)(implicit ctx: Context): Tree = {