[Platform API] Split TargetPlatform into lightweight TargetPlatform and CompilerServices

This decouples simple data (TargetPlatform) from other subsystem-specific
logic (like default imports, built-ins, etc.).

Aside from purely aesthetic improvements, it also makes it easier
to move 'TargetPlatform' into core (see next commits)
This commit is contained in:
Dmitry Savvinov
2019-03-05 18:14:11 +03:00
parent 83914614b9
commit f2a0a809f1
41 changed files with 217 additions and 98 deletions
-7
View File
@@ -1,7 +0,0 @@
<component name="CopyrightManager">
<copyright>
<option name="allowReplaceRegexp" value="JetBrains" />
<option name="notice" value="Copyright 2010-&amp;#36;today.year JetBrains s.r.o. and Kotlin Programming Language contributors.&#10;Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file." />
<option name="myName" value="apache" />
</copyright>
</component>
@@ -18,7 +18,7 @@ class FirDefaultSimpleImportingScope(session: FirSession) : FirAbstractSimpleImp
override val simpleImports = run {
val importResolveTransformer = FirImportResolveTransformer(session)
session.moduleInfo?.platform?.getDefaultImports(LanguageVersionSettingsImpl.DEFAULT, true)
session.moduleInfo?.compilerServices?.getDefaultImports(LanguageVersionSettingsImpl.DEFAULT, true)
?.filter { !it.isAllUnder }
?.map {
FirImportImpl(session, null, it.fqName, isAllUnder = false, aliasName = null)
@@ -14,7 +14,7 @@ class FirDefaultStarImportingScope(session: FirSession, lookupInFir: Boolean = f
FirAbstractStarImportingScope(session, lookupInFir) {
// TODO: put languageVersionSettings into FirSession?
override val starImports = session.moduleInfo?.platform?.getDefaultImports(LanguageVersionSettingsImpl.DEFAULT, true)
override val starImports = session.moduleInfo?.compilerServices?.getDefaultImports(LanguageVersionSettingsImpl.DEFAULT, true)
?.filter { it.isAllUnder }
?.map {
FirResolvedImportImpl(
@@ -23,8 +23,10 @@ import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
import java.io.File
import java.util.*
@@ -144,6 +146,9 @@ abstract class AbstractFirDiagnosticsSmokeTest : BaseDiagnosticsTest() {
override val platform: TargetPlatform?
get() = JvmPlatform
override val compilerServices: PlatformDependentCompilerServices
get() = JvmPlatformCompilerServices
override fun dependencies(): List<ModuleInfo> {
return listOf(this)
}
@@ -153,6 +158,9 @@ abstract class AbstractFirDiagnosticsSmokeTest : BaseDiagnosticsTest() {
override val platform: TargetPlatform?
get() = JvmPlatform
override val compilerServices: PlatformDependentCompilerServices
get() = JvmPlatformCompilerServices
val dependencies = mutableListOf<ModuleInfo>(this)
override fun dependencies(): List<ModuleInfo> {
return dependencies
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analyzer
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
@@ -16,6 +17,7 @@ interface ModuleInfo {
fun dependencies(): List<ModuleInfo>
val expectedBy: List<ModuleInfo> get() = emptyList()
val platform: TargetPlatform? get() = null
val compilerServices: PlatformDependentCompilerServices? get() = null
fun modulesWhoseInternalsAreVisible(): Collection<ModuleInfo> = listOf()
val capabilities: Map<ModuleDescriptor.Capability<*>, Any?>
get() = mapOf(Capability to this)
@@ -28,7 +30,7 @@ interface ModuleInfo {
// 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 =
platform?.dependencyOnBuiltIns() ?: ModuleInfo.DependencyOnBuiltIns.LAST
compilerServices?.dependencyOnBuiltIns() ?: ModuleInfo.DependencyOnBuiltIns.LAST
//TODO: (module refactoring) provide dependency on builtins after runtime in IDEA
enum class DependencyOnBuiltIns { NONE, AFTER_SDK, LAST }
@@ -14,6 +14,11 @@ import org.jetbrains.kotlin.storage.StorageManager
import java.util.*
abstract class TargetPlatform(val platformName: String) {
override fun toString() = platformName
abstract val platform: MultiTargetPlatform
}
abstract class PlatformDependentCompilerServices {
private data class DefaultImportsKey(val includeKotlinComparisons: Boolean, val includeLowPriorityImports: Boolean)
private val defaultImports = LockBasedStorageManager("TargetPlatform").let { storageManager ->
@@ -42,8 +47,6 @@ abstract class TargetPlatform(val platformName: String) {
}
}
override fun toString() = platformName
abstract val platformConfigurator: PlatformConfigurator
open val defaultLowPriorityImports: List<ImportPath> get() = emptyList()
@@ -60,8 +63,6 @@ abstract class TargetPlatform(val platformName: String) {
open val excludedImports: List<FqName> get() = emptyList()
abstract val multiTargetPlatform: MultiTargetPlatform
// This function is used in "cat.helm.clean:0.1.1-SNAPSHOT": https://plugins.jetbrains.com/plugin/index?xmlId=cat.helm.clean
@Suppress("DeprecatedCallableAddReplaceWith", "unused")
@Deprecated("Use getDefaultImports(LanguageVersionSettings, Boolean) instead.", level = DeprecationLevel.ERROR)
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileFinderFactory
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
@@ -92,8 +93,8 @@ fun createContainerForLazyResolveWithJava(
useBuiltInsProvider: Boolean,
configureJavaClassFinder: (StorageComponentContainer.() -> Unit)? = null,
javaClassTracker: JavaClassesTracker? = null
): StorageComponentContainer = createContainer("LazyResolveWithJava", JvmPlatform) {
configureModule(moduleContext, JvmPlatform, jvmTarget, bindingTrace)
): StorageComponentContainer = createContainer("LazyResolveWithJava", JvmPlatformCompilerServices) {
configureModule(moduleContext, JvmPlatform, jvmTarget, JvmPlatformCompilerServices, bindingTrace)
configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, lookupTracker, expectActualTracker)
if (configureJavaClassFinder != null) {
@@ -23,6 +23,10 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.StorageManager
object JvmPlatform : TargetPlatform("JVM") {
override val platform = MultiTargetPlatform.Specific(platformName)
}
object JvmPlatformCompilerServices : PlatformDependentCompilerServices() {
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {
result.add(ImportPath.fromString("kotlin.jvm.*"))
@@ -40,6 +44,4 @@ object JvmPlatform : TargetPlatform("JVM") {
override val defaultLowPriorityImports: List<ImportPath> = listOf(ImportPath.fromString("java.lang.*"))
override val platformConfigurator: PlatformConfigurator = JvmPlatformConfigurator
override val multiTargetPlatform = MultiTargetPlatform.Specific(platformName)
}
@@ -18,14 +18,8 @@ import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.DynamicTypesSettings
object CommonPlatform : TargetPlatform("Default") {
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {}
override val multiTargetPlatform: MultiTargetPlatform
override val platform: MultiTargetPlatform
get() = MultiTargetPlatform.Common
override val platformConfigurator: PlatformConfigurator = CommonPlatformConfigurator
override fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns = ModuleInfo.DependencyOnBuiltIns.AFTER_SDK
}
private object CommonPlatformConfigurator : PlatformConfiguratorBase(
@@ -41,3 +35,10 @@ private object CommonPlatformConfigurator : PlatformConfiguratorBase(
}
}
object CommonPlatformCompilerServices : PlatformDependentCompilerServices() {
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {}
override val platformConfigurator: PlatformConfigurator = CommonPlatformConfigurator
override fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns = ModuleInfo.DependencyOnBuiltIns.AFTER_SDK
}
@@ -65,6 +65,9 @@ object CommonResolverForModuleFactory : ResolverForModuleFactory() {
override fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns =
if (dependOnOldBuiltIns) ModuleInfo.DependencyOnBuiltIns.LAST else ModuleInfo.DependencyOnBuiltIns.NONE
override val compilerServices: PlatformDependentCompilerServices
get() = CommonPlatformCompilerServices
}
fun analyzeFiles(
@@ -152,8 +155,8 @@ object CommonResolverForModuleFactory : ResolverForModuleFactory() {
targetEnvironment: TargetEnvironment,
metadataPartProvider: MetadataPartProvider,
languageVersionSettings: LanguageVersionSettings
): StorageComponentContainer = createContainer("ResolveCommonCode", CommonPlatform) {
configureModule(moduleContext, CommonPlatform, TargetPlatformVersion.NoVersion, bindingTrace)
): StorageComponentContainer = createContainer("ResolveCommonCode", CommonPlatformCompilerServices) {
configureModule(moduleContext, CommonPlatform, TargetPlatformVersion.NoVersion, CommonPlatformCompilerServices, bindingTrace)
useInstance(moduleContentScope)
useInstance(LookupTracker.DO_NOTHING)
@@ -173,8 +176,6 @@ object CommonResolverForModuleFactory : ResolverForModuleFactory() {
?: error("No MetadataFinderFactory in project")
useInstance(metadataFinderFactory.create(moduleContentScope))
targetEnvironment.configure(this)
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.frontend.di
import org.jetbrains.kotlin.analyzer.common.CommonPlatform
import org.jetbrains.kotlin.analyzer.common.CommonPlatformCompilerServices
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.config.TargetPlatformVersion
@@ -45,7 +46,8 @@ import org.jetbrains.kotlin.types.expressions.LocalLazyDeclarationResolver
fun StorageComponentContainer.configureModule(
moduleContext: ModuleContext,
platform: TargetPlatform,
platformVersion: TargetPlatformVersion
platformVersion: TargetPlatformVersion,
compilerServices: PlatformDependentCompilerServices
) {
useInstance(moduleContext)
useInstance(moduleContext.module)
@@ -55,9 +57,10 @@ fun StorageComponentContainer.configureModule(
useInstance(platform)
useInstance(platformVersion)
useInstance(compilerServices)
platform.platformConfigurator.configureModuleComponents(this)
platform.platformConfigurator.configureModuleDependentCheckers(this)
compilerServices.platformConfigurator.configureModuleComponents(this)
compilerServices.platformConfigurator.configureModuleDependentCheckers(this)
for (extension in StorageComponentContainerContributor.getInstances(moduleContext.project)) {
extension.registerModuleComponents(this, platform, moduleContext.module)
@@ -81,9 +84,10 @@ fun StorageComponentContainer.configureModule(
moduleContext: ModuleContext,
platform: TargetPlatform,
platformVersion: TargetPlatformVersion,
compilerServices: PlatformDependentCompilerServices,
trace: BindingTrace
) {
configureModule(moduleContext, platform, platformVersion)
configureModule(moduleContext, platform, platformVersion, compilerServices)
useInstance(trace)
}
@@ -93,9 +97,10 @@ fun createContainerForBodyResolve(
platform: TargetPlatform,
statementFilter: StatementFilter,
targetPlatformVersion: TargetPlatformVersion,
compilerServices: PlatformDependentCompilerServices,
languageVersionSettings: LanguageVersionSettings
): StorageComponentContainer = createContainer("BodyResolve", platform) {
configureModule(moduleContext, platform, targetPlatformVersion, bindingTrace)
): StorageComponentContainer = createContainer("BodyResolve", compilerServices) {
configureModule(moduleContext, platform, targetPlatformVersion, compilerServices, bindingTrace)
useInstance(statementFilter)
@@ -114,9 +119,10 @@ fun createContainerForLazyBodyResolve(
platform: TargetPlatform,
bodyResolveCache: BodyResolveCache,
targetPlatformVersion: TargetPlatformVersion,
compilerServices: PlatformDependentCompilerServices,
languageVersionSettings: LanguageVersionSettings
): StorageComponentContainer = createContainer("LazyBodyResolve", platform) {
configureModule(moduleContext, platform, targetPlatformVersion, bindingTrace)
): StorageComponentContainer = createContainer("LazyBodyResolve", compilerServices) {
configureModule(moduleContext, platform, targetPlatformVersion, compilerServices, bindingTrace)
useInstance(kotlinCodeAnalyzer)
useInstance(kotlinCodeAnalyzer.fileScopeProvider)
@@ -136,9 +142,10 @@ fun createContainerForLazyLocalClassifierAnalyzer(
targetPlatformVersion: TargetPlatformVersion,
languageVersionSettings: LanguageVersionSettings,
statementFilter: StatementFilter,
localClassDescriptorHolder: LocalClassDescriptorHolder
): StorageComponentContainer = createContainer("LocalClassifierAnalyzer", platform) {
configureModule(moduleContext, platform, targetPlatformVersion, bindingTrace)
localClassDescriptorHolder: LocalClassDescriptorHolder,
compilerServices: PlatformDependentCompilerServices
): StorageComponentContainer = createContainer("LocalClassifierAnalyzer", compilerServices) {
configureModule(moduleContext, platform, targetPlatformVersion, compilerServices, bindingTrace)
useInstance(localClassDescriptorHolder)
useInstance(lookupTracker)
@@ -167,10 +174,11 @@ fun createContainerForLazyResolve(
bindingTrace: BindingTrace,
platform: TargetPlatform,
targetPlatformVersion: TargetPlatformVersion,
compilerServices: PlatformDependentCompilerServices,
targetEnvironment: TargetEnvironment,
languageVersionSettings: LanguageVersionSettings
): StorageComponentContainer = createContainer("LazyResolve", platform) {
configureModule(moduleContext, platform, targetPlatformVersion, bindingTrace)
): StorageComponentContainer = createContainer("LazyResolve", compilerServices) {
configureModule(moduleContext, platform, targetPlatformVersion, compilerServices, bindingTrace)
useInstance(declarationProviderFactory)
useInstance(languageVersionSettings)
@@ -191,6 +199,7 @@ fun createLazyResolveSession(moduleContext: ModuleContext, files: Collection<KtF
BindingTraceContext(),
CommonPlatform,
TargetPlatformVersion.NoVersion,
CommonPlatformCompilerServices,
CompilerEnvironment,
LanguageVersionSettingsImpl.DEFAULT
).get<ResolveSession>()
@@ -96,5 +96,5 @@ abstract class PlatformConfiguratorBase(
}
}
fun createContainer(id: String, platform: TargetPlatform, init: StorageComponentContainer.() -> Unit) =
composeContainer(id, platform.platformConfigurator.platformSpecificContainer, init)
fun createContainer(id: String, compilerServices: PlatformDependentCompilerServices, init: StorageComponentContainer.() -> Unit) =
composeContainer(id, compilerServices.platformConfigurator.platformSpecificContainer, init)
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.KtImportDirective
import org.jetbrains.kotlin.psi.KtImportInfo
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
import org.jetbrains.kotlin.resolve.extensions.ExtraImportsProviderExtension
import org.jetbrains.kotlin.resolve.scopes.*
@@ -40,13 +40,13 @@ data class FileScopes(val lexicalScope: LexicalScope, val importingScope: Import
class FileScopeFactory(
private val topLevelDescriptorProvider: TopLevelDescriptorProvider,
private val bindingTrace: BindingTrace,
private val targetPlatform: TargetPlatform,
private val compilerServices: PlatformDependentCompilerServices,
private val components: ImportResolutionComponents
) {
private val defaultImports =
targetPlatform.getDefaultImports(components.languageVersionSettings, includeLowPriorityImports = false).map(::DefaultImportImpl)
compilerServices.getDefaultImports(components.languageVersionSettings, includeLowPriorityImports = false).map(::DefaultImportImpl)
private val defaultLowPriorityImports = targetPlatform.defaultLowPriorityImports.map(::DefaultImportImpl)
private val defaultLowPriorityImports = compilerServices.defaultLowPriorityImports.map(::DefaultImportImpl)
private class DefaultImportImpl(private val importPath: ImportPath) : KtImportInfo {
override val isAllUnder: Boolean get() = importPath.isAllUnder
@@ -95,7 +95,7 @@ class FileScopeFactory(
tempTrace,
packageFragment = null,
aliasImportNames = aliasImportNames,
excludedImports = targetPlatform.excludedImports
excludedImports = compilerServices.excludedImports
)
val lowPriority = createDefaultImportResolver(
AllUnderImportsIndexed(defaultLowPriorityImports.also { imports ->
@@ -61,6 +61,7 @@ class LocalClassifierAnalyzer(
private val typeResolver: TypeResolver,
private val annotationResolver: AnnotationResolver,
private val platform: TargetPlatform,
private val compilerServices: PlatformDependentCompilerServices,
private val lookupTracker: LookupTracker,
private val supertypeLoopChecker: SupertypeLoopChecker,
private val targetPlatformVersion: TargetPlatformVersion,
@@ -103,7 +104,8 @@ class LocalClassifierAnalyzer(
delegationFilter,
wrappedTypeFactory,
substitutingScopeProvider
)
),
compilerServices
)
container.get<LazyTopDownAnalyzer>().analyzeDeclarations(
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS
import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.js.resolve.MODULE_KIND
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtFile
@@ -84,7 +84,7 @@ abstract class AbstractDiagnosticsTestWithJsStdLib : AbstractDiagnosticsTest() {
override fun shouldSkipJvmSignatureDiagnostics(groupedByModule: Map<TestModule?, List<TestFile>>): Boolean = true
override fun createModule(moduleName: String, storageManager: StorageManager): ModuleDescriptorImpl =
ModuleDescriptorImpl(Name.special("<$moduleName>"), storageManager, JsPlatform.builtIns)
ModuleDescriptorImpl(Name.special("<$moduleName>"), storageManager, JsPlatformCompilerServices.builtIns)
override fun createSealedModule(storageManager: StorageManager): ModuleDescriptorImpl {
val module = createModule("kotlin-js-test-module", storageManager)
@@ -7,13 +7,16 @@ package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
class FirTestModuleInfo(
override val name: Name = Name.identifier("TestModule"),
val dependencies: MutableList<ModuleInfo> = mutableListOf(),
override val platform: TargetPlatform = JvmPlatform
override val platform: TargetPlatform = JvmPlatform,
override val compilerServices: PlatformDependentCompilerServices = JvmPlatformCompilerServices
) : ModuleInfo {
override fun dependencies(): List<ModuleInfo> = dependencies
}
@@ -22,11 +22,15 @@ import org.jetbrains.kotlin.analyzer.LanguageSettingsProvider
import org.jetbrains.kotlin.analyzer.ModuleContent
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.analyzer.ResolverForProjectImpl
import org.jetbrains.kotlin.analyzer.common.CommonPlatform
import org.jetbrains.kotlin.analyzer.common.CommonPlatformCompilerServices
import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.JvmResolverForModuleFactory
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
@@ -61,4 +65,10 @@ private class TestModule(val dependsOnBuiltIns: Boolean) : ModuleInfo {
ModuleInfo.DependencyOnBuiltIns.LAST
else
ModuleInfo.DependencyOnBuiltIns.NONE
override val platform: TargetPlatform
get() = CommonPlatform
override val compilerServices: PlatformDependentCompilerServices?
get() = CommonPlatformCompilerServices
}
@@ -29,13 +29,14 @@ import org.jetbrains.kotlin.frontend.di.configureModule
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.FakeCallResolver
fun createContainerForTests(project: Project, module: ModuleDescriptor): ContainerForTests {
return ContainerForTests(createContainer("Tests", JvmPlatform) {
configureModule(ModuleContext(module, project), JvmPlatform, JvmTarget.DEFAULT)
return ContainerForTests(createContainer("Tests", JvmPlatformCompilerServices) {
configureModule(ModuleContext(module, project), JvmPlatform, JvmTarget.DEFAULT, JvmPlatformCompilerServices)
useInstance(LanguageVersionSettingsImpl.DEFAULT)
useImpl<SubstitutingScopeProviderImpl>()
useImpl<AnnotationResolverImpl>()
@@ -34,11 +34,15 @@ import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.descriptorUtil.annotationClass
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.jvm.JvmResolverForModuleFactory
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestJdkKind
@@ -56,6 +60,12 @@ class MultiModuleJavaAnalysisCustomTest : KtUsefulTestCase() {
) : ModuleInfo {
override fun dependencies() = _dependencies()
override val name = Name.special("<$_name>")
override val platform: TargetPlatform
get() = JvmPlatform
override val compilerServices: PlatformDependentCompilerServices?
get() = JvmPlatformCompilerServices
}
fun testJavaEntitiesBelongToCorrectModule() {
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.facade.K2JSTranslator
import org.jetbrains.kotlin.js.facade.MainCallParameters
import org.jetbrains.kotlin.js.facade.TranslationResult
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.serialization.AbstractVersionRequirementTest
@@ -76,7 +76,7 @@ class JsVersionRequirementTest : AbstractVersionRequirementTest() {
private fun createModule(environment: KotlinCoreEnvironment): MutableModuleContext {
val config = JsConfig(environment.project, environment.configuration)
return ContextForNewModule(ProjectContext(environment.project), Name.special("<test>"), JsPlatform.builtIns, null).apply {
return ContextForNewModule(ProjectContext(environment.project), Name.special("<test>"), JsPlatformCompilerServices.builtIns, null).apply {
setDependencies(listOf(module) + config.moduleDescriptors + module.builtIns.builtInsModule)
}
}
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.TEST_PACKAGE_FQNAME
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil.readModuleAsProto
@@ -94,7 +94,7 @@ class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() {
}
private fun deserialize(metaFile: File): ModuleDescriptorImpl {
val module = KotlinTestUtils.createEmptyModule("<${KotlinTestUtils.TEST_MODULE_NAME}>", JsPlatform.builtIns)
val module = KotlinTestUtils.createEmptyModule("<${KotlinTestUtils.TEST_MODULE_NAME}>", JsPlatformCompilerServices.builtIns)
val metadata = KotlinJavascriptMetadataUtils.loadMetadata(metaFile).single()
val (header, packageFragmentProtos) = readModuleAsProto(metadata.body, metadata.version)
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
import org.jetbrains.kotlin.js.resolve.JsResolverForModuleFactory
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
class JsPlatformKindResolution : IdePlatformKindResolution {
@@ -30,6 +30,6 @@ class JsPlatformKindResolution : IdePlatformKindResolution {
get() = JsResolverForModuleFactory
override fun createBuiltIns(settings: PlatformAnalysisSettings, projectContext: ProjectContext): KotlinBuiltIns {
return JsPlatform.builtIns
return JsPlatformCompilerServices.builtIns
}
}
@@ -64,6 +64,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
@@ -304,11 +305,11 @@ internal object IDELightClassContexts {
moduleDescriptor.setDependencies(moduleDescriptor, moduleDescriptor.builtIns.builtInsModule)
val moduleInfo = files.first().getModuleInfo()
val container = createContainer("LightClassStub", JvmPlatform) {
val container = createContainer("LightClassStub", JvmPlatformCompilerServices) {
val jvmTarget = IDELanguageSettingsProvider.getTargetPlatform(moduleInfo, project) as? JvmTarget
configureModule(
ModuleContext(moduleDescriptor, project), JvmPlatform,
jvmTarget ?: JvmTarget.DEFAULT, trace
jvmTarget ?: JvmTarget.DEFAULT, JvmPlatformCompilerServices, trace
)
useInstance(GlobalSearchScope.EMPTY_SCOPE)
@@ -37,13 +37,16 @@ import org.jetbrains.kotlin.idea.core.isInTestSourceContentKotlinAware
import org.jetbrains.kotlin.idea.framework.getLibraryPlatform
import org.jetbrains.kotlin.idea.project.KotlinModuleModificationTracker
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.idea.project.findCompilerServices
import org.jetbrains.kotlin.idea.project.getStableName
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
import org.jetbrains.kotlin.idea.util.isInSourceContentWithoutInjected
import org.jetbrains.kotlin.idea.util.rootManager
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.idePlatformKind
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.utils.addIfNotNull
import java.util.*
@@ -138,6 +141,9 @@ interface ModuleSourceInfo : IdeaModuleInfo, TrackableModuleInfo {
override val platform: TargetPlatform
get() = TargetPlatformDetector.getPlatform(module)
override val compilerServices: PlatformDependentCompilerServices
get() = platform.findCompilerServices
override fun createModificationTracker(): ModificationTracker =
KotlinModuleModificationTracker(module)
}
@@ -280,6 +286,9 @@ open class LibraryInfo(val project: Project, val library: Library) : IdeaModuleI
override val platform: TargetPlatform
get() = getLibraryPlatform(project, library)
override val compilerServices: PlatformDependentCompilerServices
get() = platform.findCompilerServices
override val sourcesModuleInfo: SourceForBinaryModuleInfo
get() = LibrarySourceInfo(project, library, this)
@@ -313,6 +322,9 @@ data class LibrarySourceInfo(val project: Project, val library: Library, overrid
override val platform: TargetPlatform?
get() = binariesModuleInfo.platform
override val compilerServices: PlatformDependentCompilerServices?
get() = binariesModuleInfo.compilerServices
override fun toString() = "LibrarySourceInfo(libraryName=${library.name})"
}
@@ -338,6 +350,12 @@ object NotUnderContentRootModuleInfo : IdeaModuleInfo {
//TODO: (module refactoring) dependency on runtime can be of use here
override fun dependencies(): List<IdeaModuleInfo> = listOf(this)
override val platform: TargetPlatform?
get() = null
override val compilerServices: PlatformDependentCompilerServices?
get() = null
}
private class LibraryWithoutSourceScope(project: Project, private val library: Library) :
@@ -427,6 +445,9 @@ data class PlatformModuleInfo(
override val moduleOrigin: ModuleOrigin
get() = platformModule.moduleOrigin
override val compilerServices: PlatformDependentCompilerServices?
get() = platform?.findCompilerServices
override fun dependencies() = platformModule.dependencies()
override fun modulesWhoseInternalsAreVisible() = containedModules.flatMap { it.modulesWhoseInternalsAreVisible() }
@@ -14,6 +14,8 @@ import org.jetbrains.kotlin.idea.core.script.dependencies.ScriptAdditionalIdeaDe
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.scripting.definitions.KotlinScriptDefinition
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
data class ScriptModuleInfo(
val project: Project,
@@ -45,6 +47,12 @@ data class ScriptModuleInfo(
dependenciesInfo.sdk?.let { add(SdkInfo(project, it)) }
}
}
override val platform: TargetPlatform?
get() = null
override val compilerServices: PlatformDependentCompilerServices?
get() = null
}
sealed class ScriptDependenciesInfo(val project: Project) : IdeaModuleInfo, BinaryModuleInfo {
@@ -66,6 +74,12 @@ sealed class ScriptDependenciesInfo(val project: Project) : IdeaModuleInfo, Bina
override val sourcesModuleInfo: SourceForBinaryModuleInfo?
get() = ScriptDependenciesSourceInfo.ForProject(project)
override val platform: TargetPlatform?
get() = null
override val compilerServices: PlatformDependentCompilerServices?
get() = null
class ForFile(
project: Project,
val scriptFile: VirtualFile,
@@ -115,5 +129,11 @@ sealed class ScriptDependenciesSourceInfo(val project: Project) : IdeaModuleInfo
override fun equals(other: Any?): Boolean = other is ScriptDependenciesSourceInfo && this.project == other.project
override val platform: TargetPlatform?
get() = null
override val compilerServices: PlatformDependentCompilerServices?
get() = null
class ForProject(project: Project) : ScriptDependenciesSourceInfo(project)
}
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.frontend.di.createContainerForLazyBodyResolve
import org.jetbrains.kotlin.idea.caches.project.getModuleInfo
import org.jetbrains.kotlin.idea.compiler.IDELanguageSettingsProvider
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.idea.project.findCompilerServices
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
@@ -202,6 +203,7 @@ private object KotlinResolveDataProvider {
targetPlatform,
bodyResolveCache,
targetPlatformVersion,
targetPlatform.findCompilerServices,
analyzableElement.languageVersionSettings
).get<LazyTopDownAnalyzer>()
@@ -718,6 +718,7 @@ class ResolveElementCache(
targetPlatform,
statementFilter,
file.jvmTarget,
targetPlatform.findCompilerServices,
file.languageVersionSettings
).get()
}
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.project
import org.jetbrains.kotlin.analyzer.common.CommonPlatform
import org.jetbrains.kotlin.analyzer.common.CommonPlatformCompilerServices
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.resolve.PlatformDependentCompilerServices
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
import org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform
import org.jetbrains.kotlin.resolve.konan.platform.NativePlatformCompilerServices
import java.lang.IllegalStateException
val TargetPlatform.findCompilerServices: PlatformDependentCompilerServices
get() =
when (this) {
is JvmPlatform -> JvmPlatformCompilerServices
is JsPlatform -> JsPlatformCompilerServices
is KonanPlatform -> NativePlatformCompilerServices
is CommonPlatform -> CommonPlatformCompilerServices
else -> throw IllegalStateException("Unknown platform $this")
}
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.asJava.ImpreciseResolveResult.*
import org.jetbrains.kotlin.idea.caches.project.getNullableModuleInfo
import org.jetbrains.kotlin.idea.compiler.IDELanguageSettingsProvider
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.idea.project.findCompilerServices
import org.jetbrains.kotlin.idea.stubindex.KotlinTypeAliasShortNameIndex
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.name.FqName
@@ -258,7 +259,7 @@ class PsiBasedClassResolver @TestOnly constructor(private val targetClassFqName:
private fun KtFile.getDefaultImports(): List<ImportPath> {
val moduleInfo = getNullableModuleInfo() ?: return emptyList()
return TargetPlatformDetector.getPlatform(this).getDefaultImports(
return TargetPlatformDetector.getPlatform(this).findCompilerServices.getDefaultImports(
IDELanguageSettingsProvider.getLanguageVersionSettings(moduleInfo, project),
includeLowPriorityImports = true
)
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
import org.jetbrains.kotlin.resolve.TargetEnvironment
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.konan.platform.KonanPlatform
import org.jetbrains.kotlin.resolve.konan.platform.NativePlatformCompilerServices
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService.Companion.createDeclarationProviderFactory
@@ -48,6 +49,7 @@ object NativeResolverForModuleFactory : ResolverForModuleFactory() {
CodeAnalyzerInitializer.getInstance(moduleContext.project).createTrace(),
KonanPlatform,
TargetPlatformVersion.NoVersion,
NativePlatformCompilerServices,
targetEnvironment,
languageVersionSettings
)
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.idea.inspections.collections
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.psi.qualifiedExpressionVisitor
@@ -31,7 +31,7 @@ class SimplifiableCallChainInspection : AbstractCallChainChecker() {
if (conversion.replacement.startsWith("joinTo")) {
// Function parameter in map must have String result type
if (!firstResolvedCall.hasLastFunctionalParameterWithResult(context) {
it.isSubtypeOf(JsPlatform.builtIns.charSequence.defaultType)
it.isSubtypeOf(JsPlatformCompilerServices.builtIns.charSequence.defaultType)
}
) return@check false
}
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.idea.analysis.analyzeInContext
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
import org.jetbrains.kotlin.idea.codeInliner.CodeToInline
import org.jetbrains.kotlin.idea.codeInliner.CodeToInlineBuilder
import org.jetbrains.kotlin.idea.project.findCompilerServices
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
@@ -142,7 +143,7 @@ object ReplaceWithAnnotationAnalyzer {
languageVersionSettings: LanguageVersionSettings
): List<ImportingScope> {
val allDefaultImports =
resolutionFacade.frontendService<TargetPlatform>().getDefaultImports(languageVersionSettings, includeLowPriorityImports = true)
resolutionFacade.frontendService<TargetPlatform>().findCompilerServices.getDefaultImports(languageVersionSettings, includeLowPriorityImports = true)
val (allUnderImports, aliasImports) = allDefaultImports.partition { it.isAllUnder }
// this solution doesn't support aliased default imports with a different alias
// TODO: Create import directives from ImportPath, create ImportResolver, create LazyResolverScope, see FileScopeProviderImpl
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.imports.ImportPathComparator
import org.jetbrains.kotlin.idea.imports.getImportableTargets
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.idea.project.findCompilerServices
import org.jetbrains.kotlin.idea.refactoring.fqName.isImported
import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -60,19 +61,19 @@ class ImportInsertHelperImpl(private val project: Project) : ImportInsertHelper(
override fun isImportedWithDefault(importPath: ImportPath, contextFile: KtFile): Boolean {
val languageVersionSettings = contextFile.getResolutionFacade().frontendService<LanguageVersionSettings>()
val platform = TargetPlatformDetector.getPlatform(contextFile)
val allDefaultImports = platform.getDefaultImports(languageVersionSettings, includeLowPriorityImports = true)
val allDefaultImports = platform.findCompilerServices.getDefaultImports(languageVersionSettings, includeLowPriorityImports = true)
val scriptExtraImports = contextFile.takeIf { it.isScript() }?.let { ktFile ->
val scriptDependencies = ScriptDependenciesProvider.getInstance(ktFile.project)?.getScriptDependencies(ktFile.originalFile)
scriptDependencies?.imports?.map { ImportPath.fromString(it) }
}.orEmpty()
return importPath.isImported(allDefaultImports + scriptExtraImports, platform.excludedImports)
return importPath.isImported(allDefaultImports + scriptExtraImports, platform.findCompilerServices.excludedImports)
}
override fun isImportedWithLowPriorityDefaultImport(importPath: ImportPath, contextFile: KtFile): Boolean {
val platform = TargetPlatformDetector.getPlatform(contextFile)
return importPath.isImported(platform.defaultLowPriorityImports, platform.excludedImports)
return importPath.isImported(platform.findCompilerServices.defaultLowPriorityImports, platform.findCompilerServices.excludedImports)
}
override fun mayImportOnShortenReferences(descriptor: DeclarationDescriptor): Boolean {
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.renderer.render
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformCompilerServices
fun Converter.convertImportList(importList: PsiImportList): ImportList {
val imports = importList.allImportStatements
@@ -160,7 +160,7 @@ private fun convertNonStaticImport(fqName: FqName, isOnDemand: Boolean, target:
private fun renderImportName(fqName: FqName, isOnDemand: Boolean)
= if (isOnDemand) fqName.render() + ".*" else fqName.render()
private val DEFAULT_IMPORTS_SET: Set<FqName> = JvmPlatform.getDefaultImports(
private val DEFAULT_IMPORTS_SET: Set<FqName> = JvmPlatformCompilerServices.getDefaultImports(
// TODO: use the correct LanguageVersionSettings instance here
LanguageVersionSettingsImpl.DEFAULT,
includeLowPriorityImports = true
@@ -29,13 +29,11 @@ import org.jetbrains.kotlin.frontend.di.configureModule
import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
import org.jetbrains.kotlin.serialization.js.PackagesWithHeaderMetadata
import org.jetbrains.kotlin.types.SubstitutingScopeProviderImpl
fun createTopDownAnalyzerForJs(
@@ -47,8 +45,8 @@ fun createTopDownAnalyzerForJs(
expectActualTracker: ExpectActualTracker,
additionalPackages: List<PackageFragmentProvider>
): LazyTopDownAnalyzer {
val storageComponentContainer = createContainer("TopDownAnalyzerForJs", JsPlatform) {
configureModule(moduleContext, JsPlatform, TargetPlatformVersion.NoVersion, bindingTrace)
val storageComponentContainer = createContainer("TopDownAnalyzerForJs", JsPlatformCompilerServices) {
configureModule(moduleContext, JsPlatform, TargetPlatformVersion.NoVersion, JsPlatformCompilerServices, bindingTrace)
useInstance(declarationProviderFactory)
useImpl<AnnotationResolverImpl>()
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.js.analyzer.JsAnalysisResult
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices
import org.jetbrains.kotlin.js.resolve.MODULE_KIND
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtFile
@@ -59,7 +59,7 @@ object TopDownAnalyzerFacadeForJS {
val builtIns = when {
thisIsBuiltInsModule -> DefaultBuiltIns(loadBuiltInsFromCurrentClassLoader = false)
customBuiltInsModule != null -> customBuiltInsModule.builtIns
else -> JsPlatform.builtIns
else -> JsPlatformCompilerServices.builtIns
}
val moduleName = configuration[CommonConfigurationKeys.MODULE_NAME]!!
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.config.*;
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider;
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
import org.jetbrains.kotlin.incremental.components.LookupTracker;
import org.jetbrains.kotlin.js.resolve.JsPlatform;
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration;
import org.jetbrains.kotlin.serialization.js.*;
@@ -251,7 +251,7 @@ public class JsConfig {
LanguageVersionSettings languageVersionSettings = CommonConfigurationKeysKt.getLanguageVersionSettings(configuration);
for (JsModuleDescriptor<KotlinJavaScriptLibraryParts> cached : metadataCache) {
ModuleDescriptorImpl moduleDescriptor = new ModuleDescriptorImpl(
Name.special("<" + cached.getName() + ">"), storageManager, JsPlatform.INSTANCE.getBuiltIns()
Name.special("<" + cached.getName() + ">"), storageManager, JsPlatformCompilerServices.INSTANCE.getBuiltIns()
);
KotlinJavaScriptLibraryParts parts = cached.getData();
@@ -310,7 +310,7 @@ public class JsConfig {
"Expected JS metadata version " + JsMetadataVersion.INSTANCE + ", but actual metadata version is " + m.getVersion();
ModuleDescriptorImpl moduleDescriptor = new ModuleDescriptorImpl(
Name.special("<" + m.getModuleName() + ">"), storageManager, JsPlatform.INSTANCE.getBuiltIns()
Name.special("<" + m.getModuleName() + ">"), storageManager, JsPlatformCompilerServices.INSTANCE.getBuiltIns()
);
LookupTracker lookupTracker = configuration.get(CommonConfigurationKeys.LOOKUP_TRACKER, LookupTracker.DO_NOTHING.INSTANCE);
@@ -327,6 +327,6 @@ public class JsConfig {
}
private static void setDependencies(ModuleDescriptorImpl module, List<ModuleDescriptorImpl> modules) {
module.setDependencies(CollectionsKt.plus(modules, JsPlatform.INSTANCE.getBuiltIns().getBuiltInsModule()));
module.setDependencies(CollectionsKt.plus(modules, JsPlatformCompilerServices.INSTANCE.getBuiltIns().getBuiltInsModule()));
}
}
@@ -19,13 +19,15 @@ package org.jetbrains.kotlin.js.resolve
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
import org.jetbrains.kotlin.resolve.PlatformConfigurator
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.storage.StorageManager
object JsPlatform : TargetPlatform("JS") {
override val platform: MultiTargetPlatform
get() = MultiTargetPlatform.Specific(platformName)
}
object JsPlatformCompilerServices : PlatformDependentCompilerServices() {
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {
result.add(ImportPath.fromString("kotlin.js.*"))
}
@@ -35,8 +37,6 @@ object JsPlatform : TargetPlatform("JS") {
val builtIns: KotlinBuiltIns
get() = DefaultBuiltIns.Instance
override val multiTargetPlatform = MultiTargetPlatform.Specific(platformName)
override val excludedImports: List<FqName> =
listOf("Promise", "Date", "Console", "Math", "RegExp", "RegExpMatch", "Json", "json").map { FqName("kotlin.js.$it") }
}
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.frontend.di.createContainerForLazyResolve
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.resolve.TargetEnvironment
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
@@ -61,6 +60,7 @@ object JsResolverForModuleFactory : ResolverForModuleFactory() {
BindingTraceContext(/* allowSliceRewrite = */ true),
JsPlatform,
TargetPlatformVersion.NoVersion,
JsPlatformCompilerServices,
targetEnvironment,
languageVersionSettings
)
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.js.backend.ast.metadata.TypeCheck;
import org.jetbrains.kotlin.js.config.JsConfig;
import org.jetbrains.kotlin.js.naming.NameSuggestion;
import org.jetbrains.kotlin.js.naming.SuggestedName;
import org.jetbrains.kotlin.js.resolve.JsPlatform;
import org.jetbrains.kotlin.js.resolve.JsPlatformCompilerServices;
import org.jetbrains.kotlin.js.translate.intrinsic.functions.factories.ArrayFIF;
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils;
@@ -57,8 +57,8 @@ public final class Namer {
public static final String KOTLIN_NAME = KotlinLanguage.NAME;
public static final String KOTLIN_LOWER_NAME = KOTLIN_NAME.toLowerCase();
public static final String EQUALS_METHOD_NAME = getStableMangledNameForDescriptor(JsPlatform.INSTANCE.getBuiltIns().getAny(), "equals");
public static final String COMPARE_TO_METHOD_NAME = getStableMangledNameForDescriptor(JsPlatform.INSTANCE.getBuiltIns().getComparable(), "compareTo");
public static final String EQUALS_METHOD_NAME = getStableMangledNameForDescriptor(JsPlatformCompilerServices.INSTANCE.getBuiltIns().getAny(), "equals");
public static final String COMPARE_TO_METHOD_NAME = getStableMangledNameForDescriptor(JsPlatformCompilerServices.INSTANCE.getBuiltIns().getComparable(), "compareTo");
public static final String LONG_FROM_NUMBER = "fromNumber";
public static final String LONG_TO_NUMBER = "toNumber";
public static final String LONG_FROM_INT = "fromInt";
@@ -5,18 +5,17 @@
package org.jetbrains.kotlin.resolve.konan.platform
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
import org.jetbrains.kotlin.resolve.PlatformConfigurator
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.storage.StorageManager
object KonanPlatform : TargetPlatform("Native") {
override val platform = MultiTargetPlatform.Specific(platformName)
}
object NativePlatformCompilerServices : PlatformDependentCompilerServices() {
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {
result.add(ImportPath.fromString("kotlin.native.*"))
}
override val multiTargetPlatform = MultiTargetPlatform.Specific(platformName)
override val platformConfigurator: PlatformConfigurator = KonanPlatformConfigurator
}