Commit Graph

312 Commits

Author SHA1 Message Date
Sergej Jaskiewicz f39335b3f7 [klib] Don't pass around metadata serialization closure
Pass the metadata serializer instance instead. This allows to further
reduce code duplication by introducing the common interface
`KlibSingleFileMetadataSerializer` for abstracting away K1 and K2
representation of a source file, as well as reusing
`Fir2KlibMetadataSerializer` across different backends.

KT-64392
2024-01-29 21:07:43 +00:00
Sergej Jaskiewicz 5a6f51e474 [klib] Move KlibMetadataSerializer to serialization.js
It's used only in JS compilation.
2024-01-29 21:07:43 +00:00
Sergej Jaskiewicz 93a1ceae75 [klib] Deduplicate KLIB serialization logic in K/JS and K/N
Introduce the new `serializeModuleIntoKlib` function that all KLIB-based
backends can use to serialize a module to a KLIB.

^KT-64392 Fixed
2024-01-29 21:07:43 +00:00
Sergej Jaskiewicz c335cd0b1e [IR] Remove unused IrMessageLogger from serialization logic 2024-01-29 21:07:43 +00:00
Sergej Jaskiewicz f88d09a2f6 [IR] Move KtDiagnosticReporterWithImplicitIrBasedContext to ir.tree
So that it could be accessible from the `ir.serialization.common` module
2024-01-29 21:07:43 +00:00
Sergej Jaskiewicz eda30ff704 [klib] Implement diagnostics for clashing KLIB signatures
Now, we detect clashing signatures during serialization to KLIB and
report a compiler error if two or more declarations have the same
`IdSignature`

For example, for the following code:
```kotlin
@Deprecated("", level = DeprecationLevel.HIDDEN)
fun foo(): String = ""

fun foo(): Int = 0
```

the compiler will produce this diagnostic:
```
e: main.kt:1:1 Platform declaration clash: The following declarations
       have the same KLIB signature (/foo|foo(){}[0]):
    fun foo(): String defined in root package
    fun foo(): Int defined in root package
e: main.kt:4:1 Platform declaration clash: The following declarations
       have the same KLIB signature (/foo|foo(){}[0]):
    fun foo(): String defined in root package
    fun foo(): Int defined in root package
```

Note that we report this diagnostic during serialization and not earlier
(e.g., in fir2ir) for more robustness, so ensure that we check
exactly the signatures that will be written to a KLIB.
If we later introduce some annotation for customizing a declaration's
signature (e.g., for preserving binary compatibility), this
diagnostic will continue to work as expected.

^KT-63670 Fixed
2024-01-12 15:59:28 +00:00
Sergej Jaskiewicz 2cee4ddf5c [JS] Use IrDiagnosticReporter in place of its more specific subclass
To reuse this diagnostic reporter in `serialization.common` for
reporting signature clashes (KT-63670), we must extract it to
the `serializeModuleIntoKlib` method instead of creating it in
`JsKlibCheckers`.

However, because `serialization.common` does not depend on
the `backend.common` module in which
`KtDiagnosticReporterWithImplicitIrBasedContext` is declared,
we have to use the `IrDiagnosticReporter` interface in place of
`KtDiagnosticReporterWithImplicitIrBasedContext`.

Besides, it's better from the architectural point of view:
the users of that diagnostic reporter should not know about its
implementation details.
2024-01-12 15:59:28 +00:00
Dmitriy Dolovov 46081f968d [KLIB Resolver] Report KLIB resolver issues as compiler messages
The reason of this change is to make messages (especially warnings)
that are reported by the KLIB resolver become visible to the end user.
This can be achieved to forwarding such messages to the appropriate
compiler's components such as
`org.jetbrains.kotlin.cli.common.messages.MessageCollector` and
`org.jetbrains.kotlin.ir.util.IrMessageLogger`.

Also: The default `DummyLogger` should be used as minimal as possible.
Because it just forwards messages to the standard output (console)
where they can remain unattended. When the compiler is executed
from the Gradle plugin such messages appear only in DEBUG Gradle's log.

^KT-63573
2023-12-18 13:03:40 +00:00
Pavel Kunyavskiy e80d4b1d60 [IR] Move IrDeclaration.isExpect to IrUtils
^KT-62292
2023-11-20 08:31:41 +00:00
Iaroslav Postovalov a3b55cf758 [IR] Drastically simplify the hierarchy of IR origins
IrStatementOriginImpl and IrDeclarationOriginImpl were made final
classes to simplify the creation of them (a delegate provider was
added) and to optimize performance when comparing the origins by type
and name
2023-11-13 17:56:09 +00:00
Alexander Korepanov ec71fe20e2 [JS IR] Fix file name clashes during JS BE invalidation 2023-10-30 09:14:16 +00:00
Alexander Korepanov 629e0628d6 [JS IR] Implemented a set of JS code checks before klib serialization
The diagnostics cannot be implemented with the FIR frontend checker
because it requires constant evaluation over FIR.
Therefore, the diagnostics are implemented as a set of klib checks over IR.

For the diagnostics, the js() call argument must be
evaluated and inlined as IrConst<String> into IR
in the same way as const val initializers and annotation arguments.

^KT-59388 Fixed
^KT-59399 Fixed
^KT-62425 Fixed
2023-10-26 19:22:14 +00:00
Dmitriy Novozhilov fb8bf19091 [IR] Rename IrSymbolInternals to UnsafeDuringIrConstructionAPI
The new name more precisely describes the meaning of this opt-int
2023-10-25 11:32:46 +00:00
Dmitriy Novozhilov 78a705a1bc [Build] Opt in to IrSymbolInternals for some backend-specific modules 2023-10-24 15:35:05 +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
Alexander Korepanov 522952db1f [JS IR] Run diagnostics by IR before the klib serialization
Implement an infrastructure for checking IR before JS klib serialization.
Implement the EXPORTING_JS_NAME_CLASH and EXPORTING_JS_NAME_CLASH_ES checks.

^KT-61710 Fixed
2023-09-23 19:49:17 +02:00
Dmitriy Dolovov a2e148173d [JS] Don't produce metadata-only (IR-less) KLIBs in JS
The scenario when JS source code is shared between a few JS common
source sets is not supported in Kotlin Multiplatform.

^KT-61136
2023-09-18 17:58:43 +00:00
Dmitriy Dolovov 033bb385b9 [IR] Drop expectDescriptorToSymbol completely
^KT-61136
2023-08-16 19:17:17 +00:00
Dmitriy Dolovov b7211c171f [IR][JS] Drop JsIrFileSerializer.expectDescriptorToSymbol parameter
^KT-61136
2023-08-14 15:20:28 +00:00
Dmitriy Dolovov 5991364028 [IR][JS] Drop JsIrFileSerializer.skipExpects parameter
^KT-61136
2023-08-14 15:20:28 +00:00
Artem Kobzar a29fa428b3 [K/JS] Add warning for ES-modules on the klibgen stage on the uniqueness of the exported names from the module 2023-08-08 15:45:02 +00:00
Artem Kobzar df0e4e0b53 [K/JS] Remove declarations with @JsExport.Ignore from klib explicit roots 2023-07-17 15:11:47 +00:00
Ivan Kochurkin 1a28067b76 [FIR] Merge FirBasedKotlinMangler into FirMangler
FirMangler has only one implementation and it's FirBasedKotlinMangler

It looks excessive
2023-07-12 13:11:24 +00:00
Ilya Goncharov 148d8c9246 [Gradle, JS] Migrate JS cli tests to ir backend 2023-07-05 07:10:06 +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
Igor Chevdar f90db20512 [K/N][caches] Added klib hash computing and storing 2023-05-10 08:37:32 +00:00
Nataliya.Valtman 2a391f7330 Move kotlin-build-statistic project to :compiler 2023-04-25 11:29:09 +00:00
nataliya.valtman e34dd043da Add minimal statistic report for JPS build
Fix build stat for gradle 8

#KT-56438 Fixed
2023-04-25 11:29:09 +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 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 16da1af525 [PL] Support handling IR error types 2023-04-18 09:22:50 +00:00
Sergej Jaskiewicz 78d19e143c [JS IR] Don't use JVM-specific mangler in JS IR backend
^KT-54638 Fixed
2023-04-05 14:23:51 +00:00
Svyatoslav Kuzmich 02beaa1daa [Wasm] Add BuiltInsPlatform.WASM
Use it instead of BuiltInsPlatform.JS in klibs
2023-04-01 10:50:29 +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 a450866db3 [PL] Commonize Native & JS compiler configuration keys 2023-03-30 12:38:07 +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
Alexander Korepanov e3402fcc87 [K2 JS] Do not load transitive dependencies for building K2/JS klibs
^KT-57262 Fixed
2023-03-15 10:49:54 +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
Alexander Korepanov bd3eb81aee [JS FIR] Use FIR in JS IR invalidation tests
Related to KT-56740
2023-03-08 13:18:15 +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
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
Alexander Korepanov 4cda89db9e [JS IR] Fix klib fingerprint format
^KT-56961 Fixed
2023-02-27 12:42:23 +00:00
Svyatoslav Kuzmich 54a45c49f8 [Wasm] Add Wasm platform and K1 FE infrastructure 2023-02-24 01:05:23 +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
Nikita Bobko 62b27b4613 Cleanup: drop KlibIrVersion
Review: https://jetbrains.team/p/kt/reviews/8401
In scope of: KT-55082

Because this version isn't used for anything. We have KotlinAbiVersion
to version the IR format.
2023-02-01 15:13:34 +01:00
Ilya Goncharov 1150ec6882 [JS] Implementation dependencies for JS klibs
^KT-56158 fixed
2023-01-27 13:31:59 +00:00
Ilya Goncharov 7ae85ed68e [JS IR] Module descriptors depends on each other 2023-01-23 16:16:48 +00:00
Roman Efremov 14b4cdc7c4 Write "hasEnumEntries" flag into metadata when feature enabled
^KT-53929 Fixed
2023-01-23 12:53:04 +01:00