Commit Graph

5594 Commits

Author SHA1 Message Date
pyos aa47191de4 JVM: hide ExpressionCodegen in finally block generation during inlining 2021-06-16 12:13:32 +02:00
pyos 108bd01698 JVM: refine the stack spilling around inline calls
Not all suspend functions need it - only those with suspension points.
2021-06-16 12:13:32 +02:00
pyos b136acb185 JVM: move callSiteFile to InlineCallSiteInfo 2021-06-16 12:13:32 +02:00
pyos 6c1a5e1211 JVM: make inline function argument processing a bit shorter 2021-06-16 12:13:32 +02:00
pyos 392e4fba42 JVM: fix inlining of default lambdas of signature (Result) -> Any
They have no `invoke` bridge, and the overridden invoke expectes a boxed
`Result` as an argument.
2021-06-16 12:13:32 +02:00
pyos a0a14d9e25 JVM: remove descriptors from SourceCompilerForInline
Printing the call site source on errors isn't really useful anyway - the
old backend points to a specific PsiElement, and JVM_IR wraps the
exception in FunctionCodegen (and printing the source never worked with
JVM_IR anyway).
2021-06-16 12:13:32 +02:00
pyos 32ad747632 JVM: load default lambda method nodes immediately
The ones that are not needed are filtered out before DefaultLambda is
even constructed anyway, and this way we need fewer lateinit vars.
2021-06-16 12:13:32 +02:00
pyos 1e953eaf01 JVM: remove contextKind from SourceCompilerForInline
Guess what? It's only useful for the old backend's type mapper!
2021-06-16 12:13:32 +02:00
pyos 1109348b6d JVM: remove lookupLocation from SourceCompilerForInline 2021-06-16 12:13:32 +02:00
pyos b6e9f64e18 JVM: remove functionDescriptor from InlineCodegen 2021-06-16 12:13:32 +02:00
pyos d89e2d9f08 JVM: split inline intrinsics into "needed by JVM_IR" and "not"
or, alternatively, "suspend" and "not".
2021-06-16 12:13:32 +02:00
pyos eb4d831d27 JVM_IR: implement typeOf<T> as a codegen intrinsic
rather than a fake inline function.

Also, generate more correct instructions for typeOf. Not sure how that
even worked before - `aconst(Boolean)` isn't even valid.
2021-06-16 12:13:32 +02:00
pyos 7dbf08ae1c JVM: move loadCompiledInlineFunction out of InlineCodegen 2021-06-16 12:13:32 +02:00
pyos 8307367f90 JVM: don't thread callDefault through the inliner
It's only used by the old backend, and should be given to
PsiSourceCompilerForInline by PsiInlineCodegen.
2021-06-16 12:13:32 +02:00
pyos d4485bc475 JVM: remove unused methodOwner from InlineCodegen 2021-06-11 15:03:13 +02:00
pyos ed26e97df8 JVM: refactor loading of inline functions from binaries
The IR path no longer does any descriptor unwrapping or old-style type
mapping.
2021-06-11 15:03:13 +02:00
pyos 7bcd738bb1 JVM: inline createInlineMethodNode into InlineCodegenForDefaultBody
Most of it is unused, since there we know the target function will also
need to be compiled from source.
2021-06-11 15:03:13 +02:00
pyos 4c7eb815fc JVM: remove some FunctionDescriptors from SourceCompilerForInline 2021-06-11 15:03:13 +02:00
pyos a24ad233ee JVM: move PsiSourceCompilerForInline to a separate file 2021-06-11 15:03:13 +02:00
pyos 955b9260d1 JVM: move more old backend code out of InlineCodegen 2021-06-11 15:03:13 +02:00
pyos 043452fb62 JVM: make handling of captured params for default lambdas shorter 2021-06-11 15:03:13 +02:00
pyos 4cae880b44 JVM: remove unused DefaultLambda.parameterOffsetsInDefault 2021-06-11 15:03:13 +02:00
pyos 8a3af851d9 JVM: pregenerate inline lambda bodies as early as possible
Which in JVM_IR is immediately in `genValueAndPut`, but for the old
backend needs to be delayed until `genCallInner` for some reason.
2021-06-11 15:03:13 +02:00
pyos 90412ade8a JVM: remove second parameter of putClosureParametersOnStack
Only used by the old backend.
2021-06-11 15:03:13 +02:00
pyos d4c8a033b1 JVM: remove BaseExpressionCodegen.pushClosureOnStack
It's only used by the old backend
2021-06-11 15:03:13 +02:00
pyos b6c3c9942d JVM: move activeLambda to PsiInlineCodegen 2021-06-11 15:03:13 +02:00
pyos 7333abf50d JVM: purge redundant val BaseExpressionCodegen.v 2021-06-11 15:03:13 +02:00
Dmitry Petrov dbb933e6a6 JVM use instruction liveness analysis instead of DFA in DCE 2021-06-09 17:04:47 +03:00
Dmitry Petrov 7a43c2de79 JVM remove dead code during constant condition elimination
This avoids an extra call to 'analyze', which is rather costly.

Update debugger testData: Constant condition
elimination now performs DCE more consistently.
2021-06-03 00:08:27 +03:00
Dmitry Petrov 1fd94d1bc2 JVM Minor: cleanup RedundantNullCheckMethodTransformer 2021-06-03 00:08:25 +03:00
Alexander Udalov bcf47ddc94 Move optional annotation utilities to module 'resolution'
To avoid depending on a heavy module 'frontend' in parts of the compiler
where checking for optional annotations is needed, such as in
'ir.serialization.common'.
2021-06-01 20:28:22 +02:00
Dmitry Petrov 9091ca7b51 JVM_IR KT-46864 handle "unused" LDC instructions properly 2021-05-31 21:12:35 +03:00
Pavel Kirpichenkov f5a53c82c5 Don't write type arguments of types replaced with Any to metadata
Anonymous types are not approximated by frontend for private declarations.
Class IDs for such types are replaced by StringTable before being written
to metadata. JVM string table mangles such types and keeps them generic
for reflection. For other purposes the types are replaced with `Any`.
Type arguments of the replaced type should be ignored in the latter case.
Otherwise decompiled text builder crashes on an attempt to restore `Any`
type with non-zero number of type arguments.

The code pretending to replace a type with its first supertype was dropped
from ApproximatingStringTable for two reasons:
- the first type from `getAllSuperClassifiers` is the original type itself
which doens't provide a ClassId for anonymous type, so it was a noop
- tracking potential type arguments of the first anonymous type's supertype
would be a complication with almost no practical value (types in decompiled
text would be slightly closer to the real type of a private declaration).

^KT-46393 Fixed
2021-05-28 14:42:47 +00:00
Victor Petukhov d8c68aacdd Split setting substitutor descriptor for entire resolved call into two parts: setting resulting substitutor and setting substitutor for resolved call's types 2021-05-28 15:36:22 +03:00
pyos 34878d17eb JVM: be more careful when removing unused constants
1. if an argument of a `pop` cannot be removed, then all other potential
   arguments of that `pop` can't be removed either, and the same applies
   to other `pop`s that touch them;
2. the same is true for primitive conversions, but this is even trickier
   to implement correctly, so I simply did the same thing as with
   boxing operators: replace the conversion itself with a `pop` and keep
   the argument as-is.

Somehow this actually removes *more* redundant primitive type conversions
than the old code in a couple bytecode text tests, so I've patched them
to kind of use the value, forcing the instructions to stay.

 #KT-46921 Fixed
2021-05-27 12:24:22 +02:00
pyos 2f60ce21a0 JVM: remove CHECKCAST handling from PopBackwardPropagationTransformer
Redundant CHECKCASTs should've been removed by a previous pass.
2021-05-27 12:24:22 +02:00
pyos 535934dc28 JVM: do not remove NOPs in PopBackwardPropagationTransformer
There is a pass that removes NOPs and runs afterwards anyway.
2021-05-27 12:24:22 +02:00
pyos 117fad2018 JVM: refactor inline ExpressionLambda initialization 2021-05-26 08:33:55 +02:00
Mads Ager d023966054 [JVM] Fix various undefined locals issues.
CoroutineTransformermethodVisitor attempts to extend the ranges
of local variables in various situations. Probably in an attempt
to give a better debugging experience. However, all of these
range extensions lead to invalid local variable tables where
something is in the local variable table where nothing is in the
corresponding slot.

The code that extends variables to the next suspension point
instead of ending them when they are no longer live has issues
with loops. When resuming and reentering the loop, the locals
table will mention a local that we did not spill and which
is therefore not restored when resuming.

The code that extends local variable table entries if there
are no suspension points between two entries doesn't work
for code such as:

```
var s: String
if (suspendHere() == "OK") {
  s = "OK"
} else {
  s = "FAIL"
}
```

If the local variable ranges are collapsed into one, one of
the branches will have the local defined in the local variable
table before the slot is initialized.
2021-05-26 08:33:34 +02:00
pyos 21f2b3fa2b JVM: expect a continuation parameter in default suspend references 2021-05-18 10:48:31 +02:00
pyos 57c934987c JVM_IR: try to load mangled invoke from default lambdas
Old compiler versions still won't be able to load default lambdas
generated by JVM_IR, but this way we avoid incorrect behavior of
function references taking inline class types that unbox to Any.

 #KT-46601 Fixed
2021-05-18 10:48:31 +02:00
pyos c32ccbb39a JVM: move descriptors from DefaultLambda to PsiDefaultLambda
Also, produce more correct results in IrDefaultLambda's
`invokeMethodParameters` and `invokeMethodReturnType`. This affects
whether the inliner inserts inline class boxings/unboxings around lambda
calls; while this doesn't matter now due to KT-46601, it would if the
naming was fixed.
2021-05-18 10:48:31 +02:00
pyos 7c168d663a JVM: move PSI-based LambdaInfo to PsiInlineCodegen 2021-05-18 10:48:31 +02:00
pyos 493b4e6c27 JVM: rearrange some LambdaInfo stuff 2021-05-18 10:48:31 +02:00
pyos 14e1417ea8 JVM: expect consistent signatures from LambdaInfo 2021-05-18 10:48:31 +02:00
Alexander Udalov ee6586fe4f Fix accidental usage of ASM from jdk.internal
#KT-46402 Fixed
2021-05-14 15:23:08 +02:00
Alexander Udalov 4c7f207309 Use new getInlineClassRepresentation in some utilities 2021-05-13 13:54:02 +02:00
pyos 3fc2cc410c JVM_IR: propagate reified type parameter usages from inline lambdas
...to whichever class they are inlined into, not the class they are
declared in (which is not the same if the lambda is crossinline).

 #KT-46584 Fixed
2021-05-12 15:09:35 +03:00
pyos 614d529168 JVM: remove LambdaInfo.invokeMethodDescriptor 2021-05-11 05:49:17 +02:00
Mads Ager afa1b8bfdc [JVM] Extend boxing/unboxing optimizations to coroutine boxing. 2021-05-06 15:35:49 +02:00