[codegenerator] wrap local function generation in original lambda's file scope
This commit is contained in:
+30
-21
@@ -706,27 +706,36 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
|| declaration.isExternal
|
|| declaration.isExternal
|
||||||
|| body == null)
|
|| body == null)
|
||||||
return
|
return
|
||||||
|
val isNotInlinedLambda = declaration.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
||||||
generateFunction(codegen, declaration,
|
val file = ((declaration as? IrSimpleFunction)?.attributeOwnerId as? IrSimpleFunction)?.file.takeIf {
|
||||||
declaration.location(start = true),
|
it ?: return@takeIf false
|
||||||
declaration.location(start = false)) {
|
(currentCodeContext.fileScope() as FileScope).file != it && isNotInlinedLambda
|
||||||
using(FunctionScope(declaration, it)) {
|
}
|
||||||
val parameterScope = ParameterScope(declaration, functionGenerationContext)
|
val scope = file?.let {
|
||||||
using(parameterScope) usingParameterScope@{
|
FileScope(it)
|
||||||
using(VariableScope()) usingVariableScope@{
|
}
|
||||||
recordCoverage(body)
|
using(scope) {
|
||||||
if (declaration.isReifiedInline) {
|
generateFunction(codegen, declaration,
|
||||||
callDirect(context.ir.symbols.throwIllegalStateExceptionWithMessage.owner,
|
declaration.location(start = true),
|
||||||
listOf(context.llvm.staticData.kotlinStringLiteral(
|
declaration.location(start = false)) {
|
||||||
"unsupported call of reified inlined function `${declaration.fqNameForIrSerialization}`").llvm),
|
using(FunctionScope(declaration, it)) {
|
||||||
Lifetime.IRRELEVANT)
|
val parameterScope = ParameterScope(declaration, functionGenerationContext)
|
||||||
return@usingVariableScope
|
using(parameterScope) usingParameterScope@{
|
||||||
}
|
using(VariableScope()) usingVariableScope@{
|
||||||
when (body) {
|
recordCoverage(body)
|
||||||
is IrBlockBody -> body.statements.forEach { generateStatement(it) }
|
if (declaration.isReifiedInline) {
|
||||||
is IrExpressionBody -> generateStatement(body.expression)
|
callDirect(context.ir.symbols.throwIllegalStateExceptionWithMessage.owner,
|
||||||
is IrSyntheticBody -> throw AssertionError("Synthetic body ${body.kind} has not been lowered")
|
listOf(context.llvm.staticData.kotlinStringLiteral(
|
||||||
else -> TODO(ir2string(body))
|
"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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user