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