Commit Graph

519 Commits

Author SHA1 Message Date
Victor Petukhov 447308dcfc Revert "Revert "Revert "Completely rewrite reifiedIntTypeAnalysis, making it more streamline"""
This reverts commit 5567033b
2020-06-17 13:02:40 +03:00
Ilmir Usmanov 5567033b33 Revert "Revert "Completely rewrite reifiedIntTypeAnalysis, making it more streamline""
This reverts commit 822c14814b.
2020-06-09 20:52:24 +02:00
Dmitry Petrov 202bbdf8dd Forward compatibility hacks for Result.{success, failure}
Don't mangled functions annotated with @JvmName.
Annotate 'Result.success' and 'Result.failure' with @JvmName and
@Suppress("INAPPLICABLE_JVM_NAME").
NB this would require bootstrap.
2020-06-04 12:16:27 +03:00
Ilmir Usmanov 822c14814b Revert "Completely rewrite reifiedIntTypeAnalysis, making it more streamline"
This reverts commit 1ed4324613.

Otherwise, bootstrap is broken.
2020-06-03 19:43:59 +02:00
Ilmir Usmanov 1ed4324613 Completely rewrite reifiedIntTypeAnalysis, making it more streamline
and easy to understand and optimize if it would be a bottleneck.
Use LVT to get information of refined int type in one specific case

 #KT-38925 Fixed
2020-06-03 16:03:50 +02:00
pyos 35460fed19 JVM_IR: fix a bug when isInlineParameter is applied to default stubs
If an inline parameter has a default value, its type is nullable.
There's already code to handle this in `IrInlineCodegen`, but it
really should be in `isInlineParameter` instead, otherwise e.g.
SyntheticAccessorLowering fails.
2020-05-29 10:04:36 +02:00
Dmitry Petrov a270ee094c Language feature for new inline class mangling rules (since 1.4) 2020-05-29 00:53:01 +03:00
Vitaly fe047f9b47 [JS BE] mutes tests for JS_IR_ES6, which muted for JS_IR 2020-05-27 00:32:56 +03:00
pyos 76c34a07b2 JVM: use 1 as a synthetic line number for @InlineOnly lambdas
The source path already marks it as synthetic.
2020-05-25 20:03:56 +02:00
pyos 25e1fb8502 JVM: map synthetic line numbers through the SMAP
This is necessary so that IDEA does not ignore the line number.
2020-05-25 20:03:56 +02:00
pyos d17a18f96d JVM: do not write trivial SMAPs to classes outside inline funs
where trivial == those that map the file to itself.
2020-05-25 20:03:56 +02:00
Mikhail Bogdanov 16b4342d92 Add minor test for SMAP
Relates to PR 3248
2020-05-19 18:34:56 +02:00
pyos 86b28b95ca JVM: keep call site markers when inlining lambdas into objects
A follow-up for KT-35006:

    fun f() = foo {
        bar()
    }
    inline fun foo(crossinline x: () -> Unit) = { x() }()
    inline fun bar() = TODO()

does not provide the option to navigate to bar's call site at all.
2020-05-19 18:33:27 +02:00
pyos 5feadd56ef JVM: parse KotlinDebug when regenerating anonymous objects 2020-05-19 18:33:27 +02:00
pyos 1fe7ef6521 JVM: separate the two kinds of source mappers
* a writing source mapper has `mapLineNumber(line, file, class)` that
   inserts a new SMAP entry and returns a fake line number from it;
 * a copying source mapper has `mapLineNumber(line)` that uses an
   existing SMAP to resolve the line number and call the former method
   on a different source mapper;
 * those two types are disjoint.
2020-05-19 18:33:27 +02:00
Ilmir Usmanov d6d331de2a Minor. Fix test 2020-05-08 19:36:02 +02:00
Ilmir Usmanov 05797afaf8 Replace last SourceInterpreter with specific one in inliner
#KT-38489: Fixed
2020-05-07 23:04:03 +02:00
Ilmir Usmanov 2c88844409 Replace SourceInterpreter with interpreter, which track only
functional arguments.
2020-05-07 23:04:01 +02:00
Mikhail Zarechenskiy e3fe1bcf7c [NI] Place varargs at the end of value arguments list
This is needed to preserve behavior with the OI
2020-04-29 14:15:15 +03: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
pyos 456469eb3b JVM: fix remapping of new T inside regenerated copies of T
In general, `InliningContext.findAnonymousTransformationInfo` was not
reliable because it mapped each type to *some* info for that type,
preferring ones with `shouldRegenerate == true` if those exist. Thus, it
returned incorrect results if one type was regenerated multiple times,
e.g. in a nested inlining context or because of a `finally` (which
duplicates anonymous objects). The solution is to avoid a global map and
attach the current transformation info directly to the current inlining
context.
2020-04-23 14:20:54 +02:00
Mikhail Bogdanov 461c368ee0 Minor. Unmute test 2020-04-16 13:49:48 +02:00
Kristoffer Andersen 7ec4c9990a [JVM] Improve debug step behavior around lambdas.
- Add tests to clarify problematic behavior
- Avoid line numbers on return instructions of lambdas without explicit returns
2020-04-15 14:33:49 +02:00
Mikhail Bogdanov dec93c8b49 Add ANDROID target 2020-04-14 13:53:22 +02:00
Mikhail Bogdanov 1772f20d48 Minor. Add smap test for multifile facade 2020-04-08 07:26:55 +02:00
pyos 9334327bbf JVM_IR: unmute two more tests fixed by #3106 2020-04-08 07:04:16 +02:00
pyos b3e124ad66 Add a test where classes call inline functions from each other 2020-04-08 07:04:16 +02:00
pyos 495cefe65d Dump bytecode in a test that shows the effect of recompiling inline funs 2020-04-08 07:04:16 +02:00
Mads Ager 03fb49bb38 [JVM_IR] Improve debugging behavior of inline functions
Specifically, this commit improves the stepping behavior of the IR
backend around functions with defaults.

  - Improved line numbers in the default handler itself for better
    stepping when inlined.

  - Improved source information on default arguments

  - Improved test coverage of stepping behavior in old and IR backends.

Improves the stepping behaviour around inline methods with default
arguments. In particular, we now accurately step through the
evaluation of default arguments, but do _not_ spuriously show the exit
from the $default handler.
2020-04-07 16:52:45 +02:00
pyos 516692008f JVM: add tests fixed by the last two commits
One was broken on JVM, the other on JVM_IR.
2020-04-07 15:42:41 +02:00
pyos 5ed845d0b4 JVM_IR: reuse same bodies for suspend funs and $$forInline versions 2020-04-03 19:51:45 +02:00
pyos e98bdc6f8e JVM: preserve call site markers when inlining lambdas
and default functions into their own stubs.

Fixes #KT-35006
2020-03-31 16:06:57 +02:00
pyos 9d21800d8f JVM: fix SMAP range extension logic
If `mapLineNumber` was called in non-monotonic order, e.g. N then N+2
then N+1, the first two calls created a range that spans [N; N+2] but
the third call did not reuse it.
2020-03-31 16:06:57 +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 be37e7135a Add a test for SMAPs with interleaved files 2020-03-25 14:03:32 +01:00
pyos 4558d48481 JVM: add a language feature to omit *E between SMAP strata
Fixes #KT-37704
2020-03-25 10:33:59 +01:00
max-kammerer a3125849a0 Merge pull request #3204 from pyos/ir/fix-lambda-inner-classes
JVM_IR: restore InnerClasses for objects in lambdas
2020-03-20 17:15:41 +01:00
Mikhael Bogdanov ab7e71fd68 Support per files test directives 2020-03-19 16:45:10 +01:00
pyos 186302d84e JVM_IR: restore InnerClasses for objects in lambdas 2020-03-19 15:23:44 +01:00
pyos d06c87207c Dump class structure in a test that has an object in a lambda 2020-03-19 15:11:20 +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
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
pyos 2e542da91d JVM_IR: fix accesses from crossinline lambdas in other packages again 2020-03-17 16:38:32 +01:00
pyos bdd88e1655 JVM_IR: place suspend markers in faux lambdas around inline references
Otherwise, the assumption that coroutine codegen makes about every
inlined function already having the markers breaks and it is no longer
true that calls to inline lambdas do not require them.
2020-03-13 18:33:41 +01:00
Zalim Bashorov 179ec41a6b [JS BEs] Generate tests for whole "codegen/boxInline" 2020-03-12 17:22:33 +03:00
pyos dc388f3f3a JVM_IR: add a test for suspend inline fun with defaults in a class
This is one example of a function replaced by a lowering after
AddContinuationLowering mentioned in the last commit: the lowering that
makes default stubs static is further down. Although this is not a
lambda, calling getOrCreateSuspendFunctionViewIfNeeded on it in the
inliner is fatal all the same.
2020-03-09 17:05:42 +01:00
Mark Punzalan a732e8f5fe [JVM IR] Ensure there is one accessor for each super access from a
subclass when there are multiple subclasses in a file.
2020-03-06 22:59:52 +01:00
pyos 8487211ae1 JVM_IR: refine the condition for mangling names of multifile members
Private $$forInline versions of public suspend functions should not
be mangled. (Note that there are no $$forInline versions of private
suspend functions, as those are effectively inline-only.)
2020-03-06 14:33:50 +01:00
Alexander Udalov 0f7122a88a Support MutablePropertyReferenceN supertypes in LambdaInfo
#KT-37087 Fixed
2020-03-05 14:01:30 +01:00