Commit Graph

2957 Commits

Author SHA1 Message Date
Brian Norman 0298d17987 [FIR] Remove suspend lambda redundant warning for inline functions
#KT-57971 Fixed
2023-06-02 10:49:57 +00:00
Ilya Kirillov 1eb0862820 [Analysis, build] replace testApi -> testImplementation in build.gradle.kts where it's possible 2023-06-02 09:16:47 +00:00
Ilya Kirillov 78f09409b7 [Analysis API] move ClsKotlinBinaryClassCache/FileAttributeService service registration to StandaloneProjectFactory 2023-06-02 09:16:47 +00:00
Ilya Kirillov fbcf73eb42 [Analysis API Standalone] commonize logic for Analysis API FIR service registration between standalone and tests 2023-06-02 09:16:47 +00:00
Ilya Kirillov feaf9acd1d [Analysis API] move KotlinFakeClsStubsCache service registration to StandaloneProjectFactory
so it can be used from standalone mode
2023-06-02 09:16:47 +00:00
Ilya Kirillov 452844ffc6 [Analysis API] move KotlinReferenceProvidersService service registration to StandaloneProjectFactory
so it can be used from standalone mode
2023-06-02 09:16:47 +00:00
Ilya Kirillov 9f2d750f98 [Analysis API] move KtResolveExtensionProvider EP registration to common code
so it can be used from standalone mode
2023-06-02 09:16:47 +00:00
Pavel Mikhailovskii 0ef31501b1 [SLC] KT-54804 Erase type and drop receiver annotations in $annotations methods 2023-06-01 18:22:03 +00:00
Jinseong Jeon 3f22044275 AA: collect .kts source files too 2023-06-01 14:16:31 +02:00
Anna Kozlova e180296f0e [LL] better name for library based provider in LLFirLibraryProviderFactory 2023-06-01 11:37:35 +00:00
Pavel Mikhailovskii 638cbd4d8e Preserve LanguageVersionSettings in buildKtModuleProviderByCompilerConfiguration 2023-06-01 07:16:46 +00:00
Marco Pennekamp 1c0082e4d6 [LL FIR] KT-58325 Disable combined stub-based deserialized symbol providers temporarily
- Due to KTIJ-25562, combined stub-based deserialized symbol providers
  currently create code correctness issues and should thus not be
  enabled.
- Once that issue is fixed, KT-58325 should be revisited.
2023-05-31 18:34:42 +00:00
Marco Pennekamp 0a67569163 [LL FIR] KT-58580 Add test data for resolve extensions in dependencies
- `dependency2` is needed to ensure the creation of combined Kotlin
  symbol providers. If there is only a single dependency Kotlin symbol
  provider, the combined symbol provider won't be created.
2023-05-31 18:34:42 +00:00
Marco Pennekamp a50e839660 [LL FIR] Add multi-module resolve extension reference resolve tests
- To test the reference resolution of declarations provided through
  resolve extensions of module dependencies, we need support for
  multimodule resolve extension tests.
2023-05-31 18:34:42 +00:00
Marco Pennekamp 915c412929 [AA] KT-58580 Add KotlinDeclarationProviderMerger
- A proper merging strategy for declaration providers is required for
  cases where the main declaration provider created by
  `createDeclarationProvider` can't provide all declarations that the
  original declaration providers can provide. Then, only a sublist of
  the declaration providers should be merged, while keeping the
  unmergeable declaration providers intact.

^KT-58580 fixed
2023-05-31 18:34:42 +00:00
Marco Pennekamp fba0648005 [AA] Move impl declaration providers to subpackage 2023-05-31 18:34:42 +00:00
Marco Pennekamp 52f025f39b [AA] Extract SublistMerger to analysis-api-providers utils
- This utility is useful for other places where sublists need to be
  merged.
2023-05-31 18:34:42 +00:00
Marco Pennekamp 2540343159 [LL FIR] KTIJ-25536 Add callable package names workaround for LLFirProvider$SymbolProvider
- Sadly, the only way for now is to disable computation of the callable
  package names, which will negatively affect performance.
2023-05-31 18:34:42 +00:00
Marco Pennekamp a61c6f6502 [LL FIR] Fix KtNotUnderContentRootModuleForTest requesting sessions too early
- `KtNotUnderContentRootModuleForTest.directRegularDependencies` is
  called during project structure creation, which led to builtins
  session creation during that period. This in turn led to the creation
  of `JvmStubBasedFirDeserializedSymbolProvider`, which failed upon the
  initialization of `declarationProvider` because
  `KotlinDeclarationProviderFactory` wasn't registered yet. This is
  precisely why `declarationProvider` was made lazy.
- However, with the new `FirSymbolNamesProvider`, keeping
  `declarationProvider` lazy is harder, because `symbolNamesProvider`
  (if also made lazy) is requested during composite symbol provider
  creation in `createBuiltinsAndCloneableSession`.
- The solution avoids creating the builtins session entirely. Instead,
  `directRegularDependencies` now gets the `KtBuiltinsModule` directly,
  which is more straight-forward as well.
2023-05-31 18:34:42 +00:00
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
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
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
Anna Kozlova b8e868caf6 [decompiler] navigate to containing class for fake object descriptors
^ KTIJ-25661
2023-05-30 17:23:54 +00: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
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
Brian Norman 8091aebbc7 [FIR] Create checker for simple enum entries with missing overrides
Complex enum entries (those with bodies) with missing overrides
are covered by an existing checker that checks all types of classes. But
simple enum entries (those without bodies) were not covered and require
a separate checker for missing overrides.

#KT-58637 Fixed
2023-05-29 16:34:44 +00:00
Dmitrii Gridin 870527a4a3 [LL FIR] fix testData
The test was introduced in 4b1dc4eee6 and conflicts with 0ac02be534

^KT-56551
2023-05-27 16:17:33 +02:00
Dmitrii Gridin 72f30d78d6 [LL FIR] cache import scopes during compiler required annotations phase
In LL FIR file is always already resolved to import phase, so we can
cache the result

^KT-56551
2023-05-27 08:47:13 +00:00
Dmitrii Gridin dabc4e34ff [LL FIR] drop global lock from compiler required annotations phase
^KT-56551
2023-05-27 08:47:13 +00:00
Dmitrii Gridin 8f82649529 [LL FIR] rewrite compiler required annotations transformer to avoid lazy resolve under locks
^KT-56551
2023-05-27 08:47:13 +00:00
Dmitrii Gridin 4b1dc4eee6 [LL FIR] add more lazy resolve tests on compiler required annotations
^KT-56551
2023-05-27 08:47:13 +00:00
Dmitrii Gridin 8d151df252 [FIR] COMPILER_REQUIRED_ANNOTATIONS phase: drop redundant transformation of super type refs
We should transform only top-level annotations. Nested/type annotations
we can ignore

^KT-56551
2023-05-27 08:47:13 +00:00
Andrei Klunnyi 3d1e5bb548 [KT-58817] Compiler defect workaround
Base method `RawFirBuilder.Visitor.convertElement` has a parameter with
default value, its overridden one in `VisitorWithReplacement` is not
allowed to declare default. So far so good.
During its work the compiler throws an exception:
`java.lang.IllegalArgumentException: No argument for parameter`.
2023-05-26 12:55:01 +00:00
Andrei Klunnyi 6535278bd3 [KT-58817] Implicit receiver for code completion
Prior to this commit code completion for .kts files was supported only
partially. Script has an implicit receiver - base class representing a
script itself, the point where its basic API resides. The knowledge of
this receiver was missing.

There are at least two context where this knowledge is crucial:
1. Code highlighting (worked fine)
2. Code completion (failed)

`FirScriptConfiguratorExtension` is responsible for filling
`FirScriptBuilder` with base script class (in addition to other
properties). See usages of [1] in its implementation.

The thing is that resolution during the completion works a bit
different. Instead of converting the entire `KtFile` it's interested
in `KtScript` only. See usages of [2].
`RawFirBuilder.Visitor.visitScript` is where implicit receivers were
missing.

Code completion and inspections applied to `.kts` files already have
`FirScript` and don't require its full reconstruction with expensive
`FirScriptConfiguratorExtension`. `RawFirBuilder.Visitor` was modified
to support sometimes already existing `FirElement`.

----------------------------------------------------------------
[1]: ScriptCompilationConfiguration.baseClass
[2]: RawFirBuilder.Visitor.convertScript
2023-05-26 12:55:01 +00:00
Andrei Klunnyi 2a1d4a42ae [KT-58817] Implicit import issues cannot be reported
To be reported with [1] imports require source. It was missing for
implicit script imports.

`FirScriptConfiguratorExtensionImpl` was extended and now adds fake
source elements (users don't see imports in the source code).

Since diagnostics for implicit import statements are meaningless for
IDE, they are suppressed in `LLFirDiagnosticReporter`.

----------------------------------------------------------------------
[1]: DiagnosticReporter.reportOn()
2023-05-26 12:55:00 +00:00
Andrei Klunnyi 28ff94533a [KT-58817] Add script-related extensions for FIR session
The following two registrars were missing:
- FirScriptingCompilerExtensionIdeRegistrar
- FirScriptingSamWithReceiverExtensionRegistrar

`FirScriptingCompilerExtensionIdeRegistrar` was introduced as a copy of
`FirScriptingCompilerExtensionRegistrar` adapted for usage from IDE.

`FirRegisteredPluginAnnotations` and `FirJvmTypeMapper` are mandatory at
`FirExtensionService.registerExtensions` and reported as missing at
runtime.
2023-05-26 12:55:00 +00:00
Kirill Rakhman 0ac02be534 [FIR] Generate annotations to data class copy method parameters
#KT-57003 Fixed
2023-05-26 11:29:13 +00:00
Mikhail Glukhikh 2cfa3d7e0d K2: reproduce KT-58618 2023-05-26 11:13:39 +00:00
Nikolay Lunyak ff61f70dd0 [FIR] KT-58460: Ensure the error is missing 2023-05-25 14:52:04 +00:00