mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-14 00:21:27 +00:00
Supply JVM and JS platforms when compile from CLI
To be able to check descriptor's platform in frontend during plugin processing. This is needed for serialization plugin because some synthesized descriptors (annotation interface implementation) must be JVM-only (or the Native compilation fails).
This commit is contained in:
@@ -55,6 +55,7 @@ import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentPr
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackagePartProvider
|
||||
import org.jetbrains.kotlin.modules.TargetId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
@@ -125,7 +126,11 @@ object TopDownAnalyzerFacadeForJVM {
|
||||
targetEnvironment: TargetEnvironment = CompilerEnvironment,
|
||||
sourceModuleSearchScope: GlobalSearchScope = newModuleSearchScope(project, files)
|
||||
): ComponentProvider {
|
||||
val moduleContext = createModuleContext(project, configuration)
|
||||
val jvmTarget = configuration.get(JVMConfigurationKeys.JVM_TARGET, JvmTarget.DEFAULT)
|
||||
val languageVersionSettings = configuration.languageVersionSettings
|
||||
val jvmPlatform = JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget)
|
||||
|
||||
val moduleContext = createModuleContext(project, configuration, jvmPlatform)
|
||||
|
||||
val storageManager = moduleContext.storageManager
|
||||
val module = moduleContext.module
|
||||
@@ -140,9 +145,6 @@ object TopDownAnalyzerFacadeForJVM {
|
||||
val sourceScope = if (separateModules) sourceModuleSearchScope else GlobalSearchScope.allScope(project)
|
||||
val moduleClassResolver = SourceOrBinaryModuleClassResolver(sourceScope)
|
||||
|
||||
val jvmTarget = configuration.get(JVMConfigurationKeys.JVM_TARGET, JvmTarget.DEFAULT)
|
||||
val languageVersionSettings = configuration.languageVersionSettings
|
||||
|
||||
val fallbackBuiltIns = JvmBuiltIns(storageManager, JvmBuiltIns.Kind.FALLBACK).apply {
|
||||
initialize(builtInsModule, languageVersionSettings)
|
||||
}.builtInsModule
|
||||
@@ -161,14 +163,14 @@ object TopDownAnalyzerFacadeForJVM {
|
||||
val dependencyModule = if (separateModules) {
|
||||
val dependenciesContext = ContextForNewModule(
|
||||
moduleContext, Name.special("<dependencies of ${configuration.getNotNull(CommonConfigurationKeys.MODULE_NAME)}>"),
|
||||
module.builtIns, null
|
||||
module.builtIns, jvmPlatform
|
||||
)
|
||||
|
||||
// Scope for the dependency module contains everything except files present in the scope for the source module
|
||||
val dependencyScope = GlobalSearchScope.notScope(sourceScope)
|
||||
|
||||
val dependenciesContainer = createContainerForLazyResolveWithJava(
|
||||
JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget),
|
||||
jvmPlatform,
|
||||
dependenciesContext, trace, DeclarationProviderFactory.EMPTY, dependencyScope, moduleClassResolver,
|
||||
targetEnvironment, lookupTracker, expectActualTracker,
|
||||
packagePartProvider(dependencyScope), languageVersionSettings,
|
||||
@@ -200,7 +202,7 @@ object TopDownAnalyzerFacadeForJVM {
|
||||
// to be stored in CliLightClassGenerationSupport, and it better be the source one (otherwise light classes would not be found)
|
||||
// TODO: get rid of duplicate invocation of CodeAnalyzerInitializer#initialize, or refactor CliLightClassGenerationSupport
|
||||
val container = createContainerForLazyResolveWithJava(
|
||||
JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget),
|
||||
jvmPlatform,
|
||||
moduleContext, trace, declarationProviderFactory(storageManager, files), sourceScope, moduleClassResolver,
|
||||
targetEnvironment, lookupTracker, expectActualTracker,
|
||||
partProvider, languageVersionSettings,
|
||||
@@ -275,11 +277,11 @@ object TopDownAnalyzerFacadeForJVM {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createModuleContext(project: Project, configuration: CompilerConfiguration): MutableModuleContext {
|
||||
private fun createModuleContext(project: Project, configuration: CompilerConfiguration, platform: TargetPlatform?): MutableModuleContext {
|
||||
val projectContext = ProjectContext(project, "TopDownAnalyzer for JVM")
|
||||
val builtIns = JvmBuiltIns(projectContext.storageManager, JvmBuiltIns.Kind.FROM_DEPENDENCIES)
|
||||
return ContextForNewModule(
|
||||
projectContext, Name.special("<${configuration.getNotNull(CommonConfigurationKeys.MODULE_NAME)}>"), builtIns, null
|
||||
projectContext, Name.special("<${configuration.getNotNull(CommonConfigurationKeys.MODULE_NAME)}>"), builtIns, platform
|
||||
).apply {
|
||||
builtIns.builtInsModule = module
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.js.facade.MainCallParameters
|
||||
import org.jetbrains.kotlin.js.facade.TranslationResult
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatformAnalyzerServices
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||
import org.jetbrains.kotlin.serialization.AbstractVersionRequirementTest
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
@@ -78,7 +79,7 @@ class JsVersionRequirementTest : AbstractVersionRequirementTest() {
|
||||
val config = JsConfig(environment.project, environment.configuration)
|
||||
return ContextForNewModule(
|
||||
ProjectContext(environment.project, "ProjectContext"),
|
||||
Name.special("<test>"), JsPlatformAnalyzerServices.builtIns, null
|
||||
Name.special("<test>"), JsPlatformAnalyzerServices.builtIns, JsPlatforms.defaultJsPlatform
|
||||
).apply {
|
||||
setDependencies(listOf(module) + config.moduleDescriptors + module.builtIns.builtInsModule)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.js.config.JsConfig
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatformAnalyzerServices
|
||||
import org.jetbrains.kotlin.js.resolve.MODULE_KIND
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||
@@ -67,7 +68,7 @@ object TopDownAnalyzerFacadeForJS {
|
||||
ProjectContext(project, "TopDownAnalyzer for JS"),
|
||||
Name.special("<$moduleName>"),
|
||||
builtIns,
|
||||
platform = null
|
||||
platform = JsPlatforms.defaultJsPlatform
|
||||
)
|
||||
|
||||
val additionalPackages = mutableListOf<PackageFragmentProvider>()
|
||||
|
||||
@@ -22,7 +22,9 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.platform
|
||||
import org.jetbrains.kotlin.resolve.extensions.SyntheticResolveExtension
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
|
||||
@@ -33,7 +35,7 @@ import java.util.*
|
||||
|
||||
open class SerializationResolveExtension : SyntheticResolveExtension {
|
||||
override fun getSyntheticNestedClassNames(thisDescriptor: ClassDescriptor): List<Name> = when {
|
||||
thisDescriptor.annotations.hasAnnotation(serialInfoFqName) -> listOf(SerialEntityNames.IMPL_NAME)
|
||||
thisDescriptor.annotations.hasAnnotation(serialInfoFqName) && thisDescriptor.platform?.isJvm() == true -> listOf(SerialEntityNames.IMPL_NAME)
|
||||
thisDescriptor.isInternalSerializable && !thisDescriptor.hasCompanionObjectAsSerializer ->
|
||||
listOf(SerialEntityNames.SERIALIZER_CLASS_NAME)
|
||||
else -> listOf()
|
||||
|
||||
Reference in New Issue
Block a user