IR: remove deprecated constructor of IrValueParameterImpl

This commit is contained in:
Alexander Udalov
2020-07-06 22:22:20 +02:00
parent bba597cdff
commit 0691595ed2
10 changed files with 61 additions and 88 deletions
@@ -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)
@@ -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
@@ -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<ValueParameterDescriptor>()?.index ?: -1,
type = type, varargElementType = varargElementType,
isCrossinline = descriptor.safeAs<ValueParameterDescriptor>()?.isCrossinline ?: false,
isNoinline = descriptor.safeAs<ValueParameterDescriptor>()?.isNoinline ?: false
)
@ObsoleteDescriptorBasedAPI
override val descriptor: ParameterDescriptor = symbol.descriptor
@@ -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<IrDeclaration>) {
@@ -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
}
}
@@ -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 =
@@ -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
@@ -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()
@@ -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 =
@@ -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() {