From 115e8b4492851137ad2b5b61b9bf78bb51601dff Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Sat, 27 Jul 2013 01:38:45 -0700 Subject: 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. --- src/compiler/scala/tools/nsc/Global.scala | 2 +- .../scala/tools/nsc/backend/icode/GenICode.scala | 28 +++++++--------------- .../tools/nsc/backend/jvm/BCodeBodyBuilder.scala | 24 ++++--------------- 3 files changed, 14 insertions(+), 40 deletions(-) (limited to 'src') 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) -- cgit v1.2.3