[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 getTopLevelProperties(callableId: CallableId): Collection<KtProperty>
public abstract fun getTopLevelFunctions(callableId: CallableId): Collection<KtNamedFunction> 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 getTopLevelCallableNamesInPackage(packageFqName: FqName): Set<Name>
public abstract fun findFilesForFacadeByPackage(packageFqName: FqName): Collection<KtFile> public abstract fun findFilesForFacadeByPackage(packageFqName: FqName): Collection<KtFile>
@@ -97,6 +97,11 @@ public class KotlinStaticDeclarationProvider internal constructor(
} }
?: emptyList() ?: emptyList()
override fun getTopLevelCallableFiles(callableId: CallableId): Collection<KtFile> = buildSet {
getTopLevelProperties(callableId).mapTo(this) { it.containingKtFile }
getTopLevelFunctions(callableId).mapTo(this) { it.containingKtFile }
}
} }
public class KotlinStaticDeclarationProviderFactory( public class KotlinStaticDeclarationProviderFactory(
@@ -74,7 +74,7 @@ internal class LLFirNonUnderContentRootSessionFactory(private val project: Proje
components, components,
project.createDeclarationProvider(contentScope), project.createDeclarationProvider(contentScope),
project.createPackageProvider(contentScope), project.createPackageProvider(contentScope),
cabContainKotlinPackage = true, canContainKotlinPackage = true,
) )
register(FirProvider::class, provider) register(FirProvider::class, provider)
@@ -29,7 +29,7 @@ internal class LLFirProvider(
private val moduleComponents: LLFirModuleResolveComponents, private val moduleComponents: LLFirModuleResolveComponents,
private val declarationProvider: KotlinDeclarationProvider, private val declarationProvider: KotlinDeclarationProvider,
packageProvider: KotlinPackageProvider, packageProvider: KotlinPackageProvider,
cabContainKotlinPackage: Boolean, canContainKotlinPackage: Boolean,
) : FirProvider() { ) : FirProvider() {
override val symbolProvider: FirSymbolProvider = SymbolProvider() override val symbolProvider: FirSymbolProvider = SymbolProvider()
@@ -38,7 +38,7 @@ internal class LLFirProvider(
moduleComponents.firFileBuilder, moduleComponents.firFileBuilder,
declarationProvider, declarationProvider,
packageProvider, packageProvider,
cabContainKotlinPackage, canContainKotlinPackage,
) )
override val isPhasedFirAllowed: Boolean get() = true override val isPhasedFirAllowed: Boolean get() = true
@@ -52,10 +52,7 @@ internal class LLFirProviderHelper(
private val callablesByCallableId = firSession.firCachesFactory.createCache<CallableId, List<FirCallableSymbol<*>>> { callableId -> private val callablesByCallableId = firSession.firCachesFactory.createCache<CallableId, List<FirCallableSymbol<*>>> { callableId ->
val files = Sets.newIdentityHashSet<KtFile>().apply { val files = declarationProvider.getTopLevelCallableFiles(callableId).ifEmpty { return@createCache emptyList() }
declarationProvider.getTopLevelFunctions(callableId).mapTo(this) { it.containingKtFile }
declarationProvider.getTopLevelProperties(callableId).mapTo(this) { it.containingKtFile }
}
buildList { buildList {
files.forEach { ktFile -> files.forEach { ktFile ->
val firFile = firFileBuilder.buildRawFirFileWithCaching(ktFile) val firFile = firFileBuilder.buildRawFirFileWithCaching(ktFile)
@@ -98,7 +98,8 @@ internal object LLFirSessionFactory {
components, components,
project.createDeclarationProvider(contentScope), project.createDeclarationProvider(contentScope),
project.createPackageProvider(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) register(FirProvider::class, provider)
@@ -203,7 +204,7 @@ internal object LLFirSessionFactory {
components, components,
project.createDeclarationProvider(contentScope), project.createDeclarationProvider(contentScope),
project.createPackageProvider(contentScope), project.createPackageProvider(contentScope),
cabContainKotlinPackage = true, canContainKotlinPackage = true,
) )
register(FirProvider::class, provider) register(FirProvider::class, provider)