[FIR2IR] Slightly cleanup some fir2ir classes
This commit is contained in:
committed by
Space Team
parent
2ba7194467
commit
af6b71ca2d
@@ -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)
|
||||
|
||||
+13
-9
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user