Commit Graph

199 Commits

Author SHA1 Message Date
pyos e0a5ab7146 Do not regenerate objects if all captured lambdas are noinline 2020-03-19 15:11:20 +01:00
pyos 2c06503311 JVM_IR: partially fix inline methods using captured crossinline lambdas
The fields containing crossinline lambdas should be package-private to
avoid generating synthetic accessors, which break object regeneration.

Note that the inline methods cannot actually be called, as call sites
will attempt to read the captured lambda from a field through a *copy*
of the local containing the object, so these reads will not be inlined,
causing an exception at runtime:

    inline fun f(crossinline g: () -> Unit) = object : I {
        inline fun h() = g()
        // effectively `val tmp = this; return tmp.$g()`:
        override fun run() = h()
    }

    f {}.run() // NoSuchFieldError: $g

This particular example can be fixed by reusing locals for receiver
parameters in IrInlineCodegen, but explicitly assigning `this` to
another variable and calling an inline method on it will break it again.
(This is only applicable to the JVM_IR backend, as the non-IR one fails
to generate `f` at all for some other reason.)
2020-03-18 13:13:54 +01:00
Dmitry Petrov dd27b3d4f1 KT-36973 Keep private default interface members private 2020-03-18 14:18:47 +03:00
Dmitry Petrov 1c24a97b9e KT-36972 Don't create proxies for companion @JvmStatic $default in host
When creating proxy functions in a host class for @JvmStatic members of
companion object, skip functions for default parameters handling.
2020-03-18 13:33:56 +03:00
Ilmir Usmanov 7efab887aa JVM_IR: Do not generate accessor for private function
if the function is called in suspendCoroutine's lambda.
 #KT-37242 Fixed
2020-03-12 11:15:46 +01:00
Ilmir Usmanov fd70b10b17 JVM_IR: Generate suspend fun main wrapper as class instead of reference
This way, there is no getName, getOwner and getSignature generated.
 #KT-37404: Open
2020-03-11 15:34:38 +01:00
Steven Schäfer 34fb636904 JVM: Generate generic signatures for delegate fields 2020-03-06 21:51:30 +01:00
Alexander Udalov 98aecbef6b Optimize runtime representation for callable reference subclasses
Instead of generating overrides for getOwner/getName/getSignature in
each anonymous class representing a callable reference, pass them to the
superclass' constructor and store as fields. This occupies some small
memory but helps to reduce the size of the generated class files, and
will be helpful for adding further runtime information to callable
references, such as information about implicit conversions this
reference has been subject to.

Represent owner as java.lang.Class + boolean instead of
KDeclarationContainer, so that the unnecessary wrapping Class->KClass
wouldn't happen before it's needed, and also to make sure all callable
references remain serializable.

Note that the argument type where the "is declaration container a class"
is passed is int instead of boolean. The plan is to pass the
aforementioned implicit conversion information as bits of this same
integer value.

 #KT-27362 Fixed
2020-03-06 16:55:07 +01:00
Ilmir Usmanov 354fb3c4ba JVM_IR: Generate fake continuations and their constructors as public
#KT-37093 Fixed
2020-03-04 21:32:35 +01:00
Ilmir Usmanov c94f8d3767 JVM_IR: Do not generate nullability annotation for synthetic result field
of continuation class.
 #KT-37084 Fixed
2020-03-04 21:32:34 +01:00
Ilmir Usmanov 4b4a6101c1 JVM_IR: Generate inline functions with reified generics as public synthetic
Otherwise, proguard will remove them.
 #KT-37004 Fixed
2020-03-04 21:32:31 +01:00
Ilmir Usmanov f8903ca04b JVM_IR: Generate private suspend functions as synthetic package-private
Do not generate accessors for them.
 #KT-37086 Fixed
2020-03-04 21:32:29 +01:00
Ilmir Usmanov 5826db97c7 JVM_IR: Do not duplicate inline suspend functions with reified type parameters
They are inline-only.
Generate $$forInline versions of inline suspend functions as private.
This way, there is no nullability annotation on there parameters and return
values. Unfortunately, old BE does generate them.
 #KT-37088 Fixed
2020-03-04 21:32:27 +01:00
Ilmir Usmanov 42420cb6fc JVM_IR: Generate inner classes for continuations
Also, generate correct visibilities for constructors and continuation's fields.
2020-03-02 14:03:33 +01:00
Dmitry Petrov 84baa0b4c2 Check more flags in bytecode listing tests 2020-02-26 12:03:37 +03:00
Mark Punzalan b782e8f0f0 Add IR equivalent of AbstractBytecodeListingTest and muted failures. 2020-02-13 23:44:53 +03:00
Mark Punzalan 06b6477d04 [JVM IR] Do not add nullability annotation for functions that return
platform types.

This behavior matches the non-IR backend, which was added in
f16dcdd8a9.
2020-02-13 23:44:53 +03:00
Ilya Gorbunov 9f8e3dad33 Add coroutines-compat jar dependency to those tests that require it
#KT-36083
2020-01-29 09:12:40 +03:00
Dmitriy Novozhilov 76b3964e96 Update testdata according to change compiler version to 1.4 2020-01-17 10:33:50 +03:00
Alexander Udalov e2a42446ed Use getter names for $annotations methods in most codegen tests
This is needed to update master to 1.4, while still testing the latest
compiler by default. Also add one test on the old behavior.
2019-12-30 16:29:13 +01:00
Ilya Chernikov f38bb19fc6 [minor] Fix testdata for compiler 1.4 2019-12-19 14:01:01 +01:00
Toshiaki Kameyama 4d9b19da82 Remove comments from function/property implementation template
#KT-18539 Fixed
2019-11-13 08:37:25 +09:00
Nikolay Krasko 4d0fc1dc22 Remove 182 support
#KT-33536 Fixed
2019-08-30 12:13:44 +03:00
Alexander Udalov 01ddac58e1 Add language feature for changed name of property annotations method
#KT-31352 Fixed
2019-08-12 16:48:26 +02:00
Alexander Udalov ea0142da60 Use JVM name of getter in synthetic method for property annotations
#KT-31352 In Progress
2019-08-12 16:48:25 +02:00
Ilmir Usmanov e60674f5e1 Fix test data 2019-07-29 20:34:51 +03:00
Ilmir Usmanov a35d405892 Do not generate accessor if private function is accessed from
coroutines intrinsic lambda.
The logic is if the lambda is crossinline we need to generate the
accessor. However, suspendCoroutine's and
suspendCoroutineUninterceptedOrReturn's parameter, despite being
crossinline, are effectively inline. Thus, we do not need to generate
the accessor.
 #KT-27503 Fixed
2019-07-25 15:25:59 +03:00
Alexander Udalov f9d61f2dc7 Make inline+reified functions synthetic instead of private in bytecode
#KT-18563 Fixed
2019-05-28 16:17:49 +02:00
Alexander Udalov b42adcd73d Restructure bytecode listing tests on InlineOnly/inline+reified 2019-05-28 15:56:15 +02:00
Ilmir Usmanov 266976ac1e Fix Java interop of inline suspend functions with suspend parameters
In 1.3.31 I fixed Java interop for inline function with coroutines
(TL;DR: when we need a state machine, generate two methods: one with
normal name, and the other one with $$forInline suffix, for the inliner
to use, just like inline suspend functions), however, I forgot a case
with inline suspend function with inline suspend function parameter.
In this case, the compiler a generated two functions, as needed, but,
neither of them had a state-machine. This change adds the state-machine
for the method with normal name. Note, that suspend inline functions
with crossinline parameter, which are also supported by the change,
did not cause incorrect behaviour, since until now they were generated
as synthetic.

 #KT-31354 Fixed
2019-05-21 17:50:25 +03:00
Ilmir Usmanov 360e30c133 Remove redundant continuation classes and INNERCLASS nodes
#KT-31339 Fixed
2019-05-14 16:00:39 +03:00
Ilmir Usmanov 20b9d8b2f3 Generate state-machine even if the object is going to be transformed
This fixes Java interop of inline functions, which use coroutines.
However, we cannot transform the state-machine. Thus, we generate
a $$forInline counterpart for suspend functions (similar to inline
suspend functions) and invokeSuspend$$forInline for lambdas if these
coroutines are going to transformed (i.e. are declared inside inline
functions).
During transformation we just skip method with state-machine and
transform the $$forInline counterpart. Of course, if inline site is
inline itself, we generate both state-machine version (which will be
dropped during the next transformation) and $$forInline version.
Consequently, the final version of the coroutines will not have
$$forInline counterpart.
Unfortunately, since CompileKotlinAgainstInlineKotlin tests do not allow
java sources, the tests for the interop are usual box tests.

 #KT-30707 Fixed
2019-04-18 01:12:52 +03:00
Ilmir Usmanov 00e952ab15 Introduce CHECK_TAIL_CALL_OPTIMIZATION directive
This directive generates TailCallOptimizationChecker in package helpers.
The check for tail call optimization is based on coroutine stack traces
bug (feature?): when tail call optimization hits, the continuation
object is not generated. Thus, there is no debug metadata for this
suspend function. Consequently, the coroutines stack trace does not
contain stack trace element for that function.
This check is performed by TailCallOptimizationChecker.

Since this is runtime check, unlike bytecode tests, it does not require
test data adjustments on each codegen or inliner change.

Since the check is based on debug metadata, which is JVM specific, there
is not support for other backends yet.
2019-04-09 18:01:21 +03:00
Ilmir Usmanov d154cf9a59 Fix test data 2019-03-18 14:04:04 +03:00
Ilmir Usmanov 7956ef18b2 Generate RETURN instead of ARETURN if (cross)inline suspend lambda returns Unit
#KT-30073 Fixed
2019-03-18 14:04:02 +03:00
Mikhael Bogdanov 3b57ceeafe Don't generate annotations on $default methods
#KT-29965 Fixed
2019-02-19 10:51:37 +01:00
Ilmir Usmanov 440cccae73 Loosen tail call check
Check that any source of ARETURN is inside a suspension point, not all
of them.
 #KT-27190 Fixed
2019-02-14 12:21:44 +03:00
Ilmir Usmanov dc6bb4cd08 Revert "Simplify tail-call optimisation check"
This reverts commit a5bcd3495e.

 #KT-27190: Open
 #KT-29327: Fixed
2019-01-18 13:44:05 +03:00
Alexander Udalov ec2dd58165 Remove LANGUAGE_VERSION from codegen tests on coroutines
Use `// !LANGUAGE: -ReleaseCoroutines` instead in tests which require
old (1.2) coroutines, and nothing in tests which require new coroutines
because master is already 1.3. Also remove superfluous API_VERSION and
other directives which have no effect anymore. Do not include runtime
automatically with `WITH_COROUTINES`/`COMMON_COROUTINES_TEST` in box
tests; require `WITH_RUNTIME` for that (majority of tests already had it
anyway), but remove it from bytecode text tests where runtime is always
added automatically. Fix the coroutine package selection code in
KotlinTestUtils and update the bunch files correspondingly.

Disable tests in `box/coroutines/noStdLib` on JVM: despite the name,
these tests were launched with stdlib because of the code in
CodegenTestCase, and they do not work without it because at least
CoroutineUtil.kt requires stdlib to compile correctly
2018-12-20 12:53:23 +01:00
Alexander Udalov 5b58eb8491 Remove LANGUAGE_VERSION from non-coroutine codegen tests
Most of these tests used this directive as a way to opt in to a new
language feature, and most of those features are already stable for a
long time, so no opt-in is needed. Some other tests used the directive
to opt out from a language feature, replace those by the `LANGUAGE`
directive. One test used the directive to test behavior that actually
depended on the API version; use `API_VERSION` directive there instead.
2018-12-20 12:53:23 +01:00
Alexander Udalov c1ef89df2c Make anonymous classes for callable references synthetic
#KT-28453 Fixed
2018-12-18 17:48:19 +01:00
Vyacheslav Gerasimov d84c5b1608 Switch to 183 platform 2018-12-06 20:16:58 +03:00
Mikhael Bogdanov d2a205c72d Update synthetic parameter processing logic according to ASM 7 changes
#KT-27774 Fixed
2018-11-07 15:42:57 +01:00
Alexander Udalov 17d740a373 Do not try computing return type in OverloadChecker
Return type is not needed for checking overloads, but querying it may
involve resolving function bodies, which usually happens after overload
checking (see LazyTopDownAnalyzer.analyzeDeclarations) and at this point
can lead to incorrect BACKING_FIELD_REQUIRED value being computed for
some properties (see KT-27895)

 #KT-27895 Fixed
2018-11-07 11:00:15 +01:00
Alexander Udalov 5fb1bbe3f3 Add bytecode listing test on private default setter
Also fix test data of the kotlinp test and remove the newly added test
case in the obsolete PropertyGenTest

 #KT-20344 Fixed
2018-10-18 12:13:22 +02:00
Dmitry Petrov f68ce4b35b Support default parameter values for inline class constructors and funs
#KT-26908
 #KT-26554

Move default parameter value tests to separate directory
2018-10-15 12:21:14 +03:00
Ilmir Usmanov a5bcd3495e Simplify tail-call optimisation check
Check, that all suspension points are immediately followed by ARETURN
and do not check that all these ARETURNs are immediately preceded by
suspension points.
 #KT-27190 Fixed
2018-10-12 15:10:12 +03:00
Dmitry Petrov ab90b2b901 Fix nullability propagation in inline class type mapping
#KT-27096

See https://jetbrains.slack.com/archives/C06E082M6/p1537949572000100
2018-09-28 10:46:42 +03:00
Dmitry Petrov 0dd04c3424 Postpone companion object field visibility
Have to reconsider this issue because of interface companion objects.
2018-09-27 10:35:23 +03:00
Dmitry Petrov 792ff3c39e Generate private interface companion object as package-private synthetic 2018-09-27 10:35:23 +03:00