Files
kotlin-fork/runtime
Ilya Matveev 42c4391654 backend: Process 'until MIN_VALUE' in for loops
This patch takes into account a corner case available for loops
over a progression (see backend.native/tests/external/codegen/box/
ranges/forInUntil/forInUntilMinint.kt test):

for (i in 0 until Int.MIN_VALUE) { ... }

Here we cannot use subtraction to obtain a right bound of the loop
due to an overflow. Instead we consider any loop with MIN_VALUE in
it's right bound as empty loop. Such behaviour is similar to the one
of 'until' method.

So now the empty check for a loops with 'until' call:

for (i in first until bound) { ... }

is as follows:

val last = getProgressionLast(first, bound, step) // Only if step==1
if (first <= last && bound > <Int|Long|Char>.MIN_VALUE) {
    do { ... } while(i != last)
}

Further improvements: We can generate a simpler IR for some simple
frequent cases (e.g. for until calls without steps) and eliminate
loops if we can prove that they are empty.
2017-07-25 22:26:17 +07:00
..
2017-07-14 16:44:46 +03:00