authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-26 16:43:35-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-28 17:25:39-04:00
logbdbe16c47a1a7bb7412bcfbf39c9f32d22a7e2cb
treea213b5a2c14115d6b96b420e77055be129ea7d9c
parent70e0d8170fe3de3e9be86813fc6baff013b352b4

Sema: cleanup to use more enum literals


1 files changed, 100 insertions(+), 130 deletions(-)

src/Sema.zig+100-130
......@@ -849,7 +849,7 @@ fn resolveBody(
849849 body_inst: Zir.Inst.Index,
850850) CompileError!Air.Inst.Ref {
851851 const break_data = (try sema.analyzeBodyBreak(block, body)) orelse
852 return Air.Inst.Ref.unreachable_value;
852 return .unreachable_value;
853853 // For comptime control flow, we need to detect when `analyzeBody` reports
854854 // that we need to break from an outer block. In such case we
855855 // use Zig's error mechanism to send control flow up the stack until
......@@ -1757,7 +1757,7 @@ fn analyzeBodyInner(
17571757 else => |e| return e,
17581758 };
17591759 if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn;
1760 break :blk Air.Inst.Ref.void_value;
1760 break :blk .void_value;
17611761 },
17621762 .defer_err_code => blk: {
17631763 const inst_data = sema.code.instructions.items(.data)[inst].defer_err_code;
......@@ -1770,7 +1770,7 @@ fn analyzeBodyInner(
17701770 else => |e| return e,
17711771 };
17721772 if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn;
1773 break :blk Air.Inst.Ref.void_value;
1773 break :blk .void_value;
17741774 },
17751775 };
17761776 if (sema.isNoReturn(air_inst)) {
......@@ -2742,7 +2742,7 @@ fn coerceResultPtr(
27422742 if (pointee_ty.eql(Type.null, sema.mod)) {
27432743 const null_inst = Air.internedToRef(Value.null.toIntern());
27442744 _ = try block.addBinOp(.store, new_ptr, null_inst);
2745 return Air.Inst.Ref.void_value;
2745 return .void_value;
27462746 }
27472747 return sema.bitCast(block, ptr_ty, new_ptr, src, null);
27482748 }
......@@ -5520,7 +5520,7 @@ fn zirCompileLog(
55205520 if (!gop.found_existing) {
55215521 gop.value_ptr.* = src_node;
55225522 }
5523 return Air.Inst.Ref.void_value;
5523 return .void_value;
55245524}
55255525
55265526fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
......@@ -5937,7 +5937,7 @@ fn analyzeBlockBody(
59375937
59385938 sema.air_instructions.items(.tag)[br] = .block;
59395939 sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{
5940 .ty = Air.Inst.Ref.noreturn_type,
5940 .ty = .noreturn_type,
59415941 .payload = sema.addExtraAssumeCapacity(Air.Block{
59425942 .body_len = sub_block_len,
59435943 }),
......@@ -6535,7 +6535,7 @@ fn popErrorReturnTrace(
65356535 .tag = .block,
65366536 .data = .{
65376537 .ty_pl = .{
6538 .ty = Air.Inst.Ref.void_type,
6538 .ty = .void_type,
65396539 .payload = undefined, // updated below
65406540 },
65416541 },
......@@ -6552,12 +6552,12 @@ fn popErrorReturnTrace(
65526552 const field_name = try mod.intern_pool.getOrPutString(gpa, "index");
65536553 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);
65546554 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
6555 _ = try then_block.addBr(cond_block_inst, Air.Inst.Ref.void_value);
6555 _ = try then_block.addBr(cond_block_inst, .void_value);
65566556
65576557 // Otherwise, do nothing
65586558 var else_block = block.makeSubBlock();
65596559 defer else_block.instructions.deinit(gpa);
6560 _ = try else_block.addBr(cond_block_inst, Air.Inst.Ref.void_value);
6560 _ = try else_block.addBr(cond_block_inst, .void_value);
65616561
65626562 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len +
65636563 then_block.instructions.items.len + else_block.instructions.items.len +
......@@ -7549,11 +7549,11 @@ fn analyzeCall(
75497549 }
75507550 }
75517551 try sema.safetyPanic(block, call_src, .noreturn_returned);
7552 return Air.Inst.Ref.unreachable_value;
7552 return .unreachable_value;
75537553 }
75547554 if (func_ty_info.return_type == .noreturn_type) {
75557555 _ = try block.addNoOp(.unreach);
7556 return Air.Inst.Ref.unreachable_value;
7556 return .unreachable_value;
75577557 }
75587558 break :res func_inst;
75597559 };
......@@ -7580,7 +7580,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
75807580 });
75817581 }
75827582 _ = try block.addUnOp(.ret, result);
7583 return Air.Inst.Ref.unreachable_value;
7583 return .unreachable_value;
75847584}
75857585
75867586/// Usually, returns null. If an argument was noreturn, returns that ref (which should become the call result).
......@@ -8010,7 +8010,7 @@ fn instantiateGenericCall(
80108010 }
80118011 if (func_ty.fnReturnType(mod).isNoReturn(mod)) {
80128012 _ = try block.addNoOp(.unreach);
8013 return Air.Inst.Ref.unreachable_value;
8013 return .unreachable_value;
80148014 }
80158015 return result;
80168016}
......@@ -8347,7 +8347,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
83478347 return block.addInst(.{
83488348 .tag = .bitcast,
83498349 .data = .{ .ty_op = .{
8350 .ty = Air.Inst.Ref.anyerror_type,
8350 .ty = .anyerror_type,
83518351 .operand = operand,
83528352 } },
83538353 });
......@@ -8384,7 +8384,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
83848384
83858385 // Anything merged with anyerror is anyerror.
83868386 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {
8387 return Air.Inst.Ref.anyerror_type;
8387 return .anyerror_type;
83888388 }
83898389
83908390 if (ip.isInferredErrorSetType(lhs_ty.toIntern())) {
......@@ -10472,7 +10472,7 @@ const SwitchProngAnalysis = struct {
1047210472
1047310473 if (sema.typeOf(capture_ref).isNoReturn(sema.mod)) {
1047410474 // This prong should be unreachable!
10475 return Air.Inst.Ref.unreachable_value;
10475 return .unreachable_value;
1047610476 }
1047710477
1047810478 sema.inst_map.putAssumeCapacity(spa.switch_block_inst, capture_ref);
......@@ -10641,7 +10641,7 @@ const SwitchProngAnalysis = struct {
1064110641 return sema.bitCast(block, ty, spa.operand, operand_src, null);
1064210642 } else {
1064310643 try block.addUnreachable(operand_src, false);
10644 return Air.Inst.Ref.unreachable_value;
10644 return .unreachable_value;
1064510645 },
1064610646 else => return spa.operand,
1064710647 }
......@@ -11771,7 +11771,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1177111771 }
1177211772 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, special.body, operand);
1177311773 if (empty_enum) {
11774 return Air.Inst.Ref.void_value;
11774 return .void_value;
1177511775 }
1177611776
1177711777 return spa.resolveProngComptime(
......@@ -11789,13 +11789,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1178911789
1179011790 if (scalar_cases_len + multi_cases_len == 0 and !special.is_inline) {
1179111791 if (empty_enum) {
11792 return Air.Inst.Ref.void_value;
11792 return .void_value;
1179311793 }
1179411794 if (special_prong == .none) {
1179511795 return sema.fail(block, src, "switch must handle all possibilities", .{});
1179611796 }
1179711797 if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src)) {
11798 return Air.Inst.Ref.unreachable_value;
11798 return .unreachable_value;
1179911799 }
1180011800 if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and
1180111801 (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))
......@@ -12314,8 +12314,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1231412314 special.body,
1231512315 special.capture,
1231612316 .special_capture,
12317 &.{Air.Inst.Ref.bool_true},
12318 Air.Inst.Ref.bool_true,
12317 &.{.bool_true},
12318 .bool_true,
1231912319 special.has_tag_capture,
1232012320 );
1232112321
......@@ -12340,8 +12340,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1234012340 special.body,
1234112341 special.capture,
1234212342 .special_capture,
12343 &.{Air.Inst.Ref.bool_false},
12344 Air.Inst.Ref.bool_false,
12343 &.{.bool_false},
12344 .bool_false,
1234512345 special.has_tag_capture,
1234612346 );
1234712347
......@@ -12901,11 +12901,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1290112901 ty.fmt(mod),
1290212902 });
1290312903 };
12904 if (has_field) {
12905 return Air.Inst.Ref.bool_true;
12906 } else {
12907 return Air.Inst.Ref.bool_false;
12908 }
12904 return if (has_field) .bool_true else .bool_false;
1290912905}
1291012906
1291112907fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -12921,14 +12917,14 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1292112917 try sema.checkNamespaceType(block, lhs_src, container_type);
1292212918
1292312919 const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse
12924 return Air.Inst.Ref.bool_false;
12920 return .bool_false;
1292512921 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| {
1292612922 const decl = mod.declPtr(decl_index);
1292712923 if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) {
12928 return Air.Inst.Ref.bool_true;
12924 return .bool_true;
1292912925 }
1293012926 }
12931 return Air.Inst.Ref.bool_false;
12927 return .bool_false;
1293212928}
1293312929
1293412930fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -15998,7 +15994,7 @@ fn zirAsm(
1599815994 return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{});
1599915995 }
1600015996 try sema.mod.addGlobalAssembly(sema.owner_decl_index, asm_source);
16001 return Air.Inst.Ref.void_value;
15997 return .void_value;
1600215998 }
1600315999
1600416000 if (block.is_comptime) {
......@@ -16145,11 +16141,7 @@ fn zirCmpEq(
1614516141 const rhs_ty_tag = rhs_ty.zigTypeTag(mod);
1614616142 if (lhs_ty_tag == .Null and rhs_ty_tag == .Null) {
1614716143 // null == null, null != null
16148 if (op == .eq) {
16149 return Air.Inst.Ref.bool_true;
16150 } else {
16151 return Air.Inst.Ref.bool_false;
16152 }
16144 return if (op == .eq) .bool_true else .bool_false;
1615316145 }
1615416146
1615516147 // comparing null with optionals
......@@ -16181,11 +16173,10 @@ fn zirCmpEq(
1618116173 }
1618216174 const lkey = mod.intern_pool.indexToKey(lval.toIntern());
1618316175 const rkey = mod.intern_pool.indexToKey(rval.toIntern());
16184 if ((lkey.err.name == rkey.err.name) == (op == .eq)) {
16185 return Air.Inst.Ref.bool_true;
16186 } else {
16187 return Air.Inst.Ref.bool_false;
16188 }
16176 return if ((lkey.err.name == rkey.err.name) == (op == .eq))
16177 .bool_true
16178 else
16179 .bool_false;
1618916180 } else {
1619016181 break :src rhs_src;
1619116182 }
......@@ -16199,11 +16190,7 @@ fn zirCmpEq(
1619916190 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {
1620016191 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);
1620116192 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs);
16202 if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) {
16203 return Air.Inst.Ref.bool_true;
16204 } else {
16205 return Air.Inst.Ref.bool_false;
16206 }
16193 return if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) .bool_true else .bool_false;
1620716194 }
1620816195 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true);
1620916196}
......@@ -16239,7 +16226,7 @@ fn analyzeCmpUnionTag(
1623916226 if (enum_val.isUndef(mod)) return mod.undefRef(Type.bool);
1624016227 const field_ty = union_ty.unionFieldType(enum_val, mod);
1624116228 if (field_ty.zigTypeTag(mod) == .NoReturn) {
16242 return Air.Inst.Ref.bool_false;
16229 return .bool_false;
1624316230 }
1624416231 }
1624516232
......@@ -16347,11 +16334,10 @@ fn cmpSelf(
1634716334 return Air.internedToRef(cmp_val.toIntern());
1634816335 }
1634916336
16350 if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) {
16351 return Air.Inst.Ref.bool_true;
16352 } else {
16353 return Air.Inst.Ref.bool_false;
16354 }
16337 return if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type))
16338 .bool_true
16339 else
16340 .bool_false;
1635516341 } else {
1635616342 if (resolved_type.zigTypeTag(mod) == .Bool) {
1635716343 // We can lower bool eq/neq more efficiently.
......@@ -18000,10 +17986,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1800017986 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1800117987 return if (val.isUndef(mod))
1800217988 mod.undefRef(Type.bool)
18003 else if (val.toBool())
18004 Air.Inst.Ref.bool_false
18005 else
18006 Air.Inst.Ref.bool_true;
17989 else if (val.toBool()) .bool_false else .bool_true;
1800717990 }
1800817991 try sema.requireRuntimeBlock(block, src, null);
1800917992 return block.addTyOp(.not, Type.bool, operand);
......@@ -18029,9 +18012,9 @@ fn zirBoolBr(
1802918012
1803018013 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {
1803118014 if (is_bool_or and lhs_val.toBool()) {
18032 return Air.Inst.Ref.bool_true;
18015 return .bool_true;
1803318016 } else if (!is_bool_or and !lhs_val.toBool()) {
18034 return Air.Inst.Ref.bool_false;
18017 return .bool_false;
1803518018 }
1803618019 // comptime-known left-hand side. No need for a block here; the result
1803718020 // is simply the rhs expression. Here we rely on there only being 1
......@@ -18075,9 +18058,9 @@ fn zirBoolBr(
1807518058 if (!sema.typeOf(rhs_result).isNoReturn(mod)) {
1807618059 if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| {
1807718060 if (is_bool_or and rhs_val.toBool()) {
18078 return Air.Inst.Ref.bool_true;
18061 return .bool_true;
1807918062 } else if (!is_bool_or and !rhs_val.toBool()) {
18080 return Air.Inst.Ref.bool_false;
18063 return .bool_false;
1808118064 }
1808218065 }
1808318066 }
......@@ -19732,7 +19715,7 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1973219715 // generic poison should not result in a failed compilation, but the
1973319716 // generic poison type. This prevents unnecessary failures when
1973419717 // constructing types at compile-time.
19735 error.GenericPoison => return Air.Inst.Ref.generic_poison_type,
19718 error.GenericPoison => return .generic_poison_type,
1973619719 else => |e| return e,
1973719720 };
1973819721 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);
......@@ -20066,16 +20049,16 @@ fn zirReify(
2006620049 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
2006720050 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?;
2006820051 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
20069 .Type => return Air.Inst.Ref.type_type,
20070 .Void => return Air.Inst.Ref.void_type,
20071 .Bool => return Air.Inst.Ref.bool_type,
20072 .NoReturn => return Air.Inst.Ref.noreturn_type,
20073 .ComptimeFloat => return Air.Inst.Ref.comptime_float_type,
20074 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
20075 .Undefined => return Air.Inst.Ref.undefined_type,
20076 .Null => return Air.Inst.Ref.null_type,
20052 .Type => return .type_type,
20053 .Void => return .void_type,
20054 .Bool => return .bool_type,
20055 .NoReturn => return .noreturn_type,
20056 .ComptimeFloat => return .comptime_float_type,
20057 .ComptimeInt => return .comptime_int_type,
20058 .Undefined => return .undefined_type,
20059 .Null => return .null_type,
2007720060 .AnyFrame => return sema.failWithUseOfAsync(block, src),
20078 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
20061 .EnumLiteral => return .enum_literal_type,
2007920062 .Int => {
2008020063 const fields = ip.typeOf(union_val.val).toType().structFields(mod);
2008120064 const signedness_val = try union_val.val.toValue().fieldValue(
......@@ -24566,7 +24549,7 @@ fn zirCUndef(
2456624549
2456724550 const name = try sema.resolveConstString(block, src, extra.operand, "name of macro being undefined must be comptime-known");
2456824551 try block.c_import_buf.?.writer().print("#undef {s}\n", .{name});
24569 return Air.Inst.Ref.void_value;
24552 return .void_value;
2457024553}
2457124554
2457224555fn zirCInclude(
......@@ -24579,7 +24562,7 @@ fn zirCInclude(
2457924562
2458024563 const name = try sema.resolveConstString(block, src, extra.operand, "path being included must be comptime-known");
2458124564 try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name});
24582 return Air.Inst.Ref.void_value;
24565 return .void_value;
2458324566}
2458424567
2458524568fn zirCDefine(
......@@ -24600,7 +24583,7 @@ fn zirCDefine(
2460024583 } else {
2460124584 try block.c_import_buf.?.writer().print("#define {s}\n", .{name});
2460224585 }
24603 return Air.Inst.Ref.void_value;
24586 return .void_value;
2460424587}
2460524588
2460624589fn zirWasmMemorySize(
......@@ -24717,7 +24700,7 @@ fn zirPrefetch(
2471724700 });
2471824701 }
2471924702
24720 return Air.Inst.Ref.void_value;
24703 return .void_value;
2472124704}
2472224705
2472324706fn resolveExternOptions(
......@@ -24902,11 +24885,7 @@ fn zirInComptime(
2490224885 block: *Block,
2490324886) CompileError!Air.Inst.Ref {
2490424887 _ = sema;
24905 if (block.is_comptime) {
24906 return Air.Inst.Ref.bool_true;
24907 } else {
24908 return Air.Inst.Ref.bool_false;
24909 }
24888 return if (block.is_comptime) .bool_true else .bool_false;
2491024889}
2491124890
2491224891fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
......@@ -26723,7 +26702,7 @@ fn unionFieldPtr(
2672326702 }
2672426703 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2672526704 _ = try block.addNoOp(.unreach);
26726 return Air.Inst.Ref.unreachable_value;
26705 return .unreachable_value;
2672726706 }
2672826707 return block.addStructFieldPtr(union_ptr, field_index, ptr_field_ty);
2672926708}
......@@ -26795,7 +26774,7 @@ fn unionFieldVal(
2679526774 }
2679626775 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2679726776 _ = try block.addNoOp(.unreach);
26798 return Air.Inst.Ref.unreachable_value;
26777 return .unreachable_value;
2679926778 }
2680026779 return block.addStructFieldVal(union_byval, field_index, field_ty);
2680126780}
......@@ -31227,14 +31206,10 @@ fn analyzeIsNull(
3122731206 }
3122831207 const is_null = opt_val.isNull(mod);
3122931208 const bool_value = if (invert_logic) !is_null else is_null;
31230 if (bool_value) {
31231 return Air.Inst.Ref.bool_true;
31232 } else {
31233 return Air.Inst.Ref.bool_false;
31234 }
31209 return if (bool_value) .bool_true else .bool_false;
3123531210 }
3123631211
31237 const inverted_non_null_res = if (invert_logic) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
31212 const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false;
3123831213 const operand_ty = sema.typeOf(operand);
3123931214 if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(mod).zigTypeTag(mod) == .NoReturn) {
3124031215 return inverted_non_null_res;
......@@ -31259,14 +31234,14 @@ fn analyzePtrIsNonErrComptimeOnly(
3125931234 const child_ty = ptr_ty.childType(mod);
3126031235
3126131236 const child_tag = child_ty.zigTypeTag(mod);
31262 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return Air.Inst.Ref.bool_true;
31263 if (child_tag == .ErrorSet) return Air.Inst.Ref.bool_false;
31237 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return .bool_true;
31238 if (child_tag == .ErrorSet) return .bool_false;
3126431239 assert(child_tag == .ErrorUnion);
3126531240
3126631241 _ = block;
3126731242 _ = src;
3126831243
31269 return Air.Inst.Ref.none;
31244 return .none;
3127031245}
3127131246
3127231247fn analyzeIsNonErrComptimeOnly(
......@@ -31888,11 +31863,11 @@ fn cmpNumeric(
3188831863 // Compare ints: const vs. undefined (or vice versa)
3188931864 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) {
3189031865 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
31891 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
31866 return if (res) .bool_true else .bool_false;
3189231867 }
3189331868 } else if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef(mod)) {
3189431869 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
31895 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
31870 return if (res) .bool_true else .bool_false;
3189631871 }
3189731872 }
3189831873
......@@ -31900,22 +31875,17 @@ fn cmpNumeric(
3190031875 return mod.undefRef(Type.bool);
3190131876 }
3190231877 if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) {
31903 if (op == std.math.CompareOperator.neq) {
31904 return Air.Inst.Ref.bool_true;
31905 } else {
31906 return Air.Inst.Ref.bool_false;
31907 }
31908 }
31909 if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, mod, sema)) {
31910 return Air.Inst.Ref.bool_true;
31911 } else {
31912 return Air.Inst.Ref.bool_false;
31878 return if (op == std.math.CompareOperator.neq) .bool_true else .bool_false;
3191331879 }
31880 return if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, mod, sema))
31881 .bool_true
31882 else
31883 .bool_false;
3191431884 } else {
3191531885 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) {
3191631886 // Compare ints: const vs. var
3191731887 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
31918 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
31888 return if (res) .bool_true else .bool_false;
3191931889 }
3192031890 }
3192131891 break :src rhs_src;
......@@ -31925,7 +31895,7 @@ fn cmpNumeric(
3192531895 if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) {
3192631896 // Compare ints: var vs. const
3192731897 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
31928 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
31898 return if (res) .bool_true else .bool_false;
3192931899 }
3193031900 }
3193131901 }
......@@ -31992,34 +31962,34 @@ fn cmpNumeric(
3199231962 if (lhs_val.isUndef(mod))
3199331963 return mod.undefRef(Type.bool);
3199431964 if (lhs_val.isNan(mod)) switch (op) {
31995 .neq => return Air.Inst.Ref.bool_true,
31996 else => return Air.Inst.Ref.bool_false,
31965 .neq => return .bool_true,
31966 else => return .bool_false,
3199731967 };
3199831968 if (lhs_val.isInf(mod)) switch (op) {
31999 .neq => return Air.Inst.Ref.bool_true,
32000 .eq => return Air.Inst.Ref.bool_false,
32001 .gt, .gte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
32002 .lt, .lte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
31969 .neq => return .bool_true,
31970 .eq => return .bool_false,
31971 .gt, .gte => return if (lhs_val.isNegativeInf(mod)) .bool_false else .bool_true,
31972 .lt, .lte => return if (lhs_val.isNegativeInf(mod)) .bool_true else .bool_false,
3200331973 };
3200431974 if (!rhs_is_signed) {
3200531975 switch (lhs_val.orderAgainstZero(mod)) {
3200631976 .gt => {},
3200731977 .eq => switch (op) { // LHS = 0, RHS is unsigned
32008 .lte => return Air.Inst.Ref.bool_true,
32009 .gt => return Air.Inst.Ref.bool_false,
31978 .lte => return .bool_true,
31979 .gt => return .bool_false,
3201031980 else => {},
3201131981 },
3201231982 .lt => switch (op) { // LHS < 0, RHS is unsigned
32013 .neq, .lt, .lte => return Air.Inst.Ref.bool_true,
32014 .eq, .gt, .gte => return Air.Inst.Ref.bool_false,
31983 .neq, .lt, .lte => return .bool_true,
31984 .eq, .gt, .gte => return .bool_false,
3201531985 },
3201631986 }
3201731987 }
3201831988 if (lhs_is_float) {
3201931989 if (lhs_val.floatHasFraction(mod)) {
3202031990 switch (op) {
32021 .eq => return Air.Inst.Ref.bool_false,
32022 .neq => return Air.Inst.Ref.bool_true,
31991 .eq => return .bool_false,
31992 .neq => return .bool_true,
3202331993 else => {},
3202431994 }
3202531995 }
......@@ -32050,34 +32020,34 @@ fn cmpNumeric(
3205032020 if (rhs_val.isUndef(mod))
3205132021 return mod.undefRef(Type.bool);
3205232022 if (rhs_val.isNan(mod)) switch (op) {
32053 .neq => return Air.Inst.Ref.bool_true,
32054 else => return Air.Inst.Ref.bool_false,
32023 .neq => return .bool_true,
32024 else => return .bool_false,
3205532025 };
3205632026 if (rhs_val.isInf(mod)) switch (op) {
32057 .neq => return Air.Inst.Ref.bool_true,
32058 .eq => return Air.Inst.Ref.bool_false,
32059 .gt, .gte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
32060 .lt, .lte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
32027 .neq => return .bool_true,
32028 .eq => return .bool_false,
32029 .gt, .gte => return if (rhs_val.isNegativeInf(mod)) .bool_true else .bool_false,
32030 .lt, .lte => return if (rhs_val.isNegativeInf(mod)) .bool_false else .bool_true,
3206132031 };
3206232032 if (!lhs_is_signed) {
3206332033 switch (rhs_val.orderAgainstZero(mod)) {
3206432034 .gt => {},
3206532035 .eq => switch (op) { // RHS = 0, LHS is unsigned
32066 .gte => return Air.Inst.Ref.bool_true,
32067 .lt => return Air.Inst.Ref.bool_false,
32036 .gte => return .bool_true,
32037 .lt => return .bool_false,
3206832038 else => {},
3206932039 },
3207032040 .lt => switch (op) { // RHS < 0, LHS is unsigned
32071 .neq, .gt, .gte => return Air.Inst.Ref.bool_true,
32072 .eq, .lt, .lte => return Air.Inst.Ref.bool_false,
32041 .neq, .gt, .gte => return .bool_true,
32042 .eq, .lt, .lte => return .bool_false,
3207332043 },
3207432044 }
3207532045 }
3207632046 if (rhs_is_float) {
3207732047 if (rhs_val.floatHasFraction(mod)) {
3207832048 switch (op) {
32079 .eq => return Air.Inst.Ref.bool_false,
32080 .neq => return Air.Inst.Ref.bool_true,
32049 .eq => return .bool_false,
32050 .neq => return .bool_true,
3208132051 else => {},
3208232052 }
3208332053 }