From d97681f2a906543376df79dda4fdfea433ef3380 Mon Sep 17 00:00:00 2001 From: Wojciech Litewka Date: Fri, 16 Feb 2024 12:42:01 +0100 Subject: [PATCH] [IR] Autogenerate IrFunctionWithLateBindingImpl ^KT-65773 In Progress --- .../impl/IrFunctionWithLateBindingImpl.kt | 93 ++++++++++--------- .../generator/ImplementationConfigurator.kt | 56 ++++++++++- 2 files changed, 105 insertions(+), 44 deletions(-) diff --git a/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionWithLateBindingImpl.kt b/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionWithLateBindingImpl.kt index 4918e92f23c..8ce5e0b19a9 100644 --- a/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionWithLateBindingImpl.kt +++ b/compiler/ir/ir.tree/gen/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionWithLateBindingImpl.kt @@ -3,9 +3,15 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ +// This file was generated automatically. See compiler/ir/ir.tree/tree-generator/ReadMe.md. +// DO NOT MODIFY IT MANUALLY. + +@file:Suppress("DuplicatedCode", "unused") + package org.jetbrains.kotlin.ir.declarations.impl import org.jetbrains.kotlin.descriptors.DescriptorVisibility +import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.IrImplementationDetail import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI @@ -23,28 +29,61 @@ class IrFunctionWithLateBindingImpl @IrImplementationDetail constructor( override val startOffset: Int, override val endOffset: Int, override var origin: IrDeclarationOrigin, + override val factory: IrFactory, override var name: Name, - override var visibility: DescriptorVisibility, - override var modality: Modality, - override var isInline: Boolean, override var isExternal: Boolean, + override var visibility: DescriptorVisibility, + override var isInline: Boolean, + override var isExpect: Boolean, + override var modality: Modality, override var isTailrec: Boolean, override var isSuspend: Boolean, + override var isFakeOverride: Boolean, override var isOperator: Boolean, override var isInfix: Boolean, - override var isExpect: Boolean, - override var isFakeOverride: Boolean, - override val factory: IrFactory ) : IrFunctionWithLateBinding() { + override var annotations: List = emptyList() - private var _symbol: IrSimpleFunctionSymbol? = null + override lateinit var parent: IrDeclarationParent + + override var typeParameters: List = emptyList() + + override val containerSource: DeserializedContainerSource? + get() = null + + override var metadata: MetadataSource? = null + + @ObsoleteDescriptorBasedAPI + override val descriptor: FunctionDescriptor + get() = symbol.descriptor + + override lateinit var returnType: IrType + + override var dispatchReceiverParameter: IrValueParameter? = null + + override var extensionReceiverParameter: IrValueParameter? = null + + override var valueParameters: List = emptyList() + + override var contextReceiverParametersCount: Int = 0 + + override var body: IrBody? = null + + override var attributeOwnerId: IrAttributeContainer = this + + override var originalBeforeInline: IrAttributeContainer? = null override val symbol: IrSimpleFunctionSymbol get() = _symbol ?: error("$this has not acquired a symbol yet") - @ObsoleteDescriptorBasedAPI - override val descriptor - get() = _symbol?.descriptor ?: this.toIrBasedDescriptor() + override var overriddenSymbols: List = emptyList() + + override var correspondingPropertySymbol: IrPropertySymbol? = null + + override val isBound: Boolean + get() = _symbol != null + + private var _symbol: IrSimpleFunctionSymbol? = null override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrFunctionWithLateBinding { assert(_symbol == null) { "$this already has symbol _symbol" } @@ -52,36 +91,4 @@ class IrFunctionWithLateBindingImpl @IrImplementationDetail constructor( symbol.bind(this) return this } - - override val isBound: Boolean - get() = _symbol != null - - override val containerSource: DeserializedContainerSource? - get() = null - - override lateinit var parent: IrDeclarationParent - - override var annotations: List = emptyList() - - override var typeParameters: List = emptyList() - - override var dispatchReceiverParameter: IrValueParameter? = null - override var extensionReceiverParameter: IrValueParameter? = null - override var valueParameters: List = emptyList() - - override var contextReceiverParametersCount: Int = 0 - - override lateinit var returnType: IrType - - override var body: IrBody? = null - - override var metadata: MetadataSource? = null - - override var overriddenSymbols: List = emptyList() - - override var attributeOwnerId: IrAttributeContainer = this - - override var originalBeforeInline: IrAttributeContainer? = null - - override var correspondingPropertySymbol: IrPropertySymbol? = null -} \ No newline at end of file +} diff --git a/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/ImplementationConfigurator.kt b/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/ImplementationConfigurator.kt index f6f6627d407..9b1c8d55560 100644 --- a/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/ImplementationConfigurator.kt +++ b/compiler/ir/ir.tree/tree-generator/src/org/jetbrains/kotlin/ir/generator/ImplementationConfigurator.kt @@ -5,10 +5,20 @@ package org.jetbrains.kotlin.ir.generator +import org.jetbrains.kotlin.generators.tree.ArbitraryImportable +import org.jetbrains.kotlin.generators.tree.ClassRef +import org.jetbrains.kotlin.generators.tree.ImportCollector import org.jetbrains.kotlin.generators.tree.StandardTypes +import org.jetbrains.kotlin.generators.tree.Visibility +import org.jetbrains.kotlin.generators.tree.printer.FunctionParameter +import org.jetbrains.kotlin.generators.tree.printer.VariableKind +import org.jetbrains.kotlin.generators.tree.printer.printFunctionWithBlockBody +import org.jetbrains.kotlin.generators.tree.printer.printPropertyDeclaration import org.jetbrains.kotlin.ir.generator.config.AbstractIrTreeImplementationConfigurator import org.jetbrains.kotlin.ir.generator.model.Element +import org.jetbrains.kotlin.ir.generator.model.Implementation import org.jetbrains.kotlin.ir.generator.model.ListField +import org.jetbrains.kotlin.utils.SmartPrinter object ImplementationConfigurator : AbstractIrTreeImplementationConfigurator() { override fun configure(model: Model): Unit = with(IrTree) { @@ -23,7 +33,12 @@ object ImplementationConfigurator : AbstractIrTreeImplementationConfigurator() { isLateinit("returnType") } impl(functionWithLateBinding) { - implementation.doPrint = false + defaultEmptyList("valueParameters") + defaultNull("dispatchReceiverParameter", "extensionReceiverParameter", "body", "correspondingPropertySymbol") + default("contextReceiverParametersCount", "0") + isLateinit("returnType") + defaultNull("containerSource", withGetter = true) + configureDeclarationWithLateBindinig(simpleFunctionSymbolType) } impl(constructor) { @@ -90,6 +105,45 @@ object ImplementationConfigurator : AbstractIrTreeImplementationConfigurator() { } } + private fun ImplementationContext.configureDeclarationWithLateBindinig(symbolType: ClassRef<*>) { + default("isBound") { + value = "_symbol != null" + withGetter = true + } + default("symbol") { + value = "_symbol ?: error(\"\$this has not acquired a symbol yet\")" + withGetter = true + } + additionalImports(ArbitraryImportable("org.jetbrains.kotlin.ir.descriptors", "toIrBasedDescriptor")) + default("descriptor") { + value = "_symbol?.descriptor ?: this.toIrBasedDescriptor()" + withGetter = true + } + implementation.generationCallback = { + println() + printPropertyDeclaration( + "_symbol", + symbolType.copy(nullable = true), + VariableKind.VAR, + visibility = Visibility.PRIVATE, + initializer = "null" + ) + println() + println() + printFunctionWithBlockBody( + "acquireSymbol", + listOf(FunctionParameter("symbol", symbolType)), + implementation.element, + override = true, + ) { + println("assert(_symbol == null) { \"\$this already has symbol _symbol\" }") + println("_symbol = symbol") + println("symbol.bind(this)") + println("return this") + } + } + } + override fun configureAllImplementations(model: Model) { configureFieldInAllImplementations("parent") { isLateinit("parent")