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

This commit is contained in:
g-w1 2020-12-26 12:01:14 -05:00
parent d6e9862049
commit af80240678
2 changed files with 12 additions and 22 deletions

View File

@ -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);

View File

@ -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});
}