Compute module mappings eagerly in JvmPackagePartProvider, refactor

Previously we traversed all notLoadedRoots on each request for package
parts with the given package FQ name. Since notLoadedRoots might contain
a lot of roots (which never transition into "loadedModules" because e.g.
they are not Kotlin libraries, but just Java libraries or SDK roots with
the META-INF directory), this was potentially hurting performance. It
seems it's more optimal to compute everything eagerly once
JvmPackagePartProvider is constructed.

Another problem with the previous version of JvmPackagePartProvider was
that it did not support "updateable classpath" which is used by REPL and
kapt2, it only used the initial roots provided in the
CompilerConfiguration. In REPL specifically, we would thus fail to
resolve top-level callables from libraries which were dynamically added
to the execution classpath (via some kind of a @DependsOn annotation).
In the new code, JvmPackagePartProvider no longer depends on
CompilerConfiguration to avoid this sort of confusion, but rather relies
on the object that constructed it (KotlinCoreEnvironment in this case)
to provide the correct roots. This is also beneficial because the
computation of actual VirtualFile-based roots from the ones in the
CompilerConfiguration might get trickier with modular Java 9 roots
This commit is contained in:
Alexander Udalov
2017-06-16 19:25:57 +03:00
parent a5a78b8f91
commit 999e4cda1d
10 changed files with 51 additions and 70 deletions
@@ -11,7 +11,10 @@ import com.intellij.util.io.URLUtil
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.*
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.addKotlinSourceRoot
@@ -49,14 +52,9 @@ abstract class AbstractKotlinUastTest : AbstractUastTest() {
val trace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
val kotlinCoreEnvironment = kotlinCoreEnvironment!!
val environment = kotlinCoreEnvironment!!
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
project,
kotlinCoreEnvironment.getSourceFiles(),
trace,
compilerConfiguration,
{ scope -> JvmPackagePartProvider(kotlinCoreEnvironment, scope) }
project, environment.getSourceFiles(), trace, compilerConfiguration, environment::createPackagePartProvider
)
val vfs = VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL)