[LL FIR] rework transformers, so transformers resolve only a specific set of declarations

The change is needed for the parallel resolution (^KT-55750), so we can resolve the declaration
under a lock that is specific to this declaration.
Previously, if LL FIR was resolving some FirClass, LL FIR  resolved all its children too, and it had no control over what parts of the FIR tree were modified.
The same applied to the designation path, sometimes the classes on the designation path
might be unexpectedly (and without lock) modified.

This commit introduces LLFirResolveTarget, which specifies which exact declarations should be resolved during the lazy resolution of the declaration.
All elements outside the declarations specified for resolve in LLFirResolveTarget, should not be modified.

The logic of lazy transformers is the following:
- Go to target declaration collecting all scopes from the file and containing classes
- Resolve only declarations that are specified by the LLFirResolveTarget, performing the resolve under a separate lock for each declaration

^KT-56543
^KT-57619 Fixed
This commit is contained in:
Dmitrii Gridin
2023-03-30 17:19:30 +02:00
committed by Space Team
parent 18a8cfb090
commit 72def186a3
545 changed files with 4297 additions and 2378 deletions
@@ -0,0 +1,8 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
@Target(AnnotationTarget.TYPE)
annotation class Anno
open class A
class B : <expr>@Anno</expr> A()
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
@R|Anno|[Types]()
@@ -0,0 +1,8 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
@Target(AnnotationTarget.TYPE)
annotation class Anno
interface A
class B : <expr>@Anno</expr> A
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
@R|Anno|[Types]()
@@ -0,0 +1,8 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
annotation class Ann
class X {
<expr>@delegate:Ann</expr>
val a by lazy { 1 }
}
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
@PROPERTY_DELEGATE_FIELD:R|Ann|[Types]()
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
annotation class Ann
class X(<expr>@field:Ann</expr> var x: Int)
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
@FIELD:R|Ann|[Types]()
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
<expr>@file:Ann</expr>
annotation class Ann
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
@FILE:R|Ann|[Types]()
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
annotation class Ann
class X(<expr>@get:Ann</expr> var x: Int)
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: FromUseSiteTarget
FIR element rendered:
@PROPERTY_GETTER:R|Ann|[Types]()
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
annotation class Ann
class X(<expr>@param:Ann</expr> var x: Int)
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
@CONSTRUCTOR_PARAMETER:R|Ann|[Types]()
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
annotation class Ann
class X(<expr>@property:Ann</expr> var x: Int)
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
@PROPERTY:R|Ann|[Types]()
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
annotation class Ann
class X(<expr>@setparam:Ann</expr> var x: Int)
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: FromUseSiteTarget
FIR element rendered:
@SETTER_PARAMETER:R|Ann|[Types]()
@@ -0,0 +1,5 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtAnnotationEntry
annotation class Ann
class X(<expr>@set:Ann</expr> var x: Int)
@@ -0,0 +1,6 @@
KT element: KtAnnotationEntry
FIR element: FirAnnotationCallImpl
FIR source kind: FromUseSiteTarget
FIR element rendered:
@PROPERTY_SETTER:R|Ann|[Types]()
@@ -0,0 +1,9 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtCallExpression
open class B(x: () -> Unit)
class A() : B(1, {
<expr>foo()</expr>
})
fun foo() {}
@@ -0,0 +1,6 @@
KT element: KtCallExpression
FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|/foo|()
@@ -0,0 +1,9 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtCallExpression
open class B(x: () -> Unit)
class A : B(1, {
<expr>foo()</expr>
})
fun foo() {}
@@ -0,0 +1,6 @@
KT element: KtCallExpression
FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|/foo|()
@@ -0,0 +1,19 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtCallExpression
open class A(x: () -> Unit)
class B : A {
constructor(i: Int) : super(
{
foo(i)
}
)
constructor(l: Long) : super(
{
<expr>foo(l)</expr>
}
)
}
fun foo(any: Any) {}
@@ -0,0 +1,6 @@
KT element: KtCallExpression
FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|/foo|(R|<local>/l|)
@@ -0,0 +1,13 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtCallExpression
open class A(x: () -> Unit)
class B : A {
constructor(i: Int) : super(
{
<expr>foo(i)</expr>
}
)
}
fun foo(any: Any) {}
@@ -0,0 +1,6 @@
KT element: KtCallExpression
FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|/foo|(R|<local>/i|)
@@ -0,0 +1,6 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtTypeReference
interface A
class C : <expr>A</expr> {
constructor()
}
@@ -0,0 +1,6 @@
KT element: KtTypeReference
FIR element: FirResolvedTypeRefImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|A|
@@ -3,7 +3,7 @@ FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
<Unresolved name: lazy>#(<L> = [ResolvedTo(BODY_RESOLVE)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=Unknown> {
<Unresolved name: lazy>#(<L> = [ResolvedTo(RAW_FIR)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=Unknown> {
^ Int(1)
}
)
@@ -3,7 +3,7 @@ FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|kotlin/lazy|<R|kotlin/Int|>(<L> = [ResolvedTo(BODY_RESOLVE)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
R|kotlin/lazy|<R|kotlin/Int|>(<L> = [ResolvedTo(RAW_FIR)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
^ Int(1)
}
)
@@ -3,7 +3,7 @@ FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
<Unresolved name: lazy>#(<L> = [ResolvedTo(BODY_RESOLVE)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=Unknown> {
<Unresolved name: lazy>#(<L> = [ResolvedTo(RAW_FIR)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=Unknown> {
^ Int(1)
}
)
@@ -3,7 +3,7 @@ FIR element: FirFunctionCallImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|kotlin/lazy|<R|kotlin/Int|>(<L> = [ResolvedTo(BODY_RESOLVE)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
R|kotlin/lazy|<R|kotlin/Int|>(<L> = [ResolvedTo(RAW_FIR)] lazy@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
^ Int(1)
}
)