Commit Graph

2746 Commits

Author SHA1 Message Date
Nikita Nazarov 407448d8e3 [JVM] Implement new inlined variable naming format
^KT-65478 fixed
2024-02-23 23:59:13 +01:00
Ilya Chernikov eab5164993 Scripting: fix script lowering in case of out of order declarations
The problem was that in K2 for some top-level script declarations we
need to add a dispatch receiver parameter (because frontend do not
assign any, but representing script as a class requires it to be the
script class) and at the same time, calls to these declarations rely on
properly set dispatch receiver parameter.
The simplest solution found is to have an additional traversal on the
relevan top-level declarations and assigning the dispatch receiver,
before running the main transformation.

#KT-64502 fixed
2024-02-23 22:03:44 +00:00
Sergej Jaskiewicz acee8da283 [IR] Move coroutine-related helpers to a more appropriate place
The `isBuiltInSuspendCoroutine` and
`isBuiltInSuspendCoroutineUninterceptedOrReturn` helpers are not
inherently related to function inlining.
2024-02-23 16:26:55 +00:00
Sergej Jaskiewicz 919abe483a [JVM IR] Move CachedSyntheticDeclarations to backend.common
This will allow us to use this class in KLIB-based backends (KT-64865)
2024-02-23 16:26:55 +00:00
Sergej Jaskiewicz 25be39dcc6 [JVM IR] Factor out JVM-specific logic from CachedSyntheticDeclarations
This will allow us to use this class in KLIB-based backends (KT-64865)
2024-02-23 16:26:55 +00:00
Sergej Jaskiewicz d137594c77 [JVM IR] Remove JvmLoweredDeclarationOrigin.SYNTHETIC_MARKER_PARAMETER
There is already a similar origin
`IrDeclarationOrigin.DEFAULT_CONSTRUCTOR_MARKER`
2024-02-23 16:26:55 +00:00
Sergej Jaskiewicz 4325803262 [JVM IR] Move SYNTHETIC_ACCESSOR origin to IrDeclarationOrigin.Companion
We want to generate synthetic accessors not only on JVM (KT-64865),
so this is one of the prerequisites.
2024-02-23 16:26:55 +00:00
Sergej Jaskiewicz 86587a3bf2 [JVM IR] Add KDocs for methods related to synthetic accessor generation 2024-02-23 16:26:55 +00:00
Sergej Jaskiewicz 524dd6794a [JVM IR] Use KDoc in JvmSymbols i/o regular comments when possible 2024-02-23 16:26:55 +00:00
Sergej Jaskiewicz 4f44d32cc2 [JVM IR] Avoid hard-coded checks for coroutine intrinsics
Use existing helpers for that instead, and introduce a new one.
2024-02-23 16:26:55 +00:00
vladislav.grechko f32367d2c2 Fix IrFunction.isEmptyArray implementation
The previous one was incorrect for K1 since parent of top-level function
is `IrClass`, not `IrPackageFragment`.

The change is non-functional, K1 still worked correctly, but had to do
some extra work when inlining `emptyArray` calls and produces less
performant bytecode.
2024-02-22 07:32:36 +00:00
Ilya Chernikov 3ce2172c79 Scripting: refactor script to class lowering
no functional changes, only refactoring to simplify further
modifications
2024-02-21 07:47:15 +00:00
Dmitrii Gridin 072d191306 [compiler] replace Enum values() with entries
To fix warnings. Also, use of `Enum.entries` may improve the performance

^KT-48872
2024-02-20 17:56:46 +00:00
Ivan Kylchik b0171dea63 [IR] Move FunctionInlining into separate module
#KT-64806 Fixed
2024-02-19 20:14:16 +00:00
Ivan Kylchik d0b4ca343b [IR] Move some of extensions from FunctionInlining into IrInlineUtils
#KT-64806
2024-02-19 20:14:16 +00:00
vladislav.grechko d753a22fc6 [FIR] Handle expect declarations in JVM backend
1. Do not generate bytecode for expect declarations

2. Serialize @OptionalExpectation annotations into .kotlin_module file

^KT-62931: Fixed
2024-02-19 18:17:37 +00:00
Alexander Udalov 28797a31b4 JVM: refactor JvmDefaultMode, remove/rename some entries
- remove ENABLE/COMPATIBILITY because they can no longer be used
- remove forAllMethodsWithBody because its behavior is now equivalent to
  isEnabled
- inline isCompatibility
- inline DEFAULT
- rename ALL_INCOMPATIBLE -> ALL
2024-02-06 17:18:44 +00:00
Sergej Jaskiewicz c335cd0b1e [IR] Remove unused IrMessageLogger from serialization logic 2024-01-29 21:07:43 +00:00
Sergej Jaskiewicz f88d09a2f6 [IR] Move KtDiagnosticReporterWithImplicitIrBasedContext to ir.tree
So that it could be accessible from the `ir.serialization.common` module
2024-01-29 21:07:43 +00:00
vladislav.grechko f318b5969d Erase non-reified type parameters by-default when inlining.
Substitution of type arguments to non-reified type parameters may lead
to accidental reification, which should not be done (see ^KT-60174 for
examples). So, we should erase them, except the few cases.

^KT-60174: Fixed
^KT-60175: Fixed
2024-01-26 18:31:20 +00:00
vladislav.grechko 29ecc4d987 Minor: refactor ApiVersionIsAtLeastEvaluationLowering 2024-01-26 18:31:19 +00:00
vladislav.grechko 44caa3cdd5 Do not use dispatch receiver type when calculating method owner
Motivation of using dispatch receiver type when calculating method owner
was discussed here: https://github.com/JetBrains/kotlin/pull/3054

However, this is incompatible with type erasure of non-reified type
parameters on inlining (which will be done in future). Consider the
code:

```
inline fun <T> f(arr:  Array<T>, p: (T) -> Int): Int = p(arr[0])
fun box() = f(arrayOf("abacaba"), String::length)
```

After inlining and erasure, the type of `arr[0]` is `Any`. Thus, when
calculating owner of `String::length` we would have `Any` instead of
`String` if we used dispatch receiver type.

Note, that this change affects bytecode instruction that invokes
method, but does not change which method is being invoked.
2024-01-26 18:31:19 +00:00
Igor Chevdar 978bf3d38d [IR] Refactored a bit InlineFunctionResolver 2024-01-22 09:34:42 +00:00
Igor Chevdar f3a807c507 [IR] Fixed a problem in FunctionInlining
#KT-64868 Fixed
2024-01-22 09:34:42 +00:00
Alexander Udalov b2c30921e4 JVM: support JVM-specific primitive/wrapper type overridability check
#KT-62045 Fixed
2024-01-19 12:30:48 +00:00
Ilmir Usmanov 19283048a8 Replace bytecode text test with a stepping test
#KT-62965
2024-01-19 10:52:39 +00:00
Xin Wang 2e32e13466 JVM Codegen: Mark line number before calling of indy in SAM Conversion
Fixes: KT-62965
2024-01-19 10:52:39 +00:00
Alexander Kuznetsov b828365bb5 ReflectiveAccess: find the exact class the field is declared in
Affects IR Evaluator in IDEA.

The problem is happening because
`ReflectiveAccessLowering#fieldLocationAndReceiver` returns the class
 the field was called on, not the class the field was declared in.

 Then the class is used for obtaining a field by using reflection's
 `getDeclaredField` to make the field accessible after.
 But `getDeclaredField` doesn't work for field declared in a superclass,
 hence the error.

#KT-65012 fixed


Merge-request: KT-MR-13919
Merged-by: Alexander Kuznetsov <Aleksander.Kuznetsov@jetbrains.com>
2024-01-17 11:04:33 +00:00
Ivan Kylchik 8ed7e31b5f [JVM] Validate lowered JVM IR only if it was explicitly requested
This is an addition to the f5bb477459
commit. Earlier, some of the validation checks were moved from
`stickyPostconditions` into separate lowering. But these
post-conditions checks were launched only when several flags were
set to true. In this commit, we just return to such behavior.

#KT-64116
2024-01-16 11:18:21 +00:00
Sergej Jaskiewicz e0cb145c6b [JVM] Split JvmSignatureClashDetector into two classes
One for methods, one for fields.
Later we are going to use the new `SignatureClashDetector` class
for detecting clashes of KLIB signatures.
2024-01-12 15:59:28 +00:00
Sergej Jaskiewicz e0f9e09a97 [JVM] Rename JvmSignatureClashDetector → JvmMethodSignatureClashDetector
This is to preserve the Git history of this file during the subsequent
refactoring.
2024-01-12 15:59:28 +00:00
Sergej Jaskiewicz 3430551681 [IR] Move IrElement#sourceElement to the ir.tree module
This is so that it could be used from more places.
Namely, we need to use it from the `serialization.common` module.
2024-01-12 15:59:28 +00:00
strangepleasures bb8ff9e299 KT-62584 Fix generation of type arguments for local classes
Merge-request: KT-MR-13684
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2024-01-10 14:20:09 +00:00
Alexander.Likhachev 60080e8bb8 [Build] Remove redundant trove4j compileOnly dependencies
^KTI-1135 In Progress
2024-01-10 11:29:25 +00:00
Alexander Udalov dd5fffebf2 JVM: do not generate assertion message for captured fields
#KT-64615 Fixed
2024-01-10 11:10:08 +00:00
Alexander Udalov f01e633f8b JVM: do not put public field access into a single expression block
It affects the `is IrGetField` check in
TypeOperatorLowering.computeNotNullAssertionText, which leads to missing
NPE messages when accessing backing fields of public properties.

 #KT-64615
2024-01-10 11:10:08 +00:00
Alexander Udalov d08c9ba222 JVM IR: transform fake override properties in SAM adapters
Replace every property with its getter and setter. This is needed
because later on, JVM backend assumes that all properties have been
lowered (by JvmPropertiesLowering) to this state.

 #KT-64116 Fixed
2024-01-08 21:31:13 +00:00
Alexander Udalov ee8d42532b Fir2Ir, JVM IR: support flexible Array types loaded from Java
We don't have true flexible types in the IR, but we approximate it with
internal type annotations, such as FlexibleNullability,
FlexibleMutability, RawType. These annotations are then handled
specially in JvmIrTypeSystemContext, which can construct a fake flexible
type so that type checker on IR types would behave exactly as on
frontend types.

As shown in KT-63441, one instance of flexible types where flexibility
was lost during conversion to IR is Java array/vararg types. It's
necessary to support it so that IR fake overrides could be constructed
correctly, because IR fake override checker requires parameter types to
be equal. So this change introduces another internal type annotation,
FlexibleArrayElementVariance, which is only applicable to types with
classifier kotlin/Array, and which signifies that the annotated type
`Array<X>` should rather be seen as `Array<X>..Array<out X>`.

 #KT-63441 Fixed
 #KT-63446 Fixed
2024-01-04 15:54:27 +00:00
Alexander Udalov e98902ce74 Fir2Ir, JVM IR: minor, deduplicate constants for ClassId of special annotations 2024-01-04 15:54:26 +00:00
Sonya Valchuk 588549d1d0 JVM_IR: add offsets to JvmStatic and JvmOverloads proxies
KAPT3 needs them to correct error types in arguments.

 #KT-64639 Fixed
2024-01-02 17:43:09 +00:00
Artem Kobzar da4c6dd443 [K/JS, K/N, K/Wasm] Fix more general case of the ^KT-61929 issue 2024-01-02 12:18:34 +00:00
Mads Ager e41a1247e2 JVM_IR: Generate more line numbers for intrinsic comparisons.
Otherwise, if complex expressions such as when expressions are
used in combination with the intrinsics we get incorrect stepping
behavior.

^KT-64341 Fixed
2023-12-20 15:39:03 +00:00
Ivan Kylchik a441a82357 [JVM_IR] Add some documentation to the IdeCodegenSettings class
#KT-64238 Fixed
2023-12-20 15:02:45 +00:00
Sergej Jaskiewicz 1b557c1657 [IR] Mark IrExpressionBodyImpl with an opt-in annotation
KT-59318
2023-12-19 16:20:02 +00:00
Sergej Jaskiewicz 2096d22e18 [IR] Mark IrBlockBodyImpl with an opt-in annotation
KT-59318
2023-12-19 16:20:02 +00:00
Sergej Jaskiewicz f482b6a458 [IR] Mark IrValueParameterImpl with an opt-in annotation
KT-59318
2023-12-19 16:20:02 +00:00
Sergej Jaskiewicz 28a0d0c6aa [IR] Mark IrEnumEntryImpl with an opt-in annotation
KT-59318
2023-12-19 16:20:01 +00:00
Sergej Jaskiewicz 2fab853700 [IR] Mark IrClassImpl with an opt-in annotation
KT-59318
2023-12-19 16:20:01 +00:00
Sergej Jaskiewicz 8aacb59aec [IR] Mark IrAnonymousInitializerImpl with an opt-in annotation
KT-59318
2023-12-19 16:20:01 +00:00
Ivan Kylchik c902e5f565 [JVM_IR] Allow to use irPluginContext when compiling for android
This problem is extensively described in
`cadbc87dfd1ce3e63481ab90874ca8858878c55f` commit message.
TLDR: compiler is also called from Android LiveEdit plugin where
we want to be able to use compiler plugins. For that reason, we have two
different flags in the compiler. One is only for "evaluate expression"
(`doNotLoadDependencyModuleHeaders`) and the other for both LiveEdit
plugin and "evaluate expression" (`shouldStubAndNotLinkUnboundSymbols)`.
We want to forbid using compiler extensions for "evaluate expression"
and allow for LiveEdit plugin.

#KT-63695
2023-12-08 18:34:36 +00:00