[IrFakeOverrideBuilder] Do not compute signatures in Fir2IR
No one need them, while it requires significant time usage ^KT-66281 ^KT-66441 Fixed
This commit is contained in:
committed by
Space Team
parent
5779465366
commit
1222ef7fac
@@ -728,7 +728,7 @@ class Fir2IrConverter(
|
||||
{ irBuiltins ->
|
||||
IrFakeOverrideBuilder(
|
||||
typeContextProvider(irBuiltins),
|
||||
Fir2IrFakeOverrideStrategy(friendModulesMap(session), commonMemberStorage.symbolTable, irMangler),
|
||||
Fir2IrFakeOverrideStrategy(friendModulesMap(session)),
|
||||
fir2IrExtensions.externalOverridabilityConditions
|
||||
)
|
||||
},
|
||||
|
||||
+1
-75
@@ -5,82 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.backend
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.PublicIdSignatureComputer
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunctionWithLateBinding
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPropertyWithLateBinding
|
||||
import org.jetbrains.kotlin.ir.overrides.FakeOverrideBuilderStrategy
|
||||
import org.jetbrains.kotlin.ir.overrides.IrUnimplementedOverridesStrategy.ProcessAsFakeOverrides
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertyPublicSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.KotlinMangler
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
|
||||
|
||||
internal class Fir2IrFakeOverrideStrategy(
|
||||
friendModules: Map<String, List<String>>,
|
||||
val symbolTable: SymbolTable,
|
||||
val mangler: KotlinMangler.IrMangler
|
||||
) : FakeOverrideBuilderStrategy(
|
||||
friendModules = friendModules,
|
||||
unimplementedOverridesStrategy = ProcessAsFakeOverrides
|
||||
) {
|
||||
private val publicIdSignatureComputer = PublicIdSignatureComputer(mangler)
|
||||
override fun linkFunctionFakeOverride(function: IrFunctionWithLateBinding, manglerCompatibleMode: Boolean) {
|
||||
with(mangler) {
|
||||
if (function.isExported(manglerCompatibleMode)) {
|
||||
val signature = publicIdSignatureComputer.composePublicIdSignature(function, manglerCompatibleMode)
|
||||
symbolTable.declareSimpleFunction(
|
||||
signature,
|
||||
{ IrSimpleFunctionPublicSymbolImpl(signature, descriptor = null) },
|
||||
{ function.acquireSymbol(it) }
|
||||
)
|
||||
} else {
|
||||
function.acquireSymbol(IrSimpleFunctionSymbolImpl())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun linkPropertyFakeOverride(property: IrPropertyWithLateBinding, manglerCompatibleMode: Boolean) {
|
||||
with(mangler) {
|
||||
if (property.isExported(manglerCompatibleMode)) {
|
||||
// The signature composer expects getter/setter correspondingPropertySymbol to be set correctly.
|
||||
// But we don't have any property symbol for now. To work around this problem, we are creating a temporary one,
|
||||
// and throw it away after computing signature.
|
||||
val tempSymbol = IrPropertySymbolImpl(null).apply { bind(property) }
|
||||
property.getter?.let { it.correspondingPropertySymbol = tempSymbol }
|
||||
property.setter?.let { it.correspondingPropertySymbol = tempSymbol }
|
||||
val signature = publicIdSignatureComputer.composePublicIdSignature(property, manglerCompatibleMode)
|
||||
property.getter?.let { it.correspondingPropertySymbol = null }
|
||||
property.setter?.let { it.correspondingPropertySymbol = null }
|
||||
symbolTable.declareProperty(
|
||||
signature,
|
||||
{ IrPropertyPublicSymbolImpl(signature, descriptor = null) },
|
||||
{ property.acquireSymbol(it) }
|
||||
)
|
||||
} else {
|
||||
property.acquireSymbol(IrPropertySymbolImpl())
|
||||
}
|
||||
}
|
||||
|
||||
property.getter?.let {
|
||||
it.correspondingPropertySymbol = property.symbol
|
||||
linkFunctionFakeOverride(
|
||||
it as? IrFunctionWithLateBinding ?: error("Unexpected fake override getter: $it"),
|
||||
manglerCompatibleMode
|
||||
)
|
||||
}
|
||||
property.setter?.let {
|
||||
it.correspondingPropertySymbol = property.symbol
|
||||
linkFunctionFakeOverride(
|
||||
it as? IrFunctionWithLateBinding ?: error("Unexpected fake override setter: $it"),
|
||||
manglerCompatibleMode
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <R> inFile(file: IrFile?, block: () -> R): R =
|
||||
publicIdSignatureComputer.inFile(file?.symbol, block)
|
||||
}
|
||||
) : FakeOverrideBuilderStrategy.BindToPrivateSymbols(friendModules)
|
||||
+26
@@ -10,6 +10,8 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrPropertySymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
@@ -131,6 +133,30 @@ abstract class FakeOverrideBuilderStrategy(
|
||||
* * [IrFunctionWithLateBinding.acquireSymbol] must be called inside on getter and setter of [property] argument, if they exist
|
||||
*/
|
||||
protected abstract fun linkPropertyFakeOverride(property: IrPropertyWithLateBinding, manglerCompatibleMode: Boolean)
|
||||
|
||||
abstract class BindToPrivateSymbols(friendModules: Map<String, Collection<String>>) : FakeOverrideBuilderStrategy(
|
||||
friendModules = friendModules,
|
||||
unimplementedOverridesStrategy = IrUnimplementedOverridesStrategy.ProcessAsFakeOverrides
|
||||
) {
|
||||
override fun linkFunctionFakeOverride(function: IrFunctionWithLateBinding, manglerCompatibleMode: Boolean) {
|
||||
function.acquireSymbol(IrSimpleFunctionSymbolImpl())
|
||||
}
|
||||
|
||||
override fun linkPropertyFakeOverride(property: IrPropertyWithLateBinding, manglerCompatibleMode: Boolean) {
|
||||
property.acquireSymbol(IrPropertySymbolImpl())
|
||||
|
||||
property.getter?.let {
|
||||
it.correspondingPropertySymbol = property.symbol
|
||||
linkFunctionFakeOverride(it as? IrFunctionWithLateBinding ?: error("Unexpected fake override getter: $it"), manglerCompatibleMode)
|
||||
}
|
||||
property.setter?.let {
|
||||
it.correspondingPropertySymbol = property.symbol
|
||||
linkFunctionFakeOverride(it as? IrFunctionWithLateBinding ?: error("Unexpected fake override setter: $it"), manglerCompatibleMode)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <R> inFile(file: IrFile?, block: () -> R): R = block()
|
||||
}
|
||||
}
|
||||
|
||||
fun buildFakeOverrideMember(
|
||||
|
||||
@@ -1280,40 +1280,16 @@ val IrFunction.allParameters: List<IrValueParameter>
|
||||
val IrFunction.allParametersCount: Int
|
||||
get() = if (this is IrConstructor) explicitParametersCount + 1 else explicitParametersCount
|
||||
|
||||
private object BindToNewEmptySymbols : FakeOverrideBuilderStrategy(
|
||||
private object LoweringsFakeOverrideBuilderStrategy : FakeOverrideBuilderStrategy.BindToPrivateSymbols(
|
||||
friendModules = emptyMap(), // TODO: this is probably not correct. Should be fixed by KT-61384. But it's not important for current usages
|
||||
unimplementedOverridesStrategy = IrUnimplementedOverridesStrategy.ProcessAsFakeOverrides
|
||||
) {
|
||||
override fun linkFunctionFakeOverride(function: IrFunctionWithLateBinding, manglerCompatibleMode: Boolean) {
|
||||
function.acquireSymbol(IrSimpleFunctionSymbolImpl())
|
||||
}
|
||||
|
||||
override fun linkPropertyFakeOverride(property: IrPropertyWithLateBinding, manglerCompatibleMode: Boolean) {
|
||||
val propertySymbol = IrPropertySymbolImpl()
|
||||
property.getter?.let { it.correspondingPropertySymbol = propertySymbol }
|
||||
property.setter?.let { it.correspondingPropertySymbol = propertySymbol }
|
||||
|
||||
property.acquireSymbol(propertySymbol)
|
||||
|
||||
property.getter?.let {
|
||||
it.correspondingPropertySymbol = property.symbol
|
||||
linkFunctionFakeOverride(it as? IrFunctionWithLateBinding ?: error("Unexpected fake override getter: $it"), manglerCompatibleMode)
|
||||
}
|
||||
property.setter?.let {
|
||||
it.correspondingPropertySymbol = property.symbol
|
||||
linkFunctionFakeOverride(it as? IrFunctionWithLateBinding ?: error("Unexpected fake override setter: $it"), manglerCompatibleMode)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <R> inFile(file: IrFile?, block: () -> R): R = block()
|
||||
}
|
||||
)
|
||||
|
||||
fun IrClass.addFakeOverrides(
|
||||
typeSystem: IrTypeSystemContext,
|
||||
implementedMembers: List<IrOverridableMember> = emptyList(),
|
||||
ignoredParentSymbols: List<IrSymbol> = emptyList()
|
||||
) {
|
||||
val fakeOverrides = IrFakeOverrideBuilder(typeSystem, BindToNewEmptySymbols, emptyList())
|
||||
val fakeOverrides = IrFakeOverrideBuilder(typeSystem, LoweringsFakeOverrideBuilderStrategy, emptyList())
|
||||
.buildFakeOverridesForClassUsingOverriddenSymbols(this, implementedMembers, compatibilityMode = false, ignoredParentSymbols)
|
||||
for (fakeOverride in fakeOverrides) {
|
||||
addChild(fakeOverride)
|
||||
|
||||
+4
-4
@@ -2,14 +2,14 @@
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
expect class Foo1
|
||||
expect class Foo2
|
||||
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo1<!>
|
||||
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect class Foo2<!>
|
||||
|
||||
expect fun foo2(): Int
|
||||
|
||||
expect val s: String
|
||||
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect val s: String<!>
|
||||
|
||||
expect open class Foo3
|
||||
<!EXPECT_ACTUAL_INCOMPATIBILITY{JVM}!>expect open class Foo3<!>
|
||||
|
||||
// MODULE: m2-jvm()()(m1-common)
|
||||
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// MODULE: m1-common
|
||||
// FILE: common.kt
|
||||
|
||||
expect class Foo1
|
||||
expect class Foo2
|
||||
|
||||
expect fun foo2(): Int
|
||||
|
||||
expect val s: String
|
||||
|
||||
expect open class Foo3
|
||||
|
||||
// MODULE: m2-jvm()()(m1-common)
|
||||
|
||||
// FILE: jvm.kt
|
||||
|
||||
interface <!ACTUAL_MISSING!>Foo1<!>
|
||||
actual interface <!ACTUAL_WITHOUT_EXPECT!>Foo2<!>
|
||||
|
||||
actual var <!ACTUAL_WITHOUT_EXPECT!>s<!>: String = "value"
|
||||
|
||||
fun <!ACTUAL_MISSING!>foo2<!>(): Int = 0
|
||||
|
||||
actual class <!ACTUAL_WITHOUT_EXPECT, PACKAGE_OR_CLASSIFIER_REDECLARATION!>Foo3<!>
|
||||
|
||||
class <!ACTUAL_MISSING, PACKAGE_OR_CLASSIFIER_REDECLARATION!>Foo3<!>
|
||||
Reference in New Issue
Block a user