[FIR] Change type of argumentMapping properties and parameters from Map
to LinkedHashMap, to signify that the order is important and we don't assume that mutableMapOf() will always return a LinkedHashMap.
This commit is contained in:
committed by
teamcityserver
parent
6b83f2d70e
commit
e175e87225
+1
-1
@@ -456,7 +456,7 @@ class CallAndReferenceGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun IrMemberAccessExpression<*>.applyArgumentsWithReorderingIfNeeded(
|
private fun IrMemberAccessExpression<*>.applyArgumentsWithReorderingIfNeeded(
|
||||||
argumentMapping: Map<FirExpression, FirValueParameter>,
|
argumentMapping: LinkedHashMap<FirExpression, FirValueParameter>,
|
||||||
valueParameters: List<FirValueParameter>,
|
valueParameters: List<FirValueParameter>,
|
||||||
annotationMode: Boolean
|
annotationMode: Boolean
|
||||||
): IrExpression {
|
): IrExpression {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class Candidate(
|
|||||||
var usesSAM: Boolean = false
|
var usesSAM: Boolean = false
|
||||||
var usesSuspendConversion: Boolean = false
|
var usesSuspendConversion: Boolean = false
|
||||||
|
|
||||||
var argumentMapping: Map<FirExpression, FirValueParameter>? = null
|
var argumentMapping: LinkedHashMap<FirExpression, FirValueParameter>? = null
|
||||||
var numDefaults: Int = 0
|
var numDefaults: Int = 0
|
||||||
lateinit var typeArgumentMapping: TypeArgumentMapping
|
lateinit var typeArgumentMapping: TypeArgumentMapping
|
||||||
val postponedAtoms = mutableListOf<PostponedResolvedAtom>()
|
val postponedAtoms = mutableListOf<PostponedResolvedAtom>()
|
||||||
|
|||||||
+6
-7
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScope
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.LinkedHashMap
|
||||||
import kotlin.collections.component1
|
import kotlin.collections.component1
|
||||||
import kotlin.collections.component2
|
import kotlin.collections.component2
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
@@ -29,13 +30,11 @@ data class ArgumentMapping(
|
|||||||
// fun foo(a: Int, b: Int) {}
|
// fun foo(a: Int, b: Int) {}
|
||||||
// foo(b = bar(), a = qux())
|
// foo(b = bar(), a = qux())
|
||||||
// parameterToCallArgumentMap.values() should be [ 'bar()', 'foo()' ]
|
// parameterToCallArgumentMap.values() should be [ 'bar()', 'foo()' ]
|
||||||
// TODO: Consider changing this (and other similar declarations like Candidate.argumentMapping) to LinkedHashMap to signify that
|
val parameterToCallArgumentMap: LinkedHashMap<FirValueParameter, ResolvedCallArgument>,
|
||||||
// order is important. Right now we're assuming that mutableMapOf() will always return a LinkedHashMap.
|
|
||||||
val parameterToCallArgumentMap: Map<FirValueParameter, ResolvedCallArgument>,
|
|
||||||
val diagnostics: List<ResolutionDiagnostic>
|
val diagnostics: List<ResolutionDiagnostic>
|
||||||
) {
|
) {
|
||||||
fun toArgumentToParameterMapping(): Map<FirExpression, FirValueParameter> {
|
fun toArgumentToParameterMapping(): LinkedHashMap<FirExpression, FirValueParameter> {
|
||||||
val argumentToParameterMapping = mutableMapOf<FirExpression, FirValueParameter>()
|
val argumentToParameterMapping = linkedMapOf<FirExpression, FirValueParameter>()
|
||||||
parameterToCallArgumentMap.forEach { (valueParameter, resolvedArgument) ->
|
parameterToCallArgumentMap.forEach { (valueParameter, resolvedArgument) ->
|
||||||
when (resolvedArgument) {
|
when (resolvedArgument) {
|
||||||
is ResolvedCallArgument.SimpleArgument -> argumentToParameterMapping[resolvedArgument.callArgument] = valueParameter
|
is ResolvedCallArgument.SimpleArgument -> argumentToParameterMapping[resolvedArgument.callArgument] = valueParameter
|
||||||
@@ -52,7 +51,7 @@ data class ArgumentMapping(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val EmptyArgumentMapping = ArgumentMapping(emptyMap(), emptyList())
|
private val EmptyArgumentMapping = ArgumentMapping(linkedMapOf(), emptyList())
|
||||||
|
|
||||||
fun BodyResolveComponents.mapArguments(
|
fun BodyResolveComponents.mapArguments(
|
||||||
arguments: List<FirExpression>,
|
arguments: List<FirExpression>,
|
||||||
@@ -108,7 +107,7 @@ private class FirCallArgumentsProcessor(
|
|||||||
private var nameToParameter: Map<Name, FirValueParameter>? = null
|
private var nameToParameter: Map<Name, FirValueParameter>? = null
|
||||||
var diagnostics: MutableList<ResolutionDiagnostic>? = null
|
var diagnostics: MutableList<ResolutionDiagnostic>? = null
|
||||||
private set
|
private set
|
||||||
val result: MutableMap<FirValueParameter, ResolvedCallArgument> = LinkedHashMap()
|
val result: LinkedHashMap<FirValueParameter, ResolvedCallArgument> = LinkedHashMap(function.valueParameters.size)
|
||||||
|
|
||||||
private enum class State {
|
private enum class State {
|
||||||
POSITION_ARGUMENTS,
|
POSITION_ARGUMENTS,
|
||||||
|
|||||||
+6
-2
@@ -207,8 +207,12 @@ class FirCallCompletionResultsWriterTransformer(
|
|||||||
withFirArrayOfCallTransformer {
|
withFirArrayOfCallTransformer {
|
||||||
annotationCall.argumentList.transformArguments(this, expectedArgumentsTypeMapping)
|
annotationCall.argumentList.transformArguments(this, expectedArgumentsTypeMapping)
|
||||||
var index = 0
|
var index = 0
|
||||||
subCandidate.argumentMapping = subCandidate.argumentMapping?.mapKeys { (_, _) ->
|
subCandidate.argumentMapping = subCandidate.argumentMapping?.let {
|
||||||
annotationCall.argumentList.arguments[index++]
|
LinkedHashMap<FirExpression, FirValueParameter>(it.size).let { newMapping ->
|
||||||
|
subCandidate.argumentMapping?.mapKeysTo(newMapping) { (_, _) ->
|
||||||
|
annotationCall.argumentList.arguments[index++]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!calleeReference.isError) {
|
if (!calleeReference.isError) {
|
||||||
|
|||||||
+3
-3
@@ -37,8 +37,8 @@ internal inline var FirExpression.resultType: FirTypeRef
|
|||||||
internal fun remapArgumentsWithVararg(
|
internal fun remapArgumentsWithVararg(
|
||||||
varargParameter: FirValueParameter,
|
varargParameter: FirValueParameter,
|
||||||
varargArrayType: ConeKotlinType,
|
varargArrayType: ConeKotlinType,
|
||||||
argumentMapping: Map<FirExpression, FirValueParameter>
|
argumentMapping: LinkedHashMap<FirExpression, FirValueParameter>
|
||||||
): Map<FirExpression, FirValueParameter> {
|
): LinkedHashMap<FirExpression, FirValueParameter> {
|
||||||
// Create a FirVarargArgumentExpression for the vararg arguments.
|
// Create a FirVarargArgumentExpression for the vararg arguments.
|
||||||
// The order of arguments in the mapping must be preserved for FIR2IR, hence we have to find where the vararg arguments end.
|
// The order of arguments in the mapping must be preserved for FIR2IR, hence we have to find where the vararg arguments end.
|
||||||
// FIR2IR uses the mapping order to determine if arguments need to be reordered.
|
// FIR2IR uses the mapping order to determine if arguments need to be reordered.
|
||||||
@@ -46,7 +46,7 @@ internal fun remapArgumentsWithVararg(
|
|||||||
val varargElementType = varargArrayType.arrayElementType()
|
val varargElementType = varargArrayType.arrayElementType()
|
||||||
val argumentList = argumentMapping.keys.toList()
|
val argumentList = argumentMapping.keys.toList()
|
||||||
var indexAfterVarargs = argumentList.size
|
var indexAfterVarargs = argumentList.size
|
||||||
val newArgumentMapping = mutableMapOf<FirExpression, FirValueParameter>()
|
val newArgumentMapping = linkedMapOf<FirExpression, FirValueParameter>()
|
||||||
val varargArgument = buildVarargArgumentsExpression {
|
val varargArgument = buildVarargArgumentsExpression {
|
||||||
this.varargElementType = varargParameterTypeRef.withReplacedConeType(varargElementType)
|
this.varargElementType = varargParameterTypeRef.withReplacedConeType(varargElementType)
|
||||||
this.typeRef = varargParameterTypeRef.withReplacedConeType(varargArrayType)
|
this.typeRef = varargParameterTypeRef.withReplacedConeType(varargArrayType)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ fun buildBinaryArgumentList(left: FirExpression, right: FirExpression): FirArgum
|
|||||||
fun buildArraySetArgumentList(rValue: FirExpression, indexes: List<FirExpression>): FirArgumentList =
|
fun buildArraySetArgumentList(rValue: FirExpression, indexes: List<FirExpression>): FirArgumentList =
|
||||||
FirArraySetArgumentList(rValue, indexes)
|
FirArraySetArgumentList(rValue, indexes)
|
||||||
|
|
||||||
fun buildResolvedArgumentList(mapping: Map<FirExpression, FirValueParameter>): FirArgumentList =
|
fun buildResolvedArgumentList(mapping: LinkedHashMap<FirExpression, FirValueParameter>): FirArgumentList =
|
||||||
FirResolvedArgumentList(mapping)
|
FirResolvedArgumentList(mapping)
|
||||||
|
|
||||||
object FirEmptyArgumentList : FirAbstractArgumentList() {
|
object FirEmptyArgumentList : FirAbstractArgumentList() {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ inline val FirCall.arguments: List<FirExpression> get() = argumentList.arguments
|
|||||||
|
|
||||||
inline val FirCall.argument: FirExpression get() = argumentList.arguments.first()
|
inline val FirCall.argument: FirExpression get() = argumentList.arguments.first()
|
||||||
|
|
||||||
inline val FirCall.argumentMapping: Map<FirExpression, FirValueParameter>?
|
inline val FirCall.argumentMapping: LinkedHashMap<FirExpression, FirValueParameter>?
|
||||||
get() = (argumentList as? FirResolvedArgumentList)?.mapping
|
get() = (argumentList as? FirResolvedArgumentList)?.mapping
|
||||||
|
|
||||||
fun FirExpression.toResolvedCallableReference(): FirResolvedNamedReference? {
|
fun FirExpression.toResolvedCallableReference(): FirResolvedNamedReference? {
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression
|
|||||||
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
import org.jetbrains.kotlin.fir.visitors.FirVisitor
|
||||||
|
|
||||||
class FirResolvedArgumentList internal constructor(
|
class FirResolvedArgumentList internal constructor(
|
||||||
val mapping: Map<FirExpression, FirValueParameter>
|
val mapping: LinkedHashMap<FirExpression, FirValueParameter>
|
||||||
) : FirAbstractArgumentList() {
|
) : FirAbstractArgumentList() {
|
||||||
override val arguments: List<FirExpression>
|
override val arguments: List<FirExpression>
|
||||||
get() = mapping.keys.toList()
|
get() = mapping.keys.toList()
|
||||||
|
|||||||
Reference in New Issue
Block a user