Make all progression headers inclusive, and decrement last for

last-exclusive progressions (i.e., "until" progressions and loop over
array indices).

This change makes it possible to correctly implement the handling of
"step" progressions. Computing the last element of a stepped progression
requires that the last is inclusive.

Also invert the while loop (into if + do-while) that is used when
lowering for-loops over progressions that cannot overflow. This keeps
the performance characteristics closer to the ForLoopsLowering in
kotlin-native, since the goal is to converge to this shared version.

Also used IrType instead of KotlinType, where possible.

 https://github.com/JetBrains/kotlin/pull/2390
 https://github.com/JetBrains/kotlin/pull/2305
This commit is contained in:
Mark Punzalan
2019-06-14 00:59:47 -07:00
committed by Mikhael Bogdanov
parent 39f6416757
commit de1e27c584
75 changed files with 1873 additions and 377 deletions
@@ -0,0 +1,21 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.test.*
val log = StringBuilder()
fun logged(message: String, value: Int) =
value.also { log.append(message) }
fun box(): String {
var sum = 0
for (i in (logged("start;", 4) downTo logged("end;", 1)).reversed().reversed()) {
sum = sum * 10 + i
}
assertEquals(4321, sum)
assertEquals("start;end;", log.toString())
return "OK"
}
@@ -0,0 +1,21 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.test.*
val log = StringBuilder()
fun logged(message: String, value: Int) =
value.also { log.append(message) }
fun box(): String {
var sum = 0
for (i in (logged("start;", 1)..logged("end;", 4)).reversed().reversed()) {
sum = sum * 10 + i
}
assertEquals(1234, sum)
assertEquals("start;end;", log.toString())
return "OK"
}
@@ -0,0 +1,21 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.test.*
val log = StringBuilder()
fun logged(message: String, value: Int) =
value.also { log.append(message) }
fun box(): String {
var sum = 0
for (i in (logged("start;", 1) until logged("end;", 5)).reversed().reversed()) {
sum = sum * 10 + i
}
assertEquals(1234, sum)
assertEquals("start;end;", log.toString())
return "OK"
}
@@ -3,7 +3,7 @@
import kotlin.test.assertEquals
fun box(): String {
for (ch in (-10).toChar() until '\u0000') {
for (i in Char.MAX_VALUE until Char.MAX_VALUE) {
throw AssertionError("This loop shoud not be executed")
}
return "OK"
@@ -0,0 +1,10 @@
// WITH_RUNTIME
import kotlin.test.assertEquals
fun box(): String {
for (ch in (-10).toChar() until Char.MIN_VALUE) {
throw AssertionError("This loop shoud not be executed")
}
return "OK"
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
import kotlin.test.assertEquals
fun box(): String {
var bound = Char.MIN_VALUE
for (ch in (-10).toChar() until bound) {
throw AssertionError("This loop shoud not be executed")
}
return "OK"
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
import kotlin.test.assertEquals
fun box(): String {
var bound = Int.MIN_VALUE
for (i in 0 until bound) {
throw AssertionError("This loop shoud not be executed")
}
return "OK"
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
import kotlin.test.assertEquals
fun box(): String {
for (i in Long.MAX_VALUE until Long.MAX_VALUE) {
throw AssertionError("This loop shoud not be executed")
}
return "OK"
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
import kotlin.test.assertEquals
fun box(): String {
var bound = Long.MIN_VALUE
for (i in 0 until bound) {
throw AssertionError("This loop shoud not be executed")
}
return "OK"
}