Commit Graph

8267 Commits

Author SHA1 Message Date
Igor Yakovlev 033e2c45f1 [WASM] Caching string literals in global pool 2022-11-01 13:15:09 +00:00
Alexander Udalov 3d00c173f3 Fix binary compatibility for inlined local delegated properies
#KT-54650 Fixed
2022-11-01 12:34:33 +01:00
Alexander Udalov 54ab66cd4e Add regression test for KT-54707 2022-11-01 11:24:03 +01:00
Ilya Goncharov 372a512c91 [JS IR] Add case with bridge for method with default parameters 2022-10-31 16:08:24 +00:00
Sergej Jaskiewicz b429e2f34f Remove a test that doesn't make sense anymore 2022-10-27 11:28:01 +00:00
Sergej Jaskiewicz 6a40a7e471 [JS IR] Don't forget to enable lazy property initialization 2022-10-27 11:27:59 +00:00
Dmitriy Novozhilov 027b1f861c [FIR] Update return type of delegated callables in ReturnTypeCalculator
^KT-54654 Fixed
2022-10-27 11:08:55 +00:00
Dmitriy Novozhilov f441151eab [FIR] Fix order of supertype scopes for supertypes of companion object
^KT-54645 Fixed
2022-10-27 11:08:54 +00:00
Dmitriy Novozhilov d54503e66c [Test] Add test for KT-54645 2022-10-27 11:08:54 +00:00
Nikolay Lunyak 7e323f8ac6 [FIR] KT-54692: Fix compiler crash on UInt.shl
Merge-request: KT-MR-7513
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2022-10-27 10:40:06 +00: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
Ilya Goncharov fd5fba6f09 [JS IR] Fix case with bridge with nested classes
^KT-54686 fixed
2022-10-26 12:56:03 +00:00
Johan Bay 9f3d8130db Remove unnecessary deprecation annotation
Private members on private companion objects have proper visibility
so there is no need for the @Deprecated annotation.

^KT-54539 Fixed
2022-10-25 14:03:11 +02:00
Alexander Udalov b42a7be0de Psi2ir: keep nullability when substituting function type for SAM type
After we added "careful approximation of contravariant projections" in
584b70719e, some SAM conversions started to require an additional
implicit cast of the functional value before it is converted to the SAM
interface. The target type of this implicit cast was computed
incorrectly because it didn't contain nullability of the SAM type. This
could lead to a situation where a nullable value was incorrectly cast to
a non-null type, which caused a missing null check and NPE at runtime.

For example, let's consider the test `kt54600.kt`. SAM conversion
happens in the constructor call `J(filter)`. Before 584b70719e, the IR
for that argument was (irrelevant things are omitted for simplicity):

  TYPE_OP SAM_CONVERSION type=Condition<String!>!
    GET_VAR filter type=Function1<String, Boolean>?

After 584b70719e, the IR became:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>
      GET_VAR filter type=Function1<String, Boolean>?

Note the two changes:
* The resulting SAM type changed from `Condition<String!>` to
  `Condition<Any?>`. This is exactly the point of the "careful
  approximation" change, because just erasing the "in" projection from
  the parameter type is incorrect, see the explanation for that change.
* The value is now implicitly cast to the _non-null_ function type
  before it is SAM-converted. The presence of the cast is fine, but the
  fact that it's to a non-null type is an oversight.

The target type for this cast is computed at
`KotlinType.getSubstitutedFunctionTypeForSamType` in psi2ir. Now it
extracts the nullability from the SAM type and retains it in the
resulting function type.

After this change, the IR for the argument becomes:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>!
      GET_VAR filter type=Function1<String, Boolean>?

Note that the target type is now flexible, as the resulting SAM type.
Another option would be to make it nullable, as the type of the
functional value, but there doesn't seem to be any difference.

 #KT-54600 Fixed
2022-10-25 11:20:23 +00:00
Mikhail Glukhikh c0789b5207 PSI/FIR->IR translators: return to 1.7.10 behavior for field references
In 1.7.20 we used the nearest Java-based receiver for such field
references in backend. Now we are using use-site receiver again,
it can lead to accidental usage of derived class property backing field.

This is effectively a revert of KT-49507 fix, see commits:
- fa914f20
- b0a6508d

#KT-54393 Fixed
#KT-49507 Planned
#KT-52338 Planned
2022-10-25 08:36:01 +00:00
Vsevolod Tolstopyatov b29309478e Take into account 'KTypeImpl.classifier' in its hashCode and equals
Since KT-53308, we started to cache results of typeOf invocation
in reflection. The cache uses the origin 'KClassifier' as a key with
an optional list of 'KTypeProjection' in type argument position,
and computed result as a value.

Without classifier check, the caching produces incorrect execution in
a very specific classloaders usage which is leveraged
by IDEA source-tree:

* All Kotlin stdlib and reflect classes are always loaded by the same
  classloader
* Other classes that depend on Kotlin are loaded by separate
  classloaders

The reproducer:

* Attempt to use typeOf<kotlin.List<Foo>> from one classloader caches
  the resulting KType
* Attempt to use typeOf<kotlin.List<Foo>> from another classloader
  for the same 'Foo' that differs only in classloader reuses the
  computed KType, meaning that KType type argument classifier
  is simply incorrect and points to the 'Foo' from the first classloader

#KT-54611 Fixed
#KT-54629 Fixed

Merge-request: KT-MR-7470
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
2022-10-24 19:05:08 +00:00
Ivan Kylchik 5b16b2c71e Properly verify args in string concatenation expression for interpreter
If string concatenation contains object value, then this argument
will not have explicit toString call. We must find and check toString
method manually.

#KT-54615
2022-10-24 13:14:16 +00:00
pyos 65c153a722 JVM: consider casts of null to be redundant
These should only have ever been necessary for field type inference in
coroutines, which should have been fixed by 0fc676a20c.

Unlike 903a5d69a4, this time the change is in an optimization pass.
Advantage: optimization passes have a closer to the JVM view of the
bytecode, which makes this change significantly more likely to be correct.
Disadvantage: technically we don't really guarantee optimization passes
other than FixStack will run at all. For KT-54581 this is 100% fine
since the problem itself is caused by redundant checkcast elimination in
the first place (otherwise there would've been a redundant cast to
String), but for KT-53146 this means the fix is somewhat incidental and
not necessarily guaranteed.

^KT-53146 Fixed
^KT-54581 Fixed
2022-10-24 11:11:21 +02:00
vladislav.grechko 6f4a60ac91 Fix equality comparison for inline class over inline class
^KT-54536: Fixed
2022-10-21 21:17:40 +00:00
vladislav.grechko db133bedf9 Fix ClassCastException on equality comparison on inline class objects
^KT-54603: Fixed
2022-10-21 21:17:40 +00:00
Alexander Udalov 8812f632cc Fix optimization of property delegates of platform types
The old code didn't replace the delegate field access because it was
wrapped into a TYPE_OP IMPLICIT_NOTNULL.

 #KT-54463 Fixed
2022-10-21 13:23:38 +00:00
vladislav.grechko c990bbb26c Get rid of excess method in compiled inline class with custom equals
^KT-54501: Fixed
2022-10-21 12:57:11 +00:00
vladislav.grechko 70c2f2b86f Support specifying different bytecode listings for FIR and old frontend 2022-10-21 12:57:11 +00:00
Igor Yakovlev 5218acd5c9 [WASM] Optimise interop adapters 2022-10-18 20:48:12 +02:00
pyos 1fcf099104 FIR: serialize both expanded and abbreviated type to metadata 2022-10-18 14:59:11 +00:00
Ivan Kylchik 1ce99db830 Change class loader in ir interpreter that is used to create proxy obj
#KT-54509 Fixed
2022-10-18 13:47:34 +00:00
vladislav.grechko b5a23e3ef7 Minor: improve usability of tests for custom equals in inline classes 2022-10-17 14:11:01 +00:00
vladislav.grechko cc1b4243dd Fix exception on 'equals()' returning 'Nothing' in inline class
^KT-54401: Fixed
2022-10-17 14:11:00 +00:00
vladislav.grechko aeccc2e787 Fix equality comparison of inline classes with primitive underlying type
^KT-54455 Fixed
2022-10-14 23:25:48 +00:00
Ivan Kochurkin 69ee40325b [FIR] Fix dependencyProviders generation in FirDependenciesSymbolProviderImpl
Get rid of unnecessary creating of FirCompositeSymbolProvider
2022-10-13 18:11:49 +00:00
vladislav.grechko 817afcd4af KT-MR-7307 review fixes 2022-10-13 15:19:10 +00:00
vladislav.grechko e0c8142106 Support of custom 'equals' and 'hashCode' in inline classes
'equals' from any made available for overriding in inline classes
'typed' equals made available for definition in inline classes
'typed' equals definition made compulsory if 'untyped' is overridden
'operator' keyword is allowed in 'typed' equals definition

^KT-24874: Fixed
2022-10-10 16:52:34 +00:00
Pavel Mikhailovskii 0947834f0d Add a test for KT-54318 2022-10-10 13:47:34 +02:00
Pavel Mikhailovskii 5fdfd4a421 Revert "KT-53146 Don't coerce Nothing? returned from "catch" clauses"
This reverts commit 903a5d69a4.
2022-10-10 13:36:44 +02:00
Evgeniy.Zhelenskiy 6117cdc0c3 [IR] Remove unused MFVC getters
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-1179
2022-10-07 12:43:46 +00:00
Evgeniy.Zhelenskiy 9dd308dc01 [IR] Add context receivers test, fix a flattening fields bug
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-1179
2022-10-07 12:43:46 +00:00
Evgeniy.Zhelenskiy e1f886936c [IR] Support try for MFVC
#KT-1179
2022-10-07 12:43:45 +00:00
Evgeniy.Zhelenskiy f8aa3612f8 [IR] Support if and when for MFVC, fix several bugs, refactor
#KT-1179
2022-10-07 12:43:44 +00:00
Evgeniy.Zhelenskiy 70293fab60 [IR] Rename MFVC tests + Add test for get-field optimization
#KT-1179
2022-10-07 12:43:43 +00:00
Evgeniy.Zhelenskiy ec3c0af09d [IR] Suppress temporary test failing on Android
Bug is fixed in https://jetbrains.team/p/kt/reviews/6452

#KT-1179
2022-10-07 12:43:42 +00:00
Evgeniy.Zhelenskiy 6f94af80ab [IR] Correct work of the new MFVC lowering classes
#KT-1179
2022-10-07 12:43:42 +00:00
Evgeniy.Zhelenskiy 8ba20bee5b [IR] Prepare MFVC-lowering for the new MFVC classes
#KT-1179
2022-10-07 12:43:41 +00:00
Evgeniy.Zhelenskiy eb0aa55571 [IR] Fix MFVC with type arguments/parameters
#KT-1179
2022-10-07 12:43:40 +00:00
Evgeniy.Zhelenskiy f9bed3d946 [IR] Support MFVC with type parameters
#KT-1179
2022-10-07 12:43:40 +00:00
Evgeniy.Zhelenskiy 14b8e41967 [IR] Integrate MFVC with Inline classes
#KT-1179
2022-10-07 12:43:39 +00:00
Evgeniy.Zhelenskiy 765c212327 [IR] Add MFVC generation tests
#KT-1179
2022-10-07 12:43:38 +00:00
Evgeniy.Zhelenskiy 894cdc2307 [IR] Implement equals call correct generation for MFVC
#KT-1179
2022-10-07 12:43:37 +00:00
Evgeniy.Zhelenskiy 0d350f94f2 [IR] Implement bridges generation for MFVC
#KT-1179
2022-10-07 12:43:37 +00:00
Evgeniy.Zhelenskiy 0c1c25e477 [IR] Implement MFVC basic flattening
#KT-1179
2022-10-07 12:43:36 +00:00