diff --git a/generators/builtins/unsignedTypes.kt b/generators/builtins/unsignedTypes.kt index 0be46e70c58..d2184cb904f 100644 --- a/generators/builtins/unsignedTypes.kt +++ b/generators/builtins/unsignedTypes.kt @@ -100,11 +100,12 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns * 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. */""") - if (otherType != type) - out.println(" @kotlin.internal.InlineOnly") + out.println(" @kotlin.internal.InlineOnly") + if (otherType == type) + out.println(""" @Suppress("OVERRIDE_BY_INLINE")""") out.print(" public ") - if (otherType == type) out.print("override ") else out.print("inline ") - out.print("operator fun compareTo(other: ${otherType.capitalized}): Int = ") + if (otherType == type) out.print("override ") + out.print("inline operator fun compareTo(other: ${otherType.capitalized}): Int = ") if (otherType == type && maxByDomainCapacity(type, UnsignedType.UINT) == type) { out.println("${className.toLowerCase()}Compare(this.data, other.data)") } else { diff --git a/libraries/stdlib/unsigned/src/kotlin/UByte.kt b/libraries/stdlib/unsigned/src/kotlin/UByte.kt index a8921d72818..8353e55dfcf 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UByte.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UByte.kt @@ -41,7 +41,9 @@ public inline class UByte @PublishedApi internal constructor(@PublishedApi inter * 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. */ - public override operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt()) + @kotlin.internal.InlineOnly + @Suppress("OVERRIDE_BY_INLINE") + public override inline operator fun compareTo(other: UByte): Int = this.toUInt().compareTo(other.toUInt()) /** * Compares this value with the specified value for order. diff --git a/libraries/stdlib/unsigned/src/kotlin/UInt.kt b/libraries/stdlib/unsigned/src/kotlin/UInt.kt index f516386a131..d01aba5e4b0 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UInt.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UInt.kt @@ -57,7 +57,9 @@ public inline class UInt @PublishedApi internal constructor(@PublishedApi intern * 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. */ - public override operator fun compareTo(other: UInt): Int = uintCompare(this.data, other.data) + @kotlin.internal.InlineOnly + @Suppress("OVERRIDE_BY_INLINE") + public override inline operator fun compareTo(other: UInt): Int = uintCompare(this.data, other.data) /** * Compares this value with the specified value for order. diff --git a/libraries/stdlib/unsigned/src/kotlin/ULong.kt b/libraries/stdlib/unsigned/src/kotlin/ULong.kt index 283b8a22c6e..591f7fa4965 100644 --- a/libraries/stdlib/unsigned/src/kotlin/ULong.kt +++ b/libraries/stdlib/unsigned/src/kotlin/ULong.kt @@ -65,7 +65,9 @@ public inline class ULong @PublishedApi internal constructor(@PublishedApi inter * 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. */ - public override operator fun compareTo(other: ULong): Int = ulongCompare(this.data, other.data) + @kotlin.internal.InlineOnly + @Suppress("OVERRIDE_BY_INLINE") + public override inline operator fun compareTo(other: ULong): Int = ulongCompare(this.data, other.data) /** Adds the other value to this value. */ @kotlin.internal.InlineOnly diff --git a/libraries/stdlib/unsigned/src/kotlin/UShort.kt b/libraries/stdlib/unsigned/src/kotlin/UShort.kt index 79e793534dd..578c069eb7f 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UShort.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UShort.kt @@ -49,7 +49,9 @@ public inline class UShort @PublishedApi internal constructor(@PublishedApi inte * 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. */ - public override operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt()) + @kotlin.internal.InlineOnly + @Suppress("OVERRIDE_BY_INLINE") + public override inline operator fun compareTo(other: UShort): Int = this.toUInt().compareTo(other.toUInt()) /** * Compares this value with the specified value for order. diff --git a/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt b/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt index fac74476d93..adfc1bbb269 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UnsignedUtils.kt @@ -6,7 +6,9 @@ @file:UseExperimental(ExperimentalUnsignedTypes::class) package kotlin +@PublishedApi internal fun uintCompare(v1: Int, v2: Int): Int = (v1 xor Int.MIN_VALUE).compareTo(v2 xor Int.MIN_VALUE) +@PublishedApi internal fun ulongCompare(v1: Long, v2: Long): Int = (v1 xor Long.MIN_VALUE).compareTo(v2 xor Long.MIN_VALUE) @PublishedApi diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt index 62a7fb80ce5..7bd6ea0070c 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-stdlib-runtime-merged.txt @@ -208,8 +208,6 @@ public final class kotlin/UByte : java/lang/Comparable { public static final field SIZE_BYTES I public static final synthetic fun box-impl (B)Lkotlin/UByte; public synthetic fun compareTo (Ljava/lang/Object;)I - public fun compareTo-7apg3OU (B)I - public static fun compareTo-7apg3OU (BB)I public static fun constructor-impl (B)B public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (BLjava/lang/Object;)Z @@ -270,8 +268,6 @@ public final class kotlin/UInt : java/lang/Comparable { public static final field SIZE_BYTES I public static final synthetic fun box-impl (I)Lkotlin/UInt; public synthetic fun compareTo (Ljava/lang/Object;)I - public fun compareTo-WZ4Q5Ns (I)I - public static fun compareTo-WZ4Q5Ns (II)I public static fun constructor-impl (I)I public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (ILjava/lang/Object;)Z @@ -332,8 +328,6 @@ public final class kotlin/ULong : java/lang/Comparable { public static final field SIZE_BYTES I public static final synthetic fun box-impl (J)Lkotlin/ULong; public synthetic fun compareTo (Ljava/lang/Object;)I - public fun compareTo-VKZWuLQ (J)I - public static fun compareTo-VKZWuLQ (JJ)I public static fun constructor-impl (J)J public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (JLjava/lang/Object;)Z @@ -394,8 +388,6 @@ public final class kotlin/UShort : java/lang/Comparable { public static final field SIZE_BYTES I public static final synthetic fun box-impl (S)Lkotlin/UShort; public synthetic fun compareTo (Ljava/lang/Object;)I - public fun compareTo-xj2QHRw (S)I - public static fun compareTo-xj2QHRw (SS)I public static fun constructor-impl (S)S public fun equals (Ljava/lang/Object;)Z public static fun equals-impl (SLjava/lang/Object;)Z @@ -464,8 +456,10 @@ public abstract interface annotation class kotlin/UnsafeVariance : java/lang/ann } public final class kotlin/UnsignedKt { + public static final fun uintCompare (II)I public static final fun uintDivide-J1ME1BU (II)I public static final fun uintRemainder-J1ME1BU (II)I + public static final fun ulongCompare (JJ)I public static final fun ulongDivide-eb3DHEI (JJ)J public static final fun ulongRemainder-eb3DHEI (JJ)J }