Commit Graph

492 Commits

Author SHA1 Message Date
wrongwrong a5bf8787a1 Reflection: exclude DEFAULT_CONSTRUCTOR_MARKER when calculating mask size
#KT-65156 Fixed
2024-02-09 17:54:16 +00:00
vladislav.grechko 54858c2118 [FIR] Fix naming of local classes when serializing metadata
^KT-63655: Fixed
^KT-63901: Fixed
^KT-63988: Fixed
2024-02-07 12:30:50 +00:00
Mikhail Glukhikh 672b5ba0d7 K2/Java: implement platform-dependent function filtering in JvmMappedScope
We drop Kotlin function 'remove' or 'getOrDefault' from JvmMappedScope,
if it has platform-dependent annotation, and the bound Java class scope
does not contain a function with the same signature.

#KT-57268 Fixed
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
vladislav.grechko f318b5969d Erase non-reified type parameters by-default when inlining.
Substitution of type arguments to non-reified type parameters may lead
to accidental reification, which should not be done (see ^KT-60174 for
examples). So, we should erase them, except the few cases.

^KT-60174: Fixed
^KT-60175: Fixed
2024-01-26 18:31:20 +00:00
vladislav.grechko 34bac48541 Add JVM ABI K1/K2 consistency tests 2023-12-26 10:18:19 +00:00
Alexander Udalov 931c2ce47a Reflection: fix calling suspend fun returning value class over primitive
#KT-47973 Fixed
2023-10-20 08:50:26 +00:00
Evgeniy.Zhelenskiy b89d8a65a1 [Reflection] Fix parsing JVM function descriptors
#KT-60708
2023-10-19 19:09:31 +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
Ilmir Usmanov 184b5cebe7 Minor. Add regression test for KT-60136
Spread operator works incorrectly in K1, but correctly in K2.
 #KT-60136 Fixed
2023-09-05 15:11:36 +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
Alexander Udalov a58a1a3398 Reflection: do not try to box COROUTINE_SUSPENDED
#KT-58887 Fixed
2023-08-18 10:35:34 +00:00
Alexander Udalov d4b5599373 Add JVM target bytecode version 21
Unfortunately, there are still problems with running JVM backend tests
with JVM target 21 because:

1) The D8 version that we use does not support bytecode version 21, and
   updating to a newer version requires to change JVM target of compiler
   tests to 11. This will be addressed separately when we enable JVM 21
   in tests-different-jdk.
2) Some tests are failing because of KT-60659 and KT-60770:
   - builtinStubMethods/bridgesForStubs/emptyStringListAdd.kt
   - jdk/stream.kt
   - regressions/kt528.kt

 #KT-60662 Fixed
2023-08-03 08:43:22 +00:00
vladislav.grechko cfcdc6f0ae [JVM_IR] Box primitive types in class literals of reified type arguments
Bytecode inliner boxes primitive types in class literals of reified type
arguments. This is by design, and we should backport this behaviour to
IR inliner.

^KT-60144: Fixed
2023-08-02 10:48:22 +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
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
Vladimir Sukharev 05e22e56d3 [K/N] Mark rest of reflection related tests as jvm-only
^KT-59057

Merge-request: KT-MR-10570
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-06-16 11:50:03 +00:00
Alexander Udalov 23fb96378e Tests: remove duplicate LANGUAGE test directives
To help them run on the old infrastructure, which light analysis tests
are still using.
2023-06-13 17:48:23 +00:00
Alexander Udalov b992e698e4 Minor, add regression test for KT-58772
#KT-58772
2023-06-08 15:42:27 +00:00
Pavel Kunyavskiy 15e5adf2b5 Mark reflection related tests as jvm-only 2023-06-07 14:59:38 +00:00
Pavel Kunyavskiy 733ca5a358 [K/N] Unmute tests already working on native
Also, add issue references for some tests
2023-06-06 14:29:21 +00:00
Nikita Bobko 4be7ac930b Update KClass.isData KDoc to include info about data objects
^KT-58985 Fixed
Review: https://jetbrains.team/p/kt/reviews/10385

`isData` returns `true` for `data object`s even if kotlin-reflect
version is old (1.2.0), so it looks like we got correct `KClass.isData`
behaviour for "free". That's why this behaviour was never covered with
tests.

This commit updates the documentation and covers the behaviour described
in the KDoc with tests.
2023-06-01 12:09:15 +00:00
Ilmir Usmanov d7fd2471b8 JVM IR: Remove remains of 1.2 coroutines from tests
Remove CoroutineAdapter and LANGUAGE: +ReleaseContinuation,
which are meaninless now.
Update the tests accordingly.
2023-05-31 05:56:18 +00:00
Dmitriy Novozhilov fdc236296d [FIR2IR] Generate @FlexibleMutability annotation on IR types if needed 2023-05-24 14:07:32 +00:00
Dmitriy Novozhilov af60681705 [FIR] Save declarations in metadata in source order
^KT-54792 Fixed
^KT-54801
^KT-54800
2023-05-09 07:36:32 +00:00
Alexander Udalov cd9209a7ee JVM: enable -Xlambdas=class in some codegen tests
Most of these tests check the specific structure of lambdas when they
are generated as classes, and they start to fail once invokedynamic
lambdas are enabled by default.
2023-04-28 21:34:19 +00:00
Evgeniy.Zhelenskiy 8c748bfea4 [IR] Add more tests for inline/value classes secondary constructors
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-55333
2023-04-17 12:10:14 +00:00
Igor Yakovlev 993334e5e4 [Wasm] Support feature InstantiationOfAnnotationClasses 2023-04-04 18:39:17 +00:00
Mikhail Glukhikh 563781a246 K2: serialize data class equals / hashCode / toString functions
#KT-57510 Fixed
2023-03-28 09:30:02 +00:00
Ivan Kylchik b812a6c6f5 Ignore tests that are currently not working with IR inliner 2023-03-14 20:47:42 +00:00
Evgeniy.Zhelenskiy 88f293d4a9 [IR] Support reflection for MFVC
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-1179
2023-03-07 21:44:43 +00:00
wrongwrong b039f2e574 Fix ArrayStoreException from InlineClassAwareCaller.call
#KT-56650 Fixed
2023-02-27 14:29:51 +01:00
Svyatoslav Kuzmich 26c1098a4f [Wasm] Fix inliner issues (KT-56584)
* Fix objects in inline functions and lambdas:
  * Add common lowerings used in K/JS and K/Native
* Fix inline lambda call detection logic in presence of additional casts


Merge-request: KT-MR-8791
Merged-by: Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com>
2023-02-13 13:14:43 +00:00
Alexander Udalov c58314fddf Reflection: improve and optimize kotlinFunction/kotlinProperty
- Make the implementations very similar, to fix KT-54833 where the
  companion object case was forgotten for kotlinProperty.
- Optimize both functions to look up the function/property by name
  first, to cover the most probable case when the JVM name of a
  declaration is equal to its Kotlin name. This fixes KT-55937.

 #KT-54833 Fixed
 #KT-55937 Fixed
2023-01-23 20:43:00 +01:00
Artem Kobzar 71486a321c [K/JS] Add support of compilation with ES-classes 2023-01-17 18:14:17 +00:00
Ilya Chernikov 78ca733c38 FIR JS: add K2 variants of all other JS tests
except tests that are not possible to add without some modifications in
the test infra. See todos on the commented-out test declarations
2022-11-12 16:28:24 +01:00
Ilya Chernikov 5b3816cce5 Test infra: refactor IGNORE_BACKEND directive
treat it as a general one, introduce *_K1 and *_K2 variants for
more specific ignoring
2022-11-12 16:28:23 +01:00
Alexander Udalov 4dcf50d483 Fix reflection for repeated annotations with array arguments
This is related to 8308f5d7d3 (KT-44977).

It turns out that it's necessary to create `ArrayValue` with a
precomputed type not only in case of annotations stored directly in
Kotlin metadata (i.e. annotations on types and type parameters), but
also for arguments of repeated annotations. The reason is that repeated
annotations are stored in an array themselves, as an argument to another
(container) annotation. The annotation-reading code unwraps this array
to load repeated annotations as individual instances of
`AnnotationDescriptor`, but in contrast to loading normal annotations,
it doesn't set `source` to the reflection object, it uses `NO_SOURCE`
(see BinaryClassAnnotationAndConstantLoaderImpl.AbstractAnnotationArgumentVisitor.visitArray).

So when kotlin-reflect is later asked for the arguments of the
annotation, it needs to recreate the reflection object from
`AnnotationDescriptor` in `util.kt`. Doing so requires knowing the array
type, which is now present because we're creating a `TypedArrayValue`
(previously `DeserializedArrayValue`) in places where arrays are read as
annotation arguments.

Alternative solution would be to fix source passed to
`AnnotationDescriptorImpl` in the annotation-reading code, but that
seems a bit messy because the code is very abstract and is used in lots
of other places.

 #KT-53279 Fixed
2022-10-07 10:48:51 +00:00
Alexander Udalov 51ce829b96 Fix reflection class lookup in default package
Do not append "." to the name of the class in the default package.
2022-10-07 10:48:51 +00:00
pyos 8d33de4297 JVM: partially reify typeOf and signatures as soon as possible
E.g. when substituting T -> Array<T>, write the bytecode for the
Array<...> part for typeOf.

This fixes various issues where either Array nesting levels, nullability
information (for typeOf), or entire reification markers were missing,
causing incorrect outputs ranging from missing `?`s to missing `[]`s to
just reified types not really being reified.

^KT-53761 Fixed
2022-10-06 00:58:25 +02:00
Alexander Udalov ba150ca370 Add JVM target bytecode version 19
Test data in `box/annotations/typeAnnotations` is changed because nested
classes in type annotations are rendered differently in JDK 19
(`Outer.Nested` instead of `Outer$Nested`).

 #KT-54116 Fixed
2022-09-22 21:56:10 +02:00
Pavel Mikhailovskii f8fd23e373 KT-8575 Add tests and disable reflection for Java synthetic property references 2022-09-22 13:33:28 +00:00
Svyatoslav Scherbina 0021333b91 [Native][test] Unmute more passing tests
They now pass likely due to better handling of reflection information
when renaming packages when grouping tests (see cee0731).
2022-08-23 17:05:59 +00:00
Vsevolod Tolstopyatov e32e5c26a4 [reflect] Fix flaky tests that depend on Reflection.clearCaches()
* Use ReflectionFactoryImpl as single point of synchronization
* Synchronize all cache-sensitive tests on it in order to be robust in parallel test runners
* Remove redundant cache clear after each test

Merge-request: KT-MR-6842
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
2022-08-12 14:10:08 +00:00
Mikhail Glukhikh 7333589663 K1/K2: add Enum.entries unconditionally and filter them out in tower
Before this commit, we added Enum.entries only in case when
LanguageFeature.EnumEntries was ON (with an exception in K1/Java case).
In this commit we add Enum.entries unconditionally, and in case
the language feature is OFF we filter them out during tower resolve.
2022-08-12 09:35:27 +00:00