diff options
| author | Veikka Tuominen <git@vexu.eu> | 2021-01-28 22:38:25 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2021-03-06 15:01:25 +0200 |
| commit | 17e6e09285ed29ead1a3de5d5bfeb4d287f23215 (patch) | |
| tree | 26dce4f4fd7ec0822aa3c73af8b69ad37a60245e /src/Module.zig | |
| parent | 9f722f43ac449caa0e09c1b7bb1bad0581ef323d (diff) | |
| download | zig-17e6e09285ed29ead1a3de5d5bfeb4d287f23215.tar.gz zig-17e6e09285ed29ead1a3de5d5bfeb4d287f23215.zip | |
stage2: astgen async
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/src/Module.zig b/src/Module.zig index e6d509ace5..c5cdbb3890 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -370,6 +370,8 @@ pub const Scope = struct { .gen_zir => return self.cast(GenZIR).?.arena, .local_val => return self.cast(LocalVal).?.gen_zir.arena, .local_ptr => return self.cast(LocalPtr).?.gen_zir.arena, + .gen_suspend => return self.cast(GenZIR).?.arena, + .gen_nosuspend => return self.cast(Nosuspend).?.gen_zir.arena, .file => unreachable, .container => unreachable, } @@ -385,6 +387,8 @@ pub const Scope = struct { .gen_zir => self.cast(GenZIR).?.decl, .local_val => self.cast(LocalVal).?.gen_zir.decl, .local_ptr => self.cast(LocalPtr).?.gen_zir.decl, + .gen_suspend => return self.cast(GenZIR).?.decl, + .gen_nosuspend => return self.cast(Nosuspend).?.gen_zir.decl, .file => null, .container => null, }; @@ -396,6 +400,8 @@ pub const Scope = struct { .gen_zir => self.cast(GenZIR).?.decl, .local_val => self.cast(LocalVal).?.gen_zir.decl, .local_ptr => self.cast(LocalPtr).?.gen_zir.decl, + .gen_suspend => return self.cast(GenZIR).?.decl, + .gen_nosuspend => return self.cast(Nosuspend).?.gen_zir.decl, .file => null, .container => null, }; @@ -410,6 +416,8 @@ pub const Scope = struct { .local_ptr => return self.cast(LocalPtr).?.gen_zir.decl.container, .file => return &self.cast(File).?.root_container, .container => return self.cast(Container).?, + .gen_suspend => return self.cast(GenZIR).?.decl.container, + .gen_nosuspend => return self.cast(Nosuspend).?.gen_zir.decl.container, } } @@ -422,6 +430,8 @@ pub const Scope = struct { .gen_zir => unreachable, .local_val => unreachable, .local_ptr => unreachable, + .gen_suspend => unreachable, + .gen_nosuspend => unreachable, .file => unreachable, .container => return self.cast(Container).?.fullyQualifiedNameHash(name), } @@ -436,6 +446,8 @@ pub const Scope = struct { .local_val => return &self.cast(LocalVal).?.gen_zir.decl.container.file_scope.tree, .local_ptr => return &self.cast(LocalPtr).?.gen_zir.decl.container.file_scope.tree, .container => return &self.cast(Container).?.file_scope.tree, + .gen_suspend => return &self.cast(GenZIR).?.decl.container.file_scope.tree, + .gen_nosuspend => return &self.cast(Nosuspend).?.gen_zir.decl.container.file_scope.tree, } } @@ -443,9 +455,10 @@ pub const Scope = struct { pub fn getGenZIR(self: *Scope) *GenZIR { return switch (self.tag) { .block => unreachable, - .gen_zir => self.cast(GenZIR).?, + .gen_zir, .gen_suspend => self.cast(GenZIR).?, .local_val => return self.cast(LocalVal).?.gen_zir, .local_ptr => return self.cast(LocalPtr).?.gen_zir, + .gen_nosuspend => return self.cast(Nosuspend).?.gen_zir, .file => unreachable, .container => unreachable, }; @@ -461,6 +474,8 @@ pub const Scope = struct { .gen_zir => unreachable, .local_val => unreachable, .local_ptr => unreachable, + .gen_suspend => unreachable, + .gen_nosuspend => unreachable, } } @@ -472,6 +487,8 @@ pub const Scope = struct { .local_val => unreachable, .local_ptr => unreachable, .block => unreachable, + .gen_suspend => unreachable, + .gen_nosuspend => unreachable, } } @@ -486,6 +503,36 @@ pub const Scope = struct { .local_val => @fieldParentPtr(LocalVal, "base", cur).parent, .local_ptr => @fieldParentPtr(LocalPtr, "base", cur).parent, .block => return @fieldParentPtr(Block, "base", cur).src_decl.container.file_scope, + .gen_suspend => @fieldParentPtr(GenZIR, "base", cur).parent, + .gen_nosuspend => @fieldParentPtr(Nosuspend, "base", cur).parent, + }; + } + } + + pub fn getSuspend(base: *Scope) ?*Scope.GenZIR { + var cur = base; + while (true) { + cur = switch (cur.tag) { + .gen_zir => @fieldParentPtr(GenZIR, "base", cur).parent, + .local_val => @fieldParentPtr(LocalVal, "base", cur).parent, + .local_ptr => @fieldParentPtr(LocalPtr, "base", cur).parent, + .gen_nosuspend => @fieldParentPtr(Nosuspend, "base", cur).parent, + .gen_suspend => return @fieldParentPtr(GenZIR, "base", cur), + else => return null, + }; + } + } + + pub fn getNosuspend(base: *Scope) ?*Scope.Nosuspend { + var cur = base; + while (true) { + cur = switch (cur.tag) { + .gen_zir => @fieldParentPtr(GenZIR, "base", cur).parent, + .local_val => @fieldParentPtr(LocalVal, "base", cur).parent, + .local_ptr => @fieldParentPtr(LocalPtr, "base", cur).parent, + .gen_suspend => @fieldParentPtr(GenZIR, "base", cur).parent, + .gen_nosuspend => return @fieldParentPtr(Nosuspend, "base", cur), + else => return null, }; } } @@ -507,6 +554,8 @@ pub const Scope = struct { gen_zir, local_val, local_ptr, + gen_suspend, + gen_nosuspend, }; pub const Container = struct { @@ -740,6 +789,8 @@ pub const Scope = struct { /// so they can possibly be elided later if the labeled block ends up not needing /// a result location pointer. labeled_store_to_block_ptr_list: std.ArrayListUnmanaged(*zir.Inst.BinOp) = .{}, + /// for suspend error notes + src: usize = 0, pub const Label = struct { token: ast.TokenIndex, @@ -773,6 +824,16 @@ pub const Scope = struct { name: []const u8, ptr: *zir.Inst, }; + + pub const Nosuspend = struct { + pub const base_tag: Tag = .gen_nosuspend; + + base: Scope = Scope{ .tag = base_tag }, + /// Parents can be: `LocalVal`, `LocalPtr`, `GenZIR`. + parent: *Scope, + gen_zir: *GenZIR, + src: usize, + }; }; /// This struct holds data necessary to construct API-facing `AllErrors.Message`. @@ -3586,7 +3647,7 @@ pub fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, err_msg: *ErrorMsg) I } self.failed_decls.putAssumeCapacityNoClobber(block.owner_decl, err_msg); }, - .gen_zir => { + .gen_zir, .gen_suspend => { const gen_zir = scope.cast(Scope.GenZIR).?; gen_zir.decl.analysis = .sema_failure; gen_zir.decl.generation = self.generation; @@ -3604,6 +3665,12 @@ pub fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, err_msg: *ErrorMsg) I gen_zir.decl.generation = self.generation; self.failed_decls.putAssumeCapacityNoClobber(gen_zir.decl, err_msg); }, + .gen_nosuspend => { + const gen_zir = scope.cast(Scope.Nosuspend).?.gen_zir; + gen_zir.decl.analysis = .sema_failure; + gen_zir.decl.generation = self.generation; + self.failed_decls.putAssumeCapacityNoClobber(gen_zir.decl, err_msg); + }, .file => unreachable, .container => unreachable, } |
