From 784d3a90056a2a01a91838790b55ecb9580d1fc1 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 18 May 2020 19:15:32 +0300 Subject: [PATCH] [IR] Unbind construction methods of IrValueParameterImpl from symbol.descriptor --- .../declarations/impl/IrValueParameterImpl.kt | 47 ++++++++++++------- .../ir/descriptors/IrFunctionFactory.kt | 8 ++-- .../jetbrains/kotlin/ir/util/SymbolTable.kt | 5 +- 3 files changed, 37 insertions(+), 23 deletions(-) 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 5fc3793be2e..08974b01e88 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 @@ -35,17 +35,22 @@ class IrValueParameterImpl( endOffset: Int, origin: IrDeclarationOrigin, override val symbol: IrValueParameterSymbol, - override val name: Name = symbol.descriptor.name, - override val index: Int = symbol.descriptor.safeAs()?.index ?: -1, + override val name: Name, + override val index: Int, override val type: IrType, override val varargElementType: IrType?, - override val isCrossinline: Boolean = symbol.descriptor.safeAs()?.isCrossinline ?: false, - override val isNoinline: Boolean = symbol.descriptor.safeAs()?.isNoinline ?: false + override val isCrossinline: Boolean, + override val isNoinline: Boolean ) : IrDeclarationBase(startOffset, endOffset, origin), IrValueParameter, ValueParameterCarrier { + @Deprecated( + "This constructor is left for native compilation purpose only. " + + "It takes value parameter attributes from symbol.descriptor " + + "Please either provide parameter attributes or its descriptor explicitly" + ) constructor( startOffset: Int, endOffset: Int, @@ -53,17 +58,15 @@ class IrValueParameterImpl( symbol: IrValueParameterSymbol, type: IrType, varargElementType: IrType? - ) : - this( - startOffset, endOffset, origin, - symbol, - symbol.descriptor.name, - symbol.descriptor.safeAs()?.index ?: -1, - type, - varargElementType, - symbol.descriptor.safeAs()?.isCrossinline ?: false, - symbol.descriptor.safeAs()?.isNoinline ?: false - ) + ) : this( + startOffset, endOffset, origin, symbol, + name = symbol.descriptor.name, + index = symbol.descriptor.safeAs()?.index ?: -1, + type = type, + varargElementType = varargElementType, + isCrossinline = symbol.descriptor.safeAs()?.isCrossinline == true, + isNoinline = symbol.descriptor.safeAs()?.isNoinline == true + ) constructor( startOffset: Int, @@ -71,9 +74,17 @@ class IrValueParameterImpl( origin: IrDeclarationOrigin, descriptor: ParameterDescriptor, type: IrType, - varargElementType: IrType? - ) : - this(startOffset, endOffset, origin, IrValueParameterSymbolImpl(descriptor), type, varargElementType) + 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 + ) override val descriptor: ParameterDescriptor = symbol.descriptor 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 dca79234cea..9b22e20a1cb 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 @@ -357,9 +357,11 @@ class IrFunctionFactory(private val irBuiltIns: IrBuiltIns, private val symbolTa offset, offset, memberOrigin, - symbol, - toIrType(descriptor.type), - varargType?.let { toIrType(it) }).also { + descriptor, + symbol = symbol, + type = toIrType(descriptor.type), + varargElementType = varargType?.let { toIrType(it) } + ).also { it.parent = this } } 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 47363c3342e..60a5783248b 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 @@ -800,9 +800,10 @@ open class SymbolTable( varargElementType: IrType? = null, valueParameterFactory: (IrValueParameterSymbol) -> IrValueParameter = { IrValueParameterImpl( - startOffset, endOffset, origin, it, - nameProvider.nameForDeclaration(descriptor), + startOffset, endOffset, origin, descriptor, + name = nameProvider.nameForDeclaration(descriptor), type = type, varargElementType = varargElementType, + symbol = it ) } ): IrValueParameter =