diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt index 055157ec404..58dc800c352 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/IrUtils.kt @@ -78,7 +78,7 @@ fun IrClass.addSimpleDelegatingConstructor( constructor.parent = this declarations += constructor - superConstructor.valueParameters.mapIndexedTo(constructor.valueParameters) { index, parameter -> + constructor.valueParameters = superConstructor.valueParameters.mapIndexed { index, parameter -> parameter.copyTo(constructor, index = index) } @@ -163,7 +163,7 @@ fun IrValueParameter.copyTo( descriptor.bind(it) it.parent = irFunction it.defaultValue = defaultValueCopy - it.annotations.addAll(annotations.map { it.deepCopyWithSymbols() }) + it.annotations = annotations.map { it.deepCopyWithSymbols() } } } @@ -205,7 +205,7 @@ fun IrFunction.copyValueParametersInsertingContinuationFrom(from: IrFunction, in insertContinuation() additionalShift = 1 } - valueParameters.add(it.copyTo(this, index = it.index + shift + additionalShift)) + valueParameters += it.copyTo(this, index = it.index + shift + additionalShift) } // If there was no default argument mask and handler, the continuation goes last. if (additionalShift == 0) insertContinuation() @@ -231,7 +231,7 @@ fun IrTypeParametersContainer.copyTypeParameters( oldToNewParameterMap[sourceParameter] = it } } - typeParameters.addAll(newTypeParameters) + typeParameters += newTypeParameters srcTypeParameters.zip(newTypeParameters).forEach { (srcParameter, dstParameter) -> dstParameter.copySuperTypesFrom(srcParameter, oldToNewParameterMap) } @@ -273,35 +273,29 @@ fun IrFunction.copyValueParametersToStatic( target.classIfConstructor ) - target.valueParameters.add( - originalDispatchReceiver.copyTo( - target, - origin = originalDispatchReceiver.origin, - index = shift++, - type = type, - name = Name.identifier("\$this") - ) + target.valueParameters += originalDispatchReceiver.copyTo( + target, + origin = originalDispatchReceiver.origin, + index = shift++, + type = type, + name = Name.identifier("\$this") ) } source.extensionReceiverParameter?.let { originalExtensionReceiver -> - target.valueParameters.add( - originalExtensionReceiver.copyTo( - target, - origin = originalExtensionReceiver.origin, - index = shift++, - name = Name.identifier("\$receiver") - ) + target.valueParameters += originalExtensionReceiver.copyTo( + target, + origin = originalExtensionReceiver.origin, + index = shift++, + name = Name.identifier("\$receiver") ) } for (oldValueParameter in source.valueParameters) { if (oldValueParameter.index >= numValueParametersToCopy) break - target.valueParameters.add( - oldValueParameter.copyTo( - target, - origin = origin, - index = oldValueParameter.index + shift - ) + target.valueParameters += oldValueParameter.copyTo( + target, + origin = origin, + index = oldValueParameter.index + shift ) } } @@ -601,7 +595,7 @@ fun createStaticFunctionWithReceivers( typeParameters.forEach { it.superTypes.replaceAll { remap(it) } } - annotations.addAll(oldFunction.annotations) + annotations = oldFunction.annotations var offset = 0 val dispatchReceiver = oldFunction.dispatchReceiverParameter?.copyTo( @@ -618,7 +612,7 @@ fun createStaticFunctionWithReceivers( origin = IrDeclarationOrigin.MOVED_EXTENSION_RECEIVER, remapTypeMap = typeParameterMap ) - valueParameters.addAll(listOfNotNull(dispatchReceiver, extensionReceiver) + + valueParameters = listOfNotNull(dispatchReceiver, extensionReceiver) + oldFunction.valueParameters.map { it.copyTo( this, @@ -626,7 +620,6 @@ fun createStaticFunctionWithReceivers( remapTypeMap = typeParameterMap ) } - ) if (copyMetadata) metadata = oldFunction.metadata } @@ -670,10 +663,11 @@ private fun IrSimpleFunction.copyAndRenameConflictingTypeParametersFrom( it.parent = this } - typeParameters.add(newTypeParameter) newParameters.add(newTypeParameter) } + typeParameters = typeParameters + newParameters + return newParameters } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/AbstractSuspendFunctionsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/AbstractSuspendFunctionsLowering.kt index 5521bcb25f0..5a9afbbcdd1 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/AbstractSuspendFunctionsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/AbstractSuspendFunctionsLowering.kt @@ -300,7 +300,7 @@ abstract class AbstractSuspendFunctionsLowering(val co d.bind(this) parent = irFunction.parent createParameterDeclarations() - irFunction.typeParameters.mapTo(typeParameters) { typeParam -> + typeParameters = irFunction.typeParameters.map { typeParam -> typeParam.copyToWithoutSuperTypes(this).apply { superTypes += typeParam.superTypes } } } @@ -403,7 +403,7 @@ abstract class AbstractSuspendFunctionsLowering(val co coroutineClass.declarations += this coroutineConstructors += this - functionParameters.mapIndexedTo(valueParameters) { index, parameter -> + valueParameters = functionParameters.mapIndexed { index, parameter -> parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index) } val continuationParameter = coroutineBaseClassConstructor.valueParameters[0] @@ -449,7 +449,7 @@ abstract class AbstractSuspendFunctionsLowering(val co coroutineClass.declarations += this coroutineConstructors += this - boundParams.mapIndexedTo(valueParameters) { index, parameter -> + valueParameters = boundParams.mapIndexed { index, parameter -> parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index) } @@ -498,15 +498,14 @@ abstract class AbstractSuspendFunctionsLowering(val co parent = coroutineClass coroutineClass.declarations += this - irFunction.typeParameters.mapTo(typeParameters) { parameter -> + typeParameters = irFunction.typeParameters.map { parameter -> parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL) .apply { superTypes += parameter.superTypes } } - (unboundArgs + create1CompletionParameter) - .mapIndexedTo(valueParameters) { index, parameter -> - parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index) - } + valueParameters = (unboundArgs + create1CompletionParameter).mapIndexed { index, parameter -> + parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index) + } this.createDispatchReceiverParameter() @@ -566,15 +565,15 @@ abstract class AbstractSuspendFunctionsLowering(val co parent = coroutineClass coroutineClass.declarations += this - irFunction.typeParameters.mapTo(typeParameters) { parameter -> + typeParameters = irFunction.typeParameters.map { parameter -> parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL) .apply { superTypes += parameter.superTypes } } - createFunction.valueParameters + valueParameters = createFunction.valueParameters // Skip completion - invoke() already has it implicitly as a suspend function. .take(createFunction.valueParameters.size - 1) - .mapIndexedTo(valueParameters) { index, parameter -> + .mapIndexed { index, parameter -> parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index) } @@ -626,12 +625,12 @@ abstract class AbstractSuspendFunctionsLowering(val co parent = coroutineClass coroutineClass.declarations += this - stateMachineFunction.typeParameters.mapTo(typeParameters) { parameter -> + typeParameters = stateMachineFunction.typeParameters.map { parameter -> parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL) .apply { superTypes += parameter.superTypes } } - stateMachineFunction.valueParameters.mapIndexedTo(valueParameters) { index, parameter -> + valueParameters = stateMachineFunction.valueParameters.mapIndexed { index, parameter -> parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index) } 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 99455fea670..1ff4076c6a8 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 @@ -364,7 +364,7 @@ private fun IrFunction.generateDefaultsFunction( } if (overriddenStubs.isNotEmpty()) { return generateDefaultsFunctionImpl(context, IrDeclarationOrigin.FAKE_OVERRIDE, visibility).also { - (it as IrSimpleFunction).overriddenSymbols.addAll(overriddenStubs) + (it as IrSimpleFunction).overriddenSymbols += overriddenStubs context.ir.defaultParameterDeclarationsCache[this] = it } } @@ -420,7 +420,7 @@ private fun IrFunction.generateDefaultsFunctionImpl( newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.copyTo(newFunction) newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction) - valueParameters.mapTo(newFunction.valueParameters) { + newFunction.valueParameters = valueParameters.map { val newType = it.type.remapTypeParameters(classIfConstructor, newFunction.classIfConstructor) val makeNullable = it.defaultValue != null && (context.ir.unfoldInlineClassType(it.type) ?: it.type) !in context.irBuiltIns.primitiveIrTypes @@ -445,7 +445,7 @@ private fun IrFunction.generateDefaultsFunctionImpl( } // TODO some annotations are needed (e.g. @JvmStatic), others need different values (e.g. @JvmName), the rest are redundant. - annotations.mapTo(newFunction.annotations) { it.deepCopyWithSymbols() } + newFunction.annotations = annotations.map { it.deepCopyWithSymbols() } return newFunction } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt index d7a55cf0861..e4289621abc 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalDeclarationsLowering.kt @@ -613,7 +613,7 @@ class LocalDeclarationsLowering( ) newDeclaration.recordTransformedValueParameters(localFunctionContext) - newDeclaration.annotations.addAll(oldDeclaration.annotations) + newDeclaration.annotations = oldDeclaration.annotations transformedDeclarations[oldDeclaration] = newDeclaration } diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt index d736ada3899..ee0e9844c7f 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/SingleAbstractMethodLowering.kt @@ -196,7 +196,7 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) : }.apply { overriddenSymbols += superMethod.symbol dispatchReceiverParameter = subclass.thisReceiver!!.copyTo(this) - superMethod.valueParameters.mapTo(valueParameters) { it.copyTo(this) } + valueParameters = superMethod.valueParameters.map { it.copyTo(this) } body = context.createIrBuilder(symbol).irBlockBody { +irReturn(irCall(wrappedFunctionClass.functions.single { it.name == OperatorNameConventions.INVOKE }).apply { dispatchReceiver = irGetField(irGet(dispatchReceiverParameter!!), field) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/builders/declarations/declarationBuilders.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/builders/declarations/declarationBuilders.kt index 88dd0a6ae26..14f26495cb5 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/builders/declarations/declarationBuilders.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/builders/declarations/declarationBuilders.kt @@ -234,7 +234,7 @@ inline fun IrFunction.addValueParameter(builder: IrValueParameterBuilder.() -> U index = valueParameters.size } build().also { valueParameter -> - valueParameters.add(valueParameter) + valueParameters += valueParameter valueParameter.parent = this@addValueParameter } } @@ -293,7 +293,7 @@ inline fun IrTypeParametersContainer.addTypeParameter(builder: IrTypeParameterBu index = typeParameters.size } build().also { typeParameter -> - typeParameters.add(typeParameter) + typeParameters += typeParameter typeParameter.parent = this@addTypeParameter } } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt index 8f1a69c4c49..f437ac92e83 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt @@ -137,8 +137,8 @@ class BridgesConstruction(val context: CommonBackendContext) : ClassLoweringPass extensionReceiverParameter = bridge.extensionReceiverParameter?.copyTo(this) valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) } annotations += bridge.annotations - overriddenSymbols.addAll(delegateTo.overriddenSymbols) - overriddenSymbols.add(bridge.symbol) + overriddenSymbols += delegateTo.overriddenSymbols + overriddenSymbols += bridge.symbol } context.createIrBuilder(irFunction.symbol).irBlockBody(irFunction) { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/SecondaryCtorLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/SecondaryCtorLowering.kt index 46881592c5f..09d7bc1938b 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/SecondaryCtorLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/SecondaryCtorLowering.kt @@ -155,7 +155,7 @@ private fun buildInitDeclaration(constructor: IrConstructor, irClass: IrClass): ).also { it.copyTypeParametersFrom(constructor.parentAsClass) - constructor.valueParameters.mapTo(it.valueParameters) { p -> p.copyTo(it) } + it.valueParameters = constructor.valueParameters.map { p -> p.copyTo(it) } it.valueParameters += JsIrBuilder.buildValueParameter("\$this", constructor.valueParameters.size, type).apply { parent = it } } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDeclarationFactory.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDeclarationFactory.kt index 99d3d3ec08f..a6279b726bd 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDeclarationFactory.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/JvmDeclarationFactory.kt @@ -97,7 +97,7 @@ class JvmDeclarationFactory( isExpect = oldConstructor.isExpect ).apply { newDescriptor.bind(this) - annotations.addAll(oldConstructor.annotations.map { it.deepCopyWithSymbols(this) }) + annotations = oldConstructor.annotations.map { it.deepCopyWithSymbols(this) } parent = oldConstructor.parent returnType = oldConstructor.returnType copyTypeParametersFrom(oldConstructor) @@ -117,9 +117,7 @@ class JvmDeclarationFactory( outerThisDescriptor.bind(it) it.parent = this } - valueParameters.add(outerThisValueParameter) - - oldConstructor.valueParameters.mapTo(valueParameters) { it.copyTo(this, index = it.index + 1) } + valueParameters = listOf(outerThisValueParameter) + oldConstructor.valueParameters.map { it.copyTo(this, index = it.index + 1) } metadata = oldConstructor.metadata } } @@ -267,9 +265,9 @@ class JvmDeclarationFactory( ).apply { descriptor.bind(this) parent = irClass - overriddenSymbols.addAll(fakeOverride.overriddenSymbols) + overriddenSymbols = fakeOverride.overriddenSymbols copyParameterDeclarationsFrom(fakeOverride) - annotations.addAll(fakeOverride.annotations) + annotations = fakeOverride.annotations fakeOverride.correspondingPropertySymbol?.owner?.let { fakeOverrideProperty -> // NB: property is only generated for the sake of the type mapper. // If both setter and getter are present, original property will be duplicated. diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt index 7b96fdca095..1dcb4b27d68 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/descriptors/SharedVariablesManager.kt @@ -58,7 +58,7 @@ class JvmSharedVariablesManager( }.apply { parent = jvmInternalPackage jvmInternalPackage.addChild(this) - superTypes.add(irBuiltIns.anyType) + superTypes += irBuiltIns.anyType } private abstract class RefProvider { @@ -96,7 +96,7 @@ class JvmSharedVariablesManager( }.apply { parent = refNamespaceClass refNamespaceClass.addMember(this) - superTypes.add(irBuiltIns.anyType) + superTypes += irBuiltIns.anyType thisReceiver = buildValueParameter { type = IrSimpleTypeImpl(symbol, hasQuestionMark = false, arguments = emptyList(), annotations = emptyList()) name = Name.identifier("$this") @@ -118,7 +118,7 @@ class JvmSharedVariablesManager( name = Name.identifier("ObjectRef") }.apply { val irClass = this - typeParameters.add( + typeParameters += IrTypeParameterImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, SHARED_VARIABLE_ORIGIN, @@ -132,10 +132,9 @@ class JvmSharedVariablesManager( parent = irClass superTypes.add(irBuiltIns.anyNType) } - ) parent = refNamespaceClass refNamespaceClass.addMember(this) - superTypes.add(irBuiltIns.anyType) + superTypes += irBuiltIns.anyType thisReceiver = buildValueParameter { type = IrSimpleTypeImpl( symbol, diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index 78c5e24a929..d2b277b958d 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -138,7 +138,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : copyAttributes(info.reference) copyTypeParametersFrom(info.function) val functionNClass = context.ir.symbols.getJvmFunctionClass(info.arity + 1) - superTypes.add( + superTypes += IrSimpleTypeImpl( functionNClass, hasQuestionMark = false, @@ -147,7 +147,6 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : .map { makeTypeProjection(it, Variance.INVARIANT) }, annotations = emptyList() ) - ) addField(COROUTINE_LABEL_FIELD_NAME, context.irBuiltIns.intType) @@ -217,7 +216,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : Modality.FINAL, origin = JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE ).apply { - invokeSuspend.valueParameters.mapTo(valueParameters) { it.copyTo(this) } + valueParameters += invokeSuspend.valueParameters.map { it.copyTo(this) } }.also { it.copySuspendLambdaBodyFrom(irFunction, receiverField, fields) } } @@ -268,8 +267,8 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : modality: Modality = Modality.FINAL ): IrSimpleFunction = addFunction(function.name.asString(), function.returnType, modality).apply { - overriddenSymbols.add(function.symbol) - function.valueParameters.mapTo(valueParameters) { it.copyTo(this) } + overriddenSymbols += function.symbol + valueParameters += function.valueParameters.map { it.copyTo(this) } } // Invoke function in lambdas is responsible for @@ -394,7 +393,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : visibility = newVisibility }.also { irClass -> irClass.createImplicitParameterDeclarationWithWrappedDescriptor() - irClass.superTypes.add(defaultType) + irClass.superTypes += defaultType irClass.parent = parent } @@ -622,7 +621,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : copyTypeParameters(view.typeParameters) dispatchReceiverParameter = view.dispatchReceiverParameter?.copyTo(this) extensionReceiverParameter = view.extensionReceiverParameter?.copyTo(this) - view.valueParameters.mapTo(valueParameters) { it.copyTo(this) } + valueParameters += view.valueParameters.map { it.copyTo(this) } body = view.copyBodyTo(this) copyAttributes(view) } @@ -758,15 +757,15 @@ private fun IrFunction.suspendFunctionStub(context: JvmBackendContext): IrFuncti }.also { function -> function.parent = parent - function.annotations.addAll(annotations) + function.annotations += annotations function.metadata = metadata function.copyAttributes(this) function.copyTypeParametersFrom(this) if (origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE) { - function.overriddenSymbols - .addAll(overriddenSymbols.map { it.owner.suspendFunctionViewOrStub(context).symbol as IrSimpleFunctionSymbol }) + function.overriddenSymbols += + overriddenSymbols.map { it.owner.suspendFunctionViewOrStub(context).symbol as IrSimpleFunctionSymbol } } // Copy the value parameters and insert the continuation parameter. The continuation parameter diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt index f57a26fccec..0cdfcf611b5 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AdditionalClassAnnotationLowering.kt @@ -137,11 +137,10 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC irClass.hasAnnotation(FqName("java.lang.annotation.Documented")) ) return - irClass.annotations.add( + irClass.annotations += IrConstructorCallImpl.fromSymbolOwner( UNDEFINED_OFFSET, UNDEFINED_OFFSET, documentedConstructor.returnType, documentedConstructor.symbol, 0 ) - ) } private val annotationRetentionMap = mapOf( @@ -158,7 +157,7 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC val kotlinRetentionPolicy = kotlinRetentionPolicyName?.let { KotlinRetention.valueOf(it) } val javaRetentionPolicy = kotlinRetentionPolicy?.let { annotationRetentionMap[it] } ?: rpRuntime - irClass.annotations.add( + irClass.annotations += IrConstructorCallImpl.fromSymbolOwner( UNDEFINED_OFFSET, UNDEFINED_OFFSET, retentionConstructor.returnType, retentionConstructor.symbol, 0 ).apply { @@ -169,7 +168,6 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC ) ) } - ) } private val jvm6TargetMap = mutableMapOf( @@ -221,13 +219,12 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC ) } - irClass.annotations.add( + irClass.annotations += IrConstructorCallImpl.fromSymbolOwner( UNDEFINED_OFFSET, UNDEFINED_OFFSET, targetConstructor.returnType, targetConstructor.symbol, 0 ).apply { putValueArgument(0, vararg) } - ) // TODO } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt index cab81294377..b2f48548f83 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt @@ -205,8 +205,8 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass // For lambda classes, we move override from the `invoke` function to its bridge. This will allow us to avoid boxing // the return type of `invoke` in codegen, in case lambda's return type is primitive. if (method.name == OperatorNameConventions.INVOKE && irClass.origin == JvmLoweredDeclarationOrigin.LAMBDA_IMPL) { - target.overriddenSymbols.remove(method.symbol) - bridge.overriddenSymbols.add(method.symbol) + target.overriddenSymbols = target.overriddenSymbols.filter { it != method.symbol } + bridge.overriddenSymbols += method.symbol } signaturesToSkip.add(signature) @@ -227,7 +227,7 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass parent = this@copyRenamingTo.parent dispatchReceiverParameter = this@copyRenamingTo.dispatchReceiverParameter?.copyTo(this) extensionReceiverParameter = this@copyRenamingTo.extensionReceiverParameter?.copyTo(this) - valueParameters.addAll(this@copyRenamingTo.valueParameters.map { it.copyTo(this) }) + valueParameters = this@copyRenamingTo.valueParameters.map { it.copyTo(this) } } } @@ -267,8 +267,8 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass dispatchReceiverParameter = irClass.thisReceiver?.copyTo(this, type = irClass.defaultType) extensionReceiverParameter = signatureFunction.extensionReceiverParameter ?.copyWithTypeErasure(this) - signatureFunction.valueParameters.mapIndexed { i, param -> - valueParameters.add(i, param.copyWithTypeErasure(this)) + valueParameters = signatureFunction.valueParameters.map { param -> + param.copyWithTypeErasure(this) } } } @@ -304,12 +304,13 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass body = irBlockBody { // Change the parameter types to be Any? so that null checks are not generated. The checks // we insert here make them superfluous. + val newValueParameters = ArrayList(valueParameters) argumentsToCheck.forEach { val parameterType = it.type if (!parameterType.isNullable()) { val newParameter = it.copyTo(this@rewriteSpecialMethodBody, type = context.irBuiltIns.anyNType) variableMap.put(valueParameters[it.index], newParameter) - valueParameters[it.index] = newParameter + newValueParameters[it.index] = newParameter addParameterTypeCheck( newParameter, parameterType, @@ -318,6 +319,7 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass ) } } + valueParameters = newValueParameters // After the checks, insert the orignal method body. if (body is IrExpressionBody) { +irReturn((body as IrExpressionBody).expression) @@ -330,11 +332,13 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass } else { // If the signature of this method will be changed in the output to take a boxed argument instead of a primitive, // rewrite the argument so that code will be generated for a boxed argument and not a primitive. - for ((i, p) in valueParameters.withIndex()) { + valueParameters = valueParameters.mapIndexed { i, p -> if (AsmUtil.isPrimitive(context.typeMapper.mapType(p.type)) && ourSignature.argumentTypes[i].sort == Type.OBJECT) { val newParameter = p.copyTo(this, type = p.type.makeNullable()) variableMap[p] = newParameter - valueParameters[i] = newParameter + newParameter + } else { + p } } } @@ -408,9 +412,7 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass copyTypeParametersFrom(this@orphanedCopy) this@orphanedCopy.dispatchReceiverParameter?.let { dispatchReceiverParameter = it.copyTo(this) } this@orphanedCopy.extensionReceiverParameter?.let { extensionReceiverParameter = it.copyTo(this) } - this@orphanedCopy.valueParameters.forEachIndexed { index, param -> - valueParameters.add(index, param.copyTo(this)) - } + valueParameters = this@orphanedCopy.valueParameters.map { it.copyTo(this) } /* Do NOT copy overriddenSymbols */ } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt index 4a02d665186..ac677685632 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt @@ -57,7 +57,7 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla if (existingMethod != null) { // In the case that we find a defined method that matches the stub signature, we add the overridden symbols to that // defined method, so that bridge lowering can still generate correct bridge for that method - existingMethod.overriddenSymbols.addAll(member.overriddenSymbols) + existingMethod.overriddenSymbols += member.overriddenSymbols } else { irClass.declarations.add(member) } @@ -78,13 +78,11 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla }.apply { // Replace Function metadata with the data from class // Add the abstract function symbol to stub function for bridge lowering - overriddenSymbols.add(function.symbol) + overriddenSymbols = listOf(function.symbol) parent = irClass dispatchReceiverParameter = function.dispatchReceiverParameter?.copyWithSubstitution(this, substitutionMap) extensionReceiverParameter = function.extensionReceiverParameter?.copyWithSubstitution(this, substitutionMap) - for (parameter in function.valueParameters) { - valueParameters.add(parameter.copyWithSubstitution(this, substitutionMap)) - } + valueParameters = function.valueParameters.map { it.copyWithSubstitution(this, substitutionMap) } // Function body consist only of throwing UnsupportedOperationException statement body = context.createIrBuilder(function.symbol).irBlockBody { +irThrow( diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt index e937314d3d3..e7131056c46 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt @@ -119,7 +119,7 @@ private class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringP addValueParameter( "\$enum\$ordinal", context.irBuiltIns.intType, JvmLoweredDeclarationOrigin.ENUM_CONSTRUCTOR_SYNTHETIC_PARAMETER ) - declaration.valueParameters.mapTo(valueParameters) { param -> + valueParameters += declaration.valueParameters.map { param -> param.copyTo(this, index = param.index + 2).also { newParam -> loweredEnumConstructorParameters[param.symbol] = newParam } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FileClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FileClassLowering.kt index 24b2d4f1816..1909d9d693f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FileClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FileClassLowering.kt @@ -111,7 +111,7 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa isFun = false ).apply { descriptor.bind(this) - superTypes.add(context.irBuiltIns.anyType) + superTypes += context.irBuiltIns.anyType parent = irFile declarations.addAll(fileClassMembers) createImplicitParameterDeclarationWithWrappedDescriptor() diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt index 557afbad13e..bd132f70f1c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt @@ -81,7 +81,7 @@ private class FunctionNVarargBridgeLowering(val context: JvmBackendContext) : // Fix super class val superType = bigArityFunctionSuperTypes.single() - declaration.superTypes.remove(superType) + declaration.superTypes -= superType declaration.superTypes += context.ir.symbols.functionN.typeWith( (superType.arguments.last() as IrTypeProjection).type ) @@ -90,7 +90,7 @@ private class FunctionNVarargBridgeLowering(val context: JvmBackendContext) : val invokeFunction = declaration.functions.single { it.name.asString() == "invoke" && it.valueParameters.size == superType.arguments.size - if (it.isSuspend) 0 else 1 } - invokeFunction.overriddenSymbols.clear() + invokeFunction.overriddenSymbols = emptyList() declaration.addBridge(invokeFunction, functionNInvokeFun.owner) return declaration diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt index bd9a5133e93..62917f277b6 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/GenerateMultifileFacades.kt @@ -123,7 +123,7 @@ private fun generateMultifileFacades( } if (shouldGeneratePartHierarchy) { val superClass = modifyMultifilePartsForHierarchy(context, partClasses) - superTypes.add(superClass.typeWith()) + superTypes += superClass.typeWith() addConstructor { visibility = Visibilities.PRIVATE @@ -165,8 +165,7 @@ private fun modifyMultifilePartsForHierarchy(context: JvmBackendContext, unsorte klass.modality = Modality.OPEN klass.visibility = JavaVisibilities.PACKAGE_VISIBILITY - klass.superTypes.clear() - klass.superTypes.add(superClass.typeWith()) + klass.superTypes = listOf(superClass.typeWith()) klass.addConstructor { isPrimary = true @@ -211,8 +210,7 @@ private fun IrSimpleFunction.createMultifileDelegateIfNeeded( if (shouldGeneratePartHierarchy) { function.body = null function.origin = IrDeclarationOrigin.FAKE_OVERRIDE - function.overriddenSymbols.clear() - function.overriddenSymbols.add(symbol) + function.overriddenSymbols = listOf(symbol) } else { function.body = context.createIrBuilder(function.symbol).irBlockBody { +irReturn(irCall(this@createMultifileDelegateIfNeeded).also { call -> diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt index 51c35148ffa..cae41c764fb 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt @@ -70,7 +70,7 @@ private class InheritedDefaultMethodsOnClassesLowering(val context: JvmBackendCo // Here we use the same logic as the delegation itself (`getTargetForRedirection`) to determine // if the overriden symbol has been, or will be, replaced and patch it accordingly. override fun visitSimpleFunction(declaration: IrSimpleFunction) { - declaration.overriddenSymbols.replaceAll { symbol -> + declaration.overriddenSymbols = declaration.overriddenSymbols.map { symbol -> if (symbol.owner.findInterfaceImplementation() != null) context.declarationFactory.getDefaultImplsRedirection(symbol.owner).symbol else symbol diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt index 78963f68ab4..6d864d02693 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmDefaultConstructorLowering.kt @@ -53,7 +53,7 @@ private class JvmDefaultConstructorLowering(val context: JvmBackendContext) : Cl visibility = primaryConstructor.visibility }.apply { val irBuilder = context.createIrBuilder(this.symbol, startOffset, endOffset) - primaryConstructor.annotations.mapTo(annotations) { it.deepCopyWithSymbols(this) } + annotations += primaryConstructor.annotations.map { it.deepCopyWithSymbols(this) } body = irBuilder.irBlockBody { +irDelegatingConstructorCall(primaryConstructor).apply { passTypeArgumentsFrom(irClass) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOverloadsAnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOverloadsAnnotationLowering.kt index c56d6917464..68cef413d62 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOverloadsAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOverloadsAnnotationLowering.kt @@ -165,11 +165,11 @@ private class JvmOverloadsAnnotationLowering(val context: JvmBackendContext) : C } res.parent = oldFunction.parent - res.annotations.addAll(oldFunction.annotations.map { it.deepCopyWithSymbols(res) }) + res.annotations += oldFunction.annotations.map { it.deepCopyWithSymbols(res) } res.copyTypeParametersFrom(oldFunction) res.dispatchReceiverParameter = oldFunction.dispatchReceiverParameter?.copyTo(res) res.extensionReceiverParameter = oldFunction.extensionReceiverParameter?.copyTo(res) - res.valueParameters.addAll(res.generateNewValueParameters(oldFunction, numDefaultParametersToExpect)) + res.valueParameters += res.generateNewValueParameters(oldFunction, numDefaultParametersToExpect) return res } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt index 58b7f2a3ff3..ffa08346bb0 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt @@ -83,7 +83,7 @@ class JvmPropertiesLowering(private val context: JvmBackendContext) : IrElementT body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET) parent = declaration.parent - annotations.addAll(declaration.annotations) + annotations = declaration.annotations metadata = declaration.metadata } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt index 80bf6933ad3..9f6b4452c05 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStaticAnnotationLowering.kt @@ -120,9 +120,9 @@ private class CompanionObjectJvmStaticLowering(val context: JvmBackendContext) : parent = irClass copyTypeParametersFrom(target) target.extensionReceiverParameter?.let { extensionReceiverParameter = it.copyTo(this) } - target.valueParameters.mapTo(valueParameters) { it.copyTo(this) } + valueParameters = target.valueParameters.map { it.copyTo(this) } - target.annotations.mapTo(annotations) { it.deepCopyWithSymbols() } + annotations = target.annotations.map { it.deepCopyWithSymbols() } body = createProxyBody(target, this, companion) } @@ -241,7 +241,7 @@ private class MakeCallsStatic( newDescriptor.bind(it) it.parent = parent it.correspondingPropertySymbol = correspondingPropertySymbol - it.annotations.addAll(annotations) + it.annotations += annotations it.copyParameterDeclarationsFrom(this) it.dispatchReceiverParameter = null } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt index 564794b1d76..fad89fcc1cc 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt @@ -123,10 +123,9 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class modality = Modality.OPEN origin = JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE }.apply { - overriddenSymbols.add(method.symbol) + overriddenSymbols += method.symbol dispatchReceiverParameter = thisReceiver!!.copyTo(this) - for (parameter in method.valueParameters) - valueParameters.add(parameter.copyTo(this)) + valueParameters = method.valueParameters.map { it.copyTo(this) } body = context.createIrBuilder(symbol, startOffset, endOffset).run { irExprBody(buildBody(listOf(dispatchReceiverParameter!!) + valueParameters)) } @@ -139,10 +138,9 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class visibility = method.visibility origin = IrDeclarationOrigin.FAKE_OVERRIDE }.apply { - overriddenSymbols.add(method.symbol) + overriddenSymbols += method.symbol dispatchReceiverParameter = thisReceiver!!.copyTo(this) - for (parameter in method.valueParameters) - valueParameters.add(parameter.copyTo(this)) + valueParameters = method.valueParameters.map { it.copyTo(this) } } private class PropertyReferenceKind( diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt index a56402dd15f..3839711d258 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt @@ -156,8 +156,8 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle accessor.metadata = declaration.metadata declaration.safeAs()?.metadata = null accessor.annotations += declaration.annotations - declaration.annotations.clear() - declaration.valueParameters.forEach { it.annotations.clear() } + declaration.annotations = emptyList() + declaration.valueParameters.forEach { it.annotations = emptyList() } } } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt index 621b2fdc646..8e79e9d8e4f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/ToArrayLowering.kt @@ -95,7 +95,7 @@ private class ToArrayLowering(private val context: JvmBackendContext) : ClassLow irFunction.parent = irClass typeParameter.parent = irFunction - irFunction.typeParameters.add(typeParameter) + irFunction.typeParameters += typeParameter val dispatchReceiverParameterDescriptor = WrappedValueParameterDescriptor() irFunction.dispatchReceiverParameter = IrValueParameterImpl( @@ -112,7 +112,7 @@ private class ToArrayLowering(private val context: JvmBackendContext) : ClassLow parent = irFunction } val valueParameterDescriptor = WrappedValueParameterDescriptor() - irFunction.valueParameters.add( + irFunction.valueParameters += IrValueParameterImpl( UNDEFINED_OFFSET, UNDEFINED_OFFSET, JvmLoweredDeclarationOrigin.TO_ARRAY, @@ -127,7 +127,6 @@ private class ToArrayLowering(private val context: JvmBackendContext) : ClassLow valueParameterDescriptor.bind(this) parent = irFunction } - ) irFunction.body = context.createIrBuilder(irFunction.symbol).irBlockBody { +irReturn( diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt index 5505e693202..57865ab6317 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/TypeAliasAnnotationMethodsLowering.kt @@ -50,7 +50,7 @@ class TypeAliasAnnotationMethodsLowering(val context: CommonBackendContext) : origin = JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_TYPEALIAS_ANNOTATIONS }.apply { body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET) - annotations.addAll(alias.annotations) + annotations += alias.annotations metadata = alias.metadata } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt index 90e632f204c..493bd3289f1 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt @@ -146,8 +146,9 @@ class MemoizedInlineClassReplacements { val parameterMap = mutableMapOf() val replacement = buildReplacement(function) { metadata = function.metadata - overriddenSymbols.addAll(overrides) + overriddenSymbols += overrides + val newValueParameters = ArrayList() for ((index, parameter) in function.explicitParameters.withIndex()) { val name = if (parameter == function.extensionReceiverParameter) Name.identifier("\$receiver") else parameter.name val newParameter: IrValueParameter @@ -156,13 +157,14 @@ class MemoizedInlineClassReplacements { dispatchReceiverParameter = newParameter } else { newParameter = parameter.copyTo(this, index = index - 1, name = name, defaultValue = null) - valueParameters.add(newParameter) + newValueParameters += newParameter } // Assuming that constructors and non-override functions are always replaced with the unboxed // equivalent, deep-copying the value here is unnecessary. See `JvmInlineClassLowering`. newParameter.defaultValue = parameter.defaultValue?.patchDeclarationParents(this) parameterMap[parameter.symbol] = newParameter } + valueParameters = newValueParameters } return IrReplacementFunction(replacement, parameterMap) } @@ -176,7 +178,8 @@ class MemoizedInlineClassReplacements { function.metadata = null } - for ((index, parameter) in function.explicitParameters.withIndex()) { + + valueParameters += function.explicitParameters.mapIndexed { index, parameter -> val name = when (parameter) { function.dispatchReceiverParameter -> Name.identifier("arg$index") function.extensionReceiverParameter -> Name.identifier("\$this\$${function.name}") @@ -188,10 +191,12 @@ class MemoizedInlineClassReplacements { else -> parameter.origin } val newParameter = parameter.copyTo(this, index = index, name = name, defaultValue = null, origin = parameterOrigin) - valueParameters.add(newParameter) + valueParameters += newParameter // See comment next to a similar line above. newParameter.defaultValue = parameter.defaultValue?.patchDeclarationParents(this) parameterMap[parameter.symbol] = newParameter + + newParameter } } return IrReplacementFunction(replacement, parameterMap) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AnnotationGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AnnotationGenerator.kt index 7a24f55cb98..8e11e3ab112 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AnnotationGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AnnotationGenerator.kt @@ -40,8 +40,10 @@ class AnnotationGenerator(context: GeneratorContext) : IrElementVisitorVoid { declaration.descriptor.backingField else declaration.descriptor - annotatedDescriptor?.annotations?.mapNotNullTo(declaration.annotations) { - constantValueGenerator.generateAnnotationConstructorCall(it) + if (annotatedDescriptor != null) { + declaration.annotations += annotatedDescriptor.annotations.mapNotNull { + constantValueGenerator.generateAnnotationConstructorCall(it) + } } } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt index 041b4ba2965..67c1427a373 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt @@ -87,7 +87,7 @@ class ClassGenerator( ).buildWithScope { irClass -> declarationGenerator.generateGlobalTypeParametersDeclarations(irClass, classDescriptor.declaredTypeParameters) - classDescriptor.typeConstructor.supertypes.mapTo(irClass.superTypes) { + irClass.superTypes = classDescriptor.typeConstructor.supertypes.map { it.toIrType() } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt index 019af2df6c0..9958285952a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt @@ -126,7 +126,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator { from: List, declareTypeParameter: (Int, Int, TypeParameterDescriptor) -> IrTypeParameter ) { - from.mapTo(irTypeParametersOwner.typeParameters) { typeParameterDescriptor -> + irTypeParametersOwner.typeParameters += from.map { typeParameterDescriptor -> val ktTypeParameterDeclaration = DescriptorToSourceUtils.getSourceFromDescriptor(typeParameterDescriptor) val startOffset = ktTypeParameterDeclaration.startOffsetOrUndefined val endOffset = ktTypeParameterDeclaration.endOffsetOrUndefined diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt index 4abcf024f7b..7e0369aaa15 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt @@ -286,7 +286,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio val bodyGenerator = createBodyGenerator(irFunction.symbol) // Declare all the value parameters up first. - functionDescriptor.valueParameters.mapTo(irFunction.valueParameters) { valueParameterDescriptor -> + irFunction.valueParameters += functionDescriptor.valueParameters.map { valueParameterDescriptor -> val ktParameter = DescriptorToSourceUtils.getSourceFromDescriptor(valueParameterDescriptor) as? KtParameter declareParameter(valueParameterDescriptor, ktParameter, irFunction) } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ModuleGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ModuleGenerator.kt index 0081e43fd87..87b7b50bdb8 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ModuleGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ModuleGenerator.kt @@ -71,7 +71,9 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator { for (ktAnnotationEntry in ktFile.annotationEntries) { val annotationDescriptor = getOrFail(BindingContext.ANNOTATION, ktAnnotationEntry) - irFile.annotations.addIfNotNull(constantValueGenerator.generateAnnotationConstructorCall(annotationDescriptor)) + constantValueGenerator.generateAnnotationConstructorCall(annotationDescriptor)?.let { + irFile.annotations += it + } } for (ktDeclaration in ktFile.declarations) { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt index 420be9931fe..93e9d33ec22 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt @@ -379,7 +379,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St irAdapterFun.dispatchReceiverParameter = null irAdapterFun.extensionReceiverParameter = null - ktExpectedParameterTypes.mapIndexedTo(irAdapterFun.valueParameters) { index, ktExpectedParameterType -> + irAdapterFun.valueParameters += ktExpectedParameterTypes.mapIndexed { index, ktExpectedParameterType -> val adapterValueParameterDescriptor = WrappedValueParameterDescriptor() context.symbolTable.declareValueParameter( startOffset, endOffset, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrAnnotationContainer.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrAnnotationContainer.kt index f167f80fb2b..00a338bb392 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrAnnotationContainer.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrAnnotationContainer.kt @@ -12,5 +12,5 @@ interface IrAnnotationContainer { } interface IrMutableAnnotationContainer: IrAnnotationContainer { - override val annotations: MutableList + override var annotations: List } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt index 65a20c8fd3e..eb58b3c6d63 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt @@ -41,7 +41,7 @@ interface IrClass : val isExpect: Boolean val isFun: Boolean - val superTypes: MutableList + var superTypes: List var thisReceiver: IrValueParameter? } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclaration.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclaration.kt index d308113e0f5..49537a83b34 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclaration.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclaration.kt @@ -47,7 +47,7 @@ interface IrSymbolDeclaration : IrDeclaration, IrSymbolOwner { } interface IrOverridableDeclaration : IrDeclaration { - val overriddenSymbols: MutableList + var overriddenSymbols: List } interface IrDeclarationWithVisibility : IrDeclaration { 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 7400ad2fd4c..85cb64f30de 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 @@ -37,7 +37,7 @@ interface IrFunction : var dispatchReceiverParameter: IrValueParameter? var extensionReceiverParameter: IrValueParameter? - val valueParameters: MutableList + var valueParameters: List var body: IrBody? diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrTypeParametersContainer.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrTypeParametersContainer.kt index 8395c140df4..947849fd7a6 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrTypeParametersContainer.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrTypeParametersContainer.kt @@ -17,5 +17,5 @@ package org.jetbrains.kotlin.ir.declarations interface IrTypeParametersContainer : IrDeclaration, IrDeclarationParent { - val typeParameters: MutableList + var typeParameters: List } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt index cd6eb0de4bd..4afabeb9ef4 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt @@ -24,11 +24,12 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.transform +import org.jetbrains.kotlin.ir.util.mapOptimized import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal -import org.jetbrains.kotlin.utils.SmartList +import kotlin.collections.ArrayList class IrClassImpl( startOffset: Int, @@ -81,9 +82,9 @@ class IrClassImpl( override val declarations: MutableList = ArrayList() - override val typeParameters: MutableList = SmartList() + override var typeParameters: List = emptyList() - override val superTypes: MutableList = SmartList() + override var superTypes: List = emptyList() override var metadata: MetadataSource? = null @@ -100,7 +101,7 @@ class IrClassImpl( override fun transformChildren(transformer: IrElementTransformer, data: D) { thisReceiver = thisReceiver?.transform(transformer, data) - typeParameters.transform { it.transform(transformer, data) } + typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) } declarations.transform { it.transform(transformer, data) } } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrDeclarationBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrDeclarationBase.kt index bf9cae252ae..26936ece3b7 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrDeclarationBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrDeclarationBase.kt @@ -39,7 +39,7 @@ abstract class IrDeclarationBase( _parent = v } - override val annotations: MutableList = ArrayList() + override var annotations: List = emptyList() override val metadata: MetadataSource? get() = null diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt index 54c0bd8fbf6..ab789223de2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt @@ -84,7 +84,7 @@ class IrFieldImpl( override var correspondingPropertySymbol: IrPropertySymbol? = null - override val overriddenSymbols: MutableList = mutableListOf() + override var overriddenSymbols: List = emptyList() override var metadata: MetadataSource.Property? = null diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt index 918bdedd8fb..55d61b48a86 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt @@ -55,7 +55,7 @@ class IrFileImpl( override val declarations: MutableList = ArrayList() - override val annotations: MutableList = ArrayList() + override var annotations: List = emptyList() override var metadata: MetadataSource.File? = null diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionBase.kt index b5aef66d125..1da2ecd986c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionBase.kt @@ -20,11 +20,10 @@ import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.types.IrType -import org.jetbrains.kotlin.ir.util.transform +import org.jetbrains.kotlin.ir.util.mapOptimized import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.utils.SmartList abstract class IrFunctionBase( startOffset: Int, @@ -48,11 +47,11 @@ abstract class IrFunctionBase( field } - override val typeParameters: MutableList = SmartList() + override var typeParameters: List = emptyList() override var dispatchReceiverParameter: IrValueParameter? = null override var extensionReceiverParameter: IrValueParameter? = null - override val valueParameters: MutableList = ArrayList() + override var valueParameters: List = emptyList() final override var body: IrBody? = null @@ -69,11 +68,12 @@ abstract class IrFunctionBase( } override fun transformChildren(transformer: IrElementTransformer, data: D) { - typeParameters.transform { it.transform(transformer, data) } + + typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) } dispatchReceiverParameter = dispatchReceiverParameter?.transform(transformer, data) extensionReceiverParameter = extensionReceiverParameter?.transform(transformer, data) - valueParameters.transform { it.transform(transformer, data) } + valueParameters = valueParameters.mapOptimized { it.transform(transformer, data) } body = body?.transform(transformer, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt index faa6f29c619..5f483c1adbb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.utils.SmartList class IrFunctionImpl( startOffset: Int, @@ -64,7 +63,7 @@ class IrFunctionImpl( override val descriptor: FunctionDescriptor = symbol.descriptor - override val overriddenSymbols: MutableList = SmartList() + override var overriddenSymbols: List = emptyList() override var attributeOwnerId: IrAttributeContainer = this override var correspondingPropertySymbol: IrPropertySymbol? = null diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeAliasImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeAliasImpl.kt index 383de12d769..924d6c5e370 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeAliasImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeAliasImpl.kt @@ -11,13 +11,11 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrTypeAlias import org.jetbrains.kotlin.ir.declarations.IrTypeParameter import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol -import org.jetbrains.kotlin.ir.symbols.impl.IrTypeAliasSymbolImpl import org.jetbrains.kotlin.ir.types.IrType -import org.jetbrains.kotlin.ir.util.transform +import org.jetbrains.kotlin.ir.util.mapOptimized import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.utils.SmartList class IrTypeAliasImpl( startOffset: Int, @@ -39,7 +37,7 @@ class IrTypeAliasImpl( override val descriptor: TypeAliasDescriptor get() = symbol.descriptor - override val typeParameters: MutableList = SmartList() + override var typeParameters: List = emptyList() override fun accept(visitor: IrElementVisitor, data: D): R = visitor.visitTypeAlias(this, data) @@ -49,7 +47,7 @@ class IrTypeAliasImpl( } override fun transformChildren(transformer: IrElementTransformer, data: D) { - typeParameters.transform { it.transform(transformer, data) } + typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) } } companion object { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt index 1222fc0d2b3..57dd7a9a07f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyClass.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator import org.jetbrains.kotlin.ir.util.transform +import org.jetbrains.kotlin.ir.util.mapOptimized import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name @@ -92,13 +93,13 @@ class IrLazyClass( } } - override val typeParameters: MutableList by lazy { + override var typeParameters: List by lazyVar { descriptor.declaredTypeParameters.mapTo(arrayListOf()) { stubGenerator.generateOrGetTypeParameterStub(it) } } - override val superTypes: MutableList by lazy { + override var superTypes: List by lazyVar { typeTranslator.buildWithScope(this) { // TODO get rid of code duplication, see ClassGenerator#generateClass descriptor.typeConstructor.supertypes.mapNotNullTo(arrayListOf()) { @@ -120,7 +121,7 @@ class IrLazyClass( override fun transformChildren(transformer: IrElementTransformer, data: D) { thisReceiver = thisReceiver?.transform(transformer, data) - typeParameters.transform { it.transform(transformer, data) } + typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) } declarations.transform { it.transform(transformer, data) } } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt index c7da63c237e..bf1bb6add71 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyConstructor.kt @@ -58,7 +58,7 @@ class IrLazyConstructor( typeTranslator = TypeTranslator ) - override val typeParameters: MutableList by lazy { + override var typeParameters: List by lazyVar { typeTranslator.buildWithScope(this) { stubGenerator.symbolTable.withScope(descriptor) { val classTypeParametersCount = descriptor.constructedClass.original.declaredTypeParameters.size diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt index e68dc688979..ad9b88d4d9d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyDeclarationBase.kt @@ -49,7 +49,7 @@ abstract class IrLazyDeclarationBase( createLazyParent()!! } - override val annotations: MutableList by lazy { + override var annotations: List by lazyVar { descriptor.annotations.mapNotNull(typeTranslator.constantValueGenerator::generateAnnotationConstructorCall).toMutableList() } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyField.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyField.kt index 85612375f65..b6685f8666f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyField.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyField.kt @@ -63,7 +63,7 @@ class IrLazyField( symbol.bind(this) } - override val annotations: MutableList by lazy { + override var annotations: List by lazyVar { descriptor.backingField?.annotations ?.mapNotNullTo(mutableListOf(), typeTranslator.constantValueGenerator::generateAnnotationConstructorCall) ?: mutableListOf() @@ -71,7 +71,7 @@ class IrLazyField( override val descriptor: PropertyDescriptor = symbol.descriptor - override val overriddenSymbols: MutableList by lazy { + override var overriddenSymbols: List by lazyVar { symbol.descriptor.overriddenDescriptors.map { stubGenerator.generateFieldStub(it.original).symbol }.toMutableList() diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt index 54c580fa9ab..b3182327f1c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunction.kt @@ -64,7 +64,7 @@ class IrLazyFunction( override val descriptor: FunctionDescriptor = symbol.descriptor - override val typeParameters: MutableList by lazy { + override var typeParameters: List by lazyVar { typeTranslator.buildWithScope(this) { stubGenerator.symbolTable.withScope(descriptor) { val propertyIfAccessor = descriptor.propertyIfAccessor @@ -82,7 +82,7 @@ class IrLazyFunction( } - override val overriddenSymbols: MutableList by lazy { + override var overriddenSymbols: List by lazyVar { descriptor.overriddenDescriptors.mapTo(arrayListOf()) { stubGenerator.generateFunctionStub(it.original).symbol } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunctionBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunctionBase.kt index e08c8769455..7dea34945d7 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunctionBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyFunctionBase.kt @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator -import org.jetbrains.kotlin.ir.util.transform +import org.jetbrains.kotlin.ir.util.mapOptimized import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name @@ -48,7 +48,7 @@ abstract class IrLazyFunctionBase( } } - override val valueParameters: MutableList by lazy { + override var valueParameters: List by lazyVar { typeTranslator.buildWithScope(this) { descriptor.valueParameters.mapTo(arrayListOf()) { stubGenerator.generateValueParameterStub(it).apply { parent = this@IrLazyFunctionBase } @@ -75,11 +75,11 @@ abstract class IrLazyFunctionBase( } override fun transformChildren(transformer: IrElementTransformer, data: D) { - typeParameters.transform { it.transform(transformer, data) } + typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) } dispatchReceiverParameter = dispatchReceiverParameter?.transform(transformer, data) extensionReceiverParameter = extensionReceiverParameter?.transform(transformer, data) - valueParameters.transform { it.transform(transformer, data) } + valueParameters = valueParameters.mapOptimized { it.transform(transformer, data) } body = body?.transform(transformer, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt index 2265c0bb92d..822823cf28f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyTypeAlias.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator -import org.jetbrains.kotlin.ir.util.transform +import org.jetbrains.kotlin.ir.util.mapOptimized import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.name.Name @@ -40,7 +40,7 @@ class IrLazyTypeAlias( override val descriptor: TypeAliasDescriptor get() = symbol.descriptor - override val typeParameters: MutableList by lazy { + override var typeParameters: List by lazyVar { descriptor.declaredTypeParameters.mapTo(arrayListOf()) { stubGenerator.generateOrGetTypeParameterStub(it) } @@ -60,6 +60,6 @@ class IrLazyTypeAlias( } override fun transformChildren(transformer: IrElementTransformer, data: D) { - typeParameters.transform { it.transform(transformer, data) } + typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) } } } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt index 429c9b04df2..6b7b072aeff 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt @@ -63,7 +63,7 @@ class IrBuiltIns( packageFragment.declarations += operator descriptor.bind(operator) - valueParameterTypes.mapIndexedTo(operator.valueParameters) { i, t -> + operator.valueParameters = valueParameterTypes.mapIndexed { i, t -> val valueParameterDescriptor = WrappedValueParameterDescriptor() val valueParameterSymbol = IrValueParameterSymbolImpl(valueParameterDescriptor) IrBuiltInOperatorValueParameter(valueParameterSymbol, i, t).apply { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrOperators.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrOperators.kt index 972a543dff7..a74c525f604 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrOperators.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrOperators.kt @@ -54,7 +54,7 @@ class IrBuiltInOperator( return visitor.visitSimpleFunction(this, data) } - override val overriddenSymbols: MutableList = SmartList() + override var overriddenSymbols: List = emptyList() override var attributeOwnerId: IrAttributeContainer = this override val mangle: String get() = "operator#$name@$suffix" diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt index 31074016cc2..1fe5ece4ff9 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTreeWithSymbols.kt @@ -141,7 +141,7 @@ open class DeepCopyIrTreeWithSymbols( ).apply { transformAnnotations(declaration) copyTypeParametersFrom(declaration) - declaration.superTypes.mapTo(superTypes) { + superTypes = declaration.superTypes.map { it.remapType() } thisReceiver = declaration.thisReceiver?.transform() @@ -165,7 +165,7 @@ open class DeepCopyIrTreeWithSymbols( isFakeOverride = declaration.isFakeOverride, isOperator = declaration.isOperator ).apply { - declaration.overriddenSymbols.mapTo(overriddenSymbols) { + overriddenSymbols = declaration.overriddenSymbols.map { symbolRemapper.getReferencedFunction(it) as IrSimpleFunctionSymbol } copyAttributes(declaration) @@ -196,13 +196,13 @@ open class DeepCopyIrTreeWithSymbols( dispatchReceiverParameter = declaration.dispatchReceiverParameter?.transform() extensionReceiverParameter = declaration.extensionReceiverParameter?.transform() returnType = typeRemapper.remapType(declaration.returnType) - declaration.valueParameters.transformTo(valueParameters) + valueParameters = declaration.valueParameters.transform() body = declaration.body?.transform() } } private fun IrMutableAnnotationContainer.transformAnnotations(declaration: IrAnnotationContainer) { - declaration.annotations.transformTo(annotations) + annotations = declaration.annotations.transform() } override fun visitProperty(declaration: IrProperty): IrProperty = @@ -243,7 +243,7 @@ open class DeepCopyIrTreeWithSymbols( isFakeOverride = declaration.isFakeOverride ).apply { transformAnnotations(declaration) - declaration.overriddenSymbols.mapTo(overriddenSymbols) { + overriddenSymbols = declaration.overriddenSymbols.map { symbolRemapper.getReferencedField(it) } initializer = declaration.initializer?.transform() @@ -318,7 +318,7 @@ open class DeepCopyIrTreeWithSymbols( } private fun IrTypeParametersContainer.copyTypeParametersFrom(other: IrTypeParametersContainer) { - other.typeParameters.mapTo(this.typeParameters) { + this.typeParameters = other.typeParameters.map { copyTypeParameter(it) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/overrides.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/overrides.kt index 24299c5fac2..e082d7e1751 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/overrides.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/overrides.kt @@ -27,7 +27,7 @@ fun generateOverriddenFunctionSymbols( declaration: IrSimpleFunction, symbolTable: SymbolTable ) { - declaration.descriptor.overriddenDescriptors.mapTo(declaration.overriddenSymbols) { + declaration.overriddenSymbols = declaration.descriptor.overriddenDescriptors.map { symbolTable.referenceSimpleFunction(it.original) } } @@ -49,7 +49,7 @@ fun generateOverriddenFieldSymbols( symbolTable: SymbolTable, hasBackingField: (PropertyDescriptor) -> Boolean ) { - declaration.descriptor.overriddenDescriptors.mapNotNullTo(declaration.overriddenSymbols) { + declaration.overriddenSymbols = declaration.descriptor.overriddenDescriptors.mapNotNull { if (hasBackingField(it)) { symbolTable.referenceField(it.original) } else null diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/transform.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/transform.kt index ae087cd7682..75b63903831 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/transform.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/transform.kt @@ -63,3 +63,18 @@ fun IrDeclarationContainer.transformDeclarationsFlat(transformation: (IrDeclarat transformed } } + +/** + * Similar to `map`. Return the same List instance if no element instances have changed. + */ +internal inline fun List.mapOptimized(transformation: (T) -> IrElement): List { + var result: ArrayList? = null + for ((i, item) in withIndex()) { + val transformed = transformation(item) as T + if (transformed !== item && result == null) { + result = ArrayList(this) + } + result?.set(i, transformed) + } + return result ?: this +} \ No newline at end of file diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileDeserializer.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileDeserializer.kt index 15ab54ca9ff..11f334eae9c 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileDeserializer.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/IrFileDeserializer.kt @@ -908,7 +908,7 @@ abstract class IrFileDeserializer( proto.coordinates.startOffset, proto.coordinates.endOffset, deserializeIrDeclarationOrigin(proto.origin) ) - result.annotations.addAll(deserializeAnnotations(proto.annotationList)) + result.annotations += deserializeAnnotations(proto.annotationList) result.parent = parentsStack.peek()!! return result } @@ -990,9 +990,9 @@ abstract class IrFileDeserializer( thisReceiver = deserializeIrValueParameter(proto.thisReceiver) - proto.typeParameters.typeParameterList.mapTo(typeParameters) { deserializeIrTypeParameter(it) } + typeParameters = proto.typeParameters.typeParameterList.map { deserializeIrTypeParameter(it) } - proto.superTypeList.mapTo(superTypes) { deserializeIrType(it) } + superTypes = proto.superTypeList.map { deserializeIrType(it) } (descriptor as? WrappedClassDescriptor)?.bind(this) } @@ -1011,7 +1011,7 @@ abstract class IrFileDeserializer( origin ) }.usingParent { - proto.typeParameters.typeParameterList.mapTo(typeParameters) { + typeParameters = proto.typeParameters.typeParameterList.map { deserializeIrTypeParameter(it) } @@ -1024,8 +1024,8 @@ abstract class IrFileDeserializer( block: (IrFunctionSymbol, Int, Int, IrDeclarationOrigin) -> T ) = withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin -> block(symbol as IrFunctionSymbol, startOffset, endOffset, origin).usingParent { - proto.typeParameters.typeParameterList.mapTo(typeParameters) { deserializeIrTypeParameter(it) } - proto.valueParameterList.mapTo(valueParameters) { deserializeIrValueParameter(it) } + typeParameters = proto.typeParameters.typeParameterList.map { deserializeIrTypeParameter(it) } + valueParameters = proto.valueParameterList.map { deserializeIrValueParameter(it) } if (proto.hasDispatchReceiver()) dispatchReceiverParameter = deserializeIrValueParameter(proto.dispatchReceiver) if (proto.hasExtensionReceiver()) @@ -1060,7 +1060,7 @@ abstract class IrFileDeserializer( isOperator = proto.isOperator ) }.apply { - proto.overriddenList.mapTo(overriddenSymbols) { deserializeIrSymbol(it) as IrSimpleFunctionSymbol } + overriddenSymbols = proto.overriddenList.map { deserializeIrSymbol(it) as IrSimpleFunctionSymbol } (descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this) } diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt index c6c23580618..4d486462da3 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt @@ -410,7 +410,7 @@ abstract class KotlinIrLinker( fun deserializeFileImplicitDataIfFirstUse() { annotations?.let { - file.annotations.addAll(deserializeAnnotations(it)) + file.annotations += deserializeAnnotations(it) annotations = null } } diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt index 820fee8b1e8..a3490496cd5 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/GeneratorHelpers.kt @@ -44,7 +44,7 @@ interface IrBuilderExtension { private fun IrClass.declareSimpleFunctionWithExternalOverrides(descriptor: FunctionDescriptor): IrSimpleFunction { return compilerContext.symbolTable.declareSimpleFunction(startOffset, endOffset, SERIALIZABLE_PLUGIN_ORIGIN, descriptor) .also { f -> - descriptor.overriddenDescriptors.mapTo(f.overriddenSymbols) { + f.overriddenSymbols = descriptor.overriddenDescriptors.map { compilerContext.symbolTable.referenceSimpleFunction(it.original) } } @@ -357,16 +357,15 @@ interface IrBuilderExtension { if (!overwriteValueParameters) assert(valueParameters.isEmpty()) - else - valueParameters.clear() - valueParameters.addAll(descriptor.valueParameters.map { it.irValueParameter() }) + + valueParameters = descriptor.valueParameters.map { it.irValueParameter() } assert(typeParameters.isEmpty()) if (copyTypeParameters) copyTypeParamsFromDescriptor() } fun IrFunction.copyTypeParamsFromDescriptor() { - descriptor.typeParameters.mapTo(typeParameters) { + typeParameters += descriptor.typeParameters.map { IrTypeParameterImpl( startOffset, endOffset, SERIALIZABLE_PLUGIN_ORIGIN, diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializableCompanionIrGenerator.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializableCompanionIrGenerator.kt index 4d50e45260e..aa0038fb358 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializableCompanionIrGenerator.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializableCompanionIrGenerator.kt @@ -76,7 +76,7 @@ class SerializableCompanionIrGenerator( ) } - irSerializableClass.annotations.add(annotationCtorCall) + irSerializableClass.annotations += annotationCtorCall } override fun generateSerializerGetter(methodDescriptor: FunctionDescriptor) {