Skip to content

Commit af23f66

Browse files
ilgonmicSpace
authored andcommitted
rrr/1.6.20/ilgonmic/duplicated-signatures
[JS IR] Add tests from master [JS IR] Add test from master [JS IR] Add test with overloading by generic Get rid of duplicated signatures Revert "[JS IR] Consider erasing type parameters in return type in js signatures" This reverts commit 6adcbe0. Revert "rra/ilgonmic/exported-bridges-2 [JS IR] Use js name for signature" This reverts commit 00289d3 [JS IR] Leave as is Merge-request: KT-MR-5967 Merged-by: Ilya Goncharov <[email protected]> ^KT-51700 fixed ^KT-51523 fixed ^KT-51685 fixed
1 parent b687d4c commit af23f66

File tree

7 files changed

+114
-48
lines changed

7 files changed

+114
-48
lines changed

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/JsBridgesConstruction.kt

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,18 @@ package org.jetbrains.kotlin.ir.backend.js.lower
77

88
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
99
import org.jetbrains.kotlin.ir.backend.js.JsLoweredDeclarationOrigin
10-
import org.jetbrains.kotlin.ir.backend.js.utils.eraseGenerics
11-
import org.jetbrains.kotlin.ir.backend.js.utils.getJsNameOrKotlinName
1210
import org.jetbrains.kotlin.ir.backend.js.utils.hasStableJsName
11+
import org.jetbrains.kotlin.ir.backend.js.utils.jsFunctionSignature
1312
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
1413
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
15-
import org.jetbrains.kotlin.ir.types.IrType
16-
import org.jetbrains.kotlin.ir.types.isUnit
17-
import org.jetbrains.kotlin.ir.util.render
18-
import org.jetbrains.kotlin.name.Name
1914

2015
class JsBridgesConstruction(context: JsIrBackendContext) : BridgesConstruction<JsIrBackendContext>(context) {
21-
22-
private fun IrType.getJsInlinedClass() = context.inlineClassesUtils.getInlinedClass(this)
23-
24-
override fun getFunctionSignature(function: IrSimpleFunction): JsSignature =
25-
if (function.hasStableJsName(context)) {
26-
JsStableNameSignature(function.getJsNameOrKotlinName())
27-
} else {
28-
JsNonStableSignature(
29-
function.name,
30-
function.extensionReceiverParameter?.type?.eraseGenerics(context.irBuiltIns),
31-
function.valueParameters.map { it.type.eraseGenerics(context.irBuiltIns) },
32-
function.returnType.takeIf {
33-
it.getJsInlinedClass() != null || it.isUnit()
34-
}?.eraseGenerics(context.irBuiltIns)
35-
)
36-
}
16+
override fun getFunctionSignature(function: IrSimpleFunction): String =
17+
jsFunctionSignature(function, context)
3718

3819
override fun getBridgeOrigin(bridge: IrSimpleFunction): IrDeclarationOrigin =
3920
if (bridge.hasStableJsName(context))
4021
JsLoweredDeclarationOrigin.BRIDGE_WITH_STABLE_NAME
4122
else
4223
JsLoweredDeclarationOrigin.BRIDGE_WITHOUT_STABLE_NAME
4324
}
44-
45-
interface JsSignature {
46-
val name: Name
47-
}
48-
49-
data class JsNonStableSignature(
50-
override val name: Name,
51-
val extensionReceiverType: IrType?,
52-
val valueParametersType: List<IrType>,
53-
val returnType: IrType?,
54-
) : JsSignature {
55-
override fun toString(): String {
56-
val er = extensionReceiverType?.let { "(er: ${it.render()}) " } ?: ""
57-
val parameters = valueParametersType.joinToString(", ") { it.render() }
58-
return "[$er$name($parameters) -> ${returnType?.let { " -> ${it.render()}" } ?: ""}]"
59-
}
60-
}
61-
62-
data class JsStableNameSignature(
63-
override val name: Name,
64-
) : JsSignature

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/NameTables.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import org.jetbrains.kotlin.ir.declarations.*
1313
import org.jetbrains.kotlin.ir.expressions.*
1414
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
1515
import org.jetbrains.kotlin.ir.types.isUnit
16-
import org.jetbrains.kotlin.ir.util.*
16+
import org.jetbrains.kotlin.ir.util.file
17+
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
18+
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
19+
import org.jetbrains.kotlin.ir.util.isInterface
20+
import org.jetbrains.kotlin.ir.util.render
1721
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
1822
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
1923
import org.jetbrains.kotlin.js.common.isES5IdentifierPart
@@ -122,17 +126,22 @@ fun jsFunctionSignature(declaration: IrFunction, context: JsIrBackendContext): S
122126
val nameBuilder = StringBuilder()
123127
nameBuilder.append(declarationName)
124128

129+
// TODO should we skip type parameters and use upper bound of type parameter when print type of value parameters?
130+
declaration.typeParameters.ifNotEmpty {
131+
nameBuilder.append("_\$t")
132+
joinTo(nameBuilder, "") { "_${it.name.asString()}" }
133+
}
125134
declaration.extensionReceiverParameter?.let {
126-
nameBuilder.append("_r$${it.type.eraseGenerics(context.irBuiltIns).asString()}")
135+
nameBuilder.append("_r$${it.type.asString()}")
127136
}
128137
declaration.valueParameters.ifNotEmpty {
129-
joinTo(nameBuilder, "") { "_${it.type.eraseGenerics(context.irBuiltIns).asString()}" }
138+
joinTo(nameBuilder, "") { "_${it.type.asString()}" }
130139
}
131140
declaration.returnType.let {
132141
// Return type is only used in signature for inline class and Unit types because
133142
// they are binary incompatible with supertypes.
134143
if (context.inlineClassesUtils.isTypeInlined(it) || it.isUnit()) {
135-
nameBuilder.append("_ret$${it.eraseGenerics(context.irBuiltIns).asString()}")
144+
nameBuilder.append("_ret$${it.asString()}")
136145
}
137146
}
138147

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/utils/TypeTranformer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// KJS_WITH_FULL_RUNTIME
2+
3+
class L<T>
4+
5+
class A {
6+
fun foo(a: L<Int>) = "Int"
7+
fun foo(a: L<String>) = "String"
8+
fun L<Int>.bar() = "Int2"
9+
fun L<String>.bar() = "String2"
10+
}
11+
12+
fun foo(a: L<Int>) = "Int"
13+
fun foo(a: L<String>) = "String"
14+
15+
private class TestClass {
16+
private val data = mutableListOf<List<Any>>()
17+
fun withData(data: List<List<Any>>) = apply { this.data.addAll(data) }
18+
fun withData(row: List<Any>) = apply {
19+
data.add(row)
20+
}
21+
22+
fun getCols(): Int {
23+
return data.firstOrNull()?.size ?: return 0
24+
}
25+
}
26+
27+
object B {
28+
fun baz(vararg v: B) = "[A]"
29+
30+
fun baz(vararg v: String) = "[S]"
31+
}
32+
33+
class C<in T> {
34+
fun bac(c: T): String {
35+
return "T4"
36+
}
37+
38+
fun bac(c: Int): String {
39+
return "Int5"
40+
}
41+
42+
fun bac(c: List<T>): String {
43+
return "ListT4"
44+
}
45+
46+
fun bac(c: List<Int>): String {
47+
return "ListInt4"
48+
}
49+
50+
fun bac(c: List<*>): String {
51+
return "ListStar4"
52+
}
53+
}
54+
55+
fun box(): String {
56+
if (A().foo(L<Int>()) != "Int") return "fail1"
57+
A().apply {
58+
if (L<Int>().bar() != "Int2") return "fail2"
59+
}
60+
if (foo(L<Int>()) != "Int") return "fail3"
61+
62+
val b = TestClass()
63+
val data = mutableListOf<List<Any>>()
64+
data.add(listOf("a", "b", "c"))
65+
data.add(listOf("d", "e", "f"))
66+
b.withData(data)
67+
if (b.getCols() != 3) return "fail4"
68+
69+
if (B.baz(B) != "[A]") return "fail5"
70+
if (B.baz("a") != "[S]") return "fail6"
71+
72+
if(C<String>().bac("a") != "T4") return "fail7"
73+
if(C<String>().bac(5) != "Int5") return "fail8"
74+
if(C<String>().bac(listOf("a", "b")) != "ListT4") return "fail9"
75+
if(C<String>().bac(listOf(5, 6)) != "ListInt4") return "fail10"
76+
if(C<String>().bac(listOf(Any(), Any())) != "ListStar4") return "fail11"
77+
78+
return "OK"
79+
}

native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/ExternalTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)