Fixed bug in inliner with type substitution
This commit is contained in:
+21
-20
@@ -303,7 +303,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
return IrTemporaryVariableDescriptorImpl(
|
return IrTemporaryVariableDescriptorImpl(
|
||||||
containingDeclaration = newContainingDeclaration,
|
containingDeclaration = newContainingDeclaration,
|
||||||
name = generateCopyName(oldDescriptor.name),
|
name = generateCopyName(oldDescriptor.name),
|
||||||
outType = substituteTypeAndTryGetCopied(oldDescriptor.type)!!,
|
outType = substituteType(oldDescriptor.type)!!,
|
||||||
isMutable = oldDescriptor.isVar
|
isMutable = oldDescriptor.isVar
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -325,8 +325,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
val newDispatchReceiverParameter = oldDispatchReceiverParameter?.let { descriptorSubstituteMap.getOrDefault(it, it) as ReceiverParameterDescriptor }
|
val newDispatchReceiverParameter = oldDispatchReceiverParameter?.let { descriptorSubstituteMap.getOrDefault(it, it) as ReceiverParameterDescriptor }
|
||||||
val newTypeParameters = oldDescriptor.typeParameters // TODO substitute types
|
val newTypeParameters = oldDescriptor.typeParameters // TODO substitute types
|
||||||
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, this)
|
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, this)
|
||||||
val newReceiverParameterType = substituteTypeAndTryGetCopied(oldDescriptor.extensionReceiverParameter?.type)
|
val newReceiverParameterType = substituteType(oldDescriptor.extensionReceiverParameter?.type)
|
||||||
val newReturnType = substituteTypeAndTryGetCopied(oldDescriptor.returnType)
|
val newReturnType = substituteType(oldDescriptor.returnType)
|
||||||
|
|
||||||
initialize(
|
initialize(
|
||||||
/* receiverParameterType = */ newReceiverParameterType,
|
/* receiverParameterType = */ newReceiverParameterType,
|
||||||
@@ -348,8 +348,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
(descriptorSubstituteMap[oldDescriptor] as ClassConstructorDescriptorImpl).apply {
|
(descriptorSubstituteMap[oldDescriptor] as ClassConstructorDescriptorImpl).apply {
|
||||||
val newTypeParameters = oldDescriptor.typeParameters
|
val newTypeParameters = oldDescriptor.typeParameters
|
||||||
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, this)
|
val newValueParameters = copyValueParameters(oldDescriptor.valueParameters, this)
|
||||||
val receiverParameterType = substituteTypeAndTryGetCopied(oldDescriptor.dispatchReceiverParameter?.type)
|
val receiverParameterType = substituteType(oldDescriptor.dispatchReceiverParameter?.type)
|
||||||
val returnType = substituteTypeAndTryGetCopied(oldDescriptor.returnType)
|
val returnType = substituteType(oldDescriptor.returnType)
|
||||||
|
|
||||||
initialize(
|
initialize(
|
||||||
/* receiverParameterType = */ receiverParameterType,
|
/* receiverParameterType = */ receiverParameterType,
|
||||||
@@ -367,10 +367,10 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
private fun initPropertyOrField(oldDescriptor: PropertyDescriptor) {
|
private fun initPropertyOrField(oldDescriptor: PropertyDescriptor) {
|
||||||
val newDescriptor = (descriptorSubstituteMap[oldDescriptor] as PropertyDescriptorImpl).apply {
|
val newDescriptor = (descriptorSubstituteMap[oldDescriptor] as PropertyDescriptorImpl).apply {
|
||||||
setType(
|
setType(
|
||||||
/* outType = */ substituteTypeAndTryGetCopied(oldDescriptor.type)!!,
|
/* outType = */ substituteType(oldDescriptor.type)!!,
|
||||||
/* typeParameters = */ oldDescriptor.typeParameters,
|
/* typeParameters = */ oldDescriptor.typeParameters,
|
||||||
/* dispatchReceiverParameter = */ (containingDeclaration as ClassDescriptor).thisAsReceiverParameter,
|
/* dispatchReceiverParameter = */ (containingDeclaration as ClassDescriptor).thisAsReceiverParameter,
|
||||||
/* receiverType = */ substituteTypeAndTryGetCopied(oldDescriptor.extensionReceiverParameter?.type))
|
/* receiverType = */ substituteType(oldDescriptor.extensionReceiverParameter?.type))
|
||||||
|
|
||||||
initialize(
|
initialize(
|
||||||
/* getter = */ oldDescriptor.getter?.let { copyPropertyGetterDescriptor(it, this) },
|
/* getter = */ oldDescriptor.getter?.let { copyPropertyGetterDescriptor(it, this) },
|
||||||
@@ -400,7 +400,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
/* kind = */ oldDescriptor.kind,
|
/* kind = */ oldDescriptor.kind,
|
||||||
/* original = */ null,
|
/* original = */ null,
|
||||||
/* source = */ oldDescriptor.source).apply {
|
/* source = */ oldDescriptor.source).apply {
|
||||||
initialize(substituteTypeAndTryGetCopied(oldDescriptor.returnType))
|
initialize(substituteType(oldDescriptor.returnType))
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------//
|
//---------------------------------------------------------------------//
|
||||||
@@ -430,22 +430,17 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
index = oldDescriptor.index,
|
index = oldDescriptor.index,
|
||||||
annotations = oldDescriptor.annotations,
|
annotations = oldDescriptor.annotations,
|
||||||
name = oldDescriptor.name,
|
name = oldDescriptor.name,
|
||||||
outType = substituteTypeAndTryGetCopied(oldDescriptor.type)!!,
|
outType = substituteType(oldDescriptor.type)!!,
|
||||||
declaresDefaultValue = oldDescriptor.declaresDefaultValue(),
|
declaresDefaultValue = oldDescriptor.declaresDefaultValue(),
|
||||||
isCrossinline = oldDescriptor.isCrossinline,
|
isCrossinline = oldDescriptor.isCrossinline,
|
||||||
isNoinline = oldDescriptor.isNoinline,
|
isNoinline = oldDescriptor.isNoinline,
|
||||||
varargElementType = substituteTypeAndTryGetCopied(oldDescriptor.varargElementType),
|
varargElementType = substituteType(oldDescriptor.varargElementType),
|
||||||
source = oldDescriptor.source
|
source = oldDescriptor.source
|
||||||
)
|
)
|
||||||
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
descriptorSubstituteMap[oldDescriptor] = newDescriptor
|
||||||
newDescriptor
|
newDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun substituteTypeAndTryGetCopied(type: KotlinType?): KotlinType? {
|
|
||||||
val substitutedType = substituteType(type) ?: return null
|
|
||||||
val oldClassDescriptor = TypeUtils.getClassDescriptor(substitutedType) ?: return substitutedType
|
|
||||||
return descriptorSubstituteMap[oldClassDescriptor]?.let { (it as ClassDescriptor).defaultType } ?: substitutedType
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
//-----------------------------------------------------------------------------//
|
||||||
@@ -580,7 +575,12 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
sourceFileName = expression.sourceFileName
|
sourceFileName = expression.sourceFileName
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
super.visitBlock(expression)
|
IrBlockImpl(
|
||||||
|
expression.startOffset, expression.endOffset,
|
||||||
|
substituteType(expression.type)!!,
|
||||||
|
mapStatementOrigin(expression.origin),
|
||||||
|
expression.statements.map { it.transform(this, null) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,10 +620,11 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
private fun substituteType(oldType: KotlinType?): KotlinType? {
|
private fun substituteType(type: KotlinType?): KotlinType? {
|
||||||
if (typeSubstitutor == null) return oldType
|
val substitutedType = (type?.let { typeSubstitutor?.substitute(it, Variance.INVARIANT) } ?: type)
|
||||||
if (oldType == null) return oldType
|
?: return null
|
||||||
return typeSubstitutor!!.substitute(oldType, Variance.INVARIANT) ?: oldType
|
val oldClassDescriptor = TypeUtils.getClassDescriptor(substitutedType) ?: return substitutedType
|
||||||
|
return descriptorSubstituteMap[oldClassDescriptor]?.let { (it as ClassDescriptor).defaultType } ?: substitutedType
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|||||||
Reference in New Issue
Block a user