Intrinsify 'in' with unsigned ranges

This commit is contained in:
Dmitry Petrov
2018-12-28 16:06:19 +03:00
parent e6e0e9976c
commit b878626919
13 changed files with 227 additions and 1 deletions
@@ -0,0 +1,31 @@
// IGNORE_BACKEND: JVM_IR, JS_IR
// WITH_RUNTIME
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
val M1 = MaxUI.toULong()
val M2 = M1 + 10UL
fun box(): String {
if (0u in 10u downTo 1u) throw AssertionError()
if (1u !in 10u downTo 1u) throw AssertionError()
if (5u !in 10u downTo 1u) throw AssertionError()
if (10u !in 10u downTo 1u) throw AssertionError()
if (20u in 10u downTo 1u) throw AssertionError()
if (0UL in 10UL downTo 1UL) throw AssertionError()
if (1UL !in 10UL downTo 1UL) throw AssertionError()
if (5UL !in 10UL downTo 1UL) throw AssertionError()
if (10UL !in 10UL downTo 1UL) throw AssertionError()
if (20UL in 10UL downTo 1UL) throw AssertionError()
if (0UL in M2 downTo M1) throw AssertionError()
if (1UL in M2 downTo M1) throw AssertionError()
if (10UL in M2 downTo M1) throw AssertionError()
if (M1 !in M2 downTo M1) throw AssertionError()
if (M1+1UL !in M2 downTo M1) throw AssertionError()
if (M2 !in M2 downTo M1) throw AssertionError()
return "OK"
}
@@ -0,0 +1,48 @@
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
const val MaxUL = ULong.MAX_VALUE
const val MinUL = ULong.MIN_VALUE
val M1 = MaxUI.toULong()
val M2 = M1 + 10UL
val u_1_10 = 1u .. 10u
val ul_1_10 = 1UL..10UL
val minUI_maxUI = MinUI..MaxUI
val minUL_maxUL = MinUL..MaxUL
val m1_m2 = M1..M2
fun box(): String {
if (0u in u_1_10) throw AssertionError()
if (1u !in u_1_10) throw AssertionError()
if (5u !in u_1_10) throw AssertionError()
if (10u !in u_1_10) throw AssertionError()
if (20u in u_1_10) throw AssertionError()
if (0UL in ul_1_10) throw AssertionError()
if (1UL !in ul_1_10) throw AssertionError()
if (5UL !in ul_1_10) throw AssertionError()
if (10UL !in ul_1_10) throw AssertionError()
if (20UL in ul_1_10) throw AssertionError()
if (0u !in minUI_maxUI) throw AssertionError()
if (MinUI !in minUI_maxUI) throw AssertionError()
if (MaxUI !in minUI_maxUI) throw AssertionError()
if (0UL !in minUL_maxUL) throw AssertionError()
if (MinUL !in minUL_maxUL) throw AssertionError()
if (MaxUL !in minUL_maxUL) throw AssertionError()
if (0UL in m1_m2) throw AssertionError()
if (1UL in m1_m2) throw AssertionError()
if (10UL in m1_m2) throw AssertionError()
if (M1 !in m1_m2) throw AssertionError()
if (M1+1UL !in m1_m2) throw AssertionError()
if (M2 !in m1_m2) throw AssertionError()
return "OK"
}
@@ -0,0 +1,42 @@
// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
const val MaxUL = ULong.MAX_VALUE
const val MinUL = ULong.MIN_VALUE
val M1 = MaxUI.toULong()
val M2 = M1 + 10UL
fun box(): String {
if (0u in 1u until 10u) throw AssertionError()
if (1u !in 1u until 10u) throw AssertionError()
if (5u !in 1u until 10u) throw AssertionError()
if (10u in 1u until 10u) throw AssertionError()
if (20u in 1u until 10u) throw AssertionError()
if (0UL in 1UL until 10UL) throw AssertionError()
if (1UL !in 1UL until 10UL) throw AssertionError()
if (5UL !in 1UL until 10UL) throw AssertionError()
if (10UL in 1UL until 10UL) throw AssertionError()
if (20UL in 1UL until 10UL) throw AssertionError()
if (0u !in MinUI until MaxUI) throw AssertionError()
if (MinUI !in MinUI until MaxUI) throw AssertionError()
if (MaxUI in MinUI until MaxUI) throw AssertionError()
if (0UL !in MinUL until MaxUL) throw AssertionError()
if (MinUL !in MinUL until MaxUL) throw AssertionError()
if (MaxUL in MinUL until MaxUL) throw AssertionError()
if (0UL in M1 until M2) throw AssertionError()
if (1UL in M1 until M2) throw AssertionError()
if (10UL in M1 until M2) throw AssertionError()
if (M1 !in M1 until M2) throw AssertionError()
if (M1+1UL !in M1 until M2) throw AssertionError()
if (M2 in M1 until M2) throw AssertionError()
return "OK"
}
@@ -0,0 +1,11 @@
// IGNORE_BACKEND: JVM_IR
fun testUIntRangeLiteral(a: UInt, b: UInt) = 42u in a .. b
fun testULongRangeLiteral(a: ULong, b: ULong) = 42UL in a .. b
fun testUIntUntil(a: UInt, b: UInt) = 42u in a until b
fun testULongUntil(a: ULong, b: ULong) = 42UL in a until b
// 0 contains