Add new tests for step progressions and fix existing tests.

This commit is contained in:
Mark Punzalan
2019-06-18 23:07:55 -07:00
committed by max-kammerer
parent 27642514b1
commit 277cb39e3b
215 changed files with 11982 additions and 13 deletions
@@ -2,11 +2,61 @@ fun f() {
for (i in 0..5 step 2) {
}
for (i in 5 downTo 1 step 1) { // suppress optimized code generation for 'for-in-downTo'
// JVM non-IR: `step 1` suppresses optimized code generation for 'for-in-downTo'
// JVM IR: No getProgressionLastElement() call required for `step 1`, equivalent to `5 downTo 1`
for (i in 5 downTo 1 step 1) {
}
}
// JVM non-IR does NOT specifically handle "step" progressions. The stepped progressions in the above code are constructed and their
// first/last/step properties are retrieved.
// JVM IR has an optimized handler for "step" progressions and elides the construction of the stepped progressions.
//
// Expected lowered form of `for (i in 0..5 step 2)`:
//
// // Standard form of loop over progression
// var inductionVar = 0
// val last = getProgressionLastElement(0, 5, 2)
// val step = 2
// if (inductionVar <= last) {
// // Loop is not empty
// do {
// val i = inductionVar
// inductionVar += step
// // Loop body
// } while (i != last)
// }
//
// Expected lowered form of `for (i in 5 downTo 1 step 1)`:
//
// // Standard form of loop over progression
// var inductionVar = 5
// val last = 1
// val step = -1
// if (last <= inductionVar) { // Optimized out in bytecode
// // Loop is not empty
// do {
// val i = inductionVar
// inductionVar += step
// // Loop body
// } while (last <= inductionVar)
// }
// 0 iterator
// JVM_TEMPLATES
// 2 getFirst
// 2 getLast
// 2 getStep
// 2 getStep
// JVM_IR_TEMPLATES
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 0 getStep
// 1 IF_ICMPGT
// 1 IF_ICMPNE
// 1 IF_ICMPLE
// 3 IF
// 1 INVOKESTATIC kotlin/internal/ProgressionUtilKt.getProgressionLastElement \(III\)I
@@ -0,0 +1,20 @@
fun foo() {
for (i in 1..2 step 4) {}
}
// JVM non-IR does NOT specifically handle "step" progressions. The stepped progression in the above code are constructed and its
// first/last/step properties are retrieved.
// JVM IR has an optimized handler for "step" progressions and elides the construction of the stepped progressions.
// JVM_TEMPLATES
// 1 INVOKEVIRTUAL kotlin/ranges/IntProgression.getFirst \(\)I
// 1 getFirst
// 1 INVOKEVIRTUAL kotlin/ranges/IntProgression.getLast \(\)I
// 1 getLast
// 1 INVOKEVIRTUAL kotlin/ranges/IntProgression.getStep \(\)I
// 1 getStep
// JVM_IR_TEMPLATES
// 0 getFirst
// 0 getLast
// 0 getStep
+3 -11
View File
@@ -1,18 +1,10 @@
fun Int.until(other: Int) = this..other - 1
fun foo() {
val range = 1 until 2
for (i in range) {
}
for (i in 1..2 step 4) {}
for (i in range) {}
}
// 1 INVOKEVIRTUAL kotlin/ranges/IntRange.getFirst \(\)I
// 0 INVOKEVIRTUAL kotlin/ranges/IntRange.getFirst \(\)Ljava/lang/Integer;
// 1 getFirst
// 1 INVOKEVIRTUAL kotlin/ranges/IntRange.getLast \(\)I
// 0 INVOKEVIRTUAL kotlin/ranges/IntRange.getLast \(\)Ljava/lang/Integer;
// 1 INVOKEVIRTUAL kotlin/ranges/IntProgression.getFirst \(\)I
// 0 INVOKEVIRTUAL kotlin/ranges/IntProgression.getFirst \(\)Ljava/lang/Integer;
// 1 INVOKEVIRTUAL kotlin/ranges/IntProgression.getLast \(\)I
// 0 INVOKEVIRTUAL kotlin/ranges/IntProgression.getLast \(\)Ljava/lang/Integer;
// 1 getLast