AstGen: emit nosuspend function calls

Inside a nosuspend block, emit function calls as nosuspend calls.
Also inside a comptime block, emit function calls as comptime calls.
Also emit `async foo()` calls as async calls.

Remove compile error for `nosuspend` block inside `suspend` block.
Instead of implicitly treating every `suspend` block also as a
`nosuspend` block (which would make sense), we leave suspension points
as compile errors, to hint to the programmer about accidents. Of course
they may then assert `nosuspend` by introducing a block within their
suspend block.

To make room in `Zir.Inst.Tag` I moved `typeof_peer` and `compile_log`
to `Extended`.
This commit is contained in:
Andrew Kelley
2021-04-23 21:12:29 -07:00
parent 49be88859d
commit fbfae832ea
5 changed files with 118 additions and 69 deletions

View File

@@ -1533,6 +1533,39 @@ pub const Scope = struct {
return gz.indexToRef(new_index);
}
pub fn addExtendedMultiOp(
gz: *GenZir,
opcode: Zir.Inst.Extended,
node: ast.Node.Index,
operands: []const Zir.Inst.Ref,
) !Zir.Inst.Ref {
const astgen = gz.astgen;
const gpa = astgen.gpa;
try gz.instructions.ensureUnusedCapacity(gpa, 1);
try astgen.instructions.ensureUnusedCapacity(gpa, 1);
try astgen.extra.ensureUnusedCapacity(
gpa,
@typeInfo(Zir.Inst.NodeMultiOp).Struct.fields.len + operands.len,
);
const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{
.src_node = gz.nodeIndexToRelative(node),
});
const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
astgen.instructions.appendAssumeCapacity(.{
.tag = .extended,
.data = .{ .extended = .{
.opcode = opcode,
.small = @intCast(u16, operands.len),
.operand = payload_index,
} },
});
gz.instructions.appendAssumeCapacity(new_index);
astgen.appendRefsAssumeCapacity(operands);
return gz.indexToRef(new_index);
}
pub fn addArrayTypeSentinel(
gz: *GenZir,
len: Zir.Inst.Ref,