[JS IR] Pass JsIrBackendContext as non-nullable in some functions

This commit is contained in:
Sergej Jaskiewicz
2021-12-07 19:41:31 +03:00
committed by Space
parent 3a8b4059c9
commit 962ca40687
2 changed files with 16 additions and 18 deletions
@@ -604,11 +604,11 @@ private fun getExportCandidate(declaration: IrDeclaration): IrDeclarationWithNam
return declaration
}
private fun shouldDeclarationBeExported(declaration: IrDeclarationWithName, context: JsIrBackendContext?): Boolean {
if (context?.additionalExportedDeclarationNames?.contains(declaration.fqNameWhenAvailable) == true)
private fun shouldDeclarationBeExported(declaration: IrDeclarationWithName, context: JsIrBackendContext): Boolean {
if (context.additionalExportedDeclarationNames.contains(declaration.fqNameWhenAvailable))
return true
if (context?.additionalExportedDeclarations?.contains(declaration) == true)
if (context.additionalExportedDeclarations.contains(declaration))
return true
if (declaration is IrOverridableDeclaration<*>) {
@@ -633,28 +633,26 @@ private fun shouldDeclarationBeExported(declaration: IrDeclarationWithName, cont
}
}
fun IrOverridableDeclaration<*>.isAllowedFakeOverriddenDeclaration(context: JsIrBackendContext?): Boolean {
fun IrOverridableDeclaration<*>.isAllowedFakeOverriddenDeclaration(context: JsIrBackendContext): Boolean {
if (this.resolveFakeOverride(allowAbstract = true)?.parentClassOrNull.isExportedInterface()) {
return true
}
return context?.irBuiltIns?.enumClass?.let { enumClass ->
overriddenSymbols
.asSequence()
.map { it.owner }
.filterIsInstance<IrOverridableDeclaration<*>>()
.filter { it.overriddenSymbols.isEmpty() }
.mapNotNull { it.parentClassOrNull }
.map { it.symbol }
.any { it == enumClass }
} == true
return overriddenSymbols
.asSequence()
.map { it.owner }
.filterIsInstance<IrOverridableDeclaration<*>>()
.filter { it.overriddenSymbols.isEmpty() }
.mapNotNull { it.parentClassOrNull }
.map { it.symbol }
.any { it == context.irBuiltIns.enumClass }
}
fun IrOverridableDeclaration<*>.isOverriddenExported(context: JsIrBackendContext?): Boolean =
fun IrOverridableDeclaration<*>.isOverriddenExported(context: JsIrBackendContext): Boolean =
overriddenSymbols
.any { shouldDeclarationBeExported(it.owner as IrDeclarationWithName, context) }
fun IrDeclaration.isExported(context: JsIrBackendContext?): Boolean {
fun IrDeclaration.isExported(context: JsIrBackendContext): Boolean {
val candidate = getExportCandidate(this) ?: return false
return shouldDeclarationBeExported(candidate, context)
}
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.name.Name
fun TODO(element: IrElement): Nothing = TODO(element::class.java.simpleName + " is not supported yet here")
fun IrFunction.hasStableJsName(context: JsIrBackendContext?): Boolean {
fun IrFunction.hasStableJsName(context: JsIrBackendContext): Boolean {
if (
origin == JsLoweredDeclarationOrigin.BRIDGE_WITH_STABLE_NAME ||
(this as? IrSimpleFunction)?.isMethodOfAny() == true // Handle names for special functions
@@ -118,4 +118,4 @@ fun invokeFunForLambda(call: IrCall) =
.filterIsInstance<IrSimpleFunction>()
.single { it.name.asString() == "invoke" }
fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified }
fun IrFunction.isInlineFunWithReifiedParameter() = isInline && typeParameters.any { it.isReified }