Commit Graph

6296 Commits

Author SHA1 Message Date
Ilmir Usmanov 01c670194a FIR2IR: Do not add fake override if the member is overridden
#KT-56398
2023-02-24 14:24:12 +00:00
Alexander Udalov 5f4a560899 Fix binary compatibility with AS 222/223 in PhaseConfig
(cherry picked from commit a419120cbd6050417945a0e9f411213debd15b77)
2023-02-24 14:23:52 +00:00
Svyatoslav Kuzmich 54a45c49f8 [Wasm] Add Wasm platform and K1 FE infrastructure 2023-02-24 01:05:23 +01:00
Alexander Udalov d73d3c46e2 K2 JVM IR: fix access to Java field shadowed by Kotlin property
#KT-56386 Fixed

Co-authored-by: Mikhail Glukhikh <Mikhail.Glukhikh@jetbrains.com>
2023-02-23 12:54:00 +01:00
Alexander Udalov 641d636c45 JVM IR: improve generation of receiver for bound callable references
Trick codegen into generating getfield from the anonymous class instead
of its supertype (e.g. kotlin.jvm.internal.FunctionReference,
PropertyReference or AdaptedFunctionReference). This gets rid of
unnecessary accessors in some cases, and will help in the subsequent
commit that changes logic around access to fields from Java
superclasses.
2023-02-23 12:54:00 +01:00
Dmitriy Dolovov 4b1f739c89 [PL] Don't use trove4j in partial linkage 2023-02-23 11:40:19 +00:00
Alexander Udalov 22b4b29292 IR: make most properties mutable 2023-02-22 22:40:34 +00:00
Alexander Udalov d2938e732a IR: remove IrTypeOperatorCall.typeOperandClassifier 2023-02-22 22:40:34 +00:00
Alexander Udalov 42daeaaa80 IR: remove IrCallableReference.referencedName
It was added in 66da676b9e to avoid dependency on descriptors, but now
it doesn't use descriptors anyway, so it's better to inline it than have
it in the interface.
2023-02-22 22:40:33 +00:00
Alexander Udalov d286409b76 IR: make IrComposite.isTransparentScope an extension 2023-02-22 22:40:33 +00:00
Ilmir Usmanov bfa2937fb8 FIR2IR: Do not add fake override if the member is overridden
#KT-56398 Fixed
2023-02-21 17:18:01 +01:00
Alexander Korepanov 3c9d653595 [JS IR] Ignore unbound symbols in IC infrastructure
The IR linker is responsible for detecting unbound symbols,
 if it skips them for some reason, IC infrastructure must not fail
 with unbound symbols exceptions. Anyway, the IR validator
 verifies later if there are unbound symbols in
 reachable IR and generates the corresponding error.

^KT-56602 Fixed
2023-02-21 14:46:44 +00:00
Ivan Kylchik 477d092bb8 Avoid object's interpretation with nullable type
#KT-56215 Fixed
2023-02-20 15:52:52 +00:00
Alexander Korepanov e107de6f36 [JS IR] Use a guard file for preventing incremental caches corruption
If a developer interrupts (kill gradle process) a compilation process or
 an internal error interrupts the compilation process,
 the incremental cache files may be corrupted.
 The patch creates a special guard file, which allows detecting
 if the previous compilation was not successful,
 and in case of any issues drops the incremental cache files.

^KT-56581 Fixed
2023-02-20 13:14:30 +00:00
Alexander Udalov b152600e35 IR: add flag to IrGenerationExtension for executing in kapt mode
#KT-56635 Fixed
2023-02-17 14:00:54 +00:00
Dmitriy Novozhilov 30ea4b6b53 [FIR2IR] Adapt IrActualizer to HMPP modules
Previously it collected actual declaration only from platform module
2023-02-17 11:08:51 +00:00
Ilmir Usmanov b262070922 JVM IR: Copy type parameters from outer class to suspendImpl
Previously we copied only type parameters from containing class, but we
need to do that for outer classes as well.
 #KT-55125
2023-02-15 13:43:24 +00:00
Alexander Korepanov 43cef114c6 [Compiler CLI] Sort flags and features before appending them to string
JS IR BE incremental compilation infrastructure uses
 LanguageVersionSettings::toString method to detect if any
 compiler features or flags were enabled or disabled.
 It is important that the features and flags order are stable
 in the result string.

^KT-56580 Fixed
2023-02-15 13:24:11 +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
Alexander Korepanov 121c920099 [JS IR IC] Load only top level signatures for function type interfaces
The dependency signature may refer to function type interface properties
 (e.g. name) or methods. It is impossible to detect (without hacks)
 which binary symbol for loading is required. However, when loading
 a property or a method the entire function type interface is loaded.
 And vice versa, a loading of function type interface loads
 properties and methods as well. Therefore, load the top level signature only,
 it must be the signature of function type interface.

^KT-56582 Fixed
2023-02-14 13:25:19 +00:00
Igor Chevdar 0655b02097 [IR] Proper error message for IR validation 2023-02-14 07:30:46 +00:00
Igor Chevdar 1e8cd91e0f [IR] Fixed wrong IrCall type (to fix IR validation) 2023-02-14 07:30:45 +00:00
Igor Chevdar 18e213426c [IR] Fixed wrong IrConst type (to fix IR validation) 2023-02-14 07:30:45 +00:00
Igor Chevdar 3dad0cfb05 [IR] Fixed wrong IrCall type (to fix IR validation) 2023-02-14 07:30:45 +00:00
Igor Chevdar 5e6aa649ed [IR] Extracted implicitCastIfNeeded to common utils 2023-02-14 07:30:44 +00:00
Igor Chevdar ea2ce2b52e [IR] Fixed wrong parents 2023-02-14 07:30:44 +00: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
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
Pavel Mikhailovskii 4c7f8ba196 KT-56457 Annotate Enum.entries with @NotNull 2023-02-09 20:13:56 +00:00
Ivan Kochurkin 241f457943 [IR] Use full name for expect/actual functions linking, simplify code
Don't put type parameters to expect-actual map since it's useless

^KT-56329 Fixed
2023-02-08 17:21:34 +00:00
Alexander Korepanov c82b4f6fe5 [JS IR] Append source mapping URL every time on writing JS code
Source mapping URL is not saved in JS module cache anymore,
 because it was a wrong url pointed to the source map from the cache.
 Instead, the URL is appended every time on writing the output JS code.

^KT-56469 Fixed
2023-02-08 11:04:43 +00:00
Ivan Kochurkin d401ff7b09 [FIR & IR] Implement JS MPP test infrastructure
^KT-55295 Fixed
2023-02-07 14:16:29 +00:00
Ilmir Usmanov e42efe1ee6 JVM IR: Ignore class type parameters if function is static
Otherwise, it leads to type parameters duplication in case of
suspendImpls, since they inherit type parameters from containing class.

 #KT-56407: Fixed
2023-02-07 13:39:25 +00:00
Ilmir Usmanov c7bc439661 JVM IR: Remove usages of PSI in coroutines codegen
Instead, use IR based reporter.
2023-02-07 13:12:19 +00:00
Alexander Udalov 1844869e8a Kapt+JVM_IR: fix ordering of properties in generated stubs
Apparently it depended on the ordering of the synthetic `$annotations`
methods generated for properties. And those methods were always
generated at the end of a Java stub by kapt because they lacked PSI
element, and thus `ClassFileToSourceStubConverter.convertClass` could
not compute their source position, and it placed them at the end as all
other synthetic methods.

The solution is to provide PSI element for `$annotations` methods in
JvmDeclarationOrigin. This origin is then collected in kapt in
`OriginCollectingClassBuilderFactory` and used for sorting, as in the
case of the old JVM backend.

 #KT-56360 Fixed
2023-02-06 21:34:10 +00:00
Denis.Zharkov 6d7096b5e9 IR: Fix StackOverflowError caused by using DNN type in lambda
^KT-54140 Fixed
2023-02-03 14:08:57 +00:00
Zalim Bashorov f3e022e4ca [Wasm] Print an instruction if CompileError was thrown while instantiating a module
#KT-56160 Fixed
2023-02-03 14:06:32 +01:00
Alexander Korepanov 9324cf3360 [JS IR] Support function type interfaces in incremental cache infrastructure
The patch removes logic of generating extra IrFiles (fake file) into
 IrModuleFragment for the function type interfaces during klib deserialization,
 because IC infrastructure can not process files which do not exist in klib.

 Instead of adding extra IrFiles during deserialization, the empty files
 with required packages are added into Kotlin/JS stdlib physically.
 These files are used as containers for function type interface declarations.

 Since Kotlin/WASM uses the same klib loading infrastructure as Kotlin/JS,
 the the empty files are added into Kotlin/WASM stdlib as well.

 The patch also adds a check that IrModuleFagment has files only from klib.

^KT-55720 Fixed
2023-02-03 12:23:48 +00:00
Marco Pennekamp 1c3c5417ad [JVM IR] KTIJ-24335 Fix stub generation of symbols without descriptors
- Symbols without a descriptor (e.g. `IrClassPublicSymbolImpl`) were
  causing exceptions in `DeclarationStubGenerator` after recent changes,
  because their property `irClassSymbol.descriptor` doesn't necessarily
  exist without the symbol having an owner bound to it first.
- `DeclarationStubGenerator` now falls back to its `descriptor` argument
  if `irClassSymbol` doesn't have a descriptor.
2023-02-03 12:23:11 +00:00
Marco Pennekamp e7bf4da796 [JVM IR] KTIJ-24335 Require stubbing for built-in symbol deduplication
- Built-in symbol deduplication has only been tested with stubbing
  enabled. Because there is no current use case for deduplication
  without stubbing, an exception will be thrown to communicate the
  misconfiguration.
2023-02-03 12:23:10 +00:00
Marco Pennekamp d1df6391db [JVM IR] KTIJ-24335 Fix stub generation of deduplicated built-ins
- Some built-in symbols like `OptIn` haven't been created yet by the
  time `irBuiltIns` is bound to `SymbolTableWithBuiltInsDeduplication`.
  This caused an issue where `DeclarationStubGenerator` would get the
  built-in symbol from `referenceClass`, but still stub for the original
  duplicate `descriptor` and its associated own symbol. Because
  `generateClassStub` would check `referenceClass.isBound` for the
  built-in symbol, `isBound` was never checked for the duplicate symbol
  and thus a "symbol already bound" exception occurred if
  `generateClassStub` was invoked twice for a duplicate `descriptor`.
- The solution takes the descriptor from the `IrClassSymbol` returned
  by `referenceClass`.
2023-02-03 12:23:10 +00:00
Marco Pennekamp f11ea92601 [JVM IR] KTIJ-24335 Deduplicate class symbols of duplicate built-ins
- When the IR backend is invoked from the bytecode tool window,
  multiple descriptors may exist of the same built-in. For example,
  there may be multiple descriptors for `Boolean`.
- This caused issues when the `IrClassifierSymbol` of a type was used
  as a key for some built-ins map (such as `primitiveRefProviders` in
  `JvmSharedVariablesManager`). Because while the reference map is
  built from predeclared built-ins, with duplicate descriptors,
  multiple `IrClassifierSymbol`s may exist for the same type. Such a
  duplicated symbol would lead to an exception.
- The solution invents a special symbol table which de-duplicates
  built-ins at the point where `IrClassSymbol`s are created.

I tried other approaches:

- It's possible to fix the symptoms in `JvmSharedVariablesManager` and
  `JvmSymbols` by turning the keys of the requisite maps, i.e.
  `primitiveRefProviders` and `arraysCopyOfFunctions`, from
  `IrClassifierSymbol` to something like a `Name` or `PrimitiveType`.
  This however touches the IR backend beyond the IDE and still leaves
  error potential for all the other possibly duplicated built-ins.
- I tried to handle built-ins in `DeclarationStubGenerator` specially,
  to circumvent the issue of duplicated descriptors, but this is not a
  solution because the duplicated `IrClassSymbol`s will already be part
  of the IR at that point.

^KTIJ-24335 fixed
2023-02-03 12:23:09 +00:00
Marco Pennekamp ba2e716682 [JVM IR] KTIJ-24206 Stub getters/setters of orphaned expect properties
- Property getters and setters are not marked as `isExpect` even if the
  corresponding property is. This commit fixes the generation of actual
  stubs for such functions.
2023-02-03 12:23:09 +00:00
Marco Pennekamp c9461a3827 [JVM IR] KTIJ-24206 Add an option to stub orphaned expect symbols
- The cause for KTIJ-24206 is that the `expect` function's parent is an
  `IrFile` instead of an `IrClass`. This is because
  `ExpectDeclarationsRemoveLowering` removes `expect` declarations
  before `FileClassLowering` can replace `IrFile` parents.
- That behavior is normally okay, but breaks down when an `expect`
  declaration has no associated `actual` declaration. In such cases,
  `ExpectDeclarationsRemoveLowering` doesn't replace `expect` symbols in
  expressions with their corresponding `actual` symbols, as it normally
  would.
- The solution fills in `ExpectDeclarationsRemoveLowering`'s behavior
  by replacing `expect` symbols for which no `actual` symbols exist with
  stubs. See `stubOrphanedExpectSymbols`.
- To not mess with the lowerings, `stubOrphanedExpectSymbols` is invoked
  during IR generation. It uses the same `ExpectSymbolTransformer`
  as `ExpectDeclarationRemover`.

^KTIJ-24206 fixed
2023-02-03 12:23:09 +00:00
Igor Chevdar c871ccc4dd [K/N][IR] Turned off partial tail call optimization
It is difficult to implement properly tail calls for a real coroutine (when there
are other non tail calls), because of continuation interception semantics. And the
benefits aren't clear at this point, so let's turn it off for now.
2023-02-03 11:14:53 +00:00
Igor Chevdar 716853dd00 [K/N][IR] Tail call optimization for suspend lambdas 2023-02-03 11:14:53 +00:00
Svyatoslav Kuzmich 2e26b0956e [Wasm] Improve stability of wasm import names across compiler runs
Remove code generation for external fake overrides
Fake overrides are resolved to real declaration on call sites
This also removes generation of unused
"equals", "hashCode" and "toString" methods.
Avoid using hashes of IrType in generated code
because they are unstable

Merge-request: KT-MR-8658
Merged-by: Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com>
2023-02-03 06:55:59 +00:00
Ilmir Usmanov 901ff06e90 JVM IR: Copy type parameters from class to suspendImpl
These type parameters where used in function parameters,
but since suspendImpl is static function, it has no access
to class type parameters. Solution is to copy them to
the function itself.

 #KT-55125 Fixed
2023-02-02 15:48:10 +00:00
Alexander Udalov 94f1c579df Kapt+JVM_IR: do not generate SuspendFunction supertypes
#KT-54380 Fixed
2023-02-02 15:01:43 +00:00
Nikita Bobko 711f36675c CompatibilityMode cleanup
Review: https://jetbrains.team/p/kt/reviews/8401

- Drop unused variables
- Replace `assert` with `require` because `assert` isn't reliable which
  makes hard to do any judgements about the code (`-ea` flag must be
  passed to the VM for the `assert` to be active. And it's hard to know
  when we the flag is passed). If `assert` was here for the performance
  reasons then a comment should have been left.
- Add the assert message for clearity

Because I'm evaluating what will break if KotlinAbiVersion is bumped.
And when the code around KotlinAbiVersion is clean it's easier to do the
evaluation.
2023-02-01 15:13:34 +01:00