diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaClass.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaClass.kt index f8bdacc5479..2bf1edc50b8 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaClass.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaClass.kt @@ -32,6 +32,7 @@ import kotlin.properties.Delegates class FirJavaClass @FirImplementationDetail internal constructor( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val name: Name, override val annotations: MutableList, diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaConstructor.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaConstructor.kt index dfc9cb72f87..5f9109d8363 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaConstructor.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaConstructor.kt @@ -37,6 +37,7 @@ class FirJavaConstructor @FirImplementationDetail constructor( override val typeParameters: MutableList, annotationBuilder: () -> List, override var status: FirDeclarationStatus, + @Volatile override var resolvePhase: FirResolvePhase, override val dispatchReceiverType: ConeKotlinType?, ) : FirConstructor() { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaField.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaField.kt index efd20e9759a..36df4a72a19 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaField.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaField.kt @@ -36,6 +36,7 @@ class FirJavaField @FirImplementationDetail constructor( override val moduleData: FirModuleData, override val symbol: FirFieldSymbol, override val name: Name, + @Volatile override var resolvePhase: FirResolvePhase, override var returnTypeRef: FirTypeRef, override var status: FirDeclarationStatus, diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaMethod.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaMethod.kt index 6811688cf80..a64dc59c40b 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaMethod.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaMethod.kt @@ -50,6 +50,7 @@ import kotlin.properties.Delegates class FirJavaMethod @FirImplementationDetail constructor( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val attributes: FirDeclarationAttributes, override var returnTypeRef: FirTypeRef, diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaValueParameter.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaValueParameter.kt index f0761a35b2d..fb8d33620e6 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaValueParameter.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/declarations/FirJavaValueParameter.kt @@ -30,6 +30,7 @@ import kotlin.contracts.contract class FirJavaValueParameter @FirImplementationDetail constructor( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val attributes: FirDeclarationAttributes, override var returnTypeRef: FirTypeRef, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousFunctionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousFunctionImpl.kt index 1fe38ff8b8c..a04202275e3 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousFunctionImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousFunctionImpl.kt @@ -55,6 +55,7 @@ internal class FirAnonymousFunctionImpl( override val typeParameters: MutableList, override var typeRef: FirTypeRef, ) : FirAnonymousFunction() { + @Volatile override var resolvePhase: FirResolvePhase = FirResolvePhase.DECLARATIONS override var status: FirDeclarationStatus = FirResolvedDeclarationStatusImpl.DEFAULT_STATUS_FOR_STATUSLESS_DECLARATIONS diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt index 2a66b064a8b..8ba4062dace 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousInitializerImpl.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirAnonymousInitializerImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt index b3ddee8fcd2..7c4c2f13d76 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirAnonymousObjectImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt index cf04fcffa0d..880a018cffc 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirConstructorImpl.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirConstructorImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultSetterValueParameter.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultSetterValueParameter.kt index 4c9d3e2000d..fd08b563f69 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultSetterValueParameter.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirDefaultSetterValueParameter.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirDefaultSetterValueParameter( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirEnumEntryImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirEnumEntryImpl.kt index eaf8abb2ea6..c2d88052f86 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirEnumEntryImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirEnumEntryImpl.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirEnumEntryImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt index 812e15254d1..8462db1ff20 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorFunctionImpl.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirErrorFunctionImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt index 1a447ba0e9a..169d36dec36 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirErrorPropertyImpl.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirErrorPropertyImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFieldImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFieldImpl.kt index 8062cf00554..d6da034a14d 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFieldImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFieldImpl.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.visitors.* class FirFieldImpl @FirImplementationDetail constructor( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt index a5aff82e8dd..834149f2ad4 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirFileImpl.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirFileImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructor.kt index 7b1db6e2390..57638d8e42b 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPrimaryConstructor.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirPrimaryConstructor( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt index cfd63d65356..b094dda47ae 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyAccessorImpl.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.fir.visitors.* open class FirPropertyAccessorImpl @FirImplementationDetail constructor( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt index a04864c6b59..b1f1108e2e7 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirPropertyImpl.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirPropertyImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirRegularClassImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirRegularClassImpl.kt index 8c120f23e33..4465c304ce1 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirRegularClassImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirRegularClassImpl.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirRegularClassImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirSimpleFunctionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirSimpleFunctionImpl.kt index 94e138b2d5b..d6af32d1e2d 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirSimpleFunctionImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirSimpleFunctionImpl.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirSimpleFunctionImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeAliasImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeAliasImpl.kt index 4fd37cfc841..3dbaea91701 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeAliasImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeAliasImpl.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirTypeAliasImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt index 1581d87eb78..4e38a1ed476 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirTypeParameterImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt index e925bbc2855..e0e79b8d714 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirValueParameterImpl.kt @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.fir.visitors.* internal class FirValueParameterImpl( override val source: FirSourceElement?, override val moduleData: FirModuleData, + @Volatile override var resolvePhase: FirResolvePhase, override val origin: FirDeclarationOrigin, override val attributes: FirDeclarationAttributes, diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index c2b1f8e920d..065a44e86f4 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -73,7 +73,7 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild declaration.configure { +symbolWithPackage("fir.symbols", "FirBasedSymbol", "out FirDeclaration") +field("moduleData", firModuleDataType) - +field("resolvePhase", resolvePhaseType, withReplace = true).apply { isMutable = true } + +field("resolvePhase", resolvePhaseType, withReplace = true).apply { isMutable = true; isVolatile = true } +field("origin", declarationOriginType) +field("attributes", declarationAttributesType) shouldBeAbstractClass() diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/model/Field.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/model/Field.kt index 2b5d3ac5f6b..7994edba8be 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/model/Field.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/model/Field.kt @@ -11,6 +11,7 @@ sealed class Field : Importable { abstract val name: String open val arguments = mutableListOf() abstract val nullable: Boolean + abstract var isVolatile: Boolean open var withReplace: Boolean = false abstract val isFirType: Boolean @@ -71,6 +72,7 @@ sealed class Field : Importable { class FieldWithDefault(val origin: Field) : Field() { override val name: String get() = origin.name override val type: String get() = origin.type + override var isVolatile: Boolean = origin.isVolatile override val nullable: Boolean get() = origin.nullable override var withReplace: Boolean get() = origin.withReplace @@ -123,7 +125,8 @@ class SimpleField( override val packageName: String?, val customType: Importable? = null, override val nullable: Boolean, - override var withReplace: Boolean + override var withReplace: Boolean, + override var isVolatile: Boolean = false ) : Field() { override val isFirType: Boolean = false override val fullQualifiedName: String? @@ -138,7 +141,8 @@ class SimpleField( packageName, customType, nullable, - withReplace + withReplace, + isVolatile ).apply { withBindThis = this@SimpleField.withBindThis } @@ -150,7 +154,8 @@ class SimpleField( newType.packageName, customType, nullable, - withReplace + withReplace, + isVolatile ).also { it.withBindThis = withBindThis updateFieldsInCopy(it) @@ -170,6 +175,7 @@ class FirField( } override val type: String get() = element.type + override var isVolatile: Boolean = false override val packageName: String? get() = element.packageName override val isFirType: Boolean = true @@ -202,6 +208,7 @@ class FieldList( override val nullable: Boolean get() = false + override var isVolatile: Boolean = false override var isMutable: Boolean = true override fun internalCopy(): Field { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/element.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/element.kt index 2de0a352c22..0ed3db2dc42 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/element.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/element.kt @@ -37,7 +37,6 @@ fun Element.generateCode(generationPath: File): GeneratedFile { fun SmartPrinter.printElement(element: Element) { with(element) { val isInterface = kind == Kind.Interface || kind == Kind.SealedInterface - fun abstract() { if (!isInterface) { print("abstract ") diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/field.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/field.kt index 285017bfc56..a4ce7590d1c 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/field.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/field.kt @@ -6,10 +6,14 @@ package org.jetbrains.kotlin.fir.tree.generator.printer import org.jetbrains.kotlin.fir.tree.generator.model.Field +import org.jetbrains.kotlin.fir.tree.generator.model.SimpleField import org.jetbrains.kotlin.util.SmartPrinter fun SmartPrinter.printField(field: Field, isImplementation: Boolean, override: Boolean, end: String) { + if (isImplementation && !field.isVal && field.isVolatile) { + println("@Volatile") + } if (override) { print("override ") } @@ -23,6 +27,9 @@ fun SmartPrinter.printField(field: Field, isImplementation: Boolean, override: B } fun SmartPrinter.printFieldWithDefaultInImplementation(field: Field) { + if (!field.isVal && field.isVolatile) { + println("@Volatile") + } val defaultValue = field.defaultValueInImplementation print("override ") if (field.isVal) { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/implementation.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/implementation.kt index 20041763457..3041f9555ce 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/implementation.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/printer/implementation.kt @@ -73,6 +73,7 @@ fun SmartPrinter.printImplementation(implementation: Implementation) { } println("(") withIndent { + fieldsWithoutDefault.forEachIndexed { _, field -> printField(field, isImplementation = true, override = true, end = ",") } @@ -89,6 +90,7 @@ fun SmartPrinter.printImplementation(implementation: Implementation) { withIndent { if (isInterface || isAbstract) { allFields.forEach { + abstract() printField(it, isImplementation = true, override = true, end = "") } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/IdeFirPhaseManager.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/IdeFirPhaseManager.kt index b0c94c63aca..ad73840176f 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/IdeFirPhaseManager.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/IdeFirPhaseManager.kt @@ -25,18 +25,16 @@ internal class IdeFirPhaseManager( symbol: FirBasedSymbol<*>, requiredPhase: FirResolvePhase ) { - val fir = symbol.fir as FirDeclaration + val fir = symbol.fir try { - if (fir.resolvePhase < requiredPhase) { - lazyDeclarationResolver.lazyResolveDeclaration( - firDeclarationToResolve = fir, - moduleFileCache = cache, - scopeSession = ScopeSession(), - toPhase = requiredPhase, - checkPCE = true, - skipLocalDeclaration = true, - ) - } + lazyDeclarationResolver.lazyResolveDeclaration( + firDeclarationToResolve = fir, + moduleFileCache = cache, + scopeSession = ScopeSession(), + toPhase = requiredPhase, + checkPCE = true, + skipLocalDeclaration = true, + ) } catch (e: Throwable) { sessionInvalidator.invalidate(fir.moduleData.session) throw e diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/FirModuleResolveState.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/FirModuleResolveState.kt index 5f7004736d2..40ba8a46ab1 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/FirModuleResolveState.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/FirModuleResolveState.kt @@ -13,8 +13,6 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.InternalForInline import org.jetbrains.kotlin.idea.fir.low.level.api.file.builder.ModuleFileCache import org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.ResolveType -import org.jetbrains.kotlin.idea.fir.low.level.api.sessions.FirIdeSourcesSession -import org.jetbrains.kotlin.idea.fir.low.level.api.util.getElementTextInContext import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtFile @@ -50,20 +48,6 @@ abstract class FirModuleResolveState { internal abstract fun collectDiagnosticsForFile(ktFile: KtFile, filter: DiagnosticCheckerFilter): Collection - internal inline fun withLock(declaration: D, declarationLockType: DeclarationLockType, action: (D) -> R): R { - val originalDeclaration = (declaration as? FirCallableDeclaration)?.unwrapFakeOverrides() ?: declaration - val session = originalDeclaration.moduleData.session - return when { - originalDeclaration.origin == FirDeclarationOrigin.Source && session is FirIdeSourcesSession -> { - val cache = session.cache - val file = tryGetCachedFirFile(declaration, cache) - ?: error("Fir file was not found for\n${declaration.render()}\n${(declaration.psi as? KtElement)?.getElementTextInContext()}") - cache.firFileLockProvider.withLock(file, declarationLockType) { action(declaration) } - } - else -> action(declaration) - } - } - @InternalForInline abstract fun findSourceFirDeclaration( ktDeclaration: KtDeclaration, diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/LowLevelFirApiFacade.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/LowLevelFirApiFacade.kt index 3efdab19d09..9d522de768c 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/LowLevelFirApiFacade.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/api/LowLevelFirApiFacade.kt @@ -125,7 +125,7 @@ fun D.withFirDeclaration( action: (D) -> R, ): R { resolvedFirToPhase(phase, resolveState) - return resolveState.withLock(this, DeclarationLockType.READ_LOCK, action) + return action(this) } /** @@ -138,31 +138,7 @@ fun D.withFirDeclaration( action: (D) -> R, ): R { resolvedFirToType(type, resolveState) - return resolveState.withLock(this, DeclarationLockType.READ_LOCK, action) -} - -/** - * Executes [action] with given [FirDeclaration] under write lock, so resolve **is possible** inside [action] - */ -fun D.withFirDeclarationInWriteLock( - resolveState: FirModuleResolveState, - phase: FirResolvePhase = FirResolvePhase.RAW_FIR, - action: (D) -> R, -): R { - resolvedFirToPhase(phase, resolveState) - return resolveState.withLock(this, DeclarationLockType.WRITE_LOCK, action) -} - -/** - * Executes [action] with given [FirDeclaration] under write lock, so resolve **is possible** inside [action] - */ -fun D.withFirDeclarationInWriteLock( - resolveState: FirModuleResolveState, - resolveType: ResolveType = ResolveType.BodyResolveWithChildren, - action: (D) -> R, -): R { - resolvedFirToType(resolveType, resolveState) - return resolveState.withLock(this, DeclarationLockType.WRITE_LOCK, action) + return action(this) } /** diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/LockProvider.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/LockProvider.kt index b921014c8ed..1a0a73150cc 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/LockProvider.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/LockProvider.kt @@ -8,66 +8,24 @@ package org.jetbrains.kotlin.idea.fir.low.level.api.file.builder import com.google.common.collect.MapMaker import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.idea.fir.low.level.api.annotations.PrivateForInline -import org.jetbrains.kotlin.idea.fir.low.level.api.api.DeclarationLockType import org.jetbrains.kotlin.idea.fir.low.level.api.util.lockWithPCECheck import java.util.concurrent.ConcurrentMap -import java.util.concurrent.locks.ReadWriteLock -import java.util.concurrent.locks.ReentrantReadWriteLock +import java.util.concurrent.locks.ReentrantLock import kotlin.concurrent.withLock internal class LockProvider { - private val locks: ConcurrentMap = MapMaker().weakKeys().makeMap() - - @OptIn(PrivateForInline::class) - private val deadLockGuard = DeadLockGuard() + private val locks: ConcurrentMap = MapMaker().weakKeys().makeMap() @Suppress("NOTHING_TO_INLINE") - private inline fun getLockFor(key: KEY) = locks.getOrPut(key) { ReentrantReadWriteLock() } + private inline fun getLockFor(key: KEY) = locks.getOrPut(key) { ReentrantLock() } @OptIn(PrivateForInline::class) - inline fun withReadLock(key: KEY, action: () -> R): R { - val readLock = getLockFor(key).readLock() - return deadLockGuard.guardReadLock { readLock.withLock { action() } } - } + inline fun withWriteLock(key: KEY, action: () -> R): R = + getLockFor(key).withLock(action) @OptIn(PrivateForInline::class) - inline fun withWriteLock(key: KEY, action: () -> R): R { - val writeLock = getLockFor(key).writeLock() - return deadLockGuard.guardWriteLock { writeLock.withLock { action() } } - } - - @OptIn(PrivateForInline::class) - inline fun withWriteLockPCECheck(key: KEY, lockingIntervalMs: Long, action: () -> R): R { - val writeLock = getLockFor(key).writeLock() - return deadLockGuard.guardWriteLock { writeLock.lockWithPCECheck(lockingIntervalMs, action) } - } - - inline fun withLock(declaration: KEY, declarationLockType: DeclarationLockType, action: () -> R): R = when (declarationLockType) { - DeclarationLockType.READ_LOCK -> withReadLock(declaration, action) - DeclarationLockType.WRITE_LOCK -> withWriteLock(declaration, action) - } -} - -@PrivateForInline -internal class DeadLockGuard { - private val readLocksCount = ThreadLocal.withInitial { 0 } - - inline fun guardReadLock(action: () -> R): R { - readLocksCount.set(readLocksCount.get() + 1) - return try { - action() - } finally { - readLocksCount.set(readLocksCount.get() - 1) - } - } - - inline fun guardWriteLock(action: () -> R): R { - - if (readLocksCount.get() > 0) { - throw ReadWriteDeadLockException() - } - return action() - } + inline fun withWriteLockPCECheck(key: KEY, lockingIntervalMs: Long, action: () -> R): R = + getLockFor(key).lockWithPCECheck(lockingIntervalMs, action) } /** @@ -83,6 +41,4 @@ internal inline fun LockProvider.runCustomResolveUnderLock( } else { withWriteLock(key = firFile, action = body) } -} - -class ReadWriteDeadLockException : IllegalStateException("Acquiring write lock when read lock hold") +} \ No newline at end of file diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/ModuleFileCache.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/ModuleFileCache.kt index 259fee9e2bb..3c278dbc4e8 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/ModuleFileCache.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/builder/ModuleFileCache.kt @@ -50,12 +50,6 @@ internal abstract class ModuleFileCache { abstract fun getCachedFirFile(ktFile: KtFile): FirFile? abstract val firFileLockProvider: LockProvider - - inline fun withReadLockOn(declaration: D, action: (D) -> R): R { - val file = getContainerFirFile(declaration) - ?: error("No fir file found for\n${declaration.render()}") - return firFileLockProvider.withReadLock(file) { action(declaration) } - } } internal class ModuleFileCacheImpl(override val session: FirSession) : ModuleFileCache() { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/structure/FileStructure.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/structure/FileStructure.kt index 21cd122022d..59388758451 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/structure/FileStructure.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/file/structure/FileStructure.kt @@ -123,9 +123,10 @@ internal class FileStructure private constructor( toPhase = FirResolvePhase.BODY_RESOLVE, checkPCE = true, ) - return moduleFileCache.firFileLockProvider.withReadLock(firFile) { - FileElementFactory.createFileStructureElement(firDeclaration, declaration, firFile, moduleFileCache.firFileLockProvider) - } + return FileElementFactory.createFileStructureElement(firDeclaration, declaration, firFile, moduleFileCache.firFileLockProvider) +// return moduleFileCache.firFileLockProvider.withReadLock(firFile) { +// FileElementFactory.createFileStructureElement(firDeclaration, declaration, firFile, moduleFileCache.firFileLockProvider) +// } } private fun createStructureElement(container: KtAnnotated): FileStructureElement = when (container) { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolveToType.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolveToType.kt index e76ad5ef6d3..9a166ec21bf 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolveToType.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolveToType.kt @@ -41,40 +41,26 @@ internal fun FirLazyDeclarationResolver.lazyResolveDeclaration( require(firDeclaration is FirCallableDeclaration) { "CallableReturnType type cannot be applied to ${firDeclaration::class.qualifiedName}" } - //Need to be sync - if (firDeclaration.returnTypeRef is FirResolvedTypeRef) return - val containingFile = firDeclaration.getContainingFile() - if (containingFile != null) { - moduleFileCache.firFileLockProvider.runCustomResolveUnderLock(containingFile, checkPCE) { - if (firDeclaration.returnTypeRef !is FirResolvedTypeRef) { - lazyResolveDeclaration( - firDeclarationToResolve = firDeclaration, - moduleFileCache = moduleFileCache, - toPhase = FirResolvePhase.TYPES, - scopeSession = scopeSession, - checkPCE = checkPCE, - ) - } - if (firDeclaration.returnTypeRef !is FirResolvedTypeRef) { - lazyResolveDeclaration( - firDeclarationToResolve = firDeclaration, - moduleFileCache = moduleFileCache, - toPhase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, - scopeSession = scopeSession, - checkPCE = checkPCE, - ) - } - check(firDeclaration.returnTypeRef is FirResolvedTypeRef) - } - } else { + + if (firDeclaration.resolvePhase < FirResolvePhase.TYPES) { lazyResolveDeclaration( firDeclarationToResolve = firDeclaration, moduleFileCache = moduleFileCache, - toPhase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, + toPhase = FirResolvePhase.TYPES, scopeSession = scopeSession, checkPCE = checkPCE, ) } + if (firDeclaration.returnTypeRef is FirResolvedTypeRef) return + + lazyResolveDeclaration( + firDeclarationToResolve = firDeclaration, + moduleFileCache = moduleFileCache, + toPhase = FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE, + scopeSession = scopeSession, + checkPCE = checkPCE, + ) + check(firDeclaration.returnTypeRef is FirResolvedTypeRef) } ResolveType.BodyResolveWithChildren, ResolveType.CallableBodyResolve -> { require(firDeclaration is FirCallableDeclaration || toResolveType != ResolveType.CallableBodyResolve) { diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolver.kt b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolver.kt index 90d8ecb6397..103546b8de0 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolver.kt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/src/org/jetbrains/kotlin/idea/fir/low/level/api/lazy/resolve/FirLazyDeclarationResolver.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticPropertyAccessor import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirAnnotationResolveStatus import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.transformers.FirImportResolveTransformer import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirTowerDataContextCollector @@ -41,6 +42,7 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui checkPCE: Boolean, collector: FirTowerDataContextCollector? = null, ) { + if (firFile.resolvePhase >= FirResolvePhase.IMPORTS) return moduleFileCache.firFileLockProvider.runCustomResolveUnderLock(firFile, checkPCE) { resolveFileAnnotationsWithoutLock( firFile = firFile, @@ -63,6 +65,7 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui scopeSession: ScopeSession, collector: FirTowerDataContextCollector? = null, ) { + if (firFile.resolvePhase >= FirResolvePhase.IMPORTS) return lazyResolveFileDeclarationWithoutLock( firFile = firFile, moduleFileCache = moduleFileCache, @@ -116,6 +119,8 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui scopeSession: ScopeSession, checkPCE: Boolean = false, ) { + if (toPhase == FirResolvePhase.RAW_FIR) return + if (firFile.resolvePhase >= toPhase) return moduleFileCache.firFileLockProvider.runCustomResolveUnderLock(firFile, checkPCE) { lazyResolveFileDeclarationWithoutLock( firFile = firFile, @@ -136,8 +141,9 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui collector: FirTowerDataContextCollector? = null, ) { if (toPhase == FirResolvePhase.RAW_FIR) return - if (firFile.resolvePhase >= toPhase) return - if (firFile.resolvePhase == FirResolvePhase.RAW_FIR) { + val resolvePhase = firFile.resolvePhase + if (resolvePhase >= toPhase) return + if (resolvePhase == FirResolvePhase.RAW_FIR) { firFile.transform(FirImportResolveTransformer(firFile.moduleData.session), null) firFile.replaceResolvePhase(FirResolvePhase.IMPORTS) } @@ -245,6 +251,7 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui } + if (firDeclarationToResolve.resolvePhase >= toPhase) return moduleFileCache.firFileLockProvider.runCustomResolveUnderLock(designation.firFile, checkPCE) { runLazyDesignatedResolveWithoutLock( designation = designation, @@ -263,7 +270,9 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui toPhase: FirResolvePhase, checkPCE: Boolean, ) { - if (designation.declaration.resolvePhase >= toPhase) return + if (toPhase == FirResolvePhase.RAW_FIR) return + val declarationResolvePhase = designation.declaration.resolvePhase + if (declarationResolvePhase >= toPhase) return if (designation.firFile.resolvePhase == FirResolvePhase.RAW_FIR) { lazyResolveFileDeclarationWithoutLock( @@ -275,7 +284,7 @@ internal class FirLazyDeclarationResolver(private val firFileBuilder: FirFileBui ) } if (toPhase == FirResolvePhase.IMPORTS) return - var currentPhase = maxOf(designation.declaration.resolvePhase, FirResolvePhase.IMPORTS) + var currentPhase = maxOf(declarationResolvePhase, FirResolvePhase.IMPORTS) while (currentPhase < toPhase) { currentPhase = currentPhase.next diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt index 387a2853727..b98c3991e23 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/utils/FirRefWithValidityCheck.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.idea.fir.low.level.api.api.FirModuleResolveState import org.jetbrains.kotlin.idea.fir.low.level.api.api.withFirDeclaration -import org.jetbrains.kotlin.idea.fir.low.level.api.api.withFirDeclarationInWriteLock import org.jetbrains.kotlin.idea.fir.low.level.api.lazy.resolve.ResolveType import org.jetbrains.kotlin.idea.frontend.api.ValidityTokenOwner import org.jetbrains.kotlin.idea.frontend.api.tokens.ValidityToken @@ -31,16 +30,7 @@ internal class FirRefWithValidityCheck(fir: D, resolveSt ?: throw EntityWasGarbageCollectedException("FirElement") val resolveState = resolveStateWeakRef.get() ?: throw EntityWasGarbageCollectedException("FirModuleResolveState") - return when (phase) { - FirResolvePhase.BODY_RESOLVE -> { - /* - The BODY_RESOLVE phase is the maximum possible phase we can resolve our declaration to - So there is not need to run whole `action` under read lock - */ - action(fir.withFirDeclaration(resolveState, phase) { it }) - } - else -> fir.withFirDeclaration(resolveState, phase) { action(it) } - } + return fir.withFirDeclaration(resolveState, phase) { action(it) } } /** @@ -62,23 +52,7 @@ internal class FirRefWithValidityCheck(fir: D, resolveSt inline fun withFirWithPossibleResolveInside( phase: FirResolvePhase = FirResolvePhase.RAW_FIR, crossinline action: (fir: D) -> R - ): R { - token.assertIsValidAndAccessible() - val fir = firWeakRef.get() - ?: throw EntityWasGarbageCollectedException("FirElement") - val resolveState = resolveStateWeakRef.get() - ?: throw EntityWasGarbageCollectedException("FirModuleResolveState") - return when (phase) { - FirResolvePhase.BODY_RESOLVE -> { - /* - The BODY_RESOLVE phase is the maximum possible phase we can resolve our declaration to - So there is not need to run whole `action` under write lock - */ - action(fir.withFirDeclarationInWriteLock(resolveState, phase) { it }) - } - else -> fir.withFirDeclarationInWriteLock(resolveState, phase) { action(it) } - } - } + ): R = withFir(phase, action) /** * Runs [action] with fir element with write action hold @@ -87,23 +61,7 @@ internal class FirRefWithValidityCheck(fir: D, resolveSt inline fun withFirWithPossibleResolveInside( resolveType: ResolveType = ResolveType.NoResolve, crossinline action: (fir: D) -> R - ): R { - token.assertIsValidAndAccessible() - val fir = firWeakRef.get() - ?: throw EntityWasGarbageCollectedException("FirElement") - val resolveState = resolveStateWeakRef.get() - ?: throw EntityWasGarbageCollectedException("FirModuleResolveState") - return when (resolveType) { - ResolveType.BodyResolveWithChildren -> { - /* - The ResolveType type is the maximum possible phase we can resolve our declaration to - So there is not need to run whole `action` under write lock - */ - action(fir.withFirDeclarationInWriteLock(resolveState, resolveType) { it }) - } - else -> fir.withFirDeclarationInWriteLock(resolveState, resolveType) { action(it) } - } - } + ): R = withFir(resolveType, action) val resolveState get() = resolveStateWeakRef.get() ?: throw EntityWasGarbageCollectedException("FirModuleResolveState") @@ -119,16 +77,7 @@ internal class FirRefWithValidityCheck(fir: D, resolveSt ?: throw EntityWasGarbageCollectedException("FirElement") val resolveState = resolveStateWeakRef.get() ?: throw EntityWasGarbageCollectedException("FirModuleResolveState") - return when (type) { - ResolveType.BodyResolveWithChildren -> { - /* - The CallableBodyResolve type is the maximum possible phase we can resolve our declaration to - So there is not need to run whole `action` under read lock - */ - action(fir.withFirDeclaration(type, resolveState) { it }) - } - else -> fir.withFirDeclaration(type, resolveState) { action(it) } - } + return fir.withFirDeclaration(type, resolveState) { action(it) } } inline fun withFirAndCache(type: ResolveType, crossinline createValue: (fir: D) -> R) =