Commit Graph

8197 Commits

Author SHA1 Message Date
Alexander Udalov 49c659b379 CLI: remove obsolete -Xdump-declarations-to
It was only used in the very old version of binary compatibility
validator. It was never supported in the JVM IR backend.
2024-02-01 23:37:23 +00:00
Alexander Udalov d450e3074b IR: do not build fake overrides for static members of interfaces
Split members into static/non-static, and only build fake overrides for
inherited static members of classes.

 #KT-65276 Fixed
 #KT-65277 Fixed
2024-02-01 23:25:50 +00:00
Alexander Udalov a22c16e745 IR: do not assert presence of property getter in IrFakeOverrideBuilder
#KT-65456 Fixed
2024-02-01 23:25:49 +00:00
Alexander Udalov b752d3997b Reapply "[IrFakeOverrideBuilder] Support fake overrides for java static methods"
This reverts commit 6271f5cbe5.

The original commit 15094eb03a was reverted because it caused a problem
during bootstrap. That problem is fixed in a subsequent commit.
2024-02-01 23:25:48 +00:00
Ivan Kochurkin 968ecadff2 [FIR2IR] Erasure type of parameter of delegated property in K1 manner
Add `shouldEraseType` to `Fir2IrConversionScope`

^KT-62884 Fixed
2024-02-01 15:36:32 +00:00
Kirill Rakhman 6271f5cbe5 Revert "[IrFakeOverrideBuilder] Support fake overrides for java static methods"
This reverts commit 15094eb03a.
2024-02-01 08:43:00 +00:00
Brian Norman dde2156f5f [FIR2IR] Always use property type if var
For destructing calls, the component type is used for the property type
in all cases. However, this can result in runtime and/or compilation
errors when the property is a var and changed, especially when the
component is a primitive but the property type is nullable. Instead,
only use the component type when the property is also a val.

^KT-64944 Fixed
2024-01-31 22:27:18 +00:00
Kirill Rakhman 853ad54699 [FIR] Fix incorrect updating of callable reference type in delegated property
... if the delegate happens to be a function call whose second
argument is a callable reference but not actually a provideDelegate
call.
The fix is to ensure that the call is _actually_ a desugared
provideDelegate call.

This fixes a CCE in a case where the delegate expression is a regular
function call and the second argument is a callable reference.

#KT-65165 Fixed
2024-01-31 14:51:51 +00:00
Kirill Rakhman 9ec0210c04 [FIR] Support enhancing intersection overrides
When a type annotated with @PurelyImplements (explicitly or implicitly)
inherited some methods from a java supertype and the purely implemented
Kotlin supertype, it was inconsistent which of the signatures the
intersection override would have (with or without flexible types).
This commit adds support for the enhancement of intersection overrides.
If one of the overridden methods has non-flexible types, the enhanced
method will have non-flexible types.
This fixes some false negative nullability type mismatches.

#KT-59921 Fixed
2024-01-31 11:16:50 +00:00
Kirill Rakhman 3b841dcb98 [FIR] Don't remove subsumed members from intersection overrides's overriddens
This fixes a bunch of missing overridden symbols in IR.
This is also required for fixing KT-59921 in the following commit
where we need to keep all overridden symbols of intersection overrides
so that we can enhance them properly.

#KT-57300 Fixed
#KT-57299 Fixed
#KT-59921
#KT-57300
#KT-62788
#KT-64271
#KT-64382
2024-01-31 11:16:50 +00:00
Mikhail Glukhikh 38aec7333b Drop mentioning of KT-63955 in some ABI difference comments
In fact, the commit c3926219 should do it before because the relevant
difference was removed in this commit
2024-01-30 19:44:00 +00:00
Mikhail Glukhikh 672b5ba0d7 K2/Java: implement platform-dependent function filtering in JvmMappedScope
We drop Kotlin function 'remove' or 'getOrDefault' from JvmMappedScope,
if it has platform-dependent annotation, and the bound Java class scope
does not contain a function with the same signature.

#KT-57268 Fixed
2024-01-30 19:44:00 +00:00
vladislav.grechko 9aa8fb80e7 Set correct IR origins for inc/dec operations
NB: in order to produce correct IR origins, the source element kinds for
some FIR elements has been changed. As a side effect, mapping PSI to FIR
slightly changed: namely, for `a[b]++`, `a[b]` used to be mapped on
`set` call or callable reference, but now it is mapped on `get` call.

^KT-61891: Fixed
^KT-64387: Fixed
2024-01-30 14:26:10 +00:00
vladislav.grechko 8b1d87848d [FIR2IR] Fix unwrapping of single-statement blocks
Unwrapping should be done with respect to `forceUnitType` parameter.

^KT-65019: Fixed
2024-01-30 14:26:10 +00:00
Artem Kobzar 8c69ffe8c9 [K/Wasm] Generate wasm-specific unsigned implementations ^KT-58039 Fixed 2024-01-29 20:11:41 +00:00
Artem Kobzar 1fe77705b0 [K/Wasm] Convert non-capturing lambdas into singletons ^KT-64803 Fixed 2024-01-29 12:52:18 +00:00
Evgeniy.Zhelenskiy b0367d9399 [Reflection] Support callBy for inline class interface functions with default parameters
#KT-57972
2024-01-29 04:04:59 +00:00
vladislav.grechko 1e7cc00dcb [FIR] Serialize type annotations of vararg parameters in metadata
^KT-63899: Fixed
2024-01-28 22:10:05 +00:00
vladislav.grechko f318b5969d Erase non-reified type parameters by-default when inlining.
Substitution of type arguments to non-reified type parameters may lead
to accidental reification, which should not be done (see ^KT-60174 for
examples). So, we should erase them, except the few cases.

^KT-60174: Fixed
^KT-60175: Fixed
2024-01-26 18:31:20 +00:00
vladislav.grechko 44caa3cdd5 Do not use dispatch receiver type when calculating method owner
Motivation of using dispatch receiver type when calculating method owner
was discussed here: https://github.com/JetBrains/kotlin/pull/3054

However, this is incompatible with type erasure of non-reified type
parameters on inlining (which will be done in future). Consider the
code:

```
inline fun <T> f(arr:  Array<T>, p: (T) -> Int): Int = p(arr[0])
fun box() = f(arrayOf("abacaba"), String::length)
```

After inlining and erasure, the type of `arr[0]` is `Any`. Thus, when
calculating owner of `String::length` we would have `Any` instead of
`String` if we used dispatch receiver type.

Note, that this change affects bytecode instruction that invokes
method, but does not change which method is being invoked.
2024-01-26 18:31:19 +00:00
Denis.Zharkov ca80ddb8ca K2: Run completion-writer related PCLA tasks for irregular call kinds
- For synthetic calls
- For delegated constructor calls

Also, I checked that for each toResolvedReference() (beside annotations)
that converts candidate to the resolved reference,
we run `runPCLARelatedTasksForCandidate()` in the same context.

^KT-65103 Fixed
2024-01-26 18:13:27 +00:00
Svyatoslav Scherbina 2e5a9b1416 [K/N] Make cinterop include unused Objective-C forward declarations
Previously, when an Objective-C library had an unused Objective-C
forward declaration (`@class` or `@protocol`), cinterop tool didn't
include it into the resulting klib at all.

This led to a subtle bug (KT-64105). One Obj-C library has unused
Obj-C forward declaration, and another one depends on the first and
uses this forward declaration, e.g. as a function result type.
When building the first cinterop klib, this forward declaration is not
added to `includedForwardDeclarations` in the klib manifest (the
compiler uses this property to decide whether to synthesize the
corresponding class).
When building the second cinterop klib, the forward declaration is not
added to its manifest either, because it is located in the dependency
(and therefore should've been included there).
As a result, the forward declaration is included nowhere, and any
attempt to use it in Kotlin fails, including calling the function from
the second lib.

This commit fixes this bug by including even unused Objective-C forward
declarations, which is consistent with any other kind of declarations
and seems more natural.

^KT-64105 Fixed
2024-01-25 14:06:10 +00:00
Pavel Kunyavskiy 5e25707648 [Fir2IR] Don't compute overriddenSymbols if ir builder is enabled
Ir builder would recompute them anyway, while computation
can lead to triggering computations in lazy classes too early,
which is incorrect.

^KT-65116
2024-01-25 09:22:07 +00:00
Igor Yakovlev 4a49261f8c [Wasm/WASI] Implement Wasm WASI box test for K2
Fix #KT-64449
2024-01-24 15:41:38 +00:00
Mikhail Glukhikh 51093a4764 K1/K2: add a group of BB test around primitives in Java
Related to KT-62554, KT-63242
2024-01-24 08:39:18 +00:00
Mikhail Glukhikh e42c1be354 K2: use intersection scope override checker also in intersection scope
In more details, we use either platform override checker (if we came
from platform) or the combined intersection scope override checker
at this place. Also this commit fixes various places around
JavaOverrideChecker, allowing to apply it in intersection override
checker properly:
- don't consider return types in this place
- apply JavaOverrideChecker if at least one candidate is from Java
- compare type primitivity closer to K1 logic

#KT-62554 Fixed
Partially fixes KT-63242
2024-01-24 08:39:18 +00:00
Mikhail Glukhikh 54d978ba86 K2: add various tests describing current KT-62554 / KT-63242 behavior 2024-01-24 08:39:18 +00:00
Brian Norman 17a1871b83 [FIR] Make sure the primary constructor is first in class CFG
The primary constructor of a class needs to be the first subgraph of the
class control-flow graph. Based on the Kotlin specification, class
initialization order goes first primary constructor, in-place
declarations (properties and init blocks), and then secondary
constructors. If the class doesn't have a primary constructor, then it
is just skipped in the order.

Unfortunately, the class control-flow graph had in-place declarations
first and then all constructors. Instead, we should treat the primary
constructor as the first in-place declaration, and then continue with
the existing processing as secondary constructors. This will guarantee
that super constructor calls have the correct property initialization
information.

^KT-65093 Fixed
2024-01-23 23:16:00 +00:00
Pavel Kunyavskiy 09713bb89e [Fir2IR] Don't add invisible fake overrides to Lazy class
^KT-65056
2024-01-22 13:30:05 +00:00
Vladimir Sukharev e958e57c42 [K/N][Tests] Migrate test forwardDeclarationsCast.kt
^KT-61259
2024-01-22 12:29:57 +00:00
Vladimir Sukharev 2f3705f0eb [K/N][Tests] Move funptr.kt to standalone tests due to OUTPUT_DATA_FILE directive
^KT-61259
2024-01-22 12:29:57 +00:00
Vladimir Sukharev c286b0efd7 [K/N][Tests] Migrate tests forwardDeclarationsTwoLibs.kt
^KT-61259
2024-01-22 12:29:57 +00:00
Vladimir Sukharev bd688b3ef7 [K/N][Tests] Migrate tests kt49034*.kt
^KT-61259
2024-01-22 12:29:57 +00:00
Artem Kobzar 57a4d09ad2 [K/Wasm] Add tests for nested external declarations + fix them 2024-01-22 11:55:09 +00:00
Igor Chevdar f3a807c507 [IR] Fixed a problem in FunctionInlining
#KT-64868 Fixed
2024-01-22 09:34:42 +00:00
Vladimir Sukharev d2b810c373 [K/N][Tests] Polish sharing_with_weak.kt
^KT-61259
2024-01-19 18:37:43 +01:00
Vladimir Sukharev 39e2187d31 [K/N][Tests] Split filecheck part from test direct.kt
^KT-61259
2024-01-19 18:31:25 +01:00
Vladimir Sukharev 833e125450 [K/N][Tests] Polish test sharing_with_weak.kt
^KT-61259
2024-01-19 18:22:22 +01:00
Vladimir Sukharev 4aa8774c6e [K/N][Tests] Migrate test direct.kt
^KT-61259
2024-01-19 18:22:22 +01:00
Vladimir Sukharev e59a80bd69 [K/N][Tests] Migrate test overridabilityCondition.kt
^KT-61259
2024-01-19 18:22:21 +01:00
Vladimir Sukharev 2d0009ff99 [K/N][Tests] Migrate test illegal_sharing_with_weak.kt
^KT-61259
2024-01-19 18:22:21 +01:00
Vladimir Sukharev 647a907204 [K/N][Tests] Migrate kt48816 tests
^KT-61259
2024-01-19 18:22:21 +01:00
Vladimir Sukharev cc13888dd0 [K/N][Tests] Migrate second ObjC test with framework
^KT-61259
2024-01-19 18:22:21 +01:00
Vladimir Sukharev 1b18f4ed1e [K/N][Tests] Migrate first ObjC test with framework
^KT-61259
2024-01-19 18:22:20 +01:00
Vladimir Sukharev 6e2df0e086 [K/N][Tests] Migrate first Apple-specific test
^KT-61259
2024-01-19 18:22:20 +01:00
Ilya Chernikov 3b70b3d92d K2 Scripting: restore some codegen scripting tests for K2 2024-01-19 15:54:53 +00:00
Mikhail Glukhikh a83d2b7a67 FirJavaElementFinder: return packages with true isValid()
#KT-65111 Fixed
2024-01-19 15:52:14 +00:00
Mikhail Glukhikh ae6aef3a63 K2: reproduce KT-65111 2024-01-19 15:52:14 +00:00
Sergej Jaskiewicz e8aa05928d [FIR2IR] Unconditionally disable linkViaSignatures on JVM
It was an experimental compilation mode that we don't need anymore.

KT-64809
2024-01-19 13:35:59 +00:00
Alexander Udalov b2c30921e4 JVM: support JVM-specific primitive/wrapper type overridability check
#KT-62045 Fixed
2024-01-19 12:30:48 +00:00