diff --git a/generators/builtins/unsignedTypes.kt b/generators/builtins/unsignedTypes.kt index 96766d46b6f..621da2b8cbc 100644 --- a/generators/builtins/unsignedTypes.kt +++ b/generators/builtins/unsignedTypes.kt @@ -42,6 +42,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns out.println() out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")") + out.println("@SinceKotlin(\"1.3\")") out.println("public inline class $className internal constructor(private val data: $storageType) : Comparable<$className> {") out.println() out.println(""" companion object { @@ -196,6 +197,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns for (otherType in UnsignedType.values()) { val otherSigned = otherType.asSigned.capitalized val thisSigned = type.asSigned.capitalized + out.println("@SinceKotlin(\"1.3\")") out.print("public fun $otherSigned.to$className(): $className = ") out.println(when { otherType < type -> "$className(this.to$thisSigned() and ${otherType.mask})" @@ -238,6 +240,7 @@ class UnsignedIteratorsGenerator(out: PrintWriter) : BuiltInsSourceGenerator(out for (type in UnsignedType.values()) { val s = type.capitalized out.println("/** An iterator over a sequence of values of type `$s`. */") + out.println("@SinceKotlin(\"1.3\")") out.println("public abstract class ${s}Iterator : Iterator<$s> {") // TODO: Sort modifiers out.println(" override final fun next() = next$s()") @@ -258,6 +261,7 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn val storageArrayType = storageElementType + "Array" override fun generateBody() { out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")") + out.println("@SinceKotlin(\"1.3\")") out.println("public inline class $arrayType internal constructor(private val storage: $storageArrayType) : Collection<$elementType> {") out.println( """ @@ -290,12 +294,14 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn out.println("}") - out.println(""" -public /*inline*/ fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType { + out.println() + out.println("@SinceKotlin(\"1.3\")") + out.println("""public /*inline*/ fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType { return $arrayType($storageArrayType(size) { index -> init(index).to$storageElementType() }) } @Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE") +@SinceKotlin("1.3") public fun $arrayTypeOf(vararg elements: $elementType): $arrayType { return $arrayType(elements.size) { index -> elements[index] } }""" @@ -322,6 +328,7 @@ import kotlin.internal.* /** * A range of values of type `$elementType`. */ +@SinceKotlin("1.3") public class ${elementType}Range(start: $elementType, endInclusive: $elementType) : ${elementType}Progression(start, endInclusive, 1), ClosedRange<${elementType}> { override val start: $elementType get() = first override val endInclusive: $elementType get() = last @@ -348,6 +355,7 @@ public class ${elementType}Range(start: $elementType, endInclusive: $elementType /** * A progression of values of type `$elementType`. */ +@SinceKotlin("1.3") public open class ${elementType}Progression internal constructor( start: $elementType, @@ -403,6 +411,7 @@ internal constructor( * An iterator over a progression of values of type `$elementType`. * @property step the number by which the value is incremented on each step. */ +@SinceKotlin("1.3") private class ${elementType}ProgressionIterator(first: $elementType, last: $elementType, step: $stepType) : ${elementType}Iterator() { private val finalElement = last private var hasNext: Boolean = if (step > 0) first <= last else first >= last diff --git a/libraries/stdlib/common/build.gradle b/libraries/stdlib/common/build.gradle index 98cec5a4ce7..8e7225aa2e1 100644 --- a/libraries/stdlib/common/build.gradle +++ b/libraries/stdlib/common/build.gradle @@ -64,6 +64,8 @@ compileKotlinCommon { compileUnsignedKotlinCommon { kotlinOptions { + languageVersion = "1.3" + apiVersion = "1.3" freeCompilerArgs += [ "-XXLanguage:+InlineClasses" ] diff --git a/libraries/stdlib/jvm/build.gradle b/libraries/stdlib/jvm/build.gradle index 768d5cb731f..b3f038b8c58 100644 --- a/libraries/stdlib/jvm/build.gradle +++ b/libraries/stdlib/jvm/build.gradle @@ -209,6 +209,8 @@ compileCoroutinesKotlin { compileUnsignedKotlin { kotlinOptions { + languageVersion = "1.3" + apiVersion = "1.3" freeCompilerArgs += [ "-XXLanguage:+InlineClasses" ] diff --git a/libraries/stdlib/unsigned/src/kotlin/UByte.kt b/libraries/stdlib/unsigned/src/kotlin/UByte.kt index d53f29bcdb5..8d26a29abb0 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UByte.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UByte.kt @@ -10,6 +10,7 @@ package kotlin import kotlin.experimental.* @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class UByte internal constructor(private val data: Byte) : Comparable { companion object { @@ -128,7 +129,11 @@ public inline class UByte internal constructor(private val data: Byte) : Compara } +@SinceKotlin("1.3") public fun Byte.toUByte(): UByte = UByte(this) +@SinceKotlin("1.3") public fun Short.toUByte(): UByte = UByte(this.toByte()) +@SinceKotlin("1.3") public fun Int.toUByte(): UByte = UByte(this.toByte()) +@SinceKotlin("1.3") public fun Long.toUByte(): UByte = UByte(this.toByte()) diff --git a/libraries/stdlib/unsigned/src/kotlin/UByteArray.kt b/libraries/stdlib/unsigned/src/kotlin/UByteArray.kt index 6865e9f33f0..20cc92f0bc4 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UByteArray.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UByteArray.kt @@ -8,6 +8,7 @@ package kotlin @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class UByteArray internal constructor(private val storage: ByteArray) : Collection { /** Returns the array element at the given [index]. This method can be called using the index operator. */ @@ -37,11 +38,13 @@ public inline class UByteArray internal constructor(private val storage: ByteArr override fun isEmpty(): Boolean = this.storage.size == 0 } +@SinceKotlin("1.3") public /*inline*/ fun UByteArray(size: Int, init: (Int) -> UByte): UByteArray { return UByteArray(ByteArray(size) { index -> init(index).toByte() }) } @Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE") +@SinceKotlin("1.3") public fun ubyteArrayOf(vararg elements: UByte): UByteArray { return UByteArray(elements.size) { index -> elements[index] } } diff --git a/libraries/stdlib/unsigned/src/kotlin/UInt.kt b/libraries/stdlib/unsigned/src/kotlin/UInt.kt index 95b8d20b092..476f95c569b 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UInt.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UInt.kt @@ -10,6 +10,7 @@ package kotlin import kotlin.experimental.* @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class UInt internal constructor(private val data: Int) : Comparable { companion object { @@ -132,7 +133,11 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl } +@SinceKotlin("1.3") public fun Byte.toUInt(): UInt = UInt(this.toInt() and 0xFF) +@SinceKotlin("1.3") public fun Short.toUInt(): UInt = UInt(this.toInt() and 0xFFFF) +@SinceKotlin("1.3") public fun Int.toUInt(): UInt = UInt(this) +@SinceKotlin("1.3") public fun Long.toUInt(): UInt = UInt(this.toInt()) diff --git a/libraries/stdlib/unsigned/src/kotlin/UIntArray.kt b/libraries/stdlib/unsigned/src/kotlin/UIntArray.kt index 840c3cb8fde..c76071bd7da 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UIntArray.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UIntArray.kt @@ -8,6 +8,7 @@ package kotlin @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class UIntArray internal constructor(private val storage: IntArray) : Collection { /** Returns the array element at the given [index]. This method can be called using the index operator. */ @@ -37,11 +38,13 @@ public inline class UIntArray internal constructor(private val storage: IntArray override fun isEmpty(): Boolean = this.storage.size == 0 } +@SinceKotlin("1.3") public /*inline*/ fun UIntArray(size: Int, init: (Int) -> UInt): UIntArray { return UIntArray(IntArray(size) { index -> init(index).toInt() }) } @Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE") +@SinceKotlin("1.3") public fun uintArrayOf(vararg elements: UInt): UIntArray { return UIntArray(elements.size) { index -> elements[index] } } diff --git a/libraries/stdlib/unsigned/src/kotlin/UIntRange.kt b/libraries/stdlib/unsigned/src/kotlin/UIntRange.kt index a2c81cd36e0..9081032fcf2 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UIntRange.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UIntRange.kt @@ -14,6 +14,7 @@ import kotlin.internal.* /** * A range of values of type `UInt`. */ +@SinceKotlin("1.3") public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start, endInclusive, 1), ClosedRange { override val start: UInt get() = first override val endInclusive: UInt get() = last @@ -40,6 +41,7 @@ public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start, /** * A progression of values of type `UInt`. */ +@SinceKotlin("1.3") public open class UIntProgression internal constructor( start: UInt, @@ -95,6 +97,7 @@ internal constructor( * An iterator over a progression of values of type `UInt`. * @property step the number by which the value is incremented on each step. */ +@SinceKotlin("1.3") private class UIntProgressionIterator(first: UInt, last: UInt, step: Int) : UIntIterator() { private val finalElement = last private var hasNext: Boolean = if (step > 0) first <= last else first >= last diff --git a/libraries/stdlib/unsigned/src/kotlin/UIterators.kt b/libraries/stdlib/unsigned/src/kotlin/UIterators.kt index a35614b9385..18bd7aba9af 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UIterators.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UIterators.kt @@ -8,6 +8,7 @@ package kotlin.collections /** An iterator over a sequence of values of type `UByte`. */ +@SinceKotlin("1.3") public abstract class UByteIterator : Iterator { override final fun next() = nextUByte() @@ -16,6 +17,7 @@ public abstract class UByteIterator : Iterator { } /** An iterator over a sequence of values of type `UShort`. */ +@SinceKotlin("1.3") public abstract class UShortIterator : Iterator { override final fun next() = nextUShort() @@ -24,6 +26,7 @@ public abstract class UShortIterator : Iterator { } /** An iterator over a sequence of values of type `UInt`. */ +@SinceKotlin("1.3") public abstract class UIntIterator : Iterator { override final fun next() = nextUInt() @@ -32,6 +35,7 @@ public abstract class UIntIterator : Iterator { } /** An iterator over a sequence of values of type `ULong`. */ +@SinceKotlin("1.3") public abstract class ULongIterator : Iterator { override final fun next() = nextULong() diff --git a/libraries/stdlib/unsigned/src/kotlin/ULong.kt b/libraries/stdlib/unsigned/src/kotlin/ULong.kt index 6cedd768c09..fcf0cf14d22 100644 --- a/libraries/stdlib/unsigned/src/kotlin/ULong.kt +++ b/libraries/stdlib/unsigned/src/kotlin/ULong.kt @@ -10,6 +10,7 @@ package kotlin import kotlin.experimental.* @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class ULong internal constructor(private val data: Long) : Comparable { companion object { @@ -132,7 +133,11 @@ public inline class ULong internal constructor(private val data: Long) : Compara } +@SinceKotlin("1.3") public fun Byte.toULong(): ULong = ULong(this.toLong() and 0xFF) +@SinceKotlin("1.3") public fun Short.toULong(): ULong = ULong(this.toLong() and 0xFFFF) +@SinceKotlin("1.3") public fun Int.toULong(): ULong = ULong(this.toLong() and 0xFFFF_FFFF) +@SinceKotlin("1.3") public fun Long.toULong(): ULong = ULong(this) diff --git a/libraries/stdlib/unsigned/src/kotlin/ULongArray.kt b/libraries/stdlib/unsigned/src/kotlin/ULongArray.kt index 4a8464b368f..6d50d735667 100644 --- a/libraries/stdlib/unsigned/src/kotlin/ULongArray.kt +++ b/libraries/stdlib/unsigned/src/kotlin/ULongArray.kt @@ -8,6 +8,7 @@ package kotlin @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class ULongArray internal constructor(private val storage: LongArray) : Collection { /** Returns the array element at the given [index]. This method can be called using the index operator. */ @@ -37,11 +38,13 @@ public inline class ULongArray internal constructor(private val storage: LongArr override fun isEmpty(): Boolean = this.storage.size == 0 } +@SinceKotlin("1.3") public /*inline*/ fun ULongArray(size: Int, init: (Int) -> ULong): ULongArray { return ULongArray(LongArray(size) { index -> init(index).toLong() }) } @Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE") +@SinceKotlin("1.3") public fun ulongArrayOf(vararg elements: ULong): ULongArray { return ULongArray(elements.size) { index -> elements[index] } } diff --git a/libraries/stdlib/unsigned/src/kotlin/ULongRange.kt b/libraries/stdlib/unsigned/src/kotlin/ULongRange.kt index d727edc3b8a..ca77502cf6c 100644 --- a/libraries/stdlib/unsigned/src/kotlin/ULongRange.kt +++ b/libraries/stdlib/unsigned/src/kotlin/ULongRange.kt @@ -14,6 +14,7 @@ import kotlin.internal.* /** * A range of values of type `ULong`. */ +@SinceKotlin("1.3") public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(start, endInclusive, 1), ClosedRange { override val start: ULong get() = first override val endInclusive: ULong get() = last @@ -40,6 +41,7 @@ public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(st /** * A progression of values of type `ULong`. */ +@SinceKotlin("1.3") public open class ULongProgression internal constructor( start: ULong, @@ -95,6 +97,7 @@ internal constructor( * An iterator over a progression of values of type `ULong`. * @property step the number by which the value is incremented on each step. */ +@SinceKotlin("1.3") private class ULongProgressionIterator(first: ULong, last: ULong, step: Long) : ULongIterator() { private val finalElement = last private var hasNext: Boolean = if (step > 0) first <= last else first >= last diff --git a/libraries/stdlib/unsigned/src/kotlin/UProgressionUtil.kt b/libraries/stdlib/unsigned/src/kotlin/UProgressionUtil.kt index a9fdc454e4f..971f4974d5d 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UProgressionUtil.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UProgressionUtil.kt @@ -35,6 +35,7 @@ private fun differenceModulo(a: ULong, b: ULong, c: ULong): ULong { * @suppress */ @PublishedApi +@SinceKotlin("1.3") internal fun getProgressionLastElement(start: UInt, end: UInt, step: Int): UInt = when { step > 0 -> if (start >= end) end else end - differenceModulo(end, start, step.toUInt()) step < 0 -> if (start <= end) end else end + differenceModulo(start, end, (-step).toUInt()) @@ -58,6 +59,7 @@ internal fun getProgressionLastElement(start: UInt, end: UInt, step: Int): UInt * @suppress */ @PublishedApi +@SinceKotlin("1.3") internal fun getProgressionLastElement(start: ULong, end: ULong, step: Long): ULong = when { step > 0 -> if (start >= end) end else end - differenceModulo(end, start, step.toULong()) step < 0 -> if (start <= end) end else end + differenceModulo(start, end, (-step).toULong()) diff --git a/libraries/stdlib/unsigned/src/kotlin/UShort.kt b/libraries/stdlib/unsigned/src/kotlin/UShort.kt index 3b4e2ec08d7..0aa5808ebee 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UShort.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UShort.kt @@ -10,6 +10,7 @@ package kotlin import kotlin.experimental.* @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class UShort internal constructor(private val data: Short) : Comparable { companion object { @@ -128,7 +129,11 @@ public inline class UShort internal constructor(private val data: Short) : Compa } +@SinceKotlin("1.3") public fun Byte.toUShort(): UShort = UShort(this.toShort() and 0xFF) +@SinceKotlin("1.3") public fun Short.toUShort(): UShort = UShort(this) +@SinceKotlin("1.3") public fun Int.toUShort(): UShort = UShort(this.toShort()) +@SinceKotlin("1.3") public fun Long.toUShort(): UShort = UShort(this.toShort()) diff --git a/libraries/stdlib/unsigned/src/kotlin/UShortArray.kt b/libraries/stdlib/unsigned/src/kotlin/UShortArray.kt index 7be43d7bb7a..f0de1806fef 100644 --- a/libraries/stdlib/unsigned/src/kotlin/UShortArray.kt +++ b/libraries/stdlib/unsigned/src/kotlin/UShortArray.kt @@ -8,6 +8,7 @@ package kotlin @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS") +@SinceKotlin("1.3") public inline class UShortArray internal constructor(private val storage: ShortArray) : Collection { /** Returns the array element at the given [index]. This method can be called using the index operator. */ @@ -37,11 +38,13 @@ public inline class UShortArray internal constructor(private val storage: ShortA override fun isEmpty(): Boolean = this.storage.size == 0 } +@SinceKotlin("1.3") public /*inline*/ fun UShortArray(size: Int, init: (Int) -> UShort): UShortArray { return UShortArray(ShortArray(size) { index -> init(index).toShort() }) } @Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE") +@SinceKotlin("1.3") public fun ushortArrayOf(vararg elements: UShort): UShortArray { return UShortArray(elements.size) { index -> elements[index] } }