FIR2IR: simplify ConversionTypeOrigin/Context
This commit is contained in:
committed by
Space Team
parent
2c0c9e5b5c
commit
0e6a7bbe82
@@ -61,7 +61,6 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
|
||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
|
||||
fun AbstractKtSourceElement?.startOffsetSkippingComments(): Int? {
|
||||
return when (this) {
|
||||
@@ -110,37 +109,26 @@ internal fun <T : IrElement> FirStatement.convertWithOffsets(
|
||||
|
||||
internal fun createErrorType(): IrErrorType = IrErrorTypeImpl(null, emptyList(), Variance.INVARIANT)
|
||||
|
||||
internal enum class ConversionTypeOrigin {
|
||||
DEFAULT,
|
||||
SETTER
|
||||
}
|
||||
|
||||
class ConversionTypeContext private constructor(internal val origin: ConversionTypeOrigin) {
|
||||
companion object {
|
||||
internal val DEFAULT = ConversionTypeContext(
|
||||
origin = ConversionTypeOrigin.DEFAULT
|
||||
)
|
||||
internal val IN_SETTER = ConversionTypeContext(
|
||||
origin = ConversionTypeOrigin.SETTER
|
||||
)
|
||||
}
|
||||
enum class ConversionTypeOrigin(val forSetter: Boolean) {
|
||||
DEFAULT(forSetter = false),
|
||||
SETTER(forSetter = true);
|
||||
}
|
||||
|
||||
context(Fir2IrComponents)
|
||||
fun FirClassifierSymbol<*>.toSymbol(
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT,
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
||||
handleAnnotations: ((List<FirAnnotation>) -> Unit)? = null
|
||||
): IrClassifierSymbol {
|
||||
return when (this) {
|
||||
is FirTypeParameterSymbol -> {
|
||||
classifierStorage.getIrTypeParameterSymbol(this, typeContext)
|
||||
classifierStorage.getIrTypeParameterSymbol(this, typeOrigin)
|
||||
}
|
||||
|
||||
is FirTypeAliasSymbol -> {
|
||||
handleAnnotations?.invoke(fir.expandedTypeRef.annotations)
|
||||
val coneClassLikeType = fir.expandedTypeRef.coneType as ConeClassLikeType
|
||||
coneClassLikeType.lookupTag.toSymbol(session)
|
||||
?.toSymbol(typeContext, handleAnnotations)
|
||||
?.toSymbol(typeOrigin, handleAnnotations)
|
||||
?: classifierStorage.getIrClassSymbolForNotFoundClass(coneClassLikeType.lookupTag)
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class Fir2IrBuiltIns(
|
||||
}
|
||||
|
||||
private val extensionFunctionTypeAnnotationSymbol by lazy {
|
||||
extensionFunctionTypeAnnotationFirSymbol?.toSymbol(ConversionTypeContext.DEFAULT) as? IrClassSymbol
|
||||
extensionFunctionTypeAnnotationFirSymbol?.toSymbol(ConversionTypeOrigin.DEFAULT) as? IrClassSymbol
|
||||
}
|
||||
|
||||
internal fun extensionFunctionTypeAnnotationConstructorCall(): IrConstructorCall? =
|
||||
|
||||
+16
-16
@@ -66,8 +66,8 @@ class Fir2IrClassifierStorage(
|
||||
commonMemberStorage.localClassCache
|
||||
)
|
||||
|
||||
private fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeContext) }
|
||||
private fun FirTypeRef.toIrType(typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeOrigin) }
|
||||
|
||||
fun preCacheBuiltinClasses() {
|
||||
for ((classId, irBuiltinSymbol) in typeConverter.classIdToSymbolMap) {
|
||||
@@ -93,7 +93,7 @@ class Fir2IrClassifierStorage(
|
||||
private fun IrClass.setThisReceiver(typeParameters: List<FirTypeParameterRef>) {
|
||||
symbolTable.enterScope(this)
|
||||
val typeArguments = typeParameters.map {
|
||||
IrSimpleTypeImpl(getIrTypeParameterSymbol(it.symbol, ConversionTypeContext.DEFAULT), false, emptyList(), emptyList())
|
||||
IrSimpleTypeImpl(getIrTypeParameterSymbol(it.symbol, ConversionTypeOrigin.DEFAULT), false, emptyList(), emptyList())
|
||||
}
|
||||
thisReceiver = declareThisReceiverParameter(
|
||||
thisType = IrSimpleTypeImpl(symbol, false, typeArguments, emptyList()),
|
||||
@@ -108,7 +108,7 @@ class Fir2IrClassifierStorage(
|
||||
getCachedIrTypeParameter(original)
|
||||
?: createIrTypeParameterWithoutBounds(original, index, irOwnerSymbol)
|
||||
if (owner is FirProperty && owner.isVar) {
|
||||
val context = ConversionTypeContext.IN_SETTER
|
||||
val context = ConversionTypeOrigin.SETTER
|
||||
getCachedIrTypeParameter(original, context)
|
||||
?: createIrTypeParameterWithoutBounds(original, index, irOwnerSymbol, context)
|
||||
}
|
||||
@@ -117,14 +117,14 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
internal fun IrTypeParametersContainer.setTypeParameters(
|
||||
owner: FirTypeParameterRefsOwner,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||
) {
|
||||
typeParameters = owner.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
||||
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
||||
getIrTypeParameter(typeParameter, index, symbol, typeContext).apply {
|
||||
getIrTypeParameter(typeParameter, index, symbol, typeOrigin).apply {
|
||||
parent = this@setTypeParameters
|
||||
if (superTypes.isEmpty()) {
|
||||
superTypes = typeParameter.bounds.map { it.toIrType(typeContext) }
|
||||
superTypes = typeParameter.bounds.map { it.toIrType(typeOrigin) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,7 +419,7 @@ class Fir2IrClassifierStorage(
|
||||
typeParameter: FirTypeParameter,
|
||||
index: Int,
|
||||
ownerSymbol: IrSymbol,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT,
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
||||
): IrTypeParameter {
|
||||
require(index >= 0)
|
||||
val origin = typeParameter.computeIrOrigin()
|
||||
@@ -476,7 +476,7 @@ class Fir2IrClassifierStorage(
|
||||
}
|
||||
|
||||
// Cache the type parameter BEFORE processing its bounds/supertypes, to properly handle recursive type bounds.
|
||||
if (typeContext.origin == ConversionTypeOrigin.SETTER) {
|
||||
if (typeOrigin.forSetter) {
|
||||
typeParameterCacheForSetter[typeParameter] = irTypeParameter
|
||||
} else {
|
||||
typeParameterCache[typeParameter] = irTypeParameter
|
||||
@@ -487,9 +487,9 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
internal fun getCachedIrTypeParameter(
|
||||
typeParameter: FirTypeParameter,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||
): IrTypeParameter? {
|
||||
return if (typeContext.origin == ConversionTypeOrigin.SETTER)
|
||||
return if (typeOrigin.forSetter)
|
||||
typeParameterCacheForSetter[typeParameter]
|
||||
else
|
||||
typeParameterCache[typeParameter]
|
||||
@@ -499,11 +499,11 @@ class Fir2IrClassifierStorage(
|
||||
typeParameter: FirTypeParameter,
|
||||
index: Int,
|
||||
ownerSymbol: IrSymbol,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||
): IrTypeParameter {
|
||||
getCachedIrTypeParameter(typeParameter, typeContext)?.let { return it }
|
||||
getCachedIrTypeParameter(typeParameter, typeOrigin)?.let { return it }
|
||||
return typeParameter.run {
|
||||
val irTypeParameter = createIrTypeParameterWithoutBounds(typeParameter, index, ownerSymbol, typeContext)
|
||||
val irTypeParameter = createIrTypeParameterWithoutBounds(typeParameter, index, ownerSymbol, typeOrigin)
|
||||
irTypeParameter.superTypes = bounds.map { it.toIrType() }
|
||||
irTypeParameter
|
||||
}
|
||||
@@ -664,10 +664,10 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
fun getIrTypeParameterSymbol(
|
||||
firTypeParameterSymbol: FirTypeParameterSymbol,
|
||||
typeContext: ConversionTypeContext
|
||||
typeOrigin: ConversionTypeOrigin
|
||||
): IrTypeParameterSymbol {
|
||||
val firTypeParameter = firTypeParameterSymbol.fir
|
||||
return getCachedIrTypeParameter(firTypeParameter, typeContext)?.symbol
|
||||
return getCachedIrTypeParameter(firTypeParameter, typeOrigin)?.symbol
|
||||
// We can try to use default cache because setter can use parent type parameters
|
||||
?: typeParameterCache[firTypeParameter]?.symbol
|
||||
?: error("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name} of the owner: ${firTypeParameter.containingDeclarationSymbol}")
|
||||
|
||||
@@ -135,8 +135,8 @@ class Fir2IrConversionScope {
|
||||
|
||||
fun parent(): IrDeclarationParent? = parentStack.lastOrNull()
|
||||
|
||||
fun defaultConversionTypeContext(): ConversionTypeContext =
|
||||
if ((parent() as? IrFunction)?.isSetter == true) ConversionTypeContext.IN_SETTER else ConversionTypeContext.DEFAULT
|
||||
fun defaultConversionTypeOrigin(): ConversionTypeOrigin =
|
||||
if ((parent() as? IrFunction)?.isSetter == true) ConversionTypeOrigin.SETTER else ConversionTypeOrigin.DEFAULT
|
||||
|
||||
fun dispatchReceiverParameter(irClass: IrClass): IrValueParameter? {
|
||||
for (function in functionStack.asReversed()) {
|
||||
|
||||
+13
-14
@@ -53,7 +53,6 @@ import org.jetbrains.kotlin.ir.expressions.IrSyntheticBodyKind
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrErrorType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
@@ -240,11 +239,11 @@ class Fir2IrDeclarationStorage(
|
||||
symbolTable.leaveScope(declaration)
|
||||
}
|
||||
|
||||
private fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeContext) }
|
||||
private fun FirTypeRef.toIrType(typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeOrigin) }
|
||||
|
||||
private fun ConeKotlinType.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeContext) }
|
||||
private fun ConeKotlinType.toIrType(typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeOrigin) }
|
||||
|
||||
private fun getIrExternalOrBuiltInsPackageFragment(fqName: FqName, firOrigin: FirDeclarationOrigin): IrExternalPackageFragment {
|
||||
val isBuiltIn = fqName in BUILT_INS_PACKAGE_FQ_NAMES
|
||||
@@ -365,10 +364,10 @@ class Fir2IrDeclarationStorage(
|
||||
setTypeParameters(function)
|
||||
}
|
||||
}
|
||||
val typeContext = if (forSetter) ConversionTypeContext.IN_SETTER else ConversionTypeContext.DEFAULT
|
||||
val typeOrigin = if (forSetter) ConversionTypeOrigin.SETTER else ConversionTypeOrigin.DEFAULT
|
||||
if (function is FirDefaultPropertySetter) {
|
||||
val valueParameter = function.valueParameters.first()
|
||||
val type = valueParameter.returnTypeRef.toIrType(ConversionTypeContext.IN_SETTER)
|
||||
val type = valueParameter.returnTypeRef.toIrType(ConversionTypeOrigin.SETTER)
|
||||
declareDefaultSetterParameter(type, valueParameter)
|
||||
} else if (function != null) {
|
||||
val contextReceivers = function.contextReceiversForFunctionOrContainingProperty()
|
||||
@@ -381,7 +380,7 @@ class Fir2IrDeclarationStorage(
|
||||
createIrParameter(
|
||||
valueParameter, index + contextReceiverParametersCount,
|
||||
useStubForDefaultValueStub = function !is FirConstructor || containingClass?.name != Name.identifier("Enum"),
|
||||
typeContext,
|
||||
typeOrigin,
|
||||
skipDefaultParameter = isFakeOverride || origin == IrDeclarationOrigin.DELEGATED_MEMBER
|
||||
).apply {
|
||||
this.parent = parent
|
||||
@@ -402,7 +401,7 @@ class Fir2IrDeclarationStorage(
|
||||
Name.identifier("\$this\$$suffix")
|
||||
} ?: SpecialNames.THIS
|
||||
declareThisReceiverParameter(
|
||||
thisType = receiver.typeRef.toIrType(typeContext),
|
||||
thisType = receiver.typeRef.toIrType(typeOrigin),
|
||||
thisOrigin = thisOrigin,
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
@@ -776,7 +775,7 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
with(classifierStorage) {
|
||||
setTypeParameters(
|
||||
property, if (isSetter) ConversionTypeContext.IN_SETTER else ConversionTypeContext.DEFAULT
|
||||
property, if (isSetter) ConversionTypeOrigin.SETTER else ConversionTypeOrigin.DEFAULT
|
||||
)
|
||||
}
|
||||
// NB: we should enter accessor' scope before declaring its parameters
|
||||
@@ -784,7 +783,7 @@ class Fir2IrDeclarationStorage(
|
||||
enterScope(this)
|
||||
if (propertyAccessor == null && isSetter) {
|
||||
declareDefaultSetterParameter(
|
||||
property.returnTypeRef.toIrType(ConversionTypeContext.IN_SETTER),
|
||||
property.returnTypeRef.toIrType(ConversionTypeOrigin.SETTER),
|
||||
firValueParameter = null
|
||||
)
|
||||
}
|
||||
@@ -1207,11 +1206,11 @@ class Fir2IrDeclarationStorage(
|
||||
valueParameter: FirValueParameter,
|
||||
index: Int = UNDEFINED_PARAMETER_INDEX,
|
||||
useStubForDefaultValueStub: Boolean = true,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT,
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
||||
skipDefaultParameter: Boolean = false,
|
||||
): IrValueParameter = convertCatching(valueParameter) {
|
||||
val origin = valueParameter.computeIrOrigin()
|
||||
val type = valueParameter.returnTypeRef.toIrType(typeContext)
|
||||
val type = valueParameter.returnTypeRef.toIrType(typeOrigin)
|
||||
val irParameter = valueParameter.convertWithOffsets { startOffset, endOffset ->
|
||||
irFactory.createValueParameter(
|
||||
startOffset = startOffset,
|
||||
@@ -1224,7 +1223,7 @@ class Fir2IrDeclarationStorage(
|
||||
index = index,
|
||||
varargElementType =
|
||||
if (!valueParameter.isVararg) null
|
||||
else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeContext),
|
||||
else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeOrigin),
|
||||
isCrossinline = valueParameter.isCrossinline,
|
||||
isNoinline = valueParameter.isNoinline,
|
||||
isHidden = false,
|
||||
|
||||
+12
-12
@@ -30,12 +30,12 @@ class Fir2IrImplicitCastInserter(
|
||||
private val components: Fir2IrComponents
|
||||
) : Fir2IrComponents by components, FirDefaultVisitor<IrElement, IrElement>() {
|
||||
|
||||
private fun FirTypeRef.toIrType(conversionTypeContext: ConversionTypeContext): IrType = with(typeConverter) {
|
||||
toIrType(conversionTypeContext)
|
||||
private fun FirTypeRef.toIrType(typeOrigin: ConversionTypeOrigin): IrType = with(typeConverter) {
|
||||
toIrType(typeOrigin)
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.toIrType(conversionTypeContext: ConversionTypeContext): IrType = with(typeConverter) {
|
||||
toIrType(conversionTypeContext)
|
||||
private fun ConeKotlinType.toIrType(typeOrigin: ConversionTypeOrigin): IrType = with(typeConverter) {
|
||||
toIrType(typeOrigin)
|
||||
}
|
||||
|
||||
override fun visitElement(element: FirElement, data: IrElement): IrElement {
|
||||
@@ -216,7 +216,7 @@ class Fir2IrImplicitCastInserter(
|
||||
}
|
||||
valueType is ConeDynamicType -> {
|
||||
if (expectedType !is ConeDynamicType && !expectedType.isNullableAny) {
|
||||
implicitCast(this, expectedType.toIrType(ConversionTypeContext.DEFAULT))
|
||||
implicitCast(this, expectedType.toIrType(ConversionTypeOrigin.DEFAULT))
|
||||
} else {
|
||||
this
|
||||
}
|
||||
@@ -282,7 +282,7 @@ class Fir2IrImplicitCastInserter(
|
||||
original: IrExpression,
|
||||
originalTypeRef: FirTypeRef,
|
||||
calleeReference: FirReference?,
|
||||
conversionTypeContext: ConversionTypeContext,
|
||||
typeOrigin: ConversionTypeOrigin,
|
||||
): IrExpression {
|
||||
val referencedDeclaration = calleeReference?.toResolvedCallableSymbol()?.unwrapCallRepresentative()?.fir
|
||||
|
||||
@@ -295,23 +295,23 @@ class Fir2IrImplicitCastInserter(
|
||||
val castType = originalTypeRef.coneTypeSafe<ConeIntersectionType>()
|
||||
castType?.intersectedTypes?.forEach { componentType ->
|
||||
if (AbstractTypeChecker.isSubtypeOf(session.typeContext, componentType, starProjectedDispatchReceiver)) {
|
||||
return implicitCastOrExpression(original, componentType, conversionTypeContext)
|
||||
return implicitCastOrExpression(original, componentType, typeOrigin)
|
||||
}
|
||||
}
|
||||
|
||||
return implicitCastOrExpression(original, originalTypeRef, conversionTypeContext)
|
||||
return implicitCastOrExpression(original, originalTypeRef, typeOrigin)
|
||||
}
|
||||
|
||||
private fun implicitCastOrExpression(
|
||||
original: IrExpression, castType: ConeKotlinType, conversionTypeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
original: IrExpression, castType: ConeKotlinType, typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||
): IrExpression {
|
||||
return implicitCastOrExpression(original, castType.toIrType(conversionTypeContext))
|
||||
return implicitCastOrExpression(original, castType.toIrType(typeOrigin))
|
||||
}
|
||||
|
||||
private fun implicitCastOrExpression(
|
||||
original: IrExpression, castType: FirTypeRef, conversionTypeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
original: IrExpression, castType: FirTypeRef, typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||
): IrExpression {
|
||||
return implicitCastOrExpression(original, castType.toIrType(conversionTypeContext))
|
||||
return implicitCastOrExpression(original, castType.toIrType(typeOrigin))
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -89,11 +89,11 @@ class Fir2IrTypeConverter(
|
||||
override val intersectionTypesInContravariantPositions: Boolean get() = true
|
||||
}
|
||||
|
||||
fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType {
|
||||
fun FirTypeRef.toIrType(typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT): IrType {
|
||||
capturedTypeCache.clear()
|
||||
return when (this) {
|
||||
!is FirResolvedTypeRef -> createErrorType()
|
||||
!is FirImplicitBuiltinTypeRef -> type.toIrType(typeContext, annotations)
|
||||
!is FirImplicitBuiltinTypeRef -> type.toIrType(typeOrigin, annotations)
|
||||
is FirImplicitNothingTypeRef -> irBuiltIns.nothingType
|
||||
is FirImplicitUnitTypeRef -> irBuiltIns.unitType
|
||||
is FirImplicitBooleanTypeRef -> irBuiltIns.booleanType
|
||||
@@ -102,12 +102,12 @@ class Fir2IrTypeConverter(
|
||||
is FirImplicitIntTypeRef -> irBuiltIns.intType
|
||||
is FirImplicitNullableAnyTypeRef -> irBuiltIns.anyNType
|
||||
is FirImplicitNullableNothingTypeRef -> irBuiltIns.nothingNType
|
||||
else -> type.toIrType(typeContext, annotations)
|
||||
else -> type.toIrType(typeOrigin, annotations)
|
||||
}
|
||||
}
|
||||
|
||||
fun ConeKotlinType.toIrType(
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT,
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT,
|
||||
annotations: List<FirAnnotation> = emptyList(),
|
||||
hasFlexibleNullability: Boolean = false,
|
||||
hasFlexibleMutability: Boolean = false,
|
||||
@@ -121,7 +121,7 @@ class Fir2IrTypeConverter(
|
||||
|
||||
val irSymbol =
|
||||
getBuiltInClassSymbol(classId)
|
||||
?: lookupTag.toSymbol(session)?.toSymbol(typeContext) {
|
||||
?: lookupTag.toSymbol(session)?.toSymbol(typeOrigin) {
|
||||
typeAnnotations += with(annotationGenerator) { it.toIrAnnotations() }
|
||||
}
|
||||
?: (lookupTag as? ConeClassLikeLookupTag)?.let(classifierStorage::getIrClassSymbolForNotFoundClass)
|
||||
@@ -169,7 +169,7 @@ class Fir2IrTypeConverter(
|
||||
IrSimpleTypeImpl(
|
||||
irSymbol,
|
||||
hasQuestionMark = approximatedType.isMarkedNullable,
|
||||
arguments = approximatedType.typeArguments.map { it.toIrTypeArgument(typeContext) },
|
||||
arguments = approximatedType.typeArguments.map { it.toIrTypeArgument(typeOrigin) },
|
||||
annotations = typeAnnotations
|
||||
)
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class Fir2IrTypeConverter(
|
||||
// Upper bound has star projections here, so we take lower one
|
||||
// (some reflection tests rely on this)
|
||||
lowerBound.toIrType(
|
||||
typeContext,
|
||||
typeOrigin,
|
||||
annotations,
|
||||
hasFlexibleNullability = lowerBound.nullability != upperBound.nullability,
|
||||
hasFlexibleMutability = isMutabilityFlexible(),
|
||||
@@ -198,14 +198,14 @@ class Fir2IrTypeConverter(
|
||||
(intermediate.withNullability(upper.isNullable) as ConeKotlinType)
|
||||
.withAttributes(lower.attributes)
|
||||
.toIrType(
|
||||
typeContext,
|
||||
typeOrigin,
|
||||
annotations,
|
||||
hasFlexibleNullability = lower.nullability != upper.nullability,
|
||||
hasFlexibleMutability = isMutabilityFlexible()
|
||||
)
|
||||
} else {
|
||||
upperBound.toIrType(
|
||||
typeContext,
|
||||
typeOrigin,
|
||||
annotations,
|
||||
hasFlexibleNullability = lowerBound.nullability != upperBound.nullability,
|
||||
hasFlexibleMutability = isMutabilityFlexible()
|
||||
@@ -220,7 +220,7 @@ class Fir2IrTypeConverter(
|
||||
val approximation = supertypes.find {
|
||||
it == (constructor.projection as? ConeKotlinTypeProjection)?.type
|
||||
} ?: supertypes.first()
|
||||
val irType = approximation.toIrType(typeContext)
|
||||
val irType = approximation.toIrType(typeOrigin)
|
||||
capturedTypeCache[this] = irType
|
||||
irType
|
||||
} else {
|
||||
@@ -231,11 +231,11 @@ class Fir2IrTypeConverter(
|
||||
}
|
||||
}
|
||||
is ConeDefinitelyNotNullType -> {
|
||||
original.toIrType(typeContext).makeNotNull()
|
||||
original.toIrType(typeOrigin).makeNotNull()
|
||||
}
|
||||
is ConeIntersectionType -> {
|
||||
// TODO: add intersectionTypeApproximation
|
||||
intersectedTypes.first().toIrType(typeContext)
|
||||
intersectedTypes.first().toIrType(typeOrigin)
|
||||
}
|
||||
is ConeStubType -> createErrorType()
|
||||
is ConeIntegerLiteralType -> createErrorType()
|
||||
@@ -250,9 +250,9 @@ class Fir2IrTypeConverter(
|
||||
CommonFlexibleTypeBoundsChecker.getBaseBoundFqNameByMutability(upperFqName)
|
||||
}
|
||||
|
||||
private fun ConeTypeProjection.toIrTypeArgument(typeContext: ConversionTypeContext): IrTypeArgument {
|
||||
private fun ConeTypeProjection.toIrTypeArgument(typeOrigin: ConversionTypeOrigin): IrTypeArgument {
|
||||
fun toIrTypeArgument(type: ConeKotlinType, variance: Variance): IrTypeProjection {
|
||||
val irType = type.toIrType(typeContext)
|
||||
val irType = type.toIrType(typeOrigin)
|
||||
return makeTypeProjection(irType, variance)
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ class Fir2IrTypeConverter(
|
||||
// We can return * early here to avoid recursive type conversions.
|
||||
IrStarProjectionImpl
|
||||
} else {
|
||||
val irType = toIrType(typeContext)
|
||||
val irType = toIrType(typeOrigin)
|
||||
makeTypeProjection(irType, Variance.INVARIANT)
|
||||
}
|
||||
}
|
||||
@@ -331,8 +331,8 @@ class Fir2IrTypeConverter(
|
||||
|
||||
fun FirTypeRef.toIrType(
|
||||
typeConverter: Fir2IrTypeConverter,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT
|
||||
): IrType =
|
||||
with(typeConverter) {
|
||||
toIrType(typeContext)
|
||||
toIrType(typeOrigin)
|
||||
}
|
||||
|
||||
@@ -816,7 +816,7 @@ class Fir2IrVisitor(
|
||||
|
||||
implicitCastInserter.implicitCastFromDispatchReceiver(
|
||||
this, expression.typeRef, calleeReference,
|
||||
conversionScope.defaultConversionTypeContext()
|
||||
conversionScope.defaultConversionTypeOrigin()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1411,7 +1411,7 @@ class Fir2IrVisitor(
|
||||
}
|
||||
val irClassReferenceSymbol = when (argument) {
|
||||
is FirResolvedReifiedParameterReference -> {
|
||||
classifierStorage.getIrTypeParameterSymbol(argument.symbol, ConversionTypeContext.DEFAULT)
|
||||
classifierStorage.getIrTypeParameterSymbol(argument.symbol, ConversionTypeOrigin.DEFAULT)
|
||||
}
|
||||
is FirResolvedQualifier -> {
|
||||
when (val symbol = argument.symbol) {
|
||||
|
||||
+3
-3
@@ -80,8 +80,8 @@ internal class AdapterGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeContext) }
|
||||
private fun ConeKotlinType.toIrType(typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT): IrType =
|
||||
with(typeConverter) { toIrType(typeOrigin) }
|
||||
|
||||
internal fun needToGenerateAdaptedCallableReference(
|
||||
callableReferenceAccess: FirCallableReferenceAccess,
|
||||
@@ -440,7 +440,7 @@ internal class AdapterGenerator(
|
||||
}
|
||||
|
||||
val samFirType = substitutedParameterType.removeExternalProjections() ?: substitutedParameterType
|
||||
val samType = samFirType.toIrType(ConversionTypeContext.DEFAULT)
|
||||
val samType = samFirType.toIrType(ConversionTypeOrigin.DEFAULT)
|
||||
// Make sure the converted IrType owner indeed has a single abstract method, since FunctionReferenceLowering relies on it.
|
||||
if (!samType.isSamType) return this
|
||||
return IrTypeOperatorCallImpl(
|
||||
|
||||
+2
-2
@@ -54,10 +54,10 @@ class CallAndReferenceGenerator(
|
||||
private val adapterGenerator = AdapterGenerator(components, conversionScope)
|
||||
|
||||
private fun FirTypeRef.toIrType(): IrType =
|
||||
with(typeConverter) { toIrType(conversionScope.defaultConversionTypeContext()) }
|
||||
with(typeConverter) { toIrType(conversionScope.defaultConversionTypeOrigin()) }
|
||||
|
||||
private fun ConeKotlinType.toIrType(): IrType =
|
||||
with(typeConverter) { toIrType(conversionScope.defaultConversionTypeContext()) }
|
||||
with(typeConverter) { toIrType(conversionScope.defaultConversionTypeOrigin()) }
|
||||
|
||||
fun convertToIrCallableReference(
|
||||
callableReferenceAccess: FirCallableReferenceAccess,
|
||||
|
||||
@@ -197,7 +197,7 @@ class Fir2IrLazyProperty(
|
||||
correspondingPropertySymbol = this@Fir2IrLazyProperty.symbol
|
||||
with(classifierStorage) {
|
||||
setTypeParameters(
|
||||
this@Fir2IrLazyProperty.fir, ConversionTypeContext.DEFAULT
|
||||
this@Fir2IrLazyProperty.fir, ConversionTypeOrigin.DEFAULT
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -229,7 +229,7 @@ class Fir2IrLazyProperty(
|
||||
correspondingPropertySymbol = this@Fir2IrLazyProperty.symbol
|
||||
with(classifierStorage) {
|
||||
setTypeParameters(
|
||||
this@Fir2IrLazyProperty.fir, ConversionTypeContext.IN_SETTER
|
||||
this@Fir2IrLazyProperty.fir, ConversionTypeOrigin.SETTER
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,5 +119,5 @@ class Fir2IrLazyPropertyAccessor(
|
||||
override val containerSource: DeserializedContainerSource?
|
||||
get() = firParentProperty.containerSource
|
||||
|
||||
private val conversionTypeContext = if (isSetter) ConversionTypeContext.IN_SETTER else ConversionTypeContext.DEFAULT
|
||||
private val conversionTypeContext = if (isSetter) ConversionTypeOrigin.SETTER else ConversionTypeOrigin.DEFAULT
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user