diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/AbstractValueUsageTransformer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/AbstractValueUsageTransformer.kt index a9eb3dae8dd..5eba6352049 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/AbstractValueUsageTransformer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/common/AbstractValueUsageTransformer.kt @@ -93,7 +93,7 @@ internal abstract class AbstractValueUsageTransformer( with(expression) { dispatchReceiver = dispatchReceiver?.useAsDispatchReceiver(expression) extensionReceiver = extensionReceiver?.useAsExtensionReceiver(expression) - for (index in descriptor.valueParameters.indices) { + for (index in symbol.owner.valueParameters.indices) { val argument = getValueArgument(index) ?: continue val parameter = symbol.owner.valueParameters[index] putValueArgument(index, argument.useAsValueArgument(expression, parameter)) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt index bca5a1c9501..dbb8a59caae 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt @@ -70,10 +70,6 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns) { val typeOf = packageScope.getContributedFunctions("typeOf").single() - val concurrentPackageScope = builtIns.builtInsModule.getPackage(FqName("kotlin.native.concurrent")).memberScope - - val executeImplFunction = concurrentPackageScope.getContributedFunctions("executeImpl").single() - private fun KonanBuiltIns.getUnsignedClass(unsignedType: UnsignedType): ClassDescriptor = this.builtInsModule.findClassAcrossModuleDependencies(unsignedType.classId)!! diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt index 48c5176d78a..3bab6a5bb71 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ObjCInterop.kt @@ -7,12 +7,15 @@ package org.jetbrains.kotlin.backend.konan import org.jetbrains.kotlin.backend.konan.descriptors.findPackage import org.jetbrains.kotlin.backend.konan.descriptors.getArgumentValueOrNull +import org.jetbrains.kotlin.backend.konan.descriptors.getAnnotationValueOrNull import org.jetbrains.kotlin.backend.konan.descriptors.getStringValue +import org.jetbrains.kotlin.backend.konan.descriptors.getAnnotationStringValue import org.jetbrains.kotlin.backend.konan.descriptors.getStringValueOrNull import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.types.classifierOrFail import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.FqName @@ -44,7 +47,6 @@ fun ClassDescriptor.isObjCClass(): Boolean = fun KotlinType.isObjCObjectType(): Boolean = (this.supertypes() + this).any { TypeUtils.getClassDescriptor(it)?.fqNameSafe == objCObjectFqName } - private fun IrClass.getAllSuperClassifiers(): List = listOf(this) + this.superTypes.flatMap { (it.classifierOrFail.owner as IrClass).getAllSuperClassifiers() } @@ -68,6 +70,10 @@ fun ClassDescriptor.isObjCMetaClass(): Boolean = this.getAllSuperClassifiers().a it.fqNameSafe == objCClassFqName } +fun IrClass.isObjCMetaClass(): Boolean = this.getAllSuperClassifiers().any { + it.fqNameForIrSerialization == objCClassFqName +} + fun IrClass.isObjCProtocolClass(): Boolean = this.fqNameForIrSerialization == objCProtocolFqName @@ -77,6 +83,9 @@ fun ClassDescriptor.isObjCProtocolClass(): Boolean = fun FunctionDescriptor.isObjCClassMethod() = this.containingDeclaration.let { it is ClassDescriptor && it.isObjCClass() } +fun IrFunction.isObjCClassMethod() = + this.parent.let { it is IrClass && it.isObjCClass() } + @Deprecated("Use IR version rather than descriptor version") fun FunctionDescriptor.isExternalObjCClassMethod() = this.containingDeclaration.let { it is ClassDescriptor && it.isExternalObjCClass() } @@ -108,12 +117,24 @@ private fun FunctionDescriptor.decodeObjCMethodAnnotation(): ObjCMethodInfo? { return objCMethodInfo(methodAnnotation) } +private fun IrFunction.decodeObjCMethodAnnotation(): ObjCMethodInfo? { + assert (this.isReal) + val methodAnnotation = this.annotations.findAnnotation(objCMethodFqName) ?: return null + return objCMethodInfo(methodAnnotation) +} + private fun objCMethodInfo(annotation: AnnotationDescriptor) = ObjCMethodInfo( selector = annotation.getStringValue("selector"), encoding = annotation.getStringValue("encoding"), isStret = annotation.getArgumentValueOrNull("isStret") ?: false ) +private fun objCMethodInfo(annotation: IrConstructorCall) = ObjCMethodInfo( + selector = annotation.getAnnotationStringValue("selector"), + encoding = annotation.getAnnotationStringValue("encoding"), + isStret = annotation.getAnnotationValueOrNull("isStret") ?: false +) + /** * @param onlyExternal indicates whether to accept overriding methods from Kotlin classes */ @@ -129,10 +150,29 @@ private fun FunctionDescriptor.getObjCMethodInfo(onlyExternal: Boolean): ObjCMet return this.overriddenDescriptors.asSequence().mapNotNull { it.getObjCMethodInfo(onlyExternal) }.firstOrNull() } +/** + * @param onlyExternal indicates whether to accept overriding methods from Kotlin classes + */ +private fun IrSimpleFunction.getObjCMethodInfo(onlyExternal: Boolean): ObjCMethodInfo? { + if (this.isReal) { + this.decodeObjCMethodAnnotation()?.let { return it } + + if (onlyExternal) { + return null + } + } + + return this.overriddenSymbols.mapNotNull { it.owner.getObjCMethodInfo(onlyExternal) }.firstOrNull() +} + fun FunctionDescriptor.getExternalObjCMethodInfo(): ObjCMethodInfo? = this.getObjCMethodInfo(onlyExternal = true) +fun IrFunction.getExternalObjCMethodInfo(): ObjCMethodInfo? = (this as? IrSimpleFunction)?.getObjCMethodInfo(onlyExternal = true) + fun FunctionDescriptor.getObjCMethodInfo(): ObjCMethodInfo? = this.getObjCMethodInfo(onlyExternal = false) +fun IrFunction.getObjCMethodInfo(): ObjCMethodInfo? = (this as? IrSimpleFunction)?.getObjCMethodInfo(onlyExternal = false) + fun IrFunction.isObjCBridgeBased(): Boolean { assert(this.isReal) @@ -223,7 +263,7 @@ val IrConstructor.isObjCConstructor get() = this.annotations.hasAnnotation(objCC // TODO-DCE-OBJC-INIT: Selector should be preserved by DCE. fun IrConstructor.getObjCInitMethod(): IrSimpleFunction? { return this.annotations.findAnnotation(objCConstructorFqName)?.let { - val initSelector = it.getStringValue("initSelector") + val initSelector = it.getAnnotationStringValue("initSelector") this.constructedClass.declarations.asSequence() .filterIsInstance() .single { it.getExternalObjCMethodInfo()?.selector == initSelector } @@ -239,6 +279,11 @@ fun FunctionDescriptor.getObjCFactoryInitMethodInfo(): ObjCMethodInfo? { return objCMethodInfo(factoryAnnotation) } +fun IrFunction.getObjCFactoryInitMethodInfo(): ObjCMethodInfo? { + val factoryAnnotation = this.annotations.findAnnotation(objCFactoryFqName) ?: return null + return objCMethodInfo(factoryAnnotation) +} + fun inferObjCSelector(descriptor: FunctionDescriptor): String = if (descriptor.valueParameters.isEmpty()) { descriptor.name.asString() } else { 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 38ad0910966..33e04beb9bc 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 @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.util.OperatorNameConventions +import org.jetbrains.kotlin.backend.konan.getObjCMethodInfo internal interface KotlinStubs { val irBuiltIns: IrBuiltIns @@ -538,7 +539,6 @@ internal fun KotlinStubs.generateCFunctionPointer( expression.endOffset, expression.type, fakeFunction.symbol, - fakeFunction.descriptor, 0 ) } @@ -1511,6 +1511,6 @@ private fun KotlinStubs.reportUnsupportedType(reason: String, type: IrType, loca val typeLocation: String = location.render() - reportError(location.element, "type ${type.toKotlinType()}$typeLocation is not supported here" + + reportError(location.element, "type ${type.render()} $typeLocation is not supported here" + if (reason.isNotEmpty()) ": $reason" else "") } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt index 9ec9be73449..57681634671 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt @@ -5,20 +5,21 @@ package org.jetbrains.kotlin.backend.konan.descriptors +import org.jetbrains.kotlin.backend.common.atMostOne import org.jetbrains.kotlin.backend.konan.* -import org.jetbrains.kotlin.backend.konan.descriptors.resolveFakeOverride import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.backend.konan.isObjCClass import org.jetbrains.kotlin.backend.konan.llvm.longName import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.expressions.IrConst import org.jetbrains.kotlin.ir.expressions.IrConstructorCall +import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.types.isUnit import org.jetbrains.kotlin.ir.util.* -import org.jetbrains.kotlin.types.SimpleType /** * List of all implemented interfaces (including those which implemented by a super class) @@ -219,14 +220,14 @@ internal tailrec fun IrDeclaration.findPackage(): IrPackageFragment { ?: (parent as IrDeclaration).findPackage() } -fun IrFunctionSymbol.isComparisonFunction(map: Map): Boolean = +fun IrFunctionSymbol.isComparisonFunction(map: Map): Boolean = this in map.values val IrDeclaration.isPropertyAccessor get() = - this is IrSimpleFunction && this.correspondingProperty != null + this is IrSimpleFunction && this.correspondingPropertySymbol != null val IrDeclaration.isPropertyField get() = - this is IrField && this.correspondingProperty != null + this is IrField && this.correspondingPropertySymbol != null val IrDeclaration.isTopLevelDeclaration get() = parent !is IrDeclaration && !this.isPropertyAccessor && !this.isPropertyField @@ -235,9 +236,9 @@ fun IrDeclaration.findTopLevelDeclaration(): IrDeclaration = when { this.isTopLevelDeclaration -> this this.isPropertyAccessor -> - (this as IrSimpleFunction).correspondingProperty!!.findTopLevelDeclaration() + (this as IrSimpleFunction).correspondingPropertySymbol!!.owner.findTopLevelDeclaration() this.isPropertyField -> - (this as IrField).correspondingProperty!!.findTopLevelDeclaration() + (this as IrField).correspondingPropertySymbol!!.owner.findTopLevelDeclaration() else -> (this.parent as IrDeclaration).findTopLevelDeclaration() } @@ -247,15 +248,20 @@ internal val IrClass.isFrozen: Boolean // RTTI is used for non-reference type box or Objective-C object wrapper: !this.defaultType.binaryTypeIsReference() || this.isObjCClass() -fun IrConstructorCall.getAnnotationValue() = (getValueArgument(0) as? IrConst)?.value +fun IrConstructorCall.getAnnotationStringValue() = (getValueArgument(0) as? IrConst)?.value -fun IrConstructorCall.getStringValue(name: String): String { +fun IrConstructorCall.getAnnotationStringValue(name: String): String { val parameter = symbol.owner.valueParameters.single { it.name.asString() == name } return (getValueArgument(parameter.index) as IrConst).value } +fun IrConstructorCall.getAnnotationValueOrNull(name: String): T? { + val parameter = symbol.owner.valueParameters.atMostOne { it.name.asString() == name } + return parameter?.let { getValueArgument(it.index)?.let { (it as IrConst).value } } +} + fun IrFunction.externalSymbolOrThrow(): String? { - annotations.findAnnotation(RuntimeNames.symbolNameAnnotation)?.let { return it.getAnnotationValue() } + annotations.findAnnotation(RuntimeNames.symbolNameAnnotation)?.let { return it.getAnnotationStringValue() } if (annotations.hasAnnotation(KonanFqNames.objCMethod)) return null @@ -265,3 +271,5 @@ fun IrFunction.externalSymbolOrThrow(): String? { throw Error("external function ${this.longName} must have @TypedIntrinsic, @SymbolName or @ObjCMethod annotation") } + +val IrFunction.isBuiltInOperator get() = origin == IrBuiltIns.BUILTIN_OPERATOR \ No newline at end of file diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/KonanSharedVariablesManager.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/KonanSharedVariablesManager.kt index 675169334d2..6b60beb2180 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/KonanSharedVariablesManager.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/KonanSharedVariablesManager.kt @@ -8,14 +8,11 @@ package org.jetbrains.kotlin.backend.konan.descriptors import org.jetbrains.kotlin.backend.common.ir.SharedVariablesManager import org.jetbrains.kotlin.backend.konan.KonanBackendContext -import org.jetbrains.kotlin.descriptors.PropertyDescriptor -import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrProperty import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl -import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrGetValue import org.jetbrains.kotlin.ir.expressions.IrSetVariable import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl @@ -39,14 +36,6 @@ internal class KonanSharedVariablesManager(val context: KonanBackendContext) : S return refClass.descriptor.defaultType.replace(listOf(TypeProjectionImpl(elementType))) } - private fun getElementPropertyDescriptor(sharedVariableDescriptor: VariableDescriptor): PropertyDescriptor { - return sharedVariableDescriptor.type.memberScope.getContributedDescriptors() - .filterIsInstance() - .single { - it.name.asString() == "element" - } - } - override fun declareSharedVariable(originalDeclaration: IrVariable): IrVariable { val variableDescriptor = originalDeclaration.descriptor val sharedVariableDescriptor = LocalVariableDescriptor( @@ -76,12 +65,9 @@ internal class KonanSharedVariablesManager(val context: KonanBackendContext) : S override fun defineSharedValue(originalDeclaration: IrVariable, sharedVariableDeclaration: IrVariable): IrStatement { val initializer = originalDeclaration.initializer ?: return sharedVariableDeclaration - val elementPropertyDescriptor = getElementPropertyDescriptor(sharedVariableDeclaration.descriptor) - val sharedVariableInitialization = IrCallImpl(initializer.startOffset, initializer.endOffset, - context.irBuiltIns.unitType, elementProperty.setter!!.symbol, - elementPropertyDescriptor.setter!!) + context.irBuiltIns.unitType, elementProperty.setter!!.symbol) sharedVariableInitialization.dispatchReceiver = IrGetValueImpl(initializer.startOffset, initializer.endOffset, @@ -95,31 +81,23 @@ internal class KonanSharedVariablesManager(val context: KonanBackendContext) : S ) } - override fun getSharedValue(sharedVariableSymbol: IrVariableSymbol, originalGet: IrGetValue): IrExpression { + override fun getSharedValue(sharedVariableSymbol: IrVariableSymbol, originalGet: IrGetValue) = + IrCallImpl(originalGet.startOffset, originalGet.endOffset, + originalGet.type, elementProperty.getter!!.symbol).apply { + dispatchReceiver = IrGetValueImpl( + originalGet.startOffset, originalGet.endOffset, + sharedVariableSymbol.owner.type, sharedVariableSymbol + ) + } - val elementPropertyDescriptor = getElementPropertyDescriptor(sharedVariableSymbol.descriptor) - - return IrCallImpl(originalGet.startOffset, originalGet.endOffset, - originalGet.type, elementProperty.getter!!.symbol, - elementPropertyDescriptor.getter!!).apply { - dispatchReceiver = IrGetValueImpl( - originalGet.startOffset, originalGet.endOffset, - sharedVariableSymbol.owner.type, sharedVariableSymbol - ) - } - } - - override fun setSharedValue(sharedVariableSymbol: IrVariableSymbol, originalSet: IrSetVariable): IrExpression { - val elementPropertyDescriptor = getElementPropertyDescriptor(sharedVariableSymbol.descriptor) - - return IrCallImpl(originalSet.startOffset, originalSet.endOffset, context.irBuiltIns.unitType, - elementProperty.setter!!.symbol, elementPropertyDescriptor.setter!!).apply { - dispatchReceiver = IrGetValueImpl( - originalSet.startOffset, originalSet.endOffset, - sharedVariableSymbol.owner.type, sharedVariableSymbol - ) - putValueArgument(0, originalSet.value) - } - } + override fun setSharedValue(sharedVariableSymbol: IrVariableSymbol, originalSet: IrSetVariable) = + IrCallImpl(originalSet.startOffset, originalSet.endOffset, context.irBuiltIns.unitType, + elementProperty.setter!!.symbol).apply { + dispatchReceiver = IrGetValueImpl( + originalSet.startOffset, originalSet.endOffset, + sharedVariableSymbol.owner.type, sharedVariableSymbol + ) + putValueArgument(0, originalSet.value) + } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/FakeIrUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/FakeIrUtils.kt index d28621347f8..a1af8bb0d90 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/FakeIrUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/FakeIrUtils.kt @@ -10,20 +10,12 @@ import org.jetbrains.kotlin.backend.konan.llvm.llvmSymbolOrigin import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.toKotlinType -import org.jetbrains.kotlin.name.SpecialNames -import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.resolve.descriptorUtil.module +import org.jetbrains.kotlin.ir.util.file // This file contains some IR utilities which actually use descriptors. // TODO: port this code to IR. -internal fun IrFunction.getObjCMethodInfo() = this.descriptor.getObjCMethodInfo() -internal fun IrFunction.getExternalObjCMethodInfo() = this.descriptor.getExternalObjCMethodInfo() -internal fun IrFunction.isObjCClassMethod() = this.descriptor.isObjCClassMethod() - -internal fun IrClass.isObjCMetaClass() = this.descriptor.isObjCMetaClass() - -internal val IrDeclaration.llvmSymbolOrigin get() = this.descriptor.llvmSymbolOrigin +internal val IrDeclaration.llvmSymbolOrigin get() = this.file.packageFragmentDescriptor.llvmSymbolOrigin internal fun IrType.isObjCObjectType() = this.toKotlinType().isObjCObjectType() diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index c95b010c36b..7cc0b037e0f 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -60,6 +60,8 @@ internal class KonanSymbols( val nativePtrType = nativePtr.typeWith(arguments = emptyList()) val nonNullNativePtr = symbolTable.referenceClass(context.nonNullNativePtr) + val immutableBlobOf = symbolTable.referenceSimpleFunction(context.immutableBlobOf) + private fun unsignedClass(unsignedType: UnsignedType): IrClassSymbol = classById(unsignedType.classId) val uByte = unsignedClass(UnsignedType.UBYTE) @@ -130,6 +132,8 @@ internal class KonanSymbols( val interopCValueRead = symbolTable.referenceSimpleFunction(context.interopBuiltIns.cValueRead) val interopAllocType = symbolTable.referenceSimpleFunction(context.interopBuiltIns.allocType) + val interopTypeOf = symbolTable.referenceSimpleFunction(context.interopBuiltIns.typeOf) + val interopCPointerGetRawValue = symbolTable.referenceSimpleFunction(context.interopBuiltIns.cPointerGetRawValue) val interopAllocObjCObject = symbolTable.referenceSimpleFunction(context.interopBuiltIns.allocObjCObject) @@ -168,6 +172,12 @@ internal class KonanSymbols( val interopObjCObjectRawValueGetter = symbolTable.referenceSimpleFunction(context.interopBuiltIns.objCObjectRawPtr) + val interopNativePointedRawPtrGetter = + symbolTable.referenceSimpleFunction(context.interopBuiltIns.nativePointedRawPtrGetter) + + val interopCPointerRawValue = + symbolTable.referenceProperty(context.interopBuiltIns.cPointerRawValue) + val interopInterpretObjCPointer = symbolTable.referenceSimpleFunction(context.interopBuiltIns.interpretObjCPointer) @@ -201,7 +211,11 @@ internal class KonanSymbols( ) as ClassDescriptor ) - val executeImpl = symbolTable.referenceSimpleFunction(context.interopBuiltIns.executeImplFunction) + val executeImpl = symbolTable.referenceSimpleFunction( + builtIns.builtInsModule.getPackage(FqName("kotlin.native.concurrent")).memberScope + .getContributedFunctions(Name.identifier("executeImpl"), NoLookupLocation.FROM_BACKEND) + .single() + ) val areEqualByValue = context.getKonanInternalFunctions("areEqualByValue").map { symbolTable.referenceSimpleFunction(it) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt index 9469fc41f49..2f5534ed5ad 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/BinaryInterface.kt @@ -9,11 +9,11 @@ import llvm.LLVMTypeRef import org.jetbrains.kotlin.backend.common.serialization.KotlinManglerImpl import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.descriptors.externalSymbolOrThrow -import org.jetbrains.kotlin.backend.konan.descriptors.getAnnotationValue +import org.jetbrains.kotlin.backend.konan.descriptors.getAnnotationStringValue import org.jetbrains.kotlin.backend.konan.descriptors.isAbstract import org.jetbrains.kotlin.backend.konan.ir.allParameters -import org.jetbrains.kotlin.backend.konan.ir.getObjCMethodInfo -import org.jetbrains.kotlin.backend.konan.ir.isObjCClassMethod +import org.jetbrains.kotlin.backend.konan.getObjCMethodInfo +import org.jetbrains.kotlin.backend.konan.isObjCClassMethod import org.jetbrains.kotlin.backend.konan.ir.isUnit import org.jetbrains.kotlin.backend.konan.llvm.KonanMangler.isExported import org.jetbrains.kotlin.ir.declarations.* @@ -89,7 +89,7 @@ object KonanMangler : KotlinManglerImpl() { append(it.selector) if (this@platformSpecificFunctionName is IrConstructor && this@platformSpecificFunctionName.isObjCConstructor) append("#Constructor") - if ((this@platformSpecificFunctionName as? IrSimpleFunction)?.correspondingProperty != null) { + if ((this@platformSpecificFunctionName as? IrSimpleFunction)?.correspondingPropertySymbol != null) { append("#Accessor") } } @@ -110,7 +110,7 @@ object KonanMangler : KotlinManglerImpl() { } this.annotations.findAnnotation(RuntimeNames.exportForCppRuntime)?.let { - val name = it.getAnnotationValue() ?: this.name.asString() + val name = it.getAnnotationStringValue() ?: this.name.asString() return name // no wrapping currently required } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt index b260f653efe..6d220697bfa 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IntrinsicGenerator.kt @@ -3,7 +3,7 @@ package org.jetbrains.kotlin.backend.konan.llvm import kotlinx.cinterop.cValuesOf import llvm.* import org.jetbrains.kotlin.backend.konan.RuntimeNames -import org.jetbrains.kotlin.backend.konan.descriptors.getAnnotationValue +import org.jetbrains.kotlin.backend.konan.descriptors.getAnnotationStringValue import org.jetbrains.kotlin.backend.konan.descriptors.isTypedIntrinsic import org.jetbrains.kotlin.backend.konan.llvm.objc.genObjCSelector import org.jetbrains.kotlin.backend.konan.reportCompilationError @@ -107,7 +107,7 @@ internal interface IntrinsicGeneratorEnvironment { fun evaluateCall(function: IrFunction, args: List, resultLifetime: Lifetime, superClass: IrClass? = null): LLVMValueRef - fun evaluateExplicitArgs(expression: IrMemberAccessExpression): List + fun evaluateExplicitArgs(expression: IrFunctionAccessExpression): List fun evaluateExpression(value: IrExpression): LLVMValueRef } @@ -118,7 +118,7 @@ internal fun tryGetIntrinsicType(callSite: IrFunctionAccessExpression): Intrinsi private fun getIntrinsicType(callSite: IrFunctionAccessExpression): IntrinsicType { val function = callSite.symbol.owner val annotation = function.annotations.findAnnotation(RuntimeNames.typedIntrinsicAnnotation)!! - val value = annotation.getAnnotationValue()!! + val value = annotation.getAnnotationStringValue()!! return IntrinsicType.valueOf(value) } @@ -452,8 +452,7 @@ internal class IntrinsicGenerator(private val environment: IntrinsicGeneratorEnv private val kImmOne = LLVMConstInt(int32Type, 1, 1)!! private fun FunctionGenerationContext.emitGetObjCClass(callSite: IrCall): LLVMValueRef { - val descriptor = callSite.descriptor.original - val typeArgument = callSite.getTypeArgument(descriptor.typeParameters.single()) + val typeArgument = callSite.getTypeArgument(0) return getObjCClass(typeArgument!!.getClass()!!, environment.exceptionHandler) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index d0c5714d3c5..c968715201d 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.backend.konan.llvm import kotlinx.cinterop.* import llvm.* -import org.jetbrains.kotlin.backend.common.descriptors.allParameters import org.jetbrains.kotlin.backend.common.ir.ir2string import org.jetbrains.kotlin.backend.common.lower.inline.InlinerExpressionLocationHint import org.jetbrains.kotlin.backend.konan.* @@ -208,7 +207,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map, resultLifetime: Lifetime, superClass: IrClass?) = evaluateSimpleFunctionCall(function, args, resultLifetime, superClass) - override fun evaluateExplicitArgs(expression: IrMemberAccessExpression): List = + override fun evaluateExplicitArgs(expression: IrFunctionAccessExpression): List = this@CodeGeneratorVisitor.evaluateExplicitArgs(expression) override fun evaluateExpression(value: IrExpression): LLVMValueRef = @@ -1481,17 +1480,17 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map) } else { if (context.config.threadsAreAllowed && value.symbol.owner.isMainOnlyNonPrimitive) { functionGenerationContext.checkMainThread(currentCodeContext.exceptionHandler) } val ptr = context.llvmDeclarations.forStaticField(value.symbol.owner).storage - functionGenerationContext.loadSlot(ptr, value.descriptor.isVar()) + functionGenerationContext.loadSlot(ptr, !value.symbol.owner.isFinal) } } } @@ -1941,12 +1940,12 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map { - val evaluatedArgs = expression.getArguments().map { (param, argExpr) -> + private fun evaluateExplicitArgs(expression: IrFunctionAccessExpression): List { + val evaluatedArgs = expression.getArgumentsWithIr().map { (param, argExpr) -> param to evaluateExpression(argExpr) }.toMap() - val allValueParameters = expression.descriptor.allParameters + val allValueParameters = expression.symbol.owner.allParameters return allValueParameters.dropWhile { it !in evaluatedArgs }.map { evaluatedArgs[it]!! @@ -2051,7 +2050,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map intrinsicGenerator.evaluateCall(callee, args) - function.symbol in context.irBuiltIns.irBuiltInsSymbols -> evaluateOperatorCall(callee, argsWithContinuationIfNeeded) + function.isBuiltInOperator -> evaluateOperatorCall(callee, argsWithContinuationIfNeeded) else -> evaluateSimpleFunctionCall(function, argsWithContinuationIfNeeded, resultLifetime, callee.superQualifierSymbol?.owner) } } @@ -2133,7 +2132,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map createKProperty(expression, this) // Has receiver. - 2 -> error("Callable reference to properties with two receivers is not allowed: ${expression.descriptor}") + 2 -> error("Callable reference to properties with two receivers is not allowed: ${expression.symbol.owner.name}") else -> { // Cache KProperties with no arguments. val field = kProperties.getOrPut(expression.symbol.owner) { @@ -195,7 +190,6 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa else irTemporary(value = it, nameHint = "\$extensionReceiver${tempIndex++}") } - val propertyDescriptor = expression.descriptor val returnType = expression.getter?.owner?.returnType ?: expression.field!!.owner.type val getterCallableReference = expression.getter?.owner?.let { getter -> @@ -216,7 +210,6 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa endOffset = endOffset, type = getterKFunctionType, symbol = expression.getter!!, - descriptor = getter.descriptor, typeArgumentsCount = getter.typeParameters.size, valueArgumentsCount = getter.valueParameters.size ).apply { @@ -239,7 +232,6 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa endOffset = endOffset, type = setterKFunctionType, symbol = expression.setter!!, - descriptor = setter.descriptor, typeArgumentsCount = setter.typeParameters.size, valueArgumentsCount = setter.valueParameters.size ).apply { @@ -257,7 +249,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa isLocal = false, isMutable = setterCallableReference != null) val initializer = irCall(symbol.owner, constructorTypeArguments).apply { - putValueArgument(0, irString(propertyDescriptor.name.asString())) + putValueArgument(0, irString(expression.symbol.owner.name.asString())) putValueArgument(1, with(kTypeGenerator) { irKType(returnType) }) if (getterCallableReference != null) putValueArgument(2, getterCallableReference) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt index 34507334a0e..a1d9e307837 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/EnumClassLowering.kt @@ -127,7 +127,7 @@ internal class EnumUsageLowering(val context: Context) val ordinal = loweredEnum.entriesMap[name]!! return IrCallImpl( startOffset, endOffset, enumClass.defaultType, - loweredEnum.itemGetterSymbol.owner.symbol, loweredEnum.itemGetterSymbol.descriptor, + loweredEnum.itemGetterSymbol.owner.symbol, typeArgumentsCount = 0 ).apply { dispatchReceiver = IrCallImpl(startOffset, endOffset, loweredEnum.valuesGetter.returnType, loweredEnum.valuesGetter.symbol) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt index 6add1e754e1..bb29eaa07d4 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt @@ -134,7 +134,7 @@ internal class ExpectToActualDefaultValueCopier(private val irModule: IrModuleFr symbol.descriptor.isExpect -> symbol.owner.findActualForExpected().symbol symbol.descriptor.propertyIfAccessor.isExpect -> { - val property = symbol.owner.correspondingProperty!! + val property = symbol.owner.correspondingPropertySymbol!!.owner val actualPropertyDescriptor = property.descriptor.findActualForExpect() val accessorDescriptor = when (symbol.owner) { property.getter -> actualPropertyDescriptor.getter!! 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 9bd6688689f..c3bddfa331d 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 @@ -18,12 +18,12 @@ import org.jetbrains.kotlin.backend.common.push import org.jetbrains.kotlin.backend.konan.* import org.jetbrains.kotlin.backend.konan.cgen.* import org.jetbrains.kotlin.backend.konan.descriptors.allOverriddenFunctions -import org.jetbrains.kotlin.backend.konan.descriptors.isInterface import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.backend.konan.ir.companionObject import org.jetbrains.kotlin.backend.konan.llvm.IntrinsicType import org.jetbrains.kotlin.backend.konan.llvm.tryGetIntrinsicType +import org.jetbrains.kotlin.backend.konan.serialization.resolveFakeOverrideMaybeAbstract import org.jetbrains.kotlin.builtins.UnsignedTypes import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.IrElement @@ -47,7 +47,6 @@ import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.OverridingUtil import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe internal abstract class BaseInteropIrTransformer(private val context: Context) : IrBuildingTransformer(context) { @@ -569,7 +568,6 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo endOffset, context.irBuiltIns.unitType, superConstructor, - superConstructor.descriptor, 0 ) @@ -645,11 +643,9 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo override fun visitCall(expression: IrCall): IrExpression { expression.transformChildrenVoid() - val descriptor = expression.descriptor.original - val callee = expression.symbol.owner - descriptor.getObjCFactoryInitMethodInfo()?.let { initMethodInfo -> + callee.getObjCFactoryInitMethodInfo()?.let { initMethodInfo -> val arguments = (0 until expression.valueArgumentsCount) .map { index -> expression.getValueArgument(index) } @@ -659,7 +655,7 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo } } - descriptor.getExternalObjCMethodInfo()?.let { methodInfo -> + callee.getExternalObjCMethodInfo()?.let { methodInfo -> val isInteropStubsFile = currentFile.annotations.hasAnnotation(FqName("kotlinx.cinterop.InteropStubs")) @@ -672,14 +668,14 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo val arguments = callee.valueParameters.map { expression.getValueArgument(it.index) } assert(expression.dispatchReceiver == null || expression.extensionReceiver == null) - if (expression.superQualifier?.isObjCMetaClass() == true) { + if (expression.superQualifierSymbol?.owner?.isObjCMetaClass() == true) { context.reportCompilationError( "Super calls to Objective-C meta classes are not supported yet", currentFile, expression ) } - if (expression.superQualifier?.isInterface == true) { + if (expression.superQualifierSymbol?.owner?.isInterface == true) { context.reportCompilationError( "Super calls to Objective-C protocols are not allowed", currentFile, expression @@ -698,8 +694,8 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo } } - return when (descriptor) { - context.interopBuiltIns.typeOf -> { + return when (callee.symbol) { + symbols.interopTypeOf -> { val typeArgument = expression.getSingleTypeArgument() val classSymbol = typeArgument.classifierOrNull as? IrClassSymbol @@ -839,11 +835,10 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi expression.transformChildrenVoid(this) builder.at(expression) - val descriptor = expression.descriptor.original val function = expression.symbol.owner - if (descriptor == interop.nativePointedRawPtrGetter || - OverridingUtil.overrides(descriptor, interop.nativePointedRawPtrGetter, false)) { + if ((function as? IrSimpleFunction)?.resolveFakeOverrideMaybeAbstract()?.symbol + == symbols.interopNativePointedRawPtrGetter) { // Replace by the intrinsic call to be handled by code generator: return builder.irCall(symbols.interopNativePointedGetRawPointer).apply { @@ -884,7 +879,7 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi if (irCallableReference == null || irCallableReference.getArguments().isNotEmpty() || irCallableReference.symbol !is IrSimpleFunctionSymbol) { context.reportCompilationError( - "${descriptor.fqNameSafe} must take an unbound, non-capturing function or lambda", + "${function.fqNameForIrSerialization} must take an unbound, non-capturing function or lambda", irFile, expression ) // TODO: should probably be reported during analysis. @@ -894,8 +889,8 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi val target = targetSymbol.owner val signatureTypes = target.allParameters.map { it.type } + target.returnType - descriptor.typeParameters.forEachIndexed { index, typeParameterDescriptor -> - val typeArgument = expression.getTypeArgument(typeParameterDescriptor)!!.toKotlinType() + function.typeParameters.indices.forEach { index -> + val typeArgument = expression.getTypeArgument(index)!!.toKotlinType() val signatureType = signatureTypes[index].toKotlinType() if (typeArgument.constructor != signatureType.constructor || typeArgument.isMarkedNullable != signatureType.isMarkedNullable) { @@ -1020,17 +1015,16 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi if (irCallableReference == null || irCallableReference.getArguments().isNotEmpty()) { context.reportCompilationError( - "${descriptor.fqNameSafe} must take an unbound, non-capturing function or lambda", + "${function.fqNameForIrSerialization} must take an unbound, non-capturing function or lambda", irFile, expression ) } val targetSymbol = irCallableReference.symbol - val target = targetSymbol.descriptor val jobPointer = IrFunctionReferenceImpl( builder.startOffset, builder.endOffset, symbols.executeImpl.owner.valueParameters[3].type, - targetSymbol, target, + targetSymbol, typeArgumentsCount = 0) builder.irCall(symbols.executeImpl).apply { @@ -1043,8 +1037,8 @@ private class InteropTransformer(val context: Context, override val irFile: IrFi else -> expression } } - return when (descriptor) { - interop.cPointerRawValue.getter -> + return when (function) { + symbols.interopCPointerRawValue.owner.getter -> // Replace by the intrinsic call to be handled by code generator: builder.irCall(symbols.interopCPointerGetRawValue).apply { extensionReceiver = expression.dispatchReceiver diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt index dc9c6abe01a..93e3563d79b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.konan.Context import org.jetbrains.kotlin.backend.konan.error -import org.jetbrains.kotlin.backend.konan.ir.typeWithoutArguments import org.jetbrains.kotlin.backend.konan.reportCompilationError import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.IrFile @@ -74,11 +73,11 @@ internal class PostInlineLowering(val context: Context) : FileLoweringPass { // Function inlining is changing function symbol at callsite // and unbound symbol replacement is happening later. // So we compare descriptors for now. - if (expression.descriptor == context.immutableBlobOf) { + if (expression.symbol == symbols.immutableBlobOf) { // Convert arguments of the binary blob to special IrConst structure, so that // vararg lowering will not affect it. val args = expression.getValueArgument(0) as? IrVararg - if (args == null) throw Error("varargs shall not be lowered yet") + ?: throw Error("varargs shall not be lowered yet") if (args.elements.any { it is IrSpreadElement }) { context.reportCompilationError("no spread elements allowed here", irFile, args) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt index 0407008367f..86d131a6bbd 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt @@ -106,7 +106,6 @@ internal class TestProcessor (val context: Context) { it.function.endOffset, registerTestCase.valueParameters[1].type, it.function.symbol, - it.function.descriptor, typeArgumentsCount = 0, valueArgumentsCount = 0)) putValueArgument(2, irBoolean(it.ignored)) @@ -127,7 +126,6 @@ internal class TestProcessor (val context: Context) { it.function.endOffset, registerFunction.valueParameters[1].type, it.function.symbol, - it.function.descriptor, typeArgumentsCount = 0, valueArgumentsCount = 0)) } 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 38c54b6ef3a..3bb0d54a6c8 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 @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl import org.jetbrains.kotlin.ir.symbols.IrClassSymbol @@ -65,12 +64,13 @@ internal class VarargInjectionLowering constructor(val context: KonanBackendCont val transformer = this private fun replaceEmptyParameterWithEmptyArray(expression: IrFunctionAccessExpression) { - log { "call of: ${expression.descriptor}" } + val callee = expression.symbol.owner + log { "call of: ${callee.fqNameForIrSerialization}" } context.createIrBuilder(owner, expression.startOffset, expression.endOffset).apply { - expression.descriptor.valueParameters.forEach { - log { "varargElementType: ${it.varargElementType} expr: ${ir2string(expression.getValueArgument(it))}" } + callee.valueParameters.forEach { + log { "varargElementType: ${it.varargElementType} expr: ${ir2string(expression.getValueArgument(it.index))}" } } - expression.symbol.owner.valueParameters + callee.valueParameters .filter { it.varargElementType != null && expression.getValueArgument(it.index) == null } .forEach { expression.putValueArgument( diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt index e2be5dd6600..87876e18477 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DFGBuilder.kt @@ -644,7 +644,7 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag error("Constructor call should be done with IrConstructorCall") } else { callee as IrSimpleFunction - if (callee.isOverridable && value.superQualifier == null) { + if (callee.isOverridable && value.superQualifierSymbol == null) { val owner = callee.parentAsClass val actualReceiverType = value.dispatchReceiver!!.type val actualReceiverClassifier = actualReceiverType.classifierOrFail diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt index 76ff452cced..111f1c87228 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/DataFlowIR.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.konan.descriptors.isAbstract import org.jetbrains.kotlin.backend.konan.descriptors.target import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.backend.konan.llvm.* -import org.jetbrains.kotlin.backend.konan.llvm.KonanMangler.functionName import org.jetbrains.kotlin.backend.konan.llvm.KonanMangler.symbolName import org.jetbrains.kotlin.backend.konan.lower.DECLARATION_ORIGIN_BRIDGE_METHOD import org.jetbrains.kotlin.backend.konan.lower.bridgeTarget @@ -30,8 +29,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.constants.ConstantValue -import org.jetbrains.kotlin.resolve.constants.IntValue +import org.jetbrains.kotlin.backend.konan.descriptors.isBuiltInOperator internal object DataFlowIR { @@ -599,7 +597,7 @@ internal object DataFlowIR { attributes = attributes or FunctionAttributes.EXPLICITLY_EXPORTED } val symbol = when { - it.isExternal || (it.symbol in context.irBuiltIns.irBuiltInsSymbols) -> { + it.isExternal || it.isBuiltInOperator -> { val escapesAnnotation = it.annotations.findAnnotation(FQ_NAME_ESCAPES) val pointsToAnnotation = it.annotations.findAnnotation(FQ_NAME_POINTS_TO) @Suppress("UNCHECKED_CAST") 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 2c17b5bcee7..85bef0b47df 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 @@ -13,8 +13,6 @@ import org.jetbrains.kotlin.backend.common.push import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.lower.irBlock import org.jetbrains.kotlin.backend.konan.* -import org.jetbrains.kotlin.backend.konan.descriptors.isInterface -import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.declarations.* @@ -1312,7 +1310,6 @@ internal object Devirtualization { callSite.startOffset, callSite.endOffset, actualType, actualCallee.symbol, - actualCallee.descriptor, actualCallee.typeParameters.size, actualCallee.valueParameters.size, callSite.origin, @@ -1369,8 +1366,8 @@ internal object Devirtualization { || possibleCallees.any { it.receiverType is DataFlowIR.Type.External }) return expression - val descriptor = expression.descriptor - val owner = (descriptor.containingDeclaration as ClassDescriptor) + val callee = expression.symbol.owner + val owner = callee.parentAsClass // TODO: Think how to evaluate different unfold factors (in terms of both execution speed and code size). val classMaxUnfoldFactor = 3 val interfaceMaxUnfoldFactor = 3 @@ -1383,7 +1380,7 @@ internal object Devirtualization { val startOffset = expression.startOffset val endOffset = expression.endOffset val function = expression.symbol.owner - val type = if (descriptor.isSuspend) + val type = if (callee.isSuspend) context.irBuiltIns.anyNType else function.returnType val irBuilder = context.createIrBuilder(currentScope!!.scope.scopeOwnerSymbol, startOffset, endOffset) @@ -1492,7 +1489,7 @@ internal object Devirtualization { typeOperand, typeOperandClassifier, expression) } with (coercion) { - return IrCallImpl(startOffset, endOffset, type, symbol, descriptor, typeArgumentsCount, origin).apply { + return IrCallImpl(startOffset, endOffset, type, symbol, typeArgumentsCount, origin).apply { putValueArgument(0, castedExpression) } } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/IrSerializationUtil.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/IrSerializationUtil.kt index 2f81a1d4fd1..f7ee80711c0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/IrSerializationUtil.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/IrSerializationUtil.kt @@ -30,9 +30,11 @@ import org.jetbrains.kotlin.resolve.OverridingUtil */ internal fun IrSimpleFunction.resolveFakeOverrideMaybeAbstract() = this.resolveFakeOverride(allowAbstract = true) -internal fun IrProperty.resolveFakeOverrideMaybeAbstract() = this.getter!!.resolveFakeOverrideMaybeAbstract().correspondingProperty!! +internal fun IrProperty.resolveFakeOverrideMaybeAbstract() = + this.getter!!.resolveFakeOverrideMaybeAbstract().correspondingPropertySymbol!!.owner -internal fun IrField.resolveFakeOverrideMaybeAbstract() = this.correspondingProperty!!.getter!!.resolveFakeOverrideMaybeAbstract().correspondingProperty!!.backingField +internal fun IrField.resolveFakeOverrideMaybeAbstract() = + this.correspondingPropertySymbol!!.owner.resolveFakeOverrideMaybeAbstract().backingField /** * Implementation of given method. diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDeclarationTable.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDeclarationTable.kt index 38c5bc26074..49a308a04ac 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDeclarationTable.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanDeclarationTable.kt @@ -8,6 +8,6 @@ import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns class KonanGlobalDeclarationTable(builtIns: IrBuiltIns) : GlobalDeclarationTable(KonanMangler) { init { - loadKnownBuiltins(builtIns, 0) + loadKnownBuiltins(builtIns) } } \ No newline at end of file diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt index 48d56200578..d37001a1c94 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt @@ -33,7 +33,7 @@ class KonanIrLinker( symbolTable: SymbolTable, forwardModuleDescriptor: ModuleDescriptor?, exportedDependencies: List -) : KotlinIrLinker(logger, builtIns, symbolTable, exportedDependencies, forwardModuleDescriptor, 0L), +) : KotlinIrLinker(logger, builtIns, symbolTable, exportedDependencies, forwardModuleDescriptor, KonanMangler), DescriptorUniqIdAware by DeserializedDescriptorUniqIdAware { override val descriptorReferenceDeserializer = diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt index 00639bc7266..0265cf136bf 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/ir/util/IrUtils2.kt @@ -254,7 +254,7 @@ fun IrBuilderWithScope.irCall(irFunction: IrFunction, typeArguments: List): IrCall = IrCallImpl( startOffset, endOffset, irFunction.substitutedReturnType(typeArguments), - irFunction.symbol, irFunction.descriptor.substitute(typeArguments), typeArguments.size + irFunction.symbol, typeArguments.size ).apply { typeArguments.forEachIndexed { index, irType -> this.putTypeArgument(index, irType) diff --git a/gradle.properties b/gradle.properties index 839869eb181..faa3f242d5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,12 +18,12 @@ buildKotlinVersion=1.3.70-dev-1070 buildKotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Compiler),number:1.3.70-dev-1070,branch:default:any,pinned:true/artifacts/content/maven remoteRoot=konan_tests -kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Compiler),number:1.3.70-dev-1438,branch:default:any,pinned:true/artifacts/content/maven -kotlinVersion=1.3.70-dev-1438 -kotlinStdlibRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Compiler),number:1.3.70-dev-1438,branch:default:any,pinned:true/artifacts/content/maven -kotlinStdlibVersion=1.3.70-dev-1438 -kotlinStdlibTestsVersion=1.3.70-dev-1438 -testKotlinCompilerVersion=1.3.70-dev-1438 +kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Compiler),number:1.3.70-dev-1526,branch:default:any,pinned:true/artifacts/content/maven +kotlinVersion=1.3.70-dev-1526 +kotlinStdlibRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_KotlinPublic_Compiler),number:1.3.70-dev-1526,branch:default:any,pinned:true/artifacts/content/maven +kotlinStdlibVersion=1.3.70-dev-1526 +kotlinStdlibTestsVersion=1.3.70-dev-1526 +testKotlinCompilerVersion=1.3.70-dev-1526 konanVersion=1.3.70 # A version of Xcode required to build the Kotlin/Native compiler. diff --git a/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt b/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt index ddd46a22121..42fe58cf42e 100644 --- a/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt +++ b/shared/src/library/kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt @@ -80,7 +80,8 @@ internal class KonanLibraryProperResolver( distributionKlib, localKonanDir, skipCurrentDir, - logger + logger, + emptyList() ), SearchPathResolverWithTarget { override fun libraryBuilder(file: File, isDefault: Boolean) = createKonanLibrary(file, target, isDefault)