[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:
committed by
Space Team
parent
18a8cfb090
commit
72def186a3
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
enum class SomeEnum {
|
||||
|
||||
compiler/fir/analysis-tests/testData/resolve/cfa/reassignOfNonLocalProperty_initializedProperties.kt
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// ISSUE: KT-55493
|
||||
// WITH_STDLIB
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// ISSUE: KT-55493
|
||||
// WITH_STDLIB
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// ISSUE: KT-56863
|
||||
interface I
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
|
||||
annotation class Ann
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface AutoCloseable {
|
||||
fun close()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
class Foo {
|
||||
init {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface B
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
|
||||
interface Out<out E>
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
|
||||
abstract class A(func: () -> String)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo(): A
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
annotation class Ann1(vararg val a: String)
|
||||
annotation class Ann2(val a: IntArray)
|
||||
annotation class Ann3(val a: Array<String>)
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Repeatable
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
annotation class A() {
|
||||
<!ANNOTATION_CLASS_MEMBER!><!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>constructor(s: Nothing?)<!> {}<!>
|
||||
<!ANNOTATION_CLASS_MEMBER!>init {}<!>
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
annotation class Ann(val a: Array<String>)
|
||||
|
||||
val foo = ""
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
open class A {
|
||||
open var test: Number = 10
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
open <!REPEATED_MODIFIER!>open<!> class A
|
||||
|
||||
internal <!REPEATED_MODIFIER!>internal<!> object B
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
// ISSUE: KT-37091
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
package org.jetbrains.kotlin.codegen.range.inExpression
|
||||
|
||||
interface ExpressionCodegen
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// Ignore reason: KT-57619
|
||||
import <!UNRESOLVED_IMPORT!>my<!>.println
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class NoPrimary {
|
||||
val x: String
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !CHECK_TYPE
|
||||
// UNEXPECTED BEHAVIOUR
|
||||
// ISSUES: KT-37066
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FILE: MagicConstant.java
|
||||
|
||||
public @interface MagicConstant {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
class B(p0: String) {
|
||||
val p1 = p0
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FILE: A.kt
|
||||
open class A {
|
||||
open fun getScope(): String? = null
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo(): Boolean
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
|
||||
interface A {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.kt
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
class A {
|
||||
val s: String = ""
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
|
||||
open class Base
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
fun test_0(x: Any) {
|
||||
if (x is String) {
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// ISSUE: KT-39080
|
||||
// !DUMP_CFG
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo(): Boolean
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface A {
|
||||
fun foo()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
// There would be ambiguities if some expression was smartcasted to (A & B) and foo() was called.
|
||||
// There was a bug where 2 variables were "bound" together if they are assigned from the same function call or property.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
// CONTAINS ERRORS
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
class A {
|
||||
fun foo() {}
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
// ----------------- Stable -----------------
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
fun String.foo(b: Boolean): String = ""
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
interface I
|
||||
interface S : I {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// ISSUE: KT-49747
|
||||
// DUMP_CFG
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
fun getNothing(): Nothing = throw Exception()
|
||||
fun getNullableNothing(): Nothing? = null
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
open class A(open val x: Any)
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
class A {
|
||||
fun foo() {}
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DUMP_CFG
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class C(val map: MutableMap<String, Any>) {
|
||||
var foo by map
|
||||
}
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// ISSUE: KT-39005
|
||||
// !DUMP_CFG
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class Some(var foo: Int) {
|
||||
init {
|
||||
if (foo < 0) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class TestInitValInLambdaCalledOnce {
|
||||
val x: Int
|
||||
init {
|
||||
|
||||
+33
-15
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInline
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.LocalClassesNavigationInfo
|
||||
import org.jetbrains.kotlin.fir.scopes.FirCompositeScope
|
||||
@@ -90,14 +90,13 @@ open class FirStatusResolveTransformer(
|
||||
val computationStatus = statusComputationSession.startComputing(firClass)
|
||||
forceResolveStatusesOfSupertypes(firClass)
|
||||
/*
|
||||
* Status of class may be already calculated if that class was in supertypes of one of previous classes
|
||||
* Status of class may be already calculated if that class was in supertypes of one of the previous classes
|
||||
*/
|
||||
if (computationStatus != StatusComputationSession.StatusComputationStatus.Computed) {
|
||||
firClass.transformStatus(this, statusResolver.resolveStatus(firClass, containingClass, isLocal = false))
|
||||
if (firClass is FirRegularClass && firClass.isInline) {
|
||||
firClass.valueClassRepresentation = computeValueClassRepresentation(firClass, session)
|
||||
}
|
||||
transformClassStatus(firClass)
|
||||
transformValueClassRepresentation(firClass)
|
||||
}
|
||||
|
||||
return transformClass(firClass, data).also {
|
||||
statusComputationSession.endComputing(firClass)
|
||||
}
|
||||
@@ -187,13 +186,15 @@ class StatusComputationSession {
|
||||
abstract class AbstractFirStatusResolveTransformer(
|
||||
final override val session: FirSession,
|
||||
val scopeSession: ScopeSession,
|
||||
protected val statusComputationSession: StatusComputationSession,
|
||||
val statusComputationSession: StatusComputationSession,
|
||||
private val designationMapForLocalClasses: Map<FirClassLikeDeclaration, FirClassLikeDeclaration?>,
|
||||
private val scopeForLocalClass: FirScope?
|
||||
) : FirAbstractTreeTransformer<FirResolvedDeclarationStatus?>(phase = FirResolvePhase.STATUS) {
|
||||
protected val classes = mutableListOf<FirClass>()
|
||||
protected val statusResolver = FirStatusResolver(session, scopeSession)
|
||||
@PrivateForInline
|
||||
val classes = mutableListOf<FirClass>()
|
||||
val statusResolver = FirStatusResolver(session, scopeSession)
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
protected val containingClass: FirClass? get() = classes.lastOrNull()
|
||||
|
||||
protected abstract fun FirDeclaration.needResolveMembers(): Boolean
|
||||
@@ -213,7 +214,8 @@ abstract class AbstractFirStatusResolveTransformer(
|
||||
return (data ?: declarationStatus)
|
||||
}
|
||||
|
||||
protected inline fun storeClass(
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun storeClass(
|
||||
klass: FirClass,
|
||||
computeResult: () -> FirDeclaration
|
||||
): FirDeclaration {
|
||||
@@ -309,7 +311,17 @@ abstract class AbstractFirStatusResolveTransformer(
|
||||
} as FirStatement
|
||||
}
|
||||
|
||||
protected fun forceResolveStatusesOfSupertypes(regularClass: FirClass) {
|
||||
fun transformValueClassRepresentation(firClass: FirClass) {
|
||||
if (firClass is FirRegularClass && firClass.isInline) {
|
||||
firClass.valueClassRepresentation = computeValueClassRepresentation(firClass, session)
|
||||
}
|
||||
}
|
||||
|
||||
fun transformClassStatus(firClass: FirClass) {
|
||||
firClass.transformStatus(this, statusResolver.resolveStatus(firClass, containingClass, isLocal = false))
|
||||
}
|
||||
|
||||
fun forceResolveStatusesOfSupertypes(regularClass: FirClass) {
|
||||
for (superTypeRef in regularClass.superTypeRefs) {
|
||||
forceResolveStatusOfCorrespondingClass(superTypeRef)
|
||||
}
|
||||
@@ -317,7 +329,7 @@ abstract class AbstractFirStatusResolveTransformer(
|
||||
|
||||
private fun forceResolveStatusOfCorrespondingClass(typeRef: FirTypeRef) {
|
||||
val superClassSymbol = typeRef.coneType.toSymbol(session)
|
||||
superClassSymbol?.lazyResolveToPhase(FirResolvePhase.SUPER_TYPES)
|
||||
superClassSymbol?.lazyResolveToPhase(FirResolvePhase.STATUS.previous)
|
||||
when (superClassSymbol) {
|
||||
is FirRegularClassSymbol -> forceResolveStatusesOfClass(superClassSymbol.fir)
|
||||
is FirTypeAliasSymbol -> forceResolveStatusOfCorrespondingClass(superClassSymbol.fir.expandedTypeRef)
|
||||
@@ -349,7 +361,12 @@ abstract class AbstractFirStatusResolveTransformer(
|
||||
statusComputationSession.endComputing(regularClass)
|
||||
return
|
||||
}
|
||||
val designation = DesignationState.create(regularClass.symbol, designationMapForLocalClasses, includeFile = false) ?: return
|
||||
if (!resolveClassForSuperType(regularClass)) return
|
||||
statusComputationSession.endComputing(regularClass)
|
||||
}
|
||||
|
||||
protected open fun resolveClassForSuperType(regularClass: FirRegularClass): Boolean {
|
||||
val designation = DesignationState.create(regularClass.symbol, designationMapForLocalClasses, includeFile = false) ?: return false
|
||||
|
||||
val transformer = FirDesignatedStatusResolveTransformer(
|
||||
session,
|
||||
@@ -359,8 +376,9 @@ abstract class AbstractFirStatusResolveTransformer(
|
||||
designationMapForLocalClasses,
|
||||
scopeForLocalClass
|
||||
)
|
||||
|
||||
designation.firstDeclaration.transformSingle(transformer, null)
|
||||
statusComputationSession.endComputing(regularClass)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun transformPropertyAccessor(
|
||||
|
||||
+115
-74
@@ -9,6 +9,7 @@ import kotlinx.collections.immutable.*
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||
import org.jetbrains.kotlin.fir.correspondingProperty
|
||||
import org.jetbrains.kotlin.fir.copyWithNewSourceKind
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
@@ -57,22 +58,25 @@ fun <F : FirClassLikeDeclaration> F.runTypeResolvePhaseForLocalClass(
|
||||
return this.transform(transformer, null)
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
open class FirTypeResolveTransformer(
|
||||
final override val session: FirSession,
|
||||
private val scopeSession: ScopeSession,
|
||||
@property:PrivateForInline val scopeSession: ScopeSession,
|
||||
initialScopes: List<FirScope> = emptyList(),
|
||||
initialCurrentFile: FirFile? = null,
|
||||
private val classDeclarationsStack: ArrayDeque<FirClass> = ArrayDeque()
|
||||
@property:PrivateForInline val classDeclarationsStack: ArrayDeque<FirClass> = ArrayDeque()
|
||||
) : FirAbstractTreeTransformer<Any?>(FirResolvePhase.TYPES) {
|
||||
/**
|
||||
* All current scopes sorted from outermost to innermost.
|
||||
*/
|
||||
private var scopes = initialScopes.asReversed().toPersistentList()
|
||||
@PrivateForInline
|
||||
var scopes = initialScopes.asReversed().toPersistentList()
|
||||
|
||||
/**
|
||||
* Scopes that are accessible statically, i.e. [scopes] minus type parameter scopes.
|
||||
*/
|
||||
private var staticScopes = scopes
|
||||
@PrivateForInline
|
||||
var staticScopes = scopes
|
||||
|
||||
private var currentDeclaration: FirDeclaration? = null
|
||||
|
||||
@@ -87,33 +91,48 @@ open class FirTypeResolveTransformer(
|
||||
}
|
||||
|
||||
private val typeResolverTransformer: FirSpecificTypeResolverTransformer = FirSpecificTypeResolverTransformer(session)
|
||||
private var currentFile: FirFile? = initialCurrentFile
|
||||
|
||||
@PrivateForInline
|
||||
var currentFile: FirFile? = initialCurrentFile
|
||||
|
||||
override fun transformFile(file: FirFile, data: Any?): FirFile {
|
||||
checkSessionConsistency(file)
|
||||
return withFileScope(file) {
|
||||
super.transformFile(file, data)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <R> withFileScope(file: FirFile, crossinline action: () -> R): R {
|
||||
currentFile = file
|
||||
return withScopeCleanup {
|
||||
addScopes(createImportingScopes(file, session, scopeSession))
|
||||
super.transformFile(file, data)
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: Any?): FirStatement {
|
||||
whileAnalysing(session, regularClass) {
|
||||
withClassDeclarationCleanup(classDeclarationsStack, regularClass) {
|
||||
withScopeCleanup {
|
||||
regularClass.addTypeParametersScope()
|
||||
regularClass.typeParameters.forEach {
|
||||
it.accept(this, data)
|
||||
}
|
||||
unboundCyclesInTypeParametersSupertypes(regularClass)
|
||||
}
|
||||
|
||||
withClassDeclarationCleanup(regularClass) {
|
||||
transformClassTypeParameters(regularClass, data)
|
||||
return resolveClassContent(regularClass, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun transformClassTypeParameters(regularClass: FirRegularClass, data: Any?) {
|
||||
withScopeCleanup {
|
||||
addTypeParametersScope(regularClass)
|
||||
regularClass.typeParameters.forEach {
|
||||
it.accept(this, data)
|
||||
}
|
||||
unboundCyclesInTypeParametersSupertypes(regularClass)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <R> withClassDeclarationCleanup(regularClass: FirRegularClass, action: () -> R): R {
|
||||
return withClassDeclarationCleanup(classDeclarationsStack, regularClass, action)
|
||||
}
|
||||
|
||||
override fun transformAnonymousObject(anonymousObject: FirAnonymousObject, data: Any?): FirStatement {
|
||||
withClassDeclarationCleanup(classDeclarationsStack, anonymousObject) {
|
||||
return resolveClassContent(anonymousObject, data)
|
||||
@@ -122,7 +141,7 @@ open class FirTypeResolveTransformer(
|
||||
|
||||
override fun transformConstructor(constructor: FirConstructor, data: Any?): FirConstructor = whileAnalysing(session, constructor) {
|
||||
return withScopeCleanup {
|
||||
constructor.addTypeParametersScope()
|
||||
addTypeParametersScope(constructor)
|
||||
val result = transformDeclaration(constructor, data) as FirConstructor
|
||||
|
||||
if (result.isPrimary) {
|
||||
@@ -140,7 +159,7 @@ open class FirTypeResolveTransformer(
|
||||
|
||||
override fun transformTypeAlias(typeAlias: FirTypeAlias, data: Any?): FirTypeAlias = whileAnalysing(session, typeAlias) {
|
||||
withScopeCleanup {
|
||||
typeAlias.addTypeParametersScope()
|
||||
addTypeParametersScope(typeAlias)
|
||||
transformDeclaration(typeAlias, data)
|
||||
} as FirTypeAlias
|
||||
}
|
||||
@@ -160,7 +179,7 @@ open class FirTypeResolveTransformer(
|
||||
override fun transformProperty(property: FirProperty, data: Any?): FirProperty = whileAnalysing(session, property) {
|
||||
withScopeCleanup {
|
||||
withDeclaration(property) {
|
||||
property.addTypeParametersScope()
|
||||
addTypeParametersScope(property)
|
||||
property.transformTypeParameters(this, data)
|
||||
.transformReturnTypeRef(this, data)
|
||||
.transformReceiverParameter(this, data)
|
||||
@@ -182,9 +201,18 @@ open class FirTypeResolveTransformer(
|
||||
}
|
||||
property.returnTypeRef !is FirResolvedTypeRef && property.initializer == null &&
|
||||
property.getter?.returnTypeRef is FirResolvedTypeRef -> {
|
||||
property.replaceReturnTypeRef(
|
||||
property.getter!!.returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.PropertyTypeFromGetterReturnType)
|
||||
val returnTypeRef = property.getter!!.returnTypeRef
|
||||
|
||||
property.replaceReturnTypeRef(returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.PropertyTypeFromGetterReturnType))
|
||||
property.backingField?.replaceReturnTypeRef(
|
||||
returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.PropertyTypeFromGetterReturnType)
|
||||
)
|
||||
|
||||
property.setter?.valueParameters?.forEach {
|
||||
it.replaceReturnTypeRef(
|
||||
returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.PropertyTypeFromGetterReturnType)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +247,7 @@ open class FirTypeResolveTransformer(
|
||||
): FirSimpleFunction = whileAnalysing(session, simpleFunction) {
|
||||
withScopeCleanup {
|
||||
withDeclaration(simpleFunction) {
|
||||
simpleFunction.addTypeParametersScope()
|
||||
addTypeParametersScope(simpleFunction)
|
||||
transformDeclaration(simpleFunction, data).also {
|
||||
unboundCyclesInTypeParametersSupertypes(it as FirTypeParametersOwner)
|
||||
calculateDeprecations(simpleFunction)
|
||||
@@ -339,10 +367,11 @@ open class FirTypeResolveTransformer(
|
||||
annotationCall.replaceAnnotationTypeRef(transformedTypeRef)
|
||||
}
|
||||
}
|
||||
|
||||
return annotationCall
|
||||
}
|
||||
|
||||
private inline fun <T> withScopeCleanup(crossinline l: () -> T): T {
|
||||
inline fun <T> withScopeCleanup(crossinline l: () -> T): T {
|
||||
val scopesBefore = scopes
|
||||
val staticScopesBefore = staticScopes
|
||||
|
||||
@@ -357,80 +386,92 @@ open class FirTypeResolveTransformer(
|
||||
private fun resolveClassContent(
|
||||
firClass: FirClass,
|
||||
data: Any?
|
||||
): FirStatement {
|
||||
|
||||
return withScopeCleanup {
|
||||
// Remove type parameter scopes for classes that are neither inner nor local
|
||||
if (!firClass.isInner && !firClass.isLocal) {
|
||||
this.scopes = staticScopes
|
||||
}
|
||||
|
||||
): FirStatement = withClassScopes(
|
||||
firClass,
|
||||
actionInsideStaticScope = {
|
||||
withScopeCleanup {
|
||||
firClass.transformAnnotations(this, null)
|
||||
|
||||
if (firClass is FirRegularClass) {
|
||||
firClass.addTypeParametersScope()
|
||||
addTypeParametersScope(firClass)
|
||||
}
|
||||
|
||||
// ConstructedTypeRef should be resolved only with type parameters, but not with nested classes and classes from supertypes
|
||||
for (constructor in firClass.declarations.filterIsInstance<FirConstructor>()) {
|
||||
constructor.delegatedConstructor?.let(this::resolveConstructedTypeRefForDelegatedConstructorCall)
|
||||
transformDelegatedConstructorCall(constructor)
|
||||
}
|
||||
}
|
||||
|
||||
// ? Is it Ok to use original file session here ?
|
||||
val superTypes = lookupSuperTypes(
|
||||
firClass,
|
||||
lookupInterfaces = false,
|
||||
deep = true,
|
||||
substituteTypes = true,
|
||||
useSiteSession = session
|
||||
).asReversed()
|
||||
|
||||
val scopesToAdd = mutableListOf<FirScope>()
|
||||
|
||||
for (superType in superTypes) {
|
||||
superType.lookupTag.getNestedClassifierScope(session, scopeSession)?.let { nestedClassifierScope ->
|
||||
val scope = nestedClassifierScope.wrapNestedClassifierScopeWithSubstitutionForSuperType(superType, session)
|
||||
scopesToAdd.add(scope)
|
||||
}
|
||||
}
|
||||
session.nestedClassifierScope(firClass)?.let(scopesToAdd::add)
|
||||
if (firClass is FirRegularClass) {
|
||||
val companionObject = firClass.companionObjectSymbol?.fir
|
||||
if (companionObject != null) {
|
||||
session.nestedClassifierScope(companionObject)?.let(scopesToAdd::add)
|
||||
}
|
||||
|
||||
addScopes(scopesToAdd)
|
||||
firClass.addTypeParametersScope()
|
||||
} else {
|
||||
addScopes(scopesToAdd)
|
||||
}
|
||||
|
||||
// Note that annotations are still visited here
|
||||
// again, although there's no need in it
|
||||
transformElement(firClass, data)
|
||||
}
|
||||
) {
|
||||
// Note that annotations are still visited here
|
||||
// again, although there's no need in it
|
||||
transformElement(firClass, data)
|
||||
}
|
||||
|
||||
fun transformDelegatedConstructorCall(constructor: FirConstructor) {
|
||||
constructor.delegatedConstructor?.let(this::resolveConstructedTypeRefForDelegatedConstructorCall)
|
||||
}
|
||||
|
||||
inline fun <R> withClassScopes(
|
||||
firClass: FirClass,
|
||||
crossinline actionInsideStaticScope: () -> Unit = {},
|
||||
crossinline action: () -> R,
|
||||
): R = withScopeCleanup {
|
||||
// Remove type parameter scopes for classes that are neither inner nor local
|
||||
if (!firClass.isInner && !firClass.isLocal) {
|
||||
this.scopes = staticScopes
|
||||
}
|
||||
|
||||
actionInsideStaticScope()
|
||||
|
||||
// ? Is it Ok to use original file session here ?
|
||||
val superTypes = lookupSuperTypes(
|
||||
firClass,
|
||||
lookupInterfaces = false,
|
||||
deep = true,
|
||||
substituteTypes = true,
|
||||
useSiteSession = session
|
||||
).asReversed()
|
||||
|
||||
val scopesToAdd = mutableListOf<FirScope>()
|
||||
|
||||
for (superType in superTypes) {
|
||||
superType.lookupTag.getNestedClassifierScope(session, scopeSession)?.let { nestedClassifierScope ->
|
||||
val scope = nestedClassifierScope.wrapNestedClassifierScopeWithSubstitutionForSuperType(superType, session)
|
||||
scopesToAdd.add(scope)
|
||||
}
|
||||
}
|
||||
|
||||
session.nestedClassifierScope(firClass)?.let(scopesToAdd::add)
|
||||
if (firClass is FirRegularClass) {
|
||||
val companionObject = firClass.companionObjectSymbol?.fir
|
||||
if (companionObject != null) {
|
||||
session.nestedClassifierScope(companionObject)?.let(scopesToAdd::add)
|
||||
}
|
||||
|
||||
addScopes(scopesToAdd)
|
||||
addTypeParametersScope(firClass)
|
||||
} else {
|
||||
addScopes(scopesToAdd)
|
||||
}
|
||||
|
||||
action()
|
||||
}
|
||||
|
||||
private fun resolveConstructedTypeRefForDelegatedConstructorCall(
|
||||
delegatedConstructorCall: FirDelegatedConstructorCall
|
||||
) {
|
||||
delegatedConstructorCall.replaceConstructedTypeRef(
|
||||
delegatedConstructorCall.constructedTypeRef.transform<FirTypeRef, Any?>(this, null)
|
||||
)
|
||||
|
||||
delegatedConstructorCall.replaceConstructedTypeRef(delegatedConstructorCall.constructedTypeRef.transformSingle(this, null))
|
||||
delegatedConstructorCall.transformCalleeReference(this, null)
|
||||
}
|
||||
|
||||
private fun FirMemberDeclaration.addTypeParametersScope() {
|
||||
if (typeParameters.isNotEmpty()) {
|
||||
scopes = scopes.add(FirMemberTypeParameterScope(this))
|
||||
fun addTypeParametersScope(firMemberDeclaration: FirMemberDeclaration) {
|
||||
if (firMemberDeclaration.typeParameters.isNotEmpty()) {
|
||||
scopes = scopes.add(FirMemberTypeParameterScope(firMemberDeclaration))
|
||||
}
|
||||
}
|
||||
|
||||
private fun addScopes(list: List<FirScope>) {
|
||||
fun addScopes(list: List<FirScope>) {
|
||||
// small optimization to skip unnecessary allocations
|
||||
val scopesAreTheSame = scopes === staticScopes
|
||||
|
||||
|
||||
+2
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -33,9 +33,6 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
||||
abstract var implicitTypeOnly: Boolean
|
||||
internal set
|
||||
|
||||
override val transformerPhase: FirResolvePhase
|
||||
get() = if (implicitTypeOnly) baseTransformerPhase else FirResolvePhase.BODY_RESOLVE
|
||||
|
||||
final override val session: FirSession get() = components.session
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
@@ -66,7 +63,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
||||
protected inline val typeResolverTransformer: FirSpecificTypeResolverTransformer get() = components.typeResolverTransformer
|
||||
protected inline val callResolver: FirCallResolver get() = components.callResolver
|
||||
protected inline val callCompleter: FirCallCompleter get() = components.callCompleter
|
||||
protected inline val dataFlowAnalyzer: FirDataFlowAnalyzer get() = components.dataFlowAnalyzer
|
||||
inline val dataFlowAnalyzer: FirDataFlowAnalyzer get() = components.dataFlowAnalyzer
|
||||
protected inline val scopeSession: ScopeSession get() = components.scopeSession
|
||||
protected inline val file: FirFile get() = components.file
|
||||
|
||||
|
||||
+22
-7
@@ -1,19 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
|
||||
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirTargetElement
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
|
||||
import org.jetbrains.kotlin.fir.resolve.createCurrentScopeList
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.DataFlowAnalyzerContext
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.*
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ScopeClassDeclaration
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.withFileAnalysisExceptionWrapping
|
||||
|
||||
abstract class FirAbstractBodyResolveTransformerDispatcher(
|
||||
session: FirSession,
|
||||
@@ -25,6 +33,8 @@ abstract class FirAbstractBodyResolveTransformerDispatcher(
|
||||
val firTowerDataContextCollector: FirTowerDataContextCollector? = null,
|
||||
) : FirAbstractBodyResolveTransformer(phase) {
|
||||
|
||||
open val preserveCFGForClasses: Boolean get() = !implicitTypeOnly
|
||||
|
||||
final override val context: BodyResolveContext =
|
||||
outerBodyResolveContext ?: BodyResolveContext(returnTypeCalculator, DataFlowAnalyzerContext(session))
|
||||
final override val components: BodyResolveTransformerComponents =
|
||||
@@ -32,8 +42,10 @@ abstract class FirAbstractBodyResolveTransformerDispatcher(
|
||||
|
||||
final override val resolutionContext: ResolutionContext = ResolutionContext(session, components, context)
|
||||
|
||||
internal abstract val expressionsTransformer: FirExpressionsResolveTransformer
|
||||
protected abstract val declarationsTransformer: FirDeclarationsResolveTransformer
|
||||
abstract val expressionsTransformer: FirExpressionsResolveTransformer
|
||||
|
||||
abstract val declarationsTransformer: FirDeclarationsResolveTransformer
|
||||
|
||||
private val controlFlowStatementsTransformer = FirControlFlowStatementsResolveTransformer(this)
|
||||
|
||||
override fun transformFile(file: FirFile, data: ResolutionMode): FirFile {
|
||||
@@ -194,7 +206,10 @@ abstract class FirAbstractBodyResolveTransformerDispatcher(
|
||||
desugaredAssignmentValueReferenceExpression: FirDesugaredAssignmentValueReferenceExpression,
|
||||
data: ResolutionMode
|
||||
): FirStatement {
|
||||
return expressionsTransformer.transformDesugaredAssignmentValueReferenceExpression(desugaredAssignmentValueReferenceExpression, data)
|
||||
return expressionsTransformer.transformDesugaredAssignmentValueReferenceExpression(
|
||||
desugaredAssignmentValueReferenceExpression,
|
||||
data,
|
||||
)
|
||||
}
|
||||
|
||||
override fun transformVariableAssignment(
|
||||
|
||||
+12
-3
@@ -535,18 +535,27 @@ open class FirDeclarationsResolveTransformer(
|
||||
return typeAlias
|
||||
}
|
||||
|
||||
private fun doTransformRegularClass(
|
||||
protected fun doTransformRegularClass(
|
||||
regularClass: FirRegularClass,
|
||||
data: ResolutionMode
|
||||
): FirRegularClass = withRegularClass(regularClass) {
|
||||
transformDeclarationContent(regularClass, data) as FirRegularClass
|
||||
}
|
||||
|
||||
open fun withRegularClass(
|
||||
regularClass: FirRegularClass,
|
||||
action: () -> FirRegularClass
|
||||
): FirRegularClass {
|
||||
dataFlowAnalyzer.enterClass(regularClass, !implicitTypeOnly)
|
||||
dataFlowAnalyzer.enterClass(regularClass, buildGraph = transformer.preserveCFGForClasses)
|
||||
val result = context.withRegularClass(regularClass, components) {
|
||||
transformDeclarationContent(regularClass, data) as FirRegularClass
|
||||
action()
|
||||
}
|
||||
|
||||
val controlFlowGraph = dataFlowAnalyzer.exitClass()
|
||||
if (controlFlowGraph != null) {
|
||||
result.replaceControlFlowGraphReference(FirControlFlowGraphReferenceImpl(controlFlowGraph))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -256,10 +256,16 @@ abstract class FirAbstractContractResolveTransformerDispatcher(
|
||||
}
|
||||
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: ResolutionMode): FirStatement {
|
||||
context.withRegularClass(regularClass, components) {
|
||||
return withRegularClass(regularClass) {
|
||||
transformDeclarationContent(regularClass, data)
|
||||
regularClass
|
||||
}
|
||||
}
|
||||
|
||||
override fun withRegularClass(regularClass: FirRegularClass, action: () -> FirRegularClass): FirRegularClass {
|
||||
return context.withRegularClass(regularClass, components) {
|
||||
action()
|
||||
}
|
||||
return regularClass
|
||||
}
|
||||
|
||||
override fun transformAnonymousObject(
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirAbstractTreeTransformer
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirTransformerBasedResolveProcessor
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.resolve.multiplatform.compatible
|
||||
|
||||
class FirExpectActualMatcherProcessor(
|
||||
session: FirSession,
|
||||
@@ -76,7 +75,7 @@ open class FirExpectActualMatcherTransformer(
|
||||
|
||||
// ------------------------------------------------------
|
||||
|
||||
private fun transformMemberDeclaration(memberDeclaration: FirMemberDeclaration) {
|
||||
fun transformMemberDeclaration(memberDeclaration: FirMemberDeclaration) {
|
||||
if (!memberDeclaration.isActual) return
|
||||
val actualSymbol = memberDeclaration.symbol
|
||||
|
||||
|
||||
+74
-33
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.fir.scopes.createImportingScopes
|
||||
import org.jetbrains.kotlin.fir.scopes.getProperties
|
||||
import org.jetbrains.kotlin.fir.scopes.getSingleClassifier
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirAbstractImportingScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -67,10 +66,11 @@ object CompilerRequiredAnnotationsHelper {
|
||||
)
|
||||
}
|
||||
|
||||
internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
protected val session: FirSession,
|
||||
protected val scopeSession: ScopeSession,
|
||||
protected val computationSession: CompilerRequiredAnnotationsComputationSession,
|
||||
@OptIn(PrivateForInline::class)
|
||||
abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
@property:PrivateForInline val session: FirSession,
|
||||
@property:PrivateForInline val scopeSession: ScopeSession,
|
||||
@property:PrivateForInline val computationSession: CompilerRequiredAnnotationsComputationSession,
|
||||
containingDeclarations: List<FirDeclaration> = emptyList()
|
||||
) : FirDefaultTransformer<Nothing?>() {
|
||||
companion object {
|
||||
@@ -202,8 +202,11 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
@PrivateForInline
|
||||
val argumentsTransformer = FirEnumAnnotationArgumentsTransformerDispatcher()
|
||||
|
||||
private var owners: PersistentList<FirDeclaration> = persistentListOf()
|
||||
private val classDeclarationsStack = ArrayDeque<FirClass>().apply {
|
||||
@PrivateForInline
|
||||
var owners: PersistentList<FirDeclaration> = persistentListOf()
|
||||
|
||||
@PrivateForInline
|
||||
val classDeclarationsStack = ArrayDeque<FirClass>().apply {
|
||||
for (declaration in containingDeclarations) {
|
||||
if (declaration is FirClass) {
|
||||
add(declaration)
|
||||
@@ -211,7 +214,6 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
override fun transformAnnotationCall(annotationCall: FirAnnotationCall, data: Nothing?): FirStatement {
|
||||
val annotationTypeRef = annotationCall.annotationTypeRef
|
||||
if (annotationTypeRef !is FirUserTypeRef) return annotationCall
|
||||
@@ -277,16 +279,42 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
|
||||
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): FirStatement {
|
||||
withClassDeclarationCleanup(classDeclarationsStack, regularClass) {
|
||||
if (!shouldTransformDeclaration(regularClass)) return regularClass
|
||||
computationSession.recordThatAnnotationsAreResolved(regularClass)
|
||||
return transformDeclaration(regularClass, data).also {
|
||||
val state = beforeTransformingChildren(regularClass)
|
||||
resolveRegularClass(
|
||||
regularClass,
|
||||
transformChildren = {
|
||||
regularClass.transformDeclarations(this, data)
|
||||
regularClass.transformSuperTypeRefs(this, data)
|
||||
afterTransformingChildren(state)
|
||||
},
|
||||
afterChildrenTransform = {
|
||||
calculateDeprecations(regularClass)
|
||||
} as FirStatement
|
||||
}
|
||||
)
|
||||
return regularClass
|
||||
}
|
||||
|
||||
inline fun resolveRegularClass(
|
||||
regularClass: FirRegularClass,
|
||||
transformChildren: () -> Unit,
|
||||
afterChildrenTransform: () -> Unit
|
||||
) {
|
||||
withRegularClass(regularClass) {
|
||||
if (!shouldTransformDeclaration(regularClass)) return
|
||||
computationSession.recordThatAnnotationsAreResolved(regularClass)
|
||||
transformDeclaration(regularClass, null).also {
|
||||
transformChildren(regularClass) {
|
||||
transformChildren()
|
||||
}
|
||||
afterChildrenTransform()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun withRegularClass(
|
||||
regularClass: FirRegularClass,
|
||||
action: () -> Unit
|
||||
) {
|
||||
withClassDeclarationCleanup(classDeclarationsStack, regularClass) {
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,20 +337,24 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
|
||||
override fun transformFile(file: FirFile, data: Nothing?): FirFile {
|
||||
if (!shouldTransformDeclaration(file)) return file
|
||||
return withFile(file) {
|
||||
withFileAndFileScopes(file) {
|
||||
file.transformDeclarations(this, data)
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
fun withFileAndFileScopes(file: FirFile, action: () -> Unit) {
|
||||
withFile(file) {
|
||||
withFileScopes(file) {
|
||||
scopes = createImportingScopes(file, session, scopeSession, useCaching = false)
|
||||
val state = beforeTransformingChildren(file)
|
||||
try {
|
||||
file.transformDeclarations(this, data)
|
||||
} finally {
|
||||
afterTransformingChildren(state)
|
||||
transformChildren(file) {
|
||||
action()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun <T> withFile(file: FirFile, f: () -> T): T {
|
||||
typeResolverTransformer.withFile(file) {
|
||||
argumentsTransformer.context.withFile(file, argumentsTransformer.components) {
|
||||
@@ -333,7 +365,7 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateDeprecations(classLikeDeclaration: FirClassLikeDeclaration) {
|
||||
fun calculateDeprecations(classLikeDeclaration: FirClassLikeDeclaration) {
|
||||
if (classLikeDeclaration.deprecationsProvider == UnresolvedDeprecationProvider) {
|
||||
classLikeDeclaration.replaceDeprecationsProvider(
|
||||
classLikeDeclaration.getDeprecationsProvider(session)
|
||||
@@ -341,14 +373,14 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
}
|
||||
}
|
||||
|
||||
protected lateinit var scopes: List<FirScope>
|
||||
lateinit var scopes: List<FirScope>
|
||||
|
||||
inline fun <T> withFileScopes(file: FirFile, f: () -> T): T {
|
||||
scopes = createImportingScopes(file, session, scopeSession, useCaching = false)
|
||||
return f()
|
||||
}
|
||||
|
||||
protected abstract fun shouldTransformDeclaration(declaration: FirDeclaration): Boolean
|
||||
abstract fun shouldTransformDeclaration(declaration: FirDeclaration): Boolean
|
||||
|
||||
override fun transformProperty(property: FirProperty, data: Nothing?): FirProperty {
|
||||
if (!shouldTransformDeclaration(property)) return property
|
||||
@@ -363,9 +395,9 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
if (!shouldTransformDeclaration(simpleFunction)) return simpleFunction
|
||||
computationSession.recordThatAnnotationsAreResolved(simpleFunction)
|
||||
return transformDeclaration(simpleFunction, data).also {
|
||||
val state = beforeTransformingChildren(simpleFunction)
|
||||
simpleFunction.transformValueParameters(this, data)
|
||||
afterTransformingChildren(state)
|
||||
transformChildren(simpleFunction) {
|
||||
simpleFunction.transformValueParameters(this, data)
|
||||
}
|
||||
} as FirSimpleFunction
|
||||
}
|
||||
|
||||
@@ -376,9 +408,9 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
if (!shouldTransformDeclaration(constructor)) return constructor
|
||||
computationSession.recordThatAnnotationsAreResolved(constructor)
|
||||
return transformDeclaration(constructor, data).also {
|
||||
val state = beforeTransformingChildren(constructor)
|
||||
constructor.transformValueParameters(this, data)
|
||||
afterTransformingChildren(state)
|
||||
transformChildren(constructor) {
|
||||
constructor.transformValueParameters(this, data)
|
||||
}
|
||||
} as FirConstructor
|
||||
}
|
||||
|
||||
@@ -413,7 +445,7 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
* @return Some state of the transformer; when the nested declarations are transformed, this state will be
|
||||
* passed to the [afterTransformingChildren].
|
||||
*/
|
||||
private fun beforeTransformingChildren(parentDeclaration: FirDeclaration): PersistentList<FirDeclaration> {
|
||||
fun beforeTransformingChildren(parentDeclaration: FirDeclaration): PersistentList<FirDeclaration> {
|
||||
val current = owners
|
||||
owners = owners.add(parentDeclaration)
|
||||
return current
|
||||
@@ -426,11 +458,20 @@ internal abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
*
|
||||
* @param state A state produced by the [beforeTransformingChildren] call before the transformation.
|
||||
*/
|
||||
private fun afterTransformingChildren(state: PersistentList<FirDeclaration>?) {
|
||||
fun afterTransformingChildren(state: PersistentList<FirDeclaration>?) {
|
||||
requireNotNull(state)
|
||||
owners = state
|
||||
}
|
||||
|
||||
inline fun <R> transformChildren(parentDeclaration: FirDeclaration, action: () -> R): R {
|
||||
val state = beforeTransformingChildren(parentDeclaration)
|
||||
try {
|
||||
return action()
|
||||
} finally {
|
||||
afterTransformingChildren(state)
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirUserTypeRef.createDeepCopy(): FirUserTypeRef {
|
||||
val original = this
|
||||
return buildUserTypeRef {
|
||||
|
||||
+69
-10
@@ -1,34 +1,87 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.resolve.transformers.plugin
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.BodyResolveContext
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformerDispatcher
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirDeclarationsResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
|
||||
open class FirAnnotationArgumentsMappingTransformer(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
resolvePhase: FirResolvePhase,
|
||||
outerBodyResolveContext: BodyResolveContext? = null
|
||||
outerBodyResolveContext: BodyResolveContext? = null,
|
||||
returnTypeCalculator: ReturnTypeCalculator = ReturnTypeCalculatorForFullBodyResolve,
|
||||
) : FirAbstractBodyResolveTransformerDispatcher(
|
||||
session,
|
||||
resolvePhase,
|
||||
implicitTypeOnly = false,
|
||||
scopeSession,
|
||||
outerBodyResolveContext = outerBodyResolveContext
|
||||
outerBodyResolveContext = outerBodyResolveContext,
|
||||
returnTypeCalculator = returnTypeCalculator,
|
||||
) {
|
||||
final override val expressionsTransformer: FirExpressionsResolveTransformer =
|
||||
FirExpressionsResolveTransformer(this)
|
||||
FirExpressionTransformerForAnnotationArgumentsMapping(this)
|
||||
|
||||
final override val declarationsTransformer: FirDeclarationsResolveTransformer =
|
||||
private val declarationsResolveTransformerForAnnotationArgumentsMapping =
|
||||
FirDeclarationsResolveTransformerForAnnotationArgumentsMapping(this)
|
||||
|
||||
private val usualDeclarationTransformer = FirDeclarationsResolveTransformer(this)
|
||||
|
||||
@PrivateForInline
|
||||
var isInsideAnnotationArgument = false
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun <R> insideAnnotationArgument(action: () -> R): R {
|
||||
val oldValue = this.isInsideAnnotationArgument
|
||||
isInsideAnnotationArgument = true
|
||||
try {
|
||||
return action()
|
||||
} finally {
|
||||
isInsideAnnotationArgument = oldValue
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
final override val declarationsTransformer: FirDeclarationsResolveTransformer
|
||||
get() {
|
||||
return if (isInsideAnnotationArgument) usualDeclarationTransformer
|
||||
else declarationsResolveTransformerForAnnotationArgumentsMapping
|
||||
}
|
||||
}
|
||||
|
||||
private class FirExpressionTransformerForAnnotationArgumentsMapping(
|
||||
private val annotationArgumentsMappingTransformer: FirAnnotationArgumentsMappingTransformer,
|
||||
) : FirExpressionsResolveTransformer(annotationArgumentsMappingTransformer) {
|
||||
|
||||
override fun transformAnnotationCall(annotationCall: FirAnnotationCall, data: ResolutionMode): FirStatement {
|
||||
annotationArgumentsMappingTransformer.insideAnnotationArgument {
|
||||
return super.transformAnnotationCall(annotationCall, data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun transformErrorAnnotationCall(errorAnnotationCall: FirErrorAnnotationCall, data: ResolutionMode): FirStatement {
|
||||
annotationArgumentsMappingTransformer.insideAnnotationArgument {
|
||||
return super.transformErrorAnnotationCall(errorAnnotationCall, data)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class FirDeclarationsResolveTransformerForAnnotationArgumentsMapping(
|
||||
@@ -37,14 +90,18 @@ private class FirDeclarationsResolveTransformerForAnnotationArgumentsMapping(
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: ResolutionMode): FirStatement {
|
||||
regularClass.transformAnnotations(this, data)
|
||||
doTransformTypeParameters(regularClass)
|
||||
regularClass.transformSuperTypeRefs(this, data)
|
||||
|
||||
context.withContainingClass(regularClass) {
|
||||
doTransformRegularClass(regularClass, data)
|
||||
return regularClass
|
||||
}
|
||||
|
||||
override fun withRegularClass(regularClass: FirRegularClass, action: () -> FirRegularClass): FirRegularClass {
|
||||
return context.withContainingClass(regularClass) {
|
||||
context.withRegularClass(regularClass, components) {
|
||||
transformDeclarationContent(regularClass, data) as FirRegularClass
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
return regularClass
|
||||
}
|
||||
|
||||
override fun transformAnonymousInitializer(
|
||||
@@ -158,6 +215,8 @@ private class FirDeclarationsResolveTransformerForAnnotationArgumentsMapping(
|
||||
override fun transformTypeAlias(typeAlias: FirTypeAlias, data: ResolutionMode): FirTypeAlias {
|
||||
doTransformTypeParameters(typeAlias)
|
||||
typeAlias.transformAnnotations(transformer, data)
|
||||
transformer.firTowerDataContextCollector?.addDeclarationContext(typeAlias, context.towerDataContext)
|
||||
typeAlias.expandedTypeRef.transformSingle(transformer, data)
|
||||
return typeAlias
|
||||
}
|
||||
|
||||
|
||||
+28
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -19,11 +19,15 @@ import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.toResolvedBaseSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguouslyResolvedAnnotationArgument
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.BodyResolveContext
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformerDispatcher
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirDeclarationsResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeAmbiguouslyResolvedAnnotationArgument
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
@@ -32,17 +36,21 @@ open class FirAnnotationArgumentsResolveTransformer(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
resolvePhase: FirResolvePhase,
|
||||
outerBodyResolveContext: BodyResolveContext? = null
|
||||
outerBodyResolveContext: BodyResolveContext? = null,
|
||||
returnTypeCalculator: ReturnTypeCalculator = ReturnTypeCalculatorForFullBodyResolve,
|
||||
) : FirAbstractBodyResolveTransformerDispatcher(
|
||||
session,
|
||||
resolvePhase,
|
||||
implicitTypeOnly = false,
|
||||
scopeSession,
|
||||
outerBodyResolveContext = outerBodyResolveContext
|
||||
outerBodyResolveContext = outerBodyResolveContext,
|
||||
returnTypeCalculator = returnTypeCalculator,
|
||||
) {
|
||||
final override val expressionsTransformer: FirExpressionsResolveTransformer = FirExpressionsResolveTransformerForSpecificAnnotations(this)
|
||||
final override val expressionsTransformer: FirExpressionsResolveTransformer =
|
||||
FirExpressionsResolveTransformerForSpecificAnnotations(this)
|
||||
|
||||
final override val declarationsTransformer: FirDeclarationsResolveTransformer = FirDeclarationsResolveTransformerForArgumentAnnotations(this)
|
||||
final override val declarationsTransformer: FirDeclarationsResolveTransformer =
|
||||
FirDeclarationsResolveTransformerForArgumentAnnotations(this)
|
||||
}
|
||||
|
||||
private class FirDeclarationsResolveTransformerForArgumentAnnotations(
|
||||
@@ -50,15 +58,22 @@ private class FirDeclarationsResolveTransformerForArgumentAnnotations(
|
||||
) : FirDeclarationsResolveTransformer(transformer) {
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: ResolutionMode): FirStatement {
|
||||
regularClass.transformAnnotations(this, data)
|
||||
context.withContainingClass(regularClass) {
|
||||
withRegularClass(regularClass) {
|
||||
regularClass
|
||||
.transformTypeParameters(transformer, data)
|
||||
.transformSuperTypeRefs(transformer, data)
|
||||
.transformDeclarations(transformer, data)
|
||||
}
|
||||
|
||||
return regularClass
|
||||
}
|
||||
|
||||
override fun withRegularClass(regularClass: FirRegularClass, action: () -> FirRegularClass): FirRegularClass {
|
||||
return context.withContainingClass(regularClass) {
|
||||
context.withRegularClass(regularClass, components) {
|
||||
regularClass
|
||||
.transformTypeParameters(transformer, data)
|
||||
.transformSuperTypeRefs(transformer, data)
|
||||
.transformDeclarations(transformer, data)
|
||||
action()
|
||||
}
|
||||
}
|
||||
return regularClass
|
||||
}
|
||||
|
||||
override fun transformAnonymousInitializer(
|
||||
@@ -145,6 +160,7 @@ private class FirDeclarationsResolveTransformerForArgumentAnnotations(
|
||||
|
||||
override fun transformTypeAlias(typeAlias: FirTypeAlias, data: ResolutionMode): FirTypeAlias {
|
||||
typeAlias.transformAnnotations(transformer, data)
|
||||
typeAlias.expandedTypeRef.transformSingle(transformer, data)
|
||||
return typeAlias
|
||||
}
|
||||
|
||||
|
||||
+11
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,10 @@ package org.jetbrains.kotlin.fir.resolve.transformers.plugin
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
@@ -22,7 +25,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
import org.jetbrains.kotlin.fir.withFileAnalysisExceptionWrapping
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.name.SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT
|
||||
|
||||
class FirCompanionGenerationProcessor(
|
||||
@@ -49,11 +51,15 @@ class FirCompanionGenerationTransformer(val session: FirSession) : FirTransforme
|
||||
}
|
||||
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: Nothing?): FirStatement {
|
||||
generateAndUpdateCompanion(regularClass)
|
||||
return regularClass.transformDeclarations(this, data)
|
||||
}
|
||||
|
||||
fun generateAndUpdateCompanion(regularClass: FirRegularClass) {
|
||||
val companionSymbol = generateCompanion(regularClass)
|
||||
if (companionSymbol != null) {
|
||||
regularClass.replaceCompanionObjectSymbol(companionSymbol)
|
||||
}
|
||||
return regularClass.transformDeclarations(this, data)
|
||||
}
|
||||
|
||||
private fun generateCompanion(regularClass: FirRegularClass): FirRegularClassSymbol? {
|
||||
@@ -65,6 +71,7 @@ class FirCompanionGenerationTransformer(val session: FirSession) : FirTransforme
|
||||
result = it
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
} else {
|
||||
val companionClassId = regularClass.classId.createNestedClassId(DEFAULT_NAME_FOR_COMPANION_OBJECT)
|
||||
|
||||
+12
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -7,19 +7,24 @@ package org.jetbrains.kotlin.fir.resolve.transformers.plugin
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||
import org.jetbrains.kotlin.fir.SessionConfiguration
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.extensions.*
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.extensions.generatedDeclarationsSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.extensions.registeredPluginAnnotations
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProviderInternals
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.impl.FirCachingCompositeSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.*
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.LocalClassesNavigationInfo
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.DesignationState
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirAbstractPhaseTransformer
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirGlobalResolveProcessor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirImportResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
import org.jetbrains.kotlin.fir.withFileAnalysisExceptionWrapping
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -67,7 +72,7 @@ abstract class AbstractFirCompilerRequiredAnnotationsResolveTransformer(
|
||||
final override val session: FirSession,
|
||||
computationSession: CompilerRequiredAnnotationsComputationSession
|
||||
) : FirAbstractPhaseTransformer<Nothing?>(COMPILER_REQUIRED_ANNOTATIONS) {
|
||||
internal abstract val annotationTransformer: AbstractFirSpecificAnnotationResolveTransformer
|
||||
abstract val annotationTransformer: AbstractFirSpecificAnnotationResolveTransformer
|
||||
private val importTransformer = FirPartialImportResolveTransformer(session, computationSession)
|
||||
|
||||
val extensionService = session.extensionService
|
||||
@@ -167,12 +172,13 @@ private class FirPartialImportResolveTransformer(
|
||||
}
|
||||
}
|
||||
|
||||
private class FirSpecificAnnotationResolveTransformer(
|
||||
class FirSpecificAnnotationResolveTransformer(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
computationSession: CompilerRequiredAnnotationsComputationSession
|
||||
) : AbstractFirSpecificAnnotationResolveTransformer(session, scopeSession, computationSession) {
|
||||
override fun shouldTransformDeclaration(declaration: FirDeclaration): Boolean {
|
||||
@OptIn(PrivateForInline::class)
|
||||
return !computationSession.annotationsAreResolved(declaration)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
// http://youtrack.jetbrains.net/issue/KT-419
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
interface NoC {
|
||||
<!ANONYMOUS_INITIALIZER_IN_INTERFACE!>init<!> {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
|
||||
// TODO Uncomment all the examples when there will be no problems with light classes
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DIAGNOSTICS: +UNUSED_PARAMETER
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DIAGNOSTICS: +UNUSED_PARAMETER
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DIAGNOSTICS: +UNUSED_VALUE, +UNUSED_CHANGED_VALUE, +UNUSED_PARAMETER, +UNUSED_VARIABLE
|
||||
|
||||
package unused_variables
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DIAGNOSTICS: +UNUSED_VALUE, +UNUSED_CHANGED_VALUE, +UNUSED_PARAMETER, +UNUSED_VARIABLE
|
||||
|
||||
package unused_variables
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: -ClassTypeParameterAnnotations
|
||||
@Target(AnnotationTarget.TYPE_PARAMETER)
|
||||
annotation class A1
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: -ClassTypeParameterAnnotations
|
||||
@Target(AnnotationTarget.TYPE_PARAMETER)
|
||||
annotation class A1
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: +ClassTypeParameterAnnotations
|
||||
annotation class A1
|
||||
annotation class A2(val some: Int = 12)
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: +ClassTypeParameterAnnotations
|
||||
annotation class A1
|
||||
annotation class A2(val some: Int = 12)
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions -ClassTypeParameterAnnotations
|
||||
|
||||
annotation class A1
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: +ProperCheckAnnotationsTargetInTypeUsePositions -ClassTypeParameterAnnotations
|
||||
|
||||
annotation class A1
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +NestedClassesInAnnotations
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: -NestedClassesInAnnotations
|
||||
|
||||
annotation class Annotation2() {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !LANGUAGE: -NestedClassesInAnnotations
|
||||
|
||||
annotation class Annotation2() {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +NestedClassesInAnnotations
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class A {
|
||||
@ann init {}
|
||||
@aaa init {}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class A {
|
||||
<!WRONG_ANNOTATION_TARGET!>@ann<!> init {}
|
||||
<!WRONG_ANNOTATION_TARGET!>@<!UNRESOLVED_REFERENCE!>aaa<!><!> init {}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
annotation class base
|
||||
|
||||
@base class My {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
annotation class base
|
||||
|
||||
@base class My {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: -ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
package test
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: -ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
package test
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class My(val v: Int) {
|
||||
// Ok: setter is just private
|
||||
var x: Int
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
class My(val v: Int) {
|
||||
// Ok: setter is just private
|
||||
var x: Int
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
abstract class My(val v: Int) {
|
||||
// Ok: variable is just abstract
|
||||
abstract var x: Int
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
abstract class My(val v: Int) {
|
||||
// Ok: variable is just abstract
|
||||
abstract var x: Int
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
package test
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
package test
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_REVERSED_RESOLVE
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user