Fix code review

Minor fixes
Fix JVM IR BE
Fix NATIVE
This commit is contained in:
Roman Artemev
2018-08-27 17:35:16 +03:00
committed by romanart
parent afcdcf8217
commit fec8065fd0
26 changed files with 103 additions and 133 deletions
@@ -221,7 +221,7 @@ open class WrappedSimpleFunctionDescriptor(
val extensionReceiver by lazy { val extensionReceiver by lazy {
owner.extensionReceiverParameter?.let { owner.extensionReceiverParameter?.let {
ReceiverParameterDescriptorImpl(this, ExtensionReceiver(it.descriptor, it.type.toKotlinType(), null)) ReceiverParameterDescriptorImpl(this, ExtensionReceiver(it.descriptor, it.type.toKotlinType(), null), Annotations.EMPTY)
} }
} }
@@ -294,6 +294,9 @@ open class WrappedClassConstructorDescriptor(
) : ClassConstructorDescriptor, WrappedCallableDescriptor<IrConstructor>(annotations, sourceElement) { ) : ClassConstructorDescriptor, WrappedCallableDescriptor<IrConstructor>(annotations, sourceElement) {
override fun getContainingDeclaration() = (owner.parent as IrClass).descriptor override fun getContainingDeclaration() = (owner.parent as IrClass).descriptor
override fun getDispatchReceiverParameter() = owner.dispatchReceiverParameter?.run {
(containingDeclaration.containingDeclaration as ClassDescriptor).thisAsReceiverParameter
}
override fun getTypeParameters() = owner.typeParameters.map { it.descriptor } override fun getTypeParameters() = owner.typeParameters.map { it.descriptor }
override fun getValueParameters() = owner.valueParameters.asSequence() override fun getValueParameters() = owner.valueParameters.asSequence()
.mapNotNull { it.descriptor as? ValueParameterDescriptor } .mapNotNull { it.descriptor as? ValueParameterDescriptor }
@@ -158,6 +158,7 @@ fun IrValueParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrValuePara
} }
fun IrTypeParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrTypeParameter { fun IrTypeParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrTypeParameter {
// TODO: Copy IrTypeParameter with type remapping
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source) val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
val symbol = IrTypeParameterSymbolImpl(descriptor) val symbol = IrTypeParameterSymbolImpl(descriptor)
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also { return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, shift + index, isReified, variance).also {
@@ -168,7 +169,12 @@ fun IrTypeParameter.copyTo(irFunction: IrFunction, shift: Int = 0): IrTypeParame
fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) { fun IrFunction.copyParameterDeclarationsFrom(from: IrFunction) {
dispatchReceiverParameter = from.dispatchReceiverParameter?.copyTo(this) // TODO: should dispatch receiver be copied?
dispatchReceiverParameter = from.dispatchReceiverParameter?.let {
IrValueParameterImpl(it.startOffset, it.endOffset, it.origin, it.descriptor, it.type, it.varargElementType).also {
it.parent = this
}
}
extensionReceiverParameter = from.extensionReceiverParameter?.copyTo(this) extensionReceiverParameter = from.extensionReceiverParameter?.copyTo(this)
val shift = valueParameters.size val shift = valueParameters.size
@@ -15,17 +15,16 @@ import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDesc
import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName import org.jetbrains.kotlin.backend.common.descriptors.synthesizedName
import org.jetbrains.kotlin.backend.common.ir.copyTo import org.jetbrains.kotlin.backend.common.ir.copyTo
import org.jetbrains.kotlin.backend.common.ir.ir2string import org.jetbrains.kotlin.backend.common.ir.ir2string
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
@@ -142,9 +141,9 @@ open class DefaultArgumentStubGenerator constructor(val context: CommonBackendCo
} }
} }
// Remove default argument initializers. // Remove default argument initializers.
// irFunction.valueParameters.forEach { irFunction.valueParameters.forEach {
// it.defaultValue = null it.defaultValue = IrExpressionBodyImpl(IrErrorExpressionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, it.type, "Default Stub"))
// } }
return listOf(irFunction, newIrFunction) return listOf(irFunction, newIrFunction)
} }
@@ -377,7 +376,9 @@ private fun IrFunction.generateDefaultsFunctionImpl(context: CommonBackendContex
val newTypeParameters = typeParameters.map { it.copyTo(newFunction) } val newTypeParameters = typeParameters.map { it.copyTo(newFunction) }
newFunction.returnType = returnType newFunction.returnType = returnType
newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.copyTo(newFunction) newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.run {
IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also { it.parent = newFunction }
}
newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction) newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction)
newFunction.valueParameters += newValueParameters newFunction.valueParameters += newValueParameters
newFunction.typeParameters += newTypeParameters newFunction.typeParameters += newTypeParameters
@@ -399,7 +400,7 @@ private fun buildFunctionDeclaration(irFunction: IrFunction): IrFunction {
irFunction.name, irFunction.name,
irFunction.visibility, irFunction.visibility,
irFunction.isInline, irFunction.isInline,
irFunction.isExternal, false,
false false
).also { ).also {
descriptor.bind(it) descriptor.bind(it)
@@ -417,10 +418,10 @@ private fun buildFunctionDeclaration(irFunction: IrFunction): IrFunction {
IrSimpleFunctionSymbolImpl(descriptor), IrSimpleFunctionSymbolImpl(descriptor),
name, name,
irFunction.visibility, irFunction.visibility,
irFunction.modality, Modality.FINAL,
irFunction.isInline, irFunction.isInline,
irFunction.isExternal, false,
irFunction.isTailrec, false,
irFunction.isSuspend irFunction.isSuspend
).also { ).also {
descriptor.bind(it) descriptor.bind(it)
@@ -55,7 +55,7 @@ class LocalDeclarationsLowering(
val context: BackendContext, val context: BackendContext,
val localNameProvider: LocalNameProvider = LocalNameProvider.DEFAULT, val localNameProvider: LocalNameProvider = LocalNameProvider.DEFAULT,
val loweredConstructorVisibility: Visibility = Visibilities.PRIVATE, val loweredConstructorVisibility: Visibility = Visibilities.PRIVATE,
private val isJVM: Boolean = false private val isJVM: Boolean = false // TODO: remove this workaround
) : ) :
DeclarationContainerLoweringPass { DeclarationContainerLoweringPass {
@@ -350,7 +350,7 @@ class LocalDeclarationsLowering(
override fun visitReturn(expression: IrReturn): IrExpression { override fun visitReturn(expression: IrReturn): IrExpression {
expression.transformChildrenVoid(this) expression.transformChildrenVoid(this)
val oldReturnTarget = expression.returnTargetSymbol.owner as IrFunction val oldReturnTarget = expression.returnTargetSymbol.owner as? IrFunction ?: return expression
val newReturnTarget = oldReturnTarget.transformed ?: return expression val newReturnTarget = oldReturnTarget.transformed ?: return expression
return IrReturnImpl( return IrReturnImpl(
@@ -503,7 +503,7 @@ class LocalDeclarationsLowering(
newSymbol, newSymbol,
newName, newName,
// TODO: change to PRIVATE when issue with CallableReferenceLowering in Jvm BE is fixed // TODO: change to PRIVATE when issue with CallableReferenceLowering in Jvm BE is fixed
Visibilities.PUBLIC, if (isJVM) Visibilities.PUBLIC else Visibilities.PRIVATE,
Modality.FINAL, Modality.FINAL,
oldDeclaration.isInline, oldDeclaration.isInline,
oldDeclaration.isExternal, oldDeclaration.isExternal,
@@ -596,8 +596,10 @@ class LocalDeclarationsLowering(
newDeclaration.parent = localClassContext.declaration newDeclaration.parent = localClassContext.declaration
newDeclaration.returnType = oldDeclaration.returnType newDeclaration.returnType = oldDeclaration.returnType
// TODO: should dispatch receiver be copied?
newDeclaration.dispatchReceiverParameter = oldDeclaration.dispatchReceiverParameter?.run { newDeclaration.dispatchReceiverParameter = oldDeclaration.dispatchReceiverParameter?.run {
copyTo(newDeclaration).also { IrValueParameterImpl(startOffset, endOffset, origin, descriptor, type, varargElementType).also {
it.parent = newDeclaration
newParameterToOld.putAbsentOrSame(it, this) newParameterToOld.putAbsentOrSame(it, this)
} }
} }
@@ -68,6 +68,11 @@ class VariableRemapper(val mapping: Map<IrValueParameter, IrValueParameter>) : A
mapping[value] mapping[value]
} }
class VariableRemapperDesc(val mapping: Map<ValueDescriptor, IrValueParameter>) : AbstractVariableRemapper() {
override fun remapVariable(value: IrValueDeclaration): IrValueParameter? =
mapping[value.descriptor]
}
fun BackendContext.createIrBuilder( fun BackendContext.createIrBuilder(
symbol: IrSymbol, symbol: IrSymbol,
startOffset: Int = UNDEFINED_OFFSET, startOffset: Int = UNDEFINED_OFFSET,
@@ -133,7 +133,9 @@ class JsSharedVariablesManager(val builtIns: IrBuiltIns, val implicitDeclaration
declaration.parent = implicitDeclarationsFile declaration.parent = implicitDeclarationsFile
closureBoxType = IrSimpleTypeImpl(declaration.symbol, false, emptyList(), emptyList()) closureBoxType = IrSimpleTypeImpl(declaration.symbol, false, emptyList(), emptyList())
declaration.thisReceiver = declaration.thisReceiver =
JsIrBuilder.buildValueParameter(Name.special("<this>"), -1, closureBoxType, IrDeclarationOrigin.INSTANCE_RECEIVER) JsIrBuilder.buildValueParameter(Name.special("<this>"), -1, closureBoxType, IrDeclarationOrigin.INSTANCE_RECEIVER).apply {
parent = declaration
}
implicitDeclarationsFile.declarations += declaration implicitDeclarationsFile.declarations += declaration
return declaration return declaration
@@ -176,6 +176,7 @@ object JsIrBuilder {
fun buildVar( fun buildVar(
type: IrType, type: IrType,
parent: IrDeclarationParent,
name: String = "tmp", name: String = "tmp",
isVar: Boolean = false, isVar: Boolean = false,
isConst: Boolean = false, isConst: Boolean = false,
@@ -196,6 +197,7 @@ object JsIrBuilder {
).also { ).also {
descriptor.bind(it) descriptor.bind(it)
it.initializer = initializer it.initializer = initializer
it.parent = parent
} }
} }
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.transformFlat import org.jetbrains.kotlin.ir.util.transformFlat
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
@@ -101,7 +100,7 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
} }
private fun makeTempVar(type: IrType, init: IrExpression? = null) = private fun makeTempVar(type: IrType, init: IrExpression? = null) =
JsIrBuilder.buildVar(type, initializer = init, isVar = true).also { it.parent = function } JsIrBuilder.buildVar(type, function, initializer = init, isVar = true)
private fun makeLoopLabel() = "\$l\$${tmpVarCounter++}" private fun makeLoopLabel() = "\$l\$${tmpVarCounter++}"
@@ -538,8 +537,8 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
private fun wrap(expression: IrExpression) = private fun wrap(expression: IrExpression) =
expression as? IrBlock ?: expression.let { IrBlockImpl(it.startOffset, it.endOffset, it.type, null, listOf(it)) } expression as? IrBlock ?: expression.let { IrBlockImpl(it.startOffset, it.endOffset, it.type, null, listOf(it)) }
private fun wrap(expression: IrExpression, variable: IrVariableSymbol) = private fun wrap(expression: IrExpression, variable: IrVariable) =
wrap(JsIrBuilder.buildSetVariable(variable, expression, unitType)) wrap(JsIrBuilder.buildSetVariable(variable.symbol, expression, unitType))
// try { // try {
// try_block {} // try_block {}
@@ -561,9 +560,9 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
override fun visitTry(aTry: IrTry): IrExpression { override fun visitTry(aTry: IrTry): IrExpression {
val irVar = makeTempVar(aTry.type) val irVar = makeTempVar(aTry.type)
val newTryResult = wrap(aTry.tryResult, irVar.symbol) val newTryResult = wrap(aTry.tryResult, irVar)
val newCatches = aTry.catches.map { val newCatches = aTry.catches.map {
val newCatchBody = wrap(it.result, irVar.symbol) val newCatchBody = wrap(it.result, irVar)
IrCatchImpl(it.startOffset, it.endOffset, it.catchParameter, newCatchBody) IrCatchImpl(it.startOffset, it.endOffset, it.catchParameter, newCatchBody)
} }
@@ -610,7 +609,7 @@ class BlockDecomposerTransformer(context: JsIrBackendContext) : IrElementTransfo
val irVar = makeTempVar(expression.type) val irVar = makeTempVar(expression.type)
val newBranches = decomposedResults.map { (branch, condition, result) -> val newBranches = decomposedResults.map { (branch, condition, result) ->
val newResult = wrap(result, irVar.symbol) val newResult = wrap(result, irVar)
when (branch) { when (branch) {
is IrElseBranch -> IrElseBranchImpl(branch.startOffset, branch.endOffset, condition, newResult) is IrElseBranch -> IrElseBranchImpl(branch.startOffset, branch.endOffset, condition, newResult)
else /* IrBranch */ -> IrBranchImpl(branch.startOffset, branch.endOffset, condition, newResult) else /* IrBranch */ -> IrBranchImpl(branch.startOffset, branch.endOffset, condition, newResult)
@@ -30,14 +30,15 @@ import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.isStatic import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.isStatic
import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.declarations.* 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.IrExpression
import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classifierOrNull import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.isUnit import org.jetbrains.kotlin.ir.types.isUnit
import org.jetbrains.kotlin.ir.types.toKotlinType
import org.jetbrains.kotlin.ir.util.isInterface import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.util.isReal import org.jetbrains.kotlin.ir.util.isReal
import org.jetbrains.kotlin.ir.util.parentAsClass import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -121,7 +122,10 @@ class BridgesConstruction(val context: JsIrBackendContext) : ClassLoweringPass {
IrDeclarationOrigin.BRIDGE IrDeclarationOrigin.BRIDGE
).apply { ).apply {
dispatchReceiverParameter = bridge.dispatchReceiverParameter?.copyTo(this) // 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) extensionReceiverParameter = bridge.extensionReceiverParameter?.copyTo(this)
typeParameters += bridge.typeParameters typeParameters += bridge.typeParameters
valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) } valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) }
@@ -185,9 +189,8 @@ class FunctionAndSignature(val function: IrSimpleFunction) {
private val signature = Signature( private val signature = Signature(
function.name, function.name,
// TODO: should kotlinTypes be used here? function.extensionReceiverParameter?.type?.render(),
function.extensionReceiverParameter?.type?.toKotlinType()?.toString(), function.valueParameters.map { it.type.render() }
function.valueParameters.map { it.type.toKotlinType().toString() }
) )
override fun equals(other: Any?) = override fun equals(other: Any?) =
@@ -210,9 +210,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
val additionalDeclarations = generateGetterBodyWithGuard(refGetFunction) { val additionalDeclarations = generateGetterBodyWithGuard(refGetFunction) {
val irClosureReference = JsIrBuilder.buildFunctionReference(functionReference.type, refClosureFunction.symbol) val irClosureReference = JsIrBuilder.buildFunctionReference(functionReference.type, refClosureFunction.symbol)
val irVar = JsIrBuilder.buildVar(irClosureReference.type, initializer = irClosureReference).also { val irVar = JsIrBuilder.buildVar(irClosureReference.type, refGetFunction, initializer = irClosureReference)
it.parent = refGetFunction
}
// TODO: fill other fields of callable reference (returnType, parameters, isFinal, etc.) // TODO: fill other fields of callable reference (returnType, parameters, isFinal, etc.)
val irSetName = JsIrBuilder.buildCall(context.intrinsics.jsSetJSField.symbol).apply { val irSetName = JsIrBuilder.buildCall(context.intrinsics.jsSetJSField.symbol).apply {
@@ -261,7 +259,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
val getterFunctionType = context.builtIns.getFunction(getterFunction.valueParameters.size + 1) val getterFunctionType = context.builtIns.getFunction(getterFunction.valueParameters.size + 1)
val type = getterFunctionType.toIrType(symbolTable = context.symbolTable) val type = getterFunctionType.toIrType(symbolTable = context.symbolTable)
val irGetReference = JsIrBuilder.buildFunctionReference(type, getterFunction.symbol) val irGetReference = JsIrBuilder.buildFunctionReference(type, getterFunction.symbol)
val irVar = JsIrBuilder.buildVar(type, initializer = irGetReference).also { it.parent = refGetFunction } val irVar = JsIrBuilder.buildVar(type, refGetFunction, initializer = irGetReference)
statements += irVar statements += irVar
@@ -331,7 +329,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
val getterFunctionType = context.builtIns.getFunction(getterFunction.valueParameters.size + 1) val getterFunctionType = context.builtIns.getFunction(getterFunction.valueParameters.size + 1)
val type = getterFunctionType.toIrType(symbolTable = context.symbolTable) val type = getterFunctionType.toIrType(symbolTable = context.symbolTable)
val irGetReference = JsIrBuilder.buildFunctionReference(type, getterFunction.symbol) val irGetReference = JsIrBuilder.buildFunctionReference(type, getterFunction.symbol)
val irVar = JsIrBuilder.buildVar(type = type, initializer = irGetReference).also { it.parent = refGetFunction } val irVar = JsIrBuilder.buildVar(type, refGetFunction, initializer = irGetReference)
val irVarSymbol = irVar.symbol val irVarSymbol = irVar.symbol
statements += irVar statements += irVar
@@ -374,9 +372,7 @@ class CallableReferenceLowering(val context: JsIrBackendContext) {
val cacheName = "${getterFunction.name}_${Namer.KCALLABLE_CACHE_SUFFIX}" val cacheName = "${getterFunction.name}_${Namer.KCALLABLE_CACHE_SUFFIX}"
val type = getterFunction.returnType val type = getterFunction.returnType
val irNull = JsIrBuilder.buildNull(context.irBuiltIns.nothingNType) val irNull = JsIrBuilder.buildNull(context.irBuiltIns.nothingNType)
val cacheVar = JsIrBuilder.buildVar(type, cacheName, true, initializer = irNull).also { val cacheVar = JsIrBuilder.buildVar(type, getterFunction.parent, cacheName, true, initializer = irNull)
it.parent = getterFunction.parent
}
val irCacheValue = JsIrBuilder.buildGetValue(cacheVar.symbol) val irCacheValue = JsIrBuilder.buildGetValue(cacheVar.symbol)
val irIfCondition = JsIrBuilder.buildCall(context.irBuiltIns.eqeqSymbol).apply { val irIfCondition = JsIrBuilder.buildCall(context.irBuiltIns.eqeqSymbol).apply {
@@ -317,7 +317,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
val symbol = call.symbol val symbol = call.symbol
val declaration = symbol.owner val declaration = symbol.owner
if (declaration.isDynamic || declaration.isEffectivelyExternal()) { if (declaration.isDynamic() || declaration.isEffectivelyExternal()) {
when (call.origin) { when (call.origin) {
IrStatementOrigin.GET_PROPERTY -> { IrStatementOrigin.GET_PROPERTY -> {
val fieldSymbol = context.symbolTable.lazyWrapper.referenceField( val fieldSymbol = context.symbolTable.lazyWrapper.referenceField(
@@ -340,7 +340,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
} }
} }
if (declaration.isDynamic) { if (declaration.isDynamic()) {
dynamicCallOriginToIrFunction[call.origin]?.let { dynamicCallOriginToIrFunction[call.origin]?.let {
return irCall(call, it.symbol, dispatchReceiverAsFirstArgument = true) return irCall(call, it.symbol, dispatchReceiverAsFirstArgument = true)
} }
@@ -416,7 +416,7 @@ class IntrinsicifyCallsLowering(private val context: JsIrBackendContext) : FileL
it.name == Name.identifier("equals") it.name == Name.identifier("equals")
&& it.valueParameters.size == 1 && it.valueParameters.size == 1
&& rhs.isSubtypeOf(it.valueParameters[0].type) && rhs.isSubtypeOf(it.valueParameters[0].type)
&& !it./*descriptor.*/isFakeOverriddenFromAny() && !it.isFakeOverriddenFromAny()
} }
.maxWith( // Find the most specific function .maxWith( // Find the most specific function
Comparator { f1, f2 -> Comparator { f1, f2 ->
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.ir.backend.js.lower
import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.ir.backend.js.lower.inline.addChild import org.jetbrains.kotlin.ir.backend.js.lower.inline.addChild
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
class MoveExternalDeclarationsToSeparatePlace : FileLoweringPass { class MoveExternalDeclarationsToSeparatePlace : FileLoweringPass {
@@ -69,7 +69,7 @@ class MultipleCatchesLowering(val context: JsIrBackendContext) : FileLoweringPas
val commonType = mergeTypes(aTry.catches.map { it.catchParameter.type }) val commonType = mergeTypes(aTry.catches.map { it.catchParameter.type })
val pendingExceptionDeclaration = JsIrBuilder.buildVar(commonType, "\$p").apply { parent = data } val pendingExceptionDeclaration = JsIrBuilder.buildVar(commonType, data, "\$p")
val pendingException = JsIrBuilder.buildGetValue(pendingExceptionDeclaration.symbol) val pendingException = JsIrBuilder.buildGetValue(pendingExceptionDeclaration.symbol)
val branches = mutableListOf<IrBranch>() val branches = mutableListOf<IrBranch>()
@@ -257,7 +257,7 @@ class SecondaryCtorLowering(val context: JsIrBackendContext) {
newTarget: IrSimpleFunctionSymbol newTarget: IrSimpleFunctionSymbol
) = IrCallImpl(call.startOffset, call.endOffset, call.type, newTarget).apply { ) = IrCallImpl(call.startOffset, call.endOffset, call.type, newTarget).apply {
copyTypeArgumentsFrom(call) // copyTypeArgumentsFrom(call)
for (i in 0 until call.valueArgumentsCount) { for (i in 0 until call.valueArgumentsCount) {
putValueArgument(i, call.getValueArgument(i)) putValueArgument(i, call.getValueArgument(i))
@@ -6,7 +6,8 @@
package org.jetbrains.kotlin.ir.backend.js.lower package org.jetbrains.kotlin.ir.backend.js.lower
import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.backend.common.utils.* import org.jetbrains.kotlin.backend.common.utils.getPrimitiveArrayElementType
import org.jetbrains.kotlin.backend.common.utils.isPrimitiveArray
import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrArithBuilder import org.jetbrains.kotlin.ir.backend.js.ir.JsIrArithBuilder
@@ -178,7 +179,7 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass {
newStatements: MutableList<IrStatement>, newStatements: MutableList<IrStatement>,
declaration: IrDeclarationParent declaration: IrDeclarationParent
): IrExpression { ): IrExpression {
val varDeclaration = JsIrBuilder.buildVar(value.type, initializer = value).apply { parent = declaration } val varDeclaration = JsIrBuilder.buildVar(value.type, declaration, initializer = value)
newStatements += varDeclaration newStatements += varDeclaration
return JsIrBuilder.buildGetValue(varDeclaration.symbol) return JsIrBuilder.buildGetValue(varDeclaration.symbol)
} }
@@ -75,7 +75,7 @@ class StateMachineBuilder(
val entryState = SuspendState(unit) val entryState = SuspendState(unit)
val rootExceptionTrap = buildExceptionTrapState() val rootExceptionTrap = buildExceptionTrapState()
private val globalExceptionVar = JsIrBuilder.buildVar(exceptionSymbol.owner.type, "e").also { it.parent = function.owner } private val globalExceptionVar = JsIrBuilder.buildVar(exceptionSymbol.owner.type, function.owner, "e")
lateinit var globalCatch: IrCatch lateinit var globalCatch: IrCatch
fun finalizeStateMachine() { fun finalizeStateMachine() {
@@ -719,5 +719,5 @@ class StateMachineBuilder(
) )
private fun tempVar(type: IrType, name: String = "tmp") = private fun tempVar(type: IrType, name: String = "tmp") =
JsIrBuilder.buildVar(type, name).also { it.parent = function.owner } JsIrBuilder.buildVar(type, function.owner, name)
} }
@@ -789,14 +789,15 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
dataArgument = function.valueParameters[0] dataArgument = function.valueParameters[0]
exceptionArgument = function.valueParameters[1] exceptionArgument = function.valueParameters[1]
suspendResult = JsIrBuilder.buildVar(context.irBuiltIns.anyNType, "suspendResult", true).also { suspendResult = JsIrBuilder.buildVar(
it.parent = function context.irBuiltIns.anyNType,
it.initializer = JsIrBuilder.buildGetValue(dataArgument.symbol) function,
} "suspendResult",
true,
initializer = JsIrBuilder.buildGetValue(dataArgument.symbol)
)
suspendState = JsIrBuilder.buildVar(coroutineImplLabelFieldSymbol.owner.type, "suspendState", true).also { suspendState = JsIrBuilder.buildVar(coroutineImplLabelFieldSymbol.owner.type, function, "suspendState", true)
it.parent = function
}
val body = val body =
(originalBody as IrBlockBody).run { (originalBody as IrBlockBody).run {
@@ -102,8 +102,7 @@ private class ReturnableBlockTransformer(
if (expression !is IrReturnableBlock) return super.visitContainerExpression(expression, data) if (expression !is IrReturnableBlock) return super.visitContainerExpression(expression, data)
val variable by lazy { val variable by lazy {
JsIrBuilder.buildVar(expression.type, "tmp\$ret\$${data.labelCnt++}", true) JsIrBuilder.buildVar(expression.type, data.containingDeclaration, "tmp\$ret\$${data.labelCnt++}", true)
.also { it.parent = data.containingDeclaration }
} }
val loop by lazy { val loop by lazy {
@@ -46,7 +46,6 @@ class JsGenerationContext {
fun getNameForSymbol(symbol: IrSymbol): JsName = staticContext.getNameForSymbol(symbol, this) fun getNameForSymbol(symbol: IrSymbol): JsName = staticContext.getNameForSymbol(symbol, this)
fun getNameForType(type: IrType): JsName = staticContext.getNameForType(type, this) fun getNameForType(type: IrType): JsName = staticContext.getNameForType(type, this)
// fun getNameForReceiver(symbol: IrValueSymbol, isExt: Boolean): JsName = staticContext.getNameForReceiver(symbol, isExt, this)
fun getNameForLoop(loop: IrLoop): JsName? = staticContext.getNameForLoop(loop, this) fun getNameForLoop(loop: IrLoop): JsName? = staticContext.getNameForLoop(loop, this)
val continuation val continuation
@@ -93,7 +93,7 @@ class SimpleNameGenerator : NameGenerator {
val descriptor = declaration.descriptor val descriptor = declaration.descriptor
if (declaration.isDynamic) { if (declaration.isDynamic()) {
return@getOrPut nameDeclarator(declaration.descriptor.name.asString()) return@getOrPut nameDeclarator(declaration.descriptor.name.asString())
} }
@@ -178,8 +178,8 @@ class JvmSharedVariablesManager(
) )
return IrVariableImpl( return IrVariableImpl(
originalDeclaration.startOffset, originalDeclaration.endOffset, originalDeclaration.origin, originalDeclaration.startOffset, originalDeclaration.endOffset, originalDeclaration.origin,
sharedVariableSymbol, sharedVariableDescriptor.type.toIrType()!!, refConstructorCall sharedVariableSymbol, sharedVariableDescriptor.type.toIrType()!!
) ).apply { initializer = refConstructorCall }
} }
override fun defineSharedValue( override fun defineSharedValue(
@@ -8,52 +8,46 @@ package org.jetbrains.kotlin.backend.jvm.lower
import org.jetbrains.kotlin.backend.common.ClassLoweringPass import org.jetbrains.kotlin.backend.common.ClassLoweringPass
import org.jetbrains.kotlin.backend.common.lower.DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER import org.jetbrains.kotlin.backend.common.lower.DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER
import org.jetbrains.kotlin.backend.common.lower.InitializersLowering.Companion.clinitName import org.jetbrains.kotlin.backend.common.lower.InitializersLowering.Companion.clinitName
import org.jetbrains.kotlin.backend.common.lower.VariableRemapper import org.jetbrains.kotlin.backend.common.lower.VariableRemapperDesc
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptorImpl
import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
import org.jetbrains.kotlin.ir.util.createParameterDeclarations import org.jetbrains.kotlin.ir.util.createParameterDeclarations
import org.jetbrains.kotlin.ir.util.isInterface import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.Opcodes
class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid(), ClassLoweringPass { class InterfaceLowering(val context: JvmBackendContext) : IrElementTransformerVoid(), ClassLoweringPass {
val state = context.state
override fun lower(irClass: IrClass) { override fun lower(irClass: IrClass) {
if (!irClass.isInterface) return if (!irClass.isInterface) return
val interfaceDescriptor = irClass.descriptor val defaultImplsIrClass = context.declarationFactory.getDefaultImplsClass(irClass)
val defaultImplsDescriptor = createDefaultImplsClassDescriptor(interfaceDescriptor)
val defaultImplsIrClass =
IrClassImpl(irClass.startOffset, irClass.endOffset, JvmLoweredDeclarationOrigin.DEFAULT_IMPLS, defaultImplsDescriptor)
irClass.declarations.add(defaultImplsIrClass) irClass.declarations.add(defaultImplsIrClass)
val members = defaultImplsIrClass.declarations val members = defaultImplsIrClass.declarations
irClass.declarations.filterIsInstance<IrFunction>().forEach { irClass.declarations.filterIsInstance<IrFunction>().forEach {
val descriptor = it.descriptor val descriptor = it.descriptor
if (it.origin == DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER) { if (it.origin == DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER) {
members.add(it) //just copy $default to DefaultImpls members.add(it) //just copy $default to DefaultImpls
} else if (descriptor.modality != Modality.ABSTRACT) { } else if (descriptor.modality != Modality.ABSTRACT && it.origin != IrDeclarationOrigin.FAKE_OVERRIDE) {
val functionDescriptorImpl = val element = context.declarationFactory.getDefaultImplsFunction(it)
createDefaultImplFunDescriptor(defaultImplsDescriptor, descriptor, interfaceDescriptor, state.typeMapper) members.add(element)
members.add(functionDescriptorImpl.createFunctionAndMapVariables(it, it.visibility)) element.body = it.body
it.body = null it.body = null
//TODO reset modality to abstract //TODO reset modality to abstract
} }
@@ -76,24 +70,6 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid()
irClass.declarations.removeAll(privateToRemove) irClass.declarations.removeAll(privateToRemove)
irClass.declarations.removeAll(defaultBodies) irClass.declarations.removeAll(defaultBodies)
} }
companion object {
fun createDefaultImplsClassDescriptor(interfaceDescriptor: ClassDescriptor): DefaultImplsClassDescriptorImpl {
return DefaultImplsClassDescriptorImpl(
Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME), interfaceDescriptor, interfaceDescriptor.source
)
}
fun createDefaultImplFunDescriptor(
defaultImplsDescriptor: DefaultImplsClassDescriptorImpl,
descriptor: FunctionDescriptor,
interfaceDescriptor: ClassDescriptor, typeMapper: KotlinTypeMapper
): SimpleFunctionDescriptorImpl {
val name = Name.identifier(typeMapper.mapAsmMethod(descriptor).name)
return createStaticFunctionWithReceivers(defaultImplsDescriptor, name, descriptor, interfaceDescriptor.defaultType)
}
}
} }
@@ -135,18 +111,20 @@ internal fun createStaticFunctionWithReceivers(
internal fun FunctionDescriptor.createFunctionAndMapVariables( internal fun FunctionDescriptor.createFunctionAndMapVariables(
oldFunction: IrFunction, oldFunction: IrFunction,
visibility: Visibility visibility: Visibility = oldFunction.visibility,
origin: IrDeclarationOrigin = oldFunction.origin
) = ) =
IrFunctionImpl( IrFunctionImpl(
oldFunction.startOffset, oldFunction.endOffset, oldFunction.origin, IrSimpleFunctionSymbolImpl(this), oldFunction.startOffset, oldFunction.endOffset, origin, IrSimpleFunctionSymbolImpl(this),
visibility = visibility visibility = visibility
).apply { ).apply {
body = oldFunction.body body = oldFunction.body
returnType = oldFunction.returnType returnType = oldFunction.returnType
createParameterDeclarations() createParameterDeclarations()
val mapping: Map<IrValueParameter, IrValueParameter> = // TODO: do we really need descriptor here? This workaround is about coping `dispatchReceiver` descriptor
(listOfNotNull(oldFunction.dispatchReceiverParameter!!, oldFunction.extensionReceiverParameter) + oldFunction.valueParameters) val mapping: Map<ValueDescriptor, IrValueParameter> =
.zip(valueParameters).toMap() (listOfNotNull(oldFunction.dispatchReceiverParameter!!.descriptor, oldFunction.extensionReceiverParameter?.descriptor) + oldFunction.valueParameters.map { it.descriptor })
.zip(valueParameters).toMap()
body?.transform(VariableRemapper(mapping), null) body?.transform(VariableRemapperDesc(mapping), null)
} }
@@ -242,7 +242,6 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
ktConstructorElement.pureStartOffset, ktConstructorElement.pureEndOffset, IrDeclarationOrigin.DEFINED, ktConstructorElement.pureStartOffset, ktConstructorElement.pureEndOffset, IrDeclarationOrigin.DEFINED,
constructorDescriptor constructorDescriptor
).buildWithScope { irConstructor -> ).buildWithScope { irConstructor ->
declarationGenerator.generateScopedTypeParameterDeclarations(irConstructor, constructorDescriptor.typeParameters)
generateValueParameterDeclarations(irConstructor, ktParametersElement, null) generateValueParameterDeclarations(irConstructor, ktParametersElement, null)
irConstructor.body = createBodyGenerator(irConstructor.symbol).generateBody() irConstructor.body = createBodyGenerator(irConstructor.symbol).generateBody()
irConstructor.returnType = constructorDescriptor.returnType.toIrType() irConstructor.returnType = constructorDescriptor.returnType.toIrType()
@@ -55,24 +55,6 @@ class IrVariableImpl(
isLateinit = symbol.descriptor.isLateInit isLateinit = symbol.descriptor.isLateInit
) )
constructor(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
symbol: IrVariableSymbol,
type: IrType,
initializer: IrExpression?
) : this(
startOffset, endOffset, origin, symbol,
symbol.descriptor.name, type,
isVar = symbol.descriptor.isVar,
isConst = symbol.descriptor.isConst,
isLateinit = symbol.descriptor.isLateInit
) {
this.initializer = initializer
}
@Deprecated("Use constructor which takes symbol instead of descriptor")
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -81,7 +63,6 @@ class IrVariableImpl(
type: IrType type: IrType
) : this(startOffset, endOffset, origin, IrVariableSymbolImpl(descriptor), type) ) : this(startOffset, endOffset, origin, IrVariableSymbolImpl(descriptor), type)
@Deprecated("Use constructor which takes symbol instead of descriptor")
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -5,14 +5,9 @@
package org.jetbrains.kotlin.ir.declarations.lazy package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.SymbolTable
class IrLazySymbolTable(private val originalTable: SymbolTable) : ReferenceSymbolTable by originalTable { class IrLazySymbolTable(private val originalTable: SymbolTable) : ReferenceSymbolTable by originalTable {
@@ -158,7 +158,6 @@ fun IrFunction.createParameterDeclarations() {
assert(valueParameters.isEmpty()) assert(valueParameters.isEmpty())
descriptor.valueParameters.mapTo(valueParameters) { it.irValueParameter() } descriptor.valueParameters.mapTo(valueParameters) { it.irValueParameter() }
// valueParameters.mapTo(valueParameters) { it.descriptor.irValueParameter() }
assert(typeParameters.isEmpty()) assert(typeParameters.isEmpty())
descriptor.typeParameters.mapTo(typeParameters) { descriptor.typeParameters.mapTo(typeParameters) {
@@ -331,7 +330,6 @@ fun IrCall.isSuperToAny() = superQualifier?.let { this.symbol.owner.isFakeOverri
fun IrDeclaration.isEffectivelyExternal(): Boolean { fun IrDeclaration.isEffectivelyExternal(): Boolean {
return when (this) { return when (this) {
is IrConstructor -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
is IrFunction -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal() is IrFunction -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
is IrField -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal() is IrField -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
is IrClass -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal() is IrClass -> isExternal || parent is IrDeclaration && parent.isEffectivelyExternal()
@@ -339,7 +337,7 @@ fun IrDeclaration.isEffectivelyExternal(): Boolean {
} }
} }
val IrDeclaration.isDynamic get() = this is IrFunction && dispatchReceiverParameter?.type is IrDynamicType fun IrDeclaration.isDynamic() = this is IrFunction && dispatchReceiverParameter?.type is IrDynamicType
fun IrValueParameter.copy(newDescriptor: ParameterDescriptor): IrValueParameter { fun IrValueParameter.copy(newDescriptor: ParameterDescriptor): IrValueParameter {
assert(this.descriptor.type == newDescriptor.type) assert(this.descriptor.type == newDescriptor.type)