Skip to content

Commit c75cbbd

Browse files
committed
Remove dead Android-related code from the JVM backend
1 parent be49502 commit c75cbbd

2 files changed

Lines changed: 1 addition & 144 deletions

File tree

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -591,70 +591,6 @@ trait BCodeHelpers(val bTypeLoader: BTypeLoader, val bTypes: WellKnownBTypes) ex
591591

592592
} // end of class JMirrorBuilder
593593

594-
trait JAndroidBuilder {
595-
/* From the reference documentation of the Android SDK:
596-
* The `Parcelable` interface identifies classes whose instances can be written to and restored from a `Parcel`.
597-
* Classes implementing the `Parcelable` interface must also have a static field called `CREATOR`,
598-
* which is an object implementing the `Parcelable.Creator` interface.
599-
*/
600-
val androidFieldName = "CREATOR".toTermName
601-
602-
lazy val AndroidParcelableInterface : Symbol = NoSymbol // getClassIfDefined("android.os.Parcelable")
603-
lazy val AndroidCreatorClass : Symbol = NoSymbol // getClassIfDefined("android.os.Parcelable$Creator")
604-
605-
/*
606-
* must-single-thread
607-
*/
608-
def isAndroidParcelableClass(sym: Symbol)(using Context) =
609-
(AndroidParcelableInterface != NoSymbol) &&
610-
(sym.info.parents.map(_.typeSymbol) contains AndroidParcelableInterface)
611-
612-
/*
613-
* must-single-thread
614-
*/
615-
def legacyAddCreatorCode(clinit: asm.MethodVisitor, cnode: asm.tree.ClassNode, thisName: String)(using Context): Unit = {
616-
val androidCreatorType = null.asInstanceOf[ClassBType] // would hit an assert error if it ever ran because AndroidCreatorClass is NoSymbol: bTypeLoader.getClassBType(AndroidCreatorClass)
617-
val tdesc_creator = androidCreatorType.descriptor
618-
619-
cnode.visitField(
620-
asm.Opcodes.ACC_PUBLIC | asm.Opcodes.ACC_STATIC | asm.Opcodes.ACC_FINAL,
621-
"CREATOR",
622-
tdesc_creator,
623-
null, // no java-generic-signature
624-
null // no initial value
625-
).visitEnd()
626-
627-
val moduleName = thisName + "$"
628-
629-
// GETSTATIC `moduleName`.MODULE$ : `moduleName`;
630-
clinit.visitFieldInsn(
631-
asm.Opcodes.GETSTATIC,
632-
moduleName,
633-
str.MODULE_INSTANCE_FIELD,
634-
"L" + moduleName + ";"
635-
)
636-
637-
// INVOKEVIRTUAL `moduleName`.CREATOR() : android.os.Parcelable$Creator;
638-
val bt = MethodBType(Nil, androidCreatorType)
639-
clinit.visitMethodInsn(
640-
asm.Opcodes.INVOKEVIRTUAL,
641-
moduleName,
642-
"CREATOR",
643-
bt.descriptor,
644-
false
645-
)
646-
647-
// PUTSTATIC `thisName`.CREATOR;
648-
clinit.visitFieldInsn(
649-
asm.Opcodes.PUTSTATIC,
650-
thisName,
651-
"CREATOR",
652-
tdesc_creator
653-
)
654-
}
655-
656-
} // end of trait JAndroidBuilder
657-
658594
private def getGenericSignatureHelper(sym: Symbol, owner: Symbol, memberTpe: Type)(using Context): Option[String] = {
659595
if (needsGenericSignature(sym)) {
660596
val erasedTypeSym = TypeErasure.fullErasure(sym.denot.info).typeSymbol

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ trait BCodeSkelBuilder extends BCodeHelpers {
127127
abstract class PlainSkelBuilder
128128
extends BCClassGen
129129
with BCAnnotGen
130-
with JAndroidBuilder
131130
with BCForwardersGen
132131
with BCPickles
133132
with BCJGenSigGen {
@@ -140,7 +139,6 @@ trait BCodeSkelBuilder extends BCodeHelpers {
140139
var thisName: String = null // the internal name of the class being emitted
141140

142141
var claszSymbol: Symbol = null
143-
var isCZParcelable = false
144142
var isCZStaticModule = false
145143

146144
// keep track of interfaces that are used in super calls, as they need to be directly inherited even if they are also indirectly inherited
@@ -167,7 +165,6 @@ trait BCodeSkelBuilder extends BCodeHelpers {
167165
assert(cnode == null, "GenBCode detected nested methods.")
168166

169167
claszSymbol = cd0.symbol
170-
isCZParcelable = isAndroidParcelableClass(claszSymbol)
171168
isCZStaticModule = claszSymbol.isStaticModuleClass
172169
thisName = bTypeLoader.classBTypeFromSymbol(claszSymbol).internalName
173170

@@ -267,7 +264,6 @@ trait BCodeSkelBuilder extends BCodeHelpers {
267264
} else cd0
268265

269266
val hasStaticCtor = isCZStaticModule || cd.symbol.info.decls.exists(_.name.isStaticConstructorName)
270-
if (!hasStaticCtor && isCZParcelable) fabricateStaticInitAndroid()
271267

272268
val optSerial: Option[Long] =
273269
claszSymbol.getAnnotation(defn.SerialVersionUIDAnnot).flatMap { annot =>
@@ -360,7 +356,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
360356
cnode.visitAttribute(if (ssa.isDefined) pickleMarkerLocal else pickleMarkerForeign)
361357
emitAnnotations(cnode, claszSymbol.annotations ++ ssa)
362358

363-
if (!isCZStaticModule && !isCZParcelable) {
359+
if (!isCZStaticModule) {
364360
val skipStaticForwarders = (claszSymbol.is(Module) || ctx.settings.XnoForwarders.value)
365361
if (!skipStaticForwarders) {
366362
val lmoc = claszSymbol.companionModule
@@ -381,27 +377,6 @@ trait BCodeSkelBuilder extends BCodeHelpers {
381377

382378
} // end of method initJClass
383379

384-
/*
385-
* must-single-thread
386-
*/
387-
private def fabricateStaticInitAndroid()(using Context): Unit = {
388-
389-
val clinit: asm.MethodVisitor = cnode.visitMethod(
390-
asm.Opcodes.ACC_PUBLIC | asm.Opcodes.ACC_STATIC, // TODO confirm whether we really don't want ACC_SYNTHETIC nor ACC_DEPRECATED
391-
CLASS_CONSTRUCTOR_NAME,
392-
"()V",
393-
null, // no java-generic-signature
394-
null // no throwable exceptions
395-
)
396-
clinit.visitCode()
397-
398-
legacyAddCreatorCode(clinit, cnode, thisName)
399-
400-
clinit.visitInsn(asm.Opcodes.RETURN)
401-
clinit.visitMaxs(0, 0) // just to follow protocol, dummy arguments
402-
clinit.visitEnd()
403-
}
404-
405380
private def javaFieldFlags(sym: Symbol)(using Context) = {
406381
import asm.Opcodes.*
407382
import GenBCodeOps.addFlagIf
@@ -937,8 +912,6 @@ trait BCodeSkelBuilder extends BCodeHelpers {
937912
}
938913
for (p <- params) { emitLocalVarScope(p.symbol, veryFirstProgramPoint, onePastLastProgramPoint, force = true) }
939914
}
940-
941-
if (isMethSymStaticCtor) { appendToStaticCtor() }
942915
} // end of emitNormalMethodBody()
943916

944917
lineNumber(rhs)
@@ -953,58 +926,6 @@ trait BCodeSkelBuilder extends BCodeHelpers {
953926
mnode = null
954927
} // end of method genDefDef()
955928

956-
/*
957-
* must-single-thread
958-
*
959-
* TODO document, explain interplay with `fabricateStaticInitAndroid()`
960-
*/
961-
private def appendToStaticCtor()(using Context): Unit = {
962-
963-
def insertBefore(
964-
location: asm.tree.AbstractInsnNode,
965-
i0: asm.tree.AbstractInsnNode,
966-
i1: asm.tree.AbstractInsnNode): Unit = {
967-
if (i0 != null) {
968-
mnode.instructions.insertBefore(location, i0.clone(null))
969-
mnode.instructions.insertBefore(location, i1.clone(null))
970-
}
971-
}
972-
973-
// collect all return instructions
974-
var rets: List[asm.tree.AbstractInsnNode] = Nil
975-
mnode foreachInsn { i => if (i.getOpcode() == asm.Opcodes.RETURN) { rets ::= i } }
976-
if (rets.isEmpty) { return }
977-
978-
var insnParcA: asm.tree.AbstractInsnNode = null
979-
var insnParcB: asm.tree.AbstractInsnNode = null
980-
// android creator code
981-
if (isCZParcelable) {
982-
// add a static field ("CREATOR") to this class to cache android.os.Parcelable$Creator
983-
val andrFieldDescr = bTypeLoader.classBTypeFromSymbol(AndroidCreatorClass).descriptor
984-
cnode.visitField(
985-
asm.Opcodes.ACC_STATIC | asm.Opcodes.ACC_FINAL,
986-
"CREATOR",
987-
andrFieldDescr,
988-
null,
989-
null
990-
)
991-
// INVOKESTATIC CREATOR(): android.os.Parcelable$Creator; -- TODO where does this Android method come from?
992-
val callee = claszSymbol.companionModule.info.member(androidFieldName).symbol
993-
val jowner = bTypeLoader.classBTypeFromSymbol(callee.owner).internalName
994-
val jname = callee.javaSimpleName
995-
val jtype = bTypeLoader.methodBTypeFromSymbol(callee).descriptor
996-
insnParcA = new asm.tree.MethodInsnNode(asm.Opcodes.INVOKESTATIC, jowner, jname, jtype, false)
997-
// PUTSTATIC `thisName`.CREATOR;
998-
insnParcB = new asm.tree.FieldInsnNode(asm.Opcodes.PUTSTATIC, thisName, "CREATOR", andrFieldDescr)
999-
}
1000-
1001-
// insert a few instructions for initialization before each return instruction
1002-
for(r <- rets) {
1003-
insertBefore(r, insnParcA, insnParcB)
1004-
}
1005-
1006-
}
1007-
1008929
def emitLocalVarScope(sym: Symbol, start: asm.Label, end: asm.Label, force: Boolean = false): Unit = {
1009930
val Local(tk, name, idx, isSynth) = locals(sym)
1010931
if (force || !isSynth) {

0 commit comments

Comments
 (0)