[FIR2IR] Replace FirExpression.typeRef.toIrType with coneType.toIrType
#KT-59855
This commit is contained in:
committed by
Space Team
parent
9ec814b7ad
commit
e50025f21f
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyDeclarationResolver
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeOrNull
|
||||
import org.jetbrains.kotlin.ir.PsiIrFileEntry
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -274,7 +275,7 @@ class Fir2IrConverter(
|
||||
|
||||
val irFragmentFunction = symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature) }) { irSymbol ->
|
||||
val lastStatement = codeFragment.block.statements.lastOrNull()
|
||||
val returnType = (lastStatement as? FirExpression)?.typeRef?.toIrType(typeConverter) ?: irBuiltIns.unitType
|
||||
val returnType = (lastStatement as? FirExpression)?.coneTypeOrNull?.toIrType(typeConverter) ?: irBuiltIns.unitType
|
||||
|
||||
irFactory.createSimpleFunction(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
|
||||
+10
-10
@@ -933,7 +933,7 @@ class Fir2IrDeclarationStorage(
|
||||
firInitializerExpression: FirExpression?,
|
||||
type: IrType? = null
|
||||
): IrField = convertCatching(property) {
|
||||
val inferredType = type ?: firInitializerExpression!!.typeRef.toIrType()
|
||||
val inferredType = type ?: firInitializerExpression!!.coneType.toIrType()
|
||||
return declareIrField { symbol ->
|
||||
irFactory.createField(
|
||||
startOffset = startOffset,
|
||||
@@ -1101,7 +1101,7 @@ class Fir2IrDeclarationStorage(
|
||||
property.name, property.isVal, initializer, typeToUse
|
||||
).also { field ->
|
||||
if (initializer is FirConstExpression<*>) {
|
||||
val constType = initializer.typeRef.toIrType()
|
||||
val constType = initializer.coneType.toIrType()
|
||||
field.initializer = factory.createExpressionBody(initializer.toIrConst(constType))
|
||||
}
|
||||
}
|
||||
@@ -1291,7 +1291,7 @@ class Fir2IrDeclarationStorage(
|
||||
return createIrField(
|
||||
field,
|
||||
irParent = irClass,
|
||||
typeRef = initializer?.typeRef ?: field.returnTypeRef,
|
||||
type = initializer?.coneType ?: field.returnTypeRef.coneType,
|
||||
origin = IrDeclarationOrigin.DELEGATE
|
||||
).apply {
|
||||
metadata = FirMetadataSource.Field(field)
|
||||
@@ -1301,10 +1301,10 @@ class Fir2IrDeclarationStorage(
|
||||
internal fun createIrField(
|
||||
field: FirField,
|
||||
irParent: IrDeclarationParent?,
|
||||
typeRef: FirTypeRef = field.returnTypeRef,
|
||||
type: ConeKotlinType = field.returnTypeRef.coneType,
|
||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
): IrField = convertCatching(field) {
|
||||
val type = typeRef.toIrType()
|
||||
val irType = type.toIrType()
|
||||
val classId = (irParent as? IrClass)?.classId
|
||||
val containingClassLookupTag = classId?.toLookupTag()
|
||||
val signature = signatureComposer.composeSignature(field, containingClassLookupTag)
|
||||
@@ -1320,7 +1320,7 @@ class Fir2IrDeclarationStorage(
|
||||
name = field.name,
|
||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
symbol = symbol,
|
||||
type = type,
|
||||
type = irType,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isStatic = field.isStatic,
|
||||
isExternal = false
|
||||
@@ -1334,7 +1334,7 @@ class Fir2IrDeclarationStorage(
|
||||
name = field.name,
|
||||
visibility = components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||
symbol = IrFieldSymbolImpl(),
|
||||
type = type,
|
||||
type = irType,
|
||||
isFinal = field.modality == Modality.FINAL,
|
||||
isStatic = field.isStatic,
|
||||
isExternal = false
|
||||
@@ -1349,7 +1349,7 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
val initializer = field.unwrapFakeOverrides().initializer
|
||||
if (initializer is FirConstExpression<*>) {
|
||||
this.initializer = factory.createExpressionBody(initializer.toIrConst(type))
|
||||
this.initializer = factory.createExpressionBody(initializer.toIrConst(irType))
|
||||
}
|
||||
setAndModifyParent(irParent)
|
||||
}
|
||||
@@ -1467,7 +1467,7 @@ class Fir2IrDeclarationStorage(
|
||||
// Note: for components call, we have to change type here (to original component type) to keep compatibility with PSI2IR
|
||||
// Some backend optimizations related to withIndex() probably depend on this type: index should always be Int
|
||||
// See e.g. forInStringWithIndexWithExplicitlyTypedIndexVariable.kt from codegen box tests
|
||||
val type = ((variable.initializer as? FirComponentCall)?.typeRef ?: variable.returnTypeRef).toIrType()
|
||||
val type = ((variable.initializer as? FirComponentCall)?.coneType ?: variable.returnTypeRef.coneType).toIrType()
|
||||
// Some temporary variables are produced in RawFirBuilder, but we consistently use special names for them.
|
||||
val origin = when {
|
||||
givenOrigin != null -> givenOrigin
|
||||
@@ -1509,7 +1509,7 @@ class Fir2IrDeclarationStorage(
|
||||
enterScope(this)
|
||||
delegate = declareIrVariable(
|
||||
startOffset, endOffset, IrDeclarationOrigin.PROPERTY_DELEGATE,
|
||||
NameUtils.propertyDelegateName(property.name), property.delegate!!.typeRef.toIrType(),
|
||||
NameUtils.propertyDelegateName(property.name), property.delegate!!.coneType.toIrType(),
|
||||
isVar = false, isConst = false, isLateinit = false
|
||||
)
|
||||
delegate.parent = irParent
|
||||
|
||||
+10
-10
@@ -185,7 +185,7 @@ class Fir2IrImplicitCastInserter(
|
||||
}
|
||||
|
||||
override fun visitThrowExpression(throwExpression: FirThrowExpression, data: IrElement): IrElement =
|
||||
(data as IrThrow).cast(throwExpression, throwExpression.exception.typeRef, throwExpression.typeRef)
|
||||
(data as IrThrow).cast(throwExpression, throwExpression.exception.coneType, throwExpression.coneType)
|
||||
|
||||
override fun visitBlock(block: FirBlock, data: IrElement): IrElement =
|
||||
(data as? IrContainerExpression)?.insertImplicitCasts() ?: data
|
||||
@@ -193,13 +193,13 @@ class Fir2IrImplicitCastInserter(
|
||||
override fun visitReturnExpression(returnExpression: FirReturnExpression, data: IrElement): IrElement {
|
||||
val irReturn = data as? IrReturn ?: return data
|
||||
val expectedType = returnExpression.target.labeledElement.returnTypeRef
|
||||
irReturn.value = irReturn.value.cast(returnExpression.result, returnExpression.result.typeRef, expectedType)
|
||||
irReturn.value = irReturn.value.cast(returnExpression.result, returnExpression.result.coneType, expectedType.coneType)
|
||||
return data
|
||||
}
|
||||
|
||||
// ==================================================================================
|
||||
|
||||
internal fun IrExpression.cast(expression: FirExpression, valueTypeRef: FirTypeRef, expectedTypeRef: FirTypeRef): IrExpression {
|
||||
internal fun IrExpression.cast(expression: FirExpression, valueTypeRef: ConeKotlinType, expectedTypeRef: ConeKotlinType): IrExpression {
|
||||
if (this is IrTypeOperatorCall) {
|
||||
return this
|
||||
}
|
||||
@@ -208,8 +208,8 @@ class Fir2IrImplicitCastInserter(
|
||||
insertImplicitCasts()
|
||||
}
|
||||
|
||||
val valueType = valueTypeRef.coneType.fullyExpandedType(session)
|
||||
val expectedType = expectedTypeRef.coneType.fullyExpandedType(session)
|
||||
val valueType = valueTypeRef.fullyExpandedType(session)
|
||||
val expectedType = expectedTypeRef.fullyExpandedType(session)
|
||||
|
||||
return when {
|
||||
expectedType.isUnit -> {
|
||||
@@ -273,7 +273,7 @@ class Fir2IrImplicitCastInserter(
|
||||
override fun visitSmartCastExpression(smartCastExpression: FirSmartCastExpression, data: IrElement): IrElement {
|
||||
// We don't want an implicit cast to Nothing?. This expression just encompasses nullability after null check.
|
||||
return if (smartCastExpression.isStable && smartCastExpression.smartcastTypeWithoutNullableNothing == null) {
|
||||
implicitCastOrExpression(data as IrExpression, smartCastExpression.typeRef)
|
||||
implicitCastOrExpression(data as IrExpression, smartCastExpression.coneType)
|
||||
} else {
|
||||
data as IrExpression
|
||||
}
|
||||
@@ -281,7 +281,7 @@ class Fir2IrImplicitCastInserter(
|
||||
|
||||
internal fun implicitCastFromDispatchReceiver(
|
||||
original: IrExpression,
|
||||
originalTypeRef: FirTypeRef,
|
||||
coneKotlinType: ConeKotlinType,
|
||||
calleeReference: FirReference?,
|
||||
typeOrigin: ConversionTypeOrigin,
|
||||
): IrExpression {
|
||||
@@ -289,18 +289,18 @@ class Fir2IrImplicitCastInserter(
|
||||
|
||||
val dispatchReceiverType =
|
||||
referencedDeclaration?.dispatchReceiverType as? ConeClassLikeType
|
||||
?: return implicitCastOrExpression(original, originalTypeRef)
|
||||
?: return implicitCastOrExpression(original, coneKotlinType)
|
||||
|
||||
val starProjectedDispatchReceiver = dispatchReceiverType.replaceArgumentsWithStarProjections()
|
||||
|
||||
val castType = originalTypeRef.coneTypeSafe<ConeIntersectionType>()
|
||||
val castType = coneKotlinType as? ConeIntersectionType
|
||||
castType?.intersectedTypes?.forEach { componentType ->
|
||||
if (AbstractTypeChecker.isSubtypeOf(session.typeContext, componentType, starProjectedDispatchReceiver)) {
|
||||
return implicitCastOrExpression(original, componentType, typeOrigin)
|
||||
}
|
||||
}
|
||||
|
||||
return implicitCastOrExpression(original, originalTypeRef, typeOrigin)
|
||||
return implicitCastOrExpression(original, coneKotlinType, typeOrigin)
|
||||
}
|
||||
|
||||
private fun implicitCastOrExpression(
|
||||
|
||||
@@ -336,3 +336,11 @@ fun FirTypeRef.toIrType(
|
||||
with(typeConverter) {
|
||||
toIrType(typeOrigin)
|
||||
}
|
||||
|
||||
fun ConeKotlinType.toIrType(
|
||||
typeConverter: Fir2IrTypeConverter,
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||
): IrType =
|
||||
with(typeConverter) {
|
||||
toIrType(typeOrigin)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ class Fir2IrVisitor(
|
||||
get() = _annotationMode
|
||||
|
||||
private fun FirTypeRef.toIrType(): IrType = with(typeConverter) { toIrType() }
|
||||
private fun ConeKotlinType.toIrType(): IrType = with(typeConverter) { toIrType() }
|
||||
|
||||
private fun <T : IrDeclaration> applyParentFromStackTo(declaration: T): T = conversionScope.applyParentFromStackTo(declaration)
|
||||
|
||||
@@ -468,7 +469,7 @@ class Fir2IrVisitor(
|
||||
if (initializer != null) {
|
||||
irVariable.initializer =
|
||||
convertToIrExpression(initializer)
|
||||
.insertImplicitCast(initializer, initializer.typeRef, variable.returnTypeRef)
|
||||
.insertImplicitCast(initializer, initializer.coneType, variable.returnTypeRef.coneType)
|
||||
}
|
||||
annotationGenerator.generate(irVariable, variable)
|
||||
return irVariable
|
||||
@@ -476,8 +477,8 @@ class Fir2IrVisitor(
|
||||
|
||||
private fun IrExpression.insertImplicitCast(
|
||||
baseExpression: FirExpression,
|
||||
valueType: FirTypeRef,
|
||||
expectedType: FirTypeRef
|
||||
valueType: ConeKotlinType,
|
||||
expectedType: ConeKotlinType,
|
||||
) =
|
||||
with(implicitCastInserter) {
|
||||
this@insertImplicitCast.cast(baseExpression, valueType, expectedType)
|
||||
@@ -532,7 +533,7 @@ class Fir2IrVisitor(
|
||||
IrVarargImpl(
|
||||
startOffset,
|
||||
endOffset,
|
||||
varargArgumentsExpression.typeRef.toIrType(),
|
||||
varargArgumentsExpression.coneType.toIrType(),
|
||||
varargArgumentsExpression.varargElementType.toIrType(),
|
||||
varargArgumentsExpression.arguments.map { it.convertToIrVarargElement() }
|
||||
)
|
||||
@@ -565,7 +566,7 @@ class Fir2IrVisitor(
|
||||
val explicitReceiverExpression = convertToIrReceiverExpression(functionCall.explicitReceiver, functionCall.calleeReference)
|
||||
return callGenerator.convertToIrCall(
|
||||
functionCall,
|
||||
functionCall.typeRef,
|
||||
functionCall.coneType,
|
||||
explicitReceiverExpression,
|
||||
dynamicOperator
|
||||
)
|
||||
@@ -579,7 +580,7 @@ class Fir2IrVisitor(
|
||||
explicitReceiverExpression.arguments.removeLast()
|
||||
}
|
||||
val result = callGenerator.convertToIrCall(
|
||||
functionCall, functionCall.typeRef, explicitReceiverExpression,
|
||||
functionCall, functionCall.coneType, explicitReceiverExpression,
|
||||
dynamicOperator = IrDynamicOperator.EQ
|
||||
)
|
||||
if (result is IrDynamicOperatorExpression) {
|
||||
@@ -645,7 +646,7 @@ class Fir2IrVisitor(
|
||||
qualifiedAccessExpression.explicitReceiver, qualifiedAccessExpression.calleeReference
|
||||
)
|
||||
return callGenerator.convertToIrCall(
|
||||
qualifiedAccessExpression, qualifiedAccessExpression.typeRef, explicitReceiverExpression
|
||||
qualifiedAccessExpression, qualifiedAccessExpression.coneType, explicitReceiverExpression
|
||||
)
|
||||
}
|
||||
|
||||
@@ -713,7 +714,7 @@ class Fir2IrVisitor(
|
||||
|
||||
IrGetFieldImpl(
|
||||
startOffset, endOffset, contextReceivers[calleeReference.contextReceiverNumber].symbol,
|
||||
thisReceiverExpression.typeRef.toIrType(),
|
||||
thisReceiverExpression.coneType.toIrType(),
|
||||
thisRef,
|
||||
)
|
||||
}
|
||||
@@ -770,7 +771,7 @@ class Fir2IrVisitor(
|
||||
return inaccessibleReceiverExpression.convertWithOffsets { startOffset, endOffset ->
|
||||
IrErrorExpressionImpl(
|
||||
startOffset, endOffset,
|
||||
inaccessibleReceiverExpression.typeRef.toIrType(),
|
||||
inaccessibleReceiverExpression.coneType.toIrType(),
|
||||
"Receiver is inaccessible"
|
||||
)
|
||||
}
|
||||
@@ -817,7 +818,7 @@ class Fir2IrVisitor(
|
||||
}
|
||||
|
||||
override fun <T> visitConstExpression(constExpression: FirConstExpression<T>, data: Any?): IrElement {
|
||||
return constExpression.toIrConst(constExpression.typeRef.toIrType())
|
||||
return constExpression.toIrConst(constExpression.coneType.toIrType())
|
||||
}
|
||||
|
||||
// ==================================================================================
|
||||
@@ -872,7 +873,7 @@ class Fir2IrVisitor(
|
||||
calleeReference.name != OperatorNameConventions.INVOKE &&
|
||||
(calleeReference.resolvedSymbol as? FirCallableSymbol)?.callableId?.callableName == OperatorNameConventions.INVOKE
|
||||
callGenerator.convertToIrCall(
|
||||
expression, expression.typeRef, explicitReceiverExpression = null,
|
||||
expression, expression.coneType, explicitReceiverExpression = null,
|
||||
variableAsFunctionMode = variableAsFunctionMode
|
||||
)
|
||||
} else {
|
||||
@@ -882,7 +883,7 @@ class Fir2IrVisitor(
|
||||
if (expression is FirQualifiedAccessExpression && expression.calleeReference is FirSuperReference) return@run this
|
||||
|
||||
implicitCastInserter.implicitCastFromDispatchReceiver(
|
||||
this, expression.typeRef, calleeReference,
|
||||
this, expression.coneType, calleeReference,
|
||||
conversionScope.defaultConversionTypeOrigin()
|
||||
)
|
||||
}
|
||||
@@ -990,7 +991,7 @@ class Fir2IrVisitor(
|
||||
val arrayAccess = operationReceiver as? FirFunctionCall ?: return null
|
||||
val originalVararg = arrayAccess.resolvedArgumentMapping?.keys?.filterIsInstance<FirVarargArgumentsExpression>()?.firstOrNull()
|
||||
(callGenerator.convertToIrCall(
|
||||
arrayAccess, arrayAccess.typeRef,
|
||||
arrayAccess, arrayAccess.coneType,
|
||||
convertToIrReceiverExpression(receiverValue, arrayAccess.calleeReference),
|
||||
noArguments = true
|
||||
) as IrDynamicOperatorExpression).apply {
|
||||
@@ -1009,12 +1010,12 @@ class Fir2IrVisitor(
|
||||
}
|
||||
callGenerator.convertToIrCall(
|
||||
qualifiedAccess,
|
||||
qualifiedAccess.typeRef,
|
||||
qualifiedAccess.coneType,
|
||||
convertToIrReceiverExpression(receiverExpression, qualifiedAccess.calleeReference),
|
||||
)
|
||||
}
|
||||
return callGenerator.convertToIrCall(
|
||||
operationCall, operationCall.typeRef, explicitReceiverExpression
|
||||
operationCall, operationCall.coneType, explicitReceiverExpression
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1054,7 +1055,7 @@ class Fir2IrVisitor(
|
||||
val type = if (forceUnitType)
|
||||
irBuiltIns.unitType
|
||||
else
|
||||
(lastOrNull() as? FirExpression)?.typeRef?.toIrType() ?: irBuiltIns.unitType
|
||||
(lastOrNull() as? FirExpression)?.coneType?.toIrType() ?: irBuiltIns.unitType
|
||||
return source.convertWithOffsets { startOffset, endOffset ->
|
||||
if (origin == IrStatementOrigin.DO_WHILE_LOOP) {
|
||||
IrCompositeImpl(
|
||||
@@ -1079,7 +1080,7 @@ class Fir2IrVisitor(
|
||||
return errorExpression.convertWithOffsets { startOffset, endOffset ->
|
||||
IrErrorExpressionImpl(
|
||||
startOffset, endOffset,
|
||||
errorExpression.typeRef.toIrType(),
|
||||
errorExpression.coneType.toIrType(),
|
||||
errorExpression.diagnostic.reason
|
||||
)
|
||||
}
|
||||
@@ -1122,7 +1123,7 @@ class Fir2IrVisitor(
|
||||
IrConstImpl.constNull(startOffset, endOffset, irBuiltIns.nothingNType)
|
||||
),
|
||||
convertToIrExpression(elvisExpression.rhs)
|
||||
.insertImplicitCast(elvisExpression, elvisExpression.rhs.typeRef, elvisExpression.typeRef)
|
||||
.insertImplicitCast(elvisExpression, elvisExpression.rhs.coneType, elvisExpression.coneType)
|
||||
),
|
||||
IrElseBranchImpl(
|
||||
IrConstImpl.boolean(startOffset, endOffset, irBuiltIns.booleanType, true),
|
||||
@@ -1140,7 +1141,7 @@ class Fir2IrVisitor(
|
||||
generateWhen(
|
||||
startOffset, endOffset, IrStatementOrigin.ELVIS,
|
||||
irLhsVariable, irBranches,
|
||||
elvisExpression.typeRef.toIrType()
|
||||
elvisExpression.coneType.toIrType()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1166,7 +1167,7 @@ class Fir2IrVisitor(
|
||||
val whenExpressionType =
|
||||
if (whenExpression.isProperlyExhaustive && whenExpression.branches.none {
|
||||
it.condition is FirElseIfTrueCondition && it.result.statements.isEmpty()
|
||||
}) whenExpression.typeRef else session.builtinTypes.unitType
|
||||
}) whenExpression.coneType else session.builtinTypes.unitType.type
|
||||
val irBranches = whenExpression.branches.mapTo(mutableListOf()) { branch ->
|
||||
branch.toIrWhenBranch(whenExpressionType)
|
||||
}
|
||||
@@ -1217,10 +1218,10 @@ class Fir2IrVisitor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirWhenBranch.toIrWhenBranch(whenExpressionType: FirTypeRef): IrBranch {
|
||||
private fun FirWhenBranch.toIrWhenBranch(whenExpressionType: ConeKotlinType): IrBranch {
|
||||
return convertWithOffsets { startOffset, endOffset ->
|
||||
val condition = condition
|
||||
val irResult = convertToIrExpression(result).insertImplicitCast(result, result.typeRef, whenExpressionType)
|
||||
val irResult = convertToIrExpression(result).insertImplicitCast(result, result.coneType, whenExpressionType)
|
||||
if (condition is FirElseIfTrueCondition) {
|
||||
IrElseBranchImpl(IrConstImpl.boolean(irResult.startOffset, irResult.endOffset, irBuiltIns.booleanType, true), irResult)
|
||||
} else {
|
||||
@@ -1358,7 +1359,7 @@ class Fir2IrVisitor(
|
||||
// that line number for the finally block.
|
||||
return tryExpression.convertWithOffsets { startOffset, endOffset ->
|
||||
IrTryImpl(
|
||||
startOffset, endOffset, tryExpression.typeRef.toIrType(),
|
||||
startOffset, endOffset, tryExpression.coneType.toIrType(),
|
||||
tryExpression.tryBlock.convertToIrBlock(forceUnitType = false),
|
||||
tryExpression.catches.map { it.accept(this, data) as IrCatch },
|
||||
tryExpression.finallyBlock?.convertToIrBlock(forceUnitType = true)
|
||||
@@ -1442,13 +1443,13 @@ class Fir2IrVisitor(
|
||||
return checkNotNullCall.convertWithOffsets { startOffset, endOffset ->
|
||||
IrCallImpl(
|
||||
startOffset, endOffset,
|
||||
checkNotNullCall.typeRef.toIrType(),
|
||||
checkNotNullCall.coneType.toIrType(),
|
||||
irBuiltIns.checkNotNullSymbol,
|
||||
typeArgumentsCount = 1,
|
||||
valueArgumentsCount = 1,
|
||||
origin = IrStatementOrigin.EXCLEXCL
|
||||
).apply {
|
||||
putTypeArgument(0, checkNotNullCall.argument.typeRef.toIrType().makeNotNull())
|
||||
putTypeArgument(0, checkNotNullCall.argument.coneType.toIrType().makeNotNull())
|
||||
putValueArgument(0, convertToIrExpression(checkNotNullCall.argument))
|
||||
}
|
||||
}
|
||||
@@ -1456,12 +1457,12 @@ class Fir2IrVisitor(
|
||||
|
||||
override fun visitGetClassCall(getClassCall: FirGetClassCall, data: Any?): IrElement = whileAnalysing(session, getClassCall) {
|
||||
val argument = getClassCall.argument
|
||||
val irType = getClassCall.typeRef.toIrType()
|
||||
val irType = getClassCall.coneType.toIrType()
|
||||
val irClassType =
|
||||
if (argument is FirClassReferenceExpression) {
|
||||
argument.classTypeRef.toIrType()
|
||||
} else {
|
||||
argument.typeRef.toIrType()
|
||||
argument.coneType.toIrType()
|
||||
}
|
||||
val irClassReferenceSymbol = when (argument) {
|
||||
is FirResolvedReifiedParameterReference -> {
|
||||
@@ -1509,7 +1510,7 @@ class Fir2IrVisitor(
|
||||
|
||||
private fun convertToArrayLiteral(arrayLiteral: FirArrayLiteral): IrVararg {
|
||||
return arrayLiteral.convertWithOffsets { startOffset, endOffset ->
|
||||
val arrayType = arrayLiteral.typeRef.toIrType()
|
||||
val arrayType = arrayLiteral.coneType.toIrType()
|
||||
val elementType = if (arrayLiteral.typeRef is FirResolvedTypeRef) {
|
||||
arrayType.getArrayElementType(irBuiltIns)
|
||||
} else {
|
||||
|
||||
+19
-19
@@ -368,7 +368,7 @@ class CallAndReferenceGenerator(
|
||||
@OptIn(IrSymbolInternals::class)
|
||||
fun convertToIrCall(
|
||||
qualifiedAccess: FirQualifiedAccessExpression,
|
||||
typeRef: FirTypeRef,
|
||||
type: ConeKotlinType,
|
||||
explicitReceiverExpression: IrExpression?,
|
||||
dynamicOperator: IrDynamicOperator? = null,
|
||||
variableAsFunctionMode: Boolean = false,
|
||||
@@ -377,8 +377,8 @@ class CallAndReferenceGenerator(
|
||||
try {
|
||||
injectGetValueCall(qualifiedAccess, qualifiedAccess.calleeReference)?.let { return it }
|
||||
|
||||
val type = typeRef.toIrType()
|
||||
val samConstructorCall = qualifiedAccess.tryConvertToSamConstructorCall(type)
|
||||
val irType = type.toIrType()
|
||||
val samConstructorCall = qualifiedAccess.tryConvertToSamConstructorCall(irType)
|
||||
if (samConstructorCall != null) return samConstructorCall
|
||||
|
||||
val dispatchReceiver = qualifiedAccess.dispatchReceiver
|
||||
@@ -391,7 +391,7 @@ class CallAndReferenceGenerator(
|
||||
return convertToIrCallForDynamic(
|
||||
qualifiedAccess,
|
||||
explicitReceiverExpression,
|
||||
type,
|
||||
irType,
|
||||
calleeReference,
|
||||
firSymbol ?: error("Must have had a symbol"),
|
||||
dynamicOperator,
|
||||
@@ -431,7 +431,7 @@ class CallAndReferenceGenerator(
|
||||
}
|
||||
}
|
||||
when (symbol) {
|
||||
is IrConstructorSymbol -> IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, symbol)
|
||||
is IrConstructorSymbol -> IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, irType, symbol)
|
||||
is IrSimpleFunctionSymbol -> {
|
||||
require(firSymbol is FirCallableSymbol<*>) { "Illegal symbol: ${firSymbol!!::class}" }
|
||||
val valueParametersNumber = when (firSymbol) {
|
||||
@@ -441,7 +441,7 @@ class CallAndReferenceGenerator(
|
||||
else -> error("Illegal symbol: ${firSymbol::class}")
|
||||
}
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, type, symbol,
|
||||
startOffset, endOffset, irType, symbol,
|
||||
typeArgumentsCount = firSymbol.typeParameterSymbols.size,
|
||||
valueArgumentsCount = valueParametersNumber,
|
||||
origin = calleeReference.statementOrigin(),
|
||||
@@ -451,7 +451,7 @@ class CallAndReferenceGenerator(
|
||||
|
||||
is IrLocalDelegatedPropertySymbol -> {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, type, symbol.owner.getter.symbol,
|
||||
startOffset, endOffset, irType, symbol.owner.getter.symbol,
|
||||
typeArgumentsCount = symbol.owner.getter.typeParameters.size,
|
||||
valueArgumentsCount = 0,
|
||||
origin = IrStatementOrigin.GET_LOCAL_PROPERTY,
|
||||
@@ -464,7 +464,7 @@ class CallAndReferenceGenerator(
|
||||
val backingField = symbol.owner.backingField
|
||||
when {
|
||||
getter != null -> IrCallImpl(
|
||||
startOffset, endOffset, type, getter.symbol,
|
||||
startOffset, endOffset, irType, getter.symbol,
|
||||
typeArgumentsCount = getter.typeParameters.size,
|
||||
valueArgumentsCount = getter.valueParameters.size,
|
||||
origin = IrStatementOrigin.GET_PROPERTY,
|
||||
@@ -472,12 +472,12 @@ class CallAndReferenceGenerator(
|
||||
)
|
||||
|
||||
backingField != null -> IrGetFieldImpl(
|
||||
startOffset, endOffset, backingField.symbol, type,
|
||||
startOffset, endOffset, backingField.symbol, irType,
|
||||
superQualifierSymbol = dispatchReceiver.superQualifierSymbol()
|
||||
)
|
||||
|
||||
else -> IrErrorCallExpressionImpl(
|
||||
startOffset, endOffset, type,
|
||||
startOffset, endOffset, irType,
|
||||
description = "No getter or backing field found for ${calleeReference.render()}"
|
||||
)
|
||||
}
|
||||
@@ -491,7 +491,7 @@ class CallAndReferenceGenerator(
|
||||
firConstExpression.toIrConst(returnType)
|
||||
} else {
|
||||
IrGetFieldImpl(
|
||||
startOffset, endOffset, symbol, type,
|
||||
startOffset, endOffset, symbol, irType,
|
||||
origin = IrStatementOrigin.GET_PROPERTY.takeIf { calleeReference !is FirDelegateFieldReference },
|
||||
superQualifierSymbol = dispatchReceiver.superQualifierSymbol()
|
||||
)
|
||||
@@ -508,8 +508,8 @@ class CallAndReferenceGenerator(
|
||||
)
|
||||
}
|
||||
|
||||
is IrEnumEntrySymbol -> IrGetEnumValueImpl(startOffset, endOffset, type, symbol)
|
||||
else -> generateErrorCallExpression(startOffset, endOffset, calleeReference, type)
|
||||
is IrEnumEntrySymbol -> IrGetEnumValueImpl(startOffset, endOffset, irType, symbol)
|
||||
else -> generateErrorCallExpression(startOffset, endOffset, calleeReference, irType)
|
||||
}
|
||||
}.applyTypeArguments(qualifiedAccess).applyReceivers(qualifiedAccess, convertedExplicitReceiver)
|
||||
.applyCallArguments(qualifiedAccess)
|
||||
@@ -797,7 +797,7 @@ class CallAndReferenceGenerator(
|
||||
return null
|
||||
}
|
||||
|
||||
val irType = qualifier.typeRef.toIrType()
|
||||
val irType = qualifier.coneType.toIrType()
|
||||
return qualifier.convertWithOffsets { startOffset, endOffset ->
|
||||
if (classSymbol != null) {
|
||||
IrGetObjectValueImpl(
|
||||
@@ -1010,7 +1010,7 @@ class CallAndReferenceGenerator(
|
||||
var irArgument = visitor.convertToIrExpression(argument)
|
||||
if (parameter != null) {
|
||||
with(visitor.implicitCastInserter) {
|
||||
irArgument = irArgument.cast(argument, argument.typeRef, parameter.returnTypeRef)
|
||||
irArgument = irArgument.cast(argument, argument.coneType, parameter.returnTypeRef.coneType)
|
||||
}
|
||||
}
|
||||
with(adapterGenerator) {
|
||||
@@ -1088,7 +1088,7 @@ class CallAndReferenceGenerator(
|
||||
)
|
||||
if (conversionFunctions.isNotEmpty()) {
|
||||
elements.forEachIndexed { i, irVarargElement ->
|
||||
val targetFun = argument.arguments[i].typeRef.toIrType().classifierOrNull?.let { conversionFunctions[it] }
|
||||
val targetFun = argument.arguments[i].coneType.toIrType().classifierOrNull?.let { conversionFunctions[it] }
|
||||
if (targetFun != null && irVarargElement is IrExpression) {
|
||||
elements[i] =
|
||||
irVarargElement.applyToElement(argument.arguments[i], targetFun)
|
||||
@@ -1103,7 +1103,7 @@ class CallAndReferenceGenerator(
|
||||
Name.identifier("to" + targetTypeFqName.shortName().asString()),
|
||||
StandardNames.BUILT_INS_PACKAGE_NAME.asString()
|
||||
)
|
||||
val sourceTypeClassifier = argument.typeRef.toIrType().classifierOrNull ?: return this
|
||||
val sourceTypeClassifier = argument.coneType.toIrType().classifierOrNull ?: return this
|
||||
|
||||
val conversionFunction = conversionFunctions[sourceTypeClassifier] ?: return this
|
||||
|
||||
@@ -1251,8 +1251,8 @@ class CallAndReferenceGenerator(
|
||||
with(visitor.implicitCastInserter) {
|
||||
it.cast(
|
||||
qualifiedAccess.extensionReceiver,
|
||||
qualifiedAccess.extensionReceiver.typeRef,
|
||||
receiverType
|
||||
qualifiedAccess.extensionReceiver.coneType,
|
||||
receiverType.coneType,
|
||||
)
|
||||
}
|
||||
} ?: it
|
||||
|
||||
+1
-1
@@ -268,7 +268,7 @@ internal class ClassMemberGenerator(
|
||||
val irExpression = visitor.convertToIrExpression(initializerExpression, isDelegate = property.delegate != null)
|
||||
if (property.delegate == null) {
|
||||
with(visitor.implicitCastInserter) {
|
||||
irExpression.cast(initializerExpression, initializerExpression.typeRef, property.returnTypeRef)
|
||||
irExpression.cast(initializerExpression, initializerExpression.coneType, property.returnTypeRef.coneType)
|
||||
}
|
||||
} else {
|
||||
irExpression
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.expressions.FirConstExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar
|
||||
@@ -97,7 +98,7 @@ class Fir2IrLazyProperty(
|
||||
containingClass?.classKind?.isAnnotationClass == true -> initializer?.asCompileTimeIrInitializer(components)
|
||||
// Setting initializers to every other class causes some cryptic errors in lowerings
|
||||
initializer is FirConstExpression<*> -> {
|
||||
val constType = with(typeConverter) { initializer.typeRef.toIrType() }
|
||||
val constType = with(typeConverter) { initializer.coneType.toIrType() }
|
||||
factory.createExpressionBody(initializer.toIrConst(constType))
|
||||
}
|
||||
else -> null
|
||||
|
||||
Reference in New Issue
Block a user