Commit Graph

2299 Commits

Author SHA1 Message Date
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
Mikhael Bogdanov 456037a30d Generate proper annotaions on parameters for @JvmOverloads;
Fix for KT-15743: Overloaded Kotlin extensions annotates wrong parameters in java

 #KT-15743 Fixed
2017-01-27 14:09:13 +01:00
Mikhael Bogdanov ab464ea86e Fix for KT-15726: Kotlin can't compile nested try-catch with return
#KT-15726 Fixed
2017-01-27 14:09:13 +01: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
Mikhael Bogdanov 25d75bcd8b Delegates to java defaults methods in compatibility mode 2017-01-26 14:32:33 +01:00
Dmitry Petrov 1613ad0505 KT-15898 Cannot use type alias to qualify enum entry
Type alias static scope includes enum entries for underlying enum class.
2017-01-26 10:23:56 +03:00
Dmitry Petrov a974ed1049 Support custom accessors for top-level properties in scripts. 2017-01-26 10:12:13 +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
Alexey Andreev 1c8478e46b JS: fix translation of enum entries without parentheses that call secondary constructors, constructors with default parameters and varargs. See KT-15900, KT-14097 2017-01-25 18:09:23 +03:00
Alexey Andreev 0f87320f9e JS: regenerate test data 2017-01-25 18:09:23 +03:00
Mikhael Bogdanov 4c7a07bed6 Optimize defaults format: avoid reduntant stack normalization operations 2017-01-25 15:56:56 +01:00
Mikhael Bogdanov fc4be17623 Fix for KT-14966: Regression: VerifyError on access super implementation from delegate
#KT-14966 Fixed
2017-01-25 15:56:55 +01:00
Mikhael Bogdanov 11578c602e Added inline tests for jvm 8 target 2017-01-25 15:56:55 +01: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 115f6ced87 JS: fix support of throwable constructors without message and/or cause parameters 2017-01-25 13:52:16 +03:00
Alexey Andreev 6f4d8decc7 JS: add support of custom exceptions inherited from kotlin.Throwable that call super constructor from secondary constructor 2017-01-25 13:52:16 +03:00
Alexey Andreev f34093db9f JS: make kotlin.Throwable = Error. See KT-15312 2017-01-25 13:52:13 +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
Alexey Andreev 8040d781b4 JS: fix translation of suspend lambda when it's not passed to another function 2017-01-24 20:13:53 +03:00
Alexey Andreev bf55744e64 JS: fix translation of safe calls if suspend functions. See KT-15892 2017-01-24 20:11:55 +03:00
Alexey Andreev 119bf52adf JS: fix translation of callable reference to property of outer class with private setter 2017-01-24 20:09:32 +03:00
Alexey Andreev d35ddc1017 JS: unmute tests that now pass 2017-01-24 20:09:32 +03:00
Alexey Andreev dcb8b7b92c JS: fix inlining of callable references 2017-01-24 20:09:30 +03:00
Alexey Andreev 7a0f75f164 JS: refactor generation of callable references to functions 2017-01-24 20:09:29 +03:00
Alexey Andreev 1b0648a926 JS: refactor generation of property callable references 2017-01-24 20:09:29 +03:00
Mikhael Bogdanov df8394bcd2 Fix for KT-14597: "When" over smartcasted enum is broken and breaks all other "when"
#KT-14597 Fixed
2017-01-24 15:17:47 +01:00
Dmitry Petrov ee9a174c1f KT-7897 Do not require to call enum constructor for each entry if all parameters have default values
Do not report an error on enum entry without initializer if all parameters have default values
(error is still reported if there is no such constructor, or if the constructor call is ambiguous).

Record resolved call on KtEnumEntry.

NB is the enum entry has a corresponding subclass, we still have to generate the "default" constructor call,
because FE doesn't know about the platform-specific representation of that class and its constructors.

See also KT-14097, KT-15900
2017-01-24 16:59:47 +03:00
Mikhail Zarechenskiy 2cac6a9e7d Improve inference on generics for callable references
#KT-10711 Fixed
 #KT-12802 Fixed
 #KT-12964 Fixed
 #KT-15439 Fixed

Analyze callable references in `dependent` mode, then complete them with
respect to expected types
2017-01-24 02:15:26 +03:00
Anton Bannykh 07bb7ef4d3 JS: extension lambdas translated same as local lambdas (KT-13312 fixed) 2017-01-23 20:09:36 +03:00
Alexander Udalov ebd577e52a Introduce KProperty{1,2}.getExtensionDelegate
These two functions are supposed to fix an inconvenience in the design of
KProperty{1,2}.getDelegate for extension properties, where you have to pass an
instance of the extension receiver which is going to be completely ignored

 #KT-8384 Fixed
2017-01-23 12:25:36 +03:00
Alexander Udalov 78f2515e95 Introduce KProperty{0,1,2}.getDelegate
#KT-8384 In Progress
2017-01-23 12:25:35 +03:00
Denis Zharkov 2edcd369a8 Fix inference issue with Stream.collect
See doNotCaptureSupertype test for clarification:
When resolving b.collect(toList()) we're building a common system with
two variables T and R.

The problem was that when introducing the constraint
C<T, Inv<T>> <: C<in String, R> we then were seeing the constraint
T <= in String, and add the constaint T=Captured(in String)

That lead to R=Inv<T>=Inv<Captured(in String)>, and after approximation
R=Inv<in String>, that is not the desirable result (Inv<String> suits here)

But the root problem was that we add captured constaint when projection was from supertype,
that seems to be wrong, and for example Java doesn't do that in the similar situation.

 #KT-11259 Fixed
2017-01-22 13:29:08 +03:00
Mikhael Bogdanov da1b8a02ed Exclude builtins members mapped to java default methods from delegation 2017-01-20 13:16:58 +01:00
Mikhael Bogdanov 591de36666 Added deprecated diagnostic for invoking default methods within jvm-target 1.6 2017-01-18 10:50:59 +01: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
Denis Zharkov 9f217de10b Write kotlin metadata on class-files for coroutine state machines
Otherwise it breaks JPS assumptions, that leads to exceptions like:
Error:Kotlin: [Internal Error] java.lang.AssertionError: Couldn't load KotlinClass from /Users/jetbrains/IdeaProjects/KotlinPlaygroundBeta11/out/production/KotlinPlaygroundBeta11/Counter$both$1.class; it may happen because class doesn't have valid Kotlin annotations
    at org.jetbrains.kotlin.build.GeneratedJvmClass.<init>(generatedFiles.kt:36)
    at org.jetbrains.kotlin.jps.build.KotlinBuilder.getGeneratedFiles(KotlinBuilder.kt:469)
    at org.jetbrains.kotlin.jps.build.KotlinBuilder.doBuild(KotlinBuilder.kt:241)
    at org.jetbrains.kotlin.jps.build.KotlinBuilder.build(KotlinBuilder.kt:140)
...
2017-01-16 17:53:15 +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 14f942aca7 Refine ABI for coroutine lambdas
Make their invoke work in the same way as any other suspend function:
it should return SUSPENDED_MARKER iff. it indeed became suspended
2017-01-14 19:51:05 +03:00
Denis Zharkov d346cbbe61 Update test data for light-analysis/coroutines 2017-01-14 15:13:37 +03:00
Denis Zharkov c7f76d7ec8 Minor. Fix tests after CoroutineContext introduction 2017-01-14 15:13:36 +03:00
Denis Zharkov 6a1ad3a279 Get rid of unnecessary additional declarations in tests 2017-01-14 13:24:53 +03:00
Roman Elizarov 8d6a913cee CoroutineContext and ContinuationInterceptor (instead of dispatcher) 2017-01-14 13:24:53 +03:00
Denis Zharkov f56d9cfb26 Ignore failing coroutine related tests on JS 2017-01-14 13:24:53 +03:00
Denis Zharkov c479aa7d65 JS: simplify how suspend functions inlined 2017-01-14 13:24:53 +03:00