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.
This fixes a false positive resolution error for callable references
to functions with a type parameter that's annotated with
@OnlyInputTypes.
#KT-57994 Fixed
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
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
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
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
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
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
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
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