[FIR2IR] Get rid of all usages of IrSymbol.owner from DataClassMembersGenerator

This change uncovered the following problem in pipeline: we have a contract,
  that all bodies will be generated after all fake overrides will be preprocessed.
  But DataClassMembersGenerator generates bodies before f/o creation,
  which leads to the problem, if data class has forward reference to some
  class which was not processed before (because in this case generator
  of `hashCode` function will try to reference f/o, which is not created yet,
  which leads to `SymbolAlreadyBound` problem)

```
data class Some(val a: A) {
    generated fun hashCode(): Int {
        return a.hashCode() // (1) is not generated yet
    }
}

class A {
    fake-override fun hashCode(): Int // (1)
}
```

This problem will be fixed in the next commit

(related test is compiler/testData/codegen/box/ir/kt52677.kt)

^KT-60924
This commit is contained in:
Dmitriy Novozhilov
2023-08-18 15:30:49 +03:00
committed by Space Team
parent b38de13696
commit 76d3c0e804
6 changed files with 111 additions and 56 deletions
@@ -272,6 +272,10 @@ class AnnotationImplementationMemberGenerator(
return irCallOp(context.irBuiltIns.intXorSymbol, context.irBuiltIns.intType, multiplied, propertyValueHashCode)
}
private fun IrBuilderWithScope.getHashCodeOf(type: IrType, irValue: IrExpression): IrExpression {
return getHashCodeOf(getHashCodeFunctionInfo(type), irValue)
}
// Manual implementation of equals is required for following reasons:
// 1. `other` should be casted to interface instead of implementation
// 2. Properties should be retrieved using getters without accessing backing fields
@@ -234,11 +234,11 @@ abstract class DataClassMembersGenerator(
protected open fun IrBuilderWithScope.shiftResultOfHashCode(irResultVar: IrVariable): IrExpression =
irCallOp(context.irBuiltIns.intTimesSymbol, context.irBuiltIns.intType, irGet(irResultVar), irInt(31))
protected open fun getHashCodeOf(builder: IrBuilderWithScope, property: IrProperty, irValue: IrExpression) =
builder.getHashCodeOf(property.type, irValue)
protected open fun getHashCodeOf(builder: IrBuilderWithScope, property: IrProperty, irValue: IrExpression): IrExpression {
return builder.getHashCodeOf(getHashCodeFunctionInfo(property), irValue)
}
protected fun IrBuilderWithScope.getHashCodeOf(type: IrType, irValue: IrExpression): IrExpression {
val hashCodeFunctionInfo = getHashCodeFunctionInfo(type)
protected fun IrBuilderWithScope.getHashCodeOf(hashCodeFunctionInfo: HashCodeFunctionInfo, irValue: IrExpression): IrExpression {
val hashCodeFunctionSymbol = hashCodeFunctionInfo.symbol
val hasDispatchReceiver = hashCodeFunctionSymbol.hasDispatchReceiver()
return irCall(
@@ -266,6 +266,10 @@ abstract class DataClassMembersGenerator(
fun commitSubstituted(irMemberAccessExpression: IrMemberAccessExpression<*>)
}
open fun getHashCodeFunctionInfo(property: IrProperty): HashCodeFunctionInfo {
return getHashCodeFunctionInfo(property.type)
}
abstract fun getHashCodeFunctionInfo(type: IrType): HashCodeFunctionInfo
open fun IrClass.classNameForToString(): String = irClass.name.asString()