[LL FIR] avoid redundant context collection

We assume that declaration context will be collected
during `LLFirAnnotationArgumentsTargetResolver`, so other
`LLFirAbstractBodyTargetResolver` shouldn't repeat this process

^KT-60728
This commit is contained in:
Dmitrii Gridin
2023-07-30 00:26:14 +02:00
committed by Space Team
parent 1a3b0fa9d5
commit de48a51711
2 changed files with 40 additions and 14 deletions
@@ -46,27 +46,17 @@ internal abstract class LLFirAbstractBodyTargetResolver(
}
override fun withScript(firScript: FirScript, action: () -> Unit) {
transformer.context.withScopesForScript(firScript, transformer.components) {
transformer.firResolveContextCollector?.let { collector ->
collector.addDeclarationContext(firScript, transformer.context)
}
action()
}
transformer.context.withScopesForScript(firScript, transformer.components, action)
}
override fun withFile(firFile: FirFile, action: () -> Unit) {
transformer.context.withFile(firFile, transformer.components) {
transformer.firResolveContextCollector?.addFileContext(firFile, transformer.context.towerDataContext)
action()
}
transformer.context.withFile(firFile, transformer.components, action)
}
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
transformer.declarationsTransformer?.context?.withContainingClass(firClass) {
transformer.declarationsTransformer?.withRegularClass(firClass) {
transformer.firResolveContextCollector?.addDeclarationContext(firClass, transformer.context)
action()
firClass
}
@@ -54,6 +54,38 @@ private class LLFirAnnotationArgumentsTargetResolver(
firResolveContextCollector = firResolveContextCollector,
)
override fun withScript(firScript: FirScript, action: () -> Unit) {
super.withScript(firScript) {
transformer.firResolveContextCollector?.let { collector ->
collector.addDeclarationContext(firScript, transformer.context)
}
action()
}
}
override fun withFile(firFile: FirFile, action: () -> Unit) {
super.withFile(firFile) {
transformer.firResolveContextCollector?.let { collector ->
collector.addFileContext(firFile, transformer.context.towerDataContext)
}
action()
}
}
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
@Suppress("DEPRECATION_ERROR")
super.withRegularClassImpl(firClass) {
transformer.firResolveContextCollector?.let { collector ->
collector.addDeclarationContext(firClass, transformer.context)
}
action()
}
}
override fun doLazyResolveUnderLock(target: FirElementWithResolveState) {
collectTowerDataContext(target)
@@ -82,9 +114,13 @@ private class LLFirAnnotationArgumentsTargetResolver(
}
}
/**
* [withRegularClass] and [withScript] already have [FirResolveContextCollector.addDeclarationContext] call,
* so we shouldn't do anything inside
*/
when (target) {
is FirRegularClass -> withRegularClass(target) { contextCollector.addDeclarationContext(target, bodyResolveContext) }
is FirScript -> withScript(target) { contextCollector.addDeclarationContext(target, bodyResolveContext) }
is FirRegularClass -> withRegularClass(target) { }
is FirScript -> withScript(target) { }
else -> {}
}
}