[FIR2IR] Slightly cleanup some fir2ir classes

This commit is contained in:
Dmitriy Novozhilov
2023-10-24 12:21:06 +03:00
committed by Space Team
parent 2ba7194467
commit af6b71ca2d
3 changed files with 29 additions and 25 deletions
@@ -560,7 +560,7 @@ class Fir2IrConverter(
val firModuleDescriptor = irModuleFragment.descriptor as? FirModuleDescriptor val firModuleDescriptor = irModuleFragment.descriptor as? FirModuleDescriptor
val targetPlatform = firModuleDescriptor?.platform val targetPlatform = firModuleDescriptor?.platform
val languageVersionSettings = firModuleDescriptor?.session?.languageVersionSettings ?: return val languageVersionSettings = firModuleDescriptor?.session?.languageVersionSettings ?: return
val intrinsicConstEvaluation = languageVersionSettings.supportsFeature(LanguageFeature.IntrinsicConstEvaluation) == true val intrinsicConstEvaluation = languageVersionSettings.supportsFeature(LanguageFeature.IntrinsicConstEvaluation)
val configuration = IrInterpreterConfiguration( val configuration = IrInterpreterConfiguration(
platform = targetPlatform, platform = targetPlatform,
@@ -572,7 +572,9 @@ class Fir2IrConverter(
components.session.javaElementFinder?.propertyEvaluator = { it.evaluate(components, interpreter, mode) } components.session.javaElementFinder?.propertyEvaluator = { it.evaluate(components, interpreter, mode) }
val ktDiagnosticReporter = KtDiagnosticReporterWithImplicitIrBasedContext(fir2IrConfiguration.diagnosticReporter, languageVersionSettings) val ktDiagnosticReporter = KtDiagnosticReporterWithImplicitIrBasedContext(
fir2IrConfiguration.diagnosticReporter, languageVersionSettings
)
irModuleFragment.files.forEach { irModuleFragment.files.forEach {
it.transformConst( it.transformConst(
it, it,
@@ -618,7 +620,7 @@ class Fir2IrConverter(
} }
// TODO: drop this function in favor of using [IrModuleDescriptor::shouldSeeInternalsOf] in FakeOverrideBuilder KT-61384 // 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 { session.moduleData.name.asStringStripSpecialMarkers() to session.moduleData.friendDependencies.map {
it.name.asStringStripSpecialMarkers() it.name.asStringStripSpecialMarkers()
} }
@@ -669,7 +671,8 @@ class Fir2IrConverter(
) )
if (fir2IrConfiguration.useIrFakeOverrideBuilder) { 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) return Fir2IrResult(irModuleFragment, components, moduleDescriptor)
@@ -187,7 +187,7 @@ class Fir2IrDeclarationStorage(
firOrigin: FirDeclarationOrigin, firOrigin: FirDeclarationOrigin,
): IrExternalPackageFragment { ): IrExternalPackageFragment {
val isBuiltIn = fqName in BUILT_INS_PACKAGE_FQ_NAMES val isBuiltIn = fqName in BUILT_INS_PACKAGE_FQ_NAMES
return when(isBuiltIn) { return when (isBuiltIn) {
true -> getIrBuiltInsPackageFragment(fqName) true -> getIrBuiltInsPackageFragment(fqName)
false -> getIrExternalPackageFragment(fqName, moduleData, firOrigin) false -> getIrExternalPackageFragment(fqName, moduleData, firOrigin)
} }
@@ -233,12 +233,18 @@ class Fir2IrDeclarationStorage(
// ------------------------------------ functions ------------------------------------ // ------------------------------------ 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) return if (function is FirSimpleFunction) getCachedIrFunctionSymbol(function, fakeOverrideOwnerLookupTag)
else localStorage.getLocalFunctionSymbol(function) else localStorage.getLocalFunctionSymbol(function)
} }
fun getCachedIrFunctionSymbol(function: FirSimpleFunction, fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null): IrSimpleFunctionSymbol? { fun getCachedIrFunctionSymbol(
function: FirSimpleFunction,
fakeOverrideOwnerLookupTag: ConeClassLikeLookupTag? = null,
): IrSimpleFunctionSymbol? {
return getCachedIrFunctionSymbol(function, fakeOverrideOwnerLookupTag) { return getCachedIrFunctionSymbol(function, fakeOverrideOwnerLookupTag) {
signatureComposer.composeSignature(function, fakeOverrideOwnerLookupTag) signatureComposer.composeSignature(function, fakeOverrideOwnerLookupTag)
} }
@@ -377,7 +383,7 @@ class Fir2IrDeclarationStorage(
return getOrCreateIrConstructor(constructor, { irParent }, predefinedOrigin, isLocal) return getOrCreateIrConstructor(constructor, { irParent }, predefinedOrigin, isLocal)
} }
fun getOrCreateIrConstructor( private fun getOrCreateIrConstructor(
constructor: FirConstructor, constructor: FirConstructor,
irParent: () -> IrClass, irParent: () -> IrClass,
predefinedOrigin: IrDeclarationOrigin? = null, predefinedOrigin: IrDeclarationOrigin? = null,
@@ -395,10 +401,7 @@ class Fir2IrDeclarationStorage(
fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol { fun getIrConstructorSymbol(firConstructorSymbol: FirConstructorSymbol): IrConstructorSymbol {
val fir = firConstructorSymbol.fir val fir = firConstructorSymbol.fir
return getOrCreateIrConstructor( return getOrCreateIrConstructor(fir, { findIrParent(fir, fakeOverrideOwnerLookupTag = null) as IrClass }).symbol
fir,
{ findIrParent(fir, fakeOverrideOwnerLookupTag = null) as IrClass }
).symbol
} }
@@ -451,7 +454,7 @@ class Fir2IrDeclarationStorage(
return getOrCreateIrProperty(property, { irParent }, predefinedOrigin, isLocal, fakeOverrideOwnerLookupTag) return getOrCreateIrProperty(property, { irParent }, predefinedOrigin, isLocal, fakeOverrideOwnerLookupTag)
} }
fun getOrCreateIrProperty( private fun getOrCreateIrProperty(
property: FirProperty, property: FirProperty,
irParent: () -> IrDeclarationParent?, irParent: () -> IrDeclarationParent?,
predefinedOrigin: IrDeclarationOrigin? = null, predefinedOrigin: IrDeclarationOrigin? = null,
@@ -526,6 +529,7 @@ class Fir2IrDeclarationStorage(
} }
} }
@Suppress("DuplicatedCode")
private fun FirField.toStubProperty(): FirProperty { private fun FirField.toStubProperty(): FirProperty {
val field = this val field = this
return buildProperty { return buildProperty {
@@ -90,21 +90,18 @@ class Fir2IrVisitor(
} }
override fun visitElement(element: FirElement, data: Any?): IrElement { 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) { override fun visitField(field: FirField, data: Any?): IrField = whileAnalysing(session, field) {
if (field.isSynthetic) { require(field.isSynthetic) { "Non-synthetic field found during traversal of FIR tree: ${field.render()}" }
@OptIn(UnsafeDuringIrConstructionAPI::class) @OptIn(UnsafeDuringIrConstructionAPI::class)
return declarationStorage.getCachedIrDelegateOrBackingFieldSymbol(field)!!.owner.apply { return declarationStorage.getCachedIrDelegateOrBackingFieldSymbol(field)!!.owner.apply {
// If this is a property backing field, then it has no separate initializer, // If this is a property backing field, then it has no separate initializer,
// so we shouldn't convert it // so we shouldn't convert it
if (correspondingPropertySymbol == null) { if (correspondingPropertySymbol == null) {
memberGenerator.convertFieldContent(this, field) 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 -> { statement is FirProperty && statement.origin == FirDeclarationOrigin.ScriptCustomization.ResultProperty -> {
// Generating the result property only for expressions with a meaningful result type // Generating the result property only for expressions with a meaningful result type
// otherwise skip the property and convert the expression into the statement // 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() statement.initializer!!.toIrStatement()
} else { } else {
(statement.accept(this@Fir2IrVisitor, null) as? IrDeclaration)?.also { (statement.accept(this@Fir2IrVisitor, null) as? IrDeclaration)?.also {