[Common IR] Do not add internal methods to overrides
[JS IR] Use a module name in JsFunctionSignature for internal methods ^KT-60635 Fixed
This commit is contained in:
committed by
Space Team
parent
788fa5d545
commit
7a31167e0b
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
|
||||
|
||||
object JsLoweredDeclarationOrigin {
|
||||
@@ -18,4 +19,11 @@ object JsLoweredDeclarationOrigin {
|
||||
object JS_SUPER_CONTEXT_PARAMETER : IrDeclarationOriginImpl("JS_SUPER_CONTEXT_PARAMETER")
|
||||
object JS_SHADOWED_DEFAULT_PARAMETER : IrDeclarationOriginImpl("JS_SHADOWED_DEFAULT_PARAMETER")
|
||||
object ENUM_GET_INSTANCE_FUNCTION : IrDeclarationOriginImpl("ENUM_GET_INSTANCE_FUNCTION")
|
||||
|
||||
fun isBridgeDeclarationOrigin(origin: IrDeclarationOrigin) = when (origin) {
|
||||
is BRIDGE_WITH_STABLE_NAME -> true
|
||||
is BRIDGE_WITHOUT_STABLE_NAME -> true
|
||||
is BRIDGE_PROPERTY_ACCESSOR -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.utils.memoryOptimizedPlus
|
||||
import org.jetbrains.kotlin.utils.toSmartList
|
||||
|
||||
/**
|
||||
* Constructs bridges for inherited generic functions
|
||||
@@ -148,7 +149,10 @@ abstract class BridgesConstruction<T : JsCommonBackendContext>(val context: T) :
|
||||
annotations = annotations memoryOptimizedPlus bridge.annotations
|
||||
// the js function signature building process (jsFunctionSignature()) uses dfs throught overriddenSymbols for getting js name,
|
||||
// therefore it is very important to put bridge symbol at the beginning, it allows to get correct js function name
|
||||
overriddenSymbols = overriddenSymbols memoryOptimizedPlus bridge.symbol memoryOptimizedPlus delegateTo.overriddenSymbols
|
||||
overriddenSymbols = mutableSetOf(bridge.symbol).also {
|
||||
it.addAll(overriddenSymbols)
|
||||
it.addAll(delegateTo.overriddenSymbols)
|
||||
}.toSmartList()
|
||||
}
|
||||
|
||||
irFunction.body = context.irFactory.createBlockBody(UNDEFINED_OFFSET, UNDEFINED_OFFSET) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.utils
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities.INTERNAL
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsLoweredDeclarationOrigin
|
||||
@@ -123,12 +124,28 @@ private fun List<IrType>.joinTypes(context: JsIrBackendContext): String {
|
||||
return joinToString("$", "$") { superType -> superType.asString(context) }
|
||||
}
|
||||
|
||||
private fun IrFunction.findOriginallyContainingModule(): IrModuleFragment? {
|
||||
if (JsLoweredDeclarationOrigin.isBridgeDeclarationOrigin(origin)) {
|
||||
val thisSimpleFunction = this as? IrSimpleFunction ?: error("Bridge must be IrSimpleFunction")
|
||||
val bridgeFrom = thisSimpleFunction.overriddenSymbols.firstOrNull() ?: error("Couldn't find the overridden function for the bridge")
|
||||
return bridgeFrom.owner.findOriginallyContainingModule()
|
||||
}
|
||||
return (getPackageFragment() as? IrFile)?.module
|
||||
}
|
||||
|
||||
fun calculateJsFunctionSignature(declaration: IrFunction, context: JsIrBackendContext): String {
|
||||
val declarationName = declaration.nameIfPropertyAccessor() ?: declaration.getJsNameOrKotlinName().asString()
|
||||
|
||||
val nameBuilder = StringBuilder()
|
||||
nameBuilder.append(declarationName)
|
||||
|
||||
if (declaration.visibility === INTERNAL && declaration.parentClassOrNull != null) {
|
||||
val containingModule = declaration.findOriginallyContainingModule()
|
||||
if (containingModule != null) {
|
||||
nameBuilder.append("_\$m_").append(containingModule.name.toString())
|
||||
}
|
||||
}
|
||||
|
||||
// TODO should we skip type parameters and use upper bound of type parameter when print type of value parameters?
|
||||
declaration.typeParameters.ifNotEmpty {
|
||||
nameBuilder.append("_\$t")
|
||||
|
||||
Reference in New Issue
Block a user