Commit Graph

6792 Commits

Author SHA1 Message Date
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
Yan Zhulanow fefa72fa29 [BE] Use more generic 'FacadeClassSource' in 'parentClassId'
In the IDE's evaluator, the container source for stub-based FIR
declarations is a different implementation of 'FacadeClassSource'.
2023-07-26 16:03:44 +00:00
Pavel Kunyavskiy 38ef5be217 [K/N] Don't store private signatures in symbol table
Refactoring in 4986cb14 introduced an unintentional behavior change:
private symbols are now findable in symbol table with lookup by
signature.

Unfortunately, this is not correct - private symbol signature might not
be unique (or at least was sometimes not unique in older compiler
versions), which leads to crashes on deserializing corresponding klib.

This commit restores old behavior.

^KT-60616
2023-07-26 12:03:26 +00:00
Ilya Chernikov 3dc94f3d31 Scripting: fix descriptor extraction, restore main-kts testing
Temporary solution for K1 - see comments in the code
it seems that a scenario reproduced in the MainKtsTest.testKt48812
wasn't covered with analogous changes before.
And it wasn't detected while main-kts tests weren't a part of the
K1 scripting tests.
The test is fixed now, and testing of main-kts is restored.
2023-07-26 08:49:27 +00:00
Ilya Chernikov 895a811b47 K2 Scripting: fix capturing from the imported scripts 2023-07-26 08:49:27 +00:00
Ilya Chernikov 020a590df7 K2 Scripting: fix order of arguments processing
and base class handling:
Since in K2 we do not distinguish between script arguments taken from
the base class and provided properties, we need this extra functionality
to preserve the argument order of K1 scripts.
This is a temporary measure, since we're going to deprecate base class
usage at some point (KT-60449), so the relevant constructor arguments
should disappear too.
2023-07-26 08:49:27 +00:00
Ilya Chernikov 96bde033e1 K2 Scripting: add support for imported scripts 2023-07-26 08:49:26 +00:00
Svyatoslav Kuzmich 384c700a85 [Wasm] Fix access to WebIDL dictionary members
Evaluate external interface companion objects as an empty JS object
instead of null due to null checks on interop boundary.

^KT-59082 Fixed
2023-07-25 15:27:22 +00:00
Alexander Udalov 971b4e63e7 JVM: support enumEntries intrinsic for Java & old Kotlin enums
#KT-59710 Fixed
2023-07-25 09:55:43 +00:00
Alexander Udalov 874d1c514a JVM: support enumEntries intrinsic for Kotlin enums
Implementation is very similar to the `enumValues` intrinsic.

Java enums and old (pre-1.9) Kotlin enums will be supported in a
subsequent commit.

 #KT-59710
2023-07-25 09:55:43 +00:00
vladislav.grechko e5763a692f Substitute type arguments to return type of inlined function references
Such substitution is crucial on codegen stage if the return type is
reified (e.g. for `Array`)

^KT-59507: Fixed
^KT-59281: Fixed
2023-07-24 22:11:59 +00:00
Sergej Jaskiewicz f5a00c788a [klib] Disable ManglerChecker on K2
`ManglerChecker` is a class that verifies that for each IR declaration
(except some, see its `needsChecking` property) its mangled name
(computed from IR) is the same as the mangled name computed from its
frontend representation — `DeclarationDescriptor` on K1 or
`FirDeclaration` on K2.

The way it does it is as follows.

On K1, `ManglerChecker` looks if the declaration has a true,
non-IR-based descriptor, it if it does, then it checks it
(see ManglerChecker.Companion#hasDescriptor).

On K2, since we don’t have any descriptors, `ManglerChecker` looks if
the declaration’s metadata property is `null` (because the corresponding
`FirDeclaration` is stored there). If it’s not, it checks it
(see ManglerChecker.Companion#hasMetadata).

The issue is that those two conditions are not equivalent.

When the Compose compiler plugin transforms an IR function, it copies
its `metadata` property (as it should, because `metadata` can contain
anything, not necessarily the frontend representation), but doesn't set
the descriptor. Because of that, on K1 that transformed function is
skipped in `ManglerChecker`, and on K2 it’s not.

The correct usage would be to properly distinguish which declarations
come from the FE as is, and which are transformed/synthesized,
and skip the latter. But it is unclear how to implement this.

For now, the easiest way to fix this on K2 is to not run ManglerChecker
at all.

KT-60648
^KT-59448 Fixed
2023-07-24 19:29:17 +00:00
Igor Yakovlev e8e8a26cd1 [Wasm] Fixed invalid delegated property getters lowering
#Fixed KT-58941
2023-07-24 18:15:16 +00:00
Sergej Jaskiewicz d77af3c43d [IR] Remove unnecessary ReplaceWith from deprecated methods in IrFactory
ReplaceWith doesn't do anything when deprecation level is HIDDEN.
2023-07-24 17:42:45 +00:00
Sergej Jaskiewicz 8aa0b6a562 [IR] Automatically generate IrFactory interface
^KT-59308 Fixed
2023-07-24 17:42:45 +00:00
Sergej Jaskiewicz c2a8d46867 [IR] Restore compatibility for IrFactory#createPropertyWithLateBinding
This is a follow-up to b4335c86c8.
2023-07-24 17:42:45 +00:00
Ivan Kylchik a56b462eb6 [IR] Reuse IR utils functions to find methods of Any in interpreter 2023-07-24 17:20:39 +00:00
Ivan Kylchik 1eca5d1a3b [IR] Rewrite how interpreter works with the Unit result
This way interpreter works in more correct way. Every expression
produces some result, and if we don't need it, the interpreter will
discard it.
2023-07-24 17:20:39 +00:00
Ivan Kylchik 6204119219 [IR] Simplify logic of constructing unsigned number in interpreter
This way it is a little less "hacky". We are looking only for "data"
property, and as long as this property is declared in constructor, we
can safely assume we will get the correct one even if it is
renamed.
2023-07-24 17:20:39 +00:00
Ivan Kylchik d795ce3582 [IR] Simplify logic of interpretCall
Drop excess call of `callStack.loadState(it)` when store state for
extension receiver. When we interpret lambda with extension receiver,
this receiver will be actually represented as a value parameter,
and it required some additional processing. Apparently, after all
interpreter's refactorings, this does not matter anymore and excess
call can be dropped.
2023-07-24 17:20:39 +00:00
Sergej Jaskiewicz b57b4e055e [klib] Move some duplicated code from subclasses to IdSignatureBuilder 2023-07-24 16:40:15 +00:00
Sergej Jaskiewicz ce6e904b70 [klib] Don't forget to set signatures' descriptions before serialization
Ensure that in IdSignatureBuilder hashId/hashIdAcc is only set
together with the description.

In 6142d75bb4 we implemented setting
descriptions when building signatures from descriptors, but forgot to
do the same for building signatures from IR, resulting in missing
descriptions in klibs.

See also: KT-59486
2023-07-24 16:40:14 +00:00
marat.akhin 8eabaff29e [IR] Support IrStarProjection in TypeArgumentMarker.replaceType 2023-07-24 12:15:41 +00:00
marat.akhin a2dda9e25b [IR] Transfer type annotations when substituting via IR substitutor
Other type substitutors (classic, cone-based) respect the type
annotations and copy them to the resulting type for all
cases, including type parameters.

Without this change we cannot correctly match expect/actuals
when we replace actual type parameters with expect ones in case
the actual type parameter has type enhancement annotations
(e.g., `@FlexibleNullability`).

We transfer all annotations (and not conservatively copy only type
enhancement annotations), as 1) other substitutors do that 2) other
IR type substitution utilities (e.g., `IrType.substitute`) do that.
As we will attempt reimplementing all IR type substitution utilities
via IrTypeSubstitutor, it also makes sense to completely align
the behavior.
2023-07-24 12:15:41 +00:00
Roman Efremov 6611a55a60 [FE] Relax rules of matching @Target annotation on expect and actual
Allow `expect` targets to be subset of `actual`.

^KT-58551
2023-07-24 09:48:49 +00:00
Roman Efremov ad84c83ee9 [FE] Skip more special annotations in KMP annotation matching
Many errors are reported in stdlib with these annotations
(SinceKotlin, Deprecated, so on).
But having them only on expect is a valid case. E.g. SinceKotlin added
if some old platform-specific API becomes commonized.

^KT-58551
2023-07-24 09:48:49 +00:00
Roman Efremov 234f453173 [FE, IR] Don't check SOURCE annotations if actual declaration has no source
^KT-58551
2023-07-24 09:48:49 +00:00
Roman Efremov 59f1a0dd8e [FIR, IR] Refactor: move annotation retention helper functions
Will be needed in subsequent commit to be accessible in
ExpectActualMatchingContext implementations.

^KT-58551
2023-07-24 09:48:48 +00:00
Roman Efremov 454756a2b5 [IR] Don't check annotations on expect/actual fake overrides
^KT-58551
2023-07-24 09:48:48 +00:00
Roman Efremov 2980179bd7 [IR] Implement IR checker for expect actual annotations matching
^KT-58551
2023-07-24 09:48:48 +00:00
Roman Efremov 1a4ab9bb4b [FE] Implement FE logic of expect actual annotations matching
This implementation only checks annotations set on expect/actual
declarations and requires further refinement (e.g. checking of other
annotation targets, class scopes within typealiases).

^KT-58551
2023-07-24 09:48:48 +00:00
Pavel Kunyavskiy d797505f06 [K/N] Drop merging forward and real declaration in deserializer
^KT-59643
2023-07-24 08:24:20 +00:00
Javier Segovia Córdoba e4c2fa1080 [IR] Improve printing the value parameter when there is an error 2023-07-23 00:16:46 +02:00
Alexander Udalov f7ba1b4a7a IR: minor, improve assertion error message
KT-60502
2023-07-21 20:57:41 +00:00
Shagen Ogandzhanian eb7805baf9 [KT-59294] [wasm] Resolve undefined to null for any nullable types in external functions 2023-07-21 19:13:57 +00:00
Zalim Bashorov 5d1379ead1 [Wasm] Optimize when using br_table only if all conditions read and compare the same variable
#KT-60212 Fixed
2023-07-21 17:27:16 +00:00
Alexander Udalov 56ed240774 JVM: rename IrIntrinsicFunction -> IntrinsicFunction
To avoid confusion that this might be an IR tree element.
2023-07-21 14:55:22 +00:00
Alexander Udalov f8faa0fe5a JVM: cleanup intrinsics code
Remove unused methods, remove dependency on old backend structures,
reformat, fix some inspections.
2023-07-21 14:55:21 +00:00
Sergej Jaskiewicz f061215ee9 [IR] Reorder parameters in IrFactory#createFunctionWithLateBinding
This is to prepare for IrFactory auto-generation (KT-59308).
2023-07-21 13:12:37 +00:00
Sergej Jaskiewicz 3828552a1c [IR] Make IrFunctionWithLateBinding a subclass of IrSimpleFunction 2023-07-21 13:12:37 +00:00
Sergej Jaskiewicz d16445aef2 [klib] Drop the addDebugInfo setting that was always true 2023-07-21 12:51:47 +00:00
Sergej Jaskiewicz b4335c86c8 [IR] Add a new parameter to IrFactory#createPropertyWithLateBinding
This is to prepare for IrFactory auto-generation (KT-59308).
2023-07-20 19:58:47 +00:00
mvicsokolova 5c5367d377 [atomicfu-JVM] Preparation for commonization of JVM and K/N transformers
The following updates in the JVM/IR plugin were made:
* Lots of refactoring with preparation for K/N support: commonization of transformations.
* Improved error handling (checks for visibility constraints, appending message about usage constraints in case of an error).
* Explicit requirements for the visibility of atomic properties: to prevent leaking they should be private/internal or be members of private/internal classes.
* Fixed visibility of generated properties: volatile properties are always private and atomic updaters have the same visibility as the original atomic property.
* Volatile fields are generated from scratch and original atomic properties are removed.
* Delegated properties support is fixed (only declaration in the same scope is allowed).
* Non-inline atomic extensions are forbidden.
* For top-level atomics: only one wrapper class per file (with corresponding visibility) is generated.
* Bug fixes.

The corresponding tickets: 
https://github.com/Kotlin/kotlinx-atomicfu/issues/322
KT-60528



Merge-request: KT-MR-10579
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
2023-07-20 13:59:23 +00:00
Zalim Bashorov 8d440a61e2 [Wasm] Make types for none and noextern consistent with the spec 2023-07-20 11:49:28 +00:00
Ivan Kylchik 30c00f7983 [IR] Specify explicitly that classes from Java can be interpreted
In early prototypes of interpreter, it was easier to assume that
all classes from Java can be interpreted and fix something if not.
Check for Java declaration was done by checking that the package name is
starting with "java". But this is actually wrong and can lead to errors
when some code is declared in "java" something package, but is not from
Java stdlib.

#KT-60467 Fixed
2023-07-20 09:40:42 +00:00
Sergej Jaskiewicz 212c10e674 [IR] Restore source compatibility for IrFactory methods
Previous commits:
c2fde1a915,
0b7db067e6,
0ae95b39c3,
f46761a241,
b1f7b5e982,
2b4a08524d,
5b8b3644fc,
7b77ec9930,
30cd2c3025,
9fcdc10019

have reordered parameters in IrFactory methods.

Restore and deprecate the original methods to
preserve source compatibility for compiler plugins.

KTIJ-26314
^KT-59772 Fixed
2023-07-20 09:36:05 +00:00
Ivan Kylchik 7fd601b336 [JVM_IR] Unify code between fake variables lowerings
#KT-58778 Fixed
2023-07-20 09:01:43 +00:00
Ivan Kylchik 1dec9fc675 [JVM_IR] Move methods that generate LN into LineNumberMapper class 2023-07-20 09:01:43 +00:00
Ivan Kylchik b10f6907a7 [JVM_IR] Slightly rewrite SwitchGenerator to improve readability 2023-07-20 09:01:42 +00:00
Ivan Kylchik ecd20b1348 [JVM_IR] Properly handle inlined local var located in regenerated object
#KT-58778
2023-07-20 09:01:42 +00:00