| author | |
| committer | |
| log | a95fdb06352a6a1e60d0167bad62f5a46345177a |
| tree | db2347ab29797d19c899bf2f6a043a984eb173c2 |
| parent | fc1feebdc0ffd4730c724780265d4ef6a9515dc8 |
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 bitcast4 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 |
| 2506 | 2506 | } |
| 2507 | 2507 | |
| 2508 | 2508 | 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); | |
| 2510 | 2510 | } |
| 2511 | 2511 | |
| 2512 | 2512 | fn 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 |
| 2539 | 2539 | // const is_gt_max = @panic("TODO get max errors in compilation"); |
| 2540 | 2540 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); |
| 2541 | 2541 | } |
| 2542 | return block.addUnOp(src, Type.initTag(.anyerror), .int_to_error, op); | |
| 2542 | return block.addUnOp(src, Type.initTag(.anyerror), .bitcast, op); | |
| 2543 | 2543 | } |
| 2544 | 2544 | |
| 2545 | 2545 | fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { |
src/air.zig-10| ... | ... | @@ -92,10 +92,6 @@ pub const Inst = struct { |
| 92 | 92 | is_err, |
| 93 | 93 | /// *E!T => bool |
| 94 | 94 | is_err_ptr, |
| 95 | /// E => u16 | |
| 96 | error_to_int, | |
| 97 | /// u16 => E | |
| 98 | int_to_error, | |
| 99 | 95 | bool_and, |
| 100 | 96 | bool_or, |
| 101 | 97 | /// Read a value from a pointer. |
| ... | ... | @@ -159,8 +155,6 @@ pub const Inst = struct { |
| 159 | 155 | .is_null_ptr, |
| 160 | 156 | .is_err, |
| 161 | 157 | .is_err_ptr, |
| 162 | .int_to_error, | |
| 163 | .error_to_int, | |
| 164 | 158 | .ptrtoint, |
| 165 | 159 | .floatcast, |
| 166 | 160 | .intcast, |
| ... | ... | @@ -730,8 +724,6 @@ const DumpTzir = struct { |
| 730 | 724 | .is_null_ptr, |
| 731 | 725 | .is_err, |
| 732 | 726 | .is_err_ptr, |
| 733 | .error_to_int, | |
| 734 | .int_to_error, | |
| 735 | 727 | .ptrtoint, |
| 736 | 728 | .floatcast, |
| 737 | 729 | .intcast, |
| ... | ... | @@ -865,8 +857,6 @@ const DumpTzir = struct { |
| 865 | 857 | .is_null_ptr, |
| 866 | 858 | .is_err, |
| 867 | 859 | .is_err_ptr, |
| 868 | .error_to_int, | |
| 869 | .int_to_error, | |
| 870 | 860 | .ptrtoint, |
| 871 | 861 | .floatcast, |
| 872 | 862 | .intcast, |
src/codegen.zig-10| ... | ... | @@ -850,8 +850,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 850 | 850 | .is_null_ptr => return self.genIsNullPtr(inst.castTag(.is_null_ptr).?), |
| 851 | 851 | .is_err => return self.genIsErr(inst.castTag(.is_err).?), |
| 852 | 852 | .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).?), | |
| 855 | 853 | .load => return self.genLoad(inst.castTag(.load).?), |
| 856 | 854 | .loop => return self.genLoop(inst.castTag(.loop).?), |
| 857 | 855 | .not => return self.genNot(inst.castTag(.not).?), |
| ... | ... | @@ -2960,14 +2958,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2960 | 2958 | return self.fail(inst.base.src, "TODO load the operand and call genIsErr", .{}); |
| 2961 | 2959 | } |
| 2962 | 2960 | |
| 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 | ||
| 2971 | 2961 | fn genLoop(self: *Self, inst: *ir.Inst.Loop) !MCValue { |
| 2972 | 2962 | // A loop is a setup to be able to jump back to the beginning. |
| 2973 | 2963 | 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 |
| 724 | 724 | |
| 725 | 725 | .is_err => try genIsErr(o, inst.castTag(.is_err).?), |
| 726 | 726 | .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).?), | |
| 729 | 727 | |
| 730 | 728 | .unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?), |
| 731 | 729 | .unwrap_errunion_err => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err).?), |
| ... | ... | @@ -1283,14 +1281,6 @@ fn genIsErr(o: *Object, inst: *Inst.UnOp) !CValue { |
| 1283 | 1281 | return local; |
| 1284 | 1282 | } |
| 1285 | 1283 | |
| 1286 | fn genIntToError(o: *Object, inst: *Inst.UnOp) !CValue { | |
| 1287 | return o.resolveInst(inst.operand); | |
| 1288 | } | |
| 1289 | ||
| 1290 | fn genErrorToInt(o: *Object, inst: *Inst.UnOp) !CValue { | |
| 1291 | return o.resolveInst(inst.operand); | |
| 1292 | } | |
| 1293 | ||
| 1294 | 1284 | fn IndentWriter(comptime UnderlyingWriter: type) type { |
| 1295 | 1285 | return struct { |
| 1296 | 1286 | const Self = @This(); |