diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index 3381bf4f8e3..defaf337dbc 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -560,7 +560,7 @@ class Fir2IrConverter( val firModuleDescriptor = irModuleFragment.descriptor as? FirModuleDescriptor val targetPlatform = firModuleDescriptor?.platform val languageVersionSettings = firModuleDescriptor?.session?.languageVersionSettings ?: return - val intrinsicConstEvaluation = languageVersionSettings.supportsFeature(LanguageFeature.IntrinsicConstEvaluation) == true + val intrinsicConstEvaluation = languageVersionSettings.supportsFeature(LanguageFeature.IntrinsicConstEvaluation) val configuration = IrInterpreterConfiguration( platform = targetPlatform, @@ -572,7 +572,9 @@ class Fir2IrConverter( components.session.javaElementFinder?.propertyEvaluator = { it.evaluate(components, interpreter, mode) } - val ktDiagnosticReporter = KtDiagnosticReporterWithImplicitIrBasedContext(fir2IrConfiguration.diagnosticReporter, languageVersionSettings) + val ktDiagnosticReporter = KtDiagnosticReporterWithImplicitIrBasedContext( + fir2IrConfiguration.diagnosticReporter, languageVersionSettings + ) irModuleFragment.files.forEach { it.transformConst( it, @@ -618,7 +620,7 @@ class Fir2IrConverter( } // TODO: drop this function in favor of using [IrModuleDescriptor::shouldSeeInternalsOf] in FakeOverrideBuilder KT-61384 - fun friendModulesMap(session: FirSession) = mapOf( + private fun friendModulesMap(session: FirSession) = mapOf( session.moduleData.name.asStringStripSpecialMarkers() to session.moduleData.friendDependencies.map { it.name.asStringStripSpecialMarkers() } @@ -669,7 +671,8 @@ class Fir2IrConverter( ) if (fir2IrConfiguration.useIrFakeOverrideBuilder) { - FakeOverrideRebuilder(commonMemberStorage.symbolTable, components.fakeOverrideBuilder).rebuildFakeOverrides(irModuleFragment) + val rebuilder = FakeOverrideRebuilder(commonMemberStorage.symbolTable, components.fakeOverrideBuilder) + rebuilder.rebuildFakeOverrides(irModuleFragment) } return Fir2IrResult(irModuleFragment, components, moduleDescriptor) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 900a50f0e08..d45380ea045 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -187,7 +187,7 @@ class Fir2IrDeclarationStorage( firOrigin: FirDeclarationOrigin, ): IrExternalPackageFragment { val isBuiltIn = fqName in BUILT_INS_PACKAGE_FQ_NAMES - return when(isBuiltIn) { + return when (isBuiltIn) { true -> getIrBuiltInsPackageFragment(fqName) false -> getIrExternalPackageFragment(fqName, moduleData, firOrigin) } @@ -233,12 +233,18 @@ class Fir2IrDeclarationStorage( // ------------------------------------ functions ------------------------------------ - fun getCachedIrFunctionSymbol(function: FirFunction, fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null): IrSimpleFunctionSymbol? { + fun getCachedIrFunctionSymbol( + function: FirFunction, + fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null, + ): IrSimpleFunctionSymbol? { return if (function is FirSimpleFunction) getCachedIrFunctionSymbol(function, fakeOverrideOwnerLookupTag) else localStorage.getLocalFunctionSymbol(function) } - fun getCachedIrFunctionSymbol(function: FirSimpleFunction, fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null): IrSimpleFunctionSymbol? { + fun getCachedIrFunctionSymbol( + function: FirSimpleFunction, + fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null, + ): IrSimpleFunctionSymbol? { return getCachedIrFunctionSymbol(function, fakeOverrideOwnerLookupTag) { signatureComposer.composeSignature(function, fakeOverrideOwnerLookupTag) } @@ -377,7 +383,7 @@ class Fir2IrDeclarationStorage( return getOrCreateIrConstructor(constructor, { irParent }, predefinedOrigin, isLocal) } - fun getOrCreateIrConstructor( + private fun getOrCreateIrConstructor( constructor: FirConstructor, irParent: () -> IrClass, predefinedOrigin: IrDeclarationOrigin? = null, @@ -395,10 +401,7 @@ class Fir2IrDeclarationStorage( fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol { val fir = firConstructorSymbol.fir - return getOrCreateIrConstructor( - fir, - { findIrParent(fir, fakeOverrideOwnerLookupTag = null) as IrClass } - ).symbol + return getOrCreateIrConstructor(fir, { findIrParent(fir, fakeOverrideOwnerLookupTag = null) as IrClass }).symbol } @@ -451,7 +454,7 @@ class Fir2IrDeclarationStorage( return getOrCreateIrProperty(property, { irParent }, predefinedOrigin, isLocal, fakeOverrideOwnerLookupTag) } - fun getOrCreateIrProperty( + private fun getOrCreateIrProperty( property: FirProperty, irParent: () -> IrDeclarationParent?, predefinedOrigin: IrDeclarationOrigin? = null, @@ -526,6 +529,7 @@ class Fir2IrDeclarationStorage( } } + @Suppress("DuplicatedCode") private fun FirField.toStubProperty(): FirProperty { val field = this return buildProperty { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index a2117abee52..37246c26392 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -90,21 +90,18 @@ class Fir2IrVisitor( } override fun visitElement(element: FirElement, data: Any?): IrElement { - TODO("Should not be here: ${element::class} ${element.render()}") + error("Should not be here: ${element::class} ${element.render()}") } override fun visitField(field: FirField, data: Any?): IrField = whileAnalysing(session, field) { - if (field.isSynthetic) { - @OptIn(UnsafeDuringIrConstructionAPI::class) - return declarationStorage.getCachedIrDelegateOrBackingFieldSymbol(field)!!.owner.apply { - // If this is a property backing field, then it has no separate initializer, - // so we shouldn't convert it - if (correspondingPropertySymbol == null) { - memberGenerator.convertFieldContent(this, field) - } + require(field.isSynthetic) { "Non-synthetic field found during traversal of FIR tree: ${field.render()}" } + @OptIn(UnsafeDuringIrConstructionAPI::class) + return declarationStorage.getCachedIrDelegateOrBackingFieldSymbol(field)!!.owner.apply { + // If this is a property backing field, then it has no separate initializer, + // so we shouldn't convert it + if (correspondingPropertySymbol == null) { + memberGenerator.convertFieldContent(this, field) } - } else { - throw AssertionError("Unexpected field: ${field.render()}") } } @@ -266,7 +263,7 @@ class Fir2IrVisitor( statement is FirProperty && statement.origin == FirDeclarationOrigin.ScriptCustomization.ResultProperty -> { // Generating the result property only for expressions with a meaningful result type // otherwise skip the property and convert the expression into the statement - if (statement.returnTypeRef.let { (it.isUnit || it.isNothing || it.isNullableNothing) } == true) { + if (statement.returnTypeRef.let { (it.isUnit || it.isNothing || it.isNullableNothing) }) { statement.initializer!!.toIrStatement() } else { (statement.accept(this@Fir2IrVisitor, null) as? IrDeclaration)?.also {