summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-07-27 01:38:45 -0700
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-07-27 14:09:41 -0700
commit115e8b4492851137ad2b5b61b9bf78bb51601dff (patch)
tree8305010d3e2c1270c00f98ee1a5ea1047b439607 /src
parent526f6c3934f31902fc3f5a0e690a472e86ecfc48 (diff)
downloadscala-115e8b4492851137ad2b5b61b9bf78bb51601dff.tar.gz
scala-115e8b4492851137ad2b5b61b9bf78bb51601dff.tar.bz2
scala-115e8b4492851137ad2b5b61b9bf78bb51601dff.zip
Fix Platform type in Global to be JavaPlatform.
At the moment we have just one Platform: JavaPlatform in the compiler. The whole Platform abstraction feels dubious and Java backends need to downcast to JavaPlatform to implement some optimizations. It seems like for now it's just better to fix platform declared in Global to be JavaPlatform and get rid of downcasting. I checked that even JavaScript backend declares itself as a subtype of JavaPlatform so it seems like our abstraction is not that useful. If we have an alternative platform with specific requirements we might want to refactor our Platform abstraction again but for now it seems dubious to pay a price for abstraction nobody uses.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala28
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala24
3 files changed, 14 insertions, 40 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 6417a54977..ceab0625f8 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -85,7 +85,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val settings: Settings = Global.this.settings
} with JavaPlatform
- type ThisPlatform = Platform { val symbolTable: Global.this.type }
+ type ThisPlatform = JavaPlatform { val global: Global.this.type }
lazy val platform: ThisPlatform = new GlobalPlatform
type PlatformClassPath = ClassPath[AbstractFile]
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 448ce9cb5b..410d451316 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -1479,30 +1479,18 @@ abstract class GenICode extends SubComponent {
if (mustUseAnyComparator) {
// when -optimise is on we call the @inline-version of equals, found in ScalaRunTime
- val equalsMethod: Symbol =
+ val equalsMethod: Symbol = {
if (!settings.optimise) {
- def default = platform.externalEquals
- platform match {
- // TODO: define `externalEqualsNumNum`, `externalEqualsNumChar` and `externalEqualsNumObject` in Platform
- // so we don't need special casing here
- case x: JavaPlatform =>
- // We need this cast because pattern matcher doesn't narrow type properly
- val javaPlatformRefined = x.asInstanceOf[JavaPlatform { val global: GenICode.this.global.type }]
- import javaPlatformRefined._
- if (l.tpe <:< BoxedNumberClass.tpe) {
- if (r.tpe <:< BoxedNumberClass.tpe) externalEqualsNumNum
- else if (r.tpe <:< BoxedCharacterClass.tpe) externalEqualsNumChar
- else externalEqualsNumObject
- }
- else default
-
- case _ => default
- }
- }
- else {
+ if (l.tpe <:< BoxedNumberClass.tpe) {
+ if (r.tpe <:< BoxedNumberClass.tpe) platform.externalEqualsNumNum
+ else if (r.tpe <:< BoxedCharacterClass.tpe) platform.externalEqualsNumChar
+ else platform.externalEqualsNumObject
+ } else platform.externalEquals
+ } else {
ctx.bb.emit(LOAD_MODULE(ScalaRunTimeModule))
getMember(ScalaRunTimeModule, nme.inlinedEquals)
}
+ }
val ctx1 = genLoad(l, ctx, ObjectReference)
val ctx2 = genLoad(r, ctx1, ObjectReference)
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
index 365aecf4a1..683f35e41f 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
@@ -1188,25 +1188,11 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
if (mustUseAnyComparator) {
val equalsMethod: Symbol = {
-
- def default: Symbol = platform.externalEquals
-
- platform match {
- // TODO: define `externalEqualsNumNum`, `externalEqualsNumChar` and `externalEqualsNumObject` in Platform
- // so we don't need special casing here
- case x: JavaPlatform =>
- // We need this cast because pattern matcher doesn't narrow type properly
- val javaPlatformRefined = x.asInstanceOf[JavaPlatform { val global: BCodeBodyBuilder.this.global.type }]
- import javaPlatformRefined._
- if (l.tpe <:< BoxedNumberClass.tpe) {
- if (r.tpe <:< BoxedNumberClass.tpe) externalEqualsNumNum
- else if (r.tpe <:< BoxedCharacterClass.tpe) externalEqualsNumChar
- else externalEqualsNumObject
- }
- else default
-
- case _ => default
- }
+ if (l.tpe <:< BoxedNumberClass.tpe) {
+ if (r.tpe <:< BoxedNumberClass.tpe) platform.externalEqualsNumNum
+ else if (r.tpe <:< BoxedCharacterClass.tpe) platform.externalEqualsNumChar
+ else platform.externalEqualsNumObject
+ } else platform.externalEquals
}
genLoad(l, ObjectReference)
genLoad(r, ObjectReference)