Commit Graph

502 Commits

Author SHA1 Message Date
Kirill Rakhman 67fc46a190 [FIR] Fix handling of type parameters in FIR mangling
#KT-57429 Fixed
2023-06-09 08:22:21 +00:00
Alexander Korepanov 22dfe07580 [IR BE] Add the ability to collect PL stubbed symbols
^KT-57347 related
2023-06-06 09:27:57 +00:00
Dmitriy Dolovov 280caf003f [PL] W/a for broken @Deprecated annotations in existing c-interop KLIBs
^KT-59030
2023-06-05 12:47:56 +00:00
Ivan Kylchik b9856320cf [IR] Rename fqName to packageFqName for IrPackageFragment 2023-06-02 16:38:04 +00:00
Nikolay Lunyak 70605c84df [FIR Native] KT-58549: Get rid of the builtin provider
According to
`FirNativeCodegenBoxTestGenerated.testNestedClassesInAnnotations`,
the annotation
`kotlin.internal.PlatformDependent` is
unresolved reference.

^KT-58549 Fixed
2023-06-01 10:27:54 +00:00
Dmitriy Dolovov 161fe1d2ca [IR] Don't produce gaps for skipped IR declarations during serialization 2023-05-30 10:14:08 +00:00
Dmitriy Dolovov a01a6b64ad [PL] Fix: Don't use locations in compiler messages
^KT-58837
2023-05-26 14:03:33 +00:00
Sergej Jaskiewicz 02180e8685 Factor out duplicated mangling logic for functions into the base class
^KT-57777 Fixed
^KT-57818 Fixed
2023-05-26 10:55:24 +00:00
Pavel Kunyavskiy ee1608ec99 [PL] Make call an exception in case of several inherited implementations
^KT-57701
2023-05-24 08:17:59 +00:00
Dmitriy Dolovov 650a3c467d [PL] Fix: Use stable order of return targets in 'illegalNonLocalReturn' case 2023-05-23 16:23:41 +00:00
Dmitriy Dolovov 1536bca1bb [PL] Handle illegal fun interface SAM conversions
^KT-53967
2023-05-23 16:23:41 +00:00
Dmitriy Dolovov 7f4d9ddde5 [PL] Optimization: Avoid excessive type checks in IR type operators 2023-05-23 16:23:41 +00:00
Nikolay Lunyak 00e8dc1c39 [FIR] KT-58444: Don't run IR generation when compiling native shared
Normally during metadata compilation we use
`K2MetadataCompiler` and it serializes
metadata to klibs without generating IR.

Native shared compilation uses the K2Native
compiler, which generates klibs based on both
the fir and fir2ir information.

It would be nice to reuse `K2MetadataCompiler`
for native shared, but currently it has no
support for the commonizer, and also reads
the stdlib metadata from a jar instead of a
klib, and there's no simple idiomatic way
to pass the `distribution.klib` value down
to `KLibResolverHelper` (native compilation
has some commonized dependencies, and they
explicitly depend on `stdlib`, so we must
resolve it this way or strip it away to be
able to use the metadata jar instead). There
may be other issues, I only digged a bit.

Instead, this change modifies the K2Native
in such a way that it can generate klibs
with metadata without fir2ir info.

Note that this change does not fix KT-58139,
because KT-58139 fails due to performing the
constants evaluation directly during the
metadata serialization when the needed info
does (and, as I was told, should) not exist
(namely, valid property initializers).

^KT-58444 Fixed
2023-05-23 15:59:41 +00:00
Sergej Jaskiewicz 1a29b9efff [FIR, IR] Fix name mangling for functions with context receivers
- Mangled names of property accessors now include context receiver
  types of the corresponding property when computed from FIR.
- Context receivers are now supported when computing mangled names
  from IR
- IrBasedDescriptors now account for context receivers

^KT-57435 Fixed
2023-05-23 08:55:50 +00:00
Sergej Jaskiewicz e473eaa5d6 [IR] Give generic parameters proper names in IrSymbol-related classes
Single-letter names were very confusing, especially in declarations like

```kotlin
private inline fun <
        reified D : IrDeclaration,
        reified ES : IrDelegatingSymbol<AS, D, *>,
        reified AS : IrBindableSymbol<*, D>
        > finalizeExpectActual(
    expectSymbol: ES,
    actualSymbol: IrSymbol,
    noinline actualizer: (e: D, a: D) -> Unit
)
```
2023-05-18 12:19:52 +00:00
Dmitriy Dolovov 706a4e9919 [PL] Fix: Remove annotations containing unlinked arguments
Both explicitly specified and default argument expressions are considered.

In case an argument expression is considered as 'unlinked' the whole annotation
is removed from the declaration. An appropriate compiler warning logged for each
such case.
2023-05-16 08:30:29 +00:00
Sergej Jaskiewicz 6c211f3a39 [IR] Make IrFunctionSymbol a sealed interface 2023-05-10 11:51:26 +00:00
Sergej Jaskiewicz 1a371350ea [IR] Make IrClassifierSymbol a sealed interface 2023-05-10 11:51:25 +00:00
Igor Chevdar f90db20512 [K/N][caches] Added klib hash computing and storing 2023-05-10 08:37:32 +00:00
Sergej Jaskiewicz a74df3b4b4 [IR] Store manglers used for signature computation in IrBackendInput
We will need them in signature dump tests later.
2023-05-04 14:58:06 +00:00
Artem Kobzar 4327c6645a [K/JS] Save order for modulesWithReachableTopLevels and deserializersForModules to make partial linkage work again 2023-04-25 12:20:14 +00:00
Dmitriy Dolovov 9d4db72d72 [PL] Fix: Don't raise an error when external interface inherits from external class
^KT-57378
2023-04-25 08:00:14 +00:00
Dmitriy Dolovov 3bc744af35 [PL] Fix: Don't raise an error for unimplemented callables in external classes
^KT-57378
2023-04-25 08:00:14 +00:00
Artem Kobzar 33c5068b79 [K/JS] Rework IR deserialization and lowering phases to consume less memory 2023-04-19 13:10:19 +00:00
Dmitriy Dolovov 87125d0703 [PL] Fix: Don't run partial linkage on early stages when no external dependencies have been loaded yet 2023-04-18 09:22:54 +00:00
Dmitriy Dolovov 9d3deb7e0e [PL] Fix: Don't count value arguments vs value parameters for external functions 2023-04-18 09:22:52 +00:00
Dmitriy Dolovov b644fc009d [PL] Fix: Constructor of external class may delegate to kotlin.Any regardless of the actual superclass 2023-04-18 09:22:52 +00:00
Dmitriy Dolovov 997b6e6722 [PL] Fix: Don't try to implement non-implemented fake overrides in stdlib & co 2023-04-18 09:22:51 +00:00
Dmitriy Dolovov dd8eedb8da [PL] Fix: Don't try to implement non-implemented overridden callables in case of inheritance delegation to Nothing 2023-04-18 09:22:51 +00:00
Dmitriy Dolovov 16da1af525 [PL] Support handling IR error types 2023-04-18 09:22:50 +00:00
Pavel Kunyavskiy 95541da9a1 [K/N] Remove unused default dependencies from klib
^KT-55603
2023-04-13 18:28:51 +00:00
Sergej Jaskiewicz 3713d95bb1 [klib] Don't deserialize the list of sealed subclasses from klibs
tl;dr the current design of klibs does not allow to properly deserialize
the list of sealed subclasses in a sound way. It is possible that
a subclass of a sealed class is declared in a different file, AND is
private in that file.

A more detailed explanation:

Right now we don't serialize file signatures at all.
However, a private declaration's signature must necessarily include
the file signature.

How do we serialize a private declaration's signature into a klib
and deserialize it later?

**Serialization** is simple: we just serialize the file signature as
an empty protobuf message.

When we are **deserializing** a private declaration, we look at the file
that is being deserialized right now, and construct the file signature
based on that.

This logic, however, doesn't always work. An example is KT-54028.

Basically, if we have a sealed interface with a private implementor
declared in a different file, this breaks:

1. We are deserializing the sealed interface. The deserializer knows
that we are now in the file in which the sealed interface is declared.
2. As part of deserializing the interface, we deserialize its sealed
subclasses.
3. Naturally, we come to deserializing the private implementor that is
declared in another file, but the deserializer still thinks that we are
in the file in which the interface is declared. A wrong signature is
created, which leads to linkage failure.

We *could* fix this by properly serializing the file signature,
i.e. instead of an empty protobuf message we could write the file path
and its package to the klib. However, there a problems with this
approach:

- The current design of signatures allows a situation where two
different files can have the same relative path
(for example, with the help of the `-Xklib-relative-path-base` compiler
flag) *and* the same package, which would introduce ambiguity during
linkage.
- Most importantly, this appoach won't work well with incremental
compilation of klibs. Currently we rely on the assumption that all
cross-file references are handled with public signatures, and private
signatures are only used inside a single file. This allows to move
declarations across files without recompiling it's use sites.

It has been decided to apply the following hacky solution: we just don't
deserialize the list of sealed subclasses from klibs.
The list of sealed subclasses is not used in lowerings, so it should be
safe.

#KT-54028 Fixed
2023-04-05 15:51:54 +00:00
Sergej Jaskiewicz 7e8874095a [klib] Add documentation comments for IdSignatureComputer 2023-04-05 15:51:53 +00:00
Dmitriy Dolovov 1fef48bb60 [PL] Log partial linkage messages at different severity
As specified in -Xpartial-linkage-loglevel CLI argument.
2023-03-31 18:29:44 +00:00
Vladimir Sukharev b9633375b4 [K2/N] KT-56030: Support Objective-C overloading by param names only
Merge-request: KT-MR-8901
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-03-30 09:37:57 +00:00
Dmitriy Novozhilov c957a0b43b [IR] Properly serialize IrDeclarationOrigin.GeneratedByPlugin to klibs
^KT-56911 Fixed
2023-03-30 07:52:56 +00:00
Dmitriy Dolovov 0a38b29491 [PL] Drop useless KotlinIrLinkerInternalException
It only added a confusion, while in fact has no practical sense.
2023-03-28 08:50:59 +00:00
Dmitriy Dolovov 850879375a [PL] Special handling of function references produced by FIR 2023-03-28 08:50:59 +00:00
Dmitriy Dolovov 7382b31fdc [PL] Native: Remove harmful private visibility guard in deserialization of LazyIr
Kotlin/Native codegen needs to deserialize all fields throughout the class hierarchy to build the proper binary class layout. That becomes impossible with the guard condition that prevents loading private top-level classes from another module in LazyIR (see https://github.com/JetBrains/kotlin/blob/2a4d8800374578c1aa9ec9c996b393a98f5a6e3b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt#L701). The guard suits well for the partial linkage needs, but it causes the codegen to fail with `Unbound public symbol IrClassPublicSymbolImpl: [ File '/file/in/the/library.kt' <- private.top.level/ClassDeclaration|null[0] ]` error.

To prevent this the guard is removed. This does not influence the partial linkage in general except for the different error message being generated: `Function 'foo' can not be called: Private function declared in module <A> can not be accessed in module <B>` instead of `Function 'foo' can not be called: No function found for symbol '<symbol>'`.

#KT-54469
2023-03-27 15:50:13 +02:00
Dmitriy Dolovov 0f17191e0e [PL] Fix: Allow IrEnumConstructorCall with constructed class with kind=ENUM_ENTRY 2023-03-24 18:09:37 +00:00
Dmitriy Dolovov 66532d714e [PL] Fix: Respect inlined array constructor lambdas 2023-03-24 18:09:37 +00:00
Dmitriy Dolovov 2a4d880037 [PL] Deep rework of the partial linkage
1. Leaving no unbound symbols in the IR tree, KT-54491:
   - All unbound symbols are bound to synthetic stub declarations
   - Improved detection of the root cause for every partially linked classifier
   - Improved error messages

2. Visibility valiation, KT-54469

3. Always check deserialized symbols:
   If the deserialized symbol mismatches the symbol kind at the call site in the deserializer then generate and reference another symbol with the same signature. In case PL is off, just throw IrSymbolTypeMismatchException.

4. Handle class inheritance violation:
   - Detect illegal inheritance (ex: inheriting from a final class)
   - Detect invalid constructor delegation (ex: delegating to another class than the direct superclass)
   - Simplification: Reduce the number of PartialLinkageCase subclasses
   - Reworked error message generation to have shorter and clearer messages

5. Handle class transformations and all known side-effects, examples:
   - nested <-> inner
   - class <-> enum/object
   - adding/removing subclasses of sealed class
   - adding/removing enum entries

6. Check direct instantiation of abstract class.
   Such instantiation could be possible if a class was non-abstract in the previous version of a library.

7. Handle unlinked annotations on declarations.
   Such annotations are removed from the IR. The appropriate compiler error message is produced for every individual case.

8. Handle value argument count mismatch at call sites

9. Handle calling suspend function from non-suspend context.
   This could happen if a suspen function was non-suspend in the previous version of a library.

10. Handle overriding inline callables.
    Only the leaf final callable can be marked with `inline`.

11. Detect illegal non-local returns from noinline/crossinline lambdas.
2023-03-23 10:24:27 +00:00
Dmitriy Dolovov 974ee3139c [PL] Track all unbound symbols produced by the partial linkage.
With the partial linkage turned on it's hard to predict whether a newly created IrSymbol that is added to the SymbolTable via one of referenceXXX() calls will or won't be bound to some declaration. The latter may happen in certain cases, for example when the symbol refers from an IR expression to a non-top level declaration that was removed in newer version of Kotlin library (KLIB). Unless such symbol is registered as "probably unbound" it remains invisible for the linkage process.

The optimization that allows to reference symbols without registering them as "probably unbound" is fragile. It's better to avoid calling any referenceXXX(reg = false) functions. Instead, wherever it is s suitable it is recommended to use one of the appropriate declareXXX() calls.

For the future: Consider implementing the optimization once again for the new "flat" ID signatures.

Also: Temporarily mute assertion that checks symbols overwrites in SymbolTable ^KT-57049
2023-03-23 10:24:26 +00:00
Dmitriy Dolovov eec511a767 [PL] Fix line/column numbers in error messages 2023-03-23 10:24:25 +00:00
Alexander Korepanov 2cad26f4cc [JS IR] Use cacheable ZIP file system accessor in JS IR BE
Related to KT-51712
2023-03-10 09:38:52 +00:00
Sergej Jaskiewicz f40278c036 An option to allow out-of-scope type parameters in IrManglerComputer
In the lowered IR there are often references to type parameters whose
containers are not in the current scope. This is incorrect semantically,
but it works in practice due to erasure, so when the mangler is used on
the lowered IR, we don't want to crash the compiler.
2023-03-03 22:08:57 +00:00
Sergej Jaskiewicz 88e244c1cf [IR] Remove JS-specific manglers, as they don't customize any behavior 2023-03-03 22:08:56 +00:00
Sergej Jaskiewicz 1651199ed8 [IR] Add doc comments for KotlinMangleComputer and its inheritors 2023-03-03 22:08:56 +00:00
Sergej Jaskiewicz c447b91101 [IR] Factor out duplicated code in KotlinMangleComputer into base class 2023-03-03 22:08:55 +00:00
Ivan Kochurkin de5b475f7a [FIR] Use KlibBasedSymbolProvider in FirCommonSessionFactory
Unify logic of KLib resolving (Common and JS)

^KT-56354 Fixed
2023-03-03 20:58:24 +00:00