Commit Graph

908 Commits

Author SHA1 Message Date
Artem Kobzar dca4a8e722 fix(KT-45056, KT-47516): use enum as an IR class instead of enum entity class. 2021-10-08 16:21:49 +00:00
Ilya Goncharov 669965d56c [JS IR] Generate main method call only for main module 2021-10-08 10:08:57 +00:00
Svyatoslav Kuzmich 9ef899ef10 [Wasm] Reuse Callable reference and SAM lowerings from JS 2021-10-08 07:24:41 +03:00
Ilya Goncharov a0fb60f201 [JS IR] Use label for continue loop in tailrec
^KT-46218 fixed
2021-10-06 18:40:34 +00:00
Sergej Jaskiewicz b93e0181ca [JS IR] Enable directives for IR box tests 2021-10-06 09:23:48 +00: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
Ilya Goncharov 464331d196 rra/ilgonmic/lazy-init-with-js-fun
[JS IR] Use initializer of field to use in js fun

[JS IR] Use string folding to consider const-like string vals as pure

Merge-request: KT-MR-4677
2021-10-05 13:37:06 +00:00
Roman Artemev d4ace2ffe8 [JS IR] Make sure TypeOperatorLowering is after Interop CR Lowering 2021-10-01 23:02:23 +03:00
Roman Artemev fe4a25eba1 [JS IR] Use context-dependent names for lambdas
Partially fix KT-46525

Now the code like
```
fun foo(a: () -> Unit) {}
interface A {
    fun run()
}
fun main() {
    foo {
        println()
    }
    val a = object : A {
        override fun run() {
            TODO()
        }
    }
}
```

is being compiled into

```
  function foo(a) {
  }
  function A() {
  }
  A.$metadata$ = {
    simpleName: 'A',
    kind: 'interface',
    interfaces: []
  };
  function main() {
    foo(main$lambda());
    var a = new _no_name_provided_();
  }
  function main$lambda() {
    return function () {
      println();
    };
  }

  // TODO
  function _no_name_provided_() {
  }
  _no_name_provided_.$metadata$ = {
    kind: 'class',
    interfaces: [A]
  };
```
2021-10-01 23:02:21 +03:00
Roman Artemev 76e08356d8 [JS IR] Change logic of InteropCallableReferenceLowering a bit
Now it first transforms Lambda classes and after fixes the call sites
2021-10-01 23:02:12 +03:00
Roman Artemev 7ec593b22a [JS IR] Inline lambda class into its interop wrapper 2021-10-01 23:02:10 +03:00
Roman Artemev a1b223e33d [JS IR] Set proper statement origin for bound receiver save 2021-10-01 23:02:09 +03:00
Ilya Goncharov dedb9d9018 [JS IR] Fix assertion to enable early created declarations 2021-10-01 13:32:12 +00:00
Ilya Goncharov 4c0045b136 [JS IR] Add test on initialization calling only once 2021-10-01 13:32:11 +00:00
Ilya Goncharov c2cf221965 [JS IR] Add annotation for eager property initialization 2021-10-01 13:32:10 +00: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 ebf17188cb [JS IR] Fix backend to make it possible lower partially loaded IR 2021-09-30 14:30:13 +03:00
Roman Artemev 4bd6e8a034 [JS IR] Pass dirty files into backend and load IR for them only 2021-09-30 14:30:12 +03:00
Sergej Jaskiewicz f0f60907e2 [JS IR] Fix generating property accessors
TL;DR, before we were emitting this JS code:
  Object.defineProperty(Base.prototype, 'bar', {
    configurable: true,
    get: Base.prototype._get_bar__0_k$,
    set: Base.prototype._set_bar__a4enbm_k$
  });

Now we emit this code instead:
  Object.defineProperty(Base.prototype, 'bar', {
    configurable: true,
    get: function () {
      return this._get_bar__0_k$();
    },
    set: function (value) {
      this._set_bar__a4enbm_k$(value);
    }
  });

This fixes the issue where if we had a @JsExport'ed base class with a
public property overridden in a non-exported derived class, we couldn't
access that property from JS if we were given an instance of
the derived class.

#KT-41912 Fixed
2021-09-28 20:04:38 +03:00
Roman Artemev 070c64f9b5 [JS IR] Add descriptive error message for js("...") call
Report a message instead of NPE if `js("...")`` code couldn't be emitted
2021-09-28 18:15:57 +03:00
Roman Artemev 920daac0a2 [JS IR] Fix string literal folder in codegen for js("...") function
Support `val v = "S"` and plus (`v1 + v2`) cases

Fix KT-48941, KT-47360 and probably KT-42681
2021-09-28 18:15:55 +03:00
Roman Artemev f05c8ad953 [JS IR] Fix js("...") call checker in frontend.
Call mather relies on that BuiltIn package fragment implement specific
interface `BuiltInsPackageFragment` which was missed. Make sure that
BuiltIn module's package fragments implement that interface.

Fix progression optimizer symbols resolve in JS & WASM IR BE
2021-09-28 18:15:51 +03:00
Roman Artemev 4073f177b4 [JS IR] Fix switch transformer in case of if as an expr
- Fix KT-43374
2021-09-27 19:01:43 +03:00
Roman Artemev 623f273251 [JS IR] Fix external vararg if its argument is suspend call
- Fix KT-47811
2021-09-27 15:13:04 +03:00
Vyacheslav Gerasimov ab146bd6d4 Build: Fix deprecated Gradle configurations usages
for migration to Gradle 7+ #KTI-559
2021-09-26 18:28:44 +03:00
Ilya Goncharov 064744fae7 [JS IR] Remove redundant legacy property access property 2021-09-24 07:07:12 +00:00
Pavel Kunyavskiy 773c82ae48 Refactor AnnotationImplementationLowering
- Replaced UNDEFINED_OFFSET with SYNTHETIC_OFFSET, it's required by
  Native backend codegen
- Fixed missing overridden symbols
- Enforce adding fakeoverrides for members not overridden by backend
- Support more points for platform customisation
2021-09-23 06:59:32 +00:00
Roman Artemev 0bfc88fad0 [JS IC] Implement test infra for incremental caches 2021-09-20 12:23:36 +03:00
Roman Artemev c692b0b2e0 [JS IC] Make EPs for cache generation and test 2021-09-20 12:23:36 +03:00
Roman Artemev f85a59b7f3 [JS IC] Write cache info in per-file mode too
- make sure that file is existed and not crashes the compiler
2021-09-20 12:23:35 +03: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
Dmitriy Novozhilov 70e8d23d6b Fix new warnings in project code 2021-09-12 16:19:33 +03:00
Sergej Jaskiewicz 2f07589b42 [JS IR] Avoid name clashes for @JsQualifier-annotated declarations
#KT-42039 Fixed
2021-09-10 15:48:43 +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
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
Sergej Jaskiewicz cb3d5f90e6 [JS IR] Export protected members too
#KT-47524 Fixed
#KT-47525 Fixed
2021-09-06 12:46:25 +00:00
Sergej Jaskiewicz be999564b1 [JS IR] Export nested objects
Companion objects are exported as ParentClass.Companion.
Companion object's members are not exposed to its parent class —
one must reference the companion object explicitly if they want to
access its members.

#KT-43783 Fixed
2021-09-02 14:40:15 +03:00
Leonid Startsev 1932546a90 Support instantiation of annotations in JS
#KT-47700 Fixed
2021-09-01 11:13:55 +00:00
Ilya Goncharov acb7ba86bc [JS IR] Add vararg to state machine building
^KT-48344 fixed
2021-08-26 08:52:34 +00:00
Ilya Goncharov ee712b2770 [JS IR] Invokes which is not concrete suspend not wrap into function call 2021-08-26 08:50:13 +00:00
Roman Artemev 001d3d8bc2 [JS IC] Implement per-file cache invalidation algorithm
- track inline graph
 - not finished yet, it's a POW
2021-08-24 01:09:18 +03:00
Roman Artemev cccca56c18 [JS IC] Implement inline call graph tracker and inline hash computer 2021-08-24 01:09:17 +03:00
Roman Artemev 4ad2572085 [JS IC] Delete only PIR related part of IC Cache, not the whole dir 2021-08-24 01:09:14 +03:00
Ting-Yuan Huang e75ca75e3e K2JsIrCompiler: hoist common front-end preparation logic
Instead of creating ModuleStructure and run analysis in each backend,
the common preparation logic is moved into K2JsIrCompiler.doExecute().
2021-08-12 18:01:56 +03:00
Roman Artemev d3ddeef67f [JS IR] Wrap private top level function with internal accessor stub
In case internal inline function references private top level function
after inline such function (T.L.P.) couldn't be referenced
in klib and IC cache. So create internally visible accessors for P.T.L.
function similar to what JVM backend does.

 - add box test
2021-08-10 19:52:08 +03:00
Ilya Goncharov 766857881a [JS IR] Review remarks
- Use intrinsic on this
- Enqueue invoke for DCE
- Change transform
- Ignore instead of target backend

^KT-46204 fixed
2021-08-10 07:24:51 +00:00
Ilya Goncharov 2f0f88062a [JS IR] Change global map in context to mapping
^KT-46204 fixed
2021-08-10 07:24:50 +00:00
Ilya Goncharov e6af3ff6a8 [JS IR] Rename and doc new intrinsics, add new intrinsic to call suspend fun as supertype
^KT-46204 fixed
2021-08-10 07:24:48 +00:00
Ilya Goncharov a70fc99130 [JS IR] Add intrinsic to call suspend functions as super type
^KT-46204 fixed
2021-08-10 07:24:47 +00:00
Ilya Goncharov 3c9dcdbbee [JS IR] Generate suspend function as invoke
[JS IR] Fix type check utils to work with array of arities

[JS IR] Store multiple arities for suspend functional interface implementers

^KT-46204 fixed
2021-08-10 07:24:46 +00:00