Move KonanBuiltIns to a separate module (#1860)
1. Separate (temporary) modules for the code to be moved to https://github.com/JetBrains/kotlin repo 2. KonanBuiltIns, functions for creation of module descriptors and interop descriptors and moved to "konan.descriptors" module 3. Re-organizing KonanModuleOrigin and it's inheritors to better naming/understanding
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
buildscript {
|
||||
ext.rootBuildDirectory = file('../..')
|
||||
|
||||
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
|
||||
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
group = 'org.jetbrains.kotlin'
|
||||
version = konanVersion
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url kotlinCompilerRepo
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.kotlin {
|
||||
srcDir 'src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveName = "${project.name}.jar"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion"
|
||||
compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
||||
compile "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name = "konan.descriptors"
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package org.jetbrains.kotlin.builtins.konan
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
class KonanBuiltIns(storageManager: StorageManager) : KotlinBuiltIns(storageManager) {
|
||||
|
||||
override fun getSuspendFunction(parameterCount: Int) =
|
||||
getBuiltInClassByName(Name.identifier("SuspendFunction$parameterCount"))
|
||||
}
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.jetbrains.kotlin.descriptors.konan
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
fun createKonanModuleDescriptor(
|
||||
name: Name,
|
||||
storageManager: StorageManager,
|
||||
origin: KonanModuleOrigin
|
||||
): ModuleDescriptorImpl {
|
||||
val builtIns = KonanBuiltIns(storageManager)
|
||||
|
||||
val moduleDescriptor = createKonanModuleDescriptor(name, storageManager, builtIns, origin)
|
||||
|
||||
builtIns.builtInsModule = moduleDescriptor
|
||||
// It is mostly correct because any module should depend on stdlib.
|
||||
|
||||
return moduleDescriptor
|
||||
}
|
||||
|
||||
fun createKonanModuleDescriptor(
|
||||
name: Name,
|
||||
storageManager: StorageManager,
|
||||
builtIns: KotlinBuiltIns,
|
||||
origin: KonanModuleOrigin
|
||||
) = ModuleDescriptorImpl(
|
||||
name, storageManager, builtIns,
|
||||
capabilities = mapOf(KonanModuleOrigin.CAPABILITY to origin)
|
||||
)
|
||||
|
||||
private val STDLIB_MODULE_NAME = Name.special("<stdlib>")
|
||||
|
||||
fun ModuleDescriptor.isKonanStdlib() = name == STDLIB_MODULE_NAME
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package org.jetbrains.kotlin.descriptors.konan
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
|
||||
sealed class KonanModuleOrigin {
|
||||
|
||||
companion object {
|
||||
val CAPABILITY = ModuleDescriptor.Capability<KonanModuleOrigin>("KonanModuleOrigin")
|
||||
}
|
||||
}
|
||||
|
||||
sealed class CompiledKonanModuleOrigin: KonanModuleOrigin()
|
||||
|
||||
// FIXME: ddol: replace `Any` by `KonanLibraryReader` when ready
|
||||
class DeserializedKonanModuleOrigin(val reader: Any) : CompiledKonanModuleOrigin()
|
||||
|
||||
object CurrentKonanModuleOrigin: CompiledKonanModuleOrigin()
|
||||
|
||||
object SyntheticModulesOrigin : KonanModuleOrigin()
|
||||
|
||||
val ModuleDescriptor.konanModuleOrigin get() = this.getCapability(KonanModuleOrigin.CAPABILITY)!!
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package org.jetbrains.kotlin.descriptors.konan.interop
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.konan.SyntheticModulesOrigin
|
||||
import org.jetbrains.kotlin.descriptors.konan.createKonanModuleDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
/**
|
||||
* Creates module which "contains" forward declarations.
|
||||
* Note: this module should be unique per compilation and should always be the last dependency of any module.
|
||||
*/
|
||||
fun createForwardDeclarationsModule(builtIns: KotlinBuiltIns, storageManager: StorageManager): ModuleDescriptorImpl {
|
||||
val module = createKonanModuleDescriptor(
|
||||
Name.special("<forward declarations>"),
|
||||
storageManager,
|
||||
builtIns,
|
||||
origin = SyntheticModulesOrigin
|
||||
)
|
||||
|
||||
fun createPackage(fqName: FqName, supertypeName: String, classKind: ClassKind = ClassKind.CLASS) =
|
||||
ForwardDeclarationsPackageFragmentDescriptor(
|
||||
storageManager,
|
||||
module,
|
||||
fqName,
|
||||
Name.identifier(supertypeName),
|
||||
classKind
|
||||
)
|
||||
|
||||
val packageFragmentProvider = PackageFragmentProviderImpl(
|
||||
listOf(
|
||||
createPackage(InteropFqNames.cNamesStructs, "COpaque"),
|
||||
createPackage(InteropFqNames.objCNamesClasses, "ObjCObjectBase"),
|
||||
createPackage(InteropFqNames.objCNamesProtocols, "ObjCObject", ClassKind.INTERFACE)
|
||||
)
|
||||
)
|
||||
|
||||
module.initialize(packageFragmentProvider)
|
||||
module.setDependencies(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
||||
/**
|
||||
* Package fragment which creates descriptors for forward declarations on demand.
|
||||
*/
|
||||
private class ForwardDeclarationsPackageFragmentDescriptor(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor, fqName: FqName, supertypeName: Name, classKind: ClassKind
|
||||
) : PackageFragmentDescriptorImpl(module, fqName) {
|
||||
|
||||
private val memberScope = object : MemberScopeImpl() {
|
||||
|
||||
private val declarations = storageManager.createMemoizedFunction(this::createDeclaration)
|
||||
|
||||
private val supertype by storageManager.createLazyValue {
|
||||
val descriptor = builtIns.builtInsModule.getPackage(InteropFqNames.packageName)
|
||||
.memberScope
|
||||
.getContributedClassifier(supertypeName, NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
||||
|
||||
descriptor.defaultType
|
||||
}
|
||||
|
||||
private fun createDeclaration(name: Name): ClassDescriptor {
|
||||
return ClassDescriptorImpl(
|
||||
this@ForwardDeclarationsPackageFragmentDescriptor,
|
||||
name, Modality.FINAL, classKind,
|
||||
listOf(supertype), SourceElement.NO_SOURCE, false, LockBasedStorageManager.NO_LOCKS
|
||||
).apply {
|
||||
this.initialize(MemberScope.Empty, emptySet(), null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation) = declarations(name)
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(this::class.java.simpleName, "{}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMemberScope(): MemberScope = memberScope
|
||||
}
|
||||
|
||||
object InteropFqNames {
|
||||
|
||||
const val cPointerName = "CPointer"
|
||||
const val nativePointedName = "NativePointed"
|
||||
|
||||
val packageName = FqName("kotlinx.cinterop")
|
||||
|
||||
val cPointer = packageName.child(Name.identifier(cPointerName)).toUnsafe()
|
||||
val nativePointed = packageName.child(Name.identifier(nativePointedName)).toUnsafe()
|
||||
|
||||
val cNames = FqName("cnames")
|
||||
val cNamesStructs = cNames.child(Name.identifier("structs"))
|
||||
|
||||
val objCNames = FqName("objcnames")
|
||||
val objCNamesClasses = objCNames.child(Name.identifier("classes"))
|
||||
val objCNamesProtocols = objCNames.child(Name.identifier("protocols"))
|
||||
}
|
||||
+17
@@ -0,0 +1,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.storage.StorageManager
|
||||
|
||||
object KonanPlatform : TargetPlatform("Konan") {
|
||||
|
||||
override fun computePlatformSpecificDefaultImports(storageManager: StorageManager, result: MutableList<ImportPath>) {
|
||||
result.add(ImportPath.fromString("konan.*"))
|
||||
}
|
||||
|
||||
override val multiTargetPlatform = MultiTargetPlatform.Specific(platformName)
|
||||
override val platformConfigurator: PlatformConfigurator = KonanPlatformConfigurator
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package org.jetbrains.kotlin.resolve.konan.platform
|
||||
|
||||
import org.jetbrains.kotlin.builtins.PlatformToKotlinClassMap
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.useInstance
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.ReifiedTypeParameterSubstitutionChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.components.SamConversionTransformer
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.types.DynamicTypesSettings
|
||||
|
||||
object KonanPlatformConfigurator : PlatformConfigurator(
|
||||
DynamicTypesSettings(),
|
||||
additionalDeclarationCheckers = listOf(ExpectedActualDeclarationChecker),
|
||||
additionalCallCheckers = listOf(
|
||||
org.jetbrains.kotlin.resolve.jvm.checkers.SuperCallWithDefaultArgumentsChecker(),
|
||||
ReifiedTypeParameterSubstitutionChecker()
|
||||
),
|
||||
additionalTypeCheckers = listOf(),
|
||||
additionalClassifierUsageCheckers = listOf(),
|
||||
additionalAnnotationCheckers = listOf(),
|
||||
identifierChecker = IdentifierChecker.Default,
|
||||
overloadFilter = OverloadFilter.Default,
|
||||
platformToKotlinClassMap = PlatformToKotlinClassMap.EMPTY,
|
||||
delegationFilter = DelegationFilter.Default,
|
||||
overridesBackwardCompatibilityHelper = OverridesBackwardCompatibilityHelper.Default,
|
||||
declarationReturnTypeSanitizer = DeclarationReturnTypeSanitizer.Default
|
||||
) {
|
||||
override fun configureModuleComponents(container: StorageComponentContainer) {
|
||||
container.useInstance(SyntheticScopes.Empty)
|
||||
container.useInstance(TypeSpecificityComparator.NONE)
|
||||
container.useInstance(SamConversionTransformer.Empty)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
buildscript {
|
||||
ext.rootBuildDirectory = file('../..')
|
||||
|
||||
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
|
||||
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
group = 'org.jetbrains.kotlin'
|
||||
version = konanVersion
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url kotlinCompilerRepo
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.kotlin {
|
||||
srcDir 'src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveName = "${project.name}.jar"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:konan.descriptors:$konanVersion"
|
||||
compile "org.jetbrains.kotlin:konan.metadata:$konanVersion"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name = "konan.metadata.serializer"
|
||||
@@ -0,0 +1,34 @@
|
||||
buildscript {
|
||||
ext.rootBuildDirectory = file('../..')
|
||||
|
||||
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
|
||||
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
group = 'org.jetbrains.kotlin'
|
||||
version = konanVersion
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url kotlinCompilerRepo
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.kotlin {
|
||||
srcDir 'src/main/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveName = "${project.name}.jar"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion"
|
||||
compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
||||
compile "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name = "konan.metadata"
|
||||
Reference in New Issue
Block a user