Commit Graph

5233 Commits

Author SHA1 Message Date
Dmitry Petrov ac5411c32e Command-line option disabling KotlinNothingValueException generation 2020-04-16 19:38:30 +03:00
Kristoffer Andersen 7ec4c9990a [JVM] Improve debug step behavior around lambdas.
- Add tests to clarify problematic behavior
- Avoid line numbers on return instructions of lambdas without explicit returns
2020-04-15 14:33:49 +02:00
Mikhail Zarechenskiy cf90fe81ac Move Sam(TypeAlias)ConstructorDescriptor to core 2020-04-15 02:06:32 +03:00
Dmitry Petrov f42d9eefa1 KT-30330 Support KotlinNothingValueException in JVM 2020-04-10 08:47:03 +03:00
Mikhail Bogdanov 7d54027f41 Minor. Rename new proto property, JvmFlags.getClassFlags method
Compiler requires this new flag to know where actual interface method body is generated to emit proper method calls
2020-04-09 07:37:33 +02:00
Mikhail Bogdanov 7876d821a9 Minor. Rename jvm default utility methods 2020-04-09 07:37:33 +02:00
Mikhael Bogdanov e45a892499 Support mixed compilation of new default with non-default or @JvmDefault 2020-04-09 07:37:32 +02:00
Mikhail Bogdanov a3f930d2e4 Support bridges in interfaces for default methods 2020-04-09 07:37:32 +02:00
Mikhail Bogdanov 93b915c77a Support accessors for private methods for default methods 2020-04-09 07:37:31 +02:00
Mikhail Bogdanov 7bcbae9826 Fix requirements 2020-04-09 07:37:31 +02:00
Mikhael Bogdanov ff8eac29a0 New flag in proto 2020-04-09 07:37:31 +02:00
Mikhael Bogdanov 0570c05683 Rename hasJvmDefaultAnnotation method to isCompiledToJvmDefaultIfNoAbstract 2020-04-09 07:37:30 +02:00
Mikhael Bogdanov bfd709290b Explicitly pass jvmDefaultMode 2020-04-09 07:37:30 +02:00
Alexander Udalov 587cce4a23 Avoid asserts in CodegenAnnotatingVisitor.isAdaptedCallableReference
In light classes mode, binding context may not have all the information
and this can fail, as for example was happening in the test
`diagnostics/tests/regressions/ea76264.kt`.
2020-04-08 19:21:30 +02:00
Alexander Udalov 9f758b4f25 Support toString for AdaptedFunctionReference subclasses
Also make it serializable like other lambdas, suspend lambdas and normal
callable references.
2020-04-08 19:16:38 +02:00
Alexander Udalov 66995fe1a5 Fix condition in calculation of adapted function reference flags
This only affects flags which are passed to
kotlin.jvm.internal.AdaptedFunctionReference. The only way it could lead
to changes in behavior is if it affected equals/hashCode of adapted
references. But it doesn't seem possible to construct a test where two
_different_ adaptations exist for a function reference to a
vararg-taking function, both of which use some sort of 1.4 function
reference conversion. Hence, no new tests are added.
2020-04-08 19:15:39 +02:00
Alexander Udalov 0681231e99 Introduce AdaptedFunctionReference runtime class
It's used as a superclass for anonymous classes for adapted function
references. Its main feature is that it _doesn't_ inherit from KFunction
(as opposed to FunctionReference), as per the decision to postpone
reflection support for adapted function references in KT-36024.

 #KT-36024 Fixed
2020-04-08 19:15:38 +02:00
Dmitry Petrov d1c5a42124 KT-36024 Generate adapted callable references as lambdas
Make sure both JVM and JVM_IR use the same information to determine
whether a callable reference requires argument adaptation.
2020-04-08 19:02:33 +02:00
Dmitry Petrov 9615b20e5d Box inline class return value in lambdas (including suspend lambdas) 2020-04-08 19:56:26 +03:00
pyos 0037d5a7c8 JVM: erase conditional suspension markers from inline-only functions
Otherwise, the generated bytecode is unnecessarily suboptimal in some
(arguably weird) cases.

In the JVM backend, this was an accidental regression in #3260, as I had
not noticed that effectively inline-only functions were handled by a
separate branch in FunctionCodegen. In JVM_IR, I'm pretty sure the
redundant markers have always been there as `isSuspensionPoint` in
ExpressionCodegen never checked for effectively-inline-only-ness.
2020-04-08 12:31:23 +02:00
Dmitry Petrov 0c21d63290 Box inline class return value in covariant override of suspend fun 2020-04-08 10:50:58 +03:00
Mikhail Zarechenskiy 86fd4da567 [UAST] Fix mapping types containing type aliases
#KT-27935 Fixed
2020-04-08 01:25:14 +03:00
Mads Ager 03fb49bb38 [JVM_IR] Improve debugging behavior of inline functions
Specifically, this commit improves the stepping behavior of the IR
backend around functions with defaults.

  - Improved line numbers in the default handler itself for better
    stepping when inlined.

  - Improved source information on default arguments

  - Improved test coverage of stepping behavior in old and IR backends.

Improves the stepping behaviour around inline methods with default
arguments. In particular, we now accurately step through the
evaluation of default arguments, but do _not_ spuriously show the exit
from the $default handler.
2020-04-07 16:52:45 +02:00
pyos 829343cf6f JVM: surround captured lambdas with conditional suspension markers 2020-04-07 15:42:41 +02:00
pyos c650c9570f JVM: use conditional suspension point markers 2020-04-07 15:42:41 +02:00
Dmitry Petrov dae8872aba KT-37779 Treat named value arguments in vararg as arguments with '*' 2020-04-07 15:40:43 +03:00
Dmitry Petrov d5ace43614 KT-37986 Force boxing of inline class returned from function reference
KT-37998 Provide KotlinType for safe call
2020-04-04 01:32:45 +03:00
pyos 8945d5a0df JVM_IR: remove $$forInline checks from ExpressionCodegen 2020-04-03 19:51:45 +02:00
Alexander Udalov 774fc32f3e JVM IR: support optimized callable reference superclasses
See KT-27362.

 #KT-37334 Fixed
2020-04-03 15:37:56 +02:00
Dmitry Petrov 24b8495e00 KT-30419 Box inline classes in return types of covariant overrides
Use boxed version of an inline class in return type position for
covariant and generic-specialized overrides.

Also fixes KT-35234 and KT-31585.
2020-04-01 22:59:14 +03:00
Alexander Udalov 3269a7e693 Change behavior of equals/hashCode on adapted function references
Function references are now equal if they refer to the same function,
and if the parameter/return type adaptation, which happens when a
reference is used where some function type is expected, is exactly the
same. This includes the number of expected positional parameters (which
can be affected by defaults/varargs), whether the coercion of vararg
parameter to Array type happened, and whether the coercion of return
type to Unit happened.

 #KT-37543 Fixed
2020-04-01 14:18:49 +02:00
pyos 9d7db101e6 JVM: refactor SMAP stuff some more
Just trying to keep the entropy down.
2020-03-31 16:06:57 +02:00
pyos e98bdc6f8e JVM: preserve call site markers when inlining lambdas
and default functions into their own stubs.

Fixes #KT-35006
2020-03-31 16:06:57 +02:00
pyos 9d21800d8f JVM: fix SMAP range extension logic
If `mapLineNumber` was called in non-monotonic order, e.g. N then N+2
then N+1, the first two calls created a range that spans [N; N+2] but
the third call did not reuse it.
2020-03-31 16:06:57 +02:00
Dmitry Petrov cec64a2ec7 KT-37861 'this' is uninitialized in constructor default parameters 2020-03-30 17:23:15 +03:00
Dmitry Petrov 042424d599 KT-27524 Don't box (some) inline classes in suspend fun return
If an inline class is mapped to a reference type (or an array), it's Ok
to treat JVM view on a suspend function as returning a value of
corresponding inline class (although in reality it returns 'Any?'
because of COROUTINE_SUSPENDED).
2020-03-27 18:29:36 +03:00
pyos a3fe9034e2 JVM: refactor some SMAP-related classes
In particular, remove redundant copying from SMAPAndMethodNode (which
also fails for empty methods).
2020-03-25 14:03:32 +01:00
pyos 4558d48481 JVM: add a language feature to omit *E between SMAP strata
Fixes #KT-37704
2020-03-25 10:33:59 +01:00
Dmitry Petrov d3be0462b6 Fix callable reference to inline class constructor generation 2020-03-24 22:25:59 +03:00
simon.ogorodnik 0afbf25943 [FIR2IR] Implement JvmBackendClassResolver for boxing optimizer 2020-03-24 18:58:18 +03:00
Dmitry Petrov afacb4b4b2 KT-37604 Use proper type when generating constructor call 2020-03-24 11:31:47 +03:00
Mikhail Zarechenskiy 191fb02bf6 [NI] Consider intersection type with number type as Nothing
Currently, only for "in": In<in Int & A> == In<in Nothing> == In<*>

 #KT-37302 Fixed
2020-03-23 16:39:21 +03:00
pyos d06c87207c Dump class structure in a test that has an object in a lambda 2020-03-19 15:11:20 +01:00
pyos e0a5ab7146 Do not regenerate objects if all captured lambdas are noinline 2020-03-19 15:11:20 +01:00
pyos 54e725668f Ignore reified type parameters when regenerating objects from lambdas
All reified type parameters referenced by objects in non-default lambdas
are from outside the inline call, thus they cannot be substituted yet.
This means if the only reason for object regeneration is reification,
then regeneration isn't actually necessary.

E.g. in this code:

    inline fun <reified T> f(x: () -> Unit) = x()
    inline fun <reified V> g() = f<V> { { println(V::class.simpleName) }() }

we first inline the lambda into f(), then inline f()-with-lambda into g().
Because the object inside the lambda captures nothing from outside g(),
the original class can be used both times.

This brings the JVM_IR backend into complete compliance with KT-28064.
2020-03-19 15:11:20 +01:00
Jinseong Jeon 2352b1fec5 JVM_IR: use fresh source map when generating lambda body for inline. 2020-03-19 08:28:38 +01:00
pyos 72b80ef158 Detect inline cycles faster
E.g. in the following code

    fun x() {}
    inline fun f() { x(); g() }
    inline fun g() { x(); f() }

the old implementation of inline cycle detection bailed out after
generating 3 calls of x() in each function, while the new one stops
after 2. In other words, code generation for a single function is no
longer reentered.
2020-03-19 08:13:19 +01:00
Mikhail Glukhikh 26f919df03 Fix some nullable usages of not-null type parameters (KT-36770) 2020-03-18 10:24:26 +03:00
Jinseong Jeon 5dc1651a44 JVM: missed line number for return expression. 2020-03-17 13:39:35 +01:00
Dmitry Petrov 6809f4439c Fix range-based 'for' loop with 'continue' in range bounds
1. Search for increment function in range element type, not in inferred
induction variable type
(which can be inappropriate, e.g., 'Nothing' in case of 'continue').

2. Handle nested loops with shared exit labels
(generated by JVM_IR for KT-37370 case).

KT-37370 KT-37373
2020-03-17 12:18:48 +03:00