From 0691595ed29806bd994fc481f92e757f3bad20d1 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 6 Jul 2020 22:22:20 +0200 Subject: [PATCH] IR: remove deprecated constructor of IrValueParameterImpl --- .../kotlin/backend/common/ir/IrUtils.kt | 12 ++++++---- .../backend/js/lower/BridgesConstruction.kt | 12 ++-------- .../declarations/impl/IrValueParameterImpl.kt | 22 ------------------ .../lazy/IrLazyDeclarationBase.kt | 7 +++--- .../ir/descriptors/IrFunctionFactory.kt | 21 +++++------------ .../ir/util/DeclarationStubGenerator.kt | 9 ++++---- .../kotlin/ir/util/DescriptorToIrUtil.kt | 22 ++++++++++++++++++ .../org/jetbrains/kotlin/ir/util/IrUtils.kt | 15 ------------ .../jetbrains/kotlin/ir/util/SymbolTable.kt | 6 ++--- .../compiler/backend/ir/GeneratorHelpers.kt | 23 ++++++++++--------- 10 files changed, 61 insertions(+), 88 deletions(-) create mode 100644 compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DescriptorToIrUtil.kt 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 e75e8cbe64c..9b61ab3801f 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 @@ -12,8 +12,8 @@ import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.Scope import org.jetbrains.kotlin.ir.builders.declarations.IrTypeParameterBuilder @@ -190,9 +190,13 @@ fun IrTypeParameter.copyToWithoutSuperTypes( @OptIn(ObsoleteDescriptorBasedAPI::class) fun IrFunction.copyReceiverParametersFrom(from: IrFunction) { - dispatchReceiverParameter = from.dispatchReceiverParameter?.let { - IrValueParameterImpl(it.startOffset, it.endOffset, it.origin, it.descriptor, it.type, it.varargElementType).also { - it.parent = this + dispatchReceiverParameter = from.dispatchReceiverParameter?.run { + IrValueParameterImpl( + startOffset, endOffset, origin, IrValueParameterSymbolImpl(descriptor), descriptor.name, + descriptor.indexOrMinusOne, type, varargElementType, descriptor.isCrossinline, + descriptor.isNoinline + ).also { parameter -> + parameter.parent = this@copyReceiverParametersFrom } } extensionReceiverParameter = from.extensionReceiverParameter?.copyTo(this) 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 9e3b72d0626..eff3db86ad9 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 @@ -9,10 +9,7 @@ import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.DeclarationTransformer import org.jetbrains.kotlin.backend.common.bridges.FunctionHandle import org.jetbrains.kotlin.backend.common.bridges.generateBridges -import org.jetbrains.kotlin.backend.common.ir.copyTo -import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom -import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny -import org.jetbrains.kotlin.backend.common.ir.isSuspend +import org.jetbrains.kotlin.backend.common.ir.* import org.jetbrains.kotlin.backend.common.lower.* import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI @@ -23,7 +20,6 @@ import org.jetbrains.kotlin.ir.backend.js.utils.functionSignature import org.jetbrains.kotlin.ir.backend.js.utils.getJsName import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl import org.jetbrains.kotlin.ir.types.IrType @@ -138,11 +134,7 @@ class BridgesConstruction(val context: CommonBackendContext) : DeclarationTransf origin = origin ).apply { copyTypeParametersFrom(bridge) - // TODO: should dispatch receiver be copied? - dispatchReceiverParameter = bridge.dispatchReceiverParameter?.run { - IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also { it.parent = this@apply } - } - extensionReceiverParameter = bridge.extensionReceiverParameter?.copyTo(this) + copyReceiverParametersFrom(bridge) valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) } annotations += bridge.annotations overriddenSymbols += delegateTo.overriddenSymbols diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt index 31e7488b6c1..eb013734a18 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt @@ -17,19 +17,16 @@ package org.jetbrains.kotlin.ir.declarations.impl import org.jetbrains.kotlin.descriptors.ParameterDescriptor -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.declarations.impl.carriers.ValueParameterCarrier import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol -import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType 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.addToStdlib.safeAs class IrValueParameterImpl( startOffset: Int, @@ -47,25 +44,6 @@ class IrValueParameterImpl( IrValueParameter, ValueParameterCarrier { - @ObsoleteDescriptorBasedAPI - constructor( - startOffset: Int, - endOffset: Int, - origin: IrDeclarationOrigin, - descriptor: ParameterDescriptor, - type: IrType, - varargElementType: IrType?, - name: Name = descriptor.name, - symbol: IrValueParameterSymbol = IrValueParameterSymbolImpl(descriptor) - ) : this( - startOffset, endOffset, origin, symbol, - name, - index = descriptor.safeAs()?.index ?: -1, - type = type, varargElementType = varargElementType, - isCrossinline = descriptor.safeAs()?.isCrossinline ?: false, - isNoinline = descriptor.safeAs()?.isNoinline ?: false - ) - @ObsoleteDescriptorBasedAPI override val descriptor: ParameterDescriptor = symbol.descriptor 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 5dcc670d6cc..ffa1d1053c7 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 @@ -6,12 +6,13 @@ package org.jetbrains.kotlin.ir.declarations.lazy import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.IrElementBase +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.expressions.IrConstructorCall +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator import org.jetbrains.kotlin.resolve.scopes.MemberScope @@ -30,8 +31,8 @@ abstract class IrLazyDeclarationBase( protected fun ReceiverParameterDescriptor.generateReceiverParameterStub(): IrValueParameter = IrValueParameterImpl( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, this, - type.toIrType(), null + UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, IrValueParameterSymbolImpl(this), + name, -1, type.toIrType(), null, isCrossinline = false, isNoinline = false ) protected fun generateMemberStubs(memberScope: MemberScope, container: MutableList) { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt index ffce13eda86..2eea7075de4 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrFunctionFactory.kt @@ -19,9 +19,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.impl.* -import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET -import org.jetbrains.kotlin.ir.util.SymbolTable -import org.jetbrains.kotlin.ir.util.referenceClassifier +import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal @@ -356,19 +354,12 @@ class IrFunctionFactory(private val irBuiltIns: IrBuiltIns, private val symbolTa } } - private fun IrFunction.createValueParameter(descriptor: ParameterDescriptor): IrValueParameter { - val symbol = IrValueParameterSymbolImpl(descriptor) - val varargType = if (descriptor is ValueParameterDescriptor) descriptor.varargElementType else null - return IrValueParameterImpl( - offset, - offset, - memberOrigin, - descriptor, - symbol = symbol, - type = toIrType(descriptor.type), - varargElementType = varargType?.let { toIrType(it) } + private fun IrFunction.createValueParameter(descriptor: ParameterDescriptor): IrValueParameter = with(descriptor) { + IrValueParameterImpl( + offset, offset, memberOrigin, IrValueParameterSymbolImpl(this), name, indexOrMinusOne, toIrType(type), + (this as? ValueParameterDescriptor)?.varargElementType?.let(::toIrType), isCrossinline, isNoinline ).also { - it.parent = this + it.parent = this@createValueParameter } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt index ae87c7134fc..b806538305e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.linkage.IrProvider import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal @@ -247,10 +248,10 @@ class DeclarationStubGenerator( private fun KotlinType.toIrType() = typeTranslator.translateType(this) - internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter { - return IrValueParameterImpl( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor), - descriptor, descriptor.type.toIrType(), descriptor.varargElementType?.toIrType() + internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter = with(descriptor) { + IrValueParameterImpl( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(this), IrValueParameterSymbolImpl(this), name, index, type.toIrType(), + varargElementType?.toIrType(), isCrossinline, isNoinline ).also { irValueParameter -> if (descriptor.declaresDefaultValue()) { irValueParameter.defaultValue = diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DescriptorToIrUtil.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DescriptorToIrUtil.kt new file mode 100644 index 00000000000..d9ad975e50d --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DescriptorToIrUtil.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ir.util + +import org.jetbrains.kotlin.descriptors.ParameterDescriptor +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor +import org.jetbrains.kotlin.types.KotlinType + +val ParameterDescriptor.indexOrMinusOne: Int + get() = if (this is ValueParameterDescriptor) index else -1 + +val ParameterDescriptor.varargElementType: KotlinType? + get() = (this as? ValueParameterDescriptor)?.varargElementType + +val ParameterDescriptor.isCrossinline: Boolean + get() = this is ValueParameterDescriptor && isCrossinline + +val ParameterDescriptor.isNoinline: Boolean + get() = this is ValueParameterDescriptor && isNoinline 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 ff5493bf10f..d70b6476b10 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 @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl @@ -379,20 +378,6 @@ fun IrValueParameter.hasDefaultValue(): Boolean = DFS.ifAny( { current -> current.defaultValue != null } ) -@ObsoleteDescriptorBasedAPI -fun IrValueParameter.copy(newDescriptor: ParameterDescriptor): IrValueParameter { - assert(this.descriptor.type == newDescriptor.type) - - return IrValueParameterImpl( - startOffset, - endOffset, - IrDeclarationOrigin.DEFINED, - newDescriptor, - type, - varargElementType - ) -} - // In presence of `IrBlock`s, return the expression that actually serves as the value (the last one). tailrec fun IrExpression.removeBlocks(): IrExpression? = when (this) { is IrBlock -> (statements.last() as? IrExpression)?.removeBlocks() diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt index dc525fa40f1..14c8f357b68 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/SymbolTable.kt @@ -886,10 +886,8 @@ open class SymbolTable( varargElementType: IrType? = null, valueParameterFactory: (IrValueParameterSymbol) -> IrValueParameter = { IrValueParameterImpl( - startOffset, endOffset, origin, descriptor, - name = nameProvider.nameForDeclaration(descriptor), - type = type, varargElementType = varargElementType, - symbol = it + startOffset, endOffset, origin, it, nameProvider.nameForDeclaration(descriptor), + descriptor.indexOrMinusOne, type, varargElementType, descriptor.isCrossinline, descriptor.isNoinline ) } ): IrValueParameter = 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 a7aa4d5f761..c5b747980da 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 @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.* +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection @@ -377,14 +378,14 @@ interface IrBuilderExtension { overwriteValueParameters: Boolean = false, copyTypeParameters: Boolean = true ) { - fun ParameterDescriptor.irValueParameter() = IrValueParameterImpl( - this@createParameterDeclarations.startOffset, this@createParameterDeclarations.endOffset, - SERIALIZABLE_PLUGIN_ORIGIN, - this, - type.toIrType(), - (this as? ValueParameterDescriptor)?.varargElementType?.toIrType() - ).also { - it.parent = this@createParameterDeclarations + val function = this + fun irValueParameter(descriptor: ParameterDescriptor): IrValueParameterImpl = with(descriptor) { + IrValueParameterImpl( + function.startOffset, function.endOffset, SERIALIZABLE_PLUGIN_ORIGIN, IrValueParameterSymbolImpl(this), + name, indexOrMinusOne, type.toIrType(), varargElementType?.toIrType(), isCrossinline, isNoinline + ).also { + it.parent = function + } } if (copyTypeParameters) { @@ -392,13 +393,13 @@ interface IrBuilderExtension { copyTypeParamsFromDescriptor() } - dispatchReceiverParameter = descriptor.dispatchReceiverParameter?.irValueParameter() - extensionReceiverParameter = descriptor.extensionReceiverParameter?.irValueParameter() + dispatchReceiverParameter = descriptor.dispatchReceiverParameter?.let { irValueParameter(it) } + extensionReceiverParameter = descriptor.extensionReceiverParameter?.let { irValueParameter(it) } if (!overwriteValueParameters) assert(valueParameters.isEmpty()) - valueParameters = descriptor.valueParameters.map { it.irValueParameter() } + valueParameters = descriptor.valueParameters.map { irValueParameter(it) } } fun IrFunction.copyTypeParamsFromDescriptor() {