Commit Graph

648 Commits

Author SHA1 Message Date
Mikhael Bogdanov
0c0bd67a6b Add new tests 2020-04-09 07:37:30 +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
pyos
5ed845d0b4 JVM_IR: reuse same bodies for suspend funs and $$forInline versions 2020-04-03 19:51:45 +02:00
Ilya Gorbunov
1c93911279 Make Double and Float known values constant
#KT-13887
2020-04-01 08:06:57 +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
Mads Ager
5570a5fe74 [JVM_IR] Use iinc for incrementing Int variables.
Fix line number generation for assignments where the right-hand
side of the assignment is not on the same line.

Fix line number generation for intrinsics functions where the
function is not on the same line as the last argument.

Be careful to not break stepping behavior with the iinc
optimizations.
2020-03-27 18:17:53 +03:00
Steven Schäfer
58685be4e2 IR: Don't use IrStringConcatenation for ordinary toString calls
We can only use IrStrinConcatentation to represent calls to Any?.toString
and toString calls on primitive types. Otherwise, x.toString() and "$x"
are observably different when x is a non-null type with null value
(e.g., an @NotNull value coming from Java).
2020-03-27 17:31:48 +03:00
Mark Punzalan
4234fa79c0 [JVM IR] Use append(Char) for 1-length string literals in string
templates and plus concatenations.

This is slightly more efficient and mirrors the behavior of the non-IR
backend for templates (but not for plus concatenations).

#KT-36638 Fixed
2020-03-26 12:39:39 +03:00
Dmitry Petrov
9a95941ef3 JVM_IR: Rewrite '?.' and '?:' chains
This shortens code and avoids unnecessary boxing in some cases.
2020-03-26 12:19:25 +03:00
Mads Ager
baf1f56859 [JVM_IR] Rebase test of string concatenation codegen.
The JVM IR backend code seems saner to me. The string concatenation
lowering for JVM IR calls the stringPlus intrinsic if there are
only two arguments. That leads to a lot less code:

```
load string
load argument
box argument
call Intrinsics.stringPlus
```

instead of

```
allocate StringBuilder
call StringBuilder.<init>
load string
call StringBuilder.append
load argument
call StringBuilder.append
call StringBuilder.toString
```

This will lead to more boxing, but a lot smaller code. We still
use StringBuilders in JVM IR if there are more than two strings
being concatenated.
2020-03-23 16:42:53 +03:00
pyos
186302d84e JVM_IR: restore InnerClasses for objects in lambdas 2020-03-19 15:23:44 +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
Dmitry Petrov
ade18d144a KT-36810 Implement javaPrimitiveType intrinsic in JVM_IR 2020-03-17 22:56:45 +03:00
Dmitry Petrov
2851fab281 KT-36809 Implement javaObjectType intrinsic in JVM_IR 2020-03-17 22:56:45 +03:00
Steven Schäfer
6a1e35389c JVM IR: Mangle interface implementation methods in inline classes 2020-03-16 18:48:16 +01:00
Georgy Bronnikov
92268c8144 JVM_IR: do not generate excessive stubs for immutable collections 2020-03-12 23:14:17 +03:00
Georgy Bronnikov
fded6fb494 JVM_IR: fix suspendCoroutineUninterceptedOrReturn 2020-03-12 11:28:42 +03:00
Dmitry Petrov
a9ab3ae192 KT-36047 Support when-with-subject in optimized 'when' generators 2020-03-11 18:09:17 +03:00
Mark Punzalan
368b0d9b0b [JVM IR] Use reference equality when comparing enums. 2020-03-06 23:01:32 +01:00
pyos
037b442e86 JVM_IR: do not explicitly initialize Refs to default values 2020-03-06 17:58:36 +03:00
pyos
13b04e63be JVM_IR: wrap inline class objects in unboxed refs 2020-03-06 17:58:36 +03:00
Georgy Bronnikov
8b559b20e2 Add a test for getOrDefault() bridge 2020-03-04 16:02:54 +03:00
Dmitry Petrov
f678db2f89 KT-36813 Generate optimizable null checks in JVM_IR 2020-03-03 22:38:21 +03:00
pyos
ed83e3ccef Optimize more redundant kotlin/jvm/internal/Refs
The number of initializations of the `value` field before the live range
begins does not really matter so long as we insert a write of a default
value to the local if there were none.
2020-03-02 20:20:55 +03:00
pyos
7e6d080123 JVM_IR: default-initialize variables visible in the LVT
See KT-36812. Aside from the problem stated there, D8 will throw out the
entire LVT if it sees a variable that has not been written to (and will
generate incorrect SSA if the slot is reused with a different type).

Note: this only fixes a FIR test because it's missing an `else -> throw`
branch, and default initialization satisfies the verifier and masks the
incorrect control flow.
2020-03-02 20:17:10 +03:00
Ilmir Usmanov
536e0e23a0 JVM_IR: Lazyly generate continuation classes of suspend functions
Otherwise, they will be generated, but unused, if the function is tail-call.
 #KT-36795 Fixed
2020-03-02 14:03:31 +01:00
Steven Schäfer
465e9f2d68 JVM IR: Always produce stubs for interface methods in inline classes
This matches the behavior of the JVM backend, with the exception of
@JvmDefault methods, which are currently broken on the JVM backend.
2020-02-28 14:48:17 +01:00
Ilya Gorbunov
b53cb5cb4c Cover with a test current Double/Float companion values access 2020-02-28 01:26:56 +03:00
Kristoffer Andersen
c1d350f8f3 [JVM IR] Added null-checks of handler for non-super $default calls 2020-02-26 16:28:27 +01:00
Steven Schäfer
2b6a0d6c58 JVM IR: Don't create $annotations stubs for fake overridden properties 2020-02-25 11:31:01 +01:00
Dmitry Petrov
b047d78580 Minor: update testData for IR bytecode text and unmute test 2020-02-25 11:17:08 +03:00
Ilmir Usmanov
52e7cd5725 JVM_IR: Remove $$forInline suffix for fake inliner variables
Otherwise, IDE will not be able to navigate to inline functions.
 #KT-36797 Fixed
2020-02-21 12:08:25 +01:00
Ilmir Usmanov
325ad14ac9 JVM_IR: Treat suspend main wrapper as always tail-call function
In other words, never generate suspend call markers inside it.
2020-02-21 12:00:54 +01:00
Dmitry Petrov
bc7c8e4819 Update bytecode text tests for JVM_IR 2020-02-20 14:59:29 +03:00
Dmitry Petrov
81b30b7399 Update bytecode text tests for JVM_IR 2020-02-20 14:20:21 +03:00
Steven Schäfer
0ed719f792 JVM IR: Use package visibility for $assertionsDisabled field 2020-02-20 11:07:46 +01:00
Steven Schäfer
ba90e87756 JVM, JVM IR: Fix assertion status for regenerated anonymous objects
We always set the $assertionsDisabled field based on the top-level
enclosing class. This means that for anonymous objects we have to
rewrite the call to Class.desiredAssertionStatus.
2020-02-19 11:23:24 +01:00
Dmitry Petrov
0b9b1b6945 Update bytecode text tests for JVM_IR 2020-02-18 22:51:29 +03:00
Ilmir Usmanov
c748b6f3ee JVM_IR. Minor. Update bytecode text test to JVM_IR or create issues when this
is not feasible.
2020-02-18 11:43:37 +01:00
Dmitry Petrov
94d20d9176 Update bytecode text tests in JVM_IR 2020-02-17 23:52:48 +03:00
Mark Punzalan
64141b8b38 [JVM IR] Fix issue where fields are not being set to their default
values within initializer blocks.

The issue occurs in code like this:
```
class C {
  var b = true
  init {
    b = false   // Missing PUTFIELD for this statement
  }
}
```

Added a new statement origin for field initialization (at declaration)
instead of relying on `origin == null` in ExpressionCodegen to determine
whether to generate the initializations.

This was unintentionally broken in
d68a1898d0.
2020-02-17 23:04:11 +03:00
Jinseong Jeon
e3184e407d KT-20844 Re-enable stack spilling during inline.
`dx` has entered the final stage of sunset:
https://android-developers.googleblog.com/2020/02/the-path-to-dx-deprecation.html
2020-02-17 15:44:48 +01:00
Steven Schäfer
5760c0be9c JVM IR: Avoid redundant coercions in ExpressionCodegen 2020-02-15 22:32:23 +03:00
Dmitry Petrov
59cdf3c52e Update bytecode text tests in JVM_IR 2020-02-14 14:07:03 +03:00
Yan Zhulanow
cc2fe6b0c6 Debugger, BE: Generate original line number after inlining if call is used in an if condition
If a part of an 'if' condition is an inline function call, we need to insert the original condition line after it. Otherwise, the debugger will think it is inside the inline function implementation. Obviously, this breaks stepping – instead of the 'if' body, we go on stepping through the inline function.

This commit fixes 'KotlinSteppingTestGenerated.StepOver#testSoInlineLibFun' test.
2020-02-14 17:35:17 +09:00
Yan Zhulanow
8b17718086 Debugger, BE: Make the NOP instruction optimizer save the first NOP, not the last
This commit fixes the following tests:
 - KotlinSteppingTestGenerated.StepOver#testSoInlineLibFun
 - KotlinSteppingTestGenerated.StepOver#testSoInlineIterableFun
 - KotlinSteppingTestGenerated.StepOver#testSoInlineFunOnOneLineFor
2020-02-14 17:35:17 +09:00
Kristoffer Andersen
f782ea075b [JVM IR] ProperVisibilityForCompanionObjectInstanceField
- Uncomment tests
- Add proper visibility to companion field
  + Make exception for interfaces -> they need to respect language versions 1.8
    before they can put private members there.
- Adjust synthetic accessor lowering to look for enclosing classes with access
  via companion object.
2020-02-13 21:50:48 +03:00
Mark Punzalan
ba606147c9 [JVM IR] Maintain KT-36625 bug compatibility between non-IR and IR
backends by removing IMPLICIT_NOTNULL casts from IrStringConcatenation
arguments.

Also fixed an issue where IrStringConcatenation can be lowered into
a null String instead of a literal "null" String if the lone argument
was a platform type String or String with enhanced nullability and the
value was null (e.g., "${FromJava.nullPlatformString()}").
2020-02-12 22:57:15 +03:00
Steven Schäfer
6d23e50142 JVM IR: Create non-synthetic multifile parts for -Xmultifile-parts-inherit 2020-02-11 17:01:22 +01:00