Commit Graph

342 Commits

Author SHA1 Message Date
Alexander Udalov dcbb8045bd Disallow function types with big arity on JVM if LV < 1.3 or API < 1.3
The implementation is a bit obscure because this worked on JS since
Kotlin 1.0 and we should not break that; however, on JVM, a diagnostic
will be reported with old language/API version

 #KT-25241 Fixed
2018-07-16 10:41:27 +02:00
Alexander Udalov 56f509ba09 Support function types with >= 23 parameters
See https://github.com/Kotlin/KEEP/issues/107

 #KT-13764 Fixed
2018-07-16 10:41:27 +02:00
Alexander Udalov 66b383349f Fix regression in reflection on looking up equals/hashCode/toString in interface
Caused by 4266e50be8 and 8ccbbf71ec. Previously it worked because we
used hardcoded signatures of equals/hashCode/toString and always looked
them up in java.lang.Object

 #KT-25404 Fixed
2018-07-13 18:45:44 +02:00
Alexander Udalov 0d03d5abf6 Regenerate tests 2018-07-13 18:40:31 +02:00
Georgy Bronnikov 8478c73434 Make @JvmStatic work on JVM_IR 2018-07-13 13:43:02 +03:00
Mikhail Zarechenskiy 4e3674b330 Fix for-in iterator over list of boxed inline class values
#KT-25325 Fixed
2018-07-12 18:53:30 +03:00
Mikhail Zarechenskiy 0308e10c11 Fix for-in iterator over array of boxed inline class values
#KT-25324 Fixed
2018-07-12 18:53:24 +03:00
Anton Bannykh 0579b52d6b JS: enabled codegen box tests for release coroutines 2018-07-12 14:18:34 +03:00
Mikhael Bogdanov 9cf9cb3ecd Fix KotlinType building by IrType: don't miss type parameters of outer for inner class
#KT-25405 Fixed
2018-07-11 15:12:43 +02:00
Mikhail Zarechenskiy 8d24ca65a3 Propagate KotlinType into when expression codegen
This commit removes unneeded boxing when result expression of `when` is
 value of inline class type
2018-07-10 23:10:57 +03:00
Ilya Gorbunov be8cb94105 Add failing tests for overflow in empty progressions KT-24204 2018-07-09 22:08:01 +03:00
Mikhael Bogdanov 66e68fbb53 Generate sam wrappers in inlined lambda in same way as in inline function
#KT-24825 Fixed
2018-07-09 15:52:54 +02:00
Denis Zharkov 820506d9c6 Fix tests after new Continuation API support
#KT-24863 Fixed
2018-07-09 15:27:19 +03:00
Ilmir Usmanov bc8295b137 Minor: regenerate tests 2018-07-05 15:09:13 +03:00
Ilmir Usmanov 4ec82cad90 Minor: add test to call callable references from Java 2018-07-05 15:09:06 +03:00
Ilmir Usmanov 28ad498956 Use AnonymousFunctionDescriptor for suspend callable references
Also use it for local suspend functions, which allows us to remove hack
with dropSuspend.

Regenerate tests.
2018-07-05 15:08:49 +03:00
Ilmir Usmanov eea95441c5 Add diagnostics tests. Forbid callable reference to coroutineContext
#KT-16908: Fixed
2018-07-05 15:08:42 +03:00
Ilmir Usmanov f94b579d19 Implement callable references to suspend functions
In FE they have type KSuspendFunctionN
In BE they are treated like normal callable references with additional
parameter in invoke function.
2018-07-05 15:08:34 +03:00
Mikhail Zarechenskiy 2939d9c8c6 Use correct lhs KotlinType & AsmType for is check generation
There were two problems:
  - For asm type `OBJECT_TYPE` was used, which can be wrong in case of
  inline classes, because it can be an underlying value of some inline class
  - For KotlinType, type from rhs was used
2018-07-05 12:55:43 +03:00
Mikhail Zarechenskiy 4f490ac264 Fix generation of checkcast instructions for inline classes
Normalize LHS and RHS types to use only boxed ones and then let bytecode
 optmizer reduce redundant boxing
2018-07-05 12:55:39 +03:00
Alexander Udalov 4266e50be8 Use manual type mapping in reflection for members from built-ins
There are cases when members deserialized from JVM classes have no JVM
signature in the proto. For example, if a member is inherited from a
built-in class (such as Map.getOrDefault in some Map implementations),
or if a member is synthesized in the compiler front-end and back-end
separately (such as enum values/valueOf). In these cases, we'll use the
naive type mapping to try to recover the signature.

 #KT-16616 Fixed
 #KT-17542 Fixed
2018-07-02 18:49:08 +02:00
Alexander Udalov 17fc41e0f9 Do not create primary constructor for enum entry synthetic class
The change in DescriptorSerializer is needed so that serialized protos
of enum entry classes which are resolved in sources
(LazyClassDescriptor) and are deserialized from binaries
(EnumEntrySyntheticClassDescriptor) are the same. There are tests on
incremental compilation in JS that check that the serialized proto is
exactly the same after rebuild and after an incremental build.

 #KT-22048 Fixed
2018-07-02 18:49:08 +02:00
Roman Artemev c887b88ed9 Fix coroutine test generator 2018-07-02 15:35:02 +03:00
Denis Zharkov 3b968351bb Load Java overrides of Kotlin suspend functions as suspend, too
There's still some blind spots:
- Covariant overrides in Java (KT-25036)
- Current implementation assumes that when language version is 1.3 every suspend function
reference only release-coroutines-package Continuation
(we need to check if it's a correct statement)

 #KT-24848 Fixed
 #KT-25036 Open
2018-07-02 14:14:59 +03:00
Dmitry Petrov 46a3f7420c When in debugger context, access private companion object directly 2018-06-26 16:46:55 +03:00
Alexander Udalov 1951d38f40 Retain optional expected annotations when compiling platform code
After this change, optional expected annotations will be compiled to
physical class files on JVM, and stored to metadata on other platforms,
to allow their usages from dependent platform modules. For example:

    @OptionalExpectation
    expect annotation class A

When compiling this code on JVM, A.class will be produced as if the
class A did neither have the 'expect' modifier, nor had it been
annotated with OptionalExpectation. Note that if there's no actual
annotation class for A, then usages (which can only be usages as
annotation entries) are simply skipped.

Class A will be public from Kotlin's point of view (since it should
be possible to use it in Kotlin sources), but _package-private_ in Java
to disallow its usages outside of the declaring module.

 #KT-18882 Fixed
 #KT-24617 Fixed
2018-06-26 10:23:55 +02:00
Mikhail Zarechenskiy 333411c57d Associate vararg of unsigned types with corresponding arrays
This is a first step, full support will be added later

 #KT-24880 In Progress
2018-06-25 17:15:47 +03:00
Dmitry Petrov d35a92a81d Generate accessor for private companion object 2018-06-22 16:53:07 +03:00
Denis Zharkov a644cbb5ed Fix deserialization of kotlin.suspend when LV=1.3 is used
Before this change, kotlin.suspend was being loaded as having a common
function type instead of suspend function type.

With LV=1.3, we expect that suspend function types should have
new Continuation interface as a last type argument, while
kotlin.suspend is built with LV=1.2 and has old Continuation.

This change might be reverted once stdlib will be rebuilt with LV=1.3

NB: kotlin.suspend doesn't need to be intrinsified since it only returns
its parameter with checkcast to kotlinin.jvm.functions.Function1
(i.e., it doesn't refer the coroutines package)

 #KT-24861 Fixed
2018-06-21 16:02:13 +03:00
Dmitry Petrov a7492e91c9 Check that subject expression is evaluated only once 2018-06-20 14:06:34 +03:00
Dmitry Petrov 34b76a3718 Support subject variable in specialized code generators for 'when' 2018-06-20 14:06:34 +03:00
Dmitry Petrov 6949610dcb 'val' in 'when': IEEE754 equality 2018-06-20 14:06:34 +03:00
Dmitry Petrov d6894091a9 Support 'when' with subject variable in JVM BE 2018-06-20 14:06:34 +03:00
Mikhail Zarechenskiy fcacdc1fc5 Fix bridge methods generation when inline class types are used 2018-06-19 20:09:35 +03:00
Mikhail Zarechenskiy f326fd66be Propagate KotlinType into if expression codegen for inline classes 2018-06-19 19:54:22 +03:00
Alexander Udalov 863639c9ab Revert changes to data class equals/hashCode (KT-12330)
This looked like a small and useful change, but caused so many issues
(KT-24474, KT-24790, 30b9caea, and another unreported one -- see the
test update in this commit) that it didn't pay off after all. The
optimization is not that critical for now, as it's only relevant for
data classes where component types have trivial equals/hashCode
implementation, which is not very often

 #KT-12330 Declined
2018-06-19 12:05:55 +02:00
Mikhail Zarechenskiy 6431934c13 Fix signature mapping for built-in methods inside erased inline class 2018-06-18 18:55:18 +03:00
Mikhail Zarechenskiy c5160a6a95 Don't use methods from super interface if call was on inline class type
Some methods (like `size` from kotlin.collections.Collection) have
 special rules for mapping and overriding. For example, when we call
 `size`, normally there will be `INVOKEVIRTUAL size()` in the bytecode,
 but for inline classes it should be `INVOKESTATIC ...$Erased.getSize()`
2018-06-18 12:35:31 +03:00
Alexander Udalov 5d76e463d3 Fix exception from reflection on local delegated properties
The problem was that in JvmSerializerExtension.writeLocalProperties, we
only serialized metadata for local properties, but indices generated in
MemberCodegen.generatePropertyMetadataArrayFieldIfNeeded were among all
delegated properties in the class (not only local). This behaved
incorrectly as long as there was a local and a non-local delegated
property in the same class. For example, if there were 5 non-local
properties and then one local, that local property would get the index 5
and the synthetic signature "<v#5>". But there would only be one
Property entry in the metadata, and so reflection would fail here trying
to load the 5th element of the list which contains only one element.

Now, the index for a local delegated property is computed only as the
number of _local_ delegated properties above it in the class, i.e. the
first local delegated property gets index 0 (and synthetic signature
"<v#0>"), the next one -- index 1, and so on.

 #KT-23413 Fixed
2018-06-14 11:07:26 +02:00
Alexander Udalov 813d7fcb6a Fix bytecode for equals/hashCode of data classes once again
#KT-24790 Fixed
2018-06-13 16:06:20 +02:00
Ilmir Usmanov 6b777356e8 Add test with java reflection 2018-06-13 15:08:32 +03:00
Ilmir Usmanov 8a5ae16947 Generate separate methods for inline and noinline uses of inline suspend functions
Previously, inline suspend functions were effectively inline only,
but ordinary inline functions can be used as noinline.
To fix the issue, I generate two functions: one for inline with suffix
$$forInline and without state machine; and the other one without any
suffix and state machine for direct calls.
This change does not affect effectively inline only suspend functions,
i.e. functions with reified generics, annotated with @InlineOnly
annotation and functions with crossinline parameters.
 #KT-20219: Fixed
2018-06-13 15:08:19 +03:00
Mikhail Zarechenskiy d29f3fc3c5 Add test to check work of inline classes with callable references 2018-06-08 19:14:41 +03:00
Mikhail Zarechenskiy cc19e4cd73 Refactoring: Move blackbox tests about unsigned types to new directory 2018-06-04 18:37:44 +03:00
Mikhail Zarechenskiy 5b5d9dd5a0 Allow unsigned integers overflow values of corresponding signed numbers 2018-06-04 18:37:40 +03:00
Mikhail Zarechenskiy 7d5fdb660d Treat number with unsigned literal as UByte & UShort & UInt & ULong 2018-06-04 18:37:36 +03:00
Mikhail Zarechenskiy 656f6cbded Support constant evaluation of unsigned type constructors
#KT-23816 In Progress
2018-06-04 18:37:34 +03:00
Mikhail Zarechenskiy e5958d228a Introduce WITH_UNSIGNED directive to use unsigned types in tests 2018-06-04 18:19:30 +03:00
Stanislav Erokhin 8f0b073c08 [NI] Prototype for SAM-conversion.
Supported:
- conversion in resolution parts. Also sam-with-receiver is supported automatically
- separate flag for kotlin function with java SAM as parameters

TODO:
- fix overload conflict error when function type is the same byte origin types is ordered
- consider case when parameter type is T, T <:> Runnable
- support vararg of Runnable

[NI] Turn off synthetic scope with SAM adapter functions if NI enabled
2018-06-04 12:21:56 +03:00
Alexander Udalov b5007c417d Minor, restructure reflection tests a little
To allow their usage in https://github.com/udalov/kotlin-obfuscation-test-app
2018-05-30 13:03:10 +02:00