Commit Graph

8224 Commits

Author SHA1 Message Date
Pavel Kunyavskiy 6e8a7d4662 [ObjCInterop] Implement @ObjCSignatureOverride
This annotation leads to conflicting overloads error supression,
in case where several function with the same argument types,
but different argument names are inherited from ObjC class.

We need to implement it in both K1 and K2 to make the IDE experience
better.
But the annotation itself wouldn't be available in K1.

    ^KT-61323
2024-02-14 11:44:01 +00:00
Kirill Rakhman e88865e4c7 [FIR] Fix methods with erased parameters missing from raw collection scope
#KT-65448 Fixed
2024-02-14 09:55:24 +00:00
Alexander Udalov b72effab98 IR: remove isFromJava check from isOverridableMemberOrAccessor
This is needed because in case a static member is inherited via a Kotlin
class (class C in the newly added test), its origin becomes
FAKE_OVERRIDE which is technically not Java anymore. After this change,
we'll build fake overrides for static members from superclasses
regardless of whether they come from Java or Kotlin.

Also, move the previous logic of
isOverridableFunction/isOverridableProperty to the only call site at
IdSignatureFactory.

 #KT-65589 Fixed
2024-02-13 21:03:33 +00:00
Sergej Jaskiewicz 80240198d2 [FIR2IR] Coerce to Unit for last statement in Unit-typed IrBlocks
^KT-59781 Fixed
2024-02-12 21:16:41 +00:00
Sergej Jaskiewicz eec10f3f2c [test] Reproduce KT-59781 2024-02-12 21:16:41 +00:00
Pavel Kunyavskiy 9532172a22 [Fir2IR] Don't use FIR f/o builder when IR f/o builder is enabled
Before this commit, fir f/o builder was inconsistently
disabled in some places, while it should work only for lazy declarations

Attempt to use it for non-lazy declarations, without maintaining
invariant, that it would also be used for super classes
led to unpredictable results.

This commit introduces opt-in, and marks all related API to three types
* Propagate error to user
* Fine to use, as it's checked if ir f/o builder is enabled
* Fine to use, as it is definitely a lazy class.

Several cases of missing checks was fixed.

^KT-65707
2024-02-12 15:02:50 +00:00
Vladimir Sukharev a0ffea48a2 [K/N][Tests] Use runProcess in doFileCheck
^KT-61259
2024-02-11 21:30:03 +00:00
Vladimir Sukharev 0ba509dcd6 [K/N][Tests] Adjust test signext_zeroext_interop.kt for different cache modes
^KT-61259
2024-02-11 12:44:31 +00:00
Vladimir Sukharev 370f138ad4 [K/N][Tests] Migrate test signext_zeroext_interop.kt
^KT-61259
2024-02-11 12:44:31 +00:00
Mikhail Glukhikh a189509353 K2: build override structure for Java renamed builtins more precisely
#KT-65410 Fixed
2024-02-09 19:04:42 +00:00
Mikhail Glukhikh ba374a3978 K2: reproduce KT-65410 in diagnostic/BB tests 2024-02-09 19:04:42 +00:00
wrongwrong a5bf8787a1 Reflection: exclude DEFAULT_CONSTRUCTOR_MARKER when calculating mask size
#KT-65156 Fixed
2024-02-09 17:54:16 +00:00
Pavel Kunyavskiy b4062c8974 [Fir2IR] Fix fake override generation for lazy accessors
^KT-65595 Fixed
2024-02-09 13:27:15 +00:00
Denis.Zharkov a4ccb72b94 Add tests making sure that a couple of issues are fixed by PCLA
^KT-49283 Fixed
^KT-64077 Fixed
2024-02-09 13:03:12 +00:00
Sergej Jaskiewicz 88b80e0ed2 [FIR2IR] Add Unit coercion for non-last expressions in try/catch blocks
^KT-61088 Fixed
2024-02-08 22:16:20 +00:00
Alexander Udalov 3f034e8b67 Enable lightweight lambdas (aka invokedynamic) since 2.0
#KT-45375 Fixed
 #KT-58173 Open
2024-02-08 19:46:18 +00:00
Brian Norman c8e77aad91 [FIR] Fix CFG/DFA for delegate properties within PCLA
^KT-65262 Fixed
2024-02-07 22:34:12 +00:00
Mikhail Glukhikh 8ee54a9045 K2: add a test to ensure #KT-63756 Fixed 2024-02-07 20:56:04 +00:00
vladislav.grechko 54858c2118 [FIR] Fix naming of local classes when serializing metadata
^KT-63655: Fixed
^KT-63901: Fixed
^KT-63988: Fixed
2024-02-07 12:30:50 +00:00
Vladimir Sukharev 112473f310 [Tests] Add test for KT-65197
^KT-65197
2024-02-07 09:03:49 +00:00
Mads Ager 79eee6de4f [FIR] Do not enhance nullability for annotation interface field types.
Java annotation interface fields are constant declarations that can
have any Java type and are not restricted in the same way that
method return types are for annotation interfaces.

#KT-65482 Fixed
2024-02-06 09:45:34 +00:00
Pavel Kunyavskiy 1cc138431d [Fir2IR] Get rid of simple symbol table usages
We have two sources of truth in Fir2Ir - declaration storages,
which maps fir to ir symbols and symbolTable which maps
IdSignature to ir symbol.

The long-term goal is to have only one - declaration storages. This
commit goes to this goal by removing all symbolTable usages that are
straightforward to remove, i.e., all except:

1. classes as there is some code, that uses signature inside ClassSymbol
2. functions/properties as sometimes declaration storage fails to match
symbols correctly (i.e. for generated data class members)
3. type parameters, as we need to remove functions first.

As a side effect, it fixes some of the signature clash cases on valid
code, as we no longer rely on signature uniqueness, except cases
mentioned above.

^KT-65274 Fixed
^KT-64990
2024-02-06 08:55:35 +00:00
Alexander Udalov 53c5230520 IR: copy EnhancedNullability in CopyIrTreeWithSymbolsForFakeOverrides
Otherwise it leads to the following problem in the newly added test.

Suppose that we have a fake override `remove(Int)` inherited from
LinkedList _without_ EnhancedNullability on its parameter type. By
normal Kotlin rules, this method should override the method from
KotlinInterface. However, on JVM we have another overridability check in
IrJavaIncompatibilityRulesOverridabilityCondition which ensures that
"JVM primitivity" of parameter types is the same for the base and the
overridden method.

So the fake override `remove(Int)` from LinkedList is determined to be
override-incompatible with `remove(Int)` from KotlinInterface. But when
we try to create symbols for all fake overrides in the class, we get a
clash because there are two fake overrides with exactly the same
IdSignature, neither of which overrides the other.

If we keep the EnhancedNullability annotation on the parameter, it
starts working because the logic of computing signature in
JvmIrMangler.JvmIrManglerComputer.mangleTypePlatformSpecific adds an
"{EnhancedNullability}" mark to the IdSignature of a fake override from
LinkedList.

 #KT-65499 Fixed
2024-02-05 13:28:19 +00:00
Mikhail Glukhikh 36dd9b6818 K2: add BB tests for KT-59380 working properly (compiler error in K1)
#KT-59380 As Designed
2024-02-02 17:07:40 +00:00
Pavel Kunyavskiy c0152ccf0f [IRFakeOverrides] Convert lazy callables overriddens during f/o building
Unfortunately, it's not enough to know direct overriddens
to correctly build fake overrides. This mean, that we need to know
whole overridden tree during the process of building.

It happens automatically for normal classes, but not for lazy classes,
as their overriddens are built separatly.

This commit enforces correct overrddens for lazy classes in hierarhies
at the point, where they should be normally computed.

^KT-65236
2024-02-02 16:28:25 +00:00
Pavel Kunyavskiy caa6918031 [FIR2IR] Fix handling private setters in anonymous classes
^KT-65290 Fixed
2024-02-02 16:07:35 +00:00
Denis.Zharkov 66d8f471d9 K2: Fix internal error in FIR2IR caused by PCLA + String interpolation
There's an implicit contract in PCLA that the statement-level call
should be postponed iff it has something to be postponed inside.

And that contract didn't work well for string interpolation containing
some postponed calls.

Thus, we haven't run a completion results writing for them properly,
thus leaving type parameters (K from synthetic call) for expression
types instead of an inferred substituted type.

In this commit, the contract was reversed to explicitly enumerate
the cases when it's safe to resolve the candidate outside PCLA session.

See the comments at `mightBeAnalyzedAndCompletedIndependently`.

^KT-65341 Fixed
2024-02-02 15:40:47 +00:00
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