Commit Graph

7816 Commits

Author SHA1 Message Date
Ilya Chernikov 9adf24950a Fir2Ir scripts: fix declarations registration and processing 2023-07-05 19:46:03 +00:00
Ilya Chernikov 5824b9c59c K2 Scripting: add Fir script codegen tests
27 failing tests are muted
2023-07-05 19:46:03 +00:00
Ivan Kylchik d557bcaba4 [IR] Forbid unconditional interpretation of IrGetObjectValue
Earlier we always allowed to interpret `IrGetObjectValue` because
this value is used in const val getter. But now we do a special
check for such getter avoiding visit of `IrGetObjectValue` node.

#KT-59775 Fixed
2023-07-05 13:33:41 +00:00
Kirill Rakhman b68962018c [FIR] Remove incompatible from expect actual matching if compatible exists
This fixes an issue with checking for default values in call resolution
(see FirDefaultParametersResolver) where it is expected that the map
only contains a single compatible entry.

#KT-59613 Fixed
2023-07-05 08:51:01 +00:00
Dmitrii Gridin 09ca335b7e [FIR] CFG: drop redundant edges
Edges from class to its functions and nested classes are redundant
and lead to extra resolution work in lazy resolve mode

^KT-59600 Fixed
2023-07-04 12:07:04 +00:00
Kirill Rakhman 028921ade1 [FIR] Implement checker for value parameter default value type mismatch
#KT-58901 Fixed
2023-07-03 10:11:36 +00:00
Denis.Zharkov 3279313f2c K2: Fix priority for implicit receiver + extensionInvoke
See K1 counterpart at org.jetbrains.kotlin.resolve.calls.tower.TowerResolver.Task.processImplicitReceiver

^KT-58943 Fixed
^KT-59541 Fixed
2023-07-01 16:29:06 +00:00
Abduqodiri Qurbonzoda 209c916a7e OptIn ExperimentalNativeApi 2023-06-30 15:27:09 +00:00
Alexander Udalov f5bbf2b4fe Reflection: create synthetic classes for Java lambdas
... as well as $SwitchMap and other synthetic classes generated by javac
or other JVM language compilers or runtimes.

Note that for Kotlin, all synthetic classes were already handled by the
subsequent check for `KotlinClassHeader.Kind.SYNTHETIC_CLASS`, but after
this change we won't call `ReflectKotlinClass.create` for those, which
is a minor optimization.

 #KT-41373 Fixed
2023-06-30 13:11:41 +00:00
Alexander Udalov 5dc882abf5 Reflection: create synthetic classes instead of throwing UOE
... for Kotlin-generated classes which do not correspond to a "class"
from the Kotlin language's point of view. For example, Kotlin lambdas,
file facade classes, multifile class facade/part classes, WhenMappings,
DefaultImpls. They can be distinguished from normal classes by the value
of `KotlinClassHeader.Kind` (which is the same as `Metadata.kind`).

Another theoretical option would be to throw exception at the point
where the `::class` expression is used, if the expression's type on the
left-hand side is a synthetic class. But we can't really do that since
it'll affect performance of most `<expression>::class` expressions.

So, construct a fake synthetic class instead, without any members except
equals/hashCode/toString, and without any non-trivial modifiers. It kind
of contradicts the general idea that kotlin-reflect presents anything
exactly the same as the compiler sees it, but arguably it's worth it to
avoid unexpected exceptions like in KT-41373.

In the newly added test, Java lambda check is muted but it should work
exactly the same as for Kotlin lambdas and other synthetic classes. It's
fixed in a subsequent commit.

 #KT-41373 In Progress
2023-06-30 13:11:41 +00:00
Alexander Udalov d833b732c9 Reflection: support Java anonymous/local classes
Local classes and anonymous objects are normal classes and
kotlin-reflect can load all declarations and modifiers from them, and
support calling members, exactly in the same way as it does for normal
non-local classes.

 #KT-41373 In Progress
2023-06-30 13:11:41 +00:00
Alexander Udalov 1e031d9fb8 Reflection: add test on introspection of local classes
kotlin-reflect works correctly already for Kotlin-generated local
classes and anonymous objects, but not for Java ones. This is fixed in a
subsequent commit.

 #KT-41373 In Progress
2023-06-30 13:11:41 +00:00
vladislav.grechko a6e45f9b59 Find correct class owner for inlined local delegated properties
Note that call-site class has no metadata for inlined local delegated
properties. Thus, for an inlined local delegated property we should
obtain declaration-site class as owner - otherwise, the corresponding
`PropertyReference` will have an owner without property metadata.
2023-06-29 17:44:25 +02:00
Alexander Udalov f3a7312ee6 K2: use ClassKind.CLASS for object literals
K1 uses CLASS, and libraries like kotlinx-metadata-jvm and
kotlin-reflect already rely on it.

 #KT-57641 Fixed
2023-06-26 20:58:55 +00:00
Vladimir Sukharev 09a0905ffc [Test] Convert IGNORE: NATIVE directives in rest of tests
^KT-59057 Fixed

Merge-request: KT-MR-10794
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-26 07:44:12 +00:00
Svyatoslav Kuzmich a3e2d2804c [Wasm] Update testData after adding K2 and new test infra support.
- Actualize muted K2 tests
- Actualize muted K1 tests with module systems because legacy Wasm test
  infra had no respect for "// MODULE: ..." test directives
2023-06-25 10:20:40 +02:00
Mikhail Glukhikh 0d8f3a6026 K2: generate Java synthetics for Kotlin get/sets w/out type parameters
This commit is a follow-up to d8a20f19 and
provides additional K1 compatibility.
#KT-59550 Fixed
2023-06-23 16:44:50 +02:00
Mikhail Glukhikh fcfee9384a K2: reproduce KT-59550 2023-06-23 16:44:49 +02:00
Vladimir Sukharev 7930885131 [Test] Convert IGNORE: NATIVE directives in box tests from M to R
^KT-59057

Merge-request: KT-MR-10757
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-23 14:15:48 +00:00
Vladimir Sukharev d0dc292c30 [Test] Put descriptive comment to kt49316.kt
^KT-59057

Merge-request: KT-MR-10789
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-23 13:54:24 +00:00
Vladimir Sukharev 5c7d321e45 [Test] Convert IGNORE: NATIVE directives in box tests "sealed"
^KT-59057

Merge-request: KT-MR-10763
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-23 13:53:29 +00:00
Vladimir Sukharev a036e41809 [Test] Convert IGNORE: NATIVE directives in box tests from D to I
^KT-59057

Merge-request: KT-MR-10748
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-23 09:11:17 +00:00
Vladimir Sukharev 503cd6196c [Test] Convert IGNORE: NATIVE directives in box tests specialBuiltins
^KT-59057

Merge-request: KT-MR-10760
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-23 08:07:13 +00:00
Ivan Kylchik 8f88f08573 [FIR] Use correct source for implicit this receiver
#KT-57489 Fixed
#KT-56139 Fixed
#KT-56755 Fixed
2023-06-23 07:23:39 +00:00
Vladimir Sukharev ab03cb2357 [Test] Convert IGNORE: NATIVE directives in box tests sam/* and sameFile*/*
^KT-59057

Merge-request: KT-MR-10758
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-23 06:23:53 +00:00
Ivan Kylchik d1a54a522d [JVM IR] Drop ConstLowering
It basically can be replaced with IR interpreter. The only half-hack
was required in `PropertyReferenceLowering`. Const interpreter is
running before it, so we can't optimize some calls on const
properties that appear after this lowering. Solution is to inline
constants manually during property reference lowering.
2023-06-22 18:49:50 +00:00
Vladimir Sukharev 1bf3bde4f8 [Test] Convert IGNORE: NATIVE directives in box tests from J to J
^KT-59057

Merge-request: KT-MR-10749
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-22 18:39:59 +00:00
Vladimir Sukharev f3fcaa69eb [Test] Convert IGNORE: NATIVE directives in box tests from T to W and boxInline
^KT-59057

Merge-request: KT-MR-10752
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-22 18:33:24 +00:00
Alexander Udalov 1588b07472 Tests: unmute light analysis tests passing with JVM_IR 2023-06-22 17:10:51 +02:00
Alexander Udalov cab53361f3 Use JVM IR backend in light analysis mode tests
Add some more filters on private/synthetic stuff (which doesn't matter
in practice) to make full and light analysis mode dumps as similar as
possible, so that all existing tests will pass for JVM IR. Unmute some
tests which were failing with the old JVM backend.

Tests on repeatable annotations are muted because in full analysis,
annotations are wrapped into the container (e.g. `@A(1) @A(2)` ->
`@A$Container(A(1), A(2))`), but they are no in the light analysis mode.
So there's always going to be a difference for these tests between full
and light analysis, unless we're going to change behavior of kapt, which
would be a kind of a breaking change.

 #KT-58497 Fixed
2023-06-22 17:10:51 +02:00
Alexander Udalov 4ac6f01d31 Add ReplaceWithSupertypeAnonymousTypeTransformer to light analysis tests
To make these tests behave closer to kapt, since kapt is the primary use
case for the light analysis mode.

AbstractLightAnalysisModeTest compares the text dump of bytecode
obtained with full analysis and light analysis, removing things like
anonymous/synthetic entities. In the light analysis mode anonymous
objects in supertypes are always approximated, and in the full analysis
mode they are always present as is in signatures. So we're transforming
the text dump in the same way, by approximating anonymous objects in
signatures (more precisely, in return types of methods and fields) to
the supertype.
2023-06-22 17:10:51 +02:00
Vladimir Sukharev 3e6175fe30 [Test] Convert IGNORE: NATIVE directives in box tests "super"
^KT-59057

Merge-request: KT-MR-10764
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-22 14:50:18 +00:00
Ilya Goncharov d865202bd5 [Wasm] Inline _importModule
^KT-59556 fixed
2023-06-22 13:56:47 +00:00
vladislav.grechko 38e9dfc823 Evaluate apiVersionIsAtLeast on compile time while IR-inlining
IR inliner should evaluate `apiVersionIsAtLeast` on compile-time (except
cases of inlining to inline functions from kotlin runtime) just as
bytecode inliner does.

^KT-59291: Fixed
2023-06-22 11:55:04 +00:00
Vladimir Sukharev 3d60ed8874 [Test] Convert IGNORE: NATIVE directives in box tests from A to C
^KT-59057

Merge-request: KT-MR-10747
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-22 08:39:20 +00:00
Dmitriy Novozhilov 1b24b95cde [FIR] Check for subtyping during actualization of supertypes of expect class
^KT-59356 Fixed
2023-06-22 07:05:31 +00:00
Alexander Udalov 13baf43ae3 K2: fix NSME on toChar for subclasses of Number
Code in `ReplaceNumberToCharCallSitesLowering` relies on `Number.toChar`
being declared in IR as non-abstract. Otherwise the
`resolveFakeOverride` call there doesn't work, and the lowering can't
rewrite the call to `toInt().toChar()`, and we end up with a call to the
missing method `Number.toChar` in the bytecode.

 #KT-57217 Fixed
2023-06-21 14:58:02 +00:00
Kirill Rakhman c867a4b52f [FIR] Don't expand typealiases when checking for DeprecatedSinceKotlin
During serialization, this can lead to a cycle resulting in a Stack
Overflow.

#KT-58356 Fixed
2023-06-21 14:35:43 +00:00
Mikhail Glukhikh b92f1e2036 K2: de-prioritize access to Enum.entries properly #KT-57954 Fixed 2023-06-21 13:08:00 +00:00
Kirill Rakhman ee91ee9403 [FIR] Set publishedApiEffectiveVisibility on deserialized declarations
#KT-58641 Fixed
2023-06-21 07:34:29 +00:00
Dmitriy Novozhilov 2581139b82 [FIR2IR] Expand typealiases before inserting implicit casts
^KT-59461 Fixed
^KT-59464
2023-06-21 07:34:09 +00:00
Abduqodiri Qurbonzoda 9f16daac02 [WASM] Throw IllegalArgumentException on negative array size 2023-06-20 16:31:59 +00:00
Mikhail Glukhikh 8983e3a218 K2: correctly set importedFromObjectOrStaticData for fields
#KT-59140 Fixed
#KT-58980 Fixed
2023-06-20 14:13:21 +00:00
Artem Kobzar 039b5fca7a [K/JS] Use declared upper-bound types for parameters inside inlined functions body, instead of the provided types 2023-06-20 12:01:28 +00:00
Pavel Kunyavskiy 12455451fc [K/N] Call class static initializer in constructors
^KT-59058
2023-06-20 08:41:11 +00:00
Mikhail Glukhikh d8a20f1975 K2: don't generate Java overridden synthetics for Kotlin get/sets
#KT-59038 Fixed
2023-06-20 07:07:10 +00:00
vladislav.grechko e4f1c10bc1 [JVM_IR] Do not compile-time evaluate apiVersionIsAtLeast in stdlib
Function `apiVersionIsAtLeast` was introduced to be able to have
different inline function content inlined to user code call sites
depending on their api version settings. Thus, it should not be
compile-time evaluated when being called in the body of inline stdlib
function.

^KT-59452: Fixed
2023-06-19 16:24:57 +00:00
Evgeniy.Zhelenskiy 2d920df507 [IR] Fix KT-59346, KT-55993
#KT-59346
#KT-55993
2023-06-19 12:36:08 +00:00
Dmitriy Novozhilov d972b78627 [FIR] Allow actualization of expect classes by classes with wider visibility
^KT-59355 Fixed
2023-06-19 11:09:32 +00:00
Abduqodiri Qurbonzoda 295fdc36ce Enum.valueOf throws inconsistent exception across multiple platforms #KT-35116 2023-06-16 22:18:20 +00:00