Skip to content

Commit 115e8b4

Browse files
committed
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.
1 parent 526f6c3 commit 115e8b4

File tree

3 files changed

+14
-40
lines changed

3 files changed

+14
-40
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
8585
val settings: Settings = Global.this.settings
8686
} with JavaPlatform
8787

88-
type ThisPlatform = Platform { val symbolTable: Global.this.type }
88+
type ThisPlatform = JavaPlatform { val global: Global.this.type }
8989
lazy val platform: ThisPlatform = new GlobalPlatform
9090

9191
type PlatformClassPath = ClassPath[AbstractFile]

src/compiler/scala/tools/nsc/backend/icode/GenICode.scala

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,30 +1479,18 @@ abstract class GenICode extends SubComponent {
14791479

14801480
if (mustUseAnyComparator) {
14811481
// when -optimise is on we call the @inline-version of equals, found in ScalaRunTime
1482-
val equalsMethod: Symbol =
1482+
val equalsMethod: Symbol = {
14831483
if (!settings.optimise) {
1484-
def default = platform.externalEquals
1485-
platform match {
1486-
// TODO: define `externalEqualsNumNum`, `externalEqualsNumChar` and `externalEqualsNumObject` in Platform
1487-
// so we don't need special casing here
1488-
case x: JavaPlatform =>
1489-
// We need this cast because pattern matcher doesn't narrow type properly
1490-
val javaPlatformRefined = x.asInstanceOf[JavaPlatform { val global: GenICode.this.global.type }]
1491-
import javaPlatformRefined._
1492-
if (l.tpe <:< BoxedNumberClass.tpe) {
1493-
if (r.tpe <:< BoxedNumberClass.tpe) externalEqualsNumNum
1494-
else if (r.tpe <:< BoxedCharacterClass.tpe) externalEqualsNumChar
1495-
else externalEqualsNumObject
1496-
}
1497-
else default
1498-
1499-
case _ => default
1500-
}
1501-
}
1502-
else {
1484+
if (l.tpe <:< BoxedNumberClass.tpe) {
1485+
if (r.tpe <:< BoxedNumberClass.tpe) platform.externalEqualsNumNum
1486+
else if (r.tpe <:< BoxedCharacterClass.tpe) platform.externalEqualsNumChar
1487+
else platform.externalEqualsNumObject
1488+
} else platform.externalEquals
1489+
} else {
15031490
ctx.bb.emit(LOAD_MODULE(ScalaRunTimeModule))
15041491
getMember(ScalaRunTimeModule, nme.inlinedEquals)
15051492
}
1493+
}
15061494

15071495
val ctx1 = genLoad(l, ctx, ObjectReference)
15081496
val ctx2 = genLoad(r, ctx1, ObjectReference)

src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,25 +1188,11 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
11881188

11891189
if (mustUseAnyComparator) {
11901190
val equalsMethod: Symbol = {
1191-
1192-
def default: Symbol = platform.externalEquals
1193-
1194-
platform match {
1195-
// TODO: define `externalEqualsNumNum`, `externalEqualsNumChar` and `externalEqualsNumObject` in Platform
1196-
// so we don't need special casing here
1197-
case x: JavaPlatform =>
1198-
// We need this cast because pattern matcher doesn't narrow type properly
1199-
val javaPlatformRefined = x.asInstanceOf[JavaPlatform { val global: BCodeBodyBuilder.this.global.type }]
1200-
import javaPlatformRefined._
1201-
if (l.tpe <:< BoxedNumberClass.tpe) {
1202-
if (r.tpe <:< BoxedNumberClass.tpe) externalEqualsNumNum
1203-
else if (r.tpe <:< BoxedCharacterClass.tpe) externalEqualsNumChar
1204-
else externalEqualsNumObject
1205-
}
1206-
else default
1207-
1208-
case _ => default
1209-
}
1191+
if (l.tpe <:< BoxedNumberClass.tpe) {
1192+
if (r.tpe <:< BoxedNumberClass.tpe) platform.externalEqualsNumNum
1193+
else if (r.tpe <:< BoxedCharacterClass.tpe) platform.externalEqualsNumChar
1194+
else platform.externalEqualsNumObject
1195+
} else platform.externalEquals
12101196
}
12111197
genLoad(l, ObjectReference)
12121198
genLoad(r, ObjectReference)

0 commit comments

Comments
 (0)