Skip to content

Commit ed897ff

Browse files
homurollSpace Team
authored andcommitted
[IR][K/N] Refactored out descriptors from interop lowering
1 parent 5ed58ce commit ed897ff

File tree

2 files changed

+21
-29
lines changed
  • compiler/ir/ir.objcinterop/src/org/jetbrains/kotlin/ir/objcinterop
  • kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower

2 files changed

+21
-29
lines changed

compiler/ir/ir.objcinterop/src/org/jetbrains/kotlin/ir/objcinterop/ObjCInterop.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,13 @@ fun IrFunction.getObjCFactoryInitMethodInfo(): ObjCMethodInfo? {
248248
return objCMethodInfo(factoryAnnotation)
249249
}
250250

251-
fun inferObjCSelector(descriptor: FunctionDescriptor): String = if (descriptor.valueParameters.isEmpty()) {
252-
descriptor.name.asString()
251+
fun inferObjCSelector(function: IrSimpleFunction): String = if (function.valueParameters.isEmpty()) {
252+
function.name.asString()
253253
} else {
254254
buildString {
255-
append(descriptor.name)
255+
append(function.name)
256256
append(':')
257-
descriptor.valueParameters.drop(1).forEach {
257+
function.valueParameters.drop(1).forEach {
258258
append(it.name)
259259
append(':')
260260
}

kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ import org.jetbrains.kotlin.backend.konan.ir.*
1414
import org.jetbrains.kotlin.backend.konan.llvm.IntrinsicType
1515
import org.jetbrains.kotlin.backend.konan.llvm.tryGetIntrinsicType
1616
import org.jetbrains.kotlin.backend.konan.serialization.isFromCInteropLibrary
17-
import org.jetbrains.kotlin.descriptors.ClassDescriptor
1817
import org.jetbrains.kotlin.descriptors.ClassKind
1918
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
2019
import org.jetbrains.kotlin.descriptors.Modality
2120
import org.jetbrains.kotlin.ir.IrElement
2221
import org.jetbrains.kotlin.ir.IrStatement
23-
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
2422
import org.jetbrains.kotlin.ir.builders.*
2523
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
2624
import org.jetbrains.kotlin.ir.declarations.*
@@ -338,7 +336,6 @@ private class InteropLoweringPart1(val generationState: NativeGenerationState) :
338336
}
339337
}
340338

341-
@OptIn(ObsoleteDescriptorBasedAPI::class)
342339
private class InteropTransformerPart1(
343340
generationState: NativeGenerationState,
344341
irFile: IrFile?,
@@ -471,9 +468,9 @@ private class InteropTransformerPart1(
471468
}
472469

473470
private fun IrConstructor.overridesConstructor(other: IrConstructor): Boolean {
474-
return this.descriptor.valueParameters.size == other.descriptor.valueParameters.size &&
475-
this.descriptor.valueParameters.all {
476-
val otherParameter = other.descriptor.valueParameters[it.index]
471+
return this.valueParameters.size == other.valueParameters.size &&
472+
this.valueParameters.all {
473+
val otherParameter = other.valueParameters[it.indexInOldValueParameters]
477474
it.name == otherParameter.name && it.type == otherParameter.type
478475
}
479476
}
@@ -483,13 +480,14 @@ private class InteropTransformerPart1(
483480
require(function.valueParameters.all { it.type.isObjCObjectType() }) { renderCompilerError(function) }
484481
require(function.returnType.isUnit()) { renderCompilerError(function) }
485482

486-
return generateFunctionImp(inferObjCSelector(function.descriptor), function)
483+
return generateFunctionImp(inferObjCSelector(function), function)
487484
}
488485

489486
private fun generateOutletSetterImp(property: IrProperty): IrSimpleFunction {
490487
require(property.isVar) { renderCompilerError(property) }
491-
require(property.getter?.extensionReceiverParameter == null) { renderCompilerError(property) }
492-
require(property.descriptor.type.isObjCObjectType()) { renderCompilerError(property) }
488+
val getter = property.getter!!
489+
require(getter.extensionReceiverParameter == null) { renderCompilerError(property) }
490+
require(getter.returnType.isObjCObjectType()) { renderCompilerError(property) }
493491

494492
val name = property.name.asString()
495493
val selector = "set${name.replaceFirstChar(Char::uppercaseChar)}:"
@@ -616,11 +614,11 @@ private class InteropTransformerPart1(
616614
require(irClass.companionObject()?.getSuperClassNotAny()?.hasFields() != true) { renderCompilerError(irClass) }
617615

618616
var hasObjCClassSupertype = false
619-
irClass.descriptor.defaultType.constructor.supertypes.forEach {
620-
val descriptor = it.constructor.declarationDescriptor as ClassDescriptor
621-
require(descriptor.isObjCClass()) { renderCompilerError(irClass) }
617+
irClass.superTypes.forEach {
618+
val superClass = it.classOrNull?.owner
619+
require(superClass != null && superClass.isObjCClass()) { renderCompilerError(irClass) }
622620

623-
if (descriptor.kind == ClassKind.CLASS) {
621+
if (superClass.kind == ClassKind.CLASS) {
624622
hasObjCClassSupertype = true
625623
}
626624
}
@@ -685,16 +683,11 @@ private class InteropTransformerPart1(
685683
)
686684

687685
val superConstructor = delegatingCallConstructingClass
688-
.constructors.single { it.valueParameters.size == 0 }.symbol
686+
.constructors.single { it.valueParameters.size == 0 }
689687

690688
return builder.irBlock(expression) {
691689
// Required for the IR to be valid, will be ignored in codegen:
692-
+IrDelegatingConstructorCallImpl.fromSymbolDescriptor(
693-
startOffset,
694-
endOffset,
695-
context.irBuiltIns.unitType,
696-
superConstructor
697-
)
690+
+irDelegatingConstructorCall(superConstructor)
698691
+irCall(symbols.interopObjCObjectSuperInitCheck).apply {
699692
extensionReceiver = irGet(constructedClass.thisReceiver!!)
700693
putValueArgument(0, initCall)
@@ -902,7 +895,6 @@ private class InteropLoweringPart2(val generationState: NativeGenerationState) :
902895
}
903896
}
904897

905-
@OptIn(ObsoleteDescriptorBasedAPI::class)
906898
private class InteropTransformerPart2(
907899
generationState: NativeGenerationState,
908900
irFile: IrFile?,
@@ -1106,11 +1098,11 @@ private class InteropTransformerPart2(
11061098
val signatureTypes = target.allParameters.map { it.type } + target.returnType
11071099

11081100
expression.symbol.owner.typeParameters.indices.forEach { index ->
1109-
val typeArgument = expression.typeArguments[index]!!.toKotlinType()
1110-
val signatureType = signatureTypes[index].toKotlinType()
1101+
val typeArgument = expression.typeArguments[index]!!
1102+
val signatureType = signatureTypes[index]
11111103

1112-
require(typeArgument.constructor == signatureType.constructor &&
1113-
typeArgument.isMarkedNullable == signatureType.isMarkedNullable) { renderCompilerError(expression) }
1104+
require(typeArgument.erasedUpperBound == signatureType.erasedUpperBound &&
1105+
typeArgument.isNullable() == signatureType.isNullable()) { renderCompilerError(expression) }
11141106
}
11151107

11161108
builder.at(expression)

0 commit comments

Comments
 (0)