From 77491ded1b9c8a3f63ecf0d17fd0698852aad5a2 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Thu, 20 Apr 2023 15:46:30 +0200 Subject: [PATCH] Use Array constructor with size to create Array of nulls Change the constructor visibility from public to private as it should be. --- compiler/testData/codegen/box/size/add.kt | 2 +- compiler/testData/codegen/box/size/helloWorld.kt | 2 +- compiler/testData/codegen/box/size/helloWorldDOM.kt | 2 +- compiler/testData/codegen/box/size/ok.kt | 2 +- libraries/stdlib/wasm/builtins/kotlin/Array.kt | 3 ++- libraries/stdlib/wasm/builtins/kotlin/Library.kt | 2 +- libraries/stdlib/wasm/internal/kotlin/wasm/internal/Runtime.kt | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/testData/codegen/box/size/add.kt b/compiler/testData/codegen/box/size/add.kt index 667a2e0db21..76b96555f5e 100644 --- a/compiler/testData/codegen/box/size/add.kt +++ b/compiler/testData/codegen/box/size/add.kt @@ -1,6 +1,6 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_217 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_295 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_579 // FILE: test.kt diff --git a/compiler/testData/codegen/box/size/helloWorld.kt b/compiler/testData/codegen/box/size/helloWorld.kt index fcc6a4455af..6ab6b2d02b7 100644 --- a/compiler/testData/codegen/box/size/helloWorld.kt +++ b/compiler/testData/codegen/box/size/helloWorld.kt @@ -1,6 +1,6 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 49_207 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 48_188 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_605 fun box(): String { diff --git a/compiler/testData/codegen/box/size/helloWorldDOM.kt b/compiler/testData/codegen/box/size/helloWorldDOM.kt index 5871713da96..edb51f7eee9 100644 --- a/compiler/testData/codegen/box/size/helloWorldDOM.kt +++ b/compiler/testData/codegen/box/size/helloWorldDOM.kt @@ -1,6 +1,6 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 15_582 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 13_660 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_134 // FILE: test.kt diff --git a/compiler/testData/codegen/box/size/ok.kt b/compiler/testData/codegen/box/size/ok.kt index 6fa8e62df26..39bead109dd 100644 --- a/compiler/testData/codegen/box/size/ok.kt +++ b/compiler/testData/codegen/box/size/ok.kt @@ -1,6 +1,6 @@ // TARGET_BACKEND: WASM -// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_259 +// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_337 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451 fun box() = "OK" \ No newline at end of file diff --git a/libraries/stdlib/wasm/builtins/kotlin/Array.kt b/libraries/stdlib/wasm/builtins/kotlin/Array.kt index 47d13b1bdd9..a3a9a29ff41 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Array.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Array.kt @@ -14,7 +14,7 @@ import kotlin.wasm.internal.* * See [Kotlin language documentation](https://kotlinlang.org/docs/reference/basic-types.html#arrays) * for more information on arrays. */ -public class Array constructor(size: Int) { +public class Array @PublishedApi internal constructor(size: Int) { internal val storage: WasmAnyArray = WasmAnyArray(size) @Suppress("TYPE_PARAMETER_AS_REIFIED", "UNUSED_PARAMETER", "CAST_NEVER_SUCCEEDS") @@ -28,6 +28,7 @@ public class Array constructor(size: Int) { * The function [init] is called for each array element sequentially starting from the first one. * It should return the value for an array element given its index. */ + // TODO: it have to be inline @Suppress("TYPE_PARAMETER_AS_REIFIED") public constructor(size: Int, init: (Int) -> T) : this(size) { storage.fill(size, init) diff --git a/libraries/stdlib/wasm/builtins/kotlin/Library.kt b/libraries/stdlib/wasm/builtins/kotlin/Library.kt index 407ab48f531..11715166199 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Library.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Library.kt @@ -30,7 +30,7 @@ public operator fun String?.plus(other: Any?): String = (this ?: "null") + other */ // TODO: Should T be reified? @Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE") -public fun <@PureReifiable reified T> arrayOfNulls(size: Int): Array = Array(size) { null } +public fun <@PureReifiable reified T> arrayOfNulls(size: Int): Array = Array(size) /** * Returns an array containing the specified elements. diff --git a/libraries/stdlib/wasm/internal/kotlin/wasm/internal/Runtime.kt b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/Runtime.kt index a141fde8f48..fb8bd7389bb 100644 --- a/libraries/stdlib/wasm/internal/kotlin/wasm/internal/Runtime.kt +++ b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/Runtime.kt @@ -119,4 +119,4 @@ internal fun stringGetPoolSize(): Int = // This initializer is a special case in FieldInitializersLowering @Suppress("DEPRECATION") @EagerInitialization -internal val stringPool: Array = arrayOfNulls(stringGetPoolSize()) \ No newline at end of file +internal val stringPool: Array = Array(stringGetPoolSize()) \ No newline at end of file