[IR] Drop usages of IrValueParameter.index in backend.common WIP
diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt
index 06b6cd3..d2d6be0 100644
--- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt
+++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt
@@ -80,8 +80,8 @@
//
// works correctly so that `f() { "OK" }` returns "OK" and
// `f()` throws a NullPointerException.
- originalDeclaration.valueParameters.forEach {
- variables[it.symbol] = newIrFunction.valueParameters[it.index].symbol
+ originalDeclaration.valueParameters.forEachIndexed { index, param ->
+ variables[param.symbol] = newIrFunction.valueParameters[index].symbol
}
generateSuperCallHandlerCheckIfNeeded(originalDeclaration, newIrFunction)
diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ExpectDeclarationRemover.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ExpectDeclarationRemover.kt
index 2c0a2d1..8e67fa2 100644
--- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ExpectDeclarationRemover.kt
+++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ExpectDeclarationRemover.kt
@@ -127,12 +127,10 @@
if (!function.descriptor.isActual) return
- val index = declaration.index
+ val index = function.valueParameters.indexOf(declaration)
if (index < 0) return
- assert(function.valueParameters[index] == declaration)
-
// If the containing declaration is an `expect class` that matches an `actual typealias`,
// the `actual fun` or `actual constructor` for this may be in a different module.
// Nothing we can do with those.
diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt
index bf380a9..e9a0971 100644
--- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt
+++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InlineClassDeclarationLowering.kt
@@ -169,9 +169,9 @@
// Secondary ctors of inline class must delegate to some other constructors.
// Use these delegating call later to initialize this variable.
lateinit var thisVar: IrVariable
- val parameterMapping = staticMethod.valueParameters.associateBy {
- irConstructor.valueParameters[it.index].symbol
- }
+ val parameterMapping = staticMethod.valueParameters.mapIndexed { index, param ->
+ irConstructor.valueParameters[index].symbol to param
+ }.toMap()
(constructorBody as IrBlockBody).statements.forEach { statement ->
+statement.transformStatement(object : IrElementTransformerVoid() {
@@ -262,7 +262,8 @@
in function.valueParameters -> {
val offset = if (function.extensionReceiverParameter != null) 2 else 1
- staticMethod.valueParameters[valueDeclaration.index + offset]
+ val paramIndex = function.valueParameters.indexOf(valueDeclaration)
+ staticMethod.valueParameters[paramIndex + offset]
}
else -> return expression
@@ -277,7 +278,8 @@
when (valueDeclaration) {
in function.valueParameters -> {
val offset = if (function.extensionReceiverParameter != null) 2 else 1
- staticMethod.valueParameters[valueDeclaration.index + offset].symbol
+ val paramIndex = function.valueParameters.indexOf(valueDeclaration)
+ staticMethod.valueParameters[paramIndex + offset].symbol
}
else -> return expression
},
diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt
index 99f44c3..53b9364 100644
--- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt
+++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt
@@ -138,7 +138,7 @@
private val IrValueSymbol.classForImplicitThis: IrClass?
// TODO: is this the correct way to get the class?
get() =
- if (this is IrValueParameterSymbol && owner.index == -1 &&
+ if (this is IrValueParameterSymbol &&
(owner == (owner.parent as? IrFunction)?.dispatchReceiverParameter ||
owner == (owner.parent as? IrClass)?.thisReceiver)
) {
diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SharedVariablesLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SharedVariablesLowering.kt
index 124a21b..af0eb73 100644
--- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SharedVariablesLowering.kt
+++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SharedVariablesLowering.kt
@@ -68,8 +68,8 @@
}
expression.dispatchReceiver?.accept(this, data)
expression.extensionReceiver?.accept(this, data)
- for (param in callee.valueParameters) {
- val arg = expression.getValueArgument(param.index) ?: continue
+ for ((index, param) in callee.valueParameters.withIndex()) {
+ val arg = expression.getValueArgument(index) ?: continue
if (param.isInlineParameter()
// This is somewhat conservative but simple.
// If a user put redundant <crossinline> modifier on a parameter,