Commit Graph

107649 Commits

Author SHA1 Message Date
Yan Zhulanow 1b7d1dd08a [Analysis API] Simplify 'getNotUnderContentRootModule()'
In the resulting implementation of dangling file modules,
'getNotUnderContentRootModule()' is never called with a not-null file.
2024-01-05 16:04:14 +00:00
Yan Zhulanow bed73fd650 [Analysis API] Collect designations only for autonomous declarations
Parameters, type parameters, and property accessors are not
self-sufficient declarations (their resolution depends on resolution
of their parent), so a proper designation path cannot be computed
for them.

Without a designation path, 'ContextCollector' performs analysis of the
whole file, which is inefficient.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 4a2f11b2f5 Revert "Revert "KT-61890 [AA] Use ContextCollector in KtFirScopeProvider""
This reverts commit 644e29a2ea.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 3761c1051d [Analysis API] Use ContextCollector in 'KtFirCompletionCandidateChecker' 2024-01-05 16:04:14 +00:00
Yan Zhulanow f14a67cb7d [Analysis API] Support IGNORE_SELF in containing declaration provider 2024-01-05 16:04:14 +00:00
Yan Zhulanow 957617081f [Analysis API] Refactor 'KtFirSymbolContainingDeclarationProvider'
Move out logic for dependent (not self-sufficient) declarations, as
well as for declarations, parents of which are only computed using PSI.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 452d22e14f [Analysis API] Add IGNORE_SELF dangling file resolution mode
In the 'IGNORE_SELF' mode, dangling files don't have their own
declarations in providers. As a result, all references there resolve to
declarations of the original file. It is conceptually similar to that we
had in on-air resolve, however, now it's possible to work with the whole
content of the in-memory 'FirFile'.

As it can be seen in 'ProjectStructureProvider.kt'
(KtFile.danglingFileResolutionMode), the 'IGNORE_SELF' mode is
automatically applied for non-physical files with an original file being
set. For other scenarios, now there is a new 'analyzeCopy()' function
that allows to pass the analysis mode explicitly.
2024-01-05 16:04:14 +00:00
Yan Zhulanow ae6b690d4f [Analysis API] Invert the 'isAutonomousDeclaration' flag 2024-01-05 16:04:14 +00:00
Yan Zhulanow 087398edd7 [Analysis API] Do not force session creation in 'LLSessionProvider' 2024-01-05 16:04:14 +00:00
Yan Zhulanow 6bbd252c07 [Analysis API] Implement separate caching for unstable dangling files
PSI events do not arrive for dangling files with no backing
'VirtualFile', so its partial invalidation becomes non-trivial.
In the change, a short-living cache is implemented for these 'unstable'
dangling files.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 9c91158be6 [Analysis API] Add tests for dangling files 2024-01-05 16:04:14 +00:00
Yan Zhulanow 2899822102 [Analysis API] Extract dangling file module computation
Use the same code for creating dangling file modules inside tests,
the stand-alone API, and in the IDE.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 441f3e0209 [Analysis API] Give a standalone module provider a better naming
Some components in Analysis API have the 'Impl' suffix both in test
and standalone environments. This commit fixes the logical ambiguity
for a project structure provider.
2024-01-05 16:04:14 +00:00
Yan Zhulanow a614d0325f [Analysis API] Move test-only project provider closer to tests 2024-01-05 16:04:14 +00:00
Yan Zhulanow f0a21654f8 [PSI] Allow to create contextual 'KtPsiFactory' with eventSystemEnabled
The change allows creating trackable in-memory files, which are useful
for intention preview.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 7944602066 [Analysis API] Rework in-block modifications for dandling file modules
Before the change, all code fragment sessions were invalidated on any
PSI change. It was a simple solution, though not very effective.
Fragments were invalidated not only on a physical module change, but
also on change in another, unrelated code fragment.

As code fragment sessions were reworked to support also ordinary '.kt'
files, the old logic started to have even less sense, because ordinary
dangling files do not have a context element (they only have a context
module).

Currently, code fragment sessions are invalidated on any change in a
physical (non-dangling) module, and are also invalidated on any change
in their contextual dangling module, if any. With some work, this can be
improved further, so code fragments will be invalidated only on changes
in modules they depend on.

Relevant tests can be found in the IntelliJ project
(DanglingFileModuleInvalidationTest).
2024-01-05 16:04:14 +00:00
Yan Zhulanow 432884fe84 [Analysis API] Use resolution components from the same session
In 'getFirForNonBodyElement()', a wrong 'FirProvider' was used for
elements from modules other than a use-site one, and it could lead to
"Modules are inconsistent" exceptions from 'LLFirFileBuilder'.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 297920fde9 [Analysis API] Support dangling file copies in 'KtFirVisibilityChecker'
Dangling files are copies of files in the context module, or just
depend on it. In any way, dangling file modules see all internals of
the context module.
2024-01-05 16:04:14 +00:00
Yan Zhulanow b7c774b9e5 [Analysis API] Generify 'KtCodeFragmentModule' to support ordinary files
This commit introduces dangling file modules, which may be either
code fragments or ordinary Kotlin files. As before, code fragments are
analyzed against some context element, however ordinary files only
have a context module.

Code fragments can also have a dangling file module as a contextual one,
including other code fragment. This is done to support potential usages
in completion, intentions and refactorings.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 916e46debe [Analysis API] Provide sessions in 'LLFirModuleData' for dependencies
Normally, 'bindSession()' is called on a 'FirModuleData' right after its
instantiation to make it fully initialized. For source sessions,
this is done directly during the session creation. However, module data
created for dependencies (see 'LLFirModuleData.dependencies' & friends)
stay uninitialized, breaking 'collectAllDependentSourceSessionsTo()'.
2024-01-05 16:04:14 +00:00
Yan Zhulanow c7aedd932c [Analysis API] Support compiler plugins in code fragments
Compiler plugins are currently only supported in source modules.
This commit makes them also available in code fragments with source
context.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 5179462632 [Analysis API] Support non-JVM platforms in code fragments
The 'evalJs' test is not available, as there is no proper support for
klib loading in non-standalone Analysis API yet.

^KT-64197 Fixed
2024-01-05 16:04:14 +00:00
Yan Zhulanow 75abae23d8 [Analysis API] Fix WITH_STDLIB for common modules in Analysis API tests
The previous implementation in 'TestModuleStructureFactory' had very
custom and redundant logic for binary dependency collection.
In particular, JDK and kotlin-stdlib were specifically computed,
although both already were in the module classpath, which was handled in
'createLibrariesByCompilerConfigurators()'. In addition, there was no
support for common modules.

The new behavior is much closer to what happens in production.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 1a5b9ad79c [Analysis API] Support multi-module projects in compiler facility tests 2024-01-05 16:04:14 +00:00
strangepleasures 894df8f641 KT-64719 K2 KAPT stub generation should fail on syntax errors 2024-01-05 15:58:41 +00:00
Marco Pennekamp bace053ea9 [AA decompiler] Store sealed modifiers in interface stubs
- If the `sealed` modifier is not kept in the interface's stub, a
  sealed interface will have an `abstract` modality instead, which
  causes issues with `when` exhaustiveness analysis in K2.
- This issue also affected K1, but it was less visible there because
  `when` exhaustiveness analysis in K1 uses deserialized descriptors.

^KT-62895
2024-01-05 15:55:29 +00:00
Marco Pennekamp 5797b4877c [FIR/AA decompiler] Add tests for sealed interfaces
^KT-62895
2024-01-05 15:55:29 +00:00
Dmitrii Gridin 7c8aff963f [SLC] do not create light classes for expect declarations
We shouldn't build expect declarations as they do not
exist. We can omit check on member declarations as we
won't request them as we skip expect classes

^KT-57536 Fixed
2024-01-05 15:07:55 +00:00
Dmitrii Gridin c14c12479c [SLC] fix multifile-classes in multiplatform case
Multifile-class can contain not only files from the same
module, but also files from the common part.
This commit also fixes KotlinByModulesResolutionScopeProvider as
it should provide all transitive dependencies

^KT-64714 Fixed
2024-01-05 15:07:55 +00:00
Dmitrii Gridin fc519b2339 [SLC] add test on multiplatform facade
^KT-64714
2024-01-05 15:07:55 +00:00
Mikhail Glukhikh 3d560cd92c K2: use correct scope for overrides calculation in ObjCName checker
To call retrieveDirectOverriddenOf,
one must use directly the owner scope of a callable symbol we consider,
and not a scope of some derived class.

#KT-64276 Fixed
2024-01-05 14:39:05 +00:00
Artem Kobzar e4c244d5db [K/Wasm] Generate source-map for WAT-files 2024-01-05 14:16:32 +00:00
Nikolay Lunyak aea2e8052a [FIR] Ensure KT-64089 works
Make sure SENSELESS_COMPARISON
is absent in this case.

^KT-64089 Obsolete


Merge-request: KT-MR-13754
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2024-01-05 14:15:06 +00:00
Dmitrii Gridin b6d373d8e5 Update copyright to 2024 2024-01-05 13:43:17 +00:00
Alexander Shabalin 3f2584bb02 [K/N] Move calls checker into separate module ^KT-62091 2024-01-05 13:35:35 +00:00
Nikolay Lunyak 8cd87059c8 [FIR] Fix the failing test after merging 533ed5c6
It started failing because of other
changes having been merged right before it

^KT-64644 Fixed

Merge-request: KT-MR-13755
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2024-01-05 13:34:43 +00:00
Alexander Shabalin d7929f93f2 [K/N] Fix samples compilation 2024-01-05 13:31:53 +00:00
Yahor Berdnikau 41003732b1 [Gradle] Add JVM toolchain configure method to Kotlin target
These methods are only added to provide more user-friendly error
when user tries to configure JVM toolchain in Kotlin target DSL.

^KT-64629 Verification Pending
2024-01-05 12:34:27 +00:00
Alexander Shabalin e959e97992 [K/N] Fix :kotlin-native:runtime:clean
The task erroneously deleted the build directory during
configuration phase.
2024-01-05 12:17:08 +00:00
Leonid Startsev 7700921646 Add K2 configurations for specific kotlinx.serialization tests
#KT-64447 Fixed
2024-01-05 11:38:35 +00:00
Dmitriy Novozhilov c2cbbecfe9 [K2 Serialization] Store serializable properties in metadata extension
This solution is temporary (see KT-64694 for details)

^KT-64312 Fixed
2024-01-05 11:30:57 +00:00
Dmitriy Novozhilov fb3963dead [FIR] Add extension point to metadata serialization
This is a temporary solution for KT-64312
Introduced extension point should be removed (KT-64695)
2024-01-05 11:30:57 +00:00
Dmitriy Novozhilov 717d1c774b [FIR] Save information about SerializationPluginMetadataExtensions in the property attribute
K1 implementation of kotlinx.serialization used SerializationPluginMetadataExtensions
  for two purposes:
- to extract the source-order of properties
- to identify which properties are actually serializable

In K2, the first point is covered by the compiler itself (as it correctly orders
  properties during deserialization), and to cover the second point we
  need to save in the propery information if it was mentioned in this extension
  or not

KT-64312
2024-01-05 11:30:57 +00:00
Alexander Shabalin 5208b3c024 [K/N] Put FinalizerProcessor CFRunLoop usage under a flag ^KT-64313 2024-01-05 10:46:49 +00:00
Dmitriy Novozhilov 8ff869a08c [FIR] Unregister FirJavaElementFinder at the Project disposing
^KT-64433 Fixed
2024-01-05 10:23:04 +00:00
Pavel Kunyavskiy 32de968531 [Names] Avoid deadlock in initialization of classId constants
StandardClassIds was using Annotations subclass in its initialization.
At the same time, Annotations subclass was using StandardClassIds in its
initialization implicitly through baseId() method.

This leads to a rare deadlock on CI in case where two different threads
tried to initialize both classes at the same time.

It can't be reproduced robustly, as a single thread was able to
successfully initialize both, and will do it on an attempt to
initialize any of them.

^KT-64720 Fixed
2024-01-05 09:53:05 +00:00
Dmitriy Novozhilov 7accda6cda [FIR] Make FirProviderWithGeneratedFiles know about providers from mpp dependencies
During refactoring of FIR2IR commit 8ebb4127 introduced
  `FirProviderWithGeneratedFiles` for lookups for containing FIR for
  generated declaration

But it broke the logic of `Fir2IrIrGeneratedDeclarationsRegistrar`,
  which provides annotations for metadata from generated IR annotations
  (see `containingFile` function in it), as it started to use fir
  provider from the platfrom session instead of provider of the
  corresponding session

So to fix this issue `FirProviderWithGeneratedFiles` was changed in the
  way so it sees declarations from dependant sessions too (only with
  `dependsOn` relation), which allows to use provider for the leaf
  platform session for declarations from any module within the same
  HMPP hierarchy

^KT-64444 Fixed
2024-01-05 09:42:22 +00:00
Roman Golyshev 8feb4def4d KTIJ-28167 [AA] Add a note about type aliases to the findAvailableConstructors function 2024-01-04 20:07:41 +00:00
Roman Golyshev df8c6c694a KTIJ-28167 [AA] Support SAM constructors in KtFirReferenceShortener
Utilize `FirSamResolver` to obtain the potential SAM constructor
from the classifier

Also, accept K2_SYNTHETIC_RESOLVED in the `resolveUnqualifiedAccess`,
since this is the kind of resolve success which corresponds to the
SAM constructor call resolution

^KTIJ-28167 Fixed
2024-01-04 20:07:41 +00:00
Roman Golyshev e561de8a22 KTIJ-28167 [AA] Refactor FirShorteningContext.findFunctionsInScopes
It will make it easier processing SAM constructor there later
2024-01-04 20:07:41 +00:00