From 28c2d3c29d5fe0e29bc0bdae2b7afc08ba372179 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Tue, 28 Jul 2020 12:05:52 +0200 Subject: [PATCH] [codegenerator] wrap local function generation in original lambda's file scope --- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index e8bbd22832e..6dffef043ff 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -706,27 +706,36 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map body.statements.forEach { generateStatement(it) } - is IrExpressionBody -> generateStatement(body.expression) - is IrSyntheticBody -> throw AssertionError("Synthetic body ${body.kind} has not been lowered") - else -> TODO(ir2string(body)) + val isNotInlinedLambda = declaration.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA + val file = ((declaration as? IrSimpleFunction)?.attributeOwnerId as? IrSimpleFunction)?.file.takeIf { + it ?: return@takeIf false + (currentCodeContext.fileScope() as FileScope).file != it && isNotInlinedLambda + } + val scope = file?.let { + FileScope(it) + } + using(scope) { + generateFunction(codegen, declaration, + declaration.location(start = true), + declaration.location(start = false)) { + using(FunctionScope(declaration, it)) { + val parameterScope = ParameterScope(declaration, functionGenerationContext) + using(parameterScope) usingParameterScope@{ + using(VariableScope()) usingVariableScope@{ + recordCoverage(body) + if (declaration.isReifiedInline) { + callDirect(context.ir.symbols.throwIllegalStateExceptionWithMessage.owner, + listOf(context.llvm.staticData.kotlinStringLiteral( + "unsupported call of reified inlined function `${declaration.fqNameForIrSerialization}`").llvm), + Lifetime.IRRELEVANT) + return@usingVariableScope + } + when (body) { + is IrBlockBody -> body.statements.forEach { generateStatement(it) } + is IrExpressionBody -> generateStatement(body.expression) + is IrSyntheticBody -> throw AssertionError("Synthetic body ${body.kind} has not been lowered") + else -> TODO(ir2string(body)) + } } } }