Commit Graph

1367 Commits

Author SHA1 Message Date
Kirill Rakhman 7a9c516f68 [FIR] Use Throwable as expected type for throw expressions
#KT-58533 Fixed
2023-05-22 14:05:28 +00:00
Dmitrii Gridin 579df97a7c [FIR] errorInLazyResolve: fix typo 2023-05-19 15:30:32 +02:00
Dmitriy Novozhilov b19116d3af [FIR] Provide implementation of ExpectActualMatchingContext for FIR
^KT-58578
2023-05-19 10:19:17 +00:00
Dmitriy Novozhilov 2c2f12d9ac [FIR] Slightly reformat FirFunctionSymbol.kt 2023-05-19 10:19:17 +00:00
Dmitrii Gridin d68cb73930 [FIR] add debug info instead of CCE to some FirBasedSymbol 2023-05-16 08:51:09 +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
Denis.Zharkov efdecc63cb K2: Make filterOutOverridden helper satisfying its contracts
It's obviously expected that all overridden, not only direct ones
are considered

While it likely changes the behavior and some tests are expected to be
changed, original intention was to fix the behavior for other usages
(see later commits) and the part with tests are postponed with KT-58636

^KT-58636 Related
2023-05-11 15:01:37 +00:00
Dmitrii Gridin 9a267176f5 [FIR] move deprecation calculation to COMPILER_REQUIRED_ANNOTATIONS phase
Also, this change adds SinceKotlin and Java.Deprecated to this phase
It fixes some problems with API_NOT_AVAILABLE, so now it is closer to K1

^KT-57648 Fixed
^KT-55723 Fixed
2023-05-11 10:31:52 +00:00
Dmitrii Gridin add47aa041 [FIR] provide correct origin and source to default backing field
Now it is aligned with default accessors
Covered by
analysis/analysis-api/testData/symbols/symbolByReference/accessorField.kt
test

^KT-57648
^KT-55723
2023-05-11 10:31:52 +00:00
Kirill Rakhman 93ee4d7ce7 [FIR] Refactor DiagnosticKind.Syntax into ConeSyntaxDiagnostic
#KT-58469
2023-05-09 13:36:33 +00:00
Mikhail Glukhikh 0906258d03 K2: handle suspend anonymous functions properly in various compiler parts
#KT-58332 Fixed
2023-05-09 09:19:38 +00:00
Kirill Rakhman 4c6b6dd700 [FIR] Render error properties and function in FirRenderer 2023-05-05 09:34:23 +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 3f6432cdc9 [FIR] setup origin for generated enum functions 2023-04-27 11:37:25 +00:00
Mikhail Glukhikh 4589463e92 FirBasedSymbol: call lazyResolveToPhase directly on a backing field 2023-04-25 12:18:27 +00:00
Mikhail Glukhikh 1f05ce2e01 AA/LC: Support annotation property->backing field move
#KT-57462 Fixed
2023-04-25 12:18:27 +00:00
Mikhail Glukhikh dc38ce24f7 K2: fix field annotation splitting and frontend checks
Related to KT-57135
2023-04-25 12:18:26 +00:00
Anna Kozlova 4fe239375f [cls] write contracts information to cls stubs
^ KTIJ-24665
this information would be used to create resolved FirElements from stubs,
so no ProtoBuf would be kept in memory
2023-04-25 08:34:18 +00:00
Dmitrii Gridin 02abafd98d [FIR] do not request lazy resolve on isActual and isExpect for symbols 2023-04-24 14:47:21 +00:00
Dmitrii Gridin 866e8a26c7 [FIR] set correct resolve phase for default getter, setter and backing field
^KT-58163 Fixed
2023-04-21 17:21:17 +00:00
Dmitrii Gridin 2463b904f7 [LL FIR] add ability to suppress contract violation exception
^KT-56543
2023-04-19 20:12:43 +00:00
Dmitriy Novozhilov faf212ca04 [FIR] Don't extract contracts in DFA during non-body resolution stages 2023-04-18 13:31:29 +00:00
Dmitriy Novozhilov 5a92eb2c67 [FIR] Properly track problems in contract description during effect extraction 2023-04-18 13:31:28 +00:00
Dmitrii Gridin 03eab387c0 [FIR] FirRenderer: render annotation resolve phase as well
^KT-56543
2023-04-06 08:09:41 +00:00
Kirill Rakhman 674397be82 [FIR] Trim rendered symbols in diagnostic messages 2023-04-05 08:44:56 +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
Nikolay Lunyak f0720c1d12 [FIR] Fix K2 behavior according to RULES1
The compiler should only report diagnostics for
comparisons over builtins and identity-less types,
other incompatibilities should be reported
via inspections.

It's ok that in `equalityChecksOnIntegerTypes`
instead of `EQUALITY_NOT_APPLICABLE_WARNING` we get
`EQUALITY_NOT_APPLICABLE`, because
`ProperEqualityChecksInBuilderInferenceCalls`
is already active by default.

This change also replaces the notion of a representative superclass
with the least upper bound.
This makes complex types like
intersection/flexible transparent to
RULES1-based compatibility checks.
One way to look at it is to think
that this is an automatic way of handling
type parameters: automatic picking of
"interesting" bounds, and checking them against one another.

Note that `TypeIntersector.intersectTypes`
for `Int` and `T` where `T` is a type parameter
may return both `{Int & T}` or `null`
depending on `T`-s bounds. At the same time,
for type parameters `T` and `K` it will
always return `{T & K}`.

`ConeTypeIntersector.intersectTypes`, on the
other hand, will always return `{Int & T}`
irrespectively of the bounds. Meaning, the two
intersectors differ in corner cases.

`lowerBoundIfFlexible` call in `isLiterallyTypeParameter` is backed by
the `equalityOfFlexibleTypeParameters` test.

^KT-35134 #fixed-in-k2
^KT-22499 #fixed-in-k2
^KT-46383 #fixed-in-k2
2023-03-31 15:01:50 +00:00
Dmitrii Gridin 19dbe69651 [FIR] move deprecations calculation on TYPES phase
can be moved to COMPILER_REQUIRED_ANNOTATIONS phase in the future

^KT-57256 Fixed
2023-03-29 08:52:37 +00:00
Nikolay Lunyak f644eb7988 [FIR JS] Implement FirJsExportDeclarationChecker 2023-03-29 08:51:48 +03:00
Dmitriy Novozhilov e02194b461 [FIR] Properly prohibit access to enum companion in enum entry initialization section
^KT-57456 Fixed
KT-57608
2023-03-28 15:35:12 +00:00
Dmitriy Novozhilov cbfa155333 [FIR] Make FirClass an inheritor of FirControlFlowGraphOwner
Both inheritors of FirClass (FirRegularClass and FirAnonymousObject)
  already were CFG owners
2023-03-28 15:35:11 +00:00
Dmitriy Novozhilov 336b6ba9f0 [FIR] Extract extension functional type from an annotated functional type during deserialization
^KT-57140 Fixed
2023-03-27 10:44:51 +00:00
Dmitrii Gridin a643dfbe83 [FIR][tree] introduce lazy expression to simplify code
^KT-56543
2023-03-24 09:58:38 +00:00
Dmitrii Gridin 8c599a84af [FIR][renderer] add phase renderer for file and file annotations container
^KT-56543
2023-03-24 09:58:11 +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 Kirillov 23e40693a3 [LL FIR] add api to FirLazyDeclarationResolver to resolve class with callable members
^KT-56543
2023-03-24 09:57:45 +00:00
Nikolay Lunyak a2e2a96fd3 [FIR] KT-56846: Unwrap SourceCodeAnalysisException on transformFile
^KT-56846 Fixed

Merge-request: KT-MR-9065
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-03-23 09:54:43 +00:00
Nikolay Lunyak 7b04201e77 [FIR] KT-57104: Preserve @JvmName on fake-override accessors
Otherwise, when we come to `ClassCodegen.kt:173
for `GradleActionTest` and check
`FUN FAKE_OVERRIDE name:<get-project>`,
we then go to `JvmSignatureClashDetector.kt:37`,
and call `mapRawSignature(overriddenFunction)`
which ignores the original `@JvmName`.
It does so because it relies on the property copy
which forgets to copy the getter, but
`@get:JvmName` is stored in it.

Extra when-branches for `FAKE_OVERRIDE` are needed,
because otherwise the annotations would not
be copied in `Fir2IrDeclarationStorage.kt:723`.

Extra when-branches for `DELEGATED_MEMBER` are
needed, because otherwise the generated IR changes
in some tests. For example, see:
`FirLightTreeIrTextTestGenerated.Declarations.testKt35550`.

The `assumesBackingField`-related change is backed by
the `FirLightTreeIrTextTestGenerated.Stubs.testJavaEnum` test.

`this.body = null` ensures the resulting IR
matches K1.

The change in `FirImplicitBodyResolve.kt` is needed,
because otherwise the bootstrap compiler fails at
`:compiler:frontend:compileKotlin`,
but I didn't come up with a smaller test for it.

If we don't make an explicit accessor copy,
then when we later create a `Fir2IrLazyPropertyAccessor`
for the fake override getter, it's `fir` will
be a reference to the `FirProperty`, not `FirPropertyAccessor`.
That's why `DumpIrTreeVisitor` will render `IntrinsicConstEvaluation` as
a getter annotation as well.

`FirPsiIrTextTestGenerated.testDelegatedGenericImplementation`
renders type parameters from `<get-x>`,
because when assigning `extensionReceiverParameter`
of the setter `<set-x>` we come to
`Fir2IrClassifierStorage.kt:638`,
and in this cache there's the parameter with
the `<get-x>` parent.
Note that `typeContext.origin == DEFAULT` in
`getCachedIrTypeParameter`.
It's `DEFAULT` because at the line `Fir2IrDeclarationStorage.kt:335`
the `function` variable is `null` (because there's no setter).

The change in `declarationAttributes.kt` is backed
by the `FirPsiIrTextTestGenerated.testKt45853` test.

^KT-57104 Fixed
^KT-57432 Fixed

Merge-request: KT-MR-9210
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-03-22 18:16:31 +00:00
Simon Ogorodnik a5a3c1ff8d [K2, MPP] Cleanup, remove unused FirDeclaration.actualForExpectMap
The concept of actual for expect map is broken and won't work in IDE
properly, since to fill such map we need to analyze all
dependant modules
2023-03-21 17:16:22 +00:00
Marco Pennekamp 2d85e9db51 [LL FIR] KT-57220 Optimize & combine synthetic function symbol providers
- Dependency symbol providers contained a lot of useless
  `FirExtensionSyntheticFunctionInterfaceProvider`s, because such a
  provider only generates function classes from compiler plugins. If
  there aren't any such `FunctionTypeKind`s in the session, there is no
  need to even add the provider.
- `FirExtensionSyntheticFunctionInterfaceProvider`s that are added to
  the list of dependency providers despite this optimization will now be
  combined in `LLFirCombinedSyntheticFunctionSymbolProvider`. It checks
  `ClassId` heuristics once, which is more efficient than checking them
  in every provider separately.
2023-03-21 16:08:42 +00:00
Ilya Chernikov be2a85be71 K2: support implicit integer to unsigned conversions...
with dedicated opt-in language feature and special
annotation or module capability.
Not intended for a general use, solves specific K/N
scenario with interop libs.
#KT-55902 fixed
2023-03-17 08:57:51 +00:00
Denis.Zharkov 955b8e1490 K2: Introduce new FIR node kind FirFromMissingDependenciesNamedReference
The basic idea is that during deserialization/loading compiled
Java classes, there might be some of the dependencies absent that
are referenced from enum arguments in annotations.

Such situation is not considered as totally ill-formed, thus supporting
it, allowing to read the names of mentioned in the annotation argument
might be useful for Java enhancement

^KT-56656 In Progress
2023-03-16 14:43:05 +00:00
aleksandrina-streltsova 34c739789f [AA] Fix rendering for type variable with "Type is not inferred"
It is required to show type variable name instead of ERROR in completion
^KTIJ-20913
2023-03-16 13:57:56 +00:00
Nikolay Lunyak 967ddb8bb0 [FIR] KT-57211: Generate FirArrayOfCall for unsigned types
^KT-57211 Fixed

Merge-request: KT-MR-9216
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-03-15 17:05:09 +00:00
Kirill Rakhman d20ad67aa9 [FIR] Introduce extension unwrapFakeOverridesOrDelegated() 2023-03-14 09:13:41 +00:00
Kirill Rakhman 9f33c64715 [FIR] Remove duplicate FirCallableSymbol.isStatic extension 2023-03-13 08:48:39 +00:00
Kirill Rakhman b476eee6e3 [FIR2IR] Simplify generation of bound callable reference receivers
Remove a bunch of custom logic to determine when a callable reference is
bound or not (and hence mustn't have a receiver). Instead, a helper
extension is introduced to determine when a callable reference is bound
by checking if dispatch/extensionReceiver is not FirNoReceiver and the
referenced member is not static.

#KT-57253 Fixed
2023-03-13 08:48:39 +00:00
Kirill Rakhman f946ddeb40 [FIR] Implement checks for contract not allowed
^KT-55423 Fixed
2023-03-09 08:32:02 +00:00
Kirill Rakhman 81f858a3c4 [FIR] Require not-null source in buildImplicitTypeRef
KT-56906
2023-03-08 16:20:26 +00:00
Kirill Rakhman 04d57eb2f9 [FIR] Use cached instance of FirImplicitTypeRefImpl
^KT-56906 Fixed
2023-03-08 16:20:25 +00:00