From 77949abcdcb53bd1518766e84d85d09e18bbbf30 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Fri, 9 Oct 2020 15:28:10 +0500 Subject: [PATCH] [IR] Native version of DefaultArgumentStubGenerator By default, DefaultArgumentStubGenerator produces IrSetValue to IrValueParameter which is not supported, so replace it with a temp creation and setting into it --- .../backend/konan/KonanLoweringPhases.kt | 2 +- .../KonanDefaultArgumentStubGenerator.kt | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/KonanDefaultArgumentStubGenerator.kt diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt index 0593293d2f2..549db0cccb4 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanLoweringPhases.kt @@ -217,7 +217,7 @@ internal val tailrecPhase = makeKonanFileLoweringPhase( internal val defaultParameterExtentPhase = makeKonanFileOpPhase( { context, irFile -> - DefaultArgumentStubGenerator(context, skipInlineMethods = false).lower(irFile) + KonanDefaultArgumentStubGenerator(context).lower(irFile) DefaultParameterCleaner(context, replaceDefaultValuesWithStubs = true).lower(irFile) KonanDefaultParameterInjector(context).lower(irFile) }, diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/KonanDefaultArgumentStubGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/KonanDefaultArgumentStubGenerator.kt new file mode 100644 index 00000000000..de2b529727e --- /dev/null +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/KonanDefaultArgumentStubGenerator.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package org.jetbrains.kotlin.backend.konan.lower + +import org.jetbrains.kotlin.backend.common.lower.DefaultArgumentStubGenerator +import org.jetbrains.kotlin.backend.konan.Context +import org.jetbrains.kotlin.ir.builders.* +import org.jetbrains.kotlin.ir.declarations.IrValueDeclaration +import org.jetbrains.kotlin.ir.declarations.IrValueParameter +import org.jetbrains.kotlin.ir.expressions.IrExpression + +internal class KonanDefaultArgumentStubGenerator(override val context: Context) + : DefaultArgumentStubGenerator(context, skipInlineMethods = false) +{ + override fun IrBlockBodyBuilder.selectArgumentOrDefault( + defaultFlag: IrExpression, + parameter: IrValueParameter, + default: IrExpression + ): IrValueDeclaration { + val value = irIfThenElse(parameter.type, irNotEquals(defaultFlag, irInt(0)), default, irGet(parameter)) + return createTmpVariable(value, nameHint = parameter.name.asString()) + } +} \ No newline at end of file