[FIR2IR] Remove linkViaSignatures from Fir2IrConfiguration

^KT-64809 Fixed
This commit is contained in:
Sergej Jaskiewicz
2024-01-15 18:27:50 +01:00
committed by Space Team
parent e8aa05928d
commit 8b4cc050eb
8 changed files with 28 additions and 100 deletions
@@ -267,7 +267,7 @@ internal class KtFirCompilerFacility(
fir2IrExtensions,
fir2IrConfiguration,
irGeneratorExtensions,
signatureComposerForJvmFir2Ir(fir2IrConfiguration.linkViaSignatures),
signatureComposerForJvmFir2Ir(),
JvmIrMangler,
FirJvmKotlinMangler(),
FirJvmVisibilityConverter,
@@ -38,11 +38,9 @@ import org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleResolver
import org.jetbrains.kotlin.codegen.ClassBuilderFactories
import org.jetbrains.kotlin.codegen.CodegenFactory
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.config.languageVersionSettings
import org.jetbrains.kotlin.constant.EvaluatedConstTracker
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector
import org.jetbrains.kotlin.fir.backend.Fir2IrConfiguration
@@ -205,7 +203,7 @@ fun FirResult.convertToIrAndActualizeForJvm(
fir2IrExtensions,
fir2IrConfiguration,
irGeneratorExtensions,
signatureComposerForJvmFir2Ir(fir2IrConfiguration.linkViaSignatures),
signatureComposerForJvmFir2Ir(),
JvmIrMangler,
FirJvmKotlinMangler(),
FirJvmVisibilityConverter,
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.backend.common.actualizer.SpecialFakeOverrideSymbols
import org.jetbrains.kotlin.backend.common.actualizer.SpecialFakeOverrideSymbolsResolverVisitor
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.jvm.serialization.JvmIdSignatureDescriptor
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.backend.*
@@ -44,13 +43,9 @@ data class Fir2IrActualizedResult(
val irActualizedResult: IrActualizedResult?,
)
fun signatureComposerForJvmFir2Ir(generateSignatures: Boolean): IdSignatureComposer {
fun signatureComposerForJvmFir2Ir(): IdSignatureComposer {
val mangler = JvmDescriptorMangler(null)
return if (generateSignatures) {
JvmIdSignatureDescriptor(mangler)
} else {
DescriptorSignatureComposerStub(mangler)
}
return DescriptorSignatureComposerStub(mangler)
}
fun FirResult.convertToIrAndActualize(
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
import org.jetbrains.kotlin.fir.declarations.utils.visibility
import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
@@ -27,7 +26,6 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.utils.addToStdlib.runIf
class Fir2IrClassifierStorage(
private val components: Fir2IrComponents,
@@ -177,20 +175,13 @@ class Fir2IrClassifierStorage(
parent: IrDeclarationParent,
predefinedOrigin: IrDeclarationOrigin? = null
): IrClass {
val symbol = createClassSymbol(regularClass)
val symbol = createClassSymbol(signature = null)
return classifiersGenerator.createIrClass(regularClass, parent, symbol, predefinedOrigin).also {
@OptIn(LeakedDeclarationCaches::class)
cacheIrClass(regularClass, it)
}
}
private fun createClassSymbol(regularClass: FirRegularClass): IrClassSymbol {
val signature = runIf(!regularClass.isLocal && configuration.linkViaSignatures) {
signatureComposer.composeSignature(regularClass)
}
return createClassSymbol(signature)
}
private fun createClassSymbol(signature: IdSignature?): IrClassSymbol {
return when {
signature != null -> symbolTable.referenceClass(signature)
@@ -247,7 +238,7 @@ class Fir2IrClassifierStorage(
// firClass may be referenced by some parent's type parameters as a bound. In that case, getIrClassSymbol will be called recursively.
classifierStorage.getCachedIrClass(firClass)?.let { return it }
val symbol = createClassSymbol(firClass)
val symbol = createClassSymbol(signature = null)
val irClass = lazyDeclarationsGenerator.createIrLazyClass(firClass, irParent, symbol)
classCache[firClass] = irClass
// NB: this is needed to prevent recursions in case of self bounds
@@ -24,10 +24,6 @@ import org.jetbrains.kotlin.incremental.components.InlineConstTracker
import org.jetbrains.kotlin.ir.util.SymbolTable
/**
* @param linkViaSignatures Enables calculation of signatures for IR symbols and filling the [SymbolTable] with them.
* This parameter should be set to `true` if the caller relies on the content of the symbol table in the future.
* Note: this parameter is to be removed ([KT-64809](https://youtrack.jetbrains.com/issue/KT-64809)).
*
* @param allowNonCachedDeclarations
* Normally, FIR2IR caches all declarations it meets in a compiled module.
* It means asking for an IR element of a non-cached declaration is a sign of inconsistent state.
@@ -40,7 +36,6 @@ import org.jetbrains.kotlin.ir.util.SymbolTable
class Fir2IrConfiguration private constructor(
val languageVersionSettings: LanguageVersionSettings,
val diagnosticReporter: DiagnosticReporter,
val linkViaSignatures: Boolean,
val evaluatedConstTracker: EvaluatedConstTracker,
val inlineConstTracker: InlineConstTracker?,
val expectActualTracker: ExpectActualTracker?,
@@ -56,7 +51,6 @@ class Fir2IrConfiguration private constructor(
Fir2IrConfiguration(
languageVersionSettings = compilerConfiguration.languageVersionSettings,
diagnosticReporter = diagnosticReporter,
linkViaSignatures = false,
evaluatedConstTracker = compilerConfiguration.putIfAbsent(
CommonConfigurationKeys.EVALUATED_CONST_TRACKER,
EvaluatedConstTracker.create(),
@@ -74,7 +68,6 @@ class Fir2IrConfiguration private constructor(
Fir2IrConfiguration(
languageVersionSettings = compilerConfiguration.languageVersionSettings,
diagnosticReporter = diagnosticReporter,
linkViaSignatures = false,
evaluatedConstTracker = compilerConfiguration.putIfAbsent(
CommonConfigurationKeys.EVALUATED_CONST_TRACKER,
EvaluatedConstTracker.create(),
@@ -93,7 +86,6 @@ class Fir2IrConfiguration private constructor(
Fir2IrConfiguration(
languageVersionSettings = languageVersionSettings,
diagnosticReporter = diagnosticReporter,
linkViaSignatures = false,
evaluatedConstTracker = compilerConfiguration.putIfAbsent(
CommonConfigurationKeys.EVALUATED_CONST_TRACKER,
EvaluatedConstTracker.create(),
@@ -383,7 +383,6 @@ class Fir2IrDeclarationStorage(
private fun createMemberFunctionSymbol(
function: FirFunction,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null,
signature: IdSignature?,
parentIsExternal: Boolean
): IrSimpleFunctionSymbol {
if (
@@ -392,12 +391,12 @@ class Fir2IrDeclarationStorage(
function !is FirSimpleFunction ||
!function.isFakeOverride(fakeOverrideOwnerLookupTag)
) {
return createFunctionSymbol(signature)
return createFunctionSymbol(signature = null)
}
val containingClassSymbol = findContainingIrClassSymbol(function, fakeOverrideOwnerLookupTag)
val originalFirFunction = function.unwrapFakeOverrides()
val originalSymbol = getIrFunctionSymbol(originalFirFunction.symbol) as IrSimpleFunctionSymbol
return IrFunctionFakeOverrideSymbol(originalSymbol, containingClassSymbol, signature)
return IrFunctionFakeOverrideSymbol(originalSymbol, containingClassSymbol, idSignature = null)
}
private fun findContainingIrClassSymbol(
@@ -480,13 +479,6 @@ class Fir2IrDeclarationStorage(
)
}
private fun createConstructorSymbol(signature: IdSignature?): IrConstructorSymbol {
return when {
signature != null -> symbolTable.referenceConstructor(signature)
else -> IrConstructorSymbolImpl()
}
}
private fun cacheIrConstructorSymbol(constructor: FirConstructor, irConstructorSymbol: IrConstructorSymbol) {
constructorCache[constructor] = irConstructorSymbol
}
@@ -496,10 +488,7 @@ class Fir2IrDeclarationStorage(
getCachedIrConstructorSymbol(constructor)?.let { return it }
// caching of created constructor is not called here, because `callablesGenerator` calls `cacheIrConstructor` by itself
val signature = runIf(!isLocal && configuration.linkViaSignatures) {
signatureComposer.composeSignature(constructor)
}
val symbol = createConstructorSymbol(signature)
val symbol = IrConstructorSymbolImpl()
if (!isLocal) {
val irParent = findIrParent(constructor, fakeOverrideOwnerLookupTag = null)
val isIntrinsicConstEvaluation =
@@ -565,7 +554,6 @@ class Fir2IrDeclarationStorage(
createAndCacheIrProperty(
field.toStubProperty(),
irParent,
isLocal = false,
fakeOverrideOwnerLookupTag = containingClassId?.toLookupTag(),
allowLazyDeclarationsCreation = true // pure fields exist only in java
)
@@ -576,14 +564,13 @@ class Fir2IrDeclarationStorage(
property: FirProperty,
irParent: IrDeclarationParent?,
predefinedOrigin: IrDeclarationOrigin? = null,
isLocal: Boolean = false,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null,
allowLazyDeclarationsCreation: Boolean = false
): IrProperty {
@Suppress("NAME_SHADOWING")
val property = prepareProperty(property)
val symbols = getIrPropertySymbols(property.symbol, fakeOverrideOwnerLookupTag, isLocal)
val symbols = getIrPropertySymbols(property.symbol, fakeOverrideOwnerLookupTag)
return callablesGenerator.createIrProperty(
property, irParent, symbols, predefinedOrigin, fakeOverrideOwnerLookupTag, allowLazyDeclarationsCreation
@@ -591,7 +578,6 @@ class Fir2IrDeclarationStorage(
}
private fun createPropertySymbols(
signature: IdSignature?,
property: FirProperty,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
parentIsExternal: Boolean
@@ -601,30 +587,14 @@ class Fir2IrDeclarationStorage(
!parentIsExternal &&
property.isFakeOverride(fakeOverrideOwnerLookupTag)
) {
return createFakeOverridePropertySymbols(signature, property, fakeOverrideOwnerLookupTag)
return createFakeOverridePropertySymbols(property, fakeOverrideOwnerLookupTag)
}
val propertySymbol = when {
signature != null -> when (property.isStubPropertyForPureField) {
// Very special case when two similar properties can exist so conflicts in SymbolTable are possible.
// See javaCloseFieldAndKotlinProperty.kt in BB tests
true -> IrPropertyPublicSymbolImpl(signature).also {
symbolTable.declarePropertyWithSignature(signature, it)
}
else -> symbolTable.referenceProperty(signature)
}
else -> IrPropertySymbolImpl()
}
val getterSignature = runIf(signature != null) {
signatureComposer.composeAccessorSignature(property, isSetter = false, fakeOverrideOwnerLookupTag)
}
val getterSymbol = createFunctionSymbol(getterSignature)
val propertySymbol = IrPropertySymbolImpl()
val getterSymbol = createFunctionSymbol(signature = null)
val setterSymbol = runIf(property.isVar) {
val setterSignature = runIf(signature != null) {
signatureComposer.composeAccessorSignature(property, isSetter = true, fakeOverrideOwnerLookupTag)
}
createFunctionSymbol(setterSignature)
createFunctionSymbol(signature = null)
}
val backingFieldSymbol = runIf(property.delegate != null || property.hasBackingField) {
@@ -635,33 +605,25 @@ class Fir2IrDeclarationStorage(
}
private fun createFakeOverridePropertySymbols(
signature: IdSignature?,
property: FirProperty,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
): PropertySymbols {
val originalFirProperty = property.unwrapFakeOverrides()
val originalSymbols = getIrPropertySymbols(originalFirProperty.symbol, isLocal = false)
val originalSymbols = getIrPropertySymbols(originalFirProperty.symbol)
require(property.isStubPropertyForPureField != true) {
"What are we doing here?"
}
val containingClassSymbol = findContainingIrClassSymbol(property, fakeOverrideOwnerLookupTag)
val propertySymbol = IrPropertyFakeOverrideSymbol(originalSymbols.propertySymbol, containingClassSymbol, signature)
val getterSignature = runIf(signature != null) {
signatureComposer.composeAccessorSignature(property, isSetter = false, fakeOverrideOwnerLookupTag)
}
val getterSymbol = IrFunctionFakeOverrideSymbol(originalSymbols.getterSymbol, containingClassSymbol, getterSignature)
val propertySymbol = IrPropertyFakeOverrideSymbol(originalSymbols.propertySymbol, containingClassSymbol, idSignature = null)
val getterSymbol = IrFunctionFakeOverrideSymbol(originalSymbols.getterSymbol, containingClassSymbol, idSignature = null)
val setterSymbol = runIf(property.isVar) {
val setterIsVisible = property.setter?.let { setter ->
fakeOverrideOwnerLookupTag?.toFirRegularClass(session)?.let { containingClass -> setter.isVisibleInClass(containingClass) }
} ?: true
runIf(setterIsVisible) {
val setterSignature = runIf(signature != null) {
signatureComposer.composeAccessorSignature(property, isSetter = true, fakeOverrideOwnerLookupTag)
}
IrFunctionFakeOverrideSymbol(originalSymbols.setterSymbol!!, containingClassSymbol, setterSignature)
IrFunctionFakeOverrideSymbol(originalSymbols.setterSymbol!!, containingClassSymbol, idSignature = null)
}
}
return PropertySymbols(propertySymbol, getterSymbol, setterSymbol, backingFieldSymbol = null)
@@ -718,37 +680,31 @@ class Fir2IrDeclarationStorage(
fun getIrPropertySymbol(
firPropertySymbol: FirPropertySymbol,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null,
isLocal: Boolean = false
): IrSymbol {
val property = prepareProperty(firPropertySymbol.fir)
if (property.isLocal) {
return localStorage.getDelegatedProperty(property) ?: getIrVariableSymbol(property)
}
getCachedIrPropertySymbol(property, fakeOverrideOwnerLookupTag)?.let { return it }
return getIrPropertySymbols(firPropertySymbol, fakeOverrideOwnerLookupTag, isLocal).propertySymbol
return getIrPropertySymbols(firPropertySymbol, fakeOverrideOwnerLookupTag).propertySymbol
}
private fun getIrPropertySymbols(
firPropertySymbol: FirPropertySymbol,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null,
isLocal: Boolean
): PropertySymbols {
val property = prepareProperty(firPropertySymbol.fir)
getCachedIrPropertySymbols(property, fakeOverrideOwnerLookupTag)?.let { return it }
return createAndCacheIrPropertySymbols(property, fakeOverrideOwnerLookupTag, isLocal)
return createAndCacheIrPropertySymbols(property, fakeOverrideOwnerLookupTag)
}
private fun createAndCacheIrPropertySymbols(
property: FirProperty,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag?,
isLocal: Boolean
): PropertySymbols {
val signature = runIf(!isLocal && configuration.linkViaSignatures) {
signatureComposer.composeSignature(property, fakeOverrideOwnerLookupTag)
}
val irParent = findIrParent(property, fakeOverrideOwnerLookupTag)
if (irParent?.isExternalParent() == true) {
val symbols = createPropertySymbols(signature, property, fakeOverrideOwnerLookupTag, parentIsExternal = true)
val symbols = createPropertySymbols(property, fakeOverrideOwnerLookupTag, parentIsExternal = true)
val firForLazyProperty = calculateFirForLazyDeclaration(
property, fakeOverrideOwnerLookupTag, irParent,
fakeOverrideGenerator::createFirPropertyFakeOverrideIfNeeded
@@ -768,7 +724,7 @@ class Fir2IrDeclarationStorage(
return symbols
}
val symbols = createPropertySymbols(signature, property, fakeOverrideOwnerLookupTag, parentIsExternal = false)
val symbols = createPropertySymbols(property, fakeOverrideOwnerLookupTag, parentIsExternal = false)
cacheIrPropertySymbols(property, symbols, fakeOverrideOwnerLookupTag)
return symbols
@@ -895,7 +851,7 @@ class Fir2IrDeclarationStorage(
propertyCache[fir]?.ownerIfBound()?.let { return it.backingField!!.symbol }
val irParent = findIrParent(fir, fakeOverrideOwnerLookupTag = null)
val parentOrigin = (irParent as? IrDeclaration)?.origin ?: IrDeclarationOrigin.DEFINED
createAndCacheIrProperty(fir, irParent, predefinedOrigin = parentOrigin, isLocal = false).backingField!!.symbol
createAndCacheIrProperty(fir, irParent, predefinedOrigin = parentOrigin).backingField!!.symbol
}
else -> {
getIrVariableSymbol(fir)
@@ -1129,13 +1085,10 @@ class Fir2IrDeclarationStorage(
}
getCachedIrFunctionSymbol(function, fakeOverrideOwnerLookupTag)?.let { return it }
val signature = runIf(!isLocal && configuration.linkViaSignatures) {
signatureComposer.composeSignature(firFunctionSymbol.fir, fakeOverrideOwnerLookupTag)
}
if (function is FirSimpleFunction && !isLocal) {
val irParent = findIrParent(function, fakeOverrideOwnerLookupTag)
if (irParent?.isExternalParent() == true) {
val symbol = createMemberFunctionSymbol(function, fakeOverrideOwnerLookupTag, signature, parentIsExternal = true)
val symbol = createMemberFunctionSymbol(function, fakeOverrideOwnerLookupTag, parentIsExternal = true)
val firForLazyFunction = calculateFirForLazyDeclaration(
function, fakeOverrideOwnerLookupTag, irParent,
fakeOverrideGenerator::createFirFunctionFakeOverrideIfNeeded
@@ -1158,7 +1111,7 @@ class Fir2IrDeclarationStorage(
}
}
val symbol = createMemberFunctionSymbol(function, fakeOverrideOwnerLookupTag, signature, parentIsExternal = false)
val symbol = createMemberFunctionSymbol(function, fakeOverrideOwnerLookupTag, parentIsExternal = false)
cacheIrFunctionSymbol(function, symbol, fakeOverrideOwnerLookupTag)
return symbol
}
@@ -135,12 +135,11 @@ class FakeOverrideGenerator(
createFakeOverriddenIfNeeded(
firClass, irClass, isLocal, propertyOrFieldSymbol,
declarationStorage::getCachedIrPropertySymbol,
{ property, irParent, predefinedOrigin, isLocal ->
{ property, irParent, predefinedOrigin, _ ->
declarationStorage.createAndCacheIrProperty(
property,
irParent,
predefinedOrigin,
isLocal,
allowLazyDeclarationsCreation = true
)
},
@@ -68,7 +68,7 @@ class Fir2IrJvmResultsConverter(
val phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG)
val commonMemberStorage = Fir2IrCommonMemberStorage(signatureComposerForJvmFir2Ir(false), FirJvmKotlinMangler())
val commonMemberStorage = Fir2IrCommonMemberStorage(signatureComposerForJvmFir2Ir(), FirJvmKotlinMangler())
val diagnosticReporter = DiagnosticReporterFactory.createReporter()
val compilerConfiguration = compilerConfigurationProvider.getCompilerConfiguration(module)
@@ -78,7 +78,7 @@ class Fir2IrJvmResultsConverter(
fir2IrExtensions,
fir2IrConfiguration,
module.irGenerationExtensions(testServices),
signatureComposerForJvmFir2Ir(false),
signatureComposerForJvmFir2Ir(),
irMangler,
FirJvmKotlinMangler(),
FirJvmVisibilityConverter,