Commit Graph

103680 Commits

Author SHA1 Message Date
Ivan Kylchik 55092da03b [PSI2IR] Check that a given function has the right descriptor
The issue was discovered during work on IR serialization and
this is just a safety check.

#KT-56230
2023-08-11 12:19:45 +00:00
Ivan Kylchik 5f2de9dbff [IR] Create primitive iterators in IrBuiltIns
This change is required to fix stdlib compilation with enabled
linking via signature. All primitive iterators are considered to be
builtins and are created during compile time as deserialized
declarations (at least in K1). But if we meet the definition of some
primitive iterator in code, for example, during stdlib compilation,
we will end up with two different descriptors (deserialized and lazy)
that describe the same entity. Because of that we have conflicts in
symbol table:
* For descriptors, we will end up with multiple IR declarations
that describe the same class, but with different descriptors. With
some magic compilation still works.
* For signatures, we will end up with only one IR declaration in the
table, but it will have wrong deserialized (instead of lazy)
descriptor.

In the end, this change allows us to initialize iterators in advance
with correct descriptor.

#KT-56230
2023-08-11 12:19:45 +00:00
Ivan Kylchik 782d5e86f6 [IR] Replace reference* with toIrSymbol in IrBuiltinsOverDescriptors
This change is a minor refactoring that introduces `toIrSymbol`
method for function and property descriptors, like it is done for
class descriptor.
2023-08-11 12:19:45 +00:00
Svyatoslav Scherbina 4da8b0850e Native: make CompareDistributionSignatures task fail on klib tool errors
CompareDistributionSignatures task is used to compare Native platform
libraries contents against a previous version.

Under the hood, it runs the klib tool to get a library contents. But it
didn't check the exit code, so if klib tool failed, the task could
mistakenly indicate that there are no differences in platform libs.

Fix this by checking the klib tool exit code and failing if it is not
zero.
2023-08-11 12:13:21 +00:00
Kirill Rakhman cee355196a [Tests] Fix accidental overload resolution ambiguity in test 2023-08-11 10:54:25 +00:00
Kirill Rakhman bb6d4acfb2 [Analysis API] Fix wrong override with context receiver 2023-08-11 10:54:24 +00:00
Kirill Rakhman 724d527fd8 [FIR] Fixes for call conflict resolution
Let ConeCompositeConflictResolver pass the results of the previous
resolver to the next one.
Otherwise, we get false positive conflicts when a set of candidates
can't be fully reduced by one resolver but could be resolved by the
subsequent application of multiple ones.
This change makes ConeCompositeConflictResolver order-dependent and
thus, ConeOverloadConflictResolver must be invoked last, because it
must work on a pre-filtered list.

Also, let ConeEquivalentCallConflictResolver use
FirStandardOverrideChecker instead of compareCallsByUsedArguments
because it's stricter.

This all fixes a false positive overload resolution ambiguity in common
metadata compilation that is caused by stdlib using the new KMP
format.
Now stdlib metadata is in the classpath, and so declarations from the
stdlib are returned from both MetadataSymbolProvider and
KlibBasedSymbolProvider.
This isn't a problem per se because duplicate candidates are filtered
out by ConeEquivalentCallConflictResolver (K1 works analogously), but
in the case of top-level functions with generic receivers like
Collection<T>.toTypedArray, the check failed because of the direct
comparison of receiver types.

#KT-60943 Fixed
2023-08-11 10:54:24 +00:00
Kirill Rakhman 86ef313233 [FIR] Check context receivers in FirStandardOverrideChecker
#KT-61145 Fixed
2023-08-11 10:54:24 +00:00
Artem Kobzar 4dc0d68288 [K/JS] Fix autoboxing for inlined function ^KT-60785 Fixed 2023-08-11 09:19:51 +00:00
Ilya Gorbunov 7ae443ad7f [stdlib-mpp] Use kotlin-stdlib-common artifact for dist from kotlin-stdlib project 2023-08-11 08:49:23 +00:00
Ilya Gorbunov 3e4cbd6dd2 Publish Gradle metadata for kotlin-stdlib-common, KT-60911
This makes it depend on kotlin-stdlib in all targets
and have no artifacts from Gradle's point of view
2023-08-11 08:49:23 +00:00
Dmitry Savvinov e8289181e6 [mpp] Minor: diagnostic messages clean-up
- Mention link to docs about templates in warning messages
^KT-60491 Fixed

- Make sure that each warning mentions some way to solve the problem
  aside from disabling default template

- Fix small syntactical bug in code sample

- fix incorrect indentation in trimMargin after joinToString

- Use kotl.in in Kotlin12XMppDeprecation
2023-08-11 08:26:14 +00:00
Dmitry Savvinov edbaed0da9 [Gradle] Minor: restore link to page about JVM toolchains in warning text
The link has been accidentally lost during migration of diagnostics to
the new infrastructure
2023-08-11 08:26:14 +00:00
Aleksei.Cherepanov da267ba2c8 Fix JPS import after removing dependency checksums...
...that are no longer resolved due to alignment (ca7e4941)
2023-08-11 07:05:33 +00:00
Anton Bannykh d78f7bde6a [JS] set LV=1.9 for K1-specific IC tests
Otherwise they will actully run K2 after
the LV=2.0 migration.

^KT-60829 fixed
2023-08-10 22:37:16 +00:00
Alexander Udalov 7f5bc94117 Jvm-abi-gen: do not treat KmProperty.hasConstant as part of ABI
... for non-const properties.

The meaning of this flag for non-const properties is in reality not
well-established, and it can vary from one release to another. In
particular, it's different in K2.

This commit has two parts:
1) The test (added in 5891617674) about clinit is changed. Original
   motivation was to check that presence or absence of `<clinit>` is not
   a part of the ABI. However, in addition to that, the test also
   involuntarily checked that the aforementioned "hasConstant" flag for
   the property y/Object.y is the same in both cases (which I believe
   was not the intention) because these tests check that Kotlin metadata
   is _exactly the same_ after applying jvm-abi-gen. So I've changed it
   to be more straightforward: one version declares an obvious constant,
   while another declares an obvious non-constant. After this change,
   the test started to fail (even on K1) because the value of the
   "hasConstant" flag was different between two versions.
2) Remove "hasConstant" flag for non-const properties when transforming
   metadata via jvm-abi-gen. This fixes the test and assures it won't
   fail when the project is migrated to LV 2.0.

 #KT-60849 Fixed
2023-08-10 20:24:17 +00:00
Ivan Kochurkin d4d30dcfcf [FIR] Introduce OPTIONAL_EXPECTATION_NOT_ON_EXPECTED diagnostic
^KT-60892 Fixed
2023-08-10 17:46:08 +00:00
Ivan Kochurkin 8e8de513ee [FIR] Introduce OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE diagnostic
^KT-60892
2023-08-10 17:46:08 +00:00
Ivan Kochurkin 9ec7218af6 [FIR] Add isCommon property to FirModuleData
It will be used for correct OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE reporting
2023-08-10 17:46:08 +00:00
Ivan Kochurkin b08df32cac [FIR] Introduce OPTIONAL_DECLARATION_OUTSIDE_OF_ANNOTATION_ENTRY diagnostic
^KT-60892
2023-08-10 17:46:08 +00:00
Ivan Kochurkin dc1f1fe979 Move optionalExpectationIncorrectUse from MPP integration to diagnostics tests 2023-08-10 17:46:08 +00:00
Roman Golyshev 93124ee98c KT-60957 [Analysis API] Properly handle source PSI for implicit invoke calls in KtFirReferenceShortener
For implicit invoke operator calls, there are two instances of
`FirResolvedNamedReference`. One of them references `invoke` function
and cannot be used to analyze the property access, and the second one
has `source == null`. Luckily, the parent of the second reference is
`FirPropertyAccessExpression`, which has the correct source

^KT-60957 Fixed
2023-08-10 16:51:31 +00:00
Roman Golyshev 7633e6e6f1 KT-60957 [Analysis API] Visit FirPropertyAccessExpressions instead of FirResolvedNamedReferences
It's much easier to analyze complex cases like invoke operator calls
using dedicated `FirPropertyAccessExpression`
2023-08-10 16:51:30 +00:00
Dmitrii Gridin b0b2e76e13 [LL FIR] dependent analyze: support different numbers of statements
Previously, the different number of statements has led to
some unexpected behavior. E.g., the resulting script can have
duplicated declarations – one from the original script instead of
some statement and one from the copy

^KT-60987
2023-08-10 16:18:26 +00:00
Dmitrii Gridin 4f4b30ee28 [LL FIR] dependent analyze: add test on different statements in script
It contains a wrong result. Will be fixed in the next commit

^KT-60987
2023-08-10 16:18:26 +00:00
Dmitrii Gridin 201100db60 [LL FIR] AbstractDependentCopyTest: supports custom text in copy
This provides an ability to test more real-world cases.
E.g., we can emulate completion behavior

^KT-60987
2023-08-10 16:18:26 +00:00
Nikita Bobko 52f0f75175 [FE] Cleanup: rename areXyzCompatible -> getXyzCompatibility
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

Motivation:
- Functions with prefix "are" must return Boolean. And
  AbstractExpectActualCompatibilityChecker even already contains some
  functions with prefix "are" that return Boolean (e.g.
  `areCompatibleCallableVisibilities`,
  `areCompatibleSupertypesOneByOne`, etc)
- Unification with functions that are prefixed with "are" and return
  Boolean
2023-08-10 15:46:48 +00:00
Nikita Bobko d4758014ec [FE] Type-safety refactoring: Make areCompatibleClassScopes to return Incompatible.WeakIncompatible
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

For StrongIncompatible `actual` declaration is considered as overload
and error reports on expected declaration. For WeakIncompatible the
error is reported straight away

Before the refactoring `areCompatibleClassScopes` returned just
`Incompatible`. It is bad because StrongIncompatible isn't possible for
classes (classes can't be overloaded). Now all class incompatibilities
are weak.

The commit has a minor impact on observable behavior (cases where we
reported the compilation problems are still reported but on another
elements):
- We no longer report type parameter class incompatibilities on expect
  declaration, we report them only on actuals (it happened because all
  WeakIncompatible are reported only on actuals)
- In a sense, Java implicit actualization was the only way to "overload"
  classes (it would be a redeclaration compilation problem, so it
  doesn't count as a valid "overload"). And since type parameters
  incompatibility was StrongIncompatible for classes, we counted them as
  "overloads" and didn't report incompatibility problems on Kotlin
  class. Now we do report. (see
  implicitJavaActualization_multipleActuals)
2023-08-10 15:46:48 +00:00
Nikita Bobko 98ec13b51a [FE] Type-safety refactoring: extract main logic of areCompatibleCallables into two functions
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

Extract main logic of `areCompatibleCallables` into two functions:
`areStrongIncompatibleCallables` and `areWeakIncompatibleCallables`.

The main point is that `areStrongIncompatibleCallables` &
`areWeakIncompatibleCallables` have very specific return types.

This commit doesn't change any logic. The commit makes the API more
type-safe ensuring that bugs like in previous commit (KT-60902) won't
happen again
2023-08-10 15:46:48 +00:00
Nikita Bobko eac4b81b11 [FE] Fix TypeParameterUpperBounds incompatibility priority
^KT-60902 Fixed
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

We should prioritize to return STRONG incompatibilities over WEAK
incompatibilities. But this invariant broke in `areCompatibleCallables`,
because `areCompatibleTypeParameters` returns incompatibilities of both
types, and `areCompatibleTypeParameters` is called in WEAK
incompatibilities section.

The fix is to split `areCompatibleTypeParameters` into two functions:
`areStrongIncompatibleTypeParameters` and
`areWeakIncompatibleTypeParameters`. And call each of this function in
appropriate `areCompatibleCallables` sections.
2023-08-10 15:46:47 +00:00
Nikita Bobko fd5e97ff23 [FE] Refactoring: Move check for "enumConstructorsAreAlwaysCompatible" higher than check for callable kind
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

This is a preparation refactoring for the following KT-60902 fix and
type-safety refactoring.

This commit doesn't have observable side effects (and can be called pure refactoring) because the following conditions:
1. `expectDeclaration is ConstructorSymbolMarker && actualDeclaration is ConstructorSymbolMarker`
2. `expectDeclaration is FunctionSymbolMarker != actualDeclaration is FunctionSymbolMarker`

can't be both `true` at the same time
2023-08-10 15:46:47 +00:00
Nikita Bobko 529a1dd720 Force recompile all call-sites of ExpectedActualResolver.{findActualForExpected, findExpectedForActual}
This is needed to workaround broken incremental compilation in JPS in
Kotlin plugin. The incremental compilation bug is reported KT-60759

In Kotlin plugin I created the same commit which changes the name of the
function on the call-site.

Review: https://jetbrains.team/p/kt/reviews/11039/timeline

After a few days in master branch, I will revert this commit
2023-08-10 15:46:46 +00:00
Nikita Bobko d39755b578 [FE] Convert specific diagnostic for actual function with default arguments into a common incompatibility
^KT-59665 Fixed
Review: https://jetbrains.team/p/kt/reviews/11039/timeline

It's better to have this logic in common place
(AbstractExpectActualCompatibilityChecker) to avoid missing compilation
errors in the future

This commit fixes:
1. Missing compilation error for actual function with default arguments
   for 'actual typealias' KT-59665
2. Missing compilation error for actual function with default arguments
   for actual fake-override KT-59665

Alternative solution for KT-59665 is to create a special checker.

"incompatibility" vs "special checker":

Arguments for common incompatibility:
- What if we had a rule that expect and actual default params must
  match? If so then it certainly would be an incompatibility.
- Technically, we do the matching of expect and actual params (because
  we allow default params in common ancestors of expect and actual
  declarations).
- It's hard to check that the actual definition doesn't use default
  params because `ExpectedActualResolver.findActualForExpected` filters
  out fake-overrides and doesn't return them. It's not clear logic for
  me, that I'm afraid to touch.
  implicitActualFakeOverride_AbstractMap.kt test breaks if you drop this
  weird logic
- WEAK incompatibilities can be considered as "checkers". So it doesn't
  matter how it's implemented, as a "incompatibility" or a "checker"

Arguments against common incompatibility:
- Although we match expect and actual declarations to allow default
  params in common ancestors of expect and actual declarations, it's
  still can be considered that we check that the actual declaration
  doesn't have default params. And it doesn't feel right that we check
  correctness of the actual declaration in expect-actual matcher.
- ~~It may change the rules of expect actual matching~~ (It's not true,
  because ActualFunctionWithDefaultParameters is declared as WEAK
  incompatibility)
2023-08-10 15:46:46 +00:00
Nikita Bobko ab8913dee8 [FE] Cover "implicit actualization"/"actual fake-overrides" KT-58544 with regression tests
Review: https://jetbrains.team/p/kt/reviews/11039/timeline
2023-08-10 15:46:45 +00:00
Alexey Merkulov e4ae15b3f0 [FIR] Allow resolve to private members from debugger evaluator
KT-60714
2023-08-10 13:40:52 +00:00
Alexey Merkulov 1714fb71c8 Tests: check errors from code fragment resolution 2023-08-10 13:40:52 +00:00
Nikolay Lunyak b7d1298f20 [FIR] Report UNSUPPORTED_SEALED_FUN_INTERFACE
^KT-59957 Fixed
2023-08-10 13:36:43 +00:00
Dmitriy Dolovov 8be98da1d3 [PL] Halt compilation when there are linkage issues logged with the ERROR severity
^KT-61097
2023-08-10 13:21:34 +00:00
Alexander Shabalin 288163437d [K/N] Remove legacy MM runtime modules ^KT-59121 2023-08-10 13:20:41 +00:00
Nikolay Lunyak f6e9e9379d [FIR] Drop redundant TODOS
It was decided to do so in the
corresponding tickets.

^KT-59828 Declined
^KT-59821 Declined
2023-08-10 12:55:03 +00:00
Denis.Zharkov 1eb0c606da Add clarification comments to some shouldKeepTypeVariableBasedType impls
^KT-61090 Related
2023-08-10 12:54:09 +00:00
Alexander Shabalin 6b50d0a44f [K/N] Make GC scheduler pausing less aggressive ^KT-61091 2023-08-10 11:21:30 +00:00
Ilya Gorbunov ca7e494124 Remove redundant dependency checksums
They are no longer resolved due to alignment
2023-08-10 10:35:54 +00:00
Ilya Gorbunov aaa068596c [Gradle] Disable stdlib-jdk7/8 alignment from 1.9.20
Reason: kotlin-stdlib now publishes Gradle metadata with the required dependency constraints for these artifacts

KT-55297
2023-08-10 10:35:54 +00:00
Ilya Gorbunov 0882c645dd [stdlib-mpp] Move dependency constraints to api dependencies, KT-55297
Constrained alignment is also required for compile time dependencies
2023-08-10 10:35:54 +00:00
Dmitrii Gridin 5d336e8649 [FIR] typeFromCallee: do not leak code 2023-08-10 10:35:21 +00:00
Mark Mann 8a31e2ed82 [IR] Optimize a few hot spots to reduce total CPU time
^KT-61121
2023-08-10 09:57:06 +00:00
Alexander Shabalin 83a70ddf8b [K/N] Decouple ObjectFactory from concrete ObjectData ^KT-60928
* Use type_layout to declaratively express heap object headers in both
  custom allocator and ObjectFactory.
* Invoke constructor (w/o invoking Kotin constructors) for created
  objects and arrays from both custom allocator and ObjectFactory.
  Previously:
  - custom allocator only checked body for nullability (now this is
    performed in body constructor)
  - ObjectFactory only constructed ObjectData
* In each GC have a AllocatorImpl.hpp and ObjectData.hpp headers
  the first encapsulating allocator-specific types, the second
  containing specific ObjectData implementation.
* In each GC have a separate ObjectFactoryTraits that does not
  actually depend on the specific GC anymore.
* Each GC now expose ObjectData (as undefined type) and its descriptor,
  the latter being used by the custom allocator and ObjectFactory.
* Descriptors for ObjectBody and ArrayBody now live in Memory.h and the
  code calculating size is now shared. Their constructors check that the
  memory is zeroed (Kotlin constructors will expect this).
2023-08-10 07:58:27 +00:00
Alexander Shabalin d956a5504d [K/N] Add a helper for objects with custom layout ^KT-60928 2023-08-10 07:58:27 +00:00
Nikolay Lunyak 70e98c9c2b [FIR] Report inherited java members referencing FunctionN
^KT-60000 Fixed
2023-08-10 05:14:08 +00:00