Do not use KotlinTypeMapper when generating JVM assert inline intrinsics

This commit is contained in:
Alexander Udalov
2019-09-04 18:12:44 +02:00
parent 15bfb7498c
commit 8efbcc5350
3 changed files with 11 additions and 17 deletions
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.codegen package org.jetbrains.kotlin.codegen
import org.jetbrains.kotlin.codegen.coroutines.createCustomCopy import org.jetbrains.kotlin.codegen.coroutines.createCustomCopy
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.JVMAssertionsMode import org.jetbrains.kotlin.config.JVMAssertionsMode
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.isTopLevelInPackage import org.jetbrains.kotlin.descriptors.isTopLevelInPackage
@@ -48,22 +47,17 @@ fun FunctionDescriptor.isBuiltinAlwaysEnabledAssert() =
fun FieldInsnNode.isCheckAssertionsStatus() = fun FieldInsnNode.isCheckAssertionsStatus() =
opcode == Opcodes.GETSTATIC && name == ASSERTIONS_DISABLED_FIELD_NAME && desc == Type.BOOLEAN_TYPE.descriptor opcode == Opcodes.GETSTATIC && name == ASSERTIONS_DISABLED_FIELD_NAME && desc == Type.BOOLEAN_TYPE.descriptor
fun createMethodNodeForAlwaysEnabledAssert( fun createMethodNodeForAlwaysEnabledAssert(functionDescriptor: FunctionDescriptor): MethodNode {
functionDescriptor: FunctionDescriptor, val signature = when {
typeMapper: KotlinTypeMapper functionDescriptor.isBuiltinAlwaysEnabledAssertWithLambda() ->
): MethodNode { Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE, AsmTypes.FUNCTION0)
assert(functionDescriptor.isBuiltinAlwaysEnabledAssert()) { functionDescriptor.isBuiltinAlwaysEnabledAssertWithoutLambda() ->
"functionDescriptor must be kotlin.alwaysEnabledAssert, but got $functionDescriptor" Type.getMethodDescriptor(Type.VOID_TYPE, Type.BOOLEAN_TYPE)
else ->
error("functionDescriptor must be kotlin.alwaysEnabledAssert, but got $functionDescriptor")
} }
val node = val node = MethodNode(Opcodes.API_VERSION, Opcodes.ACC_STATIC, "fake", signature, null, null)
org.jetbrains.org.objectweb.asm.tree.MethodNode(
Opcodes.API_VERSION,
Opcodes.ACC_STATIC,
"fake",
typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null
)
val v = InstructionAdapter(node) val v = InstructionAdapter(node)
val returnLabel = Label() val returnLabel = Label()
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.codegen.ExpressionCodegen
import org.jetbrains.kotlin.codegen.coroutines.createMethodNodeForCoroutineContext import org.jetbrains.kotlin.codegen.coroutines.createMethodNodeForCoroutineContext
import org.jetbrains.kotlin.codegen.coroutines.createMethodNodeForIntercepted import org.jetbrains.kotlin.codegen.coroutines.createMethodNodeForIntercepted
import org.jetbrains.kotlin.codegen.coroutines.createMethodNodeForSuspendCoroutineUninterceptedOrReturn import org.jetbrains.kotlin.codegen.coroutines.createMethodNodeForSuspendCoroutineUninterceptedOrReturn
import org.jetbrains.kotlin.codegen.coroutines.isBuiltInSuspendCoroutineUninterceptedOrReturnInJvm
import org.jetbrains.kotlin.codegen.createMethodNodeForAlwaysEnabledAssert import org.jetbrains.kotlin.codegen.createMethodNodeForAlwaysEnabledAssert
import org.jetbrains.kotlin.codegen.isBuiltinAlwaysEnabledAssert import org.jetbrains.kotlin.codegen.isBuiltinAlwaysEnabledAssert
import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.codegen.state.GenerationState
@@ -52,7 +51,7 @@ internal fun generateInlineIntrinsic(
descriptor.isBuiltInSuspendCoroutineUninterceptedOrReturn(languageVersionSettings) -> descriptor.isBuiltInSuspendCoroutineUninterceptedOrReturn(languageVersionSettings) ->
createMethodNodeForSuspendCoroutineUninterceptedOrReturn(descriptor, typeMapper, languageVersionSettings) createMethodNodeForSuspendCoroutineUninterceptedOrReturn(descriptor, typeMapper, languageVersionSettings)
descriptor.isBuiltinAlwaysEnabledAssert() -> descriptor.isBuiltinAlwaysEnabledAssert() ->
createMethodNodeForAlwaysEnabledAssert(descriptor, typeMapper) createMethodNodeForAlwaysEnabledAssert(descriptor)
else -> null else -> null
} }
} }
@@ -39,6 +39,7 @@ public class AsmTypes {
public static final Type RESULT_FAILURE = Type.getObjectType("kotlin/Result$Failure"); public static final Type RESULT_FAILURE = Type.getObjectType("kotlin/Result$Failure");
public static final Type FUNCTION0 = Type.getObjectType("kotlin/jvm/functions/Function0");
public static final Type FUNCTION1 = Type.getObjectType("kotlin/jvm/functions/Function1"); public static final Type FUNCTION1 = Type.getObjectType("kotlin/jvm/functions/Function1");
public static final Type[] PROPERTY_REFERENCE_IMPL = { public static final Type[] PROPERTY_REFERENCE_IMPL = {