Skip to content

Commit 5a686ea

Browse files
madsagerudalov
authored andcommitted
[JVM_IR] Reduce the amount of super suffixes on accesibility bridges.
The super suffix was used for any static field/method that needed an accessor. We should only use it when that field or method is inherited. (cherry picked from commit ef36b81)
1 parent ddc6238 commit 5a686ea

File tree

8 files changed

+60
-10
lines changed

8 files changed

+60
-10
lines changed

compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,10 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
531531
// Accessor for _s_uper-qualified call
532532
superQualifier != null -> "\$s" + superQualifier.owner.syntheticAccessorToSuperSuffix()
533533

534-
// Access to static members that need an accessor must be because they are inherited,
535-
// hence accessed on a _s_upertype.
536-
isStatic -> "\$s" + parentAsClass.syntheticAccessorToSuperSuffix()
534+
// Access to protected members that need an accessor must be because they are inherited,
535+
// hence accessed on a _s_upertype. If what is accessed is static, we can point to different
536+
// parts of the inheritance hierarchy and need to distinguish with a suffix.
537+
isStatic && visibility.isProtected -> "\$s" + parentAsClass.syntheticAccessorToSuperSuffix()
537538

538539
else -> ""
539540
}
@@ -556,9 +557,10 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
556557
return "cp"
557558
}
558559

559-
// Static accesses that need an accessor must be due to being inherited, hence accessed on a
560-
// _s_upertype
561-
return "p" + if (isStatic) "\$s" + parentAsClass.syntheticAccessorToSuperSuffix() else ""
560+
// Accesses to static protected fields that need an accessor must be due to being inherited, hence accessed on a
561+
// _s_upertype. If the field is static, the super class the access is on can be different and therefore
562+
// we generate a suffix to distinguish access to field with different receiver types in the super hierarchy.
563+
return "p" + if (isStatic && visibility.isProtected) "\$s" + parentAsClass.syntheticAccessorToSuperSuffix() else ""
562564
}
563565

564566
private val DescriptorVisibility.isPrivate
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
private val x: String = "OK"
2+
private fun f(y: String) = y
3+
4+
class A {
5+
fun g() = f(x)
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@kotlin.Metadata
2+
public final class A {
3+
// source: 'accessorForTopLevelMembers.kt'
4+
public method <init>(): void
5+
public final @org.jetbrains.annotations.NotNull method g(): java.lang.String
6+
}
7+
8+
@kotlin.Metadata
9+
public final class AccessorForTopLevelMembersKt {
10+
// source: 'accessorForTopLevelMembers.kt'
11+
private final static field x: java.lang.String
12+
static method <clinit>(): void
13+
public synthetic final static method access$f(p0: java.lang.String): java.lang.String
14+
public synthetic final static method access$getX$p(): java.lang.String
15+
private final static method f(p0: java.lang.String): java.lang.String
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@kotlin.Metadata
2+
public final class A {
3+
// source: 'accessorForTopLevelMembers.kt'
4+
public method <init>(): void
5+
public final @org.jetbrains.annotations.NotNull method g(): java.lang.String
6+
}
7+
8+
@kotlin.Metadata
9+
public final class AccessorForTopLevelMembersKt {
10+
// source: 'accessorForTopLevelMembers.kt'
11+
private final static @org.jetbrains.annotations.NotNull field x: java.lang.String
12+
static method <clinit>(): void
13+
public synthetic final static method access$f(p0: java.lang.String): java.lang.String
14+
public synthetic final static method access$getX$p(): java.lang.String
15+
private final static method f(p0: java.lang.String): java.lang.String
16+
}

compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/parcelize/parcelize-compiler/testData/codegen/customSimple.ir.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class User$Creator : java/lang/Object, android/os/Parcelable$Creato
4141
ALOAD (1)
4242
LDC (parcel)
4343
INVOKESTATIC (kotlin/jvm/internal/Intrinsics, checkNotNullParameter, (Ljava/lang/Object;Ljava/lang/String;)V)
44-
INVOKESTATIC (User, access$getCompanion$p$s2645995, ()LUser$Companion;)
44+
INVOKESTATIC (User, access$getCompanion$p, ()LUser$Companion;)
4545
ALOAD (1)
4646
INVOKEVIRTUAL (User$Companion, create, (Landroid/os/Parcel;)LUser;)
4747
ARETURN
@@ -90,7 +90,7 @@ public final class User : java/lang/Object, android/os/Parcelable {
9090

9191
public void <init>(java.lang.String firstName, java.lang.String lastName, int age)
9292

93-
public final static User$Companion access$getCompanion$p$s2645995()
93+
public final static User$Companion access$getCompanion$p()
9494

9595
public int describeContents()
9696

plugins/parcelize/parcelize-compiler/testData/codegen/customSimpleWithNewArray.ir.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class User$Creator : java/lang/Object, android/os/Parcelable$Creato
4040

4141
public final User[] newArray(int size) {
4242
LABEL (L0)
43-
INVOKESTATIC (User, access$getCompanion$p$s2645995, ()LUser$Companion;)
43+
INVOKESTATIC (User, access$getCompanion$p, ()LUser$Companion;)
4444
ILOAD (1)
4545
INVOKEVIRTUAL (User$Companion, newArray, (I)[LUser;)
4646
ARETURN
@@ -72,7 +72,7 @@ public final class User : java/lang/Object, android/os/Parcelable {
7272

7373
public void <init>(java.lang.String firstName, java.lang.String lastName, int age)
7474

75-
public final static User$Companion access$getCompanion$p$s2645995()
75+
public final static User$Companion access$getCompanion$p()
7676

7777
public int describeContents()
7878

0 commit comments

Comments
 (0)