[FIR2IR] Remove incorrect usages of Fir2IrDeclarationStorage.getOrCreateIrConstructor

See comment to the similar commit about `getOrCreateIrFunction`

There are two added TODOs mentioned KT-62856, without them the following
  tests are failing:
- `FirPsiJvmIrTextTestGenerated.FirProblems#testTypeParameterBounds`
- `FirPsiJvmIrTextTestGenerated.Declarations#testKt52677`
This commit is contained in:
Dmitriy Novozhilov
2023-10-24 15:07:02 +03:00
committed by Space Team
parent bced604b57
commit 3ae2a8387e
4 changed files with 30 additions and 3 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.common.actualizer.FakeOverrideRebuilder
import org.jetbrains.kotlin.backend.common.sourceElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.fir.*
@@ -233,7 +234,13 @@ class Fir2IrConverter(
irClass.declarations.addAll(classifierStorage.getFieldsWithContextReceiversForClass(irClass, klass))
val irConstructor = klass.primaryConstructorIfAny(session)?.let {
declarationStorage.getOrCreateIrConstructor(it.fir, irClass, isLocal = klass.isLocal)
if (klass.classKind == ClassKind.ANNOTATION_CLASS) {
// TODO: this branch should be removed after fix of KT-62856
@OptIn(GetOrCreateSensitiveAPI::class)
declarationStorage.getOrCreateIrConstructor(it.fir, irClass, isLocal = klass.isLocal)
} else {
declarationStorage.createAndCacheIrConstructor(it.fir, { irClass }, isLocal = klass.isLocal)
}
}
// At least on enum entry creation we may need a default constructor, so ctors should be converted first
for (declaration in syntheticPropertiesLast(allDeclarations)) {
@@ -532,7 +539,14 @@ class Fir2IrConverter(
}
}
is FirConstructor -> if (!declaration.isPrimary) {
declarationStorage.getOrCreateIrConstructor(declaration, parent as IrClass, isLocal = isInLocalClass)
// the primary constructor was already created in `processClassMembers` function
if (containingClass?.classKind == ClassKind.ANNOTATION_CLASS) {
// TODO: this branch should be removed after fix of KT-62856
@OptIn(GetOrCreateSensitiveAPI::class)
declarationStorage.getOrCreateIrConstructor(declaration, parent as IrClass, isLocal = isInLocalClass)
} else {
declarationStorage.createAndCacheIrConstructor(declaration, { parent as IrClass }, isLocal = isInLocalClass)
}
}
is FirEnumEntry -> {
classifierStorage.getOrCreateIrEnumEntry(declaration, parent as IrClass)
@@ -375,6 +375,7 @@ class Fir2IrDeclarationStorage(
}
}
@GetOrCreateSensitiveAPI
fun getOrCreateIrConstructor(
constructor: FirConstructor,
irParent: IrClass,
@@ -384,6 +385,7 @@ class Fir2IrDeclarationStorage(
return getOrCreateIrConstructor(constructor, { irParent }, predefinedOrigin, isLocal)
}
@GetOrCreateSensitiveAPI
private fun getOrCreateIrConstructor(
constructor: FirConstructor,
irParent: () -> IrClass,
@@ -391,6 +393,15 @@ class Fir2IrDeclarationStorage(
isLocal: Boolean = false,
): IrConstructor {
getCachedIrConstructorSymbol(constructor)?.ownerIfBound()?.let { return it }
return createAndCacheIrConstructor(constructor, irParent, predefinedOrigin, isLocal)
}
fun createAndCacheIrConstructor(
constructor: FirConstructor,
irParent: () -> IrClass,
predefinedOrigin: IrDeclarationOrigin? = null,
isLocal: Boolean = false,
): IrConstructor {
// caching of created constructor is not called here, because `callablesGenerator` calls `cacheIrConstructor` by itself
return callablesGenerator.createIrConstructor(constructor, irParent(), predefinedOrigin, isLocal)
}
@@ -400,6 +411,7 @@ class Fir2IrDeclarationStorage(
constructorCache[constructor] = irConstructor.symbol
}
@OptIn(GetOrCreateSensitiveAPI::class)
fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol {
val fir = firConstructorSymbol.fir
return getOrCreateIrConstructor(fir, { findIrParent(fir, fakeOverrideOwnerLookupTag = null) as IrClass }).symbol
@@ -160,6 +160,7 @@ class FirIrProvider(val components: Fir2IrComponents) : IrProvider {
val firDeclaration = findDeclarationByHash(firCandidates, signature.id) ?: return null
val parent = parentClass ?: declarationStorage.getIrExternalPackageFragment(packageFqName, firDeclaration.moduleData)
@OptIn(GetOrCreateSensitiveAPI::class)
return when (kind) {
SymbolKind.CLASS_SYMBOL -> {
classifierStorage.getOrCreateIrClass((firDeclaration as FirRegularClass).symbol)
@@ -173,7 +174,6 @@ class FirIrProvider(val components: Fir2IrComponents) : IrProvider {
}
SymbolKind.FUNCTION_SYMBOL -> {
val firSimpleFunction = firDeclaration as FirSimpleFunction
@OptIn(GetOrCreateSensitiveAPI::class)
declarationStorage.getOrCreateIrFunction(firSimpleFunction, parent)
}
SymbolKind.PROPERTY_SYMBOL -> {
@@ -162,6 +162,7 @@ class Fir2IrLazyClass(
scope.processDeclaredConstructors {
val constructor = it.fir
if (shouldBuildStub(constructor)) {
@OptIn(GetOrCreateSensitiveAPI::class)
result += declarationStorage.getOrCreateIrConstructor(constructor, this, origin)
}
}