summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-05-08 22:57:25 +0200
committerJason Zaugg <jzaugg@gmail.com>2014-05-08 22:57:25 +0200
commit972244d7e3de18c833b179277912c737301b5437 (patch)
treedf6129f4f0844621876716fa6ac63132abbdd09c /src/compiler
parenta469cabc3eaf18a8a41cbcb1de4da6a7d459c861 (diff)
parent30610d53489478663a63a89ca09189e622024dc5 (diff)
downloadscala-972244d7e3de18c833b179277912c737301b5437.tar.gz
scala-972244d7e3de18c833b179277912c737301b5437.tar.bz2
scala-972244d7e3de18c833b179277912c737301b5437.zip
Merge pull request #3721 from lrytz/t7852
SI-7852 for GenBCode
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala15
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala18
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala25
4 files changed, 38 insertions, 22 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 1cea4bedda..0da66d43f7 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -13,13 +13,12 @@ import scala.collection.{ mutable, immutable }
import scala.collection.mutable.{ ListBuffer, Buffer }
import scala.tools.nsc.symtab._
import scala.annotation.switch
-import PartialFunction._
/**
* @author Iulian Dragos
* @version 1.0
*/
-abstract class GenICode extends SubComponent {
+abstract class GenICode extends SubComponent {
import global._
import icodes._
import icodes.opcodes._
@@ -30,6 +29,9 @@ abstract class GenICode extends SubComponent {
}
import platform.isMaybeBoxed
+ private val bCodeICodeCommon: jvm.BCodeICodeCommon[global.type] = new jvm.BCodeICodeCommon(global)
+ import bCodeICodeCommon._
+
val phaseName = "icode"
override def newPhase(prev: Phase) = new ICodePhase(prev)
@@ -1326,15 +1328,6 @@ abstract class GenICode extends SubComponent {
List(tree)
}
- /** Some useful equality helpers.
- */
- def isNull(t: Tree) = cond(t) { case Literal(Constant(null)) => true }
- def isLiteral(t: Tree) = cond(t) { case Literal(_) => true }
- def isNonNullExpr(t: Tree) = isLiteral(t) || ((t.symbol ne null) && t.symbol.isModule)
-
- /* If l or r is constant null, returns the other ; otherwise null */
- def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null
-
/**
* Find the label denoted by `lsym` and enter it in context `ctx`.
*
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
index 53142fbd87..92ebe5027a 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
@@ -23,6 +23,7 @@ import scala.tools.asm
abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
import global._
import definitions._
+ import bCodeICodeCommon._
/*
* Functionality to build the body of ASM MethodNode, except for `synchronized` and `try` expressions.
@@ -1020,17 +1021,6 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
tree :: Nil
}
- /* Some useful equality helpers. */
- def isNull(t: Tree) = {
- t match {
- case Literal(Constant(null)) => true
- case _ => false
- }
- }
-
- /* If l or r is constant null, returns the other ; otherwise null */
- def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null
-
/* Emit code to compare the two top-most stack values using the 'op' operator. */
private def genCJUMP(success: asm.Label, failure: asm.Label, op: TestOp, tk: BType) {
if (tk.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
@@ -1200,6 +1190,12 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
// expr == null -> expr eq null
genLoad(l, ObjectReference)
genCZJUMP(success, failure, icodes.EQ, ObjectReference)
+ } else if (isNonNullExpr(l)) {
+ // SI-7852 Avoid null check if L is statically non-null.
+ genLoad(l, ObjectReference)
+ genLoad(r, ObjectReference)
+ genCallMethod(Object_equals, icodes.opcodes.Dynamic)
+ genCZJUMP(success, failure, icodes.NE, BOOL)
} else {
// l == r -> if (l eq null) r eq null else l.equals(r)
val eqEqTempLocal = locals.makeLocal(AnyRefReference, nme.EQEQ_LOCAL_VAR.toString)
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala
index cc3265c5f9..aa7e73a36b 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeGlue.scala
@@ -22,6 +22,8 @@ abstract class BCodeGlue extends SubComponent {
import global._
+ protected val bCodeICodeCommon: BCodeICodeCommon[global.type] = new BCodeICodeCommon(global)
+
object BType {
import global.chrs
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala
new file mode 100644
index 0000000000..50d20921d5
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeICodeCommon.scala
@@ -0,0 +1,25 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2014 LAMP/EPFL
+ * @author Martin Odersky
+ */
+
+package scala.tools.nsc.backend.jvm
+
+import scala.tools.nsc.Global
+import PartialFunction._
+
+/**
+ * This trait contains code shared between GenBCode and GenICode that depends on types defined in
+ * the compiler cake (Global).
+ */
+final class BCodeICodeCommon[G <: Global](val global: G) {
+ import global._
+
+ /** Some useful equality helpers. */
+ def isNull(t: Tree) = cond(t) { case Literal(Constant(null)) => true }
+ def isLiteral(t: Tree) = cond(t) { case Literal(_) => true }
+ def isNonNullExpr(t: Tree) = isLiteral(t) || ((t.symbol ne null) && t.symbol.isModule)
+
+ /** If l or r is constant null, returns the other ; otherwise null */
+ def ifOneIsNull(l: Tree, r: Tree) = if (isNull(l)) r else if (isNull(r)) l else null
+}