From 6c211f3a39815a3e5410c29a13ebece1bc903f4f Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Fri, 5 May 2023 13:45:40 +0200 Subject: [PATCH] [IR] Make IrFunctionSymbol a sealed interface --- .../kotlin/fir/backend/generators/AdapterGenerator.kt | 2 -- .../kotlin/backend/common/lower/InnerClassesLowering.kt | 8 ++++---- .../kotlin/backend/jvm/CachedSyntheticDeclarations.kt | 1 - .../psi2ir/generators/ReflectionReferencesGenerator.kt | 1 - .../org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt | 1 - .../src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt | 2 +- .../jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt | 1 - .../linkage/partial/PartiallyLinkedIrTreePatcher.kt | 1 - .../backend/konan/lower/ExpectDeclarationsRemoving.kt | 1 - 9 files changed, 5 insertions(+), 13 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt index 652627519e6..59ed5944ab7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt @@ -308,8 +308,6 @@ internal class AdapterGenerator( origin = null, superQualifierSymbol = null ) - else -> - error("unknown callee kind: ${adapteeFunction.render()}") } var adapterParameterIndex = 0 diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt index 35951b79095..e461ccb360e 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol import org.jetbrains.kotlin.ir.symbols.IrValueSymbol import org.jetbrains.kotlin.ir.types.classOrNull @@ -261,10 +262,9 @@ class InnerClassConstructorCallsLowering(val context: BackendContext, val innerC val newCallee = innerClassesSupport.getInnerClassConstructorWithOuterThisParameter(callee.owner) val newReflectionTarget = expression.reflectionTarget?.let { reflectionTarget -> - if (reflectionTarget is IrConstructorSymbol) { - innerClassesSupport.getInnerClassConstructorWithOuterThisParameter(reflectionTarget.owner) - } else { - null + when (reflectionTarget) { + is IrConstructorSymbol -> innerClassesSupport.getInnerClassConstructorWithOuterThisParameter(reflectionTarget.owner) + is IrSimpleFunctionSymbol -> null } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/CachedSyntheticDeclarations.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/CachedSyntheticDeclarations.kt index e9e70a5fa40..334464fd8c6 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/CachedSyntheticDeclarations.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/CachedSyntheticDeclarations.kt @@ -115,7 +115,6 @@ class CachedSyntheticDeclarations(private val context: JvmBackendContext) { symbol.owner.makeConstructorAccessor().symbol is IrSimpleFunctionSymbol -> symbol.owner.makeSimpleFunctionAccessor(superQualifierSymbol, dispatchReceiverType, parent, scopes).symbol - else -> error("Unknown subclass of IrFunctionSymbol") } } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt index b91c0e78048..bbc339aa0e6 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt @@ -313,7 +313,6 @@ internal class ReflectionReferencesGenerator(statementGenerator: StatementGenera IrConstructorCallImpl.fromSymbolDescriptor(startOffset, endOffset, irType, adapteeSymbol) is IrSimpleFunctionSymbol -> IrCallImpl.fromSymbolDescriptor(startOffset, endOffset, irType, adapteeSymbol) - else -> error("Unknown symbol kind $adapteeSymbol") } val hasBoundDispatchReceiver = resolvedCall.dispatchReceiver != null && resolvedCall.dispatchReceiver !is TransientReceiver diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt index 39febc3f5ae..106c55eb052 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt @@ -272,7 +272,6 @@ fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol, type: IrType): IrFunctio when (callee) { is IrConstructorSymbol -> irCall(callee, type) is IrSimpleFunctionSymbol -> irCall(callee, type) - else -> throw AssertionError("Unexpected callee: $callee") } fun IrBuilderWithScope.irCall(callee: IrSimpleFunctionSymbol): IrCall = diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt index 92db12a884d..e563e2527bb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt @@ -98,7 +98,7 @@ interface IrReturnTargetSymbol : IrSymbol { override val owner: IrReturnTarget } -interface IrFunctionSymbol : IrReturnTargetSymbol { +sealed interface IrFunctionSymbol : IrReturnTargetSymbol { override val owner: IrFunction } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt index 0735a60b2b9..9a2b7a96eb2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolRemapper.kt @@ -219,7 +219,6 @@ open class DeepCopySymbolRemapper( when (symbol) { is IrSimpleFunctionSymbol -> functions.getReferenced(symbol) is IrConstructorSymbol -> constructors.getReferenced(symbol) - else -> throw IllegalArgumentException("Unexpected symbol $symbol") } override fun getReferencedReturnableBlock(symbol: IrReturnableBlockSymbol): IrReturnableBlockSymbol = diff --git a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartiallyLinkedIrTreePatcher.kt b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartiallyLinkedIrTreePatcher.kt index aa06bc1025d..4c8c70de332 100644 --- a/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartiallyLinkedIrTreePatcher.kt +++ b/compiler/ir/serialization.common/src/org/jetbrains/kotlin/backend/common/linkage/partial/PartiallyLinkedIrTreePatcher.kt @@ -708,7 +708,6 @@ internal class PartiallyLinkedIrTreePatcher( val expectedDispatchReceiverClassifier: IrClassSymbol = when (symbol) { is IrSimpleFunctionSymbol -> function.parent as? IrClass is IrConstructorSymbol -> (function.parent as? IrClass)?.takeIf { it.isInner }?.parent as? IrClass - else -> null }?.symbol ?: return@run false val referenceType: IrSimpleType = type as? IrSimpleType ?: return@run false diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt index 67c5e397b42..e11e36e55ec 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ExpectDeclarationsRemoving.kt @@ -130,7 +130,6 @@ internal class ExpectToActualDefaultValueCopier(private val irModule: IrModuleFr override fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol = when (symbol) { is IrSimpleFunctionSymbol -> getReferencedSimpleFunction(symbol) is IrConstructorSymbol -> getReferencedConstructor(symbol) - else -> error("Unexpected symbol $symbol ${symbol.descriptor}") } override fun getReferencedSimpleFunction(symbol: IrSimpleFunctionSymbol) = when {