[Commonizer] Commonize 'const val' and 'val' properties
This commit is contained in:
committed by
Space
parent
9794068f22
commit
20f55ef0b7
@@ -13,7 +13,7 @@ interface CirProperty : CirFunctionOrProperty, CirLiftedUpDeclaration {
|
||||
val isExternal: Boolean
|
||||
val isVar: Boolean
|
||||
val isLateInit: Boolean
|
||||
var isConst: Boolean
|
||||
val isConst: Boolean
|
||||
val isDelegate: Boolean
|
||||
val getter: CirPropertyGetter?
|
||||
val setter: CirPropertySetter?
|
||||
|
||||
@@ -22,11 +22,6 @@ class PropertyCommonizer(classifiers: CirKnownClassifiers) : AbstractFunctionOrP
|
||||
val constCommonizationState = constCommonizationState
|
||||
val constCompileTimeInitializer = (constCommonizationState as? ConstSameValue)?.compileTimeInitializer
|
||||
|
||||
if (constCommonizationState is ConstMultipleValues) {
|
||||
// fix all commonized properties to make then non-const
|
||||
constCommonizationState.properties.forEach { it.isConst = false }
|
||||
}
|
||||
|
||||
return CirProperty.create(
|
||||
annotations = emptyList(),
|
||||
name = name,
|
||||
@@ -73,23 +68,20 @@ class PropertyCommonizer(classifiers: CirKnownClassifiers) : AbstractFunctionOrP
|
||||
when (constCommonizationState) {
|
||||
NonConst -> {
|
||||
// previous property was not constant
|
||||
return false
|
||||
this.constCommonizationState = NonConst
|
||||
}
|
||||
is Const -> {
|
||||
// previous property was constant
|
||||
constCommonizationState.properties += next
|
||||
|
||||
if (constCommonizationState is ConstSameValue) {
|
||||
if (constCommonizationState.compileTimeInitializer != next.compileTimeInitializer) {
|
||||
// const properties have different constants
|
||||
this.constCommonizationState = ConstMultipleValues(constCommonizationState)
|
||||
this.constCommonizationState = ConstMultipleValues()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (constCommonizationState != NonConst) {
|
||||
// previous property was constant but this one is not
|
||||
return false
|
||||
this.constCommonizationState = NonConst
|
||||
}
|
||||
|
||||
val result = super.doCommonizeWith(next)
|
||||
@@ -105,9 +97,7 @@ class PropertyCommonizer(classifiers: CirKnownClassifiers) : AbstractFunctionOrP
|
||||
private sealed class ConstCommonizationState {
|
||||
object NonConst : ConstCommonizationState()
|
||||
|
||||
abstract class Const : ConstCommonizationState() {
|
||||
val properties: MutableList<CirProperty> = mutableListOf()
|
||||
}
|
||||
abstract class Const : ConstCommonizationState()
|
||||
|
||||
class ConstSameValue(val compileTimeInitializer: CirConstantValue) : Const() {
|
||||
init {
|
||||
@@ -115,10 +105,6 @@ class PropertyCommonizer(classifiers: CirKnownClassifiers) : AbstractFunctionOrP
|
||||
}
|
||||
}
|
||||
|
||||
class ConstMultipleValues(previous: ConstSameValue) : Const() {
|
||||
init {
|
||||
properties += previous.properties
|
||||
}
|
||||
}
|
||||
class ConstMultipleValues : Const()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ internal class TypeAliasTypeCommonizer(private val classifiers: CirKnownClassifi
|
||||
override fun build(typeAliasId: CirEntityId, arguments: List<CirTypeProjection>, isMarkedNullable: Boolean) =
|
||||
CirClassType.createInterned(
|
||||
classId = typeAliasId,
|
||||
outerType = null, // there can't be outer type // TODO NOW!!!
|
||||
outerType = null, // there can't be outer type
|
||||
visibility = commonClass.visibility,
|
||||
arguments = arguments,
|
||||
isMarkedNullable = isMarkedNullable
|
||||
|
||||
Vendored
+2
@@ -1,4 +1,6 @@
|
||||
const val property1 = 42
|
||||
expect val property2: Int
|
||||
expect val property3: Int
|
||||
expect val property4: Int
|
||||
|
||||
const val property5: Byte = 42
|
||||
|
||||
+5
-5
@@ -557,7 +557,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"a", """
|
||||
typealias Proxy = Long
|
||||
typealias X = Proxy
|
||||
val x: X
|
||||
const val x: X = 42L
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -565,7 +565,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"b", """
|
||||
typealias Proxy = Long
|
||||
typealias X = Proxy
|
||||
val x: X
|
||||
const val x: X = 42L
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -573,7 +573,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"c", """
|
||||
typealias Proxy = Int
|
||||
typealias X = Proxy
|
||||
val x: X
|
||||
const val x: X = 42
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
@@ -581,7 +581,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"d", """
|
||||
typealias Proxy = Short
|
||||
typealias X = Proxy
|
||||
val x: X
|
||||
const val x: X = 42
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
@@ -590,7 +590,7 @@ class HierarchicalClassAndTypeAliasCommonizationTest : AbstractInlineSourcesComm
|
||||
"(a, b)", """
|
||||
typealias Proxy = Long
|
||||
typealias X = Proxy
|
||||
expect val x: X
|
||||
const val x: X = 42L
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user