Skip to content

Commit

Permalink
0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Aug 10, 2020
1 parent bb834d4 commit e5ab51d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README-chs.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fun test(a1: Int, a2: Any): String = runBlocking { test(a1, a2) }
`build.gradle``build.gradle.kts`
```kotlin
plugins {
id("net.mamoe.kotlin-jvm-blocking-bridge") version "0.6.10"
id("net.mamoe.kotlin-jvm-blocking-bridge") version "0.7.0"
}
```

Expand All @@ -142,7 +142,7 @@ pluginManagement {

本插件会自动添加如下的运行时依赖:
```kotlin
implementation("net.mamoe:kotlin-jvm-blocking-bridge:0.6.10")
implementation("net.mamoe:kotlin-jvm-blocking-bridge:0.7.0")
```
因此只需要安装插件, 而不需要添加依赖即可使用

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ The plugin is ready to use.
`build.gradle` or `build.gradle.kts`
```kotlin
plugins {
id("net.mamoe.kotlin-jvm-blocking-bridge") version "0.6.10"
id("net.mamoe.kotlin-jvm-blocking-bridge") version "0.7.0"
}
```

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object Versions {
const val project = "0.6.10"
const val idePlugin = "1.0.0"
const val project = "0.7.0"
const val idePlugin = "1.1.0"

const val kotlin = "1.4.0-rc"
const val coroutines = "1.3.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.ir.*
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
import org.jetbrains.kotlin.backend.jvm.codegen.fileParent
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
Expand All @@ -20,9 +21,9 @@ import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
import java.util.*


Expand All @@ -48,7 +49,7 @@ internal fun IrFunction.isExplicitOrImplicitStatic(): Boolean {
}

internal fun IrPluginContext.createGeneratedBlockingBridgeConstructorCall(
symbol: IrSymbol
symbol: IrSymbol,
): IrConstructorCall {
return createIrBuilder(symbol).run {
irCall(referenceClass(GENERATED_BLOCKING_BRIDGE_FQ_NAME)!!.constructors.first())
Expand All @@ -58,7 +59,10 @@ internal fun IrPluginContext.createGeneratedBlockingBridgeConstructorCall(
}


internal fun IrClass.hasDuplicateBridgeFunction(originFunction: IrFunction): Boolean {
internal val IrDeclarationContainer.functions: Sequence<IrSimpleFunction>
get() = declarations.asSequence().filterIsInstance<IrSimpleFunction>()

internal fun IrDeclarationContainer.hasDuplicateBridgeFunction(originFunction: IrFunction): Boolean {
val params = originFunction.allParameters
val typePrams = originFunction.allTypeParameters
return this.functions
Expand All @@ -69,10 +73,18 @@ internal fun IrClass.hasDuplicateBridgeFunction(originFunction: IrFunction): Boo
.any()
}

internal fun IrFunction.hasDuplicateBridgeFunction(): Boolean = parentAsClass.hasDuplicateBridgeFunction(this)
internal val IrDeclaration.parentFileOrClass: IrDeclarationContainer get() = this.parentClassOrNull ?: fileParent

internal fun IrFunction.hasDuplicateBridgeFunction(): Boolean = parentFileOrClass.hasDuplicateBridgeFunction(this)

internal fun IrType.isClassType(fqName: FqNameUnsafe, hasQuestionMark: Boolean? = null): Boolean {
if (this !is IrSimpleType) return false
if (hasQuestionMark != null && this.hasQuestionMark != hasQuestionMark) return false
return classifier.isClassWithFqName(fqName)
}

fun IrPluginContext.generateJvmBlockingBridges(originFunction: IrFunction): List<IrDeclaration> {
val originClass = originFunction.parentAsClass
val originDeclaration = originFunction.parentFileOrClass

val bridgeFunction = buildFun {
startOffset = originFunction.startOffset
Expand All @@ -93,10 +105,10 @@ fun IrPluginContext.generateJvmBlockingBridges(originFunction: IrFunction): List
this.copyParameterDeclarationsFrom(originFunction)

this.annotations = originFunction.annotations
.filterNot { it.type.safeAs<IrClass>()?.isJvmBlockingBridge() == true }
.filterNot { it.type.isClassType(JVM_BLOCKING_BRIDGE_FQ_NAME.toUnsafe()) }
.plus(createGeneratedBlockingBridgeConstructorCall(symbol))

this.parent = originClass
this.parent = originDeclaration

this.extensionReceiverParameter = originFunction.extensionReceiverParameter?.copyTo(this@fn)
this.dispatchReceiverParameter =
Expand Down Expand Up @@ -175,7 +187,7 @@ internal val Name.identifierOrMappedSpecialName: String
internal fun IrPluginContext.createSuspendLambdaWithCoroutineScope(
parent: IrDeclarationParent,
lambdaType: IrSimpleType,
originFunction: IrFunction
originFunction: IrFunction,
): IrClass {
@Suppress("RemoveExplicitTypeArguments") // Kotlin 1.4-M3 bug
return buildClass {
Expand Down Expand Up @@ -254,7 +266,7 @@ internal fun IrPluginContext.createSuspendLambdaWithCoroutineScope(
internal fun IrPluginContext.createIrBuilder(
symbol: IrSymbol,
startOffset: Int = UNDEFINED_OFFSET,
endOffset: Int = UNDEFINED_OFFSET
endOffset: Int = UNDEFINED_OFFSET,
) = DeclarationIrBuilder(this, symbol, startOffset, endOffset)


Expand All @@ -265,7 +277,7 @@ internal fun IrBuilderWithScope.irBlock(
origin: IrStatementOrigin? = null,
resultType: IrType? = null,
isTransparent: Boolean = false,
body: IrBlockBuilder.() -> Unit
body: IrBlockBuilder.() -> Unit,
): IrContainerExpression =
IrBlockBuilder(
context, scope,
Expand All @@ -277,7 +289,7 @@ internal fun IrBuilderWithScope.irBlock(
internal fun IrBuilderWithScope.irBlockBody(
startOffset: Int = this.startOffset,
endOffset: Int = this.endOffset,
body: IrBlockBodyBuilder.() -> Unit
body: IrBlockBodyBuilder.() -> Unit,
): IrBlockBody =
IrBlockBodyBuilder(
context, scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.*

internal const val JBB_VERSION = "0.6.10"
internal const val JBB_VERSION = "0.7.0"

internal const val PLUGIN_ID = "net.mamoe.kotlin-jvm-blocking-bridge-compiler-embeddable"

Expand Down

0 comments on commit e5ab51d

Please sign in to comment.