diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPlatformConfigurator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPlatformConfigurator.kt index cf29654ef0d..58bd264db62 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPlatformConfigurator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanPlatformConfigurator.kt @@ -22,10 +22,7 @@ import org.jetbrains.kotlin.container.StorageComponentContainer import org.jetbrains.kotlin.container.useImpl import org.jetbrains.kotlin.container.useInstance import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap -import org.jetbrains.kotlin.resolve.IdentifierChecker -import org.jetbrains.kotlin.resolve.OverloadFilter -import org.jetbrains.kotlin.resolve.OverridesBackwardCompatibilityHelper -import org.jetbrains.kotlin.resolve.PlatformConfigurator +import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator import org.jetbrains.kotlin.resolve.lazy.DelegationFilter import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes @@ -39,11 +36,12 @@ object KonanPlatformConfigurator : PlatformConfigurator( additionalTypeCheckers = listOf(), additionalClassifierUsageCheckers = listOf(), additionalAnnotationCheckers = listOf(), - identifierChecker = IdentifierChecker.DEFAULT, - overloadFilter = OverloadFilter.DEFAULT, + identifierChecker = IdentifierChecker.Default, + overloadFilter = OverloadFilter.Default, platformToKotlinClassMap = PlatformToKotlinClassMap.EMPTY, - delegationFilter = DelegationFilter.DEFAULT, - overridesBackwardCompatibilityHelper = OverridesBackwardCompatibilityHelper.DEFAULT + delegationFilter = DelegationFilter.Default, + overridesBackwardCompatibilityHelper = OverridesBackwardCompatibilityHelper.Default, + declarationReturnTypeSanitizer = DeclarationReturnTypeSanitizer.Default ) { override fun configureModuleComponents(container: StorageComponentContainer) { container.useInstance(SyntheticScopes.Empty) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDescriptorSerializer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDescriptorSerializer.kt index 89ba7736706..9cd7076a544 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDescriptorSerializer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDescriptorSerializer.kt @@ -31,8 +31,13 @@ import org.jetbrains.kotlin.protobuf.MessageLite import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry import org.jetbrains.kotlin.resolve.MemberComparator +import org.jetbrains.kotlin.resolve.RequireKotlinNames +import org.jetbrains.kotlin.resolve.checkers.KotlinVersionStringAnnotationValueChecker +import org.jetbrains.kotlin.resolve.constants.EnumValue +import org.jetbrains.kotlin.resolve.constants.IntValue import org.jetbrains.kotlin.resolve.constants.NullValue -import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfo +import org.jetbrains.kotlin.resolve.constants.StringValue +import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirement import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.contains import org.jetbrains.kotlin.utils.Interner @@ -44,7 +49,7 @@ class KonanDescriptorSerializer private constructor( private val typeParameters: Interner, private val extension: SerializerExtension, private val typeTable: MutableTypeTable, - private val sinceKotlinInfoTable: MutableSinceKotlinInfoTable, + private val versionRequirementTable: MutableVersionRequirementTable, private val serializeTypeTableToFunction: Boolean ) { fun serialize(message: MessageLite): ByteArray { @@ -55,7 +60,7 @@ class KonanDescriptorSerializer private constructor( } fun createChildSerializer(descriptor: DeclarationDescriptor): KonanDescriptorSerializer = - KonanDescriptorSerializer(descriptor, Interner(typeParameters), extension, typeTable, sinceKotlinInfoTable, + KonanDescriptorSerializer(descriptor, Interner(typeParameters), extension, typeTable, versionRequirementTable, serializeTypeTableToFunction = false) val stringTable: StringTable @@ -137,9 +142,14 @@ class KonanDescriptorSerializer private constructor( builder.typeTable = typeTableProto } - val sinceKotlinInfoProto = sinceKotlinInfoTable.serialize() - if (sinceKotlinInfoProto != null) { - builder.sinceKotlinInfoTable = sinceKotlinInfoProto + val requirement = serializeVersionRequirement(classDescriptor) + if (requirement != null) { + builder.versionRequirement = requirement + } + + val versionRequirementTableProto = versionRequirementTable.serialize() + if (versionRequirementTableProto != null) { + builder.versionRequirementTable = versionRequirementTableProto } extension.serializeClass(classDescriptor, builder) @@ -221,10 +231,13 @@ class KonanDescriptorSerializer private constructor( } } - if (descriptor.isSuspendOrHasSuspendTypesInSignature()) { - builder.sinceKotlinInfo = writeSinceKotlinInfo(LanguageFeature.Coroutines) + val requirement = serializeVersionRequirement(descriptor) + if (requirement != null) { + builder.versionRequirement = requirement + } + else if (descriptor.isSuspendOrHasSuspendTypesInSignature()) { + builder.versionRequirement = writeVersionRequirement(LanguageFeature.Coroutines) } - extension.serializeProperty(descriptor, builder) if (extension is IrAwareExtension) { @@ -289,8 +302,12 @@ class KonanDescriptorSerializer private constructor( } } - if (descriptor.isSuspendOrHasSuspendTypesInSignature()) { - builder.sinceKotlinInfo = writeSinceKotlinInfo(LanguageFeature.Coroutines) + val requirement = serializeVersionRequirement(descriptor) + if (requirement != null) { + builder.versionRequirement = requirement + } + else if (descriptor.isSuspendOrHasSuspendTypesInSignature()) { + builder.versionRequirement = writeVersionRequirement(LanguageFeature.Coroutines) } extension.serializeFunction(descriptor, builder) @@ -317,8 +334,12 @@ class KonanDescriptorSerializer private constructor( builder.addValueParameter(local.valueParameter(valueParameterDescriptor)) } - if (descriptor.isSuspendOrHasSuspendTypesInSignature()) { - builder.sinceKotlinInfo = writeSinceKotlinInfo(LanguageFeature.Coroutines) + val requirement = serializeVersionRequirement(descriptor) + if (requirement != null) { + builder.versionRequirement = requirement + } + else if (descriptor.isSuspendOrHasSuspendTypesInSignature()) { + builder.versionRequirement = writeVersionRequirement(LanguageFeature.Coroutines) } extension.serializeConstructor(descriptor, builder) @@ -583,9 +604,9 @@ class KonanDescriptorSerializer private constructor( builder.typeTable = typeTableProto } - val sinceKotlinInfoProto = sinceKotlinInfoTable.serialize() - if (sinceKotlinInfoProto != null) { - builder.sinceKotlinInfoTable = sinceKotlinInfoProto + val versionRequirementTableProto = versionRequirementTable.serialize() + if (versionRequirementTableProto != null) { + builder.versionRequirementTable = versionRequirementTableProto } extension.serializePackage(packageFqName, builder) @@ -593,15 +614,62 @@ class KonanDescriptorSerializer private constructor( return builder } - private fun writeSinceKotlinInfo(languageFeature: LanguageFeature): Int { + private fun writeVersionRequirement(languageFeature: LanguageFeature): Int { val languageVersion = languageFeature.sinceVersion!! - val sinceKotlinInfo = ProtoBuf.SinceKotlinInfo.newBuilder().apply { - SinceKotlinInfo.Version(languageVersion.major, languageVersion.minor).encode( + val requirement = ProtoBuf.VersionRequirement.newBuilder().apply { + VersionRequirement.Version(languageVersion.major, languageVersion.minor).encode( writeVersion = { version = it }, writeVersionFull = { versionFull = it } ) } - return sinceKotlinInfoTable[sinceKotlinInfo] + return versionRequirementTable[requirement] + } + + // Returns index into versionRequirementTable, or null if there's no @RequireKotlin on the descriptor + private fun serializeVersionRequirement(descriptor: DeclarationDescriptor): Int? { + val annotation = descriptor.annotations.findAnnotation(RequireKotlinNames.FQ_NAME) ?: return null + val args = annotation.allValueArguments + + val versionString = (args[RequireKotlinNames.VERSION] as? StringValue)?.value ?: return null + val matchResult = KotlinVersionStringAnnotationValueChecker.VERSION_REGEX.matchEntire(versionString) ?: return null + + val major = matchResult.groupValues.getOrNull(1)?.toIntOrNull() ?: return null + val minor = matchResult.groupValues.getOrNull(2)?.toIntOrNull() ?: 0 + val patch = matchResult.groupValues.getOrNull(4)?.toIntOrNull() ?: 0 + + val proto = ProtoBuf.VersionRequirement.newBuilder() + VersionRequirement.Version(major, minor, patch).encode( + writeVersion = { proto.version = it }, + writeVersionFull = { proto.versionFull = it } + ) + + val message = (args[RequireKotlinNames.MESSAGE] as? StringValue)?.value + if (message != null) { + proto.message = stringTable.getStringIndex(message) + } + + val level = (args[RequireKotlinNames.LEVEL] as? EnumValue)?.value?.name?.asString() + when (level) { + DeprecationLevel.ERROR.toString() -> { /* ERROR is the default level */ } + DeprecationLevel.WARNING.toString() -> proto.level = ProtoBuf.VersionRequirement.Level.WARNING + DeprecationLevel.HIDDEN.toString() -> proto.level = ProtoBuf.VersionRequirement.Level.HIDDEN + } + + val versionKind = (args[RequireKotlinNames.VERSION_KIND] as? EnumValue)?.value?.name?.asString() + when (versionKind) { + ProtoBuf.VersionRequirement.VersionKind.LANGUAGE_VERSION.toString() -> { /* LANGUAGE_VERSION is the default kind */ } + ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION.toString() -> + proto.versionKind = ProtoBuf.VersionRequirement.VersionKind.COMPILER_VERSION + ProtoBuf.VersionRequirement.VersionKind.API_VERSION.toString() -> + proto.versionKind = ProtoBuf.VersionRequirement.VersionKind.API_VERSION + } + + val errorCode = (args[RequireKotlinNames.ERROR_CODE] as? IntValue)?.value + if (errorCode != null && errorCode != -1) { + proto.errorCode = errorCode + } + + return versionRequirementTable[proto] } private fun getClassifierId(descriptor: ClassifierDescriptorWithTypeParameters): Int = @@ -616,13 +684,13 @@ class KonanDescriptorSerializer private constructor( companion object { @JvmStatic fun createTopLevel(extension: SerializerExtension): KonanDescriptorSerializer { - return KonanDescriptorSerializer(null, Interner(), extension, MutableTypeTable(), MutableSinceKotlinInfoTable(), + return KonanDescriptorSerializer(null, Interner(), extension, MutableTypeTable(), MutableVersionRequirementTable(), serializeTypeTableToFunction = false) } @JvmStatic fun createForLambda(extension: SerializerExtension): KonanDescriptorSerializer { - return KonanDescriptorSerializer(null, Interner(), extension, MutableTypeTable(), MutableSinceKotlinInfoTable(), + return KonanDescriptorSerializer(null, Interner(), extension, MutableTypeTable(), MutableVersionRequirementTable(), serializeTypeTableToFunction = true) } @@ -642,7 +710,7 @@ class KonanDescriptorSerializer private constructor( Interner(parentSerializer.typeParameters), parentSerializer.extension, MutableTypeTable(), - MutableSinceKotlinInfoTable(), + MutableVersionRequirementTable(), serializeTypeTableToFunction = false ) for (typeParameter in descriptor.declaredTypeParameters) { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializationUtil.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializationUtil.kt index 300d239dc2e..d75ff52c7e0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializationUtil.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanSerializationUtil.kt @@ -105,7 +105,7 @@ fun createKonanPackageFragmentProvider( LocalClassifierTypeSettings.Default, ErrorReporter.DO_NOTHING, LookupTracker.DO_NOTHING, NullFlexibleTypeDeserializer, - emptyList(), notFoundClasses) + emptyList(), notFoundClasses, ContractDeserializer.DEFAULT) for (packageFragment in packageFragments) { packageFragment.components = components diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt index 1eaba7c6054..2b82f8fb827 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/LocalDeclarationDeserializer.kt @@ -16,6 +16,9 @@ package org.jetbrains.kotlin.backend.konan.serialization +import org.jetbrains.kotlin.backend.common.peek +import org.jetbrains.kotlin.backend.common.pop +import org.jetbrains.kotlin.backend.common.push import org.jetbrains.kotlin.backend.konan.descriptors.allContainingDeclarations import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor @@ -23,14 +26,10 @@ import org.jetbrains.kotlin.serialization.Flags import org.jetbrains.kotlin.serialization.KonanIr import org.jetbrains.kotlin.serialization.KonanLinkData import org.jetbrains.kotlin.serialization.ProtoBuf -import org.jetbrains.kotlin.serialization.ProtoBuf.QualifiedNameTable.QualifiedName import org.jetbrains.kotlin.serialization.deserialization.* -import org.jetbrains.kotlin.serialization.deserialization.descriptors.* -import org.jetbrains.kotlin.serialization.deserialization.descriptors.SinceKotlinInfoTable +import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor +import org.jetbrains.kotlin.serialization.deserialization.descriptors.VersionRequirementTable import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.backend.common.peek -import org.jetbrains.kotlin.backend.common.push -import org.jetbrains.kotlin.backend.common.pop // This class knows how to construct contexts for // MemberDeserializer to deserialize descriptors declared in IR. @@ -75,7 +74,7 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) { if (descriptor is KonanPackageFragment) { val packageTypeTable = TypeTable(pkg.proto.getPackage().typeTable) return components.createContext( - pkg, nameResolver, packageTypeTable, SinceKotlinInfoTable.EMPTY, null) + pkg, nameResolver, packageTypeTable, VersionRequirementTable.EMPTY, null) } // Only packages and classes have their type tables. diff --git a/dependencies/upload.gradle b/dependencies/upload.gradle index 5a66c43fc97..fd902da0ce6 100644 --- a/dependencies/upload.gradle +++ b/dependencies/upload.gradle @@ -65,7 +65,7 @@ bintray { def (groupId, artifactId, version) = gradle.startParameter.projectProperties.module.tokenize(':') def groupPath = groupId.replace('.', '/') def artifactPath = artifactId - def versionPath = "${version.tokenize('-')[0]}-SNAPSHOT" + def versionPath = "$version" //TODO: snapshots? from project.files(gradle.startParameter.projectProperties.jar) from project.files(gradle.startParameter.projectProperties.src) from project.files(gradle.startParameter.projectProperties.doc) diff --git a/gradle.properties b/gradle.properties index 287b0f19e1f..aba50f615db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,14 +23,14 @@ testDataVersion=1067176:id kotlinCompilerRepo=https://dl.bintray.com/jetbrains/kotlin-native-dependencies #kotlinCompilerRepo=http://oss.sonatype.org/content/repositories/snapshots #kotlinCompilerRepo=http://dl.bintray.com/kotlin/kotlin-dev -kotlinVersion=1.1-20171004.235336-906 -kotlinScriptRuntimeVersion=1.1-20171004.235353-597 -kotlinStdLibVersion=1.1-20171004.235357-905 -kotlinReflectVersion=1.1-20171004.235348-905 +kotlinVersion=1.2.0-rc-39 +kotlinScriptRuntimeVersion=1.2.0-rc-39 +kotlinStdLibVersion=1.2.0-rc-39 +kotlinReflectVersion=1.2.0-rc-39 konanVersion=0.4 org.gradle.jvmargs='-Dfile.encoding=UTF-8' ## # required for performance mesuarement tasks -kotlinStdLibJdk8Version=1.1-20171004.235402-815 -kotlinGradlePluginVersion=1.1-20171004.235345-884 +kotlinStdLibJdk8Version=1.2.0-rc-39 +kotlinGradlePluginVersion=1.2.0-rc-39 diff --git a/tools/kotlin-native-gradle-plugin/build.gradle b/tools/kotlin-native-gradle-plugin/build.gradle index f64ee14ae1b..b53c7f32e79 100644 --- a/tools/kotlin-native-gradle-plugin/build.gradle +++ b/tools/kotlin-native-gradle-plugin/build.gradle @@ -39,25 +39,6 @@ apply plugin: 'com.jfrog.bintray' group = 'org.jetbrains.kotlin' version = konanVersion -// TODO: move this code to top level (the same for backend.native) -// Copied from backend.native -allprojects { - repositories { - maven { url kotlinCompilerRepo } - } - - configurations.all { - // kotlin-compiler module includes Kotlin runtime bundled; - // make Gradle aware of this to avoid multiple Kotlin runtimes in classpath: - resolutionStrategy.dependencySubstitution { - substitute module('org.jetbrains.kotlin:kotlin-runtime') with module(kotlinCompilerModule) - substitute module('org.jetbrains.kotlin:kotlin-stdlib') with module(kotlinStdLibModule) - substitute module('org.jetbrains.kotlin:kotlin-reflect') with module(kotlinReflectModule) - } - // TODO: probably we should use kotlin-compiler without bundled runtime - } -} - repositories { mavenCentral() }