Skip to content

Commit 0524f0f

Browse files
mcpiromangoodwinnk
authored andcommitted
[IR] Use *WithShape IR factory functions when needed
Most commonly, when the passed symbol may be unbound. The rest of the code should take the signature from the symbol. KT-70057
1 parent c784482 commit 0524f0f

File tree

20 files changed

+216
-132
lines changed

20 files changed

+216
-132
lines changed

compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrBuiltinSymbolsContainer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.types.isBoolean
2525
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
2626
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
2727
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
28+
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImplWithShape
2829
import org.jetbrains.kotlin.ir.symbols.*
2930
import org.jetbrains.kotlin.ir.types.*
3031
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
@@ -122,7 +123,7 @@ class Fir2IrBuiltinSymbolsContainer(
122123
val firConstructorSymbol = firSymbol.unsubstitutedScope(c).getDeclaredConstructors().singleOrNull() ?: return null
123124
val constructorSymbol = c.declarationStorage.getIrConstructorSymbol(firConstructorSymbol)
124125

125-
return IrConstructorCallImpl(
126+
return IrConstructorCallImplWithShape(
126127
startOffset = UNDEFINED_OFFSET,
127128
endOffset = UNDEFINED_OFFSET,
128129
type = IrSimpleTypeImpl(

compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
3535
import org.jetbrains.kotlin.ir.IrElement
3636
import org.jetbrains.kotlin.ir.IrStatement
3737
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
38-
import org.jetbrains.kotlin.ir.builders.primitiveOp2
3938
import org.jetbrains.kotlin.ir.declarations.*
4039
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
4140
import org.jetbrains.kotlin.ir.expressions.*
@@ -1209,12 +1208,18 @@ class Fir2IrVisitor(
12091208
val irBranches = listOf(
12101209
IrBranchImpl(
12111210
startOffset, endOffset,
1212-
primitiveOp2(
1213-
startOffset, endOffset, builtins.eqeqSymbol,
1214-
builtins.booleanType, IrStatementOrigin.EQEQ,
1215-
irGetLhsValue(),
1216-
IrConstImpl.constNull(startOffset, endOffset, builtins.nothingNType)
1217-
),
1211+
IrCallImplWithShape(
1212+
startOffset = startOffset,
1213+
endOffset = endOffset,
1214+
type = builtins.booleanType,
1215+
symbol = builtins.eqeqSymbol,
1216+
typeArgumentsCount = 0,
1217+
valueArgumentsCount = 2,
1218+
origin = IrStatementOrigin.EQEQ,
1219+
).apply {
1220+
putValueArgument(0, irGetLhsValue())
1221+
putValueArgument(1, IrConstImpl.constNull(startOffset, endOffset, builtins.nothingNType))
1222+
},
12181223
convertToIrExpression(elvisExpression.rhs)
12191224
.insertImplicitCast(elvisExpression, elvisExpression.rhs.resolvedType, elvisExpression.resolvedType)
12201225
),
@@ -1266,7 +1271,7 @@ class Fir2IrVisitor(
12661271
flattenElse = origin == IrStatementOrigin.IF,
12671272
)
12681273
if (isProperlyExhaustive && whenExpression.branches.none { it.condition is FirElseIfTrueCondition }) {
1269-
val irResult = IrCallImpl(
1274+
val irResult = IrCallImplWithShape(
12701275
startOffset, endOffset, builtins.nothingType,
12711276
builtins.noWhenBranchMatchedExceptionSymbol,
12721277
typeArgumentsCount = 0,
@@ -1602,7 +1607,7 @@ class Fir2IrVisitor(
16021607
session, checkNotNullCall
16031608
) {
16041609
return checkNotNullCall.convertWithOffsets { startOffset, endOffset ->
1605-
IrCallImpl(
1610+
IrCallImplWithShape(
16061611
startOffset, endOffset,
16071612
checkNotNullCall.resolvedType.toIrType(c),
16081613
builtins.checkNotNullSymbol,

compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ internal class AdapterGenerator(
775775
startOffset, endOffset, c.builtins.nothingType, irAdapterFunction.symbol,
776776
IrTypeOperatorCallImpl(
777777
startOffset, endOffset, irSamType, IrTypeOperator.SAM_CONVERSION, irSamType,
778-
IrCallImpl(
778+
IrCallImplWithShape(
779779
startOffset, endOffset, irFunctionType, builtins.checkNotNullSymbol,
780780
typeArgumentsCount = 1, valueArgumentsCount = 1, origin = IrStatementOrigin.EXCLEXCL
781781
).apply {

compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class CallAndReferenceGenerator(
548548
val constructor = firSymbol.unwrapCallRepresentative(c).fir as FirConstructor
549549
val totalTypeParametersCount = constructor.typeParameters.size
550550
val constructorTypeParametersCount = constructor.typeParameters.count { it is FirTypeParameter }
551-
IrConstructorCallImpl(
551+
IrConstructorCallImplWithShape(
552552
startOffset,
553553
endOffset,
554554
irType,
@@ -573,7 +573,7 @@ class CallAndReferenceGenerator(
573573
) {
574574
explicitReceiverExpression.updateStatementOrigin(callOrigin)
575575
}
576-
IrCallImpl(
576+
IrCallImplWithShape(
577577
startOffset, endOffset, irType, irSymbol,
578578
typeArgumentsCount = firSymbol.typeParameterSymbols.size,
579579
valueArgumentsCount = firSymbol.valueParametersSize(),
@@ -599,7 +599,7 @@ class CallAndReferenceGenerator(
599599
val backingFieldSymbol = declarationStorage.findBackingFieldOfProperty(irSymbol)
600600
when {
601601
getterSymbol != null -> {
602-
IrCallImpl(
602+
IrCallImplWithShape(
603603
startOffset, endOffset, irType,
604604
getterSymbol,
605605
typeArgumentsCount = property.typeParameters.size,
@@ -785,7 +785,7 @@ class CallAndReferenceGenerator(
785785
val firProperty = calleeReference.toResolvedPropertySymbol()!!.fir
786786

787787
when {
788-
setterSymbol != null -> IrCallImpl(
788+
setterSymbol != null -> IrCallImplWithShape(
789789
startOffset, endOffset, type, setterSymbol,
790790
typeArgumentsCount = firProperty.typeParameters.size,
791791
valueArgumentsCount = 1 + firProperty.contextReceivers.size,
@@ -914,7 +914,7 @@ class CallAndReferenceGenerator(
914914
}
915915
val irConstructor = declarationStorage.getIrConstructorSymbol(fullyExpandedConstructorSymbol)
916916

917-
IrConstructorCallImpl(
917+
IrConstructorCallImplWithShape(
918918
startOffset, endOffset, type, irConstructor,
919919
// Get the number of value arguments from FIR because of a possible cycle where an annotation constructor
920920
// parameter is annotated with the same annotation.

compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/OperatorExpressionGenerator.kt

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ import org.jetbrains.kotlin.fir.backend.utils.createTemporaryVariableForSafeCall
1212
import org.jetbrains.kotlin.fir.backend.utils.unsubstitutedScope
1313
import org.jetbrains.kotlin.fir.expressions.*
1414
import org.jetbrains.kotlin.fir.resolve.providers.getRegularClassSymbolByClassId
15-
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
1615
import org.jetbrains.kotlin.fir.scopes.getFunctions
1716
import org.jetbrains.kotlin.fir.types.ConeDynamicType
1817
import org.jetbrains.kotlin.fir.types.isMarkedNullable
1918
import org.jetbrains.kotlin.fir.types.isNullable
2019
import org.jetbrains.kotlin.fir.types.resolvedType
2120
import org.jetbrains.kotlin.ir.builders.primitiveOp1
22-
import org.jetbrains.kotlin.ir.builders.primitiveOp2
2321
import org.jetbrains.kotlin.ir.expressions.*
2422
import org.jetbrains.kotlin.ir.expressions.impl.*
2523
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
@@ -73,14 +71,18 @@ internal class OperatorExpressionGenerator(
7371
val (symbol, origin) = getSymbolAndOriginForComparison(operation, builtins.intType.classifierOrFail)
7472
val irCompareToCall = comparisonExpression.compareToCall.accept(visitor, null) as IrCall
7573
irCompareToCall.origin = origin
76-
return primitiveOp2(
77-
startOffset, endOffset,
78-
symbol!!,
79-
builtins.booleanType,
80-
origin,
81-
irCompareToCall,
82-
IrConstImpl.int(startOffset, endOffset, builtins.intType, 0)
83-
)
74+
return IrCallImplWithShape(
75+
startOffset = startOffset,
76+
endOffset = endOffset,
77+
type = builtins.booleanType,
78+
symbol = symbol!!,
79+
typeArgumentsCount = 0,
80+
valueArgumentsCount = 2,
81+
origin = origin,
82+
).apply {
83+
putValueArgument(0, irCompareToCall)
84+
putValueArgument(1, IrConstImpl.int(startOffset, endOffset, builtins.intType, 0))
85+
}
8486
}
8587

8688
if (comparisonExpression.compareToCall.toResolvedCallableSymbol()?.fir?.receiverParameter != null) {
@@ -93,15 +95,18 @@ internal class OperatorExpressionGenerator(
9395
val comparisonIrType = typeConverter.classIdToTypeMap[comparisonType.lookupTag.classId] ?: return fallbackToRealCall()
9496
val (symbol, origin) = getSymbolAndOriginForComparison(operation, comparisonIrType.classifierOrFail)
9597

96-
return primitiveOp2(
97-
startOffset,
98-
endOffset,
99-
symbol!!,
100-
builtins.booleanType,
101-
origin,
102-
comparisonExpression.left.convertToIrExpression(comparisonInfo, isLeftType = true),
103-
comparisonExpression.right.convertToIrExpression(comparisonInfo, isLeftType = false)
104-
)
98+
return IrCallImplWithShape(
99+
startOffset = startOffset,
100+
endOffset = endOffset,
101+
type = builtins.booleanType,
102+
symbol = symbol!!,
103+
typeArgumentsCount = 0,
104+
valueArgumentsCount = 2,
105+
origin = origin,
106+
).apply {
107+
putValueArgument(0, comparisonExpression.left.convertToIrExpression(comparisonInfo, isLeftType = true))
108+
putValueArgument(1, comparisonExpression.right.convertToIrExpression(comparisonInfo, isLeftType = false))
109+
}
105110
}
106111

107112
private fun getSymbolAndOriginForComparison(
@@ -191,15 +196,18 @@ internal class OperatorExpressionGenerator(
191196
val eqeqSymbol = comparisonType?.let { typeConverter.classIdToSymbolMap[it.lookupTag.classId] }
192197
?.let { builtins.ieee754equalsFunByOperandType[it] } ?: builtins.eqeqSymbol
193198

194-
val equalsCall = primitiveOp2(
195-
startOffset,
196-
endOffset,
197-
eqeqSymbol,
198-
builtins.booleanType,
199-
origin,
200-
convertedLeft,
201-
convertedRight
202-
)
199+
val equalsCall = IrCallImplWithShape(
200+
startOffset = startOffset,
201+
endOffset = endOffset,
202+
type = builtins.booleanType,
203+
symbol = eqeqSymbol,
204+
typeArgumentsCount = 0,
205+
valueArgumentsCount = 2,
206+
origin = origin
207+
).apply {
208+
putValueArgument(0, convertedLeft)
209+
putValueArgument(1, convertedRight)
210+
}
203211
return if (operation == FirOperation.EQ) {
204212
equalsCall
205213
} else {
@@ -226,14 +234,19 @@ internal class OperatorExpressionGenerator(
226234
)?.let {
227235
return it
228236
}
229-
val identityCall = primitiveOp2(
230-
startOffset, endOffset,
231-
builtins.eqeqeqSymbol,
232-
builtins.booleanType,
233-
origin,
234-
convertedLeft,
235-
convertedRight
236-
)
237+
val identityCall = IrCallImplWithShape(
238+
startOffset = startOffset,
239+
endOffset = endOffset,
240+
type = builtins.booleanType,
241+
symbol = builtins.eqeqeqSymbol,
242+
typeArgumentsCount = 0,
243+
valueArgumentsCount = 2,
244+
origin = origin,
245+
).apply {
246+
putValueArgument(0, convertedLeft)
247+
putValueArgument(1, convertedRight)
248+
}
249+
237250
return if (operation == FirOperation.IDENTITY) {
238251
identityCall
239252
} else {

compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/utils/IrElementsCreationUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fun Fir2IrComponents.createSafeCallConstruction(
8181
return IrBlockImpl(startOffset, endOffset, resultType, IrStatementOrigin.SAFE_CALL).apply {
8282
statements += receiverVariable
8383
statements += IrWhenImpl(startOffset, endOffset, resultType).apply {
84-
val condition = IrCallImpl(
84+
val condition = IrCallImplWithShape(
8585
startOffset, endOffset, builtins.booleanType,
8686
builtins.eqeqSymbol,
8787
valueArgumentsCount = 2,

0 commit comments

Comments
 (0)