diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-23 21:12:29 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-23 21:12:29 -0700 |
| commit | fbfae832eaf520f7fcc632580b4b4a7fb171f90f (patch) | |
| tree | 1a8b34df8132e7bffc336235cfdae17f261f41c9 /src/Module.zig | |
| parent | 49be88859d3cef22c5cc27c908264a235c78a4d0 (diff) | |
| download | zig-fbfae832eaf520f7fcc632580b4b4a7fb171f90f.tar.gz zig-fbfae832eaf520f7fcc632580b4b4a7fb171f90f.zip | |
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`.
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Module.zig b/src/Module.zig index 4e69d301f3..ef5ecc934d 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -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, |
