Use constantSdkDependencyIfAny in getKeyForSdk as well

This commit is contained in:
Dmitry Savvinov
2019-12-10 21:23:25 +03:00
parent 5b8be16f13
commit f45c11c6f2
6 changed files with 8 additions and 8 deletions
@@ -33,7 +33,7 @@ class CommonPlatformKindResolution : IdePlatformKindResolution {
override val kind get() = CommonIdePlatformKind
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo): BuiltInsCacheKey = BuiltInsCacheKey.DefaultBuiltInsKey
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?): BuiltInsCacheKey = BuiltInsCacheKey.DefaultBuiltInsKey
override fun createBuiltIns(moduleInfo: ModuleInfo, projectContext: ProjectContext, sdkDependency: SdkInfo?): KotlinBuiltIns {
return DefaultBuiltIns.Instance
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.storage.StorageManager
interface IdePlatformKindResolution {
val kind: IdePlatformKind<*>
fun getKeyForBuiltIns(moduleInfo: ModuleInfo): BuiltInsCacheKey
fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?): BuiltInsCacheKey
fun createBuiltIns(moduleInfo: ModuleInfo, projectContext: ProjectContext, sdkDependency: SdkInfo?): KotlinBuiltIns
fun createResolverForModuleFactory(
@@ -31,7 +31,7 @@ class JsPlatformKindResolution : IdePlatformKindResolution {
override val kind get() = JsIdePlatformKind
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo): BuiltInsCacheKey {
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?): BuiltInsCacheKey {
return BuiltInsCacheKey.DefaultBuiltInsKey
}
@@ -42,8 +42,7 @@ class JvmPlatformKindResolution : IdePlatformKindResolution {
override val kind get() = JvmIdePlatformKind
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo): BuiltInsCacheKey {
val sdkInfo = moduleInfo.findSdkAcrossDependencies()
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?): BuiltInsCacheKey {
return if (sdkInfo != null) CacheKeyBySdk(sdkInfo.sdk) else BuiltInsCacheKey.DefaultBuiltInsKey
}
@@ -123,13 +123,14 @@ class IdeaResolverForProject(
private val cache = mutableMapOf<BuiltInsCacheKey, KotlinBuiltIns>()
fun getOrCreateIfNeeded(module: IdeaModuleInfo): KotlinBuiltIns = projectContextFromSdkResolver.storageManager.compute {
val key = module.platform.idePlatformKind.resolution.getKeyForBuiltIns(module)
val sdk = resolverForSdk.sdkDependency(module)
val key = module.platform.idePlatformKind.resolution.getKeyForBuiltIns(module, sdk)
val cachedBuiltIns = cache[key]
if (cachedBuiltIns != null) return@compute cachedBuiltIns
// Note #1: we can't use .getOrPut, because we have to put builtIns into map *before* initialization
// Note #2: it's OK to put not-initialized built-ins into public map, because access to [cache] is guarded by storageManager.lock
val sdk = resolverForSdk.sdkDependency(module)
val newBuiltIns = module.platform.idePlatformKind.resolution.createBuiltIns(module, projectContextFromSdkResolver, sdk)
cache[key] = newBuiltIns
@@ -132,7 +132,7 @@ class NativePlatformKindResolution : IdePlatformKindResolution {
override val kind get() = NativeIdePlatformKind
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo): BuiltInsCacheKey = NativeBuiltInsCacheKey
override fun getKeyForBuiltIns(moduleInfo: ModuleInfo, sdkInfo: SdkInfo?): BuiltInsCacheKey = NativeBuiltInsCacheKey
override fun createBuiltIns(moduleInfo: ModuleInfo, projectContext: ProjectContext, sdkDependency: SdkInfo?) =
createKotlinNativeBuiltIns(moduleInfo, projectContext)