[FIR] Fix computing mangled names for top-level functions and properties

^KT-57433 Fixed
This commit is contained in:
Sergej Jaskiewicz
2023-05-30 19:57:10 +02:00
committed by Space Team
parent 1eb0862820
commit 5f59de23c5
11 changed files with 9 additions and 50 deletions
@@ -7,13 +7,10 @@ package org.jetbrains.kotlin.fir.backend.jvm
import org.jetbrains.kotlin.backend.common.serialization.mangle.MangleMode
import org.jetbrains.kotlin.fir.backend.FirMangleComputer
import org.jetbrains.kotlin.fir.containingClassLookupTag
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.java.declarations.FirJavaField
import org.jetbrains.kotlin.fir.originalForSubstitutionOverride
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.types.coneType
@@ -24,7 +21,7 @@ class FirJvmMangleComputer(
builder: StringBuilder,
mode: MangleMode,
) : FirMangleComputer(builder, mode) {
override val visitor = JvmVisitor()
override val visitor: Visitor = JvmVisitor()
override fun FirFunction.platformSpecificSuffix(): String? =
if (this is FirSimpleFunction && name.asString() == "main")
@@ -36,26 +33,6 @@ class FirJvmMangleComputer(
override fun copy(newMode: MangleMode): FirJvmMangleComputer =
FirJvmMangleComputer(builder, newMode)
// FIXME this implementation causes the mangler to deliver different result than IR mangler. Consider using base method instead
override fun FirDeclaration.visitParent() {
val (parentPackageFqName, parentClassId) = when (this) {
is FirCallableDeclaration -> this.containingClassLookupTag()?.classId?.let { it.packageFqName to it } ?: return
is FirClassLikeDeclaration -> this.symbol.classId.let { it.packageFqName to it.outerClassId }
else -> return
}
if (parentClassId != null && !parentClassId.isLocal) {
val parentClassLike = this.moduleData.session.symbolProvider.getClassLikeSymbolByClassId(parentClassId)?.fir
?: error("Attempt to find parent ($parentClassId) for probably-local declaration!")
if (parentClassLike is FirRegularClass || parentClassLike is FirTypeAlias) {
parentClassLike.visit()
} else {
error("Strange class-like declaration: ${parentClassLike.render()}")
}
} else if (parentClassId == null && !parentPackageFqName.isRoot) {
builder.appendName(parentPackageFqName.asString())
}
}
// FIXME this implementation causes the mangler to deliver different result than IR mangler. Consider using base method instead
override fun getEffectiveParent(typeParameter: ConeTypeParameterLookupTag): FirMemberDeclaration = typeParameter.symbol.fir.run {
@@ -78,7 +55,7 @@ class FirJvmMangleComputer(
throw IllegalStateException("Should not be here!")
}
protected inner class JvmVisitor : Visitor() {
private inner class JvmVisitor : Visitor() {
override fun visitField(field: FirField) {
if (field is FirJavaField) {
field.mangleSimpleDeclaration(field.name.asString())
-3
View File
@@ -2,9 +2,6 @@
// IGNORE_BACKEND_K1: JS_IR
// IGNORE_BACKEND_K1: JS_IR_ES6
// MUTE_SIGNATURE_COMPARISON_K2: ANY
// ^ KT-57433
// MODULE: a
// FILE: a.kt
package a
@@ -13,6 +13,9 @@ package b
// CHECK JVM_IR:
// Mangled name: b#foo(kotlin.Function0<kotlin.String>){}kotlin.String
// Public signature: b/foo|-5020381652845254261[0]
// CHECK JS_IR NATIVE:
// Mangled name: b#foo(kotlin.Function0<kotlin.String>){}
// Public signature: b/foo|-2695324588787180624[0]
fun foo(f: Function0<String>): String
// MODULE: c
@@ -21,5 +24,8 @@ fun foo(f: Function0<String>): String
// CHECK JVM_IR:
// Mangled name: #box(){}kotlin.String
// Public signature: /box|-9347091776561469[0]
// CHECK JS_IR NATIVE:
// Mangled name: #box(){}
// Public signature: /box|2173511048851971368[0]
fun box(): String
@@ -2,9 +2,6 @@
// TARGET_BACKEND: JVM
// SKIP_KT_DUMP
// MUTE_SIGNATURE_COMPARISON_K2: ANY
// ^ KT-57433
// FILE: box.kt
package k
@@ -2,9 +2,6 @@
// SKIP_KLIB_TEST
// Related to KT-49507
// MUTE_SIGNATURE_COMPARISON_K2: ANY
// ^ KT-57433
// FILE: A.java
public class A {
protected String x = "1";
@@ -1,8 +1,5 @@
// FIR_IDENTICAL
// MUTE_SIGNATURE_COMPARISON_K2: JVM_IR
// ^ KT-57433
// FILE: test.kt
package test
@@ -1,6 +1,3 @@
// MUTE_SIGNATURE_COMPARISON_K2: JVM_IR
// ^ KT-57433
package test
inline fun foo(x: () -> Unit) {}
@@ -1,7 +1,7 @@
// FIR_IDENTICAL
// MUTE_SIGNATURE_COMPARISON_K2: JVM_IR
// ^ KT-57433, KT-57429
// ^ KT-57429
package test
@@ -1,8 +1,5 @@
// FIR_IDENTICAL
// MUTE_SIGNATURE_COMPARISON_K2: JVM_IR
// ^ KT-57433
package test
import test.Foo.a
@@ -1,8 +1,5 @@
// FIR_IDENTICAL
// MUTE_SIGNATURE_COMPARISON_K2: JVM_IR
// ^ KT-57433
package test
import test.Host.foo
@@ -1,6 +1,3 @@
// MUTE_SIGNATURE_COMPARISON_K2: JVM_IR
// ^ KT-57433
package test
class C