authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2020-12-26 12:01:14-05:00
committergravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2020-12-26 12:01:14-05:00
logaf80240678112276cedd5c5247b843fa101186b0
tree70c10ae578d5dfd4f83d38b51050845dfb60c7ac
parentd6e9862049c069bcfcafdef3f3e7de842ba44cbd

make compileError use an UnOp since its operand is just a *Inst


2 files changed, 12 insertions(+), 22 deletions(-)

src/zir.zig+10-20
......@@ -300,6 +300,7 @@ pub const Inst = struct {
300300 => NoOp,
301301
302302 .boolnot,
303 .compileerror,
303304 .deref,
304305 .@"return",
305306 .isnull,
......@@ -387,7 +388,6 @@ pub const Inst = struct {
387388 .declval => DeclVal,
388389 .declval_in_module => DeclValInModule,
389390 .coerce_result_block_ptr => CoerceResultBlockPtr,
390 .compileerror => CompileError,
391391 .compilelog => CompileLog,
392392 .loop => Loop,
393393 .@"const" => Const,
......@@ -701,16 +701,6 @@ pub const Inst = struct {
701701 kw_args: struct {},
702702 };
703703
704 pub const CompileError = struct {
705 pub const base_tag = Tag.compileerror;
706 base: Inst,
707
708 positionals: struct {
709 msg: *Inst,
710 },
711 kw_args: struct {},
712 };
713
714704 pub const CompileLog = struct {
715705 pub const base_tag = Tag.compilelog;
716706 base: Inst,
......@@ -1943,14 +1933,14 @@ const EmitZIR = struct {
19431933 .sema_failure_retryable,
19441934 .dependency_failure,
19451935 => if (self.old_module.failed_decls.get(ir_decl)) |err_msg_list| {
1946 const fail_inst = try self.arena.allocator.create(Inst.CompileError);
1936 const fail_inst = try self.arena.allocator.create(Inst.UnOp);
19471937 fail_inst.* = .{
19481938 .base = .{
19491939 .src = ir_decl.src(),
1950 .tag = Inst.CompileError.base_tag,
1940 .tag = .compileerror,
19511941 },
19521942 .positionals = .{
1953 .msg = blk: {
1943 .operand = blk: {
19541944 const msg_str = try self.arena.allocator.dupe(u8, err_msg_list.items[0].msg);
19551945
19561946 const str_inst = try self.arena.allocator.create(Inst.Str);
......@@ -2088,14 +2078,14 @@ const EmitZIR = struct {
20882078 },
20892079 .sema_failure => {
20902080 const err_msg = self.old_module.failed_decls.get(module_fn.owner_decl).?.items[0];
2091 const fail_inst = try self.arena.allocator.create(Inst.CompileError);
2081 const fail_inst = try self.arena.allocator.create(Inst.UnOp);
20922082 fail_inst.* = .{
20932083 .base = .{
20942084 .src = src,
2095 .tag = Inst.CompileError.base_tag,
2085 .tag = .compileerror,
20962086 },
20972087 .positionals = .{
2098 .msg = blk: {
2088 .operand = blk: {
20992089 const msg_str = try self.arena.allocator.dupe(u8, err_msg.msg);
21002090
21012091 const str_inst = try self.arena.allocator.create(Inst.Str);
......@@ -2117,14 +2107,14 @@ const EmitZIR = struct {
21172107 try instructions.append(&fail_inst.base);
21182108 },
21192109 .dependency_failure => {
2120 const fail_inst = try self.arena.allocator.create(Inst.CompileError);
2110 const fail_inst = try self.arena.allocator.create(Inst.UnOp);
21212111 fail_inst.* = .{
21222112 .base = .{
21232113 .src = src,
2124 .tag = Inst.CompileError.base_tag,
2114 .tag = .compileerror,
21252115 },
21262116 .positionals = .{
2127 .msg = blk: {
2117 .operand = blk: {
21282118 const msg_str = try self.arena.allocator.dupe(u8, "depends on another failed Decl");
21292119
21302120 const str_inst = try self.arena.allocator.create(Inst.Str);
src/zir_sema.zig+2-2
......@@ -486,8 +486,8 @@ fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export)
486486 return mod.constVoid(scope, export_inst.base.src);
487487}
488488
489fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileError) InnerError!*Inst {
490 const msg = try resolveConstString(mod, scope, inst.positionals.msg);
489fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.UnOp) InnerError!*Inst {
490 const msg = try resolveConstString(mod, scope, inst.positionals.operand);
491491 return mod.fail(scope, inst.base.src, "{}", .{msg});
492492}
493493