[PIR] Use simple fast hashCode

This commit is contained in:
Roman Artemev
2021-07-30 15:04:12 +03:00
committed by teamcityserver
parent 11f70412e7
commit 15648da2b4
15 changed files with 62 additions and 18 deletions
@@ -45,6 +45,9 @@ internal class PersistentIrAnonymousInitializer(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
@ObsoleteDescriptorBasedAPI
override val descriptor: ClassDescriptor
@@ -5,23 +5,9 @@
package org.jetbrains.kotlin.ir.declarations.persistent
import java.util.ArrayList
import java.util.Collections
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
import org.jetbrains.kotlin.descriptors.InlineClassRepresentation
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.ClassCarrier
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
@@ -32,6 +18,7 @@ import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.name.Name
import java.util.*
// Auto-generated by compiler/ir/ir.tree.persistent/generator/src/org/jetbrains/kotlin/ir/persistentIrGenerator/Main.kt. DO NOT EDIT!
@@ -72,6 +59,9 @@ internal class PersistentIrClass(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
@ObsoleteDescriptorBasedAPI
override val descriptor: ClassDescriptor
@@ -63,6 +63,9 @@ internal class PersistentIrConstructor(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
override var returnTypeFieldField: IrType = returnType
@@ -48,6 +48,9 @@ internal class PersistentIrEnumEntry(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
@ObsoleteDescriptorBasedAPI
override val descriptor: ClassDescriptor
@@ -55,6 +55,9 @@ internal class PersistentIrField(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
@ObsoleteDescriptorBasedAPI
override val descriptor: PropertyDescriptor
@@ -61,6 +61,9 @@ internal abstract class PersistentIrFunctionCommon(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
override var returnTypeFieldField: IrType = returnType
@@ -53,6 +53,9 @@ internal class PersistentIrLocalDelegatedProperty(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
@ObsoleteDescriptorBasedAPI
override val descriptor: VariableDescriptorWithAccessors
@@ -54,6 +54,9 @@ internal abstract class PersistentIrPropertyCommon(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
override var backingFieldField: IrField? = null
@@ -52,6 +52,9 @@ internal class PersistentIrTypeAlias(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
@ObsoleteDescriptorBasedAPI
override val descriptor: TypeAliasDescriptor
@@ -50,6 +50,9 @@ internal class PersistentIrTypeParameter(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
@ObsoleteDescriptorBasedAPI
override val descriptor: TypeParameterDescriptor
@@ -58,6 +58,9 @@ internal class PersistentIrValueParameter(
override var originField: IrDeclarationOrigin = origin
override var removedOn: Int = Int.MAX_VALUE
override var annotationsField: List<IrConstructorCall> = emptyList()
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
override var defaultValueField: IrExpressionBody? = null
@@ -131,6 +131,13 @@ internal object PersistentIrGenerator {
+"symbol.bind(this)"
)
// import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrDeclarationBase.Companion.hashCodeCounter
val hashCodeValue = "private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++"
val hashCodeImplementation = "override fun hashCode(): Int = hashCodeValue"
val equalsImplementation = "override fun equals(other: Any?): Boolean = (this === other)"
val hashCodeAndEqualsImpl = +"$hashCodeValue\n$hashCodeImplementation\n$equalsImplementation"
// Proto types
val protoValueParameterType = import("IrValueParameter", protoPackage, "ProtoIrValueParameter")
@@ -222,6 +229,7 @@ internal object PersistentIrGenerator {
originField,
removedOn,
annotationsField,
hashCodeAndEqualsImpl
)
val typeParametersField = Field(
@@ -7,7 +7,10 @@
package org.jetbrains.kotlin.ir.declarations.persistent
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.BodyCarrier
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.DeclarationCarrier
@@ -20,7 +23,6 @@ import org.jetbrains.kotlin.utils.addToStdlib.cast
interface PersistentIrDeclarationBase<T : DeclarationCarrier> : PersistentIrElementBase<T>, IrDeclaration, DeclarationCarrier {
var removedOn: Int
override var parentField: IrDeclarationParent?
override var parentSymbolField: IrSymbol?
@@ -68,6 +70,10 @@ interface PersistentIrDeclarationBase<T : DeclarationCarrier> : PersistentIrElem
factory.stageController.lazyLower(this)
}
}
companion object {
var hashCodeCounter = 0
}
}
interface PersistentIrElementBase<T : Carrier> : IrElement, Carrier {
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.ir.expressions.persistent
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrDeclarationBase
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
@@ -44,4 +45,8 @@ internal class PersistentIrBlockBody(
override val statements: MutableList<IrStatement>
get() = checkEnabled { statementsField }
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions.persistent
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrBodyBase
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrDeclarationBase
import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
import org.jetbrains.kotlin.ir.expressions.IrExpression
@@ -49,4 +50,8 @@ internal class PersistentIrExpressionBody private constructor(
set(e) {
checkEnabled { expressionField = e }
}
private val hashCodeValue: Int = PersistentIrDeclarationBase.hashCodeCounter++
override fun hashCode(): Int = hashCodeValue
override fun equals(other: Any?): Boolean = (this === other)
}