IR: modify IrTypeParametersContainer.copyTypeParameters()
This commit is contained in:
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.common.ir
|
|||||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||||
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
|
import org.jetbrains.kotlin.backend.common.DumpIrTreeWithDescriptorsVisitor
|
||||||
import org.jetbrains.kotlin.backend.common.deepCopyWithVariables
|
import org.jetbrains.kotlin.backend.common.deepCopyWithVariables
|
||||||
import org.jetbrains.kotlin.backend.common.descriptors.*
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
@@ -166,12 +165,12 @@ fun IrValueParameter.copyTo(
|
|||||||
|
|
||||||
fun IrTypeParameter.copyToWithoutSuperTypes(
|
fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||||
target: IrTypeParametersContainer,
|
target: IrTypeParametersContainer,
|
||||||
shift: Int = 0,
|
index: Int = this.index,
|
||||||
origin: IrDeclarationOrigin = this.origin
|
origin: IrDeclarationOrigin = this.origin
|
||||||
): IrTypeParameter {
|
): IrTypeParameter {
|
||||||
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
||||||
val symbol = IrTypeParameterSymbolImpl(descriptor)
|
val symbol = IrTypeParameterSymbolImpl(descriptor)
|
||||||
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also { copied ->
|
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, index, isReified, variance).also { copied ->
|
||||||
descriptor.bind(copied)
|
descriptor.bind(copied)
|
||||||
copied.parent = target
|
copied.parent = target
|
||||||
}
|
}
|
||||||
@@ -199,17 +198,18 @@ fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
|
|||||||
fun IrTypeParametersContainer.copyTypeParameters(
|
fun IrTypeParametersContainer.copyTypeParameters(
|
||||||
srcTypeParameters: List<IrTypeParameter>,
|
srcTypeParameters: List<IrTypeParameter>,
|
||||||
origin: IrDeclarationOrigin? = null
|
origin: IrDeclarationOrigin? = null
|
||||||
) {
|
): List<IrTypeParameter> {
|
||||||
val shift = typeParameters.size
|
val shift = typeParameters.size
|
||||||
// Any type parameter can figure in a boundary type for any other parameter.
|
// Any type parameter can figure in a boundary type for any other parameter.
|
||||||
// Therefore, we first copy the parameters themselves, then set up their supertypes.
|
// Therefore, we first copy the parameters themselves, then set up their supertypes.
|
||||||
srcTypeParameters.forEachIndexed { i, sourceParameter ->
|
val newTypeParameters = srcTypeParameters.mapIndexed { i, sourceParameter ->
|
||||||
assert(sourceParameter.index == i)
|
sourceParameter.copyToWithoutSuperTypes(this, index = i + shift, origin = origin ?: sourceParameter.origin)
|
||||||
typeParameters.add(sourceParameter.copyToWithoutSuperTypes(this, shift = shift, origin = origin ?: sourceParameter.origin))
|
|
||||||
}
|
}
|
||||||
srcTypeParameters.zip(typeParameters.drop(shift)).forEach { (srcParameter, dstParameter) ->
|
typeParameters.addAll(newTypeParameters)
|
||||||
|
srcTypeParameters.zip(newTypeParameters).forEach { (srcParameter, dstParameter) ->
|
||||||
dstParameter.copySuperTypesFrom(srcParameter)
|
dstParameter.copySuperTypesFrom(srcParameter)
|
||||||
}
|
}
|
||||||
|
return newTypeParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrTypeParametersContainer.copyTypeParametersFrom(
|
fun IrTypeParametersContainer.copyTypeParametersFrom(
|
||||||
|
|||||||
+3
-3
@@ -498,7 +498,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
|
|
||||||
irFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
irFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
||||||
parameter.copyToWithoutSuperTypes(this, 0, DECLARATION_ORIGIN_COROUTINE_IMPL)
|
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
||||||
.apply { superTypes += parameter.superTypes }
|
.apply { superTypes += parameter.superTypes }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +566,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
|
|
||||||
irFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
irFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
||||||
parameter.copyToWithoutSuperTypes(this, 0, DECLARATION_ORIGIN_COROUTINE_IMPL)
|
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
||||||
.apply { superTypes += parameter.superTypes }
|
.apply { superTypes += parameter.superTypes }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,7 +626,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
|
|
||||||
stateMachineFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
stateMachineFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
||||||
parameter.copyToWithoutSuperTypes(this, 0, DECLARATION_ORIGIN_COROUTINE_IMPL)
|
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
||||||
.apply { superTypes += parameter.superTypes }
|
.apply { superTypes += parameter.superTypes }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user