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
+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