IR: minor, cleanup Symbols

This commit is contained in:
Alexander Udalov
2021-07-09 18:42:53 +02:00
parent de22a467a1
commit d33debdf7c
5 changed files with 44 additions and 63 deletions
@@ -301,7 +301,6 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va
abstract class Symbols<out T : CommonBackendContext>(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<out T : CommonBackendContext>(val context: T, irBuiltIns:
abstract val defaultConstructorMarker: IrClassSymbol
abstract val copyRangeTo: Map<ClassDescriptor, IrSimpleFunctionSymbol>
abstract val coroutineImpl: IrClassSymbol
abstract val coroutineSuspendedGetter: IrSimpleFunctionSymbol
@@ -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<ClassDescriptor, IrSimpleFunctionSymbol>
get() = TODO("not implemented")
override val coroutineImpl =
symbolTable.referenceClass(findClass(coroutinePackage.memberScope, COROUTINE_IMPL_NAME))
override val coroutineSuspendedGetter =
@@ -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<ClassDescriptor, IrSimpleFunctionSymbol>
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("<signature-string>")
@@ -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<ClassDescriptor, IrSimpleFunctionSymbol>
get() = TODO()
override val coroutineImpl
get() = TODO()
override val coroutineSuspendedGetter
@@ -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)