[LL FIR] annotation calculator for scripts should process only script inself

We shouldn't calculate annotations inside unrelated declarations without lock

^KT-63042
^KT-63282
This commit is contained in:
Dmitrii Gridin
2023-11-07 20:03:50 +01:00
committed by Space Team
parent 4f2750a189
commit ba7c341338
4 changed files with 23 additions and 12 deletions
@@ -11,6 +11,7 @@ import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDesignation
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.forEachDependentDeclaration
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.builder.PsiRawFirBuilder
import org.jetbrains.kotlin.fir.contracts.FirRawContractDescription
@@ -660,6 +661,15 @@ private object FirTargetLazyAnnotationCalculatorTransformer : FirLazyAnnotationT
return regularClass
}
override fun transformScript(script: FirScript, data: FirLazyAnnotationTransformerData): FirScript {
script.transformAnnotations(this, data)
script.forEachDependentDeclaration {
it.transformSingle(this, data)
}
return script
}
override fun transformBlock(block: FirBlock, data: FirLazyAnnotationTransformerData): FirStatement {
// We shouldn't process blocks because there are no lazy annotations
return block
@@ -11,7 +11,7 @@ FILE: [ResolvedTo(IMPORTS)] annotationApplicationArgumentOnStatement.kts
SCRIPT: [ResolvedTo(BODY_RESOLVE)] <script-annotationApplicationArgumentOnStatement.kts>
[ResolvedTo(BODY_RESOLVE)] lval args: R|kotlin/Array<kotlin/String>|
@R|kotlin/annotation/Target|[Types](Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.EXPRESSION|) @R|kotlin/annotation/Retention|[Types](AnnotationRetention#.SOURCE#) public final [ResolvedTo(STATUS)] annotation class Annotation : R|kotlin/Annotation| {
@R|kotlin/annotation/Target|[Types](Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.EXPRESSION|) @R|kotlin/annotation/Retention|[Types](LAZY_EXPRESSION) public final [ResolvedTo(STATUS)] annotation class Annotation : R|kotlin/Annotation| {
public [ResolvedTo(STATUS)] [ContainingClassKey=Annotation] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=/Annotation.name] name: R|kotlin/String|): R|Annotation| {
LAZY_super<R|kotlin/Any|>
}
@@ -25,4 +25,4 @@ FILE: [ResolvedTo(IMPORTS)] annotationApplicationArgumentOnStatement.kts
}
public final [ResolvedTo(BODY_RESOLVE)] val $$result: R|kotlin/Unit| = @R|Annotation|[Types](name = String(y)) R|/x|()
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Unit|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Unit|
@@ -224,7 +224,7 @@ FILE: [ResolvedTo(IMPORTS)] scriptWithTypeAnnotationsOnDeclaration.kts
SCRIPT: [ResolvedTo(ANNOTATION_ARGUMENTS)] <script-scriptWithTypeAnnotationsOnDeclaration.kts>
[ResolvedTo(RAW_FIR)] lval args: R|kotlin/Array<kotlin/String>|
@Target[Unresolved](AnnotationTarget#.TYPE#) public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
@Target[Unresolved](LAZY_EXPRESSION) public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=foo/Anno.position] position: String): R|foo/Anno| {
LAZY_super<R|kotlin/Any|>
}
@@ -237,7 +237,7 @@ FILE: [ResolvedTo(IMPORTS)] scriptWithTypeAnnotationsOnDeclaration.kts
public? final? const [ResolvedTo(RAW_FIR)] val constant: <implicit> = LAZY_EXPRESSION
public? [ResolvedTo(RAW_FIR)] get(): <implicit>
public? final? [ResolvedTo(RAW_FIR)] fun explicitType(): @Anno[Unresolved](<strcat>(String(return type: ), constant#)) List<@Anno[Unresolved](<strcat>(String(nested return type: ), constant#)) Collection<@Anno[Unresolved](<strcat>(String(nested nested return type: ), constant#)) String>> { LAZY_BLOCK }
public? final? [ResolvedTo(RAW_FIR)] fun explicitType(): @Anno[Unresolved](LAZY_EXPRESSION) List<@Anno[Unresolved](LAZY_EXPRESSION) Collection<@Anno[Unresolved](LAZY_EXPRESSION) String>> { LAZY_BLOCK }
BODY_RESOLVE:
@@ -246,7 +246,7 @@ FILE: [ResolvedTo(IMPORTS)] scriptWithTypeAnnotationsOnDeclaration.kts
SCRIPT: [ResolvedTo(BODY_RESOLVE)] <script-scriptWithTypeAnnotationsOnDeclaration.kts>
[ResolvedTo(BODY_RESOLVE)] lval args: R|kotlin/Array<kotlin/String>|
@Target[Unresolved](AnnotationTarget#.TYPE#) public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
@Target[Unresolved](LAZY_EXPRESSION) public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=foo/Anno.position] position: String): R|foo/Anno| {
LAZY_super<R|kotlin/Any|>
}
@@ -259,7 +259,7 @@ FILE: [ResolvedTo(IMPORTS)] scriptWithTypeAnnotationsOnDeclaration.kts
public? final? const [ResolvedTo(RAW_FIR)] val constant: <implicit> = LAZY_EXPRESSION
public? [ResolvedTo(RAW_FIR)] get(): <implicit>
public? final? [ResolvedTo(RAW_FIR)] fun explicitType(): @Anno[Unresolved](<strcat>(String(return type: ), constant#)) List<@Anno[Unresolved](<strcat>(String(nested return type: ), constant#)) Collection<@Anno[Unresolved](<strcat>(String(nested nested return type: ), constant#)) String>> { LAZY_BLOCK }
public? final? [ResolvedTo(RAW_FIR)] fun explicitType(): @Anno[Unresolved](LAZY_EXPRESSION) List<@Anno[Unresolved](LAZY_EXPRESSION) Collection<@Anno[Unresolved](LAZY_EXPRESSION) String>> { LAZY_BLOCK }
FILE RAW TO BODY:
@@ -284,3 +284,4 @@ FILE: [ResolvedTo(BODY_RESOLVE)] scriptWithTypeAnnotationsOnDeclaration.kts
public final [ResolvedTo(BODY_RESOLVE)] fun explicitType(): R|@R|foo/Anno|(position = <strcat>(String(return type: ), R|foo/constant|)) kotlin/collections/List<@R|foo/Anno|(position = <strcat>(String(nested return type: ), R|foo/constant|)) kotlin/collections/Collection<@R|foo/Anno|(position = <strcat>(String(nested nested return type: ), R|foo/constant|)) kotlin/String>>| {
^explicitType Int(0)
}
+6 -6
View File
@@ -584,7 +584,7 @@ FILE: [ResolvedTo(IMPORTS)] script.kts
}
@Target[Unresolved](AnnotationTarget#.EXPRESSION#, AnnotationTarget#.FUNCTION#) @Retention[Unresolved](AnnotationRetention#.SOURCE#) public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
@Target[Unresolved](LAZY_EXPRESSION, LAZY_EXPRESSION) @Retention[Unresolved](LAZY_EXPRESSION) public? final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=Anno] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/Anno.s] s: En): R|Anno| {
LAZY_super<R|kotlin/Any|>
}
@@ -594,13 +594,13 @@ FILE: [ResolvedTo(IMPORTS)] script.kts
}
@Anno[Unresolved](En#.Entry#) public? final? [ResolvedTo(RAW_FIR)] fun build([ResolvedTo(RAW_FIR)] action: ( Builder.() -> Unit )): <implicit> { LAZY_BLOCK }
@Anno[Unresolved](LAZY_EXPRESSION) public? final? [ResolvedTo(RAW_FIR)] fun build([ResolvedTo(RAW_FIR)] action: ( Builder.() -> Unit )): <implicit> { LAZY_BLOCK }
@Anno[Unresolved](En#.Entry#) build#(<L> = LAZY_EXPRESSION)
@Anno[Unresolved](LAZY_EXPRESSION) build#(<L> = LAZY_EXPRESSION)
public? final? [ResolvedTo(RAW_FIR)] val builder: <implicit> = LAZY_EXPRESSION
public? [ResolvedTo(RAW_FIR)] get(): <implicit>
@Anno[Unresolved](En#.Entry#) builder#.execute#()
@Anno[Unresolved](LAZY_EXPRESSION) builder#.execute#()
builder#.version# = String()
BODY_RESOLVE:
@@ -641,7 +641,7 @@ FILE: [ResolvedTo(IMPORTS)] script.kts
}
@R|kotlin/annotation/Target|[Types](Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.EXPRESSION|, Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.FUNCTION|) @R|kotlin/annotation/Retention|[Types](AnnotationRetention#.SOURCE#) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
@R|kotlin/annotation/Target|[Types](Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.EXPRESSION|, Q|kotlin/annotation/AnnotationTarget|.R|kotlin/annotation/AnnotationTarget.FUNCTION|) @R|kotlin/annotation/Retention|[Types](LAZY_EXPRESSION) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] constructor([ResolvedTo(STATUS)] [CorrespondingProperty=/Anno.s] s: R|En|): R|Anno| {
LAZY_super<R|kotlin/Any|>
}
@@ -651,7 +651,7 @@ FILE: [ResolvedTo(IMPORTS)] script.kts
}
@R|Anno|[Types](En#.Entry#) public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun build([ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] action: R|Builder.() -> kotlin/Unit|): R|Builder| {
@R|Anno|[Types](LAZY_EXPRESSION) public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] fun build([ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] action: R|Builder.() -> kotlin/Unit|): R|Builder| {
^build R|/Builder.Builder|().R|kotlin/apply|<R|Builder|>(R|<local>/action|)
}