Commit Graph

145 Commits

Author SHA1 Message Date
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
Mikhael Bogdanov 5cffb3892d Added intrinsics for nullable Double/Float equals check 2017-02-02 16:31:49 +01: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
Mikhael Bogdanov 1e2b50332d Test data update 2017-02-02 09:39:03 +01:00
Mikhael Bogdanov a2c5c94ee6 Fix for KT-15868: NPE when comparing nullable doubles
#KT-15868 Fixed
2017-02-01 17:43:56 +01:00
Anton Bannykh 385a02ea55 Added forgotten kt8666.txt for LightAnalysisModeCodegenTestGenerated 2017-02-01 18:20:30 +03:00
Dmitry Petrov 7600f89f0b KT-15574 Can't instantiate Array through Type Alias
Array instatiation code should handle type alias constructors properly.

So far, we don't have constructors with type parameters
different from the type parameters of the resulting type,
so we can safely take type arguments of the underlying type.
2017-02-01 17:14:50 +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
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
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 ab2448307e Functions imported from objects should be properly mapped to "real" suspend function descriptors. 2017-01-26 09:39:53 +03:00
Alexey Andreev 0f87320f9e JS: regenerate test data 2017-01-25 18:09:23 +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 115f6ced87 JS: fix support of throwable constructors without message and/or cause parameters 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 119bf52adf JS: fix translation of callable reference to property of outer class with private setter 2017-01-24 20:09:32 +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 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
Mikhael Bogdanov b88a9025e0 Don't check DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE when compiling to 1.0 2017-01-13 18:01:05 +01:00
Dmitry Petrov ba933fa887 KT-15112, KT-15631
Revert changes for "tolerant to uninitialized values" in OptimizationBasicInterpreter:
this approach doesn't converge for some specific cases where local variable is reused
(e.g., in several inlined functions - see https://youtrack.jetbrains.com/issue/KT-15112).

Instead, treat fake always-false conditional jump in the beginning of the post-condition loop as a "reference point" for stack on loop break / continue.
This requires an extra abstraction layer in FixStackAnalyzer, since we can't perform fine-grain manipulations on Frames
(such as "combine frame C from local variables of frame A and stack of frame B").

NB additional NOPs will be generated for post-condition loops.
Should make a separate bytecode postprocessing pass to get rid of unnecessary NOPs
(several YT issues for perceived quality of the generated bytecode are about such NOPs).
2017-01-13 10:31:07 +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
Alexey Andreev 4eed7c1fcb JS: fix translation of augmented assignment in class initializer. See KT-15569 2017-01-12 18:12:38 +03:00
Alexey Andreev e6b78f68cd JS: support case when class inherits method from superclass and both implements same method (but with optional parameter) from superinterface. 2017-01-12 18:12:36 +03:00
Mikhael Bogdanov 2931c316a3 Fix for KT-15575: VerifyError: Bad type on operand stack
#KT-15575 Fixed
2017-01-11 11:50:33 +01:00
Mikhael Bogdanov 043f3199c7 Fix for KT-15446: Property reference on an instance of subclass causes java.lang.VerifyError
#KT-15446 Fixed
2017-01-10 14:09:42 +01:00
Alexander Udalov 32d2faf3d1 Fix KAnnotatedElement.findAnnotation when no annotation is found
#KT-15540 Fixed
2017-01-10 12:23:26 +03:00
Mikhail Zarechenskiy cff0865c87 Fix error type for implicit invoke with function literal argument
#KT-11401 Fixed
2017-01-10 11:44:51 +03:00