authorgravatar for daniele.cocca@gmail.comDaniele Cocca <daniele.cocca@gmail.com> 2022-03-20 20:50:59+00:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-30 11:57:15+03:00
log633fe41a2c2310d8cfab53ee9d87bb50ac4efc41
tree131d009bf31145ed8185f3a9fd4d7914de361a35
parent5d5282b5f18b33489187a9a9e23a1aa2d301b4e8

Sema: allow comptime blocks for global assembly

An assembly expression in a comptime block is legal Zig in the case of global assembly [^1]. Instead of unconditionally asserting that the expression lives in a runtime block, here we assert that if the expression lives in a comptime block it must be outside of function scope. [^1]: https://ziglang.org/documentation/0.9.1/#Global-Assembly

1 files changed, 5 insertions(+), 1 deletions(-)

src/Sema.zig+5-1
...@@ -10253,6 +10253,11 @@ fn zirAsm(...@@ -10253,6 +10253,11 @@ fn zirAsm(
10253 const inputs_len = @truncate(u5, extended.small >> 5);10253 const inputs_len = @truncate(u5, extended.small >> 5);
10254 const clobbers_len = @truncate(u5, extended.small >> 10);10254 const clobbers_len = @truncate(u5, extended.small >> 10);
10255 const is_volatile = @truncate(u1, extended.small >> 15) != 0;10255 const is_volatile = @truncate(u1, extended.small >> 15) != 0;
10256 const is_global_assembly = sema.func == null;
10257
10258 if (block.is_comptime and !is_global_assembly) {
10259 try sema.requireRuntimeBlock(block, src);
10260 }
1025610261
10257 if (extra.data.asm_source == 0) {10262 if (extra.data.asm_source == 0) {
10258 // This can move to become an AstGen error after inline assembly improvements land10263 // This can move to become an AstGen error after inline assembly improvements land
...@@ -10317,7 +10322,6 @@ fn zirAsm(...@@ -10317,7 +10322,6 @@ fn zirAsm(
10317 needed_capacity += (asm_source.len + 3) / 4;10322 needed_capacity += (asm_source.len + 3) / 4;
1031810323
10319 const gpa = sema.gpa;10324 const gpa = sema.gpa;
10320 try sema.requireRuntimeBlock(block, src);
10321 try sema.air_extra.ensureUnusedCapacity(gpa, needed_capacity);10325 try sema.air_extra.ensureUnusedCapacity(gpa, needed_capacity);
10322 const asm_air = try block.addInst(.{10326 const asm_air = try block.addInst(.{
10323 .tag = .assembly,10327 .tag = .assembly,