[JS IR BE] make default argument lowering support per-file mode
This commit is contained in:
committed by
Anton Bannykh
parent
4c30888d89
commit
b83df18e22
+17
-17
@@ -66,6 +66,23 @@ open class DefaultArgumentStubGenerator constructor(val context: CommonBackendCo
|
||||
if (bodies.isEmpty()) {
|
||||
// Fake override
|
||||
val newIrFunction = irFunction.generateDefaultsFunction(context, IrDeclarationOrigin.FAKE_OVERRIDE)
|
||||
|
||||
if (irFunction is IrSimpleFunction) {
|
||||
for (baseFunSymbol in irFunction.overriddenSymbols) {
|
||||
val baseFun = baseFunSymbol.owner
|
||||
if (baseFun.needsDefaultArgumentsLowering(skipInlineMethods)) {
|
||||
val baseOrigin = if (baseFun.valueParameters.any { it.defaultValue != null }) {
|
||||
DECLARATION_ORIGIN_FUNCTION_FOR_DEFAULT_PARAMETER
|
||||
} else {
|
||||
IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
}
|
||||
(baseFun.generateDefaultsFunction(context, baseOrigin) as? IrSimpleFunction)?.let {
|
||||
(newIrFunction as IrSimpleFunction).overriddenSymbols.add(it.symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return listOf(irFunction, newIrFunction)
|
||||
}
|
||||
|
||||
@@ -163,23 +180,6 @@ private fun maskParameter(function: IrFunction, number: Int) =
|
||||
private fun markerParameterDeclaration(function: IrFunction) =
|
||||
function.valueParameters.single { it.name == kConstructorMarkerName }
|
||||
|
||||
// Populates `overriddenSymbols` for the newly created functions
|
||||
class DefaultParameterFakeOverrideCleanup(val context: CommonBackendContext): DeclarationContainerLoweringPass {
|
||||
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
||||
for (func in irDeclarationContainer.declarations) {
|
||||
if (func !is IrSimpleFunction) continue
|
||||
|
||||
val defFunc = context.ir.defaultParameterDeclarationsCache[func] as? IrSimpleFunction ?: continue
|
||||
|
||||
for (o in func.overriddenSymbols) {
|
||||
(context.ir.defaultParameterDeclarationsCache[o.owner] as? IrSimpleFunction)?.let {
|
||||
defFunc.overriddenSymbols.add(it.symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class DefaultParameterInjector constructor(
|
||||
val context: CommonBackendContext,
|
||||
private val skipInline: Boolean = true
|
||||
|
||||
@@ -107,7 +107,6 @@ private fun JsIrBackendContext.lower(moduleFragment: IrModuleFragment, dependenc
|
||||
VarargLowering(this).lower(moduleFragment)
|
||||
LateinitLowering(this, true).lower(moduleFragment)
|
||||
DefaultArgumentStubGenerator(this).runOnFilesPostfix(moduleFragment)
|
||||
DefaultParameterFakeOverrideCleanup(this).runOnFilesPostfix(moduleFragment)
|
||||
DefaultParameterInjector(this).runOnFilesPostfix(moduleFragment)
|
||||
DefaultParameterCleaner(this).runOnFilesPostfix(moduleFragment)
|
||||
SharedVariablesLowering(this).runOnFilesPostfix(moduleFragment)
|
||||
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1289
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
@@ -12,4 +11,4 @@ public class C : I {
|
||||
override fun f(p: String) = p + "K"
|
||||
}
|
||||
|
||||
fun box() = C().f()
|
||||
fun box() = C().f()
|
||||
|
||||
Reference in New Issue
Block a user