Commit Graph

27 Commits

Author SHA1 Message Date
pyos 5acb3e14fb IR: mark parameters for captures of crossinline parameters 2020-02-07 12:16:26 +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
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
pyos 06c00f4d9e Unmute some JVM_IR inlining tests 2019-10-08 17:19:41 +02:00
Ilmir Usmanov 63f6d515bc JVM_IR: Generate correct invoke of numbered suspend lambda
Instead of continuation type as last parameter's type, generate Object
type.
2019-09-19 19:28:05 +03:00
Ilmir Usmanov 1951ff8054 JVM_IR: Minor. Unmute tests 2019-09-16 16:49:24 +03:00
Ilmir Usmanov 402a77126f JVM_IR: Support inline suspend functions
Only no state-machine version for now.
2019-09-16 16:49:21 +03:00
Georgy Bronnikov 7ede26e8f4 IrCompileKotlinAgainstInlineKotlin tests 2019-09-06 09:19:57 +03:00
Ilmir Usmanov e88dce3e19 Use CFG to recognize suspension point's end
Previously it was linear scan, failing on unbalanced suspension markers.
Now, I use CFG to find end markers, which are reachable from start
markers. Using CFG allows to walk through suspension point instructions
only, since they form region.
If, for some reason, end marker does not exist (inliner or unreachable
code elimination pass remove unreachable code) or is unreachable,
just ignore the whole suspension point, as before.
 #KT-33172 Fixed
 #KT-28507 Fixed
2019-08-09 21:05:03 +03:00
Ilmir Usmanov 2dee506022 Generate suspend markers for inline and crossinline parameters
if they are not inlined, but directly called.
Previously, all inline and crossinline lambda calls were treated by
codegen as if they are always going to be inlined. However, this is not
always the case.

Note, that we cannot generate these markers during codegen, since we
can inline code with no suspension points, but the whole inlined code
will become one giant suspension point. This, of course, breaks
tail-call optimization and, hence, slows down cold streams.

Because of that, we generate these markers, when we are sure, that they
are not going to be inlined. The only place, in which we know that, is
the inliner. During inlining of the inline function, we check, whether
the parameter is inline or crossinline and whether it is not an inline
lambda. If these checks pass, we generate the markers. Noinline
parameters are already covered by the codegen.
 #KT-30706 Fixed
 #KT-26925 Fixed
 #KT-26418 Fixed
2019-04-08 17:28:37 +03:00
Ilmir Usmanov 0fec3470dd Regenerate anonymous object if call site of non-inlineable
functional argument is suspend
Split LambdaInfo into inlineable and non-inlineable
 #KT-26925
2019-03-27 17:44:37 +03:00
Ilmir Usmanov 1c2b8e6fad Fix wrong state-machine generation if inner object is retransformed
during inlining.
 #KT-29492 Fixed
2019-03-27 17:44:35 +03:00
Ilmir Usmanov c68413b953 Do not generate StateMachineChecker if CHECK_STATE_MACHINE directive is
not present.
Otherwise, since it uses suspend functions, it breaks IR tests.
2019-03-18 14:04:03 +03:00
Ilmir Usmanov cc9a0041e0 Check number of suspensions in crossinline tests 2019-03-18 14:04:01 +03:00
Ilmir Usmanov df52c5217d Add facility to check number of suspensions in coroutine tests 2019-03-18 14:04:01 +03:00
Anton Bannykh 59009430e5 JS: report inline suspend functions to IC
* Also inline suspend lambda'a
* Also use correct JsName's in exported suspend inline fun's
* Also use less unused imports
2018-11-07 12:11:01 +03:00
Mikhael Bogdanov 6c65507f29 Mute inline tests 2018-08-02 13:19:25 +02:00
Roman Artemev c9b7db646c Temporary mute test with issue between coroutines and crossinline 2018-08-01 10:56:08 +03:00
Denis Zharkov 0b3048f60a Replace trivial usages of suspendCoroutineOrReturn in tests
This is necessary since suspendCoroutineOrReturn gets removed in 1.3
2018-07-09 15:27:19 +03:00
Denis Zharkov f23a0c8fea Add ContinuationAdapter to coroutine tests helpers
It allows having the same Continuation implementations for different
API versions
2018-07-09 15:27:19 +03:00
Denis Zharkov f01e690f49 Minor. Use coroutine test helpers for inline/diagnostics tests
It should help with decreasing test data copy-pasting when
testing against release / pre-release coroutines
2018-07-09 15:27:19 +03:00
Ilmir Usmanov f60787d57c Move coroutines to kotlin.coroutines package: tests
Introduce COMMON_COROUTINES_TEST directive.
Every test with this directive is run twice: one time with
language version 1.2 and kotlin.coroutines.experimental package
and the other time with language version 1.3 and kotlin.coroutines
package. Each run is a separate method: with suffixes _1_2 and _1_3
respectively.
However, since codegen of release coroutines is not supported in JS
backend, we generate only one method: with suffix _1_2.
 #KT-23362
2018-04-23 21:51:59 +03:00
Ilmir Usmanov 6854135077 Support crossinline suspend lambda as parameter of inline function
Use fake continuation instead of ALOAD 0 while inlining
Do not generate state machine for inner lambdas and inner objects,
which capture crossinline suspend lambda.

 #KT-19159: Fixed
2018-03-16 16:26:11 +03:00