[Commonizer] Encapsulate interning inside of CIR entities: CirPropertyGetter

This commit is contained in:
Dmitriy Dolovov
2021-03-04 13:15:01 +03:00
parent ec1e4fb26e
commit f1739980d3
4 changed files with 44 additions and 50 deletions
@@ -5,4 +5,43 @@
package org.jetbrains.kotlin.descriptors.commonizer.cir
interface CirPropertyGetter : CirPropertyAccessor
import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner
interface CirPropertyGetter : CirPropertyAccessor {
companion object {
// optimization for speed
val DEFAULT_NO_ANNOTATIONS: CirPropertyGetter
fun createInterned(
annotations: List<CirAnnotation>,
isDefault: Boolean,
isExternal: Boolean,
isInline: Boolean
): CirPropertyGetter = interner.intern(
CirPropertyGetterInternedImpl(
annotations = annotations,
isDefault = isDefault,
isExternal = isExternal,
isInline = isInline
)
)
private val interner = Interner<CirPropertyGetterInternedImpl>()
init {
DEFAULT_NO_ANNOTATIONS = createInterned(
annotations = emptyList(),
isDefault = true,
isExternal = false,
isInline = false
)
}
}
}
private data class CirPropertyGetterInternedImpl(
override val annotations: List<CirAnnotation>,
override val isDefault: Boolean,
override val isExternal: Boolean,
override val isInline: Boolean
) : CirPropertyGetter
@@ -8,22 +8,9 @@ package org.jetbrains.kotlin.descriptors.commonizer.cir.factory
import kotlinx.metadata.Flag
import kotlinx.metadata.KmProperty
import kotlinx.metadata.klib.getterAnnotations
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertyGetter
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirPropertyGetterImpl
import org.jetbrains.kotlin.descriptors.commonizer.utils.Interner
object CirPropertyGetterFactory {
private val interner = Interner<CirPropertyGetter>()
// speed optimization
val DEFAULT_NO_ANNOTATIONS: CirPropertyGetter = create(
annotations = emptyList(),
isDefault = true,
isExternal = false,
isInline = false
)
fun create(source: KmProperty, typeResolver: CirTypeResolver): CirPropertyGetter? {
if (!Flag.Property.HAS_GETTER(source.flags))
return null
@@ -34,29 +21,13 @@ object CirPropertyGetterFactory {
val annotations = CirAnnotationFactory.createAnnotations(getterFlags, typeResolver, source::getterAnnotations)
if (isDefault && annotations.isEmpty())
return DEFAULT_NO_ANNOTATIONS
return CirPropertyGetter.DEFAULT_NO_ANNOTATIONS
return create(
return CirPropertyGetter.createInterned(
annotations = annotations,
isDefault = isDefault,
isExternal = Flag.PropertyAccessor.IS_EXTERNAL(getterFlags),
isInline = Flag.PropertyAccessor.IS_INLINE(getterFlags)
)
}
fun create(
annotations: List<CirAnnotation>,
isDefault: Boolean,
isExternal: Boolean,
isInline: Boolean
): CirPropertyGetter {
return interner.intern(
CirPropertyGetterImpl(
annotations = annotations,
isDefault = isDefault,
isExternal = isExternal,
isInline = isInline
)
)
}
}
@@ -1,16 +0,0 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.descriptors.commonizer.cir.impl
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertyGetter
data class CirPropertyGetterImpl(
override val annotations: List<CirAnnotation>,
override val isDefault: Boolean,
override val isExternal: Boolean,
override val isInline: Boolean
) : CirPropertyGetter
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirConstantValue
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirProperty
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPropertyGetter
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirPropertyFactory
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirPropertyGetterFactory
import org.jetbrains.kotlin.descriptors.commonizer.core.PropertyCommonizer.ConstCommonizationState.*
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers
@@ -43,7 +43,7 @@ class PropertyCommonizer(classifiers: CirKnownClassifiers) : AbstractFunctionOrP
isLateInit = false,
isConst = constCompileTimeInitializer != null,
isDelegate = false,
getter = CirPropertyGetterFactory.DEFAULT_NO_ANNOTATIONS,
getter = CirPropertyGetter.DEFAULT_NO_ANNOTATIONS,
setter = setter,
backingFieldAnnotations = emptyList(),
delegateFieldAnnotations = emptyList(),