FIR2IR: minimize scope processing in data class synthetic member generation
This commit is contained in:
committed by
Mikhail Glukhikh
parent
22d6433cf6
commit
c830aed946
+12
-20
@@ -189,31 +189,27 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||
} else
|
||||
null
|
||||
}
|
||||
val scope = klass.unsubstitutedScope(
|
||||
components.session,
|
||||
components.scopeSession,
|
||||
withForcedTypeCalculator = true
|
||||
)
|
||||
val contributedFunctionsInSupertypes =
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
buildMap<Name, FirSimpleFunction> {
|
||||
for (name in listOf(EQUALS, HASHCODE_NAME, TO_STRING)) {
|
||||
klass.unsubstitutedScope(
|
||||
components.session,
|
||||
components.scopeSession,
|
||||
withForcedTypeCalculator = true
|
||||
).processFunctionsByName(name) {
|
||||
// We won't synthesize a function if there is a user-contributed one.
|
||||
if (contributedFunctionsInThisType.contains(name)) continue
|
||||
scope.processFunctionsByName(name) {
|
||||
val declaration = it.fir
|
||||
if (declaration.matchesDataClassSyntheticMemberSignatures) {
|
||||
if (declaration.matchesDataClassSyntheticMemberSignatures && declaration.modality != Modality.FINAL) {
|
||||
putIfAbsent(declaration.name, declaration)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isOverridableDeclaration(name: Name): Boolean {
|
||||
val declaration = contributedFunctionsInSupertypes[name] ?: return false
|
||||
return declaration.modality != Modality.FINAL
|
||||
}
|
||||
|
||||
if (!contributedFunctionsInThisType.contains(EQUALS) &&
|
||||
isOverridableDeclaration(EQUALS)
|
||||
) {
|
||||
if (contributedFunctionsInSupertypes.containsKey(EQUALS)) {
|
||||
result.add(contributedFunctionsInSupertypes.getValue(EQUALS))
|
||||
val equalsFunction = createSyntheticIrFunction(
|
||||
EQUALS,
|
||||
@@ -224,9 +220,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||
irClass.declarations.add(equalsFunction)
|
||||
}
|
||||
|
||||
if (!contributedFunctionsInThisType.contains(HASHCODE_NAME) &&
|
||||
isOverridableDeclaration(HASHCODE_NAME)
|
||||
) {
|
||||
if (contributedFunctionsInSupertypes.containsKey(HASHCODE_NAME)) {
|
||||
result.add(contributedFunctionsInSupertypes.getValue(HASHCODE_NAME))
|
||||
val hashCodeFunction = createSyntheticIrFunction(
|
||||
HASHCODE_NAME,
|
||||
@@ -236,9 +230,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||
irClass.declarations.add(hashCodeFunction)
|
||||
}
|
||||
|
||||
if (!contributedFunctionsInThisType.contains(TO_STRING) &&
|
||||
isOverridableDeclaration(TO_STRING)
|
||||
) {
|
||||
if (contributedFunctionsInSupertypes.containsKey(TO_STRING)) {
|
||||
result.add(contributedFunctionsInSupertypes.getValue(TO_STRING))
|
||||
val toStringFunction = createSyntheticIrFunction(
|
||||
TO_STRING,
|
||||
|
||||
Reference in New Issue
Block a user