Don't try to transform sam wrappers in same module
#KT-22304 Fixed
This commit is contained in:
@@ -55,6 +55,7 @@ public class SamWrapperCodegen {
|
|||||||
private final SamType samType;
|
private final SamType samType;
|
||||||
private final MemberCodegen<?> parentCodegen;
|
private final MemberCodegen<?> parentCodegen;
|
||||||
private final int visibility;
|
private final int visibility;
|
||||||
|
public static final String SAM_WRAPPER_SUFFIX = "$0";
|
||||||
|
|
||||||
public SamWrapperCodegen(
|
public SamWrapperCodegen(
|
||||||
@NotNull GenerationState state,
|
@NotNull GenerationState state,
|
||||||
@@ -206,7 +207,7 @@ public class SamWrapperCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String shortName = String.format(
|
String shortName = String.format(
|
||||||
"%s$sam%s$%s$0",
|
"%s$sam%s$%s" + SAM_WRAPPER_SUFFIX,
|
||||||
outermostOwner.shortName().asString(),
|
outermostOwner.shortName().asString(),
|
||||||
(isInsideInline ? "$i" : ""),
|
(isInsideInline ? "$i" : ""),
|
||||||
DescriptorUtils.getFqNameSafe(samType.getJavaClassDescriptor()).asString().replace('.', '_')
|
DescriptorUtils.getFqNameSafe(samType.getJavaClassDescriptor()).asString().replace('.', '_')
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ class MethodInliner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun anew(type: Type) {
|
override fun anew(type: Type) {
|
||||||
if (isOldSamWrapper(type.internalName) || isAnonymousClass(type.internalName)) {
|
if (isSamWrapper(type.internalName) || isAnonymousClass(type.internalName)) {
|
||||||
handleAnonymousObjectRegeneration()
|
handleAnonymousObjectRegeneration()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.codegen.AsmUtil
|
|||||||
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
|
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
|
||||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||||
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
||||||
|
import org.jetbrains.kotlin.codegen.SamWrapperCodegen.SAM_WRAPPER_SUFFIX
|
||||||
import org.jetbrains.kotlin.codegen.`when`.WhenByEnumsMapping
|
import org.jetbrains.kotlin.codegen.`when`.WhenByEnumsMapping
|
||||||
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
|
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
|
||||||
import org.jetbrains.kotlin.codegen.context.CodegenContext
|
import org.jetbrains.kotlin.codegen.context.CodegenContext
|
||||||
@@ -226,14 +227,18 @@ internal fun isAnonymousSingletonLoad(internalName: String, fieldName: String):
|
|||||||
* hash
|
* hash
|
||||||
* );
|
* );
|
||||||
*/
|
*/
|
||||||
internal fun isOldSamWrapper(internalName: String) =
|
private fun isOldSamWrapper(internalName: String) =
|
||||||
internalName.contains("\$sam$") && internalName.substringAfter("\$i$", "").run { length == 8 && toLongOrNull(16) != null }
|
internalName.contains("\$sam$") && internalName.substringAfter("\$i$", "").run { length == 8 && toLongOrNull(16) != null }
|
||||||
|
|
||||||
|
internal fun isSamWrapper(internalName: String) =
|
||||||
|
(internalName.endsWith(SAM_WRAPPER_SUFFIX) && internalName.contains("\$sam\$i\$")) || isOldSamWrapper(internalName)
|
||||||
|
|
||||||
|
|
||||||
internal fun isSamWrapperConstructorCall(internalName: String, methodName: String) =
|
internal fun isSamWrapperConstructorCall(internalName: String, methodName: String) =
|
||||||
isConstructor(methodName) && isOldSamWrapper(internalName)
|
isConstructor(methodName) && isSamWrapper(internalName)
|
||||||
|
|
||||||
internal fun isAnonymousClass(internalName: String) =
|
internal fun isAnonymousClass(internalName: String) =
|
||||||
!isOldSamWrapper(internalName) &&
|
!isSamWrapper(internalName) &&
|
||||||
internalName.substringAfterLast('/').substringAfterLast("$", "").isInteger()
|
internalName.substringAfterLast('/').substringAfterLast("$", "").isInteger()
|
||||||
|
|
||||||
fun wrapWithMaxLocalCalc(methodNode: MethodNode) =
|
fun wrapWithMaxLocalCalc(methodNode: MethodNode) =
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
$TESTDATA_DIR$/kt22304_1.kt
|
||||||
|
$TESTDATA_DIR$/kt22304_2.kt
|
||||||
|
$TESTDATA_DIR$/kt22304_3.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
|
fun test(): String = ""
|
||||||
|
|
||||||
|
inline fun String.switchMapOnce(crossinline mapper: (String) -> String): String {
|
||||||
|
Callable(::test)
|
||||||
|
return { mapper(this) }()
|
||||||
|
}
|
||||||
|
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package beforeTest //package name should be less than imported one
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
"O".switchMapOnce {
|
||||||
|
|
||||||
|
"K".switchMapOnce {
|
||||||
|
"OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package ttest //package name should be more than imported one
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
fun foo(): String {
|
||||||
|
return "O".switchMapOnce {
|
||||||
|
|
||||||
|
"K".switchMapOnce {
|
||||||
|
"OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
// FULL_JDK
|
||||||
|
|
||||||
|
package test
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
|
fun test(): String = ""
|
||||||
|
|
||||||
|
inline fun String.switchMapOnce(crossinline mapper: (String) -> String): String {
|
||||||
|
Callable(::test)
|
||||||
|
return { mapper(this) }()
|
||||||
|
}
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
return "O".switchMapOnce {
|
||||||
|
|
||||||
|
"K".switchMapOnce {
|
||||||
|
"OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ import test.*
|
|||||||
fun box(): String {
|
fun box(): String {
|
||||||
val anotherModule = doWork { "K" }
|
val anotherModule = doWork { "K" }
|
||||||
|
|
||||||
if (anotherModule.javaClass.name != "BKt\$box$\$inlined\$doWork$1") return "class should be regenerated, but ${anotherModule.javaClass.name}"
|
if (anotherModule.javaClass.name != "BKt\$inlined\$sam\$i\$java_util_concurrent_Callable\$0") return "class should be regenerated, but ${anotherModule.javaClass.name}"
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -482,6 +482,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22304.kt")
|
||||||
|
public void testKt22304() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("samOnCallSite.kt")
|
@TestMetadata("samOnCallSite.kt")
|
||||||
public void testSamOnCallSite() throws Exception {
|
public void testSamOnCallSite() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
||||||
|
|||||||
+6
@@ -482,6 +482,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22304.kt")
|
||||||
|
public void testKt22304() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("samOnCallSite.kt")
|
@TestMetadata("samOnCallSite.kt")
|
||||||
public void testSamOnCallSite() throws Exception {
|
public void testSamOnCallSite() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
||||||
|
|||||||
@@ -387,6 +387,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
doJvmTest(fileName);
|
doJvmTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22304.args")
|
||||||
|
public void testKt22304() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/kt22304.args");
|
||||||
|
doJvmTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("languageVersion.args")
|
@TestMetadata("languageVersion.args")
|
||||||
public void testLanguageVersion() throws Exception {
|
public void testLanguageVersion() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/languageVersion.args");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/languageVersion.args");
|
||||||
|
|||||||
+6
@@ -482,6 +482,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22304.kt")
|
||||||
|
public void testKt22304() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("samOnCallSite.kt")
|
@TestMetadata("samOnCallSite.kt")
|
||||||
public void testSamOnCallSite() throws Exception {
|
public void testSamOnCallSite() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
||||||
|
|||||||
Generated
+6
@@ -482,6 +482,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt22304.kt")
|
||||||
|
public void testKt22304() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("samOnCallSite.kt")
|
@TestMetadata("samOnCallSite.kt")
|
||||||
public void testSamOnCallSite() throws Exception {
|
public void testSamOnCallSite() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/sam/samOnCallSite.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user