diff --git a/compiler/testData/codegen/box/enum/sortEnumEntries.kt b/compiler/testData/codegen/box/enum/sortEnumEntries.kt index 41dd0f3c7c0..2c1034a7df8 100644 --- a/compiler/testData/codegen/box/enum/sortEnumEntries.kt +++ b/compiler/testData/codegen/box/enum/sortEnumEntries.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_GENERATED // WITH_STDLIB import Game.* diff --git a/compiler/testData/codegen/box/regressions/kt2017.kt b/compiler/testData/codegen/box/regressions/kt2017.kt index 2c721b61db1..632e31924da 100644 --- a/compiler/testData/codegen/box/regressions/kt2017.kt +++ b/compiler/testData/codegen/box/regressions/kt2017.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_SORT // WITH_STDLIB fun box(): String { diff --git a/compiler/testData/codegen/box/regressions/kt5056.kt b/compiler/testData/codegen/box/regressions/kt5056.kt index 664adafbcd6..f1693c1f115 100644 --- a/compiler/testData/codegen/box/regressions/kt5056.kt +++ b/compiler/testData/codegen/box/regressions/kt5056.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_GENERATED // WITH_STDLIB fun box(): String { diff --git a/compiler/testData/codegen/box/regressions/kt6434.kt b/compiler/testData/codegen/box/regressions/kt6434.kt index 350b12c0a11..c767c63c6e9 100644 --- a/compiler/testData/codegen/box/regressions/kt6434.kt +++ b/compiler/testData/codegen/box/regressions/kt6434.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: IGNORED_IN_JS // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt index 92b819ed187..71bca9a23f2 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt @@ -22,22 +22,6 @@ internal inline fun arrayOfUninitializedElements(size: Int): Array { return Array(size) } - -/** - * Returns a new array which is a copy of the original array with new elements filled with null values. - */ -internal fun Array.copyOfNulls(newSize: Int): Array = copyOfNulls(0, newSize) - -internal fun Array.copyOfNulls(fromIndex: Int, toIndex: Int): Array { - val newSize = toIndex - fromIndex - if (newSize < 0) { - throw IllegalArgumentException("$fromIndex > $toIndex") - } - val result = @Suppress("TYPE_PARAMETER_AS_REIFIED") arrayOfNulls(newSize) - this.copyInto(result, 0, fromIndex, toIndex.coerceAtMost(size)) - return result -} - /** * Copies elements of the [collection] into the given [array]. * If the array is too small, allocates a new one of collection.size size. diff --git a/libraries/stdlib/native-wasm/src/kotlin/collections/Arrays.kt b/libraries/stdlib/native-wasm/src/kotlin/collections/Arrays.kt index 7a230623ba0..b94a7935607 100644 --- a/libraries/stdlib/native-wasm/src/kotlin/collections/Arrays.kt +++ b/libraries/stdlib/native-wasm/src/kotlin/collections/Arrays.kt @@ -123,3 +123,18 @@ public actual inline fun Collection.toTypedArray(): Array { @Suppress("UNCHECKED_CAST") return result as Array } + +/** + * Returns a new array which is a copy of the original array with new elements filled with null values. + */ +internal fun Array.copyOfNulls(newSize: Int): Array = copyOfNulls(0, newSize) + +internal fun Array.copyOfNulls(fromIndex: Int, toIndex: Int): Array { + val newSize = toIndex - fromIndex + if (newSize < 0) { + throw IllegalArgumentException("$fromIndex > $toIndex") + } + val result = @Suppress("TYPE_PARAMETER_AS_REIFIED") arrayOfNulls(newSize) + this.copyInto(result, 0, fromIndex, toIndex.coerceAtMost(size)) + return result +} \ No newline at end of file diff --git a/libraries/stdlib/wasm/src/generated/_ArraysWasm.kt b/libraries/stdlib/wasm/src/generated/_ArraysWasm.kt index b861b847697..1eab9a76c96 100644 --- a/libraries/stdlib/wasm/src/generated/_ArraysWasm.kt +++ b/libraries/stdlib/wasm/src/generated/_ArraysWasm.kt @@ -1499,7 +1499,7 @@ public actual fun CharArray.copyOf(newSize: Int): CharArray { * @sample samples.collections.Arrays.CopyOfOperations.resizingCopyOf */ public actual fun Array.copyOf(newSize: Int): Array { - TODO("Wasm stdlib: copyOf(newSize: Int)") + return this.copyOfNulls(newSize) } /** @@ -2299,7 +2299,7 @@ public actual inline fun Array.plusElement(element: T): Array { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun IntArray.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2308,7 +2308,7 @@ public actual fun IntArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun LongArray.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2317,7 +2317,7 @@ public actual fun LongArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun ByteArray.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2326,7 +2326,7 @@ public actual fun ByteArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun ShortArray.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2335,7 +2335,7 @@ public actual fun ShortArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun DoubleArray.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2344,7 +2344,7 @@ public actual fun DoubleArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun FloatArray.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2353,7 +2353,7 @@ public actual fun FloatArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArray */ public actual fun CharArray.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2364,7 +2364,7 @@ public actual fun CharArray.sort(): Unit { * @sample samples.collections.Arrays.Sorting.sortArrayOfComparable */ public actual fun > Array.sort(): Unit { - TODO("Wasm stdlib: sort()") + if (size > 1) sortArray(this, 0, size) } /** @@ -2383,7 +2383,8 @@ public actual fun > Array.sort(): Unit { @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun > Array.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2400,7 +2401,8 @@ public actual fun > Array.sort(fromIndex: Int = 0, toIn @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2417,7 +2419,8 @@ public actual fun ByteArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2434,7 +2437,8 @@ public actual fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2451,7 +2455,8 @@ public actual fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2468,7 +2473,8 @@ public actual fun LongArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2485,7 +2491,8 @@ public actual fun FloatArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2502,7 +2509,8 @@ public actual fun DoubleArray.sort(fromIndex: Int = 0, toIndex: Int = size): Uni @SinceKotlin("1.4") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun CharArray.sort(fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sort(fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArray(this, fromIndex, toIndex) } /** @@ -2527,7 +2535,8 @@ public actual fun Array.sortWith(comparator: Comparator): Unit */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun Array.sortWith(comparator: Comparator, fromIndex: Int = 0, toIndex: Int = size): Unit { - TODO("Wasm stdlib: sortWith(comparator: Comparator, fromIndex: Int = 0, toIndex: Int = size)") + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + sortArrayWith(this, fromIndex, toIndex, comparator) } /** diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt index 90d6cc80842..ca933f25362 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt @@ -1174,9 +1174,6 @@ object ArrayOps : TemplateGroupBase() { } on(Platform.Native) { body { "return this.copyOfNulls(newSize)" } - on(Backend.Wasm) { - body { """TODO("Wasm stdlib: $signature")""" } - } } } specialFor(ArraysOfPrimitives, InvariantArraysOfObjects) { @@ -1259,9 +1256,6 @@ object ArrayOps : TemplateGroupBase() { } on(Platform.Native) { body { """if (size > 1) sortArray(this, 0, size)""" } - on(Backend.Wasm) { - body { """TODO("Wasm stdlib: $signature")""" } - } } } } @@ -1396,9 +1390,6 @@ object ArrayOps : TemplateGroupBase() { sortArray(this, fromIndex, toIndex) """ } - on(Backend.Wasm) { - body { """TODO("Wasm stdlib: $signature")""" } - } } on(Platform.JS) { since("1.4") @@ -1455,9 +1446,6 @@ object ArrayOps : TemplateGroupBase() { sortArrayWith(this, fromIndex, toIndex, comparator) """ } - on(Backend.Wasm) { - body { """TODO("Wasm stdlib: $signature")""" } - } } on(Platform.JS) { since("1.4")