75 Commits

Author SHA1 Message Date
Ilmir Usmanov f1fd84f539 Put $completion parameter to LVT
The parameter, unlike other ones, should span the whole method, since
throughout the whole method it has some value and thus should be
visible.

This effectively rolls bb5a99ec back

 #KT-64309 Fixed
2024-02-08 22:58:20 +00:00
Alexander Udalov d757847ed6 JVM: enable -Xlambdas=class for some backend tests
These tests are checking the specifics of the class-generated lambdas.
2023-05-12 15:21:00 +00:00
Mads Ager 1e444e0451 [JVM IR] Limit local variables in do-while conditions.
Locals introduced in the body of a do-while loop are not
necessarily live at the do-while condition. For example,
if there is a continue in the body before the declaration:

    do {
      if (shouldContinue(x))
        continue
      val y = 32  // not always defined in the condition
      doSomething(y)
    } while (x < 2)

For locals referenced in the condition such code is rejected
by the frontend because a local referenced in the condition
must be always defined when you get there.

However, locals that are not used in the condition were always
put in the local variable table. This leads to invalid locals
information which can trip of debuggers and other build tools
such as the D8 dexer.

This patch only puts in locals information for locals actually
referenced in the local variable table for the condition.

^Fixes KT-51754
2022-04-12 15:47:14 +02:00
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00
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 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 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
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
Ilmir Usmanov 8bfcef415e Do not generate variables for non-generated fields
Use attributes instead of classes.
 #KT-43048 Fixed
2020-12-23 19:45:15 +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
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 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
pyos 5c55f67923 JVM_IR: generate shorter names for classes in delegate initializers
#KT-41493 Fixed
2020-10-20 21:14:44 +02: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
Ilmir Usmanov bb5a99ec18 Do not put $completion to LVT if is dead 2020-08-05 19:47:54 +02:00
Ilmir Usmanov 4fb5f8603a Keep $continuation in LVT
in case of suspend functions and `this` is case of lambdas, since they
are used in async stack trace generation.
Update tests.
 #KT-40661 Open
2020-07-29 00:01:12 +02:00
Ilmir Usmanov d9821412d0 Do not generate fields for unused suspend lambda parameters
This also allows us to not spill them in the lambda.
But, disable this optimization for local named functions.

 #KT-16222 In progress
2020-06-17 12:00:25 +02:00
Mark Punzalan e46adbae29 [JVM IR] Fix checkLocalVariablesTableTest/parametersInSuspendLambda
for JVM IR.
2020-01-14 20:47:36 +01:00
Mark Punzalan 31ba2d64db [JVM IR] Mangle variable names for anonymous parameters in lambdas. 2020-01-09 17:57:50 +01:00
Mark Punzalan 36c4df6d99 [JVM IR] Use names of local functions in names of local classes.
This undoes changes in
https://github.com/JetBrains/kotlin/commit/fbe66c3496d082d2d487b2c39673f0cd4ac5b70a
which broke calculation of the simple name of local classes in
reflection (the enclosing method was not a substring of the name of the
local class).
2020-01-08 18:45:40 +01:00
Mark Punzalan 70b304e6e4 [JVM IR] Support target templates in
AbstractCheckLocalVariablesTableTest and fix
`checkLocalVariablesTable/localFun.kt` for JVM IR.

Also improved diagnosability of CheckLocalVariablesTableTest failures.
2020-01-08 18:45:40 +01:00
Mads Ager 3b2843fe7a Introduce local variable type checker.
CheckLocalVariablesTableTests will now check the validity of
the locals table against types of locals computed based on the
bytecode.

These checks and the new destructuringInFor test act as a
regression test for the changes in
https://github.com/JetBrains/kotlin/pull/2613

These checks also caught a similar issue for destructuring
lambda parameters, where the local is introduced before the
value has been written to the local slot. This change also
fixes that.

Finally, this change fixes the asmLike tests to correctly
look up the name of parameters in the locals table.
2019-10-07 15:06:44 +02:00
Ilmir Usmanov f1d31c8221 JVM_IR: Minor. Unmute tests
Rename FAKE_CONTINUATION -> fakeContinuation
2019-09-19 19:28:11 +03:00
Alexander Udalov fbe66c3496 JVM IR: fix another naming inconsistency with old backend
This fixes slice rewrite stacktraces from RecordNamesForKotlinTypeMapper
which are printed out when running some JVM IR tests (even though
they're ignored), e.g. localClassSimpleName.kt
2019-08-27 19:27:46 +02:00
Ilmir Usmanov 06388b885c JVM_IR: Support suspend lambdas with receiver 2019-07-31 21:17:09 +03:00
Steven Schäfer efb938a7c8 (Un)mute tests 2019-07-31 11:18:44 +02:00
Alexander Udalov 29fa1793d3 JVM IR: add InventNamesForLocalClasses pass 2019-07-17 13:55:36 +02:00
Jiaxiang Chen 2c102ecd57 Replicate old backend's naming logic for captured receiver parameter and extension receiver parameters.
Context for determine if a value parameter is captured from outer
context is not directly available after lowering, hence introduce a new
IrDeclarationOrigin for captured receiver parameter to avoid duplicate
calculation.
2019-07-08 16:25:18 +09:00
Ilmir Usmanov 60cbf0696d Do not generate tests with experimental coroutines on JVM_IR backend
Enable working tests.
2019-06-25 16:30:01 +03:00
Mads Ager b1e8a7cfce JVM: Generate LVT entry for this in @JvmOverload methods.
This change also makes sure that no line numbers are generated
in the wrappers in the JVM_IR backend.

Change-Id: If6c37f8a20894455abddb526039df059e02015a3
2019-05-14 15:14:07 +02:00
Ilmir Usmanov d2a80e7938 Add $result to suspend functions' LVT
#KT-28535
2019-04-01 18:19:32 +03:00
Ilmir Usmanov 05937a28ee Rename result to $result
this way it does not interfere with user-defined variables.
 #KT-28535 Fixed
2019-04-01 18:19:31 +03:00
Ilmir Usmanov 8c8ad48152 Enable test 2019-03-30 04:18:55 +03:00
Ilmir Usmanov ea1e72e7b4 Generate $this$<label> as receiver name instead of $receiver 2019-03-30 04:18:53 +03:00
Ilmir Usmanov 6f14dcfacb Put suspend lambda's parameters to LVT
#KT-26412 Fixed
 #KT-28534 Fixed
2019-03-30 04:18:50 +03:00
Yan Zhulanow e43fd713ef Fix new compiler tests (new receiver name mangling – $this$label) 2019-02-25 14:44:00 +03:00
Yan Zhulanow 28e4356e6e Restore original variable name mangling for captured/receiver $this
Design for the new one is still not finished.
2019-02-25 14:43:59 +03:00
Yan Zhulanow 47f0b68a8c Change mangling for destructured lambda parameters 2019-02-25 14:43:56 +03:00
Ilmir Usmanov ec7315e6da Add $completion entry to suspend functions' LVT
#KT-28810 Fixed
2019-02-22 13:50:35 +03:00
Ilmir Usmanov 871134cff8 Update test data
#KT-28309
2018-12-28 14:18:39 +03:00
Yan Zhulanow dd49d35320 Fix backend tests after changing format of synthetic variables for inline functions 2018-12-12 21:40:44 +09:00
Ilmir Usmanov 8ec49adcf0 Minor. Ignore test 2018-09-11 17:50:46 +03:00
Roman Artemev 8a871b3f0c Update tests 2018-08-31 15:34:18 +03:00
Denis Zharkov c6eaaac877 Adjust coroutines test data to changing the default LV to 1.3 2018-08-30 14:58:43 +03:00
Mikhael Bogdanov 232170b72a Migrate AbstractIrCheckLocalVariablesTableTest to CodegenTestCase stuff 2018-08-24 20:17:18 +02:00
Denis Vnukov 65c79ecfe9 Primitive support for LocalVariables for function parameters 2018-08-09 16:13:21 +03:00
Ilmir Usmanov f507a26a12 Generate decomposed lambda params in suspend lambda's local variables
Unlike ordinary lambdas, suspend lambdas do the computation in
doResume(Ljava/lang/Object;Ljava/lang/Throwable;)Ljava/lang/Object;
method. As you can see, there are no decomposed parameters. As a result,
they used not to be generated.
To fix the issue, I add decomposed parameters to value parameters while
generating local variables table.

In addition, when generating suspend lambda for inline, the codegen
does not take this kind of parameters into account. This is also fixed.

 #KT-18576: Fixed
2018-05-03 10:35:13 +03:00
Dmitry Petrov e2fa613b70 Cache array length in for-in-array loop if possible
If the range expression is not a local variable (which can be updated in
the loop body affecting loop behavior, see KT-21354), we can cache the
array length, thus turning a for-in-array loop into a simple optimizable
counter loop.

 #KT-21321 In Progress
2017-11-29 10:15:32 +03:00