Commit Graph

1059 Commits

Author SHA1 Message Date
Mikhael Bogdanov 2ed0cb2a89 Support type annotations
#KT-35843 Fixed
2020-01-09 14:00:11 +01:00
Alexander Udalov 8a4510c21b Regenerate tests 2020-01-02 10:31:00 +01:00
Alexander Udalov cc0b231b3b Convert SyntheticMethodForAnnotatedPropertyGenTest to a box test 2019-12-30 16:30:50 +01:00
Dmitry Petrov 98bf0e278f Fix problem with empty vararg of boxed primitives in JVM_IR
When calling a generic Java generic method with vararg parameters with empty
vararg, incorrect array creation instruction was generated for primitive type:
NEWARRAY T_INT instead of ANEWARRAY java/lang/Integer. Here for Java method

  public static <T> void takesVarargOfT(T x1, T... xs) {}

corresponding vararg parameter was considered to be of type 'Array<T>?',
which is not a non-null array type, so, NewArray intrinsic failed to generate
proper bytecode.
2019-12-30 11:26:21 +03:00
Mark Punzalan 2dd8727baf [JVM IR] ForLoopsLowering: Keep IMPLICIT_NOTNULL type-casts in next()
and `componentN()` calls.

There were issues when we have iterables from Java where the element
type has "not null" type information.
2019-12-26 10:11:18 +03:00
Dmitriy Novozhilov b54169d312 [NI] Fix substitution in completion of callable references in coroutine inference 2019-12-25 16:19:19 +03:00
Dmitry Petrov a8e9a6a1d0 Properly reference type parameter descriptors
'descriptor -> descriptor.original' relation is often inconsistent
wrt 'containingDeclaration', parameters, and type parameters,
we have to introduce some workarounds here.
2019-12-25 14:20:47 +03:00
pyos 982a088f00 JVM_IR: do not copy defaults in functions with inline class parameters 2019-12-24 18:59:33 +03: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
pyos 59f2aa7add JVM_IR: remove constructors of nested annotations 2019-12-23 13:59:42 +01:00
pyos 17d2fda946 JVM_IR: keep nullability when remapping type parameters 2019-12-23 14:28:05 +03:00
Dmitriy Novozhilov c94dd2939e [NI] Add test for KT-32429
#KT-32429 Can't Reproduce
2019-12-20 11:33:06 +03:00
Dmitriy Novozhilov 26f7bf1c21 Regenerate tests 2019-12-20 11:33:06 +03:00
Alexander Gorshenev dc8240c24e Expect/actual support in klibs under -Xklib-mpp 2019-12-18 19:29:56 +03:00
Georgy Bronnikov 220ea72d65 JVM_IR: add coercion for index in ArrayGet intrinsic 2019-12-18 13:03:12 +03:00
Alexander Udalov 7eda60d57e Minor, add more tests on signature-polymorphic calls
Add a test on null (since null is a special case in the
PolymorphicSignature spec), and a test on a call without assignment to a
variable
2019-12-17 18:44:19 +01:00
Alexander Udalov 64d40b4743 Support JVM polymorphic signature calls to methods with void return type
#KT-32026 Fixed
2019-12-17 18:39:05 +01:00
Ilmir Usmanov b6de3c2fcc Disable tail-call optimization for suspend functions with Unit return type
if it overrides functions with another return type.
Otherwise, we cannot determine on call site that the function returns Unit
and cannot { POP, PUSH Unit } in order to avoid the situation when callee's
continuation resumes with non-unit result. The observed behavior is that
suspend function, which should return Unit, suddenly returns other value.
 #KT-35262: Fixed
2019-12-17 12:08:35 +01:00
Alexander Udalov f51a0048f6 Minor, rename test and avoid commented directive
Get rid of "_lv12" in the test name, since it's actually a test on the
modern compiler. Also, avoid the commented "IGNORE_BACKEND: JVM_IR"
directive in another test to make JVM IR test failures more greppable.
2019-12-16 17:38:11 +01:00
Anton Bannykh d6fcde7316 JS_IR: fix typecheck corner case
Consider `fun <E : I> foo(a: Any?) = a as? E`, where I is an interface.
This check used to fail, because the `a == null` was missing, and
the `isInterface` stdlib method crashes if the first argument
is null. This change adds the null check.

Also this change prettifies the instance check in case of type parameter
left operand.
2019-12-15 17:36:24 +03:00
Anton Bannykh 9a971172c9 JS: fix object expression constructor delegation to secondary constructors with default arguments (KT-30517 fixed) 2019-12-15 15:21:23 +03:00
Georgy Bronnikov 92c2cfa968 JVM_IR: handle property references at class level 2019-12-13 20:44:09 +03:00
Victor Petukhov 07269661b4 NI: Allow to resolve to functions with SAM conversion and passing array without spread as vararg (with warning)
^KT-35224 Fixed
2019-12-12 23:46:16 +03:00
Dmitriy Novozhilov e7f8c8e155 [TEST] Regenerate tests after previous commit 2019-12-12 16:11:45 +03:00
Georgy Bronnikov bb301f8aca JVM_IR: fix wrong check in skipping captured vars 2019-12-12 15:38:18 +03:00
Mikhael Bogdanov c335015c05 Generate proper exception table
Don't forget to split nested try blocks without finally block
 on generating finally blocks from outer ones.

 #KT-31923 InProgress
2019-12-12 13:33:39 +01:00
Alexander Udalov 5f367278c1 Psi2ir: support generic properties in class delegation
Since property accessor descriptors (unlike corresponding IR elements)
do not have type parameters, we need to take them from the corresponding
property to ensure the correct IR for delegated property accessors.
2019-12-12 15:02:32 +03:00
Alexander Udalov 025360edc4 JVM IR: lookup symbols by name in ProgressionHandlers in known classes only
Alternatively, we could improve the lookup utilities and their usages to
always find the exact override of a symbol from
Collection/Iterable/CharSequence/etc, but since we need to load the
original symbol anyway in cases when the loop subject's type is a type
parameter, we might as well simplify everything and always reference the
original symbol.

Also improve exception message and removed unused declarations in
IrBackendUtils.kt.
2019-12-12 14:55:47 +03:00
pyos 498b41b148 JVM_IR: do not do invokeinterface on Object methods
This works on HotSpot, but might confuse other VMs.
2019-12-11 15:09:37 +01:00
victor.petukhov a92f58b1ac Revert "NI: Prefer nullable lower bound to flexible one when substitution of type variable is performed ^KT-32435 Fixed"
This reverts commit 09c2b92b
2019-12-11 15:32:46 +03:00
Victor Petukhov 09c2b92b1d NI: Prefer nullable lower bound to flexible one when substitution of type variable is performed
^KT-32435 Fixed
2019-12-11 12:15:02 +03:00
Georgy Bronnikov 094de9fb5e IR: Do not capture variables from method calls in ClosureAnnotator
To call a method of a class, you never need to supply any values of
local variables (they would always be provided to the constructor).
2019-12-10 17:31:12 +03:00
Dmitry Petrov fc7783c7dd JVM_IR: JvmArgumentNullabilityAssertionsLowering 2019-12-06 11:03:06 +03:00
Alexander Udalov f869be6a71 JVM IR: do not mangle synthetic methods with inline class parameters
For example, synthetic `$annotations` methods for properties were
previously mangled to `$annotations-...`, which breaks annotation
loader, and fails an assert in ClassCodegen.generateMethod.
2019-12-03 11:34:55 +01:00
pyos 35c2573b33 PSI2IR: generate IrEnumConstructorCalls with correct return type
Normally, the fact that is was Unit was not visible as enum constructors
are lowered to normal class constructors anyway. The exception is when
the arguments are reordered, causing the incorrect return type to leak
into the block that holds temporary variables.
2019-12-03 11:54:41 +03:00
Kristoffer Andersen d1c2862e27 IR: Align Interface Defaults with Old Backend
Change the treatment of default implementations on interfaces in JVM
compatibility mode. Previously, the IR backend moved the actual
default implementation to the DefaultImpls class, and then bridged to
it from the interface default. The old backend did the reverse, at the
cost of an additional accessor, in order to gain better binary
compatibility properties. See #2612 for discussion.

The accessor needs to call a specific implementation, so must be
performed through an `invokespecial`. We trick the
SyntheticAccessorLowering into doing this for us, by marking the
bridging call as a super call. We do this in want of an explicit
`invokespecial` Ir Node.

InterfaceDefaultCallsPhase previously assumed the old behaviour of the
IR backend (that calls to default implementations, e.g. `foo$default`
should target `DefaultImpls.foo$default`). But now the bridge to
foo$default resides on `DefaultImpls` already, causing that pass to
create a recursive loop. We cut that loop with a simple check.
2019-12-02 08:19:52 +01:00
Ilmir Usmanov 51a9df2902 JVM_IR: Support suspend lambdas with receivers and multiple parameters
In old BE we generate `create` for this kind of suspend lambdas, which,
like in simple suspend lambdas is responsible for putting arguments
(including extension receiver) to fields.
But, if number of parameters of suspend lambda (including receiver) >= 1,
there is no need to generate `create`, since `create` is called only by
`createCoroutine` and friends from stdlib, and there is no version of
`createCoroutine` for lambdas with multiple parameters.
Thus, in old BE we generate a redundant method, which affects method
count.
In JVM_BE we decided to 'inline' create into `invoke` for suspend lambdas
with multiple parameters.
2019-11-28 21:19:27 +03:00
pyos 98660cdf2d JVM_IR: serialize anonymous functions' descriptors 2019-11-28 18:17:01 +01:00
Mark Punzalan 1a2e09e6a5 ForLoopsLowering: Handle Iterable.withIndex() where the type is a
bounded type parameter.

TODO: Handle Sequences by extending DefaultIterableHandler.
2019-11-27 10:59:34 +01:00
Pavel Kirpichenkov 4622041706 Update box test for unsigned to signed conversions
Updated test checks, that large unsigned numbers are converted to corresponding
negative signed numbers properly. Using unsinged constants instead of signed
in test allows to remove supressed OI error as well as use test with NI.
2019-11-25 12:22:58 +03:00
Pavel Kirpichenkov f80a71517f [NI] Handle vararg parameter in reflection type wrt array types
Vararg parameter in reflection type is interpreted as covariant
array type against array in expected functional type and as
vararg element type otherwise. For instance having function
fun foo(vararg args: Int): Unit { /*...*/ }
reference ::foo can be passed against expected
(Int) -> Unit,
(Int, Int) -> Unit, etc.
In none of such cases type for parameter in foo's reflection type
should be changed to array.
However, against expected type (IntArray) -> Unit args' type
must become IntArray.

^KT-25514 Fixed
2019-11-21 20:07:14 +03:00
pyos d221c1f242 JVM_IR: refactor MoveCompanionObjectFieldsLowering
* Extract replacement of IrGetField/IrSetField into a separate
   file-level lowering (should reduce the amount of work to linear in
   the number of classes rather than potentially quadratic)

 * Extract static backing field construction into JvmDeclarationFactory
   and move that lowering after PropertiesToFields lowering to reduce
   code duplication
2019-11-21 15:14:44 +01:00
Alexander Udalov bf06d381b9 Minor, move old Java nullability assertion tests under oldLanguageVersions/
Also drop the (now confusing) "_lv12" suffix from newer tests
2019-11-21 13:46:17 +01:00
Dmitry Petrov d3a5dcb601 KT-35004: keep track of KotlinType for 'when' subject 2019-11-21 10:48:14 +03:00
pyos 7c015564ce JVM_IR: do not set ACC_VARARGS if vararg is not the last parameter
Fun fact: this is not actually validated when loading the class; and
even when compiling a java file against a class file that does this,
only javac 9 has a check (1.8 and before simply crashes with
NullPointerException somewhere deep inside the compiler).
2019-11-20 13:40:46 +01:00
Mark Punzalan 7adffe0007 Handle withIndex() on Iterables (including progressions) and Sequences
in ForLoopsLowering.
2019-11-20 13:02:21 +01:00
Mark Punzalan a54d9482dd Handle withIndex() on arrays and CharSequences in ForLoopsLowering. 2019-11-20 13:02:21 +01:00
Mark Punzalan 7f803e60b6 Fix typo in forInArrayWithIndex testdata filenames. 2019-11-20 13:02:21 +01:00
Georgy Bronnikov 119a3f1306 JVM_IR: do not generate accessors to lateinit private properties 2019-11-19 16:30:04 +03:00
Roman Artemev c459b2ca6e [JS IR] Fix state machine control flow
- exception loop unwinding: make sure exception state is reset after try block is finished
 - break/continue of suspended loops
2019-11-19 11:15:36 +03:00