[FIR2IR] Don't access symbol.owner in DataClassMembersGenerator

This commit is contained in:
Dmitriy Novozhilov
2023-11-27 14:09:49 +02:00
committed by Space Team
parent 50f1ea79c5
commit da531bc261
2 changed files with 16 additions and 6 deletions
@@ -109,7 +109,10 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
}
} ?: error("Property for parameter $irValueParameter")
inner class Fir2IrHashCodeFunctionInfo(override val symbol: IrSimpleFunctionSymbol) : HashCodeFunctionInfo {
inner class Fir2IrHashCodeFunctionInfo(
override val symbol: IrSimpleFunctionSymbol,
override val hasDispatchReceiver: Boolean,
) : HashCodeFunctionInfo {
override fun commitSubstituted(irMemberAccessExpression: IrMemberAccessExpression<*>) {
// TODO
}
@@ -158,8 +161,8 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
.first { (it as FirPropertySymbol).fromPrimaryConstructor } as FirPropertySymbol
val type = firProperty.resolvedReturnType.fullyExpandedType(session)
val symbol = when {
type.isArrayOrPrimitiveArray(checkUnsignedArrays = false) -> context.irBuiltIns.dataClassArrayMemberHashCodeSymbol
val (symbol, hasDispatchReceiver) = when {
type.isArrayOrPrimitiveArray(checkUnsignedArrays = false) -> context.irBuiltIns.dataClassArrayMemberHashCodeSymbol to false
else -> {
val classForType = when (val classifier = type.coerceToAny().toSymbol(session)?.fir) {
is FirRegularClass -> classifier
@@ -168,10 +171,10 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
}
val firHashCode = getHashCodeFunction(classForType)
val lookupTag = classForType.symbol.toLookupTag()
declarationStorage.getIrFunctionSymbol(firHashCode, lookupTag) as IrSimpleFunctionSymbol
declarationStorage.getIrFunctionSymbol(firHashCode, lookupTag) as IrSimpleFunctionSymbol to (firHashCode.dispatchReceiverType != null)
}
}
return Fir2IrHashCodeFunctionInfo(symbol)
return Fir2IrHashCodeFunctionInfo(symbol, hasDispatchReceiver)
}
}
@@ -240,7 +240,7 @@ abstract class DataClassMembersGenerator(
protected fun IrBuilderWithScope.getHashCodeOf(hashCodeFunctionInfo: HashCodeFunctionInfo, irValue: IrExpression): IrExpression {
val hashCodeFunctionSymbol = hashCodeFunctionInfo.symbol
val hasDispatchReceiver = hashCodeFunctionSymbol.hasDispatchReceiver()
val hasDispatchReceiver = hashCodeFunctionInfo.hasDispatchReceiver ?: hashCodeFunctionSymbol.hasDispatchReceiver()
return irCall(
hashCodeFunctionSymbol,
context.irBuiltIns.intType,
@@ -263,6 +263,13 @@ abstract class DataClassMembersGenerator(
interface HashCodeFunctionInfo {
val symbol: IrSimpleFunctionSymbol
/**
* Implement it if [symbol] may be unbound
*/
val hasDispatchReceiver: Boolean?
get() = null
fun commitSubstituted(irMemberAccessExpression: IrMemberAccessExpression<*>)
}