[FIR2IR] Properly setup IrClass.sealedSubclasses

This commit is contained in:
Dmitriy Novozhilov
2021-10-08 16:36:27 +03:00
committed by TeamCityServer
parent 146f0f4904
commit 63d841247c
6 changed files with 33 additions and 8 deletions
@@ -561,3 +561,11 @@ fun Fir2IrComponents.computeInlineClassRepresentation(klass: FirRegularClass): I
underlyingType as? IrSimpleType ?: error("Inline class underlying type is not a simple type: ${klass.render()}")
)
}
fun FirRegularClass.getIrSymbolsForSealedSubclasses(components: Fir2IrComponents): List<IrClassSymbol> {
val session = components.session
val symbolProvider = session.symbolProvider
return getSealedClassInheritors(session).mapNotNull {
symbolProvider.getClassLikeSymbolByClassId(it)?.toSymbol(session, components.classifierStorage)
}.filterIsInstance<IrClassSymbol>()
}
@@ -15,10 +15,7 @@ import org.jetbrains.kotlin.fir.backend.generators.OperatorExpressionGenerator
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
import org.jetbrains.kotlin.fir.declarations.utils.isSynthetic
import org.jetbrains.kotlin.fir.declarations.utils.primaryConstructor
import org.jetbrains.kotlin.fir.declarations.utils.visibility
import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.buildBlock
import org.jetbrains.kotlin.fir.expressions.impl.FirElseIfTrueCondition
@@ -156,6 +153,9 @@ class Fir2IrVisitor(
converter.processLocalClassAndNestedClasses(regularClass, irParent)
}
val irClass = classifierStorage.getCachedIrClass(regularClass)!!
if (regularClass.isSealed) {
irClass.sealedSubclasses = regularClass.getIrSymbolsForSealedSubclasses(components)
}
return conversionScope.withParent(irClass) {
conversionScope.withContainingFirClass(regularClass) {
memberGenerator.convertClassContent(irClass, regularClass)
@@ -6,10 +6,8 @@
package org.jetbrains.kotlin.fir.lazy
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
import org.jetbrains.kotlin.fir.backend.computeInlineClassRepresentation
import org.jetbrains.kotlin.fir.backend.*
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
import org.jetbrains.kotlin.fir.backend.toIrType
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.dispatchReceiverClassOrNull
@@ -104,7 +102,11 @@ class Fir2IrLazyClass(
}
override var sealedSubclasses: List<IrClassSymbol> by lazyVar(lock) {
TODO()
if (fir.isSealed) {
fir.getIrSymbolsForSealedSubclasses(components)
} else {
emptyList()
}
}
override var thisReceiver: IrValueParameter? by lazyVar(lock) {
@@ -19,6 +19,9 @@ FILE fqName:<root> fileName:/kt44814.kt
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:FirSourceElement modality:SEALED visibility:public superTypes:[kotlin.Any]
sealedSubclasses:
CLASS CLASS name:FirPsiSourceElement modality:FINAL visibility:public superTypes:[<root>.FirSourceElement]
CLASS CLASS name:FirLightSourceElement modality:FINAL visibility:public superTypes:[<root>.FirSourceElement]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.FirSourceElement
CONSTRUCTOR visibility:protected <> () returnType:<root>.FirSourceElement [primary]
BLOCK_BODY
@@ -368,6 +371,9 @@ FILE fqName:<root> fileName:/kt44814.kt
public open fun toString (): kotlin.String [fake_override] declared in <root>.PsiElement
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:FirModifier modality:SEALED visibility:internal superTypes:[kotlin.Any]
sealedSubclasses:
CLASS CLASS name:FirPsiModifier modality:FINAL visibility:public superTypes:[<root>.FirModifier<<root>.ASTNode>]
CLASS CLASS name:FirLightModifier modality:FINAL visibility:public superTypes:[<root>.FirModifier<<root>.LighterASTNode>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.FirModifier<Node of <root>.FirModifier>
TYPE_PARAMETER name:Node index:0 variance: superTypes:[kotlin.Any]
CONSTRUCTOR visibility:protected <> (node:Node of <root>.FirModifier, token:<root>.KtModifierKeywordToken) returnType:<root>.FirModifier<Node of <root>.FirModifier> [primary]
@@ -504,6 +510,9 @@ FILE fqName:<root> fileName:/kt44814.kt
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS CLASS name:FirModifierList modality:SEALED visibility:internal superTypes:[kotlin.Any]
sealedSubclasses:
CLASS CLASS name:FirPsiModifierList modality:FINAL visibility:public superTypes:[<root>.FirModifierList]
CLASS CLASS name:FirLightModifierList modality:FINAL visibility:public superTypes:[<root>.FirModifierList]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.FirModifierList
CONSTRUCTOR visibility:protected <> () returnType:<root>.FirModifierList [primary]
BLOCK_BODY
@@ -1,5 +1,9 @@
FILE fqName:<root> fileName:/ArrayMap.kt
CLASS CLASS name:ArrayMap modality:SEALED visibility:public superTypes:[kotlin.collections.Iterable<T of <root>.ArrayMap>]
sealedSubclasses:
CLASS OBJECT name:EmptyArrayMap modality:FINAL visibility:internal superTypes:[<root>.ArrayMap<kotlin.Nothing>]
CLASS CLASS name:OneElementArrayMap modality:FINAL visibility:internal superTypes:[<root>.ArrayMap<T of <root>.OneElementArrayMap>]
CLASS CLASS name:ArrayMapImpl modality:FINAL visibility:internal superTypes:[<root>.ArrayMap<T of <root>.ArrayMapImpl>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.ArrayMap<T of <root>.ArrayMap>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any]
CONSTRUCTOR visibility:protected <> () returnType:<root>.ArrayMap<T of <root>.ArrayMap> [primary]
@@ -1,5 +1,7 @@
FILE fqName:<root> fileName:/kt45236.kt
CLASS CLASS name:NetRequestStatus modality:SEALED visibility:public superTypes:[kotlin.Any]
sealedSubclasses:
CLASS CLASS name:Error modality:FINAL visibility:public [data] superTypes:[<root>.NetRequestStatus<T of <root>.NetRequestStatus.Error>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.NetRequestStatus<T of <root>.NetRequestStatus>
TYPE_PARAMETER name:T index:0 variance:out superTypes:[kotlin.Any]
CONSTRUCTOR visibility:protected <> () returnType:<root>.NetRequestStatus<T of <root>.NetRequestStatus> [primary]