Migrate to release coroutines

This commit is contained in:
Dmitry Petrov
2018-09-18 14:11:52 +03:00
committed by Ilmir Usmanov
parent bbc73ec0e5
commit 0191e3d1cf
17 changed files with 46 additions and 55 deletions
+3 -4
View File
@@ -123,8 +123,8 @@ extra["versions.junit"] = "4.12"
extra["versions.javaslang"] = "2.0.6" extra["versions.javaslang"] = "2.0.6"
extra["versions.ant"] = "1.8.2" extra["versions.ant"] = "1.8.2"
extra["versions.android"] = "2.3.1" extra["versions.android"] = "2.3.1"
extra["versions.kotlinx-coroutines-core"] = "0.20" extra["versions.kotlinx-coroutines-core"] = "0.26.1-eap13"
extra["versions.kotlinx-coroutines-jdk8"] = "0.20" extra["versions.kotlinx-coroutines-jdk8"] = "0.26.1-eap13"
extra["versions.json"] = "20160807" extra["versions.json"] = "20160807"
extra["versions.native-platform"] = "0.14" extra["versions.native-platform"] = "0.14"
extra["versions.ant-launcher"] = "1.8.0" extra["versions.ant-launcher"] = "1.8.0"
@@ -274,8 +274,7 @@ allprojects {
val commonCompilerArgs = listOfNotNull( val commonCompilerArgs = listOfNotNull(
"-Xallow-kotlin-package", "-Xallow-kotlin-package",
"-Xread-deserialized-contracts", "-Xread-deserialized-contracts",
"-Xprogressive".takeIf { hasProperty("test.progressive.mode") }, // TODO: change to "-progressive" after bootstrap "-Xprogressive".takeIf { hasProperty("test.progressive.mode") } // TODO: change to "-progressive" after bootstrap
"-XXLanguage:-ReleaseCoroutines"
) )
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> { tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>> {
@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.script package org.jetbrains.kotlin.script
import kotlinx.coroutines.experimental.runBlocking import kotlinx.coroutines.runBlocking
import kotlin.script.experimental.dependencies.DependenciesResolver import kotlin.script.experimental.dependencies.DependenciesResolver
import kotlin.script.dependencies.Environment import kotlin.script.dependencies.Environment
import kotlin.script.dependencies.ScriptContents import kotlin.script.dependencies.ScriptContents
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.storage.getValue import org.jetbrains.kotlin.storage.getValue
import java.util.* import java.util.*
import kotlin.coroutines.experimental.buildSequence
class ResolverForModule( class ResolverForModule(
val packageFragmentProvider: PackageFragmentProvider, val packageFragmentProvider: PackageFragmentProvider,
@@ -346,7 +345,7 @@ class LazyModuleDependencies<M : ModuleInfo>(
) : ModuleDependencies { ) : ModuleDependencies {
private val dependencies = storageManager.createLazyValue { private val dependencies = storageManager.createLazyValue {
val moduleDescriptor = resolverForProject.descriptorForModule(module) val moduleDescriptor = resolverForProject.descriptorForModule(module)
buildSequence { sequence {
if (firstDependency != null) { if (firstDependency != null) {
yield(resolverForProject.descriptorForModule(firstDependency)) yield(resolverForProject.descriptorForModule(firstDependency))
} }
@@ -53,7 +53,6 @@ import org.jetbrains.kotlin.types.typeUtil.makeNullable
import org.jetbrains.kotlin.utils.yieldIfNotNull import org.jetbrains.kotlin.utils.yieldIfNotNull
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.experimental.buildSequence
sealed class DoubleColonLHS(val type: KotlinType) { sealed class DoubleColonLHS(val type: KotlinType) {
/** /**
@@ -715,13 +714,13 @@ class DoubleColonExpressionResolver(
?.apply { commitTrace() }?.results ?.apply { commitTrace() }?.results
} }
val resultSequence = buildSequence { val resultSequence = sequence {
when (lhs) { when (lhs) {
is DoubleColonLHS.Type -> { is DoubleColonLHS.Type -> {
val classifier = lhsType.constructor.declarationDescriptor val classifier = lhsType.constructor.declarationDescriptor
if (classifier !is ClassDescriptor) { if (classifier !is ClassDescriptor) {
c.trace.report(CALLABLE_REFERENCE_LHS_NOT_A_CLASS.on(expression)) c.trace.report(CALLABLE_REFERENCE_LHS_NOT_A_CLASS.on(expression))
return@buildSequence return@sequence
} }
val qualifier = c.trace.get(BindingContext.QUALIFIER, expression.receiverExpression!!) val qualifier = c.trace.get(BindingContext.QUALIFIER, expression.receiverExpression!!)
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
import kotlin.coroutines.experimental.buildSequence
import kotlin.script.templates.standard.ScriptTemplateWithArgs import kotlin.script.templates.standard.ScriptTemplateWithArgs
class ScriptProviderTest : KtUsefulTestCase() { class ScriptProviderTest : KtUsefulTestCase() {
@@ -71,7 +70,7 @@ private class TestScriptDefinitionSource(val counter: AtomicInteger, val defGens
{ {
constructor(counter: AtomicInteger, vararg suffixes: String) : this(counter, suffixes.map { { FakeScriptDefinition(it) } }) constructor(counter: AtomicInteger, vararg suffixes: String) : this(counter, suffixes.map { { FakeScriptDefinition(it) } })
override val definitions: Sequence<KotlinScriptDefinition> = buildSequence { override val definitions: Sequence<KotlinScriptDefinition> = sequence {
for (gen in defGens) { for (gen in defGens) {
counter.incrementAndGet() counter.incrementAndGet()
yield(gen()) yield(gen())
@@ -17,13 +17,12 @@
package org.jetbrains.kotlin.utils package org.jetbrains.kotlin.utils
import java.util.* import java.util.*
import kotlin.coroutines.experimental.SequenceBuilder
fun <K, V> Iterable<K>.keysToMap(value: (K) -> V): Map<K, V> { fun <K, V> Iterable<K>.keysToMap(value: (K) -> V): Map<K, V> {
return associateBy({ it }, value) return associateBy({ it }, value)
} }
fun <K, V: Any> Iterable<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K, V> { fun <K, V : Any> Iterable<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K, V> {
val map = LinkedHashMap<K, V>() val map = LinkedHashMap<K, V>()
for (k in this) { for (k in this) {
val v = value(k) val v = value(k)
@@ -47,45 +46,44 @@ inline fun <K, V> MutableMap<K, V>.getOrPutNullable(key: K, defaultValue: () ->
val answer = defaultValue() val answer = defaultValue()
put(key, answer) put(key, answer)
answer answer
} } else {
else {
get(key) as V get(key) as V
} }
} }
inline fun <T, C: Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpty()) body() else this inline fun <T, C : Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpty()) body() else this
inline fun <K, V, M: Map<K, V>> M.ifEmpty(body: () -> M): M = if (isEmpty()) body() else this inline fun <K, V, M : Map<K, V>> M.ifEmpty(body: () -> M): M = if (isEmpty()) body() else this
inline fun <T> Array<out T>.ifEmpty(body: () -> Array<out T>): Array<out T> = if (isEmpty()) body() else this inline fun <T> Array<out T>.ifEmpty(body: () -> Array<out T>): Array<out T> = if (isEmpty()) body() else this
fun <T: Any> MutableCollection<T>.addIfNotNull(t: T?) { fun <T : Any> MutableCollection<T>.addIfNotNull(t: T?) {
if (t != null) add(t) if (t != null) add(t)
} }
suspend fun <T: Any> SequenceBuilder<T>.yieldIfNotNull(t: T?) = if (t != null) yield(t) else Unit suspend fun <T : Any> SequenceScope<T>.yieldIfNotNull(t: T?) = if (t != null) yield(t) else Unit
fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> = fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> =
HashMap(capacity(expectedSize)) HashMap(capacity(expectedSize))
fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> = fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> =
HashSet(capacity(expectedSize)) HashSet(capacity(expectedSize))
fun <K, V> newLinkedHashMapWithExpectedSize(expectedSize: Int): LinkedHashMap<K, V> = fun <K, V> newLinkedHashMapWithExpectedSize(expectedSize: Int): LinkedHashMap<K, V> =
LinkedHashMap(capacity(expectedSize)) LinkedHashMap(capacity(expectedSize))
fun <E> newLinkedHashSetWithExpectedSize(expectedSize: Int): LinkedHashSet<E> = fun <E> newLinkedHashSetWithExpectedSize(expectedSize: Int): LinkedHashSet<E> =
LinkedHashSet(capacity(expectedSize)) LinkedHashSet(capacity(expectedSize))
private fun capacity(expectedSize: Int): Int = private fun capacity(expectedSize: Int): Int =
if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1 if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1
fun <T> ArrayList<T>.compact(): List<T> = fun <T> ArrayList<T>.compact(): List<T> =
when (size) { when (size) {
0 -> emptyList() 0 -> emptyList()
1 -> listOf(first()) 1 -> listOf(first())
else -> apply { trimToSize() } else -> apply { trimToSize() }
} }
fun <T> List<T>.indexOfFirst(startFrom: Int, predicate: (T) -> Boolean): Int { fun <T> List<T>.indexOfFirst(startFrom: Int, predicate: (T) -> Boolean): Int {
for (index in startFrom..lastIndex) { for (index in startFrom..lastIndex) {
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.script.findScriptDefinition
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
import org.jetbrains.kotlin.utils.sure import org.jetbrains.kotlin.utils.sure
import org.jetbrains.kotlin.utils.yieldIfNotNull import org.jetbrains.kotlin.utils.yieldIfNotNull
import kotlin.coroutines.experimental.buildSequence
var PsiFile.forcedModuleInfo: ModuleInfo? by UserDataProperty(Key.create("FORCED_MODULE_INFO")) var PsiFile.forcedModuleInfo: ModuleInfo? by UserDataProperty(Key.create("FORCED_MODULE_INFO"))
@@ -121,7 +120,7 @@ private sealed class ModuleInfoCollector<out T>(
emptySequence() emptySequence()
}, },
virtualFileProcessor = { project, virtualFile, isLibrarySource -> virtualFileProcessor = { project, virtualFile, isLibrarySource ->
buildSequence { sequence {
collectInfosByVirtualFile( collectInfosByVirtualFile(
project, project,
virtualFile, virtualFile,
@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.idea.completion package org.jetbrains.kotlin.idea.completion
import kotlinx.coroutines.experimental.channels.ConflatedChannel import kotlinx.coroutines.channels.ConflatedChannel
import java.lang.System.currentTimeMillis import java.lang.System.currentTimeMillis
@@ -24,7 +24,7 @@ import com.intellij.psi.PsiElementFinder
import com.intellij.psi.PsiManager import com.intellij.psi.PsiManager
import com.intellij.psi.search.NonClasspathDirectoriesScope import com.intellij.psi.search.NonClasspathDirectoriesScope
import com.intellij.util.containers.SLRUMap import com.intellij.util.containers.SLRUMap
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.launch
import org.jetbrains.kotlin.idea.core.util.EDT import org.jetbrains.kotlin.idea.core.util.EDT
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
import java.io.File import java.io.File
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.core.script.dependencies
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFile
import kotlinx.coroutines.experimental.* import kotlinx.coroutines.*
import org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings import org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings
import org.jetbrains.kotlin.idea.core.util.cancelOnDisposal import org.jetbrains.kotlin.idea.core.util.cancelOnDisposal
import org.jetbrains.kotlin.script.KotlinScriptDefinition import org.jetbrains.kotlin.script.KotlinScriptDefinition
@@ -22,10 +22,10 @@ import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Disposer
import kotlinx.coroutines.experimental.CoroutineDispatcher import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.experimental.Job import kotlinx.coroutines.Job
import kotlin.coroutines.experimental.AbstractCoroutineContextElement import kotlin.coroutines.AbstractCoroutineContextElement
import kotlin.coroutines.experimental.CoroutineContext import kotlin.coroutines.CoroutineContext
public object EDT : CoroutineDispatcher() { public object EDT : CoroutineDispatcher() {
@@ -36,10 +36,10 @@ import com.intellij.psi.search.GlobalSearchScope
import com.intellij.ui.components.JBLabel import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField import com.intellij.ui.components.JBTextField
import com.intellij.uiDesigner.core.GridConstraints import com.intellij.uiDesigner.core.GridConstraints
import kotlinx.coroutines.experimental.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.experimental.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.experimental.withTimeout import kotlinx.coroutines.withTimeout
import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.caches.project.ModuleOrigin import org.jetbrains.kotlin.idea.caches.project.ModuleOrigin
import org.jetbrains.kotlin.idea.caches.project.getNullableModuleInfo import org.jetbrains.kotlin.idea.caches.project.getNullableModuleInfo
@@ -32,9 +32,9 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.ui.components.JBPanel import com.intellij.ui.components.JBPanel
import com.intellij.ui.components.JBTextField import com.intellij.ui.components.JBTextField
import com.intellij.uiDesigner.core.GridLayoutManager import com.intellij.uiDesigner.core.GridLayoutManager
import kotlinx.coroutines.experimental.channels.ConflatedChannel import kotlinx.coroutines.channels.ConflatedChannel
import kotlinx.coroutines.experimental.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.launch
import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.addBoxWithLabel import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.addBoxWithLabel
import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.collectSuitableKotlinFiles import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.collectSuitableKotlinFiles
import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.shuffledSequence import org.jetbrains.kotlin.idea.actions.internal.benchmark.AbstractCompletionBenchmarkAction.Companion.shuffledSequence
@@ -34,8 +34,6 @@ import org.jetbrains.kotlin.psi.KtEscapeStringTemplateEntry
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtStringTemplateExpression import org.jetbrains.kotlin.psi.KtStringTemplateExpression
import org.jetbrains.kotlin.psi.psiUtil.* import org.jetbrains.kotlin.psi.psiUtil.*
import kotlin.coroutines.experimental.SequenceBuilder
import kotlin.coroutines.experimental.buildIterator
private val PsiElement.templateContentRange: TextRange? private val PsiElement.templateContentRange: TextRange?
get() = this.getParentOfType<KtStringTemplateExpression>(false)?.let{ get() = this.getParentOfType<KtStringTemplateExpression>(false)?.let{
@@ -219,7 +217,7 @@ private class TemplateTokenSequence(private val inputString: String) : Sequence<
} }
} }
private suspend fun SequenceBuilder<TemplateChunk>.yieldLiteral(chunk: String) { private suspend fun SequenceScope<TemplateChunk>.yieldLiteral(chunk: String) {
val splitLines = LineTokenizer.tokenize(chunk, false, false) val splitLines = LineTokenizer.tokenize(chunk, false, false)
for (i in 0..splitLines.size - 1) { for (i in 0..splitLines.size - 1) {
if (i != 0) { if (i != 0) {
@@ -233,7 +231,7 @@ private class TemplateTokenSequence(private val inputString: String) : Sequence<
if (inputString.isEmpty()) { if (inputString.isEmpty()) {
return emptySequence<TemplateChunk>().iterator() return emptySequence<TemplateChunk>().iterator()
} }
return buildIterator { return iterator {
var from = 0 var from = 0
var to = 0 var to = 0
while (to < inputString.length) { while (to < inputString.length) {
@@ -23,8 +23,8 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiRecursiveElementVisitor import com.intellij.psi.PsiRecursiveElementVisitor
import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.psi.codeStyle.CodeStyleManager
import kotlinx.coroutines.experimental.run import kotlinx.coroutines.run
import kotlinx.coroutines.experimental.runBlocking import kotlinx.coroutines.runBlocking
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
import org.jetbrains.kotlin.idea.conversion.copy.range import org.jetbrains.kotlin.idea.conversion.copy.range
@@ -18,8 +18,8 @@
package kotlin.script.experimental.host package kotlin.script.experimental.host
import kotlinx.coroutines.experimental.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.experimental.runBlocking import kotlinx.coroutines.runBlocking
import kotlin.script.experimental.api.* import kotlin.script.experimental.api.*
/** /**
@@ -5,7 +5,7 @@
package kotlin.script.experimental.jvm.impl package kotlin.script.experimental.jvm.impl
import kotlinx.coroutines.experimental.runBlocking import kotlinx.coroutines.runBlocking
import java.io.File import java.io.File
import kotlin.script.dependencies.Environment import kotlin.script.dependencies.Environment
import kotlin.script.dependencies.ScriptContents import kotlin.script.dependencies.ScriptContents