Commit Graph

3663 Commits

Author SHA1 Message Date
Yan Zhulanow 4690a430f4 [LL API] Fix smart-cast collection for special 'FirElement's
'DFANode' is not created for certain elements, such as types or
references. Before the change, only the target element itself was
queried for DFA, making the 'ContextCollector' return an empty map of
smart casts.

^KTIJ-26973 Fixed
2023-09-22 13:40:09 +00:00
Mikhail Glukhikh b9302869d5 K2: reproduce KT-61844 2023-09-22 12:23:46 +00:00
Yan Zhulanow 36df749697 [LL API] Invalidate code fragment sessions on PSI modifications
Code fragments depend not only on their context module, but also on
body of the context declaration.
2023-09-22 12:20:05 +00:00
Yan Zhulanow 1293eb0fab [LL API] Rename 'KtModuleKind' to 'KtModuleResolutionStrategy'
The word "kind" is ambiguous – users might assume the kind is somehow
related to 'KtSourceModule'/'KtScriptModule'.
2023-09-22 12:20:05 +00:00
Yan Zhulanow 0f33f82ffc [LL API] Fix reflective patching for field accesses
Implement the same behavior as in K1 evaluator. Also see
'IRFragmentCompilerCodegen#codegenFactory' in the IntelliJ project.

The commit fixes the following failing tests in the IntelliJ project:
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$CompilingEvaluator$InaccessibleMembers.testPrivateAnnotationCompanionValue
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$CompilingEvaluator$InaccessibleMembers.testSelfMembers
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$CompilingEvaluator$InaccessibleMembers.testOuterMembers
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testPrivateMember
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testProperties
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testPrivatePropertyWithExplicitDefaultGetter
- K2IdeK2CodeKotlinEvaluateExpressionTestGenerated$SingleBreakpoint$Uncategorized.testPrivateClass
2023-09-22 12:20:05 +00:00
Yan Zhulanow fa98945719 [LL API] Remove KtCodeFragment-targeted conflict resolver from libraries
Before, 'KtCodeFragment's were analyzed as a part of their context
session. Now, a separate session is created for each code fragment,
and the LLLibraryScopeAwareCallConflictResolverFactory registration
moved there.
2023-09-22 12:20:05 +00:00
Yan Zhulanow 715f7d1a35 [LL API] Analyze code fragment in a separate 'FirSession'
Before, `KtCodeFragment`/`FirCodeFragment` was analyzed as a part of
its context `KtModule`. This has the following complications:

- In non-source sessions, diagnostic reporting is globally disabled.
  For code fragments, however, checking the code before passing it to
  the backend is essential.

- Special treatment for call ambiguities in libraries
  (`LLLibraryScopeAwareCallConflictResolverFactory`) becomes complicated
  as the conflict resolver has to be applied to a library module.

- `KtCodeFragment`s usually have a shorter lifetime than their own
  context. Caching may potentially be implemented differently for them.

^KT-61783 Fixed
2023-09-22 12:20:05 +00:00
Yan Zhulanow b32c083346 [LL API] Remove leaves of 'LLFirResolvableResolveSession' 2023-09-22 12:20:05 +00:00
Yan Zhulanow f51a7515e1 [LL API] Move 'LLModuleKindProvider' instantiation out 2023-09-22 12:20:05 +00:00
Yan Zhulanow 095dd7d9c3 [LL API] Move 'LLDiagnosticProvider' instantiation out 2023-09-22 12:20:05 +00:00
Yan Zhulanow 68bb39fbcd [LL API] Pass 'LLDiagnosticProvider' to 'LLFirResolveSession' explicitly 2023-09-22 12:20:05 +00:00
Yan Zhulanow b18856dc0a [LL API] Move LLModuleProvider and LLSessionProvider instantiation out 2023-09-22 12:20:05 +00:00
Yan Zhulanow 147712975f [LL API] Remove instance checks for LLFirResolveSession implementations 2023-09-22 12:20:04 +00:00
Yan Zhulanow fee3e696ea [LL API] Move out traits of 'LLFirResolveSession' to separate classes 2023-09-22 12:20:04 +00:00
Yan Zhulanow 25c9ef12df [LL API] Minor, return 'List' from 'getAllDiagnosticsForFile()' 2023-09-22 20:53:26 +09:00
Yan Zhulanow 9ef58f2bdb [LL API] Collect syntax errors in 'KtFirCompilerFacility'
^KTIJ-27167 Fixed
2023-09-22 11:39:49 +00:00
Ilya Kirillov e2252f5e6b [FIR] add testcase for KT-62031 2023-09-22 10:48:31 +00:00
Ilya Kirillov d98da87278 [FIR] Render dot-separated FQNs instead of slash-separated ones in diagnostics
^KT-62030 fixed
2023-09-22 10:48:31 +00:00
Dmitrii Gridin 850201a65c [LL FIR] LLFirContractsLazyResolver: avoid transformation for primary constructors
Primary constructors can't have any contracts.
This change also should improve memory consumption because we will
less frequently calculate bodies.

^KT-55750
2023-09-21 20:08:32 +00:00
Dmitrii Gridin d5047bfa90 [LL FIR] LLFirContractsLazyResolver: process synthetic properties correctly
FirContractResolveTransformer under the hood calls
```
if (property is FirSyntheticProperty) {
  transformSimpleFunction(property.getter.delegate, data)
}
```,
so this leads to unsafe transformation of the original function

^KT-55750
2023-09-21 20:08:32 +00:00
Dmitrii Gridin 2962482d75 [LL FIR] LLFirContractsLazyResolver: avoid transformation for delegated properties
Delegated properties can't have any contracts.
This change also should improve memory consumption because we will
less frequently calculate bodies.

^KT-55750
2023-09-21 20:08:31 +00:00
Dmitrii Gridin 3e9e66493f [LL FIR] LLFirContractsLazyResolver: avoid transformation for functions with implicit type
Legacy (current) contracts can exist only on functions with bodies.
This change also should improve memory consumption because we will
less frequently calculate bodies.

^KT-55750
2023-09-21 20:08:31 +00:00
Dmitrii Gridin 3c865bdddd [LL FIR] add lazy resolve tests on function with raw contract and implicit type
^KT-56551
2023-09-21 20:08:31 +00:00
Dmitrii Gridin c0b147e31c [LL FIR] LLFirContractsLazyResolver: drop redundant branch for property accessor
FirPropertyAccessor is not supposed to be processed separately from property

^KT-55750
2023-09-21 20:08:31 +00:00
Dmitrii Gridin a128cbc97a [LL FIR] skip implicit type resolution for declarations without implicit type
This also fixes non-resolved contract calls in the case
of wrong contract description.
And we can avoid body calculation.

^KT-56551
2023-09-21 20:08:31 +00:00
Ivan Kochurkin b5acd1da6a [FIR] Fix local RETURN_TYPE_MISMATCH with flexible Unit and multiple Unit returns 2023-09-21 12:52:32 +00:00
Dmitriy Novozhilov 9e5ee3afa0 [FE] Add isLocal name to ClassId constructor calls where it needed 2023-09-21 12:40:44 +00:00
Mikhail Glukhikh 326d68c1f4 Drop separate K1/K2 implementations of generateMetadataExtraFlags
Related to KT-62056
2023-09-21 11:14:09 +00:00
Nikolay Lunyak 76fa812949 [FIR] Ensure K2 reports redundant diagnostics for default values 2023-09-21 07:48:31 +00:00
Nikolay Lunyak 8755cf75ac [FIR] Improve the messages of the multiple defaults diagnostics
Mention the base functions where the default
values come from.
2023-09-21 07:48:30 +00:00
Kirill Rakhman 4e1dfcd2a8 [FIR] Improve readability of rendered types in diagnostics
#KT-61824 Fixed
#KT-61688 Fixed
2023-09-21 07:18:19 +00:00
Kirill Rakhman 99b852adf8 [FIR] Refactor constructors of ConeTypeRenders 2023-09-21 07:18:19 +00:00
Yan Zhulanow 834cbaac5a [LL API] Run fir2ir separately for files in different modules
Each module may have its own compiler configuration.

^KTIJ-27061 Fixed
2023-09-21 06:19:15 +00:00
Ivan Kochurkin 1026cdf035 [FIR] Register necessary resolve components for library session for all backends
^KT-61876 Fixed
2023-09-20 17:12:52 +00:00
Mikhail Glukhikh 0c287c9945 K2: reproduce KT-61933 2023-09-20 15:42:03 +00:00
Roman Efremov ad4d1a5ba8 [IR] Support ACTUAL_ANNOTATION_CONFLICTING_DEFAULT_ARGUMENT_VALUE in K2
It's implemented as IR checker because in K2 constant expressions are
evaluated on backend. FIR diagnostic removed because isn't needed.

"annotationViaActualTypeAlias" test has no `// FIR_IDENTICAL` because
diagnostic reported on entire typealias declaration instead of its name.
This is because in IR+LightTree we have only offsets, so can't navigate
to typealias name element.

^KT-59940 Fixed
2023-09-20 15:40:37 +00:00
Dmitrii Gridin 1d0785e246 [LL FIR] do not try to apply in-block modifications for unresolved bodies
In-block modifications are applicable only for FIR declarations with
fully resolved bodies. It can happen only during implicit type and body
phases. The implicit type phase probably is not applicable for our
particular case, but we will play safe because properties have a
complicated resolution logic, so it is hard to be sure that only body
phase will be enough.
Changes inside contracts are treated as out-of-block, so we can avoid
marker from this phase. Also, all mentioned calls inside bodies resolve
the corresponding declarations to the contract phase, so we will save a
lot with this optimization.

Q: Why in-block modification can be heavy?
A: In most cases this invalidation is pretty cheap because we have all
required information inside caches. But it is possible that we can
receive an in-block modification event for PSI without a corresponding
FIR element, or it is not yet fully resolved. In this case, for example,
we will do such redundant works as a raw FIR building or KtModule search

^KT-61842 Fixed
2023-09-20 15:36:02 +00:00
Dmitrii Gridin f7fe33bd98 [LL FIR] move in-block analysis declarations closer to service
^KT-61842
2023-09-20 16:04:03 +02:00
Ilya Kirillov b25185530f [Analysis API Standalone] use compiler FirSymbolProvider for standalone mode
^KT-61371 fixed
2023-09-20 07:47:59 +00:00
Ilya Kirillov d377d87c77 [LL FIR] refactoring, add service accessor for LLFirLibrarySymbolProviderFactory
^KT-61371
2023-09-20 07:47:59 +00:00
Ilya Kirillov 9c50308954 [LL FIR] refactoring, rename LLFirLibrarySymbolProviderFactory.createJvmFirDeserializedSymbolProviders -> createJvmLibrarySymbolProvider
to match the behavior

^KT-61371
2023-09-20 07:47:59 +00:00
Ilya Kirillov cce8bc6f83 [LL FIR] refactoring, use Project from project session constructor for implementations of LLFirLibrarySymbolProviderFactory
^KT-61371
2023-09-20 07:47:59 +00:00
Ilya Kirillov 2422fc6df3 [LL FIR] refactoring, extract LLFirLibrarySymbolProviderFactory implementation to the standalone module
^KT-61371
2023-09-20 07:47:59 +00:00
Ilya Kirillov 575c7ea0d9 [LL FIR] refactoring, rename JvmFirDeserializedSymbolProviderFactory
so it can be used not only for JVM

^KT-61371
2023-09-20 07:47:59 +00:00
Nikolay Lunyak ec9cb8beb6 [FIR] Rename JvmNames -> JvmStandardClassIds
This is more consistent with the code of
the common compiler checkers.

It would be nice to refactor the contents
of this object further, but it's out
of scope of the current branch.

^KT-54596
2023-09-19 22:14:09 +00:00
Nikolay Lunyak 986f1624ec [FIR] Remove jvm-specific annotations from common compiler code
^KT-54596 Fixed
2023-09-19 22:14:09 +00:00
Ilya Chernikov e5ee364419 IC: Implement expect/actual tracking
fixes NewMultiplatformIT.testIncrementalCompilation
also #KT-61590 fixed
2023-09-19 15:46:30 +00:00
Dmitrii Gridin 11d86992c5 [SLC] update test data for 2.0 version
* disable compiled tests for scripts because they are not supported yet
* fix test data

^KT-60590 Fixed
2023-09-19 15:46:27 +00:00
Dmitrii Gridin 9ff3871a8b [LL FIR] LLFirPhaseUpdater: add missing update for code fragment block 2023-09-19 14:03:29 +00:00
Dmitrii Gridin e5f0356e16 [LL FIR] LLFirPhaseUpdater: add missing update for initializer body 2023-09-19 14:03:29 +00:00