Commit Graph

101542 Commits

Author SHA1 Message Date
Marco Pennekamp bb7625c5b0 [LL FIR] KT-58325 Fix test library discoverability for combined Kotlin symbol providers
- An LL FIR test failed after merging stub-based deserialized symbol
  providers into combined Kotlin symbol providers:
  `DiagnosticCompilerTestFE10TestdataTestGenerated.TestsWithStdLib.Multiplatform.testJvmOverloads`
- Cause: The combined Kotlin symbol provider was able to find a class
  for `JvmOverloads`. However, the `KtModule` of `JvmOverloads` was
  `LibraryByRoots` with just the stdlib, while the registered stub-based
  deserialized symbol provider was known to the combined symbol provider
  with a `LibraryByRoots` containing 6 different paths. Hence, the
  single-root module wasn't found in the provider map.
- The fix creates a `LibraryByRoot` for each root, which leads to a
  separate deserialized symbol provider for each of the six roots,
  solving the discoverability problem.
2023-05-31 18:34:41 +00:00
Marco Pennekamp accc9b0eb3 [FIR/LL FIR] Introduce FirSymbolNamesProvider
- In LL FIR, we have increasingly formalized symbol name caches as
  palpable objects. The main reasons for this formalization were the
  need to share implementations of caching between different (LL FIR)
  symbol providers, the need to build composite name caches from
  individual name caches, and the introduction of resolve extensions
  which may provide additional declarations and thus complicate the name
  set construction for Kotlin symbol providers in LL FIR.
- `LLFirSymbolProviderNameCache` also shared a lot of similarities with
  cache handling in FIR providers like
  `FirCachingCompositeSymbolProvider` and
  `AbstractFirDeserializedSymbolProvider`.
- This commit introduces a `FirSymbolNamesProvider` as a component of
  `FirSymbolProvider`. This symbol names provider's task is to provide
  the sets of names which `FirSymbolProvider` previously provided. It
  also allows sharing implementations of `mayHaveTopLevel*` once and for
  all, which is an improvement over the previously scattered
  implementations (the same ideas replicated many times throughout
  different symbol providers).
- `FirSymbolNamesProvider` by design doesn't cache, as many symbol
  providers may not need such a cache. `FirCachedSymbolNamesProvider`
  can be used to cache symbol names if needed. The symbol name provider
  architecture also makes it easier to switch between caching and
  non-caching, without the need to reimplement caches every time.
- Synthetic function types complicate the picture, but this complication
  is now exposed with the rest of the API, instead of being hidden in a
  few implementations here and there. This allows symbol providers to
  more explicitly state whether they can provide generated function
  types, which is an advantage for the correctness of composite symbol
  providers.

Some specific notes:

- In `FirSyntheticFunctionInterfaceProviderBase`, the class ID check has
  been replaced with a full `mayHaveTopLevelClassifier` check so that
  the cache doesn't get filled with `null` entries.
- `LLFirKotlinSymbolProviderNameCache` is turned into a non-caching
  `LLFirKotlinSymbolNamesProvider` so that this symbol names provider
  and those of resolve extensions can be composed into one caching
  symbol provider in `LLFirProviderHelper` without creating layers of
  caches. If the Kotlin symbol names provider was caching out of the
  box, `LLFirProviderHelper.symbolNameCache` would cache the
  names (1) in the combined symbol names cache and (2) in the Kotlin
  symbol names cache.
  - A caching Kotlin symbol names cache can still be created easily with
    the `LLFirKotlinSymbolNamesProvider.cached` constructor function.
2023-05-31 18:34:41 +00:00
Marco Pennekamp b82a589e56 [LL FIR] KT-58325 Implement JvmStubBasedFirDeserializedSymbolProvider as LLFirKotlinSymbolProvider
- This enables merging `JvmStubBasedFirDeserializedSymbolProvider`
  into `LLFirCombinedKotlinSymbolProvider` automatically.
- Crucially, we have to also allow callable caches to take already found
  callables as a context.
- We can also simplify the name cache boilerplate using
  `LLFirKotlinSymbolProviderWithNameCache`.
2023-05-31 18:34:41 +00:00
Marco Pennekamp 3322ec9dd9 [LL FIR] KT-58325 Base LLFirCombinedKotlinSymbolProvider on LLFirKotlinSymbolProvider 2023-05-31 18:34:41 +00:00
Marco Pennekamp f4d3cceabd [LL FIR] KT-58325 Introduce LLFirKotlinSymbolProvider
- `LLFirKotlinSymbolProvider` is a shared interface for any symbol
  providers that are based on `KotlinDeclarationProvider`.
- `LLFirKotlinSymbolProviderWithNameCache` simplifies symbol provider
  implementations which use a `LLFirSymbolProviderNameCache`.
  - Note that the domain is not limited to "Kotlin symbol providers",
    but I don't want to introduce a general base class like
    `LLFirSymbolProviderWithNameCache` without multiple class
    inheritance (think Scala traits).
  - It would be possible to use delegation instead of such a base class,
    but that would require a shared interface for the "package name"
    functions, which would require some compiler refactoring as well.
- We can base `LLFirProvider$SymbolProvider` on
  `LLFirKotlinSymbolProvider`.
- The callables functions in `LLFirKotlinSymbolProvider` expect
  `KtCallableDeclaration`s instead of `KtFile`s. This is the preferred
  interface, because callable files are only needed for `LLFirProvider`,
  not Kotlin symbol providers in general (such as the stub-based
  deserialized symbol provider). This also has the advantage that FIR
  files containing only properties won't be built for
  `getTopLevelFunctionSymbolsTo` and vice versa.
2023-05-31 18:34:41 +00:00
Marco Pennekamp 29f7e922f6 [LL FIR] Polish documentation of LLFirSymbolProviderNameCache 2023-05-31 18:34:41 +00:00
Marco Pennekamp 63f29b5d24 [LL FIR] Add top-level callable package name set support to LLFirSymbolProviderNameCache
- `KotlinDeclarationProvider` supports computing the top-level callable
  package name set now, so we can propagate it to the symbol name cache
  implementation.
- Adds the package name check to `getTopLevelCallableNamesInPackage`
  directly, which will likely reduce the size of
  `topLevelCallableNamesByPackage`, because it needs to store fewer
  empty sets.
2023-05-31 18:34:41 +00:00
Brian Norman e10a9263d0 [FIR] Only inherit class type parameters if inner class
Nested classes which are not inner class should not be able to access
type parameters of the outer class. Make sure access is not available
when resolving super types.

#KT-54748 Fixed
2023-05-31 16:25:51 +00:00
Anton Lakotka dfae730d0f [Gradle] Update kotlin-gradle-plugin.api after removing
unused defaultConfigurationName

^KT-55201 Verification Pending
2023-05-31 15:45:26 +00:00
Anton Lakotka b96e5a2a93 [Gradle] Remove defaultConfiguration from ExternalKotlinTargetImpl
^KT-55201 Verification Pending
2023-05-31 15:45:25 +00:00
Anton Lakotka 67a511544c [Gradle] Remove defaultConfigurationName
^KT-55201 Verification Pending
2023-05-31 15:45:25 +00:00
Ivan Kochurkin 2251214d24 [FIR] Don't crash on complex expression as annotation argument if metadata compilation is used
^KT-58139 Fixed
2023-05-31 14:38:38 +00:00
Ivan Kochurkin abdb173f6c Add AnalysisFlags.metadataCompilation flag
It's `true` if metadata compilation mode is activated

It's being initialized in K2MetadataCompilerArguments
2023-05-31 14:38:38 +00:00
Alexander Shabalin 2364ffb299 [K/N] Remove diagnostics about old Native GC ^KT-58853 2023-05-31 14:29:17 +00:00
Roman Efremov d2eb4a0abf [FE] Prohibit default arguments in expect declarations actualized via typealias
Cases when default argument inhertied from super class are allowed.

Some tests for default arguments already exist and can be found in
`testData/diagnostics/tests/multiplatform/defaultArguments`, for example
`annotationsViaActualTypeAlias.kt`.

^KT-57614 Fixed

Merge-request: KT-MR-10356
Merged-by: Roman Efremov <Roman.Efremov@jetbrains.com>
2023-05-31 13:14:37 +00:00
Ilya Kirillov 9829a2bf98 [LL FIR] fix contract violation exception from Java Resolution
When we create `SmartTypePointer` directly inside `JavaSymbolProvider`,
the Java resolution is called which is forbidden inside the
`JavaSymbolProvider`.

Instead, the lazy `JavaElementTypeSource` for JavaType is created,
which creates a `SmartTypePointer` outside `JavaSymbolProvider`.

^KT-58194
2023-05-31 13:01:19 +00:00
Ilya Kirillov 2d08d29dac [Java Resolution] use a smart psi pointer to store PSI in JavaElement for IDE
`JavaElement`s are reused between read actions, so underlying PSI elements might be invalidated when using hard PSI references

^KT-58194 fixed
2023-05-31 13:01:19 +00:00
Ilya Kirillov c114cb67cb [Java resolution] make it possible to provide custom source element for JavaElement
This is needed to allow using PSI pointers in IDE in JavaElement.
`JavaElement`s are reused between read actions,
so underlying PSI elements might be invalidated when using hard PSI references

^KT-58194
2023-05-31 13:01:19 +00:00
Ilmir Usmanov a41d36edba JS IR: Minor. Disable test 2023-05-31 11:21:39 +00:00
Igor Yakovlev 53783daeaf Codereview 2023-05-31 10:46:24 +00:00
Igor Yakovlev 39c8d5759b Codereview 2023-05-31 10:46:24 +00:00
Igor Yakovlev c71a2c6dd3 Codereview 2023-05-31 10:46:24 +00:00
Igor Yakovlev 78b72efd32 [Wasm] Make Arrays' constructors with size and lambda inline
Fixed #KT-58746
2023-05-31 10:46:24 +00:00
Anna Kozlova 1d5c080dd8 [AA] calculate ktType based on symbols when possible
then, for compiled code deserialized fir would be used instead of building
decompiled text and consequence building and resolving of raw fir;

type for ktTypeReference from compiled code is called e.g., by UAST inspections
when they check annotations of the called function parameters
2023-05-31 06:26:28 +00:00
Ilmir Usmanov d7fd2471b8 JVM IR: Remove remains of 1.2 coroutines from tests
Remove CoroutineAdapter and LANGUAGE: +ReleaseContinuation,
which are meaninless now.
Update the tests accordingly.
2023-05-31 05:56:18 +00:00
Vladimir Sukharev ebc4cf7f96 [K/N] Normalize klib paths for KonanLibraryImpl
^KT-58979 Fixed

Merge-request: KT-MR-10372
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-05-31 04:53:58 +00:00
Ilya Gorbunov e11ebcadb4 Test refactor: extract big duration adjustment to a separate test 2023-05-31 04:45:15 +00:00
Ilya Gorbunov f8f3862f0c Make TimeMark adjustment test more stable 2023-05-31 04:45:15 +00:00
Sergej Jaskiewicz fd76a34277 [IR] Don't print flags in declaration references in irText tests
This doesn't reduce the quality of tests, because the flags are still
printed for declarations themselves. We only omit them in references.

However, this makes the tests more compatible with non-JVM backends
(see KT-58605), because flags of referenced stdlib declarations may
differ among target platforms.
2023-05-30 17:26:30 +00:00
Anna Kozlova b8e868caf6 [decompiler] navigate to containing class for fake object descriptors
^ KTIJ-25661
2023-05-30 17:23:54 +00:00
Kirill Rakhman 793e3552e7 [FIR] Add tests for K2-only suspend operators get/set/contains
#KT-57169
2023-05-30 16:48:53 +00:00
Kirill Rakhman ca022cf4dc [FIR] Forbid suspend operator get/setValue and provideDelegate
#KT-58989 Fixed
2023-05-30 16:48:53 +00:00
Alexander Shabalin aea8bac7d2 [K/N] Do not compile for deprecated targets and legacy MM
^KT-56533
^KT-58853
2023-05-30 16:44:58 +00:00
Kirill Rakhman d1ce55cbd2 [FIR2IR] Fix infinite loop between annotation and annotation parameter
When an annotation constructor value parameter is annotated with the
very same annotation, FIR2IR went in an infinite loop when trying
to generate it.
To fix this, the constructor is added to the Fir2IrDeclarationStorage
cache before generating the value parameters.
To accommodate for the missing parameters, the value arguments count
is determined using the FIR.
2023-05-30 15:53:12 +00:00
Ivan Kylchik fc75402f65 [IR] Add test to specify new logic of enum initialization with name call
#KT-58948
#KT-57538
2023-05-30 15:28:04 +00:00
Alexander Udalov 60016d3e5b Remove obsolete compiler flag -Xuse-ir 2023-05-30 14:46:09 +00:00
Alexander Udalov 2951e0b955 Rename/remove some compileKotlinAgainstCustomBinaries tests
"oldJvm*" tests are no longer testing the old JVM backend, so remove
that prefix from them. Also, remove the test "firAgainstOldJvm" because
it is now checking something that cannot NOT work.
2023-05-30 14:46:09 +00:00
Alexander Udalov bb4bb58453 Remove tests on -Xuse-ir compiler flag
This flag is going to be removed because old backend is not supported
anymore, therefore there's no need to test it.
2023-05-30 14:46:09 +00:00
Leonid Startsev 22096cec3c Make changelog for kotlinx-metadata-jvm 0.6.1 release
Note: actual release is done from 1.8.20 branch (commit 0043ae4390c8555b03428a014b660f395b924695)
2023-05-30 14:27:45 +02:00
Kirill Rakhman bc602b3827 [FIR] Reproduce #KT-58939 2023-05-30 11:59:57 +00:00
Kirill Rakhman cf2ef443f4 [FIR] Introduce a feature flag for context-sensitive enum resolution
The feature was previously enabled unconditionally in K2 which
triggered a bug when an enum has an entry with the same name as itself.

#KT-58897 Fixed
#KT-52774
2023-05-30 11:59:56 +00:00
Yahor Berdnikau 4b643480d6 [Gradle] Fix spelling errors in tryK2 report
^KT-58869 Fixed
2023-05-30 11:24:16 +00:00
Denis.Zharkov a9352abb93 K2: Optimize JvmMappedScope.processFunctionsByName for final classes 2023-05-30 10:44:41 +00:00
Denis.Zharkov 6683e229b4 K2: Simplify JvmMappedScope-related code a bit
JvmMappedScope.Signatures became mostly irrelevant and only
"useful" for checking if we really need to have the scope mapped

Now, the check is rewritten according to K1 semantics

^KT-57694 Fixed
2023-05-30 10:44:41 +00:00
Denis.Zharkov 6b1d9c4d56 K2: Adjust how additional built-in constructors from JDK are handled
This change is both makes code more consistent with K1 version
and fixes some issues introduced by previous changes

Before this fix, the test
FirPsiOldFrontendDiagnosticsTestGenerated$Tests$Modifiers$Const.testKCallable_after
was failing

^KT-57694 In Progress
2023-05-30 10:44:41 +00:00
Denis.Zharkov e4480a1c52 K2: Refine mapping of primitive arrays to JVM descriptor
Earlier, it wasn't really important but after the previous commit
when JvmMappedScope semantics has been changed, we erroneously
started loading `toCharArray` as a member to String because
its jvmDescriptor was computed to "toCharArray()Lkotlin/CharArray",
while hardcoded information that prevents it from loading expect
"toCharArray()[C" there.

^KT-57694 In progress
2023-05-30 10:44:41 +00:00
Denis.Zharkov 2e5b783cc6 K2: Refine how JDK members are mapped to built-in classes
Previously, the semantic was more-or-less correct for most of the cases
but some corner one, like `sort` in MutableList didn't work properly.

Namely, `sort` should be marked there in a way to forbid to call it
everywhere beside super-calls.
Also, overriding it should be allowed.

Mostly, the logic was re-written to K2 model from K1-related
JvmBuiltInsCustomizer.

^KT-57694 In progress
^KT-57269 Fixed
2023-05-30 10:44:41 +00:00
Dmitriy Dolovov 161fe1d2ca [IR] Don't produce gaps for skipped IR declarations during serialization 2023-05-30 10:14:08 +00:00
Kirill Rakhman a4c9a4f150 [FIR] Use optimized stdlib version of reversed list 2023-05-30 09:22:50 +00:00
Alexander Korepanov 8066f1b7d2 [JS IR] Do not copy interface method if base class inherits it
^KT-58599 Fixed
2023-05-30 08:22:43 +00:00