JVM_IR minor: more JvmIrBuilder helpers
This commit is contained in:
committed by
TeamCityServer
parent
4339671457
commit
27e5655480
+1
-1
@@ -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(
|
||||
|
||||
+3
-26
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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)
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+3
-3
@@ -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 = <expression>
|
||||
// fun `<anonymous>`(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 = <expression>
|
||||
// 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 ->
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user