Commit Graph

235 Commits

Author SHA1 Message Date
Dmitriy Novozhilov c70a6425f5 [FIR2IR] Don't insert not-needed upcasts for smartcasted expressions
Related to KT-63257
2023-11-10 07:50:00 +00:00
Mikhail Glukhikh 290adda8fc Calculate empty array literal types in FIR2IR instead of deserializer
This commit handles situations when some annotation in deserialized code
has an empty array literal argument [] or even non-empty [something].
Before this commit, we tried to guess a type of this array by "resolving"
the relevant annotation class and looking into the corresponding
parameter. Sometimes it can work, but also it can provoke recursive
resolve e.g. when the annotation class is a nested class in the same scope.
In this commit we changed the behavior in the following way:
- first, for non-empty array literals in deserialized code we just
take the array type from the corresponding array literal element
- second, for empty array literals we no more try to "guess" anything.
Instead we approximate array type as Array<Any>, and later at FIR2IR
stage we use the corresponding parameter type instead. At FIR2IR stage,
everything is already resolved and problems with recursions are no more
possible.

#KT-62598 Fixed
2023-10-31 12:30:29 +00:00
Dmitriy Novozhilov 3d6ec0ec75 [FIR2IR] Automatically store IR declaration in its parent upon creation
Previously, creating a declaration with Fir2IrCallableDeclarationsGenerator/
  Fir2IrClassifiersGenerator didn't guarantee that this declaration will
  be actually added to the list of parent class/file declarations, which
  lead to situations when FIR2IR created some declarations in the air
  (mostly fake-overrides)
2023-10-17 12:46:27 +00:00
Pavel Kunyavskiy cd409abfd8 [Fir2IR] Fix dispatch receiver of fake override lazy function
After the fix, it's at least consistent with what generated
for other fake overrides.

^KT-61386
2023-09-21 13:09:32 +00:00
Ivan Kochurkin 3cd4f7c3aa [FIR] Consider @PlatformDependent annotation everywhere (including JS and Native)
^KT-57858 Fixed

Remove FirEmptyOverridesBackwardCompatibilityHelper since it's not used anymore

Remove overridesMemberWithPlatformDependent.kt test file since it becomes redundant
2023-09-20 17:12:52 +00:00
Alexander Udalov 019836e9c7 IR: use origin DEFINED for value parameters of fake overrides
Fake overrides created by K1, as well as fir2ir in K2, use DEFINED. So
this gets rid of a lot of differences in IR text dumps between the K2
normal mode and K2 with IR fake overrides, and will ultimately help in
implementing and testing KT-61360.

The change in AddContinuationLowering is needed to fix tests like
kt47549. When creating anonymous classes for SAM implementations, we're
reusing the same fake override building machinery. And since we can't
extract any meaningful information from the fake override parameter's
origin anymore, we have to get the parameter from the original symbol.
2023-09-15 12:52:57 +00:00
Pavel Kunyavskiy 91e96e9f31 [Fir2Ir] Introduce testing with IrFakeOverrideBuilder
^KT-61514
2023-08-31 13:12:15 +00:00
Dmitriy Novozhilov d4f55894b4 [FIR2IR] Properly calculate dispatch receiver type for fake overrides
If some function is not fake-override, then its type should be just
  default type of containing class
For fake overrides the default type calculated in the following way:
1. Find first overridden function, which is not fake override
2. Take its containing class
3. Find supertype of current containing class with type constructor of
   class from step 2

^KT-60252 Fixed
2023-08-25 21:06:15 +00:00
Mikhail Glukhikh 2ff075c961 FIR2IR: use ELVIS origin only on wrapping blocks #KT-60250 Fixed 2023-08-22 11:20:19 +00:00
Kirill Rakhman bd6af5cc42 [FIR2IR] Set correct modality of lazy annotation classes
#KT-60268 Fixed
2023-08-18 09:43:40 +00:00
Leonid Startsev 7f795f212f Support instantiation of Java annotations with defaults
For annotations defined in Java, IrProperties do not contain initializers in backing fields,
as annotation properties are represented as Java methods.
Therefore, it is not possible to use initializer values as default values for constructor parameters.

However, K2 stores default values in annotation's constructor parameters,
so it is possible to fix this issue if they're properly transfered to the IR
and inspected in JvmAnnotationImplementationTransformer

#KT-47702 Fixed
#KT-47702 tag fixed-in-k2
2023-08-03 10:25:13 +00:00
Leonid Startsev 648c1f4599 Support instantiation of annotations with type parameters
By ignoring type parameters. Since type parameters in annotations are a
very limited feature, their sole use is to be able to specify them as
KClass argument: annotation class Foo<T: Any>(val bar: KClass<T>).
Since we can encounter type param only as a KClass type argument (and
never as a property type), simple approach of ignoring them works fine.
In that case, since we simply copy property types to synthetic
implementation class, its properties in IR start look like this:
annotation class FooImpl(override val bar: KClass<T of Foo>). This IR
seems to be not completely correct, since FooImpl.bar type contains T of
Foo param, which is out of its scope. However, so far I didn't
encounter any problems with this during testing and after MR discussion
this approach has been considered possible.

#KT-59558 Fixed
#KT-59036 Fixed
2023-07-26 17:16:13 +00:00
Leonid Startsev 5f21244b99 Additional test case for annotation instantiation: empty arrays by default.
#KT-59035
2023-07-17 12:40:04 +00:00
Kirill Rakhman feed740415 [FIR2IR] Don't copy default value to annotation call with vararg parameter
This aligns the behavior with K1 and fixes an issue when the default
value was deserialized as FirExpressionStub leading to an exception
in FIR2IR when trying to convert it to an IR expression.

#KT-60120 Fixed
#KT-59610 Fixed
2023-07-17 11:42:39 +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
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
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
Alexander Udalov be4df35867 Tests: add FILE directives to some multimodule tests
To help them run on the old infrastructure, which light analysis tests
are still using.
2023-06-13 17:48:23 +00:00
Ilmir Usmanov 95662234d0 JVM: Support instantiation of annotations with vararg parameters
when they are instantiated without argument.
 #KT-59033 Fixed
2023-06-06 17:27:52 +00:00
Sergej Jaskiewicz f2031ae642 [IR] Don't print multifile/synthetic facade class names in irText tests
This only applies to JVM and fq-names in declaration references
in IR dumps.

This enables us to run more irText tests on platforms other than JVM
(see KT-58605).
2023-06-05 10:40:17 +00:00
Sergej Jaskiewicz 56b729f181 [test] Fix failing IR dump test 2023-06-01 13:22:01 +00:00
Sergej Jaskiewicz fd76a34277 [IR] Don't print flags in declaration references in irText tests
This doesn't reduce the quality of tests, because the flags are still
printed for declarations themselves. We only omit them in references.

However, this makes the tests more compatible with non-JVM backends
(see KT-58605), because flags of referenced stdlib declarations may
differ among target platforms.
2023-05-30 17:26:30 +00:00
Kirill Rakhman d1ce55cbd2 [FIR2IR] Fix infinite loop between annotation and annotation parameter
When an annotation constructor value parameter is annotated with the
very same annotation, FIR2IR went in an infinite loop when trying
to generate it.
To fix this, the constructor is added to the Fir2IrDeclarationStorage
cache before generating the value parameters.
To accommodate for the missing parameters, the value arguments count
is determined using the FIR.
2023-05-30 15:53:12 +00:00
Kirill Rakhman 9ca9fc9c68 [FIR2IR] Set type arguments on annotation calls
#KT-58553 Fixed
2023-05-30 07:58:03 +00:00
Alexander Udalov e4e1bcefbd JVM: remove tests on JVM target 1.6 2023-05-19 13:23:59 +00:00
Sergej Jaskiewicz 56f977f70c [IR] Don't render facade classes in JVM fq-names in irText tests
This makes the tests more compatible with non-JVM backends
(see KT-58605)
2023-05-17 12:43:35 +00:00
Leonid Startsev c4255f9a9e [K2] Instantiation of annotations having default values for properties
This commit adds missing pieces for the puzzle:

Annotation instantiation feature uses IrProperty's initializer to instantiate
properties from other modules that have default values which weren't
specified on call site.

To support this feature properly, Fir2IrVisitor should fill LazyIrProperty's
backing field initializer with information from Fir.

To get this information into Fir, FirMemberDeserializer should be able to read
it from KotlinJvmBinaryClass with AnnotationLoaderVisitorImpl. (klibs are unsupported for now)

There's a catch with enum entries references: we can't access session.SymbolProvider to resolve it
because we're still at the deserialization stage, and it can cause StackOverflow if enum is nested in the
same class (see RequiresOptIn.Level). To mitigate this, a new FirEnumEntryDeserializedAccessExpression is produced
instead; it is later replaced with the correct reference in the Fir2IrVisitor.

^KT-58137 Fixed

Also add test to loadJava folder with annotations default values that
verifies metadata loading
2023-05-12 16:08:02 +00:00
Pavel Kunyavskiy 2f3947d8e5 [K/N] Unmute some actually passing tests 2023-05-09 09:15:41 +00:00
Mikhail Glukhikh dc38ce24f7 K2: fix field annotation splitting and frontend checks
Related to KT-57135
2023-04-25 12:18:26 +00:00
Pavel Mikhailovskii 37ed7beda0 KT-57135 Take into account annotations' allowed targets
- Check allowed targets
- Attach field annotations to the backing field
2023-04-25 12:18:26 +00:00
Ivan Kylchik 5956e9b500 [IR] Print evaluated const directly into interpreter's tests 2023-04-19 13:52:44 +00:00
Nikolay Lunyak caa7bee917 [FIR] KT-57835: Prevent the compiler crash
^KT-57835 Fixed
2023-04-12 10:20:44 +00:00
Dmitriy Novozhilov af05646fe3 [FIR] Don't expand typealiases in annotations during type deserialization
During extracting type attributes from annotations we should expand
  typealiases of annotation type to handle cases when user makes a typealias
  on some special annotation, like `kotlin.internal.Exact`. And to exapnd
  typealias we should resolve annotation class id to symbol.
This leads to a cycle during class deserialization, if some nested annotation
  is used as type annotation in some declaration in the same class

```
interface SomeInterface {
    interface NestedInterface : @Ann Some

    interface Some

    @Target(AnnotationTarget.TYPE)
    annotation class Ann
}
```
Attempt to find symbol for SomeInterface.Ann during deserialization of
  SomeInterface.NestedInterface wil lead to second attempt to deserialize
  class SomeInterface, which eventually leads to StackOverFlow. And at the
  same time expanding typealiases for annotations from binaries has not
  much sense, because types in binaries are already expanded

So to fix this issue it's enough to just not expand typealiases on type
  annotations for types of deserialized declarations

^KT-57876 Fixed
2023-04-11 16:02:57 +00:00
Ilya Gorbunov b8da3e69ce KT-55268 Make k.c.Volatile stable 2023-04-08 15:07:56 +00:00
Igor Yakovlev 993334e5e4 [Wasm] Support feature InstantiationOfAnnotationClasses 2023-04-04 18:39:17 +00:00
Nikolay Lunyak bcfafc601e Add EnumEntries to minimal-stdlib-for-tests
This change allows to revert adding `WITH_STDLIB` directive
to tests which happened at `a9343aeb`.

Co-authored-by: Alexander Udalov <Alexander.Udalov@jetbrains.com>
2023-03-02 10:23:38 +00:00
Kirill Rakhman eee66ab43f [FIR] Remove duplicate annotations from primary ctor params/properties
If an annotation doesn't specify an explicit use-site target,
previously it was added to both, the primary constructor value parameter
and the property in the FIR. Then, in FIR2IR, only the "correct" one was
added to the IR. Move up the deduplication logic into the frontend.

^KT-56177 Fixed
2023-02-28 10:19:17 +00:00
Dmitriy Novozhilov aef9b129d2 [FIR] Add regression tests for number of issues fixed in K2
List of issues:
KT-4113,  KT-6822,  KT-7389,  KT-17817, KT-20223
KT-21463, KT-24503, KT-24737, KT-24779, KT-24901
KT-27261, KT-28668, KT-30497, KT-30756, KT-36958
KT-37365, KT-37490, KT-38288, KT-41038, KT-41721
KT-42136, KT-42169, KT-42449, KT-42715, KT-43553
KT-43603, KT-43846, KT-43936, KT-46288, KT-46301
KT-47373, KT-47484, KT-47490, KT-47495, KT-47750
KT-47815, KT-47870, KT-48975, KT-49024, KT-49045
KT-50134, KT-50160, KT-50550, KT-51045, KT-51143
KT-51796, KT-52262, KT-52424, KT-52860, KT-52934
KT-53086, KT-53494, KT-53671, KT-53752, KT-53819
KT-54478, KT-54518, KT-54931, KT-54990, KT-55138
KT-55379, KT-55555, KT-56243
2023-02-14 17:08:55 +00:00
Nikolay Lunyak a9343aeb7d [FIR] KT-55840: Ensure everything actually works
This inconsistency is present due to not using the `// WITH_STDLIB`
in the above tests. When K1 creates the enum, it tries to generate
`entries()`, and for that it tries to load `kotlin.enums.EnumEntries`,
but this is actually an unresolved reference. K1 silently swallows it,
and proceeds.

The reason K2 doesn't fail is that in order to generate `entries()` it
simply creates the necessary `ConeClassLikeType` with the desired
`classId` instead of loading the whole `ClassDescriptor`.

The reason we can still observe `$ENTRIES` and `$entries` in K1
is because they are generated during the JVM codegen, and it
only checks if the `EnumEntries` language feature is supported. It
doesn't check if the `entries` property has really existed in IR
(by this time it's expected to have already been lowered to the
`get-entries` function - that's why "has ... existed").

The reason why the codegen doesn't fail when working with
`kotlin.enums.EnumEntries` is because it creates its
own `IrClassSymbol`.

^KT-55840 Fixed

Merge-request: KT-MR-8727
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-02-10 16:57:51 +00:00
Ivan Kylchik bc21753877 Move IR interpreter's tests from ir/loweredIr directory into box 2023-01-27 10:52:56 +00:00
Ilya Gorbunov 916f733f73 Make k.c.Volatile since 1.9 in JVM and Common KT-55268, KT-55609
Leave it experimental since 1.8 for K/Native.
2023-01-04 17:28:46 +00:00
Vladimir Sukharev 924898afb7 [K/N] KFC-446: K2 platform: Native alpha
Merge-request: KT-MR-7905
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-01-04 16:10:40 +00:00
Mikhail Glukhikh 0d50f71fb8 K2: expand type aliases in annotation position #KT-55615 Fixed 2023-01-04 10:06:39 +00:00
Ilya Gorbunov e2d96da396 Introduce experimental kotlin.concurrent.Volatile annotation KT-55268, KT-55609
Use this annotation in tests to ensure it works the same at least on JVM
2022-12-23 19:07:30 +01:00
Dmitriy Novozhilov 9946bfcdfd [FIR2IR] Properly handle error references in generation of receivers
^KT-53698 Fixed
2022-12-09 12:02:06 +00:00
Dmitriy Novozhilov f3da26946b [FIR] Change priority of K2_VISIBILITY_ERROR CandidateApplicability
In K1 analogue of `K2_VISIBILITY_ERROR` is `K1_RUNTIME_ERROR`, so
  candidates with `K2_VISIBILITY_ERROR` should win over innaplicable
  candidates with `INAPPLICABLE`, `INAPPLICABLE_ARGUMENTS_MAPPING_ERROR`
  or `INAPPLICABLE_WRONG_RECEIVER` applicability

This is needed to allow resolution to invisible symbols (and later
  suppress error with `@Suppress("INVISIBLE_SYMBOL", "INVISIBLE_REFERENCE")`

^KT-55026 Fixed
^KT-55234
2022-12-09 12:02:05 +00:00
Dmitriy Novozhilov 6c6525ecde [FIR] Add test for KT-55026 2022-12-09 12:02:04 +00:00
Ivan Kylchik a1477983ba Properly handle vararg interpretation for classic frontend
#KT-55108 Fixed
2022-11-24 11:07:07 +00:00
Ilya Chernikov 7e4ee399c8 FIR JS: temporarily mute remaining codegen tests 2022-11-12 16:28:25 +01:00