[IR] Use extractTypeParameter instead of collectTypeParameters

^KT-45866 fixed
This commit is contained in:
Ilya Goncharov
2021-04-07 13:07:39 +03:00
committed by TeamCityServer
parent 5955faecec
commit b976cd812a
3 changed files with 12 additions and 24 deletions
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.expressions.IrGetValue
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
import org.jetbrains.kotlin.ir.types.extractTypeParameters
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
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
@@ -106,8 +107,8 @@ class ExpectDeclarationRemover(val symbolTable: ReferenceSymbolTable, private va
val expectToActual = expectFunction to function val expectToActual = expectFunction to function
if (expectToActual !in typeParameterSubstitutionMap) { if (expectToActual !in typeParameterSubstitutionMap) {
val functionTypeParameters = collectTypeParameters(function) val functionTypeParameters = extractTypeParameters(function)
val expectFunctionTypeParameters = collectTypeParameters(expectFunction) val expectFunctionTypeParameters = extractTypeParameters(expectFunction)
expectFunctionTypeParameters.zip(functionTypeParameters).let { typeParametersMapping -> expectFunctionTypeParameters.zip(functionTypeParameters).let { typeParametersMapping ->
typeParameterSubstitutionMap[expectToActual] = typeParametersMapping.toMap() typeParameterSubstitutionMap[expectToActual] = typeParametersMapping.toMap()
@@ -117,11 +118,13 @@ class ExpectDeclarationRemover(val symbolTable: ReferenceSymbolTable, private va
defaultValue.let { originalDefault -> defaultValue.let { originalDefault ->
declaration.defaultValue = declaration.factory.createExpressionBody(originalDefault.startOffset, originalDefault.endOffset) { declaration.defaultValue = declaration.factory.createExpressionBody(originalDefault.startOffset, originalDefault.endOffset) {
expression = originalDefault.expression expression = originalDefault.expression
.deepCopyWithSymbols(function) .deepCopyWithSymbols(function) { symbolRemapper, _ ->
.remapExpectValueSymbols() DeepCopyIrTreeWithSymbols(
.apply { symbolRemapper,
remapTypes(IrTypeParameterRemapper(typeParameterSubstitutionMap.getValue(expectToActual))) IrTypeParameterRemapper(typeParameterSubstitutionMap.getValue(expectToActual))
)
} }
.remapExpectValueSymbols()
} }
} }
} }
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.transformStatement import org.jetbrains.kotlin.ir.transformStatement
import org.jetbrains.kotlin.ir.types.extractTypeParameters
import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
@@ -350,6 +351,6 @@ class InlineClassLowering(val context: CommonBackendContext) {
function.parent, function.parent,
function.toInlineClassImplementationName(), function.toInlineClassImplementationName(),
function, function,
typeParametersFromContext = collectTypeParameters(function.parentAsClass) typeParametersFromContext = extractTypeParameters(function.parentAsClass)
) )
} }
@@ -602,20 +602,4 @@ internal fun <T> IrConst<T>.shallowCopy() = IrConstImpl(
type, type,
kind, kind,
value value
) )
fun collectTypeParameters(declaration: IrTypeParametersContainer): List<IrTypeParameter> {
val result = mutableListOf<IrTypeParameter>()
fun collectImpl(declaration: IrDeclaration) {
if (declaration is IrTypeParametersContainer) {
result.addAll(declaration.typeParameters)
declaration.parentClassOrNull?.let { collectImpl(it) }
}
if (declaration is IrClass && declaration.isInner) collectImpl(declaration.parent as IrDeclaration)
}
collectImpl(declaration)
return result
}