diff --git a/compiler/ir/serialization.js/build.gradle.kts b/compiler/ir/serialization.js/build.gradle.kts index 20f298511a7..f9b50e3bbe6 100644 --- a/compiler/ir/serialization.js/build.gradle.kts +++ b/compiler/ir/serialization.js/build.gradle.kts @@ -56,18 +56,8 @@ val fullRuntimeSources by task { // stdlib/js/src/generated is used exclusively for current `js-v1` backend. "libraries/stdlib/js/src/generated/**", - "libraries/stdlib/common/src/kotlin/JvmAnnotationsH.kt", - "libraries/stdlib/src/kotlin/annotations/Multiplatform.kt", - "libraries/stdlib/common/src/kotlin/NativeAnnotationsH.kt", - - // Fails with: EXPERIMENTAL_IS_NOT_ENABLED - "libraries/stdlib/common/src/kotlin/annotations/Annotations.kt", - // JS-specific optimized version of emptyArray() already defined - "core/builtins/src/kotlin/ArrayIntrinsics.kt", - - // Expect declarations get thrown away and libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt doesn't compile - "libraries/stdlib/common/src/kotlin/NativeAnnotationsH.kt" + "core/builtins/src/kotlin/ArrayIntrinsics.kt" ) sources.forEach { path -> @@ -152,14 +142,14 @@ val reducedRuntimeSources by task { } -fun JavaExec.buildKLib(sources: List, dependencies: List, outPath: String) { +fun JavaExec.buildKLib(sources: List, dependencies: List, outPath: String, commonSources: List) { inputs.files(sources) outputs.dir(file(outPath).parent) classpath = sourceSets.test.get().runtimeClasspath main = "org.jetbrains.kotlin.ir.backend.js.GenerateIrRuntimeKt" workingDir = rootDir - args = sources.toList() + listOf("-o", outPath) + dependencies.flatMap { listOf("-d", it) } + args = sources.toList() + listOf("-o", outPath) + dependencies.flatMap { listOf("-d", it) } + commonSources.flatMap { listOf("-c", it) } passClasspathInJar() } @@ -169,7 +159,9 @@ val generateFullRuntimeKLib by task { buildKLib(sources = listOf(fullRuntimeSources.outputs.files.singleFile.path), dependencies = emptyList(), - outPath = "$buildDir/fullRuntime/klib/JS_IR_RUNTIME.klm") + outPath = "$buildDir/fullRuntime/klib/JS_IR_RUNTIME.klm", + commonSources = listOf("common", "src", "unsigned").map { "$buildDir/fullRuntime/src/libraries/stdlib/$it" } + ) } val generateReducedRuntimeKLib by task { @@ -177,20 +169,23 @@ val generateReducedRuntimeKLib by task { buildKLib(sources = listOf(reducedRuntimeSources.outputs.files.singleFile.path), dependencies = emptyList(), - outPath = "$buildDir/reducedRuntime/klib/JS_IR_RUNTIME.klm") + outPath = "$buildDir/reducedRuntime/klib/JS_IR_RUNTIME.klm", + commonSources = listOf("common", "src", "unsigned").map { "$buildDir/reducedRuntime/src/libraries/stdlib/$it" } + ) } +val kotlinTestCommonSources = listOf( + "$rootDir/libraries/kotlin.test/annotations-common/src/main", + "$rootDir/libraries/kotlin.test/common/src/main" +) val generateKotlinTestKLib by task { dependsOn(generateFullRuntimeKLib) buildKLib( - sources = listOf( - "$rootDir/libraries/kotlin.test/annotations-common/src/main", - "$rootDir/libraries/kotlin.test/common/src/main", - "$rootDir/libraries/kotlin.test/js/src/main" - ), + sources = listOf("$rootDir/libraries/kotlin.test/js/src/main") + kotlinTestCommonSources, dependencies = listOf("${generateFullRuntimeKLib.outputs.files.singleFile.path}/JS_IR_RUNTIME.klm"), - outPath = "$buildDir/kotlin.test/klib/kotlin.test.klm" + outPath = "$buildDir/kotlin.test/klib/kotlin.test.klm", + commonSources = kotlinTestCommonSources ) } diff --git a/compiler/ir/serialization.js/test/GenerateIrRuntime.kt b/compiler/ir/serialization.js/test/GenerateIrRuntime.kt index ce82d79e05c..f2b92b0c155 100644 --- a/compiler/ir/serialization.js/test/GenerateIrRuntime.kt +++ b/compiler/ir/serialization.js/test/GenerateIrRuntime.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.resolve.multiplatform.isCommonSource import org.jetbrains.kotlin.serialization.js.ModuleKind import java.io.File @@ -29,7 +30,11 @@ fun buildConfiguration(environment: KotlinCoreEnvironment, moduleName: String): LanguageFeature.MultiPlatformProjects to LanguageFeature.State.ENABLED ), analysisFlags = mapOf( - AnalysisFlags.useExperimental to listOf("kotlin.contracts.ExperimentalContracts", "kotlin.Experimental"), + AnalysisFlags.useExperimental to listOf( + "kotlin.contracts.ExperimentalContracts", + "kotlin.Experimental", + "kotlin.ExperimentalMultiplatform" + ), AnalysisFlags.allowResultReturnType to true ) ) @@ -49,10 +54,22 @@ fun createPsiFile(fileName: String): KtFile { } -fun buildKLib(moduleName: String, sources: List, outputPath: String, dependencies: List): KlibModuleRef { +fun buildKLib( + moduleName: String, + sources: List, + outputPath: String, + dependencies: List, + commonSources: List +): KlibModuleRef { return generateKLib( project = environment.project, - files = sources.map(::createPsiFile), + files = sources.map { source -> + val file = createPsiFile(source) + if (source in commonSources) { + file.isCommonSource = true + } + file + }, configuration = buildConfiguration(environment, moduleName), immediateDependencies = dependencies, allDependencies = dependencies, @@ -76,6 +93,7 @@ fun main(args: Array) { val inputFiles = mutableListOf() var outputPath: String? = null val dependencies = mutableListOf() + val commonSources = mutableListOf() var index = 0 while (index < args.size) { @@ -84,6 +102,7 @@ fun main(args: Array) { when (arg) { "-o" -> outputPath = args[index++] "-d" -> dependencies += args[index++] + "-c" -> commonSources += args[index++] else -> inputFiles += arg } } @@ -101,5 +120,5 @@ fun main(args: Array) { KlibModuleRef(file.name.dropLast(4), file.parent) } - buildKLib(name.dropLast(4), listOfKtFilesFrom(inputFiles), File(outputPath).parent, dependencyKLibs) + buildKLib(name.dropLast(4), listOfKtFilesFrom(inputFiles), File(outputPath).parent, dependencyKLibs, listOfKtFilesFrom(commonSources)) } diff --git a/compiler/testData/codegen/box/multiplatform/optionalExpectation.kt b/compiler/testData/codegen/box/multiplatform/optionalExpectation.kt index bff1124353c..91d1f7864b7 100644 --- a/compiler/testData/codegen/box/multiplatform/optionalExpectation.kt +++ b/compiler/testData/codegen/box/multiplatform/optionalExpectation.kt @@ -1,7 +1,6 @@ // !LANGUAGE: +MultiPlatformProjects // !USE_EXPERIMENTAL: kotlin.ExperimentalMultiplatform // IGNORE_BACKEND: NATIVE -// IGNORE_BACKEND: JS_IR // WITH_RUNTIME // MODULE: library // FILE: expected.kt diff --git a/libraries/stdlib/js-ir/runtime/irTestsJvmAnnotations.kt b/libraries/stdlib/js-ir/runtime/irTestsJvmAnnotations.kt deleted file mode 100644 index b3fc361ff83..00000000000 --- a/libraries/stdlib/js-ir/runtime/irTestsJvmAnnotations.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package kotlin.jvm - -import kotlin.annotation.AnnotationTarget.* - -@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR) -@Retention(AnnotationRetention.SOURCE) -internal annotation class JvmOverloads - -@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, AnnotationTarget.FILE) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -internal annotation class JvmName(public val name: String) - -@Target(AnnotationTarget.FILE) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -internal annotation class JvmMultifileClass - -@Target(AnnotationTarget.FILE) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -internal annotation class JvmPackageName(val name: String) - -@Target(AnnotationTarget.FIELD) -@Retention(AnnotationRetention.SOURCE) -@MustBeDocumented -internal annotation class JvmField - - -@Target(FIELD) -@MustBeDocumented -@OptionalExpectation -public expect annotation class Volatile() - -@Target(FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER) -@MustBeDocumented -@OptionalExpectation -public expect annotation class Synchronized() \ No newline at end of file diff --git a/libraries/stdlib/js-ir/runtime/irTestsOptionalExpectation.kt b/libraries/stdlib/js-ir/runtime/irTestsOptionalExpectation.kt deleted file mode 100644 index 393f6c501b1..00000000000 --- a/libraries/stdlib/js-ir/runtime/irTestsOptionalExpectation.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kotlin - - -annotation class OptionalExpectationDummy() - -// in order to make the compiler ignore semantics of the real OptionalExpectation -typealias OptionalExpectation = OptionalExpectationDummy \ No newline at end of file diff --git a/libraries/stdlib/js-ir/runtime/kotlinNativeHacks.kt b/libraries/stdlib/js-ir/runtime/kotlinNativeHacks.kt deleted file mode 100644 index 9d26467367b..00000000000 --- a/libraries/stdlib/js-ir/runtime/kotlinNativeHacks.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package kotlin.native.concurrent - -// Current serialization removes expect declarations, so some dummy annotations are needed -// Expect declarations: libraries/stdlib/common/src/kotlin/NativeAnnotationsH.kt - -@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -@Retention(AnnotationRetention.BINARY) -@OptionalExpectation -public annotation class ThreadLocal() - -@Target(AnnotationTarget.PROPERTY) -@Retention(AnnotationRetention.BINARY) -@OptionalExpectation -public annotation class SharedImmutable()