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