JVM IR: More precise check for calls to the implementation method in a default stub
This commit is contained in:
committed by
max-kammerer
parent
648bc9b1c4
commit
3a7cc93c4e
Generated
+5
@@ -9450,6 +9450,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/protected.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveDefaultArguments.kt")
|
||||
public void testRecursiveDefaultArguments() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceAsArg.kt")
|
||||
public void testReferenceAsArg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/referenceAsArg.kt");
|
||||
|
||||
+3
-1
@@ -178,12 +178,14 @@ open class DefaultArgumentStubGenerator(
|
||||
return createTmpVariable(value, nameHint = parameter.name.asString())
|
||||
}
|
||||
|
||||
protected open fun getOriginForCallToImplementation(): IrStatementOrigin? = null
|
||||
|
||||
private fun IrBlockBodyBuilder.dispatchToImplementation(
|
||||
irFunction: IrSimpleFunction,
|
||||
newIrFunction: IrFunction,
|
||||
params: MutableList<IrValueDeclaration>
|
||||
): IrExpression {
|
||||
val dispatchCall = irCall(irFunction.symbol).apply {
|
||||
val dispatchCall = irCall(irFunction, origin = getOriginForCallToImplementation()).apply {
|
||||
passTypeArgumentsFrom(newIrFunction)
|
||||
dispatchReceiver = newIrFunction.dispatchReceiverParameter?.let { irGet(it) }
|
||||
extensionReceiver = newIrFunction.extensionReceiverParameter?.let { irGet(it) }
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOriginImpl
|
||||
|
||||
interface JvmLoweredStatementOrigin {
|
||||
object DEFAULT_STUB_CALL_TO_IMPLEMENTATION : IrStatementOriginImpl("DEFAULT_STUB_CALL_TO_IMPLEMENTATION")
|
||||
}
|
||||
+2
-1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.jvm.codegen
|
||||
import org.jetbrains.kotlin.backend.common.lower.BOUND_RECEIVER_PARAMETER
|
||||
import org.jetbrains.kotlin.backend.common.lower.SYNTHESIZED_INIT_BLOCK
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.JavaClassProperty
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.MultifileFacadeFileEntry
|
||||
@@ -1174,7 +1175,7 @@ class ExpressionCodegen(
|
||||
return IrCallGenerator.DefaultCallGenerator
|
||||
}
|
||||
|
||||
if (irFunction == context.mapping.defaultArgumentsDispatchFunction[element.symbol.owner]) {
|
||||
if (element.origin == JvmLoweredStatementOrigin.DEFAULT_STUB_CALL_TO_IMPLEMENTATION) {
|
||||
return IrInlineDefaultCodegen
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.common.lower.irNot
|
||||
import org.jetbrains.kotlin.backend.common.lower.irThrow
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getJvmVisibilityOfDefaultArgumentStub
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -75,4 +76,7 @@ class JvmDefaultArgumentStubGenerator(override val context: JvmBackendContext) :
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// Since the call to the underlying implementation in a default stub has different inlining behavior we need to mark it.
|
||||
override fun getOriginForCallToImplementation() = JvmLoweredStatementOrigin.DEFAULT_STUB_CALL_TO_IMPLEMENTATION
|
||||
}
|
||||
|
||||
+9
-1
@@ -43,7 +43,15 @@ class ResolveInlineCalls(val context: JvmBackendContext) : IrElementTransformerV
|
||||
maybeFakeOverrideOfMultiFileBridge.resolveMultiFileFacades() ?: maybeFakeOverrideOfMultiFileBridge.resolveFakeOverride()
|
||||
?: return super.visitCall(expression)
|
||||
return super.visitCall(with(expression) {
|
||||
IrCallImpl(startOffset, endOffset, type, resolved.symbol, expression.typeArgumentsCount, null, superQualifierSymbol).apply {
|
||||
IrCallImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
type,
|
||||
resolved.symbol,
|
||||
expression.typeArgumentsCount,
|
||||
expression.origin,
|
||||
superQualifierSymbol
|
||||
).apply {
|
||||
copyTypeAndValueArgumentsFrom(expression)
|
||||
dispatchReceiver?.let { receiver ->
|
||||
val receiverType = resolved.parentAsClass.defaultType
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR
|
||||
@Suppress("RECURSION_IN_INLINE")
|
||||
inline fun test(p: String = test("OK")): String {
|
||||
return p
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return test()
|
||||
}
|
||||
+5
@@ -10845,6 +10845,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/protected.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveDefaultArguments.kt")
|
||||
public void testRecursiveDefaultArguments() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceAsArg.kt")
|
||||
public void testReferenceAsArg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/referenceAsArg.kt");
|
||||
|
||||
+5
@@ -10845,6 +10845,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/protected.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveDefaultArguments.kt")
|
||||
public void testRecursiveDefaultArguments() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceAsArg.kt")
|
||||
public void testReferenceAsArg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/referenceAsArg.kt");
|
||||
|
||||
+5
@@ -9450,6 +9450,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/protected.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveDefaultArguments.kt")
|
||||
public void testRecursiveDefaultArguments() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceAsArg.kt")
|
||||
public void testReferenceAsArg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/referenceAsArg.kt");
|
||||
|
||||
Generated
+5
@@ -8020,6 +8020,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/protected.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveDefaultArguments.kt")
|
||||
public void testRecursiveDefaultArguments() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceAsArg.kt")
|
||||
public void testReferenceAsArg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/referenceAsArg.kt");
|
||||
|
||||
Generated
+5
@@ -8020,6 +8020,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/protected.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveDefaultArguments.kt")
|
||||
public void testRecursiveDefaultArguments() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceAsArg.kt")
|
||||
public void testReferenceAsArg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/referenceAsArg.kt");
|
||||
|
||||
+5
@@ -8020,6 +8020,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/protected.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("recursiveDefaultArguments.kt")
|
||||
public void testRecursiveDefaultArguments() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/recursiveDefaultArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("referenceAsArg.kt")
|
||||
public void testReferenceAsArg() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/defaultArguments/referenceAsArg.kt");
|
||||
|
||||
Reference in New Issue
Block a user