Exclude non-inline method bodies from ABI classes
This commit is contained in:
@@ -7,11 +7,9 @@ package org.jetbrains.kotlin.jvm.abi.asm
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.codegen.AbstractClassBuilder
|
import org.jetbrains.kotlin.codegen.AbstractClassBuilder
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||||
import org.jetbrains.org.objectweb.asm.ClassVisitor
|
import org.jetbrains.org.objectweb.asm.*
|
||||||
import org.jetbrains.org.objectweb.asm.FieldVisitor
|
|
||||||
import org.jetbrains.org.objectweb.asm.MethodVisitor
|
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
|
||||||
|
|
||||||
internal class AbiClassBuilder(private val cv: ClassVisitor) : AbstractClassBuilder() {
|
internal class AbiClassBuilder(private val cv: ClassVisitor) : AbstractClassBuilder() {
|
||||||
override fun getVisitor(): ClassVisitor = cv
|
override fun getVisitor(): ClassVisitor = cv
|
||||||
@@ -26,7 +24,13 @@ internal class AbiClassBuilder(private val cv: ClassVisitor) : AbstractClassBuil
|
|||||||
): MethodVisitor {
|
): MethodVisitor {
|
||||||
if (isPrivate(access)) return EMPTY_METHOD_VISITOR
|
if (isPrivate(access)) return EMPTY_METHOD_VISITOR
|
||||||
|
|
||||||
return super.newMethod(origin, access, name, desc, signature, exceptions)
|
val mv = super.newMethod(origin, access, name, desc, signature, exceptions)
|
||||||
|
val descriptor = origin.descriptor
|
||||||
|
if (descriptor is FunctionDescriptor && descriptor.isInline) return mv
|
||||||
|
|
||||||
|
// getArgumentsAndReturnSizes returns `(argSize << 2) | retSize`, where argSize includes `this`
|
||||||
|
val maxLocals = (Type.getArgumentsAndReturnSizes(desc) shr 2) - 1
|
||||||
|
return ReplaceWithEmptyMethodVisitor(maxLocals, mv, Opcodes.ASM6)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun newField(
|
override fun newField(
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.jvm.abi.asm
|
||||||
|
|
||||||
|
import org.jetbrains.org.objectweb.asm.*
|
||||||
|
|
||||||
|
internal class ReplaceWithEmptyMethodVisitor(
|
||||||
|
private val newMaxLocals: Int,
|
||||||
|
private val delegate: MethodVisitor,
|
||||||
|
api: Int
|
||||||
|
) : MethodVisitor(api, null) {
|
||||||
|
override fun visitCode() {
|
||||||
|
delegate.visitCode()
|
||||||
|
delegate.visitMaxs(0, newMaxLocals)
|
||||||
|
delegate.visitEnd()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitParameter(name: String?, access: Int) {
|
||||||
|
delegate.visitParameter(name, access)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitParameterAnnotation(parameter: Int, desc: String?, visible: Boolean): AnnotationVisitor =
|
||||||
|
delegate.visitParameterAnnotation(parameter, desc, visible)
|
||||||
|
|
||||||
|
override fun visitAnnotationDefault(): AnnotationVisitor =
|
||||||
|
delegate.visitAnnotationDefault()
|
||||||
|
|
||||||
|
override fun visitAnnotation(desc: String?, visible: Boolean): AnnotationVisitor =
|
||||||
|
delegate.visitAnnotation(desc, visible)
|
||||||
|
|
||||||
|
override fun visitTypeAnnotation(typeRef: Int, typePath: TypePath?, desc: String?, visible: Boolean): AnnotationVisitor =
|
||||||
|
delegate.visitTypeAnnotation(typeRef, typePath, desc, visible)
|
||||||
|
|
||||||
|
override fun visitAttribute(attr: Attribute?) {
|
||||||
|
delegate.visitAttribute(attr)
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -34,6 +34,16 @@ public class CompareJvmAbiTestGenerated extends AbstractCompareJvmAbiTest {
|
|||||||
runTest("plugins/jvm-abi-gen/testData/compare/classPrivateMemebers/");
|
runTest("plugins/jvm-abi-gen/testData/compare/classPrivateMemebers/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionBody")
|
||||||
|
public void testFunctionBody() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compare/functionBody/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inlineFunctionBody")
|
||||||
|
public void testInlineFunctionBody() throws Exception {
|
||||||
|
runTest("plugins/jvm-abi-gen/testData/compare/inlineFunctionBody/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("topLevelPrivateMembers")
|
@TestMetadata("topLevelPrivateMembers")
|
||||||
public void testTopLevelPrivateMembers() throws Exception {
|
public void testTopLevelPrivateMembers() throws Exception {
|
||||||
runTest("plugins/jvm-abi-gen/testData/compare/topLevelPrivateMembers/");
|
runTest("plugins/jvm-abi-gen/testData/compare/topLevelPrivateMembers/");
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
fun sum(x: Int, y: Int): Int = x + y
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
fun sum(x: Int, y: Int): Int = y + x
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
inline fun sum(x: Int, y: Int): Int = x + y
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
inline fun sum(x: Int, y: Int): Int = y + x
|
||||||
Reference in New Issue
Block a user