Commit Graph

85981 Commits

Author SHA1 Message Date
Ilya Matveev 474b2fc90e [K/N][New MM] Fix getting current thread data in thread suspension 2021-09-20 07:28:57 +00:00
Ilya Matveev bfc4ff6343 [K/N][New MM] Disallow getting thread data for detached threads
This patch fixes a performance degradation introduced by
99bd26c2ef (Switch thread states
in termination handlers).
2021-09-20 07:28:57 +00:00
Igor Chevdar 3a4e8e7a61 [K/N][IR] Used .isFakeOverride instead of a special origin 2021-09-18 19:46:09 +05:00
Steven Schäfer dc568426bd Parcelize: Allow IgnoredOnParcel annotations on object properties 2021-09-18 00:26:16 +02:00
Steven Schäfer ae27be16eb AsmLikeInstructionListingTest: Print owner for FieldInsnNode 2021-09-18 00:25:58 +02:00
Igor Laevsky e23b4df519 [WASM] Remove workaround for frontend bug 2021-09-17 19:17:45 +03:00
Alexander Udalov 987a346015 JVM IR: support cyclic module dependencies
The only way to make the compiler compile several modules with a
dependency loop is via the "build file", given by -Xbuild-file and used
in the JPS (IntelliJ built-in build system) plugin.

For the old frontend/backend it works like this: we _analyze_ sources of
all modules once, as if it's one big module, and then for each module,
we _generate_ (invoke backend) only sources of that module. Backend
needs to be invoked separately per-module because every module has its
own destination directory specified in the build file.

For JVM IR, this separation into just two steps, analyze and generate,
was problematic because there's psi2ir, which works like frontend, in
that it needs the global analysis result to be able to create and link
IR correctly. So, in case of JVM IR, we need to run psi2ir on the whole
module after analysis and before generation.

In this change, psi2ir is run on the whole module via
`CodegenFactory.convertToIr` (which does nothing in the old backend),
and then parts of the resulting IR module are extracted according to the
original separation of the combined module into individual modules via
`getModuleChunkBackendInput` by matching IrFile against KtFile. And
then, backend is run for each such module.

 #KT-45915 Fixed
 #KT-48668 Fixed
2021-09-17 17:39:49 +02:00
Alexander Udalov 5d6ca27c93 JVM IR: introduce CodegenFactory.convertToIr
The steps of psi2ir and JVM backend need to be separated in the API
because in case of cyclic module dependencies (which are allowed in JPS)
psi2ir should be run first on all sources, and then JVM backend on each
module separately. `CodegenFactory.convertToIr` does nothing in the old
backend.

Also, move the ignoreErrors to GenerationState for simplicity.
2021-09-17 17:39:48 +02:00
Dmitriy Novozhilov bfeb9c219d [FE 1.0] Correctly set USED_AS_EXPRESSION for unreachable catch clauses
^KT-48806 Fixed
2021-09-17 18:38:19 +03:00
Tianyu Geng 9ca8d39240 FIR IDE: use KtVariableWithInvokeFunctionCall for extension invoke 2021-09-17 17:27:53 +02:00
Tianyu Geng c19ed07fd1 FIR IDE: add cache in KtFirCallResolver 2021-09-17 17:27:52 +02:00
Tianyu Geng d2ed203528 FIR IDE: Add substitutor to KtCall 2021-09-17 17:27:52 +02:00
Tianyu Geng 9f0f1781c9 FIR IDE: add validity token to KtCall 2021-09-17 17:27:52 +02:00
Tianyu Geng 245c4082cd FIR IDE: add KtSubstitutor 2021-09-17 17:27:52 +02:00
Nikolay Lunyak ba8dc49a31 [FIX] Move backing field bytecodeListing tests to a separate folder 2021-09-17 15:29:35 +03:00
Nikolay Lunyak 54067628ff [FIX] Add a checker for unsupported explicit backing fields 2021-09-17 14:36:39 +03:00
Nikolay Lunyak 7921e64540 [FIX] Add the ExplicitBackingFields language feature 2021-09-17 14:36:39 +03:00
Dmitry Gridin 9ceb477523 [light classes] fix cache value creation
Cause: we are implicitly wrapping `jvmDefaultMode` that leads to
incorrect result

^KTIJ-19042 Fixed
^EA-357501 Fixed
2021-09-17 03:49:38 +00:00
Tianyu Geng 765cad8448 FIR checker: substitute type parameters in dispatch receiver type
Consider the following code:

```
fun test(a: List<String>) {
  a.first()
}
```

The dispatch receiver type of `first` in this case is `List<T>` before
this change. After this change, it's `List<String>`.

In addition, this change also replace the dispatch receiver type with
the more specific type if available. For example, consider the following

```
class MyList: ArrayList<String>()

fun test(a: MyList) {
  a.get(0)
}
```
The dispatch receiver type of `get` is `MyList`, instead of
`ArrayList<String>`. That is, a fake override is created in this case.
2021-09-17 01:59:06 +03:00
Tianyu Geng c047adbaec FIR IDE: register module data for library modules
Various HL API needs to create fake override for symbols in libraries.
Without module data it may fail. Following exception is an example:

java.lang.IllegalStateException: Module data is not registered in Libraries session
	at org.jetbrains.kotlin.fir.FirModuleDataKt.getModuleData(FirModuleData.kt:80)
	at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createCopyForFirProperty(FirFakeOverrideGenerator.kt:297)
	at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createCopyForFirProperty$default(FirFakeOverrideGenerator.kt:281)
	at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createSubstitutionOverrideProperty(FirFakeOverrideGenerator.kt:271)
	at org.jetbrains.kotlin.fir.scopes.impl.FirFakeOverrideGenerator.createSubstitutionOverrideProperty$default(FirFakeOverrideGenerator.kt:254)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope.createSubstitutionOverrideProperty(FirClassSubstitutionScope.kt:211)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope.access$createSubstitutionOverrideProperty(FirClassSubstitutionScope.kt:30)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope$processPropertiesByName$1.invoke(FirClassSubstitutionScope.kt:84)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope$processPropertiesByName$1.invoke(FirClassSubstitutionScope.kt:81)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:32)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:25)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope.processPropertiesByName(FirClassDeclaredMemberScope.kt:115)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.processPropertiesByName(FirClassUseSiteMemberScope.kt:25)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope.processPropertiesByName(FirClassSubstitutionScope.kt:81)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.computeDirectOverridden(FirClassUseSiteMemberScope.kt:45)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.access$computeDirectOverridden(FirClassUseSiteMemberScope.kt:17)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:28)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope$processPropertiesByName$1.invoke(FirClassUseSiteMemberScope.kt:25)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassDeclaredMemberScope.processPropertiesByName(FirClassDeclaredMemberScope.kt:115)
	at org.jetbrains.kotlin.fir.scopes.impl.FirClassUseSiteMemberScope.processPropertiesByName(FirClassUseSiteMemberScope.kt:25)
	at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider.processCallableByName(KtFirSymbolDeclarationOverridesProvider.kt:58)
	at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider.access$processCallableByName(KtFirSymbolDeclarationOverridesProvider.kt:29)
	at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider$getDirectlyOverriddenSymbols$$inlined$processOverrides$1.invoke(FirRefWithValidityCheck.kt:105)
	at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider$getDirectlyOverriddenSymbols$$inlined$processOverrides$1.invoke(FirRefWithValidityCheck.kt:33)
	at org.jetbrains.kotlin.idea.fir.low.level.api.api.LowLevelFirApiFacadeKt.withFirDeclaration(LowLevelFirApiFacade.kt:129)
	at org.jetbrains.kotlin.idea.frontend.api.fir.components.KtFirSymbolDeclarationOverridesProvider.getDirectlyOverriddenSymbols(KtFirSymbolDeclarationOverridesProvider.kt:253)
	at org.jetbrains.kotlin.idea.frontend.api.components.KtSymbolDeclarationOverridesProviderMixIn$DefaultImpls.getDirectlyOverriddenSymbols(KtSymbolDeclarationOverridesProvider.kt:45)
	at org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession.getDirectlyOverriddenSymbols(KtAnalysisSession.kt:29)
	at org.jetbrains.kotlin.idea.completion.weighers.CallableWeigher.addWeight(CallableWeigher.kt:28)
	at org.jetbrains.kotlin.idea.completion.weighers.Weighers.applyWeighsToLookupElement(Weighers.kt:61)
	at org.jetbrains.kotlin.idea.completion.contributors.FirCompletionContributorBase.applyWeighers(FirCompletionContributorBase.kt:115)
	at org.jetbrains.kotlin.idea.completion.contributors.FirCompletionContributorBase.addCallableSymbolToCompletion(FirCompletionContributorBase.kt:101)
	at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.collectDotCompletionForCallableReceiver(FirCallableCompletionContributor.kt:189)
	at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.collectDotCompletion(FirCallableCompletionContributor.kt:145)
	at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.complete(FirCallableCompletionContributor.kt:79)
	at org.jetbrains.kotlin.idea.completion.contributors.FirCallableCompletionContributor.complete(FirCallableCompletionContributor.kt:31)
	at org.jetbrains.kotlin.idea.completion.contributors.FirCompletionContributorBaseKt.complete(FirCompletionContributorBase.kt:124)
	at org.jetbrains.kotlin.idea.completion.Completions.complete(Completions.kt:18)
	at org.jetbrains.kotlin.idea.completion.KotlinFirCompletionProvider.complete(KotlinFirCompletionContributor.kt:81)
	at org.jetbrains.kotlin.idea.completion.KotlinFirCompletionProvider.addCompletions(KotlinFirCompletionContributor.kt:70)
	at com.intellij.codeInsight.completion.CompletionProvider.addCompletionVariants(CompletionProvider.java:34)
	at com.intellij.codeInsight.completion.CompletionContributor.fillCompletionVariants(CompletionContributor.java:156)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:77)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:60)
	at com.intellij.codeInsight.completion.CompletionService.performCompletion(CompletionService.java:133)
	at com.intellij.codeInsight.completion.BaseCompletionService.performCompletion(BaseCompletionService.java:41)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.lambda$calculateItems$12(CompletionProgressIndicator.java:863)
	at com.intellij.util.indexing.FileBasedIndex.lambda$ignoreDumbMode$0(FileBasedIndex.java:163)
	at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:111)
	at com.intellij.util.indexing.FileBasedIndexEx.ignoreDumbMode(FileBasedIndexEx.java:588)
	at com.intellij.util.indexing.FileBasedIndex.ignoreDumbMode(FileBasedIndex.java:162)
	at com.intellij.util.indexing.DumbModeAccessType.ignoreDumbMode(DumbModeAccessType.java:43)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.calculateItems(CompletionProgressIndicator.java:859)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.runContributors(CompletionProgressIndicator.java:847)
	at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$6(CodeCompletionHandlerBase.java:353)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$tryReadOrCancel$5(CompletionThreading.java:172)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1078)
	at com.intellij.codeInsight.completion.AsyncCompletion.tryReadOrCancel(CompletionThreading.java:170)
	at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$7(CodeCompletionHandlerBase.java:345)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$0(CompletionThreading.java:95)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:183)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:170)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$1(CompletionThreading.java:91)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:265)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
2021-09-17 01:59:05 +03:00
Tianyu Geng d77db2cda6 FIR checker: expose API to check if two types are compatible
This is useful for quickfixes offering casts. We don't want to offer
user to cast incompatible types.

Also, explicitly allow compare to `Nothing` and handle `Nothing` from intersection
2021-09-17 01:59:05 +03:00
Tianyu Geng 5b0ca06e95 FIR checker: make SMARTCAST_IMPOSSIBLE report the desired type at receiver position
Previously the smartcast type is reported. This is undesirable because
usually this type is an intersection and hence not denotable.
2021-09-17 01:59:03 +03:00
Tianyu Geng 951812f130 FIR checker: record whether type mismatch is due to nullability
This is useful for downstream quickfixes.
2021-09-17 01:59:01 +03:00
Tianyu Geng d3e8cc577c FIR checker: fix local type approximation on delegated property
Previously types of delegated property is not approximated, which can
cause local types to leak through public APIs.
2021-09-16 22:38:08 +03:00
Tianyu Geng 76e192fc8a FIR Checker: check AMBIGUOUS_ANONYMOUS_TYPE_INFERRED
Also change
org.jetbrains.kotlin.fir.types.TypeUtilsKt#hideLocalTypeIfNeeded to skip
approximating anonymous objects if there are multiple super type refs so
that resolution behaves the same (for uncompilable code).

Note that this change does not implement check for
ApproximateAnonymousReturnTypesInPrivateInlineFunctions as the check is
already turned on in 1.5 and will likely not needed when FIR becomes
stable.
2021-09-16 22:38:06 +03:00
Igor Laevsky 6432388778 [WASM] Don't handle ref.cast of nulls. Spec was updated a while ago 2021-09-16 20:24:45 +03:00
Igor Laevsky 15668e2266 [WASM] Lower Unit to Void in order to mark statements with no result 2021-09-16 20:24:44 +03:00
Igor Laevsky 9685695769 [WASM] Fold redundant patterns with drop instruction on a wasm level 2021-09-16 20:24:43 +03:00
Igor Laevsky 1db45faba2 [WASM] NFC. Fold instructions from the wasm expression builder 2021-09-16 20:24:42 +03:00
Abduqodiri Qurbonzoda 718965227e Advance deprecation level of K/N StringBuilder renamed functions to ERROR #KT-46101 2021-09-16 19:45:04 +03:00
Abduqodiri Qurbonzoda bde055fe5c Advance deprecation level of Float/DoubleArray contains, indexOf, lastIndexOf to ERROR #KT-28753 2021-09-16 19:38:40 +03:00
Abduqodiri Qurbonzoda 3ddc29363a Remove deprecated Common synchronized and deprecate it in JS #KT-46101 2021-09-16 19:38:37 +03:00
Abduqodiri Qurbonzoda 7e1cd757fb Advance max/min(By/With) deprecation level to HIDDEN #KT-38854 2021-09-16 19:38:35 +03:00
Abduqodiri Qurbonzoda d9f8ce899a Promote rotateLeft and rotateRight to stable 2021-09-16 19:27:21 +03:00
Abduqodiri Qurbonzoda 34a50e4e34 Promote regex splitToSequence to stable 2021-09-16 19:26:33 +03:00
Alexander Likhachev 453d263393 [Gradle, JVM] Add test that JVM target is untouched with no toolchain 2021-09-16 13:26:13 +00:00
Alexander Likhachev aa52a60f45 [Gradle, JVM] Validate JVM targets even if compiler isn't called
Previously the validation was inconsistent allowing non-incremental builds without Kotlin sources to pass successfully with JVM target misconfiguraiton but fail incremental builds
#KT-48408 Fixed
2021-09-16 13:26:13 +00:00
Alexander Likhachev 2a77da4caa [Gradle, JVM] Add test for KT-48408 2021-09-16 13:26:12 +00:00
Alexander Likhachev 612b96bd54 [Daemon] Introduce the way to get Kotlin daemon compiler version
#KT-48294 In Progress
2021-09-16 13:25:18 +00:00
Abduqodiri Qurbonzoda 815329df15 Remove private KTypeProjection.asString() that duplicates toString() logic
KT-30071 has been already fixed.
2021-09-16 11:39:07 +00:00
Svyatoslav Kuzmich 0abc798da9 [Wasm] Add JS interop tests 2021-09-16 14:20:35 +03:00
Svyatoslav Kuzmich a32b86d016 [Wasm] Simple support for external classes and interfaces
* Map these types to Wasm externref
* Don't generate any declaration code for now

Casting and accessing members is not supported yet
2021-09-16 14:20:35 +03:00
Svyatoslav Kuzmich 35a5c9ea71 [Wasm] Support exporting functions via @kotlin.js.JsExport
Previously we exported main function only.
Extend this feature to arbitrary number of annotated functions.
Type restrictions and conversions are similar to imported functions.
2021-09-16 14:20:35 +03:00
Svyatoslav Kuzmich de7fa8c778 [Wasm][Stdlib] Add kotlin.js.JsExport annotation 2021-09-16 14:20:34 +03:00
Svyatoslav Kuzmich a384ba6442 [Wasm IR] Add data heap type 2021-09-16 14:14:58 +03:00
Svyatoslav Kuzmich c0d48e3417 [Wasm] Support external functions 2021-09-16 14:14:58 +03:00
Svyatoslav Kuzmich 7e399202a2 [Wasm] Support generating browser-compatible JS harness
* Use fetch and instantiateStreaming
* Call main export if it is present
* Produce a variable with module name that contains a
  promise of module exports
2021-09-16 14:14:58 +03:00
Igor Chevdar e194a07358 [tests] Added some tests 2021-09-16 10:54:14 +00:00
Igor Chevdar cc75b45479 [K/N][IR] Fix for https://youtrack.jetbrains.com/issue/KT-47669
Outer this references should be lowered before inliner
2021-09-16 10:54:14 +00:00
Yahor Berdnikau 03db8e9c43 Fix 'kotlinOptions.jdkHome' deprecation message typo.
Use proper DSL example how-to set toolchain.

^KT-48768 Fixed
2021-09-16 11:51:32 +02:00