Commit Graph

3616 Commits

Author SHA1 Message Date
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
Dmitrii Gridin 12dc6b1ebc [FIR] FirRenderer: render name for scripts
A script name is important information, so it is better to render it.
This also will fix the inconsistency with redundant space after 'SCRIPT:'.
2023-09-19 14:03:29 +00:00
Dmitrii Gridin c6bb9af823 [FIR] FirRenderer: add missing resolvePhaseRenderer usage for anonymous initializer and dangling modifiers 2023-09-19 14:03:29 +00:00
Dmitrii Gridin c9df6aff5f [LL FIR] do not crash on attempt to resolve class initializer in case of class clash
^KT-61788 Fixed
2023-09-19 14:03:29 +00:00
Dmitrii Gridin e3ad946d23 [LL FIR] add more debug info into containingClass
^KT-61788
2023-09-19 14:03:29 +00:00
Alexander Udalov 5cae87b263 K2: add package FQ name to ClassId of anonymous objects
This is needed because in order to figure out which declarations are
visible from anonymous objects in terms of overridability (see
`FirVisibilityChecker.isVisibleForOverriding`), we need to get the
package name of that anonymous object, because there's package-private
visibility on JVM.

 #KT-62017 Fixed
2023-09-19 09:32:55 +00:00
Dmitrii Gridin 5981fb3022 [LL FIR] drop copyright from testData 2023-09-18 21:12:45 +00:00
Dmitrii Gridin 33e6a85a2d [LL FIR] rename testdata to testData to avoid copyright generation
We exclude testData pattern from copyright scope
2023-09-18 21:12:45 +00:00
Yan Zhulanow 40ecd4bc1e [fir2ir] Fix annotation conversion on partial module compilation
Backend requires annotation constructors to be fully resolved for the
'IrConst' default value lowering. However, in the IDE there is usually
no need in complete annotation class resolution.

^KTIJ-27061 Fixed
2023-09-18 19:48:08 +00:00
Dmitrii Gridin f4df4f8007 [FIR] do not invoke body resolution for properties with excplicit type on implicit type phase
`property.backingField != null` is too soft condition because currently
each property has a backing field. We should trigger the full body
resolution only in the case of an implicit type on the property or on
the backing field

^KT-61991 Fixed
2023-09-18 15:26:53 +00:00
Jinseong Jeon cec299ac0a K2 UAST: Improve performance of PSI declaration provider
When it comes to finding regular class (of `PsiClass`) from the given
`ClassId`, we've reinvented the wheel in a worse way. `JavaFileManager`
is there to find `PsiClass`, and we already build/populate index for
that while initializing AA standalone mode's own project environment.
We can simply load that manager and send a query, that's it.

However, our efforts so far on binary PSI declaration providers are not
entirely useless. `JavaFileManager` can't handle top-level declarations
and search for all callables/classes in a given package in general. So,
we can still use existing logic for non-ClassId queries. We just need to
cache the intermediate results: fq name to `VirtualFile`s.

To fully utilize the aforementioned cache, we also need to cache an
instance of `KotlinPsiDeclarationProvider`.

Combing these three ideas, now running K2 UAST on a very large module is
"on par", e.g.,
K1:
//tools/adt/idea/android:intellij.android.core_lint_test PASSED in 112.8s
  Stats over 7 runs: max = 112.8s, min = 104.3s, avg = 107.9s, dev = 3.6s
K2 (before):
//tools/adt/idea/android:intellij.android.core_lint_test PASSED in 303.0s
  Stats over 7 runs: max = 303.0s, min = 286.8s, avg = 294.4s, dev = 5.0s
K2 (after):
//tools/adt/idea/android:intellij.android.core_lint_test PASSED in 112.8s
  Stats over 7 runs: max = 112.8s, min = 105.7s, avg = 108.9s, dev = 2.4s
2023-09-18 14:55:11 +00:00
Nikolay Lunyak 93958ec73d [FIR] Check conflicts between nested classes' constructors and member functions
For an example of an object with
an implicit primary constructor,
see `FirPsiOldFrontendDiagnosticsTestGenerated.testSingletonAndFunctionSameName`.

^KT-62005 Fixed


Merge-request: KT-MR-12242
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-09-18 11:41:42 +00:00
Roman Golyshev a78d631b16 KTIJ-27050 [Analysis API] Correctly handle type parameters in KtFirReferenceShortener
Make `FirShorteningContext` correctly return symbols for type
parameters, so they are not ignored when scopes are inspected

Add additional type of `PartialOrderOfScope` - `TypeParameter`, because
otherwise it would have been classified as `Unclassified`, and that
breaks scopes comparison

Add missing type parameters to the scope of class header in
`ContextCollector`, add testdata for that

There is a bug in the compiler with type parameters leaking to nested
classes headers (KT-61959). After it's fixed, the testData with
incorrect expected shortenings/scopes should be adjusted and fixed too

^KTIJ-27050 Fixed
2023-09-18 10:23:30 +00:00
Roman Golyshev e2019ceb95 KTIJ-27050 [Analysis API] Refactor FirShorteningContext
Use `AvailableSymbol<FirClassLikeSymbol<*>>` instead
of `AvailableSymbol<ClassId>`
2023-09-18 10:23:29 +00:00
Roman Golyshev 020f8c0742 KTIJ-27050 [Analysis API] Refactor FirShorteningContext
Remove duplication from `findFirstClassifier*` functions
2023-09-18 10:23:29 +00:00
Roman Golyshev b4209a4196 KT-61889 [Analysis API] Remove last usage of onAirResolve from Reference shortener
Add factory function `create` to
`FirTowerContextProviderByContextCollector`

^KT-61889 Fixed
2023-09-15 19:18:09 +00:00
Mikhail Glukhikh f8ada456e4 K2: rename FakeOverrideTypeCalculator to CallableCopyTypeCalculator
This commits performs a rename.
According to KT-61443 this calculator is applicable not only to
fake (substitution/intersection) overrides.
2023-09-15 15:21:10 +00:00
Roman Efremov 420dceb7d8 [FE, IR] Store PsiElement for mismatched annotation's actual target
There is IDE quick fix which suggests to copy mismatched annotation
from `expect` to `actual` (see KTIJ-26633). It needs to find
`actual` PsiElement where to add annotation. Before previous commit, it
was easy - just get source of `Incompatibility.actualSymbol`.
After previous commit, the problem might be in value parameter, while
`actualSymbol` would contain function symbol. This is solved by adding
new field `Incompatibility.actualAnnotationTargetElement`.

`SourceElementMarker` introduced, because it's needed to be used in
abstract checker. Existing `DeclarationSymbolMarker` doesn't fit
because in next PR for this issue annotations set on types will be reported,
and types are not declarations.

^KT-60671
2023-09-15 14:41:37 +00:00
Roman Efremov 371db10330 Remove IncDecOperatorsInExpectClass test
It is incorrect because has expect and actual in same module,
which results in ACTUAL_WITHOUT_EXPECT reported in FIR.
But there is already same test
`multiplatform/incDecOperatorsInExpectClass.kt`, so there is no need
to fix and maintain test `IncDecOperatorsInExpectClass`.

^KT-60075 Fixed
2023-09-15 12:04:08 +00:00
Pavel Kunyavskiy 9a9598c16b [Klib] Run prerelease checker in all backends
The checker also checks the metadata version, which
would be handled separately. Now it would never
emmit this error for klib-based backends.

^KT-61773
^KT-61596
^KT-55809
2023-09-15 09:48:42 +00:00
Dmitrii Gridin 1b1e1d5b3f [Analysis API] DebugSymbolRenderer: unify error types
They are still can be different in the case of error inside
type argument (e.g. `kotlin/Array<out ERROR CLASS: Incomplete code>`)
2023-09-14 18:53:25 +02:00
Dmitrii Gridin 2d83509200 [Analysis API Fe10] add missing initializer for properties 2023-09-14 18:53:25 +02:00
Dmitrii Gridin bb470b5504 [Analysis API Fe10] fix isFromPrimaryConstructor 2023-09-14 18:53:25 +02:00
strangepleasures cf01d2970f [SLC] [KAPT] KT-61916 Fix generation of annotations in annotation arguments 2023-09-14 13:21:07 +00:00
Kirill Rakhman 0d628c9e59 [FIR] Inline FirExpression.coneTypeSafe und use resolvedType
The call-sites don't actually need to handle unresolved expressions,
they only need safe-casts to ConeClassLikeType or
ConeIntegerLiteralType.

#KT-61367
2023-09-14 10:03:03 +00:00
Kirill Rakhman aebb3bf0ee [FIR AA] Use resolvedType instead of coneTypeOrNull where applicable
#KT-61367 Fixed
2023-09-14 10:03:02 +00:00
Dmitrii Gridin 7d42bfa859 [LL FIR] LLFirResolveTarget: mark class as internal
^KT-61296
2023-09-13 20:26:50 +00:00
Dmitrii Gridin 31b36ee766 [LL FIR] introduce lazyResolveRecursively API
FirFile after KT-56683 has its own phases and resolution logic,
so we should have a separate API for lazy resolution for FirFile and for
the entire file

^KT-61296 Fixed
2023-09-13 20:26:50 +00:00
Dmitrii Gridin b77ae5d275 [LL FIR] rework LLFirResolveTarget
* Move visiting logic to LLFirTargetResolver to
avoid code duplication
* Introduce more common LLFirWholeElementResolveTarget

^KT-61296
2023-09-13 20:26:50 +00:00
Dmitrii Gridin aeeb64b9ef [LL FIR] LLFirResolveTarget: more accurate toString
^KT-61296
2023-09-13 20:26:49 +00:00
Dmitrii Gridin 6893c44a06 [LL FIR] merge LLFirResolveTargetWithDedicatedElement into LLFirResolveTarget
^KT-61296
2023-09-13 20:26:49 +00:00
Dmitrii Gridin fd25531268 [LL FIR] LLFirResolveTargetWithDedicatedElement: implement common toStringForTarget
^KT-61296
2023-09-13 20:26:49 +00:00
Dmitrii Gridin 3432e8d1f9 [LL FIR] LLFirResolveTarget: move util to a separate file
^KT-61296
2023-09-13 20:26:49 +00:00
Roman Golyshev 7b50506aea KT-61889 [AA] Migrate KtFirReferenceShortener to ContextCollector
This should make reference shortener considerably faster, since it won't
need to perform redundant extra resolve of the file.

`ContextCollector` more accurately collects the scopes for the scripts,
so some script tests are also fixed.

It should fix the following bugs:

^KTIJ-26714 Fixed
^KTIJ-26727 Fixed

This is also an important part of fixing the following bugs:
- KTIJ-26715
- KTIJ-26734

But those bugs also rely on KT-61890, because completion uses scopes
and snows incorrect elements from them
2023-09-13 16:43:20 +00:00
Dmitrii Gridin ce900063c0 [LL FIR] reduce number of in-block modifications
The idea of optimization is simple – delay in-block modification
until the end of a write action.

Q: Why the end of write action?
A: We have to publish the result of modification somewhere during
write action to be sure that the next read action will see the
updated result. We can't publish the result somewhere later
because we can't guarantee that the modification will be visible
to all customers.

In the case of out-of-block modification, we still have to publish
the result immediately because it is hard to evaluate the consequences
of the opposite decision yet.

If an out-of-block modification happens, we can drop all previous
in-block modifications from the queue because they don't make sense
due to invalidation of the entire KtModule.

A corner case is the analysis under write action. The delay means that
there is no longer any guarantee that all PSI changes will be reflected
into FIR tree immediately. So now we can guaranty only that at
the start of `analyze` block you will have the up-to-date FIR tree.

^KT-60611 Fixed
2023-09-13 16:23:27 +00:00
Nikolay Lunyak fa600a58ac [FIR] Fix analysis of FirScript contents
Running the
`FirScriptCodegenTestGenerated.testSecondLevelFunction` test results
in "Expected is `FirResolvedDeclarationStatus`, but was
`FirDeclarationStatusImpl`. This is similar to the
`FirIdeNormalAnalysisSourceModuleCodeFragmentCollectDiagnosticsTestGenerated.testLocalFunction`
test, but that one was fixed by `9514f8f8`.
Looks like the situation here is the same,
it's just `FirScript` that needs to be
fixed.

The changed regarding the approximation is needed to avoid exposing
the anonymous type in
`FirScriptLazyDeclarationResolveTestGenerated.testDelegatesScript`.

The difference in the
`ScriptInBlockModificationTestGenerated.testRawContractScript`
test appeared because previously
the contract used to be
`FirRawContractDescription`, but
it now resolves to
`FirEmptyContractDescription`.
2023-09-13 14:11:42 +00:00
Nikolay Lunyak 01d4f25363 [FIR] Move TypeAliasConstructorsSubstitutingScope
It will be needed in the next commit
to check for conflicting declarations
2023-09-13 14:11:41 +00:00
Alexander Udalov fd68b9f49c CLI: add -Xuse-ir-fake-override-builder
To be able to test IR fake override builder (KT-61514) outside of
compiler tests.
2023-09-13 15:01:52 +02:00
Dmitrii Gridin 8d5787db12 [Analysis API FIR] KtFirValueParameterSymbol: fix expection
Effectively, it restores the fix from 2f8a64fff2

^KT-61422 Fixed
2023-09-13 12:56:57 +00:00
Kirill Rakhman ce65d3c7b8 [FIR] Set source on callee reference of implicit invoke receiver
This fixes an IllegalArgumentException when a diagnostic was reported on
it because no source was set.

#KT-61829 Fixed
2023-09-13 12:20:57 +00:00
Vladimir Dolzhenko d8c80b0270 Fix parameters matching for suspend functions
#KT-61894 Fixed
2023-09-13 11:59:02 +00:00
Mikhail Glukhikh 91aa679214 K2: reproduce KT-61691 2023-09-13 11:27:14 +00:00
aleksandrina-streltsova 752ea6fd98 [AA] Add tests for scope context for position
KTIJ-27007
2023-09-12 14:44:23 +00:00
Yan Zhulanow 9514f8f873 [LL API] Fix analysis of functions inside code fragments
FirDeclarationsResolveTransformer.transformSimpleFunction() performs
proper local function analysis only if the parent is properly set.

^KTIJ-26608 Fixed
2023-09-12 13:08:49 +00:00
Kirill Rakhman 2bc25d4f6e [FIR] Properly check for visibility in FirTypeIntersectionScopeContext
This fixes a false positive OVERRIDING_FINAL_MEMBER caused by a
package-private member in a different package being added to the
list of overridden symbols. However, in Java, package-private members
from different packages are effectively like private members in that
they cannot be overridden.

#KT-61696 Fixed
2023-09-12 10:46:46 +00:00
Yan Zhulanow 11096325c8 [LL API] Fix 'this' capturing inside property accessors
^KTIJ-26726 Fixed
2023-09-12 08:47:28 +00:00
Roman Efremov 2dae7ce6c1 [LT2FIR] Fix missing "expect" modifier on members of nested classes
For members of nested classes inside expect class
`classWrapper.hasExpect()` would be false, because it only reflects
modifiers of nested class itself and not aware of "expect" modifier
inherited from the parent class.
Fix is done in same way in PSI2FIR, see
`PsiRawFirBuilder.Visitor.toFirProperty`.

This fix now makes it possible to add test for functionality from
previous commit.

Review: KT-MR-12107

^KT-61784
2023-09-11 21:29:02 +00:00
Dmitrii Gridin ecb808992d [SLC] add more tests on vararg
^KT-61422
2023-09-11 15:47:47 +00:00