Commit Graph

106151 Commits

Author SHA1 Message Date
Brian Norman b309786353 [FIR] RHS assignment during equality comparison should invalidate DFA
If the right-hand side of an equality comparison contains an assignment
to the variable used in the left-hand side, then implications about the
equality comparison within data-flow analysis cannot be applied, as the
value of the variable will be different after the comparison.

^KT-55096 Fixed
2023-11-06 22:12:22 +00:00
Ilya Chernikov 879f0eff71 Fir: Print origin of the generated diagnostics
similar to other generated entities by now.
2023-11-06 21:21:16 +00:00
Ilya Chernikov 1ad4f19181 Fix default positioning strategy handling
that causes flaky tests because the default positioning strategy
was dependent on the order of the reported messages.
The code led to it was introduced in an attempt to extract common
PSI-independent strategy because PSI is leaking into the abstract
diagnostic infrastructure. The approach is definitely problematic,
but to fix it now, the leaking dependency to the psi-based module
is introduced. This should be fixed in the future by introducing
better abstractions.
Fixes flaky tests touched in the commit.
#KT-63002 fixed
2023-11-06 21:21:16 +00:00
Dmitriy Dolovov 0de04f934e [Commonizer] Switch from trove4j to fastutil
^KT-63159
2023-11-06 19:56:17 +00:00
Dmitriy Dolovov 7658b818ac [Commonizer] Add a performance test (muted by default)
This test can be used to make small performance measurements of
the core commonizer on occasional basis. This test is not intended
for regular execution, e.g. at the CI server.

^KT-63159
2023-11-06 19:56:17 +00:00
Evgenii Mazhukin 20af98c776 [Tests] Re-enable K1 IC tests for expect-actual
^KT-60831 fixed
^KT-60831 next step KT-63183


Merge-request: KT-MR-12855
Merged-by: Evgenii Mazhukin <evgenii.mazhukin@jetbrains.com>
2023-11-06 19:46:43 +00:00
Nikita Bobko 4050285fef Drop unnecessary suppress from stdlib
^KT-62785 Fixed
Review: https://jetbrains.team/p/kt/reviews/12858/files
2023-11-06 19:00:35 +00:00
Dmitrii Krasnov aad19ab844 [Gradle, Native] Override equals and hashCode in KonanTarget
"data objects" is only available since language version 1.9. But we should not use LV 1.9, because it is used in the Gradle build classpath and would be incompatible with Gradle Kotlin runtime.
Then only manually override equals/toString/ works here.

#KT-61657 Fixed


Merge-request: KT-MR-12759
Merged-by: Dmitrii Krasnov <Dmitrii.Krasnov@jetbrains.com>
2023-11-06 18:55:40 +00:00
Dmitrii Krasnov f8507d5220 [Gradle, Native] Switched downloading k/n to from Maven Central in KGP
#KT-62907 Fixed
2023-11-06 16:50:43 +00:00
Dmitriy Novozhilov c5d1c4e816 [Test] Add test for KT-62137 2023-11-06 15:24:39 +00:00
Marco Pennekamp fd1c885c5b [FIR] Allow "missing from dependencies" severity names in opt-in usage checker
- KT-62397 occurs in the IDE because enum entry symbols from libraries
  are deserialized from stubs, which currently produce
  `FirFromMissingDependenciesNamedReference`.
- During opt-in usage checks, the compiler only considered resolved
  references when getting the severity name, but we can just take the
  name from the `FirFromMissingDependenciesNamedReference`.

^KT-62397 fixed
2023-11-06 15:20:49 +00:00
Yahor Berdnikau 570d9dbb19 [Gradle] Fix early buildDir capturing in kotlinTestRegistry
User may change build directory location in the script, and our
plugin should handle such situations correctly.

^KT-61295 Fixed
2023-11-06 14:42:52 +00:00
Nikita Bobko 5c8d55fba7 Update docs/fir/k2_kmp.md wrt KT-62590 2023-11-06 14:41:28 +00:00
Nikita Bobko 8f9b6a08fc [FIR] Cleanup ACTUAL_MISSING reporting
The cleanup became possible after KT-62590
Review: https://jetbrains.team/p/kt/reviews/12750/timeline

`matchingCompatibilityToMembersMap.allMismatches()` is equivalent to
`ExpectActualMatchingCompatibility.MatchedSuccessfully !in
matchingCompatibilityToMembersMap`
2023-11-06 14:41:28 +00:00
Nikita Bobko 5be8778b44 [FIR] Cleanup ClassScopes reporting
The cleanup became possible after KT-62590
Review: https://jetbrains.team/p/kt/reviews/12750/timeline

incompatibility.allMismatches() always returns true for
mismatchedMembers => hasSingleActualSuspect always returns false =>
filterNot doesn't have any effect

incompatibility.allMismatches() always returns false for
incompatibleMembers => incompatibility.allMismatches() is redundant
2023-11-06 14:41:27 +00:00
Nikita Bobko 0fc7ea6004 [IR] Workaround expectActualOverloads test failure
Under the hood this test was broken before my KT-62590 changes. KT-62926
demonstrates it
2023-11-06 14:41:27 +00:00
Nikita Bobko b7198c35b9 Update incompatibleClassScopesWithImplTypeAlias test
Caused by: KT-62590

Now we have the pipeline:
1. Match declarations
2. Run checkers on matched declarations

Since the constructors with empty parameters match we only report
"checking incompatibility" about their incompatible visibility

Before the pipeline introduction, we were running matching and checking
checks together
2023-11-06 14:41:26 +00:00
Nikita Bobko facdbfdc11 [FIR, IR] Cleanup: inline functions that have only one usage in matcher/checker
Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:26 +00:00
Nikita Bobko 92850dcc84 [FIR, IR] Cleanup: convert vector of actuals to scalar of a single actual in AbstractExpectActualChecker
Review: https://jetbrains.team/p/kt/reviews/12750/timeline

`AbstractExpectActualChecker` works on pairs obtain from
`AbstractExpectActualMatcher` and the last one always returns single
actual for single expect. That's why handling of multiple actuals
doesn't make sense
2023-11-06 14:41:25 +00:00
Nikita Bobko fd39795f41 [FIR, IR] Cleanup: deduplicate common code in AbstractExpectActualMatcher & AbstractExpectActualChecker
Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:25 +00:00
Nikita Bobko b331726c6e [FIR, IR] Cleanup: drop redundant enumConstructorsAreAlwaysCompatible
It's constantly true in FIR and IR (it was false in K1)

Also see: 8b9079d026

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:24 +00:00
Nikita Bobko 75a0442b61 [FIR] 2/2 Cleanup: drop no longer necessary FirActualCallableDeclarationChecker
It became possible to drop it after KT-62590. Now, on a frontend, the
return type check is part of a common AbstractExpectActualChecker logic

Change in nestedAnnotationClassViaActualTypealias.fir.kt aligns the
behaviour with K1. KT-61964

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:23 +00:00
Nikita Bobko a9583e4f9a [FIR, IR] 1/2 Align FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes with ExpectActualUtilsKt.areCompatibleExpectActualTypes
Those two functions are copy-paste of each other. They diverged since
the time they were copy-pasted. This commit makes
FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes
up-to-date.

I didn't update ExpectActualUtilsKt.areCompatibleExpectActualTypes
because I will drop it in the next commit.

Change in `dynamicTypesEqualToAnything` doesn't change any logic (yet.
This change in logic will take effect in the next commit), because:
1. `dynamicTypesEqualToAnything` is only changed in
AbstractExpectActualChecker.getCallablesCheckingIncompatibility. But
AbstractExpectActualChecker.getCallablesCheckingIncompatibility doesn't
check return types on frontend (it only check return types on backend).
2. `dynamicTypesEqualToAnything` is ignored on IR backend

I have no idea what is the difference between `createTypeCheckerState()`
and `actualSession.typeContext`, but it aligns these copy-pasted
versions and makes the tests behave like in K1 (at least
'typeUsageWithUnresolvedReference' and 'kt57320' are affected)

This commit is mainly a preparation for the next commit.

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:23 +00:00
Nikita Bobko ddc1ae9ac6 [IR] Split INCOMPATIBLE_MATCHING to EXPECT_ACTUAL_MISMATCH & EXPECT_ACTUAL_INCOMPATIBILITY
KT-62590

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:22 +00:00
Nikita Bobko dab69e38c4 [FIR, IR] AbstractExpectActualChecker: drop redundant code
- getCallablesStrongIncompatibility is unused (because it moved to the
  "matcher" KT-62590)
- `checkClassScopesCompatibility` parameter is always `true` or unused

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:22 +00:00
Nikita Bobko 60e5a9c298 [IR] Update testData INCOMPATIBLE_MATCHING
^KT-62916 Fixed
(well, actually it got fixed in one of my previous commits, but it's
hard to track)

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:21 +00:00
Nikita Bobko 24e74487d6 [FIR] Fix DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE tests
This commit fixes the following tests:
    FirOldFrontendMPPDiagnosticsWithPsiTestGenerated
        DefaultArguments
            MethodDefaultArgsViaActualFakeOverride
                testIntersectionOverride
                testSimple
                testDelegation
                testSubstitutionOverride
                testSimpleIncompatible

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:21 +00:00
Nikita Bobko 76ffbcc67c [IR] Update testData ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
After previous commits, IrExpectActualAnnotationMatchingChecker reports
errors even if the declaration is incompatible but matched

We had a duplicated diagnostic in other cases before my commits, anyway.
it will be fixed in
https://youtrack.jetbrains.com/issue/KT-62559/KMP-K2-prevent-reporting-ACTUALANNOTATIONSNOTMATCHEXPECT-twice-in-CLI#focus=Comments-27-8293687.0-0

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:20 +00:00
Nikita Bobko 8722e142f6 [IR] 2/2 Propogate expect-actual checker incompatibilities to IR backend
Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:20 +00:00
Nikita Bobko eb0c8c00c3 [FIR, IR] 1/2 Minimize usages of ExpectActualCompatibility, MismatchOrIncompatible and MatchedOrCompatible
- Migrate ExpectActualCompatibility -> ExpectActualCheckingCompatibility
  where the "checker" is expect
- Migrate ExpectActualCompatibility -> ExpectActualMatchingCompatibility
  where the "matching" is expect

KT-62590 in progress. A lot of tests start to fail now. I will fix them
in next commits

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:19 +00:00
Nikita Bobko 664b9cc3ba [FIR, IR] ClassScopes incompatibility: split unfulfilled incompatibilities into "mismatchedMembers" and "incompatibleMembers"
KT-62590 is in progress

Unfortunatelly, ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT is now reported
twice in 'classScopeViaTypealiasIncompatible' test.

We had a duplicated diagnostic in other cases before my commits, anyway.
it will be fixed in
https://youtrack.jetbrains.com/issue/KT-62559/KMP-K2-prevent-reporting-ACTUALANNOTATIONSNOTMATCHEXPECT-twice-in-CLI#focus=Comments-27-8293687.0-0

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:19 +00:00
Nikita Bobko d0b34fe378 [FIR, IR] Refactor: restructure ExpectActualCompatibility class hierarchy
KT-62590 is in progress

This commit is pure refactoring.
- No tests changed their behaviour
- Semantics isn't changed

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:18 +00:00
Nikita Bobko bbbc775181 [FIR, IR] Drop code that don't belong to AbstractExpectActualMatcher
- The Matcher must only do the "matching" (aka "strong compatibility")
- Drop all "checking" related (aka "weak compatibility" related) logic
- `checkClassScopesCompatibility` parameter belongs to the
  "expect-actual checker" not to the "expect-actual matcher". Drop it

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:18 +00:00
Nikita Bobko 1c6e529146 [FIR, IR] Rough split of AbstractExpectActualCompatibilityChecker into matcher & checker
This commit:
1. renames AbstractExpectActualCompatibilityChecker to AbstractExpectActualChecker
2. `cp compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualChecker.kt compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualMatcher.kt`
   + rename the object in AbstractExpectActualMatcher.kt
3. KDocs

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:17 +00:00
Nikita Bobko 4ef8595a4b [IR] Don't check class scopes compatibility in collectActualCallablesMatchingToSpecificExpect
This is a minor optimization.
This commit is a step forward for KT-62590

Conceptually, `checkClassScopesCompatibility` belongs to the
"expect-actual checker". It doesn't belong to the "expect-actual
matcher".

- `checkClassScopesCompatibility` should be set to `true` when you want
  to do the "checking"
- `checkClassScopesCompatibility` should be set to `false` when you want
  to do the "matching"

`collectActualCallablesMatchingToSpecificExpect` only needs the
"matching"

No tests changed their behaviour

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:17 +00:00
Nikita Bobko a3401b2f9e Minor: cleanup + support variance in ErrorListDiagnosticListRenderer
1. Support variance in ErrorListDiagnosticListRenderer.
   I will make some diagnostics to have covariant type arguments in the
   next commits
2. Drop unused code

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:17 +00:00
Nikita Bobko 3b47610817 [FIR] Refactoring: "Move in" parentSubstitutor creation to getCallablesCompatibility
Motivation: Make getCallablesCompatibility API slightly nicer. The
function is going to be called from more places after KT-62590 is fixed.
This commit makes fixing KT-62590 easier

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:16 +00:00
Nikita Bobko bc5180656d [FIR] ReturnType expect-actual incompatibility: convert from strong to weak
It should have been WeakIncompatible from the beginning because it's not
possible to overload by return type in Kotlin

This commit is a step forward to fix KT-62591

Unfortunately, the test cannot demonstrate the problem because of
another bug in K2 KT-59887

^KT-62752 Fixed
Review: https://jetbrains.team/p/kt/reviews/12750/timeline

Motivation:

It makes expect-actual matching-checking model more consistent.

expect-actual "matching" is run before FirResolvePhase.BODY_RESOLVE. You
can't know return types, until you run BODY_RESOLVE. That's why the
return type can't be checked during expect-actual matching. But it's
cursed: you have something that have to match by, but, at the same time,
you can't do it.

expect-actual "checking" is run after FirResolvePhase.BODY_RESOLVE.
That's why if we convert ReturnType incompatibility to WeakIncompatible
(which should have been called CheckingIncompatible), then expect-actual
matching model becomes consistent.

We will also be able to get rid of unnecessary
FirActualCallableDeclarationChecker. Because it won't be necessary.
Return types will be checked by common logic of expect-actual "checker"
2023-11-06 14:41:16 +00:00
Nikita Bobko e778ddfd21 [AA] getExpectForActual analysis-api now returns compatible or weakly incompatible
^KTIJ-27522 Fixed

It's the only reasonable behavior for this API in it's current shape
(when it returns a list of declarations)

It's a common mistake to take only Compatible from
expectActualMatchingMap. The problem will be gone after I fix KT-62590

Motivation to fix this bug, is because it will be easier for me to split
expect-actual matcher-checker-monster thing KT-62590

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:15 +00:00
cristiangarcia 69c209874d Use cache-redirector to download Node.js for js.tests 2023-11-06 11:01:54 +01:00
Sergej Jaskiewicz a84277782a [IR generator] Don't use kotlinpoet for auto-generating IrFactory
KT-61970
2023-11-06 09:47:22 +00:00
Anton Lakotka ebe0a84dee [Gradle] Fix GCC support for IOS specific Kotlin Native Test Tasks
^KT-63044 Verification Pending
2023-11-06 09:37:59 +00:00
Anton Lakotka 704adc053a [Gradle] Test native tasks with Gradle 8.4 Configuration Cache
^KT-63044 In Progress
2023-11-06 09:37:59 +00:00
Anton Lakotka 096cb0abce [Gradle] Add Gradle.G_8_4 version for tests 2023-11-06 09:37:59 +00:00
Alexander Udalov 4fca52b66c FIR entrypoint: deduplicate some code and remove JVM dependency
Deduplicate Fir2IrExtensions creation and move the
convertToIrAndActualizeForJvm function to 'cli', which allows to remove
the dependency of 'fir.entrypoint' on 'backend.jvm'.

Note that behavior slightly changes in IncrementalFirJvmCompilerRunner:
previously the value of linkViaSignatures was always false, now it is
taken from the compiler configuration, which seems more correct.
2023-11-06 08:49:04 +00:00
Dmitriy Novozhilov 420fbad73d [FIR2IR] Properly insert implicit casts to extension receiver in case of intersection smartcast type
^KT-62863 Fixed
2023-11-06 06:50:35 +00:00
Mikhail Glukhikh 50106c740c K2: reproduce situation from KT-62863 2023-11-06 06:50:35 +00:00
Mikhail Glukhikh 168b3416ea FIR2IR: avoid redundant implicit cast creation
Related to KT-62544
2023-11-06 06:50:35 +00:00
Mikhail Glukhikh ba06af9d7f FIR2IR: extract implicitCast function 2023-11-06 06:50:35 +00:00
Mikhail Glukhikh 1ef0f9e944 K2: reproduce strange "smartcast aside" behavior related to KT-62544 fix 2023-11-06 06:50:35 +00:00