Commit Graph

63 Commits

Author SHA1 Message Date
Alexander Udalov
025360edc4 JVM IR: lookup symbols by name in ProgressionHandlers in known classes only
Alternatively, we could improve the lookup utilities and their usages to
always find the exact override of a symbol from
Collection/Iterable/CharSequence/etc, but since we need to load the
original symbol anyway in cases when the loop subject's type is a type
parameter, we might as well simplify everything and always reference the
original symbol.

Also improve exception message and removed unused declarations in
IrBackendUtils.kt.
2019-12-12 14:55:47 +03:00
Mark Punzalan
1a2e09e6a5 ForLoopsLowering: Handle Iterable.withIndex() where the type is a
bounded type parameter.

TODO: Handle Sequences by extending DefaultIterableHandler.
2019-11-27 10:59:34 +01:00
Mark Punzalan
7adffe0007 Handle withIndex() on Iterables (including progressions) and Sequences
in ForLoopsLowering.
2019-11-20 13:02:21 +01:00
Mark Punzalan
a54d9482dd Handle withIndex() on arrays and CharSequences in ForLoopsLowering. 2019-11-20 13:02:21 +01:00
Mark Punzalan
7f803e60b6 Fix typo in forInArrayWithIndex testdata filenames. 2019-11-20 13:02:21 +01:00
Mark Punzalan
f444702cf3 JVM: Always invoke get()/charAt() in optimized for-loop over
CharSequence.withIndex(), even if element variable is unused in
destructuring declaration.

#KT-34779 Fixed
2019-11-08 10:55:09 +03:00
Mark Punzalan
21178a4f1a Fix issue getting the size property from Collection bounded type
parameters, when lowering for-loops over Collection.indices.
2019-11-07 13:43:24 +01:00
Mark Punzalan
de333c18fc JVM_IR: Enable loopVarInterval and forInReversedCollectionIndices
bytecode text tests.
2019-10-29 07:43:37 +01:00
Mark Punzalan
9bb9ab67a7 Add bytecode text tests for ForLoopsLowering. 2019-10-28 15:26:38 +01:00
Mark Punzalan
277cb39e3b Add new tests for step progressions and fix existing tests. 2019-10-28 15:26:38 +01:00
Mads Ager
507857d452 [IR] Support Collection<*>.indices in for loop lowering.
Unmute a couple of tests that are working as intended.
2019-09-18 19:00:17 +02:00
Mads Ager
90a37617a4 [JVM_IR, IR] Remove more needless temporary variables.
Avoid using a separate origin for temporary variables introduced
for for loops. That doesn't add anything and gives one more case
for optimizations to deal with.

Extend the JVM specific optimizations to remove temporary
variables to deal with more cases encountered in for loops
lowering.
2019-09-11 10:07:45 +02:00
Mads Ager
3f28b71509 [IR] Fix issue getting the length property from CharSequence bounded type parameter
Use the class of the subtype of CharSequence when available. When
it is not (for type parameters bounded by CharSequence) call the
CharSequence getter and 'get' method. Using the most specific type
posible fixes the forInStringSpecialized test that expects the
use of INVOKEVIRTUAL and not INVOKEINTERFACE.

Add tests for the type parameter use.
2019-09-03 20:18:03 +02:00
Mads Ager
85b1e0165b [IR] For loop lowering for CharacterSequence.indices. 2019-09-03 13:18:21 +02:00
Mads Ager
8ed1317839 [IR] For loop lowering for iteration over CharacterSequences.
Change-Id: I7aeadfffc80f791ec19a3607e219c1dc4de028db
2019-08-30 09:35:59 +02:00
Mikhael Bogdanov
496765f41e Support target templates in bytecode tests
Avoid test data duplication
2019-07-16 14:08:27 +02:00
Mark Punzalan
de1e27c584 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
2019-07-16 14:08:21 +02:00
Mark Punzalan
1b703448d3 Handle reversed() in ForLoopsLowering.
We get the info for the underlying progression and invert it. For
progressions whose last bound was open (e.g., `until` loop), the
reversed version will have an open first bound and so the induction
variable must be incremented first.

Also unified the way of extracting HeaderInfo out of changed calls
(e.g., `indices.reversed()`), and fixed declaration parents in
ForLoopsLowering.
2019-04-11 08:54:55 +02:00
Mark Punzalan
a0940b1342 Use stricter assertions in for-loop bytecode text tests. 2019-04-04 09:07:19 +02:00
Mark Punzalan
dd65e0876f Simplify loop building by encoding open/closed bound information in the
HeaderInfo object, and modifying the operator in the loop condition.

The "additional emptiness condition" is no longer necessary with this.
The open/closed property was removed from HeaderInfo in an earlier
commit, but bringing it back in to simplify the loop building makes
more sense.

Also expanded tests for evaluation order of range bounds.
2019-04-04 09:07:19 +02:00
Mark Punzalan
7680e7fd56 Use while loop for progressions that cannot overflow (instead of
do-while with enclosing "not empty" check).

Also do not add additional "not empty" condition for `until` loops when
the given bound is a constant != MIN_VALUE.
2019-04-04 09:07:19 +02:00
Mark Punzalan
ba0e016c4e Add bytecode tests for array for-loop iteration. 2019-04-04 09:07:19 +02:00
Mark Punzalan
7afe121238 Eliminated the redundant ForLoopHeader.needsEmptinessCheck property, cast "bound" to progression type if necessary, fixed variable declaration order. 2019-04-04 09:07:19 +02:00
Mark Punzalan
ea9572ad28 Add DefaultProgressionHandler that handles for-loops over
non-specialized progressions, including "step" progressions.

DefaultProgressionHandler uses the "first/last/step" properties of
the progression when building the loop header.
2019-04-04 09:07:19 +02:00
Mark Punzalan
7b153b2b68 Move building of "not empty" condition (used to check if loop is empty)
from ForLoopsLowering into ForLoopHeader, reducing the building logic in
ForLoopsLowering.
2019-04-04 09:07:19 +02:00
Mark Punzalan
409d99a52a Add ForLoopsLowering to JVM phases.
Also deleted StepHandler. Since the HeaderInfo.needLastCalculation is
only set to true for handling step progressions, deleted that property
and all associated logic around it.
2019-04-04 09:07:19 +02:00
Ilmir Usmanov
20e4efaeab Fix test data 2019-02-01 17:33:49 +03:00
Dmitry Petrov
e6e0e9976c Tests for for-in optimization with unsigned ranges 2019-01-10 17:17:51 +03:00
Mads Ager
3a11322506 Enable bytecode text tests for the JVM_IR backend. 2018-12-21 16:20:45 +01:00
Alexander Udalov
f5ff3d2fa9 Remove directives that have no effect from bytecode text tests
All bytecode text tests are run with stdlib in the classpath and only
for JVM backend, therefore directives WITH_RUNTIME, TARGET_BACKEND,
IGNORE_BACKEND are not needed
2018-12-20 12:53:24 +01:00
Mikaël Peltier
be07a348ea Reformat tests 2018-02-15 12:41:33 +03:00
Mikaël Peltier
8676ca34d7 KT-22334 Specialized loops using range such as integer..array.size-1
- Into PrimitiveNumberRangeLiteralRangeValue modifies how bounded
value are created by checking if the high bound range can be modified
to be exclusive instead of inclusive such as the generated code will
be optimized.
- Add black box tests checking that the specialization does not fail
on any kind of arrays.
- Add a bytecode test checking that the code is correctly optimized.

Fix of https://youtrack.jetbrains.com/issue/KT-22334
2018-02-15 12:41:33 +03:00
Dmitry Petrov
40d1925e19 Provide optimized code generation for for-in-withIndex for sequences
#KT-5177 In Progress
2018-01-23 10:55:24 +03:00
Dmitry Petrov
2399a39414 Provide optimized code generation for for-in-withIndex for CharSequences
#KT-5177 In Progress
2018-01-23 10:55:24 +03:00
Dmitry Petrov
9c9e507172 Provide optimized code generation for for-in-withIndex for iterables
#KT-5177 In Progress
2018-01-23 10:55:24 +03:00
Dmitry Petrov
08622b0953 Provide optimized code generation for for-in-withIndex for arrays
#KT-5177 In Progress
2018-01-23 10:55:24 +03:00
Dmitry Petrov
9fa9a8748b Check that qualified const expressions are recognized properly in 'for' 2017-12-14 10:41:51 +03:00
Dmitry Petrov
54cceac99b Intrinsics for 'reversed': until 2017-12-14 10:41:51 +03:00
Dmitry Petrov
5f7460a8c7 Support const-bound counter loop generation for 'downTo' 2017-12-14 10:41:51 +03:00
Dmitry Petrov
a4c29b3587 Support Long and Char in const-bounded counter loop generation
If the loop end value is a compile-time constant (best we can do now),
and it is safe to iterate over a given range using "naive" for loop
(using '<=' or '>=' in loop condition),
generate such loops for Longs and Chars as well Ints (Bytes, Shorts).
2017-12-14 10:41:51 +03:00
Dmitry Petrov
455a1c0f53 Intrinsics for 'reversed': downTo
#KT-21323 In Progress
2017-12-14 10:41:51 +03:00
Dmitry Petrov
64ba811b7f Intrinsics for 'reversed': CharSequence.indices
#KT-21323 In Progress
2017-12-14 10:41:51 +03:00
Dmitry Petrov
7ba73c1635 Intrinsics for 'reversed': collection.indices
#KT-21323 In Progress
2017-12-14 10:41:51 +03:00
Dmitry Petrov
5bcbe25469 Intrinsics for 'reversed': array.indices
#KT-21323 In Progress
2017-12-14 10:41:51 +03:00
Dmitry Petrov
beff4a1b92 Intrinsics for 'reversed': support non-literal range expressions
#KT-21323 In Progress
2017-12-14 10:41:51 +03:00
Dmitry Petrov
821843e13f Intrinsics for 'reversed': generate in-const-bound ranges as countable
#KT-21323 In Progress
2017-12-14 10:41:51 +03:00
Dmitry Petrov
1775f294f4 Intrinsics for 'reversed': infrastructure & primitive range support
#KT-21323 In Progress
2017-12-14 10:41:51 +03:00
Dmitry Petrov
5b8c0d4c3e Optimize for-in-string loops
For-in-string loop can be generated using specialized 'length' and
'charAt' method calls, and with cached string length.
Note that update of the string variable in loop body doesn't affect
loop execution semantics.

 #KT-21322 Fixed Target versions 1.2.20
2017-11-29 10:15:38 +03:00
Dmitry Petrov
b867c46f72 Generate for-in-range loop as counter loop when possible
If an upper bound is a compile-time constant != Int.MAX_VALUE,
we can generate 'for (i in x..N)' as 'for (i in x until N+1)'.
2017-07-27 09:02:26 +03:00
Dmitry Petrov
f558b4238c Use counter loop in intrinsic array constructors
#KT-19149 Fixed Target versions 1.1.5
2017-07-24 10:17:30 +03:00