KT-53154 extract implementation of enumEntries into an expect/actual internal helper function

It's required, so it can be implemented in different backends
at a different pace and in a different manner
This commit is contained in:
Ilya Gorbunov
2023-07-14 05:29:02 +02:00
committed by Space Team
parent 40a6c81d97
commit 61175889b9
6 changed files with 88 additions and 11 deletions
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2023 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.enums
@SinceKotlin("1.9")
@ExperimentalStdlibApi
@PublishedApi
internal actual inline fun <reified T : Enum<T>> enumEntriesIntrinsic(): EnumEntries<T> {
/*
* Implementation note: this body will be replaced with `throw NotImplementedException()` the moment
* all backends starts intrinsifying this call.
*/
return enumEntries(enumValues<T>())
}
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2023 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.enums
@SinceKotlin("1.9")
@ExperimentalStdlibApi
@PublishedApi
internal actual inline fun <reified T : Enum<T>> enumEntriesIntrinsic(): EnumEntries<T> {
/*
* Implementation note: this body will be replaced with `throw NotImplementedException()` the moment
* all backends starts intrinsifying this call.
*/
return enumEntries(enumValues<T>())
}
@@ -39,7 +39,8 @@ val copySources by task<Sync> {
"kotlin/text/TypeAliases.kt")
from(stdlibProjectDir.resolve("src"))
.include("kotlin/collections/TypeAliases.kt",
"kotlin/enums/EnumEntriesSerializationProxy.kt")
"kotlin/enums/EnumEntriesSerializationProxy.kt",
"kotlin/enums/EnumEntriesJVM.kt")
from(stdlibProjectDir.resolve("../src"))
.include("kotlin/util/Standard.kt",
"kotlin/internal/Annotations.kt",
@@ -52,8 +53,13 @@ val copySources by task<Sync> {
into(File(buildDir, "src"))
}
tasks.withType<KotlinCompile> {
tasks.compileKotlin {
dependsOn(copySources)
val commonSources = listOf(
"kotlin/enums/EnumEntries.kt"
).map { copySources.get().destinationDir.resolve(it) }
kotlinOptions {
freeCompilerArgs += listOf(
"-Xallow-kotlin-package",
@@ -63,6 +69,11 @@ tasks.withType<KotlinCompile> {
)
moduleName = "kotlin-stdlib"
}
doFirst {
kotlinOptions.freeCompilerArgs += listOf(
"-Xcommon-sources=${commonSources.joinToString(File.pathSeparator)}",
)
}
}
val jar = runtimeJar {
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2023 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.enums
@SinceKotlin("1.9")
@ExperimentalStdlibApi
@PublishedApi
internal actual inline fun <reified T : Enum<T>> enumEntriesIntrinsic(): EnumEntries<T> {
/*
* Implementation note: this body will be replaced with `throw NotImplementedException()` the moment
* all backends starts intrinsifying this call.
*/
return enumEntries(enumValues<T>())
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 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.
*/
@@ -29,14 +29,12 @@ public sealed interface EnumEntries<E : Enum<E>> : List<E>
@PublishedApi
@ExperimentalStdlibApi
@SinceKotlin("1.9")
internal inline fun <reified T : Enum<T>> enumEntries(): EnumEntries<T> {
/*
* Implementation note: this body will be replaced with `throw NotImplementedException()` the moment
* all backends starts intrinsifying this call.
* Then this method will also be promoted to public.
*/
return enumEntries(enumValues<T>())
}
internal inline fun <reified T : Enum<T>> enumEntries(): EnumEntries<T> = enumEntriesIntrinsic()
@PublishedApi
@ExperimentalStdlibApi
@SinceKotlin("1.9")
internal expect inline fun <reified T : Enum<T>> enumEntriesIntrinsic(): EnumEntries<T>
@PublishedApi
@SinceKotlin("1.8") // Used by pre-1.9.0 JVM compiler for the feature in preview mode. Can be safely removed around 2.1
@@ -0,0 +1,17 @@
/*
* Copyright 2010-2023 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.enums
@SinceKotlin("1.9")
@ExperimentalStdlibApi
@PublishedApi
internal actual inline fun <reified T : Enum<T>> enumEntriesIntrinsic(): EnumEntries<T> {
/*
* Implementation note: this body will be replaced with `throw NotImplementedException()` the moment
* all backends starts intrinsifying this call.
*/
return enumEntries(enumValues<T>())
}