Commit Graph

99 Commits

Author SHA1 Message Date
Sergej Jaskiewicz c335cd0b1e [IR] Remove unused IrMessageLogger from serialization logic 2024-01-29 21:07:43 +00:00
Sergej Jaskiewicz bc5810ee67 [FIR2IR] Don't use descriptor manglers in FIR2IR
They don't do anything, only complicate the initial configuration.

KT-64990
2024-01-19 13:36:00 +00:00
Sergej Jaskiewicz 918335e12e [IR] Replace error("Should not be called") with shouldNotBeCalled() 2023-11-10 12:31:40 +00:00
Sergej Jaskiewicz 47f8dedfa5 [IR] Remove methods for computing full mangled names from non-IR manglers
A full mangled name of a declaration is a mangled name that includes
the mangled names of all the declaration's parents.

We don't use full mangled names for building `IdSignature`s. We use them
in two places:
- Generating stable names for JavaScript functions in Kotlin/JS
  (see `NameTables.kt`)
- Generating names for LLVM symbols from lowered IR functions in
  Kotlin/Native (see `BinaryInterface.kt`)

In both of these places we run the IR mangler, hence we don't need this
functionality in other manglers.
2023-11-10 12:31:40 +00:00
Pavel Kunyavskiy 2b8b6a2b21 [IR] Split FakeOverrideBuilder to two parts
Now there is separate class encapsulating logic about how to build
fakeOverrides and one encapsulating logic of which classes
do need building fake overrides.

This also allows to untie strange inheritance dependencies.

^KT-61934
2023-09-24 16:11:49 +00:00
Johan Bay a041e51ff2 Rename IdSignatureSerializer to IdSignatureFactory
^KT-61642
2023-09-22 22:30:24 +00:00
Dmitriy Dolovov 7be877ce74 [IR][JVM] Drop JvmIrSerializerSession.skipExpects parameter
^KT-61136
2023-08-14 15:21:04 +00:00
Dmitriy Dolovov 6c12556c41 [IR][JVM] Drop JvmIrSerializerSession.expectDescriptorToSymbol parameter
^KT-61136
2023-08-14 15:21:04 +00:00
Dmitriy Dolovov 6e648ac374 [IR] Drop IR expect/actual table
^KT-61136
2023-08-12 07:03:29 +00:00
Sergej Jaskiewicz f14a713e49 [mangling] Remove the unused fqnString method from KotlinMangler 2023-06-29 13:04:25 +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 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 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
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
Sergej Jaskiewicz c447b91101 [IR] Factor out duplicated code in KotlinMangleComputer into base class 2023-03-03 22:08:55 +00:00
Roman Efremov 14b4cdc7c4 Write "hasEnumEntries" flag into metadata when feature enabled
^KT-53929 Fixed
2023-01-23 12:53:04 +01:00
Alexander Udalov 1418423423 Remove unsafe cast function usages from JVM backend modules 2022-12-06 19:44:55 +00:00
Sergej Jaskiewicz 1539d7ef1a [klib] Bring package names in sync with the directory layout
Basically, some package names were Native-specific, whilst the packages
themselves were not Native-specific at all. This was already reflected
in the directory layout, but not in the package names.
This is fixed here.

NFC, just an automatic rename of packages with fixes of imports.
2022-12-01 21:46:43 +00:00
Dmitriy Dolovov 71d51801ce [IR] Partial linkage fix: Implement abstract fake overrides in non-abstract classes so that there are no call sites that still refer to abstract fake overrides
^KT-53663
2022-10-20 10:18:54 +02:00
Dmitriy Dolovov 15635482aa [IR] Partial linkage: Enable it by just passing a boolean flag to IR linker constructor 2022-10-19 13:46:22 +00:00
Dmitriy Dolovov 532b9e2c5f [Native][IR] Partial linkage support for cached inline functions
- Support partial linkage for declarations from inline functions that are lazily deserialized from a KLIB with static cache
- Linker API: Split IrModuleDeserializer.deserializeIrSymbol() into deserializeIrSymbolOrFail() and tryDeserializeIrSymbol()
- Linker API: Refactor KotlinIrLinker.handleSignatureIdNotFoundInModuleWithDependencies() to deserializeOrReturnUnboundIrSymbolIfPartialLinkageEnabled()

^KT-52478
2022-07-18 17:29:50 +02:00
Alexander Udalov ec9d929532 Remove dependency of fir2ir:jvm-backend on backend.jvm.entrypoint
Extract JvmIrDeserializer(Impl), similarly to the existing
JvmIrSerializer(Impl). Remove `allowErrorNodes` which is always false
anyway.
2022-06-13 12:35:51 +00:00
Georgy Bronnikov 12d34589d8 Psi2Ir, Fir2Ir: always include return type into signature mangle of a function 2022-05-19 12:02:42 +02:00
Georgy Bronnikov 0ef474a8d3 Do not set parent for deserialized IR declarations 2022-05-19 12:02:42 +02:00
Alexander Udalov 6379fe4c4c JVM IR: link via descriptors instead of signatures by default
Doing so speeds up psi2ir ~2 times, and thus improves total compiler
performance by about 6-8%.

Unless JVM IR is in the mode where linking via signatures is the only
way (-Xserialize-ir, -Xklib), signatures are actually not needed at all,
SymbolTable can use the frontend representation (descriptors for FE1.0,
and hopefully FIR elements for K2) as hash table keys. The only catch is
that since other backends still need to work with signatures, all the
common IR utilities, such as irTypePredicates.kt, need to work correctly
for IR elements both with signatures and without.

Also, introduce a fallback compiler flag -Xlink-via-signatures, in case
something goes wrong, to be able to troubleshoot and workaround any
issues.

 #KT-48233
2022-02-03 02:48:05 +01:00
Georgy Bronnikov d2418a1329 IR: never attach return type to signatures of fake overrides
Cases that necessitate the return type hack (see KT-46042) always
involve exactly two methods, exactly one of which is a fake override. It
is sufficient to mark one of them.
2022-01-27 01:02:25 +03:00
Georgy Bronnikov f0fb0cbefe IR: remove IdSignatureBuilder.isKotlinPackage() 2022-01-27 01:02:23 +03:00
Georgy Bronnikov f4ddbb5e71 JVM_IR: remove DeclarationStubGenerator from deserializeLazyDeclarations.kt
No descriptor references remain.
2022-01-27 01:02:21 +03:00
Georgy Bronnikov 633e3a82e2 JVM_IR: record file facade fq name in serialized IR
This is needed to distinguish between file level privates by signature.
2022-01-27 01:02:20 +03:00
Georgy Bronnikov c0f6508ff9 JVM_IR: do not compute stored file signature when not needed 2022-01-27 01:02:19 +03:00
Georgy Bronnikov 10c3429ce6 IR: remove dead code 2022-01-27 01:02:19 +03:00
Georgy Bronnikov 044acbb5ef JVM_IR: do not use return type in Java property mangles
Another case of discrepancy between IR-based mangles and
descriptor-based mangles.
2022-01-27 01:02:16 +03:00
Georgy Bronnikov 4d2bcf7e66 IR: compute file local signatures from descriptors 2022-01-27 01:02:16 +03:00
Georgy Bronnikov b6ddd758ec IR: fix deserialization of publicly visible type parameters 2022-01-27 01:02:15 +03:00
Georgy Bronnikov 3cc883cf7b IR: use DescriptorBySignatureFinder in DeclarationStubGenerator
Duplicating code that was used for the same purpose in
DeclarationStubGenerator is removed.
2022-01-27 01:02:14 +03:00
Dmitriy Dolovov 99300bd885 [IR] IrModuleDeserializerKind API cleanup
Related to #KT-50591
2022-01-12 11:05:12 +03:00
Dmitriy Dolovov cb5a052227 [IR] Distinguish IrModuleDeserializers with and w/o underlying KLIBs
Fixes #KT-50591
2022-01-11 21:53:06 +03:00
Roman Artemev 7341a17a5d [IR] Cleanup ir serialization 2021-12-24 16:50:44 +03:00
Roman Artemev fb84287ae0 [KLIB] Compute relative path instead of absolute if relative base is provided
- normalize  path if required
 - path it in JS/Native
 - path null for JVM (temporary)
 - fix build
2021-12-15 21:13:52 +03:00
Georgy Bronnikov a9ce25cf33 JVM_IR: only serialize inline functions themselves with -Xserialize-ir=inline 2021-10-11 11:53:30 +03:00
Georgy Bronnikov 4caa71538d JVM_IR: introduce modes for IR serialization
Instead of a Boolean flag -Xserialize-ir, use modes: none,inline,all.
In "inline" mode, only information needed to deserialize bodies of inline
functions is serialized.
In the "all" mode, all declarations are serialized completely.
2021-10-11 11:53:29 +03:00
Roman Artemev e6de812788 [IR] Implement checker for friendship of modules in fake override builder
- pass corresponding information to FO builder
 - implement check
 - fix KT-47192 and KT-48673
2021-10-07 16:00:49 +03:00
Roman Artemev ba759fb61b [IR] Fix compatibility mode
- pass corresponding flag to mangler
 - properly handle local declarations in field initializers
 - fix KT-48912
2021-10-06 03:47:20 +03:00
Alexander Udalov 6e93006a94 JVM IR: slightly optimize keepTrackOfOverridesForPossiblyClashingFakeOverride
Collecting all outer classes into a hash set and looking up classifiers
in that set for each type of each fake override is noticeably slow.
Instead, check that function types reference any type parameter whose
container is a class; if the function is not local, it means such type
parameter belongs to one of the outer classes.

 #KT-42020
2021-10-05 12:16:24 +02:00
Georgy Bronnikov 8a459821d0 JVM_IR: avoid double encoding of byte strings
IrLibraryFile, ingerited from Klib code, needed types, bodies, strings,
signatures encoded as byte strings.
When we store this data as class annotations, it is better to store it
as protobuf structs, to avoid re-encoding byte streams twice.
2021-10-01 00:58:06 +03:00
Roman Artemev 78cd45f937 [KLIB] Resolve deserialization on for each file separately
Needs for IC
2021-09-07 20:41:28 +03:00
Roman Artemev 5a7298808e [JVM KLIB] Fix Type Parameter resolve 2021-08-06 20:49:19 +03:00
Roman Artemev b1251c1716 [JS IC] Drop special IdSignatureSerializer for IC 2021-08-06 20:49:04 +03:00
Roman Artemev 0310f7cb0b [JS IC] Lot of fixes after rebase 2021-07-22 21:56:57 +03:00
Ilya Chernikov dee0487185 IR: Refactor IrBuiltIns to abstract it from descriptors 2021-07-16 02:24:18 +03:00