Commit Graph

48 Commits

Author SHA1 Message Date
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
Alexey Andreev 0606ebe0dc Fix suspend function with default argument
In JS BE, fix translation of suspend function with default argument
inherited from interface.

See KT-16658
2017-03-28 11:32:45 +03:00
Alexey Andreev 6ba3812582 Fix inlining of tail call suspend function
When inlining tail-call suspend function to regular
suspend function in JS BE, don't forget to insert suspension point.
See KT-16951
2017-03-28 11:32:45 +03:00
Yan Zhulanow e25e19c4d6 Refactoring: Remove light analysis test data
The light analysis test data is not needed anymore cause the light analysis result is now automatically checked against the one from the full analysis.
2017-03-21 20:49:36 +03:00
Alexey Andreev 8567db10b5 JS: fix coroutine transformation of callable references to local functions. See KT-16164 2017-03-07 10:46:07 +03:00
Denis Zharkov ecec87cbc7 Refine signature calculation for methods with default parameters
The problem was that he number of mask parameters for defaults when
generating methods declaration was being calculated upon resulting signature
(with additional parameters: extension receivers, enum name/ordinal),
while on call-sites the masks number was calculated by the arguments number
in resolved call, i.e. by the number of real value parameters.

And because of the additional synthetic parameters (like enum.ordinal) these
two numbers could be different.

The solution is just to use value parameters number in both places.
Note, that we only count value parameters from the original sourse
declaration, ignoring synthetic ones generated by backend (e.g.
Continuation for suspend functions)

 #KT-14565 Fixed
2017-02-28 10:42:07 +03:00
Denis Zharkov 80638ebc99 Prohibit unsupported suspend operators
contains/get/set operators don't work properly on both backends

Also add box test checking that 'compareTo' operator works just fine

 #KT-16219 Fixed
2017-02-08 11:07:27 +03:00
Denis Zharkov cc7f0e2d83 Fix codegen problem with safe-call on suspension point with two receivers
#KT-16145 Fixed
2017-02-07 11:56:37 +03:00
Denis Zharkov 258ee0db75 Introduce startCoroutineUninterceptedOrReturn coroutine intrinsic
#KT-15716 Fixed
2017-02-07 11:07:04 +03:00
Denis Zharkov 29b0b30031 Make createCoroutine return a safe continuation
#KT-15718 Fixed
2017-02-07 11:06:50 +03:00
Alexey Andreev 97b6c3013a JS: fix destructuring declaration and increment in coroutines. See KT-16058 2017-02-03 11:09:10 +03:00
Denis Zharkov cc28fecacd Fix VerifyError in coroutines caused by null spilling
While within a method by the JVM spec null-value has a special
Nothing-like type, when we spill it for a coroutine, we must choose
some real type to CHECKCAST to after restoring the variable's value.

But the problem is that such a real type depends on usage of that null value,
and there may be more than one usage.

The solution is not to spill such variables into fields, but instead
init them with ACONST_NULL after each suspension point

 #KT-16122 Fixed
2017-02-03 10:32:28 +03:00
Denis Zharkov 60c2579436 Allow destructuring in suspend lambda with suspend componentX
#KT-16113 Fixed
2017-02-03 10:32:28 +03:00
Denis Zharkov 529b526763 Support parameter destructuring in suspend lambdas
#KT-16092 Fixed
2017-02-02 18:09:19 +03:00
Denis Zharkov 0878049f15 Support tailrec suspend functions in JVM backend
The main problem is that inside a state machine for a named suspend
function parameters of it's owner are available as a usual captured
closure parameters (i.e. through synthetic fields), while
TailRecursion codegen expects that parameters are straight local
variables.

So, the solution is just to define local var for each of real parameters
(all but the last continuation parameters) for tailrec functions.

 #KT-15759 Fixed
2017-02-02 18:09:19 +03:00
Denis Zharkov b0ebbe99d6 Fix coroutine-related VerifyError
The problem was that we spilled the `origin` variable (see test) as Object, because
we determined the type of merge(null, String) incorrectly.

 #KT-15973 Fixed
2017-01-30 15:45:02 +03:00
Denis Zharkov 463af85f78 Minor. Update light-classes test data after coroutine-related changes 2017-01-27 23:24:13 +03:00
Denis Zharkov 0e132b9857 Move all coroutine-related declarations from built-ins to stdlib
Also move internal declarations from runtime.jvm module into new package
kotlin.coroutines.jvm.internal in stdlib

The necessity of these declarations being in built-ins is controversial,
but also it will complicate the migration of current coroutine runtime
to a separate jar if we ever need this
2017-01-27 23:24:13 +03:00
Dmitry Petrov e05f2eaff6 KT-15017 Throwing exception in the end of inline suspend-functions lead to internal compiler error
Suspend function call with a reachable (alive) begin marker and unreachable (dead) end marker
is an exit point for the corresponding coroutine.
It isn't a suspension point, and doesn't introduce a new state in the coroutine FSM.
2017-01-27 10:43:00 +03:00
Dmitry Petrov ab2448307e Functions imported from objects should be properly mapped to "real" suspend function descriptors. 2017-01-26 09:39:53 +03:00
Denis Zharkov 9ce3880ac6 Support getValue/setValue/provideDelegate suspend functions in JVM backend
- Determine if there are non-tail calls to getValue/setValue simply
by existance of such a property
(it might be too strict, but implementing more granular check may be rather hard)

- Change in ExpressionCodegen is relevant for provideDelegate,
that in case of local variables uses OnStack as StackValue
(see the comment near these changes)

 #KT-15933 Fixed
2017-01-25 13:54:01 +03:00
Denis Zharkov 9ca9a988a6 Fix accessor generation for suspend functions
1. JVM view of suspend accessors must be also an instance of AccessorForFunctionDescriptor,
thus `createSubstitutedCopy` should be correctly overidden.

2. accessibleFunctionDescriptor should unwap the initial suspend descriptor,
for the same reasons as for type aliases constructors and etc:
these descriptors are used as keys of the map of accessors, so
to avoid duplication for suspend view and initial suspend descriptor,
we always use the latter one as a key.

 #KT-15907 Fixed
 #KT-15935 Fixed
2017-01-25 13:54:01 +03:00
Denis Zharkov 0693bd6b62 Fix codegen issue on suspend functions with receiver
When the extension receiver of a named suspend function was marked as used
from the inner lambda, codegen used to throw a "Don't know how to generate outer expression for class" exception.

It may seem quite tricky, but currently for suspend lambda body
its extension receiver is treated as it's defined inside the relevant "doResume"
(there is an actual bytecode part that fills the relevant local variable)

The problem was that inside ExpressionCodegen for "doResume" of named
suspend function we couldn't determine that original function has
an extension receiver.

 #KT-15821 Fixed
 #KT-15820 Fixed
2017-01-25 13:54:01 +03:00
Denis Zharkov 02b40326cc Fix incorrect coroutines codegen behavior
If all the suspension calls in a suspend function were "hidden"
under the for-convention (iterator/next/hasNext) calls,
control-flow didn't find them, thus supposing that there is no
suspension points and there is no need to generate a coroutine state machine

The solution is to add relevant calls to CFG

 #KT-15824 Fixed
2017-01-25 13:54:01 +03:00
Alexey Andreev 26a3ac5a9b JS: fix translation of delegated local variables in coroutines. See KT-15834 2017-01-24 20:13:53 +03:00
Denis Zharkov 37b364a70a Fix processing of uninitialized instances for coroutines
The problem is that code in the attached test led to VerifyError at runtime
because the Bar's uninitialized instance created in 'map' was being stored
to the field (leaked from the JVM point of view).

The actual problem was that after repeating visiting of NEW operation
we used to drop the set of already visited copy usages.

For clarification see the comment before 'processUninitializedStores'

 #KT-15016 Fixed
2017-01-18 12:00:46 +03:00
Denis Zharkov 630fab1952 Fix signature of accessor for suspend function
It must be a suspend function too to have an additional Continuation parameter

 #KT-15715 Fixed
2017-01-18 12:00:45 +03:00
Denis Zharkov d0d617b44e Fix signature mapping for default suspend function from interface
Use jvm suspend function view in function codegen.
Also use SUSPEND_FUNCTION_TO_JVM_VIEW slice if the value exists
for the given key

 #KT-15552 Fixed
2017-01-18 12:00:45 +03:00
Denis Zharkov fae9cc1c63 Fix codegen issue of safe-qualified suspension points
#KT-15527 Fixed
2017-01-18 12:00:44 +03:00
Roman Elizarov 25739a08ea CoroutineContext Key and Element are now inside CoroutineContext interface itself (just like Map.Entry)
ContinuationInterceptor companion object is named Key
CoroutineContext.Element property for key is named just key
AbstractCoroutineContextElement implements all of CoroutineContext.Element, including key
2017-01-16 14:33:02 +03:00
Denis Zharkov d346cbbe61 Update test data for light-analysis/coroutines 2017-01-14 15:13:37 +03:00
Denis Zharkov 2286027bed Fix verify error with 'return when/if/try' in suspend function
The problem appears for tail-optimized suspend functions,
we erroneously assumed that when/if/try expressions in tail-call
position have simple types like `I` while actually, they can return SUSPENDED
object, i.e. must have `java/lang/Object` as return type.

But this only concerns branching operations in tail-call position,
so we have to make an additional analysis for remembering whether
a given expression is in a tail-call position.

Also, it's important here that we now assume
the return type of the current function  as `java/lang/Object`
that is necessary to avoid wrong checkcasts.

 #KT-15364 Fixed
2017-01-14 13:24:53 +03:00
Denis Zharkov 695b6d9e67 Minor. Add test on local vars of suspend function type 2017-01-14 13:24:53 +03:00
Denis Zharkov 0240ab0738 Support non-tail suspend calls in JVM back-end
#KT-15597 In Progress
2017-01-14 13:24:53 +03:00
Alexey Andreev a016147a79 JS: fix translation of return statement surrounded by try..finally block in suspend lambda. See KT-15625 2017-01-12 18:12:39 +03:00
Yan Zhulanow 5844f3cf1b Kapt3: Write stub class files with metadata (needed for incremental compilation) 2016-12-28 22:28:30 +03:00
Alexander Udalov cf2839a088 Fix light-analysis test data 2016-12-24 14:37:24 +03:00
Alexander Udalov 5402d50ea3 Light analysis tests: do not render empty lines between classes and in the beginning 2016-12-23 22:30:48 +03:00
Alexey Andreev cef32b3327 JS: initialize fields of coroutine state machine with undefined value so that they match local variable semantics. Fix KT-15366 2016-12-22 17:19:23 +03:00
Denis Zharkov 8475869fb3 Support common calls on suspend function typed values
Also support multiple value parameters in suspend function type

 #KT-15379 Fixed
 #KT-15380 Fixed
2016-12-22 11:15:52 +03:00
Denis Zharkov a1ac77d382 Support async iterator case with coroutines
Not all the `hasNext` operators return types is exactly Z,
suspend operators return boxed versions.

So the fix is just coercing result value after invoked function to Z
2016-12-19 11:07:33 +03:00
Denis Zharkov 5dbc04abbb Refine returns codegen for suspend functions
This change should make the logic a bit more simple.
For all suspend functions/coroutines treat them in expression codegen
like they return boxed version of the original type.

Everything works fine then, except Unit type functions:
their bodies must be generated just like they're VOID and then load
Unit on stack manually.
2016-12-19 11:07:32 +03:00
Stanislav Erokhin d7566d84d0 Fixed testdata. 2016-12-16 02:01:12 +03:00
Stanislav Erokhin b527a4d158 Global rename in test data for coroutines
(cherry picked from commit 132f97b)
2016-12-15 23:58:26 +03:00
Dmitry Petrov 9fd1ac72a9 Purge remaining traces of @AllowSuspendExtensions. 2016-12-15 23:58:19 +03:00
Denis Zharkov 7ffefb515f Update test data for LightAnalysis/Coroutines 2016-12-15 23:57:58 +03:00
Yan Zhulanow 2f50bd8c80 Minor: Fix light analysis tests (rebase to master) 2016-12-11 21:03:05 +03:00
Yan Zhulanow fcafaf5500 Update LightAnalysisModeCodegenTests for Kotlin 1.1 2016-12-05 20:10:32 +03:00