Commit Graph

5160 Commits

Author SHA1 Message Date
Alexander Udalov 987a346015 JVM IR: support cyclic module dependencies
The only way to make the compiler compile several modules with a
dependency loop is via the "build file", given by -Xbuild-file and used
in the JPS (IntelliJ built-in build system) plugin.

For the old frontend/backend it works like this: we _analyze_ sources of
all modules once, as if it's one big module, and then for each module,
we _generate_ (invoke backend) only sources of that module. Backend
needs to be invoked separately per-module because every module has its
own destination directory specified in the build file.

For JVM IR, this separation into just two steps, analyze and generate,
was problematic because there's psi2ir, which works like frontend, in
that it needs the global analysis result to be able to create and link
IR correctly. So, in case of JVM IR, we need to run psi2ir on the whole
module after analysis and before generation.

In this change, psi2ir is run on the whole module via
`CodegenFactory.convertToIr` (which does nothing in the old backend),
and then parts of the resulting IR module are extracted according to the
original separation of the combined module into individual modules via
`getModuleChunkBackendInput` by matching IrFile against KtFile. And
then, backend is run for each such module.

 #KT-45915 Fixed
 #KT-48668 Fixed
2021-09-17 17:39:49 +02:00
Alexander Udalov 5d6ca27c93 JVM IR: introduce CodegenFactory.convertToIr
The steps of psi2ir and JVM backend need to be separated in the API
because in case of cyclic module dependencies (which are allowed in JPS)
psi2ir should be run first on all sources, and then JVM backend on each
module separately. `CodegenFactory.convertToIr` does nothing in the old
backend.

Also, move the ignoreErrors to GenerationState for simplicity.
2021-09-17 17:39:48 +02:00
Igor Laevsky 6432388778 [WASM] Don't handle ref.cast of nulls. Spec was updated a while ago 2021-09-16 20:24:45 +03:00
Igor Laevsky 15668e2266 [WASM] Lower Unit to Void in order to mark statements with no result 2021-09-16 20:24:44 +03:00
Igor Laevsky 9685695769 [WASM] Fold redundant patterns with drop instruction on a wasm level 2021-09-16 20:24:43 +03:00
Svyatoslav Kuzmich a32b86d016 [Wasm] Simple support for external classes and interfaces
* Map these types to Wasm externref
* Don't generate any declaration code for now

Casting and accessing members is not supported yet
2021-09-16 14:20:35 +03:00
Svyatoslav Kuzmich 35a5c9ea71 [Wasm] Support exporting functions via @kotlin.js.JsExport
Previously we exported main function only.
Extend this feature to arbitrary number of annotated functions.
Type restrictions and conversions are similar to imported functions.
2021-09-16 14:20:35 +03:00
Svyatoslav Kuzmich c0d48e3417 [Wasm] Support external functions 2021-09-16 14:14:58 +03:00
Elena Lepilkina 45493b6542 [IR] Support simple cases of inlining fake override getters/setters 2021-09-16 07:55:15 +00:00
Elena Lepilkina bdb61ec5d7 [K/N] Run inline property accessors later to inline all cases including devirtualized 2021-09-15 12:29:03 +00:00
pyos 72752b64c5 Revert "JVM_IR: assume function reference adapters are tail-call"
This reverts commit 537ce05bc9.

 #KT-48478 Fixed
2021-09-15 13:23:11 +02:00
pyos 0864f9faf8 JVM_IR: mark inline lambda functions with a special origin
Keeping the origin as LOCAL_FUNCTION_FOR_LAMBDA was a mistake as this
tells codegen nothing. Changing the origin in allows, for example,
removing the hack that detaches inline lambdas from the IR tree before
verification and codegen, or treating inline lambdas and inline
anonymous functions the same way.

This includes fake functions created for inline callable references.

 #KT-48319 Fixed
 #KT-47279 Fixed?
2021-09-15 13:23:11 +02:00
pyos 6b58c3d035 JVM_IR: mark inlined callable references with a different origin
Makes them easier to find.
2021-09-15 13:23:11 +02:00
Tianyu Geng 3c84fbcab1 IR: make calls with explicit singleton receiver tailrec [KT-48602] 2021-09-14 23:48:52 +03:00
Alexander Udalov 7efc9dac9b JVM IR: extract lowerings to a separate module
Together with extracting codegen to a separate (unrelated) module in the
future, hopefully it'll speed up the build of JVM IR by making it more
parallel, and helping incremental compilation to avoid recompiling code
that depends on lowerings because of `implementation` dependency.
2021-09-14 22:29:12 +02:00
Alexander Udalov eee8b033a6 JVM IR: minimize usages of jvmPhases outside backend.jvm 2021-09-14 22:29:12 +02:00
Alexander Udalov b4c84aa2a6 JVM IR: move out bridge/collection lowering caches to separate files
Both BridgeLoweringCache and CollectionStubComputer are not tecnically
part of the lowerings, so they shouldn't be in the "lower" package.
2021-09-14 22:29:12 +02:00
Alexander Udalov 08cc789123 JVM IR: move out common utilities from lowerings
The main idea is to remove dependencies on lowerings from other
backend.jvm code (mainly codegen), with the hope of extracting lowerings
and codegen to separate unrelated modules in the future.

To achieve this, code which is used both in lowerings and codegen is
moved to the "common" code, mainly JvmIrUtils/JvmIrTypeUtils.
2021-09-14 22:29:12 +02:00
Alexander Udalov 36a3db44da JVM IR: slightly cleanup and split IrUtils.kt
- Move IrType-specific utilities to separate JvmIrTypeUtils.kt
- Extract JvmIrBuilder to a separate file
- Rename IrUtils.kt to JvmIrUtils.kt to be able to tell it apart from
  numerous other IR utils files
2021-09-14 22:29:12 +02:00
Alexander Udalov e857966edb JVM: remove support for disabling NoConstantValueAttributeForNonConstVals
This feature is enabled by default since 1.4, which is the earliest
language version supported by Kotlin at this moment.
2021-09-14 22:29:12 +02:00
pyos d07070e184 JVM_IR: avoid redundant accessors in private inline funs
Their call sites are all in the same file, so we can check whether the
declarations used in the inline function are accessible from all the
places where it will be inlined.

 #KT-48736 Fixed
2021-09-14 22:17:10 +02:00
Roman Artemev a2e4ebd820 [JS IC] Support //RECOMPILE directive in js box tests
- change test runner to production mode when sources are being compiled
 into klib and then klib is being translated into js, not directly from
 kt to js
 - fix IC cache format
 - support IC tests
2021-09-13 13:44:55 +03:00
Roman Artemev 6b2fee7143 [JS IC] Add holder class for incremental codegen cache 2021-09-13 13:44:54 +03:00
Roman Artemev 08aa909569 [JS IC] Add API to save/restore binary AST into IR codegen cache
- Add EMPTY stubs for cache accessors
2021-09-13 13:44:49 +03:00
Dmitriy Novozhilov 70e8d23d6b Fix new warnings in project code 2021-09-12 16:19:33 +03:00
Nikolay Lunyak e571de5942 [FIR] Fix dumpKotlinLike 2021-09-11 22:05:38 +03:00
Aleksei.Cherepanov cc5382b37e [JPS] Fix incremental build after changing Java constant
InlineConstantTracker implemented for tracking changed java static final constants, that used in kotlin.

#KT-46506 Fixed
2021-09-11 13:00:00 +03:00
pyos 23420ecf7a IR: do not infer array element types for non-annotation constants
While annotations restrict the set of allowed types to a few final
built-ins, in arbitrary constants we can have array elements that are
some subtype of the array's element type.

 #KT-48671 Fixed
2021-09-10 21:55:15 +02:00
Sergej Jaskiewicz 2f07589b42 [JS IR] Avoid name clashes for @JsQualifier-annotated declarations
#KT-42039 Fixed
2021-09-10 15:48:43 +03:00
Ivan Kochurkin 2baed77598 [FIR] Add JVM_SYNTHETIC_ON_DELEGATE diagnostic
Extract JVM names to common JvmNames
2021-09-10 00:49:03 +03:00
Mikhail Glukhikh f397553e94 PSI2IR: don't generate annotations on init block (related to KT-48687) 2021-09-09 22:14:48 +03:00
Mikhail Glukhikh 457a6f4e9d IR: copy anonymous initializer annotations properly #KT-48687 Fixed 2021-09-09 22:14:48 +03:00
Jinseong Jeon 9e7ee2fdea Unify and use default value parameter name in default setter 2021-09-09 16:07:09 +02:00
Alexander Udalov 64b911ea5e JVM IR: do not optimize casts for primitives in TypeOperatorLowering
#KT-48659 Fixed
2021-09-09 15:06:57 +02:00
Igor Laevsky ef2970a888 WASM: Cover frontend issue where unit-type is casted to the non-unit type 2021-09-08 19:56:36 +03:00
Igor Laevsky 4299915326 WASM: Implement finally blocks for try/catch'es 2021-09-08 19:56:36 +03:00
Igor Laevsky d99473fe4d WASM: Canonicalize catches without finally blocks 2021-09-08 19:56:35 +03:00
Igor Laevsky 02aed80e18 WASM: Implement simple try/catch codegen 2021-09-08 19:56:34 +03:00
Igor Laevsky 6ca965af6f WASM: Generate throw instruction instead of wasmThrow call 2021-09-08 19:56:33 +03:00
Igor Laevsky 2ef5fd95db WASM: NFC. Rename statementToWasmInstruction into generateStatement 2021-09-08 19:56:32 +03:00
Igor Laevsky 3ecf9306b1 WASM: NFC. Move IrBlockBody visit into body builder 2021-09-08 19:56:31 +03:00
Igor Laevsky a246ec636e WASM: Stupidify unit handling
Now every IR instruction returns an actual Unit instance.
All Unit's are actual objects passed around except for function boundaries.
2021-09-08 19:56:29 +03:00
Igor Laevsky 37874b1937 WASM: Lower expression bodies into block bodies 2021-09-08 19:56:27 +03:00
Svyatoslav Kuzmich b79719d6f5 [Wasm] Fix unit issues
- Materialize unit when its value is actually needed.
- Special-case Unit_getInstance return type at codegen. It should be a
  proper Unit object instead of a "void"
2021-09-08 19:56:26 +03:00
Mikhail Glukhikh 20ddaa9ebf Remove redundant upcast in JvmPropertiesLowering
#KT-48621 Fixed
2021-09-08 18:04:36 +03:00
Leonid Startsev 6f954462d6 Implement proper contract for generated java.lang.Annotation.hashCode()
#KT-48606 Fixed
2021-09-08 14:41:25 +00: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 28ffcf1e81 [KLIB] Fix typo 2021-09-07 20:41:26 +03:00
Dmitry Petrov d9e4dec810 JVM_IR reuse loop variable as index variable should happen after LDL
We can't apply "reuse loop variable as index variable" transformation
before local declarations lowering, otherwise it will affect captured
loop variable behavior, resulting in KT-48626.

Since it's JVM-specific, move it to JvmOptimizationLowering.
2021-09-06 22:16:40 +03:00
Sergej Jaskiewicz cb3d5f90e6 [JS IR] Export protected members too
#KT-47524 Fixed
#KT-47525 Fixed
2021-09-06 12:46:25 +00:00