suspendExpr
Function parameters
Parameters
- gz:*GenZir
- scope:*Scope
- node:Ast.Node.Index
Functions in this namespace
Functions
Source
Implementation
fn suspendExpr(
gz: *GenZir,
scope: *Scope,
node: Ast.Node.Index,
) InnerError!Zir.Inst.Ref {
const astgen = gz.astgen;
const gpa = astgen.gpa;
const tree = astgen.tree;
const body_node = tree.nodeData(node).node;
if (gz.nosuspend_node.unwrap()) |nosuspend_node| {
return astgen.failNodeNotes(node, "suspend inside nosuspend block", .{}, &[_]u32{
try astgen.errNoteNode(nosuspend_node, "nosuspend block here", .{}),
});
}
if (gz.suspend_node.unwrap()) |suspend_node| {
return astgen.failNodeNotes(node, "cannot suspend inside suspend block", .{}, &[_]u32{
try astgen.errNoteNode(suspend_node, "other suspend block here", .{}),
});
}
const suspend_inst = try gz.makeBlockInst(.suspend_block, node);
try gz.instructions.append(gpa, suspend_inst);
var suspend_scope = gz.makeSubBlock(scope);
suspend_scope.suspend_node = node.toOptional();
defer suspend_scope.unstack();
const body_result = try fullBodyExpr(&suspend_scope, &suspend_scope.base, .{ .rl = .none }, body_node, .normal);
if (!gz.refIsNoReturn(body_result)) {
_ = try suspend_scope.addBreak(.break_inline, suspend_inst, .void_value);
}
try suspend_scope.setBlockBody(suspend_inst);
return suspend_inst.toRef();
}