Fix issue #KT-24475
* count coroutine metadata references during RemoveUnusedImport pass in JsInliner * add cases to test usage of stdlib symbols in inlined functions
This commit is contained in:
committed by
Roman Artemev
parent
75c7045ea7
commit
14b1f0ef6a
@@ -0,0 +1,50 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_COROUTINES
|
||||
// WITH_RUNTIME
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
// MODULE: lib(support)
|
||||
// FILE: lib.kt
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
import COROUTINES_PACKAGE.intrinsics.*
|
||||
|
||||
suspend inline fun <R> inlined(
|
||||
crossinline step: suspend () -> R
|
||||
): R = notInlined { step() }
|
||||
|
||||
suspend fun <R> notInlined(
|
||||
block: suspend () -> R
|
||||
): R = block()
|
||||
|
||||
// MODULE: main(lib, support)
|
||||
// FILE: main.kt
|
||||
// WITH_COROUTINES
|
||||
// WITH_RUNTIME
|
||||
// COMMON_COROUTINES_TEST
|
||||
|
||||
import helpers.*
|
||||
import COROUTINES_PACKAGE.*
|
||||
import COROUTINES_PACKAGE.intrinsics.*
|
||||
|
||||
var result = "FAIL"
|
||||
|
||||
suspend fun test() {
|
||||
inlined {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
builder {
|
||||
test()
|
||||
}
|
||||
return result
|
||||
}
|
||||
Generated
+10
@@ -7033,6 +7033,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithOptionalParam.kt")
|
||||
public void testInlineFunctionWithOptionalParam_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineFunctionWithOptionalParam.kt", "kotlin.coroutines.experimental");
|
||||
|
||||
+10
@@ -7033,6 +7033,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithOptionalParam.kt")
|
||||
public void testInlineFunctionWithOptionalParam_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineFunctionWithOptionalParam.kt", "kotlin.coroutines.experimental");
|
||||
|
||||
+10
@@ -7033,6 +7033,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithOptionalParam.kt")
|
||||
public void testInlineFunctionWithOptionalParam_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineFunctionWithOptionalParam.kt", "kotlin.coroutines.experimental");
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.js.inline.clean
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.coroutineMetadata
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.imported
|
||||
|
||||
fun removeUnusedImports(root: JsNode) {
|
||||
@@ -43,4 +44,12 @@ private class UsedImportsCollector : RecursiveJsVisitor() {
|
||||
}
|
||||
super.visitNameRef(nameRef)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitFunction(x: JsFunction) {
|
||||
x.coroutineMetadata?.apply {
|
||||
accept(suspendObjectRef)
|
||||
accept(baseClassRef)
|
||||
}
|
||||
super.visitFunction(x)
|
||||
}
|
||||
}
|
||||
+5
@@ -4599,6 +4599,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/inlineMultiModule/importObjectInstance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("importStdLib.kt")
|
||||
public void testImportStdLib() throws Exception {
|
||||
runTest("js/js.translator/testData/box/inlineMultiModule/importStdLib.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineInInlineWithLambdaMultiModule.kt")
|
||||
public void testInlineInInlineWithLambdaMultiModule() throws Exception {
|
||||
runTest("js/js.translator/testData/box/inlineMultiModule/inlineInInlineWithLambdaMultiModule.kt");
|
||||
|
||||
+5
@@ -4599,6 +4599,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/inlineMultiModule/importObjectInstance.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("importStdLib.kt")
|
||||
public void testImportStdLib() throws Exception {
|
||||
runTest("js/js.translator/testData/box/inlineMultiModule/importStdLib.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineInInlineWithLambdaMultiModule.kt")
|
||||
public void testInlineInInlineWithLambdaMultiModule() throws Exception {
|
||||
runTest("js/js.translator/testData/box/inlineMultiModule/inlineInInlineWithLambdaMultiModule.kt");
|
||||
|
||||
+5
@@ -5963,6 +5963,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithOptionalParam.kt")
|
||||
public void testInlineFunctionWithOptionalParam_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineFunctionWithOptionalParam.kt", "kotlin.coroutines.experimental");
|
||||
|
||||
+10
@@ -6738,6 +6738,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/coroutines/multiModule"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines.experimental");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineCrossModule.kt")
|
||||
public void testInlineCrossModule_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineCrossModule.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineFunctionWithOptionalParam.kt")
|
||||
public void testInlineFunctionWithOptionalParam_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/multiModule/inlineFunctionWithOptionalParam.kt", "kotlin.coroutines.experimental");
|
||||
|
||||
+5
-2
@@ -27,7 +27,10 @@ import org.jetbrains.kotlin.js.backend.ast.metadata.coroutineMetadata
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.isInlineableCoroutineBody
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.shouldBeExported
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.expression.*
|
||||
import org.jetbrains.kotlin.js.translate.expression.InlineMetadata
|
||||
import org.jetbrains.kotlin.js.translate.expression.translateAndAliasParameters
|
||||
import org.jetbrains.kotlin.js.translate.expression.translateFunction
|
||||
import org.jetbrains.kotlin.js.translate.expression.wrapWithInlineMetadata
|
||||
import org.jetbrains.kotlin.js.translate.general.TranslatorVisitor
|
||||
import org.jetbrains.kotlin.js.translate.utils.*
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -123,7 +126,7 @@ abstract class AbstractDeclarationVisitor : TranslatorVisitor<Unit>() {
|
||||
val innerContext = context.newDeclaration(descriptor).translateAndAliasParameters(descriptor, function.parameters)
|
||||
|
||||
if (descriptor.isSuspend) {
|
||||
function.fillCoroutineMetadata(context, descriptor, hasController = false)
|
||||
function.fillCoroutineMetadata(innerContext, descriptor, hasController = false)
|
||||
}
|
||||
|
||||
if (!descriptor.isOverridable) {
|
||||
|
||||
@@ -167,15 +167,13 @@ fun JsFunction.fillCoroutineMetadata(
|
||||
.memberScope
|
||||
.getContributedVariables(COROUTINE_SUSPENDED_NAME, NoLookupLocation.FROM_BACKEND).first()
|
||||
|
||||
val coroutineBaseClassRef = ReferenceTranslator.translateAsTypeReference(TranslationUtils.getCoroutineBaseClass(context), context)
|
||||
|
||||
fun getCoroutinePropertyName(id: String) =
|
||||
context.getNameForDescriptor(TranslationUtils.getCoroutineProperty(context, id))
|
||||
|
||||
coroutineMetadata = CoroutineMetadata(
|
||||
doResumeName = context.getNameForDescriptor(TranslationUtils.getCoroutineDoResumeFunction(context)),
|
||||
suspendObjectRef = ReferenceTranslator.translateAsValueReference(suspendPropertyDescriptor, context),
|
||||
baseClassRef = coroutineBaseClassRef,
|
||||
baseClassRef = ReferenceTranslator.translateAsTypeReference(TranslationUtils.getCoroutineBaseClass(context), context),
|
||||
stateName = getCoroutinePropertyName("state"),
|
||||
exceptionStateName = getCoroutinePropertyName("exceptionState"),
|
||||
finallyPathName = getCoroutinePropertyName("finallyPath"),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1117
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
|
||||
inline fun foo(i1: Int, i2: Double): Int {
|
||||
val o = object : Comparable<Int> {
|
||||
override fun compareTo(other: Int) = i1-other
|
||||
}
|
||||
|
||||
return o.compareTo(i2.toInt())
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
fun bar(i: Int):Int {
|
||||
class Cmp2() : Comparable<Int> {
|
||||
override fun compareTo(other: Int) = -other
|
||||
}
|
||||
|
||||
return Cmp2().compareTo(i)
|
||||
}
|
||||
|
||||
fun box():String {
|
||||
if (foo(10, 20.0) + bar(-10) != 0) return "FAIL"
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user