Commit Graph

4748 Commits

Author SHA1 Message Date
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
Mikhail Glukhikh a545ec41a0 FIR serializer: consider exotic types as errors (breaks 4 BB tests) 2020-04-28 07:35:09 +03:00
Mikhail Glukhikh 394fa7affc FIR serializer: add bad test data changes 2020-04-28 07:35:06 +03:00
Mikhail Glukhikh f98c73cb30 [FIR] Support FirMetadataSource.File in FIR2IR & serializer (KT-38156) 2020-04-28 07:35:04 +03:00
Mikhail Glukhikh c2c85365e6 Use FIR metadata in FIR2IR data class member generator (KT-38156) 2020-04-28 07:34:59 +03:00
Mikhail Glukhikh c6c848f929 Introduce & use FirJvmSerializerExtension & FirBasedClassCodegen
#KT-38156 In Process
2020-04-28 07:34:56 +03:00
Dmitry Petrov c7a96810bf JVM: Suspend conversion for function references 2020-04-27 21:02:37 +03:00
Jinseong Jeon ef09850df8 FIR2IR: set superQualifierSymbol for super call 2020-04-27 11:50:26 +03:00
Jinseong Jeon 57fe01c375 FIR2IR: populate overriddenSymbols for overriding functions
#KT-38416 Fixed
2020-04-27 11:50:24 +03:00
Georgy Bronnikov 565874b3a0 Pass along type in IfNullExpressionFusionLowering 2020-04-23 18:18:34 +03:00
Alexander Udalov 025d1ca64d psi2ir: rework representation of bound adapted function references
This fixes the problem in JVM IR backend which didn't pass bound
receiver value of an adapted function reference to the superclass
(kotlin/jvm/internal/AdaptedFunctionReference), which caused equals to
work incorrectly on such references (see changes in box tests).

Previously, bound adapted function reference was represented as
IrFunctionExpression to an adapter function which calls the callee. The
value of the bound receiver in that case could only be found in the body
of that adapter function. This is not very convenient, so this change
makes psi2ir produce a block of the adapter function + reference to it.
The bound receiver value is then found in the reference. This is
basically similar to what ProvisionalFunctionExpressionLowering is doing
for all function expressions. And since this IR structure is already
supported in FunctionReferenceLowering, the problem in the JVM IR is
fixed without any additional modifications.

However, inliners do not support this IR structure yet, see KT-38535 and
KT-38536.
2020-04-23 16:47:23 +02:00
Jinseong Jeon 39e1635c41 [FIR2IR] Pre-cache original function type parameters for fake overrides 2020-04-23 17:19:44 +03: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
Jinseong Jeon 07add635eb FIR2IR: generate synthetic members for data class only if needed 2020-04-23 13:44:13 +03:00
Mark Punzalan b74652aa5b [FIR] Use ieee754equals for floating-point equality operations 2020-04-23 11:50:54 +03:00
Mads Ager 8bc360fa0c Properly link properties and their getter/setters.
This allows removing a hack in the MethodSignatureMapper.

When introducing non-getter methods that dispatch to a getter
we have to be careful to use the right name.

DeepCopyIrTreeWithSymbols should create the link between new
properties and their new getter/setter.
2020-04-22 16:26:59 +02:00
Georgy Bronnikov 3bb32941a0 IR: bugfix in KotlinNothingValueExceptionLowering 2020-04-21 21:00:16 +03:00
Dmitry Petrov 318d4d17ba KT-38337 Fix inline class value coercion in delegated members 2020-04-21 13:21:58 +03:00
Mikhail Bogdanov d83a35d898 Minor. Update test data to support Corretto JVM 11 2020-04-21 12:03:02 +02:00
Denis Zharkov 6fdbc38cf1 FIR: Fix label/receiver for lambda within infix calls
While this fix only changes label name, it's important for proper
lambda resolution because receiver is set for a lambda
only in presence of a label

This commit fixes a lot of checkType calls in diagnostic tests
2020-04-21 09:52:52 +03:00
Dmitry Petrov 05cb0e8994 KNVE: support in JVM_IR and JS_IR 2020-04-20 20:07:52 +03:00
Mikhail Glukhikh 96d8b0bea3 FIR: make KFunctionX derived from KFunction 2020-04-20 17:05:37 +03:00
Mikhail Glukhikh 4bb6410ce3 [FIR TEST] Temporary ignore overrideDefaultArgument test (KT-38416)
This test enters an infinite loop and can't finish
2020-04-20 17:05:35 +03:00
Mikhail Glukhikh aada7bfe51 FIR: handle suspend functions in callable reference resolve properly 2020-04-20 17:05:31 +03:00
Jinseong Jeon c26adf53dd FIR: resolve suspend lambda properly 2020-04-20 17:05:30 +03:00
Mikhail Zarechenskiy befa1e114c Add tests for obsolete issues
#KT-38092 Obsolete
 #KT-38179 Obsolete
 #KT-35105 Obsolete
 #KT-36696 Obsolete
 #KT-36947 Obsolete
 #KT-37337 Obsolete
 #KT-37309 Obsolete
 #KT-37727 Obsolete
 #KT-37735 Obsolete
 #KT-37853 Obsolete
 #KT-37920 Obsolete
 #KT-37709 Obsolete
 #KT-37706 Obsolete
2020-04-20 04:10:37 +03:00
Georgy Bronnikov 2c4fcebfec IR: handle adapted bound references 2020-04-18 20:31:57 +03:00
Jinseong Jeon 9f1ecadd65 IR: more consolidation of synthetic member generation for data class. 2020-04-17 12:38:38 +03:00
Dmitriy Novozhilov 7f02d57d88 [FIR] Correctly detect super type in delegated constructor call 2020-04-17 12:37:29 +03:00
Georgy Bronnikov 41a28bde5c JVM_IR: repair synthetic accessors to fields 2020-04-16 15:08:11 +03:00
Mikhail Bogdanov 461c368ee0 Minor. Unmute test 2020-04-16 13:49:48 +02:00
Igor Chevdar 6d86d6ccdc [box-tests] Turned on some tests on fun interfaces for JS & Native 2020-04-16 16:01:17 +05:00
Mikhail Zarechenskiy 4ffcbc0c2f [NI] Properly support UnsafeVariance annotation
#KT-38134 Fixed
 #KT-34433 Fixed
 #KT-31823 Fixed
2020-04-16 13:55:47 +03:00
Georgy Bronnikov 611c4fe052 JVM_IR: repair super calls to methods of Any 2020-04-16 10:53:48 +03:00
Dmitry Petrov e2ee3d1d18 Unmute passing tests 2020-04-16 09:07:35 +03:00
Steven Schäfer 74791495d7 JVM IR: Box inline classes in covariant overrides (KT-30419) 2020-04-16 09:07:35 +03:00
Anton Bannykh 81798282b9 JS: support explicit SAM constructor invocation 2020-04-15 17:13:21 +03:00
Mikhail Bogdanov 1de0fbfc3a Add delegation tests for new default modes 2020-04-15 15:25:03 +02:00
Mikhail Bogdanov dda2f53993 Support JVM 8 target on Android 2020-04-15 15:25:02 +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
Steven Schäfer fc7d667282 Psi2Ir: Bind unbound type parameters 2020-04-15 15:32:53 +03:00
Mikhail Bogdanov 10b9ff1066 Minor. Rollback test data change
There is inconsistent behaviour between JS and JVM in case of package presence
2020-04-15 11:04:01 +02:00
Juan Chen a1e0e8b0e7 [FIR] Handle receiver types of extension methods when computing maximally specific types.
Test case (from testPrimitiveReceiver):

fun Short.foo() = 3
fun Int.foo() = 4

1::foo
2020-04-15 11:16:33 +03:00
Dmitriy Novozhilov f7dc06a772 [FIR] Approximate integer constants in lhs of callable reference 2020-04-15 11:13:01 +03:00
Mikhail Bogdanov dec93c8b49 Add ANDROID target 2020-04-14 13:53:22 +02:00
Mikhail Bogdanov b0e72f90f1 Android tests: add reflect flavor 2020-04-14 13:53:22 +02:00
Jinseong Jeon 08b91da6db FIR: fix body generation for data class's copy method 2020-04-14 11:51:30 +03:00
Mark Punzalan d4cbfcb79e [FIR] Promote numeric types during comparisons
Added support for comparing platform types. Extracted logic to convert
operator expressions to OperatorExpressionGenerator.
2020-04-14 11:51:30 +03:00
Roman Artemev 766b8bf74b [KLIB MPP] Mute broken test
- To fix this test `ExpectActualTable` has to be refactored from usage
 of descriptors to IdSignature since Wrapped and Deserialized descriptors
 for the same declaration are not equal to each other.
2020-04-14 11:12:08 +03:00
simon.ogorodnik 356e42196c [FIR2IR] Fix inner class constructor receiver parameter type 2020-04-13 20:26:19 +03:00