[IR] Remove descriptor-related methods from SymbolTable
Replace them with calls to SymbolTableExtension
This commit is contained in:
committed by
Space Team
parent
b886b7488d
commit
8ad202eb8b
+4
-4
@@ -64,7 +64,7 @@ class JsCommonCoroutineSymbols(
|
||||
val coroutineIntrinsicsPackage = module.getPackage(COROUTINE_INTRINSICS_PACKAGE_FQNAME)
|
||||
|
||||
val coroutineImpl =
|
||||
symbolTable.referenceClass(findClass(coroutinePackage.memberScope, COROUTINE_IMPL_NAME))
|
||||
symbolTable.descriptorExtension.referenceClass(findClass(coroutinePackage.memberScope, COROUTINE_IMPL_NAME))
|
||||
|
||||
val coroutineImplLabelPropertyGetter by lazy(LazyThreadSafetyMode.NONE) { coroutineImpl.getPropertyGetter("state")!!.owner }
|
||||
val coroutineImplLabelPropertySetter by lazy(LazyThreadSafetyMode.NONE) { coroutineImpl.getPropertySetter("state")!!.owner }
|
||||
@@ -75,14 +75,14 @@ class JsCommonCoroutineSymbols(
|
||||
val coroutineImplExceptionStatePropertyGetter by lazy(LazyThreadSafetyMode.NONE) { coroutineImpl.getPropertyGetter("exceptionState")!!.owner }
|
||||
val coroutineImplExceptionStatePropertySetter by lazy(LazyThreadSafetyMode.NONE) { coroutineImpl.getPropertySetter("exceptionState")!!.owner }
|
||||
|
||||
val continuationClass = symbolTable.referenceClass(
|
||||
val continuationClass = symbolTable.descriptorExtension.referenceClass(
|
||||
coroutinePackage.memberScope.getContributedClassifier(
|
||||
CONTINUATION_NAME,
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
) as ClassDescriptor
|
||||
)
|
||||
|
||||
val coroutineSuspendedGetter = symbolTable.referenceSimpleFunction(
|
||||
val coroutineSuspendedGetter = symbolTable.descriptorExtension.referenceSimpleFunction(
|
||||
coroutineIntrinsicsPackage.memberScope.getContributedVariables(
|
||||
COROUTINE_SUSPENDED_NAME,
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
@@ -154,4 +154,4 @@ interface JsCommonInlineClassesUtils : InlineClassesUtils {
|
||||
* An intrinsic for obtaining the underlying value from an instance of an inline class.
|
||||
*/
|
||||
val unboxIntrinsic: IrSimpleFunctionSymbol
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,12 +204,12 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
val metadataObjectConstructorSymbol = getInternalFunction("objectMeta")
|
||||
val metadataClassConstructorSymbol = getInternalFunction("classMeta")
|
||||
|
||||
val longToDouble = context.symbolTable.referenceSimpleFunction(
|
||||
val longToDouble = context.symbolTable.descriptorExtension.referenceSimpleFunction(
|
||||
context.getClass(FqName("kotlin.Long")).unsubstitutedMemberScope.findSingleFunction(
|
||||
Name.identifier("toDouble")
|
||||
)
|
||||
)
|
||||
val longToFloat = context.symbolTable.referenceSimpleFunction(
|
||||
val longToFloat = context.symbolTable.descriptorExtension.referenceSimpleFunction(
|
||||
context.getClass(FqName("kotlin.Long")).unsubstitutedMemberScope.findSingleFunction(
|
||||
Name.identifier("toFloat")
|
||||
)
|
||||
@@ -323,12 +323,13 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
val jsBind = getInternalFunction("jsBind")
|
||||
|
||||
// TODO move to IntrinsifyCallsLowering
|
||||
val doNotIntrinsifyAnnotationSymbol = context.symbolTable.referenceClass(context.getJsInternalClass("DoNotIntrinsify"))
|
||||
val jsFunAnnotationSymbol = context.symbolTable.referenceClass(context.getJsInternalClass("JsFun"))
|
||||
val jsNameAnnotationSymbol = context.symbolTable.referenceClass(context.getJsInternalClass("JsName"))
|
||||
val doNotIntrinsifyAnnotationSymbol =
|
||||
context.symbolTable.descriptorExtension.referenceClass(context.getJsInternalClass("DoNotIntrinsify"))
|
||||
val jsFunAnnotationSymbol = context.symbolTable.descriptorExtension.referenceClass(context.getJsInternalClass("JsFun"))
|
||||
val jsNameAnnotationSymbol = context.symbolTable.descriptorExtension.referenceClass(context.getJsInternalClass("JsName"))
|
||||
|
||||
val jsExportAnnotationSymbol by lazy(LazyThreadSafetyMode.NONE) {
|
||||
context.symbolTable.referenceClass(context.getJsInternalClass("JsExport"))
|
||||
context.symbolTable.descriptorExtension.referenceClass(context.getJsInternalClass("JsExport"))
|
||||
}
|
||||
|
||||
val jsExportIgnoreAnnotationSymbol by lazy(LazyThreadSafetyMode.NONE) {
|
||||
@@ -337,10 +338,11 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
?.symbol ?: error("can't find kotlin.js.JsExport.Ignore annotation")
|
||||
}
|
||||
|
||||
val jsImplicitExportAnnotationSymbol = context.symbolTable.referenceClass(context.getJsInternalClass("JsImplicitExport"))
|
||||
val jsImplicitExportAnnotationSymbol =
|
||||
context.symbolTable.descriptorExtension.referenceClass(context.getJsInternalClass("JsImplicitExport"))
|
||||
|
||||
// TODO move CharSequence-related stiff to IntrinsifyCallsLowering
|
||||
val charSequenceClassSymbol = context.symbolTable.referenceClass(context.getClass(FqName("kotlin.CharSequence")))
|
||||
val charSequenceClassSymbol = context.symbolTable.descriptorExtension.referenceClass(context.getClass(FqName("kotlin.CharSequence")))
|
||||
val charSequenceLengthPropertyGetterSymbol by context.lazy2 {
|
||||
with(charSequenceClassSymbol.owner.declarations) {
|
||||
filterIsInstance<IrProperty>().firstOrNull { it.name.asString() == "length" }?.getter ?:
|
||||
@@ -381,22 +383,24 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
|
||||
// Helpers:
|
||||
|
||||
private fun getInternalFunction(name: String) =
|
||||
context.symbolTable.referenceSimpleFunction(context.getJsInternalFunction(name))
|
||||
context.symbolTable.descriptorExtension.referenceSimpleFunction(context.getJsInternalFunction(name))
|
||||
|
||||
private fun getInternalProperty(name: String) =
|
||||
context.symbolTable.referenceProperty(context.getJsInternalProperty(name))
|
||||
context.symbolTable.descriptorExtension.referenceProperty(context.getJsInternalProperty(name))
|
||||
|
||||
private fun getInternalWithoutPackage(name: String) =
|
||||
context.symbolTable.referenceSimpleFunction(context.getFunctions(FqName(name)).single())
|
||||
context.symbolTable.descriptorExtension.referenceSimpleFunction(context.getFunctions(FqName(name)).single())
|
||||
|
||||
private fun getInternalWithoutPackageOrNull(name: String): IrSimpleFunctionSymbol? {
|
||||
val descriptor = context.getFunctions(FqName(name)).singleOrNull() ?: return null
|
||||
return context.symbolTable.referenceSimpleFunction(descriptor)
|
||||
return context.symbolTable.descriptorExtension.referenceSimpleFunction(descriptor)
|
||||
}
|
||||
|
||||
private fun getFunctionInKotlinPackage(name: String) =
|
||||
context.symbolTable.referenceSimpleFunction(context.getFunctions(kotlinPackageFqn.child(Name.identifier(name))).single())
|
||||
context.symbolTable.descriptorExtension.referenceSimpleFunction(
|
||||
context.getFunctions(kotlinPackageFqn.child(Name.identifier(name))).single()
|
||||
)
|
||||
|
||||
private fun getInternalClassWithoutPackage(fqName: String) =
|
||||
context.symbolTable.referenceClass(context.getClass(FqName(fqName)))
|
||||
context.symbolTable.descriptorExtension.referenceClass(context.getClass(FqName(fqName)))
|
||||
}
|
||||
|
||||
+36
-26
@@ -160,7 +160,7 @@ class JsIrBackendContext(
|
||||
|
||||
override val propertyLazyInitialization: PropertyLazyInitialization = PropertyLazyInitialization(
|
||||
enabled = configuration.get(JSConfigurationKeys.PROPERTY_LAZY_INITIALIZATION, true),
|
||||
eagerInitialization = symbolTable.referenceClass(getJsInternalClass("EagerInitialization"))
|
||||
eagerInitialization = symbolTable.descriptorExtension.referenceClass(getJsInternalClass("EagerInitialization"))
|
||||
)
|
||||
|
||||
override val catchAllThrowableType: IrType
|
||||
@@ -194,36 +194,36 @@ class JsIrBackendContext(
|
||||
override val enumEntries = getIrClass(ENUMS_PACKAGE_FQNAME.child(Name.identifier("EnumEntries")))
|
||||
override val createEnumEntries = getFunctions(ENUMS_PACKAGE_FQNAME.child(Name.identifier("enumEntries")))
|
||||
.find { it.valueParameters.firstOrNull()?.type?.isFunctionType == false }
|
||||
.let { symbolTable.referenceSimpleFunction(it!!) }
|
||||
.let { symbolTable.descriptorExtension.referenceSimpleFunction(it!!) }
|
||||
|
||||
override val ir = object : Ir<JsIrBackendContext>(this) {
|
||||
override val symbols = object : Symbols(irBuiltIns, symbolTable) {
|
||||
private val context = this@JsIrBackendContext
|
||||
|
||||
override val throwNullPointerException =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single())
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single())
|
||||
|
||||
init {
|
||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("noWhenBranchMatchedException"))).single())
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("noWhenBranchMatchedException"))).single())
|
||||
}
|
||||
|
||||
override val throwTypeCastException =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).single())
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).single())
|
||||
|
||||
override val throwUninitializedPropertyAccessException =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(FqName("kotlin.throwUninitializedPropertyAccessException")).single())
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getFunctions(FqName("kotlin.throwUninitializedPropertyAccessException")).single())
|
||||
|
||||
override val throwKotlinNothingValueException: IrSimpleFunctionSymbol =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(FqName("kotlin.throwKotlinNothingValueException")).single())
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getFunctions(FqName("kotlin.throwKotlinNothingValueException")).single())
|
||||
|
||||
override val defaultConstructorMarker =
|
||||
symbolTable.referenceClass(context.getJsInternalClass("DefaultConstructorMarker"))
|
||||
symbolTable.descriptorExtension.referenceClass(context.getJsInternalClass("DefaultConstructorMarker"))
|
||||
|
||||
override val throwISE: IrSimpleFunctionSymbol =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))).single())
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_ISE"))).single())
|
||||
|
||||
override val throwIAE: IrSimpleFunctionSymbol =
|
||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_IAE"))).single())
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_IAE"))).single())
|
||||
|
||||
override val stringBuilder
|
||||
get() = TODO("not implemented")
|
||||
@@ -234,7 +234,7 @@ class JsIrBackendContext(
|
||||
|
||||
private val _arraysContentEquals = getFunctions(FqName("kotlin.collections.contentEquals")).mapNotNull {
|
||||
if (it.extensionReceiverParameter != null && it.extensionReceiverParameter!!.type.isNullable())
|
||||
symbolTable.referenceSimpleFunction(it)
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(it)
|
||||
else null
|
||||
}
|
||||
|
||||
@@ -242,19 +242,21 @@ class JsIrBackendContext(
|
||||
override val arraysContentEquals: Map<IrType, IrSimpleFunctionSymbol>
|
||||
get() = _arraysContentEquals.associateBy { it.owner.extensionReceiverParameter!!.type.makeNotNull() }
|
||||
|
||||
override val getContinuation = symbolTable.referenceSimpleFunction(getJsInternalFunction("getContinuation"))
|
||||
override val getContinuation = symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction("getContinuation"))
|
||||
|
||||
override val continuationClass = context.coroutineSymbols.continuationClass
|
||||
|
||||
override val coroutineContextGetter =
|
||||
symbolTable.referenceSimpleFunction(context.coroutineSymbols.coroutineContextProperty.getter!!)
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(context.coroutineSymbols.coroutineContextProperty.getter!!)
|
||||
|
||||
override val suspendCoroutineUninterceptedOrReturn =
|
||||
symbolTable.referenceSimpleFunction(getJsInternalFunction(COROUTINE_SUSPEND_OR_RETURN_JS_NAME))
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction(COROUTINE_SUSPEND_OR_RETURN_JS_NAME))
|
||||
|
||||
override val coroutineGetContext = symbolTable.referenceSimpleFunction(getJsInternalFunction(GET_COROUTINE_CONTEXT_NAME))
|
||||
override val coroutineGetContext =
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction(GET_COROUTINE_CONTEXT_NAME))
|
||||
|
||||
override val returnIfSuspended = symbolTable.referenceSimpleFunction(getJsInternalFunction("returnIfSuspended"))
|
||||
override val returnIfSuspended =
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction("returnIfSuspended"))
|
||||
|
||||
override val functionAdapter: IrClassSymbol
|
||||
get() = TODO("Not implemented")
|
||||
@@ -300,7 +302,7 @@ class JsIrBackendContext(
|
||||
// classes forced to be loaded
|
||||
|
||||
val errorCodeSymbol: IrSimpleFunctionSymbol? =
|
||||
if (errorPolicy.allowErrors) symbolTable.referenceSimpleFunction(getJsInternalFunction("errorCode")) else null
|
||||
if (errorPolicy.allowErrors) symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction("errorCode")) else null
|
||||
|
||||
val throwableClass = getIrClass(JsIrBackendContext.KOTLIN_PACKAGE_FQN.child(Name.identifier("Throwable")))
|
||||
|
||||
@@ -311,7 +313,7 @@ class JsIrBackendContext(
|
||||
// Top-level functions forced to be loaded
|
||||
|
||||
|
||||
val coroutineEmptyContinuation = symbolTable.referenceProperty(
|
||||
val coroutineEmptyContinuation = symbolTable.descriptorExtension.referenceProperty(
|
||||
getProperty(
|
||||
FqName.fromSegments(
|
||||
listOf(
|
||||
@@ -326,20 +328,28 @@ class JsIrBackendContext(
|
||||
)
|
||||
|
||||
|
||||
val newThrowableSymbol = symbolTable.referenceSimpleFunction(getJsInternalFunction("newThrowable"))
|
||||
val extendThrowableSymbol = symbolTable.referenceSimpleFunction(getJsInternalFunction("extendThrowable"))
|
||||
val newThrowableSymbol = symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction("newThrowable"))
|
||||
val extendThrowableSymbol = symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction("extendThrowable"))
|
||||
val setPropertiesToThrowableInstanceSymbol =
|
||||
symbolTable.referenceSimpleFunction(getJsInternalFunction("setPropertiesToThrowableInstance"))
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(getJsInternalFunction("setPropertiesToThrowableInstance"))
|
||||
|
||||
override val suiteFun = getFunctions(FqName("kotlin.test.suite")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
override val testFun = getFunctions(FqName("kotlin.test.test")).singleOrNull()?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
override val suiteFun = getFunctions(FqName("kotlin.test.suite")).singleOrNull()?.let {
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(it)
|
||||
}
|
||||
override val testFun = getFunctions(FqName("kotlin.test.test")).singleOrNull()?.let {
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(it)
|
||||
}
|
||||
|
||||
val throwableConstructors by lazy2 { throwableClass.owner.declarations.filterIsInstance<IrConstructor>().map { it.symbol } }
|
||||
val defaultThrowableCtor by lazy2 { throwableConstructors.single { !it.owner.isPrimary && it.owner.valueParameters.size == 0 } }
|
||||
|
||||
val kpropertyBuilder = getFunctions(FqName("kotlin.js.getPropertyCallableRef")).single().let { symbolTable.referenceSimpleFunction(it) }
|
||||
val kpropertyBuilder = getFunctions(FqName("kotlin.js.getPropertyCallableRef")).single().let {
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(it)
|
||||
}
|
||||
val klocalDelegateBuilder =
|
||||
getFunctions(FqName("kotlin.js.getLocalDelegateReference")).single().let { symbolTable.referenceSimpleFunction(it) }
|
||||
getFunctions(FqName("kotlin.js.getLocalDelegateReference")).single().let {
|
||||
symbolTable.descriptorExtension.referenceSimpleFunction(it)
|
||||
}
|
||||
|
||||
private fun referenceOperators(): Map<Name, Map<IrClassSymbol, Collection<IrSimpleFunctionSymbol>>> {
|
||||
val primitiveIrSymbols = irBuiltIns.primitiveIrTypes.map { it.classifierOrFail as IrClassSymbol }
|
||||
@@ -365,7 +375,7 @@ class JsIrBackendContext(
|
||||
internal fun getProperty(fqName: FqName): PropertyDescriptor =
|
||||
findProperty(module.getPackage(fqName.parent()).memberScope, fqName.shortName()).single()
|
||||
|
||||
internal fun getIrClass(fqName: FqName): IrClassSymbol = symbolTable.referenceClass(getClass(fqName))
|
||||
internal fun getIrClass(fqName: FqName): IrClassSymbol = symbolTable.descriptorExtension.referenceClass(getClass(fqName))
|
||||
|
||||
internal fun getJsInternalFunction(name: String): SimpleFunctionDescriptor =
|
||||
findFunctions(internalPackage.memberScope, Name.identifier(name)).singleOrNull() ?: error("Internal function '$name' not found")
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ class ExceptionHelperCallsTransformer(private val context: JsIrBackendContext) :
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
private fun referenceFunction(fqn: FqName) =
|
||||
context.getFunctions(fqn).singleOrNull()?.let {
|
||||
context.symbolTable.referenceSimpleFunction(it)
|
||||
context.symbolTable.descriptorExtension.referenceSimpleFunction(it)
|
||||
} ?: throw AssertionError("Function not found: $fqn")
|
||||
|
||||
private val helperMapping = mapOf(
|
||||
|
||||
Reference in New Issue
Block a user