From 4aa73c5b3552b942927b707de1603324566743a0 Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Sun, 18 Oct 2020 14:18:57 +0300 Subject: [PATCH] Adapt to changes in Scope.kt (cherry picked from commit 9bafee3bf0393e6a25f2ee2f610b553392acc492) --- .../jetbrains/kotlin/backend/konan/cgen/CBridgeGen.kt | 5 +++-- .../ir/interop/cenum/CEnumByValueFunctionGenerator.kt | 8 ++++---- .../kotlin/backend/konan/lower/InteropLowering.kt | 3 ++- .../kotlin/backend/konan/lower/VarargLowering.kt | 9 +++++---- .../backend/konan/optimizations/Devirtualization.kt | 8 ++++---- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGen.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGen.kt index babf77e1ad4..b152f77862c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGen.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/cgen/CBridgeGen.kt @@ -319,8 +319,9 @@ internal fun KotlinStubs.generateObjCCall( val callBuilder = KotlinToCCallBuilder(builder, this@generateObjCCall, isObjCMethod = true, exceptionMode) - val superClass = irTemporaryVar( - superQualifier?.let { getObjCClass(symbols, it) } ?: irNullNativePtr(symbols) + val superClass = irTemporary( + superQualifier?.let { getObjCClass(symbols, it) } ?: irNullNativePtr(symbols), + isMutable = true ) val messenger = irCall(if (isStret) { diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/cenum/CEnumByValueFunctionGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/cenum/CEnumByValueFunctionGenerator.kt index d3c0f0541ee..eab5171e6c0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/cenum/CEnumByValueFunctionGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/interop/cenum/CEnumByValueFunctionGenerator.kt @@ -52,8 +52,8 @@ internal class CEnumByValueFunctionGenerator( // throw NPE byValueIrFunction.body = irBuilder(irBuiltIns, byValueIrFunction.symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET).irBlockBody { +irReturn(irBlock { - val values = irTemporaryVar(irCall(valuesIrFunctionSymbol)) - val inductionVariable = irTemporaryVar(irInt(0)) + val values = irTemporary(irCall(valuesIrFunctionSymbol), isMutable = true) + val inductionVariable = irTemporary(irInt(0), isMutable = true) val arrayClass = values.type.classOrNull!! val valuesSize = irCall(symbols.arraySize.getValue(arrayClass), irBuiltIns.intType).also { irCall -> irCall.dispatchReceiver = irGet(values) @@ -67,10 +67,10 @@ internal class CEnumByValueFunctionGenerator( irCall.putValueArgument(1, valuesSize) } loop.body = irBlock { - val entry = irTemporaryVar(irCall(getElementFn, byValueIrFunction.returnType).also { irCall -> + val entry = irTemporary(irCall(getElementFn, byValueIrFunction.returnType).also { irCall -> irCall.dispatchReceiver = irGet(values) irCall.putValueArgument(0, irGet(inductionVariable)) - }) + }, isMutable = true) val valueGetter = entry.type.getClass()!!.getPropertyGetter("value")!! val entryValue = irGet(irValueParameter.type, irGet(entry), valueGetter) +irIfThenElse( diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt index f6ea1d3586d..7328cb3bad5 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt @@ -767,7 +767,8 @@ private class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfor // Special case: bridge from Objective-C method implementation template to Kotlin method; // handled in CodeGeneratorVisitor.callVirtual. val useKotlinDispatch = isInteropStubsFile && - builder.scope.scopeOwner.annotations.hasAnnotation(FqName("kotlin.native.internal.ExportForCppRuntime")) + (builder.scope.scopeOwnerSymbol.owner as? IrAnnotationContainer) + ?.hasAnnotation(FqName("kotlin.native.internal.ExportForCppRuntime")) == true if (!useKotlinDispatch) { val arguments = callee.valueParameters.map { expression.getValueArgument(it.index) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt index da612c61517..0652aea9149 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/VarargLowering.kt @@ -103,18 +103,19 @@ internal class VarargInjectionLowering constructor(val context: KonanBackendCont val arrayHandle = arrayType(expression.type) val vars = expression.elements.map { - it to irTemporaryVar( + it to irTemporary( (it as? IrSpreadElement)?.expression ?: it as IrExpression, - "elem".synthesizedString + "elem".synthesizedString, + isMutable = true ) }.toMap() val arraySize = calculateArraySize(arrayHandle, hasSpreadElement, scope, expression, vars) val array = arrayHandle.createArray(this, expression.varargElementType, arraySize) - val arrayTmpVariable = irTemporaryVar(array, "array".synthesizedString) + val arrayTmpVariable = irTemporary(array, "array".synthesizedString, isMutable = true) lateinit var indexTmpVariable: IrVariable if (hasSpreadElement) - indexTmpVariable = irTemporaryVar(kIntZero, "index".synthesizedString) + indexTmpVariable = irTemporary(kIntZero, "index".synthesizedString, isMutable = true) expression.elements.forEachIndexed { i, element -> irBuilder.at(element.startOffset, element.endOffset) log { "element:$i> ${ir2string(element)}" } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt index 53cf6c28e37..3f67829cdf2 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl -import org.jetbrains.kotlin.ir.descriptors.IrTemporaryVariableDescriptorImpl +import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol @@ -1318,13 +1318,13 @@ internal object Devirtualization { } fun IrStatementsBuilder.irTemporary(value: IrExpression, tempName: String, type: IrType): IrVariable { - val originalKotlinType = type.originalKotlinType ?: type.toKotlinType() - val descriptor = IrTemporaryVariableDescriptorImpl(scope.scopeOwner, Name.identifier(tempName), originalKotlinType, false) + val descriptor = WrappedVariableDescriptor() val temporary = IrVariableImpl( value.startOffset, value.endOffset, IrDeclarationOrigin.IR_TEMPORARY_VARIABLE, IrVariableSymbolImpl(descriptor), - descriptor.name, type, isVar = false, isConst = false, isLateinit = false + Name.identifier(tempName), type, isVar = false, isConst = false, isLateinit = false ).apply { + descriptor.bind(this) this.initializer = value }