Commit Graph

101 Commits

Author SHA1 Message Date
Ivan Kylchik f4bbcdc013 [TESTS] Move global directives outside file scope 2021-10-25 00:14:19 +03:00
Svyatoslav Kuzmich 15acc412ba [Wasm] Update testdata after coroutines support 2021-10-12 08:42:00 +03:00
pyos f786084a0a JVM_IR: mark direct uses of inline lambdas as conditionally suspend
They may or may not be inlined later.

IDK how the test passes when both modules are compiled with the old
backend - perhaps this has something to do with the fact that when `f`
is compiled with the IR backend, the call to `x()` is followed by `pop`
and `getstatic kotlin/Unit.INSTANCE`? This is probably why the original
issue in kotlinx.coroutines reports that everything works fine with
kotlinx-coroutines-core:1.4.3.

^KT-46879 Fixed
^KT-48801 Fixed
2021-09-20 19:29:44 +02:00
pyos 33ddeffcfd JVM_IR: box inline class values returned by suspend inline lambdas
The call site inside the inline function expects them to return a boxed
value, like FunctionN.invoke would.

 #KT-46915 Fixed
2021-05-26 08:33:55 +02:00
pyos 21f2b3fa2b JVM: expect a continuation parameter in default suspend references 2021-05-18 10:48:31 +02:00
pyos 7eedcf75f9 Add tests for default inline suspend lambdas
Broken on JVM and JVM_IR
2021-05-18 10:48:31 +02:00
pyos e6d923f65c FIR: rename HIDDEN to INVISIBLE_REFERENCE
Some of them should be INVISIBLE_MEMBER though
2021-04-21 16:18:21 +03:00
Ilmir Usmanov a30a961cf5 Minor. Throw exceptions in test coroutine builders 2021-02-03 19:18:24 +01:00
Dmitriy Novozhilov 64a300bfcd [TD] Update testdata according to previous commit 2021-02-02 17:53:52 +03:00
Dmitriy Novozhilov 8973e3f362 [TD] Update fir directives in boxInline tests 2021-02-02 17:50:07 +03:00
Alexander Udalov 5480faf5c5 Add tests for issues fixed in JVM IR and other obsolete issues
#KT-6007
 #KT-16445
 #KT-17753
 #KT-22488
 #KT-23881
 #KT-24135
 #KT-26360
 #KT-27427
 #KT-27449
 #KT-27830
 #KT-28042
 #KT-29595
 #KT-30708
 #KT-32793
2021-02-01 18:29:59 +01:00
Dmitriy Novozhilov b416c669b0 [TEST] Update testdata due to dropped COMMON_COROUTINE_TEST directive 2020-12-10 01:31:04 +03:00
Mikhail Glukhikh 0a0b5b5d2b [FIR DFA] Don't consider anonymous object as stable initializer to bind
#KT-43332 Fixed
2020-11-26 16:29:06 +03:00
Mark Punzalan 348ba3e08c [FIR] Enable BlackBoxInlineCodegen tests for FIR.
16 out of 638 tests (2.5%) are currently failing.
2020-09-29 10:21:21 +03:00
Ilmir Usmanov dfd7f33bd3 Minor. Add test with reified type parameter 2020-09-17 16:14:07 +02:00
Ilmir Usmanov 58146c4452 Keep DebugMetadata annotation when regenerate lambda with state-machine
When a suspend lambda does not capture crossinline lambda, it is
generated with as state-machine, since it does not inline anything.
However, when regenerating, the inliner used to remove all DebugMetadata
annotations to avoid duplication. This lead to missing annotation if
the lambda is regenerated, but state-machine is not regenerated.
This change fixes the blind spot by readding the annotation after
regeneration.
 #KT-41789 Fixed
2020-09-15 19:57:02 +02:00
Ilmir Usmanov 52f9569d33 Generate CHECKCAST Object inside the markers
otherwise, the unboxing interferes with bytecode analysis.
2020-09-09 17:43:42 +02:00
Alexander Udalov 9e357354fb Add JVM/JVM_IR mixed compilation tests for compileKotlinAgainstKotlin/boxInline 2020-09-07 19:41:37 +02:00
Ilmir Usmanov a6f14c206b Revert "Revert "Revert "Revert "Completely rewrite reifiedIntTypeAnalysis, making it more streamline""""
This reverts commit 447308dcfc.
2020-06-25 18:51:11 +02:00
Victor Petukhov 447308dcfc Revert "Revert "Revert "Completely rewrite reifiedIntTypeAnalysis, making it more streamline"""
This reverts commit 5567033b
2020-06-17 13:02:40 +03:00
Ilmir Usmanov 5567033b33 Revert "Revert "Completely rewrite reifiedIntTypeAnalysis, making it more streamline""
This reverts commit 822c14814b.
2020-06-09 20:52:24 +02:00
Ilmir Usmanov 822c14814b Revert "Completely rewrite reifiedIntTypeAnalysis, making it more streamline"
This reverts commit 1ed4324613.

Otherwise, bootstrap is broken.
2020-06-03 19:43:59 +02:00
Ilmir Usmanov 1ed4324613 Completely rewrite reifiedIntTypeAnalysis, making it more streamline
and easy to understand and optimize if it would be a bottleneck.
Use LVT to get information of refined int type in one specific case

 #KT-38925 Fixed
2020-06-03 16:03:50 +02:00
pyos 456469eb3b JVM: fix remapping of new T inside regenerated copies of T
In general, `InliningContext.findAnonymousTransformationInfo` was not
reliable because it mapped each type to *some* info for that type,
preferring ones with `shouldRegenerate == true` if those exist. Thus, it
returned incorrect results if one type was regenerated multiple times,
e.g. in a nested inlining context or because of a `finally` (which
duplicates anonymous objects). The solution is to avoid a global map and
attach the current transformation info directly to the current inlining
context.
2020-04-23 14:20:54 +02:00
pyos 516692008f JVM: add tests fixed by the last two commits
One was broken on JVM, the other on JVM_IR.
2020-04-07 15:42:41 +02:00
pyos 5ed845d0b4 JVM_IR: reuse same bodies for suspend funs and $$forInline versions 2020-04-03 19:51:45 +02:00
pyos bdd88e1655 JVM_IR: place suspend markers in faux lambdas around inline references
Otherwise, the assumption that coroutine codegen makes about every
inlined function already having the markers breaks and it is no longer
true that calls to inline lambdas do not require them.
2020-03-13 18:33:41 +01:00
pyos dc388f3f3a JVM_IR: add a test for suspend inline fun with defaults in a class
This is one example of a function replaced by a lowering after
AddContinuationLowering mentioned in the last commit: the lowering that
makes default stubs static is further down. Although this is not a
lambda, calling getOrCreateSuspendFunctionViewIfNeeded on it in the
inliner is fatal all the same.
2020-03-09 17:05:42 +01:00
pyos 8487211ae1 JVM_IR: refine the condition for mangling names of multifile members
Private $$forInline versions of public suspend functions should not
be mangled. (Note that there are no $$forInline versions of private
suspend functions, as those are effectively inline-only.)
2020-03-06 14:33:50 +01:00
pyos 159d292ea7 JVM_IR: make continuation detection more consistent
* unify various checks for whether a suspend function needs a
    continuation;

  * mark the continuation parameter with an origin (this also allows
    correctly computing the offset of the local in codegen -- see the
    new test);

  * when wrapping `suspend fun main`, use a suspend reference instead of
    a synthetic non-suspend lambda (required to correctly implement the
    previous point, as previously the continuation parameter was passed
    to main() itself correctly only because of very lenient checks in
    AddContinuationLowering).
2020-03-03 15:12:13 +01:00
pyos c5ffbfd33c JVM_IR: mark origins of capture fields in suspend lambdas 2020-02-21 12:11:19 +01:00
pyos 6b98ea2378 JVM_IR: do not place suspend markers around crossinline lambda calls 2020-02-21 12:11:19 +01:00
pyos 39ebc8cfa5 Add a suspend test that fails on JVM_IR 2020-02-21 12:11:19 +01:00
pyos eff02b6e72 JVM_IR: improve suspend tail call detection.
* TailCallOptimizationLowering should go into local classes in order to
   transform their suspend methods;
 * the check for invokes of noinline lambda arguments in codegen was
   incorrect, as it also returned true for calls of lambdas stored in
   local variables;
 * IrInlineCodegen should mark non-inlinable arguments used as inline
   suspend parameters;
 * detection of suspend/inline call sites was incorrect (or maybe it's
   the `compilationContextDescriptor` that was incorrect?..)
2020-02-20 11:10:26 +01:00
pyos 5acb3e14fb IR: mark parameters for captures of crossinline parameters 2020-02-07 12:16:26 +01:00
pyos 2bf50cc91a JVM_IR: correctly name $$forInline versions of @JvmName suspend funs
Using a hack similar to $default stubs.
2020-02-07 12:16:26 +01:00
pyos 08074bb60e JVM_IR: wrap inline suspend references in suspend lambdas 2020-02-07 12:16:26 +01:00
Ilmir Usmanov 7dfd7b6081 Spill stack before analyzing it when looking for non-inline suspend lambda
parameters of inline function. Otherwise, it leads to AnalyzerException,
when inlined lambda contains try-catch block. The reason is simple:
in try block, we leave some variables on stack, while on catch block the
stack is empty. Spilling the variables before try block does the trick.
 #KT-34708 Fixed
2020-02-06 13:10:21 +01:00
Ilmir Usmanov fc70455877 JVM_IR: Move suspend function views creation to lowering
Now AddContinuationLowering is responsible for both adding continuation
classes to suspend functions and adding continuation parameters to
them.
Because we cannot create a view if inline suspend function is defined
in another file, we generate a stub without body when we encounter call
to it. And then, when we lower the file containing the function we add
the body. This way we have no unlowered views after the lowering.
Thus, after the lowering there should be no suspend function, which
are not views, therefore, remove VIEW origins.
Because transformations of suspend functions can copy them into another
object, use attribute as a key inside function to view map.
2020-02-05 15:07:37 +01:00
Ilmir Usmanov 877509306d JVM_IR: Minor. Unmute tests. 2020-01-20 16:00:36 +01:00
Ilmir Usmanov 891a55d79a JVM_IR: Fix visibility of inner suspend lambda inside inline function
It should be public, otherwise, after inlining, we will get IllegalAccessError.
2020-01-20 16:00:36 +01:00
Ilmir Usmanov 9f5b51ed43 JVM_IR: Do not generate fake continuation markers inside inline suspend lambdas
Since the markers replace ALOAD 0 as continuations, passed to suspend calls, in
JVM_IR we do not need this, since in JVM_IR all inline lambdas are static
functions.
2020-01-20 16:00:35 +01:00
Ilmir Usmanov 2507e2b526 JVM_IR: Fix parents of $$forInline companions 2020-01-20 16:00:33 +01:00
Ilmir Usmanov 7167d5f75c JVM_IR: Generate $$forInline companion for transformed crossroutines 2020-01-20 16:00:33 +01:00
pyos ef5fe0675a JVM_IR: refactor suspendFunctionView
fixing the check for DescriptorWithContainerSource in the process
(containerSource *may* be null).
2020-01-08 19:52:20 +01:00
Georgy Bronnikov d4b0151f51 JVM_IR: fix name of received field for suspend lambdas
$ at the start caused AnonymousObjectTransformer to skip the field.
2019-12-23 18:03:46 +01:00
Ilmir Usmanov 9292022f88 JVM_IR: Support inner lambdas which capture crossinline 2019-12-23 18:03:42 +01:00
Ilmir Usmanov daa76cbf1e JVM_IR: Support inner objects with multiple suspend functions
Do not clean `functionsToAdd`
2019-12-23 18:03:41 +01:00
Ilmir Usmanov a1448ebb37 JVM_IR: Support crossinline suspend lambdas
The main idea is the following: since we need to generate
(fake)continuations before inlining, we move IrClasses of suspend
lambdas and continuation classes of named functions into the functions.
Thus, it allows the codegen to generate them prior to inlining and
the inliner will happily transform them for us.
Because of that, lowerings which transform call-site function are likely
to change reference to lowered suspend lambdas or functions.
Hence, do not rely on references to lowered suspend lambdas or
functions, instead, rely on attributes.

Do not generate continuation for inline suspend lambdas.
Previously, inline suspend lambdas were treated like suspend functions,
thus we generated continuations for them. Now we just do not treat them
as suspend functions or lambdas during AddContinuationLowering.
We should add continuation parameter to them, however.

Do not generate secondary constructor for suspend lambdas, otherwise,
the inliner is unable to transform them (it requires only one
constructor to be present).

Generate continuation classes for suspend functions as first statement
inside the function.
This enables suspend functions in local object inside inline functions.
Since we already have attributes inside suspend named functions, we
just reuse them to generate continuation class names. This allows us
to close the gap between code generated by old back-end and the new
one.

If a suspend named function captures crossinline lambda, we should
generate a template for inliner: a copy of the function without
state-machine and a continuation constructor call. The call is needed
so the inliner transforms the continuation as well.

Refactor CoroutineTransformerMethodVisitor, so it no longer depends on
PSI.
2019-12-23 18:03:40 +01:00
Ilmir Usmanov df0a86ea57 Add NOP as first instruction in coroutine's try blocks
#KT-35035 Fixed
2019-12-11 15:01:41 +01:00