Backend: Partially get rid of descriptors in InteropLowering

This commit is contained in:
Ilya Matveev
2019-09-02 19:00:38 +07:00
committed by Ilya Matveev
parent 8a6146ac08
commit ee4dbfaa67
2 changed files with 35 additions and 17 deletions
@@ -5,13 +5,16 @@
package org.jetbrains.kotlin.backend.konan.lower package org.jetbrains.kotlin.backend.konan.lower
import org.jetbrains.kotlin.backend.common.* import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor
import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDescriptor import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDescriptor
import org.jetbrains.kotlin.backend.common.ir.copyTo import org.jetbrains.kotlin.backend.common.ir.copyTo
import org.jetbrains.kotlin.backend.common.ir.createDispatchReceiverParameter import org.jetbrains.kotlin.backend.common.ir.createDispatchReceiverParameter
import org.jetbrains.kotlin.backend.common.ir.simpleFunctions import org.jetbrains.kotlin.backend.common.ir.simpleFunctions
import org.jetbrains.kotlin.backend.common.lower.* import org.jetbrains.kotlin.backend.common.lower.*
import org.jetbrains.kotlin.backend.common.peek
import org.jetbrains.kotlin.backend.common.pop
import org.jetbrains.kotlin.backend.common.push
import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.*
import org.jetbrains.kotlin.backend.konan.cgen.* import org.jetbrains.kotlin.backend.konan.cgen.*
import org.jetbrains.kotlin.backend.konan.descriptors.allOverriddenFunctions import org.jetbrains.kotlin.backend.konan.descriptors.allOverriddenFunctions
@@ -19,13 +22,10 @@ import org.jetbrains.kotlin.backend.konan.descriptors.isInterface
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.backend.konan.ir.*
import org.jetbrains.kotlin.backend.konan.ir.companionObject import org.jetbrains.kotlin.backend.konan.ir.companionObject
import org.jetbrains.kotlin.backend.konan.ir.containsNull
import org.jetbrains.kotlin.backend.konan.llvm.IntrinsicType import org.jetbrains.kotlin.backend.konan.llvm.IntrinsicType
import org.jetbrains.kotlin.backend.konan.llvm.llvmSymbolOrigin
import org.jetbrains.kotlin.backend.konan.llvm.tryGetIntrinsicType import org.jetbrains.kotlin.backend.konan.llvm.tryGetIntrinsicType
import org.jetbrains.kotlin.builtins.UnsignedTypes import org.jetbrains.kotlin.builtins.UnsignedTypes
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.*
@@ -33,7 +33,10 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
@@ -318,7 +321,7 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo
currentFile, property) currentFile, property)
} }
val name = descriptor.name.asString() val name = property.name.asString()
val selector = "set${name.capitalize()}:" val selector = "set${name.capitalize()}:"
return generateFunctionImp(selector, property.setter!!) return generateFunctionImp(selector, property.setter!!)
@@ -620,11 +623,10 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo
override fun visitConstructorCall(expression: IrConstructorCall): IrExpression { override fun visitConstructorCall(expression: IrConstructorCall): IrExpression {
expression.transformChildrenVoid() expression.transformChildrenVoid()
val descriptor = expression.descriptor.original
val callee = expression.symbol.owner val callee = expression.symbol.owner
val initMethod = callee.getObjCInitMethod() ?: return expression val initMethod = callee.getObjCInitMethod() ?: return expression
val arguments = descriptor.valueParameters.map { expression.getValueArgument(it) } val arguments = callee.valueParameters.map { expression.getValueArgument(it.index) }
assert(expression.extensionReceiver == null) assert(expression.extensionReceiver == null)
assert(expression.dispatchReceiver == null) assert(expression.dispatchReceiver == null)
@@ -663,7 +665,7 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo
builder.scope.scopeOwner.annotations.hasAnnotation(FqName("kotlin.native.internal.ExportForCppRuntime")) builder.scope.scopeOwner.annotations.hasAnnotation(FqName("kotlin.native.internal.ExportForCppRuntime"))
if (!useKotlinDispatch) { if (!useKotlinDispatch) {
val arguments = descriptor.valueParameters.map { expression.getValueArgument(it) } val arguments = callee.valueParameters.map { expression.getValueArgument(it.index) }
assert(expression.dispatchReceiver == null || expression.extensionReceiver == null) assert(expression.dispatchReceiver == null || expression.extensionReceiver == null)
if (expression.superQualifier?.isObjCMetaClass() == true) { if (expression.superQualifier?.isObjCMetaClass() == true) {
@@ -846,7 +848,7 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi
} }
if (function.annotations.hasAnnotation(RuntimeNames.cCall)) { if (function.annotations.hasAnnotation(RuntimeNames.cCall)) {
context.llvmImports.add(function.descriptor.llvmSymbolOrigin) context.llvmImports.add(function.llvmSymbolOrigin)
return generateWithStubs { generateCCall(expression, builder, isInvoke = false) } return generateWithStubs { generateCCall(expression, builder, isInvoke = false) }
} }
@@ -952,7 +954,7 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi
} }
val conversionSymbol = receiverClass.functions.single { val conversionSymbol = receiverClass.functions.single {
it.descriptor.name == Name.identifier("to${targetClass.owner.name}") it.owner.name == Name.identifier("to${targetClass.owner.name}")
} }
builder.irCall(conversionSymbol).apply { builder.irCall(conversionSymbol).apply {
@@ -993,7 +995,7 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi
val intrinsic = interop.objCObjectInitBy.name val intrinsic = interop.objCObjectInitBy.name
val argument = expression.getValueArgument(0)!! val argument = expression.getValueArgument(0)!!
val constructedClass = (argument as? IrConstructorCall)?.symbol?.owner?.constructedClass?.descriptor val constructedClass = (argument as? IrConstructorCall)?.symbol?.owner?.constructedClass
if (constructedClass == null) { if (constructedClass == null) {
context.reportCompilationError("Argument of '$intrinsic' must be a constructor call", context.reportCompilationError("Argument of '$intrinsic' must be a constructor call",
@@ -1002,7 +1004,7 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi
val extensionReceiver = expression.extensionReceiver!! val extensionReceiver = expression.extensionReceiver!!
if (extensionReceiver !is IrGetValue || if (extensionReceiver !is IrGetValue ||
extensionReceiver.descriptor != constructedClass.thisAsReceiverParameter) { !extensionReceiver.symbol.owner.isDispatchReceiverFor(constructedClass)) {
context.reportCompilationError("Receiver of '$intrinsic' must be a 'this' of the constructed class", context.reportCompilationError("Receiver of '$intrinsic' must be a 'this' of the constructed class",
irFile, extensionReceiver) irFile, extensionReceiver)
@@ -1122,11 +1124,22 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi
return argument.statements.last() as? IrFunctionReference return argument.statements.last() as? IrFunctionReference
} }
val IrValueParameter.isDispatchReceiver: Boolean
get() = when(val parent = this.parent) {
is IrClass -> true
is IrFunction -> parent.dispatchReceiverParameter == this
else -> false
}
private fun IrValueDeclaration.isDispatchReceiverFor(irClass: IrClass): Boolean =
this is IrValueParameter && isDispatchReceiver && type.getClass() == irClass
} }
private fun IrCall.getSingleTypeArgument(): IrType { private fun IrCall.getSingleTypeArgument(): IrType {
val typeParameter = descriptor.original.typeParameters.single() val typeParameter = symbol.owner.typeParameters.single()
return getTypeArgument(typeParameter)!! return getTypeArgument(typeParameter.index)!!
} }
private fun IrBuilder.irFloat(value: Float) = private fun IrBuilder.irFloat(value: Float) =
+7 -2
View File
@@ -3460,8 +3460,7 @@ standaloneTest("interop_opengl_teapot") {
*/ */
interopTest("interop_objc_smoke") { interopTest("interop_objc_smoke") {
// Cannot be executed in the two-stage mode due to KT-33160. disabled = !isAppleTarget(project)
disabled = !isAppleTarget(project) || twoStageEnabled
goldValue = "84\nFoo\nDeallocated\n" + goldValue = "84\nFoo\nDeallocated\n" +
"Hello, World!\nKotlin says: Hello, everybody!\nHello from Kotlin\n2, 1\n" + "Hello, World!\nKotlin says: Hello, everybody!\nHello from Kotlin\n2, 1\n" +
"true\ntrue\n" + "true\ntrue\n" +
@@ -3474,6 +3473,12 @@ interopTest("interop_objc_smoke") {
source = "interop/objc/smoke.kt" source = "interop/objc/smoke.kt"
interop = 'objcSmoke' interop = 'objcSmoke'
if (twoStageEnabled) {
// Without this flag the test fails in the two-stage mode due to KT-33160.
// TODO: Remove this flag when the bug is fixed.
flags += "-nodefaultlibs"
}
doBefore { doBefore {
execKonanClang(project.target) { execKonanClang(project.target) {
args "$projectDir/interop/objc/smoke.m" args "$projectDir/interop/objc/smoke.m"