authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-12 18:23:40+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-01-09 14:02:34-07:00
log33fe7f28811e91d8801b0bdf7c6b2d776a60a745
treead0a4c40237b8d2bb28909f98888d571ca601207
parent568a61925187a96176d1e45a5a8ffee39c121cce

Sema: remove `block` and `src` parameters from `getBuiltin`

These parameters are only ever needed when `std.builtin` is out of sync with the compiler in which case panicking is the only valid operation anyways. Removing them causes a domino effect of functions no longer needing a `src` and/or a `block` parameter resulting in handling compilation errors where they are actually meaningful becoming simpler.

4 files changed, 840 insertions(+), 982 deletions(-)

src/Module.zig+9-27
......@@ -224,12 +224,6 @@ const MonomorphedFuncsContext = struct {
224224 }
225225};
226226
227pub const WipAnalysis = struct {
228 sema: *Sema,
229 block: *Sema.Block,
230 src: Module.LazySrcLoc,
231};
232
233227pub const MemoizedCallSet = std.HashMapUnmanaged(
234228 MemoizedCall.Key,
235229 MemoizedCall.Result,
......@@ -4642,7 +4636,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
46424636 // Note this resolves the type of the Decl, not the value; if this Decl
46434637 // is a struct, for example, this resolves `type` (which needs no resolution),
46444638 // not the struct itself.
4645 try sema.resolveTypeLayout(&block_scope, ty_src, decl_tv.ty);
4639 try sema.resolveTypeLayout(decl_tv.ty);
46464640
46474641 const decl_arena_state = try decl_arena_allocator.create(std.heap.ArenaAllocator.State);
46484642
......@@ -4810,14 +4804,14 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
48104804 decl.generation = mod.generation;
48114805
48124806 const has_runtime_bits = is_extern or
4813 (queue_linker_work and try sema.typeHasRuntimeBits(&block_scope, ty_src, decl.ty));
4807 (queue_linker_work and try sema.typeHasRuntimeBits(decl.ty));
48144808
48154809 if (has_runtime_bits) {
48164810 log.debug("queue linker work for {*} ({s})", .{ decl, decl.name });
48174811
48184812 // Needed for codegen_decl which will call updateDecl and then the
48194813 // codegen backend wants full access to the Decl Type.
4820 try sema.resolveTypeFully(&block_scope, ty_src, decl.ty);
4814 try sema.resolveTypeFully(decl.ty);
48214815
48224816 try mod.comp.bin_file.allocateDeclIndexes(decl_index);
48234817 try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
......@@ -5586,21 +5580,10 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
55865580 var runtime_param_index: usize = 0;
55875581 var total_param_index: usize = 0;
55885582 for (fn_info.param_body) |inst| {
5589 const param: struct { name: u32, src: LazySrcLoc } = switch (zir_tags[inst]) {
5590 .param, .param_comptime => blk: {
5591 const pl_tok = sema.code.instructions.items(.data)[inst].pl_tok;
5592 const extra = sema.code.extraData(Zir.Inst.Param, pl_tok.payload_index).data;
5593 break :blk .{ .name = extra.name, .src = pl_tok.src() };
5594 },
5595
5596 .param_anytype, .param_anytype_comptime => blk: {
5597 const str_tok = sema.code.instructions.items(.data)[inst].str_tok;
5598 break :blk .{ .name = str_tok.start, .src = str_tok.src() };
5599 },
5600
5583 switch (zir_tags[inst]) {
5584 .param, .param_comptime, .param_anytype, .param_anytype_comptime => {},
56015585 else => continue,
5602 };
5603
5586 }
56045587 const param_ty = if (func.comptime_args) |comptime_args| t: {
56055588 const arg_tv = comptime_args[total_param_index];
56065589
......@@ -5617,7 +5600,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
56175600 continue;
56185601 } else fn_ty_info.param_types[runtime_param_index];
56195602
5620 const opt_opv = sema.typeHasOnePossibleValue(&inner_block, param.src, param_ty) catch |err| switch (err) {
5603 const opt_opv = sema.typeHasOnePossibleValue(param_ty) catch |err| switch (err) {
56215604 error.NeededSourceLocation => unreachable,
56225605 error.GenericPoison => unreachable,
56235606 error.ComptimeReturn => unreachable,
......@@ -5707,8 +5690,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
57075690 // Crucially, this happens *after* we set the function state to success above,
57085691 // so that dependencies on the function body will now be satisfied rather than
57095692 // result in circular dependency errors.
5710 const src = LazySrcLoc.nodeOffset(0);
5711 sema.resolveFnTypes(&inner_block, src, fn_ty_info) catch |err| switch (err) {
5693 sema.resolveFnTypes(fn_ty_info) catch |err| switch (err) {
57125694 error.NeededSourceLocation => unreachable,
57135695 error.GenericPoison => unreachable,
57145696 error.ComptimeReturn => unreachable,
......@@ -5726,7 +5708,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
57265708 // the backends.
57275709 for (sema.types_to_resolve.items) |inst_ref| {
57285710 const ty = sema.getTmpAir().getRefType(inst_ref);
5729 sema.resolveTypeFully(&inner_block, src, ty) catch |err| switch (err) {
5711 sema.resolveTypeFully(ty) catch |err| switch (err) {
57305712 error.NeededSourceLocation => unreachable,
57315713 error.GenericPoison => unreachable,
57325714 error.ComptimeReturn => unreachable,
src/Sema.zig+697-823
......@@ -195,7 +195,7 @@ pub const Block = struct {
195195 try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{});
196196 },
197197 .comptime_ret_ty => |rt| {
198 const src_loc = if (try sema.funcDeclSrc(rt.block, rt.func_src, rt.func)) |capture| blk: {
198 const src_loc = if (try sema.funcDeclSrc(rt.func)) |capture| blk: {
199199 var src_loc = capture;
200200 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };
201201 break :blk src_loc;
......@@ -579,10 +579,9 @@ pub const Block = struct {
579579 }
580580 }
581581
582 pub fn startAnonDecl(block: *Block, src: LazySrcLoc) !WipAnonDecl {
582 pub fn startAnonDecl(block: *Block) !WipAnonDecl {
583583 return WipAnonDecl{
584584 .block = block,
585 .src = src,
586585 .new_decl_arena = std.heap.ArenaAllocator.init(block.sema.gpa),
587586 .finished = false,
588587 };
......@@ -590,7 +589,6 @@ pub const Block = struct {
590589
591590 pub const WipAnonDecl = struct {
592591 block: *Block,
593 src: LazySrcLoc,
594592 new_decl_arena: std.heap.ArenaAllocator,
595593 finished: bool,
596594
......@@ -610,7 +608,7 @@ pub const Block = struct {
610608 const sema = wad.block.sema;
611609 // Do this ahead of time because `createAnonymousDecl` depends on calling
612610 // `type.hasRuntimeBits()`.
613 _ = try sema.typeHasRuntimeBits(wad.block, wad.src, ty);
611 _ = try sema.typeHasRuntimeBits(ty);
614612 const new_decl_index = try sema.mod.createAnonymousDecl(wad.block, .{
615613 .ty = ty,
616614 .val = val,
......@@ -995,7 +993,7 @@ fn analyzeBodyInner(
995993 .shl_exact => try sema.zirShl(block, inst, .shl_exact),
996994 .shl_sat => try sema.zirShl(block, inst, .shl_sat),
997995
998 .ret_ptr => try sema.zirRetPtr(block, inst),
996 .ret_ptr => try sema.zirRetPtr(block),
999997 .ret_type => try sema.addType(sema.fn_ret_ty),
1000998
1001999 // Instructions that we know to *always* be noreturn based solely on their tag.
......@@ -1023,7 +1021,7 @@ fn analyzeBodyInner(
10231021 .this => try sema.zirThis( block, extended),
10241022 .ret_addr => try sema.zirRetAddr( block, extended),
10251023 .builtin_src => try sema.zirBuiltinSrc( block, extended),
1026 .error_return_trace => try sema.zirErrorReturnTrace( block, extended),
1024 .error_return_trace => try sema.zirErrorReturnTrace( block),
10271025 .frame => try sema.zirFrame( block, extended),
10281026 .frame_address => try sema.zirFrameAddress( block, extended),
10291027 .alloc => try sema.zirAllocExtended( block, extended),
......@@ -1031,7 +1029,7 @@ fn analyzeBodyInner(
10311029 .@"asm" => try sema.zirAsm( block, extended, false),
10321030 .asm_expr => try sema.zirAsm( block, extended, true),
10331031 .typeof_peer => try sema.zirTypeofPeer( block, extended),
1034 .compile_log => try sema.zirCompileLog( block, extended),
1032 .compile_log => try sema.zirCompileLog( extended),
10351033 .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),
10361034 .sub_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),
10371035 .mul_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),
......@@ -1746,8 +1744,8 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
17461744 const addrs_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, addr_arr_ty));
17471745
17481746 // var st: StackTrace = undefined;
1749 const unresolved_stack_trace_ty = try sema.getBuiltinType(&err_trace_block, src, "StackTrace");
1750 const stack_trace_ty = try sema.resolveTypeFields(&err_trace_block, src, unresolved_stack_trace_ty);
1747 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
1748 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
17511749 const st_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty));
17521750
17531751 // st.instruction_addresses = &addrs;
......@@ -1774,7 +1772,7 @@ fn resolveValue(
17741772 air_ref: Air.Inst.Ref,
17751773 reason: []const u8,
17761774) CompileError!Value {
1777 if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| {
1775 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
17781776 if (val.tag() == .generic_poison) return error.GenericPoison;
17791777 return val;
17801778 }
......@@ -1790,7 +1788,7 @@ fn resolveConstMaybeUndefVal(
17901788 inst: Air.Inst.Ref,
17911789 reason: []const u8,
17921790) CompileError!Value {
1793 if (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) |val| {
1791 if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| {
17941792 switch (val.tag()) {
17951793 .variable => return sema.failWithNeededComptime(block, src, reason),
17961794 .generic_poison => return error.GenericPoison,
......@@ -1809,7 +1807,7 @@ fn resolveConstValue(
18091807 air_ref: Air.Inst.Ref,
18101808 reason: []const u8,
18111809) CompileError!Value {
1812 if (try sema.resolveMaybeUndefValAllowVariables(block, src, air_ref)) |val| {
1810 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
18131811 switch (val.tag()) {
18141812 .undef => return sema.failWithUseOfUndef(block, src),
18151813 .variable => return sema.failWithNeededComptime(block, src, reason),
......@@ -1828,7 +1826,7 @@ fn resolveDefinedValue(
18281826 src: LazySrcLoc,
18291827 air_ref: Air.Inst.Ref,
18301828) CompileError!?Value {
1831 if (try sema.resolveMaybeUndefVal(block, src, air_ref)) |val| {
1829 if (try sema.resolveMaybeUndefVal(air_ref)) |val| {
18321830 if (val.isUndef()) {
18331831 if (block.is_typeof) return null;
18341832 return sema.failWithUseOfUndef(block, src);
......@@ -1843,11 +1841,9 @@ fn resolveDefinedValue(
18431841/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
18441842fn resolveMaybeUndefVal(
18451843 sema: *Sema,
1846 block: *Block,
1847 src: LazySrcLoc,
18481844 inst: Air.Inst.Ref,
18491845) CompileError!?Value {
1850 const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) orelse return null;
1846 const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null;
18511847 switch (val.tag()) {
18521848 .variable => return null,
18531849 .generic_poison => return error.GenericPoison,
......@@ -1861,11 +1857,9 @@ fn resolveMaybeUndefVal(
18611857/// Value Tag `decl_ref` and `decl_ref_mut` or any nested such value results in `null`.
18621858fn resolveMaybeUndefValIntable(
18631859 sema: *Sema,
1864 block: *Block,
1865 src: LazySrcLoc,
18661860 inst: Air.Inst.Ref,
18671861) CompileError!?Value {
1868 const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, inst)) orelse return null;
1862 const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null;
18691863 var check = val;
18701864 while (true) switch (check.tag()) {
18711865 .variable, .decl_ref, .decl_ref_mut, .comptime_field_ptr => return null,
......@@ -1874,21 +1868,16 @@ fn resolveMaybeUndefValIntable(
18741868 .eu_payload_ptr, .opt_payload_ptr => check = check.cast(Value.Payload.PayloadPtr).?.data.container_ptr,
18751869 .generic_poison => return error.GenericPoison,
18761870 else => {
1877 try sema.resolveLazyValue(block, src, val);
1871 try sema.resolveLazyValue(val);
18781872 return val;
18791873 },
18801874 };
18811875}
18821876
18831877/// Returns all Value tags including `variable` and `undef`.
1884fn resolveMaybeUndefValAllowVariables(
1885 sema: *Sema,
1886 block: *Block,
1887 src: LazySrcLoc,
1888 inst: Air.Inst.Ref,
1889) CompileError!?Value {
1878fn resolveMaybeUndefValAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
18901879 var make_runtime = false;
1891 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, src, inst, &make_runtime)) |val| {
1880 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(inst, &make_runtime)) |val| {
18921881 if (make_runtime) return null;
18931882 return val;
18941883 }
......@@ -1898,8 +1887,6 @@ fn resolveMaybeUndefValAllowVariables(
18981887/// Returns all Value tags including `variable`, `undef` and `runtime_value`.
18991888fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
19001889 sema: *Sema,
1901 block: *Block,
1902 src: LazySrcLoc,
19031890 inst: Air.Inst.Ref,
19041891 make_runtime: *bool,
19051892) CompileError!?Value {
......@@ -1910,7 +1897,7 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
19101897 }
19111898 i -= Air.Inst.Ref.typed_value_map.len;
19121899
1913 if (try sema.typeHasOnePossibleValue(block, src, sema.typeOf(inst))) |opv| {
1900 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
19141901 return opv;
19151902 }
19161903 const air_tags = sema.air_instructions.items(.tag);
......@@ -2209,7 +2196,7 @@ pub fn resolveAlign(
22092196 zir_ref: Zir.Inst.Ref,
22102197) !u32 {
22112198 const air_ref = try sema.resolveInst(zir_ref);
2212 return analyzeAsAlign(sema, block, src, air_ref);
2199 return sema.analyzeAsAlign(block, src, air_ref);
22132200}
22142201
22152202fn resolveInt(
......@@ -2221,7 +2208,7 @@ fn resolveInt(
22212208 reason: []const u8,
22222209) !u64 {
22232210 const air_ref = try sema.resolveInst(zir_ref);
2224 return analyzeAsInt(sema, block, src, air_ref, dest_ty, reason);
2211 return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason);
22252212}
22262213
22272214fn analyzeAsInt(
......@@ -2235,7 +2222,7 @@ fn analyzeAsInt(
22352222 const coerced = try sema.coerce(block, dest_ty, air_ref, src);
22362223 const val = try sema.resolveConstValue(block, src, coerced, reason);
22372224 const target = sema.mod.getTarget();
2238 return (try val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?;
2225 return (try val.getUnsignedIntAdvanced(target, sema)).?;
22392226}
22402227
22412228// Returns a compile error if the value has tag `variable`. See `resolveInstValue` for
......@@ -2317,7 +2304,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
23172304 const iac = ptr_val.castTag(.inferred_alloc_comptime).?;
23182305 // There will be only one coerce_result_ptr because we are running at comptime.
23192306 // The alloc will turn into a Decl.
2320 var anon_decl = try block.startAnonDecl(src);
2307 var anon_decl = try block.startAnonDecl();
23212308 defer anon_decl.deinit();
23222309 iac.data.decl_index = try anon_decl.finish(
23232310 try pointee_ty.copy(anon_decl.arena()),
......@@ -2325,7 +2312,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
23252312 iac.data.alignment,
23262313 );
23272314 if (iac.data.alignment != 0) {
2328 try sema.resolveTypeLayout(block, src, pointee_ty);
2315 try sema.resolveTypeLayout(pointee_ty);
23292316 }
23302317 const ptr_ty = try Type.ptr(sema.arena, sema.mod, .{
23312318 .pointee_type = pointee_ty,
......@@ -2355,7 +2342,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
23552342
23562343 const dummy_ptr = try trash_block.addTy(.alloc, sema.typeOf(ptr));
23572344 const dummy_operand = try trash_block.addBitCast(pointee_ty, .void_value);
2358 return coerceResultPtr(sema, block, src, ptr, dummy_ptr, dummy_operand, &trash_block);
2345 return sema.coerceResultPtr(block, src, ptr, dummy_ptr, dummy_operand, &trash_block);
23592346}
23602347
23612348fn coerceResultPtr(
......@@ -2386,7 +2373,7 @@ fn coerceResultPtr(
23862373 const trash_inst = trash_block.instructions.items[trash_block.instructions.items.len - 1];
23872374 if (air_tags[trash_inst] != .store) {
23882375 // no store instruction is generated for zero sized types
2389 assert((try sema.typeHasOnePossibleValue(block, src, pointee_ty)) != null);
2376 assert((try sema.typeHasOnePossibleValue(pointee_ty)) != null);
23902377 } else {
23912378 trash_block.instructions.items.len -= 1;
23922379 assert(trash_inst == sema.air_instructions.len - 1);
......@@ -2876,7 +2863,7 @@ fn zirEnumDecl(
28762863 }
28772864 } else if (any_values) {
28782865 const tag_val = if (last_tag_val) |val|
2879 try sema.intAdd(block, src, val, Value.one, enum_obj.tag_ty)
2866 try sema.intAdd(val, Value.one, enum_obj.tag_ty)
28802867 else
28812868 Value.zero;
28822869 last_tag_val = tag_val;
......@@ -2905,7 +2892,7 @@ fn zirEnumDecl(
29052892 last_tag_val = Value.initPayload(&tag_val_buf.base);
29062893 }
29072894
2908 if (!(try sema.intFitsInType(block, src, last_tag_val.?, enum_obj.tag_ty, null))) {
2895 if (!(try sema.intFitsInType(last_tag_val.?, enum_obj.tag_ty, null))) {
29092896 const tree = try sema.getAstTree(block);
29102897 const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i);
29112898 const msg = try sema.errMsg(block, field_src, "enumeration value '{}' too large for type '{}'", .{
......@@ -3113,16 +3100,13 @@ fn zirErrorSetDecl(
31133100 return sema.analyzeDeclVal(block, src, new_decl_index);
31143101}
31153102
3116fn zirRetPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3103fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
31173104 const tracy = trace(@src());
31183105 defer tracy.end();
31193106
3120 const inst_data = sema.code.instructions.items(.data)[inst].node;
3121 const src = LazySrcLoc.nodeOffset(inst_data);
3122
31233107 if (block.is_comptime or try sema.typeRequiresComptime(sema.fn_ret_ty)) {
3124 const fn_ret_ty = try sema.resolveTypeFields(block, src, sema.fn_ret_ty);
3125 return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0, src);
3108 const fn_ret_ty = try sema.resolveTypeFields(sema.fn_ret_ty);
3109 return sema.analyzeComptimeAlloc(block, fn_ret_ty, 0);
31263110 }
31273111
31283112 const target = sema.mod.getTarget();
......@@ -3287,7 +3271,6 @@ fn zirAllocExtended(
32873271 extended: Zir.Inst.Extended.InstData,
32883272) CompileError!Air.Inst.Ref {
32893273 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
3290 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
32913274 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
32923275 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };
32933276 const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small);
......@@ -3314,7 +3297,7 @@ fn zirAllocExtended(
33143297
33153298 if (block.is_comptime or small.is_comptime) {
33163299 if (small.has_type) {
3317 return sema.analyzeComptimeAlloc(block, var_ty, alignment, ty_src);
3300 return sema.analyzeComptimeAlloc(block, var_ty, alignment);
33183301 } else {
33193302 return sema.addConstant(
33203303 inferred_alloc_ty,
......@@ -3331,7 +3314,7 @@ fn zirAllocExtended(
33313314 try sema.validateVarType(block, ty_src, var_ty, false);
33323315 }
33333316 const target = sema.mod.getTarget();
3334 try sema.resolveTypeLayout(block, src, var_ty);
3317 try sema.resolveTypeLayout(var_ty);
33353318 const ptr_type = try Type.ptr(sema.arena, sema.mod, .{
33363319 .pointee_type = var_ty,
33373320 .@"align" = alignment,
......@@ -3360,12 +3343,11 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
33603343 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
33613344 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
33623345 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
3363 return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src);
3346 return sema.analyzeComptimeAlloc(block, var_ty, 0);
33643347}
33653348
33663349fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
33673350 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
3368 const src = inst_data.src();
33693351 const alloc = try sema.resolveInst(inst_data.operand);
33703352 const alloc_ty = sema.typeOf(alloc);
33713353
......@@ -3406,13 +3388,13 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
34063388 }
34073389
34083390 const store_op = air_datas[store_inst].bin_op;
3409 const store_val = (try sema.resolveMaybeUndefVal(block, src, store_op.rhs)) orelse break :ct;
3391 const store_val = (try sema.resolveMaybeUndefVal(store_op.rhs)) orelse break :ct;
34103392 if (store_op.lhs != alloc) break :ct;
34113393
34123394 // Remove all the unnecessary runtime instructions.
34133395 block.instructions.shrinkRetainingCapacity(search_index);
34143396
3415 var anon_decl = try block.startAnonDecl(src);
3397 var anon_decl = try block.startAnonDecl();
34163398 defer anon_decl.deinit();
34173399 return sema.analyzeDeclRef(try anon_decl.finish(
34183400 try elem_ty.copy(anon_decl.arena()),
......@@ -3425,7 +3407,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
34253407 const const_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);
34263408
34273409 // Detect if a comptime value simply needs to have its type changed.
3428 if (try sema.resolveMaybeUndefVal(block, inst_data.src(), alloc)) |val| {
3410 if (try sema.resolveMaybeUndefVal(alloc)) |val| {
34293411 return sema.addConstant(const_ptr_ty, val);
34303412 }
34313413
......@@ -3457,7 +3439,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
34573439 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
34583440 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
34593441 if (block.is_comptime) {
3460 return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src);
3442 return sema.analyzeComptimeAlloc(block, var_ty, 0);
34613443 }
34623444 const target = sema.mod.getTarget();
34633445 const ptr_type = try Type.ptr(sema.arena, sema.mod, .{
......@@ -3476,7 +3458,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
34763458 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
34773459 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
34783460 if (block.is_comptime) {
3479 return sema.analyzeComptimeAlloc(block, var_ty, 0, ty_src);
3461 return sema.analyzeComptimeAlloc(block, var_ty, 0);
34803462 }
34813463 try sema.validateVarType(block, ty_src, var_ty, false);
34823464 const target = sema.mod.getTarget();
......@@ -3641,12 +3623,12 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
36413623 } else unreachable; // TODO shouldn't need this
36423624
36433625 const store_op = air_datas[store_inst].bin_op;
3644 const store_val = (try sema.resolveMaybeUndefVal(block, src, store_op.rhs)) orelse break :ct;
3626 const store_val = (try sema.resolveMaybeUndefVal(store_op.rhs)) orelse break :ct;
36453627 if (store_op.lhs != Air.indexToRef(bitcast_inst)) break :ct;
36463628 if (air_datas[bitcast_inst].ty_op.operand != Air.indexToRef(const_inst)) break :ct;
36473629
36483630 const new_decl_index = d: {
3649 var anon_decl = try block.startAnonDecl(src);
3631 var anon_decl = try block.startAnonDecl();
36503632 defer anon_decl.deinit();
36513633 const new_decl_index = try anon_decl.finish(
36523634 try final_elem_ty.copy(anon_decl.arena()),
......@@ -3668,7 +3650,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
36683650 // Unless the block is comptime, `alloc_inferred` always produces
36693651 // a runtime constant. The final inferred type needs to be
36703652 // fully resolved so it can be lowered in codegen.
3671 try sema.resolveTypeFully(block, ty_src, final_elem_ty);
3653 try sema.resolveTypeFully(final_elem_ty);
36723654
36733655 return;
36743656 }
......@@ -3714,7 +3696,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
37143696 defer bitcast_block.instructions.deinit(gpa);
37153697
37163698 trash_block.instructions.shrinkRetainingCapacity(empty_trash_count);
3717 const sub_ptr = try coerceResultPtr(sema, &bitcast_block, src, ptr, dummy_ptr, peer_inst_list[i], &trash_block);
3699 const sub_ptr = try sema.coerceResultPtr(&bitcast_block, src, ptr, dummy_ptr, peer_inst_list[i], &trash_block);
37183700
37193701 assert(bitcast_block.instructions.items.len > 0);
37203702 // If only one instruction is produced then we can replace the bitcast
......@@ -3997,7 +3979,7 @@ fn validateUnionInit(
39973979 } else {
39983980 first_block_index = @min(first_block_index, block_index);
39993981 }
4000 init_val = try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, init_src, bin_op.rhs, &make_runtime);
3982 init_val = try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime);
40013983 break;
40023984 }
40033985
......@@ -4073,7 +4055,7 @@ fn validateStructInit(
40734055 if ((is_comptime or block.is_comptime) and
40744056 (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null)
40754057 {
4076 try sema.resolveStructLayout(block, init_src, struct_ty);
4058 try sema.resolveStructLayout(struct_ty);
40774059 // In this case the only thing we need to do is evaluate the implicit
40784060 // store instructions for default field values, and report any missing fields.
40794061 // Avoid the cost of the extra machinery for detecting a comptime struct init value.
......@@ -4143,12 +4125,9 @@ fn validateStructInit(
41434125
41444126 field: for (found_fields) |field_ptr, i| {
41454127 if (field_ptr != 0) {
4146 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
4147 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
4148
41494128 // Determine whether the value stored to this pointer is comptime-known.
41504129 const field_ty = struct_ty.structFieldType(i);
4151 if (try sema.typeHasOnePossibleValue(block, field_src, field_ty)) |opv| {
4130 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {
41524131 field_values[i] = opv;
41534132 continue;
41544133 }
......@@ -4210,7 +4189,7 @@ fn validateStructInit(
42104189 } else {
42114190 first_block_index = @min(first_block_index, block_index);
42124191 }
4213 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, field_src, bin_op.rhs, &make_runtime)) |val| {
4192 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
42144193 field_values[i] = val;
42154194 } else {
42164195 struct_is_comptime = false;
......@@ -4271,7 +4250,7 @@ fn validateStructInit(
42714250 try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store);
42724251 return;
42734252 }
4274 try sema.resolveStructLayout(block, init_src, struct_ty);
4253 try sema.resolveStructLayout(struct_ty);
42754254
42764255 // Our task is to insert `store` instructions for all the default field values.
42774256 for (found_fields) |field_ptr, i| {
......@@ -4352,14 +4331,11 @@ fn zirValidateArrayInit(
43524331 // being comptime-known.
43534332 const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel());
43544333 const element_vals = try sema.arena.alloc(Value, array_len_s);
4355 const opt_opv = try sema.typeHasOnePossibleValue(block, init_src, array_ty);
4334 const opt_opv = try sema.typeHasOnePossibleValue(array_ty);
43564335 const air_tags = sema.air_instructions.items(.tag);
43574336 const air_datas = sema.air_instructions.items(.data);
43584337
43594338 outer: for (instrs) |elem_ptr, i| {
4360 const elem_ptr_data = sema.code.instructions.items(.data)[elem_ptr].pl_node;
4361 const elem_src = LazySrcLoc.nodeOffset(elem_ptr_data.src_node);
4362
43634339 // Determine whether the value stored to this pointer is comptime-known.
43644340
43654341 if (array_ty.isTuple()) {
......@@ -4427,7 +4403,7 @@ fn zirValidateArrayInit(
44274403 } else {
44284404 first_block_index = @min(first_block_index, block_index);
44294405 }
4430 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(block, elem_src, bin_op.rhs, &make_runtime)) |val| {
4406 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
44314407 element_vals[i] = val;
44324408 } else {
44334409 array_is_comptime = false;
......@@ -4465,7 +4441,6 @@ fn zirValidateArrayInit(
44654441fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
44664442 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
44674443 const src = inst_data.src();
4468 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
44694444 const operand = try sema.resolveInst(inst_data.operand);
44704445 const operand_ty = sema.typeOf(operand);
44714446
......@@ -4478,11 +4453,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
44784453 }
44794454
44804455 const elem_ty = operand_ty.elemType2();
4481 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
4456 if (try sema.resolveMaybeUndefVal(operand)) |val| {
44824457 if (val.isUndef()) {
44834458 return sema.fail(block, src, "cannot dereference undefined value", .{});
44844459 }
4485 } else if (!(try sema.validateRunTimeType(block, src, elem_ty, false))) {
4460 } else if (!(try sema.validateRunTimeType(elem_ty, false))) {
44864461 const msg = msg: {
44874462 const msg = try sema.errMsg(
44884463 block,
......@@ -4689,9 +4664,9 @@ fn storeToInferredAllocComptime(
46894664 const operand_ty = sema.typeOf(operand);
46904665 // There will be only one store_to_inferred_ptr because we are running at comptime.
46914666 // The alloc will turn into a Decl.
4692 if (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) |operand_val| store: {
4667 if (try sema.resolveMaybeUndefValAllowVariables(operand)) |operand_val| store: {
46934668 if (operand_val.tag() == .variable) break :store;
4694 var anon_decl = try block.startAnonDecl(src);
4669 var anon_decl = try block.startAnonDecl();
46954670 defer anon_decl.deinit();
46964671 iac.data.decl_index = try anon_decl.finish(
46974672 try operand_ty.copy(anon_decl.arena()),
......@@ -4788,7 +4763,7 @@ fn addStrLit(sema: *Sema, block: *Block, zir_bytes: []const u8) CompileError!Air
47884763 gop.value_ptr.* = .none;
47894764 }
47904765 const decl_index = gop.value_ptr.unwrap() orelse di: {
4791 var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded);
4766 var anon_decl = try block.startAnonDecl();
47924767 defer anon_decl.deinit();
47934768
47944769 const decl_index = try anon_decl.finish(
......@@ -4869,7 +4844,6 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
48694844
48704845fn zirCompileLog(
48714846 sema: *Sema,
4872 block: *Block,
48734847 extended: Zir.Inst.Extended.InstData,
48744848) CompileError!Air.Inst.Ref {
48754849 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
......@@ -4878,7 +4852,6 @@ fn zirCompileLog(
48784852
48794853 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
48804854 const src_node = extra.data.src_node;
4881 const src = LazySrcLoc.nodeOffset(src_node);
48824855 const args = sema.code.refSlice(extra.end, extended.small);
48834856
48844857 for (args) |arg_ref, i| {
......@@ -4886,8 +4859,8 @@ fn zirCompileLog(
48864859
48874860 const arg = try sema.resolveInst(arg_ref);
48884861 const arg_ty = sema.typeOf(arg);
4889 if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| {
4890 try sema.resolveLazyValue(block, src, val);
4862 if (try sema.resolveMaybeUndefVal(arg)) |val| {
4863 try sema.resolveLazyValue(val);
48914864 try writer.print("@as({}, {})", .{
48924865 arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod),
48934866 });
......@@ -5207,7 +5180,7 @@ fn analyzeBlockBody(
52075180 // TODO add note "missing else causes void value"
52085181
52095182 const type_src = src; // TODO: better source location
5210 const valid_rt = try sema.validateRunTimeType(child_block, type_src, resolved_ty, false);
5183 const valid_rt = try sema.validateRunTimeType(resolved_ty, false);
52115184 if (!valid_rt) {
52125185 const msg = msg: {
52135186 const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)});
......@@ -5352,7 +5325,7 @@ pub fn analyzeExport(
53525325 try mod.ensureDeclAnalyzed(exported_decl_index);
53535326 const exported_decl = mod.declPtr(exported_decl_index);
53545327
5355 if (!try sema.validateExternType(block, src, exported_decl.ty, .other)) {
5328 if (!try sema.validateExternType(exported_decl.ty, .other)) {
53565329 const msg = msg: {
53575330 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(sema.mod)});
53585331 errdefer msg.destroy(sema.gpa);
......@@ -5581,10 +5554,10 @@ fn addDbgVar(
55815554 const operand_ty = sema.typeOf(operand);
55825555 switch (air_tag) {
55835556 .dbg_var_ptr => {
5584 if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty.childType()))) return;
5557 if (!(try sema.typeHasRuntimeBits(operand_ty.childType()))) return;
55855558 },
55865559 .dbg_var_val => {
5587 if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return;
5560 if (!(try sema.typeHasRuntimeBits(operand_ty))) return;
55885561 },
55895562 else => unreachable,
55905563 }
......@@ -5746,8 +5719,8 @@ fn lookupInNamespace(
57465719 return null;
57475720}
57485721
5749fn funcDeclSrc(sema: *Sema, block: *Block, src: LazySrcLoc, func_inst: Air.Inst.Ref) !?Module.SrcLoc {
5750 const func_val = (try sema.resolveMaybeUndefVal(block, src, func_inst)) orelse return null;
5722fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?Module.SrcLoc {
5723 const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null;
57515724 if (func_val.isUndef()) return null;
57525725 const owner_decl_index = switch (func_val.tag()) {
57535726 .extern_fn => func_val.castTag(.extern_fn).?.data.owner_decl,
......@@ -5769,11 +5742,11 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
57695742 if (block.is_comptime)
57705743 return .none;
57715744
5772 const unresolved_stack_trace_ty = sema.getBuiltinType(block, src, "StackTrace") catch |err| switch (err) {
5745 const unresolved_stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) {
57735746 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
57745747 else => |e| return e,
57755748 };
5776 const stack_trace_ty = sema.resolveTypeFields(block, src, unresolved_stack_trace_ty) catch |err| switch (err) {
5749 const stack_trace_ty = sema.resolveTypeFields(unresolved_stack_trace_ty) catch |err| switch (err) {
57775750 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
57785751 else => |e| return e,
57795752 };
......@@ -5812,8 +5785,8 @@ fn popErrorReturnTrace(
58125785 // AstGen determined this result does not go to an error-handling expr (try/catch/return etc.), or
58135786 // the result is comptime-known to be a non-error. Either way, pop unconditionally.
58145787
5815 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
5816 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
5788 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
5789 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
58175790 const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty);
58185791 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);
58195792 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, "index", src, stack_trace_ty, true);
......@@ -5837,8 +5810,8 @@ fn popErrorReturnTrace(
58375810 defer then_block.instructions.deinit(sema.gpa);
58385811
58395812 // If non-error, then pop the error return trace by restoring the index.
5840 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
5841 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
5813 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
5814 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
58425815 const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty);
58435816 const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty);
58445817 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, "index", src, stack_trace_ty, true);
......@@ -5934,7 +5907,7 @@ fn zirCall(
59345907 break :check_args;
59355908 }
59365909
5937 const decl_src = try sema.funcDeclSrc(block, func_src, func);
5910 const decl_src = try sema.funcDeclSrc(func);
59385911 const member_str = if (bound_arg_src != null) "member function " else "";
59395912 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";
59405913 const msg = msg: {
......@@ -6017,8 +5990,8 @@ fn zirCall(
60175990 // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only
60185991 // need to clean-up our own trace if we were passed to a non-error-handling expression.
60195992 if (input_is_error or (pop_error_return_trace and modifier != .always_tail and return_ty.isError())) {
6020 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, call_src, "StackTrace");
6021 const stack_trace_ty = try sema.resolveTypeFields(block, call_src, unresolved_stack_trace_ty);
5993 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
5994 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
60225995 const field_index = try sema.structFieldIndex(block, stack_trace_ty, "index", call_src);
60235996
60245997 // Insert a save instruction before the arg resolution + call instructions we just generated
......@@ -6145,7 +6118,7 @@ fn analyzeCall(
61456118 const func_ty_info = func_ty.fnInfo();
61466119 const cc = func_ty_info.cc;
61476120 if (cc == .Naked) {
6148 const decl_src = try sema.funcDeclSrc(block, func_src, func);
6121 const decl_src = try sema.funcDeclSrc(func);
61496122 const msg = msg: {
61506123 const msg = try sema.errMsg(
61516124 block,
......@@ -6677,7 +6650,7 @@ fn analyzeInlineCallArg(
66776650 // Needed so that lazy values do not trigger
66786651 // assertion due to type not being resolved
66796652 // when the hash function is called.
6680 try sema.resolveLazyValue(arg_block, arg_src, arg_val);
6653 try sema.resolveLazyValue(arg_val);
66816654 },
66826655 }
66836656 should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState();
......@@ -6687,7 +6660,7 @@ fn analyzeInlineCallArg(
66876660 };
66886661 } else if (zir_tags[inst] == .param_comptime or try sema.typeRequiresComptime(param_ty)) {
66896662 try sema.inst_map.putNoClobber(sema.gpa, inst, casted_arg);
6690 } else if (try sema.resolveMaybeUndefVal(arg_block, arg_src, casted_arg)) |val| {
6663 } else if (try sema.resolveMaybeUndefVal(casted_arg)) |val| {
66916664 // We have a comptime value but we need a runtime value to preserve inlining semantics,
66926665 const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val));
66936666 try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped);
......@@ -6719,7 +6692,7 @@ fn analyzeInlineCallArg(
67196692 // Needed so that lazy values do not trigger
67206693 // assertion due to type not being resolved
67216694 // when the hash function is called.
6722 try sema.resolveLazyValue(arg_block, arg_src, arg_val);
6695 try sema.resolveLazyValue(arg_val);
67236696 },
67246697 }
67256698 should_memoize.* = should_memoize.* and !arg_val.canMutateComptimeVarState();
......@@ -6729,7 +6702,7 @@ fn analyzeInlineCallArg(
67296702 };
67306703 } else if (zir_tags[inst] == .param_anytype_comptime or try sema.typeRequiresComptime(param_ty)) {
67316704 try sema.inst_map.putNoClobber(sema.gpa, inst, uncasted_arg);
6732 } else if (try sema.resolveMaybeUndefVal(arg_block, arg_src, uncasted_arg)) |val| {
6705 } else if (try sema.resolveMaybeUndefVal(uncasted_arg)) |val| {
67336706 // We have a comptime value but we need a runtime value to preserve inlining semantics,
67346707 const wrapped = try sema.addConstant(param_ty, try Value.Tag.runtime_value.create(sema.arena, val));
67356708 try sema.inst_map.putNoClobber(sema.gpa, inst, wrapped);
......@@ -6750,7 +6723,7 @@ fn analyzeCallArg(
67506723 param_ty: Type,
67516724 uncasted_arg: Air.Inst.Ref,
67526725) !Air.Inst.Ref {
6753 try sema.resolveTypeFully(block, arg_src, param_ty);
6726 try sema.resolveTypeFully(param_ty);
67546727 return sema.coerce(block, param_ty, uncasted_arg, arg_src);
67556728}
67566729
......@@ -6773,14 +6746,14 @@ fn analyzeGenericCallArg(
67736746 try sema.queueFullTypeResolution(param_ty);
67746747 runtime_args[runtime_i.*] = casted_arg;
67756748 runtime_i.* += 1;
6776 } else if (try sema.typeHasOnePossibleValue(block, arg_src, comptime_arg.ty)) |_| {
6749 } else if (try sema.typeHasOnePossibleValue(comptime_arg.ty)) |_| {
67776750 _ = try sema.coerce(block, comptime_arg.ty, uncasted_arg, arg_src);
67786751 }
67796752}
67806753
67816754fn analyzeGenericCallArgVal(sema: *Sema, block: *Block, arg_src: LazySrcLoc, uncasted_arg: Air.Inst.Ref) !Value {
67826755 const arg_val = try sema.resolveValue(block, arg_src, uncasted_arg, "parameter is comptime");
6783 try sema.resolveLazyValue(block, arg_src, arg_val);
6756 try sema.resolveLazyValue(arg_val);
67846757 return arg_val;
67856758}
67866759
......@@ -7032,7 +7005,7 @@ fn instantiateGenericCall(
70327005 }
70337006 const arg = uncasted_args[arg_i];
70347007 if (is_comptime) {
7035 if (try sema.resolveMaybeUndefVal(block, .unneeded, arg)) |arg_val| {
7008 if (try sema.resolveMaybeUndefVal(arg)) |arg_val| {
70367009 const child_arg = try child_sema.addConstant(sema.typeOf(arg), arg_val);
70377010 child_sema.inst_map.putAssumeCapacityNoClobber(inst, child_arg);
70387011 } else {
......@@ -7105,11 +7078,7 @@ fn instantiateGenericCall(
71057078 }
71067079
71077080 if (is_comptime) {
7108 const arg_val = (child_sema.resolveMaybeUndefValAllowVariables(
7109 &child_block,
7110 .unneeded,
7111 arg,
7112 ) catch unreachable).?;
7081 const arg_val = (child_sema.resolveMaybeUndefValAllowVariables(arg) catch unreachable).?;
71137082 child_sema.comptime_args[arg_i] = .{
71147083 .ty = copied_arg_ty,
71157084 .val = try arg_val.copy(new_decl_arena_allocator),
......@@ -7240,7 +7209,7 @@ fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type)
72407209 for (tuple.values) |field_val, i| {
72417210 try sema.resolveTupleLazyValues(block, src, tuple.types[i]);
72427211 if (field_val.tag() == .unreachable_value) continue;
7243 try sema.resolveLazyValue(block, src, field_val);
7212 try sema.resolveLazyValue(field_val);
72447213 }
72457214}
72467215
......@@ -7429,7 +7398,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
74297398 const uncasted_operand = try sema.resolveInst(extra.operand);
74307399 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
74317400
7432 if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| {
7401 if (try sema.resolveMaybeUndefVal(operand)) |val| {
74337402 if (val.isUndef()) {
74347403 return sema.addConstUndef(Type.err_int);
74357404 }
......@@ -7601,11 +7570,11 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
76017570 var int_tag_type_buffer: Type.Payload.Bits = undefined;
76027571 const int_tag_ty = try enum_tag_ty.intTagType(&int_tag_type_buffer).copy(arena);
76037572
7604 if (try sema.typeHasOnePossibleValue(block, src, enum_tag_ty)) |opv| {
7573 if (try sema.typeHasOnePossibleValue(enum_tag_ty)) |opv| {
76057574 return sema.addConstant(int_tag_ty, opv);
76067575 }
76077576
7608 if (try sema.resolveMaybeUndefVal(block, operand_src, enum_tag)) |enum_tag_val| {
7577 if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| {
76097578 var buffer: Value.Payload.U64 = undefined;
76107579 const val = enum_tag_val.enumToInt(enum_tag_ty, &buffer);
76117580 return sema.addConstant(int_tag_ty, try val.copy(sema.arena));
......@@ -7629,14 +7598,14 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
76297598 }
76307599 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
76317600
7632 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| {
7601 if (try sema.resolveMaybeUndefVal(operand)) |int_val| {
76337602 if (dest_ty.isNonexhaustiveEnum()) {
76347603 return sema.addConstant(dest_ty, int_val);
76357604 }
76367605 if (int_val.isUndef()) {
76377606 return sema.failWithUseOfUndef(block, operand_src);
76387607 }
7639 if (!(try sema.enumHasInt(block, src, dest_ty, int_val))) {
7608 if (!(try sema.enumHasInt(dest_ty, int_val))) {
76407609 const msg = msg: {
76417610 const msg = try sema.errMsg(
76427611 block,
......@@ -7653,7 +7622,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
76537622 return sema.addConstant(dest_ty, int_val);
76547623 }
76557624
7656 if (try sema.typeHasOnePossibleValue(block, operand_src, dest_ty)) |opv| {
7625 if (try sema.typeHasOnePossibleValue(dest_ty)) |opv| {
76577626 const result = try sema.addConstant(dest_ty, opv);
76587627 // The operand is runtime-known but the result is comptime-known. In
76597628 // this case we still need a safety check.
......@@ -8355,7 +8324,7 @@ fn funcCommon(
83558324 };
83568325 return sema.failWithOwnedErrorMsg(msg);
83578326 }
8358 if (!Type.fnCallingConventionAllowsZigTypes(cc_workaround) and !try sema.validateExternType(block, ret_ty_src, return_type, .ret_ty)) {
8327 if (!Type.fnCallingConventionAllowsZigTypes(cc_workaround) and !try sema.validateExternType(return_type, .ret_ty)) {
83598328 const msg = msg: {
83608329 const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
83618330 return_type.fmt(sema.mod), @tagName(cc_workaround),
......@@ -8459,8 +8428,8 @@ fn funcCommon(
84598428 if (!is_generic and sema.wantErrorReturnTracing(return_type)) {
84608429 // Make sure that StackTrace's fields are resolved so that the backend can
84618430 // lower this fn type.
8462 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, ret_ty_src, "StackTrace");
8463 _ = try sema.resolveTypeFields(block, ret_ty_src, unresolved_stack_trace_ty);
8431 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
8432 _ = try sema.resolveTypeFields(unresolved_stack_trace_ty);
84648433 }
84658434
84668435 break :fn_ty try Type.Tag.function.create(sema.arena, .{
......@@ -8583,7 +8552,7 @@ fn analyzeParameter(
85838552 };
85848553 return sema.failWithOwnedErrorMsg(msg);
85858554 }
8586 if (!this_generic and !Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(block, param_src, param.ty, .param_ty)) {
8555 if (!this_generic and !Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(param.ty, .param_ty)) {
85878556 const msg = msg: {
85888557 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{
85898558 param.ty.fmt(sema.mod), @tagName(cc),
......@@ -8693,7 +8662,7 @@ fn zirParam(
86938662 }
86948663
86958664 if (sema.preallocated_new_func != null) {
8696 if (try sema.typeHasOnePossibleValue(block, src, param_ty)) |opv| {
8665 if (try sema.typeHasOnePossibleValue(param_ty)) |opv| {
86978666 // In this case we are instantiating a generic function call with a non-comptime
86988667 // non-anytype parameter that ended up being a one-possible-type.
86998668 // We don't want the parameter to be part of the instantiated function type.
......@@ -8733,7 +8702,6 @@ fn zirParamAnytype(
87338702 comptime_syntax: bool,
87348703) CompileError!void {
87358704 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
8736 const src = inst_data.src();
87378705 const param_name = inst_data.get(sema.code);
87388706
87398707 if (sema.inst_map.get(inst)) |air_ref| {
......@@ -8743,7 +8711,7 @@ fn zirParamAnytype(
87438711 // function type of the function instruction in this block.
87448712 return;
87458713 }
8746 if (null != try sema.typeHasOnePossibleValue(block, src, param_ty)) {
8714 if (null != try sema.typeHasOnePossibleValue(param_ty)) {
87478715 return;
87488716 }
87498717 // The map is already populated but we do need to add a runtime parameter.
......@@ -8829,7 +8797,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
88298797 if (!ptr_ty.isPtrAtRuntime()) {
88308798 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)});
88318799 }
8832 if (try sema.resolveMaybeUndefValIntable(block, ptr_src, ptr)) |ptr_val| {
8800 if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| {
88338801 return sema.addConstant(Type.usize, ptr_val);
88348802 }
88358803 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
......@@ -8942,7 +8910,7 @@ fn intCast(
89428910 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, dest_ty_src);
89438911 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
89448912
8945 if (try sema.isComptimeKnown(block, operand_src, operand)) {
8913 if (try sema.isComptimeKnown(operand)) {
89468914 return sema.coerce(block, dest_ty, operand, operand_src);
89478915 } else if (dest_scalar_ty.zigTypeTag() == .ComptimeInt) {
89488916 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_int'", .{});
......@@ -8951,7 +8919,7 @@ fn intCast(
89518919 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, dest_ty_src, operand_src);
89528920 const is_vector = dest_ty.zigTypeTag() == .Vector;
89538921
8954 if ((try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty))) |opv| {
8922 if ((try sema.typeHasOnePossibleValue(dest_ty))) |opv| {
89558923 // requirement: intCast(u0, input) iff input == 0
89568924 if (runtime_safety and block.wantSafety()) {
89578925 try sema.requireRuntimeBlock(block, src, operand_src);
......@@ -9012,7 +8980,7 @@ fn intCast(
90128980 // range to account for negative values.
90138981 const dest_range_val = if (wanted_info.signedness == .signed) range_val: {
90148982 const range_minus_one = try dest_max_val.shl(Value.one, unsigned_operand_ty, sema.arena, target);
9015 break :range_val try sema.intAdd(block, operand_src, range_minus_one, Value.one, unsigned_operand_ty);
8983 break :range_val try sema.intAdd(range_minus_one, Value.one, unsigned_operand_ty);
90168984 } else dest_max_val;
90178985 const dest_range = try sema.addConstant(unsigned_operand_ty, dest_range_val);
90188986
......@@ -9254,7 +9222,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
92549222 ),
92559223 }
92569224
9257 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| {
9225 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
92589226 return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, target));
92599227 }
92609228 if (dest_is_comptime_float) {
......@@ -9415,7 +9383,7 @@ fn zirSwitchCapture(
94159383 return block.addStructFieldVal(operand_ptr, field_index, field_ty);
94169384 }
94179385 } else if (is_ref) {
9418 return sema.addConstantMaybeRef(block, operand_src, operand_ty, item_val, true);
9386 return sema.addConstantMaybeRef(block, operand_ty, item_val, true);
94199387 } else {
94209388 return block.inline_case_capture;
94219389 }
......@@ -9616,14 +9584,14 @@ fn zirSwitchCond(
96169584 if (operand_ty.isSlice()) {
96179585 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)});
96189586 }
9619 if ((try sema.typeHasOnePossibleValue(block, operand_src, operand_ty))) |opv| {
9587 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {
96209588 return sema.addConstant(operand_ty, opv);
96219589 }
96229590 return operand;
96239591 },
96249592
96259593 .Union => {
9626 const union_ty = try sema.resolveTypeFields(block, operand_src, operand_ty);
9594 const union_ty = try sema.resolveTypeFields(operand_ty);
96279595 const enum_ty = union_ty.unionTagType() orelse {
96289596 const msg = msg: {
96299597 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});
......@@ -10336,8 +10304,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1033610304 // Validation above ensured these will succeed.
1033710305 const first_tv = sema.resolveInstConst(&child_block, .unneeded, item_first, "") catch unreachable;
1033810306 const last_tv = sema.resolveInstConst(&child_block, .unneeded, item_last, "") catch unreachable;
10339 if ((try sema.compareAll(block, src, operand_val, .gte, first_tv.val, operand_ty)) and
10340 (try sema.compareAll(block, src, operand_val, .lte, last_tv.val, operand_ty)))
10307 if ((try sema.compareAll(operand_val, .gte, first_tv.val, operand_ty)) and
10308 (try sema.compareAll(operand_val, .lte, last_tv.val, operand_ty)))
1034110309 {
1034210310 if (is_inline) child_block.inline_case_capture = operand;
1034310311 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
......@@ -10487,7 +10455,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1048710455
1048810456 while (item.compareAll(.lte, item_last, operand_ty, sema.mod)) : ({
1048910457 // Previous validation has resolved any possible lazy values.
10490 item = try sema.intAddScalar(block, .unneeded, item, Value.one);
10458 item = try sema.intAddScalar(item, Value.one);
1049110459 }) {
1049210460 cases_len += 1;
1049310461
......@@ -10766,7 +10734,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1076610734 }
1076710735 },
1076810736 .Int => {
10769 var it = try RangeSetUnhandledIterator.init(sema, block, special_prong_src, operand_ty, range_set);
10737 var it = try RangeSetUnhandledIterator.init(sema, operand_ty, range_set);
1077010738 while (try it.next()) |cur| {
1077110739 cases_len += 1;
1077210740
......@@ -10909,8 +10877,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1090910877
1091010878const RangeSetUnhandledIterator = struct {
1091110879 sema: *Sema,
10912 block: *Block,
10913 src: LazySrcLoc,
1091410880 ty: Type,
1091510881 cur: Value,
1091610882 max: Value,
......@@ -10918,15 +10884,13 @@ const RangeSetUnhandledIterator = struct {
1091810884 range_i: usize = 0,
1091910885 first: bool = true,
1092010886
10921 fn init(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, range_set: RangeSet) !RangeSetUnhandledIterator {
10887 fn init(sema: *Sema, ty: Type, range_set: RangeSet) !RangeSetUnhandledIterator {
1092210888 const target = sema.mod.getTarget();
1092310889 const min = try ty.minInt(sema.arena, target);
1092410890 const max = try ty.maxInt(sema.arena, target);
1092510891
1092610892 return RangeSetUnhandledIterator{
1092710893 .sema = sema,
10928 .block = block,
10929 .src = src,
1093010894 .ty = ty,
1093110895 .cur = min,
1093210896 .max = max,
......@@ -10937,7 +10901,7 @@ const RangeSetUnhandledIterator = struct {
1093710901 fn next(it: *RangeSetUnhandledIterator) !?Value {
1093810902 while (it.range_i < it.ranges.len) : (it.range_i += 1) {
1093910903 if (!it.first) {
10940 it.cur = try it.sema.intAdd(it.block, it.src, it.cur, Value.one, it.ty);
10904 it.cur = try it.sema.intAdd(it.cur, Value.one, it.ty);
1094110905 }
1094210906 it.first = false;
1094310907 if (it.cur.compareAll(.lt, it.ranges[it.range_i].first, it.ty, it.sema.mod)) {
......@@ -10946,7 +10910,7 @@ const RangeSetUnhandledIterator = struct {
1094610910 it.cur = it.ranges[it.range_i].last;
1094710911 }
1094810912 if (!it.first) {
10949 it.cur = try it.sema.intAdd(it.block, it.src, it.cur, Value.one, it.ty);
10913 it.cur = try it.sema.intAdd(it.cur, Value.one, it.ty);
1095010914 }
1095110915 it.first = false;
1095210916 if (it.cur.compareAll(.lte, it.max, it.ty, it.sema.mod)) {
......@@ -11199,8 +11163,8 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op
1119911163 const inst_data = sema.code.instructions.items(.data)[inst].@"unreachable";
1120011164 const src = inst_data.src();
1120111165
11202 const panic_fn = try sema.getBuiltin(block, src, "panicUnwrapError");
11203 const err_return_trace = try sema.getErrorReturnTrace(block, src);
11166 const panic_fn = try sema.getBuiltin("panicUnwrapError");
11167 const err_return_trace = try sema.getErrorReturnTrace(block);
1120411168 const args: [2]Air.Inst.Ref = .{ err_return_trace, operand };
1120511169 _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null);
1120611170 return true;
......@@ -11210,8 +11174,8 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op
1121011174 const src = inst_data.src();
1121111175 const msg_inst = try sema.resolveInst(inst_data.operand);
1121211176
11213 const panic_fn = try sema.getBuiltin(block, src, "panic");
11214 const err_return_trace = try sema.getErrorReturnTrace(block, src);
11177 const panic_fn = try sema.getBuiltin("panic");
11178 const err_return_trace = try sema.getErrorReturnTrace(block);
1121511179 const args: [3]Air.Inst.Ref = .{ msg_inst, err_return_trace, .null_value };
1121611180 _ = try sema.analyzeCall(block, panic_fn, src, src, .auto, false, &args, null);
1121711181 return true;
......@@ -11272,7 +11236,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1127211236 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1127311237 const unresolved_ty = try sema.resolveType(block, ty_src, extra.lhs);
1127411238 const field_name = try sema.resolveConstString(block, name_src, extra.rhs, "field name must be comptime-known");
11275 const ty = try sema.resolveTypeFields(block, ty_src, unresolved_ty);
11239 const ty = try sema.resolveTypeFields(unresolved_ty);
1127611240
1127711241 const has_field = hf: {
1127811242 if (ty.isSlice()) {
......@@ -11315,7 +11279,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1131511279 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
1131611280 const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "decl name must be comptime-known");
1131711281
11318 try checkNamespaceType(sema, block, lhs_src, container_type);
11282 try sema.checkNamespaceType(block, lhs_src, container_type);
1131911283
1132011284 const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false;
1132111285 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| {
......@@ -11390,7 +11354,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1139011354 },
1139111355 };
1139211356
11393 var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded);
11357 var anon_decl = try block.startAnonDecl();
1139411358 defer anon_decl.deinit();
1139511359
1139611360 const bytes_including_null = embed_file.bytes[0 .. embed_file.bytes.len + 1];
......@@ -11451,15 +11415,15 @@ fn zirShl(
1145111415 // TODO coerce rhs if air_tag is not shl_sat
1145211416 const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty);
1145311417
11454 const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs);
11455 const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs);
11418 const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs);
11419 const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs);
1145611420
1145711421 if (maybe_rhs_val) |rhs_val| {
1145811422 if (rhs_val.isUndef()) {
1145911423 return sema.addConstUndef(sema.typeOf(lhs));
1146011424 }
1146111425 // If rhs is 0, return lhs without doing any calculations.
11462 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
11426 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1146311427 return lhs;
1146411428 }
1146511429 if (scalar_ty.zigTypeTag() != .ComptimeInt and air_tag != .shl_sat) {
......@@ -11620,15 +11584,15 @@ fn zirShr(
1162011584 const target = sema.mod.getTarget();
1162111585 const scalar_ty = lhs_ty.scalarType();
1162211586
11623 const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs);
11624 const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs);
11587 const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs);
11588 const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs);
1162511589
1162611590 const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {
1162711591 if (rhs_val.isUndef()) {
1162811592 return sema.addConstUndef(lhs_ty);
1162911593 }
1163011594 // If rhs is 0, return lhs without doing any calculations.
11631 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
11595 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1163211596 return lhs;
1163311597 }
1163411598 if (scalar_ty.zigTypeTag() != .ComptimeInt) {
......@@ -11662,7 +11626,7 @@ fn zirShr(
1166211626 if (air_tag == .shr_exact) {
1166311627 // Detect if any ones would be shifted out.
1166411628 const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, target);
11665 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
11629 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {
1166611630 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
1166711631 }
1166811632 }
......@@ -11759,8 +11723,8 @@ fn zirBitwise(
1175911723 const runtime_src = runtime: {
1176011724 // TODO: ask the linker what kind of relocations are available, and
1176111725 // in some cases emit a Value that means "this decl's address AND'd with this operand".
11762 if (try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs)) |lhs_val| {
11763 if (try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs)) |rhs_val| {
11726 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
11727 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
1176411728 const result_val = switch (air_tag) {
1176511729 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, target),
1176611730 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, target),
......@@ -11799,7 +11763,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1179911763 });
1180011764 }
1180111765
11802 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
11766 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1180311767 if (val.isUndef()) {
1180411768 return sema.addConstUndef(operand_type);
1180511769 } else if (operand_type.zigTypeTag() == .Vector) {
......@@ -11946,7 +11910,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1194611910 const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src);
1194711911 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known");
1194811912 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known");
11949 if (try sema.valuesEqual(block, src, lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) {
11913 if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) {
1195011914 break :s lhs_sent_casted_val;
1195111915 } else {
1195211916 break :s null;
......@@ -12019,7 +11983,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1201911983 element_vals[result_len] = sent_val;
1202011984 }
1202111985 const val = try Value.Tag.aggregate.create(sema.arena, element_vals);
12022 return sema.addConstantMaybeRef(block, src, result_ty, val, ptr_addrspace != null);
11986 return sema.addConstantMaybeRef(block, result_ty, val, ptr_addrspace != null);
1202311987 } else break :rs rhs_src;
1202411988 } else lhs_src;
1202511989
......@@ -12238,7 +12202,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1223812202 }
1223912203 break :v try Value.Tag.aggregate.create(sema.arena, element_vals);
1224012204 };
12241 return sema.addConstantMaybeRef(block, src, result_ty, val, ptr_addrspace != null);
12205 return sema.addConstantMaybeRef(block, result_ty, val, ptr_addrspace != null);
1224212206 }
1224312207
1224412208 try sema.requireRuntimeBlock(block, src, lhs_src);
......@@ -12310,7 +12274,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1231012274
1231112275 if (rhs_scalar_ty.isAnyFloat()) {
1231212276 // We handle float negation here to ensure negative zero is represented in the bits.
12313 if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| {
12277 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
1231412278 if (rhs_val.isUndef()) return sema.addConstUndef(rhs_ty);
1231512279 const target = sema.mod.getTarget();
1231612280 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, target));
......@@ -12406,8 +12370,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1240612370
1240712371 const mod = sema.mod;
1240812372 const target = mod.getTarget();
12409 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
12410 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
12373 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
12374 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1241112375
1241212376 if ((lhs_ty.zigTypeTag() == .ComptimeFloat and rhs_ty.zigTypeTag() == .ComptimeInt) or
1241312377 (lhs_ty.zigTypeTag() == .ComptimeInt and rhs_ty.zigTypeTag() == .ComptimeFloat))
......@@ -12455,7 +12419,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1245512419 .Int, .ComptimeInt, .ComptimeFloat => {
1245612420 if (maybe_lhs_val) |lhs_val| {
1245712421 if (!lhs_val.isUndef()) {
12458 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
12422 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1245912423 const zero_val = if (is_vector) b: {
1246012424 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1246112425 } else Value.zero;
......@@ -12467,7 +12431,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1246712431 if (rhs_val.isUndef()) {
1246812432 return sema.failWithUseOfUndef(block, rhs_src);
1246912433 }
12470 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
12434 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1247112435 return sema.failWithDivideByZero(block, rhs_src);
1247212436 }
1247312437 // TODO: if the RHS is one, return the LHS directly
......@@ -12481,7 +12445,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1248112445 if (lhs_val.isUndef()) {
1248212446 if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) {
1248312447 if (maybe_rhs_val) |rhs_val| {
12484 if (try sema.compareAll(block, src, rhs_val, .neq, Value.negative_one, resolved_type)) {
12448 if (try sema.compareAll(rhs_val, .neq, Value.negative_one, resolved_type)) {
1248512449 return sema.addConstUndef(resolved_type);
1248612450 }
1248712451 }
......@@ -12494,7 +12458,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1249412458 if (is_int) {
1249512459 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
1249612460 var vector_index: usize = undefined;
12497 if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) {
12461 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1249812462 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
1249912463 }
1250012464 return sema.addConstant(resolved_type, res);
......@@ -12566,8 +12530,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1256612530
1256712531 const mod = sema.mod;
1256812532 const target = mod.getTarget();
12569 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
12570 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
12533 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
12534 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1257112535
1257212536 const runtime_src = rs: {
1257312537 // For integers:
......@@ -12590,7 +12554,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1259012554 if (lhs_val.isUndef()) {
1259112555 return sema.failWithUseOfUndef(block, rhs_src);
1259212556 } else {
12593 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
12557 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1259412558 const zero_val = if (is_vector) b: {
1259512559 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1259612560 } else Value.zero;
......@@ -12602,7 +12566,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1260212566 if (rhs_val.isUndef()) {
1260312567 return sema.failWithUseOfUndef(block, rhs_src);
1260412568 }
12605 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
12569 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1260612570 return sema.failWithDivideByZero(block, rhs_src);
1260712571 }
1260812572 // TODO: if the RHS is one, return the LHS directly
......@@ -12616,7 +12580,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1261612580 }
1261712581 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
1261812582 var vector_index: usize = undefined;
12619 if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) {
12583 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1262012584 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
1262112585 }
1262212586 return sema.addConstant(resolved_type, res);
......@@ -12731,8 +12695,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1273112695
1273212696 const mod = sema.mod;
1273312697 const target = mod.getTarget();
12734 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
12735 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
12698 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
12699 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1273612700
1273712701 const runtime_src = rs: {
1273812702 // For integers:
......@@ -12756,7 +12720,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1275612720 // If the lhs is undefined, result is undefined.
1275712721 if (maybe_lhs_val) |lhs_val| {
1275812722 if (!lhs_val.isUndef()) {
12759 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
12723 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1276012724 const zero_val = if (is_vector) b: {
1276112725 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1276212726 } else Value.zero;
......@@ -12768,7 +12732,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1276812732 if (rhs_val.isUndef()) {
1276912733 return sema.failWithUseOfUndef(block, rhs_src);
1277012734 }
12771 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
12735 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1277212736 return sema.failWithDivideByZero(block, rhs_src);
1277312737 }
1277412738 // TODO: if the RHS is one, return the LHS directly
......@@ -12777,7 +12741,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1277712741 if (lhs_val.isUndef()) {
1277812742 if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) {
1277912743 if (maybe_rhs_val) |rhs_val| {
12780 if (try sema.compareAll(block, src, rhs_val, .neq, Value.negative_one, resolved_type)) {
12744 if (try sema.compareAll(rhs_val, .neq, Value.negative_one, resolved_type)) {
1278112745 return sema.addConstUndef(resolved_type);
1278212746 }
1278312747 }
......@@ -12848,8 +12812,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1284812812
1284912813 const mod = sema.mod;
1285012814 const target = mod.getTarget();
12851 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
12852 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
12815 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
12816 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1285312817
1285412818 const runtime_src = rs: {
1285512819 // For integers:
......@@ -12873,7 +12837,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1287312837 // If the lhs is undefined, result is undefined.
1287412838 if (maybe_lhs_val) |lhs_val| {
1287512839 if (!lhs_val.isUndef()) {
12876 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
12840 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1287712841 const zero_val = if (is_vector) b: {
1287812842 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1287912843 } else Value.zero;
......@@ -12885,7 +12849,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1288512849 if (rhs_val.isUndef()) {
1288612850 return sema.failWithUseOfUndef(block, rhs_src);
1288712851 }
12888 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
12852 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1288912853 return sema.failWithDivideByZero(block, rhs_src);
1289012854 }
1289112855 }
......@@ -12893,7 +12857,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1289312857 if (lhs_val.isUndef()) {
1289412858 if (lhs_scalar_ty.isSignedInt() and rhs_scalar_ty.isSignedInt()) {
1289512859 if (maybe_rhs_val) |rhs_val| {
12896 if (try sema.compareAll(block, src, rhs_val, .neq, Value.negative_one, resolved_type)) {
12860 if (try sema.compareAll(rhs_val, .neq, Value.negative_one, resolved_type)) {
1289712861 return sema.addConstUndef(resolved_type);
1289812862 }
1289912863 }
......@@ -12906,7 +12870,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1290612870 if (is_int) {
1290712871 const res = try lhs_val.intDiv(rhs_val, resolved_type, sema.arena, target);
1290812872 var vector_index: usize = undefined;
12909 if (!(try sema.intFitsInType(block, src, res, resolved_type, &vector_index))) {
12873 if (!(try sema.intFitsInType(res, resolved_type, &vector_index))) {
1291012874 return sema.failWithIntegerOverflow(block, src, resolved_type, res, vector_index);
1291112875 }
1291212876 return sema.addConstant(resolved_type, res);
......@@ -13092,8 +13056,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1309213056
1309313057 const mod = sema.mod;
1309413058 const target = mod.getTarget();
13095 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
13096 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
13059 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13060 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1309713061
1309813062 const runtime_src = rs: {
1309913063 // For integers:
......@@ -13114,7 +13078,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1311413078 if (lhs_val.isUndef()) {
1311513079 return sema.failWithUseOfUndef(block, lhs_src);
1311613080 }
13117 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13081 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1311813082 const zero_val = if (is_vector) b: {
1311913083 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1312013084 } else Value.zero;
......@@ -13127,18 +13091,18 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1312713091 if (rhs_val.isUndef()) {
1312813092 return sema.failWithUseOfUndef(block, rhs_src);
1312913093 }
13130 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
13094 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1313113095 return sema.failWithDivideByZero(block, rhs_src);
1313213096 }
13133 if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) {
13097 if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema))) {
1313413098 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);
1313513099 }
1313613100 if (maybe_lhs_val) |lhs_val| {
13137 const rem_result = try sema.intRem(block, resolved_type, lhs_val, lhs_src, rhs_val, rhs_src);
13101 const rem_result = try sema.intRem(resolved_type, lhs_val, rhs_val);
1313813102 // If this answer could possibly be different by doing `intMod`,
1313913103 // we must emit a compile error. Otherwise, it's OK.
13140 if (!(try lhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src))) and
13141 !(try rem_result.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))))
13104 if (!(try lhs_val.compareAllWithZeroAdvanced(.gte, sema)) and
13105 !(try rem_result.compareAllWithZeroAdvanced(.eq, sema)))
1314213106 {
1314313107 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
1314413108 }
......@@ -13156,14 +13120,14 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1315613120 if (rhs_val.isUndef()) {
1315713121 return sema.failWithUseOfUndef(block, rhs_src);
1315813122 }
13159 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
13123 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1316013124 return sema.failWithDivideByZero(block, rhs_src);
1316113125 }
13162 if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) {
13126 if (!(try rhs_val.compareAllWithZeroAdvanced(.gte, sema))) {
1316313127 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);
1316413128 }
1316513129 if (maybe_lhs_val) |lhs_val| {
13166 if (lhs_val.isUndef() or !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) {
13130 if (lhs_val.isUndef() or !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema))) {
1316713131 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
1316813132 }
1316913133 return sema.addConstant(
......@@ -13190,38 +13154,32 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1319013154
1319113155fn intRem(
1319213156 sema: *Sema,
13193 block: *Block,
1319413157 ty: Type,
1319513158 lhs: Value,
13196 lhs_src: LazySrcLoc,
1319713159 rhs: Value,
13198 rhs_src: LazySrcLoc,
1319913160) CompileError!Value {
1320013161 if (ty.zigTypeTag() == .Vector) {
1320113162 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
1320213163 for (result_data) |*scalar, i| {
13203 scalar.* = try sema.intRemScalar(block, lhs.indexVectorlike(i), lhs_src, rhs.indexVectorlike(i), rhs_src);
13164 scalar.* = try sema.intRemScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));
1320413165 }
1320513166 return Value.Tag.aggregate.create(sema.arena, result_data);
1320613167 }
13207 return sema.intRemScalar(block, lhs, lhs_src, rhs, rhs_src);
13168 return sema.intRemScalar(lhs, rhs);
1320813169}
1320913170
1321013171fn intRemScalar(
1321113172 sema: *Sema,
13212 block: *Block,
1321313173 lhs: Value,
13214 lhs_src: LazySrcLoc,
1321513174 rhs: Value,
13216 rhs_src: LazySrcLoc,
1321713175) CompileError!Value {
1321813176 const target = sema.mod.getTarget();
1321913177 // TODO is this a performance issue? maybe we should try the operation without
1322013178 // resorting to BigInt first.
1322113179 var lhs_space: Value.BigIntSpace = undefined;
1322213180 var rhs_space: Value.BigIntSpace = undefined;
13223 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, lhs_src));
13224 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, rhs_src));
13181 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema);
13182 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema);
1322513183 const limbs_q = try sema.arena.alloc(
1322613184 math.big.Limb,
1322713185 lhs_bigint.limbs.len,
......@@ -13274,8 +13232,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1327413232
1327513233 const mod = sema.mod;
1327613234 const target = mod.getTarget();
13277 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
13278 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
13235 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13236 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1327913237
1328013238 const runtime_src = rs: {
1328113239 // For integers:
......@@ -13299,7 +13257,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1329913257 if (rhs_val.isUndef()) {
1330013258 return sema.failWithUseOfUndef(block, rhs_src);
1330113259 }
13302 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
13260 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1330313261 return sema.failWithDivideByZero(block, rhs_src);
1330413262 }
1330513263 if (maybe_lhs_val) |lhs_val| {
......@@ -13318,7 +13276,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1331813276 if (rhs_val.isUndef()) {
1331913277 return sema.failWithUseOfUndef(block, rhs_src);
1332013278 }
13321 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
13279 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1332213280 return sema.failWithDivideByZero(block, rhs_src);
1332313281 }
1332413282 }
......@@ -13377,8 +13335,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1337713335
1337813336 const mod = sema.mod;
1337913337 const target = mod.getTarget();
13380 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
13381 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
13338 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13339 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1338213340
1338313341 const runtime_src = rs: {
1338413342 // For integers:
......@@ -13402,13 +13360,13 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1340213360 if (rhs_val.isUndef()) {
1340313361 return sema.failWithUseOfUndef(block, rhs_src);
1340413362 }
13405 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
13363 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1340613364 return sema.failWithDivideByZero(block, rhs_src);
1340713365 }
1340813366 if (maybe_lhs_val) |lhs_val| {
1340913367 return sema.addConstant(
1341013368 resolved_type,
13411 try sema.intRem(block, resolved_type, lhs_val, lhs_src, rhs_val, rhs_src),
13369 try sema.intRem(resolved_type, lhs_val, rhs_val),
1341213370 );
1341313371 }
1341413372 break :rs lhs_src;
......@@ -13421,7 +13379,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1342113379 if (rhs_val.isUndef()) {
1342213380 return sema.failWithUseOfUndef(block, rhs_src);
1342313381 }
13424 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema.kit(block, src)))) {
13382 if (!(try rhs_val.compareAllWithZeroAdvanced(.neq, sema))) {
1342513383 return sema.failWithDivideByZero(block, rhs_src);
1342613384 }
1342713385 }
......@@ -13480,8 +13438,8 @@ fn zirOverflowArithmetic(
1348013438 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)});
1348113439 }
1348213440
13483 const maybe_lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs);
13484 const maybe_rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs);
13441 const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs);
13442 const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs);
1348513443
1348613444 const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty);
1348713445 const ov_ty = tuple_ty.tupleFields().types[1];
......@@ -13500,12 +13458,12 @@ fn zirOverflowArithmetic(
1350013458 // to the result, even if it is undefined..
1350113459 // Otherwise, if either of the argument is undefined, undefined is returned.
1350213460 if (maybe_lhs_val) |lhs_val| {
13503 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
13461 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) {
1350413462 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs };
1350513463 }
1350613464 }
1350713465 if (maybe_rhs_val) |rhs_val| {
13508 if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
13466 if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) {
1350913467 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs };
1351013468 }
1351113469 }
......@@ -13515,7 +13473,7 @@ fn zirOverflowArithmetic(
1351513473 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
1351613474 }
1351713475
13518 const result = try sema.intAddWithOverflow(block, src, lhs_val, rhs_val, dest_ty);
13476 const result = try sema.intAddWithOverflow(lhs_val, rhs_val, dest_ty);
1351913477 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
1352013478 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
1352113479 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
......@@ -13528,14 +13486,14 @@ fn zirOverflowArithmetic(
1352813486 if (maybe_rhs_val) |rhs_val| {
1352913487 if (rhs_val.isUndef()) {
1353013488 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
13531 } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13489 } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1353213490 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs };
1353313491 } else if (maybe_lhs_val) |lhs_val| {
1353413492 if (lhs_val.isUndef()) {
1353513493 break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) };
1353613494 }
1353713495
13538 const result = try sema.intSubWithOverflow(block, src, lhs_val, rhs_val, dest_ty);
13496 const result = try sema.intSubWithOverflow(lhs_val, rhs_val, dest_ty);
1353913497 const overflowed = try sema.addConstant(overflowed_ty, result.overflowed);
1354013498 const wrapped = try sema.addConstant(dest_ty, result.wrapped_result);
1354113499 break :result .{ .overflowed = overflowed, .wrapped = wrapped };
......@@ -13548,9 +13506,9 @@ fn zirOverflowArithmetic(
1354813506 // Otherwise, if either of the arguments is undefined, both results are undefined.
1354913507 if (maybe_lhs_val) |lhs_val| {
1355013508 if (!lhs_val.isUndef()) {
13551 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13509 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1355213510 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs };
13553 } else if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, dest_ty)) {
13511 } else if (try sema.compareAll(lhs_val, .eq, Value.one, dest_ty)) {
1355413512 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs };
1355513513 }
1355613514 }
......@@ -13558,9 +13516,9 @@ fn zirOverflowArithmetic(
1355813516
1355913517 if (maybe_rhs_val) |rhs_val| {
1356013518 if (!rhs_val.isUndef()) {
13561 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13519 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1356213520 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs };
13563 } else if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, dest_ty)) {
13521 } else if (try sema.compareAll(rhs_val, .eq, Value.one, dest_ty)) {
1356413522 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs };
1356513523 }
1356613524 }
......@@ -13584,12 +13542,12 @@ fn zirOverflowArithmetic(
1358413542 // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred.
1358513543 // Oterhwise if either of the arguments is undefined, both results are undefined.
1358613544 if (maybe_lhs_val) |lhs_val| {
13587 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
13545 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) {
1358813546 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs };
1358913547 }
1359013548 }
1359113549 if (maybe_rhs_val) |rhs_val| {
13592 if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
13550 if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) {
1359313551 break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs };
1359413552 }
1359513553 }
......@@ -13697,7 +13655,7 @@ fn analyzeArithmetic(
1369713655 .{@tagName(zir_tag)},
1369813656 ),
1369913657 };
13700 return analyzePtrArithmetic(sema, block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
13658 return sema.analyzePtrArithmetic(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
1370113659 },
1370213660 };
1370313661
......@@ -13719,8 +13677,8 @@ fn analyzeArithmetic(
1371913677
1372013678 const mod = sema.mod;
1372113679 const target = mod.getTarget();
13722 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs);
13723 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs);
13680 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
13681 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
1372413682 const rs: struct { src: LazySrcLoc, air_tag: Air.Inst.Tag } = rs: {
1372513683 switch (zir_tag) {
1372613684 .add => {
......@@ -13732,7 +13690,7 @@ fn analyzeArithmetic(
1373213690 // overflow (max_int), causing illegal behavior.
1373313691 // For floats: either operand being undef makes the result undef.
1373413692 if (maybe_lhs_val) |lhs_val| {
13735 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
13693 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) {
1373613694 return casted_rhs;
1373713695 }
1373813696 }
......@@ -13744,7 +13702,7 @@ fn analyzeArithmetic(
1374413702 return sema.addConstUndef(resolved_type);
1374513703 }
1374613704 }
13747 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13705 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1374813706 return casted_lhs;
1374913707 }
1375013708 }
......@@ -13759,9 +13717,9 @@ fn analyzeArithmetic(
1375913717 }
1376013718 if (maybe_rhs_val) |rhs_val| {
1376113719 if (is_int) {
13762 const sum = try sema.intAdd(block, src, lhs_val, rhs_val, resolved_type);
13720 const sum = try sema.intAdd(lhs_val, rhs_val, resolved_type);
1376313721 var vector_index: usize = undefined;
13764 if (!(try sema.intFitsInType(block, src, sum, resolved_type, &vector_index))) {
13722 if (!(try sema.intFitsInType(sum, resolved_type, &vector_index))) {
1376513723 return sema.failWithIntegerOverflow(block, src, resolved_type, sum, vector_index);
1376613724 }
1376713725 return sema.addConstant(resolved_type, sum);
......@@ -13779,7 +13737,7 @@ fn analyzeArithmetic(
1377913737 // If either of the operands are zero, the other operand is returned.
1378013738 // If either of the operands are undefined, the result is undefined.
1378113739 if (maybe_lhs_val) |lhs_val| {
13782 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
13740 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) {
1378313741 return casted_rhs;
1378413742 }
1378513743 }
......@@ -13788,13 +13746,13 @@ fn analyzeArithmetic(
1378813746 if (rhs_val.isUndef()) {
1378913747 return sema.addConstUndef(resolved_type);
1379013748 }
13791 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13749 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1379213750 return casted_lhs;
1379313751 }
1379413752 if (maybe_lhs_val) |lhs_val| {
1379513753 return sema.addConstant(
1379613754 resolved_type,
13797 try sema.numberAddWrap(block, src, lhs_val, rhs_val, resolved_type),
13755 try sema.numberAddWrapScalar(lhs_val, rhs_val, resolved_type),
1379813756 );
1379913757 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
1380013758 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
......@@ -13804,7 +13762,7 @@ fn analyzeArithmetic(
1380413762 // If either of the operands are zero, then the other operand is returned.
1380513763 // If either of the operands are undefined, the result is undefined.
1380613764 if (maybe_lhs_val) |lhs_val| {
13807 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src)))) {
13765 if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) {
1380813766 return casted_rhs;
1380913767 }
1381013768 }
......@@ -13812,12 +13770,12 @@ fn analyzeArithmetic(
1381213770 if (rhs_val.isUndef()) {
1381313771 return sema.addConstUndef(resolved_type);
1381413772 }
13815 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13773 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1381613774 return casted_lhs;
1381713775 }
1381813776 if (maybe_lhs_val) |lhs_val| {
1381913777 const val = if (scalar_tag == .ComptimeInt)
13820 try sema.intAdd(block, src, lhs_val, rhs_val, resolved_type)
13778 try sema.intAdd(lhs_val, rhs_val, resolved_type)
1382113779 else
1382213780 try lhs_val.intAddSat(rhs_val, resolved_type, sema.arena, target);
1382313781
......@@ -13841,7 +13799,7 @@ fn analyzeArithmetic(
1384113799 return sema.addConstUndef(resolved_type);
1384213800 }
1384313801 }
13844 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13802 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1384513803 return casted_lhs;
1384613804 }
1384713805 }
......@@ -13856,9 +13814,9 @@ fn analyzeArithmetic(
1385613814 }
1385713815 if (maybe_rhs_val) |rhs_val| {
1385813816 if (is_int) {
13859 const diff = try sema.intSub(block, src, lhs_val, rhs_val, resolved_type);
13817 const diff = try sema.intSub(lhs_val, rhs_val, resolved_type);
1386013818 var vector_index: usize = undefined;
13861 if (!(try sema.intFitsInType(block, src, diff, resolved_type, &vector_index))) {
13819 if (!(try sema.intFitsInType(diff, resolved_type, &vector_index))) {
1386213820 return sema.failWithIntegerOverflow(block, src, resolved_type, diff, vector_index);
1386313821 }
1386413822 return sema.addConstant(resolved_type, diff);
......@@ -13879,7 +13837,7 @@ fn analyzeArithmetic(
1387913837 if (rhs_val.isUndef()) {
1388013838 return sema.addConstUndef(resolved_type);
1388113839 }
13882 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13840 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1388313841 return casted_lhs;
1388413842 }
1388513843 }
......@@ -13891,7 +13849,7 @@ fn analyzeArithmetic(
1389113849 if (maybe_rhs_val) |rhs_val| {
1389213850 return sema.addConstant(
1389313851 resolved_type,
13894 try sema.numberSubWrap(block, src, lhs_val, rhs_val, resolved_type),
13852 try sema.numberSubWrapScalar(lhs_val, rhs_val, resolved_type),
1389513853 );
1389613854 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
1389713855 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
......@@ -13904,7 +13862,7 @@ fn analyzeArithmetic(
1390413862 if (rhs_val.isUndef()) {
1390513863 return sema.addConstUndef(resolved_type);
1390613864 }
13907 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13865 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1390813866 return casted_lhs;
1390913867 }
1391013868 }
......@@ -13914,7 +13872,7 @@ fn analyzeArithmetic(
1391413872 }
1391513873 if (maybe_rhs_val) |rhs_val| {
1391613874 const val = if (scalar_tag == .ComptimeInt)
13917 try sema.intSub(block, src, lhs_val, rhs_val, resolved_type)
13875 try sema.intSub(lhs_val, rhs_val, resolved_type)
1391813876 else
1391913877 try lhs_val.intSubSat(rhs_val, resolved_type, sema.arena, target);
1392013878
......@@ -13933,13 +13891,13 @@ fn analyzeArithmetic(
1393313891 // For floats: either operand being undef makes the result undef.
1393413892 if (maybe_lhs_val) |lhs_val| {
1393513893 if (!lhs_val.isUndef()) {
13936 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13894 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1393713895 const zero_val = if (is_vector) b: {
1393813896 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1393913897 } else Value.zero;
1394013898 return sema.addConstant(resolved_type, zero_val);
1394113899 }
13942 if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, resolved_type)) {
13900 if (try sema.compareAll(lhs_val, .eq, Value.one, resolved_type)) {
1394313901 return casted_rhs;
1394413902 }
1394513903 }
......@@ -13953,13 +13911,13 @@ fn analyzeArithmetic(
1395313911 return sema.addConstUndef(resolved_type);
1395413912 }
1395513913 }
13956 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13914 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1395713915 const zero_val = if (is_vector) b: {
1395813916 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1395913917 } else Value.zero;
1396013918 return sema.addConstant(resolved_type, zero_val);
1396113919 }
13962 if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, resolved_type)) {
13920 if (try sema.compareAll(rhs_val, .eq, Value.one, resolved_type)) {
1396313921 return casted_lhs;
1396413922 }
1396513923 if (maybe_lhs_val) |lhs_val| {
......@@ -13973,7 +13931,7 @@ fn analyzeArithmetic(
1397313931 if (is_int) {
1397413932 const product = try lhs_val.intMul(rhs_val, resolved_type, sema.arena, target);
1397513933 var vector_index: usize = undefined;
13976 if (!(try sema.intFitsInType(block, src, product, resolved_type, &vector_index))) {
13934 if (!(try sema.intFitsInType(product, resolved_type, &vector_index))) {
1397713935 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vector_index);
1397813936 }
1397913937 return sema.addConstant(resolved_type, product);
......@@ -13993,13 +13951,13 @@ fn analyzeArithmetic(
1399313951 // If either of the operands are undefined, result is undefined.
1399413952 if (maybe_lhs_val) |lhs_val| {
1399513953 if (!lhs_val.isUndef()) {
13996 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13954 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1399713955 const zero_val = if (is_vector) b: {
1399813956 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1399913957 } else Value.zero;
1400013958 return sema.addConstant(resolved_type, zero_val);
1400113959 }
14002 if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, resolved_type)) {
13960 if (try sema.compareAll(lhs_val, .eq, Value.one, resolved_type)) {
1400313961 return casted_rhs;
1400413962 }
1400513963 }
......@@ -14009,13 +13967,13 @@ fn analyzeArithmetic(
1400913967 if (rhs_val.isUndef()) {
1401013968 return sema.addConstUndef(resolved_type);
1401113969 }
14012 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13970 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1401313971 const zero_val = if (is_vector) b: {
1401413972 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1401513973 } else Value.zero;
1401613974 return sema.addConstant(resolved_type, zero_val);
1401713975 }
14018 if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, resolved_type)) {
13976 if (try sema.compareAll(rhs_val, .eq, Value.one, resolved_type)) {
1401913977 return casted_lhs;
1402013978 }
1402113979 if (maybe_lhs_val) |lhs_val| {
......@@ -14036,13 +13994,13 @@ fn analyzeArithmetic(
1403613994 // If either of the operands are undefined, result is undefined.
1403713995 if (maybe_lhs_val) |lhs_val| {
1403813996 if (!lhs_val.isUndef()) {
14039 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
13997 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1404013998 const zero_val = if (is_vector) b: {
1404113999 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1404214000 } else Value.zero;
1404314001 return sema.addConstant(resolved_type, zero_val);
1404414002 }
14045 if (try sema.compareAll(block, src, lhs_val, .eq, Value.one, resolved_type)) {
14003 if (try sema.compareAll(lhs_val, .eq, Value.one, resolved_type)) {
1404614004 return casted_rhs;
1404714005 }
1404814006 }
......@@ -14051,13 +14009,13 @@ fn analyzeArithmetic(
1405114009 if (rhs_val.isUndef()) {
1405214010 return sema.addConstUndef(resolved_type);
1405314011 }
14054 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema.kit(block, src))) {
14012 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1405514013 const zero_val = if (is_vector) b: {
1405614014 break :b try Value.Tag.repeated.create(sema.arena, Value.zero);
1405714015 } else Value.zero;
1405814016 return sema.addConstant(resolved_type, zero_val);
1405914017 }
14060 if (try sema.compareAll(block, src, rhs_val, .eq, Value.one, resolved_type)) {
14018 if (try sema.compareAll(rhs_val, .eq, Value.one, resolved_type)) {
1406114019 return casted_lhs;
1406214020 }
1406314021 if (maybe_lhs_val) |lhs_val| {
......@@ -14135,7 +14093,7 @@ fn analyzePtrArithmetic(
1413514093 // coerce to isize instead of usize.
1413614094 const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src);
1413714095 const target = sema.mod.getTarget();
14138 const opt_ptr_val = try sema.resolveMaybeUndefVal(block, ptr_src, ptr);
14096 const opt_ptr_val = try sema.resolveMaybeUndefVal(ptr);
1413914097 const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset);
1414014098 const ptr_ty = sema.typeOf(ptr);
1414114099 const ptr_info = ptr_ty.ptrInfo().data;
......@@ -14183,7 +14141,7 @@ fn analyzePtrArithmetic(
1418314141
1418414142 const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(target));
1418514143 if (offset_int == 0) return ptr;
14186 if (try ptr_val.getUnsignedIntAdvanced(target, sema.kit(block, ptr_src))) |addr| {
14144 if (try ptr_val.getUnsignedIntAdvanced(target, sema)) |addr| {
1418714145 const elem_size = elem_ty.abiSize(target);
1418814146 const new_addr = switch (air_tag) {
1418914147 .ptr_add => addr + elem_size * offset_int,
......@@ -14438,8 +14396,8 @@ fn zirCmpEq(
1443814396
1443914397 if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) {
1444014398 const runtime_src: LazySrcLoc = src: {
14441 if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lval| {
14442 if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rval| {
14399 if (try sema.resolveMaybeUndefVal(lhs)) |lval| {
14400 if (try sema.resolveMaybeUndefVal(rhs)) |rval| {
1444314401 if (lval.isUndef() or rval.isUndef()) {
1444414402 return sema.addConstUndef(Type.bool);
1444514403 }
......@@ -14485,7 +14443,7 @@ fn analyzeCmpUnionTag(
1448514443 tag_src: LazySrcLoc,
1448614444 op: std.math.CompareOperator,
1448714445) CompileError!Air.Inst.Ref {
14488 const union_ty = try sema.resolveTypeFields(block, un_src, sema.typeOf(un));
14446 const union_ty = try sema.resolveTypeFields(sema.typeOf(un));
1448914447 const union_tag_ty = union_ty.unionTagType() orelse {
1449014448 const msg = msg: {
1449114449 const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
......@@ -14500,7 +14458,7 @@ fn analyzeCmpUnionTag(
1450014458 const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src);
1450114459 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);
1450214460
14503 if (try sema.resolveMaybeUndefVal(block, tag_src, coerced_tag)) |enum_val| {
14461 if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| {
1450414462 if (enum_val.isUndef()) return sema.addConstUndef(Type.bool);
1450514463 const field_ty = union_ty.unionFieldType(enum_val, sema.mod);
1450614464 if (field_ty.zigTypeTag() == .NoReturn) {
......@@ -14598,18 +14556,18 @@ fn cmpSelf(
1459814556) CompileError!Air.Inst.Ref {
1459914557 const resolved_type = sema.typeOf(casted_lhs);
1460014558 const runtime_src: LazySrcLoc = src: {
14601 if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| {
14559 if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| {
1460214560 if (lhs_val.isUndef()) return sema.addConstUndef(Type.bool);
14603 if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {
14561 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
1460414562 if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool);
1460514563
1460614564 if (resolved_type.zigTypeTag() == .Vector) {
1460714565 const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.@"bool");
14608 const cmp_val = try sema.compareVector(block, lhs_src, lhs_val, op, rhs_val, resolved_type);
14566 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type);
1460914567 return sema.addConstant(result_ty, cmp_val);
1461014568 }
1461114569
14612 if (try sema.compareAll(block, lhs_src, lhs_val, op, rhs_val, resolved_type)) {
14570 if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) {
1461314571 return Air.Inst.Ref.bool_true;
1461414572 } else {
1461514573 return Air.Inst.Ref.bool_false;
......@@ -14625,7 +14583,7 @@ fn cmpSelf(
1462514583 // For bools, we still check the other operand, because we can lower
1462614584 // bool eq/neq more efficiently.
1462714585 if (resolved_type.zigTypeTag() == .Bool) {
14628 if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {
14586 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
1462914587 if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool);
1463014588 return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src);
1463114589 }
......@@ -14710,7 +14668,6 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1471014668
1471114669fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1471214670 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
14713 const src = inst_data.src();
1471414671 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1471514672 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
1471614673 switch (operand_ty.zigTypeTag()) {
......@@ -14746,7 +14703,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1474614703 => {},
1474714704 }
1474814705 const target = sema.mod.getTarget();
14749 const bit_size = try operand_ty.bitSizeAdvanced(target, sema.kit(block, src));
14706 const bit_size = try operand_ty.bitSizeAdvanced(target, sema);
1475014707 return sema.addIntUnsigned(Type.comptime_int, bit_size);
1475114708}
1475214709
......@@ -14767,14 +14724,13 @@ fn zirClosureCapture(
1476714724) CompileError!void {
1476814725 // TODO: Compile error when closed over values are modified
1476914726 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
14770 const src = inst_data.src();
1477114727 // Closures are not necessarily constant values. For example, the
1477214728 // code might do something like this:
1477314729 // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; }
1477414730 // ...in which case the closure_capture instruction has access to a runtime
1477514731 // value only. In such case we preserve the type and use a dummy runtime value.
1477614732 const operand = try sema.resolveInst(inst_data.operand);
14777 const val = (try sema.resolveMaybeUndefValAllowVariables(block, src, operand)) orelse
14733 const val = (try sema.resolveMaybeUndefValAllowVariables(operand)) orelse
1477814734 Value.initTag(.unreachable_value);
1477914735
1478014736 try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, .{
......@@ -14913,7 +14869,7 @@ fn zirBuiltinSrc(
1491314869 const fn_owner_decl = sema.mod.declPtr(func.owner_decl);
1491414870
1491514871 const func_name_val = blk: {
14916 var anon_decl = try block.startAnonDecl(src);
14872 var anon_decl = try block.startAnonDecl();
1491714873 defer anon_decl.deinit();
1491814874 const name = std.mem.span(fn_owner_decl.name);
1491914875 const bytes = try anon_decl.arena().dupe(u8, name[0 .. name.len + 1]);
......@@ -14926,7 +14882,7 @@ fn zirBuiltinSrc(
1492614882 };
1492714883
1492814884 const file_name_val = blk: {
14929 var anon_decl = try block.startAnonDecl(src);
14885 var anon_decl = try block.startAnonDecl();
1493014886 defer anon_decl.deinit();
1493114887 const relative_path = try fn_owner_decl.getFileScope().fullPath(sema.arena);
1493214888 const absolute_path = std.fs.realpathAlloc(sema.arena, relative_path) catch |err| {
......@@ -14952,7 +14908,7 @@ fn zirBuiltinSrc(
1495214908 field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1);
1495314909
1495414910 return sema.addConstant(
14955 try sema.getBuiltinType(block, src, "SourceLocation"),
14911 try sema.getBuiltinType("SourceLocation"),
1495614912 try Value.Tag.aggregate.create(sema.arena, field_values),
1495714913 );
1495814914}
......@@ -14961,7 +14917,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1496114917 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1496214918 const src = inst_data.src();
1496314919 const ty = try sema.resolveType(block, src, inst_data.operand);
14964 const type_info_ty = try sema.getBuiltinType(block, src, "Type");
14920 const type_info_ty = try sema.getBuiltinType("Type");
1496514921 const target = sema.mod.getTarget();
1496614922
1496714923 switch (ty.zigTypeTag()) {
......@@ -15032,7 +14988,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1503214988 // TODO: look into memoizing this result.
1503314989 const info = ty.fnInfo();
1503414990
15035 var params_anon_decl = try block.startAnonDecl(src);
14991 var params_anon_decl = try block.startAnonDecl();
1503614992 defer params_anon_decl.deinit();
1503714993
1503814994 const param_vals = try params_anon_decl.arena().alloc(Value, info.param_types.len);
......@@ -15187,7 +15143,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1518715143 // is_allowzero: bool,
1518815144 Value.makeBool(info.@"allowzero"),
1518915145 // sentinel: ?*const anyopaque,
15190 try sema.optRefValue(block, src, info.pointee_type, info.sentinel),
15146 try sema.optRefValue(block, info.pointee_type, info.sentinel),
1519115147 };
1519215148
1519315149 return sema.addConstant(
......@@ -15206,7 +15162,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1520615162 // child: type,
1520715163 field_values[1] = try Value.Tag.ty.create(sema.arena, info.elem_type);
1520815164 // sentinel: ?*const anyopaque,
15209 field_values[2] = try sema.optRefValue(block, src, info.elem_type, info.sentinel);
15165 field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel);
1521015166
1521115167 return sema.addConstant(
1521215168 type_info_ty,
......@@ -15246,7 +15202,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1524615202 );
1524715203 },
1524815204 .ErrorSet => {
15249 var fields_anon_decl = try block.startAnonDecl(src);
15205 var fields_anon_decl = try block.startAnonDecl();
1525015206 defer fields_anon_decl.deinit();
1525115207
1525215208 // Get the Error type
......@@ -15278,7 +15234,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1527815234 for (vals) |*field_val, i| {
1527915235 const name = names[i];
1528015236 const name_val = v: {
15281 var anon_decl = try block.startAnonDecl(src);
15237 var anon_decl = try block.startAnonDecl();
1528215238 defer anon_decl.deinit();
1528315239 const bytes = try anon_decl.arena().dupeZ(u8, name);
1528415240 const new_decl = try anon_decl.finish(
......@@ -15357,7 +15313,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1535715313
1535815314 const is_exhaustive = Value.makeBool(!ty.isNonexhaustiveEnum());
1535915315
15360 var fields_anon_decl = try block.startAnonDecl(src);
15316 var fields_anon_decl = try block.startAnonDecl();
1536115317 defer fields_anon_decl.deinit();
1536215318
1536315319 const enum_field_ty = t: {
......@@ -15389,7 +15345,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1538915345
1539015346 const name = enum_fields.keys()[i];
1539115347 const name_val = v: {
15392 var anon_decl = try block.startAnonDecl(src);
15348 var anon_decl = try block.startAnonDecl();
1539315349 defer anon_decl.deinit();
1539415350 const bytes = try anon_decl.arena().dupeZ(u8, name);
1539515351 const new_decl = try anon_decl.finish(
......@@ -15456,7 +15412,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1545615412 .Union => {
1545715413 // TODO: look into memoizing this result.
1545815414
15459 var fields_anon_decl = try block.startAnonDecl(src);
15415 var fields_anon_decl = try block.startAnonDecl();
1546015416 defer fields_anon_decl.deinit();
1546115417
1546215418 const union_field_ty = t: {
......@@ -15473,8 +15429,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1547315429 break :t try union_field_ty_decl.val.toType(&buffer).copy(fields_anon_decl.arena());
1547415430 };
1547515431
15476 const union_ty = try sema.resolveTypeFields(block, src, ty);
15477 try sema.resolveTypeLayout(block, src, ty); // Getting alignment requires type layout
15432 const union_ty = try sema.resolveTypeFields(ty);
15433 try sema.resolveTypeLayout(ty); // Getting alignment requires type layout
1547815434 const layout = union_ty.containerLayout();
1547915435
1548015436 const union_fields = union_ty.unionFields();
......@@ -15484,7 +15440,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1548415440 const field = union_fields.values()[i];
1548515441 const name = union_fields.keys()[i];
1548615442 const name_val = v: {
15487 var anon_decl = try block.startAnonDecl(src);
15443 var anon_decl = try block.startAnonDecl();
1548815444 defer anon_decl.deinit();
1548915445 const bytes = try anon_decl.arena().dupeZ(u8, name);
1549015446 const new_decl = try anon_decl.finish(
......@@ -15497,7 +15453,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1549715453
1549815454 const union_field_fields = try fields_anon_decl.arena().create([3]Value);
1549915455 const alignment = switch (layout) {
15500 .Auto, .Extern => try sema.unionFieldAlignment(block, src, field),
15456 .Auto, .Extern => try sema.unionFieldAlignment(field),
1550115457 .Packed => 0,
1550215458 };
1550315459
......@@ -15564,7 +15520,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1556415520 .Struct => {
1556515521 // TODO: look into memoizing this result.
1556615522
15567 var fields_anon_decl = try block.startAnonDecl(src);
15523 var fields_anon_decl = try block.startAnonDecl();
1556815524 defer fields_anon_decl.deinit();
1556915525
1557015526 const struct_field_ty = t: {
......@@ -15580,8 +15536,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1558015536 var buffer: Value.ToTypeBuffer = undefined;
1558115537 break :t try struct_field_ty_decl.val.toType(&buffer).copy(fields_anon_decl.arena());
1558215538 };
15583 const struct_ty = try sema.resolveTypeFields(block, src, ty);
15584 try sema.resolveTypeLayout(block, src, ty); // Getting alignment requires type layout
15539 const struct_ty = try sema.resolveTypeFields(ty);
15540 try sema.resolveTypeLayout(ty); // Getting alignment requires type layout
1558515541 const layout = struct_ty.containerLayout();
1558615542
1558715543 const struct_field_vals = fv: {
......@@ -15592,7 +15548,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1559215548 for (struct_field_vals) |*struct_field_val, i| {
1559315549 const field_ty = field_types[i];
1559415550 const name_val = v: {
15595 var anon_decl = try block.startAnonDecl(src);
15551 var anon_decl = try block.startAnonDecl();
1559615552 defer anon_decl.deinit();
1559715553 const bytes = if (struct_ty.castTag(.anon_struct)) |payload|
1559815554 try anon_decl.arena().dupeZ(u8, payload.data.names[i])
......@@ -15613,7 +15569,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1561315569 const field_val = tuple.values[i];
1561415570 const is_comptime = field_val.tag() != .unreachable_value;
1561515571 const opt_default_val = if (is_comptime) field_val else null;
15616 const default_val_ptr = try sema.optRefValue(block, src, field_ty, opt_default_val);
15572 const default_val_ptr = try sema.optRefValue(block, field_ty, opt_default_val);
1561715573 struct_field_fields.* = .{
1561815574 // name: []const u8,
1561915575 name_val,
......@@ -15637,7 +15593,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1563715593 const field = struct_fields.values()[i];
1563815594 const name = struct_fields.keys()[i];
1563915595 const name_val = v: {
15640 var anon_decl = try block.startAnonDecl(src);
15596 var anon_decl = try block.startAnonDecl();
1564115597 defer anon_decl.deinit();
1564215598 const bytes = try anon_decl.arena().dupeZ(u8, name);
1564315599 const new_decl = try anon_decl.finish(
......@@ -15656,7 +15612,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1565615612 null
1565715613 else
1565815614 field.default_val;
15659 const default_val_ptr = try sema.optRefValue(block, src, field.ty, opt_default_val);
15615 const default_val_ptr = try sema.optRefValue(block, field.ty, opt_default_val);
1566015616 const alignment = field.alignment(target, layout);
1566115617
1566215618 struct_field_fields.* = .{
......@@ -15736,7 +15692,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1573615692 .Opaque => {
1573715693 // TODO: look into memoizing this result.
1573815694
15739 const opaque_ty = try sema.resolveTypeFields(block, src, ty);
15695 const opaque_ty = try sema.resolveTypeFields(ty);
1574015696 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, opaque_ty.getNamespace());
1574115697
1574215698 const field_values = try sema.arena.create([1]Value);
......@@ -15766,7 +15722,7 @@ fn typeInfoDecls(
1576615722 type_info_ty: Type,
1576715723 opt_namespace: ?*Module.Namespace,
1576815724) CompileError!Value {
15769 var decls_anon_decl = try block.startAnonDecl(src);
15725 var decls_anon_decl = try block.startAnonDecl();
1577015726 defer decls_anon_decl.deinit();
1577115727
1577215728 const declaration_ty = t: {
......@@ -15790,7 +15746,7 @@ fn typeInfoDecls(
1579015746 const decl_index = opt_namespace.?.decls.keys()[i];
1579115747 const decl = sema.mod.declPtr(decl_index);
1579215748 const name_val = v: {
15793 var anon_decl = try block.startAnonDecl(src);
15749 var anon_decl = try block.startAnonDecl();
1579415750 defer anon_decl.deinit();
1579515751 const bytes = try anon_decl.arena().dupeZ(u8, mem.sliceTo(decl.name, 0));
1579615752 const new_decl = try anon_decl.finish(
......@@ -15971,7 +15927,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1597115927 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1597215928
1597315929 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
15974 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
15930 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1597515931 return if (val.isUndef())
1597615932 sema.addConstUndef(Type.bool)
1597715933 else if (val.toBool())
......@@ -16044,7 +16000,7 @@ fn zirBoolBr(
1604416000 _ = try rhs_block.addBr(block_inst, rhs_result);
1604516001 }
1604616002
16047 const result = finishCondBr(sema, parent_block, &child_block, &then_block, &else_block, lhs, block_inst);
16003 const result = sema.finishCondBr(parent_block, &child_block, &then_block, &else_block, lhs, block_inst);
1604816004 if (!sema.typeOf(rhs_result).isNoReturn()) {
1604916005 if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| {
1605016006 if (is_bool_or and rhs_val.toBool()) {
......@@ -16119,7 +16075,7 @@ fn zirIsNonNullPtr(
1611916075 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1612016076 const src = inst_data.src();
1612116077 const ptr = try sema.resolveInst(inst_data.operand);
16122 if ((try sema.resolveMaybeUndefVal(block, src, ptr)) == null) {
16078 if ((try sema.resolveMaybeUndefVal(ptr)) == null) {
1612316079 return block.addUnOp(.is_non_null_ptr, ptr);
1612416080 }
1612516081 const loaded = try sema.analyzeLoad(block, src, ptr, src);
......@@ -16449,7 +16405,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir
1644916405
1645016406 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
1645116407 const is_non_err = try sema.analyzePtrIsNonErr(block, src, ret_ptr);
16452 return retWithErrTracing(sema, block, src, is_non_err, .ret_load, ret_ptr);
16408 return sema.retWithErrTracing(block, src, is_non_err, .ret_load, ret_ptr);
1645316409 }
1645416410
1645516411 _ = try block.addUnOp(.ret_load, ret_ptr);
......@@ -16473,11 +16429,11 @@ fn retWithErrTracing(
1647316429 else => true,
1647416430 };
1647516431 const gpa = sema.gpa;
16476 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
16477 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
16432 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
16433 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
1647816434 const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty);
1647916435 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);
16480 const return_err_fn = try sema.getBuiltin(block, src, "returnError");
16436 const return_err_fn = try sema.getBuiltin("returnError");
1648116437 const args: [1]Air.Inst.Ref = .{err_return_trace};
1648216438
1648316439 if (!need_check) {
......@@ -16635,13 +16591,13 @@ fn analyzeRet(
1663516591 return always_noreturn;
1663616592 }
1663716593
16638 try sema.resolveTypeLayout(block, src, sema.fn_ret_ty);
16594 try sema.resolveTypeLayout(sema.fn_ret_ty);
1663916595
1664016596 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
1664116597 // Avoid adding a frame to the error return trace in case the value is comptime-known
1664216598 // to be not an error.
1664316599 const is_non_err = try sema.analyzeIsNonErr(block, src, operand);
16644 return retWithErrTracing(sema, block, src, is_non_err, .ret, operand);
16600 return sema.retWithErrTracing(block, src, is_non_err, .ret, operand);
1664516601 }
1664616602
1664716603 _ = try block.addUnOp(.ret, operand);
......@@ -16720,7 +16676,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1672016676 break :blk 0;
1672116677 }
1672216678 }
16723 const abi_align = @intCast(u32, (try val.getUnsignedIntAdvanced(target, sema.kit(block, align_src))).?);
16679 const abi_align = @intCast(u32, (try val.getUnsignedIntAdvanced(target, sema)).?);
1672416680 try sema.validateAlign(block, align_src, abi_align);
1672516681 break :blk abi_align;
1672616682 } else 0;
......@@ -16752,8 +16708,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1675216708 const elem_ty = if (abi_align == 0)
1675316709 unresolved_elem_ty
1675416710 else t: {
16755 const elem_ty = try sema.resolveTypeFields(block, elem_ty_src, unresolved_elem_ty);
16756 try sema.resolveTypeLayout(block, elem_ty_src, elem_ty);
16711 const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty);
16712 try sema.resolveTypeLayout(elem_ty);
1675716713 break :t elem_ty;
1675816714 };
1675916715
......@@ -16772,7 +16728,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1677216728 } else if (inst_data.size == .Many and elem_ty.zigTypeTag() == .Opaque) {
1677316729 return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{});
1677416730 } else if (inst_data.size == .C) {
16775 if (!try sema.validateExternType(block, elem_ty_src, elem_ty, .other)) {
16731 if (!try sema.validateExternType(elem_ty, .other)) {
1677616732 const msg = msg: {
1677716733 const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)});
1677816734 errdefer msg.destroy(sema.gpa);
......@@ -16831,7 +16787,7 @@ fn structInitEmpty(
1683116787) CompileError!Air.Inst.Ref {
1683216788 const gpa = sema.gpa;
1683316789 // This logic must be synchronized with that in `zirStructInit`.
16834 const struct_ty = try sema.resolveTypeFields(block, dest_src, obj_ty);
16790 const struct_ty = try sema.resolveTypeFields(obj_ty);
1683516791
1683616792 // The init values to use for the struct instance.
1683716793 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount());
......@@ -16884,7 +16840,7 @@ fn unionInit(
1688416840 const field = union_ty.unionFields().values()[field_index];
1688516841 const init = try sema.coerce(block, field.ty, uncasted_init, init_src);
1688616842
16887 if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| {
16843 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
1688816844 const tag_ty = union_ty.unionTagTypeHypothetical();
1688916845 const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name).?);
1689016846 const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index);
......@@ -16916,7 +16872,7 @@ fn zirStructInit(
1691616872 const first_field_type_data = zir_datas[first_item.field_type].pl_node;
1691716873 const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;
1691816874 const resolved_ty = try sema.resolveType(block, src, first_field_type_extra.container_type);
16919 try sema.resolveTypeLayout(block, src, resolved_ty);
16875 try sema.resolveTypeLayout(resolved_ty);
1692016876
1692116877 if (resolved_ty.zigTypeTag() == .Struct) {
1692216878 // This logic must be synchronized with that in `zirStructInitEmpty`.
......@@ -16962,7 +16918,7 @@ fn zirStructInit(
1696216918 found_fields[field_index] = item.data.field_type;
1696316919 field_inits[field_index] = try sema.resolveInst(item.data.init);
1696416920 if (!is_packed) if (resolved_ty.structFieldValueComptime(field_index)) |default_value| {
16965 const init_val = (try sema.resolveMaybeUndefVal(block, field_src, field_inits[field_index])) orelse {
16921 const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse {
1696616922 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
1696716923 };
1696816924
......@@ -16990,10 +16946,9 @@ fn zirStructInit(
1699016946 const tag_val = try Value.Tag.enum_field_index.create(sema.arena, enum_field_index);
1699116947
1699216948 const init_inst = try sema.resolveInst(item.data.init);
16993 if (try sema.resolveMaybeUndefVal(block, field_src, init_inst)) |val| {
16949 if (try sema.resolveMaybeUndefVal(init_inst)) |val| {
1699416950 return sema.addConstantMaybeRef(
1699516951 block,
16996 src,
1699716952 resolved_ty,
1699816953 try Value.Tag.@"union".create(sema.arena, .{ .tag = tag_val, .val = val }),
1699916954 is_ref,
......@@ -17107,7 +17062,7 @@ fn finishStructInit(
1710717062 }
1710817063
1710917064 const is_comptime = for (field_inits) |field_init| {
17110 if (!(try sema.isComptimeKnown(block, dest_src, field_init))) {
17065 if (!(try sema.isComptimeKnown(field_init))) {
1711117066 break false;
1711217067 }
1711317068 } else true;
......@@ -17115,14 +17070,14 @@ fn finishStructInit(
1711517070 if (is_comptime) {
1711617071 const values = try sema.arena.alloc(Value, field_inits.len);
1711717072 for (field_inits) |field_init, i| {
17118 values[i] = (sema.resolveMaybeUndefVal(block, dest_src, field_init) catch unreachable).?;
17073 values[i] = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?;
1711917074 }
1712017075 const struct_val = try Value.Tag.aggregate.create(sema.arena, values);
17121 return sema.addConstantMaybeRef(block, dest_src, struct_ty, struct_val, is_ref);
17076 return sema.addConstantMaybeRef(block, struct_ty, struct_val, is_ref);
1712217077 }
1712317078
1712417079 if (is_ref) {
17125 try sema.resolveStructLayout(block, dest_src, struct_ty);
17080 try sema.resolveStructLayout(struct_ty);
1712617081 const target = sema.mod.getTarget();
1712717082 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
1712817083 .pointee_type = struct_ty,
......@@ -17197,8 +17152,7 @@ fn zirStructInitAnon(
1719717152 };
1719817153 return sema.failWithOwnedErrorMsg(msg);
1719917154 }
17200 const init_src = src; // TODO better source location
17201 if (try sema.resolveMaybeUndefVal(block, init_src, init)) |init_val| {
17155 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
1720217156 values[i] = init_val;
1720317157 } else {
1720417158 values[i] = Value.initTag(.unreachable_value);
......@@ -17216,7 +17170,7 @@ fn zirStructInitAnon(
1721617170
1721717171 const runtime_index = opt_runtime_index orelse {
1721817172 const tuple_val = try Value.Tag.aggregate.create(sema.arena, values);
17219 return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref);
17173 return sema.addConstantMaybeRef(block, tuple_ty, tuple_val, is_ref);
1722017174 };
1722117175
1722217176 sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) {
......@@ -17303,7 +17257,7 @@ fn zirArrayInit(
1730317257
1730417258 const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| {
1730517259 const arg_src = src; // TODO better source location
17306 const comptime_known = try sema.isComptimeKnown(block, arg_src, arg);
17260 const comptime_known = try sema.isComptimeKnown(arg);
1730717261 if (!comptime_known) break arg_src;
1730817262 } else null;
1730917263
......@@ -17312,11 +17266,11 @@ fn zirArrayInit(
1731217266
1731317267 for (resolved_args) |arg, i| {
1731417268 // We checked that all args are comptime above.
17315 elem_vals[i] = (sema.resolveMaybeUndefVal(block, src, arg) catch unreachable).?;
17269 elem_vals[i] = (sema.resolveMaybeUndefVal(arg) catch unreachable).?;
1731617270 }
1731717271
1731817272 const array_val = try Value.Tag.aggregate.create(sema.arena, elem_vals);
17319 return sema.addConstantMaybeRef(block, src, array_ty, array_val, is_ref);
17273 return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref);
1732017274 };
1732117275
1732217276 try sema.requireRuntimeBlock(block, src, runtime_src);
......@@ -17395,7 +17349,7 @@ fn zirArrayInitAnon(
1739517349 };
1739617350 return sema.failWithOwnedErrorMsg(msg);
1739717351 }
17398 if (try sema.resolveMaybeUndefVal(block, operand_src, elem)) |val| {
17352 if (try sema.resolveMaybeUndefVal(elem)) |val| {
1739917353 values[i] = val;
1740017354 } else {
1740117355 values[i] = Value.initTag(.unreachable_value);
......@@ -17412,7 +17366,7 @@ fn zirArrayInitAnon(
1741217366
1741317367 const runtime_src = opt_runtime_src orelse {
1741417368 const tuple_val = try Value.Tag.aggregate.create(sema.arena, values);
17415 return sema.addConstantMaybeRef(block, src, tuple_ty, tuple_val, is_ref);
17369 return sema.addConstantMaybeRef(block, tuple_ty, tuple_val, is_ref);
1741617370 };
1741717371
1741817372 try sema.requireRuntimeBlock(block, src, runtime_src);
......@@ -17451,14 +17405,13 @@ fn zirArrayInitAnon(
1745117405fn addConstantMaybeRef(
1745217406 sema: *Sema,
1745317407 block: *Block,
17454 src: LazySrcLoc,
1745517408 ty: Type,
1745617409 val: Value,
1745717410 is_ref: bool,
1745817411) !Air.Inst.Ref {
1745917412 if (!is_ref) return sema.addConstant(ty, val);
1746017413
17461 var anon_decl = try block.startAnonDecl(src);
17414 var anon_decl = try block.startAnonDecl();
1746217415 defer anon_decl.deinit();
1746317416 const decl = try anon_decl.finish(
1746417417 try ty.copy(anon_decl.arena()),
......@@ -17499,7 +17452,7 @@ fn fieldType(
1749917452) CompileError!Air.Inst.Ref {
1750017453 var cur_ty = aggregate_ty;
1750117454 while (true) {
17502 const resolved_ty = try sema.resolveTypeFields(block, ty_src, cur_ty);
17455 const resolved_ty = try sema.resolveTypeFields(cur_ty);
1750317456 cur_ty = resolved_ty;
1750417457 switch (cur_ty.zigTypeTag()) {
1750517458 .Struct => {
......@@ -17538,18 +17491,13 @@ fn fieldType(
1753817491 }
1753917492}
1754017493
17541fn zirErrorReturnTrace(
17542 sema: *Sema,
17543 block: *Block,
17544 extended: Zir.Inst.Extended.InstData,
17545) CompileError!Air.Inst.Ref {
17546 const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand));
17547 return sema.getErrorReturnTrace(block, src);
17494fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
17495 return sema.getErrorReturnTrace(block);
1754817496}
1754917497
17550fn getErrorReturnTrace(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!Air.Inst.Ref {
17551 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
17552 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
17498fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
17499 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
17500 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
1755317501 const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty);
1755417502
1755517503 // TODO implement this feature in all the backends and then delete this check.
......@@ -17592,9 +17540,8 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1759217540
1759317541fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1759417542 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
17595 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1759617543 const operand = try sema.resolveInst(inst_data.operand);
17597 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
17544 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1759817545 if (val.isUndef()) return sema.addConstUndef(Type.initTag(.u1));
1759917546 const bool_ints = [2]Air.Inst.Ref{ .zero, .one };
1760017547 return bool_ints[@boolToInt(val.toBool())];
......@@ -17650,7 +17597,7 @@ fn zirUnaryMath(
1765017597 const scalar_ty = operand_ty.scalarType();
1765117598 const vec_len = operand_ty.vectorLen();
1765217599 const result_ty = try Type.vector(sema.arena, vec_len, scalar_ty);
17653 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
17600 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1765417601 if (val.isUndef())
1765517602 return sema.addConstUndef(result_ty);
1765617603
......@@ -17670,7 +17617,7 @@ fn zirUnaryMath(
1767017617 return block.addUnOp(air_tag, operand);
1767117618 },
1767217619 .ComptimeFloat, .Float => {
17673 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| {
17620 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
1767417621 if (operand_val.isUndef())
1767517622 return sema.addConstUndef(operand_ty);
1767617623 const result_val = try eval(operand_val, operand_ty, sema.arena, target);
......@@ -17692,7 +17639,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1769217639 const operand_ty = sema.typeOf(operand);
1769317640 const mod = sema.mod;
1769417641
17695 try sema.resolveTypeLayout(block, operand_src, operand_ty);
17642 try sema.resolveTypeLayout(operand_ty);
1769617643 const enum_ty = switch (operand_ty.zigTypeTag()) {
1769717644 .EnumLiteral => {
1769817645 const val = try sema.resolveConstValue(block, .unneeded, operand, "");
......@@ -17749,7 +17696,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1774917696 const name_strategy = @intToEnum(Zir.Inst.NameStrategy, extended.small);
1775017697 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1775117698 const src = LazySrcLoc.nodeOffset(extra.node);
17752 const type_info_ty = try sema.resolveBuiltinTypeFields(block, src, "Type");
17699 const type_info_ty = try sema.getBuiltinType("Type");
1775317700 const uncasted_operand = try sema.resolveInst(extra.operand);
1775417701 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
1775517702 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
......@@ -17827,18 +17774,18 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1782717774 const is_allowzero_val = struct_val[6];
1782817775 const sentinel_val = struct_val[7];
1782917776
17830 if (!try sema.intFitsInType(block, src, alignment_val, Type.u32, null)) {
17777 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
1783117778 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
1783217779 }
17833 const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?);
17780 const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?);
1783417781
1783517782 var buffer: Value.ToTypeBuffer = undefined;
1783617783 const unresolved_elem_ty = child_val.toType(&buffer);
1783717784 const elem_ty = if (abi_align == 0)
1783817785 unresolved_elem_ty
1783917786 else t: {
17840 const elem_ty = try sema.resolveTypeFields(block, src, unresolved_elem_ty);
17841 try sema.resolveTypeLayout(block, src, elem_ty);
17787 const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty);
17788 try sema.resolveTypeLayout(elem_ty);
1784217789 break :t elem_ty;
1784317790 };
1784417791
......@@ -17872,7 +17819,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1787217819 } else if (ptr_size == .Many and elem_ty.zigTypeTag() == .Opaque) {
1787317820 return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{});
1787417821 } else if (ptr_size == .C) {
17875 if (!try sema.validateExternType(block, src, elem_ty, .other)) {
17822 if (!try sema.validateExternType(elem_ty, .other)) {
1787617823 const msg = msg: {
1787717824 const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)});
1787817825 errdefer msg.destroy(sema.gpa);
......@@ -18119,7 +18066,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1811918066 sema.mod,
1812018067 );
1812118068
18122 if (!try sema.intFitsInType(block, src, value_val, enum_obj.tag_ty, null)) {
18069 if (!try sema.intFitsInType(value_val, enum_obj.tag_ty, null)) {
1812318070 // TODO: better source location
1812418071 return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{
1812518072 field_name,
......@@ -18309,7 +18256,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1830918256 var buffer: Value.ToTypeBuffer = undefined;
1831018257 gop.value_ptr.* = .{
1831118258 .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator),
18312 .abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?),
18259 .abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?),
1831318260 };
1831418261 }
1831518262
......@@ -18359,7 +18306,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1835918306 }
1836018307
1836118308 const alignment = alignment: {
18362 if (!try sema.intFitsInType(block, src, alignment_val, Type.u32, null)) {
18309 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
1836318310 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
1836418311 }
1836518312 const alignment = @intCast(u29, alignment_val.toUnsignedInt(target));
......@@ -18571,10 +18518,10 @@ fn reifyStruct(
1857118518 // alignment: comptime_int,
1857218519 const alignment_val = field_struct_val[4];
1857318520
18574 if (!try sema.intFitsInType(block, src, alignment_val, Type.u32, null)) {
18521 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
1857518522 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
1857618523 }
18577 const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?);
18524 const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?);
1857818525
1857918526 if (layout == .Packed and abi_align != 0) {
1858018527 return sema.fail(block, src, "alignment in a packed struct field must be set to 0", .{});
......@@ -18614,7 +18561,7 @@ fn reifyStruct(
1861418561 struct_obj.status = .layout_wip;
1861518562
1861618563 for (struct_obj.fields.values()) |field, index| {
18617 sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) {
18564 sema.resolveTypeLayout(field.ty) catch |err| switch (err) {
1861818565 error.AnalysisFail => {
1861918566 const msg = sema.err orelse return err;
1862018567 try sema.addFieldErrNote(struct_ty, index, msg, "while checking this field", .{});
......@@ -18697,7 +18644,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1869718644 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1869818645 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
1869918646
18700 var anon_decl = try block.startAnonDecl(LazySrcLoc.unneeded);
18647 var anon_decl = try block.startAnonDecl();
1870118648 defer anon_decl.deinit();
1870218649
1870318650 const bytes = try ty.nameAllocArena(anon_decl.arena(), sema.mod);
......@@ -18735,7 +18682,7 @@ fn zirFloatToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1873518682 _ = try sema.checkIntType(block, ty_src, dest_ty);
1873618683 try sema.checkFloatType(block, operand_src, operand_ty);
1873718684
18738 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
18685 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1873918686 const result_val = try sema.floatToInt(block, operand_src, val, operand_ty, dest_ty);
1874018687 return sema.addConstant(dest_ty, result_val);
1874118688 } else if (dest_ty.zigTypeTag() == .ComptimeInt) {
......@@ -18774,9 +18721,9 @@ fn zirIntToFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1877418721 try sema.checkFloatType(block, ty_src, dest_ty);
1877518722 _ = try sema.checkIntType(block, operand_src, operand_ty);
1877618723
18777 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
18724 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1877818725 const target = sema.mod.getTarget();
18779 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, target, sema.kit(block, operand_src));
18726 const result_val = try val.intToFloatAdvanced(sema.arena, operand_ty, dest_ty, target, sema);
1878018727 return sema.addConstant(dest_ty, result_val);
1878118728 } else if (dest_ty.zigTypeTag() == .ComptimeFloat) {
1878218729 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known");
......@@ -18801,7 +18748,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1880118748 const elem_ty = ptr_ty.elemType2();
1880218749 try sema.checkPtrType(block, type_src, ptr_ty);
1880318750 const target = sema.mod.getTarget();
18804 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(target, sema.kit(block, src));
18751 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(target, sema);
1880518752
1880618753 if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| {
1880718754 const addr = val.toUnsignedInt(target);
......@@ -18819,7 +18766,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1881918766 }
1882018767
1882118768 try sema.requireRuntimeBlock(block, src, operand_src);
18822 if (block.wantSafety() and try sema.typeHasRuntimeBits(block, sema.src, elem_ty)) {
18769 if (block.wantSafety() and try sema.typeHasRuntimeBits(elem_ty)) {
1882318770 if (!ptr_ty.isAllowzeroPtr()) {
1882418771 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
1882518772 try sema.addSafetyCheck(block, is_non_zero, .cast_to_null);
......@@ -18961,11 +18908,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1896118908 operand;
1896218909
1896318910 const dest_elem_ty = dest_ty.elemType2();
18964 try sema.resolveTypeLayout(block, dest_ty_src, dest_elem_ty);
18911 try sema.resolveTypeLayout(dest_elem_ty);
1896518912 const dest_align = dest_ty.ptrAlignment(target);
1896618913
1896718914 const operand_elem_ty = operand_ty.elemType2();
18968 try sema.resolveTypeLayout(block, operand_src, operand_elem_ty);
18915 try sema.resolveTypeLayout(operand_elem_ty);
1896918916 const operand_align = operand_ty.ptrAlignment(target);
1897018917
1897118918 // If the destination is less aligned than the source, preserve the source alignment
......@@ -19009,7 +18956,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1900918956 return sema.failWithOwnedErrorMsg(msg);
1901018957 }
1901118958
19012 if (try sema.resolveMaybeUndefVal(block, operand_src, ptr)) |operand_val| {
18959 if (try sema.resolveMaybeUndefVal(ptr)) |operand_val| {
1901318960 if (!dest_ty.ptrAllowsZero() and operand_val.isUndef()) {
1901418961 return sema.failWithUseOfUndef(block, operand_src);
1901518962 }
......@@ -19024,7 +18971,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1902418971
1902518972 try sema.requireRuntimeBlock(block, src, null);
1902618973 if (block.wantSafety() and operand_ty.ptrAllowsZero() and !dest_ty.ptrAllowsZero() and
19027 try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2()))
18974 try sema.typeHasRuntimeBits(dest_ty.elemType2()))
1902818975 {
1902918976 const ptr_int = try block.addUnOp(.ptrtoint, ptr);
1903018977 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
......@@ -19063,13 +19010,13 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1906319010 const target = sema.mod.getTarget();
1906419011 const dest_info = dest_scalar_ty.intInfo(target);
1906519012
19066 if (try sema.typeHasOnePossibleValue(block, dest_ty_src, dest_ty)) |val| {
19013 if (try sema.typeHasOnePossibleValue(dest_ty)) |val| {
1906719014 return sema.addConstant(dest_ty, val);
1906819015 }
1906919016
1907019017 if (operand_scalar_ty.zigTypeTag() != .ComptimeInt) {
1907119018 const operand_info = operand_ty.intInfo(target);
19072 if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| {
19019 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
1907319020 return sema.addConstant(operand_ty, val);
1907419021 }
1907519022
......@@ -19099,7 +19046,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1909919046 }
1910019047 }
1910119048
19102 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
19049 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1910319050 if (val.isUndef()) return sema.addConstUndef(dest_ty);
1910419051 if (!is_vector) {
1910519052 return sema.addConstant(
......@@ -19152,7 +19099,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1915219099
1915319100 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
1915419101 if (block.wantSafety() and dest_align > 1 and
19155 try sema.typeHasRuntimeBits(block, sema.src, ptr_info.pointee_type))
19102 try sema.typeHasRuntimeBits(ptr_info.pointee_type))
1915619103 {
1915719104 const val_payload = try sema.arena.create(Value.Payload.U64);
1915819105 val_payload.* = .{
......@@ -19192,11 +19139,11 @@ fn zirBitCount(
1919219139 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1919319140 const operand = try sema.resolveInst(inst_data.operand);
1919419141 const operand_ty = sema.typeOf(operand);
19195 _ = try checkIntOrVector(sema, block, operand, operand_src);
19142 _ = try sema.checkIntOrVector(block, operand, operand_src);
1919619143 const target = sema.mod.getTarget();
1919719144 const bits = operand_ty.intInfo(target).bits;
1919819145
19199 if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| {
19146 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
1920019147 return sema.addConstant(operand_ty, val);
1920119148 }
1920219149
......@@ -19205,7 +19152,7 @@ fn zirBitCount(
1920519152 .Vector => {
1920619153 const vec_len = operand_ty.vectorLen();
1920719154 const result_ty = try Type.vector(sema.arena, vec_len, result_scalar_ty);
19208 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
19155 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1920919156 if (val.isUndef()) return sema.addConstUndef(result_ty);
1921019157
1921119158 var elem_buf: Value.ElemValueBuffer = undefined;
......@@ -19226,7 +19173,7 @@ fn zirBitCount(
1922619173 }
1922719174 },
1922819175 .Int => {
19229 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
19176 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1923019177 if (val.isUndef()) return sema.addConstUndef(result_scalar_ty);
1923119178 return sema.addIntUnsigned(result_scalar_ty, comptimeOp(val, operand_ty, target));
1923219179 } else {
......@@ -19256,13 +19203,13 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1925619203 );
1925719204 }
1925819205
19259 if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| {
19206 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
1926019207 return sema.addConstant(operand_ty, val);
1926119208 }
1926219209
1926319210 switch (operand_ty.zigTypeTag()) {
1926419211 .Int => {
19265 const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
19212 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
1926619213 if (val.isUndef()) return sema.addConstUndef(operand_ty);
1926719214 const result_val = try val.byteSwap(operand_ty, target, sema.arena);
1926819215 return sema.addConstant(operand_ty, result_val);
......@@ -19272,7 +19219,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1927219219 return block.addTyOp(.byte_swap, operand_ty, operand);
1927319220 },
1927419221 .Vector => {
19275 const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
19222 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
1927619223 if (val.isUndef())
1927719224 return sema.addConstUndef(operand_ty);
1927819225
......@@ -19304,14 +19251,14 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1930419251 const operand_ty = sema.typeOf(operand);
1930519252 _ = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
1930619253
19307 if (try sema.typeHasOnePossibleValue(block, operand_src, operand_ty)) |val| {
19254 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
1930819255 return sema.addConstant(operand_ty, val);
1930919256 }
1931019257
1931119258 const target = sema.mod.getTarget();
1931219259 switch (operand_ty.zigTypeTag()) {
1931319260 .Int, .ComptimeInt => {
19314 const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
19261 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
1931519262 if (val.isUndef()) return sema.addConstUndef(operand_ty);
1931619263 const result_val = try val.bitReverse(operand_ty, target, sema.arena);
1931719264 return sema.addConstant(operand_ty, result_val);
......@@ -19321,7 +19268,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1932119268 return block.addTyOp(.bit_reverse, operand_ty, operand);
1932219269 },
1932319270 .Vector => {
19324 const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
19271 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
1932519272 if (val.isUndef())
1932619273 return sema.addConstUndef(operand_ty);
1932719274
......@@ -19346,12 +19293,12 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1934619293}
1934719294
1934819295fn zirBitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19349 const offset = try bitOffsetOf(sema, block, inst);
19296 const offset = try sema.bitOffsetOf(block, inst);
1935019297 return sema.addIntUnsigned(Type.comptime_int, offset);
1935119298}
1935219299
1935319300fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19354 const offset = try bitOffsetOf(sema, block, inst);
19301 const offset = try sema.bitOffsetOf(block, inst);
1935519302 // TODO reminder to make this a compile error for packed structs
1935619303 return sema.addIntUnsigned(Type.comptime_int, offset / 8);
1935719304}
......@@ -19368,7 +19315,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
1936819315 const field_name = try sema.resolveConstString(block, rhs_src, extra.rhs, "name of field must be comptime-known");
1936919316 const target = sema.mod.getTarget();
1937019317
19371 try sema.resolveTypeLayout(block, lhs_src, ty);
19318 try sema.resolveTypeLayout(ty);
1937219319 switch (ty.zigTypeTag()) {
1937319320 .Struct => {},
1937419321 else => {
......@@ -19758,8 +19705,8 @@ fn checkSimdBinOp(
1975819705 .len = vec_len,
1975919706 .lhs = lhs,
1976019707 .rhs = rhs,
19761 .lhs_val = try sema.resolveMaybeUndefVal(block, lhs_src, lhs),
19762 .rhs_val = try sema.resolveMaybeUndefVal(block, rhs_src, rhs),
19708 .lhs_val = try sema.resolveMaybeUndefVal(lhs),
19709 .rhs_val = try sema.resolveMaybeUndefVal(rhs),
1976319710 .result_ty = result_ty,
1976419711 .scalar_ty = result_ty.scalarType(),
1976519712 };
......@@ -19830,7 +19777,7 @@ fn resolveExportOptions(
1983019777 src: LazySrcLoc,
1983119778 zir_ref: Zir.Inst.Ref,
1983219779) CompileError!std.builtin.ExportOptions {
19833 const export_options_ty = try sema.getBuiltinType(block, src, "ExportOptions");
19780 const export_options_ty = try sema.getBuiltinType("ExportOptions");
1983419781 const air_ref = try sema.resolveInst(zir_ref);
1983519782 const options = try sema.coerce(block, export_options_ty, air_ref, src);
1983619783
......@@ -19885,7 +19832,7 @@ fn resolveBuiltinEnum(
1988519832 comptime name: []const u8,
1988619833 reason: []const u8,
1988719834) CompileError!@field(std.builtin, name) {
19888 const ty = try sema.getBuiltinType(block, src, name);
19835 const ty = try sema.getBuiltinType(name);
1988919836 const air_ref = try sema.resolveInst(zir_ref);
1989019837 const coerced = try sema.coerce(block, ty, air_ref, src);
1989119838 const val = try sema.resolveConstValue(block, src, coerced, reason);
......@@ -19899,7 +19846,7 @@ fn resolveAtomicOrder(
1989919846 zir_ref: Zir.Inst.Ref,
1990019847 reason: []const u8,
1990119848) CompileError!std.builtin.AtomicOrder {
19902 return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicOrder", reason);
19849 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason);
1990319850}
1990419851
1990519852fn resolveAtomicRmwOp(
......@@ -19908,7 +19855,7 @@ fn resolveAtomicRmwOp(
1990819855 src: LazySrcLoc,
1990919856 zir_ref: Zir.Inst.Ref,
1991019857) CompileError!std.builtin.AtomicRmwOp {
19911 return resolveBuiltinEnum(sema, block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known");
19858 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known");
1991219859}
1991319860
1991419861fn zirCmpxchg(
......@@ -19963,13 +19910,13 @@ fn zirCmpxchg(
1996319910 const result_ty = try Type.optional(sema.arena, elem_ty);
1996419911
1996519912 // special case zero bit types
19966 if ((try sema.typeHasOnePossibleValue(block, elem_ty_src, elem_ty)) != null) {
19913 if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) {
1996719914 return sema.addConstant(result_ty, Value.@"null");
1996819915 }
1996919916
1997019917 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
19971 if (try sema.resolveMaybeUndefVal(block, expected_src, expected_value)) |expected_val| {
19972 if (try sema.resolveMaybeUndefVal(block, new_value_src, new_value)) |new_val| {
19918 if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| {
19919 if (try sema.resolveMaybeUndefVal(new_value)) |new_val| {
1997319920 if (expected_val.isUndef() or new_val.isUndef()) {
1997419921 // TODO: this should probably cause the memory stored at the pointer
1997519922 // to become undef as well
......@@ -20018,7 +19965,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2001819965 .len = len,
2001919966 .elem_type = scalar_ty,
2002019967 });
20021 if (try sema.resolveMaybeUndefVal(block, scalar_src, scalar)) |scalar_val| {
19968 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {
2002219969 if (scalar_val.isUndef()) return sema.addConstUndef(vector_ty);
2002319970
2002419971 return sema.addConstant(
......@@ -20070,7 +20017,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2007020017 return sema.fail(block, operand_src, "@reduce operation requires a vector with nonzero length", .{});
2007120018 }
2007220019
20073 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |operand_val| {
20020 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
2007420021 if (operand_val.isUndef()) return sema.addConstUndef(scalar_ty);
2007520022
2007620023 var accum: Value = try operand_val.elemValue(sema.mod, sema.arena, 0);
......@@ -20084,7 +20031,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2008420031 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, target),
2008520032 .Min => accum = accum.numberMin(elem_val, target),
2008620033 .Max => accum = accum.numberMax(elem_val, target),
20087 .Add => accum = try sema.numberAddWrap(block, operand_src, accum, elem_val, scalar_ty),
20034 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),
2008820035 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, target),
2008920036 }
2009020037 }
......@@ -20222,8 +20169,8 @@ fn analyzeShuffle(
2022220169 }
2022320170 }
2022420171
20225 if (try sema.resolveMaybeUndefVal(block, a_src, a)) |a_val| {
20226 if (try sema.resolveMaybeUndefVal(block, b_src, b)) |b_val| {
20172 if (try sema.resolveMaybeUndefVal(a)) |a_val| {
20173 if (try sema.resolveMaybeUndefVal(b)) |b_val| {
2022720174 const values = try sema.arena.alloc(Value, mask_len);
2022820175
2022920176 i = 0;
......@@ -20319,9 +20266,9 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2031920266 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
2032020267 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);
2032120268
20322 const maybe_pred = try sema.resolveMaybeUndefVal(block, pred_src, pred);
20323 const maybe_a = try sema.resolveMaybeUndefVal(block, a_src, a);
20324 const maybe_b = try sema.resolveMaybeUndefVal(block, b_src, b);
20269 const maybe_pred = try sema.resolveMaybeUndefVal(pred);
20270 const maybe_a = try sema.resolveMaybeUndefVal(a);
20271 const maybe_b = try sema.resolveMaybeUndefVal(b);
2032520272
2032620273 const runtime_src = if (maybe_pred) |pred_val| rs: {
2032720274 if (pred_val.isUndef()) return sema.addConstUndef(vec_ty);
......@@ -20405,7 +20352,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2040520352 else => {},
2040620353 }
2040720354
20408 if (try sema.typeHasOnePossibleValue(block, elem_ty_src, elem_ty)) |val| {
20355 if (try sema.typeHasOnePossibleValue(elem_ty)) |val| {
2040920356 return sema.addConstant(elem_ty, val);
2041020357 }
2041120358
......@@ -20462,12 +20409,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2046220409 }
2046320410
2046420411 // special case zero bit types
20465 if (try sema.typeHasOnePossibleValue(block, elem_ty_src, elem_ty)) |val| {
20412 if (try sema.typeHasOnePossibleValue(elem_ty)) |val| {
2046620413 return sema.addConstant(elem_ty, val);
2046720414 }
2046820415
2046920416 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
20470 const maybe_operand_val = try sema.resolveMaybeUndefVal(block, operand_src, operand);
20417 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
2047120418 const operand_val = maybe_operand_val orelse {
2047220419 try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src);
2047320420 break :rs operand_src;
......@@ -20479,8 +20426,8 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2047920426 const new_val = switch (op) {
2048020427 // zig fmt: off
2048120428 .Xchg => operand_val,
20482 .Add => try sema.numberAddWrap(block, src, stored_val, operand_val, elem_ty),
20483 .Sub => try sema.numberSubWrap(block, src, stored_val, operand_val, elem_ty),
20429 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),
20430 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),
2048420431 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, target),
2048520432 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, target),
2048620433 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, target),
......@@ -20559,9 +20506,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2055920506
2056020507 const target = sema.mod.getTarget();
2056120508
20562 const maybe_mulend1 = try sema.resolveMaybeUndefVal(block, mulend1_src, mulend1);
20563 const maybe_mulend2 = try sema.resolveMaybeUndefVal(block, mulend2_src, mulend2);
20564 const maybe_addend = try sema.resolveMaybeUndefVal(block, addend_src, addend);
20509 const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1);
20510 const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2);
20511 const maybe_addend = try sema.resolveMaybeUndefVal(addend);
2056520512
2056620513 switch (ty.zigTypeTag()) {
2056720514 .ComptimeFloat, .Float, .Vector => {},
......@@ -20618,7 +20565,7 @@ fn resolveCallOptions(
2061820565 func: Air.Inst.Ref,
2061920566 func_src: LazySrcLoc,
2062020567) CompileError!std.builtin.CallOptions.Modifier {
20621 const call_options_ty = try sema.getBuiltinType(block, src, "CallOptions");
20568 const call_options_ty = try sema.getBuiltinType("CallOptions");
2062220569 const air_ref = try sema.resolveInst(zir_ref);
2062320570 const options = try sema.coerce(block, call_options_ty, air_ref, src);
2062420571
......@@ -20767,7 +20714,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2076720714 if (struct_ty.zigTypeTag() != .Struct) {
2076820715 return sema.fail(block, ty_src, "expected struct type, found '{}'", .{struct_ty.fmt(sema.mod)});
2076920716 }
20770 try sema.resolveTypeLayout(block, ty_src, struct_ty);
20717 try sema.resolveTypeLayout(struct_ty);
2077120718
2077220719 const field_index = if (struct_ty.isTuple()) blk: {
2077320720 if (mem.eql(u8, field_name, "len")) {
......@@ -20981,7 +20928,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2098120928 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: {
2098220929 if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src;
2098320930 if (try sema.resolveDefinedValue(block, len_src, len)) |len_val| {
20984 if (try sema.resolveMaybeUndefVal(block, value_src, value)) |val| {
20931 if (try sema.resolveMaybeUndefVal(value)) |val| {
2098520932 _ = len_val;
2098620933 _ = val;
2098720934 return sema.fail(block, src, "TODO: Sema.zirMemset at comptime", .{});
......@@ -21076,7 +21023,7 @@ fn zirVarExtended(
2107621023 else
2107721024 uncasted_init;
2107821025
21079 break :blk (try sema.resolveMaybeUndefVal(block, init_src, init)) orelse
21026 break :blk (try sema.resolveMaybeUndefVal(init)) orelse
2108021027 return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known");
2108121028 } else Value.initTag(.unreachable_value);
2108221029
......@@ -21181,7 +21128,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2118121128 const body = sema.code.extra[extra_index..][0..body_len];
2118221129 extra_index += body.len;
2118321130
21184 const addrspace_ty = try sema.getBuiltinType(block, addrspace_src, "AddressSpace");
21131 const addrspace_ty = try sema.getBuiltinType("AddressSpace");
2118521132 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known");
2118621133 if (val.tag() == .generic_poison) {
2118721134 break :blk null;
......@@ -21229,7 +21176,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2122921176 const body = sema.code.extra[extra_index..][0..body_len];
2123021177 extra_index += body.len;
2123121178
21232 const cc_ty = try sema.getBuiltinType(block, addrspace_src, "CallingConvention");
21179 const cc_ty = try sema.getBuiltinType("CallingConvention");
2123321180 const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known");
2123421181 if (val.tag() == .generic_poison) {
2123521182 break :blk null;
......@@ -21411,7 +21358,7 @@ fn resolvePrefetchOptions(
2141121358 src: LazySrcLoc,
2141221359 zir_ref: Zir.Inst.Ref,
2141321360) CompileError!std.builtin.PrefetchOptions {
21414 const options_ty = try sema.getBuiltinType(block, src, "PrefetchOptions");
21361 const options_ty = try sema.getBuiltinType("PrefetchOptions");
2141521362 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2141621363 const target = sema.mod.getTarget();
2141721364
......@@ -21476,7 +21423,7 @@ fn resolveExternOptions(
2147621423 zir_ref: Zir.Inst.Ref,
2147721424) CompileError!std.builtin.ExternOptions {
2147821425 const options_inst = try sema.resolveInst(zir_ref);
21479 const extern_options_ty = try sema.getBuiltinType(block, src, "ExternOptions");
21426 const extern_options_ty = try sema.getBuiltinType("ExternOptions");
2148021427 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
2148121428 const mod = sema.mod;
2148221429
......@@ -21619,7 +21566,7 @@ fn validateVarType(
2161921566 var_ty: Type,
2162021567 is_extern: bool,
2162121568) CompileError!void {
21622 if (try sema.validateRunTimeType(block, src, var_ty, is_extern)) return;
21569 if (try sema.validateRunTimeType(var_ty, is_extern)) return;
2162321570
2162421571 const mod = sema.mod;
2162521572
......@@ -21640,8 +21587,6 @@ fn validateVarType(
2164021587
2164121588fn validateRunTimeType(
2164221589 sema: *Sema,
21643 block: *Block,
21644 src: LazySrcLoc,
2164521590 var_ty: Type,
2164621591 is_extern: bool,
2164721592) CompileError!bool {
......@@ -21682,14 +21627,14 @@ fn validateRunTimeType(
2168221627 .Optional => {
2168321628 var buf: Type.Payload.ElemType = undefined;
2168421629 const child_ty = ty.optionalChild(&buf);
21685 return validateRunTimeType(sema, block, src, child_ty, is_extern);
21630 return sema.validateRunTimeType(child_ty, is_extern);
2168621631 },
2168721632 .Array, .Vector => ty = ty.elemType(),
2168821633
2168921634 .ErrorUnion => ty = ty.errorUnionPayload(),
2169021635
2169121636 .Struct, .Union => {
21692 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
21637 const resolved_ty = try sema.resolveTypeFields(ty);
2169321638 const needs_comptime = try sema.typeRequiresComptime(resolved_ty);
2169421639 return !needs_comptime;
2169521640 },
......@@ -21709,7 +21654,7 @@ fn explainWhyTypeIsComptime(
2170921654 var type_set = TypeSet{};
2171021655 defer type_set.deinit(sema.gpa);
2171121656
21712 try sema.resolveTypeFully(block, src, ty);
21657 try sema.resolveTypeFully(ty);
2171321658 return sema.explainWhyTypeIsComptimeInner(block, src, msg, src_loc, ty, &type_set);
2171421659}
2171521660
......@@ -21842,8 +21787,6 @@ const ExternPosition = enum {
2184221787/// Calls `resolveTypeLayout` for packed containers.
2184321788fn validateExternType(
2184421789 sema: *Sema,
21845 block: *Block,
21846 src: LazySrcLoc,
2184721790 ty: Type,
2184821791 position: ExternPosition,
2184921792) !bool {
......@@ -21882,13 +21825,13 @@ fn validateExternType(
2188221825 },
2188321826 .Enum => {
2188421827 var buf: Type.Payload.Bits = undefined;
21885 return sema.validateExternType(block, src, ty.intTagType(&buf), position);
21828 return sema.validateExternType(ty.intTagType(&buf), position);
2188621829 },
2188721830 .Struct, .Union => switch (ty.containerLayout()) {
2188821831 .Extern => return true,
2188921832 .Packed => {
2189021833 const target = sema.mod.getTarget();
21891 const bit_size = try ty.bitSizeAdvanced(target, sema.kit(block, src));
21834 const bit_size = try ty.bitSizeAdvanced(target, sema);
2189221835 switch (bit_size) {
2189321836 8, 16, 32, 64, 128 => return true,
2189421837 else => return false,
......@@ -21898,9 +21841,9 @@ fn validateExternType(
2189821841 },
2189921842 .Array => {
2190021843 if (position == .ret_ty or position == .param_ty) return false;
21901 return sema.validateExternType(block, src, ty.elemType2(), .element);
21844 return sema.validateExternType(ty.elemType2(), .element);
2190221845 },
21903 .Vector => return sema.validateExternType(block, src, ty.elemType2(), .element),
21846 .Vector => return sema.validateExternType(ty.elemType2(), .element),
2190421847 .Optional => return ty.isPtrLikeOptional(),
2190521848 }
2190621849}
......@@ -22173,9 +22116,9 @@ fn panicWithMsg(
2217322116 _ = try block.addNoOp(.unreach);
2217422117 return always_noreturn;
2217522118 }
22176 const panic_fn = try sema.getBuiltin(block, src, "panic");
22177 const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace");
22178 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
22119 const panic_fn = try sema.getBuiltin("panic");
22120 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
22121 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
2217922122 const target = mod.getTarget();
2218022123 const ptr_stack_trace_ty = try Type.ptr(arena, mod, .{
2218122124 .pointee_type = stack_trace_ty,
......@@ -22224,9 +22167,9 @@ fn panicUnwrapError(
2222422167 _ = try fail_block.addNoOp(.breakpoint);
2222522168 _ = try fail_block.addNoOp(.unreach);
2222622169 } else {
22227 const panic_fn = try sema.getBuiltin(&fail_block, src, "panicUnwrapError");
22170 const panic_fn = try sema.getBuiltin("panicUnwrapError");
2222822171 const err = try fail_block.addTyOp(unwrap_err_tag, Type.anyerror, operand);
22229 const err_return_trace = try sema.getErrorReturnTrace(&fail_block, src);
22172 const err_return_trace = try sema.getErrorReturnTrace(&fail_block);
2223022173 const args: [2]Air.Inst.Ref = .{ err_return_trace, err };
2223122174 _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null);
2223222175 }
......@@ -22268,7 +22211,7 @@ fn panicIndexOutOfBounds(
2226822211 _ = try fail_block.addNoOp(.breakpoint);
2226922212 _ = try fail_block.addNoOp(.unreach);
2227022213 } else {
22271 const panic_fn = try sema.getBuiltin(&fail_block, src, "panicOutOfBounds");
22214 const panic_fn = try sema.getBuiltin("panicOutOfBounds");
2227222215 const args: [2]Air.Inst.Ref = .{ index, len };
2227322216 _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null);
2227422217 }
......@@ -22311,7 +22254,7 @@ fn panicSentinelMismatch(
2231122254 } else if (sentinel_ty.isSelfComparable(true))
2231222255 try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel)
2231322256 else {
22314 const panic_fn = try sema.getBuiltin(parent_block, src, "checkNonScalarSentinel");
22257 const panic_fn = try sema.getBuiltin("checkNonScalarSentinel");
2231522258 const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel };
2231622259 _ = try sema.analyzeCall(parent_block, panic_fn, src, src, .auto, false, &args, null);
2231722260 return;
......@@ -22340,7 +22283,7 @@ fn panicSentinelMismatch(
2234022283 _ = try fail_block.addNoOp(.breakpoint);
2234122284 _ = try fail_block.addNoOp(.unreach);
2234222285 } else {
22343 const panic_fn = try sema.getBuiltin(&fail_block, src, "panicSentinelMismatch");
22286 const panic_fn = try sema.getBuiltin("panicSentinelMismatch");
2234422287 const args: [2]Air.Inst.Ref = .{ expected_sentinel, actual_sentinel };
2234522288 _ = try sema.analyzeCall(&fail_block, panic_fn, src, src, .auto, false, &args, null);
2234622289 }
......@@ -22377,7 +22320,7 @@ fn safetyPanic(
2237722320 const msg_inst = msg_inst: {
2237822321 // TODO instead of making a new decl for every panic in the entire compilation,
2237922322 // introduce the concept of a reference-counted decl for these
22380 var anon_decl = try block.startAnonDecl(src);
22323 var anon_decl = try block.startAnonDecl();
2238122324 defer anon_decl.deinit();
2238222325 break :msg_inst try sema.analyzeDeclRef(try anon_decl.finish(
2238322326 try Type.Tag.array_u8.create(anon_decl.arena(), msg.len),
......@@ -22526,7 +22469,7 @@ fn fieldVal(
2252622469 );
2252722470 },
2252822471 .Union => {
22529 const union_ty = try sema.resolveTypeFields(block, src, child_type);
22472 const union_ty = try sema.resolveTypeFields(child_type);
2253022473
2253122474 if (union_ty.getNamespace()) |namespace| {
2253222475 if (try sema.namespaceLookupVal(block, src, namespace, field_name)) |inst| {
......@@ -22627,7 +22570,7 @@ fn fieldPtr(
2262722570 switch (inner_ty.zigTypeTag()) {
2262822571 .Array => {
2262922572 if (mem.eql(u8, field_name, "len")) {
22630 var anon_decl = try block.startAnonDecl(src);
22573 var anon_decl = try block.startAnonDecl();
2263122574 defer anon_decl.deinit();
2263222575 return sema.analyzeDeclRef(try anon_decl.finish(
2263322576 Type.usize,
......@@ -22729,7 +22672,7 @@ fn fieldPtr(
2272922672 });
2273022673 } else (try sema.mod.getErrorValue(field_name)).key;
2273122674
22732 var anon_decl = try block.startAnonDecl(src);
22675 var anon_decl = try block.startAnonDecl();
2273322676 defer anon_decl.deinit();
2273422677 return sema.analyzeDeclRef(try anon_decl.finish(
2273522678 if (!child_type.isAnyError())
......@@ -22749,7 +22692,7 @@ fn fieldPtr(
2274922692 if (child_type.unionTagType()) |enum_ty| {
2275022693 if (enum_ty.enumFieldIndex(field_name)) |field_index| {
2275122694 const field_index_u32 = @intCast(u32, field_index);
22752 var anon_decl = try block.startAnonDecl(src);
22695 var anon_decl = try block.startAnonDecl();
2275322696 defer anon_decl.deinit();
2275422697 return sema.analyzeDeclRef(try anon_decl.finish(
2275522698 try enum_ty.copy(anon_decl.arena()),
......@@ -22770,7 +22713,7 @@ fn fieldPtr(
2277022713 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2277122714 };
2277222715 const field_index_u32 = @intCast(u32, field_index);
22773 var anon_decl = try block.startAnonDecl(src);
22716 var anon_decl = try block.startAnonDecl();
2277422717 defer anon_decl.deinit();
2277522718 return sema.analyzeDeclRef(try anon_decl.finish(
2277622719 try child_type.copy(anon_decl.arena()),
......@@ -22839,40 +22782,40 @@ fn fieldCallBind(
2283922782 find_field: {
2284022783 switch (concrete_ty.zigTypeTag()) {
2284122784 .Struct => {
22842 const struct_ty = try sema.resolveTypeFields(block, src, concrete_ty);
22785 const struct_ty = try sema.resolveTypeFields(concrete_ty);
2284322786 if (struct_ty.castTag(.@"struct")) |struct_obj| {
2284422787 const field_index_usize = struct_obj.data.fields.getIndex(field_name) orelse
2284522788 break :find_field;
2284622789 const field_index = @intCast(u32, field_index_usize);
2284722790 const field = struct_obj.data.fields.values()[field_index];
2284822791
22849 return finishFieldCallBind(sema, block, src, ptr_ty, field.ty, field_index, object_ptr);
22792 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);
2285022793 } else if (struct_ty.isTuple()) {
2285122794 if (mem.eql(u8, field_name, "len")) {
2285222795 return sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount());
2285322796 }
2285422797 if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| {
2285522798 if (field_index >= struct_ty.structFieldCount()) break :find_field;
22856 return finishFieldCallBind(sema, block, src, ptr_ty, struct_ty.structFieldType(field_index), field_index, object_ptr);
22799 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index), field_index, object_ptr);
2285722800 } else |_| {}
2285822801 } else {
2285922802 const max = struct_ty.structFieldCount();
2286022803 var i: u32 = 0;
2286122804 while (i < max) : (i += 1) {
2286222805 if (mem.eql(u8, struct_ty.structFieldName(i), field_name)) {
22863 return finishFieldCallBind(sema, block, src, ptr_ty, struct_ty.structFieldType(i), i, object_ptr);
22806 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(i), i, object_ptr);
2286422807 }
2286522808 }
2286622809 }
2286722810 },
2286822811 .Union => {
22869 const union_ty = try sema.resolveTypeFields(block, src, concrete_ty);
22812 const union_ty = try sema.resolveTypeFields(concrete_ty);
2287022813 const fields = union_ty.unionFields();
2287122814 const field_index_usize = fields.getIndex(field_name) orelse break :find_field;
2287222815 const field_index = @intCast(u32, field_index_usize);
2287322816 const field = fields.values()[field_index];
2287422817
22875 return finishFieldCallBind(sema, block, src, ptr_ty, field.ty, field_index, object_ptr);
22818 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);
2287622819 },
2287722820 .Type => {
2287822821 const namespace = try sema.analyzeLoad(block, src, object_ptr, src);
......@@ -23058,8 +23001,8 @@ fn structFieldPtr(
2305823001) CompileError!Air.Inst.Ref {
2305923002 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
2306023003
23061 const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty);
23062 try sema.resolveStructLayout(block, src, struct_ty);
23004 const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty);
23005 try sema.resolveStructLayout(struct_ty);
2306323006
2306423007 if (struct_ty.isTuple()) {
2306523008 if (mem.eql(u8, field_name, "len")) {
......@@ -23115,7 +23058,7 @@ fn structFieldPtrByIndex(
2311523058
2311623059 var running_bits: u16 = 0;
2311723060 for (struct_obj.fields.values()) |f, i| {
23118 if (!(try sema.typeHasRuntimeBits(block, field_src, f.ty))) continue;
23061 if (!(try sema.typeHasRuntimeBits(f.ty))) continue;
2311923062
2312023063 if (i == field_index) {
2312123064 ptr_ty_data.bit_offset = running_bits;
......@@ -23198,12 +23141,12 @@ fn structFieldVal(
2319823141) CompileError!Air.Inst.Ref {
2319923142 assert(unresolved_struct_ty.zigTypeTag() == .Struct);
2320023143
23201 const struct_ty = try sema.resolveTypeFields(block, src, unresolved_struct_ty);
23144 const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty);
2320223145 switch (struct_ty.tag()) {
2320323146 .tuple, .empty_struct_literal => return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty),
2320423147 .anon_struct => {
2320523148 const field_index = try sema.anonStructFieldIndex(block, struct_ty, field_name, field_name_src);
23206 return tupleFieldValByIndex(sema, block, src, struct_byval, field_index, struct_ty);
23149 return sema.tupleFieldValByIndex(block, src, struct_byval, field_index, struct_ty);
2320723150 },
2320823151 .@"struct" => {
2320923152 const struct_obj = struct_ty.castTag(.@"struct").?.data;
......@@ -23217,9 +23160,9 @@ fn structFieldVal(
2321723160 return sema.addConstant(field.ty, field.default_val);
2321823161 }
2321923162
23220 if (try sema.resolveMaybeUndefVal(block, src, struct_byval)) |struct_val| {
23163 if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| {
2322123164 if (struct_val.isUndef()) return sema.addConstUndef(field.ty);
23222 if ((try sema.typeHasOnePossibleValue(block, src, field.ty))) |opv| {
23165 if ((try sema.typeHasOnePossibleValue(field.ty))) |opv| {
2322323166 return sema.addConstant(field.ty, opv);
2322423167 }
2322523168
......@@ -23247,7 +23190,7 @@ fn tupleFieldVal(
2324723190 return sema.addIntUnsigned(Type.usize, tuple_ty.structFieldCount());
2324823191 }
2324923192 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
23250 return tupleFieldValByIndex(sema, block, src, tuple_byval, field_index, tuple_ty);
23193 return sema.tupleFieldValByIndex(block, src, tuple_byval, field_index, tuple_ty);
2325123194}
2325223195
2325323196/// Asserts that `field_name` is not "len".
......@@ -23286,9 +23229,9 @@ fn tupleFieldValByIndex(
2328623229 return sema.addConstant(field_ty, tuple.values[field_index]);
2328723230 }
2328823231
23289 if (try sema.resolveMaybeUndefVal(block, src, tuple_byval)) |tuple_val| {
23232 if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| {
2329023233 if (tuple_val.isUndef()) return sema.addConstUndef(field_ty);
23291 if ((try sema.typeHasOnePossibleValue(block, src, field_ty))) |opv| {
23234 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2329223235 return sema.addConstant(field_ty, opv);
2329323236 }
2329423237 const field_values = tuple_val.castTag(.aggregate).?.data;
......@@ -23317,7 +23260,7 @@ fn unionFieldPtr(
2331723260 assert(unresolved_union_ty.zigTypeTag() == .Union);
2331823261
2331923262 const union_ptr_ty = sema.typeOf(union_ptr);
23320 const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty);
23263 const union_ty = try sema.resolveTypeFields(unresolved_union_ty);
2332123264 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
2332223265 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
2332323266 const field = union_obj.fields.values()[field_index];
......@@ -23410,13 +23353,13 @@ fn unionFieldVal(
2341023353) CompileError!Air.Inst.Ref {
2341123354 assert(unresolved_union_ty.zigTypeTag() == .Union);
2341223355
23413 const union_ty = try sema.resolveTypeFields(block, src, unresolved_union_ty);
23356 const union_ty = try sema.resolveTypeFields(unresolved_union_ty);
2341423357 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
2341523358 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
2341623359 const field = union_obj.fields.values()[field_index];
2341723360 const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name).?);
2341823361
23419 if (try sema.resolveMaybeUndefVal(block, src, union_byval)) |union_val| {
23362 if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| {
2342023363 if (union_val.isUndef()) return sema.addConstUndef(field.ty);
2342123364
2342223365 const tag_and_val = union_val.castTag(.@"union").?.data;
......@@ -23586,7 +23529,7 @@ fn elemVal(
2358623529 // Tuple field access.
2358723530 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
2358823531 const index = @intCast(u32, index_val.toUnsignedInt(target));
23589 return tupleField(sema, block, indexable_src, indexable, elem_index_src, index);
23532 return sema.tupleField(block, indexable_src, indexable, elem_index_src, index);
2359023533 },
2359123534 else => unreachable,
2359223535 }
......@@ -23600,7 +23543,7 @@ fn validateRuntimeElemAccess(
2360023543 parent_ty: Type,
2360123544 parent_src: LazySrcLoc,
2360223545) CompileError!void {
23603 const valid_rt = try sema.validateRunTimeType(block, elem_index_src, elem_ty, false);
23546 const valid_rt = try sema.validateRunTimeType(elem_ty, false);
2360423547 if (!valid_rt) {
2360523548 const msg = msg: {
2360623549 const msg = try sema.errMsg(
......@@ -23659,7 +23602,7 @@ fn tupleFieldPtr(
2365923602 return sema.addConstant(ptr_field_ty, val);
2366023603 }
2366123604
23662 if (try sema.resolveMaybeUndefVal(block, tuple_ptr_src, tuple_ptr)) |tuple_ptr_val| {
23605 if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| {
2366323606 return sema.addConstant(
2366423607 ptr_field_ty,
2366523608 try Value.Tag.field_ptr.create(sema.arena, .{
......@@ -23706,7 +23649,7 @@ fn tupleField(
2370623649 return sema.addConstant(field_ty, field_val); // comptime field
2370723650 }
2370823651
23709 if (try sema.resolveMaybeUndefVal(block, tuple_src, tuple)) |tuple_val| {
23652 if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| {
2371023653 if (tuple_val.isUndef()) return sema.addConstUndef(field_ty);
2371123654 return sema.addConstant(field_ty, tuple_val.fieldValue(tuple_ty, field_index));
2371223655 }
......@@ -23736,7 +23679,7 @@ fn elemValArray(
2373623679 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});
2373723680 }
2373823681
23739 const maybe_undef_array_val = try sema.resolveMaybeUndefVal(block, array_src, array);
23682 const maybe_undef_array_val = try sema.resolveMaybeUndefVal(array);
2374023683 // index must be defined since it can access out of bounds
2374123684 const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
2374223685 const target = sema.mod.getTarget();
......@@ -23800,7 +23743,7 @@ fn elemPtrArray(
2380023743 return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{});
2380123744 }
2380223745
23803 const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(block, array_ptr_src, array_ptr);
23746 const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(array_ptr);
2380423747 // The index must not be undefined since it can be out of bounds.
2380523748 const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
2380623749 const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target));
......@@ -23909,7 +23852,7 @@ fn elemPtrSlice(
2390923852 const slice_ty = sema.typeOf(slice);
2391023853 const slice_sent = slice_ty.sentinel() != null;
2391123854
23912 const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(block, slice_src, slice);
23855 const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(slice);
2391323856 // The index must not be undefined since it can be out of bounds.
2391423857 const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
2391523858 const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(target));
......@@ -23996,15 +23939,15 @@ fn coerceExtra(
2399623939 else => {},
2399723940 }
2399823941 const dest_ty_src = inst_src; // TODO better source location
23999 const dest_ty = try sema.resolveTypeFields(block, dest_ty_src, dest_ty_unresolved);
24000 const inst_ty = try sema.resolveTypeFields(block, inst_src, sema.typeOf(inst));
23942 const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved);
23943 const inst_ty = try sema.resolveTypeFields(sema.typeOf(inst));
2400123944 const target = sema.mod.getTarget();
2400223945 // If the types are the same, we can return the operand.
2400323946 if (dest_ty.eql(inst_ty, sema.mod))
2400423947 return inst;
2400523948
2400623949 const arena = sema.arena;
24007 const maybe_inst_val = try sema.resolveMaybeUndefVal(block, inst_src, inst);
23950 const maybe_inst_val = try sema.resolveMaybeUndefVal(inst);
2400823951
2400923952 var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);
2401023953 if (in_memory_result == .ok) {
......@@ -24354,7 +24297,7 @@ fn coerceExtra(
2435424297 .Int, .ComptimeInt => {
2435524298 if (try sema.resolveDefinedValue(block, inst_src, inst)) |val| {
2435624299 // comptime-known integer to other number
24357 if (!(try sema.intFitsInType(block, inst_src, val, dest_ty, null))) {
24300 if (!(try sema.intFitsInType(val, dest_ty, null))) {
2435824301 if (!opts.report_err) return error.NotCoercible;
2435924302 return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) });
2436024303 }
......@@ -24421,7 +24364,7 @@ fn coerceExtra(
2442124364 }
2442224365 break :int;
2442324366 };
24424 const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, target, sema.kit(block, inst_src));
24367 const result_val = try val.intToFloatAdvanced(sema.arena, inst_ty, dest_ty, target, sema);
2442524368 // TODO implement this compile error
2442624369 //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty);
2442724370 //if (!int_again_val.eql(val, inst_ty, mod)) {
......@@ -24559,7 +24502,7 @@ fn coerceExtra(
2455924502 return sema.structInitEmpty(block, dest_ty, dest_ty_src, inst_src);
2456024503 }
2456124504 if (inst_ty.isTupleOrAnonStruct()) {
24562 return sema.coerceTupleToStruct(block, dest_ty, dest_ty_src, inst, inst_src);
24505 return sema.coerceTupleToStruct(block, dest_ty, inst, inst_src);
2456324506 }
2456424507 },
2456524508 else => {},
......@@ -25031,8 +24974,8 @@ fn coerceInMemoryAllowed(
2503124974 // Pointers / Pointer-like Optionals
2503224975 var dest_buf: Type.Payload.ElemType = undefined;
2503324976 var src_buf: Type.Payload.ElemType = undefined;
25034 const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(block, dest_ty, &dest_buf, dest_src);
25035 const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(block, src_ty, &src_buf, src_src);
24977 const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(dest_ty, &dest_buf);
24978 const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(src_ty, &src_buf);
2503624979 if (maybe_dest_ptr_ty) |dest_ptr_ty| {
2503724980 if (maybe_src_ptr_ty) |src_ptr_ty| {
2503824981 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ptr_ty, src_ptr_ty, dest_is_mut, target, dest_src, src_src);
......@@ -25528,7 +25471,7 @@ fn coerceVarArgParam(
2552825471 };
2552925472
2553025473 const coerced_ty = sema.typeOf(coerced);
25531 if (!try sema.validateExternType(block, inst_src, coerced_ty, .param_ty)) {
25474 if (!try sema.validateExternType(coerced_ty, .param_ty)) {
2553225475 const msg = msg: {
2553325476 const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)});
2553425477 errdefer msg.destroy(sema.gpa);
......@@ -25585,7 +25528,7 @@ fn storePtr2(
2558525528 for (tuple.types) |_, i_usize| {
2558625529 const i = @intCast(u32, i_usize);
2558725530 const elem_src = operand_src; // TODO better source location
25588 const elem = try tupleField(sema, block, operand_src, uncasted_operand, elem_src, i);
25531 const elem = try sema.tupleField(block, operand_src, uncasted_operand, elem_src, i);
2558925532 const elem_index = try sema.addIntUnsigned(Type.usize, i);
2559025533 const elem_ptr = try sema.elemPtr(block, ptr_src, ptr, elem_index, elem_src, false);
2559125534 try sema.storePtr2(block, src, elem_ptr, elem_src, elem, elem_src, .store);
......@@ -25618,7 +25561,7 @@ fn storePtr2(
2561825561 error.NotCoercible => unreachable,
2561925562 else => |e| return e,
2562025563 };
25621 const maybe_operand_val = try sema.resolveMaybeUndefVal(block, operand_src, operand);
25564 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
2562225565
2562325566 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
2562425567 const operand_val = maybe_operand_val orelse {
......@@ -25633,7 +25576,7 @@ fn storePtr2(
2563325576
2563425577 // We do this after the possible comptime store above, for the case of field_ptr stores
2563525578 // to unions because we want the comptime tag to be set, even if the field type is void.
25636 if ((try sema.typeHasOnePossibleValue(block, src, elem_ty)) != null)
25579 if ((try sema.typeHasOnePossibleValue(elem_ty)) != null)
2563725580 return;
2563825581
2563925582 if (air_tag == .bitcast) {
......@@ -25695,7 +25638,7 @@ fn storePtrVal(
2569525638 operand_val: Value,
2569625639 operand_ty: Type,
2569725640) !void {
25698 var mut_kit = try beginComptimePtrMutation(sema, block, src, ptr_val, operand_ty);
25641 var mut_kit = try sema.beginComptimePtrMutation(block, src, ptr_val, operand_ty);
2569925642 try sema.checkComptimeVarStore(block, src, mut_kit.decl_ref_mut);
2570025643
2570125644 switch (mut_kit.pointee) {
......@@ -25784,20 +25727,20 @@ fn beginComptimePtrMutation(
2578425727 .decl_ref_mut => {
2578525728 const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data;
2578625729 const decl = sema.mod.declPtr(decl_ref_mut.decl_index);
25787 return beginComptimePtrMutationInner(sema, block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut);
25730 return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut);
2578825731 },
2578925732 .comptime_field_ptr => {
2579025733 const payload = ptr_val.castTag(.comptime_field_ptr).?.data;
2579125734 const duped = try sema.arena.create(Value);
2579225735 duped.* = payload.field_val;
25793 return beginComptimePtrMutationInner(sema, block, src, payload.field_ty, duped, ptr_elem_ty, .{
25736 return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{
2579425737 .decl_index = @intToEnum(Module.Decl.Index, 0),
2579525738 .runtime_index = .comptime_field_ptr,
2579625739 });
2579725740 },
2579825741 .elem_ptr => {
2579925742 const elem_ptr = ptr_val.castTag(.elem_ptr).?.data;
25800 var parent = try beginComptimePtrMutation(sema, block, src, elem_ptr.array_ptr, elem_ptr.elem_ty);
25743 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty);
2580125744 switch (parent.pointee) {
2580225745 .direct => |val_ptr| switch (parent.ty.zigTypeTag()) {
2580325746 .Array, .Vector => {
......@@ -25987,7 +25930,7 @@ fn beginComptimePtrMutation(
2598725930 };
2598825931 }
2598925932
25990 const elem_abi_size_u64 = try sema.typeAbiSize(block, src, elem_ptr.elem_ty);
25933 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);
2599125934 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
2599225935 return ComptimePtrMutationKit{
2599325936 .decl_ref_mut = parent.decl_ref_mut,
......@@ -26005,7 +25948,7 @@ fn beginComptimePtrMutation(
2600525948 const field_ptr = ptr_val.castTag(.field_ptr).?.data;
2600625949 const field_index = @intCast(u32, field_ptr.field_index);
2600725950
26008 var parent = try beginComptimePtrMutation(sema, block, src, field_ptr.container_ptr, field_ptr.container_ty);
25951 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.container_ptr, field_ptr.container_ty);
2600925952 switch (parent.pointee) {
2601025953 .direct => |val_ptr| switch (val_ptr.tag()) {
2601125954 .undef => {
......@@ -26169,7 +26112,7 @@ fn beginComptimePtrMutation(
2616926112 },
2617026113 .eu_payload_ptr => {
2617126114 const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data;
26172 var parent = try beginComptimePtrMutation(sema, block, src, eu_ptr.container_ptr, eu_ptr.container_ty);
26115 var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.container_ptr, eu_ptr.container_ty);
2617326116 switch (parent.pointee) {
2617426117 .direct => |val_ptr| {
2617526118 const payload_ty = parent.ty.errorUnionPayload();
......@@ -26216,7 +26159,7 @@ fn beginComptimePtrMutation(
2621626159 const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else {
2621726160 return sema.beginComptimePtrMutation(block, src, ptr_val, try ptr_elem_ty.optionalChildAlloc(sema.arena));
2621826161 };
26219 var parent = try beginComptimePtrMutation(sema, block, src, opt_ptr.container_ptr, opt_ptr.container_ty);
26162 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty);
2622026163 switch (parent.pointee) {
2622126164 .direct => |val_ptr| {
2622226165 const payload_ty = try parent.ty.optionalChildAlloc(sema.arena);
......@@ -26385,7 +26328,7 @@ fn beginComptimePtrLoad(
2638526328 .elem_ptr => blk: {
2638626329 const elem_ptr = ptr_val.castTag(.elem_ptr).?.data;
2638726330 const elem_ty = elem_ptr.elem_ty;
26388 var deref = try beginComptimePtrLoad(sema, block, src, elem_ptr.array_ptr, null);
26331 var deref = try sema.beginComptimePtrLoad(block, src, elem_ptr.array_ptr, null);
2638926332
2639026333 // This code assumes that elem_ptrs have been "flattened" in order for direct dereference
2639126334 // to succeed, meaning that elem ptrs of the same elem_ty are coalesced. Here we check that
......@@ -26398,7 +26341,7 @@ fn beginComptimePtrLoad(
2639826341 if (elem_ty.hasWellDefinedLayout()) {
2639926342 if (deref.parent) |*parent| {
2640026343 // Update the byte offset (in-place)
26401 const elem_size = try sema.typeAbiSize(block, src, elem_ty);
26344 const elem_size = try sema.typeAbiSize(elem_ty);
2640226345 const offset = parent.byte_offset + elem_size * elem_ptr.index;
2640326346 parent.byte_offset = try sema.usizeCast(block, src, offset);
2640426347 }
......@@ -26457,13 +26400,13 @@ fn beginComptimePtrLoad(
2645726400
2645826401 .slice => blk: {
2645926402 const slice = ptr_val.castTag(.slice).?.data;
26460 break :blk try beginComptimePtrLoad(sema, block, src, slice.ptr, null);
26403 break :blk try sema.beginComptimePtrLoad(block, src, slice.ptr, null);
2646126404 },
2646226405
2646326406 .field_ptr => blk: {
2646426407 const field_ptr = ptr_val.castTag(.field_ptr).?.data;
2646526408 const field_index = @intCast(u32, field_ptr.field_index);
26466 var deref = try beginComptimePtrLoad(sema, block, src, field_ptr.container_ptr, field_ptr.container_ty);
26409 var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.container_ptr, field_ptr.container_ty);
2646726410
2646826411 if (field_ptr.container_ty.hasWellDefinedLayout()) {
2646926412 const struct_ty = field_ptr.container_ty.castTag(.@"struct");
......@@ -26472,7 +26415,7 @@ fn beginComptimePtrLoad(
2647226415 deref.parent = null;
2647326416 } else if (deref.parent) |*parent| {
2647426417 // Update the byte offset (in-place)
26475 try sema.resolveTypeLayout(block, src, field_ptr.container_ty);
26418 try sema.resolveTypeLayout(field_ptr.container_ty);
2647626419 const field_offset = field_ptr.container_ty.structFieldOffset(field_index, target);
2647726420 parent.byte_offset = try sema.usizeCast(block, src, parent.byte_offset + field_offset);
2647826421 }
......@@ -26535,7 +26478,7 @@ fn beginComptimePtrLoad(
2653526478 .opt_payload_ptr => try payload_ptr.container_ty.optionalChildAlloc(sema.arena),
2653626479 else => unreachable,
2653726480 };
26538 var deref = try beginComptimePtrLoad(sema, block, src, payload_ptr.container_ptr, payload_ptr.container_ty);
26481 var deref = try sema.beginComptimePtrLoad(block, src, payload_ptr.container_ptr, payload_ptr.container_ty);
2653926482
2654026483 // eu_payload_ptr and opt_payload_ptr never have a well-defined layout
2654126484 if (deref.parent != null) {
......@@ -26598,11 +26541,11 @@ fn bitCast(
2659826541 inst: Air.Inst.Ref,
2659926542 inst_src: LazySrcLoc,
2660026543) CompileError!Air.Inst.Ref {
26601 const dest_ty = try sema.resolveTypeFields(block, inst_src, dest_ty_unresolved);
26602 try sema.resolveTypeLayout(block, inst_src, dest_ty);
26544 const dest_ty = try sema.resolveTypeFields(dest_ty_unresolved);
26545 try sema.resolveTypeLayout(dest_ty);
2660326546
26604 const old_ty = try sema.resolveTypeFields(block, inst_src, sema.typeOf(inst));
26605 try sema.resolveTypeLayout(block, inst_src, old_ty);
26547 const old_ty = try sema.resolveTypeFields(sema.typeOf(inst));
26548 try sema.resolveTypeLayout(old_ty);
2660626549
2660726550 const target = sema.mod.getTarget();
2660826551 const dest_bits = dest_ty.bitSize(target);
......@@ -26617,7 +26560,7 @@ fn bitCast(
2661726560 });
2661826561 }
2661926562
26620 if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| {
26563 if (try sema.resolveMaybeUndefVal(inst)) |val| {
2662126564 const result_val = try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0);
2662226565 return sema.addConstant(dest_ty, result_val);
2662326566 }
......@@ -26653,7 +26596,7 @@ fn coerceArrayPtrToSlice(
2665326596 inst: Air.Inst.Ref,
2665426597 inst_src: LazySrcLoc,
2665526598) CompileError!Air.Inst.Ref {
26656 if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| {
26599 if (try sema.resolveMaybeUndefVal(inst)) |val| {
2665726600 const ptr_array_ty = sema.typeOf(inst);
2665826601 const array_ty = ptr_array_ty.childType();
2665926602 const slice_val = try Value.Tag.slice.create(sema.arena, .{
......@@ -26725,14 +26668,14 @@ fn coerceCompatiblePtrs(
2672526668 inst_src: LazySrcLoc,
2672626669) !Air.Inst.Ref {
2672726670 const inst_ty = sema.typeOf(inst);
26728 if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| {
26671 if (try sema.resolveMaybeUndefVal(inst)) |val| {
2672926672 // The comptime Value representation is compatible with both types.
2673026673 return sema.addConstant(dest_ty, val);
2673126674 }
2673226675 try sema.requireRuntimeBlock(block, inst_src, null);
2673326676 const inst_allows_zero = (inst_ty.zigTypeTag() == .Pointer and inst_ty.ptrAllowsZero()) or true;
2673426677 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero() and
26735 try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2()))
26678 try sema.typeHasRuntimeBits(dest_ty.elemType2()))
2673626679 {
2673726680 const actual_ptr = if (inst_ty.isSlice())
2673826681 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
......@@ -26789,7 +26732,7 @@ fn coerceEnumToUnion(
2678926732
2679026733 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
2679126734 const field = union_obj.fields.values()[field_index];
26792 const field_ty = try sema.resolveTypeFields(block, inst_src, field.ty);
26735 const field_ty = try sema.resolveTypeFields(field.ty);
2679326736 if (field_ty.zigTypeTag() == .NoReturn) {
2679426737 const msg = msg: {
2679526738 const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{});
......@@ -26802,7 +26745,7 @@ fn coerceEnumToUnion(
2680226745 };
2680326746 return sema.failWithOwnedErrorMsg(msg);
2680426747 }
26805 const opv = (try sema.typeHasOnePossibleValue(block, inst_src, field_ty)) orelse {
26748 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
2680626749 const msg = msg: {
2680726750 const field_name = union_obj.fields.keys()[field_index];
2680826751 const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{s}'", .{
......@@ -26954,7 +26897,7 @@ fn coerceAnonStructToStructPtrs(
2695426897) !Air.Inst.Ref {
2695526898 const struct_ty = ptr_struct_ty.childType();
2695626899 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
26957 const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, struct_ty_src, anon_struct, anon_struct_src);
26900 const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, anon_struct, anon_struct_src);
2695826901 return sema.analyzeRef(block, struct_ty_src, struct_inst);
2695926902}
2696026903
......@@ -26989,7 +26932,7 @@ fn coerceArrayLike(
2698926932 const inst_elem_ty = inst_ty.childType();
2699026933 const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_elem_ty, inst_elem_ty, false, target, dest_ty_src, inst_src);
2699126934 if (in_memory_result == .ok) {
26992 if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |inst_val| {
26935 if (try sema.resolveMaybeUndefVal(inst)) |inst_val| {
2699326936 // These types share the same comptime value representation.
2699426937 return sema.addConstant(dest_ty, inst_val);
2699526938 }
......@@ -27012,7 +26955,7 @@ fn coerceArrayLike(
2701226955 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
2701326956 element_refs[i] = coerced;
2701426957 if (runtime_src == null) {
27015 if (try sema.resolveMaybeUndefVal(block, elem_src, coerced)) |elem_val| {
26958 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
2701626959 elem.* = elem_val;
2701726960 } else {
2701826961 runtime_src = elem_src;
......@@ -27071,11 +27014,11 @@ fn coerceTupleToArray(
2707127014 break;
2707227015 }
2707327016 const elem_src = inst_src; // TODO better source location
27074 const elem_ref = try tupleField(sema, block, inst_src, inst, elem_src, i);
27017 const elem_ref = try sema.tupleField(block, inst_src, inst, elem_src, i);
2707527018 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
2707627019 element_refs[i] = coerced;
2707727020 if (runtime_src == null) {
27078 if (try sema.resolveMaybeUndefVal(block, elem_src, coerced)) |elem_val| {
27021 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
2707927022 elem.* = elem_val;
2708027023 } else {
2708127024 runtime_src = elem_src;
......@@ -27141,11 +27084,10 @@ fn coerceTupleToStruct(
2714127084 sema: *Sema,
2714227085 block: *Block,
2714327086 dest_ty: Type,
27144 dest_ty_src: LazySrcLoc,
2714527087 inst: Air.Inst.Ref,
2714627088 inst_src: LazySrcLoc,
2714727089) !Air.Inst.Ref {
27148 const struct_ty = try sema.resolveTypeFields(block, dest_ty_src, dest_ty);
27090 const struct_ty = try sema.resolveTypeFields(dest_ty);
2714927091
2715027092 if (struct_ty.isTupleOrAnonStruct()) {
2715127093 return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src);
......@@ -27168,11 +27110,11 @@ fn coerceTupleToStruct(
2716827110 try std.fmt.allocPrint(sema.arena, "{d}", .{i});
2716927111 const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);
2717027112 const field = fields.values()[field_index];
27171 const elem_ref = try tupleField(sema, block, inst_src, inst, field_src, i);
27113 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, i);
2717227114 const coerced = try sema.coerce(block, field.ty, elem_ref, field_src);
2717327115 field_refs[field_index] = coerced;
2717427116 if (field.is_comptime) {
27175 const init_val = (try sema.resolveMaybeUndefVal(block, field_src, coerced)) orelse {
27117 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
2717627118 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
2717727119 };
2717827120
......@@ -27181,7 +27123,7 @@ fn coerceTupleToStruct(
2718127123 }
2718227124 }
2718327125 if (runtime_src == null) {
27184 if (try sema.resolveMaybeUndefVal(block, field_src, coerced)) |field_val| {
27126 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
2718527127 field_vals[field_index] = field_val;
2718627128 } else {
2718727129 runtime_src = field_src;
......@@ -27264,11 +27206,11 @@ fn coerceTupleToTuple(
2726427206
2726527207 const field_ty = tuple_ty.structFieldType(i);
2726627208 const default_val = tuple_ty.structFieldDefaultValue(i);
27267 const elem_ref = try tupleField(sema, block, inst_src, inst, field_src, i);
27209 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, i);
2726827210 const coerced = try sema.coerce(block, field_ty, elem_ref, field_src);
2726927211 field_refs[field_index] = coerced;
2727027212 if (default_val.tag() != .unreachable_value) {
27271 const init_val = (try sema.resolveMaybeUndefVal(block, field_src, coerced)) orelse {
27213 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
2727227214 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
2727327215 };
2727427216
......@@ -27277,7 +27219,7 @@ fn coerceTupleToTuple(
2727727219 }
2727827220 }
2727927221 if (runtime_src == null) {
27280 if (try sema.resolveMaybeUndefVal(block, field_src, coerced)) |field_val| {
27222 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
2728127223 field_vals[field_index] = field_val;
2728227224 } else {
2728327225 runtime_src = field_src;
......@@ -27400,8 +27342,8 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: *Module.Fn) CompileError!void {
2740027342 };
2740127343}
2740227344
27403fn refValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, val: Value) !Value {
27404 var anon_decl = try block.startAnonDecl(src);
27345fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value {
27346 var anon_decl = try block.startAnonDecl();
2740527347 defer anon_decl.deinit();
2740627348 const decl = try anon_decl.finish(
2740727349 try ty.copy(anon_decl.arena()),
......@@ -27412,9 +27354,9 @@ fn refValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, val: Value) !
2741227354 return try Value.Tag.decl_ref.create(sema.arena, decl);
2741327355}
2741427356
27415fn optRefValue(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, opt_val: ?Value) !Value {
27357fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value {
2741627358 const val = opt_val orelse return Value.@"null";
27417 const ptr_val = try refValue(sema, block, src, ty, val);
27359 const ptr_val = try sema.refValue(block, ty, val);
2741827360 const result = try Value.Tag.opt_payload.create(sema.arena, ptr_val);
2741927361 return result;
2742027362}
......@@ -27454,8 +27396,8 @@ fn analyzeRef(
2745427396) CompileError!Air.Inst.Ref {
2745527397 const operand_ty = sema.typeOf(operand);
2745627398
27457 if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| {
27458 var anon_decl = try block.startAnonDecl(src);
27399 if (try sema.resolveMaybeUndefVal(operand)) |val| {
27400 var anon_decl = try block.startAnonDecl();
2745927401 defer anon_decl.deinit();
2746027402 return sema.analyzeDeclRef(try anon_decl.finish(
2746127403 try operand_ty.copy(anon_decl.arena()),
......@@ -27495,7 +27437,7 @@ fn analyzeLoad(
2749527437 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}),
2749627438 };
2749727439
27498 if (try sema.typeHasOnePossibleValue(block, src, elem_ty)) |opv| {
27440 if (try sema.typeHasOnePossibleValue(elem_ty)) |opv| {
2749927441 return sema.addConstant(elem_ty, opv);
2750027442 }
2750127443
......@@ -27517,7 +27459,7 @@ fn analyzeSlicePtr(
2751727459) CompileError!Air.Inst.Ref {
2751827460 const buf = try sema.arena.create(Type.SlicePtrFieldTypeBuffer);
2751927461 const result_ty = slice_ty.slicePtrFieldType(buf);
27520 if (try sema.resolveMaybeUndefVal(block, slice_src, slice)) |val| {
27462 if (try sema.resolveMaybeUndefVal(slice)) |val| {
2752127463 if (val.isUndef()) return sema.addConstUndef(result_ty);
2752227464 return sema.addConstant(result_ty, val.slicePtr());
2752327465 }
......@@ -27531,7 +27473,7 @@ fn analyzeSliceLen(
2753127473 src: LazySrcLoc,
2753227474 slice_inst: Air.Inst.Ref,
2753327475) CompileError!Air.Inst.Ref {
27534 if (try sema.resolveMaybeUndefVal(block, src, slice_inst)) |slice_val| {
27476 if (try sema.resolveMaybeUndefVal(slice_inst)) |slice_val| {
2753527477 if (slice_val.isUndef()) {
2753627478 return sema.addConstUndef(Type.usize);
2753727479 }
......@@ -27549,7 +27491,7 @@ fn analyzeIsNull(
2754927491 invert_logic: bool,
2755027492) CompileError!Air.Inst.Ref {
2755127493 const result_ty = Type.bool;
27552 if (try sema.resolveMaybeUndefVal(block, src, operand)) |opt_val| {
27494 if (try sema.resolveMaybeUndefVal(operand)) |opt_val| {
2755327495 if (opt_val.isUndef()) {
2755427496 return sema.addConstUndef(result_ty);
2755527497 }
......@@ -27627,7 +27569,7 @@ fn analyzeIsNonErrComptimeOnly(
2762727569 return Air.Inst.Ref.bool_true;
2762827570 }
2762927571
27630 const maybe_operand_val = try sema.resolveMaybeUndefVal(block, src, operand);
27572 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
2763127573
2763227574 // exception if the error union error set is known to be empty,
2763327575 // we allow the comparison but always make it comptime-known.
......@@ -27791,7 +27733,7 @@ fn analyzeSlice(
2779127733 ptr_or_slice;
2779227734
2779327735 const start = try sema.coerce(block, Type.usize, uncasted_start, start_src);
27794 const new_ptr = try analyzePtrArithmetic(sema, block, src, ptr, start, .ptr_add, ptr_src, start_src);
27736 const new_ptr = try sema.analyzePtrArithmetic(block, src, ptr, start, .ptr_add, ptr_src, start_src);
2779527737
2779627738 // true if and only if the end index of the slice, implicitly or explicitly, equals
2779727739 // the length of the underlying object being sliced. we might learn the length of the
......@@ -27804,12 +27746,12 @@ fn analyzeSlice(
2780427746
2780527747 if (!end_is_len) {
2780627748 const end = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
27807 if (try sema.resolveMaybeUndefVal(block, end_src, end)) |end_val| {
27749 if (try sema.resolveMaybeUndefVal(end)) |end_val| {
2780827750 const len_s_val = try Value.Tag.int_u64.create(
2780927751 sema.arena,
2781027752 array_ty.arrayLenIncludingSentinel(),
2781127753 );
27812 if (!(try sema.compareAll(block, src, end_val, .lte, len_s_val, Type.usize))) {
27754 if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) {
2781327755 const sentinel_label: []const u8 = if (array_ty.sentinel() != null)
2781427756 " +1 (sentinel)"
2781527757 else
......@@ -27842,7 +27784,7 @@ fn analyzeSlice(
2784227784 if (!end_is_len) {
2784327785 const end = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
2784427786 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
27845 if (try sema.resolveMaybeUndefVal(block, src, ptr_or_slice)) |slice_val| {
27787 if (try sema.resolveMaybeUndefVal(ptr_or_slice)) |slice_val| {
2784627788 if (slice_val.isUndef()) {
2784727789 return sema.fail(block, src, "slice of undefined", .{});
2784827790 }
......@@ -27852,7 +27794,7 @@ fn analyzeSlice(
2785227794 .data = slice_val.sliceLen(mod) + @boolToInt(has_sentinel),
2785327795 };
2785427796 const slice_len_val = Value.initPayload(&int_payload.base);
27855 if (!(try sema.compareAll(block, src, end_val, .lte, slice_len_val, Type.usize))) {
27797 if (!(try sema.compareAll(end_val, .lte, slice_len_val, Type.usize))) {
2785627798 const sentinel_label: []const u8 = if (has_sentinel)
2785727799 " +1 (sentinel)"
2785827800 else
......@@ -27911,7 +27853,7 @@ fn analyzeSlice(
2791127853 // requirement: start <= end
2791227854 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
2791327855 if (try sema.resolveDefinedValue(block, start_src, start)) |start_val| {
27914 if (!(try sema.compareAll(block, src, start_val, .lte, end_val, Type.usize))) {
27856 if (!(try sema.compareAll(start_val, .lte, end_val, Type.usize))) {
2791527857 return sema.fail(
2791627858 block,
2791727859 start_src,
......@@ -27922,7 +27864,7 @@ fn analyzeSlice(
2792227864 },
2792327865 );
2792427866 }
27925 if (try sema.resolveMaybeUndefVal(block, ptr_src, new_ptr)) |ptr_val| sentinel_check: {
27867 if (try sema.resolveMaybeUndefVal(new_ptr)) |ptr_val| sentinel_check: {
2792627868 const expected_sentinel = sentinel orelse break :sentinel_check;
2792727869 const start_int = start_val.getUnsignedInt(sema.mod.getTarget()).?;
2792827870 const end_int = end_val.getUnsignedInt(sema.mod.getTarget()).?;
......@@ -27984,7 +27926,7 @@ fn analyzeSlice(
2798427926 .size = .One,
2798527927 });
2798627928
27987 const opt_new_ptr_val = try sema.resolveMaybeUndefVal(block, ptr_src, new_ptr);
27929 const opt_new_ptr_val = try sema.resolveMaybeUndefVal(new_ptr);
2798827930 const new_ptr_val = opt_new_ptr_val orelse {
2798927931 const result = try block.addBitCast(return_ty, new_ptr);
2799027932 if (block.wantSafety()) {
......@@ -28038,9 +27980,9 @@ fn analyzeSlice(
2803827980 .size = .Slice,
2803927981 });
2804027982
28041 const runtime_src = if ((try sema.resolveMaybeUndefVal(block, ptr_src, ptr_or_slice)) == null)
27983 const runtime_src = if ((try sema.resolveMaybeUndefVal(ptr_or_slice)) == null)
2804227984 ptr_src
28043 else if ((try sema.resolveMaybeUndefVal(block, src, start)) == null)
27985 else if ((try sema.resolveMaybeUndefVal(start)) == null)
2804427986 start_src
2804527987 else
2804627988 end_src;
......@@ -28132,8 +28074,8 @@ fn cmpNumeric(
2813228074 uncasted_rhs;
2813328075
2813428076 const runtime_src: LazySrcLoc = src: {
28135 if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| {
28136 if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| {
28077 if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
28078 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
2813728079 if (lhs_val.isUndef() or rhs_val.isUndef()) {
2813828080 return sema.addConstUndef(Type.bool);
2813928081 }
......@@ -28144,7 +28086,7 @@ fn cmpNumeric(
2814428086 return Air.Inst.Ref.bool_false;
2814528087 }
2814628088 }
28147 if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, target, sema.kit(block, src))) {
28089 if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, target, sema)) {
2814828090 return Air.Inst.Ref.bool_true;
2814928091 } else {
2815028092 return Air.Inst.Ref.bool_false;
......@@ -28200,11 +28142,11 @@ fn cmpNumeric(
2820028142 // a signed integer with mantissa bits + 1, and if there was any non-integral part of the float,
2820128143 // add/subtract 1.
2820228144 const lhs_is_signed = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val|
28203 !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))
28145 !(try lhs_val.compareAllWithZeroAdvanced(.gte, sema))
2820428146 else
2820528147 (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt());
2820628148 const rhs_is_signed = if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val|
28207 !(try rhs_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))
28149 !(try rhs_val.compareAllWithZeroAdvanced(.gte, sema))
2820828150 else
2820928151 (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt());
2821028152 const dest_int_is_signed = lhs_is_signed or rhs_is_signed;
......@@ -28212,7 +28154,7 @@ fn cmpNumeric(
2821228154 var dest_float_type: ?Type = null;
2821328155
2821428156 var lhs_bits: usize = undefined;
28215 if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| {
28157 if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
2821628158 if (lhs_val.isUndef())
2821728159 return sema.addConstUndef(Type.bool);
2821828160 if (lhs_val.isNan()) switch (op) {
......@@ -28265,7 +28207,7 @@ fn cmpNumeric(
2826528207 }
2826628208
2826728209 var rhs_bits: usize = undefined;
28268 if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| {
28210 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
2826928211 if (rhs_val.isUndef())
2827028212 return sema.addConstUndef(Type.bool);
2827128213 if (rhs_val.isNan()) switch (op) {
......@@ -28349,12 +28291,12 @@ fn cmpVector(
2834928291 const result_ty = try Type.vector(sema.arena, lhs_ty.vectorLen(), Type.@"bool");
2835028292
2835128293 const runtime_src: LazySrcLoc = src: {
28352 if (try sema.resolveMaybeUndefVal(block, lhs_src, lhs)) |lhs_val| {
28353 if (try sema.resolveMaybeUndefVal(block, rhs_src, rhs)) |rhs_val| {
28294 if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
28295 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
2835428296 if (lhs_val.isUndef() or rhs_val.isUndef()) {
2835528297 return sema.addConstUndef(result_ty);
2835628298 }
28357 const cmp_val = try sema.compareVector(block, src, lhs_val, op, rhs_val, lhs_ty);
28299 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, lhs_ty);
2835828300 return sema.addConstant(result_ty, cmp_val);
2835928301 } else {
2836028302 break :src rhs_src;
......@@ -28376,7 +28318,7 @@ fn wrapOptional(
2837628318 inst: Air.Inst.Ref,
2837728319 inst_src: LazySrcLoc,
2837828320) !Air.Inst.Ref {
28379 if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| {
28321 if (try sema.resolveMaybeUndefVal(inst)) |val| {
2838028322 return sema.addConstant(dest_ty, try Value.Tag.opt_payload.create(sema.arena, val));
2838128323 }
2838228324
......@@ -28393,7 +28335,7 @@ fn wrapErrorUnionPayload(
2839328335) !Air.Inst.Ref {
2839428336 const dest_payload_ty = dest_ty.errorUnionPayload();
2839528337 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
28396 if (try sema.resolveMaybeUndefVal(block, inst_src, coerced)) |val| {
28338 if (try sema.resolveMaybeUndefVal(coerced)) |val| {
2839728339 return sema.addConstant(dest_ty, try Value.Tag.eu_payload.create(sema.arena, val));
2839828340 }
2839928341 try sema.requireRuntimeBlock(block, inst_src, null);
......@@ -28410,7 +28352,7 @@ fn wrapErrorUnionSet(
2841028352) !Air.Inst.Ref {
2841128353 const inst_ty = sema.typeOf(inst);
2841228354 const dest_err_set_ty = dest_ty.errorUnionSet();
28413 if (try sema.resolveMaybeUndefVal(block, inst_src, inst)) |val| {
28355 if (try sema.resolveMaybeUndefVal(inst)) |val| {
2841428356 switch (dest_err_set_ty.tag()) {
2841528357 .anyerror => {},
2841628358 .error_set_single => ok: {
......@@ -28464,10 +28406,10 @@ fn unionToTag(
2846428406 un: Air.Inst.Ref,
2846528407 un_src: LazySrcLoc,
2846628408) !Air.Inst.Ref {
28467 if ((try sema.typeHasOnePossibleValue(block, un_src, enum_ty))) |opv| {
28409 if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| {
2846828410 return sema.addConstant(enum_ty, opv);
2846928411 }
28470 if (try sema.resolveMaybeUndefVal(block, un_src, un)) |un_val| {
28412 if (try sema.resolveMaybeUndefVal(un)) |un_val| {
2847128413 return sema.addConstant(enum_ty, un_val.unionTag());
2847228414 }
2847328415 try sema.requireRuntimeBlock(block, un_src, null);
......@@ -29029,72 +28971,57 @@ fn resolvePeerTypes(
2902928971 return chosen_ty;
2903028972}
2903128973
29032pub fn resolveFnTypes(
29033 sema: *Sema,
29034 block: *Block,
29035 src: LazySrcLoc,
29036 fn_info: Type.Payload.Function.Data,
29037) CompileError!void {
29038 try sema.resolveTypeFully(block, src, fn_info.return_type);
28974pub fn resolveFnTypes(sema: *Sema, fn_info: Type.Payload.Function.Data) CompileError!void {
28975 try sema.resolveTypeFully(fn_info.return_type);
2903928976
2904028977 if (sema.mod.comp.bin_file.options.error_return_tracing and fn_info.return_type.isError()) {
2904128978 // Ensure the type exists so that backends can assume that.
29042 _ = try sema.getBuiltinType(block, src, "StackTrace");
28979 _ = try sema.getBuiltinType("StackTrace");
2904328980 }
2904428981
2904528982 for (fn_info.param_types) |param_ty| {
29046 try sema.resolveTypeFully(block, src, param_ty);
28983 try sema.resolveTypeFully(param_ty);
2904728984 }
2904828985}
2904928986
2905028987/// Make it so that calling hash() and eql() on `val` will not assert due
2905128988/// to a type not having its layout resolved.
29052fn resolveLazyValue(
29053 sema: *Sema,
29054 block: *Block,
29055 src: LazySrcLoc,
29056 val: Value,
29057) CompileError!void {
28989fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void {
2905828990 switch (val.tag()) {
2905928991 .lazy_align => {
2906028992 const ty = val.castTag(.lazy_align).?.data;
29061 return sema.resolveTypeLayout(block, src, ty);
28993 return sema.resolveTypeLayout(ty);
2906228994 },
2906328995 .lazy_size => {
2906428996 const ty = val.castTag(.lazy_size).?.data;
29065 return sema.resolveTypeLayout(block, src, ty);
28997 return sema.resolveTypeLayout(ty);
2906628998 },
2906728999 .comptime_field_ptr => {
2906829000 const field_ptr = val.castTag(.comptime_field_ptr).?.data;
29069 return sema.resolveLazyValue(block, src, field_ptr.field_val);
29001 return sema.resolveLazyValue(field_ptr.field_val);
2907029002 },
2907129003 .@"union" => {
2907229004 const union_val = val.castTag(.@"union").?.data;
29073 return sema.resolveLazyValue(block, src, union_val.val);
29005 return sema.resolveLazyValue(union_val.val);
2907429006 },
2907529007 .aggregate => {
2907629008 const aggregate = val.castTag(.aggregate).?.data;
2907729009 for (aggregate) |elem_val| {
29078 try sema.resolveLazyValue(block, src, elem_val);
29010 try sema.resolveLazyValue(elem_val);
2907929011 }
2908029012 },
2908129013 else => return,
2908229014 }
2908329015}
2908429016
29085pub fn resolveTypeLayout(
29086 sema: *Sema,
29087 block: *Block,
29088 src: LazySrcLoc,
29089 ty: Type,
29090) CompileError!void {
29017pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
2909129018 switch (ty.zigTypeTag()) {
29092 .Struct => return sema.resolveStructLayout(block, src, ty),
29093 .Union => return sema.resolveUnionLayout(block, src, ty),
29019 .Struct => return sema.resolveStructLayout(ty),
29020 .Union => return sema.resolveUnionLayout(ty),
2909429021 .Array => {
2909529022 if (ty.arrayLenIncludingSentinel() == 0) return;
2909629023 const elem_ty = ty.childType();
29097 return sema.resolveTypeLayout(block, src, elem_ty);
29024 return sema.resolveTypeLayout(elem_ty);
2909829025 },
2909929026 .Optional => {
2910029027 var buf: Type.Payload.ElemType = undefined;
......@@ -29103,23 +29030,18 @@ pub fn resolveTypeLayout(
2910329030 // for hasRuntimeBits() of the payload type, so we need "requires comptime"
2910429031 // to be known already before this function returns.
2910529032 _ = try sema.typeRequiresComptime(payload_ty);
29106 return sema.resolveTypeLayout(block, src, payload_ty);
29033 return sema.resolveTypeLayout(payload_ty);
2910729034 },
2910829035 .ErrorUnion => {
2910929036 const payload_ty = ty.errorUnionPayload();
29110 return sema.resolveTypeLayout(block, src, payload_ty);
29037 return sema.resolveTypeLayout(payload_ty);
2911129038 },
2911229039 else => {},
2911329040 }
2911429041}
2911529042
29116fn resolveStructLayout(
29117 sema: *Sema,
29118 block: *Block,
29119 src: LazySrcLoc,
29120 ty: Type,
29121) CompileError!void {
29122 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
29043fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
29044 const resolved_ty = try sema.resolveTypeFields(ty);
2912329045 if (resolved_ty.castTag(.@"struct")) |payload| {
2912429046 const struct_obj = payload.data;
2912529047 switch (struct_obj.status) {
......@@ -29137,7 +29059,7 @@ fn resolveStructLayout(
2913729059 }
2913829060 struct_obj.status = .layout_wip;
2913929061 for (struct_obj.fields.values()) |field, i| {
29140 sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) {
29062 sema.resolveTypeLayout(field.ty) catch |err| switch (err) {
2914129063 error.AnalysisFail => {
2914229064 const msg = sema.err orelse return err;
2914329065 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
......@@ -29301,13 +29223,8 @@ fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_
2930129223 }
2930229224}
2930329225
29304fn resolveUnionLayout(
29305 sema: *Sema,
29306 block: *Block,
29307 src: LazySrcLoc,
29308 ty: Type,
29309) CompileError!void {
29310 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
29226fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
29227 const resolved_ty = try sema.resolveTypeFields(ty);
2931129228 const union_obj = resolved_ty.cast(Type.Payload.Union).?.data;
2931229229 switch (union_obj.status) {
2931329230 .none, .have_field_types => {},
......@@ -29324,7 +29241,7 @@ fn resolveUnionLayout(
2932429241 }
2932529242 union_obj.status = .layout_wip;
2932629243 for (union_obj.fields.values()) |field, i| {
29327 sema.resolveTypeLayout(block, src, field.ty) catch |err| switch (err) {
29244 sema.resolveTypeLayout(field.ty) catch |err| switch (err) {
2932829245 error.AnalysisFail => {
2932929246 const msg = sema.err orelse return err;
2933029247 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
......@@ -29338,35 +29255,30 @@ fn resolveUnionLayout(
2933829255
2933929256/// Returns `error.AnalysisFail` if any of the types (recursively) failed to
2934029257/// be resolved.
29341pub fn resolveTypeFully(
29342 sema: *Sema,
29343 block: *Block,
29344 src: LazySrcLoc,
29345 ty: Type,
29346) CompileError!void {
29258pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
2934729259 switch (ty.zigTypeTag()) {
2934829260 .Pointer => {
29349 const child_ty = try sema.resolveTypeFields(block, src, ty.childType());
29350 return resolveTypeFully(sema, block, src, child_ty);
29261 const child_ty = try sema.resolveTypeFields(ty.childType());
29262 return sema.resolveTypeFully(child_ty);
2935129263 },
2935229264 .Struct => switch (ty.tag()) {
29353 .@"struct" => return resolveStructFully(sema, block, src, ty),
29265 .@"struct" => return sema.resolveStructFully(ty),
2935429266 .tuple, .anon_struct => {
2935529267 const tuple = ty.tupleFields();
2935629268
2935729269 for (tuple.types) |field_ty| {
29358 try sema.resolveTypeFully(block, src, field_ty);
29270 try sema.resolveTypeFully(field_ty);
2935929271 }
2936029272 },
2936129273 else => {},
2936229274 },
29363 .Union => return resolveUnionFully(sema, block, src, ty),
29364 .Array => return resolveTypeFully(sema, block, src, ty.childType()),
29275 .Union => return sema.resolveUnionFully(ty),
29276 .Array => return sema.resolveTypeFully(ty.childType()),
2936529277 .Optional => {
2936629278 var buf: Type.Payload.ElemType = undefined;
29367 return resolveTypeFully(sema, block, src, ty.optionalChild(&buf));
29279 return sema.resolveTypeFully(ty.optionalChild(&buf));
2936829280 },
29369 .ErrorUnion => return resolveTypeFully(sema, block, src, ty.errorUnionPayload()),
29281 .ErrorUnion => return sema.resolveTypeFully(ty.errorUnionPayload()),
2937029282 .Fn => {
2937129283 const info = ty.fnInfo();
2937229284 if (info.is_generic) {
......@@ -29375,25 +29287,18 @@ pub fn resolveTypeFully(
2937529287 return;
2937629288 }
2937729289 for (info.param_types) |param_ty| {
29378 const param_ty_src = src; // TODO better source location
29379 try sema.resolveTypeFully(block, param_ty_src, param_ty);
29290 try sema.resolveTypeFully(param_ty);
2938029291 }
29381 const return_ty_src = src; // TODO better source location
29382 try sema.resolveTypeFully(block, return_ty_src, info.return_type);
29292 try sema.resolveTypeFully(info.return_type);
2938329293 },
2938429294 else => {},
2938529295 }
2938629296}
2938729297
29388fn resolveStructFully(
29389 sema: *Sema,
29390 block: *Block,
29391 src: LazySrcLoc,
29392 ty: Type,
29393) CompileError!void {
29394 try resolveStructLayout(sema, block, src, ty);
29298fn resolveStructFully(sema: *Sema, ty: Type) CompileError!void {
29299 try sema.resolveStructLayout(ty);
2939529300
29396 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
29301 const resolved_ty = try sema.resolveTypeFields(ty);
2939729302 const payload = resolved_ty.castTag(.@"struct").?;
2939829303 const struct_obj = payload.data;
2939929304
......@@ -29411,7 +29316,7 @@ fn resolveStructFully(
2941129316
2941229317 struct_obj.status = .fully_resolved_wip;
2941329318 for (struct_obj.fields.values()) |field| {
29414 try sema.resolveTypeFully(block, src, field.ty);
29319 try sema.resolveTypeFully(field.ty);
2941529320 }
2941629321 struct_obj.status = .fully_resolved;
2941729322 }
......@@ -29420,15 +29325,10 @@ fn resolveStructFully(
2942029325 _ = try sema.typeRequiresComptime(ty);
2942129326}
2942229327
29423fn resolveUnionFully(
29424 sema: *Sema,
29425 block: *Block,
29426 src: LazySrcLoc,
29427 ty: Type,
29428) CompileError!void {
29429 try resolveUnionLayout(sema, block, src, ty);
29328fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
29329 try sema.resolveUnionLayout(ty);
2943029330
29431 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
29331 const resolved_ty = try sema.resolveTypeFields(ty);
2943229332 const union_obj = resolved_ty.cast(Type.Payload.Union).?.data;
2943329333 switch (union_obj.status) {
2943429334 .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {},
......@@ -29444,7 +29344,7 @@ fn resolveUnionFully(
2944429344
2944529345 union_obj.status = .fully_resolved_wip;
2944629346 for (union_obj.fields.values()) |field| {
29447 try sema.resolveTypeFully(block, src, field.ty);
29347 try sema.resolveTypeFully(field.ty);
2944829348 }
2944929349 union_obj.status = .fully_resolved;
2945029350 }
......@@ -29453,7 +29353,7 @@ fn resolveUnionFully(
2945329353 _ = try sema.typeRequiresComptime(ty);
2945429354}
2945529355
29456pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {
29356pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
2945729357 switch (ty.tag()) {
2945829358 .@"struct" => {
2945929359 const struct_obj = ty.castTag(.@"struct").?.data;
......@@ -29465,17 +29365,17 @@ pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type)
2946529365 try sema.resolveTypeFieldsUnion(ty, union_obj);
2946629366 return ty;
2946729367 },
29468 .type_info => return sema.resolveBuiltinTypeFields(block, src, "Type"),
29469 .extern_options => return sema.resolveBuiltinTypeFields(block, src, "ExternOptions"),
29470 .export_options => return sema.resolveBuiltinTypeFields(block, src, "ExportOptions"),
29471 .atomic_order => return sema.resolveBuiltinTypeFields(block, src, "AtomicOrder"),
29472 .atomic_rmw_op => return sema.resolveBuiltinTypeFields(block, src, "AtomicRmwOp"),
29473 .calling_convention => return sema.resolveBuiltinTypeFields(block, src, "CallingConvention"),
29474 .address_space => return sema.resolveBuiltinTypeFields(block, src, "AddressSpace"),
29475 .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"),
29476 .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"),
29477 .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"),
29478 .prefetch_options => return sema.resolveBuiltinTypeFields(block, src, "PrefetchOptions"),
29368 .type_info => return sema.getBuiltinType("Type"),
29369 .extern_options => return sema.getBuiltinType("ExternOptions"),
29370 .export_options => return sema.getBuiltinType("ExportOptions"),
29371 .atomic_order => return sema.getBuiltinType("AtomicOrder"),
29372 .atomic_rmw_op => return sema.getBuiltinType("AtomicRmwOp"),
29373 .calling_convention => return sema.getBuiltinType("CallingConvention"),
29374 .address_space => return sema.getBuiltinType("AddressSpace"),
29375 .float_mode => return sema.getBuiltinType("FloatMode"),
29376 .reduce_op => return sema.getBuiltinType("ReduceOp"),
29377 .call_options => return sema.getBuiltinType("CallOptions"),
29378 .prefetch_options => return sema.getBuiltinType("PrefetchOptions"),
2947929379
2948029380 else => return ty,
2948129381 }
......@@ -29534,16 +29434,6 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_obj: *Module.Union) Compi
2953429434 union_obj.status = .have_field_types;
2953529435}
2953629436
29537fn resolveBuiltinTypeFields(
29538 sema: *Sema,
29539 block: *Block,
29540 src: LazySrcLoc,
29541 name: []const u8,
29542) CompileError!Type {
29543 const resolved_ty = try sema.getBuiltinType(block, src, name);
29544 return sema.resolveTypeFields(block, src, resolved_ty);
29545}
29546
2954729437fn resolveInferredErrorSet(
2954829438 sema: *Sema,
2954929439 block: *Block,
......@@ -29828,7 +29718,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
2982829718 };
2982929719 return sema.failWithOwnedErrorMsg(msg);
2983029720 }
29831 if (struct_obj.layout == .Extern and !try sema.validateExternType(&block_scope, src, field.ty, .struct_field)) {
29721 if (struct_obj.layout == .Extern and !try sema.validateExternType(field.ty, .struct_field)) {
2983229722 const msg = msg: {
2983329723 const tree = try sema.getAstTree(&block_scope);
2983429724 const fields_src = enumFieldSrcLoc(decl, tree.*, 0, i);
......@@ -29879,7 +29769,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
2987929769 const init = try sema.resolveBody(&block_scope, body, struct_obj.zir_index);
2988029770 const field = &struct_obj.fields.values()[i];
2988129771 const coerced = try sema.coerce(&block_scope, field.ty, init, src);
29882 const default_val = (try sema.resolveMaybeUndefVal(&block_scope, src, coerced)) orelse
29772 const default_val = (try sema.resolveMaybeUndefVal(coerced)) orelse
2988329773 return sema.failWithNeededComptime(&block_scope, src, "struct field default value must be comptime-known");
2988429774 field.default_val = try default_val.copy(decl_arena_allocator);
2988529775 }
......@@ -30089,7 +29979,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3008929979 });
3009029980 } else {
3009129981 const val = if (last_tag_val) |val|
30092 try sema.intAdd(&block_scope, src, val, Value.one, int_tag_ty)
29982 try sema.intAdd(val, Value.one, int_tag_ty)
3009329983 else
3009429984 Value.zero;
3009529985 last_tag_val = val;
......@@ -30166,7 +30056,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3016630056 };
3016730057 return sema.failWithOwnedErrorMsg(msg);
3016830058 }
30169 if (union_obj.layout == .Extern and !try sema.validateExternType(&block_scope, src, field_ty, .union_field)) {
30059 if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) {
3017030060 const msg = msg: {
3017130061 const tree = try sema.getAstTree(&block_scope);
3017230062 const field_src = enumFieldSrcLoc(decl, tree.*, 0, field_i);
......@@ -30338,41 +30228,76 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Block, fields_len: usize, may
3033830228 return enum_ty;
3033930229}
3034030230
30341fn getBuiltin(
30342 sema: *Sema,
30343 block: *Block,
30344 src: LazySrcLoc,
30345 name: []const u8,
30346) CompileError!Air.Inst.Ref {
30231fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
30232 var wip_captures = try WipCaptureScope.init(sema.gpa, sema.perm_arena, sema.owner_decl.src_scope);
30233 defer wip_captures.deinit();
30234
30235 var block: Block = .{
30236 .parent = null,
30237 .sema = sema,
30238 .src_decl = sema.owner_decl_index,
30239 .namespace = sema.owner_decl.src_namespace,
30240 .wip_capture_scope = wip_captures.scope,
30241 .instructions = .{},
30242 .inlining = null,
30243 .is_comptime = true,
30244 };
30245 defer {
30246 block.instructions.deinit(sema.gpa);
30247 block.params.deinit(sema.gpa);
30248 }
30249 const src = LazySrcLoc.nodeOffset(0);
30250
3034730251 const mod = sema.mod;
3034830252 const std_pkg = mod.main_pkg.table.get("std").?;
3034930253 const std_file = (mod.importPkg(std_pkg) catch unreachable).file;
30350 const opt_builtin_inst = try sema.namespaceLookupRef(
30351 block,
30254 const opt_builtin_inst = (try sema.namespaceLookupRef(
30255 &block,
3035230256 src,
3035330257 mod.declPtr(std_file.root_decl.unwrap().?).src_namespace,
3035430258 "builtin",
30355 );
30356 const builtin_inst = try sema.analyzeLoad(block, src, opt_builtin_inst.?, src);
30357 const builtin_ty = try sema.analyzeAsType(block, src, builtin_inst);
30358 const opt_ty_decl = try sema.namespaceLookup(
30359 block,
30259 )) orelse @panic("lib/std.zig is corrupt and missing 'builtin'");
30260 const builtin_inst = try sema.analyzeLoad(&block, src, opt_builtin_inst, src);
30261 const builtin_ty = sema.analyzeAsType(&block, src, builtin_inst) catch |err| switch (err) {
30262 error.AnalysisFail => std.debug.panic("std.builtin is corrupt", .{}),
30263 else => |e| return e,
30264 };
30265 const opt_ty_decl = (try sema.namespaceLookup(
30266 &block,
3036030267 src,
3036130268 builtin_ty.getNamespace().?,
3036230269 name,
30363 );
30364 return sema.analyzeDeclVal(block, src, opt_ty_decl.?);
30270 )) orelse std.debug.panic("lib/std/builtin.zig is corrupt and missing '{s}'", .{name});
30271 return sema.analyzeDeclVal(&block, src, opt_ty_decl);
3036530272}
3036630273
30367fn getBuiltinType(
30368 sema: *Sema,
30369 block: *Block,
30370 src: LazySrcLoc,
30371 name: []const u8,
30372) CompileError!Type {
30373 const ty_inst = try sema.getBuiltin(block, src, name);
30374 const result_ty = try sema.analyzeAsType(block, src, ty_inst);
30375 try sema.resolveTypeFully(block, src, result_ty); // Should not fail
30274fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
30275 const ty_inst = try sema.getBuiltin(name);
30276
30277 var wip_captures = try WipCaptureScope.init(sema.gpa, sema.perm_arena, sema.owner_decl.src_scope);
30278 defer wip_captures.deinit();
30279
30280 var block: Block = .{
30281 .parent = null,
30282 .sema = sema,
30283 .src_decl = sema.owner_decl_index,
30284 .namespace = sema.owner_decl.src_namespace,
30285 .wip_capture_scope = wip_captures.scope,
30286 .instructions = .{},
30287 .inlining = null,
30288 .is_comptime = true,
30289 };
30290 defer {
30291 block.instructions.deinit(sema.gpa);
30292 block.params.deinit(sema.gpa);
30293 }
30294 const src = LazySrcLoc.nodeOffset(0);
30295
30296 const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) {
30297 error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}),
30298 else => |e| return e,
30299 };
30300 try sema.resolveTypeFully(result_ty); // Should not fail
3037630301 return result_ty;
3037730302}
3037830303
......@@ -30381,12 +30306,7 @@ fn getBuiltinType(
3038130306/// to get the answer. The one in `Type` is for calling during codegen and asserts
3038230307/// that the types are already resolved.
3038330308/// TODO assert the return value matches `ty.onePossibleValue`
30384pub fn typeHasOnePossibleValue(
30385 sema: *Sema,
30386 block: *Block,
30387 src: LazySrcLoc,
30388 ty: Type,
30389) CompileError!?Value {
30309pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3039030310 switch (ty.tag()) {
3039130311 .f16,
3039230312 .f32,
......@@ -30482,7 +30402,7 @@ pub fn typeHasOnePossibleValue(
3048230402 },
3048330403
3048430404 .@"struct" => {
30485 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
30405 const resolved_ty = try sema.resolveTypeFields(ty);
3048630406 const s = resolved_ty.castTag(.@"struct").?.data;
3048730407 for (s.fields.values()) |field, i| {
3048830408 if (field.is_comptime) continue;
......@@ -30496,7 +30416,7 @@ pub fn typeHasOnePossibleValue(
3049630416 try sema.addFieldErrNote(resolved_ty, i, msg, "while checking this field", .{});
3049730417 return sema.failWithOwnedErrorMsg(msg);
3049830418 }
30499 if ((try sema.typeHasOnePossibleValue(block, src, field.ty)) == null) {
30419 if ((try sema.typeHasOnePossibleValue(field.ty)) == null) {
3050030420 return null;
3050130421 }
3050230422 }
......@@ -30508,14 +30428,14 @@ pub fn typeHasOnePossibleValue(
3050830428 for (tuple.values) |val, i| {
3050930429 const is_comptime = val.tag() != .unreachable_value;
3051030430 if (is_comptime) continue;
30511 if ((try sema.typeHasOnePossibleValue(block, src, tuple.types[i])) != null) continue;
30431 if ((try sema.typeHasOnePossibleValue(tuple.types[i])) != null) continue;
3051230432 return null;
3051330433 }
3051430434 return Value.initTag(.empty_struct_value);
3051530435 },
3051630436
3051730437 .enum_numbered => {
30518 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
30438 const resolved_ty = try sema.resolveTypeFields(ty);
3051930439 const enum_obj = resolved_ty.castTag(.enum_numbered).?.data;
3052030440 // An explicit tag type is always provided for enum_numbered.
3052130441 if (enum_obj.tag_ty.hasRuntimeBits()) {
......@@ -30532,7 +30452,7 @@ pub fn typeHasOnePossibleValue(
3053230452 }
3053330453 },
3053430454 .enum_full => {
30535 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
30455 const resolved_ty = try sema.resolveTypeFields(ty);
3053630456 const enum_obj = resolved_ty.castTag(.enum_full).?.data;
3053730457 if (enum_obj.tag_ty.hasRuntimeBits()) {
3053830458 return null;
......@@ -30548,7 +30468,7 @@ pub fn typeHasOnePossibleValue(
3054830468 }
3054930469 },
3055030470 .enum_simple => {
30551 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
30471 const resolved_ty = try sema.resolveTypeFields(ty);
3055230472 const enum_simple = resolved_ty.castTag(.enum_simple).?.data;
3055330473 switch (enum_simple.fields.count()) {
3055430474 0 => return Value.initTag(.unreachable_value),
......@@ -30558,16 +30478,16 @@ pub fn typeHasOnePossibleValue(
3055830478 },
3055930479 .enum_nonexhaustive => {
3056030480 const tag_ty = ty.castTag(.enum_nonexhaustive).?.data.tag_ty;
30561 if (tag_ty.zigTypeTag() != .ComptimeInt and !(try sema.typeHasRuntimeBits(block, src, tag_ty))) {
30481 if (tag_ty.zigTypeTag() != .ComptimeInt and !(try sema.typeHasRuntimeBits(tag_ty))) {
3056230482 return Value.zero;
3056330483 } else {
3056430484 return null;
3056530485 }
3056630486 },
3056730487 .@"union", .union_safety_tagged, .union_tagged => {
30568 const resolved_ty = try sema.resolveTypeFields(block, src, ty);
30488 const resolved_ty = try sema.resolveTypeFields(ty);
3056930489 const union_obj = resolved_ty.cast(Type.Payload.Union).?.data;
30570 const tag_val = (try sema.typeHasOnePossibleValue(block, src, union_obj.tag_ty)) orelse
30490 const tag_val = (try sema.typeHasOnePossibleValue(union_obj.tag_ty)) orelse
3057130491 return null;
3057230492 const fields = union_obj.fields.values();
3057330493 if (fields.len == 0) return Value.initTag(.unreachable_value);
......@@ -30582,7 +30502,7 @@ pub fn typeHasOnePossibleValue(
3058230502 try sema.addFieldErrNote(resolved_ty, 0, msg, "while checking this field", .{});
3058330503 return sema.failWithOwnedErrorMsg(msg);
3058430504 }
30585 const val_val = (try sema.typeHasOnePossibleValue(block, src, only_field.ty)) orelse
30505 const val_val = (try sema.typeHasOnePossibleValue(only_field.ty)) orelse
3058630506 return null;
3058730507 // TODO make this not allocate. The function in `Type.onePossibleValue`
3058830508 // currently returns `empty_struct_value` and we should do that here too.
......@@ -30608,7 +30528,7 @@ pub fn typeHasOnePossibleValue(
3060830528 .vector, .array, .array_u8 => {
3060930529 if (ty.arrayLen() == 0)
3061030530 return Value.initTag(.empty_array);
30611 if ((try sema.typeHasOnePossibleValue(block, src, ty.elemType())) != null) {
30531 if ((try sema.typeHasOnePossibleValue(ty.elemType())) != null) {
3061230532 return Value.initTag(.the_only_possible_value);
3061330533 }
3061430534 return null;
......@@ -30799,7 +30719,7 @@ pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref {
3079930719pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
3080030720 const fields = std.meta.fields(@TypeOf(extra));
3080130721 try sema.air_extra.ensureUnusedCapacity(sema.gpa, fields.len);
30802 return addExtraAssumeCapacity(sema, extra);
30722 return sema.addExtraAssumeCapacity(extra);
3080330723}
3080430724
3080530725pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
......@@ -30832,11 +30752,9 @@ fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {
3083230752
3083330753fn isComptimeKnown(
3083430754 sema: *Sema,
30835 block: *Block,
30836 src: LazySrcLoc,
3083730755 inst: Air.Inst.Ref,
3083830756) !bool {
30839 return (try sema.resolveMaybeUndefVal(block, src, inst)) != null;
30757 return (try sema.resolveMaybeUndefVal(inst)) != null;
3084030758}
3084130759
3084230760fn analyzeComptimeAlloc(
......@@ -30844,10 +30762,9 @@ fn analyzeComptimeAlloc(
3084430762 block: *Block,
3084530763 var_type: Type,
3084630764 alignment: u32,
30847 src: LazySrcLoc,
3084830765) CompileError!Air.Inst.Ref {
3084930766 // Needed to make an anon decl with type `var_type` (the `finish()` call below).
30850 _ = try sema.typeHasOnePossibleValue(block, src, var_type);
30767 _ = try sema.typeHasOnePossibleValue(var_type);
3085130768
3085230769 const ptr_type = try Type.ptr(sema.arena, sema.mod, .{
3085330770 .pointee_type = var_type,
......@@ -30855,7 +30772,7 @@ fn analyzeComptimeAlloc(
3085530772 .@"align" = alignment,
3085630773 });
3085730774
30858 var anon_decl = try block.startAnonDecl(src);
30775 var anon_decl = try block.startAnonDecl();
3085930776 defer anon_decl.deinit();
3086030777
3086130778 const decl_index = try anon_decl.finish(
......@@ -30996,14 +30913,14 @@ fn pointerDerefExtra(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value
3099630913 return DerefResult{ .needed_well_defined = load_ty };
3099730914 }
3099830915
30999 const load_sz = try sema.typeAbiSize(block, src, load_ty);
30916 const load_sz = try sema.typeAbiSize(load_ty);
3100030917
3100130918 // Try the smaller bit-cast first, since that's more efficient than using the larger `parent`
31002 if (deref.pointee) |tv| if (load_sz <= try sema.typeAbiSize(block, src, tv.ty))
30919 if (deref.pointee) |tv| if (load_sz <= try sema.typeAbiSize(tv.ty))
3100330920 return DerefResult{ .val = try sema.bitCastVal(block, src, tv.val, tv.ty, load_ty, 0) };
3100430921
3100530922 // If that fails, try to bit-cast from the largest parent value with a well-defined layout
31006 if (deref.parent) |parent| if (load_sz + parent.byte_offset <= try sema.typeAbiSize(block, src, parent.tv.ty))
30923 if (deref.parent) |parent| if (load_sz + parent.byte_offset <= try sema.typeAbiSize(parent.tv.ty))
3100730924 return DerefResult{ .val = try sema.bitCastVal(block, src, parent.tv.val, parent.tv.ty, load_ty, parent.byte_offset) };
3100830925
3100930926 if (deref.ty_without_well_defined_layout) |bad_ty| {
......@@ -31031,10 +30948,8 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError
3103130948/// This logic must be kept in sync with `Type.isPtrLikeOptional`.
3103230949fn typePtrOrOptionalPtrTy(
3103330950 sema: *Sema,
31034 block: *Block,
3103530951 ty: Type,
3103630952 buf: *Type.Payload.ElemType,
31037 src: LazySrcLoc,
3103830953) !?Type {
3103930954 switch (ty.tag()) {
3104030955 .optional_single_const_pointer,
......@@ -31073,7 +30988,7 @@ fn typePtrOrOptionalPtrTy(
3107330988 if (info.@"allowzero") return null;
3107430989
3107530990 // optionals of zero sized types behave like bools, not pointers
31076 if ((try sema.typeHasOnePossibleValue(block, src, child_type)) != null) {
30991 if ((try sema.typeHasOnePossibleValue(child_type)) != null) {
3107730992 return null;
3107830993 }
3107930994
......@@ -31090,7 +31005,7 @@ fn typePtrOrOptionalPtrTy(
3109031005/// This function returns false negatives when structs and unions are having their
3109131006/// field types resolved.
3109231007/// TODO assert the return value matches `ty.comptimeOnly`
31093/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
31008/// TODO merge these implementations together with the "advanced"/opt_sema pattern seen
3109431009/// elsewhere in value.zig
3109531010pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3109631011 return switch (ty.tag()) {
......@@ -31287,33 +31202,28 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3128731202 };
3128831203}
3128931204
31290pub fn typeHasRuntimeBits(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
31291 return ty.hasRuntimeBitsAdvanced(false, sema.kit(block, src));
31205pub fn typeHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool {
31206 return ty.hasRuntimeBitsAdvanced(false, sema);
3129231207}
3129331208
31294fn typeAbiSize(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !u64 {
31295 try sema.resolveTypeLayout(block, src, ty);
31209fn typeAbiSize(sema: *Sema, ty: Type) !u64 {
31210 try sema.resolveTypeLayout(ty);
3129631211 const target = sema.mod.getTarget();
3129731212 return ty.abiSize(target);
3129831213}
3129931214
31300fn typeAbiAlignment(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!u32 {
31215fn typeAbiAlignment(sema: *Sema, ty: Type) CompileError!u32 {
3130131216 const target = sema.mod.getTarget();
31302 return (try ty.abiAlignmentAdvanced(target, .{ .sema_kit = sema.kit(block, src) })).scalar;
31217 return (try ty.abiAlignmentAdvanced(target, .{ .sema = sema })).scalar;
3130331218}
3130431219
3130531220/// Not valid to call for packed unions.
3130631221/// Keep implementation in sync with `Module.Union.Field.normalAlignment`.
31307fn unionFieldAlignment(
31308 sema: *Sema,
31309 block: *Block,
31310 src: LazySrcLoc,
31311 field: Module.Union.Field,
31312) !u32 {
31222fn unionFieldAlignment(sema: *Sema, field: Module.Union.Field) !u32 {
3131331223 if (field.ty.zigTypeTag() == .NoReturn) {
3131431224 return @as(u32, 0);
3131531225 } else if (field.abi_align == 0) {
31316 return sema.typeAbiAlignment(block, src, field.ty);
31226 return sema.typeAbiAlignment(field.ty);
3131731227 } else {
3131831228 return field.abi_align;
3131931229 }
......@@ -31342,7 +31252,7 @@ fn unionFieldIndex(
3134231252 field_name: []const u8,
3134331253 field_src: LazySrcLoc,
3134431254) !u32 {
31345 const union_ty = try sema.resolveTypeFields(block, field_src, unresolved_union_ty);
31255 const union_ty = try sema.resolveTypeFields(unresolved_union_ty);
3134631256 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
3134731257 const field_index_usize = union_obj.fields.getIndex(field_name) orelse
3134831258 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
......@@ -31356,7 +31266,7 @@ fn structFieldIndex(
3135631266 field_name: []const u8,
3135731267 field_src: LazySrcLoc,
3135831268) !u32 {
31359 const struct_ty = try sema.resolveTypeFields(block, field_src, unresolved_struct_ty);
31269 const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty);
3136031270 if (struct_ty.isAnonStruct()) {
3136131271 return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src);
3136231272 } else {
......@@ -31385,34 +31295,30 @@ fn anonStructFieldIndex(
3138531295 });
3138631296}
3138731297
31388fn kit(sema: *Sema, block: *Block, src: LazySrcLoc) Module.WipAnalysis {
31389 return .{ .sema = sema, .block = block, .src = src };
31390}
31391
3139231298fn queueFullTypeResolution(sema: *Sema, ty: Type) !void {
3139331299 const inst_ref = try sema.addType(ty);
3139431300 try sema.types_to_resolve.append(sema.gpa, inst_ref);
3139531301}
3139631302
31397fn intAdd(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Value, ty: Type) !Value {
31303fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3139831304 if (ty.zigTypeTag() == .Vector) {
3139931305 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3140031306 for (result_data) |*scalar, i| {
31401 scalar.* = try sema.intAddScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i));
31307 scalar.* = try sema.intAddScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));
3140231308 }
3140331309 return Value.Tag.aggregate.create(sema.arena, result_data);
3140431310 }
31405 return sema.intAddScalar(block, src, lhs, rhs);
31311 return sema.intAddScalar(lhs, rhs);
3140631312}
3140731313
31408fn intAddScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Value) !Value {
31314fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value) !Value {
3140931315 // TODO is this a performance issue? maybe we should try the operation without
3141031316 // resorting to BigInt first.
3141131317 var lhs_space: Value.BigIntSpace = undefined;
3141231318 var rhs_space: Value.BigIntSpace = undefined;
3141331319 const target = sema.mod.getTarget();
31414 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src));
31415 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src));
31320 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema);
31321 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema);
3141631322 const limbs = try sema.arena.alloc(
3141731323 std.math.big.Limb,
3141831324 std.math.max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
......@@ -31425,8 +31331,6 @@ fn intAddScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Va
3142531331/// Supports both (vectors of) floats and ints; handles undefined scalars.
3142631332fn numberAddWrap(
3142731333 sema: *Sema,
31428 block: *Block,
31429 src: LazySrcLoc,
3143031334 lhs: Value,
3143131335 rhs: Value,
3143231336 ty: Type,
......@@ -31434,18 +31338,16 @@ fn numberAddWrap(
3143431338 if (ty.zigTypeTag() == .Vector) {
3143531339 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3143631340 for (result_data) |*scalar, i| {
31437 scalar.* = try sema.numberAddWrapScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
31341 scalar.* = try sema.numberAddWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
3143831342 }
3143931343 return Value.Tag.aggregate.create(sema.arena, result_data);
3144031344 }
31441 return sema.numberAddWrapScalar(block, src, lhs, rhs, ty);
31345 return sema.numberAddWrapScalar(lhs, rhs, ty);
3144231346}
3144331347
3144431348/// Supports both floats and ints; handles undefined.
3144531349fn numberAddWrapScalar(
3144631350 sema: *Sema,
31447 block: *Block,
31448 src: LazySrcLoc,
3144931351 lhs: Value,
3145031352 rhs: Value,
3145131353 ty: Type,
......@@ -31453,21 +31355,19 @@ fn numberAddWrapScalar(
3145331355 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);
3145431356
3145531357 if (ty.zigTypeTag() == .ComptimeInt) {
31456 return sema.intAdd(block, src, lhs, rhs, ty);
31358 return sema.intAdd(lhs, rhs, ty);
3145731359 }
3145831360
3145931361 if (ty.isAnyFloat()) {
3146031362 return sema.floatAdd(lhs, rhs, ty);
3146131363 }
3146231364
31463 const overflow_result = try sema.intAddWithOverflow(block, src, lhs, rhs, ty);
31365 const overflow_result = try sema.intAddWithOverflow(lhs, rhs, ty);
3146431366 return overflow_result.wrapped_result;
3146531367}
3146631368
3146731369fn intSub(
3146831370 sema: *Sema,
31469 block: *Block,
31470 src: LazySrcLoc,
3147131371 lhs: Value,
3147231372 rhs: Value,
3147331373 ty: Type,
......@@ -31475,21 +31375,21 @@ fn intSub(
3147531375 if (ty.zigTypeTag() == .Vector) {
3147631376 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3147731377 for (result_data) |*scalar, i| {
31478 scalar.* = try sema.intSubScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i));
31378 scalar.* = try sema.intSubScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i));
3147931379 }
3148031380 return Value.Tag.aggregate.create(sema.arena, result_data);
3148131381 }
31482 return sema.intSubScalar(block, src, lhs, rhs);
31382 return sema.intSubScalar(lhs, rhs);
3148331383}
3148431384
31485fn intSubScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Value) !Value {
31385fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value) !Value {
3148631386 // TODO is this a performance issue? maybe we should try the operation without
3148731387 // resorting to BigInt first.
3148831388 var lhs_space: Value.BigIntSpace = undefined;
3148931389 var rhs_space: Value.BigIntSpace = undefined;
3149031390 const target = sema.mod.getTarget();
31491 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src));
31492 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src));
31391 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema);
31392 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema);
3149331393 const limbs = try sema.arena.alloc(
3149431394 std.math.big.Limb,
3149531395 std.math.max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
......@@ -31502,8 +31402,6 @@ fn intSubScalar(sema: *Sema, block: *Block, src: LazySrcLoc, lhs: Value, rhs: Va
3150231402/// Supports both (vectors of) floats and ints; handles undefined scalars.
3150331403fn numberSubWrap(
3150431404 sema: *Sema,
31505 block: *Block,
31506 src: LazySrcLoc,
3150731405 lhs: Value,
3150831406 rhs: Value,
3150931407 ty: Type,
......@@ -31511,18 +31409,16 @@ fn numberSubWrap(
3151131409 if (ty.zigTypeTag() == .Vector) {
3151231410 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3151331411 for (result_data) |*scalar, i| {
31514 scalar.* = try sema.numberSubWrapScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
31412 scalar.* = try sema.numberSubWrapScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
3151531413 }
3151631414 return Value.Tag.aggregate.create(sema.arena, result_data);
3151731415 }
31518 return sema.numberSubWrapScalar(block, src, lhs, rhs, ty);
31416 return sema.numberSubWrapScalar(lhs, rhs, ty);
3151931417}
3152031418
3152131419/// Supports both floats and ints; handles undefined.
3152231420fn numberSubWrapScalar(
3152331421 sema: *Sema,
31524 block: *Block,
31525 src: LazySrcLoc,
3152631422 lhs: Value,
3152731423 rhs: Value,
3152831424 ty: Type,
......@@ -31530,14 +31426,14 @@ fn numberSubWrapScalar(
3153031426 if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef);
3153131427
3153231428 if (ty.zigTypeTag() == .ComptimeInt) {
31533 return sema.intSub(block, src, lhs, rhs, ty);
31429 return sema.intSub(lhs, rhs, ty);
3153431430 }
3153531431
3153631432 if (ty.isAnyFloat()) {
3153731433 return sema.floatSub(lhs, rhs, ty);
3153831434 }
3153931435
31540 const overflow_result = try sema.intSubWithOverflow(block, src, lhs, rhs, ty);
31436 const overflow_result = try sema.intSubWithOverflow(lhs, rhs, ty);
3154131437 return overflow_result.wrapped_result;
3154231438}
3154331439
......@@ -31649,8 +31545,6 @@ fn floatSubScalar(
3164931545
3165031546fn intSubWithOverflow(
3165131547 sema: *Sema,
31652 block: *Block,
31653 src: LazySrcLoc,
3165431548 lhs: Value,
3165531549 rhs: Value,
3165631550 ty: Type,
......@@ -31659,7 +31553,7 @@ fn intSubWithOverflow(
3165931553 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
3166031554 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3166131555 for (result_data) |*scalar, i| {
31662 const of_math_result = try sema.intSubWithOverflowScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
31556 const of_math_result = try sema.intSubWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
3166331557 overflowed_data[i] = of_math_result.overflowed;
3166431558 scalar.* = of_math_result.wrapped_result;
3166531559 }
......@@ -31668,13 +31562,11 @@ fn intSubWithOverflow(
3166831562 .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data),
3166931563 };
3167031564 }
31671 return sema.intSubWithOverflowScalar(block, src, lhs, rhs, ty);
31565 return sema.intSubWithOverflowScalar(lhs, rhs, ty);
3167231566}
3167331567
3167431568fn intSubWithOverflowScalar(
3167531569 sema: *Sema,
31676 block: *Block,
31677 src: LazySrcLoc,
3167831570 lhs: Value,
3167931571 rhs: Value,
3168031572 ty: Type,
......@@ -31684,8 +31576,8 @@ fn intSubWithOverflowScalar(
3168431576
3168531577 var lhs_space: Value.BigIntSpace = undefined;
3168631578 var rhs_space: Value.BigIntSpace = undefined;
31687 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src));
31688 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src));
31579 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema);
31580 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema);
3168931581 const limbs = try sema.arena.alloc(
3169031582 std.math.big.Limb,
3169131583 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -31774,7 +31666,7 @@ fn floatToIntScalar(
3177431666 else
3177531667 try Value.Tag.int_big_positive.create(sema.arena, result_limbs);
3177631668
31777 if (!(try sema.intFitsInType(block, src, result, int_ty, null))) {
31669 if (!(try sema.intFitsInType(result, int_ty, null))) {
3177831670 return sema.fail(block, src, "float value '{}' cannot be stored in integer type '{}'", .{
3177931671 val.fmtValue(float_ty, sema.mod), int_ty.fmt(sema.mod),
3178031672 });
......@@ -31788,8 +31680,6 @@ fn floatToIntScalar(
3178831680/// If provided, `vector_index` reports the first element that failed the range check.
3178931681fn intFitsInType(
3179031682 sema: *Sema,
31791 block: *Block,
31792 src: LazySrcLoc,
3179331683 val: Value,
3179431684 ty: Type,
3179531685 vector_index: ?*usize,
......@@ -31821,7 +31711,7 @@ fn intFitsInType(
3182131711 const max_needed_bits = @as(u16, 16) + @boolToInt(info.signedness == .signed);
3182231712 // If it is u16 or bigger we know the alignment fits without resolving it.
3182331713 if (info.bits >= max_needed_bits) return true;
31824 const x = try sema.typeAbiAlignment(block, src, val.castTag(.lazy_align).?.data);
31714 const x = try sema.typeAbiAlignment(val.castTag(.lazy_align).?.data);
3182531715 if (x == 0) return true;
3182631716 const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
3182731717 return info.bits >= actual_needed_bits;
......@@ -31835,7 +31725,7 @@ fn intFitsInType(
3183531725 const max_needed_bits = @as(u16, 64) + @boolToInt(info.signedness == .signed);
3183631726 // If it is u64 or bigger we know the size fits without resolving it.
3183731727 if (info.bits >= max_needed_bits) return true;
31838 const x = try sema.typeAbiSize(block, src, val.castTag(.lazy_size).?.data);
31728 const x = try sema.typeAbiSize(val.castTag(.lazy_size).?.data);
3183931729 if (x == 0) return true;
3184031730 const actual_needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
3184131731 return info.bits >= actual_needed_bits;
......@@ -31863,7 +31753,7 @@ fn intFitsInType(
3186331753 if (info.signedness == .unsigned and x < 0)
3186431754 return false;
3186531755 var buffer: Value.BigIntSpace = undefined;
31866 return (try val.toBigIntAdvanced(&buffer, target, sema.kit(block, src))).fitsInTwosComp(info.signedness, info.bits);
31756 return (try val.toBigIntAdvanced(&buffer, target, sema)).fitsInTwosComp(info.signedness, info.bits);
3186731757 },
3186831758 .ComptimeInt => return true,
3186931759 else => unreachable,
......@@ -31911,7 +31801,7 @@ fn intFitsInType(
3191131801 .aggregate => {
3191231802 assert(ty.zigTypeTag() == .Vector);
3191331803 for (val.castTag(.aggregate).?.data) |elem, i| {
31914 if (!(try sema.intFitsInType(block, src, elem, ty.scalarType(), null))) {
31804 if (!(try sema.intFitsInType(elem, ty.scalarType(), null))) {
3191531805 if (vector_index) |some| some.* = i;
3191631806 return false;
3191731807 }
......@@ -31925,37 +31815,33 @@ fn intFitsInType(
3192531815
3192631816fn intInRange(
3192731817 sema: *Sema,
31928 block: *Block,
31929 src: LazySrcLoc,
3193031818 tag_ty: Type,
3193131819 int_val: Value,
3193231820 end: usize,
3193331821) !bool {
31934 if (!(try int_val.compareAllWithZeroAdvanced(.gte, sema.kit(block, src)))) return false;
31822 if (!(try int_val.compareAllWithZeroAdvanced(.gte, sema))) return false;
3193531823 var end_payload: Value.Payload.U64 = .{
3193631824 .base = .{ .tag = .int_u64 },
3193731825 .data = end,
3193831826 };
3193931827 const end_val = Value.initPayload(&end_payload.base);
31940 if (!(try sema.compareAll(block, src, int_val, .lt, end_val, tag_ty))) return false;
31828 if (!(try sema.compareAll(int_val, .lt, end_val, tag_ty))) return false;
3194131829 return true;
3194231830}
3194331831
3194431832/// Asserts the type is an enum.
3194531833fn enumHasInt(
3194631834 sema: *Sema,
31947 block: *Block,
31948 src: LazySrcLoc,
3194931835 ty: Type,
3195031836 int: Value,
3195131837) CompileError!bool {
3195231838 switch (ty.tag()) {
31953 .enum_nonexhaustive => return sema.intFitsInType(block, src, int, ty, null),
31839 .enum_nonexhaustive => return sema.intFitsInType(int, ty, null),
3195431840 .enum_full => {
3195531841 const enum_full = ty.castTag(.enum_full).?.data;
3195631842 const tag_ty = enum_full.tag_ty;
3195731843 if (enum_full.values.count() == 0) {
31958 return intInRange(sema, block, src, tag_ty, int, enum_full.fields.count());
31844 return sema.intInRange(tag_ty, int, enum_full.fields.count());
3195931845 } else {
3196031846 return enum_full.values.containsContext(int, .{
3196131847 .ty = tag_ty,
......@@ -31967,7 +31853,7 @@ fn enumHasInt(
3196731853 const enum_obj = ty.castTag(.enum_numbered).?.data;
3196831854 const tag_ty = enum_obj.tag_ty;
3196931855 if (enum_obj.values.count() == 0) {
31970 return intInRange(sema, block, src, tag_ty, int, enum_obj.fields.count());
31856 return sema.intInRange(tag_ty, int, enum_obj.fields.count());
3197131857 } else {
3197231858 return enum_obj.values.containsContext(int, .{
3197331859 .ty = tag_ty,
......@@ -31984,7 +31870,7 @@ fn enumHasInt(
3198431870 .data = bits,
3198531871 };
3198631872 const tag_ty = Type.initPayload(&buffer.base);
31987 return intInRange(sema, block, src, tag_ty, int, fields_len);
31873 return sema.intInRange(tag_ty, int, fields_len);
3198831874 },
3198931875 .atomic_order,
3199031876 .atomic_rmw_op,
......@@ -32004,8 +31890,6 @@ fn enumHasInt(
3200431890
3200531891fn intAddWithOverflow(
3200631892 sema: *Sema,
32007 block: *Block,
32008 src: LazySrcLoc,
3200931893 lhs: Value,
3201031894 rhs: Value,
3201131895 ty: Type,
......@@ -32014,7 +31898,7 @@ fn intAddWithOverflow(
3201431898 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
3201531899 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3201631900 for (result_data) |*scalar, i| {
32017 const of_math_result = try sema.intAddWithOverflowScalar(block, src, lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
31901 const of_math_result = try sema.intAddWithOverflowScalar(lhs.indexVectorlike(i), rhs.indexVectorlike(i), ty.scalarType());
3201831902 overflowed_data[i] = of_math_result.overflowed;
3201931903 scalar.* = of_math_result.wrapped_result;
3202031904 }
......@@ -32023,13 +31907,11 @@ fn intAddWithOverflow(
3202331907 .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data),
3202431908 };
3202531909 }
32026 return sema.intAddWithOverflowScalar(block, src, lhs, rhs, ty);
31910 return sema.intAddWithOverflowScalar(lhs, rhs, ty);
3202731911}
3202831912
3202931913fn intAddWithOverflowScalar(
3203031914 sema: *Sema,
32031 block: *Block,
32032 src: LazySrcLoc,
3203331915 lhs: Value,
3203431916 rhs: Value,
3203531917 ty: Type,
......@@ -32039,8 +31921,8 @@ fn intAddWithOverflowScalar(
3203931921
3204031922 var lhs_space: Value.BigIntSpace = undefined;
3204131923 var rhs_space: Value.BigIntSpace = undefined;
32042 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema.kit(block, src));
32043 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema.kit(block, src));
31924 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, target, sema);
31925 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, target, sema);
3204431926 const limbs = try sema.arena.alloc(
3204531927 std.math.big.Limb,
3204631928 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -32060,8 +31942,6 @@ fn intAddWithOverflowScalar(
3206031942/// Note that `!compareAll(.eq, ...) != compareAll(.neq, ...)`
3206131943fn compareAll(
3206231944 sema: *Sema,
32063 block: *Block,
32064 src: LazySrcLoc,
3206531945 lhs: Value,
3206631946 op: std.math.CompareOperator,
3206731947 rhs: Value,
......@@ -32070,48 +31950,42 @@ fn compareAll(
3207031950 if (ty.zigTypeTag() == .Vector) {
3207131951 var i: usize = 0;
3207231952 while (i < ty.vectorLen()) : (i += 1) {
32073 if (!(try sema.compareScalar(block, src, lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()))) {
31953 if (!(try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType()))) {
3207431954 return false;
3207531955 }
3207631956 }
3207731957 return true;
3207831958 }
32079 return sema.compareScalar(block, src, lhs, op, rhs, ty);
31959 return sema.compareScalar(lhs, op, rhs, ty);
3208031960}
3208131961
3208231962/// Asserts the values are comparable. Both operands have type `ty`.
3208331963fn compareScalar(
3208431964 sema: *Sema,
32085 block: *Block,
32086 src: LazySrcLoc,
3208731965 lhs: Value,
3208831966 op: std.math.CompareOperator,
3208931967 rhs: Value,
3209031968 ty: Type,
3209131969) CompileError!bool {
3209231970 switch (op) {
32093 .eq => return sema.valuesEqual(block, src, lhs, rhs, ty),
32094 .neq => return !(try sema.valuesEqual(block, src, lhs, rhs, ty)),
32095 else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod.getTarget(), sema.kit(block, src)),
31971 .eq => return sema.valuesEqual(lhs, rhs, ty),
31972 .neq => return !(try sema.valuesEqual(lhs, rhs, ty)),
31973 else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod.getTarget(), sema),
3209631974 }
3209731975}
3209831976
3209931977fn valuesEqual(
3210031978 sema: *Sema,
32101 block: *Block,
32102 src: LazySrcLoc,
3210331979 lhs: Value,
3210431980 rhs: Value,
3210531981 ty: Type,
3210631982) CompileError!bool {
32107 return Value.eqlAdvanced(lhs, ty, rhs, ty, sema.mod, sema.kit(block, src));
31983 return Value.eqlAdvanced(lhs, ty, rhs, ty, sema.mod, sema);
3210831984}
3210931985
3211031986/// Asserts the values are comparable vectors of type `ty`.
3211131987fn compareVector(
3211231988 sema: *Sema,
32113 block: *Block,
32114 src: LazySrcLoc,
3211531989 lhs: Value,
3211631990 op: std.math.CompareOperator,
3211731991 rhs: Value,
......@@ -32120,7 +31994,7 @@ fn compareVector(
3212031994 assert(ty.zigTypeTag() == .Vector);
3212131995 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
3212231996 for (result_data) |*scalar, i| {
32123 const res_bool = try sema.compareScalar(block, src, lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType());
31997 const res_bool = try sema.compareScalar(lhs.indexVectorlike(i), op, rhs.indexVectorlike(i), ty.scalarType());
3212431998 scalar.* = Value.makeBool(res_bool);
3212531999 }
3212632000 return Value.Tag.aggregate.create(sema.arena, result_data);
src/type.zig+78-76
......@@ -7,6 +7,7 @@ const Module = @import("Module.zig");
77const log = std.log.scoped(.Type);
88const target_util = @import("target.zig");
99const TypedValue = @import("TypedValue.zig");
10const Sema = @import("Sema.zig");
1011
1112const file_struct = @This();
1213
......@@ -2325,7 +2326,7 @@ pub const Type = extern union {
23252326 pub fn hasRuntimeBitsAdvanced(
23262327 ty: Type,
23272328 ignore_comptime_only: bool,
2328 sema_kit: ?Module.WipAnalysis,
2329 opt_sema: ?*Sema,
23292330 ) Module.CompileError!bool {
23302331 switch (ty.tag()) {
23312332 .u1,
......@@ -2405,8 +2406,8 @@ pub const Type = extern union {
24052406 return true;
24062407 } else if (ty.childType().zigTypeTag() == .Fn) {
24072408 return !ty.childType().fnInfo().is_generic;
2408 } else if (sema_kit) |sk| {
2409 return !(try sk.sema.typeRequiresComptime(ty));
2409 } else if (opt_sema) |sema| {
2410 return !(try sema.typeRequiresComptime(ty));
24102411 } else {
24112412 return !comptimeOnly(ty);
24122413 }
......@@ -2444,8 +2445,8 @@ pub const Type = extern union {
24442445 }
24452446 if (ignore_comptime_only) {
24462447 return true;
2447 } else if (sema_kit) |sk| {
2448 return !(try sk.sema.typeRequiresComptime(child_ty));
2448 } else if (opt_sema) |sema| {
2449 return !(try sema.typeRequiresComptime(child_ty));
24492450 } else {
24502451 return !comptimeOnly(child_ty);
24512452 }
......@@ -2458,13 +2459,13 @@ pub const Type = extern union {
24582459 // and then later if our guess was incorrect, we emit a compile error.
24592460 return true;
24602461 }
2461 if (sema_kit) |sk| {
2462 _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
2462 if (opt_sema) |sema| {
2463 _ = try sema.resolveTypeFields(ty);
24632464 }
24642465 assert(struct_obj.haveFieldTypes());
24652466 for (struct_obj.fields.values()) |field| {
24662467 if (field.is_comptime) continue;
2467 if (try field.ty.hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit))
2468 if (try field.ty.hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema))
24682469 return true;
24692470 } else {
24702471 return false;
......@@ -2473,7 +2474,7 @@ pub const Type = extern union {
24732474
24742475 .enum_full => {
24752476 const enum_full = ty.castTag(.enum_full).?.data;
2476 return enum_full.tag_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit);
2477 return enum_full.tag_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema);
24772478 },
24782479 .enum_simple => {
24792480 const enum_simple = ty.castTag(.enum_simple).?.data;
......@@ -2482,17 +2483,17 @@ pub const Type = extern union {
24822483 .enum_numbered, .enum_nonexhaustive => {
24832484 var buffer: Payload.Bits = undefined;
24842485 const int_tag_ty = ty.intTagType(&buffer);
2485 return int_tag_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit);
2486 return int_tag_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema);
24862487 },
24872488
24882489 .@"union" => {
24892490 const union_obj = ty.castTag(.@"union").?.data;
2490 if (sema_kit) |sk| {
2491 _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
2491 if (opt_sema) |sema| {
2492 _ = try sema.resolveTypeFields(ty);
24922493 }
24932494 assert(union_obj.haveFieldTypes());
24942495 for (union_obj.fields.values()) |value| {
2495 if (try value.ty.hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit))
2496 if (try value.ty.hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema))
24962497 return true;
24972498 } else {
24982499 return false;
......@@ -2500,16 +2501,16 @@ pub const Type = extern union {
25002501 },
25012502 .union_safety_tagged, .union_tagged => {
25022503 const union_obj = ty.cast(Payload.Union).?.data;
2503 if (try union_obj.tag_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit)) {
2504 if (try union_obj.tag_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema)) {
25042505 return true;
25052506 }
25062507
2507 if (sema_kit) |sk| {
2508 _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
2508 if (opt_sema) |sema| {
2509 _ = try sema.resolveTypeFields(ty);
25092510 }
25102511 assert(union_obj.haveFieldTypes());
25112512 for (union_obj.fields.values()) |value| {
2512 if (try value.ty.hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit))
2513 if (try value.ty.hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema))
25132514 return true;
25142515 } else {
25152516 return false;
......@@ -2517,9 +2518,9 @@ pub const Type = extern union {
25172518 },
25182519
25192520 .array, .vector => return ty.arrayLen() != 0 and
2520 try ty.elemType().hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit),
2521 try ty.elemType().hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema),
25212522 .array_u8 => return ty.arrayLen() != 0,
2522 .array_sentinel => return ty.childType().hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit),
2523 .array_sentinel => return ty.childType().hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema),
25232524
25242525 .int_signed, .int_unsigned => return ty.cast(Payload.Bits).?.data != 0,
25252526
......@@ -2528,7 +2529,7 @@ pub const Type = extern union {
25282529 for (tuple.types) |field_ty, i| {
25292530 const val = tuple.values[i];
25302531 if (val.tag() != .unreachable_value) continue; // comptime field
2531 if (try field_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, sema_kit)) return true;
2532 if (try field_ty.hasRuntimeBitsAdvanced(ignore_comptime_only, opt_sema)) return true;
25322533 }
25332534 return false;
25342535 },
......@@ -2721,7 +2722,7 @@ pub const Type = extern union {
27212722 return ptrAlignmentAdvanced(ty, target, null) catch unreachable;
27222723 }
27232724
2724 pub fn ptrAlignmentAdvanced(ty: Type, target: Target, sema_kit: ?Module.WipAnalysis) !u32 {
2725 pub fn ptrAlignmentAdvanced(ty: Type, target: Target, opt_sema: ?*Sema) !u32 {
27252726 switch (ty.tag()) {
27262727 .single_const_pointer,
27272728 .single_mut_pointer,
......@@ -2735,8 +2736,8 @@ pub const Type = extern union {
27352736 .optional_single_mut_pointer,
27362737 => {
27372738 const child_type = ty.cast(Payload.ElemType).?.data;
2738 if (sema_kit) |sk| {
2739 const res = try child_type.abiAlignmentAdvanced(target, .{ .sema_kit = sk });
2739 if (opt_sema) |sema| {
2740 const res = try child_type.abiAlignmentAdvanced(target, .{ .sema = sema });
27402741 return res.scalar;
27412742 }
27422743 return (child_type.abiAlignmentAdvanced(target, .eager) catch unreachable).scalar;
......@@ -2753,14 +2754,14 @@ pub const Type = extern union {
27532754 const ptr_info = ty.castTag(.pointer).?.data;
27542755 if (ptr_info.@"align" != 0) {
27552756 return ptr_info.@"align";
2756 } else if (sema_kit) |sk| {
2757 const res = try ptr_info.pointee_type.abiAlignmentAdvanced(target, .{ .sema_kit = sk });
2757 } else if (opt_sema) |sema| {
2758 const res = try ptr_info.pointee_type.abiAlignmentAdvanced(target, .{ .sema = sema });
27582759 return res.scalar;
27592760 } else {
27602761 return (ptr_info.pointee_type.abiAlignmentAdvanced(target, .eager) catch unreachable).scalar;
27612762 }
27622763 },
2763 .optional => return ty.castTag(.optional).?.data.ptrAlignmentAdvanced(target, sema_kit),
2764 .optional => return ty.castTag(.optional).?.data.ptrAlignmentAdvanced(target, opt_sema),
27642765
27652766 else => unreachable,
27662767 }
......@@ -2819,22 +2820,22 @@ pub const Type = extern union {
28192820 const AbiAlignmentAdvancedStrat = union(enum) {
28202821 eager,
28212822 lazy: Allocator,
2822 sema_kit: Module.WipAnalysis,
2823 sema: *Sema,
28232824 };
28242825
28252826 /// If you pass `eager` you will get back `scalar` and assert the type is resolved.
28262827 /// In this case there will be no error, guaranteed.
28272828 /// If you pass `lazy` you may get back `scalar` or `val`.
28282829 /// If `val` is returned, a reference to `ty` has been captured.
2829 /// If you pass `sema_kit` you will get back `scalar` and resolve the type if
2830 /// If you pass `sema` you will get back `scalar` and resolve the type if
28302831 /// necessary, possibly returning a CompileError.
28312832 pub fn abiAlignmentAdvanced(
28322833 ty: Type,
28332834 target: Target,
28342835 strat: AbiAlignmentAdvancedStrat,
28352836 ) Module.CompileError!AbiAlignmentAdvanced {
2836 const sema_kit = switch (strat) {
2837 .sema_kit => |sk| sk,
2837 const opt_sema = switch (strat) {
2838 .sema => |sema| sema,
28382839 else => null,
28392840 };
28402841 switch (ty.tag()) {
......@@ -2939,7 +2940,7 @@ pub const Type = extern union {
29392940
29402941 .vector => {
29412942 const len = ty.arrayLen();
2942 const bits = try bitSizeAdvanced(ty.elemType(), target, sema_kit);
2943 const bits = try bitSizeAdvanced(ty.elemType(), target, opt_sema);
29432944 const bytes = ((bits * len) + 7) / 8;
29442945 const alignment = std.math.ceilPowerOfTwoAssert(u64, bytes);
29452946 return AbiAlignmentAdvanced{ .scalar = @intCast(u32, alignment) };
......@@ -2969,8 +2970,8 @@ pub const Type = extern union {
29692970 }
29702971
29712972 switch (strat) {
2972 .eager, .sema_kit => {
2973 if (!(try child_type.hasRuntimeBitsAdvanced(false, sema_kit))) {
2973 .eager, .sema => {
2974 if (!(try child_type.hasRuntimeBitsAdvanced(false, opt_sema))) {
29742975 return AbiAlignmentAdvanced{ .scalar = 1 };
29752976 }
29762977 return child_type.abiAlignmentAdvanced(target, strat);
......@@ -2988,8 +2989,8 @@ pub const Type = extern union {
29882989 const data = ty.castTag(.error_union).?.data;
29892990 const code_align = abiAlignment(Type.anyerror, target);
29902991 switch (strat) {
2991 .eager, .sema_kit => {
2992 if (!(try data.payload.hasRuntimeBitsAdvanced(false, sema_kit))) {
2992 .eager, .sema => {
2993 if (!(try data.payload.hasRuntimeBitsAdvanced(false, opt_sema))) {
29932994 return AbiAlignmentAdvanced{ .scalar = code_align };
29942995 }
29952996 return AbiAlignmentAdvanced{ .scalar = @max(
......@@ -3013,22 +3014,22 @@ pub const Type = extern union {
30133014
30143015 .@"struct" => {
30153016 const struct_obj = ty.castTag(.@"struct").?.data;
3016 if (sema_kit) |sk| {
3017 if (opt_sema) |sema| {
30173018 if (struct_obj.status == .field_types_wip) {
30183019 // We'll guess "pointer-aligned" and if we guess wrong, emit
30193020 // a compile error later.
30203021 return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) };
30213022 }
3022 _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
3023 _ = try sema.resolveTypeFields(ty);
30233024 }
30243025 if (!struct_obj.haveFieldTypes()) switch (strat) {
30253026 .eager => unreachable, // struct layout not resolved
3026 .sema_kit => unreachable, // handled above
3027 .sema => unreachable, // handled above
30273028 .lazy => |arena| return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) },
30283029 };
30293030 if (struct_obj.layout == .Packed) {
30303031 switch (strat) {
3031 .sema_kit => |sk| try sk.sema.resolveTypeLayout(sk.block, sk.src, ty),
3032 .sema => |sema| try sema.resolveTypeLayout(ty),
30323033 .lazy => |arena| {
30333034 if (!struct_obj.haveLayout()) {
30343035 return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) };
......@@ -3043,7 +3044,7 @@ pub const Type = extern union {
30433044 const fields = ty.structFields();
30443045 var big_align: u32 = 0;
30453046 for (fields.values()) |field| {
3046 if (!(try field.ty.hasRuntimeBitsAdvanced(false, sema_kit))) continue;
3047 if (!(try field.ty.hasRuntimeBitsAdvanced(false, opt_sema))) continue;
30473048
30483049 const field_align = if (field.abi_align != 0)
30493050 field.abi_align
......@@ -3051,7 +3052,7 @@ pub const Type = extern union {
30513052 .scalar => |a| a,
30523053 .val => switch (strat) {
30533054 .eager => unreachable, // struct layout not resolved
3054 .sema_kit => unreachable, // handled above
3055 .sema => unreachable, // handled above
30553056 .lazy => |arena| return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) },
30563057 },
30573058 };
......@@ -3080,7 +3081,7 @@ pub const Type = extern union {
30803081 .scalar => |field_align| big_align = @max(big_align, field_align),
30813082 .val => switch (strat) {
30823083 .eager => unreachable, // field type alignment not resolved
3083 .sema_kit => unreachable, // passed to abiAlignmentAdvanced above
3084 .sema => unreachable, // passed to abiAlignmentAdvanced above
30843085 .lazy => |arena| return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) },
30853086 },
30863087 }
......@@ -3132,21 +3133,21 @@ pub const Type = extern union {
31323133 union_obj: *Module.Union,
31333134 have_tag: bool,
31343135 ) Module.CompileError!AbiAlignmentAdvanced {
3135 const sema_kit = switch (strat) {
3136 .sema_kit => |sk| sk,
3136 const opt_sema = switch (strat) {
3137 .sema => |sema| sema,
31373138 else => null,
31383139 };
3139 if (sema_kit) |sk| {
3140 if (opt_sema) |sema| {
31403141 if (union_obj.status == .field_types_wip) {
31413142 // We'll guess "pointer-aligned" and if we guess wrong, emit
31423143 // a compile error later.
31433144 return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) };
31443145 }
3145 _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
3146 _ = try sema.resolveTypeFields(ty);
31463147 }
31473148 if (!union_obj.haveFieldTypes()) switch (strat) {
31483149 .eager => unreachable, // union layout not resolved
3149 .sema_kit => unreachable, // handled above
3150 .sema => unreachable, // handled above
31503151 .lazy => |arena| return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) },
31513152 };
31523153 if (union_obj.fields.count() == 0) {
......@@ -3160,7 +3161,7 @@ pub const Type = extern union {
31603161 var max_align: u32 = 0;
31613162 if (have_tag) max_align = union_obj.tag_ty.abiAlignment(target);
31623163 for (union_obj.fields.values()) |field| {
3163 if (!(try field.ty.hasRuntimeBitsAdvanced(false, sema_kit))) continue;
3164 if (!(try field.ty.hasRuntimeBitsAdvanced(false, opt_sema))) continue;
31643165
31653166 const field_align = if (field.abi_align != 0)
31663167 field.abi_align
......@@ -3168,7 +3169,7 @@ pub const Type = extern union {
31683169 .scalar => |a| a,
31693170 .val => switch (strat) {
31703171 .eager => unreachable, // struct layout not resolved
3171 .sema_kit => unreachable, // handled above
3172 .sema => unreachable, // handled above
31723173 .lazy => |arena| return AbiAlignmentAdvanced{ .val = try Value.Tag.lazy_align.create(arena, ty) },
31733174 },
31743175 };
......@@ -3200,7 +3201,7 @@ pub const Type = extern union {
32003201 /// In this case there will be no error, guaranteed.
32013202 /// If you pass `lazy` you may get back `scalar` or `val`.
32023203 /// If `val` is returned, a reference to `ty` has been captured.
3203 /// If you pass `sema_kit` you will get back `scalar` and resolve the type if
3204 /// If you pass `sema` you will get back `scalar` and resolve the type if
32043205 /// necessary, possibly returning a CompileError.
32053206 pub fn abiSizeAdvanced(
32063207 ty: Type,
......@@ -3243,7 +3244,7 @@ pub const Type = extern union {
32433244 .Packed => {
32443245 const struct_obj = ty.castTag(.@"struct").?.data;
32453246 switch (strat) {
3246 .sema_kit => |sk| try sk.sema.resolveTypeLayout(sk.block, sk.src, ty),
3247 .sema => |sema| try sema.resolveTypeLayout(ty),
32473248 .lazy => |arena| {
32483249 if (!struct_obj.haveLayout()) {
32493250 return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) };
......@@ -3256,7 +3257,7 @@ pub const Type = extern union {
32563257 },
32573258 else => {
32583259 switch (strat) {
3259 .sema_kit => |sk| try sk.sema.resolveTypeLayout(sk.block, sk.src, ty),
3260 .sema => |sema| try sema.resolveTypeLayout(ty),
32603261 .lazy => |arena| {
32613262 if (ty.castTag(.@"struct")) |payload| {
32623263 const struct_obj = payload.data;
......@@ -3308,7 +3309,7 @@ pub const Type = extern union {
33083309 switch (try payload.elem_type.abiSizeAdvanced(target, strat)) {
33093310 .scalar => |elem_size| return AbiSizeAdvanced{ .scalar = payload.len * elem_size },
33103311 .val => switch (strat) {
3311 .sema_kit => unreachable,
3312 .sema => unreachable,
33123313 .eager => unreachable,
33133314 .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) },
33143315 },
......@@ -3319,7 +3320,7 @@ pub const Type = extern union {
33193320 switch (try payload.elem_type.abiSizeAdvanced(target, strat)) {
33203321 .scalar => |elem_size| return AbiSizeAdvanced{ .scalar = (payload.len + 1) * elem_size },
33213322 .val => switch (strat) {
3322 .sema_kit => unreachable,
3323 .sema => unreachable,
33233324 .eager => unreachable,
33243325 .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) },
33253326 },
......@@ -3328,14 +3329,14 @@ pub const Type = extern union {
33283329
33293330 .vector => {
33303331 const payload = ty.castTag(.vector).?.data;
3331 const sema_kit = switch (strat) {
3332 .sema_kit => |sk| sk,
3332 const opt_sema = switch (strat) {
3333 .sema => |sema| sema,
33333334 .eager => null,
33343335 .lazy => |arena| return AbiSizeAdvanced{
33353336 .val = try Value.Tag.lazy_size.create(arena, ty),
33363337 },
33373338 };
3338 const elem_bits = try payload.elem_type.bitSizeAdvanced(target, sema_kit);
3339 const elem_bits = try payload.elem_type.bitSizeAdvanced(target, opt_sema);
33393340 const total_bits = elem_bits * payload.len;
33403341 const total_bytes = (total_bits + 7) / 8;
33413342 const alignment = switch (try ty.abiAlignmentAdvanced(target, strat)) {
......@@ -3446,7 +3447,7 @@ pub const Type = extern union {
34463447 const payload_size = switch (try child_type.abiSizeAdvanced(target, strat)) {
34473448 .scalar => |elem_size| elem_size,
34483449 .val => switch (strat) {
3449 .sema_kit => unreachable,
3450 .sema => unreachable,
34503451 .eager => unreachable,
34513452 .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) },
34523453 },
......@@ -3475,7 +3476,7 @@ pub const Type = extern union {
34753476 const payload_size = switch (try data.payload.abiSizeAdvanced(target, strat)) {
34763477 .scalar => |elem_size| elem_size,
34773478 .val => switch (strat) {
3478 .sema_kit => unreachable,
3479 .sema => unreachable,
34793480 .eager => unreachable,
34803481 .lazy => |arena| return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) },
34813482 },
......@@ -3506,7 +3507,7 @@ pub const Type = extern union {
35063507 have_tag: bool,
35073508 ) Module.CompileError!AbiSizeAdvanced {
35083509 switch (strat) {
3509 .sema_kit => |sk| try sk.sema.resolveTypeLayout(sk.block, sk.src, ty),
3510 .sema => |sema| try sema.resolveTypeLayout(ty),
35103511 .lazy => |arena| {
35113512 if (!union_obj.haveLayout()) {
35123513 return AbiSizeAdvanced{ .val = try Value.Tag.lazy_size.create(arena, ty) };
......@@ -3533,14 +3534,15 @@ pub const Type = extern union {
35333534 return bitSizeAdvanced(ty, target, null) catch unreachable;
35343535 }
35353536
3536 /// If you pass `sema_kit`, any recursive type resolutions will happen if
3537 /// If you pass `opt_sema`, any recursive type resolutions will happen if
35373538 /// necessary, possibly returning a CompileError. Passing `null` instead asserts
35383539 /// the type is fully resolved, and there will be no error, guaranteed.
35393540 pub fn bitSizeAdvanced(
35403541 ty: Type,
35413542 target: Target,
3542 sema_kit: ?Module.WipAnalysis,
3543 opt_sema: ?*Sema,
35433544 ) Module.CompileError!u64 {
3545 const strat: AbiAlignmentAdvancedStrat = if (opt_sema) |sema| .{ .sema = sema } else .eager;
35443546 switch (ty.tag()) {
35453547 .fn_noreturn_no_args => unreachable, // represents machine code; not a pointer
35463548 .fn_void_no_args => unreachable, // represents machine code; not a pointer
......@@ -3578,21 +3580,21 @@ pub const Type = extern union {
35783580 .@"struct" => {
35793581 const struct_obj = ty.castTag(.@"struct").?.data;
35803582 if (struct_obj.layout != .Packed) {
3581 return (try ty.abiSizeAdvanced(target, if (sema_kit) |sk| .{ .sema_kit = sk } else .eager)).scalar * 8;
3583 return (try ty.abiSizeAdvanced(target, strat)).scalar * 8;
35823584 }
3583 if (sema_kit) |sk| _ = try sk.sema.resolveTypeLayout(sk.block, sk.src, ty);
3585 if (opt_sema) |sema| _ = try sema.resolveTypeLayout(ty);
35843586 assert(struct_obj.haveLayout());
3585 return try struct_obj.backing_int_ty.bitSizeAdvanced(target, sema_kit);
3587 return try struct_obj.backing_int_ty.bitSizeAdvanced(target, opt_sema);
35863588 },
35873589
35883590 .tuple, .anon_struct => {
3589 if (sema_kit) |sk| _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
3591 if (opt_sema) |sema| _ = try sema.resolveTypeFields(ty);
35903592 if (ty.containerLayout() != .Packed) {
3591 return (try ty.abiSizeAdvanced(target, if (sema_kit) |sk| .{ .sema_kit = sk } else .eager)).scalar * 8;
3593 return (try ty.abiSizeAdvanced(target, strat)).scalar * 8;
35923594 }
35933595 var total: u64 = 0;
35943596 for (ty.tupleFields().types) |field_ty| {
3595 total += try bitSizeAdvanced(field_ty, target, sema_kit);
3597 total += try bitSizeAdvanced(field_ty, target, opt_sema);
35963598 }
35973599 return total;
35983600 },
......@@ -3600,27 +3602,27 @@ pub const Type = extern union {
36003602 .enum_simple, .enum_full, .enum_nonexhaustive, .enum_numbered => {
36013603 var buffer: Payload.Bits = undefined;
36023604 const int_tag_ty = ty.intTagType(&buffer);
3603 return try bitSizeAdvanced(int_tag_ty, target, sema_kit);
3605 return try bitSizeAdvanced(int_tag_ty, target, opt_sema);
36043606 },
36053607
36063608 .@"union", .union_safety_tagged, .union_tagged => {
3607 if (sema_kit) |sk| _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
3609 if (opt_sema) |sema| _ = try sema.resolveTypeFields(ty);
36083610 if (ty.containerLayout() != .Packed) {
3609 return (try ty.abiSizeAdvanced(target, if (sema_kit) |sk| .{ .sema_kit = sk } else .eager)).scalar * 8;
3611 return (try ty.abiSizeAdvanced(target, strat)).scalar * 8;
36103612 }
36113613 const union_obj = ty.cast(Payload.Union).?.data;
36123614 assert(union_obj.haveFieldTypes());
36133615
36143616 var size: u64 = 0;
36153617 for (union_obj.fields.values()) |field| {
3616 size = @max(size, try bitSizeAdvanced(field.ty, target, sema_kit));
3618 size = @max(size, try bitSizeAdvanced(field.ty, target, opt_sema));
36173619 }
36183620 return size;
36193621 },
36203622
36213623 .vector => {
36223624 const payload = ty.castTag(.vector).?.data;
3623 const elem_bit_size = try bitSizeAdvanced(payload.elem_type, target, sema_kit);
3625 const elem_bit_size = try bitSizeAdvanced(payload.elem_type, target, opt_sema);
36243626 return elem_bit_size * payload.len;
36253627 },
36263628 .array_u8 => return 8 * ty.castTag(.array_u8).?.data,
......@@ -3630,7 +3632,7 @@ pub const Type = extern union {
36303632 const elem_size = std.math.max(payload.elem_type.abiAlignment(target), payload.elem_type.abiSize(target));
36313633 if (elem_size == 0 or payload.len == 0)
36323634 return @as(u64, 0);
3633 const elem_bit_size = try bitSizeAdvanced(payload.elem_type, target, sema_kit);
3635 const elem_bit_size = try bitSizeAdvanced(payload.elem_type, target, opt_sema);
36343636 return (payload.len - 1) * 8 * elem_size + elem_bit_size;
36353637 },
36363638 .array_sentinel => {
......@@ -3639,7 +3641,7 @@ pub const Type = extern union {
36393641 payload.elem_type.abiAlignment(target),
36403642 payload.elem_type.abiSize(target),
36413643 );
3642 const elem_bit_size = try bitSizeAdvanced(payload.elem_type, target, sema_kit);
3644 const elem_bit_size = try bitSizeAdvanced(payload.elem_type, target, opt_sema);
36433645 return payload.len * 8 * elem_size + elem_bit_size;
36443646 },
36453647
......@@ -3706,7 +3708,7 @@ pub const Type = extern union {
37063708 .optional, .error_union => {
37073709 // Optionals and error unions are not packed so their bitsize
37083710 // includes padding bits.
3709 return (try abiSizeAdvanced(ty, target, if (sema_kit) |sk| .{ .sema_kit = sk } else .eager)).scalar * 8;
3711 return (try abiSizeAdvanced(ty, target, strat)).scalar * 8;
37103712 },
37113713
37123714 .atomic_order,
src/value.zig+56-56
......@@ -1099,7 +1099,7 @@ pub const Value = extern union {
10991099 val: Value,
11001100 space: *BigIntSpace,
11011101 target: Target,
1102 sema_kit: ?Module.WipAnalysis,
1102 opt_sema: ?*Sema,
11031103 ) Module.CompileError!BigIntConst {
11041104 switch (val.tag()) {
11051105 .null_value,
......@@ -1121,16 +1121,16 @@ pub const Value = extern union {
11211121
11221122 .lazy_align => {
11231123 const ty = val.castTag(.lazy_align).?.data;
1124 if (sema_kit) |sk| {
1125 try sk.sema.resolveTypeLayout(sk.block, sk.src, ty);
1124 if (opt_sema) |sema| {
1125 try sema.resolveTypeLayout(ty);
11261126 }
11271127 const x = ty.abiAlignment(target);
11281128 return BigIntMutable.init(&space.limbs, x).toConst();
11291129 },
11301130 .lazy_size => {
11311131 const ty = val.castTag(.lazy_size).?.data;
1132 if (sema_kit) |sk| {
1133 try sk.sema.resolveTypeLayout(sk.block, sk.src, ty);
1132 if (opt_sema) |sema| {
1133 try sema.resolveTypeLayout(ty);
11341134 }
11351135 const x = ty.abiSize(target);
11361136 return BigIntMutable.init(&space.limbs, x).toConst();
......@@ -1138,7 +1138,7 @@ pub const Value = extern union {
11381138
11391139 .elem_ptr => {
11401140 const elem_ptr = val.castTag(.elem_ptr).?.data;
1141 const array_addr = (try elem_ptr.array_ptr.getUnsignedIntAdvanced(target, sema_kit)).?;
1141 const array_addr = (try elem_ptr.array_ptr.getUnsignedIntAdvanced(target, opt_sema)).?;
11421142 const elem_size = elem_ptr.elem_ty.abiSize(target);
11431143 const new_addr = array_addr + elem_size * elem_ptr.index;
11441144 return BigIntMutable.init(&space.limbs, new_addr).toConst();
......@@ -1156,7 +1156,7 @@ pub const Value = extern union {
11561156
11571157 /// If the value fits in a u64, return it, otherwise null.
11581158 /// Asserts not undefined.
1159 pub fn getUnsignedIntAdvanced(val: Value, target: Target, sema_kit: ?Module.WipAnalysis) !?u64 {
1159 pub fn getUnsignedIntAdvanced(val: Value, target: Target, opt_sema: ?*Sema) !?u64 {
11601160 switch (val.tag()) {
11611161 .zero,
11621162 .bool_false,
......@@ -1176,16 +1176,16 @@ pub const Value = extern union {
11761176
11771177 .lazy_align => {
11781178 const ty = val.castTag(.lazy_align).?.data;
1179 if (sema_kit) |sk| {
1180 return (try ty.abiAlignmentAdvanced(target, .{ .sema_kit = sk })).scalar;
1179 if (opt_sema) |sema| {
1180 return (try ty.abiAlignmentAdvanced(target, .{ .sema = sema })).scalar;
11811181 } else {
11821182 return ty.abiAlignment(target);
11831183 }
11841184 },
11851185 .lazy_size => {
11861186 const ty = val.castTag(.lazy_size).?.data;
1187 if (sema_kit) |sk| {
1188 return (try ty.abiSizeAdvanced(target, .{ .sema_kit = sk })).scalar;
1187 if (opt_sema) |sema| {
1188 return (try ty.abiSizeAdvanced(target, .{ .sema = sema })).scalar;
11891189 } else {
11901190 return ty.abiSize(target);
11911191 }
......@@ -1886,7 +1886,7 @@ pub const Value = extern union {
18861886
18871887 pub fn orderAgainstZeroAdvanced(
18881888 lhs: Value,
1889 sema_kit: ?Module.WipAnalysis,
1889 opt_sema: ?*Sema,
18901890 ) Module.CompileError!std.math.Order {
18911891 return switch (lhs.tag()) {
18921892 .zero,
......@@ -1911,7 +1911,7 @@ pub const Value = extern union {
19111911
19121912 .lazy_align => {
19131913 const ty = lhs.castTag(.lazy_align).?.data;
1914 if (try ty.hasRuntimeBitsAdvanced(false, sema_kit)) {
1914 if (try ty.hasRuntimeBitsAdvanced(false, opt_sema)) {
19151915 return .gt;
19161916 } else {
19171917 return .eq;
......@@ -1919,7 +1919,7 @@ pub const Value = extern union {
19191919 },
19201920 .lazy_size => {
19211921 const ty = lhs.castTag(.lazy_size).?.data;
1922 if (try ty.hasRuntimeBitsAdvanced(false, sema_kit)) {
1922 if (try ty.hasRuntimeBitsAdvanced(false, opt_sema)) {
19231923 return .gt;
19241924 } else {
19251925 return .eq;
......@@ -1934,7 +1934,7 @@ pub const Value = extern union {
19341934
19351935 .elem_ptr => {
19361936 const elem_ptr = lhs.castTag(.elem_ptr).?.data;
1937 switch (try elem_ptr.array_ptr.orderAgainstZeroAdvanced(sema_kit)) {
1937 switch (try elem_ptr.array_ptr.orderAgainstZeroAdvanced(opt_sema)) {
19381938 .lt => unreachable,
19391939 .gt => return .gt,
19401940 .eq => {
......@@ -1957,12 +1957,12 @@ pub const Value = extern union {
19571957 }
19581958
19591959 /// Asserts the value is comparable.
1960 /// If sema_kit is null then this function asserts things are resolved and cannot fail.
1961 pub fn orderAdvanced(lhs: Value, rhs: Value, target: Target, sema_kit: ?Module.WipAnalysis) !std.math.Order {
1960 /// If opt_sema is null then this function asserts things are resolved and cannot fail.
1961 pub fn orderAdvanced(lhs: Value, rhs: Value, target: Target, opt_sema: ?*Sema) !std.math.Order {
19621962 const lhs_tag = lhs.tag();
19631963 const rhs_tag = rhs.tag();
1964 const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(sema_kit);
1965 const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(sema_kit);
1964 const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(opt_sema);
1965 const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(opt_sema);
19661966 switch (lhs_against_zero) {
19671967 .lt => if (rhs_against_zero != .lt) return .lt,
19681968 .eq => return rhs_against_zero.invert(),
......@@ -1996,8 +1996,8 @@ pub const Value = extern union {
19961996
19971997 var lhs_bigint_space: BigIntSpace = undefined;
19981998 var rhs_bigint_space: BigIntSpace = undefined;
1999 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_bigint_space, target, sema_kit);
2000 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_bigint_space, target, sema_kit);
1999 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_bigint_space, target, opt_sema);
2000 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_bigint_space, target, opt_sema);
20012001 return lhs_bigint.order(rhs_bigint);
20022002 }
20032003
......@@ -2012,7 +2012,7 @@ pub const Value = extern union {
20122012 op: std.math.CompareOperator,
20132013 rhs: Value,
20142014 target: Target,
2015 sema_kit: ?Module.WipAnalysis,
2015 opt_sema: ?*Sema,
20162016 ) !bool {
20172017 if (lhs.pointerDecl()) |lhs_decl| {
20182018 if (rhs.pointerDecl()) |rhs_decl| {
......@@ -2035,7 +2035,7 @@ pub const Value = extern union {
20352035 else => {},
20362036 }
20372037 }
2038 return (try orderAdvanced(lhs, rhs, target, sema_kit)).compare(op);
2038 return (try orderAdvanced(lhs, rhs, target, opt_sema)).compare(op);
20392039 }
20402040
20412041 /// Asserts the values are comparable. Both operands have type `ty`.
......@@ -2079,13 +2079,13 @@ pub const Value = extern union {
20792079 pub fn compareAllWithZeroAdvanced(
20802080 lhs: Value,
20812081 op: std.math.CompareOperator,
2082 sema_kit: ?Module.WipAnalysis,
2082 opt_sema: ?*Sema,
20832083 ) Module.CompileError!bool {
20842084 switch (lhs.tag()) {
2085 .repeated => return lhs.castTag(.repeated).?.data.compareAllWithZeroAdvanced(op, sema_kit),
2085 .repeated => return lhs.castTag(.repeated).?.data.compareAllWithZeroAdvanced(op, opt_sema),
20862086 .aggregate => {
20872087 for (lhs.castTag(.aggregate).?.data) |elem_val| {
2088 if (!(try elem_val.compareAllWithZeroAdvanced(op, sema_kit))) return false;
2088 if (!(try elem_val.compareAllWithZeroAdvanced(op, opt_sema))) return false;
20892089 }
20902090 return true;
20912091 },
......@@ -2096,7 +2096,7 @@ pub const Value = extern union {
20962096 .float_128 => if (std.math.isNan(lhs.castTag(.float_128).?.data)) return op != .neq,
20972097 else => {},
20982098 }
2099 return (try orderAgainstZeroAdvanced(lhs, sema_kit)).compare(op);
2099 return (try orderAgainstZeroAdvanced(lhs, opt_sema)).compare(op);
21002100 }
21012101
21022102 pub fn eql(a: Value, b: Value, ty: Type, mod: *Module) bool {
......@@ -2111,14 +2111,14 @@ pub const Value = extern union {
21112111 /// for `a`. This function must act *as if* `a` has been coerced to `ty`. This complication
21122112 /// is required in order to make generic function instantiation efficient - specifically
21132113 /// the insertion into the monomorphized function table.
2114 /// If `null` is provided for `sema_kit` then it is guaranteed no error will be returned.
2114 /// If `null` is provided for `opt_sema` then it is guaranteed no error will be returned.
21152115 pub fn eqlAdvanced(
21162116 a: Value,
21172117 a_ty: Type,
21182118 b: Value,
21192119 ty: Type,
21202120 mod: *Module,
2121 sema_kit: ?Module.WipAnalysis,
2121 opt_sema: ?*Sema,
21222122 ) Module.CompileError!bool {
21232123 const target = mod.getTarget();
21242124 const a_tag = a.tag();
......@@ -2141,33 +2141,33 @@ pub const Value = extern union {
21412141 const b_payload = b.castTag(.opt_payload).?.data;
21422142 var buffer: Type.Payload.ElemType = undefined;
21432143 const payload_ty = ty.optionalChild(&buffer);
2144 return eqlAdvanced(a_payload, payload_ty, b_payload, payload_ty, mod, sema_kit);
2144 return eqlAdvanced(a_payload, payload_ty, b_payload, payload_ty, mod, opt_sema);
21452145 },
21462146 .slice => {
21472147 const a_payload = a.castTag(.slice).?.data;
21482148 const b_payload = b.castTag(.slice).?.data;
2149 if (!(try eqlAdvanced(a_payload.len, Type.usize, b_payload.len, Type.usize, mod, sema_kit))) {
2149 if (!(try eqlAdvanced(a_payload.len, Type.usize, b_payload.len, Type.usize, mod, opt_sema))) {
21502150 return false;
21512151 }
21522152
21532153 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
21542154 const ptr_ty = ty.slicePtrFieldType(&ptr_buf);
21552155
2156 return eqlAdvanced(a_payload.ptr, ptr_ty, b_payload.ptr, ptr_ty, mod, sema_kit);
2156 return eqlAdvanced(a_payload.ptr, ptr_ty, b_payload.ptr, ptr_ty, mod, opt_sema);
21572157 },
21582158 .elem_ptr => {
21592159 const a_payload = a.castTag(.elem_ptr).?.data;
21602160 const b_payload = b.castTag(.elem_ptr).?.data;
21612161 if (a_payload.index != b_payload.index) return false;
21622162
2163 return eqlAdvanced(a_payload.array_ptr, ty, b_payload.array_ptr, ty, mod, sema_kit);
2163 return eqlAdvanced(a_payload.array_ptr, ty, b_payload.array_ptr, ty, mod, opt_sema);
21642164 },
21652165 .field_ptr => {
21662166 const a_payload = a.castTag(.field_ptr).?.data;
21672167 const b_payload = b.castTag(.field_ptr).?.data;
21682168 if (a_payload.field_index != b_payload.field_index) return false;
21692169
2170 return eqlAdvanced(a_payload.container_ptr, ty, b_payload.container_ptr, ty, mod, sema_kit);
2170 return eqlAdvanced(a_payload.container_ptr, ty, b_payload.container_ptr, ty, mod, opt_sema);
21712171 },
21722172 .@"error" => {
21732173 const a_name = a.castTag(.@"error").?.data.name;
......@@ -2178,7 +2178,7 @@ pub const Value = extern union {
21782178 const a_payload = a.castTag(.eu_payload).?.data;
21792179 const b_payload = b.castTag(.eu_payload).?.data;
21802180 const payload_ty = ty.errorUnionPayload();
2181 return eqlAdvanced(a_payload, payload_ty, b_payload, payload_ty, mod, sema_kit);
2181 return eqlAdvanced(a_payload, payload_ty, b_payload, payload_ty, mod, opt_sema);
21822182 },
21832183 .eu_payload_ptr => @panic("TODO: Implement more pointer eql cases"),
21842184 .opt_payload_ptr => @panic("TODO: Implement more pointer eql cases"),
......@@ -2196,7 +2196,7 @@ pub const Value = extern union {
21962196 const types = ty.tupleFields().types;
21972197 assert(types.len == a_field_vals.len);
21982198 for (types) |field_ty, i| {
2199 if (!(try eqlAdvanced(a_field_vals[i], field_ty, b_field_vals[i], field_ty, mod, sema_kit))) {
2199 if (!(try eqlAdvanced(a_field_vals[i], field_ty, b_field_vals[i], field_ty, mod, opt_sema))) {
22002200 return false;
22012201 }
22022202 }
......@@ -2207,7 +2207,7 @@ pub const Value = extern union {
22072207 const fields = ty.structFields().values();
22082208 assert(fields.len == a_field_vals.len);
22092209 for (fields) |field, i| {
2210 if (!(try eqlAdvanced(a_field_vals[i], field.ty, b_field_vals[i], field.ty, mod, sema_kit))) {
2210 if (!(try eqlAdvanced(a_field_vals[i], field.ty, b_field_vals[i], field.ty, mod, opt_sema))) {
22112211 return false;
22122212 }
22132213 }
......@@ -2218,7 +2218,7 @@ pub const Value = extern union {
22182218 for (a_field_vals) |a_elem, i| {
22192219 const b_elem = b_field_vals[i];
22202220
2221 if (!(try eqlAdvanced(a_elem, elem_ty, b_elem, elem_ty, mod, sema_kit))) {
2221 if (!(try eqlAdvanced(a_elem, elem_ty, b_elem, elem_ty, mod, opt_sema))) {
22222222 return false;
22232223 }
22242224 }
......@@ -2230,7 +2230,7 @@ pub const Value = extern union {
22302230 switch (ty.containerLayout()) {
22312231 .Packed, .Extern => {
22322232 const tag_ty = ty.unionTagTypeHypothetical();
2233 if (!(try eqlAdvanced(a_union.tag, tag_ty, b_union.tag, tag_ty, mod, sema_kit))) {
2233 if (!(try eqlAdvanced(a_union.tag, tag_ty, b_union.tag, tag_ty, mod, opt_sema))) {
22342234 // In this case, we must disregard mismatching tags and compare
22352235 // based on the in-memory bytes of the payloads.
22362236 @panic("TODO comptime comparison of extern union values with mismatching tags");
......@@ -2238,13 +2238,13 @@ pub const Value = extern union {
22382238 },
22392239 .Auto => {
22402240 const tag_ty = ty.unionTagTypeHypothetical();
2241 if (!(try eqlAdvanced(a_union.tag, tag_ty, b_union.tag, tag_ty, mod, sema_kit))) {
2241 if (!(try eqlAdvanced(a_union.tag, tag_ty, b_union.tag, tag_ty, mod, opt_sema))) {
22422242 return false;
22432243 }
22442244 },
22452245 }
22462246 const active_field_ty = ty.unionFieldType(a_union.tag, mod);
2247 return eqlAdvanced(a_union.val, active_field_ty, b_union.val, active_field_ty, mod, sema_kit);
2247 return eqlAdvanced(a_union.val, active_field_ty, b_union.val, active_field_ty, mod, opt_sema);
22482248 },
22492249 else => {},
22502250 } else if (b_tag == .null_value or b_tag == .@"error") {
......@@ -2278,7 +2278,7 @@ pub const Value = extern union {
22782278 const b_val = b.enumToInt(ty, &buf_b);
22792279 var buf_ty: Type.Payload.Bits = undefined;
22802280 const int_ty = ty.intTagType(&buf_ty);
2281 return eqlAdvanced(a_val, int_ty, b_val, int_ty, mod, sema_kit);
2281 return eqlAdvanced(a_val, int_ty, b_val, int_ty, mod, opt_sema);
22822282 },
22832283 .Array, .Vector => {
22842284 const len = ty.arrayLen();
......@@ -2289,7 +2289,7 @@ pub const Value = extern union {
22892289 while (i < len) : (i += 1) {
22902290 const a_elem = elemValueBuffer(a, mod, i, &a_buf);
22912291 const b_elem = elemValueBuffer(b, mod, i, &b_buf);
2292 if (!(try eqlAdvanced(a_elem, elem_ty, b_elem, elem_ty, mod, sema_kit))) {
2292 if (!(try eqlAdvanced(a_elem, elem_ty, b_elem, elem_ty, mod, opt_sema))) {
22932293 return false;
22942294 }
22952295 }
......@@ -2313,7 +2313,7 @@ pub const Value = extern union {
23132313 .One => a,
23142314 else => unreachable,
23152315 };
2316 return try eqlAdvanced(a_ptr, ptr_ty, b.slicePtr(), ptr_ty, mod, sema_kit);
2316 return try eqlAdvanced(a_ptr, ptr_ty, b.slicePtr(), ptr_ty, mod, opt_sema);
23172317 },
23182318 .Many, .C, .One => {},
23192319 },
......@@ -2346,7 +2346,7 @@ pub const Value = extern union {
23462346 const field_tag = Value.initPayload(&field_tag_buf.base);
23472347 const tag_matches = tag_and_val.tag.eql(field_tag, union_obj.tag_ty, mod);
23482348 if (!tag_matches) return false;
2349 return eqlAdvanced(tag_and_val.val, union_obj.tag_ty, tuple.values[0], tuple.types[0], mod, sema_kit);
2349 return eqlAdvanced(tag_and_val.val, union_obj.tag_ty, tuple.values[0], tuple.types[0], mod, opt_sema);
23502350 }
23512351 return false;
23522352 },
......@@ -2377,7 +2377,7 @@ pub const Value = extern union {
23772377 .data = a,
23782378 };
23792379 const sub_val = Value.initPayload(&sub_pl.base);
2380 return eqlAdvanced(sub_val, ty, b, ty, mod, sema_kit);
2380 return eqlAdvanced(sub_val, ty, b, ty, mod, opt_sema);
23812381 },
23822382 .ErrorUnion => if (a_tag != .@"error" and b_tag == .eu_payload) {
23832383 var sub_pl: Payload.SubValue = .{
......@@ -2385,12 +2385,12 @@ pub const Value = extern union {
23852385 .data = a,
23862386 };
23872387 const sub_val = Value.initPayload(&sub_pl.base);
2388 return eqlAdvanced(sub_val, ty, b, ty, mod, sema_kit);
2388 return eqlAdvanced(sub_val, ty, b, ty, mod, opt_sema);
23892389 },
23902390 else => {},
23912391 }
23922392 if (a_tag == .null_value or a_tag == .@"error") return false;
2393 return (try orderAdvanced(a, b, target, sema_kit)).compare(.eq);
2393 return (try orderAdvanced(a, b, target, opt_sema)).compare(.eq);
23942394 }
23952395
23962396 /// This function is used by hash maps and so treats floating-point NaNs as equal
......@@ -3161,18 +3161,18 @@ pub const Value = extern union {
31613161 };
31623162 }
31633163
3164 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, target: Target, sema_kit: ?Module.WipAnalysis) !Value {
3164 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, target: Target, opt_sema: ?*Sema) !Value {
31653165 if (int_ty.zigTypeTag() == .Vector) {
31663166 const result_data = try arena.alloc(Value, int_ty.vectorLen());
31673167 for (result_data) |*scalar, i| {
3168 scalar.* = try intToFloatScalar(val.indexVectorlike(i), arena, float_ty.scalarType(), target, sema_kit);
3168 scalar.* = try intToFloatScalar(val.indexVectorlike(i), arena, float_ty.scalarType(), target, opt_sema);
31693169 }
31703170 return Value.Tag.aggregate.create(arena, result_data);
31713171 }
3172 return intToFloatScalar(val, arena, float_ty, target, sema_kit);
3172 return intToFloatScalar(val, arena, float_ty, target, opt_sema);
31733173 }
31743174
3175 pub fn intToFloatScalar(val: Value, arena: Allocator, float_ty: Type, target: Target, sema_kit: ?Module.WipAnalysis) !Value {
3175 pub fn intToFloatScalar(val: Value, arena: Allocator, float_ty: Type, target: Target, opt_sema: ?*Sema) !Value {
31763176 switch (val.tag()) {
31773177 .undef, .zero, .one => return val,
31783178 .the_only_possible_value => return Value.initTag(.zero), // for i0, u0
......@@ -3194,16 +3194,16 @@ pub const Value = extern union {
31943194 },
31953195 .lazy_align => {
31963196 const ty = val.castTag(.lazy_align).?.data;
3197 if (sema_kit) |sk| {
3198 return intToFloatInner((try ty.abiAlignmentAdvanced(target, .{ .sema_kit = sk })).scalar, arena, float_ty, target);
3197 if (opt_sema) |sema| {
3198 return intToFloatInner((try ty.abiAlignmentAdvanced(target, .{ .sema = sema })).scalar, arena, float_ty, target);
31993199 } else {
32003200 return intToFloatInner(ty.abiAlignment(target), arena, float_ty, target);
32013201 }
32023202 },
32033203 .lazy_size => {
32043204 const ty = val.castTag(.lazy_size).?.data;
3205 if (sema_kit) |sk| {
3206 return intToFloatInner((try ty.abiSizeAdvanced(target, .{ .sema_kit = sk })).scalar, arena, float_ty, target);
3205 if (opt_sema) |sema| {
3206 return intToFloatInner((try ty.abiSizeAdvanced(target, .{ .sema = sema })).scalar, arena, float_ty, target);
32073207 } else {
32083208 return intToFloatInner(ty.abiSize(target), arena, float_ty, target);
32093209 }