Commit Graph

106705 Commits

Author SHA1 Message Date
Nikita Bobko 1aeefe6c33 [FIR] Don't traverse expect hierarchy to check DefaultArgumentsInExpectActualizedByFakeOverride
^KT-63860 Fixed
Review: https://jetbrains.team/p/kt/reviews/13334/timeline

The previous code was nonsense (I wrote it). It doesn't make sense to
subtract actualOverriddenDeclarations from expectOverriddenDeclarations.
Default parameters are mentioned on the expect side. So default params
in expect/actual supertypes won't be subtracted from
expectOverriddenDeclarations (but should be)
2023-12-05 13:30:14 +00:00
Sergej Jaskiewicz d0f87f9aba [FIR/IR generator] Rename field's needAcceptAndTransform to isChild
This better describes the semantics.
2023-12-05 11:41:02 +00:00
Simon Ogorodnik 02052421e6 K2 Inference. Fix naming of locals to match its purpose
There were a number of locals where components of InitialConstraint were
named lower and upper in the FirBuilderInferenceSession.

That is not true for equality constraints, so such naming should be
avoided to avoid misconception about the nature of type relation encoded
in constraint.

^KT-64031 Fixed
2023-12-05 10:45:09 +00:00
Yahor Berdnikau b7d6cdb6eb [Gradle] Fix warning in GradleCompilationResults
^KT-56904 In Progress
2023-12-05 09:26:45 +00:00
Dmitriy Novozhilov c3fdbab7fe [FIR] Get rid of FirProvidedDeclarationsForMetadataService.getProvidedNestedClassifiers
It's now impossible to add new classes to metadata, because this
  functionality is not implemented in IrGeneratedDeclarationsRegistrar
  and FirDeclarationsForMetadataProviderExtension is removed
2023-12-05 10:21:40 +02:00
Dmitriy Novozhilov 139e1223ea [Serialization] Workaround registering static writeSelf method in metadata
`IrGeneratedDeclarationsRegistrar` assumes that all generated functions
  are correct from a Kotlin point of view. But `writeSelf` method on JVM
  is a static method outside any object/companion object

So to properly calculate containing class for this method we should
  generate a dispatch receiver parameter, register the method in metadata,
  and then remove the parameter (to make function static)
2023-12-05 10:21:40 +02:00
Dmitriy Novozhilov 51dcd7c076 [Serialization] Introduce utility for generation of IR annotation calls 2023-12-05 10:21:40 +02:00
Dmitriy Novozhilov c70c8f927e [FIR] Remove FirDeclarationsForMetadataProviderExtension extension
`IrGeneratedDeclarationsRegistrar` should be now used instead to register
  IR declarations in resulting metadata
2023-12-05 10:21:40 +02:00
Dmitriy Novozhilov d94ce4dcb8 [Serialization] Migrate to IrGeneratedDeclarationsRegistrar API
^KT-63591 Fixed
2023-12-05 10:21:39 +02:00
Dmitriy Novozhilov 159bc1b435 [IR] Introduce API to register generated IR declaration to be present in metatada
KT-63881
2023-12-05 10:21:38 +02:00
Dmitriy Novozhilov 1cdc8361d6 [IR] Rename IrAnnotationsFromPluginRegistrar to IrGeneratedDeclarationsRegistrar
In further commits, this service will be used not only for registering
  annotations, but newly generated IR declarations too
2023-12-05 10:21:27 +02:00
Simon Ogorodnik 751defc812 K2 Inference: Remove unreachable condition.
The condition was added to the substitute function, when it was also
re-used in delegate inference.
However, delegate inference no longer uses this function.
It is not very possible to both have variable fixed and being present in
nonFixedToVariablesSubstitutor in builder inference.

^KT-64028 Fixed
2023-12-04 21:56:03 +00:00
Simon Ogorodnik 2037714eec K2 Inference: Add doc to the substituteNonFixedToVariables function 2023-12-04 21:56:03 +00:00
Simon Ogorodnik 8bf7c30407 K2 Inference: Remove overloading of FirBuilderInferenceSession.substitute
There are two overloads of substitute function
in the FirBuilderInferenceSession.
In fact, it has very different usage and semantics.

Relates to KT-64028
2023-12-04 21:56:03 +00:00
Mikhail Glukhikh 1f989dce64 K2: add test for KT-56520, case (7), qualifier receivers (4.2)
This commit covers enum entry vs companion member case,
when two companion objects are in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets two candidates with companions.
After that it tries to resolve Some as a qualifier,
but we have no scope with a single qualifier, so no influence here.
With two ambiguous candidates with companions for Some,
OVERLOAD_RESOLUTION_AMBIGUITY is reported.
2023-12-04 21:50:46 +00:00
Mikhail Glukhikh 63ce4ba6b0 K2: add test for KT-56520, case (7), qualifier receivers (4.1)
This commit covers enum entry vs companion member case,
when one companion object is in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets the only candidate with companion.
After that it tries to resolve Some as a qualifier,
but we have no scope with a single qualifier, so no influence here.
Finally during foo resolve it should choose between enum entry and
companion member, and enum entry wins due to KT-37591.
2023-12-04 21:50:45 +00:00
Mikhail Glukhikh 76b2b9fc66 K2: add test for KT-56520, case (7), qualifier receivers (3)
This commit covers object vs static member case,
when no companion objects are in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets two erroneous candidates
without companions. After it tries to resolve Some as a qualifier,
but we have no scope with a single qualifier.
That's why we finally report NONE_APPLICABLE on candidates with companions.
2023-12-04 21:50:45 +00:00
Mikhail Glukhikh 602801dcfd K2: add test for KT-56520, case (7), qualifier receivers (2.2)
This commit covers object vs companion member vs static member case
but now we have two different companions (first is empty) in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets some/Some & some2/Some
because both of them have a companion. This means ambiguity.
After it tries to resolve Some as a qualifier, but we have no scope
with a single qualifier, so finally we prefer to report ambiguity
from variable access resolve.
2023-12-04 21:50:44 +00:00
Mikhail Glukhikh ab161333a7 K2: add test for KT-56520, case (7), qualifier receivers (2.1)
This commit covers object vs companion member vs static member case
in situation with only one companion in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets only some2/Some
because it has a companion. Then it tries to resolve Some as a qualifier,
but here we have an ambiguity, so finally Some with companion is preferred.
2023-12-04 21:50:43 +00:00
Mikhail Glukhikh c2ac9daa7f K2: add test for KT-56520, case (4), callable references (unbound)
Again, both frontends here ignored classifiers from
explicit star imported scope (some.HashMap, java.util.HashMap)
because of their ambiguity. In case of K2, it works so due to logic
in BodyResolveComponents.resolveRootPartOfQualifier.
This function is called to resolve qualifier without receiver.
See also cases (3) and (7).
2023-12-04 21:50:43 +00:00
Mikhail Glukhikh f0058ee0d8 K2: add test for KT-56520, case (4), callable references (bound)
In this test, things work in the similar way as in constructors case (2).
K1 resolves the explicit receiver HashMap<String, String>()
to kotlin.collections.HashMap /* = java.util.HashMap */.
K2 does the similar, but fun processConstructors from ConstructorProcessing.kt
makes a type alias substitution, so in fact constructor of expanded
java.util.HashMap is processed.

Pay attention that both frontends ignore some.HashMap and java.util.HashMap
due to ambiguous classifiers in explicit star importing scope.
See FirScope.processConstructorsByName in ConstructorProcessing.kt
2023-12-04 21:50:42 +00:00
Mikhail Glukhikh 168717b811 K2: add test for KT-56520, case (7), qualifier receivers (1)
Again, both frontends here ignored classifiers from
explicit star imported scope (some.HashMap, java.util.HashMap)
because of their ambiguity. In case of K2, it works so due to logic
in BodyResolveComponents.resolveRootPartOfQualifier.
This function is called to resolve qualifier without receiver
2023-12-04 21:50:42 +00:00
Mikhail Glukhikh 22d083a7a9 K2: add test for KT-56520, case (3), class literals
Again, both frontends here ignored classifiers from
explicit star imported scope (some.HashMap, java.util.HashMap)
because of their ambiguity. In case of K2, it works so due to logic
in BodyResolveComponents.resolveRootPartOfQualifier.
This function is called to resolve qualifier without receiver, in case
it's used as a receiver itself (::class counts as a selector equivalent).
2023-12-04 21:50:41 +00:00
Mikhail Glukhikh 6fb88102a5 K2: add test for KT-56520, cases (1), (5), (6), type references
In both these situations, we have some.HashMap & java.util.HashMap
from explicit star importing scope, and kotlin.collections.HashMap
from implicit star importing scope after it.
K1 ignores both explicitly imported classifiers due to their ambiguity,
and then resolves to kotlin.collections.HashMap at the next level.
In contrast, K2 takes explicitly imported classifiers and
properly reports ambiguity.
2023-12-04 21:50:40 +00:00
Mikhail Glukhikh d07f3a14e6 K2: add test for KT-56520, case (2), constructors, Space subcase
In this test, both frontends resolve to fun Semaphore.
Both work this way because interface/class Semaphore classifiers are
clashed (ambiguity) and ignored.
K2 reports ambiguity for some similar cases,
but constructor resolve still ignores ambiguous classifiers when found.
(see FirScope.processConstructorsByName in ConstructorProcessing.kt)
2023-12-04 21:50:40 +00:00
Mikhail Glukhikh 6049f8657b K2: add test for KT-56520, case (2), constructors
In this test, K1 resolves to kotlin.collections.HashMap /* = java.util.HashMap */
K2 does the similar, but fun processConstructors from ConstructorProcessing.kt
makes a type alias substitution, so in fact constructor of expanded
java.util.HashMap is processed.

Pay attention that both frontends ignore some.HashMap and java.util.HashMap
due to ambiguous classifiers in explicit star importing scope.
See FirScope.processConstructorsByName in ConstructorProcessing.kt
2023-12-04 21:50:39 +00:00
Sebastian Sellmair 0713866c1e [K/N] Modularise :kotlin-native:native.backend to extract objc header generation (2/2)
^KT-63905 Fixed
2023-12-04 18:52:08 +00:00
Sebastian Sellmair ae9f3d66c2 [K/N] Modularise :kotlin-native:native.backend to extract objc header generation (1/2)
^KT-63905
2023-12-04 18:52:08 +00:00
Nataliya.Valtman 4294c7bab7 Add limitation for changed files list for JPS build report
#KT-63549
2023-12-04 18:19:15 +00:00
Anton Lakotka 6eeb459076 [Gradle] Add defaultDestinationDir to FatFrameworkTask
To prevent cycle when updating destinationDirProperty
2023-12-04 18:08:09 +00:00
Anton Lakotka 8b335ea051 [Gradle] Add destinationDirProperty to FatFrameworkTask
And use gradle's projectLayout.buildDirectory instead deprecated
project.buildDir.

^KT-56904
2023-12-04 18:08:09 +00:00
Evgenii Mazhukin 834602b737 [Tests] Add javadoc for @TestMetadata
Merge-request: KT-MR-13338
Merged-by: Evgenii Mazhukin <evgenii.mazhukin@jetbrains.com>
2023-12-04 17:29:42 +00:00
Roman Golyshev 776926518d KT-59732 [FIR] Add testdata to check incorrect imports with test compiler plugins 2023-12-04 16:51:46 +00:00
Roman Golyshev 99c7fab401 KT-59732 [FIR] Adjust test data for the absence of unresolved imports
Now there are no real unresolved imports - all imports are considered
resolved starting from the IMPORTS phase and until they are proven
otherwise in the checkers.

Because of that, some `UNRESOLVED_REFERENCE` diagnostics are gone -
in the cases when such references were actually resolved through
those unsupported imports.

The compilation of incorrect files should not be affected by this,
the checkers would still prevent the compilation of the files with
incorrect imports.
But now the references to the declarations from such imports no longer
will be highlighted as unresolved references.
2023-12-04 16:51:46 +00:00
Roman Golyshev ad2c77b298 KT-59732 [FIR] Get rid of FirErrorImport node
It's no longer relevant, since it's not created anywhere
2023-12-04 16:51:46 +00:00
Roman Golyshev d6d9402b66 KT-59732 [FIR] Move reporting ConeUnresolvedParentInImport errors to FirUnresolvedInMiddleOfImportChecker 2023-12-04 16:51:46 +00:00
Roman Golyshev cd62f2f7a4 KT-59732 [FIR] Do not perform an actual resolve during IMPORTS phase
Use `FirSymbolProvider` to find the longest existing package, and
assume that the rest of the import is class name
2023-12-04 16:51:46 +00:00
Kirill Rakhman 476a0b6783 [FIR] Don't capture flexible types that only have projections in one bound
This fixes a false positive NEW_INFERENCE_ERROR.
See the code comment for the rationale.

#KT-63982 Fixed
2023-12-04 15:42:12 +00:00
Simon Ogorodnik eaa93b2582 K2: Add todo about builder inference session 2023-12-04 15:27:21 +00:00
Simon Ogorodnik c2ddbfc93b K2: Fix false-positive error with captured types in builder inference
Error arises from the fact that type substitution operation isn't
consistent when applied to captured types.

E.g.:
```
substitution = { A => B }
substituteOrSelf(C<CapturedType(out A)_0>) -> C<CapturedType(out B)_1>
substituteOrSelf(C<CapturedType(out A)_0>) -> C<CapturedType(out B)_2>
C<CapturedType(out B)_1> <!:> C<CapturedType(out B)_2>
```

Relates to KT-53749
2023-12-04 15:27:21 +00:00
Simon Ogorodnik d46075a9db K2: Use correct position for substitution constrains in builder inference
Before, we were wrapping the original constraint position into
ConeBuilderInferenceSubstitutionConstraintPosition twice during the
constraint substitution in builder inference.

It was causing problems with diagnostic reporting.

Remove TODOs about diagnostic reporting from FirBuilderInferenceSession.
Propagation of errors from the common system is now implemented
Diagnostic reporting in updateCalls isn't needed, since we
report errors after the system completion unlike K1

Relates to KT-53749
2023-12-04 15:27:21 +00:00
Simon Ogorodnik 2f367b013a K2: Don't lose constraint errors in the builder inference session
Pass constraint errors from the integration system into a candidate to
make sure it is reported later.

Related to KT-59426, KT-59437, KT-53749
#KT-55168 Submitted
2023-12-04 15:27:20 +00:00
Simon Ogorodnik cb3d65f669 [Test] Add test for KT-63996
False-positive TYPE_MISMATCH in builder inference with captured types
2023-12-04 15:27:20 +00:00
Nikita Bobko 48fdeeb42d [FIR, IR] Cleanups around allRecursivelyOverriddenDeclarationsIncludingSelf
- Pass containingClass (helps to avoid calculations of the
  containingClass in allRecursivelyOverriddenDeclarationsIncludingSelf
  implementation)
- Reuse allRecursivelyOverriddenDeclarationsIncludingSelf by
  DefaultArgumentsInExpectActualizedByFakeOverride &
  ActualFunctionWithDefaultParameters

Review: https://jetbrains.team/p/kt/reviews/13244
2023-12-04 13:08:23 +00:00
Nikita Bobko 8c0cf7d0bc [FIR] Fix disappeared ACTUAL_MISSING
^KT-59887 Fixed

Review: https://jetbrains.team/p/kt/reviews/13244
2023-12-04 13:08:23 +00:00
Nikita Bobko e44e84d1b0 [FIR] Reuse expect/actual matching data of outer declarations during matching of inner declarations
Review: https://jetbrains.team/p/kt/reviews/13244

Motivation:
    ```
    // Module :lib
    class Foo {
        val member: Int = 2
    }

    // Module :app
    // dependencies { implementation(project(":lib")) }
    class Foo {
        val member: Int = 2
    }
    ```

    Before the commit:
        app_Foo.expectForActual is `null`
        app_Foo.member.expectForActual = lib_foo.member
    After the commit:
        app_Foo.expectForActual is `null`
        app_Foo.member.expectForActual is `null`

    If I don't fix this problem then
    `CommonizerHierarchicalIT.testCommonizeHierarchicallyMultiModule`
    becomes red after I fix KT-59887 in the following commits

    `app_Foo.member.expectForActual = lib_foo.member` happens because we
    also need to match fake-overrides (KT-63550)

I didn't measure it, but theoretically, this commit should be a
performance improvement, becuase we reuse `expectForActual` cache

Additionally, The commit breaks some other tests (e.g.
compiler/testData/diagnostics/tests/multiplatform/headerClass/actualMissing.fir.kt).
The tests will become green again, once I fix KT-59887
2023-12-04 13:08:23 +00:00
Nikita Bobko 453d871b25 [LL] Run LLFirExpectActualMatchingTargetResolver only for KMP projects
Review: https://jetbrains.team/p/kt/reviews/13244

Motivation: Performance. When I fix KT-59887 in later commits, I will
make actual-to-expect resolve to work not only for actual declarations.
Considering that LLFirExpectActualMatcherLazyResolver worked even for
non-KMP projects that might be a potential performance regression

FirExpectActualMatcherProcessor in the compiler does the same thing (it
checks for MultiPlatformProjects before running the transformer)
2023-12-04 13:08:23 +00:00
Nikita Bobko ac3d8ad3ac [FIR] Expect classes can never have in implicit constructor. enums included
Motivation: If I don't fix it then I will get a false positive
ACTUAL_MISSING in
DiagnosticCompilerTestFE10TestdataTestGenerated.Tests.Multiplatform.Enum.testSimpleEnum
after I fix KT-59887

The commit also fixes false positive diagnostic in
annotationArgTypeAliasWithArray.fir.kt test

Review: https://jetbrains.team/p/kt/reviews/13244
2023-12-04 13:08:23 +00:00
Timofey Solonin 04dec2769b Step through the <compiler-generated> functions via a stop hook in konan_lldb.py
^KT-63598
2023-12-04 10:20:54 +00:00
Anastasia.Nekrasova b83d8595e5 [K2] Disappeared UNSUPPORTED
Forbid prefixes and suffixes for numeric literals and string

^KT-59881
2023-12-04 10:12:43 +00:00