Commit Graph

95 Commits

Author SHA1 Message Date
pyos 7ce5556de3 JVM_IR: try to fix SyntheticAccessorLowering.isAccessible again
The condition on the relationship between the current class and the type
of the receiver for protected members was the opposite of what the JVMS
says, and yet somehow mostly worked?

 #KT-48331 Fixed
 #KT-20542 Fixed
2021-09-03 15:54:16 +03:00
Dmitriy Novozhilov b9c549803d [Test] Replace public fun box() with fun box() in all box tests 2021-08-01 22:23:40 +03:00
Dmitry Petrov 851980e36f JVM_IR KT-45103 optimize direct invoke for lambdas and callable refs 2021-05-18 22:20:12 +03:00
Mikhael Bogdanov 95d95f9a9b Put reification markers came from super object signature
#KT-44770 Fixed
  #KT-30696 Open
2021-04-30 17:34:16 +02:00
Alexander Udalov 7fe10e27a1 Minor, fix failing codegen tests on different JDKs
#KT-46238
2021-04-21 14:43:10 +02:00
Alexander Udalov 27ddc31f15 Ignore codegen test using streams on Android 2021-04-21 11:39:08 +02:00
Alexander Udalov 21e9bd7ea2 Add regression tests for obsolete issues
#KT-9304
 #KT-14961
 #KT-16549
 #KT-21080
 #KT-28234
 #KT-30102
 #KT-31994
 #KT-34291
 #KT-38099
 #KT-41174
 #KT-44622
 #KT-44701
 #KT-44781
 #KT-44849
 #KT-44978
 #KT-45081
 #KT-45286
 #KT-45383
 #KT-45444
 #KT-45907
2021-04-20 21:24:29 +02:00
Mads Ager 41f5ac393a Update D8 used for dexing tests to version 2.1.96. 2021-03-24 20:16:15 +01:00
Dmitry Petrov 0cca07fa19 Bump d8 used in box tests to 2.1.75 2021-03-10 21:04:12 +03:00
pyos 1310a65f0c JVM: rename this$0 when regenerating nested objects too
In the old backend, this was unnecessary because nested objects would
reference their lambdas' captures through the original this$0. On
JVM_IR, using loose capture fields means a name/descriptor clash can
occur on any level of nesting, not just the top.
2021-02-17 07:56:03 +01:00
Alexander Udalov 73aa465ee9 Add tests for issues fixed in JVM IR
Note that KT-30696 is fixed only in the single-module case, and KT-42012
is not fixed fully (see KT-44855).

 #KT-30041
 #KT-30629
 #KT-30696
 #KT-30933
 #KT-32351
 #KT-32749
 #KT-38849
 #KT-42012
 #KT-42990
 #KT-44234
 #KT-44529
 #KT-44631
 #KT-44647
2021-02-10 21:42:10 +01:00
Dmitriy Novozhilov 49c2bfe637 [Test] Enable SMAP dump handler in boxInline tests 2021-02-02 17:53:53 +03:00
Dmitriy Novozhilov 64a300bfcd [TD] Update testdata according to previous commit 2021-02-02 17:53:52 +03:00
Alexander Udalov 5480faf5c5 Add tests for issues fixed in JVM IR and other obsolete issues
#KT-6007
 #KT-16445
 #KT-17753
 #KT-22488
 #KT-23881
 #KT-24135
 #KT-26360
 #KT-27427
 #KT-27449
 #KT-27830
 #KT-28042
 #KT-29595
 #KT-30708
 #KT-32793
2021-02-01 18:29:59 +01:00
Dmitriy Novozhilov 6a2796b067 [Test] Fix source maps in testdata according to KT-37704 2021-01-28 13:19:29 +03:00
pyos 4a76ea6ecb JVM: regenerate objects if they have been regenerated in parent contexts
This is a hack to work around the fact that type mappings should not be
inherited by inlining contexts for lambdas called from anonymous
objects. As the lambda can call the inline function again, this could
produce a reference to the original object, which is remapped to a new
type in the parent context. Unfortunately, there are many redundant
`MethodRemapper`s between the lambda and the class file, so simply
editing `TypeRemapper` does not work. Hence, this hack. For now.

(Issue found by compiling IntelliJ IDEA BTW.)
2021-01-22 13:39:20 +01:00
Mikhael Bogdanov c5015c9294 Don't recognize IrVariable as declaration scope in inlining
#KT-42815 Fixed
2020-12-08 06:16:12 +01:00
Mark Punzalan 348ba3e08c [FIR] Enable BlackBoxInlineCodegen tests for FIR.
16 out of 638 tests (2.5%) are currently failing.
2020-09-29 10:21:21 +03:00
Alexander Udalov 9e357354fb Add JVM/JVM_IR mixed compilation tests for compileKotlinAgainstKotlin/boxInline 2020-09-07 19:41:37 +02:00
Alexander Udalov 24aee1cce3 JVM IR: unmute tests on anonymous objects in inline lambdas
All tests on anonymous objects should use the NO_CHECK_LAMBDA_INLINING
directive, since the test framework can't tell an anonymous object from
a lambda and checking that anonymous objects are "inlined" makes no
sense.
2020-09-02 16:46:04 +02:00
Igor Chevdar 3c4f0d3c9e [box-tests] Added test 2020-07-16 19:23:03 +05:00
Mikhail Bogdanov 16b4342d92 Add minor test for SMAP
Relates to PR 3248
2020-05-19 18:34:56 +02:00
Alexander Udalov 098a935aa7 Fix exponential string table size of anonymous classes during inlining
When we inline an anonymous object which captures something such as
crossinline values or reified parameters, we copy and transform its
metadata in `AnonymousObjectTransformer.transformMetadata`. Basically we
read the metadata of the original class, add a minor protobuf extension
and write it to the new class.

This also includes copying the string table. We read the string table
into `JvmNameResolver` (a representation of string table used in
deserialization), then construct a `JvmStringTable` (a representation
used in _serialization_) and then write it back.

There's a few optimizations in the string table representation in JVM
metadata which allow to store less strings and thus take less space. See
`StringTableTypes.Record` in `jvm_metadata.proto` for more information.
One of the optimizations `Record.range` allows to avoid storing the same
record many times in a sequence. For example, if we have N different
strings in the string table but none of them require any operation (such
as substring, char replacement, etc.), then we only store the record
with all default values (no operation, no predefined string, etc.) and
set its `range` to N. Upon reading such optimized record list in
`JvmNameResolver`, we "expand" it back to normal, so that we could index
it quickly and figure out what operation needs to be performed on each
string from the string table.

The problem was that when we expanded this list, we didn't set the range
of the expanded record entry to 1. So each record in
`JvmNameResolver.records` still has its original range. It doesn't cause
any problems most of the time because the range in this expanded list is
almost unused. However, when copying/transforming metadata for anonymous
objects, we mistakenly passed this expanded list with incorrect ranges
to `JvmStringTable`. So the metadata in the copied anonymous object
ended up being incorrect: each record now was present the number of
times equal to its range. Copying such metadata once again led to
another multiplication of the record list size. Multiple copies resulted
in exponential increase in memory consumption and quickly led to OOM.

For the fix, we now take the original, unexpanded list of records when
creating `JvmStringTable` out of `JvmNameResolver` for transformation of
anonymous object metadata.

Note that another possible fix would be to make range for each record in
`JvmNameResolver.records` equal to 1. This is undesirable though, since
then we'd need to copy each `JvmProtoBuf.StringTableTypes.Record`
instance, of which there could be many, and use some memory for no
apparent gain (since ranges in that expanded list are now not used at
all).

 #KT-38197 Fixed
2020-04-28 12:59:52 +02:00
Igor Chevdar d808ef10b2 Added some tests on local classes in inline bodies 2020-03-28 15:26:19 +03:00
Igor Chevdar e2a378bed7 [JS_IR] More subtle local classes copying in inliner 2020-03-28 15:26:19 +03:00
pyos 2c06503311 JVM_IR: partially fix inline methods using captured crossinline lambdas
The fields containing crossinline lambdas should be package-private to
avoid generating synthetic accessors, which break object regeneration.

Note that the inline methods cannot actually be called, as call sites
will attempt to read the captured lambda from a field through a *copy*
of the local containing the object, so these reads will not be inlined,
causing an exception at runtime:

    inline fun f(crossinline g: () -> Unit) = object : I {
        inline fun h() = g()
        // effectively `val tmp = this; return tmp.$g()`:
        override fun run() = h()
    }

    f {}.run() // NoSuchFieldError: $g

This particular example can be fixed by reusing locals for receiver
parameters in IrInlineCodegen, but explicitly assigning `this` to
another variable and calling an inline method on it will break it again.
(This is only applicable to the JVM_IR backend, as the non-IR one fails
to generate `f` at all for some other reason.)
2020-03-18 13:13:54 +01:00
Zalim Bashorov 179ec41a6b [JS BEs] Generate tests for whole "codegen/boxInline" 2020-03-12 17:22:33 +03:00
Steven Schäfer 5760c0be9c JVM IR: Avoid redundant coercions in ExpressionCodegen 2020-02-15 22:32:23 +03:00
pyos f906524d76 Mark a SAM conversion test as JVM-only 2019-11-12 12:24:55 +01:00
pyos 5d8aac456f JVM_IR: create temporaries for complex super constructor arguments
As for SAM wrappers, the bytecode sequence

    new A
    dup
    new B
    dup
    invokespecial B.<init>
    invokespecial A.<init>

breaks the inliner, so instead we do

    new B
    dup
    invokespecial B.<init>
    store x
    new A
    dup
    load x
    invokespecial A.<init>
2019-11-06 15:54:40 +01:00
pyos 42f75b3247 JVM_IR: have SAM wrapper constructors accept FunctionN
Otherwise, the cached instances cannot be reused for different wrapped
types. Also, if the wrapped type is regenerated during inlining, the
inliner would produce a call to a nonexistent constructor that takes the
regenerated type as an argument.
2019-11-06 15:54:40 +01:00
pyos 862197d713 JVM_IR: create temporaries for complex SAM conversion arguments
To avoid bytecode sequences like

    new _1Kt$sam$i$java_lang_Runnable$0
    dup
    new _1Kt$f$1
    dup
    invokespecial _1Kt$f$1.<init>()V
    invokespecial _1Kt$sam$i$java_lang_Runnable$0.<init>(...)V

as the different order of `new` and `<init>` confuses the inliner.
2019-11-06 15:54:40 +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
pyos a835f07d51 JVM_IR: don't regenerate objects in lambdas inlined into objects 2019-10-31 09:09:54 +01:00
Mikhael Bogdanov 63b115abb6 Workaround for KT-34656: temporary disable assertion 2019-10-29 09:48:49 +01:00
pyos d3992826e4 JVM_IR: discard parameter annotations in anonymous object constructors 2019-10-14 14:54:44 +02:00
pyos 06c00f4d9e Unmute some JVM_IR inlining tests 2019-10-08 17:19:41 +02:00
Georgy Bronnikov 7ede26e8f4 IrCompileKotlinAgainstInlineKotlin tests 2019-09-06 09:19:57 +03:00
Mikhael Bogdanov 1eda42cb88 JVM_IR. Generate SMAP information for anonymous classes
#KT-28092 Fixed
2019-08-08 12:02:50 +02:00
Mikhael Bogdanov 971d36837a JVM_IR. Don't generate annotations and signature on synthetic methods 2019-08-05 15:00:51 +02:00
Steven Schäfer efb938a7c8 (Un)mute tests 2019-07-31 11:18:44 +02:00
pyos 90f11211d3 JVM_IR: wrap performInline in enterIntoInlining/exitFromInliningOf 2019-05-06 16:23:28 +02:00
pyos b74586f84e JVM_IR: implement single-abstract-method conversions 2019-04-04 09:45:00 +02:00
pyos 8c55376f0c Unmute almost all JVM_IR tests that use property references 2019-03-19 12:00:29 +01:00
Mikhael Bogdanov 9ab6062295 Properly capture extension receiver for array convention expressions in object constructor
#KT-19389 Fixed
2019-02-05 16:14:50 +01:00
Mikhael Bogdanov f7ce8c18c6 Add tests for Obsolete issues
#KT-18977 Obsolete
2019-01-09 10:20:54 +01:00
Mikhael Bogdanov 9a059809bf Add test for Obsolete issues
#KT-15956 Obsolete
 #KT-15751 Obsolete
 #KT-16417 Obsolete
 #KT-21787 Obsolete
2019-01-08 13:52:47 +01:00
Mikhael Bogdanov f59b6a350f Specify JVM target backend for other java related tests 2018-12-21 16:09:11 +01:00
Mikhael Bogdanov 1217d3591b Specify JVM target backend for test with '::class.java' usage 2018-12-21 16:09:04 +01:00
Pavel Punegov 2ff6047845 Update ignore tag for Native backend 2018-08-28 13:48:43 +03:00