[Resolve] Rewrite how built-ins are created

Under COMPOSITE mode we don't have a globally known way to create
built-ins, instead, we have to create them on per-module basis.

So, in this commit we:

1. Use builtInsProvider: (ModuleInfo) -> KotlinBuiltIns instead of
precomputed builtIns instance, in order to be able to calculate
builtIns on per-module basis

2. Introduce new entity, called BuiltInsCache, which, roughly
speaking, is a map of form ModuleInfo -> KotlinBuiltIns, to prevent
creation of multiple builtInsInstances
NB. Actually, it's of form BuiltInsCacheKey -> KotlinBuiltIns, because
we shouldn't create new builtIns for each module. Also, currently,
each platform has its own BuiltInsCacheKey implementation, because
parameters by which built-ins are created, are a bit different across
different platforms. Ideally, we should eliminate those differences
and they use one concrete implementation as a key.
This commit is contained in:
Dmitry Savvinov
2019-06-07 18:08:37 +03:00
parent 9f2a03947c
commit 2b4d70fcf0
11 changed files with 135 additions and 55 deletions
@@ -20,6 +20,7 @@ import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.analyzer.*
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.container.StorageComponentContainer
@@ -149,7 +150,9 @@ class CommonResolverForModuleFactory(
CommonPlatforms.defaultCommonPlatform,
shouldCheckExpectActual = false
)
}
},
builtInsProvider = { DefaultBuiltIns.Instance },
sdkDependency = { null }
)
val moduleDescriptor = resolver.descriptorForModule(moduleInfo)
@@ -58,7 +58,7 @@ abstract class ResolverForProject<M : ModuleInfo> {
abstract val name: String
abstract val allModules: Collection<M>
abstract val builtIns: KotlinBuiltIns
abstract val builtInsProvider: (M) -> KotlinBuiltIns
override fun toString() = name
@@ -83,7 +83,7 @@ class EmptyResolverForProject<M : ModuleInfo> : ResolverForProject<M>() {
override fun descriptorForModule(moduleInfo: M) = diagnoseUnknownModuleInfo(listOf(moduleInfo))
override val allModules: Collection<M> = listOf()
override fun diagnoseUnknownModuleInfo(infos: List<ModuleInfo>) = throw IllegalStateException("Should not be called for $infos")
override val builtIns get() = DefaultBuiltIns.Instance
override val builtInsProvider: (M) -> KotlinBuiltIns = { DefaultBuiltIns.Instance }
}
class ResolverForProjectImpl<M : ModuleInfo>(
@@ -94,7 +94,7 @@ class ResolverForProjectImpl<M : ModuleInfo>(
private val moduleLanguageSettingsProvider: LanguageSettingsProvider,
private val resolverForModuleFactoryByPlatform: (TargetPlatform?) -> ResolverForModuleFactory,
private val invalidateOnOOCB: Boolean,
override val builtIns: KotlinBuiltIns = DefaultBuiltIns.Instance,
override val builtInsProvider: (M) -> KotlinBuiltIns,
private val delegateResolver: ResolverForProject<M> = EmptyResolverForProject(),
private val sdkDependency: (M) -> M?,
private val packageOracleFactory: PackageOracleFactory = PackageOracleFactory.OptimisticFactory,
@@ -251,7 +251,7 @@ class ResolverForProjectImpl<M : ModuleInfo>(
val moduleDescriptor = ModuleDescriptorImpl(
module.name,
projectContext.storageManager,
builtIns,
builtInsProvider(module),
module.platform,
module.capabilities,
module.stableName
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.ModificationTracker
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.analyzer.*
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
@@ -53,7 +54,9 @@ fun createResolveSessionForFiles(
moduleLanguageSettingsProvider = LanguageSettingsProvider.Default,
resolverForModuleFactoryByPlatform = {
JvmResolverForModuleFactory(platformParameters, CompilerEnvironment, JvmPlatforms.defaultJvmPlatform)
}
},
builtInsProvider = { DefaultBuiltIns.Instance },
sdkDependency = { null }
)
return resolverForProject.resolverForModule(testModule).componentProvider.get<ResolveSession>()
}
@@ -96,7 +96,8 @@ class MultiModuleJavaAnalysisCustomTest : KtUsefulTestCase() {
resolverForModuleFactoryByPlatform = {
JvmResolverForModuleFactory(platformParameters, CompilerEnvironment, JvmPlatforms.defaultJvmPlatform)
},
sdkDependency = { null }
sdkDependency = { null },
builtInsProvider = { builtIns }
)
builtIns.initialize(