Commit Graph

104 Commits

Author SHA1 Message Date
Nikita Nazarov 407448d8e3 [JVM] Implement new inlined variable naming format
^KT-65478 fixed
2024-02-23 23:59:13 +01:00
Ivan Kylchik 8f88f08573 [FIR] Use correct source for implicit this receiver
#KT-57489 Fixed
#KT-56139 Fixed
#KT-56755 Fixed
2023-06-23 07:23:39 +00:00
Ilya Chernikov 5b3816cce5 Test infra: refactor IGNORE_BACKEND directive
treat it as a general one, introduce *_K1 and *_K2 variants for
more specific ignoring
2022-11-12 16:28:23 +01:00
Ilmir Usmanov f34ae686a0 JVM: Make coroutines spilling tests runtime
instead of bytecode text ones. Check the content of continuation
object instead of bytecode, since this is less prone to changes during
changes in coroutines codegen.

 #KT-48678
2022-06-27 23:11:40 +02:00
Victor Petukhov fa7809cd80 [FE] Remove BuilderInference annotation from tests 2022-06-21 15:01:56 +02:00
Ilmir Usmanov 7579be6c68 Generate CHECKCAST after ACONST_NULL in coroutines
If we do not do this, the state-machine builder will not know the type
of the ACONST_NULL, defaulting to Object, leading to VerifyError.
Alternatively, we could use LVT to deduce the type, but getting types
from LVT is something I got rid of long time ago, and I have no desire
to return it back.

Generating CHECKCAST hints the state-machine builder the type of the
variable avoiding the issue of VerifyError. However, this CHECKCAST
replaces StrictBasicValue.NULL_VALUE with BasicValue in
OptimizationBasicInterpreter. To preserve optimization on not-spilling
known nulls, introduce BasicValues, which represent typed nulls and
create BasicInterpreter, which is aware of them. This way we have the
best of two worlds - we do not spill known nulls, and we know the type
of ACONST_NULL.

 #KT-51718 Fixed
2022-03-30 14:27:29 +00:00
Dmitry Petrov f4a1e27124 JVM optimize unneeded temporary vals 2021-08-24 18:56:20 +03:00
Dmitry Petrov d8f6d82411 JVM don't optimize temporary vals in old back-end 2021-08-24 18:56:19 +03:00
Dmitry Petrov 939f25333e JVM update testData 2021-08-24 18:56:17 +03:00
Dmitry Petrov 7e943ab757 JVM don't optimize out starting ASTORE of TCB handler 2021-08-24 18:56:14 +03:00
Dmitry Petrov dcbc2ea2b3 JVM infer temporary vals from bytecode 2021-08-24 18:56:13 +03:00
Dmitry Petrov 041773fd25 JVM optimize out temporary variables in bytecode 2021-08-24 18:56:11 +03:00
Ilmir Usmanov ebb340fe68 Do not just merge consequent LVT ranges, but also extend them 2021-08-13 23:12:10 +03:00
Dmitry Petrov bd71fbe982 JVM_IR KT-34594 strip fake variable initialization during inlining 2021-08-03 20:41:31 +03:00
Ilmir Usmanov e870a200c4 Merge consequent LVT records
that is, if LVT record starts where previous one ends, merge them.
 #KT-47749 Fixed
2021-07-19 22:07:16 +00:00
Ilmir Usmanov 5ae01c8b2a Do not duplicate $result in LVT
#KT-47749
2021-07-19 22:07:16 +00:00
Ilmir Usmanov b4d356c5bd Split LVT record for known nulls
Since they are not spilled, the logic for splitting LVT records, that
is applied for spilled variables, was not applied for known nulls.
Fix that by applying the logic to them.
 #KT-47749
2021-07-19 22:07:15 +00:00
Mads Ager 83dddd73b0 Always add a local variable for its live ranges.
There used to be code that extended a previous range instead.
However, that does not work as that extension could have the
local cover code where it does not exists. Since we no longer
extend the range of locals, we should always introduce a new
one even if there was another one for a previous range.
2021-07-19 22:07:14 +00:00
Mads Ager d023966054 [JVM] Fix various undefined locals issues.
CoroutineTransformermethodVisitor attempts to extend the ranges
of local variables in various situations. Probably in an attempt
to give a better debugging experience. However, all of these
range extensions lead to invalid local variable tables where
something is in the local variable table where nothing is in the
corresponding slot.

The code that extends variables to the next suspension point
instead of ending them when they are no longer live has issues
with loops. When resuming and reentering the loop, the locals
table will mention a local that we did not spill and which
is therefore not restored when resuming.

The code that extends local variable table entries if there
are no suspension points between two entries doesn't work
for code such as:

```
var s: String
if (suspendHere() == "OK") {
  s = "OK"
} else {
  s = "FAIL"
}
```

If the local variable ranges are collapsed into one, one of
the branches will have the local defined in the local variable
table before the slot is initialized.
2021-05-26 08:33:34 +02:00
Ilmir Usmanov c4ddf3530d Use GETFIELD instead of unbox-impl inside inline classes
#KT-36783 Fixed
2021-05-12 06:50:06 +00:00
Mads Ager df225c0c7f [JVM] Fix uninitialized locals after coroutine transformation.
The coroutine transformation would leave locals in the local
variable table across the code that reloads local variables from
the continuation on reentry. However, when reentering the function
the local has no value until after the reloads from the
continuation.

This change splits the locals in the local variable table to
avoid such uninitialized locals. A local alive across a
suspension point has its range split in two. One that goes
from the original start to the state label for the restart
after the suspension. The other goes from after the local
has been reloaded from the continuation until the previous
end of the local.
2021-04-30 22:24:03 +02:00
Ilmir Usmanov e79c9a3618 Extend LVT record of alive variables to end of next suspension point
Otherwise, arguments of suspend call become invisible in async stack
trace
 #KT-44714
2021-03-08 23:56:40 +01:00
Ilmir Usmanov b6bb8a576e Make start label of LVT record the point where variable becomes alive
Otherwise, there will be overlapping LVT records, which leads to
removal of the whole LVT by R8.
 #KT-44714 Fixed
2021-03-08 23:56:39 +01:00
Ilmir Usmanov e17b7f01b6 Do not remove dead variables' LVT records
Also, extend liveness of alive variable to nearest suspension points
 #KT-44714
2021-03-08 23:56:36 +01:00
Dmitriy Novozhilov f61a318c9d [Test] Migrate AbstractBytecodeTextTest to new test infrastructure 2021-01-25 17:11:21 +03:00
Steven Schäfer dad10e94aa JVM IR: Mangle names of $$forInline functions 2021-01-08 16:30:18 +01:00
Iaroslav Postovalov 8a7bc2ef6f Rename continuation fields according the convention and count them in IR 2020-12-23 19:45:13 +01:00
Iaroslav Postovalov 6f34f00c61 Do not generate the field for unused parameters in suspend lambdas 2020-12-23 19:45:04 +01:00
Kristoffer Andersen 8a5f260d04 [IR] Align debugging of suspend lambdas with old BE
The existing backend restores LVs and parameters from the suspend lambda
fields used for spilling between suspension points, hence they are
visible in the debugger as local variables, plain and simple.

This PR introduces the same pattern to the IR backend, to bring the
debugging experience in line with the existing backend.

Both backends are still at the mercy of the liveness analysis
performed in the coroutine transformer where a liveness analysis
minimizes live ranges of entries in the LVT. E.g. an unused parameter
will be dropped entirely.

Adjusted existing test expectations accounting for the differences in
LV behavior.
2020-12-12 11:48:47 +01:00
Dmitriy Novozhilov b416c669b0 [TEST] Update testdata due to dropped COMMON_COROUTINE_TEST directive 2020-12-10 01:31:04 +03:00
Georgy Bronnikov d246005891 JVM_IR: fix unbound type parameters in AddContinuationLowering 2020-11-10 17:49:55 +03:00
Ilmir Usmanov 375d92cf67 Merge two consequent records in LVT
Otherwise, atomicfu will be unable to transform atomic variable usages.
2020-10-09 18:36:37 +02:00
Mikhail Glukhikh ac50433e17 Fix failing bytecode text test
In this commit I moved IGNORE_BACKEND_FIR to the end or deleted it
when it was applicable, to preserve correct line numbers
2020-09-29 19:16:42 +03:00
Mark Punzalan 238cc7c257 [FIR] Enable BytecodeText tests for FIR.
143 out of 767 tests (18.6%) are currently failing.
2020-09-29 10:21:21 +03:00
Ilmir Usmanov f22f10febb JVM_IR: Unbox inline classes in suspend functions
if the function can be verified to safely returning unboxed
inline class.
Box the return value on resume path.
2020-09-24 10:08:41 +02:00
Ilmir Usmanov e8a451072e Minor. Add tests with same JvmType in covariant override 2020-09-09 17:43:41 +02:00
Ilmir Usmanov 1c97eafea8 Check for COROUTINE_SUSPENDED inside callable reference
#KT-41429 Fixed
2020-09-09 17:43:37 +02:00
Ilmir Usmanov 023cdd7cd4 Support not boxing inline class of reference class
even if the class is other than Any.
 #KT-41429 In progress
2020-09-09 17:43:34 +02:00
Ilmir Usmanov 8a098545e6 Minor. Add test 2020-08-11 22:10:51 +02:00
Steven Schäfer 53fe30eb45 JVM IR: Don't produce CHECKCASTs on null constants (KT-36650) 2020-08-11 15:13:40 +02:00
Ilmir Usmanov 824991a9dd Minor. Add tests. 2020-08-04 15:42:38 +02:00
Ilmir Usmanov bbd4c21595 Cleanup spilled variables
#KT-16222
2020-08-04 15:42:37 +02:00
Ilmir Usmanov 70e91bd5db Shrink and split LVT records of variables according to their liveness
Otherwise, debugger will show uninitialized values of dead variables
after resume.
 #KT-16222
 #KT-28016 Fixed
 #KT-20571 Fixed
2020-07-29 00:01:10 +02:00
Ilmir Usmanov 60875f96b4 Do not take LVT into account when calculating liveness of variables 2020-07-29 00:01:09 +02:00
Ilmir Usmanov 697c8637ee For all int-like typed variables, use int as field type and coerce
it during spill-unspill.
Coerce int to boolean, otherwise, VerifyError is thrown on android
Completely rewrite SpilledVariableFieldTypesAnalysis... again,
but this time use BasicInterpreter
This way, the analysis both does not use SourceInterpreter and
is in line with the rest on analyses.
2020-07-01 17:26:47 +02:00
Steven Schäfer dc0ef996b7 JVM IR: Implement the new inline class ABI 2020-05-28 18:00:35 +03:00
Dmitry Petrov c165b8d55c JVM: Update IR bytecode text and signature tests 2020-05-20 07:19:30 +03:00
pyos 0037d5a7c8 JVM: erase conditional suspension markers from inline-only functions
Otherwise, the generated bytecode is unnecessarily suboptimal in some
(arguably weird) cases.

In the JVM backend, this was an accidental regression in #3260, as I had
not noticed that effectively inline-only functions were handled by a
separate branch in FunctionCodegen. In JVM_IR, I'm pretty sure the
redundant markers have always been there as `isSuspensionPoint` in
ExpressionCodegen never checked for effectively-inline-only-ness.
2020-04-08 12:31:23 +02:00
pyos 5ed845d0b4 JVM_IR: reuse same bodies for suspend funs and $$forInline versions 2020-04-03 19:51:45 +02:00
Dmitry Petrov 042424d599 KT-27524 Don't box (some) inline classes in suspend fun return
If an inline class is mapped to a reference type (or an array), it's Ok
to treat JVM view on a suspend function as returning a value of
corresponding inline class (although in reality it returns 'Any?'
because of COROUTINE_SUSPENDED).
2020-03-27 18:29:36 +03:00