[IR] Pass null instead of IrUninitializedType to IrFactory

#KT-66053 In progress
This commit is contained in:
Wojciech Litewka
2024-03-05 12:36:53 +01:00
committed by Space Team
parent 1a4eaf796d
commit d1e8016ab2
16 changed files with 54 additions and 55 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.ir.util.DeepCopyIrTreeWithSymbols
import org.jetbrains.kotlin.ir.util.DeepCopySymbolRemapper
import org.jetbrains.kotlin.ir.util.SimpleTypeRemapper
@@ -96,7 +95,7 @@ class SyntheticAccessorLowering(private val context: CommonBackendContext) : Bod
visibility = DescriptorVisibilities.INTERNAL,
isInline = declaration.isInline,
isExpect = declaration.isExpect,
returnType = IrUninitializedType,
returnType = null,
modality = declaration.modality,
symbol = symbolRemapper.getDeclaredFunction(declaration.symbol),
isTailrec = declaration.isTailrec,
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.ir.util.declareSimpleFunctionWithOverrides
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
@@ -297,7 +296,7 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D
visibility = visibility,
isInline = isInline,
isExpect = isExpect,
returnType = IrUninitializedType,
returnType = null,
symbol = it,
isPrimary = isPrimary,
isExternal = isEffectivelyExternal(),
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.ir.util.createIrClassFromDescriptor
import org.jetbrains.kotlin.ir.util.withScope
import org.jetbrains.kotlin.psi.KtParameter
@@ -181,7 +180,7 @@ internal class StandaloneDeclarationGenerator(private val context: GeneratorCont
visibility = visibility,
isInline = isInline,
isExpect = isExpect,
returnType = IrUninitializedType,
returnType = null,
symbol = symbol,
isPrimary = isPrimary,
isExternal = isEffectivelyExternal(),
@@ -216,7 +215,7 @@ internal class StandaloneDeclarationGenerator(private val context: GeneratorCont
visibility = visibility,
isInline = isInline,
isExpect = isExpect,
returnType = IrUninitializedType,
returnType = null,
modality = modality,
symbol = symbol,
isTailrec = isTailrec,
@@ -57,7 +57,7 @@ interface IrFactory {
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
symbol: IrConstructorSymbol,
isPrimary: Boolean,
isExternal: Boolean = false,
@@ -99,7 +99,7 @@ interface IrFactory {
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
modality: Modality,
isTailrec: Boolean,
isSuspend: Boolean,
@@ -161,7 +161,7 @@ interface IrFactory {
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
modality: Modality,
symbol: IrSimpleFunctionSymbol,
isTailrec: Boolean,
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
class IrFunctionBuilder : IrDeclarationBuilder() {
@@ -18,7 +17,7 @@ class IrFunctionBuilder : IrDeclarationBuilder() {
var isInline: Boolean = false
var isExternal: Boolean = false
var returnType: IrType = IrUninitializedType
var returnType: IrType? = null
var modality: Modality = Modality.FINAL
var isTailrec: Boolean = false
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
import org.jetbrains.kotlin.types.Variance
@@ -94,7 +93,7 @@ abstract class AbstractIrFactoryImpl : IrFactory {
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
symbol: IrConstructorSymbol,
isPrimary: Boolean,
isExternal: Boolean,
@@ -114,7 +113,7 @@ abstract class AbstractIrFactoryImpl : IrFactory {
containerSource = containerSource,
factory = this
).apply {
if (returnType != IrUninitializedType) {
if (returnType != null) {
this.returnType = returnType
}
}
@@ -184,7 +183,7 @@ abstract class AbstractIrFactoryImpl : IrFactory {
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
modality: Modality,
symbol: IrSimpleFunctionSymbol,
isTailrec: Boolean,
@@ -214,7 +213,7 @@ abstract class AbstractIrFactoryImpl : IrFactory {
containerSource = containerSource,
factory = this
).apply {
if (returnType != IrUninitializedType) {
if (returnType != null) {
this.returnType = returnType
}
}
@@ -227,7 +226,7 @@ abstract class AbstractIrFactoryImpl : IrFactory {
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
modality: Modality,
isTailrec: Boolean,
isSuspend: Boolean,
@@ -253,7 +252,7 @@ abstract class AbstractIrFactoryImpl : IrFactory {
isFakeOverride = isFakeOverride,
factory = this
).apply {
if (returnType != IrUninitializedType) {
if (returnType != null) {
this.returnType = returnType
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -94,11 +94,11 @@ class IrFactoryImplForJsIC(override val stageController: StageController) : Abst
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
symbol: IrConstructorSymbol,
isPrimary: Boolean,
isExternal: Boolean,
containerSource: DeserializedContainerSource?
containerSource: DeserializedContainerSource?,
): IrConstructor {
return super.createConstructor(
startOffset,
@@ -170,7 +170,7 @@ class IrFactoryImplForJsIC(override val stageController: StageController) : Abst
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
modality: Modality,
symbol: IrSimpleFunctionSymbol,
isTailrec: Boolean,
@@ -179,7 +179,7 @@ class IrFactoryImplForJsIC(override val stageController: StageController) : Abst
isInfix: Boolean,
isExternal: Boolean,
containerSource: DeserializedContainerSource?,
isFakeOverride: Boolean
isFakeOverride: Boolean,
): IrSimpleFunction {
return super.createSimpleFunction(
startOffset,
@@ -210,7 +210,7 @@ class IrFactoryImplForJsIC(override val stageController: StageController) : Abst
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
modality: Modality,
isTailrec: Boolean,
isSuspend: Boolean,
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -69,11 +69,11 @@ class LazyIrFactory(
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
symbol: IrConstructorSymbol,
isPrimary: Boolean,
isExternal: Boolean,
containerSource: DeserializedContainerSource?
containerSource: DeserializedContainerSource?,
): IrConstructor = if (symbol.isBound)
symbol.owner
else
@@ -127,7 +127,7 @@ class LazyIrFactory(
visibility: DescriptorVisibility,
isInline: Boolean,
isExpect: Boolean,
returnType: IrType,
returnType: IrType?,
modality: Modality,
symbol: IrSimpleFunctionSymbol,
isTailrec: Boolean,
@@ -136,7 +136,7 @@ class LazyIrFactory(
isInfix: Boolean,
isExternal: Boolean,
containerSource: DeserializedContainerSource?,
isFakeOverride: Boolean
isFakeOverride: Boolean,
): IrSimpleFunction = if (symbol.isBound)
symbol.owner
else
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
import org.jetbrains.kotlin.utils.memoryOptimizedMap
@@ -33,7 +32,7 @@ fun SymbolTable.declareSimpleFunctionWithOverrides(
visibility = visibility,
isInline = isInline,
isExpect = isExpect,
returnType = IrUninitializedType,
returnType = null,
modality = modality,
symbol = it,
isTailrec = isTailrec,
@@ -405,7 +405,9 @@ object IrTree : AbstractTreeBuilder() {
// NB: there's an inline constructor for Array and each primitive array class.
+field("isInline", boolean)
+field("isExpect", boolean)
+field("returnType", irTypeType)
+field("returnType", irTypeType) {
useFieldInIrFactory(customType = irTypeType.copy(nullable = true))
}
+field("dispatchReceiverParameter", valueParameter, nullable = true)
+field("extensionReceiverParameter", valueParameter, nullable = true)
+listField("valueParameters", valueParameter, mutability = Var)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -25,8 +25,8 @@ abstract class AbstractTreeBuilder {
customUseInIrFactoryStrategy = Field.UseFieldAsParameterInIrFactoryStrategy.No
}
protected fun Field.useFieldInIrFactory(defaultValue: String? = null) {
customUseInIrFactoryStrategy = Field.UseFieldAsParameterInIrFactoryStrategy.Yes(defaultValue)
protected fun Field.useFieldInIrFactory(customType: TypeRef? = null, defaultValue: String? = null) {
customUseInIrFactoryStrategy = Field.UseFieldAsParameterInIrFactoryStrategy.Yes(customType, defaultValue)
}
fun element(category: Element.Category, name: String? = null, initializer: Element.() -> Unit = {}): ElementDelegate {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -16,7 +16,7 @@ sealed class Field(
data object No : UseFieldAsParameterInIrFactoryStrategy()
data class Yes(val defaultValue: String?) : UseFieldAsParameterInIrFactoryStrategy()
data class Yes(val customType: TypeRef?, val defaultValue: String?) : UseFieldAsParameterInIrFactoryStrategy()
}
var customUseInIrFactoryStrategy: UseFieldAsParameterInIrFactoryStrategy? = null
@@ -26,7 +26,7 @@ sealed class Field(
?: if (isChild && containsElement) {
UseFieldAsParameterInIrFactoryStrategy.No
} else {
UseFieldAsParameterInIrFactoryStrategy.Yes(null)
UseFieldAsParameterInIrFactoryStrategy.Yes(null, null)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -50,7 +50,7 @@ private class FactoryMethod(val element: Element) {
.filterNot { it.name in element.fieldsToSkipInIrFactoryMethod }
.mapNotNull { field ->
(field.useInIrFactoryStrategy as? Field.UseFieldAsParameterInIrFactoryStrategy.Yes)?.let {
FunctionParameter(field.name, field.typeRef, it.defaultValue)
FunctionParameter(field.name, it.customType ?: field.typeRef, it.defaultValue)
}
}
.sortedBy { it.defaultValue != null } // All parameters with default values must go last
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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.
*/
@@ -611,7 +611,7 @@ class IrDeclarationDeserializer(
visibility = flags.visibility,
isInline = flags.isInline,
isExpect = flags.isExpect,
returnType = IrUninitializedType,
returnType = null,
modality = flags.modality,
symbol = it,
isTailrec = flags.isTailrec,
@@ -685,7 +685,7 @@ class IrDeclarationDeserializer(
visibility = flags.visibility,
isInline = flags.isInline,
isExpect = flags.isExpect,
returnType = IrUninitializedType,
returnType = null,
symbol = it,
isPrimary = flags.isPrimary,
isExternal = flags.isExternal || isEffectivelyExternal,
@@ -1,3 +1,8 @@
/*
* 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.backend.konan.cgen
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
@@ -19,7 +24,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrTryImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.simpleFunctions
import org.jetbrains.kotlin.konan.ForeignExceptionMode
@@ -123,7 +127,7 @@ private fun createKotlinBridge(
DescriptorVisibilities.PRIVATE,
isInline = false,
isExpect = false,
IrUninitializedType,
null,
Modality.FINAL,
IrSimpleFunctionSymbolImpl(),
isTailrec = false,
@@ -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 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.backend.konan.ir.interop
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.resolve.descriptorUtil.*
import org.jetbrains.kotlin.types.KotlinType
@@ -95,7 +94,7 @@ internal interface DescriptorToIrTranslationMixin {
visibility,
isInline,
isExpect,
IrUninitializedType,
null,
it,
isPrimary,
isEffectivelyExternal(),