Fix for KT-11479: 1.0.2 Snapshot: CompilationException: Back-end (JVM) Internal error: Couldn't inline method call
#KT-11479 Fixed
This commit is contained in:
@@ -370,7 +370,7 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
MethodInliner inliner = new MethodInliner(
|
MethodInliner inliner = new MethodInliner(
|
||||||
node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule,
|
node, parameters, info, new FieldRemapper(null, null, parameters), isSameModule,
|
||||||
"Method inlining " + callElement.getText(),
|
"Method inlining " + callElement.getText(),
|
||||||
createNestedSourceMapper(nodeAndSmap), info.getCallSiteInfo(),
|
createNestedSourceMapper(nodeAndSmap, sourceMapper), info.getCallSiteInfo(),
|
||||||
AnnotationUtilKt.hasInlineOnlyAnnotation(functionDescriptor) ? new InlineOnlySmapSkipper(codegen) : null
|
AnnotationUtilKt.hasInlineOnlyAnnotation(functionDescriptor) ? new InlineOnlySmapSkipper(codegen) : null
|
||||||
); //with captured
|
); //with captured
|
||||||
|
|
||||||
@@ -882,8 +882,8 @@ public class InlineCodegen extends CallGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SourceMapper createNestedSourceMapper(@NotNull SMAPAndMethodNode nodeAndSmap) {
|
public static SourceMapper createNestedSourceMapper(@NotNull SMAPAndMethodNode nodeAndSmap, @NotNull SourceMapper parent) {
|
||||||
return new NestedSourceMapper(sourceMapper, nodeAndSmap.getRanges(), nodeAndSmap.getClassSMAP().getSourceInfo());
|
return new NestedSourceMapper(parent, nodeAndSmap.getRanges(), nodeAndSmap.getClassSMAP().getSourceInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reportIncrementalInfo(
|
static void reportIncrementalInfo(
|
||||||
|
|||||||
+16
-1
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||||
|
|
||||||
class InlineCodegenForDefaultBody(
|
class InlineCodegenForDefaultBody(
|
||||||
function: FunctionDescriptor,
|
function: FunctionDescriptor,
|
||||||
@@ -34,6 +35,8 @@ class InlineCodegenForDefaultBody(
|
|||||||
val state: GenerationState
|
val state: GenerationState
|
||||||
) : CallGenerator() {
|
) : CallGenerator() {
|
||||||
|
|
||||||
|
private val sourceMapper: SourceMapper = codegen.parentCodegen.orCreateSourceMapper
|
||||||
|
|
||||||
private val functionDescriptor =
|
private val functionDescriptor =
|
||||||
if (InlineUtil.isArrayConstructorWithLambda(function))
|
if (InlineUtil.isArrayConstructorWithLambda(function))
|
||||||
FictitiousArrayConstructor.create(function as ConstructorDescriptor)
|
FictitiousArrayConstructor.create(function as ConstructorDescriptor)
|
||||||
@@ -57,7 +60,19 @@ 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.createMethodNode(functionDescriptor, jvmSignature, codegen, context, callDefault, state)
|
val nodeAndSmap = InlineCodegen.createMethodNode(functionDescriptor, jvmSignature, codegen, context, callDefault, state)
|
||||||
nodeAndSmap.node.accept(MethodBodyVisitor(codegen.v))
|
val childSourceMapper = InlineCodegen.createNestedSourceMapper(nodeAndSmap, sourceMapper)
|
||||||
|
|
||||||
|
val node = nodeAndSmap.node
|
||||||
|
val transformedMethod = MethodNode(
|
||||||
|
node.access,
|
||||||
|
node.name,
|
||||||
|
node.desc,
|
||||||
|
node.signature,
|
||||||
|
node.exceptions.toTypedArray())
|
||||||
|
|
||||||
|
node.accept(InlineAdapter(transformedMethod, 0, childSourceMapper))
|
||||||
|
|
||||||
|
transformedMethod.accept(MethodBodyVisitor(codegen.v))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterParameterPut(type: Type, stackValue: StackValue?, parameterIndex: Int) {
|
override fun afterParameterPut(type: Type, stackValue: StackValue?, parameterIndex: Int) {
|
||||||
|
|||||||
@@ -29,15 +29,15 @@ class SMAPAndMethodNode(val node: MethodNode, val classSMAP: SMAP) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createLineNumberSequence(node: MethodNode, classSMAP: SMAP): Sequence<LabelAndMapping> {
|
private fun createLineNumberSequence(node: MethodNode, classSMAP: SMAP): Sequence<LabelAndMapping> {
|
||||||
return InsnSequence(node.instructions.first, null).filterIsInstance<LineNumberNode>().map { node ->
|
return InsnSequence(node.instructions.first, null).filterIsInstance<LineNumberNode>().map { lineNumber ->
|
||||||
val index = classSMAP.intervals.binarySearch(RangeMapping(node.line, node.line, 1), Comparator {
|
val index = classSMAP.intervals.binarySearch(RangeMapping(lineNumber.line, lineNumber.line, 1), Comparator {
|
||||||
value, key ->
|
value, key ->
|
||||||
if (key.dest in value) 0 else RangeMapping.Comparator.compare(value, key)
|
if (key.dest in value) 0 else RangeMapping.Comparator.compare(value, key)
|
||||||
})
|
})
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
error("Unmapped label in inlined function $node ${node.line}")
|
error("Unmapped label in inlined function $node ${lineNumber.line}")
|
||||||
}
|
}
|
||||||
LabelAndMapping(node, classSMAP.intervals[index])
|
LabelAndMapping(lineNumber, classSMAP.intervals[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
package test
|
||||||
|
|
||||||
|
inline fun log(lazyMessage: () -> Any?) {
|
||||||
|
lazyMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
inline fun getOrCreate(
|
||||||
|
z : Boolean = false,
|
||||||
|
s: () -> String
|
||||||
|
) {
|
||||||
|
log { s() }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var z = "fail"
|
||||||
|
getOrCreate { z = "OK"; z }
|
||||||
|
|
||||||
|
return z
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
package test
|
||||||
|
|
||||||
|
inline fun log(lazyMessage: () -> Any?) {
|
||||||
|
lazyMessage()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun z(): Boolean {
|
||||||
|
"zzz"
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
inline fun getOrCreate(
|
||||||
|
z : Boolean = z(),
|
||||||
|
s: () -> String
|
||||||
|
) {
|
||||||
|
log { s() }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var z = "fail"
|
||||||
|
getOrCreate { z = "OK"; z }
|
||||||
|
|
||||||
|
return z
|
||||||
|
}
|
||||||
@@ -37,6 +37,17 @@ fun box(): String {
|
|||||||
|
|
||||||
// FILE: 1.smap
|
// FILE: 1.smap
|
||||||
|
|
||||||
|
SMAP
|
||||||
|
1.kt
|
||||||
|
Kotlin
|
||||||
|
*S Kotlin
|
||||||
|
*F
|
||||||
|
+ 1 1.kt
|
||||||
|
test/_1Kt
|
||||||
|
*L
|
||||||
|
1#1,25:1
|
||||||
|
*E
|
||||||
|
|
||||||
// FILE: 2.smap
|
// FILE: 2.smap
|
||||||
|
|
||||||
SMAP
|
SMAP
|
||||||
|
|||||||
@@ -709,6 +709,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt11479.kt")
|
||||||
|
public void testKt11479() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt11479InlinedDefaultParameter.kt")
|
||||||
|
public void testKt11479InlinedDefaultParameter() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479InlinedDefaultParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5685.kt")
|
@TestMetadata("kt5685.kt")
|
||||||
public void testKt5685() throws Exception {
|
public void testKt5685() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt");
|
||||||
|
|||||||
+12
@@ -709,6 +709,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt11479.kt")
|
||||||
|
public void testKt11479() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt11479InlinedDefaultParameter.kt")
|
||||||
|
public void testKt11479InlinedDefaultParameter() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt11479InlinedDefaultParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt5685.kt")
|
@TestMetadata("kt5685.kt")
|
||||||
public void testKt5685() throws Exception {
|
public void testKt5685() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/defaultValues/kt5685.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user