Commit Graph

2531 Commits

Author SHA1 Message Date
Jinseong Jeon fbe558a0de AA FIR: handle smartcasted arg when building call's argument mapping
^KTIJ-25112 Fixed
2023-04-17 13:57:08 +02:00
Marco Pennekamp 73d99019bd [AA] KT-57515 Add createCompositeModificationTracker 2023-04-17 11:20:52 +00:00
Mikhail Zarechenskiy fc37885d6d K1: report a warning for invisible setter accessed from a derived class
The issue is that during binding fake overrides, the compiler doesn't
 differ setters from its properties, so the compiler uses the same
 visibility for setter and entire property.

 Changing logic at the binding stage can cause some unpredictable consequences so
 the fix is to do this differentiation right at the reporting stage

 ^KT-56662 Fixed

Merge-request: KT-MR-9565
Merged-by: Michail Zarečenskij <Mikhail.Zarechenskiy@jetbrains.com>
2023-04-17 11:08:16 +00:00
Marco Pennekamp d8f253d07b [LL FIR] KT-57207 Choose combined Java symbol providers cache size 2023-04-17 11:07:48 +00:00
Marco Pennekamp e13d4f2328 [LL FIR] KT-57207 Combine Java symbol providers
- `LLFirCombinedJavaSymbolProvider` combines multiple
  `JavaSymbolProvider`s. Its advantages are: combined index access,
  caching, classpath order disambiguation.
- Scopes can still be optimized with a combined scope instead of a naive
  union scope.

^KT-57207 fixed
2023-04-17 11:07:48 +00:00
Marco Pennekamp 3da3e14543 [LL FIR] KT-57220 Get rid of duplicate providers field 2023-04-17 11:07:47 +00:00
Marco Pennekamp b50ecfddb7 [LL FIR] KT-57220 Make combined symbol provider constructors private
- The combined symbol provider should always be constructed using the
  dedicated `merge` function.
2023-04-17 11:07:47 +00:00
Marco Pennekamp 624164e183 [LL FIR] Remove unused "multi module lazy resolve" test data
- The test `AbstractFirMultiModuleLazyResolveTest` which used this test
  data was moved to `intellij` with the following commit: https://github.com/JetBrains/kotlin/commit/39fa2b0baf89b246348b1e9c33cfebfc3068c014
- In `intellij`, the test was later deleted with the following commit: https://github.com/JetBrains/intellij-community/commit/042a50dcdff50b0771e73c6948b020a5366ef137#diff-74605de26ac0b4a2a65e53e919001d51199769822a46620ac34ba7e08e85f5e0
2023-04-17 10:57:06 +00:00
Mikhail Glukhikh 089222cecc K2: reproduce KT-57880 2023-04-17 10:21:24 +00:00
Jinseong Jeon 5403cc7feb SLC: fix type mapping mode for var
^KT-57578
2023-04-17 10:59:03 +02:00
Alexander Korepanov e8be3043cc [JS IR] Allow restriction of function argument by external type
Add a special annotation @JsExternalTypeArgument for
 marking function parameters. The marked parameter
 accepts an argument with an external type only.

^KT-57479 Fixed
2023-04-17 08:21:10 +00:00
Jaebaek Seo 3fbd3d7e20 [FIR] Return K2 reference shortener result
This commit sets a list of `KtElement` as the return type of
`ShortenCommand::invokeShortening()`. It allows us to take the result
i.e., shortened PSIs. This can be used, for example, when we want to
run code-format only on the shortened PSI after running the reference
shortener.

^KT-57636 Fixed
2023-04-14 21:50:20 +02:00
Anna Kozlova f810d435f4 [cls] write flexible type information to cls
^KTIJ-25172
this information would be used to create resolved FirElements from stubs,
so no ProtoBuf would be kept in memory
2023-04-14 18:12:48 +00:00
Dmitrii Gridin ffb705fe2f [AA FIR] add missing new line to addImportToFile
^KTIJ-24928
2023-04-14 16:37:12 +00:00
Roman Golyshev f662908440 KTIJ-25232 [FIR IDE] Do not shorten properties with non-trivial receiver
If property call receiver is something real (like another property or a
function call), then it should not be shortened because the semantics
might change

^KTIJ-25232 Fixed
2023-04-13 15:48:08 +00:00
Dmitrii Gridin 9724febf88 [AA FIR] add missing new line to addImportToFile
^KTIJ-24928
2023-04-13 11:38:32 +00:00
Kirill Rakhman 1f29490118 [FIR] Report when typealias expansion contains deprecated type
#KT-57843 Fixed
2023-04-13 10:50:36 +00:00
Denis.Zharkov fa8eca7a7b K2: Fix invokeExtension resolution when property type is implicit
^KT-57947 Fixed
2023-04-12 14:40:56 +00:00
Denis.Zharkov 39639e08f9 K2: Fix incorrect inference of delegated property type
It was working incorrectly, because we've been trying to fix
P1 variable to intersectTypes(String?, StubForP2) that should result
to String? because we've got stubEqualsToAnything enabled there,
but nullability was being chosen incorrectly because
`StubForP2.isNullableType()` returned false

NB: The code inside `is ConeTypeVariable` case wasn't working properly
because it always `lookupTag.toSymbol(session)` always returned null,
thus there was effectively five dead lines of code there.

^KT-57814 Fixed
^KT-57921 Related
2023-04-12 11:31:43 +00:00
Dmitriy Novozhilov f8ef478647 [FIR] Assume smartacsts on member properties from friend modules as stable
^KT-57893 Fixed
2023-04-12 08:59:03 +00:00
Dmitriy Novozhilov cfa06dbf74 [FIR] Fix incorrect usages of getClassLikeSymbolByClassId with lookup tag
^KT-57839 Fixed
2023-04-11 14:45:36 +00:00
Nikolay Lunyak f826011c9f [FIR] KT-57655: Add the missing branch
^KT-57655 Fixed
2023-04-11 13:49:07 +00:00
Anna Kozlova 1aba9460f2 [LL] fix resolving of compiled type value parameter
KT-57917
occurs when UAST requests e.g. annotations for the target parameter
to check correctness of nullability or Nls
2023-04-11 12:04:50 +00:00
Dmitrii Gridin 7d37bb1f78 [LC] FakeFileForLightClass: drop stub access from equals/hashCode
^KT-57857 Fixed
2023-04-11 09:19:39 +00:00
Jaebaek Seo 820d027676 [K2] Avoid shortening duplicated PSI elements
The existing K2 reference shortener collects all the PSI elements to
shorten. As a result, it possibly shortens duplicated PSI elements. For
example,
```
// FILE: main.kt
package a.b.c

fun test(n: Int) {
    return if (<expr>x.y.z.Outer.Inner.VALUE0 > x.y.z.Outer.Inner.VALUE1</expr>) 1
    else n
}
// FILE: values.kt
package x.y.z

class Outer {
    object Inner {
        val VALUE0 = 13
        val VALUE1 = 17
    }
}
```
for the above code, the existing K2 reference shortener tried to shorten
- x.y.z.Outer.Inner -> Inner
- x.y.z.Outer.Inner.VALUE0 -> VALUE0
- x.y.z.Outer.Inner -> Inner
- x.y.z.Outer.Inner.VALUE1 -> VALUE1

`x.y.z.Outer.Inner` is included in the list to shorten twice.
When it actually shortens the PSI elements, it shortens only
- x.y.z.Outer.Inner.VALUE0 -> VALUE0
- x.y.z.Outer.Inner.VALUE1 -> VALUE1

but it imports all of
- x.y.z.Outer.Inner
- x.y.z.Outer.Inner.VALUE0
- x.y.z.Outer.Inner.VALUE1

As a result, it has unnecessary additional import directives.
This commit fixes the issue by avoiding duplicated shortening for a
single PSI element.
2023-04-10 11:00:11 +00:00
Anna Kozlova 22b0a8d9fb [FIR] reference shortener should not touch fake sources
e.g. implicit types can't be shortened.
On the other hand, requesting textRange means building ast
which might be slow, especially for compiled code
2023-04-06 15:44:02 +00:00
Bart van Helvert f7ec5885f5 KT-56200 Don't leak user code in reference resolve exception 2023-04-06 12:04:13 +00:00
Anna Kozlova de965d39be [LL] always get fir from decompiled stubs 2023-04-06 11:50:39 +00:00
Dmitrii Gridin 03eab387c0 [FIR] FirRenderer: render annotation resolve phase as well
^KT-56543
2023-04-06 08:09:41 +00:00
Nikolay Lunyak 03e2152957 [FIR JS] Support 2 JS diagnostics
The change in `FirDiagnosticsHandler` ensures
`DEBUG_INFO_DYNAMIC` is still reported in
`FirPsiJsOldFrontendDiagnosticsTestGenerated.testConventions`.

Support `SPREAD_OPERATOR_IN_DYNAMIC_CALL` and
`WRONG_OPERATION_WITH_DYNAMIC`
2023-04-05 16:51:51 +00:00
Roman Efremov b368b78faa [FE] Prohibit protected members in final expected or actual classes
^KT-28850 Fixed
2023-04-05 15:25:46 +00:00
Alexander Korepanov 4813b659ab [JS IR] Control an inheritance of non-external entity from external
Add a special annotation @JsExternalInheritorsOnly for marking
 external interfaces and classes. The marked interface or class
 can’t be a parent for non external interfaces, classes or objects.

^KT-57423 Fixed
2023-04-05 09:00:45 +00:00
Kirill Rakhman 674397be82 [FIR] Trim rendered symbols in diagnostic messages 2023-04-05 08:44:56 +00:00
Justin Paupore 6604627fa8 Use registered FIR compiler extensions in Analysis API.
This will allow IDE plugins to contribute compiler plugins to analysis,
above and beyond those used for the actual compilation step. These
plugins can be used to, for example, provide declarations for code that
is generated during build by an external tool.

^KT-57763 fixed
2023-04-05 07:31:08 +00:00
Marco Pennekamp c2acb77b84 [LL FIR] KT-57220 LLFirSessionCache: Clean up symbol provider merging
- `SymbolProviderMerger` encapsulates some boilerplate, which should
  make `mergeDependencySymbolProvidersInto` easier to read and also much
  easier to extend.
2023-04-04 12:45:33 +00:00
Marco Pennekamp 87bcc3ad08 [LL FIR] KT-57220 Don't merge empty synthetic function symbol providers 2023-04-04 12:45:32 +00:00
Marco Pennekamp eac6458500 [LL FIR] KT-57314 Add cache to combined Kotlin symbol providers
- This Caffeine cache is limited to classes for now, but may also be
  tried with callables.
- The cache has a small memory footprint, but still avoids most of the
  unnecessary index accesses. In my local tests, this approach takes 50%
  of the time compared to no caches. A full cache has no performance
  advantage over the limited-size cache in my local tests.
2023-04-04 12:45:32 +00:00
Marco Pennekamp 375288539e [LL FIR] Add NullableCaffeineCache
- `NullableCaffeineCache` wraps a Caffeine cache and allows storing
  `null` values returned by the computation in the form of explicit
  `NullValue`s in the cache.
2023-04-04 12:45:32 +00:00
Marco Pennekamp b805c6e32b [LL FIR] Add Caffeine library dependency
- Our current FIR caches are based on `ConcurrentMap` and thereby do not
  support size and lifetime limits out of the box. For example,
  first-layer caches with a limited size can speed up access of the most
  frequently used elements, while having a small memory footprint.
- Caffeine is a modern and well optimized caching library that allows us
  to create thread-safe and performant caches with various size or
  lifetime limits.
- The cache must support concurrency because session components such as
  symbol providers may be accessed concurrently once parallel resolve in
  the Analysis API has been implemented (see KT-55750). Caffeine caches
  support concurrency.
2023-04-04 12:45:31 +00:00
Marco Pennekamp a7360a54fe [LL FIR] KT-57314 Prepare for getting top-level names from index
- Getting top-level names from `declarationProvider` directly instead of
  from subordinate symbol providers has a lot of potential for
  performance, but the current performance of the index access is worse
  than the iterative version because scopes aren't optimized yet.
- This commit prepares `LLFirCombinedKotlinSymbolProvider` for the
  switch to getting top-level names from `declarationProvider`.
2023-04-04 12:45:31 +00:00
Marco Pennekamp 028d65e402 [LL FIR] KT-57220 Add LLFirSelectingCombinedSymbolProvider
- Classpath order disambiguation will also be needed by the combined
  Java symbol provider, so it makes sense to move it to its own base
  class.
2023-04-04 12:45:31 +00:00
Marco Pennekamp 29276d94ca [LL FIR] KT-57314 Combine Kotlin symbol providers
- `LLFirCombinedKotlinSymbolProvider` combines multiple
  `LLFirProvider$SymbolProvider`s. Its advantages are: combined "names
  in package" optimization, caching, combined index access, classpath
  order disambiguation.
- Scopes can still be optimized with a combined scope instead of a naive
  union scope.

^KT-57314 fixed
2023-04-04 12:45:30 +00:00
Marco Pennekamp 16af67e99c [LL FIR] KT-57314 Allow passing index results to Kotlin symbol provider
- If a `KtClassLikeDeclaration` or all `KtFile`s which contain a
  callable are already known, they can now be passed to
  `LLFirProvider$SymbolProvider` directly. This avoids index accesses in
  `providerHelper`.
2023-04-04 12:45:30 +00:00
Marco Pennekamp bf1ee6ebed [LL FIR] KTIJ-24296 LL FIR symbol provider: Remove function class check
- `LLFirProvider$SymbolProvider` cannot provide synthetic function
  classes, so there is no need to check `isNameForFunctionClass` for the
  `ClassId`.
2023-04-04 12:45:30 +00:00
Kirill Rakhman 085df96afe [FIR] Make Volatile diagnostics applicable to kotlin.concurrent.Volatile
#KT-55628 Fixed
2023-04-04 10:36:39 +00:00
Mikhail Glukhikh bd27ec840c K1: report swallowed diagnostic about receiver type mismatch
#KT-55056 Fixed
2023-04-03 16:35:55 +00:00
Denis.Zharkov 56557fb8ff K2: Fix generic inference case with !! synthetic call
Result of the `checkNotNull` calls should always be a non-nullable
values.
The simplest idea how to acheive it is adding not-nullable Any bound
to the type parameter declaration.

Existing comment stating about impossibility of such bound seems to be
not 100% correct because it doesn't take into account presence of
definitely-non-nullable X & Any types that allow described case with
nullable generic.

^KT-55804 Fixed
2023-04-03 12:44:52 +00:00
Dmitrii Gridin faeafbbe29 [FIR][tree] replace FirDeclaration.resolvePhase -> resolveState
Lazy resolve state represents the lazy resolve
state of the current declaration
It can be either resolved or be in a process of resolve

^KT-56543
2023-04-01 06:53:27 +00:00
Dmitrii Gridin 77e1bc6f9e [LL FIR] calculate lazy bodies for type annotations
^KT-56543
2023-04-01 06:39:46 +00:00
Marco Pennekamp d266f49c7c [LL FIR] KTIJ-25096 Add option to exclude binaries when incrementing modification trackers
- In performance tests, modification trackers were incorrectly
  incremented between tests for binary modules even with library caches
  enabled. The new option `includeBinaryTrackers` can be used by
  performance tests to exclude binary modules.
2023-03-31 15:40:14 +00:00