Commit Graph

124 Commits

Author SHA1 Message Date
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
Mikhail Glukhikh ae4b8be16b FIR2IR: never generate empty when #KT-55459 Fixed
In details, this commit changes the following:
- it converts FIR when without branches to empty IR block without when
- it doesn't drop empty else branches in when anymore
2023-01-25 12:31:34 +00:00
Vladimir Sukharev 924898afb7 [K/N] KFC-446: K2 platform: Native alpha
Merge-request: KT-MR-7905
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-01-04 16:10:40 +00:00
Ilya Chernikov 7e4ee399c8 FIR JS: temporarily mute remaining codegen tests 2022-11-12 16:28:25 +01:00
Ilya Chernikov 78ca733c38 FIR JS: add K2 variants of all other JS tests
except tests that are not possible to add without some modifications in
the test infra. See todos on the commented-out test declarations
2022-11-12 16:28:24 +01: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
Simon Ogorodnik 2cf8f75a90 KT-53255. Fix StackOverflow during IR verification from K2
In FIR we desugar when with multiple conditions leading to same block
as tree of OR expressions

Given
```
when(some) {
  "a", "b", "c" -> {}
  else -> {}
}
```

actually desugared into
```
when(val <subj> = some) {
  <subj> == "a" || <subj> == "b" || <subj> == "c" -> {}
  else -> {}
}
```

There is a multiple ways of how we can organize such expressions in FIR
Previously it was just nesting-chain of OR expressions

While the most efficient way in terms of required stack depth is
a balanced tree

KT-53255
2022-10-26 17:44:46 +00:00
Simon Ogorodnik ac8cae16ba KT-53255. Extend test for long when expression 2022-10-26 17:44:46 +00:00
Pavel Mikhailovskii d65775ca1a KT-47475 Do not copy InnerClass attribute for WhenMapping classes 2022-08-25 21:41:14 +00:00
Mads Ager 59c2bde10a [K/N] Unmute passing tests. 2022-08-01 08:57:16 +00:00
Sergej Jaskiewicz d7d86a0e95 [JS IR] Lift lambdas that capture no context
If a lambda expression does not capture any local variables, convert
it to a global free function and replace the lambda creation with
a reference to that function.

Example: for the following Kotlin code

```kotlin
fun foo(f: () -> Unit) = f()

fun bar() = foo { console.log("hello") }
```

before this patch, we generated:

```js
function foo(f) {
  return f();
}
function bar() {
  return foo(bar$lambda());
}
function bar$lambda() {
  return function () {
    console.log('hello');
  };
}
```

after this patch, we generate:

```js
function foo(f) {
  return f();
}
function bar() {
  return foo(bar$lambda);
}
function bar$lambda() {
  console.log('hello');
}
```
2022-04-07 10:31:35 +00:00
Xin Wang 4277827506 Don't transform irBranch if tableswitch can't be generated
#KT-34466 Fixed
2022-03-12 14:30:00 +03:00
Alexander Udalov 328853dffe Add tests for obsolete issues
(Test for KT-37331 is added to multiplatform/defaultArguments/suspend.kt.)

 #KT-30080
 #KT-33641
 #KT-36237
 #KT-36952
 #KT-37331
 #KT-38920
 #KT-39256
 #KT-42415
 #KT-44636
 #KT-45704
 #KT-47084
 #KT-47894
2022-03-08 14:19:37 +01:00
Mikhail Glukhikh 53d6ac24e5 Switch kotlin version to 1.7
* Change 1.6 to 1.7 constants
* Fix SAFE_CALL_WILL_CHANGE_NULLABILITY for testData
* Change EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_WARNING to EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR
* Change NON_EXHAUSTIVE_WHEN_STATEMENT to NO_ELSE_IN_WHEN
* Fix testData for SafeCallsAreAlwaysNullable
* Change T -> T & Any in test dumps
* Change INVALID_CHARACTERS_NATIVE_WARNING -> INVALID_CHARACTERS_NATIVE_ERROR
* TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_WARNING -> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR
2022-02-25 11:46:27 +00:00
Xin Wang ebcc2cc3b2 PSI2IR: KT-49485 chunk ktConditions to avoid stackoverflow 2022-01-24 19:28:59 +03:00
Dmitry Petrov 8905586cbb IR KT-50258 rewrite enum-based 'when' more carefully 2021-12-21 06:06:45 +00:00
Igor Yakovlev 4f9b54da26 [WASM] Remove ignore from wasm std text tests 2021-12-07 21:33:28 +03:00
Dmitriy Novozhilov 330574cab6 [FIR] Properly support smartcasts on stable when subjects in when conditions
^KT-49860 Fixed
2021-11-26 11:26:21 +03:00
Mikhail Glukhikh cf104c8433 FIR: add status line to all failing black box tests 2021-11-20 03:37:31 +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
Sergej Jaskiewicz 55ae6d1f3e [JS IR] Optimize pattern-matching of enums into comparing their ordinals
For this code:
```
enum class Season {
    WINTER,
    SPRING,
    SUMMER,
    AUTUMN
}

fun bar1(x : Season) : String {
    return when (x) {
        Season.WINTER, Season.SPRING -> "winter_spring"
        Season.SUMMER -> "summer"
        else -> "autumn"
    }
}
```

previously we generated this:
```
function foo(x) {
    var tmp0_subject = x;
    return (tmp0_subject.equals(Season_WINTER_getInstance())
        ? true
        : tmp0_subject.equals(Season_SPRING_getInstance()))
            ? 'winter_spring'
            : tmp0_subject.equals(Season_SUMMER_getInstance())
                ? 'summer'
                : 'autumn';
}
```

And now we generated this:
```
function bar2(x) {
  var tmp0_subject = x;
  var tmp0 = tmp0_subject._get_ordinal__0_k$();
  var tmp;
  switch (tmp0) {
    case 0:
    case 1:
      tmp = 'winter_spring';
      break;
    case 2:
      tmp = 'summer';
      break;
    case 3:
      tmp = 'autumn';
      break;
    default:
      noWhenBranchMatchedException();
      break;
  }
  return tmp;
}
```
2021-10-14 11:44:01 +00:00
Svyatoslav Kuzmich 279f184703 [JS] Remove failed checks based on unstable naming 2021-10-12 23:29:39 +03:00
Svyatoslav Kuzmich aa5f98f919 [JS] Remove KJS_WITH_FULL_RUNTIME for tests that already have WITH_RUNTIME 2021-10-07 22:36:18 +03:00
Sergej Jaskiewicz 65d40c2253 [JS IR] Make tests that use directives pass with IR BE 2021-10-06 09:23:50 +00:00
Svyatoslav Kuzmich 6eb81517a0 [Wasm] Unmute passed Wasm tests 2021-10-02 06:14:35 +00:00
Svyatoslav Kuzmich c88cde2f8b [Wasm] DONT_TARGET_WASM_BACKEND => IGNORE_BACKEND in testdata 2021-10-02 06:14:35 +00:00
Svyatoslav Kuzmich ab9a23cbfa [Wasm][Stdlib] Reuse K/N collections and StringBuilder 2021-10-01 17:18:49 +03:00
Igor Laevsky 00f61978b8 WASM: Enable exception handling tests 2021-09-08 19:56:38 +03:00
Svyatoslav Kuzmich b79719d6f5 [Wasm] Fix unit issues
- Materialize unit when its value is actually needed.
- Special-case Unit_getInstance return type at codegen. It should be a
  proper Unit object instead of a "void"
2021-09-08 19:56:26 +03:00
Mikhael Bogdanov c519003e13 Update test affected by ProhibitSimplificationOfNonTrivialConstBooleanExpressions feature 2021-07-16 13:26:36 +00:00
Dmitry Petrov 0104b1275f JVM_IR KT-47398 handle @EnhancedNullability String subject as in 1.0 2021-06-23 20:11:24 +03:00
Dmitry Petrov c26d71c4ef JVM KT-47365 add box test 2021-06-23 20:11:23 +03:00
Andi Wenger f9d2ca68ce KJS IR: Fix KT-45738 - Consider recursive checkForPrimitiveOrPattern
Recursive results from checkForPrimitiveOrPattern were ignored. If it found a case/condition that could not be optimized the resulting "false" was not propagated. This would lead to a "optimized" when without all conditions.
- see KT-45738
- The return is now lifted out of the when to make it more obvious what is going on.
- New test for mixed multiple conditions in when
2021-04-29 23:52:01 +03:00
Alexander Udalov 21e9bd7ea2 Add regression tests for obsolete issues
#KT-9304
 #KT-14961
 #KT-16549
 #KT-21080
 #KT-28234
 #KT-30102
 #KT-31994
 #KT-34291
 #KT-38099
 #KT-41174
 #KT-44622
 #KT-44701
 #KT-44781
 #KT-44849
 #KT-44978
 #KT-45081
 #KT-45286
 #KT-45383
 #KT-45444
 #KT-45907
2021-04-20 21:24:29 +02:00
pyos 29f95c7df2 FIR: improve inference of implicit type arguments in casts
Type parameters do not necessarily match one-to-one, or preserve order.
2021-01-18 18:01:03 +03:00
Dmitry Petrov 118a7d4e34 JVM_IR KT-43242 generate switch subject as primitive 'int' 2020-11-19 16:34:04 +03:00
Svyatoslav Kuzmich fdd7fa5aea [Wasm] Mute codegen box tests 2020-11-09 16:04:43 +03:00
Ilya Goncharov 14d9aa1660 Add test on break in when without label
^KT-42262 fixed
2020-10-21 16:59:24 +03:00
Vitaly fe047f9b47 [JS BE] mutes tests for JS_IR_ES6, which muted for JS_IR 2020-05-27 00:32:56 +03:00
Mikhail Glukhikh e7e80be34a [FIR2IR] Populate overridden symbols even for !isOverride
Before this commit we considered !isOverride as a sign that
function / field / accessor has no overridden symbols.
However, it's false for deserialized, because isOverride
is always false there.

This commit fixes 68 BB tests but breaks 25 BB tests (not yet muted)
2020-05-14 13:40:36 +03:00
Mikhail Glukhikh d8f9643650 [FIR2IR] Use intersection type approximation for receivers 2020-05-07 15:27:17 +03:00
Mark Punzalan b74652aa5b [FIR] Use ieee754equals for floating-point equality operations 2020-04-23 11:50:54 +03:00
Juan Chen 882e6931d6 [FIR] Add backing fields to const properties during Fir2Ir translation 2020-04-06 16:41:57 +03:00
Mikhail Glukhikh 03143bc788 [FIR2IR] Implement mapping of FIR & IR built-in class members 2020-03-24 12:15:18 +03:00
Mikhail Glukhikh a4c7619c89 [FIR2IR] Introduce & use FirBuiltInsPackageFragment
Without this commit, JVM name mapping logic in BE does not work for FIR,
because FIR cannot use old BuiltInsPackageFragmentImpl descriptor.
In this commit we add our own implementation thus fixing
a pack of FIR black box tests.
2020-03-24 10:37:53 +03:00
Mikhail Glukhikh 94fe79578e [FIR2IR] Generate unconditional branch in exhaustive whens 2020-03-20 11:55:34 +03:00
Mikhail Glukhikh cfa626ad77 FIR2IR: introduce conversion scope, remove dispatch receiver for lambdas 2020-03-04 16:55:31 +03:00
pyos 7e6d080123 JVM_IR: default-initialize variables visible in the LVT
See KT-36812. Aside from the problem stated there, D8 will throw out the
entire LVT if it sees a variable that has not been written to (and will
generate incorrect SSA if the slot is reused with a different type).

Note: this only fixes a FIR test because it's missing an `else -> throw`
branch, and default initialization satisfies the verifier and masks the
incorrect control flow.
2020-03-02 20:17:10 +03:00
Mikhail Glukhikh 2308e5bb7c FIR2IR: in case of use-site generic type use call from original class 2020-02-28 15:29:02 +03:00
Mikhail Glukhikh 39bd97147f [FIR] Don't create initializers for simple enum entries
Usually FIR enum entry is initialized by anonymous object,
which is the container for all enum entry' declarations.
However, for simple enum entries there is no need of initializer at all.
2020-02-21 16:38:52 +03:00