From d33debdf7cb4b93001f49252d11ddcf80da4be5f Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 9 Jul 2021 18:42:53 +0200 Subject: [PATCH] IR: minor, cleanup Symbols --- .../jetbrains/kotlin/backend/common/ir/Ir.kt | 3 - .../ir/backend/js/JsIrBackendContext.kt | 5 +- .../kotlin/backend/jvm/JvmSymbols.kt | 84 ++++++++----------- .../kotlin/backend/wasm/WasmSymbols.kt | 3 - .../jetbrains/kotlin/backend/konan/ir/Ir.kt | 12 +-- 5 files changed, 44 insertions(+), 63 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt index a8e969ad58c..3a84025eb40 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt @@ -301,7 +301,6 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va abstract class Symbols(val context: T, irBuiltIns: IrBuiltIns, symbolTable: SymbolTable) : BuiltinSymbolsBase(irBuiltIns, context.builtIns, symbolTable) { abstract val throwNullPointerException: IrSimpleFunctionSymbol - abstract val throwNoWhenBranchMatchedException: IrSimpleFunctionSymbol abstract val throwTypeCastException: IrSimpleFunctionSymbol abstract val throwUninitializedPropertyAccessException: IrSimpleFunctionSymbol @@ -315,8 +314,6 @@ abstract class Symbols(val context: T, irBuiltIns: abstract val defaultConstructorMarker: IrClassSymbol - abstract val copyRangeTo: Map - abstract val coroutineImpl: IrClassSymbol abstract val coroutineSuspendedGetter: IrSimpleFunctionSymbol diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index 29c22c636ad..82f63870733 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -204,8 +204,9 @@ class JsIrBackendContext( override val throwNullPointerException = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single()) - override val throwNoWhenBranchMatchedException = + init { symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("noWhenBranchMatchedException"))).single()) + } override val throwTypeCastException = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).single()) @@ -224,8 +225,6 @@ class JsIrBackendContext( override val stringBuilder get() = TODO("not implemented") - override val copyRangeTo: Map - get() = TODO("not implemented") override val coroutineImpl = symbolTable.referenceClass(findClass(coroutinePackage.memberScope, COROUTINE_IMPL_NAME)) override val coroutineSuspendedGetter = diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt index b17cf1b58ca..6f72debb4e2 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt @@ -15,7 +15,11 @@ import org.jetbrains.kotlin.codegen.coroutines.INVOKE_SUSPEND_METHOD_NAME import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_CALL_RESULT_NAME import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_FUNCTION_COMPLETION_PARAMETER_NAME import org.jetbrains.kotlin.codegen.coroutines.SUSPEND_FUNCTION_CREATE_METHOD_NAME -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.ClassKind +import org.jetbrains.kotlin.descriptors.DescriptorVisibilities +import org.jetbrains.kotlin.descriptors.InlineClassRepresentation +import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.declarations.* import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin @@ -23,6 +27,8 @@ import org.jetbrains.kotlin.ir.declarations.IrPackageFragment import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns +import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.* @@ -151,9 +157,6 @@ class JvmSymbols( override val throwNullPointerException: IrSimpleFunctionSymbol = intrinsicsClass.functions.single { it.owner.name.asString() == "throwNullPointerException" } - override val throwNoWhenBranchMatchedException: IrSimpleFunctionSymbol - get() = error("Unused in JVM IR") - override val throwTypeCastException: IrSimpleFunctionSymbol = intrinsicsClass.functions.single { it.owner.name.asString() == "throwTypeCastException" } @@ -175,7 +178,7 @@ class JvmSymbols( override val stringBuilder: IrClassSymbol = createClass(FqName("java.lang.StringBuilder")) { klass -> klass.addConstructor() klass.addFunction("toString", irBuiltIns.stringType).apply { - overriddenSymbols += any.functionByName("toString") + overriddenSymbols = overriddenSymbols + any.functionByName("toString") } val appendTypes = with(irBuiltIns) { listOf(anyNType, stringType, booleanType, charType, intType, longType, floatType, doubleType) } @@ -189,29 +192,26 @@ class JvmSymbols( override val defaultConstructorMarker: IrClassSymbol = createClass(FqName("kotlin.jvm.internal.DefaultConstructorMarker")) - override val copyRangeTo: Map - get() = error("Unused in JVM IR") - override val coroutineImpl: IrClassSymbol - get() = TODO("not implemented") + get() = error("not implemented") override val coroutineSuspendedGetter: IrSimpleFunctionSymbol - get() = TODO("not implemented") + get() = error("not implemented") override val getContinuation: IrSimpleFunctionSymbol - get() = TODO("not implemented") + get() = error("not implemented") override val coroutineContextGetter: IrSimpleFunctionSymbol - get() = TODO("not implemented") + get() = error("not implemented") override val suspendCoroutineUninterceptedOrReturn: IrSimpleFunctionSymbol - get() = TODO("not implemented") + get() = error("not implemented") override val coroutineGetContext: IrSimpleFunctionSymbol - get() = TODO("not implemented") + get() = error("not implemented") override val returnIfSuspended: IrSimpleFunctionSymbol - get() = TODO("not implemented") + get() = error("not implemented") private val kDeclarationContainer: IrClassSymbol = createClass(StandardNames.FqNames.kDeclarationContainer.toSafe(), ClassKind.INTERFACE, Modality.ABSTRACT) @@ -776,52 +776,38 @@ class JvmSymbols( throw AssertionError("Array type expected: ${arrayType.render()}") } - private val javaLangInteger: IrClassSymbol = createClass(FqName("java.lang.Integer")) { klass -> - klass.addFunction("compareUnsigned", irBuiltIns.intType, isStatic = true).apply { - addValueParameter("x", irBuiltIns.intType) - addValueParameter("y", irBuiltIns.intType) - } - klass.addFunction("divideUnsigned", irBuiltIns.intType, isStatic = true).apply { - addValueParameter("dividend", irBuiltIns.intType) - addValueParameter("divisor", irBuiltIns.intType) - } - klass.addFunction("remainderUnsigned", irBuiltIns.intType, isStatic = true).apply { - addValueParameter("dividend", irBuiltIns.intType) - addValueParameter("divisor", irBuiltIns.intType) - } - klass.addFunction("toUnsignedString", irBuiltIns.stringType, isStatic = true).apply { - addValueParameter("i", irBuiltIns.intType) - } - } + private val javaLangInteger: IrClassSymbol = createJavaPrimitiveClass(FqName("java.lang.Integer"), irBuiltIns.intType) val compareUnsignedInt: IrSimpleFunctionSymbol = javaLangInteger.functionByName("compareUnsigned") val divideUnsignedInt: IrSimpleFunctionSymbol = javaLangInteger.functionByName("divideUnsigned") val remainderUnsignedInt: IrSimpleFunctionSymbol = javaLangInteger.functionByName("remainderUnsigned") val toUnsignedStringInt: IrSimpleFunctionSymbol = javaLangInteger.functionByName("toUnsignedString") - private val javaLangLong: IrClassSymbol = createClass(FqName("java.lang.Long")) { klass -> - klass.addFunction("compareUnsigned", irBuiltIns.intType, isStatic = true).apply { - addValueParameter("x", irBuiltIns.longType) - addValueParameter("y", irBuiltIns.longType) - } - klass.addFunction("divideUnsigned", irBuiltIns.longType, isStatic = true).apply { - addValueParameter("dividend", irBuiltIns.longType) - addValueParameter("divisor", irBuiltIns.longType) - } - klass.addFunction("remainderUnsigned", irBuiltIns.longType, isStatic = true).apply { - addValueParameter("dividend", irBuiltIns.longType) - addValueParameter("divisor", irBuiltIns.longType) - } - klass.addFunction("toUnsignedString", irBuiltIns.stringType, isStatic = true).apply { - addValueParameter("i", irBuiltIns.longType) - } - } + private val javaLangLong: IrClassSymbol = createJavaPrimitiveClass(FqName("java.lang.Long"), irBuiltIns.longType) val compareUnsignedLong: IrSimpleFunctionSymbol = javaLangLong.functionByName("compareUnsigned") val divideUnsignedLong: IrSimpleFunctionSymbol = javaLangLong.functionByName("divideUnsigned") val remainderUnsignedLong: IrSimpleFunctionSymbol = javaLangLong.functionByName("remainderUnsigned") val toUnsignedStringLong: IrSimpleFunctionSymbol = javaLangLong.functionByName("toUnsignedString") + private fun createJavaPrimitiveClass(fqName: FqName, type: IrType): IrClassSymbol = createClass(fqName) { klass -> + klass.addFunction("compareUnsigned", irBuiltIns.intType, isStatic = true).apply { + addValueParameter("x", type) + addValueParameter("y", type) + } + klass.addFunction("divideUnsigned", type, isStatic = true).apply { + addValueParameter("dividend", type) + addValueParameter("divisor", type) + } + klass.addFunction("remainderUnsigned", type, isStatic = true).apply { + addValueParameter("dividend", type) + addValueParameter("divisor", type) + } + klass.addFunction("toUnsignedString", irBuiltIns.stringType, isStatic = true).apply { + addValueParameter("i", type) + } + } + val signatureStringIntrinsic: IrSimpleFunctionSymbol = irFactory.buildFun { name = Name.special("") diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt index 1c4fc2c148e..6babdd6b487 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt @@ -35,7 +35,6 @@ class WasmSymbols( override val throwNullPointerException = getInternalFunction("THROW_NPE") override val throwISE = getInternalFunction("THROW_ISE") - override val throwNoWhenBranchMatchedException = throwISE override val throwTypeCastException = getInternalFunction("THROW_CCE") override val throwUninitializedPropertyAccessException = getInternalFunction("throwUninitializedPropertyAccessException") @@ -45,8 +44,6 @@ class WasmSymbols( get() = TODO() override val stringBuilder get() = TODO() - override val copyRangeTo: Map - get() = TODO() override val coroutineImpl get() = TODO() override val coroutineSuspendedGetter diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index c1978409157..b4147a5ea97 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -13,13 +13,13 @@ import org.jetbrains.kotlin.backend.konan.descriptors.enumEntries import org.jetbrains.kotlin.backend.konan.descriptors.kotlinNativeInternal import org.jetbrains.kotlin.backend.konan.llvm.findMainEntryPoint import org.jetbrains.kotlin.backend.konan.lower.TestProcessor -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.UnsignedType import org.jetbrains.kotlin.config.coroutinesIntrinsicsPackageFqName import org.jetbrains.kotlin.config.coroutinesPackageFqName import org.jetbrains.kotlin.config.languageVersionSettings -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns @@ -29,7 +29,10 @@ import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.typeWith -import org.jetbrains.kotlin.ir.util.* +import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable +import org.jetbrains.kotlin.ir.util.SymbolTable +import org.jetbrains.kotlin.ir.util.constructors +import org.jetbrains.kotlin.ir.util.referenceFunction import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -277,7 +280,7 @@ internal class KonanSymbols( override val throwNullPointerException = internalFunction("ThrowNullPointerException") - override val throwNoWhenBranchMatchedException = internalFunction("ThrowNoWhenBranchMatchedException") + val throwNoWhenBranchMatchedException = internalFunction("ThrowNoWhenBranchMatchedException") override val throwTypeCastException = internalFunction("ThrowTypeCastException") @@ -332,7 +335,6 @@ internal class KonanSymbols( } ?: error(descriptor.toString()) return symbolTable.referenceSimpleFunction(functionDescriptor) } - override val copyRangeTo get() = TODO() fun getNoParamFunction(name: Name, receiverType: KotlinType): IrFunctionSymbol { val descriptor = receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)