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 8aa37e534c5..c0ca53af039 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 @@ -14,13 +14,12 @@ import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.annotations.Annotations 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.buildConstructor import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.declarations.buildReceiverParameter import org.jetbrains.kotlin.ir.builders.declarations.buildTypeParameter import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.descriptors.* @@ -28,7 +27,6 @@ import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.* @@ -40,7 +38,6 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource import java.io.StringWriter - fun ir2string(ir: IrElement?): String = ir?.render() ?: "" // NB: this function is used in native @@ -55,20 +52,16 @@ fun IrClass.addSimpleDelegatingConstructor( irBuiltIns: IrBuiltIns, isPrimary: Boolean = false, origin: IrDeclarationOrigin? = null -) = WrappedClassConstructorDescriptor().let { descriptor -> - IrConstructorImpl( - startOffset, endOffset, - origin ?: this.origin, - IrConstructorSymbolImpl(descriptor), - superConstructor.name, - superConstructor.visibility, - defaultType, - isInline = false, - isExternal = false, - isPrimary = isPrimary, - isExpect = false - ).also { constructor -> - descriptor.bind(constructor) +): IrConstructor = + buildConstructor { + val klass = this@addSimpleDelegatingConstructor + this.startOffset = klass.startOffset + this.endOffset = klass.endOffset + this.origin = origin ?: klass.origin + this.visibility = superConstructor.visibility + this.returnType = klass.defaultType + this.isPrimary = isPrimary + }.also { constructor -> constructor.parent = this declarations += constructor @@ -92,7 +85,6 @@ fun IrClass.addSimpleDelegatingConstructor( ) ) } -} val IrCall.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true val IrFunctionReference.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true 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 de6f902ad7d..b1883332329 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 @@ -13,12 +13,11 @@ import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.builders.* +import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor import org.jetbrains.kotlin.ir.expressions.* @@ -26,7 +25,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.classifierOrFail @@ -378,20 +376,15 @@ abstract class AbstractSuspendFunctionsLowering(val co ) } - fun buildConstructor(): IrConstructor = WrappedClassConstructorDescriptor().let { d -> - IrConstructorImpl( - startOffset, endOffset, - DECLARATION_ORIGIN_COROUTINE_IMPL, - IrConstructorSymbolImpl(d), - coroutineBaseClassConstructor.name, - irFunction.visibility, - coroutineClass.defaultType, - isInline = false, - isExternal = false, - isPrimary = true, - isExpect = false - ).apply { - d.bind(this) + fun buildConstructor(): IrConstructor = + buildConstructor { + startOffset = irFunction.startOffset + endOffset = irFunction.endOffset + origin = DECLARATION_ORIGIN_COROUTINE_IMPL + visibility = irFunction.visibility + returnType = coroutineClass.defaultType + isPrimary = true + }.apply { parent = coroutineClass coroutineClass.declarations += this coroutineConstructors += this @@ -422,22 +415,15 @@ abstract class AbstractSuspendFunctionsLowering(val co } } } - } - private fun buildFactoryConstructor(boundParams: List) = WrappedClassConstructorDescriptor().let { d -> - IrConstructorImpl( - startOffset, endOffset, - DECLARATION_ORIGIN_COROUTINE_IMPL, - IrConstructorSymbolImpl(d), - coroutineBaseClassConstructor.name, - irFunction.visibility, - coroutineClass.defaultType, - isInline = false, - isExternal = false, - isPrimary = false, - isExpect = false - ).apply { - d.bind(this) + private fun buildFactoryConstructor(boundParams: List): IrConstructor = + buildConstructor { + startOffset = irFunction.startOffset + endOffset = irFunction.endOffset + origin = DECLARATION_ORIGIN_COROUTINE_IMPL + visibility = irFunction.visibility + returnType = coroutineClass.defaultType + }.apply { parent = coroutineClass coroutineClass.declarations += this coroutineConstructors += this @@ -464,7 +450,6 @@ abstract class AbstractSuspendFunctionsLowering(val co } } } - } private fun buildCreateMethod( unboundArgs: List, 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 e9c5c144163..f71cbe024f4 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 @@ -17,19 +17,17 @@ import org.jetbrains.kotlin.ir.IrStatement 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.buildConstructor import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol import org.jetbrains.kotlin.ir.symbols.IrValueSymbol -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl @@ -43,7 +41,6 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.name.Name -import java.util.* interface LocalNameProvider { fun localName(declaration: IrDeclarationWithName): String = @@ -693,22 +690,11 @@ class LocalDeclarationsLowering( val localClassContext = localClasses[oldDeclaration.parent]!! val capturedValues = localClassContext.closure.capturedValues - val newDescriptor = WrappedClassConstructorDescriptor(oldDeclaration.descriptor.annotations, oldDeclaration.descriptor.source) - val newSymbol = IrConstructorSymbolImpl(newDescriptor) - - val loweredConstructorVisibility = - visibilityPolicy.forConstructor(oldDeclaration, constructorContext.inInlineFunctionScope) - - val newDeclaration = IrConstructorImpl( - oldDeclaration.startOffset, oldDeclaration.endOffset, oldDeclaration.origin, - newSymbol, oldDeclaration.name, loweredConstructorVisibility, oldDeclaration.returnType, - isInline = oldDeclaration.isInline, - isExternal = oldDeclaration.isExternal, - isPrimary = oldDeclaration.isPrimary, - isExpect = oldDeclaration.isExpect - ) - - newDescriptor.bind(newDeclaration) + val newDeclaration = buildConstructor(oldDeclaration.descriptor) { + updateFrom(oldDeclaration) + visibility = visibilityPolicy.forConstructor(oldDeclaration, constructorContext.inInlineFunctionScope) + returnType = oldDeclaration.returnType + } constructorContext.transformedDeclaration = newDeclaration 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 cbf51920a63..cb77575ea36 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 @@ -143,8 +143,11 @@ internal fun IrFunctionBuilder.buildFunction(originalDescriptor: FunctionDescrip } } -fun IrFunctionBuilder.buildConstructor(): IrConstructor { - val wrappedDescriptor = WrappedClassConstructorDescriptor() +@PublishedApi +internal fun IrFunctionBuilder.buildConstructor(originalDescriptor: ConstructorDescriptor?): IrConstructor { + val wrappedDescriptor = + if (originalDescriptor != null) WrappedClassConstructorDescriptor(originalDescriptor.annotations, originalDescriptor.source) + else WrappedClassConstructorDescriptor() return IrConstructorImpl( startOffset, endOffset, origin, IrConstructorSymbolImpl(wrappedDescriptor), @@ -192,10 +195,10 @@ fun IrDeclarationContainer.addFunction( } } -inline fun buildConstructor(builder: IrFunctionBuilder.() -> Unit): IrConstructor = +inline fun buildConstructor(originalDescriptor: ConstructorDescriptor? = null, builder: IrFunctionBuilder.() -> Unit): IrConstructor = IrFunctionBuilder().run { builder() - buildConstructor() + buildConstructor(originalDescriptor) } inline fun IrClass.addConstructor(builder: IrFunctionBuilder.() -> Unit = {}): IrConstructor = diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsDeclarationFactory.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsDeclarationFactory.kt index abeb2e00f76..15dfabe579e 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsDeclarationFactory.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsDeclarationFactory.kt @@ -17,12 +17,10 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.backend.js.JsMapping import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder import org.jetbrains.kotlin.ir.backend.js.utils.Namer +import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.defaultType @@ -99,23 +97,10 @@ class JsDeclarationFactory(mapping: JsMapping) : DeclarationFactory { val irClass = oldConstructor.parent as IrClass val outerThisType = (irClass.parent as IrClass).defaultType - val descriptor = WrappedClassConstructorDescriptor(oldConstructor.descriptor.annotations, oldConstructor.descriptor.source) - val symbol = IrConstructorSymbolImpl(descriptor) - - val newConstructor = IrConstructorImpl( - oldConstructor.startOffset, - oldConstructor.endOffset, - oldConstructor.origin, - symbol, - oldConstructor.name, - oldConstructor.visibility, - oldConstructor.returnType, - isInline = oldConstructor.isInline, - isExternal = oldConstructor.isExternal, - isPrimary = oldConstructor.isPrimary, - isExpect = oldConstructor.isExpect - ).also { - descriptor.bind(it) + val newConstructor = buildConstructor(oldConstructor.descriptor) { + updateFrom(oldConstructor) + returnType = oldConstructor.returnType + }.also { it.parent = oldConstructor.parent } diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt index dd44c4397dc..63ca4a72aff 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/EnumClassLowering.kt @@ -22,15 +22,16 @@ import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder import org.jetbrains.kotlin.ir.backend.js.utils.toJsArrayLiteral import org.jetbrains.kotlin.ir.builders.* +import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor import org.jetbrains.kotlin.ir.builders.declarations.buildField import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.expressions.impl.* -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.makeNullable @@ -119,23 +120,10 @@ class EnumClassConstructorLowering(val context: JsCommonBackendContext) : Declar } private fun transformEnumConstructor(enumConstructor: IrConstructor, enumClass: IrClass): IrConstructor { - val loweredConstructorDescriptor = WrappedClassConstructorDescriptor() - val loweredConstructorSymbol = IrConstructorSymbolImpl(loweredConstructorDescriptor) - - return IrConstructorImpl( - enumConstructor.startOffset, - enumConstructor.endOffset, - enumConstructor.origin, - loweredConstructorSymbol, - enumConstructor.name, - enumConstructor.visibility, - enumConstructor.returnType, - isInline = enumConstructor.isInline, - isExternal = enumConstructor.isExternal, - isPrimary = enumConstructor.isPrimary, - isExpect = enumConstructor.isExpect - ).apply { - loweredConstructorDescriptor.bind(this) + return buildConstructor { + updateFrom(enumConstructor) + returnType = enumConstructor.returnType + }.apply { parent = enumClass valueParameters += JsIrBuilder.buildValueParameter(this, "name", 0, context.irBuiltIns.stringType) valueParameters += JsIrBuilder.buildValueParameter(this, "ordinal", 1, context.irBuiltIns.intType) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt index 6104dadfddb..c5e0ce1ae0a 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/AbstractSuspendFunctionsLowering.kt @@ -14,12 +14,11 @@ import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.backend.js.lower.CallableReferenceLowering import org.jetbrains.kotlin.ir.builders.* +import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor import org.jetbrains.kotlin.ir.expressions.* @@ -27,7 +26,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.classifierOrFail @@ -253,49 +251,43 @@ abstract class AbstractSuspendFunctionsLowering(val co } } - return WrappedClassConstructorDescriptor().let { d -> - IrConstructorImpl( - startOffset, endOffset, - DECLARATION_ORIGIN_COROUTINE_IMPL, - IrConstructorSymbolImpl(d), - coroutineBaseClassConstructor.name, - function.visibility, - coroutineClass.defaultType, - isInline = false, - isExternal = false, - isPrimary = true, - isExpect = false - ).apply { - d.bind(this) - parent = coroutineClass - coroutineClass.addChild(this) + return buildConstructor { + startOffset = function.startOffset + endOffset = function.endOffset + origin = DECLARATION_ORIGIN_COROUTINE_IMPL + name = coroutineBaseClassConstructor.name + visibility = function.visibility + returnType = coroutineClass.defaultType + isPrimary = true + }.apply { + parent = coroutineClass + coroutineClass.addChild(this) - valueParameters = functionParameters.mapIndexed { index, parameter -> - parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, defaultValue = null) + valueParameters = functionParameters.mapIndexed { index, parameter -> + parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, defaultValue = null) + } + val continuationParameter = coroutineBaseClassConstructor.valueParameters[0] + valueParameters += continuationParameter.copyTo( + this, DECLARATION_ORIGIN_COROUTINE_IMPL, + index = valueParameters.size, + type = continuationType, + defaultValue = null + ) + + val irBuilder = context.createIrBuilder(symbol, startOffset, endOffset) + body = irBuilder.irBlockBody { + val completionParameter = valueParameters.last() + +irDelegatingConstructorCall(coroutineBaseClassConstructor).apply { + putValueArgument(0, irGet(completionParameter)) } - val continuationParameter = coroutineBaseClassConstructor.valueParameters[0] - valueParameters += continuationParameter.copyTo( - this, DECLARATION_ORIGIN_COROUTINE_IMPL, - index = valueParameters.size, - type = continuationType, - defaultValue = null - ) + +IrInstanceInitializerCallImpl(startOffset, endOffset, coroutineClass.symbol, context.irBuiltIns.unitType) - val irBuilder = context.createIrBuilder(symbol, startOffset, endOffset) - body = irBuilder.irBlockBody { - val completionParameter = valueParameters.last() - +irDelegatingConstructorCall(coroutineBaseClassConstructor).apply { - putValueArgument(0, irGet(completionParameter)) - } - +IrInstanceInitializerCallImpl(startOffset, endOffset, coroutineClass.symbol, context.irBuiltIns.unitType) - - functionParameters.forEachIndexed { index, parameter -> - +irSetField( - irGet(coroutineClassThis), - argumentToPropertiesMap.getValue(parameter), - irGet(valueParameters[index]) - ) - } + functionParameters.forEachIndexed { index, parameter -> + +irSetField( + irGet(coroutineClassThis), + argumentToPropertiesMap.getValue(parameter), + irGet(valueParameters[index]) + ) } } } 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 00f2c4c7c61..c180fc03304 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 @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor import org.jetbrains.kotlin.ir.builders.declarations.buildField import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter @@ -27,12 +28,9 @@ import org.jetbrains.kotlin.ir.builders.irCall import org.jetbrains.kotlin.ir.builders.setSourceRange import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.load.java.JavaVisibilities import org.jetbrains.kotlin.load.java.JvmAbi @@ -103,22 +101,11 @@ class JvmDeclarationFactory( return originalInnerClassPrimaryConstructorByClass[innerClass] } - private fun createInnerClassConstructorWithOuterThisParameter(oldConstructor: IrConstructor): IrConstructor { - val newDescriptor = WrappedClassConstructorDescriptor(oldConstructor.descriptor.annotations) - return IrConstructorImpl( - oldConstructor.startOffset, - oldConstructor.endOffset, - oldConstructor.origin, - IrConstructorSymbolImpl(newDescriptor), - oldConstructor.name, - oldConstructor.visibility, - oldConstructor.returnType, - isInline = oldConstructor.isInline, - isExternal = oldConstructor.isExternal, - isPrimary = oldConstructor.isPrimary, - isExpect = oldConstructor.isExpect - ).apply { - newDescriptor.bind(this) + private fun createInnerClassConstructorWithOuterThisParameter(oldConstructor: IrConstructor): IrConstructor = + buildConstructor(oldConstructor.descriptor) { + updateFrom(oldConstructor) + returnType = oldConstructor.returnType + }.apply { annotations = oldConstructor.annotations.map { it.deepCopyWithSymbols(this) } parent = oldConstructor.parent returnType = oldConstructor.returnType @@ -133,7 +120,6 @@ class JvmDeclarationFactory( valueParameters = listOf(outerThisValueParameter) + oldConstructor.valueParameters.map { it.copyTo(this, index = it.index + 1) } metadata = oldConstructor.metadata } - } override fun getFieldForObjectInstance(singleton: IrClass): IrField = singletonFieldDeclarations.getOrPut(singleton) { 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 e3d72a181e0..c8c946840dc 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 @@ -14,12 +14,10 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET +import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.declarations.* -import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl -import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor import org.jetbrains.kotlin.ir.expressions.impl.* -import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.types.defaultType import org.jetbrains.kotlin.ir.util.allTypeParameters import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols @@ -119,20 +117,12 @@ private class JvmOverloadsAnnotationLowering(val context: JvmBackendContext) : C private fun generateWrapperHeader(oldFunction: IrFunction, numDefaultParametersToExpect: Int): IrFunction { val res = when (oldFunction) { is IrConstructor -> { - val descriptor = WrappedClassConstructorDescriptor(oldFunction.descriptor.annotations) - IrConstructorImpl( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, - JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER, - IrConstructorSymbolImpl(descriptor), - oldFunction.name, - oldFunction.visibility, - returnType = oldFunction.returnType, - isInline = oldFunction.isInline, - isExternal = false, - isPrimary = false, - isExpect = false - ).apply { - descriptor.bind(this) + buildConstructor(oldFunction.descriptor) { + origin = JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER + name = oldFunction.name + visibility = oldFunction.visibility + returnType = oldFunction.returnType + isInline = oldFunction.isInline } } is IrSimpleFunction -> buildFun(oldFunction.descriptor) {