Skip to content

Commit fe9d9ec

Browse files
mcpiromanSpace Team
authored andcommitted
[IR] Rename IrElement.attributes
Debugger shows both the field and the property. Rename them so it is clear that one is a backing filed of the other.
1 parent abb3895 commit fe9d9ec

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

compiler/ir/backend.common/test/org/jetbrains/kotlin/backend/common/IrAttributeTests.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ class IrAttributeTests {
2727
IrConstImpl.constNull(0, 0, IrErrorTypeImpl(null, listOf(), Variance.INVARIANT))
2828

2929
private val IrElement.allAttributes: Map<IrAttribute<*, *>, Any>
30-
get() = (this as IrElementBase).allAttributes
30+
get() = (this as IrElementBase).attributes
3131

3232

3333
@Test
3434
fun simpleSet() {
3535
val element = createIrElement()
3636

3737
assertEquals(null, element.foo)
38-
assertTrue(element.allAttributes.isEmpty())
38+
assertTrue(element.attributes.isEmpty())
3939

4040
element.foo = 10
4141
assertEquals(10, element.foo)
42-
assertEquals<Map<IrAttribute<*, *>, Any?>>(mapOf(fooAttr to 10), element.allAttributes)
42+
assertEquals<Map<IrAttribute<*, *>, Any?>>(mapOf(fooAttr to 10), element.attributes)
4343
}
4444

4545
@Test
@@ -83,7 +83,7 @@ class IrAttributeTests {
8383
assertEquals("test", element.baz)
8484
assertEquals<Map<IrAttribute<*, *>, Any?>>(
8585
mapOf(fooAttr to 10, barAttr to true, bazAttr to "test"),
86-
element.allAttributes
86+
element.attributes
8787
)
8888

8989
element.foo = 200
@@ -92,7 +92,7 @@ class IrAttributeTests {
9292
assertEquals(null, element.bar)
9393
assertEquals<Map<IrAttribute<*, *>, Any?>>(
9494
mapOf(fooAttr to 200, bazAttr to "test"),
95-
element.allAttributes
95+
element.attributes
9696
)
9797
}
9898

@@ -106,7 +106,7 @@ class IrAttributeTests {
106106
element.foo = it
107107
assertEquals(it, element.foo)
108108
assertEquals(true, element.bar)
109-
assertEquals(2, element.allAttributes.size)
109+
assertEquals(2, element.attributes.size)
110110

111111
element.foo = null
112112
}
@@ -131,7 +131,7 @@ class IrAttributeTests {
131131
realAttributeValues.remove(attr)
132132
}
133133
2 -> {
134-
assertEquals<Map<out IrAttribute<*, *>, Any?>>(element.allAttributes, realAttributeValues)
134+
assertEquals<Map<out IrAttribute<*, *>, Any?>>(element.attributes, realAttributeValues)
135135
}
136136
else -> {
137137
assertEquals(realAttributeValues[attr], element[attr])

compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrElementBase.kt

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class IrElementBase : IrElement {
2626
* Keys are of type [IrAttribute].
2727
* Values are arbitrary objects but cannot be null.
2828
*/
29-
private var attributeMap: Array<Any?>? = null
29+
private var _attributes: Array<Any?>? = null
3030

3131
override fun <D> transform(transformer: IrTransformer<D>, data: D): IrElement =
3232
accept(transformer, data)
@@ -44,15 +44,15 @@ abstract class IrElementBase : IrElement {
4444
* Returns a snapshot of all attributes held by this element.
4545
* Designated mainly for debugging.
4646
*/
47-
val allAttributes: Map<IrAttribute<*, *>, Any>
47+
val attributes: Map<IrAttribute<*, *>, Any>
4848
get() {
49-
val attributeMap = attributeMap
49+
val attributes = _attributes
5050
?: return emptyMap()
51-
return buildMap(attributeMap.size / 2) {
52-
for (i in attributeMap.indices step 2) {
53-
val key = attributeMap[i] as IrAttribute<*, *>?
51+
return buildMap(attributes.size / 2) {
52+
for (i in attributes.indices step 2) {
53+
val key = attributes[i] as IrAttribute<*, *>?
5454
?: break
55-
val value = attributeMap[i + 1]!!
55+
val value = attributes[i + 1]!!
5656
put(key, value)
5757
}
5858
}
@@ -64,28 +64,28 @@ abstract class IrElementBase : IrElement {
6464
return null
6565
} else {
6666
@Suppress("UNCHECKED_CAST")
67-
return attributeMap!![foundIndex + 1] as T
67+
return _attributes!![foundIndex + 1] as T
6868
}
6969
}
7070

7171
internal fun <T : Any> setAttributeInternal(key: IrAttribute<*, T>, value: T?): T? {
7272
val foundIndex = findAttributeIndex(key)
7373
val previousValue: T? = if (foundIndex >= 0) {
7474
@Suppress("UNCHECKED_CAST")
75-
attributeMap!![foundIndex + 1] as T
75+
_attributes!![foundIndex + 1] as T
7676
} else null
7777

7878
putAttribute(foundIndex, key, value)
7979
return previousValue
8080
}
8181

8282
private fun findAttributeIndex(key: IrAttribute<*, *>): Int {
83-
val attributeMap = attributeMap
83+
val attributes = _attributes
8484
?: return -1
8585

8686
var i = 0
87-
while (i < attributeMap.size) {
88-
val foundKey = attributeMap[i]
87+
while (i < attributes.size) {
88+
val foundKey = attributes[i]
8989
?: break
9090
if (foundKey === key) {
9191
return i
@@ -98,21 +98,21 @@ abstract class IrElementBase : IrElement {
9898

9999
private fun <T : Any> initializeAttributes(firstKey: IrAttribute<*, T>, firstValue: T) {
100100
val initialSlots = 1
101-
val attributeMap = arrayOfNulls<Any?>(initialSlots * 2)
102-
attributeMap[0] = firstKey
103-
attributeMap[1] = firstValue
104-
this.attributeMap = attributeMap
101+
val attributes = arrayOfNulls<Any?>(initialSlots * 2)
102+
attributes[0] = firstKey
103+
attributes[1] = firstValue
104+
this._attributes = attributes
105105
}
106106

107107
private fun <T : Any> putAttribute(existingIndex: Int, key: IrAttribute<*, T>, value: T?) {
108108
if (existingIndex >= 0) {
109109
if (value == null) {
110110
removeAttributeAt(existingIndex)
111111
} else {
112-
attributeMap!![existingIndex + 1] = value
112+
_attributes!![existingIndex + 1] = value
113113
}
114114
} else if (value != null) {
115-
if (attributeMap == null) {
115+
if (_attributes == null) {
116116
initializeAttributes(key, value)
117117
} else {
118118
val newEntryIndex = existingIndex.inv()
@@ -122,33 +122,33 @@ abstract class IrElementBase : IrElement {
122122
}
123123

124124
private fun <T : Any> addAttributeAt(index: Int, key: IrAttribute<*, T>, value: T) {
125-
var attributeMap = attributeMap!!
126-
if (attributeMap.size <= index) {
125+
var attributes = _attributes!!
126+
if (attributes.size <= index) {
127127
val newSlots = 2
128-
attributeMap = attributeMap.copyOf(attributeMap.size + newSlots * 2)
129-
this.attributeMap = attributeMap
128+
attributes = attributes.copyOf(attributes.size + newSlots * 2)
129+
this._attributes = attributes
130130
}
131131

132-
attributeMap[index] = key
133-
attributeMap[index + 1] = value
132+
attributes[index] = key
133+
attributes[index + 1] = value
134134
}
135135

136136
private fun removeAttributeAt(keyIndex: Int) {
137137
// It is expected that during the compilation process, attributes are mostly appended
138138
// and rarely removed, hence no need to shrink the array.
139139

140-
val attributeMap = attributeMap!!
140+
val attributes = _attributes!!
141141

142-
var lastKeyIndex = attributeMap.size - 2
143-
while (lastKeyIndex > keyIndex && attributeMap[lastKeyIndex] == null) {
142+
var lastKeyIndex = attributes.size - 2
143+
while (lastKeyIndex > keyIndex && attributes[lastKeyIndex] == null) {
144144
lastKeyIndex -= 2
145145
}
146146

147147
if (lastKeyIndex > keyIndex) {
148-
attributeMap[keyIndex] = attributeMap[lastKeyIndex]
149-
attributeMap[keyIndex + 1] = attributeMap[lastKeyIndex + 1]
148+
attributes[keyIndex] = attributes[lastKeyIndex]
149+
attributes[keyIndex + 1] = attributes[lastKeyIndex + 1]
150150
}
151-
attributeMap[lastKeyIndex] = null
152-
attributeMap[lastKeyIndex + 1] = null
151+
attributes[lastKeyIndex] = null
152+
attributes[lastKeyIndex + 1] = null
153153
}
154154
}

0 commit comments

Comments
 (0)