IR: make call symbols mutable

This will help in some lowerings which need to change the callee of a
call. Instead of creating a new call and copying everything (type
arguments, value arguments, receivers, annotations, attributes, ...),
it's easier to modify the `symbol`. In a way, this is a continuation of
22b4b29292.
This commit is contained in:
Alexander Udalov
2023-06-15 17:44:46 +02:00
committed by Space Team
parent 3744192806
commit 978553c513
28 changed files with 44 additions and 39 deletions
@@ -881,7 +881,7 @@ class FunctionInlining(
}
private class IrGetValueWithoutLocation(
override val symbol: IrValueSymbol,
override var symbol: IrValueSymbol,
override var origin: IrStatementOrigin? = null
) : IrGetValue() {
override val startOffset: Int get() = UNDEFINED_OFFSET
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.call]
*/
abstract class IrCall : IrFunctionAccessExpression() {
abstract override val symbol: IrSimpleFunctionSymbol
abstract override var symbol: IrSimpleFunctionSymbol
abstract var superQualifierSymbol: IrClassSymbol?
@@ -15,4 +15,6 @@ import org.jetbrains.kotlin.ir.symbols.IrSymbol
*
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.callableReference]
*/
abstract class IrCallableReference<S : IrSymbol> : IrMemberAccessExpression<S>()
abstract class IrCallableReference<S : IrSymbol> : IrMemberAccessExpression<S>() {
abstract override var symbol: S
}
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.classReference]
*/
abstract class IrClassReference : IrDeclarationReference() {
abstract override val symbol: IrClassifierSymbol
abstract override var symbol: IrClassifierSymbol
abstract var classType: IrType
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.constructorCall]
*/
abstract class IrConstructorCall : IrFunctionAccessExpression() {
abstract override val symbol: IrConstructorSymbol
abstract override var symbol: IrConstructorSymbol
abstract var source: SourceElement
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.delegatingConstructorCall]
*/
abstract class IrDelegatingConstructorCall : IrFunctionAccessExpression() {
abstract override val symbol: IrConstructorSymbol
abstract override var symbol: IrConstructorSymbol
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitDelegatingConstructorCall(this, data)
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.enumConstructorCall]
*/
abstract class IrEnumConstructorCall : IrFunctionAccessExpression() {
abstract override val symbol: IrConstructorSymbol
abstract override var symbol: IrConstructorSymbol
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitEnumConstructorCall(this, data)
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.fieldAccessExpression]
*/
abstract class IrFieldAccessExpression : IrDeclarationReference() {
abstract override val symbol: IrFieldSymbol
abstract override var symbol: IrFieldSymbol
abstract var superQualifierSymbol: IrClassSymbol?
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.getEnumValue]
*/
abstract class IrGetEnumValue : IrGetSingletonValue() {
abstract override val symbol: IrEnumEntrySymbol
abstract override var symbol: IrEnumEntrySymbol
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitGetEnumValue(this, data)
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.getObjectValue]
*/
abstract class IrGetObjectValue : IrGetSingletonValue() {
abstract override val symbol: IrClassSymbol
abstract override var symbol: IrClassSymbol
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitGetObjectValue(this, data)
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.rawFunctionReference]
*/
abstract class IrRawFunctionReference : IrDeclarationReference() {
abstract override val symbol: IrFunctionSymbol
abstract override var symbol: IrFunctionSymbol
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitRawFunctionReference(this, data)
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.valueAccessExpression]
*/
abstract class IrValueAccessExpression : IrDeclarationReference() {
abstract override val symbol: IrValueSymbol
abstract override var symbol: IrValueSymbol
abstract var origin: IrStatementOrigin?
}
@@ -33,7 +33,7 @@ class IrCallImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrSimpleFunctionSymbol,
override var symbol: IrSimpleFunctionSymbol,
typeArgumentsCount: Int,
valueArgumentsCount: Int,
override var origin: IrStatementOrigin? = null,
@@ -24,6 +24,6 @@ class IrClassReferenceImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrClassifierSymbol,
override var symbol: IrClassifierSymbol,
override var classType: IrType
) : IrClassReference()
@@ -21,7 +21,7 @@ class IrConstructorCallImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrConstructorSymbol,
override var symbol: IrConstructorSymbol,
typeArgumentsCount: Int,
override var constructorTypeArgumentsCount: Int,
valueArgumentsCount: Int,
@@ -31,7 +31,7 @@ class IrDelegatingConstructorCallImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrConstructorSymbol,
override var symbol: IrConstructorSymbol,
typeArgumentsCount: Int,
valueArgumentsCount: Int,
) : IrDelegatingConstructorCall() {
@@ -29,7 +29,7 @@ class IrEnumConstructorCallImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrConstructorSymbol,
override var symbol: IrConstructorSymbol,
typeArgumentsCount: Int,
valueArgumentsCount: Int
) : IrEnumConstructorCall() {
@@ -29,7 +29,7 @@ class IrFunctionReferenceImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrFunctionSymbol,
override var symbol: IrFunctionSymbol,
typeArgumentsCount: Int,
valueArgumentsCount: Int,
override var reflectionTarget: IrFunctionSymbol? = symbol,
@@ -24,5 +24,5 @@ class IrGetEnumValueImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrEnumEntrySymbol,
override var symbol: IrEnumEntrySymbol,
) : IrGetEnumValue()
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.ir.types.IrType
class IrGetFieldImpl(
override val startOffset: Int,
override val endOffset: Int,
override val symbol: IrFieldSymbol,
override var symbol: IrFieldSymbol,
override var type: IrType,
override var origin: IrStatementOrigin? = null,
override var superQualifierSymbol: IrClassSymbol? = null,
@@ -24,5 +24,5 @@ class IrGetObjectValueImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrClassSymbol
override var symbol: IrClassSymbol
) : IrGetObjectValue()
@@ -14,7 +14,7 @@ class IrGetValueImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrValueSymbol,
override var symbol: IrValueSymbol,
override var origin: IrStatementOrigin? = null
) : IrGetValue() {
constructor(
@@ -30,7 +30,7 @@ class IrLocalDelegatedPropertyReferenceImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrLocalDelegatedPropertySymbol,
override var symbol: IrLocalDelegatedPropertySymbol,
override var delegate: IrVariableSymbol,
override var getter: IrSimpleFunctionSymbol,
override var setter: IrSimpleFunctionSymbol?,
@@ -30,7 +30,7 @@ class IrPropertyReferenceImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrPropertySymbol,
override var symbol: IrPropertySymbol,
typeArgumentsCount: Int,
override var field: IrFieldSymbol?,
override var getter: IrSimpleFunctionSymbol?,
@@ -24,5 +24,5 @@ class IrRawFunctionReferenceImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrFunctionSymbol,
override var symbol: IrFunctionSymbol,
) : IrRawFunctionReference()
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.ir.types.IrType
class IrSetFieldImpl(
override val startOffset: Int,
override val endOffset: Int,
override val symbol: IrFieldSymbol,
override var symbol: IrFieldSymbol,
override var type: IrType,
override var origin: IrStatementOrigin? = null,
override var superQualifierSymbol: IrClassSymbol? = null,
@@ -26,7 +26,7 @@ class IrSetValueImpl(
override val startOffset: Int,
override val endOffset: Int,
override var type: IrType,
override val symbol: IrValueSymbol,
override var symbol: IrValueSymbol,
override var value: IrExpression,
override var origin: IrStatementOrigin?
) : IrSetValue() {
@@ -31,8 +31,9 @@ import org.jetbrains.kotlin.types.Variance
// 2) parents
// 3) fields
object IrTree : AbstractTreeBuilder() {
private fun symbol(type: TypeRef) = field("symbol", type, mutable = false)
private fun descriptor(typeName: String) =
private fun symbol(type: TypeRef, mutable: Boolean = false): SimpleFieldConfig =
field("symbol", type, mutable = mutable)
private fun descriptor(typeName: String): SimpleFieldConfig =
field("descriptor", ClassRef<TypeParameterRef>(TypeKind.Interface, "org.jetbrains.kotlin.descriptors", typeName), mutable = false)
private val factory: SimpleFieldConfig = field("factory", type(Packages.declarations, "IrFactory"), mutable = false)
@@ -716,7 +717,7 @@ object IrTree : AbstractTreeBuilder() {
parent(functionAccessExpression)
+symbol(constructorSymbolType)
+symbol(constructorSymbolType, mutable = true)
+field("source", type<SourceElement>())
+field("constructorTypeArgumentsCount", int)
}
@@ -731,14 +732,14 @@ object IrTree : AbstractTreeBuilder() {
parent(getSingletonValue)
+symbol(classSymbolType)
+symbol(classSymbolType, mutable = true)
}
val getEnumValue: ElementConfig by element(Expression) {
visitorParent = getSingletonValue
parent(getSingletonValue)
+symbol(enumEntrySymbolType)
+symbol(enumEntrySymbolType, mutable = true)
}
/**
@@ -752,7 +753,7 @@ object IrTree : AbstractTreeBuilder() {
parent(declarationReference)
+symbol(functionSymbolType)
+symbol(functionSymbolType, mutable = true)
}
val containerExpression: ElementConfig by element(Expression) {
visitorParent = expression
@@ -828,7 +829,7 @@ object IrTree : AbstractTreeBuilder() {
parent(functionAccessExpression)
+symbol(simpleFunctionSymbolType)
+symbol(simpleFunctionSymbolType, mutable = true)
+field("superQualifierSymbol", classSymbolType, nullable = true)
}
val callableReference: ElementConfig by element(Expression) {
@@ -836,6 +837,8 @@ object IrTree : AbstractTreeBuilder() {
val s = +param("S", symbolType)
parent(memberAccessExpression.withArgs("S" to s))
+symbol(s, mutable = true)
}
val functionReference: ElementConfig by element(Expression) {
visitorParent = callableReference
@@ -867,7 +870,7 @@ object IrTree : AbstractTreeBuilder() {
parent(declarationReference)
+symbol(classifierSymbolType)
+symbol(classifierSymbolType, mutable = true)
+field("classType", irTypeType)
}
val const: ElementConfig by element(Expression) {
@@ -929,7 +932,7 @@ object IrTree : AbstractTreeBuilder() {
parent(functionAccessExpression)
+symbol(constructorSymbolType)
+symbol(constructorSymbolType, mutable = true)
}
val dynamicExpression: ElementConfig by element(Expression) {
visitorParent = expression
@@ -958,7 +961,7 @@ object IrTree : AbstractTreeBuilder() {
parent(functionAccessExpression)
+symbol(constructorSymbolType)
+symbol(constructorSymbolType, mutable = true)
}
val errorExpression: ElementConfig by element(Expression) {
visitorParent = expression
@@ -983,7 +986,7 @@ object IrTree : AbstractTreeBuilder() {
parent(declarationReference)
+symbol(fieldSymbolType)
+symbol(fieldSymbolType, mutable = true)
+field("superQualifierSymbol", classSymbolType, nullable = true)
+field("receiver", expression, nullable = true, isChild = true) {
baseDefaultValue = code("null")
@@ -1128,7 +1131,7 @@ object IrTree : AbstractTreeBuilder() {
parent(declarationReference)
+symbol(valueSymbolType)
+symbol(valueSymbolType, mutable = true)
+field("origin", statementOriginType, nullable = true)
}
val getValue: ElementConfig by element(Expression) {