From b83df18e22ed46af2c99b9333fbd98b0e12081b0 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Fri, 19 Oct 2018 18:15:40 +0300 Subject: [PATCH] [JS IR BE] make default argument lowering support per-file mode --- .../lower/DefaultArgumentStubGenerator.kt | 34 +++++++++---------- .../kotlin/ir/backend/js/compiler.kt | 1 - .../interfaceMethodWithDefaultParameter.kt | 3 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt index 9b14e650512..e2980f64ccd 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt @@ -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 diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt index 0d26b78d881..bce360c6380 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compiler.kt @@ -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) diff --git a/js/js.translator/testData/box/multiModule/interfaceMethodWithDefaultParameter.kt b/js/js.translator/testData/box/multiModule/interfaceMethodWithDefaultParameter.kt index 43ee3177b2c..3fa35737168 100644 --- a/js/js.translator/testData/box/multiModule/interfaceMethodWithDefaultParameter.kt +++ b/js/js.translator/testData/box/multiModule/interfaceMethodWithDefaultParameter.kt @@ -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() \ No newline at end of file +fun box() = C().f()