Commit Graph

550 Commits

Author SHA1 Message Date
Kristoffer Andersen
4973baae4e [JVM IR] Fix JvmOverloads+Parameterless Main
Resolves the interaction of @JvmOverloads annotations and
parameterless main methods.

In the following code, both mechanisms generate methods that
ultimately produce the signature `public static void main(String[] args)`
of which there can be only one (true in general of any signature).

```
fun main() { }

@JvmOverloads
fun main(Array<String> args, x: Int = 42) { }
```

This PR simply shuffles the lowerings around, letting parameterless
main methods detect the presence of the default overload produced by
the annotation.

Additionally, this PR improves the testing of parameterless main
methods by actual bytecode patterns, and not simple check for
successful compilation (as @sfs and I discovered, there are issues in
flagging an error on duplicate signatures on the IR backend).
2019-11-13 13:03:14 +01:00
pyos
82fb5c4d19 JVM_IR: move lambda captures to end of signature when inlining
For example, a lambda `{ param -> captured }` of type `E.(T) -> U` will
be transformed by LocalDeclarationsLowering into a private static method

    fun f$lambda-0($this: E, $captured: U, param: T) = $captured

The reason for such an ordering is that a lambda looks the same as a
local function, and local function can have default arguments, and those
arguments can reference captured variables; thus, captured variables
must come before actual declared arguments.

However, this is not the order that the inliner wants. Moreover, since
it was written to handle lambdas represented as `invoke` methods of
anonymous objects, it does not expect the actual callable method to have
any parameters corresponding to captured variables at all. This results
in it attempting to generate a temporary node with descriptor

    (LE;LU;LT;LU;)LU;

while still using locals 1 and 2 as `param` and `$captured` respectively.
In the example above, this is not critical, as they both have reference
type and the lambda will eventually be pasted into a different node
anyway; however, if it happens that one of them is a primitive, or both
are primitives of different types, the bytecode will use incorrect
instructions, causing verification errors. The correct descriptor is

    (LE;LT;LU;)LU;
2019-11-11 13:46:42 +01:00
Kristoffer Andersen
8561f08f06 [JVM_IR] Reintroduce non-IEEE comparisons
- Ieee754Equality and PrimitiveComparisons intrinsics
  respects absence of -Xproper-ieee754-comparisons, unmuted tests to
  show.
2019-11-08 12:58:31 +01:00
Mark Punzalan
f444702cf3 JVM: Always invoke get()/charAt() in optimized for-loop over
CharSequence.withIndex(), even if element variable is unused in
destructuring declaration.

#KT-34779 Fixed
2019-11-08 10:55:09 +03:00
Alexander Udalov
1978db9d0e Move codegen tests on old language versions under oldLanguageVersions/
This directory is skipped in JVM IR test generator, so they won't show
up as failed anymore.

Note that only failing tests are moved to oldLanguageVersions/. Tests
which already pass are still being run. It may be useful not to break
them in case we _do_ need to support some pre-1.3 language feature
switches in JVM IR.
2019-11-07 19:05:24 +01:00
Alexander Udalov
c3729c8189 Reorganize codegen tests for old language versions
Put all files under a single "oldLanguageVersions" directory under test
data of each test
2019-11-07 18:49:27 +01:00
Alexander Udalov
66e19b13ce IR: create shared variables for val-variables when needed
This is possible when a lambda's contract guarantees initialization of a
variable.
2019-11-07 15:20:34 +01:00
Mark Punzalan
21178a4f1a Fix issue getting the size property from Collection bounded type
parameters, when lowering for-loops over Collection.indices.
2019-11-07 13:43:24 +01:00
pyos
4fc1bd9ec5 Support inlining functions with KT-28064 style objects
Namely, anonymous objects defined in lambdas that have all captured
variables as loose fields instead of a single reference to the parent.

The question is, when a lambda inside an inline function defines an
anonymous object, and that object is not regenerated during codegen for
the inline function itself, but then has to be regenerated at call site
anyway, do we use an outer `this` or loose capture fields? For example,
before KT-28064:

    inline fun f1(g: () -> Unit) = object { g() }
    // -> f1$1 { $g: () -> Unit }
    inline fun f2(g: () -> Unit) = f1 { object { g() } }
    // -> f2$$inlined$f1$1 { $g: () -> Unit }
    //    f2$$inlined$f1$1$lambda$1 { this$0: f2$$inlined$f1$1 }
    inline fun f3(g: () -> Unit) = f2 { object { g() } }
    // -> f3$$inlined$f2$1 { $g: () -> Unit }
    //    f3$$inlined$f2$1$1 { this$0: f3$$inlined$f2$1 }
    //    f3$$inlined$f2$1$1$lambda$1 { this$0: f3$$inlined$f2$1$1 }

After KT-28064:

    inline fun f2(g: () -> Unit) = f1 { object { g() } }
    // -> f2$$inlined$f1$1 { $g: () -> Unit }
    //    f2$1$1 { $g: () -> Unit }
    inline fun f3(g: () -> Unit) = f2 { object { g() } }
    // -> f3$$inlined$f2$1 { $g: () -> Unit }
    //    f3$$inlined$f2$2 { ??? }
    //    f3$1$1 { $g: () -> Unit }

Should `???` be `this$0: f3$$inlined$f2$1` or `$g: () -> Unit`? This
commit chooses the latter for KT-28064 bytecode and keeps `this$0` when
inlining the old bytecode.
2019-11-06 13:11:44 +01:00
Steven Schäfer
b1b70e503c JVM IR: Improve codegen for try/catch statements 2019-10-31 11:13:44 +03:00
Mark Punzalan
de333c18fc JVM_IR: Enable loopVarInterval and forInReversedCollectionIndices
bytecode text tests.
2019-10-29 07:43:37 +01:00
Mark Punzalan
9bb9ab67a7 Add bytecode text tests for ForLoopsLowering. 2019-10-28 15:26:38 +01:00
Mark Punzalan
277cb39e3b Add new tests for step progressions and fix existing tests. 2019-10-28 15:26:38 +01:00
Kristoffer Andersen
8af3b3e51e [Backend] Reorganize version 1.0 codegen tests
- Extract all backend codegen tests that specifically target behaviour
  in to-be-deprecated functionality from language versions < 1.3"
- Remove those tests from the JVM IR test suite.
2019-10-24 16:51:19 +02:00
pyos
55acc296a2 JVM_IR: never create temporaries in $default stubs
Given the strict pattern-matching in the inliner, this is the only way
to make it not crash when attempting to inline these stubs. Note that
the IR backend does not currently use the inliner's default method stub
handling; the crash only occurs when a module compiled with the non-IR
JVM backend is attempting to call an inline function with default
arguments defined in a module that was compiled with the IR backend.
2019-10-23 11:11:16 +02:00
pyos
847e287bd6 JVM_IR: add $assertionsDisabled when an inlined function uses it
NOTE: jvmCrossinlineLambdaDeclarationSite.kt is muted because the
inliner does not remap references to an anonymous object's parent
class after regenerating it. Unlike the JVM backend, JVM_IR uses the
top level named class' assertion status for all inner classes. (The
test used to pass because the lambda in `inline fun call` read the
`$assertionsDisabled` field of `CrossinlineLambdaContainer`, which
was not reloaded after changing the assertion status of package `test`.)
2019-10-21 21:05:18 +03:00
Kristoffer Andersen
28b6913a25 JVM IR: Support parameterless main methods
This commit:

- introduces tests explicating what is and isn't considered a
  proper main method on the JVM backends.
- implements support for parameterless main methods on the JVM IR
  backend
- See KT-34338 for more tests.
2019-10-21 15:08:34 +02:00
Steven Schäfer
c905209504 JVM IR: Lower IrStringConcatenation 2019-10-18 17:24:53 +02:00
Steven Schäfer
c2de89cb8c Minor: Make String.valueOf bytecode tests more precise 2019-10-18 17:24:12 +02:00
Steven Schäfer
f2e0c1a930 JVM IR: Minor fix for nullable SAM wrappers 2019-10-18 17:22:58 +02:00
Steven Schäfer
21af7dfbe1 Add tests for constructors taking inline class arguments 2019-10-18 17:20:22 +02:00
pyos
d1f25d1c26 JVM_IR: discard results of nonexhaustive whens' branches 2019-10-17 15:41:42 +02:00
Georgy Bronnikov
c70b2e3e4b JVM_IR: specify correct type for defaultConstructorMarker arguments 2019-10-10 14:07:43 +03:00
pyos
06c00f4d9e Unmute some JVM_IR inlining tests 2019-10-08 17:19:41 +02:00
pyos
cd47c11efd Generate unique parameter names in LocalDeclarationsLowering 2019-10-07 15:14:48 +02:00
Steven Schäfer
3659b517bb Minor: Fix some test cases 2019-10-07 12:54:11 +02:00
Steven Schäfer
0b76f60b63 JVM IR: Handle NonInlinedConst 2019-10-05 10:52:59 +02:00
Dmitry Petrov
a633a33627 KT-14513 Don't generate delegated property metadata when unused
If the delegated property operators involved are inline, and delegated
property metadata parameter is not used (which is often the case, e.g.,
'lazy'), we can skip those properties in metadata generation.

NOT implemented: special case when only 'kProperty.name' is used by the
corresponding delegated property operators.

Also a sneak fix for KT-34060.
2019-10-02 17:14:48 +04:00
Mads Ager
507857d452 [IR] Support Collection<*>.indices in for loop lowering.
Unmute a couple of tests that are working as intended.
2019-09-18 19:00:17 +02:00
Steven Schäfer
ce3ef4e4d0 Add more tests for inline class equality with nullable arguments 2019-09-18 18:52:58 +02:00
Steven Schäfer
49efa5fbc4 Split up Result API boxing tests 2019-09-18 18:52:58 +02:00
Steven Schäfer
b85b2d9af8 Add more tests for inline class equality 2019-09-18 18:52:58 +02:00
Steven Schäfer
cdc5e1347b JVM: Avoid boxing in inline class equality 2019-09-18 18:52:58 +02:00
Steven Schäfer
f53b28e8a3 JVM: Generate equals-impl0 method for inline classes 2019-09-18 18:52:58 +02:00
Steven Schäfer
475079611d JVM IR: Avoid parameter null-checks in inline class impl methods 2019-09-18 18:52:58 +02:00
Steven Schäfer
cdd3f82396 JVM IR: Use correct scope owner in JvmInlineClassLowering 2019-09-18 18:52:58 +02:00
Ilmir Usmanov
0e3f0c98e5 JVM_IR: Support inline suspend lambdas 2019-09-17 19:19:27 +03:00
Dmitry Petrov
0531bd4fe6 KT-29229 Intrinsify 'in' operator for unsigned integer ranges
Support mixed type case, e.g., '[UByte] in [UIntRange]'.
2019-09-17 15:50:47 +03:00
Alexander Udalov
45929f57b6 Minor, add test on name mangling of private multi-file part members 2019-09-16 14:44:16 +02:00
Alexander Udalov
9d257a1ed8 JVM IR: generate call to checkNotNull in IrCheckNotNull since 1.4
#KT-22275
2019-09-16 12:33:01 +02:00
Mads Ager
90a37617a4 [JVM_IR, IR] Remove more needless temporary variables.
Avoid using a separate origin for temporary variables introduced
for for loops. That doesn't add anything and gives one more case
for optimizations to deal with.

Extend the JVM specific optimizations to remove temporary
variables to deal with more cases encountered in for loops
lowering.
2019-09-11 10:07:45 +02:00
Kristoffer Andersen
e7d0909979 JVM_IR: Fix null-constant comparison with primitive types. 2019-09-09 10:23:11 +02:00
Mads Ager
3f28b71509 [IR] Fix issue getting the length property from CharSequence bounded type parameter
Use the class of the subtype of CharSequence when available. When
it is not (for type parameters bounded by CharSequence) call the
CharSequence getter and 'get' method. Using the most specific type
posible fixes the forInStringSpecialized test that expects the
use of INVOKEVIRTUAL and not INVOKEINTERFACE.

Add tests for the type parameter use.
2019-09-03 20:18:03 +02:00
Mads Ager
85b1e0165b [IR] For loop lowering for CharacterSequence.indices. 2019-09-03 13:18:21 +02:00
Mads Ager
8ed1317839 [IR] For loop lowering for iteration over CharacterSequences.
Change-Id: I7aeadfffc80f791ec19a3607e219c1dc4de028db
2019-08-30 09:35:59 +02:00
Steven Schäfer
6bf16a96e1 Add more tests for type operators on the jvm 2019-08-27 10:44:23 +02:00
Dmitry Petrov
7d49b72b79 JVM_IR: Support 'CHECK_NOT_NULL' intrinsic
TODO: migrate to changes related to KT-22275
2019-08-14 11:16:10 +03:00
Steven Schäfer
ac667403ef (Un)mute and add tests for vararg codegen 2019-08-13 14:24:55 +02:00
Alexander Udalov
2baddb029c Use Intrinsics.checkNotNullParameter to throw NPE in parameter null checks
Similarly to previous commits, this method was unused, so we're changing
its semantics in API version >= 1.4.

 #KT-22275 In Progress
2019-08-12 16:09:23 +02:00
Alexander Udalov
480313210a Use Intrinsics.checkNotNullExpressionValue to throw NPE in Java null checks
Similarly to previous commit, this method was unused since its
introduction before 1.0, so we're changing its semantics to throw NPE
and starting to use it with API version >= 1.4.

 #KT-22275 In Progress
2019-08-12 16:09:23 +02:00