[JS] Mark necessary methods that must be evaluated at compile-time

It includes methods and properties from Boolean, Char, String,
Enum and KCallable.
This commit is contained in:
Ivan Kylchik
2023-02-02 12:18:49 +01:00
committed by Space Team
parent fcd3fe4fe3
commit 695229e288
10 changed files with 252 additions and 82 deletions
+60
View File
@@ -44,6 +44,7 @@ public class Long internal constructor(
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun compareTo(other: Byte): Int = compareTo(other.toLong())
/**
@@ -51,6 +52,7 @@ public class Long internal constructor(
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun compareTo(other: Short): Int = compareTo(other.toLong())
/**
@@ -58,6 +60,7 @@ public class Long internal constructor(
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun compareTo(other: Int): Int = compareTo(other.toLong())
/**
@@ -65,6 +68,7 @@ public class Long internal constructor(
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
@kotlin.internal.IntrinsicConstEvaluation
public override operator fun compareTo(other: Long): Int = compare(other)
/**
@@ -72,6 +76,7 @@ public class Long internal constructor(
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun compareTo(other: Float): Int = toFloat().compareTo(other)
/**
@@ -79,78 +84,103 @@ public class Long internal constructor(
* Returns zero if this value is equal to the specified other value, a negative number if it's less than other,
* or a positive number if it's greater than other.
*/
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun compareTo(other: Double): Int = toDouble().compareTo(other)
/** Adds the other value to this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun plus(other: Byte): Long = plus(other.toLong())
/** Adds the other value to this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun plus(other: Short): Long = plus(other.toLong())
/** Adds the other value to this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun plus(other: Int): Long = plus(other.toLong())
/** Adds the other value to this value. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun plus(other: Long): Long = add(other)
/** Adds the other value to this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun plus(other: Float): Float = toFloat() + other
/** Adds the other value to this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun plus(other: Double): Double = toDouble() + other
/** Subtracts the other value from this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun minus(other: Byte): Long = minus(other.toLong())
/** Subtracts the other value from this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun minus(other: Short): Long = minus(other.toLong())
/** Subtracts the other value from this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun minus(other: Int): Long = minus(other.toLong())
/** Subtracts the other value from this value. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun minus(other: Long): Long = subtract(other)
/** Subtracts the other value from this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun minus(other: Float): Float = toFloat() - other
/** Subtracts the other value from this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun minus(other: Double): Double = toDouble() - other
/** Multiplies this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun times(other: Byte): Long = times(other.toLong())
/** Multiplies this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun times(other: Short): Long = times(other.toLong())
/** Multiplies this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun times(other: Int): Long = times(other.toLong())
/** Multiplies this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun times(other: Long): Long = multiply(other)
/** Multiplies this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun times(other: Float): Float = toFloat() * other
/** Multiplies this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun times(other: Double): Double = toDouble() * other
/** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun div(other: Byte): Long = div(other.toLong())
/** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun div(other: Short): Long = div(other.toLong())
/** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun div(other: Int): Long = div(other.toLong())
/** Divides this value by the other value, truncating the result to an integer that is closer to zero. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun div(other: Long): Long = divide(other)
/** Divides this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun div(other: Float): Float = toFloat() / other
/** Divides this value by the other value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun div(other: Double): Double = toDouble() / other
/**
@@ -159,6 +189,7 @@ public class Long internal constructor(
* The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
*/
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun rem(other: Byte): Long = rem(other.toLong())
/**
@@ -167,6 +198,7 @@ public class Long internal constructor(
* The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
*/
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun rem(other: Short): Long = rem(other.toLong())
/**
@@ -175,6 +207,7 @@ public class Long internal constructor(
* The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
*/
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun rem(other: Int): Long = rem(other.toLong())
/**
@@ -183,6 +216,7 @@ public class Long internal constructor(
* The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
*/
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public operator fun rem(other: Long): Long = modulo(other)
/**
@@ -191,6 +225,7 @@ public class Long internal constructor(
* The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
*/
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun rem(other: Float): Float = toFloat() % other
/**
@@ -199,6 +234,7 @@ public class Long internal constructor(
* The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
*/
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun rem(other: Double): Double = toDouble() % other
/**
@@ -216,9 +252,11 @@ public class Long internal constructor(
public operator fun dec(): Long = this - 1L
/** Returns this value. */
@kotlin.internal.IntrinsicConstEvaluation
public inline operator fun unaryPlus(): Long = this
/** Returns the negative of this value. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun unaryMinus(): Long = inv() + 1L
/** Creates a range from this value to the specified [other] value. */
@@ -275,6 +313,7 @@ public class Long internal constructor(
* Note that only the six lowest-order bits of the [bitCount] are used as the shift distance.
* The shift distance actually used is therefore always in the range `0..63`.
*/
@kotlin.internal.IntrinsicConstEvaluation
public infix fun shl(bitCount: Int): Long = shiftLeft(bitCount)
/**
@@ -283,6 +322,7 @@ public class Long internal constructor(
* Note that only the six lowest-order bits of the [bitCount] are used as the shift distance.
* The shift distance actually used is therefore always in the range `0..63`.
*/
@kotlin.internal.IntrinsicConstEvaluation
public infix fun shr(bitCount: Int): Long = shiftRight(bitCount)
/**
@@ -291,28 +331,46 @@ public class Long internal constructor(
* Note that only the six lowest-order bits of the [bitCount] are used as the shift distance.
* The shift distance actually used is therefore always in the range `0..63`.
*/
@kotlin.internal.IntrinsicConstEvaluation
public infix fun ushr(bitCount: Int): Long = shiftRightUnsigned(bitCount)
/** Performs a bitwise AND operation between the two values. */
@kotlin.internal.IntrinsicConstEvaluation
public infix fun and(other: Long): Long = Long(low and other.low, high and other.high)
/** Performs a bitwise OR operation between the two values. */
@kotlin.internal.IntrinsicConstEvaluation
public infix fun or(other: Long): Long = Long(low or other.low, high or other.high)
/** Performs a bitwise XOR operation between the two values. */
@kotlin.internal.IntrinsicConstEvaluation
public infix fun xor(other: Long): Long = Long(low xor other.low, high xor other.high)
/** Inverts the bits in this value. */
@kotlin.internal.IntrinsicConstEvaluation
public fun inv(): Long = Long(low.inv(), high.inv())
@kotlin.internal.IntrinsicConstEvaluation
public override fun toByte(): Byte = low.toByte()
@Deprecated("Direct conversion to Char is deprecated. Use toInt().toChar() or Char constructor instead.", ReplaceWith("this.toInt().toChar()"))
@DeprecatedSinceKotlin(warningSince = "1.5", errorSince = "2.3")
@kotlin.internal.IntrinsicConstEvaluation
public override fun toChar(): Char = low.toChar()
@kotlin.internal.IntrinsicConstEvaluation
public override fun toShort(): Short = low.toShort()
@kotlin.internal.IntrinsicConstEvaluation
public override fun toInt(): Int = low
@kotlin.internal.IntrinsicConstEvaluation
public override fun toLong(): Long = this
@kotlin.internal.IntrinsicConstEvaluation
public override fun toFloat(): Float = toDouble().toFloat()
@kotlin.internal.IntrinsicConstEvaluation
public override fun toDouble(): Double = toNumber()
// This method is used by JavaScript to convert objects of type Long to primitives.
@@ -324,9 +382,11 @@ public class Long internal constructor(
@JsName("valueOf")
internal fun valueOf() = toDouble()
@kotlin.internal.IntrinsicConstEvaluation
override fun equals(other: Any?): Boolean = other is Long && equalsLong(other)
override fun hashCode(): Int = hashCode(this)
@kotlin.internal.IntrinsicConstEvaluation
override fun toString(): String = this.toStringImpl(radix = 10)
}