diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 400cc7c57f0..f7d463aed40 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.codegen.FunctionCodegen import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.ir.declarations.IrConstructor import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.psi.KtParameter @@ -46,8 +47,7 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class fun generate() { try { doGenerate() - } - catch (e: Throwable) { + } catch (e: Throwable) { throw RuntimeException("${e.message} while generating code for:\n${irFunction.dump()}", e) } } @@ -75,7 +75,7 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class private fun calculateMethodFlags(isStatic: Boolean): Int { var flags = AsmUtil.getMethodAsmFlags(descriptor, OwnerKind.IMPLEMENTATION, state).or(if (isStatic) Opcodes.ACC_STATIC else 0).xor( - if (DescriptorUtils.isAnnotationClass(descriptor.containingDeclaration)) Opcodes.ACC_FINAL else 0/*TODO*/ + if (DescriptorUtils.isAnnotationClass(descriptor.containingDeclaration)) Opcodes.ACC_FINAL else 0/*TODO*/ ).or(if (descriptor is JvmDescriptorWithExtraFlags) descriptor.extraFlags else 0) if (irFunction.origin == DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER) { @@ -91,10 +91,12 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class } open protected fun createMethod(flags: Int, signature: JvmMethodGenericSignature): MethodVisitor { - return classCodegen.visitor.newMethod(irFunction.OtherOrigin, - flags, - signature.asmMethod.name, signature.asmMethod.descriptor, - signature.genericsSignature, null/*TODO support exception*/) + return classCodegen.visitor.newMethod( + irFunction.OtherOrigin, + flags, + signature.asmMethod.name, signature.asmMethod.descriptor, + signature.genericsSignature, null/*TODO support exception*/ + ) } private fun generateAnnotationDefaultValueIfNeeded(methodVisitor: MethodVisitor) { @@ -104,7 +106,8 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class (source.getPsi() as? KtParameter)?.defaultValue?.apply { val defaultValue = this val constant = org.jetbrains.kotlin.codegen.ExpressionCodegen.getCompileTimeConstant( - defaultValue, state.bindingContext, true, state.shouldInlineConstVals) + defaultValue, state.bindingContext, true, state.shouldInlineConstVals + ) assert(!state.classBuilderMode.generateBodies || constant != null) { "Default value for annotation parameter should be compile time value: " + defaultValue.text } if (constant != null) { val annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(methodVisitor, classCodegen, state.typeMapper) @@ -116,18 +119,18 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class } fun createFrameMapWithReceivers( - state: GenerationState, - function: FunctionDescriptor, - signature: JvmMethodSignature, - isStatic: Boolean + state: GenerationState, + function: FunctionDescriptor, + signature: JvmMethodSignature, + isStatic: Boolean ): FrameMap { val frameMap = FrameMap() if (!isStatic) { val descriptorForThis = - if (function is ClassConstructorDescriptor) - function.containingDeclaration.thisAsReceiverParameter - else - function.dispatchReceiverParameter + if (function is ClassConstructorDescriptor) + function.containingDeclaration.thisAsReceiverParameter + else + function.dispatchReceiverParameter frameMap.enter(descriptorForThis, AsmTypes.OBJECT_TYPE) } @@ -137,12 +140,10 @@ fun createFrameMapWithReceivers( val receiverParameter = function.extensionReceiverParameter if (receiverParameter != null) { frameMap.enter(receiverParameter, state.typeMapper.mapType(receiverParameter)) - } - else { + } else { frameMap.enterTemp(parameter.asmType) } - } - else if (parameter.kind != JvmMethodParameterKind.VALUE) { + } else if (parameter.kind != JvmMethodParameterKind.VALUE) { frameMap.enterTemp(parameter.asmType) } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt index 36d8bb4424e..1dfa9152c5c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt @@ -89,8 +89,8 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { val functions = irClass.declarations.filterIsInstance().filterNot { val descriptor = it.descriptor descriptor is ConstructorDescriptor || - DescriptorUtils.isStaticDeclaration(descriptor) || - !descriptor.kind.isReal + DescriptorUtils.isStaticDeclaration(descriptor) || + !descriptor.kind.isReal } functions.forEach { @@ -105,8 +105,7 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { if (!memberDescriptor.kind.isReal && findInterfaceImplementation(memberDescriptor) == null) { if (memberDescriptor is FunctionDescriptor) { generateBridges(memberDescriptor, irClass) - } - else if (memberDescriptor is PropertyDescriptor) { + } else if (memberDescriptor is PropertyDescriptor) { val getter = memberDescriptor.getter if (getter != null) { generateBridges(getter, irClass) @@ -133,44 +132,47 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { val bridgesToGenerate: Set> if (!isSpecial) { bridgesToGenerate = generateBridgesForFunctionDescriptor( - descriptor, - getSignatureMapper(typeMapper), - DECLARATION_AND_DEFINITION_CHECKER + descriptor, + getSignatureMapper(typeMapper), + DECLARATION_AND_DEFINITION_CHECKER ) if (!bridgesToGenerate.isEmpty()) { val origin = if (descriptor.kind == DECLARATION) getSourceFromDescriptor(descriptor) else null - val isSpecialBridge = BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(descriptor) != null + val isSpecialBridge = + BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(descriptor) != null for (bridge in bridgesToGenerate) { irClass.declarations.add(createBridge(origin, descriptor, bridge.from, bridge.to, isSpecialBridge, false)) } } - } - else { + } else { val specials = BuiltinSpecialBridgesUtil.generateBridgesForBuiltinSpecial( - descriptor, - getSignatureMapper(typeMapper), - DECLARATION_AND_DEFINITION_CHECKER + descriptor, + getSignatureMapper(typeMapper), + DECLARATION_AND_DEFINITION_CHECKER ) if (!specials.isEmpty()) { val origin = if (descriptor.kind == DECLARATION) getSourceFromDescriptor(descriptor) else null for (bridge in specials) { - irClass.declarations.add(createBridge( + irClass.declarations.add( + createBridge( origin, descriptor, bridge.from, bridge.to, - bridge.isSpecial, bridge.isDelegateToSuper)) + bridge.isSpecial, bridge.isDelegateToSuper + ) + ) } } if (!descriptor.kind.isReal && isAbstractMethod(descriptor, OwnerKind.IMPLEMENTATION)) { - descriptor.getOverriddenBuiltinReflectingJvmDescriptor() ?: - error("Expect to find overridden descriptors for $descriptor") + descriptor.getOverriddenBuiltinReflectingJvmDescriptor() + ?: error("Expect to find overridden descriptors for $descriptor") if (!isThereOverriddenInKotlinClass(descriptor)) { val flags = Opcodes.ACC_ABSTRACT or getVisibilityAccessFlag(descriptor) val bridgeDescriptor = JvmFunctionDescriptorImpl( - descriptor.containingDeclaration as ClassDescriptor, null, Annotations.EMPTY, - descriptor.name, CallableMemberDescriptor.Kind.SYNTHESIZED, descriptor.source, flags + descriptor.containingDeclaration as ClassDescriptor, null, Annotations.EMPTY, + descriptor.name, CallableMemberDescriptor.Kind.SYNTHESIZED, descriptor.source, flags ) val irFunction = IrFunctionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.DEFINED, bridgeDescriptor) irClass.declarations.add(irFunction) @@ -180,26 +182,27 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { } private fun createBridge( - origin: PsiElement?, - descriptor: FunctionDescriptor, - bridge: SignatureAndDescriptor, - delegateTo: SignatureAndDescriptor, - isSpecialBridge: Boolean, - isStubDeclarationWithDelegationToSuper: Boolean + origin: PsiElement?, + descriptor: FunctionDescriptor, + bridge: SignatureAndDescriptor, + delegateTo: SignatureAndDescriptor, + isSpecialBridge: Boolean, + isStubDeclarationWithDelegationToSuper: Boolean ): IrFunction { val isSpecialOrDelegationToSuper = isSpecialBridge || isStubDeclarationWithDelegationToSuper - val flags = ACC_PUBLIC or ACC_BRIDGE or (if (!isSpecialOrDelegationToSuper) ACC_SYNTHETIC else 0) or if (isSpecialBridge) ACC_FINAL else 0 // TODO. + val flags = + ACC_PUBLIC or ACC_BRIDGE or (if (!isSpecialOrDelegationToSuper) ACC_SYNTHETIC else 0) or if (isSpecialBridge) ACC_FINAL else 0 // TODO. val containingClass = descriptor.containingDeclaration as ClassDescriptor //here some 'isSpecialBridge' magic val bridgeDescriptor = JvmFunctionDescriptorImpl( - containingClass, null, Annotations.EMPTY, Name.identifier(bridge.method.name), - CallableMemberDescriptor.Kind.SYNTHESIZED, descriptor.source, flags + containingClass, null, Annotations.EMPTY, Name.identifier(bridge.method.name), + CallableMemberDescriptor.Kind.SYNTHESIZED, descriptor.source, flags ) bridgeDescriptor.initialize( - null, containingClass.thisAsReceiverParameter, emptyList(), - bridge.descriptor.valueParameters.map { it.copy(bridgeDescriptor, it.name, it.index) }, - bridge.descriptor.returnType, Modality.OPEN, descriptor.visibility + null, containingClass.thisAsReceiverParameter, emptyList(), + bridge.descriptor.valueParameters.map { it.copy(bridgeDescriptor, it.name, it.index) }, + bridge.descriptor.returnType, Modality.OPEN, descriptor.visibility ) val irFunction = IrFunctionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.DEFINED, bridgeDescriptor) @@ -212,12 +215,27 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { } val implementation = if (isSpecialBridge) delegateTo.descriptor.copyAsDeclaration() else delegateTo.descriptor - val call = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, - implementation, - null, JvmLoweredStatementOrigin.BRIDGE_DELEGATION, null) - call.dispatchReceiver = IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, containingClass.thisAsReceiverParameter, JvmLoweredStatementOrigin.BRIDGE_DELEGATION) + val call = IrCallImpl( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, + implementation, + null, JvmLoweredStatementOrigin.BRIDGE_DELEGATION, null + ) + call.dispatchReceiver = IrGetValueImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + containingClass.thisAsReceiverParameter, + JvmLoweredStatementOrigin.BRIDGE_DELEGATION + ) bridgeDescriptor.valueParameters.mapIndexed { i, valueParameterDescriptor -> - call.putValueArgument(i, IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, valueParameterDescriptor, JvmLoweredStatementOrigin.BRIDGE_DELEGATION)) + call.putValueArgument( + i, + IrGetValueImpl( + UNDEFINED_OFFSET, + UNDEFINED_OFFSET, + valueParameterDescriptor, + JvmLoweredStatementOrigin.BRIDGE_DELEGATION + ) + ) } +IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, bridgeDescriptor, call) }.apply { @@ -228,25 +246,26 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { } private fun IrBlockBodyBuilder.generateTypeCheckBarrierIfNeeded( - overrideDescriptor: FunctionDescriptor, - bridgeDescriptor: FunctionDescriptor, - delegateParameterTypes: Array? + overrideDescriptor: FunctionDescriptor, + bridgeDescriptor: FunctionDescriptor, + delegateParameterTypes: Array? ) { - val typeSafeBarrierDescription = BuiltinMethodsWithSpecialGenericSignature.getDefaultValueForOverriddenBuiltinFunction(overrideDescriptor) ?: return + val typeSafeBarrierDescription = + BuiltinMethodsWithSpecialGenericSignature.getDefaultValueForOverriddenBuiltinFunction(overrideDescriptor) ?: return - BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(overrideDescriptor) ?: - error("Overridden built-in method should not be null for " + overrideDescriptor) + BuiltinMethodsWithSpecialGenericSignature.getOverriddenBuiltinFunctionWithErasedValueParametersInJava(overrideDescriptor) + ?: error("Overridden built-in method should not be null for " + overrideDescriptor) val conditions = bridgeDescriptor.valueParameters.withIndex().filter { (i, parameterDescriptor) -> typeSafeBarrierDescription.checkParameter(i) || - !(delegateParameterTypes == null || OBJECT_TYPE == delegateParameterTypes[i]) || - !TypeUtils.isNullableType(parameterDescriptor.type) + !(delegateParameterTypes == null || OBJECT_TYPE == delegateParameterTypes[i]) || + !TypeUtils.isNullableType(parameterDescriptor.type) }.map { (i, parameterDescriptor) -> - val checkValue = IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, parameterDescriptor, JvmLoweredStatementOrigin.BRIDGE_DELEGATION) + val checkValue = + IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, parameterDescriptor, JvmLoweredStatementOrigin.BRIDGE_DELEGATION) if (delegateParameterTypes == null || OBJECT_TYPE == delegateParameterTypes[i]) { irNotEquals(checkValue, irNull()) - } - else { + } else { irIs(checkValue, overrideDescriptor.valueParameters[i].type) } } @@ -258,13 +277,14 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { +irIfThen(irNot(condition), irBlock { +irReturn( - when (typeSafeBarrierDescription) { - MAP_GET_OR_DEFAULT -> irGet(IrVariableSymbolImpl(bridgeDescriptor.valueParameters[1])) - BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.NULL -> irNull() - INDEX -> IrConstImpl.int( - UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.builtIns.intType, typeSafeBarrierDescription.defaultValue as Int) - FALSE -> irFalse() - } + when (typeSafeBarrierDescription) { + MAP_GET_OR_DEFAULT -> irGet(IrVariableSymbolImpl(bridgeDescriptor.valueParameters[1])) + BuiltinMethodsWithSpecialGenericSignature.TypeSafeBarrierDescription.NULL -> irNull() + INDEX -> IrConstImpl.int( + UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.builtIns.intType, typeSafeBarrierDescription.defaultValue as Int + ) + FALSE -> irFalse() + } ) } ) @@ -276,14 +296,15 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass { companion object { fun getSignatureMapper(typeMapper: KotlinTypeMapper): Function1 { return fun(descriptor: FunctionDescriptor) = - SignatureAndDescriptor(typeMapper.mapAsmMethod(descriptor), descriptor) + SignatureAndDescriptor(typeMapper.mapAsmMethod(descriptor), descriptor) } fun FunctionDescriptor.copyAsDeclaration(): FunctionDescriptor { val isGetter = this is PropertyGetterDescriptor val isAccessor = this is PropertyAccessorDescriptor val directMember = getDirectMember(this) - val copy = directMember.copy(directMember.containingDeclaration, directMember.modality, directMember.visibility, DECLARATION, false) + val copy = + directMember.copy(directMember.containingDeclaration, directMember.modality, directMember.visibility, DECLARATION, false) if (isAccessor) { val property = copy as PropertyDescriptor return if (isGetter) property.getter!! else property.setter!! diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt index 37c4ccbf231..20d3122f4ad 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt @@ -57,12 +57,16 @@ class InterfaceDelegationLowering(val state: GenerationState) : IrElementTransfo //skip java 8 default methods if (!interfaceFun.isDefinitelyNotDefaultImplsMethod()) { val inheritedFun = - if (classDescriptor !== descriptor) { - InterfaceLowering.createDefaultImplFunDescriptor(descriptor as DefaultImplsClassDescriptorImpl, interfaceFun, classDescriptor, state.typeMapper) - } - else { - value - } + if (classDescriptor !== descriptor) { + InterfaceLowering.createDefaultImplFunDescriptor( + descriptor as DefaultImplsClassDescriptorImpl, + interfaceFun, + classDescriptor, + state.typeMapper + ) + } else { + value + } generateDelegationToDefaultImpl(irClass, interfaceFun, inheritedFun) } } @@ -75,9 +79,11 @@ class InterfaceDelegationLowering(val state: GenerationState) : IrElementTransfo val interfaceDescriptor = interfaceFun.containingDeclaration as ClassDescriptor val defaultImpls = InterfaceLowering.createDefaultImplsClassDescriptor(interfaceDescriptor) - val defaultImplFun = InterfaceLowering.createDefaultImplFunDescriptor(defaultImpls, interfaceFun.original, interfaceDescriptor, state.typeMapper) + val defaultImplFun = + InterfaceLowering.createDefaultImplFunDescriptor(defaultImpls, interfaceFun.original, interfaceDescriptor, state.typeMapper) val returnType = inheritedFun.returnType!! - val irCallImpl = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, defaultImplFun, null, JvmLoweredStatementOrigin.DEFAULT_IMPLS_DELEGATION) + val irCallImpl = + IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, defaultImplFun, null, JvmLoweredStatementOrigin.DEFAULT_IMPLS_DELEGATION) irBody.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, inheritedFun, irCallImpl)) var shift = 0 diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt index 3a4119b19f5..d04f4e5452f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceLowering.kt @@ -49,7 +49,8 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid() val interfaceDescriptor = irClass.descriptor val defaultImplsDescriptor = createDefaultImplsClassDescriptor(interfaceDescriptor) - val defaultImplsIrClass = IrClassImpl(irClass.startOffset, irClass.endOffset, JvmLoweredDeclarationOrigin.DEFAULT_IMPLS, defaultImplsDescriptor) + val defaultImplsIrClass = + IrClassImpl(irClass.startOffset, irClass.endOffset, JvmLoweredDeclarationOrigin.DEFAULT_IMPLS, defaultImplsDescriptor) irClass.declarations.add(defaultImplsIrClass) val members = defaultImplsIrClass.declarations @@ -57,7 +58,8 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid() irClass.declarations.filterIsInstance().forEach { val descriptor = it.descriptor if (descriptor.modality != Modality.ABSTRACT) { - val functionDescriptorImpl = createDefaultImplFunDescriptor(defaultImplsDescriptor, descriptor, interfaceDescriptor, state.typeMapper) + val functionDescriptorImpl = + createDefaultImplFunDescriptor(defaultImplsDescriptor, descriptor, interfaceDescriptor, state.typeMapper) members.add(functionDescriptorImpl.createFunctionAndMapVariables(it)) it.body = null } @@ -71,8 +73,7 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid() val visibility = AsmUtil.getVisibilityAccessFlag(it.descriptor) if (visibility == Opcodes.ACC_PRIVATE && it.descriptor.name != clinitName) { it - } - else null + } else null } val defaultBodies = irClass.declarations.filterIsInstance().filter { @@ -86,14 +87,14 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid() fun createDefaultImplsClassDescriptor(interfaceDescriptor: ClassDescriptor): DefaultImplsClassDescriptorImpl { return DefaultImplsClassDescriptorImpl( - Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME), interfaceDescriptor, interfaceDescriptor.source + Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME), interfaceDescriptor, interfaceDescriptor.source ) } fun createDefaultImplFunDescriptor( - defaultImplsDescriptor: DefaultImplsClassDescriptorImpl, - descriptor: FunctionDescriptor, - interfaceDescriptor: ClassDescriptor, typeMapper: KotlinTypeMapper + defaultImplsDescriptor: DefaultImplsClassDescriptorImpl, + descriptor: FunctionDescriptor, + interfaceDescriptor: ClassDescriptor, typeMapper: KotlinTypeMapper ): SimpleFunctionDescriptorImpl { val name = Name.identifier(typeMapper.mapAsmMethod(descriptor).name) return createStaticFunctionWithReceivers(defaultImplsDescriptor, name, descriptor, interfaceDescriptor.defaultType) @@ -102,42 +103,49 @@ class InterfaceLowering(val state: GenerationState) : IrElementTransformerVoid() } -internal fun createStaticFunctionWithReceivers(owner: ClassOrPackageFragmentDescriptor, name: Name, descriptor: FunctionDescriptor, dispatchReceiverType: KotlinType): SimpleFunctionDescriptorImpl { +internal fun createStaticFunctionWithReceivers( + owner: ClassOrPackageFragmentDescriptor, + name: Name, + descriptor: FunctionDescriptor, + dispatchReceiverType: KotlinType +): SimpleFunctionDescriptorImpl { val newFunction = SimpleFunctionDescriptorImpl.create( - owner, - AnnotationsImpl(emptyList()), - name, - CallableMemberDescriptor.Kind.DECLARATION, descriptor.source + owner, + AnnotationsImpl(emptyList()), + name, + CallableMemberDescriptor.Kind.DECLARATION, descriptor.source ) var offset = 0 val dispatchReceiver = - ValueParameterDescriptorImpl.createWithDestructuringDeclarations( - newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("this"), - dispatchReceiverType, false, false, false, null, descriptor.source, null) + ValueParameterDescriptorImpl.createWithDestructuringDeclarations( + newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("this"), + dispatchReceiverType, false, false, false, null, descriptor.source, null + ) val extensionReceiver = - descriptor.extensionReceiverParameter?.let { extensionReceiver -> - ValueParameterDescriptorImpl.createWithDestructuringDeclarations( - newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("receiver"), - extensionReceiver.value.type, false, false, false, null, extensionReceiver.source, null) - } + descriptor.extensionReceiverParameter?.let { extensionReceiver -> + ValueParameterDescriptorImpl.createWithDestructuringDeclarations( + newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("receiver"), + extensionReceiver.value.type, false, false, false, null, extensionReceiver.source, null + ) + } val valueParameters = listOfNotNull(dispatchReceiver, extensionReceiver) + - descriptor.valueParameters.map { it.copy(newFunction, it.name, it.index + offset) } + descriptor.valueParameters.map { it.copy(newFunction, it.name, it.index + offset) } newFunction.initialize( - null, null, emptyList()/*TODO: type parameters*/, - valueParameters, descriptor.returnType, Modality.FINAL, descriptor.visibility + null, null, emptyList()/*TODO: type parameters*/, + valueParameters, descriptor.returnType, Modality.FINAL, descriptor.visibility ) return newFunction } internal fun FunctionDescriptor.createFunctionAndMapVariables(oldFunction: IrFunction) = - IrFunctionImpl(oldFunction.startOffset, oldFunction.endOffset, oldFunction.origin, this, oldFunction.body).also { - val mapping: Map = - ( - listOfNotNull(oldFunction.descriptor.dispatchReceiverParameter!!, oldFunction.descriptor.extensionReceiverParameter) + + IrFunctionImpl(oldFunction.startOffset, oldFunction.endOffset, oldFunction.origin, this, oldFunction.body).also { + val mapping: Map = + ( + listOfNotNull(oldFunction.descriptor.dispatchReceiverParameter!!, oldFunction.descriptor.extensionReceiverParameter) + oldFunction.descriptor.valueParameters ).zip(this.valueParameters).toMap() - it.body?.transform(VariableRemapper(mapping), null) - } + it.body?.transform(VariableRemapper(mapping), null) + }