diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt index af309bc09a3..c5073c33c6d 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionNVarargBridgeLowering.kt @@ -53,7 +53,7 @@ private class FunctionNVarargBridgeLowering(val context: JvmBackendContext) : expression.symbol.owner.name.asString() != "invoke" ) return super.visitFunctionAccess(expression) - return context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol).run { + return context.createJvmIrBuilder(currentScope!!).run { at(expression) irCall(functionNInvokeFun).apply { dispatchReceiver = irImplicitCast( diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt index 6d7c7e36cab..bb49f784027 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt @@ -401,24 +401,6 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) val proxyFunBody = IrBlockBodyImpl(startOffset, endOffset).also { proxyFun.body = it } when { - targetFun.isArrayOf() -> { - // Lower arrayOf-like function in place. - // TODO it seems that VarargLowering does a little bit too much. - // Maybe worth decomposing it into varargs part and arrayOf intrinsics part. - val varargParameter = proxyFun.valueParameters.singleOrNull { it.isVararg } - ?: throw AssertionError( - "Proxy for *arrayOf should have single vararg parameter:\n" + - proxyFun.valueParameters.joinToString(separator = "\n") { it.dump() } - ) - proxyFunBody.statements.add( - IrReturnImpl( - startOffset, endOffset, - context.irBuiltIns.nothingType, - proxyFun.symbol, - IrGetValueImpl(startOffset, endOffset, varargParameter.symbol, null) - ) - ) - } targetFun.returnType.isUnit() -> { proxyFunBody.statements.add(targetCall) } @@ -510,7 +492,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) ): IrCall { val notNullSamType = samType.makeNotNull() .removeAnnotations { it.type.classFqName in specialNullabilityAnnotationsFqNames } - return context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol).run { + return context.createJvmIrBuilder(currentScope!!).run { // See [org.jetbrains.kotlin.backend.jvm.JvmSymbols::indyLambdaMetafactoryIntrinsic]. irCall(jvmIndyLambdaMetafactoryIntrinsic, notNullSamType).apply { putTypeArgument(0, notNullSamType) @@ -655,7 +637,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) private val receiverField = context.ir.symbols.functionReferenceReceiverField.owner - fun build(): IrExpression = context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol).run { + fun build(): IrExpression = context.createJvmIrBuilder(currentScope!!).run { irBlock(irFunctionReference.startOffset, irFunctionReference.endOffset) { val constructor = createConstructor() val boundReceiverVar = @@ -892,12 +874,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) }?.let { putArgument(callee, parameter, it) } } } - irExprBody( - if (irFunctionReference.symbol.owner.isArrayOf()) - call.transform(VarargLowering(this@FunctionReferenceLowering.context), null) - else - call - ) + irExprBody(call) } } diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt index 88ff474aa0f..802dcff8bae 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmInlineClassLowering.kt @@ -47,7 +47,7 @@ val jvmInlineClassPhase = makeIrFilePhase( // forLoopsPhase may produce UInt and ULong which are inline classes. // Standard library replacements are done on the unmangled names for UInt and ULong classes. // Collection stubs may require mangling by inline class rules. - prerequisite = setOf(forLoopsPhase, jvmStandardLibraryBuiltInsPhase, collectionStubMethodLowering) + prerequisite = setOf(forLoopsPhase, jvmBuiltInsPhase, collectionStubMethodLowering) ) /** diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt index fecf1a74124..01ec6878f9c 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmStringConcatenationLowering.kt @@ -132,7 +132,7 @@ private class JvmStringConcatenationLowering(val context: JvmBackendContext) : F override fun visitStringConcatenation(expression: IrStringConcatenation): IrExpression { expression.transformChildrenVoid(this) - return context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset).run { + return context.createJvmIrBuilder(currentScope!!, expression).run { // When `String.plus(Any?)` is invoked with receiver of platform type String or String with enhanced nullability, this could // fail a nullability check (NullPointerException) on the receiver. However, the non-IR backend currently does NOT insert this // check (see KT-36625, pending language design decision). To maintain compatibility with the non-IR backend, we remove @@ -203,7 +203,7 @@ private class JvmDynamicStringConcatenationLowering(val context: JvmBackendConte override fun visitStringConcatenation(expression: IrStringConcatenation): IrExpression { expression.transformChildrenVoid(this) - return context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset).run { + return context.createJvmIrBuilder(currentScope!!, expression).run { // When `String.plus(Any?)` is invoked with receiver of platform type String or String with enhanced nullability, this could // fail a nullability check (NullPointerException) on the receiver. However, the non-IR backend currently does NOT insert this // check (see KT-36625, pending language design decision). To maintain compatibility with the non-IR backend, we remove diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt index 22a9d09d33e..8a4385255b4 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/PropertyReferenceLowering.kt @@ -327,7 +327,7 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : IrEle return createSpecializedKProperty(expression) } val referenceKind = propertyReferenceKindFor(expression) - return context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset).run { + return context.createJvmIrBuilder(currentScope!!, expression).run { val arity = when { boundReceiver != null -> 5 // (receiver, jClass, name, desc, flags) useOptimizedSuperClass -> 4 // (jClass, name, desc, flags) diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/SamDelegatingLambdaBlock.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/SamDelegatingLambdaBlock.kt index 17bf80e48c8..d5b62fd4f60 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/SamDelegatingLambdaBlock.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/SamDelegatingLambdaBlock.kt @@ -77,7 +77,7 @@ internal class SamDelegatingLambdaBuilder(private val jvmContext: JvmBackendCont parent: IrDeclarationParent ): SamDelegatingLambdaBlock { lateinit var ref: IrFunctionReference - val block = jvmContext.createJvmIrBuilder(scopeSymbol, expression.startOffset, expression.endOffset).run { + val block = jvmContext.createJvmIrBuilder(scopeSymbol, expression).run { // { // val tmp = // fun ``(p1: T1, ..., pN: TN): R = @@ -106,7 +106,7 @@ internal class SamDelegatingLambdaBuilder(private val jvmContext: JvmBackendCont lateinit var ref: IrFunctionReference lateinit var ifExpr: IrExpression lateinit var ifNotNullBlock: IrContainerExpression - val block = jvmContext.createJvmIrBuilder(scopeSymbol, expression.startOffset, expression.endOffset).run { + val block = jvmContext.createJvmIrBuilder(scopeSymbol, expression).run { // { // val tmp = // if (tmp == null) @@ -163,7 +163,7 @@ internal class SamDelegatingLambdaBuilder(private val jvmContext: JvmBackendCont lambda.dispatchReceiverParameter = null lambda.extensionReceiverParameter = null lambda.valueParameters = createLambdaValueParameters(superMethod, lambda, typeSubstitutor) - lambda.body = jvmContext.createJvmIrBuilder(lambda.symbol, expression.startOffset, expression.endOffset) + lambda.body = jvmContext.createJvmIrBuilder(lambda.symbol, expression) .irBlockBody { +irReturn( irCall(invokeFunction).also { invokeCall -> diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrBuilder.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrBuilder.kt index a4c0bc47bf7..99c8d36163c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrBuilder.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrBuilder.kt @@ -5,8 +5,10 @@ package org.jetbrains.kotlin.backend.jvm.ir +import org.jetbrains.kotlin.backend.common.ScopeWithIr import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmSymbols +import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope import org.jetbrains.kotlin.ir.builders.IrGeneratorContextBase @@ -34,3 +36,16 @@ fun JvmBackendContext.createJvmIrBuilder( startOffset: Int = UNDEFINED_OFFSET, endOffset: Int = UNDEFINED_OFFSET, ): JvmIrBuilder = JvmIrBuilder(this, symbol, startOffset, endOffset) + + +fun JvmBackendContext.createJvmIrBuilder(symbol: IrSymbol, source: IrElement): JvmIrBuilder = + JvmIrBuilder(this, symbol, source.startOffset, source.endOffset) + +fun JvmBackendContext.createJvmIrBuilder(scopeWithIr: ScopeWithIr): JvmIrBuilder = + JvmIrBuilder(this, scopeWithIr.scope.scopeOwnerSymbol, UNDEFINED_OFFSET, UNDEFINED_OFFSET) + +fun JvmBackendContext.createJvmIrBuilder(scopeWithIr: ScopeWithIr, startOffset: Int, endOffset: Int): JvmIrBuilder = + JvmIrBuilder(this, scopeWithIr.scope.scopeOwnerSymbol, startOffset, endOffset) + +fun JvmBackendContext.createJvmIrBuilder(scopeWithIr: ScopeWithIr, source: IrElement): JvmIrBuilder = + JvmIrBuilder(this, scopeWithIr.scope.scopeOwnerSymbol, source.startOffset, source.endOffset)