Minor, add comment to synthetic accessor generation for super calls
Also fix "useless elvis" warning in SyntheticAccessorLowering.
This commit is contained in:
@@ -33,7 +33,8 @@ private fun CallableMemberDescriptor.getJvmName() =
|
|||||||
fun getAccessorNameSuffix(
|
fun getAccessorNameSuffix(
|
||||||
descriptor: CallableMemberDescriptor, superCallDescriptor: ClassDescriptor?, accessorKind: AccessorKind
|
descriptor: CallableMemberDescriptor, superCallDescriptor: ClassDescriptor?, accessorKind: AccessorKind
|
||||||
): String {
|
): String {
|
||||||
if (accessorKind == AccessorKind.JVM_DEFAULT_COMPATIBILITY) return descriptor.getJvmName() + "$" + AccessorKind.JVM_DEFAULT_COMPATIBILITY.suffix
|
if (accessorKind == AccessorKind.JVM_DEFAULT_COMPATIBILITY)
|
||||||
|
return descriptor.getJvmName() + "$" + AccessorKind.JVM_DEFAULT_COMPATIBILITY.suffix
|
||||||
|
|
||||||
val suffix = when (descriptor) {
|
val suffix = when (descriptor) {
|
||||||
is ConstructorDescriptor ->
|
is ConstructorDescriptor ->
|
||||||
@@ -45,5 +46,9 @@ fun getAccessorNameSuffix(
|
|||||||
else ->
|
else ->
|
||||||
throw UnsupportedOperationException("Do not know how to create accessor for descriptor $descriptor")
|
throw UnsupportedOperationException("Do not know how to create accessor for descriptor $descriptor")
|
||||||
}
|
}
|
||||||
return if (superCallDescriptor == null) suffix else "$suffix\$s${superCallDescriptor.name.asString().hashCode()}"
|
return if (superCallDescriptor == null) suffix else "$suffix\$s${superCallDescriptor.syntheticAccessorToSuperSuffix()}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ClassDescriptor.syntheticAccessorToSuperSuffix(): String =
|
||||||
|
// TODO: change this to `fqNameUnsafe.asString().replace(".", "_")` as soon as we're ready to break compatibility with pre-KT-21178 code
|
||||||
|
name.asString().hashCode().toString()
|
||||||
|
|||||||
+4
-10
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.backend.jvm.ir.IrInlineReferenceLocator
|
|||||||
import org.jetbrains.kotlin.backend.jvm.ir.hasJvmDefault
|
import org.jetbrains.kotlin.backend.jvm.ir.hasJvmDefault
|
||||||
import org.jetbrains.kotlin.backend.jvm.ir.isLambda
|
import org.jetbrains.kotlin.backend.jvm.ir.isLambda
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.hasMangledParameters
|
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.hasMangledParameters
|
||||||
|
import org.jetbrains.kotlin.codegen.syntheticAccessorToSuperSuffix
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
@@ -467,11 +468,11 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
|||||||
parentAsClass.isJvmInterface -> if (!Visibilities.isPrivate(visibility) && hasJvmDefault()) "\$jd" else ""
|
parentAsClass.isJvmInterface -> if (!Visibilities.isPrivate(visibility) && hasJvmDefault()) "\$jd" else ""
|
||||||
|
|
||||||
// Accessor for _s_uper-qualified call
|
// Accessor for _s_uper-qualified call
|
||||||
superQualifier != null -> "\$s" + superQualifier.descriptor.name.asString().hashCode()
|
superQualifier != null -> "\$s" + superQualifier.descriptor.syntheticAccessorToSuperSuffix()
|
||||||
|
|
||||||
// Access to static members that need an accessor must be because they are inherited,
|
// Access to static members that need an accessor must be because they are inherited,
|
||||||
// hence accessed on a _s_upertype.
|
// hence accessed on a _s_upertype.
|
||||||
isStatic -> "\$s" + hashForAccessorDisambiguation()
|
isStatic -> "\$s" + parentAsClass.descriptor.syntheticAccessorToSuperSuffix()
|
||||||
|
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
@@ -496,17 +497,10 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
|||||||
|
|
||||||
// Static accesses that need an accessor must be due to being inherited, hence accessed on a
|
// Static accesses that need an accessor must be due to being inherited, hence accessed on a
|
||||||
// _s_upertype
|
// _s_upertype
|
||||||
val staticSuffix = if (isStatic) "\$s"+ hashForAccessorDisambiguation() else ""
|
val staticSuffix = if (isStatic) "\$s" + parentAsClass.descriptor.syntheticAccessorToSuperSuffix() else ""
|
||||||
return companionSuffix + staticSuffix
|
return companionSuffix + staticSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrDeclaration.hashForAccessorDisambiguation() =
|
|
||||||
if (parentAsClass.name.isSpecial) {
|
|
||||||
context.getLocalClassType(parentAsClass)?.className.hashCode() ?: parentAsClass.name.hashCode()
|
|
||||||
} else {
|
|
||||||
parentAsClass.name.identifier.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val Visibility.isPrivate
|
private val Visibility.isPrivate
|
||||||
get() = Visibilities.isPrivate(this)
|
get() = Visibilities.isPrivate(this)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user