Commit Graph

73 Commits

Author SHA1 Message Date
Mads Ager 6622846bc1 [JVM IR] Do not put destructuring params or underscores in LVT.
Putting them in the local variable table means that the debugger
needs to have special handling for parameters with specific names.
That forces us to generate mangled names for these.

Instead of also implementing the name mangling for FIR, this
change gets rid of the parameters from the LVT instead.
2021-11-02 15:13:14 +03:00
Mads Ager e9c9d5731e [JVM] Port Stepping and LocalVariable tests to new test infra.
This is in preparation for enabling the tests for FIR which will
be easier to do when the tests are on the new infrastructure.
2021-10-15 20:03:54 +03:00
Dmitry Petrov 7e86f5dcd9 JVM_IR don't use Intrinsics.stringPlus for 2-argument concatenation 2021-10-01 02:59:52 +03:00
Dmitry Petrov ca7ee75f88 JVM replace redundant GOTOs with NOPs to preserve debugging behavior 2021-09-29 19:14:33 +03:00
Alexander Udalov 3ef9649344 Minor, fix test data of localVariables/suspend/mergeLvt.kt
It was incorrectly adapted (by me) in d07070e184.
2021-09-15 00:07:49 +02:00
pyos d07070e184 JVM_IR: avoid redundant accessors in private inline funs
Their call sites are all in the same file, so we can check whether the
declarations used in the inline function are accessible from all the
places where it will be inlined.

 #KT-48736 Fixed
2021-09-14 22:17:10 +02:00
Dmitry Petrov b669de1663 JVM_IR generate range-based loop closer to Java counter loop
KT-48435 KT-48507
2021-09-03 10:38:20 +03:00
Dmitry Petrov 1c1b9547c1 JVM_IR KT-48435 use Java-like counter loop when possible 2021-08-31 16:39:25 +03:00
Dmitry Petrov c30b23ed01 JVM_IR fixes after review 2021-08-24 18:56:22 +03:00
Dmitry Petrov f4dd75e769 JVM_IR don't inline temporary val for 'when' subject 2021-08-24 18:56:21 +03:00
Mads Ager 0b84de31b7 [JVM IR] Generate line number for exception store for finally.
^KT-46451 Fixed
2021-08-20 00:59:55 +02:00
Mads Ager d33b70af1a [JVM IR] Ensure an instruction for the line number for a break.
This ensures that the debugger always has a bytecode offset for
the line number of a break/continue so that you step there and
so that you can set breakpoints there.

The `nop` instruction is optimized out if it has no line number
information.

^KT-46450 Fixed
2021-08-19 15:40:44 +02: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 caa13b33b1 JVM_IR minor: update testdata 2021-07-29 20:45:16 +03:00
Mads Ager c0f5d09759 Copy locals in addition to instructions when inlining finally blocks
^KT-46448 Fixed
2021-07-23 09:11:48 +02:00
Ilmir Usmanov 5517aa36e1 Minor. Add debugger test
#KT-47749
2021-07-19 22:07:17 +00:00
Dmitry Petrov 24fcadb869 JVM don't run CCE on methods without optimizable conditional jumps 2021-07-08 22:11:59 +03:00
Mads Ager ae03e2983d [JVM_IR] Keep track of catch variable gaps.
This ensures that catch variables are not visible in duplicated
finally blocks generated at an exit within the catch variable
scope.

^KT-46449 Fixed
2021-06-15 15:18:59 +02:00
Dmitry Petrov 7a43c2de79 JVM remove dead code during constant condition elimination
This avoids an extra call to 'analyze', which is rather costly.

Update debugger testData: Constant condition
elimination now performs DCE more consistently.
2021-06-03 00:08:27 +03:00
Vasily Levchenko 1ff6dc1275 [kotlin][tests][compiler/testData/debug/stepping] kt-42208 test added. 2021-05-31 11:45:31 +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
Dmitry Petrov 851980e36f JVM_IR KT-45103 optimize direct invoke for lambdas and callable refs 2021-05-18 22:20:12 +03:00
Mads Ager 0c77565104 JVM_IR: Add more local variable tests for finally code. 2021-05-03 07:43:38 +02:00
Mads Ager 6095d8a7fa [JVM] Split the variable range for external finally blocks in inliner
When external finally blocks are inlined none of the current locals
are in scope of the finally block.
2021-05-03 07:43:37 +02:00
Mads Ager 6d9f02cfc6 [JVM_IR] Fix range of locals in connection with finally blocks.
For code such as:

```
try {
  var y = "y"
  for (i in 0 until 1) {
    return y
  }
} finally {
  println("finally")
}
```

The local variables `y` and `i` ended up covering the finally block as
well in the debugger.

This change splits the range of the locals so that they do
not cover the finally block.

This change does not change the inliner to do similar transformations,
so the range of locals is still wrong win finally blocks when inlined
into an inline function. Added a failing test to that effect.
2021-05-03 07:43:37 +02: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
Vasily Levchenko ef2c2c2c9e [kotlin][tests][compiler/testData/debug/stepping] kt-42208 test added. 2021-04-30 18:44:55 +00: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
Alexander Udalov 5480faf5c5 Add tests for issues fixed in JVM IR and other obsolete issues
#KT-6007
 #KT-16445
 #KT-17753
 #KT-22488
 #KT-23881
 #KT-24135
 #KT-26360
 #KT-27427
 #KT-27449
 #KT-27830
 #KT-28042
 #KT-29595
 #KT-30708
 #KT-32793
2021-02-01 18:29:59 +01:00
Kristoffer Andersen 836261ba6e [Test] Ignore test infrastucture sources in debugging tests
This solves no immediate deficiency, but is a to-do that arose as part
of an ongoing effort to port the old, slightly too restrictive
checkLocalVariableTable tests to the more "functional" debugger
infrastructure.

This just shaves a little bit of overhead off the test expectations
and couples them less tightly to the specifics of the test
infrastructure.
2021-01-28 08:09:42 +01:00
Kristoffer Andersen 43b61a618d [IR+Tests] Improve Local Function Debugging Experience
This change improves the debugging experience around local functions
on the IR backend. The changes include moving old
checkLocalVariablesTable (cLVT) tests to the new stepping/local variable
infrastructure in order to refine the tests and further define the
behavior of the two JVM backends, and their differences.

The primary ported test case is cLVT/localFun.kt that documents the
discrepancy in implementation strategy for local functions on the two
backends. The old backend implements local functions as lambdas
assigned to a local variable while the IR backend lifts them out as
static funtions on the surrounding class. The discrepancies and their
consequences are documented in bytecodeListing, idea-stepping,
localVariableTable and debugStepping tests.

The only _code change_ is disabling the captured variable name
mangling for captured variables on the IR backend. Captured variables
are passed as arguments to the static function, so in the debugger,
they really just are local variables. For them to show properly in the
debugger and be detectable by evaluate expression, they simply need no
mangling.

Finally, this change cleans 3 redundant cLVT tests, copyFunction.kt
and destructuringInlineLambda.kt and destructuringInFor.kt, that are
all covered in the new suite. The stepping behavior needs to be made
precise around for loops, but that is an entirely seperate issue.
2021-01-11 18:21:23 +01:00
Kristoffer Andersen 77836f1aa9 [Test] Port checkVariableTable suspend lambda tests
Reveals discrepancy in LVT presence on lambda implementations on the
old and new backend.

The generated code in the constructors of Suspend Lambda objects is
identical, but the IR backend generates an LVT with the constructor
parameters.

The user has to be very insistent to see this ("for step into" +
disabling "Show only kotlin variables"), but it is an observable
difference.
2021-01-06 22:33:37 +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
Mads Ager 717e087fd9 [JVM] Do not collaps unrelated locals in state machine transform. 2020-12-08 18:12:19 +01:00
Mads Ager 1bb864bbb0 [JVM] Add tests that expose problem with locals collapsing.
The collapsing happens during suspend function state machine
transformation.
2020-12-08 18:12:19 +01:00
Kristoffer Andersen 18612c1ef0 [JVM+IR] Rebase LVT test of destructuing in lambda params
The debug experiece of destructuring patterns in lambdas is different
across the two backends due to the IR backend moving local variables
to fields.

However, since the destructuring variable is never actually visible in
the debugger (no linenumbers in the live range of the variable), and
the variable is never used for anything other than hiding it from the
debugger, we propose that it is not actually necessary to include it
in the LVT (and in fact, could be left out of the LVT on the old
backend).
2020-11-23 10:54:04 +01:00
Kristoffer Andersen edd3b457d4 [JVM+IR] Migrate/improve receiver mangling test suite 2020-11-18 15:18:10 +01:00
Kristoffer Andersen 5967e8295e [IR] Align captured receiver variable naming with old BE 2020-11-18 15:18:10 +01:00
Kristoffer Andersen 297c33b452 [IR] Correct line number on suspend function with implicit unit return 2020-11-10 10:58:02 +01:00
Mads Ager 617279310e [JVM_IR] Rebase inline function and defaults args stepping test. 2020-11-02 13:14:12 +01:00
Kristoffer Andersen 27fb46712a [JVM+IR] Unify new debugger tests expectations
This commit unifies the expectation format between the stepping and
LVT tests in the new debugging test harness.

Furthermore, it introduces a compression of runs of locations without
linenumbers. These default to showing as bytecode offsets from
previous line number, which overspecifies the tests: the bytecodes
chosen should not be constrained by a debugging step test.
2020-10-23 11:19:58 +02:00
pyos e19ecdfb3d [Tests] Suspend Codegen Tests Improvements
This commit enables the execution of suspend box tests in a separate
test. It's a QoL improvement in the existing bb tests but, motivating
these changes, enables the new debugger stepping tests to step
coroutine code.
2020-10-23 11:19:58 +02:00
Kristoffer Andersen 3291f8455b [JVM+IR] Update straight-forward LVT tests 2020-10-23 11:19:58 +02:00
Kristoffer Andersen 2c9bf95227 [JVM+IR] New LVT debugging test harness improvements
This is the first step in a push to improve the test coverage of the
IR debugging experience. This commit improves on the sketch of local
variable table tests built on the new debugger stepping
infrastructure. As improvements on the existing
checkLocalVariableTableTest they:
 - don't overspecify codegen strategy: no hard requirements on slots.
 - test the observed lifespans of locals by stepping through code.

Ultimately this should enable us to bring over all existing tests for
improved coverage of both old and new JVM backends.

WIP list:
 - Gracefully handle absent LVT: treat as empty Add type of local and
 - type of value stored there to expectations Print values in local
 - slots if primitive or java.lang.String Enable specifying
 - expectations per backend Gracefully handle absent box methods
 - Gracefully handle null values in slots of reference type
 - Port a first LVT test
2020-10-23 11:19:58 +02:00
Mads Ager a37f16d7a2 [IR] Do not generate line numbers for synthesized data class members.
Fixes KT-41903.
2020-10-06 19:53:47 +02:00
Mads Ager ac742123fd [JVM_IR] Generate line numbers in synthetic bridges.
The current backend does that for some bridges. We do it consistently
for all bridges.

The line number used differs. For the JVM_IR backend, we use the
line number of the class to which the bridge is added. For the
JVM backend, that does not appear to be the case for bridges
in lambdas. I prefer the line number for a lambda invoke bridge
to be the line for the lambda instead os some surrounding class.
2020-09-24 08:59:48 +02:00
Steven Schäfer 5e27d9b089 JVM IR: Make inlining in $default stubs compatible with the JVM BE
The JVM BE inlines calls to the underlying function in a $default stub
verbatim, e.g., without renaming LVT entries or regenerating anonymous
objects. This commit introduces the same behavior in the JVM IR BE.

Fixes KT-36769.
2020-09-24 07:53:31 +02:00
Alexander Udalov 84df996204 JVM IR: fix "step over" for inline function calls in conditions
Reimplement the same hacky approach used in the old backend (see
cc2fe6b0c6).

Previously, the debugger incorrectly stepped into Collections.kt on
"step over" inline function calls from stdlib like 'any'.

Since `if` and `when` expressions are represented the same way in IR,
the behavior is fixed for both of them. It's not the case in the old JVM
backend, where stepping over `when` conditions still suffers from the
same problem, which the newly added test checks.
2020-09-23 15:54:15 +02:00
Mads Ager 78483930bc [JVM_IR] Fix offsets in constant propagation optimization.
Loads of temporary variables that contain constants are replaced
with a copy of the constant. This avoids locals loads and stores.
However, the copy of the constant needs to have the offset of
the load and not of the original constant.

Fixes KT-41963.
2020-09-22 19:12:06 +02:00
Mads Ager a6f301e84a [JVM_IR] Rebase constructor stepping tests that are working as intended.
JVM_IR has consistent stepping behavior for secondary constructors
and init blocks. This change fixes the expectations for tests that
expect the less consistent JVM backend behavior.
2020-08-20 13:12:22 +02:00