[K/N] Remove some descriptor usages from lowerings

This commit is contained in:
Pavel Kunyavskiy
2021-10-21 15:34:45 +03:00
committed by Space
parent 55ac3e78d2
commit 4b49356a56
10 changed files with 28 additions and 29 deletions
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.backend.common
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
@@ -37,7 +36,6 @@ import java.lang.IllegalStateException
* TODO: consider making this visitor non-recursive to make it more general.
*/
internal abstract class AbstractValueUsageTransformer(
val builtIns: KotlinBuiltIns,
val symbols: KonanSymbols,
val irBuiltIns: IrBuiltIns
): IrElementTransformerVoid() {
@@ -49,7 +49,6 @@ internal class Autoboxing(val context: Context) : FileLoweringPass {
}
private class AutoboxingTransformer(val context: Context) : AbstractValueUsageTransformer(
context.builtIns,
context.ir.symbols,
context.irBuiltIns
) {
@@ -112,7 +112,7 @@ internal class WorkersBridgesBuilding(val context: Context) : DeclarationContain
overriddenFunction = overriddenJobDescriptor,
targetSymbol = jobFunction.symbol)
bridges += bridge
expression.putValueArgument(3, IrFunctionReferenceImpl.fromSymbolDescriptor(
expression.putValueArgument(3, IrFunctionReferenceImpl.fromSymbolOwner(
startOffset = job.startOffset,
endOffset = job.endOffset,
type = job.type,
@@ -183,7 +183,7 @@ internal class BridgesBuilding(val context: Context) : ClassLoweringPass {
internal class DECLARATION_ORIGIN_BRIDGE_METHOD(val bridgeTarget: IrFunction) : IrDeclarationOrigin {
override fun toString(): String {
return "BRIDGE_METHOD(target=${bridgeTarget.descriptor})"
return "BRIDGE_METHOD(target=${bridgeTarget.symbol})"
}
}
@@ -241,7 +241,7 @@ private fun Context.buildBridge(startOffset: Int, endOffset: Int,
val typeSafeBarrierDescription = BuiltinMethodsWithSpecialGenericSignature.getDefaultValueForOverriddenBuiltinFunction(overriddenFunction.overriddenFunction.descriptor)
typeSafeBarrierDescription?.let { buildTypeSafeBarrier(bridge, overriddenFunction.function, it) }
val delegatingCall = IrCallImpl.fromSymbolDescriptor(
val delegatingCall = IrCallImpl.fromSymbolOwner(
startOffset,
endOffset,
targetSymbol.owner.returnType,
@@ -56,7 +56,7 @@ internal class BuiltinOperatorLowering(val context: Context) : FileLoweringPass,
irBuiltins.checkNotNullSymbol -> lowerCheckNotNull(expression)
irBuiltins.noWhenBranchMatchedExceptionSymbol -> IrCallImpl.fromSymbolDescriptor(
irBuiltins.noWhenBranchMatchedExceptionSymbol -> IrCallImpl.fromSymbolOwner(
expression.startOffset, expression.endOffset,
context.ir.symbols.throwNoWhenBranchMatchedException.owner.returnType,
context.ir.symbols.throwNoWhenBranchMatchedException,
@@ -171,7 +171,7 @@ internal class EnumConstructorsLowering(val context: Context) : ClassLoweringPas
val endOffset = enumConstructorCall.endOffset
val origin = enumConstructorCall.origin
val result = IrDelegatingConstructorCallImpl.fromSymbolDescriptor(
val result = IrDelegatingConstructorCallImpl.fromSymbolOwner(
startOffset, endOffset,
context.irBuiltIns.unitType,
enumConstructorCall.symbol
@@ -206,7 +206,7 @@ internal class EnumConstructorsLowering(val context: Context) : ClassLoweringPas
throw AssertionError("Constructor called in enum entry initializer should've been lowered: $delegatingConstructor")
}
val result = IrDelegatingConstructorCallImpl.fromSymbolDescriptor(
val result = IrDelegatingConstructorCallImpl.fromSymbolOwner(
startOffset, endOffset,
context.irBuiltIns.unitType,
loweredDelegatingConstructor.symbol
@@ -326,12 +326,13 @@ internal class FunctionReferenceLowering(val context: Context): FileLoweringPass
addOverride("computeFqName") { irString(functionReferenceTarget.computeFullName()) }
val receiver = boundFunctionParameters.singleOrNull()
if (receiver?.descriptor is ReceiverParameterDescriptor) {
addOverrideInner("computeReceiver") { f ->
irGetField(irGet(f.dispatchReceiverParameter!!), argumentToPropertiesMap[receiver]!!)
}
}
functionReference.symbol.owner.dispatchReceiverParameter
?.takeIf { it in boundFunctionParameters }
?.let { receiver ->
addOverrideInner("computeReceiver") { f ->
irGetField(irGet(f.dispatchReceiverParameter!!), argumentToPropertiesMap[receiver]!!)
}
}
}
functionReferenceClass.addFakeOverrides(context.typeSystem)
@@ -379,7 +380,7 @@ internal class FunctionReferenceLowering(val context: Context): FileLoweringPass
fun build(): BuiltFunctionReference {
val clazz = buildClass()
val constructor = buildConstructor()
val arguments = functionReference.getArguments()
val arguments = functionReference.getArgumentsWithIr()
val expression = if (arguments.isEmpty()) {
irBuilder.irConstantObject(clazz, emptyMap())
} else {
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.impl.IrReturnableBlockSymbolImpl
import org.jetbrains.kotlin.ir.types.classifierOrFail
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.util.getArguments
import org.jetbrains.kotlin.ir.util.getArgumentsWithIr
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
@@ -82,7 +82,7 @@ internal class RedundantCoercionsCleaner(val context: Context) : FileLoweringPas
if (!expression.isBoxOrUnboxCall())
return super.visitCall(expression)
val argument = expression.getArguments().single().second
val argument = expression.getArgumentsWithIr().single().second
val foldedArgument = fold(
expression = argument,
coercion = expression,
@@ -133,7 +133,7 @@ internal class RedundantCoercionsCleaner(val context: Context) : FileLoweringPas
if (it.isBoxOrUnboxCall()) {
val result =
if (coercionDeclaringClass == (it as IrCall).symbol.owner.getCoercedClass())
it.getArguments().single().second
it.getArgumentsWithIr().single().second
else expression
return PossiblyFoldedExpression(result.transformIfAsked(), result != expression)
@@ -5,13 +5,12 @@
package org.jetbrains.kotlin.backend.konan.lower
import org.jetbrains.kotlin.backend.konan.InteropFqNames
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
import org.jetbrains.kotlin.backend.konan.ir.getSuperClassNotAny
import org.jetbrains.kotlin.backend.konan.ir.typeWithStarProjections
import org.jetbrains.kotlin.backend.konan.isObjCClass
import org.jetbrains.kotlin.backend.konan.llvm.computeFullName
import org.jetbrains.kotlin.backend.konan.reportCompilationError
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.*
@@ -20,8 +19,6 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers
import org.jetbrains.kotlin.types.Variance
private fun IrBuilderWithScope.irConstantString(string: String) = irConstantPrimitive(irString(string))
@@ -181,13 +178,16 @@ internal class KTypeGenerator(
internal fun IrBuilderWithScope.irKClass(context: KonanBackendContext, symbol: IrClassSymbol): IrConstantValue {
val symbols = context.ir.symbols
fun IrClass.isNativePointedChild() : Boolean =
this.symbol == context.ir.symbols.nativePointed || getSuperClassNotAny()?.isNativePointedChild() == true
return when {
symbol.descriptor.isObjCClass() ->
symbol.owner.isObjCClass() ->
irKClassUnsupported(context, "KClass for Objective-C classes is not supported yet")
symbol.descriptor.getAllSuperClassifiers().any {
it is ClassDescriptor && it.fqNameUnsafe == InteropFqNames.nativePointed
} -> irKClassUnsupported(context, "KClass for interop types is not supported yet")
symbol.owner.isNativePointedChild() ->
irKClassUnsupported(context, "KClass for interop types is not supported yet")
else -> irConstantObject(symbols.kClassImplIntrinsicConstructor, emptyList(), listOf(symbol.typeWithStarProjections))
}
@@ -191,7 +191,7 @@ internal class TestProcessor (val context: Context) {
element.acceptChildrenVoid(this)
}
fun IrFunctionSymbol.hasAnnotation(fqName: FqName) = descriptor.annotations.any { it.fqName == fqName }
fun IrFunctionSymbol.hasAnnotation(fqName: FqName) = owner.hasAnnotation(fqName)
/**
* Checks if [this] or any of its parent functions has the annotation with the given [testAnnotation].
@@ -177,7 +177,7 @@ internal class VarargInjectionLowering constructor(val context: KonanBackendCont
private fun arrayType(type: IrType): ArrayHandle {
val arrayClass = type.classifierOrFail
return arrayToHandle[arrayClass] ?: error(arrayClass.descriptor)
return arrayToHandle[arrayClass] ?: error(arrayClass)
}
private fun IrBuilderWithScope.intPlus() = irCall(intPlusInt)
@@ -194,6 +194,7 @@ internal class VarargInjectionLowering constructor(val context: KonanBackendCont
putValueArgument(0, value)
})
}
private fun calculateArraySize(arrayHandle: ArrayHandle, hasSpreadElement: Boolean, scope:Scope, expression: IrVararg, vars: Map<IrVarargElement, IrVariable>): IrExpression {
context.createIrBuilder(scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset).run {
if (!hasSpreadElement)