24 Commits

Author SHA1 Message Date
Nikolay Lunyak afd8895e51 [FIR] Introduce the PluginGenerated source kind
Make parcelize work consistently with
`FirOverrideChecker`.

Actually, there is a philosophical question about
what to do when a plugin generates a class
in a new package, and this class is red code
(for instance, doesn't implement an abstract
member from a supertype). There's no source
to report such an error, but we probably do
want to run checkers to avoid trying to
compile red code to binaries (because it may
crash in backend, or it may silently work).
2024-02-15 16:10:13 +00:00
Alexander Udalov 3f034e8b67 Enable lightweight lambdas (aka invokedynamic) since 2.0
#KT-45375 Fixed
 #KT-58173 Open
2024-02-08 19:46:18 +00:00
Mads Ager e41a1247e2 JVM_IR: Generate more line numbers for intrinsic comparisons.
Otherwise, if complex expressions such as when expressions are
used in combination with the intrinsics we get incorrect stepping
behavior.

^KT-64341 Fixed
2023-12-20 15:39:03 +00:00
Leonid Startsev 6c6f2ccacd Handle non-reified type parameters of function inside serializer<T>() intrinsic
to match an error message thrown from KType-based serializer<T>().

Fixes https://github.com/Kotlin/kotlinx.serialization/issues/2528
2023-12-20 13:50:39 +00:00
Leonid Startsev a03fd2e29a Make visibilities of writeSelf and deserialization constructor in FIR
same as they were in K1 (see KSerializerDescriptorResolver): internal for
final classes and public for non-final.

Unfortunately, there are no Klib API dumps tests in the compiler, so I tested manually.

#KT-64124 Fixed
2023-12-12 09:02:14 +00:00
Leonid Startsev 662bff7351 Make $serializer generic constructor public
If a serializable class has generic type parameters, its serializer is not an object
and has a specialized constructor. This constructor was public in K1 and should
be public in K2 so it can be called from other serializable classes
(in case class is e.g., part of sealed hierarchy).

#KT-63402 Fixed
2023-11-28 13:31:08 +00:00
Mikhail Glukhikh 9d3bf69212 Raw FIR/LT: use similar sources for delegated constructor calls
After this commit all IR source range tests behave in the same way
for FIR/PSI and FIR/LT, test data is now consistent
2023-10-10 13:38:52 +00:00
Sergey.Shanshin 5ba1b36796 [KxSerialization] Change visibility for synthetic functions
- synthetic constructor became internal for final classes
- write$Self became internal for final classes

Resolves https://github.com/Kotlin/kotlinx.serialization/issues/2209

Merge-request: KT-MR-9068
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
2023-07-14 17:36:22 +00:00
Sergey.Shanshin d8d643b7d7 [KxSerialization] Fix "IllegalAccessError: Update to static final field"
Fixes #KT-57647

For value classes, if you add code to companion anonymous init block in IR, it will be executed in the instance constructor. This causes an error when initializing static fields, because writing to them can only occur from the <clinit> method.

The solution is to transfer the static field initialization code from an anonymous init block to the IR initializer of this field

Merge-request: KT-MR-9633
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
2023-04-21 12:37:32 +00:00
Igor Yakovlev 8102744e00 [Serialization] Fix serialization test data 2023-04-04 11:04:18 +00:00
Ivan Kylchik 2b387e7a10 [FIR LT] Get correct startOffset value for declarations with comments
#KT-56913 Fixed
#KT-56926 Fixed
2023-03-21 16:33:00 +00:00
Dmitriy Novozhilov e5b4cf9f04 [Test] Update serialization tests according to KT-56755 2023-02-20 08:40:34 +00:00
Leonid Startsev 80ad6a4cd7 Support plugin intrinsics for serializer() function in K2.
- Add IrPluginContext to JvmBackendContext, so plugin intrinsics can
reference external functions properly.

- Do not use module.findClassAcrossModuleDependencies as Descriptor API does not work for FIR.

- Add asm listing tests in serialization plugin for K2

- Remove Delegated.kt asm listing test as we have similar test in boxIr group.

#KT-56553 Fixed
2023-02-14 13:43:09 +00:00
Leonid Startsev e0dce31cde Support situation when argument for serializer<T>() function has SerialInfo annotations.
Because SerializationJvmIrIntrinsicSupport does not instantiate annotations yet,
this info could be lost. As a workaround, it is possible to call Companion.serializer()
functions instead of direct serializer instantiation, as they are plugin-generated
and correctly handle annotations.

Note that for some cases (enums & interfaces) this WA is not enough, so additional work
is needed later.

Fixes https://github.com/Kotlin/kotlinx.serialization/issues/2179
2023-02-07 16:41:01 +00:00
Pavel Mikhailovskii 06d3e1d8bd KT-55005 Do not generate CHECKCAST before AASTORE 2022-12-21 15:06:07 +00:00
Sergey.Shanshin 339b152390 Implemented caching of child serializers
Resolves Kotlin/kotlinx.serialization#1918

Merge-request: KT-MR-7578
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
2022-11-23 19:53:44 +00:00
Sergey.Shanshin f4845b8dd9 Marked write$Self and $serializer from serialization as synthetic 2022-10-11 17:05:03 +00:00
Leonid Startsev ad2adadb36 Remove OperationType.PLUGIN_DEFINED type:
instead, plugins should emit the code similar to the TYPE_OF one with
a special call to MagicApiIntrinsics.voidMagicApiCall directly afterwards.

This is required because old compiler need to correctly inline code
rewritten by plugin.
2022-09-16 14:34:29 +00:00
Leonid Startsev eae588abea Improve line numbers handling in serialization intrinsic
Fix nullable serializers on top-level & method with incorrect receiver

Improve handling of different runtime versions
2022-09-16 14:34:29 +00:00
Leonid Startsev aac9a06474 Also support intrinsification for SerializersModule.serializer<T>()
method that fallbacks to module.getContextual().
2022-09-16 14:34:28 +00:00
Leonid Startsev a59f5f407b Introduce support for plugin-defined intrinsics in JVM IR backend:
Add intrinsic for kotlinx.serialization.serializer<T>() function.

Plugin intrinsic for old backend is removed because it is too hard
and unjustifiable to unify them.
2022-09-16 14:34:28 +00:00
Leonid Startsev f9edbd825a Introduce support for plugin-defined intrinsics in old JVM backend:
(Old is created first because all intrinsics emit bytecode anyway)

Provide intrinsic for serializer<T>() function so it won't
invoke typeOf() construction and KType->KSerializer conversion
making it fast and truly reflectionless

Add support for recalculating stack size in plugin-defined intrinsics
since it is needed for correct work:
Unify method for recalculating stack size with existing typeOf intrinsic

Add testdata for IR for future intrinsic in IR
2022-09-16 14:34:28 +00:00
Dmitriy Novozhilov a2ffba275c [Serialization] Migrate all tests to new test infrastructure 2022-09-05 10:20:05 +00:00
Dmitriy Novozhilov cc00dcc038 [Serialization] Reorganize module structure 2022-08-22 17:23:18 +03:00