From 1c17219a7b0d9d6428b9297d2c53fe6820bbea01 Mon Sep 17 00:00:00 2001 From: Wojciech Litewka Date: Mon, 4 Mar 2024 12:00:47 +0100 Subject: [PATCH] [IR] Mark IrConstructorCall as AnnotationMarker IrConstructorCall is already used to represent both regular constructor call and annotations. Implementing AnnotationMarker avoids 'casting' it to this type later on in IrTypeSystemContext, which was done with a new IrElement implementation. We'd like to avoid such implementations, e.g. as so to make the IR hierarchy sealed. #KT-65773 In Progress --- .../jetbrains/kotlin/ir/expressions/IrConstructorCall.kt | 3 ++- .../org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt | 7 +++---- .../src/org/jetbrains/kotlin/ir/generator/IrTree.kt | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/expressions/IrConstructorCall.kt b/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/expressions/IrConstructorCall.kt index 31c0728b093..e9bc9daace0 100644 --- a/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/expressions/IrConstructorCall.kt +++ b/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/expressions/IrConstructorCall.kt @@ -11,11 +11,12 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor +import org.jetbrains.kotlin.types.model.AnnotationMarker /** * Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.constructorCall] */ -abstract class IrConstructorCall : IrFunctionAccessExpression() { +abstract class IrConstructorCall : IrFunctionAccessExpression(), AnnotationMarker { abstract override var symbol: IrConstructorSymbol abstract var source: SourceElement diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt index a0182e0d04d..0f54841b368 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSystemContext.kt @@ -1,6 +1,6 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. + * Copyright 2010-2024 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.ir.types @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.IrBuiltIns -import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrConst import org.jetbrains.kotlin.ir.expressions.IrConstructorCall @@ -411,7 +410,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon override fun KotlinTypeMarker.getAttributes(): List { require(this is IrType) - return this.annotations.memoryOptimizedMap { object : AnnotationMarker, IrElement by it {} } + return this.annotations } override fun KotlinTypeMarker.hasCustomAttributes(): Boolean { diff --git a/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/IrTree.kt b/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/IrTree.kt index 74191bb1816..159c56222ac 100644 --- a/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/IrTree.kt +++ b/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/IrTree.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource import org.jetbrains.kotlin.types.Variance +import org.jetbrains.kotlin.types.model.AnnotationMarker import org.jetbrains.kotlin.utils.withIndent // Note the style of the DSL to describe IR elements, which is these things in the following order: @@ -800,6 +801,7 @@ object IrTree : AbstractTreeBuilder() { transformerReturnType = rootElement parent(functionAccessExpression) + parent(type()) +symbol(constructorSymbolType, mutable = true) +field("source", type()) {