jvm-abi-gen: Remove WhenMapping classes from ABI if possible
This commit is contained in:
committed by
Alexander Udalov
parent
ec4d7b2bb6
commit
19660f11a7
+5
-1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.codegen.ClassBuilder
|
|||||||
import org.jetbrains.kotlin.codegen.ClassBuilderFactory
|
import org.jetbrains.kotlin.codegen.ClassBuilderFactory
|
||||||
import org.jetbrains.kotlin.codegen.DelegatingClassBuilder
|
import org.jetbrains.kotlin.codegen.DelegatingClassBuilder
|
||||||
import org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory
|
import org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory
|
||||||
|
import org.jetbrains.kotlin.codegen.`when`.WhenByEnumsMapping
|
||||||
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
|
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
|
||||||
import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
|
import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
@@ -156,7 +157,7 @@ class JvmAbiClassBuilderInterceptor : ClassBuilderInterceptorExtension {
|
|||||||
when {
|
when {
|
||||||
publicAbi ->
|
publicAbi ->
|
||||||
abiClassInfo[internalName] = AbiClassInfo.Public
|
abiClassInfo[internalName] = AbiClassInfo.Public
|
||||||
!localOrAnonymousClass -> {
|
!localOrAnonymousClass && !isWhenMappingClass -> {
|
||||||
for (method in maskedMethods) {
|
for (method in maskedMethods) {
|
||||||
methodInfos.replace(method, AbiMethodInfo.STRIP)
|
methodInfos.replace(method, AbiMethodInfo.STRIP)
|
||||||
}
|
}
|
||||||
@@ -165,5 +166,8 @@ class JvmAbiClassBuilderInterceptor : ClassBuilderInterceptorExtension {
|
|||||||
}
|
}
|
||||||
super.done()
|
super.done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val isWhenMappingClass: Boolean
|
||||||
|
get() = internalName.endsWith(WhenByEnumsMapping.MAPPINGS_CLASS_NAME_POSTFIX)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+5
@@ -65,6 +65,11 @@ public class CompileAgainstJvmAbiTestGenerated extends AbstractCompileAgainstJvm
|
|||||||
runTest("plugins/jvm-abi-gen/testData/compile/inlineReifiedFunction/");
|
runTest("plugins/jvm-abi-gen/testData/compile/inlineReifiedFunction/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineWhenMappings")
|
||||||
|
public void testInlineWhenMappings() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/inlineWhenMappings/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("innerObjectRegeneration")
|
@TestMetadata("innerObjectRegeneration")
|
||||||
public void testInnerObjectRegeneration() throws Exception {
|
public void testInnerObjectRegeneration() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/compile/innerObjectRegeneration/");
|
runTest("plugins/jvm-abi-gen/testData/compile/innerObjectRegeneration/");
|
||||||
|
|||||||
Generated
+5
@@ -65,6 +65,11 @@ public class IrCompileAgainstJvmAbiTestGenerated extends AbstractIrCompileAgains
|
|||||||
runTest("plugins/jvm-abi-gen/testData/compile/inlineReifiedFunction/");
|
runTest("plugins/jvm-abi-gen/testData/compile/inlineReifiedFunction/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineWhenMappings")
|
||||||
|
public void testInlineWhenMappings() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/inlineWhenMappings/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("innerObjectRegeneration")
|
@TestMetadata("innerObjectRegeneration")
|
||||||
public void testInnerObjectRegeneration() throws Exception {
|
public void testInnerObjectRegeneration() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/compile/innerObjectRegeneration/");
|
runTest("plugins/jvm-abi-gen/testData/compile/innerObjectRegeneration/");
|
||||||
|
|||||||
+10
@@ -35,8 +35,18 @@ public class IrJvmAbiContentTestGenerated extends AbstractIrJvmAbiContentTest {
|
|||||||
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
|
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("anonymousWhenMapping")
|
||||||
|
public void testAnonymousWhenMapping() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/content/anonymousWhenMapping/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("class")
|
@TestMetadata("class")
|
||||||
public void testClass() throws Exception {
|
public void testClass() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/content/class/");
|
runTest("plugins/jvm-abi-gen/testData/content/class/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenMapping")
|
||||||
|
public void testWhenMapping() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/content/whenMapping/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -35,8 +35,18 @@ public class JvmAbiContentTestGenerated extends AbstractJvmAbiContentTest {
|
|||||||
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
|
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("anonymousWhenMapping")
|
||||||
|
public void testAnonymousWhenMapping() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/content/anonymousWhenMapping/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("class")
|
@TestMetadata("class")
|
||||||
public void testClass() throws Exception {
|
public void testClass() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/content/class/");
|
runTest("plugins/jvm-abi-gen/testData/content/class/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenMapping")
|
||||||
|
public void testWhenMapping() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/content/whenMapping/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+5
@@ -65,6 +65,11 @@ public class LegacyCompileAgainstJvmAbiTestGenerated extends AbstractLegacyCompi
|
|||||||
runTest("plugins/jvm-abi-gen/testData/compile/inlineReifiedFunction/");
|
runTest("plugins/jvm-abi-gen/testData/compile/inlineReifiedFunction/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineWhenMappings")
|
||||||
|
public void testInlineWhenMappings() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compile/inlineWhenMappings/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("innerObjectRegeneration")
|
@TestMetadata("innerObjectRegeneration")
|
||||||
public void testInnerObjectRegeneration() throws Exception {
|
public void testInnerObjectRegeneration() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/compile/innerObjectRegeneration/");
|
runTest("plugins/jvm-abi-gen/testData/compile/innerObjectRegeneration/");
|
||||||
|
|||||||
Generated
+10
@@ -35,8 +35,18 @@ public class LegacyJvmAbiContentTestGenerated extends AbstractLegacyJvmAbiConten
|
|||||||
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
|
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("anonymousWhenMapping")
|
||||||
|
public void testAnonymousWhenMapping() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/content/anonymousWhenMapping/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("class")
|
@TestMetadata("class")
|
||||||
public void testClass() throws Exception {
|
public void testClass() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/content/class/");
|
runTest("plugins/jvm-abi-gen/testData/content/class/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenMapping")
|
||||||
|
public void testWhenMapping() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/content/whenMapping/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import lib.*
|
||||||
|
|
||||||
|
fun runAppAndReturnOk(): String = value(E.A)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// IGNORE_BACKEND_LEGACY: JVM
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
enum class E {
|
||||||
|
A, B
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun value(x: E) = when (x) {
|
||||||
|
E.A -> "OK"
|
||||||
|
E.B -> "Fail"
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
@kotlin.Metadata
|
||||||
|
public final enum class test/E {
|
||||||
|
// source: 'test.kt'
|
||||||
|
public final enum static field A: test.E
|
||||||
|
public final enum static field B: test.E
|
||||||
|
public static method valueOf(p0: java.lang.String): test.E
|
||||||
|
public static method values(): test.E[]
|
||||||
|
}
|
||||||
|
@kotlin.Metadata
|
||||||
|
public final class test/Test {
|
||||||
|
// source: 'test.kt'
|
||||||
|
public method <init>(): void
|
||||||
|
public final @org.jetbrains.annotations.NotNull method anonymousWhenMapping(@org.jetbrains.annotations.NotNull p0: test.E): java.lang.String
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
enum class E { A, B }
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
fun anonymousWhenMapping(e: E) = when (e) {
|
||||||
|
E.A -> "OK"
|
||||||
|
else -> "Fail"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// IGNORE_BACKEND_LEGACY: JVM
|
||||||
|
// IGNORE_BACKEND: JVM
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
@kotlin.Metadata
|
||||||
|
public final enum class test/E {
|
||||||
|
// source: 'test.kt'
|
||||||
|
public final enum static field A: test.E
|
||||||
|
public final enum static field B: test.E
|
||||||
|
public static method valueOf(p0: java.lang.String): test.E
|
||||||
|
public static method values(): test.E[]
|
||||||
|
}
|
||||||
|
@kotlin.Metadata
|
||||||
|
public synthetic final class test/Test$WhenMappings {
|
||||||
|
// source: 'test.kt'
|
||||||
|
public synthetic final static field $EnumSwitchMapping$0: int[]
|
||||||
|
static method <clinit>(): void
|
||||||
|
public synthetic inner class test/Test$WhenMappings
|
||||||
|
}
|
||||||
|
@kotlin.Metadata
|
||||||
|
public final class test/Test {
|
||||||
|
// source: 'test.kt'
|
||||||
|
public method <init>(): void
|
||||||
|
public final @org.jetbrains.annotations.NotNull method visibleWhenMapping(@org.jetbrains.annotations.NotNull p0: test.E): java.lang.String
|
||||||
|
public synthetic inner class test/Test$WhenMappings
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
enum class E { A, B }
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
inline fun visibleWhenMapping(e: E) = when (e) {
|
||||||
|
E.A -> "OK"
|
||||||
|
else -> "Fail"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user