Commit Graph

111 Commits

Author SHA1 Message Date
Dmitriy Novozhilov 28b83a1a5d [Test] Mute tests due to KT-56755 2023-02-20 08:40:32 +00:00
Nikolay Lunyak a9343aeb7d [FIR] KT-55840: Ensure everything actually works
This inconsistency is present due to not using the `// WITH_STDLIB`
in the above tests. When K1 creates the enum, it tries to generate
`entries()`, and for that it tries to load `kotlin.enums.EnumEntries`,
but this is actually an unresolved reference. K1 silently swallows it,
and proceeds.

The reason K2 doesn't fail is that in order to generate `entries()` it
simply creates the necessary `ConeClassLikeType` with the desired
`classId` instead of loading the whole `ClassDescriptor`.

The reason we can still observe `$ENTRIES` and `$entries` in K1
is because they are generated during the JVM codegen, and it
only checks if the `EnumEntries` language feature is supported. It
doesn't check if the `entries` property has really existed in IR
(by this time it's expected to have already been lowered to the
`get-entries` function - that's why "has ... existed").

The reason why the codegen doesn't fail when working with
`kotlin.enums.EnumEntries` is because it creates its
own `IrClassSymbol`.

^KT-55840 Fixed

Merge-request: KT-MR-8727
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-02-10 16:57:51 +00:00
Artem Kobzar 71486a321c [K/JS] Add support of compilation with ES-classes 2023-01-17 18:14:17 +00:00
Artem Kobzar 67048151fb [K/JS] Change js-call inlining strategy and + ability to referencethis safely from the js call ^Fixed KT-54134 2022-11-30 11:43:22 +00:00
Sergej Jaskiewicz becbc06663 [JS] Re-enable some stepping tests 2022-11-18 10:37:58 +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
Sergej Jaskiewicz 7b7c517dbb [JS IR] Emit original names for local vars to sourcemaps
#KT-35655 Fixed
2022-11-09 12:35:44 +00:00
Sergej Jaskiewicz ba7f5afebe [JS IR] Generate debug info for catch parameters
We will need it to generate original names for catch parameters in
sourcemaps.

Also, don't generate redundant debug info for compiler-generated
exception handling control flow operators.

See the doc comment to the MultipleCatchesLowering class

#KT-46276
2022-11-02 13:14:01 +00:00
Sergej Jaskiewicz 4ae03ea74a [JS IR] Improve debug info for if and when statements
#KT-46276
2022-11-02 13:14:01 +00:00
Sergej Jaskiewicz ccbb2a08a0 [JS IR] Improve debug info for functions with default parameters
Don't generate unnecessary mappings so that the user doesn't need to
step in many times to get where they want

#KT-46276
2022-11-02 13:14:00 +00:00
Sergej Jaskiewicz 512a2bfd7a [JS IR] Improve debug info for callable references and lambdas
#KT-46276
2022-11-02 13:13:59 +00:00
Sergej Jaskiewicz fe0e9db3aa [JS IR] Generate debug info for JS switch statements
#KT-46276
2022-11-02 13:13:59 +00:00
Sergej Jaskiewicz b2b7958b62 [JS IR] Generate debug info for secondary constructors
#KT-46276
2022-11-02 13:13:58 +00:00
Sergej Jaskiewicz ec18dce7cb [JS IR] Improve debug info for suspend functions
- Map generated explicit Unit returns to the closing brace of
  the original body
- Name the continuation parameter as `$completion` to match the JVM BE,
  and generate debug info for it (so that it appears in the 'names'
  array in sourcemaps)
- Don't generate debug info for coroutine instantiation ceremony
  (so that the user doesn't need to step in many times to get where they
  want)

#KT-46276
2022-11-02 13:13:58 +00:00
Sergej Jaskiewicz 0e3f48314a [JS IR] Improve stepping test executor
Don't search for box function in the generated code;
instead, stop the execution right before calling it.

This makes stepping tests more accurate.
2022-10-27 09:28:05 +00:00
Sergej Jaskiewicz a939f9ccd0 [JS IR] Improve debug info precision for blocks
Namely:
- Generate debug info for closing braces, which allows the breakpoints
  set on closing braces to be hit
- Generate debug info for 'if' and 'try/catch' statements.

KT-46276
2022-10-18 14:31:14 +00:00
Sergej Jaskiewicz d9681caf0c [JS IR] Generate 'names' entries for functions in sourcemaps 2022-10-14 10:09:40 +00:00
Sergej Jaskiewicz c9c50ff73c [JS IR] Disable some flaky stepping tests
^KT-54283
2022-10-04 10:31:14 +00:00
Artem Kobzar 73e7053c35 [K/JS] Use only single variant of default arguments function wrapper for exported and not-exported functions 2022-09-19 17:49:04 +00:00
Sergej Jaskiewicz 17f22c7204 [JS IR] Use a special executor for stepping tests
This will hopefully fix flakiness for some tests
2022-08-30 13:38:47 +00:00
Sergej Jaskiewicz d57ddc5f83 [JS IR] Generate debug info for JS injections
Also, fix the JS parser to collect the "correct" debug info
(see the note in `translateJsCodeIntoStatementList`)

#KT-53361 Fixed
2022-08-22 23:15:52 +00:00
Sergej Jaskiewicz 2ece4f4dbf [JS IR] Improve the precision of execution of stepping tests 2022-08-05 11:53:40 +00:00
Steven Schäfer 7e472301b6 Re-enable "JVM IR: Move direct invoke optimization into a separate pass" 2022-07-29 01:06:44 +02:00
Sergej Jaskiewicz 1241565cce [JS IR] Adapt stepping tests for Kotlin/JS 2022-07-19 16:06:24 +00:00
Sergej Jaskiewicz ea556ce428 [JS IR] Implement stepping tests for Kotlin/JS
We already have stepping tests for Kotlin/JVM.
They are helpful for testing the correctness of the generated
debugging information.

They are better than line number tests in that they allow to test the
_behavior_, not the generated data. The structure of the data may change
even if the behavior stays the same. For that reason, stepping tests
are more stable.
2022-07-19 16:06:23 +00:00
Alexander Udalov b50d2ff20a Revert "JVM IR: Move direct invoke optimization into a separate pass"
This reverts commit f0760e0550.

The reason is that it leads to KT-53202.
2022-07-15 18:29:07 +02:00
Steven Schäfer f0760e0550 JVM IR: Move direct invoke optimization into a separate pass
This also changes the transformation to inline the body of a directly
invoked lambda rather than producing a call to an anonymous local
function. The latter is unsupported in inline functions and problematic
from an ABI perspective, since it results in functions whose name
depends on the entire source code up to this point.
2022-07-14 23:24:18 +02:00
Pavel Mikhailovskii ecb3cc193c KT-51883 Don't use "-" in generated unique lifted declaration names 2022-06-10 18:36:04 +00:00
Kristoffer Andersen 7f531d8426 [IR] Improve stepping/LVT behavior around destructuring 2022-05-13 23:19:27 +02:00
Kristoffer Andersen c3dbb44e5f [IR] Adjust LVT test expectations and mute accordingly 2022-05-13 23:19:27 +02:00
Kristoffer Andersen b81139ad36 [IR] More extensive LVT tests around destructuring
All tests in this commit _pass_ to document existing behavior, but
this will change in a separate commit as we reflect desired behavior
in the test expectations.
2022-05-13 23:19:27 +02:00
pyos c43acba0b9 JVM: restore call site line number after inlining lambda
E.g. in `x + f()` where `f` is an inline lambda, the instructions for
`+` should have the line number of that expression (while previously
they instead had the line number of the last line of the lambda).

^KT-51738 Fixed
2022-05-02 19:28:10 +02:00
Kristoffer Andersen 4f8ef8c315 [EE-IR] Support Local Functions
This commit introduces support for calling and referencing local functions and
objects in evaluate expression on the IR backend.

The primary incision is a lowering inserted after Local Declaration Lowering,
that uses the intermediate data structures recorded by LDL to rewrite calls to
local functions to the appropriate function in the binary, instead of predicting
the compilation strategy. The required changes to the rest of the pipeline
facilitate piping the required data around.

The key to this transformation is that _captures by the local function_ must be
introduced as _captures by the fragment function_, such that the evaluator
infrastructure can find the appropriate values at run-time. This is necessary
due to the strategy of compiling local functions to static functions instead of
closures.

Additional test coverage of stepping behavior support the corresponding changes
in the Evaluator, part of the Kotlin Debugger plug-in.
2022-04-25 16:59:04 +03: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
Alexander Udalov c53d91bae1 JVM IR: adjust generation of linenumber for try-finally
Do not generate linenumber for the start of the finally block, because
that is usually where the only word 'finally' is located. Instead,
generate linenumber for the first expression inside the finally block.

Not generating this linenumber fixes an issue in code coverage tools
which would consider such finally uncovered. Although this might be
technically considered as designed, it makes more sense to NOT detect it
as uncovered because semantics of the finally block shouldn't really
differ whether it's executed normally or because an exception happened.
It's also beneficial for the tool support to behave like javac, which
doesn't generate the linenumber either.

 #KT-50973 Fixed
2022-02-24 16:33:40 +01:00
Denis.Zharkov c0b6a593e0 FIR: Fix incorrect type of block generated for inc operator
Previously, it was obtained from expected type of a variable being assigned,
but it's better to use the type of resulting expression

Initially this part was brought in 4ab0897d7d,
but as we see in commit message and tests it was all about unit-coercion
2021-11-26 19:39:38 +03: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 e1f6c19c83 [FIR] Fix local variable tests.
- Mangle names for extension receivers in lambdas
 - Correctly mark anonymous variables and variables for arguments
   for destructuring declaration.

There is one failure remaining which is cause by lambda
type inference differences that leads to FIR having an explicit
return from the lambda whereas old frontend leads to an implicit
return. This difference is visible in debug stepping that the
local variables tests do because the implicit return has the line
number of the closing brace of the lambda. This change adds an
IrText test to make the difference clear.
2021-11-09 11:09:11 +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 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