From 0faa83bacb8e6cf157dd779fbff8cb582485a135 Mon Sep 17 00:00:00 2001 From: Abduqodiri Qurbonzoda Date: Wed, 1 Sep 2021 11:27:43 +0300 Subject: [PATCH] Deprecate JS Array/PrimitiveArray.sort(comparison) functions --- .../stdlib/api/js-v1/kotlin.collections.kt | 16 ++++++++++++++++ libraries/stdlib/api/js/kotlin.collections.kt | 16 ++++++++++++++++ .../stdlib/js-ir/src/generated/_ArraysJs.kt | 17 +++++++++++++++++ libraries/stdlib/js/src/generated/_ArraysJs.kt | 17 +++++++++++++++++ .../kotlin-stdlib-gen/src/templates/Arrays.kt | 9 ++++++++- 5 files changed, 74 insertions(+), 1 deletion(-) diff --git a/libraries/stdlib/api/js-v1/kotlin.collections.kt b/libraries/stdlib/api/js-v1/kotlin.collections.kt index fdb99c17447..290c2e4c4dc 100644 --- a/libraries/stdlib/api/js-v1/kotlin.collections.kt +++ b/libraries/stdlib/api/js-v1/kotlin.collections.kt @@ -8341,6 +8341,8 @@ public fun kotlin.UShortArray.sliceArray(indices: kotlin.ranges.IntRange): kotli public fun > kotlin.Array.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use sortWith instead", replaceWith = kotlin.ReplaceWith(expression = "this.sortWith(Comparator(comparison))", imports = {})) +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") public fun kotlin.Array.sort(comparison: (a: T, b: T) -> kotlin.Int): kotlin.Unit @kotlin.SinceKotlin(version = "1.4") @@ -8349,6 +8351,8 @@ public fun > kotlin.Array.sort(fromIndex: kotlin /*∆*/ @kotlin.js.library(name = "primitiveArraySort") public fun kotlin.ByteArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.ByteArray.sort(noinline comparison: (a: kotlin.Byte, b: kotlin.Byte) -> kotlin.Int): kotlin.Unit @@ -8358,6 +8362,8 @@ public fun kotlin.ByteArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.In /*∆*/ @kotlin.js.library(name = "primitiveArraySort") public fun kotlin.CharArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.CharArray.sort(noinline comparison: (a: kotlin.Char, b: kotlin.Char) -> kotlin.Int): kotlin.Unit @@ -8367,6 +8373,8 @@ public fun kotlin.CharArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.In /*∆*/ @kotlin.js.library(name = "primitiveArraySort") public fun kotlin.DoubleArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.DoubleArray.sort(noinline comparison: (a: kotlin.Double, b: kotlin.Double) -> kotlin.Int): kotlin.Unit @@ -8376,6 +8384,8 @@ public fun kotlin.DoubleArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin. /*∆*/ @kotlin.js.library(name = "primitiveArraySort") public fun kotlin.FloatArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.FloatArray.sort(noinline comparison: (a: kotlin.Float, b: kotlin.Float) -> kotlin.Int): kotlin.Unit @@ -8385,6 +8395,8 @@ public fun kotlin.FloatArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.I /*∆*/ @kotlin.js.library(name = "primitiveArraySort") public fun kotlin.IntArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.IntArray.sort(noinline comparison: (a: kotlin.Int, b: kotlin.Int) -> kotlin.Int): kotlin.Unit @@ -8393,6 +8405,8 @@ public fun kotlin.IntArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.Int public fun kotlin.LongArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.LongArray.sort(noinline comparison: (a: kotlin.Long, b: kotlin.Long) -> kotlin.Int): kotlin.Unit @@ -8402,6 +8416,8 @@ public fun kotlin.LongArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.In /*∆*/ @kotlin.js.library(name = "primitiveArraySort") public fun kotlin.ShortArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.ShortArray.sort(noinline comparison: (a: kotlin.Short, b: kotlin.Short) -> kotlin.Int): kotlin.Unit diff --git a/libraries/stdlib/api/js/kotlin.collections.kt b/libraries/stdlib/api/js/kotlin.collections.kt index 7ebd7720d4b..d73d78fef39 100644 --- a/libraries/stdlib/api/js/kotlin.collections.kt +++ b/libraries/stdlib/api/js/kotlin.collections.kt @@ -8311,6 +8311,8 @@ public fun kotlin.UShortArray.sliceArray(indices: kotlin.ranges.IntRange): kotli public fun > kotlin.Array.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use sortWith instead", replaceWith = kotlin.ReplaceWith(expression = "this.sortWith(Comparator(comparison))", imports = {})) +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") public fun kotlin.Array.sort(comparison: (a: T, b: T) -> kotlin.Int): kotlin.Unit @kotlin.SinceKotlin(version = "1.4") @@ -8318,6 +8320,8 @@ public fun > kotlin.Array.sort(fromIndex: kotlin public fun kotlin.ByteArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.ByteArray.sort(noinline comparison: (a: kotlin.Byte, b: kotlin.Byte) -> kotlin.Int): kotlin.Unit @@ -8326,6 +8330,8 @@ public fun kotlin.ByteArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.In public fun kotlin.CharArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.CharArray.sort(noinline comparison: (a: kotlin.Char, b: kotlin.Char) -> kotlin.Int): kotlin.Unit @@ -8334,6 +8340,8 @@ public fun kotlin.CharArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.In public fun kotlin.DoubleArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.DoubleArray.sort(noinline comparison: (a: kotlin.Double, b: kotlin.Double) -> kotlin.Int): kotlin.Unit @@ -8342,6 +8350,8 @@ public fun kotlin.DoubleArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin. public fun kotlin.FloatArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.FloatArray.sort(noinline comparison: (a: kotlin.Float, b: kotlin.Float) -> kotlin.Int): kotlin.Unit @@ -8350,6 +8360,8 @@ public fun kotlin.FloatArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.I public fun kotlin.IntArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.IntArray.sort(noinline comparison: (a: kotlin.Int, b: kotlin.Int) -> kotlin.Int): kotlin.Unit @@ -8358,6 +8370,8 @@ public fun kotlin.IntArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.Int public fun kotlin.LongArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.LongArray.sort(noinline comparison: (a: kotlin.Long, b: kotlin.Long) -> kotlin.Int): kotlin.Unit @@ -8366,6 +8380,8 @@ public fun kotlin.LongArray.sort(fromIndex: kotlin.Int = ..., toIndex: kotlin.In public fun kotlin.ShortArray.sort(): kotlin.Unit +@kotlin.Deprecated(message = "Use other sorting functions from the Standard Library") +@kotlin.DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun kotlin.ShortArray.sort(noinline comparison: (a: kotlin.Short, b: kotlin.Short) -> kotlin.Int): kotlin.Unit diff --git a/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt b/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt index fde309db189..efde4350490 100644 --- a/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt +++ b/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt @@ -1814,6 +1814,7 @@ public actual fun IntArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun LongArray.sort(): Unit { + @Suppress("DEPRECATION") if (size > 1) sort { a: Long, b: Long -> a.compareTo(b) } } @@ -1878,6 +1879,8 @@ public actual fun > Array.sort(): Unit { * * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. */ +@Deprecated("Use sortWith instead", ReplaceWith("this.sortWith(Comparator(comparison))")) +@DeprecatedSinceKotlin(warningSince = "1.6") public fun Array.sort(comparison: (a: T, b: T) -> Int): Unit { if (size > 1) sortArrayWith(this, comparison) } @@ -2036,6 +2039,8 @@ public actual fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int): Unit { asDynamic().sort(comparison) @@ -2044,6 +2049,8 @@ public inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int) /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun ShortArray.sort(noinline comparison: (a: Short, b: Short) -> Int): Unit { asDynamic().sort(comparison) @@ -2052,6 +2059,8 @@ public inline fun ShortArray.sort(noinline comparison: (a: Short, b: Short) -> I /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun IntArray.sort(noinline comparison: (a: Int, b: Int) -> Int): Unit { asDynamic().sort(comparison) @@ -2060,6 +2069,8 @@ public inline fun IntArray.sort(noinline comparison: (a: Int, b: Int) -> Int): U /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun LongArray.sort(noinline comparison: (a: Long, b: Long) -> Int): Unit { asDynamic().sort(comparison) @@ -2068,6 +2079,8 @@ public inline fun LongArray.sort(noinline comparison: (a: Long, b: Long) -> Int) /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun FloatArray.sort(noinline comparison: (a: Float, b: Float) -> Int): Unit { asDynamic().sort(comparison) @@ -2076,6 +2089,8 @@ public inline fun FloatArray.sort(noinline comparison: (a: Float, b: Float) -> I /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun DoubleArray.sort(noinline comparison: (a: Double, b: Double) -> Int): Unit { asDynamic().sort(comparison) @@ -2084,6 +2099,8 @@ public inline fun DoubleArray.sort(noinline comparison: (a: Double, b: Double) - /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun CharArray.sort(noinline comparison: (a: Char, b: Char) -> Int): Unit { asDynamic().sort(comparison) diff --git a/libraries/stdlib/js/src/generated/_ArraysJs.kt b/libraries/stdlib/js/src/generated/_ArraysJs.kt index 689e24bbac7..357fd6bf5bb 100644 --- a/libraries/stdlib/js/src/generated/_ArraysJs.kt +++ b/libraries/stdlib/js/src/generated/_ArraysJs.kt @@ -1827,6 +1827,7 @@ public actual fun IntArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun LongArray.sort(): Unit { + @Suppress("DEPRECATION") if (size > 1) sort { a: Long, b: Long -> a.compareTo(b) } } @@ -1896,6 +1897,8 @@ public actual fun > Array.sort(): Unit { * * The sort is _stable_. It means that equal elements preserve their order relative to each other after sorting. */ +@Deprecated("Use sortWith instead", ReplaceWith("this.sortWith(Comparator(comparison))")) +@DeprecatedSinceKotlin(warningSince = "1.6") public fun Array.sort(comparison: (a: T, b: T) -> Int): Unit { if (size > 1) sortArrayWith(this, comparison) } @@ -2055,6 +2058,8 @@ public actual fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int): Unit { asDynamic().sort(comparison) @@ -2063,6 +2068,8 @@ public inline fun ByteArray.sort(noinline comparison: (a: Byte, b: Byte) -> Int) /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun ShortArray.sort(noinline comparison: (a: Short, b: Short) -> Int): Unit { asDynamic().sort(comparison) @@ -2071,6 +2078,8 @@ public inline fun ShortArray.sort(noinline comparison: (a: Short, b: Short) -> I /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun IntArray.sort(noinline comparison: (a: Int, b: Int) -> Int): Unit { asDynamic().sort(comparison) @@ -2079,6 +2088,8 @@ public inline fun IntArray.sort(noinline comparison: (a: Int, b: Int) -> Int): U /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun LongArray.sort(noinline comparison: (a: Long, b: Long) -> Int): Unit { asDynamic().sort(comparison) @@ -2087,6 +2098,8 @@ public inline fun LongArray.sort(noinline comparison: (a: Long, b: Long) -> Int) /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun FloatArray.sort(noinline comparison: (a: Float, b: Float) -> Int): Unit { asDynamic().sort(comparison) @@ -2095,6 +2108,8 @@ public inline fun FloatArray.sort(noinline comparison: (a: Float, b: Float) -> I /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun DoubleArray.sort(noinline comparison: (a: Double, b: Double) -> Int): Unit { asDynamic().sort(comparison) @@ -2103,6 +2118,8 @@ public inline fun DoubleArray.sort(noinline comparison: (a: Double, b: Double) - /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ +@Deprecated("Use other sorting functions from the Standard Library") +@DeprecatedSinceKotlin(warningSince = "1.6") @kotlin.internal.InlineOnly public inline fun CharArray.sort(noinline comparison: (a: Char, b: Char) -> Int): Unit { asDynamic().sort(comparison) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt index 50132608fd1..a5169f9356b 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt @@ -1233,7 +1233,10 @@ object ArrayOps : TemplateGroupBase() { } } else { body { - """if (size > 1) sort { a: T, b: T -> a.compareTo(b) }""" + """ + @Suppress("DEPRECATION") + if (size > 1) sort { a: T, b: T -> a.compareTo(b) } + """ } } } @@ -1295,11 +1298,15 @@ object ArrayOps : TemplateGroupBase() { returns("Unit") doc { "Sorts the array in-place according to the order specified by the given [comparison] function." } specialFor(ArraysOfPrimitives) { + deprecate(Deprecation("Use other sorting functions from the Standard Library", warningSince = "1.6")) inlineOnly() signature("sort(noinline comparison: (a: T, b: T) -> Int)") body { "asDynamic().sort(comparison)" } } specialFor(ArraysOfObjects) { + deprecate( + Deprecation("Use sortWith instead", replaceWith = "this.sortWith(Comparator(comparison))", warningSince = "1.6") + ) appendStableSortNote() body { """if (size > 1) sortArrayWith(this, comparison)""" } }