Don't propagate reified markers for special enum functions
#KT-18254 Fixed
This commit is contained in:
@@ -4232,14 +4232,29 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
putReifiedOperationMarkerIfTypeIsReifiedParameter(type, operationKind, v, this);
|
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(
|
public static void putReifiedOperationMarkerIfTypeIsReifiedParameter(
|
||||||
@NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v,
|
@NotNull KotlinType type, @NotNull ReifiedTypeInliner.OperationKind operationKind, @NotNull InstructionAdapter v,
|
||||||
@NotNull BaseExpressionCodegen codegen
|
@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);
|
Pair<TypeParameterDescriptor, ReificationArgument> typeParameterAndReificationArgument = extractReificationArgument(type);
|
||||||
if (typeParameterAndReificationArgument != null && typeParameterAndReificationArgument.getFirst().isReified()) {
|
if (typeParameterAndReificationArgument != null && typeParameterAndReificationArgument.getFirst().isReified()) {
|
||||||
TypeParameterDescriptor typeParameterDescriptor = typeParameterAndReificationArgument.getFirst();
|
TypeParameterDescriptor typeParameterDescriptor = typeParameterAndReificationArgument.getFirst();
|
||||||
codegen.consumeReifiedOperationMarker(typeParameterDescriptor);
|
if (codegen != null) {
|
||||||
|
codegen.consumeReifiedOperationMarker(typeParameterDescriptor);
|
||||||
|
}
|
||||||
v.iconst(operationKind.getId());
|
v.iconst(operationKind.getId());
|
||||||
v.visitLdcInsn(typeParameterAndReificationArgument.getSecond().asString());
|
v.visitLdcInsn(typeParameterAndReificationArgument.getSecond().asString());
|
||||||
v.invokestatic(
|
v.invokestatic(
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
|
|||||||
|
|
||||||
var nodeAndSmap: SMAPAndMethodNode? = null
|
var nodeAndSmap: SMAPAndMethodNode? = null
|
||||||
try {
|
try {
|
||||||
nodeAndSmap = createInlineMethodNode(functionDescriptor, jvmSignature, codegen, callDefault, resolvedCall, state, sourceCompiler)
|
nodeAndSmap = createInlineMethodNode(functionDescriptor, jvmSignature, callDefault, resolvedCall, state, sourceCompiler)
|
||||||
endCall(inlineCall(nodeAndSmap, callDefault))
|
endCall(inlineCall(nodeAndSmap, callDefault))
|
||||||
}
|
}
|
||||||
catch (e: CompilationException) {
|
catch (e: CompilationException) {
|
||||||
@@ -467,7 +467,6 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
|
|||||||
internal fun createInlineMethodNode(
|
internal fun createInlineMethodNode(
|
||||||
functionDescriptor: FunctionDescriptor,
|
functionDescriptor: FunctionDescriptor,
|
||||||
jvmSignature: JvmMethodSignature,
|
jvmSignature: JvmMethodSignature,
|
||||||
codegen: BaseExpressionCodegen,
|
|
||||||
callDefault: Boolean,
|
callDefault: Boolean,
|
||||||
resolvedCall: ResolvedCall<*>?,
|
resolvedCall: ResolvedCall<*>?,
|
||||||
state: GenerationState,
|
state: GenerationState,
|
||||||
@@ -478,7 +477,6 @@ abstract class InlineCodegen<out T: BaseExpressionCodegen>(
|
|||||||
val arguments = resolvedCall!!.typeArguments
|
val arguments = resolvedCall!!.typeArguments
|
||||||
|
|
||||||
val node = createSpecialEnumMethodBody(
|
val node = createSpecialEnumMethodBody(
|
||||||
codegen,
|
|
||||||
functionDescriptor.name.asString(),
|
functionDescriptor.name.asString(),
|
||||||
arguments.keys.single().defaultType,
|
arguments.keys.single().defaultType,
|
||||||
state.typeMapper
|
state.typeMapper
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ class InlineCodegenForDefaultBody(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun genCallInner(callableMethod: Callable, resolvedCall: ResolvedCall<*>?, callDefault: Boolean, codegen: ExpressionCodegen) {
|
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 childSourceMapper = InlineCodegen.createNestedSourceMapper(nodeAndSmap, sourceMapper)
|
||||||
|
|
||||||
val node = nodeAndSmap.node
|
val node = nodeAndSmap.node
|
||||||
|
|||||||
@@ -511,7 +511,6 @@ internal fun isSpecialEnumMethod(functionDescriptor: FunctionDescriptor): Boolea
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun createSpecialEnumMethodBody(
|
internal fun createSpecialEnumMethodBody(
|
||||||
codegen: BaseExpressionCodegen,
|
|
||||||
name: String,
|
name: String,
|
||||||
type: KotlinType,
|
type: KotlinType,
|
||||||
typeMapper: KotlinTypeMapper
|
typeMapper: KotlinTypeMapper
|
||||||
@@ -520,7 +519,7 @@ internal fun createSpecialEnumMethodBody(
|
|||||||
val invokeType = typeMapper.mapType(type)
|
val invokeType = typeMapper.mapType(type)
|
||||||
val desc = getSpecialEnumFunDescriptor(invokeType, isValueOf)
|
val desc = getSpecialEnumFunDescriptor(invokeType, isValueOf)
|
||||||
val node = MethodNode(API, Opcodes.ACC_STATIC, "fake", desc, null, null)
|
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) {
|
if (isValueOf) {
|
||||||
node.visitInsn(Opcodes.ACONST_NULL)
|
node.visitInsn(Opcodes.ACONST_NULL)
|
||||||
node.visitVarInsn(Opcodes.ALOAD, 0)
|
node.visitVarInsn(Opcodes.ALOAD, 0)
|
||||||
|
|||||||
@@ -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
@@ -2,8 +2,8 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
package test
|
package test
|
||||||
|
|
||||||
inline fun <reified T : Enum<T>> myValueOf(): String {
|
inline fun <reified X : Enum<X>> myValueOf(): String {
|
||||||
return enumValueOf<T>("OK").name
|
return enumValueOf<X>("OK").name
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Z {
|
enum class Z {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
package test
|
package test
|
||||||
|
|
||||||
inline fun <reified T : Enum<T>> myValueOf(): String {
|
inline fun <reified Z : Enum<Z>> myValueOf(): String {
|
||||||
return myValueOf2<T>()
|
return myValueOf2<Z>()
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified Y : Enum<Y>> myValueOf2(): String {
|
inline fun <reified Y : Enum<Y>> myValueOf2(): String {
|
||||||
|
|||||||
+6
@@ -1484,6 +1484,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("valueOf.kt")
|
||||||
public void testValueOf() throws Exception {
|
public void testValueOf() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
||||||
|
|||||||
+6
@@ -1484,6 +1484,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("valueOf.kt")
|
||||||
public void testValueOf() throws Exception {
|
public void testValueOf() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
||||||
|
|||||||
@@ -1484,6 +1484,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("valueOf.kt")
|
||||||
public void testValueOf() throws Exception {
|
public void testValueOf() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
||||||
|
|||||||
+6
@@ -1484,6 +1484,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("valueOf.kt")
|
||||||
public void testValueOf() throws Exception {
|
public void testValueOf() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
||||||
|
|||||||
+6
@@ -42,6 +42,12 @@ public class EnumValuesInlineTestsGenerated extends AbstractEnumValuesInlineTest
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("valueOf.kt")
|
||||||
public void testValueOf() throws Exception {
|
public void testValueOf() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/enum/valueOf.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user