[IR] Make IrParameterKind not-nullable.
diff --git a/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt b/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt
index e69f41f..f248c4d 100644
--- a/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt
+++ b/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt
@@ -62,7 +62,7 @@
with(factory) { declarationCreated() }
annotations = declaration.annotations.memoryOptimizedMap { it.transform() }
defaultValue = declaration.defaultValue?.transform()
- _kind = declaration._kind
+ kind = declaration.kind
processAttributes(declaration)
}
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/declarations/IrValueParameterBuilder.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/declarations/IrValueParameterBuilder.kt
index 36d3f43..a359011 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/declarations/IrValueParameterBuilder.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/declarations/IrValueParameterBuilder.kt
@@ -12,7 +12,7 @@
const val UNDEFINED_PARAMETER_INDEX = -1
class IrValueParameterBuilder : IrDeclarationBuilder() {
- var kind: IrParameterKind? = null
+ var kind: IrParameterKind = IrParameterKind.Regular
lateinit var type: IrType
var varargElementType: IrType? = null
@@ -24,9 +24,7 @@
fun updateFrom(from: IrValueParameter) {
super.updateFrom(from)
- if (from._kind != null) {
- kind = from._kind
- }
+ kind = from.kind
type = from.type
varargElementType = from.varargElementType
isCrossInline = from.isCrossinline
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt
index bdd7790..1169735 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFactory.kt
@@ -415,7 +415,7 @@
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
- kind: IrParameterKind?,
+ kind: IrParameterKind,
name: Name,
type: IrType,
isAssignable: Boolean,
@@ -439,7 +439,7 @@
isAssignable = isAssignable,
factory = this
).apply {
- _kind = kind
+ this.kind = kind
}.declarationCreated()
/**
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt
index 4bed052..4a9285a 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt
@@ -60,16 +60,14 @@
var newContextParametersCount = 0
var oldIndex = 0
for ((index, parameter) in newParameters.withIndex()) {
- val kind = requireNotNull(parameter._kind) { "Kind must be set explicitly when adding a parameter" }
-
parameter.indexInParameters = index
@OptIn(DeprecatedForRemovalCompilerApi::class)
- parameter.indexInOldValueParameters = when (kind) {
+ parameter.indexInOldValueParameters = when (parameter.kind) {
IrParameterKind.DispatchReceiver, IrParameterKind.ExtensionReceiver -> -1
IrParameterKind.Context, IrParameterKind.Regular -> oldIndex++
}
- if (kind == IrParameterKind.Context) {
+ if (parameter.kind == IrParameterKind.Context) {
newContextParametersCount++
}
}
@@ -124,7 +122,7 @@
@OptIn(DeprecatedForRemovalCompilerApi::class)
old.indexInOldValueParameters = -1
old.indexInParameters = -1
- old._kind = null
+ old.kind = IrParameterKind.Regular
if (value != null) {
parameters[index] = value
@@ -211,7 +209,7 @@
if (newValueParameters != null) {
for (param in newValueParameters) {
- if (param._kind.let { it == IrParameterKind.DispatchReceiver || it == IrParameterKind.ExtensionReceiver }) {
+ if (param.kind.let { it == IrParameterKind.DispatchReceiver || it == IrParameterKind.ExtensionReceiver }) {
if (param === parameters.getOrNull(param.indexInParameters)) {
throw IllegalArgumentException(
"Adding a value parameter ${param.render()} to function ${this.render()}, when it's already present as a receiver.\n" +
@@ -237,7 +235,7 @@
param.indexInParameters = -1
@OptIn(DeprecatedForRemovalCompilerApi::class)
param.indexInOldValueParameters = -1
- param._kind = null
+ param.kind = IrParameterKind.Regular
}
}
}
@@ -273,8 +271,7 @@
var indexInOldValueParameters = 0
for (param in _parameters) {
@OptIn(DeprecatedForRemovalCompilerApi::class)
- param.indexInOldValueParameters = when (param._kind) {
- null -> -1
+ param.indexInOldValueParameters = when (param.kind) {
IrParameterKind.DispatchReceiver, IrParameterKind.ExtensionReceiver -> -1
IrParameterKind.Context, IrParameterKind.Regular -> indexInOldValueParameters++
}
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrValueParameter.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrValueParameter.kt
index 9176d69..93c100e 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrValueParameter.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrValueParameter.kt
@@ -70,17 +70,12 @@
@DelicateIrParameterIndexSetter
set
- // When using old parameter API, kind is assigned automatically when adding a parameter
- // to a function. However, up until that moment it is `null`.
- // When using new API (IrFunction.parameters), `kind` must be set explicitly before adding
- // a parameter to a function, such as by filling IrFactory.createValueParameter(kind = ...).
- // It is expected that after migration, all parameters will have a proper kind set upon creation,
- // and the nullable `_kind` will be dropped.
- // Before that happens, please use `_kind` in lower level code, that might see a not-yet-attached parameter,
- // and non-nullable `kind` otherwise, which e.g. enables exhaustive when.
- internal var _kind: IrParameterKind? = null
+ // Here the kind defaults to Regular, however, unless using the old parameter API,
+ // it is reassigned right away to the specified value (see IrFactory.createValueParameter).
+ // Also, when using the old API, kind is assigned automatically when a parameter is added to a function, and reverts to Regular when removed.
+ var kind: IrParameterKind = IrParameterKind.Regular
set(value) {
- if (field === value) return
+ if (field == value) return
field = value
// When a parameter is already in a function, changing its kind e.g. from regular parameter to
@@ -89,11 +84,6 @@
// This only affects old-API index, new API is alright.
(_parent as? IrFunction)?.reindexValueParameters()
}
- var kind: IrParameterKind
- get() = _kind!!
- set(value) {
- _kind = value
- }
abstract var varargElementType: IrType?
diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt
index 9c4f000..6a2d03c 100644
--- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt
+++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt
@@ -796,7 +796,7 @@
isCrossinline: Boolean = this.isCrossinline,
isNoinline: Boolean = this.isNoinline,
isAssignable: Boolean = this.isAssignable,
- kind: IrParameterKind? = this._kind,
+ kind: IrParameterKind = this.kind,
): IrValueParameter {
val symbol = IrValueParameterSymbolImpl()
val defaultValueCopy = defaultValue?.let { originalDefault ->
@@ -811,6 +811,7 @@
startOffset = startOffset,
endOffset = endOffset,
origin = origin,
+ kind = kind,
name = name,
type = type,
isAssignable = isAssignable,
@@ -820,7 +821,6 @@
isNoinline = isNoinline,
isHidden = false,
).also {
- it._kind = kind
it.parent = irFunction
it.defaultValue = defaultValueCopy
it.copyAnnotationsFrom(this)
diff --git a/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/print/DeepCopyIrTreeWithSymbolsPrinter.kt b/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/print/DeepCopyIrTreeWithSymbolsPrinter.kt
index 608142b..5731244 100644
--- a/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/print/DeepCopyIrTreeWithSymbolsPrinter.kt
+++ b/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/print/DeepCopyIrTreeWithSymbolsPrinter.kt
@@ -222,7 +222,7 @@
println("parameters = ${element.visitorParameterName}.parameters.memoryOptimizedMap { it.transform() }")
}
if (element.isSubclassOf(IrTree.valueParameter)) {
- println("_kind = ${element.visitorParameterName}._kind")
+ println("kind = ${element.visitorParameterName}.kind")
}
if (element.isSubclassOf(IrTree.file)) {
println("module = transformedModule ?: ${element.visitorParameterName}.module")