[Wasm] stdlib NFC: Fix or suppress remaining warnings

This commit is contained in:
Svyatoslav Kuzmich
2023-01-20 13:05:08 +01:00
parent 238da4c793
commit 72d9b8ddae
22 changed files with 46 additions and 17 deletions
@@ -112,6 +112,7 @@ internal fun Dynamic.getDouble(index: String): Double = dynamicGetDouble(this, i
@PublishedApi
internal fun Dynamic.getString(index: String): String? = dynamicGetString(this, index)
@Suppress("UNCHECKED_CAST")
@PublishedApi
internal fun <T> Dynamic.getAny(index: String): T? = dynamicGetAny(this, index) as T?
@@ -142,6 +143,7 @@ internal fun Dynamic.getDouble(index: Int): Double = dynamicGetDouble(this, inde
@PublishedApi
internal fun Dynamic.getString(index: Int): String? = dynamicGetString(this, index.toString())
@Suppress("UNCHECKED_CAST")
@PublishedApi
internal fun <T> Dynamic.getAny(index: Int): T? = dynamicGetAny(this, index.toString()) as T?
@@ -153,6 +155,7 @@ external interface Dynamic
/**
* Reinterprets this value as a value of the Dynamic type.
*/
@Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE")
@kotlin.internal.InlineOnly
fun Any.asDynamic(): Dynamic = this as Dynamic
@@ -183,6 +186,8 @@ operator fun Dynamic.set(index: Int, value: Any?) {
@JsFun("(x) => x")
private external fun <T> unsafeCastJs(x: String): Dynamic
@Suppress("UNCHECKED_CAST")
fun <T> String.unsafeCast(): T = unsafeCastJs<T>(this) as T
@JsFun("(x) => x")
@@ -191,6 +196,7 @@ private external fun <T> unsafeCastJs(x: Boolean): Dynamic
/**
* Reinterprets boolean value as a value of the specified type [T] without any actual type checking.
*/
@Suppress("UNCHECKED_CAST")
fun <T> Boolean.unsafeCast(): T = unsafeCastJs<T>(this) as T
/**
@@ -201,6 +207,7 @@ fun <T> Nothing?.unsafeCast(): Dynamic? = null
/**
* Reinterprets Dynamic type value as a value of the specified type [T] without any actual type checking.
*/
@Suppress("UNCHECKED_CAST")
fun <T> Dynamic.unsafeCast(): T = this as T
@JsFun("e => { throw e; }")
@@ -75,6 +75,7 @@ public actual fun Int.rotateRight(bitCount: Int): Int =
/**
* Counts the number of set bits in the binary representation of this [Long] number.
*/
@Suppress("NOTHING_TO_INLINE")
public actual inline fun Long.countOneBits(): Int =
wasm_i64_popcnt(this).toInt()
@@ -87,6 +88,7 @@ public actual fun Long.countLeadingZeroBits(): Int = wasm_i64_clz(this).toInt()
/**
* Counts the number of consecutive least significant bits that are zero in the binary representation of this [Long] number.
*/
@Suppress("NOTHING_TO_INLINE")
public actual inline fun Long.countTrailingZeroBits(): Int =
wasm_i64_ctz(this).toInt()
@@ -15,6 +15,7 @@ package kotlin.collections
@kotlin.internal.InlineOnly
public actual inline fun <T> Collection<T>.toTypedArray(): Array<T> = copyToArray(this)
@Suppress("UNCHECKED_CAST")
@PublishedApi
internal fun <T> copyToArray(collection: Collection<T>): Array<T> =
if (collection is AbstractCollection<T>)
@@ -10,6 +10,7 @@ package kotlin.collections
* Attempts to read _uninitialized_ values from this array work in implementation-dependent manner,
* either throwing exception or returning some kind of implementation-specific default value.
*/
@Suppress("NOTHING_TO_INLINE")
@PublishedApi
internal inline fun <E> arrayOfUninitializedElements(size: Int): Array<E> {
require(size >= 0) { "capacity must be non-negative." }
@@ -9,10 +9,10 @@ package kotlin.js
* Exposes the JavaScript [Promise object](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) to Kotlin.
*/
public external class Promise<out T>(executor: (resolve: (Dynamic?) -> Unit, reject: (Dynamic) -> Unit) -> Unit) {
public open fun then(onFulfilled: (Dynamic?) -> Dynamic?): Promise<Dynamic?>
public open fun then(onFulfilled: (Dynamic?) -> Dynamic?, onRejected: (Dynamic) -> Dynamic?): Promise<Dynamic?>
public open fun catch(onRejected: (Dynamic) -> Dynamic?): Promise<Dynamic?>
public open fun finally(onFinally: () -> Unit): Promise<Dynamic?>
public fun then(onFulfilled: (Dynamic?) -> Dynamic?): Promise<Dynamic?>
public fun then(onFulfilled: (Dynamic?) -> Dynamic?, onRejected: (Dynamic) -> Dynamic?): Promise<Dynamic?>
public fun catch(onRejected: (Dynamic) -> Dynamic?): Promise<Dynamic?>
public fun finally(onFinally: () -> Unit): Promise<Dynamic?>
public companion object {
public fun reject(e: Dynamic): Promise<Dynamic?>
@@ -12,6 +12,7 @@ import kotlin.reflect.wasm.internal.*
internal fun <T : Any> getKClass(typeInfoData: TypeInfoData): KClass<T> =
KClassImpl(typeInfoData)
@Suppress("UNCHECKED_CAST")
internal fun <T : Any> getKClassFromExpression(e: T): KClass<T> =
when (e) {
is String -> PrimitiveClasses.stringClass
@@ -299,9 +299,10 @@ public actual fun CharSequence.repeat(n: Int): String {
0 -> ""
1 -> this.toString()
else -> {
val sequence = this
buildString(n * length) {
repeat(n) {
append(this@repeat)
append(sequence)
}
}
}
@@ -27,13 +27,13 @@ internal actual object MonotonicTimeSource : TimeSource.WithComparableMarks {
if (performance != null) getPerformanceNow(performance) else dateNow()
actual override fun markNow(): ValueTimeMark = ValueTimeMark(read())
actual fun elapsedFrom(timeMark: ValueTimeMark): Duration = (read() - timeMark.reading as Double).milliseconds
actual fun elapsedFrom(timeMark: ValueTimeMark): Duration = (read() - timeMark.reading).milliseconds
actual fun adjustReading(timeMark: ValueTimeMark, duration: Duration): ValueTimeMark =
ValueTimeMark(sumCheckNaN(timeMark.reading as Double + duration.toDouble(DurationUnit.MILLISECONDS)))
ValueTimeMark(sumCheckNaN(timeMark.reading + duration.toDouble(DurationUnit.MILLISECONDS)))
actual fun differenceBetween(one: ValueTimeMark, another: ValueTimeMark): Duration {
val ms1 = one.reading as Double
val ms2 = another.reading as Double
val ms1 = one.reading
val ms2 = another.reading
return if (ms1 == ms2) Duration.ZERO else (ms1 - ms2).milliseconds
}
@@ -52,21 +52,25 @@ public value class Pointer public constructor(public val address: UInt) {
implementedAsIntrinsic
/** Store a Byte (8 bit) [value] */
@Suppress("UNUSED_PARAMETER")
@WasmOp(WasmOp.I32_STORE8)
public fun storeByte(value: Byte): Unit =
implementedAsIntrinsic
/** Store a Short (16 bit) [value] */
@Suppress("UNUSED_PARAMETER")
@WasmOp(WasmOp.I32_STORE16)
public fun storeShort(value: Short): Unit =
implementedAsIntrinsic
/** Store an Int (32 bit) [value] */
@Suppress("UNUSED_PARAMETER")
@WasmOp(WasmOp.I32_STORE)
public fun storeInt(value: Int): Unit =
implementedAsIntrinsic
/** Store a Long (64 bit) [value] */
@Suppress("UNUSED_PARAMETER")
@WasmOp(WasmOp.I64_STORE)
public fun storeLong(value: Long): Unit =
implementedAsIntrinsic
@@ -151,6 +151,7 @@ internal fun wasmMemorySize(): Int =
* Grow memory by a given delta (in pages).
* Return the previous size, or -1 if enough memory cannot be allocated.
*/
@Suppress("UNUSED_PARAMETER")
@WasmOp(WasmOp.MEMORY_GROW)
internal fun wasmMemoryGrow(delta: Int): Int =
implementedAsIntrinsic
@@ -13,6 +13,7 @@ public external interface ItemArrayLike<out T> {
public fun <T> ItemArrayLike<T>.asList(): List<T> = object : AbstractList<T>() {
override val size: Int get() = this@asList.length
@Suppress("UNCHECKED_CAST")
override fun get(index: Int): T = when (index) {
in 0..lastIndex -> this@asList.item(index) as T
else -> throw IndexOutOfBoundsException("index $index is not in range [0..$lastIndex]")