[LL FIR] ContextCollector: optimize collector for file elements
We shouldn't trigger declaration processing if we want to check just annotations/package/imports. But currently, we still will iterate over the entire file if there is an element somewhere inside package/import (see `fileImportInside.kt` test case) ^KT-65344 ^KT-65560 Fixed
This commit is contained in:
committed by
Space Team
parent
0c3a1dfd67
commit
47e8d987b9
+30
-7
@@ -335,18 +335,34 @@ private class ContextCollectorVisitor(
|
||||
else -> true
|
||||
}
|
||||
|
||||
override fun visitScript(script: FirScript) {
|
||||
context.withScript(script, holder) {
|
||||
withInterceptor {
|
||||
super.visitScript(script)
|
||||
override fun visitScript(script: FirScript) = withProcessor(script) {
|
||||
dumpContext(script, ContextKind.SELF)
|
||||
|
||||
processSignatureAnnotations(script)
|
||||
|
||||
onActiveBody {
|
||||
context.withScript(script, holder) {
|
||||
dumpContext(script, ContextKind.BODY)
|
||||
|
||||
onActive {
|
||||
withInterceptor {
|
||||
processChildren(script)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitFile(file: FirFile) {
|
||||
override fun visitFile(file: FirFile) = withProcessor(file) {
|
||||
context.withFile(file, holder) {
|
||||
withInterceptor {
|
||||
super.visitFile(file)
|
||||
dumpContext(file, ContextKind.SELF)
|
||||
|
||||
processFileHeader(file)
|
||||
|
||||
onActive {
|
||||
withInterceptor {
|
||||
processChildren(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,6 +433,13 @@ private class ContextCollectorVisitor(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
private fun Processor.processFileHeader(file: FirFile) {
|
||||
process(file.packageDirective)
|
||||
processList(file.imports)
|
||||
process(file.annotationsContainer)
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as [processClassHeader], but for anonymous objects.
|
||||
*
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
Tower Data Context:
|
||||
Element 0
|
||||
Scope: FirDefaultStarImportingScope
|
||||
Element 1
|
||||
Scope: FirExplicitStarImportingScope
|
||||
Element 2
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 3
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 4
|
||||
Scope: FirPackageMemberScope
|
||||
Element 5
|
||||
Scope: FirExplicitSimpleImportingScope
|
||||
|
||||
FILE: [ResolvedTo(IMPORTS)] fileAnnotation.kt
|
||||
@FILE:R|Anno|[Types]()
|
||||
[ResolvedTo(STATUS)] annotations container
|
||||
@R|kotlin/annotation/Target|[Types](FILE#) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public? [ResolvedTo(RAW_FIR)] constructor(): R|Anno| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,10 +13,10 @@ Tower Data Context:
|
||||
Scope: FirExplicitSimpleImportingScope
|
||||
|
||||
FILE: [ResolvedTo(IMPORTS)] fileAnnotation.kt
|
||||
@FILE:R|Anno|[Types]()
|
||||
[ResolvedTo(STATUS)] annotations container
|
||||
@R|kotlin/annotation/Target|[Types](FILE#) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public [ResolvedTo(STATUS)] constructor(): R|Anno| {
|
||||
@FILE:Anno[Unresolved]()
|
||||
[ResolvedTo(RAW_FIR)] annotations container
|
||||
@Target[Unresolved](LAZY_EXPRESSION) public final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public? [ResolvedTo(RAW_FIR)] constructor(): R|Anno| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
Tower Data Context:
|
||||
Element 0
|
||||
Scope: FirDefaultStarImportingScope
|
||||
Element 1
|
||||
Scope: FirExplicitStarImportingScope
|
||||
Element 2
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 3
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 4
|
||||
Scope: FirPackageMemberScope
|
||||
Element 5
|
||||
Scope: FirExplicitSimpleImportingScope
|
||||
Import name:Anno
|
||||
Qualified name: foo.Anno
|
||||
Is all under: false
|
||||
|
||||
FILE: [ResolvedTo(IMPORTS)] fileImport.kt
|
||||
@R|kotlin/annotation/Target|[Types](FILE#) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public? [ResolvedTo(RAW_FIR)] constructor(): R|foo/Anno| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,8 @@ Tower Data Context:
|
||||
Is all under: false
|
||||
|
||||
FILE: [ResolvedTo(IMPORTS)] fileImport.kt
|
||||
@R|kotlin/annotation/Target|[Types](FILE#) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public [ResolvedTo(STATUS)] constructor(): R|foo/Anno| {
|
||||
@Target[Unresolved](LAZY_EXPRESSION) public final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public? [ResolvedTo(RAW_FIR)] constructor(): R|foo/Anno| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
Tower Data Context:
|
||||
Element 0
|
||||
Scope: FirDefaultStarImportingScope
|
||||
Element 1
|
||||
Scope: FirExplicitStarImportingScope
|
||||
Element 2
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 3
|
||||
Scope: FirDefaultSimpleImportingScope
|
||||
Element 4
|
||||
Scope: FirPackageMemberScope
|
||||
Element 5
|
||||
Scope: FirExplicitSimpleImportingScope
|
||||
|
||||
FILE: [ResolvedTo(IMPORTS)] filePackage.kt
|
||||
@R|kotlin/annotation/Target|[Types](FILE#) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public? [ResolvedTo(RAW_FIR)] constructor(): R|foo/Anno| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,9 +13,9 @@ Tower Data Context:
|
||||
Scope: FirExplicitSimpleImportingScope
|
||||
|
||||
FILE: [ResolvedTo(IMPORTS)] filePackage.kt
|
||||
@R|kotlin/annotation/Target|[Types](FILE#) public final [ResolvedTo(STATUS)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public [ResolvedTo(STATUS)] constructor(): R|foo/Anno| {
|
||||
@Target[Unresolved](LAZY_EXPRESSION) public final? [ResolvedTo(RAW_FIR)] annotation class Anno : R|kotlin/Annotation| {
|
||||
public? [ResolvedTo(RAW_FIR)] constructor(): R|foo/Anno| {
|
||||
LAZY_super<R|kotlin/Any|>
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user