Commit Graph

1550 Commits

Author SHA1 Message Date
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
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
Ivan Kylchik 35b13775d8 [IR] Move declaration of origins for IR inliner into LoweredStatementOrigins
#KT-64806
2024-02-19 20:14:16 +00:00
Marco Pennekamp d121b529b5 [IR] Remove strong references to IR entities in CompilationException
- `CompilationException` should not strongly reference `IrFile`s and
  other IR elements, which in turn reference FIR elements strongly. It
  can lead to a memory leak in the IDE as the exception is held
  statically in the IDE's `MessagePool`.
- I considered fixing this on the level of `KtCodeCompilationException`
  from the Analysis API, but:
  1. `KtCodeCompilationException` can wrap many kinds of exceptions.
     Snapshotting the cause only for `CompilationException` (somewhere
     down the cause chain) would be messy, as it'd require traversing
     the cause chain and referencing `CompilationException` directly,
     breaking API boundaries.
  2. Keeping the same level of report quality while snapshotting a cause
     is not trivial.
  3. Exceptions in general should be as lean as possible, so it makes
     sense to fix `CompilationException` itself.

^KT-65655 fixed
2024-02-09 13:12:40 +00:00
Igor Chevdar 6c05219485 [IR][K/N] Extracted explicit var spilling phase from coroutines lowering
Not only does it give some flexibility but also it could be turned off
in the future (by providing trivial replacement) as a workaround

 #KT-65153
2024-02-07 18:54:31 +00:00
Igor Chevdar 954eade78c [IR][K/N] Refactored a bit SuspendFunctionLowering 2024-02-07 18:54:31 +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 cb43f3c805 Fix Symbols::isTypeOfIntrinsic implementation
Function did not work as expected for JVM backend
2024-01-26 18:31:19 +00:00
Igor Chevdar 006410641b [IR][K/JS] Removed unused function 2024-01-22 09:34:42 +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
Sergej Jaskiewicz c800144025 [IR] Add a new method to the IrDiagnosticReporter interface 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
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
Igor Chevdar aaf34c3436 [IR] Fixed a bug with local classes extraction from lambdas
#KT-64508 Fixed
2024-01-04 11:15:18 +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
Igor Chevdar 69459b056e [IR] Correct handling of loops in liveness analysis
#KT-64139 Fixed
2023-12-18 12:55:51 +00:00
Ilmir Usmanov 32e43998a0 IR: Restore method used by Anvil annotation processor
But make it hidden, so, the new method will be used instead
 #KT-62281
2023-12-06 09:52:07 +00:00
Dmitriy Novozhilov 159bc1b435 [IR] Introduce API to register generated IR declaration to be present in metatada
KT-63881
2023-12-05 10:21:38 +02:00
Dmitriy Novozhilov 1cdc8361d6 [IR] Rename IrAnnotationsFromPluginRegistrar to IrGeneratedDeclarationsRegistrar
In further commits, this service will be used not only for registering
  annotations, but newly generated IR declarations too
2023-12-05 10:21:27 +02:00
Artem Kobzar 33ab1871c7 [K/JS] Fix coroutines but turn back the fix for coroutines intrinsics intercepted and releaseIntercepted 2023-11-22 18:10:08 +00:00
Pavel Kunyavskiy 55e7ff18c6 [IR] Extract IrActualizationErrors from CommonBackendErrors
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 763d2ec2fe [IR] Move IrGetValue.actualize() to IrUtils and rename it
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy e80d4b1d60 [IR] Move IrDeclaration.isExpect to IrUtils
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 41098a2e34 [IR] Extract IrDiagnosticReporter interface
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy faaefbd8e7 [IR] Move .parents and .parentsWithSelf to IR utils
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 649a7bd66b [IR] Moved actualizer and related things to separate module
^KT-62292
2023-11-20 08:31:41 +00:00
Artem Kobzar e64068cf82 [K/JS, K/Wasm, K/Native] Process anonymous initializers inside classes as a part of their primary constructors ^KT-61929 Fixed 2023-11-17 13:04:34 +00:00
Ivan Kylchik af716b2e3e [IR] Add KDoc for PhaserState, CompilerPhase and PhaseConfig classes 2023-11-16 12:03:41 +00:00
Artem Kobzar bec434d534 [K/JS] Save nullability from the original type of value parameters ^KT-63013 Fixed 2023-11-14 10:40:07 +00:00
Iaroslav Postovalov a3b55cf758 [IR] Drastically simplify the hierarchy of IR origins
IrStatementOriginImpl and IrDeclarationOriginImpl were made final
classes to simplify the creation of them (a delegate provider was
added) and to optimize performance when comparing the origins by type
and name
2023-11-13 17:56:09 +00:00
Nikita Bobko e13ebe8474 [FIR, IR] 1/2 Refactoring: propogate LanguageVersionSettings to areCompatibleCallableVisibilities
This refactoring is needed for KT-61955
2023-11-07 15:53:54 +00:00
Nikita Bobko 92850dcc84 [FIR, IR] Cleanup: convert vector of actuals to scalar of a single actual in AbstractExpectActualChecker
Review: https://jetbrains.team/p/kt/reviews/12750/timeline

`AbstractExpectActualChecker` works on pairs obtain from
`AbstractExpectActualMatcher` and the last one always returns single
actual for single expect. That's why handling of multiple actuals
doesn't make sense
2023-11-06 14:41:25 +00:00
Nikita Bobko b331726c6e [FIR, IR] Cleanup: drop redundant enumConstructorsAreAlwaysCompatible
It's constantly true in FIR and IR (it was false in K1)

Also see: 8b9079d026

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:24 +00:00
Nikita Bobko 75a0442b61 [FIR] 2/2 Cleanup: drop no longer necessary FirActualCallableDeclarationChecker
It became possible to drop it after KT-62590. Now, on a frontend, the
return type check is part of a common AbstractExpectActualChecker logic

Change in nestedAnnotationClassViaActualTypealias.fir.kt aligns the
behaviour with K1. KT-61964

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:23 +00:00
Nikita Bobko a9583e4f9a [FIR, IR] 1/2 Align FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes with ExpectActualUtilsKt.areCompatibleExpectActualTypes
Those two functions are copy-paste of each other. They diverged since
the time they were copy-pasted. This commit makes
FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes
up-to-date.

I didn't update ExpectActualUtilsKt.areCompatibleExpectActualTypes
because I will drop it in the next commit.

Change in `dynamicTypesEqualToAnything` doesn't change any logic (yet.
This change in logic will take effect in the next commit), because:
1. `dynamicTypesEqualToAnything` is only changed in
AbstractExpectActualChecker.getCallablesCheckingIncompatibility. But
AbstractExpectActualChecker.getCallablesCheckingIncompatibility doesn't
check return types on frontend (it only check return types on backend).
2. `dynamicTypesEqualToAnything` is ignored on IR backend

I have no idea what is the difference between `createTypeCheckerState()`
and `actualSession.typeContext`, but it aligns these copy-pasted
versions and makes the tests behave like in K1 (at least
'typeUsageWithUnresolvedReference' and 'kt57320' are affected)

This commit is mainly a preparation for the next commit.

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:23 +00:00
Nikita Bobko ddc1ae9ac6 [IR] Split INCOMPATIBLE_MATCHING to EXPECT_ACTUAL_MISMATCH & EXPECT_ACTUAL_INCOMPATIBILITY
KT-62590

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:22 +00:00
Nikita Bobko dab69e38c4 [FIR, IR] AbstractExpectActualChecker: drop redundant code
- getCallablesStrongIncompatibility is unused (because it moved to the
  "matcher" KT-62590)
- `checkClassScopesCompatibility` parameter is always `true` or unused

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:22 +00:00
Nikita Bobko 8722e142f6 [IR] 2/2 Propogate expect-actual checker incompatibilities to IR backend
Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:20 +00:00
Nikita Bobko eb0c8c00c3 [FIR, IR] 1/2 Minimize usages of ExpectActualCompatibility, MismatchOrIncompatible and MatchedOrCompatible
- Migrate ExpectActualCompatibility -> ExpectActualCheckingCompatibility
  where the "checker" is expect
- Migrate ExpectActualCompatibility -> ExpectActualMatchingCompatibility
  where the "matching" is expect

KT-62590 in progress. A lot of tests start to fail now. I will fix them
in next commits

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:19 +00:00
Nikita Bobko 664b9cc3ba [FIR, IR] ClassScopes incompatibility: split unfulfilled incompatibilities into "mismatchedMembers" and "incompatibleMembers"
KT-62590 is in progress

Unfortunatelly, ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT is now reported
twice in 'classScopeViaTypealiasIncompatible' test.

We had a duplicated diagnostic in other cases before my commits, anyway.
it will be fixed in
https://youtrack.jetbrains.com/issue/KT-62559/KMP-K2-prevent-reporting-ACTUALANNOTATIONSNOTMATCHEXPECT-twice-in-CLI#focus=Comments-27-8293687.0-0

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:19 +00:00
Nikita Bobko d0b34fe378 [FIR, IR] Refactor: restructure ExpectActualCompatibility class hierarchy
KT-62590 is in progress

This commit is pure refactoring.
- No tests changed their behaviour
- Semantics isn't changed

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:18 +00:00
Nikita Bobko 1c6e529146 [FIR, IR] Rough split of AbstractExpectActualCompatibilityChecker into matcher & checker
This commit:
1. renames AbstractExpectActualCompatibilityChecker to AbstractExpectActualChecker
2. `cp compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualChecker.kt compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualMatcher.kt`
   + rename the object in AbstractExpectActualMatcher.kt
3. KDocs

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:17 +00:00
Nikita Bobko 4ef8595a4b [IR] Don't check class scopes compatibility in collectActualCallablesMatchingToSpecificExpect
This is a minor optimization.
This commit is a step forward for KT-62590

Conceptually, `checkClassScopesCompatibility` belongs to the
"expect-actual checker". It doesn't belong to the "expect-actual
matcher".

- `checkClassScopesCompatibility` should be set to `true` when you want
  to do the "checking"
- `checkClassScopesCompatibility` should be set to `false` when you want
  to do the "matching"

`collectActualCallablesMatchingToSpecificExpect` only needs the
"matching"

No tests changed their behaviour

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:17 +00:00
Alejandro Serrano Mena 312187dbe6 [IR] Improve error messages for constant evaluation error 2023-11-03 14:54:48 +00:00
Ivan Kylchik 32057f6d10 [JVM_IR] Use createSimpleNamedCompilerPhase to create lowerings 2023-11-01 14:01:17 +00:00
Ivan Kylchik f5bb477459 [JVM_IR] Move all stickyPostconditions into single lowering
`stickyPostconditions` are such conditions that are checked
every time after applying when a new lowering finishes its execution.
Right now we are using them only in JVM, and this is a blocker
for adopting Native approach for lowering execution.

In Native we are using
`SimpleNamedCompilerPhase<in Context : LoggingContext, Input, Output>`
as the common super type for all lowerings. Here we have `Input` and
`Output` that can potentially be different and `stickyPostconditions`
don't have much sense in that case.
2023-11-01 14:01:17 +00:00