authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-06-17 11:57:27-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-21 18:45:28+03:00
loga95fdb06352a6a1e60d0167bad62f5a46345177a
treedb2347ab29797d19c899bf2f6a043a984eb173c2
parentfc1feebdc0ffd4730c724780265d4ef6a9515dc8

stage2: simplify codegen for errorToInt and intToError

We can just use bitcast instead of error_to_int, int_to_error since errorToInt and intToError do not actually do anything, just change types. This allows us to remove 2 air ops that were the exact same as bitcast

4 files changed, 2 insertions(+), 32 deletions(-)

src/Sema.zig+2-2
......@@ -2506,7 +2506,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25062506 }
25072507
25082508 try sema.requireRuntimeBlock(block, src);
2509 return block.addUnOp(src, result_ty, .error_to_int, op_coerced);
2509 return block.addUnOp(src, result_ty, .bitcast, op_coerced);
25102510}
25112511
25122512fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
......@@ -2539,7 +2539,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr
25392539 // const is_gt_max = @panic("TODO get max errors in compilation");
25402540 // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code);
25412541 }
2542 return block.addUnOp(src, Type.initTag(.anyerror), .int_to_error, op);
2542 return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op);
25432543}
25442544
25452545fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst {
src/air.zig-10
......@@ -92,10 +92,6 @@ pub const Inst = struct {
9292 is_err,
9393 /// *E!T => bool
9494 is_err_ptr,
95 /// E => u16
96 error_to_int,
97 /// u16 => E
98 int_to_error,
9995 bool_and,
10096 bool_or,
10197 /// Read a value from a pointer.
......@@ -159,8 +155,6 @@ pub const Inst = struct {
159155 .is_null_ptr,
160156 .is_err,
161157 .is_err_ptr,
162 .int_to_error,
163 .error_to_int,
164158 .ptrtoint,
165159 .floatcast,
166160 .intcast,
......@@ -730,8 +724,6 @@ const DumpTzir = struct {
730724 .is_null_ptr,
731725 .is_err,
732726 .is_err_ptr,
733 .error_to_int,
734 .int_to_error,
735727 .ptrtoint,
736728 .floatcast,
737729 .intcast,
......@@ -865,8 +857,6 @@ const DumpTzir = struct {
865857 .is_null_ptr,
866858 .is_err,
867859 .is_err_ptr,
868 .error_to_int,
869 .int_to_error,
870860 .ptrtoint,
871861 .floatcast,
872862 .intcast,
src/codegen.zig-10
......@@ -850,8 +850,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
850850 .is_null_ptr => return self.genIsNullPtr(inst.castTag(.is_null_ptr).?),
851851 .is_err => return self.genIsErr(inst.castTag(.is_err).?),
852852 .is_err_ptr => return self.genIsErrPtr(inst.castTag(.is_err_ptr).?),
853 .error_to_int => return self.genErrorToInt(inst.castTag(.error_to_int).?),
854 .int_to_error => return self.genIntToError(inst.castTag(.int_to_error).?),
855853 .load => return self.genLoad(inst.castTag(.load).?),
856854 .loop => return self.genLoop(inst.castTag(.loop).?),
857855 .not => return self.genNot(inst.castTag(.not).?),
......@@ -2960,14 +2958,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
29602958 return self.fail(inst.base.src, "TODO load the operand and call genIsErr", .{});
29612959 }
29622960
2963 fn genErrorToInt(self: *Self, inst: *ir.Inst.UnOp) !MCValue {
2964 return self.resolveInst(inst.operand);
2965 }
2966
2967 fn genIntToError(self: *Self, inst: *ir.Inst.UnOp) !MCValue {
2968 return self.resolveInst(inst.operand);
2969 }
2970
29712961 fn genLoop(self: *Self, inst: *ir.Inst.Loop) !MCValue {
29722962 // A loop is a setup to be able to jump back to the beginning.
29732963 const start_index = self.code.items.len;
src/codegen/c.zig-10
......@@ -724,8 +724,6 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi
724724
725725 .is_err => try genIsErr(o, inst.castTag(.is_err).?),
726726 .is_err_ptr => try genIsErr(o, inst.castTag(.is_err_ptr).?),
727 .error_to_int => try genErrorToInt(o, inst.castTag(.error_to_int).?),
728 .int_to_error => try genIntToError(o, inst.castTag(.int_to_error).?),
729727
730728 .unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?),
731729 .unwrap_errunion_err => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err).?),
......@@ -1283,14 +1281,6 @@ fn genIsErr(o: *Object, inst: *Inst.UnOp) !CValue {
12831281 return local;
12841282}
12851283
1286fn genIntToError(o: *Object, inst: *Inst.UnOp) !CValue {
1287 return o.resolveInst(inst.operand);
1288}
1289
1290fn genErrorToInt(o: *Object, inst: *Inst.UnOp) !CValue {
1291 return o.resolveInst(inst.operand);
1292}
1293
12941284fn IndentWriter(comptime UnderlyingWriter: type) type {
12951285 return struct {
12961286 const Self = @This();