Commit Graph

426 Commits

Author SHA1 Message Date
Ilmir Usmanov
d269ff8ac8 Update test data 2019-02-14 18:33:20 +03:00
Ilmir Usmanov
19d2262cf1 Generate call of throwOnFailure instead of manual check
whether coroutine is resumed with exception.
 #KT-28015 Fixed
2019-02-14 18:33:17 +03:00
Alexander Udalov
ce7d8a6874 JVM IR: replace unnecessary property accessor calls with field access
Split the ConstAndJvmFieldPropertiesLowering into two: ConstLowering
which replaces const vals with their values, and
PropertiesToFieldsLowering which removes unnecessary property accessors
(such as for JvmField or private properties with default accessors) and
replaces calls to those accessors with field access
2019-02-07 23:32:32 +01:00
Mark Punzalan
e91a16556c JVM_IR: Do not add redundant field initializers.
Initializers are "set field" expressions and are considered redundant
when they are:
1. In the primary constructor; and
2. Set the field to `0`, `false`, or `null`; and
3. Have a `null` origin. I.e., not in an initializer block or
constructor body, and therefore the field could not have been set by a
prior expression.
2019-02-05 08:44:33 +01:00
Ilmir Usmanov
39de3c2ab1 Fix test data on JVM_IR BE 2019-02-01 21:45:44 +03:00
Ilmir Usmanov
20e4efaeab Fix test data 2019-02-01 17:33:49 +03:00
Alexander Udalov
db487a622a Add -Xsanitize-parentheses to workaround ASM 6.1 issue in frame computation
#KT-29475 Fixed
2019-01-31 15:47:43 +01:00
Mads Ager
52464fd103 JVM_IR: do not generate line number info for temporary loads.
Loads from compiler-introduces temporary variables to do not
correspond to loads in user code.
2019-01-29 14:25:17 +01:00
Mads Ager
bb0cd92da0 JVM_IR: Fix codegeneration for missing branches.
This used to generate an ACONST_NULL instruction leading to incorrect
stack height for code such as:

```
if (condition) else 32
```
2019-01-28 15:41:48 +01:00
Alexander Udalov
6b5a16884c Refactor inheritMultifileParts to be a JVM analysis flag
Instead of a JVMConfigurationKeys key. This will allow to use it in a
checker in 'frontend.java'
2019-01-25 15:57:13 +01:00
Mads Ager
fb6eafddf1 JVM_IR: Generate better code for null checks.
Simplify ifs when branches have condition true/false.

Simplify blocks containing only a variable declaration
and a variable get of the same variable. Simplify to
just the condition.

Do not introduce temporary variables for constants for
null checks. Constants have no side-effects and can be
reloaded freely instead of going through a local.

This simplifies code such as "42.toLong()!!" so that the
resulting code has no branches and uses no locals. The
simplifications happen as follows:

```
block
  temp = 42.toLong()
  when
    (temp == null) throw NPE
    (true) load temp

---> null test simplification

block
  temp = 42.toLong()
  when
    (false) throw NPE
    (true) load temp

---> when simplification

block
  temp = 42.toLong()
  load temp

---> block simplification

42.toLong()
```
2019-01-23 15:11:14 +01:00
Mads Ager
690b8e0ac9 JVM_IR: Optimize null checks.
Introduce lowering to remove null checks for primitive type
expressions and replace them with true/false. Side-effects
are preserved.

Generate ifnull/ifnonnull instructions for null checks instead
of materializing a null literal for an equality check.
2019-01-19 09:43:43 +01:00
Ilmir Usmanov
e8c52e0a8f Do not mark fake inliner variables as alive
This prevents them from spilling.
 #KT-29317 Fixed
2019-01-18 13:45:20 +03:00
Dmitry Petrov
c1de845d29 Generate switch instruction for 'when' with unsigned subject 2019-01-17 13:49:39 +03:00
Ilmir Usmanov
2ec1222cd1 Fix test data 2019-01-16 20:40:33 +03:00
Ilmir Usmanov
76e9b574cd Put default value to vars iff they are not boxed
#KT-24672 Fixed
2019-01-16 20:40:29 +03:00
Dmitry Petrov
08abf5f2a2 Specialize unsigned range and progression iterator calls 2019-01-16 11:00:23 +03:00
Dmitry Petrov
9973d59643 Use java.lang.Long.divideUnsigned/remainderUnsigned in Java 1.8+
#KT-24876
2019-01-14 14:17:52 +03:00
Dmitry Petrov
b878626919 Intrinsify 'in' with unsigned ranges 2019-01-10 17:17:51 +03:00
Dmitry Petrov
e6e0e9976c Tests for for-in optimization with unsigned ranges 2019-01-10 17:17:51 +03:00
Mads Ager
57489febf0 JVM IR: simplify chains of negations in if conditions.
Introduce lowering phase that turns !!exp -> exp for the boolean
'not' builtin. This makes sure that code such as

```
if (!!!!!booleanValue) {
    doStuff()
}
```

generates only one branch.
2019-01-08 12:09:23 +01:00
Mads Ager
864b90f8c0 JVM_IR: Do not materialize negated boolean for branches.
Instead, flip the branch targets. This generates java byte code
such as:

   L2
    IFNE L3
    ALOAD 0
    INVOKEVIRTUAL A.getX ()F
    GOTO L4
   L3

instead of:

   L2
    IFNE L3
    ICONST_1
    GOTO L4
   L3
    ICONST_0
   L4
    IFEQ L5
    ALOAD 0
    INVOKEVIRTUAL A.getX ()F
    GOTO L6
   L5
2019-01-03 08:21:31 +01:00
Ilmir Usmanov
1d52fb2e26 Fix test data 2018-12-28 19:51:59 +03:00
Ilmir Usmanov
8a01da6ec6 Support val initialization in non-inline function with EXACTLY_ONCE effect
by generating a box for the value.
 #KT-26126 Fixed
2018-12-28 15:09:11 +03:00
Ilmir Usmanov
a52f430d8f Put default value (null or zero) to slot for uninitialized values
This way range of the variable is correct in LVT.
 #KT-24672 Fixed
2018-12-28 15:09:07 +03:00
Ilmir Usmanov
871134cff8 Update test data
#KT-28309
2018-12-28 14:18:39 +03:00
Ilmir Usmanov
a107b5d6b6 Set type of inliner's fake variable slots to int by storing 0
Otherwise, D8 drops the whole LVT.
 #KT-28309 Fixed
2018-12-28 14:18:37 +03:00
Mads Ager
48bd99730d Suppress final failure which relies on line numbers. 2018-12-21 16:20:45 +01:00
Mads Ager
3a11322506 Enable bytecode text tests for the JVM_IR backend. 2018-12-21 16:20:45 +01:00
Alexander Udalov
f5ff3d2fa9 Remove directives that have no effect from bytecode text tests
All bytecode text tests are run with stdlib in the classpath and only
for JVM backend, therefore directives WITH_RUNTIME, TARGET_BACKEND,
IGNORE_BACKEND are not needed
2018-12-20 12:53:24 +01: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
e3c381a298 Remove API_VERSION 1.3 from tests on JvmDefault
So that these tests will now check behavior on the latest API version
2018-12-20 12:53:23 +01:00
Alexander Udalov
0871a3cc4d Use API_VERSION instead of LANGUAGE_VERSION in IEEE754 tests
See `ExpressionCodegen.genEqualsForExpressionsPreferIeee754Arithmetic`:
the behavior here actually depends on the API version, not any language
feature
2018-12-20 12:53:22 +01:00
Alexander Udalov
83528a75be Minor, fix typo in IEEE754 bytecode text tests
The runtime function in kotlin.jvm.internal.Intrinsics is called
"areEqual", not "areEquals"
2018-12-20 12:53:22 +01:00
Alexander Udalov
43413fcc44 Move lateinit assertion for companion property to companion object
Previously, for a property named `x` in the companion object of a class
named `Foo`, we generated:
- `Foo.access$getX$cp`, consisting of `GETFIELD Foo.x` and lateinit
  assertion
- `Foo.Companion.getX`, consisting of `INVOKEVIRTUAL Foo.access$getX$cp`

Now, we generate:
- `Foo.access$getX$cp`, consisting of `GETFIELD Foo.x`
- `Foo.Companion.getX`, consisting of `INVOKEVIRTUAL Foo.access$getX$cp`
  and lateinit assertion

The reason is that this way we can avoid generating another accessor and
reuse `Foo.access$getX$cp` in case `isInitialized` is called on a
lateinit property from companion.

For private properties, getX is not generated, but instead the assertion
is generated on each access to the field (which can be improved, see
KT-28331). The same happens for access to non-private properties from
inside the same context where they're declared.

 #KT-21862 In Progress
2018-12-13 14:12:33 +01:00
Ilmir Usmanov
0934db8fbd Do not transform state-machine when inlining
Sometimes, state-machine, generated in inline functions with
crossinline parameter, is transformed, since all usages should be
renamed.
However, this is wrong: in this case, we will have state-machine
inside state-machine.
This fix addresses the issue.

 #KT-25893 Fixed
2018-11-29 14:58:35 +03:00
Mikhail Zarechenskiy
9d2524a790 Fix failing test because of lack of inference annotation
LINENUMBER was incremented because of added import
2018-11-20 19:36:50 +03:00
Mikhail Zarechenskiy
d28488eaed Remove WITH_UNSIGNED directive from tests
#KT-25226 Fixed
2018-11-13 11:48:32 +03:00
Mikhael Bogdanov
c6b4bae81f Move 'bytecodeText' java 8 tests to common 2018-10-23 16:27:50 +02:00
Dmitry Petrov
5304754e88 Generate specialized 'toString' for inline classes when possible
#KT-25613
2018-10-15 12:21:14 +03:00
Dmitry Petrov
5480bf69e8 Support property delegation to inline class values (KT-27070) 2018-10-03 11:09:46 +03:00
Ilmir Usmanov
35056543a2 Fix LVT entries of 'this' and parameters in coroutine code
#KT-24510 Fixed
2018-09-17 20:03:51 +03:00
Ilya Gorbunov
1b889c976a Use new sequence builders in tests
Coroutine tests will fail when LV=1.2 because there're no such builders
in kotlin.coroutines.experimental.

#KT-26678
2018-09-16 23:30:36 +03:00
Ilmir Usmanov
e9fc65c7ae Use our own primitive boxing methods in coroutines codegen
#KT-26490 Fixed
2018-09-12 15:36:17 +03:00
Denis Zharkov
c1cc722ac4 Turn off incorrect switch-optimization for when by enums
#KT-24708 Fixed
2018-09-12 09:49:25 +03:00
Yan Zhulanow
d16b55033e Introduce new naming convention for captured receiver backing fields
'receiver$0' -> '$this_<label>'
2018-09-11 16:41:20 +03:00
Dmitry Petrov
e3fa785678 Minor: drop irrelevant test case
Hiding constructors with inline class type parameters
is tested by bytecodeListing tests
2018-09-10 17:45:05 +03:00
Roman Elizarov
e2713501ce Rename SuccessOrFailure to Result and hide Failure from ABI
* The members of Result are isSuccess, isFailure, exceptionOrNull, getOrNull
* The rest of API is implemented via inline-only extensions
* There are two internal functions to hide detailed mechanics of an internal
  Result.Failure class: createFailure and throwOnFailure
* Result.toString is explicit: either Success(v) or Failure(x)

See KT-26538
2018-09-09 11:34:31 +03:00
Dmitry Petrov
cafaa3e13c Mangle inline class members
<IMPL_SUFFIX> for method is a method signature hash,
if method value parameter types contain inline class types,
otherwise 'impl'.

Constructor methods are named as 'constructor-<IMPL_SUFFIX>'.

Synthesized 'box' and 'unbox' methods are named as
'<METHOD_NAME>-<IMPL_SUFFIX>'.

Erased implementations of overriding and non-overriding methods
are named as '<METHOD_NAME>-<IMPL_SUFFIX>'.

Fully specialized implementation of 'equals' will have a special suffix.
2018-09-07 10:25:53 +03:00