Move dependency on built-ins in IDE higher for common modules
See the comment in ModuleInfo
This commit is contained in:
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.TargetEnvironment
|
|||||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||||
import org.jetbrains.kotlin.utils.keysToMap
|
import org.jetbrains.kotlin.utils.keysToMap
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.coroutines.experimental.buildSequence
|
||||||
|
|
||||||
class ResolverForModule(
|
class ResolverForModule(
|
||||||
val packageFragmentProvider: PackageFragmentProvider,
|
val packageFragmentProvider: PackageFragmentProvider,
|
||||||
@@ -130,27 +131,22 @@ interface ModuleInfo {
|
|||||||
fun dependencies(): List<ModuleInfo>
|
fun dependencies(): List<ModuleInfo>
|
||||||
val platform: TargetPlatform? get() = null
|
val platform: TargetPlatform? get() = null
|
||||||
fun modulesWhoseInternalsAreVisible(): Collection<ModuleInfo> = listOf()
|
fun modulesWhoseInternalsAreVisible(): Collection<ModuleInfo> = listOf()
|
||||||
fun dependencyOnBuiltIns(): DependencyOnBuiltIns = DependenciesOnBuiltIns.LAST
|
|
||||||
val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
|
val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
|
||||||
get() = mapOf(Capability to this)
|
get() = mapOf(Capability to this)
|
||||||
|
|
||||||
//TODO: (module refactoring) provide dependency on builtins after runtime in IDEA
|
// For common modules, we add built-ins at the beginning of the dependencies list, after the SDK.
|
||||||
interface DependencyOnBuiltIns {
|
// This is needed because if a JVM module depends on the common module, we should use JVM built-ins for resolution of both modules.
|
||||||
fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>)
|
// The common module usually depends on kotlin-stdlib-common which may or may not have its own (common, non-JVM) built-ins,
|
||||||
}
|
// but if they are present, they should come after JVM built-ins in the dependencies list, because JVM built-ins contain
|
||||||
|
// additional members dependent on the JDK
|
||||||
|
fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns =
|
||||||
|
if (platform == TargetPlatform.Default)
|
||||||
|
ModuleInfo.DependencyOnBuiltIns.AFTER_SDK
|
||||||
|
else
|
||||||
|
ModuleInfo.DependencyOnBuiltIns.LAST
|
||||||
|
|
||||||
enum class DependenciesOnBuiltIns : DependencyOnBuiltIns {
|
//TODO: (module refactoring) provide dependency on builtins after runtime in IDEA
|
||||||
NONE {
|
enum class DependencyOnBuiltIns { NONE, AFTER_SDK, LAST }
|
||||||
override fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>) {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
},
|
|
||||||
LAST {
|
|
||||||
override fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>) {
|
|
||||||
dependencies.add(builtinsModule)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val Capability = ModuleDescriptor.Capability<ModuleInfo>("ModuleInfo")
|
val Capability = ModuleDescriptor.Capability<ModuleInfo>("ModuleInfo")
|
||||||
@@ -180,16 +176,24 @@ abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
|||||||
}, delegateResolver)
|
}, delegateResolver)
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
resolverForProject.descriptorForModule(module).setDependencies(LazyModuleDependencies(
|
val moduleDescriptor = resolverForProject.descriptorForModule(module)
|
||||||
|
moduleDescriptor.setDependencies(LazyModuleDependencies(
|
||||||
storageManager,
|
storageManager,
|
||||||
computeDependencies = {
|
computeDependencies = {
|
||||||
val orderedDependencies = listOfNotNull(firstDependency) + module.dependencies()
|
buildSequence {
|
||||||
val dependenciesDescriptors = orderedDependencies.mapTo(ArrayList<ModuleDescriptorImpl>()) { dependencyInfo ->
|
if (firstDependency != null) {
|
||||||
resolverForProject.descriptorForModule(dependencyInfo as M)
|
yield(resolverForProject.descriptorForModule(firstDependency))
|
||||||
}
|
}
|
||||||
module.dependencyOnBuiltIns().adjustDependencies(
|
if (module.dependencyOnBuiltIns() == ModuleInfo.DependencyOnBuiltIns.AFTER_SDK) {
|
||||||
resolverForProject.descriptorForModule(module).builtIns.builtInsModule, dependenciesDescriptors)
|
yield(moduleDescriptor.builtIns.builtInsModule)
|
||||||
dependenciesDescriptors
|
}
|
||||||
|
for (dependency in module.dependencies()) {
|
||||||
|
yield(resolverForProject.descriptorForModule(dependency as M))
|
||||||
|
}
|
||||||
|
if (module.dependencyOnBuiltIns() == ModuleInfo.DependencyOnBuiltIns.LAST) {
|
||||||
|
yield(moduleDescriptor.builtIns.builtInsModule)
|
||||||
|
}
|
||||||
|
}.toList()
|
||||||
},
|
},
|
||||||
computeModulesWhoseInternalsAreVisible = {
|
computeModulesWhoseInternalsAreVisible = {
|
||||||
module.modulesWhoseInternalsAreVisible().mapTo(LinkedHashSet()) {
|
module.modulesWhoseInternalsAreVisible().mapTo(LinkedHashSet()) {
|
||||||
@@ -202,8 +206,7 @@ abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
|||||||
.filter { modulePlatforms(it) != MultiTargetPlatform.Common && module in it.dependencies() }
|
.filter { modulePlatforms(it) != MultiTargetPlatform.Common && module in it.dependencies() }
|
||||||
.mapTo(mutableSetOf(), resolverForProject::descriptorForModule)
|
.mapTo(mutableSetOf(), resolverForProject::descriptorForModule)
|
||||||
}
|
}
|
||||||
)
|
))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (module in modules) {
|
for (module in modules) {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ object DefaultAnalyzerFacade : AnalyzerFacade<PlatformAnalysisParameters>() {
|
|||||||
override fun dependencies() = listOf(this)
|
override fun dependencies() = listOf(this)
|
||||||
|
|
||||||
override fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns =
|
override fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns =
|
||||||
if (dependOnOldBuiltIns) ModuleInfo.DependenciesOnBuiltIns.LAST else ModuleInfo.DependenciesOnBuiltIns.NONE
|
if (dependOnOldBuiltIns) ModuleInfo.DependencyOnBuiltIns.LAST else ModuleInfo.DependencyOnBuiltIns.NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
fun analyzeFiles(
|
fun analyzeFiles(
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ private class TestModule(val dependsOnBuiltIns: Boolean) : ModuleInfo {
|
|||||||
override fun dependencies() = listOf(this)
|
override fun dependencies() = listOf(this)
|
||||||
override fun dependencyOnBuiltIns() =
|
override fun dependencyOnBuiltIns() =
|
||||||
if (dependsOnBuiltIns)
|
if (dependsOnBuiltIns)
|
||||||
ModuleInfo.DependenciesOnBuiltIns.LAST
|
ModuleInfo.DependencyOnBuiltIns.LAST
|
||||||
else
|
else
|
||||||
ModuleInfo.DependenciesOnBuiltIns.NONE
|
ModuleInfo.DependencyOnBuiltIns.NONE
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user