| 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,7 +2506,7 @@ fn zirErrorToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 2506 | } | 2506 | } |
| 2507 | 2507 | ||
| 2508 | try sema.requireRuntimeBlock(block, src); | 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 | fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | 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,7 +2539,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerEr |
| 2539 | // const is_gt_max = @panic("TODO get max errors in compilation"); | 2539 | // const is_gt_max = @panic("TODO get max errors in compilation"); |
| 2540 | // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code); | 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 | fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!*Inst { | 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,10 +92,6 @@ pub const Inst = struct { |
| 92 | is_err, | 92 | is_err, |
| 93 | /// *E!T => bool | 93 | /// *E!T => bool |
| 94 | is_err_ptr, | 94 | is_err_ptr, |
| 95 | /// E => u16 | ||
| 96 | error_to_int, | ||
| 97 | /// u16 => E | ||
| 98 | int_to_error, | ||
| 99 | bool_and, | 95 | bool_and, |
| 100 | bool_or, | 96 | bool_or, |
| 101 | /// Read a value from a pointer. | 97 | /// Read a value from a pointer. |
| ... | @@ -159,8 +155,6 @@ pub const Inst = struct { | ... | @@ -159,8 +155,6 @@ pub const Inst = struct { |
| 159 | .is_null_ptr, | 155 | .is_null_ptr, |
| 160 | .is_err, | 156 | .is_err, |
| 161 | .is_err_ptr, | 157 | .is_err_ptr, |
| 162 | .int_to_error, | ||
| 163 | .error_to_int, | ||
| 164 | .ptrtoint, | 158 | .ptrtoint, |
| 165 | .floatcast, | 159 | .floatcast, |
| 166 | .intcast, | 160 | .intcast, |
| ... | @@ -730,8 +724,6 @@ const DumpTzir = struct { | ... | @@ -730,8 +724,6 @@ const DumpTzir = struct { |
| 730 | .is_null_ptr, | 724 | .is_null_ptr, |
| 731 | .is_err, | 725 | .is_err, |
| 732 | .is_err_ptr, | 726 | .is_err_ptr, |
| 733 | .error_to_int, | ||
| 734 | .int_to_error, | ||
| 735 | .ptrtoint, | 727 | .ptrtoint, |
| 736 | .floatcast, | 728 | .floatcast, |
| 737 | .intcast, | 729 | .intcast, |
| ... | @@ -865,8 +857,6 @@ const DumpTzir = struct { | ... | @@ -865,8 +857,6 @@ const DumpTzir = struct { |
| 865 | .is_null_ptr, | 857 | .is_null_ptr, |
| 866 | .is_err, | 858 | .is_err, |
| 867 | .is_err_ptr, | 859 | .is_err_ptr, |
| 868 | .error_to_int, | ||
| 869 | .int_to_error, | ||
| 870 | .ptrtoint, | 860 | .ptrtoint, |
| 871 | .floatcast, | 861 | .floatcast, |
| 872 | .intcast, | 862 | .intcast, |
src/codegen.zig-10| ... | @@ -850,8 +850,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -850,8 +850,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 850 | .is_null_ptr => return self.genIsNullPtr(inst.castTag(.is_null_ptr).?), | 850 | .is_null_ptr => return self.genIsNullPtr(inst.castTag(.is_null_ptr).?), |
| 851 | .is_err => return self.genIsErr(inst.castTag(.is_err).?), | 851 | .is_err => return self.genIsErr(inst.castTag(.is_err).?), |
| 852 | .is_err_ptr => return self.genIsErrPtr(inst.castTag(.is_err_ptr).?), | 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 | .load => return self.genLoad(inst.castTag(.load).?), | 853 | .load => return self.genLoad(inst.castTag(.load).?), |
| 856 | .loop => return self.genLoop(inst.castTag(.loop).?), | 854 | .loop => return self.genLoop(inst.castTag(.loop).?), |
| 857 | .not => return self.genNot(inst.castTag(.not).?), | 855 | .not => return self.genNot(inst.castTag(.not).?), |
| ... | @@ -2960,14 +2958,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { | ... | @@ -2960,14 +2958,6 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { |
| 2960 | return self.fail(inst.base.src, "TODO load the operand and call genIsErr", .{}); | 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 | fn genLoop(self: *Self, inst: *ir.Inst.Loop) !MCValue { | 2961 | fn genLoop(self: *Self, inst: *ir.Inst.Loop) !MCValue { |
| 2972 | // A loop is a setup to be able to jump back to the beginning. | 2962 | // A loop is a setup to be able to jump back to the beginning. |
| 2973 | const start_index = self.code.items.len; | 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,8 +724,6 @@ pub fn genBody(o: *Object, body: ir.Body) error{ AnalysisFail, OutOfMemory }!voi |
| 724 | 724 | ||
| 725 | .is_err => try genIsErr(o, inst.castTag(.is_err).?), | 725 | .is_err => try genIsErr(o, inst.castTag(.is_err).?), |
| 726 | .is_err_ptr => try genIsErr(o, inst.castTag(.is_err_ptr).?), | 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 | .unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?), | 728 | .unwrap_errunion_payload => try genUnwrapErrUnionPay(o, inst.castTag(.unwrap_errunion_payload).?), |
| 731 | .unwrap_errunion_err => try genUnwrapErrUnionErr(o, inst.castTag(.unwrap_errunion_err).?), | 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,14 +1281,6 @@ fn genIsErr(o: *Object, inst: *Inst.UnOp) !CValue { |
| 1283 | return local; | 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 | fn IndentWriter(comptime UnderlyingWriter: type) type { | 1284 | fn IndentWriter(comptime UnderlyingWriter: type) type { |
| 1295 | return struct { | 1285 | return struct { |
| 1296 | const Self = @This(); | 1286 | const Self = @This(); |