Intrinsify 'in' with unsigned ranges
This commit is contained in:
+2
-1
@@ -47,7 +47,8 @@ abstract class PrimitiveNumberRangeIntrinsicRangeValue(
|
||||
resolvedCallForIn.resultingDescriptor.let {
|
||||
isPrimitiveRangeContains(it) ||
|
||||
isClosedFloatingPointRangeContains(it) ||
|
||||
isPrimitiveNumberRangeExtensionContainsPrimitiveNumber(it)
|
||||
isPrimitiveNumberRangeExtensionContainsPrimitiveNumber(it) ||
|
||||
isUnsignedIntegerRangeContains(it)
|
||||
}
|
||||
|
||||
override fun createIntrinsicInExpressionGenerator(
|
||||
|
||||
@@ -224,6 +224,14 @@ fun isPrimitiveRangeContains(descriptor: CallableDescriptor): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
fun isUnsignedIntegerRangeContains(descriptor: CallableDescriptor): Boolean {
|
||||
if (descriptor.name.asString() != "contains") return false
|
||||
val dispatchReceiverType = descriptor.dispatchReceiverParameter?.type ?: return false
|
||||
if (!isUnsignedRange(dispatchReceiverType)) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun isPrimitiveNumberRangeExtensionContainsPrimitiveNumber(descriptor: CallableDescriptor): Boolean {
|
||||
if (descriptor.name.asString() != "contains") return false
|
||||
|
||||
|
||||
@@ -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
|
||||
+15
@@ -24218,11 +24218,26 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedDownTo.kt")
|
||||
public void testInUnsignedDownTo() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedDownTo.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRange.kt")
|
||||
public void testInUnsignedRange() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||
public void testInUnsignedRangeLiteral() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedUntil.kt")
|
||||
public void testInUnsignedUntil() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||
|
||||
@@ -2885,6 +2885,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/ranges/inOptimizableRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inOptimizableUnsignedRange.kt")
|
||||
public void testInOptimizableUnsignedRange() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/ranges/inOptimizableUnsignedRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUntil.kt")
|
||||
public void testInUntil() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/ranges/inUntil.kt");
|
||||
|
||||
@@ -2885,6 +2885,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/ranges/inOptimizableRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inOptimizableUnsignedRange.kt")
|
||||
public void testInOptimizableUnsignedRange() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/ranges/inOptimizableUnsignedRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUntil.kt")
|
||||
public void testInUntil() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/ranges/inUntil.kt");
|
||||
|
||||
+15
@@ -24218,11 +24218,26 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedDownTo.kt")
|
||||
public void testInUnsignedDownTo() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedDownTo.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRange.kt")
|
||||
public void testInUnsignedRange() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||
public void testInUnsignedRangeLiteral() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedUntil.kt")
|
||||
public void testInUnsignedUntil() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||
|
||||
+15
@@ -24223,11 +24223,26 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedDownTo.kt")
|
||||
public void testInUnsignedDownTo() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedDownTo.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRange.kt")
|
||||
public void testInUnsignedRange() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||
public void testInUnsignedRangeLiteral() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedUntil.kt")
|
||||
public void testInUnsignedUntil() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||
|
||||
+15
@@ -18668,11 +18668,26 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedDownTo.kt")
|
||||
public void testInUnsignedDownTo() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedDownTo.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRange.kt")
|
||||
public void testInUnsignedRange() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||
public void testInUnsignedRangeLiteral() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedUntil.kt")
|
||||
public void testInUnsignedUntil() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||
|
||||
+15
@@ -19718,11 +19718,26 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedDownTo.kt")
|
||||
public void testInUnsignedDownTo() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedDownTo.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRange.kt")
|
||||
public void testInUnsignedRange() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||
public void testInUnsignedRangeLiteral() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inUnsignedUntil.kt")
|
||||
public void testInUnsignedUntil() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||
|
||||
Reference in New Issue
Block a user