Commit Graph

5775 Commits

Author SHA1 Message Date
Roman Efremov 423f4ca5f0 [FE, IR] Check compatibility of annotations set on type usages in expect and actual declarations
This includes checking of annotatins set on:

- value parameter types
- type parameter bound types
- extension functions receiver types
- function return types
- class super types

Fix in `defaultParams_inheritanceByDelegation_positive.kt`
is needed because of problem in resolution of implicit return types
(KT-62064), which leads to crash in annotation checker, because it
expects resolved return type.

MR: KT-MR-12245

^KT-60671 Fixed
2023-10-16 10:48:08 +00:00
Svyatoslav Kuzmich 1ddcdb95bd [Wasm] Add compiler.common.wasm module
This module is introduced to mirror K/JS code layout
Add WasmStandardClassIds to use in checkers
2023-10-12 13:26:58 +00:00
Ilya Kirillov 86c8f3cc35 Remove obsolete @OptIn(ExperimentalUnsignedTypes::class) annotations
^KT-62510
2023-10-12 10:41:00 +00:00
Ilya Kirillov f11cb277cd Remove obsolete @OptIn(ExperimentalStdlibApi::class) annotations
They were added when `buildList`, `buildMap` and `buildSet` were experimental.

^KT-62510
2023-10-12 10:41:00 +00:00
Anastasia.Nekrasova e3bab4a7da [K2] Prohibit smart casts for 'expect' properties
^KT-61340
2023-10-11 17:05:29 +00:00
Nikita Bobko 91a337074e Refactoring: Improve createExpectActualTypeParameterSubstitutor API
Review: https://jetbrains.team/p/kt/reviews/12279/files

Motivation: make sure that cases like KT-62027 won't happen again
Review: https://jetbrains.team/p/kt/reviews/12279/files

Now it's responsibility of the
`createExpectActualTypeParameterSubstitutor` calller to think about the
case when parameters size isn't equal. You must not be able to create a
substitutor if type parameters sizes are not equal

Improvement in `createExpectActualTypeParameterSubstitutor` API also
improves
`AbstractExpectActualCompatibilityChecker.getCallablesCompatibility`
API.

Because suppose that you accidentally created a redundant wrapping
substitutor => you need to handle the case of not equal type parameters
size on the call site => you start thinking why you should do that on
the call site? It must be a responsibility of
`getCallablesCompatibility` => you realize that you created a redundant
wrapping substitutor
2023-10-10 09:02:07 +00:00
Evgeniy.Zhelenskiy 291d52820c [Reflection] Use reference equality to determine that a callable reference is bound
It helps to avoid problems when receiver object implements structural equals violating the equality contract

#KT-60709
2023-10-05 22:16:39 +00:00
Mikhail Glukhikh 87904fd766 AbstractTypeChecker: don't create forks for identical supertypes
The main reason of this commit is the fact that it makes no sense
to create type checker forks in case of two or more types which equal
each other.

Also, this commit fixes the test taken from KT-59514
(see interconnectedGenerics.kt test changed in this commit).
In this particular case we have a subType of C.WithL<Pr!, En<Pr>!>,
and a superType of R<T> with a superType constructor R.
In findCorrespondingSupertypes we get *two* similar supertypes here,
both have a string representation of:
R<Il<@EnhancedNullability En<Pr>!>!>.
If we create two forks because of it, we get NEW_INFERENCE_ERROR
with the following subtyping violation:
Il<@EnhancedNullability En<Pr>!>! <: En<Pr>!.
NEW_INFERENCE_ERROR happens because we make a redundant fork in that case,
but the forks should still work despite it (see KT-62333).

These two types appear due to the content of FirCorrespondingSupertypeCache.
For a key C.WithL and a superType R it stores the following pair of supertypes:
- R<Il<@EnhancedNullability S>!>
- R<Il<(@EnhancedNullability S & Any, @EnhancedNullability S?)>!>
After substitution of S to En<Pr>! they become similar.
NB: if we change jspecify severity level from strict to warn,
then 'R<Il<(S & Any, S?)>!>' is the only remaining supertype,
and @EnhancedNullability annotation is no more in use.

The type hierarchy in this example looks like:
WithL<T, S> <: CanWithB<T, S>, R.F<S, Il<S>>
CanWithB<T, S> <: R.F<S, Il<S>>
R.F<S, Il<S>> <: R<Il<S>>

So R is reachable by two different ways, via CanWithB and directly via R.F.

#KT-59514 Fixed
2023-10-05 11:29:18 +00:00
Dmitriy Novozhilov e5530147f0 [FE] Make ClassId a data class 2023-09-21 12:40:44 +00:00
Dmitriy Novozhilov 9e5ee3afa0 [FE] Add isLocal name to ClassId constructor calls where it needed 2023-09-21 12:40:44 +00:00
Dmitriy Novozhilov adaf8ae46a [FE] Cleanup implementation of ClassId 2023-09-21 12:40:44 +00:00
Dmitriy Novozhilov a43cb721ba [FE] Convert ClassId.java to Kotlin 2023-09-21 12:40:43 +00:00
Dmitriy Novozhilov a3bcac00e4 [FE] Rename ClassId.java to ClassId.kt 2023-09-21 12:40:43 +00:00
Mikhail Glukhikh 8b8088720b Rename: DeserializedContainerAbiStability.IR_UNSTABLE -> UNSTABLE
Related to KT-62056
2023-09-21 11:14:09 +00:00
Mikhail Glukhikh a77b758efa LV 2.0: drop reporting FIR_COMPILED_CLASS and relevant stuff
#KT-62056 Fixed
Related to KT-59171, KT-61951
2023-09-21 11:14:09 +00:00
Nikolay Lunyak ec9cb8beb6 [FIR] Rename JvmNames -> JvmStandardClassIds
This is more consistent with the code of
the common compiler checkers.

It would be nice to refactor the contents
of this object further, but it's out
of scope of the current branch.

^KT-54596
2023-09-19 22:14:09 +00:00
Nikolay Lunyak 986f1624ec [FIR] Remove jvm-specific annotations from common compiler code
^KT-54596 Fixed
2023-09-19 22:14:09 +00:00
Mikhail Glukhikh 5fb38008b7 Switch Kotlin version to 2.0
#KT-59171 In Progress
2023-09-19 15:46:26 +00:00
Alexander Udalov 5cae87b263 K2: add package FQ name to ClassId of anonymous objects
This is needed because in order to figure out which declarations are
visible from anonymous objects in terms of overridability (see
`FirVisibilityChecker.isVisibleForOverriding`), we need to get the
package name of that anonymous object, because there's package-private
visibility on JVM.

 #KT-62017 Fixed
2023-09-19 09:32:55 +00:00
Alexander Udalov bb381e7aef IR: check visibility when building fake overrides
This fixes the difference at least in the IR text test
testFakeOverridesForJavaNonStaticMembers. There's no fake override
created anymore for `packagePrivateMethod` in Test2.

 #KT-61366 Fixed
2023-09-18 12:33:07 +00:00
Roman Efremov 420dceb7d8 [FE, IR] Store PsiElement for mismatched annotation's actual target
There is IDE quick fix which suggests to copy mismatched annotation
from `expect` to `actual` (see KTIJ-26633). It needs to find
`actual` PsiElement where to add annotation. Before previous commit, it
was easy - just get source of `Incompatibility.actualSymbol`.
After previous commit, the problem might be in value parameter, while
`actualSymbol` would contain function symbol. This is solved by adding
new field `Incompatibility.actualAnnotationTargetElement`.

`SourceElementMarker` introduced, because it's needed to be used in
abstract checker. Existing `DeclarationSymbolMarker` doesn't fit
because in next PR for this issue annotations set on types will be reported,
and types are not declarations.

^KT-60671
2023-09-15 14:41:37 +00:00
Artem Kobzar 878452bd2b [K/JS] Implement file merging for clashed file during per-file compilation 2023-09-14 13:14:15 +00:00
Timofey Solonin 53584cdd49 Don't emit CAST_NEVER_SUCCEEDS when casting to a forward declaration type
^KT-58929
2023-09-13 17:49:12 +00:00
Sergej Jaskiewicz 5cb252fe49 [descriptors] Move DeclarationDescriptor#findPackage helper to core
There is nothing serialization-specific about this function
2023-09-13 14:25:09 +00:00
Sergej Jaskiewicz dff2d2ed60 [descriptors] Move some annotation-related utilities to the core module
- AnnotationDescriptor#argumentValue is not frontend-specific
- AnnotationDescriptor#getAnnotationStringValue is not Native-specific

We are going to need these functions in the IR code, so it makes
sense to factor them out to the core module.
2023-09-13 14:25:08 +00:00
Sergej Jaskiewicz 56cb0bf071 [utils] Move atMostOne to core/util.runtime
There is nothing backend-specific about this helper function.
2023-09-13 14:25:08 +00:00
Alexander Udalov d528faa0fe Minor, add toString to OverrideCompatibilityInfo 2023-09-13 15:01:52 +02:00
Mikhail Glukhikh ffd77850ef K2: add proper catch parameter annotation targeting
In this commit we begin counting a catch parameter as
both a local variable and a value parameter for the purpose
of annotation targeting.

#KT-61691 Fixed
2023-09-13 11:27:14 +00:00
Dmitry Savvinov 5736201e3a [K1, MPP] Implement hack for KTIJ-24195
Force-refine typealiases if their expansion isn't visible in the
refiner's module

^KTIJ-24195
2023-09-08 15:31:22 +00:00
Alexander.Likhachev 6f96be0b76 [Build] Get rid of the testApiJUnit5 method
#KTI-1349 In Progress
2023-09-06 22:47:34 +00:00
Ilya Kirillov 030250d387 [FIR] fix resolution ambiguities between weakly compatible expect and actual
There is a corresponding example inside the stdlib,
see `kotlin.text.startsWith`.

JVM and common counterpart are weakly-compatible
as the actual declaration has default arguments,
which results in `ExpectActualCompatibility.Incompatible.ActualFunctionWithDefaultParameters`

This commit allows such cases.

^KT-61732 fixed
2023-09-06 16:30:28 +00:00
Roman Efremov 5e49b472f8 [FE, IR] Allow @ImplicitlyActualizedByJvmDeclaration to be set only on expect
@ImplicitlyActualizedByJvmDeclaration is the only one
OptionalExpectation annotation which works correctly when set only on
`expect`. All other (like @JvmName, @JsName) - not, so warning for them
must be reported.

^KT-61725 Fixed
2023-09-06 14:27:07 +00:00
Alexander Udalov 34f52aaeda Reflection: fix callBy for functions with 32 * N parameters
Optimization in 2439c22ff6 introduced an array `absentArguments` with
default values of all parameter types, which is copied in `callBy`
instead of being recomputed each time. Unfortunately, its size was
computed incorrectly: `maskSize` should only take into account
value parameters (see the `parameter.kind == KParameter.Kind.VALUE`
check in `callBy`).

This led to an issue where if the function had 32 * N value parameters
and 1 receiver parameter, `maskSize` was greater by 1 than expected,
which caused an exception due to mismatching argument array sizes.

 #KT-61304 Fixed
2023-09-05 11:05:29 +00:00
Ilya Gorbunov 68a9b9c312 [Generator] Reference generator class in generated code files 2023-09-04 11:32:39 +00:00
Iaroslav Postovalov 059046a2b1 [JVM] Micro-optimize method signature mapping
This commit optimizes functions related to method signature mapping on
the JVM backend. The most significant change is avoiding re-allocations
in StringBuilder when building internal names. The commit also includes
minor optimizations, such as removing redundant allocations of strings
and other objects.
2023-09-01 20:26:17 +00:00
Nikita Bobko 373abbde5d Partially revert "[FE] Stop ignoring ABSTRACT_MEMBER_NOT_IMPLEMENTED for expect classes"
^KT-61039 Fixed
KT-59739 is now open for K1 (but fixed in K2)
Review: https://jetbrains.team/p/kt/reviews/11867/timeline

This partially reverts commit 4f3ecedbca.
Only K1 part is reverted.

Motivation for revert: KT-59739 cannot be properly fixed in K1 because
of the bug it causes - KT-61039

We just accepted that we will have one more "green in K1 -> red in K2"
case
2023-08-30 14:35:59 +00:00
Nikita Bobko 3534a4b7a9 Improve NON_ACTUAL_MEMBER_DECLARED_IN_EXPECT_NON_FINAL_CLASSIFIER_ACTUALIZATION diagnostic message
In scope of: KT-22841
Review: https://jetbrains.team/p/kt/reviews/11867/timeline
2023-08-30 14:35:58 +00:00
Nikita Bobko 3722f4d7d6 ActualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker: reuse "expect-actual" matcher
In scope of: KT-22841
Review: https://jetbrains.team/p/kt/reviews/11867/timeline

Reduce complexity by reusing "expect-actual matcher" (namely
`AbstractExpectActualCompatibilityChecker.getCallablesCompatibility`)

The current solution has worse algorithmic complexity. Previously it was
O(n) in the best case, where `n` is a number of members. Now, it's
O(m^2), where `m` is number of members in one overload group. But we
prefer to have worse complexity but reuse expect-actual matcher, number
of elements in one overload group shall not be big on real world
examples.

The previous logic was non-trivial because it compared types with with
double comparison in `equals`.
2023-08-30 14:35:56 +00:00
Aleksei.Cherepanov 68af705664 Add import tracker
This tracker reports import directives to IJ's JPS to track changes and detectwehen it is needed to adjust compilation scope.

#KT-44835 Fixed
2023-08-30 12:42:39 +00:00
Stanislav Ruban e7b7ef18fa [KMP] Tweak ACTUAL_WITHOUT_EXPECT message to include 'value' modifier
See KT-59660 for an example of relevant code.
2023-08-30 12:06:43 +00:00
vladislav.grechko e9ccc0329c Fix isKotlinFunctionWithBigArity function
fixup! Fix `isKotlinFunctionWithBigArity` function

Fix `isKotlinFunctionWithBigArity` function

Previous implementation could return false positive results, e.g. for
class named `abacaba.kotlin.Function42`

^KT-61548: Fixed


Merge-request: KT-MR-11928
Merged-by: Vladislav Grechko <Vladislav.Grechko@jetbrains.com>
2023-08-30 09:15:00 +00:00
Ilmir Usmanov e333716fbe JVM: Optimize isPrimitiveBoxing and isPrimitiveUnboxing
Precompute internal names and method descriptors instead of computing
on every access.
2023-08-29 12:15:31 +00:00
Kirill Rakhman c30ce4aabe [FIR] Print operator keyword and token to unresolved diagnostic message
#KT-55672 Fixed
2023-08-28 08:12:25 +00:00
Dmitriy Novozhilov d4f55894b4 [FIR2IR] Properly calculate dispatch receiver type for fake overrides
If some function is not fake-override, then its type should be just
  default type of containing class
For fake overrides the default type calculated in the following way:
1. Find first overridden function, which is not fake override
2. Take its containing class
3. Find supertype of current containing class with type constructor of
   class from step 2

^KT-60252 Fixed
2023-08-25 21:06:15 +00:00
Nikita Bobko b87958d04a Cleanup: drop unused ExpectActualCompatibility.Incompatible.Unknown 2023-08-24 16:56:53 +00:00
Ivan Kylchik ee973c0ede [Generator] Generate Char class 2023-08-24 08:59:49 +00:00
Ivan Kylchik 38e434bc07 [Generator] Generate Boolean class 2023-08-24 08:59:49 +00:00
Pavel Kunyavskiy 8bcd1f4efa [FIR/Native] Move fir-related code from backend.native module to new one
^KT-61249
2023-08-22 08:56:16 +00:00
Nikita Bobko 25c082f02b K1: Implement a checker that disallows to have different member scopes for expect open and its actual
^KT-22841 Fixed
Review: https://jetbrains.team/p/kt/reviews/11603/timeline

The commit also introduces `@AllowDifferentMembersInActual` annotation in
stdlib which allows to suppress the diagnostic
2023-08-21 19:51:08 +00:00
Kirill Rakhman c32a0a83f9 [FIR] Report warning when error is suppressed
#KT-61129
2023-08-18 13:29:20 +00:00