Commit Graph

572 Commits

Author SHA1 Message Date
Mikhael Bogdanov
3e219f4ebf Keep original casts during reification to avoid VerifyError
#KT-26435 Fixed

(cherry picked from commit 03c2350e79)
2019-12-17 12:48:16 +01:00
Alexander Udalov
025360edc4 JVM IR: lookup symbols by name in ProgressionHandlers in known classes only
Alternatively, we could improve the lookup utilities and their usages to
always find the exact override of a symbol from
Collection/Iterable/CharSequence/etc, but since we need to load the
original symbol anyway in cases when the loop subject's type is a type
parameter, we might as well simplify everything and always reference the
original symbol.

Also improve exception message and removed unused declarations in
IrBackendUtils.kt.
2019-12-12 14:55:47 +03:00
pyos
498b41b148 JVM_IR: do not do invokeinterface on Object methods
This works on HotSpot, but might confuse other VMs.
2019-12-11 15:09:37 +01:00
Dmitry Petrov
f6b99955f8 Update testData in bytecodeText (argument nullability assertions) 2019-12-06 11:03:07 +03:00
Alexander Udalov
e9946b21b5 JVM IR: do not hide constructor with inline class types and defaults
This corresponds to the ABI generated by the old backend. Moreover, when
compiling the module 'ir.tree' with JVM IR (could not reproduce on a
small sample), this led to a codegen crash when trying to reassign
parameter value to the default stub, which is an error expression and
can't be generated by ExpressionCodegen.
2019-12-02 10:19:55 +01:00
Kristoffer Andersen
6f8682c950 [JVM IR] Stabilize accesor names in IR Backend
- introduce a scoped counter instead of a global one for name
  generation for accessors. Naive solution not working.

- Introduced hardcoded "jd" suffix for accessors on interfaces, under
  the assumption that the only such accessors are due to JvmDefault
  and their bridges from `$DefaultImpls`. Removed all associated
  templated tests, so the old and IR backend correspond on this matter
  again.

- Respecialized writeFlags from regexps to string-equality: we are
  going for exact matches now!

- Fixed package calculation in `IrUtils.kt`.

- Accessors for static members must be due to accessing super
  classes. Actual super-qualified calls are naturally also accessing
  super classes. Hence the `$s+{hashcode(superClassName)}`
  suffix. Added test to affirm this naming scheme.

- Field getters/setters for static fields must be companion accessors,
  otherwise just labelled as accessors. They are also tagged with `s`
  suffix when accessing static fields.

- For naming of accessors to coincide with the old backend, field
  renaming to avoid JVM signature clashes must be done _after_
  generation of accessors for those fields.
2019-12-02 08:19:52 +01:00
Kristoffer Andersen
d1c2862e27 IR: Align Interface Defaults with Old Backend
Change the treatment of default implementations on interfaces in JVM
compatibility mode. Previously, the IR backend moved the actual
default implementation to the DefaultImpls class, and then bridged to
it from the interface default. The old backend did the reverse, at the
cost of an additional accessor, in order to gain better binary
compatibility properties. See #2612 for discussion.

The accessor needs to call a specific implementation, so must be
performed through an `invokespecial`. We trick the
SyntheticAccessorLowering into doing this for us, by marking the
bridging call as a super call. We do this in want of an explicit
`invokespecial` Ir Node.

InterfaceDefaultCallsPhase previously assumed the old behaviour of the
IR backend (that calls to default implementations, e.g. `foo$default`
should target `DefaultImpls.foo$default`). But now the bridge to
foo$default resides on `DefaultImpls` already, causing that pass to
create a recursive loop. We cut that loop with a simple check.
2019-12-02 08:19:52 +01:00
pyos
e4b1599457 JVM_IR: do not erase constant non-static field initializers...
...unless in 1.4 mode.
2019-11-29 16:49:52 +01:00
pyos
fc6b03b08f JVM_IR: move const initialization handling to lowering
Had to edit some bytecodeText tests to account for the fact that JVM_IR
no longer generates explicit initializations for ConstantValue fields,
but NoConstantValueAttributeForNonConstVals is not the default yet.
2019-11-29 16:49:52 +01:00
Mads Ager
e2a1cb1077 JVM_IR: Generate fake inlining local variables for debugging. 2019-11-29 13:38:34 +01:00
Mikhael Bogdanov
742c3a228a JVM_IR. Proper lower toArray functions 2019-11-28 08:31:15 +01:00
Mark Punzalan
1a2e09e6a5 ForLoopsLowering: Handle Iterable.withIndex() where the type is a
bounded type parameter.

TODO: Handle Sequences by extending DefaultIterableHandler.
2019-11-27 10:59:34 +01:00
Mark Punzalan
7adffe0007 Handle withIndex() on Iterables (including progressions) and Sequences
in ForLoopsLowering.
2019-11-20 13:02:21 +01:00
Mark Punzalan
a54d9482dd Handle withIndex() on arrays and CharSequences in ForLoopsLowering. 2019-11-20 13:02:21 +01:00
Mark Punzalan
7f803e60b6 Fix typo in forInArrayWithIndex testdata filenames. 2019-11-20 13:02:21 +01:00
Mikhael Bogdanov
a214d61567 IR. Change visibility to lowered default function/constructors to public 2019-11-20 12:57:38 +01:00
Mikhael Bogdanov
ac31e0e8c7 Support default lambda inlining in IR 2019-11-20 12:57:36 +01:00
Mikhael Bogdanov
8adac2d1ea Don't add unused label if variables are absent 2019-11-20 12:57:36 +01:00
Mikhael Bogdanov
3196893166 Don't write synthetic arguments to LVT 2019-11-20 12:57:33 +01:00
Mikhael Bogdanov
f264942bf9 Don't coerce intrisic value, it's already coerced 2019-11-20 12:57:33 +01:00
Mikhael Bogdanov
e409387078 Don't generate jump for last when condition 2019-11-20 12:57:32 +01:00
Alexander Udalov
6f5aa58338 JVM IR: support -Xmultifile-parts-inherit mode 2019-11-18 18:58:40 +01:00
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