Commit Graph

798 Commits

Author SHA1 Message Date
Dmitrii Gridin 5b3f617378 [FIR] add memberRequiredPhase to declaredMemberScope
^KT-56551
2023-05-19 12:43:45 +00:00
Dmitrii Gridin 71386cc117 [FIR] SignatureEnhancement: fix CME from type parameters enhancement
The problem was that type parameters of Java function were changed
without any synchronization.
In fact, we shouldn't mutate Java declarations at all.
So now we don't mutate type parameters – instead of this,
we mutate only its copy that is safe

^KT-58613 Fixed
^KTIJ-25242 Fixed
^KTIJ-21791 Fixed
2023-05-19 12:17:12 +00:00
Leonid Startsev c4255f9a9e [K2] Instantiation of annotations having default values for properties
This commit adds missing pieces for the puzzle:

Annotation instantiation feature uses IrProperty's initializer to instantiate
properties from other modules that have default values which weren't
specified on call site.

To support this feature properly, Fir2IrVisitor should fill LazyIrProperty's
backing field initializer with information from Fir.

To get this information into Fir, FirMemberDeserializer should be able to read
it from KotlinJvmBinaryClass with AnnotationLoaderVisitorImpl. (klibs are unsupported for now)

There's a catch with enum entries references: we can't access session.SymbolProvider to resolve it
because we're still at the deserialization stage, and it can cause StackOverflow if enum is nested in the
same class (see RequiresOptIn.Level). To mitigate this, a new FirEnumEntryDeserializedAccessExpression is produced
instead; it is later replaced with the correct reference in the Fir2IrVisitor.

^KT-58137 Fixed

Also add test to loadJava folder with annotations default values that
verifies metadata loading
2023-05-12 16:08:02 +00:00
Mikhail Glukhikh 36d6e6dd06 K2: prevent infinite recursion in findJavaSuperClass #KT-55078 Fixed 2023-05-12 08:24:13 +00:00
Kirill Rakhman 993925f656 [FIR] Ignore private properties in accessor override check
JavaClassUseSiteMemberScope won't return a Java method getFoo if there
is an inherited Kotlin property foo in scope because calling this method
would effectively call the property accessor which is not possible in
Kotlin.
This commit excludes private properties from this consideration because
no accessor methods are generated for them, and so calling a Java method
getFoo is ok.

#KT-58577 Fixed
2023-05-11 15:22:42 +00:00
Kirill Rakhman b2fa104081 [FIR] Keep all failed resolution candidates and fully resolve them
Previously, when a candidate was found with an applicability that is
better than the current best applicability, all previous candidates were
thrown away. Now we keep them, unless the new applicability is
successful. If no successful candidates are found, we fully resolve all
the unsuccessful ones and select the ones with the least bad
applicability. This improves diagnostics for unresolved calls.

#KT-57844 Fixed
2023-05-10 11:48:58 +00:00
Dmitrii Gridin c2b09d3b1e [LL FIR] rewrite LLFirSuperTypeTargetResolver
The previous implementation had issues with
locks, publication and performance

Also, this change fixed a problem with mixed cycle inheritance

^KT-56550
^KTIJ-25430 Fixed
^KTIJ-23520 Fixed
^KT-57623 Fixed
^KTIJ-25372 Fixed
^KT-58357 Fixed
2023-05-05 12:35:46 +00:00
Anna Kozlova d59d66e876 [AA, LL] use stubs to build deserialized Fir elements in IDE
^KTIJ-24638

Notice on `DebugSymbolRenderer`:
stub based deserializer sets source directly,
but it's available in IDE mode only.
Thus, standalone and IDE tests have different results.
In order to avoid this, sources for compiled code are explicitly ignored

Notice on distinct callables:
for a file which belong to multiple libraries, decompiled code would be build per library.
In order to avoid ambiguity errors for members in that file,
we need to distinct provided elements by origins
failed test from IJ repo:
 FirReferenceResolveWithCrossLibTestGenerated#testSetWithTypeParameters
2023-04-27 11:37:28 +00:00
Anna Kozlova d491fd2f70 [LL] don't include kotlin classes in combined java provider
do not resolve annotations when short name doesn't match
2023-04-27 11:37:27 +00:00
Dmitrii Gridin 7b91cd0ff3 [FIR] calculate java Target annotation on COMPILER_REQUIRED_ANNOTATIONS phase
^KT-57849
^KT-57949
2023-04-21 10:14:05 +00:00
Dmitrii Gridin efdae98ba8 [FIR] SignatureEnhancement: reduce access to initializer field
It can trigger lazy calculation of FirJavaField initializer

^KT-56543
2023-04-19 20:12:41 +00:00
Nikita Bobko 8314812ef9 2/2 FirUnsupportedSyntheticCallableReferenceChecker: don't report error on FirJavaOverriddenSyntheticPropertySymbol
Meta issue: KT-8575
^KT-58061 Fixed
Review: https://jetbrains.team/p/kt/reviews/9677

This commit fixes an inconsistency between
FirUnsupportedSyntheticCallableReferenceChecker and
UnsupportedSyntheticCallableReferenceChecker

In K1 such properties were not considered synthetic and are called
JavaPropertyDescriptor. That's why we need to do an additional check in
K2 checker, while in K1 we didn't need to do it

Also see the previous commit for more related tests that already was
green without this fix but are related to KT-58061 problem
2023-04-19 14:33:45 +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 f2e3c593a1 [FIR] KT-57207 JavaSymbolProvider: Accept existing JavaClasses
- `javaFacade.findClass` is a potentially costly operation. This commit
  extends `JavaSymbolProvider` and its class cache to accept an already
  existing `JavaClass` if provided, circumventing the `findClass`
  operation.
2023-04-17 11:07:46 +00:00
Marco Pennekamp b33c5f77ac [FIR] Move JavaClass.hasMetadataAnnotation to JavaUtils
- This function will be reused in a later commit.
2023-04-17 11:07:46 +00:00
Marco Pennekamp 288606868e [FIR] KT-57207 Avoid FirJavaFacade.knownClassNamesInPackage in the IDE
- `FirJavaFacade.knownClassNamesInPackage` cannot be computed in the IDE
  using the current strategy because there are multiple finders and
  there is no `CliFinder`. However, the cache was still used, which
  caused it to be filled with `null` values and additionally caused
  worse performance in `JavaSymbolProvider` due to hash map accesses via
  `hasTopLevelClassOf`.
- Rewriting the strategy is non-trivial as additional indices are needed
  on the IDE side. See KTIJ-24642.
2023-04-17 11:07:46 +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
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
Kirill Rakhman 38f0ac332d [FIR] Report INVISIBLE_REFERENCE in imports
#KT-55405 Fixed
2023-03-31 12:54:30 +00:00
Denis.Zharkov 55a58e54fe K2: Rework scopes for types with projection arguments for Out types
The only case when behavior is change is described at
 computeNonTrivialTypeArgumentForScopeSubstitutor

The idea is to avoid depending on the presence of @UnsafeVariance
and instead approximate captured types in covariant argument positions
before building substitution scopes

It's correct because for Captured(*) <: Supertype,
Out<Captured(*)> <: Out<Supertype> and when we've got @UnsafeVariance
value parameters at Out, it's ok to allow passing Supertype there.

^KT-57602 Fixed
^KT-54894 Fixed
2023-03-29 10:45:40 +00:00
Marco Pennekamp f9785c1050 [LL FIR] KT-57455 Avoid creating optional annotation class providers
- An `OptionalAnnotationClassesProvider` only needs to be created if the
  package part provider may even have optional annotation classes.
- In the IDE case, the package part provider never provides optional
  annotation classes, so especially in the IDE, we can avoid a lot of
  useless symbol providers with this.
2023-03-27 10:38:50 +00:00
Dmitrii Gridin 706ff6b61f [FIR] pre-resolve some scope callables before creating a scope
In a lot of cases, when we want to process the
declaration in scope, it should be resolved to at least TYPES phase.

To avoid doing it manually in all our variety of scopes, we do it when the scope it created.
It was implicitly working manually before as lazy resolve did a lot of extra work
on resolving a declaration it was not supposed to resolve.
Now it's not the case, and we have to explicitly resolve all the declarations we need.

^KT-56543

Co-authored-by: Ilya Kirillov <ilya.kirillov@jetbrains.com>
2023-03-24 09:57:46 +00:00
Ilya Chernikov 0e77b67170 K2: implement correct check for ctors mapped from java
so the check is functionally the same as in K1.
#KT-57064 fixed
#KT-57065 fixed
One of the tests introduced here (javaMappedCtors) revealed an
additional issue, filed as KT-57368
2023-03-20 11:33:34 +00:00
Denis.Zharkov 3e2f8b834c K2: Replicate K1 enhancement behavior for warning-mode top-level types
^KT-56657 Fixed
^KT-57307 Related
2023-03-17 08:52:31 +00:00
Denis.Zharkov 644391a8e0 K2: Fix Java enhancement when jsr305.jar is not in classpath
In that case, when loading Java, we just remember the name of `@Nonnull`
argument (javax.annotation.meta.When), and then use it during enhancement

^KT-56656 Fixed
2023-03-16 14:43:05 +00:00
Mikhail Glukhikh 58959951d3 K2: fix CCE during bound conversion for Java raw Kotlin-based type
#KT-56630 Fixed
2023-03-15 13:40:49 +00:00
Kirill Rakhman 9f33c64715 [FIR] Remove duplicate FirCallableSymbol.isStatic extension 2023-03-13 08:48:39 +00:00
Marco Pennekamp 1c46d37663 [AA] KT-56617 Build FirClassSymbols for Java classes lazily
- Some completion performance tests (e.g. IntelliJ: "empty place typing
  with library cache") spent a considerable amount of time in
  `KtFirSymbolProviderByJavaPsi.getNamedClassSymbol`.
- This commit introduces `KtFirPsiJavaClassSymbol`, which implements
  many `KtNamedClassOrObjectSymbol` properties with the `PsiClass`
  instead of the FIR class. The `FirClassSymbol` is built only when
  necessary. This improves performance when no "slow" properties need to
  be computed for the symbol.

^KT-56617 fixed
2023-03-09 18:35:56 +00:00
Marco Pennekamp 9cc6809ec6 [FIR] Fix JavaClass.modality for annotation classes and enums
- `JavaClass.modality` should return the correct modality instead of
  requiring the caller to handle annotation classes and enums.
2023-03-09 18:35:56 +00:00
Kirill Rakhman f946ddeb40 [FIR] Implement checks for contract not allowed
^KT-55423 Fixed
2023-03-09 08:32:02 +00:00
Ivan Kochurkin d829f8b684 [FIR] Drop using of JavaSymbolProvider and OptionalAnnotationClassesProvider in FirCommonSessionFactory
Drop using of all Java stuff inside FirCommonSessionFactory

^KT-56063
2023-03-03 20:58:24 +00:00
Kirill Rakhman 9268fd0e87 [FIR] Call enum entries in deserialized annotations as property access
KT-56177
2023-02-28 10:19:15 +00:00
Dmitriy Novozhilov f836d16dc6 [FIR] Don't generate synthetic declarations from java records from binary dependencies
^KT-56548 Fixed
2023-02-28 09:17:40 +00:00
Dmitriy Novozhilov 244dbb37cf [FIR] Properly set isOperator flag for java functions
^KT-56875 Fixed
2023-02-28 09:17:40 +00:00
Denis.Zharkov b4b443034f K2: Fix false-positive OVERLOAD_RESOLUTION_AMBIGUITY
It's been introduced in the previous commit
("K2: Simplify handling mixed smartcast vs. original candidates")

Because previously, it was assumed wrongly that each next level of
ConeCallConflictResolver filter out the candidates that are 100% less
applicable/specific, but the main one (ConeOverloadConflictResolver)
either leaves the single candidate or the whole same set, thus at
FilteringOutOriginalInPresenceOfSmartCastConeCallConflictResolver
we've got 4 candidates only two of which we might filter out.
2023-02-15 08:13:57 +00:00
Denis.Zharkov 1e1d122dd3 K2: Simplify ConeConflictResolver hierarchy
Remove AbstractConeCallConflictResolver super class where it's actually
unnecessary
2023-02-15 08:13:56 +00:00
Denis.Zharkov b6b132a9a3 K2: Avoid false-positive overload resolution ambiguity with smart casts
The idea is that when we have successful candidates both from smart cast
and original type, we should discriminate in the favor of former ones.

While this problem (see kt55722.kt) existed before this branch is merged,
initially it was recognized on FP Ultimate when we stopped assuming
captured types from the same projections as equal (see kt55722Initial.kt).

^KT-55722 Fixed
^KT-55024 Fixed
^KT-56283 Related
^KT-56310 Related
2023-02-15 08:13:54 +00:00
Denis.Zharkov 427b221eaf K2: Get rid of redundant parameter of ConeCallConflictResolver methods
discriminateGenerics was only set to false in recursive calls of
ConeOverloadConflictResolver
2023-02-14 07:14:10 +00:00
Kirill Rakhman 314784f435 [FIR] Introduce FirDeclarationStatus.hasStableParameterNames
This flag is true by default but is set to false for

- Java methods and constructors
- interface delegation methods that delegate to Java

The NAMED_ARGUMENTS_NOT_ALLOWED logic is mostly refactored to use the
new flag though some custom logic remains for determining the correct
message and to work around a corner case with fake overrides.

The flag is (de)serialized from/to metadata. For backward compatibility
with K1, delegated methods to Java types are deserialized as stable.

^KT-40480 Fixed
2023-02-13 12:09:39 +00:00
Kirill Rakhman 152e63b198 [FIR] Remove redundant setting of DeclarationStatus properties 2023-02-13 12:09:39 +00:00
Dmitriy Novozhilov ea73cde5fb [Lombok] Make visibility of fields of @Value classes private by default (K2)
^KT-51092 Fixed
2023-02-10 12:30:13 +00:00
Dmitriy Novozhilov ff4c5c1d03 [FIR] Pass symbol of containing class to FirStatusTransformerExtension instead of fir node 2023-02-10 12:30:13 +00:00
Kirill Rakhman 22fd7921fe [FIR] Introduce MetadataBasedAnnotationDeserializer for compiling common
^KT-56361 Fixed
2023-02-08 13:32:33 +00:00
Ivan Kochurkin a9bac2f18b Add PackageAndMetadataPartProvider interface
Use it for parameter in MetadataSymbolProvider
2023-02-07 14:16:29 +00:00
Dmitriy Novozhilov 125b773205 [FIR] Introduce utility for creating ConeClassLikeLookupTagImpl from ClassId
`classId.toLookupTag()` looks much cleaner than `ConeClassLikeLookupTagImpl(classId)`
2023-02-02 08:24:48 +00:00
Dmitriy Novozhilov d856ae1f35 [FIR] Move common members in symbols up in the hierarchy 2023-01-31 07:53:11 +00:00
Artem Vasilev ccc3f52acf [FIR] Rename FirSyntheticPropertiesStorage, extract property creation 2023-01-30 20:05:51 +00:00
Artem Vasilev 075a80613b [FIR] Introduce cache for not-yet-enhanced synthetic properties
The original synthetic properties from Java were not cached anywhere and
created anew for every session. However, the enhanced properties are
(along with their originals) saved inside the session's cache, causing
inconsistency with newly created symbols via referential equality.
2023-01-30 20:05:50 +00:00
Mikhail Glukhikh 938e1d5ce8 K2: copy explicit receiver to dispatch receiver for static member accesses
Related to KT-55116
2023-01-26 15:27:57 +00:00
Kirill Rakhman f6c189be7b FIR: Handle visibility of public setter of protected synthetic property like in K1
K1 allows writing access to a public setter of a protected synthetic
property only if the call is inside a subclass. K2 previously allowed
that unconditionally. This changes brings the behavior in line with K1.

^KT-56050 Fixed
2023-01-26 11:33:30 +00:00