Commit Graph

98643 Commits

Author SHA1 Message Date
Sebastian Sellmair 419b0e3e23 [Gradle] Implement MppCompositeBuildIT for builds with rootProject.name set
KT-56536
2023-02-09 12:36:53 +00:00
Denis.Zharkov aa8885ddfc K2: Get rid of last unhandled CheckerContext modification
Previously, it was necessary because otherwise reporting diagnostics
from a checker of FirFile level didn't work

Now, it has been fixed in the previous commit
2023-02-09 12:08:06 +00:00
Denis.Zharkov a71251d856 K2: Set correct containingFile in CheckerContext
Previously, it was working for all the checkers but the file-level
DeclarationChecker's because when execution comes to
DeclarationCheck::check for a file, `containingDeclarations` is empty
(it doesn't contain the file itself yet), thus some things that rely on
CheckerContext::containingFile don't work properly.

For example, SimpleDiagnosticsCollectorWithSuppress.report that
effectively doesn't collect diagnostics when the containingFile is null.
2023-02-09 12:08:06 +00:00
Denis.Zharkov 970d4f2949 K2: Extract PersistentCheckerContext::copy 2023-02-09 12:08:05 +00:00
Denis.Zharkov a311d6eea0 K2: Extract CheckerContextForProvider from CheckerContext
So, the idea is that CheckerContext should remain just read-only
while the one who runs the checkers might build/modify the context.

^KT-56460 Related
2023-02-09 12:08:05 +00:00
Sebastian Sellmair d24092e467 Demote LoggingStringTemplateAsArgument inspection to 'consideration' 2023-02-09 10:58:10 +00:00
Yahor Berdnikau 3c01ad6bc3 Exclude transitive :kotlin-build-common dependency
This dependency has non-relocated 'com.intellij' types which could
lead to build errors if build classpath will have it earlier in the list
then kotlin-compiler-embeddable.

^KT-56414 Fixed
2023-02-09 10:09:24 +00:00
Ilya Goncharov 40d75d531b [Gradle, JS] Wasm Karma support
^KT-56159 fixed
2023-02-09 09:47:05 +00:00
Sergey Bogolepov f7d3312ad5 [K/N] Finish refactoring TempFiles usages
1. Introduce CExportFiles class
This class aggregates all files that are created specifically for
C export. Adding more such classes for other output kinds should
help getting rid of OutputFiles class.

2. Remove NativeGenerationState.tempFiles
Making NativeGenerationState (and compiler phases in general)
unaware of files and their lifetime is necessary for making phases
simpler and easier to compose.
2023-02-09 08:20:34 +00:00
Sergey Bogolepov 4fbddf1786 [K/N] Pass NativeGenerationState components as parameters
tempFiles is finally moved to the driver.
2023-02-09 08:20:34 +00:00
Sergey Bogolepov b7b85177a7 [K/N] Refactor module splitting for backend
We want to extract tempFiles from NativeGenerationState.
To do so, we need to move creation of NativeGenerationState from
`splitIntoFragments` function and untie CacheLlvmModuleSpecification
from NativeGenerationState
2023-02-09 08:20:34 +00:00
Sergey Bogolepov eba1b4c388 [K/N] Untie DependenciesTracker from NativeGenerationState 2023-02-09 08:20:33 +00:00
Sergey Bogolepov 7402ef24bb [K/N] Remove obsolete TempFiles constructor parameter 2023-02-09 08:20:33 +00:00
Sergey Bogolepov 6a06be08cd [K/N] Extract pre-link from linker and a bit of refactoring
Finish extracting all usages of TempFiles to the driver.
2023-02-09 08:20:32 +00:00
Sergey Bogolepov e6081e5851 [K/N] Extract cache management in linker to a separate file
Also, more meaningful names.
2023-02-09 08:20:32 +00:00
Sergey Bogolepov 2f1e9844df [K/N] Move temp file from BitcodeCompiler to the driver
Continue extracting all temporary files to the driver, so we have
a better control over them. For example, this allows creating of a new
driver where pipeline split between multiple compiler invocations.
2023-02-09 08:20:31 +00:00
Sergey Bogolepov a11be433e2 [K/N] Get rid of predefined values in TempFiles
One step closer to getting rid of this class at all.
2023-02-09 08:20:31 +00:00
Sergey Bogolepov 1182903b20 [K/N] Move c++ adapter compilation to a separate phase
Besides purely architectural reasons or, rather, as a
direct effect of those, it allows moving tempFiles usages
to the driver.
2023-02-09 08:20:30 +00:00
Sergey Bogolepov bb1feabb79 [K/N] Untie C header generation from NativeGenerationState 2023-02-09 08:20:29 +00:00
Sergey Bogolepov 8516ae2b72 [K/N] Extract C header generation to a separate phase 2023-02-09 08:20:29 +00:00
Sergey Bogolepov 818b738921 [K/N] Fix context.log in NativeGenerationState phases 2023-02-09 08:19:47 +00:00
Dmitriy Dolovov 469a2315fc [Native] Move BuiltinOperatorLowering to a later stage of the lowerings pipeline
This would allow using unlowered operator symbols from IrBuiltIns in all lowerings before BuiltinOperatorLowering.
2023-02-09 08:07:15 +00:00
Ting-Yuan Huang 42b08d411b [FIR] Pass container when creating FunctionType
so that it can be resolved when type annotations are demanded.
2023-02-08 19:43:24 +00:00
Dmitrii Gridin 8f34b6599a [AA FIR] BuilderCache: replace regular map with concurrent to avoid exceptions
Example:
```stacktrace
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 32 out of bounds for length 17
  at com.intellij.util.containers.RefHashMap$MyMap.rehash(RefHashMap.java:85)
  at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap.insert(Object2ObjectOpenHashMap.java:251)
  at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap.put(Object2ObjectOpenHashMap.java:259)
  at com.intellij.util.containers.RefHashMap.putKey(RefHashMap.java:160)
  at com.intellij.util.containers.RefKeyRefValueHashMap.put(RefKeyRefValueHashMap.java:55)
  at org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder$FunctionLikeSymbolBuilder.buildFunctionSymbol(KtSymbolByFirBuilder.kt:727)
  at org.jetbrains.kotlin.analysis.api.fir.scopes.FirScopeUtilsKt$getCallableSymbols$1$1$1$1.invoke(firScopeUtils.kt:25)
  at org.jetbrains.kotlin.analysis.api.fir.scopes.FirScopeUtilsKt$getCallableSymbols$1$1$1$1.invoke(firScopeUtils.kt:24)
  at org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScopeImpl.processFunctionsByName(FirClassDeclaredMemberScope.kt:103)
  ```

^KTIJ-22749
2023-02-08 20:12:12 +01:00
Jaebaek Seo a09d0aa1cf Handle SHORTEN_IF_ALEADY_IMPORTED case of KtFirReferenceShortener
For the following example, when we run the reference shortener, it
drops `a.b.c` qualifier, because it matches "FOURTH".
```
package a.b.c

fun <T, E, D> foo(a: T, b: E, c: D) = a.hashCode() + b.hashCode() + c.hashCode() // FIRST
fun <E> E.foo() = hashCode() // SECOND

object Receiver {
    fun <T, E, D> foo(a: T, b: E, c: D) = a.hashCode() + b.hashCode() + c.hashCode() // THIRD
    fun foo(a: Int, b: Boolean, c: String) = a.hashCode() + b.hashCode() + c.hashCode() // FOURTH
    fun test(): Int {
        fun foo(a: Int, b: Boolean, c: Int) = a + b.hashCode() + c // FIFTH
        return <expr>a.b.c.foo(1, false, "bar")</expr>
    }
}
```

As shown in the above example, when SHORTEN_IF_ALEADY_IMPORTED option is
given from a user, the reference shortener has to check whether it can
drop the qualifier without changing the referenced symbol and if it is
possible to do that without adding a new import directive, it deletes
the qualifier.

It needs two steps:
 1. Collect all candidate symbols matching the signature e.g., function
    arguments / type arguments
 2. Determine whether the referenced symbol has the highest reference
    priority when we drops the qualifier depending on scopes

This commit uses `AllCandidatesResolver(shorteningContext.analysisSession.useSiteSession).
getAllCandidates( .. fake FIR call/property-access ..)` for step1.
For step2, we use a heuristic based on scopes of candidates. If a
candidate symbol is under the same scope with the target expression, it
has a `FirLocalScope` which has the high priority. So when we have a
candidate under a `FirLocalScope` and the actual referenced symbol is
different from the candidate, we must avoid dropping its qualifier
because the shortening will change its semantics i.e., reference.

The order of scopes depending on their scope types is:
 1. FirLocalScope
 2. FirClassUseSiteMemberScope / FirNestedClassifierScope
 3. FirExplicitSimpleImportingScope
 4. FirPackageMemberScope
 5. others

Note that for "others" the above rule can be wrong. Please update it if
you find other scopes that have a priority higher than the specified
scopes.

One of non-trivial parts is the priority among multiple
FirClassUseSiteMemberScope and FirNestedClassifierScope. They are
basically scopes for class declarations. We decide their priorities
based on the distance of class declaration from the target expression.

Note that we take a strict approach to reject all false positive. For
example, when we are not sure, we don't shorten it to avoid changing its
semantics.

TODO: One corner case is handling receivers. We have to update
```
private fun shortenIfAlreadyImported(
    firQualifiedAccess: FirQualifiedAccess,
    calledSymbol: FirCallableSymbol<*>,
    expressionInScope: KtExpression,
): Boolean
```

The current implementation cannot handle the following example:
```
package foo
class Foo {
    fun test() {
        // It references FIRST. Removing `foo` lets it reference SECOND.
        <caret>foo.myRun {
            42
        }
    }
}
inline fun <R> myRun(block: () -> R): R = block()         // FIRST
inline fun <T, R> T.myRun(block: T.() -> R): R = block()  // SECOND
```

Tests related to TODO:
 - analysis/analysis-api/testData/components/referenceShortener/referenceShortener/receiver2.kt
 - analysis/analysis-api/testData/components/referenceShortener/referenceShortener/receiver3.kt
2023-02-08 18:39:12 +00:00
Jaebaek Seo 860dee2cb1 Fix reference resolver bug for companion object whose name is the same as class
FirReferenceResolveHelper internally checks whether the referenced class
id matches the qualifed access or not. If they do not match, it reports
an error. When the companion object has the same name as the class,
resolving a qualified expression access to a member of the companion
object causes an error because of the mismatch e.g.,

```
package my.sample

class Test {
    fun a() {
        my.sample.<caret>Test.say()
    }

    companion object Test {
        fun say() {}
    }
}
```

This commit fixes the issue.

TODO: When the companion object has a name difference from class, it
does not report an error but the resolution result is wrong in FIR. See
KT-56167.

---

Commentary from rebaser: the issue mentioned in this code is
fixed in 71a368e06e, so the actual
fix is omitted, and only test data is preserved
2023-02-08 18:39:11 +00:00
Igor Chevdar 633d182846 [gradle] Do not pass cache-related options for optimized compilation
#KT-56443 Fixed
2023-02-08 18:36:35 +00:00
Ilya Kirillov d03f523a71 [LL FIR] return non-cancellable section back for resolve until cache invalidation problems (^KTIJ-24594) are fixed
^KTIJ-24594
2023-02-08 18:31:42 +00:00
Mikhail Glukhikh 1ee93553df K2: extract isSubtypeForSamConversion for SAM arguments check
Related to KT-53966
2023-02-08 17:40:21 +00:00
Mikhail Glukhikh 898a9a0f2c K2: apply SAM if argument has postponed lambdas #KT-53966 Fixed 2023-02-08 17:40:21 +00:00
Mikhail Glukhikh 5a9e8b3c0a FE: add tests for KT-53966 (positive/negative) 2023-02-08 17:40:20 +00:00
Ivan Kochurkin 12a083af25 [FIR2IR] Consider isExpect flag for generated synthetic functions
It's actual for value classes

^KT-51969 Fixed
2023-02-08 17:21:34 +00:00
Ivan Kochurkin 4374ca390a [IR] Extend enumEntryNameCall.kt test sample to check enum entries actualization 2023-02-08 17:21:34 +00:00
Ivan Kochurkin 241f457943 [IR] Use full name for expect/actual functions linking, simplify code
Don't put type parameters to expect-actual map since it's useless

^KT-56329 Fixed
2023-02-08 17:21:34 +00:00
Yahor Berdnikau 4e705d2f40 Fix flaky JS tests.
They are disabling error for using JS/Legacy backend via System property
by passing it to the Kotlin Daemon. But daemon may already be started
and not contain such property.

Workaround for now is to use 'in-process' compilation for such cases.
2023-02-08 16:27:29 +00:00
Yahor Berdnikau 78dc59f759 Update test-retry-gradle-plugin to 1.5.1 version 2023-02-08 16:27:29 +00:00
Yahor Berdnikau b3e6a3c274 Update test-data for Gradle 7.6 version. 2023-02-08 16:27:28 +00:00
Yahor Berdnikau 3c863b5bbf Add foojay plugin to download JVM toolchains via DiscoAPI 2023-02-08 16:27:28 +00:00
Yahor Berdnikau 4de3a62680 Update KGP test-suite plugin setup
This ensures compatibility with changes in test-suite plugin new
versions.
2023-02-08 16:27:28 +00:00
Yahor Berdnikau 6f8422eab3 Revert "[Build] Temporary disable hmpp metadata tasks with CoCa"
This reverts commit e42bed07fa.
2023-02-08 16:27:27 +00:00
Yahor Berdnikau 8d41c87b6b Revert "[Build] Add configuration cache compatibility workaround for MetadataDependencyTransformationTask"
This reverts commit a5f48e295e.
2023-02-08 16:27:27 +00:00
Yahor Berdnikau adf79b6f00 Allow warnings in :kotlin-native:build-tools compilation
Fixing native benchmark setup is out of scope of these changes.
2023-02-08 16:27:27 +00:00
Yahor Berdnikau 5ae1372c3a Set gradlew.bat eol in .gitattributes
This fixes common error on updating Gradle wrapper and then trying to
add 'gradlew.bat' to changes.
2023-02-08 16:27:26 +00:00
Martin Bonnin a199fa7624 Bump Gradle version to 7.6
As well remove usages of forUseAtConfigurationTime - see also
https://github.com/JetBrains/kotlin/pull/5003
2023-02-08 16:27:26 +00:00
Martin Bonnin 2f1147f224 DurationUnit is not a typealias of TimeUnit anymore, use inWholeMilliseconds instead
See https://kotlinlang.org/docs/whatsnew16.html#stable-duration-api
2023-02-08 16:27:26 +00:00
Vladimir Sukharev ab32f90117 Put tags to klib contents tests
Merge-request: KT-MR-8641
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-02-08 15:42:00 +00:00
Stanislav Erokhin da98a47c4c Minor: tweak wording in the deprecated message 2023-02-08 15:41:21 +00:00
Vladimir Sukharev c86f3d1103 Transform native compiler source code to be compiled by K2 bootstrap.
Merge-request: KT-MR-8720
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-02-08 15:37:34 +00:00
Kirill Rakhman 22fd7921fe [FIR] Introduce MetadataBasedAnnotationDeserializer for compiling common
^KT-56361 Fixed
2023-02-08 13:32:33 +00:00
Mikhail Glukhikh 81ac94b2d7 FE: convert LanguageVersion.versionString to a stored property
Suggested by Yuriy Artamonov
#KT-56276 Fixed
2023-02-08 12:51:21 +00:00