[Wasm] Introduce check and error specialized for String to reduce output size
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
// TARGET_BACKEND: WASM
|
||||
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 65_583
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_517
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 34_990
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_359
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// TARGET_BACKEND: WASM
|
||||
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 65_908
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 65_772
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_458
|
||||
|
||||
fun box(): String {
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// TARGET_BACKEND: WASM
|
||||
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 77_603
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_956
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 38_291
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_798
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// TARGET_BACKEND: WASM
|
||||
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 65_634
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_389
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 35_038
|
||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_231
|
||||
|
||||
fun box() = "OK"
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import kotlin.contracts.contract
|
||||
|
||||
// Here are functions specialized with String type to avoid marking Any.toString and its overrides as reachable in DCE.
|
||||
// Just making the declarations public is impossible since it may change the resolution in a user code.
|
||||
// TODO: investigate other ways to achieve the same, preferably covering not stdlib only but user cases too.
|
||||
|
||||
@PublishedApi
|
||||
@kotlin.internal.InlineOnly
|
||||
internal inline fun check(value: Boolean, lazyMessage: () -> String): Unit {
|
||||
contract {
|
||||
returns() implies value
|
||||
}
|
||||
if (!value) {
|
||||
val message = lazyMessage()
|
||||
throw IllegalStateException(message)
|
||||
}
|
||||
}
|
||||
|
||||
@PublishedApi
|
||||
@kotlin.internal.InlineOnly
|
||||
internal inline fun error(message: String): Nothing = throw IllegalStateException(message)
|
||||
Reference in New Issue
Block a user