diff --git a/js/js.libraries/src/core/numbers.kt b/js/js.libraries/src/core/numbers.kt new file mode 100644 index 00000000000..53ef6fbb069 --- /dev/null +++ b/js/js.libraries/src/core/numbers.kt @@ -0,0 +1,33 @@ +package kotlin + +/** + * Returns `true` if the specified number is a + * Not-a-Number (NaN) value, `false` otherwise. + */ +public fun Double.isNaN(): Boolean = this != this + +/** + * Returns `true` if the specified number is a + * Not-a-Number (NaN) value, `false` otherwise. + */ +public fun Float.isNaN(): Boolean = this != this + +/** + * Returns `true` if this value is infinitely large in magnitude. + */ +public fun Double.isInfinite(): Boolean = this == Double.POSITIVE_INFINITY || this == Double.NEGATIVE_INFINITY + +/** + * Returns `true` if this value is infinitely large in magnitude. + */ +public fun Float.isInfinite(): Boolean = this == Float.POSITIVE_INFINITY || this == Float.NEGATIVE_INFINITY + +/** + * Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments). + */ +public fun Double.isFinite(): Boolean = !isInfinite() && !isNaN() + +/** + * Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments). + */ +public fun Float.isFinite(): Boolean = !isInfinite() && !isNaN() diff --git a/libraries/stdlib/src/kotlin/system/Process.kt b/libraries/stdlib/src/kotlin/system/Process.kt index b5d60a2f00a..373813bc684 100644 --- a/libraries/stdlib/src/kotlin/system/Process.kt +++ b/libraries/stdlib/src/kotlin/system/Process.kt @@ -9,7 +9,8 @@ package kotlin.system * * This method never returns normally. */ -public fun exitProcess(status: Int): Nothing { +@kotlin.internal.InlineOnly +public inline fun exitProcess(status: Int): Nothing { System.exit(status) throw RuntimeException("System.exit returned normally, while it was supposed to halt JVM.") } \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt index e6f7e27360b..5c1950657d0 100644 --- a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt +++ b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt @@ -19,6 +19,7 @@ public fun assert(value: Boolean) { * Throws an [AssertionError] calculated by [lazyMessage] if the [value] is false * and runtime assertions have been enabled on the JVM using the *-ea* JVM option. */ +@kotlin.internal.InlineOnly public inline fun assert(value: Boolean, lazyMessage: () -> Any) { @Suppress("INVISIBLE_MEMBER_FROM_INLINE") if (ASSERTIONS_ENABLED) { diff --git a/libraries/stdlib/src/kotlin/util/BigNumbers.kt b/libraries/stdlib/src/kotlin/util/BigNumbers.kt index 45488068f77..ef7410fdfed 100644 --- a/libraries/stdlib/src/kotlin/util/BigNumbers.kt +++ b/libraries/stdlib/src/kotlin/util/BigNumbers.kt @@ -9,55 +9,66 @@ import java.math.BigInteger /** * Enables the use of the `+` operator for [BigInteger] instances. */ -public operator fun BigInteger.plus(other: BigInteger) : BigInteger = this.add(other) +@kotlin.internal.InlineOnly +public inline operator fun BigInteger.plus(other: BigInteger) : BigInteger = this.add(other) /** * Enables the use of the `-` operator for [BigInteger] instances. */ -public operator fun BigInteger.minus(other: BigInteger) : BigInteger = this.subtract(other) +@kotlin.internal.InlineOnly +public inline operator fun BigInteger.minus(other: BigInteger) : BigInteger = this.subtract(other) /** * Enables the use of the `*` operator for [BigInteger] instances. */ -public operator fun BigInteger.times(other: BigInteger) : BigInteger = this.multiply(other) +@kotlin.internal.InlineOnly +public inline operator fun BigInteger.times(other: BigInteger) : BigInteger = this.multiply(other) /** * Enables the use of the `/` operator for [BigInteger] instances. */ -public operator fun BigInteger.div(other: BigInteger) : BigInteger = this.divide(other) +@kotlin.internal.InlineOnly +public inline operator fun BigInteger.div(other: BigInteger) : BigInteger = this.divide(other) /** * Enables the use of the unary `-` operator for [BigInteger] instances. */ -public operator fun BigInteger.unaryMinus() : BigInteger = this.negate() +@kotlin.internal.InlineOnly +public inline operator fun BigInteger.unaryMinus() : BigInteger = this.negate() /** * Enables the use of the `+` operator for [BigDecimal] instances. */ -public operator fun BigDecimal.plus(other: BigDecimal) : BigDecimal = this.add(other) +@kotlin.internal.InlineOnly +public inline operator fun BigDecimal.plus(other: BigDecimal) : BigDecimal = this.add(other) /** * Enables the use of the `-` operator for [BigDecimal] instances. */ -public operator fun BigDecimal.minus(other: BigDecimal) : BigDecimal = this.subtract(other) +@kotlin.internal.InlineOnly +public inline operator fun BigDecimal.minus(other: BigDecimal) : BigDecimal = this.subtract(other) /** * Enables the use of the `*` operator for [BigDecimal] instances. */ -public operator fun BigDecimal.times(other: BigDecimal) : BigDecimal = this.multiply(other) +@kotlin.internal.InlineOnly +public inline operator fun BigDecimal.times(other: BigDecimal) : BigDecimal = this.multiply(other) /** * Enables the use of the `/` operator for [BigDecimal] instances. */ -public operator fun BigDecimal.div(other: BigDecimal) : BigDecimal = this.divide(other) +@kotlin.internal.InlineOnly +public inline operator fun BigDecimal.div(other: BigDecimal) : BigDecimal = this.divide(other) /** * Enables the use of the `%` operator for [BigDecimal] instances. */ -public operator fun BigDecimal.mod(other: BigDecimal) : BigDecimal = this.remainder(other) +@kotlin.internal.InlineOnly +public inline operator fun BigDecimal.mod(other: BigDecimal) : BigDecimal = this.remainder(other) /** * Enables the use of the unary `-` operator for [BigDecimal] instances. */ -public operator fun BigDecimal.unaryMinus() : BigDecimal = this.negate() +@kotlin.internal.InlineOnly +public inline operator fun BigDecimal.unaryMinus() : BigDecimal = this.negate() diff --git a/libraries/stdlib/src/kotlin/util/Integers.kt b/libraries/stdlib/src/kotlin/util/Integers.kt index 899b9bb4ef2..20ca1e414ad 100644 --- a/libraries/stdlib/src/kotlin/util/Integers.kt +++ b/libraries/stdlib/src/kotlin/util/Integers.kt @@ -7,6 +7,7 @@ package kotlin * * A zero-based index of current iteration is passed as a parameter to [action]. */ +@kotlin.internal.InlineOnly public inline fun repeat(times: Int, action: (Int) -> Unit) { for (index in 0..times - 1) { action(index) diff --git a/libraries/stdlib/src/kotlin/util/Numbers.kt b/libraries/stdlib/src/kotlin/util/Numbers.kt index acbc942ce90..1587dd4c498 100644 --- a/libraries/stdlib/src/kotlin/util/Numbers.kt +++ b/libraries/stdlib/src/kotlin/util/Numbers.kt @@ -1,35 +1,42 @@ @file:kotlin.jvm.JvmMultifileClass @file:kotlin.jvm.JvmName("MathKt") +@file:kotlin.jvm.JvmVersion package kotlin /** * Returns `true` if the specified number is a * Not-a-Number (NaN) value, `false` otherwise. */ -public fun Double.isNaN(): Boolean = this != this +@kotlin.internal.InlineOnly +public inline fun Double.isNaN(): Boolean = java.lang.Double.isNaN(this) /** * Returns `true` if the specified number is a * Not-a-Number (NaN) value, `false` otherwise. */ -public fun Float.isNaN(): Boolean = this != this +@kotlin.internal.InlineOnly +public inline fun Float.isNaN(): Boolean = java.lang.Float.isNaN(this) /** * Returns `true` if this value is infinitely large in magnitude. */ -public fun Double.isInfinite(): Boolean = this == Double.POSITIVE_INFINITY || this == Double.NEGATIVE_INFINITY +@kotlin.internal.InlineOnly +public inline fun Double.isInfinite(): Boolean = java.lang.Double.isInfinite(this) /** * Returns `true` if this value is infinitely large in magnitude. */ -public fun Float.isInfinite(): Boolean = this == Float.POSITIVE_INFINITY || this == Float.NEGATIVE_INFINITY +@kotlin.internal.InlineOnly +public inline fun Float.isInfinite(): Boolean = java.lang.Float.isInfinite(this) /** * Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments). */ -public fun Double.isFinite(): Boolean = !isInfinite() && !isNaN() +@kotlin.internal.InlineOnly +public inline fun Double.isFinite(): Boolean = !isInfinite() && !isNaN() /** * Returns `true` if the argument is a finite floating-point value; returns `false` otherwise (for `NaN` and infinity arguments). */ -public fun Float.isFinite(): Boolean = !isInfinite() && !isNaN() +@kotlin.internal.InlineOnly +public inline fun Float.isFinite(): Boolean = !isInfinite() && !isNaN() diff --git a/libraries/stdlib/src/kotlin/util/Preconditions.kt b/libraries/stdlib/src/kotlin/util/Preconditions.kt index db138715d9f..a50e10e8643 100644 --- a/libraries/stdlib/src/kotlin/util/Preconditions.kt +++ b/libraries/stdlib/src/kotlin/util/Preconditions.kt @@ -2,20 +2,21 @@ @file:kotlin.jvm.JvmName("PreconditionsKt") package kotlin -// TODO should not need this - its here for the JS stuff import java.lang.IllegalArgumentException import java.lang.IllegalStateException /** * Throws an [IllegalArgumentException] if the [value] is false. */ -public fun require(value: Boolean): Unit = require(value) { "Failed requirement" } +@kotlin.internal.InlineOnly +public inline fun require(value: Boolean): Unit = require(value) { "Failed requirement" } /** * Throws an [IllegalArgumentException] with the result of calling [lazyMessage] if the [value] is false. * * @sample test.collections.PreconditionsTest.failingRequireWithLazyMessage */ +@kotlin.internal.InlineOnly public inline fun require(value: Boolean, lazyMessage: () -> Any): Unit { if (!value) { val message = lazyMessage() @@ -26,7 +27,8 @@ public inline fun require(value: Boolean, lazyMessage: () -> Any): Unit { /** * Throws an [IllegalArgumentException] if the [value] is null. Otherwise returns the not null value. */ -public fun requireNotNull(value: T?): T = requireNotNull(value) { "Required value was null" } +@kotlin.internal.InlineOnly +public inline fun requireNotNull(value: T?): T = requireNotNull(value) { "Required value was null" } /** * Throws an [IllegalArgumentException] with the result of calling [lazyMessage] if the [value] is null. Otherwise @@ -34,6 +36,7 @@ public fun requireNotNull(value: T?): T = requireNotNull(value) { "Requi * * @sample test.collections.PreconditionsTest.requireNotNullWithLazyMessage */ +@kotlin.internal.InlineOnly public inline fun requireNotNull(value: T?, lazyMessage: () -> Any): T { if (value == null) { val message = lazyMessage() @@ -46,13 +49,15 @@ public inline fun requireNotNull(value: T?, lazyMessage: () -> Any): T { /** * Throws an [IllegalStateException] if the [value] is false. */ -public fun check(value: Boolean): Unit = check(value) { "Check failed" } +@kotlin.internal.InlineOnly +public inline fun check(value: Boolean): Unit = check(value) { "Check failed" } /** * Throws an [IllegalStateException] with the result of calling [lazyMessage] if the [value] is false. * * @sample test.collections.PreconditionsTest.failingCheckWithLazyMessage */ +@kotlin.internal.InlineOnly public inline fun check(value: Boolean, lazyMessage: () -> Any): Unit { if (!value) { val message = lazyMessage() @@ -64,12 +69,14 @@ public inline fun check(value: Boolean, lazyMessage: () -> Any): Unit { * Throws an [IllegalStateException] if the [value] is null. Otherwise * returns the not null value. */ -public fun checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null" } +@kotlin.internal.InlineOnly +public inline fun checkNotNull(value: T?): T = checkNotNull(value) { "Required value was null" } /** * Throws an [IllegalStateException] with the result of calling [lazyMessage] if the [value] is null. Otherwise * returns the not null value. */ +@kotlin.internal.InlineOnly public inline fun checkNotNull(value: T?, lazyMessage: () -> Any): T { if (value == null) { val message = lazyMessage() @@ -85,4 +92,5 @@ public inline fun checkNotNull(value: T?, lazyMessage: () -> Any): T { * * @sample test.collections.PreconditionsTest.error */ -public fun error(message: Any): Nothing = throw IllegalStateException(message.toString()) +@kotlin.internal.InlineOnly +public inline fun error(message: Any): Nothing = throw IllegalStateException(message.toString()) diff --git a/libraries/stdlib/src/kotlin/util/Standard.kt b/libraries/stdlib/src/kotlin/util/Standard.kt index c8d7c86ffa6..e34edd70489 100644 --- a/libraries/stdlib/src/kotlin/util/Standard.kt +++ b/libraries/stdlib/src/kotlin/util/Standard.kt @@ -10,38 +10,46 @@ public class NotImplementedError(message: String = "An operation is not implemen /** * Always throws [NotImplementedError] stating that operation is not implemented. */ -public fun TODO(): Nothing = throw NotImplementedError() + +@kotlin.internal.InlineOnly +public inline fun TODO(): Nothing = throw NotImplementedError() /** * Always throws [NotImplementedError] stating that operation is not implemented. * * @param reason a string explaining why the implementation is missing. */ -public fun TODO(reason: String): Nothing = throw NotImplementedError("An operation is not implemented: $reason") +@kotlin.internal.InlineOnly +public inline fun TODO(reason: String): Nothing = throw NotImplementedError("An operation is not implemented: $reason") /** * Calls the specified function [block] and returns its result. */ +@kotlin.internal.InlineOnly public inline fun run(block: () -> R): R = block() /** * Calls the specified function [block] with `this` value as its receiver and returns its result. */ +@kotlin.internal.InlineOnly public inline fun T.run(block: T.() -> R): R = block() /** * Calls the specified function [block] with the given [receiver] as its receiver and returns its result. */ +@kotlin.internal.InlineOnly public inline fun with(receiver: T, block: T.() -> R): R = receiver.block() /** * Calls the specified function [block] with `this` value as its receiver and returns `this` value. */ +@kotlin.internal.InlineOnly public inline fun T.apply(block: T.() -> Unit): T { block(); return this } /** * Calls the specified function [block] with `this` value as its argument and returns its result. */ +@kotlin.internal.InlineOnly public inline fun T.let(block: (T) -> R): R = block(this) diff --git a/libraries/stdlib/src/kotlin/util/StandardJVM.kt b/libraries/stdlib/src/kotlin/util/StandardJVM.kt index 803613983ed..777ef31d29e 100644 --- a/libraries/stdlib/src/kotlin/util/StandardJVM.kt +++ b/libraries/stdlib/src/kotlin/util/StandardJVM.kt @@ -9,26 +9,20 @@ import java.io.PrintWriter /** * Prints the stack trace of this throwable to the standard output. */ -public fun Throwable.printStackTrace(): Unit { - val jlt = this as java.lang.Throwable - jlt.printStackTrace() -} +@kotlin.internal.InlineOnly +public inline fun Throwable.printStackTrace(): Unit = (this as java.lang.Throwable).printStackTrace() /** * Prints the stack trace of this throwable to the specified [writer]. */ -public fun Throwable.printStackTrace(writer: PrintWriter): Unit { - val jlt = this as java.lang.Throwable - jlt.printStackTrace(writer) -} +@kotlin.internal.InlineOnly +public inline fun Throwable.printStackTrace(writer: PrintWriter): Unit = (this as java.lang.Throwable).printStackTrace(writer) /** * Prints the stack trace of this throwable to the specified [stream]. */ -public fun Throwable.printStackTrace(stream: PrintStream): Unit { - val jlt = this as java.lang.Throwable - jlt.printStackTrace(stream) -} +@kotlin.internal.InlineOnly +public inline fun Throwable.printStackTrace(stream: PrintStream): Unit = (this as java.lang.Throwable).printStackTrace(stream) /** * Returns an array of stack trace elements representing the stack trace diff --git a/libraries/stdlib/src/kotlin/util/Synchronized.kt b/libraries/stdlib/src/kotlin/util/Synchronized.kt index e36d7c772d2..989e9950528 100644 --- a/libraries/stdlib/src/kotlin/util/Synchronized.kt +++ b/libraries/stdlib/src/kotlin/util/Synchronized.kt @@ -9,6 +9,7 @@ import kotlin.jvm.internal.unsafe.* * Executes the given function [block] while holding the monitor of the given object [lock]. */ @Suppress("DEPRECATION_ERROR") +@kotlin.internal.InlineOnly public inline fun synchronized(lock: Any, block: () -> R): R { monitorEnter(lock) try {