[FIR] Change FIR structure by replacing FirExpression.typeRef with cone type

#KT-59855
This commit is contained in:
Kirill Rakhman
2023-08-04 10:37:06 +02:00
committed by Space Team
parent 270aa1656f
commit bec39a9258
6 changed files with 56 additions and 75 deletions
@@ -293,8 +293,9 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
default("inlineStatus", "InlineStatus.Unknown")
default("contractDescription", "FirEmptyContractDescription")
default("status", "FirResolvedDeclarationStatusImpl.DEFAULT_STATUS_FOR_STATUSLESS_DECLARATIONS")
default("typeRef", "FirImplicitTypeRefImplWithoutSource")
withCopy()
useTypes(emptyContractDescriptionType, resolvedDeclarationStatusImport)
useTypes(emptyContractDescriptionType, resolvedDeclarationStatusImport, firImplicitTypeWithoutSourceType)
}
builder(propertyAccessor) {
@@ -313,7 +314,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
builder(resolvedTypeRef) {
defaultNull("delegatedTypeRef")
default("isFromStubType", "false")
withCopy()
}
@@ -391,12 +391,12 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
builder(resolvedQualifier) {
parents += abstractResolvedQualifierBuilder
defaultFalse("isNullableLHSForCallableReference", "isFullyQualified")
defaultFalse("isNullableLHSForCallableReference", "isFullyQualified", "canBeValue")
}
builder(errorResolvedQualifier) {
parents += abstractResolvedQualifierBuilder
defaultFalse("isNullableLHSForCallableReference", "isFullyQualified")
defaultFalse("isNullableLHSForCallableReference", "isFullyQualified", "canBeValue")
}
// builder(safeCallExpression) {
@@ -411,37 +411,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
// useTypes(whenExpressionType)
// }
val elementsWithDefaultTypeRef = listOf(
thisReceiverExpression,
callableReferenceAccess,
propertyAccessExpression,
functionCall,
anonymousFunction,
whenExpression,
tryExpression,
checkNotNullCall,
resolvedQualifier,
resolvedReifiedParameterReference,
expression to "FirExpressionStub",
varargArgumentsExpression,
checkedSafeCallSubject,
safeCallExpression,
arrayLiteral,
classReferenceExpression,
getClassCall
)
elementsWithDefaultTypeRef.forEach {
val (element, name) = when (it) {
is Pair<*, *> -> it.first as Element to it.second as String
is Element -> it to null
else -> throw IllegalArgumentException()
}
builder(element, name) {
default("typeRef", "FirImplicitTypeRefImplWithoutSource")
useTypes(firImplicitTypeWithoutSourceType)
}
}
noBuilder(constExpression)
// -----------------------------------------------------------------------
@@ -85,10 +85,11 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
fun ImplementationContext.commonAnnotationConfig() {
defaultEmptyList("annotations")
default("typeRef") {
value = "annotationTypeRef"
default("coneTypeOrNull") {
value = "annotationTypeRef.coneTypeOrNull"
withGetter = true
}
useTypes(coneTypeOrNullImport)
}
impl(annotation) {
@@ -204,7 +205,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(expression, "FirElseIfTrueCondition") {
defaultTypeRefWithSource("FirImplicitBooleanTypeRef")
defaultBuiltInType("Boolean")
useTypes(implicitBooleanTypeRefType)
publicImplementation()
}
@@ -216,6 +217,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
defaultEmptyList("statements")
defaultEmptyList("annotations")
publicImplementation()
defaultNull("coneTypeOrNull")
}
impl(lazyBlock) {
@@ -232,7 +234,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
value = error
withGetter = true
}
default("typeRef") {
default("coneTypeOrNull") {
value = error
withGetter = true
}
@@ -250,7 +252,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
impl(lazyExpression) {
val error = """error("FirLazyExpression should be calculated before accessing")"""
default("typeRef") {
default("coneTypeOrNull") {
value = error
withGetter = true
}
@@ -305,7 +307,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
"getter", "setter",
withGetter = true
)
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic, false)")
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
useTypes(errorTypeRefImplType)
}
@@ -326,7 +328,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(namedArgumentExpression) {
default("typeRef") {
default("coneTypeOrNull") {
delegate = "expression"
}
}
@@ -336,7 +338,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
value = "false"
withGetter = true
}
default("typeRef") {
default("coneTypeOrNull") {
delegate = "expression"
}
}
@@ -346,25 +348,27 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
value = "true"
withGetter = true
}
default("typeRef") {
default("coneTypeOrNull") {
delegate = "expression"
}
}
impl(comparisonExpression) {
default("typeRef", "FirImplicitBooleanTypeRef(null)")
useTypes(implicitBooleanTypeRefType)
default("coneTypeOrNull", "StandardClassIds.Boolean.constructClassLikeType()")
useTypes(standardClassIdsType, constructClassLikeTypeImport)
}
impl(typeOperatorCall)
impl(typeOperatorCall) {
defaultFalse("argFromStubType")
}
impl(assignmentOperatorStatement)
impl(incrementDecrementExpression)
impl(equalityOperatorCall) {
default("typeRef", "FirImplicitBooleanTypeRef(null)")
useTypes(implicitBooleanTypeRefType)
default("coneTypeOrNull", "StandardClassIds.Boolean.constructClassLikeType()")
useTypes(standardClassIdsType, constructClassLikeTypeImport)
}
impl(resolvedQualifier) {
@@ -375,17 +379,17 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
impl(resolvedReifiedParameterReference)
impl(returnExpression) {
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
defaultBuiltInType("Nothing")
useTypes(implicitNothingTypeRefType)
}
impl(stringConcatenationCall) {
defaultTypeRefWithSource("FirImplicitStringTypeRef")
defaultBuiltInType("String")
useTypes(implicitStringTypeRefType)
}
impl(throwExpression) {
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
defaultBuiltInType("Nothing")
useTypes(implicitNothingTypeRefType)
}
@@ -394,7 +398,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(expression, "FirUnitExpression") {
defaultTypeRefWithSource("FirImplicitUnitTypeRef")
defaultBuiltInType("Unit")
useTypes(implicitUnitTypeRefType)
publicImplementation()
}
@@ -422,11 +426,12 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(whenSubjectExpression) {
default("typeRef") {
value = "whenRef.value.subject?.typeRef ?: org.jetbrains.kotlin.fir.types.impl.FirImplicitUnitTypeRef(source)"
default("coneTypeOrNull") {
value = "whenRef.value.subject?.coneTypeOrNull ?: StandardClassIds.Unit.constructClassLikeType()"
withGetter = true
}
useTypes(whenExpression)
useTypes(whenExpression, standardClassIdsType, constructClassLikeTypeImport)
useTypes(standardClassIdsType, constructClassLikeTypeImport)
}
impl(desugaredAssignmentValueReferenceExpression) {
@@ -434,16 +439,16 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(wrappedDelegateExpression) {
default("typeRef") {
default("coneTypeOrNull") {
delegate = "expression"
}
}
impl(enumEntryDeserializedAccessExpression) {
noSource()
default("typeRef") {
value = "buildResolvedTypeRef { type = enumClassId.toLookupTag().constructClassType(emptyArray(), false) }"
useTypes(buildResolvedTypeRefImport, toLookupTagImport, constructClassTypeImport)
default("coneTypeOrNull") {
value = "enumClassId.toLookupTag().constructClassType(emptyArray(), false)"
useTypes(toLookupTagImport, constructClassTypeImport)
}
}
@@ -520,18 +525,18 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
impl(errorExpression) {
default("typeRef", "FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic), false)")
useTypes(errorTypeRefImplType, coneStubDiagnosticType)
default("coneTypeOrNull", "ConeErrorType(ConeStubDiagnostic(diagnostic))")
useTypes(coneErrorTypeType, coneStubDiagnosticType)
}
impl(qualifiedErrorAccessExpression) {
default("typeRef", "FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic), false)")
useTypes(errorTypeRefImplType, coneStubDiagnosticType)
default("coneTypeOrNull", "ConeErrorType(ConeStubDiagnostic(diagnostic))")
useTypes(coneErrorTypeType, coneStubDiagnosticType)
}
impl(errorFunction) {
defaultNull("receiverParameter", "body", withGetter = true)
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic, false)")
default("returnTypeRef", "FirErrorTypeRefImpl(null, null, diagnostic)")
useTypes(errorTypeRefImplType)
}
@@ -553,12 +558,12 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
impl(fromMissingDependenciesNamedReference)
impl(breakExpression) {
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
defaultBuiltInType("Nothing")
useTypes(implicitNothingTypeRefType)
}
impl(continueExpression) {
defaultTypeRefWithSource("FirImplicitNothingTypeRef")
defaultBuiltInType("Nothing")
useTypes(implicitNothingTypeRefType)
}
@@ -132,7 +132,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
}
expression.configure {
+typeRefField
+field("coneTypeOrNull", coneKotlinTypeType, nullable = true, withReplace = true)
+annotations
}
@@ -146,7 +146,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
block.configure {
+fieldList(statement).withTransform()
+typeRefField
needTransformOtherChildren()
}
@@ -250,6 +249,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
typeOperatorCall.configure {
+field("operation", operationType)
+field("conversionTypeRef", typeRef).withTransform()
+booleanField("argFromStubType", withReplace = true)
needTransformOtherChildren()
}
@@ -568,7 +568,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
}
smartCastExpression.configure {
+typeRefField
+field("originalExpression", expression, withReplace = true).withTransform()
+field("typesFromSmartCast", "Collection<ConeKotlinType>", null, customType = coneKotlinTypeType)
+field("smartcastType", typeRef)
@@ -618,6 +617,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
+field("symbol", classLikeSymbolType, nullable = true)
+booleanField("isNullableLHSForCallableReference", withReplace = true)
+booleanField("resolvedToCompanionObject", withReplace = true)
+booleanField("canBeValue", withReplace = true)
+booleanField("isFullyQualified")
+fieldList("nonFatalDiagnostics", coneDiagnosticType, useMutableOrEmpty = true)
+typeArguments.withTransform()
@@ -695,6 +695,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
+field("boundSymbol", firBasedSymbolType, "*", nullable = true, withReplace = true)
+intField("contextReceiverNumber", withReplace = true)
+booleanField("isImplicit")
+field("diagnostic", coneDiagnosticType, nullable = true, withReplace = true)
}
typeRef.configure {
@@ -704,7 +705,6 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
resolvedTypeRef.configure {
+field("type", coneKotlinTypeType)
+field("delegatedTypeRef", typeRef, nullable = true)
+booleanField("isFromStubType")
}
typeRefWithNullability.configure {
@@ -16,11 +16,13 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.fir.tree.generator.context.generatedType
import org.jetbrains.kotlin.fir.tree.generator.context.type
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeSimpleKotlinType
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.SmartcastStability
import org.jetbrains.kotlin.types.Variance
@@ -44,8 +46,10 @@ val classIdType = type(ClassId::class)
val annotationUseSiteTargetType = type(AnnotationUseSiteTarget::class)
val operationKindType = type("contracts.description", "LogicOperationKind")
val coneKotlinTypeType = type(ConeKotlinType::class)
val coneErrorTypeType = type(ConeErrorType::class)
val coneSimpleKotlinTypeType = type(ConeSimpleKotlinType::class)
val coneClassLikeTypeType = type(ConeClassLikeType::class)
val standardClassIdsType = type(StandardClassIds::class)
val whenRefType = generatedType("", "FirExpressionRef<FirWhenExpression>")
val referenceToSimpleExpressionType = generatedType("", "FirExpressionRef<FirExpression>")
@@ -5,9 +5,11 @@
package org.jetbrains.kotlin.fir.tree.generator.context
import org.jetbrains.kotlin.fir.tree.generator.constructClassLikeTypeImport
import org.jetbrains.kotlin.fir.tree.generator.model.*
import org.jetbrains.kotlin.fir.tree.generator.noReceiverExpressionType
import org.jetbrains.kotlin.fir.tree.generator.printer.call
import org.jetbrains.kotlin.fir.tree.generator.standardClassIdsType
abstract class AbstractFirTreeImplementationConfigurator {
private val elementsWithImpl = mutableSetOf<Element>()
@@ -119,10 +121,9 @@ abstract class AbstractFirTreeImplementationConfigurator {
}
}
fun defaultTypeRefWithSource(typeRefClass: String) {
default("typeRef", "$typeRefClass(source?.fakeElement(KtFakeSourceElementKind.ImplicitTypeRef))")
implementation.arbitraryImportables += ArbitraryImportable("org.jetbrains.kotlin", "KtFakeSourceElementKind")
implementation.arbitraryImportables += ArbitraryImportable("org.jetbrains.kotlin", "fakeElement")
fun defaultBuiltInType(type: String) {
default("coneTypeOrNull", "StandardClassIds.$type.constructClassLikeType()")
useTypes(standardClassIdsType, constructClassLikeTypeImport)
}
fun defaultTrue(field: String, withGetter: Boolean = false) {
@@ -14,7 +14,9 @@ val resolvedDeclarationStatusImport = ArbitraryImportable("org.jetbrains.kotlin.
val buildResolvedTypeRefImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types.builder", "buildResolvedTypeRef")
val constructClassTypeImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "constructClassType")
val constructClassLikeTypeImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "constructClassLikeType")
val toLookupTagImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "toLookupTag")
val coneTypeOrNullImport = ArbitraryImportable("org.jetbrains.kotlin.fir.types", "coneTypeOrNull")
val fakeSourceElementKindImport = ArbitraryImportable("org.jetbrains.kotlin", "KtFakeSourceElementKind")
val fakeElementImport = ArbitraryImportable("org.jetbrains.kotlin", "fakeElement")