Fix libraries analysis for case of isReleaseCoroutines feature enabled

#KT-25466 In Progress
This commit is contained in:
Denis Zharkov
2018-07-19 16:18:46 +03:00
parent f1463b4a2e
commit f72aa78eec
11 changed files with 168 additions and 18 deletions
@@ -61,7 +61,12 @@ internal val LOG = Logger.getInstance(KotlinCacheService::class.java)
// For every different instance of these settings we must create a different builtIns instance and thus a different moduleDescriptor graph
// since in the current implementation types from one module are leaking into other modules' resolution
// meaning that we can't just change those setting on a per module basis
data class PlatformAnalysisSettings(val platform: TargetPlatform, val sdk: Sdk?, val isAdditionalBuiltInFeaturesSupported: Boolean)
data class PlatformAnalysisSettings(
val platform: TargetPlatform, val sdk: Sdk?,
val isAdditionalBuiltInFeaturesSupported: Boolean,
// Effectively unused as a property. Needed only to distinguish different modes when being put in a map
val isReleaseCoroutines: Boolean
)
class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
override fun getResolutionFacade(elements: List<KtElement>): ResolutionFacade {
@@ -89,7 +94,10 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
): ProjectResolutionFacade {
val sdk = dependenciesModuleInfo.sdk
val platform = JvmPlatform // TODO: Js scripts?
val settings = PlatformAnalysisSettings(platform, sdk, true)
val settings = PlatformAnalysisSettings(
platform, sdk, true,
LanguageFeature.ReleaseCoroutines.defaultState == LanguageFeature.State.ENABLED
)
val dependenciesForScriptDependencies = listOf(
LibraryModificationTracker.getInstance(project),
@@ -162,12 +170,24 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
)
}
private fun IdeaModuleInfo.platformSettings(targetPlatform: TargetPlatform) = PlatformAnalysisSettings(
targetPlatform, sdk,
supportsAdditionalBuiltInsMembers(),
isReleaseCoroutines()
)
private fun IdeaModuleInfo.supportsAdditionalBuiltInsMembers(): Boolean {
return IDELanguageSettingsProvider
.getLanguageVersionSettings(this, project)
.supportsFeature(LanguageFeature.AdditionalBuiltInsMembers)
}
private fun IdeaModuleInfo.isReleaseCoroutines(): Boolean {
return IDELanguageSettingsProvider
.getLanguageVersionSettings(this, project)
.supportsFeature(LanguageFeature.ReleaseCoroutines)
}
private fun globalFacade(settings: PlatformAnalysisSettings) =
getOrBuildGlobalFacade(settings).facadeForModules
@@ -184,8 +204,7 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
// we assume that all files come from the same module
val targetPlatform = files.map { TargetPlatformDetector.getPlatform(it) }.toSet().single()
val specialModuleInfo = files.map(KtFile::getModuleInfo).toSet().single()
val sdk = specialModuleInfo.sdk
val settings = PlatformAnalysisSettings(targetPlatform, sdk, specialModuleInfo.supportsAdditionalBuiltInsMembers())
val settings = specialModuleInfo.platformSettings(targetPlatform)
// File copies are created during completion and receive correct modification events through POM.
// Dummy files created e.g. by J2K do not receive events.
@@ -419,7 +438,7 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
}
private fun getResolutionFacadeByModuleInfo(moduleInfo: IdeaModuleInfo, platform: TargetPlatform): ResolutionFacade {
val settings = PlatformAnalysisSettings(platform, moduleInfo.sdk, moduleInfo.supportsAdditionalBuiltInsMembers())
val settings = moduleInfo.platformSettings(platform)
val projectFacade = when (moduleInfo) {
is ScriptDependenciesInfo.ForProject,
is ScriptDependenciesSourceInfo.ForProject -> facadeForScriptDependenciesForProject
@@ -154,7 +154,8 @@ internal class ProjectResolutionFacade(
delegateResolver = delegateResolverForProject,
firstDependency = settings.sdk?.let { SdkInfo(project, it) },
packageOracleFactory = ServiceManager.getService(project, IdePackageOracleFactory::class.java),
invalidateOnOOCB = invalidateOnOOCB
invalidateOnOOCB = invalidateOnOOCB,
isReleaseCoroutines = settings.isReleaseCoroutines
)
if (delegateBuiltIns == null && builtIns is JvmBuiltIns) {
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.cli.common.arguments.Jsr305Parser
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.config.AnalysisFlag
import org.jetbrains.kotlin.config.KotlinFacetSettingsProvider
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.TargetPlatformVersion
@@ -41,10 +40,16 @@ import org.jetbrains.kotlin.script.KotlinScriptDefinition
import org.jetbrains.kotlin.utils.Jsr305State
object IDELanguageSettingsProvider : LanguageSettingsProvider {
override fun getLanguageVersionSettings(moduleInfo: ModuleInfo, project: Project): LanguageVersionSettings =
override fun getLanguageVersionSettings(
moduleInfo: ModuleInfo,
project: Project,
isReleaseCoroutines: Boolean?
): LanguageVersionSettings =
when (moduleInfo) {
is ModuleSourceInfo -> moduleInfo.module.languageVersionSettings
is LibraryInfo -> project.getLanguageVersionSettings(jsr305State = computeJsr305State(project))
is LibraryInfo -> project.getLanguageVersionSettings(
jsr305State = computeJsr305State(project), isReleaseCoroutines = isReleaseCoroutines
)
is ScriptModuleInfo -> getVersionLanguageSettingsForScripts(project, moduleInfo.scriptDefinition)
is ScriptDependenciesInfo.ForFile -> getVersionLanguageSettingsForScripts(project, moduleInfo.scriptDefinition)
is PlatformModuleInfo -> moduleInfo.platformModule.module.languageVersionSettings
@@ -110,13 +110,14 @@ fun Module.getStableName(): Name {
@JvmOverloads
fun Project.getLanguageVersionSettings(
contextModule: Module? = null,
jsr305State: Jsr305State? = null // this is a temporary hack until we'll have a sane way to configure libraries analysis
jsr305State: Jsr305State? = null,
isReleaseCoroutines: Boolean? = null
): LanguageVersionSettings {
val arguments = KotlinCommonCompilerArgumentsHolder.getInstance(this).settings
val languageVersion =
LanguageVersion.fromVersionString(arguments.languageVersion)
?: contextModule?.getAndCacheLanguageLevelByDependencies()
?: LanguageVersion.LATEST_STABLE
?: contextModule?.getAndCacheLanguageLevelByDependencies()
?: LanguageVersion.LATEST_STABLE
val apiVersion = ApiVersion.createByLanguageVersion(LanguageVersion.fromVersionString(arguments.apiVersion) ?: languageVersion)
val compilerSettings = KotlinCompilerSettings.getInstance(this).settings
@@ -127,6 +128,12 @@ fun Project.getLanguageVersionSettings(
val extraLanguageFeatures = additionalArguments.configureLanguageFeatures(MessageCollector.NONE).apply {
configureCoroutinesSupport(CoroutineSupport.byCompilerArguments(KotlinCommonCompilerArgumentsHolder.getInstance(this@getLanguageVersionSettings).settings))
if (isReleaseCoroutines != null) {
put(
LanguageFeature.ReleaseCoroutines,
if (isReleaseCoroutines) LanguageFeature.State.ENABLED else LanguageFeature.State.DISABLED
)
}
}
val extraAnalysisFlags = additionalArguments.configureAnalysisFlags(MessageCollector.NONE).apply {
@@ -146,7 +153,7 @@ val Module.languageVersionSettings: LanguageVersionSettings
get() {
val cachedValue =
getUserData(LANGUAGE_VERSION_SETTINGS)
?: createCachedValueForLanguageVersionSettings().also { putUserData(LANGUAGE_VERSION_SETTINGS, it) }
?: createCachedValueForLanguageVersionSettings().also { putUserData(LANGUAGE_VERSION_SETTINGS, it) }
return cachedValue.value
}