Commit Graph

958 Commits

Author SHA1 Message Date
Kirill Rakhman 26fae9e83a [FIR] Allow declarations to override parts of non-trivial intersection
A class can inherit two declarations that are compatible from the
overridability standpoint and are therefore combined to a non-trivial
intersection.
At the same time, the class can declare a member declaration that
only overrides one of the intersection's members.
In this case, we break up the intersection and only add the overridden
parts to the declared member's direct overridden list.

If the class doesn't override the intersection, it exists as
intersection override, like before.

#KT-65487 Fixed
2024-02-20 09:02:39 +00:00
Kirill Rakhman 889182629e [FIR] Simplify JavaOverridabilityRules.shouldApplyJavaChecker 2024-02-20 09:02:39 +00:00
vladislav.grechko d753a22fc6 [FIR] Handle expect declarations in JVM backend
1. Do not generate bytecode for expect declarations

2. Serialize @OptionalExpectation annotations into .kotlin_module file

^KT-62931: Fixed
2024-02-19 18:17:37 +00:00
Kirill Rakhman 81e0abeb8f [FIR] Fix mapped constructor hiding logic
Partially reverts 24367e0ad8

Constructors have their own list of hidden/visible.
We now require the constructor to be in VISIBLE_CONSTRUCTOR_SIGNATURES,
everything else is hidden.
This makes it unnecessary to check HIDDEN_CONSTRUCTOR_SIGNATURES

#KT-65821 Fixed
2024-02-15 13:08:15 +00:00
Kirill Rakhman eae72eac54 [FIR] Fix substitution of Java arrays enhanced for warning
... w.r.t the variance of their type arguments.
Because `Object[]` is represented as `Array<Any>..Array<out Any>?`,
when we substitute, we can't just take the upper bound because it
changes the variance of the type agument.
Instead, we construct a flexible type and use both bounds, like with
collections with flexible mutability.

#KT-65246 Fixed
2024-02-15 10:48:56 +00:00
Kirill Rakhman 35e9170af1 [FIR] Rename hidden methods around HiddenEverywhereBesideSuperCalls and add documentation. 2024-02-14 13:13:01 +00:00
Kirill Rakhman 24367e0ad8 [FIR] Implement isHiddenEverywhereBesideSuperCalls logic for constructors
#KT-61448 Fixed
2024-02-14 13:13:01 +00:00
Kirill Rakhman 2f49272c42 [FIR] Create fake hidden versions of List.getFirst/getLast in JDK < 21
... so that overrides are marked as deprecated regardless of the JDK.

#KT-65440 Fixed
2024-02-14 13:13:01 +00:00
Kirill Rakhman fc6d25e50f [FIR] By default, only hide members from mapped scope but not overrides
This affects methods like List.getFirst/getLast where it was decided
to keep them hidden but to make them visible on overrides like
ArrayList or LinkedList.
The goal is to prevent a breaking change since some implementations
like LinkedList had this method before JDK 21.

#KT-65438
2024-02-14 13:13:00 +00:00
Kirill Rakhman e88865e4c7 [FIR] Fix methods with erased parameters missing from raw collection scope
#KT-65448 Fixed
2024-02-14 09:55:24 +00:00
Mikhail Glukhikh 8f906ca669 K2: refactor/simplify/comment processOverridesForFunctionsWithDifferentJvmName 2024-02-09 19:04:42 +00:00
Mikhail Glukhikh a189509353 K2: build override structure for Java renamed builtins more precisely
#KT-65410 Fixed
2024-02-09 19:04:42 +00:00
Mikhail Glukhikh c6f5e5f297 Add Kdoc to processOverridesForFunctionsWithDifferentJvmName 2024-02-09 19:04:42 +00:00
Mads Ager 79eee6de4f [FIR] Do not enhance nullability for annotation interface field types.
Java annotation interface fields are constant declarations that can
have any Java type and are not restricted in the same way that
method return types are for annotation interfaces.

#KT-65482 Fixed
2024-02-06 09:45:34 +00:00
Kirill Rakhman d937fb4350 [FIR] Fix exception in scopes caused by property and extension property with the same name in KJK hierarchy
#KT-65373 Fixed
2024-02-02 08:51:10 +00:00
Mikhail Glukhikh 7615d863d5 K2: add ACCIDENTAL_OVERRIDE_CLASH_BY_JVM_SIGNATURE for clashing functions
This diagnostic is reported on an explicitly-declared function which
overrides a regular Java function with the same signature as a hidden
one from the same scope.

#KT-64846 Fixed
2024-01-31 17:06:36 +00:00
Mikhail Glukhikh 3b164e560c JavaClassUseSiteMemberScope: add KDoc 2024-01-31 17:06:36 +00:00
Mikhail Glukhikh c0e0b4d32b K2/Java: cleanup code around processOverridesForFunctionsWithErasedValueParameter
#KT-64846 In Progress
2024-01-31 17:06:36 +00:00
Mikhail Glukhikh ac729e28da K2/Java: fix processing of built-in with value parameters to be erased in Java
In this commit we started to create and process a hidden copy
for a built-in functions, which value parameters are erased in Java,
in case we have an accidental Java override which value parameters
are not erased.

In this situation attempt to override such a Java override in Kotlin
again will lead to inaccessible functions
(see changes in containsAndOverload.fir.kt)

#KT-64846 In Progress
2024-01-31 17:06:35 +00:00
Kirill Rakhman 1238f081b7 [FIR] Defer computation of intersection override return type if overridden has implicit return type
#KT-59921
2024-01-31 11:16:50 +00:00
Kirill Rakhman 9ec0210c04 [FIR] Support enhancing intersection overrides
When a type annotated with @PurelyImplements (explicitly or implicitly)
inherited some methods from a java supertype and the purely implemented
Kotlin supertype, it was inconsistent which of the signatures the
intersection override would have (with or without flexible types).
This commit adds support for the enhancement of intersection overrides.
If one of the overridden methods has non-flexible types, the enhanced
method will have non-flexible types.
This fixes some false negative nullability type mismatches.

#KT-59921 Fixed
2024-01-31 11:16:50 +00:00
Mikhail Glukhikh ed246d372b K2: introduce platform-dependent filtering for non-JVM platforms
This commit fixes a false negative in testData/cli/metadata/getOrDefault
Related to KT-57268
2024-01-30 19:44:00 +00:00
Mikhail Glukhikh 672b5ba0d7 K2/Java: implement platform-dependent function filtering in JvmMappedScope
We drop Kotlin function 'remove' or 'getOrDefault' from JvmMappedScope,
if it has platform-dependent annotation, and the bound Java class scope
does not contain a function with the same signature.

#KT-57268 Fixed
2024-01-30 19:44:00 +00:00
Alexander Udalov 7d584e0eb4 K2/Java: add initial version of FirJvmPlatformDeclarationFilter
#KT-57268 In Progress
2024-01-30 19:44:00 +00:00
Simon Ogorodnik 53e89a9722 K2. Minor. Rename FirConstExpression to FirLiteralExpression
FirConstExpression is usually confused with "constant" calculations,
while in fact, it just denotes a simple literal expression
and `1 + 1` isn't represented by a FirConstExpression.

^KT-64314 Fixed
2024-01-25 23:05:15 +00:00
Dmitriy Novozhilov 3fba3b703e [FIR] Update call-sites which are interested in annotation arguments
After the previous commit, enum entry access to the annotation may be
  presented by two different nodes

^KT-64975
2024-01-25 15:55:19 +00:00
Dmitriy Novozhilov a4e8be8687 [FIR] Deserialize enum entries access in annotations into FirEnumEntryDeserializedAccessExpression
^KT-64975 Fixed
^KT-62900
2024-01-25 15:55:19 +00:00
Dmitriy Novozhilov 150ff1172e [FIR] Add session parameter to all "element --> reference" utilities
`FirDeserializedEnumAccessExpression` requires session to build proper
  reference, so it's important to have it in all utilities, which may
  pass this element as input

^KT-64975
2024-01-25 15:55:19 +00:00
Mikhail Glukhikh e42c1be354 K2: use intersection scope override checker also in intersection scope
In more details, we use either platform override checker (if we came
from platform) or the combined intersection scope override checker
at this place. Also this commit fixes various places around
JavaOverrideChecker, allowing to apply it in intersection override
checker properly:
- don't consider return types in this place
- apply JavaOverrideChecker if at least one candidate is from Java
- compare type primitivity closer to K1 logic

#KT-62554 Fixed
Partially fixes KT-63242
2024-01-24 08:39:18 +00:00
Mikhail Glukhikh a83d2b7a67 FirJavaElementFinder: return packages with true isValid()
#KT-65111 Fixed
2024-01-19 15:52:14 +00:00
Ivan Kylchik aecf05c4ac [FIR] Use ConeKotlinType to represent vararg's element type
We are using `ConeKotlinType` instead of `FirTypeRef` to represent
that element type of vararg doesn't have any source. It has a type
that was inferred. If we try to specify a source, then we could
end up with the incorrect place for diagnostic.

#KT-59682 Fixed
2024-01-18 13:33:48 +00:00
Kirill Rakhman b8ff04004a [FIR] Make EnhancedTypeForWarningAttribute a data class
(cherry picked from commit 76898ddb0f)
2024-01-18 08:27:10 +00:00
Kirill Rakhman e91e9d8ca8 [FIR] Don't lose error level enhancements in warning-level-enhanced arguments
The error-level enhancement is kept as warning-level and a new
LanguageFeature is introduced to turn the warning into an error.

#KT-63208 Fixed
#KT-63209

(cherry picked from commit 371b1eb3d5)
2024-01-18 08:27:10 +00:00
Kirill Rakhman c39262195d [FIR] Let attributes opt-in to participating in ConeClassLikeTypeImpl structural equality
This is required for EnhancedTypeForWarningAttribute because scopes
should not be reused between cone types with different values of
this attribute.

#KT-63208

(cherry picked from commit 9189154cae)
2024-01-18 08:27:10 +00:00
Kirill Rakhman 8c04206709 Revert "[FIR] Let attributes opt-in to participating in ConeClassLikeTypeImpl structural equality"
This reverts commit 9189154cae.
2024-01-16 09:14:22 +01:00
Kirill Rakhman 121536d2e5 Revert "[FIR] Don't lose error level enhancements in warning-level-enhanced arguments"
This reverts commit 371b1eb3d5.
2024-01-16 09:14:21 +01:00
Kirill Rakhman 9fa889ed61 Revert "[FIR] Make EnhancedTypeForWarningAttribute a data class"
This reverts commit 76898ddb0f.
2024-01-16 09:14:18 +01:00
Kirill Rakhman 76898ddb0f [FIR] Make EnhancedTypeForWarningAttribute a data class 2024-01-15 12:23:27 +00:00
Kirill Rakhman 371b1eb3d5 [FIR] Don't lose error level enhancements in warning-level-enhanced arguments
The error-level enhancement is kept as warning-level and a new
LanguageFeature is introduced to turn the warning into an error.

#KT-63208 Fixed
#KT-63209
2024-01-15 12:23:26 +00:00
Kirill Rakhman 9189154cae [FIR] Let attributes opt-in to participating in ConeClassLikeTypeImpl structural equality
This is required for EnhancedTypeForWarningAttribute because scopes
should not be reused between cone types with different values of
this attribute.

#KT-63208
2024-01-15 12:23:26 +00:00
Mikhail Glukhikh 64948fe48f Minor cleanup: JvmMappedScope 2024-01-06 07:11:27 +00:00
Mikhail Glukhikh f5453690a6 K2: prefer base class sources for JVM mapped functions
This commit is a follow-up to 3cb9396b20
"K2: prefer derived class sources for callable copies (e.g. fake overrides)"

#KT-64044 Fixed
2024-01-06 07:11:27 +00:00
Dmitrii Gridin 37ccf5d4f3 [resolution] KotlinJavaPsiFacade: do not return classes with wrong ClassId
We shouldn't return from `findClass`/`findClasses` Java classes with
`ClassId` different from the requested one

^KT-62892
2024-01-04 15:20:38 +00:00
Dmitrii Gridin 48c36ce475 [FIR] FirJavaFacade: calculate default value for annotations lazily
To avoid contract violation

^KT-62776 Fixed
2023-12-21 18:43:19 +00:00
Mikhail Glukhikh d1edbe0c4b FIR scopes: createSuspendView -> more abstract replaceWithWrapperSymbolIfNeeded
Related to KT-59818
2023-12-21 13:10:17 +00:00
Mikhail Glukhikh 1ebf0f5376 K2: show all Java function with suspend view if possible
This commit fixes two tests related to removed workaround of KT-59818,
and also makes processing suspend functions in J/K hierarchy more consistent.
Before this commit, when we had Java class "suspend" method
(implemented with the help of Continuation) overriding Kotlin suspend fun,
the Kotlin suspend fun was visible in outer use-site scope,
and the Java method was invisible.
Also, we used a special "Java suspend view" just to determine
that Java method overrides Kotlin suspend fun and no more.
After this commit, Java class "suspend" method will be visible
in this hierarchy and Kotlin suspend fun will not.
Also, the "suspend" is visible as a synthetic Kotlin suspend fun
which is more correct.

Related to KT-63233
#KT-59818 Fixed
2023-12-21 13:10:17 +00:00
Mikhail Glukhikh b6d2d23f41 K2: use API instead of FirJavaMethod(Constructor) subtyping in enhancement
FirJavaMethod and FirJavaConstructor are implementation classes.
It's anyway not good to check subtyping using them,
because it makes the code implementation-dependent.
This commit begins to check Java origin instead.
2023-12-21 13:10:16 +00:00
Mikhail Glukhikh 2f29738989 K2: use lookupTag instead of classId in use-site scopes
We used this classId to get an associated symbol,
but this way is anyway not recommended (e.g. problems with local classes).
In this commit we migrated to usage of lookup tags instead.
2023-12-21 13:10:16 +00:00
Marco Pennekamp 6474ff88fa [FIR] FirSymbolNamesProvider: Implement classifier package name sets
- Previously, only callable package name sets were implemented, because
  the compiler cannot economically compute classifier package sets for
  libraries. This has not changed. However, the K2 IntelliJ plugin and
  standalone Analysis API can very easily compute classifier package
  sets. Hence, this commit adds support to `FirSymbolNamesProvider` for
  such sets.
- Similar to callable package sets, classifier package sets (1) improve
  the memory usage of symbol names providers and (2) improve the
  performance of `mayHaveTopLevelClassifier`, which is a significant
  bottleneck in the IDE.
- In many cases, the package sets for callables and classifiers are the
  same. For example, the IDE Kotlin declaration provider computes the
  set of packages that contain any classifier and/or callable, for the
  following reasons: (1) indexing package names without filtering for
  declarations is much faster, (2) computing separate sets is not free
  both in time and memory, and (3) the performance impact of having a
  more narrow set for callables is expected to be negligible. For this
  reason, `FirSymbolNamesProvider.getPackageNames` exists to provide a
  shared package set.
- The `hasSpecific*PackageNamesComputation` properties are required to
  avoid caching the same package set in cached symbol names providers
  twice. Because these properties are constant, they can be checked very
  quickly, and no time has to be wasted trying a specific package set
  computation to find out whether it's supported.

### IDE Performance Results

Package set construction performance improved in the IDE in multiple
benchmarks. This improves the performance of symbol providers overall,
which has a direct impact on completion, code analysis, and Find Usages.

In a local manual run of the `intellij_commit/setUp` Find Usages
performance test, the total time spent in `getClassLikeSymbolByClassId`
improved from ~18.7s to ~11.2s. Due to parallel resolve, this does not
translate to a wall clock improvement of 7 seconds, but rather of a few
seconds.

Some performance tests improved markedly in warmup, with for example
`toolbox_enterprise/genUuid` Find Usages having an improvement in
`StubBasedFirDeserializedSymbolProvider.getClassLikeSymbolByClassId`
from 2.4s to 0.2s. This has a direct impact on the first-run performance
of the tested Find Usages command.

So far, classifier package sets in the IDE are only implemented for
libraries, and library sessions are cached after the first warmup.
Because the biggest impact of classifier package sets is avoiding
computation of "class names in package" sets, the impact of this
optimization is not accurately reflected in the timings reported by our
performance tests. `toolbox_enterprise/genUuid` above is a good example,
as the warmup timings are great, but after warmup,
`StubBasedFirDeserializedSymbolProvider.getClassLikeSymbolByClassId`
improved only from 150ms to 70ms.

`toolbox_enterprise/genUuid` is another example, as we can confidently
say that the first-run Find Usages performance has improved (which makes
a difference for the user), but it is unclear by how much, as warmup is
not measured in performance tests.

The same optimization for source sessions will be easier to measure, as
source sessions are invalidated after each performance test run. This
commit lays the groundwork for that as well, because source session
support only requires the requisite package set computation in the
IDE declaration provider to be implemented.

^KT-62553 fixed
2023-12-13 14:40:10 +00:00
Ivan Kylchik 79c300209e [K2] Avoid type check for Kotlin's property in ConstUtils
When we check Java field for constant initializer, we could
be asked to get and check the type of Kotlin's property that
is used in this Java field. But there is no guarantee that the type
resolve phase was finished and this type is available. So we just
check for `const` modifier and skip type check.

#KT-63752 Fixed
#KT-62558 Obsolete
#KT-61786 Declined
2023-12-12 13:54:32 +00:00