Commit Graph

62 Commits

Author SHA1 Message Date
Alexander Udalov 04c5bbdcf8 JVM IR: change generation scheme of property $delegate methods
Generate $delegate method as instance method in
PropertyReferenceDelegationLowering, and remove dispatch receiver later
in MakePropertyDelegateMethodsStatic. The method needs to be static to
be non-overridable (see delegateMethodIsNonOverridable.kt), and public
to be accessible in reflection.

Otherwise we generated incorrect IR where a static function accessed an
instance field of the containing class, which failed in multiple places
including LocalDeclarationsLowering.

 #KT-48350 Fixed
2021-08-31 14:07:22 +02:00
Dmitry Petrov 851980e36f JVM_IR KT-45103 optimize direct invoke for lambdas and callable refs 2021-05-18 22:20:12 +03:00
Alexander Udalov 401f0ac583 Use TARGET_BACKEND instead of DONT_TARGET_EXACT_BACKEND in box against Java tests
"// TARGET_BACKEND: JVM" more clearly says that the test is
JVM-specific, rather than DONT_TARGET_EXACT_BACKEND which excludes all
other backends.
2021-02-11 13:50:08 +01:00
Dmitriy Novozhilov 29b96aa15d [Test] Properly merge box against java testdata into codegen/box
Previous commit about it was 3199ce03 and it was completely wrong
2021-02-04 10:53:50 +03:00
pyos 41f56729f9 FIR: serialize correct fqnames for local classes 2020-12-10 20:52:48 +03:00
Mikhail Glukhikh fb961f7070 [FIR] Copy also synthetic setter during fake override generation 2020-11-12 13:37:37 +03:00
Mikhail Glukhikh 23e7468e57 [FIR2IR] Cache Java field-based properties more correctly #KT-42805 Fixed
Before this commit, we cached such IR properties by FIR property
which was created by Java field each time when we referenced it.
This led to signature clashes. Now we cache such IR properties
directly by associated FIR field.
2020-10-22 13:05:00 +03:00
Jinseong Jeon 5f64d6ec76 FIR2IR: add support for callable reference to Java field
#KT-42656 Fixed
2020-10-15 08:47:46 +03:00
pyos 1663619606 JVM_IR: add local delegated property metadata to non-synthetic classes
Otherwise kotlin-reflect won't find it (and it won't even be serialized
anyway).

 #KT-42562 Fixed
2020-10-12 21:14:00 +02:00
pyos 6e143a2656 JVM_IR: collect free type parameters when serializing FIR metadata
The "free" in "createFreeFakeLambdaDescriptor" and such refers to the
fact that there are no references to type parameters from outside the
current declaration. This is necessary because at the point where the
metadata is written, the type parameters may not even be in scope (e.g.
local delegated properties are serialized at class level, but may refer
to function-scope type parameters).
2020-09-22 09:35:50 +03:00
pyos aa58ed9234 JVM_IR: partially implement FIR local delegated property reflection
Type parameter references are broken, just like for lambdas. Also, the
code is super ugly.
2020-09-22 09:35:45 +03:00
Jinseong Jeon bff36e0199 FIR2IR: convert annotations on FirTypeRef 2020-07-30 11:25:36 +03:00
Jinseong Jeon ba1172b3ad FIR2IR: distinguish substitution case when adding external fake overrides 2020-06-08 12:11:34 +03:00
Jinseong Jeon 6eb21031b2 FIR JVM serializer: serialize property signature 2020-06-02 12:00:52 +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
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
Jinseong Jeon 08ca6f5f99 [FIR2IR] Set @Metadata when declaring IR symbols 2020-04-06 16:41:57 +03:00
Jinseong Jeon 3e6b38a921 [FIR] Fix type reference for 1st arg of GetClassCall 2020-04-02 12:42:50 +03:00
Mikhail Glukhikh 8231377f6b FIR2IR: convert qualifiers inside getClass properly 2020-03-11 16:01:57 +03:00
Mark Punzalan 9df2f69f09 [FIR] Disable failing blackbox codegen tests for FIR. 2019-11-19 11:00:09 +03:00
Alexander Udalov 4be0e00071 JVM IR: support multi-file classes
Without the `-Xmultifile-parts-inherit` mode for now.

This is implemented as follows: FileClassLowering collects information
about multifile parts and the corresponding facades, which a later
GenerateMultifileFacades phase uses to generate new IrFile instances and
add it to the module fragment that's being compiled.

Note that GenerateMultifileFacades is in the end of lowering phases
because delegates in the facade should be generated for all additional
functions generated by certain lowerings (default arguments,
JvmOverloads, etc.). If GenerateMultifileFacades was right after
FileClassLowering, they would still be generated, but we'd then process
them in lowerings mentioned above, which would result in duplicated
logic in the bytecode. There's a new bytecode text test which checks
that this doesn't happen for functions with default arguments.
2019-08-05 21:27:21 +02:00
pyos 4cd4ea126b JVM_IR: generate more accessors for use in inline functions 2019-05-24 11:27:19 +02:00
Mikhael Bogdanov 007af75e1e Properly calculate call site file in JVM IR inliner 2019-05-21 07:42:16 +02:00
pyos f392b027fa JVM_IR: support references to Java fields 2019-05-15 13:29:48 +02:00
Alexander Udalov 6cc293a0c5 JVM IR: record FIELD_FOR_PROPERTY for property delegates
Delegated properties now have their $delegate fields recorded in the
metadata (in `ClassCodegen.generateField`). This part of metadata is
used by `KPropertyN.getDelegate` functions, so almost all tests on
getDelegate are now unmuted
2019-04-30 13:15:29 +02:00
pyos 8ae9e7a106 JVM_IR: unwrap fake overrides when computing property signatures 2019-04-10 19:21:37 +02:00
pyos ef5e02da84 JVM_IR: handle Nothing and Unit more consistently.
* In blocks, discard the result of any statement that has a return
   type other than void. This was previously done by wrapping each
   statement into an "implicit Unit conversion" that was actually
   compiled down to a stack pop instead. If an expression happened to
   already have type Unit, however, such a conversion was not inserted,
   resulting in a stray reference on the stack. These conversions are
   now redundant and should probably be removed.

 * In assignments and non-exhaustive conditionals, materialize a Unit
   on the stack to avoid depth mismatches that trip up the bytecode
   validator. Because such expressions are generally used at block level
   (and, indeed, the frontend will reject a non-exhaustive conditional
   used as an expression), combined with the above change this results
   in no additional GETSTATIC opcodes, as they are immediately removed
   by the peephole optimizer.
2019-03-26 13:32:02 +01:00
pyos 6c68474489 JVM_IR: use correct signatures for local delegated property references
Which is `<v#N>` where N is the index of that property in the containing
class.
2019-03-19 12:00:29 +01:00
pyos 8c55376f0c Unmute almost all JVM_IR tests that use property references 2019-03-19 12:00:29 +01:00
Alexander Udalov d267f1e875 JVM IR: generate synthetic $annotations methods for properties 2019-02-19 17:25:47 +01:00
Alexander Udalov c92c50aa98 JVM IR: generate JVM signatures of companion object properties 2019-02-19 16:37:47 +01:00
Alexander Udalov c357967c2c JVM IR: generate Kotlin metadata
Introduce MetadataSource as a way to store the original descriptor for
any element (before any lowerings) and maintain it until the end of the
codegen where it's used in generating the metadata. Note that JVM
signatures written to the metadata are formed from the _resulting_
generated elements, not by mapping the original descriptors.

Some corner cases are not supported yet, namely properties declared in
companion objects, synthetic methods for property annotations,
JvmPackageName, etc.

 #KT-29119 Fixed
2019-02-19 16:37:47 +01:00
Alexander Udalov 5c807266f6 JVM IR: fix origin of file class in FileClassLowering
IrDeclarationOrigin.FILE_CLASS is used in CallableReferenceLowering to
generate correct declaration owner.

Many reflection tests start to fail with this commit because they are
now treating callable references to top level declarations as Kotlin
symbols and fail because there's no JVM signature for them; this is
fixed in subsequent commits (previously, they worked because without
Kotlin metadata, these files were treated as Java classes)
2019-02-07 21:23:02 +01:00
Mikhael Bogdanov f2a51d3b80 Support reflection tests on Android 2019-01-26 08:26:49 +01:00
Mikhael Bogdanov 3e6f8db975 Specify JVM target backend for test with 'import kotlin.reflect.jvm' 2018-12-21 16:09:09 +01:00
Mikhael Bogdanov f4e532e449 Specify JVM target backend for test with '@JvmXXX' annotations 2018-12-21 16:09:07 +01:00
Mikhael Bogdanov a8a1bfca72 Specify JVM target backend for test with '// File: *.java' 2018-12-21 16:09:06 +01:00
Georgy Bronnikov 605afbae90 Move fields and init blocks of companions to their owners 2018-10-17 21:15:28 +03:00
Mikhael Bogdanov 2884d728fd Mute/unmute jvm_ir tests 2018-08-01 12:29:24 +02:00
Alexander Udalov 79c2aa4acf Minor, move tests on JvmField into subdirectory 2018-07-18 13:24:45 +02:00
Mikhael Bogdanov bca6b98ea8 Fix test data 2018-07-18 08:41:48 +02:00
Mikhael Bogdanov 1d283d243e Support @JvmField on interface properties
#KT-15807 Fixed
2018-07-16 16:13:15 +02:00
Mikhael Bogdanov e149cbe852 Mute failed jvm ir tests 2018-06-28 12:26:41 +02:00
Alexander Udalov 5d76e463d3 Fix exception from reflection on local delegated properties
The problem was that in JvmSerializerExtension.writeLocalProperties, we
only serialized metadata for local properties, but indices generated in
MemberCodegen.generatePropertyMetadataArrayFieldIfNeeded were among all
delegated properties in the class (not only local). This behaved
incorrectly as long as there was a local and a non-local delegated
property in the same class. For example, if there were 5 non-local
properties and then one local, that local property would get the index 5
and the synthetic signature "<v#5>". But there would only be one
Property entry in the metadata, and so reflection would fail here trying
to load the 5th element of the list which contains only one element.

Now, the index for a local delegated property is computed only as the
number of _local_ delegated properties above it in the class, i.e. the
first local delegated property gets index 0 (and synthetic signature
"<v#0>"), the next one -- index 1, and so on.

 #KT-23413 Fixed
2018-06-14 11:07:26 +02:00
Anton Bannykh 96355e2732 JS IR: mute codegen box tests automatically 2018-06-09 19:15:38 +03:00
Alexander Udalov 60c735f2fd Do not use deprecated kotlin.reflect API 2017-09-12 15:08:21 +03:00
Alexander Udalov 593d6b7a95 Minor, do not use ".java.kotlin" on KClass instances 2017-09-12 15:02:25 +03:00
Alexander Udalov 4d2fbf1801 Fix reflection for local delegated properties inside interface
#KT-19690
2017-08-17 15:35:11 +02:00