Commit Graph

2593 Commits

Author SHA1 Message Date
Anna Kozlova 4fe239375f [cls] write contracts information to cls stubs
^ KTIJ-24665
this information would be used to create resolved FirElements from stubs,
so no ProtoBuf would be kept in memory
2023-04-25 08:34:18 +00:00
Yan Zhulanow cb825f664f [LL API] Do not throw PCE on invalid sessions, patch specific cases
This is a temporary solution to fix the problem with sessions that
turned to be invalid at the time of analysis.

Currently, 'FirSession's and associated 'FirFile's are reused
between threads. When an exception, which might be an ordinary one
or 'ProcessCancelledException', occurs during an analysis of a module
file, a 'FirSession' for that module becomes invalid.

As there is currently a single resolution lock in the K2 IDE, other
threads might be waiting for resolution on the same session.
These threads are unaware that the session cannot be safely used
anymore, as it was correct before the lock.

The previous approach with cancelling analysis in all waiting threads
with manual 'ProcessCancelledException' throwing right inside the lock
showed it's incorrect. While some actions might be prepared to sudden
PCEs and can restart themselves, such behavior is not granted
by the platform.

The fix patches a few common places so the diagnostic list and
a file structure tree can be built safely. It is expected that in
some places exceptions caused by an inconsistent FIR tree can revive.

The right, ultimate fix to the problem involves modifying transformers,
so the FIR tree will mutate only when the analysis is complete. Although
it's planned work, it is expected to take quite a time.
2023-04-25 06:03:52 +00:00
Roman Golyshev e4390e47cf [Analysis API] KTIJ-23588 Do not ignore calls qualified with objects
^KTIJ-23588 Fixed
2023-04-24 22:16:55 +00:00
Dmitrii Gridin cb546926d5 [LL FIR] LLFirLazyResolveContractChecker: drop hack for COMPILER_REQUIRED_ANNOTATIONS phase
This is an obsolete hack

^KT-56543
2023-04-24 16:04:44 +00:00
Kirill Rakhman 7f46225bed [FIR] Set correct constraint position for callable reference
This fixes a false positive resolution error for callable references
to functions with a type parameter that's annotated with
@OnlyInputTypes.

#KT-57994 Fixed
2023-04-24 14:04:50 +00:00
Dmitrii Gridin 89acaae819 [LL FIR] RawFirNonLocalDeclarationBuilder: improve diagnostics 2023-04-24 14:01:57 +00:00
Dmitrii Gridin 2a00be916a [SLC] SymbolLightAccessorMethod: avoid symbol restoring on isValid
^KTIJ-25108 Fixed
2023-04-24 11:53:36 +00:00
Alexander Udalov 9ec78e1aa9 K2: remove JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE error
This is a partial revert of 949a39b80f. In the end it turned out not
necessary to prohibit this case (and perform a breaking change), because
JVM backend was fixed to generate it correctly in d73d3c46e2.

 #KT-55307 Declined
 #KT-55846 Declined
2023-04-24 11:45:55 +00:00
Dmitrii Gridin 63e6816a50 [LL FIR] avoid body resolve on attempt to build symbol for type parameters
^KT-57850
2023-04-21 17:21:36 +00:00
Dmitrii Gridin 5a53d796e1 [LL FIR] add more tests on lazy resolve for type parameters
^KT-57850
2023-04-21 17:21:36 +00:00
Dmitrii Gridin 9fe77d6a56 [LL FIR] avoid body resolve on attempt to build symbol for parameters
^KT-57850
2023-04-21 17:21:36 +00:00
Dmitrii Gridin 3394097f47 [LL FIR] run lazy resolve tests by caret
To test production resolveToFirSymbol entry point

^KT-57850
2023-04-21 17:21:36 +00:00
Dmitrii Gridin 6b3e49e824 [AA FIR] correctly restore declaration with annotation with argument inside some type from symbol pointer
ConeAttributes can have some non-stable info, so we shouldn't render it

Also reduce resolve from IMPLICIT_TYPES_BODY_RESOLVE to TYPES where it is possible

^KT-58141 Fixed
2023-04-21 17:21:36 +00:00
Kirill Rakhman 0a2477585a [FIR] Implement DEFINITELY_NON_NULLABLE_AS_REIFIED diagnostic
#KT-55646 Fixed
2023-04-21 16:23:16 +00:00
Roman Golyshev fb9de6ba45 [213] Avoid using ConcurrentCollectionFactory.createConcurrentIdentityMap
The `ConcurrentCollectionFactory` class was moved to the module
which is no longer available in the 213 platform distribution

`MapMaker().weakKeys().makeMap()` is used as drop-in replacement of
concurrent hash map with identity-based equals strategy

The new implementation stores keys on weak references, which should not
change the behavior of the `ModuleFileCacheImpl`.

1. If someone still has a strong reference to the `ktFile`, then the
cache will also keep it.

2. If there are no more strong references to the `ktFile`, then the
cache will not hold it from being garbage-collected. However, since
nobody  has a strong reference to the `ktFile` anymore, nobody can call
 `fileCached` or `getCachedFirFile` with it, and it will never be
 requested from the cache.

KTI-1114
2023-04-21 13:19:04 +00:00
Roman Golyshev d4cffb8a5a [213] Switch to 213 platform
KTI-1114
2023-04-21 13:19:04 +00:00
Yan Zhulanow c9c6508b03 [LL API] Fix declaration mapping for library dependencies
As there is no accurate way to figure out exact dependencies for each
library JAR, all project libraries but the current one are added as
dependencies. However, for performance reasons, each library is not
treated as an individual 'LLFirLibrarySession', instead a scope-based
'JvmClassFileBasedSymbolProvider' is used.

Although code analysis is correct with this setup, navigation between
libraries was broken. The reason is that source declarations were only
queried inside the library itself.

After the fix, declarations are first queried in the library,
and if there are no good candidates, all other libraries are scanned.
The same way things work in the Java plugin.

^KTIJ-23073 Fixed
2023-04-21 12:49:43 +00:00
Dmitrii Gridin f85dc95b66 [SLC] SymbolLightAccessorMethod: reduce number of requests on symbol restoring
We can avoid extra restoring of property accessors
if the corresponding property is already restored

^KT-57850
2023-04-21 11:10:20 +00:00
Dmitrii Gridin 5d1c853adf [AA FIR] fix contract violation for java Target annotation
^KT-57849 Fixed
2023-04-21 10:14:05 +00:00
Dmitrii Gridin f540826207 [AA FIR] add tests on java target annotation stability
^KT-57849
2023-04-21 10:14:05 +00:00
Dmitrii Gridin 7b91cd0ff3 [FIR] calculate java Target annotation on COMPILER_REQUIRED_ANNOTATIONS phase
^KT-57849
^KT-57949
2023-04-21 10:14:05 +00:00
Dmitrii Gridin 1c456b216b [AA FIR] add lazy resolve test on java target
^KT-57849
2023-04-21 10:14:05 +00:00
Dmitrii Gridin 0caaca45ae [AA FIR] fix contract violation for Target annotation
^KT-57849
2023-04-21 10:14:05 +00:00
Dmitrii Gridin d66b919c12 [AA] introduce tests on annotation stability
^KT-57849
2023-04-21 10:14:05 +00:00
Egor Kulikov c46c922841 [ClsStubs] Add context receivers on function types 2023-04-20 18:57:51 +00:00
Dmitrii Gridin bca8be6c39 [LL FIR] avoid resolve to find property accessor declaration
^KT-57850 Fixed
2023-04-20 11:12:39 +00:00
Kirill Rakhman 8b47a4fa48 [FIR] Fix resolution of objects in presence of low-priority candidates
For CallKind.VariableAccess, the condition when to *skip* resolution of
objects was previously collector.isSuccess. This wasn't strict enough
because collector.isSuccess could be true when the best found candidate
has an applicability like RESOLVED_WITH_LOW_PRIORITY (e.g. from dynamic
scope or annotated with @LowPriorityInOverloadResolution). In these
cases, we do want to resolve objects. To fix this, the condition is
changed to collector.shouldStopResolve which is stricter.

#KT-57960 Fixed
2023-04-20 08:04:07 +00:00
Dmitrii Gridin 2463b904f7 [LL FIR] add ability to suppress contract violation exception
^KT-56543
2023-04-19 20:12:43 +00:00
Dmitrii Gridin 8387ea8a39 [LL FIR] FileStructure: process annotations from constructors correctly
^KT-56543
2023-04-19 20:12:43 +00:00
Dmitrii Gridin 71f48ede53 [LL FIR] resolve compiler required annotations correctly
Original AbstractFirSpecificAnnotationResolveTransformer can jump
to other classes and resolve them outside
our transformers, so it leads to
problems with locks and lazy bodies

^KT-56543
2023-04-19 20:12:42 +00:00
Dmitrii Gridin 6170d83301 [FIR] update reversed testData
^KT-56543
2023-04-19 20:12:41 +00:00
Dmitrii Gridin 26f8147a8c [LL FIR] FileStructure: process super class calls correctly
^KT-56543
^KT-57793
2023-04-19 20:12:39 +00:00
Dmitrii Gridin d0e801054c [FIR] builder: add test on class with wrong super call
^KT-56543
^KT-57793
2023-04-19 20:12:39 +00:00
Dmitrii Gridin 332cdc514b [LL FIR] reanalyse declarations on the air for incremental analysis
We cannot do it inplace now as we do not have a lock to do
it under after analysis started to use declaration-level lock

This part is mostly covered by the plugin tests
(which failed after the previous commit)

^KT-56543
2023-04-19 20:12:39 +00:00
Dmitrii Gridin 72def186a3 [LL FIR] rework transformers, so transformers resolve only a specific set of declarations
The change is needed for the parallel resolution (^KT-55750), so we can resolve the declaration
under a lock that is specific to this declaration.
Previously, if LL FIR was resolving some FirClass, LL FIR  resolved all its children too, and it had no control over what parts of the FIR tree were modified.
The same applied to the designation path, sometimes the classes on the designation path
might be unexpectedly (and without lock) modified.

This commit introduces LLFirResolveTarget, which specifies which exact declarations should be resolved during the lazy resolution of the declaration.
All elements outside the declarations specified for resolve in LLFirResolveTarget, should not be modified.

The logic of lazy transformers is the following:
- Go to target declaration collecting all scopes from the file and containing classes
- Resolve only declarations that are specified by the LLFirResolveTarget, performing the resolve under a separate lock for each declaration

^KT-56543
^KT-57619 Fixed
2023-04-19 20:12:38 +00:00
Dmitrii Gridin 18a8cfb090 [AA FIR] firSymbolUtils: avoid redundant resolve
^KT-56543
2023-04-19 20:12:36 +00:00
Dmitrii Gridin 7e380e7df5 [LL FIR] remove LLFirPhaseRunner as it does nothing
^KT-56543
2023-04-19 20:12:36 +00:00
Dmitrii Gridin 72fce82f2f [LL FIR] remove useless checks for resolve phases inside transformers
Those checks are not performed during locking

^KT-56543
2023-04-19 20:12:35 +00:00
Dmitrii Gridin 0f379e592a [LL FIR] make LLFirLazyTransformerExecutor an object
^KT-56543
2023-04-19 20:12:35 +00:00
Dmitrii Gridin a172439f2a [LL FIR] move update declaration resolve phase out of updatePhaseForDeclarationInternals
needed for further safe publication of phase update

^KT-56543
2023-04-19 20:12:35 +00:00
Dmitrii Gridin d52c8b6793 [LL FIR] move updateDeclarationInternalsPhase checks out of LLFirLazyTransformer
needed for further safe publication of phase update

^KT-56543
2023-04-19 20:12:34 +00:00
Dmitrii Gridin e686e840b0 [LL FIR] move checkIsResolved checks out of LLFirLazyTransformer
needed for further safe publication of phase update

^KT-56543
2023-04-19 20:12:34 +00:00
Ilya Kirillov 930708ebb0 [LL FIR] lazy resolve imports under a separate lock
^KT-56543
2023-04-19 20:12:34 +00:00
Ilya Kirillov 167ed5e049 [Analysis API] add a KDoc for the LLFirSymbolProviderNameCache 2023-04-19 16:09:07 +00:00
Ilya Kirillov 806fff0887 [Analysis API] forbid Analysis inside KtResolveExtensionProvider
As it's called during FIR sessions initialization

^KT-57930
2023-04-19 16:09:06 +00:00
Ilya Kirillov 0d0b1b7945 [Analysis API] add ability for a custom element navigation for a KtResolveExtensionFile
^KT-57930
2023-04-19 16:09:05 +00:00
Ilya Kirillov 51eaa3f9cf [Analysis API] provide tests for the KtResolveExtensionProvider
^KT-57930
2023-04-19 16:09:05 +00:00
Ilya Kirillov d68587de77 [Analysis API] implement API to extend Kotlin resolution by generated declarations
^KT-57930 fixed
2023-04-19 16:09:04 +00:00
Ilya Kirillov 0dbc948616 [LL FIR] introduce CompositeKotlinDeclarationProvider
^KT-57930
2023-04-19 16:09:01 +00:00
Ilya Kirillov 9ca99ba7c7 [LL FIR] introduce CompositeKotlinPackageProvider
^KT-57930
2023-04-19 16:09:00 +00:00