From af80240678112276cedd5c5247b843fa101186b0 Mon Sep 17 00:00:00 2001 From: g-w1 Date: Sat, 26 Dec 2020 12:01:14 -0500 Subject: [PATCH] make compileError use an UnOp since its operand is just a *Inst --- src/zir.zig | 30 ++++++++++-------------------- src/zir_sema.zig | 4 ++-- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/zir.zig b/src/zir.zig index b44d06bad5..73530ec86d 100644 --- a/src/zir.zig +++ b/src/zir.zig @@ -300,6 +300,7 @@ pub const Inst = struct { => NoOp, .boolnot, + .compileerror, .deref, .@"return", .isnull, @@ -387,7 +388,6 @@ pub const Inst = struct { .declval => DeclVal, .declval_in_module => DeclValInModule, .coerce_result_block_ptr => CoerceResultBlockPtr, - .compileerror => CompileError, .compilelog => CompileLog, .loop => Loop, .@"const" => Const, @@ -701,16 +701,6 @@ pub const Inst = struct { kw_args: struct {}, }; - pub const CompileError = struct { - pub const base_tag = Tag.compileerror; - base: Inst, - - positionals: struct { - msg: *Inst, - }, - kw_args: struct {}, - }; - pub const CompileLog = struct { pub const base_tag = Tag.compilelog; base: Inst, @@ -1943,14 +1933,14 @@ const EmitZIR = struct { .sema_failure_retryable, .dependency_failure, => if (self.old_module.failed_decls.get(ir_decl)) |err_msg_list| { - const fail_inst = try self.arena.allocator.create(Inst.CompileError); + const fail_inst = try self.arena.allocator.create(Inst.UnOp); fail_inst.* = .{ .base = .{ .src = ir_decl.src(), - .tag = Inst.CompileError.base_tag, + .tag = .compileerror, }, .positionals = .{ - .msg = blk: { + .operand = blk: { const msg_str = try self.arena.allocator.dupe(u8, err_msg_list.items[0].msg); const str_inst = try self.arena.allocator.create(Inst.Str); @@ -2088,14 +2078,14 @@ const EmitZIR = struct { }, .sema_failure => { const err_msg = self.old_module.failed_decls.get(module_fn.owner_decl).?.items[0]; - const fail_inst = try self.arena.allocator.create(Inst.CompileError); + const fail_inst = try self.arena.allocator.create(Inst.UnOp); fail_inst.* = .{ .base = .{ .src = src, - .tag = Inst.CompileError.base_tag, + .tag = .compileerror, }, .positionals = .{ - .msg = blk: { + .operand = blk: { const msg_str = try self.arena.allocator.dupe(u8, err_msg.msg); const str_inst = try self.arena.allocator.create(Inst.Str); @@ -2117,14 +2107,14 @@ const EmitZIR = struct { try instructions.append(&fail_inst.base); }, .dependency_failure => { - const fail_inst = try self.arena.allocator.create(Inst.CompileError); + const fail_inst = try self.arena.allocator.create(Inst.UnOp); fail_inst.* = .{ .base = .{ .src = src, - .tag = Inst.CompileError.base_tag, + .tag = .compileerror, }, .positionals = .{ - .msg = blk: { + .operand = blk: { const msg_str = try self.arena.allocator.dupe(u8, "depends on another failed Decl"); const str_inst = try self.arena.allocator.create(Inst.Str); diff --git a/src/zir_sema.zig b/src/zir_sema.zig index 4f0c8c0233..8e6632ee84 100644 --- a/src/zir_sema.zig +++ b/src/zir_sema.zig @@ -486,8 +486,8 @@ fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export) return mod.constVoid(scope, export_inst.base.src); } -fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileError) InnerError!*Inst { - const msg = try resolveConstString(mod, scope, inst.positionals.msg); +fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst { + const msg = try resolveConstString(mod, scope, inst.positionals.operand); return mod.fail(scope, inst.base.src, "{}", .{msg}); }