[LL FIR] adapt LLFirTargetResolver for new FirDesignation
We should maintain `containingDeclarations` to be consistent with the new ` FirDesignation ` ^KT-65345 Fixed
This commit is contained in:
committed by
Space Team
parent
9b60e5ca06
commit
9589043a05
+13
-11
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2024 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -43,22 +43,24 @@ internal abstract class LLFirAbstractBodyTargetResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun withScript(firScript: FirScript, action: () -> Unit) {
|
@Deprecated("Should never be called directly, only for override purposes, please use withFile", level = DeprecationLevel.ERROR)
|
||||||
transformer.declarationsTransformer?.withScript(firScript) {
|
override fun withContainingFile(firFile: FirFile, action: () -> Unit) {
|
||||||
action()
|
|
||||||
firScript
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
|
||||||
transformer.declarationsTransformer?.withFile(firFile) {
|
transformer.declarationsTransformer?.withFile(firFile) {
|
||||||
action()
|
action()
|
||||||
firFile
|
firFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Should never be called directly, only for override purposes, please use withScript", level = DeprecationLevel.ERROR)
|
||||||
|
override fun withContainingScript(firScript: FirScript, action: () -> Unit) {
|
||||||
|
transformer.declarationsTransformer?.withScript(firScript) {
|
||||||
|
action()
|
||||||
|
firScript
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
transformer.declarationsTransformer?.context?.withContainingClass(firClass) {
|
transformer.declarationsTransformer?.context?.withContainingClass(firClass) {
|
||||||
transformer.declarationsTransformer?.withRegularClass(firClass) {
|
transformer.declarationsTransformer?.withRegularClass(firClass) {
|
||||||
action()
|
action()
|
||||||
@@ -68,7 +70,7 @@ internal abstract class LLFirAbstractBodyTargetResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun <T : FirElementWithResolveState> resolve(target: T, keeper: StateKeeper<T, FirDesignation>) {
|
protected fun <T : FirElementWithResolveState> resolve(target: T, keeper: StateKeeper<T, FirDesignation>) {
|
||||||
val firDesignation = FirDesignation(nestedClassesStack, target)
|
val firDesignation = FirDesignation(containingDeclarations, target)
|
||||||
resolveWithKeeper(target, firDesignation, keeper, { FirLazyBodiesCalculator.calculateBodies(firDesignation) }) {
|
resolveWithKeeper(target, firDesignation, keeper, { FirLazyBodiesCalculator.calculateBodies(firDesignation) }) {
|
||||||
rawResolve(target)
|
rawResolve(target)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -175,7 +175,7 @@ private class LLFirAnnotationArgumentsTargetResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
transformer.declarationsTransformer.withRegularClass(firClass) {
|
transformer.declarationsTransformer.withRegularClass(firClass) {
|
||||||
action()
|
action()
|
||||||
firClass
|
firClass
|
||||||
|
|||||||
+4
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2024 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -90,12 +90,13 @@ private class LLFirCompilerRequiredAnnotationsTargetResolver(
|
|||||||
private val llFirComputationSession: LLFirCompilerRequiredAnnotationsComputationSession
|
private val llFirComputationSession: LLFirCompilerRequiredAnnotationsComputationSession
|
||||||
get() = transformer.annotationTransformer.computationSession as LLFirCompilerRequiredAnnotationsComputationSession
|
get() = transformer.annotationTransformer.computationSession as LLFirCompilerRequiredAnnotationsComputationSession
|
||||||
|
|
||||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
@Deprecated("Should never be called directly, only for override purposes, please use withFile", level = DeprecationLevel.ERROR)
|
||||||
|
override fun withContainingFile(firFile: FirFile, action: () -> Unit) {
|
||||||
transformer.annotationTransformer.withFileAndFileScopes(firFile, action)
|
transformer.annotationTransformer.withFileAndFileScopes(firFile, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
transformer.annotationTransformer.withRegularClass(firClass, action)
|
transformer.annotationTransformer.withRegularClass(firClass, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-13
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2024 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -116,30 +116,34 @@ private class LLFirContractsTargetResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun withScript(firScript: FirScript, action: () -> Unit) {
|
@Deprecated("Should never be called directly, only for override purposes, please use withFile", level = DeprecationLevel.ERROR)
|
||||||
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
override fun withContainingFile(firFile: FirFile, action: () -> Unit) {
|
||||||
collector.addDeclarationContext(firScript, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
super.withScript(firScript, actionWithCollector)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
|
||||||
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
||||||
collector.addFileContext(firFile, context.towerDataContext)
|
collector.addFileContext(firFile, context.towerDataContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.withFile(firFile, actionWithCollector)
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
super.withContainingFile(firFile, actionWithCollector)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Should never be called directly, only for override purposes, please use withScript", level = DeprecationLevel.ERROR)
|
||||||
|
override fun withContainingScript(firScript: FirScript, action: () -> Unit) {
|
||||||
|
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
||||||
|
collector.addDeclarationContext(firScript, context)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
super.withContainingScript(firScript, actionWithCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
||||||
collector.addDeclarationContext(firClass, context)
|
collector.addDeclarationContext(firClass, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
@Suppress("DEPRECATION_ERROR")
|
||||||
super.withRegularClassImpl(firClass, actionWithCollector)
|
super.withContainingRegularClass(firClass, actionWithCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collectTowerDataContext(target: FirElementWithResolveState) {
|
private fun collectTowerDataContext(target: FirElementWithResolveState) {
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ private class LLFirExpectActualMatchingTargetResolver(
|
|||||||
private val enabled = resolveTargetSession.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)
|
private val enabled = resolveTargetSession.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
// Resolve outer classes before resolving inner declarations. It's the requirement of FirExpectActualResolver
|
// Resolve outer classes before resolving inner declarations. It's the requirement of FirExpectActualResolver
|
||||||
firClass.lazyResolveToPhase(resolverPhase.previous)
|
firClass.lazyResolveToPhase(resolverPhase.previous)
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2024 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ private class LLFirStatusTargetResolver(
|
|||||||
private val transformer = Transformer(resolveTargetSession, scopeSession)
|
private val transformer = Transformer(resolveTargetSession, scopeSession)
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
doResolveWithoutLock(firClass)
|
doResolveWithoutLock(firClass)
|
||||||
transformer.storeClass(firClass) {
|
transformer.storeClass(firClass) {
|
||||||
action()
|
action()
|
||||||
@@ -213,7 +213,7 @@ private class LLFirStatusTargetResolver(
|
|||||||
|
|
||||||
if (resolveMode.resolveSupertypes) {
|
if (resolveMode.resolveSupertypes) {
|
||||||
transformer.storeClass(firClass) {
|
transformer.storeClass(firClass) {
|
||||||
withClassInStack(firClass) {
|
withContainingDeclaration(firClass) {
|
||||||
resolveCallableMembers(firClass)
|
resolveCallableMembers(firClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ private class LLFirSuperTypeTargetResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
supertypeResolver.withClass(firClass) {
|
supertypeResolver.withClass(firClass) {
|
||||||
doResolveWithoutLock(firClass)
|
doResolveWithoutLock(firClass)
|
||||||
action()
|
action()
|
||||||
|
|||||||
+47
-18
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.FirElementWithResolveState
|
|||||||
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
|
import org.jetbrains.kotlin.fir.FirFileAnnotationsContainer
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirField
|
import org.jetbrains.kotlin.fir.declarations.FirField
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||||
@@ -42,26 +43,38 @@ internal abstract class LLFirTargetResolver(
|
|||||||
) : LLFirResolveTargetVisitor {
|
) : LLFirResolveTargetVisitor {
|
||||||
val resolveTargetSession: LLFirSession get() = resolveTarget.session
|
val resolveTargetSession: LLFirSession get() = resolveTarget.session
|
||||||
|
|
||||||
private val _nestedClassesStack = mutableListOf<FirRegularClass>()
|
private val _containingDeclarations = mutableListOf<FirDeclaration>()
|
||||||
|
|
||||||
val nestedClassesStack: List<FirRegularClass> get() = _nestedClassesStack
|
val containingDeclarations: List<FirDeclaration> get() = _containingDeclarations
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context used as a context in the case of exception
|
* @param context used as a context in the case of exception
|
||||||
* @return the last class from [nestedClassesStack]
|
* @return the last class from [containingDeclarations]
|
||||||
*/
|
*/
|
||||||
fun containingClass(context: FirElement): FirRegularClass = nestedClassesStack.lastOrNull()
|
fun containingClass(context: FirElement): FirRegularClass {
|
||||||
?: errorWithAttachment("Containing class is not found") {
|
val containingDeclaration = containingDeclarations.lastOrNull() ?: errorWithAttachment("Containing declaration is not found") {
|
||||||
withFirEntry("context", context)
|
withFirEntry("context", context)
|
||||||
|
withEntry("originalTarget", resolveTarget.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
protected inline fun withClassInStack(clazz: FirRegularClass, action: () -> Unit) {
|
requireWithAttachment(
|
||||||
_nestedClassesStack += clazz
|
containingDeclaration is FirRegularClass,
|
||||||
action()
|
{ "${FirRegularClass::class.simpleName} expected, but ${containingDeclaration::class.simpleName} found" },
|
||||||
val removed = _nestedClassesStack.removeLast()
|
)
|
||||||
checkWithAttachment(removed === clazz, { "Unexpected state"}) {
|
|
||||||
withFirEntry("expected", clazz)
|
return containingDeclaration
|
||||||
withFirEntry("actual", removed)
|
}
|
||||||
|
|
||||||
|
protected inline fun withContainingDeclaration(declaration: FirDeclaration, action: () -> Unit) {
|
||||||
|
_containingDeclarations += declaration
|
||||||
|
try {
|
||||||
|
action()
|
||||||
|
} finally {
|
||||||
|
val removed = _containingDeclarations.removeLast()
|
||||||
|
checkWithAttachment(removed === declaration, { "Unexpected state" }) {
|
||||||
|
withFirEntry("expected", declaration)
|
||||||
|
withFirEntry("actual", removed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,23 +142,39 @@ internal abstract class LLFirTargetResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
final override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||||
|
withContainingDeclaration(firFile) {
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
withContainingFile(firFile, action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Should never be called directly, only for override purposes, please use withFile", level = DeprecationLevel.ERROR)
|
||||||
|
protected open fun withContainingFile(firFile: FirFile, action: () -> Unit) {
|
||||||
action()
|
action()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun withScript(firScript: FirScript, action: () -> Unit) {
|
final override fun withScript(firScript: FirScript, action: () -> Unit) {
|
||||||
|
withContainingDeclaration(firScript) {
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
withContainingScript(firScript, action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Should never be called directly, only for override purposes, please use withScript", level = DeprecationLevel.ERROR)
|
||||||
|
protected open fun withContainingScript(firScript: FirScript, action: () -> Unit) {
|
||||||
action()
|
action()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
protected open fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
protected open fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
action()
|
action()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION_ERROR")
|
|
||||||
final override fun withRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
final override fun withRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
withClassInStack(firClass) {
|
withContainingDeclaration(firClass) {
|
||||||
withRegularClassImpl(firClass, action)
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
withContainingRegularClass(firClass, action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2024 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -81,12 +81,13 @@ private class LLFirTypeTargetResolver(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
@Deprecated("Should never be called directly, only for override purposes, please use withFile", level = DeprecationLevel.ERROR)
|
||||||
|
override fun withContainingFile(firFile: FirFile, action: () -> Unit) {
|
||||||
transformer.withFileScope(firFile, action)
|
transformer.withFileScope(firFile, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
override fun withContainingRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||||
firClass.lazyResolveToPhase(resolverPhase.previous)
|
firClass.lazyResolveToPhase(resolverPhase.previous)
|
||||||
transformer.withClassDeclarationCleanup(firClass) {
|
transformer.withClassDeclarationCleanup(firClass) {
|
||||||
performCustomResolveUnderLock(firClass) {
|
performCustomResolveUnderLock(firClass) {
|
||||||
|
|||||||
Reference in New Issue
Block a user