Upgrade to Kotlin 1.4.20

This commit is contained in:
Brian Norman
2020-11-20 16:04:49 -06:00
parent 19bb4742e1
commit 7d878b17d9
7 changed files with 29 additions and 18 deletions
+9
View File
@@ -0,0 +1,9 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.{kt,kts}]
indent_style = space
indent_size = 2
+2 -2
View File
@@ -75,7 +75,7 @@ Builds of the Gradle plugin are available through the
```kotlin ```kotlin
plugins { plugins {
kotlin("jvm") version "1.4.0" kotlin("jvm") version "1.4.20"
id("com.bnorm.power.kotlin-power-assert") version "0.5.3" id("com.bnorm.power.kotlin-power-assert") version "0.5.3"
} }
``` ```
@@ -94,7 +94,7 @@ configure<com.bnorm.power.PowerAssertGradleExtension> {
## Kotlin IR ## Kotlin IR
Using this compiler plugin only works if the code is compiled using Kotlin Using this compiler plugin only works if the code is compiled using Kotlin
1.4.0 and IR is enabled. This includes all IR based compiler backends: JVM, JS, 1.4.20 and IR is enabled. This includes all IR based compiler backends: JVM, JS,
and Native! As Kotlin IR is still experimental, mileage may vary. and Native! As Kotlin IR is still experimental, mileage may vary.
##### Kotlin/JVM ##### Kotlin/JVM
+1 -1
View File
@@ -1,5 +1,5 @@
plugins { plugins {
kotlin("jvm") version "1.4.0" apply false kotlin("jvm") version "1.4.20" apply false
id("org.jetbrains.dokka") version "0.10.0" apply false id("org.jetbrains.dokka") version "0.10.0" apply false
id("com.gradle.plugin-publish") version "0.11.0" apply false id("com.gradle.plugin-publish") version "0.11.0" apply false
id("com.github.gmazzo.buildconfig") version "2.0.2" apply false id("com.github.gmazzo.buildconfig") version "2.0.2" apply false
@@ -16,6 +16,7 @@
package com.bnorm.power package com.bnorm.power
import org.jetbrains.kotlin.backend.common.ir.isSuspend
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
@@ -23,10 +24,13 @@ import org.jetbrains.kotlin.ir.builders.irConcat
import org.jetbrains.kotlin.ir.builders.irGet import org.jetbrains.kotlin.ir.builders.irGet
import org.jetbrains.kotlin.ir.builders.irString import org.jetbrains.kotlin.ir.builders.irString
import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
data class IrStackVariable( data class IrStackVariable(
val temporary: IrVariable, val temporary: IrVariable,
@@ -62,11 +66,10 @@ fun IrBuilderWithScope.buildMessage(
var row = info.startLineNumber - originalInfo.startLineNumber var row = info.startLineNumber - originalInfo.startLineNumber
val columnOffset: Int = when (original) { val columnOffset: Int = when (original) {
is IrMemberAccessExpression -> { is IrMemberAccessExpression<*> -> {
// TODO IrFunction doesn't have 'isInfix' as a property val owner = original.symbol.owner
val descriptor = original.symbol.descriptor
when { when {
descriptor is FunctionDescriptor && descriptor.isInfix -> source.indexOf(descriptor.name.asString()) owner is IrSimpleFunction && owner.isInfix -> source.indexOf(owner.name.asString())
else -> when (original.origin) { else -> when (original.origin) {
// TODO handle equality and comparison better? // TODO handle equality and comparison better?
IrStatementOrigin.EQEQ, IrStatementOrigin.EQEQEQ -> source.indexOf("==") IrStatementOrigin.EQEQ, IrStatementOrigin.EQEQEQ -> source.indexOf("==")
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.backend.common.ir.inline
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
import org.jetbrains.kotlin.backend.common.lower.at import org.jetbrains.kotlin.backend.common.lower.at
import org.jetbrains.kotlin.cli.common.messages.* import org.jetbrains.kotlin.cli.common.messages.*
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.declarations.buildFun
@@ -48,9 +47,9 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.util.OperatorNameConventions
import java.io.File import java.io.File
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
fun FileLoweringPass.runOnFileInOrder(irFile: IrFile) { fun FileLoweringPass.runOnFileInOrder(irFile: IrFile) {
irFile.acceptVoid(object : IrElementVisitorVoid { irFile.acceptVoid(object : IrElementVisitorVoid {
@@ -81,8 +80,7 @@ class PowerAssertCallTransformer(
} }
override fun visitCall(expression: IrCall): IrExpression { override fun visitCall(expression: IrCall): IrExpression {
// TODO expression.symbol.owner.fqNameSafe includes the wrapping ClassKt while descriptor doesn't val fqName = expression.symbol.owner.kotlinFqName
val fqName = expression.symbol.descriptor.fqNameSafe
if (functions.none { fqName == it }) if (functions.none { fqName == it })
return super.visitCall(expression) return super.visitCall(expression)
@@ -179,10 +177,10 @@ class PowerAssertCallTransformer(
object : FunctionDelegate { object : FunctionDelegate {
override fun buildCall(builder: IrBuilderWithScope, original: IrCall, message: IrExpression): IrExpression = with(builder) { override fun buildCall(builder: IrBuilderWithScope, original: IrCall, message: IrExpression): IrExpression = with(builder) {
val scope = this val scope = this
val lambda = buildFun { val lambda = builder.context.irFactory.buildFun {
name = Name.special("<anonymous>") name = Name.special("<anonymous>")
returnType = context.irBuiltIns.stringType returnType = context.irBuiltIns.stringType
visibility = Visibilities.LOCAL visibility = DescriptorVisibilities.LOCAL
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
}.apply { }.apply {
val bodyBuilder = DeclarationIrBuilder(this@PowerAssertCallTransformer.context, symbol) val bodyBuilder = DeclarationIrBuilder(this@PowerAssertCallTransformer.context, symbol)
@@ -2,7 +2,7 @@
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
* *
* Copied from https://github.com/JetBrains/kotlin/blob/1.4.0/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt * Copied from https://github.com/JetBrains/kotlin/blob/1.4.20/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ReturnableBlockLowering.kt
*/ */
package com.bnorm.power.internal package com.bnorm.power.internal
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.transformStatement
// TODO Remove when inlining works correctly on Kotlin/JS and Kotlin/Native // TODO Remove when inlining works correctly on Kotlin/JS and Kotlin/Native
class ReturnableBlockTransformer(val context: IrGeneratorContext, val containerSymbol: IrSymbol? = null) : IrElementTransformerVoidWithContext() { class ReturnableBlockTransformer(val context: IrGeneratorContext, val containerSymbol: IrSymbol? = null) : IrElementTransformerVoidWithContext() {
@@ -52,7 +53,7 @@ class ReturnableBlockTransformer(val context: IrGeneratorContext, val containerS
returnMap[expression.symbol] = { returnExpression -> returnMap[expression.symbol] = { returnExpression ->
hasReturned = true hasReturned = true
builder.irComposite(returnExpression) { builder.irComposite(returnExpression) {
+irSetVar(variable.symbol, returnExpression.value) +irSet(variable.symbol, returnExpression.value)
+irBreak(loop) +irBreak(loop)
} }
} }
@@ -61,10 +62,10 @@ class ReturnableBlockTransformer(val context: IrGeneratorContext, val containerS
if (i == expression.statements.lastIndex && s is IrReturn && s.returnTargetSymbol == expression.symbol) { if (i == expression.statements.lastIndex && s is IrReturn && s.returnTargetSymbol == expression.symbol) {
s.transformChildrenVoid() s.transformChildrenVoid()
if (!hasReturned) s.value else { if (!hasReturned) s.value else {
builder.irSetVar(variable.symbol, s.value) builder.irSet(variable.symbol, s.value)
} }
} else { } else {
s.transform(this, null) s.transformStatement(this)
} }
} }
+1 -1
View File
@@ -1,5 +1,5 @@
plugins { plugins {
kotlin("multiplatform") version "1.4.0" kotlin("multiplatform") version "1.4.20"
id("com.bnorm.power.kotlin-power-assert") version "0.5.3" id("com.bnorm.power.kotlin-power-assert") version "0.5.3"
} }