IR: remove non-supertype usages of abstract impl classes
Work with the corresponding base interfaces instead. This change will help in moving the IR element hierarchy from interfaces to classes, should the need arise. There's a possible change in behavior in `CallAndReferenceGenerator.applyCallArguments`, which however doesn't seem to break anything: IrPropertyReferenceImpl can now also be handled by this method.
This commit is contained in:
@@ -673,7 +673,7 @@ class Fir2IrVisitor(
|
||||
}
|
||||
|
||||
private fun FirJump<FirLoop>.convertJumpWithOffsets(
|
||||
f: (startOffset: Int, endOffset: Int, irLoop: IrLoop) -> IrBreakContinueBase
|
||||
f: (startOffset: Int, endOffset: Int, irLoop: IrLoop, label: String?) -> IrBreakContinue
|
||||
): IrExpression {
|
||||
return convertWithOffsets { startOffset, endOffset ->
|
||||
val firLoop = target.labeledElement
|
||||
@@ -681,22 +681,24 @@ class Fir2IrVisitor(
|
||||
if (irLoop == null) {
|
||||
IrErrorExpressionImpl(startOffset, endOffset, irBuiltIns.nothingType, "Unbound loop: ${render()}")
|
||||
} else {
|
||||
f(startOffset, endOffset, irLoop).apply {
|
||||
label = irLoop.label.takeIf { target.labelName != null }
|
||||
}
|
||||
f(startOffset, endOffset, irLoop, irLoop.label.takeIf { target.labelName != null })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBreakExpression(breakExpression: FirBreakExpression, data: Any?): IrElement {
|
||||
return breakExpression.convertJumpWithOffsets { startOffset, endOffset, irLoop ->
|
||||
IrBreakImpl(startOffset, endOffset, irBuiltIns.nothingType, irLoop)
|
||||
return breakExpression.convertJumpWithOffsets { startOffset, endOffset, irLoop, label ->
|
||||
IrBreakImpl(startOffset, endOffset, irBuiltIns.nothingType, irLoop).apply {
|
||||
this.label = label
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitContinueExpression(continueExpression: FirContinueExpression, data: Any?): IrElement {
|
||||
return continueExpression.convertJumpWithOffsets { startOffset, endOffset, irLoop ->
|
||||
IrContinueImpl(startOffset, endOffset, irBuiltIns.nothingType, irLoop)
|
||||
return continueExpression.convertJumpWithOffsets { startOffset, endOffset, irLoop, label ->
|
||||
IrContinueImpl(startOffset, endOffset, irBuiltIns.nothingType, irLoop).apply {
|
||||
this.label = label
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-18
@@ -30,7 +30,8 @@ import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
||||
import org.jetbrains.kotlin.psi.KtPropertyDelegate
|
||||
import org.jetbrains.kotlin.psi2ir.generators.hasNoSideEffects
|
||||
@@ -317,7 +318,7 @@ class CallAndReferenceGenerator(
|
||||
internal fun IrExpression.applyCallArguments(call: FirCall?): IrExpression {
|
||||
if (call == null) return this
|
||||
return when (this) {
|
||||
is IrCallWithIndexedArgumentsBase -> {
|
||||
is IrMemberAccessExpression -> {
|
||||
val argumentsCount = call.arguments.size
|
||||
if (argumentsCount <= valueArgumentsCount) {
|
||||
apply {
|
||||
@@ -362,11 +363,11 @@ class CallAndReferenceGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrCallWithIndexedArgumentsBase.applyArgumentsWithReorderingIfNeeded(
|
||||
private fun IrMemberAccessExpression.applyArgumentsWithReorderingIfNeeded(
|
||||
call: FirCall,
|
||||
argumentMapping: Map<FirExpression, FirValueParameter>,
|
||||
valueParameters: List<FirValueParameter>,
|
||||
): IrExpressionBase {
|
||||
): IrExpression {
|
||||
// Assuming compile-time constants only inside annotation, we don't need a block to reorder arguments to preserve semantics.
|
||||
// But, we still need to pick correct indices for named arguments.
|
||||
if (call !is FirAnnotationCall &&
|
||||
@@ -436,7 +437,7 @@ class CallAndReferenceGenerator(
|
||||
|
||||
private fun IrExpression.applyTypeArguments(access: FirQualifiedAccess): IrExpression {
|
||||
return when (this) {
|
||||
is IrMemberAccessExpressionBase -> {
|
||||
is IrMemberAccessExpression -> {
|
||||
val argumentsCount = access.typeArguments.size
|
||||
if (argumentsCount <= typeArgumentsCount) {
|
||||
apply {
|
||||
@@ -494,8 +495,10 @@ class CallAndReferenceGenerator(
|
||||
|
||||
private fun IrExpression.applyReceivers(qualifiedAccess: FirQualifiedAccess, explicitReceiverExpression: IrExpression?): IrExpression {
|
||||
return when (this) {
|
||||
is IrCallWithIndexedArgumentsBase -> {
|
||||
val ownerFunction = symbol.owner as? IrFunction
|
||||
is IrMemberAccessExpression -> {
|
||||
val ownerFunction =
|
||||
symbol.owner as? IrFunction
|
||||
?: (symbol.owner as? IrProperty)?.getter
|
||||
if (ownerFunction?.dispatchReceiverParameter != null) {
|
||||
dispatchReceiver = qualifiedAccess.findIrDispatchReceiver(explicitReceiverExpression)
|
||||
}
|
||||
@@ -504,17 +507,7 @@ class CallAndReferenceGenerator(
|
||||
}
|
||||
this
|
||||
}
|
||||
is IrNoArgumentsCallableReferenceBase -> {
|
||||
val ownerPropertyGetter = (symbol.owner as? IrProperty)?.getter
|
||||
if (ownerPropertyGetter?.dispatchReceiverParameter != null) {
|
||||
dispatchReceiver = qualifiedAccess.findIrDispatchReceiver(explicitReceiverExpression)
|
||||
}
|
||||
if (ownerPropertyGetter?.extensionReceiverParameter != null) {
|
||||
extensionReceiver = qualifiedAccess.findIrExtensionReceiver(explicitReceiverExpression)
|
||||
}
|
||||
this
|
||||
}
|
||||
is IrFieldExpressionBase -> {
|
||||
is IrFieldAccessExpression -> {
|
||||
val ownerField = symbol.owner
|
||||
if (!ownerField.isStatic) {
|
||||
receiver = qualifiedAccess.findIrDispatchReceiver(explicitReceiverExpression)
|
||||
|
||||
+3
-2
@@ -8,7 +8,8 @@ package org.jetbrains.kotlin.fir.lazy
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
||||
import org.jetbrains.kotlin.fir.backend.toIrType
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrBindableSymbol
|
||||
import org.jetbrains.kotlin.ir.IrElementBase
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
@@ -38,7 +39,7 @@ abstract class AbstractFir2IrLazyDeclaration<F : FirMemberDeclaration, D : IrSym
|
||||
|
||||
lateinit var typeParameters: List<IrTypeParameter>
|
||||
|
||||
override var metadata: Nothing?
|
||||
override var metadata: MetadataSource?
|
||||
get() = null
|
||||
set(_) = error("We should never need to store metadata of external declarations.")
|
||||
|
||||
|
||||
+4
-3
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFunWithDescriptorForInlining
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionBase
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
@@ -204,8 +203,10 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean) {
|
||||
parent = function.parent
|
||||
annotations += function.annotations
|
||||
copyTypeParameters(function.allTypeParameters)
|
||||
metadata = function.metadata
|
||||
function.safeAs<IrFunctionBase<*>>()?.metadata = null
|
||||
if (function.metadata != null) {
|
||||
metadata = function.metadata
|
||||
function.metadata = null
|
||||
}
|
||||
|
||||
if (function is IrSimpleFunction) {
|
||||
val propertySymbol = function.correspondingPropertySymbol
|
||||
|
||||
+3
-5
@@ -20,12 +20,10 @@ import org.jetbrains.kotlin.ir.builders.IrGeneratorContext
|
||||
import org.jetbrains.kotlin.ir.builders.Scope
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionWithCopy
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrContainerExpressionBase
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementContainer
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class RematerializableValue(val irExpression: IrExpressionWithCopy) : IntermediateValue {
|
||||
|
||||
override val type: IrType get() = irExpression.type
|
||||
|
||||
override fun load(): IrExpression = irExpression.copy()
|
||||
@@ -34,10 +32,10 @@ class RematerializableValue(val irExpression: IrExpressionWithCopy) : Intermedia
|
||||
fun Scope.createTemporaryVariableInBlock(
|
||||
context: IrGeneratorContext,
|
||||
irExpression: IrExpression,
|
||||
block: IrContainerExpressionBase,
|
||||
block: IrStatementContainer,
|
||||
nameHint: String? = null
|
||||
): IntermediateValue {
|
||||
val temporaryVariable = createTemporaryVariable(irExpression, nameHint)
|
||||
block.statements.add(temporaryVariable)
|
||||
return VariableLValue(context, temporaryVariable)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ interface IrFunction :
|
||||
|
||||
var body: IrBody?
|
||||
|
||||
override val metadata: MetadataSource?
|
||||
override var metadata: MetadataSource?
|
||||
}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
|
||||
+1
-2
@@ -55,9 +55,8 @@ abstract class IrLazyDeclarationBase(
|
||||
descriptor.annotations.mapNotNull(typeTranslator.constantValueGenerator::generateAnnotationConstructorCall).toMutableList()
|
||||
}
|
||||
|
||||
override var metadata: Nothing?
|
||||
override val metadata: MetadataSource?
|
||||
get() = null
|
||||
set(_) = error("We should never need to store metadata of external declarations.")
|
||||
|
||||
private fun createLazyParent(): IrDeclarationParent? {
|
||||
val currentDescriptor = descriptor
|
||||
|
||||
+5
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||
@@ -66,6 +67,10 @@ abstract class IrLazyFunctionBase(
|
||||
}
|
||||
}
|
||||
|
||||
override var metadata: MetadataSource?
|
||||
get() = null
|
||||
set(_) = error("We should never need to store metadata of external declarations.")
|
||||
|
||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||
typeParameters.forEach { it.accept(visitor, data) }
|
||||
|
||||
|
||||
@@ -20,10 +20,9 @@ interface IrLoop : IrExpression {
|
||||
val origin: IrStatementOrigin?
|
||||
var body: IrExpression?
|
||||
var condition: IrExpression
|
||||
val label: String?
|
||||
var label: String?
|
||||
}
|
||||
|
||||
interface IrWhileLoop : IrLoop
|
||||
|
||||
interface IrDoWhileLoop : IrLoop
|
||||
|
||||
|
||||
+2
-2
@@ -120,7 +120,7 @@ abstract class IrFileDeserializer(
|
||||
abstract fun deserializeString(index: Int): String
|
||||
abstract fun deserializeExpressionBody(index: Int): IrExpression
|
||||
abstract fun deserializeStatementBody(index: Int): IrElement
|
||||
abstract fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoopBase): IrLoopBase
|
||||
abstract fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoop): IrLoop
|
||||
|
||||
abstract fun referenceIrSymbol(symbol: IrSymbol, signature: IdSignature)
|
||||
|
||||
@@ -709,7 +709,7 @@ abstract class IrFileDeserializer(
|
||||
return IrWhenImpl(start, end, type, origin, branches)
|
||||
}
|
||||
|
||||
private fun deserializeLoop(proto: ProtoLoop, loop: IrLoopBase): IrLoopBase {
|
||||
private fun deserializeLoop(proto: ProtoLoop, loop: IrLoop): IrLoop {
|
||||
val label = if (proto.hasLabel()) deserializeString(proto.label) else null
|
||||
val body = if (proto.hasBody()) deserializeExpression(proto.body) else null
|
||||
val condition = deserializeExpression(proto.condition)
|
||||
|
||||
+4
-4
@@ -21,9 +21,9 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrLoopBase
|
||||
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
@@ -230,7 +230,7 @@ abstract class KotlinIrLinker(
|
||||
private val moduleDeserializer: IrModuleDeserializer
|
||||
) : IrFileDeserializer(logger, builtIns, symbolTable, !onlyHeaders, deserializeFakeOverrides) {
|
||||
|
||||
private var fileLoops = mutableMapOf<Int, IrLoopBase>()
|
||||
private var fileLoops = mutableMapOf<Int, IrLoop>()
|
||||
|
||||
lateinit var file: IrFile
|
||||
|
||||
@@ -396,7 +396,7 @@ abstract class KotlinIrLinker(
|
||||
override fun deserializeString(index: Int): String =
|
||||
loadStringProto(index)
|
||||
|
||||
override fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoopBase) =
|
||||
override fun deserializeLoopHeader(loopIndex: Int, loopBuilder: () -> IrLoop) =
|
||||
fileLoops.getOrPut(loopIndex, loopBuilder)
|
||||
|
||||
override fun deserializeExpressionBody(index: Int): IrExpression {
|
||||
@@ -688,4 +688,4 @@ enum class DeserializationStrategy(
|
||||
EXPLICITLY_EXPORTED(true, true, false, true),
|
||||
ONLY_DECLARATION_HEADERS(false, false, false, false),
|
||||
WITH_INLINE_BODIES(false, false, false, true)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user