Don't propagate reified markers for special enum functions

#KT-18254 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-11-06 11:43:41 +01:00
parent 800cc63347
commit 416392bb74
12 changed files with 70 additions and 11 deletions
@@ -4232,14 +4232,29 @@ The "returned" value of try expression with no finally is either the last expres
putReifiedOperationMarkerIfTypeIsReifiedParameter(type, operationKind, v, this);
}
public static void putReifiedOperationMarkerIfTypeIsReifiedParameterWithoutPropagation(
@NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v
) {
putReifiedOperationMarkerIfTypeIsReifiedParameterImpl(type, operationKind, v, null);
}
public static void putReifiedOperationMarkerIfTypeIsReifiedParameter(
@NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v,
@NotNull BaseExpressionCodegen codegen
) {
putReifiedOperationMarkerIfTypeIsReifiedParameterImpl(type, operationKind, v, codegen);
}
private static void putReifiedOperationMarkerIfTypeIsReifiedParameterImpl(
@NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v,
@Nullable BaseExpressionCodegen codegen
) {
Pair<TypeParameterDescriptor, ReificationArgument> typeParameterAndReificationArgument = extractReificationArgument(type);
if (typeParameterAndReificationArgument != null && typeParameterAndReificationArgument.getFirst().isReified()) {
TypeParameterDescriptor typeParameterDescriptor = typeParameterAndReificationArgument.getFirst();
codegen.consumeReifiedOperationMarker(typeParameterDescriptor);
if (codegen != null) {
codegen.consumeReifiedOperationMarker(typeParameterDescriptor);
}
v.iconst(operationKind.getId());
v.visitLdcInsn(typeParameterAndReificationArgument.getSecond().asString());
v.invokestatic(
@@ -166,7 +166,7 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
var nodeAndSmap: SMAPAndMethodNode? = null
try {
nodeAndSmap = createInlineMethodNode(functionDescriptor, jvmSignature, codegen, callDefault, resolvedCall, state, sourceCompiler)
nodeAndSmap = createInlineMethodNode(functionDescriptor, jvmSignature, callDefault, resolvedCall, state, sourceCompiler)
endCall(inlineCall(nodeAndSmap, callDefault))
}
catch (e: CompilationException) {
@@ -467,7 +467,6 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
internal fun createInlineMethodNode(
functionDescriptor: FunctionDescriptor,
jvmSignature: JvmMethodSignature,
codegen: BaseExpressionCodegen,
callDefault: Boolean,
resolvedCall: ResolvedCall<*>?,
state: GenerationState,
@@ -478,7 +477,6 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
val arguments = resolvedCall!!.typeArguments
val node = createSpecialEnumMethodBody(
codegen,
functionDescriptor.name.asString(),
arguments.keys.single().defaultType,
state.typeMapper
@@ -66,7 +66,7 @@ class InlineCodegenForDefaultBody(
}
override fun genCallInner(callableMethod: Callable, resolvedCall: ResolvedCall<*>?, callDefault: Boolean, codegen: ExpressionCodegen) {
val nodeAndSmap = InlineCodegen.createInlineMethodNode(functionDescriptor, jvmSignature, codegen, callDefault, null, state, sourceCompilerForInline)
val nodeAndSmap = InlineCodegen.createInlineMethodNode(functionDescriptor, jvmSignature, callDefault, null, state, sourceCompilerForInline)
val childSourceMapper = InlineCodegen.createNestedSourceMapper(nodeAndSmap, sourceMapper)
val node = nodeAndSmap.node
@@ -511,7 +511,6 @@ internal fun isSpecialEnumMethod(functionDescriptor: FunctionDescriptor): Boolea
}
internal fun createSpecialEnumMethodBody(
codegen: BaseExpressionCodegen,
name: String,
type: KotlinType,
typeMapper: KotlinTypeMapper
@@ -520,7 +519,7 @@ internal fun createSpecialEnumMethodBody(
val invokeType = typeMapper.mapType(type)
val desc = getSpecialEnumFunDescriptor(invokeType, isValueOf)
val node = MethodNode(API, Opcodes.ACC_STATIC, "fake", desc, null, null)
ExpressionCodegen.putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.ENUM_REIFIED, InstructionAdapter(node), codegen)
ExpressionCodegen.putReifiedOperationMarkerIfTypeIsReifiedParameterWithoutPropagation(type, ReifiedTypeInliner.OperationKind.ENUM_REIFIED, InstructionAdapter(node))
if (isValueOf) {
node.visitInsn(Opcodes.ACONST_NULL)
node.visitVarInsn(Opcodes.ALOAD, 0)
+17
View File
@@ -0,0 +1,17 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun stub() {}
enum class Z {
OK
}
// FILE: 2.kt
// NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
return { enumValueOf<Z>("OK").name } ()
}
+2 -2
View File
@@ -2,8 +2,8 @@
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValueOf(): String {
return enumValueOf<T>("OK").name
inline fun <reified X : Enum<X>> myValueOf(): String {
return enumValueOf<X>("OK").name
}
enum class Z {
@@ -2,8 +2,8 @@
// WITH_RUNTIME
package test
inline fun <reified T : Enum<T>> myValueOf(): String {
return myValueOf2<T>()
inline fun <reified Z : Enum<Z>> myValueOf(): String {
return myValueOf2<Z>()
}
inline fun <reified Y : Enum<Y>> myValueOf2(): String {
@@ -1484,6 +1484,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
doTest(fileName);
}
@TestMetadata("kt18254.kt")
public void testKt18254() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt");
doTest(fileName);
}
@TestMetadata("valueOf.kt")
public void testValueOf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
@@ -1484,6 +1484,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
doTest(fileName);
}
@TestMetadata("kt18254.kt")
public void testKt18254() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt");
doTest(fileName);
}
@TestMetadata("valueOf.kt")
public void testValueOf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
@@ -1484,6 +1484,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName);
}
@TestMetadata("kt18254.kt")
public void testKt18254() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt");
doTest(fileName);
}
@TestMetadata("valueOf.kt")
public void testValueOf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
@@ -1484,6 +1484,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName);
}
@TestMetadata("kt18254.kt")
public void testKt18254() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt");
doTest(fileName);
}
@TestMetadata("valueOf.kt")
public void testValueOf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
@@ -42,6 +42,12 @@ public class EnumValuesInlineTestsGenerated extends AbstractEnumValuesInlineTest
doTest(fileName);
}
@TestMetadata("kt18254.kt")
public void testKt18254() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/kt18254.kt");
doTest(fileName);
}
@TestMetadata("valueOf.kt")
public void testValueOf() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");