Commit Graph

5862 Commits

Author SHA1 Message Date
Mikhail Glukhikh 91e9fbd9bf K1: change depr. level of List.getFirst to HIDDEN but don't force it on overrides
#KT-65441 Fixed
2024-02-27 08:40:53 +00:00
Roman Golyshev 47aa6392bf KT-64808 [stubs] Materialize all synthethic declarations in Kotlin Stubs
Here is the reasoning behind that change:

Historically, all the declarations generated by compiler plugins
were marked with `SYNTHESIZED` member kind in Kotlin Metadata
by K1 compiler.

In K1 IDE, descriptors were deserialized directly from the Kotlin
Metadata, and they saw all the generated declarations from it.

In the stubs, however, such declarations were not materialized at all.
It caused no troubles, since K1 IDE relied on descriptors to get the
essential resolution information in completion and other subsystems.
So, the resolution of members from jars processed
by compiler plugins (e.g. `kotlinx-serialization-json`) was mostly fine.

In K2 IDE, however, we use stubs to "deserialize" FIR declarations from
them, to later create `KtSymbol`s upon that FIR.

If we see a library file which was processed by compiler plugins, we
build stubs for it based on the Kotlin Metadata, and then use stubs to
create FIR.
But if stubs do not contain information about the generated
declarations,
then the resulting FIR will also not contain such declarations.

In the end, the K2 IDE would also be blind to such declarations, since
there is no other way to retrieve them from the library jar.

By meterializing all the synthethic declarations in stubs (with some
minor exceptions for data classes), we would avoid such problems,
and the resolve of such declarations from compiler jars in
K2 IDE would become possible.

Important note: currently, the Kotlin Metadata format between K1 and K2
frontends is not 100% the same; most notably, in K2, the generated
declarations are marked as regular declarations,
not as `SYNTHESIZED` ones.

Hence, if you compile a jar with the current version of K2 frontend,
then all the generated declarations would have a regular `DECLARATION`
origin, and there would be no such issues as described above.

There are two notes here:

1. K2 IDE still has to support the jars compiled by the K1 compiler,
so it still makes sense to alter the stubs and make the generated
declarations visible.
2. The issue about the different stub formats has been reported
(see KT-64924), and might be resolved in the future.
So it is possible that K2 frontend's metadata will also start
marking the generated declarations as `SYNTHESIZED`.

^KT-64808 Fixed
2024-02-23 10:51:28 +00:00
vladislav.grechko d753a22fc6 [FIR] Handle expect declarations in JVM backend
1. Do not generate bytecode for expect declarations

2. Serialize @OptionalExpectation annotations into .kotlin_module file

^KT-62931: Fixed
2024-02-19 18:17:37 +00:00
Dmitriy Novozhilov acf2296590 [Test] Regenerate tests after two previous commits 2024-02-16 12:48:24 +00:00
Dmitriy Novozhilov d9beae0556 [Test] Change indent from four to two spaces in generated tests
This is needed to reduce the size of generated test files, which started
  to exceed default IDE limit
2024-02-16 12:48:24 +00:00
Nikolay Lunyak 8f8c7fe7cf [FIR] Properly calculate visibilities
`testIntersectionOfPrimitiveBasedFunctions`
is fine, because we deprecate this
already in ^KT-63243.

`CANNOT_INFER_VISIBILITY` is
positioned as `DECLARATION_NAME`,
just in case we decide for
some reason that we do want to
report it along with
`MANY_*_NOT_IMPLEMENTED`. In that
case, we'd get a problem that
their bounds overlap, but not
completely contain one another.

^KT-63741 Fixed
^KT-59400 Fixed
2024-02-15 16:10:14 +00:00
Dmitriy Novozhilov c64575f4a2 [FIR] Move check for _private-to-this_ visibility into checker
^KT-55446
^KT-65790 Fixed
2024-02-15 13:08:35 +00:00
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
cristiangarcia 15227d655f Builtins serializer logger is not required anymore
...and modifying jvmArguments in doFirst breaks ConfigurationCache
Required for KTI-1553
2024-02-13 11:22:25 +00:00
wrongwrong a5bf8787a1 Reflection: exclude DEFAULT_CONSTRUCTOR_MARKER when calculating mask size
#KT-65156 Fixed
2024-02-09 17:54:16 +00:00
Alexander Udalov 7d584e0eb4 K2/Java: add initial version of FirJvmPlatformDeclarationFilter
#KT-57268 In Progress
2024-01-30 19:44:00 +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
cristiangarcia c53ac2e91f Update Proguard to 7.4.1 2024-01-25 11:36:31 +00:00
Yan Zhulanow c8af3381d6 [Stubs] Fix stub inconsistency on unnamed setter parameters
If an unused setter parameter was replaced with an underscore ('_'),
it had a special name in the stub ('<anonymous parameter 0>'). The text
version of the stub inserted it as is, leading to an extra
'PsiErrorElement'.

^KTIJ-28194 Fixed
2024-01-24 18:41:42 +00:00
Dmitriy Novozhilov cb3f41f669 [Test] Don't override manually registered services during test configuration
There are two ways of test service registration:
- manual call to `useAdditionalServices` in abstract test runner
- using of `additionalServices` property in one of test entity (e.g. in handler)

Services are registered in the same order (manual first, automatic second)

This led to the situation that if there was registered more specific
  implementation of the service in the test configuration, it will be
  overridden with regular implementation from handler, which is fixed
  by this commit
2024-01-24 10:45:00 +02:00
Roman Golyshev bb044bb57e [docs] Improve formatting in JavaToKotlinClassMap docs
Add `-` symbols to form a proper list
2024-01-17 14:28:35 +00:00
Kirill Rakhman 251827c9aa [FIR] Don't approximate captured types
This fixes some type argument mismatch errors caused by a captured type
being approximated and then captured again.
Some places need to be adapted to work with captured types that
previously only worked with approximated types.

#KT-62959 Fixed
2024-01-17 08:20:05 +00:00
wrongwrong ab76f94aa7 Reflection: minor, fix obsolete comment
InlineAwareCaller has already been renamed.
2024-01-16 20:03:58 +00:00
Mikhail Glukhikh c3c215b6a4 CallableId: return pathToLocal to constructor (KT-58739) 2024-01-16 18:26:41 +00:00
Mikhail Glukhikh 34877130c7 Refactor callableId around pathToLocal and classId properties
#KT-58739 Fixed
2024-01-15 18:46:51 +00:00
Denis.Zharkov 2db031d71e Drop unused createDeprecatedAnnotation
^KT-60858 Fixed
2024-01-12 16:59:42 +00:00
Sergej Jaskiewicz eda30ff704 [klib] Implement diagnostics for clashing KLIB signatures
Now, we detect clashing signatures during serialization to KLIB and
report a compiler error if two or more declarations have the same
`IdSignature`

For example, for the following code:
```kotlin
@Deprecated("", level = DeprecationLevel.HIDDEN)
fun foo(): String = ""

fun foo(): Int = 0
```

the compiler will produce this diagnostic:
```
e: main.kt:1:1 Platform declaration clash: The following declarations
       have the same KLIB signature (/foo|foo(){}[0]):
    fun foo(): String defined in root package
    fun foo(): Int defined in root package
e: main.kt:4:1 Platform declaration clash: The following declarations
       have the same KLIB signature (/foo|foo(){}[0]):
    fun foo(): String defined in root package
    fun foo(): Int defined in root package
```

Note that we report this diagnostic during serialization and not earlier
(e.g., in fir2ir) for more robustness, so ensure that we check
exactly the signatures that will be written to a KLIB.
If we later introduce some annotation for customizing a declaration's
signature (e.g., for preserving binary compatibility), this
diagnostic will continue to work as expected.

^KT-63670 Fixed
2024-01-12 15:59:28 +00:00
Denis.Zharkov 276f5b26d8 K2: Implement partially constrained lambda analysis (PCLA)
It's expected to partially mimic the behavior of what
previously was called builder inference, but with more clear contracts
(documentation is in progress, though)

See a lot of fixed issues in the later commits with test data,
especially [red-to-green]

^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Alexander Udalov 9b5c331c8e IR, descriptors: remove (Ir)ExternalOverridabilityCondition.Result.CONFLICT
No existing external overridability condition reports a conflict anyway,
and there's no support for it in the IR case.
2024-01-09 16:19:14 +00:00
Vladimir Sukharev a78cfff8c9 [K/N] Move more names to NativeStandardInteropNames
^KT-61564
2024-01-09 14:17:47 +00:00
Vladimir Sukharev 7eb239c282 [K/N][Tests] Move objCActionFqName to NativeStandardInteropNames
^KT-61259
2024-01-09 14:17:47 +00:00
Mikhail Glukhikh 0ef41d75b5 K1/K2: consider List.(add/remove)(First/Last) as mutable list methods
#KT-64640 Fixed
2024-01-05 17:20:32 +00:00
Marco Pennekamp 5797b4877c [FIR/AA decompiler] Add tests for sealed interfaces
^KT-62895
2024-01-05 15:55:29 +00:00
Dmitrii Gridin b6d373d8e5 Update copyright to 2024 2024-01-05 13:43:17 +00:00
Pavel Kunyavskiy 32de968531 [Names] Avoid deadlock in initialization of classId constants
StandardClassIds was using Annotations subclass in its initialization.
At the same time, Annotations subclass was using StandardClassIds in its
initialization implicitly through baseId() method.

This leads to a rare deadlock on CI in case where two different threads
tried to initialize both classes at the same time.

It can't be reproduced robustly, as a single thread was able to
successfully initialize both, and will do it on an attempt to
initialize any of them.

^KT-64720 Fixed
2024-01-05 09:53:05 +00:00
Alexander Udalov ee8d42532b Fir2Ir, JVM IR: support flexible Array types loaded from Java
We don't have true flexible types in the IR, but we approximate it with
internal type annotations, such as FlexibleNullability,
FlexibleMutability, RawType. These annotations are then handled
specially in JvmIrTypeSystemContext, which can construct a fake flexible
type so that type checker on IR types would behave exactly as on
frontend types.

As shown in KT-63441, one instance of flexible types where flexibility
was lost during conversion to IR is Java array/vararg types. It's
necessary to support it so that IR fake overrides could be constructed
correctly, because IR fake override checker requires parameter types to
be equal. So this change introduces another internal type annotation,
FlexibleArrayElementVariance, which is only applicable to types with
classifier kotlin/Array, and which signifies that the annotated type
`Array<X>` should rather be seen as `Array<X>..Array<out X>`.

 #KT-63441 Fixed
 #KT-63446 Fixed
2024-01-04 15:54:27 +00:00
Alexander Korepanov d5aaa29a7f [JS FIR] Implement FirJsReflectionAPICallChecker diagnostic
^KT-60899 Fixed
2024-01-02 16:45:12 +00:00
Kirill Rakhman c8b965c102 [FIR] Improve SMARTCAST_IMPOSSIBLE message 2024-01-02 15:17:02 +00:00
Roman Efremov 30aad31ece [FIR, IR] Prohibit actualization of expect Kotlin property to Java field
The problem from KT-63624 was that during matching phase we must choose
only one candidate, but in Java we can have two successfully matched
properties: 1) from field and 2) from method, which overrides Kotlin
property.
See test `propertyAgainstJavaPrivateFieldAndPublicMethod.kt`.
As a result, we choose field candidate, throw away method candidate, and
then fail during visibility check.

Instead of inventing special rule of prioritizing field over method
it was decided to prohibit actualization to Java field at all because:

1. It doesn't seem that Java fields actualization was implemented in K1
on purpose
2. People usually don't use public Java fields, and use instead
private field + getter, especially when compatibility is important, so
it shouldn't be a breaking change

Besides that, such solution simplifies code and is consistent with
the current logic of matcher, which doesn't expect that two members
can be matched successfully. Also, it fixes KT-63624 and KT-63667.

^KT-63624 Fixed
^KT-63667 Fixed
2023-12-20 13:37:43 +00:00
Sergej Jaskiewicz 2096d22e18 [IR] Mark IrBlockBodyImpl with an opt-in annotation
KT-59318
2023-12-19 16:20:02 +00:00
Sergej Jaskiewicz a1970d3d57 [K/N] Move KonanIrModuleSerializer to serialization.native
KT-64392
2023-12-19 15:20:01 +00:00
Sergej Jaskiewicz 3f9de91bec [K/N] Move KonanIrFileSerializer to the serialization.native module
KT-64392
2023-12-19 15:20:01 +00:00
Sergej Jaskiewicz f844a86057 [utils] Introduce the bind function and use it throughout 2023-12-13 10:04:45 +00:00
Ivan Kylchik 79c300209e [K2] Avoid type check for Kotlin's property in ConstUtils
When we check Java field for constant initializer, we could
be asked to get and check the type of Kotlin's property that
is used in this Java field. But there is no guarantee that the type
resolve phase was finished and this type is available. So we just
check for `const` modifier and skip type check.

#KT-63752 Fixed
#KT-62558 Obsolete
#KT-61786 Declined
2023-12-12 13:54:32 +00:00
Sergey Bogolepov ce4eecebf4 KT-63264: Introduce a new ExportedBridge annotation
Swift Export Frontend generates a Kotlin file/library that contains a
set of simple bridging functions that connect Swift wrappers to their
Kotlin counterparts.
There are certain requirements for these wrappers:
1. They should not be DCEd when compiling a binary library.
In other words, these functions are roots.
2. They should provide a stable simple binary name.
3. Their signatures should be much simpler and restricted comparing to
other Kotlin functions.

Altogether, these requirements should be covered by introducing the new
ExportedBridge annotation.

Note: Frontend checks of ExportedBridge functions are not implemented
yet.
2023-12-12 07:03:25 +00:00
Vladimir Sukharev 93af9f33e4 Fix FqNameUnsafe.startsWith() when first segment of fqName is shorter than given segment
FqNameUnsafe("c.C").startsWith("cnames")
must return false
It's a refix of fdf826208f
2023-12-08 16:27:18 +00:00
Artem Kobzar 2eb1e65bbf [K/Wasm] Allow to export unsigned numbers 2023-12-08 09:06:19 +00:00
Alexander.Likhachev a19bd2ed2e [Build] Migrate most of the build logic from Project.buildDir usage
It's going to be deprecated in Gradle 8.3

There's currently no way to pass a `org.gradle.api.provider.Provider` to the JavaExec.systemProperty or Test.systemProperty. There's a workaround using `org.gradle.process.CommandLineArgumentProvider`, but I intentionally don't rework these calls as Gradle is going to allow passing providers to configure system properties: https://github.com/gradle/gradle/issues/12247#issuecomment-1568427242
^KTI-1473 In Progress
2023-12-07 18:31:06 +00:00
Mikhail Glukhikh 06ce57ea56 K2: report MISSING_DEPENDENCY_CLASS for lambda parameters if needed
#KT-62525 Fixed
2023-12-05 18:16:52 +00:00
Leonid Startsev 36703ff9ae Implement strict and lenient modes for Kotlin metadata reading
In strict mode, an exception will be thrown when inconsistent metadata is encountered. In lenient mode, the reader will attempt to handle the inconsistent metadata by ignoring certain inconsistencies. This is a solution to a problem of reading metadata 'from the future' that is not allowed by default, but desired in certain cases. See updated ReadMe for details.

Also fix problem with Strict Semantics flag.

#KT-57922 Fixed
#KT-59441 Fixed
2023-12-01 17:43:11 +00:00
Kirill Rakhman 560c1cacf3 [FIR] Fix capturing of flexible types during resolution
Previously, because we didn't handle flexible types properly in
prepareCapturedType, projections inside flexible types would only be
captured during subtyping with captureStatus=FOR_SUBTYPING
which would lead to the constraint type being wrongly approximated
(see ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint).

Fixing the capturing produced two kinds of false positive diagnostics:

1. In ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint we would get two instances of cone types
that are structurally equal and containing the same captured type.
However, because we only skipped subtyping if the types were
referentially equal, we would get a contradiction here.
The fix was to use structural equality instead, which should be okay
as the captured type instances are the same.

2. Reified type variables were inferred to captured types because
flexible arrays with captured upper bounds
(Array<Foo>..Array<Captured(out Foo)>?) were not properly approximated.

#KT-62609 Fixed
2023-11-30 08:54:26 +00:00
Evgeniy.Zhelenskiy 5258e2044d [FIR] Forbid annotations on anonymous initializers and destructuring declarations
#KT-59896


Merge-request: KT-MR-13197
Merged-by: Evgeniy Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>
2023-11-28 11:59:26 +00:00
Svyatoslav Kuzmich 6b6353f3b9 [Wasm] Add external file checker to K2
#KT-56849
2023-11-27 16:55:04 +00:00
Nikita Bobko 7166adb179 [FIR, IR] Convert FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker into ExpectActualCheckingCompatibility
FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker is an adhoc
checker which can be converted to ExpectActualCheckingCompatibility to
reuse common expect-actual checking infrastructure.

^KT-62913 Fixed
Review: https://jetbrains.team/p/kt/reviews/13094/timeline

Tests that were broken by one of my previous commits are now fixed:
- actualFakeOverride_paramsAreCompatibleViaSharedMethodWithDefaultParams.kt
- inheritedJavaMembers.kt

DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE diagnostic
disappeared in delegation.fir.kt because only one
AbstractExpectActualChecker incompatibility can be reported at a time
(DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE is now reported
not by adhoc checker but by common AbstractExpectActualChecker). It
would be nice to report both of them, but it's a separate issue KT-62631

delegation2 test makes sure that
DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE is reported when
NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS is fixed
2023-11-24 18:02:49 +00:00
Ivan Kochurkin 115d685d91 [FIR] Fix ambiguity of Throws and other std annotations importing
Including `SharedImmutable` and `ThreadLocal`

Simplify code, remove `DefaultImportPriority.KOTLIN_THROWS`

Introduce `FirNativeClassMapper`
2023-11-23 23:51:23 +00:00