jvm-abi-gen: remove SourceDebugExtension if no inline functions present

#KT-65072 Fixed
This commit is contained in:
Vladimir Tagakov
2024-01-16 16:03:30 -07:00
committed by Space Team
parent 8fbe376f25
commit 06095e86ca
7 changed files with 29 additions and 3 deletions
@@ -79,6 +79,7 @@ class JvmAbiOutputExtension(
else -> /* abiInfo is AbiClassInfo.Stripped */ {
val methodInfo = (abiInfo as AbiClassInfo.Stripped).methodInfo
val innerClassesToKeep = mutableSetOf<String>()
val noMethodsKept = methodInfo.values.none { it == AbiMethodInfo.KEEP }
val writer = ClassWriter(0)
val remapper = ClassRemapper(writer, object : Remapper() {
override fun map(internalName: String): String =
@@ -127,7 +128,7 @@ class JvmAbiOutputExtension(
override fun visitSource(source: String?, debug: String?) {
when {
removeDebugInfo -> super.visitSource(null, null)
methodInfo.values.none { it == AbiMethodInfo.KEEP } -> {
noMethodsKept -> {
// Strip SourceDebugExtension attribute if there are no inline functions.
super.visitSource(source, null)
}
@@ -144,8 +145,9 @@ class JvmAbiOutputExtension(
override fun visitAnnotation(descriptor: String?, visible: Boolean): AnnotationVisitor? {
// Strip @SourceDebugExtension annotation if we're removing debug info.
if (removeDebugInfo && descriptor == JvmAnnotationNames.SOURCE_DEBUG_EXTENSION_DESC)
return null
if (descriptor == JvmAnnotationNames.SOURCE_DEBUG_EXTENSION_DESC) {
if (removeDebugInfo || noMethodsKept) return null
}
val delegate = super.visitAnnotation(descriptor, visible)
if (descriptor != JvmAnnotationNames.METADATA_DESC)
@@ -115,6 +115,11 @@ public class CompareJvmAbiTestGenerated extends AbstractCompareJvmAbiTest {
runTest("plugins/jvm-abi-gen/testData/compare/inlineFunInPrivateNestedClass/");
}
@TestMetadata("inlineFunUsageMakesAbiUnstable")
public void testInlineFunUsageMakesAbiUnstable() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compare/inlineFunUsageMakesAbiUnstable/");
}
@TestMetadata("inlineFunctionBody")
public void testInlineFunctionBody() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compare/inlineFunctionBody/");
@@ -0,0 +1,4 @@
//this file could be in the same or in the different compilation module
package test
inline fun inlineFun() = Unit
@@ -0,0 +1,5 @@
package test
private fun main() {
inlineFun()
}
@@ -0,0 +1,4 @@
//this file could be in the same or in the different compilation module
package test
inline fun inlineFun() = Unit
@@ -0,0 +1,6 @@
package test
private fun main() {
//comment should not break ABI
inlineFun()
}