[Low Level FIR] optimize getting callables in LLFirProviderHelper

This commit is contained in:
Ilya Kirillov
2022-09-16 14:51:41 +02:00
parent 556b7894d5
commit ae76ce666f
6 changed files with 14 additions and 9 deletions
@@ -29,6 +29,8 @@ public abstract class KotlinDeclarationProvider {
public abstract fun getTopLevelProperties(callableId: CallableId): Collection<KtProperty>
public abstract fun getTopLevelFunctions(callableId: CallableId): Collection<KtNamedFunction>
public abstract fun getTopLevelCallableFiles(callableId: CallableId): Collection<KtFile>
public abstract fun getTopLevelCallableNamesInPackage(packageFqName: FqName): Set<Name>
public abstract fun findFilesForFacadeByPackage(packageFqName: FqName): Collection<KtFile>
@@ -97,6 +97,11 @@ public class KotlinStaticDeclarationProvider internal constructor(
}
?: emptyList()
override fun getTopLevelCallableFiles(callableId: CallableId): Collection<KtFile> = buildSet {
getTopLevelProperties(callableId).mapTo(this) { it.containingKtFile }
getTopLevelFunctions(callableId).mapTo(this) { it.containingKtFile }
}
}
public class KotlinStaticDeclarationProviderFactory(
@@ -74,7 +74,7 @@ internal class LLFirNonUnderContentRootSessionFactory(private val project: Proje
components,
project.createDeclarationProvider(contentScope),
project.createPackageProvider(contentScope),
cabContainKotlinPackage = true,
canContainKotlinPackage = true,
)
register(FirProvider::class, provider)
@@ -29,7 +29,7 @@ internal class LLFirProvider(
private val moduleComponents: LLFirModuleResolveComponents,
private val declarationProvider: KotlinDeclarationProvider,
packageProvider: KotlinPackageProvider,
cabContainKotlinPackage: Boolean,
canContainKotlinPackage: Boolean,
) : FirProvider() {
override val symbolProvider: FirSymbolProvider = SymbolProvider()
@@ -38,7 +38,7 @@ internal class LLFirProvider(
moduleComponents.firFileBuilder,
declarationProvider,
packageProvider,
cabContainKotlinPackage,
canContainKotlinPackage,
)
override val isPhasedFirAllowed: Boolean get() = true
@@ -52,10 +52,7 @@ internal class LLFirProviderHelper(
private val callablesByCallableId = firSession.firCachesFactory.createCache<CallableId, List<FirCallableSymbol<*>>> { callableId ->
val files = Sets.newIdentityHashSet<KtFile>().apply {
declarationProvider.getTopLevelFunctions(callableId).mapTo(this) { it.containingKtFile }
declarationProvider.getTopLevelProperties(callableId).mapTo(this) { it.containingKtFile }
}
val files = declarationProvider.getTopLevelCallableFiles(callableId).ifEmpty { return@createCache emptyList() }
buildList {
files.forEach { ktFile ->
val firFile = firFileBuilder.buildRawFirFileWithCaching(ktFile)
@@ -98,7 +98,8 @@ internal object LLFirSessionFactory {
components,
project.createDeclarationProvider(contentScope),
project.createPackageProvider(contentScope),
cabContainKotlinPackage = true,
/* Source modules can contain `kotlin` package only if `-Xallow-kotlin-package` is specified, this is handled in LLFirProvider */
canContainKotlinPackage = false,
)
register(FirProvider::class, provider)
@@ -203,7 +204,7 @@ internal object LLFirSessionFactory {
components,
project.createDeclarationProvider(contentScope),
project.createPackageProvider(contentScope),
cabContainKotlinPackage = true,
canContainKotlinPackage = true,
)
register(FirProvider::class, provider)