diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirBodyLazyResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirBodyLazyResolver.kt index 707ee099898..361ff212d37 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirBodyLazyResolver.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirBodyLazyResolver.kt @@ -125,7 +125,7 @@ private class LLFirBodyTargetResolver( } } - return false + return super.doResolveWithoutLock(target) } private fun calculateControlFlowGraph(target: FirRegularClass) { diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirCompilerAnnotationsLazyResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirCompilerAnnotationsLazyResolver.kt index 7d492f9ba6f..da1d8df6ca0 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirCompilerAnnotationsLazyResolver.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirCompilerAnnotationsLazyResolver.kt @@ -102,7 +102,10 @@ private class LLFirCompilerRequiredAnnotationsTargetResolver( } override fun doResolveWithoutLock(target: FirElementWithResolveState): Boolean { - if (target is FirFile) return false + if (target is FirFile) { + resolveFileAnnotationContainerIfNeeded(target) + return false + } when (target) { is FirRegularClass, is FirScript, is FirCodeFragment -> {} diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirStatusLazyResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirStatusLazyResolver.kt index bfcb6720470..aae33a2677d 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirStatusLazyResolver.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirStatusLazyResolver.kt @@ -148,9 +148,7 @@ private class LLFirStatusTargetResolver( true } - else -> { - false - } + else -> super.doResolveWithoutLock(target) } private inline fun performResolveWithOverriddenCallables( diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirSupertypeLazyResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirSupertypeLazyResolver.kt index 850a89633a1..ad24d314846 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirSupertypeLazyResolver.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirSupertypeLazyResolver.kt @@ -119,8 +119,11 @@ private class LLFirSuperTypeTargetResolver( resolver = { supertypeResolver.resolveTypeAliasSupertype(target, it, resolveRecursively = false) }, superTypeUpdater = { target.replaceExpandedTypeRef(it.single()) }, ) - else -> performCustomResolveUnderLock(target) { - // just update the phase + else -> { + resolveFileAnnotationContainerIfNeeded(target) + performCustomResolveUnderLock(target) { + // just update the phase + } } } diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt index 84995d5ee9b..c577e770e73 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirTargetResolver.kt @@ -28,6 +28,17 @@ internal abstract class LLFirTargetResolver( val nestedClassesStack: List get() = _nestedClassesStack.toList() + /** + * Must be executed without a lock + */ + protected fun LLFirTargetResolver.resolveFileAnnotationContainerIfNeeded(elementWithResolveState: FirElementWithResolveState) { + if (elementWithResolveState !is FirFile) return + val annotationContainer = elementWithResolveState.annotationsContainer ?: return + withFile(elementWithResolveState) { + performResolve(annotationContainer) + } + } + protected open fun withFile(firFile: FirFile, action: () -> Unit) { action() } @@ -50,7 +61,11 @@ internal abstract class LLFirTargetResolver( protected open fun checkResolveConsistency() {} - protected open fun doResolveWithoutLock(target: FirElementWithResolveState): Boolean = false + protected open fun doResolveWithoutLock(target: FirElementWithResolveState): Boolean { + resolveFileAnnotationContainerIfNeeded(target) + return false + } + protected abstract fun doLazyResolveUnderLock(target: FirElementWithResolveState) fun resolveDesignation() { @@ -171,4 +186,4 @@ internal abstract class LLFirTargetResolver( } } } -} \ No newline at end of file +} diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.kt b/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.kt index 796a27defce..6b162b732fe 100644 --- a/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.kt +++ b/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.kt @@ -1,5 +1,6 @@ // RESOLVE_FILE +@file:[Deprecated("deprecated file") Anno(1)] package one annotation class Anno(val i: Int) diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.txt b/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.txt index 021cdbf7dc6..ce95d0a4270 100644 --- a/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.txt +++ b/analysis/low-level-api-fir/testdata/lazyResolve/fileElements.txt @@ -1,5 +1,8 @@ RAW_FIR: FILE: [ResolvedTo(IMPORTS)] fileElements.kt + @FILE:Deprecated[Unresolved](LAZY_EXPRESSION) + @FILE:Anno[Unresolved](LAZY_EXPRESSION) + [ResolvedTo(RAW_FIR)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -36,6 +39,9 @@ FILE: [ResolvedTo(IMPORTS)] fileElements.kt IMPORTS: FILE: [ResolvedTo(IMPORTS)] fileElements.kt + @FILE:Deprecated[Unresolved](LAZY_EXPRESSION) + @FILE:Anno[Unresolved](LAZY_EXPRESSION) + [ResolvedTo(RAW_FIR)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -72,6 +78,9 @@ FILE: [ResolvedTo(IMPORTS)] fileElements.kt COMPILER_REQUIRED_ANNOTATIONS: FILE: [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] fileElements.kt + @FILE:R|kotlin/Deprecated|[CompilerRequiredAnnotations](String(deprecated file)) + @FILE:Anno[Unresolved](LAZY_EXPRESSION) + [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -108,6 +117,9 @@ FILE: [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] fileElements.kt COMPANION_GENERATION: FILE: [ResolvedTo(COMPANION_GENERATION)] fileElements.kt + @FILE:R|kotlin/Deprecated|[CompilerRequiredAnnotations](String(deprecated file)) + @FILE:Anno[Unresolved](LAZY_EXPRESSION) + [ResolvedTo(COMPANION_GENERATION)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -144,6 +156,9 @@ FILE: [ResolvedTo(COMPANION_GENERATION)] fileElements.kt SUPER_TYPES: FILE: [ResolvedTo(SUPER_TYPES)] fileElements.kt + @FILE:R|kotlin/Deprecated|[CompilerRequiredAnnotations](String(deprecated file)) + @FILE:Anno[Unresolved](LAZY_EXPRESSION) + [ResolvedTo(SUPER_TYPES)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -180,6 +195,9 @@ FILE: [ResolvedTo(SUPER_TYPES)] fileElements.kt TYPES: FILE: [ResolvedTo(TYPES)] fileElements.kt + @FILE:R|kotlin/Deprecated|[Types](String(deprecated file)) + @FILE:R|one/Anno|[Types](LAZY_EXPRESSION) + [ResolvedTo(TYPES)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -216,6 +234,9 @@ FILE: [ResolvedTo(TYPES)] fileElements.kt STATUS: FILE: [ResolvedTo(STATUS)] fileElements.kt + @FILE:R|kotlin/Deprecated|[Types](String(deprecated file)) + @FILE:R|one/Anno|[Types](LAZY_EXPRESSION) + [ResolvedTo(STATUS)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -252,6 +273,9 @@ FILE: [ResolvedTo(STATUS)] fileElements.kt EXPECT_ACTUAL_MATCHING: FILE: [ResolvedTo(EXPECT_ACTUAL_MATCHING)] fileElements.kt + @FILE:R|kotlin/Deprecated|[Types](String(deprecated file)) + @FILE:R|one/Anno|[Types](LAZY_EXPRESSION) + [ResolvedTo(EXPECT_ACTUAL_MATCHING)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -288,6 +312,9 @@ FILE: [ResolvedTo(EXPECT_ACTUAL_MATCHING)] fileElements.kt ARGUMENTS_OF_ANNOTATIONS: FILE: [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] fileElements.kt + @FILE:R|kotlin/Deprecated|[Types](String(deprecated file)) + @FILE:R|one/Anno|[Types](IntegerLiteral(1)) + [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -324,6 +351,9 @@ FILE: [ResolvedTo(ARGUMENTS_OF_ANNOTATIONS)] fileElements.kt CONTRACTS: FILE: [ResolvedTo(CONTRACTS)] fileElements.kt + @FILE:R|kotlin/Deprecated|[Types](String(deprecated file)) + @FILE:R|one/Anno|[Types](IntegerLiteral(1)) + [ResolvedTo(CONTRACTS)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -360,6 +390,9 @@ FILE: [ResolvedTo(CONTRACTS)] fileElements.kt IMPLICIT_TYPES_BODY_RESOLVE: FILE: [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fileElements.kt + @FILE:R|kotlin/Deprecated|[Types](String(deprecated file)) + @FILE:R|one/Anno|[Types](IntegerLiteral(1)) + [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] annotations container public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { LAZY_super @@ -396,13 +429,16 @@ FILE: [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fileElements.kt ANNOTATIONS_ARGUMENTS_MAPPING: FILE: [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] fileElements.kt - public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { - public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { + @FILE:R|kotlin/Deprecated|[Types](message = String(deprecated file)) + @FILE:R|one/Anno|[Types](i = Int(1)) + [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] annotations container + public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| { + public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=one/Anno.i] i: R|kotlin/Int|): R|one/Anno| { LAZY_super } - public? final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val i: Int = R|/i| - public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] get(): Int + public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val i: R|kotlin/Int| = R|/i| + public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] get(): R|kotlin/Int| } public? final? [ResolvedTo(RAW_FIR)] val a: = LAZY_EXPRESSION @@ -432,13 +468,16 @@ FILE: [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] fileElements.kt BODY_RESOLVE: FILE: [ResolvedTo(BODY_RESOLVE)] fileElements.kt - public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| { - public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=one/Anno.i] i: Int): R|one/Anno| { + @FILE:R|kotlin/Deprecated|[Types](message = String(deprecated file)) + @FILE:R|one/Anno|[Types](i = Int(1)) + [ResolvedTo(BODY_RESOLVE)] annotations container + public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| { + public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=one/Anno.i] i: R|kotlin/Int|): R|one/Anno| { LAZY_super } - public? final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val i: Int = R|/i| - public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] get(): Int + public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val i: R|kotlin/Int| = R|/i| + public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] get(): R|kotlin/Int| } public? final? [ResolvedTo(RAW_FIR)] val a: = LAZY_EXPRESSION @@ -468,6 +507,9 @@ FILE: [ResolvedTo(BODY_RESOLVE)] fileElements.kt FILE RAW TO BODY: FILE: [ResolvedTo(BODY_RESOLVE)] fileElements.kt + @FILE:R|kotlin/Deprecated|[Types](message = String(deprecated file)) + @FILE:R|one/Anno|[Types](i = Int(1)) + [ResolvedTo(BODY_RESOLVE)] annotations container public final [ResolvedTo(BODY_RESOLVE)] annotation class Anno : R|kotlin/Annotation| { public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=Anno] constructor([ResolvedTo(BODY_RESOLVE)] [CorrespondingProperty=one/Anno.i] i: R|kotlin/Int|): R|one/Anno| { super()