Commit Graph

679 Commits

Author SHA1 Message Date
Roman Artemev 318568636e [IR] Pass IrBuiltIns to BuiltinSymbolsBase 2020-05-12 14:29:53 +03:00
Roman Artemev da661e4db7 [IR BE] Remove usage of KotlinType from ir loop optimization 2020-05-12 14:29:53 +03:00
Alexander Udalov 91ef053fbc IR: keep local scope with counter maps across LDL invocations
Since LocalDeclarationsLowering is a BodyLoweringPass, local
functions inside one declaration are handled independently of local
functions in the other declaration. This can lead to name clashes, in
case a local function with the same name and signature is declared in
overloads in the same container, which results in a signature clash
error in JVM IR.

The issue became more common with the introduction of adapted function
references, where psi2ir generates a local adapter-function with a
predefined name, which can easily clash with another reference to the
same target in an overload. This led to a compilation error when
bootstrapping Kotlin with JVM IR, for example in GradleIRBuilder.kt
where there are a lot of references to the same function.
2020-05-08 14:33:34 +02:00
Alexander Udalov 7a369b3a6a Mark PureIrGenerationExtension as deprecated to prevent more usages
The IR plugin extension mechanism is being reworked and in the new
scheme, this new extension point won't be necessary.
2020-05-06 22:51:32 +02:00
Steven Schäfer 7cad2be329 IR: Add an extension point after IR construction
The existing IrGenerationExtension is in the middle of IR construction
and basically requires plugins to work with the (deprecated) descriptors.

Since there are plans to change the IR extension point it makes sense to
introduce a temporary work-around to allow pure IR plugins to be
developed now, which could be ported to a more permanent API later.
2020-05-06 22:51:12 +02:00
Alexander Udalov 9fa8e009c6 Support equals/hashCode for fun interfaces in JVM and JVM_IR
#KT-33455 Fixed
2020-04-29 12:15:50 +02:00
pyos 887165a23b JVM_IR: avoid copying when optimizing ?:/?. 2020-04-24 21:00:07 +03:00
Alexander Udalov 2815bb88c2 Remove unnecessary dependency of 'fir2ir' on 'ir.backend.common'
Move some lookup utilities which are used in
`OperatorExpressionGenerator`, to 'ir.tree'.
2020-04-23 23:16:29 +02:00
Georgy Bronnikov 565874b3a0 Pass along type in IfNullExpressionFusionLowering 2020-04-23 18:18:34 +03:00
Georgy Bronnikov 3bb32941a0 IR: bugfix in KotlinNothingValueExceptionLowering 2020-04-21 21:00:16 +03:00
Dmitry Petrov 05cb0e8994 KNVE: support in JVM_IR and JS_IR 2020-04-20 20:07:52 +03:00
Roman Artemev a9788f9506 [KLIB] Create an abstract class for module deserializer
- Introduce Ir-based Functional interface factory
 - Switch from LazyIr to pure
 - Use kotlin library to access raw bytes
 - Link dirty files against IC cache and dependencies instead of LazyIr
 - Move `DescriptorByIdSignatureFinder` from K/N to common
 - Support inline-bodies only MODE
2020-04-14 11:12:08 +03:00
Igor Chevdar 626c94c54d [IR] Fixed bug with redundant creation of Ref<> in inline lambdas 2020-04-13 21:11:59 +05:00
Anton Bannykh 998218716d IR: make lateinit lowering traverse local classes 2020-04-08 14:44:25 +03:00
Igor Chevdar ae906c163d [IR] Added possibility to customize inline functions resolver 2020-04-07 13:25:46 +03:00
pyos a75408b1ed JVM_IR: use non-nullable types as SAM super types
The wrappers for conversions to nullable and non-nullable SAM types are
the same, so differentiating those has no effect other than class name
collisions.
2020-04-02 15:40:17 +02:00
Georgy Bronnikov 5fe28b3179 IR: explicitly pass isFakeOverride to buildFun and friends 2020-03-30 17:32:02 +03:00
Georgy Bronnikov fb6956f842 IR common: use .isFakeOverride instead of checking origin 2020-03-30 17:32:02 +03:00
Igor Chevdar 643e581448 [IR] Supported extraction of local classes from inline bodies
The mental model for inline functions/lambdas is as following:
inline functions have the `inline` keyword before them so it makes sense
for their bodies to be copied at call sites although the compiler might optimize
that if there is no usage of reified type parameters or crossinline value parameters.
But since there is no `inline` keyword around an inline lambda, then
it is logical to think that there will be no copy of it and that it will be just embedded
at the corresponding call site as is.
2020-03-28 15:26:19 +03:00
Igor Chevdar 7a48c3a945 [IR] Made currentDeclarationParent nullable 2020-03-28 15:26:19 +03:00
Steven Schäfer 58685be4e2 IR: Don't use IrStringConcatenation for ordinary toString calls
We can only use IrStrinConcatentation to represent calls to Any?.toString
and toString calls on primitive types. Otherwise, x.toString() and "$x"
are observably different when x is a non-null type with null value
(e.g., an @NotNull value coming from Java).
2020-03-27 17:31:48 +03:00
Dmitry Petrov 9a95941ef3 JVM_IR: Rewrite '?.' and '?:' chains
This shortens code and avoids unnecessary boxing in some cases.
2020-03-26 12:19:25 +03:00
pyos e0a5ab7146 Do not regenerate objects if all captured lambdas are noinline 2020-03-19 15:11:20 +01:00
Mikhail Glukhikh 0f0e5e603d [FIR2IR] Use IR built-in types, their symbols & constructors directly 2020-03-18 17:09:36 +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
Dmitry Petrov 6809f4439c Fix range-based 'for' loop with 'continue' in range bounds
1. Search for increment function in range element type, not in inferred
induction variable type
(which can be inappropriate, e.g., 'Nothing' in case of 'continue').

2. Handle nested loops with shared exit labels
(generated by JVM_IR for KT-37370 case).

KT-37370 KT-37373
2020-03-17 12:18:48 +03:00
Igor Chevdar a1eff7f4af [IR] Set source offsets in SAM lowering
This is needed for debug info generating in K/N
2020-03-16 11:58:36 +03:00
Zalim Bashorov d22e4495de [JS IR DCE] Improve handling overrides
Introduce the notion of contagious for overridable declarations.
So, now overriding uncontagious declaration will not lead to becoming a declaration reachable.
By default, all declarations treated as contagious, it's not the most efficient, but it's safest.
In case when we access a declaration through a fake-override declaration,
the original (real) one will not be marked as contagious, so, later,
other overrides will not be processed unconditionally only because
it overrides a reachable declaration.
2020-03-11 12:54:40 +03:00
pyos 68745ec43f JVM_IR: refactor JvmSharedVariablesManager 2020-03-06 17:58:35 +03:00
Igor Chevdar 93394656a3 [IR] Supported fake overrides in SAM lowering + enabled test 2020-03-06 12:47:00 +03:00
Roman Artemev cf41172521 [JS IR] A bunch of fixes to make PIR mode work
- provide required mappings
 - fix fake overrides
 - fix local declaration lowering
 - fix DCE
2020-03-03 18:54:35 +03:00
Roman Artemev b9eff4b246 [JS IR] Make coroutines work with new lambda scheme
- Do not create extra class for suspend lambda
2020-03-03 18:54:35 +03:00
Roman Artemev 26237f8bd5 [JS IR] Implement new function references scheme 2020-03-03 18:54:34 +03:00
pyos 159d292ea7 JVM_IR: make continuation detection more consistent
* unify various checks for whether a suspend function needs a
    continuation;

  * mark the continuation parameter with an origin (this also allows
    correctly computing the offset of the local in codegen -- see the
    new test);

  * when wrapping `suspend fun main`, use a suspend reference instead of
    a synthetic non-suspend lambda (required to correctly implement the
    previous point, as previously the continuation parameter was passed
    to main() itself correctly only because of very lenient checks in
    AddContinuationLowering).
2020-03-03 15:12:13 +01:00
Svyatoslav Kuzmich 1e02fa3db9 [JS IR BE] Create temporary variables with wrapped descriptors. 2020-02-27 16:54:55 +03:00
Kristoffer Andersen c1d350f8f3 [JVM IR] Added null-checks of handler for non-super $default calls 2020-02-26 16:28:27 +01:00
Mads Ager d982203d56 [JVM_IR] Handle big arity suspend functions in existing lowering.
Now that suspend function views are created in
AddContinuationLowering, we can let the
FunctionNVarargBridgeLowering deal with rewriting of large
arity FunctionN/SuspendFunctionN.
2020-02-24 13:01:18 +01:00
Mark Punzalan 64141b8b38 [JVM IR] Fix issue where fields are not being set to their default
values within initializer blocks.

The issue occurs in code like this:
```
class C {
  var b = true
  init {
    b = false   // Missing PUTFIELD for this statement
  }
}
```

Added a new statement origin for field initialization (at declaration)
instead of relying on `origin == null` in ExpressionCodegen to determine
whether to generate the initializations.

This was unintentionally broken in
d68a1898d0.
2020-02-17 23:04:11 +03:00
Igor Chevdar 9bc7a43991 [IR] [JS_IR] Supported fun interfaces in JS 2020-02-17 12:21:00 +03:00
Steven Schäfer 2b2ae8a5f1 IR: Optimize implicit integer coercions on constants. 2020-02-15 22:32:23 +03:00
Roman Artemev d51b14fe3c [IR] Fix classic mangler expect checker 2020-02-14 18:22:15 +03:00
Anton Bannykh 52ae63f191 IR: decommonize AbstractSuspendFunctionsLowering.kt
Some issues emerged while building kotlinx.coroutines
Reverted changes to the common lowering.

TODO: fix after M1
2020-02-12 20:19:10 +03:00
Steven Schäfer 9db82bfcc8 JVM IR: Create package private synthetic multi file part classes 2020-02-11 17:01:22 +01:00
Steven Schäfer 461d8ef368 Add renaming special bridges to SpecialBridgeMethods 2020-02-07 18:44:50 +03:00
Steven Schäfer 73b4f897b6 JVM IR: Fix modalities in JvmSymbols 2020-02-07 18:44:50 +03:00
pyos 5acb3e14fb IR: mark parameters for captures of crossinline parameters 2020-02-07 12:16:26 +01:00
Anton Bannykh 1e96c3d21e DCE-driven mode
:js:js.tests:jsIrTest works same as before
:js:js.tests:jsPirTest runs tests in DCE-driven mode
2020-02-06 21:03:41 +03:00
Anton Bannykh f07fb91e9d Simple stage layers + enforce model 2020-02-06 21:03:40 +03:00
Anton Bannykh 4c4b0ef013 Suspend Functions
2 tests muted due to duplicate variables found by the validator
If memory serves:
- there is a `suspend inline fun` and a callable reference to it
- the suspend function doesn't remove the original function in this
  case anymore
- the duplicate `var`'s are inside the function body and the
  callable reference state machine body
2020-02-06 21:03:40 +03:00
Anton Bannykh 94d2a79d2e FoldConstantLowering 2020-02-06 21:03:40 +03:00