Commit Graph

5871 Commits

Author SHA1 Message Date
Ilya Chernikov 684d0b8690 K2 IC: filter out builtins lookups
Do not record lookups to kotlin builtins, since it is considered
useless.

Related to #KT-66417
2024-03-12 11:38:06 +00:00
Mikhail Glukhikh c4bcdc42c1 K2: don't count use-sites of Java type parameter with nullable bounds as not null 2024-03-11 18:05:04 +00:00
Wojciech Litewka 2ed0ffd123 [IR] Autogenerate IrExternalPackageFragmentImpl
#KT-65773 In Progress
2024-03-07 14:32:31 +00:00
Jinseong Jeon 9c16c52564 AA: pass wildcard suppression hints on declarations
^KT-61734
2024-03-07 10:17:00 +00:00
Jinseong Jeon 94e5653eb7 Migrate utils to check/alter TypeMappingMode according to suppress wildcard annotations
^KT-61734
2024-03-07 10:16:59 +00:00
Jinseong Jeon 5d730233cd Migrate Jvm(Suppress)?Wildcard(s)? FqName (and ClassId) 2024-03-07 10:16:58 +00:00
Alexander Udalov d430673320 JVM IR: optimize type equality check on IR types
`AbstractTypeChecker.isCommonDenotableType` calls a few functions which
check if the type is flexible, which is not cheap in case of JVM IR, see
`asFlexibleType`.

 #KT-66281
2024-03-06 22:03:10 +00:00
Dmitriy Novozhilov e8f8399af4 [FIR2IR] Properly cache generated data/value class members
FIR instances of generated toString/hashCode/equals are session dependant,
  so we need some cache, which operates only session-independent stuff.
  Pair of `FirClass` and `Name` was chosen here

Previously SymbolTable played the role of this cache (with signatures as
  keys). But it should be replaced in scope of KT-66341 and KT-64990
2024-03-06 08:28:24 +00:00
Roman Golyshev 69426e2129 [kotlin] Add a small KDoc to getAllSuperClassifiers function 2024-02-28 16:16:40 +00:00
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