authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-11 03:14:12-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-08-25 15:16:42-07:00
logb4bb64ce78bf2dee9437f366a362ef4d8c77b204
tree218658e59522e59a432b6e9adea9f1993c0fb51d
parent849c31a6cc3d1e554f97c2ccf7aaa886070cfadd
signaturelock-open Commit is signed but in an unrecognized format.

sema: rework type resolution to use Zcu when possible


32 files changed, 7330 insertions(+), 7120 deletions(-)

src/InternPool.zig+2-2
......@@ -3483,7 +3483,7 @@ pub const LoadedStructType = struct {
34833483 return s.field_aligns.get(ip)[i];
34843484 }
34853485
3486 pub fn fieldInit(s: LoadedStructType, ip: *InternPool, i: usize) Index {
3486 pub fn fieldInit(s: LoadedStructType, ip: *const InternPool, i: usize) Index {
34873487 if (s.field_inits.len == 0) return .none;
34883488 assert(s.haveFieldInits(ip));
34893489 return s.field_inits.get(ip)[i];
......@@ -11066,7 +11066,7 @@ pub fn destroyNamespace(
1106611066 local.mutate.namespaces.free_list = @intFromEnum(namespace_index);
1106711067}
1106811068
11069pub fn filePtr(ip: *InternPool, file_index: FileIndex) *Zcu.File {
11069pub fn filePtr(ip: *const InternPool, file_index: FileIndex) *Zcu.File {
1107011070 const file_index_unwrapped = file_index.unwrap(ip);
1107111071 const files = ip.getLocalShared(file_index_unwrapped.tid).files.acquire();
1107211072 return files.view().items(.file)[file_index_unwrapped.index];
src/RangeSet.zig+15-15
......@@ -9,7 +9,7 @@ const Zcu = @import("Zcu.zig");
99const RangeSet = @This();
1010const LazySrcLoc = Zcu.LazySrcLoc;
1111
12pt: Zcu.PerThread,
12zcu: *Zcu,
1313ranges: std.ArrayList(Range),
1414
1515pub const Range = struct {
......@@ -18,9 +18,9 @@ pub const Range = struct {
1818 src: LazySrcLoc,
1919};
2020
21pub fn init(allocator: std.mem.Allocator, pt: Zcu.PerThread) RangeSet {
21pub fn init(allocator: std.mem.Allocator, zcu: *Zcu) RangeSet {
2222 return .{
23 .pt = pt,
23 .zcu = zcu,
2424 .ranges = std.ArrayList(Range).init(allocator),
2525 };
2626}
......@@ -35,8 +35,8 @@ pub fn add(
3535 last: InternPool.Index,
3636 src: LazySrcLoc,
3737) !?LazySrcLoc {
38 const pt = self.pt;
39 const ip = &pt.zcu.intern_pool;
38 const zcu = self.zcu;
39 const ip = &zcu.intern_pool;
4040
4141 const ty = ip.typeOf(first);
4242 assert(ty == ip.typeOf(last));
......@@ -45,8 +45,8 @@ pub fn add(
4545 assert(ty == ip.typeOf(range.first));
4646 assert(ty == ip.typeOf(range.last));
4747
48 if (Value.fromInterned(last).compareScalar(.gte, Value.fromInterned(range.first), Type.fromInterned(ty), pt) and
49 Value.fromInterned(first).compareScalar(.lte, Value.fromInterned(range.last), Type.fromInterned(ty), pt))
48 if (Value.fromInterned(last).compareScalar(.gte, Value.fromInterned(range.first), Type.fromInterned(ty), zcu) and
49 Value.fromInterned(first).compareScalar(.lte, Value.fromInterned(range.last), Type.fromInterned(ty), zcu))
5050 {
5151 return range.src; // They overlap.
5252 }
......@@ -61,20 +61,20 @@ pub fn add(
6161}
6262
6363/// Assumes a and b do not overlap
64fn lessThan(pt: Zcu.PerThread, a: Range, b: Range) bool {
65 const ty = Type.fromInterned(pt.zcu.intern_pool.typeOf(a.first));
66 return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, pt);
64fn lessThan(zcu: *Zcu, a: Range, b: Range) bool {
65 const ty = Type.fromInterned(zcu.intern_pool.typeOf(a.first));
66 return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, zcu);
6767}
6868
6969pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !bool {
70 const pt = self.pt;
71 const ip = &pt.zcu.intern_pool;
70 const zcu = self.zcu;
71 const ip = &zcu.intern_pool;
7272 assert(ip.typeOf(first) == ip.typeOf(last));
7373
7474 if (self.ranges.items.len == 0)
7575 return false;
7676
77 std.mem.sort(Range, self.ranges.items, pt, lessThan);
77 std.mem.sort(Range, self.ranges.items, zcu, lessThan);
7878
7979 if (self.ranges.items[0].first != first or
8080 self.ranges.items[self.ranges.items.len - 1].last != last)
......@@ -93,10 +93,10 @@ pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !
9393 const prev = self.ranges.items[i];
9494
9595 // prev.last + 1 == cur.first
96 try counter.copy(Value.fromInterned(prev.last).toBigInt(&space, pt));
96 try counter.copy(Value.fromInterned(prev.last).toBigInt(&space, zcu));
9797 try counter.addScalar(&counter, 1);
9898
99 const cur_start_int = Value.fromInterned(cur.first).toBigInt(&space, pt);
99 const cur_start_int = Value.fromInterned(cur.first).toBigInt(&space, zcu);
100100 if (!cur_start_int.eql(counter.toConst())) {
101101 return false;
102102 }
src/Sema.zig+2143-2144
......@@ -6,7 +6,7 @@
66//! This is the the heart of the Zig compiler.
77
88pt: Zcu.PerThread,
9/// Alias to `mod.gpa`.
9/// Alias to `zcu.gpa`.
1010gpa: Allocator,
1111/// Points to the temporary arena allocator of the Sema.
1212/// This arena will be cleared when the sema is destroyed.
......@@ -67,7 +67,7 @@ generic_call_src: LazySrcLoc = LazySrcLoc.unneeded,
6767/// breaking from a block.
6868post_hoc_blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, *LabeledBlock) = .{},
6969/// Populated with the last compile error created.
70err: ?*Module.ErrorMsg = null,
70err: ?*Zcu.ErrorMsg = null,
7171/// Set to true when analyzing a func type instruction so that nested generic
7272/// function types will emit generic poison instead of a partial type.
7373no_partial_func_ty: bool = false,
......@@ -172,11 +172,10 @@ const Type = @import("Type.zig");
172172const Air = @import("Air.zig");
173173const Zir = std.zig.Zir;
174174const Zcu = @import("Zcu.zig");
175const Module = Zcu;
176175const trace = @import("tracy.zig").trace;
177const Namespace = Module.Namespace;
178const CompileError = Module.CompileError;
179const SemaError = Module.SemaError;
176const Namespace = Zcu.Namespace;
177const CompileError = Zcu.CompileError;
178const SemaError = Zcu.SemaError;
180179const LazySrcLoc = Zcu.LazySrcLoc;
181180const RangeSet = @import("RangeSet.zig");
182181const target_util = @import("target.zig");
......@@ -431,7 +430,7 @@ pub const Block = struct {
431430 return_ty: Type,
432431 },
433432
434 fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Module.ErrorMsg) !void {
433 fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Zcu.ErrorMsg) !void {
435434 const parent = msg orelse return;
436435 const pt = sema.pt;
437436 const prefix = "expression is evaluated at comptime because ";
......@@ -733,12 +732,12 @@ pub const Block = struct {
733732 fn addCmpVector(block: *Block, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref, cmp_op: std.math.CompareOperator) !Air.Inst.Ref {
734733 const sema = block.sema;
735734 const pt = sema.pt;
736 const mod = pt.zcu;
735 const zcu = pt.zcu;
737736 return block.addInst(.{
738737 .tag = if (block.float_mode == .optimized) .cmp_vector_optimized else .cmp_vector,
739738 .data = .{ .ty_pl = .{
740739 .ty = Air.internedToRef((try pt.vectorType(.{
741 .len = sema.typeOf(lhs).vectorLen(mod),
740 .len = sema.typeOf(lhs).vectorLen(zcu),
742741 .child = .bool_type,
743742 })).toIntern()),
744743 .payload = try sema.addExtra(Air.VectorCmp{
......@@ -852,7 +851,7 @@ const LabeledBlock = struct {
852851/// The value stored in the inferred allocation. This will go into
853852/// peer type resolution. This is stored in a separate list so that
854853/// the items are contiguous in memory and thus can be passed to
855/// `Module.resolvePeerTypes`.
854/// `Zcu.resolvePeerTypes`.
856855const InferredAlloc = struct {
857856 /// The placeholder `store` instructions used before the result pointer type
858857 /// is known. These should be rewritten to perform any required coercions
......@@ -1950,7 +1949,7 @@ fn resolveDestType(
19501949 builtin_name: []const u8,
19511950) !Type {
19521951 const pt = sema.pt;
1953 const mod = pt.zcu;
1952 const zcu = pt.zcu;
19541953 const remove_eu = switch (strat) {
19551954 .remove_eu_opt, .remove_eu => true,
19561955 .remove_opt => false,
......@@ -1980,15 +1979,15 @@ fn resolveDestType(
19801979 else => |e| return e,
19811980 };
19821981
1983 if (remove_eu and raw_ty.zigTypeTag(mod) == .ErrorUnion) {
1984 const eu_child = raw_ty.errorUnionPayload(mod);
1985 if (remove_opt and eu_child.zigTypeTag(mod) == .Optional) {
1986 return eu_child.childType(mod);
1982 if (remove_eu and raw_ty.zigTypeTag(zcu) == .ErrorUnion) {
1983 const eu_child = raw_ty.errorUnionPayload(zcu);
1984 if (remove_opt and eu_child.zigTypeTag(zcu) == .Optional) {
1985 return eu_child.childType(zcu);
19871986 }
19881987 return eu_child;
19891988 }
1990 if (remove_opt and raw_ty.zigTypeTag(mod) == .Optional) {
1991 return raw_ty.childType(mod);
1989 if (remove_opt and raw_ty.zigTypeTag(zcu) == .Optional) {
1990 return raw_ty.childType(zcu);
19921991 }
19931992 return raw_ty;
19941993}
......@@ -2068,10 +2067,10 @@ fn analyzeAsType(
20682067
20692068pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void {
20702069 const pt = sema.pt;
2071 const mod = pt.zcu;
2072 const comp = mod.comp;
2070 const zcu = pt.zcu;
2071 const comp = zcu.comp;
20732072 const gpa = sema.gpa;
2074 const ip = &mod.intern_pool;
2073 const ip = &zcu.intern_pool;
20752074 if (!comp.config.any_error_tracing) return;
20762075
20772076 assert(!block.is_comptime);
......@@ -2140,9 +2139,9 @@ fn resolveDefinedValue(
21402139 air_ref: Air.Inst.Ref,
21412140) CompileError!?Value {
21422141 const pt = sema.pt;
2143 const mod = pt.zcu;
2142 const zcu = pt.zcu;
21442143 const val = try sema.resolveValue(air_ref) orelse return null;
2145 if (val.isUndef(mod)) {
2144 if (val.isUndef(zcu)) {
21462145 return sema.failWithUseOfUndef(block, src);
21472146 }
21482147 return val;
......@@ -2340,12 +2339,12 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
23402339
23412340fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {
23422341 const pt = sema.pt;
2343 const mod = pt.zcu;
2342 const zcu = pt.zcu;
23442343 const msg = msg: {
23452344 const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{});
23462345 errdefer msg.destroy(sema.gpa);
23472346
2348 const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg;
2347 const struct_type = zcu.typeToStruct(container_ty) orelse break :msg msg;
23492348 try sema.errNote(.{
23502349 .base_node_inst = struct_type.zir_index.unwrap().?,
23512350 .offset = .{ .container_field_value = @intCast(field_index) },
......@@ -2372,12 +2371,12 @@ fn failWithInvalidFieldAccess(
23722371 field_name: InternPool.NullTerminatedString,
23732372) CompileError {
23742373 const pt = sema.pt;
2375 const mod = pt.zcu;
2376 const inner_ty = if (object_ty.isSinglePointer(mod)) object_ty.childType(mod) else object_ty;
2374 const zcu = pt.zcu;
2375 const inner_ty = if (object_ty.isSinglePointer(zcu)) object_ty.childType(zcu) else object_ty;
23772376
2378 if (inner_ty.zigTypeTag(mod) == .Optional) opt: {
2379 const child_ty = inner_ty.optionalChild(mod);
2380 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;
2377 if (inner_ty.zigTypeTag(zcu) == .Optional) opt: {
2378 const child_ty = inner_ty.optionalChild(zcu);
2379 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :opt;
23812380 const msg = msg: {
23822381 const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(pt)});
23832382 errdefer msg.destroy(sema.gpa);
......@@ -2385,9 +2384,9 @@ fn failWithInvalidFieldAccess(
23852384 break :msg msg;
23862385 };
23872386 return sema.failWithOwnedErrorMsg(block, msg);
2388 } else if (inner_ty.zigTypeTag(mod) == .ErrorUnion) err: {
2389 const child_ty = inner_ty.errorUnionPayload(mod);
2390 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;
2387 } else if (inner_ty.zigTypeTag(zcu) == .ErrorUnion) err: {
2388 const child_ty = inner_ty.errorUnionPayload(zcu);
2389 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :err;
23912390 const msg = msg: {
23922391 const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(pt)});
23932392 errdefer msg.destroy(sema.gpa);
......@@ -2399,15 +2398,15 @@ fn failWithInvalidFieldAccess(
23992398 return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(pt)});
24002399}
24012400
2402fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.NullTerminatedString) bool {
2403 const ip = &mod.intern_pool;
2404 switch (ty.zigTypeTag(mod)) {
2401fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.NullTerminatedString) bool {
2402 const ip = &zcu.intern_pool;
2403 switch (ty.zigTypeTag(zcu)) {
24052404 .Array => return field_name.eqlSlice("len", ip),
24062405 .Pointer => {
2407 const ptr_info = ty.ptrInfo(mod);
2406 const ptr_info = ty.ptrInfo(zcu);
24082407 if (ptr_info.flags.size == .Slice) {
24092408 return field_name.eqlSlice("ptr", ip) or field_name.eqlSlice("len", ip);
2410 } else if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
2409 } else if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Array) {
24112410 return field_name.eqlSlice("len", ip);
24122411 } else return false;
24132412 },
......@@ -2423,9 +2422,9 @@ fn failWithComptimeErrorRetTrace(
24232422 name: InternPool.NullTerminatedString,
24242423) CompileError {
24252424 const pt = sema.pt;
2426 const mod = pt.zcu;
2425 const zcu = pt.zcu;
24272426 const msg = msg: {
2428 const msg = try sema.errMsg(src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
2427 const msg = try sema.errMsg(src, "caught unexpected error '{}'", .{name.fmt(&zcu.intern_pool)});
24292428 errdefer msg.destroy(sema.gpa);
24302429
24312430 for (sema.comptime_err_ret_trace.items) |src_loc| {
......@@ -2451,7 +2450,7 @@ fn failWithInvalidPtrArithmetic(sema: *Sema, block: *Block, src: LazySrcLoc, ari
24512450pub fn errNote(
24522451 sema: *Sema,
24532452 src: LazySrcLoc,
2454 parent: *Module.ErrorMsg,
2453 parent: *Zcu.ErrorMsg,
24552454 comptime format: []const u8,
24562455 args: anytype,
24572456) error{OutOfMemory}!void {
......@@ -2462,7 +2461,7 @@ fn addFieldErrNote(
24622461 sema: *Sema,
24632462 container_ty: Type,
24642463 field_index: usize,
2465 parent: *Module.ErrorMsg,
2464 parent: *Zcu.ErrorMsg,
24662465 comptime format: []const u8,
24672466 args: anytype,
24682467) !void {
......@@ -2480,9 +2479,9 @@ pub fn errMsg(
24802479 src: LazySrcLoc,
24812480 comptime format: []const u8,
24822481 args: anytype,
2483) Allocator.Error!*Module.ErrorMsg {
2482) Allocator.Error!*Zcu.ErrorMsg {
24842483 assert(src.offset != .unneeded);
2485 return Module.ErrorMsg.create(sema.gpa, src, format, args);
2484 return Zcu.ErrorMsg.create(sema.gpa, src, format, args);
24862485}
24872486
24882487pub fn fail(
......@@ -2501,16 +2500,16 @@ pub fn fail(
25012500 return sema.failWithOwnedErrorMsg(block, err_msg);
25022501}
25032502
2504pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg) error{ AnalysisFail, OutOfMemory } {
2503pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg) error{ AnalysisFail, OutOfMemory } {
25052504 @setCold(true);
25062505 const gpa = sema.gpa;
2507 const mod = sema.pt.zcu;
2506 const zcu = sema.pt.zcu;
25082507
2509 if (build_options.enable_debug_extensions and mod.comp.debug_compile_errors) {
2508 if (build_options.enable_debug_extensions and zcu.comp.debug_compile_errors) {
25102509 var all_references: ?std.AutoHashMapUnmanaged(AnalUnit, ?Zcu.ResolvedReference) = null;
25112510 var wip_errors: std.zig.ErrorBundle.Wip = undefined;
25122511 wip_errors.init(gpa) catch @panic("out of memory");
2513 Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*, &all_references) catch @panic("out of memory");
2512 Compilation.addModuleErrorMsg(zcu, &wip_errors, err_msg.*, &all_references) catch @panic("out of memory");
25142513 std.debug.print("compile error during Sema:\n", .{});
25152514 var error_bundle = wip_errors.toOwnedBundle("") catch @panic("out of memory");
25162515 error_bundle.renderToStdErr(.{ .ttyconf = .no_color });
......@@ -2530,12 +2529,12 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25302529 }
25312530 }
25322531
2533 const use_ref_trace = if (mod.comp.reference_trace) |n| n > 0 else mod.failed_analysis.count() == 0;
2532 const use_ref_trace = if (zcu.comp.reference_trace) |n| n > 0 else zcu.failed_analysis.count() == 0;
25342533 if (use_ref_trace) {
25352534 err_msg.reference_trace_root = sema.owner.toOptional();
25362535 }
25372536
2538 const gop = try mod.failed_analysis.getOrPut(gpa, sema.owner);
2537 const gop = try zcu.failed_analysis.getOrPut(gpa, sema.owner);
25392538 if (gop.found_existing) {
25402539 // If there are multiple errors for the same Decl, prefer the first one added.
25412540 sema.err = null;
......@@ -2554,7 +2553,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25542553fn reparentOwnedErrorMsg(
25552554 sema: *Sema,
25562555 src: LazySrcLoc,
2557 msg: *Module.ErrorMsg,
2556 msg: *Zcu.ErrorMsg,
25582557 comptime format: []const u8,
25592558 args: anytype,
25602559) !void {
......@@ -2562,7 +2561,7 @@ fn reparentOwnedErrorMsg(
25622561
25632562 const orig_notes = msg.notes.len;
25642563 msg.notes = try sema.gpa.realloc(msg.notes, orig_notes + 1);
2565 std.mem.copyBackwards(Module.ErrorMsg, msg.notes[1..], msg.notes[0..orig_notes]);
2564 std.mem.copyBackwards(Zcu.ErrorMsg, msg.notes[1..], msg.notes[0..orig_notes]);
25662565 msg.notes[0] = .{
25672566 .src_loc = msg.src_loc,
25682567 .msg = msg.msg,
......@@ -2644,7 +2643,7 @@ fn analyzeAsInt(
26442643) !u64 {
26452644 const coerced = try sema.coerce(block, dest_ty, air_ref, src);
26462645 const val = try sema.resolveConstDefinedValue(block, src, coerced, reason);
2647 return (try val.getUnsignedIntAdvanced(sema.pt, .sema)).?;
2646 return try val.toUnsignedIntSema(sema.pt);
26482647}
26492648
26502649/// Given a ZIR extra index which points to a list of `Zir.Inst.Capture`,
......@@ -2722,9 +2721,9 @@ fn zirStructDecl(
27222721 inst: Zir.Inst.Index,
27232722) CompileError!Air.Inst.Ref {
27242723 const pt = sema.pt;
2725 const mod = pt.zcu;
2724 const zcu = pt.zcu;
27262725 const gpa = sema.gpa;
2727 const ip = &mod.intern_pool;
2726 const ip = &zcu.intern_pool;
27282727 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
27292728 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);
27302729
......@@ -2786,7 +2785,7 @@ fn zirStructDecl(
27862785
27872786 // Make sure we update the namespace if the declaration is re-analyzed, to pick
27882787 // up on e.g. changed comptime decls.
2789 try pt.ensureNamespaceUpToDate(Type.fromInterned(new_ty).getNamespaceIndex(mod));
2788 try pt.ensureNamespaceUpToDate(Type.fromInterned(new_ty).getNamespaceIndex(zcu));
27902789
27912790 try sema.declareDependency(.{ .interned = new_ty });
27922791 try sema.addTypeReferenceEntry(src, new_ty);
......@@ -2807,8 +2806,8 @@ fn zirStructDecl(
28072806 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
28082807 .parent = block.namespace.toOptional(),
28092808 .owner_type = wip_ty.index,
2810 .file_scope = block.getFileScopeIndex(mod),
2811 .generation = mod.generation,
2809 .file_scope = block.getFileScopeIndex(zcu),
2810 .generation = zcu.generation,
28122811 });
28132812 errdefer pt.destroyNamespace(new_namespace_index);
28142813
......@@ -2825,11 +2824,11 @@ fn zirStructDecl(
28252824 const decls = sema.code.bodySlice(extra_index, decls_len);
28262825 try pt.scanNamespace(new_namespace_index, decls);
28272826
2828 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
2827 try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
28292828 codegen_type: {
2830 if (mod.comp.config.use_llvm) break :codegen_type;
2829 if (zcu.comp.config.use_llvm) break :codegen_type;
28312830 if (block.ownerModule().strip) break :codegen_type;
2832 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
2831 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
28332832 }
28342833 try sema.declareDependency(.{ .interned = wip_ty.index });
28352834 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -2938,9 +2937,9 @@ fn zirEnumDecl(
29382937 defer tracy.end();
29392938
29402939 const pt = sema.pt;
2941 const mod = pt.zcu;
2940 const zcu = pt.zcu;
29422941 const gpa = sema.gpa;
2943 const ip = &mod.intern_pool;
2942 const ip = &zcu.intern_pool;
29442943 const small: Zir.Inst.EnumDecl.Small = @bitCast(extended.small);
29452944 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);
29462945 var extra_index: usize = extra.end;
......@@ -3015,7 +3014,7 @@ fn zirEnumDecl(
30153014
30163015 // Make sure we update the namespace if the declaration is re-analyzed, to pick
30173016 // up on e.g. changed comptime decls.
3018 try pt.ensureNamespaceUpToDate(Type.fromInterned(new_ty).getNamespaceIndex(mod));
3017 try pt.ensureNamespaceUpToDate(Type.fromInterned(new_ty).getNamespaceIndex(zcu));
30193018
30203019 try sema.declareDependency(.{ .interned = new_ty });
30213020 try sema.addTypeReferenceEntry(src, new_ty);
......@@ -3042,8 +3041,8 @@ fn zirEnumDecl(
30423041 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
30433042 .parent = block.namespace.toOptional(),
30443043 .owner_type = wip_ty.index,
3045 .file_scope = block.getFileScopeIndex(mod),
3046 .generation = mod.generation,
3044 .file_scope = block.getFileScopeIndex(zcu),
3045 .generation = zcu.generation,
30473046 });
30483047 errdefer if (!done) pt.destroyNamespace(new_namespace_index);
30493048
......@@ -3077,9 +3076,9 @@ fn zirEnumDecl(
30773076 );
30783077
30793078 codegen_type: {
3080 if (mod.comp.config.use_llvm) break :codegen_type;
3079 if (zcu.comp.config.use_llvm) break :codegen_type;
30813080 if (block.ownerModule().strip) break :codegen_type;
3082 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
3081 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
30833082 }
30843083 return Air.internedToRef(wip_ty.index);
30853084}
......@@ -3094,9 +3093,9 @@ fn zirUnionDecl(
30943093 defer tracy.end();
30953094
30963095 const pt = sema.pt;
3097 const mod = pt.zcu;
3096 const zcu = pt.zcu;
30983097 const gpa = sema.gpa;
3099 const ip = &mod.intern_pool;
3098 const ip = &zcu.intern_pool;
31003099 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
31013100 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);
31023101 var extra_index: usize = extra.end;
......@@ -3159,7 +3158,7 @@ fn zirUnionDecl(
31593158
31603159 // Make sure we update the namespace if the declaration is re-analyzed, to pick
31613160 // up on e.g. changed comptime decls.
3162 try pt.ensureNamespaceUpToDate(Type.fromInterned(new_ty).getNamespaceIndex(mod));
3161 try pt.ensureNamespaceUpToDate(Type.fromInterned(new_ty).getNamespaceIndex(zcu));
31633162
31643163 try sema.declareDependency(.{ .interned = new_ty });
31653164 try sema.addTypeReferenceEntry(src, new_ty);
......@@ -3180,15 +3179,15 @@ fn zirUnionDecl(
31803179 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
31813180 .parent = block.namespace.toOptional(),
31823181 .owner_type = wip_ty.index,
3183 .file_scope = block.getFileScopeIndex(mod),
3184 .generation = mod.generation,
3182 .file_scope = block.getFileScopeIndex(zcu),
3183 .generation = zcu.generation,
31853184 });
31863185 errdefer pt.destroyNamespace(new_namespace_index);
31873186
31883187 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
31893188
31903189 if (pt.zcu.comp.incremental) {
3191 try mod.intern_pool.addDependency(
3190 try zcu.intern_pool.addDependency(
31923191 gpa,
31933192 AnalUnit.wrap(.{ .cau = new_cau_index }),
31943193 .{ .src_hash = tracked_inst },
......@@ -3198,11 +3197,11 @@ fn zirUnionDecl(
31983197 const decls = sema.code.bodySlice(extra_index, decls_len);
31993198 try pt.scanNamespace(new_namespace_index, decls);
32003199
3201 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
3200 try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
32023201 codegen_type: {
3203 if (mod.comp.config.use_llvm) break :codegen_type;
3202 if (zcu.comp.config.use_llvm) break :codegen_type;
32043203 if (block.ownerModule().strip) break :codegen_type;
3205 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
3204 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
32063205 }
32073206 try sema.declareDependency(.{ .interned = wip_ty.index });
32083207 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -3219,9 +3218,9 @@ fn zirOpaqueDecl(
32193218 defer tracy.end();
32203219
32213220 const pt = sema.pt;
3222 const mod = pt.zcu;
3221 const zcu = pt.zcu;
32233222 const gpa = sema.gpa;
3224 const ip = &mod.intern_pool;
3223 const ip = &zcu.intern_pool;
32253224
32263225 const small: Zir.Inst.OpaqueDecl.Small = @bitCast(extended.small);
32273226 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
......@@ -3255,7 +3254,7 @@ fn zirOpaqueDecl(
32553254 .existing => |ty| {
32563255 // Make sure we update the namespace if the declaration is re-analyzed, to pick
32573256 // up on e.g. changed comptime decls.
3258 try pt.ensureNamespaceUpToDate(Type.fromInterned(ty).getNamespaceIndex(mod));
3257 try pt.ensureNamespaceUpToDate(Type.fromInterned(ty).getNamespaceIndex(zcu));
32593258
32603259 try sema.declareDependency(.{ .interned = ty });
32613260 try sema.addTypeReferenceEntry(src, ty);
......@@ -3276,8 +3275,8 @@ fn zirOpaqueDecl(
32763275 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
32773276 .parent = block.namespace.toOptional(),
32783277 .owner_type = wip_ty.index,
3279 .file_scope = block.getFileScopeIndex(mod),
3280 .generation = mod.generation,
3278 .file_scope = block.getFileScopeIndex(zcu),
3279 .generation = zcu.generation,
32813280 });
32823281 errdefer pt.destroyNamespace(new_namespace_index);
32833282
......@@ -3285,9 +3284,9 @@ fn zirOpaqueDecl(
32853284 try pt.scanNamespace(new_namespace_index, decls);
32863285
32873286 codegen_type: {
3288 if (mod.comp.config.use_llvm) break :codegen_type;
3287 if (zcu.comp.config.use_llvm) break :codegen_type;
32893288 if (block.ownerModule().strip) break :codegen_type;
3290 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
3289 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
32913290 }
32923291 try sema.addTypeReferenceEntry(src, wip_ty.index);
32933292 return Air.internedToRef(wip_ty.finish(ip, .none, new_namespace_index));
......@@ -3301,7 +3300,7 @@ fn zirErrorSetDecl(
33013300 defer tracy.end();
33023301
33033302 const pt = sema.pt;
3304 const mod = pt.zcu;
3303 const zcu = pt.zcu;
33053304 const gpa = sema.gpa;
33063305 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
33073306 const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);
......@@ -3314,7 +3313,7 @@ fn zirErrorSetDecl(
33143313 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
33153314 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);
33163315 const name = sema.code.nullTerminatedString(name_index);
3317 const name_ip = try mod.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
3316 const name_ip = try zcu.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
33183317 _ = try pt.getErrorValue(name_ip);
33193318 const result = names.getOrPutAssumeCapacity(name_ip);
33203319 assert(!result.found_existing); // verified in AstGen
......@@ -3329,7 +3328,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
33293328
33303329 const pt = sema.pt;
33313330
3332 if (block.is_comptime or try sema.typeRequiresComptime(sema.fn_ret_ty)) {
3331 if (block.is_comptime or try sema.fn_ret_ty.comptimeOnlySema(pt)) {
33333332 try sema.fn_ret_ty.resolveFields(pt);
33343333 return sema.analyzeComptimeAlloc(block, sema.fn_ret_ty, .none);
33353334 }
......@@ -3377,8 +3376,8 @@ fn ensureResultUsed(
33773376 src: LazySrcLoc,
33783377) CompileError!void {
33793378 const pt = sema.pt;
3380 const mod = pt.zcu;
3381 switch (ty.zigTypeTag(mod)) {
3379 const zcu = pt.zcu;
3380 switch (ty.zigTypeTag(zcu)) {
33823381 .Void, .NoReturn => return,
33833382 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),
33843383 .ErrorUnion => {
......@@ -3408,12 +3407,12 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
34083407 defer tracy.end();
34093408
34103409 const pt = sema.pt;
3411 const mod = pt.zcu;
3410 const zcu = pt.zcu;
34123411 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
34133412 const operand = try sema.resolveInst(inst_data.operand);
34143413 const src = block.nodeOffset(inst_data.src_node);
34153414 const operand_ty = sema.typeOf(operand);
3416 switch (operand_ty.zigTypeTag(mod)) {
3415 switch (operand_ty.zigTypeTag(zcu)) {
34173416 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),
34183417 .ErrorUnion => {
34193418 const msg = msg: {
......@@ -3433,17 +3432,17 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
34333432 defer tracy.end();
34343433
34353434 const pt = sema.pt;
3436 const mod = pt.zcu;
3435 const zcu = pt.zcu;
34373436 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
34383437 const src = block.nodeOffset(inst_data.src_node);
34393438 const operand = try sema.resolveInst(inst_data.operand);
34403439 const operand_ty = sema.typeOf(operand);
3441 const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer)
3442 operand_ty.childType(mod)
3440 const err_union_ty = if (operand_ty.zigTypeTag(zcu) == .Pointer)
3441 operand_ty.childType(zcu)
34433442 else
34443443 operand_ty;
3445 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) return;
3446 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);
3444 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) return;
3445 const payload_ty = err_union_ty.errorUnionPayload(zcu).zigTypeTag(zcu);
34473446 if (payload_ty != .Void and payload_ty != .NoReturn) {
34483447 const msg = msg: {
34493448 const msg = try sema.errMsg(src, "error union payload is ignored", .{});
......@@ -3473,12 +3472,12 @@ fn indexablePtrLen(
34733472 object: Air.Inst.Ref,
34743473) CompileError!Air.Inst.Ref {
34753474 const pt = sema.pt;
3476 const mod = pt.zcu;
3475 const zcu = pt.zcu;
34773476 const object_ty = sema.typeOf(object);
3478 const is_pointer_to = object_ty.isSinglePointer(mod);
3479 const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty;
3477 const is_pointer_to = object_ty.isSinglePointer(zcu);
3478 const indexable_ty = if (is_pointer_to) object_ty.childType(zcu) else object_ty;
34803479 try checkIndexable(sema, block, src, indexable_ty);
3481 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);
3480 const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);
34823481 return sema.fieldVal(block, src, object, field_name, src);
34833482}
34843483
......@@ -3489,11 +3488,11 @@ fn indexablePtrLenOrNone(
34893488 operand: Air.Inst.Ref,
34903489) CompileError!Air.Inst.Ref {
34913490 const pt = sema.pt;
3492 const mod = pt.zcu;
3491 const zcu = pt.zcu;
34933492 const operand_ty = sema.typeOf(operand);
34943493 try checkMemOperand(sema, block, src, operand_ty);
3495 if (operand_ty.ptrSize(mod) == .Many) return .none;
3496 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);
3494 if (operand_ty.ptrSize(zcu) == .Many) return .none;
3495 const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);
34973496 return sema.fieldVal(block, src, operand, field_name, src);
34983497}
34993498
......@@ -3592,11 +3591,11 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
35923591
35933592fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
35943593 const pt = sema.pt;
3595 const mod = pt.zcu;
3594 const zcu = pt.zcu;
35963595 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
35973596 const alloc = try sema.resolveInst(inst_data.operand);
35983597 const alloc_ty = sema.typeOf(alloc);
3599 const ptr_info = alloc_ty.ptrInfo(mod);
3598 const ptr_info = alloc_ty.ptrInfo(zcu);
36003599 const elem_ty = Type.fromInterned(ptr_info.child);
36013600
36023601 // If the alloc was created in a comptime scope, we already created a comptime alloc for it.
......@@ -3607,7 +3606,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36073606
36083607 // If this was a comptime inferred alloc, then `storeToInferredAllocComptime`
36093608 // might have already done our job and created an anon decl ref.
3610 switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) {
3609 switch (zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
36113610 .ptr => |ptr| switch (ptr.base_addr) {
36123611 .uav => {
36133612 // The comptime-ification was already done for us.
......@@ -3620,12 +3619,12 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36203619 }
36213620
36223621 if (!sema.isComptimeMutablePtr(ptr_val)) break :already_ct;
3623 const ptr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
3622 const ptr = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
36243623 assert(ptr.byte_offset == 0);
36253624 const alloc_index = ptr.base_addr.comptime_alloc;
36263625 const ct_alloc = sema.getComptimeAlloc(alloc_index);
36273626 const interned = try ct_alloc.val.intern(pt, sema.arena);
3628 if (interned.canMutateComptimeVarState(mod)) {
3627 if (interned.canMutateComptimeVarState(zcu)) {
36293628 // Preserve the comptime alloc, just make the pointer const.
36303629 ct_alloc.val = .{ .interned = interned.toIntern() };
36313630 ct_alloc.is_const = true;
......@@ -3649,7 +3648,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36493648 return sema.makePtrConst(block, Air.internedToRef(ptr_val));
36503649 }
36513650
3652 if (try sema.typeRequiresComptime(elem_ty)) {
3651 if (try elem_ty.comptimeOnlySema(pt)) {
36533652 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
36543653 // TODO: source location of runtime control flow
36553654 const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
......@@ -3918,7 +3917,7 @@ fn finishResolveComptimeKnownAllocPtr(
39183917
39193918 if (Value.fromInterned(result_val).canMutateComptimeVarState(zcu)) {
39203919 const alloc_index = existing_comptime_alloc orelse a: {
3921 const idx = try sema.newComptimeAlloc(block, alloc_ty.childType(zcu), alloc_ty.ptrAlignment(pt));
3920 const idx = try sema.newComptimeAlloc(block, alloc_ty.childType(zcu), alloc_ty.ptrAlignment(zcu));
39223921 const alloc = sema.getComptimeAlloc(idx);
39233922 alloc.val = .{ .interned = result_val };
39243923 break :a idx;
......@@ -4072,14 +4071,14 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40724071 defer tracy.end();
40734072
40744073 const pt = sema.pt;
4075 const mod = pt.zcu;
4074 const zcu = pt.zcu;
40764075 const gpa = sema.gpa;
40774076 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
40784077 const src = block.nodeOffset(inst_data.src_node);
40794078 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
40804079 const ptr = try sema.resolveInst(inst_data.operand);
40814080 const ptr_inst = ptr.toIndex().?;
4082 const target = mod.getTarget();
4081 const target = zcu.getTarget();
40834082
40844083 switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) {
40854084 .inferred_alloc_comptime => {
......@@ -4093,7 +4092,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
40934092 sema.air_instructions.set(@intFromEnum(ptr_inst), .{ .tag = undefined, .data = undefined });
40944093 }
40954094
4096 const val = switch (mod.intern_pool.indexToKey(resolved_ptr).ptr.base_addr) {
4095 const val = switch (zcu.intern_pool.indexToKey(resolved_ptr).ptr.base_addr) {
40974096 .uav => |a| a.val,
40984097 .comptime_alloc => |i| val: {
40994098 const alloc = sema.getComptimeAlloc(i);
......@@ -4101,11 +4100,11 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
41014100 },
41024101 else => unreachable,
41034102 };
4104 if (mod.intern_pool.isFuncBody(val)) {
4105 const ty = Type.fromInterned(mod.intern_pool.typeOf(val));
4106 if (try sema.fnHasRuntimeBits(ty)) {
4103 if (zcu.intern_pool.isFuncBody(val)) {
4104 const ty = Type.fromInterned(zcu.intern_pool.typeOf(val));
4105 if (try ty.fnHasRuntimeBitsSema(pt)) {
41074106 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .func = val }));
4108 try mod.ensureFuncBodyAnalysisQueued(val);
4107 try zcu.ensureFuncBodyAnalysisQueued(val);
41094108 }
41104109 }
41114110
......@@ -4148,7 +4147,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
41484147 return;
41494148 }
41504149
4151 if (try sema.typeRequiresComptime(final_elem_ty)) {
4150 if (try final_elem_ty.comptimeOnlySema(pt)) {
41524151 // The alloc wasn't comptime-known per the above logic, so the
41534152 // type cannot be comptime-only.
41544153 // TODO: source location of runtime control flow
......@@ -4213,9 +4212,9 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
42134212
42144213fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
42154214 const pt = sema.pt;
4216 const mod = pt.zcu;
4215 const zcu = pt.zcu;
42174216 const gpa = sema.gpa;
4218 const ip = &mod.intern_pool;
4217 const ip = &zcu.intern_pool;
42194218 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
42204219 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
42214220 const args = sema.code.refSlice(extra.end, extra.data.operands_len);
......@@ -4238,7 +4237,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
42384237 const object_ty = sema.typeOf(object);
42394238 // Each arg could be an indexable, or a range, in which case the length
42404239 // is passed directly as an integer.
4241 const is_int = switch (object_ty.zigTypeTag(mod)) {
4240 const is_int = switch (object_ty.zigTypeTag(zcu)) {
42424241 .Int, .ComptimeInt => true,
42434242 else => false,
42444243 };
......@@ -4247,14 +4246,14 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
42474246 .input_index = i,
42484247 } });
42494248 const arg_len_uncoerced = if (is_int) object else l: {
4250 if (!object_ty.isIndexable(mod)) {
4249 if (!object_ty.isIndexable(zcu)) {
42514250 // Instead of using checkIndexable we customize this error.
42524251 const msg = msg: {
42534252 const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(pt)});
42544253 errdefer msg.destroy(sema.gpa);
42554254 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
42564255
4257 if (object_ty.zigTypeTag(mod) == .ErrorUnion) {
4256 if (object_ty.zigTypeTag(zcu) == .ErrorUnion) {
42584257 try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});
42594258 }
42604259
......@@ -4262,7 +4261,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
42624261 };
42634262 return sema.failWithOwnedErrorMsg(block, msg);
42644263 }
4265 if (!object_ty.indexableHasLen(mod)) continue;
4264 if (!object_ty.indexableHasLen(zcu)) continue;
42664265
42674266 break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), arg_src);
42684267 };
......@@ -4313,7 +4312,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43134312 const object_ty = sema.typeOf(object);
43144313 // Each arg could be an indexable, or a range, in which case the length
43154314 // is passed directly as an integer.
4316 switch (object_ty.zigTypeTag(mod)) {
4315 switch (object_ty.zigTypeTag(zcu)) {
43174316 .Int, .ComptimeInt => continue,
43184317 else => {},
43194318 }
......@@ -4349,9 +4348,9 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43494348/// May invalidate already-stored payload data.
43504349fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcLoc) CompileError!Air.Inst.Ref {
43514350 const pt = sema.pt;
4352 const mod = pt.zcu;
4351 const zcu = pt.zcu;
43534352 var base_ptr = ptr;
4354 while (true) switch (sema.typeOf(base_ptr).childType(mod).zigTypeTag(mod)) {
4353 while (true) switch (sema.typeOf(base_ptr).childType(zcu).zigTypeTag(zcu)) {
43554354 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
43564355 .Optional => base_ptr = try sema.analyzeOptionalPayloadPtr(block, src, base_ptr, false, true),
43574356 else => break,
......@@ -4368,7 +4367,7 @@ fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
43684367
43694368fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
43704369 const pt = sema.pt;
4371 const mod = pt.zcu;
4370 const zcu = pt.zcu;
43724371 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
43734372 const src = block.nodeOffset(pl_node.src_node);
43744373 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
......@@ -4377,13 +4376,13 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
43774376 error.GenericPoison => return uncoerced_val,
43784377 else => |e| return e,
43794378 };
4380 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(mod);
4381 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction
4382 const elem_ty = ptr_ty.childType(mod);
4383 switch (ptr_ty.ptrSize(mod)) {
4379 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu);
4380 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
4381 const elem_ty = ptr_ty.childType(zcu);
4382 switch (ptr_ty.ptrSize(zcu)) {
43844383 .One => {
43854384 const uncoerced_ty = sema.typeOf(uncoerced_val);
4386 if (elem_ty.zigTypeTag(mod) == .Array and elem_ty.childType(mod).toIntern() == uncoerced_ty.toIntern()) {
4385 if (elem_ty.zigTypeTag(zcu) == .Array and elem_ty.childType(zcu).toIntern() == uncoerced_ty.toIntern()) {
43874386 // We're trying to initialize a *[1]T with a reference to a T - don't perform any coercion.
43884387 return uncoerced_val;
43894388 }
......@@ -4397,16 +4396,16 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
43974396 .Slice, .Many => {
43984397 // Our goal is to coerce `uncoerced_val` to an array of `elem_ty`.
43994398 const val_ty = sema.typeOf(uncoerced_val);
4400 switch (val_ty.zigTypeTag(mod)) {
4399 switch (val_ty.zigTypeTag(zcu)) {
44014400 .Array, .Vector => {},
4402 else => if (!val_ty.isTuple(mod)) {
4401 else => if (!val_ty.isTuple(zcu)) {
44034402 return sema.fail(block, src, "expected array of '{}', found '{}'", .{ elem_ty.fmt(pt), val_ty.fmt(pt) });
44044403 },
44054404 }
44064405 const want_ty = try pt.arrayType(.{
4407 .len = val_ty.arrayLen(mod),
4406 .len = val_ty.arrayLen(zcu),
44084407 .child = elem_ty.toIntern(),
4409 .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
4408 .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
44104409 });
44114410 return sema.coerce(block, want_ty, uncoerced_val, src);
44124411 },
......@@ -4420,7 +4419,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
44204419
44214420fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
44224421 const pt = sema.pt;
4423 const mod = pt.zcu;
4422 const zcu = pt.zcu;
44244423 const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
44254424 const src = block.tokenOffset(un_tok.src_tok);
44264425 // In case of GenericPoison, we don't actually have a type, so this will be
......@@ -4434,7 +4433,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
44344433 else => |e| return e,
44354434 };
44364435 if (ty_operand.isGenericPoison()) return;
4437 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {
4436 if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .Pointer) {
44384437 return sema.failWithOwnedErrorMsg(block, msg: {
44394438 const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(pt)});
44404439 errdefer msg.destroy(sema.gpa);
......@@ -4450,7 +4449,7 @@ fn zirValidateArrayInitRefTy(
44504449 inst: Zir.Inst.Index,
44514450) CompileError!Air.Inst.Ref {
44524451 const pt = sema.pt;
4453 const mod = pt.zcu;
4452 const zcu = pt.zcu;
44544453 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
44554454 const src = block.nodeOffset(pl_node.src_node);
44564455 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;
......@@ -4458,16 +4457,16 @@ fn zirValidateArrayInitRefTy(
44584457 error.GenericPoison => return .generic_poison_type,
44594458 else => |e| return e,
44604459 };
4461 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(mod);
4462 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction
4463 switch (mod.intern_pool.indexToKey(ptr_ty.toIntern())) {
4460 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu);
4461 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
4462 switch (zcu.intern_pool.indexToKey(ptr_ty.toIntern())) {
44644463 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
44654464 .Slice, .Many => {
44664465 // Use array of correct length
44674466 const arr_ty = try pt.arrayType(.{
44684467 .len = extra.elem_count,
4469 .child = ptr_ty.childType(mod).toIntern(),
4470 .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
4468 .child = ptr_ty.childType(zcu).toIntern(),
4469 .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
44714470 });
44724471 return Air.internedToRef(arr_ty.toIntern());
44734472 },
......@@ -4476,12 +4475,12 @@ fn zirValidateArrayInitRefTy(
44764475 else => {},
44774476 }
44784477 // Otherwise, we just want the pointer child type
4479 const ret_ty = ptr_ty.childType(mod);
4478 const ret_ty = ptr_ty.childType(zcu);
44804479 if (ret_ty.toIntern() == .anyopaque_type) {
44814480 // The actual array type is unknown, which we represent with a generic poison.
44824481 return .generic_poison_type;
44834482 }
4484 const arr_ty = ret_ty.optEuBaseType(mod);
4483 const arr_ty = ret_ty.optEuBaseType(zcu);
44854484 try sema.validateArrayInitTy(block, src, src, extra.elem_count, arr_ty);
44864485 return Air.internedToRef(ret_ty.toIntern());
44874486}
......@@ -4493,7 +4492,7 @@ fn zirValidateArrayInitTy(
44934492 is_result_ty: bool,
44944493) CompileError!void {
44954494 const pt = sema.pt;
4496 const mod = pt.zcu;
4495 const zcu = pt.zcu;
44974496 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
44984497 const src = block.nodeOffset(inst_data.src_node);
44994498 const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node });
......@@ -4503,7 +4502,7 @@ fn zirValidateArrayInitTy(
45034502 error.GenericPoison => return,
45044503 else => |e| return e,
45054504 };
4506 const arr_ty = if (is_result_ty) ty.optEuBaseType(mod) else ty;
4505 const arr_ty = if (is_result_ty) ty.optEuBaseType(zcu) else ty;
45074506 return sema.validateArrayInitTy(block, src, ty_src, extra.init_count, arr_ty);
45084507}
45094508
......@@ -4516,10 +4515,10 @@ fn validateArrayInitTy(
45164515 ty: Type,
45174516) CompileError!void {
45184517 const pt = sema.pt;
4519 const mod = pt.zcu;
4520 switch (ty.zigTypeTag(mod)) {
4518 const zcu = pt.zcu;
4519 switch (ty.zigTypeTag(zcu)) {
45214520 .Array => {
4522 const array_len = ty.arrayLen(mod);
4521 const array_len = ty.arrayLen(zcu);
45234522 if (init_count != array_len) {
45244523 return sema.fail(block, src, "expected {d} array elements; found {d}", .{
45254524 array_len, init_count,
......@@ -4528,7 +4527,7 @@ fn validateArrayInitTy(
45284527 return;
45294528 },
45304529 .Vector => {
4531 const array_len = ty.arrayLen(mod);
4530 const array_len = ty.arrayLen(zcu);
45324531 if (init_count != array_len) {
45334532 return sema.fail(block, src, "expected {d} vector elements; found {d}", .{
45344533 array_len, init_count,
......@@ -4536,9 +4535,9 @@ fn validateArrayInitTy(
45364535 }
45374536 return;
45384537 },
4539 .Struct => if (ty.isTuple(mod)) {
4538 .Struct => if (ty.isTuple(zcu)) {
45404539 try ty.resolveFields(pt);
4541 const array_len = ty.arrayLen(mod);
4540 const array_len = ty.arrayLen(zcu);
45424541 if (init_count > array_len) {
45434542 return sema.fail(block, src, "expected at most {d} tuple fields; found {d}", .{
45444543 array_len, init_count,
......@@ -4558,7 +4557,7 @@ fn zirValidateStructInitTy(
45584557 is_result_ty: bool,
45594558) CompileError!void {
45604559 const pt = sema.pt;
4561 const mod = pt.zcu;
4560 const zcu = pt.zcu;
45624561 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
45634562 const src = block.nodeOffset(inst_data.src_node);
45644563 const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
......@@ -4566,9 +4565,9 @@ fn zirValidateStructInitTy(
45664565 error.GenericPoison => return,
45674566 else => |e| return e,
45684567 };
4569 const struct_ty = if (is_result_ty) ty.optEuBaseType(mod) else ty;
4568 const struct_ty = if (is_result_ty) ty.optEuBaseType(zcu) else ty;
45704569
4571 switch (struct_ty.zigTypeTag(mod)) {
4570 switch (struct_ty.zigTypeTag(zcu)) {
45724571 .Struct, .Union => return,
45734572 else => {},
45744573 }
......@@ -4584,7 +4583,7 @@ fn zirValidatePtrStructInit(
45844583 defer tracy.end();
45854584
45864585 const pt = sema.pt;
4587 const mod = pt.zcu;
4586 const zcu = pt.zcu;
45884587 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
45894588 const init_src = block.nodeOffset(validate_inst.src_node);
45904589 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
......@@ -4592,8 +4591,8 @@ fn zirValidatePtrStructInit(
45924591 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
45934592 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
45944593 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);
4595 const agg_ty = sema.typeOf(object_ptr).childType(mod).optEuBaseType(mod);
4596 switch (agg_ty.zigTypeTag(mod)) {
4594 const agg_ty = sema.typeOf(object_ptr).childType(zcu).optEuBaseType(zcu);
4595 switch (agg_ty.zigTypeTag(zcu)) {
45974596 .Struct => return sema.validateStructInit(
45984597 block,
45994598 agg_ty,
......@@ -4620,7 +4619,7 @@ fn validateUnionInit(
46204619 union_ptr: Air.Inst.Ref,
46214620) CompileError!void {
46224621 const pt = sema.pt;
4623 const mod = pt.zcu;
4622 const zcu = pt.zcu;
46244623 const gpa = sema.gpa;
46254624
46264625 if (instrs.len != 1) {
......@@ -4654,7 +4653,7 @@ fn validateUnionInit(
46544653 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
46554654 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
46564655 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
4657 const field_name = try mod.intern_pool.getOrPutString(
4656 const field_name = try zcu.intern_pool.getOrPutString(
46584657 gpa,
46594658 pt.tid,
46604659 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
......@@ -4718,9 +4717,9 @@ fn validateUnionInit(
47184717 break;
47194718 }
47204719
4721 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
4720 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
47224721 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
4723 const field_type = union_ty.unionFieldType(tag_val, mod).?;
4722 const field_type = union_ty.unionFieldType(tag_val, zcu).?;
47244723
47254724 if (try sema.typeHasOnePossibleValue(field_type)) |field_only_value| {
47264725 init_val = field_only_value;
......@@ -4761,7 +4760,7 @@ fn validateUnionInit(
47614760 const union_init = Air.internedToRef(union_val);
47624761 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
47634762 return;
4764 } else if (try sema.typeRequiresComptime(union_ty)) {
4763 } else if (try union_ty.comptimeOnlySema(pt)) {
47654764 return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{
47664765 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
47674766 });
......@@ -4781,15 +4780,15 @@ fn validateStructInit(
47814780 instrs: []const Zir.Inst.Index,
47824781) CompileError!void {
47834782 const pt = sema.pt;
4784 const mod = pt.zcu;
4783 const zcu = pt.zcu;
47854784 const gpa = sema.gpa;
4786 const ip = &mod.intern_pool;
4785 const ip = &zcu.intern_pool;
47874786
47884787 const field_indices = try gpa.alloc(u32, instrs.len);
47894788 defer gpa.free(field_indices);
47904789
47914790 // Maps field index to field_ptr index of where it was already initialized.
4792 const found_fields = try gpa.alloc(Zir.Inst.OptionalIndex, struct_ty.structFieldCount(mod));
4791 const found_fields = try gpa.alloc(Zir.Inst.OptionalIndex, struct_ty.structFieldCount(zcu));
47934792 defer gpa.free(found_fields);
47944793 @memset(found_fields, .none);
47954794
......@@ -4806,7 +4805,7 @@ fn validateStructInit(
48064805 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
48074806 .no_embedded_nulls,
48084807 );
4809 field_index.* = if (struct_ty.isTuple(mod))
4808 field_index.* = if (struct_ty.isTuple(zcu))
48104809 try sema.tupleFieldIndex(block, struct_ty, field_name, field_src)
48114810 else
48124811 try sema.structFieldIndex(block, struct_ty, field_name, field_src);
......@@ -4814,7 +4813,7 @@ fn validateStructInit(
48144813 found_fields[field_index.*] = field_ptr.toOptional();
48154814 }
48164815
4817 var root_msg: ?*Module.ErrorMsg = null;
4816 var root_msg: ?*Zcu.ErrorMsg = null;
48184817 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
48194818
48204819 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);
......@@ -4830,9 +4829,9 @@ fn validateStructInit(
48304829 if (field_ptr != .none) continue;
48314830
48324831 try struct_ty.resolveStructFieldInits(pt);
4833 const default_val = struct_ty.structFieldDefaultValue(i, mod);
4832 const default_val = struct_ty.structFieldDefaultValue(i, zcu);
48344833 if (default_val.toIntern() == .unreachable_value) {
4835 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
4834 const field_name = struct_ty.structFieldName(i, zcu).unwrap() orelse {
48364835 const template = "missing tuple field with index {d}";
48374836 if (root_msg) |msg| {
48384837 try sema.errNote(init_src, msg, template, .{i});
......@@ -4852,7 +4851,7 @@ fn validateStructInit(
48524851 }
48534852
48544853 const field_src = init_src; // TODO better source location
4855 const default_field_ptr = if (struct_ty.isTuple(mod))
4854 const default_field_ptr = if (struct_ty.isTuple(zcu))
48564855 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)
48574856 else
48584857 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);
......@@ -4874,7 +4873,7 @@ fn validateStructInit(
48744873 var struct_is_comptime = true;
48754874 var first_block_index = block.instructions.items.len;
48764875
4877 const require_comptime = try sema.typeRequiresComptime(struct_ty);
4876 const require_comptime = try struct_ty.comptimeOnlySema(pt);
48784877 const air_tags = sema.air_instructions.items(.tag);
48794878 const air_datas = sema.air_instructions.items(.data);
48804879
......@@ -4882,13 +4881,13 @@ fn validateStructInit(
48824881
48834882 // We collect the comptime field values in case the struct initialization
48844883 // ends up being comptime-known.
4885 const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(mod));
4884 const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(zcu));
48864885
48874886 field: for (found_fields, 0..) |opt_field_ptr, i_usize| {
48884887 const i: u32 = @intCast(i_usize);
48894888 if (opt_field_ptr.unwrap()) |field_ptr| {
48904889 // Determine whether the value stored to this pointer is comptime-known.
4891 const field_ty = struct_ty.structFieldType(i, mod);
4890 const field_ty = struct_ty.structFieldType(i, zcu);
48924891 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {
48934892 field_values[i] = opv.toIntern();
48944893 continue;
......@@ -4958,9 +4957,9 @@ fn validateStructInit(
49584957 continue :field;
49594958 }
49604959
4961 const default_val = struct_ty.structFieldDefaultValue(i, mod);
4960 const default_val = struct_ty.structFieldDefaultValue(i, zcu);
49624961 if (default_val.toIntern() == .unreachable_value) {
4963 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
4962 const field_name = struct_ty.structFieldName(i, zcu).unwrap() orelse {
49644963 const template = "missing tuple field with index {d}";
49654964 if (root_msg) |msg| {
49664965 try sema.errNote(init_src, msg, template, .{i});
......@@ -5000,7 +4999,7 @@ fn validateStructInit(
50004999 var block_index = first_block_index;
50015000 for (block.instructions.items[first_block_index..]) |cur_inst| {
50025001 while (field_ptr_ref == .none and init_index < instrs.len) : (init_index += 1) {
5003 const field_ty = struct_ty.structFieldType(field_indices[init_index], mod);
5002 const field_ty = struct_ty.structFieldType(field_indices[init_index], zcu);
50045003 if (try field_ty.onePossibleValue(pt)) |_| continue;
50055004 field_ptr_ref = sema.inst_map.get(instrs[init_index]).?;
50065005 }
......@@ -5044,7 +5043,7 @@ fn validateStructInit(
50445043 if (field_ptr != .none) continue;
50455044
50465045 const field_src = init_src; // TODO better source location
5047 const default_field_ptr = if (struct_ty.isTuple(mod))
5046 const default_field_ptr = if (struct_ty.isTuple(zcu))
50485047 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)
50495048 else
50505049 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);
......@@ -5060,7 +5059,7 @@ fn zirValidatePtrArrayInit(
50605059 inst: Zir.Inst.Index,
50615060) CompileError!void {
50625061 const pt = sema.pt;
5063 const mod = pt.zcu;
5062 const zcu = pt.zcu;
50645063 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
50655064 const init_src = block.nodeOffset(validate_inst.src_node);
50665065 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
......@@ -5068,8 +5067,8 @@ fn zirValidatePtrArrayInit(
50685067 const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
50695068 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;
50705069 const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr);
5071 const array_ty = sema.typeOf(array_ptr).childType(mod).optEuBaseType(mod);
5072 const array_len = array_ty.arrayLen(mod);
5070 const array_ty = sema.typeOf(array_ptr).childType(zcu).optEuBaseType(zcu);
5071 const array_len = array_ty.arrayLen(zcu);
50735072
50745073 // Collect the comptime element values in case the array literal ends up
50755074 // being comptime-known.
......@@ -5078,15 +5077,15 @@ fn zirValidatePtrArrayInit(
50785077 try sema.usizeCast(block, init_src, array_len),
50795078 );
50805079
5081 if (instrs.len != array_len) switch (array_ty.zigTypeTag(mod)) {
5080 if (instrs.len != array_len) switch (array_ty.zigTypeTag(zcu)) {
50825081 .Struct => {
5083 var root_msg: ?*Module.ErrorMsg = null;
5082 var root_msg: ?*Zcu.ErrorMsg = null;
50845083 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
50855084
50865085 try array_ty.resolveStructFieldInits(pt);
50875086 var i = instrs.len;
50885087 while (i < array_len) : (i += 1) {
5089 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();
5088 const default_val = array_ty.structFieldDefaultValue(i, zcu).toIntern();
50905089 if (default_val == .unreachable_value) {
50915090 const template = "missing tuple field with index {d}";
50925091 if (root_msg) |msg| {
......@@ -5125,7 +5124,7 @@ fn zirValidatePtrArrayInit(
51255124 // at comptime so we have almost nothing to do here. However, in case of a
51265125 // sentinel-terminated array, the sentinel will not have been populated by
51275126 // any ZIR instructions at comptime; we need to do that here.
5128 if (array_ty.sentinel(mod)) |sentinel_val| {
5127 if (array_ty.sentinel(zcu)) |sentinel_val| {
51295128 const array_len_ref = try pt.intRef(Type.usize, array_len);
51305129 const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true);
51315130 const sentinel = Air.internedToRef(sentinel_val.toIntern());
......@@ -5150,8 +5149,8 @@ fn zirValidatePtrArrayInit(
51505149 outer: for (instrs, 0..) |elem_ptr, i| {
51515150 // Determine whether the value stored to this pointer is comptime-known.
51525151
5153 if (array_ty.isTuple(mod)) {
5154 if (array_ty.structFieldIsComptime(i, mod))
5152 if (array_ty.isTuple(zcu)) {
5153 if (array_ty.structFieldIsComptime(i, zcu))
51555154 try array_ty.resolveStructFieldInits(pt);
51565155 if (try array_ty.structFieldValueComptime(pt, i)) |opv| {
51575156 element_vals[i] = opv.toIntern();
......@@ -5216,7 +5215,7 @@ fn zirValidatePtrArrayInit(
52165215
52175216 if (array_is_comptime) {
52185217 if (try sema.resolveDefinedValue(block, init_src, array_ptr)) |ptr_val| {
5219 switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) {
5218 switch (zcu.intern_pool.indexToKey(ptr_val.toIntern())) {
52205219 .ptr => |ptr| switch (ptr.base_addr) {
52215220 .comptime_field => return, // This store was validated by the individual elem ptrs.
52225221 else => {},
......@@ -5232,7 +5231,7 @@ fn zirValidatePtrArrayInit(
52325231 var block_index = first_block_index;
52335232 for (block.instructions.items[first_block_index..]) |cur_inst| {
52345233 while (elem_ptr_ref == .none and elem_index < instrs.len) : (elem_index += 1) {
5235 if (array_ty.isTuple(mod) and array_ty.structFieldIsComptime(elem_index, mod)) continue;
5234 if (array_ty.isTuple(zcu) and array_ty.structFieldIsComptime(elem_index, zcu)) continue;
52365235 elem_ptr_ref = sema.inst_map.get(instrs[elem_index]).?;
52375236 }
52385237 switch (air_tags[@intFromEnum(cur_inst)]) {
......@@ -5266,31 +5265,31 @@ fn zirValidatePtrArrayInit(
52665265
52675266fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
52685267 const pt = sema.pt;
5269 const mod = pt.zcu;
5268 const zcu = pt.zcu;
52705269 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
52715270 const src = block.nodeOffset(inst_data.src_node);
52725271 const operand = try sema.resolveInst(inst_data.operand);
52735272 const operand_ty = sema.typeOf(operand);
52745273
5275 if (operand_ty.zigTypeTag(mod) != .Pointer) {
5274 if (operand_ty.zigTypeTag(zcu) != .Pointer) {
52765275 return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(pt)});
5277 } else switch (operand_ty.ptrSize(mod)) {
5276 } else switch (operand_ty.ptrSize(zcu)) {
52785277 .One, .C => {},
52795278 .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(pt)}),
52805279 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(pt)}),
52815280 }
52825281
5283 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) {
5282 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(zcu))) != null) {
52845283 // No need to validate the actual pointer value, we don't need it!
52855284 return;
52865285 }
52875286
5288 const elem_ty = operand_ty.elemType2(mod);
5287 const elem_ty = operand_ty.elemType2(zcu);
52895288 if (try sema.resolveValue(operand)) |val| {
5290 if (val.isUndef(mod)) {
5289 if (val.isUndef(zcu)) {
52915290 return sema.fail(block, src, "cannot dereference undefined value", .{});
52925291 }
5293 } else if (try sema.typeRequiresComptime(elem_ty)) {
5292 } else if (try elem_ty.comptimeOnlySema(pt)) {
52945293 const msg = msg: {
52955294 const msg = try sema.errMsg(
52965295 src,
......@@ -5308,7 +5307,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
53085307
53095308fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
53105309 const pt = sema.pt;
5311 const mod = pt.zcu;
5310 const zcu = pt.zcu;
53125311 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
53135312 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
53145313 const src = block.nodeOffset(inst_data.src_node);
......@@ -5316,9 +5315,9 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
53165315 const operand = try sema.resolveInst(extra.operand);
53175316 const operand_ty = sema.typeOf(operand);
53185317
5319 const can_destructure = switch (operand_ty.zigTypeTag(mod)) {
5318 const can_destructure = switch (operand_ty.zigTypeTag(zcu)) {
53205319 .Array, .Vector => true,
5321 .Struct => operand_ty.isTuple(mod),
5320 .Struct => operand_ty.isTuple(zcu),
53225321 else => false,
53235322 };
53245323
......@@ -5331,11 +5330,11 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
53315330 });
53325331 }
53335332
5334 if (operand_ty.arrayLen(mod) != extra.expect_len) {
5333 if (operand_ty.arrayLen(zcu) != extra.expect_len) {
53355334 return sema.failWithOwnedErrorMsg(block, msg: {
53365335 const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{
53375336 extra.expect_len,
5338 operand_ty.arrayLen(mod),
5337 operand_ty.arrayLen(zcu),
53395338 });
53405339 errdefer msg.destroy(sema.gpa);
53415340 try sema.errNote(destructure_src, msg, "result destructured here", .{});
......@@ -5423,7 +5422,7 @@ fn failWithBadUnionFieldAccess(
54235422 return sema.failWithOwnedErrorMsg(block, msg);
54245423}
54255424
5426fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {
5425fn addDeclaredHereNote(sema: *Sema, parent: *Zcu.ErrorMsg, decl_ty: Type) !void {
54275426 const zcu = sema.pt.zcu;
54285427 const src_loc = decl_ty.srcLocOrNull(zcu) orelse return;
54295428 const category = switch (decl_ty.zigTypeTag(zcu)) {
......@@ -5537,7 +5536,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
55375536 defer tracy.end();
55385537
55395538 const pt = sema.pt;
5540 const mod = pt.zcu;
5539 const zcu = pt.zcu;
55415540 const zir_tags = sema.code.instructions.items(.tag);
55425541 const zir_datas = sema.code.instructions.items(.data);
55435542 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;
......@@ -5556,7 +5555,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
55565555 // %b = store(%a, %c)
55575556 // Where %c is an error union or error set. In such case we need to add
55585557 // to the current function's inferred error set, if any.
5559 if (is_ret and sema.fn_ret_ty_ies != null) switch (sema.typeOf(operand).zigTypeTag(mod)) {
5558 if (is_ret and sema.fn_ret_ty_ies != null) switch (sema.typeOf(operand).zigTypeTag(zcu)) {
55605559 .ErrorUnion, .ErrorSet => try sema.addToInferredErrorSet(operand),
55615560 else => {},
55625561 };
......@@ -5688,9 +5687,9 @@ fn zirCompileLog(
56885687 extended: Zir.Inst.Extended.InstData,
56895688) CompileError!Air.Inst.Ref {
56905689 const pt = sema.pt;
5691 const mod = pt.zcu;
5690 const zcu = pt.zcu;
56925691
5693 var managed = mod.compile_log_text.toManaged(sema.gpa);
5692 var managed = zcu.compile_log_text.toManaged(sema.gpa);
56945693 defer pt.zcu.compile_log_text = managed.moveToUnmanaged();
56955694 const writer = managed.writer();
56965695
......@@ -5713,7 +5712,7 @@ fn zirCompileLog(
57135712 }
57145713 try writer.print("\n", .{});
57155714
5716 const gop = try mod.compile_log_sources.getOrPut(sema.gpa, sema.owner);
5715 const gop = try zcu.compile_log_sources.getOrPut(sema.gpa, sema.owner);
57175716 if (!gop.found_existing) gop.value_ptr.* = .{
57185717 .base_node_inst = block.src_base_inst,
57195718 .node_offset = src_node,
......@@ -5749,7 +5748,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
57495748 defer tracy.end();
57505749
57515750 const pt = sema.pt;
5752 const mod = pt.zcu;
5751 const zcu = pt.zcu;
57535752 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
57545753 const src = parent_block.nodeOffset(inst_data.src_node);
57555754 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);
......@@ -5800,7 +5799,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
58005799 try sema.analyzeBodyInner(&loop_block, body);
58015800
58025801 const loop_block_len = loop_block.instructions.items.len;
5803 if (loop_block_len > 0 and sema.typeOf(loop_block.instructions.items[loop_block_len - 1].toRef()).isNoReturn(mod)) {
5802 if (loop_block_len > 0 and sema.typeOf(loop_block.instructions.items[loop_block_len - 1].toRef()).isNoReturn(zcu)) {
58045803 // If the loop ended with a noreturn terminator, then there is no way for it to loop,
58055804 // so we can just use the block instead.
58065805 try child_block.instructions.appendSlice(gpa, loop_block.instructions.items);
......@@ -6069,11 +6068,11 @@ fn resolveAnalyzedBlock(
60696068
60706069 const gpa = sema.gpa;
60716070 const pt = sema.pt;
6072 const mod = pt.zcu;
6071 const zcu = pt.zcu;
60736072
60746073 // Blocks must terminate with noreturn instruction.
60756074 assert(child_block.instructions.items.len != 0);
6076 assert(sema.typeOf(child_block.instructions.items[child_block.instructions.items.len - 1].toRef()).isNoReturn(mod));
6075 assert(sema.typeOf(child_block.instructions.items[child_block.instructions.items.len - 1].toRef()).isNoReturn(zcu));
60776076
60786077 const block_tag = sema.air_instructions.items(.tag)[@intFromEnum(merges.block_inst)];
60796078 switch (block_tag) {
......@@ -6178,7 +6177,7 @@ fn resolveAnalyzedBlock(
61786177 // TODO add note "missing else causes void value"
61796178
61806179 const type_src = src; // TODO: better source location
6181 if (try sema.typeRequiresComptime(resolved_ty)) {
6180 if (try resolved_ty.comptimeOnlySema(pt)) {
61826181 const msg = msg: {
61836182 const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(pt)});
61846183 errdefer msg.destroy(sema.gpa);
......@@ -6227,7 +6226,7 @@ fn resolveAnalyzedBlock(
62276226 const br_operand = sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand;
62286227 const br_operand_src = src;
62296228 const br_operand_ty = sema.typeOf(br_operand);
6230 if (br_operand_ty.eql(resolved_ty, mod)) {
6229 if (br_operand_ty.eql(resolved_ty, zcu)) {
62316230 // No type coercion needed.
62326231 continue;
62336232 }
......@@ -6354,7 +6353,7 @@ pub fn analyzeExport(
63546353 sema: *Sema,
63556354 block: *Block,
63566355 src: LazySrcLoc,
6357 options: Module.Export.Options,
6356 options: Zcu.Export.Options,
63586357 exported_nav_index: InternPool.Nav.Index,
63596358) !void {
63606359 const gpa = sema.gpa;
......@@ -6427,8 +6426,8 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
64276426
64286427fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
64296428 const pt = sema.pt;
6430 const mod = pt.zcu;
6431 const ip = &mod.intern_pool;
6429 const zcu = pt.zcu;
6430 const ip = &zcu.intern_pool;
64326431 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
64336432 const operand_src = block.builtinCallArgSrc(extra.node, 0);
64346433 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{
......@@ -6446,8 +6445,8 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
64466445
64476446fn zirDisableInstrumentation(sema: *Sema) CompileError!void {
64486447 const pt = sema.pt;
6449 const mod = pt.zcu;
6450 const ip = &mod.intern_pool;
6448 const zcu = pt.zcu;
6449 const ip = &zcu.intern_pool;
64516450 const func = switch (sema.owner.unwrap()) {
64526451 .func => |func| func,
64536452 .cau => return, // does nothing outside a function
......@@ -6572,17 +6571,17 @@ fn addDbgVar(
65726571 if (block.is_comptime or block.ownerModule().strip) return;
65736572
65746573 const pt = sema.pt;
6575 const mod = pt.zcu;
6574 const zcu = pt.zcu;
65766575 const operand_ty = sema.typeOf(operand);
65776576 const val_ty = switch (air_tag) {
6578 .dbg_var_ptr => operand_ty.childType(mod),
6577 .dbg_var_ptr => operand_ty.childType(zcu),
65796578 .dbg_var_val, .dbg_arg_inline => operand_ty,
65806579 else => unreachable,
65816580 };
6582 if (try sema.typeRequiresComptime(val_ty)) return;
6583 if (!(try sema.typeHasRuntimeBits(val_ty))) return;
6581 if (try val_ty.comptimeOnlySema(pt)) return;
6582 if (!(try val_ty.hasRuntimeBitsSema(pt))) return;
65846583 if (try sema.resolveValue(operand)) |operand_val| {
6585 if (operand_val.canMutateComptimeVarState(mod)) return;
6584 if (operand_val.canMutateComptimeVarState(zcu)) return;
65866585 }
65876586
65886587 // To ensure the lexical scoping is known to backends, this alloc must be
......@@ -6619,10 +6618,10 @@ pub fn appendAirString(sema: *Sema, str: []const u8) Allocator.Error!Air.NullTer
66196618
66206619fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
66216620 const pt = sema.pt;
6622 const mod = pt.zcu;
6621 const zcu = pt.zcu;
66236622 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
66246623 const src = block.tokenOffset(inst_data.src_tok);
6625 const decl_name = try mod.intern_pool.getOrPutString(
6624 const decl_name = try zcu.intern_pool.getOrPutString(
66266625 sema.gpa,
66276626 pt.tid,
66286627 inst_data.get(sema.code),
......@@ -6634,10 +6633,10 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
66346633
66356634fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
66366635 const pt = sema.pt;
6637 const mod = pt.zcu;
6636 const zcu = pt.zcu;
66386637 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
66396638 const src = block.tokenOffset(inst_data.src_tok);
6640 const decl_name = try mod.intern_pool.getOrPutString(
6639 const decl_name = try zcu.intern_pool.getOrPutString(
66416640 sema.gpa,
66426641 pt.tid,
66436642 inst_data.get(sema.code),
......@@ -6649,14 +6648,14 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
66496648
66506649fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !InternPool.Nav.Index {
66516650 const pt = sema.pt;
6652 const mod = pt.zcu;
6651 const zcu = pt.zcu;
66536652 var namespace = block.namespace;
66546653 while (true) {
66556654 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |lookup| {
66566655 assert(lookup.accessible);
66576656 return lookup.nav;
66586657 }
6659 namespace = mod.namespacePtr(namespace).parent.unwrap() orelse break;
6658 namespace = zcu.namespacePtr(namespace).parent.unwrap() orelse break;
66606659 }
66616660 unreachable; // AstGen detects use of undeclared identifiers.
66626661}
......@@ -6801,7 +6800,7 @@ fn funcDeclSrcInst(sema: *Sema, func_inst: Air.Inst.Ref) !?InternPool.TrackedIns
68016800
68026801pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref {
68036802 const pt = sema.pt;
6804 const mod = pt.zcu;
6803 const zcu = pt.zcu;
68056804 const gpa = sema.gpa;
68066805
68076806 if (block.is_comptime or block.is_typeof) {
......@@ -6813,7 +6812,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
68136812
68146813 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
68156814 try stack_trace_ty.resolveFields(pt);
6816 const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
6815 const field_name = try zcu.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
68176816 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
68186817 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
68196818 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
......@@ -6839,7 +6838,7 @@ fn popErrorReturnTrace(
68396838 saved_error_trace_index: Air.Inst.Ref,
68406839) CompileError!void {
68416840 const pt = sema.pt;
6842 const mod = pt.zcu;
6841 const zcu = pt.zcu;
68436842 const gpa = sema.gpa;
68446843 var is_non_error: ?bool = null;
68456844 var is_non_error_inst: Air.Inst.Ref = undefined;
......@@ -6857,7 +6856,7 @@ fn popErrorReturnTrace(
68576856 try stack_trace_ty.resolveFields(pt);
68586857 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
68596858 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);
6860 const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
6859 const field_name = try zcu.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
68616860 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true);
68626861 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);
68636862 } else if (is_non_error == null) {
......@@ -6883,7 +6882,7 @@ fn popErrorReturnTrace(
68836882 try stack_trace_ty.resolveFields(pt);
68846883 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
68856884 const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty);
6886 const field_name = try mod.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
6885 const field_name = try zcu.intern_pool.getOrPutString(gpa, pt.tid, "index", .no_embedded_nulls);
68876886 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);
68886887 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
68896888 _ = try then_block.addBr(cond_block_inst, .void_value);
......@@ -6923,7 +6922,7 @@ fn zirCall(
69236922 defer tracy.end();
69246923
69256924 const pt = sema.pt;
6926 const mod = pt.zcu;
6925 const zcu = pt.zcu;
69276926 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
69286927 const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node });
69296928 const call_src = block.nodeOffset(inst_data.src_node);
......@@ -6942,7 +6941,7 @@ fn zirCall(
69426941 .direct => .{ .direct = try sema.resolveInst(extra.data.callee) },
69436942 .field => blk: {
69446943 const object_ptr = try sema.resolveInst(extra.data.obj_ptr);
6945 const field_name = try mod.intern_pool.getOrPutString(
6944 const field_name = try zcu.intern_pool.getOrPutString(
69466945 sema.gpa,
69476946 pt.tid,
69486947 sema.code.nullTerminatedString(extra.data.field_name_start),
......@@ -6987,7 +6986,7 @@ fn zirCall(
69876986
69886987 switch (sema.owner.unwrap()) {
69896988 .cau => input_is_error = false,
6990 .func => |owner_func| if (!mod.intern_pool.funcAnalysisUnordered(owner_func).calls_or_awaits_errorable_fn) {
6989 .func => |owner_func| if (!zcu.intern_pool.funcAnalysisUnordered(owner_func).calls_or_awaits_errorable_fn) {
69916990 // No errorable fn actually called; we have no error return trace
69926991 input_is_error = false;
69936992 },
......@@ -6997,7 +6996,7 @@ fn zirCall(
69976996 !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace))
69986997 {
69996998 const return_ty = sema.typeOf(call_inst);
7000 if (modifier != .always_tail and return_ty.isNoReturn(mod))
6999 if (modifier != .always_tail and return_ty.isNoReturn(zcu))
70017000 return call_inst; // call to "fn (...) noreturn", don't pop
70027001
70037002 // TODO: we don't fix up the error trace for always_tail correctly, we should be doing it
......@@ -7008,10 +7007,10 @@ fn zirCall(
70087007
70097008 // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only
70107009 // need to clean-up our own trace if we were passed to a non-error-handling expression.
7011 if (input_is_error or (pop_error_return_trace and return_ty.isError(mod))) {
7010 if (input_is_error or (pop_error_return_trace and return_ty.isError(zcu))) {
70127011 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
70137012 try stack_trace_ty.resolveFields(pt);
7014 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "index", .no_embedded_nulls);
7013 const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "index", .no_embedded_nulls);
70157014 const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src);
70167015
70177016 // Insert a save instruction before the arg resolution + call instructions we just generated
......@@ -7044,20 +7043,20 @@ fn checkCallArgumentCount(
70447043 member_fn: bool,
70457044) !Type {
70467045 const pt = sema.pt;
7047 const mod = pt.zcu;
7046 const zcu = pt.zcu;
70487047 const func_ty = func_ty: {
7049 switch (callee_ty.zigTypeTag(mod)) {
7048 switch (callee_ty.zigTypeTag(zcu)) {
70507049 .Fn => break :func_ty callee_ty,
70517050 .Pointer => {
7052 const ptr_info = callee_ty.ptrInfo(mod);
7053 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {
7051 const ptr_info = callee_ty.ptrInfo(zcu);
7052 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Fn) {
70547053 break :func_ty Type.fromInterned(ptr_info.child);
70557054 }
70567055 },
70577056 .Optional => {
7058 const opt_child = callee_ty.optionalChild(mod);
7059 if (opt_child.zigTypeTag(mod) == .Fn or (opt_child.isSinglePointer(mod) and
7060 opt_child.childType(mod).zigTypeTag(mod) == .Fn))
7057 const opt_child = callee_ty.optionalChild(zcu);
7058 if (opt_child.zigTypeTag(zcu) == .Fn or (opt_child.isSinglePointer(zcu) and
7059 opt_child.childType(zcu).zigTypeTag(zcu) == .Fn))
70617060 {
70627061 const msg = msg: {
70637062 const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{
......@@ -7075,7 +7074,7 @@ fn checkCallArgumentCount(
70757074 return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(pt)});
70767075 };
70777076
7078 const func_ty_info = mod.typeToFunc(func_ty).?;
7077 const func_ty_info = zcu.typeToFunc(func_ty).?;
70797078 const fn_params_len = func_ty_info.param_types.len;
70807079 const args_len = total_args - @intFromBool(member_fn);
70817080 if (func_ty_info.is_var_args) {
......@@ -7122,14 +7121,14 @@ fn callBuiltin(
71227121 operation: CallOperation,
71237122) !void {
71247123 const pt = sema.pt;
7125 const mod = pt.zcu;
7124 const zcu = pt.zcu;
71267125 const callee_ty = sema.typeOf(builtin_fn);
71277126 const func_ty = func_ty: {
7128 switch (callee_ty.zigTypeTag(mod)) {
7127 switch (callee_ty.zigTypeTag(zcu)) {
71297128 .Fn => break :func_ty callee_ty,
71307129 .Pointer => {
7131 const ptr_info = callee_ty.ptrInfo(mod);
7132 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {
7130 const ptr_info = callee_ty.ptrInfo(zcu);
7131 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Fn) {
71337132 break :func_ty Type.fromInterned(ptr_info.child);
71347133 }
71357134 },
......@@ -7138,7 +7137,7 @@ fn callBuiltin(
71387137 std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(pt)});
71397138 };
71407139
7141 const func_ty_info = mod.typeToFunc(func_ty).?;
7140 const func_ty_info = zcu.typeToFunc(func_ty).?;
71427141 const fn_params_len = func_ty_info.param_types.len;
71437142 if (args.len != fn_params_len or (func_ty_info.is_var_args and args.len < fn_params_len)) {
71447143 std.debug.panic("parameter count mismatch calling builtin fn, expected {d}, found {d}", .{ fn_params_len, args.len });
......@@ -7242,7 +7241,7 @@ const CallArgsInfo = union(enum) {
72427241 func_inst: Air.Inst.Ref,
72437242 ) CompileError!Air.Inst.Ref {
72447243 const pt = sema.pt;
7245 const mod = pt.zcu;
7244 const zcu = pt.zcu;
72467245 const param_count = func_ty_info.param_types.len;
72477246 const uncoerced_arg: Air.Inst.Ref = switch (cai) {
72487247 inline .resolved, .call_builtin => |resolved| resolved.args[arg_index],
......@@ -7277,13 +7276,13 @@ const CallArgsInfo = union(enum) {
72777276 // Resolve the arg!
72787277 const uncoerced_arg = try sema.resolveInlineBody(block, arg_body, zir_call.call_inst);
72797278
7280 if (sema.typeOf(uncoerced_arg).zigTypeTag(mod) == .NoReturn) {
7279 if (sema.typeOf(uncoerced_arg).zigTypeTag(zcu) == .NoReturn) {
72817280 // This terminates resolution of arguments. The caller should
72827281 // propagate this.
72837282 return uncoerced_arg;
72847283 }
72857284
7286 if (sema.typeOf(uncoerced_arg).isError(mod)) {
7285 if (sema.typeOf(uncoerced_arg).isError(zcu)) {
72877286 zir_call.any_arg_is_error.* = true;
72887287 }
72897288
......@@ -7476,7 +7475,7 @@ fn analyzeCall(
74767475 var is_inline_call = is_comptime_call or modifier == .always_inline or func_ty_info.cc == .Inline;
74777476 var comptime_reason: ?*const Block.ComptimeReason = null;
74787477 if (!is_inline_call and !is_comptime_call) {
7479 if (try sema.typeRequiresComptime(Type.fromInterned(func_ty_info.return_type))) {
7478 if (try Type.fromInterned(func_ty_info.return_type).comptimeOnlySema(pt)) {
74807479 is_comptime_call = true;
74817480 is_inline_call = true;
74827481 comptime_reason = &.{ .comptime_ret_ty = .{
......@@ -7968,8 +7967,8 @@ fn analyzeInlineCallArg(
79687967 func_ty_info: InternPool.Key.FuncType,
79697968 func_inst: Air.Inst.Ref,
79707969) !?Air.Inst.Ref {
7971 const mod = ics.sema.pt.zcu;
7972 const ip = &mod.intern_pool;
7970 const zcu = ics.sema.pt.zcu;
7971 const ip = &zcu.intern_pool;
79737972 const zir_tags = ics.callee().code.instructions.items(.tag);
79747973 switch (zir_tags[@intFromEnum(inst)]) {
79757974 .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true,
......@@ -7992,11 +7991,11 @@ fn analyzeInlineCallArg(
79927991 };
79937992 new_param_types[arg_i.*] = param_ty;
79947993 const casted_arg = try args_info.analyzeArg(ics.caller(), arg_block, arg_i.*, Type.fromInterned(param_ty), func_ty_info, func_inst);
7995 if (ics.caller().typeOf(casted_arg).zigTypeTag(mod) == .NoReturn) {
7994 if (ics.caller().typeOf(casted_arg).zigTypeTag(zcu) == .NoReturn) {
79967995 return casted_arg;
79977996 }
79987997 const arg_src = args_info.argSrc(arg_block, arg_i.*);
7999 if (try ics.callee().typeRequiresComptime(Type.fromInterned(param_ty))) {
7998 if (try Type.fromInterned(param_ty).comptimeOnlySema(ics.callee().pt)) {
80007999 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
80018000 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
80028001 .block_comptime_reason = param_block.comptime_reason,
......@@ -8025,7 +8024,7 @@ fn analyzeInlineCallArg(
80258024 // assertion due to type not being resolved
80268025 // when the hash function is called.
80278026 const resolved_arg_val = try ics.caller().resolveLazyValue(arg_val);
8028 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod);
8027 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(zcu);
80298028 memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern();
80308029 } else {
80318030 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
......@@ -8040,7 +8039,7 @@ fn analyzeInlineCallArg(
80408039 .param_anytype, .param_anytype_comptime => {
80418040 // No coercion needed.
80428041 const uncasted_arg = try args_info.analyzeArg(ics.caller(), arg_block, arg_i.*, Type.generic_poison, func_ty_info, func_inst);
8043 if (ics.caller().typeOf(uncasted_arg).zigTypeTag(mod) == .NoReturn) {
8042 if (ics.caller().typeOf(uncasted_arg).zigTypeTag(zcu) == .NoReturn) {
80448043 return uncasted_arg;
80458044 }
80468045 const arg_src = args_info.argSrc(arg_block, arg_i.*);
......@@ -8064,7 +8063,7 @@ fn analyzeInlineCallArg(
80648063 // assertion due to type not being resolved
80658064 // when the hash function is called.
80668065 const resolved_arg_val = try ics.caller().resolveLazyValue(arg_val);
8067 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod);
8066 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(zcu);
80688067 memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern();
80698068 } else {
80708069 if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) {
......@@ -8236,7 +8235,7 @@ fn instantiateGenericCall(
82368235
82378236 const arg_is_comptime = switch (param_tag) {
82388237 .param_comptime, .param_anytype_comptime => true,
8239 .param, .param_anytype => try sema.typeRequiresComptime(arg_ty),
8238 .param, .param_anytype => try arg_ty.comptimeOnlySema(pt),
82408239 else => unreachable,
82418240 };
82428241
......@@ -8325,7 +8324,7 @@ fn instantiateGenericCall(
83258324
83268325 // If the call evaluated to a return type that requires comptime, never mind
83278326 // our generic instantiation. Instead we need to perform a comptime call.
8328 if (try sema.typeRequiresComptime(Type.fromInterned(func_ty_info.return_type))) {
8327 if (try Type.fromInterned(func_ty_info.return_type).comptimeOnlySema(pt)) {
83298328 return error.ComptimeReturn;
83308329 }
83318330 // Similarly, if the call evaluated to a generic type we need to instead
......@@ -8376,8 +8375,8 @@ fn instantiateGenericCall(
83768375
83778376fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
83788377 const pt = sema.pt;
8379 const mod = pt.zcu;
8380 const ip = &mod.intern_pool;
8378 const zcu = pt.zcu;
8379 const ip = &zcu.intern_pool;
83818380 const tuple = switch (ip.indexToKey(ty.toIntern())) {
83828381 .anon_struct_type => |tuple| tuple,
83838382 else => return,
......@@ -8401,13 +8400,13 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
84018400 defer tracy.end();
84028401
84038402 const pt = sema.pt;
8404 const mod = pt.zcu;
8403 const zcu = pt.zcu;
84058404 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
84068405 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
84078406 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
8408 if (child_type.zigTypeTag(mod) == .Opaque) {
8407 if (child_type.zigTypeTag(zcu) == .Opaque) {
84098408 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(pt)});
8410 } else if (child_type.zigTypeTag(mod) == .Null) {
8409 } else if (child_type.zigTypeTag(zcu) == .Null) {
84118410 return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(pt)});
84128411 }
84138412 const opt_type = try pt.optionalType(child_type.toIntern());
......@@ -8417,7 +8416,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
84178416
84188417fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84198418 const pt = sema.pt;
8420 const mod = pt.zcu;
8419 const zcu = pt.zcu;
84218420 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
84228421 const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) {
84238422 // Since this is a ZIR instruction that returns a type, encountering
......@@ -8427,40 +8426,40 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
84278426 error.GenericPoison => return .generic_poison_type,
84288427 else => |e| return e,
84298428 };
8430 const indexable_ty = maybe_wrapped_indexable_ty.optEuBaseType(mod);
8429 const indexable_ty = maybe_wrapped_indexable_ty.optEuBaseType(zcu);
84318430 try indexable_ty.resolveFields(pt);
8432 assert(indexable_ty.isIndexable(mod)); // validated by a previous instruction
8433 if (indexable_ty.zigTypeTag(mod) == .Struct) {
8434 const elem_type = indexable_ty.structFieldType(@intFromEnum(bin.rhs), mod);
8431 assert(indexable_ty.isIndexable(zcu)); // validated by a previous instruction
8432 if (indexable_ty.zigTypeTag(zcu) == .Struct) {
8433 const elem_type = indexable_ty.structFieldType(@intFromEnum(bin.rhs), zcu);
84358434 return Air.internedToRef(elem_type.toIntern());
84368435 } else {
8437 const elem_type = indexable_ty.elemType2(mod);
8436 const elem_type = indexable_ty.elemType2(zcu);
84388437 return Air.internedToRef(elem_type.toIntern());
84398438 }
84408439}
84418440
84428441fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84438442 const pt = sema.pt;
8444 const mod = pt.zcu;
8443 const zcu = pt.zcu;
84458444 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
84468445 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
84478446 error.GenericPoison => return .generic_poison_type,
84488447 else => |e| return e,
84498448 };
8450 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(mod);
8451 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction
8452 const elem_ty = ptr_ty.childType(mod);
8449 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu);
8450 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
8451 const elem_ty = ptr_ty.childType(zcu);
84538452 if (elem_ty.toIntern() == .anyopaque_type) {
84548453 // The pointer's actual child type is effectively unknown, so it makes
84558454 // sense to represent it with a generic poison.
84568455 return .generic_poison_type;
84578456 }
8458 return Air.internedToRef(ptr_ty.childType(mod).toIntern());
8457 return Air.internedToRef(ptr_ty.childType(zcu).toIntern());
84598458}
84608459
84618460fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84628461 const pt = sema.pt;
8463 const mod = pt.zcu;
8462 const zcu = pt.zcu;
84648463 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
84658464 const src = block.nodeOffset(un_node.src_node);
84668465 const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) {
......@@ -8468,16 +8467,16 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
84688467 else => |e| return e,
84698468 };
84708469 try sema.checkMemOperand(block, src, ptr_ty);
8471 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
8472 .Slice, .Many, .C => ptr_ty.childType(mod),
8473 .One => ptr_ty.childType(mod).childType(mod),
8470 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
8471 .Slice, .Many, .C => ptr_ty.childType(zcu),
8472 .One => ptr_ty.childType(zcu).childType(zcu),
84748473 };
84758474 return Air.internedToRef(elem_ty.toIntern());
84768475}
84778476
84788477fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84798478 const pt = sema.pt;
8480 const mod = pt.zcu;
8479 const zcu = pt.zcu;
84818480 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
84828481 const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
84838482 // Since this is a ZIR instruction that returns a type, encountering
......@@ -8487,10 +8486,10 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
84878486 error.GenericPoison => return .generic_poison_type,
84888487 else => |e| return e,
84898488 };
8490 if (!vec_ty.isVector(mod)) {
8489 if (!vec_ty.isVector(zcu)) {
84918490 return sema.fail(block, block.nodeOffset(un_node.src_node), "expected vector type, found '{}'", .{vec_ty.fmt(pt)});
84928491 }
8493 return Air.internedToRef(vec_ty.childType(mod).toIntern());
8492 return Air.internedToRef(vec_ty.childType(zcu).toIntern());
84948493}
84958494
84968495fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8561,10 +8560,10 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
85618560
85628561fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void {
85638562 const pt = sema.pt;
8564 const mod = pt.zcu;
8565 if (elem_type.zigTypeTag(mod) == .Opaque) {
8563 const zcu = pt.zcu;
8564 if (elem_type.zigTypeTag(zcu) == .Opaque) {
85668565 return sema.fail(block, elem_src, "array of opaque type '{}' not allowed", .{elem_type.fmt(pt)});
8567 } else if (elem_type.zigTypeTag(mod) == .NoReturn) {
8566 } else if (elem_type.zigTypeTag(zcu) == .NoReturn) {
85688567 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});
85698568 }
85708569}
......@@ -8577,10 +8576,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
85778576 if (true) {
85788577 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));
85798578 }
8580 const mod = sema.mod;
8579 const zcu = sema.zcu;
85818580 const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node });
85828581 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
8583 const anyframe_type = try mod.anyframeType(return_type);
8582 const anyframe_type = try zcu.anyframeType(return_type);
85848583
85858584 return Air.internedToRef(anyframe_type.toIntern());
85868585}
......@@ -8590,7 +8589,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
85908589 defer tracy.end();
85918590
85928591 const pt = sema.pt;
8593 const mod = pt.zcu;
8592 const zcu = pt.zcu;
85948593 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
85958594 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
85968595 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -8598,7 +8597,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
85988597 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);
85998598 const payload = try sema.resolveType(block, rhs_src, extra.rhs);
86008599
8601 if (error_set.zigTypeTag(mod) != .ErrorSet) {
8600 if (error_set.zigTypeTag(zcu) != .ErrorSet) {
86028601 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{
86038602 error_set.fmt(pt),
86048603 });
......@@ -8610,12 +8609,12 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
86108609
86118610fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, payload_src: LazySrcLoc) !void {
86128611 const pt = sema.pt;
8613 const mod = pt.zcu;
8614 if (payload_ty.zigTypeTag(mod) == .Opaque) {
8612 const zcu = pt.zcu;
8613 if (payload_ty.zigTypeTag(zcu) == .Opaque) {
86158614 return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{
86168615 payload_ty.fmt(pt),
86178616 });
8618 } else if (payload_ty.zigTypeTag(mod) == .ErrorSet) {
8617 } else if (payload_ty.zigTypeTag(zcu) == .ErrorSet) {
86198618 return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{
86208619 payload_ty.fmt(pt),
86218620 });
......@@ -8646,8 +8645,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
86468645 defer tracy.end();
86478646
86488647 const pt = sema.pt;
8649 const mod = pt.zcu;
8650 const ip = &mod.intern_pool;
8648 const zcu = pt.zcu;
8649 const ip = &zcu.intern_pool;
86518650 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
86528651 const src = block.nodeOffset(extra.node);
86538652 const operand_src = block.builtinCallArgSrc(extra.node, 0);
......@@ -8656,7 +8655,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
86568655 const err_int_ty = try pt.errorIntType();
86578656
86588657 if (try sema.resolveValue(operand)) |val| {
8659 if (val.isUndef(mod)) {
8658 if (val.isUndef(zcu)) {
86608659 return pt.undefRef(err_int_ty);
86618660 }
86628661 const err_name = ip.indexToKey(val.toIntern()).err.name;
......@@ -8688,8 +8687,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
86888687 defer tracy.end();
86898688
86908689 const pt = sema.pt;
8691 const mod = pt.zcu;
8692 const ip = &mod.intern_pool;
8690 const zcu = pt.zcu;
8691 const ip = &zcu.intern_pool;
86938692 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
86948693 const src = block.nodeOffset(extra.node);
86958694 const operand_src = block.builtinCallArgSrc(extra.node, 0);
......@@ -8733,8 +8732,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
87338732 defer tracy.end();
87348733
87358734 const pt = sema.pt;
8736 const mod = pt.zcu;
8737 const ip = &mod.intern_pool;
8735 const zcu = pt.zcu;
8736 const ip = &zcu.intern_pool;
87388737 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
87398738 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
87408739 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
......@@ -8742,7 +8741,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
87428741 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
87438742 const lhs = try sema.resolveInst(extra.lhs);
87448743 const rhs = try sema.resolveInst(extra.rhs);
8745 if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) {
8744 if (sema.typeOf(lhs).zigTypeTag(zcu) == .Bool and sema.typeOf(rhs).zigTypeTag(zcu) == .Bool) {
87468745 const msg = msg: {
87478746 const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{});
87488747 errdefer msg.destroy(sema.gpa);
......@@ -8753,9 +8752,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
87538752 }
87548753 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);
87558754 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);
8756 if (lhs_ty.zigTypeTag(mod) != .ErrorSet)
8755 if (lhs_ty.zigTypeTag(zcu) != .ErrorSet)
87578756 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{lhs_ty.fmt(pt)});
8758 if (rhs_ty.zigTypeTag(mod) != .ErrorSet)
8757 if (rhs_ty.zigTypeTag(zcu) != .ErrorSet)
87598758 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(pt)});
87608759
87618760 // Anything merged with anyerror is anyerror.
......@@ -8790,28 +8789,28 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
87908789 defer tracy.end();
87918790
87928791 const pt = sema.pt;
8793 const mod = pt.zcu;
8792 const zcu = pt.zcu;
87948793 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
87958794 const name = inst_data.get(sema.code);
87968795 return Air.internedToRef((try pt.intern(.{
8797 .enum_literal = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, name, .no_embedded_nulls),
8796 .enum_literal = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, name, .no_embedded_nulls),
87988797 })));
87998798}
88008799
88018800fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
88028801 const pt = sema.pt;
8803 const mod = pt.zcu;
8802 const zcu = pt.zcu;
88048803 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
88058804 const src = block.nodeOffset(inst_data.src_node);
88068805 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
88078806 const operand = try sema.resolveInst(inst_data.operand);
88088807 const operand_ty = sema.typeOf(operand);
88098808
8810 const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag(mod)) {
8809 const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag(zcu)) {
88118810 .Enum => operand,
88128811 .Union => blk: {
88138812 try operand_ty.resolveFields(pt);
8814 const tag_ty = operand_ty.unionTagType(mod) orelse {
8813 const tag_ty = operand_ty.unionTagType(zcu) orelse {
88158814 return sema.fail(
88168815 block,
88178816 operand_src,
......@@ -8829,11 +8828,11 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88298828 },
88308829 };
88318830 const enum_tag_ty = sema.typeOf(enum_tag);
8832 const int_tag_ty = enum_tag_ty.intTagType(mod);
8831 const int_tag_ty = enum_tag_ty.intTagType(zcu);
88338832
88348833 // TODO: use correct solution
88358834 // https://github.com/ziglang/zig/issues/15909
8836 if (enum_tag_ty.enumFieldCount(mod) == 0 and !enum_tag_ty.isNonexhaustiveEnum(mod)) {
8835 if (enum_tag_ty.enumFieldCount(zcu) == 0 and !enum_tag_ty.isNonexhaustiveEnum(zcu)) {
88378836 return sema.fail(block, operand_src, "cannot use @intFromEnum on empty enum '{}'", .{
88388837 enum_tag_ty.fmt(pt),
88398838 });
......@@ -8844,7 +8843,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88448843 }
88458844
88468845 if (try sema.resolveValue(enum_tag)) |enum_tag_val| {
8847 if (enum_tag_val.isUndef(mod)) {
8846 if (enum_tag_val.isUndef(zcu)) {
88488847 return pt.undefRef(int_tag_ty);
88498848 }
88508849
......@@ -8858,7 +8857,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88588857
88598858fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
88608859 const pt = sema.pt;
8861 const mod = pt.zcu;
8860 const zcu = pt.zcu;
88628861 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
88638862 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
88648863 const src = block.nodeOffset(inst_data.src_node);
......@@ -8866,14 +8865,14 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88668865 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
88678866 const operand = try sema.resolveInst(extra.rhs);
88688867
8869 if (dest_ty.zigTypeTag(mod) != .Enum) {
8868 if (dest_ty.zigTypeTag(zcu) != .Enum) {
88708869 return sema.fail(block, src, "expected enum, found '{}'", .{dest_ty.fmt(pt)});
88718870 }
88728871 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
88738872
88748873 if (try sema.resolveValue(operand)) |int_val| {
8875 if (dest_ty.isNonexhaustiveEnum(mod)) {
8876 const int_tag_ty = dest_ty.intTagType(mod);
8874 if (dest_ty.isNonexhaustiveEnum(zcu)) {
8875 const int_tag_ty = dest_ty.intTagType(zcu);
88778876 if (try sema.intFitsInType(int_val, int_tag_ty, null)) {
88788877 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
88798878 }
......@@ -8881,7 +8880,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88818880 int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt),
88828881 });
88838882 }
8884 if (int_val.isUndef(mod)) {
8883 if (int_val.isUndef(zcu)) {
88858884 return sema.failWithUseOfUndef(block, operand_src);
88868885 }
88878886 if (!(try sema.enumHasInt(dest_ty, int_val))) {
......@@ -8892,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88928891 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
88938892 }
88948893
8895 if (dest_ty.intTagType(mod).zigTypeTag(mod) == .ComptimeInt) {
8894 if (dest_ty.intTagType(zcu).zigTypeTag(zcu) == .ComptimeInt) {
88968895 return sema.failWithNeededComptime(block, operand_src, .{
88978896 .needed_comptime_reason = "value being casted to enum with 'comptime_int' tag type must be comptime-known",
88988897 });
......@@ -8909,8 +8908,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
89098908
89108909 try sema.requireRuntimeBlock(block, src, operand_src);
89118910 const result = try block.addTyOp(.intcast, dest_ty, operand);
8912 if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(mod) and
8913 mod.backendSupportsFeature(.is_named_enum_value))
8911 if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(zcu) and
8912 zcu.backendSupportsFeature(.is_named_enum_value))
89148913 {
89158914 const ok = try block.addUnOp(.is_named_enum_value, result);
89168915 try sema.addSafetyCheck(block, src, ok, .invalid_enum_value);
......@@ -9014,20 +9013,20 @@ fn zirOptionalPayload(
90149013 defer tracy.end();
90159014
90169015 const pt = sema.pt;
9017 const mod = pt.zcu;
9016 const zcu = pt.zcu;
90189017 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
90199018 const src = block.nodeOffset(inst_data.src_node);
90209019 const operand = try sema.resolveInst(inst_data.operand);
90219020 const operand_ty = sema.typeOf(operand);
9022 const result_ty = switch (operand_ty.zigTypeTag(mod)) {
9023 .Optional => operand_ty.optionalChild(mod),
9021 const result_ty = switch (operand_ty.zigTypeTag(zcu)) {
9022 .Optional => operand_ty.optionalChild(zcu),
90249023 .Pointer => t: {
9025 if (operand_ty.ptrSize(mod) != .C) {
9024 if (operand_ty.ptrSize(zcu) != .C) {
90269025 return sema.failWithExpectedOptionalType(block, src, operand_ty);
90279026 }
90289027 // TODO https://github.com/ziglang/zig/issues/6597
90299028 if (true) break :t operand_ty;
9030 const ptr_info = operand_ty.ptrInfo(mod);
9029 const ptr_info = operand_ty.ptrInfo(zcu);
90319030 break :t try pt.ptrTypeSema(.{
90329031 .child = ptr_info.child,
90339032 .flags = .{
......@@ -9043,7 +9042,7 @@ fn zirOptionalPayload(
90439042 };
90449043
90459044 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
9046 return if (val.optionalValue(mod)) |payload|
9045 return if (val.optionalValue(zcu)) |payload|
90479046 Air.internedToRef(payload.toIntern())
90489047 else
90499048 sema.fail(block, src, "unable to unwrap null", .{});
......@@ -9067,13 +9066,13 @@ fn zirErrUnionPayload(
90679066 defer tracy.end();
90689067
90699068 const pt = sema.pt;
9070 const mod = pt.zcu;
9069 const zcu = pt.zcu;
90719070 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
90729071 const src = block.nodeOffset(inst_data.src_node);
90739072 const operand = try sema.resolveInst(inst_data.operand);
90749073 const operand_src = src;
90759074 const err_union_ty = sema.typeOf(operand);
9076 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
9075 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
90779076 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{
90789077 err_union_ty.fmt(pt),
90799078 });
......@@ -9091,20 +9090,20 @@ fn analyzeErrUnionPayload(
90919090 safety_check: bool,
90929091) CompileError!Air.Inst.Ref {
90939092 const pt = sema.pt;
9094 const mod = pt.zcu;
9095 const payload_ty = err_union_ty.errorUnionPayload(mod);
9093 const zcu = pt.zcu;
9094 const payload_ty = err_union_ty.errorUnionPayload(zcu);
90969095 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
9097 if (val.getErrorName(mod).unwrap()) |name| {
9096 if (val.getErrorName(zcu).unwrap()) |name| {
90989097 return sema.failWithComptimeErrorRetTrace(block, src, name);
90999098 }
9100 return Air.internedToRef(mod.intern_pool.indexToKey(val.toIntern()).error_union.val.payload);
9099 return Air.internedToRef(zcu.intern_pool.indexToKey(val.toIntern()).error_union.val.payload);
91019100 }
91029101
91039102 try sema.requireRuntimeBlock(block, src, null);
91049103
91059104 // If the error set has no fields then no safety check is needed.
91069105 if (safety_check and block.wantSafety() and
9107 !err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod))
9106 !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu))
91089107 {
91099108 try sema.panicUnwrapError(block, src, operand, .unwrap_errunion_err, .is_non_err);
91109109 }
......@@ -9215,20 +9214,20 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
92159214
92169215fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref) CompileError!Air.Inst.Ref {
92179216 const pt = sema.pt;
9218 const mod = pt.zcu;
9217 const zcu = pt.zcu;
92199218 const operand_ty = sema.typeOf(operand);
9220 if (operand_ty.zigTypeTag(mod) != .ErrorUnion) {
9219 if (operand_ty.zigTypeTag(zcu) != .ErrorUnion) {
92219220 return sema.fail(block, src, "expected error union type, found '{}'", .{
92229221 operand_ty.fmt(pt),
92239222 });
92249223 }
92259224
9226 const result_ty = operand_ty.errorUnionSet(mod);
9225 const result_ty = operand_ty.errorUnionSet(zcu);
92279226
92289227 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
92299228 return Air.internedToRef((try pt.intern(.{ .err = .{
92309229 .ty = result_ty.toIntern(),
9231 .name = mod.intern_pool.indexToKey(val.toIntern()).error_union.val.err_name,
9230 .name = zcu.intern_pool.indexToKey(val.toIntern()).error_union.val.err_name,
92329231 } })));
92339232 }
92349233
......@@ -9249,24 +9248,24 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
92499248
92509249fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref) CompileError!Air.Inst.Ref {
92519250 const pt = sema.pt;
9252 const mod = pt.zcu;
9251 const zcu = pt.zcu;
92539252 const operand_ty = sema.typeOf(operand);
9254 assert(operand_ty.zigTypeTag(mod) == .Pointer);
9253 assert(operand_ty.zigTypeTag(zcu) == .Pointer);
92559254
9256 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {
9255 if (operand_ty.childType(zcu).zigTypeTag(zcu) != .ErrorUnion) {
92579256 return sema.fail(block, src, "expected error union type, found '{}'", .{
9258 operand_ty.childType(mod).fmt(pt),
9257 operand_ty.childType(zcu).fmt(pt),
92599258 });
92609259 }
92619260
9262 const result_ty = operand_ty.childType(mod).errorUnionSet(mod);
9261 const result_ty = operand_ty.childType(zcu).errorUnionSet(zcu);
92639262
92649263 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
92659264 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {
9266 assert(val.getErrorName(mod) != .none);
9265 assert(val.getErrorName(zcu) != .none);
92679266 return Air.internedToRef((try pt.intern(.{ .err = .{
92689267 .ty = result_ty.toIntern(),
9269 .name = mod.intern_pool.indexToKey(val.toIntern()).error_union.val.err_name,
9268 .name = zcu.intern_pool.indexToKey(val.toIntern()).error_union.val.err_name,
92709269 } })));
92719270 }
92729271 }
......@@ -9412,7 +9411,7 @@ fn resolveGenericBody(
94129411/// and puts it there if it doesn't exist.
94139412/// It also dupes the library name which can then be saved as part of the
94149413/// respective `Decl` (either `ExternFn` or `Var`).
9415/// The liveness of the duped library name is tied to liveness of `Module`.
9414/// The liveness of the duped library name is tied to liveness of `Zcu`.
94169415/// To deallocate, call `deinit` on the respective `Decl` (`ExternFn` or `Var`).
94179416fn handleExternLibName(
94189417 sema: *Sema,
......@@ -9422,9 +9421,9 @@ fn handleExternLibName(
94229421) CompileError!void {
94239422 blk: {
94249423 const pt = sema.pt;
9425 const mod = pt.zcu;
9426 const comp = mod.comp;
9427 const target = mod.getTarget();
9424 const zcu = pt.zcu;
9425 const comp = zcu.comp;
9426 const target = zcu.getTarget();
94289427 log.debug("extern fn symbol expected in lib '{s}'", .{lib_name});
94299428 if (target.is_libc_lib_name(lib_name)) {
94309429 if (!comp.config.link_libc) {
......@@ -9575,7 +9574,7 @@ fn funcCommon(
95759574 .fn_proto_node_offset = src_node_offset,
95769575 .param_index = @intCast(i),
95779576 } });
9578 const requires_comptime = try sema.typeRequiresComptime(param_ty);
9577 const requires_comptime = try param_ty.comptimeOnlySema(pt);
95799578 if (param_is_comptime or requires_comptime) {
95809579 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error
95819580 }
......@@ -9631,7 +9630,7 @@ fn funcCommon(
96319630 const err_code_size = target.ptrBitWidth();
96329631 switch (i) {
96339632 0 => if (param_ty.zigTypeTag(zcu) != .Pointer) return sema.fail(block, param_src, "first parameter of function with 'Interrupt' calling convention must be a pointer type", .{}),
9634 1 => if (param_ty.bitSize(pt) != err_code_size) return sema.fail(block, param_src, "second parameter of function with 'Interrupt' calling convention must be a {d}-bit integer", .{err_code_size}),
9633 1 => if (param_ty.bitSize(zcu) != err_code_size) return sema.fail(block, param_src, "second parameter of function with 'Interrupt' calling convention must be a {d}-bit integer", .{err_code_size}),
96359634 else => return sema.fail(block, param_src, "'Interrupt' calling convention supports up to 2 parameters, found {d}", .{i + 1}),
96369635 }
96379636 } else return sema.fail(block, param_src, "parameters are not allowed with 'Interrupt' calling convention", .{}),
......@@ -9640,7 +9639,7 @@ fn funcCommon(
96409639 }
96419640 }
96429641
9643 const ret_ty_requires_comptime = try sema.typeRequiresComptime(bare_return_type);
9642 const ret_ty_requires_comptime = try bare_return_type.comptimeOnlySema(pt);
96449643 const ret_poison = bare_return_type.isGenericPoison();
96459644 const final_is_generic = is_generic or comptime_bits != 0 or ret_ty_requires_comptime;
96469645
......@@ -9881,18 +9880,18 @@ fn finishFunc(
98819880 final_is_generic: bool,
98829881) CompileError!Air.Inst.Ref {
98839882 const pt = sema.pt;
9884 const mod = pt.zcu;
9885 const ip = &mod.intern_pool;
9883 const zcu = pt.zcu;
9884 const ip = &zcu.intern_pool;
98869885 const gpa = sema.gpa;
9887 const target = mod.getTarget();
9886 const target = zcu.getTarget();
98889887
98899888 const return_type: Type = if (opt_func_index == .none or ret_poison)
98909889 bare_return_type
98919890 else
98929891 Type.fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));
98939892
9894 if (!return_type.isValidReturnType(mod)) {
9895 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";
9893 if (!return_type.isValidReturnType(zcu)) {
9894 const opaque_str = if (return_type.zigTypeTag(zcu) == .Opaque) "opaque " else "";
98969895 return sema.fail(block, ret_ty_src, "{s}return type '{}' not allowed", .{
98979896 opaque_str, return_type.fmt(pt),
98989897 });
......@@ -9954,7 +9953,7 @@ fn finishFunc(
99549953 }
99559954
99569955 switch (cc_resolved) {
9957 .Interrupt, .Signal => if (return_type.zigTypeTag(mod) != .Void and return_type.zigTypeTag(mod) != .NoReturn) {
9956 .Interrupt, .Signal => if (return_type.zigTypeTag(zcu) != .Void and return_type.zigTypeTag(zcu) != .NoReturn) {
99589957 return sema.fail(block, ret_ty_src, "function with calling convention '{s}' must return 'void' or 'noreturn'", .{@tagName(cc_resolved)});
99599958 },
99609959 .Inline => if (is_noinline) {
......@@ -10070,7 +10069,7 @@ fn zirParam(
1007010069 }
1007110070 };
1007210071
10073 const is_comptime = try sema.typeRequiresComptime(param_ty) or comptime_syntax;
10072 const is_comptime = try param_ty.comptimeOnlySema(sema.pt) or comptime_syntax;
1007410073
1007510074 try block.params.append(sema.arena, .{
1007610075 .ty = param_ty.toIntern(),
......@@ -10141,7 +10140,7 @@ fn analyzeAs(
1014110140 no_cast_to_comptime_int: bool,
1014210141) CompileError!Air.Inst.Ref {
1014310142 const pt = sema.pt;
10144 const mod = pt.zcu;
10143 const zcu = pt.zcu;
1014510144 const operand = try sema.resolveInst(zir_operand);
1014610145 const operand_air_inst = sema.resolveInst(zir_dest_type) catch |err| switch (err) {
1014710146 error.GenericPoison => return operand,
......@@ -10151,7 +10150,7 @@ fn analyzeAs(
1015110150 error.GenericPoison => return operand,
1015210151 else => |e| return e,
1015310152 };
10154 const dest_ty_tag = dest_ty.zigTypeTagOrPoison(mod) catch |err| switch (err) {
10153 const dest_ty_tag = dest_ty.zigTypeTagOrPoison(zcu) catch |err| switch (err) {
1015510154 error.GenericPoison => return operand,
1015610155 };
1015710156
......@@ -10189,7 +10188,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1018910188 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(pt)});
1019010189 }
1019110190 const pointee_ty = ptr_ty.childType(zcu);
10192 if (try sema.typeRequiresComptime(ptr_ty)) {
10191 if (try ptr_ty.comptimeOnlySema(pt)) {
1019310192 const msg = msg: {
1019410193 const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(pt)});
1019510194 errdefer msg.destroy(sema.gpa);
......@@ -10205,7 +10204,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1020510204 }
1020610205 return Air.internedToRef((try pt.intValue(
1020710206 Type.usize,
10208 (try operand_val.getUnsignedIntAdvanced(pt, .sema)).?,
10207 (try operand_val.toUnsignedIntSema(pt)),
1020910208 )).toIntern());
1021010209 }
1021110210 const len = operand_ty.vectorLen(zcu);
......@@ -10217,7 +10216,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1021710216 new_elem.* = (try pt.undefValue(Type.usize)).toIntern();
1021810217 continue;
1021910218 }
10220 const addr = try ptr_val.getUnsignedIntAdvanced(pt, .sema) orelse {
10219 const addr = try ptr_val.getUnsignedIntSema(pt) orelse {
1022110220 // A vector element wasn't an integer pointer. This is a runtime operation.
1022210221 break :ct;
1022310222 };
......@@ -10252,12 +10251,12 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1025210251 defer tracy.end();
1025310252
1025410253 const pt = sema.pt;
10255 const mod = pt.zcu;
10254 const zcu = pt.zcu;
1025610255 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1025710256 const src = block.nodeOffset(inst_data.src_node);
1025810257 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
1025910258 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10260 const field_name = try mod.intern_pool.getOrPutString(
10259 const field_name = try zcu.intern_pool.getOrPutString(
1026110260 sema.gpa,
1026210261 pt.tid,
1026310262 sema.code.nullTerminatedString(extra.field_name_start),
......@@ -10272,12 +10271,12 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1027210271 defer tracy.end();
1027310272
1027410273 const pt = sema.pt;
10275 const mod = pt.zcu;
10274 const zcu = pt.zcu;
1027610275 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1027710276 const src = block.nodeOffset(inst_data.src_node);
1027810277 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
1027910278 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10280 const field_name = try mod.intern_pool.getOrPutString(
10279 const field_name = try zcu.intern_pool.getOrPutString(
1028110280 sema.gpa,
1028210281 pt.tid,
1028310282 sema.code.nullTerminatedString(extra.field_name_start),
......@@ -10292,20 +10291,20 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
1029210291 defer tracy.end();
1029310292
1029410293 const pt = sema.pt;
10295 const mod = pt.zcu;
10294 const zcu = pt.zcu;
1029610295 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1029710296 const src = block.nodeOffset(inst_data.src_node);
1029810297 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
1029910298 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10300 const field_name = try mod.intern_pool.getOrPutString(
10299 const field_name = try zcu.intern_pool.getOrPutString(
1030110300 sema.gpa,
1030210301 pt.tid,
1030310302 sema.code.nullTerminatedString(extra.field_name_start),
1030410303 .no_embedded_nulls,
1030510304 );
1030610305 const object_ptr = try sema.resolveInst(extra.lhs);
10307 const struct_ty = sema.typeOf(object_ptr).childType(mod);
10308 switch (struct_ty.zigTypeTag(mod)) {
10306 const struct_ty = sema.typeOf(object_ptr).childType(zcu);
10307 switch (struct_ty.zigTypeTag(zcu)) {
1030910308 .Struct, .Union => {
1031010309 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, true);
1031110310 },
......@@ -10371,25 +10370,25 @@ fn intCast(
1037110370 runtime_safety: bool,
1037210371) CompileError!Air.Inst.Ref {
1037310372 const pt = sema.pt;
10374 const mod = pt.zcu;
10373 const zcu = pt.zcu;
1037510374 const operand_ty = sema.typeOf(operand);
1037610375 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, dest_ty_src);
1037710376 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
1037810377
1037910378 if (try sema.isComptimeKnown(operand)) {
1038010379 return sema.coerce(block, dest_ty, operand, operand_src);
10381 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
10380 } else if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
1038210381 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_int'", .{});
1038310382 }
1038410383
1038510384 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, dest_ty_src, operand_src);
10386 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
10385 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
1038710386
1038810387 if ((try sema.typeHasOnePossibleValue(dest_ty))) |opv| {
1038910388 // requirement: intCast(u0, input) iff input == 0
1039010389 if (runtime_safety and block.wantSafety()) {
1039110390 try sema.requireRuntimeBlock(block, src, operand_src);
10392 const wanted_info = dest_scalar_ty.intInfo(mod);
10391 const wanted_info = dest_scalar_ty.intInfo(zcu);
1039310392 const wanted_bits = wanted_info.bits;
1039410393
1039510394 if (wanted_bits == 0) {
......@@ -10416,8 +10415,8 @@ fn intCast(
1041610415
1041710416 try sema.requireRuntimeBlock(block, src, operand_src);
1041810417 if (runtime_safety and block.wantSafety()) {
10419 const actual_info = operand_scalar_ty.intInfo(mod);
10420 const wanted_info = dest_scalar_ty.intInfo(mod);
10418 const actual_info = operand_scalar_ty.intInfo(zcu);
10419 const wanted_info = dest_scalar_ty.intInfo(zcu);
1042110420 const actual_bits = actual_info.bits;
1042210421 const wanted_bits = wanted_info.bits;
1042310422 const actual_value_bits = actual_bits - @intFromBool(actual_info.signedness == .signed);
......@@ -10437,7 +10436,7 @@ fn intCast(
1043710436 // negative differences (`operand` > `dest_max`) appear too big.
1043810437 const unsigned_scalar_operand_ty = try pt.intType(.unsigned, actual_bits);
1043910438 const unsigned_operand_ty = if (is_vector) try pt.vectorType(.{
10440 .len = dest_ty.vectorLen(mod),
10439 .len = dest_ty.vectorLen(zcu),
1044110440 .child = unsigned_scalar_operand_ty.toIntern(),
1044210441 }) else unsigned_scalar_operand_ty;
1044310442 const diff_unsigned = try block.addBitCast(unsigned_operand_ty, diff);
......@@ -10520,7 +10519,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1052010519 defer tracy.end();
1052110520
1052210521 const pt = sema.pt;
10523 const mod = pt.zcu;
10522 const zcu = pt.zcu;
1052410523 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1052510524 const src = block.nodeOffset(inst_data.src_node);
1052610525 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -10529,7 +10528,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1052910528 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");
1053010529 const operand = try sema.resolveInst(extra.rhs);
1053110530 const operand_ty = sema.typeOf(operand);
10532 switch (dest_ty.zigTypeTag(mod)) {
10531 switch (dest_ty.zigTypeTag(zcu)) {
1053310532 .AnyFrame,
1053410533 .ComptimeFloat,
1053510534 .ComptimeInt,
......@@ -10551,7 +10550,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1055110550 const msg = msg: {
1055210551 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(pt)});
1055310552 errdefer msg.destroy(sema.gpa);
10554 switch (operand_ty.zigTypeTag(mod)) {
10553 switch (operand_ty.zigTypeTag(zcu)) {
1055510554 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(pt)}),
1055610555 else => {},
1055710556 }
......@@ -10565,7 +10564,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1056510564 const msg = msg: {
1056610565 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(pt)});
1056710566 errdefer msg.destroy(sema.gpa);
10568 switch (operand_ty.zigTypeTag(mod)) {
10567 switch (operand_ty.zigTypeTag(zcu)) {
1056910568 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(pt)}),
1057010569 .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(pt)}),
1057110570 else => {},
......@@ -10575,8 +10574,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1057510574 };
1057610575 return sema.failWithOwnedErrorMsg(block, msg);
1057710576 },
10578 .Struct, .Union => if (dest_ty.containerLayout(mod) == .auto) {
10579 const container = switch (dest_ty.zigTypeTag(mod)) {
10577 .Struct, .Union => if (dest_ty.containerLayout(zcu) == .auto) {
10578 const container = switch (dest_ty.zigTypeTag(zcu)) {
1058010579 .Struct => "struct",
1058110580 .Union => "union",
1058210581 else => unreachable,
......@@ -10593,7 +10592,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1059310592 .Vector,
1059410593 => {},
1059510594 }
10596 switch (operand_ty.zigTypeTag(mod)) {
10595 switch (operand_ty.zigTypeTag(zcu)) {
1059710596 .AnyFrame,
1059810597 .ComptimeFloat,
1059910598 .ComptimeInt,
......@@ -10615,7 +10614,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1061510614 const msg = msg: {
1061610615 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(pt)});
1061710616 errdefer msg.destroy(sema.gpa);
10618 switch (dest_ty.zigTypeTag(mod)) {
10617 switch (dest_ty.zigTypeTag(zcu)) {
1061910618 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(pt)}),
1062010619 else => {},
1062110620 }
......@@ -10628,7 +10627,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1062810627 const msg = msg: {
1062910628 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(pt)});
1063010629 errdefer msg.destroy(sema.gpa);
10631 switch (dest_ty.zigTypeTag(mod)) {
10630 switch (dest_ty.zigTypeTag(zcu)) {
1063210631 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(pt)}),
1063310632 .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(pt)}),
1063410633 else => {},
......@@ -10638,8 +10637,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1063810637 };
1063910638 return sema.failWithOwnedErrorMsg(block, msg);
1064010639 },
10641 .Struct, .Union => if (operand_ty.containerLayout(mod) == .auto) {
10642 const container = switch (operand_ty.zigTypeTag(mod)) {
10640 .Struct, .Union => if (operand_ty.containerLayout(zcu) == .auto) {
10641 const container = switch (operand_ty.zigTypeTag(zcu)) {
1064310642 .Struct => "struct",
1064410643 .Union => "union",
1064510644 else => unreachable,
......@@ -10664,24 +10663,24 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1066410663 defer tracy.end();
1066510664
1066610665 const pt = sema.pt;
10667 const mod = pt.zcu;
10666 const zcu = pt.zcu;
1066810667 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1066910668 const src = block.nodeOffset(inst_data.src_node);
1067010669 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1067110670 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1067210671
1067310672 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");
10674 const dest_scalar_ty = dest_ty.scalarType(mod);
10673 const dest_scalar_ty = dest_ty.scalarType(zcu);
1067510674
1067610675 const operand = try sema.resolveInst(extra.rhs);
1067710676 const operand_ty = sema.typeOf(operand);
10678 const operand_scalar_ty = operand_ty.scalarType(mod);
10677 const operand_scalar_ty = operand_ty.scalarType(zcu);
1067910678
1068010679 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);
10681 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
10680 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
1068210681
10683 const target = mod.getTarget();
10684 const dest_is_comptime_float = switch (dest_scalar_ty.zigTypeTag(mod)) {
10682 const target = zcu.getTarget();
10683 const dest_is_comptime_float = switch (dest_scalar_ty.zigTypeTag(zcu)) {
1068510684 .ComptimeFloat => true,
1068610685 .Float => false,
1068710686 else => return sema.fail(
......@@ -10692,7 +10691,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1069210691 ),
1069310692 };
1069410693
10695 switch (operand_scalar_ty.zigTypeTag(mod)) {
10694 switch (operand_scalar_ty.zigTypeTag(zcu)) {
1069610695 .ComptimeFloat, .Float, .ComptimeInt => {},
1069710696 else => return sema.fail(
1069810697 block,
......@@ -10706,7 +10705,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1070610705 if (!is_vector) {
1070710706 return Air.internedToRef((try operand_val.floatCast(dest_ty, pt)).toIntern());
1070810707 }
10709 const vec_len = operand_ty.vectorLen(mod);
10708 const vec_len = operand_ty.vectorLen(zcu);
1071010709 const new_elems = try sema.arena.alloc(InternPool.Index, vec_len);
1071110710 for (new_elems, 0..) |*new_elem, i| {
1071210711 const old_elem = try operand_val.elemValue(pt, i);
......@@ -10730,7 +10729,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1073010729 if (!is_vector) {
1073110730 return block.addTyOp(.fptrunc, dest_ty, operand);
1073210731 }
10733 const vec_len = operand_ty.vectorLen(mod);
10732 const vec_len = operand_ty.vectorLen(zcu);
1073410733 const new_elems = try sema.arena.alloc(Air.Inst.Ref, vec_len);
1073510734 for (new_elems, 0..) |*new_elem, i| {
1073610735 const idx_ref = try pt.intRef(Type.usize, i);
......@@ -10781,21 +10780,21 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1078110780 defer tracy.end();
1078210781
1078310782 const pt = sema.pt;
10784 const mod = pt.zcu;
10783 const zcu = pt.zcu;
1078510784 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1078610785 const src = block.nodeOffset(inst_data.src_node);
1078710786 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1078810787 const array_ptr = try sema.resolveInst(extra.lhs);
1078910788 const elem_index = try sema.resolveInst(extra.rhs);
1079010789 const indexable_ty = sema.typeOf(array_ptr);
10791 if (indexable_ty.zigTypeTag(mod) != .Pointer) {
10790 if (indexable_ty.zigTypeTag(zcu) != .Pointer) {
1079210791 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
1079310792 const msg = msg: {
1079410793 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{
1079510794 indexable_ty.fmt(pt),
1079610795 });
1079710796 errdefer msg.destroy(sema.gpa);
10798 if (indexable_ty.isIndexable(mod)) {
10797 if (indexable_ty.isIndexable(zcu)) {
1079910798 try sema.errNote(src, msg, "consider using '&' here", .{});
1080010799 }
1080110800 break :msg msg;
......@@ -10824,16 +10823,16 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
1082410823 defer tracy.end();
1082510824
1082610825 const pt = sema.pt;
10827 const mod = pt.zcu;
10826 const zcu = pt.zcu;
1082810827 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1082910828 const src = block.nodeOffset(inst_data.src_node);
1083010829 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
1083110830 const array_ptr = try sema.resolveInst(extra.ptr);
1083210831 const elem_index = try pt.intRef(Type.usize, extra.index);
10833 const array_ty = sema.typeOf(array_ptr).childType(mod);
10834 switch (array_ty.zigTypeTag(mod)) {
10832 const array_ty = sema.typeOf(array_ptr).childType(zcu);
10833 switch (array_ty.zigTypeTag(zcu)) {
1083510834 .Array, .Vector => {},
10836 else => if (!array_ty.isTuple(mod)) {
10835 else => if (!array_ty.isTuple(zcu)) {
1083710836 return sema.failWithArrayInitNotSupported(block, src, array_ty);
1083810837 },
1083910838 }
......@@ -11059,9 +11058,9 @@ const SwitchProngAnalysis = struct {
1105911058 ) CompileError!Air.Inst.Ref {
1106011059 const sema = spa.sema;
1106111060 const pt = sema.pt;
11062 const mod = pt.zcu;
11061 const zcu = pt.zcu;
1106311062 const operand_ty = sema.typeOf(spa.operand);
11064 if (operand_ty.zigTypeTag(mod) != .Union) {
11063 if (operand_ty.zigTypeTag(zcu) != .Union) {
1106511064 const tag_capture_src: LazySrcLoc = .{
1106611065 .base_node_inst = capture_src.base_node_inst,
1106711066 .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture },
......@@ -11429,9 +11428,9 @@ fn switchCond(
1142911428 operand: Air.Inst.Ref,
1143011429) CompileError!Air.Inst.Ref {
1143111430 const pt = sema.pt;
11432 const mod = pt.zcu;
11431 const zcu = pt.zcu;
1143311432 const operand_ty = sema.typeOf(operand);
11434 switch (operand_ty.zigTypeTag(mod)) {
11433 switch (operand_ty.zigTypeTag(zcu)) {
1143511434 .Type,
1143611435 .Void,
1143711436 .Bool,
......@@ -11445,7 +11444,7 @@ fn switchCond(
1144511444 .ErrorSet,
1144611445 .Enum,
1144711446 => {
11448 if (operand_ty.isSlice(mod)) {
11447 if (operand_ty.isSlice(zcu)) {
1144911448 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(pt)});
1145011449 }
1145111450 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {
......@@ -11456,11 +11455,11 @@ fn switchCond(
1145611455
1145711456 .Union => {
1145811457 try operand_ty.resolveFields(pt);
11459 const enum_ty = operand_ty.unionTagType(mod) orelse {
11458 const enum_ty = operand_ty.unionTagType(zcu) orelse {
1146011459 const msg = msg: {
1146111460 const msg = try sema.errMsg(src, "switch on union with no attached enum", .{});
1146211461 errdefer msg.destroy(sema.gpa);
11463 if (operand_ty.srcLocOrNull(mod)) |union_src| {
11462 if (operand_ty.srcLocOrNull(zcu)) |union_src| {
1146411463 try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{});
1146511464 }
1146611465 break :msg msg;
......@@ -11492,7 +11491,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1149211491 defer tracy.end();
1149311492
1149411493 const pt = sema.pt;
11495 const mod = pt.zcu;
11494 const zcu = pt.zcu;
1149611495 const gpa = sema.gpa;
1149711496 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1149811497 const switch_src = block.nodeOffset(inst_data.src_node);
......@@ -11577,17 +11576,17 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1157711576
1157811577 const operand_ty = sema.typeOf(raw_operand_val);
1157911578 const operand_err_set = if (extra.data.bits.payload_is_ref)
11580 operand_ty.childType(mod)
11579 operand_ty.childType(zcu)
1158111580 else
1158211581 operand_ty;
1158311582
11584 if (operand_err_set.zigTypeTag(mod) != .ErrorUnion) {
11583 if (operand_err_set.zigTypeTag(zcu) != .ErrorUnion) {
1158511584 return sema.fail(block, switch_src, "expected error union type, found '{}'", .{
1158611585 operand_ty.fmt(pt),
1158711586 });
1158811587 }
1158911588
11590 const operand_err_set_ty = operand_err_set.errorUnionSet(mod);
11589 const operand_err_set_ty = operand_err_set.errorUnionSet(zcu);
1159111590
1159211591 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
1159311592 try sema.air_instructions.append(gpa, .{
......@@ -11628,7 +11627,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1162811627 defer merges.deinit(gpa);
1162911628
1163011629 const resolved_err_set = try sema.resolveInferredErrorSetTy(block, main_src, operand_err_set_ty.toIntern());
11631 if (Type.fromInterned(resolved_err_set).errorSetIsEmpty(mod)) {
11630 if (Type.fromInterned(resolved_err_set).errorSetIsEmpty(zcu)) {
1163211631 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);
1163311632 }
1163411633
......@@ -11662,13 +11661,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1166211661 else
1166311662 ov;
1166411663
11665 if (operand_val.errorUnionIsPayload(mod)) {
11664 if (operand_val.errorUnionIsPayload(zcu)) {
1166611665 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);
1166711666 } else {
1166811667 const err_val = Value.fromInterned(try pt.intern(.{
1166911668 .err = .{
1167011669 .ty = operand_err_set_ty.toIntern(),
11671 .name = operand_val.getErrorName(mod).unwrap().?,
11670 .name = operand_val.getErrorName(zcu).unwrap().?,
1167211671 },
1167311672 }));
1167411673 spa.operand = if (extra.data.bits.payload_is_ref)
......@@ -11706,7 +11705,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1170611705 }
1170711706
1170811707 if (scalar_cases_len + multi_cases_len == 0) {
11709 if (else_error_ty) |ty| if (ty.errorSetIsEmpty(mod)) {
11708 if (else_error_ty) |ty| if (ty.errorSetIsEmpty(zcu)) {
1171011709 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);
1171111710 };
1171211711 }
......@@ -11720,7 +11719,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1172011719 }
1172111720
1172211721 const cond = if (extra.data.bits.payload_is_ref) blk: {
11723 try sema.checkErrorType(block, main_src, sema.typeOf(raw_operand_val).elemType2(mod));
11722 try sema.checkErrorType(block, main_src, sema.typeOf(raw_operand_val).elemType2(zcu));
1172411723 const loaded = try sema.analyzeLoad(block, main_src, raw_operand_val, main_src);
1172511724 break :blk try sema.analyzeIsNonErr(block, main_src, loaded);
1172611725 } else blk: {
......@@ -11803,7 +11802,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1180311802 defer tracy.end();
1180411803
1180511804 const pt = sema.pt;
11806 const mod = pt.zcu;
11805 const zcu = pt.zcu;
1180711806 const gpa = sema.gpa;
1180811807 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1180911808 const src = block.nodeOffset(inst_data.src_node);
......@@ -11873,12 +11872,12 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1187311872 };
1187411873
1187511874 const maybe_union_ty = sema.typeOf(raw_operand_val);
11876 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;
11875 const union_originally = maybe_union_ty.zigTypeTag(zcu) == .Union;
1187711876
1187811877 // Duplicate checking variables later also used for `inline else`.
1187911878 var seen_enum_fields: []?LazySrcLoc = &.{};
1188011879 var seen_errors = SwitchErrorSet.init(gpa);
11881 var range_set = RangeSet.init(gpa, pt);
11880 var range_set = RangeSet.init(gpa, zcu);
1188211881 var true_count: u8 = 0;
1188311882 var false_count: u8 = 0;
1188411883
......@@ -11891,12 +11890,12 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1189111890 var empty_enum = false;
1189211891
1189311892 const operand_ty = sema.typeOf(operand);
11894 const err_set = operand_ty.zigTypeTag(mod) == .ErrorSet;
11893 const err_set = operand_ty.zigTypeTag(zcu) == .ErrorSet;
1189511894
1189611895 var else_error_ty: ?Type = null;
1189711896
1189811897 // Validate usage of '_' prongs.
11899 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) {
11898 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(zcu) or union_originally)) {
1190011899 const msg = msg: {
1190111900 const msg = try sema.errMsg(
1190211901 src,
......@@ -11922,11 +11921,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1192211921 }
1192311922
1192411923 // Validate for duplicate items, missing else prong, and invalid range.
11925 switch (operand_ty.zigTypeTag(mod)) {
11924 switch (operand_ty.zigTypeTag(zcu)) {
1192611925 .Union => unreachable, // handled in `switchCond`
1192711926 .Enum => {
11928 seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(mod));
11929 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);
11927 seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(zcu));
11928 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(zcu);
1193011929 @memset(seen_enum_fields, null);
1193111930 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
1193211931
......@@ -11989,7 +11988,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1198911988 } else true;
1199011989
1199111990 if (special_prong == .@"else") {
11992 if (all_tags_handled and !operand_ty.isNonexhaustiveEnum(mod)) return sema.fail(
11991 if (all_tags_handled and !operand_ty.isNonexhaustiveEnum(zcu)) return sema.fail(
1199311992 block,
1199411993 special_prong_src,
1199511994 "unreachable else prong; all cases already handled",
......@@ -12006,17 +12005,17 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1200612005 for (seen_enum_fields, 0..) |seen_src, i| {
1200712006 if (seen_src != null) continue;
1200812007
12009 const field_name = operand_ty.enumFieldName(i, mod);
12008 const field_name = operand_ty.enumFieldName(i, zcu);
1201012009 try sema.addFieldErrNote(
1201112010 operand_ty,
1201212011 i,
1201312012 msg,
1201412013 "unhandled enumeration value: '{}'",
12015 .{field_name.fmt(&mod.intern_pool)},
12014 .{field_name.fmt(&zcu.intern_pool)},
1201612015 );
1201712016 }
1201812017 try sema.errNote(
12019 operand_ty.srcLoc(mod),
12018 operand_ty.srcLoc(zcu),
1202012019 msg,
1202112020 "enum '{}' declared here",
1202212021 .{operand_ty.fmt(pt)},
......@@ -12024,7 +12023,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1202412023 break :msg msg;
1202512024 };
1202612025 return sema.failWithOwnedErrorMsg(block, msg);
12027 } else if (special_prong == .none and operand_ty.isNonexhaustiveEnum(mod) and !union_originally) {
12026 } else if (special_prong == .none and operand_ty.isNonexhaustiveEnum(zcu) and !union_originally) {
1202812027 return sema.fail(
1202912028 block,
1203012029 src,
......@@ -12124,7 +12123,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1212412123 }
1212512124
1212612125 check_range: {
12127 if (operand_ty.zigTypeTag(mod) == .Int) {
12126 if (operand_ty.zigTypeTag(zcu) == .Int) {
1212812127 const min_int = try operand_ty.minInt(pt, operand_ty);
1212912128 const max_int = try operand_ty.maxInt(pt, operand_ty);
1213012129 if (try range_set.spans(min_int.toIntern(), max_int.toIntern())) {
......@@ -12388,8 +12387,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1238812387 if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src, false)) {
1238912388 return .unreachable_value;
1239012389 }
12391 if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and
12392 (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))
12390 if (zcu.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(zcu) == .Enum and
12391 (!operand_ty.isNonexhaustiveEnum(zcu) or union_originally))
1239312392 {
1239412393 try sema.zirDbgStmt(block, cond_dbg_node_index);
1239512394 const ok = try block.addUnOp(.is_named_enum_value, operand);
......@@ -12482,9 +12481,9 @@ fn analyzeSwitchRuntimeBlock(
1248212481 allow_err_code_unwrap: bool,
1248312482) CompileError!Air.Inst.Ref {
1248412483 const pt = sema.pt;
12485 const mod = pt.zcu;
12484 const zcu = pt.zcu;
1248612485 const gpa = sema.gpa;
12487 const ip = &mod.intern_pool;
12486 const ip = &zcu.intern_pool;
1248812487
1248912488 const block = child_block.parent.?;
1249012489
......@@ -12519,8 +12518,8 @@ fn analyzeSwitchRuntimeBlock(
1251912518 const analyze_body = if (union_originally) blk: {
1252012519 const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1252112520 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
12522 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12523 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
12521 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12522 break :blk field_ty.zigTypeTag(zcu) != .NoReturn;
1252412523 } else true;
1252512524
1252612525 if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src, allow_err_code_unwrap)) {
......@@ -12592,7 +12591,7 @@ fn analyzeSwitchRuntimeBlock(
1259212591 var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable;
1259312592 const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable;
1259412593
12595 while (item.compareScalar(.lte, item_last, operand_ty, pt)) : ({
12594 while (item.compareScalar(.lte, item_last, operand_ty, zcu)) : ({
1259612595 // Previous validation has resolved any possible lazy values.
1259712596 item = sema.intAddScalar(item, try pt.intValue(operand_ty, 1), operand_ty) catch |err| switch (err) {
1259812597 error.Overflow => unreachable,
......@@ -12633,7 +12632,7 @@ fn analyzeSwitchRuntimeBlock(
1263312632 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1263412633 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
1263512634
12636 if (item.compareScalar(.eq, item_last, operand_ty, pt)) break;
12635 if (item.compareScalar(.eq, item_last, operand_ty, zcu)) break;
1263712636 }
1263812637 }
1263912638
......@@ -12645,8 +12644,8 @@ fn analyzeSwitchRuntimeBlock(
1264512644
1264612645 const analyze_body = if (union_originally) blk: {
1264712646 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12648 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12649 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
12647 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12648 break :blk field_ty.zigTypeTag(zcu) != .NoReturn;
1265012649 } else true;
1265112650
1265212651 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
......@@ -12696,8 +12695,8 @@ fn analyzeSwitchRuntimeBlock(
1269612695 const analyze_body = if (union_originally)
1269712696 for (items) |item| {
1269812697 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12699 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12700 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
12698 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12699 if (field_ty.zigTypeTag(zcu) != .NoReturn) break true;
1270112700 } else false
1270212701 else
1270312702 true;
......@@ -12836,9 +12835,9 @@ fn analyzeSwitchRuntimeBlock(
1283612835 var final_else_body: []const Air.Inst.Index = &.{};
1283712836 if (special.body.len != 0 or !is_first or case_block.wantSafety()) {
1283812837 var emit_bb = false;
12839 if (special.is_inline) switch (operand_ty.zigTypeTag(mod)) {
12838 if (special.is_inline) switch (operand_ty.zigTypeTag(zcu)) {
1284012839 .Enum => {
12841 if (operand_ty.isNonexhaustiveEnum(mod) and !union_originally) {
12840 if (operand_ty.isNonexhaustiveEnum(zcu) and !union_originally) {
1284212841 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
1284312842 operand_ty.fmt(pt),
1284412843 });
......@@ -12854,8 +12853,8 @@ fn analyzeSwitchRuntimeBlock(
1285412853 case_block.error_return_trace_index = child_block.error_return_trace_index;
1285512854
1285612855 const analyze_body = if (union_originally) blk: {
12857 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12858 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
12856 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12857 break :blk field_ty.zigTypeTag(zcu) != .NoReturn;
1285912858 } else true;
1286012859
1286112860 if (emit_bb) try sema.emitBackwardBranch(block, special_prong_src);
......@@ -12887,12 +12886,12 @@ fn analyzeSwitchRuntimeBlock(
1288712886 }
1288812887 },
1288912888 .ErrorSet => {
12890 if (operand_ty.isAnyError(mod)) {
12889 if (operand_ty.isAnyError(zcu)) {
1289112890 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
1289212891 operand_ty.fmt(pt),
1289312892 });
1289412893 }
12895 const error_names = operand_ty.errorSetNames(mod);
12894 const error_names = operand_ty.errorSetNames(zcu);
1289612895 for (0..error_names.len) |name_index| {
1289712896 const error_name = error_names.get(ip)[name_index];
1289812897 if (seen_errors.contains(error_name)) continue;
......@@ -13033,10 +13032,10 @@ fn analyzeSwitchRuntimeBlock(
1303313032 case_block.instructions.shrinkRetainingCapacity(0);
1303413033 case_block.error_return_trace_index = child_block.error_return_trace_index;
1303513034
13036 if (mod.backendSupportsFeature(.is_named_enum_value) and
13035 if (zcu.backendSupportsFeature(.is_named_enum_value) and
1303713036 special.body.len != 0 and block.wantSafety() and
13038 operand_ty.zigTypeTag(mod) == .Enum and
13039 (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))
13037 operand_ty.zigTypeTag(zcu) == .Enum and
13038 (!operand_ty.isNonexhaustiveEnum(zcu) or union_originally))
1304013039 {
1304113040 try sema.zirDbgStmt(&case_block, cond_dbg_node_index);
1304213041 const ok = try case_block.addUnOp(.is_named_enum_value, operand);
......@@ -13046,9 +13045,9 @@ fn analyzeSwitchRuntimeBlock(
1304613045 const analyze_body = if (union_originally and !special.is_inline)
1304713046 for (seen_enum_fields, 0..) |seen_field, index| {
1304813047 if (seen_field != null) continue;
13049 const union_obj = mod.typeToUnion(maybe_union_ty).?;
13048 const union_obj = zcu.typeToUnion(maybe_union_ty).?;
1305013049 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[index]);
13051 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
13050 if (field_ty.zigTypeTag(zcu) != .NoReturn) break true;
1305213051 } else false
1305313052 else
1305413053 true;
......@@ -13371,8 +13370,8 @@ fn validateErrSetSwitch(
1337113370) CompileError!?Type {
1337213371 const gpa = sema.gpa;
1337313372 const pt = sema.pt;
13374 const mod = pt.zcu;
13375 const ip = &mod.intern_pool;
13373 const zcu = pt.zcu;
13374 const ip = &zcu.intern_pool;
1337613375
1337713376 const src_node_offset = inst_data.src_node;
1337813377 const src = block.nodeOffset(src_node_offset);
......@@ -13444,7 +13443,7 @@ fn validateErrSetSwitch(
1344413443 },
1344513444 else => |err_set_ty_index| else_validation: {
1344613445 const error_names = ip.indexToKey(err_set_ty_index).error_set_type.names;
13447 var maybe_msg: ?*Module.ErrorMsg = null;
13446 var maybe_msg: ?*Zcu.ErrorMsg = null;
1344813447 errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa);
1344913448
1345013449 for (error_names.get(ip)) |error_name| {
......@@ -13711,8 +13710,8 @@ fn maybeErrorUnwrap(
1371113710 allow_err_code_inst: bool,
1371213711) !bool {
1371313712 const pt = sema.pt;
13714 const mod = pt.zcu;
13715 if (!mod.backendSupportsFeature(.panic_unwrap_error)) return false;
13713 const zcu = pt.zcu;
13714 if (!zcu.backendSupportsFeature(.panic_unwrap_error)) return false;
1371613715
1371713716 const tags = sema.code.instructions.items(.tag);
1371813717 for (body) |inst| {
......@@ -13745,7 +13744,7 @@ fn maybeErrorUnwrap(
1374513744 .as_node => try sema.zirAsNode(block, inst),
1374613745 .field_val => try sema.zirFieldVal(block, inst),
1374713746 .@"unreachable" => {
13748 if (!mod.comp.formatted_panics) {
13747 if (!zcu.comp.formatted_panics) {
1374913748 try sema.safetyPanic(block, operand_src, .unwrap_error);
1375013749 return true;
1375113750 }
......@@ -13768,7 +13767,7 @@ fn maybeErrorUnwrap(
1376813767 },
1376913768 else => unreachable,
1377013769 };
13771 if (sema.typeOf(air_inst).isNoReturn(mod))
13770 if (sema.typeOf(air_inst).isNoReturn(zcu))
1377213771 return true;
1377313772 sema.inst_map.putAssumeCapacity(inst, air_inst);
1377413773 }
......@@ -13777,20 +13776,20 @@ fn maybeErrorUnwrap(
1377713776
1377813777fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void {
1377913778 const pt = sema.pt;
13780 const mod = pt.zcu;
13779 const zcu = pt.zcu;
1378113780 const index = cond.toIndex() orelse return;
1378213781 if (sema.code.instructions.items(.tag)[@intFromEnum(index)] != .is_non_err) return;
1378313782
1378413783 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;
1378513784 const err_operand = try sema.resolveInst(err_inst_data.operand);
1378613785 const operand_ty = sema.typeOf(err_operand);
13787 if (operand_ty.zigTypeTag(mod) == .ErrorSet) {
13786 if (operand_ty.zigTypeTag(zcu) == .ErrorSet) {
1378813787 try sema.maybeErrorUnwrapComptime(block, body, err_operand);
1378913788 return;
1379013789 }
1379113790 if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| {
13792 if (!operand_ty.isError(mod)) return;
13793 if (val.getErrorName(mod) == .none) return;
13791 if (!operand_ty.isError(zcu)) return;
13792 if (val.getErrorName(zcu) == .none) return;
1379413793 try sema.maybeErrorUnwrapComptime(block, body, err_operand);
1379513794 }
1379613795}
......@@ -13818,7 +13817,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
1381813817
1381913818fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1382013819 const pt = sema.pt;
13821 const mod = pt.zcu;
13820 const zcu = pt.zcu;
1382213821 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1382313822 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1382413823 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -13828,7 +13827,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1382813827 .needed_comptime_reason = "field name must be comptime-known",
1382913828 });
1383013829 try ty.resolveFields(pt);
13831 const ip = &mod.intern_pool;
13830 const ip = &zcu.intern_pool;
1383213831
1383313832 const has_field = hf: {
1383413833 switch (ip.indexToKey(ty.toIntern())) {
......@@ -13845,7 +13844,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1384513844 break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names.get(ip), field_name) != null;
1384613845 } else {
1384713846 const field_index = field_name.toUnsigned(ip) orelse break :hf false;
13848 break :hf field_index < ty.structFieldCount(mod);
13847 break :hf field_index < ty.structFieldCount(zcu);
1384913848 }
1385013849 },
1385113850 .struct_type => {
......@@ -13870,7 +13869,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1387013869
1387113870fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1387213871 const pt = sema.pt;
13873 const mod = pt.zcu;
13872 const zcu = pt.zcu;
1387413873 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1387513874 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1387613875 const src = block.nodeOffset(inst_data.src_node);
......@@ -13883,7 +13882,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1388313882
1388413883 try sema.checkNamespaceType(block, lhs_src, container_type);
1388513884
13886 const namespace = container_type.getNamespace(mod).unwrap() orelse return .bool_false;
13885 const namespace = container_type.getNamespace(zcu).unwrap() orelse return .bool_false;
1388713886 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| {
1388813887 if (lookup.accessible) {
1388913888 return .bool_true;
......@@ -13958,9 +13957,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1395813957
1395913958fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1396013959 const pt = sema.pt;
13961 const mod = pt.zcu;
13960 const zcu = pt.zcu;
1396213961 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
13963 const name = try mod.intern_pool.getOrPutString(
13962 const name = try zcu.intern_pool.getOrPutString(
1396413963 sema.gpa,
1396513964 pt.tid,
1396613965 inst_data.get(sema.code),
......@@ -13984,7 +13983,7 @@ fn zirShl(
1398413983 defer tracy.end();
1398513984
1398613985 const pt = sema.pt;
13987 const mod = pt.zcu;
13986 const zcu = pt.zcu;
1398813987 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1398913988 const src = block.nodeOffset(inst_data.src_node);
1399013989 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -13996,8 +13995,8 @@ fn zirShl(
1399613995 const rhs_ty = sema.typeOf(rhs);
1399713996 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1399813997
13999 const scalar_ty = lhs_ty.scalarType(mod);
14000 const scalar_rhs_ty = rhs_ty.scalarType(mod);
13998 const scalar_ty = lhs_ty.scalarType(zcu);
13999 const scalar_rhs_ty = rhs_ty.scalarType(zcu);
1400114000
1400214001 // TODO coerce rhs if air_tag is not shl_sat
1400314002 const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty);
......@@ -14006,20 +14005,20 @@ fn zirShl(
1400614005 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1400714006
1400814007 if (maybe_rhs_val) |rhs_val| {
14009 if (rhs_val.isUndef(mod)) {
14008 if (rhs_val.isUndef(zcu)) {
1401014009 return pt.undefRef(sema.typeOf(lhs));
1401114010 }
1401214011 // If rhs is 0, return lhs without doing any calculations.
1401314012 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
1401414013 return lhs;
1401514014 }
14016 if (scalar_ty.zigTypeTag(mod) != .ComptimeInt and air_tag != .shl_sat) {
14017 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(mod).bits);
14018 if (rhs_ty.zigTypeTag(mod) == .Vector) {
14015 if (scalar_ty.zigTypeTag(zcu) != .ComptimeInt and air_tag != .shl_sat) {
14016 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(zcu).bits);
14017 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
1401914018 var i: usize = 0;
14020 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
14019 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
1402114020 const rhs_elem = try rhs_val.elemValue(pt, i);
14022 if (rhs_elem.compareHetero(.gte, bit_value, pt)) {
14021 if (rhs_elem.compareHetero(.gte, bit_value, zcu)) {
1402314022 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
1402414023 rhs_elem.fmtValueSema(pt, sema),
1402514024 i,
......@@ -14027,25 +14026,25 @@ fn zirShl(
1402714026 });
1402814027 }
1402914028 }
14030 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {
14029 } else if (rhs_val.compareHetero(.gte, bit_value, zcu)) {
1403114030 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
1403214031 rhs_val.fmtValueSema(pt, sema),
1403314032 scalar_ty.fmt(pt),
1403414033 });
1403514034 }
1403614035 }
14037 if (rhs_ty.zigTypeTag(mod) == .Vector) {
14036 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
1403814037 var i: usize = 0;
14039 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
14038 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
1404014039 const rhs_elem = try rhs_val.elemValue(pt, i);
14041 if (rhs_elem.compareHetero(.lt, try pt.intValue(scalar_rhs_ty, 0), pt)) {
14040 if (rhs_elem.compareHetero(.lt, try pt.intValue(scalar_rhs_ty, 0), zcu)) {
1404214041 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
1404314042 rhs_elem.fmtValueSema(pt, sema),
1404414043 i,
1404514044 });
1404614045 }
1404714046 }
14048 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) {
14047 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), zcu)) {
1404914048 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
1405014049 rhs_val.fmtValueSema(pt, sema),
1405114050 });
......@@ -14053,19 +14052,19 @@ fn zirShl(
1405314052 }
1405414053
1405514054 const runtime_src = if (maybe_lhs_val) |lhs_val| rs: {
14056 if (lhs_val.isUndef(mod)) return pt.undefRef(lhs_ty);
14055 if (lhs_val.isUndef(zcu)) return pt.undefRef(lhs_ty);
1405714056 const rhs_val = maybe_rhs_val orelse {
14058 if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
14057 if (scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
1405914058 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
1406014059 }
1406114060 break :rs rhs_src;
1406214061 };
14063 const val = if (scalar_ty.zigTypeTag(mod) == .ComptimeInt)
14062 const val = if (scalar_ty.zigTypeTag(zcu) == .ComptimeInt)
1406414063 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, pt)
1406514064 else switch (air_tag) {
1406614065 .shl_exact => val: {
1406714066 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, pt);
14068 if (shifted.overflow_bit.compareAllWithZero(.eq, pt)) {
14067 if (shifted.overflow_bit.compareAllWithZero(.eq, zcu)) {
1406914068 break :val shifted.wrapped_result;
1407014069 }
1407114070 return sema.fail(block, src, "operation caused overflow", .{});
......@@ -14080,7 +14079,7 @@ fn zirShl(
1408014079 const new_rhs = if (air_tag == .shl_sat) rhs: {
1408114080 // Limit the RHS type for saturating shl to be an integer as small as the LHS.
1408214081 if (rhs_is_comptime_int or
14083 scalar_rhs_ty.intInfo(mod).bits > scalar_ty.intInfo(mod).bits)
14082 scalar_rhs_ty.intInfo(zcu).bits > scalar_ty.intInfo(zcu).bits)
1408414083 {
1408514084 const max_int = Air.internedToRef((try lhs_ty.maxInt(pt, lhs_ty)).toIntern());
1408614085 const rhs_limited = try sema.analyzeMinMax(block, rhs_src, .min, &.{ rhs, max_int }, &.{ rhs_src, rhs_src });
......@@ -14092,10 +14091,10 @@ fn zirShl(
1409214091
1409314092 try sema.requireRuntimeBlock(block, src, runtime_src);
1409414093 if (block.wantSafety()) {
14095 const bit_count = scalar_ty.intInfo(mod).bits;
14094 const bit_count = scalar_ty.intInfo(zcu).bits;
1409614095 if (!std.math.isPowerOfTwo(bit_count)) {
1409714096 const bit_count_val = try pt.intValue(scalar_rhs_ty, bit_count);
14098 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {
14097 const ok = if (rhs_ty.zigTypeTag(zcu) == .Vector) ok: {
1409914098 const bit_count_inst = Air.internedToRef((try sema.splat(rhs_ty, bit_count_val)).toIntern());
1410014099 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);
1410114100 break :ok try block.addInst(.{
......@@ -14125,7 +14124,7 @@ fn zirShl(
1412514124 } },
1412614125 });
1412714126 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);
14128 const any_ov_bit = if (lhs_ty.zigTypeTag(mod) == .Vector)
14127 const any_ov_bit = if (lhs_ty.zigTypeTag(zcu) == .Vector)
1412914128 try block.addInst(.{
1413014129 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
1413114130 .data = .{ .reduce = .{
......@@ -14155,7 +14154,7 @@ fn zirShr(
1415514154 defer tracy.end();
1415614155
1415714156 const pt = sema.pt;
14158 const mod = pt.zcu;
14157 const zcu = pt.zcu;
1415914158 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1416014159 const src = block.nodeOffset(inst_data.src_node);
1416114160 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -14166,26 +14165,26 @@ fn zirShr(
1416614165 const lhs_ty = sema.typeOf(lhs);
1416714166 const rhs_ty = sema.typeOf(rhs);
1416814167 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
14169 const scalar_ty = lhs_ty.scalarType(mod);
14168 const scalar_ty = lhs_ty.scalarType(zcu);
1417014169
1417114170 const maybe_lhs_val = try sema.resolveValueIntable(lhs);
1417214171 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1417314172
1417414173 const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {
14175 if (rhs_val.isUndef(mod)) {
14174 if (rhs_val.isUndef(zcu)) {
1417614175 return pt.undefRef(lhs_ty);
1417714176 }
1417814177 // If rhs is 0, return lhs without doing any calculations.
1417914178 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
1418014179 return lhs;
1418114180 }
14182 if (scalar_ty.zigTypeTag(mod) != .ComptimeInt) {
14183 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(mod).bits);
14184 if (rhs_ty.zigTypeTag(mod) == .Vector) {
14181 if (scalar_ty.zigTypeTag(zcu) != .ComptimeInt) {
14182 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(zcu).bits);
14183 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
1418514184 var i: usize = 0;
14186 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
14185 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
1418714186 const rhs_elem = try rhs_val.elemValue(pt, i);
14188 if (rhs_elem.compareHetero(.gte, bit_value, pt)) {
14187 if (rhs_elem.compareHetero(.gte, bit_value, zcu)) {
1418914188 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
1419014189 rhs_elem.fmtValueSema(pt, sema),
1419114190 i,
......@@ -14193,31 +14192,31 @@ fn zirShr(
1419314192 });
1419414193 }
1419514194 }
14196 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {
14195 } else if (rhs_val.compareHetero(.gte, bit_value, zcu)) {
1419714196 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
1419814197 rhs_val.fmtValueSema(pt, sema),
1419914198 scalar_ty.fmt(pt),
1420014199 });
1420114200 }
1420214201 }
14203 if (rhs_ty.zigTypeTag(mod) == .Vector) {
14202 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
1420414203 var i: usize = 0;
14205 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
14204 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
1420614205 const rhs_elem = try rhs_val.elemValue(pt, i);
14207 if (rhs_elem.compareHetero(.lt, try pt.intValue(rhs_ty.childType(mod), 0), pt)) {
14206 if (rhs_elem.compareHetero(.lt, try pt.intValue(rhs_ty.childType(zcu), 0), zcu)) {
1420814207 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
1420914208 rhs_elem.fmtValueSema(pt, sema),
1421014209 i,
1421114210 });
1421214211 }
1421314212 }
14214 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), pt)) {
14213 } else if (rhs_val.compareHetero(.lt, try pt.intValue(rhs_ty, 0), zcu)) {
1421514214 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
1421614215 rhs_val.fmtValueSema(pt, sema),
1421714216 });
1421814217 }
1421914218 if (maybe_lhs_val) |lhs_val| {
14220 if (lhs_val.isUndef(mod)) {
14219 if (lhs_val.isUndef(zcu)) {
1422114220 return pt.undefRef(lhs_ty);
1422214221 }
1422314222 if (air_tag == .shr_exact) {
......@@ -14234,18 +14233,18 @@ fn zirShr(
1423414233 }
1423514234 } else rhs_src;
1423614235
14237 if (maybe_rhs_val == null and scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
14236 if (maybe_rhs_val == null and scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
1423814237 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
1423914238 }
1424014239
1424114240 try sema.requireRuntimeBlock(block, src, runtime_src);
1424214241 const result = try block.addBinOp(air_tag, lhs, rhs);
1424314242 if (block.wantSafety()) {
14244 const bit_count = scalar_ty.intInfo(mod).bits;
14243 const bit_count = scalar_ty.intInfo(zcu).bits;
1424514244 if (!std.math.isPowerOfTwo(bit_count)) {
14246 const bit_count_val = try pt.intValue(rhs_ty.scalarType(mod), bit_count);
14245 const bit_count_val = try pt.intValue(rhs_ty.scalarType(zcu), bit_count);
1424714246
14248 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {
14247 const ok = if (rhs_ty.zigTypeTag(zcu) == .Vector) ok: {
1424914248 const bit_count_inst = Air.internedToRef((try sema.splat(rhs_ty, bit_count_val)).toIntern());
1425014249 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);
1425114250 break :ok try block.addInst(.{
......@@ -14265,7 +14264,7 @@ fn zirShr(
1426514264 if (air_tag == .shr_exact) {
1426614265 const back = try block.addBinOp(.shl, result, rhs);
1426714266
14268 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {
14267 const ok = if (rhs_ty.zigTypeTag(zcu) == .Vector) ok: {
1426914268 const eql = try block.addCmpVector(lhs, back, .eq);
1427014269 break :ok try block.addInst(.{
1427114270 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
......@@ -14291,7 +14290,7 @@ fn zirBitwise(
1429114290 defer tracy.end();
1429214291
1429314292 const pt = sema.pt;
14294 const mod = pt.zcu;
14293 const zcu = pt.zcu;
1429514294 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1429614295 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1429714296 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -14305,8 +14304,8 @@ fn zirBitwise(
1430514304
1430614305 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
1430714306 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
14308 const scalar_type = resolved_type.scalarType(mod);
14309 const scalar_tag = scalar_type.zigTypeTag(mod);
14307 const scalar_type = resolved_type.scalarType(zcu);
14308 const scalar_tag = scalar_type.zigTypeTag(zcu);
1431014309
1431114310 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1431214311 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
......@@ -14314,7 +14313,7 @@ fn zirBitwise(
1431414313 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1431514314
1431614315 if (!is_int) {
14317 return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag(mod)), @tagName(rhs_ty.zigTypeTag(mod)) });
14316 return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag(zcu)), @tagName(rhs_ty.zigTypeTag(zcu)) });
1431814317 }
1431914318
1432014319 const runtime_src = runtime: {
......@@ -14346,26 +14345,26 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1434614345 defer tracy.end();
1434714346
1434814347 const pt = sema.pt;
14349 const mod = pt.zcu;
14348 const zcu = pt.zcu;
1435014349 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1435114350 const src = block.nodeOffset(inst_data.src_node);
1435214351 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1435314352
1435414353 const operand = try sema.resolveInst(inst_data.operand);
1435514354 const operand_type = sema.typeOf(operand);
14356 const scalar_type = operand_type.scalarType(mod);
14355 const scalar_type = operand_type.scalarType(zcu);
1435714356
14358 if (scalar_type.zigTypeTag(mod) != .Int) {
14357 if (scalar_type.zigTypeTag(zcu) != .Int) {
1435914358 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{
1436014359 operand_type.fmt(pt),
1436114360 });
1436214361 }
1436314362
1436414363 if (try sema.resolveValue(operand)) |val| {
14365 if (val.isUndef(mod)) {
14364 if (val.isUndef(zcu)) {
1436614365 return pt.undefRef(operand_type);
14367 } else if (operand_type.zigTypeTag(mod) == .Vector) {
14368 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));
14366 } else if (operand_type.zigTypeTag(zcu) == .Vector) {
14367 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(zcu));
1436914368 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
1437014369 for (elems, 0..) |*elem, i| {
1437114370 const elem_val = try val.elemValue(pt, i);
......@@ -14393,13 +14392,13 @@ fn analyzeTupleCat(
1439314392 rhs: Air.Inst.Ref,
1439414393) CompileError!Air.Inst.Ref {
1439514394 const pt = sema.pt;
14396 const mod = pt.zcu;
14395 const zcu = pt.zcu;
1439714396 const lhs_ty = sema.typeOf(lhs);
1439814397 const rhs_ty = sema.typeOf(rhs);
1439914398 const src = block.nodeOffset(src_node);
1440014399
14401 const lhs_len = lhs_ty.structFieldCount(mod);
14402 const rhs_len = rhs_ty.structFieldCount(mod);
14400 const lhs_len = lhs_ty.structFieldCount(zcu);
14401 const rhs_len = rhs_ty.structFieldCount(zcu);
1440314402 const dest_fields = lhs_len + rhs_len;
1440414403
1440514404 if (dest_fields == 0) {
......@@ -14420,8 +14419,8 @@ fn analyzeTupleCat(
1442014419 var runtime_src: ?LazySrcLoc = null;
1442114420 var i: u32 = 0;
1442214421 while (i < lhs_len) : (i += 1) {
14423 types[i] = lhs_ty.structFieldType(i, mod).toIntern();
14424 const default_val = lhs_ty.structFieldDefaultValue(i, mod);
14422 types[i] = lhs_ty.structFieldType(i, zcu).toIntern();
14423 const default_val = lhs_ty.structFieldDefaultValue(i, zcu);
1442514424 values[i] = default_val.toIntern();
1442614425 const operand_src = block.src(.{ .array_cat_lhs = .{
1442714426 .array_cat_offset = src_node,
......@@ -14434,8 +14433,8 @@ fn analyzeTupleCat(
1443414433 }
1443514434 i = 0;
1443614435 while (i < rhs_len) : (i += 1) {
14437 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();
14438 const default_val = rhs_ty.structFieldDefaultValue(i, mod);
14436 types[i + lhs_len] = rhs_ty.structFieldType(i, zcu).toIntern();
14437 const default_val = rhs_ty.structFieldDefaultValue(i, zcu);
1443914438 values[i + lhs_len] = default_val.toIntern();
1444014439 const operand_src = block.src(.{ .array_cat_rhs = .{
1444114440 .array_cat_offset = src_node,
......@@ -14449,7 +14448,7 @@ fn analyzeTupleCat(
1444914448 break :rs runtime_src;
1445014449 };
1445114450
14452 const tuple_ty = try mod.intern_pool.getAnonStructType(mod.gpa, pt.tid, .{
14451 const tuple_ty = try zcu.intern_pool.getAnonStructType(zcu.gpa, pt.tid, .{
1445314452 .types = types,
1445414453 .values = values,
1445514454 .names = &.{},
......@@ -14492,7 +14491,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1449214491 defer tracy.end();
1449314492
1449414493 const pt = sema.pt;
14495 const mod = pt.zcu;
14494 const zcu = pt.zcu;
1449614495 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1449714496 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1449814497 const lhs = try sema.resolveInst(extra.lhs);
......@@ -14501,8 +14500,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1450114500 const rhs_ty = sema.typeOf(rhs);
1450214501 const src = block.nodeOffset(inst_data.src_node);
1450314502
14504 const lhs_is_tuple = lhs_ty.isTuple(mod);
14505 const rhs_is_tuple = rhs_ty.isTuple(mod);
14503 const lhs_is_tuple = lhs_ty.isTuple(zcu);
14504 const rhs_is_tuple = rhs_ty.isTuple(zcu);
1450614505 if (lhs_is_tuple and rhs_is_tuple) {
1450714506 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);
1450814507 }
......@@ -14584,31 +14583,31 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1458414583 .child = resolved_elem_ty.toIntern(),
1458514584 });
1458614585 const ptr_addrspace = p: {
14587 if (lhs_ty.zigTypeTag(mod) == .Pointer) break :p lhs_ty.ptrAddressSpace(mod);
14588 if (rhs_ty.zigTypeTag(mod) == .Pointer) break :p rhs_ty.ptrAddressSpace(mod);
14586 if (lhs_ty.zigTypeTag(zcu) == .Pointer) break :p lhs_ty.ptrAddressSpace(zcu);
14587 if (rhs_ty.zigTypeTag(zcu) == .Pointer) break :p rhs_ty.ptrAddressSpace(zcu);
1458914588 break :p null;
1459014589 };
1459114590
14592 const runtime_src = if (switch (lhs_ty.zigTypeTag(mod)) {
14591 const runtime_src = if (switch (lhs_ty.zigTypeTag(zcu)) {
1459314592 .Array, .Struct => try sema.resolveValue(lhs),
1459414593 .Pointer => try sema.resolveDefinedValue(block, lhs_src, lhs),
1459514594 else => unreachable,
1459614595 }) |lhs_val| rs: {
14597 if (switch (rhs_ty.zigTypeTag(mod)) {
14596 if (switch (rhs_ty.zigTypeTag(zcu)) {
1459814597 .Array, .Struct => try sema.resolveValue(rhs),
1459914598 .Pointer => try sema.resolveDefinedValue(block, rhs_src, rhs),
1460014599 else => unreachable,
1460114600 }) |rhs_val| {
14602 const lhs_sub_val = if (lhs_ty.isSinglePointer(mod))
14601 const lhs_sub_val = if (lhs_ty.isSinglePointer(zcu))
1460314602 try sema.pointerDeref(block, lhs_src, lhs_val, lhs_ty) orelse break :rs lhs_src
14604 else if (lhs_ty.isSlice(mod))
14603 else if (lhs_ty.isSlice(zcu))
1460514604 try sema.maybeDerefSliceAsArray(block, lhs_src, lhs_val) orelse break :rs lhs_src
1460614605 else
1460714606 lhs_val;
1460814607
14609 const rhs_sub_val = if (rhs_ty.isSinglePointer(mod))
14608 const rhs_sub_val = if (rhs_ty.isSinglePointer(zcu))
1461014609 try sema.pointerDeref(block, rhs_src, rhs_val, rhs_ty) orelse break :rs rhs_src
14611 else if (rhs_ty.isSlice(mod))
14610 else if (rhs_ty.isSlice(zcu))
1461214611 try sema.maybeDerefSliceAsArray(block, rhs_src, rhs_val) orelse break :rs rhs_src
1461314612 else
1461414613 rhs_val;
......@@ -14617,7 +14616,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1461714616 var elem_i: u32 = 0;
1461814617 while (elem_i < lhs_len) : (elem_i += 1) {
1461914618 const lhs_elem_i = elem_i;
14620 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";
14619 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, zcu) else Value.@"unreachable";
1462114620 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(pt, lhs_elem_i) else elem_default_val;
1462214621 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1462314622 const operand_src = block.src(.{ .array_cat_lhs = .{
......@@ -14630,7 +14629,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1463014629 }
1463114630 while (elem_i < result_len) : (elem_i += 1) {
1463214631 const rhs_elem_i = elem_i - lhs_len;
14633 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";
14632 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, zcu) else Value.@"unreachable";
1463414633 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(pt, rhs_elem_i) else elem_default_val;
1463514634 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1463614635 const operand_src = block.src(.{ .array_cat_rhs = .{
......@@ -14723,12 +14722,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1472314722
1472414723fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref, peer_ty: Type) !?Type.ArrayInfo {
1472514724 const pt = sema.pt;
14726 const mod = pt.zcu;
14725 const zcu = pt.zcu;
1472714726 const operand_ty = sema.typeOf(operand);
14728 switch (operand_ty.zigTypeTag(mod)) {
14729 .Array => return operand_ty.arrayInfo(mod),
14727 switch (operand_ty.zigTypeTag(zcu)) {
14728 .Array => return operand_ty.arrayInfo(zcu),
1473014729 .Pointer => {
14731 const ptr_info = operand_ty.ptrInfo(mod);
14730 const ptr_info = operand_ty.ptrInfo(zcu);
1473214731 switch (ptr_info.flags.size) {
1473314732 .Slice => {
1473414733 const val = try sema.resolveConstDefinedValue(block, src, operand, .{
......@@ -14744,20 +14743,20 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1474414743 };
1474514744 },
1474614745 .One => {
14747 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
14748 return Type.fromInterned(ptr_info.child).arrayInfo(mod);
14746 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Array) {
14747 return Type.fromInterned(ptr_info.child).arrayInfo(zcu);
1474914748 }
1475014749 },
1475114750 .C, .Many => {},
1475214751 }
1475314752 },
1475414753 .Struct => {
14755 if (operand_ty.isTuple(mod) and peer_ty.isIndexable(mod)) {
14756 assert(!peer_ty.isTuple(mod));
14754 if (operand_ty.isTuple(zcu) and peer_ty.isIndexable(zcu)) {
14755 assert(!peer_ty.isTuple(zcu));
1475714756 return .{
14758 .elem_type = peer_ty.elemType2(mod),
14757 .elem_type = peer_ty.elemType2(zcu),
1475914758 .sentinel = null,
14760 .len = operand_ty.arrayLen(mod),
14759 .len = operand_ty.arrayLen(zcu),
1476114760 };
1476214761 }
1476314762 },
......@@ -14774,12 +14773,12 @@ fn analyzeTupleMul(
1477414773 factor: usize,
1477514774) CompileError!Air.Inst.Ref {
1477614775 const pt = sema.pt;
14777 const mod = pt.zcu;
14776 const zcu = pt.zcu;
1477814777 const operand_ty = sema.typeOf(operand);
1477914778 const src = block.nodeOffset(src_node);
1478014779 const len_src = block.src(.{ .node_offset_bin_rhs = src_node });
1478114780
14782 const tuple_len = operand_ty.structFieldCount(mod);
14781 const tuple_len = operand_ty.structFieldCount(zcu);
1478314782 const final_len = std.math.mul(usize, tuple_len, factor) catch
1478414783 return sema.fail(block, len_src, "operation results in overflow", .{});
1478514784
......@@ -14792,8 +14791,8 @@ fn analyzeTupleMul(
1479214791 const opt_runtime_src = rs: {
1479314792 var runtime_src: ?LazySrcLoc = null;
1479414793 for (0..tuple_len) |i| {
14795 types[i] = operand_ty.structFieldType(i, mod).toIntern();
14796 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();
14794 types[i] = operand_ty.structFieldType(i, zcu).toIntern();
14795 values[i] = operand_ty.structFieldDefaultValue(i, zcu).toIntern();
1479714796 const operand_src = block.src(.{ .array_cat_lhs = .{
1479814797 .array_cat_offset = src_node,
1479914798 .elem_index = @intCast(i),
......@@ -14810,7 +14809,7 @@ fn analyzeTupleMul(
1481014809 break :rs runtime_src;
1481114810 };
1481214811
14813 const tuple_ty = try mod.intern_pool.getAnonStructType(mod.gpa, pt.tid, .{
14812 const tuple_ty = try zcu.intern_pool.getAnonStructType(zcu.gpa, pt.tid, .{
1481414813 .types = types,
1481514814 .values = values,
1481614815 .names = &.{},
......@@ -14848,7 +14847,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1484814847 defer tracy.end();
1484914848
1485014849 const pt = sema.pt;
14851 const mod = pt.zcu;
14850 const zcu = pt.zcu;
1485214851 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1485314852 const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;
1485414853 const uncoerced_lhs = try sema.resolveInst(extra.lhs);
......@@ -14867,17 +14866,17 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1486714866 const res_ty_inst = try sema.resolveInst(extra.res_ty);
1486814867 const res_ty = try sema.analyzeAsType(block, src, res_ty_inst);
1486914868 if (res_ty.isGenericPoison()) break :no_coerce;
14870 if (!uncoerced_lhs_ty.isTuple(mod)) break :no_coerce;
14871 const lhs_len = uncoerced_lhs_ty.structFieldCount(mod);
14872 const lhs_dest_ty = switch (res_ty.zigTypeTag(mod)) {
14869 if (!uncoerced_lhs_ty.isTuple(zcu)) break :no_coerce;
14870 const lhs_len = uncoerced_lhs_ty.structFieldCount(zcu);
14871 const lhs_dest_ty = switch (res_ty.zigTypeTag(zcu)) {
1487314872 else => break :no_coerce,
1487414873 .Array => try pt.arrayType(.{
14875 .child = res_ty.childType(mod).toIntern(),
14874 .child = res_ty.childType(zcu).toIntern(),
1487614875 .len = lhs_len,
14877 .sentinel = if (res_ty.sentinel(mod)) |s| s.toIntern() else .none,
14876 .sentinel = if (res_ty.sentinel(zcu)) |s| s.toIntern() else .none,
1487814877 }),
1487914878 .Vector => try pt.vectorType(.{
14880 .child = res_ty.childType(mod).toIntern(),
14879 .child = res_ty.childType(zcu).toIntern(),
1488114880 .len = lhs_len,
1488214881 }),
1488314882 };
......@@ -14893,7 +14892,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1489314892 break :coerced_lhs .{ uncoerced_lhs, uncoerced_lhs_ty };
1489414893 };
1489514894
14896 if (lhs_ty.isTuple(mod)) {
14895 if (lhs_ty.isTuple(zcu)) {
1489714896 // In `**` rhs must be comptime-known, but lhs can be runtime-known
1489814897 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{
1489914898 .needed_comptime_reason = "array multiplication factor must be comptime-known",
......@@ -14907,7 +14906,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1490714906 const msg = msg: {
1490814907 const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(pt)});
1490914908 errdefer msg.destroy(sema.gpa);
14910 switch (lhs_ty.zigTypeTag(mod)) {
14909 switch (lhs_ty.zigTypeTag(zcu)) {
1491114910 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {
1491214911 try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});
1491314912 },
......@@ -14933,13 +14932,13 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1493314932 .child = lhs_info.elem_type.toIntern(),
1493414933 });
1493514934
14936 const ptr_addrspace = if (lhs_ty.zigTypeTag(mod) == .Pointer) lhs_ty.ptrAddressSpace(mod) else null;
14935 const ptr_addrspace = if (lhs_ty.zigTypeTag(zcu) == .Pointer) lhs_ty.ptrAddressSpace(zcu) else null;
1493714936 const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len);
1493814937
1493914938 if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| ct: {
14940 const lhs_sub_val = if (lhs_ty.isSinglePointer(mod))
14939 const lhs_sub_val = if (lhs_ty.isSinglePointer(zcu))
1494114940 try sema.pointerDeref(block, lhs_src, lhs_val, lhs_ty) orelse break :ct
14942 else if (lhs_ty.isSlice(mod))
14941 else if (lhs_ty.isSlice(zcu))
1494314942 try sema.maybeDerefSliceAsArray(block, lhs_src, lhs_val) orelse break :ct
1494414943 else
1494514944 lhs_val;
......@@ -15022,7 +15021,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1502215021
1502315022fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1502415023 const pt = sema.pt;
15025 const mod = pt.zcu;
15024 const zcu = pt.zcu;
1502615025 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1502715026 const src = block.nodeOffset(inst_data.src_node);
1502815027 const lhs_src = src;
......@@ -15030,9 +15029,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1503015029
1503115030 const rhs = try sema.resolveInst(inst_data.operand);
1503215031 const rhs_ty = sema.typeOf(rhs);
15033 const rhs_scalar_ty = rhs_ty.scalarType(mod);
15032 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
1503415033
15035 if (rhs_scalar_ty.isUnsignedInt(mod) or switch (rhs_scalar_ty.zigTypeTag(mod)) {
15034 if (rhs_scalar_ty.isUnsignedInt(zcu) or switch (rhs_scalar_ty.zigTypeTag(zcu)) {
1503615035 .Int, .ComptimeInt, .Float, .ComptimeFloat => false,
1503715036 else => true,
1503815037 }) {
......@@ -15042,7 +15041,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1504215041 if (rhs_scalar_ty.isAnyFloat()) {
1504315042 // We handle float negation here to ensure negative zero is represented in the bits.
1504415043 if (try sema.resolveValue(rhs)) |rhs_val| {
15045 if (rhs_val.isUndef(mod)) return pt.undefRef(rhs_ty);
15044 if (rhs_val.isUndef(zcu)) return pt.undefRef(rhs_ty);
1504615045 return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, pt)).toIntern());
1504715046 }
1504815047 try sema.requireRuntimeBlock(block, src, null);
......@@ -15055,7 +15054,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1505515054
1505615055fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1505715056 const pt = sema.pt;
15058 const mod = pt.zcu;
15057 const zcu = pt.zcu;
1505915058 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1506015059 const src = block.nodeOffset(inst_data.src_node);
1506115060 const lhs_src = src;
......@@ -15063,9 +15062,9 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1506315062
1506415063 const rhs = try sema.resolveInst(inst_data.operand);
1506515064 const rhs_ty = sema.typeOf(rhs);
15066 const rhs_scalar_ty = rhs_ty.scalarType(mod);
15065 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
1506715066
15068 switch (rhs_scalar_ty.zigTypeTag(mod)) {
15067 switch (rhs_scalar_ty.zigTypeTag(zcu)) {
1506915068 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},
1507015069 else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(pt)}),
1507115070 }
......@@ -15097,7 +15096,7 @@ fn zirArithmetic(
1509715096
1509815097fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1509915098 const pt = sema.pt;
15100 const mod = pt.zcu;
15099 const zcu = pt.zcu;
1510115100 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1510215101 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1510315102 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -15107,8 +15106,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1510715106 const rhs = try sema.resolveInst(extra.rhs);
1510815107 const lhs_ty = sema.typeOf(lhs);
1510915108 const rhs_ty = sema.typeOf(rhs);
15110 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
15111 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
15109 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15110 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1511215111 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1511315112 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1511415113
......@@ -15120,9 +15119,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1512015119 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1512115120 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1512215121
15123 const lhs_scalar_ty = lhs_ty.scalarType(mod);
15124 const rhs_scalar_ty = rhs_ty.scalarType(mod);
15125 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);
15122 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15123 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15124 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1512615125
1512715126 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1512815127
......@@ -15131,15 +15130,15 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1513115130 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
1513215131 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1513315132
15134 if ((lhs_ty.zigTypeTag(mod) == .ComptimeFloat and rhs_ty.zigTypeTag(mod) == .ComptimeInt) or
15135 (lhs_ty.zigTypeTag(mod) == .ComptimeInt and rhs_ty.zigTypeTag(mod) == .ComptimeFloat))
15133 if ((lhs_ty.zigTypeTag(zcu) == .ComptimeFloat and rhs_ty.zigTypeTag(zcu) == .ComptimeInt) or
15134 (lhs_ty.zigTypeTag(zcu) == .ComptimeInt and rhs_ty.zigTypeTag(zcu) == .ComptimeFloat))
1513615135 {
1513715136 // If it makes a difference whether we coerce to ints or floats before doing the division, error.
1513815137 // If lhs % rhs is 0, it doesn't matter.
1513915138 const lhs_val = maybe_lhs_val orelse unreachable;
1514015139 const rhs_val = maybe_rhs_val orelse unreachable;
1514115140 const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, pt) catch unreachable;
15142 if (!rem.compareAllWithZero(.eq, pt)) {
15141 if (!rem.compareAllWithZero(.eq, zcu)) {
1514315142 return sema.fail(
1514415143 block,
1514515144 src,
......@@ -15179,11 +15178,11 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1517915178 switch (scalar_tag) {
1518015179 .Int, .ComptimeInt, .ComptimeFloat => {
1518115180 if (maybe_lhs_val) |lhs_val| {
15182 if (!lhs_val.isUndef(mod)) {
15181 if (!lhs_val.isUndef(zcu)) {
1518315182 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1518415183 const scalar_zero = switch (scalar_tag) {
15185 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),
15186 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),
15184 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15185 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
1518715186 else => unreachable,
1518815187 };
1518915188 const zero_val = try sema.splat(resolved_type, scalar_zero);
......@@ -15192,7 +15191,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1519215191 }
1519315192 }
1519415193 if (maybe_rhs_val) |rhs_val| {
15195 if (rhs_val.isUndef(mod)) {
15194 if (rhs_val.isUndef(zcu)) {
1519615195 return sema.failWithUseOfUndef(block, rhs_src);
1519715196 }
1519815197 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -15206,8 +15205,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1520615205
1520715206 const runtime_src = rs: {
1520815207 if (maybe_lhs_val) |lhs_val| {
15209 if (lhs_val.isUndef(mod)) {
15210 if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) {
15208 if (lhs_val.isUndef(zcu)) {
15209 if (lhs_scalar_ty.isSignedInt(zcu) and rhs_scalar_ty.isSignedInt(zcu)) {
1521115210 if (maybe_rhs_val) |rhs_val| {
1521215211 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {
1521315212 return pt.undefRef(resolved_type);
......@@ -15245,7 +15244,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1524515244 }
1524615245
1524715246 const air_tag = if (is_int) blk: {
15248 if (lhs_ty.isSignedInt(mod) or rhs_ty.isSignedInt(mod)) {
15247 if (lhs_ty.isSignedInt(zcu) or rhs_ty.isSignedInt(zcu)) {
1524915248 return sema.fail(
1525015249 block,
1525115250 src,
......@@ -15263,7 +15262,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1526315262
1526415263fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1526515264 const pt = sema.pt;
15266 const mod = pt.zcu;
15265 const zcu = pt.zcu;
1526715266 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1526815267 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1526915268 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -15273,8 +15272,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1527315272 const rhs = try sema.resolveInst(extra.rhs);
1527415273 const lhs_ty = sema.typeOf(lhs);
1527515274 const rhs_ty = sema.typeOf(rhs);
15276 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
15277 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
15275 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15276 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1527815277 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1527915278 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1528015279
......@@ -15286,8 +15285,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1528615285 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1528715286 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1528815287
15289 const lhs_scalar_ty = lhs_ty.scalarType(mod);
15290 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);
15288 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15289 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1529115290
1529215291 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1529315292
......@@ -15314,13 +15313,13 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1531415313 // If the lhs is undefined, compile error because there is a possible
1531515314 // value for which the division would result in a remainder.
1531615315 if (maybe_lhs_val) |lhs_val| {
15317 if (lhs_val.isUndef(mod)) {
15316 if (lhs_val.isUndef(zcu)) {
1531815317 return sema.failWithUseOfUndef(block, rhs_src);
1531915318 } else {
1532015319 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1532115320 const scalar_zero = switch (scalar_tag) {
15322 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),
15323 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),
15321 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15322 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
1532415323 else => unreachable,
1532515324 };
1532615325 const zero_val = try sema.splat(resolved_type, scalar_zero);
......@@ -15329,7 +15328,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1532915328 }
1533015329 }
1533115330 if (maybe_rhs_val) |rhs_val| {
15332 if (rhs_val.isUndef(mod)) {
15331 if (rhs_val.isUndef(zcu)) {
1533315332 return sema.failWithUseOfUndef(block, rhs_src);
1533415333 }
1533515334 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -15341,7 +15340,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1534115340 if (maybe_rhs_val) |rhs_val| {
1534215341 if (is_int) {
1534315342 const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, pt);
15344 if (!(modulus_val.compareAllWithZero(.eq, pt))) {
15343 if (!(modulus_val.compareAllWithZero(.eq, zcu))) {
1534515344 return sema.fail(block, src, "exact division produced remainder", .{});
1534615345 }
1534715346 var overflow_idx: ?usize = null;
......@@ -15352,7 +15351,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1535215351 return Air.internedToRef(res.toIntern());
1535315352 } else {
1535415353 const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, pt);
15355 if (!(modulus_val.compareAllWithZero(.eq, pt))) {
15354 if (!(modulus_val.compareAllWithZero(.eq, zcu))) {
1535615355 return sema.fail(block, src, "exact division produced remainder", .{});
1535715356 }
1535815357 return Air.internedToRef((try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, pt)).toIntern());
......@@ -15376,7 +15375,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1537615375 const ok = if (!is_int) ok: {
1537715376 const floored = try block.addUnOp(.floor, result);
1537815377
15379 if (resolved_type.zigTypeTag(mod) == .Vector) {
15378 if (resolved_type.zigTypeTag(zcu) == .Vector) {
1538015379 const eql = try block.addCmpVector(result, floored, .eq);
1538115380 break :ok try block.addInst(.{
1538215381 .tag = switch (block.float_mode) {
......@@ -15399,11 +15398,11 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1539915398 const remainder = try block.addBinOp(.rem, casted_lhs, casted_rhs);
1540015399
1540115400 const scalar_zero = switch (scalar_tag) {
15402 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),
15403 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),
15401 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15402 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
1540415403 else => unreachable,
1540515404 };
15406 if (resolved_type.zigTypeTag(mod) == .Vector) {
15405 if (resolved_type.zigTypeTag(zcu) == .Vector) {
1540715406 const zero_val = try sema.splat(resolved_type, scalar_zero);
1540815407 const zero = Air.internedToRef(zero_val.toIntern());
1540915408 const eql = try block.addCmpVector(remainder, zero, .eq);
......@@ -15429,7 +15428,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1542915428
1543015429fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1543115430 const pt = sema.pt;
15432 const mod = pt.zcu;
15431 const zcu = pt.zcu;
1543315432 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1543415433 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1543515434 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -15439,8 +15438,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1543915438 const rhs = try sema.resolveInst(extra.rhs);
1544015439 const lhs_ty = sema.typeOf(lhs);
1544115440 const rhs_ty = sema.typeOf(rhs);
15442 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
15443 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
15441 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15442 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1544415443 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1544515444 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1544615445
......@@ -15452,9 +15451,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1545215451 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1545315452 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1545415453
15455 const lhs_scalar_ty = lhs_ty.scalarType(mod);
15456 const rhs_scalar_ty = rhs_ty.scalarType(mod);
15457 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);
15454 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15455 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15456 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1545815457
1545915458 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1546015459
......@@ -15484,11 +15483,11 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1548415483 // value (zero) for which the division would be illegal behavior.
1548515484 // If the lhs is undefined, result is undefined.
1548615485 if (maybe_lhs_val) |lhs_val| {
15487 if (!lhs_val.isUndef(mod)) {
15486 if (!lhs_val.isUndef(zcu)) {
1548815487 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1548915488 const scalar_zero = switch (scalar_tag) {
15490 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),
15491 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),
15489 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15490 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
1549215491 else => unreachable,
1549315492 };
1549415493 const zero_val = try sema.splat(resolved_type, scalar_zero);
......@@ -15497,7 +15496,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1549715496 }
1549815497 }
1549915498 if (maybe_rhs_val) |rhs_val| {
15500 if (rhs_val.isUndef(mod)) {
15499 if (rhs_val.isUndef(zcu)) {
1550115500 return sema.failWithUseOfUndef(block, rhs_src);
1550215501 }
1550315502 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -15506,8 +15505,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1550615505 // TODO: if the RHS is one, return the LHS directly
1550715506 }
1550815507 if (maybe_lhs_val) |lhs_val| {
15509 if (lhs_val.isUndef(mod)) {
15510 if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) {
15508 if (lhs_val.isUndef(zcu)) {
15509 if (lhs_scalar_ty.isSignedInt(zcu) and rhs_scalar_ty.isSignedInt(zcu)) {
1551115510 if (maybe_rhs_val) |rhs_val| {
1551215511 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {
1551315512 return pt.undefRef(resolved_type);
......@@ -15540,7 +15539,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1554015539
1554115540fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1554215541 const pt = sema.pt;
15543 const mod = pt.zcu;
15542 const zcu = pt.zcu;
1554415543 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1554515544 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1554615545 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -15550,8 +15549,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1555015549 const rhs = try sema.resolveInst(extra.rhs);
1555115550 const lhs_ty = sema.typeOf(lhs);
1555215551 const rhs_ty = sema.typeOf(rhs);
15553 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
15554 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
15552 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15553 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1555515554 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1555615555 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1555715556
......@@ -15563,9 +15562,9 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1556315562 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1556415563 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1556515564
15566 const lhs_scalar_ty = lhs_ty.scalarType(mod);
15567 const rhs_scalar_ty = rhs_ty.scalarType(mod);
15568 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);
15565 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15566 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15567 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1556915568
1557015569 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1557115570
......@@ -15595,11 +15594,11 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1559515594 // value (zero) for which the division would be illegal behavior.
1559615595 // If the lhs is undefined, result is undefined.
1559715596 if (maybe_lhs_val) |lhs_val| {
15598 if (!lhs_val.isUndef(mod)) {
15597 if (!lhs_val.isUndef(zcu)) {
1559915598 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1560015599 const scalar_zero = switch (scalar_tag) {
15601 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),
15602 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),
15600 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15601 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
1560315602 else => unreachable,
1560415603 };
1560515604 const zero_val = try sema.splat(resolved_type, scalar_zero);
......@@ -15608,7 +15607,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1560815607 }
1560915608 }
1561015609 if (maybe_rhs_val) |rhs_val| {
15611 if (rhs_val.isUndef(mod)) {
15610 if (rhs_val.isUndef(zcu)) {
1561215611 return sema.failWithUseOfUndef(block, rhs_src);
1561315612 }
1561415613 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -15616,8 +15615,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1561615615 }
1561715616 }
1561815617 if (maybe_lhs_val) |lhs_val| {
15619 if (lhs_val.isUndef(mod)) {
15620 if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) {
15618 if (lhs_val.isUndef(zcu)) {
15619 if (lhs_scalar_ty.isSignedInt(zcu) and rhs_scalar_ty.isSignedInt(zcu)) {
1562115620 if (maybe_rhs_val) |rhs_val| {
1562215621 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {
1562315622 return pt.undefRef(resolved_type);
......@@ -15666,14 +15665,14 @@ fn addDivIntOverflowSafety(
1566615665 is_int: bool,
1566715666) CompileError!void {
1566815667 const pt = sema.pt;
15669 const mod = pt.zcu;
15668 const zcu = pt.zcu;
1567015669 if (!is_int) return;
1567115670
1567215671 // If the LHS is unsigned, it cannot cause overflow.
15673 if (!lhs_scalar_ty.isSignedInt(mod)) return;
15672 if (!lhs_scalar_ty.isSignedInt(zcu)) return;
1567415673
1567515674 // If the LHS is widened to a larger integer type, no overflow is possible.
15676 if (lhs_scalar_ty.intInfo(mod).bits < resolved_type.intInfo(mod).bits) {
15675 if (lhs_scalar_ty.intInfo(zcu).bits < resolved_type.intInfo(zcu).bits) {
1567715676 return;
1567815677 }
1567915678
......@@ -15693,7 +15692,7 @@ fn addDivIntOverflowSafety(
1569315692 }
1569415693
1569515694 var ok: Air.Inst.Ref = .none;
15696 if (resolved_type.zigTypeTag(mod) == .Vector) {
15695 if (resolved_type.zigTypeTag(zcu) == .Vector) {
1569715696 if (maybe_lhs_val == null) {
1569815697 const min_int_ref = Air.internedToRef(min_int.toIntern());
1569915698 ok = try block.addCmpVector(casted_lhs, min_int_ref, .neq);
......@@ -15751,12 +15750,12 @@ fn addDivByZeroSafety(
1575115750 if (maybe_rhs_val != null) return;
1575215751
1575315752 const pt = sema.pt;
15754 const mod = pt.zcu;
15753 const zcu = pt.zcu;
1575515754 const scalar_zero = if (is_int)
15756 try pt.intValue(resolved_type.scalarType(mod), 0)
15755 try pt.intValue(resolved_type.scalarType(zcu), 0)
1575715756 else
15758 try pt.floatValue(resolved_type.scalarType(mod), 0.0);
15759 const ok = if (resolved_type.zigTypeTag(mod) == .Vector) ok: {
15757 try pt.floatValue(resolved_type.scalarType(zcu), 0.0);
15758 const ok = if (resolved_type.zigTypeTag(zcu) == .Vector) ok: {
1576015759 const zero_val = try sema.splat(resolved_type, scalar_zero);
1576115760 const zero = Air.internedToRef(zero_val.toIntern());
1576215761 const ok = try block.addCmpVector(casted_rhs, zero, .neq);
......@@ -15784,7 +15783,7 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst
1578415783
1578515784fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1578615785 const pt = sema.pt;
15787 const mod = pt.zcu;
15786 const zcu = pt.zcu;
1578815787 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1578915788 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1579015789 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -15794,8 +15793,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1579415793 const rhs = try sema.resolveInst(extra.rhs);
1579515794 const lhs_ty = sema.typeOf(lhs);
1579615795 const rhs_ty = sema.typeOf(rhs);
15797 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
15798 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
15796 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15797 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1579915798 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1580015799 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1580115800
......@@ -15804,14 +15803,14 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1580415803 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },
1580515804 });
1580615805
15807 const is_vector = resolved_type.zigTypeTag(mod) == .Vector;
15806 const is_vector = resolved_type.zigTypeTag(zcu) == .Vector;
1580815807
1580915808 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1581015809 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1581115810
15812 const lhs_scalar_ty = lhs_ty.scalarType(mod);
15813 const rhs_scalar_ty = rhs_ty.scalarType(mod);
15814 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);
15811 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15812 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15813 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1581515814
1581615815 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1581715816
......@@ -15836,13 +15835,13 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1583615835 // then emit a compile error saying you have to pick one.
1583715836 if (is_int) {
1583815837 if (maybe_lhs_val) |lhs_val| {
15839 if (lhs_val.isUndef(mod)) {
15838 if (lhs_val.isUndef(zcu)) {
1584015839 return sema.failWithUseOfUndef(block, lhs_src);
1584115840 }
1584215841 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1584315842 const scalar_zero = switch (scalar_tag) {
15844 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),
15845 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),
15843 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15844 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
1584615845 else => unreachable,
1584715846 };
1584815847 const zero_val = if (is_vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
......@@ -15851,11 +15850,11 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1585115850 } })) else scalar_zero;
1585215851 return Air.internedToRef(zero_val.toIntern());
1585315852 }
15854 } else if (lhs_scalar_ty.isSignedInt(mod)) {
15853 } else if (lhs_scalar_ty.isSignedInt(zcu)) {
1585515854 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
1585615855 }
1585715856 if (maybe_rhs_val) |rhs_val| {
15858 if (rhs_val.isUndef(mod)) {
15857 if (rhs_val.isUndef(zcu)) {
1585915858 return sema.failWithUseOfUndef(block, rhs_src);
1586015859 }
1586115860 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -15876,7 +15875,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1587615875 return Air.internedToRef(rem_result.toIntern());
1587715876 }
1587815877 break :rs lhs_src;
15879 } else if (rhs_scalar_ty.isSignedInt(mod)) {
15878 } else if (rhs_scalar_ty.isSignedInt(zcu)) {
1588015879 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);
1588115880 } else {
1588215881 break :rs rhs_src;
......@@ -15884,7 +15883,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1588415883 }
1588515884 // float operands
1588615885 if (maybe_rhs_val) |rhs_val| {
15887 if (rhs_val.isUndef(mod)) {
15886 if (rhs_val.isUndef(zcu)) {
1588815887 return sema.failWithUseOfUndef(block, rhs_src);
1588915888 }
1589015889 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -15894,7 +15893,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1589415893 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);
1589515894 }
1589615895 if (maybe_lhs_val) |lhs_val| {
15897 if (lhs_val.isUndef(mod) or !(try lhs_val.compareAllWithZeroSema(.gte, pt))) {
15896 if (lhs_val.isUndef(zcu) or !(try lhs_val.compareAllWithZeroSema(.gte, pt))) {
1589815897 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
1589915898 }
1590015899 return Air.internedToRef((try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, pt)).toIntern());
......@@ -15923,10 +15922,10 @@ fn intRem(
1592315922 rhs: Value,
1592415923) CompileError!Value {
1592515924 const pt = sema.pt;
15926 const mod = pt.zcu;
15927 if (ty.zigTypeTag(mod) == .Vector) {
15928 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
15929 const scalar_ty = ty.scalarType(mod);
15925 const zcu = pt.zcu;
15926 if (ty.zigTypeTag(zcu) == .Vector) {
15927 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
15928 const scalar_ty = ty.scalarType(zcu);
1593015929 for (result_data, 0..) |*scalar, i| {
1593115930 const lhs_elem = try lhs.elemValue(pt, i);
1593215931 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -15946,8 +15945,8 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
1594615945 // resorting to BigInt first.
1594715946 var lhs_space: Value.BigIntSpace = undefined;
1594815947 var rhs_space: Value.BigIntSpace = undefined;
15949 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);
15950 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);
15948 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
15949 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
1595115950 const limbs_q = try sema.arena.alloc(
1595215951 math.big.Limb,
1595315952 lhs_bigint.limbs.len,
......@@ -15970,7 +15969,7 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
1597015969
1597115970fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1597215971 const pt = sema.pt;
15973 const mod = pt.zcu;
15972 const zcu = pt.zcu;
1597415973 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1597515974 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1597615975 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -15980,8 +15979,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1598015979 const rhs = try sema.resolveInst(extra.rhs);
1598115980 const lhs_ty = sema.typeOf(lhs);
1598215981 const rhs_ty = sema.typeOf(rhs);
15983 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
15984 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
15982 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15983 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1598515984 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1598615985 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1598715986
......@@ -15993,7 +15992,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1599315992 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1599415993 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1599515994
15996 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);
15995 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1599715996
1599815997 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1599915998
......@@ -16016,12 +16015,12 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1601616015 // If the lhs is undefined, result is undefined.
1601716016 if (is_int) {
1601816017 if (maybe_lhs_val) |lhs_val| {
16019 if (lhs_val.isUndef(mod)) {
16018 if (lhs_val.isUndef(zcu)) {
1602016019 return sema.failWithUseOfUndef(block, lhs_src);
1602116020 }
1602216021 }
1602316022 if (maybe_rhs_val) |rhs_val| {
16024 if (rhs_val.isUndef(mod)) {
16023 if (rhs_val.isUndef(zcu)) {
1602516024 return sema.failWithUseOfUndef(block, rhs_src);
1602616025 }
1602716026 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -16037,7 +16036,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1603716036 }
1603816037 // float operands
1603916038 if (maybe_rhs_val) |rhs_val| {
16040 if (rhs_val.isUndef(mod)) {
16039 if (rhs_val.isUndef(zcu)) {
1604116040 return sema.failWithUseOfUndef(block, rhs_src);
1604216041 }
1604316042 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -16045,7 +16044,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1604516044 }
1604616045 }
1604716046 if (maybe_lhs_val) |lhs_val| {
16048 if (lhs_val.isUndef(mod)) {
16047 if (lhs_val.isUndef(zcu)) {
1604916048 return pt.undefRef(resolved_type);
1605016049 }
1605116050 if (maybe_rhs_val) |rhs_val| {
......@@ -16066,7 +16065,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1606616065
1606716066fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1606816067 const pt = sema.pt;
16069 const mod = pt.zcu;
16068 const zcu = pt.zcu;
1607016069 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1607116070 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
1607216071 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
......@@ -16076,8 +16075,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1607616075 const rhs = try sema.resolveInst(extra.rhs);
1607716076 const lhs_ty = sema.typeOf(lhs);
1607816077 const rhs_ty = sema.typeOf(rhs);
16079 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
16080 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
16078 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
16079 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1608116080 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1608216081 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1608316082
......@@ -16089,7 +16088,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1608916088 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1609016089 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1609116090
16092 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);
16091 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1609316092
1609416093 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1609516094
......@@ -16112,12 +16111,12 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1611216111 // If the lhs is undefined, result is undefined.
1611316112 if (is_int) {
1611416113 if (maybe_lhs_val) |lhs_val| {
16115 if (lhs_val.isUndef(mod)) {
16114 if (lhs_val.isUndef(zcu)) {
1611616115 return sema.failWithUseOfUndef(block, lhs_src);
1611716116 }
1611816117 }
1611916118 if (maybe_rhs_val) |rhs_val| {
16120 if (rhs_val.isUndef(mod)) {
16119 if (rhs_val.isUndef(zcu)) {
1612116120 return sema.failWithUseOfUndef(block, rhs_src);
1612216121 }
1612316122 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -16133,7 +16132,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1613316132 }
1613416133 // float operands
1613516134 if (maybe_rhs_val) |rhs_val| {
16136 if (rhs_val.isUndef(mod)) {
16135 if (rhs_val.isUndef(zcu)) {
1613716136 return sema.failWithUseOfUndef(block, rhs_src);
1613816137 }
1613916138 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
......@@ -16141,7 +16140,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1614116140 }
1614216141 }
1614316142 if (maybe_lhs_val) |lhs_val| {
16144 if (lhs_val.isUndef(mod)) {
16143 if (lhs_val.isUndef(zcu)) {
1614516144 return pt.undefRef(resolved_type);
1614616145 }
1614716146 if (maybe_rhs_val) |rhs_val| {
......@@ -16181,8 +16180,8 @@ fn zirOverflowArithmetic(
1618116180 const lhs_ty = sema.typeOf(uncasted_lhs);
1618216181 const rhs_ty = sema.typeOf(uncasted_rhs);
1618316182 const pt = sema.pt;
16184 const mod = pt.zcu;
16185 const ip = &mod.intern_pool;
16183 const zcu = pt.zcu;
16184 const ip = &zcu.intern_pool;
1618616185
1618716186 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1618816187
......@@ -16202,7 +16201,7 @@ fn zirOverflowArithmetic(
1620216201 const lhs = try sema.coerce(block, dest_ty, uncasted_lhs, lhs_src);
1620316202 const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src);
1620416203
16205 if (dest_ty.scalarType(mod).zigTypeTag(mod) != .Int) {
16204 if (dest_ty.scalarType(zcu).zigTypeTag(zcu) != .Int) {
1620616205 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(pt)});
1620716206 }
1620816207
......@@ -16224,18 +16223,18 @@ fn zirOverflowArithmetic(
1622416223 // to the result, even if it is undefined..
1622516224 // Otherwise, if either of the argument is undefined, undefined is returned.
1622616225 if (maybe_lhs_val) |lhs_val| {
16227 if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
16226 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
1622816227 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };
1622916228 }
1623016229 }
1623116230 if (maybe_rhs_val) |rhs_val| {
16232 if (!rhs_val.isUndef(mod) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {
16231 if (!rhs_val.isUndef(zcu) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {
1623316232 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
1623416233 }
1623516234 }
1623616235 if (maybe_lhs_val) |lhs_val| {
1623716236 if (maybe_rhs_val) |rhs_val| {
16238 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
16237 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
1623916238 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
1624016239 }
1624116240
......@@ -16248,12 +16247,12 @@ fn zirOverflowArithmetic(
1624816247 // If the rhs is zero, then the result is lhs and no overflow occured.
1624916248 // Otherwise, if either result is undefined, both results are undefined.
1625016249 if (maybe_rhs_val) |rhs_val| {
16251 if (rhs_val.isUndef(mod)) {
16250 if (rhs_val.isUndef(zcu)) {
1625216251 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
1625316252 } else if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
1625416253 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
1625516254 } else if (maybe_lhs_val) |lhs_val| {
16256 if (lhs_val.isUndef(mod)) {
16255 if (lhs_val.isUndef(zcu)) {
1625716256 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
1625816257 }
1625916258
......@@ -16266,9 +16265,9 @@ fn zirOverflowArithmetic(
1626616265 // If either of the arguments is zero, the result is zero and no overflow occured.
1626716266 // If either of the arguments is one, the result is the other and no overflow occured.
1626816267 // Otherwise, if either of the arguments is undefined, both results are undefined.
16269 const scalar_one = try pt.intValue(dest_ty.scalarType(mod), 1);
16268 const scalar_one = try pt.intValue(dest_ty.scalarType(zcu), 1);
1627016269 if (maybe_lhs_val) |lhs_val| {
16271 if (!lhs_val.isUndef(mod)) {
16270 if (!lhs_val.isUndef(zcu)) {
1627216271 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1627316272 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
1627416273 } else if (try sema.compareAll(lhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
......@@ -16278,7 +16277,7 @@ fn zirOverflowArithmetic(
1627816277 }
1627916278
1628016279 if (maybe_rhs_val) |rhs_val| {
16281 if (!rhs_val.isUndef(mod)) {
16280 if (!rhs_val.isUndef(zcu)) {
1628216281 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
1628316282 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };
1628416283 } else if (try sema.compareAll(rhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
......@@ -16289,7 +16288,7 @@ fn zirOverflowArithmetic(
1628916288
1629016289 if (maybe_lhs_val) |lhs_val| {
1629116290 if (maybe_rhs_val) |rhs_val| {
16292 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
16291 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
1629316292 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
1629416293 }
1629516294
......@@ -16303,18 +16302,18 @@ fn zirOverflowArithmetic(
1630316302 // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred.
1630416303 // Oterhwise if either of the arguments is undefined, both results are undefined.
1630516304 if (maybe_lhs_val) |lhs_val| {
16306 if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
16305 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
1630716306 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
1630816307 }
1630916308 }
1631016309 if (maybe_rhs_val) |rhs_val| {
16311 if (!rhs_val.isUndef(mod) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {
16310 if (!rhs_val.isUndef(zcu) and (try rhs_val.compareAllWithZeroSema(.eq, pt))) {
1631216311 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
1631316312 }
1631416313 }
1631516314 if (maybe_lhs_val) |lhs_val| {
1631616315 if (maybe_rhs_val) |rhs_val| {
16317 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
16316 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
1631816317 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
1631916318 }
1632016319
......@@ -16374,8 +16373,8 @@ fn zirOverflowArithmetic(
1637416373
1637516374fn splat(sema: *Sema, ty: Type, val: Value) !Value {
1637616375 const pt = sema.pt;
16377 const mod = pt.zcu;
16378 if (ty.zigTypeTag(mod) != .Vector) return val;
16376 const zcu = pt.zcu;
16377 if (ty.zigTypeTag(zcu) != .Vector) return val;
1637916378 const repeated = try pt.intern(.{ .aggregate = .{
1638016379 .ty = ty.toIntern(),
1638116380 .storage = .{ .repeated_elem = val.toIntern() },
......@@ -16385,16 +16384,16 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {
1638516384
1638616385fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
1638716386 const pt = sema.pt;
16388 const mod = pt.zcu;
16389 const ip = &mod.intern_pool;
16390 const ov_ty = if (ty.zigTypeTag(mod) == .Vector) try pt.vectorType(.{
16391 .len = ty.vectorLen(mod),
16387 const zcu = pt.zcu;
16388 const ip = &zcu.intern_pool;
16389 const ov_ty = if (ty.zigTypeTag(zcu) == .Vector) try pt.vectorType(.{
16390 .len = ty.vectorLen(zcu),
1639216391 .child = .u1_type,
1639316392 }) else Type.u1;
1639416393
1639516394 const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() };
1639616395 const values = [2]InternPool.Index{ .none, .none };
16397 const tuple_ty = try ip.getAnonStructType(mod.gpa, pt.tid, .{
16396 const tuple_ty = try ip.getAnonStructType(zcu.gpa, pt.tid, .{
1639816397 .types = &types,
1639916398 .values = &values,
1640016399 .names = &.{},
......@@ -16415,41 +16414,41 @@ fn analyzeArithmetic(
1641516414 want_safety: bool,
1641616415) CompileError!Air.Inst.Ref {
1641716416 const pt = sema.pt;
16418 const mod = pt.zcu;
16417 const zcu = pt.zcu;
1641916418 const lhs_ty = sema.typeOf(lhs);
1642016419 const rhs_ty = sema.typeOf(rhs);
16421 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
16422 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
16420 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
16421 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
1642316422 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1642416423
1642516424 if (lhs_zig_ty_tag == .Pointer) {
1642616425 if (rhs_zig_ty_tag == .Pointer) {
16427 if (lhs_ty.ptrSize(mod) != .Slice and rhs_ty.ptrSize(mod) != .Slice) {
16426 if (lhs_ty.ptrSize(zcu) != .Slice and rhs_ty.ptrSize(zcu) != .Slice) {
1642816427 if (zir_tag != .sub) {
1642916428 return sema.failWithInvalidPtrArithmetic(block, src, "pointer-pointer", "subtraction");
1643016429 }
16431 if (!lhs_ty.elemType2(mod).eql(rhs_ty.elemType2(mod), mod)) {
16430 if (!lhs_ty.elemType2(zcu).eql(rhs_ty.elemType2(zcu), zcu)) {
1643216431 return sema.fail(block, src, "incompatible pointer arithmetic operands '{}' and '{}'", .{
1643316432 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
1643416433 });
1643516434 }
1643616435
16437 const elem_size = lhs_ty.elemType2(mod).abiSize(pt);
16436 const elem_size = lhs_ty.elemType2(zcu).abiSize(zcu);
1643816437 if (elem_size == 0) {
1643916438 return sema.fail(block, src, "pointer arithmetic requires element type '{}' to have runtime bits", .{
16440 lhs_ty.elemType2(mod).fmt(pt),
16439 lhs_ty.elemType2(zcu).fmt(pt),
1644116440 });
1644216441 }
1644316442
1644416443 const runtime_src = runtime_src: {
1644516444 if (try sema.resolveValue(lhs)) |lhs_value| {
1644616445 if (try sema.resolveValue(rhs)) |rhs_value| {
16447 const lhs_ptr = switch (mod.intern_pool.indexToKey(lhs_value.toIntern())) {
16446 const lhs_ptr = switch (zcu.intern_pool.indexToKey(lhs_value.toIntern())) {
1644816447 .undef => return sema.failWithUseOfUndef(block, lhs_src),
1644916448 .ptr => |ptr| ptr,
1645016449 else => unreachable,
1645116450 };
16452 const rhs_ptr = switch (mod.intern_pool.indexToKey(rhs_value.toIntern())) {
16451 const rhs_ptr = switch (zcu.intern_pool.indexToKey(rhs_value.toIntern())) {
1645316452 .undef => return sema.failWithUseOfUndef(block, rhs_src),
1645416453 .ptr => |ptr| ptr,
1645516454 else => unreachable,
......@@ -16475,7 +16474,7 @@ fn analyzeArithmetic(
1647516474 return try block.addBinOp(.div_exact, address, try pt.intRef(Type.usize, elem_size));
1647616475 }
1647716476 } else {
16478 switch (lhs_ty.ptrSize(mod)) {
16477 switch (lhs_ty.ptrSize(zcu)) {
1647916478 .One, .Slice => {},
1648016479 .Many, .C => {
1648116480 const air_tag: Air.Inst.Tag = switch (zir_tag) {
......@@ -16484,9 +16483,9 @@ fn analyzeArithmetic(
1648416483 else => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"),
1648516484 };
1648616485
16487 if (!try sema.typeHasRuntimeBits(lhs_ty.elemType2(mod))) {
16486 if (!try lhs_ty.elemType2(zcu).hasRuntimeBitsSema(pt)) {
1648816487 return sema.fail(block, src, "pointer arithmetic requires element type '{}' to have runtime bits", .{
16489 lhs_ty.elemType2(mod).fmt(pt),
16488 lhs_ty.elemType2(zcu).fmt(pt),
1649016489 });
1649116490 }
1649216491 return sema.analyzePtrArithmetic(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
......@@ -16503,8 +16502,8 @@ fn analyzeArithmetic(
1650316502 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
1650416503 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1650516504
16506 const scalar_type = resolved_type.scalarType(mod);
16507 const scalar_tag = scalar_type.zigTypeTag(mod);
16505 const scalar_type = resolved_type.scalarType(zcu);
16506 const scalar_tag = scalar_type.zigTypeTag(zcu);
1650816507
1650916508 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1651016509
......@@ -16523,12 +16522,12 @@ fn analyzeArithmetic(
1652316522 // overflow (max_int), causing illegal behavior.
1652416523 // For floats: either operand being undef makes the result undef.
1652516524 if (maybe_lhs_val) |lhs_val| {
16526 if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
16525 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
1652716526 return casted_rhs;
1652816527 }
1652916528 }
1653016529 if (maybe_rhs_val) |rhs_val| {
16531 if (rhs_val.isUndef(mod)) {
16530 if (rhs_val.isUndef(zcu)) {
1653216531 if (is_int) {
1653316532 return sema.failWithUseOfUndef(block, rhs_src);
1653416533 } else {
......@@ -16541,7 +16540,7 @@ fn analyzeArithmetic(
1654116540 }
1654216541 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .add_optimized else .add;
1654316542 if (maybe_lhs_val) |lhs_val| {
16544 if (lhs_val.isUndef(mod)) {
16543 if (lhs_val.isUndef(zcu)) {
1654516544 if (is_int) {
1654616545 return sema.failWithUseOfUndef(block, lhs_src);
1654716546 } else {
......@@ -16567,12 +16566,12 @@ fn analyzeArithmetic(
1656716566 // If either of the operands are zero, the other operand is returned.
1656816567 // If either of the operands are undefined, the result is undefined.
1656916568 if (maybe_lhs_val) |lhs_val| {
16570 if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
16569 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
1657116570 return casted_rhs;
1657216571 }
1657316572 }
1657416573 if (maybe_rhs_val) |rhs_val| {
16575 if (rhs_val.isUndef(mod)) {
16574 if (rhs_val.isUndef(zcu)) {
1657616575 return pt.undefRef(resolved_type);
1657716576 }
1657816577 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
......@@ -16588,19 +16587,19 @@ fn analyzeArithmetic(
1658816587 // If either of the operands are zero, then the other operand is returned.
1658916588 // If either of the operands are undefined, the result is undefined.
1659016589 if (maybe_lhs_val) |lhs_val| {
16591 if (!lhs_val.isUndef(mod) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
16590 if (!lhs_val.isUndef(zcu) and (try lhs_val.compareAllWithZeroSema(.eq, pt))) {
1659216591 return casted_rhs;
1659316592 }
1659416593 }
1659516594 if (maybe_rhs_val) |rhs_val| {
16596 if (rhs_val.isUndef(mod)) {
16595 if (rhs_val.isUndef(zcu)) {
1659716596 return pt.undefRef(resolved_type);
1659816597 }
1659916598 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
1660016599 return casted_lhs;
1660116600 }
1660216601 if (maybe_lhs_val) |lhs_val| {
16603 if (lhs_val.isUndef(mod)) {
16602 if (lhs_val.isUndef(zcu)) {
1660416603 return pt.undefRef(resolved_type);
1660516604 }
1660616605
......@@ -16630,7 +16629,7 @@ fn analyzeArithmetic(
1663016629 // overflow, causing illegal behavior.
1663116630 // For floats: either operand being undef makes the result undef.
1663216631 if (maybe_rhs_val) |rhs_val| {
16633 if (rhs_val.isUndef(mod)) {
16632 if (rhs_val.isUndef(zcu)) {
1663416633 if (is_int) {
1663516634 return sema.failWithUseOfUndef(block, rhs_src);
1663616635 } else {
......@@ -16643,7 +16642,7 @@ fn analyzeArithmetic(
1664316642 }
1664416643 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .sub_optimized else .sub;
1664516644 if (maybe_lhs_val) |lhs_val| {
16646 if (lhs_val.isUndef(mod)) {
16645 if (lhs_val.isUndef(zcu)) {
1664716646 if (is_int) {
1664816647 return sema.failWithUseOfUndef(block, lhs_src);
1664916648 } else {
......@@ -16669,7 +16668,7 @@ fn analyzeArithmetic(
1666916668 // If the RHS is zero, then the LHS is returned, even if it is undefined.
1667016669 // If either of the operands are undefined, the result is undefined.
1667116670 if (maybe_rhs_val) |rhs_val| {
16672 if (rhs_val.isUndef(mod)) {
16671 if (rhs_val.isUndef(zcu)) {
1667316672 return pt.undefRef(resolved_type);
1667416673 }
1667516674 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
......@@ -16677,7 +16676,7 @@ fn analyzeArithmetic(
1667716676 }
1667816677 }
1667916678 if (maybe_lhs_val) |lhs_val| {
16680 if (lhs_val.isUndef(mod)) {
16679 if (lhs_val.isUndef(zcu)) {
1668116680 return pt.undefRef(resolved_type);
1668216681 }
1668316682 if (maybe_rhs_val) |rhs_val| {
......@@ -16690,7 +16689,7 @@ fn analyzeArithmetic(
1669016689 // If the RHS is zero, then the LHS is returned, even if it is undefined.
1669116690 // If either of the operands are undefined, the result is undefined.
1669216691 if (maybe_rhs_val) |rhs_val| {
16693 if (rhs_val.isUndef(mod)) {
16692 if (rhs_val.isUndef(zcu)) {
1669416693 return pt.undefRef(resolved_type);
1669516694 }
1669616695 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
......@@ -16698,7 +16697,7 @@ fn analyzeArithmetic(
1669816697 }
1669916698 }
1670016699 if (maybe_lhs_val) |lhs_val| {
16701 if (lhs_val.isUndef(mod)) {
16700 if (lhs_val.isUndef(zcu)) {
1670216701 return pt.undefRef(resolved_type);
1670316702 }
1670416703 if (maybe_rhs_val) |rhs_val| {
......@@ -16736,16 +16735,16 @@ fn analyzeArithmetic(
1673616735 else => unreachable,
1673716736 };
1673816737 if (maybe_lhs_val) |lhs_val| {
16739 if (!lhs_val.isUndef(mod)) {
16740 if (lhs_val.isNan(mod)) {
16738 if (!lhs_val.isUndef(zcu)) {
16739 if (lhs_val.isNan(zcu)) {
1674116740 return Air.internedToRef(lhs_val.toIntern());
1674216741 }
1674316742 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) lz: {
1674416743 if (maybe_rhs_val) |rhs_val| {
16745 if (rhs_val.isNan(mod)) {
16744 if (rhs_val.isNan(zcu)) {
1674616745 return Air.internedToRef(rhs_val.toIntern());
1674716746 }
16748 if (rhs_val.isInf(mod)) {
16747 if (rhs_val.isInf(zcu)) {
1674916748 return Air.internedToRef((try pt.floatValue(resolved_type, std.math.nan(f128))).toIntern());
1675016749 }
1675116750 } else if (resolved_type.isAnyFloat()) {
......@@ -16761,19 +16760,19 @@ fn analyzeArithmetic(
1676116760 }
1676216761 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .mul_optimized else .mul;
1676316762 if (maybe_rhs_val) |rhs_val| {
16764 if (rhs_val.isUndef(mod)) {
16763 if (rhs_val.isUndef(zcu)) {
1676516764 if (is_int) {
1676616765 return sema.failWithUseOfUndef(block, rhs_src);
1676716766 } else {
1676816767 return pt.undefRef(resolved_type);
1676916768 }
1677016769 }
16771 if (rhs_val.isNan(mod)) {
16770 if (rhs_val.isNan(zcu)) {
1677216771 return Air.internedToRef(rhs_val.toIntern());
1677316772 }
1677416773 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) rz: {
1677516774 if (maybe_lhs_val) |lhs_val| {
16776 if (lhs_val.isInf(mod)) {
16775 if (lhs_val.isInf(zcu)) {
1677716776 return Air.internedToRef((try pt.floatValue(resolved_type, std.math.nan(f128))).toIntern());
1677816777 }
1677916778 } else if (resolved_type.isAnyFloat()) {
......@@ -16786,7 +16785,7 @@ fn analyzeArithmetic(
1678616785 return casted_lhs;
1678716786 }
1678816787 if (maybe_lhs_val) |lhs_val| {
16789 if (lhs_val.isUndef(mod)) {
16788 if (lhs_val.isUndef(zcu)) {
1679016789 if (is_int) {
1679116790 return sema.failWithUseOfUndef(block, lhs_src);
1679216791 } else {
......@@ -16822,7 +16821,7 @@ fn analyzeArithmetic(
1682216821 else => unreachable,
1682316822 };
1682416823 if (maybe_lhs_val) |lhs_val| {
16825 if (!lhs_val.isUndef(mod)) {
16824 if (!lhs_val.isUndef(zcu)) {
1682616825 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1682716826 const zero_val = try sema.splat(resolved_type, scalar_zero);
1682816827 return Air.internedToRef(zero_val.toIntern());
......@@ -16833,7 +16832,7 @@ fn analyzeArithmetic(
1683316832 }
1683416833 }
1683516834 if (maybe_rhs_val) |rhs_val| {
16836 if (rhs_val.isUndef(mod)) {
16835 if (rhs_val.isUndef(zcu)) {
1683716836 return pt.undefRef(resolved_type);
1683816837 }
1683916838 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
......@@ -16844,7 +16843,7 @@ fn analyzeArithmetic(
1684416843 return casted_lhs;
1684516844 }
1684616845 if (maybe_lhs_val) |lhs_val| {
16847 if (lhs_val.isUndef(mod)) {
16846 if (lhs_val.isUndef(zcu)) {
1684816847 return pt.undefRef(resolved_type);
1684916848 }
1685016849 return Air.internedToRef((try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, pt)).toIntern());
......@@ -16867,7 +16866,7 @@ fn analyzeArithmetic(
1686716866 else => unreachable,
1686816867 };
1686916868 if (maybe_lhs_val) |lhs_val| {
16870 if (!lhs_val.isUndef(mod)) {
16869 if (!lhs_val.isUndef(zcu)) {
1687116870 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
1687216871 const zero_val = try sema.splat(resolved_type, scalar_zero);
1687316872 return Air.internedToRef(zero_val.toIntern());
......@@ -16878,7 +16877,7 @@ fn analyzeArithmetic(
1687816877 }
1687916878 }
1688016879 if (maybe_rhs_val) |rhs_val| {
16881 if (rhs_val.isUndef(mod)) {
16880 if (rhs_val.isUndef(zcu)) {
1688216881 return pt.undefRef(resolved_type);
1688316882 }
1688416883 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
......@@ -16889,7 +16888,7 @@ fn analyzeArithmetic(
1688916888 return casted_lhs;
1689016889 }
1689116890 if (maybe_lhs_val) |lhs_val| {
16892 if (lhs_val.isUndef(mod)) {
16891 if (lhs_val.isUndef(zcu)) {
1689316892 return pt.undefRef(resolved_type);
1689416893 }
1689516894
......@@ -16909,7 +16908,7 @@ fn analyzeArithmetic(
1690916908 try sema.requireRuntimeBlock(block, src, runtime_src);
1691016909
1691116910 if (block.wantSafety() and want_safety and scalar_tag == .Int) {
16912 if (mod.backendSupportsFeature(.safety_checked_instructions)) {
16911 if (zcu.backendSupportsFeature(.safety_checked_instructions)) {
1691316912 if (air_tag != air_tag_safe) {
1691416913 _ = try sema.preparePanicId(block, src, .integer_overflow);
1691516914 }
......@@ -16934,7 +16933,7 @@ fn analyzeArithmetic(
1693416933 } },
1693516934 });
1693616935 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);
16937 const any_ov_bit = if (resolved_type.zigTypeTag(mod) == .Vector)
16936 const any_ov_bit = if (resolved_type.zigTypeTag(zcu) == .Vector)
1693816937 try block.addInst(.{
1693916938 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
1694016939 .data = .{ .reduce = .{
......@@ -16969,11 +16968,11 @@ fn analyzePtrArithmetic(
1696916968 // coerce to isize instead of usize.
1697016969 const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src);
1697116970 const pt = sema.pt;
16972 const mod = pt.zcu;
16971 const zcu = pt.zcu;
1697316972 const opt_ptr_val = try sema.resolveValue(ptr);
1697416973 const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset);
1697516974 const ptr_ty = sema.typeOf(ptr);
16976 const ptr_info = ptr_ty.ptrInfo(mod);
16975 const ptr_info = ptr_ty.ptrInfo(zcu);
1697716976 assert(ptr_info.flags.size == .Many or ptr_info.flags.size == .C);
1697816977
1697916978 const new_ptr_ty = t: {
......@@ -16985,7 +16984,7 @@ fn analyzePtrArithmetic(
1698516984 }
1698616985 // If the addend is not a comptime-known value we can still count on
1698716986 // it being a multiple of the type size.
16988 const elem_size = try sema.typeAbiSize(Type.fromInterned(ptr_info.child));
16987 const elem_size = try Type.fromInterned(ptr_info.child).abiSizeSema(pt);
1698916988 const addend = if (opt_off_val) |off_val| a: {
1699016989 const off_int = try sema.usizeCast(block, offset_src, try off_val.toUnsignedIntSema(pt));
1699116990 break :a elem_size * off_int;
......@@ -17017,12 +17016,12 @@ fn analyzePtrArithmetic(
1701717016 const runtime_src = rs: {
1701817017 if (opt_ptr_val) |ptr_val| {
1701917018 if (opt_off_val) |offset_val| {
17020 if (ptr_val.isUndef(mod)) return pt.undefRef(new_ptr_ty);
17019 if (ptr_val.isUndef(zcu)) return pt.undefRef(new_ptr_ty);
1702117020
1702217021 const offset_int = try sema.usizeCast(block, offset_src, try offset_val.toUnsignedIntSema(pt));
1702317022 if (offset_int == 0) return ptr;
1702417023 if (air_tag == .ptr_sub) {
17025 const elem_size = try sema.typeAbiSize(Type.fromInterned(ptr_info.child));
17024 const elem_size = try Type.fromInterned(ptr_info.child).abiSizeSema(pt);
1702617025 const new_ptr_val = try sema.ptrSubtract(block, op_src, ptr_val, offset_int * elem_size, new_ptr_ty);
1702717026 return Air.internedToRef(new_ptr_val.toIntern());
1702817027 } else {
......@@ -17067,7 +17066,7 @@ fn zirAsm(
1706717066 defer tracy.end();
1706817067
1706917068 const pt = sema.pt;
17070 const mod = pt.zcu;
17069 const zcu = pt.zcu;
1707117070 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
1707217071 const src = block.nodeOffset(extra.data.src_node);
1707317072 const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node });
......@@ -17099,7 +17098,7 @@ fn zirAsm(
1709917098 if (is_volatile) {
1710017099 return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{});
1710117100 }
17102 try mod.addGlobalAssembly(sema.owner.unwrap().cau, asm_source);
17101 try zcu.addGlobalAssembly(sema.owner.unwrap().cau, asm_source);
1710317102 return .void_value;
1710417103 }
1710517104
......@@ -17153,7 +17152,7 @@ fn zirAsm(
1715317152
1715417153 const uncasted_arg = try sema.resolveInst(input.data.operand);
1715517154 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
17156 switch (uncasted_arg_ty.zigTypeTag(mod)) {
17155 switch (uncasted_arg_ty.zigTypeTag(zcu)) {
1715717156 .ComptimeInt => arg.* = try sema.coerce(block, Type.usize, uncasted_arg, src),
1715817157 .ComptimeFloat => arg.* = try sema.coerce(block, Type.f64, uncasted_arg, src),
1715917158 else => {
......@@ -17236,7 +17235,7 @@ fn zirCmpEq(
1723617235 defer tracy.end();
1723717236
1723817237 const pt = sema.pt;
17239 const mod = pt.zcu;
17238 const zcu = pt.zcu;
1724017239 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1724117240 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1724217241 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
......@@ -17247,18 +17246,18 @@ fn zirCmpEq(
1724717246
1724817247 const lhs_ty = sema.typeOf(lhs);
1724917248 const rhs_ty = sema.typeOf(rhs);
17250 const lhs_ty_tag = lhs_ty.zigTypeTag(mod);
17251 const rhs_ty_tag = rhs_ty.zigTypeTag(mod);
17249 const lhs_ty_tag = lhs_ty.zigTypeTag(zcu);
17250 const rhs_ty_tag = rhs_ty.zigTypeTag(zcu);
1725217251 if (lhs_ty_tag == .Null and rhs_ty_tag == .Null) {
1725317252 // null == null, null != null
1725417253 return if (op == .eq) .bool_true else .bool_false;
1725517254 }
1725617255
1725717256 // comparing null with optionals
17258 if (lhs_ty_tag == .Null and (rhs_ty_tag == .Optional or rhs_ty.isCPtr(mod))) {
17257 if (lhs_ty_tag == .Null and (rhs_ty_tag == .Optional or rhs_ty.isCPtr(zcu))) {
1725917258 return sema.analyzeIsNull(block, src, rhs, op == .neq);
1726017259 }
17261 if (rhs_ty_tag == .Null and (lhs_ty_tag == .Optional or lhs_ty.isCPtr(mod))) {
17260 if (rhs_ty_tag == .Null and (lhs_ty_tag == .Optional or lhs_ty.isCPtr(zcu))) {
1726217261 return sema.analyzeIsNull(block, src, lhs, op == .neq);
1726317262 }
1726417263
......@@ -17278,11 +17277,11 @@ fn zirCmpEq(
1727817277 const runtime_src: LazySrcLoc = src: {
1727917278 if (try sema.resolveValue(lhs)) |lval| {
1728017279 if (try sema.resolveValue(rhs)) |rval| {
17281 if (lval.isUndef(mod) or rval.isUndef(mod)) {
17280 if (lval.isUndef(zcu) or rval.isUndef(zcu)) {
1728217281 return pt.undefRef(Type.bool);
1728317282 }
17284 const lkey = mod.intern_pool.indexToKey(lval.toIntern());
17285 const rkey = mod.intern_pool.indexToKey(rval.toIntern());
17283 const lkey = zcu.intern_pool.indexToKey(lval.toIntern());
17284 const rkey = zcu.intern_pool.indexToKey(rval.toIntern());
1728617285 return if ((lkey.err.name == rkey.err.name) == (op == .eq))
1728717286 .bool_true
1728817287 else
......@@ -17300,7 +17299,7 @@ fn zirCmpEq(
1730017299 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {
1730117300 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);
1730217301 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs);
17303 return if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) .bool_true else .bool_false;
17302 return if (lhs_as_type.eql(rhs_as_type, zcu) == (op == .eq)) .bool_true else .bool_false;
1730417303 }
1730517304 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true);
1730617305}
......@@ -17316,14 +17315,14 @@ fn analyzeCmpUnionTag(
1731617315 op: std.math.CompareOperator,
1731717316) CompileError!Air.Inst.Ref {
1731817317 const pt = sema.pt;
17319 const mod = pt.zcu;
17318 const zcu = pt.zcu;
1732017319 const union_ty = sema.typeOf(un);
1732117320 try union_ty.resolveFields(pt);
17322 const union_tag_ty = union_ty.unionTagType(mod) orelse {
17321 const union_tag_ty = union_ty.unionTagType(zcu) orelse {
1732317322 const msg = msg: {
1732417323 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
1732517324 errdefer msg.destroy(sema.gpa);
17326 try sema.errNote(union_ty.srcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(pt)});
17325 try sema.errNote(union_ty.srcLoc(zcu), msg, "union '{}' is not a tagged union", .{union_ty.fmt(pt)});
1732717326 break :msg msg;
1732817327 };
1732917328 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -17334,9 +17333,9 @@ fn analyzeCmpUnionTag(
1733417333 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);
1733517334
1733617335 if (try sema.resolveValue(coerced_tag)) |enum_val| {
17337 if (enum_val.isUndef(mod)) return pt.undefRef(Type.bool);
17338 const field_ty = union_ty.unionFieldType(enum_val, mod).?;
17339 if (field_ty.zigTypeTag(mod) == .NoReturn) {
17336 if (enum_val.isUndef(zcu)) return pt.undefRef(Type.bool);
17337 const field_ty = union_ty.unionFieldType(enum_val, zcu).?;
17338 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
1734017339 return .bool_false;
1734117340 }
1734217341 }
......@@ -17376,33 +17375,33 @@ fn analyzeCmp(
1737617375 is_equality_cmp: bool,
1737717376) CompileError!Air.Inst.Ref {
1737817377 const pt = sema.pt;
17379 const mod = pt.zcu;
17378 const zcu = pt.zcu;
1738017379 const lhs_ty = sema.typeOf(lhs);
1738117380 const rhs_ty = sema.typeOf(rhs);
17382 if (lhs_ty.zigTypeTag(mod) != .Optional and rhs_ty.zigTypeTag(mod) != .Optional) {
17381 if (lhs_ty.zigTypeTag(zcu) != .Optional and rhs_ty.zigTypeTag(zcu) != .Optional) {
1738317382 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1738417383 }
1738517384
17386 if (lhs_ty.zigTypeTag(mod) == .Vector and rhs_ty.zigTypeTag(mod) == .Vector) {
17385 if (lhs_ty.zigTypeTag(zcu) == .Vector and rhs_ty.zigTypeTag(zcu) == .Vector) {
1738717386 return sema.cmpVector(block, src, lhs, rhs, op, lhs_src, rhs_src);
1738817387 }
17389 if (lhs_ty.isNumeric(mod) and rhs_ty.isNumeric(mod)) {
17388 if (lhs_ty.isNumeric(zcu) and rhs_ty.isNumeric(zcu)) {
1739017389 // This operation allows any combination of integer and float types, regardless of the
1739117390 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
1739217391 // numeric types.
1739317392 return sema.cmpNumeric(block, src, lhs, rhs, op, lhs_src, rhs_src);
1739417393 }
17395 if (is_equality_cmp and lhs_ty.zigTypeTag(mod) == .ErrorUnion and rhs_ty.zigTypeTag(mod) == .ErrorSet) {
17394 if (is_equality_cmp and lhs_ty.zigTypeTag(zcu) == .ErrorUnion and rhs_ty.zigTypeTag(zcu) == .ErrorSet) {
1739617395 const casted_lhs = try sema.analyzeErrUnionCode(block, lhs_src, lhs);
1739717396 return sema.cmpSelf(block, src, casted_lhs, rhs, op, lhs_src, rhs_src);
1739817397 }
17399 if (is_equality_cmp and lhs_ty.zigTypeTag(mod) == .ErrorSet and rhs_ty.zigTypeTag(mod) == .ErrorUnion) {
17398 if (is_equality_cmp and lhs_ty.zigTypeTag(zcu) == .ErrorSet and rhs_ty.zigTypeTag(zcu) == .ErrorUnion) {
1740017399 const casted_rhs = try sema.analyzeErrUnionCode(block, rhs_src, rhs);
1740117400 return sema.cmpSelf(block, src, lhs, casted_rhs, op, lhs_src, rhs_src);
1740217401 }
1740317402 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
1740417403 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
17405 if (!resolved_type.isSelfComparable(mod, is_equality_cmp)) {
17404 if (!resolved_type.isSelfComparable(zcu, is_equality_cmp)) {
1740617405 return sema.fail(block, src, "operator {s} not allowed for type '{}'", .{
1740717406 compareOperatorName(op), resolved_type.fmt(pt),
1740817407 });
......@@ -17434,15 +17433,15 @@ fn cmpSelf(
1743417433 rhs_src: LazySrcLoc,
1743517434) CompileError!Air.Inst.Ref {
1743617435 const pt = sema.pt;
17437 const mod = pt.zcu;
17436 const zcu = pt.zcu;
1743817437 const resolved_type = sema.typeOf(casted_lhs);
1743917438 const runtime_src: LazySrcLoc = src: {
1744017439 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
17441 if (lhs_val.isUndef(mod)) return pt.undefRef(Type.bool);
17440 if (lhs_val.isUndef(zcu)) return pt.undefRef(Type.bool);
1744217441 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
17443 if (rhs_val.isUndef(mod)) return pt.undefRef(Type.bool);
17442 if (rhs_val.isUndef(zcu)) return pt.undefRef(Type.bool);
1744417443
17445 if (resolved_type.zigTypeTag(mod) == .Vector) {
17444 if (resolved_type.zigTypeTag(zcu) == .Vector) {
1744617445 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type);
1744717446 return Air.internedToRef(cmp_val.toIntern());
1744817447 }
......@@ -17452,7 +17451,7 @@ fn cmpSelf(
1745217451 else
1745317452 .bool_false;
1745417453 } else {
17455 if (resolved_type.zigTypeTag(mod) == .Bool) {
17454 if (resolved_type.zigTypeTag(zcu) == .Bool) {
1745617455 // We can lower bool eq/neq more efficiently.
1745717456 return sema.runtimeBoolCmp(block, src, op, casted_rhs, lhs_val.toBool(), rhs_src);
1745817457 }
......@@ -17461,9 +17460,9 @@ fn cmpSelf(
1746117460 } else {
1746217461 // For bools, we still check the other operand, because we can lower
1746317462 // bool eq/neq more efficiently.
17464 if (resolved_type.zigTypeTag(mod) == .Bool) {
17463 if (resolved_type.zigTypeTag(zcu) == .Bool) {
1746517464 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
17466 if (rhs_val.isUndef(mod)) return pt.undefRef(Type.bool);
17465 if (rhs_val.isUndef(zcu)) return pt.undefRef(Type.bool);
1746717466 return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src);
1746817467 }
1746917468 }
......@@ -17471,7 +17470,7 @@ fn cmpSelf(
1747117470 }
1747217471 };
1747317472 try sema.requireRuntimeBlock(block, src, runtime_src);
17474 if (resolved_type.zigTypeTag(mod) == .Vector) {
17473 if (resolved_type.zigTypeTag(zcu) == .Vector) {
1747517474 return block.addCmpVector(casted_lhs, casted_rhs, op);
1747617475 }
1747717476 const tag = Air.Inst.Tag.fromCmpOp(op, block.float_mode == .optimized);
......@@ -17541,11 +17540,11 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1754117540
1754217541fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1754317542 const pt = sema.pt;
17544 const mod = pt.zcu;
17543 const zcu = pt.zcu;
1754517544 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1754617545 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1754717546 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
17548 switch (operand_ty.zigTypeTag(mod)) {
17547 switch (operand_ty.zigTypeTag(zcu)) {
1754917548 .Fn,
1755017549 .NoReturn,
1755117550 .Undefined,
......@@ -17576,7 +17575,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1757617575 .AnyFrame,
1757717576 => {},
1757817577 }
17579 const bit_size = try operand_ty.bitSizeAdvanced(pt, .sema);
17578 const bit_size = try operand_ty.bitSizeSema(pt);
1758017579 return pt.intRef(Type.comptime_int, bit_size);
1758117580}
1758217581
......@@ -17599,9 +17598,9 @@ fn zirThis(
1759917598
1760017599fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
1760117600 const pt = sema.pt;
17602 const mod = pt.zcu;
17603 const ip = &mod.intern_pool;
17604 const captures = Type.fromInterned(mod.namespacePtr(block.namespace).owner_type).getCaptures(mod);
17601 const zcu = pt.zcu;
17602 const ip = &zcu.intern_pool;
17603 const captures = Type.fromInterned(zcu.namespacePtr(block.namespace).owner_type).getCaptures(zcu);
1760517604
1760617605 const src_node: i32 = @bitCast(extended.operand);
1760717606 const src = block.nodeOffset(src_node);
......@@ -17619,7 +17618,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1761917618 const msg = msg: {
1762017619 const name = name: {
1762117620 // TODO: we should probably store this name in the ZIR to avoid this complexity.
17622 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod).?;
17621 const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?;
1762317622 const tree = file.getTree(sema.gpa) catch |err| {
1762417623 // In this case we emit a warning + a less precise source location.
1762517624 log.warn("unable to load {s}: {s}", .{
......@@ -17647,7 +17646,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1764717646 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {
1764817647 const msg = msg: {
1764917648 const name = name: {
17650 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod).?;
17649 const file, const src_base_node = Zcu.LazySrcLoc.resolveBaseNode(block.src_base_inst, zcu).?;
1765117650 const tree = file.getTree(sema.gpa) catch |err| {
1765217651 // In this case we emit a warning + a less precise source location.
1765317652 log.warn("unable to load {s}: {s}", .{
......@@ -17816,20 +17815,20 @@ fn zirBuiltinSrc(
1781617815
1781717816fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1781817817 const pt = sema.pt;
17819 const mod = pt.zcu;
17818 const zcu = pt.zcu;
1782017819 const gpa = sema.gpa;
17821 const ip = &mod.intern_pool;
17820 const ip = &zcu.intern_pool;
1782217821 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1782317822 const src = block.nodeOffset(inst_data.src_node);
1782417823 const ty = try sema.resolveType(block, src, inst_data.operand);
1782517824 const type_info_ty = try pt.getBuiltinType("Type");
17826 const type_info_tag_ty = type_info_ty.unionTagType(mod).?;
17825 const type_info_tag_ty = type_info_ty.unionTagType(zcu).?;
1782717826
17828 if (ty.typeDeclInst(mod)) |type_decl_inst| {
17827 if (ty.typeDeclInst(zcu)) |type_decl_inst| {
1782917828 try sema.declareDependency(.{ .namespace = type_decl_inst });
1783017829 }
1783117830
17832 switch (ty.zigTypeTag(mod)) {
17831 switch (ty.zigTypeTag(zcu)) {
1783317832 .Type,
1783417833 .Void,
1783517834 .Bool,
......@@ -17848,7 +17847,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1784817847 const fn_info_nav = try sema.namespaceLookup(
1784917848 block,
1785017849 src,
17851 type_info_ty.getNamespaceIndex(mod),
17850 type_info_ty.getNamespaceIndex(zcu),
1785217851 try ip.getOrPutString(gpa, pt.tid, "Fn", .no_embedded_nulls),
1785317852 ) orelse @panic("std.builtin.Type is corrupt");
1785417853 try sema.ensureNavResolved(src, fn_info_nav);
......@@ -17857,13 +17856,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1785717856 const param_info_nav = try sema.namespaceLookup(
1785817857 block,
1785917858 src,
17860 fn_info_ty.getNamespaceIndex(mod),
17859 fn_info_ty.getNamespaceIndex(zcu),
1786117860 try ip.getOrPutString(gpa, pt.tid, "Param", .no_embedded_nulls),
1786217861 ) orelse @panic("std.builtin.Type is corrupt");
1786317862 try sema.ensureNavResolved(src, param_info_nav);
1786417863 const param_info_ty = Type.fromInterned(ip.getNav(param_info_nav).status.resolved.val);
1786517864
17866 const func_ty_info = mod.typeToFunc(ty).?;
17865 const func_ty_info = zcu.typeToFunc(ty).?;
1786717866 const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
1786817867 for (param_vals, 0..) |*param_val, i| {
1786917868 const param_ty = func_ty_info.param_types.get(ip)[i];
......@@ -17908,7 +17907,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1790817907 .is_const = true,
1790917908 },
1791017909 })).toIntern();
17911 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();
17910 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
1791217911 break :v try pt.intern(.{ .slice = .{
1791317912 .ty = slice_ty,
1791417913 .ptr = try pt.intern(.{ .ptr = .{
......@@ -17958,14 +17957,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1795817957 const int_info_nav = try sema.namespaceLookup(
1795917958 block,
1796017959 src,
17961 type_info_ty.getNamespaceIndex(mod),
17960 type_info_ty.getNamespaceIndex(zcu),
1796217961 try ip.getOrPutString(gpa, pt.tid, "Int", .no_embedded_nulls),
1796317962 ) orelse @panic("std.builtin.Type is corrupt");
1796417963 try sema.ensureNavResolved(src, int_info_nav);
1796517964 const int_info_ty = Type.fromInterned(ip.getNav(int_info_nav).status.resolved.val);
1796617965
1796717966 const signedness_ty = try pt.getBuiltinType("Signedness");
17968 const info = ty.intInfo(mod);
17967 const info = ty.intInfo(zcu);
1796917968 const field_values = .{
1797017969 // signedness: Signedness,
1797117970 (try pt.enumValueFieldIndex(signedness_ty, @intFromEnum(info.signedness))).toIntern(),
......@@ -17985,7 +17984,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1798517984 const float_info_nav = try sema.namespaceLookup(
1798617985 block,
1798717986 src,
17988 type_info_ty.getNamespaceIndex(mod),
17987 type_info_ty.getNamespaceIndex(zcu),
1798917988 try ip.getOrPutString(gpa, pt.tid, "Float", .no_embedded_nulls),
1799017989 ) orelse @panic("std.builtin.Type is corrupt");
1799117990 try sema.ensureNavResolved(src, float_info_nav);
......@@ -17993,7 +17992,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1799317992
1799417993 const field_vals = .{
1799517994 // bits: u16,
17996 (try pt.intValue(Type.u16, ty.bitSize(pt))).toIntern(),
17995 (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(),
1799717996 };
1799817997 return Air.internedToRef((try pt.intern(.{ .un = .{
1799917998 .ty = type_info_ty.toIntern(),
......@@ -18005,7 +18004,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1800518004 } })));
1800618005 },
1800718006 .Pointer => {
18008 const info = ty.ptrInfo(mod);
18007 const info = ty.ptrInfo(zcu);
1800918008 const alignment = if (info.flags.alignment.toByteUnits()) |alignment|
1801018009 try pt.intValue(Type.comptime_int, alignment)
1801118010 else
......@@ -18016,7 +18015,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1801618015 const nav = try sema.namespaceLookup(
1801718016 block,
1801818017 src,
18019 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
18018 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
1802018019 try ip.getOrPutString(gpa, pt.tid, "Pointer", .no_embedded_nulls),
1802118020 ) orelse @panic("std.builtin.Type is corrupt");
1802218021 try sema.ensureNavResolved(src, nav);
......@@ -18026,7 +18025,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1802618025 const nav = try sema.namespaceLookup(
1802718026 block,
1802818027 src,
18029 pointer_ty.getNamespaceIndex(mod),
18028 pointer_ty.getNamespaceIndex(zcu),
1803018029 try ip.getOrPutString(gpa, pt.tid, "Size", .no_embedded_nulls),
1803118030 ) orelse @panic("std.builtin.Type is corrupt");
1803218031 try sema.ensureNavResolved(src, nav);
......@@ -18068,14 +18067,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1806818067 const nav = try sema.namespaceLookup(
1806918068 block,
1807018069 src,
18071 type_info_ty.getNamespaceIndex(mod),
18070 type_info_ty.getNamespaceIndex(zcu),
1807218071 try ip.getOrPutString(gpa, pt.tid, "Array", .no_embedded_nulls),
1807318072 ) orelse @panic("std.builtin.Type is corrupt");
1807418073 try sema.ensureNavResolved(src, nav);
1807518074 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);
1807618075 };
1807718076
18078 const info = ty.arrayInfo(mod);
18077 const info = ty.arrayInfo(zcu);
1807918078 const field_values = .{
1808018079 // len: comptime_int,
1808118080 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),
......@@ -18098,14 +18097,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1809818097 const nav = try sema.namespaceLookup(
1809918098 block,
1810018099 src,
18101 type_info_ty.getNamespaceIndex(mod),
18100 type_info_ty.getNamespaceIndex(zcu),
1810218101 try ip.getOrPutString(gpa, pt.tid, "Vector", .no_embedded_nulls),
1810318102 ) orelse @panic("std.builtin.Type is corrupt");
1810418103 try sema.ensureNavResolved(src, nav);
1810518104 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);
1810618105 };
1810718106
18108 const info = ty.arrayInfo(mod);
18107 const info = ty.arrayInfo(zcu);
1810918108 const field_values = .{
1811018109 // len: comptime_int,
1811118110 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),
......@@ -18126,7 +18125,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1812618125 const nav = try sema.namespaceLookup(
1812718126 block,
1812818127 src,
18129 type_info_ty.getNamespaceIndex(mod),
18128 type_info_ty.getNamespaceIndex(zcu),
1813018129 try ip.getOrPutString(gpa, pt.tid, "Optional", .no_embedded_nulls),
1813118130 ) orelse @panic("std.builtin.Type is corrupt");
1813218131 try sema.ensureNavResolved(src, nav);
......@@ -18135,7 +18134,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1813518134
1813618135 const field_values = .{
1813718136 // child: type,
18138 ty.optionalChild(mod).toIntern(),
18137 ty.optionalChild(zcu).toIntern(),
1813918138 };
1814018139 return Air.internedToRef((try pt.intern(.{ .un = .{
1814118140 .ty = type_info_ty.toIntern(),
......@@ -18152,7 +18151,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1815218151 const nav = try sema.namespaceLookup(
1815318152 block,
1815418153 src,
18155 type_info_ty.getNamespaceIndex(mod),
18154 type_info_ty.getNamespaceIndex(zcu),
1815618155 try ip.getOrPutString(gpa, pt.tid, "Error", .no_embedded_nulls),
1815718156 ) orelse @panic("std.builtin.Type is corrupt");
1815818157 try sema.ensureNavResolved(src, nav);
......@@ -18226,7 +18225,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1822618225 .ty = array_errors_ty.toIntern(),
1822718226 .storage = .{ .elems = vals },
1822818227 } });
18229 const manyptr_errors_ty = slice_errors_ty.slicePtrFieldType(mod).toIntern();
18228 const manyptr_errors_ty = slice_errors_ty.slicePtrFieldType(zcu).toIntern();
1823018229 break :v try pt.intern(.{ .slice = .{
1823118230 .ty = slice_errors_ty.toIntern(),
1823218231 .ptr = try pt.intern(.{ .ptr = .{
......@@ -18257,7 +18256,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1825718256 const nav = try sema.namespaceLookup(
1825818257 block,
1825918258 src,
18260 type_info_ty.getNamespaceIndex(mod),
18259 type_info_ty.getNamespaceIndex(zcu),
1826118260 try ip.getOrPutString(gpa, pt.tid, "ErrorUnion", .no_embedded_nulls),
1826218261 ) orelse @panic("std.builtin.Type is corrupt");
1826318262 try sema.ensureNavResolved(src, nav);
......@@ -18266,9 +18265,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1826618265
1826718266 const field_values = .{
1826818267 // error_set: type,
18269 ty.errorUnionSet(mod).toIntern(),
18268 ty.errorUnionSet(zcu).toIntern(),
1827018269 // payload: type,
18271 ty.errorUnionPayload(mod).toIntern(),
18270 ty.errorUnionPayload(zcu).toIntern(),
1827218271 };
1827318272 return Air.internedToRef((try pt.intern(.{ .un = .{
1827418273 .ty = type_info_ty.toIntern(),
......@@ -18286,7 +18285,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1828618285 const nav = try sema.namespaceLookup(
1828718286 block,
1828818287 src,
18289 type_info_ty.getNamespaceIndex(mod),
18288 type_info_ty.getNamespaceIndex(zcu),
1829018289 try ip.getOrPutString(gpa, pt.tid, "EnumField", .no_embedded_nulls),
1829118290 ) orelse @panic("std.builtin.Type is corrupt");
1829218291 try sema.ensureNavResolved(src, nav);
......@@ -18298,7 +18297,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1829818297 const enum_type = ip.loadEnumType(ty.toIntern());
1829918298 const value_val = if (enum_type.values.len > 0)
1830018299 try ip.getCoercedInts(
18301 mod.gpa,
18300 zcu.gpa,
1830218301 pt.tid,
1830318302 ip.indexToKey(enum_type.values.get(ip)[tag_index]).int,
1830418303 .comptime_int_type,
......@@ -18361,7 +18360,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1836118360 .is_const = true,
1836218361 },
1836318362 })).toIntern();
18364 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();
18363 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
1836518364 break :v try pt.intern(.{ .slice = .{
1836618365 .ty = slice_ty,
1836718366 .ptr = try pt.intern(.{ .ptr = .{
......@@ -18382,7 +18381,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1838218381 const nav = try sema.namespaceLookup(
1838318382 block,
1838418383 src,
18385 type_info_ty.getNamespaceIndex(mod),
18384 type_info_ty.getNamespaceIndex(zcu),
1838618385 try ip.getOrPutString(gpa, pt.tid, "Enum", .no_embedded_nulls),
1838718386 ) orelse @panic("std.builtin.Type is corrupt");
1838818387 try sema.ensureNavResolved(src, nav);
......@@ -18413,7 +18412,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1841318412 const nav = try sema.namespaceLookup(
1841418413 block,
1841518414 src,
18416 type_info_ty.getNamespaceIndex(mod),
18415 type_info_ty.getNamespaceIndex(zcu),
1841718416 try ip.getOrPutString(gpa, pt.tid, "Union", .no_embedded_nulls),
1841818417 ) orelse @panic("std.builtin.Type is corrupt");
1841918418 try sema.ensureNavResolved(src, nav);
......@@ -18424,7 +18423,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1842418423 const nav = try sema.namespaceLookup(
1842518424 block,
1842618425 src,
18427 type_info_ty.getNamespaceIndex(mod),
18426 type_info_ty.getNamespaceIndex(zcu),
1842818427 try ip.getOrPutString(gpa, pt.tid, "UnionField", .no_embedded_nulls),
1842918428 ) orelse @panic("std.builtin.Type is corrupt");
1843018429 try sema.ensureNavResolved(src, nav);
......@@ -18432,7 +18431,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1843218431 };
1843318432
1843418433 try ty.resolveLayout(pt); // Getting alignment requires type layout
18435 const union_obj = mod.typeToUnion(ty).?;
18434 const union_obj = zcu.typeToUnion(ty).?;
1843618435 const tag_type = union_obj.loadTagType(ip);
1843718436 const layout = union_obj.flagsUnordered(ip).layout;
1843818437
......@@ -18467,7 +18466,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1846718466 };
1846818467
1846918468 const alignment = switch (layout) {
18470 .auto, .@"extern" => try pt.unionFieldNormalAlignmentAdvanced(union_obj, @intCast(field_index), .sema),
18469 .auto, .@"extern" => try Type.unionFieldNormalAlignmentAdvanced(
18470 union_obj,
18471 @intCast(field_index),
18472 .sema,
18473 pt.zcu,
18474 pt.tid,
18475 ),
1847118476 .@"packed" => .none,
1847218477 };
1847318478
......@@ -18502,7 +18507,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1850218507 .is_const = true,
1850318508 },
1850418509 })).toIntern();
18505 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();
18510 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
1850618511 break :v try pt.intern(.{ .slice = .{
1850718512 .ty = slice_ty,
1850818513 .ptr = try pt.intern(.{ .ptr = .{
......@@ -18517,18 +18522,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1851718522 } });
1851818523 };
1851918524
18520 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(mod).toOptional());
18525 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(zcu).toOptional());
1852118526
1852218527 const enum_tag_ty_val = try pt.intern(.{ .opt = .{
1852318528 .ty = (try pt.optionalType(.type_type)).toIntern(),
18524 .val = if (ty.unionTagType(mod)) |tag_ty| tag_ty.toIntern() else .none,
18529 .val = if (ty.unionTagType(zcu)) |tag_ty| tag_ty.toIntern() else .none,
1852518530 } });
1852618531
1852718532 const container_layout_ty = t: {
1852818533 const nav = try sema.namespaceLookup(
1852918534 block,
1853018535 src,
18531 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
18536 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
1853218537 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
1853318538 ) orelse @panic("std.builtin.Type is corrupt");
1853418539 try sema.ensureNavResolved(src, nav);
......@@ -18560,7 +18565,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1856018565 const nav = try sema.namespaceLookup(
1856118566 block,
1856218567 src,
18563 type_info_ty.getNamespaceIndex(mod),
18568 type_info_ty.getNamespaceIndex(zcu),
1856418569 try ip.getOrPutString(gpa, pt.tid, "Struct", .no_embedded_nulls),
1856518570 ) orelse @panic("std.builtin.Type is corrupt");
1856618571 try sema.ensureNavResolved(src, nav);
......@@ -18571,7 +18576,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1857118576 const nav = try sema.namespaceLookup(
1857218577 block,
1857318578 src,
18574 type_info_ty.getNamespaceIndex(mod),
18579 type_info_ty.getNamespaceIndex(zcu),
1857518580 try ip.getOrPutString(gpa, pt.tid, "StructField", .no_embedded_nulls),
1857618581 ) orelse @panic("std.builtin.Type is corrupt");
1857718582 try sema.ensureNavResolved(src, nav);
......@@ -18633,7 +18638,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1863318638 // is_comptime: bool,
1863418639 Value.makeBool(is_comptime).toIntern(),
1863518640 // alignment: comptime_int,
18636 (try pt.intValue(Type.comptime_int, Type.fromInterned(field_ty).abiAlignment(pt).toByteUnits() orelse 0)).toIntern(),
18641 (try pt.intValue(Type.comptime_int, Type.fromInterned(field_ty).abiAlignment(zcu).toByteUnits() orelse 0)).toIntern(),
1863718642 };
1863818643 struct_field_val.* = try pt.intern(.{ .aggregate = .{
1863918644 .ty = struct_field_ty.toIntern(),
......@@ -18686,11 +18691,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1868618691 const default_val_ptr = try sema.optRefValue(opt_default_val);
1868718692 const alignment = switch (struct_type.layout) {
1868818693 .@"packed" => .none,
18689 else => try pt.structFieldAlignmentAdvanced(
18694 else => try field_ty.structFieldAlignmentAdvanced(
1869018695 struct_type.fieldAlign(ip, field_index),
18691 field_ty,
1869218696 struct_type.layout,
1869318697 .sema,
18698 pt.zcu,
18699 pt.tid,
1869418700 ),
1869518701 };
1869618702
......@@ -18729,7 +18735,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1872918735 .is_const = true,
1873018736 },
1873118737 })).toIntern();
18732 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();
18738 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
1873318739 break :v try pt.intern(.{ .slice = .{
1873418740 .ty = slice_ty,
1873518741 .ptr = try pt.intern(.{ .ptr = .{
......@@ -18744,12 +18750,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1874418750 } });
1874518751 };
1874618752
18747 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod));
18753 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu));
1874818754
1874918755 const backing_integer_val = try pt.intern(.{ .opt = .{
1875018756 .ty = (try pt.optionalType(.type_type)).toIntern(),
18751 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {
18752 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(mod));
18757 .val = if (zcu.typeToPackedStruct(ty)) |packed_struct| val: {
18758 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(zcu));
1875318759 break :val packed_struct.backingIntTypeUnordered(ip);
1875418760 } else .none,
1875518761 } });
......@@ -18758,14 +18764,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1875818764 const nav = try sema.namespaceLookup(
1875918765 block,
1876018766 src,
18761 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
18767 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
1876218768 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
1876318769 ) orelse @panic("std.builtin.Type is corrupt");
1876418770 try sema.ensureNavResolved(src, nav);
1876518771 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);
1876618772 };
1876718773
18768 const layout = ty.containerLayout(mod);
18774 const layout = ty.containerLayout(zcu);
1876918775
1877018776 const field_values = [_]InternPool.Index{
1877118777 // layout: ContainerLayout,
......@@ -18777,7 +18783,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1877718783 // decls: []const Declaration,
1877818784 decls_val,
1877918785 // is_tuple: bool,
18780 Value.makeBool(ty.isTuple(mod)).toIntern(),
18786 Value.makeBool(ty.isTuple(zcu)).toIntern(),
1878118787 };
1878218788 return Air.internedToRef((try pt.intern(.{ .un = .{
1878318789 .ty = type_info_ty.toIntern(),
......@@ -18793,7 +18799,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1879318799 const nav = try sema.namespaceLookup(
1879418800 block,
1879518801 src,
18796 type_info_ty.getNamespaceIndex(mod),
18802 type_info_ty.getNamespaceIndex(zcu),
1879718803 try ip.getOrPutString(gpa, pt.tid, "Opaque", .no_embedded_nulls),
1879818804 ) orelse @panic("std.builtin.Type is corrupt");
1879918805 try sema.ensureNavResolved(src, nav);
......@@ -18801,7 +18807,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1880118807 };
1880218808
1880318809 try ty.resolveFields(pt);
18804 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod));
18810 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu));
1880518811
1880618812 const field_values = .{
1880718813 // decls: []const Declaration,
......@@ -19000,11 +19006,11 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
1900019006
1900119007fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Type {
1900219008 const pt = sema.pt;
19003 const mod = pt.zcu;
19004 switch (operand.zigTypeTag(mod)) {
19009 const zcu = pt.zcu;
19010 switch (operand.zigTypeTag(zcu)) {
1900519011 .ComptimeInt => return Type.comptime_int,
1900619012 .Int => {
19007 const bits = operand.bitSize(pt);
19013 const bits = operand.bitSize(zcu);
1900819014 const count = if (bits == 0)
1900919015 0
1901019016 else blk: {
......@@ -19018,10 +19024,10 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1901819024 return pt.intType(.unsigned, count);
1901919025 },
1902019026 .Vector => {
19021 const elem_ty = operand.elemType2(mod);
19027 const elem_ty = operand.elemType2(zcu);
1902219028 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);
1902319029 return pt.vectorType(.{
19024 .len = operand.vectorLen(mod),
19030 .len = operand.vectorLen(zcu),
1902519031 .child = log2_elem_ty.toIntern(),
1902619032 });
1902719033 },
......@@ -19084,7 +19090,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1908419090 defer tracy.end();
1908519091
1908619092 const pt = sema.pt;
19087 const mod = pt.zcu;
19093 const zcu = pt.zcu;
1908819094 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1908919095 const src = block.nodeOffset(inst_data.src_node);
1909019096 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
......@@ -19092,7 +19098,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1909219098
1909319099 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
1909419100 if (try sema.resolveValue(operand)) |val| {
19095 return if (val.isUndef(mod))
19101 return if (val.isUndef(zcu))
1909619102 pt.undefRef(Type.bool)
1909719103 else if (val.toBool()) .bool_false else .bool_true;
1909819104 }
......@@ -19110,7 +19116,7 @@ fn zirBoolBr(
1911019116 defer tracy.end();
1911119117
1911219118 const pt = sema.pt;
19113 const mod = pt.zcu;
19119 const zcu = pt.zcu;
1911419120 const gpa = sema.gpa;
1911519121
1911619122 const datas = sema.code.instructions.items(.data);
......@@ -19134,7 +19140,7 @@ fn zirBoolBr(
1913419140 // is simply the rhs expression. Here we rely on there only being 1
1913519141 // break instruction (`break_inline`).
1913619142 const rhs_result = try sema.resolveInlineBody(parent_block, body, inst);
19137 if (sema.typeOf(rhs_result).isNoReturn(mod)) {
19143 if (sema.typeOf(rhs_result).isNoReturn(zcu)) {
1913819144 return rhs_result;
1913919145 }
1914019146 return sema.coerce(parent_block, Type.bool, rhs_result, rhs_src);
......@@ -19168,7 +19174,7 @@ fn zirBoolBr(
1916819174 _ = try lhs_block.addBr(block_inst, lhs_result);
1916919175
1917019176 const rhs_result = try sema.resolveInlineBody(rhs_block, body, inst);
19171 const rhs_noret = sema.typeOf(rhs_result).isNoReturn(mod);
19177 const rhs_noret = sema.typeOf(rhs_result).isNoReturn(zcu);
1917219178 const coerced_rhs_result = if (!rhs_noret) rhs: {
1917319179 const coerced_result = try sema.coerce(rhs_block, Type.bool, rhs_result, rhs_src);
1917419180 _ = try rhs_block.addBr(block_inst, coerced_result);
......@@ -19227,10 +19233,10 @@ fn finishCondBr(
1922719233
1922819234fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1922919235 const pt = sema.pt;
19230 const mod = pt.zcu;
19231 switch (ty.zigTypeTag(mod)) {
19236 const zcu = pt.zcu;
19237 switch (ty.zigTypeTag(zcu)) {
1923219238 .Optional, .Null, .Undefined => return,
19233 .Pointer => if (ty.isPtrLikeOptional(mod)) return,
19239 .Pointer => if (ty.isPtrLikeOptional(zcu)) return,
1923419240 else => {},
1923519241 }
1923619242 return sema.failWithExpectedOptionalType(block, src, ty);
......@@ -19260,11 +19266,11 @@ fn zirIsNonNullPtr(
1926019266 defer tracy.end();
1926119267
1926219268 const pt = sema.pt;
19263 const mod = pt.zcu;
19269 const zcu = pt.zcu;
1926419270 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1926519271 const src = block.nodeOffset(inst_data.src_node);
1926619272 const ptr = try sema.resolveInst(inst_data.operand);
19267 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));
19273 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(zcu));
1926819274 if ((try sema.resolveValue(ptr)) == null) {
1926919275 return block.addUnOp(.is_non_null_ptr, ptr);
1927019276 }
......@@ -19274,8 +19280,8 @@ fn zirIsNonNullPtr(
1927419280
1927519281fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1927619282 const pt = sema.pt;
19277 const mod = pt.zcu;
19278 switch (ty.zigTypeTag(mod)) {
19283 const zcu = pt.zcu;
19284 switch (ty.zigTypeTag(zcu)) {
1927919285 .ErrorSet, .ErrorUnion, .Undefined => return,
1928019286 else => return sema.fail(block, src, "expected error union type, found '{}'", .{
1928119287 ty.fmt(pt),
......@@ -19299,11 +19305,11 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1929919305 defer tracy.end();
1930019306
1930119307 const pt = sema.pt;
19302 const mod = pt.zcu;
19308 const zcu = pt.zcu;
1930319309 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1930419310 const src = block.nodeOffset(inst_data.src_node);
1930519311 const ptr = try sema.resolveInst(inst_data.operand);
19306 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod));
19312 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(zcu));
1930719313 const loaded = try sema.analyzeLoad(block, src, ptr, src);
1930819314 return sema.analyzeIsNonErr(block, src, loaded);
1930919315}
......@@ -19327,7 +19333,7 @@ fn zirCondbr(
1932719333 defer tracy.end();
1932819334
1932919335 const pt = sema.pt;
19330 const mod = pt.zcu;
19336 const zcu = pt.zcu;
1933119337 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1933219338 const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node });
1933319339 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
......@@ -19368,8 +19374,8 @@ fn zirCondbr(
1936819374 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;
1936919375 const err_operand = try sema.resolveInst(err_inst_data.operand);
1937019376 const operand_ty = sema.typeOf(err_operand);
19371 assert(operand_ty.zigTypeTag(mod) == .ErrorUnion);
19372 const result_ty = operand_ty.errorUnionSet(mod);
19377 assert(operand_ty.zigTypeTag(zcu) == .ErrorUnion);
19378 const result_ty = operand_ty.errorUnionSet(zcu);
1937319379 break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand);
1937419380 };
1937519381
......@@ -19403,8 +19409,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1940319409 const err_union = try sema.resolveInst(extra.data.operand);
1940419410 const err_union_ty = sema.typeOf(err_union);
1940519411 const pt = sema.pt;
19406 const mod = pt.zcu;
19407 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
19412 const zcu = pt.zcu;
19413 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
1940819414 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
1940919415 err_union_ty.fmt(pt),
1941019416 });
......@@ -19452,8 +19458,8 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1945219458 const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src);
1945319459 const err_union_ty = sema.typeOf(err_union);
1945419460 const pt = sema.pt;
19455 const mod = pt.zcu;
19456 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
19461 const zcu = pt.zcu;
19462 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
1945719463 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
1945819464 err_union_ty.fmt(pt),
1945919465 });
......@@ -19477,9 +19483,9 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1947719483 try sema.analyzeBodyInner(&sub_block, body);
1947819484
1947919485 const operand_ty = sema.typeOf(operand);
19480 const ptr_info = operand_ty.ptrInfo(mod);
19486 const ptr_info = operand_ty.ptrInfo(zcu);
1948119487 const res_ty = try pt.ptrTypeSema(.{
19482 .child = err_union_ty.errorUnionPayload(mod).toIntern(),
19488 .child = err_union_ty.errorUnionPayload(zcu).toIntern(),
1948319489 .flags = .{
1948419490 .is_const = ptr_info.flags.is_const,
1948519491 .is_volatile = ptr_info.flags.is_volatile,
......@@ -19594,10 +19600,10 @@ fn zirRetErrValue(
1959419600 inst: Zir.Inst.Index,
1959519601) CompileError!void {
1959619602 const pt = sema.pt;
19597 const mod = pt.zcu;
19603 const zcu = pt.zcu;
1959819604 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
1959919605 const src = block.tokenOffset(inst_data.src_tok);
19600 const err_name = try mod.intern_pool.getOrPutString(
19606 const err_name = try zcu.intern_pool.getOrPutString(
1960119607 sema.gpa,
1960219608 pt.tid,
1960319609 inst_data.get(sema.code),
......@@ -19622,7 +19628,7 @@ fn zirRetImplicit(
1962219628 defer tracy.end();
1962319629
1962419630 const pt = sema.pt;
19625 const mod = pt.zcu;
19631 const zcu = pt.zcu;
1962619632 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
1962719633 const r_brace_src = block.tokenOffset(inst_data.src_tok);
1962819634 if (block.inlining == null and sema.func_is_naked) {
......@@ -19638,7 +19644,7 @@ fn zirRetImplicit(
1963819644
1963919645 const operand = try sema.resolveInst(inst_data.operand);
1964019646 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 });
19641 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);
19647 const base_tag = sema.fn_ret_ty.baseZigTypeTag(zcu);
1964219648 if (base_tag == .NoReturn) {
1964319649 const msg = msg: {
1964419650 const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{
......@@ -19755,13 +19761,13 @@ fn retWithErrTracing(
1975519761
1975619762fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool {
1975719763 const pt = sema.pt;
19758 const mod = pt.zcu;
19759 return fn_ret_ty.isError(mod) and mod.comp.config.any_error_tracing;
19764 const zcu = pt.zcu;
19765 return fn_ret_ty.isError(zcu) and zcu.comp.config.any_error_tracing;
1976019766}
1976119767
1976219768fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1976319769 const pt = sema.pt;
19764 const mod = pt.zcu;
19770 const zcu = pt.zcu;
1976519771 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
1976619772
1976719773 if (!block.ownerModule().error_tracing) return;
......@@ -19772,7 +19778,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1977219778 const save_index = inst_data.operand == .none or b: {
1977319779 const operand = try sema.resolveInst(inst_data.operand);
1977419780 const operand_ty = sema.typeOf(operand);
19775 break :b operand_ty.isError(mod);
19781 break :b operand_ty.isError(zcu);
1977619782 };
1977719783
1977819784 if (save_index)
......@@ -19792,7 +19798,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1979219798 defer tracy.end();
1979319799
1979419800 const pt = sema.pt;
19795 const mod = pt.zcu;
19801 const zcu = pt.zcu;
1979619802
1979719803 const saved_index = if (target_block.toIndexAllowNone()) |zir_block| b: {
1979819804 var block = start_block;
......@@ -19830,13 +19836,13 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1983019836 if (is_non_error) return;
1983119837
1983219838 const saved_index_val = try sema.resolveDefinedValue(start_block, src, saved_index);
19833 const saved_index_int = saved_index_val.?.toUnsignedInt(pt);
19839 const saved_index_int = saved_index_val.?.toUnsignedInt(zcu);
1983419840 assert(saved_index_int <= sema.comptime_err_ret_trace.items.len);
1983519841 sema.comptime_err_ret_trace.items.len = @intCast(saved_index_int);
1983619842 return;
1983719843 }
1983819844
19839 if (!mod.intern_pool.funcAnalysisUnordered(sema.owner.unwrap().func).calls_or_awaits_errorable_fn) return;
19845 if (!zcu.intern_pool.funcAnalysisUnordered(sema.owner.unwrap().func).calls_or_awaits_errorable_fn) return;
1984019846 if (!start_block.ownerModule().error_tracing) return;
1984119847
1984219848 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere
......@@ -19846,10 +19852,10 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1984619852
1984719853fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
1984819854 const pt = sema.pt;
19849 const mod = pt.zcu;
19850 const ip = &mod.intern_pool;
19851 assert(sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion);
19852 const err_set_ty = sema.fn_ret_ty.errorUnionSet(mod).toIntern();
19855 const zcu = pt.zcu;
19856 const ip = &zcu.intern_pool;
19857 assert(sema.fn_ret_ty.zigTypeTag(zcu) == .ErrorUnion);
19858 const err_set_ty = sema.fn_ret_ty.errorUnionSet(zcu).toIntern();
1985319859 switch (err_set_ty) {
1985419860 .adhoc_inferred_error_set_type => {
1985519861 const ies = sema.fn_ret_ty_ies.?;
......@@ -19867,11 +19873,11 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
1986719873fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void {
1986819874 const arena = sema.arena;
1986919875 const pt = sema.pt;
19870 const mod = pt.zcu;
19871 const ip = &mod.intern_pool;
19872 switch (op_ty.zigTypeTag(mod)) {
19876 const zcu = pt.zcu;
19877 const ip = &zcu.intern_pool;
19878 switch (op_ty.zigTypeTag(zcu)) {
1987319879 .ErrorSet => try ies.addErrorSet(op_ty, ip, arena),
19874 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, arena),
19880 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(zcu), ip, arena),
1987519881 else => {},
1987619882 }
1987719883}
......@@ -19887,8 +19893,8 @@ fn analyzeRet(
1988719893 // add the error tag to the inferred error set of the in-scope function, so
1988819894 // that the coercion below works correctly.
1988919895 const pt = sema.pt;
19890 const mod = pt.zcu;
19891 if (sema.fn_ret_ty_ies != null and sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion) {
19896 const zcu = pt.zcu;
19897 if (sema.fn_ret_ty_ies != null and sema.fn_ret_ty.zigTypeTag(zcu) == .ErrorUnion) {
1989219898 try sema.addToInferredErrorSet(uncasted_operand);
1989319899 }
1989419900 const operand = sema.coerceExtra(block, sema.fn_ret_ty, uncasted_operand, operand_src, .{ .is_ret = true }) catch |err| switch (err) {
......@@ -19903,7 +19909,7 @@ fn analyzeRet(
1990319909 });
1990419910 inlining.comptime_result = operand;
1990519911
19906 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
19912 if (sema.fn_ret_ty.isError(zcu) and ret_val.getErrorName(zcu) != .none) {
1990719913 try sema.comptime_err_ret_trace.append(src);
1990819914 }
1990919915 return error.ComptimeReturn;
......@@ -19955,7 +19961,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1995519961 defer tracy.end();
1995619962
1995719963 const pt = sema.pt;
19958 const mod = pt.zcu;
19964 const zcu = pt.zcu;
1995919965 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
1996019966 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
1996119967 const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node });
......@@ -19968,7 +19974,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1996819974 const elem_ty = blk: {
1996919975 const air_inst = try sema.resolveInst(extra.data.elem_type);
1997019976 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {
19971 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) {
19977 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(zcu)) {
1997219978 try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
1997319979 }
1997419980 return err;
......@@ -19977,10 +19983,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1997719983 break :blk ty;
1997819984 };
1997919985
19980 if (elem_ty.zigTypeTag(mod) == .NoReturn)
19986 if (elem_ty.zigTypeTag(zcu) == .NoReturn)
1998119987 return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});
1998219988
19983 const target = mod.getTarget();
19989 const target = zcu.getTarget();
1998419990
1998519991 var extra_i = extra.end;
1998619992
......@@ -20003,14 +20009,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2000320009 });
2000420010 // Check if this happens to be the lazy alignment of our element type, in
2000520011 // which case we can make this 0 without resolving it.
20006 switch (mod.intern_pool.indexToKey(val.toIntern())) {
20012 switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2000720013 .int => |int| switch (int.storage) {
2000820014 .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.toIntern()) break :blk .none,
2000920015 else => {},
2001020016 },
2001120017 else => {},
2001220018 }
20013 const align_bytes = (try val.getUnsignedIntAdvanced(pt, .sema)).?;
20019 const align_bytes = (try val.getUnsignedIntSema(pt)).?;
2001420020 break :blk try sema.validateAlignAllowZero(block, align_src, align_bytes);
2001520021 } else .none;
2001620022
......@@ -20018,7 +20024,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2001820024 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
2001920025 extra_i += 1;
2002020026 break :blk try sema.resolveAddressSpace(block, addrspace_src, ref, .pointer);
20021 } else if (elem_ty.zigTypeTag(mod) == .Fn and target.cpu.arch == .avr) .flash else .generic;
20027 } else if (elem_ty.zigTypeTag(zcu) == .Fn and target.cpu.arch == .avr) .flash else .generic;
2002220028
2002320029 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {
2002420030 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
......@@ -20044,7 +20050,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2004420050 elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size,
2004520051 });
2004620052 }
20047 const elem_bit_size = try elem_ty.bitSizeAdvanced(pt, .sema);
20053 const elem_bit_size = try elem_ty.bitSizeSema(pt);
2004820054 if (elem_bit_size > host_size * 8 - bit_offset) {
2004920055 return sema.fail(block, bitoffset_src, "packed type '{}' at bit offset {} ends {} bits after the end of a {} byte host integer", .{
2005020056 elem_ty.fmt(pt), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,
......@@ -20052,11 +20058,11 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2005220058 }
2005320059 }
2005420060
20055 if (elem_ty.zigTypeTag(mod) == .Fn) {
20061 if (elem_ty.zigTypeTag(zcu) == .Fn) {
2005620062 if (inst_data.size != .One) {
2005720063 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
2005820064 }
20059 } else if (inst_data.size == .Many and elem_ty.zigTypeTag(mod) == .Opaque) {
20065 } else if (inst_data.size == .Many and elem_ty.zigTypeTag(zcu) == .Opaque) {
2006020066 return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{});
2006120067 } else if (inst_data.size == .C) {
2006220068 if (!try sema.validateExternType(elem_ty, .other)) {
......@@ -20071,7 +20077,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2007120077 };
2007220078 return sema.failWithOwnedErrorMsg(block, msg);
2007320079 }
20074 if (elem_ty.zigTypeTag(mod) == .Opaque) {
20080 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
2007520081 return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{});
2007620082 }
2007720083 }
......@@ -20113,9 +20119,9 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2011320119 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
2011420120 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
2011520121 const pt = sema.pt;
20116 const mod = pt.zcu;
20122 const zcu = pt.zcu;
2011720123
20118 switch (obj_ty.zigTypeTag(mod)) {
20124 switch (obj_ty.zigTypeTag(zcu)) {
2011920125 .Struct => return sema.structInitEmpty(block, obj_ty, src, src),
2012020126 .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty),
2012120127 .Void => return Air.internedToRef(Value.void.toIntern()),
......@@ -20129,7 +20135,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
2012920135 defer tracy.end();
2013020136
2013120137 const pt = sema.pt;
20132 const mod = pt.zcu;
20138 const zcu = pt.zcu;
2013320139 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2013420140 const src = block.nodeOffset(inst_data.src_node);
2013520141 const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
......@@ -20138,21 +20144,21 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
2013820144 else => |e| return e,
2013920145 };
2014020146 const init_ty = if (is_byref) ty: {
20141 const ptr_ty = ty_operand.optEuBaseType(mod);
20142 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction
20143 if (!ptr_ty.isSlice(mod)) {
20144 break :ty ptr_ty.childType(mod);
20147 const ptr_ty = ty_operand.optEuBaseType(zcu);
20148 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
20149 if (!ptr_ty.isSlice(zcu)) {
20150 break :ty ptr_ty.childType(zcu);
2014520151 }
2014620152 // To make `&.{}` a `[:s]T`, the init should be a `[0:s]T`.
2014720153 break :ty try pt.arrayType(.{
2014820154 .len = 0,
20149 .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
20150 .child = ptr_ty.childType(mod).toIntern(),
20155 .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
20156 .child = ptr_ty.childType(zcu).toIntern(),
2015120157 });
2015220158 } else ty_operand;
20153 const obj_ty = init_ty.optEuBaseType(mod);
20159 const obj_ty = init_ty.optEuBaseType(zcu);
2015420160
20155 const empty_ref = switch (obj_ty.zigTypeTag(mod)) {
20161 const empty_ref = switch (obj_ty.zigTypeTag(zcu)) {
2015620162 .Struct => try sema.structInitEmpty(block, obj_ty, src, src),
2015720163 .Array, .Vector => try sema.arrayInitEmpty(block, src, obj_ty),
2015820164 .Union => return sema.fail(block, src, "union initializer must initialize one field", .{}),
......@@ -20176,13 +20182,13 @@ fn structInitEmpty(
2017620182 init_src: LazySrcLoc,
2017720183) CompileError!Air.Inst.Ref {
2017820184 const pt = sema.pt;
20179 const mod = pt.zcu;
20185 const zcu = pt.zcu;
2018020186 const gpa = sema.gpa;
2018120187 // This logic must be synchronized with that in `zirStructInit`.
2018220188 try struct_ty.resolveFields(pt);
2018320189
2018420190 // The init values to use for the struct instance.
20185 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount(mod));
20191 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount(zcu));
2018620192 defer gpa.free(field_inits);
2018720193 @memset(field_inits, .none);
2018820194
......@@ -20191,10 +20197,10 @@ fn structInitEmpty(
2019120197
2019220198fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) CompileError!Air.Inst.Ref {
2019320199 const pt = sema.pt;
20194 const mod = pt.zcu;
20195 const arr_len = obj_ty.arrayLen(mod);
20200 const zcu = pt.zcu;
20201 const arr_len = obj_ty.arrayLen(zcu);
2019620202 if (arr_len != 0) {
20197 if (obj_ty.zigTypeTag(mod) == .Array) {
20203 if (obj_ty.zigTypeTag(zcu) == .Array) {
2019820204 return sema.fail(block, src, "expected {d} array elements; found 0", .{arr_len});
2019920205 } else {
2020020206 return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len});
......@@ -20235,14 +20241,14 @@ fn unionInit(
2023520241 field_src: LazySrcLoc,
2023620242) CompileError!Air.Inst.Ref {
2023720243 const pt = sema.pt;
20238 const mod = pt.zcu;
20239 const ip = &mod.intern_pool;
20244 const zcu = pt.zcu;
20245 const ip = &zcu.intern_pool;
2024020246 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);
20241 const field_ty = Type.fromInterned(mod.typeToUnion(union_ty).?.field_types.get(ip)[field_index]);
20247 const field_ty = Type.fromInterned(zcu.typeToUnion(union_ty).?.field_types.get(ip)[field_index]);
2024220248 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
2024320249
2024420250 if (try sema.resolveValue(init)) |init_val| {
20245 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
20251 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
2024620252 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
2024720253 return Air.internedToRef((try pt.intern(.{ .un = .{
2024820254 .ty = union_ty.toIntern(),
......@@ -20269,8 +20275,8 @@ fn zirStructInit(
2026920275 const src = block.nodeOffset(inst_data.src_node);
2027020276
2027120277 const pt = sema.pt;
20272 const mod = pt.zcu;
20273 const ip = &mod.intern_pool;
20278 const zcu = pt.zcu;
20279 const ip = &zcu.intern_pool;
2027420280 const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data;
2027520281 const first_field_type_data = zir_datas[@intFromEnum(first_item.field_type)].pl_node;
2027620282 const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;
......@@ -20281,26 +20287,26 @@ fn zirStructInit(
2028120287 },
2028220288 else => |e| return e,
2028320289 };
20284 const resolved_ty = result_ty.optEuBaseType(mod);
20290 const resolved_ty = result_ty.optEuBaseType(zcu);
2028520291 try resolved_ty.resolveLayout(pt);
2028620292
20287 if (resolved_ty.zigTypeTag(mod) == .Struct) {
20293 if (resolved_ty.zigTypeTag(zcu) == .Struct) {
2028820294 // This logic must be synchronized with that in `zirStructInitEmpty`.
2028920295
2029020296 // Maps field index to field_type index of where it was already initialized.
2029120297 // For making sure all fields are accounted for and no fields are duplicated.
20292 const found_fields = try gpa.alloc(Zir.Inst.Index, resolved_ty.structFieldCount(mod));
20298 const found_fields = try gpa.alloc(Zir.Inst.Index, resolved_ty.structFieldCount(zcu));
2029320299 defer gpa.free(found_fields);
2029420300
2029520301 // The init values to use for the struct instance.
20296 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount(mod));
20302 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount(zcu));
2029720303 defer gpa.free(field_inits);
2029820304 @memset(field_inits, .none);
2029920305
2030020306 var field_i: u32 = 0;
2030120307 var extra_index = extra.end;
2030220308
20303 const is_packed = resolved_ty.containerLayout(mod) == .@"packed";
20309 const is_packed = resolved_ty.containerLayout(zcu) == .@"packed";
2030420310 while (field_i < extra.data.fields_len) : (field_i += 1) {
2030520311 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index);
2030620312 extra_index = item.end;
......@@ -20314,14 +20320,14 @@ fn zirStructInit(
2031420320 sema.code.nullTerminatedString(field_type_extra.name_start),
2031520321 .no_embedded_nulls,
2031620322 );
20317 const field_index = if (resolved_ty.isTuple(mod))
20323 const field_index = if (resolved_ty.isTuple(zcu))
2031820324 try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src)
2031920325 else
2032020326 try sema.structFieldIndex(block, resolved_ty, field_name, field_src);
2032120327 assert(field_inits[field_index] == .none);
2032220328 found_fields[field_index] = item.data.field_type;
2032320329 const uncoerced_init = try sema.resolveInst(item.data.init);
20324 const field_ty = resolved_ty.structFieldType(field_index, mod);
20330 const field_ty = resolved_ty.structFieldType(field_index, zcu);
2032520331 field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src);
2032620332 if (!is_packed) {
2032720333 try resolved_ty.resolveStructFieldInits(pt);
......@@ -20332,7 +20338,7 @@ fn zirStructInit(
2033220338 });
2033320339 };
2033420340
20335 if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) {
20341 if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, zcu), zcu)) {
2033620342 return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index);
2033720343 }
2033820344 }
......@@ -20340,7 +20346,7 @@ fn zirStructInit(
2034020346 }
2034120347
2034220348 return sema.finishStructInit(block, src, src, field_inits, resolved_ty, result_ty, is_ref);
20343 } else if (resolved_ty.zigTypeTag(mod) == .Union) {
20349 } else if (resolved_ty.zigTypeTag(zcu) == .Union) {
2034420350 if (extra.data.fields_len != 1) {
2034520351 return sema.fail(block, src, "union initialization expects exactly one field", .{});
2034620352 }
......@@ -20357,11 +20363,11 @@ fn zirStructInit(
2035720363 .no_embedded_nulls,
2035820364 );
2035920365 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
20360 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
20366 const tag_ty = resolved_ty.unionTagTypeHypothetical(zcu);
2036120367 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
20362 const field_ty = Type.fromInterned(mod.typeToUnion(resolved_ty).?.field_types.get(ip)[field_index]);
20368 const field_ty = Type.fromInterned(zcu.typeToUnion(resolved_ty).?.field_types.get(ip)[field_index]);
2036320369
20364 if (field_ty.zigTypeTag(mod) == .NoReturn) {
20370 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
2036520371 return sema.failWithOwnedErrorMsg(block, msg: {
2036620372 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2036720373 errdefer msg.destroy(sema.gpa);
......@@ -20388,7 +20394,7 @@ fn zirStructInit(
2038820394 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
2038920395 }
2039020396
20391 if (try sema.typeRequiresComptime(resolved_ty)) {
20397 if (try resolved_ty.comptimeOnlySema(pt)) {
2039220398 return sema.failWithNeededComptime(block, field_src, .{
2039320399 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
2039420400 });
......@@ -20397,7 +20403,7 @@ fn zirStructInit(
2039720403 try sema.validateRuntimeValue(block, field_src, init_inst);
2039820404
2039920405 if (is_ref) {
20400 const target = mod.getTarget();
20406 const target = zcu.getTarget();
2040120407 const alloc_ty = try pt.ptrTypeSema(.{
2040220408 .child = result_ty.toIntern(),
2040320409 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20429,10 +20435,10 @@ fn finishStructInit(
2042920435 is_ref: bool,
2043020436) CompileError!Air.Inst.Ref {
2043120437 const pt = sema.pt;
20432 const mod = pt.zcu;
20433 const ip = &mod.intern_pool;
20438 const zcu = pt.zcu;
20439 const ip = &zcu.intern_pool;
2043420440
20435 var root_msg: ?*Module.ErrorMsg = null;
20441 var root_msg: ?*Zcu.ErrorMsg = null;
2043620442 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
2043720443
2043820444 switch (ip.indexToKey(struct_ty.toIntern())) {
......@@ -20545,7 +20551,7 @@ fn finishStructInit(
2054520551 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
2054620552 };
2054720553
20548 if (try sema.typeRequiresComptime(struct_ty)) {
20554 if (try struct_ty.comptimeOnlySema(pt)) {
2054920555 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{
2055020556 .init_node_offset = init_src.offset.node_offset.x,
2055120557 .elem_index = @intCast(runtime_index),
......@@ -20560,7 +20566,7 @@ fn finishStructInit(
2056020566
2056120567 if (is_ref) {
2056220568 try struct_ty.resolveLayout(pt);
20563 const target = mod.getTarget();
20569 const target = zcu.getTarget();
2056420570 const alloc_ty = try pt.ptrTypeSema(.{
2056520571 .child = result_ty.toIntern(),
2056620572 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20612,9 +20618,9 @@ fn structInitAnon(
2061220618 is_ref: bool,
2061320619) CompileError!Air.Inst.Ref {
2061420620 const pt = sema.pt;
20615 const mod = pt.zcu;
20621 const zcu = pt.zcu;
2061620622 const gpa = sema.gpa;
20617 const ip = &mod.intern_pool;
20623 const ip = &zcu.intern_pool;
2061820624 const zir_datas = sema.code.instructions.items(.data);
2061920625
2062020626 const types = try sema.arena.alloc(InternPool.Index, extra_data.fields_len);
......@@ -20642,11 +20648,11 @@ fn structInitAnon(
2064220648 },
2064320649 };
2064420650
20645 field_name.* = try mod.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
20651 field_name.* = try zcu.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
2064620652
2064720653 const init = try sema.resolveInst(item.data.init);
2064820654 field_ty.* = sema.typeOf(init).toIntern();
20649 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
20655 if (Type.fromInterned(field_ty.*).zigTypeTag(zcu) == .Opaque) {
2065020656 const msg = msg: {
2065120657 const field_src = block.src(.{ .init_elem = .{
2065220658 .init_node_offset = src.offset.node_offset.x,
......@@ -20690,7 +20696,7 @@ fn structInitAnon(
2069020696 } }));
2069120697
2069220698 if (is_ref) {
20693 const target = mod.getTarget();
20699 const target = zcu.getTarget();
2069420700 const alloc_ty = try pt.ptrTypeSema(.{
2069520701 .child = tuple_ty,
2069620702 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20740,7 +20746,7 @@ fn zirArrayInit(
2074020746 is_ref: bool,
2074120747) CompileError!Air.Inst.Ref {
2074220748 const pt = sema.pt;
20743 const mod = pt.zcu;
20749 const zcu = pt.zcu;
2074420750 const gpa = sema.gpa;
2074520751 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2074620752 const src = block.nodeOffset(inst_data.src_node);
......@@ -20756,14 +20762,14 @@ fn zirArrayInit(
2075620762 },
2075720763 else => |e| return e,
2075820764 };
20759 const array_ty = result_ty.optEuBaseType(mod);
20760 const is_tuple = array_ty.zigTypeTag(mod) == .Struct;
20761 const sentinel_val = array_ty.sentinel(mod);
20765 const array_ty = result_ty.optEuBaseType(zcu);
20766 const is_tuple = array_ty.zigTypeTag(zcu) == .Struct;
20767 const sentinel_val = array_ty.sentinel(zcu);
2076220768
20763 var root_msg: ?*Module.ErrorMsg = null;
20769 var root_msg: ?*Zcu.ErrorMsg = null;
2076420770 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
2076520771
20766 const final_len = try sema.usizeCast(block, src, array_ty.arrayLenIncludingSentinel(mod));
20772 const final_len = try sema.usizeCast(block, src, array_ty.arrayLenIncludingSentinel(zcu));
2076720773 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);
2076820774 defer gpa.free(resolved_args);
2076920775 for (resolved_args, 0..) |*dest, i| {
......@@ -20773,7 +20779,7 @@ fn zirArrayInit(
2077320779 } });
2077420780 // Less inits than needed.
2077520781 if (i + 2 > args.len) if (is_tuple) {
20776 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();
20782 const default_val = array_ty.structFieldDefaultValue(i, zcu).toIntern();
2077720783 if (default_val == .unreachable_value) {
2077820784 const template = "missing tuple field with index {d}";
2077920785 if (root_msg) |msg| {
......@@ -20793,12 +20799,12 @@ fn zirArrayInit(
2079320799 const arg = args[i + 1];
2079420800 const resolved_arg = try sema.resolveInst(arg);
2079520801 const elem_ty = if (is_tuple)
20796 array_ty.structFieldType(i, mod)
20802 array_ty.structFieldType(i, zcu)
2079720803 else
20798 array_ty.elemType2(mod);
20804 array_ty.elemType2(zcu);
2079920805 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
2080020806 if (is_tuple) {
20801 if (array_ty.structFieldIsComptime(i, mod))
20807 if (array_ty.structFieldIsComptime(i, zcu))
2080220808 try array_ty.resolveStructFieldInits(pt);
2080320809 if (try array_ty.structFieldValueComptime(pt, i)) |field_val| {
2080420810 const init_val = try sema.resolveValue(dest.*) orelse {
......@@ -20806,7 +20812,7 @@ fn zirArrayInit(
2080620812 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
2080720813 });
2080820814 };
20809 if (!field_val.eql(init_val, elem_ty, mod)) {
20815 if (!field_val.eql(init_val, elem_ty, zcu)) {
2081020816 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);
2081120817 }
2081220818 }
......@@ -20845,7 +20851,7 @@ fn zirArrayInit(
2084520851 } }));
2084620852
2084720853 if (is_ref) {
20848 const target = mod.getTarget();
20854 const target = zcu.getTarget();
2084920855 const alloc_ty = try pt.ptrTypeSema(.{
2085020856 .child = result_ty.toIntern(),
2085120857 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20856,7 +20862,7 @@ fn zirArrayInit(
2085620862 if (is_tuple) {
2085720863 for (resolved_args, 0..) |arg, i| {
2085820864 const elem_ptr_ty = try pt.ptrTypeSema(.{
20859 .child = array_ty.structFieldType(i, mod).toIntern(),
20865 .child = array_ty.structFieldType(i, zcu).toIntern(),
2086020866 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
2086120867 });
2086220868 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
......@@ -20869,7 +20875,7 @@ fn zirArrayInit(
2086920875 }
2087020876
2087120877 const elem_ptr_ty = try pt.ptrTypeSema(.{
20872 .child = array_ty.elemType2(mod).toIntern(),
20878 .child = array_ty.elemType2(zcu).toIntern(),
2087320879 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
2087420880 });
2087520881 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
......@@ -20906,9 +20912,9 @@ fn arrayInitAnon(
2090620912 is_ref: bool,
2090720913) CompileError!Air.Inst.Ref {
2090820914 const pt = sema.pt;
20909 const mod = pt.zcu;
20915 const zcu = pt.zcu;
2091020916 const gpa = sema.gpa;
20911 const ip = &mod.intern_pool;
20917 const ip = &zcu.intern_pool;
2091220918
2091320919 const types = try sema.arena.alloc(InternPool.Index, operands.len);
2091420920 const values = try sema.arena.alloc(InternPool.Index, operands.len);
......@@ -20919,7 +20925,7 @@ fn arrayInitAnon(
2091920925 const operand_src = src; // TODO better source location
2092020926 const elem = try sema.resolveInst(operand);
2092120927 types[i] = sema.typeOf(elem).toIntern();
20922 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
20928 if (Type.fromInterned(types[i]).zigTypeTag(zcu) == .Opaque) {
2092320929 const msg = msg: {
2092420930 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2092520931 errdefer msg.destroy(gpa);
......@@ -21003,8 +21009,8 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2100321009
2100421010fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2100521011 const pt = sema.pt;
21006 const mod = pt.zcu;
21007 const ip = &mod.intern_pool;
21012 const zcu = pt.zcu;
21013 const ip = &zcu.intern_pool;
2100821014 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2100921015 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
2101021016 const ty_src = block.nodeOffset(inst_data.src_node);
......@@ -21017,7 +21023,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
2101721023 error.GenericPoison => return .generic_poison_type,
2101821024 else => |e| return e,
2101921025 };
21020 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod);
21026 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(zcu);
2102121027 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);
2102221028 const field_name = try ip.getOrPutString(sema.gpa, pt.tid, zir_field_name, .no_embedded_nulls);
2102321029 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);
......@@ -21032,12 +21038,12 @@ fn fieldType(
2103221038 ty_src: LazySrcLoc,
2103321039) CompileError!Air.Inst.Ref {
2103421040 const pt = sema.pt;
21035 const mod = pt.zcu;
21036 const ip = &mod.intern_pool;
21041 const zcu = pt.zcu;
21042 const ip = &zcu.intern_pool;
2103721043 var cur_ty = aggregate_ty;
2103821044 while (true) {
2103921045 try cur_ty.resolveFields(pt);
21040 switch (cur_ty.zigTypeTag(mod)) {
21046 switch (cur_ty.zigTypeTag(zcu)) {
2104121047 .Struct => switch (ip.indexToKey(cur_ty.toIntern())) {
2104221048 .anon_struct_type => |anon_struct| {
2104321049 const field_index = if (anon_struct.names.len == 0)
......@@ -21056,7 +21062,7 @@ fn fieldType(
2105621062 else => unreachable,
2105721063 },
2105821064 .Union => {
21059 const union_obj = mod.typeToUnion(cur_ty).?;
21065 const union_obj = zcu.typeToUnion(cur_ty).?;
2106021066 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
2106121067 return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name);
2106221068 const field_ty = union_obj.field_types.get(ip)[field_index];
......@@ -21069,7 +21075,7 @@ fn fieldType(
2106921075 continue;
2107021076 },
2107121077 .ErrorUnion => {
21072 cur_ty = cur_ty.errorUnionPayload(mod);
21078 cur_ty = cur_ty.errorUnionPayload(zcu);
2107321079 continue;
2107421080 },
2107521081 else => {},
......@@ -21086,8 +21092,8 @@ fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
2108621092
2108721093fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
2108821094 const pt = sema.pt;
21089 const mod = pt.zcu;
21090 const ip = &mod.intern_pool;
21095 const zcu = pt.zcu;
21096 const ip = &zcu.intern_pool;
2109121097 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
2109221098 try stack_trace_ty.resolveFields(pt);
2109321099 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
......@@ -21115,42 +21121,42 @@ fn zirFrame(
2111521121}
2111621122
2111721123fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21118 const pt = sema.pt;
21124 const zcu = sema.pt.zcu;
2111921125 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2112021126 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2112121127 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
21122 if (ty.isNoReturn(pt.zcu)) {
21123 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(pt)});
21128 if (ty.isNoReturn(zcu)) {
21129 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.pt)});
2112421130 }
21125 const val = try ty.lazyAbiAlignment(pt);
21131 const val = try ty.lazyAbiAlignment(sema.pt);
2112621132 return Air.internedToRef(val.toIntern());
2112721133}
2112821134
2112921135fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2113021136 const pt = sema.pt;
21131 const mod = pt.zcu;
21137 const zcu = pt.zcu;
2113221138 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2113321139 const src = block.nodeOffset(inst_data.src_node);
2113421140 const operand = try sema.resolveInst(inst_data.operand);
2113521141 const operand_ty = sema.typeOf(operand);
21136 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;
21137 const operand_scalar_ty = operand_ty.scalarType(mod);
21142 const is_vector = operand_ty.zigTypeTag(zcu) == .Vector;
21143 const operand_scalar_ty = operand_ty.scalarType(zcu);
2113821144 if (operand_scalar_ty.toIntern() != .bool_type) {
21139 return sema.fail(block, src, "expected 'bool', found '{}'", .{operand_scalar_ty.zigTypeTag(mod)});
21145 return sema.fail(block, src, "expected 'bool', found '{}'", .{operand_scalar_ty.zigTypeTag(zcu)});
2114021146 }
2114121147 if (try sema.resolveValue(operand)) |val| {
2114221148 if (!is_vector) {
21143 if (val.isUndef(mod)) return pt.undefRef(Type.u1);
21149 if (val.isUndef(zcu)) return pt.undefRef(Type.u1);
2114421150 if (val.toBool()) return Air.internedToRef((try pt.intValue(Type.u1, 1)).toIntern());
2114521151 return Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());
2114621152 }
21147 const len = operand_ty.vectorLen(mod);
21153 const len = operand_ty.vectorLen(zcu);
2114821154 const dest_ty = try pt.vectorType(.{ .child = .u1_type, .len = len });
21149 if (val.isUndef(mod)) return pt.undefRef(dest_ty);
21155 if (val.isUndef(zcu)) return pt.undefRef(dest_ty);
2115021156 const new_elems = try sema.arena.alloc(InternPool.Index, len);
2115121157 for (new_elems, 0..) |*new_elem, i| {
2115221158 const old_elem = try val.elemValue(pt, i);
21153 const new_val = if (old_elem.isUndef(mod))
21159 const new_val = if (old_elem.isUndef(zcu))
2115421160 try pt.undefValue(Type.u1)
2115521161 else if (old_elem.toBool())
2115621162 try pt.intValue(Type.u1, 1)
......@@ -21166,7 +21172,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2116621172 if (!is_vector) {
2116721173 return block.addUnOp(.int_from_bool, operand);
2116821174 }
21169 const len = operand_ty.vectorLen(mod);
21175 const len = operand_ty.vectorLen(zcu);
2117021176 const dest_ty = try pt.vectorType(.{ .child = .u1_type, .len = len });
2117121177 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2117221178 for (new_elems, 0..) |*new_elem, i| {
......@@ -21199,16 +21205,16 @@ fn zirAbs(
2119921205 inst: Zir.Inst.Index,
2120021206) CompileError!Air.Inst.Ref {
2120121207 const pt = sema.pt;
21202 const mod = pt.zcu;
21208 const zcu = pt.zcu;
2120321209 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2120421210 const operand = try sema.resolveInst(inst_data.operand);
2120521211 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2120621212 const operand_ty = sema.typeOf(operand);
21207 const scalar_ty = operand_ty.scalarType(mod);
21213 const scalar_ty = operand_ty.scalarType(zcu);
2120821214
21209 const result_ty = switch (scalar_ty.zigTypeTag(mod)) {
21215 const result_ty = switch (scalar_ty.zigTypeTag(zcu)) {
2121021216 .ComptimeFloat, .Float, .ComptimeInt => operand_ty,
21211 .Int => if (scalar_ty.isSignedInt(mod)) try operand_ty.toUnsigned(pt) else return operand,
21217 .Int => if (scalar_ty.isSignedInt(zcu)) try operand_ty.toUnsigned(pt) else return operand,
2121221218 else => return sema.fail(
2121321219 block,
2121421220 operand_src,
......@@ -21230,12 +21236,12 @@ fn maybeConstantUnaryMath(
2123021236 comptime eval: fn (Value, Type, Allocator, Zcu.PerThread) Allocator.Error!Value,
2123121237) CompileError!?Air.Inst.Ref {
2123221238 const pt = sema.pt;
21233 const mod = pt.zcu;
21234 switch (result_ty.zigTypeTag(mod)) {
21239 const zcu = pt.zcu;
21240 switch (result_ty.zigTypeTag(zcu)) {
2123521241 .Vector => if (try sema.resolveValue(operand)) |val| {
21236 const scalar_ty = result_ty.scalarType(mod);
21237 const vec_len = result_ty.vectorLen(mod);
21238 if (val.isUndef(mod))
21242 const scalar_ty = result_ty.scalarType(zcu);
21243 const vec_len = result_ty.vectorLen(zcu);
21244 if (val.isUndef(zcu))
2123921245 return try pt.undefRef(result_ty);
2124021246
2124121247 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
......@@ -21249,7 +21255,7 @@ fn maybeConstantUnaryMath(
2124921255 } })));
2125021256 },
2125121257 else => if (try sema.resolveValue(operand)) |operand_val| {
21252 if (operand_val.isUndef(mod))
21258 if (operand_val.isUndef(zcu))
2125321259 return try pt.undefRef(result_ty);
2125421260 const result_val = try eval(operand_val, result_ty, sema.arena, pt);
2125521261 return Air.internedToRef(result_val.toIntern());
......@@ -21269,14 +21275,14 @@ fn zirUnaryMath(
2126921275 defer tracy.end();
2127021276
2127121277 const pt = sema.pt;
21272 const mod = pt.zcu;
21278 const zcu = pt.zcu;
2127321279 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2127421280 const operand = try sema.resolveInst(inst_data.operand);
2127521281 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2127621282 const operand_ty = sema.typeOf(operand);
21277 const scalar_ty = operand_ty.scalarType(mod);
21283 const scalar_ty = operand_ty.scalarType(zcu);
2127821284
21279 switch (scalar_ty.zigTypeTag(mod)) {
21285 switch (scalar_ty.zigTypeTag(zcu)) {
2128021286 .ComptimeFloat, .Float => {},
2128121287 else => return sema.fail(
2128221288 block,
......@@ -21359,9 +21365,9 @@ fn zirReify(
2135921365 inst: Zir.Inst.Index,
2136021366) CompileError!Air.Inst.Ref {
2136121367 const pt = sema.pt;
21362 const mod = pt.zcu;
21368 const zcu = pt.zcu;
2136321369 const gpa = sema.gpa;
21364 const ip = &mod.intern_pool;
21370 const ip = &zcu.intern_pool;
2136521371 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
2136621372 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
2136721373 const tracked_inst = try block.trackZir(inst);
......@@ -21388,7 +21394,7 @@ fn zirReify(
2138821394 if (try sema.anyUndef(block, operand_src, Value.fromInterned(union_val.val))) {
2138921395 return sema.failWithUseOfUndef(block, operand_src);
2139021396 }
21391 const tag_index = type_info_ty.unionTagFieldIndex(Value.fromInterned(union_val.tag), mod).?;
21397 const tag_index = type_info_ty.unionTagFieldIndex(Value.fromInterned(union_val.tag), zcu).?;
2139221398 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
2139321399 .Type => return .type_type,
2139421400 .Void => return .void_type,
......@@ -21411,7 +21417,7 @@ fn zirReify(
2141121417 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls)).?,
2141221418 );
2141321419
21414 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
21420 const signedness = zcu.toEnum(std.builtin.Signedness, signedness_val);
2141521421 const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt));
2141621422 const ty = try pt.intType(signedness, bits);
2141721423 return Air.internedToRef(ty.toIntern());
......@@ -21495,7 +21501,7 @@ fn zirReify(
2149521501 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
2149621502 }
2149721503
21498 const alignment_val_int = (try alignment_val.getUnsignedIntAdvanced(pt, .sema)).?;
21504 const alignment_val_int = try alignment_val.toUnsignedIntSema(pt);
2149921505 if (alignment_val_int > 0 and !math.isPowerOfTwo(alignment_val_int)) {
2150021506 return sema.fail(block, src, "alignment value '{d}' is not a power of two or zero", .{alignment_val_int});
2150121507 }
......@@ -21506,14 +21512,14 @@ fn zirReify(
2150621512 try elem_ty.resolveLayout(pt);
2150721513 }
2150821514
21509 const ptr_size = mod.toEnum(std.builtin.Type.Pointer.Size, size_val);
21515 const ptr_size = zcu.toEnum(std.builtin.Type.Pointer.Size, size_val);
2151021516
2151121517 const actual_sentinel: InternPool.Index = s: {
21512 if (!sentinel_val.isNull(mod)) {
21518 if (!sentinel_val.isNull(zcu)) {
2151321519 if (ptr_size == .One or ptr_size == .C) {
2151421520 return sema.fail(block, src, "sentinels are only allowed on slices and unknown-length pointers", .{});
2151521521 }
21516 const sentinel_ptr_val = sentinel_val.optionalValue(mod).?;
21522 const sentinel_ptr_val = sentinel_val.optionalValue(zcu).?;
2151721523 const ptr_ty = try pt.singleMutPtrType(elem_ty);
2151821524 const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?;
2151921525 break :s sent_val.toIntern();
......@@ -21521,13 +21527,13 @@ fn zirReify(
2152121527 break :s .none;
2152221528 };
2152321529
21524 if (elem_ty.zigTypeTag(mod) == .NoReturn) {
21530 if (elem_ty.zigTypeTag(zcu) == .NoReturn) {
2152521531 return sema.fail(block, src, "pointer to noreturn not allowed", .{});
21526 } else if (elem_ty.zigTypeTag(mod) == .Fn) {
21532 } else if (elem_ty.zigTypeTag(zcu) == .Fn) {
2152721533 if (ptr_size != .One) {
2152821534 return sema.fail(block, src, "function pointers must be single pointers", .{});
2152921535 }
21530 } else if (ptr_size == .Many and elem_ty.zigTypeTag(mod) == .Opaque) {
21536 } else if (ptr_size == .Many and elem_ty.zigTypeTag(zcu) == .Opaque) {
2153121537 return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{});
2153221538 } else if (ptr_size == .C) {
2153321539 if (!try sema.validateExternType(elem_ty, .other)) {
......@@ -21542,7 +21548,7 @@ fn zirReify(
2154221548 };
2154321549 return sema.failWithOwnedErrorMsg(block, msg);
2154421550 }
21545 if (elem_ty.zigTypeTag(mod) == .Opaque) {
21551 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
2154621552 return sema.fail(block, src, "C pointers cannot point to opaque types", .{});
2154721553 }
2154821554 }
......@@ -21555,7 +21561,7 @@ fn zirReify(
2155521561 .is_const = is_const_val.toBool(),
2155621562 .is_volatile = is_volatile_val.toBool(),
2155721563 .alignment = abi_align,
21558 .address_space = mod.toEnum(std.builtin.AddressSpace, address_space_val),
21564 .address_space = zcu.toEnum(std.builtin.AddressSpace, address_space_val),
2155921565 .is_allowzero = is_allowzero_val.toBool(),
2156021566 },
2156121567 });
......@@ -21578,7 +21584,7 @@ fn zirReify(
2157821584
2157921585 const len = try len_val.toUnsignedIntSema(pt);
2158021586 const child_ty = child_val.toType();
21581 const sentinel = if (sentinel_val.optionalValue(mod)) |p| blk: {
21587 const sentinel = if (sentinel_val.optionalValue(zcu)) |p| blk: {
2158221588 const ptr_ty = try pt.singleMutPtrType(child_ty);
2158321589 break :blk (try sema.pointerDeref(block, src, p, ptr_ty)).?;
2158421590 } else null;
......@@ -21616,7 +21622,7 @@ fn zirReify(
2161621622 const error_set_ty = error_set_val.toType();
2161721623 const payload_ty = payload_val.toType();
2161821624
21619 if (error_set_ty.zigTypeTag(mod) != .ErrorSet) {
21625 if (error_set_ty.zigTypeTag(zcu) != .ErrorSet) {
2162021626 return sema.fail(block, src, "Type.ErrorUnion.error_set must be an error set type", .{});
2162121627 }
2162221628
......@@ -21624,14 +21630,14 @@ fn zirReify(
2162421630 return Air.internedToRef(ty.toIntern());
2162521631 },
2162621632 .ErrorSet => {
21627 const payload_val = Value.fromInterned(union_val.val).optionalValue(mod) orelse
21633 const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse
2162821634 return Air.internedToRef(Type.anyerror.toIntern());
2162921635
2163021636 const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{
2163121637 .needed_comptime_reason = "error set contents must be comptime-known",
2163221638 });
2163321639
21634 const len = try sema.usizeCast(block, src, names_val.typeOf(mod).arrayLen(mod));
21640 const len = try sema.usizeCast(block, src, names_val.typeOf(zcu).arrayLen(zcu));
2163521641 var names: InferredErrorSet.NameMap = .{};
2163621642 try names.ensureUnusedCapacity(sema.arena, len);
2163721643 for (0..len) |i| {
......@@ -21680,14 +21686,14 @@ fn zirReify(
2168021686 try ip.getOrPutString(gpa, pt.tid, "is_tuple", .no_embedded_nulls),
2168121687 ).?);
2168221688
21683 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);
21689 const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val);
2168421690
2168521691 // Decls
2168621692 if (try decls_val.sliceLen(pt) > 0) {
2168721693 return sema.fail(block, src, "reified structs must have no decls", .{});
2168821694 }
2168921695
21690 if (layout != .@"packed" and !backing_integer_val.isNull(mod)) {
21696 if (layout != .@"packed" and !backing_integer_val.isNull(zcu)) {
2169121697 return sema.fail(block, src, "non-packed struct does not support backing integer type", .{});
2169221698 }
2169321699
......@@ -21762,8 +21768,8 @@ fn zirReify(
2176221768 const new_namespace_index = try pt.createNamespace(.{
2176321769 .parent = block.namespace.toOptional(),
2176421770 .owner_type = wip_ty.index,
21765 .file_scope = block.getFileScopeIndex(mod),
21766 .generation = mod.generation,
21771 .file_scope = block.getFileScopeIndex(zcu),
21772 .generation = zcu.generation,
2176721773 });
2176821774
2176921775 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -21791,7 +21797,7 @@ fn zirReify(
2179121797 if (try decls_val.sliceLen(pt) > 0) {
2179221798 return sema.fail(block, src, "reified unions must have no decls", .{});
2179321799 }
21794 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);
21800 const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val);
2179521801
2179621802 const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{
2179721803 .needed_comptime_reason = "union fields must be comptime-known",
......@@ -21828,19 +21834,19 @@ fn zirReify(
2182821834 }
2182921835
2183021836 const is_var_args = is_var_args_val.toBool();
21831 const cc = mod.toEnum(std.builtin.CallingConvention, calling_convention_val);
21837 const cc = zcu.toEnum(std.builtin.CallingConvention, calling_convention_val);
2183221838 if (is_var_args) {
2183321839 try sema.checkCallConvSupportsVarArgs(block, src, cc);
2183421840 }
2183521841
21836 const return_type = return_type_val.optionalValue(mod) orelse
21842 const return_type = return_type_val.optionalValue(zcu) orelse
2183721843 return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{});
2183821844
2183921845 const params_val = try sema.derefSliceAsArray(block, operand_src, params_slice_val, .{
2184021846 .needed_comptime_reason = "function parameters must be comptime-known",
2184121847 });
2184221848
21843 const args_len = try sema.usizeCast(block, src, params_val.typeOf(mod).arrayLen(mod));
21849 const args_len = try sema.usizeCast(block, src, params_val.typeOf(zcu).arrayLen(zcu));
2184421850 const param_types = try sema.arena.alloc(InternPool.Index, args_len);
2184521851
2184621852 var noalias_bits: u32 = 0;
......@@ -21864,12 +21870,12 @@ fn zirReify(
2186421870 return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{});
2186521871 }
2186621872
21867 const param_type_val = opt_param_type_val.optionalValue(mod) orelse
21873 const param_type_val = opt_param_type_val.optionalValue(zcu) orelse
2186821874 return sema.fail(block, src, "Type.Fn.Param.type must be non-null for @Type", .{});
2186921875 param_type.* = param_type_val.toIntern();
2187021876
2187121877 if (param_is_noalias_val.toBool()) {
21872 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(mod)) {
21878 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(zcu)) {
2187321879 return sema.fail(block, src, "non-pointer parameter declared noalias", .{});
2187421880 }
2187521881 noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse
......@@ -21901,13 +21907,13 @@ fn reifyEnum(
2190121907 name_strategy: Zir.Inst.NameStrategy,
2190221908) CompileError!Air.Inst.Ref {
2190321909 const pt = sema.pt;
21904 const mod = pt.zcu;
21910 const zcu = pt.zcu;
2190521911 const gpa = sema.gpa;
21906 const ip = &mod.intern_pool;
21912 const ip = &zcu.intern_pool;
2190721913
2190821914 // This logic must stay in sync with the structure of `std.builtin.Type.Enum` - search for `fieldValue`.
2190921915
21910 const fields_len: u32 = @intCast(fields_val.typeOf(mod).arrayLen(mod));
21916 const fields_len: u32 = @intCast(fields_val.typeOf(zcu).arrayLen(zcu));
2191121917
2191221918 // The validation work here is non-trivial, and it's possible the type already exists.
2191321919 // So in this first pass, let's just construct a hash to optimize for this case. If the
......@@ -21957,7 +21963,7 @@ fn reifyEnum(
2195721963 var done = false;
2195821964 errdefer if (!done) wip_ty.cancel(ip, pt.tid);
2195921965
21960 if (tag_ty.zigTypeTag(mod) != .Int) {
21966 if (tag_ty.zigTypeTag(zcu) != .Int) {
2196121967 return sema.fail(block, src, "Type.Enum.tag_type must be an integer type", .{});
2196221968 }
2196321969
......@@ -21972,8 +21978,8 @@ fn reifyEnum(
2197221978 const new_namespace_index = try pt.createNamespace(.{
2197321979 .parent = block.namespace.toOptional(),
2197421980 .owner_type = wip_ty.index,
21975 .file_scope = block.getFileScopeIndex(mod),
21976 .generation = mod.generation,
21981 .file_scope = block.getFileScopeIndex(zcu),
21982 .generation = zcu.generation,
2197721983 });
2197821984
2197921985 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
......@@ -22023,14 +22029,14 @@ fn reifyEnum(
2202322029 }
2202422030 }
2202522031
22026 if (!is_exhaustive and fields_len > 1 and std.math.log2_int(u64, fields_len) == tag_ty.bitSize(pt)) {
22032 if (!is_exhaustive and fields_len > 1 and std.math.log2_int(u64, fields_len) == tag_ty.bitSize(zcu)) {
2202722033 return sema.fail(block, src, "non-exhaustive enum specified every value", .{});
2202822034 }
2202922035
2203022036 codegen_type: {
22031 if (mod.comp.config.use_llvm) break :codegen_type;
22037 if (zcu.comp.config.use_llvm) break :codegen_type;
2203222038 if (block.ownerModule().strip) break :codegen_type;
22033 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
22039 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
2203422040 }
2203522041 return Air.internedToRef(wip_ty.index);
2203622042}
......@@ -22046,13 +22052,13 @@ fn reifyUnion(
2204622052 name_strategy: Zir.Inst.NameStrategy,
2204722053) CompileError!Air.Inst.Ref {
2204822054 const pt = sema.pt;
22049 const mod = pt.zcu;
22055 const zcu = pt.zcu;
2205022056 const gpa = sema.gpa;
22051 const ip = &mod.intern_pool;
22057 const ip = &zcu.intern_pool;
2205222058
2205322059 // This logic must stay in sync with the structure of `std.builtin.Type.Union` - search for `fieldValue`.
2205422060
22055 const fields_len: u32 = @intCast(fields_val.typeOf(mod).arrayLen(mod));
22061 const fields_len: u32 = @intCast(fields_val.typeOf(zcu).arrayLen(zcu));
2205622062
2205722063 // The validation work here is non-trivial, and it's possible the type already exists.
2205822064 // So in this first pass, let's just construct a hash to optimize for this case. If the
......@@ -22084,7 +22090,7 @@ fn reifyUnion(
2208422090 field_align_val.toIntern(),
2208522091 });
2208622092
22087 if (field_align_val.toUnsignedInt(pt) != 0) {
22093 if (field_align_val.toUnsignedInt(zcu) != 0) {
2208822094 any_aligns = true;
2208922095 }
2209022096 }
......@@ -22095,7 +22101,7 @@ fn reifyUnion(
2209522101 .flags = .{
2209622102 .layout = layout,
2209722103 .status = .none,
22098 .runtime_tag = if (opt_tag_type_val.optionalValue(mod) != null)
22104 .runtime_tag = if (opt_tag_type_val.optionalValue(zcu) != null)
2209922105 .tagged
2210022106 else if (layout != .auto)
2210122107 .none
......@@ -22139,7 +22145,7 @@ fn reifyUnion(
2213922145 const field_types = try sema.arena.alloc(InternPool.Index, fields_len);
2214022146 const field_aligns = if (any_aligns) try sema.arena.alloc(InternPool.Alignment, fields_len) else undefined;
2214122147
22142 const enum_tag_ty, const has_explicit_tag = if (opt_tag_type_val.optionalValue(mod)) |tag_type_val| tag_ty: {
22148 const enum_tag_ty, const has_explicit_tag = if (opt_tag_type_val.optionalValue(zcu)) |tag_type_val| tag_ty: {
2214322149 switch (ip.indexToKey(tag_type_val.toIntern())) {
2214422150 .enum_type => {},
2214522151 else => return sema.fail(block, src, "Type.Union.tag_type must be an enum type", .{}),
......@@ -22147,7 +22153,7 @@ fn reifyUnion(
2214722153 const enum_tag_ty = tag_type_val.toType();
2214822154
2214922155 // We simply track which fields of the tag type have been seen.
22150 const tag_ty_fields_len = enum_tag_ty.enumFieldCount(mod);
22156 const tag_ty_fields_len = enum_tag_ty.enumFieldCount(zcu);
2215122157 var seen_tags = try std.DynamicBitSetUnmanaged.initEmpty(sema.arena, tag_ty_fields_len);
2215222158
2215322159 for (field_types, 0..) |*field_ty, field_idx| {
......@@ -22159,7 +22165,7 @@ fn reifyUnion(
2215922165 // Don't pass a reason; first loop acts as an assertion that this is valid.
2216022166 const field_name = try sema.sliceToIpString(block, src, field_name_val, undefined);
2216122167
22162 const enum_index = enum_tag_ty.enumFieldIndex(field_name, mod) orelse {
22168 const enum_index = enum_tag_ty.enumFieldIndex(field_name, zcu) orelse {
2216322169 // TODO: better source location
2216422170 return sema.fail(block, src, "no field named '{}' in enum '{}'", .{
2216522171 field_name.fmt(ip), enum_tag_ty.fmt(pt),
......@@ -22187,7 +22193,7 @@ fn reifyUnion(
2218722193 errdefer msg.destroy(gpa);
2218822194 var it = seen_tags.iterator(.{ .kind = .unset });
2218922195 while (it.next()) |enum_index| {
22190 const field_name = enum_tag_ty.enumFieldName(enum_index, mod);
22196 const field_name = enum_tag_ty.enumFieldName(enum_index, zcu);
2219122197 try sema.addFieldErrNote(enum_tag_ty, enum_index, msg, "field '{}' missing, declared here", .{
2219222198 field_name.fmt(ip),
2219322199 });
......@@ -22234,7 +22240,7 @@ fn reifyUnion(
2223422240
2223522241 for (field_types) |field_ty_ip| {
2223622242 const field_ty = Type.fromInterned(field_ty_ip);
22237 if (field_ty.zigTypeTag(mod) == .Opaque) {
22243 if (field_ty.zigTypeTag(zcu) == .Opaque) {
2223822244 return sema.failWithOwnedErrorMsg(block, msg: {
2223922245 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
2224022246 errdefer msg.destroy(gpa);
......@@ -22277,17 +22283,17 @@ fn reifyUnion(
2227722283 const new_namespace_index = try pt.createNamespace(.{
2227822284 .parent = block.namespace.toOptional(),
2227922285 .owner_type = wip_ty.index,
22280 .file_scope = block.getFileScopeIndex(mod),
22281 .generation = mod.generation,
22286 .file_scope = block.getFileScopeIndex(zcu),
22287 .generation = zcu.generation,
2228222288 });
2228322289
2228422290 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
2228522291
22286 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
22292 try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
2228722293 codegen_type: {
22288 if (mod.comp.config.use_llvm) break :codegen_type;
22294 if (zcu.comp.config.use_llvm) break :codegen_type;
2228922295 if (block.ownerModule().strip) break :codegen_type;
22290 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
22296 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
2229122297 }
2229222298 try sema.declareDependency(.{ .interned = wip_ty.index });
2229322299 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -22306,13 +22312,13 @@ fn reifyStruct(
2230622312 is_tuple: bool,
2230722313) CompileError!Air.Inst.Ref {
2230822314 const pt = sema.pt;
22309 const mod = pt.zcu;
22315 const zcu = pt.zcu;
2231022316 const gpa = sema.gpa;
22311 const ip = &mod.intern_pool;
22317 const ip = &zcu.intern_pool;
2231222318
2231322319 // This logic must stay in sync with the structure of `std.builtin.Type.Struct` - search for `fieldValue`.
2231422320
22315 const fields_len: u32 = @intCast(fields_val.typeOf(mod).arrayLen(mod));
22321 const fields_len: u32 = @intCast(fields_val.typeOf(zcu).arrayLen(zcu));
2231622322
2231722323 // The validation work here is non-trivial, and it's possible the type already exists.
2231822324 // So in this first pass, let's just construct a hash to optimize for this case. If the
......@@ -22343,7 +22349,7 @@ fn reifyStruct(
2234322349 .needed_comptime_reason = "struct field name must be comptime-known",
2234422350 });
2234522351 const field_is_comptime = field_is_comptime_val.toBool();
22346 const field_default_value: InternPool.Index = if (field_default_value_val.optionalValue(mod)) |ptr_val| d: {
22352 const field_default_value: InternPool.Index = if (field_default_value_val.optionalValue(zcu)) |ptr_val| d: {
2234722353 const ptr_ty = try pt.singleConstPtrType(field_type_val.toType());
2234822354 // We need to do this deref here, so we won't check for this error case later on.
2234922355 const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime(
......@@ -22365,7 +22371,7 @@ fn reifyStruct(
2236522371
2236622372 if (field_is_comptime) any_comptime_fields = true;
2236722373 if (field_default_value != .none) any_default_inits = true;
22368 switch (try field_alignment_val.orderAgainstZeroAdvanced(pt, .sema)) {
22374 switch (try field_alignment_val.orderAgainstZeroSema(pt)) {
2236922375 .eq => {},
2237022376 .gt => any_aligned_fields = true,
2237122377 .lt => unreachable,
......@@ -22475,7 +22481,7 @@ fn reifyStruct(
2247522481
2247622482 const field_default: InternPool.Index = d: {
2247722483 if (!any_default_inits) break :d .none;
22478 const ptr_val = field_default_value_val.optionalValue(mod) orelse break :d .none;
22484 const ptr_val = field_default_value_val.optionalValue(zcu) orelse break :d .none;
2247922485 const ptr_ty = try pt.singleConstPtrType(field_ty);
2248022486 // Asserted comptime-dereferencable above.
2248122487 const val = (try sema.pointerDeref(block, src, ptr_val, ptr_ty)).?;
......@@ -22492,7 +22498,7 @@ fn reifyStruct(
2249222498 struct_type.field_inits.get(ip)[field_idx] = field_default;
2249322499 }
2249422500
22495 if (field_ty.zigTypeTag(mod) == .Opaque) {
22501 if (field_ty.zigTypeTag(zcu) == .Opaque) {
2249622502 return sema.failWithOwnedErrorMsg(block, msg: {
2249722503 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2249822504 errdefer msg.destroy(gpa);
......@@ -22501,7 +22507,7 @@ fn reifyStruct(
2250122507 break :msg msg;
2250222508 });
2250322509 }
22504 if (field_ty.zigTypeTag(mod) == .NoReturn) {
22510 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
2250522511 return sema.failWithOwnedErrorMsg(block, msg: {
2250622512 const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{});
2250722513 errdefer msg.destroy(gpa);
......@@ -22545,10 +22551,10 @@ fn reifyStruct(
2254522551 },
2254622552 else => return err,
2254722553 };
22548 fields_bit_sum += field_ty.bitSize(pt);
22554 fields_bit_sum += field_ty.bitSize(zcu);
2254922555 }
2255022556
22551 if (opt_backing_int_val.optionalValue(mod)) |backing_int_val| {
22557 if (opt_backing_int_val.optionalValue(zcu)) |backing_int_val| {
2255222558 const backing_int_ty = backing_int_val.toType();
2255322559 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
2255422560 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
......@@ -22561,17 +22567,17 @@ fn reifyStruct(
2256122567 const new_namespace_index = try pt.createNamespace(.{
2256222568 .parent = block.namespace.toOptional(),
2256322569 .owner_type = wip_ty.index,
22564 .file_scope = block.getFileScopeIndex(mod),
22565 .generation = mod.generation,
22570 .file_scope = block.getFileScopeIndex(zcu),
22571 .generation = zcu.generation,
2256622572 });
2256722573
2256822574 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
2256922575
22570 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
22576 try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
2257122577 codegen_type: {
22572 if (mod.comp.config.use_llvm) break :codegen_type;
22578 if (zcu.comp.config.use_llvm) break :codegen_type;
2257322579 if (block.ownerModule().strip) break :codegen_type;
22574 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
22580 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
2257522581 }
2257622582 try sema.declareDependency(.{ .interned = wip_ty.index });
2257722583 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -22649,8 +22655,8 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2264922655
2265022656fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2265122657 const pt = sema.pt;
22652 const mod = pt.zcu;
22653 const ip = &mod.intern_pool;
22658 const zcu = pt.zcu;
22659 const ip = &zcu.intern_pool;
2265422660
2265522661 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2265622662 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -22674,7 +22680,7 @@ fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2267422680
2267522681fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2267622682 const pt = sema.pt;
22677 const mod = pt.zcu;
22683 const zcu = pt.zcu;
2267822684 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2267922685 const src = block.nodeOffset(inst_data.src_node);
2268022686 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -22684,10 +22690,10 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2268422690 const operand_ty = sema.typeOf(operand);
2268522691
2268622692 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);
22687 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
22693 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2268822694
22689 const dest_scalar_ty = dest_ty.scalarType(mod);
22690 const operand_scalar_ty = operand_ty.scalarType(mod);
22695 const dest_scalar_ty = dest_ty.scalarType(zcu);
22696 const operand_scalar_ty = operand_ty.scalarType(zcu);
2269122697
2269222698 _ = try sema.checkIntType(block, src, dest_scalar_ty);
2269322699 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
......@@ -22695,14 +22701,14 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2269522701 if (try sema.resolveValue(operand)) |operand_val| {
2269622702 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate);
2269722703 return Air.internedToRef(result_val.toIntern());
22698 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
22704 } else if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
2269922705 return sema.failWithNeededComptime(block, operand_src, .{
2270022706 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
2270122707 });
2270222708 }
2270322709
2270422710 try sema.requireRuntimeBlock(block, src, operand_src);
22705 if (dest_scalar_ty.intInfo(mod).bits == 0) {
22711 if (dest_scalar_ty.intInfo(zcu).bits == 0) {
2270622712 if (!is_vector) {
2270722713 if (block.wantSafety()) {
2270822714 const ok = try block.addBinOp(if (block.float_mode == .optimized) .cmp_eq_optimized else .cmp_eq, operand, Air.internedToRef((try pt.floatValue(operand_ty, 0.0)).toIntern()));
......@@ -22711,7 +22717,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2271122717 return Air.internedToRef((try pt.intValue(dest_ty, 0)).toIntern());
2271222718 }
2271322719 if (block.wantSafety()) {
22714 const len = dest_ty.vectorLen(mod);
22720 const len = dest_ty.vectorLen(zcu);
2271522721 for (0..len) |i| {
2271622722 const idx_ref = try pt.intRef(Type.usize, i);
2271722723 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);
......@@ -22736,7 +22742,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2273622742 }
2273722743 return result;
2273822744 }
22739 const len = dest_ty.vectorLen(mod);
22745 const len = dest_ty.vectorLen(zcu);
2274022746 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2274122747 for (new_elems, 0..) |*new_elem, i| {
2274222748 const idx_ref = try pt.intRef(Type.usize, i);
......@@ -22757,7 +22763,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2275722763
2275822764fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2275922765 const pt = sema.pt;
22760 const mod = pt.zcu;
22766 const zcu = pt.zcu;
2276122767 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2276222768 const src = block.nodeOffset(inst_data.src_node);
2276322769 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -22767,10 +22773,10 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2276722773 const operand_ty = sema.typeOf(operand);
2276822774
2276922775 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);
22770 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
22776 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2277122777
22772 const dest_scalar_ty = dest_ty.scalarType(mod);
22773 const operand_scalar_ty = operand_ty.scalarType(mod);
22778 const dest_scalar_ty = dest_ty.scalarType(zcu);
22779 const operand_scalar_ty = operand_ty.scalarType(zcu);
2277422780
2277522781 try sema.checkFloatType(block, src, dest_scalar_ty);
2277622782 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
......@@ -22778,7 +22784,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2277822784 if (try sema.resolveValue(operand)) |operand_val| {
2277922785 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, pt, .sema);
2278022786 return Air.internedToRef(result_val.toIntern());
22781 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) {
22787 } else if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeFloat) {
2278222788 return sema.failWithNeededComptime(block, operand_src, .{
2278322789 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
2278422790 });
......@@ -22788,7 +22794,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2278822794 if (!is_vector) {
2278922795 return block.addTyOp(.float_from_int, dest_ty, operand);
2279022796 }
22791 const len = operand_ty.vectorLen(mod);
22797 const len = operand_ty.vectorLen(zcu);
2279222798 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2279322799 for (new_elems, 0..) |*new_elem, i| {
2279422800 const idx_ref = try pt.intRef(Type.usize, i);
......@@ -22800,7 +22806,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2280022806
2280122807fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2280222808 const pt = sema.pt;
22803 const mod = pt.zcu;
22809 const zcu = pt.zcu;
2280422810 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2280522811 const src = block.nodeOffset(inst_data.src_node);
2280622812
......@@ -22813,21 +22819,21 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2281322819 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrFromInt");
2281422820 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, uncoerced_operand_ty, src, operand_src);
2281522821
22816 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
22822 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2281722823 const operand_ty = if (is_vector) operand_ty: {
22818 const len = dest_ty.vectorLen(mod);
22824 const len = dest_ty.vectorLen(zcu);
2281922825 break :operand_ty try pt.vectorType(.{ .child = .usize_type, .len = len });
2282022826 } else Type.usize;
2282122827
2282222828 const operand_coerced = try sema.coerce(block, operand_ty, operand_res, operand_src);
2282322829
22824 const ptr_ty = dest_ty.scalarType(mod);
22830 const ptr_ty = dest_ty.scalarType(zcu);
2282522831 try sema.checkPtrType(block, src, ptr_ty, true);
2282622832
22827 const elem_ty = ptr_ty.elemType2(mod);
22828 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(pt, .sema);
22833 const elem_ty = ptr_ty.elemType2(zcu);
22834 const ptr_align = try ptr_ty.ptrAlignmentSema(pt);
2282922835
22830 if (ptr_ty.isSlice(mod)) {
22836 if (ptr_ty.isSlice(zcu)) {
2283122837 const msg = msg: {
2283222838 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(pt)});
2283322839 errdefer msg.destroy(sema.gpa);
......@@ -22842,7 +22848,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2284222848 const ptr_val = try sema.ptrFromIntVal(block, operand_src, val, ptr_ty, ptr_align);
2284322849 return Air.internedToRef(ptr_val.toIntern());
2284422850 }
22845 const len = dest_ty.vectorLen(mod);
22851 const len = dest_ty.vectorLen(zcu);
2284622852 const new_elems = try sema.arena.alloc(InternPool.Index, len);
2284722853 for (new_elems, 0..) |*new_elem, i| {
2284822854 const elem = try val.elemValue(pt, i);
......@@ -22854,7 +22860,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2285422860 .storage = .{ .elems = new_elems },
2285522861 } }));
2285622862 }
22857 if (try sema.typeRequiresComptime(ptr_ty)) {
22863 if (try ptr_ty.comptimeOnlySema(pt)) {
2285822864 return sema.failWithOwnedErrorMsg(block, msg: {
2285922865 const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(pt)});
2286022866 errdefer msg.destroy(sema.gpa);
......@@ -22865,8 +22871,8 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2286522871 }
2286622872 try sema.requireRuntimeBlock(block, src, operand_src);
2286722873 if (!is_vector) {
22868 if (block.wantSafety() and (try sema.typeHasRuntimeBits(elem_ty) or elem_ty.zigTypeTag(mod) == .Fn)) {
22869 if (!ptr_ty.isAllowzeroPtr(mod)) {
22874 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .Fn)) {
22875 if (!ptr_ty.isAllowzeroPtr(zcu)) {
2287022876 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
2287122877 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
2287222878 }
......@@ -22881,12 +22887,12 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2288122887 return block.addBitCast(dest_ty, operand_coerced);
2288222888 }
2288322889
22884 const len = dest_ty.vectorLen(mod);
22885 if (block.wantSafety() and (try sema.typeHasRuntimeBits(elem_ty) or elem_ty.zigTypeTag(mod) == .Fn)) {
22890 const len = dest_ty.vectorLen(zcu);
22891 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .Fn)) {
2288622892 for (0..len) |i| {
2288722893 const idx_ref = try pt.intRef(Type.usize, i);
2288822894 const elem_coerced = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
22889 if (!ptr_ty.isAllowzeroPtr(mod)) {
22895 if (!ptr_ty.isAllowzeroPtr(zcu)) {
2289022896 const is_non_zero = try block.addBinOp(.cmp_neq, elem_coerced, .zero_usize);
2289122897 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
2289222898 }
......@@ -22943,16 +22949,16 @@ fn ptrFromIntVal(
2294322949
2294422950fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2294522951 const pt = sema.pt;
22946 const mod = pt.zcu;
22947 const ip = &mod.intern_pool;
22952 const zcu = pt.zcu;
22953 const ip = &zcu.intern_pool;
2294822954 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2294922955 const src = block.nodeOffset(extra.node);
2295022956 const operand_src = block.builtinCallArgSrc(extra.node, 0);
2295122957 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");
2295222958 const operand = try sema.resolveInst(extra.rhs);
2295322959 const base_operand_ty = sema.typeOf(operand);
22954 const dest_tag = base_dest_ty.zigTypeTag(mod);
22955 const operand_tag = base_operand_ty.zigTypeTag(mod);
22960 const dest_tag = base_dest_ty.zigTypeTag(zcu);
22961 const operand_tag = base_operand_ty.zigTypeTag(zcu);
2295622962
2295722963 if (dest_tag != .ErrorSet and dest_tag != .ErrorUnion) {
2295822964 return sema.fail(block, src, "expected error set or error union type, found '{s}'", .{@tagName(dest_tag)});
......@@ -22964,13 +22970,13 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2296422970 return sema.fail(block, src, "cannot cast an error union type to error set", .{});
2296522971 }
2296622972 if (dest_tag == .ErrorUnion and operand_tag == .ErrorUnion and
22967 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())
22973 base_dest_ty.errorUnionPayload(zcu).toIntern() != base_operand_ty.errorUnionPayload(zcu).toIntern())
2296822974 {
2296922975 return sema.failWithOwnedErrorMsg(block, msg: {
2297022976 const msg = try sema.errMsg(src, "payload types of error unions must match", .{});
2297122977 errdefer msg.destroy(sema.gpa);
22972 const dest_ty = base_dest_ty.errorUnionPayload(mod);
22973 const operand_ty = base_operand_ty.errorUnionPayload(mod);
22978 const dest_ty = base_dest_ty.errorUnionPayload(zcu);
22979 const operand_ty = base_operand_ty.errorUnionPayload(zcu);
2297422980 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(pt)});
2297522981 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(pt)});
2297622982 try addDeclaredHereNote(sema, msg, dest_ty);
......@@ -22978,19 +22984,19 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2297822984 break :msg msg;
2297922985 });
2298022986 }
22981 const dest_ty = if (dest_tag == .ErrorUnion) base_dest_ty.errorUnionSet(mod) else base_dest_ty;
22982 const operand_ty = if (operand_tag == .ErrorUnion) base_operand_ty.errorUnionSet(mod) else base_operand_ty;
22987 const dest_ty = if (dest_tag == .ErrorUnion) base_dest_ty.errorUnionSet(zcu) else base_dest_ty;
22988 const operand_ty = if (operand_tag == .ErrorUnion) base_operand_ty.errorUnionSet(zcu) else base_operand_ty;
2298322989
2298422990 // operand must be defined since it can be an invalid error value
2298522991 const maybe_operand_val = try sema.resolveDefinedValue(block, operand_src, operand);
2298622992
2298722993 const disjoint = disjoint: {
2298822994 // Try avoiding resolving inferred error sets if we can
22989 if (!dest_ty.isAnyError(mod) and dest_ty.errorSetIsEmpty(mod)) break :disjoint true;
22990 if (!operand_ty.isAnyError(mod) and operand_ty.errorSetIsEmpty(mod)) break :disjoint true;
22991 if (dest_ty.isAnyError(mod)) break :disjoint false;
22992 if (operand_ty.isAnyError(mod)) break :disjoint false;
22993 const dest_err_names = dest_ty.errorSetNames(mod);
22995 if (!dest_ty.isAnyError(zcu) and dest_ty.errorSetIsEmpty(zcu)) break :disjoint true;
22996 if (!operand_ty.isAnyError(zcu) and operand_ty.errorSetIsEmpty(zcu)) break :disjoint true;
22997 if (dest_ty.isAnyError(zcu)) break :disjoint false;
22998 if (operand_ty.isAnyError(zcu)) break :disjoint false;
22999 const dest_err_names = dest_ty.errorSetNames(zcu);
2299423000 for (0..dest_err_names.len) |dest_err_index| {
2299523001 if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_names.get(ip)[dest_err_index]))
2299623002 break :disjoint false;
......@@ -23018,8 +23024,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2301823024 }
2301923025
2302023026 if (maybe_operand_val) |val| {
23021 if (!dest_ty.isAnyError(mod)) check: {
23022 const operand_val = mod.intern_pool.indexToKey(val.toIntern());
23027 if (!dest_ty.isAnyError(zcu)) check: {
23028 const operand_val = zcu.intern_pool.indexToKey(val.toIntern());
2302323029 var error_name: InternPool.NullTerminatedString = undefined;
2302423030 if (operand_tag == .ErrorUnion) {
2302523031 if (operand_val.error_union.val != .err_name) break :check;
......@@ -23039,9 +23045,9 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2303923045
2304023046 try sema.requireRuntimeBlock(block, src, operand_src);
2304123047 const err_int_ty = try pt.errorIntType();
23042 if (block.wantSafety() and !dest_ty.isAnyError(mod) and
23048 if (block.wantSafety() and !dest_ty.isAnyError(zcu) and
2304323049 dest_ty.toIntern() != .adhoc_inferred_error_set_type and
23044 mod.backendSupportsFeature(.error_set_has_value))
23050 zcu.backendSupportsFeature(.error_set_has_value))
2304523051 {
2304623052 if (dest_tag == .ErrorUnion) {
2304723053 const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand);
......@@ -23116,23 +23122,23 @@ fn ptrCastFull(
2311623122 operation: []const u8,
2311723123) CompileError!Air.Inst.Ref {
2311823124 const pt = sema.pt;
23119 const mod = pt.zcu;
23125 const zcu = pt.zcu;
2312023126 const operand_ty = sema.typeOf(operand);
2312123127
2312223128 try sema.checkPtrType(block, src, dest_ty, true);
2312323129 try sema.checkPtrOperand(block, operand_src, operand_ty);
2312423130
23125 const src_info = operand_ty.ptrInfo(mod);
23126 const dest_info = dest_ty.ptrInfo(mod);
23131 const src_info = operand_ty.ptrInfo(zcu);
23132 const dest_info = dest_ty.ptrInfo(zcu);
2312723133
2312823134 try Type.fromInterned(src_info.child).resolveLayout(pt);
2312923135 try Type.fromInterned(dest_info.child).resolveLayout(pt);
2313023136
2313123137 const src_slice_like = src_info.flags.size == .Slice or
23132 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array);
23138 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .Array);
2313323139
2313423140 const dest_slice_like = dest_info.flags.size == .Slice or
23135 (dest_info.flags.size == .One and Type.fromInterned(dest_info.child).zigTypeTag(mod) == .Array);
23141 (dest_info.flags.size == .One and Type.fromInterned(dest_info.child).zigTypeTag(zcu) == .Array);
2313623142
2313723143 if (dest_info.flags.size == .Slice and !src_slice_like) {
2313823144 return sema.fail(block, src, "illegal pointer cast to slice", .{});
......@@ -23140,12 +23146,12 @@ fn ptrCastFull(
2314023146
2314123147 if (dest_info.flags.size == .Slice) {
2314223148 const src_elem_size = switch (src_info.flags.size) {
23143 .Slice => Type.fromInterned(src_info.child).abiSize(pt),
23149 .Slice => Type.fromInterned(src_info.child).abiSize(zcu),
2314423150 // pointer to array
23145 .One => Type.fromInterned(src_info.child).childType(mod).abiSize(pt),
23151 .One => Type.fromInterned(src_info.child).childType(zcu).abiSize(zcu),
2314623152 else => unreachable,
2314723153 };
23148 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(pt);
23154 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(zcu);
2314923155 if (src_elem_size != dest_elem_size) {
2315023156 return sema.fail(block, src, "TODO: implement {s} between slices changing the length", .{operation});
2315123157 }
......@@ -23167,7 +23173,7 @@ fn ptrCastFull(
2316723173 errdefer msg.destroy(sema.gpa);
2316823174 if (dest_info.flags.size == .Many and
2316923175 (src_info.flags.size == .Slice or
23170 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))
23176 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .Array)))
2317123177 {
2317223178 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});
2317323179 } else {
......@@ -23180,7 +23186,7 @@ fn ptrCastFull(
2318023186 check_child: {
2318123187 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {
2318223188 // *[n]T -> []T
23183 break :blk Type.fromInterned(src_info.child).childType(mod);
23189 break :blk Type.fromInterned(src_info.child).childType(zcu);
2318423190 } else Type.fromInterned(src_info.child);
2318523191
2318623192 const dest_child = Type.fromInterned(dest_info.child);
......@@ -23190,7 +23196,7 @@ fn ptrCastFull(
2319023196 dest_child,
2319123197 src_child,
2319223198 !dest_info.flags.is_const,
23193 mod.getTarget(),
23199 zcu.getTarget(),
2319423200 src,
2319523201 operand_src,
2319623202 null,
......@@ -23211,14 +23217,14 @@ fn ptrCastFull(
2321123217 if (dest_info.sentinel == .none) break :check_sent;
2321223218 if (src_info.flags.size == .C) break :check_sent;
2321323219 if (src_info.sentinel != .none) {
23214 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, pt.tid, src_info.sentinel, dest_info.child);
23220 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_info.sentinel, dest_info.child);
2321523221 if (dest_info.sentinel == coerced_sent) break :check_sent;
2321623222 }
2321723223 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {
2321823224 // [*]nT -> []T
2321923225 const arr_ty = Type.fromInterned(src_info.child);
23220 if (arr_ty.sentinel(mod)) |src_sentinel| {
23221 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);
23226 if (arr_ty.sentinel(zcu)) |src_sentinel| {
23227 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);
2322223228 if (dest_info.sentinel == coerced_sent) break :check_sent;
2322323229 }
2322423230 }
......@@ -23264,8 +23270,8 @@ fn ptrCastFull(
2326423270 }
2326523271
2326623272 check_allowzero: {
23267 const src_allows_zero = operand_ty.ptrAllowsZero(mod);
23268 const dest_allows_zero = dest_ty.ptrAllowsZero(mod);
23273 const src_allows_zero = operand_ty.ptrAllowsZero(zcu);
23274 const dest_allows_zero = dest_ty.ptrAllowsZero(zcu);
2326923275 if (!src_allows_zero) break :check_allowzero;
2327023276 if (dest_allows_zero) break :check_allowzero;
2327123277
......@@ -23286,12 +23292,12 @@ fn ptrCastFull(
2328623292 const src_align = if (src_info.flags.alignment != .none)
2328723293 src_info.flags.alignment
2328823294 else
23289 Type.fromInterned(src_info.child).abiAlignment(pt);
23295 Type.fromInterned(src_info.child).abiAlignment(zcu);
2329023296
2329123297 const dest_align = if (dest_info.flags.alignment != .none)
2329223298 dest_info.flags.alignment
2329323299 else
23294 Type.fromInterned(dest_info.child).abiAlignment(pt);
23300 Type.fromInterned(dest_info.child).abiAlignment(zcu);
2329523301
2329623302 if (!flags.align_cast) {
2329723303 if (dest_align.compare(.gt, src_align)) {
......@@ -23327,7 +23333,7 @@ fn ptrCastFull(
2332723333 }
2332823334 } else {
2332923335 // Some address space casts are always disallowed
23330 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
23336 if (!target_util.addrSpaceCastIsValid(zcu.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
2333123337 return sema.failWithOwnedErrorMsg(block, msg: {
2333223338 const msg = try sema.errMsg(src, "invalid address space cast", .{});
2333323339 errdefer msg.destroy(sema.gpa);
......@@ -23363,7 +23369,7 @@ fn ptrCastFull(
2336323369 }
2336423370
2336523371 const ptr = if (src_info.flags.size == .Slice and dest_info.flags.size != .Slice) ptr: {
23366 if (operand_ty.zigTypeTag(mod) == .Optional) {
23372 if (operand_ty.zigTypeTag(zcu) == .Optional) {
2336723373 break :ptr try sema.analyzeOptionalSlicePtr(block, operand_src, operand, operand_ty);
2336823374 } else {
2336923375 break :ptr try sema.analyzeSlicePtr(block, operand_src, operand, operand_ty);
......@@ -23375,7 +23381,7 @@ fn ptrCastFull(
2337523381 var info = dest_info;
2337623382 info.flags.size = .Many;
2337723383 const ty = try pt.ptrTypeSema(info);
23378 if (dest_ty.zigTypeTag(mod) == .Optional) {
23384 if (dest_ty.zigTypeTag(zcu) == .Optional) {
2337923385 break :blk try pt.optionalType(ty.toIntern());
2338023386 } else {
2338123387 break :blk ty;
......@@ -23385,14 +23391,14 @@ fn ptrCastFull(
2338523391 // Cannot do @addrSpaceCast at comptime
2338623392 if (!flags.addrspace_cast) {
2338723393 if (try sema.resolveValue(ptr)) |ptr_val| {
23388 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isUndef(mod)) {
23394 if (!dest_ty.ptrAllowsZero(zcu) and ptr_val.isUndef(zcu)) {
2338923395 return sema.failWithUseOfUndef(block, operand_src);
2339023396 }
23391 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isNull(mod)) {
23397 if (!dest_ty.ptrAllowsZero(zcu) and ptr_val.isNull(zcu)) {
2339223398 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});
2339323399 }
2339423400 if (dest_align.compare(.gt, src_align)) {
23395 if (try ptr_val.getUnsignedIntAdvanced(pt, .sema)) |addr| {
23401 if (try ptr_val.getUnsignedIntSema(pt)) |addr| {
2339623402 if (!dest_align.check(addr)) {
2339723403 return sema.fail(block, operand_src, "pointer address 0x{X} is not aligned to {d} bytes", .{
2339823404 addr,
......@@ -23402,20 +23408,20 @@ fn ptrCastFull(
2340223408 }
2340323409 }
2340423410 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
23405 if (ptr_val.isUndef(mod)) return pt.undefRef(dest_ty);
23406 const arr_len = try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(mod));
23407 const ptr_val_key = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
23411 if (ptr_val.isUndef(zcu)) return pt.undefRef(dest_ty);
23412 const arr_len = try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(zcu));
23413 const ptr_val_key = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
2340823414 return Air.internedToRef((try pt.intern(.{ .slice = .{
2340923415 .ty = dest_ty.toIntern(),
2341023416 .ptr = try pt.intern(.{ .ptr = .{
23411 .ty = dest_ty.slicePtrFieldType(mod).toIntern(),
23417 .ty = dest_ty.slicePtrFieldType(zcu).toIntern(),
2341223418 .base_addr = ptr_val_key.base_addr,
2341323419 .byte_offset = ptr_val_key.byte_offset,
2341423420 } }),
2341523421 .len = arr_len.toIntern(),
2341623422 } })));
2341723423 } else {
23418 assert(dest_ptr_ty.eql(dest_ty, mod));
23424 assert(dest_ptr_ty.eql(dest_ty, zcu));
2341923425 return Air.internedToRef((try pt.getCoerced(ptr_val, dest_ty)).toIntern());
2342023426 }
2342123427 }
......@@ -23424,8 +23430,8 @@ fn ptrCastFull(
2342423430 try sema.requireRuntimeBlock(block, src, null);
2342523431 try sema.validateRuntimeValue(block, operand_src, ptr);
2342623432
23427 if (block.wantSafety() and operand_ty.ptrAllowsZero(mod) and !dest_ty.ptrAllowsZero(mod) and
23428 (try sema.typeHasRuntimeBits(Type.fromInterned(dest_info.child)) or Type.fromInterned(dest_info.child).zigTypeTag(mod) == .Fn))
23433 if (block.wantSafety() and operand_ty.ptrAllowsZero(zcu) and !dest_ty.ptrAllowsZero(zcu) and
23434 (try Type.fromInterned(dest_info.child).hasRuntimeBitsSema(pt) or Type.fromInterned(dest_info.child).zigTypeTag(zcu) == .Fn))
2342923435 {
2343023436 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
2343123437 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
......@@ -23439,7 +23445,7 @@ fn ptrCastFull(
2343923445
2344023446 if (block.wantSafety() and
2344123447 dest_align.compare(.gt, src_align) and
23442 try sema.typeHasRuntimeBits(Type.fromInterned(dest_info.child)))
23448 try Type.fromInterned(dest_info.child).hasRuntimeBitsSema(pt))
2344323449 {
2344423450 const align_bytes_minus_1 = dest_align.toByteUnits().? - 1;
2344523451 const align_minus_1 = Air.internedToRef((try pt.intValue(Type.usize, align_bytes_minus_1)).toIntern());
......@@ -23460,7 +23466,7 @@ fn ptrCastFull(
2346023466 var intermediate_info = src_info;
2346123467 intermediate_info.flags.address_space = dest_info.flags.address_space;
2346223468 const intermediate_ptr_ty = try pt.ptrTypeSema(intermediate_info);
23463 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(mod) == .Optional) blk: {
23469 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(zcu) == .Optional) blk: {
2346423470 break :blk try pt.optionalType(intermediate_ptr_ty.toIntern());
2346523471 } else intermediate_ptr_ty;
2346623472 const intermediate = try block.addInst(.{
......@@ -23470,7 +23476,7 @@ fn ptrCastFull(
2347023476 .operand = ptr,
2347123477 } },
2347223478 });
23473 if (intermediate_ty.eql(dest_ptr_ty, mod)) {
23479 if (intermediate_ty.eql(dest_ptr_ty, zcu)) {
2347423480 // We only changed the address space, so no need for a bitcast
2347523481 break :ptr intermediate;
2347623482 }
......@@ -23482,7 +23488,7 @@ fn ptrCastFull(
2348223488 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
2348323489 // We have to construct a slice using the operand's child's array length
2348423490 // Note that we know from the check at the start of the function that operand_ty is slice-like
23485 const arr_len = Air.internedToRef((try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(mod))).toIntern());
23491 const arr_len = Air.internedToRef((try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(zcu))).toIntern());
2348623492 return block.addInst(.{
2348723493 .tag = .slice,
2348823494 .data = .{ .ty_pl = .{
......@@ -23494,7 +23500,7 @@ fn ptrCastFull(
2349423500 } },
2349523501 });
2349623502 } else {
23497 assert(dest_ptr_ty.eql(dest_ty, mod));
23503 assert(dest_ptr_ty.eql(dest_ty, zcu));
2349823504 try sema.checkKnownAllocPtr(block, operand, result_ptr);
2349923505 return result_ptr;
2350023506 }
......@@ -23502,7 +23508,7 @@ fn ptrCastFull(
2350223508
2350323509fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2350423510 const pt = sema.pt;
23505 const mod = pt.zcu;
23511 const zcu = pt.zcu;
2350623512 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
2350723513 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2350823514 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
......@@ -23512,13 +23518,13 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2351223518 const operand_ty = sema.typeOf(operand);
2351323519 try sema.checkPtrOperand(block, operand_src, operand_ty);
2351423520
23515 var ptr_info = operand_ty.ptrInfo(mod);
23521 var ptr_info = operand_ty.ptrInfo(zcu);
2351623522 if (flags.const_cast) ptr_info.flags.is_const = false;
2351723523 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;
2351823524
2351923525 const dest_ty = blk: {
2352023526 const dest_ty = try pt.ptrTypeSema(ptr_info);
23521 if (operand_ty.zigTypeTag(mod) == .Optional) {
23527 if (operand_ty.zigTypeTag(zcu) == .Optional) {
2352223528 break :blk try pt.optionalType(dest_ty.toIntern());
2352323529 }
2352423530 break :blk dest_ty;
......@@ -23536,7 +23542,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2353623542
2353723543fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2353823544 const pt = sema.pt;
23539 const mod = pt.zcu;
23545 const zcu = pt.zcu;
2354023546 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2354123547 const src = block.nodeOffset(inst_data.src_node);
2354223548 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -23547,24 +23553,24 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2354723553 const operand_ty = sema.typeOf(operand);
2354823554 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
2354923555
23550 const operand_is_vector = operand_ty.zigTypeTag(mod) == .Vector;
23551 const dest_is_vector = dest_ty.zigTypeTag(mod) == .Vector;
23556 const operand_is_vector = operand_ty.zigTypeTag(zcu) == .Vector;
23557 const dest_is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2355223558 if (operand_is_vector != dest_is_vector) {
2355323559 return sema.fail(block, operand_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(pt), operand_ty.fmt(pt) });
2355423560 }
2355523561
23556 if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
23562 if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
2355723563 return sema.coerce(block, dest_ty, operand, operand_src);
2355823564 }
2355923565
23560 const dest_info = dest_scalar_ty.intInfo(mod);
23566 const dest_info = dest_scalar_ty.intInfo(zcu);
2356123567
2356223568 if (try sema.typeHasOnePossibleValue(dest_ty)) |val| {
2356323569 return Air.internedToRef(val.toIntern());
2356423570 }
2356523571
23566 if (operand_scalar_ty.zigTypeTag(mod) != .ComptimeInt) {
23567 const operand_info = operand_ty.intInfo(mod);
23572 if (operand_scalar_ty.zigTypeTag(zcu) != .ComptimeInt) {
23573 const operand_info = operand_ty.intInfo(zcu);
2356823574 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
2356923575 return Air.internedToRef(val.toIntern());
2357023576 }
......@@ -23595,14 +23601,14 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2359523601 }
2359623602
2359723603 if (try sema.resolveValueIntable(operand)) |val| {
23598 if (val.isUndef(mod)) return pt.undefRef(dest_ty);
23604 if (val.isUndef(zcu)) return pt.undefRef(dest_ty);
2359923605 if (!dest_is_vector) {
2360023606 return Air.internedToRef((try pt.getCoerced(
2360123607 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, pt),
2360223608 dest_ty,
2360323609 )).toIntern());
2360423610 }
23605 const elems = try sema.arena.alloc(InternPool.Index, operand_ty.vectorLen(mod));
23611 const elems = try sema.arena.alloc(InternPool.Index, operand_ty.vectorLen(zcu));
2360623612 for (elems, 0..) |*elem, i| {
2360723613 const elem_val = try val.elemValue(pt, i);
2360823614 const uncoerced_elem = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, pt);
......@@ -23623,38 +23629,38 @@ fn zirBitCount(
2362323629 block: *Block,
2362423630 inst: Zir.Inst.Index,
2362523631 air_tag: Air.Inst.Tag,
23626 comptime comptimeOp: fn (val: Value, ty: Type, pt: Zcu.PerThread) u64,
23632 comptime comptimeOp: fn (val: Value, ty: Type, zcu: *Zcu) u64,
2362723633) CompileError!Air.Inst.Ref {
2362823634 const pt = sema.pt;
23629 const mod = pt.zcu;
23635 const zcu = pt.zcu;
2363023636 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2363123637 const src = block.nodeOffset(inst_data.src_node);
2363223638 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2363323639 const operand = try sema.resolveInst(inst_data.operand);
2363423640 const operand_ty = sema.typeOf(operand);
2363523641 _ = try sema.checkIntOrVector(block, operand, operand_src);
23636 const bits = operand_ty.intInfo(mod).bits;
23642 const bits = operand_ty.intInfo(zcu).bits;
2363723643
2363823644 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
2363923645 return Air.internedToRef(val.toIntern());
2364023646 }
2364123647
2364223648 const result_scalar_ty = try pt.smallestUnsignedInt(bits);
23643 switch (operand_ty.zigTypeTag(mod)) {
23649 switch (operand_ty.zigTypeTag(zcu)) {
2364423650 .Vector => {
23645 const vec_len = operand_ty.vectorLen(mod);
23651 const vec_len = operand_ty.vectorLen(zcu);
2364623652 const result_ty = try pt.vectorType(.{
2364723653 .len = vec_len,
2364823654 .child = result_scalar_ty.toIntern(),
2364923655 });
2365023656 if (try sema.resolveValue(operand)) |val| {
23651 if (val.isUndef(mod)) return pt.undefRef(result_ty);
23657 if (val.isUndef(zcu)) return pt.undefRef(result_ty);
2365223658
2365323659 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
23654 const scalar_ty = operand_ty.scalarType(mod);
23660 const scalar_ty = operand_ty.scalarType(zcu);
2365523661 for (elems, 0..) |*elem, i| {
2365623662 const elem_val = try val.elemValue(pt, i);
23657 const count = comptimeOp(elem_val, scalar_ty, pt);
23663 const count = comptimeOp(elem_val, scalar_ty, zcu);
2365823664 elem.* = (try pt.intValue(result_scalar_ty, count)).toIntern();
2365923665 }
2366023666 return Air.internedToRef((try pt.intern(.{ .aggregate = .{
......@@ -23668,8 +23674,8 @@ fn zirBitCount(
2366823674 },
2366923675 .Int => {
2367023676 if (try sema.resolveValueResolveLazy(operand)) |val| {
23671 if (val.isUndef(mod)) return pt.undefRef(result_scalar_ty);
23672 return pt.intRef(result_scalar_ty, comptimeOp(val, operand_ty, pt));
23677 if (val.isUndef(zcu)) return pt.undefRef(result_scalar_ty);
23678 return pt.intRef(result_scalar_ty, comptimeOp(val, operand_ty, zcu));
2367323679 } else {
2367423680 try sema.requireRuntimeBlock(block, src, operand_src);
2367523681 return block.addTyOp(air_tag, result_scalar_ty, operand);
......@@ -23681,14 +23687,14 @@ fn zirBitCount(
2368123687
2368223688fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2368323689 const pt = sema.pt;
23684 const mod = pt.zcu;
23690 const zcu = pt.zcu;
2368523691 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2368623692 const src = block.nodeOffset(inst_data.src_node);
2368723693 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2368823694 const operand = try sema.resolveInst(inst_data.operand);
2368923695 const operand_ty = sema.typeOf(operand);
2369023696 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
23691 const bits = scalar_ty.intInfo(mod).bits;
23697 const bits = scalar_ty.intInfo(zcu).bits;
2369223698 if (bits % 8 != 0) {
2369323699 return sema.fail(
2369423700 block,
......@@ -23702,10 +23708,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2370223708 return Air.internedToRef(val.toIntern());
2370323709 }
2370423710
23705 switch (operand_ty.zigTypeTag(mod)) {
23711 switch (operand_ty.zigTypeTag(zcu)) {
2370623712 .Int => {
2370723713 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23708 if (val.isUndef(mod)) return pt.undefRef(operand_ty);
23714 if (val.isUndef(zcu)) return pt.undefRef(operand_ty);
2370923715 const result_val = try val.byteSwap(operand_ty, pt, sema.arena);
2371023716 return Air.internedToRef(result_val.toIntern());
2371123717 } else operand_src;
......@@ -23715,10 +23721,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2371523721 },
2371623722 .Vector => {
2371723723 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23718 if (val.isUndef(mod))
23724 if (val.isUndef(zcu))
2371923725 return pt.undefRef(operand_ty);
2372023726
23721 const vec_len = operand_ty.vectorLen(mod);
23727 const vec_len = operand_ty.vectorLen(zcu);
2372223728 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
2372323729 for (elems, 0..) |*elem, i| {
2372423730 const elem_val = try val.elemValue(pt, i);
......@@ -23750,11 +23756,11 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2375023756 }
2375123757
2375223758 const pt = sema.pt;
23753 const mod = pt.zcu;
23754 switch (operand_ty.zigTypeTag(mod)) {
23759 const zcu = pt.zcu;
23760 switch (operand_ty.zigTypeTag(zcu)) {
2375523761 .Int => {
2375623762 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23757 if (val.isUndef(mod)) return pt.undefRef(operand_ty);
23763 if (val.isUndef(zcu)) return pt.undefRef(operand_ty);
2375823764 const result_val = try val.bitReverse(operand_ty, pt, sema.arena);
2375923765 return Air.internedToRef(result_val.toIntern());
2376023766 } else operand_src;
......@@ -23764,10 +23770,10 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2376423770 },
2376523771 .Vector => {
2376623772 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23767 if (val.isUndef(mod))
23773 if (val.isUndef(zcu))
2376823774 return pt.undefRef(operand_ty);
2376923775
23770 const vec_len = operand_ty.vectorLen(mod);
23776 const vec_len = operand_ty.vectorLen(zcu);
2377123777 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
2377223778 for (elems, 0..) |*elem, i| {
2377323779 const elem_val = try val.elemValue(pt, i);
......@@ -23810,26 +23816,26 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2381023816 });
2381123817
2381223818 const pt = sema.pt;
23813 const mod = pt.zcu;
23814 const ip = &mod.intern_pool;
23819 const zcu = pt.zcu;
23820 const ip = &zcu.intern_pool;
2381523821 try ty.resolveLayout(pt);
23816 switch (ty.zigTypeTag(mod)) {
23822 switch (ty.zigTypeTag(zcu)) {
2381723823 .Struct => {},
2381823824 else => return sema.fail(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(pt)}),
2381923825 }
2382023826
23821 const field_index = if (ty.isTuple(mod)) blk: {
23827 const field_index = if (ty.isTuple(zcu)) blk: {
2382223828 if (field_name.eqlSlice("len", ip)) {
2382323829 return sema.fail(block, src, "no offset available for 'len' field of tuple", .{});
2382423830 }
2382523831 break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src);
2382623832 } else try sema.structFieldIndex(block, ty, field_name, rhs_src);
2382723833
23828 if (ty.structFieldIsComptime(field_index, mod)) {
23834 if (ty.structFieldIsComptime(field_index, zcu)) {
2382923835 return sema.fail(block, src, "no offset available for comptime field", .{});
2383023836 }
2383123837
23832 switch (ty.containerLayout(mod)) {
23838 switch (ty.containerLayout(zcu)) {
2383323839 .@"packed" => {
2383423840 var bit_sum: u64 = 0;
2383523841 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -23838,17 +23844,17 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2383823844 return bit_sum;
2383923845 }
2384023846 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
23841 bit_sum += field_ty.bitSize(pt);
23847 bit_sum += field_ty.bitSize(zcu);
2384223848 } else unreachable;
2384323849 },
23844 else => return ty.structFieldOffset(field_index, pt) * 8,
23850 else => return ty.structFieldOffset(field_index, zcu) * 8,
2384523851 }
2384623852}
2384723853
2384823854fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
2384923855 const pt = sema.pt;
23850 const mod = pt.zcu;
23851 switch (ty.zigTypeTag(mod)) {
23856 const zcu = pt.zcu;
23857 switch (ty.zigTypeTag(zcu)) {
2385223858 .Struct, .Enum, .Union, .Opaque => return,
2385323859 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(pt)}),
2385423860 }
......@@ -23857,8 +23863,8 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
2385723863/// Returns `true` if the type was a comptime_int.
2385823864fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
2385923865 const pt = sema.pt;
23860 const mod = pt.zcu;
23861 switch (try ty.zigTypeTagOrPoison(mod)) {
23866 const zcu = pt.zcu;
23867 switch (try ty.zigTypeTagOrPoison(zcu)) {
2386223868 .ComptimeInt => return true,
2386323869 .Int => return false,
2386423870 else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(pt)}),
......@@ -23872,9 +23878,9 @@ fn checkInvalidPtrIntArithmetic(
2387223878 ty: Type,
2387323879) CompileError!void {
2387423880 const pt = sema.pt;
23875 const mod = pt.zcu;
23876 switch (try ty.zigTypeTagOrPoison(mod)) {
23877 .Pointer => switch (ty.ptrSize(mod)) {
23881 const zcu = pt.zcu;
23882 switch (try ty.zigTypeTagOrPoison(zcu)) {
23883 .Pointer => switch (ty.ptrSize(zcu)) {
2387823884 .One, .Slice => return,
2387923885 .Many, .C => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"),
2388023886 },
......@@ -23908,8 +23914,8 @@ fn checkPtrOperand(
2390823914 ty: Type,
2390923915) CompileError!void {
2391023916 const pt = sema.pt;
23911 const mod = pt.zcu;
23912 switch (ty.zigTypeTag(mod)) {
23917 const zcu = pt.zcu;
23918 switch (ty.zigTypeTag(zcu)) {
2391323919 .Pointer => return,
2391423920 .Fn => {
2391523921 const msg = msg: {
......@@ -23926,7 +23932,7 @@ fn checkPtrOperand(
2392623932 };
2392723933 return sema.failWithOwnedErrorMsg(block, msg);
2392823934 },
23929 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
23935 .Optional => if (ty.childType(zcu).zigTypeTag(zcu) == .Pointer) return,
2393023936 else => {},
2393123937 }
2393223938 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});
......@@ -23940,9 +23946,9 @@ fn checkPtrType(
2394023946 allow_slice: bool,
2394123947) CompileError!void {
2394223948 const pt = sema.pt;
23943 const mod = pt.zcu;
23944 switch (ty.zigTypeTag(mod)) {
23945 .Pointer => if (allow_slice or !ty.isSlice(mod)) return,
23949 const zcu = pt.zcu;
23950 switch (ty.zigTypeTag(zcu)) {
23951 .Pointer => if (allow_slice or !ty.isSlice(zcu)) return,
2394623952 .Fn => {
2394723953 const msg = msg: {
2394823954 const msg = try sema.errMsg(
......@@ -23958,7 +23964,7 @@ fn checkPtrType(
2395823964 };
2395923965 return sema.failWithOwnedErrorMsg(block, msg);
2396023966 },
23961 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
23967 .Optional => if (ty.childType(zcu).zigTypeTag(zcu) == .Pointer) return,
2396223968 else => {},
2396323969 }
2396423970 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});
......@@ -23971,10 +23977,10 @@ fn checkVectorElemType(
2397123977 ty: Type,
2397223978) CompileError!void {
2397323979 const pt = sema.pt;
23974 const mod = pt.zcu;
23975 switch (ty.zigTypeTag(mod)) {
23980 const zcu = pt.zcu;
23981 switch (ty.zigTypeTag(zcu)) {
2397623982 .Int, .Float, .Bool => return,
23977 .Optional, .Pointer => if (ty.isPtrAtRuntime(mod)) return,
23983 .Optional, .Pointer => if (ty.isPtrAtRuntime(zcu)) return,
2397823984 else => {},
2397923985 }
2398023986 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{}'", .{ty.fmt(pt)});
......@@ -23987,8 +23993,8 @@ fn checkFloatType(
2398723993 ty: Type,
2398823994) CompileError!void {
2398923995 const pt = sema.pt;
23990 const mod = pt.zcu;
23991 switch (ty.zigTypeTag(mod)) {
23996 const zcu = pt.zcu;
23997 switch (ty.zigTypeTag(zcu)) {
2399223998 .ComptimeInt, .ComptimeFloat, .Float => {},
2399323999 else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(pt)}),
2399424000 }
......@@ -24001,10 +24007,10 @@ fn checkNumericType(
2400124007 ty: Type,
2400224008) CompileError!void {
2400324009 const pt = sema.pt;
24004 const mod = pt.zcu;
24005 switch (ty.zigTypeTag(mod)) {
24010 const zcu = pt.zcu;
24011 switch (ty.zigTypeTag(zcu)) {
2400624012 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
24007 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
24013 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
2400824014 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
2400924015 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),
2401024016 },
......@@ -24023,9 +24029,9 @@ fn checkAtomicPtrOperand(
2402324029 ptr_const: bool,
2402424030) CompileError!Air.Inst.Ref {
2402524031 const pt = sema.pt;
24026 const mod = pt.zcu;
24027 var diag: Module.AtomicPtrAlignmentDiagnostics = .{};
24028 const alignment = mod.atomicPtrAlignment(elem_ty, &diag) catch |err| switch (err) {
24032 const zcu = pt.zcu;
24033 var diag: Zcu.AtomicPtrAlignmentDiagnostics = .{};
24034 const alignment = zcu.atomicPtrAlignment(elem_ty, &diag) catch |err| switch (err) {
2402924035 error.OutOfMemory => return error.OutOfMemory,
2403024036 error.FloatTooBig => return sema.fail(
2403124037 block,
......@@ -24056,8 +24062,8 @@ fn checkAtomicPtrOperand(
2405624062 };
2405724063
2405824064 const ptr_ty = sema.typeOf(ptr);
24059 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {
24060 .Pointer => ptr_ty.ptrInfo(mod),
24065 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(zcu)) {
24066 .Pointer => ptr_ty.ptrInfo(zcu),
2406124067 else => {
2406224068 const wanted_ptr_ty = try pt.ptrTypeSema(wanted_ptr_data);
2406324069 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
......@@ -24095,13 +24101,13 @@ fn checkIntOrVector(
2409524101 operand_src: LazySrcLoc,
2409624102) CompileError!Type {
2409724103 const pt = sema.pt;
24098 const mod = pt.zcu;
24104 const zcu = pt.zcu;
2409924105 const operand_ty = sema.typeOf(operand);
24100 switch (try operand_ty.zigTypeTagOrPoison(mod)) {
24106 switch (try operand_ty.zigTypeTagOrPoison(zcu)) {
2410124107 .Int => return operand_ty,
2410224108 .Vector => {
24103 const elem_ty = operand_ty.childType(mod);
24104 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
24109 const elem_ty = operand_ty.childType(zcu);
24110 switch (try elem_ty.zigTypeTagOrPoison(zcu)) {
2410524111 .Int => return elem_ty,
2410624112 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
2410724113 elem_ty.fmt(pt),
......@@ -24121,12 +24127,12 @@ fn checkIntOrVectorAllowComptime(
2412124127 operand_src: LazySrcLoc,
2412224128) CompileError!Type {
2412324129 const pt = sema.pt;
24124 const mod = pt.zcu;
24125 switch (try operand_ty.zigTypeTagOrPoison(mod)) {
24130 const zcu = pt.zcu;
24131 switch (try operand_ty.zigTypeTagOrPoison(zcu)) {
2412624132 .Int, .ComptimeInt => return operand_ty,
2412724133 .Vector => {
24128 const elem_ty = operand_ty.childType(mod);
24129 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
24134 const elem_ty = operand_ty.childType(zcu);
24135 switch (try elem_ty.zigTypeTagOrPoison(zcu)) {
2413024136 .Int, .ComptimeInt => return elem_ty,
2413124137 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
2413224138 elem_ty.fmt(pt),
......@@ -24162,12 +24168,12 @@ fn checkSimdBinOp(
2416224168 rhs_src: LazySrcLoc,
2416324169) CompileError!SimdBinOp {
2416424170 const pt = sema.pt;
24165 const mod = pt.zcu;
24171 const zcu = pt.zcu;
2416624172 const lhs_ty = sema.typeOf(uncasted_lhs);
2416724173 const rhs_ty = sema.typeOf(uncasted_rhs);
2416824174
2416924175 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
24170 const vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null;
24176 const vec_len: ?usize = if (lhs_ty.zigTypeTag(zcu) == .Vector) lhs_ty.vectorLen(zcu) else null;
2417124177 const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{
2417224178 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },
2417324179 });
......@@ -24181,7 +24187,7 @@ fn checkSimdBinOp(
2418124187 .lhs_val = try sema.resolveValue(lhs),
2418224188 .rhs_val = try sema.resolveValue(rhs),
2418324189 .result_ty = result_ty,
24184 .scalar_ty = result_ty.scalarType(mod),
24190 .scalar_ty = result_ty.scalarType(zcu),
2418524191 };
2418624192}
2418724193
......@@ -24195,9 +24201,9 @@ fn checkVectorizableBinaryOperands(
2419524201 rhs_src: LazySrcLoc,
2419624202) CompileError!void {
2419724203 const pt = sema.pt;
24198 const mod = pt.zcu;
24199 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);
24200 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
24204 const zcu = pt.zcu;
24205 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
24206 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
2420124207 if (lhs_zig_ty_tag != .Vector and rhs_zig_ty_tag != .Vector) return;
2420224208
2420324209 const lhs_is_vector = switch (lhs_zig_ty_tag) {
......@@ -24210,8 +24216,8 @@ fn checkVectorizableBinaryOperands(
2421024216 };
2421124217
2421224218 if (lhs_is_vector and rhs_is_vector) {
24213 const lhs_len = lhs_ty.arrayLen(mod);
24214 const rhs_len = rhs_ty.arrayLen(mod);
24219 const lhs_len = lhs_ty.arrayLen(zcu);
24220 const rhs_len = rhs_ty.arrayLen(zcu);
2421524221 if (lhs_len != rhs_len) {
2421624222 const msg = msg: {
2421724223 const msg = try sema.errMsg(src, "vector length mismatch", .{});
......@@ -24246,11 +24252,11 @@ fn resolveExportOptions(
2424624252 block: *Block,
2424724253 src: LazySrcLoc,
2424824254 zir_ref: Zir.Inst.Ref,
24249) CompileError!Module.Export.Options {
24255) CompileError!Zcu.Export.Options {
2425024256 const pt = sema.pt;
24251 const mod = pt.zcu;
24257 const zcu = pt.zcu;
2425224258 const gpa = sema.gpa;
24253 const ip = &mod.intern_pool;
24259 const ip = &zcu.intern_pool;
2425424260 const export_options_ty = try pt.getBuiltinType("ExportOptions");
2425524261 const air_ref = try sema.resolveInst(zir_ref);
2425624262 const options = try sema.coerce(block, export_options_ty, air_ref, src);
......@@ -24269,13 +24275,13 @@ fn resolveExportOptions(
2426924275 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
2427024276 .needed_comptime_reason = "linkage of exported value must be comptime-known",
2427124277 });
24272 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
24278 const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val);
2427324279
2427424280 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src);
2427524281 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
2427624282 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2427724283 });
24278 const section = if (section_opt_val.optionalValue(mod)) |section_val|
24284 const section = if (section_opt_val.optionalValue(zcu)) |section_val|
2427924285 try sema.toConstString(block, section_src, Air.internedToRef(section_val.toIntern()), .{
2428024286 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2428124287 })
......@@ -24286,7 +24292,7 @@ fn resolveExportOptions(
2428624292 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
2428724293 .needed_comptime_reason = "visibility of exported value must be comptime-known",
2428824294 });
24289 const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val);
24295 const visibility = zcu.toEnum(std.builtin.SymbolVisibility, visibility_val);
2429024296
2429124297 if (name.len < 1) {
2429224298 return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});
......@@ -24349,7 +24355,7 @@ fn zirCmpxchg(
2434924355 extended: Zir.Inst.Extended.InstData,
2435024356) CompileError!Air.Inst.Ref {
2435124357 const pt = sema.pt;
24352 const mod = pt.zcu;
24358 const zcu = pt.zcu;
2435324359 const extra = sema.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
2435424360 const air_tag: Air.Inst.Tag = switch (extended.small) {
2435524361 0 => .cmpxchg_weak,
......@@ -24367,7 +24373,7 @@ fn zirCmpxchg(
2436724373 // zig fmt: on
2436824374 const expected_value = try sema.resolveInst(extra.expected_value);
2436924375 const elem_ty = sema.typeOf(expected_value);
24370 if (elem_ty.zigTypeTag(mod) == .Float) {
24376 if (elem_ty.zigTypeTag(zcu) == .Float) {
2437124377 return sema.fail(
2437224378 block,
2437324379 elem_ty_src,
......@@ -24411,7 +24417,7 @@ fn zirCmpxchg(
2441124417 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
2441224418 if (try sema.resolveValue(expected_value)) |expected_val| {
2441324419 if (try sema.resolveValue(new_value)) |new_val| {
24414 if (expected_val.isUndef(mod) or new_val.isUndef(mod)) {
24420 if (expected_val.isUndef(zcu) or new_val.isUndef(zcu)) {
2441524421 // TODO: this should probably cause the memory stored at the pointer
2441624422 // to become undef as well
2441724423 return pt.undefRef(result_ty);
......@@ -24420,7 +24426,7 @@ fn zirCmpxchg(
2442024426 const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src;
2442124427 const result_val = try pt.intern(.{ .opt = .{
2442224428 .ty = result_ty.toIntern(),
24423 .val = if (stored_val.eql(expected_val, elem_ty, mod)) blk: {
24429 .val = if (stored_val.eql(expected_val, elem_ty, zcu)) blk: {
2442424430 try sema.storePtr(block, src, ptr, new_value);
2442524431 break :blk .none;
2442624432 } else stored_val.toIntern(),
......@@ -24450,16 +24456,16 @@ fn zirCmpxchg(
2445024456
2445124457fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2445224458 const pt = sema.pt;
24453 const mod = pt.zcu;
24459 const zcu = pt.zcu;
2445424460 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2445524461 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2445624462 const src = block.nodeOffset(inst_data.src_node);
2445724463 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2445824464 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");
2445924465
24460 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(pt)});
24466 if (!dest_ty.isVector(zcu)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(pt)});
2446124467
24462 if (!dest_ty.hasRuntimeBits(pt)) {
24468 if (!dest_ty.hasRuntimeBits(zcu)) {
2446324469 const empty_aggregate = try pt.intern(.{ .aggregate = .{
2446424470 .ty = dest_ty.toIntern(),
2446524471 .storage = .{ .elems = &[_]InternPool.Index{} },
......@@ -24468,10 +24474,10 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2446824474 }
2446924475
2447024476 const operand = try sema.resolveInst(extra.rhs);
24471 const scalar_ty = dest_ty.childType(mod);
24477 const scalar_ty = dest_ty.childType(zcu);
2447224478 const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src);
2447324479 if (try sema.resolveValue(scalar)) |scalar_val| {
24474 if (scalar_val.isUndef(mod)) return pt.undefRef(dest_ty);
24480 if (scalar_val.isUndef(zcu)) return pt.undefRef(dest_ty);
2447524481 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());
2447624482 }
2447724483
......@@ -24490,23 +24496,23 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2449024496 const operand = try sema.resolveInst(extra.rhs);
2449124497 const operand_ty = sema.typeOf(operand);
2449224498 const pt = sema.pt;
24493 const mod = pt.zcu;
24499 const zcu = pt.zcu;
2449424500
24495 if (operand_ty.zigTypeTag(mod) != .Vector) {
24501 if (operand_ty.zigTypeTag(zcu) != .Vector) {
2449624502 return sema.fail(block, operand_src, "expected vector, found '{}'", .{operand_ty.fmt(pt)});
2449724503 }
2449824504
24499 const scalar_ty = operand_ty.childType(mod);
24505 const scalar_ty = operand_ty.childType(zcu);
2450024506
2450124507 // Type-check depending on operation.
2450224508 switch (operation) {
24503 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(mod)) {
24509 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) {
2450424510 .Int, .Bool => {},
2450524511 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{}'", .{
2450624512 @tagName(operation), operand_ty.fmt(pt),
2450724513 }),
2450824514 },
24509 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(mod)) {
24515 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
2451024516 .Int, .Float => {},
2451124517 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{}'", .{
2451224518 @tagName(operation), operand_ty.fmt(pt),
......@@ -24514,7 +24520,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2451424520 },
2451524521 }
2451624522
24517 const vec_len = operand_ty.vectorLen(mod);
24523 const vec_len = operand_ty.vectorLen(zcu);
2451824524 if (vec_len == 0) {
2451924525 // TODO re-evaluate if we should introduce a "neutral value" for some operations,
2452024526 // e.g. zero for add and one for mul.
......@@ -24522,7 +24528,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2452224528 }
2452324529
2452424530 if (try sema.resolveValue(operand)) |operand_val| {
24525 if (operand_val.isUndef(mod)) return pt.undefRef(scalar_ty);
24531 if (operand_val.isUndef(zcu)) return pt.undefRef(scalar_ty);
2452624532
2452724533 var accum: Value = try operand_val.elemValue(pt, 0);
2452824534 var i: u32 = 1;
......@@ -24532,8 +24538,8 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2453224538 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, pt),
2453324539 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, pt),
2453424540 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, pt),
24535 .Min => accum = accum.numberMin(elem_val, pt),
24536 .Max => accum = accum.numberMax(elem_val, pt),
24541 .Min => accum = accum.numberMin(elem_val, zcu),
24542 .Max => accum = accum.numberMax(elem_val, zcu),
2453724543 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),
2453824544 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, pt),
2453924545 }
......@@ -24553,7 +24559,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2455324559
2455424560fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2455524561 const pt = sema.pt;
24556 const mod = pt.zcu;
24562 const zcu = pt.zcu;
2455724563 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2455824564 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
2455924565 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -24566,8 +24572,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2456624572 var mask = try sema.resolveInst(extra.mask);
2456724573 var mask_ty = sema.typeOf(mask);
2456824574
24569 const mask_len = switch (sema.typeOf(mask).zigTypeTag(mod)) {
24570 .Array, .Vector => sema.typeOf(mask).arrayLen(mod),
24575 const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) {
24576 .Array, .Vector => sema.typeOf(mask).arrayLen(zcu),
2457124577 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(pt)}),
2457224578 };
2457324579 mask_ty = try pt.vectorType(.{
......@@ -24592,6 +24598,7 @@ fn analyzeShuffle(
2459224598 mask_len: u32,
2459324599) CompileError!Air.Inst.Ref {
2459424600 const pt = sema.pt;
24601 const zcu = pt.zcu;
2459524602 const a_src = block.builtinCallArgSrc(src_node, 1);
2459624603 const b_src = block.builtinCallArgSrc(src_node, 2);
2459724604 const mask_src = block.builtinCallArgSrc(src_node, 3);
......@@ -24603,16 +24610,16 @@ fn analyzeShuffle(
2460324610 .child = elem_ty.toIntern(),
2460424611 });
2460524612
24606 const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(pt.zcu)) {
24607 .Array, .Vector => sema.typeOf(a).arrayLen(pt.zcu),
24613 const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(zcu)) {
24614 .Array, .Vector => sema.typeOf(a).arrayLen(zcu),
2460824615 .Undefined => null,
2460924616 else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{
2461024617 elem_ty.fmt(pt),
2461124618 sema.typeOf(a).fmt(pt),
2461224619 }),
2461324620 };
24614 const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(pt.zcu)) {
24615 .Array, .Vector => sema.typeOf(b).arrayLen(pt.zcu),
24621 const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(zcu)) {
24622 .Array, .Vector => sema.typeOf(b).arrayLen(zcu),
2461624623 .Undefined => null,
2461724624 else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{
2461824625 elem_ty.fmt(pt),
......@@ -24644,9 +24651,9 @@ fn analyzeShuffle(
2464424651
2464524652 for (0..@intCast(mask_len)) |i| {
2464624653 const elem = try mask.elemValue(pt, i);
24647 if (elem.isUndef(pt.zcu)) continue;
24654 if (elem.isUndef(zcu)) continue;
2464824655 const elem_resolved = try sema.resolveLazyValue(elem);
24649 const int = elem_resolved.toSignedInt(pt);
24656 const int = elem_resolved.toSignedInt(zcu);
2465024657 var unsigned: u32 = undefined;
2465124658 var chosen: u32 = undefined;
2465224659 if (int >= 0) {
......@@ -24681,11 +24688,11 @@ fn analyzeShuffle(
2468124688 const values = try sema.arena.alloc(InternPool.Index, mask_len);
2468224689 for (values, 0..) |*value, i| {
2468324690 const mask_elem_val = try mask.elemValue(pt, i);
24684 if (mask_elem_val.isUndef(pt.zcu)) {
24691 if (mask_elem_val.isUndef(zcu)) {
2468524692 value.* = try pt.intern(.{ .undef = elem_ty.toIntern() });
2468624693 continue;
2468724694 }
24688 const int = mask_elem_val.toSignedInt(pt);
24695 const int = mask_elem_val.toSignedInt(zcu);
2468924696 const unsigned: u32 = @intCast(if (int >= 0) int else ~int);
2469024697 values[i] = (try (if (int >= 0) a_val else b_val).elemValue(pt, unsigned)).toIntern();
2469124698 }
......@@ -24743,7 +24750,7 @@ fn analyzeShuffle(
2474324750
2474424751fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2474524752 const pt = sema.pt;
24746 const mod = pt.zcu;
24753 const zcu = pt.zcu;
2474724754 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
2474824755
2474924756 const src = block.nodeOffset(extra.node);
......@@ -24757,8 +24764,8 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2475724764 const pred_uncoerced = try sema.resolveInst(extra.pred);
2475824765 const pred_ty = sema.typeOf(pred_uncoerced);
2475924766
24760 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) {
24761 .Vector, .Array => pred_ty.arrayLen(mod),
24767 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(zcu)) {
24768 .Vector, .Array => pred_ty.arrayLen(zcu),
2476224769 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(pt)}),
2476324770 };
2476424771 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));
......@@ -24781,13 +24788,13 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2478124788 const maybe_b = try sema.resolveValue(b);
2478224789
2478324790 const runtime_src = if (maybe_pred) |pred_val| rs: {
24784 if (pred_val.isUndef(mod)) return pt.undefRef(vec_ty);
24791 if (pred_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2478524792
2478624793 if (maybe_a) |a_val| {
24787 if (a_val.isUndef(mod)) return pt.undefRef(vec_ty);
24794 if (a_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2478824795
2478924796 if (maybe_b) |b_val| {
24790 if (b_val.isUndef(mod)) return pt.undefRef(vec_ty);
24797 if (b_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2479124798
2479224799 const elems = try sema.gpa.alloc(InternPool.Index, vec_len);
2479324800 defer sema.gpa.free(elems);
......@@ -24806,16 +24813,16 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2480624813 }
2480724814 } else {
2480824815 if (maybe_b) |b_val| {
24809 if (b_val.isUndef(mod)) return pt.undefRef(vec_ty);
24816 if (b_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2481024817 }
2481124818 break :rs a_src;
2481224819 }
2481324820 } else rs: {
2481424821 if (maybe_a) |a_val| {
24815 if (a_val.isUndef(mod)) return pt.undefRef(vec_ty);
24822 if (a_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2481624823 }
2481724824 if (maybe_b) |b_val| {
24818 if (b_val.isUndef(mod)) return pt.undefRef(vec_ty);
24825 if (b_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2481924826 }
2482024827 break :rs pred_src;
2482124828 };
......@@ -24882,7 +24889,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2488224889
2488324890fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2488424891 const pt = sema.pt;
24885 const mod = pt.zcu;
24892 const zcu = pt.zcu;
2488624893 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2488724894 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
2488824895 const src = block.nodeOffset(inst_data.src_node);
......@@ -24899,7 +24906,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2489924906 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
2490024907 const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation);
2490124908
24902 switch (elem_ty.zigTypeTag(mod)) {
24909 switch (elem_ty.zigTypeTag(zcu)) {
2490324910 .Enum => if (op != .Xchg) {
2490424911 return sema.fail(block, op_src, "@atomicRmw with enum only allowed with .Xchg", .{});
2490524912 },
......@@ -24939,12 +24946,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2493924946 .Xchg => operand_val,
2494024947 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),
2494124948 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),
24942 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, pt),
24943 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, pt),
24944 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, pt),
24945 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, pt),
24946 .Max => stored_val.numberMax (operand_val, pt),
24947 .Min => stored_val.numberMin (operand_val, pt),
24949 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, pt ),
24950 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, pt ),
24951 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, pt ),
24952 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, pt ),
24953 .Max => stored_val.numberMax (operand_val, zcu),
24954 .Min => stored_val.numberMin (operand_val, zcu),
2494824955 // zig fmt: on
2494924956 };
2495024957 try sema.storePtrVal(block, src, ptr_val, new_val, elem_ty);
......@@ -25021,19 +25028,19 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2502125028 const maybe_mulend2 = try sema.resolveValue(mulend2);
2502225029 const maybe_addend = try sema.resolveValue(addend);
2502325030 const pt = sema.pt;
25024 const mod = pt.zcu;
25031 const zcu = pt.zcu;
2502525032
25026 switch (ty.scalarType(mod).zigTypeTag(mod)) {
25033 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
2502725034 .ComptimeFloat, .Float => {},
2502825035 else => return sema.fail(block, src, "expected vector of floats or float type, found '{}'", .{ty.fmt(pt)}),
2502925036 }
2503025037
2503125038 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {
2503225039 if (maybe_mulend2) |mulend2_val| {
25033 if (mulend2_val.isUndef(mod)) return pt.undefRef(ty);
25040 if (mulend2_val.isUndef(zcu)) return pt.undefRef(ty);
2503425041
2503525042 if (maybe_addend) |addend_val| {
25036 if (addend_val.isUndef(mod)) return pt.undefRef(ty);
25043 if (addend_val.isUndef(zcu)) return pt.undefRef(ty);
2503725044 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, pt);
2503825045 return Air.internedToRef(result_val.toIntern());
2503925046 } else {
......@@ -25041,16 +25048,16 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2504125048 }
2504225049 } else {
2504325050 if (maybe_addend) |addend_val| {
25044 if (addend_val.isUndef(mod)) return pt.undefRef(ty);
25051 if (addend_val.isUndef(zcu)) return pt.undefRef(ty);
2504525052 }
2504625053 break :rs mulend2_src;
2504725054 }
2504825055 } else rs: {
2504925056 if (maybe_mulend2) |mulend2_val| {
25050 if (mulend2_val.isUndef(mod)) return pt.undefRef(ty);
25057 if (mulend2_val.isUndef(zcu)) return pt.undefRef(ty);
2505125058 }
2505225059 if (maybe_addend) |addend_val| {
25053 if (addend_val.isUndef(mod)) return pt.undefRef(ty);
25060 if (addend_val.isUndef(zcu)) return pt.undefRef(ty);
2505425061 }
2505525062 break :rs mulend1_src;
2505625063 };
......@@ -25073,7 +25080,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2507325080 defer tracy.end();
2507425081
2507525082 const pt = sema.pt;
25076 const mod = pt.zcu;
25083 const zcu = pt.zcu;
2507725084 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2507825085 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2507925086 const func_src = block.builtinCallArgSrc(inst_data.src_node, 1);
......@@ -25089,7 +25096,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2508925096 const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{
2509025097 .needed_comptime_reason = "call modifier must be comptime-known",
2509125098 });
25092 var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val);
25099 var modifier = zcu.toEnum(std.builtin.CallModifier, modifier_val);
2509325100 switch (modifier) {
2509425101 // These can be upgraded to comptime or nosuspend calls.
2509525102 .auto, .never_tail, .no_async => {
......@@ -25135,11 +25142,11 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2513525142 const args = try sema.resolveInst(extra.args);
2513625143
2513725144 const args_ty = sema.typeOf(args);
25138 if (!args_ty.isTuple(mod) and args_ty.toIntern() != .empty_struct_type) {
25145 if (!args_ty.isTuple(zcu) and args_ty.toIntern() != .empty_struct_type) {
2513925146 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(pt)});
2514025147 }
2514125148
25142 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));
25149 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(zcu));
2514325150 for (resolved_args, 0..) |*resolved, i| {
2514425151 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty);
2514525152 }
......@@ -25219,7 +25226,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2521925226 var actual_parent_ptr_info: InternPool.Key.PtrType = .{
2522025227 .child = parent_ty.toIntern(),
2522125228 .flags = .{
25222 .alignment = try parent_ptr_ty.ptrAlignmentAdvanced(pt, .sema),
25229 .alignment = try parent_ptr_ty.ptrAlignmentSema(pt),
2522325230 .is_const = field_ptr_info.flags.is_const,
2522425231 .is_volatile = field_ptr_info.flags.is_volatile,
2522525232 .is_allowzero = field_ptr_info.flags.is_allowzero,
......@@ -25231,7 +25238,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2523125238 var actual_field_ptr_info: InternPool.Key.PtrType = .{
2523225239 .child = field_ty.toIntern(),
2523325240 .flags = .{
25234 .alignment = try field_ptr_ty.ptrAlignmentAdvanced(pt, .sema),
25241 .alignment = try field_ptr_ty.ptrAlignmentSema(pt),
2523525242 .is_const = field_ptr_info.flags.is_const,
2523625243 .is_volatile = field_ptr_info.flags.is_volatile,
2523725244 .is_allowzero = field_ptr_info.flags.is_allowzero,
......@@ -25242,13 +25249,20 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2524225249 switch (parent_ty.containerLayout(zcu)) {
2524325250 .auto => {
2524425251 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(
25245 if (zcu.typeToStruct(parent_ty)) |struct_obj| try pt.structFieldAlignmentAdvanced(
25252 if (zcu.typeToStruct(parent_ty)) |struct_obj| try field_ty.structFieldAlignmentAdvanced(
2524625253 struct_obj.fieldAlign(ip, field_index),
25247 field_ty,
2524825254 struct_obj.layout,
2524925255 .sema,
25256 pt.zcu,
25257 pt.tid,
2525025258 ) else if (zcu.typeToUnion(parent_ty)) |union_obj|
25251 try pt.unionFieldNormalAlignmentAdvanced(union_obj, field_index, .sema)
25259 try Type.unionFieldNormalAlignmentAdvanced(
25260 union_obj,
25261 field_index,
25262 .sema,
25263 pt.zcu,
25264 pt.tid,
25265 )
2525225266 else
2525325267 actual_field_ptr_info.flags.alignment,
2525425268 );
......@@ -25257,7 +25271,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2525725271 actual_field_ptr_info.packed_offset = .{ .bit_offset = 0, .host_size = 0 };
2525825272 },
2525925273 .@"extern" => {
25260 const field_offset = parent_ty.structFieldOffset(field_index, pt);
25274 const field_offset = parent_ty.structFieldOffset(field_index, zcu);
2526125275 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(if (field_offset > 0)
2526225276 Alignment.fromLog2Units(@ctz(field_offset))
2526325277 else
......@@ -25287,7 +25301,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2528725301 .Struct => switch (parent_ty.containerLayout(zcu)) {
2528825302 .auto => {},
2528925303 .@"extern" => {
25290 const byte_offset = parent_ty.structFieldOffset(field_index, pt);
25304 const byte_offset = parent_ty.structFieldOffset(field_index, zcu);
2529125305 const parent_ptr_val = try sema.ptrSubtract(block, field_ptr_src, field_ptr_val, byte_offset, actual_parent_ptr_ty);
2529225306 break :result Air.internedToRef(parent_ptr_val.toIntern());
2529325307 },
......@@ -25428,7 +25442,7 @@ fn analyzeMinMax(
2542825442 assert(operands.len == operand_srcs.len);
2542925443 assert(operands.len > 0);
2543025444 const pt = sema.pt;
25431 const mod = pt.zcu;
25445 const zcu = pt.zcu;
2543225446
2543325447 if (operands.len == 1) return operands[0];
2543425448
......@@ -25466,20 +25480,20 @@ fn analyzeMinMax(
2546625480 switch (bounds_status) {
2546725481 .unknown, .defined => refine_bounds: {
2546825482 const ty = sema.typeOf(operand);
25469 if (!ty.scalarType(mod).isInt(mod) and !ty.scalarType(mod).eql(Type.comptime_int, mod)) {
25483 if (!ty.scalarType(zcu).isInt(zcu) and !ty.scalarType(zcu).eql(Type.comptime_int, zcu)) {
2547025484 bounds_status = .non_integral;
2547125485 break :refine_bounds;
2547225486 }
2547325487 const scalar_bounds: ?[2]Value = bounds: {
25474 if (!ty.isVector(mod)) break :bounds try uncoerced_val.intValueBounds(pt);
25488 if (!ty.isVector(zcu)) break :bounds try uncoerced_val.intValueBounds(pt);
2547525489 var cur_bounds: [2]Value = try Value.intValueBounds(try uncoerced_val.elemValue(pt, 0), pt) orelse break :bounds null;
25476 const len = try sema.usizeCast(block, src, ty.vectorLen(mod));
25490 const len = try sema.usizeCast(block, src, ty.vectorLen(zcu));
2547725491 for (1..len) |i| {
2547825492 const elem = try uncoerced_val.elemValue(pt, i);
2547925493 const elem_bounds = try elem.intValueBounds(pt) orelse break :bounds null;
2548025494 cur_bounds = .{
25481 Value.numberMin(elem_bounds[0], cur_bounds[0], pt),
25482 Value.numberMax(elem_bounds[1], cur_bounds[1], pt),
25495 Value.numberMin(elem_bounds[0], cur_bounds[0], zcu),
25496 Value.numberMax(elem_bounds[1], cur_bounds[1], zcu),
2548325497 };
2548425498 }
2548525499 break :bounds cur_bounds;
......@@ -25490,8 +25504,8 @@ fn analyzeMinMax(
2549025504 cur_max_scalar = bounds[1];
2549125505 bounds_status = .defined;
2549225506 } else {
25493 cur_min_scalar = opFunc(cur_min_scalar, bounds[0], pt);
25494 cur_max_scalar = opFunc(cur_max_scalar, bounds[1], pt);
25507 cur_min_scalar = opFunc(cur_min_scalar, bounds[0], zcu);
25508 cur_max_scalar = opFunc(cur_max_scalar, bounds[1], zcu);
2549525509 }
2549625510 }
2549725511 },
......@@ -25509,7 +25523,7 @@ fn analyzeMinMax(
2550925523 const operand_val = try sema.resolveLazyValue(simd_op.rhs_val.?); // we checked the operand was resolvable above
2551025524
2551125525 const vec_len = simd_op.len orelse {
25512 const result_val = opFunc(cur_val, operand_val, pt);
25526 const result_val = opFunc(cur_val, operand_val, zcu);
2551325527 cur_minmax = Air.internedToRef(result_val.toIntern());
2551425528 continue;
2551525529 };
......@@ -25517,7 +25531,7 @@ fn analyzeMinMax(
2551725531 for (elems, 0..) |*elem, i| {
2551825532 const lhs_elem_val = try cur_val.elemValue(pt, i);
2551925533 const rhs_elem_val = try operand_val.elemValue(pt, i);
25520 const uncoerced_elem = opFunc(lhs_elem_val, rhs_elem_val, pt);
25534 const uncoerced_elem = opFunc(lhs_elem_val, rhs_elem_val, zcu);
2552125535 elem.* = (try pt.getCoerced(uncoerced_elem, simd_op.scalar_ty)).toIntern();
2552225536 }
2552325537 cur_minmax = Air.internedToRef((try pt.intern(.{ .aggregate = .{
......@@ -25537,19 +25551,19 @@ fn analyzeMinMax(
2553725551 const val = (try sema.resolveValue(ct_minmax_ref)).?;
2553825552 const orig_ty = sema.typeOf(ct_minmax_ref);
2553925553
25540 if (opt_runtime_idx == null and orig_ty.scalarType(mod).eql(Type.comptime_int, mod)) {
25554 if (opt_runtime_idx == null and orig_ty.scalarType(zcu).eql(Type.comptime_int, zcu)) {
2554125555 // If all arguments were `comptime_int`, and there are no runtime args, we'll preserve that type
2554225556 break :refine;
2554325557 }
2554425558
2554525559 // We can't refine float types
25546 if (orig_ty.scalarType(mod).isAnyFloat()) break :refine;
25560 if (orig_ty.scalarType(zcu).isAnyFloat()) break :refine;
2554725561
2554825562 assert(bounds_status == .defined); // there was a non-comptime-int integral comptime-known arg
2554925563
2555025564 const refined_scalar_ty = try pt.intFittingRange(cur_min_scalar, cur_max_scalar);
25551 const refined_ty = if (orig_ty.isVector(mod)) try pt.vectorType(.{
25552 .len = orig_ty.vectorLen(mod),
25565 const refined_ty = if (orig_ty.isVector(zcu)) try pt.vectorType(.{
25566 .len = orig_ty.vectorLen(zcu),
2555325567 .child = refined_scalar_ty.toIntern(),
2555425568 }) else refined_scalar_ty;
2555525569
......@@ -25570,7 +25584,7 @@ fn analyzeMinMax(
2557025584 // If the comptime-known part is undef we can avoid emitting actual instructions later
2557125585 const known_undef = if (cur_minmax) |operand| blk: {
2557225586 const val = (try sema.resolveValue(operand)).?;
25573 break :blk val.isUndef(mod);
25587 break :blk val.isUndef(zcu);
2557425588 } else false;
2557525589
2557625590 if (cur_minmax == null) {
......@@ -25580,8 +25594,8 @@ fn analyzeMinMax(
2558025594 cur_minmax = operands[0];
2558125595 cur_minmax_src = runtime_src;
2558225596 runtime_known.unset(0); // don't look at this operand in the loop below
25583 const scalar_ty = sema.typeOf(cur_minmax.?).scalarType(mod);
25584 if (scalar_ty.isInt(mod)) {
25597 const scalar_ty = sema.typeOf(cur_minmax.?).scalarType(zcu);
25598 if (scalar_ty.isInt(zcu)) {
2558525599 cur_min_scalar = try scalar_ty.minInt(pt, scalar_ty);
2558625600 cur_max_scalar = try scalar_ty.maxInt(pt, scalar_ty);
2558725601 bounds_status = .defined;
......@@ -25605,7 +25619,7 @@ fn analyzeMinMax(
2560525619 // Compute the bounds of this type
2560625620 switch (bounds_status) {
2560725621 .unknown, .defined => refine_bounds: {
25608 const scalar_ty = sema.typeOf(rhs).scalarType(mod);
25622 const scalar_ty = sema.typeOf(rhs).scalarType(zcu);
2560925623 if (scalar_ty.isAnyFloat()) {
2561025624 bounds_status = .non_integral;
2561125625 break :refine_bounds;
......@@ -25617,8 +25631,8 @@ fn analyzeMinMax(
2561725631 cur_max_scalar = scalar_max;
2561825632 bounds_status = .defined;
2561925633 } else {
25620 cur_min_scalar = opFunc(cur_min_scalar, scalar_min, pt);
25621 cur_max_scalar = opFunc(cur_max_scalar, scalar_max, pt);
25634 cur_min_scalar = opFunc(cur_min_scalar, scalar_min, zcu);
25635 cur_max_scalar = opFunc(cur_max_scalar, scalar_max, zcu);
2562225636 }
2562325637 },
2562425638 .non_integral => {},
......@@ -25627,18 +25641,18 @@ fn analyzeMinMax(
2562725641
2562825642 // Finally, refine the type based on the known bounds.
2562925643 const unrefined_ty = sema.typeOf(cur_minmax.?);
25630 if (unrefined_ty.scalarType(mod).isAnyFloat()) {
25644 if (unrefined_ty.scalarType(zcu).isAnyFloat()) {
2563125645 // We can't refine floats, so we're done.
2563225646 return cur_minmax.?;
2563325647 }
2563425648 assert(bounds_status == .defined); // there were integral runtime operands
2563525649 const refined_scalar_ty = try pt.intFittingRange(cur_min_scalar, cur_max_scalar);
25636 const refined_ty = if (unrefined_ty.isVector(mod)) try pt.vectorType(.{
25637 .len = unrefined_ty.vectorLen(mod),
25650 const refined_ty = if (unrefined_ty.isVector(zcu)) try pt.vectorType(.{
25651 .len = unrefined_ty.vectorLen(zcu),
2563825652 .child = refined_scalar_ty.toIntern(),
2563925653 }) else refined_scalar_ty;
2564025654
25641 if (!refined_ty.eql(unrefined_ty, mod)) {
25655 if (!refined_ty.eql(unrefined_ty, zcu)) {
2564225656 // We've reduced the type - cast the result down
2564325657 return block.addTyOp(.intcast, refined_ty, cur_minmax.?);
2564425658 }
......@@ -25648,9 +25662,9 @@ fn analyzeMinMax(
2564825662
2564925663fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !Air.Inst.Ref {
2565025664 const pt = sema.pt;
25651 const mod = pt.zcu;
25665 const zcu = pt.zcu;
2565225666 const ptr_ty = sema.typeOf(ptr);
25653 const info = ptr_ty.ptrInfo(mod);
25667 const info = ptr_ty.ptrInfo(zcu);
2565425668 if (info.flags.size == .One) {
2565525669 // Already an array pointer.
2565625670 return ptr;
......@@ -25670,7 +25684,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
2567025684 },
2567125685 });
2567225686 const non_slice_ptr = if (info.flags.size == .Slice)
25673 try block.addTyOp(.slice_ptr, ptr_ty.slicePtrFieldType(mod), ptr)
25687 try block.addTyOp(.slice_ptr, ptr_ty.slicePtrFieldType(zcu), ptr)
2567425688 else
2567525689 ptr;
2567625690 return block.addBitCast(new_ty, non_slice_ptr);
......@@ -25689,10 +25703,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2568925703 const dest_len = try indexablePtrLenOrNone(sema, block, dest_src, dest_ptr);
2569025704 const src_len = try indexablePtrLenOrNone(sema, block, src_src, src_ptr);
2569125705 const pt = sema.pt;
25692 const mod = pt.zcu;
25693 const target = mod.getTarget();
25706 const zcu = pt.zcu;
25707 const target = zcu.getTarget();
2569425708
25695 if (dest_ty.isConstPtr(mod)) {
25709 if (dest_ty.isConstPtr(zcu)) {
2569625710 return sema.fail(block, dest_src, "cannot memcpy to constant pointer", .{});
2569725711 }
2569825712
......@@ -25755,7 +25769,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2575525769 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {
2575625770 if (!sema.isComptimeMutablePtr(dest_ptr_val)) break :rs dest_src;
2575725771 if (try sema.resolveDefinedValue(block, src_src, src_ptr)) |_| {
25758 const len_u64 = (try len_val.?.getUnsignedIntAdvanced(pt, .sema)).?;
25772 const len_u64 = try len_val.?.toUnsignedIntSema(pt);
2575925773 const len = try sema.usizeCast(block, dest_src, len_u64);
2576025774 for (0..len) |i| {
2576125775 const elem_index = try pt.intRef(Type.usize, i);
......@@ -25798,12 +25812,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2579825812 // lowering. The AIR instruction requires pointers with element types of
2579925813 // equal ABI size.
2580025814
25801 if (dest_ty.zigTypeTag(mod) != .Pointer or src_ty.zigTypeTag(mod) != .Pointer) {
25815 if (dest_ty.zigTypeTag(zcu) != .Pointer or src_ty.zigTypeTag(zcu) != .Pointer) {
2580225816 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the source or destination iterable is a tuple", .{});
2580325817 }
2580425818
25805 const dest_elem_ty = dest_ty.elemType2(mod);
25806 const src_elem_ty = src_ty.elemType2(mod);
25819 const dest_elem_ty = dest_ty.elemType2(zcu);
25820 const src_elem_ty = src_ty.elemType2(zcu);
2580725821 if (.ok != try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, true, target, dest_src, src_src, null)) {
2580825822 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the element types have different ABI sizes", .{});
2580925823 }
......@@ -25827,7 +25841,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2582725841 // Change the src from slice to a many pointer, to avoid multiple ptr
2582825842 // slice extractions in AIR instructions.
2582925843 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25830 if (new_src_ptr_ty.isSlice(mod)) {
25844 if (new_src_ptr_ty.isSlice(zcu)) {
2583125845 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
2583225846 }
2583325847 } else if (dest_len == .none and len_val == null) {
......@@ -25835,7 +25849,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2583525849 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
2583625850 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, LazySrcLoc.unneeded, dest_src, dest_src, dest_src, false);
2583725851 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25838 if (new_src_ptr_ty.isSlice(mod)) {
25852 if (new_src_ptr_ty.isSlice(zcu)) {
2583925853 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
2584025854 }
2584125855 }
......@@ -25854,10 +25868,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2585425868 // Extract raw pointer from dest slice. The AIR instructions could support them, but
2585525869 // it would cause redundant machine code instructions.
2585625870 const new_dest_ptr_ty = sema.typeOf(new_dest_ptr);
25857 const raw_dest_ptr = if (new_dest_ptr_ty.isSlice(mod))
25871 const raw_dest_ptr = if (new_dest_ptr_ty.isSlice(zcu))
2585825872 try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty)
25859 else if (new_dest_ptr_ty.ptrSize(mod) == .One) ptr: {
25860 var dest_manyptr_ty_key = mod.intern_pool.indexToKey(new_dest_ptr_ty.toIntern()).ptr_type;
25873 else if (new_dest_ptr_ty.ptrSize(zcu) == .One) ptr: {
25874 var dest_manyptr_ty_key = zcu.intern_pool.indexToKey(new_dest_ptr_ty.toIntern()).ptr_type;
2586125875 assert(dest_manyptr_ty_key.flags.size == .One);
2586225876 dest_manyptr_ty_key.child = dest_elem_ty.toIntern();
2586325877 dest_manyptr_ty_key.flags.size = .Many;
......@@ -25865,10 +25879,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2586525879 } else new_dest_ptr;
2586625880
2586725881 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25868 const raw_src_ptr = if (new_src_ptr_ty.isSlice(mod))
25882 const raw_src_ptr = if (new_src_ptr_ty.isSlice(zcu))
2586925883 try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty)
25870 else if (new_src_ptr_ty.ptrSize(mod) == .One) ptr: {
25871 var src_manyptr_ty_key = mod.intern_pool.indexToKey(new_src_ptr_ty.toIntern()).ptr_type;
25884 else if (new_src_ptr_ty.ptrSize(zcu) == .One) ptr: {
25885 var src_manyptr_ty_key = zcu.intern_pool.indexToKey(new_src_ptr_ty.toIntern()).ptr_type;
2587225886 assert(src_manyptr_ty_key.flags.size == .One);
2587325887 src_manyptr_ty_key.child = src_elem_ty.toIntern();
2587425888 src_manyptr_ty_key.flags.size = .Many;
......@@ -25896,9 +25910,9 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2589625910
2589725911fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2589825912 const pt = sema.pt;
25899 const mod = pt.zcu;
25913 const zcu = pt.zcu;
2590025914 const gpa = sema.gpa;
25901 const ip = &mod.intern_pool;
25915 const ip = &zcu.intern_pool;
2590225916 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2590325917 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2590425918 const src = block.nodeOffset(inst_data.src_node);
......@@ -25909,17 +25923,17 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2590925923 const dest_ptr_ty = sema.typeOf(dest_ptr);
2591025924 try checkMemOperand(sema, block, dest_src, dest_ptr_ty);
2591125925
25912 if (dest_ptr_ty.isConstPtr(mod)) {
25926 if (dest_ptr_ty.isConstPtr(zcu)) {
2591325927 return sema.fail(block, dest_src, "cannot memset constant pointer", .{});
2591425928 }
2591525929
2591625930 const dest_elem_ty: Type = dest_elem_ty: {
25917 const ptr_info = dest_ptr_ty.ptrInfo(mod);
25931 const ptr_info = dest_ptr_ty.ptrInfo(zcu);
2591825932 switch (ptr_info.flags.size) {
2591925933 .Slice => break :dest_elem_ty Type.fromInterned(ptr_info.child),
2592025934 .One => {
25921 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
25922 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(mod);
25935 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Array) {
25936 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(zcu);
2592325937 }
2592425938 },
2592525939 .Many, .C => {},
......@@ -25940,7 +25954,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2594025954 const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;
2594125955 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), dest_src);
2594225956 const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src;
25943 const len_u64 = (try len_val.getUnsignedIntAdvanced(pt, .sema)).?;
25957 const len_u64 = try len_val.toUnsignedIntSema(pt);
2594425958 const len = try sema.usizeCast(block, dest_src, len_u64);
2594525959 if (len == 0) {
2594625960 // This AIR instruction guarantees length > 0 if it is comptime-known.
......@@ -25958,12 +25972,12 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2595825972 .storage = .{ .repeated_elem = elem_val.toIntern() },
2595925973 } }));
2596025974 const array_ptr_ty = ty: {
25961 var info = dest_ptr_ty.ptrInfo(mod);
25975 var info = dest_ptr_ty.ptrInfo(zcu);
2596225976 info.flags.size = .One;
2596325977 info.child = array_ty.toIntern();
2596425978 break :ty try pt.ptrType(info);
2596525979 };
25966 const raw_ptr_val = if (dest_ptr_ty.isSlice(mod)) ptr_val.slicePtr(mod) else ptr_val;
25980 const raw_ptr_val = if (dest_ptr_ty.isSlice(zcu)) ptr_val.slicePtr(zcu) else ptr_val;
2596725981 const array_ptr_val = try pt.getCoerced(raw_ptr_val, array_ptr_ty);
2596825982 return sema.storePtrVal(block, src, array_ptr_val, array_val, array_ty);
2596925983 };
......@@ -26129,10 +26143,10 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2612926143 defer tracy.end();
2613026144
2613126145 const pt = sema.pt;
26132 const mod = pt.zcu;
26146 const zcu = pt.zcu;
2613326147 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2613426148 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
26135 const target = mod.getTarget();
26149 const target = zcu.getTarget();
2613626150
2613726151 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });
2613826152 const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node });
......@@ -26207,7 +26221,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2620726221 if (val.isGenericPoison()) {
2620826222 break :blk null;
2620926223 }
26210 break :blk mod.toEnum(std.builtin.AddressSpace, val);
26224 break :blk zcu.toEnum(std.builtin.AddressSpace, val);
2621126225 } else if (extra.data.bits.has_addrspace_ref) blk: {
2621226226 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2621326227 extra_index += 1;
......@@ -26226,7 +26240,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2622626240 error.GenericPoison => break :blk null,
2622726241 else => |e| return e,
2622826242 };
26229 break :blk mod.toEnum(std.builtin.AddressSpace, addrspace_val);
26243 break :blk zcu.toEnum(std.builtin.AddressSpace, addrspace_val);
2623026244 } else target_util.defaultAddressSpace(target, .function);
2623126245
2623226246 const section: Section = if (extra.data.bits.has_section_body) blk: {
......@@ -26272,7 +26286,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2627226286 if (val.isGenericPoison()) {
2627326287 break :blk null;
2627426288 }
26275 break :blk mod.toEnum(std.builtin.CallingConvention, val);
26289 break :blk zcu.toEnum(std.builtin.CallingConvention, val);
2627626290 } else if (extra.data.bits.has_cc_ref) blk: {
2627726291 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2627826292 extra_index += 1;
......@@ -26291,18 +26305,18 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2629126305 error.GenericPoison => break :blk null,
2629226306 else => |e| return e,
2629326307 };
26294 break :blk mod.toEnum(std.builtin.CallingConvention, cc_val);
26308 break :blk zcu.toEnum(std.builtin.CallingConvention, cc_val);
2629526309 } else cc: {
2629626310 if (has_body) {
2629726311 const decl_inst = if (sema.generic_owner != .none) decl_inst: {
2629826312 // Generic instance -- use the original function declaration to
2629926313 // look for the `export` syntax.
26300 const nav = mod.intern_pool.getNav(mod.funcInfo(sema.generic_owner).owner_nav);
26301 const cau = mod.intern_pool.getCau(nav.analysis_owner.unwrap().?);
26314 const nav = zcu.intern_pool.getNav(zcu.funcInfo(sema.generic_owner).owner_nav);
26315 const cau = zcu.intern_pool.getCau(nav.analysis_owner.unwrap().?);
2630226316 break :decl_inst cau.zir_index;
2630326317 } else sema.getOwnerCauDeclInst(); // not an instantiation so we're analyzing a function declaration Cau
2630426318
26305 const zir_decl = sema.code.getDeclaration(decl_inst.resolve(&mod.intern_pool) orelse return error.AnalysisFail)[0];
26319 const zir_decl = sema.code.getDeclaration(decl_inst.resolve(&zcu.intern_pool) orelse return error.AnalysisFail)[0];
2630626320 if (zir_decl.flags.is_export) {
2630726321 break :cc .C;
2630826322 }
......@@ -26408,7 +26422,7 @@ fn zirCDefine(
2640826422 extended: Zir.Inst.Extended.InstData,
2640926423) CompileError!Air.Inst.Ref {
2641026424 const pt = sema.pt;
26411 const mod = pt.zcu;
26425 const zcu = pt.zcu;
2641226426 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2641326427 const name_src = block.builtinCallArgSrc(extra.node, 0);
2641426428 const val_src = block.builtinCallArgSrc(extra.node, 1);
......@@ -26417,7 +26431,7 @@ fn zirCDefine(
2641726431 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
2641826432 });
2641926433 const rhs = try sema.resolveInst(extra.rhs);
26420 if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) {
26434 if (sema.typeOf(rhs).zigTypeTag(zcu) != .Void) {
2642126435 const value = try sema.resolveConstString(block, val_src, extra.rhs, .{
2642226436 .needed_comptime_reason = "value of macro being undefined must be comptime-known",
2642326437 });
......@@ -26490,9 +26504,9 @@ fn resolvePrefetchOptions(
2649026504 zir_ref: Zir.Inst.Ref,
2649126505) CompileError!std.builtin.PrefetchOptions {
2649226506 const pt = sema.pt;
26493 const mod = pt.zcu;
26507 const zcu = pt.zcu;
2649426508 const gpa = sema.gpa;
26495 const ip = &mod.intern_pool;
26509 const ip = &zcu.intern_pool;
2649626510 const options_ty = try pt.getBuiltinType("PrefetchOptions");
2649726511 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2649826512
......@@ -26516,9 +26530,9 @@ fn resolvePrefetchOptions(
2651626530 });
2651726531
2651826532 return std.builtin.PrefetchOptions{
26519 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
26533 .rw = zcu.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
2652026534 .locality = @intCast(try locality_val.toUnsignedIntSema(pt)),
26521 .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
26535 .cache = zcu.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
2652226536 };
2652326537}
2652426538
......@@ -26562,9 +26576,9 @@ fn resolveExternOptions(
2656226576 is_thread_local: bool = false,
2656326577} {
2656426578 const pt = sema.pt;
26565 const mod = pt.zcu;
26579 const zcu = pt.zcu;
2656626580 const gpa = sema.gpa;
26567 const ip = &mod.intern_pool;
26581 const ip = &zcu.intern_pool;
2656826582 const options_inst = try sema.resolveInst(zir_ref);
2656926583 const extern_options_ty = try pt.getBuiltinType("ExternOptions");
2657026584 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
......@@ -26588,14 +26602,14 @@ fn resolveExternOptions(
2658826602 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
2658926603 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
2659026604 });
26591 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
26605 const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val);
2659226606
2659326607 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "is_thread_local", .no_embedded_nulls), thread_local_src);
2659426608 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
2659526609 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
2659626610 });
2659726611
26598 const library_name = if (library_name_val.optionalValue(mod)) |library_name_payload| library_name: {
26612 const library_name = if (library_name_val.optionalValue(zcu)) |library_name_payload| library_name: {
2659926613 const library_name = try sema.toConstString(block, library_src, Air.internedToRef(library_name_payload.toIntern()), .{
2660026614 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
2660126615 });
......@@ -26628,14 +26642,14 @@ fn zirBuiltinExtern(
2662826642 extended: Zir.Inst.Extended.InstData,
2662926643) CompileError!Air.Inst.Ref {
2663026644 const pt = sema.pt;
26631 const mod = pt.zcu;
26632 const ip = &mod.intern_pool;
26645 const zcu = pt.zcu;
26646 const ip = &zcu.intern_pool;
2663326647 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2663426648 const ty_src = block.builtinCallArgSrc(extra.node, 0);
2663526649 const options_src = block.builtinCallArgSrc(extra.node, 1);
2663626650
2663726651 var ty = try sema.resolveType(block, ty_src, extra.lhs);
26638 if (!ty.isPtrAtRuntime(mod)) {
26652 if (!ty.isPtrAtRuntime(zcu)) {
2663926653 return sema.fail(block, ty_src, "expected (optional) pointer", .{});
2664026654 }
2664126655 if (!try sema.validateExternType(ty, .other)) {
......@@ -26652,10 +26666,10 @@ fn zirBuiltinExtern(
2665226666
2665326667 // TODO: error for threadlocal functions, non-const functions, etc
2665426668
26655 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
26669 if (options.linkage == .weak and !ty.ptrAllowsZero(zcu)) {
2665626670 ty = try pt.optionalType(ty.toIntern());
2665726671 }
26658 const ptr_info = ty.ptrInfo(mod);
26672 const ptr_info = ty.ptrInfo(zcu);
2665926673
2666026674 const extern_val = try pt.getExtern(.{
2666126675 .name = options.name,
......@@ -26801,7 +26815,7 @@ fn validateVarType(
2680126815 is_extern: bool,
2680226816) CompileError!void {
2680326817 const pt = sema.pt;
26804 const mod = pt.zcu;
26818 const zcu = pt.zcu;
2680526819 if (is_extern) {
2680626820 if (!try sema.validateExternType(var_ty, .other)) {
2680726821 const msg = msg: {
......@@ -26813,7 +26827,7 @@ fn validateVarType(
2681326827 return sema.failWithOwnedErrorMsg(block, msg);
2681426828 }
2681526829 } else {
26816 if (var_ty.zigTypeTag(mod) == .Opaque) {
26830 if (var_ty.zigTypeTag(zcu) == .Opaque) {
2681726831 return sema.fail(
2681826832 block,
2681926833 src,
......@@ -26823,14 +26837,14 @@ fn validateVarType(
2682326837 }
2682426838 }
2682526839
26826 if (!try sema.typeRequiresComptime(var_ty)) return;
26840 if (!try var_ty.comptimeOnlySema(pt)) return;
2682726841
2682826842 const msg = msg: {
2682926843 const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(pt)});
2683026844 errdefer msg.destroy(sema.gpa);
2683126845
2683226846 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
26833 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
26847 if (var_ty.zigTypeTag(zcu) == .ComptimeInt or var_ty.zigTypeTag(zcu) == .ComptimeFloat) {
2683426848 try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
2683526849 }
2683626850
......@@ -26843,7 +26857,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
2684326857
2684426858fn explainWhyTypeIsComptime(
2684526859 sema: *Sema,
26846 msg: *Module.ErrorMsg,
26860 msg: *Zcu.ErrorMsg,
2684726861 src_loc: LazySrcLoc,
2684826862 ty: Type,
2684926863) CompileError!void {
......@@ -26856,15 +26870,15 @@ fn explainWhyTypeIsComptime(
2685626870
2685726871fn explainWhyTypeIsComptimeInner(
2685826872 sema: *Sema,
26859 msg: *Module.ErrorMsg,
26873 msg: *Zcu.ErrorMsg,
2686026874 src_loc: LazySrcLoc,
2686126875 ty: Type,
2686226876 type_set: *TypeSet,
2686326877) CompileError!void {
2686426878 const pt = sema.pt;
26865 const mod = pt.zcu;
26866 const ip = &mod.intern_pool;
26867 switch (ty.zigTypeTag(mod)) {
26879 const zcu = pt.zcu;
26880 const ip = &zcu.intern_pool;
26881 switch (ty.zigTypeTag(zcu)) {
2686826882 .Bool,
2686926883 .Int,
2687026884 .Float,
......@@ -26896,12 +26910,12 @@ fn explainWhyTypeIsComptimeInner(
2689626910 },
2689726911
2689826912 .Array, .Vector => {
26899 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(mod), type_set);
26913 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(zcu), type_set);
2690026914 },
2690126915 .Pointer => {
26902 const elem_ty = ty.elemType2(mod);
26903 if (elem_ty.zigTypeTag(mod) == .Fn) {
26904 const fn_info = mod.typeToFunc(elem_ty).?;
26916 const elem_ty = ty.elemType2(zcu);
26917 if (elem_ty.zigTypeTag(zcu) == .Fn) {
26918 const fn_info = zcu.typeToFunc(elem_ty).?;
2690526919 if (fn_info.is_generic) {
2690626920 try sema.errNote(src_loc, msg, "function is generic", .{});
2690726921 }
......@@ -26909,25 +26923,25 @@ fn explainWhyTypeIsComptimeInner(
2690926923 .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}),
2691026924 else => {},
2691126925 }
26912 if (Type.fromInterned(fn_info.return_type).comptimeOnly(pt)) {
26926 if (Type.fromInterned(fn_info.return_type).comptimeOnly(zcu)) {
2691326927 try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{});
2691426928 }
2691526929 return;
2691626930 }
26917 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(mod), type_set);
26931 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(zcu), type_set);
2691826932 },
2691926933
2692026934 .Optional => {
26921 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.optionalChild(mod), type_set);
26935 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.optionalChild(zcu), type_set);
2692226936 },
2692326937 .ErrorUnion => {
26924 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.errorUnionPayload(mod), type_set);
26938 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.errorUnionPayload(zcu), type_set);
2692526939 },
2692626940
2692726941 .Struct => {
2692826942 if ((try type_set.getOrPut(sema.gpa, ty.toIntern())).found_existing) return;
2692926943
26930 if (mod.typeToStruct(ty)) |struct_type| {
26944 if (zcu.typeToStruct(ty)) |struct_type| {
2693126945 for (0..struct_type.field_types.len) |i| {
2693226946 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
2693326947 const field_src: LazySrcLoc = .{
......@@ -26935,7 +26949,7 @@ fn explainWhyTypeIsComptimeInner(
2693526949 .offset = .{ .container_field_type = @intCast(i) },
2693626950 };
2693726951
26938 if (try sema.typeRequiresComptime(field_ty)) {
26952 if (try field_ty.comptimeOnlySema(pt)) {
2693926953 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});
2694026954 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2694126955 }
......@@ -26947,7 +26961,7 @@ fn explainWhyTypeIsComptimeInner(
2694726961 .Union => {
2694826962 if ((try type_set.getOrPut(sema.gpa, ty.toIntern())).found_existing) return;
2694926963
26950 if (mod.typeToUnion(ty)) |union_obj| {
26964 if (zcu.typeToUnion(ty)) |union_obj| {
2695126965 for (0..union_obj.field_types.len) |i| {
2695226966 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
2695326967 const field_src: LazySrcLoc = .{
......@@ -26955,7 +26969,7 @@ fn explainWhyTypeIsComptimeInner(
2695526969 .offset = .{ .container_field_type = @intCast(i) },
2695626970 };
2695726971
26958 if (try sema.typeRequiresComptime(field_ty)) {
26972 if (try field_ty.comptimeOnlySema(pt)) {
2695926973 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});
2696026974 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2696126975 }
......@@ -26983,8 +26997,8 @@ fn validateExternType(
2698326997 position: ExternPosition,
2698426998) !bool {
2698526999 const pt = sema.pt;
26986 const mod = pt.zcu;
26987 switch (ty.zigTypeTag(mod)) {
27000 const zcu = pt.zcu;
27001 switch (ty.zigTypeTag(zcu)) {
2698827002 .Type,
2698927003 .ComptimeFloat,
2699027004 .ComptimeInt,
......@@ -27003,58 +27017,58 @@ fn validateExternType(
2700327017 .AnyFrame,
2700427018 => return true,
2700527019 .Pointer => {
27006 if (ty.childType(mod).zigTypeTag(mod) == .Fn) {
27007 return ty.isConstPtr(mod) and try sema.validateExternType(ty.childType(mod), .other);
27020 if (ty.childType(zcu).zigTypeTag(zcu) == .Fn) {
27021 return ty.isConstPtr(zcu) and try sema.validateExternType(ty.childType(zcu), .other);
2700827022 }
27009 return !(ty.isSlice(mod) or try sema.typeRequiresComptime(ty));
27023 return !(ty.isSlice(zcu) or try ty.comptimeOnlySema(pt));
2701027024 },
27011 .Int => switch (ty.intInfo(mod).bits) {
27025 .Int => switch (ty.intInfo(zcu).bits) {
2701227026 0, 8, 16, 32, 64, 128 => return true,
2701327027 else => return false,
2701427028 },
2701527029 .Fn => {
2701627030 if (position != .other) return false;
27017 const target = mod.getTarget();
27031 const target = zcu.getTarget();
2701827032 // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI.
2701927033 // The goal is to experiment with more integrated CPU/GPU code.
27020 if (ty.fnCallingConvention(mod) == .Kernel and (target.cpu.arch == .nvptx or target.cpu.arch == .nvptx64)) {
27034 if (ty.fnCallingConvention(zcu) == .Kernel and (target.cpu.arch == .nvptx or target.cpu.arch == .nvptx64)) {
2702127035 return true;
2702227036 }
27023 return !target_util.fnCallConvAllowsZigTypes(target, ty.fnCallingConvention(mod));
27037 return !target_util.fnCallConvAllowsZigTypes(target, ty.fnCallingConvention(zcu));
2702427038 },
2702527039 .Enum => {
27026 return sema.validateExternType(ty.intTagType(mod), position);
27040 return sema.validateExternType(ty.intTagType(zcu), position);
2702727041 },
27028 .Struct, .Union => switch (ty.containerLayout(mod)) {
27042 .Struct, .Union => switch (ty.containerLayout(zcu)) {
2702927043 .@"extern" => return true,
2703027044 .@"packed" => {
27031 const bit_size = try ty.bitSizeAdvanced(pt, .sema);
27045 const bit_size = try ty.bitSizeSema(pt);
2703227046 switch (bit_size) {
2703327047 0, 8, 16, 32, 64, 128 => return true,
2703427048 else => return false,
2703527049 }
2703627050 },
27037 .auto => return !(try sema.typeHasRuntimeBits(ty)),
27051 .auto => return !(try ty.hasRuntimeBitsSema(pt)),
2703827052 },
2703927053 .Array => {
2704027054 if (position == .ret_ty or position == .param_ty) return false;
27041 return sema.validateExternType(ty.elemType2(mod), .element);
27055 return sema.validateExternType(ty.elemType2(zcu), .element);
2704227056 },
27043 .Vector => return sema.validateExternType(ty.elemType2(mod), .element),
27044 .Optional => return ty.isPtrLikeOptional(mod),
27057 .Vector => return sema.validateExternType(ty.elemType2(zcu), .element),
27058 .Optional => return ty.isPtrLikeOptional(zcu),
2704527059 }
2704627060}
2704727061
2704827062fn explainWhyTypeIsNotExtern(
2704927063 sema: *Sema,
27050 msg: *Module.ErrorMsg,
27064 msg: *Zcu.ErrorMsg,
2705127065 src_loc: LazySrcLoc,
2705227066 ty: Type,
2705327067 position: ExternPosition,
2705427068) CompileError!void {
2705527069 const pt = sema.pt;
27056 const mod = pt.zcu;
27057 switch (ty.zigTypeTag(mod)) {
27070 const zcu = pt.zcu;
27071 switch (ty.zigTypeTag(zcu)) {
2705827072 .Opaque,
2705927073 .Bool,
2706027074 .Float,
......@@ -27073,13 +27087,13 @@ fn explainWhyTypeIsNotExtern(
2707327087 => return,
2707427088
2707527089 .Pointer => {
27076 if (ty.isSlice(mod)) {
27090 if (ty.isSlice(zcu)) {
2707727091 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2707827092 } else {
27079 const pointee_ty = ty.childType(mod);
27080 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {
27093 const pointee_ty = ty.childType(zcu);
27094 if (!ty.isConstPtr(zcu) and pointee_ty.zigTypeTag(zcu) == .Fn) {
2708127095 try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{});
27082 } else if (try sema.typeRequiresComptime(ty)) {
27096 } else if (try ty.comptimeOnlySema(pt)) {
2708327097 try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(pt)});
2708427098 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
2708527099 }
......@@ -27088,7 +27102,7 @@ fn explainWhyTypeIsNotExtern(
2708827102 },
2708927103 .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
2709027104 .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
27091 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) {
27105 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(zcu).bits)) {
2709227106 try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
2709327107 } else {
2709427108 try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});
......@@ -27099,7 +27113,7 @@ fn explainWhyTypeIsNotExtern(
2709927113 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
2710027114 return;
2710127115 }
27102 switch (ty.fnCallingConvention(mod)) {
27116 switch (ty.fnCallingConvention(zcu)) {
2710327117 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
2710427118 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
2710527119 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
......@@ -27107,7 +27121,7 @@ fn explainWhyTypeIsNotExtern(
2710727121 }
2710827122 },
2710927123 .Enum => {
27110 const tag_ty = ty.intTagType(mod);
27124 const tag_ty = ty.intTagType(zcu);
2711127125 try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(pt)});
2711227126 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
2711327127 },
......@@ -27119,9 +27133,9 @@ fn explainWhyTypeIsNotExtern(
2711927133 } else if (position == .param_ty) {
2712027134 return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{});
2712127135 }
27122 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);
27136 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(zcu), .element);
2712327137 },
27124 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),
27138 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(zcu), .element),
2712527139 .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
2712627140 }
2712727141}
......@@ -27158,20 +27172,20 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {
2715827172 .auto => false,
2715927173 .explicit, .nonexhaustive => true,
2716027174 },
27161 .Pointer => !ty.isSlice(zcu) and !try sema.typeRequiresComptime(ty),
27175 .Pointer => !ty.isSlice(zcu) and !try ty.comptimeOnlySema(pt),
2716227176 .Struct, .Union => ty.containerLayout(zcu) == .@"packed",
2716327177 };
2716427178}
2716527179
2716627180fn explainWhyTypeIsNotPacked(
2716727181 sema: *Sema,
27168 msg: *Module.ErrorMsg,
27182 msg: *Zcu.ErrorMsg,
2716927183 src_loc: LazySrcLoc,
2717027184 ty: Type,
2717127185) CompileError!void {
2717227186 const pt = sema.pt;
27173 const mod = pt.zcu;
27174 switch (ty.zigTypeTag(mod)) {
27187 const zcu = pt.zcu;
27188 switch (ty.zigTypeTag(zcu)) {
2717527189 .Void,
2717627190 .Bool,
2717727191 .Float,
......@@ -27194,7 +27208,7 @@ fn explainWhyTypeIsNotPacked(
2719427208 .Optional,
2719527209 .Array,
2719627210 => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
27197 .Pointer => if (ty.isSlice(mod)) {
27211 .Pointer => if (ty.isSlice(zcu)) {
2719827212 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2719927213 } else {
2720027214 try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
......@@ -27211,23 +27225,23 @@ fn explainWhyTypeIsNotPacked(
2721127225
2721227226fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2721327227 const pt = sema.pt;
27214 const mod = pt.zcu;
27228 const zcu = pt.zcu;
2721527229
27216 if (mod.panic_func_index == .none) {
27230 if (zcu.panic_func_index == .none) {
2721727231 const fn_ref = try sema.analyzeNavVal(block, src, try pt.getBuiltinNav("panic"));
2721827232 const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{
2721927233 .needed_comptime_reason = "panic handler must be comptime-known",
2722027234 });
27221 assert(fn_val.typeOf(mod).zigTypeTag(mod) == .Fn);
27222 assert(try sema.fnHasRuntimeBits(fn_val.typeOf(mod)));
27223 try mod.ensureFuncBodyAnalysisQueued(fn_val.toIntern());
27224 mod.panic_func_index = fn_val.toIntern();
27235 assert(fn_val.typeOf(zcu).zigTypeTag(zcu) == .Fn);
27236 assert(try fn_val.typeOf(zcu).fnHasRuntimeBitsSema(pt));
27237 try zcu.ensureFuncBodyAnalysisQueued(fn_val.toIntern());
27238 zcu.panic_func_index = fn_val.toIntern();
2722527239 }
2722627240
27227 if (mod.null_stack_trace == .none) {
27241 if (zcu.null_stack_trace == .none) {
2722827242 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
2722927243 try stack_trace_ty.resolveFields(pt);
27230 const target = mod.getTarget();
27244 const target = zcu.getTarget();
2723127245 const ptr_stack_trace_ty = try pt.ptrTypeSema(.{
2723227246 .child = stack_trace_ty.toIntern(),
2723327247 .flags = .{
......@@ -27235,7 +27249,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2723527249 },
2723627250 });
2723727251 const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern());
27238 mod.null_stack_trace = try pt.intern(.{ .opt = .{
27252 zcu.null_stack_trace = try pt.intern(.{ .opt = .{
2723927253 .ty = opt_ptr_stack_trace_ty.toIntern(),
2724027254 .val = .none,
2724127255 } });
......@@ -27245,11 +27259,11 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2724527259/// Backends depend on panic decls being available when lowering safety-checked
2724627260/// instructions. This function ensures the panic function will be available to
2724727261/// be called during that time.
27248fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module.PanicId) !InternPool.Nav.Index {
27262fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) !InternPool.Nav.Index {
2724927263 const pt = sema.pt;
27250 const mod = pt.zcu;
27264 const zcu = pt.zcu;
2725127265 const gpa = sema.gpa;
27252 if (mod.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x;
27266 if (zcu.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x;
2725327267
2725427268 try sema.prepareSimplePanic(block, src);
2725527269
......@@ -27257,15 +27271,15 @@ fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module.
2725727271 const msg_nav_index = (sema.namespaceLookup(
2725827272 block,
2725927273 LazySrcLoc.unneeded,
27260 panic_messages_ty.getNamespaceIndex(mod),
27261 try mod.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls),
27274 panic_messages_ty.getNamespaceIndex(zcu),
27275 try zcu.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls),
2726227276 ) catch |err| switch (err) {
2726327277 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),
2726427278 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
2726527279 error.OutOfMemory => |e| return e,
2726627280 }).?;
2726727281 try sema.ensureNavResolved(src, msg_nav_index);
27268 mod.panic_messages[@intFromEnum(panic_id)] = msg_nav_index.toOptional();
27282 zcu.panic_messages[@intFromEnum(panic_id)] = msg_nav_index.toOptional();
2726927283 return msg_nav_index;
2727027284}
2727127285
......@@ -27274,7 +27288,7 @@ fn addSafetyCheck(
2727427288 parent_block: *Block,
2727527289 src: LazySrcLoc,
2727627290 ok: Air.Inst.Ref,
27277 panic_id: Module.PanicId,
27291 panic_id: Zcu.PanicId,
2727827292) !void {
2727927293 const gpa = sema.gpa;
2728027294 assert(!parent_block.is_comptime);
......@@ -27353,18 +27367,18 @@ fn addSafetyCheckExtra(
2735327367
2735427368fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst.Ref, operation: CallOperation) !void {
2735527369 const pt = sema.pt;
27356 const mod = pt.zcu;
27370 const zcu = pt.zcu;
2735727371
27358 if (!mod.backendSupportsFeature(.panic_fn)) {
27372 if (!zcu.backendSupportsFeature(.panic_fn)) {
2735927373 _ = try block.addNoOp(.trap);
2736027374 return;
2736127375 }
2736227376
2736327377 try sema.prepareSimplePanic(block, src);
2736427378
27365 const panic_func = mod.funcInfo(mod.panic_func_index);
27379 const panic_func = zcu.funcInfo(zcu.panic_func_index);
2736627380 const panic_fn = try sema.analyzeNavVal(block, src, panic_func.owner_nav);
27367 const null_stack_trace = Air.internedToRef(mod.null_stack_trace);
27381 const null_stack_trace = Air.internedToRef(zcu.null_stack_trace);
2736827382
2736927383 const opt_usize_ty = try pt.optionalType(.usize_type);
2737027384 const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{
......@@ -27459,12 +27473,12 @@ fn panicSentinelMismatch(
2745927473) !void {
2746027474 assert(!parent_block.is_comptime);
2746127475 const pt = sema.pt;
27462 const mod = pt.zcu;
27476 const zcu = pt.zcu;
2746327477 const expected_sentinel_val = maybe_sentinel orelse return;
2746427478 const expected_sentinel = Air.internedToRef(expected_sentinel_val.toIntern());
2746527479
2746627480 const ptr_ty = sema.typeOf(ptr);
27467 const actual_sentinel = if (ptr_ty.isSlice(mod))
27481 const actual_sentinel = if (ptr_ty.isSlice(zcu))
2746827482 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)
2746927483 else blk: {
2747027484 const elem_ptr_ty = try ptr_ty.elemPtrType(null, pt);
......@@ -27472,7 +27486,7 @@ fn panicSentinelMismatch(
2747227486 break :blk try parent_block.addTyOp(.load, sentinel_ty, sentinel_ptr);
2747327487 };
2747427488
27475 const ok = if (sentinel_ty.zigTypeTag(mod) == .Vector) ok: {
27489 const ok = if (sentinel_ty.zigTypeTag(zcu) == .Vector) ok: {
2747627490 const eql =
2747727491 try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq);
2747827492 break :ok try parent_block.addInst(.{
......@@ -27482,7 +27496,7 @@ fn panicSentinelMismatch(
2748227496 .operation = .And,
2748327497 } },
2748427498 });
27485 } else if (sentinel_ty.isSelfComparable(mod, true))
27499 } else if (sentinel_ty.isSelfComparable(zcu, true))
2748627500 try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel)
2748727501 else {
2748827502 const panic_fn = try pt.getBuiltin("checkNonScalarSentinel");
......@@ -27532,7 +27546,7 @@ fn safetyCheckFormatted(
2753227546 try sema.addSafetyCheckExtra(parent_block, ok, &fail_block);
2753327547}
2753427548
27535fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module.PanicId) CompileError!void {
27549fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) CompileError!void {
2753627550 const msg_nav_index = try sema.preparePanicId(block, src, panic_id);
2753727551 const msg_inst = try sema.analyzeNavVal(block, src, msg_nav_index);
2753827552 try sema.panicWithMsg(block, src, msg_inst, .@"safety check");
......@@ -27568,30 +27582,30 @@ fn fieldVal(
2756827582 // in `fieldPtr`. This function takes a value and returns a value.
2756927583
2757027584 const pt = sema.pt;
27571 const mod = pt.zcu;
27572 const ip = &mod.intern_pool;
27585 const zcu = pt.zcu;
27586 const ip = &zcu.intern_pool;
2757327587 const object_src = src; // TODO better source location
2757427588 const object_ty = sema.typeOf(object);
2757527589
2757627590 // Zig allows dereferencing a single pointer during field lookup. Note that
2757727591 // we don't actually need to generate the dereference some field lookups, like the
2757827592 // length of arrays and other comptime operations.
27579 const is_pointer_to = object_ty.isSinglePointer(mod);
27593 const is_pointer_to = object_ty.isSinglePointer(zcu);
2758027594
2758127595 const inner_ty = if (is_pointer_to)
27582 object_ty.childType(mod)
27596 object_ty.childType(zcu)
2758327597 else
2758427598 object_ty;
2758527599
27586 switch (inner_ty.zigTypeTag(mod)) {
27600 switch (inner_ty.zigTypeTag(zcu)) {
2758727601 .Array => {
2758827602 if (field_name.eqlSlice("len", ip)) {
27589 return Air.internedToRef((try pt.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern());
27603 return Air.internedToRef((try pt.intValue(Type.usize, inner_ty.arrayLen(zcu))).toIntern());
2759027604 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27591 const ptr_info = object_ty.ptrInfo(mod);
27605 const ptr_info = object_ty.ptrInfo(zcu);
2759227606 const result_ty = try pt.ptrTypeSema(.{
27593 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),
27594 .sentinel = if (inner_ty.sentinel(mod)) |s| s.toIntern() else .none,
27607 .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(),
27608 .sentinel = if (inner_ty.sentinel(zcu)) |s| s.toIntern() else .none,
2759527609 .flags = .{
2759627610 .size = .Many,
2759727611 .alignment = ptr_info.flags.alignment,
......@@ -27614,7 +27628,7 @@ fn fieldVal(
2761427628 }
2761527629 },
2761627630 .Pointer => {
27617 const ptr_info = inner_ty.ptrInfo(mod);
27631 const ptr_info = inner_ty.ptrInfo(zcu);
2761827632 if (ptr_info.flags.size == .Slice) {
2761927633 if (field_name.eqlSlice("ptr", ip)) {
2762027634 const slice = if (is_pointer_to)
......@@ -27647,7 +27661,7 @@ fn fieldVal(
2764727661 const val = (try sema.resolveDefinedValue(block, object_src, dereffed_type)).?;
2764827662 const child_type = val.toType();
2764927663
27650 switch (try child_type.zigTypeTagOrPoison(mod)) {
27664 switch (try child_type.zigTypeTagOrPoison(zcu)) {
2765127665 .ErrorSet => {
2765227666 switch (ip.indexToKey(child_type.toIntern())) {
2765327667 .error_set_type => |error_set_type| blk: {
......@@ -27666,7 +27680,7 @@ fn fieldVal(
2766627680 else => unreachable,
2766727681 }
2766827682
27669 const error_set_type = if (!child_type.isAnyError(mod))
27683 const error_set_type = if (!child_type.isAnyError(zcu))
2767027684 child_type
2767127685 else
2767227686 try pt.singleErrorSetType(field_name);
......@@ -27676,12 +27690,12 @@ fn fieldVal(
2767627690 } })));
2767727691 },
2767827692 .Union => {
27679 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27693 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2768027694 return inst;
2768127695 }
2768227696 try child_type.resolveFields(pt);
27683 if (child_type.unionTagType(mod)) |enum_ty| {
27684 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| {
27697 if (child_type.unionTagType(zcu)) |enum_ty| {
27698 if (enum_ty.enumFieldIndex(field_name, zcu)) |field_index_usize| {
2768527699 const field_index: u32 = @intCast(field_index_usize);
2768627700 return Air.internedToRef((try pt.enumValueFieldIndex(enum_ty, field_index)).toIntern());
2768727701 }
......@@ -27689,10 +27703,10 @@ fn fieldVal(
2768927703 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2769027704 },
2769127705 .Enum => {
27692 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27706 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2769327707 return inst;
2769427708 }
27695 const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse
27709 const field_index_usize = child_type.enumFieldIndex(field_name, zcu) orelse
2769627710 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2769727711 const field_index: u32 = @intCast(field_index_usize);
2769827712 const enum_val = try pt.enumValueFieldIndex(child_type, field_index);
......@@ -27701,7 +27715,7 @@ fn fieldVal(
2770127715 .Struct, .Opaque => {
2770227716 switch (child_type.toIntern()) {
2770327717 .empty_struct_type, .anyopaque_type => {}, // no namespace
27704 else => if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27718 else => if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2770527719 return inst;
2770627720 },
2770727721 }
......@@ -27710,8 +27724,8 @@ fn fieldVal(
2771027724 else => return sema.failWithOwnedErrorMsg(block, msg: {
2771127725 const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(pt)});
2771227726 errdefer msg.destroy(sema.gpa);
27713 if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
27714 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
27727 if (child_type.isSlice(zcu)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
27728 if (child_type.zigTypeTag(zcu) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
2771527729 break :msg msg;
2771627730 }),
2771727731 }
......@@ -27748,35 +27762,35 @@ fn fieldPtr(
2774827762 // in `fieldVal`. This function takes a pointer and returns a pointer.
2774927763
2775027764 const pt = sema.pt;
27751 const mod = pt.zcu;
27752 const ip = &mod.intern_pool;
27765 const zcu = pt.zcu;
27766 const ip = &zcu.intern_pool;
2775327767 const object_ptr_src = src; // TODO better source location
2775427768 const object_ptr_ty = sema.typeOf(object_ptr);
27755 const object_ty = switch (object_ptr_ty.zigTypeTag(mod)) {
27756 .Pointer => object_ptr_ty.childType(mod),
27769 const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) {
27770 .Pointer => object_ptr_ty.childType(zcu),
2775727771 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(pt)}),
2775827772 };
2775927773
2776027774 // Zig allows dereferencing a single pointer during field lookup. Note that
2776127775 // we don't actually need to generate the dereference some field lookups, like the
2776227776 // length of arrays and other comptime operations.
27763 const is_pointer_to = object_ty.isSinglePointer(mod);
27777 const is_pointer_to = object_ty.isSinglePointer(zcu);
2776427778
2776527779 const inner_ty = if (is_pointer_to)
27766 object_ty.childType(mod)
27780 object_ty.childType(zcu)
2776727781 else
2776827782 object_ty;
2776927783
27770 switch (inner_ty.zigTypeTag(mod)) {
27784 switch (inner_ty.zigTypeTag(zcu)) {
2777127785 .Array => {
2777227786 if (field_name.eqlSlice("len", ip)) {
27773 const int_val = try pt.intValue(Type.usize, inner_ty.arrayLen(mod));
27787 const int_val = try pt.intValue(Type.usize, inner_ty.arrayLen(zcu));
2777427788 return uavRef(sema, int_val.toIntern());
2777527789 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27776 const ptr_info = object_ty.ptrInfo(mod);
27790 const ptr_info = object_ty.ptrInfo(zcu);
2777727791 const new_ptr_ty = try pt.ptrTypeSema(.{
27778 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),
27779 .sentinel = if (object_ty.sentinel(mod)) |s| s.toIntern() else .none,
27792 .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(),
27793 .sentinel = if (object_ty.sentinel(zcu)) |s| s.toIntern() else .none,
2778027794 .flags = .{
2778127795 .size = .Many,
2778227796 .alignment = ptr_info.flags.alignment,
......@@ -27788,10 +27802,10 @@ fn fieldPtr(
2778827802 },
2778927803 .packed_offset = ptr_info.packed_offset,
2779027804 });
27791 const ptr_ptr_info = object_ptr_ty.ptrInfo(mod);
27805 const ptr_ptr_info = object_ptr_ty.ptrInfo(zcu);
2779227806 const result_ty = try pt.ptrTypeSema(.{
2779327807 .child = new_ptr_ty.toIntern(),
27794 .sentinel = if (object_ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
27808 .sentinel = if (object_ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
2779527809 .flags = .{
2779627810 .alignment = ptr_ptr_info.flags.alignment,
2779727811 .is_const = ptr_ptr_info.flags.is_const,
......@@ -27812,7 +27826,7 @@ fn fieldPtr(
2781227826 );
2781327827 }
2781427828 },
27815 .Pointer => if (inner_ty.isSlice(mod)) {
27829 .Pointer => if (inner_ty.isSlice(zcu)) {
2781627830 const inner_ptr = if (is_pointer_to)
2781727831 try sema.analyzeLoad(block, src, object_ptr, object_ptr_src)
2781827832 else
......@@ -27821,14 +27835,14 @@ fn fieldPtr(
2782127835 const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty;
2782227836
2782327837 if (field_name.eqlSlice("ptr", ip)) {
27824 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);
27838 const slice_ptr_ty = inner_ty.slicePtrFieldType(zcu);
2782527839
2782627840 const result_ty = try pt.ptrTypeSema(.{
2782727841 .child = slice_ptr_ty.toIntern(),
2782827842 .flags = .{
27829 .is_const = !attr_ptr_ty.ptrIsMutable(mod),
27830 .is_volatile = attr_ptr_ty.isVolatilePtr(mod),
27831 .address_space = attr_ptr_ty.ptrAddressSpace(mod),
27843 .is_const = !attr_ptr_ty.ptrIsMutable(zcu),
27844 .is_volatile = attr_ptr_ty.isVolatilePtr(zcu),
27845 .address_space = attr_ptr_ty.ptrAddressSpace(zcu),
2783227846 },
2783327847 });
2783427848
......@@ -27844,9 +27858,9 @@ fn fieldPtr(
2784427858 const result_ty = try pt.ptrTypeSema(.{
2784527859 .child = .usize_type,
2784627860 .flags = .{
27847 .is_const = !attr_ptr_ty.ptrIsMutable(mod),
27848 .is_volatile = attr_ptr_ty.isVolatilePtr(mod),
27849 .address_space = attr_ptr_ty.ptrAddressSpace(mod),
27861 .is_const = !attr_ptr_ty.ptrIsMutable(zcu),
27862 .is_volatile = attr_ptr_ty.isVolatilePtr(zcu),
27863 .address_space = attr_ptr_ty.ptrAddressSpace(zcu),
2785027864 },
2785127865 });
2785227866
......@@ -27878,7 +27892,7 @@ fn fieldPtr(
2787827892 const val = (sema.resolveDefinedValue(block, src, inner) catch unreachable).?;
2787927893 const child_type = val.toType();
2788027894
27881 switch (child_type.zigTypeTag(mod)) {
27895 switch (child_type.zigTypeTag(zcu)) {
2788227896 .ErrorSet => {
2788327897 switch (ip.indexToKey(child_type.toIntern())) {
2788427898 .error_set_type => |error_set_type| blk: {
......@@ -27899,7 +27913,7 @@ fn fieldPtr(
2789927913 else => unreachable,
2790027914 }
2790127915
27902 const error_set_type = if (!child_type.isAnyError(mod))
27916 const error_set_type = if (!child_type.isAnyError(zcu))
2790327917 child_type
2790427918 else
2790527919 try pt.singleErrorSetType(field_name);
......@@ -27909,12 +27923,12 @@ fn fieldPtr(
2790927923 } }));
2791027924 },
2791127925 .Union => {
27912 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27926 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2791327927 return inst;
2791427928 }
2791527929 try child_type.resolveFields(pt);
27916 if (child_type.unionTagType(mod)) |enum_ty| {
27917 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| {
27930 if (child_type.unionTagType(zcu)) |enum_ty| {
27931 if (enum_ty.enumFieldIndex(field_name, zcu)) |field_index| {
2791827932 const field_index_u32: u32 = @intCast(field_index);
2791927933 const idx_val = try pt.enumValueFieldIndex(enum_ty, field_index_u32);
2792027934 return uavRef(sema, idx_val.toIntern());
......@@ -27923,10 +27937,10 @@ fn fieldPtr(
2792327937 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2792427938 },
2792527939 .Enum => {
27926 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27940 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2792727941 return inst;
2792827942 }
27929 const field_index = child_type.enumFieldIndex(field_name, mod) orelse {
27943 const field_index = child_type.enumFieldIndex(field_name, zcu) orelse {
2793027944 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2793127945 };
2793227946 const field_index_u32: u32 = @intCast(field_index);
......@@ -27934,7 +27948,7 @@ fn fieldPtr(
2793427948 return uavRef(sema, idx_val.toIntern());
2793527949 },
2793627950 .Struct, .Opaque => {
27937 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27951 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2793827952 return inst;
2793927953 }
2794027954 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
......@@ -28149,18 +28163,18 @@ fn finishFieldCallBind(
2814928163 object_ptr: Air.Inst.Ref,
2815028164) CompileError!ResolvedFieldCallee {
2815128165 const pt = sema.pt;
28152 const mod = pt.zcu;
28166 const zcu = pt.zcu;
2815328167 const ptr_field_ty = try pt.ptrTypeSema(.{
2815428168 .child = field_ty.toIntern(),
2815528169 .flags = .{
28156 .is_const = !ptr_ty.ptrIsMutable(mod),
28157 .address_space = ptr_ty.ptrAddressSpace(mod),
28170 .is_const = !ptr_ty.ptrIsMutable(zcu),
28171 .address_space = ptr_ty.ptrAddressSpace(zcu),
2815828172 },
2815928173 });
2816028174
28161 const container_ty = ptr_ty.childType(mod);
28162 if (container_ty.zigTypeTag(mod) == .Struct) {
28163 if (container_ty.structFieldIsComptime(field_index, mod)) {
28175 const container_ty = ptr_ty.childType(zcu);
28176 if (container_ty.zigTypeTag(zcu) == .Struct) {
28177 if (container_ty.structFieldIsComptime(field_index, zcu)) {
2816428178 try container_ty.resolveStructFieldInits(pt);
2816528179 const default_val = (try container_ty.structFieldValueComptime(pt, field_index)).?;
2816628180 return .{ .direct = Air.internedToRef(default_val.toIntern()) };
......@@ -28237,26 +28251,26 @@ fn structFieldPtr(
2823728251 initializing: bool,
2823828252) CompileError!Air.Inst.Ref {
2823928253 const pt = sema.pt;
28240 const mod = pt.zcu;
28241 const ip = &mod.intern_pool;
28242 assert(struct_ty.zigTypeTag(mod) == .Struct);
28254 const zcu = pt.zcu;
28255 const ip = &zcu.intern_pool;
28256 assert(struct_ty.zigTypeTag(zcu) == .Struct);
2824328257
2824428258 try struct_ty.resolveFields(pt);
2824528259 try struct_ty.resolveLayout(pt);
2824628260
28247 if (struct_ty.isTuple(mod)) {
28261 if (struct_ty.isTuple(zcu)) {
2824828262 if (field_name.eqlSlice("len", ip)) {
28249 const len_inst = try pt.intRef(Type.usize, struct_ty.structFieldCount(mod));
28263 const len_inst = try pt.intRef(Type.usize, struct_ty.structFieldCount(zcu));
2825028264 return sema.analyzeRef(block, src, len_inst);
2825128265 }
2825228266 const field_index = try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);
2825328267 return sema.tupleFieldPtr(block, src, struct_ptr, field_name_src, field_index, initializing);
28254 } else if (struct_ty.isAnonStruct(mod)) {
28268 } else if (struct_ty.isAnonStruct(zcu)) {
2825528269 const field_index = try sema.anonStructFieldIndex(block, struct_ty, field_name, field_name_src);
2825628270 return sema.tupleFieldPtr(block, src, struct_ptr, field_name_src, field_index, initializing);
2825728271 }
2825828272
28259 const struct_type = mod.typeToStruct(struct_ty).?;
28273 const struct_type = zcu.typeToStruct(struct_ty).?;
2826028274
2826128275 const field_index = struct_type.nameIndex(ip, field_name) orelse
2826228276 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
......@@ -28275,9 +28289,9 @@ fn structFieldPtrByIndex(
2827528289 initializing: bool,
2827628290) CompileError!Air.Inst.Ref {
2827728291 const pt = sema.pt;
28278 const mod = pt.zcu;
28279 const ip = &mod.intern_pool;
28280 if (struct_ty.isAnonStruct(mod)) {
28292 const zcu = pt.zcu;
28293 const ip = &zcu.intern_pool;
28294 if (struct_ty.isAnonStruct(zcu)) {
2828128295 return sema.tupleFieldPtr(block, src, struct_ptr, field_src, field_index, initializing);
2828228296 }
2828328297
......@@ -28286,10 +28300,10 @@ fn structFieldPtrByIndex(
2828628300 return Air.internedToRef(val.toIntern());
2828728301 }
2828828302
28289 const struct_type = mod.typeToStruct(struct_ty).?;
28303 const struct_type = zcu.typeToStruct(struct_ty).?;
2829028304 const field_ty = struct_type.field_types.get(ip)[field_index];
2829128305 const struct_ptr_ty = sema.typeOf(struct_ptr);
28292 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(mod);
28306 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu);
2829328307
2829428308 var ptr_ty_data: InternPool.Key.PtrType = .{
2829528309 .child = field_ty,
......@@ -28303,7 +28317,7 @@ fn structFieldPtrByIndex(
2830328317 const parent_align = if (struct_ptr_ty_info.flags.alignment != .none)
2830428318 struct_ptr_ty_info.flags.alignment
2830528319 else
28306 try sema.typeAbiAlignment(Type.fromInterned(struct_ptr_ty_info.child));
28320 try Type.fromInterned(struct_ptr_ty_info.child).abiAlignmentSema(pt);
2830728321
2830828322 if (struct_type.layout == .@"packed") {
2830928323 switch (struct_ty.packedStructFieldPtrInfo(struct_ptr_ty, field_index, pt)) {
......@@ -28319,18 +28333,19 @@ fn structFieldPtrByIndex(
2831928333 // For extern structs, field alignment might be bigger than type's
2832028334 // natural alignment. Eg, in `extern struct { x: u32, y: u16 }` the
2832128335 // second field is aligned as u32.
28322 const field_offset = struct_ty.structFieldOffset(field_index, pt);
28336 const field_offset = struct_ty.structFieldOffset(field_index, zcu);
2832328337 ptr_ty_data.flags.alignment = if (parent_align == .none)
2832428338 .none
2832528339 else
2832628340 @enumFromInt(@min(@intFromEnum(parent_align), @ctz(field_offset)));
2832728341 } else {
2832828342 // Our alignment is capped at the field alignment.
28329 const field_align = try pt.structFieldAlignmentAdvanced(
28343 const field_align = try Type.fromInterned(field_ty).structFieldAlignmentAdvanced(
2833028344 struct_type.fieldAlign(ip, field_index),
28331 Type.fromInterned(field_ty),
2833228345 struct_type.layout,
2833328346 .sema,
28347 pt.zcu,
28348 pt.tid,
2833428349 );
2833528350 ptr_ty_data.flags.alignment = if (struct_ptr_ty_info.flags.alignment == .none)
2833628351 field_align
......@@ -28364,9 +28379,9 @@ fn structFieldVal(
2836428379 struct_ty: Type,
2836528380) CompileError!Air.Inst.Ref {
2836628381 const pt = sema.pt;
28367 const mod = pt.zcu;
28368 const ip = &mod.intern_pool;
28369 assert(struct_ty.zigTypeTag(mod) == .Struct);
28382 const zcu = pt.zcu;
28383 const ip = &zcu.intern_pool;
28384 assert(struct_ty.zigTypeTag(zcu) == .Struct);
2837028385
2837128386 try struct_ty.resolveFields(pt);
2837228387
......@@ -28388,7 +28403,7 @@ fn structFieldVal(
2838828403 return Air.internedToRef(field_val.toIntern());
2838928404
2839028405 if (try sema.resolveValue(struct_byval)) |struct_val| {
28391 if (struct_val.isUndef(mod)) return pt.undefRef(field_ty);
28406 if (struct_val.isUndef(zcu)) return pt.undefRef(field_ty);
2839228407 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2839328408 return Air.internedToRef(opv.toIntern());
2839428409 }
......@@ -28421,9 +28436,9 @@ fn tupleFieldVal(
2842128436 tuple_ty: Type,
2842228437) CompileError!Air.Inst.Ref {
2842328438 const pt = sema.pt;
28424 const mod = pt.zcu;
28425 if (field_name.eqlSlice("len", &mod.intern_pool)) {
28426 return pt.intRef(Type.usize, tuple_ty.structFieldCount(mod));
28439 const zcu = pt.zcu;
28440 if (field_name.eqlSlice("len", &zcu.intern_pool)) {
28441 return pt.intRef(Type.usize, tuple_ty.structFieldCount(zcu));
2842728442 }
2842828443 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
2842928444 return sema.tupleFieldValByIndex(block, src, tuple_byval, field_index, tuple_ty);
......@@ -28461,10 +28476,10 @@ fn tupleFieldValByIndex(
2846128476 tuple_ty: Type,
2846228477) CompileError!Air.Inst.Ref {
2846328478 const pt = sema.pt;
28464 const mod = pt.zcu;
28465 const field_ty = tuple_ty.structFieldType(field_index, mod);
28479 const zcu = pt.zcu;
28480 const field_ty = tuple_ty.structFieldType(field_index, zcu);
2846628481
28467 if (tuple_ty.structFieldIsComptime(field_index, mod))
28482 if (tuple_ty.structFieldIsComptime(field_index, zcu))
2846828483 try tuple_ty.resolveStructFieldInits(pt);
2846928484 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {
2847028485 return Air.internedToRef(default_value.toIntern());
......@@ -28474,10 +28489,10 @@ fn tupleFieldValByIndex(
2847428489 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2847528490 return Air.internedToRef(opv.toIntern());
2847628491 }
28477 return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) {
28492 return switch (zcu.intern_pool.indexToKey(tuple_val.toIntern())) {
2847828493 .undef => pt.undefRef(field_ty),
2847928494 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {
28480 .bytes => |bytes| try pt.intValue(Type.u8, bytes.at(field_index, &mod.intern_pool)),
28495 .bytes => |bytes| try pt.intValue(Type.u8, bytes.at(field_index, &zcu.intern_pool)),
2848128496 .elems => |elems| Value.fromInterned(elems[field_index]),
2848228497 .repeated_elem => |elem| Value.fromInterned(elem),
2848328498 }.toIntern()),
......@@ -28501,15 +28516,15 @@ fn unionFieldPtr(
2850128516 initializing: bool,
2850228517) CompileError!Air.Inst.Ref {
2850328518 const pt = sema.pt;
28504 const mod = pt.zcu;
28505 const ip = &mod.intern_pool;
28519 const zcu = pt.zcu;
28520 const ip = &zcu.intern_pool;
2850628521
28507 assert(union_ty.zigTypeTag(mod) == .Union);
28522 assert(union_ty.zigTypeTag(zcu) == .Union);
2850828523
2850928524 const union_ptr_ty = sema.typeOf(union_ptr);
28510 const union_ptr_info = union_ptr_ty.ptrInfo(mod);
28525 const union_ptr_info = union_ptr_ty.ptrInfo(zcu);
2851128526 try union_ty.resolveFields(pt);
28512 const union_obj = mod.typeToUnion(union_ty).?;
28527 const union_obj = zcu.typeToUnion(union_ty).?;
2851328528 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
2851428529 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
2851528530 const ptr_field_ty = try pt.ptrTypeSema(.{
......@@ -28522,16 +28537,22 @@ fn unionFieldPtr(
2852228537 const union_align = if (union_ptr_info.flags.alignment != .none)
2852328538 union_ptr_info.flags.alignment
2852428539 else
28525 try sema.typeAbiAlignment(union_ty);
28526 const field_align = try pt.unionFieldNormalAlignmentAdvanced(union_obj, field_index, .sema);
28540 try union_ty.abiAlignmentSema(pt);
28541 const field_align = try Type.unionFieldNormalAlignmentAdvanced(
28542 union_obj,
28543 field_index,
28544 .sema,
28545 pt.zcu,
28546 pt.tid,
28547 );
2852728548 break :blk union_align.min(field_align);
2852828549 } else union_ptr_info.flags.alignment,
2852928550 },
2853028551 .packed_offset = union_ptr_info.packed_offset,
2853128552 });
28532 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, mod).?);
28553 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, zcu).?);
2853328554
28534 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
28555 if (initializing and field_ty.zigTypeTag(zcu) == .NoReturn) {
2853528556 const msg = msg: {
2853628557 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2853728558 errdefer msg.destroy(sema.gpa);
......@@ -28556,7 +28577,7 @@ fn unionFieldPtr(
2855628577 } else {
2855728578 const union_val = (try sema.pointerDeref(block, src, union_ptr_val, union_ptr_ty)) orelse
2855828579 break :ct;
28559 if (union_val.isUndef(mod)) {
28580 if (union_val.isUndef(zcu)) {
2856028581 return sema.failWithUseOfUndef(block, src);
2856128582 }
2856228583 const un = ip.indexToKey(union_val.toIntern()).un;
......@@ -28564,8 +28585,8 @@ fn unionFieldPtr(
2856428585 const tag_matches = un.tag == field_tag.toIntern();
2856528586 if (!tag_matches) {
2856628587 const msg = msg: {
28567 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
28568 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
28588 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
28589 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);
2856928590 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
2857028591 field_name.fmt(ip),
2857128592 active_field_name.fmt(ip),
......@@ -28585,7 +28606,7 @@ fn unionFieldPtr(
2858528606
2858628607 try sema.requireRuntimeBlock(block, src, null);
2858728608 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
28588 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_types.len > 1)
28609 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
2858928610 {
2859028611 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2859128612 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
......@@ -28594,7 +28615,7 @@ fn unionFieldPtr(
2859428615 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val);
2859528616 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);
2859628617 }
28597 if (field_ty.zigTypeTag(mod) == .NoReturn) {
28618 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
2859828619 _ = try block.addNoOp(.unreach);
2859928620 return .unreachable_value;
2860028621 }
......@@ -28654,7 +28675,7 @@ fn unionFieldVal(
2865428675 .@"packed" => if (tag_matches) {
2865528676 // Fast path - no need to use bitcast logic.
2865628677 return Air.internedToRef(un.val);
28657 } else if (try sema.bitCastVal(union_val, field_ty, 0, try union_ty.bitSizeAdvanced(pt, .sema), 0)) |field_val| {
28678 } else if (try sema.bitCastVal(union_val, field_ty, 0, try union_ty.bitSizeSema(pt), 0)) |field_val| {
2865828679 return Air.internedToRef(field_val.toIntern());
2865928680 },
2866028681 }
......@@ -28688,17 +28709,17 @@ fn elemPtr(
2868828709 oob_safety: bool,
2868928710) CompileError!Air.Inst.Ref {
2869028711 const pt = sema.pt;
28691 const mod = pt.zcu;
28712 const zcu = pt.zcu;
2869228713 const indexable_ptr_src = src; // TODO better source location
2869328714 const indexable_ptr_ty = sema.typeOf(indexable_ptr);
2869428715
28695 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(mod)) {
28696 .Pointer => indexable_ptr_ty.childType(mod),
28716 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) {
28717 .Pointer => indexable_ptr_ty.childType(zcu),
2869728718 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(pt)}),
2869828719 };
2869928720 try checkIndexable(sema, block, src, indexable_ty);
2870028721
28701 const elem_ptr = switch (indexable_ty.zigTypeTag(mod)) {
28722 const elem_ptr = switch (indexable_ty.zigTypeTag(zcu)) {
2870228723 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),
2870328724 .Struct => blk: {
2870428725 // Tuple field access.
......@@ -28732,11 +28753,11 @@ fn elemPtrOneLayerOnly(
2873228753 const indexable_src = src; // TODO better source location
2873328754 const indexable_ty = sema.typeOf(indexable);
2873428755 const pt = sema.pt;
28735 const mod = pt.zcu;
28756 const zcu = pt.zcu;
2873628757
2873728758 try checkIndexable(sema, block, src, indexable_ty);
2873828759
28739 switch (indexable_ty.ptrSize(mod)) {
28760 switch (indexable_ty.ptrSize(zcu)) {
2874028761 .Slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
2874128762 .Many, .C => {
2874228763 const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
......@@ -28754,11 +28775,11 @@ fn elemPtrOneLayerOnly(
2875428775 return block.addPtrElemPtr(indexable, elem_index, result_ty);
2875528776 },
2875628777 .One => {
28757 const child_ty = indexable_ty.childType(mod);
28758 const elem_ptr = switch (child_ty.zigTypeTag(mod)) {
28778 const child_ty = indexable_ty.childType(zcu);
28779 const elem_ptr = switch (child_ty.zigTypeTag(zcu)) {
2875928780 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety),
2876028781 .Struct => blk: {
28761 assert(child_ty.isTuple(mod));
28782 assert(child_ty.isTuple(zcu));
2876228783 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2876328784 .needed_comptime_reason = "tuple field access index must be comptime-known",
2876428785 });
......@@ -28785,7 +28806,7 @@ fn elemVal(
2878528806 const indexable_src = src; // TODO better source location
2878628807 const indexable_ty = sema.typeOf(indexable);
2878728808 const pt = sema.pt;
28788 const mod = pt.zcu;
28809 const zcu = pt.zcu;
2878928810
2879028811 try checkIndexable(sema, block, src, indexable_ty);
2879128812
......@@ -28793,8 +28814,8 @@ fn elemVal(
2879328814 // index is a scalar or vector instead of unconditionally casting to usize.
2879428815 const elem_index = try sema.coerce(block, Type.usize, elem_index_uncasted, elem_index_src);
2879528816
28796 switch (indexable_ty.zigTypeTag(mod)) {
28797 .Pointer => switch (indexable_ty.ptrSize(mod)) {
28817 switch (indexable_ty.zigTypeTag(zcu)) {
28818 .Pointer => switch (indexable_ty.ptrSize(zcu)) {
2879828819 .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
2879928820 .Many, .C => {
2880028821 const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
......@@ -28804,7 +28825,7 @@ fn elemVal(
2880428825 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
2880528826 const index_val = maybe_index_val orelse break :rs elem_index_src;
2880628827 const index: usize = @intCast(try index_val.toUnsignedIntSema(pt));
28807 const elem_ty = indexable_ty.elemType2(mod);
28828 const elem_ty = indexable_ty.elemType2(zcu);
2880828829 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);
2880928830 const many_ptr_val = try pt.getCoerced(indexable_val, many_ptr_ty);
2881028831 const elem_ptr_ty = try pt.singleConstPtrType(elem_ty);
......@@ -28820,12 +28841,12 @@ fn elemVal(
2882028841 },
2882128842 .One => {
2882228843 arr_sent: {
28823 const inner_ty = indexable_ty.childType(mod);
28824 if (inner_ty.zigTypeTag(mod) != .Array) break :arr_sent;
28825 const sentinel = inner_ty.sentinel(mod) orelse break :arr_sent;
28844 const inner_ty = indexable_ty.childType(zcu);
28845 if (inner_ty.zigTypeTag(zcu) != .Array) break :arr_sent;
28846 const sentinel = inner_ty.sentinel(zcu) orelse break :arr_sent;
2882628847 const index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index) orelse break :arr_sent;
2882728848 const index = try sema.usizeCast(block, src, try index_val.toUnsignedIntSema(pt));
28828 if (index != inner_ty.arrayLen(mod)) break :arr_sent;
28849 if (index != inner_ty.arrayLen(zcu)) break :arr_sent;
2882928850 return Air.internedToRef(sentinel.toIntern());
2883028851 }
2883128852 const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety);
......@@ -28857,7 +28878,7 @@ fn validateRuntimeElemAccess(
2885728878 parent_ty: Type,
2885828879 parent_src: LazySrcLoc,
2885928880) CompileError!void {
28860 if (try sema.typeRequiresComptime(elem_ty)) {
28881 if (try elem_ty.comptimeOnlySema(sema.pt)) {
2886128882 const msg = msg: {
2886228883 const msg = try sema.errMsg(
2886328884 elem_index_src,
......@@ -28884,11 +28905,11 @@ fn tupleFieldPtr(
2888428905 init: bool,
2888528906) CompileError!Air.Inst.Ref {
2888628907 const pt = sema.pt;
28887 const mod = pt.zcu;
28908 const zcu = pt.zcu;
2888828909 const tuple_ptr_ty = sema.typeOf(tuple_ptr);
28889 const tuple_ty = tuple_ptr_ty.childType(mod);
28910 const tuple_ty = tuple_ptr_ty.childType(zcu);
2889028911 try tuple_ty.resolveFields(pt);
28891 const field_count = tuple_ty.structFieldCount(mod);
28912 const field_count = tuple_ty.structFieldCount(zcu);
2889228913
2889328914 if (field_count == 0) {
2889428915 return sema.fail(block, tuple_ptr_src, "indexing into empty tuple is not allowed", .{});
......@@ -28900,17 +28921,17 @@ fn tupleFieldPtr(
2890028921 });
2890128922 }
2890228923
28903 const field_ty = tuple_ty.structFieldType(field_index, mod);
28924 const field_ty = tuple_ty.structFieldType(field_index, zcu);
2890428925 const ptr_field_ty = try pt.ptrTypeSema(.{
2890528926 .child = field_ty.toIntern(),
2890628927 .flags = .{
28907 .is_const = !tuple_ptr_ty.ptrIsMutable(mod),
28908 .is_volatile = tuple_ptr_ty.isVolatilePtr(mod),
28909 .address_space = tuple_ptr_ty.ptrAddressSpace(mod),
28928 .is_const = !tuple_ptr_ty.ptrIsMutable(zcu),
28929 .is_volatile = tuple_ptr_ty.isVolatilePtr(zcu),
28930 .address_space = tuple_ptr_ty.ptrAddressSpace(zcu),
2891028931 },
2891128932 });
2891228933
28913 if (tuple_ty.structFieldIsComptime(field_index, mod))
28934 if (tuple_ty.structFieldIsComptime(field_index, zcu))
2891428935 try tuple_ty.resolveStructFieldInits(pt);
2891528936
2891628937 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_val| {
......@@ -28943,10 +28964,10 @@ fn tupleField(
2894328964 field_index: u32,
2894428965) CompileError!Air.Inst.Ref {
2894528966 const pt = sema.pt;
28946 const mod = pt.zcu;
28967 const zcu = pt.zcu;
2894728968 const tuple_ty = sema.typeOf(tuple);
2894828969 try tuple_ty.resolveFields(pt);
28949 const field_count = tuple_ty.structFieldCount(mod);
28970 const field_count = tuple_ty.structFieldCount(zcu);
2895028971
2895128972 if (field_count == 0) {
2895228973 return sema.fail(block, tuple_src, "indexing into empty tuple is not allowed", .{});
......@@ -28958,16 +28979,16 @@ fn tupleField(
2895828979 });
2895928980 }
2896028981
28961 const field_ty = tuple_ty.structFieldType(field_index, mod);
28982 const field_ty = tuple_ty.structFieldType(field_index, zcu);
2896228983
28963 if (tuple_ty.structFieldIsComptime(field_index, mod))
28984 if (tuple_ty.structFieldIsComptime(field_index, zcu))
2896428985 try tuple_ty.resolveStructFieldInits(pt);
2896528986 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {
2896628987 return Air.internedToRef(default_value.toIntern()); // comptime field
2896728988 }
2896828989
2896928990 if (try sema.resolveValue(tuple)) |tuple_val| {
28970 if (tuple_val.isUndef(mod)) return pt.undefRef(field_ty);
28991 if (tuple_val.isUndef(zcu)) return pt.undefRef(field_ty);
2897128992 return Air.internedToRef((try tuple_val.fieldValue(pt, field_index)).toIntern());
2897228993 }
2897328994
......@@ -28989,12 +29010,12 @@ fn elemValArray(
2898929010 oob_safety: bool,
2899029011) CompileError!Air.Inst.Ref {
2899129012 const pt = sema.pt;
28992 const mod = pt.zcu;
29013 const zcu = pt.zcu;
2899329014 const array_ty = sema.typeOf(array);
28994 const array_sent = array_ty.sentinel(mod);
28995 const array_len = array_ty.arrayLen(mod);
29015 const array_sent = array_ty.sentinel(zcu);
29016 const array_len = array_ty.arrayLen(zcu);
2899629017 const array_len_s = array_len + @intFromBool(array_sent != null);
28997 const elem_ty = array_ty.childType(mod);
29018 const elem_ty = array_ty.childType(zcu);
2899829019
2899929020 if (array_len_s == 0) {
2900029021 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});
......@@ -29017,7 +29038,7 @@ fn elemValArray(
2901729038 }
2901829039 }
2901929040 if (maybe_undef_array_val) |array_val| {
29020 if (array_val.isUndef(mod)) {
29041 if (array_val.isUndef(zcu)) {
2902129042 return pt.undefRef(elem_ty);
2902229043 }
2902329044 if (maybe_index_val) |index_val| {
......@@ -29058,11 +29079,11 @@ fn elemPtrArray(
2905829079 oob_safety: bool,
2905929080) CompileError!Air.Inst.Ref {
2906029081 const pt = sema.pt;
29061 const mod = pt.zcu;
29082 const zcu = pt.zcu;
2906229083 const array_ptr_ty = sema.typeOf(array_ptr);
29063 const array_ty = array_ptr_ty.childType(mod);
29064 const array_sent = array_ty.sentinel(mod) != null;
29065 const array_len = array_ty.arrayLen(mod);
29084 const array_ty = array_ptr_ty.childType(zcu);
29085 const array_sent = array_ty.sentinel(zcu) != null;
29086 const array_len = array_ty.arrayLen(zcu);
2906629087 const array_len_s = array_len + @intFromBool(array_sent);
2906729088
2906829089 if (array_len_s == 0) {
......@@ -29083,7 +29104,7 @@ fn elemPtrArray(
2908329104 const elem_ptr_ty = try array_ptr_ty.elemPtrType(offset, pt);
2908429105
2908529106 if (maybe_undef_array_ptr_val) |array_ptr_val| {
29086 if (array_ptr_val.isUndef(mod)) {
29107 if (array_ptr_val.isUndef(zcu)) {
2908729108 return pt.undefRef(elem_ptr_ty);
2908829109 }
2908929110 if (offset) |index| {
......@@ -29093,7 +29114,7 @@ fn elemPtrArray(
2909329114 }
2909429115
2909529116 if (!init) {
29096 try sema.validateRuntimeElemAccess(block, elem_index_src, array_ty.elemType2(mod), array_ty, array_ptr_src);
29117 try sema.validateRuntimeElemAccess(block, elem_index_src, array_ty.elemType2(zcu), array_ty, array_ptr_src);
2909729118 }
2909829119
2909929120 const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src;
......@@ -29120,10 +29141,10 @@ fn elemValSlice(
2912029141 oob_safety: bool,
2912129142) CompileError!Air.Inst.Ref {
2912229143 const pt = sema.pt;
29123 const mod = pt.zcu;
29144 const zcu = pt.zcu;
2912429145 const slice_ty = sema.typeOf(slice);
29125 const slice_sent = slice_ty.sentinel(mod) != null;
29126 const elem_ty = slice_ty.elemType2(mod);
29146 const slice_sent = slice_ty.sentinel(zcu) != null;
29147 const elem_ty = slice_ty.elemType2(zcu);
2912729148 var runtime_src = slice_src;
2912829149
2912929150 // slice must be defined since it can dereferenced as null
......@@ -29178,9 +29199,9 @@ fn elemPtrSlice(
2917829199 oob_safety: bool,
2917929200) CompileError!Air.Inst.Ref {
2918029201 const pt = sema.pt;
29181 const mod = pt.zcu;
29202 const zcu = pt.zcu;
2918229203 const slice_ty = sema.typeOf(slice);
29183 const slice_sent = slice_ty.sentinel(mod) != null;
29204 const slice_sent = slice_ty.sentinel(zcu) != null;
2918429205
2918529206 const maybe_undef_slice_val = try sema.resolveValue(slice);
2918629207 // The index must not be undefined since it can be out of bounds.
......@@ -29192,7 +29213,7 @@ fn elemPtrSlice(
2919229213 const elem_ptr_ty = try slice_ty.elemPtrType(offset, pt);
2919329214
2919429215 if (maybe_undef_slice_val) |slice_val| {
29195 if (slice_val.isUndef(mod)) {
29216 if (slice_val.isUndef(zcu)) {
2919629217 return pt.undefRef(elem_ptr_ty);
2919729218 }
2919829219 const slice_len = try slice_val.sliceLen(pt);
......@@ -29217,7 +29238,7 @@ fn elemPtrSlice(
2921729238 if (oob_safety and block.wantSafety()) {
2921829239 const len_inst = len: {
2921929240 if (maybe_undef_slice_val) |slice_val|
29220 if (!slice_val.isUndef(mod))
29241 if (!slice_val.isUndef(zcu))
2922129242 break :len try pt.intRef(Type.usize, try slice_val.sliceLen(pt));
2922229243 break :len try block.addTyOp(.slice_len, Type.usize, slice);
2922329244 };
......@@ -29600,7 +29621,7 @@ fn coerceExtra(
2960029621 // empty tuple to zero-length slice
2960129622 // note that this allows coercing to a mutable slice.
2960229623 if (inst_child_ty.structFieldCount(zcu) == 0) {
29603 const align_val = try dest_ty.ptrAlignmentAdvanced(pt, .sema);
29624 const align_val = try dest_ty.ptrAlignmentSema(pt);
2960429625 return Air.internedToRef(try pt.intern(.{ .slice = .{
2960529626 .ty = dest_ty.toIntern(),
2960629627 .ptr = try pt.intern(.{ .ptr = .{
......@@ -30098,7 +30119,7 @@ const InMemoryCoercionResult = union(enum) {
3009830119 return res;
3009930120 }
3010030121
30101 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Module.ErrorMsg) !void {
30122 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Zcu.ErrorMsg) !void {
3010230123 const pt = sema.pt;
3010330124 var cur = res;
3010430125 while (true) switch (cur.*) {
......@@ -30364,18 +30385,18 @@ pub fn coerceInMemoryAllowed(
3036430385 src_val: ?Value,
3036530386) CompileError!InMemoryCoercionResult {
3036630387 const pt = sema.pt;
30367 const mod = pt.zcu;
30388 const zcu = pt.zcu;
3036830389
30369 if (dest_ty.eql(src_ty, mod))
30390 if (dest_ty.eql(src_ty, zcu))
3037030391 return .ok;
3037130392
30372 const dest_tag = dest_ty.zigTypeTag(mod);
30373 const src_tag = src_ty.zigTypeTag(mod);
30393 const dest_tag = dest_ty.zigTypeTag(zcu);
30394 const src_tag = src_ty.zigTypeTag(zcu);
3037430395
3037530396 // Differently-named integers with the same number of bits.
3037630397 if (dest_tag == .Int and src_tag == .Int) {
30377 const dest_info = dest_ty.intInfo(mod);
30378 const src_info = src_ty.intInfo(mod);
30398 const dest_info = dest_ty.intInfo(zcu);
30399 const src_info = src_ty.intInfo(zcu);
3037930400
3038030401 if (dest_info.signedness == src_info.signedness and
3038130402 dest_info.bits == src_info.bits)
......@@ -30425,7 +30446,7 @@ pub fn coerceInMemoryAllowed(
3042530446 }
3042630447
3042730448 // Slices
30428 if (dest_ty.isSlice(mod) and src_ty.isSlice(mod)) {
30449 if (dest_ty.isSlice(zcu) and src_ty.isSlice(zcu)) {
3042930450 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src);
3043030451 }
3043130452
......@@ -30436,8 +30457,8 @@ pub fn coerceInMemoryAllowed(
3043630457
3043730458 // Error Unions
3043830459 if (dest_tag == .ErrorUnion and src_tag == .ErrorUnion) {
30439 const dest_payload = dest_ty.errorUnionPayload(mod);
30440 const src_payload = src_ty.errorUnionPayload(mod);
30460 const dest_payload = dest_ty.errorUnionPayload(zcu);
30461 const src_payload = src_ty.errorUnionPayload(zcu);
3044130462 const child = try sema.coerceInMemoryAllowed(block, dest_payload, src_payload, dest_is_mut, target, dest_src, src_src, null);
3044230463 if (child != .ok) {
3044330464 return InMemoryCoercionResult{ .error_union_payload = .{
......@@ -30446,7 +30467,7 @@ pub fn coerceInMemoryAllowed(
3044630467 .wanted = dest_payload,
3044730468 } };
3044830469 }
30449 return try sema.coerceInMemoryAllowed(block, dest_ty.errorUnionSet(mod), src_ty.errorUnionSet(mod), dest_is_mut, target, dest_src, src_src, null);
30470 return try sema.coerceInMemoryAllowed(block, dest_ty.errorUnionSet(zcu), src_ty.errorUnionSet(zcu), dest_is_mut, target, dest_src, src_src, null);
3045030471 }
3045130472
3045230473 // Error Sets
......@@ -30456,8 +30477,8 @@ pub fn coerceInMemoryAllowed(
3045630477
3045730478 // Arrays
3045830479 if (dest_tag == .Array and src_tag == .Array) {
30459 const dest_info = dest_ty.arrayInfo(mod);
30460 const src_info = src_ty.arrayInfo(mod);
30480 const dest_info = dest_ty.arrayInfo(zcu);
30481 const src_info = src_ty.arrayInfo(zcu);
3046130482 if (dest_info.len != src_info.len) {
3046230483 return InMemoryCoercionResult{ .array_len = .{
3046330484 .actual = src_info.len,
......@@ -30483,7 +30504,7 @@ pub fn coerceInMemoryAllowed(
3048330504 dest_info.sentinel.?.eql(
3048430505 try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type),
3048530506 dest_info.elem_type,
30486 mod,
30507 zcu,
3048730508 ));
3048830509 if (!ok_sent) {
3048930510 return InMemoryCoercionResult{ .array_sentinel = .{
......@@ -30497,8 +30518,8 @@ pub fn coerceInMemoryAllowed(
3049730518
3049830519 // Vectors
3049930520 if (dest_tag == .Vector and src_tag == .Vector) {
30500 const dest_len = dest_ty.vectorLen(mod);
30501 const src_len = src_ty.vectorLen(mod);
30521 const dest_len = dest_ty.vectorLen(zcu);
30522 const src_len = src_ty.vectorLen(zcu);
3050230523 if (dest_len != src_len) {
3050330524 return InMemoryCoercionResult{ .vector_len = .{
3050430525 .actual = src_len,
......@@ -30506,8 +30527,8 @@ pub fn coerceInMemoryAllowed(
3050630527 } };
3050730528 }
3050830529
30509 const dest_elem_ty = dest_ty.scalarType(mod);
30510 const src_elem_ty = src_ty.scalarType(mod);
30530 const dest_elem_ty = dest_ty.scalarType(zcu);
30531 const src_elem_ty = src_ty.scalarType(zcu);
3051130532 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);
3051230533 if (child != .ok) {
3051330534 return InMemoryCoercionResult{ .vector_elem = .{
......@@ -30524,8 +30545,8 @@ pub fn coerceInMemoryAllowed(
3052430545 if ((dest_tag == .Vector and src_tag == .Array) or
3052530546 (dest_tag == .Array and src_tag == .Vector))
3052630547 {
30527 const dest_len = dest_ty.arrayLen(mod);
30528 const src_len = src_ty.arrayLen(mod);
30548 const dest_len = dest_ty.arrayLen(zcu);
30549 const src_len = src_ty.arrayLen(zcu);
3052930550 if (dest_len != src_len) {
3053030551 return InMemoryCoercionResult{ .array_len = .{
3053130552 .actual = src_len,
......@@ -30533,8 +30554,8 @@ pub fn coerceInMemoryAllowed(
3053330554 } };
3053430555 }
3053530556
30536 const dest_elem_ty = dest_ty.childType(mod);
30537 const src_elem_ty = src_ty.childType(mod);
30557 const dest_elem_ty = dest_ty.childType(zcu);
30558 const src_elem_ty = src_ty.childType(zcu);
3053830559 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);
3053930560 if (child != .ok) {
3054030561 return InMemoryCoercionResult{ .array_elem = .{
......@@ -30545,7 +30566,7 @@ pub fn coerceInMemoryAllowed(
3054530566 }
3054630567
3054730568 if (dest_tag == .Array) {
30548 const dest_info = dest_ty.arrayInfo(mod);
30569 const dest_info = dest_ty.arrayInfo(zcu);
3054930570 if (dest_info.sentinel != null) {
3055030571 return InMemoryCoercionResult{ .array_sentinel = .{
3055130572 .actual = Value.@"unreachable",
......@@ -30558,8 +30579,8 @@ pub fn coerceInMemoryAllowed(
3055830579 // The memory layout of @Vector(N, iM) is the same as the integer type i(N*M),
3055930580 // that is to say, the padding bits are not in the same place as the array [N]iM.
3056030581 // If there's no padding, the bitcast is possible.
30561 const elem_bit_size = dest_elem_ty.bitSize(pt);
30562 const elem_abi_byte_size = dest_elem_ty.abiSize(pt);
30582 const elem_bit_size = dest_elem_ty.bitSize(zcu);
30583 const elem_abi_byte_size = dest_elem_ty.abiSize(zcu);
3056330584 if (elem_abi_byte_size * 8 == elem_bit_size)
3056430585 return .ok;
3056530586 }
......@@ -30572,8 +30593,8 @@ pub fn coerceInMemoryAllowed(
3057230593 .wanted = dest_ty,
3057330594 } };
3057430595 }
30575 const dest_child_type = dest_ty.optionalChild(mod);
30576 const src_child_type = src_ty.optionalChild(mod);
30596 const dest_child_type = dest_ty.optionalChild(zcu);
30597 const src_child_type = src_ty.optionalChild(zcu);
3057730598
3057830599 const child = try sema.coerceInMemoryAllowed(block, dest_child_type, src_child_type, dest_is_mut, target, dest_src, src_src, null);
3057930600 if (child != .ok) {
......@@ -30588,15 +30609,15 @@ pub fn coerceInMemoryAllowed(
3058830609 }
3058930610
3059030611 // Tuples (with in-memory-coercible fields)
30591 if (dest_ty.isTuple(mod) and src_ty.isTuple(mod)) tuple: {
30592 if (dest_ty.containerLayout(mod) != src_ty.containerLayout(mod)) break :tuple;
30593 if (dest_ty.structFieldCount(mod) != src_ty.structFieldCount(mod)) break :tuple;
30594 const field_count = dest_ty.structFieldCount(mod);
30612 if (dest_ty.isTuple(zcu) and src_ty.isTuple(zcu)) tuple: {
30613 if (dest_ty.containerLayout(zcu) != src_ty.containerLayout(zcu)) break :tuple;
30614 if (dest_ty.structFieldCount(zcu) != src_ty.structFieldCount(zcu)) break :tuple;
30615 const field_count = dest_ty.structFieldCount(zcu);
3059530616 for (0..field_count) |field_idx| {
30596 if (dest_ty.structFieldIsComptime(field_idx, mod) != src_ty.structFieldIsComptime(field_idx, mod)) break :tuple;
30597 if (dest_ty.structFieldAlign(field_idx, pt) != src_ty.structFieldAlign(field_idx, pt)) break :tuple;
30598 const dest_field_ty = dest_ty.structFieldType(field_idx, mod);
30599 const src_field_ty = src_ty.structFieldType(field_idx, mod);
30617 if (dest_ty.structFieldIsComptime(field_idx, zcu) != src_ty.structFieldIsComptime(field_idx, zcu)) break :tuple;
30618 if (dest_ty.structFieldAlign(field_idx, zcu) != src_ty.structFieldAlign(field_idx, zcu)) break :tuple;
30619 const dest_field_ty = dest_ty.structFieldType(field_idx, zcu);
30620 const src_field_ty = src_ty.structFieldType(field_idx, zcu);
3060030621 const field = try sema.coerceInMemoryAllowed(block, dest_field_ty, src_field_ty, dest_is_mut, target, dest_src, src_src, null);
3060130622 if (field != .ok) break :tuple;
3060230623 }
......@@ -30618,13 +30639,13 @@ fn coerceInMemoryAllowedErrorSets(
3061830639 src_src: LazySrcLoc,
3061930640) !InMemoryCoercionResult {
3062030641 const pt = sema.pt;
30621 const mod = pt.zcu;
30642 const zcu = pt.zcu;
3062230643 const gpa = sema.gpa;
30623 const ip = &mod.intern_pool;
30644 const ip = &zcu.intern_pool;
3062430645
3062530646 // Coercion to `anyerror`. Note that this check can return false negatives
3062630647 // in case the error sets did not get resolved.
30627 if (dest_ty.isAnyError(mod)) {
30648 if (dest_ty.isAnyError(zcu)) {
3062830649 return .ok;
3062930650 }
3063030651
......@@ -30669,7 +30690,7 @@ fn coerceInMemoryAllowedErrorSets(
3066930690 const resolved_src_ty = try sema.resolveInferredErrorSet(block, src_src, src_ty.toIntern());
3067030691 // src anyerror status might have changed after the resolution.
3067130692 if (resolved_src_ty == .anyerror_type) {
30672 // dest_ty.isAnyError(mod) == true is already checked for at this point.
30693 // dest_ty.isAnyError(zcu) == true is already checked for at this point.
3067330694 return .from_anyerror;
3067430695 }
3067530696
......@@ -30717,11 +30738,11 @@ fn coerceInMemoryAllowedFns(
3071730738 src_src: LazySrcLoc,
3071830739) !InMemoryCoercionResult {
3071930740 const pt = sema.pt;
30720 const mod = pt.zcu;
30721 const ip = &mod.intern_pool;
30741 const zcu = pt.zcu;
30742 const ip = &zcu.intern_pool;
3072230743
30723 const dest_info = mod.typeToFunc(dest_ty).?;
30724 const src_info = mod.typeToFunc(src_ty).?;
30744 const dest_info = zcu.typeToFunc(dest_ty).?;
30745 const src_info = zcu.typeToFunc(src_ty).?;
3072530746
3072630747 {
3072730748 if (dest_info.is_var_args != src_info.is_var_args) {
......@@ -30922,12 +30943,12 @@ fn coerceInMemoryAllowedPtrs(
3092230943 const src_align = if (src_info.flags.alignment != .none)
3092330944 src_info.flags.alignment
3092430945 else
30925 try sema.typeAbiAlignment(Type.fromInterned(src_info.child));
30946 try Type.fromInterned(src_info.child).abiAlignmentSema(pt);
3092630947
3092730948 const dest_align = if (dest_info.flags.alignment != .none)
3092830949 dest_info.flags.alignment
3092930950 else
30930 try sema.typeAbiAlignment(Type.fromInterned(dest_info.child));
30951 try Type.fromInterned(dest_info.child).abiAlignmentSema(pt);
3093130952
3093230953 if (dest_align.compare(.gt, src_align)) {
3093330954 return InMemoryCoercionResult{ .ptr_alignment = .{
......@@ -31044,12 +31065,12 @@ fn storePtr2(
3104431065 air_tag: Air.Inst.Tag,
3104531066) CompileError!void {
3104631067 const pt = sema.pt;
31047 const mod = pt.zcu;
31068 const zcu = pt.zcu;
3104831069 const ptr_ty = sema.typeOf(ptr);
31049 if (ptr_ty.isConstPtr(mod))
31070 if (ptr_ty.isConstPtr(zcu))
3105031071 return sema.fail(block, ptr_src, "cannot assign to constant", .{});
3105131072
31052 const elem_ty = ptr_ty.childType(mod);
31073 const elem_ty = ptr_ty.childType(zcu);
3105331074
3105431075 // To generate better code for tuples, we detect a tuple operand here, and
3105531076 // analyze field loads and stores directly. This avoids an extra allocation + memcpy
......@@ -31060,8 +31081,8 @@ fn storePtr2(
3106031081 // this code does not handle tuple-to-struct coercion which requires dealing with missing
3106131082 // fields.
3106231083 const operand_ty = sema.typeOf(uncasted_operand);
31063 if (operand_ty.isTuple(mod) and elem_ty.zigTypeTag(mod) == .Array) {
31064 const field_count = operand_ty.structFieldCount(mod);
31084 if (operand_ty.isTuple(zcu) and elem_ty.zigTypeTag(zcu) == .Array) {
31085 const field_count = operand_ty.structFieldCount(zcu);
3106531086 var i: u32 = 0;
3106631087 while (i < field_count) : (i += 1) {
3106731088 const elem_src = operand_src; // TODO better source location
......@@ -31085,7 +31106,7 @@ fn storePtr2(
3108531106 // as well as working around an LLVM bug:
3108631107 // https://github.com/ziglang/zig/issues/11154
3108731108 if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| {
31088 const vector_ty = sema.typeOf(vector_ptr).childType(mod);
31109 const vector_ty = sema.typeOf(vector_ptr).childType(zcu);
3108931110 const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
3109031111 error.NotCoercible => unreachable,
3109131112 else => |e| return e,
......@@ -31119,7 +31140,7 @@ fn storePtr2(
3111931140
3112031141 try sema.requireRuntimeBlock(block, src, runtime_src);
3112131142
31122 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
31143 if (ptr_ty.ptrInfo(zcu).flags.vector_index == .runtime) {
3112331144 const ptr_inst = ptr.toIndex().?;
3112431145 const air_tags = sema.air_instructions.items(.tag);
3112531146 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
......@@ -31253,9 +31274,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3125331274/// lengths match.
3125431275fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
3125531276 const pt = sema.pt;
31256 const mod = pt.zcu;
31257 const array_ty = sema.typeOf(ptr).childType(mod);
31258 if (array_ty.zigTypeTag(mod) != .Array) return null;
31277 const zcu = pt.zcu;
31278 const array_ty = sema.typeOf(ptr).childType(zcu);
31279 if (array_ty.zigTypeTag(zcu) != .Array) return null;
3125931280 var ptr_ref = ptr;
3126031281 var ptr_inst = ptr_ref.toIndex() orelse return null;
3126131282 const air_datas = sema.air_instructions.items(.data);
......@@ -31263,15 +31284,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
3126331284 const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
3126431285 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
3126531286 if (!sema.isKnownZigType(ptr_ref, .Pointer)) return null;
31266 const child_ty = sema.typeOf(ptr_ref).childType(mod);
31267 if (child_ty.zigTypeTag(mod) == .Vector) break child_ty;
31287 const child_ty = sema.typeOf(ptr_ref).childType(zcu);
31288 if (child_ty.zigTypeTag(zcu) == .Vector) break child_ty;
3126831289 ptr_inst = ptr_ref.toIndex() orelse return null;
3126931290 } else return null;
3127031291
3127131292 // We have a pointer-to-array and a pointer-to-vector. If the elements and
3127231293 // lengths match, return the result.
31273 if (array_ty.childType(mod).eql(vector_ty.childType(mod), mod) and
31274 array_ty.arrayLen(mod) == vector_ty.vectorLen(mod))
31294 if (array_ty.childType(zcu).eql(vector_ty.childType(zcu), zcu) and
31295 array_ty.arrayLen(zcu) == vector_ty.vectorLen(zcu))
3127531296 {
3127631297 return ptr_ref;
3127731298 } else {
......@@ -31347,8 +31368,8 @@ fn bitCast(
3134731368 const old_ty = sema.typeOf(inst);
3134831369 try old_ty.resolveLayout(pt);
3134931370
31350 const dest_bits = dest_ty.bitSize(pt);
31351 const old_bits = old_ty.bitSize(pt);
31371 const dest_bits = dest_ty.bitSize(zcu);
31372 const old_bits = old_ty.bitSize(zcu);
3135231373
3135331374 if (old_bits != dest_bits) {
3135431375 return sema.fail(block, inst_src, "@bitCast size mismatch: destination type '{}' has {d} bits but source type '{}' has {d} bits", .{
......@@ -31384,16 +31405,16 @@ fn coerceArrayPtrToSlice(
3138431405 inst_src: LazySrcLoc,
3138531406) CompileError!Air.Inst.Ref {
3138631407 const pt = sema.pt;
31387 const mod = pt.zcu;
31408 const zcu = pt.zcu;
3138831409 if (try sema.resolveValue(inst)) |val| {
3138931410 const ptr_array_ty = sema.typeOf(inst);
31390 const array_ty = ptr_array_ty.childType(mod);
31391 const slice_ptr_ty = dest_ty.slicePtrFieldType(mod);
31411 const array_ty = ptr_array_ty.childType(zcu);
31412 const slice_ptr_ty = dest_ty.slicePtrFieldType(zcu);
3139231413 const slice_ptr = try pt.getCoerced(val, slice_ptr_ty);
3139331414 const slice_val = try pt.intern(.{ .slice = .{
3139431415 .ty = dest_ty.toIntern(),
3139531416 .ptr = slice_ptr.toIntern(),
31396 .len = (try pt.intValue(Type.usize, array_ty.arrayLen(mod))).toIntern(),
31417 .len = (try pt.intValue(Type.usize, array_ty.arrayLen(zcu))).toIntern(),
3139731418 } });
3139831419 return Air.internedToRef(slice_val);
3139931420 }
......@@ -31403,12 +31424,12 @@ fn coerceArrayPtrToSlice(
3140331424
3140431425fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_result: *InMemoryCoercionResult) bool {
3140531426 const pt = sema.pt;
31406 const mod = pt.zcu;
31407 const dest_info = dest_ty.ptrInfo(mod);
31408 const inst_info = inst_ty.ptrInfo(mod);
31409 const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(mod) == .Array and (Type.fromInterned(inst_info.child).arrayLenIncludingSentinel(mod) == 0 or
31410 (Type.fromInterned(inst_info.child).arrayLen(mod) == 0 and dest_info.sentinel == .none and dest_info.flags.size != .C and dest_info.flags.size != .Many))) or
31411 (Type.fromInterned(inst_info.child).isTuple(mod) and Type.fromInterned(inst_info.child).structFieldCount(mod) == 0);
31427 const zcu = pt.zcu;
31428 const dest_info = dest_ty.ptrInfo(zcu);
31429 const inst_info = inst_ty.ptrInfo(zcu);
31430 const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(zcu) == .Array and (Type.fromInterned(inst_info.child).arrayLenIncludingSentinel(zcu) == 0 or
31431 (Type.fromInterned(inst_info.child).arrayLen(zcu) == 0 and dest_info.sentinel == .none and dest_info.flags.size != .C and dest_info.flags.size != .Many))) or
31432 (Type.fromInterned(inst_info.child).isTuple(zcu) and Type.fromInterned(inst_info.child).structFieldCount(zcu) == 0);
3141231433
3141331434 const ok_cv_qualifiers =
3141431435 ((!inst_info.flags.is_const or dest_info.flags.is_const) or len0) and
......@@ -31436,12 +31457,12 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul
3143631457 const inst_align = if (inst_info.flags.alignment != .none)
3143731458 inst_info.flags.alignment
3143831459 else
31439 Type.fromInterned(inst_info.child).abiAlignment(pt);
31460 Type.fromInterned(inst_info.child).abiAlignment(zcu);
3144031461
3144131462 const dest_align = if (dest_info.flags.alignment != .none)
3144231463 dest_info.flags.alignment
3144331464 else
31444 Type.fromInterned(dest_info.child).abiAlignment(pt);
31465 Type.fromInterned(dest_info.child).abiAlignment(zcu);
3144531466
3144631467 if (dest_align.compare(.gt, inst_align)) {
3144731468 in_memory_result.* = .{ .ptr_alignment = .{
......@@ -31461,10 +31482,10 @@ fn coerceCompatiblePtrs(
3146131482 inst_src: LazySrcLoc,
3146231483) !Air.Inst.Ref {
3146331484 const pt = sema.pt;
31464 const mod = pt.zcu;
31485 const zcu = pt.zcu;
3146531486 const inst_ty = sema.typeOf(inst);
3146631487 if (try sema.resolveValue(inst)) |val| {
31467 if (!val.isUndef(mod) and val.isNull(mod) and !dest_ty.isAllowzeroPtr(mod)) {
31488 if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) {
3146831489 return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});
3146931490 }
3147031491 // The comptime Value representation is compatible with both types.
......@@ -31473,17 +31494,17 @@ fn coerceCompatiblePtrs(
3147331494 );
3147431495 }
3147531496 try sema.requireRuntimeBlock(block, inst_src, null);
31476 const inst_allows_zero = inst_ty.zigTypeTag(mod) != .Pointer or inst_ty.ptrAllowsZero(mod);
31477 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(mod) and
31478 (try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn))
31497 const inst_allows_zero = inst_ty.zigTypeTag(zcu) != .Pointer or inst_ty.ptrAllowsZero(zcu);
31498 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(zcu) and
31499 (try dest_ty.elemType2(zcu).hasRuntimeBitsSema(pt) or dest_ty.elemType2(zcu).zigTypeTag(zcu) == .Fn))
3147931500 {
31480 const actual_ptr = if (inst_ty.isSlice(mod))
31501 const actual_ptr = if (inst_ty.isSlice(zcu))
3148131502 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
3148231503 else
3148331504 inst;
3148431505 const ptr_int = try block.addUnOp(.int_from_ptr, actual_ptr);
3148531506 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
31486 const ok = if (inst_ty.isSlice(mod)) ok: {
31507 const ok = if (inst_ty.isSlice(zcu)) ok: {
3148731508 const len = try sema.analyzeSliceLen(block, inst_src, inst);
3148831509 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
3148931510 break :ok try block.addBinOp(.bool_or, len_zero, is_non_zero);
......@@ -31504,11 +31525,11 @@ fn coerceEnumToUnion(
3150431525 inst_src: LazySrcLoc,
3150531526) !Air.Inst.Ref {
3150631527 const pt = sema.pt;
31507 const mod = pt.zcu;
31508 const ip = &mod.intern_pool;
31528 const zcu = pt.zcu;
31529 const ip = &zcu.intern_pool;
3150931530 const inst_ty = sema.typeOf(inst);
3151031531
31511 const tag_ty = union_ty.unionTagType(mod) orelse {
31532 const tag_ty = union_ty.unionTagType(zcu) orelse {
3151231533 const msg = msg: {
3151331534 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3151431535 union_ty.fmt(pt), inst_ty.fmt(pt),
......@@ -31529,10 +31550,10 @@ fn coerceEnumToUnion(
3152931550 });
3153031551 };
3153131552
31532 const union_obj = mod.typeToUnion(union_ty).?;
31553 const union_obj = zcu.typeToUnion(union_ty).?;
3153331554 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3153431555 try field_ty.resolveFields(pt);
31535 if (field_ty.zigTypeTag(mod) == .NoReturn) {
31556 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
3153631557 const msg = msg: {
3153731558 const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{});
3153831559 errdefer msg.destroy(sema.gpa);
......@@ -31569,7 +31590,7 @@ fn coerceEnumToUnion(
3156931590
3157031591 try sema.requireRuntimeBlock(block, inst_src, null);
3157131592
31572 if (tag_ty.isNonexhaustiveEnum(mod)) {
31593 if (tag_ty.isNonexhaustiveEnum(zcu)) {
3157331594 const msg = msg: {
3157431595 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
3157531596 union_ty.fmt(pt),
......@@ -31581,13 +31602,13 @@ fn coerceEnumToUnion(
3158131602 return sema.failWithOwnedErrorMsg(block, msg);
3158231603 }
3158331604
31584 const union_obj = mod.typeToUnion(union_ty).?;
31605 const union_obj = zcu.typeToUnion(union_ty).?;
3158531606 {
31586 var msg: ?*Module.ErrorMsg = null;
31607 var msg: ?*Zcu.ErrorMsg = null;
3158731608 errdefer if (msg) |some| some.destroy(sema.gpa);
3158831609
3158931610 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
31590 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {
31611 if (Type.fromInterned(field_ty).zigTypeTag(zcu) == .NoReturn) {
3159131612 const err_msg = msg orelse try sema.errMsg(
3159231613 inst_src,
3159331614 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",
......@@ -31606,7 +31627,7 @@ fn coerceEnumToUnion(
3160631627 }
3160731628
3160831629 // If the union has all fields 0 bits, the union value is just the enum value.
31609 if (union_ty.unionHasAllZeroBitFieldTypes(pt)) {
31630 if (union_ty.unionHasAllZeroBitFieldTypes(zcu)) {
3161031631 return block.addBitCast(union_ty, enum_tag);
3161131632 }
3161231633
......@@ -31621,7 +31642,7 @@ fn coerceEnumToUnion(
3162131642 for (0..union_obj.field_types.len) |field_index| {
3162231643 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
3162331644 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
31624 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
31645 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
3162531646 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
3162631647 field_name.fmt(ip),
3162731648 field_ty.fmt(pt),
......@@ -31642,8 +31663,8 @@ fn coerceAnonStructToUnion(
3164231663 inst_src: LazySrcLoc,
3164331664) !Air.Inst.Ref {
3164431665 const pt = sema.pt;
31645 const mod = pt.zcu;
31646 const ip = &mod.intern_pool;
31666 const zcu = pt.zcu;
31667 const ip = &zcu.intern_pool;
3164731668 const inst_ty = sema.typeOf(inst);
3164831669 const field_info: union(enum) {
3164931670 name: InternPool.NullTerminatedString,
......@@ -31701,8 +31722,8 @@ fn coerceAnonStructToUnionPtrs(
3170131722 anon_struct_src: LazySrcLoc,
3170231723) !Air.Inst.Ref {
3170331724 const pt = sema.pt;
31704 const mod = pt.zcu;
31705 const union_ty = ptr_union_ty.childType(mod);
31725 const zcu = pt.zcu;
31726 const union_ty = ptr_union_ty.childType(zcu);
3170631727 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
3170731728 const union_inst = try sema.coerceAnonStructToUnion(block, union_ty, union_ty_src, anon_struct, anon_struct_src);
3170831729 return sema.analyzeRef(block, union_ty_src, union_inst);
......@@ -31717,8 +31738,8 @@ fn coerceAnonStructToStructPtrs(
3171731738 anon_struct_src: LazySrcLoc,
3171831739) !Air.Inst.Ref {
3171931740 const pt = sema.pt;
31720 const mod = pt.zcu;
31721 const struct_ty = ptr_struct_ty.childType(mod);
31741 const zcu = pt.zcu;
31742 const struct_ty = ptr_struct_ty.childType(zcu);
3172231743 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
3172331744 const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, anon_struct, anon_struct_src);
3172431745 return sema.analyzeRef(block, struct_ty_src, struct_inst);
......@@ -31734,9 +31755,9 @@ fn coerceArrayLike(
3173431755 inst_src: LazySrcLoc,
3173531756) !Air.Inst.Ref {
3173631757 const pt = sema.pt;
31737 const mod = pt.zcu;
31758 const zcu = pt.zcu;
3173831759 const inst_ty = sema.typeOf(inst);
31739 const target = mod.getTarget();
31760 const target = zcu.getTarget();
3174031761
3174131762 // try coercion of the whole array
3174231763 const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src, null);
......@@ -31750,8 +31771,8 @@ fn coerceArrayLike(
3175031771 }
3175131772
3175231773 // otherwise, try element by element
31753 const inst_len = inst_ty.arrayLen(mod);
31754 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));
31774 const inst_len = inst_ty.arrayLen(zcu);
31775 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(zcu));
3175531776 if (dest_len != inst_len) {
3175631777 const msg = msg: {
3175731778 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
......@@ -31765,14 +31786,14 @@ fn coerceArrayLike(
3176531786 return sema.failWithOwnedErrorMsg(block, msg);
3176631787 }
3176731788
31768 const dest_elem_ty = dest_ty.childType(mod);
31769 if (dest_ty.isVector(mod) and inst_ty.isVector(mod) and (try sema.resolveValue(inst)) == null) {
31770 const inst_elem_ty = inst_ty.childType(mod);
31771 switch (dest_elem_ty.zigTypeTag(mod)) {
31772 .Int => if (inst_elem_ty.isInt(mod)) {
31789 const dest_elem_ty = dest_ty.childType(zcu);
31790 if (dest_ty.isVector(zcu) and inst_ty.isVector(zcu) and (try sema.resolveValue(inst)) == null) {
31791 const inst_elem_ty = inst_ty.childType(zcu);
31792 switch (dest_elem_ty.zigTypeTag(zcu)) {
31793 .Int => if (inst_elem_ty.isInt(zcu)) {
3177331794 // integer widening
31774 const dst_info = dest_elem_ty.intInfo(mod);
31775 const src_info = inst_elem_ty.intInfo(mod);
31795 const dst_info = dest_elem_ty.intInfo(zcu);
31796 const src_info = inst_elem_ty.intInfo(zcu);
3177631797 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or
3177731798 // small enough unsigned ints can get casted to large enough signed ints
3177831799 (dst_info.signedness == .signed and dst_info.bits > src_info.bits))
......@@ -31835,10 +31856,10 @@ fn coerceTupleToArray(
3183531856 inst_src: LazySrcLoc,
3183631857) !Air.Inst.Ref {
3183731858 const pt = sema.pt;
31838 const mod = pt.zcu;
31859 const zcu = pt.zcu;
3183931860 const inst_ty = sema.typeOf(inst);
31840 const inst_len = inst_ty.arrayLen(mod);
31841 const dest_len = dest_ty.arrayLen(mod);
31861 const inst_len = inst_ty.arrayLen(zcu);
31862 const dest_len = dest_ty.arrayLen(zcu);
3184231863
3184331864 if (dest_len != inst_len) {
3184431865 const msg = msg: {
......@@ -31856,13 +31877,13 @@ fn coerceTupleToArray(
3185631877 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len);
3185731878 const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems);
3185831879 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
31859 const dest_elem_ty = dest_ty.childType(mod);
31880 const dest_elem_ty = dest_ty.childType(zcu);
3186031881
3186131882 var runtime_src: ?LazySrcLoc = null;
3186231883 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
3186331884 const i: u32 = @intCast(i_usize);
3186431885 if (i_usize == inst_len) {
31865 const sentinel_val = dest_ty.sentinel(mod).?;
31886 const sentinel_val = dest_ty.sentinel(zcu).?;
3186631887 val.* = sentinel_val.toIntern();
3186731888 ref.* = Air.internedToRef(sentinel_val.toIntern());
3186831889 break;
......@@ -31901,12 +31922,12 @@ fn coerceTupleToSlicePtrs(
3190131922 tuple_src: LazySrcLoc,
3190231923) !Air.Inst.Ref {
3190331924 const pt = sema.pt;
31904 const mod = pt.zcu;
31905 const tuple_ty = sema.typeOf(ptr_tuple).childType(mod);
31925 const zcu = pt.zcu;
31926 const tuple_ty = sema.typeOf(ptr_tuple).childType(zcu);
3190631927 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
31907 const slice_info = slice_ty.ptrInfo(mod);
31928 const slice_info = slice_ty.ptrInfo(zcu);
3190831929 const array_ty = try pt.arrayType(.{
31909 .len = tuple_ty.structFieldCount(mod),
31930 .len = tuple_ty.structFieldCount(zcu),
3191031931 .sentinel = slice_info.sentinel,
3191131932 .child = slice_info.child,
3191231933 });
......@@ -31928,9 +31949,9 @@ fn coerceTupleToArrayPtrs(
3192831949 tuple_src: LazySrcLoc,
3192931950) !Air.Inst.Ref {
3193031951 const pt = sema.pt;
31931 const mod = pt.zcu;
31952 const zcu = pt.zcu;
3193231953 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
31933 const ptr_info = ptr_array_ty.ptrInfo(mod);
31954 const ptr_info = ptr_array_ty.ptrInfo(zcu);
3193431955 const array_ty = Type.fromInterned(ptr_info.child);
3193531956 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
3193631957 if (ptr_info.flags.alignment != .none) {
......@@ -31950,16 +31971,16 @@ fn coerceTupleToStruct(
3195031971 inst_src: LazySrcLoc,
3195131972) !Air.Inst.Ref {
3195231973 const pt = sema.pt;
31953 const mod = pt.zcu;
31954 const ip = &mod.intern_pool;
31974 const zcu = pt.zcu;
31975 const ip = &zcu.intern_pool;
3195531976 try struct_ty.resolveFields(pt);
3195631977 try struct_ty.resolveStructFieldInits(pt);
3195731978
31958 if (struct_ty.isTupleOrAnonStruct(mod)) {
31979 if (struct_ty.isTupleOrAnonStruct(zcu)) {
3195931980 return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src);
3196031981 }
3196131982
31962 const struct_type = mod.typeToStruct(struct_ty).?;
31983 const struct_type = zcu.typeToStruct(struct_ty).?;
3196331984 const field_vals = try sema.arena.alloc(InternPool.Index, struct_type.field_types.len);
3196431985 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
3196531986 @memset(field_refs, .none);
......@@ -31973,7 +31994,7 @@ fn coerceTupleToStruct(
3197331994 };
3197431995 for (0..field_count) |tuple_field_index| {
3197531996 const field_src = inst_src; // TODO better source location
31976 const field_name = inst_ty.structFieldName(tuple_field_index, mod).unwrap() orelse
31997 const field_name = inst_ty.structFieldName(tuple_field_index, zcu).unwrap() orelse
3197731998 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{tuple_field_index}, .no_embedded_nulls);
3197831999
3197932000 const struct_field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);
......@@ -32003,7 +32024,7 @@ fn coerceTupleToStruct(
3200332024 }
3200432025
3200532026 // Populate default field values and report errors for missing fields.
32006 var root_msg: ?*Module.ErrorMsg = null;
32027 var root_msg: ?*Zcu.ErrorMsg = null;
3200732028 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
3200832029
3200932030 for (field_refs, 0..) |*field_ref, i| {
......@@ -32058,8 +32079,8 @@ fn coerceTupleToTuple(
3205832079 inst_src: LazySrcLoc,
3205932080) !Air.Inst.Ref {
3206032081 const pt = sema.pt;
32061 const mod = pt.zcu;
32062 const ip = &mod.intern_pool;
32082 const zcu = pt.zcu;
32083 const ip = &zcu.intern_pool;
3206332084 const dest_field_count = switch (ip.indexToKey(tuple_ty.toIntern())) {
3206432085 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,
3206532086 .struct_type => ip.loadStructType(tuple_ty.toIntern()).field_types.len,
......@@ -32081,7 +32102,7 @@ fn coerceTupleToTuple(
3208132102 for (0..dest_field_count) |field_index_usize| {
3208232103 const field_i: u32 = @intCast(field_index_usize);
3208332104 const field_src = inst_src; // TODO better source location
32084 const field_name = inst_ty.structFieldName(field_index_usize, mod).unwrap() orelse
32105 const field_name = inst_ty.structFieldName(field_index_usize, zcu).unwrap() orelse
3208532106 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_index_usize}, .no_embedded_nulls);
3208632107
3208732108 if (field_name.eqlSlice("len", ip))
......@@ -32124,7 +32145,7 @@ fn coerceTupleToTuple(
3212432145 }
3212532146
3212632147 // Populate default field values and report errors for missing fields.
32127 var root_msg: ?*Module.ErrorMsg = null;
32148 var root_msg: ?*Zcu.ErrorMsg = null;
3212832149 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
3212932150
3213032151 for (field_refs, 0..) |*field_ref, i_usize| {
......@@ -32139,7 +32160,7 @@ fn coerceTupleToTuple(
3213932160
3214032161 const field_src = inst_src; // TODO better source location
3214132162 if (default_val == .none) {
32142 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {
32163 const field_name = tuple_ty.structFieldName(i, zcu).unwrap() orelse {
3214332164 const template = "missing tuple field: {d}";
3214432165 if (root_msg) |msg| {
3214532166 try sema.errNote(field_src, msg, template, .{i});
......@@ -32308,7 +32329,7 @@ fn maybeQueueFuncBodyAnalysis(sema: *Sema, src: LazySrcLoc, nav_index: InternPoo
3230832329 const ip = &zcu.intern_pool;
3230932330 const nav_val = zcu.navValue(nav_index);
3231032331 if (!ip.isFuncBody(nav_val.toIntern())) return;
32311 if (!try sema.fnHasRuntimeBits(nav_val.typeOf(zcu))) return;
32332 if (!try nav_val.typeOf(zcu).fnHasRuntimeBitsSema(sema.pt)) return;
3231232333 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .func = nav_val.toIntern() }));
3231332334 try zcu.ensureFuncBodyAnalysisQueued(nav_val.toIntern());
3231432335}
......@@ -32320,11 +32341,11 @@ fn analyzeRef(
3232032341 operand: Air.Inst.Ref,
3232132342) CompileError!Air.Inst.Ref {
3232232343 const pt = sema.pt;
32323 const mod = pt.zcu;
32344 const zcu = pt.zcu;
3232432345 const operand_ty = sema.typeOf(operand);
3232532346
3232632347 if (try sema.resolveValue(operand)) |val| {
32327 switch (mod.intern_pool.indexToKey(val.toIntern())) {
32348 switch (zcu.intern_pool.indexToKey(val.toIntern())) {
3232832349 .@"extern" => |e| return sema.analyzeNavRef(src, e.owner_nav),
3232932350 .func => |f| return sema.analyzeNavRef(src, f.owner_nav),
3233032351 else => return uavRef(sema, val.toIntern()),
......@@ -32332,7 +32353,7 @@ fn analyzeRef(
3233232353 }
3233332354
3233432355 try sema.requireRuntimeBlock(block, src, null);
32335 const address_space = target_util.defaultAddressSpace(mod.getTarget(), .local);
32356 const address_space = target_util.defaultAddressSpace(zcu.getTarget(), .local);
3233632357 const ptr_type = try pt.ptrTypeSema(.{
3233732358 .child = operand_ty.toIntern(),
3233832359 .flags = .{
......@@ -32359,13 +32380,13 @@ fn analyzeLoad(
3235932380 ptr_src: LazySrcLoc,
3236032381) CompileError!Air.Inst.Ref {
3236132382 const pt = sema.pt;
32362 const mod = pt.zcu;
32383 const zcu = pt.zcu;
3236332384 const ptr_ty = sema.typeOf(ptr);
32364 const elem_ty = switch (ptr_ty.zigTypeTag(mod)) {
32365 .Pointer => ptr_ty.childType(mod),
32385 const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) {
32386 .Pointer => ptr_ty.childType(zcu),
3236632387 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(pt)}),
3236732388 };
32368 if (elem_ty.zigTypeTag(mod) == .Opaque) {
32389 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
3236932390 return sema.fail(block, ptr_src, "cannot load opaque type '{}'", .{elem_ty.fmt(pt)});
3237032391 }
3237132392
......@@ -32379,7 +32400,7 @@ fn analyzeLoad(
3237932400 }
3238032401 }
3238132402
32382 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
32403 if (ptr_ty.ptrInfo(zcu).flags.vector_index == .runtime) {
3238332404 const ptr_inst = ptr.toIndex().?;
3238432405 const air_tags = sema.air_instructions.items(.tag);
3238532406 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
......@@ -32403,11 +32424,11 @@ fn analyzeSlicePtr(
3240332424 slice_ty: Type,
3240432425) CompileError!Air.Inst.Ref {
3240532426 const pt = sema.pt;
32406 const mod = pt.zcu;
32407 const result_ty = slice_ty.slicePtrFieldType(mod);
32427 const zcu = pt.zcu;
32428 const result_ty = slice_ty.slicePtrFieldType(zcu);
3240832429 if (try sema.resolveValue(slice)) |val| {
32409 if (val.isUndef(mod)) return pt.undefRef(result_ty);
32410 return Air.internedToRef(val.slicePtr(mod).toIntern());
32430 if (val.isUndef(zcu)) return pt.undefRef(result_ty);
32431 return Air.internedToRef(val.slicePtr(zcu).toIntern());
3241132432 }
3241232433 try sema.requireRuntimeBlock(block, slice_src, null);
3241332434 return block.addTyOp(.slice_ptr, result_ty, slice);
......@@ -32421,13 +32442,13 @@ fn analyzeOptionalSlicePtr(
3242132442 opt_slice_ty: Type,
3242232443) CompileError!Air.Inst.Ref {
3242332444 const pt = sema.pt;
32424 const mod = pt.zcu;
32425 const result_ty = opt_slice_ty.optionalChild(mod).slicePtrFieldType(mod);
32445 const zcu = pt.zcu;
32446 const result_ty = opt_slice_ty.optionalChild(zcu).slicePtrFieldType(zcu);
3242632447
3242732448 if (try sema.resolveValue(opt_slice)) |opt_val| {
32428 if (opt_val.isUndef(mod)) return pt.undefRef(result_ty);
32429 const slice_ptr: InternPool.Index = if (opt_val.optionalValue(mod)) |val|
32430 val.slicePtr(mod).toIntern()
32449 if (opt_val.isUndef(zcu)) return pt.undefRef(result_ty);
32450 const slice_ptr: InternPool.Index = if (opt_val.optionalValue(zcu)) |val|
32451 val.slicePtr(zcu).toIntern()
3243132452 else
3243232453 .null_value;
3243332454
......@@ -32447,9 +32468,9 @@ fn analyzeSliceLen(
3244732468 slice_inst: Air.Inst.Ref,
3244832469) CompileError!Air.Inst.Ref {
3244932470 const pt = sema.pt;
32450 const mod = pt.zcu;
32471 const zcu = pt.zcu;
3245132472 if (try sema.resolveValue(slice_inst)) |slice_val| {
32452 if (slice_val.isUndef(mod)) {
32473 if (slice_val.isUndef(zcu)) {
3245332474 return pt.undefRef(Type.usize);
3245432475 }
3245532476 return pt.intRef(Type.usize, try slice_val.sliceLen(pt));
......@@ -32466,23 +32487,23 @@ fn analyzeIsNull(
3246632487 invert_logic: bool,
3246732488) CompileError!Air.Inst.Ref {
3246832489 const pt = sema.pt;
32469 const mod = pt.zcu;
32490 const zcu = pt.zcu;
3247032491 const result_ty = Type.bool;
3247132492 if (try sema.resolveValue(operand)) |opt_val| {
32472 if (opt_val.isUndef(mod)) {
32493 if (opt_val.isUndef(zcu)) {
3247332494 return pt.undefRef(result_ty);
3247432495 }
32475 const is_null = opt_val.isNull(mod);
32496 const is_null = opt_val.isNull(zcu);
3247632497 const bool_value = if (invert_logic) !is_null else is_null;
3247732498 return if (bool_value) .bool_true else .bool_false;
3247832499 }
3247932500
3248032501 const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false;
3248132502 const operand_ty = sema.typeOf(operand);
32482 if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(mod).zigTypeTag(mod) == .NoReturn) {
32503 if (operand_ty.zigTypeTag(zcu) == .Optional and operand_ty.optionalChild(zcu).zigTypeTag(zcu) == .NoReturn) {
3248332504 return inverted_non_null_res;
3248432505 }
32485 if (operand_ty.zigTypeTag(mod) != .Optional and !operand_ty.isPtrLikeOptional(mod)) {
32506 if (operand_ty.zigTypeTag(zcu) != .Optional and !operand_ty.isPtrLikeOptional(zcu)) {
3248632507 return inverted_non_null_res;
3248732508 }
3248832509 try sema.requireRuntimeBlock(block, src, null);
......@@ -32497,12 +32518,12 @@ fn analyzePtrIsNonErrComptimeOnly(
3249732518 operand: Air.Inst.Ref,
3249832519) CompileError!Air.Inst.Ref {
3249932520 const pt = sema.pt;
32500 const mod = pt.zcu;
32521 const zcu = pt.zcu;
3250132522 const ptr_ty = sema.typeOf(operand);
32502 assert(ptr_ty.zigTypeTag(mod) == .Pointer);
32503 const child_ty = ptr_ty.childType(mod);
32523 assert(ptr_ty.zigTypeTag(zcu) == .Pointer);
32524 const child_ty = ptr_ty.childType(zcu);
3250432525
32505 const child_tag = child_ty.zigTypeTag(mod);
32526 const child_tag = child_ty.zigTypeTag(zcu);
3250632527 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return .bool_true;
3250732528 if (child_tag == .ErrorSet) return .bool_false;
3250832529 assert(child_tag == .ErrorUnion);
......@@ -32520,16 +32541,16 @@ fn analyzeIsNonErrComptimeOnly(
3252032541 operand: Air.Inst.Ref,
3252132542) CompileError!Air.Inst.Ref {
3252232543 const pt = sema.pt;
32523 const mod = pt.zcu;
32524 const ip = &mod.intern_pool;
32544 const zcu = pt.zcu;
32545 const ip = &zcu.intern_pool;
3252532546 const operand_ty = sema.typeOf(operand);
32526 const ot = operand_ty.zigTypeTag(mod);
32547 const ot = operand_ty.zigTypeTag(zcu);
3252732548 if (ot != .ErrorSet and ot != .ErrorUnion) return .bool_true;
3252832549 if (ot == .ErrorSet) return .bool_false;
3252932550 assert(ot == .ErrorUnion);
3253032551
32531 const payload_ty = operand_ty.errorUnionPayload(mod);
32532 if (payload_ty.zigTypeTag(mod) == .NoReturn) {
32552 const payload_ty = operand_ty.errorUnionPayload(zcu);
32553 if (payload_ty.zigTypeTag(zcu) == .NoReturn) {
3253332554 return .bool_false;
3253432555 }
3253532556
......@@ -32588,7 +32609,7 @@ fn analyzeIsNonErrComptimeOnly(
3258832609 // If the error set is empty, we must return a comptime true or false.
3258932610 // However we want to avoid unnecessarily resolving an inferred error set
3259032611 // in case it is already non-empty.
32591 try mod.maybeUnresolveIes(func_index);
32612 try zcu.maybeUnresolveIes(func_index);
3259232613 switch (ip.funcIesResolvedUnordered(func_index)) {
3259332614 .anyerror_type => break :blk,
3259432615 .none => {},
......@@ -32624,10 +32645,10 @@ fn analyzeIsNonErrComptimeOnly(
3262432645 }
3262532646
3262632647 if (maybe_operand_val) |err_union| {
32627 if (err_union.isUndef(mod)) {
32648 if (err_union.isUndef(zcu)) {
3262832649 return pt.undefRef(Type.bool);
3262932650 }
32630 if (err_union.getErrorName(mod) == .none) {
32651 if (err_union.getErrorName(zcu) == .none) {
3263132652 return .bool_true;
3263232653 } else {
3263332654 return .bool_false;
......@@ -32681,12 +32702,12 @@ fn analyzeSlice(
3268132702 by_length: bool,
3268232703) CompileError!Air.Inst.Ref {
3268332704 const pt = sema.pt;
32684 const mod = pt.zcu;
32705 const zcu = pt.zcu;
3268532706 // Slice expressions can operate on a variable whose type is an array. This requires
3268632707 // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer.
3268732708 const ptr_ptr_ty = sema.typeOf(ptr_ptr);
32688 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(mod)) {
32689 .Pointer => ptr_ptr_ty.childType(mod),
32709 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) {
32710 .Pointer => ptr_ptr_ty.childType(zcu),
3269032711 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ptr_ty.fmt(pt)}),
3269132712 };
3269232713
......@@ -32695,20 +32716,20 @@ fn analyzeSlice(
3269532716 var ptr_or_slice = ptr_ptr;
3269632717 var elem_ty: Type = undefined;
3269732718 var ptr_sentinel: ?Value = null;
32698 switch (ptr_ptr_child_ty.zigTypeTag(mod)) {
32719 switch (ptr_ptr_child_ty.zigTypeTag(zcu)) {
3269932720 .Array => {
32700 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
32701 elem_ty = ptr_ptr_child_ty.childType(mod);
32721 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
32722 elem_ty = ptr_ptr_child_ty.childType(zcu);
3270232723 },
32703 .Pointer => switch (ptr_ptr_child_ty.ptrSize(mod)) {
32724 .Pointer => switch (ptr_ptr_child_ty.ptrSize(zcu)) {
3270432725 .One => {
32705 const double_child_ty = ptr_ptr_child_ty.childType(mod);
32726 const double_child_ty = ptr_ptr_child_ty.childType(zcu);
3270632727 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
32707 if (double_child_ty.zigTypeTag(mod) == .Array) {
32708 ptr_sentinel = double_child_ty.sentinel(mod);
32728 if (double_child_ty.zigTypeTag(zcu) == .Array) {
32729 ptr_sentinel = double_child_ty.sentinel(zcu);
3270932730 slice_ty = ptr_ptr_child_ty;
3271032731 array_ty = double_child_ty;
32711 elem_ty = double_child_ty.childType(mod);
32732 elem_ty = double_child_ty.childType(zcu);
3271232733 } else {
3271332734 const bounds_error_message = "slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1]";
3271432735 if (uncasted_end_opt == .none) {
......@@ -32777,7 +32798,7 @@ fn analyzeSlice(
3277732798 .len = 1,
3277832799 .child = double_child_ty.toIntern(),
3277932800 });
32780 const ptr_info = ptr_ptr_child_ty.ptrInfo(mod);
32801 const ptr_info = ptr_ptr_child_ty.ptrInfo(zcu);
3278132802 slice_ty = try pt.ptrType(.{
3278232803 .child = array_ty.toIntern(),
3278332804 .flags = .{
......@@ -32792,35 +32813,35 @@ fn analyzeSlice(
3279232813 }
3279332814 },
3279432815 .Many, .C => {
32795 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
32816 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
3279632817 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
3279732818 slice_ty = ptr_ptr_child_ty;
3279832819 array_ty = ptr_ptr_child_ty;
32799 elem_ty = ptr_ptr_child_ty.childType(mod);
32820 elem_ty = ptr_ptr_child_ty.childType(zcu);
3280032821
32801 if (ptr_ptr_child_ty.ptrSize(mod) == .C) {
32822 if (ptr_ptr_child_ty.ptrSize(zcu) == .C) {
3280232823 if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| {
32803 if (ptr_val.isNull(mod)) {
32824 if (ptr_val.isNull(zcu)) {
3280432825 return sema.fail(block, src, "slice of null pointer", .{});
3280532826 }
3280632827 }
3280732828 }
3280832829 },
3280932830 .Slice => {
32810 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
32831 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
3281132832 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
3281232833 slice_ty = ptr_ptr_child_ty;
3281332834 array_ty = ptr_ptr_child_ty;
32814 elem_ty = ptr_ptr_child_ty.childType(mod);
32835 elem_ty = ptr_ptr_child_ty.childType(zcu);
3281532836 },
3281632837 },
3281732838 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(pt)}),
3281832839 }
3281932840
32820 const ptr = if (slice_ty.isSlice(mod))
32841 const ptr = if (slice_ty.isSlice(zcu))
3282132842 try sema.analyzeSlicePtr(block, ptr_src, ptr_or_slice, slice_ty)
32822 else if (array_ty.zigTypeTag(mod) == .Array) ptr: {
32823 var manyptr_ty_key = mod.intern_pool.indexToKey(slice_ty.toIntern()).ptr_type;
32843 else if (array_ty.zigTypeTag(zcu) == .Array) ptr: {
32844 var manyptr_ty_key = zcu.intern_pool.indexToKey(slice_ty.toIntern()).ptr_type;
3282432845 assert(manyptr_ty_key.child == array_ty.toIntern());
3282532846 assert(manyptr_ty_key.flags.size == .One);
3282632847 manyptr_ty_key.child = elem_ty.toIntern();
......@@ -32838,8 +32859,8 @@ fn analyzeSlice(
3283832859 // we might learn of the length because it is a comptime-known slice value.
3283932860 var end_is_len = uncasted_end_opt == .none;
3284032861 const end = e: {
32841 if (array_ty.zigTypeTag(mod) == .Array) {
32842 const len_val = try pt.intValue(Type.usize, array_ty.arrayLen(mod));
32862 if (array_ty.zigTypeTag(zcu) == .Array) {
32863 const len_val = try pt.intValue(Type.usize, array_ty.arrayLen(zcu));
3284332864
3284432865 if (!end_is_len) {
3284532866 const end = if (by_length) end: {
......@@ -32850,10 +32871,10 @@ fn analyzeSlice(
3285032871 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
3285132872 const len_s_val = try pt.intValue(
3285232873 Type.usize,
32853 array_ty.arrayLenIncludingSentinel(mod),
32874 array_ty.arrayLenIncludingSentinel(zcu),
3285432875 );
3285532876 if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) {
32856 const sentinel_label: []const u8 = if (array_ty.sentinel(mod) != null)
32877 const sentinel_label: []const u8 = if (array_ty.sentinel(zcu) != null)
3285732878 " +1 (sentinel)"
3285832879 else
3285932880 "";
......@@ -32873,7 +32894,7 @@ fn analyzeSlice(
3287332894 // end_is_len is only true if we are NOT using the sentinel
3287432895 // length. For sentinel-length, we don't want the type to
3287532896 // contain the sentinel.
32876 if (end_val.eql(len_val, Type.usize, mod)) {
32897 if (end_val.eql(len_val, Type.usize, zcu)) {
3287732898 end_is_len = true;
3287832899 }
3287932900 }
......@@ -32881,7 +32902,7 @@ fn analyzeSlice(
3288132902 }
3288232903
3288332904 break :e Air.internedToRef(len_val.toIntern());
32884 } else if (slice_ty.isSlice(mod)) {
32905 } else if (slice_ty.isSlice(zcu)) {
3288532906 if (!end_is_len) {
3288632907 const end = if (by_length) end: {
3288732908 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
......@@ -32890,10 +32911,10 @@ fn analyzeSlice(
3289032911 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
3289132912 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
3289232913 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {
32893 if (slice_val.isUndef(mod)) {
32914 if (slice_val.isUndef(zcu)) {
3289432915 return sema.fail(block, src, "slice of undefined", .{});
3289532916 }
32896 const has_sentinel = slice_ty.sentinel(mod) != null;
32917 const has_sentinel = slice_ty.sentinel(zcu) != null;
3289732918 const slice_len = try slice_val.sliceLen(pt);
3289832919 const len_plus_sent = slice_len + @intFromBool(has_sentinel);
3289932920 const slice_len_val_with_sentinel = try pt.intValue(Type.usize, len_plus_sent);
......@@ -32919,7 +32940,7 @@ fn analyzeSlice(
3291932940 // is only true if it equals the length WITHOUT the
3292032941 // sentinel, so we don't add a sentinel type.
3292132942 const slice_len_val = try pt.intValue(Type.usize, slice_len);
32922 if (end_val.eql(slice_len_val, Type.usize, mod)) {
32943 if (end_val.eql(slice_len_val, Type.usize, zcu)) {
3292332944 end_is_len = true;
3292432945 }
3292532946 }
......@@ -32976,8 +32997,8 @@ fn analyzeSlice(
3297632997 checked_start_lte_end = true;
3297732998 if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: {
3297832999 const expected_sentinel = sentinel orelse break :sentinel_check;
32979 const start_int = start_val.getUnsignedInt(pt).?;
32980 const end_int = end_val.getUnsignedInt(pt).?;
33000 const start_int = start_val.toUnsignedInt(zcu);
33001 const end_int = end_val.toUnsignedInt(zcu);
3298133002 const sentinel_index = try sema.usizeCast(block, end_src, end_int - start_int);
3298233003
3298333004 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);
......@@ -33001,7 +33022,7 @@ fn analyzeSlice(
3300133022 ),
3300233023 };
3300333024
33004 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {
33025 if (!actual_sentinel.eql(expected_sentinel, elem_ty, zcu)) {
3300533026 const msg = msg: {
3300633027 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
3300733028 errdefer msg.destroy(sema.gpa);
......@@ -33041,8 +33062,8 @@ fn analyzeSlice(
3304133062 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);
3304233063 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);
3304333064
33044 const new_ptr_ty_info = new_ptr_ty.ptrInfo(mod);
33045 const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(mod) != .C;
33065 const new_ptr_ty_info = new_ptr_ty.ptrInfo(zcu);
33066 const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(zcu) != .C;
3304633067
3304733068 if (opt_new_len_val) |new_len_val| {
3304833069 const new_len_int = try new_len_val.toUnsignedIntSema(pt);
......@@ -33067,17 +33088,17 @@ fn analyzeSlice(
3306733088 const result = try block.addBitCast(return_ty, new_ptr);
3306833089 if (block.wantSafety()) {
3306933090 // requirement: slicing C ptr is non-null
33070 if (ptr_ptr_child_ty.isCPtr(mod)) {
33091 if (ptr_ptr_child_ty.isCPtr(zcu)) {
3307133092 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);
3307233093 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);
3307333094 }
3307433095
3307533096 bounds_check: {
33076 const actual_len = if (array_ty.zigTypeTag(mod) == .Array)
33077 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(mod))
33078 else if (slice_ty.isSlice(mod)) l: {
33097 const actual_len = if (array_ty.zigTypeTag(zcu) == .Array)
33098 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
33099 else if (slice_ty.isSlice(zcu)) l: {
3307933100 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
33080 break :l if (slice_ty.sentinel(mod) == null)
33101 break :l if (slice_ty.sentinel(zcu) == null)
3308133102 slice_len_inst
3308233103 else
3308333104 try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
......@@ -33097,7 +33118,7 @@ fn analyzeSlice(
3309733118 return result;
3309833119 };
3309933120
33100 if (!new_ptr_val.isUndef(mod)) {
33121 if (!new_ptr_val.isUndef(zcu)) {
3310133122 return Air.internedToRef((try pt.getCoerced(new_ptr_val, return_ty)).toIntern());
3310233123 }
3310333124
......@@ -33125,15 +33146,15 @@ fn analyzeSlice(
3312533146 try sema.requireRuntimeBlock(block, src, runtime_src.?);
3312633147 if (block.wantSafety()) {
3312733148 // requirement: slicing C ptr is non-null
33128 if (ptr_ptr_child_ty.isCPtr(mod)) {
33149 if (ptr_ptr_child_ty.isCPtr(zcu)) {
3312933150 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);
3313033151 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);
3313133152 }
3313233153
3313333154 // requirement: end <= len
33134 const opt_len_inst = if (array_ty.zigTypeTag(mod) == .Array)
33135 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(mod))
33136 else if (slice_ty.isSlice(mod)) blk: {
33155 const opt_len_inst = if (array_ty.zigTypeTag(zcu) == .Array)
33156 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
33157 else if (slice_ty.isSlice(zcu)) blk: {
3313733158 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
3313833159 // we don't need to add one for sentinels because the
3313933160 // underlying value data includes the sentinel
......@@ -33141,7 +33162,7 @@ fn analyzeSlice(
3314133162 }
3314233163
3314333164 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
33144 if (slice_ty.sentinel(mod) == null) break :blk slice_len_inst;
33165 if (slice_ty.sentinel(zcu) == null) break :blk slice_len_inst;
3314533166
3314633167 // we have to add one because slice lengths don't include the sentinel
3314733168 break :blk try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
......@@ -33186,16 +33207,16 @@ fn cmpNumeric(
3318633207 rhs_src: LazySrcLoc,
3318733208) CompileError!Air.Inst.Ref {
3318833209 const pt = sema.pt;
33189 const mod = pt.zcu;
33210 const zcu = pt.zcu;
3319033211 const lhs_ty = sema.typeOf(uncasted_lhs);
3319133212 const rhs_ty = sema.typeOf(uncasted_rhs);
3319233213
33193 assert(lhs_ty.isNumeric(mod));
33194 assert(rhs_ty.isNumeric(mod));
33214 assert(lhs_ty.isNumeric(zcu));
33215 assert(rhs_ty.isNumeric(zcu));
3319533216
33196 const lhs_ty_tag = lhs_ty.zigTypeTag(mod);
33197 const rhs_ty_tag = rhs_ty.zigTypeTag(mod);
33198 const target = mod.getTarget();
33217 const lhs_ty_tag = lhs_ty.zigTypeTag(zcu);
33218 const rhs_ty_tag = rhs_ty.zigTypeTag(zcu);
33219 const target = zcu.getTarget();
3319933220
3320033221 // One exception to heterogeneous comparison: comptime_float needs to
3320133222 // coerce to fixed-width float.
......@@ -33214,28 +33235,28 @@ fn cmpNumeric(
3321433235 if (try sema.resolveValue(lhs)) |lhs_val| {
3321533236 if (try sema.resolveValue(rhs)) |rhs_val| {
3321633237 // Compare ints: const vs. undefined (or vice versa)
33217 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) {
33238 if (!lhs_val.isUndef(zcu) and (lhs_ty.isInt(zcu) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(zcu) and rhs_val.isUndef(zcu)) {
3321833239 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
3321933240 return if (res) .bool_true else .bool_false;
3322033241 }
33221 } else if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef(mod)) {
33242 } else if (!rhs_val.isUndef(zcu) and (rhs_ty.isInt(zcu) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(zcu) and lhs_val.isUndef(zcu)) {
3322233243 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
3322333244 return if (res) .bool_true else .bool_false;
3322433245 }
3322533246 }
3322633247
33227 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
33248 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
3322833249 return pt.undefRef(Type.bool);
3322933250 }
33230 if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) {
33251 if (lhs_val.isNan(zcu) or rhs_val.isNan(zcu)) {
3323133252 return if (op == std.math.CompareOperator.neq) .bool_true else .bool_false;
3323233253 }
33233 return if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, pt, .sema))
33254 return if (try Value.compareHeteroSema(lhs_val, op, rhs_val, pt))
3323433255 .bool_true
3323533256 else
3323633257 .bool_false;
3323733258 } else {
33238 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) {
33259 if (!lhs_val.isUndef(zcu) and (lhs_ty.isInt(zcu) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(zcu)) {
3323933260 // Compare ints: const vs. var
3324033261 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
3324133262 return if (res) .bool_true else .bool_false;
......@@ -33245,7 +33266,7 @@ fn cmpNumeric(
3324533266 }
3324633267 } else {
3324733268 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
33248 if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) {
33269 if (!rhs_val.isUndef(zcu) and (rhs_ty.isInt(zcu) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(zcu)) {
3324933270 // Compare ints: var vs. const
3325033271 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
3325133272 return if (res) .bool_true else .bool_false;
......@@ -33301,31 +33322,31 @@ fn cmpNumeric(
3330133322 const lhs_is_signed = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val|
3330233323 !(try lhs_val.compareAllWithZeroSema(.gte, pt))
3330333324 else
33304 (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt(mod));
33325 (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt(zcu));
3330533326 const rhs_is_signed = if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val|
3330633327 !(try rhs_val.compareAllWithZeroSema(.gte, pt))
3330733328 else
33308 (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt(mod));
33329 (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt(zcu));
3330933330 const dest_int_is_signed = lhs_is_signed or rhs_is_signed;
3331033331
3331133332 var dest_float_type: ?Type = null;
3331233333
3331333334 var lhs_bits: usize = undefined;
3331433335 if (try sema.resolveValueResolveLazy(lhs)) |lhs_val| {
33315 if (lhs_val.isUndef(mod))
33336 if (lhs_val.isUndef(zcu))
3331633337 return pt.undefRef(Type.bool);
33317 if (lhs_val.isNan(mod)) switch (op) {
33338 if (lhs_val.isNan(zcu)) switch (op) {
3331833339 .neq => return .bool_true,
3331933340 else => return .bool_false,
3332033341 };
33321 if (lhs_val.isInf(mod)) switch (op) {
33342 if (lhs_val.isInf(zcu)) switch (op) {
3332233343 .neq => return .bool_true,
3332333344 .eq => return .bool_false,
33324 .gt, .gte => return if (lhs_val.isNegativeInf(mod)) .bool_false else .bool_true,
33325 .lt, .lte => return if (lhs_val.isNegativeInf(mod)) .bool_true else .bool_false,
33345 .gt, .gte => return if (lhs_val.isNegativeInf(zcu)) .bool_false else .bool_true,
33346 .lt, .lte => return if (lhs_val.isNegativeInf(zcu)) .bool_true else .bool_false,
3332633347 };
3332733348 if (!rhs_is_signed) {
33328 switch (lhs_val.orderAgainstZero(pt)) {
33349 switch (lhs_val.orderAgainstZero(zcu)) {
3332933350 .gt => {},
3333033351 .eq => switch (op) { // LHS = 0, RHS is unsigned
3333133352 .lte => return .bool_true,
......@@ -33339,7 +33360,7 @@ fn cmpNumeric(
3333933360 }
3334033361 }
3334133362 if (lhs_is_float) {
33342 if (lhs_val.floatHasFraction(mod)) {
33363 if (lhs_val.floatHasFraction(zcu)) {
3334333364 switch (op) {
3334433365 .eq => return .bool_false,
3334533366 .neq => return .bool_true,
......@@ -33347,9 +33368,9 @@ fn cmpNumeric(
3334733368 }
3334833369 }
3334933370
33350 var bigint = try float128IntPartToBigInt(sema.gpa, lhs_val.toFloat(f128, pt));
33371 var bigint = try float128IntPartToBigInt(sema.gpa, lhs_val.toFloat(f128, zcu));
3335133372 defer bigint.deinit();
33352 if (lhs_val.floatHasFraction(mod)) {
33373 if (lhs_val.floatHasFraction(zcu)) {
3335333374 if (lhs_is_signed) {
3335433375 try bigint.addScalar(&bigint, -1);
3335533376 } else {
......@@ -33358,32 +33379,32 @@ fn cmpNumeric(
3335833379 }
3335933380 lhs_bits = bigint.toConst().bitCountTwosComp();
3336033381 } else {
33361 lhs_bits = lhs_val.intBitCountTwosComp(pt);
33382 lhs_bits = lhs_val.intBitCountTwosComp(zcu);
3336233383 }
3336333384 lhs_bits += @intFromBool(!lhs_is_signed and dest_int_is_signed);
3336433385 } else if (lhs_is_float) {
3336533386 dest_float_type = lhs_ty;
3336633387 } else {
33367 const int_info = lhs_ty.intInfo(mod);
33388 const int_info = lhs_ty.intInfo(zcu);
3336833389 lhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);
3336933390 }
3337033391
3337133392 var rhs_bits: usize = undefined;
3337233393 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
33373 if (rhs_val.isUndef(mod))
33394 if (rhs_val.isUndef(zcu))
3337433395 return pt.undefRef(Type.bool);
33375 if (rhs_val.isNan(mod)) switch (op) {
33396 if (rhs_val.isNan(zcu)) switch (op) {
3337633397 .neq => return .bool_true,
3337733398 else => return .bool_false,
3337833399 };
33379 if (rhs_val.isInf(mod)) switch (op) {
33400 if (rhs_val.isInf(zcu)) switch (op) {
3338033401 .neq => return .bool_true,
3338133402 .eq => return .bool_false,
33382 .gt, .gte => return if (rhs_val.isNegativeInf(mod)) .bool_true else .bool_false,
33383 .lt, .lte => return if (rhs_val.isNegativeInf(mod)) .bool_false else .bool_true,
33403 .gt, .gte => return if (rhs_val.isNegativeInf(zcu)) .bool_true else .bool_false,
33404 .lt, .lte => return if (rhs_val.isNegativeInf(zcu)) .bool_false else .bool_true,
3338433405 };
3338533406 if (!lhs_is_signed) {
33386 switch (rhs_val.orderAgainstZero(pt)) {
33407 switch (rhs_val.orderAgainstZero(zcu)) {
3338733408 .gt => {},
3338833409 .eq => switch (op) { // RHS = 0, LHS is unsigned
3338933410 .gte => return .bool_true,
......@@ -33397,7 +33418,7 @@ fn cmpNumeric(
3339733418 }
3339833419 }
3339933420 if (rhs_is_float) {
33400 if (rhs_val.floatHasFraction(mod)) {
33421 if (rhs_val.floatHasFraction(zcu)) {
3340133422 switch (op) {
3340233423 .eq => return .bool_false,
3340333424 .neq => return .bool_true,
......@@ -33405,9 +33426,9 @@ fn cmpNumeric(
3340533426 }
3340633427 }
3340733428
33408 var bigint = try float128IntPartToBigInt(sema.gpa, rhs_val.toFloat(f128, pt));
33429 var bigint = try float128IntPartToBigInt(sema.gpa, rhs_val.toFloat(f128, zcu));
3340933430 defer bigint.deinit();
33410 if (rhs_val.floatHasFraction(mod)) {
33431 if (rhs_val.floatHasFraction(zcu)) {
3341133432 if (rhs_is_signed) {
3341233433 try bigint.addScalar(&bigint, -1);
3341333434 } else {
......@@ -33416,13 +33437,13 @@ fn cmpNumeric(
3341633437 }
3341733438 rhs_bits = bigint.toConst().bitCountTwosComp();
3341833439 } else {
33419 rhs_bits = rhs_val.intBitCountTwosComp(pt);
33440 rhs_bits = rhs_val.intBitCountTwosComp(zcu);
3342033441 }
3342133442 rhs_bits += @intFromBool(!rhs_is_signed and dest_int_is_signed);
3342233443 } else if (rhs_is_float) {
3342333444 dest_float_type = rhs_ty;
3342433445 } else {
33425 const int_info = rhs_ty.intInfo(mod);
33446 const int_info = rhs_ty.intInfo(zcu);
3342633447 rhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);
3342733448 }
3342833449
......@@ -33450,9 +33471,9 @@ fn compareIntsOnlyPossibleResult(
3345033471 rhs_ty: Type,
3345133472) Allocator.Error!?bool {
3345233473 const pt = sema.pt;
33453 const mod = pt.zcu;
33454 const rhs_info = rhs_ty.intInfo(mod);
33455 const vs_zero = lhs_val.orderAgainstZeroAdvanced(pt, .sema) catch unreachable;
33474 const zcu = pt.zcu;
33475 const rhs_info = rhs_ty.intInfo(zcu);
33476 const vs_zero = lhs_val.orderAgainstZeroSema(pt) catch unreachable;
3345633477 const is_zero = vs_zero == .eq;
3345733478 const is_negative = vs_zero == .lt;
3345833479 const is_positive = vs_zero == .gt;
......@@ -33484,7 +33505,7 @@ fn compareIntsOnlyPossibleResult(
3348433505 };
3348533506
3348633507 const sign_adj = @intFromBool(!is_negative and rhs_info.signedness == .signed);
33487 const req_bits = lhs_val.intBitCountTwosComp(pt) + sign_adj;
33508 const req_bits = lhs_val.intBitCountTwosComp(zcu) + sign_adj;
3348833509
3348933510 // No sized type can have more than 65535 bits.
3349033511 // The RHS type operand is either a runtime value or sized (but undefined) constant.
......@@ -33515,7 +33536,7 @@ fn compareIntsOnlyPossibleResult(
3351533536 if (is_negative) .signed else .unsigned,
3351633537 @intCast(req_bits),
3351733538 );
33518 const pop_count = lhs_val.popCount(ty, pt);
33539 const pop_count = lhs_val.popCount(ty, zcu);
3351933540
3352033541 if (is_negative) {
3352133542 break :edge .{ pop_count == 1, false };
......@@ -33546,11 +33567,11 @@ fn cmpVector(
3354633567 rhs_src: LazySrcLoc,
3354733568) CompileError!Air.Inst.Ref {
3354833569 const pt = sema.pt;
33549 const mod = pt.zcu;
33570 const zcu = pt.zcu;
3355033571 const lhs_ty = sema.typeOf(lhs);
3355133572 const rhs_ty = sema.typeOf(rhs);
33552 assert(lhs_ty.zigTypeTag(mod) == .Vector);
33553 assert(rhs_ty.zigTypeTag(mod) == .Vector);
33573 assert(lhs_ty.zigTypeTag(zcu) == .Vector);
33574 assert(rhs_ty.zigTypeTag(zcu) == .Vector);
3355433575 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
3355533576
3355633577 const resolved_ty = try sema.resolvePeerTypes(block, src, &.{ lhs, rhs }, .{ .override = &.{ lhs_src, rhs_src } });
......@@ -33558,14 +33579,14 @@ fn cmpVector(
3355833579 const casted_rhs = try sema.coerce(block, resolved_ty, rhs, rhs_src);
3355933580
3356033581 const result_ty = try pt.vectorType(.{
33561 .len = lhs_ty.vectorLen(mod),
33582 .len = lhs_ty.vectorLen(zcu),
3356233583 .child = .bool_type,
3356333584 });
3356433585
3356533586 const runtime_src: LazySrcLoc = src: {
3356633587 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
3356733588 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
33568 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
33589 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
3356933590 return pt.undefRef(result_ty);
3357033591 }
3357133592 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty);
......@@ -33608,8 +33629,8 @@ fn wrapErrorUnionPayload(
3360833629 inst_src: LazySrcLoc,
3360933630) !Air.Inst.Ref {
3361033631 const pt = sema.pt;
33611 const mod = pt.zcu;
33612 const dest_payload_ty = dest_ty.errorUnionPayload(mod);
33632 const zcu = pt.zcu;
33633 const dest_payload_ty = dest_ty.errorUnionPayload(zcu);
3361333634 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
3361433635 if (try sema.resolveValue(coerced)) |val| {
3361533636 return Air.internedToRef((try pt.intern(.{ .error_union = .{
......@@ -33629,12 +33650,12 @@ fn wrapErrorUnionSet(
3362933650 inst_src: LazySrcLoc,
3363033651) !Air.Inst.Ref {
3363133652 const pt = sema.pt;
33632 const mod = pt.zcu;
33633 const ip = &mod.intern_pool;
33653 const zcu = pt.zcu;
33654 const ip = &zcu.intern_pool;
3363433655 const inst_ty = sema.typeOf(inst);
33635 const dest_err_set_ty = dest_ty.errorUnionSet(mod);
33656 const dest_err_set_ty = dest_ty.errorUnionSet(zcu);
3363633657 if (try sema.resolveValue(inst)) |val| {
33637 const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
33658 const expected_name = zcu.intern_pool.indexToKey(val.toIntern()).err.name;
3363833659 switch (dest_err_set_ty.toIntern()) {
3363933660 .anyerror_type => {},
3364033661 .adhoc_inferred_error_set_type => ok: {
......@@ -33658,7 +33679,7 @@ fn wrapErrorUnionSet(
3365833679 .inferred_error_set_type => |func_index| ok: {
3365933680 // We carefully do this in an order that avoids unnecessarily
3366033681 // resolving the destination error set type.
33661 try mod.maybeUnresolveIes(func_index);
33682 try zcu.maybeUnresolveIes(func_index);
3366233683 switch (ip.funcIesResolvedUnordered(func_index)) {
3366333684 .anyerror_type => break :ok,
3366433685 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
......@@ -33693,13 +33714,13 @@ fn unionToTag(
3369333714 un_src: LazySrcLoc,
3369433715) !Air.Inst.Ref {
3369533716 const pt = sema.pt;
33696 const mod = pt.zcu;
33717 const zcu = pt.zcu;
3369733718 if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| {
3369833719 return Air.internedToRef(opv.toIntern());
3369933720 }
3370033721 if (try sema.resolveValue(un)) |un_val| {
33701 const tag_val = un_val.unionTag(mod).?;
33702 if (tag_val.isUndef(mod))
33722 const tag_val = un_val.unionTag(zcu).?;
33723 if (tag_val.isUndef(zcu))
3370333724 return try pt.undefRef(enum_ty);
3370433725 return Air.internedToRef(tag_val.toIntern());
3370533726 }
......@@ -33861,8 +33882,8 @@ const PeerResolveStrategy = enum {
3386133882 return strat;
3386233883 }
3386333884
33864 fn select(ty: Type, mod: *Module) PeerResolveStrategy {
33865 return switch (ty.zigTypeTag(mod)) {
33885 fn select(ty: Type, zcu: *Zcu) PeerResolveStrategy {
33886 return switch (ty.zigTypeTag(zcu)) {
3386633887 .Type, .Void, .Bool, .Opaque, .Frame, .AnyFrame => .exact,
3386733888 .NoReturn, .Undefined => .unknown,
3386833889 .Null => .nullable,
......@@ -33870,14 +33891,14 @@ const PeerResolveStrategy = enum {
3387033891 .Int => .fixed_int,
3387133892 .ComptimeFloat => .comptime_float,
3387233893 .Float => .fixed_float,
33873 .Pointer => if (ty.ptrInfo(mod).flags.size == .C) .c_ptr else .ptr,
33894 .Pointer => if (ty.ptrInfo(zcu).flags.size == .C) .c_ptr else .ptr,
3387433895 .Array => .array,
3387533896 .Vector => .vector,
3387633897 .Optional => .optional,
3387733898 .ErrorSet => .error_set,
3387833899 .ErrorUnion => .error_union,
3387933900 .EnumLiteral, .Enum, .Union => .enum_or_union,
33880 .Struct => if (ty.isTupleOrAnonStruct(mod)) .coercible_struct else .exact,
33901 .Struct => if (ty.isTupleOrAnonStruct(zcu)) .coercible_struct else .exact,
3388133902 .Fn => .func,
3388233903 };
3388333904 }
......@@ -33933,10 +33954,10 @@ const PeerResolveResult = union(enum) {
3393333954 src: LazySrcLoc,
3393433955 instructions: []const Air.Inst.Ref,
3393533956 candidate_srcs: PeerTypeCandidateSrc,
33936 ) !*Module.ErrorMsg {
33957 ) !*Zcu.ErrorMsg {
3393733958 const pt = sema.pt;
3393833959
33939 var opt_msg: ?*Module.ErrorMsg = null;
33960 var opt_msg: ?*Zcu.ErrorMsg = null;
3394033961 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
3394133962
3394233963 // If we mention fields we'll want to include field types, so put peer types in a buffer
......@@ -34053,14 +34074,14 @@ fn resolvePeerTypesInner(
3405334074 peer_vals: []?Value,
3405434075) !PeerResolveResult {
3405534076 const pt = sema.pt;
34056 const mod = pt.zcu;
34057 const ip = &mod.intern_pool;
34077 const zcu = pt.zcu;
34078 const ip = &zcu.intern_pool;
3405834079
3405934080 var strat_reason: usize = 0;
3406034081 var s: PeerResolveStrategy = .unknown;
3406134082 for (peer_tys, 0..) |opt_ty, i| {
3406234083 const ty = opt_ty orelse continue;
34063 s = s.merge(PeerResolveStrategy.select(ty, mod), &strat_reason, i);
34084 s = s.merge(PeerResolveStrategy.select(ty, zcu), &strat_reason, i);
3406434085 }
3406534086
3406634087 if (s == .unknown) {
......@@ -34070,14 +34091,14 @@ fn resolvePeerTypesInner(
3407034091 // There was something other than noreturn and undefined, so we can ignore those peers
3407134092 for (peer_tys) |*ty_ptr| {
3407234093 const ty = ty_ptr.* orelse continue;
34073 switch (ty.zigTypeTag(mod)) {
34094 switch (ty.zigTypeTag(zcu)) {
3407434095 .NoReturn, .Undefined => ty_ptr.* = null,
3407534096 else => {},
3407634097 }
3407734098 }
3407834099 }
3407934100
34080 const target = mod.getTarget();
34101 const target = zcu.getTarget();
3408134102
3408234103 switch (s) {
3408334104 .unknown => unreachable,
......@@ -34086,7 +34107,7 @@ fn resolvePeerTypesInner(
3408634107 var final_set: ?Type = null;
3408734108 for (peer_tys, 0..) |opt_ty, i| {
3408834109 const ty = opt_ty orelse continue;
34089 if (ty.zigTypeTag(mod) != .ErrorSet) return .{ .conflict = .{
34110 if (ty.zigTypeTag(zcu) != .ErrorSet) return .{ .conflict = .{
3409034111 .peer_idx_a = strat_reason,
3409134112 .peer_idx_b = i,
3409234113 } };
......@@ -34103,15 +34124,15 @@ fn resolvePeerTypesInner(
3410334124 var final_set: ?Type = null;
3410434125 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {
3410534126 const ty = ty_ptr.* orelse continue;
34106 const set_ty = switch (ty.zigTypeTag(mod)) {
34127 const set_ty = switch (ty.zigTypeTag(zcu)) {
3410734128 .ErrorSet => blk: {
3410834129 ty_ptr.* = null; // no payload to decide on
3410934130 val_ptr.* = null;
3411034131 break :blk ty;
3411134132 },
3411234133 .ErrorUnion => blk: {
34113 const set_ty = ty.errorUnionSet(mod);
34114 ty_ptr.* = ty.errorUnionPayload(mod);
34134 const set_ty = ty.errorUnionSet(zcu);
34135 ty_ptr.* = ty.errorUnionPayload(zcu);
3411534136 if (val_ptr.*) |eu_val| switch (ip.indexToKey(eu_val.toIntern())) {
3411634137 .error_union => |eu| switch (eu.val) {
3411734138 .payload => |payload_ip| val_ptr.* = Value.fromInterned(payload_ip),
......@@ -34146,7 +34167,7 @@ fn resolvePeerTypesInner(
3414634167 .nullable => {
3414734168 for (peer_tys, 0..) |opt_ty, i| {
3414834169 const ty = opt_ty orelse continue;
34149 if (!ty.eql(Type.null, mod)) return .{ .conflict = .{
34170 if (!ty.eql(Type.null, zcu)) return .{ .conflict = .{
3415034171 .peer_idx_a = strat_reason,
3415134172 .peer_idx_b = i,
3415234173 } };
......@@ -34157,14 +34178,14 @@ fn resolvePeerTypesInner(
3415734178 .optional => {
3415834179 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {
3415934180 const ty = ty_ptr.* orelse continue;
34160 switch (ty.zigTypeTag(mod)) {
34181 switch (ty.zigTypeTag(zcu)) {
3416134182 .Null => {
3416234183 ty_ptr.* = null;
3416334184 val_ptr.* = null;
3416434185 },
3416534186 .Optional => {
34166 ty_ptr.* = ty.optionalChild(mod);
34167 if (val_ptr.*) |opt_val| val_ptr.* = if (!opt_val.isUndef(mod)) opt_val.optionalValue(mod) else null;
34187 ty_ptr.* = ty.optionalChild(zcu);
34188 if (val_ptr.*) |opt_val| val_ptr.* = if (!opt_val.isUndef(zcu)) opt_val.optionalValue(zcu) else null;
3416834189 },
3416934190 else => {},
3417034191 }
......@@ -34195,7 +34216,7 @@ fn resolvePeerTypesInner(
3419534216 for (peer_tys, 0..) |*ty_ptr, i| {
3419634217 const ty = ty_ptr.* orelse continue;
3419734218
34198 if (!ty.isArrayOrVector(mod)) {
34219 if (!ty.isArrayOrVector(zcu)) {
3419934220 // We allow tuples of the correct length. We won't validate their elem type, since the elements can be coerced.
3420034221 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{
3420134222 .peer_idx_a = strat_reason,
......@@ -34220,29 +34241,29 @@ fn resolvePeerTypesInner(
3422034241 const first_arr_idx = opt_first_arr_idx orelse {
3422134242 if (opt_first_idx == null) {
3422234243 opt_first_idx = i;
34223 len = ty.arrayLen(mod);
34224 sentinel = ty.sentinel(mod);
34244 len = ty.arrayLen(zcu);
34245 sentinel = ty.sentinel(zcu);
3422534246 }
3422634247 opt_first_arr_idx = i;
34227 elem_ty = ty.childType(mod);
34248 elem_ty = ty.childType(zcu);
3422834249 continue;
3422934250 };
3423034251
34231 if (ty.arrayLen(mod) != len) return .{ .conflict = .{
34252 if (ty.arrayLen(zcu) != len) return .{ .conflict = .{
3423234253 .peer_idx_a = first_arr_idx,
3423334254 .peer_idx_b = i,
3423434255 } };
3423534256
34236 const peer_elem_ty = ty.childType(mod);
34237 if (!peer_elem_ty.eql(elem_ty, mod)) coerce: {
34257 const peer_elem_ty = ty.childType(zcu);
34258 if (!peer_elem_ty.eql(elem_ty, zcu)) coerce: {
3423834259 const peer_elem_coerces_to_elem =
34239 try sema.coerceInMemoryAllowed(block, elem_ty, peer_elem_ty, false, mod.getTarget(), src, src, null);
34260 try sema.coerceInMemoryAllowed(block, elem_ty, peer_elem_ty, false, zcu.getTarget(), src, src, null);
3424034261 if (peer_elem_coerces_to_elem == .ok) {
3424134262 break :coerce;
3424234263 }
3424334264
3424434265 const elem_coerces_to_peer_elem =
34245 try sema.coerceInMemoryAllowed(block, peer_elem_ty, elem_ty, false, mod.getTarget(), src, src, null);
34266 try sema.coerceInMemoryAllowed(block, peer_elem_ty, elem_ty, false, zcu.getTarget(), src, src, null);
3424634267 if (elem_coerces_to_peer_elem == .ok) {
3424734268 elem_ty = peer_elem_ty;
3424834269 break :coerce;
......@@ -34255,8 +34276,8 @@ fn resolvePeerTypesInner(
3425534276 }
3425634277
3425734278 if (sentinel) |cur_sent| {
34258 if (ty.sentinel(mod)) |peer_sent| {
34259 if (!peer_sent.eql(cur_sent, elem_ty, mod)) sentinel = null;
34279 if (ty.sentinel(zcu)) |peer_sent| {
34280 if (!peer_sent.eql(cur_sent, elem_ty, zcu)) sentinel = null;
3426034281 } else {
3426134282 sentinel = null;
3426234283 }
......@@ -34279,7 +34300,7 @@ fn resolvePeerTypesInner(
3427934300 for (peer_tys, peer_vals, 0..) |*ty_ptr, *val_ptr, i| {
3428034301 const ty = ty_ptr.* orelse continue;
3428134302
34282 if (!ty.isArrayOrVector(mod)) {
34303 if (!ty.isArrayOrVector(zcu)) {
3428334304 // Allow tuples of the correct length
3428434305 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{
3428534306 .peer_idx_a = strat_reason,
......@@ -34305,16 +34326,16 @@ fn resolvePeerTypesInner(
3430534326 }
3430634327
3430734328 if (len) |expect_len| {
34308 if (ty.arrayLen(mod) != expect_len) return .{ .conflict = .{
34329 if (ty.arrayLen(zcu) != expect_len) return .{ .conflict = .{
3430934330 .peer_idx_a = first_idx,
3431034331 .peer_idx_b = i,
3431134332 } };
3431234333 } else {
34313 len = ty.arrayLen(mod);
34334 len = ty.arrayLen(zcu);
3431434335 first_idx = i;
3431534336 }
3431634337
34317 ty_ptr.* = ty.childType(mod);
34338 ty_ptr.* = ty.childType(zcu);
3431834339 val_ptr.* = null; // multiple child vals, so we can't easily use them in PTR
3431934340 }
3432034341
......@@ -34339,7 +34360,7 @@ fn resolvePeerTypesInner(
3433934360 var first_idx: usize = undefined;
3434034361 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {
3434134362 const ty = opt_ty orelse continue;
34342 switch (ty.zigTypeTag(mod)) {
34363 switch (ty.zigTypeTag(zcu)) {
3434334364 .ComptimeInt => continue, // comptime-known integers can always coerce to C pointers
3434434365 .Int => {
3434534366 if (opt_val != null) {
......@@ -34348,7 +34369,7 @@ fn resolvePeerTypesInner(
3434834369 } else {
3434934370 // Runtime-known, so check if the type is no bigger than a usize
3435034371 const ptr_bits = target.ptrBitWidth();
34351 const bits = ty.intInfo(mod).bits;
34372 const bits = ty.intInfo(zcu).bits;
3435234373 if (bits <= ptr_bits) continue;
3435334374 }
3435434375 },
......@@ -34356,13 +34377,13 @@ fn resolvePeerTypesInner(
3435634377 else => {},
3435734378 }
3435834379
34359 if (!ty.isPtrAtRuntime(mod)) return .{ .conflict = .{
34380 if (!ty.isPtrAtRuntime(zcu)) return .{ .conflict = .{
3436034381 .peer_idx_a = strat_reason,
3436134382 .peer_idx_b = i,
3436234383 } };
3436334384
3436434385 // Goes through optionals
34365 const peer_info = ty.ptrInfo(mod);
34386 const peer_info = ty.ptrInfo(zcu);
3436634387
3436734388 var ptr_info = opt_ptr_info orelse {
3436834389 opt_ptr_info = peer_info;
......@@ -34391,17 +34412,17 @@ fn resolvePeerTypesInner(
3439134412 ptr_info.sentinel = .none;
3439234413 }
3439334414
34394 // Note that the align can be always non-zero; Module.ptrType will canonicalize it
34415 // Note that the align can be always non-zero; Zcu.ptrType will canonicalize it
3439534416 ptr_info.flags.alignment = InternPool.Alignment.min(
3439634417 if (ptr_info.flags.alignment != .none)
3439734418 ptr_info.flags.alignment
3439834419 else
34399 Type.fromInterned(ptr_info.child).abiAlignment(pt),
34420 Type.fromInterned(ptr_info.child).abiAlignment(zcu),
3440034421
3440134422 if (peer_info.flags.alignment != .none)
3440234423 peer_info.flags.alignment
3440334424 else
34404 Type.fromInterned(peer_info.child).abiAlignment(pt),
34425 Type.fromInterned(peer_info.child).abiAlignment(zcu),
3440534426 );
3440634427 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
3440734428 return .{ .conflict = .{
......@@ -34438,8 +34459,8 @@ fn resolvePeerTypesInner(
3443834459
3443934460 for (peer_tys, 0..) |opt_ty, i| {
3444034461 const ty = opt_ty orelse continue;
34441 const peer_info: InternPool.Key.PtrType = switch (ty.zigTypeTag(mod)) {
34442 .Pointer => ty.ptrInfo(mod),
34462 const peer_info: InternPool.Key.PtrType = switch (ty.zigTypeTag(zcu)) {
34463 .Pointer => ty.ptrInfo(zcu),
3444334464 .Fn => .{
3444434465 .child = ty.toIntern(),
3444534466 .flags = .{
......@@ -34480,12 +34501,12 @@ fn resolvePeerTypesInner(
3448034501 if (ptr_info.flags.alignment != .none)
3448134502 ptr_info.flags.alignment
3448234503 else
34483 try sema.typeAbiAlignment(Type.fromInterned(ptr_info.child)),
34504 try Type.fromInterned(ptr_info.child).abiAlignmentSema(pt),
3448434505
3448534506 if (peer_info.flags.alignment != .none)
3448634507 peer_info.flags.alignment
3448734508 else
34488 try sema.typeAbiAlignment(Type.fromInterned(peer_info.child)),
34509 try Type.fromInterned(peer_info.child).abiAlignmentSema(pt),
3448934510 );
3449034511
3449134512 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
......@@ -34747,7 +34768,7 @@ fn resolvePeerTypesInner(
3474734768 first_idx = i;
3474834769 continue;
3474934770 };
34750 if (ty.zigTypeTag(mod) != .Fn) return .{ .conflict = .{
34771 if (ty.zigTypeTag(zcu) != .Fn) return .{ .conflict = .{
3475134772 .peer_idx_a = strat_reason,
3475234773 .peer_idx_b = i,
3475334774 } };
......@@ -34775,7 +34796,7 @@ fn resolvePeerTypesInner(
3477534796
3477634797 for (peer_tys, 0..) |opt_ty, i| {
3477734798 const ty = opt_ty orelse continue;
34778 switch (ty.zigTypeTag(mod)) {
34799 switch (ty.zigTypeTag(zcu)) {
3477934800 .EnumLiteral, .Enum, .Union => {},
3478034801 else => return .{ .conflict = .{
3478134802 .peer_idx_a = strat_reason,
......@@ -34794,32 +34815,32 @@ fn resolvePeerTypesInner(
3479434815 .peer_idx_b = i,
3479534816 } };
3479634817
34797 switch (cur_ty.zigTypeTag(mod)) {
34818 switch (cur_ty.zigTypeTag(zcu)) {
3479834819 .EnumLiteral => {
3479934820 opt_cur_ty = ty;
3480034821 cur_ty_idx = i;
3480134822 },
34802 .Enum => switch (ty.zigTypeTag(mod)) {
34823 .Enum => switch (ty.zigTypeTag(zcu)) {
3480334824 .EnumLiteral => {},
3480434825 .Enum => {
34805 if (!ty.eql(cur_ty, mod)) return generic_err;
34826 if (!ty.eql(cur_ty, zcu)) return generic_err;
3480634827 },
3480734828 .Union => {
34808 const tag_ty = ty.unionTagTypeHypothetical(mod);
34809 if (!tag_ty.eql(cur_ty, mod)) return generic_err;
34829 const tag_ty = ty.unionTagTypeHypothetical(zcu);
34830 if (!tag_ty.eql(cur_ty, zcu)) return generic_err;
3481034831 opt_cur_ty = ty;
3481134832 cur_ty_idx = i;
3481234833 },
3481334834 else => unreachable,
3481434835 },
34815 .Union => switch (ty.zigTypeTag(mod)) {
34836 .Union => switch (ty.zigTypeTag(zcu)) {
3481634837 .EnumLiteral => {},
3481734838 .Enum => {
34818 const cur_tag_ty = cur_ty.unionTagTypeHypothetical(mod);
34819 if (!ty.eql(cur_tag_ty, mod)) return generic_err;
34839 const cur_tag_ty = cur_ty.unionTagTypeHypothetical(zcu);
34840 if (!ty.eql(cur_tag_ty, zcu)) return generic_err;
3482034841 },
3482134842 .Union => {
34822 if (!ty.eql(cur_ty, mod)) return generic_err;
34843 if (!ty.eql(cur_ty, zcu)) return generic_err;
3482334844 },
3482434845 else => unreachable,
3482534846 },
......@@ -34832,7 +34853,7 @@ fn resolvePeerTypesInner(
3483234853 .comptime_int => {
3483334854 for (peer_tys, 0..) |opt_ty, i| {
3483434855 const ty = opt_ty orelse continue;
34835 switch (ty.zigTypeTag(mod)) {
34856 switch (ty.zigTypeTag(zcu)) {
3483634857 .ComptimeInt => {},
3483734858 else => return .{ .conflict = .{
3483834859 .peer_idx_a = strat_reason,
......@@ -34846,7 +34867,7 @@ fn resolvePeerTypesInner(
3484634867 .comptime_float => {
3484734868 for (peer_tys, 0..) |opt_ty, i| {
3484834869 const ty = opt_ty orelse continue;
34849 switch (ty.zigTypeTag(mod)) {
34870 switch (ty.zigTypeTag(zcu)) {
3485034871 .ComptimeInt, .ComptimeFloat => {},
3485134872 else => return .{ .conflict = .{
3485234873 .peer_idx_a = strat_reason,
......@@ -34868,11 +34889,11 @@ fn resolvePeerTypesInner(
3486834889 const ty = opt_ty orelse continue;
3486934890 const opt_val = ptr_opt_val.*;
3487034891
34871 const peer_tag = ty.zigTypeTag(mod);
34892 const peer_tag = ty.zigTypeTag(zcu);
3487234893 switch (peer_tag) {
3487334894 .ComptimeInt => {
3487434895 // If the value is undefined, we can't refine to a fixed-width int
34875 if (opt_val == null or opt_val.?.isUndef(mod)) return .{ .conflict = .{
34896 if (opt_val == null or opt_val.?.isUndef(zcu)) return .{ .conflict = .{
3487634897 .peer_idx_a = strat_reason,
3487734898 .peer_idx_b = i,
3487834899 } };
......@@ -34889,7 +34910,7 @@ fn resolvePeerTypesInner(
3488934910
3489034911 if (opt_val != null) any_comptime_known = true;
3489134912
34892 const info = ty.intInfo(mod);
34913 const info = ty.intInfo(zcu);
3489334914
3489434915 const idx_ptr = switch (info.signedness) {
3489534916 .unsigned => &idx_unsigned,
......@@ -34901,7 +34922,7 @@ fn resolvePeerTypesInner(
3490134922 continue;
3490234923 };
3490334924
34904 const cur_info = peer_tys[largest_idx].?.intInfo(mod);
34925 const cur_info = peer_tys[largest_idx].?.intInfo(zcu);
3490534926 if (info.bits > cur_info.bits) {
3490634927 idx_ptr.* = i;
3490734928 }
......@@ -34915,8 +34936,8 @@ fn resolvePeerTypesInner(
3491534936 return .{ .success = peer_tys[idx_signed.?].? };
3491634937 }
3491734938
34918 const unsigned_info = peer_tys[idx_unsigned.?].?.intInfo(mod);
34919 const signed_info = peer_tys[idx_signed.?].?.intInfo(mod);
34939 const unsigned_info = peer_tys[idx_unsigned.?].?.intInfo(zcu);
34940 const signed_info = peer_tys[idx_signed.?].?.intInfo(zcu);
3492034941 if (signed_info.bits > unsigned_info.bits) {
3492134942 return .{ .success = peer_tys[idx_signed.?].? };
3492234943 }
......@@ -34948,7 +34969,7 @@ fn resolvePeerTypesInner(
3494834969
3494934970 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {
3495034971 const ty = opt_ty orelse continue;
34951 switch (ty.zigTypeTag(mod)) {
34972 switch (ty.zigTypeTag(zcu)) {
3495234973 .ComptimeFloat, .ComptimeInt => {},
3495334974 .Int => {
3495434975 if (opt_val == null) return .{ .conflict = .{
......@@ -34958,7 +34979,7 @@ fn resolvePeerTypesInner(
3495834979 },
3495934980 .Float => {
3496034981 if (opt_cur_ty) |cur_ty| {
34961 if (cur_ty.eql(ty, mod)) continue;
34982 if (cur_ty.eql(ty, zcu)) continue;
3496234983 // Recreate the type so we eliminate any c_longdouble
3496334984 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));
3496434985 opt_cur_ty = switch (bits) {
......@@ -34997,7 +35018,7 @@ fn resolvePeerTypesInner(
3499735018 for (peer_tys, 0..) |opt_ty, i| {
3499835019 const ty = opt_ty orelse continue;
3499935020
35000 if (!ty.isTupleOrAnonStruct(mod)) {
35021 if (!ty.isTupleOrAnonStruct(zcu)) {
3500135022 return .{ .conflict = .{
3500235023 .peer_idx_a = strat_reason,
3500335024 .peer_idx_b = i,
......@@ -35006,8 +35027,8 @@ fn resolvePeerTypesInner(
3500635027
3500735028 const first_idx = opt_first_idx orelse {
3500835029 opt_first_idx = i;
35009 is_tuple = ty.isTuple(mod);
35010 field_count = ty.structFieldCount(mod);
35030 is_tuple = ty.isTuple(zcu);
35031 field_count = ty.structFieldCount(zcu);
3501135032 if (!is_tuple) {
3501235033 const names = ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip);
3501335034 field_names = try sema.arena.dupe(InternPool.NullTerminatedString, names);
......@@ -35015,7 +35036,7 @@ fn resolvePeerTypesInner(
3501535036 continue;
3501635037 };
3501735038
35018 if (ty.isTuple(mod) != is_tuple or ty.structFieldCount(mod) != field_count) {
35039 if (ty.isTuple(zcu) != is_tuple or ty.structFieldCount(zcu) != field_count) {
3501935040 return .{ .conflict = .{
3502035041 .peer_idx_a = first_idx,
3502135042 .peer_idx_b = i,
......@@ -35025,7 +35046,7 @@ fn resolvePeerTypesInner(
3502535046 if (!is_tuple) {
3502635047 for (field_names, 0..) |expected, field_index_usize| {
3502735048 const field_index: u32 = @intCast(field_index_usize);
35028 const actual = ty.structFieldName(field_index, mod).unwrap().?;
35049 const actual = ty.structFieldName(field_index, zcu).unwrap().?;
3502935050 if (actual == expected) continue;
3503035051 return .{ .conflict = .{
3503135052 .peer_idx_a = first_idx,
......@@ -35052,7 +35073,7 @@ fn resolvePeerTypesInner(
3505235073 peer_field_val.* = null;
3505335074 continue;
3505435075 };
35055 peer_field_ty.* = ty.structFieldType(field_index, mod);
35076 peer_field_ty.* = ty.structFieldType(field_index, zcu);
3505635077 peer_field_val.* = if (opt_val) |val| try val.fieldValue(pt, field_index) else null;
3505735078 }
3505835079
......@@ -35074,7 +35095,7 @@ fn resolvePeerTypesInner(
3507435095 // Already-resolved types won't be referenced by the error so it's fine
3507535096 // to leave them undefined.
3507635097 const ty = opt_ty orelse continue;
35077 peer_field_ty.* = ty.structFieldType(field_index, mod);
35098 peer_field_ty.* = ty.structFieldType(field_index, zcu);
3507835099 }
3507935100
3508035101 return .{ .field_error = .{
......@@ -35111,7 +35132,7 @@ fn resolvePeerTypesInner(
3511135132 comptime_val = coerced_val;
3511235133 continue;
3511335134 };
35114 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), mod)) {
35135 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), zcu)) {
3511535136 comptime_val = null;
3511635137 break;
3511735138 }
......@@ -35120,7 +35141,7 @@ fn resolvePeerTypesInner(
3512035141 field_val.* = if (comptime_val) |v| v.toIntern() else .none;
3512135142 }
3512235143
35123 const final_ty = try ip.getAnonStructType(mod.gpa, pt.tid, .{
35144 const final_ty = try ip.getAnonStructType(zcu.gpa, pt.tid, .{
3512435145 .types = field_types,
3512535146 .names = if (is_tuple) &.{} else field_names,
3512635147 .values = field_vals,
......@@ -35135,7 +35156,7 @@ fn resolvePeerTypesInner(
3513535156 for (peer_tys, 0..) |opt_ty, i| {
3513635157 const ty = opt_ty orelse continue;
3513735158 if (expect_ty) |expect| {
35138 if (!ty.eql(expect, mod)) return .{ .conflict = .{
35159 if (!ty.eql(expect, zcu)) return .{ .conflict = .{
3513935160 .peer_idx_a = first_idx,
3514035161 .peer_idx_b = i,
3514135162 } };
......@@ -35186,22 +35207,22 @@ const ArrayLike = struct {
3518635207};
3518735208fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3518835209 const pt = sema.pt;
35189 const mod = pt.zcu;
35190 return switch (ty.zigTypeTag(mod)) {
35210 const zcu = pt.zcu;
35211 return switch (ty.zigTypeTag(zcu)) {
3519135212 .Array => .{
35192 .len = ty.arrayLen(mod),
35193 .elem_ty = ty.childType(mod),
35213 .len = ty.arrayLen(zcu),
35214 .elem_ty = ty.childType(zcu),
3519435215 },
3519535216 .Struct => {
35196 const field_count = ty.structFieldCount(mod);
35217 const field_count = ty.structFieldCount(zcu);
3519735218 if (field_count == 0) return .{
3519835219 .len = 0,
3519935220 .elem_ty = Type.noreturn,
3520035221 };
35201 if (!ty.isTuple(mod)) return null;
35202 const elem_ty = ty.structFieldType(0, mod);
35222 if (!ty.isTuple(zcu)) return null;
35223 const elem_ty = ty.structFieldType(0, zcu);
3520335224 for (1..field_count) |i| {
35204 if (!ty.structFieldType(i, mod).eql(elem_ty, mod)) {
35225 if (!ty.structFieldType(i, zcu).eql(elem_ty, zcu)) {
3520535226 return null;
3520635227 }
3520735228 }
......@@ -35216,8 +35237,8 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3521635237
3521735238pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void {
3521835239 const pt = sema.pt;
35219 const mod = pt.zcu;
35220 const ip = &mod.intern_pool;
35240 const zcu = pt.zcu;
35241 const ip = &zcu.intern_pool;
3522135242
3522235243 if (sema.fn_ret_ty_ies) |ies| {
3522335244 try sema.resolveInferredErrorSetPtr(block, src, ies);
......@@ -35228,14 +35249,14 @@ pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void
3522835249
3522935250pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void {
3523035251 const pt = sema.pt;
35231 const mod = pt.zcu;
35232 const ip = &mod.intern_pool;
35233 const fn_ty_info = mod.typeToFunc(fn_ty).?;
35252 const zcu = pt.zcu;
35253 const ip = &zcu.intern_pool;
35254 const fn_ty_info = zcu.typeToFunc(fn_ty).?;
3523435255
3523535256 try Type.fromInterned(fn_ty_info.return_type).resolveFully(pt);
3523635257
35237 if (mod.comp.config.any_error_tracing and
35238 Type.fromInterned(fn_ty_info.return_type).isError(mod))
35258 if (zcu.comp.config.any_error_tracing and
35259 Type.fromInterned(fn_ty_info.return_type).isError(zcu))
3523935260 {
3524035261 // Ensure the type exists so that backends can assume that.
3524135262 _ = try pt.getBuiltinType("StackTrace");
......@@ -35258,9 +35279,9 @@ pub fn resolveStructAlignment(
3525835279 struct_type: InternPool.LoadedStructType,
3525935280) SemaError!void {
3526035281 const pt = sema.pt;
35261 const mod = pt.zcu;
35262 const ip = &mod.intern_pool;
35263 const target = mod.getTarget();
35282 const zcu = pt.zcu;
35283 const ip = &zcu.intern_pool;
35284 const target = zcu.getTarget();
3526435285
3526535286 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);
3526635287
......@@ -35286,13 +35307,14 @@ pub fn resolveStructAlignment(
3528635307
3528735308 for (0..struct_type.field_types.len) |i| {
3528835309 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
35289 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty))
35310 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt))
3529035311 continue;
35291 const field_align = try pt.structFieldAlignmentAdvanced(
35312 const field_align = try field_ty.structFieldAlignmentAdvanced(
3529235313 struct_type.fieldAlign(ip, i),
35293 field_ty,
3529435314 struct_type.layout,
3529535315 .sema,
35316 pt.zcu,
35317 pt.tid,
3529635318 );
3529735319 alignment = alignment.maxStrict(field_align);
3529835320 }
......@@ -35338,14 +35360,14 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3533835360
3533935361 for (aligns, sizes, 0..) |*field_align, *field_size, i| {
3534035362 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
35341 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {
35363 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
3534235364 struct_type.offsets.get(ip)[i] = 0;
3534335365 field_size.* = 0;
3534435366 field_align.* = .none;
3534535367 continue;
3534635368 }
3534735369
35348 field_size.* = sema.typeAbiSize(field_ty) catch |err| switch (err) {
35370 field_size.* = field_ty.abiSizeSema(pt) catch |err| switch (err) {
3534935371 error.AnalysisFail => {
3535035372 const msg = sema.err orelse return err;
3535135373 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
......@@ -35353,16 +35375,17 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3535335375 },
3535435376 else => return err,
3535535377 };
35356 field_align.* = try pt.structFieldAlignmentAdvanced(
35378 field_align.* = try field_ty.structFieldAlignmentAdvanced(
3535735379 struct_type.fieldAlign(ip, i),
35358 field_ty,
3535935380 struct_type.layout,
3536035381 .sema,
35382 pt.zcu,
35383 pt.tid,
3536135384 );
3536235385 big_align = big_align.maxStrict(field_align.*);
3536335386 }
3536435387
35365 if (struct_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35388 if (struct_type.flagsUnordered(ip).assumed_runtime_bits and !(try ty.hasRuntimeBitsSema(pt))) {
3536635389 const msg = try sema.errMsg(
3536735390 ty.srcLoc(zcu),
3536835391 "struct layout depends on it having runtime bits",
......@@ -35387,7 +35410,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3538735410
3538835411 for (runtime_order, 0..) |*ro, i| {
3538935412 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
35390 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {
35413 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
3539135414 ro.* = .omitted;
3539235415 } else {
3539335416 ro.* = @enumFromInt(i);
......@@ -35440,7 +35463,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3544035463 offset = offsets[i] + sizes[i];
3544135464 }
3544235465 struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);
35443 _ = try sema.typeRequiresComptime(ty);
35466 _ = try ty.comptimeOnlySema(pt);
3544435467}
3544535468
3544635469fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructType) CompileError!void {
......@@ -35488,7 +35511,7 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
3548835511 var accumulator: u64 = 0;
3548935512 for (0..struct_type.field_types.len) |i| {
3549035513 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
35491 accumulator += try field_ty.bitSizeAdvanced(pt, .sema);
35514 accumulator += try field_ty.bitSizeSema(pt);
3549235515 }
3549335516 break :blk accumulator;
3549435517 };
......@@ -35543,17 +35566,17 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
3554335566
3554435567fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ty: Type, fields_bit_sum: u64) CompileError!void {
3554535568 const pt = sema.pt;
35546 const mod = pt.zcu;
35569 const zcu = pt.zcu;
3554735570
35548 if (!backing_int_ty.isInt(mod)) {
35571 if (!backing_int_ty.isInt(zcu)) {
3554935572 return sema.fail(block, src, "expected backing integer type, found '{}'", .{backing_int_ty.fmt(pt)});
3555035573 }
35551 if (backing_int_ty.bitSize(pt) != fields_bit_sum) {
35574 if (backing_int_ty.bitSize(zcu) != fields_bit_sum) {
3555235575 return sema.fail(
3555335576 block,
3555435577 src,
3555535578 "backing integer type '{}' has bit size {} but the struct fields have a total bit size of {}",
35556 .{ backing_int_ty.fmt(pt), backing_int_ty.bitSize(pt), fields_bit_sum },
35579 .{ backing_int_ty.fmt(pt), backing_int_ty.bitSize(zcu), fields_bit_sum },
3555735580 );
3555835581 }
3555935582}
......@@ -35573,13 +35596,13 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3557335596
3557435597fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3557535598 const pt = sema.pt;
35576 const mod = pt.zcu;
35577 if (ty.zigTypeTag(mod) == .Pointer) {
35578 switch (ty.ptrSize(mod)) {
35599 const zcu = pt.zcu;
35600 if (ty.zigTypeTag(zcu) == .Pointer) {
35601 switch (ty.ptrSize(zcu)) {
3557935602 .Slice, .Many, .C => return,
3558035603 .One => {
35581 const elem_ty = ty.childType(mod);
35582 if (elem_ty.zigTypeTag(mod) == .Array) return;
35604 const elem_ty = ty.childType(zcu);
35605 if (elem_ty.zigTypeTag(zcu) == .Array) return;
3558335606 // TODO https://github.com/ziglang/zig/issues/15479
3558435607 // if (elem_ty.isTuple()) return;
3558535608 },
......@@ -35601,7 +35624,8 @@ pub fn resolveUnionAlignment(
3560135624 ty: Type,
3560235625 union_type: InternPool.LoadedUnionType,
3560335626) SemaError!void {
35604 const zcu = sema.pt.zcu;
35627 const pt = sema.pt;
35628 const zcu = pt.zcu;
3560535629 const ip = &zcu.intern_pool;
3560635630 const target = zcu.getTarget();
3560735631
......@@ -35621,13 +35645,13 @@ pub fn resolveUnionAlignment(
3562135645 var max_align: Alignment = .@"1";
3562235646 for (0..union_type.field_types.len) |field_index| {
3562335647 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
35624 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
35648 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
3562535649
3562635650 const explicit_align = union_type.fieldAlign(ip, field_index);
3562735651 const field_align = if (explicit_align != .none)
3562835652 explicit_align
3562935653 else
35630 try sema.typeAbiAlignment(field_ty);
35654 try field_ty.abiAlignmentSema(sema.pt);
3563135655
3563235656 max_align = max_align.max(field_align);
3563335657 }
......@@ -35635,7 +35659,7 @@ pub fn resolveUnionAlignment(
3563535659 union_type.setAlignment(ip, max_align);
3563635660}
3563735661
35638/// This logic must be kept in sync with `Module.getUnionLayout`.
35662/// This logic must be kept in sync with `Zcu.getUnionLayout`.
3563935663pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3564035664 const pt = sema.pt;
3564135665 const ip = &pt.zcu.intern_pool;
......@@ -35670,9 +35694,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3567035694 for (0..union_type.field_types.len) |field_index| {
3567135695 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
3567235696
35673 if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(pt.zcu) == .NoReturn) continue; // TODO: should this affect alignment?
35697 if (try field_ty.comptimeOnlySema(pt) or field_ty.zigTypeTag(pt.zcu) == .NoReturn) continue; // TODO: should this affect alignment?
3567435698
35675 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {
35699 max_size = @max(max_size, field_ty.abiSizeSema(pt) catch |err| switch (err) {
3567635700 error.AnalysisFail => {
3567735701 const msg = sema.err orelse return err;
3567835702 try sema.addFieldErrNote(ty, field_index, msg, "while checking this field", .{});
......@@ -35685,17 +35709,17 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3568535709 const field_align = if (explicit_align != .none)
3568635710 explicit_align
3568735711 else
35688 try sema.typeAbiAlignment(field_ty);
35712 try field_ty.abiAlignmentSema(pt);
3568935713
3569035714 max_align = max_align.max(field_align);
3569135715 }
3569235716
3569335717 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and
35694 try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));
35718 try Type.fromInterned(union_type.enum_tag_ty).hasRuntimeBitsSema(pt);
3569535719 const size, const alignment, const padding = if (has_runtime_tag) layout: {
3569635720 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);
35697 const tag_align = try sema.typeAbiAlignment(enum_tag_type);
35698 const tag_size = try sema.typeAbiSize(enum_tag_type);
35721 const tag_align = try enum_tag_type.abiAlignmentSema(pt);
35722 const tag_size = try enum_tag_type.abiSizeSema(pt);
3569935723
3570035724 // Put the tag before or after the payload depending on which one's
3570135725 // alignment is greater.
......@@ -35727,7 +35751,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3572735751
3572835752 union_type.setHaveLayout(ip, @intCast(size), padding, alignment);
3572935753
35730 if (union_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35754 if (union_type.flagsUnordered(ip).assumed_runtime_bits and !(try ty.hasRuntimeBitsSema(pt))) {
3573135755 const msg = try sema.errMsg(
3573235756 ty.srcLoc(pt.zcu),
3573335757 "union layout depends on it having runtime bits",
......@@ -35746,6 +35770,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3574635770 );
3574735771 return sema.failWithOwnedErrorMsg(null, msg);
3574835772 }
35773 _ = try ty.comptimeOnlySema(pt);
3574935774}
3575035775
3575135776/// Returns `error.AnalysisFail` if any of the types (recursively) failed to
......@@ -35754,9 +35779,9 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {
3575435779 try sema.resolveStructLayout(ty);
3575535780
3575635781 const pt = sema.pt;
35757 const mod = pt.zcu;
35758 const ip = &mod.intern_pool;
35759 const struct_type = mod.typeToStruct(ty).?;
35782 const zcu = pt.zcu;
35783 const ip = &zcu.intern_pool;
35784 const struct_type = zcu.typeToStruct(ty).?;
3576035785
3576135786 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);
3576235787
......@@ -35777,9 +35802,9 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3577735802 try sema.resolveUnionLayout(ty);
3577835803
3577935804 const pt = sema.pt;
35780 const mod = pt.zcu;
35781 const ip = &mod.intern_pool;
35782 const union_obj = mod.typeToUnion(ty).?;
35805 const zcu = pt.zcu;
35806 const ip = &zcu.intern_pool;
35807 const union_obj = zcu.typeToUnion(ty).?;
3578335808
3578435809 assert(sema.owner.unwrap().cau == union_obj.cau);
3578535810
......@@ -35804,7 +35829,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3580435829 }
3580535830
3580635831 // And let's not forget comptime-only status.
35807 _ = try sema.typeRequiresComptime(ty);
35832 _ = try ty.comptimeOnlySema(pt);
3580835833}
3580935834
3581035835pub fn resolveTypeFieldsStruct(
......@@ -35950,7 +35975,7 @@ fn resolveInferredErrorSet(
3595035975 try pt.ensureFuncBodyAnalyzed(func_index);
3595135976 }
3595235977
35953 // This will now have been resolved by the logic at the end of `Module.analyzeFnBody`
35978 // This will now have been resolved by the logic at the end of `Zcu.analyzeFnBody`
3595435979 // which calls `resolveInferredErrorSetPtr`.
3595535980 const final_resolved_ty = func.resolvedErrorSetUnordered(ip);
3595635981 assert(final_resolved_ty != .none);
......@@ -35997,9 +36022,9 @@ fn resolveAdHocInferredErrorSet(
3599736022 value: InternPool.Index,
3599836023) CompileError!InternPool.Index {
3599936024 const pt = sema.pt;
36000 const mod = pt.zcu;
36025 const zcu = pt.zcu;
3600136026 const gpa = sema.gpa;
36002 const ip = &mod.intern_pool;
36027 const ip = &zcu.intern_pool;
3600336028 const new_ty = try resolveAdHocInferredErrorSetTy(sema, block, src, ip.typeOf(value));
3600436029 if (new_ty == .none) return value;
3600536030 return ip.getCoerced(gpa, pt.tid, value, new_ty);
......@@ -36013,8 +36038,8 @@ fn resolveAdHocInferredErrorSetTy(
3601336038) CompileError!InternPool.Index {
3601436039 const ies = sema.fn_ret_ty_ies orelse return .none;
3601536040 const pt = sema.pt;
36016 const mod = pt.zcu;
36017 const ip = &mod.intern_pool;
36041 const zcu = pt.zcu;
36042 const ip = &zcu.intern_pool;
3601836043 const error_union_info = switch (ip.indexToKey(ty)) {
3601936044 .error_union_type => |x| x,
3602036045 else => return .none,
......@@ -36037,8 +36062,8 @@ fn resolveInferredErrorSetTy(
3603736062 ty: InternPool.Index,
3603836063) CompileError!InternPool.Index {
3603936064 const pt = sema.pt;
36040 const mod = pt.zcu;
36041 const ip = &mod.intern_pool;
36065 const zcu = pt.zcu;
36066 const ip = &zcu.intern_pool;
3604236067 if (ty == .anyerror_type) return ty;
3604336068 switch (ip.indexToKey(ty)) {
3604436069 .error_set_type => return ty,
......@@ -36845,9 +36870,9 @@ fn generateUnionTagTypeNumbered(
3684536870 union_name: InternPool.NullTerminatedString,
3684636871) !InternPool.Index {
3684736872 const pt = sema.pt;
36848 const mod = pt.zcu;
36873 const zcu = pt.zcu;
3684936874 const gpa = sema.gpa;
36850 const ip = &mod.intern_pool;
36875 const ip = &zcu.intern_pool;
3685136876
3685236877 const name = try ip.getOrPutStringFmt(
3685336878 gpa,
......@@ -36881,8 +36906,8 @@ fn generateUnionTagTypeSimple(
3688136906 union_name: InternPool.NullTerminatedString,
3688236907) !InternPool.Index {
3688336908 const pt = sema.pt;
36884 const mod = pt.zcu;
36885 const ip = &mod.intern_pool;
36909 const zcu = pt.zcu;
36910 const ip = &zcu.intern_pool;
3688636911 const gpa = sema.gpa;
3688736912
3688836913 const name = try ip.getOrPutStringFmt(
......@@ -37192,7 +37217,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3719237217 return null;
3719337218 },
3719437219 .auto, .explicit => {
37195 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(pt)) return null;
37220 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null;
3719637221
3719737222 return Value.fromInterned(switch (enum_type.names.len) {
3719837223 0 => try pt.intern(.{ .empty_enum_value = ty.toIntern() }),
......@@ -37279,7 +37304,7 @@ fn analyzeComptimeAlloc(
3727937304 alignment: Alignment,
3728037305) CompileError!Air.Inst.Ref {
3728137306 const pt = sema.pt;
37282 const mod = pt.zcu;
37307 const zcu = pt.zcu;
3728337308
3728437309 // Needed to make an anon decl with type `var_type` (the `finish()` call below).
3728537310 _ = try sema.typeHasOnePossibleValue(var_type);
......@@ -37288,7 +37313,7 @@ fn analyzeComptimeAlloc(
3728837313 .child = var_type.toIntern(),
3728937314 .flags = .{
3729037315 .alignment = alignment,
37291 .address_space = target_util.defaultAddressSpace(mod.getTarget(), .global_constant),
37316 .address_space = target_util.defaultAddressSpace(zcu.getTarget(), .global_constant),
3729237317 },
3729337318 });
3729437319
......@@ -37338,13 +37363,13 @@ pub fn analyzeAsAddressSpace(
3733837363 ctx: AddressSpaceContext,
3733937364) !std.builtin.AddressSpace {
3734037365 const pt = sema.pt;
37341 const mod = pt.zcu;
37366 const zcu = pt.zcu;
3734237367 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
3734337368 const coerced = try sema.coerce(block, addrspace_ty, air_ref, src);
3734437369 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{
3734537370 .needed_comptime_reason = "address space must be comptime-known",
3734637371 });
37347 const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_val);
37372 const address_space = zcu.toEnum(std.builtin.AddressSpace, addrspace_val);
3734837373 const target = pt.zcu.getTarget();
3734937374 const arch = target.cpu.arch;
3735037375
......@@ -37446,13 +37471,13 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError
3744637471/// This logic must be kept in sync with `Type.isPtrLikeOptional`.
3744737472fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3744837473 const pt = sema.pt;
37449 const mod = pt.zcu;
37450 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
37474 const zcu = pt.zcu;
37475 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
3745137476 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
3745237477 .One, .Many, .C => ty,
3745337478 .Slice => null,
3745437479 },
37455 .opt_type => |opt_child| switch (mod.intern_pool.indexToKey(opt_child)) {
37480 .opt_type => |opt_child| switch (zcu.intern_pool.indexToKey(opt_child)) {
3745637481 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
3745737482 .Slice, .C => null,
3745837483 .Many, .One => {
......@@ -37473,33 +37498,6 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3747337498 };
3747437499}
3747537500
37476/// `generic_poison` will return false.
37477/// May return false negatives when structs and unions are having their field types resolved.
37478pub fn typeRequiresComptime(sema: *Sema, ty: Type) SemaError!bool {
37479 return ty.comptimeOnlyAdvanced(sema.pt, .sema);
37480}
37481
37482pub fn typeHasRuntimeBits(sema: *Sema, ty: Type) SemaError!bool {
37483 return ty.hasRuntimeBitsAdvanced(sema.pt, false, .sema) catch |err| switch (err) {
37484 error.NeedLazy => unreachable,
37485 else => |e| return e,
37486 };
37487}
37488
37489pub fn typeAbiSize(sema: *Sema, ty: Type) SemaError!u64 {
37490 const pt = sema.pt;
37491 try ty.resolveLayout(pt);
37492 return ty.abiSize(pt);
37493}
37494
37495pub fn typeAbiAlignment(sema: *Sema, ty: Type) SemaError!Alignment {
37496 return (try ty.abiAlignmentAdvanced(sema.pt, .sema)).scalar;
37497}
37498
37499pub fn fnHasRuntimeBits(sema: *Sema, ty: Type) CompileError!bool {
37500 return ty.fnHasRuntimeBitsAdvanced(sema.pt, .sema);
37501}
37502
3750337501fn unionFieldIndex(
3750437502 sema: *Sema,
3750537503 block: *Block,
......@@ -37508,10 +37506,10 @@ fn unionFieldIndex(
3750837506 field_src: LazySrcLoc,
3750937507) !u32 {
3751037508 const pt = sema.pt;
37511 const mod = pt.zcu;
37512 const ip = &mod.intern_pool;
37509 const zcu = pt.zcu;
37510 const ip = &zcu.intern_pool;
3751337511 try union_ty.resolveFields(pt);
37514 const union_obj = mod.typeToUnion(union_ty).?;
37512 const union_obj = zcu.typeToUnion(union_ty).?;
3751537513 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
3751637514 return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name);
3751737515 return @intCast(field_index);
......@@ -37525,13 +37523,13 @@ fn structFieldIndex(
3752537523 field_src: LazySrcLoc,
3752637524) !u32 {
3752737525 const pt = sema.pt;
37528 const mod = pt.zcu;
37529 const ip = &mod.intern_pool;
37526 const zcu = pt.zcu;
37527 const ip = &zcu.intern_pool;
3753037528 try struct_ty.resolveFields(pt);
37531 if (struct_ty.isAnonStruct(mod)) {
37529 if (struct_ty.isAnonStruct(zcu)) {
3753237530 return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src);
3753337531 } else {
37534 const struct_type = mod.typeToStruct(struct_ty).?;
37532 const struct_type = zcu.typeToStruct(struct_ty).?;
3753537533 return struct_type.nameIndex(ip, field_name) orelse
3753637534 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name);
3753737535 }
......@@ -37545,8 +37543,8 @@ fn anonStructFieldIndex(
3754537543 field_src: LazySrcLoc,
3754637544) !u32 {
3754737545 const pt = sema.pt;
37548 const mod = pt.zcu;
37549 const ip = &mod.intern_pool;
37546 const zcu = pt.zcu;
37547 const ip = &zcu.intern_pool;
3755037548 switch (ip.indexToKey(struct_ty.toIntern())) {
3755137549 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names.get(ip), 0..) |name, i| {
3755237550 if (name == field_name) return @intCast(i);
......@@ -37583,10 +37581,10 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize)
3758337581
3758437582fn intAddInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize) !Value {
3758537583 const pt = sema.pt;
37586 const mod = pt.zcu;
37587 if (ty.zigTypeTag(mod) == .Vector) {
37588 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
37589 const scalar_ty = ty.scalarType(mod);
37584 const zcu = pt.zcu;
37585 if (ty.zigTypeTag(zcu) == .Vector) {
37586 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
37587 const scalar_ty = ty.scalarType(zcu);
3759037588 for (result_data, 0..) |*scalar, i| {
3759137589 const lhs_elem = try lhs.elemValue(pt, i);
3759237590 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -37611,15 +37609,15 @@ fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
3761137609 const pt = sema.pt;
3761237610 if (scalar_ty.toIntern() != .comptime_int_type) {
3761337611 const res = try sema.intAddWithOverflowScalar(lhs, rhs, scalar_ty);
37614 if (res.overflow_bit.compareAllWithZero(.neq, pt)) return error.Overflow;
37612 if (res.overflow_bit.compareAllWithZero(.neq, pt.zcu)) return error.Overflow;
3761537613 return res.wrapped_result;
3761637614 }
3761737615 // TODO is this a performance issue? maybe we should try the operation without
3761837616 // resorting to BigInt first.
3761937617 var lhs_space: Value.BigIntSpace = undefined;
3762037618 var rhs_space: Value.BigIntSpace = undefined;
37621 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);
37622 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);
37619 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37620 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3762337621 const limbs = try sema.arena.alloc(
3762437622 std.math.big.Limb,
3762537623 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
......@@ -37637,10 +37635,10 @@ fn numberAddWrapScalar(
3763737635 ty: Type,
3763837636) !Value {
3763937637 const pt = sema.pt;
37640 const mod = pt.zcu;
37641 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return pt.undefValue(ty);
37638 const zcu = pt.zcu;
37639 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return pt.undefValue(ty);
3764237640
37643 if (ty.zigTypeTag(mod) == .ComptimeInt) {
37641 if (ty.zigTypeTag(zcu) == .ComptimeInt) {
3764437642 return sema.intAdd(lhs, rhs, ty, undefined);
3764537643 }
3764637644
......@@ -37701,17 +37699,18 @@ fn intSubInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi
3770137699
3770237700fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
3770337701 const pt = sema.pt;
37702 const zcu = pt.zcu;
3770437703 if (scalar_ty.toIntern() != .comptime_int_type) {
3770537704 const res = try sema.intSubWithOverflowScalar(lhs, rhs, scalar_ty);
37706 if (res.overflow_bit.compareAllWithZero(.neq, pt)) return error.Overflow;
37705 if (res.overflow_bit.compareAllWithZero(.neq, zcu)) return error.Overflow;
3770737706 return res.wrapped_result;
3770837707 }
3770937708 // TODO is this a performance issue? maybe we should try the operation without
3771037709 // resorting to BigInt first.
3771137710 var lhs_space: Value.BigIntSpace = undefined;
3771237711 var rhs_space: Value.BigIntSpace = undefined;
37713 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);
37714 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);
37712 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37713 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3771537714 const limbs = try sema.arena.alloc(
3771637715 std.math.big.Limb,
3771737716 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
......@@ -37729,10 +37728,10 @@ fn numberSubWrapScalar(
3772937728 ty: Type,
3773037729) !Value {
3773137730 const pt = sema.pt;
37732 const mod = pt.zcu;
37733 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return pt.undefValue(ty);
37731 const zcu = pt.zcu;
37732 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return pt.undefValue(ty);
3773437733
37735 if (ty.zigTypeTag(mod) == .ComptimeInt) {
37734 if (ty.zigTypeTag(zcu) == .ComptimeInt) {
3773637735 return sema.intSub(lhs, rhs, ty, undefined);
3773737736 }
3773837737
......@@ -37751,12 +37750,12 @@ fn intSubWithOverflow(
3775137750 ty: Type,
3775237751) !Value.OverflowArithmeticResult {
3775337752 const pt = sema.pt;
37754 const mod = pt.zcu;
37755 if (ty.zigTypeTag(mod) == .Vector) {
37756 const vec_len = ty.vectorLen(mod);
37753 const zcu = pt.zcu;
37754 if (ty.zigTypeTag(zcu) == .Vector) {
37755 const vec_len = ty.vectorLen(zcu);
3775737756 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
3775837757 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);
37759 const scalar_ty = ty.scalarType(mod);
37758 const scalar_ty = ty.scalarType(zcu);
3776037759 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
3776137760 const lhs_elem = try lhs.elemValue(pt, i);
3776237761 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -37785,10 +37784,10 @@ fn intSubWithOverflowScalar(
3778537784 ty: Type,
3778637785) !Value.OverflowArithmeticResult {
3778737786 const pt = sema.pt;
37788 const mod = pt.zcu;
37789 const info = ty.intInfo(mod);
37787 const zcu = pt.zcu;
37788 const info = ty.intInfo(zcu);
3779037789
37791 if (lhs.isUndef(mod) or rhs.isUndef(mod)) {
37790 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) {
3779237791 return .{
3779337792 .overflow_bit = try pt.undefValue(Type.u1),
3779437793 .wrapped_result = try pt.undefValue(ty),
......@@ -37797,8 +37796,8 @@ fn intSubWithOverflowScalar(
3779737796
3779837797 var lhs_space: Value.BigIntSpace = undefined;
3779937798 var rhs_space: Value.BigIntSpace = undefined;
37800 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);
37801 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);
37799 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37800 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3780237801 const limbs = try sema.arena.alloc(
3780337802 std.math.big.Limb,
3780437803 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -37824,12 +37823,12 @@ fn intFromFloat(
3782437823 mode: IntFromFloatMode,
3782537824) CompileError!Value {
3782637825 const pt = sema.pt;
37827 const mod = pt.zcu;
37828 if (float_ty.zigTypeTag(mod) == .Vector) {
37829 const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(mod));
37826 const zcu = pt.zcu;
37827 if (float_ty.zigTypeTag(zcu) == .Vector) {
37828 const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(zcu));
3783037829 for (result_data, 0..) |*scalar, i| {
3783137830 const elem_val = try val.elemValue(pt, i);
37832 scalar.* = (try sema.intFromFloatScalar(block, src, elem_val, int_ty.scalarType(mod), mode)).toIntern();
37831 scalar.* = (try sema.intFromFloatScalar(block, src, elem_val, int_ty.scalarType(zcu), mode)).toIntern();
3783337832 }
3783437833 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
3783537834 .ty = int_ty.toIntern(),
......@@ -37873,18 +37872,18 @@ fn intFromFloatScalar(
3787337872 mode: IntFromFloatMode,
3787437873) CompileError!Value {
3787537874 const pt = sema.pt;
37876 const mod = pt.zcu;
37875 const zcu = pt.zcu;
3787737876
37878 if (val.isUndef(mod)) return sema.failWithUseOfUndef(block, src);
37877 if (val.isUndef(zcu)) return sema.failWithUseOfUndef(block, src);
3787937878
37880 if (mode == .exact and val.floatHasFraction(mod)) return sema.fail(
37879 if (mode == .exact and val.floatHasFraction(zcu)) return sema.fail(
3788137880 block,
3788237881 src,
3788337882 "fractional component prevents float value '{}' from coercion to type '{}'",
3788437883 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },
3788537884 );
3788637885
37887 const float = val.toFloat(f128, pt);
37886 const float = val.toFloat(f128, zcu);
3788837887 if (std.math.isNan(float)) {
3788937888 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{}'", .{
3789037889 int_ty.fmt(pt),
......@@ -37920,15 +37919,15 @@ fn intFitsInType(
3792037919 vector_index: ?*usize,
3792137920) CompileError!bool {
3792237921 const pt = sema.pt;
37923 const mod = pt.zcu;
37922 const zcu = pt.zcu;
3792437923 if (ty.toIntern() == .comptime_int_type) return true;
37925 const info = ty.intInfo(mod);
37924 const info = ty.intInfo(zcu);
3792637925 switch (val.toIntern()) {
3792737926 .zero_usize, .zero_u8 => return true,
37928 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
37927 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
3792937928 .undef => return true,
3793037929 .variable, .@"extern", .func, .ptr => {
37931 const target = mod.getTarget();
37930 const target = zcu.getTarget();
3793237931 const ptr_bits = target.ptrBitWidth();
3793337932 return switch (info.signedness) {
3793437933 .signed => info.bits > ptr_bits,
......@@ -37945,7 +37944,7 @@ fn intFitsInType(
3794537944 const max_needed_bits = @as(u16, 16) + @intFromBool(info.signedness == .signed);
3794637945 // If it is u16 or bigger we know the alignment fits without resolving it.
3794737946 if (info.bits >= max_needed_bits) return true;
37948 const x = try sema.typeAbiAlignment(Type.fromInterned(lazy_ty));
37947 const x = try Type.fromInterned(lazy_ty).abiAlignmentSema(pt);
3794937948 if (x == .none) return true;
3795037949 const actual_needed_bits = @as(usize, x.toLog2Units()) + 1 + @intFromBool(info.signedness == .signed);
3795137950 return info.bits >= actual_needed_bits;
......@@ -37954,16 +37953,16 @@ fn intFitsInType(
3795437953 const max_needed_bits = @as(u16, 64) + @intFromBool(info.signedness == .signed);
3795537954 // If it is u64 or bigger we know the size fits without resolving it.
3795637955 if (info.bits >= max_needed_bits) return true;
37957 const x = try sema.typeAbiSize(Type.fromInterned(lazy_ty));
37956 const x = try Type.fromInterned(lazy_ty).abiSizeSema(pt);
3795837957 if (x == 0) return true;
3795937958 const actual_needed_bits = std.math.log2(x) + 1 + @intFromBool(info.signedness == .signed);
3796037959 return info.bits >= actual_needed_bits;
3796137960 },
3796237961 },
3796337962 .aggregate => |aggregate| {
37964 assert(ty.zigTypeTag(mod) == .Vector);
37963 assert(ty.zigTypeTag(zcu) == .Vector);
3796537964 return switch (aggregate.storage) {
37966 .bytes => |bytes| for (bytes.toSlice(ty.vectorLen(mod), &mod.intern_pool), 0..) |byte, i| {
37965 .bytes => |bytes| for (bytes.toSlice(ty.vectorLen(zcu), &zcu.intern_pool), 0..) |byte, i| {
3796737966 if (byte == 0) continue;
3796837967 const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed);
3796937968 if (info.bits >= actual_needed_bits) continue;
......@@ -37975,7 +37974,7 @@ fn intFitsInType(
3797537974 .elems => |elems| elems,
3797637975 .repeated_elem => |elem| @as(*const [1]InternPool.Index, &elem),
3797737976 }, 0..) |elem, i| {
37978 if (try sema.intFitsInType(Value.fromInterned(elem), ty.scalarType(mod), null)) continue;
37977 if (try sema.intFitsInType(Value.fromInterned(elem), ty.scalarType(zcu), null)) continue;
3797937978 if (vector_index) |vi| vi.* = i;
3798037979 break false;
3798137980 } else true,
......@@ -37997,15 +37996,15 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {
3799737996/// Asserts the type is an enum.
3799837997fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
3799937998 const pt = sema.pt;
38000 const mod = pt.zcu;
38001 const enum_type = mod.intern_pool.loadEnumType(ty.toIntern());
37999 const zcu = pt.zcu;
38000 const enum_type = zcu.intern_pool.loadEnumType(ty.toIntern());
3800238001 assert(enum_type.tag_mode != .nonexhaustive);
3800338002 // The `tagValueIndex` function call below relies on the type being the integer tag type.
3800438003 // `getCoerced` assumes the value will fit the new type.
3800538004 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;
3800638005 const int_coerced = try pt.getCoerced(int, Type.fromInterned(enum_type.tag_ty));
3800738006
38008 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced.toIntern()) != null;
38007 return enum_type.tagValueIndex(&zcu.intern_pool, int_coerced.toIntern()) != null;
3800938008}
3801038009
3801138010fn intAddWithOverflow(
......@@ -38015,12 +38014,12 @@ fn intAddWithOverflow(
3801538014 ty: Type,
3801638015) !Value.OverflowArithmeticResult {
3801738016 const pt = sema.pt;
38018 const mod = pt.zcu;
38019 if (ty.zigTypeTag(mod) == .Vector) {
38020 const vec_len = ty.vectorLen(mod);
38017 const zcu = pt.zcu;
38018 if (ty.zigTypeTag(zcu) == .Vector) {
38019 const vec_len = ty.vectorLen(zcu);
3802138020 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
3802238021 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);
38023 const scalar_ty = ty.scalarType(mod);
38022 const scalar_ty = ty.scalarType(zcu);
3802438023 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
3802538024 const lhs_elem = try lhs.elemValue(pt, i);
3802638025 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -38049,10 +38048,10 @@ fn intAddWithOverflowScalar(
3804938048 ty: Type,
3805038049) !Value.OverflowArithmeticResult {
3805138050 const pt = sema.pt;
38052 const mod = pt.zcu;
38053 const info = ty.intInfo(mod);
38051 const zcu = pt.zcu;
38052 const info = ty.intInfo(zcu);
3805438053
38055 if (lhs.isUndef(mod) or rhs.isUndef(mod)) {
38054 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) {
3805638055 return .{
3805738056 .overflow_bit = try pt.undefValue(Type.u1),
3805838057 .wrapped_result = try pt.undefValue(ty),
......@@ -38061,8 +38060,8 @@ fn intAddWithOverflowScalar(
3806138060
3806238061 var lhs_space: Value.BigIntSpace = undefined;
3806338062 var rhs_space: Value.BigIntSpace = undefined;
38064 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);
38065 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);
38063 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
38064 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3806638065 const limbs = try sema.arena.alloc(
3806738066 std.math.big.Limb,
3806838067 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -38088,13 +38087,13 @@ fn compareAll(
3808838087 ty: Type,
3808938088) CompileError!bool {
3809038089 const pt = sema.pt;
38091 const mod = pt.zcu;
38092 if (ty.zigTypeTag(mod) == .Vector) {
38090 const zcu = pt.zcu;
38091 if (ty.zigTypeTag(zcu) == .Vector) {
3809338092 var i: usize = 0;
38094 while (i < ty.vectorLen(mod)) : (i += 1) {
38093 while (i < ty.vectorLen(zcu)) : (i += 1) {
3809538094 const lhs_elem = try lhs.elemValue(pt, i);
3809638095 const rhs_elem = try rhs.elemValue(pt, i);
38097 if (!(try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod)))) {
38096 if (!(try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(zcu)))) {
3809838097 return false;
3809938098 }
3810038099 }
......@@ -38117,7 +38116,7 @@ fn compareScalar(
3811738116 switch (op) {
3811838117 .eq => return sema.valuesEqual(coerced_lhs, coerced_rhs, ty),
3811938118 .neq => return !(try sema.valuesEqual(coerced_lhs, coerced_rhs, ty)),
38120 else => return Value.compareHeteroAdvanced(coerced_lhs, op, coerced_rhs, pt, .sema),
38119 else => return Value.compareHeteroSema(coerced_lhs, op, coerced_rhs, pt),
3812138120 }
3812238121}
3812338122
......@@ -38139,17 +38138,17 @@ fn compareVector(
3813938138 ty: Type,
3814038139) !Value {
3814138140 const pt = sema.pt;
38142 const mod = pt.zcu;
38143 assert(ty.zigTypeTag(mod) == .Vector);
38144 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
38141 const zcu = pt.zcu;
38142 assert(ty.zigTypeTag(zcu) == .Vector);
38143 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
3814538144 for (result_data, 0..) |*scalar, i| {
3814638145 const lhs_elem = try lhs.elemValue(pt, i);
3814738146 const rhs_elem = try rhs.elemValue(pt, i);
38148 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));
38147 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(zcu));
3814938148 scalar.* = Value.makeBool(res_bool).toIntern();
3815038149 }
3815138150 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
38152 .ty = (try pt.vectorType(.{ .len = ty.vectorLen(mod), .child = .bool_type })).toIntern(),
38151 .ty = (try pt.vectorType(.{ .len = ty.vectorLen(zcu), .child = .bool_type })).toIntern(),
3815338152 .storage = .{ .elems = result_data },
3815438153 } }));
3815538154}
......@@ -38250,8 +38249,8 @@ fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Ai
3825038249/// Returns true if any value contained in `val` is undefined.
3825138250fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {
3825238251 const pt = sema.pt;
38253 const mod = pt.zcu;
38254 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
38252 const zcu = pt.zcu;
38253 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
3825538254 .undef => true,
3825638255 .simple_value => |v| v == .undefined,
3825738256 .slice => {
......@@ -38261,7 +38260,7 @@ fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {
3826138260 return sema.anyUndef(block, src, arr);
3826238261 },
3826338262 .aggregate => |aggregate| for (0..aggregate.storage.values().len) |i| {
38264 const elem = mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.values()[i];
38263 const elem = zcu.intern_pool.indexToKey(val.toIntern()).aggregate.storage.values()[i];
3826538264 if (try sema.anyUndef(block, src, Value.fromInterned(elem))) break true;
3826638265 } else false,
3826738266 else => false,
src/Sema/bitcast.zig+48-44
......@@ -85,23 +85,23 @@ fn bitCastInner(
8585 assert(val_ty.hasWellDefinedLayout(zcu));
8686
8787 const abi_pad_bits, const host_pad_bits = if (host_bits > 0)
88 .{ val_ty.abiSize(pt) * 8 - host_bits, host_bits - val_ty.bitSize(pt) }
88 .{ val_ty.abiSize(zcu) * 8 - host_bits, host_bits - val_ty.bitSize(zcu) }
8989 else
90 .{ val_ty.abiSize(pt) * 8 - val_ty.bitSize(pt), 0 };
90 .{ val_ty.abiSize(zcu) * 8 - val_ty.bitSize(zcu), 0 };
9191
9292 const skip_bits = switch (endian) {
9393 .little => bit_offset + byte_offset * 8,
9494 .big => if (host_bits > 0)
95 val_ty.abiSize(pt) * 8 - byte_offset * 8 - host_bits + bit_offset
95 val_ty.abiSize(zcu) * 8 - byte_offset * 8 - host_bits + bit_offset
9696 else
97 val_ty.abiSize(pt) * 8 - byte_offset * 8 - dest_ty.bitSize(pt),
97 val_ty.abiSize(zcu) * 8 - byte_offset * 8 - dest_ty.bitSize(zcu),
9898 };
9999
100100 var unpack: UnpackValueBits = .{
101101 .pt = sema.pt,
102102 .arena = sema.arena,
103103 .skip_bits = skip_bits,
104 .remaining_bits = dest_ty.bitSize(pt),
104 .remaining_bits = dest_ty.bitSize(zcu),
105105 .unpacked = std.ArrayList(InternPool.Index).init(sema.arena),
106106 };
107107 switch (endian) {
......@@ -141,22 +141,22 @@ fn bitCastSpliceInner(
141141 try val_ty.resolveLayout(pt);
142142 try splice_val_ty.resolveLayout(pt);
143143
144 const splice_bits = splice_val_ty.bitSize(pt);
144 const splice_bits = splice_val_ty.bitSize(zcu);
145145
146146 const splice_offset = switch (endian) {
147147 .little => bit_offset + byte_offset * 8,
148148 .big => if (host_bits > 0)
149 val_ty.abiSize(pt) * 8 - byte_offset * 8 - host_bits + bit_offset
149 val_ty.abiSize(zcu) * 8 - byte_offset * 8 - host_bits + bit_offset
150150 else
151 val_ty.abiSize(pt) * 8 - byte_offset * 8 - splice_bits,
151 val_ty.abiSize(zcu) * 8 - byte_offset * 8 - splice_bits,
152152 };
153153
154 assert(splice_offset + splice_bits <= val_ty.abiSize(pt) * 8);
154 assert(splice_offset + splice_bits <= val_ty.abiSize(zcu) * 8);
155155
156156 const abi_pad_bits, const host_pad_bits = if (host_bits > 0)
157 .{ val_ty.abiSize(pt) * 8 - host_bits, host_bits - val_ty.bitSize(pt) }
157 .{ val_ty.abiSize(zcu) * 8 - host_bits, host_bits - val_ty.bitSize(zcu) }
158158 else
159 .{ val_ty.abiSize(pt) * 8 - val_ty.bitSize(pt), 0 };
159 .{ val_ty.abiSize(zcu) * 8 - val_ty.bitSize(zcu), 0 };
160160
161161 var unpack: UnpackValueBits = .{
162162 .pt = pt,
......@@ -181,7 +181,7 @@ fn bitCastSpliceInner(
181181 try unpack.add(splice_val);
182182
183183 unpack.skip_bits = splice_offset + splice_bits;
184 unpack.remaining_bits = val_ty.abiSize(pt) * 8 - splice_offset - splice_bits;
184 unpack.remaining_bits = val_ty.abiSize(zcu) * 8 - splice_offset - splice_bits;
185185 switch (endian) {
186186 .little => {
187187 try unpack.add(val);
......@@ -229,7 +229,7 @@ const UnpackValueBits = struct {
229229 }
230230
231231 const ty = val.typeOf(zcu);
232 const bit_size = ty.bitSize(pt);
232 const bit_size = ty.bitSize(zcu);
233233
234234 if (unpack.skip_bits >= bit_size) {
235235 unpack.skip_bits -= bit_size;
......@@ -291,7 +291,7 @@ const UnpackValueBits = struct {
291291 // The final element does not have trailing padding.
292292 // Elements are reversed in packed memory on BE targets.
293293 const elem_ty = ty.childType(zcu);
294 const pad_bits = elem_ty.abiSize(pt) * 8 - elem_ty.bitSize(pt);
294 const pad_bits = elem_ty.abiSize(zcu) * 8 - elem_ty.bitSize(zcu);
295295 const len = ty.arrayLen(zcu);
296296 const maybe_sent = ty.sentinel(zcu);
297297
......@@ -323,12 +323,12 @@ const UnpackValueBits = struct {
323323 var cur_bit_off: u64 = 0;
324324 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrder(ip);
325325 while (it.next()) |field_idx| {
326 const want_bit_off = ty.structFieldOffset(field_idx, pt) * 8;
326 const want_bit_off = ty.structFieldOffset(field_idx, zcu) * 8;
327327 const pad_bits = want_bit_off - cur_bit_off;
328328 const field_val = try val.fieldValue(pt, field_idx);
329329 try unpack.padding(pad_bits);
330330 try unpack.add(field_val);
331 cur_bit_off = want_bit_off + field_val.typeOf(zcu).bitSize(pt);
331 cur_bit_off = want_bit_off + field_val.typeOf(zcu).bitSize(zcu);
332332 }
333333 // Add trailing padding bits.
334334 try unpack.padding(bit_size - cur_bit_off);
......@@ -339,11 +339,11 @@ const UnpackValueBits = struct {
339339 while (it.next()) |field_idx| {
340340 const field_val = try val.fieldValue(pt, field_idx);
341341 const field_ty = field_val.typeOf(zcu);
342 const want_bit_off = ty.structFieldOffset(field_idx, pt) * 8 + field_ty.bitSize(pt);
342 const want_bit_off = ty.structFieldOffset(field_idx, zcu) * 8 + field_ty.bitSize(zcu);
343343 const pad_bits = cur_bit_off - want_bit_off;
344344 try unpack.padding(pad_bits);
345345 try unpack.add(field_val);
346 cur_bit_off = want_bit_off - field_ty.bitSize(pt);
346 cur_bit_off = want_bit_off - field_ty.bitSize(zcu);
347347 }
348348 assert(cur_bit_off == 0);
349349 },
......@@ -366,7 +366,7 @@ const UnpackValueBits = struct {
366366 // This correctly handles the case where `tag == .none`, since the payload is then
367367 // either an integer or a byte array, both of which we can unpack.
368368 const payload_val = Value.fromInterned(un.val);
369 const pad_bits = bit_size - payload_val.typeOf(zcu).bitSize(pt);
369 const pad_bits = bit_size - payload_val.typeOf(zcu).bitSize(zcu);
370370 if (endian == .little or ty.containerLayout(zcu) == .@"packed") {
371371 try unpack.add(payload_val);
372372 try unpack.padding(pad_bits);
......@@ -398,13 +398,14 @@ const UnpackValueBits = struct {
398398
399399 fn primitive(unpack: *UnpackValueBits, val: Value) BitCastError!void {
400400 const pt = unpack.pt;
401 const zcu = pt.zcu;
401402
402403 if (unpack.remaining_bits == 0) {
403404 return;
404405 }
405406
406407 const ty = val.typeOf(pt.zcu);
407 const bit_size = ty.bitSize(pt);
408 const bit_size = ty.bitSize(zcu);
408409
409410 // Note that this skips all zero-bit types.
410411 if (unpack.skip_bits >= bit_size) {
......@@ -429,9 +430,10 @@ const UnpackValueBits = struct {
429430
430431 fn splitPrimitive(unpack: *UnpackValueBits, val: Value, bit_offset: u64, bit_count: u64) BitCastError!void {
431432 const pt = unpack.pt;
433 const zcu = pt.zcu;
432434 const ty = val.typeOf(pt.zcu);
433435
434 const val_bits = ty.bitSize(pt);
436 const val_bits = ty.bitSize(zcu);
435437 assert(bit_offset + bit_count <= val_bits);
436438
437439 switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
......@@ -499,12 +501,12 @@ const PackValueBits = struct {
499501 const len = ty.arrayLen(zcu);
500502 const elem_ty = ty.childType(zcu);
501503 const maybe_sent = ty.sentinel(zcu);
502 const pad_bits = elem_ty.abiSize(pt) * 8 - elem_ty.bitSize(pt);
504 const pad_bits = elem_ty.abiSize(zcu) * 8 - elem_ty.bitSize(zcu);
503505 const elems = try arena.alloc(InternPool.Index, @intCast(len));
504506
505507 if (endian == .big and maybe_sent != null) {
506508 // TODO: validate sentinel was preserved!
507 try pack.padding(elem_ty.bitSize(pt));
509 try pack.padding(elem_ty.bitSize(zcu));
508510 if (len != 0) try pack.padding(pad_bits);
509511 }
510512
......@@ -520,7 +522,7 @@ const PackValueBits = struct {
520522 if (endian == .little and maybe_sent != null) {
521523 // TODO: validate sentinel was preserved!
522524 if (len != 0) try pack.padding(pad_bits);
523 try pack.padding(elem_ty.bitSize(pt));
525 try pack.padding(elem_ty.bitSize(zcu));
524526 }
525527
526528 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
......@@ -538,23 +540,23 @@ const PackValueBits = struct {
538540 var cur_bit_off: u64 = 0;
539541 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrder(ip);
540542 while (it.next()) |field_idx| {
541 const want_bit_off = ty.structFieldOffset(field_idx, pt) * 8;
543 const want_bit_off = ty.structFieldOffset(field_idx, zcu) * 8;
542544 try pack.padding(want_bit_off - cur_bit_off);
543545 const field_ty = ty.structFieldType(field_idx, zcu);
544546 elems[field_idx] = (try pack.get(field_ty)).toIntern();
545 cur_bit_off = want_bit_off + field_ty.bitSize(pt);
547 cur_bit_off = want_bit_off + field_ty.bitSize(zcu);
546548 }
547 try pack.padding(ty.bitSize(pt) - cur_bit_off);
549 try pack.padding(ty.bitSize(zcu) - cur_bit_off);
548550 },
549551 .big => {
550 var cur_bit_off: u64 = ty.bitSize(pt);
552 var cur_bit_off: u64 = ty.bitSize(zcu);
551553 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrderReverse(ip);
552554 while (it.next()) |field_idx| {
553555 const field_ty = ty.structFieldType(field_idx, zcu);
554 const want_bit_off = ty.structFieldOffset(field_idx, pt) * 8 + field_ty.bitSize(pt);
556 const want_bit_off = ty.structFieldOffset(field_idx, zcu) * 8 + field_ty.bitSize(zcu);
555557 try pack.padding(cur_bit_off - want_bit_off);
556558 elems[field_idx] = (try pack.get(field_ty)).toIntern();
557 cur_bit_off = want_bit_off - field_ty.bitSize(pt);
559 cur_bit_off = want_bit_off - field_ty.bitSize(zcu);
558560 }
559561 assert(cur_bit_off == 0);
560562 },
......@@ -622,16 +624,16 @@ const PackValueBits = struct {
622624 for (field_order, 0..) |*f, i| f.* = @intCast(i);
623625 // Sort `field_order` to put the fields with the largest bit sizes first.
624626 const SizeSortCtx = struct {
625 pt: Zcu.PerThread,
627 zcu: *Zcu,
626628 field_types: []const InternPool.Index,
627629 fn lessThan(ctx: @This(), a_idx: u32, b_idx: u32) bool {
628630 const a_ty = Type.fromInterned(ctx.field_types[a_idx]);
629631 const b_ty = Type.fromInterned(ctx.field_types[b_idx]);
630 return a_ty.bitSize(ctx.pt) > b_ty.bitSize(ctx.pt);
632 return a_ty.bitSize(ctx.zcu) > b_ty.bitSize(ctx.zcu);
631633 }
632634 };
633635 std.mem.sortUnstable(u32, field_order, SizeSortCtx{
634 .pt = pt,
636 .zcu = zcu,
635637 .field_types = zcu.typeToUnion(ty).?.field_types.get(ip),
636638 }, SizeSortCtx.lessThan);
637639
......@@ -639,7 +641,7 @@ const PackValueBits = struct {
639641
640642 for (field_order) |field_idx| {
641643 const field_ty = Type.fromInterned(zcu.typeToUnion(ty).?.field_types.get(ip)[field_idx]);
642 const pad_bits = ty.bitSize(pt) - field_ty.bitSize(pt);
644 const pad_bits = ty.bitSize(zcu) - field_ty.bitSize(zcu);
643645 if (!padding_after) try pack.padding(pad_bits);
644646 const field_val = pack.get(field_ty) catch |err| switch (err) {
645647 error.ReinterpretDeclRef => {
......@@ -682,10 +684,11 @@ const PackValueBits = struct {
682684
683685 fn primitive(pack: *PackValueBits, want_ty: Type) BitCastError!Value {
684686 const pt = pack.pt;
685 const vals, const bit_offset = pack.prepareBits(want_ty.bitSize(pt));
687 const zcu = pt.zcu;
688 const vals, const bit_offset = pack.prepareBits(want_ty.bitSize(zcu));
686689
687690 for (vals) |val| {
688 if (!Value.fromInterned(val).isUndef(pt.zcu)) break;
691 if (!Value.fromInterned(val).isUndef(zcu)) break;
689692 } else {
690693 // All bits of the value are `undefined`.
691694 return pt.undefValue(want_ty);
......@@ -706,8 +709,8 @@ const PackValueBits = struct {
706709 ptr_cast: {
707710 if (vals.len != 1) break :ptr_cast;
708711 const val = Value.fromInterned(vals[0]);
709 if (!val.typeOf(pt.zcu).isPtrAtRuntime(pt.zcu)) break :ptr_cast;
710 if (!want_ty.isPtrAtRuntime(pt.zcu)) break :ptr_cast;
712 if (!val.typeOf(zcu).isPtrAtRuntime(zcu)) break :ptr_cast;
713 if (!want_ty.isPtrAtRuntime(zcu)) break :ptr_cast;
711714 return pt.getCoerced(val, want_ty);
712715 }
713716
......@@ -717,7 +720,7 @@ const PackValueBits = struct {
717720 for (vals) |ip_val| {
718721 const val = Value.fromInterned(ip_val);
719722 const ty = val.typeOf(pt.zcu);
720 buf_bits += ty.bitSize(pt);
723 buf_bits += ty.bitSize(zcu);
721724 }
722725
723726 const buf = try pack.arena.alloc(u8, @intCast((buf_bits + 7) / 8));
......@@ -726,11 +729,11 @@ const PackValueBits = struct {
726729 var cur_bit_off: usize = 0;
727730 for (vals) |ip_val| {
728731 const val = Value.fromInterned(ip_val);
729 const ty = val.typeOf(pt.zcu);
730 if (!val.isUndef(pt.zcu)) {
732 const ty = val.typeOf(zcu);
733 if (!val.isUndef(zcu)) {
731734 try val.writeToPackedMemory(ty, pt, buf, cur_bit_off);
732735 }
733 cur_bit_off += @intCast(ty.bitSize(pt));
736 cur_bit_off += @intCast(ty.bitSize(zcu));
734737 }
735738
736739 return Value.readFromPackedMemory(want_ty, pt, buf, @intCast(bit_offset), pack.arena);
......@@ -740,11 +743,12 @@ const PackValueBits = struct {
740743 if (need_bits == 0) return .{ &.{}, 0 };
741744
742745 const pt = pack.pt;
746 const zcu = pt.zcu;
743747
744748 var bits: u64 = 0;
745749 var len: usize = 0;
746750 while (bits < pack.bit_offset + need_bits) {
747 bits += Value.fromInterned(pack.unpacked[len]).typeOf(pt.zcu).bitSize(pt);
751 bits += Value.fromInterned(pack.unpacked[len]).typeOf(pt.zcu).bitSize(zcu);
748752 len += 1;
749753 }
750754
......@@ -757,7 +761,7 @@ const PackValueBits = struct {
757761 pack.bit_offset = 0;
758762 } else {
759763 pack.unpacked = pack.unpacked[len - 1 ..];
760 pack.bit_offset = Value.fromInterned(pack.unpacked[0]).typeOf(pt.zcu).bitSize(pt) - extra_bits;
764 pack.bit_offset = Value.fromInterned(pack.unpacked[0]).typeOf(pt.zcu).bitSize(zcu) - extra_bits;
761765 }
762766
763767 return .{ result_vals, result_offset };
src/Sema/comptime_ptr_access.zig+29-28
......@@ -13,14 +13,15 @@ pub const ComptimeLoadResult = union(enum) {
1313
1414pub fn loadComptimePtr(sema: *Sema, block: *Block, src: LazySrcLoc, ptr: Value) !ComptimeLoadResult {
1515 const pt = sema.pt;
16 const zcu = pt.zcu;
1617 const ptr_info = ptr.typeOf(pt.zcu).ptrInfo(pt.zcu);
1718 // TODO: host size for vectors is terrible
1819 const host_bits = switch (ptr_info.flags.vector_index) {
1920 .none => ptr_info.packed_offset.host_size * 8,
20 else => ptr_info.packed_offset.host_size * Type.fromInterned(ptr_info.child).bitSize(pt),
21 else => ptr_info.packed_offset.host_size * Type.fromInterned(ptr_info.child).bitSize(zcu),
2122 };
2223 const bit_offset = if (host_bits != 0) bit_offset: {
23 const child_bits = Type.fromInterned(ptr_info.child).bitSize(pt);
24 const child_bits = Type.fromInterned(ptr_info.child).bitSize(zcu);
2425 const bit_offset = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
2526 .none => 0,
2627 .runtime => return .runtime_load,
......@@ -67,18 +68,18 @@ pub fn storeComptimePtr(
6768 // TODO: host size for vectors is terrible
6869 const host_bits = switch (ptr_info.flags.vector_index) {
6970 .none => ptr_info.packed_offset.host_size * 8,
70 else => ptr_info.packed_offset.host_size * Type.fromInterned(ptr_info.child).bitSize(pt),
71 else => ptr_info.packed_offset.host_size * Type.fromInterned(ptr_info.child).bitSize(zcu),
7172 };
7273 const bit_offset = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
7374 .none => 0,
7475 .runtime => return .runtime_store,
7576 else => |idx| switch (zcu.getTarget().cpu.arch.endian()) {
76 .little => Type.fromInterned(ptr_info.child).bitSize(pt) * @intFromEnum(idx),
77 .big => host_bits - Type.fromInterned(ptr_info.child).bitSize(pt) * (@intFromEnum(idx) + 1), // element order reversed on big endian
77 .little => Type.fromInterned(ptr_info.child).bitSize(zcu) * @intFromEnum(idx),
78 .big => host_bits - Type.fromInterned(ptr_info.child).bitSize(zcu) * (@intFromEnum(idx) + 1), // element order reversed on big endian
7879 },
7980 };
8081 const pseudo_store_ty = if (host_bits > 0) t: {
81 const need_bits = Type.fromInterned(ptr_info.child).bitSize(pt);
82 const need_bits = Type.fromInterned(ptr_info.child).bitSize(zcu);
8283 if (need_bits + bit_offset > host_bits) {
8384 return .exceeds_host_size;
8485 }
......@@ -166,9 +167,9 @@ pub fn storeComptimePtr(
166167 .direct => |direct| .{ direct.val, 0 },
167168 .index => |index| .{
168169 index.val,
169 index.elem_index * index.val.typeOf(zcu).childType(zcu).abiSize(pt),
170 index.elem_index * index.val.typeOf(zcu).childType(zcu).abiSize(zcu),
170171 },
171 .flat_index => |flat| .{ flat.val, flat.flat_elem_index * flat.val.typeOf(zcu).arrayBase(zcu)[0].abiSize(pt) },
172 .flat_index => |flat| .{ flat.val, flat.flat_elem_index * flat.val.typeOf(zcu).arrayBase(zcu)[0].abiSize(zcu) },
172173 .reinterpret => |reinterpret| .{ reinterpret.val, reinterpret.byte_offset },
173174 else => unreachable,
174175 };
......@@ -347,8 +348,8 @@ fn loadComptimePtrInner(
347348 const load_one_ty, const load_count = load_ty.arrayBase(zcu);
348349
349350 const extra_base_index: u64 = if (ptr.byte_offset == 0) 0 else idx: {
350 if (try sema.typeRequiresComptime(load_one_ty)) break :restructure_array;
351 const elem_len = try sema.typeAbiSize(load_one_ty);
351 if (try load_one_ty.comptimeOnlySema(pt)) break :restructure_array;
352 const elem_len = try load_one_ty.abiSizeSema(pt);
352353 if (ptr.byte_offset % elem_len != 0) break :restructure_array;
353354 break :idx @divExact(ptr.byte_offset, elem_len);
354355 };
......@@ -394,12 +395,12 @@ fn loadComptimePtrInner(
394395 var cur_offset = ptr.byte_offset;
395396
396397 if (load_ty.zigTypeTag(zcu) == .Array and array_offset > 0) {
397 cur_offset += try sema.typeAbiSize(load_ty.childType(zcu)) * array_offset;
398 cur_offset += try load_ty.childType(zcu).abiSizeSema(pt) * array_offset;
398399 }
399400
400 const need_bytes = if (host_bits > 0) (host_bits + 7) / 8 else try sema.typeAbiSize(load_ty);
401 const need_bytes = if (host_bits > 0) (host_bits + 7) / 8 else try load_ty.abiSizeSema(pt);
401402
402 if (cur_offset + need_bytes > try sema.typeAbiSize(cur_val.typeOf(zcu))) {
403 if (cur_offset + need_bytes > try cur_val.typeOf(zcu).abiSizeSema(pt)) {
403404 return .{ .out_of_bounds = cur_val.typeOf(zcu) };
404405 }
405406
......@@ -434,7 +435,7 @@ fn loadComptimePtrInner(
434435 .Optional => break, // this can only be a pointer-like optional so is terminal
435436 .Array => {
436437 const elem_ty = cur_ty.childType(zcu);
437 const elem_size = try sema.typeAbiSize(elem_ty);
438 const elem_size = try elem_ty.abiSizeSema(pt);
438439 const elem_idx = cur_offset / elem_size;
439440 const next_elem_off = elem_size * (elem_idx + 1);
440441 if (cur_offset + need_bytes <= next_elem_off) {
......@@ -449,8 +450,8 @@ fn loadComptimePtrInner(
449450 .auto => unreachable, // ill-defined layout
450451 .@"packed" => break, // let the bitcast logic handle this
451452 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
452 const start_off = cur_ty.structFieldOffset(field_idx, pt);
453 const end_off = start_off + try sema.typeAbiSize(cur_ty.structFieldType(field_idx, zcu));
453 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
454 const end_off = start_off + try cur_ty.structFieldType(field_idx, zcu).abiSizeSema(pt);
454455 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
455456 cur_val = try cur_val.getElem(sema.pt, field_idx);
456457 cur_offset -= start_off;
......@@ -477,7 +478,7 @@ fn loadComptimePtrInner(
477478 };
478479 // The payload always has offset 0. If it's big enough
479480 // to represent the whole load type, we can use it.
480 if (try sema.typeAbiSize(payload.typeOf(zcu)) >= need_bytes) {
481 if (try payload.typeOf(zcu).abiSizeSema(pt) >= need_bytes) {
481482 cur_val = payload;
482483 } else {
483484 break;
......@@ -746,8 +747,8 @@ fn prepareComptimePtrStore(
746747
747748 const store_one_ty, const store_count = store_ty.arrayBase(zcu);
748749 const extra_base_index: u64 = if (ptr.byte_offset == 0) 0 else idx: {
749 if (try sema.typeRequiresComptime(store_one_ty)) break :restructure_array;
750 const elem_len = try sema.typeAbiSize(store_one_ty);
750 if (try store_one_ty.comptimeOnlySema(pt)) break :restructure_array;
751 const elem_len = try store_one_ty.abiSizeSema(pt);
751752 if (ptr.byte_offset % elem_len != 0) break :restructure_array;
752753 break :idx @divExact(ptr.byte_offset, elem_len);
753754 };
......@@ -800,11 +801,11 @@ fn prepareComptimePtrStore(
800801 var cur_val: *MutableValue, var cur_offset: u64 = switch (base_strat) {
801802 .direct => |direct| .{ direct.val, 0 },
802803 // It's okay to do `abiSize` - the comptime-only case will be caught below.
803 .index => |index| .{ index.val, index.elem_index * try sema.typeAbiSize(index.val.typeOf(zcu).childType(zcu)) },
804 .index => |index| .{ index.val, index.elem_index * try index.val.typeOf(zcu).childType(zcu).abiSizeSema(pt) },
804805 .flat_index => |flat_index| .{
805806 flat_index.val,
806807 // It's okay to do `abiSize` - the comptime-only case will be caught below.
807 flat_index.flat_elem_index * try sema.typeAbiSize(flat_index.val.typeOf(zcu).arrayBase(zcu)[0]),
808 flat_index.flat_elem_index * try flat_index.val.typeOf(zcu).arrayBase(zcu)[0].abiSizeSema(pt),
808809 },
809810 .reinterpret => |r| .{ r.val, r.byte_offset },
810811 else => unreachable,
......@@ -816,12 +817,12 @@ fn prepareComptimePtrStore(
816817 }
817818
818819 if (store_ty.zigTypeTag(zcu) == .Array and array_offset > 0) {
819 cur_offset += try sema.typeAbiSize(store_ty.childType(zcu)) * array_offset;
820 cur_offset += try store_ty.childType(zcu).abiSizeSema(pt) * array_offset;
820821 }
821822
822 const need_bytes = try sema.typeAbiSize(store_ty);
823 const need_bytes = try store_ty.abiSizeSema(pt);
823824
824 if (cur_offset + need_bytes > try sema.typeAbiSize(cur_val.typeOf(zcu))) {
825 if (cur_offset + need_bytes > try cur_val.typeOf(zcu).abiSizeSema(pt)) {
825826 return .{ .out_of_bounds = cur_val.typeOf(zcu) };
826827 }
827828
......@@ -856,7 +857,7 @@ fn prepareComptimePtrStore(
856857 .Optional => break, // this can only be a pointer-like optional so is terminal
857858 .Array => {
858859 const elem_ty = cur_ty.childType(zcu);
859 const elem_size = try sema.typeAbiSize(elem_ty);
860 const elem_size = try elem_ty.abiSizeSema(pt);
860861 const elem_idx = cur_offset / elem_size;
861862 const next_elem_off = elem_size * (elem_idx + 1);
862863 if (cur_offset + need_bytes <= next_elem_off) {
......@@ -871,8 +872,8 @@ fn prepareComptimePtrStore(
871872 .auto => unreachable, // ill-defined layout
872873 .@"packed" => break, // let the bitcast logic handle this
873874 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
874 const start_off = cur_ty.structFieldOffset(field_idx, pt);
875 const end_off = start_off + try sema.typeAbiSize(cur_ty.structFieldType(field_idx, zcu));
875 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
876 const end_off = start_off + try cur_ty.structFieldType(field_idx, zcu).abiSizeSema(pt);
876877 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
877878 cur_val = try cur_val.elem(pt, sema.arena, field_idx);
878879 cur_offset -= start_off;
......@@ -895,7 +896,7 @@ fn prepareComptimePtrStore(
895896 };
896897 // The payload always has offset 0. If it's big enough
897898 // to represent the whole load type, we can use it.
898 if (try sema.typeAbiSize(payload.typeOf(zcu)) >= need_bytes) {
899 if (try payload.typeOf(zcu).abiSizeSema(pt) >= need_bytes) {
899900 cur_val = payload;
900901 } else {
901902 break;
src/Type.zig+714-503
......@@ -10,8 +10,6 @@ const Value = @import("Value.zig");
1010const assert = std.debug.assert;
1111const Target = std.Target;
1212const Zcu = @import("Zcu.zig");
13/// Deprecated.
14const Module = Zcu;
1513const log = std.log.scoped(.Type);
1614const target_util = @import("target.zig");
1715const Sema = @import("Sema.zig");
......@@ -23,15 +21,15 @@ const SemaError = Zcu.SemaError;
2321
2422ip_index: InternPool.Index,
2523
26pub fn zigTypeTag(ty: Type, mod: *const Module) std.builtin.TypeId {
27 return ty.zigTypeTagOrPoison(mod) catch unreachable;
24pub fn zigTypeTag(ty: Type, zcu: *const Zcu) std.builtin.TypeId {
25 return ty.zigTypeTagOrPoison(zcu) catch unreachable;
2826}
2927
30pub fn zigTypeTagOrPoison(ty: Type, mod: *const Module) error{GenericPoison}!std.builtin.TypeId {
31 return mod.intern_pool.zigTypeTagOrPoison(ty.toIntern());
28pub fn zigTypeTagOrPoison(ty: Type, zcu: *const Zcu) error{GenericPoison}!std.builtin.TypeId {
29 return zcu.intern_pool.zigTypeTagOrPoison(ty.toIntern());
3230}
3331
34pub fn baseZigTypeTag(self: Type, mod: *Module) std.builtin.TypeId {
32pub fn baseZigTypeTag(self: Type, mod: *Zcu) std.builtin.TypeId {
3533 return switch (self.zigTypeTag(mod)) {
3634 .ErrorUnion => self.errorUnionPayload(mod).baseZigTypeTag(mod),
3735 .Optional => {
......@@ -41,15 +39,15 @@ pub fn baseZigTypeTag(self: Type, mod: *Module) std.builtin.TypeId {
4139 };
4240}
4341
44pub fn isSelfComparable(ty: Type, mod: *const Module, is_equality_cmp: bool) bool {
45 return switch (ty.zigTypeTag(mod)) {
42pub fn isSelfComparable(ty: Type, zcu: *const Zcu, is_equality_cmp: bool) bool {
43 return switch (ty.zigTypeTag(zcu)) {
4644 .Int,
4745 .Float,
4846 .ComptimeFloat,
4947 .ComptimeInt,
5048 => true,
5149
52 .Vector => ty.elemType2(mod).isSelfComparable(mod, is_equality_cmp),
50 .Vector => ty.elemType2(zcu).isSelfComparable(zcu, is_equality_cmp),
5351
5452 .Bool,
5553 .Type,
......@@ -72,25 +70,25 @@ pub fn isSelfComparable(ty: Type, mod: *const Module, is_equality_cmp: bool) boo
7270 .Frame,
7371 => false,
7472
75 .Pointer => !ty.isSlice(mod) and (is_equality_cmp or ty.isCPtr(mod)),
73 .Pointer => !ty.isSlice(zcu) and (is_equality_cmp or ty.isCPtr(zcu)),
7674 .Optional => {
7775 if (!is_equality_cmp) return false;
78 return ty.optionalChild(mod).isSelfComparable(mod, is_equality_cmp);
76 return ty.optionalChild(zcu).isSelfComparable(zcu, is_equality_cmp);
7977 },
8078 };
8179}
8280
8381/// If it is a function pointer, returns the function type. Otherwise returns null.
84pub fn castPtrToFn(ty: Type, mod: *const Module) ?Type {
85 if (ty.zigTypeTag(mod) != .Pointer) return null;
86 const elem_ty = ty.childType(mod);
87 if (elem_ty.zigTypeTag(mod) != .Fn) return null;
82pub fn castPtrToFn(ty: Type, zcu: *const Zcu) ?Type {
83 if (ty.zigTypeTag(zcu) != .Pointer) return null;
84 const elem_ty = ty.childType(zcu);
85 if (elem_ty.zigTypeTag(zcu) != .Fn) return null;
8886 return elem_ty;
8987}
9088
9189/// Asserts the type is a pointer.
92pub fn ptrIsMutable(ty: Type, mod: *const Module) bool {
93 return !mod.intern_pool.indexToKey(ty.toIntern()).ptr_type.flags.is_const;
90pub fn ptrIsMutable(ty: Type, zcu: *const Zcu) bool {
91 return !zcu.intern_pool.indexToKey(ty.toIntern()).ptr_type.flags.is_const;
9492}
9593
9694pub const ArrayInfo = struct {
......@@ -99,18 +97,18 @@ pub const ArrayInfo = struct {
9997 len: u64,
10098};
10199
102pub fn arrayInfo(self: Type, mod: *const Module) ArrayInfo {
100pub fn arrayInfo(self: Type, zcu: *const Zcu) ArrayInfo {
103101 return .{
104 .len = self.arrayLen(mod),
105 .sentinel = self.sentinel(mod),
106 .elem_type = self.childType(mod),
102 .len = self.arrayLen(zcu),
103 .sentinel = self.sentinel(zcu),
104 .elem_type = self.childType(zcu),
107105 };
108106}
109107
110pub fn ptrInfo(ty: Type, mod: *const Module) InternPool.Key.PtrType {
111 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
108pub fn ptrInfo(ty: Type, zcu: *const Zcu) InternPool.Key.PtrType {
109 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
112110 .ptr_type => |p| p,
113 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {
111 .opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) {
114112 .ptr_type => |p| p,
115113 else => unreachable,
116114 },
......@@ -118,8 +116,8 @@ pub fn ptrInfo(ty: Type, mod: *const Module) InternPool.Key.PtrType {
118116 };
119117}
120118
121pub fn eql(a: Type, b: Type, mod: *const Module) bool {
122 _ = mod; // TODO: remove this parameter
119pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
120 _ = zcu; // TODO: remove this parameter
123121 // The InternPool data structure hashes based on Key to make interned objects
124122 // unique. An Index can be treated simply as u32 value for the
125123 // purpose of Type/Value hashing and equality.
......@@ -179,8 +177,8 @@ pub fn dump(
179177/// Prints a name suitable for `@typeName`.
180178/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
181179pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error!void {
182 const mod = pt.zcu;
183 const ip = &mod.intern_pool;
180 const zcu = pt.zcu;
181 const ip = &zcu.intern_pool;
184182 switch (ip.indexToKey(ty.toIntern())) {
185183 .int_type => |int_type| {
186184 const sign_char: u8 = switch (int_type.signedness) {
......@@ -190,7 +188,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
190188 return writer.print("{c}{d}", .{ sign_char, int_type.bits });
191189 },
192190 .ptr_type => {
193 const info = ty.ptrInfo(mod);
191 const info = ty.ptrInfo(zcu);
194192
195193 if (info.sentinel != .none) switch (info.flags.size) {
196194 .One, .C => unreachable,
......@@ -210,7 +208,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
210208 const alignment = if (info.flags.alignment != .none)
211209 info.flags.alignment
212210 else
213 Type.fromInterned(info.child).abiAlignment(pt);
211 Type.fromInterned(info.child).abiAlignment(pt.zcu);
214212 try writer.print("align({d}", .{alignment.toByteUnits() orelse 0});
215213
216214 if (info.packed_offset.bit_offset != 0 or info.packed_offset.host_size != 0) {
......@@ -268,7 +266,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
268266 return;
269267 },
270268 .inferred_error_set_type => |func_index| {
271 const func_nav = ip.getNav(mod.funcInfo(func_index).owner_nav);
269 const func_nav = ip.getNav(zcu.funcInfo(func_index).owner_nav);
272270 try writer.print("@typeInfo(@typeInfo(@TypeOf({})).Fn.return_type.?).ErrorUnion.error_set", .{
273271 func_nav.fqn.fmt(ip),
274272 });
......@@ -338,7 +336,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
338336 try writer.writeAll("comptime ");
339337 }
340338 if (anon_struct.names.len != 0) {
341 try writer.print("{}: ", .{anon_struct.names.get(ip)[i].fmt(&mod.intern_pool)});
339 try writer.print("{}: ", .{anon_struct.names.get(ip)[i].fmt(&zcu.intern_pool)});
342340 }
343341
344342 try print(Type.fromInterned(field_ty), writer, pt);
......@@ -367,7 +365,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
367365 try writer.writeAll("noinline ");
368366 }
369367 try writer.writeAll("fn (");
370 const param_types = fn_info.param_types.get(&mod.intern_pool);
368 const param_types = fn_info.param_types.get(&zcu.intern_pool);
371369 for (param_types, 0..) |param_ty, i| {
372370 if (i != 0) try writer.writeAll(", ");
373371 if (std.math.cast(u5, i)) |index| {
......@@ -448,6 +446,21 @@ pub fn toValue(self: Type) Value {
448446
449447const RuntimeBitsError = SemaError || error{NeedLazy};
450448
449pub fn hasRuntimeBits(ty: Type, zcu: *Zcu) bool {
450 return hasRuntimeBitsInner(ty, false, .eager, zcu, {}) catch unreachable;
451}
452
453pub fn hasRuntimeBitsSema(ty: Type, pt: Zcu.PerThread) SemaError!bool {
454 return hasRuntimeBitsInner(ty, false, .sema, pt.zcu, pt.tid) catch |err| switch (err) {
455 error.NeedLazy => unreachable, // this would require a resolve strat of lazy
456 else => |e| return e,
457 };
458}
459
460pub fn hasRuntimeBitsIgnoreComptime(ty: Type, zcu: *Zcu) bool {
461 return hasRuntimeBitsInner(ty, true, .eager, zcu, {}) catch unreachable;
462}
463
451464/// true if and only if the type takes up space in memory at runtime.
452465/// There are two reasons a type will return false:
453466/// * the type is a comptime-only type. For example, the type `type` itself.
......@@ -459,14 +472,14 @@ const RuntimeBitsError = SemaError || error{NeedLazy};
459472/// making it one-possible-value only if the integer tag type has 0 bits.
460473/// When `ignore_comptime_only` is true, then types that are comptime-only
461474/// may return false positives.
462pub fn hasRuntimeBitsAdvanced(
475pub fn hasRuntimeBitsInner(
463476 ty: Type,
464 pt: Zcu.PerThread,
465477 ignore_comptime_only: bool,
466478 comptime strat: ResolveStratLazy,
479 zcu: *Zcu,
480 tid: strat.Tid(),
467481) RuntimeBitsError!bool {
468 const mod = pt.zcu;
469 const ip = &mod.intern_pool;
482 const ip = &zcu.intern_pool;
470483 return switch (ty.toIntern()) {
471484 // False because it is a comptime-only type.
472485 .empty_struct_type => false,
......@@ -477,26 +490,29 @@ pub fn hasRuntimeBitsAdvanced(
477490 // to comptime-only types do not, with the exception of function pointers.
478491 if (ignore_comptime_only) return true;
479492 return switch (strat) {
480 .sema => !try ty.comptimeOnlyAdvanced(pt, .sema),
481 .eager => !ty.comptimeOnly(pt),
493 .sema => {
494 const pt = strat.pt(zcu, tid);
495 return !try ty.comptimeOnlySema(pt);
496 },
497 .eager => !ty.comptimeOnly(zcu),
482498 .lazy => error.NeedLazy,
483499 };
484500 },
485501 .anyframe_type => true,
486502 .array_type => |array_type| return array_type.lenIncludingSentinel() > 0 and
487 try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat),
503 try Type.fromInterned(array_type.child).hasRuntimeBitsInner(ignore_comptime_only, strat, zcu, tid),
488504 .vector_type => |vector_type| return vector_type.len > 0 and
489 try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat),
505 try Type.fromInterned(vector_type.child).hasRuntimeBitsInner(ignore_comptime_only, strat, zcu, tid),
490506 .opt_type => |child| {
491507 const child_ty = Type.fromInterned(child);
492 if (child_ty.isNoReturn(mod)) {
508 if (child_ty.isNoReturn(zcu)) {
493509 // Then the optional is comptime-known to be null.
494510 return false;
495511 }
496512 if (ignore_comptime_only) return true;
497513 return switch (strat) {
498 .sema => !try child_ty.comptimeOnlyAdvanced(pt, .sema),
499 .eager => !child_ty.comptimeOnly(pt),
514 .sema => !try child_ty.comptimeOnlyInner(.sema, zcu, tid),
515 .eager => !child_ty.comptimeOnly(zcu),
500516 .lazy => error.NeedLazy,
501517 };
502518 },
......@@ -556,14 +572,14 @@ pub fn hasRuntimeBitsAdvanced(
556572 return true;
557573 }
558574 switch (strat) {
559 .sema => try ty.resolveFields(pt),
575 .sema => try ty.resolveFields(strat.pt(zcu, tid)),
560576 .eager => assert(struct_type.haveFieldTypes(ip)),
561577 .lazy => if (!struct_type.haveFieldTypes(ip)) return error.NeedLazy,
562578 }
563579 for (0..struct_type.field_types.len) |i| {
564580 if (struct_type.comptime_bits.getBit(ip, i)) continue;
565581 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
566 if (try field_ty.hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat))
582 if (try field_ty.hasRuntimeBitsInner(ignore_comptime_only, strat, zcu, tid))
567583 return true;
568584 } else {
569585 return false;
......@@ -572,7 +588,12 @@ pub fn hasRuntimeBitsAdvanced(
572588 .anon_struct_type => |tuple| {
573589 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
574590 if (val != .none) continue; // comptime field
575 if (try Type.fromInterned(field_ty).hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat)) return true;
591 if (try Type.fromInterned(field_ty).hasRuntimeBitsInner(
592 ignore_comptime_only,
593 strat,
594 zcu,
595 tid,
596 )) return true;
576597 }
577598 return false;
578599 },
......@@ -591,21 +612,25 @@ pub fn hasRuntimeBitsAdvanced(
591612 // tag_ty will be `none` if this union's tag type is not resolved yet,
592613 // in which case we want control flow to continue down below.
593614 if (tag_ty != .none and
594 try Type.fromInterned(tag_ty).hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat))
595 {
615 try Type.fromInterned(tag_ty).hasRuntimeBitsInner(
616 ignore_comptime_only,
617 strat,
618 zcu,
619 tid,
620 )) {
596621 return true;
597622 }
598623 },
599624 }
600625 switch (strat) {
601 .sema => try ty.resolveFields(pt),
626 .sema => try ty.resolveFields(strat.pt(zcu, tid)),
602627 .eager => assert(union_flags.status.haveFieldTypes()),
603628 .lazy => if (!union_flags.status.haveFieldTypes())
604629 return error.NeedLazy,
605630 }
606631 for (0..union_type.field_types.len) |field_index| {
607632 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
608 if (try field_ty.hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat))
633 if (try field_ty.hasRuntimeBitsInner(ignore_comptime_only, strat, zcu, tid))
609634 return true;
610635 } else {
611636 return false;
......@@ -613,7 +638,12 @@ pub fn hasRuntimeBitsAdvanced(
613638 },
614639
615640 .opaque_type => true,
616 .enum_type => Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat),
641 .enum_type => Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).hasRuntimeBitsInner(
642 ignore_comptime_only,
643 strat,
644 zcu,
645 tid,
646 ),
617647
618648 // values, not types
619649 .undef,
......@@ -643,8 +673,8 @@ pub fn hasRuntimeBitsAdvanced(
643673/// true if and only if the type has a well-defined memory layout
644674/// readFrom/writeToMemory are supported only for types with a well-
645675/// defined memory layout
646pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
647 const ip = &mod.intern_pool;
676pub fn hasWellDefinedLayout(ty: Type, zcu: *const Zcu) bool {
677 const ip = &zcu.intern_pool;
648678 return switch (ip.indexToKey(ty.toIntern())) {
649679 .int_type,
650680 .vector_type,
......@@ -660,8 +690,8 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
660690 .func_type,
661691 => false,
662692
663 .array_type => |array_type| Type.fromInterned(array_type.child).hasWellDefinedLayout(mod),
664 .opt_type => ty.isPtrLikeOptional(mod),
693 .array_type => |array_type| Type.fromInterned(array_type.child).hasWellDefinedLayout(zcu),
694 .opt_type => ty.isPtrLikeOptional(zcu),
665695 .ptr_type => |ptr_type| ptr_type.flags.size != .Slice,
666696
667697 .simple_type => |t| switch (t) {
......@@ -740,94 +770,99 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
740770 };
741771}
742772
743pub fn hasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool {
744 return hasRuntimeBitsAdvanced(ty, pt, false, .eager) catch unreachable;
773pub fn fnHasRuntimeBits(ty: Type, zcu: *Zcu) bool {
774 return ty.fnHasRuntimeBitsInner(.normal, zcu, {}) catch unreachable;
745775}
746776
747pub fn hasRuntimeBitsIgnoreComptime(ty: Type, pt: Zcu.PerThread) bool {
748 return hasRuntimeBitsAdvanced(ty, pt, true, .eager) catch unreachable;
749}
750
751pub fn fnHasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool {
752 return ty.fnHasRuntimeBitsAdvanced(pt, .normal) catch unreachable;
777pub fn fnHasRuntimeBitsSema(ty: Type, pt: Zcu.PerThread) SemaError!bool {
778 return try ty.fnHasRuntimeBitsInner(.sema, pt.zcu, pt.tid);
753779}
754780
755781/// Determines whether a function type has runtime bits, i.e. whether a
756782/// function with this type can exist at runtime.
757783/// Asserts that `ty` is a function type.
758pub fn fnHasRuntimeBitsAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) SemaError!bool {
759 const fn_info = pt.zcu.typeToFunc(ty).?;
784pub fn fnHasRuntimeBitsInner(
785 ty: Type,
786 comptime strat: ResolveStrat,
787 zcu: *Zcu,
788 tid: strat.Tid(),
789) SemaError!bool {
790 const fn_info = zcu.typeToFunc(ty).?;
760791 if (fn_info.is_generic) return false;
761792 if (fn_info.is_var_args) return true;
762793 if (fn_info.cc == .Inline) return false;
763 return !try Type.fromInterned(fn_info.return_type).comptimeOnlyAdvanced(pt, strat);
794 return !try Type.fromInterned(fn_info.return_type).comptimeOnlyInner(strat, zcu, tid);
764795}
765796
766pub fn isFnOrHasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool {
767 switch (ty.zigTypeTag(pt.zcu)) {
768 .Fn => return ty.fnHasRuntimeBits(pt),
769 else => return ty.hasRuntimeBits(pt),
797pub fn isFnOrHasRuntimeBits(ty: Type, zcu: *Zcu) bool {
798 switch (ty.zigTypeTag(zcu)) {
799 .Fn => return ty.fnHasRuntimeBits(zcu),
800 else => return ty.hasRuntimeBits(zcu),
770801 }
771802}
772803
773804/// Same as `isFnOrHasRuntimeBits` but comptime-only types may return a false positive.
774pub fn isFnOrHasRuntimeBitsIgnoreComptime(ty: Type, pt: Zcu.PerThread) bool {
775 return switch (ty.zigTypeTag(pt.zcu)) {
805pub fn isFnOrHasRuntimeBitsIgnoreComptime(ty: Type, zcu: *Zcu) bool {
806 return switch (ty.zigTypeTag(zcu)) {
776807 .Fn => true,
777 else => return ty.hasRuntimeBitsIgnoreComptime(pt),
808 else => return ty.hasRuntimeBitsIgnoreComptime(zcu),
778809 };
779810}
780811
781pub fn isNoReturn(ty: Type, mod: *Module) bool {
782 return mod.intern_pool.isNoReturn(ty.toIntern());
812pub fn isNoReturn(ty: Type, zcu: *const Zcu) bool {
813 return zcu.intern_pool.isNoReturn(ty.toIntern());
783814}
784815
785816/// Returns `none` if the pointer is naturally aligned and the element type is 0-bit.
786pub fn ptrAlignment(ty: Type, pt: Zcu.PerThread) Alignment {
787 return ptrAlignmentAdvanced(ty, pt, .normal) catch unreachable;
817pub fn ptrAlignment(ty: Type, zcu: *Zcu) Alignment {
818 return ptrAlignmentInner(ty, .normal, zcu, {}) catch unreachable;
819}
820
821pub fn ptrAlignmentSema(ty: Type, pt: Zcu.PerThread) SemaError!Alignment {
822 return try ty.ptrAlignmentInner(.sema, pt.zcu, pt.tid);
788823}
789824
790pub fn ptrAlignmentAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment {
791 return switch (pt.zcu.intern_pool.indexToKey(ty.toIntern())) {
825pub fn ptrAlignmentInner(
826 ty: Type,
827 comptime strat: ResolveStrat,
828 zcu: *Zcu,
829 tid: strat.Tid(),
830) !Alignment {
831 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
792832 .ptr_type => |ptr_type| {
793833 if (ptr_type.flags.alignment != .none)
794834 return ptr_type.flags.alignment;
795835
796836 if (strat == .sema) {
797 const res = try Type.fromInterned(ptr_type.child).abiAlignmentAdvanced(pt, .sema);
837 const res = try Type.fromInterned(ptr_type.child).abiAlignmentInner(.sema, zcu, tid);
798838 return res.scalar;
799839 }
800840
801 return (Type.fromInterned(ptr_type.child).abiAlignmentAdvanced(pt, .eager) catch unreachable).scalar;
841 return Type.fromInterned(ptr_type.child).abiAlignment(zcu);
802842 },
803 .opt_type => |child| Type.fromInterned(child).ptrAlignmentAdvanced(pt, strat),
843 .opt_type => |child| Type.fromInterned(child).ptrAlignmentInner(strat, zcu, tid),
804844 else => unreachable,
805845 };
806846}
807847
808pub fn ptrAddressSpace(ty: Type, mod: *const Module) std.builtin.AddressSpace {
809 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
848pub fn ptrAddressSpace(ty: Type, zcu: *const Zcu) std.builtin.AddressSpace {
849 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
810850 .ptr_type => |ptr_type| ptr_type.flags.address_space,
811 .opt_type => |child| mod.intern_pool.indexToKey(child).ptr_type.flags.address_space,
851 .opt_type => |child| zcu.intern_pool.indexToKey(child).ptr_type.flags.address_space,
812852 else => unreachable,
813853 };
814854}
815855
816/// Never returns `none`. Asserts that all necessary type resolution is already done.
817pub fn abiAlignment(ty: Type, pt: Zcu.PerThread) Alignment {
818 return (ty.abiAlignmentAdvanced(pt, .eager) catch unreachable).scalar;
819}
820
821856/// May capture a reference to `ty`.
822857/// Returned value has type `comptime_int`.
823858pub fn lazyAbiAlignment(ty: Type, pt: Zcu.PerThread) !Value {
824 switch (try ty.abiAlignmentAdvanced(pt, .lazy)) {
859 switch (try ty.abiAlignmentInner(.lazy, pt.zcu, pt.tid)) {
825860 .val => |val| return val,
826861 .scalar => |x| return pt.intValue(Type.comptime_int, x.toByteUnits() orelse 0),
827862 }
828863}
829864
830pub const AbiAlignmentAdvanced = union(enum) {
865pub const AbiAlignmentInner = union(enum) {
831866 scalar: Alignment,
832867 val: Value,
833868};
......@@ -842,6 +877,23 @@ pub const ResolveStratLazy = enum {
842877 /// Return a scalar result, performing type resolution as necessary.
843878 /// This should typically be used from semantic analysis.
844879 sema,
880
881 pub fn Tid(comptime strat: ResolveStratLazy) type {
882 return switch (strat) {
883 .lazy, .sema => Zcu.PerThread.Id,
884 .eager => void,
885 };
886 }
887
888 pub fn pt(comptime strat: ResolveStratLazy, zcu: *Zcu, tid: strat.Tid()) switch (strat) {
889 .lazy, .sema => Zcu.PerThread,
890 .eager => void,
891 } {
892 return switch (strat) {
893 .lazy, .sema => .{ .tid = tid, .zcu = zcu },
894 else => {},
895 };
896 }
845897};
846898
847899/// The chosen strategy can be easily optimized away in release builds.
......@@ -854,6 +906,23 @@ pub const ResolveStrat = enum {
854906 /// This should typically be used from semantic analysis.
855907 sema,
856908
909 pub fn Tid(comptime strat: ResolveStrat) type {
910 return switch (strat) {
911 .sema => Zcu.PerThread.Id,
912 .normal => void,
913 };
914 }
915
916 pub fn pt(comptime strat: ResolveStrat, zcu: *Zcu, tid: strat.Tid()) switch (strat) {
917 .sema => Zcu.PerThread,
918 .normal => void,
919 } {
920 return switch (strat) {
921 .sema => .{ .tid = tid, .zcu = zcu },
922 .normal => {},
923 };
924 }
925
857926 pub inline fn toLazy(strat: ResolveStrat) ResolveStratLazy {
858927 return switch (strat) {
859928 .normal => .eager,
......@@ -862,21 +931,31 @@ pub const ResolveStrat = enum {
862931 }
863932};
864933
934/// Never returns `none`. Asserts that all necessary type resolution is already done.
935pub fn abiAlignment(ty: Type, zcu: *Zcu) Alignment {
936 return (ty.abiAlignmentInner(.eager, zcu, {}) catch unreachable).scalar;
937}
938
939pub fn abiAlignmentSema(ty: Type, pt: Zcu.PerThread) SemaError!Alignment {
940 return (try ty.abiAlignmentInner(.sema, pt.zcu, pt.tid)).scalar;
941}
942
865943/// If you pass `eager` you will get back `scalar` and assert the type is resolved.
866944/// In this case there will be no error, guaranteed.
867945/// If you pass `lazy` you may get back `scalar` or `val`.
868946/// If `val` is returned, a reference to `ty` has been captured.
869947/// If you pass `sema` you will get back `scalar` and resolve the type if
870948/// necessary, possibly returning a CompileError.
871pub fn abiAlignmentAdvanced(
949pub fn abiAlignmentInner(
872950 ty: Type,
873 pt: Zcu.PerThread,
874951 comptime strat: ResolveStratLazy,
875) SemaError!AbiAlignmentAdvanced {
876 const mod = pt.zcu;
877 const target = mod.getTarget();
878 const use_llvm = mod.comp.config.use_llvm;
879 const ip = &mod.intern_pool;
952 zcu: *Zcu,
953 tid: strat.Tid(),
954) SemaError!AbiAlignmentInner {
955 const pt = strat.pt(zcu, tid);
956 const target = zcu.getTarget();
957 const use_llvm = zcu.comp.config.use_llvm;
958 const ip = &zcu.intern_pool;
880959
881960 switch (ty.toIntern()) {
882961 .empty_struct_type => return .{ .scalar = .@"1" },
......@@ -889,22 +968,22 @@ pub fn abiAlignmentAdvanced(
889968 return .{ .scalar = ptrAbiAlignment(target) };
890969 },
891970 .array_type => |array_type| {
892 return Type.fromInterned(array_type.child).abiAlignmentAdvanced(pt, strat);
971 return Type.fromInterned(array_type.child).abiAlignmentInner(strat, zcu, tid);
893972 },
894973 .vector_type => |vector_type| {
895974 if (vector_type.len == 0) return .{ .scalar = .@"1" };
896 switch (mod.comp.getZigBackend()) {
975 switch (zcu.comp.getZigBackend()) {
897976 else => {
898977 // This is fine because the child type of a vector always has a bit-size known
899978 // without needing any type resolution.
900 const elem_bits: u32 = @intCast(Type.fromInterned(vector_type.child).bitSize(pt));
979 const elem_bits: u32 = @intCast(Type.fromInterned(vector_type.child).bitSize(zcu));
901980 if (elem_bits == 0) return .{ .scalar = .@"1" };
902981 const bytes = ((elem_bits * vector_type.len) + 7) / 8;
903982 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
904983 return .{ .scalar = Alignment.fromByteUnits(alignment) };
905984 },
906985 .stage2_c => {
907 return Type.fromInterned(vector_type.child).abiAlignmentAdvanced(pt, strat);
986 return Type.fromInterned(vector_type.child).abiAlignmentInner(strat, zcu, tid);
908987 },
909988 .stage2_x86_64 => {
910989 if (vector_type.child == .bool_type) {
......@@ -915,7 +994,7 @@ pub fn abiAlignmentAdvanced(
915994 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
916995 return .{ .scalar = Alignment.fromByteUnits(alignment) };
917996 }
918 const elem_bytes: u32 = @intCast((try Type.fromInterned(vector_type.child).abiSizeAdvanced(pt, strat)).scalar);
997 const elem_bytes: u32 = @intCast((try Type.fromInterned(vector_type.child).abiSizeInner(strat, zcu, tid)).scalar);
919998 if (elem_bytes == 0) return .{ .scalar = .@"1" };
920999 const bytes = elem_bytes * vector_type.len;
9211000 if (bytes > 32 and std.Target.x86.featureSetHas(target.cpu.features, .avx512f)) return .{ .scalar = .@"64" };
......@@ -925,11 +1004,16 @@ pub fn abiAlignmentAdvanced(
9251004 }
9261005 },
9271006
928 .opt_type => return ty.abiAlignmentAdvancedOptional(pt, strat),
929 .error_union_type => |info| return ty.abiAlignmentAdvancedErrorUnion(pt, strat, Type.fromInterned(info.payload_type)),
1007 .opt_type => return ty.abiAlignmentInnerOptional(strat, zcu, tid),
1008 .error_union_type => |info| return ty.abiAlignmentInnerErrorUnion(
1009 strat,
1010 zcu,
1011 tid,
1012 Type.fromInterned(info.payload_type),
1013 ),
9301014
9311015 .error_set_type, .inferred_error_set_type => {
932 const bits = mod.errorSetBits();
1016 const bits = zcu.errorSetBits();
9331017 if (bits == 0) return .{ .scalar = .@"1" };
9341018 return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };
9351019 },
......@@ -965,7 +1049,7 @@ pub fn abiAlignmentAdvanced(
9651049 },
9661050 .f80 => switch (target.cTypeBitSize(.longdouble)) {
9671051 80 => return .{ .scalar = cTypeAlign(target, .longdouble) },
968 else => return .{ .scalar = Type.u80.abiAlignment(pt) },
1052 else => return .{ .scalar = Type.u80.abiAlignment(zcu) },
9691053 },
9701054 .f128 => switch (target.cTypeBitSize(.longdouble)) {
9711055 128 => return .{ .scalar = cTypeAlign(target, .longdouble) },
......@@ -973,7 +1057,7 @@ pub fn abiAlignmentAdvanced(
9731057 },
9741058
9751059 .anyerror, .adhoc_inferred_error_set => {
976 const bits = mod.errorSetBits();
1060 const bits = zcu.errorSetBits();
9771061 if (bits == 0) return .{ .scalar = .@"1" };
9781062 return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };
9791063 },
......@@ -1003,7 +1087,7 @@ pub fn abiAlignmentAdvanced(
10031087 },
10041088 .eager => {},
10051089 }
1006 return .{ .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiAlignment(pt) };
1090 return .{ .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiAlignment(zcu) };
10071091 }
10081092
10091093 if (struct_type.flagsUnordered(ip).alignment == .none) switch (strat) {
......@@ -1021,11 +1105,11 @@ pub fn abiAlignmentAdvanced(
10211105 var big_align: Alignment = .@"1";
10221106 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
10231107 if (val != .none) continue; // comptime field
1024 switch (try Type.fromInterned(field_ty).abiAlignmentAdvanced(pt, strat)) {
1108 switch (try Type.fromInterned(field_ty).abiAlignmentInner(strat, zcu, tid)) {
10251109 .scalar => |field_align| big_align = big_align.max(field_align),
10261110 .val => switch (strat) {
10271111 .eager => unreachable, // field type alignment not resolved
1028 .sema => unreachable, // passed to abiAlignmentAdvanced above
1112 .sema => unreachable, // passed to abiAlignmentInner above
10291113 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
10301114 .ty = .comptime_int_type,
10311115 .storage = .{ .lazy_align = ty.toIntern() },
......@@ -1051,7 +1135,7 @@ pub fn abiAlignmentAdvanced(
10511135 },
10521136 .opaque_type => return .{ .scalar = .@"1" },
10531137 .enum_type => return .{
1054 .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiAlignment(pt),
1138 .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiAlignment(zcu),
10551139 },
10561140
10571141 // values, not types
......@@ -1079,32 +1163,37 @@ pub fn abiAlignmentAdvanced(
10791163 }
10801164}
10811165
1082fn abiAlignmentAdvancedErrorUnion(
1166fn abiAlignmentInnerErrorUnion(
10831167 ty: Type,
1084 pt: Zcu.PerThread,
10851168 comptime strat: ResolveStratLazy,
1169 zcu: *Zcu,
1170 tid: strat.Tid(),
10861171 payload_ty: Type,
1087) SemaError!AbiAlignmentAdvanced {
1172) SemaError!AbiAlignmentInner {
10881173 // This code needs to be kept in sync with the equivalent switch prong
1089 // in abiSizeAdvanced.
1090 const code_align = Type.anyerror.abiAlignment(pt);
1174 // in abiSizeInner.
1175 const code_align = Type.anyerror.abiAlignment(zcu);
10911176 switch (strat) {
10921177 .eager, .sema => {
1093 if (!(payload_ty.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {
1094 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1095 .ty = .comptime_int_type,
1096 .storage = .{ .lazy_align = ty.toIntern() },
1097 } })) },
1178 if (!(payload_ty.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1179 error.NeedLazy => if (strat == .lazy) {
1180 const pt = strat.pt(zcu, tid);
1181 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1182 .ty = .comptime_int_type,
1183 .storage = .{ .lazy_align = ty.toIntern() },
1184 } })) };
1185 } else unreachable,
10981186 else => |e| return e,
10991187 })) {
11001188 return .{ .scalar = code_align };
11011189 }
11021190 return .{ .scalar = code_align.max(
1103 (try payload_ty.abiAlignmentAdvanced(pt, strat)).scalar,
1191 (try payload_ty.abiAlignmentInner(strat, zcu, tid)).scalar,
11041192 ) };
11051193 },
11061194 .lazy => {
1107 switch (try payload_ty.abiAlignmentAdvanced(pt, strat)) {
1195 const pt = strat.pt(zcu, tid);
1196 switch (try payload_ty.abiAlignmentInner(strat, zcu, tid)) {
11081197 .scalar => |payload_align| return .{ .scalar = code_align.max(payload_align) },
11091198 .val => {},
11101199 }
......@@ -1116,36 +1205,39 @@ fn abiAlignmentAdvancedErrorUnion(
11161205 }
11171206}
11181207
1119fn abiAlignmentAdvancedOptional(
1208fn abiAlignmentInnerOptional(
11201209 ty: Type,
1121 pt: Zcu.PerThread,
11221210 comptime strat: ResolveStratLazy,
1123) SemaError!AbiAlignmentAdvanced {
1124 const mod = pt.zcu;
1125 const target = mod.getTarget();
1126 const child_type = ty.optionalChild(mod);
1127
1128 switch (child_type.zigTypeTag(mod)) {
1211 zcu: *Zcu,
1212 tid: strat.Tid(),
1213) SemaError!AbiAlignmentInner {
1214 const pt = strat.pt(zcu, tid);
1215 const target = zcu.getTarget();
1216 const child_type = ty.optionalChild(zcu);
1217
1218 switch (child_type.zigTypeTag(zcu)) {
11291219 .Pointer => return .{ .scalar = ptrAbiAlignment(target) },
1130 .ErrorSet => return Type.anyerror.abiAlignmentAdvanced(pt, strat),
1220 .ErrorSet => return Type.anyerror.abiAlignmentInner(strat, zcu, tid),
11311221 .NoReturn => return .{ .scalar = .@"1" },
11321222 else => {},
11331223 }
11341224
11351225 switch (strat) {
11361226 .eager, .sema => {
1137 if (!(child_type.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {
1138 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1139 .ty = .comptime_int_type,
1140 .storage = .{ .lazy_align = ty.toIntern() },
1141 } })) },
1227 if (!(child_type.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1228 error.NeedLazy => if (strat == .lazy) {
1229 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1230 .ty = .comptime_int_type,
1231 .storage = .{ .lazy_align = ty.toIntern() },
1232 } })) };
1233 } else unreachable,
11421234 else => |e| return e,
11431235 })) {
11441236 return .{ .scalar = .@"1" };
11451237 }
1146 return child_type.abiAlignmentAdvanced(pt, strat);
1238 return child_type.abiAlignmentInner(strat, zcu, tid);
11471239 },
1148 .lazy => switch (try child_type.abiAlignmentAdvanced(pt, strat)) {
1240 .lazy => switch (try child_type.abiAlignmentInner(strat, zcu, tid)) {
11491241 .scalar => |x| return .{ .scalar = x.max(.@"1") },
11501242 .val => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
11511243 .ty = .comptime_int_type,
......@@ -1155,40 +1247,44 @@ fn abiAlignmentAdvancedOptional(
11551247 }
11561248}
11571249
1250const AbiSizeInner = union(enum) {
1251 scalar: u64,
1252 val: Value,
1253};
1254
1255/// Asserts the type has the ABI size already resolved.
1256/// Types that return false for hasRuntimeBits() return 0.
1257pub fn abiSize(ty: Type, zcu: *Zcu) u64 {
1258 return (abiSizeInner(ty, .eager, zcu, {}) catch unreachable).scalar;
1259}
1260
11581261/// May capture a reference to `ty`.
11591262pub fn lazyAbiSize(ty: Type, pt: Zcu.PerThread) !Value {
1160 switch (try ty.abiSizeAdvanced(pt, .lazy)) {
1263 switch (try ty.abiSizeInner(.lazy, pt.zcu, pt.tid)) {
11611264 .val => |val| return val,
11621265 .scalar => |x| return pt.intValue(Type.comptime_int, x),
11631266 }
11641267}
11651268
1166/// Asserts the type has the ABI size already resolved.
1167/// Types that return false for hasRuntimeBits() return 0.
1168pub fn abiSize(ty: Type, pt: Zcu.PerThread) u64 {
1169 return (abiSizeAdvanced(ty, pt, .eager) catch unreachable).scalar;
1269pub fn abiSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {
1270 return (try abiSizeInner(ty, .sema, pt.zcu, pt.tid)).scalar;
11701271}
11711272
1172const AbiSizeAdvanced = union(enum) {
1173 scalar: u64,
1174 val: Value,
1175};
1176
11771273/// If you pass `eager` you will get back `scalar` and assert the type is resolved.
11781274/// In this case there will be no error, guaranteed.
11791275/// If you pass `lazy` you may get back `scalar` or `val`.
11801276/// If `val` is returned, a reference to `ty` has been captured.
11811277/// If you pass `sema` you will get back `scalar` and resolve the type if
11821278/// necessary, possibly returning a CompileError.
1183pub fn abiSizeAdvanced(
1279pub fn abiSizeInner(
11841280 ty: Type,
1185 pt: Zcu.PerThread,
11861281 comptime strat: ResolveStratLazy,
1187) SemaError!AbiSizeAdvanced {
1188 const mod = pt.zcu;
1189 const target = mod.getTarget();
1190 const use_llvm = mod.comp.config.use_llvm;
1191 const ip = &mod.intern_pool;
1282 zcu: *Zcu,
1283 tid: strat.Tid(),
1284) SemaError!AbiSizeInner {
1285 const target = zcu.getTarget();
1286 const use_llvm = zcu.comp.config.use_llvm;
1287 const ip = &zcu.intern_pool;
11921288
11931289 switch (ty.toIntern()) {
11941290 .empty_struct_type => return .{ .scalar = 0 },
......@@ -1207,14 +1303,17 @@ pub fn abiSizeAdvanced(
12071303 .array_type => |array_type| {
12081304 const len = array_type.lenIncludingSentinel();
12091305 if (len == 0) return .{ .scalar = 0 };
1210 switch (try Type.fromInterned(array_type.child).abiSizeAdvanced(pt, strat)) {
1306 switch (try Type.fromInterned(array_type.child).abiSizeInner(strat, zcu, tid)) {
12111307 .scalar => |elem_size| return .{ .scalar = len * elem_size },
12121308 .val => switch (strat) {
12131309 .sema, .eager => unreachable,
1214 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1215 .ty = .comptime_int_type,
1216 .storage = .{ .lazy_size = ty.toIntern() },
1217 } })) },
1310 .lazy => {
1311 const pt = strat.pt(zcu, tid);
1312 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1313 .ty = .comptime_int_type,
1314 .storage = .{ .lazy_size = ty.toIntern() },
1315 } })) };
1316 },
12181317 },
12191318 }
12201319 },
......@@ -1222,41 +1321,38 @@ pub fn abiSizeAdvanced(
12221321 const sub_strat: ResolveStrat = switch (strat) {
12231322 .sema => .sema,
12241323 .eager => .normal,
1225 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1226 .ty = .comptime_int_type,
1227 .storage = .{ .lazy_size = ty.toIntern() },
1228 } })) },
1229 };
1230 const alignment = switch (try ty.abiAlignmentAdvanced(pt, strat)) {
1231 .scalar => |x| x,
1232 .val => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1233 .ty = .comptime_int_type,
1234 .storage = .{ .lazy_size = ty.toIntern() },
1235 } })) },
1324 .lazy => {
1325 const pt = strat.pt(zcu, tid);
1326 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1327 .ty = .comptime_int_type,
1328 .storage = .{ .lazy_size = ty.toIntern() },
1329 } })) };
1330 },
12361331 };
1237 const total_bytes = switch (mod.comp.getZigBackend()) {
1332 const alignment = (try ty.abiAlignmentInner(strat, zcu, tid)).scalar;
1333 const total_bytes = switch (zcu.comp.getZigBackend()) {
12381334 else => total_bytes: {
1239 const elem_bits = try Type.fromInterned(vector_type.child).bitSizeAdvanced(pt, sub_strat);
1335 const elem_bits = try Type.fromInterned(vector_type.child).bitSizeInner(sub_strat, zcu, tid);
12401336 const total_bits = elem_bits * vector_type.len;
12411337 break :total_bytes (total_bits + 7) / 8;
12421338 },
12431339 .stage2_c => total_bytes: {
1244 const elem_bytes: u32 = @intCast((try Type.fromInterned(vector_type.child).abiSizeAdvanced(pt, strat)).scalar);
1340 const elem_bytes: u32 = @intCast((try Type.fromInterned(vector_type.child).abiSizeInner(strat, zcu, tid)).scalar);
12451341 break :total_bytes elem_bytes * vector_type.len;
12461342 },
12471343 .stage2_x86_64 => total_bytes: {
12481344 if (vector_type.child == .bool_type) break :total_bytes std.math.divCeil(u32, vector_type.len, 8) catch unreachable;
1249 const elem_bytes: u32 = @intCast((try Type.fromInterned(vector_type.child).abiSizeAdvanced(pt, strat)).scalar);
1345 const elem_bytes: u32 = @intCast((try Type.fromInterned(vector_type.child).abiSizeInner(strat, zcu, tid)).scalar);
12501346 break :total_bytes elem_bytes * vector_type.len;
12511347 },
12521348 };
12531349 return .{ .scalar = alignment.forward(total_bytes) };
12541350 },
12551351
1256 .opt_type => return ty.abiSizeAdvancedOptional(pt, strat),
1352 .opt_type => return ty.abiSizeInnerOptional(strat, zcu, tid),
12571353
12581354 .error_set_type, .inferred_error_set_type => {
1259 const bits = mod.errorSetBits();
1355 const bits = zcu.errorSetBits();
12601356 if (bits == 0) return .{ .scalar = 0 };
12611357 return .{ .scalar = intAbiSize(bits, target, use_llvm) };
12621358 },
......@@ -1264,29 +1360,35 @@ pub fn abiSizeAdvanced(
12641360 .error_union_type => |error_union_type| {
12651361 const payload_ty = Type.fromInterned(error_union_type.payload_type);
12661362 // This code needs to be kept in sync with the equivalent switch prong
1267 // in abiAlignmentAdvanced.
1268 const code_size = Type.anyerror.abiSize(pt);
1269 if (!(payload_ty.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {
1270 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1271 .ty = .comptime_int_type,
1272 .storage = .{ .lazy_size = ty.toIntern() },
1273 } })) },
1363 // in abiAlignmentInner.
1364 const code_size = Type.anyerror.abiSize(zcu);
1365 if (!(payload_ty.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1366 error.NeedLazy => if (strat == .lazy) {
1367 const pt = strat.pt(zcu, tid);
1368 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1369 .ty = .comptime_int_type,
1370 .storage = .{ .lazy_size = ty.toIntern() },
1371 } })) };
1372 } else unreachable,
12741373 else => |e| return e,
12751374 })) {
12761375 // Same as anyerror.
12771376 return .{ .scalar = code_size };
12781377 }
1279 const code_align = Type.anyerror.abiAlignment(pt);
1280 const payload_align = payload_ty.abiAlignment(pt);
1281 const payload_size = switch (try payload_ty.abiSizeAdvanced(pt, strat)) {
1378 const code_align = Type.anyerror.abiAlignment(zcu);
1379 const payload_align = (try payload_ty.abiAlignmentInner(strat, zcu, tid)).scalar;
1380 const payload_size = switch (try payload_ty.abiSizeInner(strat, zcu, tid)) {
12821381 .scalar => |elem_size| elem_size,
12831382 .val => switch (strat) {
12841383 .sema => unreachable,
12851384 .eager => unreachable,
1286 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1287 .ty = .comptime_int_type,
1288 .storage = .{ .lazy_size = ty.toIntern() },
1289 } })) },
1385 .lazy => {
1386 const pt = strat.pt(zcu, tid);
1387 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1388 .ty = .comptime_int_type,
1389 .storage = .{ .lazy_size = ty.toIntern() },
1390 } })) };
1391 },
12901392 },
12911393 };
12921394
......@@ -1314,7 +1416,7 @@ pub fn abiSizeAdvanced(
13141416 .f128 => return .{ .scalar = 16 },
13151417 .f80 => switch (target.cTypeBitSize(.longdouble)) {
13161418 80 => return .{ .scalar = target.cTypeByteSize(.longdouble) },
1317 else => return .{ .scalar = Type.u80.abiSize(pt) },
1419 else => return .{ .scalar = Type.u80.abiSize(zcu) },
13181420 },
13191421
13201422 .usize,
......@@ -1343,7 +1445,7 @@ pub fn abiSizeAdvanced(
13431445 => return .{ .scalar = 0 },
13441446
13451447 .anyerror, .adhoc_inferred_error_set => {
1346 const bits = mod.errorSetBits();
1448 const bits = zcu.errorSetBits();
13471449 if (bits == 0) return .{ .scalar = 0 };
13481450 return .{ .scalar = intAbiSize(bits, target, use_llvm) };
13491451 },
......@@ -1354,30 +1456,33 @@ pub fn abiSizeAdvanced(
13541456 .struct_type => {
13551457 const struct_type = ip.loadStructType(ty.toIntern());
13561458 switch (strat) {
1357 .sema => try ty.resolveLayout(pt),
1358 .lazy => switch (struct_type.layout) {
1359 .@"packed" => {
1360 if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
1361 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1362 .ty = .comptime_int_type,
1363 .storage = .{ .lazy_size = ty.toIntern() },
1364 } })),
1365 };
1366 },
1367 .auto, .@"extern" => {
1368 if (!struct_type.haveLayout(ip)) return .{
1369 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1370 .ty = .comptime_int_type,
1371 .storage = .{ .lazy_size = ty.toIntern() },
1372 } })),
1373 };
1374 },
1459 .sema => try ty.resolveLayout(strat.pt(zcu, tid)),
1460 .lazy => {
1461 const pt = strat.pt(zcu, tid);
1462 switch (struct_type.layout) {
1463 .@"packed" => {
1464 if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
1465 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1466 .ty = .comptime_int_type,
1467 .storage = .{ .lazy_size = ty.toIntern() },
1468 } })),
1469 };
1470 },
1471 .auto, .@"extern" => {
1472 if (!struct_type.haveLayout(ip)) return .{
1473 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1474 .ty = .comptime_int_type,
1475 .storage = .{ .lazy_size = ty.toIntern() },
1476 } })),
1477 };
1478 },
1479 }
13751480 },
13761481 .eager => {},
13771482 }
13781483 switch (struct_type.layout) {
13791484 .@"packed" => return .{
1380 .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiSize(pt),
1485 .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiSize(zcu),
13811486 },
13821487 .auto, .@"extern" => {
13831488 assert(struct_type.haveLayout(ip));
......@@ -1387,25 +1492,28 @@ pub fn abiSizeAdvanced(
13871492 },
13881493 .anon_struct_type => |tuple| {
13891494 switch (strat) {
1390 .sema => try ty.resolveLayout(pt),
1495 .sema => try ty.resolveLayout(strat.pt(zcu, tid)),
13911496 .lazy, .eager => {},
13921497 }
13931498 const field_count = tuple.types.len;
13941499 if (field_count == 0) {
13951500 return .{ .scalar = 0 };
13961501 }
1397 return .{ .scalar = ty.structFieldOffset(field_count, pt) };
1502 return .{ .scalar = ty.structFieldOffset(field_count, zcu) };
13981503 },
13991504
14001505 .union_type => {
14011506 const union_type = ip.loadUnionType(ty.toIntern());
14021507 switch (strat) {
1403 .sema => try ty.resolveLayout(pt),
1404 .lazy => if (!union_type.flagsUnordered(ip).status.haveLayout()) return .{
1405 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1406 .ty = .comptime_int_type,
1407 .storage = .{ .lazy_size = ty.toIntern() },
1408 } })),
1508 .sema => try ty.resolveLayout(strat.pt(zcu, tid)),
1509 .lazy => {
1510 const pt = strat.pt(zcu, tid);
1511 if (!union_type.flagsUnordered(ip).status.haveLayout()) return .{
1512 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1513 .ty = .comptime_int_type,
1514 .storage = .{ .lazy_size = ty.toIntern() },
1515 } })),
1516 };
14091517 },
14101518 .eager => {},
14111519 }
......@@ -1414,7 +1522,7 @@ pub fn abiSizeAdvanced(
14141522 return .{ .scalar = union_type.sizeUnordered(ip) };
14151523 },
14161524 .opaque_type => unreachable, // no size available
1417 .enum_type => return .{ .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiSize(pt) },
1525 .enum_type => return .{ .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiSize(zcu) },
14181526
14191527 // values, not types
14201528 .undef,
......@@ -1441,36 +1549,39 @@ pub fn abiSizeAdvanced(
14411549 }
14421550}
14431551
1444fn abiSizeAdvancedOptional(
1552fn abiSizeInnerOptional(
14451553 ty: Type,
1446 pt: Zcu.PerThread,
14471554 comptime strat: ResolveStratLazy,
1448) SemaError!AbiSizeAdvanced {
1449 const mod = pt.zcu;
1450 const child_ty = ty.optionalChild(mod);
1555 zcu: *Zcu,
1556 tid: strat.Tid(),
1557) SemaError!AbiSizeInner {
1558 const child_ty = ty.optionalChild(zcu);
14511559
1452 if (child_ty.isNoReturn(mod)) {
1560 if (child_ty.isNoReturn(zcu)) {
14531561 return .{ .scalar = 0 };
14541562 }
14551563
1456 if (!(child_ty.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {
1457 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1458 .ty = .comptime_int_type,
1459 .storage = .{ .lazy_size = ty.toIntern() },
1460 } })) },
1564 if (!(child_ty.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1565 error.NeedLazy => if (strat == .lazy) {
1566 const pt = strat.pt(zcu, tid);
1567 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1568 .ty = .comptime_int_type,
1569 .storage = .{ .lazy_size = ty.toIntern() },
1570 } })) };
1571 } else unreachable,
14611572 else => |e| return e,
14621573 })) return .{ .scalar = 1 };
14631574
1464 if (ty.optionalReprIsPayload(mod)) {
1465 return child_ty.abiSizeAdvanced(pt, strat);
1575 if (ty.optionalReprIsPayload(zcu)) {
1576 return child_ty.abiSizeInner(strat, zcu, tid);
14661577 }
14671578
1468 const payload_size = switch (try child_ty.abiSizeAdvanced(pt, strat)) {
1579 const payload_size = switch (try child_ty.abiSizeInner(strat, zcu, tid)) {
14691580 .scalar => |elem_size| elem_size,
14701581 .val => switch (strat) {
14711582 .sema => unreachable,
14721583 .eager => unreachable,
1473 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1584 .lazy => return .{ .val = Value.fromInterned(try strat.pt(zcu, tid).intern(.{ .int = .{
14741585 .ty = .comptime_int_type,
14751586 .storage = .{ .lazy_size = ty.toIntern() },
14761587 } })) },
......@@ -1482,7 +1593,7 @@ fn abiSizeAdvancedOptional(
14821593 // guaranteed to be >= that of bool's (1 byte) the added size is exactly equal
14831594 // to the child type's ABI alignment.
14841595 return .{
1485 .scalar = (child_ty.abiAlignment(pt).toByteUnits() orelse 0) + payload_size,
1596 .scalar = (child_ty.abiAlignment(zcu).toByteUnits() orelse 0) + payload_size,
14861597 };
14871598}
14881599
......@@ -1600,18 +1711,22 @@ pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {
16001711 };
16011712}
16021713
1603pub fn bitSize(ty: Type, pt: Zcu.PerThread) u64 {
1604 return bitSizeAdvanced(ty, pt, .normal) catch unreachable;
1714pub fn bitSize(ty: Type, zcu: *Zcu) u64 {
1715 return bitSizeInner(ty, .normal, zcu, {}) catch unreachable;
1716}
1717
1718pub fn bitSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {
1719 return bitSizeInner(ty, .sema, pt.zcu, pt.tid);
16051720}
16061721
1607pub fn bitSizeAdvanced(
1722pub fn bitSizeInner(
16081723 ty: Type,
1609 pt: Zcu.PerThread,
16101724 comptime strat: ResolveStrat,
1725 zcu: *Zcu,
1726 tid: strat.Tid(),
16111727) SemaError!u64 {
1612 const mod = pt.zcu;
1613 const target = mod.getTarget();
1614 const ip = &mod.intern_pool;
1728 const target = zcu.getTarget();
1729 const ip = &zcu.intern_pool;
16151730
16161731 const strat_lazy: ResolveStratLazy = strat.toLazy();
16171732
......@@ -1628,30 +1743,30 @@ pub fn bitSizeAdvanced(
16281743 if (len == 0) return 0;
16291744 const elem_ty = Type.fromInterned(array_type.child);
16301745 const elem_size = @max(
1631 (try elem_ty.abiAlignmentAdvanced(pt, strat_lazy)).scalar.toByteUnits() orelse 0,
1632 (try elem_ty.abiSizeAdvanced(pt, strat_lazy)).scalar,
1746 (try elem_ty.abiAlignmentInner(strat_lazy, zcu, tid)).scalar.toByteUnits() orelse 0,
1747 (try elem_ty.abiSizeInner(strat_lazy, zcu, tid)).scalar,
16331748 );
16341749 if (elem_size == 0) return 0;
1635 const elem_bit_size = try elem_ty.bitSizeAdvanced(pt, strat);
1750 const elem_bit_size = try elem_ty.bitSizeInner(strat, zcu, tid);
16361751 return (len - 1) * 8 * elem_size + elem_bit_size;
16371752 },
16381753 .vector_type => |vector_type| {
16391754 const child_ty = Type.fromInterned(vector_type.child);
1640 const elem_bit_size = try child_ty.bitSizeAdvanced(pt, strat);
1755 const elem_bit_size = try child_ty.bitSizeInner(strat, zcu, tid);
16411756 return elem_bit_size * vector_type.len;
16421757 },
16431758 .opt_type => {
16441759 // Optionals and error unions are not packed so their bitsize
16451760 // includes padding bits.
1646 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
1761 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
16471762 },
16481763
1649 .error_set_type, .inferred_error_set_type => return mod.errorSetBits(),
1764 .error_set_type, .inferred_error_set_type => return zcu.errorSetBits(),
16501765
16511766 .error_union_type => {
16521767 // Optionals and error unions are not packed so their bitsize
16531768 // includes padding bits.
1654 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
1769 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
16551770 },
16561771 .func_type => unreachable, // represents machine code; not a pointer
16571772 .simple_type => |t| switch (t) {
......@@ -1681,7 +1796,7 @@ pub fn bitSizeAdvanced(
16811796
16821797 .anyerror,
16831798 .adhoc_inferred_error_set,
1684 => return mod.errorSetBits(),
1799 => return zcu.errorSetBits(),
16851800
16861801 .anyopaque => unreachable,
16871802 .type => unreachable,
......@@ -1697,42 +1812,46 @@ pub fn bitSizeAdvanced(
16971812 const struct_type = ip.loadStructType(ty.toIntern());
16981813 const is_packed = struct_type.layout == .@"packed";
16991814 if (strat == .sema) {
1815 const pt = strat.pt(zcu, tid);
17001816 try ty.resolveFields(pt);
17011817 if (is_packed) try ty.resolveLayout(pt);
17021818 }
17031819 if (is_packed) {
1704 return try Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).bitSizeAdvanced(pt, strat);
1820 return try Type.fromInterned(struct_type.backingIntTypeUnordered(ip))
1821 .bitSizeInner(strat, zcu, tid);
17051822 }
1706 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
1823 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
17071824 },
17081825
17091826 .anon_struct_type => {
1710 if (strat == .sema) try ty.resolveFields(pt);
1711 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
1827 if (strat == .sema) try ty.resolveFields(strat.pt(zcu, tid));
1828 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
17121829 },
17131830
17141831 .union_type => {
17151832 const union_type = ip.loadUnionType(ty.toIntern());
1716 const is_packed = ty.containerLayout(mod) == .@"packed";
1833 const is_packed = ty.containerLayout(zcu) == .@"packed";
17171834 if (strat == .sema) {
1835 const pt = strat.pt(zcu, tid);
17181836 try ty.resolveFields(pt);
17191837 if (is_packed) try ty.resolveLayout(pt);
17201838 }
17211839 if (!is_packed) {
1722 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
1840 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
17231841 }
17241842 assert(union_type.flagsUnordered(ip).status.haveFieldTypes());
17251843
17261844 var size: u64 = 0;
17271845 for (0..union_type.field_types.len) |field_index| {
17281846 const field_ty = union_type.field_types.get(ip)[field_index];
1729 size = @max(size, try Type.fromInterned(field_ty).bitSizeAdvanced(pt, strat));
1847 size = @max(size, try Type.fromInterned(field_ty).bitSizeInner(strat, zcu, tid));
17301848 }
17311849
17321850 return size;
17331851 },
17341852 .opaque_type => unreachable,
1735 .enum_type => return Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).bitSizeAdvanced(pt, strat),
1853 .enum_type => return Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty)
1854 .bitSizeInner(strat, zcu, tid),
17361855
17371856 // values, not types
17381857 .undef,
......@@ -1760,61 +1879,61 @@ pub fn bitSizeAdvanced(
17601879
17611880/// Returns true if the type's layout is already resolved and it is safe
17621881/// to use `abiSize`, `abiAlignment` and `bitSize` on it.
1763pub fn layoutIsResolved(ty: Type, mod: *Module) bool {
1764 const ip = &mod.intern_pool;
1882pub fn layoutIsResolved(ty: Type, zcu: *const Zcu) bool {
1883 const ip = &zcu.intern_pool;
17651884 return switch (ip.indexToKey(ty.toIntern())) {
17661885 .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip),
17671886 .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip),
17681887 .array_type => |array_type| {
17691888 if (array_type.lenIncludingSentinel() == 0) return true;
1770 return Type.fromInterned(array_type.child).layoutIsResolved(mod);
1889 return Type.fromInterned(array_type.child).layoutIsResolved(zcu);
17711890 },
1772 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod),
1773 .error_union_type => |k| Type.fromInterned(k.payload_type).layoutIsResolved(mod),
1891 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(zcu),
1892 .error_union_type => |k| Type.fromInterned(k.payload_type).layoutIsResolved(zcu),
17741893 else => true,
17751894 };
17761895}
17771896
1778pub fn isSinglePointer(ty: Type, mod: *const Module) bool {
1779 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1897pub fn isSinglePointer(ty: Type, zcu: *const Zcu) bool {
1898 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
17801899 .ptr_type => |ptr_info| ptr_info.flags.size == .One,
17811900 else => false,
17821901 };
17831902}
17841903
17851904/// Asserts `ty` is a pointer.
1786pub fn ptrSize(ty: Type, mod: *const Module) std.builtin.Type.Pointer.Size {
1787 return ty.ptrSizeOrNull(mod).?;
1905pub fn ptrSize(ty: Type, zcu: *const Zcu) std.builtin.Type.Pointer.Size {
1906 return ty.ptrSizeOrNull(zcu).?;
17881907}
17891908
17901909/// Returns `null` if `ty` is not a pointer.
1791pub fn ptrSizeOrNull(ty: Type, mod: *const Module) ?std.builtin.Type.Pointer.Size {
1792 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1910pub fn ptrSizeOrNull(ty: Type, zcu: *const Zcu) ?std.builtin.Type.Pointer.Size {
1911 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
17931912 .ptr_type => |ptr_info| ptr_info.flags.size,
17941913 else => null,
17951914 };
17961915}
17971916
1798pub fn isSlice(ty: Type, mod: *const Module) bool {
1799 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1917pub fn isSlice(ty: Type, zcu: *const Zcu) bool {
1918 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
18001919 .ptr_type => |ptr_type| ptr_type.flags.size == .Slice,
18011920 else => false,
18021921 };
18031922}
18041923
1805pub fn slicePtrFieldType(ty: Type, mod: *const Module) Type {
1806 return Type.fromInterned(mod.intern_pool.slicePtrType(ty.toIntern()));
1924pub fn slicePtrFieldType(ty: Type, zcu: *const Zcu) Type {
1925 return Type.fromInterned(zcu.intern_pool.slicePtrType(ty.toIntern()));
18071926}
18081927
1809pub fn isConstPtr(ty: Type, mod: *const Module) bool {
1810 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1928pub fn isConstPtr(ty: Type, zcu: *const Zcu) bool {
1929 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
18111930 .ptr_type => |ptr_type| ptr_type.flags.is_const,
18121931 else => false,
18131932 };
18141933}
18151934
1816pub fn isVolatilePtr(ty: Type, mod: *const Module) bool {
1817 return isVolatilePtrIp(ty, &mod.intern_pool);
1935pub fn isVolatilePtr(ty: Type, zcu: *const Zcu) bool {
1936 return isVolatilePtrIp(ty, &zcu.intern_pool);
18181937}
18191938
18201939pub fn isVolatilePtrIp(ty: Type, ip: *const InternPool) bool {
......@@ -1824,28 +1943,28 @@ pub fn isVolatilePtrIp(ty: Type, ip: *const InternPool) bool {
18241943 };
18251944}
18261945
1827pub fn isAllowzeroPtr(ty: Type, mod: *const Module) bool {
1828 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1946pub fn isAllowzeroPtr(ty: Type, zcu: *const Zcu) bool {
1947 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
18291948 .ptr_type => |ptr_type| ptr_type.flags.is_allowzero,
18301949 .opt_type => true,
18311950 else => false,
18321951 };
18331952}
18341953
1835pub fn isCPtr(ty: Type, mod: *const Module) bool {
1836 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1954pub fn isCPtr(ty: Type, zcu: *const Zcu) bool {
1955 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
18371956 .ptr_type => |ptr_type| ptr_type.flags.size == .C,
18381957 else => false,
18391958 };
18401959}
18411960
1842pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool {
1843 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1961pub fn isPtrAtRuntime(ty: Type, zcu: *const Zcu) bool {
1962 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
18441963 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
18451964 .Slice => false,
18461965 .One, .Many, .C => true,
18471966 },
1848 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {
1967 .opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) {
18491968 .ptr_type => |p| switch (p.flags.size) {
18501969 .Slice, .C => false,
18511970 .Many, .One => !p.flags.is_allowzero,
......@@ -1858,17 +1977,17 @@ pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool {
18581977
18591978/// For pointer-like optionals, returns true, otherwise returns the allowzero property
18601979/// of pointers.
1861pub fn ptrAllowsZero(ty: Type, mod: *const Module) bool {
1862 if (ty.isPtrLikeOptional(mod)) {
1980pub fn ptrAllowsZero(ty: Type, zcu: *const Zcu) bool {
1981 if (ty.isPtrLikeOptional(zcu)) {
18631982 return true;
18641983 }
1865 return ty.ptrInfo(mod).flags.is_allowzero;
1984 return ty.ptrInfo(zcu).flags.is_allowzero;
18661985}
18671986
18681987/// See also `isPtrLikeOptional`.
1869pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool {
1870 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1871 .opt_type => |child_type| child_type == .anyerror_type or switch (mod.intern_pool.indexToKey(child_type)) {
1988pub fn optionalReprIsPayload(ty: Type, zcu: *const Zcu) bool {
1989 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1990 .opt_type => |child_type| child_type == .anyerror_type or switch (zcu.intern_pool.indexToKey(child_type)) {
18721991 .ptr_type => |ptr_type| ptr_type.flags.size != .C and !ptr_type.flags.is_allowzero,
18731992 .error_set_type, .inferred_error_set_type => true,
18741993 else => false,
......@@ -1881,10 +2000,10 @@ pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool {
18812000/// Returns true if the type is optional and would be lowered to a single pointer
18822001/// address value, using 0 for null. Note that this returns true for C pointers.
18832002/// This function must be kept in sync with `Sema.typePtrOrOptionalPtrTy`.
1884pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool {
1885 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2003pub fn isPtrLikeOptional(ty: Type, zcu: *const Zcu) bool {
2004 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
18862005 .ptr_type => |ptr_type| ptr_type.flags.size == .C,
1887 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {
2006 .opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) {
18882007 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
18892008 .Slice, .C => false,
18902009 .Many, .One => !ptr_type.flags.is_allowzero,
......@@ -1898,8 +2017,8 @@ pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool {
18982017/// For *[N]T, returns [N]T.
18992018/// For *T, returns T.
19002019/// For [*]T, returns T.
1901pub fn childType(ty: Type, mod: *const Module) Type {
1902 return childTypeIp(ty, &mod.intern_pool);
2020pub fn childType(ty: Type, zcu: *const Zcu) Type {
2021 return childTypeIp(ty, &zcu.intern_pool);
19032022}
19042023
19052024pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
......@@ -1915,10 +2034,10 @@ pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
19152034/// For [N]T, returns T.
19162035/// For []T, returns T.
19172036/// For anyframe->T, returns T.
1918pub fn elemType2(ty: Type, mod: *const Module) Type {
1919 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2037pub fn elemType2(ty: Type, zcu: *const Zcu) Type {
2038 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
19202039 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
1921 .One => Type.fromInterned(ptr_type.child).shallowElemType(mod),
2040 .One => Type.fromInterned(ptr_type.child).shallowElemType(zcu),
19222041 .Many, .C, .Slice => Type.fromInterned(ptr_type.child),
19232042 },
19242043 .anyframe_type => |child| {
......@@ -1927,30 +2046,30 @@ pub fn elemType2(ty: Type, mod: *const Module) Type {
19272046 },
19282047 .vector_type => |vector_type| Type.fromInterned(vector_type.child),
19292048 .array_type => |array_type| Type.fromInterned(array_type.child),
1930 .opt_type => |child| Type.fromInterned(mod.intern_pool.childType(child)),
2049 .opt_type => |child| Type.fromInterned(zcu.intern_pool.childType(child)),
19312050 else => unreachable,
19322051 };
19332052}
19342053
1935fn shallowElemType(child_ty: Type, mod: *const Module) Type {
1936 return switch (child_ty.zigTypeTag(mod)) {
1937 .Array, .Vector => child_ty.childType(mod),
2054fn shallowElemType(child_ty: Type, zcu: *const Zcu) Type {
2055 return switch (child_ty.zigTypeTag(zcu)) {
2056 .Array, .Vector => child_ty.childType(zcu),
19382057 else => child_ty,
19392058 };
19402059}
19412060
19422061/// For vectors, returns the element type. Otherwise returns self.
1943pub fn scalarType(ty: Type, mod: *Module) Type {
1944 return switch (ty.zigTypeTag(mod)) {
1945 .Vector => ty.childType(mod),
2062pub fn scalarType(ty: Type, zcu: *const Zcu) Type {
2063 return switch (ty.zigTypeTag(zcu)) {
2064 .Vector => ty.childType(zcu),
19462065 else => ty,
19472066 };
19482067}
19492068
19502069/// Asserts that the type is an optional.
19512070/// Note that for C pointers this returns the type unmodified.
1952pub fn optionalChild(ty: Type, mod: *const Module) Type {
1953 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2071pub fn optionalChild(ty: Type, zcu: *const Zcu) Type {
2072 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
19542073 .opt_type => |child| Type.fromInterned(child),
19552074 .ptr_type => |ptr_type| b: {
19562075 assert(ptr_type.flags.size == .C);
......@@ -1962,8 +2081,8 @@ pub fn optionalChild(ty: Type, mod: *const Module) Type {
19622081
19632082/// Returns the tag type of a union, if the type is a union and it has a tag type.
19642083/// Otherwise, returns `null`.
1965pub fn unionTagType(ty: Type, mod: *Module) ?Type {
1966 const ip = &mod.intern_pool;
2084pub fn unionTagType(ty: Type, zcu: *const Zcu) ?Type {
2085 const ip = &zcu.intern_pool;
19672086 switch (ip.indexToKey(ty.toIntern())) {
19682087 .union_type => {},
19692088 else => return null,
......@@ -1981,8 +2100,8 @@ pub fn unionTagType(ty: Type, mod: *Module) ?Type {
19812100
19822101/// Same as `unionTagType` but includes safety tag.
19832102/// Codegen should use this version.
1984pub fn unionTagTypeSafety(ty: Type, mod: *Module) ?Type {
1985 const ip = &mod.intern_pool;
2103pub fn unionTagTypeSafety(ty: Type, zcu: *const Zcu) ?Type {
2104 const ip = &zcu.intern_pool;
19862105 return switch (ip.indexToKey(ty.toIntern())) {
19872106 .union_type => {
19882107 const union_type = ip.loadUnionType(ty.toIntern());
......@@ -1996,35 +2115,35 @@ pub fn unionTagTypeSafety(ty: Type, mod: *Module) ?Type {
19962115
19972116/// Asserts the type is a union; returns the tag type, even if the tag will
19982117/// not be stored at runtime.
1999pub fn unionTagTypeHypothetical(ty: Type, mod: *Module) Type {
2000 const union_obj = mod.typeToUnion(ty).?;
2118pub fn unionTagTypeHypothetical(ty: Type, zcu: *const Zcu) Type {
2119 const union_obj = zcu.typeToUnion(ty).?;
20012120 return Type.fromInterned(union_obj.enum_tag_ty);
20022121}
20032122
2004pub fn unionFieldType(ty: Type, enum_tag: Value, mod: *Module) ?Type {
2005 const ip = &mod.intern_pool;
2006 const union_obj = mod.typeToUnion(ty).?;
2123pub fn unionFieldType(ty: Type, enum_tag: Value, zcu: *const Zcu) ?Type {
2124 const ip = &zcu.intern_pool;
2125 const union_obj = zcu.typeToUnion(ty).?;
20072126 const union_fields = union_obj.field_types.get(ip);
2008 const index = mod.unionTagFieldIndex(union_obj, enum_tag) orelse return null;
2127 const index = zcu.unionTagFieldIndex(union_obj, enum_tag) orelse return null;
20092128 return Type.fromInterned(union_fields[index]);
20102129}
20112130
2012pub fn unionFieldTypeByIndex(ty: Type, index: usize, mod: *Module) Type {
2013 const ip = &mod.intern_pool;
2014 const union_obj = mod.typeToUnion(ty).?;
2131pub fn unionFieldTypeByIndex(ty: Type, index: usize, zcu: *const Zcu) Type {
2132 const ip = &zcu.intern_pool;
2133 const union_obj = zcu.typeToUnion(ty).?;
20152134 return Type.fromInterned(union_obj.field_types.get(ip)[index]);
20162135}
20172136
2018pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {
2019 const union_obj = mod.typeToUnion(ty).?;
2020 return mod.unionTagFieldIndex(union_obj, enum_tag);
2137pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, zcu: *const Zcu) ?u32 {
2138 const union_obj = zcu.typeToUnion(ty).?;
2139 return zcu.unionTagFieldIndex(union_obj, enum_tag);
20212140}
20222141
2023pub fn unionHasAllZeroBitFieldTypes(ty: Type, pt: Zcu.PerThread) bool {
2024 const ip = &pt.zcu.intern_pool;
2025 const union_obj = pt.zcu.typeToUnion(ty).?;
2142pub fn unionHasAllZeroBitFieldTypes(ty: Type, zcu: *Zcu) bool {
2143 const ip = &zcu.intern_pool;
2144 const union_obj = zcu.typeToUnion(ty).?;
20262145 for (union_obj.field_types.get(ip)) |field_ty| {
2027 if (Type.fromInterned(field_ty).hasRuntimeBits(pt)) return false;
2146 if (Type.fromInterned(field_ty).hasRuntimeBits(zcu)) return false;
20282147 }
20292148 return true;
20302149}
......@@ -2032,20 +2151,21 @@ pub fn unionHasAllZeroBitFieldTypes(ty: Type, pt: Zcu.PerThread) bool {
20322151/// Returns the type used for backing storage of this union during comptime operations.
20332152/// Asserts the type is either an extern or packed union.
20342153pub fn unionBackingType(ty: Type, pt: Zcu.PerThread) !Type {
2035 return switch (ty.containerLayout(pt.zcu)) {
2036 .@"extern" => try pt.arrayType(.{ .len = ty.abiSize(pt), .child = .u8_type }),
2037 .@"packed" => try pt.intType(.unsigned, @intCast(ty.bitSize(pt))),
2154 const zcu = pt.zcu;
2155 return switch (ty.containerLayout(zcu)) {
2156 .@"extern" => try pt.arrayType(.{ .len = ty.abiSize(zcu), .child = .u8_type }),
2157 .@"packed" => try pt.intType(.unsigned, @intCast(ty.bitSize(zcu))),
20382158 .auto => unreachable,
20392159 };
20402160}
20412161
2042pub fn unionGetLayout(ty: Type, pt: Zcu.PerThread) Module.UnionLayout {
2043 const union_obj = pt.zcu.intern_pool.loadUnionType(ty.toIntern());
2044 return pt.getUnionLayout(union_obj);
2162pub fn unionGetLayout(ty: Type, zcu: *Zcu) Zcu.UnionLayout {
2163 const union_obj = zcu.intern_pool.loadUnionType(ty.toIntern());
2164 return Type.getUnionLayout(union_obj, zcu);
20452165}
20462166
2047pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout {
2048 const ip = &mod.intern_pool;
2167pub fn containerLayout(ty: Type, zcu: *const Zcu) std.builtin.Type.ContainerLayout {
2168 const ip = &zcu.intern_pool;
20492169 return switch (ip.indexToKey(ty.toIntern())) {
20502170 .struct_type => ip.loadStructType(ty.toIntern()).layout,
20512171 .anon_struct_type => .auto,
......@@ -2055,18 +2175,18 @@ pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout
20552175}
20562176
20572177/// Asserts that the type is an error union.
2058pub fn errorUnionPayload(ty: Type, mod: *Module) Type {
2059 return Type.fromInterned(mod.intern_pool.indexToKey(ty.toIntern()).error_union_type.payload_type);
2178pub fn errorUnionPayload(ty: Type, zcu: *const Zcu) Type {
2179 return Type.fromInterned(zcu.intern_pool.indexToKey(ty.toIntern()).error_union_type.payload_type);
20602180}
20612181
20622182/// Asserts that the type is an error union.
2063pub fn errorUnionSet(ty: Type, mod: *Module) Type {
2064 return Type.fromInterned(mod.intern_pool.errorUnionSet(ty.toIntern()));
2183pub fn errorUnionSet(ty: Type, zcu: *const Zcu) Type {
2184 return Type.fromInterned(zcu.intern_pool.errorUnionSet(ty.toIntern()));
20652185}
20662186
20672187/// Returns false for unresolved inferred error sets.
2068pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
2069 const ip = &mod.intern_pool;
2188pub fn errorSetIsEmpty(ty: Type, zcu: *const Zcu) bool {
2189 const ip = &zcu.intern_pool;
20702190 return switch (ty.toIntern()) {
20712191 .anyerror_type, .adhoc_inferred_error_set_type => false,
20722192 else => switch (ip.indexToKey(ty.toIntern())) {
......@@ -2083,20 +2203,20 @@ pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
20832203/// Returns true if it is an error set that includes anyerror, false otherwise.
20842204/// Note that the result may be a false negative if the type did not get error set
20852205/// resolution prior to this call.
2086pub fn isAnyError(ty: Type, mod: *Module) bool {
2087 const ip = &mod.intern_pool;
2206pub fn isAnyError(ty: Type, zcu: *const Zcu) bool {
2207 const ip = &zcu.intern_pool;
20882208 return switch (ty.toIntern()) {
20892209 .anyerror_type => true,
20902210 .adhoc_inferred_error_set_type => false,
2091 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2211 else => switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
20922212 .inferred_error_set_type => |i| ip.funcIesResolvedUnordered(i) == .anyerror_type,
20932213 else => false,
20942214 },
20952215 };
20962216}
20972217
2098pub fn isError(ty: Type, mod: *const Module) bool {
2099 return switch (ty.zigTypeTag(mod)) {
2218pub fn isError(ty: Type, zcu: *const Zcu) bool {
2219 return switch (ty.zigTypeTag(zcu)) {
21002220 .ErrorUnion, .ErrorSet => true,
21012221 else => false,
21022222 };
......@@ -2127,8 +2247,8 @@ pub fn errorSetHasFieldIp(
21272247/// Returns whether ty, which must be an error set, includes an error `name`.
21282248/// Might return a false negative if `ty` is an inferred error set and not fully
21292249/// resolved yet.
2130pub fn errorSetHasField(ty: Type, name: []const u8, mod: *Module) bool {
2131 const ip = &mod.intern_pool;
2250pub fn errorSetHasField(ty: Type, name: []const u8, zcu: *const Zcu) bool {
2251 const ip = &zcu.intern_pool;
21322252 return switch (ty.toIntern()) {
21332253 .anyerror_type => true,
21342254 else => switch (ip.indexToKey(ty.toIntern())) {
......@@ -2152,20 +2272,20 @@ pub fn errorSetHasField(ty: Type, name: []const u8, mod: *Module) bool {
21522272}
21532273
21542274/// Asserts the type is an array or vector or struct.
2155pub fn arrayLen(ty: Type, mod: *const Module) u64 {
2156 return ty.arrayLenIp(&mod.intern_pool);
2275pub fn arrayLen(ty: Type, zcu: *const Zcu) u64 {
2276 return ty.arrayLenIp(&zcu.intern_pool);
21572277}
21582278
21592279pub fn arrayLenIp(ty: Type, ip: *const InternPool) u64 {
21602280 return ip.aggregateTypeLen(ty.toIntern());
21612281}
21622282
2163pub fn arrayLenIncludingSentinel(ty: Type, mod: *const Module) u64 {
2164 return mod.intern_pool.aggregateTypeLenIncludingSentinel(ty.toIntern());
2283pub fn arrayLenIncludingSentinel(ty: Type, zcu: *const Zcu) u64 {
2284 return zcu.intern_pool.aggregateTypeLenIncludingSentinel(ty.toIntern());
21652285}
21662286
2167pub fn vectorLen(ty: Type, mod: *const Module) u32 {
2168 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2287pub fn vectorLen(ty: Type, zcu: *const Zcu) u32 {
2288 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
21692289 .vector_type => |vector_type| vector_type.len,
21702290 .anon_struct_type => |tuple| @intCast(tuple.types.len),
21712291 else => unreachable,
......@@ -2173,8 +2293,8 @@ pub fn vectorLen(ty: Type, mod: *const Module) u32 {
21732293}
21742294
21752295/// Asserts the type is an array, pointer or vector.
2176pub fn sentinel(ty: Type, mod: *const Module) ?Value {
2177 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2296pub fn sentinel(ty: Type, zcu: *const Zcu) ?Value {
2297 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
21782298 .vector_type,
21792299 .struct_type,
21802300 .anon_struct_type,
......@@ -2188,17 +2308,17 @@ pub fn sentinel(ty: Type, mod: *const Module) ?Value {
21882308}
21892309
21902310/// Returns true if and only if the type is a fixed-width integer.
2191pub fn isInt(self: Type, mod: *const Module) bool {
2311pub fn isInt(self: Type, zcu: *const Zcu) bool {
21922312 return self.toIntern() != .comptime_int_type and
2193 mod.intern_pool.isIntegerType(self.toIntern());
2313 zcu.intern_pool.isIntegerType(self.toIntern());
21942314}
21952315
21962316/// Returns true if and only if the type is a fixed-width, signed integer.
2197pub fn isSignedInt(ty: Type, mod: *const Module) bool {
2317pub fn isSignedInt(ty: Type, zcu: *const Zcu) bool {
21982318 return switch (ty.toIntern()) {
2199 .c_char_type => mod.getTarget().charSignedness() == .signed,
2319 .c_char_type => zcu.getTarget().charSignedness() == .signed,
22002320 .isize_type, .c_short_type, .c_int_type, .c_long_type, .c_longlong_type => true,
2201 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2321 else => switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
22022322 .int_type => |int_type| int_type.signedness == .signed,
22032323 else => false,
22042324 },
......@@ -2206,11 +2326,11 @@ pub fn isSignedInt(ty: Type, mod: *const Module) bool {
22062326}
22072327
22082328/// Returns true if and only if the type is a fixed-width, unsigned integer.
2209pub fn isUnsignedInt(ty: Type, mod: *const Module) bool {
2329pub fn isUnsignedInt(ty: Type, zcu: *const Zcu) bool {
22102330 return switch (ty.toIntern()) {
2211 .c_char_type => mod.getTarget().charSignedness() == .unsigned,
2331 .c_char_type => zcu.getTarget().charSignedness() == .unsigned,
22122332 .usize_type, .c_ushort_type, .c_uint_type, .c_ulong_type, .c_ulonglong_type => true,
2213 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2333 else => switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
22142334 .int_type => |int_type| int_type.signedness == .unsigned,
22152335 else => false,
22162336 },
......@@ -2219,27 +2339,27 @@ pub fn isUnsignedInt(ty: Type, mod: *const Module) bool {
22192339
22202340/// Returns true for integers, enums, error sets, and packed structs.
22212341/// If this function returns true, then intInfo() can be called on the type.
2222pub fn isAbiInt(ty: Type, mod: *Module) bool {
2223 return switch (ty.zigTypeTag(mod)) {
2342pub fn isAbiInt(ty: Type, zcu: *const Zcu) bool {
2343 return switch (ty.zigTypeTag(zcu)) {
22242344 .Int, .Enum, .ErrorSet => true,
2225 .Struct => ty.containerLayout(mod) == .@"packed",
2345 .Struct => ty.containerLayout(zcu) == .@"packed",
22262346 else => false,
22272347 };
22282348}
22292349
22302350/// Asserts the type is an integer, enum, error set, or vector of one of them.
2231pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
2232 const ip = &mod.intern_pool;
2233 const target = mod.getTarget();
2351pub fn intInfo(starting_ty: Type, zcu: *const Zcu) InternPool.Key.IntType {
2352 const ip = &zcu.intern_pool;
2353 const target = zcu.getTarget();
22342354 var ty = starting_ty;
22352355
22362356 while (true) switch (ty.toIntern()) {
22372357 .anyerror_type, .adhoc_inferred_error_set_type => {
2238 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
2358 return .{ .signedness = .unsigned, .bits = zcu.errorSetBits() };
22392359 },
22402360 .usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
22412361 .isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },
2242 .c_char_type => return .{ .signedness = mod.getTarget().charSignedness(), .bits = target.cTypeBitSize(.char) },
2362 .c_char_type => return .{ .signedness = zcu.getTarget().charSignedness(), .bits = target.cTypeBitSize(.char) },
22432363 .c_short_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.short) },
22442364 .c_ushort_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ushort) },
22452365 .c_int_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.int) },
......@@ -2255,7 +2375,7 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
22552375 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),
22562376
22572377 .error_set_type, .inferred_error_set_type => {
2258 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
2378 return .{ .signedness = .unsigned, .bits = zcu.errorSetBits() };
22592379 },
22602380
22612381 .anon_struct_type => unreachable,
......@@ -2363,35 +2483,35 @@ pub fn floatBits(ty: Type, target: Target) u16 {
23632483}
23642484
23652485/// Asserts the type is a function or a function pointer.
2366pub fn fnReturnType(ty: Type, mod: *Module) Type {
2367 return Type.fromInterned(mod.intern_pool.funcTypeReturnType(ty.toIntern()));
2486pub fn fnReturnType(ty: Type, zcu: *const Zcu) Type {
2487 return Type.fromInterned(zcu.intern_pool.funcTypeReturnType(ty.toIntern()));
23682488}
23692489
23702490/// Asserts the type is a function.
2371pub fn fnCallingConvention(ty: Type, mod: *Module) std.builtin.CallingConvention {
2372 return mod.intern_pool.indexToKey(ty.toIntern()).func_type.cc;
2491pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.CallingConvention {
2492 return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.cc;
23732493}
23742494
2375pub fn isValidParamType(self: Type, mod: *const Module) bool {
2376 return switch (self.zigTypeTagOrPoison(mod) catch return true) {
2495pub fn isValidParamType(self: Type, zcu: *const Zcu) bool {
2496 return switch (self.zigTypeTagOrPoison(zcu) catch return true) {
23772497 .Opaque, .NoReturn => false,
23782498 else => true,
23792499 };
23802500}
23812501
2382pub fn isValidReturnType(self: Type, mod: *const Module) bool {
2383 return switch (self.zigTypeTagOrPoison(mod) catch return true) {
2502pub fn isValidReturnType(self: Type, zcu: *const Zcu) bool {
2503 return switch (self.zigTypeTagOrPoison(zcu) catch return true) {
23842504 .Opaque => false,
23852505 else => true,
23862506 };
23872507}
23882508
23892509/// Asserts the type is a function.
2390pub fn fnIsVarArgs(ty: Type, mod: *Module) bool {
2391 return mod.intern_pool.indexToKey(ty.toIntern()).func_type.is_var_args;
2510pub fn fnIsVarArgs(ty: Type, zcu: *const Zcu) bool {
2511 return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.is_var_args;
23922512}
23932513
2394pub fn isNumeric(ty: Type, mod: *const Module) bool {
2514pub fn isNumeric(ty: Type, zcu: *const Zcu) bool {
23952515 return switch (ty.toIntern()) {
23962516 .f16_type,
23972517 .f32_type,
......@@ -2414,7 +2534,7 @@ pub fn isNumeric(ty: Type, mod: *const Module) bool {
24142534 .c_ulonglong_type,
24152535 => true,
24162536
2417 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2537 else => switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
24182538 .int_type => true,
24192539 else => false,
24202540 },
......@@ -2424,9 +2544,9 @@ pub fn isNumeric(ty: Type, mod: *const Module) bool {
24242544/// During semantic analysis, instead call `Sema.typeHasOnePossibleValue` which
24252545/// resolves field types rather than asserting they are already resolved.
24262546pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2427 const mod = pt.zcu;
2547 const zcu = pt.zcu;
24282548 var ty = starting_type;
2429 const ip = &mod.intern_pool;
2549 const ip = &zcu.intern_pool;
24302550 while (true) switch (ty.toIntern()) {
24312551 .empty_struct_type => return Value.empty_struct,
24322552
......@@ -2509,8 +2629,8 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
25092629 assert(struct_type.haveFieldTypes(ip));
25102630 if (struct_type.knownNonOpv(ip))
25112631 return null;
2512 const field_vals = try mod.gpa.alloc(InternPool.Index, struct_type.field_types.len);
2513 defer mod.gpa.free(field_vals);
2632 const field_vals = try zcu.gpa.alloc(InternPool.Index, struct_type.field_types.len);
2633 defer zcu.gpa.free(field_vals);
25142634 for (field_vals, 0..) |*field_val, i_usize| {
25152635 const i: u32 = @intCast(i_usize);
25162636 if (struct_type.fieldIsComptime(ip, i)) {
......@@ -2539,8 +2659,8 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
25392659 // In this case the struct has all comptime-known fields and
25402660 // therefore has one possible value.
25412661 // TODO: write something like getCoercedInts to avoid needing to dupe
2542 const duped_values = try mod.gpa.dupe(InternPool.Index, tuple.values.get(ip));
2543 defer mod.gpa.free(duped_values);
2662 const duped_values = try zcu.gpa.dupe(InternPool.Index, tuple.values.get(ip));
2663 defer zcu.gpa.free(duped_values);
25442664 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
25452665 .ty = ty.toIntern(),
25462666 .storage = .{ .elems = duped_values },
......@@ -2583,7 +2703,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
25832703 return null;
25842704 },
25852705 .auto, .explicit => {
2586 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(pt)) return null;
2706 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null;
25872707
25882708 switch (enum_type.names.len) {
25892709 0 => {
......@@ -2635,17 +2755,25 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
26352755 };
26362756}
26372757
2638/// During semantic analysis, instead call `Sema.typeRequiresComptime` which
2758/// During semantic analysis, instead call `ty.comptimeOnlySema` which
26392759/// resolves field types rather than asserting they are already resolved.
2640pub fn comptimeOnly(ty: Type, pt: Zcu.PerThread) bool {
2641 return ty.comptimeOnlyAdvanced(pt, .normal) catch unreachable;
2760pub fn comptimeOnly(ty: Type, zcu: *Zcu) bool {
2761 return ty.comptimeOnlyInner(.normal, zcu, {}) catch unreachable;
2762}
2763
2764pub fn comptimeOnlySema(ty: Type, pt: Zcu.PerThread) SemaError!bool {
2765 return try ty.comptimeOnlyInner(.sema, pt.zcu, pt.tid);
26422766}
26432767
26442768/// `generic_poison` will return false.
26452769/// May return false negatives when structs and unions are having their field types resolved.
2646pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) SemaError!bool {
2647 const mod = pt.zcu;
2648 const ip = &mod.intern_pool;
2770pub fn comptimeOnlyInner(
2771 ty: Type,
2772 comptime strat: ResolveStrat,
2773 zcu: *Zcu,
2774 tid: strat.Tid(),
2775) SemaError!bool {
2776 const ip = &zcu.intern_pool;
26492777 return switch (ty.toIntern()) {
26502778 .empty_struct_type => false,
26512779
......@@ -2653,20 +2781,20 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
26532781 .int_type => false,
26542782 .ptr_type => |ptr_type| {
26552783 const child_ty = Type.fromInterned(ptr_type.child);
2656 switch (child_ty.zigTypeTag(mod)) {
2657 .Fn => return !try child_ty.fnHasRuntimeBitsAdvanced(pt, strat),
2784 switch (child_ty.zigTypeTag(zcu)) {
2785 .Fn => return !try child_ty.fnHasRuntimeBitsInner(strat, zcu, tid),
26582786 .Opaque => return false,
2659 else => return child_ty.comptimeOnlyAdvanced(pt, strat),
2787 else => return child_ty.comptimeOnlyInner(strat, zcu, tid),
26602788 }
26612789 },
26622790 .anyframe_type => |child| {
26632791 if (child == .none) return false;
2664 return Type.fromInterned(child).comptimeOnlyAdvanced(pt, strat);
2792 return Type.fromInterned(child).comptimeOnlyInner(strat, zcu, tid);
26652793 },
2666 .array_type => |array_type| return Type.fromInterned(array_type.child).comptimeOnlyAdvanced(pt, strat),
2667 .vector_type => |vector_type| return Type.fromInterned(vector_type.child).comptimeOnlyAdvanced(pt, strat),
2668 .opt_type => |child| return Type.fromInterned(child).comptimeOnlyAdvanced(pt, strat),
2669 .error_union_type => |error_union_type| return Type.fromInterned(error_union_type.payload_type).comptimeOnlyAdvanced(pt, strat),
2794 .array_type => |array_type| return Type.fromInterned(array_type.child).comptimeOnlyInner(strat, zcu, tid),
2795 .vector_type => |vector_type| return Type.fromInterned(vector_type.child).comptimeOnlyInner(strat, zcu, tid),
2796 .opt_type => |child| return Type.fromInterned(child).comptimeOnlyInner(strat, zcu, tid),
2797 .error_union_type => |error_union_type| return Type.fromInterned(error_union_type.payload_type).comptimeOnlyInner(strat, zcu, tid),
26702798
26712799 .error_set_type,
26722800 .inferred_error_set_type,
......@@ -2732,13 +2860,14 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27322860
27332861 errdefer struct_type.setRequiresComptime(ip, .unknown);
27342862
2863 const pt = strat.pt(zcu, tid);
27352864 try ty.resolveFields(pt);
27362865
27372866 for (0..struct_type.field_types.len) |i_usize| {
27382867 const i: u32 = @intCast(i_usize);
27392868 if (struct_type.fieldIsComptime(ip, i)) continue;
27402869 const field_ty = struct_type.field_types.get(ip)[i];
2741 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(pt, strat)) {
2870 if (try Type.fromInterned(field_ty).comptimeOnlyInner(strat, zcu, tid)) {
27422871 // Note that this does not cause the layout to
27432872 // be considered resolved. Comptime-only types
27442873 // still maintain a layout of their
......@@ -2757,7 +2886,7 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27572886 .anon_struct_type => |tuple| {
27582887 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
27592888 const have_comptime_val = val != .none;
2760 if (!have_comptime_val and try Type.fromInterned(field_ty).comptimeOnlyAdvanced(pt, strat)) return true;
2889 if (!have_comptime_val and try Type.fromInterned(field_ty).comptimeOnlyInner(strat, zcu, tid)) return true;
27612890 }
27622891 return false;
27632892 },
......@@ -2778,11 +2907,12 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27782907
27792908 errdefer union_type.setRequiresComptime(ip, .unknown);
27802909
2910 const pt = strat.pt(zcu, tid);
27812911 try ty.resolveFields(pt);
27822912
27832913 for (0..union_type.field_types.len) |field_idx| {
27842914 const field_ty = union_type.field_types.get(ip)[field_idx];
2785 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(pt, strat)) {
2915 if (try Type.fromInterned(field_ty).comptimeOnlyInner(strat, zcu, tid)) {
27862916 union_type.setRequiresComptime(ip, .yes);
27872917 return true;
27882918 }
......@@ -2796,7 +2926,7 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27962926
27972927 .opaque_type => false,
27982928
2799 .enum_type => return Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).comptimeOnlyAdvanced(pt, strat),
2929 .enum_type => return Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).comptimeOnlyInner(strat, zcu, tid),
28002930
28012931 // values, not types
28022932 .undef,
......@@ -2823,53 +2953,53 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
28232953 };
28242954}
28252955
2826pub fn isVector(ty: Type, mod: *const Module) bool {
2827 return ty.zigTypeTag(mod) == .Vector;
2956pub fn isVector(ty: Type, zcu: *const Zcu) bool {
2957 return ty.zigTypeTag(zcu) == .Vector;
28282958}
28292959
28302960/// Returns 0 if not a vector, otherwise returns @bitSizeOf(Element) * vector_len.
2831pub fn totalVectorBits(ty: Type, pt: Zcu.PerThread) u64 {
2832 if (!ty.isVector(pt.zcu)) return 0;
2833 const v = pt.zcu.intern_pool.indexToKey(ty.toIntern()).vector_type;
2834 return v.len * Type.fromInterned(v.child).bitSize(pt);
2961pub fn totalVectorBits(ty: Type, zcu: *Zcu) u64 {
2962 if (!ty.isVector(zcu)) return 0;
2963 const v = zcu.intern_pool.indexToKey(ty.toIntern()).vector_type;
2964 return v.len * Type.fromInterned(v.child).bitSize(zcu);
28352965}
28362966
2837pub fn isArrayOrVector(ty: Type, mod: *const Module) bool {
2838 return switch (ty.zigTypeTag(mod)) {
2967pub fn isArrayOrVector(ty: Type, zcu: *const Zcu) bool {
2968 return switch (ty.zigTypeTag(zcu)) {
28392969 .Array, .Vector => true,
28402970 else => false,
28412971 };
28422972}
28432973
2844pub fn isIndexable(ty: Type, mod: *Module) bool {
2845 return switch (ty.zigTypeTag(mod)) {
2974pub fn isIndexable(ty: Type, zcu: *const Zcu) bool {
2975 return switch (ty.zigTypeTag(zcu)) {
28462976 .Array, .Vector => true,
2847 .Pointer => switch (ty.ptrSize(mod)) {
2977 .Pointer => switch (ty.ptrSize(zcu)) {
28482978 .Slice, .Many, .C => true,
2849 .One => switch (ty.childType(mod).zigTypeTag(mod)) {
2979 .One => switch (ty.childType(zcu).zigTypeTag(zcu)) {
28502980 .Array, .Vector => true,
2851 .Struct => ty.childType(mod).isTuple(mod),
2981 .Struct => ty.childType(zcu).isTuple(zcu),
28522982 else => false,
28532983 },
28542984 },
2855 .Struct => ty.isTuple(mod),
2985 .Struct => ty.isTuple(zcu),
28562986 else => false,
28572987 };
28582988}
28592989
2860pub fn indexableHasLen(ty: Type, mod: *Module) bool {
2861 return switch (ty.zigTypeTag(mod)) {
2990pub fn indexableHasLen(ty: Type, zcu: *const Zcu) bool {
2991 return switch (ty.zigTypeTag(zcu)) {
28622992 .Array, .Vector => true,
2863 .Pointer => switch (ty.ptrSize(mod)) {
2993 .Pointer => switch (ty.ptrSize(zcu)) {
28642994 .Many, .C => false,
28652995 .Slice => true,
2866 .One => switch (ty.childType(mod).zigTypeTag(mod)) {
2996 .One => switch (ty.childType(zcu).zigTypeTag(zcu)) {
28672997 .Array, .Vector => true,
2868 .Struct => ty.childType(mod).isTuple(mod),
2998 .Struct => ty.childType(zcu).isTuple(zcu),
28692999 else => false,
28703000 },
28713001 },
2872 .Struct => ty.isTuple(mod),
3002 .Struct => ty.isTuple(zcu),
28733003 else => false,
28743004 };
28753005}
......@@ -2973,17 +3103,17 @@ pub fn maxIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
29733103}
29743104
29753105/// Asserts the type is an enum or a union.
2976pub fn intTagType(ty: Type, mod: *Module) Type {
2977 const ip = &mod.intern_pool;
3106pub fn intTagType(ty: Type, zcu: *const Zcu) Type {
3107 const ip = &zcu.intern_pool;
29783108 return switch (ip.indexToKey(ty.toIntern())) {
2979 .union_type => Type.fromInterned(ip.loadUnionType(ty.toIntern()).enum_tag_ty).intTagType(mod),
3109 .union_type => Type.fromInterned(ip.loadUnionType(ty.toIntern()).enum_tag_ty).intTagType(zcu),
29803110 .enum_type => Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty),
29813111 else => unreachable,
29823112 };
29833113}
29843114
2985pub fn isNonexhaustiveEnum(ty: Type, mod: *Module) bool {
2986 const ip = &mod.intern_pool;
3115pub fn isNonexhaustiveEnum(ty: Type, zcu: *const Zcu) bool {
3116 const ip = &zcu.intern_pool;
29873117 return switch (ip.indexToKey(ty.toIntern())) {
29883118 .enum_type => switch (ip.loadEnumType(ty.toIntern()).tag_mode) {
29893119 .nonexhaustive => true,
......@@ -2995,8 +3125,8 @@ pub fn isNonexhaustiveEnum(ty: Type, mod: *Module) bool {
29953125
29963126// Asserts that `ty` is an error set and not `anyerror`.
29973127// Asserts that `ty` is resolved if it is an inferred error set.
2998pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Slice {
2999 const ip = &mod.intern_pool;
3128pub fn errorSetNames(ty: Type, zcu: *const Zcu) InternPool.NullTerminatedString.Slice {
3129 const ip = &zcu.intern_pool;
30003130 return switch (ip.indexToKey(ty.toIntern())) {
30013131 .error_set_type => |x| x.names,
30023132 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
......@@ -3008,21 +3138,21 @@ pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Sli
30083138 };
30093139}
30103140
3011pub fn enumFields(ty: Type, mod: *Module) InternPool.NullTerminatedString.Slice {
3012 return mod.intern_pool.loadEnumType(ty.toIntern()).names;
3141pub fn enumFields(ty: Type, zcu: *const Zcu) InternPool.NullTerminatedString.Slice {
3142 return zcu.intern_pool.loadEnumType(ty.toIntern()).names;
30133143}
30143144
3015pub fn enumFieldCount(ty: Type, mod: *Module) usize {
3016 return mod.intern_pool.loadEnumType(ty.toIntern()).names.len;
3145pub fn enumFieldCount(ty: Type, zcu: *const Zcu) usize {
3146 return zcu.intern_pool.loadEnumType(ty.toIntern()).names.len;
30173147}
30183148
3019pub fn enumFieldName(ty: Type, field_index: usize, mod: *Module) InternPool.NullTerminatedString {
3020 const ip = &mod.intern_pool;
3149pub fn enumFieldName(ty: Type, field_index: usize, zcu: *const Zcu) InternPool.NullTerminatedString {
3150 const ip = &zcu.intern_pool;
30213151 return ip.loadEnumType(ty.toIntern()).names.get(ip)[field_index];
30223152}
30233153
3024pub fn enumFieldIndex(ty: Type, field_name: InternPool.NullTerminatedString, mod: *Module) ?u32 {
3025 const ip = &mod.intern_pool;
3154pub fn enumFieldIndex(ty: Type, field_name: InternPool.NullTerminatedString, zcu: *const Zcu) ?u32 {
3155 const ip = &zcu.intern_pool;
30263156 const enum_type = ip.loadEnumType(ty.toIntern());
30273157 return enum_type.nameIndex(ip, field_name);
30283158}
......@@ -3030,8 +3160,8 @@ pub fn enumFieldIndex(ty: Type, field_name: InternPool.NullTerminatedString, mod
30303160/// Asserts `ty` is an enum. `enum_tag` can either be `enum_field_index` or
30313161/// an integer which represents the enum value. Returns the field index in
30323162/// declaration order, or `null` if `enum_tag` does not match any field.
3033pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {
3034 const ip = &mod.intern_pool;
3163pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, zcu: *const Zcu) ?u32 {
3164 const ip = &zcu.intern_pool;
30353165 const enum_type = ip.loadEnumType(ty.toIntern());
30363166 const int_tag = switch (ip.indexToKey(enum_tag.toIntern())) {
30373167 .int => enum_tag.toIntern(),
......@@ -3043,8 +3173,8 @@ pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {
30433173}
30443174
30453175/// Returns none in the case of a tuple which uses the integer index as the field name.
3046pub fn structFieldName(ty: Type, index: usize, mod: *Module) InternPool.OptionalNullTerminatedString {
3047 const ip = &mod.intern_pool;
3176pub fn structFieldName(ty: Type, index: usize, zcu: *const Zcu) InternPool.OptionalNullTerminatedString {
3177 const ip = &zcu.intern_pool;
30483178 return switch (ip.indexToKey(ty.toIntern())) {
30493179 .struct_type => ip.loadStructType(ty.toIntern()).fieldName(ip, index),
30503180 .anon_struct_type => |anon_struct| anon_struct.fieldName(ip, index),
......@@ -3052,8 +3182,8 @@ pub fn structFieldName(ty: Type, index: usize, mod: *Module) InternPool.Optional
30523182 };
30533183}
30543184
3055pub fn structFieldCount(ty: Type, mod: *Module) u32 {
3056 const ip = &mod.intern_pool;
3185pub fn structFieldCount(ty: Type, zcu: *const Zcu) u32 {
3186 const ip = &zcu.intern_pool;
30573187 return switch (ip.indexToKey(ty.toIntern())) {
30583188 .struct_type => ip.loadStructType(ty.toIntern()).field_types.len,
30593189 .anon_struct_type => |anon_struct| anon_struct.types.len,
......@@ -3062,8 +3192,8 @@ pub fn structFieldCount(ty: Type, mod: *Module) u32 {
30623192}
30633193
30643194/// Supports structs and unions.
3065pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {
3066 const ip = &mod.intern_pool;
3195pub fn structFieldType(ty: Type, index: usize, zcu: *const Zcu) Type {
3196 const ip = &zcu.intern_pool;
30673197 return switch (ip.indexToKey(ty.toIntern())) {
30683198 .struct_type => Type.fromInterned(ip.loadStructType(ty.toIntern()).field_types.get(ip)[index]),
30693199 .union_type => {
......@@ -3075,33 +3205,111 @@ pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {
30753205 };
30763206}
30773207
3078pub fn structFieldAlign(ty: Type, index: usize, pt: Zcu.PerThread) Alignment {
3079 return ty.structFieldAlignAdvanced(index, pt, .normal) catch unreachable;
3208pub fn structFieldAlign(ty: Type, index: usize, zcu: *Zcu) Alignment {
3209 return ty.structFieldAlignAdvanced(index, .normal, zcu, {}) catch unreachable;
30803210}
30813211
3082pub fn structFieldAlignAdvanced(ty: Type, index: usize, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment {
3083 const ip = &pt.zcu.intern_pool;
3212pub fn structFieldAlignAdvanced(
3213 ty: Type,
3214 index: usize,
3215 comptime strat: ResolveStrat,
3216 zcu: *Zcu,
3217 tid: strat.Tid(),
3218) !Alignment {
3219 const ip = &zcu.intern_pool;
30843220 switch (ip.indexToKey(ty.toIntern())) {
30853221 .struct_type => {
30863222 const struct_type = ip.loadStructType(ty.toIntern());
30873223 assert(struct_type.layout != .@"packed");
30883224 const explicit_align = struct_type.fieldAlign(ip, index);
30893225 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[index]);
3090 return pt.structFieldAlignmentAdvanced(explicit_align, field_ty, struct_type.layout, strat);
3226 return field_ty.structFieldAlignmentAdvanced(
3227 explicit_align,
3228 struct_type.layout,
3229 strat,
3230 zcu,
3231 tid,
3232 );
30913233 },
30923234 .anon_struct_type => |anon_struct| {
3093 return (try Type.fromInterned(anon_struct.types.get(ip)[index]).abiAlignmentAdvanced(pt, strat.toLazy())).scalar;
3235 return (try Type.fromInterned(anon_struct.types.get(ip)[index]).abiAlignmentInner(
3236 strat.toLazy(),
3237 zcu,
3238 tid,
3239 )).scalar;
30943240 },
30953241 .union_type => {
30963242 const union_obj = ip.loadUnionType(ty.toIntern());
3097 return pt.unionFieldNormalAlignmentAdvanced(union_obj, @intCast(index), strat);
3243 return unionFieldNormalAlignmentAdvanced(
3244 union_obj,
3245 @intCast(index),
3246 strat,
3247 zcu,
3248 tid,
3249 );
30983250 },
30993251 else => unreachable,
31003252 }
31013253}
31023254
3103pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value {
3104 const ip = &mod.intern_pool;
3255/// Returns the field alignment of a non-packed struct. Asserts the layout is not packed.
3256/// If `strat` is `.sema`, may perform type resolution.
3257pub fn structFieldAlignmentAdvanced(
3258 field_ty: Type,
3259 explicit_alignment: InternPool.Alignment,
3260 layout: std.builtin.Type.ContainerLayout,
3261 comptime strat: Type.ResolveStrat,
3262 zcu: *Zcu,
3263 tid: strat.Tid(),
3264) Zcu.SemaError!InternPool.Alignment {
3265 assert(layout != .@"packed");
3266 if (explicit_alignment != .none) return explicit_alignment;
3267 const ty_abi_align = (try field_ty.abiAlignmentInner(
3268 strat.toLazy(),
3269 zcu,
3270 tid,
3271 )).scalar;
3272 switch (layout) {
3273 .@"packed" => unreachable,
3274 .auto => if (zcu.getTarget().ofmt != .c) return ty_abi_align,
3275 .@"extern" => {},
3276 }
3277 // extern
3278 if (field_ty.isAbiInt(zcu) and field_ty.intInfo(zcu).bits >= 128) {
3279 return ty_abi_align.maxStrict(.@"16");
3280 }
3281 return ty_abi_align;
3282}
3283
3284/// Returns the field alignment of a non-packed union. Asserts the layout is not packed.
3285pub fn unionFieldNormalAlignment(
3286 loaded_union: InternPool.LoadedUnionType,
3287 field_index: u32,
3288 zcu: *Zcu,
3289) InternPool.Alignment {
3290 return unionFieldNormalAlignmentAdvanced(loaded_union, field_index, .normal, zcu, {}) catch unreachable;
3291}
3292
3293/// Returns the field alignment of a non-packed union. Asserts the layout is not packed.
3294/// If `strat` is `.sema`, may perform type resolution.
3295pub fn unionFieldNormalAlignmentAdvanced(
3296 loaded_union: InternPool.LoadedUnionType,
3297 field_index: u32,
3298 comptime strat: Type.ResolveStrat,
3299 zcu: *Zcu,
3300 tid: strat.Tid(),
3301) Zcu.SemaError!InternPool.Alignment {
3302 const ip = &zcu.intern_pool;
3303 assert(loaded_union.flagsUnordered(ip).layout != .@"packed");
3304 const field_align = loaded_union.fieldAlign(ip, field_index);
3305 if (field_align != .none) return field_align;
3306 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
3307 if (field_ty.isNoReturn(zcu)) return .none;
3308 return (try field_ty.abiAlignmentInner(strat.toLazy(), zcu, tid)).scalar;
3309}
3310
3311pub fn structFieldDefaultValue(ty: Type, index: usize, zcu: *const Zcu) Value {
3312 const ip = &zcu.intern_pool;
31053313 switch (ip.indexToKey(ty.toIntern())) {
31063314 .struct_type => {
31073315 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3121,8 +3329,8 @@ pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value {
31213329}
31223330
31233331pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Value {
3124 const mod = pt.zcu;
3125 const ip = &mod.intern_pool;
3332 const zcu = pt.zcu;
3333 const ip = &zcu.intern_pool;
31263334 switch (ip.indexToKey(ty.toIntern())) {
31273335 .struct_type => {
31283336 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3145,8 +3353,8 @@ pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Val
31453353 }
31463354}
31473355
3148pub fn structFieldIsComptime(ty: Type, index: usize, mod: *Module) bool {
3149 const ip = &mod.intern_pool;
3356pub fn structFieldIsComptime(ty: Type, index: usize, zcu: *const Zcu) bool {
3357 const ip = &zcu.intern_pool;
31503358 return switch (ip.indexToKey(ty.toIntern())) {
31513359 .struct_type => ip.loadStructType(ty.toIntern()).fieldIsComptime(ip, index),
31523360 .anon_struct_type => |anon_struct| anon_struct.values.get(ip)[index] != .none,
......@@ -3160,9 +3368,12 @@ pub const FieldOffset = struct {
31603368};
31613369
31623370/// Supports structs and unions.
3163pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
3164 const mod = pt.zcu;
3165 const ip = &mod.intern_pool;
3371pub fn structFieldOffset(
3372 ty: Type,
3373 index: usize,
3374 zcu: *Zcu,
3375) u64 {
3376 const ip = &zcu.intern_pool;
31663377 switch (ip.indexToKey(ty.toIntern())) {
31673378 .struct_type => {
31683379 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3176,17 +3387,17 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
31763387 var big_align: Alignment = .none;
31773388
31783389 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
3179 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) {
3390 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) {
31803391 // comptime field
31813392 if (i == index) return offset;
31823393 continue;
31833394 }
31843395
3185 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
3396 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
31863397 big_align = big_align.max(field_align);
31873398 offset = field_align.forward(offset);
31883399 if (i == index) return offset;
3189 offset += Type.fromInterned(field_ty).abiSize(pt);
3400 offset += Type.fromInterned(field_ty).abiSize(zcu);
31903401 }
31913402 offset = big_align.max(.@"1").forward(offset);
31923403 return offset;
......@@ -3196,7 +3407,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
31963407 const union_type = ip.loadUnionType(ty.toIntern());
31973408 if (!union_type.hasTag(ip))
31983409 return 0;
3199 const layout = pt.getUnionLayout(union_type);
3410 const layout = union_type.getUnionLayout(zcu);
32003411 if (layout.tag_align.compare(.gte, layout.payload_align)) {
32013412 // {Tag, Payload}
32023413 return layout.payload_align.forward(layout.tag_size);
......@@ -3210,7 +3421,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
32103421 }
32113422}
32123423
3213pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {
3424pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Zcu.LazySrcLoc {
32143425 const ip = &zcu.intern_pool;
32153426 return .{
32163427 .base_node_inst = switch (ip.indexToKey(ty.toIntern())) {
......@@ -3222,11 +3433,11 @@ pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {
32223433 },
32233434 else => return null,
32243435 },
3225 .offset = Module.LazySrcLoc.Offset.nodeOffset(0),
3436 .offset = Zcu.LazySrcLoc.Offset.nodeOffset(0),
32263437 };
32273438}
32283439
3229pub fn srcLoc(ty: Type, zcu: *Zcu) Module.LazySrcLoc {
3440pub fn srcLoc(ty: Type, zcu: *Zcu) Zcu.LazySrcLoc {
32303441 return ty.srcLocOrNull(zcu).?;
32313442}
32323443
......@@ -3234,8 +3445,8 @@ pub fn isGenericPoison(ty: Type) bool {
32343445 return ty.toIntern() == .generic_poison_type;
32353446}
32363447
3237pub fn isTuple(ty: Type, mod: *Module) bool {
3238 const ip = &mod.intern_pool;
3448pub fn isTuple(ty: Type, zcu: *const Zcu) bool {
3449 const ip = &zcu.intern_pool;
32393450 return switch (ip.indexToKey(ty.toIntern())) {
32403451 .struct_type => {
32413452 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3248,16 +3459,16 @@ pub fn isTuple(ty: Type, mod: *Module) bool {
32483459 };
32493460}
32503461
3251pub fn isAnonStruct(ty: Type, mod: *Module) bool {
3462pub fn isAnonStruct(ty: Type, zcu: *const Zcu) bool {
32523463 if (ty.toIntern() == .empty_struct_type) return true;
3253 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3464 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
32543465 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len > 0,
32553466 else => false,
32563467 };
32573468}
32583469
3259pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
3260 const ip = &mod.intern_pool;
3470pub fn isTupleOrAnonStruct(ty: Type, zcu: *const Zcu) bool {
3471 const ip = &zcu.intern_pool;
32613472 return switch (ip.indexToKey(ty.toIntern())) {
32623473 .struct_type => {
32633474 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3270,15 +3481,15 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
32703481 };
32713482}
32723483
3273pub fn isSimpleTuple(ty: Type, mod: *Module) bool {
3274 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3484pub fn isSimpleTuple(ty: Type, zcu: *const Zcu) bool {
3485 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
32753486 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len == 0,
32763487 else => false,
32773488 };
32783489}
32793490
3280pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool {
3281 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3491pub fn isSimpleTupleOrAnonStruct(ty: Type, zcu: *const Zcu) bool {
3492 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
32823493 .anon_struct_type => true,
32833494 else => false,
32843495 };
......@@ -3286,11 +3497,11 @@ pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool {
32863497
32873498/// Traverses optional child types and error union payloads until the type
32883499/// is not a pointer. For `E!?u32`, returns `u32`; for `*u8`, returns `*u8`.
3289pub fn optEuBaseType(ty: Type, mod: *Module) Type {
3500pub fn optEuBaseType(ty: Type, zcu: *const Zcu) Type {
32903501 var cur = ty;
3291 while (true) switch (cur.zigTypeTag(mod)) {
3292 .Optional => cur = cur.optionalChild(mod),
3293 .ErrorUnion => cur = cur.errorUnionPayload(mod),
3502 while (true) switch (cur.zigTypeTag(zcu)) {
3503 .Optional => cur = cur.optionalChild(zcu),
3504 .ErrorUnion => cur = cur.errorUnionPayload(zcu),
32943505 else => return cur,
32953506 };
32963507}
......@@ -3406,7 +3617,7 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
34063617 if (i == field_idx) {
34073618 bit_offset = running_bits;
34083619 }
3409 running_bits += @intCast(f_ty.bitSize(pt));
3620 running_bits += @intCast(f_ty.bitSize(zcu));
34103621 }
34113622
34123623 const res_host_size: u16, const res_bit_offset: u16 = if (parent_ptr_info.packed_offset.host_size != 0)
......@@ -3423,9 +3634,9 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
34233634 // targets before adding the necessary complications to this code. This will not
34243635 // cause miscompilations; it only means the field pointer uses bit masking when it
34253636 // might not be strictly necessary.
3426 if (res_bit_offset % 8 == 0 and field_ty.bitSize(pt) == field_ty.abiSize(pt) * 8 and zcu.getTarget().cpu.arch.endian() == .little) {
3637 if (res_bit_offset % 8 == 0 and field_ty.bitSize(zcu) == field_ty.abiSize(zcu) * 8 and zcu.getTarget().cpu.arch.endian() == .little) {
34273638 const byte_offset = res_bit_offset / 8;
3428 const new_align = Alignment.fromLog2Units(@ctz(byte_offset | parent_ptr_ty.ptrAlignment(pt).toByteUnits().?));
3639 const new_align = Alignment.fromLog2Units(@ctz(byte_offset | parent_ptr_ty.ptrAlignment(zcu).toByteUnits().?));
34293640 return .{ .byte_ptr = .{
34303641 .offset = byte_offset,
34313642 .alignment = new_align,
......@@ -3768,14 +3979,14 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {
37683979 alignment: Alignment = .none,
37693980 vector_index: VI = .none,
37703981 } = if (parent_ty.isVector(zcu) and ptr_info.flags.size == .One) blk: {
3771 const elem_bits = elem_ty.bitSize(pt);
3982 const elem_bits = elem_ty.bitSize(zcu);
37723983 if (elem_bits == 0) break :blk .{};
37733984 const is_packed = elem_bits < 8 or !std.math.isPowerOfTwo(elem_bits);
37743985 if (!is_packed) break :blk .{};
37753986
37763987 break :blk .{
37773988 .host_size = @intCast(parent_ty.arrayLen(zcu)),
3778 .alignment = parent_ty.abiAlignment(pt),
3989 .alignment = parent_ty.abiAlignment(zcu),
37793990 .vector_index = if (offset) |some| @enumFromInt(some) else .runtime,
37803991 };
37813992 } else .{};
......@@ -3789,7 +4000,7 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {
37894000 }
37904001 // If the addend is not a comptime-known value we can still count on
37914002 // it being a multiple of the type size.
3792 const elem_size = (try elem_ty.abiSizeAdvanced(pt, .sema)).scalar;
4003 const elem_size = (try elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar;
37934004 const addend = if (offset) |off| elem_size * off else elem_size;
37944005
37954006 // The resulting pointer is aligned to the lcd between the offset (an
src/Value.zig+759-689
......@@ -65,19 +65,19 @@ pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_
6565/// Converts `val` to a null-terminated string stored in the InternPool.
6666/// Asserts `val` is an array of `u8`
6767pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
68 const mod = pt.zcu;
69 assert(ty.zigTypeTag(mod) == .Array);
70 assert(ty.childType(mod).toIntern() == .u8_type);
71 const ip = &mod.intern_pool;
72 switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {
73 .bytes => |bytes| return bytes.toNullTerminatedString(ty.arrayLen(mod), ip),
74 .elems => return arrayToIpString(val, ty.arrayLen(mod), pt),
68 const zcu = pt.zcu;
69 assert(ty.zigTypeTag(zcu) == .Array);
70 assert(ty.childType(zcu).toIntern() == .u8_type);
71 const ip = &zcu.intern_pool;
72 switch (zcu.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {
73 .bytes => |bytes| return bytes.toNullTerminatedString(ty.arrayLen(zcu), ip),
74 .elems => return arrayToIpString(val, ty.arrayLen(zcu), pt),
7575 .repeated_elem => |elem| {
76 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt));
77 const len: u32 = @intCast(ty.arrayLen(mod));
78 const strings = ip.getLocal(pt.tid).getMutableStrings(mod.gpa);
76 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(zcu));
77 const len: u32 = @intCast(ty.arrayLen(zcu));
78 const strings = ip.getLocal(pt.tid).getMutableStrings(zcu.gpa);
7979 try strings.appendNTimes(.{byte}, len);
80 return ip.getOrPutTrailingString(mod.gpa, pt.tid, len, .no_embedded_nulls);
80 return ip.getOrPutTrailingString(zcu.gpa, pt.tid, len, .no_embedded_nulls);
8181 },
8282 }
8383}
......@@ -85,17 +85,17 @@ pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTermi
8585/// Asserts that the value is representable as an array of bytes.
8686/// Copies the value into a freshly allocated slice of memory, which is owned by the caller.
8787pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) ![]u8 {
88 const mod = pt.zcu;
89 const ip = &mod.intern_pool;
88 const zcu = pt.zcu;
89 const ip = &zcu.intern_pool;
9090 return switch (ip.indexToKey(val.toIntern())) {
9191 .enum_literal => |enum_literal| allocator.dupe(u8, enum_literal.toSlice(ip)),
92 .slice => |slice| try arrayToAllocatedBytes(val, Value.fromInterned(slice.len).toUnsignedInt(pt), allocator, pt),
92 .slice => |slice| try arrayToAllocatedBytes(val, Value.fromInterned(slice.len).toUnsignedInt(zcu), allocator, pt),
9393 .aggregate => |aggregate| switch (aggregate.storage) {
94 .bytes => |bytes| try allocator.dupe(u8, bytes.toSlice(ty.arrayLenIncludingSentinel(mod), ip)),
95 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, pt),
94 .bytes => |bytes| try allocator.dupe(u8, bytes.toSlice(ty.arrayLenIncludingSentinel(zcu), ip)),
95 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(zcu), allocator, pt),
9696 .repeated_elem => |elem| {
97 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt));
98 const result = try allocator.alloc(u8, @intCast(ty.arrayLen(mod)));
97 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(zcu));
98 const result = try allocator.alloc(u8, @intCast(ty.arrayLen(zcu)));
9999 @memset(result, byte);
100100 return result;
101101 },
......@@ -108,15 +108,15 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, pt: Zcu.Per
108108 const result = try allocator.alloc(u8, @intCast(len));
109109 for (result, 0..) |*elem, i| {
110110 const elem_val = try val.elemValue(pt, i);
111 elem.* = @intCast(elem_val.toUnsignedInt(pt));
111 elem.* = @intCast(elem_val.toUnsignedInt(pt.zcu));
112112 }
113113 return result;
114114}
115115
116116fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
117 const mod = pt.zcu;
118 const gpa = mod.gpa;
119 const ip = &mod.intern_pool;
117 const zcu = pt.zcu;
118 const gpa = zcu.gpa;
119 const ip = &zcu.intern_pool;
120120 const len: u32 = @intCast(len_u64);
121121 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);
122122 try strings.ensureUnusedCapacity(len);
......@@ -126,7 +126,7 @@ fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.Null
126126 const prev_len = strings.mutate.len;
127127 const elem_val = try val.elemValue(pt, i);
128128 assert(strings.mutate.len == prev_len);
129 const byte: u8 = @intCast(elem_val.toUnsignedInt(pt));
129 const byte: u8 = @intCast(elem_val.toUnsignedInt(zcu));
130130 strings.appendAssumeCapacity(.{byte});
131131 }
132132 return ip.getOrPutTrailingString(gpa, pt.tid, len, .no_embedded_nulls);
......@@ -178,50 +178,55 @@ pub fn intFromEnum(val: Value, ty: Type, pt: Zcu.PerThread) Allocator.Error!Valu
178178pub const ResolveStrat = Type.ResolveStrat;
179179
180180/// Asserts the value is an integer.
181pub fn toBigInt(val: Value, space: *BigIntSpace, pt: Zcu.PerThread) BigIntConst {
182 return val.toBigIntAdvanced(space, pt, .normal) catch unreachable;
181pub fn toBigInt(val: Value, space: *BigIntSpace, zcu: *Zcu) BigIntConst {
182 return val.toBigIntAdvanced(space, .normal, zcu, {}) catch unreachable;
183}
184
185pub fn toBigIntSema(val: Value, space: *BigIntSpace, pt: Zcu.PerThread) !BigIntConst {
186 return try val.toBigIntAdvanced(space, .sema, pt.zcu, pt.tid);
183187}
184188
185189/// Asserts the value is an integer.
186190pub fn toBigIntAdvanced(
187191 val: Value,
188192 space: *BigIntSpace,
189 pt: Zcu.PerThread,
190193 comptime strat: ResolveStrat,
194 zcu: *Zcu,
195 tid: strat.Tid(),
191196) Module.CompileError!BigIntConst {
192197 return switch (val.toIntern()) {
193198 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
194199 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
195200 .null_value => BigIntMutable.init(&space.limbs, 0).toConst(),
196 else => switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
201 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
197202 .int => |int| switch (int.storage) {
198203 .u64, .i64, .big_int => int.storage.toBigInt(space),
199204 .lazy_align, .lazy_size => |ty| {
200 if (strat == .sema) try Type.fromInterned(ty).resolveLayout(pt);
205 if (strat == .sema) try Type.fromInterned(ty).resolveLayout(strat.pt(zcu, tid));
201206 const x = switch (int.storage) {
202207 else => unreachable,
203 .lazy_align => Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0,
204 .lazy_size => Type.fromInterned(ty).abiSize(pt),
208 .lazy_align => Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0,
209 .lazy_size => Type.fromInterned(ty).abiSize(zcu),
205210 };
206211 return BigIntMutable.init(&space.limbs, x).toConst();
207212 },
208213 },
209 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).toBigIntAdvanced(space, pt, strat),
214 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).toBigIntAdvanced(space, strat, zcu, tid),
210215 .opt, .ptr => BigIntMutable.init(
211216 &space.limbs,
212 (try val.getUnsignedIntAdvanced(pt, strat)).?,
217 (try val.getUnsignedIntInner(strat, zcu, tid)).?,
213218 ).toConst(),
214219 else => unreachable,
215220 },
216221 };
217222}
218223
219pub fn isFuncBody(val: Value, mod: *Module) bool {
220 return mod.intern_pool.isFuncBody(val.toIntern());
224pub fn isFuncBody(val: Value, zcu: *Module) bool {
225 return zcu.intern_pool.isFuncBody(val.toIntern());
221226}
222227
223pub fn getFunction(val: Value, mod: *Module) ?InternPool.Key.Func {
224 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
228pub fn getFunction(val: Value, zcu: *Module) ?InternPool.Key.Func {
229 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
225230 .func => |x| x,
226231 else => null,
227232 };
......@@ -236,68 +241,79 @@ pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {
236241
237242/// If the value fits in a u64, return it, otherwise null.
238243/// Asserts not undefined.
239pub fn getUnsignedInt(val: Value, pt: Zcu.PerThread) ?u64 {
240 return getUnsignedIntAdvanced(val, pt, .normal) catch unreachable;
244pub fn getUnsignedInt(val: Value, zcu: *Zcu) ?u64 {
245 return getUnsignedIntInner(val, .normal, zcu, {}) catch unreachable;
246}
247
248/// Asserts the value is an integer and it fits in a u64
249pub fn toUnsignedInt(val: Value, zcu: *Zcu) u64 {
250 return getUnsignedInt(val, zcu).?;
251}
252
253pub fn getUnsignedIntSema(val: Value, pt: Zcu.PerThread) !?u64 {
254 return try val.getUnsignedIntInner(.sema, pt.zcu, pt.tid);
241255}
242256
243257/// If the value fits in a u64, return it, otherwise null.
244258/// Asserts not undefined.
245pub fn getUnsignedIntAdvanced(val: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !?u64 {
246 const mod = pt.zcu;
259pub fn getUnsignedIntInner(
260 val: Value,
261 comptime strat: ResolveStrat,
262 zcu: *Zcu,
263 tid: strat.Tid(),
264) !?u64 {
247265 return switch (val.toIntern()) {
248266 .undef => unreachable,
249267 .bool_false => 0,
250268 .bool_true => 1,
251 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
269 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
252270 .undef => unreachable,
253271 .int => |int| switch (int.storage) {
254272 .big_int => |big_int| big_int.to(u64) catch null,
255273 .u64 => |x| x,
256274 .i64 => |x| std.math.cast(u64, x),
257 .lazy_align => |ty| (try Type.fromInterned(ty).abiAlignmentAdvanced(pt, strat.toLazy())).scalar.toByteUnits() orelse 0,
258 .lazy_size => |ty| (try Type.fromInterned(ty).abiSizeAdvanced(pt, strat.toLazy())).scalar,
275 .lazy_align => |ty| (try Type.fromInterned(ty).abiAlignmentInner(strat.toLazy(), zcu, tid)).scalar.toByteUnits() orelse 0,
276 .lazy_size => |ty| (try Type.fromInterned(ty).abiSizeInner(strat.toLazy(), zcu, tid)).scalar,
259277 },
260278 .ptr => |ptr| switch (ptr.base_addr) {
261279 .int => ptr.byte_offset,
262280 .field => |field| {
263 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(pt, strat)) orelse return null;
264 const struct_ty = Value.fromInterned(field.base).typeOf(mod).childType(mod);
265 if (strat == .sema) try struct_ty.resolveLayout(pt);
266 return base_addr + struct_ty.structFieldOffset(@intCast(field.index), pt) + ptr.byte_offset;
281 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntInner(strat, zcu, tid)) orelse return null;
282 const struct_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu);
283 if (strat == .sema) {
284 const pt = strat.pt(zcu, tid);
285 try struct_ty.resolveLayout(pt);
286 }
287 return base_addr + struct_ty.structFieldOffset(@intCast(field.index), zcu) + ptr.byte_offset;
267288 },
268289 else => null,
269290 },
270291 .opt => |opt| switch (opt.val) {
271292 .none => 0,
272 else => |payload| Value.fromInterned(payload).getUnsignedIntAdvanced(pt, strat),
293 else => |payload| Value.fromInterned(payload).getUnsignedIntInner(strat, zcu, tid),
273294 },
274295 else => null,
275296 },
276297 };
277298}
278299
279/// Asserts the value is an integer and it fits in a u64
280pub fn toUnsignedInt(val: Value, pt: Zcu.PerThread) u64 {
281 return getUnsignedInt(val, pt).?;
282}
283
284300/// Asserts the value is an integer and it fits in a u64
285301pub fn toUnsignedIntSema(val: Value, pt: Zcu.PerThread) !u64 {
286 return (try getUnsignedIntAdvanced(val, pt, .sema)).?;
302 return (try getUnsignedIntInner(val, .sema, pt.zcu, pt.tid)).?;
287303}
288304
289305/// Asserts the value is an integer and it fits in a i64
290pub fn toSignedInt(val: Value, pt: Zcu.PerThread) i64 {
306pub fn toSignedInt(val: Value, zcu: *Zcu) i64 {
291307 return switch (val.toIntern()) {
292308 .bool_false => 0,
293309 .bool_true => 1,
294 else => switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
310 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
295311 .int => |int| switch (int.storage) {
296312 .big_int => |big_int| big_int.to(i64) catch unreachable,
297313 .i64 => |x| x,
298314 .u64 => |x| @intCast(x),
299 .lazy_align => |ty| @intCast(Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0),
300 .lazy_size => |ty| @intCast(Type.fromInterned(ty).abiSize(pt)),
315 .lazy_align => |ty| @intCast(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0),
316 .lazy_size => |ty| @intCast(Type.fromInterned(ty).abiSize(zcu)),
301317 },
302318 else => unreachable,
303319 },
......@@ -326,41 +342,41 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
326342 Unimplemented,
327343 OutOfMemory,
328344}!void {
329 const mod = pt.zcu;
330 const target = mod.getTarget();
345 const zcu = pt.zcu;
346 const target = zcu.getTarget();
331347 const endian = target.cpu.arch.endian();
332 if (val.isUndef(mod)) {
333 const size: usize = @intCast(ty.abiSize(pt));
348 if (val.isUndef(zcu)) {
349 const size: usize = @intCast(ty.abiSize(zcu));
334350 @memset(buffer[0..size], 0xaa);
335351 return;
336352 }
337 const ip = &mod.intern_pool;
338 switch (ty.zigTypeTag(mod)) {
353 const ip = &zcu.intern_pool;
354 switch (ty.zigTypeTag(zcu)) {
339355 .Void => {},
340356 .Bool => {
341357 buffer[0] = @intFromBool(val.toBool());
342358 },
343359 .Int, .Enum => {
344 const int_info = ty.intInfo(mod);
360 const int_info = ty.intInfo(zcu);
345361 const bits = int_info.bits;
346362 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
347363
348364 var bigint_buffer: BigIntSpace = undefined;
349 const bigint = val.toBigInt(&bigint_buffer, pt);
365 const bigint = val.toBigInt(&bigint_buffer, zcu);
350366 bigint.writeTwosComplement(buffer[0..byte_count], endian);
351367 },
352368 .Float => switch (ty.floatBits(target)) {
353 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(val.toFloat(f16, pt)), endian),
354 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(val.toFloat(f32, pt)), endian),
355 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(val.toFloat(f64, pt)), endian),
356 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(val.toFloat(f80, pt)), endian),
357 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(val.toFloat(f128, pt)), endian),
369 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(val.toFloat(f16, zcu)), endian),
370 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(val.toFloat(f32, zcu)), endian),
371 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(val.toFloat(f64, zcu)), endian),
372 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(val.toFloat(f80, zcu)), endian),
373 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(val.toFloat(f128, zcu)), endian),
358374 else => unreachable,
359375 },
360376 .Array => {
361 const len = ty.arrayLen(mod);
362 const elem_ty = ty.childType(mod);
363 const elem_size: usize = @intCast(elem_ty.abiSize(pt));
377 const len = ty.arrayLen(zcu);
378 const elem_ty = ty.childType(zcu);
379 const elem_size: usize = @intCast(elem_ty.abiSize(zcu));
364380 var elem_i: usize = 0;
365381 var buf_off: usize = 0;
366382 while (elem_i < len) : (elem_i += 1) {
......@@ -372,15 +388,15 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
372388 .Vector => {
373389 // We use byte_count instead of abi_size here, so that any padding bytes
374390 // follow the data bytes, on both big- and little-endian systems.
375 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
391 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
376392 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
377393 },
378394 .Struct => {
379 const struct_type = mod.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;
395 const struct_type = zcu.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;
380396 switch (struct_type.layout) {
381397 .auto => return error.IllDefinedMemoryLayout,
382398 .@"extern" => for (0..struct_type.field_types.len) |field_index| {
383 const off: usize = @intCast(ty.structFieldOffset(field_index, pt));
399 const off: usize = @intCast(ty.structFieldOffset(field_index, zcu));
384400 const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
385401 .bytes => |bytes| {
386402 buffer[off] = bytes.at(field_index, ip);
......@@ -393,13 +409,13 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
393409 try writeToMemory(field_val, field_ty, pt, buffer[off..]);
394410 },
395411 .@"packed" => {
396 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
412 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
397413 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
398414 },
399415 }
400416 },
401417 .ErrorSet => {
402 const bits = mod.errorSetBits();
418 const bits = zcu.errorSetBits();
403419 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
404420
405421 const name = switch (ip.indexToKey(val.toIntern())) {
......@@ -414,37 +430,37 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
414430 ).toConst();
415431 bigint.writeTwosComplement(buffer[0..byte_count], endian);
416432 },
417 .Union => switch (ty.containerLayout(mod)) {
433 .Union => switch (ty.containerLayout(zcu)) {
418434 .auto => return error.IllDefinedMemoryLayout, // Sema is supposed to have emitted a compile error already
419435 .@"extern" => {
420 if (val.unionTag(mod)) |union_tag| {
421 const union_obj = mod.typeToUnion(ty).?;
422 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;
436 if (val.unionTag(zcu)) |union_tag| {
437 const union_obj = zcu.typeToUnion(ty).?;
438 const field_index = zcu.unionTagFieldIndex(union_obj, union_tag).?;
423439 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
424440 const field_val = try val.fieldValue(pt, field_index);
425 const byte_count: usize = @intCast(field_type.abiSize(pt));
441 const byte_count: usize = @intCast(field_type.abiSize(zcu));
426442 return writeToMemory(field_val, field_type, pt, buffer[0..byte_count]);
427443 } else {
428444 const backing_ty = try ty.unionBackingType(pt);
429 const byte_count: usize = @intCast(backing_ty.abiSize(pt));
430 return writeToMemory(val.unionValue(mod), backing_ty, pt, buffer[0..byte_count]);
445 const byte_count: usize = @intCast(backing_ty.abiSize(zcu));
446 return writeToMemory(val.unionValue(zcu), backing_ty, pt, buffer[0..byte_count]);
431447 }
432448 },
433449 .@"packed" => {
434450 const backing_ty = try ty.unionBackingType(pt);
435 const byte_count: usize = @intCast(backing_ty.abiSize(pt));
451 const byte_count: usize = @intCast(backing_ty.abiSize(zcu));
436452 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
437453 },
438454 },
439455 .Pointer => {
440 if (ty.isSlice(mod)) return error.IllDefinedMemoryLayout;
441 if (!val.ptrHasIntAddr(mod)) return error.ReinterpretDeclRef;
456 if (ty.isSlice(zcu)) return error.IllDefinedMemoryLayout;
457 if (!val.ptrHasIntAddr(zcu)) return error.ReinterpretDeclRef;
442458 return val.writeToMemory(Type.usize, pt, buffer);
443459 },
444460 .Optional => {
445 if (!ty.isPtrLikeOptional(mod)) return error.IllDefinedMemoryLayout;
446 const child = ty.optionalChild(mod);
447 const opt_val = val.optionalValue(mod);
461 if (!ty.isPtrLikeOptional(zcu)) return error.IllDefinedMemoryLayout;
462 const child = ty.optionalChild(zcu);
463 const opt_val = val.optionalValue(zcu);
448464 if (opt_val) |some| {
449465 return some.writeToMemory(child, pt, buffer);
450466 } else {
......@@ -466,18 +482,18 @@ pub fn writeToPackedMemory(
466482 buffer: []u8,
467483 bit_offset: usize,
468484) error{ ReinterpretDeclRef, OutOfMemory }!void {
469 const mod = pt.zcu;
470 const ip = &mod.intern_pool;
471 const target = mod.getTarget();
485 const zcu = pt.zcu;
486 const ip = &zcu.intern_pool;
487 const target = zcu.getTarget();
472488 const endian = target.cpu.arch.endian();
473 if (val.isUndef(mod)) {
474 const bit_size: usize = @intCast(ty.bitSize(pt));
489 if (val.isUndef(zcu)) {
490 const bit_size: usize = @intCast(ty.bitSize(zcu));
475491 if (bit_size != 0) {
476492 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);
477493 }
478494 return;
479495 }
480 switch (ty.zigTypeTag(mod)) {
496 switch (ty.zigTypeTag(zcu)) {
481497 .Void => {},
482498 .Bool => {
483499 const byte_index = switch (endian) {
......@@ -492,34 +508,34 @@ pub fn writeToPackedMemory(
492508 },
493509 .Int, .Enum => {
494510 if (buffer.len == 0) return;
495 const bits = ty.intInfo(mod).bits;
511 const bits = ty.intInfo(zcu).bits;
496512 if (bits == 0) return;
497513
498514 switch (ip.indexToKey((try val.intFromEnum(ty, pt)).toIntern()).int.storage) {
499515 inline .u64, .i64 => |int| std.mem.writeVarPackedInt(buffer, bit_offset, bits, int, endian),
500516 .big_int => |bigint| bigint.writePackedTwosComplement(buffer, bit_offset, bits, endian),
501517 .lazy_align => |lazy_align| {
502 const num = Type.fromInterned(lazy_align).abiAlignment(pt).toByteUnits() orelse 0;
518 const num = Type.fromInterned(lazy_align).abiAlignment(zcu).toByteUnits() orelse 0;
503519 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
504520 },
505521 .lazy_size => |lazy_size| {
506 const num = Type.fromInterned(lazy_size).abiSize(pt);
522 const num = Type.fromInterned(lazy_size).abiSize(zcu);
507523 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
508524 },
509525 }
510526 },
511527 .Float => switch (ty.floatBits(target)) {
512 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(val.toFloat(f16, pt)), endian),
513 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(val.toFloat(f32, pt)), endian),
514 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(val.toFloat(f64, pt)), endian),
515 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(val.toFloat(f80, pt)), endian),
516 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(val.toFloat(f128, pt)), endian),
528 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(val.toFloat(f16, zcu)), endian),
529 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(val.toFloat(f32, zcu)), endian),
530 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(val.toFloat(f64, zcu)), endian),
531 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(val.toFloat(f80, zcu)), endian),
532 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(val.toFloat(f128, zcu)), endian),
517533 else => unreachable,
518534 },
519535 .Vector => {
520 const elem_ty = ty.childType(mod);
521 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(pt));
522 const len: usize = @intCast(ty.arrayLen(mod));
536 const elem_ty = ty.childType(zcu);
537 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(zcu));
538 const len: usize = @intCast(ty.arrayLen(zcu));
523539
524540 var bits: u16 = 0;
525541 var elem_i: usize = 0;
......@@ -544,37 +560,37 @@ pub fn writeToPackedMemory(
544560 .repeated_elem => |elem| elem,
545561 });
546562 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
547 const field_bits: u16 = @intCast(field_ty.bitSize(pt));
563 const field_bits: u16 = @intCast(field_ty.bitSize(zcu));
548564 try field_val.writeToPackedMemory(field_ty, pt, buffer, bit_offset + bits);
549565 bits += field_bits;
550566 }
551567 },
552568 .Union => {
553 const union_obj = mod.typeToUnion(ty).?;
569 const union_obj = zcu.typeToUnion(ty).?;
554570 switch (union_obj.flagsUnordered(ip).layout) {
555571 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory
556572 .@"packed" => {
557 if (val.unionTag(mod)) |union_tag| {
558 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;
573 if (val.unionTag(zcu)) |union_tag| {
574 const field_index = zcu.unionTagFieldIndex(union_obj, union_tag).?;
559575 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
560576 const field_val = try val.fieldValue(pt, field_index);
561577 return field_val.writeToPackedMemory(field_type, pt, buffer, bit_offset);
562578 } else {
563579 const backing_ty = try ty.unionBackingType(pt);
564 return val.unionValue(mod).writeToPackedMemory(backing_ty, pt, buffer, bit_offset);
580 return val.unionValue(zcu).writeToPackedMemory(backing_ty, pt, buffer, bit_offset);
565581 }
566582 },
567583 }
568584 },
569585 .Pointer => {
570 assert(!ty.isSlice(mod)); // No well defined layout.
571 if (!val.ptrHasIntAddr(mod)) return error.ReinterpretDeclRef;
586 assert(!ty.isSlice(zcu)); // No well defined layout.
587 if (!val.ptrHasIntAddr(zcu)) return error.ReinterpretDeclRef;
572588 return val.writeToPackedMemory(Type.usize, pt, buffer, bit_offset);
573589 },
574590 .Optional => {
575 assert(ty.isPtrLikeOptional(mod));
576 const child = ty.optionalChild(mod);
577 const opt_val = val.optionalValue(mod);
591 assert(ty.isPtrLikeOptional(zcu));
592 const child = ty.optionalChild(zcu);
593 const opt_val = val.optionalValue(zcu);
578594 if (opt_val) |some| {
579595 return some.writeToPackedMemory(child, pt, buffer, bit_offset);
580596 } else {
......@@ -599,11 +615,11 @@ pub fn readFromMemory(
599615 Unimplemented,
600616 OutOfMemory,
601617}!Value {
602 const mod = pt.zcu;
603 const ip = &mod.intern_pool;
604 const target = mod.getTarget();
618 const zcu = pt.zcu;
619 const ip = &zcu.intern_pool;
620 const target = zcu.getTarget();
605621 const endian = target.cpu.arch.endian();
606 switch (ty.zigTypeTag(mod)) {
622 switch (ty.zigTypeTag(zcu)) {
607623 .Void => return Value.void,
608624 .Bool => {
609625 if (buffer[0] == 0) {
......@@ -615,24 +631,24 @@ pub fn readFromMemory(
615631 .Int, .Enum => |ty_tag| {
616632 const int_ty = switch (ty_tag) {
617633 .Int => ty,
618 .Enum => ty.intTagType(mod),
634 .Enum => ty.intTagType(zcu),
619635 else => unreachable,
620636 };
621 const int_info = int_ty.intInfo(mod);
637 const int_info = int_ty.intInfo(zcu);
622638 const bits = int_info.bits;
623639 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
624 if (bits == 0 or buffer.len == 0) return mod.getCoerced(try mod.intValue(int_ty, 0), ty);
640 if (bits == 0 or buffer.len == 0) return zcu.getCoerced(try zcu.intValue(int_ty, 0), ty);
625641
626642 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64
627643 .signed => {
628644 const val = std.mem.readVarInt(i64, buffer[0..byte_count], endian);
629645 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
630 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
646 return zcu.getCoerced(try zcu.intValue(int_ty, result), ty);
631647 },
632648 .unsigned => {
633649 const val = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
634650 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
635 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
651 return zcu.getCoerced(try zcu.intValue(int_ty, result), ty);
636652 },
637653 } else { // Slow path, we have to construct a big-int
638654 const Limb = std.math.big.Limb;
......@@ -641,7 +657,7 @@ pub fn readFromMemory(
641657
642658 var bigint = BigIntMutable.init(limbs_buffer, 0);
643659 bigint.readTwosComplement(buffer[0..byte_count], bits, endian, int_info.signedness);
644 return mod.getCoerced(try mod.intValue_big(int_ty, bigint.toConst()), ty);
660 return zcu.getCoerced(try zcu.intValue_big(int_ty, bigint.toConst()), ty);
645661 }
646662 },
647663 .Float => return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -656,12 +672,12 @@ pub fn readFromMemory(
656672 },
657673 } })),
658674 .Array => {
659 const elem_ty = ty.childType(mod);
660 const elem_size = elem_ty.abiSize(pt);
661 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod)));
675 const elem_ty = ty.childType(zcu);
676 const elem_size = elem_ty.abiSize(zcu);
677 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(zcu)));
662678 var offset: usize = 0;
663679 for (elems) |*elem| {
664 elem.* = (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).toIntern();
680 elem.* = (try readFromMemory(elem_ty, zcu, buffer[offset..], arena)).toIntern();
665681 offset += @intCast(elem_size);
666682 }
667683 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
......@@ -672,11 +688,11 @@ pub fn readFromMemory(
672688 .Vector => {
673689 // We use byte_count instead of abi_size here, so that any padding bytes
674690 // follow the data bytes, on both big- and little-endian systems.
675 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
676 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
691 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
692 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
677693 },
678694 .Struct => {
679 const struct_type = mod.typeToStruct(ty).?;
695 const struct_type = zcu.typeToStruct(ty).?;
680696 switch (struct_type.layout) {
681697 .auto => unreachable, // Sema is supposed to have emitted a compile error already
682698 .@"extern" => {
......@@ -684,9 +700,9 @@ pub fn readFromMemory(
684700 const field_vals = try arena.alloc(InternPool.Index, field_types.len);
685701 for (field_vals, 0..) |*field_val, i| {
686702 const field_ty = Type.fromInterned(field_types.get(ip)[i]);
687 const off: usize = @intCast(ty.structFieldOffset(i, mod));
688 const sz: usize = @intCast(field_ty.abiSize(pt));
689 field_val.* = (try readFromMemory(field_ty, mod, buffer[off..(off + sz)], arena)).toIntern();
703 const off: usize = @intCast(ty.structFieldOffset(i, zcu));
704 const sz: usize = @intCast(field_ty.abiSize(zcu));
705 field_val.* = (try readFromMemory(field_ty, zcu, buffer[off..(off + sz)], arena)).toIntern();
690706 }
691707 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
692708 .ty = ty.toIntern(),
......@@ -694,29 +710,29 @@ pub fn readFromMemory(
694710 } }));
695711 },
696712 .@"packed" => {
697 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
698 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
713 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
714 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
699715 },
700716 }
701717 },
702718 .ErrorSet => {
703 const bits = mod.errorSetBits();
719 const bits = zcu.errorSetBits();
704720 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
705721 const int = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
706722 const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
707 const name = mod.global_error_set.keys()[@intCast(index)];
723 const name = zcu.global_error_set.keys()[@intCast(index)];
708724
709725 return Value.fromInterned(try pt.intern(.{ .err = .{
710726 .ty = ty.toIntern(),
711727 .name = name,
712728 } }));
713729 },
714 .Union => switch (ty.containerLayout(mod)) {
730 .Union => switch (ty.containerLayout(zcu)) {
715731 .auto => return error.IllDefinedMemoryLayout,
716732 .@"extern" => {
717 const union_size = ty.abiSize(pt);
718 const array_ty = try mod.arrayType(.{ .len = union_size, .child = .u8_type });
719 const val = (try readFromMemory(array_ty, mod, buffer, arena)).toIntern();
733 const union_size = ty.abiSize(zcu);
734 const array_ty = try zcu.arrayType(.{ .len = union_size, .child = .u8_type });
735 const val = (try readFromMemory(array_ty, zcu, buffer, arena)).toIntern();
720736 return Value.fromInterned(try pt.intern(.{ .un = .{
721737 .ty = ty.toIntern(),
722738 .tag = .none,
......@@ -724,23 +740,23 @@ pub fn readFromMemory(
724740 } }));
725741 },
726742 .@"packed" => {
727 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
728 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
743 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
744 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
729745 },
730746 },
731747 .Pointer => {
732 assert(!ty.isSlice(mod)); // No well defined layout.
733 const int_val = try readFromMemory(Type.usize, mod, buffer, arena);
748 assert(!ty.isSlice(zcu)); // No well defined layout.
749 const int_val = try readFromMemory(Type.usize, zcu, buffer, arena);
734750 return Value.fromInterned(try pt.intern(.{ .ptr = .{
735751 .ty = ty.toIntern(),
736752 .base_addr = .int,
737 .byte_offset = int_val.toUnsignedInt(pt),
753 .byte_offset = int_val.toUnsignedInt(zcu),
738754 } }));
739755 },
740756 .Optional => {
741 assert(ty.isPtrLikeOptional(mod));
742 const child_ty = ty.optionalChild(mod);
743 const child_val = try readFromMemory(child_ty, mod, buffer, arena);
757 assert(ty.isPtrLikeOptional(zcu));
758 const child_ty = ty.optionalChild(zcu);
759 const child_val = try readFromMemory(child_ty, zcu, buffer, arena);
744760 return Value.fromInterned(try pt.intern(.{ .opt = .{
745761 .ty = ty.toIntern(),
746762 .val = switch (child_val.orderAgainstZero(pt)) {
......@@ -768,11 +784,11 @@ pub fn readFromPackedMemory(
768784 IllDefinedMemoryLayout,
769785 OutOfMemory,
770786}!Value {
771 const mod = pt.zcu;
772 const ip = &mod.intern_pool;
773 const target = mod.getTarget();
787 const zcu = pt.zcu;
788 const ip = &zcu.intern_pool;
789 const target = zcu.getTarget();
774790 const endian = target.cpu.arch.endian();
775 switch (ty.zigTypeTag(mod)) {
791 switch (ty.zigTypeTag(zcu)) {
776792 .Void => return Value.void,
777793 .Bool => {
778794 const byte = switch (endian) {
......@@ -787,7 +803,7 @@ pub fn readFromPackedMemory(
787803 },
788804 .Int => {
789805 if (buffer.len == 0) return pt.intValue(ty, 0);
790 const int_info = ty.intInfo(mod);
806 const int_info = ty.intInfo(zcu);
791807 const bits = int_info.bits;
792808 if (bits == 0) return pt.intValue(ty, 0);
793809
......@@ -800,7 +816,7 @@ pub fn readFromPackedMemory(
800816 };
801817
802818 // Slow path, we have to construct a big-int
803 const abi_size: usize = @intCast(ty.abiSize(pt));
819 const abi_size: usize = @intCast(ty.abiSize(zcu));
804820 const Limb = std.math.big.Limb;
805821 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
806822 const limbs_buffer = try arena.alloc(Limb, limb_count);
......@@ -810,7 +826,7 @@ pub fn readFromPackedMemory(
810826 return pt.intValue_big(ty, bigint.toConst());
811827 },
812828 .Enum => {
813 const int_ty = ty.intTagType(mod);
829 const int_ty = ty.intTagType(zcu);
814830 const int_val = try Value.readFromPackedMemory(int_ty, pt, buffer, bit_offset, arena);
815831 return pt.getCoerced(int_val, ty);
816832 },
......@@ -826,11 +842,11 @@ pub fn readFromPackedMemory(
826842 },
827843 } })),
828844 .Vector => {
829 const elem_ty = ty.childType(mod);
830 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod)));
845 const elem_ty = ty.childType(zcu);
846 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(zcu)));
831847
832848 var bits: u16 = 0;
833 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(pt));
849 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(zcu));
834850 for (elems, 0..) |_, i| {
835851 // On big-endian systems, LLVM reverses the element order of vectors by default
836852 const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i;
......@@ -845,12 +861,12 @@ pub fn readFromPackedMemory(
845861 .Struct => {
846862 // Sema is supposed to have emitted a compile error already for Auto layout structs,
847863 // and Extern is handled by non-packed readFromMemory.
848 const struct_type = mod.typeToPackedStruct(ty).?;
864 const struct_type = zcu.typeToPackedStruct(ty).?;
849865 var bits: u16 = 0;
850866 const field_vals = try arena.alloc(InternPool.Index, struct_type.field_types.len);
851867 for (field_vals, 0..) |*field_val, i| {
852868 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
853 const field_bits: u16 = @intCast(field_ty.bitSize(pt));
869 const field_bits: u16 = @intCast(field_ty.bitSize(zcu));
854870 field_val.* = (try readFromPackedMemory(field_ty, pt, buffer, bit_offset + bits, arena)).toIntern();
855871 bits += field_bits;
856872 }
......@@ -859,7 +875,7 @@ pub fn readFromPackedMemory(
859875 .storage = .{ .elems = field_vals },
860876 } }));
861877 },
862 .Union => switch (ty.containerLayout(mod)) {
878 .Union => switch (ty.containerLayout(zcu)) {
863879 .auto, .@"extern" => unreachable, // Handled by non-packed readFromMemory
864880 .@"packed" => {
865881 const backing_ty = try ty.unionBackingType(pt);
......@@ -872,21 +888,21 @@ pub fn readFromPackedMemory(
872888 },
873889 },
874890 .Pointer => {
875 assert(!ty.isSlice(mod)); // No well defined layout.
891 assert(!ty.isSlice(zcu)); // No well defined layout.
876892 const int_val = try readFromPackedMemory(Type.usize, pt, buffer, bit_offset, arena);
877893 return Value.fromInterned(try pt.intern(.{ .ptr = .{
878894 .ty = ty.toIntern(),
879895 .base_addr = .int,
880 .byte_offset = int_val.toUnsignedInt(pt),
896 .byte_offset = int_val.toUnsignedInt(zcu),
881897 } }));
882898 },
883899 .Optional => {
884 assert(ty.isPtrLikeOptional(mod));
885 const child_ty = ty.optionalChild(mod);
900 assert(ty.isPtrLikeOptional(zcu));
901 const child_ty = ty.optionalChild(zcu);
886902 const child_val = try readFromPackedMemory(child_ty, pt, buffer, bit_offset, arena);
887903 return Value.fromInterned(try pt.intern(.{ .opt = .{
888904 .ty = ty.toIntern(),
889 .val = switch (child_val.orderAgainstZero(pt)) {
905 .val = switch (child_val.orderAgainstZero(zcu)) {
890906 .lt => unreachable,
891907 .eq => .none,
892908 .gt => child_val.toIntern(),
......@@ -898,8 +914,8 @@ pub fn readFromPackedMemory(
898914}
899915
900916/// Asserts that the value is a float or an integer.
901pub fn toFloat(val: Value, comptime T: type, pt: Zcu.PerThread) T {
902 return switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
917pub fn toFloat(val: Value, comptime T: type, zcu: *Zcu) T {
918 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
903919 .int => |int| switch (int.storage) {
904920 .big_int => |big_int| @floatCast(bigIntToFloat(big_int.limbs, big_int.positive)),
905921 inline .u64, .i64 => |x| {
......@@ -908,8 +924,8 @@ pub fn toFloat(val: Value, comptime T: type, pt: Zcu.PerThread) T {
908924 }
909925 return @floatFromInt(x);
910926 },
911 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0),
912 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(pt)),
927 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0),
928 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(zcu)),
913929 },
914930 .float => |float| switch (float.storage) {
915931 inline else => |x| @floatCast(x),
......@@ -937,30 +953,30 @@ fn bigIntToFloat(limbs: []const std.math.big.Limb, positive: bool) f128 {
937953 }
938954}
939955
940pub fn clz(val: Value, ty: Type, pt: Zcu.PerThread) u64 {
956pub fn clz(val: Value, ty: Type, zcu: *Zcu) u64 {
941957 var bigint_buf: BigIntSpace = undefined;
942 const bigint = val.toBigInt(&bigint_buf, pt);
943 return bigint.clz(ty.intInfo(pt.zcu).bits);
958 const bigint = val.toBigInt(&bigint_buf, zcu);
959 return bigint.clz(ty.intInfo(zcu).bits);
944960}
945961
946pub fn ctz(val: Value, ty: Type, pt: Zcu.PerThread) u64 {
962pub fn ctz(val: Value, ty: Type, zcu: *Zcu) u64 {
947963 var bigint_buf: BigIntSpace = undefined;
948 const bigint = val.toBigInt(&bigint_buf, pt);
949 return bigint.ctz(ty.intInfo(pt.zcu).bits);
964 const bigint = val.toBigInt(&bigint_buf, zcu);
965 return bigint.ctz(ty.intInfo(zcu).bits);
950966}
951967
952pub fn popCount(val: Value, ty: Type, pt: Zcu.PerThread) u64 {
968pub fn popCount(val: Value, ty: Type, zcu: *Zcu) u64 {
953969 var bigint_buf: BigIntSpace = undefined;
954 const bigint = val.toBigInt(&bigint_buf, pt);
955 return @intCast(bigint.popCount(ty.intInfo(pt.zcu).bits));
970 const bigint = val.toBigInt(&bigint_buf, zcu);
971 return @intCast(bigint.popCount(ty.intInfo(zcu).bits));
956972}
957973
958974pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {
959 const mod = pt.zcu;
960 const info = ty.intInfo(mod);
975 const zcu = pt.zcu;
976 const info = ty.intInfo(zcu);
961977
962978 var buffer: Value.BigIntSpace = undefined;
963 const operand_bigint = val.toBigInt(&buffer, pt);
979 const operand_bigint = val.toBigInt(&buffer, zcu);
964980
965981 const limbs = try arena.alloc(
966982 std.math.big.Limb,
......@@ -973,14 +989,14 @@ pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Va
973989}
974990
975991pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {
976 const mod = pt.zcu;
977 const info = ty.intInfo(mod);
992 const zcu = pt.zcu;
993 const info = ty.intInfo(zcu);
978994
979995 // Bit count must be evenly divisible by 8
980996 assert(info.bits % 8 == 0);
981997
982998 var buffer: Value.BigIntSpace = undefined;
983 const operand_bigint = val.toBigInt(&buffer, pt);
999 const operand_bigint = val.toBigInt(&buffer, zcu);
9841000
9851001 const limbs = try arena.alloc(
9861002 std.math.big.Limb,
......@@ -994,33 +1010,34 @@ pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Valu
9941010
9951011/// Asserts the value is an integer and not undefined.
9961012/// Returns the number of bits the value requires to represent stored in twos complement form.
997pub fn intBitCountTwosComp(self: Value, pt: Zcu.PerThread) usize {
1013pub fn intBitCountTwosComp(self: Value, zcu: *Zcu) usize {
9981014 var buffer: BigIntSpace = undefined;
999 const big_int = self.toBigInt(&buffer, pt);
1015 const big_int = self.toBigInt(&buffer, zcu);
10001016 return big_int.bitCountTwosComp();
10011017}
10021018
10031019/// Converts an integer or a float to a float. May result in a loss of information.
10041020/// Caller can find out by equality checking the result against the operand.
10051021pub fn floatCast(val: Value, dest_ty: Type, pt: Zcu.PerThread) !Value {
1006 const target = pt.zcu.getTarget();
1007 if (val.isUndef(pt.zcu)) return pt.undefValue(dest_ty);
1022 const zcu = pt.zcu;
1023 const target = zcu.getTarget();
1024 if (val.isUndef(zcu)) return pt.undefValue(dest_ty);
10081025 return Value.fromInterned(try pt.intern(.{ .float = .{
10091026 .ty = dest_ty.toIntern(),
10101027 .storage = switch (dest_ty.floatBits(target)) {
1011 16 => .{ .f16 = val.toFloat(f16, pt) },
1012 32 => .{ .f32 = val.toFloat(f32, pt) },
1013 64 => .{ .f64 = val.toFloat(f64, pt) },
1014 80 => .{ .f80 = val.toFloat(f80, pt) },
1015 128 => .{ .f128 = val.toFloat(f128, pt) },
1028 16 => .{ .f16 = val.toFloat(f16, zcu) },
1029 32 => .{ .f32 = val.toFloat(f32, zcu) },
1030 64 => .{ .f64 = val.toFloat(f64, zcu) },
1031 80 => .{ .f80 = val.toFloat(f80, zcu) },
1032 128 => .{ .f128 = val.toFloat(f128, zcu) },
10161033 else => unreachable,
10171034 },
10181035 } }));
10191036}
10201037
10211038/// Asserts the value is a float
1022pub fn floatHasFraction(self: Value, mod: *const Module) bool {
1023 return switch (mod.intern_pool.indexToKey(self.toIntern())) {
1039pub fn floatHasFraction(self: Value, zcu: *const Module) bool {
1040 return switch (zcu.intern_pool.indexToKey(self.toIntern())) {
10241041 .float => |float| switch (float.storage) {
10251042 inline else => |x| @rem(x, 1) != 0,
10261043 },
......@@ -1028,19 +1045,24 @@ pub fn floatHasFraction(self: Value, mod: *const Module) bool {
10281045 };
10291046}
10301047
1031pub fn orderAgainstZero(lhs: Value, pt: Zcu.PerThread) std.math.Order {
1032 return orderAgainstZeroAdvanced(lhs, pt, .normal) catch unreachable;
1048pub fn orderAgainstZero(lhs: Value, zcu: *Zcu) std.math.Order {
1049 return orderAgainstZeroInner(lhs, .normal, zcu, {}) catch unreachable;
10331050}
10341051
1035pub fn orderAgainstZeroAdvanced(
1052pub fn orderAgainstZeroSema(lhs: Value, pt: Zcu.PerThread) !std.math.Order {
1053 return try orderAgainstZeroInner(lhs, .sema, pt.zcu, pt.tid);
1054}
1055
1056pub fn orderAgainstZeroInner(
10361057 lhs: Value,
1037 pt: Zcu.PerThread,
10381058 comptime strat: ResolveStrat,
1059 zcu: *Zcu,
1060 tid: strat.Tid(),
10391061) Module.CompileError!std.math.Order {
10401062 return switch (lhs.toIntern()) {
10411063 .bool_false => .eq,
10421064 .bool_true => .gt,
1043 else => switch (pt.zcu.intern_pool.indexToKey(lhs.toIntern())) {
1065 else => switch (zcu.intern_pool.indexToKey(lhs.toIntern())) {
10441066 .ptr => |ptr| if (ptr.byte_offset > 0) .gt else switch (ptr.base_addr) {
10451067 .nav, .comptime_alloc, .comptime_field => .gt,
10461068 .int => .eq,
......@@ -1050,16 +1072,17 @@ pub fn orderAgainstZeroAdvanced(
10501072 .big_int => |big_int| big_int.orderAgainstScalar(0),
10511073 inline .u64, .i64 => |x| std.math.order(x, 0),
10521074 .lazy_align => .gt, // alignment is never 0
1053 .lazy_size => |ty| return if (Type.fromInterned(ty).hasRuntimeBitsAdvanced(
1054 pt,
1075 .lazy_size => |ty| return if (Type.fromInterned(ty).hasRuntimeBitsInner(
10551076 false,
10561077 strat.toLazy(),
1078 zcu,
1079 tid,
10571080 ) catch |err| switch (err) {
10581081 error.NeedLazy => unreachable,
10591082 else => |e| return e,
10601083 }) .gt else .eq,
10611084 },
1062 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).orderAgainstZeroAdvanced(pt, strat),
1085 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).orderAgainstZeroInner(strat, zcu, tid),
10631086 .float => |float| switch (float.storage) {
10641087 inline else => |x| std.math.order(x, 0),
10651088 },
......@@ -1069,14 +1092,20 @@ pub fn orderAgainstZeroAdvanced(
10691092}
10701093
10711094/// Asserts the value is comparable.
1072pub fn order(lhs: Value, rhs: Value, pt: Zcu.PerThread) std.math.Order {
1073 return orderAdvanced(lhs, rhs, pt, .normal) catch unreachable;
1095pub fn order(lhs: Value, rhs: Value, zcu: *Zcu) std.math.Order {
1096 return orderAdvanced(lhs, rhs, .normal, zcu, {}) catch unreachable;
10741097}
10751098
10761099/// Asserts the value is comparable.
1077pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !std.math.Order {
1078 const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(pt, strat);
1079 const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(pt, strat);
1100pub fn orderAdvanced(
1101 lhs: Value,
1102 rhs: Value,
1103 comptime strat: ResolveStrat,
1104 zcu: *Zcu,
1105 tid: strat.Tid(),
1106) !std.math.Order {
1107 const lhs_against_zero = try lhs.orderAgainstZeroInner(strat, zcu, tid);
1108 const rhs_against_zero = try rhs.orderAgainstZeroInner(strat, zcu, tid);
10801109 switch (lhs_against_zero) {
10811110 .lt => if (rhs_against_zero != .lt) return .lt,
10821111 .eq => return rhs_against_zero.invert(),
......@@ -1088,34 +1117,39 @@ pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat:
10881117 .gt => {},
10891118 }
10901119
1091 if (lhs.isFloat(pt.zcu) or rhs.isFloat(pt.zcu)) {
1092 const lhs_f128 = lhs.toFloat(f128, pt);
1093 const rhs_f128 = rhs.toFloat(f128, pt);
1120 if (lhs.isFloat(zcu) or rhs.isFloat(zcu)) {
1121 const lhs_f128 = lhs.toFloat(f128, zcu);
1122 const rhs_f128 = rhs.toFloat(f128, zcu);
10941123 return std.math.order(lhs_f128, rhs_f128);
10951124 }
10961125
10971126 var lhs_bigint_space: BigIntSpace = undefined;
10981127 var rhs_bigint_space: BigIntSpace = undefined;
1099 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_bigint_space, pt, strat);
1100 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_bigint_space, pt, strat);
1128 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_bigint_space, strat, zcu, tid);
1129 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_bigint_space, strat, zcu, tid);
11011130 return lhs_bigint.order(rhs_bigint);
11021131}
11031132
11041133/// Asserts the value is comparable. Does not take a type parameter because it supports
11051134/// comparisons between heterogeneous types.
1106pub fn compareHetero(lhs: Value, op: std.math.CompareOperator, rhs: Value, pt: Zcu.PerThread) bool {
1107 return compareHeteroAdvanced(lhs, op, rhs, pt, .normal) catch unreachable;
1135pub fn compareHetero(lhs: Value, op: std.math.CompareOperator, rhs: Value, zcu: *Zcu) bool {
1136 return compareHeteroAdvanced(lhs, op, rhs, .normal, zcu, {}) catch unreachable;
1137}
1138
1139pub fn compareHeteroSema(lhs: Value, op: std.math.CompareOperator, rhs: Value, pt: Zcu.PerThread) !bool {
1140 return try compareHeteroAdvanced(lhs, op, rhs, .sema, pt.zcu, pt.tid);
11081141}
11091142
11101143pub fn compareHeteroAdvanced(
11111144 lhs: Value,
11121145 op: std.math.CompareOperator,
11131146 rhs: Value,
1114 pt: Zcu.PerThread,
11151147 comptime strat: ResolveStrat,
1148 zcu: *Zcu,
1149 tid: strat.Tid(),
11161150) !bool {
1117 if (lhs.pointerNav(pt.zcu)) |lhs_nav| {
1118 if (rhs.pointerNav(pt.zcu)) |rhs_nav| {
1151 if (lhs.pointerNav(zcu)) |lhs_nav| {
1152 if (rhs.pointerNav(zcu)) |rhs_nav| {
11191153 switch (op) {
11201154 .eq => return lhs_nav == rhs_nav,
11211155 .neq => return lhs_nav != rhs_nav,
......@@ -1128,32 +1162,32 @@ pub fn compareHeteroAdvanced(
11281162 else => {},
11291163 }
11301164 }
1131 } else if (rhs.pointerNav(pt.zcu)) |_| {
1165 } else if (rhs.pointerNav(zcu)) |_| {
11321166 switch (op) {
11331167 .eq => return false,
11341168 .neq => return true,
11351169 else => {},
11361170 }
11371171 }
1138 return (try orderAdvanced(lhs, rhs, pt, strat)).compare(op);
1172 return (try orderAdvanced(lhs, rhs, strat, zcu, tid)).compare(op);
11391173}
11401174
11411175/// Asserts the values are comparable. Both operands have type `ty`.
11421176/// For vectors, returns true if comparison is true for ALL elements.
11431177pub fn compareAll(lhs: Value, op: std.math.CompareOperator, rhs: Value, ty: Type, pt: Zcu.PerThread) !bool {
1144 const mod = pt.zcu;
1145 if (ty.zigTypeTag(mod) == .Vector) {
1146 const scalar_ty = ty.scalarType(mod);
1147 for (0..ty.vectorLen(mod)) |i| {
1178 const zcu = pt.zcu;
1179 if (ty.zigTypeTag(zcu) == .Vector) {
1180 const scalar_ty = ty.scalarType(zcu);
1181 for (0..ty.vectorLen(zcu)) |i| {
11481182 const lhs_elem = try lhs.elemValue(pt, i);
11491183 const rhs_elem = try rhs.elemValue(pt, i);
1150 if (!compareScalar(lhs_elem, op, rhs_elem, scalar_ty, pt)) {
1184 if (!compareScalar(lhs_elem, op, rhs_elem, scalar_ty, zcu)) {
11511185 return false;
11521186 }
11531187 }
11541188 return true;
11551189 }
1156 return compareScalar(lhs, op, rhs, ty, pt);
1190 return compareScalar(lhs, op, rhs, ty, zcu);
11571191}
11581192
11591193/// Asserts the values are comparable. Both operands have type `ty`.
......@@ -1162,12 +1196,12 @@ pub fn compareScalar(
11621196 op: std.math.CompareOperator,
11631197 rhs: Value,
11641198 ty: Type,
1165 pt: Zcu.PerThread,
1199 zcu: *Zcu,
11661200) bool {
11671201 return switch (op) {
1168 .eq => lhs.eql(rhs, ty, pt.zcu),
1169 .neq => !lhs.eql(rhs, ty, pt.zcu),
1170 else => compareHetero(lhs, op, rhs, pt),
1202 .eq => lhs.eql(rhs, ty, zcu),
1203 .neq => !lhs.eql(rhs, ty, zcu),
1204 else => compareHetero(lhs, op, rhs, zcu),
11711205 };
11721206}
11731207
......@@ -1176,8 +1210,8 @@ pub fn compareScalar(
11761210/// Returns `false` if the value or any vector element is undefined.
11771211///
11781212/// Note that `!compareAllWithZero(.eq, ...) != compareAllWithZero(.neq, ...)`
1179pub fn compareAllWithZero(lhs: Value, op: std.math.CompareOperator, pt: Zcu.PerThread) bool {
1180 return compareAllWithZeroAdvancedExtra(lhs, op, pt, .normal) catch unreachable;
1213pub fn compareAllWithZero(lhs: Value, op: std.math.CompareOperator, zcu: *Zcu) bool {
1214 return compareAllWithZeroAdvancedExtra(lhs, op, .normal, zcu, {}) catch unreachable;
11811215}
11821216
11831217pub fn compareAllWithZeroSema(
......@@ -1185,47 +1219,47 @@ pub fn compareAllWithZeroSema(
11851219 op: std.math.CompareOperator,
11861220 pt: Zcu.PerThread,
11871221) Module.CompileError!bool {
1188 return compareAllWithZeroAdvancedExtra(lhs, op, pt, .sema);
1222 return compareAllWithZeroAdvancedExtra(lhs, op, .sema, pt.zcu, pt.tid);
11891223}
11901224
11911225pub fn compareAllWithZeroAdvancedExtra(
11921226 lhs: Value,
11931227 op: std.math.CompareOperator,
1194 pt: Zcu.PerThread,
11951228 comptime strat: ResolveStrat,
1229 zcu: *Zcu,
1230 tid: strat.Tid(),
11961231) Module.CompileError!bool {
1197 const mod = pt.zcu;
1198 if (lhs.isInf(mod)) {
1232 if (lhs.isInf(zcu)) {
11991233 switch (op) {
12001234 .neq => return true,
12011235 .eq => return false,
1202 .gt, .gte => return !lhs.isNegativeInf(mod),
1203 .lt, .lte => return lhs.isNegativeInf(mod),
1236 .gt, .gte => return !lhs.isNegativeInf(zcu),
1237 .lt, .lte => return lhs.isNegativeInf(zcu),
12041238 }
12051239 }
12061240
1207 switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
1241 switch (zcu.intern_pool.indexToKey(lhs.toIntern())) {
12081242 .float => |float| switch (float.storage) {
12091243 inline else => |x| if (std.math.isNan(x)) return op == .neq,
12101244 },
12111245 .aggregate => |aggregate| return switch (aggregate.storage) {
1212 .bytes => |bytes| for (bytes.toSlice(lhs.typeOf(mod).arrayLenIncludingSentinel(mod), &mod.intern_pool)) |byte| {
1246 .bytes => |bytes| for (bytes.toSlice(lhs.typeOf(zcu).arrayLenIncludingSentinel(zcu), &zcu.intern_pool)) |byte| {
12131247 if (!std.math.order(byte, 0).compare(op)) break false;
12141248 } else true,
12151249 .elems => |elems| for (elems) |elem| {
1216 if (!try Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, pt, strat)) break false;
1250 if (!try Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, strat, zcu, tid)) break false;
12171251 } else true,
1218 .repeated_elem => |elem| Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, pt, strat),
1252 .repeated_elem => |elem| Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, strat, zcu, tid),
12191253 },
12201254 .undef => return false,
12211255 else => {},
12221256 }
1223 return (try orderAgainstZeroAdvanced(lhs, pt, strat)).compare(op);
1257 return (try orderAgainstZeroInner(lhs, strat, zcu, tid)).compare(op);
12241258}
12251259
1226pub fn eql(a: Value, b: Value, ty: Type, mod: *Module) bool {
1227 assert(mod.intern_pool.typeOf(a.toIntern()) == ty.toIntern());
1228 assert(mod.intern_pool.typeOf(b.toIntern()) == ty.toIntern());
1260pub fn eql(a: Value, b: Value, ty: Type, zcu: *Module) bool {
1261 assert(zcu.intern_pool.typeOf(a.toIntern()) == ty.toIntern());
1262 assert(zcu.intern_pool.typeOf(b.toIntern()) == ty.toIntern());
12291263 return a.toIntern() == b.toIntern();
12301264}
12311265
......@@ -1260,8 +1294,8 @@ pub fn canMutateComptimeVarState(val: Value, zcu: *Zcu) bool {
12601294/// Gets the `Nav` referenced by this pointer. If the pointer does not point
12611295/// to a `Nav`, or if it points to some part of one (like a field or element),
12621296/// returns null.
1263pub fn pointerNav(val: Value, mod: *Module) ?InternPool.Nav.Index {
1264 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1297pub fn pointerNav(val: Value, zcu: *Zcu) ?InternPool.Nav.Index {
1298 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
12651299 // TODO: these 3 cases are weird; these aren't pointer values!
12661300 .variable => |v| v.owner_nav,
12671301 .@"extern" => |e| e.owner_nav,
......@@ -1277,8 +1311,8 @@ pub fn pointerNav(val: Value, mod: *Module) ?InternPool.Nav.Index {
12771311pub const slice_ptr_index = 0;
12781312pub const slice_len_index = 1;
12791313
1280pub fn slicePtr(val: Value, mod: *Module) Value {
1281 return Value.fromInterned(mod.intern_pool.slicePtr(val.toIntern()));
1314pub fn slicePtr(val: Value, zcu: *Module) Value {
1315 return Value.fromInterned(zcu.intern_pool.slicePtr(val.toIntern()));
12821316}
12831317
12841318/// Gets the `len` field of a slice value as a `u64`.
......@@ -1312,15 +1346,15 @@ pub fn elemValue(val: Value, pt: Zcu.PerThread, index: usize) Allocator.Error!Va
13121346 }
13131347}
13141348
1315pub fn isLazyAlign(val: Value, mod: *Module) bool {
1316 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1349pub fn isLazyAlign(val: Value, zcu: *Module) bool {
1350 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13171351 .int => |int| int.storage == .lazy_align,
13181352 else => false,
13191353 };
13201354}
13211355
1322pub fn isLazySize(val: Value, mod: *Module) bool {
1323 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1356pub fn isLazySize(val: Value, zcu: *Module) bool {
1357 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13241358 .int => |int| int.storage == .lazy_size,
13251359 else => false,
13261360 };
......@@ -1377,15 +1411,15 @@ pub fn sliceArray(
13771411}
13781412
13791413pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
1380 const mod = pt.zcu;
1381 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1414 const zcu = pt.zcu;
1415 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13821416 .undef => |ty| Value.fromInterned(try pt.intern(.{
1383 .undef = Type.fromInterned(ty).structFieldType(index, mod).toIntern(),
1417 .undef = Type.fromInterned(ty).structFieldType(index, zcu).toIntern(),
13841418 })),
13851419 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {
13861420 .bytes => |bytes| try pt.intern(.{ .int = .{
13871421 .ty = .u8_type,
1388 .storage = .{ .u64 = bytes.at(index, &mod.intern_pool) },
1422 .storage = .{ .u64 = bytes.at(index, &zcu.intern_pool) },
13891423 } }),
13901424 .elems => |elems| elems[index],
13911425 .repeated_elem => |elem| elem,
......@@ -1396,40 +1430,40 @@ pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
13961430 };
13971431}
13981432
1399pub fn unionTag(val: Value, mod: *Module) ?Value {
1400 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1433pub fn unionTag(val: Value, zcu: *Module) ?Value {
1434 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14011435 .undef, .enum_tag => val,
14021436 .un => |un| if (un.tag != .none) Value.fromInterned(un.tag) else return null,
14031437 else => unreachable,
14041438 };
14051439}
14061440
1407pub fn unionValue(val: Value, mod: *Module) Value {
1408 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1441pub fn unionValue(val: Value, zcu: *Module) Value {
1442 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14091443 .un => |un| Value.fromInterned(un.val),
14101444 else => unreachable,
14111445 };
14121446}
14131447
1414pub fn isUndef(val: Value, mod: *Module) bool {
1415 return mod.intern_pool.isUndef(val.toIntern());
1448pub fn isUndef(val: Value, zcu: *Module) bool {
1449 return zcu.intern_pool.isUndef(val.toIntern());
14161450}
14171451
14181452/// TODO: check for cases such as array that is not marked undef but all the element
14191453/// values are marked undef, or struct that is not marked undef but all fields are marked
14201454/// undef, etc.
1421pub fn isUndefDeep(val: Value, mod: *Module) bool {
1422 return val.isUndef(mod);
1455pub fn isUndefDeep(val: Value, zcu: *Module) bool {
1456 return val.isUndef(zcu);
14231457}
14241458
14251459/// Asserts the value is not undefined and not unreachable.
14261460/// C pointers with an integer value of 0 are also considered null.
1427pub fn isNull(val: Value, mod: *Module) bool {
1461pub fn isNull(val: Value, zcu: *Module) bool {
14281462 return switch (val.toIntern()) {
14291463 .undef => unreachable,
14301464 .unreachable_value => unreachable,
14311465 .null_value => true,
1432 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1466 else => return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14331467 .undef => unreachable,
14341468 .ptr => |ptr| switch (ptr.base_addr) {
14351469 .int => ptr.byte_offset == 0,
......@@ -1442,8 +1476,8 @@ pub fn isNull(val: Value, mod: *Module) bool {
14421476}
14431477
14441478/// Valid only for error (union) types. Asserts the value is not undefined and not unreachable.
1445pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTerminatedString {
1446 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1479pub fn getErrorName(val: Value, zcu: *const Module) InternPool.OptionalNullTerminatedString {
1480 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14471481 .err => |err| err.name.toOptional(),
14481482 .error_union => |error_union| switch (error_union.val) {
14491483 .err_name => |err_name| err_name.toOptional(),
......@@ -1462,13 +1496,13 @@ pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {
14621496
14631497/// Assumes the type is an error union. Returns true if and only if the value is
14641498/// the error union payload, not an error.
1465pub fn errorUnionIsPayload(val: Value, mod: *const Module) bool {
1466 return mod.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;
1499pub fn errorUnionIsPayload(val: Value, zcu: *const Module) bool {
1500 return zcu.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;
14671501}
14681502
14691503/// Value of the optional, null if optional has no payload.
1470pub fn optionalValue(val: Value, mod: *const Module) ?Value {
1471 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1504pub fn optionalValue(val: Value, zcu: *const Module) ?Value {
1505 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14721506 .opt => |opt| switch (opt.val) {
14731507 .none => null,
14741508 else => |payload| Value.fromInterned(payload),
......@@ -1479,10 +1513,10 @@ pub fn optionalValue(val: Value, mod: *const Module) ?Value {
14791513}
14801514
14811515/// Valid for all types. Asserts the value is not undefined.
1482pub fn isFloat(self: Value, mod: *const Module) bool {
1516pub fn isFloat(self: Value, zcu: *const Module) bool {
14831517 return switch (self.toIntern()) {
14841518 .undef => unreachable,
1485 else => switch (mod.intern_pool.indexToKey(self.toIntern())) {
1519 else => switch (zcu.intern_pool.indexToKey(self.toIntern())) {
14861520 .undef => unreachable,
14871521 .float => true,
14881522 else => false,
......@@ -1490,8 +1524,8 @@ pub fn isFloat(self: Value, mod: *const Module) bool {
14901524 };
14911525}
14921526
1493pub fn floatFromInt(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module) !Value {
1494 return floatFromIntAdvanced(val, arena, int_ty, float_ty, mod, .normal) catch |err| switch (err) {
1527pub fn floatFromInt(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, zcu: *Module) !Value {
1528 return floatFromIntAdvanced(val, arena, int_ty, float_ty, zcu, .normal) catch |err| switch (err) {
14951529 error.OutOfMemory => return error.OutOfMemory,
14961530 else => unreachable,
14971531 };
......@@ -1505,10 +1539,10 @@ pub fn floatFromIntAdvanced(
15051539 pt: Zcu.PerThread,
15061540 comptime strat: ResolveStrat,
15071541) !Value {
1508 const mod = pt.zcu;
1509 if (int_ty.zigTypeTag(mod) == .Vector) {
1510 const result_data = try arena.alloc(InternPool.Index, int_ty.vectorLen(mod));
1511 const scalar_ty = float_ty.scalarType(mod);
1542 const zcu = pt.zcu;
1543 if (int_ty.zigTypeTag(zcu) == .Vector) {
1544 const result_data = try arena.alloc(InternPool.Index, int_ty.vectorLen(zcu));
1545 const scalar_ty = float_ty.scalarType(zcu);
15121546 for (result_data, 0..) |*scalar, i| {
15131547 const elem_val = try val.elemValue(pt, i);
15141548 scalar.* = (try floatFromIntScalar(elem_val, scalar_ty, pt, strat)).toIntern();
......@@ -1522,8 +1556,8 @@ pub fn floatFromIntAdvanced(
15221556}
15231557
15241558pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Value {
1525 const mod = pt.zcu;
1526 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1559 const zcu = pt.zcu;
1560 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
15271561 .undef => try pt.undefValue(float_ty),
15281562 .int => |int| switch (int.storage) {
15291563 .big_int => |big_int| {
......@@ -1531,8 +1565,8 @@ pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptim
15311565 return pt.floatValue(float_ty, float);
15321566 },
15331567 inline .u64, .i64 => |x| floatFromIntInner(x, float_ty, pt),
1534 .lazy_align => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiAlignmentAdvanced(pt, strat.toLazy())).scalar.toByteUnits() orelse 0, float_ty, pt),
1535 .lazy_size => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiSizeAdvanced(pt, strat.toLazy())).scalar, float_ty, pt),
1568 .lazy_align => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiAlignmentInner(strat.toLazy(), pt.zcu, pt.tid)).scalar.toByteUnits() orelse 0, float_ty, pt),
1569 .lazy_size => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiSizeInner(strat.toLazy(), pt.zcu, pt.tid)).scalar, float_ty, pt),
15361570 },
15371571 else => unreachable,
15381572 };
......@@ -1600,15 +1634,16 @@ pub fn intAddSatScalar(
16001634 arena: Allocator,
16011635 pt: Zcu.PerThread,
16021636) !Value {
1603 assert(!lhs.isUndef(pt.zcu));
1604 assert(!rhs.isUndef(pt.zcu));
1637 const zcu = pt.zcu;
1638 assert(!lhs.isUndef(zcu));
1639 assert(!rhs.isUndef(zcu));
16051640
1606 const info = ty.intInfo(pt.zcu);
1641 const info = ty.intInfo(zcu);
16071642
16081643 var lhs_space: Value.BigIntSpace = undefined;
16091644 var rhs_space: Value.BigIntSpace = undefined;
1610 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1611 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1645 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1646 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
16121647 const limbs = try arena.alloc(
16131648 std.math.big.Limb,
16141649 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -1650,15 +1685,17 @@ pub fn intSubSatScalar(
16501685 arena: Allocator,
16511686 pt: Zcu.PerThread,
16521687) !Value {
1653 assert(!lhs.isUndef(pt.zcu));
1654 assert(!rhs.isUndef(pt.zcu));
1688 const zcu = pt.zcu;
16551689
1656 const info = ty.intInfo(pt.zcu);
1690 assert(!lhs.isUndef(zcu));
1691 assert(!rhs.isUndef(zcu));
1692
1693 const info = ty.intInfo(zcu);
16571694
16581695 var lhs_space: Value.BigIntSpace = undefined;
16591696 var rhs_space: Value.BigIntSpace = undefined;
1660 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1661 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1697 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1698 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
16621699 const limbs = try arena.alloc(
16631700 std.math.big.Limb,
16641701 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -1675,12 +1712,12 @@ pub fn intMulWithOverflow(
16751712 arena: Allocator,
16761713 pt: Zcu.PerThread,
16771714) !OverflowArithmeticResult {
1678 const mod = pt.zcu;
1679 if (ty.zigTypeTag(mod) == .Vector) {
1680 const vec_len = ty.vectorLen(mod);
1715 const zcu = pt.zcu;
1716 if (ty.zigTypeTag(zcu) == .Vector) {
1717 const vec_len = ty.vectorLen(zcu);
16811718 const overflowed_data = try arena.alloc(InternPool.Index, vec_len);
16821719 const result_data = try arena.alloc(InternPool.Index, vec_len);
1683 const scalar_ty = ty.scalarType(mod);
1720 const scalar_ty = ty.scalarType(zcu);
16841721 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
16851722 const lhs_elem = try lhs.elemValue(pt, i);
16861723 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -1709,10 +1746,10 @@ pub fn intMulWithOverflowScalar(
17091746 arena: Allocator,
17101747 pt: Zcu.PerThread,
17111748) !OverflowArithmeticResult {
1712 const mod = pt.zcu;
1713 const info = ty.intInfo(mod);
1749 const zcu = pt.zcu;
1750 const info = ty.intInfo(zcu);
17141751
1715 if (lhs.isUndef(mod) or rhs.isUndef(mod)) {
1752 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) {
17161753 return .{
17171754 .overflow_bit = try pt.undefValue(Type.u1),
17181755 .wrapped_result = try pt.undefValue(ty),
......@@ -1721,8 +1758,8 @@ pub fn intMulWithOverflowScalar(
17211758
17221759 var lhs_space: Value.BigIntSpace = undefined;
17231760 var rhs_space: Value.BigIntSpace = undefined;
1724 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1725 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1761 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1762 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
17261763 const limbs = try arena.alloc(
17271764 std.math.big.Limb,
17281765 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
......@@ -1753,10 +1790,10 @@ pub fn numberMulWrap(
17531790 arena: Allocator,
17541791 pt: Zcu.PerThread,
17551792) !Value {
1756 const mod = pt.zcu;
1757 if (ty.zigTypeTag(mod) == .Vector) {
1758 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
1759 const scalar_ty = ty.scalarType(mod);
1793 const zcu = pt.zcu;
1794 if (ty.zigTypeTag(zcu) == .Vector) {
1795 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
1796 const scalar_ty = ty.scalarType(zcu);
17601797 for (result_data, 0..) |*scalar, i| {
17611798 const lhs_elem = try lhs.elemValue(pt, i);
17621799 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -1778,10 +1815,10 @@ pub fn numberMulWrapScalar(
17781815 arena: Allocator,
17791816 pt: Zcu.PerThread,
17801817) !Value {
1781 const mod = pt.zcu;
1782 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.undef;
1818 const zcu = pt.zcu;
1819 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.undef;
17831820
1784 if (ty.zigTypeTag(mod) == .ComptimeInt) {
1821 if (ty.zigTypeTag(zcu) == .ComptimeInt) {
17851822 return intMul(lhs, rhs, ty, undefined, arena, pt);
17861823 }
17871824
......@@ -1825,15 +1862,17 @@ pub fn intMulSatScalar(
18251862 arena: Allocator,
18261863 pt: Zcu.PerThread,
18271864) !Value {
1828 assert(!lhs.isUndef(pt.zcu));
1829 assert(!rhs.isUndef(pt.zcu));
1865 const zcu = pt.zcu;
1866
1867 assert(!lhs.isUndef(zcu));
1868 assert(!rhs.isUndef(zcu));
18301869
1831 const info = ty.intInfo(pt.zcu);
1870 const info = ty.intInfo(zcu);
18321871
18331872 var lhs_space: Value.BigIntSpace = undefined;
18341873 var rhs_space: Value.BigIntSpace = undefined;
1835 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1836 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1874 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1875 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
18371876 const limbs = try arena.alloc(
18381877 std.math.big.Limb,
18391878 @max(
......@@ -1853,24 +1892,24 @@ pub fn intMulSatScalar(
18531892}
18541893
18551894/// Supports both floats and ints; handles undefined.
1856pub fn numberMax(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {
1857 if (lhs.isUndef(pt.zcu) or rhs.isUndef(pt.zcu)) return undef;
1858 if (lhs.isNan(pt.zcu)) return rhs;
1859 if (rhs.isNan(pt.zcu)) return lhs;
1895pub fn numberMax(lhs: Value, rhs: Value, zcu: *Zcu) Value {
1896 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return undef;
1897 if (lhs.isNan(zcu)) return rhs;
1898 if (rhs.isNan(zcu)) return lhs;
18601899
1861 return switch (order(lhs, rhs, pt)) {
1900 return switch (order(lhs, rhs, zcu)) {
18621901 .lt => rhs,
18631902 .gt, .eq => lhs,
18641903 };
18651904}
18661905
18671906/// Supports both floats and ints; handles undefined.
1868pub fn numberMin(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {
1869 if (lhs.isUndef(pt.zcu) or rhs.isUndef(pt.zcu)) return undef;
1870 if (lhs.isNan(pt.zcu)) return rhs;
1871 if (rhs.isNan(pt.zcu)) return lhs;
1907pub fn numberMin(lhs: Value, rhs: Value, zcu: *Zcu) Value {
1908 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return undef;
1909 if (lhs.isNan(zcu)) return rhs;
1910 if (rhs.isNan(zcu)) return lhs;
18721911
1873 return switch (order(lhs, rhs, pt)) {
1912 return switch (order(lhs, rhs, zcu)) {
18741913 .lt => lhs,
18751914 .gt, .eq => rhs,
18761915 };
......@@ -1878,10 +1917,10 @@ pub fn numberMin(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {
18781917
18791918/// operands must be (vectors of) integers; handles undefined scalars.
18801919pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
1881 const mod = pt.zcu;
1882 if (ty.zigTypeTag(mod) == .Vector) {
1883 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
1884 const scalar_ty = ty.scalarType(mod);
1920 const zcu = pt.zcu;
1921 if (ty.zigTypeTag(zcu) == .Vector) {
1922 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
1923 const scalar_ty = ty.scalarType(zcu);
18851924 for (result_data, 0..) |*scalar, i| {
18861925 const elem_val = try val.elemValue(pt, i);
18871926 scalar.* = (try bitwiseNotScalar(elem_val, scalar_ty, arena, pt)).toIntern();
......@@ -1896,11 +1935,11 @@ pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Va
18961935
18971936/// operands must be integers; handles undefined.
18981937pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
1899 const mod = pt.zcu;
1900 if (val.isUndef(mod)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
1938 const zcu = pt.zcu;
1939 if (val.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
19011940 if (ty.toIntern() == .bool_type) return makeBool(!val.toBool());
19021941
1903 const info = ty.intInfo(mod);
1942 const info = ty.intInfo(zcu);
19041943
19051944 if (info.bits == 0) {
19061945 return val;
......@@ -1909,7 +1948,7 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea
19091948 // TODO is this a performance issue? maybe we should try the operation without
19101949 // resorting to BigInt first.
19111950 var val_space: Value.BigIntSpace = undefined;
1912 const val_bigint = val.toBigInt(&val_space, pt);
1951 const val_bigint = val.toBigInt(&val_space, zcu);
19131952 const limbs = try arena.alloc(
19141953 std.math.big.Limb,
19151954 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -1922,10 +1961,10 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea
19221961
19231962/// operands must be (vectors of) integers; handles undefined scalars.
19241963pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
1925 const mod = pt.zcu;
1926 if (ty.zigTypeTag(mod) == .Vector) {
1927 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
1928 const scalar_ty = ty.scalarType(mod);
1964 const zcu = pt.zcu;
1965 if (ty.zigTypeTag(zcu) == .Vector) {
1966 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
1967 const scalar_ty = ty.scalarType(zcu);
19291968 for (result_data, 0..) |*scalar, i| {
19301969 const lhs_elem = try lhs.elemValue(pt, i);
19311970 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -1962,8 +2001,8 @@ pub fn bitwiseAndScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloc
19622001 // resorting to BigInt first.
19632002 var lhs_space: Value.BigIntSpace = undefined;
19642003 var rhs_space: Value.BigIntSpace = undefined;
1965 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1966 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2004 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2005 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
19672006 const limbs = try arena.alloc(
19682007 std.math.big.Limb,
19692008 // + 1 for negatives
......@@ -1995,10 +2034,10 @@ fn intValueAa(ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
19952034
19962035/// operands must be (vectors of) integers; handles undefined scalars.
19972036pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
1998 const mod = pt.zcu;
1999 if (ty.zigTypeTag(mod) == .Vector) {
2000 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
2001 const scalar_ty = ty.scalarType(mod);
2037 const zcu = pt.zcu;
2038 if (ty.zigTypeTag(zcu) == .Vector) {
2039 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
2040 const scalar_ty = ty.scalarType(zcu);
20022041 for (result_data, 0..) |*scalar, i| {
20032042 const lhs_elem = try lhs.elemValue(pt, i);
20042043 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2014,21 +2053,21 @@ pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.P
20142053
20152054/// operands must be integers; handles undefined.
20162055pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
2017 const mod = pt.zcu;
2018 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
2056 const zcu = pt.zcu;
2057 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
20192058 if (ty.toIntern() == .bool_type) return makeBool(!(lhs.toBool() and rhs.toBool()));
20202059
20212060 const anded = try bitwiseAnd(lhs, rhs, ty, arena, pt);
2022 const all_ones = if (ty.isSignedInt(mod)) try pt.intValue(ty, -1) else try ty.maxIntScalar(pt, ty);
2061 const all_ones = if (ty.isSignedInt(zcu)) try pt.intValue(ty, -1) else try ty.maxIntScalar(pt, ty);
20232062 return bitwiseXor(anded, all_ones, ty, arena, pt);
20242063}
20252064
20262065/// operands must be (vectors of) integers; handles undefined scalars.
20272066pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2028 const mod = pt.zcu;
2029 if (ty.zigTypeTag(mod) == .Vector) {
2030 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2031 const scalar_ty = ty.scalarType(mod);
2067 const zcu = pt.zcu;
2068 if (ty.zigTypeTag(zcu) == .Vector) {
2069 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2070 const scalar_ty = ty.scalarType(zcu);
20322071 for (result_data, 0..) |*scalar, i| {
20332072 const lhs_elem = try lhs.elemValue(pt, i);
20342073 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2047,9 +2086,10 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
20472086 // If one operand is defined, we turn the other into `0xAA` so the bitwise AND can
20482087 // still zero out some bits.
20492088 // TODO: ideally we'd still like tracking for the undef bits. Related: #19634.
2089 const zcu = pt.zcu;
20502090 const lhs: Value, const rhs: Value = make_defined: {
2051 const lhs_undef = orig_lhs.isUndef(pt.zcu);
2052 const rhs_undef = orig_rhs.isUndef(pt.zcu);
2091 const lhs_undef = orig_lhs.isUndef(zcu);
2092 const rhs_undef = orig_rhs.isUndef(zcu);
20532093 break :make_defined switch ((@as(u2, @intFromBool(lhs_undef)) << 1) | @intFromBool(rhs_undef)) {
20542094 0b00 => .{ orig_lhs, orig_rhs },
20552095 0b01 => .{ orig_lhs, try intValueAa(ty, arena, pt) },
......@@ -2064,8 +2104,8 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
20642104 // resorting to BigInt first.
20652105 var lhs_space: Value.BigIntSpace = undefined;
20662106 var rhs_space: Value.BigIntSpace = undefined;
2067 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2068 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2107 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2108 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
20692109 const limbs = try arena.alloc(
20702110 std.math.big.Limb,
20712111 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len),
......@@ -2077,10 +2117,10 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
20772117
20782118/// operands must be (vectors of) integers; handles undefined scalars.
20792119pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2080 const mod = pt.zcu;
2081 if (ty.zigTypeTag(mod) == .Vector) {
2082 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2083 const scalar_ty = ty.scalarType(mod);
2120 const zcu = pt.zcu;
2121 if (ty.zigTypeTag(zcu) == .Vector) {
2122 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2123 const scalar_ty = ty.scalarType(zcu);
20842124 for (result_data, 0..) |*scalar, i| {
20852125 const lhs_elem = try lhs.elemValue(pt, i);
20862126 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2096,16 +2136,16 @@ pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zc
20962136
20972137/// operands must be integers; handles undefined.
20982138pub fn bitwiseXorScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
2099 const mod = pt.zcu;
2100 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
2139 const zcu = pt.zcu;
2140 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
21012141 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() != rhs.toBool());
21022142
21032143 // TODO is this a performance issue? maybe we should try the operation without
21042144 // resorting to BigInt first.
21052145 var lhs_space: Value.BigIntSpace = undefined;
21062146 var rhs_space: Value.BigIntSpace = undefined;
2107 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2108 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2147 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2148 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
21092149 const limbs = try arena.alloc(
21102150 std.math.big.Limb,
21112151 // + 1 for negatives
......@@ -2164,10 +2204,11 @@ fn intDivInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator
21642204pub fn intDivScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
21652205 // TODO is this a performance issue? maybe we should try the operation without
21662206 // resorting to BigInt first.
2207 const zcu = pt.zcu;
21672208 var lhs_space: Value.BigIntSpace = undefined;
21682209 var rhs_space: Value.BigIntSpace = undefined;
2169 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2170 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2210 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2211 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
21712212 const limbs_q = try allocator.alloc(
21722213 std.math.big.Limb,
21732214 lhs_bigint.limbs.len,
......@@ -2212,10 +2253,11 @@ pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Z
22122253pub fn intDivFloorScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
22132254 // TODO is this a performance issue? maybe we should try the operation without
22142255 // resorting to BigInt first.
2256 const zcu = pt.zcu;
22152257 var lhs_space: Value.BigIntSpace = undefined;
22162258 var rhs_space: Value.BigIntSpace = undefined;
2217 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2218 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2259 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2260 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
22192261 const limbs_q = try allocator.alloc(
22202262 std.math.big.Limb,
22212263 lhs_bigint.limbs.len,
......@@ -2254,10 +2296,11 @@ pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.Pe
22542296pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
22552297 // TODO is this a performance issue? maybe we should try the operation without
22562298 // resorting to BigInt first.
2299 const zcu = pt.zcu;
22572300 var lhs_space: Value.BigIntSpace = undefined;
22582301 var rhs_space: Value.BigIntSpace = undefined;
2259 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2260 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2302 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2303 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
22612304 const limbs_q = try allocator.alloc(
22622305 std.math.big.Limb,
22632306 lhs_bigint.limbs.len,
......@@ -2277,8 +2320,8 @@ pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
22772320}
22782321
22792322/// Returns true if the value is a floating point type and is NaN. Returns false otherwise.
2280pub fn isNan(val: Value, mod: *const Module) bool {
2281 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2323pub fn isNan(val: Value, zcu: *const Module) bool {
2324 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
22822325 .float => |float| switch (float.storage) {
22832326 inline else => |x| std.math.isNan(x),
22842327 },
......@@ -2287,8 +2330,8 @@ pub fn isNan(val: Value, mod: *const Module) bool {
22872330}
22882331
22892332/// Returns true if the value is a floating point type and is infinite. Returns false otherwise.
2290pub fn isInf(val: Value, mod: *const Module) bool {
2291 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2333pub fn isInf(val: Value, zcu: *const Module) bool {
2334 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
22922335 .float => |float| switch (float.storage) {
22932336 inline else => |x| std.math.isInf(x),
22942337 },
......@@ -2296,8 +2339,8 @@ pub fn isInf(val: Value, mod: *const Module) bool {
22962339 };
22972340}
22982341
2299pub fn isNegativeInf(val: Value, mod: *const Module) bool {
2300 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2342pub fn isNegativeInf(val: Value, zcu: *const Module) bool {
2343 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
23012344 .float => |float| switch (float.storage) {
23022345 inline else => |x| std.math.isNegativeInf(x),
23032346 },
......@@ -2323,13 +2366,14 @@ pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:
23232366}
23242367
23252368pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThread) !Value {
2369 const zcu = pt.zcu;
23262370 const target = pt.zcu.getTarget();
23272371 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2328 16 => .{ .f16 = @rem(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },
2329 32 => .{ .f32 = @rem(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },
2330 64 => .{ .f64 = @rem(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },
2331 80 => .{ .f80 = @rem(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },
2332 128 => .{ .f128 = @rem(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },
2372 16 => .{ .f16 = @rem(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
2373 32 => .{ .f32 = @rem(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
2374 64 => .{ .f64 = @rem(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
2375 80 => .{ .f80 = @rem(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
2376 128 => .{ .f128 = @rem(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
23332377 else => unreachable,
23342378 };
23352379 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2356,13 +2400,14 @@ pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:
23562400}
23572401
23582402pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThread) !Value {
2359 const target = pt.zcu.getTarget();
2403 const zcu = pt.zcu;
2404 const target = zcu.getTarget();
23602405 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2361 16 => .{ .f16 = @mod(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },
2362 32 => .{ .f32 = @mod(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },
2363 64 => .{ .f64 = @mod(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },
2364 80 => .{ .f80 = @mod(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },
2365 128 => .{ .f128 = @mod(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },
2406 16 => .{ .f16 = @mod(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
2407 32 => .{ .f32 = @mod(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
2408 64 => .{ .f64 = @mod(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
2409 80 => .{ .f80 = @mod(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
2410 128 => .{ .f128 = @mod(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
23662411 else => unreachable,
23672412 };
23682413 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2374,14 +2419,14 @@ pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThrea
23742419/// If the value overflowed the type, returns a comptime_int (or vector thereof) instead, setting
23752420/// overflow_idx to the vector index the overflow was at (or 0 for a scalar).
23762421pub fn intMul(lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize, allocator: Allocator, pt: Zcu.PerThread) !Value {
2377 const mod = pt.zcu;
2422 const zcu = pt.zcu;
23782423 var overflow: usize = undefined;
23792424 return intMulInner(lhs, rhs, ty, &overflow, allocator, pt) catch |err| switch (err) {
23802425 error.Overflow => {
2381 const is_vec = ty.isVector(mod);
2426 const is_vec = ty.isVector(zcu);
23822427 overflow_idx.* = if (is_vec) overflow else 0;
23832428 const safe_ty = if (is_vec) try pt.vectorType(.{
2384 .len = ty.vectorLen(mod),
2429 .len = ty.vectorLen(zcu),
23852430 .child = .comptime_int_type,
23862431 }) else Type.comptime_int;
23872432 return intMulInner(lhs, rhs, safe_ty, undefined, allocator, pt) catch |err1| switch (err1) {
......@@ -2394,10 +2439,10 @@ pub fn intMul(lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize, allocator
23942439}
23952440
23962441fn intMulInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator: Allocator, pt: Zcu.PerThread) !Value {
2397 const mod = pt.zcu;
2398 if (ty.zigTypeTag(mod) == .Vector) {
2399 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2400 const scalar_ty = ty.scalarType(mod);
2442 const zcu = pt.zcu;
2443 if (ty.zigTypeTag(zcu) == .Vector) {
2444 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2445 const scalar_ty = ty.scalarType(zcu);
24012446 for (result_data, 0..) |*scalar, i| {
24022447 const lhs_elem = try lhs.elemValue(pt, i);
24032448 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2419,17 +2464,18 @@ fn intMulInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator
24192464}
24202465
24212466pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2467 const zcu = pt.zcu;
24222468 if (ty.toIntern() != .comptime_int_type) {
24232469 const res = try intMulWithOverflowScalar(lhs, rhs, ty, allocator, pt);
2424 if (res.overflow_bit.compareAllWithZero(.neq, pt)) return error.Overflow;
2470 if (res.overflow_bit.compareAllWithZero(.neq, zcu)) return error.Overflow;
24252471 return res.wrapped_result;
24262472 }
24272473 // TODO is this a performance issue? maybe we should try the operation without
24282474 // resorting to BigInt first.
24292475 var lhs_space: Value.BigIntSpace = undefined;
24302476 var rhs_space: Value.BigIntSpace = undefined;
2431 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2432 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2477 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2478 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
24332479 const limbs = try allocator.alloc(
24342480 std.math.big.Limb,
24352481 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
......@@ -2445,10 +2491,10 @@ pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
24452491}
24462492
24472493pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, pt: Zcu.PerThread) !Value {
2448 const mod = pt.zcu;
2449 if (ty.zigTypeTag(mod) == .Vector) {
2450 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2451 const scalar_ty = ty.scalarType(mod);
2494 const zcu = pt.zcu;
2495 if (ty.zigTypeTag(zcu) == .Vector) {
2496 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2497 const scalar_ty = ty.scalarType(zcu);
24522498 for (result_data, 0..) |*scalar, i| {
24532499 const elem_val = try val.elemValue(pt, i);
24542500 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, pt)).toIntern();
......@@ -2470,20 +2516,21 @@ pub fn intTruncBitsAsValue(
24702516 bits: Value,
24712517 pt: Zcu.PerThread,
24722518) !Value {
2473 if (ty.zigTypeTag(pt.zcu) == .Vector) {
2474 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(pt.zcu));
2475 const scalar_ty = ty.scalarType(pt.zcu);
2519 const zcu = pt.zcu;
2520 if (ty.zigTypeTag(zcu) == .Vector) {
2521 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2522 const scalar_ty = ty.scalarType(zcu);
24762523 for (result_data, 0..) |*scalar, i| {
24772524 const elem_val = try val.elemValue(pt, i);
24782525 const bits_elem = try bits.elemValue(pt, i);
2479 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(bits_elem.toUnsignedInt(pt)), pt)).toIntern();
2526 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(bits_elem.toUnsignedInt(zcu)), pt)).toIntern();
24802527 }
24812528 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
24822529 .ty = ty.toIntern(),
24832530 .storage = .{ .elems = result_data },
24842531 } }));
24852532 }
2486 return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(pt)), pt);
2533 return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(zcu)), pt);
24872534}
24882535
24892536pub fn intTruncScalar(
......@@ -2500,7 +2547,7 @@ pub fn intTruncScalar(
25002547 if (val.isUndef(zcu)) return pt.undefValue(ty);
25012548
25022549 var val_space: Value.BigIntSpace = undefined;
2503 const val_bigint = val.toBigInt(&val_space, pt);
2550 const val_bigint = val.toBigInt(&val_space, zcu);
25042551
25052552 const limbs = try allocator.alloc(
25062553 std.math.big.Limb,
......@@ -2513,10 +2560,10 @@ pub fn intTruncScalar(
25132560}
25142561
25152562pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2516 const mod = pt.zcu;
2517 if (ty.zigTypeTag(mod) == .Vector) {
2518 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2519 const scalar_ty = ty.scalarType(mod);
2563 const zcu = pt.zcu;
2564 if (ty.zigTypeTag(zcu) == .Vector) {
2565 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2566 const scalar_ty = ty.scalarType(zcu);
25202567 for (result_data, 0..) |*scalar, i| {
25212568 const lhs_elem = try lhs.elemValue(pt, i);
25222569 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2533,9 +2580,10 @@ pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerTh
25332580pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
25342581 // TODO is this a performance issue? maybe we should try the operation without
25352582 // resorting to BigInt first.
2583 const zcu = pt.zcu;
25362584 var lhs_space: Value.BigIntSpace = undefined;
2537 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2538 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2585 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2586 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
25392587 const limbs = try allocator.alloc(
25402588 std.math.big.Limb,
25412589 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2547,7 +2595,7 @@ pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu
25472595 };
25482596 result_bigint.shiftLeft(lhs_bigint, shift);
25492597 if (ty.toIntern() != .comptime_int_type) {
2550 const int_info = ty.intInfo(pt.zcu);
2598 const int_info = ty.intInfo(zcu);
25512599 result_bigint.truncate(result_bigint.toConst(), int_info.signedness, int_info.bits);
25522600 }
25532601
......@@ -2594,10 +2642,11 @@ pub fn shlWithOverflowScalar(
25942642 allocator: Allocator,
25952643 pt: Zcu.PerThread,
25962644) !OverflowArithmeticResult {
2597 const info = ty.intInfo(pt.zcu);
2645 const zcu = pt.zcu;
2646 const info = ty.intInfo(zcu);
25982647 var lhs_space: Value.BigIntSpace = undefined;
2599 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2600 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2648 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2649 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
26012650 const limbs = try allocator.alloc(
26022651 std.math.big.Limb,
26032652 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2650,11 +2699,12 @@ pub fn shlSatScalar(
26502699) !Value {
26512700 // TODO is this a performance issue? maybe we should try the operation without
26522701 // resorting to BigInt first.
2653 const info = ty.intInfo(pt.zcu);
2702 const zcu = pt.zcu;
2703 const info = ty.intInfo(zcu);
26542704
26552705 var lhs_space: Value.BigIntSpace = undefined;
2656 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2657 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2706 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2707 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
26582708 const limbs = try arena.alloc(
26592709 std.math.big.Limb,
26602710 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,
......@@ -2724,9 +2774,10 @@ pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerTh
27242774pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
27252775 // TODO is this a performance issue? maybe we should try the operation without
27262776 // resorting to BigInt first.
2777 const zcu = pt.zcu;
27272778 var lhs_space: Value.BigIntSpace = undefined;
2728 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2729 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2779 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2780 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
27302781
27312782 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
27322783 if (result_limbs == 0) {
......@@ -2758,10 +2809,10 @@ pub fn floatNeg(
27582809 arena: Allocator,
27592810 pt: Zcu.PerThread,
27602811) !Value {
2761 const mod = pt.zcu;
2762 if (float_type.zigTypeTag(mod) == .Vector) {
2763 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
2764 const scalar_ty = float_type.scalarType(mod);
2812 const zcu = pt.zcu;
2813 if (float_type.zigTypeTag(zcu) == .Vector) {
2814 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2815 const scalar_ty = float_type.scalarType(zcu);
27652816 for (result_data, 0..) |*scalar, i| {
27662817 const elem_val = try val.elemValue(pt, i);
27672818 scalar.* = (try floatNegScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -2775,13 +2826,14 @@ pub fn floatNeg(
27752826}
27762827
27772828pub fn floatNegScalar(val: Value, float_type: Type, pt: Zcu.PerThread) !Value {
2778 const target = pt.zcu.getTarget();
2829 const zcu = pt.zcu;
2830 const target = zcu.getTarget();
27792831 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2780 16 => .{ .f16 = -val.toFloat(f16, pt) },
2781 32 => .{ .f32 = -val.toFloat(f32, pt) },
2782 64 => .{ .f64 = -val.toFloat(f64, pt) },
2783 80 => .{ .f80 = -val.toFloat(f80, pt) },
2784 128 => .{ .f128 = -val.toFloat(f128, pt) },
2832 16 => .{ .f16 = -val.toFloat(f16, zcu) },
2833 32 => .{ .f32 = -val.toFloat(f32, zcu) },
2834 64 => .{ .f64 = -val.toFloat(f64, zcu) },
2835 80 => .{ .f80 = -val.toFloat(f80, zcu) },
2836 128 => .{ .f128 = -val.toFloat(f128, zcu) },
27852837 else => unreachable,
27862838 };
27872839 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2797,10 +2849,10 @@ pub fn floatAdd(
27972849 arena: Allocator,
27982850 pt: Zcu.PerThread,
27992851) !Value {
2800 const mod = pt.zcu;
2801 if (float_type.zigTypeTag(mod) == .Vector) {
2802 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
2803 const scalar_ty = float_type.scalarType(mod);
2852 const zcu = pt.zcu;
2853 if (float_type.zigTypeTag(zcu) == .Vector) {
2854 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2855 const scalar_ty = float_type.scalarType(zcu);
28042856 for (result_data, 0..) |*scalar, i| {
28052857 const lhs_elem = try lhs.elemValue(pt, i);
28062858 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2820,14 +2872,14 @@ pub fn floatAddScalar(
28202872 float_type: Type,
28212873 pt: Zcu.PerThread,
28222874) !Value {
2823 const mod = pt.zcu;
2824 const target = mod.getTarget();
2875 const zcu = pt.zcu;
2876 const target = zcu.getTarget();
28252877 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2826 16 => .{ .f16 = lhs.toFloat(f16, pt) + rhs.toFloat(f16, pt) },
2827 32 => .{ .f32 = lhs.toFloat(f32, pt) + rhs.toFloat(f32, pt) },
2828 64 => .{ .f64 = lhs.toFloat(f64, pt) + rhs.toFloat(f64, pt) },
2829 80 => .{ .f80 = lhs.toFloat(f80, pt) + rhs.toFloat(f80, pt) },
2830 128 => .{ .f128 = lhs.toFloat(f128, pt) + rhs.toFloat(f128, pt) },
2878 16 => .{ .f16 = lhs.toFloat(f16, zcu) + rhs.toFloat(f16, zcu) },
2879 32 => .{ .f32 = lhs.toFloat(f32, zcu) + rhs.toFloat(f32, zcu) },
2880 64 => .{ .f64 = lhs.toFloat(f64, zcu) + rhs.toFloat(f64, zcu) },
2881 80 => .{ .f80 = lhs.toFloat(f80, zcu) + rhs.toFloat(f80, zcu) },
2882 128 => .{ .f128 = lhs.toFloat(f128, zcu) + rhs.toFloat(f128, zcu) },
28312883 else => unreachable,
28322884 };
28332885 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2843,10 +2895,10 @@ pub fn floatSub(
28432895 arena: Allocator,
28442896 pt: Zcu.PerThread,
28452897) !Value {
2846 const mod = pt.zcu;
2847 if (float_type.zigTypeTag(mod) == .Vector) {
2848 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
2849 const scalar_ty = float_type.scalarType(mod);
2898 const zcu = pt.zcu;
2899 if (float_type.zigTypeTag(zcu) == .Vector) {
2900 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2901 const scalar_ty = float_type.scalarType(zcu);
28502902 for (result_data, 0..) |*scalar, i| {
28512903 const lhs_elem = try lhs.elemValue(pt, i);
28522904 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2866,14 +2918,14 @@ pub fn floatSubScalar(
28662918 float_type: Type,
28672919 pt: Zcu.PerThread,
28682920) !Value {
2869 const mod = pt.zcu;
2870 const target = mod.getTarget();
2921 const zcu = pt.zcu;
2922 const target = zcu.getTarget();
28712923 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2872 16 => .{ .f16 = lhs.toFloat(f16, pt) - rhs.toFloat(f16, pt) },
2873 32 => .{ .f32 = lhs.toFloat(f32, pt) - rhs.toFloat(f32, pt) },
2874 64 => .{ .f64 = lhs.toFloat(f64, pt) - rhs.toFloat(f64, pt) },
2875 80 => .{ .f80 = lhs.toFloat(f80, pt) - rhs.toFloat(f80, pt) },
2876 128 => .{ .f128 = lhs.toFloat(f128, pt) - rhs.toFloat(f128, pt) },
2924 16 => .{ .f16 = lhs.toFloat(f16, zcu) - rhs.toFloat(f16, zcu) },
2925 32 => .{ .f32 = lhs.toFloat(f32, zcu) - rhs.toFloat(f32, zcu) },
2926 64 => .{ .f64 = lhs.toFloat(f64, zcu) - rhs.toFloat(f64, zcu) },
2927 80 => .{ .f80 = lhs.toFloat(f80, zcu) - rhs.toFloat(f80, zcu) },
2928 128 => .{ .f128 = lhs.toFloat(f128, zcu) - rhs.toFloat(f128, zcu) },
28772929 else => unreachable,
28782930 };
28792931 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2911,13 +2963,14 @@ pub fn floatDivScalar(
29112963 float_type: Type,
29122964 pt: Zcu.PerThread,
29132965) !Value {
2914 const target = pt.zcu.getTarget();
2966 const zcu = pt.zcu;
2967 const target = zcu.getTarget();
29152968 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2916 16 => .{ .f16 = lhs.toFloat(f16, pt) / rhs.toFloat(f16, pt) },
2917 32 => .{ .f32 = lhs.toFloat(f32, pt) / rhs.toFloat(f32, pt) },
2918 64 => .{ .f64 = lhs.toFloat(f64, pt) / rhs.toFloat(f64, pt) },
2919 80 => .{ .f80 = lhs.toFloat(f80, pt) / rhs.toFloat(f80, pt) },
2920 128 => .{ .f128 = lhs.toFloat(f128, pt) / rhs.toFloat(f128, pt) },
2969 16 => .{ .f16 = lhs.toFloat(f16, zcu) / rhs.toFloat(f16, zcu) },
2970 32 => .{ .f32 = lhs.toFloat(f32, zcu) / rhs.toFloat(f32, zcu) },
2971 64 => .{ .f64 = lhs.toFloat(f64, zcu) / rhs.toFloat(f64, zcu) },
2972 80 => .{ .f80 = lhs.toFloat(f80, zcu) / rhs.toFloat(f80, zcu) },
2973 128 => .{ .f128 = lhs.toFloat(f128, zcu) / rhs.toFloat(f128, zcu) },
29212974 else => unreachable,
29222975 };
29232976 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2955,13 +3008,14 @@ pub fn floatDivFloorScalar(
29553008 float_type: Type,
29563009 pt: Zcu.PerThread,
29573010) !Value {
2958 const target = pt.zcu.getTarget();
3011 const zcu = pt.zcu;
3012 const target = zcu.getTarget();
29593013 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2960 16 => .{ .f16 = @divFloor(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },
2961 32 => .{ .f32 = @divFloor(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },
2962 64 => .{ .f64 = @divFloor(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },
2963 80 => .{ .f80 = @divFloor(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },
2964 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },
3014 16 => .{ .f16 = @divFloor(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
3015 32 => .{ .f32 = @divFloor(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
3016 64 => .{ .f64 = @divFloor(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
3017 80 => .{ .f80 = @divFloor(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
3018 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
29653019 else => unreachable,
29663020 };
29673021 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2999,13 +3053,14 @@ pub fn floatDivTruncScalar(
29993053 float_type: Type,
30003054 pt: Zcu.PerThread,
30013055) !Value {
3002 const target = pt.zcu.getTarget();
3056 const zcu = pt.zcu;
3057 const target = zcu.getTarget();
30033058 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3004 16 => .{ .f16 = @divTrunc(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },
3005 32 => .{ .f32 = @divTrunc(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },
3006 64 => .{ .f64 = @divTrunc(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },
3007 80 => .{ .f80 = @divTrunc(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },
3008 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },
3059 16 => .{ .f16 = @divTrunc(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
3060 32 => .{ .f32 = @divTrunc(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
3061 64 => .{ .f64 = @divTrunc(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
3062 80 => .{ .f80 = @divTrunc(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
3063 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
30093064 else => unreachable,
30103065 };
30113066 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3021,10 +3076,10 @@ pub fn floatMul(
30213076 arena: Allocator,
30223077 pt: Zcu.PerThread,
30233078) !Value {
3024 const mod = pt.zcu;
3025 if (float_type.zigTypeTag(mod) == .Vector) {
3026 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3027 const scalar_ty = float_type.scalarType(mod);
3079 const zcu = pt.zcu;
3080 if (float_type.zigTypeTag(zcu) == .Vector) {
3081 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3082 const scalar_ty = float_type.scalarType(zcu);
30283083 for (result_data, 0..) |*scalar, i| {
30293084 const lhs_elem = try lhs.elemValue(pt, i);
30303085 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -3044,14 +3099,14 @@ pub fn floatMulScalar(
30443099 float_type: Type,
30453100 pt: Zcu.PerThread,
30463101) !Value {
3047 const mod = pt.zcu;
3048 const target = mod.getTarget();
3102 const zcu = pt.zcu;
3103 const target = zcu.getTarget();
30493104 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3050 16 => .{ .f16 = lhs.toFloat(f16, pt) * rhs.toFloat(f16, pt) },
3051 32 => .{ .f32 = lhs.toFloat(f32, pt) * rhs.toFloat(f32, pt) },
3052 64 => .{ .f64 = lhs.toFloat(f64, pt) * rhs.toFloat(f64, pt) },
3053 80 => .{ .f80 = lhs.toFloat(f80, pt) * rhs.toFloat(f80, pt) },
3054 128 => .{ .f128 = lhs.toFloat(f128, pt) * rhs.toFloat(f128, pt) },
3105 16 => .{ .f16 = lhs.toFloat(f16, zcu) * rhs.toFloat(f16, zcu) },
3106 32 => .{ .f32 = lhs.toFloat(f32, zcu) * rhs.toFloat(f32, zcu) },
3107 64 => .{ .f64 = lhs.toFloat(f64, zcu) * rhs.toFloat(f64, zcu) },
3108 80 => .{ .f80 = lhs.toFloat(f80, zcu) * rhs.toFloat(f80, zcu) },
3109 128 => .{ .f128 = lhs.toFloat(f128, zcu) * rhs.toFloat(f128, zcu) },
30553110 else => unreachable,
30563111 };
30573112 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3077,14 +3132,14 @@ pub fn sqrt(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
30773132}
30783133
30793134pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3080 const mod = pt.zcu;
3081 const target = mod.getTarget();
3135 const zcu = pt.zcu;
3136 const target = zcu.getTarget();
30823137 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3083 16 => .{ .f16 = @sqrt(val.toFloat(f16, pt)) },
3084 32 => .{ .f32 = @sqrt(val.toFloat(f32, pt)) },
3085 64 => .{ .f64 = @sqrt(val.toFloat(f64, pt)) },
3086 80 => .{ .f80 = @sqrt(val.toFloat(f80, pt)) },
3087 128 => .{ .f128 = @sqrt(val.toFloat(f128, pt)) },
3138 16 => .{ .f16 = @sqrt(val.toFloat(f16, zcu)) },
3139 32 => .{ .f32 = @sqrt(val.toFloat(f32, zcu)) },
3140 64 => .{ .f64 = @sqrt(val.toFloat(f64, zcu)) },
3141 80 => .{ .f80 = @sqrt(val.toFloat(f80, zcu)) },
3142 128 => .{ .f128 = @sqrt(val.toFloat(f128, zcu)) },
30883143 else => unreachable,
30893144 };
30903145 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3094,10 +3149,10 @@ pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
30943149}
30953150
30963151pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3097 const mod = pt.zcu;
3098 if (float_type.zigTypeTag(mod) == .Vector) {
3099 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3100 const scalar_ty = float_type.scalarType(mod);
3152 const zcu = pt.zcu;
3153 if (float_type.zigTypeTag(zcu) == .Vector) {
3154 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3155 const scalar_ty = float_type.scalarType(zcu);
31013156 for (result_data, 0..) |*scalar, i| {
31023157 const elem_val = try val.elemValue(pt, i);
31033158 scalar.* = (try sinScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3111,14 +3166,14 @@ pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
31113166}
31123167
31133168pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3114 const mod = pt.zcu;
3115 const target = mod.getTarget();
3169 const zcu = pt.zcu;
3170 const target = zcu.getTarget();
31163171 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3117 16 => .{ .f16 = @sin(val.toFloat(f16, pt)) },
3118 32 => .{ .f32 = @sin(val.toFloat(f32, pt)) },
3119 64 => .{ .f64 = @sin(val.toFloat(f64, pt)) },
3120 80 => .{ .f80 = @sin(val.toFloat(f80, pt)) },
3121 128 => .{ .f128 = @sin(val.toFloat(f128, pt)) },
3172 16 => .{ .f16 = @sin(val.toFloat(f16, zcu)) },
3173 32 => .{ .f32 = @sin(val.toFloat(f32, zcu)) },
3174 64 => .{ .f64 = @sin(val.toFloat(f64, zcu)) },
3175 80 => .{ .f80 = @sin(val.toFloat(f80, zcu)) },
3176 128 => .{ .f128 = @sin(val.toFloat(f128, zcu)) },
31223177 else => unreachable,
31233178 };
31243179 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3128,10 +3183,10 @@ pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
31283183}
31293184
31303185pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3131 const mod = pt.zcu;
3132 if (float_type.zigTypeTag(mod) == .Vector) {
3133 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3134 const scalar_ty = float_type.scalarType(mod);
3186 const zcu = pt.zcu;
3187 if (float_type.zigTypeTag(zcu) == .Vector) {
3188 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3189 const scalar_ty = float_type.scalarType(zcu);
31353190 for (result_data, 0..) |*scalar, i| {
31363191 const elem_val = try val.elemValue(pt, i);
31373192 scalar.* = (try cosScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3145,14 +3200,14 @@ pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
31453200}
31463201
31473202pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3148 const mod = pt.zcu;
3149 const target = mod.getTarget();
3203 const zcu = pt.zcu;
3204 const target = zcu.getTarget();
31503205 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3151 16 => .{ .f16 = @cos(val.toFloat(f16, pt)) },
3152 32 => .{ .f32 = @cos(val.toFloat(f32, pt)) },
3153 64 => .{ .f64 = @cos(val.toFloat(f64, pt)) },
3154 80 => .{ .f80 = @cos(val.toFloat(f80, pt)) },
3155 128 => .{ .f128 = @cos(val.toFloat(f128, pt)) },
3206 16 => .{ .f16 = @cos(val.toFloat(f16, zcu)) },
3207 32 => .{ .f32 = @cos(val.toFloat(f32, zcu)) },
3208 64 => .{ .f64 = @cos(val.toFloat(f64, zcu)) },
3209 80 => .{ .f80 = @cos(val.toFloat(f80, zcu)) },
3210 128 => .{ .f128 = @cos(val.toFloat(f128, zcu)) },
31563211 else => unreachable,
31573212 };
31583213 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3162,10 +3217,10 @@ pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
31623217}
31633218
31643219pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3165 const mod = pt.zcu;
3166 if (float_type.zigTypeTag(mod) == .Vector) {
3167 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3168 const scalar_ty = float_type.scalarType(mod);
3220 const zcu = pt.zcu;
3221 if (float_type.zigTypeTag(zcu) == .Vector) {
3222 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3223 const scalar_ty = float_type.scalarType(zcu);
31693224 for (result_data, 0..) |*scalar, i| {
31703225 const elem_val = try val.elemValue(pt, i);
31713226 scalar.* = (try tanScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3179,14 +3234,14 @@ pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
31793234}
31803235
31813236pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3182 const mod = pt.zcu;
3183 const target = mod.getTarget();
3237 const zcu = pt.zcu;
3238 const target = zcu.getTarget();
31843239 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3185 16 => .{ .f16 = @tan(val.toFloat(f16, pt)) },
3186 32 => .{ .f32 = @tan(val.toFloat(f32, pt)) },
3187 64 => .{ .f64 = @tan(val.toFloat(f64, pt)) },
3188 80 => .{ .f80 = @tan(val.toFloat(f80, pt)) },
3189 128 => .{ .f128 = @tan(val.toFloat(f128, pt)) },
3240 16 => .{ .f16 = @tan(val.toFloat(f16, zcu)) },
3241 32 => .{ .f32 = @tan(val.toFloat(f32, zcu)) },
3242 64 => .{ .f64 = @tan(val.toFloat(f64, zcu)) },
3243 80 => .{ .f80 = @tan(val.toFloat(f80, zcu)) },
3244 128 => .{ .f128 = @tan(val.toFloat(f128, zcu)) },
31903245 else => unreachable,
31913246 };
31923247 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3196,10 +3251,10 @@ pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
31963251}
31973252
31983253pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3199 const mod = pt.zcu;
3200 if (float_type.zigTypeTag(mod) == .Vector) {
3201 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3202 const scalar_ty = float_type.scalarType(mod);
3254 const zcu = pt.zcu;
3255 if (float_type.zigTypeTag(zcu) == .Vector) {
3256 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3257 const scalar_ty = float_type.scalarType(zcu);
32033258 for (result_data, 0..) |*scalar, i| {
32043259 const elem_val = try val.elemValue(pt, i);
32053260 scalar.* = (try expScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3213,14 +3268,14 @@ pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
32133268}
32143269
32153270pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3216 const mod = pt.zcu;
3217 const target = mod.getTarget();
3271 const zcu = pt.zcu;
3272 const target = zcu.getTarget();
32183273 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3219 16 => .{ .f16 = @exp(val.toFloat(f16, pt)) },
3220 32 => .{ .f32 = @exp(val.toFloat(f32, pt)) },
3221 64 => .{ .f64 = @exp(val.toFloat(f64, pt)) },
3222 80 => .{ .f80 = @exp(val.toFloat(f80, pt)) },
3223 128 => .{ .f128 = @exp(val.toFloat(f128, pt)) },
3274 16 => .{ .f16 = @exp(val.toFloat(f16, zcu)) },
3275 32 => .{ .f32 = @exp(val.toFloat(f32, zcu)) },
3276 64 => .{ .f64 = @exp(val.toFloat(f64, zcu)) },
3277 80 => .{ .f80 = @exp(val.toFloat(f80, zcu)) },
3278 128 => .{ .f128 = @exp(val.toFloat(f128, zcu)) },
32243279 else => unreachable,
32253280 };
32263281 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3230,10 +3285,10 @@ pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
32303285}
32313286
32323287pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3233 const mod = pt.zcu;
3234 if (float_type.zigTypeTag(mod) == .Vector) {
3235 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3236 const scalar_ty = float_type.scalarType(mod);
3288 const zcu = pt.zcu;
3289 if (float_type.zigTypeTag(zcu) == .Vector) {
3290 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3291 const scalar_ty = float_type.scalarType(zcu);
32373292 for (result_data, 0..) |*scalar, i| {
32383293 const elem_val = try val.elemValue(pt, i);
32393294 scalar.* = (try exp2Scalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3247,14 +3302,14 @@ pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
32473302}
32483303
32493304pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3250 const mod = pt.zcu;
3251 const target = mod.getTarget();
3305 const zcu = pt.zcu;
3306 const target = zcu.getTarget();
32523307 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3253 16 => .{ .f16 = @exp2(val.toFloat(f16, pt)) },
3254 32 => .{ .f32 = @exp2(val.toFloat(f32, pt)) },
3255 64 => .{ .f64 = @exp2(val.toFloat(f64, pt)) },
3256 80 => .{ .f80 = @exp2(val.toFloat(f80, pt)) },
3257 128 => .{ .f128 = @exp2(val.toFloat(f128, pt)) },
3308 16 => .{ .f16 = @exp2(val.toFloat(f16, zcu)) },
3309 32 => .{ .f32 = @exp2(val.toFloat(f32, zcu)) },
3310 64 => .{ .f64 = @exp2(val.toFloat(f64, zcu)) },
3311 80 => .{ .f80 = @exp2(val.toFloat(f80, zcu)) },
3312 128 => .{ .f128 = @exp2(val.toFloat(f128, zcu)) },
32583313 else => unreachable,
32593314 };
32603315 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3264,10 +3319,10 @@ pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
32643319}
32653320
32663321pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3267 const mod = pt.zcu;
3268 if (float_type.zigTypeTag(mod) == .Vector) {
3269 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3270 const scalar_ty = float_type.scalarType(mod);
3322 const zcu = pt.zcu;
3323 if (float_type.zigTypeTag(zcu) == .Vector) {
3324 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3325 const scalar_ty = float_type.scalarType(zcu);
32713326 for (result_data, 0..) |*scalar, i| {
32723327 const elem_val = try val.elemValue(pt, i);
32733328 scalar.* = (try logScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3281,14 +3336,14 @@ pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
32813336}
32823337
32833338pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3284 const mod = pt.zcu;
3285 const target = mod.getTarget();
3339 const zcu = pt.zcu;
3340 const target = zcu.getTarget();
32863341 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3287 16 => .{ .f16 = @log(val.toFloat(f16, pt)) },
3288 32 => .{ .f32 = @log(val.toFloat(f32, pt)) },
3289 64 => .{ .f64 = @log(val.toFloat(f64, pt)) },
3290 80 => .{ .f80 = @log(val.toFloat(f80, pt)) },
3291 128 => .{ .f128 = @log(val.toFloat(f128, pt)) },
3342 16 => .{ .f16 = @log(val.toFloat(f16, zcu)) },
3343 32 => .{ .f32 = @log(val.toFloat(f32, zcu)) },
3344 64 => .{ .f64 = @log(val.toFloat(f64, zcu)) },
3345 80 => .{ .f80 = @log(val.toFloat(f80, zcu)) },
3346 128 => .{ .f128 = @log(val.toFloat(f128, zcu)) },
32923347 else => unreachable,
32933348 };
32943349 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3298,10 +3353,10 @@ pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
32983353}
32993354
33003355pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3301 const mod = pt.zcu;
3302 if (float_type.zigTypeTag(mod) == .Vector) {
3303 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3304 const scalar_ty = float_type.scalarType(mod);
3356 const zcu = pt.zcu;
3357 if (float_type.zigTypeTag(zcu) == .Vector) {
3358 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3359 const scalar_ty = float_type.scalarType(zcu);
33053360 for (result_data, 0..) |*scalar, i| {
33063361 const elem_val = try val.elemValue(pt, i);
33073362 scalar.* = (try log2Scalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3315,14 +3370,14 @@ pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
33153370}
33163371
33173372pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3318 const mod = pt.zcu;
3319 const target = mod.getTarget();
3373 const zcu = pt.zcu;
3374 const target = zcu.getTarget();
33203375 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3321 16 => .{ .f16 = @log2(val.toFloat(f16, pt)) },
3322 32 => .{ .f32 = @log2(val.toFloat(f32, pt)) },
3323 64 => .{ .f64 = @log2(val.toFloat(f64, pt)) },
3324 80 => .{ .f80 = @log2(val.toFloat(f80, pt)) },
3325 128 => .{ .f128 = @log2(val.toFloat(f128, pt)) },
3376 16 => .{ .f16 = @log2(val.toFloat(f16, zcu)) },
3377 32 => .{ .f32 = @log2(val.toFloat(f32, zcu)) },
3378 64 => .{ .f64 = @log2(val.toFloat(f64, zcu)) },
3379 80 => .{ .f80 = @log2(val.toFloat(f80, zcu)) },
3380 128 => .{ .f128 = @log2(val.toFloat(f128, zcu)) },
33263381 else => unreachable,
33273382 };
33283383 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3332,10 +3387,10 @@ pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
33323387}
33333388
33343389pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3335 const mod = pt.zcu;
3336 if (float_type.zigTypeTag(mod) == .Vector) {
3337 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3338 const scalar_ty = float_type.scalarType(mod);
3390 const zcu = pt.zcu;
3391 if (float_type.zigTypeTag(zcu) == .Vector) {
3392 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3393 const scalar_ty = float_type.scalarType(zcu);
33393394 for (result_data, 0..) |*scalar, i| {
33403395 const elem_val = try val.elemValue(pt, i);
33413396 scalar.* = (try log10Scalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3349,14 +3404,14 @@ pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
33493404}
33503405
33513406pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3352 const mod = pt.zcu;
3353 const target = mod.getTarget();
3407 const zcu = pt.zcu;
3408 const target = zcu.getTarget();
33543409 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3355 16 => .{ .f16 = @log10(val.toFloat(f16, pt)) },
3356 32 => .{ .f32 = @log10(val.toFloat(f32, pt)) },
3357 64 => .{ .f64 = @log10(val.toFloat(f64, pt)) },
3358 80 => .{ .f80 = @log10(val.toFloat(f80, pt)) },
3359 128 => .{ .f128 = @log10(val.toFloat(f128, pt)) },
3410 16 => .{ .f16 = @log10(val.toFloat(f16, zcu)) },
3411 32 => .{ .f32 = @log10(val.toFloat(f32, zcu)) },
3412 64 => .{ .f64 = @log10(val.toFloat(f64, zcu)) },
3413 80 => .{ .f80 = @log10(val.toFloat(f80, zcu)) },
3414 128 => .{ .f128 = @log10(val.toFloat(f128, zcu)) },
33603415 else => unreachable,
33613416 };
33623417 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3366,10 +3421,10 @@ pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
33663421}
33673422
33683423pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3369 const mod = pt.zcu;
3370 if (ty.zigTypeTag(mod) == .Vector) {
3371 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
3372 const scalar_ty = ty.scalarType(mod);
3424 const zcu = pt.zcu;
3425 if (ty.zigTypeTag(zcu) == .Vector) {
3426 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
3427 const scalar_ty = ty.scalarType(zcu);
33733428 for (result_data, 0..) |*scalar, i| {
33743429 const elem_val = try val.elemValue(pt, i);
33753430 scalar.* = (try absScalar(elem_val, scalar_ty, pt, arena)).toIntern();
......@@ -3383,30 +3438,30 @@ pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
33833438}
33843439
33853440pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allocator.Error!Value {
3386 const mod = pt.zcu;
3387 switch (ty.zigTypeTag(mod)) {
3441 const zcu = pt.zcu;
3442 switch (ty.zigTypeTag(zcu)) {
33883443 .Int => {
33893444 var buffer: Value.BigIntSpace = undefined;
3390 var operand_bigint = try val.toBigInt(&buffer, pt).toManaged(arena);
3445 var operand_bigint = try val.toBigInt(&buffer, zcu).toManaged(arena);
33913446 operand_bigint.abs();
33923447
33933448 return pt.intValue_big(try ty.toUnsigned(pt), operand_bigint.toConst());
33943449 },
33953450 .ComptimeInt => {
33963451 var buffer: Value.BigIntSpace = undefined;
3397 var operand_bigint = try val.toBigInt(&buffer, pt).toManaged(arena);
3452 var operand_bigint = try val.toBigInt(&buffer, zcu).toManaged(arena);
33983453 operand_bigint.abs();
33993454
34003455 return pt.intValue_big(ty, operand_bigint.toConst());
34013456 },
34023457 .ComptimeFloat, .Float => {
3403 const target = mod.getTarget();
3458 const target = zcu.getTarget();
34043459 const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(target)) {
3405 16 => .{ .f16 = @abs(val.toFloat(f16, pt)) },
3406 32 => .{ .f32 = @abs(val.toFloat(f32, pt)) },
3407 64 => .{ .f64 = @abs(val.toFloat(f64, pt)) },
3408 80 => .{ .f80 = @abs(val.toFloat(f80, pt)) },
3409 128 => .{ .f128 = @abs(val.toFloat(f128, pt)) },
3460 16 => .{ .f16 = @abs(val.toFloat(f16, zcu)) },
3461 32 => .{ .f32 = @abs(val.toFloat(f32, zcu)) },
3462 64 => .{ .f64 = @abs(val.toFloat(f64, zcu)) },
3463 80 => .{ .f80 = @abs(val.toFloat(f80, zcu)) },
3464 128 => .{ .f128 = @abs(val.toFloat(f128, zcu)) },
34103465 else => unreachable,
34113466 };
34123467 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3419,10 +3474,10 @@ pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allo
34193474}
34203475
34213476pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3422 const mod = pt.zcu;
3423 if (float_type.zigTypeTag(mod) == .Vector) {
3424 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3425 const scalar_ty = float_type.scalarType(mod);
3477 const zcu = pt.zcu;
3478 if (float_type.zigTypeTag(zcu) == .Vector) {
3479 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3480 const scalar_ty = float_type.scalarType(zcu);
34263481 for (result_data, 0..) |*scalar, i| {
34273482 const elem_val = try val.elemValue(pt, i);
34283483 scalar.* = (try floorScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3436,14 +3491,14 @@ pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
34363491}
34373492
34383493pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3439 const mod = pt.zcu;
3440 const target = mod.getTarget();
3494 const zcu = pt.zcu;
3495 const target = zcu.getTarget();
34413496 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3442 16 => .{ .f16 = @floor(val.toFloat(f16, pt)) },
3443 32 => .{ .f32 = @floor(val.toFloat(f32, pt)) },
3444 64 => .{ .f64 = @floor(val.toFloat(f64, pt)) },
3445 80 => .{ .f80 = @floor(val.toFloat(f80, pt)) },
3446 128 => .{ .f128 = @floor(val.toFloat(f128, pt)) },
3497 16 => .{ .f16 = @floor(val.toFloat(f16, zcu)) },
3498 32 => .{ .f32 = @floor(val.toFloat(f32, zcu)) },
3499 64 => .{ .f64 = @floor(val.toFloat(f64, zcu)) },
3500 80 => .{ .f80 = @floor(val.toFloat(f80, zcu)) },
3501 128 => .{ .f128 = @floor(val.toFloat(f128, zcu)) },
34473502 else => unreachable,
34483503 };
34493504 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3453,10 +3508,10 @@ pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
34533508}
34543509
34553510pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3456 const mod = pt.zcu;
3457 if (float_type.zigTypeTag(mod) == .Vector) {
3458 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3459 const scalar_ty = float_type.scalarType(mod);
3511 const zcu = pt.zcu;
3512 if (float_type.zigTypeTag(zcu) == .Vector) {
3513 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3514 const scalar_ty = float_type.scalarType(zcu);
34603515 for (result_data, 0..) |*scalar, i| {
34613516 const elem_val = try val.elemValue(pt, i);
34623517 scalar.* = (try ceilScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3470,14 +3525,14 @@ pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
34703525}
34713526
34723527pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3473 const mod = pt.zcu;
3474 const target = mod.getTarget();
3528 const zcu = pt.zcu;
3529 const target = zcu.getTarget();
34753530 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3476 16 => .{ .f16 = @ceil(val.toFloat(f16, pt)) },
3477 32 => .{ .f32 = @ceil(val.toFloat(f32, pt)) },
3478 64 => .{ .f64 = @ceil(val.toFloat(f64, pt)) },
3479 80 => .{ .f80 = @ceil(val.toFloat(f80, pt)) },
3480 128 => .{ .f128 = @ceil(val.toFloat(f128, pt)) },
3531 16 => .{ .f16 = @ceil(val.toFloat(f16, zcu)) },
3532 32 => .{ .f32 = @ceil(val.toFloat(f32, zcu)) },
3533 64 => .{ .f64 = @ceil(val.toFloat(f64, zcu)) },
3534 80 => .{ .f80 = @ceil(val.toFloat(f80, zcu)) },
3535 128 => .{ .f128 = @ceil(val.toFloat(f128, zcu)) },
34813536 else => unreachable,
34823537 };
34833538 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3487,10 +3542,10 @@ pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
34873542}
34883543
34893544pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3490 const mod = pt.zcu;
3491 if (float_type.zigTypeTag(mod) == .Vector) {
3492 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3493 const scalar_ty = float_type.scalarType(mod);
3545 const zcu = pt.zcu;
3546 if (float_type.zigTypeTag(zcu) == .Vector) {
3547 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3548 const scalar_ty = float_type.scalarType(zcu);
34943549 for (result_data, 0..) |*scalar, i| {
34953550 const elem_val = try val.elemValue(pt, i);
34963551 scalar.* = (try roundScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3504,14 +3559,14 @@ pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
35043559}
35053560
35063561pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3507 const mod = pt.zcu;
3508 const target = mod.getTarget();
3562 const zcu = pt.zcu;
3563 const target = zcu.getTarget();
35093564 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3510 16 => .{ .f16 = @round(val.toFloat(f16, pt)) },
3511 32 => .{ .f32 = @round(val.toFloat(f32, pt)) },
3512 64 => .{ .f64 = @round(val.toFloat(f64, pt)) },
3513 80 => .{ .f80 = @round(val.toFloat(f80, pt)) },
3514 128 => .{ .f128 = @round(val.toFloat(f128, pt)) },
3565 16 => .{ .f16 = @round(val.toFloat(f16, zcu)) },
3566 32 => .{ .f32 = @round(val.toFloat(f32, zcu)) },
3567 64 => .{ .f64 = @round(val.toFloat(f64, zcu)) },
3568 80 => .{ .f80 = @round(val.toFloat(f80, zcu)) },
3569 128 => .{ .f128 = @round(val.toFloat(f128, zcu)) },
35153570 else => unreachable,
35163571 };
35173572 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3521,10 +3576,10 @@ pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
35213576}
35223577
35233578pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3524 const mod = pt.zcu;
3525 if (float_type.zigTypeTag(mod) == .Vector) {
3526 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3527 const scalar_ty = float_type.scalarType(mod);
3579 const zcu = pt.zcu;
3580 if (float_type.zigTypeTag(zcu) == .Vector) {
3581 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3582 const scalar_ty = float_type.scalarType(zcu);
35283583 for (result_data, 0..) |*scalar, i| {
35293584 const elem_val = try val.elemValue(pt, i);
35303585 scalar.* = (try truncScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3538,14 +3593,14 @@ pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
35383593}
35393594
35403595pub fn truncScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3541 const mod = pt.zcu;
3542 const target = mod.getTarget();
3596 const zcu = pt.zcu;
3597 const target = zcu.getTarget();
35433598 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3544 16 => .{ .f16 = @trunc(val.toFloat(f16, pt)) },
3545 32 => .{ .f32 = @trunc(val.toFloat(f32, pt)) },
3546 64 => .{ .f64 = @trunc(val.toFloat(f64, pt)) },
3547 80 => .{ .f80 = @trunc(val.toFloat(f80, pt)) },
3548 128 => .{ .f128 = @trunc(val.toFloat(f128, pt)) },
3599 16 => .{ .f16 = @trunc(val.toFloat(f16, zcu)) },
3600 32 => .{ .f32 = @trunc(val.toFloat(f32, zcu)) },
3601 64 => .{ .f64 = @trunc(val.toFloat(f64, zcu)) },
3602 80 => .{ .f80 = @trunc(val.toFloat(f80, zcu)) },
3603 128 => .{ .f128 = @trunc(val.toFloat(f128, zcu)) },
35493604 else => unreachable,
35503605 };
35513606 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3562,10 +3617,10 @@ pub fn mulAdd(
35623617 arena: Allocator,
35633618 pt: Zcu.PerThread,
35643619) !Value {
3565 const mod = pt.zcu;
3566 if (float_type.zigTypeTag(mod) == .Vector) {
3567 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3568 const scalar_ty = float_type.scalarType(mod);
3620 const zcu = pt.zcu;
3621 if (float_type.zigTypeTag(zcu) == .Vector) {
3622 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3623 const scalar_ty = float_type.scalarType(zcu);
35693624 for (result_data, 0..) |*scalar, i| {
35703625 const mulend1_elem = try mulend1.elemValue(pt, i);
35713626 const mulend2_elem = try mulend2.elemValue(pt, i);
......@@ -3587,14 +3642,14 @@ pub fn mulAddScalar(
35873642 addend: Value,
35883643 pt: Zcu.PerThread,
35893644) Allocator.Error!Value {
3590 const mod = pt.zcu;
3591 const target = mod.getTarget();
3645 const zcu = pt.zcu;
3646 const target = zcu.getTarget();
35923647 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3593 16 => .{ .f16 = @mulAdd(f16, mulend1.toFloat(f16, pt), mulend2.toFloat(f16, pt), addend.toFloat(f16, pt)) },
3594 32 => .{ .f32 = @mulAdd(f32, mulend1.toFloat(f32, pt), mulend2.toFloat(f32, pt), addend.toFloat(f32, pt)) },
3595 64 => .{ .f64 = @mulAdd(f64, mulend1.toFloat(f64, pt), mulend2.toFloat(f64, pt), addend.toFloat(f64, pt)) },
3596 80 => .{ .f80 = @mulAdd(f80, mulend1.toFloat(f80, pt), mulend2.toFloat(f80, pt), addend.toFloat(f80, pt)) },
3597 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, pt), mulend2.toFloat(f128, pt), addend.toFloat(f128, pt)) },
3648 16 => .{ .f16 = @mulAdd(f16, mulend1.toFloat(f16, zcu), mulend2.toFloat(f16, zcu), addend.toFloat(f16, zcu)) },
3649 32 => .{ .f32 = @mulAdd(f32, mulend1.toFloat(f32, zcu), mulend2.toFloat(f32, zcu), addend.toFloat(f32, zcu)) },
3650 64 => .{ .f64 = @mulAdd(f64, mulend1.toFloat(f64, zcu), mulend2.toFloat(f64, zcu), addend.toFloat(f64, zcu)) },
3651 80 => .{ .f80 = @mulAdd(f80, mulend1.toFloat(f80, zcu), mulend2.toFloat(f80, zcu), addend.toFloat(f80, zcu)) },
3652 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, zcu), mulend2.toFloat(f128, zcu), addend.toFloat(f128, zcu)) },
35983653 else => unreachable,
35993654 };
36003655 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3606,10 +3661,11 @@ pub fn mulAddScalar(
36063661/// If the value is represented in-memory as a series of bytes that all
36073662/// have the same value, return that byte value, otherwise null.
36083663pub fn hasRepeatedByteRepr(val: Value, ty: Type, pt: Zcu.PerThread) !?u8 {
3609 const abi_size = std.math.cast(usize, ty.abiSize(pt)) orelse return null;
3664 const zcu = pt.zcu;
3665 const abi_size = std.math.cast(usize, ty.abiSize(zcu)) orelse return null;
36103666 assert(abi_size >= 1);
3611 const byte_buffer = try pt.zcu.gpa.alloc(u8, abi_size);
3612 defer pt.zcu.gpa.free(byte_buffer);
3667 const byte_buffer = try zcu.gpa.alloc(u8, abi_size);
3668 defer zcu.gpa.free(byte_buffer);
36133669
36143670 writeToMemory(val, ty, pt, byte_buffer) catch |err| switch (err) {
36153671 error.OutOfMemory => return error.OutOfMemory,
......@@ -3756,13 +3812,13 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
37563812 .Struct => field: {
37573813 const field_ty = aggregate_ty.structFieldType(field_idx, zcu);
37583814 switch (aggregate_ty.containerLayout(zcu)) {
3759 .auto => break :field .{ field_ty, try aggregate_ty.structFieldAlignAdvanced(@intCast(field_idx), pt, .sema) },
3815 .auto => break :field .{ field_ty, try aggregate_ty.structFieldAlignAdvanced(@intCast(field_idx), .sema, zcu, pt.tid) },
37603816 .@"extern" => {
37613817 // Well-defined layout, so just offset the pointer appropriately.
3762 const byte_off = aggregate_ty.structFieldOffset(field_idx, pt);
3818 const byte_off = aggregate_ty.structFieldOffset(field_idx, zcu);
37633819 const field_align = a: {
37643820 const parent_align = if (parent_ptr_info.flags.alignment == .none) pa: {
3765 break :pa (try aggregate_ty.abiAlignmentAdvanced(pt, .sema)).scalar;
3821 break :pa try aggregate_ty.abiAlignmentSema(pt);
37663822 } else parent_ptr_info.flags.alignment;
37673823 break :a InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(byte_off)));
37683824 };
......@@ -3781,7 +3837,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
37813837 new.packed_offset = packed_offset;
37823838 new.child = field_ty.toIntern();
37833839 if (new.flags.alignment == .none) {
3784 new.flags.alignment = (try aggregate_ty.abiAlignmentAdvanced(pt, .sema)).scalar;
3840 new.flags.alignment = try aggregate_ty.abiAlignmentSema(pt);
37853841 }
37863842 break :info new;
37873843 });
......@@ -3807,7 +3863,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38073863 const union_obj = zcu.typeToUnion(aggregate_ty).?;
38083864 const field_ty = Type.fromInterned(union_obj.field_types.get(&zcu.intern_pool)[field_idx]);
38093865 switch (aggregate_ty.containerLayout(zcu)) {
3810 .auto => break :field .{ field_ty, try aggregate_ty.structFieldAlignAdvanced(@intCast(field_idx), pt, .sema) },
3866 .auto => break :field .{ field_ty, try aggregate_ty.structFieldAlignAdvanced(@intCast(field_idx), .sema, zcu, pt.tid) },
38113867 .@"extern" => {
38123868 // Point to the same address.
38133869 const result_ty = try pt.ptrTypeSema(info: {
......@@ -3820,17 +3876,17 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38203876 .@"packed" => {
38213877 // If the field has an ABI size matching its bit size, then we can continue to use a
38223878 // non-bit pointer if the parent pointer is also a non-bit pointer.
3823 if (parent_ptr_info.packed_offset.host_size == 0 and (try field_ty.abiSizeAdvanced(pt, .sema)).scalar * 8 == try field_ty.bitSizeAdvanced(pt, .sema)) {
3879 if (parent_ptr_info.packed_offset.host_size == 0 and (try field_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar * 8 == try field_ty.bitSizeSema(pt)) {
38243880 // We must offset the pointer on big-endian targets, since the bits of packed memory don't align nicely.
38253881 const byte_offset = switch (zcu.getTarget().cpu.arch.endian()) {
38263882 .little => 0,
3827 .big => (try aggregate_ty.abiSizeAdvanced(pt, .sema)).scalar - (try field_ty.abiSizeAdvanced(pt, .sema)).scalar,
3883 .big => (try aggregate_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar - (try field_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar,
38283884 };
38293885 const result_ty = try pt.ptrTypeSema(info: {
38303886 var new = parent_ptr_info;
38313887 new.child = field_ty.toIntern();
38323888 new.flags.alignment = InternPool.Alignment.fromLog2Units(
3833 @ctz(byte_offset | (try parent_ptr_ty.ptrAlignmentAdvanced(pt, .sema)).toByteUnits().?),
3889 @ctz(byte_offset | (try parent_ptr_ty.ptrAlignmentSema(pt)).toByteUnits().?),
38343890 );
38353891 break :info new;
38363892 });
......@@ -3841,7 +3897,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38413897 var new = parent_ptr_info;
38423898 new.child = field_ty.toIntern();
38433899 if (new.packed_offset.host_size == 0) {
3844 new.packed_offset.host_size = @intCast(((try aggregate_ty.bitSizeAdvanced(pt, .sema)) + 7) / 8);
3900 new.packed_offset.host_size = @intCast(((try aggregate_ty.bitSizeSema(pt)) + 7) / 8);
38453901 assert(new.packed_offset.bit_offset == 0);
38463902 }
38473903 break :info new;
......@@ -3854,8 +3910,8 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38543910 .Pointer => field_ty: {
38553911 assert(aggregate_ty.isSlice(zcu));
38563912 break :field_ty switch (field_idx) {
3857 Value.slice_ptr_index => .{ aggregate_ty.slicePtrFieldType(zcu), Type.usize.abiAlignment(pt) },
3858 Value.slice_len_index => .{ Type.usize, Type.usize.abiAlignment(pt) },
3913 Value.slice_ptr_index => .{ aggregate_ty.slicePtrFieldType(zcu), Type.usize.abiAlignment(zcu) },
3914 Value.slice_len_index => .{ Type.usize, Type.usize.abiAlignment(zcu) },
38593915 else => unreachable,
38603916 };
38613917 },
......@@ -3863,7 +3919,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38633919 };
38643920
38653921 const new_align: InternPool.Alignment = if (parent_ptr_info.flags.alignment != .none) a: {
3866 const ty_align = (try field_ty.abiAlignmentAdvanced(pt, .sema)).scalar;
3922 const ty_align = (try field_ty.abiAlignmentInner(.sema, zcu, pt.tid)).scalar;
38673923 const true_field_align = if (field_align == .none) ty_align else field_align;
38683924 const new_align = true_field_align.min(parent_ptr_info.flags.alignment);
38693925 if (new_align == ty_align) break :a .none;
......@@ -3919,21 +3975,21 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value
39193975
39203976 const strat: PtrStrat = switch (parent_ptr_ty.ptrSize(zcu)) {
39213977 .One => switch (elem_ty.zigTypeTag(zcu)) {
3922 .Vector => .{ .offset = field_idx * @divExact(try elem_ty.childType(zcu).bitSizeAdvanced(pt, .sema), 8) },
3978 .Vector => .{ .offset = field_idx * @divExact(try elem_ty.childType(zcu).bitSizeSema(pt), 8) },
39233979 .Array => strat: {
39243980 const arr_elem_ty = elem_ty.childType(zcu);
3925 if (try arr_elem_ty.comptimeOnlyAdvanced(pt, .sema)) {
3981 if (try arr_elem_ty.comptimeOnlySema(pt)) {
39263982 break :strat .{ .elem_ptr = arr_elem_ty };
39273983 }
3928 break :strat .{ .offset = field_idx * (try arr_elem_ty.abiSizeAdvanced(pt, .sema)).scalar };
3984 break :strat .{ .offset = field_idx * (try arr_elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar };
39293985 },
39303986 else => unreachable,
39313987 },
39323988
3933 .Many, .C => if (try elem_ty.comptimeOnlyAdvanced(pt, .sema))
3989 .Many, .C => if (try elem_ty.comptimeOnlySema(pt))
39343990 .{ .elem_ptr = elem_ty }
39353991 else
3936 .{ .offset = field_idx * (try elem_ty.abiSizeAdvanced(pt, .sema)).scalar },
3992 .{ .offset = field_idx * (try elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar },
39373993
39383994 .Slice => unreachable,
39393995 };
......@@ -4142,22 +4198,32 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
41424198 const base_ptr_ty = base_ptr.typeOf(zcu);
41434199 const agg_ty = base_ptr_ty.childType(zcu);
41444200 const field_ty, const field_align = switch (agg_ty.zigTypeTag(zcu)) {
4145 .Struct => .{ agg_ty.structFieldType(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, if (have_sema) .sema else .normal) },
4146 .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, if (have_sema) .sema else .normal) },
4201 .Struct => .{ agg_ty.structFieldType(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(
4202 @intCast(field.index),
4203 if (have_sema) .sema else .normal,
4204 pt.zcu,
4205 if (have_sema) pt.tid else {},
4206 ) },
4207 .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(
4208 @intCast(field.index),
4209 if (have_sema) .sema else .normal,
4210 pt.zcu,
4211 if (have_sema) pt.tid else {},
4212 ) },
41474213 .Pointer => .{ switch (field.index) {
41484214 Value.slice_ptr_index => agg_ty.slicePtrFieldType(zcu),
41494215 Value.slice_len_index => Type.usize,
41504216 else => unreachable,
4151 }, Type.usize.abiAlignment(pt) },
4217 }, Type.usize.abiAlignment(zcu) },
41524218 else => unreachable,
41534219 };
4154 const base_align = base_ptr_ty.ptrAlignment(pt);
4220 const base_align = base_ptr_ty.ptrAlignment(zcu);
41554221 const result_align = field_align.minStrict(base_align);
41564222 const result_ty = try pt.ptrType(.{
41574223 .child = field_ty.toIntern(),
41584224 .flags = flags: {
41594225 var flags = base_ptr_ty.ptrInfo(zcu).flags;
4160 if (result_align == field_ty.abiAlignment(pt)) {
4226 if (result_align == field_ty.abiAlignment(zcu)) {
41614227 flags.alignment = .none;
41624228 } else {
41634229 flags.alignment = result_align;
......@@ -4198,7 +4264,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
41984264 }
41994265
42004266 const need_child = Type.fromInterned(ptr.ty).childType(zcu);
4201 if (need_child.comptimeOnly(pt)) {
4267 if (need_child.comptimeOnly(zcu)) {
42024268 // No refinement can happen - this pointer is presumably invalid.
42034269 // Just offset it.
42044270 const parent = try arena.create(PointerDeriveStep);
......@@ -4209,7 +4275,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42094275 .new_ptr_ty = Type.fromInterned(ptr.ty),
42104276 } };
42114277 }
4212 const need_bytes = need_child.abiSize(pt);
4278 const need_bytes = need_child.abiSize(zcu);
42134279
42144280 var cur_derive = base_derive;
42154281 var cur_offset = ptr.byte_offset;
......@@ -4248,7 +4314,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42484314
42494315 .Array => {
42504316 const elem_ty = cur_ty.childType(zcu);
4251 const elem_size = elem_ty.abiSize(pt);
4317 const elem_size = elem_ty.abiSize(zcu);
42524318 const start_idx = cur_offset / elem_size;
42534319 const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;
42544320 if (end_idx == start_idx + 1) {
......@@ -4279,11 +4345,11 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42794345 .auto, .@"packed" => break,
42804346 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
42814347 const field_ty = cur_ty.structFieldType(field_idx, zcu);
4282 const start_off = cur_ty.structFieldOffset(field_idx, pt);
4283 const end_off = start_off + field_ty.abiSize(pt);
4348 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
4349 const end_off = start_off + field_ty.abiSize(zcu);
42844350 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
42854351 const old_ptr_ty = try cur_derive.ptrType(pt);
4286 const parent_align = old_ptr_ty.ptrAlignment(pt);
4352 const parent_align = old_ptr_ty.ptrAlignment(zcu);
42874353 const field_align = InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(start_off)));
42884354 const parent = try arena.create(PointerDeriveStep);
42894355 parent.* = cur_derive;
......@@ -4291,7 +4357,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42914357 .child = field_ty.toIntern(),
42924358 .flags = flags: {
42934359 var flags = old_ptr_ty.ptrInfo(zcu).flags;
4294 if (field_align == field_ty.abiAlignment(pt)) {
4360 if (field_align == field_ty.abiAlignment(zcu)) {
42954361 flags.alignment = .none;
42964362 } else {
42974363 flags.alignment = field_align;
......@@ -4325,13 +4391,17 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
43254391 } };
43264392}
43274393
4328pub fn resolveLazy(val: Value, arena: Allocator, pt: Zcu.PerThread) Zcu.SemaError!Value {
4394pub fn resolveLazy(
4395 val: Value,
4396 arena: Allocator,
4397 pt: Zcu.PerThread,
4398) Zcu.SemaError!Value {
43294399 switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
43304400 .int => |int| switch (int.storage) {
43314401 .u64, .i64, .big_int => return val,
43324402 .lazy_align, .lazy_size => return pt.intValue(
43334403 Type.fromInterned(int.ty),
4334 (try val.getUnsignedIntAdvanced(pt, .sema)).?,
4404 (try val.getUnsignedIntInner(.sema, pt.zcu, pt.tid)).?,
43354405 ),
43364406 },
43374407 .slice => |slice| {
src/Zcu.zig+35-35
......@@ -2109,9 +2109,9 @@ pub const CompileError = error{
21092109 ComptimeBreak,
21102110};
21112111
2112pub fn init(mod: *Zcu, thread_count: usize) !void {
2113 const gpa = mod.gpa;
2114 try mod.intern_pool.init(gpa, thread_count);
2112pub fn init(zcu: *Zcu, thread_count: usize) !void {
2113 const gpa = zcu.gpa;
2114 try zcu.intern_pool.init(gpa, thread_count);
21152115}
21162116
21172117pub fn deinit(zcu: *Zcu) void {
......@@ -2204,8 +2204,8 @@ pub fn namespacePtr(zcu: *Zcu, index: Namespace.Index) *Namespace {
22042204 return zcu.intern_pool.namespacePtr(index);
22052205}
22062206
2207pub fn namespacePtrUnwrap(mod: *Zcu, index: Namespace.OptionalIndex) ?*Namespace {
2208 return mod.namespacePtr(index.unwrap() orelse return null);
2207pub fn namespacePtrUnwrap(zcu: *Zcu, index: Namespace.OptionalIndex) ?*Namespace {
2208 return zcu.namespacePtr(index.unwrap() orelse return null);
22092209}
22102210
22112211// TODO https://github.com/ziglang/zig/issues/8643
......@@ -2682,7 +2682,7 @@ pub fn mapOldZirToNew(
26822682///
26832683/// The caller is responsible for ensuring the function decl itself is already
26842684/// analyzed, and for ensuring it can exist at runtime (see
2685/// `sema.fnHasRuntimeBits`). This function does *not* guarantee that the body
2685/// `Type.fnHasRuntimeBitsSema`). This function does *not* guarantee that the body
26862686/// will be analyzed when it returns: for that, see `ensureFuncBodyAnalyzed`.
26872687pub fn ensureFuncBodyAnalysisQueued(zcu: *Zcu, func_index: InternPool.Index) !void {
26882688 const ip = &zcu.intern_pool;
......@@ -2846,16 +2846,16 @@ pub fn errorSetBits(mod: *Zcu) u16 {
28462846}
28472847
28482848pub fn errNote(
2849 mod: *Zcu,
2849 zcu: *Zcu,
28502850 src_loc: LazySrcLoc,
28512851 parent: *ErrorMsg,
28522852 comptime format: []const u8,
28532853 args: anytype,
28542854) error{OutOfMemory}!void {
2855 const msg = try std.fmt.allocPrint(mod.gpa, format, args);
2856 errdefer mod.gpa.free(msg);
2855 const msg = try std.fmt.allocPrint(zcu.gpa, format, args);
2856 errdefer zcu.gpa.free(msg);
28572857
2858 parent.notes = try mod.gpa.realloc(parent.notes, parent.notes.len + 1);
2858 parent.notes = try zcu.gpa.realloc(parent.notes, parent.notes.len + 1);
28592859 parent.notes[parent.notes.len - 1] = .{
28602860 .src_loc = src_loc,
28612861 .msg = msg,
......@@ -2876,14 +2876,14 @@ pub fn optimizeMode(zcu: *const Zcu) std.builtin.OptimizeMode {
28762876 return zcu.root_mod.optimize_mode;
28772877}
28782878
2879fn lockAndClearFileCompileError(mod: *Zcu, file: *File) void {
2879fn lockAndClearFileCompileError(zcu: *Zcu, file: *File) void {
28802880 switch (file.status) {
28812881 .success_zir, .retryable_failure => {},
28822882 .never_loaded, .parse_failure, .astgen_failure => {
2883 mod.comp.mutex.lock();
2884 defer mod.comp.mutex.unlock();
2885 if (mod.failed_files.fetchSwapRemove(file)) |kv| {
2886 if (kv.value) |msg| msg.destroy(mod.gpa); // Delete previous error message.
2883 zcu.comp.mutex.lock();
2884 defer zcu.comp.mutex.unlock();
2885 if (zcu.failed_files.fetchSwapRemove(file)) |kv| {
2886 if (kv.value) |msg| msg.destroy(zcu.gpa); // Delete previous error message.
28872887 }
28882888 },
28892889 }
......@@ -2965,11 +2965,11 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
29652965// TODO this function does not take into account CPU features, which can affect
29662966// this value. Audit this!
29672967pub fn atomicPtrAlignment(
2968 mod: *Zcu,
2968 zcu: *Zcu,
29692969 ty: Type,
29702970 diags: *AtomicPtrAlignmentDiagnostics,
29712971) AtomicPtrAlignmentError!Alignment {
2972 const target = mod.getTarget();
2972 const target = zcu.getTarget();
29732973 const max_atomic_bits: u16 = switch (target.cpu.arch) {
29742974 .avr,
29752975 .msp430,
......@@ -3039,8 +3039,8 @@ pub fn atomicPtrAlignment(
30393039 }
30403040 return .none;
30413041 }
3042 if (ty.isAbiInt(mod)) {
3043 const bit_count = ty.intInfo(mod).bits;
3042 if (ty.isAbiInt(zcu)) {
3043 const bit_count = ty.intInfo(zcu).bits;
30443044 if (bit_count > max_atomic_bits) {
30453045 diags.* = .{
30463046 .bits = bit_count,
......@@ -3050,7 +3050,7 @@ pub fn atomicPtrAlignment(
30503050 }
30513051 return .none;
30523052 }
3053 if (ty.isPtrAtRuntime(mod)) return .none;
3053 if (ty.isPtrAtRuntime(zcu)) return .none;
30543054 return error.BadType;
30553055}
30563056
......@@ -3058,45 +3058,45 @@ pub fn atomicPtrAlignment(
30583058/// * `@TypeOf(.{})`
30593059/// * A struct which has no fields (`struct {}`).
30603060/// * Not a struct.
3061pub fn typeToStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3061pub fn typeToStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {
30623062 if (ty.ip_index == .none) return null;
3063 const ip = &mod.intern_pool;
3063 const ip = &zcu.intern_pool;
30643064 return switch (ip.indexToKey(ty.ip_index)) {
30653065 .struct_type => ip.loadStructType(ty.ip_index),
30663066 else => null,
30673067 };
30683068}
30693069
3070pub fn typeToPackedStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3071 const s = mod.typeToStruct(ty) orelse return null;
3070pub fn typeToPackedStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3071 const s = zcu.typeToStruct(ty) orelse return null;
30723072 if (s.layout != .@"packed") return null;
30733073 return s;
30743074}
30753075
3076pub fn typeToUnion(mod: *Zcu, ty: Type) ?InternPool.LoadedUnionType {
3076pub fn typeToUnion(zcu: *const Zcu, ty: Type) ?InternPool.LoadedUnionType {
30773077 if (ty.ip_index == .none) return null;
3078 const ip = &mod.intern_pool;
3078 const ip = &zcu.intern_pool;
30793079 return switch (ip.indexToKey(ty.ip_index)) {
30803080 .union_type => ip.loadUnionType(ty.ip_index),
30813081 else => null,
30823082 };
30833083}
30843084
3085pub fn typeToFunc(mod: *Zcu, ty: Type) ?InternPool.Key.FuncType {
3085pub fn typeToFunc(zcu: *const Zcu, ty: Type) ?InternPool.Key.FuncType {
30863086 if (ty.ip_index == .none) return null;
3087 return mod.intern_pool.indexToFuncType(ty.toIntern());
3087 return zcu.intern_pool.indexToFuncType(ty.toIntern());
30883088}
30893089
30903090pub fn iesFuncIndex(zcu: *const Zcu, ies_index: InternPool.Index) InternPool.Index {
30913091 return zcu.intern_pool.iesFuncIndex(ies_index);
30923092}
30933093
3094pub fn funcInfo(mod: *Zcu, func_index: InternPool.Index) InternPool.Key.Func {
3095 return mod.intern_pool.indexToKey(func_index).func;
3094pub fn funcInfo(zcu: *const Zcu, func_index: InternPool.Index) InternPool.Key.Func {
3095 return zcu.intern_pool.indexToKey(func_index).func;
30963096}
30973097
3098pub fn toEnum(mod: *Zcu, comptime E: type, val: Value) E {
3099 return mod.intern_pool.toEnum(E, val.toIntern());
3098pub fn toEnum(zcu: *const Zcu, comptime E: type, val: Value) E {
3099 return zcu.intern_pool.toEnum(E, val.toIntern());
31003100}
31013101
31023102pub const UnionLayout = struct {
......@@ -3121,8 +3121,8 @@ pub const UnionLayout = struct {
31213121};
31223122
31233123/// Returns the index of the active field, given the current tag value
3124pub fn unionTagFieldIndex(mod: *Zcu, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
3125 const ip = &mod.intern_pool;
3124pub fn unionTagFieldIndex(zcu: *const Zcu, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
3125 const ip = &zcu.intern_pool;
31263126 if (enum_tag.toIntern() == .none) return null;
31273127 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);
31283128 return loaded_union.loadTagType(ip).tagValueIndex(ip, enum_tag.toIntern());
......@@ -3348,7 +3348,7 @@ pub fn resolveReferences(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolve
33483348 return result;
33493349}
33503350
3351pub fn fileByIndex(zcu: *Zcu, file_index: File.Index) *File {
3351pub fn fileByIndex(zcu: *const Zcu, file_index: File.Index) *File {
33523352 return zcu.intern_pool.filePtr(file_index);
33533353}
33543354
src/Zcu/PerThread.zig+27-135
......@@ -2756,7 +2756,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!
27562756 // pointee type needs to be resolved more, that needs to be done before calling
27572757 // this ptr() function.
27582758 if (info.flags.alignment != .none and
2759 info.flags.alignment == Type.fromInterned(info.child).abiAlignment(pt))
2759 info.flags.alignment == Type.fromInterned(info.child).abiAlignment(pt.zcu))
27602760 {
27612761 canon_info.flags.alignment = .none;
27622762 }
......@@ -2766,7 +2766,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!
27662766 // we change it to 0 here. If this causes an assertion trip, the pointee type
27672767 // needs to be resolved before calling this ptr() function.
27682768 .none => if (info.packed_offset.host_size != 0) {
2769 const elem_bit_size = Type.fromInterned(info.child).bitSize(pt);
2769 const elem_bit_size = Type.fromInterned(info.child).bitSize(pt.zcu);
27702770 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);
27712771 if (info.packed_offset.host_size * 8 == elem_bit_size) {
27722772 canon_info.packed_offset.host_size = 0;
......@@ -2784,7 +2784,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!
27842784/// In general, prefer this function during semantic analysis.
27852785pub fn ptrTypeSema(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Zcu.SemaError!Type {
27862786 if (info.flags.alignment != .none) {
2787 _ = try Type.fromInterned(info.child).abiAlignmentAdvanced(pt, .sema);
2787 _ = try Type.fromInterned(info.child).abiAlignmentSema(pt);
27882788 }
27892789 return pt.ptrType(info);
27902790}
......@@ -2984,15 +2984,15 @@ pub fn smallestUnsignedInt(pt: Zcu.PerThread, max: u64) Allocator.Error!Type {
29842984/// `max`. Asserts that neither value is undef.
29852985/// TODO: if #3806 is implemented, this becomes trivial
29862986pub fn intFittingRange(pt: Zcu.PerThread, min: Value, max: Value) !Type {
2987 const mod = pt.zcu;
2988 assert(!min.isUndef(mod));
2989 assert(!max.isUndef(mod));
2987 const zcu = pt.zcu;
2988 assert(!min.isUndef(zcu));
2989 assert(!max.isUndef(zcu));
29902990
29912991 if (std.debug.runtime_safety) {
2992 assert(Value.order(min, max, pt).compare(.lte));
2992 assert(Value.order(min, max, zcu).compare(.lte));
29932993 }
29942994
2995 const sign = min.orderAgainstZero(pt) == .lt;
2995 const sign = min.orderAgainstZero(zcu) == .lt;
29962996
29972997 const min_val_bits = pt.intBitsForValue(min, sign);
29982998 const max_val_bits = pt.intBitsForValue(max, sign);
......@@ -3032,120 +3032,30 @@ pub fn intBitsForValue(pt: Zcu.PerThread, val: Value, sign: bool) u16 {
30323032 return @as(u16, @intCast(big.bitCountTwosComp()));
30333033 },
30343034 .lazy_align => |lazy_ty| {
3035 return Type.smallestUnsignedBits(Type.fromInterned(lazy_ty).abiAlignment(pt).toByteUnits() orelse 0) + @intFromBool(sign);
3035 return Type.smallestUnsignedBits(Type.fromInterned(lazy_ty).abiAlignment(pt.zcu).toByteUnits() orelse 0) + @intFromBool(sign);
30363036 },
30373037 .lazy_size => |lazy_ty| {
3038 return Type.smallestUnsignedBits(Type.fromInterned(lazy_ty).abiSize(pt)) + @intFromBool(sign);
3038 return Type.smallestUnsignedBits(Type.fromInterned(lazy_ty).abiSize(pt.zcu)) + @intFromBool(sign);
30393039 },
30403040 }
30413041}
30423042
3043pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionType) Zcu.UnionLayout {
3044 const mod = pt.zcu;
3045 const ip = &mod.intern_pool;
3046 assert(loaded_union.haveLayout(ip));
3047 var most_aligned_field: u32 = undefined;
3048 var most_aligned_field_size: u64 = undefined;
3049 var biggest_field: u32 = undefined;
3050 var payload_size: u64 = 0;
3051 var payload_align: InternPool.Alignment = .@"1";
3052 for (loaded_union.field_types.get(ip), 0..) |field_ty, field_index| {
3053 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
3054
3055 const explicit_align = loaded_union.fieldAlign(ip, field_index);
3056 const field_align = if (explicit_align != .none)
3057 explicit_align
3058 else
3059 Type.fromInterned(field_ty).abiAlignment(pt);
3060 const field_size = Type.fromInterned(field_ty).abiSize(pt);
3061 if (field_size > payload_size) {
3062 payload_size = field_size;
3063 biggest_field = @intCast(field_index);
3064 }
3065 if (field_align.compare(.gte, payload_align)) {
3066 payload_align = field_align;
3067 most_aligned_field = @intCast(field_index);
3068 most_aligned_field_size = field_size;
3069 }
3070 }
3071 const have_tag = loaded_union.flagsUnordered(ip).runtime_tag.hasTag();
3072 if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(pt)) {
3073 return .{
3074 .abi_size = payload_align.forward(payload_size),
3075 .abi_align = payload_align,
3076 .most_aligned_field = most_aligned_field,
3077 .most_aligned_field_size = most_aligned_field_size,
3078 .biggest_field = biggest_field,
3079 .payload_size = payload_size,
3080 .payload_align = payload_align,
3081 .tag_align = .none,
3082 .tag_size = 0,
3083 .padding = 0,
3084 };
3085 }
3086
3087 const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(pt);
3088 const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(pt).max(.@"1");
3089 return .{
3090 .abi_size = loaded_union.sizeUnordered(ip),
3091 .abi_align = tag_align.max(payload_align),
3092 .most_aligned_field = most_aligned_field,
3093 .most_aligned_field_size = most_aligned_field_size,
3094 .biggest_field = biggest_field,
3095 .payload_size = payload_size,
3096 .payload_align = payload_align,
3097 .tag_align = tag_align,
3098 .tag_size = tag_size,
3099 .padding = loaded_union.paddingUnordered(ip),
3100 };
3101}
3102
3103pub fn unionAbiSize(mod: *Module, loaded_union: InternPool.LoadedUnionType) u64 {
3104 return mod.getUnionLayout(loaded_union).abi_size;
3105}
3106
31073043/// Returns 0 if the union is represented with 0 bits at runtime.
31083044pub fn unionAbiAlignment(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionType) InternPool.Alignment {
3109 const mod = pt.zcu;
3110 const ip = &mod.intern_pool;
3045 const zcu = pt.zcu;
3046 const ip = &zcu.intern_pool;
31113047 const have_tag = loaded_union.flagsPtr(ip).runtime_tag.hasTag();
31123048 var max_align: InternPool.Alignment = .none;
3113 if (have_tag) max_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(pt);
3049 if (have_tag) max_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(zcu);
31143050 for (loaded_union.field_types.get(ip), 0..) |field_ty, field_index| {
3115 if (!Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
3051 if (!Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
31163052
3117 const field_align = mod.unionFieldNormalAlignment(loaded_union, @intCast(field_index));
3053 const field_align = zcu.unionFieldNormalAlignment(loaded_union, @intCast(field_index));
31183054 max_align = max_align.max(field_align);
31193055 }
31203056 return max_align;
31213057}
31223058
3123/// Returns the field alignment of a non-packed union. Asserts the layout is not packed.
3124pub fn unionFieldNormalAlignment(
3125 pt: Zcu.PerThread,
3126 loaded_union: InternPool.LoadedUnionType,
3127 field_index: u32,
3128) InternPool.Alignment {
3129 return pt.unionFieldNormalAlignmentAdvanced(loaded_union, field_index, .normal) catch unreachable;
3130}
3131
3132/// Returns the field alignment of a non-packed union. Asserts the layout is not packed.
3133/// If `strat` is `.sema`, may perform type resolution.
3134pub fn unionFieldNormalAlignmentAdvanced(
3135 pt: Zcu.PerThread,
3136 loaded_union: InternPool.LoadedUnionType,
3137 field_index: u32,
3138 comptime strat: Type.ResolveStrat,
3139) Zcu.SemaError!InternPool.Alignment {
3140 const ip = &pt.zcu.intern_pool;
3141 assert(loaded_union.flagsUnordered(ip).layout != .@"packed");
3142 const field_align = loaded_union.fieldAlign(ip, field_index);
3143 if (field_align != .none) return field_align;
3144 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
3145 if (field_ty.isNoReturn(pt.zcu)) return .none;
3146 return (try field_ty.abiAlignmentAdvanced(pt, strat.toLazy())).scalar;
3147}
3148
31493059/// Returns the field alignment of a non-packed struct. Asserts the layout is not packed.
31503060pub fn structFieldAlignment(
31513061 pt: Zcu.PerThread,
......@@ -3153,31 +3063,13 @@ pub fn structFieldAlignment(
31533063 field_ty: Type,
31543064 layout: std.builtin.Type.ContainerLayout,
31553065) InternPool.Alignment {
3156 return pt.structFieldAlignmentAdvanced(explicit_alignment, field_ty, layout, .normal) catch unreachable;
3157}
3158
3159/// Returns the field alignment of a non-packed struct. Asserts the layout is not packed.
3160/// If `strat` is `.sema`, may perform type resolution.
3161pub fn structFieldAlignmentAdvanced(
3162 pt: Zcu.PerThread,
3163 explicit_alignment: InternPool.Alignment,
3164 field_ty: Type,
3165 layout: std.builtin.Type.ContainerLayout,
3166 comptime strat: Type.ResolveStrat,
3167) Zcu.SemaError!InternPool.Alignment {
3168 assert(layout != .@"packed");
3169 if (explicit_alignment != .none) return explicit_alignment;
3170 const ty_abi_align = (try field_ty.abiAlignmentAdvanced(pt, strat.toLazy())).scalar;
3171 switch (layout) {
3172 .@"packed" => unreachable,
3173 .auto => if (pt.zcu.getTarget().ofmt != .c) return ty_abi_align,
3174 .@"extern" => {},
3175 }
3176 // extern
3177 if (field_ty.isAbiInt(pt.zcu) and field_ty.intInfo(pt.zcu).bits >= 128) {
3178 return ty_abi_align.maxStrict(.@"16");
3179 }
3180 return ty_abi_align;
3066 return field_ty.structFieldAlignmentAdvanced(
3067 explicit_alignment,
3068 layout,
3069 .normal,
3070 pt.zcu,
3071 {},
3072 ) catch unreachable;
31813073}
31823074
31833075/// https://github.com/ziglang/zig/issues/17178 explored storing these bit offsets
......@@ -3189,8 +3081,8 @@ pub fn structPackedFieldBitOffset(
31893081 struct_type: InternPool.LoadedStructType,
31903082 field_index: u32,
31913083) u16 {
3192 const mod = pt.zcu;
3193 const ip = &mod.intern_pool;
3084 const zcu = pt.zcu;
3085 const ip = &zcu.intern_pool;
31943086 assert(struct_type.layout == .@"packed");
31953087 assert(struct_type.haveLayout(ip));
31963088 var bit_sum: u64 = 0;
......@@ -3199,7 +3091,7 @@ pub fn structPackedFieldBitOffset(
31993091 return @intCast(bit_sum);
32003092 }
32013093 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3202 bit_sum += field_ty.bitSize(pt);
3094 bit_sum += field_ty.bitSize(zcu);
32033095 }
32043096 unreachable; // index out of bounds
32053097}
......@@ -3244,7 +3136,7 @@ pub fn navPtrType(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.
32443136 return pt.ptrType(.{
32453137 .child = ty.toIntern(),
32463138 .flags = .{
3247 .alignment = if (r.alignment == ty.abiAlignment(pt))
3139 .alignment = if (r.alignment == ty.abiAlignment(zcu))
32483140 .none
32493141 else
32503142 r.alignment,
......@@ -3274,7 +3166,7 @@ pub fn navAlignment(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) InternPo
32743166 const zcu = pt.zcu;
32753167 const r = zcu.intern_pool.getNav(nav_index).status.resolved;
32763168 if (r.alignment != .none) return r.alignment;
3277 return Value.fromInterned(r.val).typeOf(zcu).abiAlignment(pt);
3169 return Value.fromInterned(r.val).typeOf(zcu).abiAlignment(zcu);
32783170}
32793171
32803172/// Given a container type requiring resolution, ensures that it is up-to-date.
src/arch/aarch64/CodeGen.zig+261-260
......@@ -467,8 +467,8 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
467467
468468fn gen(self: *Self) !void {
469469 const pt = self.pt;
470 const mod = pt.zcu;
471 const cc = self.fn_type.fnCallingConvention(mod);
470 const zcu = pt.zcu;
471 const cc = self.fn_type.fnCallingConvention(zcu);
472472 if (cc != .Naked) {
473473 // stp fp, lr, [sp, #-16]!
474474 _ = try self.addInst(.{
......@@ -517,8 +517,8 @@ fn gen(self: *Self) !void {
517517
518518 const ty = self.typeOfIndex(inst);
519519
520 const abi_size = @as(u32, @intCast(ty.abiSize(pt)));
521 const abi_align = ty.abiAlignment(pt);
520 const abi_size = @as(u32, @intCast(ty.abiSize(zcu)));
521 const abi_align = ty.abiAlignment(zcu);
522522 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
523523 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
524524
......@@ -648,8 +648,8 @@ fn gen(self: *Self) !void {
648648
649649fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
650650 const pt = self.pt;
651 const mod = pt.zcu;
652 const ip = &mod.intern_pool;
651 const zcu = pt.zcu;
652 const ip = &zcu.intern_pool;
653653 const air_tags = self.air.instructions.items(.tag);
654654
655655 for (body) |inst| {
......@@ -1016,31 +1016,31 @@ fn allocMem(
10161016/// Use a pointer instruction as the basis for allocating stack memory.
10171017fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10181018 const pt = self.pt;
1019 const mod = pt.zcu;
1020 const elem_ty = self.typeOfIndex(inst).childType(mod);
1019 const zcu = pt.zcu;
1020 const elem_ty = self.typeOfIndex(inst).childType(zcu);
10211021
1022 if (!elem_ty.hasRuntimeBits(pt)) {
1022 if (!elem_ty.hasRuntimeBits(zcu)) {
10231023 // return the stack offset 0. Stack offset 0 will be where all
10241024 // zero-sized stack allocations live as non-zero-sized
10251025 // allocations will always have an offset > 0.
10261026 return @as(u32, 0);
10271027 }
10281028
1029 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
1029 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
10301030 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
10311031 };
10321032 // TODO swap this for inst.ty.ptrAlign
1033 const abi_align = elem_ty.abiAlignment(pt);
1033 const abi_align = elem_ty.abiAlignment(zcu);
10341034
10351035 return self.allocMem(abi_size, abi_align, inst);
10361036}
10371037
10381038fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst.Index) !MCValue {
10391039 const pt = self.pt;
1040 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
1040 const abi_size = math.cast(u32, elem_ty.abiSize(pt.zcu)) orelse {
10411041 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
10421042 };
1043 const abi_align = elem_ty.abiAlignment(pt);
1043 const abi_align = elem_ty.abiAlignment(pt.zcu);
10441044
10451045 if (reg_ok) {
10461046 // Make sure the type can fit in a register before we try to allocate one.
......@@ -1128,13 +1128,13 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
11281128
11291129fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
11301130 const pt = self.pt;
1131 const mod = pt.zcu;
1131 const zcu = pt.zcu;
11321132 const result: MCValue = switch (self.ret_mcv) {
11331133 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },
11341134 .stack_offset => blk: {
11351135 // self.ret_mcv is an address to where this function
11361136 // should store its result into
1137 const ret_ty = self.fn_type.fnReturnType(mod);
1137 const ret_ty = self.fn_type.fnReturnType(zcu);
11381138 const ptr_ty = try pt.singleMutPtrType(ret_ty);
11391139
11401140 // addr_reg will contain the address of where to store the
......@@ -1166,14 +1166,14 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
11661166 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
11671167
11681168 const pt = self.pt;
1169 const mod = pt.zcu;
1169 const zcu = pt.zcu;
11701170 const operand = ty_op.operand;
11711171 const operand_mcv = try self.resolveInst(operand);
11721172 const operand_ty = self.typeOf(operand);
1173 const operand_info = operand_ty.intInfo(mod);
1173 const operand_info = operand_ty.intInfo(zcu);
11741174
11751175 const dest_ty = self.typeOfIndex(inst);
1176 const dest_info = dest_ty.intInfo(mod);
1176 const dest_info = dest_ty.intInfo(zcu);
11771177
11781178 const result: MCValue = result: {
11791179 const operand_lock: ?RegisterLock = switch (operand_mcv) {
......@@ -1248,9 +1248,9 @@ fn trunc(
12481248 dest_ty: Type,
12491249) !MCValue {
12501250 const pt = self.pt;
1251 const mod = pt.zcu;
1252 const info_a = operand_ty.intInfo(mod);
1253 const info_b = dest_ty.intInfo(mod);
1251 const zcu = pt.zcu;
1252 const info_a = operand_ty.intInfo(zcu);
1253 const info_b = dest_ty.intInfo(zcu);
12541254
12551255 if (info_b.bits <= 64) {
12561256 const operand_reg = switch (operand) {
......@@ -1312,7 +1312,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
13121312fn airNot(self: *Self, inst: Air.Inst.Index) !void {
13131313 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
13141314 const pt = self.pt;
1315 const mod = pt.zcu;
1315 const zcu = pt.zcu;
13161316 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
13171317 const operand = try self.resolveInst(ty_op.operand);
13181318 const operand_ty = self.typeOf(ty_op.operand);
......@@ -1321,7 +1321,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
13211321 .unreach => unreachable,
13221322 .compare_flags => |cond| break :result MCValue{ .compare_flags = cond.negate() },
13231323 else => {
1324 switch (operand_ty.zigTypeTag(mod)) {
1324 switch (operand_ty.zigTypeTag(zcu)) {
13251325 .Bool => {
13261326 // TODO convert this to mvn + and
13271327 const op_reg = switch (operand) {
......@@ -1355,7 +1355,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
13551355 },
13561356 .Vector => return self.fail("TODO bitwise not for vectors", .{}),
13571357 .Int => {
1358 const int_info = operand_ty.intInfo(mod);
1358 const int_info = operand_ty.intInfo(zcu);
13591359 if (int_info.bits <= 64) {
13601360 const op_reg = switch (operand) {
13611361 .register => |r| r,
......@@ -1408,13 +1408,13 @@ fn minMax(
14081408 maybe_inst: ?Air.Inst.Index,
14091409) !MCValue {
14101410 const pt = self.pt;
1411 const mod = pt.zcu;
1412 switch (lhs_ty.zigTypeTag(mod)) {
1411 const zcu = pt.zcu;
1412 switch (lhs_ty.zigTypeTag(zcu)) {
14131413 .Float => return self.fail("TODO ARM min/max on floats", .{}),
14141414 .Vector => return self.fail("TODO ARM min/max on vectors", .{}),
14151415 .Int => {
1416 assert(lhs_ty.eql(rhs_ty, mod));
1417 const int_info = lhs_ty.intInfo(mod);
1416 assert(lhs_ty.eql(rhs_ty, zcu));
1417 const int_info = lhs_ty.intInfo(zcu);
14181418 if (int_info.bits <= 64) {
14191419 var lhs_reg: Register = undefined;
14201420 var rhs_reg: Register = undefined;
......@@ -1899,13 +1899,13 @@ fn addSub(
18991899 maybe_inst: ?Air.Inst.Index,
19001900) InnerError!MCValue {
19011901 const pt = self.pt;
1902 const mod = pt.zcu;
1903 switch (lhs_ty.zigTypeTag(mod)) {
1902 const zcu = pt.zcu;
1903 switch (lhs_ty.zigTypeTag(zcu)) {
19041904 .Float => return self.fail("TODO binary operations on floats", .{}),
19051905 .Vector => return self.fail("TODO binary operations on vectors", .{}),
19061906 .Int => {
1907 assert(lhs_ty.eql(rhs_ty, mod));
1908 const int_info = lhs_ty.intInfo(mod);
1907 assert(lhs_ty.eql(rhs_ty, zcu));
1908 const int_info = lhs_ty.intInfo(zcu);
19091909 if (int_info.bits <= 64) {
19101910 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
19111911 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
......@@ -1961,12 +1961,12 @@ fn mul(
19611961 maybe_inst: ?Air.Inst.Index,
19621962) InnerError!MCValue {
19631963 const pt = self.pt;
1964 const mod = pt.zcu;
1965 switch (lhs_ty.zigTypeTag(mod)) {
1964 const zcu = pt.zcu;
1965 switch (lhs_ty.zigTypeTag(zcu)) {
19661966 .Vector => return self.fail("TODO binary operations on vectors", .{}),
19671967 .Int => {
1968 assert(lhs_ty.eql(rhs_ty, mod));
1969 const int_info = lhs_ty.intInfo(mod);
1968 assert(lhs_ty.eql(rhs_ty, zcu));
1969 const int_info = lhs_ty.intInfo(zcu);
19701970 if (int_info.bits <= 64) {
19711971 // TODO add optimisations for multiplication
19721972 // with immediates, for example a * 2 can be
......@@ -1994,8 +1994,8 @@ fn divFloat(
19941994 _ = maybe_inst;
19951995
19961996 const pt = self.pt;
1997 const mod = pt.zcu;
1998 switch (lhs_ty.zigTypeTag(mod)) {
1997 const zcu = pt.zcu;
1998 switch (lhs_ty.zigTypeTag(zcu)) {
19991999 .Float => return self.fail("TODO div_float", .{}),
20002000 .Vector => return self.fail("TODO div_float on vectors", .{}),
20012001 else => unreachable,
......@@ -2011,13 +2011,13 @@ fn divTrunc(
20112011 maybe_inst: ?Air.Inst.Index,
20122012) InnerError!MCValue {
20132013 const pt = self.pt;
2014 const mod = pt.zcu;
2015 switch (lhs_ty.zigTypeTag(mod)) {
2014 const zcu = pt.zcu;
2015 switch (lhs_ty.zigTypeTag(zcu)) {
20162016 .Float => return self.fail("TODO div on floats", .{}),
20172017 .Vector => return self.fail("TODO div on vectors", .{}),
20182018 .Int => {
2019 assert(lhs_ty.eql(rhs_ty, mod));
2020 const int_info = lhs_ty.intInfo(mod);
2019 assert(lhs_ty.eql(rhs_ty, zcu));
2020 const int_info = lhs_ty.intInfo(zcu);
20212021 if (int_info.bits <= 64) {
20222022 switch (int_info.signedness) {
20232023 .signed => {
......@@ -2046,13 +2046,13 @@ fn divFloor(
20462046 maybe_inst: ?Air.Inst.Index,
20472047) InnerError!MCValue {
20482048 const pt = self.pt;
2049 const mod = pt.zcu;
2050 switch (lhs_ty.zigTypeTag(mod)) {
2049 const zcu = pt.zcu;
2050 switch (lhs_ty.zigTypeTag(zcu)) {
20512051 .Float => return self.fail("TODO div on floats", .{}),
20522052 .Vector => return self.fail("TODO div on vectors", .{}),
20532053 .Int => {
2054 assert(lhs_ty.eql(rhs_ty, mod));
2055 const int_info = lhs_ty.intInfo(mod);
2054 assert(lhs_ty.eql(rhs_ty, zcu));
2055 const int_info = lhs_ty.intInfo(zcu);
20562056 if (int_info.bits <= 64) {
20572057 switch (int_info.signedness) {
20582058 .signed => {
......@@ -2080,13 +2080,13 @@ fn divExact(
20802080 maybe_inst: ?Air.Inst.Index,
20812081) InnerError!MCValue {
20822082 const pt = self.pt;
2083 const mod = pt.zcu;
2084 switch (lhs_ty.zigTypeTag(mod)) {
2083 const zcu = pt.zcu;
2084 switch (lhs_ty.zigTypeTag(zcu)) {
20852085 .Float => return self.fail("TODO div on floats", .{}),
20862086 .Vector => return self.fail("TODO div on vectors", .{}),
20872087 .Int => {
2088 assert(lhs_ty.eql(rhs_ty, mod));
2089 const int_info = lhs_ty.intInfo(mod);
2088 assert(lhs_ty.eql(rhs_ty, zcu));
2089 const int_info = lhs_ty.intInfo(zcu);
20902090 if (int_info.bits <= 64) {
20912091 switch (int_info.signedness) {
20922092 .signed => {
......@@ -2117,13 +2117,13 @@ fn rem(
21172117 _ = maybe_inst;
21182118
21192119 const pt = self.pt;
2120 const mod = pt.zcu;
2121 switch (lhs_ty.zigTypeTag(mod)) {
2122 .Float => return self.fail("TODO rem/mod on floats", .{}),
2123 .Vector => return self.fail("TODO rem/mod on vectors", .{}),
2120 const zcu = pt.zcu;
2121 switch (lhs_ty.zigTypeTag(zcu)) {
2122 .Float => return self.fail("TODO rem/zcu on floats", .{}),
2123 .Vector => return self.fail("TODO rem/zcu on vectors", .{}),
21242124 .Int => {
2125 assert(lhs_ty.eql(rhs_ty, mod));
2126 const int_info = lhs_ty.intInfo(mod);
2125 assert(lhs_ty.eql(rhs_ty, zcu));
2126 const int_info = lhs_ty.intInfo(zcu);
21272127 if (int_info.bits <= 64) {
21282128 var lhs_reg: Register = undefined;
21292129 var rhs_reg: Register = undefined;
......@@ -2168,7 +2168,7 @@ fn rem(
21682168
21692169 return MCValue{ .register = remainder_reg };
21702170 } else {
2171 return self.fail("TODO rem/mod for integers with bits > 64", .{});
2171 return self.fail("TODO rem/zcu for integers with bits > 64", .{});
21722172 }
21732173 },
21742174 else => unreachable,
......@@ -2189,11 +2189,11 @@ fn modulo(
21892189 _ = maybe_inst;
21902190
21912191 const pt = self.pt;
2192 const mod = pt.zcu;
2193 switch (lhs_ty.zigTypeTag(mod)) {
2194 .Float => return self.fail("TODO mod on floats", .{}),
2195 .Vector => return self.fail("TODO mod on vectors", .{}),
2196 .Int => return self.fail("TODO mod on ints", .{}),
2192 const zcu = pt.zcu;
2193 switch (lhs_ty.zigTypeTag(zcu)) {
2194 .Float => return self.fail("TODO zcu on floats", .{}),
2195 .Vector => return self.fail("TODO zcu on vectors", .{}),
2196 .Int => return self.fail("TODO zcu on ints", .{}),
21972197 else => unreachable,
21982198 }
21992199}
......@@ -2208,11 +2208,11 @@ fn wrappingArithmetic(
22082208 maybe_inst: ?Air.Inst.Index,
22092209) InnerError!MCValue {
22102210 const pt = self.pt;
2211 const mod = pt.zcu;
2212 switch (lhs_ty.zigTypeTag(mod)) {
2211 const zcu = pt.zcu;
2212 switch (lhs_ty.zigTypeTag(zcu)) {
22132213 .Vector => return self.fail("TODO binary operations on vectors", .{}),
22142214 .Int => {
2215 const int_info = lhs_ty.intInfo(mod);
2215 const int_info = lhs_ty.intInfo(zcu);
22162216 if (int_info.bits <= 64) {
22172217 // Generate an add/sub/mul
22182218 const result: MCValue = switch (tag) {
......@@ -2244,12 +2244,12 @@ fn bitwise(
22442244 maybe_inst: ?Air.Inst.Index,
22452245) InnerError!MCValue {
22462246 const pt = self.pt;
2247 const mod = pt.zcu;
2248 switch (lhs_ty.zigTypeTag(mod)) {
2247 const zcu = pt.zcu;
2248 switch (lhs_ty.zigTypeTag(zcu)) {
22492249 .Vector => return self.fail("TODO binary operations on vectors", .{}),
22502250 .Int => {
2251 assert(lhs_ty.eql(rhs_ty, mod));
2252 const int_info = lhs_ty.intInfo(mod);
2251 assert(lhs_ty.eql(rhs_ty, zcu));
2252 const int_info = lhs_ty.intInfo(zcu);
22532253 if (int_info.bits <= 64) {
22542254 // TODO implement bitwise operations with immediates
22552255 const mir_tag: Mir.Inst.Tag = switch (tag) {
......@@ -2280,11 +2280,11 @@ fn shiftExact(
22802280 _ = rhs_ty;
22812281
22822282 const pt = self.pt;
2283 const mod = pt.zcu;
2284 switch (lhs_ty.zigTypeTag(mod)) {
2283 const zcu = pt.zcu;
2284 switch (lhs_ty.zigTypeTag(zcu)) {
22852285 .Vector => return self.fail("TODO binary operations on vectors", .{}),
22862286 .Int => {
2287 const int_info = lhs_ty.intInfo(mod);
2287 const int_info = lhs_ty.intInfo(zcu);
22882288 if (int_info.bits <= 64) {
22892289 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
22902290
......@@ -2331,11 +2331,11 @@ fn shiftNormal(
23312331 maybe_inst: ?Air.Inst.Index,
23322332) InnerError!MCValue {
23332333 const pt = self.pt;
2334 const mod = pt.zcu;
2335 switch (lhs_ty.zigTypeTag(mod)) {
2334 const zcu = pt.zcu;
2335 switch (lhs_ty.zigTypeTag(zcu)) {
23362336 .Vector => return self.fail("TODO binary operations on vectors", .{}),
23372337 .Int => {
2338 const int_info = lhs_ty.intInfo(mod);
2338 const int_info = lhs_ty.intInfo(zcu);
23392339 if (int_info.bits <= 64) {
23402340 // Generate a shl_exact/shr_exact
23412341 const result: MCValue = switch (tag) {
......@@ -2372,8 +2372,8 @@ fn booleanOp(
23722372 maybe_inst: ?Air.Inst.Index,
23732373) InnerError!MCValue {
23742374 const pt = self.pt;
2375 const mod = pt.zcu;
2376 switch (lhs_ty.zigTypeTag(mod)) {
2375 const zcu = pt.zcu;
2376 switch (lhs_ty.zigTypeTag(zcu)) {
23772377 .Bool => {
23782378 assert((try lhs_bind.resolveToImmediate(self)) == null); // should have been handled by Sema
23792379 assert((try rhs_bind.resolveToImmediate(self)) == null); // should have been handled by Sema
......@@ -2400,17 +2400,17 @@ fn ptrArithmetic(
24002400 maybe_inst: ?Air.Inst.Index,
24012401) InnerError!MCValue {
24022402 const pt = self.pt;
2403 const mod = pt.zcu;
2404 switch (lhs_ty.zigTypeTag(mod)) {
2403 const zcu = pt.zcu;
2404 switch (lhs_ty.zigTypeTag(zcu)) {
24052405 .Pointer => {
2406 assert(rhs_ty.eql(Type.usize, mod));
2406 assert(rhs_ty.eql(Type.usize, zcu));
24072407
24082408 const ptr_ty = lhs_ty;
2409 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
2410 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
2411 else => ptr_ty.childType(mod),
2409 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
2410 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
2411 else => ptr_ty.childType(zcu),
24122412 };
2413 const elem_size = elem_ty.abiSize(pt);
2413 const elem_size = elem_ty.abiSize(zcu);
24142414
24152415 const base_tag: Air.Inst.Tag = switch (tag) {
24162416 .ptr_add => .add,
......@@ -2524,7 +2524,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
25242524 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
25252525 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
25262526 const pt = self.pt;
2527 const mod = pt.zcu;
2527 const zcu = pt.zcu;
25282528 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
25292529 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
25302530 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
......@@ -2532,15 +2532,15 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
25322532 const rhs_ty = self.typeOf(extra.rhs);
25332533
25342534 const tuple_ty = self.typeOfIndex(inst);
2535 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(pt)));
2536 const tuple_align = tuple_ty.abiAlignment(pt);
2537 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, pt)));
2535 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(zcu)));
2536 const tuple_align = tuple_ty.abiAlignment(zcu);
2537 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, zcu)));
25382538
2539 switch (lhs_ty.zigTypeTag(mod)) {
2539 switch (lhs_ty.zigTypeTag(zcu)) {
25402540 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
25412541 .Int => {
2542 assert(lhs_ty.eql(rhs_ty, mod));
2543 const int_info = lhs_ty.intInfo(mod);
2542 assert(lhs_ty.eql(rhs_ty, zcu));
2543 const int_info = lhs_ty.intInfo(zcu);
25442544 switch (int_info.bits) {
25452545 1...31, 33...63 => {
25462546 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);
......@@ -2652,8 +2652,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
26522652 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
26532653 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
26542654 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
2655 const pt = self.pt;
2656 const mod = pt.zcu;
2655 const zcu = self.pt.zcu;
26572656 const result: MCValue = result: {
26582657 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
26592658 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
......@@ -2661,15 +2660,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
26612660 const rhs_ty = self.typeOf(extra.rhs);
26622661
26632662 const tuple_ty = self.typeOfIndex(inst);
2664 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(pt)));
2665 const tuple_align = tuple_ty.abiAlignment(pt);
2666 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, pt)));
2663 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(zcu)));
2664 const tuple_align = tuple_ty.abiAlignment(zcu);
2665 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, zcu)));
26672666
2668 switch (lhs_ty.zigTypeTag(mod)) {
2667 switch (lhs_ty.zigTypeTag(zcu)) {
26692668 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
26702669 .Int => {
2671 assert(lhs_ty.eql(rhs_ty, mod));
2672 const int_info = lhs_ty.intInfo(mod);
2670 assert(lhs_ty.eql(rhs_ty, zcu));
2671 const int_info = lhs_ty.intInfo(zcu);
26732672 if (int_info.bits <= 32) {
26742673 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);
26752674
......@@ -2878,7 +2877,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
28782877 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
28792878 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
28802879 const pt = self.pt;
2881 const mod = pt.zcu;
2880 const zcu = pt.zcu;
28822881 const result: MCValue = result: {
28832882 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
28842883 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
......@@ -2886,14 +2885,14 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
28862885 const rhs_ty = self.typeOf(extra.rhs);
28872886
28882887 const tuple_ty = self.typeOfIndex(inst);
2889 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(pt)));
2890 const tuple_align = tuple_ty.abiAlignment(pt);
2891 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, pt)));
2888 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(zcu)));
2889 const tuple_align = tuple_ty.abiAlignment(zcu);
2890 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, zcu)));
28922891
2893 switch (lhs_ty.zigTypeTag(mod)) {
2892 switch (lhs_ty.zigTypeTag(zcu)) {
28942893 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
28952894 .Int => {
2896 const int_info = lhs_ty.intInfo(mod);
2895 const int_info = lhs_ty.intInfo(zcu);
28972896 if (int_info.bits <= 64) {
28982897 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);
28992898
......@@ -3027,10 +3026,10 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
30273026
30283027fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty: Type) !MCValue {
30293028 const pt = self.pt;
3030 const mod = pt.zcu;
3031 const payload_ty = optional_ty.optionalChild(mod);
3032 if (!payload_ty.hasRuntimeBits(pt)) return MCValue.none;
3033 if (optional_ty.isPtrLikeOptional(mod)) {
3029 const zcu = pt.zcu;
3030 const payload_ty = optional_ty.optionalChild(zcu);
3031 if (!payload_ty.hasRuntimeBits(zcu)) return MCValue.none;
3032 if (optional_ty.isPtrLikeOptional(zcu)) {
30343033 // TODO should we reuse the operand here?
30353034 const raw_reg = try self.register_manager.allocReg(inst, gp);
30363035 const reg = self.registerAlias(raw_reg, payload_ty);
......@@ -3072,17 +3071,17 @@ fn errUnionErr(
30723071 maybe_inst: ?Air.Inst.Index,
30733072) !MCValue {
30743073 const pt = self.pt;
3075 const mod = pt.zcu;
3076 const err_ty = error_union_ty.errorUnionSet(mod);
3077 const payload_ty = error_union_ty.errorUnionPayload(mod);
3078 if (err_ty.errorSetIsEmpty(mod)) {
3074 const zcu = pt.zcu;
3075 const err_ty = error_union_ty.errorUnionSet(zcu);
3076 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3077 if (err_ty.errorSetIsEmpty(zcu)) {
30793078 return MCValue{ .immediate = 0 };
30803079 }
3081 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3080 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
30823081 return try error_union_bind.resolveToMcv(self);
30833082 }
30843083
3085 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, pt));
3084 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, zcu));
30863085 switch (try error_union_bind.resolveToMcv(self)) {
30873086 .register => {
30883087 var operand_reg: Register = undefined;
......@@ -3104,7 +3103,7 @@ fn errUnionErr(
31043103 );
31053104
31063105 const err_bit_offset = err_offset * 8;
3107 const err_bit_size = @as(u32, @intCast(err_ty.abiSize(pt))) * 8;
3106 const err_bit_size = @as(u32, @intCast(err_ty.abiSize(zcu))) * 8;
31083107
31093108 _ = try self.addInst(.{
31103109 .tag = .ubfx, // errors are unsigned integers
......@@ -3153,17 +3152,17 @@ fn errUnionPayload(
31533152 maybe_inst: ?Air.Inst.Index,
31543153) !MCValue {
31553154 const pt = self.pt;
3156 const mod = pt.zcu;
3157 const err_ty = error_union_ty.errorUnionSet(mod);
3158 const payload_ty = error_union_ty.errorUnionPayload(mod);
3159 if (err_ty.errorSetIsEmpty(mod)) {
3155 const zcu = pt.zcu;
3156 const err_ty = error_union_ty.errorUnionSet(zcu);
3157 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3158 if (err_ty.errorSetIsEmpty(zcu)) {
31603159 return try error_union_bind.resolveToMcv(self);
31613160 }
3162 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3161 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
31633162 return MCValue.none;
31643163 }
31653164
3166 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt)));
3165 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu)));
31673166 switch (try error_union_bind.resolveToMcv(self)) {
31683167 .register => {
31693168 var operand_reg: Register = undefined;
......@@ -3185,10 +3184,10 @@ fn errUnionPayload(
31853184 );
31863185
31873186 const payload_bit_offset = payload_offset * 8;
3188 const payload_bit_size = @as(u32, @intCast(payload_ty.abiSize(pt))) * 8;
3187 const payload_bit_size = @as(u32, @intCast(payload_ty.abiSize(zcu))) * 8;
31893188
31903189 _ = try self.addInst(.{
3191 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
3190 .tag = if (payload_ty.isSignedInt(zcu)) Mir.Inst.Tag.sbfx else .ubfx,
31923191 .data = .{
31933192 .rr_lsb_width = .{
31943193 // Set both registers to the X variant to get the full width
......@@ -3266,7 +3265,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
32663265
32673266fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32683267 const pt = self.pt;
3269 const mod = pt.zcu;
3268 const zcu = pt.zcu;
32703269 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
32713270
32723271 if (self.liveness.isUnused(inst)) {
......@@ -3275,7 +3274,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32753274
32763275 const result: MCValue = result: {
32773276 const payload_ty = self.typeOf(ty_op.operand);
3278 if (!payload_ty.hasRuntimeBits(pt)) {
3277 if (!payload_ty.hasRuntimeBits(zcu)) {
32793278 break :result MCValue{ .immediate = 1 };
32803279 }
32813280
......@@ -3287,7 +3286,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32873286 };
32883287 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
32893288
3290 if (optional_ty.isPtrLikeOptional(mod)) {
3289 if (optional_ty.isPtrLikeOptional(zcu)) {
32913290 // TODO should we check if we can reuse the operand?
32923291 const raw_reg = try self.register_manager.allocReg(inst, gp);
32933292 const reg = self.registerAlias(raw_reg, payload_ty);
......@@ -3295,9 +3294,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32953294 break :result MCValue{ .register = reg };
32963295 }
32973296
3298 const optional_abi_size: u32 = @intCast(optional_ty.abiSize(pt));
3299 const optional_abi_align = optional_ty.abiAlignment(pt);
3300 const offset: u32 = @intCast(payload_ty.abiSize(pt));
3297 const optional_abi_size: u32 = @intCast(optional_ty.abiSize(zcu));
3298 const optional_abi_align = optional_ty.abiAlignment(zcu);
3299 const offset: u32 = @intCast(payload_ty.abiSize(zcu));
33013300
33023301 const stack_offset = try self.allocMem(optional_abi_size, optional_abi_align, inst);
33033302 try self.genSetStack(payload_ty, stack_offset, operand);
......@@ -3312,20 +3311,20 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
33123311/// T to E!T
33133312fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
33143313 const pt = self.pt;
3315 const mod = pt.zcu;
3314 const zcu = pt.zcu;
33163315 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
33173316 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
33183317 const error_union_ty = ty_op.ty.toType();
3319 const error_ty = error_union_ty.errorUnionSet(mod);
3320 const payload_ty = error_union_ty.errorUnionPayload(mod);
3318 const error_ty = error_union_ty.errorUnionSet(zcu);
3319 const payload_ty = error_union_ty.errorUnionPayload(zcu);
33213320 const operand = try self.resolveInst(ty_op.operand);
3322 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result operand;
3321 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result operand;
33233322
3324 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(pt)));
3325 const abi_align = error_union_ty.abiAlignment(pt);
3323 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(zcu)));
3324 const abi_align = error_union_ty.abiAlignment(zcu);
33263325 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
3327 const payload_off = errUnionPayloadOffset(payload_ty, pt);
3328 const err_off = errUnionErrorOffset(payload_ty, pt);
3326 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
3327 const err_off = errUnionErrorOffset(payload_ty, zcu);
33293328 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
33303329 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });
33313330
......@@ -3339,18 +3338,18 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
33393338 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
33403339 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
33413340 const pt = self.pt;
3342 const mod = pt.zcu;
3341 const zcu = pt.zcu;
33433342 const error_union_ty = ty_op.ty.toType();
3344 const error_ty = error_union_ty.errorUnionSet(mod);
3345 const payload_ty = error_union_ty.errorUnionPayload(mod);
3343 const error_ty = error_union_ty.errorUnionSet(zcu);
3344 const payload_ty = error_union_ty.errorUnionPayload(zcu);
33463345 const operand = try self.resolveInst(ty_op.operand);
3347 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result operand;
3346 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result operand;
33483347
3349 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(pt)));
3350 const abi_align = error_union_ty.abiAlignment(pt);
3348 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(zcu)));
3349 const abi_align = error_union_ty.abiAlignment(zcu);
33513350 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
3352 const payload_off = errUnionPayloadOffset(payload_ty, pt);
3353 const err_off = errUnionErrorOffset(payload_ty, pt);
3351 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
3352 const err_off = errUnionErrorOffset(payload_ty, zcu);
33543353 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
33553354 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);
33563355
......@@ -3443,11 +3442,11 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
34433442
34443443fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
34453444 const pt = self.pt;
3446 const mod = pt.zcu;
3445 const zcu = pt.zcu;
34473446 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
34483447 const slice_ty = self.typeOf(bin_op.lhs);
3449 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
3450 const ptr_ty = slice_ty.slicePtrFieldType(mod);
3448 const result: MCValue = if (!slice_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) .dead else result: {
3449 const ptr_ty = slice_ty.slicePtrFieldType(zcu);
34513450
34523451 const slice_mcv = try self.resolveInst(bin_op.lhs);
34533452 const base_mcv = slicePtr(slice_mcv);
......@@ -3468,9 +3467,9 @@ fn ptrElemVal(
34683467 maybe_inst: ?Air.Inst.Index,
34693468) !MCValue {
34703469 const pt = self.pt;
3471 const mod = pt.zcu;
3472 const elem_ty = ptr_ty.childType(mod);
3473 const elem_size = @as(u32, @intCast(elem_ty.abiSize(pt)));
3470 const zcu = pt.zcu;
3471 const elem_ty = ptr_ty.childType(zcu);
3472 const elem_size = @as(u32, @intCast(elem_ty.abiSize(zcu)));
34743473
34753474 // TODO optimize for elem_sizes of 1, 2, 4, 8
34763475 switch (elem_size) {
......@@ -3511,10 +3510,10 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
35113510
35123511fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
35133512 const pt = self.pt;
3514 const mod = pt.zcu;
3513 const zcu = pt.zcu;
35153514 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
35163515 const ptr_ty = self.typeOf(bin_op.lhs);
3517 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
3516 const result: MCValue = if (!ptr_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) .dead else result: {
35183517 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
35193518 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
35203519
......@@ -3635,9 +3634,9 @@ fn reuseOperand(
36353634
36363635fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
36373636 const pt = self.pt;
3638 const mod = pt.zcu;
3639 const elem_ty = ptr_ty.childType(mod);
3640 const elem_size = elem_ty.abiSize(pt);
3637 const zcu = pt.zcu;
3638 const elem_ty = ptr_ty.childType(zcu);
3639 const elem_size = elem_ty.abiSize(zcu);
36413640
36423641 switch (ptr) {
36433642 .none => unreachable,
......@@ -3884,16 +3883,16 @@ fn genInlineMemsetCode(
38843883
38853884fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
38863885 const pt = self.pt;
3887 const mod = pt.zcu;
3886 const zcu = pt.zcu;
38883887 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
38893888 const elem_ty = self.typeOfIndex(inst);
3890 const elem_size = elem_ty.abiSize(pt);
3889 const elem_size = elem_ty.abiSize(zcu);
38913890 const result: MCValue = result: {
3892 if (!elem_ty.hasRuntimeBits(pt))
3891 if (!elem_ty.hasRuntimeBits(zcu))
38933892 break :result MCValue.none;
38943893
38953894 const ptr = try self.resolveInst(ty_op.operand);
3896 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(mod);
3895 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(zcu);
38973896 if (self.liveness.isUnused(inst) and !is_volatile)
38983897 break :result MCValue.dead;
38993898
......@@ -3916,12 +3915,12 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
39163915
39173916fn genLdrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type) !void {
39183917 const pt = self.pt;
3919 const mod = pt.zcu;
3920 const abi_size = ty.abiSize(pt);
3918 const zcu = pt.zcu;
3919 const abi_size = ty.abiSize(zcu);
39213920
39223921 const tag: Mir.Inst.Tag = switch (abi_size) {
3923 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_immediate else .ldrb_immediate,
3924 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh_immediate else .ldrh_immediate,
3922 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb_immediate else .ldrb_immediate,
3923 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_immediate else .ldrh_immediate,
39253924 4 => .ldr_immediate,
39263925 8 => .ldr_immediate,
39273926 3, 5, 6, 7 => return self.fail("TODO: genLdrRegister for more abi_sizes", .{}),
......@@ -3940,7 +3939,7 @@ fn genLdrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type
39403939
39413940fn genStrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type) !void {
39423941 const pt = self.pt;
3943 const abi_size = ty.abiSize(pt);
3942 const abi_size = ty.abiSize(pt.zcu);
39443943
39453944 const tag: Mir.Inst.Tag = switch (abi_size) {
39463945 1 => .strb_immediate,
......@@ -3963,7 +3962,7 @@ fn genStrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type
39633962fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
39643963 const pt = self.pt;
39653964 log.debug("store: storing {} to {}", .{ value, ptr });
3966 const abi_size = value_ty.abiSize(pt);
3965 const abi_size = value_ty.abiSize(pt.zcu);
39673966
39683967 switch (ptr) {
39693968 .none => unreachable,
......@@ -4116,11 +4115,11 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
41164115fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
41174116 return if (self.liveness.isUnused(inst)) .dead else result: {
41184117 const pt = self.pt;
4119 const mod = pt.zcu;
4118 const zcu = pt.zcu;
41204119 const mcv = try self.resolveInst(operand);
41214120 const ptr_ty = self.typeOf(operand);
4122 const struct_ty = ptr_ty.childType(mod);
4123 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));
4121 const struct_ty = ptr_ty.childType(zcu);
4122 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
41244123 switch (mcv) {
41254124 .ptr_stack_offset => |off| {
41264125 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
......@@ -4142,11 +4141,11 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
41424141 const index = extra.field_index;
41434142 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
41444143 const pt = self.pt;
4145 const mod = pt.zcu;
4144 const zcu = pt.zcu;
41464145 const mcv = try self.resolveInst(operand);
41474146 const struct_ty = self.typeOf(operand);
4148 const struct_field_ty = struct_ty.structFieldType(index, mod);
4149 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));
4147 const struct_field_ty = struct_ty.structFieldType(index, zcu);
4148 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
41504149
41514150 switch (mcv) {
41524151 .dead, .unreach => unreachable,
......@@ -4193,13 +4192,13 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
41934192
41944193fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
41954194 const pt = self.pt;
4196 const mod = pt.zcu;
4195 const zcu = pt.zcu;
41974196 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
41984197 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
41994198 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
42004199 const field_ptr = try self.resolveInst(extra.field_ptr);
4201 const struct_ty = ty_pl.ty.toType().childType(mod);
4202 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, pt)));
4200 const struct_ty = ty_pl.ty.toType().childType(zcu);
4201 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, zcu)));
42034202 switch (field_ptr) {
42044203 .ptr_stack_offset => |off| {
42054204 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
......@@ -4274,12 +4273,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42744273 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
42754274 const ty = self.typeOf(callee);
42764275 const pt = self.pt;
4277 const mod = pt.zcu;
4278 const ip = &mod.intern_pool;
4276 const zcu = pt.zcu;
4277 const ip = &zcu.intern_pool;
42794278
4280 const fn_ty = switch (ty.zigTypeTag(mod)) {
4279 const fn_ty = switch (ty.zigTypeTag(zcu)) {
42814280 .Fn => ty,
4282 .Pointer => ty.childType(mod),
4281 .Pointer => ty.childType(zcu),
42834282 else => unreachable,
42844283 };
42854284
......@@ -4298,9 +4297,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42984297
42994298 if (info.return_value == .stack_offset) {
43004299 log.debug("airCall: return by reference", .{});
4301 const ret_ty = fn_ty.fnReturnType(mod);
4302 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(pt));
4303 const ret_abi_align = ret_ty.abiAlignment(pt);
4300 const ret_ty = fn_ty.fnReturnType(zcu);
4301 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(zcu));
4302 const ret_abi_align = ret_ty.abiAlignment(zcu);
43044303 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
43054304
43064305 const ret_ptr_reg = self.registerAlias(.x0, Type.usize);
......@@ -4387,7 +4386,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43874386 },
43884387 else => return self.fail("TODO implement calling bitcasted functions", .{}),
43894388 } else {
4390 assert(ty.zigTypeTag(mod) == .Pointer);
4389 assert(ty.zigTypeTag(zcu) == .Pointer);
43914390 const mcv = try self.resolveInst(callee);
43924391 try self.genSetReg(ty, .x30, mcv);
43934392
......@@ -4426,15 +4425,15 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
44264425
44274426fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44284427 const pt = self.pt;
4429 const mod = pt.zcu;
4428 const zcu = pt.zcu;
44304429 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
44314430 const operand = try self.resolveInst(un_op);
4432 const ret_ty = self.fn_type.fnReturnType(mod);
4431 const ret_ty = self.fn_type.fnReturnType(zcu);
44334432
44344433 switch (self.ret_mcv) {
44354434 .none => {},
44364435 .immediate => {
4437 assert(ret_ty.isError(mod));
4436 assert(ret_ty.isError(zcu));
44384437 },
44394438 .register => |reg| {
44404439 // Return result by value
......@@ -4459,11 +4458,11 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44594458
44604459fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44614460 const pt = self.pt;
4462 const mod = pt.zcu;
4461 const zcu = pt.zcu;
44634462 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
44644463 const ptr = try self.resolveInst(un_op);
44654464 const ptr_ty = self.typeOf(un_op);
4466 const ret_ty = self.fn_type.fnReturnType(mod);
4465 const ret_ty = self.fn_type.fnReturnType(zcu);
44674466
44684467 switch (self.ret_mcv) {
44694468 .none => {},
......@@ -4483,8 +4482,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44834482 // location.
44844483 const op_inst = un_op.toIndex().?;
44854484 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
4486 const abi_size = @as(u32, @intCast(ret_ty.abiSize(pt)));
4487 const abi_align = ret_ty.abiAlignment(pt);
4485 const abi_size = @as(u32, @intCast(ret_ty.abiSize(zcu)));
4486 const abi_align = ret_ty.abiAlignment(zcu);
44884487
44894488 const offset = try self.allocMem(abi_size, abi_align, null);
44904489
......@@ -4520,20 +4519,20 @@ fn cmp(
45204519 op: math.CompareOperator,
45214520) !MCValue {
45224521 const pt = self.pt;
4523 const mod = pt.zcu;
4524 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {
4522 const zcu = pt.zcu;
4523 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {
45254524 .Optional => blk: {
4526 const payload_ty = lhs_ty.optionalChild(mod);
4527 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4525 const payload_ty = lhs_ty.optionalChild(zcu);
4526 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
45284527 break :blk Type.u1;
4529 } else if (lhs_ty.isPtrLikeOptional(mod)) {
4528 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
45304529 break :blk Type.usize;
45314530 } else {
45324531 return self.fail("TODO ARM cmp non-pointer optionals", .{});
45334532 }
45344533 },
45354534 .Float => return self.fail("TODO ARM cmp floats", .{}),
4536 .Enum => lhs_ty.intTagType(mod),
4535 .Enum => lhs_ty.intTagType(zcu),
45374536 .Int => lhs_ty,
45384537 .Bool => Type.u1,
45394538 .Pointer => Type.usize,
......@@ -4541,7 +4540,7 @@ fn cmp(
45414540 else => unreachable,
45424541 };
45434542
4544 const int_info = int_ty.intInfo(mod);
4543 const int_info = int_ty.intInfo(zcu);
45454544 if (int_info.bits <= 64) {
45464545 try self.spillCompareFlagsIfOccupied();
45474546
......@@ -4628,10 +4627,10 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
46284627
46294628fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {
46304629 const pt = self.pt;
4631 const mod = pt.zcu;
4630 const zcu = pt.zcu;
46324631 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
46334632 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);
4634 const func = mod.funcInfo(extra.data.func);
4633 const func = zcu.funcInfo(extra.data.func);
46354634 // TODO emit debug info for function change
46364635 _ = func;
46374636 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
......@@ -4834,13 +4833,13 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
48344833
48354834fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
48364835 const pt = self.pt;
4837 const mod = pt.zcu;
4838 const sentinel: struct { ty: Type, bind: ReadArg.Bind } = if (!operand_ty.isPtrLikeOptional(mod)) blk: {
4839 const payload_ty = operand_ty.optionalChild(mod);
4840 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt))
4836 const zcu = pt.zcu;
4837 const sentinel: struct { ty: Type, bind: ReadArg.Bind } = if (!operand_ty.isPtrLikeOptional(zcu)) blk: {
4838 const payload_ty = operand_ty.optionalChild(zcu);
4839 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
48414840 break :blk .{ .ty = operand_ty, .bind = operand_bind };
48424841
4843 const offset = @as(u32, @intCast(payload_ty.abiSize(pt)));
4842 const offset = @as(u32, @intCast(payload_ty.abiSize(zcu)));
48444843 const operand_mcv = try operand_bind.resolveToMcv(self);
48454844 const new_mcv: MCValue = switch (operand_mcv) {
48464845 .register => |source_reg| new: {
......@@ -4853,7 +4852,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
48534852 try self.genSetReg(payload_ty, dest_reg, operand_mcv);
48544853 } else {
48554854 _ = try self.addInst(.{
4856 .tag = if (payload_ty.isSignedInt(mod))
4855 .tag = if (payload_ty.isSignedInt(zcu))
48574856 Mir.Inst.Tag.asr_immediate
48584857 else
48594858 Mir.Inst.Tag.lsr_immediate,
......@@ -4891,10 +4890,10 @@ fn isErr(
48914890 error_union_ty: Type,
48924891) !MCValue {
48934892 const pt = self.pt;
4894 const mod = pt.zcu;
4895 const error_type = error_union_ty.errorUnionSet(mod);
4893 const zcu = pt.zcu;
4894 const error_type = error_union_ty.errorUnionSet(zcu);
48964895
4897 if (error_type.errorSetIsEmpty(mod)) {
4896 if (error_type.errorSetIsEmpty(zcu)) {
48984897 return MCValue{ .immediate = 0 }; // always false
48994898 }
49004899
......@@ -4934,12 +4933,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
49344933
49354934fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49364935 const pt = self.pt;
4937 const mod = pt.zcu;
4936 const zcu = pt.zcu;
49384937 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
49394938 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49404939 const operand_ptr = try self.resolveInst(un_op);
49414940 const ptr_ty = self.typeOf(un_op);
4942 const elem_ty = ptr_ty.childType(mod);
4941 const elem_ty = ptr_ty.childType(zcu);
49434942
49444943 const operand = try self.allocRegOrMem(elem_ty, true, null);
49454944 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4962,12 +4961,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
49624961
49634962fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
49644963 const pt = self.pt;
4965 const mod = pt.zcu;
4964 const zcu = pt.zcu;
49664965 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
49674966 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49684967 const operand_ptr = try self.resolveInst(un_op);
49694968 const ptr_ty = self.typeOf(un_op);
4970 const elem_ty = ptr_ty.childType(mod);
4969 const elem_ty = ptr_ty.childType(zcu);
49714970
49724971 const operand = try self.allocRegOrMem(elem_ty, true, null);
49734972 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4990,12 +4989,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49904989
49914990fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49924991 const pt = self.pt;
4993 const mod = pt.zcu;
4992 const zcu = pt.zcu;
49944993 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
49954994 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49964995 const operand_ptr = try self.resolveInst(un_op);
49974996 const ptr_ty = self.typeOf(un_op);
4998 const elem_ty = ptr_ty.childType(mod);
4997 const elem_ty = ptr_ty.childType(zcu);
49994998
50004999 const operand = try self.allocRegOrMem(elem_ty, true, null);
50015000 try self.load(operand, operand_ptr, ptr_ty);
......@@ -5018,12 +5017,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
50185017
50195018fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
50205019 const pt = self.pt;
5021 const mod = pt.zcu;
5020 const zcu = pt.zcu;
50225021 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
50235022 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50245023 const operand_ptr = try self.resolveInst(un_op);
50255024 const ptr_ty = self.typeOf(un_op);
5026 const elem_ty = ptr_ty.childType(mod);
5025 const elem_ty = ptr_ty.childType(zcu);
50275026
50285027 const operand = try self.allocRegOrMem(elem_ty, true, null);
50295028 try self.load(operand, operand_ptr, ptr_ty);
......@@ -5240,9 +5239,10 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
52405239
52415240fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
52425241 const pt = self.pt;
5242 const zcu = pt.zcu;
52435243 const block_data = self.blocks.getPtr(block).?;
52445244
5245 if (self.typeOf(operand).hasRuntimeBits(pt)) {
5245 if (self.typeOf(operand).hasRuntimeBits(zcu)) {
52465246 const operand_mcv = try self.resolveInst(operand);
52475247 const block_mcv = block_data.mcv;
52485248 if (block_mcv == .none) {
......@@ -5417,8 +5417,8 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
54175417
54185418fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
54195419 const pt = self.pt;
5420 const mod = pt.zcu;
5421 const abi_size = @as(u32, @intCast(ty.abiSize(pt)));
5420 const zcu = pt.zcu;
5421 const abi_size = @as(u32, @intCast(ty.abiSize(zcu)));
54225422 switch (mcv) {
54235423 .dead => unreachable,
54245424 .unreach, .none => return, // Nothing to do.
......@@ -5473,11 +5473,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54735473 const reg_lock = self.register_manager.lockReg(rwo.reg);
54745474 defer if (reg_lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
54755475
5476 const wrapped_ty = ty.structFieldType(0, mod);
5476 const wrapped_ty = ty.structFieldType(0, zcu);
54775477 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
54785478
5479 const overflow_bit_ty = ty.structFieldType(1, mod);
5480 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, pt)));
5479 const overflow_bit_ty = ty.structFieldType(1, zcu);
5480 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, zcu)));
54815481 const raw_cond_reg = try self.register_manager.allocReg(null, gp);
54825482 const cond_reg = self.registerAlias(raw_cond_reg, overflow_bit_ty);
54835483
......@@ -5589,7 +5589,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
55895589
55905590fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {
55915591 const pt = self.pt;
5592 const mod = pt.zcu;
5592 const zcu = pt.zcu;
55935593 switch (mcv) {
55945594 .dead => unreachable,
55955595 .unreach, .none => return, // Nothing to do.
......@@ -5701,13 +5701,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57015701 try self.genLdrRegister(reg, reg.toX(), ty);
57025702 },
57035703 .stack_offset => |off| {
5704 const abi_size = ty.abiSize(pt);
5704 const abi_size = ty.abiSize(zcu);
57055705
57065706 switch (abi_size) {
57075707 1, 2, 4, 8 => {
57085708 const tag: Mir.Inst.Tag = switch (abi_size) {
5709 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_stack else .ldrb_stack,
5710 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh_stack else .ldrh_stack,
5709 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb_stack else .ldrb_stack,
5710 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_stack else .ldrh_stack,
57115711 4, 8 => .ldr_stack,
57125712 else => unreachable, // unexpected abi size
57135713 };
......@@ -5725,13 +5725,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57255725 }
57265726 },
57275727 .stack_argument_offset => |off| {
5728 const abi_size = ty.abiSize(pt);
5728 const abi_size = ty.abiSize(zcu);
57295729
57305730 switch (abi_size) {
57315731 1, 2, 4, 8 => {
57325732 const tag: Mir.Inst.Tag = switch (abi_size) {
5733 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_stack_argument else .ldrb_stack_argument,
5734 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh_stack_argument else .ldrh_stack_argument,
5733 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb_stack_argument else .ldrb_stack_argument,
5734 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_stack_argument else .ldrh_stack_argument,
57355735 4, 8 => .ldr_stack_argument,
57365736 else => unreachable, // unexpected abi size
57375737 };
......@@ -5753,7 +5753,8 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57535753
57545754fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
57555755 const pt = self.pt;
5756 const abi_size = @as(u32, @intCast(ty.abiSize(pt)));
5756 const zcu = pt.zcu;
5757 const abi_size = @as(u32, @intCast(ty.abiSize(zcu)));
57575758 switch (mcv) {
57585759 .dead => unreachable,
57595760 .none, .unreach => return,
......@@ -5761,7 +5762,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
57615762 if (!self.wantSafety())
57625763 return; // The already existing value will do just fine.
57635764 // TODO Upgrade this to a memset call when we have that available.
5764 switch (ty.abiSize(pt)) {
5765 switch (ty.abiSize(pt.zcu)) {
57655766 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),
57665767 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),
57675768 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),
......@@ -5953,13 +5954,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59535954
59545955fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59555956 const pt = self.pt;
5956 const mod = pt.zcu;
5957 const zcu = pt.zcu;
59575958 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59585959 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
59595960 const ptr_ty = self.typeOf(ty_op.operand);
59605961 const ptr = try self.resolveInst(ty_op.operand);
5961 const array_ty = ptr_ty.childType(mod);
5962 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));
5962 const array_ty = ptr_ty.childType(zcu);
5963 const array_len = @as(u32, @intCast(array_ty.arrayLen(zcu)));
59635964 const ptr_bytes = 8;
59645965 const stack_offset = try self.allocMem(ptr_bytes * 2, .@"8", inst);
59655966 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -6074,9 +6075,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60746075
60756076fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60766077 const pt = self.pt;
6077 const mod = pt.zcu;
6078 const zcu = pt.zcu;
60786079 const vector_ty = self.typeOfIndex(inst);
6079 const len = vector_ty.vectorLen(mod);
6080 const len = vector_ty.vectorLen(zcu);
60806081 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
60816082 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
60826083 const result: MCValue = res: {
......@@ -6125,8 +6126,8 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
61256126 const result: MCValue = result: {
61266127 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
61276128 const error_union_ty = self.typeOf(pl_op.operand);
6128 const error_union_size = @as(u32, @intCast(error_union_ty.abiSize(pt)));
6129 const error_union_align = error_union_ty.abiAlignment(pt);
6129 const error_union_size = @as(u32, @intCast(error_union_ty.abiSize(pt.zcu)));
6130 const error_union_align = error_union_ty.abiAlignment(pt.zcu);
61306131
61316132 // The error union will die in the body. However, we need the
61326133 // error union after the body in order to extract the payload
......@@ -6156,11 +6157,11 @@ fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
61566157
61576158fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61586159 const pt = self.pt;
6159 const mod = pt.zcu;
6160 const zcu = pt.zcu;
61606161
61616162 // If the type has no codegen bits, no need to store it.
61626163 const inst_ty = self.typeOf(inst);
6163 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt) and !inst_ty.isError(mod))
6164 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu) and !inst_ty.isError(zcu))
61646165 return MCValue{ .none = {} };
61656166
61666167 const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, pt)).?);
......@@ -6220,9 +6221,9 @@ const CallMCValues = struct {
62206221/// Caller must call `CallMCValues.deinit`.
62216222fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62226223 const pt = self.pt;
6223 const mod = pt.zcu;
6224 const ip = &mod.intern_pool;
6225 const fn_info = mod.typeToFunc(fn_ty).?;
6224 const zcu = pt.zcu;
6225 const ip = &zcu.intern_pool;
6226 const fn_info = zcu.typeToFunc(fn_ty).?;
62266227 const cc = fn_info.cc;
62276228 var result: CallMCValues = .{
62286229 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),
......@@ -6233,7 +6234,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62336234 };
62346235 errdefer self.gpa.free(result.args);
62356236
6236 const ret_ty = fn_ty.fnReturnType(mod);
6237 const ret_ty = fn_ty.fnReturnType(zcu);
62376238
62386239 switch (cc) {
62396240 .Naked => {
......@@ -6248,14 +6249,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62486249 var ncrn: usize = 0; // Next Core Register Number
62496250 var nsaa: u32 = 0; // Next stacked argument address
62506251
6251 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
6252 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
62526253 result.return_value = .{ .unreach = {} };
6253 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt) and !ret_ty.isError(mod)) {
6254 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and !ret_ty.isError(zcu)) {
62546255 result.return_value = .{ .none = {} };
62556256 } else {
6256 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));
6257 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
62576258 if (ret_ty_size == 0) {
6258 assert(ret_ty.isError(mod));
6259 assert(ret_ty.isError(zcu));
62596260 result.return_value = .{ .immediate = 0 };
62606261 } else if (ret_ty_size <= 8) {
62616262 result.return_value = .{ .register = self.registerAlias(c_abi_int_return_regs[0], ret_ty) };
......@@ -6265,7 +6266,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62656266 }
62666267
62676268 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6268 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(pt)));
6269 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(zcu)));
62696270 if (param_size == 0) {
62706271 result_arg.* = .{ .none = {} };
62716272 continue;
......@@ -6273,7 +6274,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62736274
62746275 // We round up NCRN only for non-Apple platforms which allow the 16-byte aligned
62756276 // values to spread across odd-numbered registers.
6276 if (Type.fromInterned(ty).abiAlignment(pt) == .@"16" and !self.target.isDarwin()) {
6277 if (Type.fromInterned(ty).abiAlignment(zcu) == .@"16" and !self.target.isDarwin()) {
62776278 // Round up NCRN to the next even number
62786279 ncrn += ncrn % 2;
62796280 }
......@@ -6291,7 +6292,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62916292 ncrn = 8;
62926293 // TODO Apple allows the arguments on the stack to be non-8-byte aligned provided
62936294 // that the entire stack space consumed by the arguments is 8-byte aligned.
6294 if (Type.fromInterned(ty).abiAlignment(pt) == .@"8") {
6295 if (Type.fromInterned(ty).abiAlignment(zcu) == .@"8") {
62956296 if (nsaa % 8 != 0) {
62966297 nsaa += 8 - (nsaa % 8);
62976298 }
......@@ -6306,14 +6307,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63066307 result.stack_align = 16;
63076308 },
63086309 .Unspecified => {
6309 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
6310 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
63106311 result.return_value = .{ .unreach = {} };
6311 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt) and !ret_ty.isError(mod)) {
6312 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and !ret_ty.isError(zcu)) {
63126313 result.return_value = .{ .none = {} };
63136314 } else {
6314 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(pt)));
6315 const ret_ty_size = @as(u32, @intCast(ret_ty.abiSize(zcu)));
63156316 if (ret_ty_size == 0) {
6316 assert(ret_ty.isError(mod));
6317 assert(ret_ty.isError(zcu));
63176318 result.return_value = .{ .immediate = 0 };
63186319 } else if (ret_ty_size <= 8) {
63196320 result.return_value = .{ .register = self.registerAlias(.x0, ret_ty) };
......@@ -6330,9 +6331,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63306331 var stack_offset: u32 = 0;
63316332
63326333 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6333 if (Type.fromInterned(ty).abiSize(pt) > 0) {
6334 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(pt));
6335 const param_alignment = Type.fromInterned(ty).abiAlignment(pt);
6334 if (Type.fromInterned(ty).abiSize(zcu) > 0) {
6335 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(zcu));
6336 const param_alignment = Type.fromInterned(ty).abiAlignment(zcu);
63366337
63376338 stack_offset = @intCast(param_alignment.forward(stack_offset));
63386339 result_arg.* = .{ .stack_argument_offset = stack_offset };
......@@ -6383,7 +6384,7 @@ fn parseRegName(name: []const u8) ?Register {
63836384}
63846385
63856386fn registerAlias(self: *Self, reg: Register, ty: Type) Register {
6386 const abi_size = ty.abiSize(self.pt);
6387 const abi_size = ty.abiSize(self.pt.zcu);
63876388
63886389 switch (reg.class()) {
63896390 .general_purpose => {
src/arch/aarch64/abi.zig+12-12
......@@ -15,44 +15,44 @@ pub const Class = union(enum) {
1515};
1616
1717/// For `float_array` the second element will be the amount of floats.
18pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
19 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(pt));
18pub fn classifyType(ty: Type, zcu: *Zcu) Class {
19 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
2020
2121 var maybe_float_bits: ?u16 = null;
22 switch (ty.zigTypeTag(pt.zcu)) {
22 switch (ty.zigTypeTag(zcu)) {
2323 .Struct => {
24 if (ty.containerLayout(pt.zcu) == .@"packed") return .byval;
25 const float_count = countFloats(ty, pt.zcu, &maybe_float_bits);
24 if (ty.containerLayout(zcu) == .@"packed") return .byval;
25 const float_count = countFloats(ty, zcu, &maybe_float_bits);
2626 if (float_count <= sret_float_count) return .{ .float_array = float_count };
2727
28 const bit_size = ty.bitSize(pt);
28 const bit_size = ty.bitSize(zcu);
2929 if (bit_size > 128) return .memory;
3030 if (bit_size > 64) return .double_integer;
3131 return .integer;
3232 },
3333 .Union => {
34 if (ty.containerLayout(pt.zcu) == .@"packed") return .byval;
35 const float_count = countFloats(ty, pt.zcu, &maybe_float_bits);
34 if (ty.containerLayout(zcu) == .@"packed") return .byval;
35 const float_count = countFloats(ty, zcu, &maybe_float_bits);
3636 if (float_count <= sret_float_count) return .{ .float_array = float_count };
3737
38 const bit_size = ty.bitSize(pt);
38 const bit_size = ty.bitSize(zcu);
3939 if (bit_size > 128) return .memory;
4040 if (bit_size > 64) return .double_integer;
4141 return .integer;
4242 },
4343 .Int, .Enum, .ErrorSet, .Float, .Bool => return .byval,
4444 .Vector => {
45 const bit_size = ty.bitSize(pt);
45 const bit_size = ty.bitSize(zcu);
4646 // TODO is this controlled by a cpu feature?
4747 if (bit_size > 128) return .memory;
4848 return .byval;
4949 },
5050 .Optional => {
51 std.debug.assert(ty.isPtrLikeOptional(pt.zcu));
51 std.debug.assert(ty.isPtrLikeOptional(zcu));
5252 return .byval;
5353 },
5454 .Pointer => {
55 std.debug.assert(!ty.isSlice(pt.zcu));
55 std.debug.assert(!ty.isSlice(zcu));
5656 return .byval;
5757 },
5858 .ErrorUnion,
src/arch/arm/CodeGen.zig+252-252
......@@ -474,8 +474,8 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
474474
475475fn gen(self: *Self) !void {
476476 const pt = self.pt;
477 const mod = pt.zcu;
478 const cc = self.fn_type.fnCallingConvention(mod);
477 const zcu = pt.zcu;
478 const cc = self.fn_type.fnCallingConvention(zcu);
479479 if (cc != .Naked) {
480480 // push {fp, lr}
481481 const push_reloc = try self.addNop();
......@@ -518,8 +518,8 @@ fn gen(self: *Self) !void {
518518
519519 const ty = self.typeOfIndex(inst);
520520
521 const abi_size: u32 = @intCast(ty.abiSize(pt));
522 const abi_align = ty.abiAlignment(pt);
521 const abi_size: u32 = @intCast(ty.abiSize(zcu));
522 const abi_align = ty.abiAlignment(zcu);
523523 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
524524 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
525525
......@@ -635,8 +635,8 @@ fn gen(self: *Self) !void {
635635
636636fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
637637 const pt = self.pt;
638 const mod = pt.zcu;
639 const ip = &mod.intern_pool;
638 const zcu = pt.zcu;
639 const ip = &zcu.intern_pool;
640640 const air_tags = self.air.instructions.items(.tag);
641641
642642 for (body) |inst| {
......@@ -999,10 +999,10 @@ fn allocMem(
999999/// Use a pointer instruction as the basis for allocating stack memory.
10001000fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10011001 const pt = self.pt;
1002 const mod = pt.zcu;
1003 const elem_ty = self.typeOfIndex(inst).childType(mod);
1002 const zcu = pt.zcu;
1003 const elem_ty = self.typeOfIndex(inst).childType(zcu);
10041004
1005 if (!elem_ty.hasRuntimeBits(pt)) {
1005 if (!elem_ty.hasRuntimeBits(zcu)) {
10061006 // As this stack item will never be dereferenced at runtime,
10071007 // return the stack offset 0. Stack offset 0 will be where all
10081008 // zero-sized stack allocations live as non-zero-sized
......@@ -1010,21 +1010,21 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10101010 return 0;
10111011 }
10121012
1013 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
1013 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
10141014 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
10151015 };
10161016 // TODO swap this for inst.ty.ptrAlign
1017 const abi_align = elem_ty.abiAlignment(pt);
1017 const abi_align = elem_ty.abiAlignment(zcu);
10181018
10191019 return self.allocMem(abi_size, abi_align, inst);
10201020}
10211021
10221022fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst.Index) !MCValue {
10231023 const pt = self.pt;
1024 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
1024 const abi_size = math.cast(u32, elem_ty.abiSize(pt.zcu)) orelse {
10251025 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
10261026 };
1027 const abi_align = elem_ty.abiAlignment(pt);
1027 const abi_align = elem_ty.abiAlignment(pt.zcu);
10281028
10291029 if (reg_ok) {
10301030 // Make sure the type can fit in a register before we try to allocate one.
......@@ -1108,13 +1108,13 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
11081108
11091109fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
11101110 const pt = self.pt;
1111 const mod = pt.zcu;
1111 const zcu = pt.zcu;
11121112 const result: MCValue = switch (self.ret_mcv) {
11131113 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },
11141114 .stack_offset => blk: {
11151115 // self.ret_mcv is an address to where this function
11161116 // should store its result into
1117 const ret_ty = self.fn_type.fnReturnType(mod);
1117 const ret_ty = self.fn_type.fnReturnType(zcu);
11181118 const ptr_ty = try pt.singleMutPtrType(ret_ty);
11191119
11201120 // addr_reg will contain the address of where to store the
......@@ -1142,7 +1142,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
11421142
11431143fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
11441144 const pt = self.pt;
1145 const mod = pt.zcu;
1145 const zcu = pt.zcu;
11461146 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
11471147 if (self.liveness.isUnused(inst))
11481148 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
......@@ -1151,10 +1151,10 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
11511151 const operand_ty = self.typeOf(ty_op.operand);
11521152 const dest_ty = self.typeOfIndex(inst);
11531153
1154 const operand_abi_size = operand_ty.abiSize(pt);
1155 const dest_abi_size = dest_ty.abiSize(pt);
1156 const info_a = operand_ty.intInfo(mod);
1157 const info_b = dest_ty.intInfo(mod);
1154 const operand_abi_size = operand_ty.abiSize(zcu);
1155 const dest_abi_size = dest_ty.abiSize(zcu);
1156 const info_a = operand_ty.intInfo(zcu);
1157 const info_b = dest_ty.intInfo(zcu);
11581158
11591159 const dst_mcv: MCValue = blk: {
11601160 if (info_a.bits == info_b.bits) {
......@@ -1209,9 +1209,9 @@ fn trunc(
12091209 dest_ty: Type,
12101210) !MCValue {
12111211 const pt = self.pt;
1212 const mod = pt.zcu;
1213 const info_a = operand_ty.intInfo(mod);
1214 const info_b = dest_ty.intInfo(mod);
1212 const zcu = pt.zcu;
1213 const info_a = operand_ty.intInfo(zcu);
1214 const info_b = dest_ty.intInfo(zcu);
12151215
12161216 if (info_b.bits <= 32) {
12171217 if (info_a.bits > 32) {
......@@ -1274,7 +1274,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
12741274fn airNot(self: *Self, inst: Air.Inst.Index) !void {
12751275 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
12761276 const pt = self.pt;
1277 const mod = pt.zcu;
1277 const zcu = pt.zcu;
12781278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
12791279 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
12801280 const operand_ty = self.typeOf(ty_op.operand);
......@@ -1283,7 +1283,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
12831283 .unreach => unreachable,
12841284 .cpsr_flags => |cond| break :result MCValue{ .cpsr_flags = cond.negate() },
12851285 else => {
1286 switch (operand_ty.zigTypeTag(mod)) {
1286 switch (operand_ty.zigTypeTag(zcu)) {
12871287 .Bool => {
12881288 var op_reg: Register = undefined;
12891289 var dest_reg: Register = undefined;
......@@ -1316,7 +1316,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
13161316 },
13171317 .Vector => return self.fail("TODO bitwise not for vectors", .{}),
13181318 .Int => {
1319 const int_info = operand_ty.intInfo(mod);
1319 const int_info = operand_ty.intInfo(zcu);
13201320 if (int_info.bits <= 32) {
13211321 var op_reg: Register = undefined;
13221322 var dest_reg: Register = undefined;
......@@ -1371,13 +1371,13 @@ fn minMax(
13711371 maybe_inst: ?Air.Inst.Index,
13721372) !MCValue {
13731373 const pt = self.pt;
1374 const mod = pt.zcu;
1375 switch (lhs_ty.zigTypeTag(mod)) {
1374 const zcu = pt.zcu;
1375 switch (lhs_ty.zigTypeTag(zcu)) {
13761376 .Float => return self.fail("TODO ARM min/max on floats", .{}),
13771377 .Vector => return self.fail("TODO ARM min/max on vectors", .{}),
13781378 .Int => {
1379 assert(lhs_ty.eql(rhs_ty, mod));
1380 const int_info = lhs_ty.intInfo(mod);
1379 assert(lhs_ty.eql(rhs_ty, zcu));
1380 const int_info = lhs_ty.intInfo(zcu);
13811381 if (int_info.bits <= 32) {
13821382 var lhs_reg: Register = undefined;
13831383 var rhs_reg: Register = undefined;
......@@ -1581,7 +1581,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
15811581 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
15821582 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
15831583 const pt = self.pt;
1584 const mod = pt.zcu;
1584 const zcu = pt.zcu;
15851585 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
15861586 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
15871587 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
......@@ -1589,15 +1589,15 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
15891589 const rhs_ty = self.typeOf(extra.rhs);
15901590
15911591 const tuple_ty = self.typeOfIndex(inst);
1592 const tuple_size: u32 = @intCast(tuple_ty.abiSize(pt));
1593 const tuple_align = tuple_ty.abiAlignment(pt);
1594 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, pt));
1592 const tuple_size: u32 = @intCast(tuple_ty.abiSize(zcu));
1593 const tuple_align = tuple_ty.abiAlignment(zcu);
1594 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, zcu));
15951595
1596 switch (lhs_ty.zigTypeTag(mod)) {
1596 switch (lhs_ty.zigTypeTag(zcu)) {
15971597 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
15981598 .Int => {
1599 assert(lhs_ty.eql(rhs_ty, mod));
1600 const int_info = lhs_ty.intInfo(mod);
1599 assert(lhs_ty.eql(rhs_ty, zcu));
1600 const int_info = lhs_ty.intInfo(zcu);
16011601 if (int_info.bits < 32) {
16021602 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);
16031603
......@@ -1695,7 +1695,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
16951695 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
16961696 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
16971697 const pt = self.pt;
1698 const mod = pt.zcu;
1698 const zcu = pt.zcu;
16991699 const result: MCValue = result: {
17001700 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
17011701 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
......@@ -1703,15 +1703,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
17031703 const rhs_ty = self.typeOf(extra.rhs);
17041704
17051705 const tuple_ty = self.typeOfIndex(inst);
1706 const tuple_size: u32 = @intCast(tuple_ty.abiSize(pt));
1707 const tuple_align = tuple_ty.abiAlignment(pt);
1708 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, pt));
1706 const tuple_size: u32 = @intCast(tuple_ty.abiSize(zcu));
1707 const tuple_align = tuple_ty.abiAlignment(zcu);
1708 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, zcu));
17091709
1710 switch (lhs_ty.zigTypeTag(mod)) {
1710 switch (lhs_ty.zigTypeTag(zcu)) {
17111711 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
17121712 .Int => {
1713 assert(lhs_ty.eql(rhs_ty, mod));
1714 const int_info = lhs_ty.intInfo(mod);
1713 assert(lhs_ty.eql(rhs_ty, zcu));
1714 const int_info = lhs_ty.intInfo(zcu);
17151715 if (int_info.bits <= 16) {
17161716 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);
17171717
......@@ -1860,20 +1860,20 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
18601860 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
18611861 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
18621862 const pt = self.pt;
1863 const mod = pt.zcu;
1863 const zcu = pt.zcu;
18641864 const result: MCValue = result: {
18651865 const lhs_ty = self.typeOf(extra.lhs);
18661866 const rhs_ty = self.typeOf(extra.rhs);
18671867
18681868 const tuple_ty = self.typeOfIndex(inst);
1869 const tuple_size: u32 = @intCast(tuple_ty.abiSize(pt));
1870 const tuple_align = tuple_ty.abiAlignment(pt);
1871 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, pt));
1869 const tuple_size: u32 = @intCast(tuple_ty.abiSize(zcu));
1870 const tuple_align = tuple_ty.abiAlignment(zcu);
1871 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, zcu));
18721872
1873 switch (lhs_ty.zigTypeTag(mod)) {
1873 switch (lhs_ty.zigTypeTag(zcu)) {
18741874 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
18751875 .Int => {
1876 const int_info = lhs_ty.intInfo(mod);
1876 const int_info = lhs_ty.intInfo(zcu);
18771877 if (int_info.bits <= 32) {
18781878 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);
18791879
......@@ -2020,7 +2020,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
20202020 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
20212021 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20222022 const optional_ty = self.typeOfIndex(inst);
2023 const abi_size: u32 = @intCast(optional_ty.abiSize(pt));
2023 const abi_size: u32 = @intCast(optional_ty.abiSize(pt.zcu));
20242024
20252025 // Optional with a zero-bit payload type is just a boolean true
20262026 if (abi_size == 1) {
......@@ -2040,17 +2040,17 @@ fn errUnionErr(
20402040 maybe_inst: ?Air.Inst.Index,
20412041) !MCValue {
20422042 const pt = self.pt;
2043 const mod = pt.zcu;
2044 const err_ty = error_union_ty.errorUnionSet(mod);
2045 const payload_ty = error_union_ty.errorUnionPayload(mod);
2046 if (err_ty.errorSetIsEmpty(mod)) {
2043 const zcu = pt.zcu;
2044 const err_ty = error_union_ty.errorUnionSet(zcu);
2045 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2046 if (err_ty.errorSetIsEmpty(zcu)) {
20472047 return MCValue{ .immediate = 0 };
20482048 }
2049 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2049 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
20502050 return try error_union_bind.resolveToMcv(self);
20512051 }
20522052
2053 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, pt));
2053 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, zcu));
20542054 switch (try error_union_bind.resolveToMcv(self)) {
20552055 .register => {
20562056 var operand_reg: Register = undefined;
......@@ -2072,7 +2072,7 @@ fn errUnionErr(
20722072 );
20732073
20742074 const err_bit_offset = err_offset * 8;
2075 const err_bit_size: u32 = @intCast(err_ty.abiSize(pt) * 8);
2075 const err_bit_size: u32 = @intCast(err_ty.abiSize(zcu) * 8);
20762076
20772077 _ = try self.addInst(.{
20782078 .tag = .ubfx, // errors are unsigned integers
......@@ -2118,17 +2118,17 @@ fn errUnionPayload(
21182118 maybe_inst: ?Air.Inst.Index,
21192119) !MCValue {
21202120 const pt = self.pt;
2121 const mod = pt.zcu;
2122 const err_ty = error_union_ty.errorUnionSet(mod);
2123 const payload_ty = error_union_ty.errorUnionPayload(mod);
2124 if (err_ty.errorSetIsEmpty(mod)) {
2121 const zcu = pt.zcu;
2122 const err_ty = error_union_ty.errorUnionSet(zcu);
2123 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2124 if (err_ty.errorSetIsEmpty(zcu)) {
21252125 return try error_union_bind.resolveToMcv(self);
21262126 }
2127 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2127 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
21282128 return MCValue.none;
21292129 }
21302130
2131 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, pt));
2131 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
21322132 switch (try error_union_bind.resolveToMcv(self)) {
21332133 .register => {
21342134 var operand_reg: Register = undefined;
......@@ -2150,10 +2150,10 @@ fn errUnionPayload(
21502150 );
21512151
21522152 const payload_bit_offset = payload_offset * 8;
2153 const payload_bit_size: u32 = @intCast(payload_ty.abiSize(pt) * 8);
2153 const payload_bit_size: u32 = @intCast(payload_ty.abiSize(zcu) * 8);
21542154
21552155 _ = try self.addInst(.{
2156 .tag = if (payload_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
2156 .tag = if (payload_ty.isSignedInt(zcu)) Mir.Inst.Tag.sbfx else .ubfx,
21572157 .data = .{ .rr_lsb_width = .{
21582158 .rd = dest_reg,
21592159 .rn = operand_reg,
......@@ -2229,20 +2229,20 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
22292229/// T to E!T
22302230fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
22312231 const pt = self.pt;
2232 const mod = pt.zcu;
2232 const zcu = pt.zcu;
22332233 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
22342234 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
22352235 const error_union_ty = ty_op.ty.toType();
2236 const error_ty = error_union_ty.errorUnionSet(mod);
2237 const payload_ty = error_union_ty.errorUnionPayload(mod);
2236 const error_ty = error_union_ty.errorUnionSet(zcu);
2237 const payload_ty = error_union_ty.errorUnionPayload(zcu);
22382238 const operand = try self.resolveInst(ty_op.operand);
2239 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result operand;
2239 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result operand;
22402240
2241 const abi_size: u32 = @intCast(error_union_ty.abiSize(pt));
2242 const abi_align = error_union_ty.abiAlignment(pt);
2241 const abi_size: u32 = @intCast(error_union_ty.abiSize(zcu));
2242 const abi_align = error_union_ty.abiAlignment(zcu);
22432243 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));
2244 const payload_off = errUnionPayloadOffset(payload_ty, pt);
2245 const err_off = errUnionErrorOffset(payload_ty, pt);
2244 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
2245 const err_off = errUnionErrorOffset(payload_ty, zcu);
22462246 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
22472247 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });
22482248
......@@ -2254,20 +2254,20 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
22542254/// E to E!T
22552255fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
22562256 const pt = self.pt;
2257 const mod = pt.zcu;
2257 const zcu = pt.zcu;
22582258 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
22592259 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
22602260 const error_union_ty = ty_op.ty.toType();
2261 const error_ty = error_union_ty.errorUnionSet(mod);
2262 const payload_ty = error_union_ty.errorUnionPayload(mod);
2261 const error_ty = error_union_ty.errorUnionSet(zcu);
2262 const payload_ty = error_union_ty.errorUnionPayload(zcu);
22632263 const operand = try self.resolveInst(ty_op.operand);
2264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result operand;
2264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result operand;
22652265
2266 const abi_size: u32 = @intCast(error_union_ty.abiSize(pt));
2267 const abi_align = error_union_ty.abiAlignment(pt);
2266 const abi_size: u32 = @intCast(error_union_ty.abiSize(zcu));
2267 const abi_align = error_union_ty.abiAlignment(zcu);
22682268 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));
2269 const payload_off = errUnionPayloadOffset(payload_ty, pt);
2270 const err_off = errUnionErrorOffset(payload_ty, pt);
2269 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
2270 const err_off = errUnionErrorOffset(payload_ty, zcu);
22712271 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
22722272 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);
22732273
......@@ -2372,9 +2372,9 @@ fn ptrElemVal(
23722372 maybe_inst: ?Air.Inst.Index,
23732373) !MCValue {
23742374 const pt = self.pt;
2375 const mod = pt.zcu;
2376 const elem_ty = ptr_ty.childType(mod);
2377 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));
2375 const zcu = pt.zcu;
2376 const elem_ty = ptr_ty.childType(zcu);
2377 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
23782378
23792379 switch (elem_size) {
23802380 1, 4 => {
......@@ -2432,11 +2432,11 @@ fn ptrElemVal(
24322432
24332433fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24342434 const pt = self.pt;
2435 const mod = pt.zcu;
2435 const zcu = pt.zcu;
24362436 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
24372437 const slice_ty = self.typeOf(bin_op.lhs);
2438 const result: MCValue = if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
2439 const ptr_ty = slice_ty.slicePtrFieldType(mod);
2438 const result: MCValue = if (!slice_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) .dead else result: {
2439 const ptr_ty = slice_ty.slicePtrFieldType(zcu);
24402440
24412441 const slice_mcv = try self.resolveInst(bin_op.lhs);
24422442 const base_mcv = slicePtr(slice_mcv);
......@@ -2476,8 +2476,8 @@ fn arrayElemVal(
24762476 maybe_inst: ?Air.Inst.Index,
24772477) InnerError!MCValue {
24782478 const pt = self.pt;
2479 const mod = pt.zcu;
2480 const elem_ty = array_ty.childType(mod);
2479 const zcu = pt.zcu;
2480 const elem_ty = array_ty.childType(zcu);
24812481
24822482 const mcv = try array_bind.resolveToMcv(self);
24832483 switch (mcv) {
......@@ -2533,10 +2533,10 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
25332533
25342534fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
25352535 const pt = self.pt;
2536 const mod = pt.zcu;
2536 const zcu = pt.zcu;
25372537 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
25382538 const ptr_ty = self.typeOf(bin_op.lhs);
2539 const result: MCValue = if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) .dead else result: {
2539 const result: MCValue = if (!ptr_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) .dead else result: {
25402540 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
25412541 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
25422542
......@@ -2668,9 +2668,9 @@ fn reuseOperand(
26682668
26692669fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
26702670 const pt = self.pt;
2671 const mod = pt.zcu;
2672 const elem_ty = ptr_ty.childType(mod);
2673 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));
2671 const zcu = pt.zcu;
2672 const elem_ty = ptr_ty.childType(zcu);
2673 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
26742674
26752675 switch (ptr) {
26762676 .none => unreachable,
......@@ -2746,20 +2746,20 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
27462746
27472747fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27482748 const pt = self.pt;
2749 const mod = pt.zcu;
2749 const zcu = pt.zcu;
27502750 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
27512751 const elem_ty = self.typeOfIndex(inst);
27522752 const result: MCValue = result: {
2753 if (!elem_ty.hasRuntimeBits(pt))
2753 if (!elem_ty.hasRuntimeBits(zcu))
27542754 break :result MCValue.none;
27552755
27562756 const ptr = try self.resolveInst(ty_op.operand);
2757 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(mod);
2757 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(zcu);
27582758 if (self.liveness.isUnused(inst) and !is_volatile)
27592759 break :result MCValue.dead;
27602760
27612761 const dest_mcv: MCValue = blk: {
2762 const ptr_fits_dest = elem_ty.abiSize(pt) <= 4;
2762 const ptr_fits_dest = elem_ty.abiSize(zcu) <= 4;
27632763 if (ptr_fits_dest and self.reuseOperand(inst, ty_op.operand, 0, ptr)) {
27642764 // The MCValue that holds the pointer can be re-used as the value.
27652765 break :blk ptr;
......@@ -2776,7 +2776,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27762776
27772777fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
27782778 const pt = self.pt;
2779 const elem_size: u32 = @intCast(value_ty.abiSize(pt));
2779 const elem_size: u32 = @intCast(value_ty.abiSize(pt.zcu));
27802780
27812781 switch (ptr) {
27822782 .none => unreachable,
......@@ -2896,11 +2896,11 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
28962896fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
28972897 return if (self.liveness.isUnused(inst)) .dead else result: {
28982898 const pt = self.pt;
2899 const mod = pt.zcu;
2899 const zcu = pt.zcu;
29002900 const mcv = try self.resolveInst(operand);
29012901 const ptr_ty = self.typeOf(operand);
2902 const struct_ty = ptr_ty.childType(mod);
2903 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, pt));
2902 const struct_ty = ptr_ty.childType(zcu);
2903 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, zcu));
29042904 switch (mcv) {
29052905 .ptr_stack_offset => |off| {
29062906 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
......@@ -2921,12 +2921,12 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
29212921 const operand = extra.struct_operand;
29222922 const index = extra.field_index;
29232923 const pt = self.pt;
2924 const mod = pt.zcu;
2924 const zcu = pt.zcu;
29252925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
29262926 const mcv = try self.resolveInst(operand);
29272927 const struct_ty = self.typeOf(operand);
2928 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, pt));
2929 const struct_field_ty = struct_ty.structFieldType(index, mod);
2928 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, zcu));
2929 const struct_field_ty = struct_ty.structFieldType(index, zcu);
29302930
29312931 switch (mcv) {
29322932 .dead, .unreach => unreachable,
......@@ -2989,10 +2989,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
29892989 );
29902990
29912991 const field_bit_offset = struct_field_offset * 8;
2992 const field_bit_size: u32 = @intCast(struct_field_ty.abiSize(pt) * 8);
2992 const field_bit_size: u32 = @intCast(struct_field_ty.abiSize(zcu) * 8);
29932993
29942994 _ = try self.addInst(.{
2995 .tag = if (struct_field_ty.isSignedInt(mod)) Mir.Inst.Tag.sbfx else .ubfx,
2995 .tag = if (struct_field_ty.isSignedInt(zcu)) Mir.Inst.Tag.sbfx else .ubfx,
29962996 .data = .{ .rr_lsb_width = .{
29972997 .rd = dest_reg,
29982998 .rn = operand_reg,
......@@ -3012,18 +3012,18 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
30123012
30133013fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
30143014 const pt = self.pt;
3015 const mod = pt.zcu;
3015 const zcu = pt.zcu;
30163016 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
30173017 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
30183018 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
30193019 const field_ptr = try self.resolveInst(extra.field_ptr);
3020 const struct_ty = ty_pl.ty.toType().childType(mod);
3020 const struct_ty = ty_pl.ty.toType().childType(zcu);
30213021
3022 if (struct_ty.zigTypeTag(mod) == .Union) {
3022 if (struct_ty.zigTypeTag(zcu) == .Union) {
30233023 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});
30243024 }
30253025
3026 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(extra.field_index, pt));
3026 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(extra.field_index, zcu));
30273027 switch (field_ptr) {
30283028 .ptr_stack_offset => |off| {
30293029 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
......@@ -3407,13 +3407,13 @@ fn addSub(
34073407 maybe_inst: ?Air.Inst.Index,
34083408) InnerError!MCValue {
34093409 const pt = self.pt;
3410 const mod = pt.zcu;
3411 switch (lhs_ty.zigTypeTag(mod)) {
3410 const zcu = pt.zcu;
3411 switch (lhs_ty.zigTypeTag(zcu)) {
34123412 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
34133413 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
34143414 .Int => {
3415 assert(lhs_ty.eql(rhs_ty, mod));
3416 const int_info = lhs_ty.intInfo(mod);
3415 assert(lhs_ty.eql(rhs_ty, zcu));
3416 const int_info = lhs_ty.intInfo(zcu);
34173417 if (int_info.bits <= 32) {
34183418 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
34193419 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
......@@ -3464,13 +3464,13 @@ fn mul(
34643464 maybe_inst: ?Air.Inst.Index,
34653465) InnerError!MCValue {
34663466 const pt = self.pt;
3467 const mod = pt.zcu;
3468 switch (lhs_ty.zigTypeTag(mod)) {
3467 const zcu = pt.zcu;
3468 switch (lhs_ty.zigTypeTag(zcu)) {
34693469 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
34703470 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
34713471 .Int => {
3472 assert(lhs_ty.eql(rhs_ty, mod));
3473 const int_info = lhs_ty.intInfo(mod);
3472 assert(lhs_ty.eql(rhs_ty, zcu));
3473 const int_info = lhs_ty.intInfo(zcu);
34743474 if (int_info.bits <= 32) {
34753475 // TODO add optimisations for multiplication
34763476 // with immediates, for example a * 2 can be
......@@ -3498,8 +3498,8 @@ fn divFloat(
34983498 _ = maybe_inst;
34993499
35003500 const pt = self.pt;
3501 const mod = pt.zcu;
3502 switch (lhs_ty.zigTypeTag(mod)) {
3501 const zcu = pt.zcu;
3502 switch (lhs_ty.zigTypeTag(zcu)) {
35033503 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
35043504 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
35053505 else => unreachable,
......@@ -3515,13 +3515,13 @@ fn divTrunc(
35153515 maybe_inst: ?Air.Inst.Index,
35163516) InnerError!MCValue {
35173517 const pt = self.pt;
3518 const mod = pt.zcu;
3519 switch (lhs_ty.zigTypeTag(mod)) {
3518 const zcu = pt.zcu;
3519 switch (lhs_ty.zigTypeTag(zcu)) {
35203520 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
35213521 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
35223522 .Int => {
3523 assert(lhs_ty.eql(rhs_ty, mod));
3524 const int_info = lhs_ty.intInfo(mod);
3523 assert(lhs_ty.eql(rhs_ty, zcu));
3524 const int_info = lhs_ty.intInfo(zcu);
35253525 if (int_info.bits <= 32) {
35263526 switch (int_info.signedness) {
35273527 .signed => {
......@@ -3559,13 +3559,13 @@ fn divFloor(
35593559 maybe_inst: ?Air.Inst.Index,
35603560) InnerError!MCValue {
35613561 const pt = self.pt;
3562 const mod = pt.zcu;
3563 switch (lhs_ty.zigTypeTag(mod)) {
3562 const zcu = pt.zcu;
3563 switch (lhs_ty.zigTypeTag(zcu)) {
35643564 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
35653565 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
35663566 .Int => {
3567 assert(lhs_ty.eql(rhs_ty, mod));
3568 const int_info = lhs_ty.intInfo(mod);
3567 assert(lhs_ty.eql(rhs_ty, zcu));
3568 const int_info = lhs_ty.intInfo(zcu);
35693569 if (int_info.bits <= 32) {
35703570 switch (int_info.signedness) {
35713571 .signed => {
......@@ -3608,8 +3608,8 @@ fn divExact(
36083608 _ = maybe_inst;
36093609
36103610 const pt = self.pt;
3611 const mod = pt.zcu;
3612 switch (lhs_ty.zigTypeTag(mod)) {
3611 const zcu = pt.zcu;
3612 switch (lhs_ty.zigTypeTag(zcu)) {
36133613 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
36143614 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
36153615 .Int => return self.fail("TODO ARM div_exact", .{}),
......@@ -3626,17 +3626,17 @@ fn rem(
36263626 maybe_inst: ?Air.Inst.Index,
36273627) InnerError!MCValue {
36283628 const pt = self.pt;
3629 const mod = pt.zcu;
3630 switch (lhs_ty.zigTypeTag(mod)) {
3629 const zcu = pt.zcu;
3630 switch (lhs_ty.zigTypeTag(zcu)) {
36313631 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
36323632 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
36333633 .Int => {
3634 assert(lhs_ty.eql(rhs_ty, mod));
3635 const int_info = lhs_ty.intInfo(mod);
3634 assert(lhs_ty.eql(rhs_ty, zcu));
3635 const int_info = lhs_ty.intInfo(zcu);
36363636 if (int_info.bits <= 32) {
36373637 switch (int_info.signedness) {
36383638 .signed => {
3639 return self.fail("TODO ARM signed integer mod", .{});
3639 return self.fail("TODO ARM signed integer zcu", .{});
36403640 },
36413641 .unsigned => {
36423642 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
......@@ -3667,10 +3667,10 @@ fn rem(
36673667
36683668 return MCValue{ .register = dest_reg };
36693669 } else {
3670 return self.fail("TODO ARM integer mod by constants", .{});
3670 return self.fail("TODO ARM integer zcu by constants", .{});
36713671 }
36723672 } else {
3673 return self.fail("TODO ARM integer mod", .{});
3673 return self.fail("TODO ARM integer zcu", .{});
36743674 }
36753675 },
36763676 }
......@@ -3696,11 +3696,11 @@ fn modulo(
36963696 _ = maybe_inst;
36973697
36983698 const pt = self.pt;
3699 const mod = pt.zcu;
3700 switch (lhs_ty.zigTypeTag(mod)) {
3699 const zcu = pt.zcu;
3700 switch (lhs_ty.zigTypeTag(zcu)) {
37013701 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
37023702 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3703 .Int => return self.fail("TODO ARM mod", .{}),
3703 .Int => return self.fail("TODO ARM zcu", .{}),
37043704 else => unreachable,
37053705 }
37063706}
......@@ -3715,11 +3715,11 @@ fn wrappingArithmetic(
37153715 maybe_inst: ?Air.Inst.Index,
37163716) InnerError!MCValue {
37173717 const pt = self.pt;
3718 const mod = pt.zcu;
3719 switch (lhs_ty.zigTypeTag(mod)) {
3718 const zcu = pt.zcu;
3719 switch (lhs_ty.zigTypeTag(zcu)) {
37203720 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
37213721 .Int => {
3722 const int_info = lhs_ty.intInfo(mod);
3722 const int_info = lhs_ty.intInfo(zcu);
37233723 if (int_info.bits <= 32) {
37243724 // Generate an add/sub/mul
37253725 const result: MCValue = switch (tag) {
......@@ -3754,12 +3754,12 @@ fn bitwise(
37543754 maybe_inst: ?Air.Inst.Index,
37553755) InnerError!MCValue {
37563756 const pt = self.pt;
3757 const mod = pt.zcu;
3758 switch (lhs_ty.zigTypeTag(mod)) {
3757 const zcu = pt.zcu;
3758 switch (lhs_ty.zigTypeTag(zcu)) {
37593759 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
37603760 .Int => {
3761 assert(lhs_ty.eql(rhs_ty, mod));
3762 const int_info = lhs_ty.intInfo(mod);
3761 assert(lhs_ty.eql(rhs_ty, zcu));
3762 const int_info = lhs_ty.intInfo(zcu);
37633763 if (int_info.bits <= 32) {
37643764 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
37653765 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
......@@ -3800,17 +3800,17 @@ fn shiftExact(
38003800 maybe_inst: ?Air.Inst.Index,
38013801) InnerError!MCValue {
38023802 const pt = self.pt;
3803 const mod = pt.zcu;
3804 switch (lhs_ty.zigTypeTag(mod)) {
3803 const zcu = pt.zcu;
3804 switch (lhs_ty.zigTypeTag(zcu)) {
38053805 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
38063806 .Int => {
3807 const int_info = lhs_ty.intInfo(mod);
3807 const int_info = lhs_ty.intInfo(zcu);
38083808 if (int_info.bits <= 32) {
38093809 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
38103810
38113811 const mir_tag: Mir.Inst.Tag = switch (tag) {
38123812 .shl_exact => .lsl,
3813 .shr_exact => switch (lhs_ty.intInfo(mod).signedness) {
3813 .shr_exact => switch (lhs_ty.intInfo(zcu).signedness) {
38143814 .signed => Mir.Inst.Tag.asr,
38153815 .unsigned => Mir.Inst.Tag.lsr,
38163816 },
......@@ -3840,11 +3840,11 @@ fn shiftNormal(
38403840 maybe_inst: ?Air.Inst.Index,
38413841) InnerError!MCValue {
38423842 const pt = self.pt;
3843 const mod = pt.zcu;
3844 switch (lhs_ty.zigTypeTag(mod)) {
3843 const zcu = pt.zcu;
3844 switch (lhs_ty.zigTypeTag(zcu)) {
38453845 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
38463846 .Int => {
3847 const int_info = lhs_ty.intInfo(mod);
3847 const int_info = lhs_ty.intInfo(zcu);
38483848 if (int_info.bits <= 32) {
38493849 // Generate a shl_exact/shr_exact
38503850 const result: MCValue = switch (tag) {
......@@ -3884,8 +3884,8 @@ fn booleanOp(
38843884 maybe_inst: ?Air.Inst.Index,
38853885) InnerError!MCValue {
38863886 const pt = self.pt;
3887 const mod = pt.zcu;
3888 switch (lhs_ty.zigTypeTag(mod)) {
3887 const zcu = pt.zcu;
3888 switch (lhs_ty.zigTypeTag(zcu)) {
38893889 .Bool => {
38903890 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
38913891 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
......@@ -3919,17 +3919,17 @@ fn ptrArithmetic(
39193919 maybe_inst: ?Air.Inst.Index,
39203920) InnerError!MCValue {
39213921 const pt = self.pt;
3922 const mod = pt.zcu;
3923 switch (lhs_ty.zigTypeTag(mod)) {
3922 const zcu = pt.zcu;
3923 switch (lhs_ty.zigTypeTag(zcu)) {
39243924 .Pointer => {
3925 assert(rhs_ty.eql(Type.usize, mod));
3925 assert(rhs_ty.eql(Type.usize, zcu));
39263926
39273927 const ptr_ty = lhs_ty;
3928 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
3929 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
3930 else => ptr_ty.childType(mod),
3928 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
3929 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
3930 else => ptr_ty.childType(zcu),
39313931 };
3932 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));
3932 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
39333933
39343934 const base_tag: Air.Inst.Tag = switch (tag) {
39353935 .ptr_add => .add,
......@@ -3957,12 +3957,12 @@ fn ptrArithmetic(
39573957
39583958fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type) !void {
39593959 const pt = self.pt;
3960 const mod = pt.zcu;
3961 const abi_size = ty.abiSize(pt);
3960 const zcu = pt.zcu;
3961 const abi_size = ty.abiSize(zcu);
39623962
39633963 const tag: Mir.Inst.Tag = switch (abi_size) {
3964 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,
3965 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh else .ldrh,
3964 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb else .ldrb,
3965 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh else .ldrh,
39663966 3, 4 => .ldr,
39673967 else => unreachable,
39683968 };
......@@ -3979,7 +3979,7 @@ fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type)
39793979 } };
39803980
39813981 const data: Mir.Inst.Data = switch (abi_size) {
3982 1 => if (ty.isSignedInt(mod)) rr_extra_offset else rr_offset,
3982 1 => if (ty.isSignedInt(zcu)) rr_extra_offset else rr_offset,
39833983 2 => rr_extra_offset,
39843984 3, 4 => rr_offset,
39853985 else => unreachable,
......@@ -3993,7 +3993,7 @@ fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type)
39933993
39943994fn genStrRegister(self: *Self, source_reg: Register, addr_reg: Register, ty: Type) !void {
39953995 const pt = self.pt;
3996 const abi_size = ty.abiSize(pt);
3996 const abi_size = ty.abiSize(pt.zcu);
39973997
39983998 const tag: Mir.Inst.Tag = switch (abi_size) {
39993999 1 => .strb,
......@@ -4253,12 +4253,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42534253 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
42544254 const ty = self.typeOf(callee);
42554255 const pt = self.pt;
4256 const mod = pt.zcu;
4257 const ip = &mod.intern_pool;
4256 const zcu = pt.zcu;
4257 const ip = &zcu.intern_pool;
42584258
4259 const fn_ty = switch (ty.zigTypeTag(mod)) {
4259 const fn_ty = switch (ty.zigTypeTag(zcu)) {
42604260 .Fn => ty,
4261 .Pointer => ty.childType(mod),
4261 .Pointer => ty.childType(zcu),
42624262 else => unreachable,
42634263 };
42644264
......@@ -4283,9 +4283,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42834283 // untouched by the parameter passing code
42844284 const r0_lock: ?RegisterLock = if (info.return_value == .stack_offset) blk: {
42854285 log.debug("airCall: return by reference", .{});
4286 const ret_ty = fn_ty.fnReturnType(mod);
4287 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(pt));
4288 const ret_abi_align = ret_ty.abiAlignment(pt);
4286 const ret_ty = fn_ty.fnReturnType(zcu);
4287 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(zcu));
4288 const ret_abi_align = ret_ty.abiAlignment(zcu);
42894289 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
42904290
42914291 const ptr_ty = try pt.singleMutPtrType(ret_ty);
......@@ -4335,7 +4335,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43354335 return self.fail("TODO implement calling bitcasted functions", .{});
43364336 },
43374337 } else {
4338 assert(ty.zigTypeTag(mod) == .Pointer);
4338 assert(ty.zigTypeTag(zcu) == .Pointer);
43394339 const mcv = try self.resolveInst(callee);
43404340
43414341 try self.genSetReg(Type.usize, .lr, mcv);
......@@ -4370,7 +4370,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43704370 if (RegisterManager.indexOfRegIntoTracked(reg) == null) {
43714371 // Save function return value into a tracked register
43724372 log.debug("airCall: copying {} as it is not tracked", .{reg});
4373 const new_reg = try self.copyToTmpRegister(fn_ty.fnReturnType(mod), info.return_value);
4373 const new_reg = try self.copyToTmpRegister(fn_ty.fnReturnType(zcu), info.return_value);
43744374 break :result MCValue{ .register = new_reg };
43754375 }
43764376 },
......@@ -4395,15 +4395,15 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43954395
43964396fn airRet(self: *Self, inst: Air.Inst.Index) !void {
43974397 const pt = self.pt;
4398 const mod = pt.zcu;
4398 const zcu = pt.zcu;
43994399 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
44004400 const operand = try self.resolveInst(un_op);
4401 const ret_ty = self.fn_type.fnReturnType(mod);
4401 const ret_ty = self.fn_type.fnReturnType(zcu);
44024402
44034403 switch (self.ret_mcv) {
44044404 .none => {},
44054405 .immediate => {
4406 assert(ret_ty.isError(mod));
4406 assert(ret_ty.isError(zcu));
44074407 },
44084408 .register => |reg| {
44094409 // Return result by value
......@@ -4428,11 +4428,11 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44284428
44294429fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44304430 const pt = self.pt;
4431 const mod = pt.zcu;
4431 const zcu = pt.zcu;
44324432 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
44334433 const ptr = try self.resolveInst(un_op);
44344434 const ptr_ty = self.typeOf(un_op);
4435 const ret_ty = self.fn_type.fnReturnType(mod);
4435 const ret_ty = self.fn_type.fnReturnType(zcu);
44364436
44374437 switch (self.ret_mcv) {
44384438 .none => {},
......@@ -4452,8 +4452,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
44524452 // location.
44534453 const op_inst = un_op.toIndex().?;
44544454 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
4455 const abi_size: u32 = @intCast(ret_ty.abiSize(pt));
4456 const abi_align = ret_ty.abiAlignment(pt);
4455 const abi_size: u32 = @intCast(ret_ty.abiSize(zcu));
4456 const abi_align = ret_ty.abiAlignment(zcu);
44574457
44584458 const offset = try self.allocMem(abi_size, abi_align, null);
44594459
......@@ -4490,20 +4490,20 @@ fn cmp(
44904490 op: math.CompareOperator,
44914491) !MCValue {
44924492 const pt = self.pt;
4493 const mod = pt.zcu;
4494 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {
4493 const zcu = pt.zcu;
4494 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {
44954495 .Optional => blk: {
4496 const payload_ty = lhs_ty.optionalChild(mod);
4497 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4496 const payload_ty = lhs_ty.optionalChild(zcu);
4497 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
44984498 break :blk Type.u1;
4499 } else if (lhs_ty.isPtrLikeOptional(mod)) {
4499 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
45004500 break :blk Type.usize;
45014501 } else {
45024502 return self.fail("TODO ARM cmp non-pointer optionals", .{});
45034503 }
45044504 },
45054505 .Float => return self.fail("TODO ARM cmp floats", .{}),
4506 .Enum => lhs_ty.intTagType(mod),
4506 .Enum => lhs_ty.intTagType(zcu),
45074507 .Int => lhs_ty,
45084508 .Bool => Type.u1,
45094509 .Pointer => Type.usize,
......@@ -4511,7 +4511,7 @@ fn cmp(
45114511 else => unreachable,
45124512 };
45134513
4514 const int_info = int_ty.intInfo(mod);
4514 const int_info = int_ty.intInfo(zcu);
45154515 if (int_info.bits <= 32) {
45164516 try self.spillCompareFlagsIfOccupied();
45174517
......@@ -4597,10 +4597,10 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
45974597
45984598fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {
45994599 const pt = self.pt;
4600 const mod = pt.zcu;
4600 const zcu = pt.zcu;
46014601 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
46024602 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);
4603 const func = mod.funcInfo(extra.data.func);
4603 const func = zcu.funcInfo(extra.data.func);
46044604 // TODO emit debug info for function change
46054605 _ = func;
46064606 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
......@@ -4810,9 +4810,9 @@ fn isNull(
48104810 operand_ty: Type,
48114811) !MCValue {
48124812 const pt = self.pt;
4813 const mod = pt.zcu;
4814 if (operand_ty.isPtrLikeOptional(mod)) {
4815 assert(operand_ty.abiSize(pt) == 4);
4813 const zcu = pt.zcu;
4814 if (operand_ty.isPtrLikeOptional(zcu)) {
4815 assert(operand_ty.abiSize(zcu) == 4);
48164816
48174817 const imm_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = 0 } };
48184818 return self.cmp(operand_bind, imm_bind, Type.usize, .eq);
......@@ -4845,12 +4845,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
48454845
48464846fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
48474847 const pt = self.pt;
4848 const mod = pt.zcu;
4848 const zcu = pt.zcu;
48494849 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
48504850 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48514851 const operand_ptr = try self.resolveInst(un_op);
48524852 const ptr_ty = self.typeOf(un_op);
4853 const elem_ty = ptr_ty.childType(mod);
4853 const elem_ty = ptr_ty.childType(zcu);
48544854
48554855 const operand = try self.allocRegOrMem(elem_ty, true, null);
48564856 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4873,12 +4873,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
48734873
48744874fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
48754875 const pt = self.pt;
4876 const mod = pt.zcu;
4876 const zcu = pt.zcu;
48774877 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
48784878 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48794879 const operand_ptr = try self.resolveInst(un_op);
48804880 const ptr_ty = self.typeOf(un_op);
4881 const elem_ty = ptr_ty.childType(mod);
4881 const elem_ty = ptr_ty.childType(zcu);
48824882
48834883 const operand = try self.allocRegOrMem(elem_ty, true, null);
48844884 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4894,10 +4894,10 @@ fn isErr(
48944894 error_union_ty: Type,
48954895) !MCValue {
48964896 const pt = self.pt;
4897 const mod = pt.zcu;
4898 const error_type = error_union_ty.errorUnionSet(mod);
4897 const zcu = pt.zcu;
4898 const error_type = error_union_ty.errorUnionSet(zcu);
48994899
4900 if (error_type.errorSetIsEmpty(mod)) {
4900 if (error_type.errorSetIsEmpty(zcu)) {
49014901 return MCValue{ .immediate = 0 }; // always false
49024902 }
49034903
......@@ -4937,12 +4937,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49374937
49384938fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49394939 const pt = self.pt;
4940 const mod = pt.zcu;
4940 const zcu = pt.zcu;
49414941 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
49424942 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49434943 const operand_ptr = try self.resolveInst(un_op);
49444944 const ptr_ty = self.typeOf(un_op);
4945 const elem_ty = ptr_ty.childType(mod);
4945 const elem_ty = ptr_ty.childType(zcu);
49464946
49474947 const operand = try self.allocRegOrMem(elem_ty, true, null);
49484948 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4965,12 +4965,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
49654965
49664966fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
49674967 const pt = self.pt;
4968 const mod = pt.zcu;
4968 const zcu = pt.zcu;
49694969 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
49704970 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49714971 const operand_ptr = try self.resolveInst(un_op);
49724972 const ptr_ty = self.typeOf(un_op);
4973 const elem_ty = ptr_ty.childType(mod);
4973 const elem_ty = ptr_ty.childType(zcu);
49744974
49754975 const operand = try self.allocRegOrMem(elem_ty, true, null);
49764976 try self.load(operand, operand_ptr, ptr_ty);
......@@ -5184,10 +5184,10 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
51845184}
51855185
51865186fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
5187 const pt = self.pt;
5187 const zcu = self.pt.zcu;
51885188 const block_data = self.blocks.getPtr(block).?;
51895189
5190 if (self.typeOf(operand).hasRuntimeBits(pt)) {
5190 if (self.typeOf(operand).hasRuntimeBits(zcu)) {
51915191 const operand_mcv = try self.resolveInst(operand);
51925192 const block_mcv = block_data.mcv;
51935193 if (block_mcv == .none) {
......@@ -5356,8 +5356,8 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
53565356
53575357fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
53585358 const pt = self.pt;
5359 const mod = pt.zcu;
5360 const abi_size: u32 = @intCast(ty.abiSize(pt));
5359 const zcu = pt.zcu;
5360 const abi_size: u32 = @intCast(ty.abiSize(zcu));
53615361 switch (mcv) {
53625362 .dead => unreachable,
53635363 .unreach, .none => return, // Nothing to do.
......@@ -5434,11 +5434,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54345434 const reg_lock = self.register_manager.lockReg(reg);
54355435 defer if (reg_lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
54365436
5437 const wrapped_ty = ty.structFieldType(0, mod);
5437 const wrapped_ty = ty.structFieldType(0, zcu);
54385438 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });
54395439
5440 const overflow_bit_ty = ty.structFieldType(1, mod);
5441 const overflow_bit_offset: u32 = @intCast(ty.structFieldOffset(1, pt));
5440 const overflow_bit_ty = ty.structFieldType(1, zcu);
5441 const overflow_bit_offset: u32 = @intCast(ty.structFieldOffset(1, zcu));
54425442 const cond_reg = try self.register_manager.allocReg(null, gp);
54435443
54445444 // C flag: movcs reg, #1
......@@ -5519,7 +5519,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
55195519
55205520fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {
55215521 const pt = self.pt;
5522 const mod = pt.zcu;
5522 const zcu = pt.zcu;
55235523 switch (mcv) {
55245524 .dead => unreachable,
55255525 .unreach, .none => return, // Nothing to do.
......@@ -5694,17 +5694,17 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
56945694 },
56955695 .stack_offset => |off| {
56965696 // TODO: maybe addressing from sp instead of fp
5697 const abi_size: u32 = @intCast(ty.abiSize(pt));
5697 const abi_size: u32 = @intCast(ty.abiSize(zcu));
56985698
56995699 const tag: Mir.Inst.Tag = switch (abi_size) {
5700 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,
5701 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh else .ldrh,
5700 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb else .ldrb,
5701 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh else .ldrh,
57025702 3, 4 => .ldr,
57035703 else => unreachable,
57045704 };
57055705
57065706 const extra_offset = switch (abi_size) {
5707 1 => ty.isSignedInt(mod),
5707 1 => ty.isSignedInt(zcu),
57085708 2 => true,
57095709 3, 4 => false,
57105710 else => unreachable,
......@@ -5745,11 +5745,11 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57455745 }
57465746 },
57475747 .stack_argument_offset => |off| {
5748 const abi_size = ty.abiSize(pt);
5748 const abi_size = ty.abiSize(zcu);
57495749
57505750 const tag: Mir.Inst.Tag = switch (abi_size) {
5751 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_stack_argument else .ldrb_stack_argument,
5752 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh_stack_argument else .ldrh_stack_argument,
5751 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb_stack_argument else .ldrb_stack_argument,
5752 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_stack_argument else .ldrh_stack_argument,
57535753 3, 4 => .ldr_stack_argument,
57545754 else => unreachable,
57555755 };
......@@ -5767,7 +5767,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57675767
57685768fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
57695769 const pt = self.pt;
5770 const abi_size: u32 = @intCast(ty.abiSize(pt));
5770 const abi_size: u32 = @intCast(ty.abiSize(pt.zcu));
57715771 switch (mcv) {
57725772 .dead => unreachable,
57735773 .none, .unreach => return,
......@@ -5923,13 +5923,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59235923
59245924fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
59255925 const pt = self.pt;
5926 const mod = pt.zcu;
5926 const zcu = pt.zcu;
59275927 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59285928 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
59295929 const ptr_ty = self.typeOf(ty_op.operand);
59305930 const ptr = try self.resolveInst(ty_op.operand);
5931 const array_ty = ptr_ty.childType(mod);
5932 const array_len: u32 = @intCast(array_ty.arrayLen(mod));
5931 const array_ty = ptr_ty.childType(zcu);
5932 const array_len: u32 = @intCast(array_ty.arrayLen(zcu));
59335933
59345934 const stack_offset = try self.allocMem(8, .@"8", inst);
59355935 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -6043,9 +6043,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60436043
60446044fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
60456045 const pt = self.pt;
6046 const mod = pt.zcu;
6046 const zcu = pt.zcu;
60476047 const vector_ty = self.typeOfIndex(inst);
6048 const len = vector_ty.vectorLen(mod);
6048 const len = vector_ty.vectorLen(zcu);
60496049 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
60506050 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
60516051 const result: MCValue = res: {
......@@ -6095,8 +6095,8 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
60956095 const result: MCValue = result: {
60966096 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
60976097 const error_union_ty = self.typeOf(pl_op.operand);
6098 const error_union_size: u32 = @intCast(error_union_ty.abiSize(pt));
6099 const error_union_align = error_union_ty.abiAlignment(pt);
6098 const error_union_size: u32 = @intCast(error_union_ty.abiSize(pt.zcu));
6099 const error_union_align = error_union_ty.abiAlignment(pt.zcu);
61006100
61016101 // The error union will die in the body. However, we need the
61026102 // error union after the body in order to extract the payload
......@@ -6126,11 +6126,11 @@ fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
61266126
61276127fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61286128 const pt = self.pt;
6129 const mod = pt.zcu;
6129 const zcu = pt.zcu;
61306130
61316131 // If the type has no codegen bits, no need to store it.
61326132 const inst_ty = self.typeOf(inst);
6133 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt) and !inst_ty.isError(mod))
6133 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu) and !inst_ty.isError(zcu))
61346134 return MCValue{ .none = {} };
61356135
61366136 const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, pt)).?);
......@@ -6189,9 +6189,9 @@ const CallMCValues = struct {
61896189/// Caller must call `CallMCValues.deinit`.
61906190fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
61916191 const pt = self.pt;
6192 const mod = pt.zcu;
6193 const ip = &mod.intern_pool;
6194 const fn_info = mod.typeToFunc(fn_ty).?;
6192 const zcu = pt.zcu;
6193 const ip = &zcu.intern_pool;
6194 const fn_info = zcu.typeToFunc(fn_ty).?;
61956195 const cc = fn_info.cc;
61966196 var result: CallMCValues = .{
61976197 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),
......@@ -6202,7 +6202,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62026202 };
62036203 errdefer self.gpa.free(result.args);
62046204
6205 const ret_ty = fn_ty.fnReturnType(mod);
6205 const ret_ty = fn_ty.fnReturnType(zcu);
62066206
62076207 switch (cc) {
62086208 .Naked => {
......@@ -6217,12 +6217,12 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62176217 var ncrn: usize = 0; // Next Core Register Number
62186218 var nsaa: u32 = 0; // Next stacked argument address
62196219
6220 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
6220 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
62216221 result.return_value = .{ .unreach = {} };
6222 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
6222 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
62236223 result.return_value = .{ .none = {} };
62246224 } else {
6225 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));
6225 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
62266226 // TODO handle cases where multiple registers are used
62276227 if (ret_ty_size <= 4) {
62286228 result.return_value = .{ .register = c_abi_int_return_regs[0] };
......@@ -6237,10 +6237,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62376237 }
62386238
62396239 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6240 if (Type.fromInterned(ty).abiAlignment(pt) == .@"8")
6240 if (Type.fromInterned(ty).abiAlignment(zcu) == .@"8")
62416241 ncrn = std.mem.alignForward(usize, ncrn, 2);
62426242
6243 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(pt));
6243 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(zcu));
62446244 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
62456245 if (param_size <= 4) {
62466246 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };
......@@ -6252,7 +6252,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62526252 return self.fail("TODO MCValues split between registers and stack", .{});
62536253 } else {
62546254 ncrn = 4;
6255 if (Type.fromInterned(ty).abiAlignment(pt) == .@"8")
6255 if (Type.fromInterned(ty).abiAlignment(zcu) == .@"8")
62566256 nsaa = std.mem.alignForward(u32, nsaa, 8);
62576257
62586258 result_arg.* = .{ .stack_argument_offset = nsaa };
......@@ -6264,14 +6264,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62646264 result.stack_align = 8;
62656265 },
62666266 .Unspecified => {
6267 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
6267 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
62686268 result.return_value = .{ .unreach = {} };
6269 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt) and !ret_ty.isError(mod)) {
6269 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and !ret_ty.isError(zcu)) {
62706270 result.return_value = .{ .none = {} };
62716271 } else {
6272 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));
6272 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
62736273 if (ret_ty_size == 0) {
6274 assert(ret_ty.isError(mod));
6274 assert(ret_ty.isError(zcu));
62756275 result.return_value = .{ .immediate = 0 };
62766276 } else if (ret_ty_size <= 4) {
62776277 result.return_value = .{ .register = .r0 };
......@@ -6287,9 +6287,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62876287 var stack_offset: u32 = 0;
62886288
62896289 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6290 if (Type.fromInterned(ty).abiSize(pt) > 0) {
6291 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(pt));
6292 const param_alignment = Type.fromInterned(ty).abiAlignment(pt);
6290 if (Type.fromInterned(ty).abiSize(zcu) > 0) {
6291 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(zcu));
6292 const param_alignment = Type.fromInterned(ty).abiAlignment(zcu);
62936293
62946294 stack_offset = @intCast(param_alignment.forward(stack_offset));
62956295 result_arg.* = .{ .stack_argument_offset = stack_offset };
src/arch/arm/abi.zig+21-21
......@@ -24,29 +24,29 @@ pub const Class = union(enum) {
2424
2525pub const Context = enum { ret, arg };
2626
27pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
28 assert(ty.hasRuntimeBitsIgnoreComptime(pt));
27pub fn classifyType(ty: Type, zcu: *Zcu, ctx: Context) Class {
28 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
2929
3030 var maybe_float_bits: ?u16 = null;
3131 const max_byval_size = 512;
32 const ip = &pt.zcu.intern_pool;
33 switch (ty.zigTypeTag(pt.zcu)) {
32 const ip = &zcu.intern_pool;
33 switch (ty.zigTypeTag(zcu)) {
3434 .Struct => {
35 const bit_size = ty.bitSize(pt);
36 if (ty.containerLayout(pt.zcu) == .@"packed") {
35 const bit_size = ty.bitSize(zcu);
36 if (ty.containerLayout(zcu) == .@"packed") {
3737 if (bit_size > 64) return .memory;
3838 return .byval;
3939 }
4040 if (bit_size > max_byval_size) return .memory;
41 const float_count = countFloats(ty, pt.zcu, &maybe_float_bits);
41 const float_count = countFloats(ty, zcu, &maybe_float_bits);
4242 if (float_count <= byval_float_count) return .byval;
4343
44 const fields = ty.structFieldCount(pt.zcu);
44 const fields = ty.structFieldCount(zcu);
4545 var i: u32 = 0;
4646 while (i < fields) : (i += 1) {
47 const field_ty = ty.structFieldType(i, pt.zcu);
48 const field_alignment = ty.structFieldAlign(i, pt);
49 const field_size = field_ty.bitSize(pt);
47 const field_ty = ty.structFieldType(i, zcu);
48 const field_alignment = ty.structFieldAlign(i, zcu);
49 const field_size = field_ty.bitSize(zcu);
5050 if (field_size > 32 or field_alignment.compare(.gt, .@"32")) {
5151 return Class.arrSize(bit_size, 64);
5252 }
......@@ -54,19 +54,19 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
5454 return Class.arrSize(bit_size, 32);
5555 },
5656 .Union => {
57 const bit_size = ty.bitSize(pt);
58 const union_obj = pt.zcu.typeToUnion(ty).?;
57 const bit_size = ty.bitSize(zcu);
58 const union_obj = zcu.typeToUnion(ty).?;
5959 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
6060 if (bit_size > 64) return .memory;
6161 return .byval;
6262 }
6363 if (bit_size > max_byval_size) return .memory;
64 const float_count = countFloats(ty, pt.zcu, &maybe_float_bits);
64 const float_count = countFloats(ty, zcu, &maybe_float_bits);
6565 if (float_count <= byval_float_count) return .byval;
6666
6767 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
68 if (Type.fromInterned(field_ty).bitSize(pt) > 32 or
69 pt.unionFieldNormalAlignment(union_obj, @intCast(field_index)).compare(.gt, .@"32"))
68 if (Type.fromInterned(field_ty).bitSize(zcu) > 32 or
69 Type.unionFieldNormalAlignment(union_obj, @intCast(field_index), zcu).compare(.gt, .@"32"))
7070 {
7171 return Class.arrSize(bit_size, 64);
7272 }
......@@ -77,28 +77,28 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
7777 .Int => {
7878 // TODO this is incorrect for _BitInt(128) but implementing
7979 // this correctly makes implementing compiler-rt impossible.
80 // const bit_size = ty.bitSize(pt);
80 // const bit_size = ty.bitSize(zcu);
8181 // if (bit_size > 64) return .memory;
8282 return .byval;
8383 },
8484 .Enum, .ErrorSet => {
85 const bit_size = ty.bitSize(pt);
85 const bit_size = ty.bitSize(zcu);
8686 if (bit_size > 64) return .memory;
8787 return .byval;
8888 },
8989 .Vector => {
90 const bit_size = ty.bitSize(pt);
90 const bit_size = ty.bitSize(zcu);
9191 // TODO is this controlled by a cpu feature?
9292 if (ctx == .ret and bit_size > 128) return .memory;
9393 if (bit_size > 512) return .memory;
9494 return .byval;
9595 },
9696 .Optional => {
97 assert(ty.isPtrLikeOptional(pt.zcu));
97 assert(ty.isPtrLikeOptional(zcu));
9898 return .byval;
9999 },
100100 .Pointer => {
101 assert(!ty.isSlice(pt.zcu));
101 assert(!ty.isSlice(zcu));
102102 return .byval;
103103 },
104104 .ErrorUnion,
src/arch/riscv64/CodeGen.zig+165-158
......@@ -591,14 +591,14 @@ const FrameAlloc = struct {
591591 .ref_count = 0,
592592 };
593593 }
594 fn initType(ty: Type, pt: Zcu.PerThread) FrameAlloc {
594 fn initType(ty: Type, zcu: *Zcu) FrameAlloc {
595595 return init(.{
596 .size = ty.abiSize(pt),
597 .alignment = ty.abiAlignment(pt),
596 .size = ty.abiSize(zcu),
597 .alignment = ty.abiAlignment(zcu),
598598 });
599599 }
600 fn initSpill(ty: Type, pt: Zcu.PerThread) FrameAlloc {
601 const abi_size = ty.abiSize(pt);
600 fn initSpill(ty: Type, zcu: *Zcu) FrameAlloc {
601 const abi_size = ty.abiSize(zcu);
602602 const spill_size = if (abi_size < 8)
603603 math.ceilPowerOfTwoAssert(u64, abi_size)
604604 else
......@@ -606,7 +606,7 @@ const FrameAlloc = struct {
606606 return init(.{
607607 .size = spill_size,
608608 .pad = @intCast(spill_size - abi_size),
609 .alignment = ty.abiAlignment(pt).maxStrict(
609 .alignment = ty.abiAlignment(zcu).maxStrict(
610610 Alignment.fromNonzeroByteUnits(@min(spill_size, 8)),
611611 ),
612612 });
......@@ -835,11 +835,11 @@ pub fn generate(
835835 function.args = call_info.args;
836836 function.ret_mcv = call_info.return_value;
837837 function.frame_allocs.set(@intFromEnum(FrameIndex.ret_addr), FrameAlloc.init(.{
838 .size = Type.u64.abiSize(pt),
839 .alignment = Type.u64.abiAlignment(pt).min(call_info.stack_align),
838 .size = Type.u64.abiSize(zcu),
839 .alignment = Type.u64.abiAlignment(zcu).min(call_info.stack_align),
840840 }));
841841 function.frame_allocs.set(@intFromEnum(FrameIndex.base_ptr), FrameAlloc.init(.{
842 .size = Type.u64.abiSize(pt),
842 .size = Type.u64.abiSize(zcu),
843843 .alignment = Alignment.min(
844844 call_info.stack_align,
845845 Alignment.fromNonzeroByteUnits(function.target.stackAlignment()),
......@@ -851,7 +851,7 @@ pub fn generate(
851851 }));
852852 function.frame_allocs.set(@intFromEnum(FrameIndex.spill_frame), FrameAlloc.init(.{
853853 .size = 0,
854 .alignment = Type.u64.abiAlignment(pt),
854 .alignment = Type.u64.abiAlignment(zcu),
855855 }));
856856
857857 function.gen() catch |err| switch (err) {
......@@ -1245,7 +1245,7 @@ fn gen(func: *Func) !void {
12451245 // The address where to store the return value for the caller is in a
12461246 // register which the callee is free to clobber. Therefore, we purposely
12471247 // spill it to stack immediately.
1248 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(Type.u64, pt));
1248 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(Type.u64, zcu));
12491249 try func.genSetMem(
12501250 .{ .frame = frame_index },
12511251 0,
......@@ -1379,9 +1379,9 @@ fn gen(func: *Func) !void {
13791379
13801380fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
13811381 const pt = func.pt;
1382 const mod = pt.zcu;
1383 const ip = &mod.intern_pool;
1384 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(mod)) {
1382 const zcu = pt.zcu;
1383 const ip = &zcu.intern_pool;
1384 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {
13851385 .Enum => {
13861386 const enum_ty = Type.fromInterned(lazy_sym.ty);
13871387 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});
......@@ -1390,7 +1390,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
13901390 const ret_reg = param_regs[0];
13911391 const enum_mcv: MCValue = .{ .register = param_regs[1] };
13921392
1393 const exitlude_jump_relocs = try func.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod));
1393 const exitlude_jump_relocs = try func.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(zcu));
13941394 defer func.gpa.free(exitlude_jump_relocs);
13951395
13961396 const data_reg, const data_lock = try func.allocReg(.int);
......@@ -1410,7 +1410,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
14101410 defer func.register_manager.unlockReg(cmp_lock);
14111411
14121412 var data_off: i32 = 0;
1413 const tag_names = enum_ty.enumFields(mod);
1413 const tag_names = enum_ty.enumFields(zcu);
14141414 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {
14151415 const tag_name_len = tag_names.get(ip)[tag_index].length(ip);
14161416 const tag_val = try pt.enumValueFieldIndex(enum_ty, @intCast(tag_index));
......@@ -1944,32 +1944,32 @@ fn memSize(func: *Func, ty: Type) Memory.Size {
19441944 const zcu = pt.zcu;
19451945 return switch (ty.zigTypeTag(zcu)) {
19461946 .Float => Memory.Size.fromBitSize(ty.floatBits(func.target.*)),
1947 else => Memory.Size.fromByteSize(ty.abiSize(pt)),
1947 else => Memory.Size.fromByteSize(ty.abiSize(zcu)),
19481948 };
19491949}
19501950
19511951fn splitType(func: *Func, ty: Type) ![2]Type {
1952 const pt = func.pt;
1953 const classes = mem.sliceTo(&abi.classifySystem(ty, pt), .none);
1952 const zcu = func.pt.zcu;
1953 const classes = mem.sliceTo(&abi.classifySystem(ty, zcu), .none);
19541954 var parts: [2]Type = undefined;
19551955 if (classes.len == 2) for (&parts, classes, 0..) |*part, class, part_i| {
19561956 part.* = switch (class) {
19571957 .integer => switch (part_i) {
19581958 0 => Type.u64,
19591959 1 => part: {
1960 const elem_size = ty.abiAlignment(pt).minStrict(.@"8").toByteUnits().?;
1961 const elem_ty = try pt.intType(.unsigned, @intCast(elem_size * 8));
1962 break :part switch (@divExact(ty.abiSize(pt) - 8, elem_size)) {
1960 const elem_size = ty.abiAlignment(zcu).minStrict(.@"8").toByteUnits().?;
1961 const elem_ty = try func.pt.intType(.unsigned, @intCast(elem_size * 8));
1962 break :part switch (@divExact(ty.abiSize(zcu) - 8, elem_size)) {
19631963 1 => elem_ty,
1964 else => |len| try pt.arrayType(.{ .len = len, .child = elem_ty.toIntern() }),
1964 else => |len| try func.pt.arrayType(.{ .len = len, .child = elem_ty.toIntern() }),
19651965 };
19661966 },
19671967 else => unreachable,
19681968 },
19691969 else => return func.fail("TODO: splitType class {}", .{class}),
19701970 };
1971 } else if (parts[0].abiSize(pt) + parts[1].abiSize(pt) == ty.abiSize(pt)) return parts;
1972 return func.fail("TODO implement splitType for {}", .{ty.fmt(pt)});
1971 } else if (parts[0].abiSize(zcu) + parts[1].abiSize(zcu) == ty.abiSize(zcu)) return parts;
1972 return func.fail("TODO implement splitType for {}", .{ty.fmt(func.pt)});
19731973}
19741974
19751975/// Truncates the value in the register in place.
......@@ -1979,7 +1979,7 @@ fn truncateRegister(func: *Func, ty: Type, reg: Register) !void {
19791979 const zcu = pt.zcu;
19801980 const int_info = if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else std.builtin.Type.Int{
19811981 .signedness = .unsigned,
1982 .bits = @intCast(ty.bitSize(pt)),
1982 .bits = @intCast(ty.bitSize(zcu)),
19831983 };
19841984 assert(reg.class() == .int);
19851985
......@@ -2081,10 +2081,10 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex {
20812081 const ptr_ty = func.typeOfIndex(inst);
20822082 const val_ty = ptr_ty.childType(zcu);
20832083 return func.allocFrameIndex(FrameAlloc.init(.{
2084 .size = math.cast(u32, val_ty.abiSize(pt)) orelse {
2084 .size = math.cast(u32, val_ty.abiSize(zcu)) orelse {
20852085 return func.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});
20862086 },
2087 .alignment = ptr_ty.ptrAlignment(pt).max(.@"1"),
2087 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
20882088 }));
20892089}
20902090
......@@ -2118,7 +2118,7 @@ fn allocRegOrMem(func: *Func, elem_ty: Type, inst: ?Air.Inst.Index, reg_ok: bool
21182118 const pt = func.pt;
21192119 const zcu = pt.zcu;
21202120
2121 const bit_size = elem_ty.bitSize(pt);
2121 const bit_size = elem_ty.bitSize(zcu);
21222122 const min_size: u64 = switch (elem_ty.zigTypeTag(zcu)) {
21232123 .Float => if (func.hasFeature(.d)) 64 else 32,
21242124 .Vector => 256, // TODO: calculate it from avl * vsew
......@@ -2133,7 +2133,7 @@ fn allocRegOrMem(func: *Func, elem_ty: Type, inst: ?Air.Inst.Index, reg_ok: bool
21332133 return func.fail("did you forget to extend vector registers before allocating", .{});
21342134 }
21352135
2136 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(elem_ty, pt));
2136 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(elem_ty, zcu));
21372137 return .{ .load_frame = .{ .index = frame_index } };
21382138}
21392139
......@@ -2368,7 +2368,7 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void {
23682368 });
23692369 },
23702370 .Int => {
2371 const size = ty.bitSize(pt);
2371 const size = ty.bitSize(zcu);
23722372 if (!math.isPowerOfTwo(size))
23732373 return func.fail("TODO: airNot non-pow 2 int size", .{});
23742374
......@@ -2399,11 +2399,12 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void {
23992399
24002400fn airSlice(func: *Func, inst: Air.Inst.Index) !void {
24012401 const pt = func.pt;
2402 const zcu = pt.zcu;
24022403 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
24032404 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
24042405
24052406 const slice_ty = func.typeOfIndex(inst);
2406 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(slice_ty, pt));
2407 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(slice_ty, zcu));
24072408
24082409 const ptr_ty = func.typeOf(bin_op.lhs);
24092410 try func.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, .{ .air_ref = bin_op.lhs });
......@@ -2411,7 +2412,7 @@ fn airSlice(func: *Func, inst: Air.Inst.Index) !void {
24112412 const len_ty = func.typeOf(bin_op.rhs);
24122413 try func.genSetMem(
24132414 .{ .frame = frame_index },
2414 @intCast(ptr_ty.abiSize(pt)),
2415 @intCast(ptr_ty.abiSize(zcu)),
24152416 len_ty,
24162417 .{ .air_ref = bin_op.rhs },
24172418 );
......@@ -2428,8 +2429,8 @@ fn airBinOp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
24282429
24292430 const dst_ty = func.typeOfIndex(inst);
24302431 if (dst_ty.isAbiInt(zcu)) {
2431 const abi_size: u32 = @intCast(dst_ty.abiSize(pt));
2432 const bit_size: u32 = @intCast(dst_ty.bitSize(pt));
2432 const abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
2433 const bit_size: u32 = @intCast(dst_ty.bitSize(zcu));
24332434 if (abi_size * 8 > bit_size) {
24342435 const dst_lock = switch (dst_mcv) {
24352436 .register => |dst_reg| func.register_manager.lockRegAssumeUnused(dst_reg),
......@@ -2443,7 +2444,7 @@ fn airBinOp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
24432444 const tmp_reg, const tmp_lock = try func.allocReg(.int);
24442445 defer func.register_manager.unlockReg(tmp_lock);
24452446
2446 const hi_ty = try pt.intType(.unsigned, @intCast((dst_ty.bitSize(pt) - 1) % 64 + 1));
2447 const hi_ty = try pt.intType(.unsigned, @intCast((dst_ty.bitSize(zcu) - 1) % 64 + 1));
24472448 const hi_mcv = dst_mcv.address().offset(@intCast(bit_size / 64 * 8)).deref();
24482449 try func.genSetReg(hi_ty, tmp_reg, hi_mcv);
24492450 try func.truncateRegister(dst_ty, tmp_reg);
......@@ -2464,6 +2465,7 @@ fn binOp(
24642465) !MCValue {
24652466 _ = maybe_inst;
24662467 const pt = func.pt;
2468 const zcu = pt.zcu;
24672469 const lhs_ty = func.typeOf(lhs_air);
24682470 const rhs_ty = func.typeOf(rhs_air);
24692471
......@@ -2480,9 +2482,9 @@ fn binOp(
24802482 }
24812483
24822484 // don't have support for certain sizes of addition
2483 switch (lhs_ty.zigTypeTag(pt.zcu)) {
2485 switch (lhs_ty.zigTypeTag(zcu)) {
24842486 .Vector => {}, // works differently and fails in a different place
2485 else => if (lhs_ty.bitSize(pt) > 64) return func.fail("TODO: binOp >= 64 bits", .{}),
2487 else => if (lhs_ty.bitSize(zcu) > 64) return func.fail("TODO: binOp >= 64 bits", .{}),
24862488 }
24872489
24882490 const lhs_mcv = try func.resolveInst(lhs_air);
......@@ -2533,7 +2535,7 @@ fn genBinOp(
25332535) !void {
25342536 const pt = func.pt;
25352537 const zcu = pt.zcu;
2536 const bit_size = lhs_ty.bitSize(pt);
2538 const bit_size = lhs_ty.bitSize(zcu);
25372539
25382540 const is_unsigned = lhs_ty.isUnsignedInt(zcu);
25392541
......@@ -2646,7 +2648,7 @@ fn genBinOp(
26462648 },
26472649 .Vector => {
26482650 const num_elem = lhs_ty.vectorLen(zcu);
2649 const elem_size = lhs_ty.childType(zcu).bitSize(pt);
2651 const elem_size = lhs_ty.childType(zcu).bitSize(zcu);
26502652
26512653 const child_ty = lhs_ty.childType(zcu);
26522654
......@@ -2753,7 +2755,7 @@ fn genBinOp(
27532755 defer func.register_manager.unlockReg(tmp_lock);
27542756
27552757 // RISC-V has no immediate mul, so we copy the size to a temporary register
2756 const elem_size = lhs_ty.elemType2(zcu).abiSize(pt);
2758 const elem_size = lhs_ty.elemType2(zcu).abiSize(zcu);
27572759 const elem_size_reg = try func.copyToTmpRegister(Type.u64, .{ .immediate = elem_size });
27582760
27592761 try func.genBinOp(
......@@ -2990,7 +2992,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
29902992
29912993 try func.genSetMem(
29922994 .{ .frame = offset.index },
2993 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(0, pt))),
2995 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(0, zcu))),
29942996 lhs_ty,
29952997 add_result,
29962998 );
......@@ -3016,7 +3018,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
30163018
30173019 try func.genSetMem(
30183020 .{ .frame = offset.index },
3019 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, pt))),
3021 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, zcu))),
30203022 Type.u1,
30213023 .{ .register = overflow_reg },
30223024 );
......@@ -3053,7 +3055,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
30533055
30543056 try func.genSetMem(
30553057 .{ .frame = offset.index },
3056 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(0, pt))),
3058 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(0, zcu))),
30573059 lhs_ty,
30583060 add_result,
30593061 );
......@@ -3079,7 +3081,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
30793081
30803082 try func.genSetMem(
30813083 .{ .frame = offset.index },
3082 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, pt))),
3084 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, zcu))),
30833085 Type.u1,
30843086 .{ .register = overflow_reg },
30853087 );
......@@ -3126,7 +3128,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
31263128
31273129 try func.genSetMem(
31283130 .{ .frame = offset.index },
3129 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(0, pt))),
3131 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(0, zcu))),
31303132 lhs_ty,
31313133 .{ .register = dest_reg },
31323134 );
......@@ -3155,7 +3157,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
31553157
31563158 try func.genSetMem(
31573159 .{ .frame = offset.index },
3158 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, pt))),
3160 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, zcu))),
31593161 Type.u1,
31603162 .{ .register = overflow_reg },
31613163 );
......@@ -3203,7 +3205,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
32033205
32043206 try func.genSetMem(
32053207 .{ .frame = offset.index },
3206 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, pt))),
3208 offset.off + @as(i32, @intCast(tuple_ty.structFieldOffset(1, zcu))),
32073209 Type.u1,
32083210 .{ .register = overflow_reg },
32093211 );
......@@ -3236,8 +3238,8 @@ fn airMulWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
32363238 // genSetReg needs to support register_offset src_mcv for this to be true.
32373239 const result_mcv = try func.allocRegOrMem(tuple_ty, inst, false);
32383240
3239 const result_off: i32 = @intCast(tuple_ty.structFieldOffset(0, pt));
3240 const overflow_off: i32 = @intCast(tuple_ty.structFieldOffset(1, pt));
3241 const result_off: i32 = @intCast(tuple_ty.structFieldOffset(0, zcu));
3242 const overflow_off: i32 = @intCast(tuple_ty.structFieldOffset(1, zcu));
32413243
32423244 const dest_reg, const dest_lock = try func.allocReg(.int);
32433245 defer func.register_manager.unlockReg(dest_lock);
......@@ -3320,11 +3322,11 @@ fn airShlSat(func: *Func, inst: Air.Inst.Index) !void {
33203322}
33213323
33223324fn airOptionalPayload(func: *Func, inst: Air.Inst.Index) !void {
3323 const pt = func.pt;
3325 const zcu = func.pt.zcu;
33243326 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
33253327 const result: MCValue = result: {
33263328 const pl_ty = func.typeOfIndex(inst);
3327 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
3329 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
33283330
33293331 const opt_mcv = try func.resolveInst(ty_op.operand);
33303332 if (func.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {
......@@ -3368,11 +3370,11 @@ fn airUnwrapErrErr(func: *Func, inst: Air.Inst.Index) !void {
33683370 break :result .{ .immediate = 0 };
33693371 }
33703372
3371 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3373 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
33723374 break :result operand;
33733375 }
33743376
3375 const err_off: u32 = @intCast(errUnionErrorOffset(payload_ty, pt));
3377 const err_off: u32 = @intCast(errUnionErrorOffset(payload_ty, zcu));
33763378
33773379 switch (operand) {
33783380 .register => |reg| {
......@@ -3421,9 +3423,9 @@ fn genUnwrapErrUnionPayloadMir(
34213423 const payload_ty = err_union_ty.errorUnionPayload(zcu);
34223424
34233425 const result: MCValue = result: {
3424 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
3426 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
34253427
3426 const payload_off: u31 = @intCast(errUnionPayloadOffset(payload_ty, pt));
3428 const payload_off: u31 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
34273429 switch (err_union) {
34283430 .load_frame => |frame_addr| break :result .{ .load_frame = .{
34293431 .index = frame_addr.index,
......@@ -3497,7 +3499,7 @@ fn airWrapOptional(func: *Func, inst: Air.Inst.Index) !void {
34973499 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
34983500 const result: MCValue = result: {
34993501 const pl_ty = func.typeOf(ty_op.operand);
3500 if (!pl_ty.hasRuntimeBits(pt)) break :result .{ .immediate = 1 };
3502 if (!pl_ty.hasRuntimeBits(zcu)) break :result .{ .immediate = 1 };
35013503
35023504 const opt_ty = func.typeOfIndex(inst);
35033505 const pl_mcv = try func.resolveInst(ty_op.operand);
......@@ -3514,7 +3516,7 @@ fn airWrapOptional(func: *Func, inst: Air.Inst.Index) !void {
35143516 try func.genCopy(pl_ty, opt_mcv, pl_mcv);
35153517
35163518 if (!same_repr) {
3517 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(pt));
3519 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(zcu));
35183520 switch (opt_mcv) {
35193521 .load_frame => |frame_addr| {
35203522 try func.genCopy(pl_ty, opt_mcv, pl_mcv);
......@@ -3545,11 +3547,11 @@ fn airWrapErrUnionPayload(func: *Func, inst: Air.Inst.Index) !void {
35453547 const operand = try func.resolveInst(ty_op.operand);
35463548
35473549 const result: MCValue = result: {
3548 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .{ .immediate = 0 };
3550 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .{ .immediate = 0 };
35493551
3550 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, pt));
3551 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));
3552 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));
3552 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
3553 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
3554 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
35533555 try func.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand);
35543556 try func.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 });
35553557 break :result .{ .load_frame = .{ .index = frame_index } };
......@@ -3569,11 +3571,11 @@ fn airWrapErrUnionErr(func: *Func, inst: Air.Inst.Index) !void {
35693571 const err_ty = eu_ty.errorUnionSet(zcu);
35703572
35713573 const result: MCValue = result: {
3572 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result try func.resolveInst(ty_op.operand);
3574 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result try func.resolveInst(ty_op.operand);
35733575
3574 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, pt));
3575 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));
3576 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));
3576 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
3577 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
3578 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
35773579 try func.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .{ .undef = null });
35783580 const operand = try func.resolveInst(ty_op.operand);
35793581 try func.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand);
......@@ -3717,7 +3719,7 @@ fn airSliceElemVal(func: *Func, inst: Air.Inst.Index) !void {
37173719
37183720 const result: MCValue = result: {
37193721 const elem_ty = func.typeOfIndex(inst);
3720 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
3722 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
37213723
37223724 const slice_ty = func.typeOf(bin_op.lhs);
37233725 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
......@@ -3748,7 +3750,7 @@ fn genSliceElemPtr(func: *Func, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
37483750 defer if (slice_mcv_lock) |lock| func.register_manager.unlockReg(lock);
37493751
37503752 const elem_ty = slice_ty.childType(zcu);
3751 const elem_size = elem_ty.abiSize(pt);
3753 const elem_size = elem_ty.abiSize(zcu);
37523754
37533755 const index_ty = func.typeOf(rhs);
37543756 const index_mcv = try func.resolveInst(rhs);
......@@ -3792,14 +3794,14 @@ fn airArrayElemVal(func: *Func, inst: Air.Inst.Index) !void {
37923794 const index_ty = func.typeOf(bin_op.rhs);
37933795
37943796 const elem_ty = array_ty.childType(zcu);
3795 const elem_abi_size = elem_ty.abiSize(pt);
3797 const elem_abi_size = elem_ty.abiSize(zcu);
37963798
37973799 const addr_reg, const addr_reg_lock = try func.allocReg(.int);
37983800 defer func.register_manager.unlockReg(addr_reg_lock);
37993801
38003802 switch (array_mcv) {
38013803 .register => {
3802 const frame_index = try func.allocFrameIndex(FrameAlloc.initType(array_ty, pt));
3804 const frame_index = try func.allocFrameIndex(FrameAlloc.initType(array_ty, zcu));
38033805 try func.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv);
38043806 try func.genSetReg(Type.u64, addr_reg, .{ .lea_frame = .{ .index = frame_index } });
38053807 },
......@@ -3870,7 +3872,7 @@ fn airPtrElemVal(func: *Func, inst: Air.Inst.Index) !void {
38703872
38713873 const result: MCValue = if (!is_volatile and func.liveness.isUnused(inst)) .unreach else result: {
38723874 const elem_ty = base_ptr_ty.elemType2(zcu);
3873 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
3875 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
38743876
38753877 const base_ptr_mcv = try func.resolveInst(bin_op.lhs);
38763878 const base_ptr_lock: ?RegisterLock = switch (base_ptr_mcv) {
......@@ -3970,11 +3972,12 @@ fn airSetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
39703972
39713973fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
39723974 const pt = func.pt;
3975 const zcu = pt.zcu;
39733976 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
39743977
39753978 const tag_ty = func.typeOfIndex(inst);
39763979 const union_ty = func.typeOf(ty_op.operand);
3977 const layout = union_ty.unionGetLayout(pt);
3980 const layout = union_ty.unionGetLayout(zcu);
39783981
39793982 if (layout.tag_size == 0) {
39803983 return func.finishAir(inst, .none, .{ ty_op.operand, .none, .none });
......@@ -3985,7 +3988,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
39853988 const frame_mcv = try func.allocRegOrMem(union_ty, null, false);
39863989 try func.genCopy(union_ty, frame_mcv, operand);
39873990
3988 const tag_abi_size = tag_ty.abiSize(pt);
3991 const tag_abi_size = tag_ty.abiSize(zcu);
39893992 const result_reg, const result_lock = try func.allocReg(.int);
39903993 defer func.register_manager.unlockReg(result_lock);
39913994
......@@ -4034,7 +4037,7 @@ fn airClz(func: *Func, inst: Air.Inst.Index) !void {
40344037 else
40354038 (try func.allocRegOrMem(func.typeOfIndex(inst), inst, true)).register;
40364039
4037 const bit_size = ty.bitSize(func.pt);
4040 const bit_size = ty.bitSize(func.pt.zcu);
40384041 if (!math.isPowerOfTwo(bit_size)) try func.truncateRegister(ty, src_reg);
40394042
40404043 if (bit_size > 64) {
......@@ -4081,6 +4084,7 @@ fn airPopcount(func: *Func, inst: Air.Inst.Index) !void {
40814084 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
40824085 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
40834086 const pt = func.pt;
4087 const zcu = pt.zcu;
40844088
40854089 const operand = try func.resolveInst(ty_op.operand);
40864090 const src_ty = func.typeOf(ty_op.operand);
......@@ -4090,7 +4094,7 @@ fn airPopcount(func: *Func, inst: Air.Inst.Index) !void {
40904094 const dst_reg, const dst_lock = try func.allocReg(.int);
40914095 defer func.register_manager.unlockReg(dst_lock);
40924096
4093 const bit_size = src_ty.bitSize(pt);
4097 const bit_size = src_ty.bitSize(zcu);
40944098 switch (bit_size) {
40954099 32, 64 => {},
40964100 1...31, 33...63 => try func.truncateRegister(src_ty, operand_reg),
......@@ -4283,12 +4287,13 @@ fn airBitReverse(func: *Func, inst: Air.Inst.Index) !void {
42834287
42844288fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
42854289 const pt = func.pt;
4290 const zcu = pt.zcu;
42864291 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
42874292 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
42884293 const ty = func.typeOf(un_op);
42894294
42904295 const operand = try func.resolveInst(un_op);
4291 const operand_bit_size = ty.bitSize(pt);
4296 const operand_bit_size = ty.bitSize(zcu);
42924297
42934298 if (!math.isPowerOfTwo(operand_bit_size))
42944299 return func.fail("TODO: airUnaryMath non-pow 2", .{});
......@@ -4300,7 +4305,7 @@ fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
43004305 const dst_reg, const dst_lock = try func.allocReg(dst_class);
43014306 defer func.register_manager.unlockReg(dst_lock);
43024307
4303 switch (ty.zigTypeTag(pt.zcu)) {
4308 switch (ty.zigTypeTag(zcu)) {
43044309 .Float => {
43054310 assert(dst_class == .float);
43064311
......@@ -4397,7 +4402,7 @@ fn airLoad(func: *Func, inst: Air.Inst.Index) !void {
43974402 const elem_ty = func.typeOfIndex(inst);
43984403
43994404 const result: MCValue = result: {
4400 if (!elem_ty.hasRuntimeBits(pt))
4405 if (!elem_ty.hasRuntimeBits(zcu))
44014406 break :result .none;
44024407
44034408 const ptr = try func.resolveInst(ty_op.operand);
......@@ -4405,7 +4410,7 @@ fn airLoad(func: *Func, inst: Air.Inst.Index) !void {
44054410 if (func.liveness.isUnused(inst) and !is_volatile)
44064411 break :result .unreach;
44074412
4408 const elem_size = elem_ty.abiSize(pt);
4413 const elem_size = elem_ty.abiSize(zcu);
44094414
44104415 const dst_mcv: MCValue = blk: {
44114416 // The MCValue that holds the pointer can be re-used as the value.
......@@ -4544,7 +4549,7 @@ fn structFieldPtr(func: *Func, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
45444549 const container_ty = ptr_container_ty.childType(zcu);
45454550
45464551 const field_offset: i32 = switch (container_ty.containerLayout(zcu)) {
4547 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(index, pt)),
4552 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(index, zcu)),
45484553 .@"packed" => @divExact(@as(i32, ptr_container_ty.ptrInfo(zcu).packed_offset.bit_offset) +
45494554 (if (zcu.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, index) else 0) -
45504555 ptr_field_ty.ptrInfo(zcu).packed_offset.bit_offset, 8),
......@@ -4572,10 +4577,10 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
45724577 const src_mcv = try func.resolveInst(operand);
45734578 const struct_ty = func.typeOf(operand);
45744579 const field_ty = struct_ty.structFieldType(index, zcu);
4575 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
4580 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
45764581
45774582 const field_off: u32 = switch (struct_ty.containerLayout(zcu)) {
4578 .auto, .@"extern" => @intCast(struct_ty.structFieldOffset(index, pt) * 8),
4583 .auto, .@"extern" => @intCast(struct_ty.structFieldOffset(index, zcu) * 8),
45794584 .@"packed" => if (zcu.typeToStruct(struct_ty)) |struct_type|
45804585 pt.structPackedFieldBitOffset(struct_type, index)
45814586 else
......@@ -4615,11 +4620,11 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
46154620 break :result if (field_off == 0) dst_mcv else try func.copyToNewRegister(inst, dst_mcv);
46164621 },
46174622 .load_frame => {
4618 const field_abi_size: u32 = @intCast(field_ty.abiSize(pt));
4623 const field_abi_size: u32 = @intCast(field_ty.abiSize(zcu));
46194624 if (field_off % 8 == 0) {
46204625 const field_byte_off = @divExact(field_off, 8);
46214626 const off_mcv = src_mcv.address().offset(@intCast(field_byte_off)).deref();
4622 const field_bit_size = field_ty.bitSize(pt);
4627 const field_bit_size = field_ty.bitSize(zcu);
46234628
46244629 if (field_abi_size <= 8) {
46254630 const int_ty = try pt.intType(
......@@ -4635,7 +4640,7 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
46354640 break :result try func.copyToNewRegister(inst, dst_mcv);
46364641 }
46374642
4638 const container_abi_size: u32 = @intCast(struct_ty.abiSize(pt));
4643 const container_abi_size: u32 = @intCast(struct_ty.abiSize(zcu));
46394644 const dst_mcv = if (field_byte_off + field_abi_size <= container_abi_size and
46404645 func.reuseOperand(inst, operand, 0, src_mcv))
46414646 off_mcv
......@@ -4880,7 +4885,7 @@ fn genCall(
48804885 try reg_locks.appendSlice(&func.register_manager.lockRegs(2, regs));
48814886 },
48824887 .indirect => |reg_off| {
4883 frame_index.* = try func.allocFrameIndex(FrameAlloc.initType(arg_ty, pt));
4888 frame_index.* = try func.allocFrameIndex(FrameAlloc.initType(arg_ty, zcu));
48844889 try func.genSetMem(.{ .frame = frame_index.* }, 0, arg_ty, src_arg);
48854890 try func.register_manager.getReg(reg_off.reg, null);
48864891 try reg_locks.append(func.register_manager.lockReg(reg_off.reg));
......@@ -4893,7 +4898,7 @@ fn genCall(
48934898 .none, .unreach => {},
48944899 .indirect => |reg_off| {
48954900 const ret_ty = Type.fromInterned(fn_info.return_type);
4896 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(ret_ty, pt));
4901 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(ret_ty, zcu));
48974902 try func.genSetReg(Type.u64, reg_off.reg, .{
48984903 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },
48994904 });
......@@ -5013,7 +5018,7 @@ fn airRet(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
50135018 .register_pair,
50145019 => {
50155020 if (ret_ty.isVector(zcu)) {
5016 const bit_size = ret_ty.totalVectorBits(pt);
5021 const bit_size = ret_ty.totalVectorBits(zcu);
50175022
50185023 // set the vtype to hold the entire vector's contents in a single element
50195024 try func.setVl(.zero, 0, .{
......@@ -5113,7 +5118,7 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
51135118 .ErrorSet => Type.anyerror,
51145119 .Optional => blk: {
51155120 const payload_ty = lhs_ty.optionalChild(zcu);
5116 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5121 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
51175122 break :blk Type.u1;
51185123 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
51195124 break :blk Type.u64;
......@@ -5289,7 +5294,7 @@ fn isNull(func: *Func, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
52895294 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(zcu))
52905295 .{ .off = 0, .ty = if (pl_ty.isSlice(zcu)) pl_ty.slicePtrFieldType(zcu) else pl_ty }
52915296 else
5292 .{ .off = @intCast(pl_ty.abiSize(pt)), .ty = Type.bool };
5297 .{ .off = @intCast(pl_ty.abiSize(zcu)), .ty = Type.bool };
52935298
52945299 const return_mcv = try func.allocRegOrMem(func.typeOfIndex(inst), inst, true);
52955300 assert(return_mcv == .register); // should not be larger 8 bytes
......@@ -5472,11 +5477,10 @@ fn airIsErrPtr(func: *Func, inst: Air.Inst.Index) !void {
54725477/// Result is in the return register.
54735478fn isErr(func: *Func, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue) !MCValue {
54745479 _ = maybe_inst;
5475 const pt = func.pt;
5476 const zcu = pt.zcu;
5480 const zcu = func.pt.zcu;
54775481 const err_ty = eu_ty.errorUnionSet(zcu);
54785482 if (err_ty.errorSetIsEmpty(zcu)) return MCValue{ .immediate = 0 }; // always false
5479 const err_off: u31 = @intCast(errUnionErrorOffset(eu_ty.errorUnionPayload(zcu), pt));
5483 const err_off: u31 = @intCast(errUnionErrorOffset(eu_ty.errorUnionPayload(zcu), zcu));
54805484
54815485 const return_reg, const return_lock = try func.allocReg(.int);
54825486 defer func.register_manager.unlockReg(return_lock);
......@@ -5769,12 +5773,12 @@ fn performReloc(func: *Func, inst: Mir.Inst.Index) void {
57695773}
57705774
57715775fn airBr(func: *Func, inst: Air.Inst.Index) !void {
5772 const pt = func.pt;
5776 const zcu = func.pt.zcu;
57735777 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;
57745778
57755779 const block_ty = func.typeOfIndex(br.block_inst);
57765780 const block_unused =
5777 !block_ty.hasRuntimeBitsIgnoreComptime(pt) or func.liveness.isUnused(br.block_inst);
5781 !block_ty.hasRuntimeBitsIgnoreComptime(zcu) or func.liveness.isUnused(br.block_inst);
57785782 const block_tracking = func.inst_tracking.getPtr(br.block_inst).?;
57795783 const block_data = func.blocks.getPtr(br.block_inst).?;
57805784 const first_br = block_data.relocs.items.len == 0;
......@@ -6354,6 +6358,8 @@ fn genCopy(func: *Func, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {
63546358 return std.debug.panic("tried to genCopy immutable: {s}", .{@tagName(dst_mcv)});
63556359 }
63566360
6361 const zcu = func.pt.zcu;
6362
63576363 switch (dst_mcv) {
63586364 .register => |reg| return func.genSetReg(ty, reg, src_mcv),
63596365 .register_offset => |dst_reg_off| try func.genSetReg(ty, dst_reg_off.reg, switch (src_mcv) {
......@@ -6425,7 +6431,7 @@ fn genCopy(func: *Func, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {
64256431 } },
64266432 else => unreachable,
64276433 });
6428 part_disp += @intCast(dst_ty.abiSize(func.pt));
6434 part_disp += @intCast(dst_ty.abiSize(zcu));
64296435 }
64306436 },
64316437 else => return std.debug.panic("TODO: genCopy to {s} from {s}", .{ @tagName(dst_mcv), @tagName(src_mcv) }),
......@@ -6622,7 +6628,7 @@ fn genInlineMemset(
66226628fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!void {
66236629 const pt = func.pt;
66246630 const zcu = pt.zcu;
6625 const abi_size: u32 = @intCast(ty.abiSize(pt));
6631 const abi_size: u32 = @intCast(ty.abiSize(zcu));
66266632
66276633 const max_size: u32 = switch (reg.class()) {
66286634 .int => 64,
......@@ -6729,7 +6735,7 @@ fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!
67296735 // size to the total size of the vector, and vmv.x.s will work then
67306736 if (src_reg.class() == .vector) {
67316737 try func.setVl(.zero, 0, .{
6732 .vsew = switch (ty.totalVectorBits(pt)) {
6738 .vsew = switch (ty.totalVectorBits(zcu)) {
67336739 8 => .@"8",
67346740 16 => .@"16",
67356741 32 => .@"32",
......@@ -6848,7 +6854,7 @@ fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!
68486854 // and load from it.
68496855 const len = ty.vectorLen(zcu);
68506856 const elem_ty = ty.childType(zcu);
6851 const elem_size = elem_ty.abiSize(pt);
6857 const elem_size = elem_ty.abiSize(zcu);
68526858
68536859 try func.setVl(.zero, len, .{
68546860 .vsew = switch (elem_size) {
......@@ -6945,7 +6951,7 @@ fn genSetMem(
69456951 const pt = func.pt;
69466952 const zcu = pt.zcu;
69476953
6948 const abi_size: u32 = @intCast(ty.abiSize(pt));
6954 const abi_size: u32 = @intCast(ty.abiSize(zcu));
69496955 const dst_ptr_mcv: MCValue = switch (base) {
69506956 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },
69516957 .frame => |base_frame_index| .{ .lea_frame = .{ .index = base_frame_index, .off = disp } },
......@@ -6995,7 +7001,7 @@ fn genSetMem(
69957001 const addr_reg = try func.copyToTmpRegister(Type.u64, dst_ptr_mcv);
69967002
69977003 const num_elem = ty.vectorLen(zcu);
6998 const elem_size = ty.childType(zcu).bitSize(pt);
7004 const elem_size = ty.childType(zcu).bitSize(zcu);
69997005
70007006 try func.setVl(.zero, num_elem, .{
70017007 .vsew = switch (elem_size) {
......@@ -7083,7 +7089,7 @@ fn genSetMem(
70837089 var part_disp: i32 = disp;
70847090 for (try func.splitType(ty), src_regs) |src_ty, src_reg| {
70857091 try func.genSetMem(base, part_disp, src_ty, .{ .register = src_reg });
7086 part_disp += @intCast(src_ty.abiSize(pt));
7092 part_disp += @intCast(src_ty.abiSize(zcu));
70877093 }
70887094 },
70897095 .immediate => {
......@@ -7128,10 +7134,10 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
71287134 const src_lock = if (src_mcv.getReg()) |reg| func.register_manager.lockReg(reg) else null;
71297135 defer if (src_lock) |lock| func.register_manager.unlockReg(lock);
71307136
7131 const dst_mcv = if (dst_ty.abiSize(pt) <= src_ty.abiSize(pt) and src_mcv != .register_pair and
7137 const dst_mcv = if (dst_ty.abiSize(zcu) <= src_ty.abiSize(zcu) and src_mcv != .register_pair and
71327138 func.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {
71337139 const dst_mcv = try func.allocRegOrMem(dst_ty, inst, true);
7134 try func.genCopy(switch (math.order(dst_ty.abiSize(pt), src_ty.abiSize(pt))) {
7140 try func.genCopy(switch (math.order(dst_ty.abiSize(zcu), src_ty.abiSize(zcu))) {
71357141 .lt => dst_ty,
71367142 .eq => if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,
71377143 .gt => src_ty,
......@@ -7142,8 +7148,8 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
71427148 if (dst_ty.isAbiInt(zcu) and src_ty.isAbiInt(zcu) and
71437149 dst_ty.intInfo(zcu).signedness == src_ty.intInfo(zcu).signedness) break :result dst_mcv;
71447150
7145 const abi_size = dst_ty.abiSize(pt);
7146 const bit_size = dst_ty.bitSize(pt);
7151 const abi_size = dst_ty.abiSize(zcu);
7152 const bit_size = dst_ty.bitSize(zcu);
71477153 if (abi_size * 8 <= bit_size) break :result dst_mcv;
71487154
71497155 return func.fail("TODO: airBitCast {} to {}", .{ src_ty.fmt(pt), dst_ty.fmt(pt) });
......@@ -7162,11 +7168,11 @@ fn airArrayToSlice(func: *Func, inst: Air.Inst.Index) !void {
71627168 const array_ty = ptr_ty.childType(zcu);
71637169 const array_len = array_ty.arrayLen(zcu);
71647170
7165 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(slice_ty, pt));
7171 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(slice_ty, zcu));
71667172 try func.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
71677173 try func.genSetMem(
71687174 .{ .frame = frame_index },
7169 @intCast(ptr_ty.abiSize(pt)),
7175 @intCast(ptr_ty.abiSize(zcu)),
71707176 Type.u64,
71717177 .{ .immediate = array_len },
71727178 );
......@@ -7190,21 +7196,21 @@ fn airFloatFromInt(func: *Func, inst: Air.Inst.Index) !void {
71907196 defer if (src_lock) |lock| func.register_manager.unlockReg(lock);
71917197
71927198 const is_unsigned = dst_ty.isUnsignedInt(zcu);
7193 const src_bits = src_ty.bitSize(pt);
7194 const dst_bits = dst_ty.bitSize(pt);
7199 const src_bits = src_ty.bitSize(zcu);
7200 const dst_bits = dst_ty.bitSize(zcu);
71957201
71967202 switch (src_bits) {
71977203 32, 64 => {},
71987204 else => try func.truncateRegister(src_ty, src_reg),
71997205 }
72007206
7201 const int_mod: Mir.FcvtOp = switch (src_bits) {
7207 const int_zcu: Mir.FcvtOp = switch (src_bits) {
72027208 8, 16, 32 => if (is_unsigned) .wu else .w,
72037209 64 => if (is_unsigned) .lu else .l,
72047210 else => return func.fail("TODO: airFloatFromInt src size: {d}", .{src_bits}),
72057211 };
72067212
7207 const float_mod: enum { s, d } = switch (dst_bits) {
7213 const float_zcu: enum { s, d } = switch (dst_bits) {
72087214 32 => .s,
72097215 64 => .d,
72107216 else => return func.fail("TODO: airFloatFromInt dst size {d}", .{dst_bits}),
......@@ -7214,14 +7220,14 @@ fn airFloatFromInt(func: *Func, inst: Air.Inst.Index) !void {
72147220 defer func.register_manager.unlockReg(dst_lock);
72157221
72167222 _ = try func.addInst(.{
7217 .tag = switch (float_mod) {
7218 .s => switch (int_mod) {
7223 .tag = switch (float_zcu) {
7224 .s => switch (int_zcu) {
72197225 .l => .fcvtsl,
72207226 .lu => .fcvtslu,
72217227 .w => .fcvtsw,
72227228 .wu => .fcvtswu,
72237229 },
7224 .d => switch (int_mod) {
7230 .d => switch (int_zcu) {
72257231 .l => .fcvtdl,
72267232 .lu => .fcvtdlu,
72277233 .w => .fcvtdw,
......@@ -7250,16 +7256,16 @@ fn airIntFromFloat(func: *Func, inst: Air.Inst.Index) !void {
72507256 const dst_ty = ty_op.ty.toType();
72517257
72527258 const is_unsigned = dst_ty.isUnsignedInt(zcu);
7253 const src_bits = src_ty.bitSize(pt);
7254 const dst_bits = dst_ty.bitSize(pt);
7259 const src_bits = src_ty.bitSize(zcu);
7260 const dst_bits = dst_ty.bitSize(zcu);
72557261
7256 const float_mod: enum { s, d } = switch (src_bits) {
7262 const float_zcu: enum { s, d } = switch (src_bits) {
72577263 32 => .s,
72587264 64 => .d,
72597265 else => return func.fail("TODO: airIntFromFloat src size {d}", .{src_bits}),
72607266 };
72617267
7262 const int_mod: Mir.FcvtOp = switch (dst_bits) {
7268 const int_zcu: Mir.FcvtOp = switch (dst_bits) {
72637269 32 => if (is_unsigned) .wu else .w,
72647270 8, 16, 64 => if (is_unsigned) .lu else .l,
72657271 else => return func.fail("TODO: airIntFromFloat dst size: {d}", .{dst_bits}),
......@@ -7272,14 +7278,14 @@ fn airIntFromFloat(func: *Func, inst: Air.Inst.Index) !void {
72727278 defer func.register_manager.unlockReg(dst_lock);
72737279
72747280 _ = try func.addInst(.{
7275 .tag = switch (float_mod) {
7276 .s => switch (int_mod) {
7281 .tag = switch (float_zcu) {
7282 .s => switch (int_zcu) {
72777283 .l => .fcvtls,
72787284 .lu => .fcvtlus,
72797285 .w => .fcvtws,
72807286 .wu => .fcvtwus,
72817287 },
7282 .d => switch (int_mod) {
7288 .d => switch (int_zcu) {
72837289 .l => .fcvtld,
72847290 .lu => .fcvtlud,
72857291 .w => .fcvtwd,
......@@ -7301,12 +7307,13 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
73017307 _ = strength; // TODO: do something with this
73027308
73037309 const pt = func.pt;
7310 const zcu = pt.zcu;
73047311 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
73057312 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
73067313
73077314 const ptr_ty = func.typeOf(extra.ptr);
73087315 const val_ty = func.typeOf(extra.expected_value);
7309 const val_abi_size: u32 = @intCast(val_ty.abiSize(pt));
7316 const val_abi_size: u32 = @intCast(val_ty.abiSize(pt.zcu));
73107317
73117318 switch (val_abi_size) {
73127319 1, 2, 4, 8 => {},
......@@ -7364,7 +7371,7 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
73647371 defer func.register_manager.unlockReg(fallthrough_lock);
73657372
73667373 const jump_back = try func.addInst(.{
7367 .tag = if (val_ty.bitSize(pt) <= 32) .lrw else .lrd,
7374 .tag = if (val_ty.bitSize(zcu) <= 32) .lrw else .lrd,
73687375 .data = .{ .amo = .{
73697376 .aq = lr_order.aq,
73707377 .rl = lr_order.rl,
......@@ -7385,7 +7392,7 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
73857392 });
73867393
73877394 _ = try func.addInst(.{
7388 .tag = if (val_ty.bitSize(pt) <= 32) .scw else .scd,
7395 .tag = if (val_ty.bitSize(zcu) <= 32) .scw else .scd,
73897396 .data = .{ .amo = .{
73907397 .aq = sc_order.aq,
73917398 .rl = sc_order.rl,
......@@ -7449,7 +7456,7 @@ fn airAtomicRmw(func: *Func, inst: Air.Inst.Index) !void {
74497456 const ptr_mcv = try func.resolveInst(pl_op.operand);
74507457
74517458 const val_ty = func.typeOf(extra.operand);
7452 const val_size = val_ty.abiSize(pt);
7459 const val_size = val_ty.abiSize(zcu);
74537460 const val_mcv = try func.resolveInst(extra.operand);
74547461
74557462 if (!math.isPowerOfTwo(val_size))
......@@ -7488,7 +7495,7 @@ fn airAtomicRmw(func: *Func, inst: Air.Inst.Index) !void {
74887495
74897496 switch (method) {
74907497 .amo => {
7491 const is_d = val_ty.abiSize(pt) == 8;
7498 const is_d = val_ty.abiSize(zcu) == 8;
74927499 const is_un = val_ty.isUnsignedInt(zcu);
74937500
74947501 const mnem: Mnemonic = switch (op) {
......@@ -7587,7 +7594,7 @@ fn airAtomicLoad(func: *Func, inst: Air.Inst.Index) !void {
75877594 const elem_ty = ptr_ty.childType(zcu);
75887595 const ptr_mcv = try func.resolveInst(atomic_load.ptr);
75897596
7590 const bit_size = elem_ty.bitSize(pt);
7597 const bit_size = elem_ty.bitSize(zcu);
75917598 if (bit_size > 64) return func.fail("TODO: airAtomicStore > 64 bits", .{});
75927599
75937600 const result_mcv = try func.allocRegOrMem(elem_ty, inst, true);
......@@ -7634,7 +7641,7 @@ fn airAtomicStore(func: *Func, inst: Air.Inst.Index, order: std.builtin.AtomicOr
76347641 const val_ty = func.typeOf(bin_op.rhs);
76357642 const val_mcv = try func.resolveInst(bin_op.rhs);
76367643
7637 const bit_size = val_ty.bitSize(func.pt);
7644 const bit_size = val_ty.bitSize(func.pt.zcu);
76387645 if (bit_size > 64) return func.fail("TODO: airAtomicStore > 64 bits", .{});
76397646
76407647 switch (order) {
......@@ -7679,7 +7686,7 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
76797686 };
76807687 defer if (src_val_lock) |lock| func.register_manager.unlockReg(lock);
76817688
7682 const elem_abi_size: u31 = @intCast(elem_ty.abiSize(pt));
7689 const elem_abi_size: u31 = @intCast(elem_ty.abiSize(zcu));
76837690
76847691 if (elem_abi_size == 1) {
76857692 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
......@@ -7751,7 +7758,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {
77517758 const len_reg, const len_lock = try func.allocReg(.int);
77527759 defer func.register_manager.unlockReg(len_lock);
77537760
7754 const elem_size = dst_ty.childType(zcu).abiSize(pt);
7761 const elem_size = dst_ty.childType(zcu).abiSize(zcu);
77557762 try func.genBinOp(
77567763 .mul,
77577764 .{ .immediate = elem_size },
......@@ -7764,7 +7771,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {
77647771 },
77657772 .One => len: {
77667773 const array_ty = dst_ty.childType(zcu);
7767 break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(pt) };
7774 break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(zcu) };
77687775 },
77697776 else => |size| return func.fail("TODO: airMemcpy size {s}", .{@tagName(size)}),
77707777 };
......@@ -7862,13 +7869,13 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
78627869 const result: MCValue = result: {
78637870 switch (result_ty.zigTypeTag(zcu)) {
78647871 .Struct => {
7865 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(result_ty, pt));
7872 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(result_ty, zcu));
78667873 if (result_ty.containerLayout(zcu) == .@"packed") {
78677874 const struct_obj = zcu.typeToStruct(result_ty).?;
78687875 try func.genInlineMemset(
78697876 .{ .lea_frame = .{ .index = frame_index } },
78707877 .{ .immediate = 0 },
7871 .{ .immediate = result_ty.abiSize(pt) },
7878 .{ .immediate = result_ty.abiSize(zcu) },
78727879 );
78737880
78747881 for (elements, 0..) |elem, elem_i_usize| {
......@@ -7876,7 +7883,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
78767883 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
78777884
78787885 const elem_ty = result_ty.structFieldType(elem_i, zcu);
7879 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(pt));
7886 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(zcu));
78807887 if (elem_bit_size > 64) {
78817888 return func.fail(
78827889 "TODO airAggregateInit implement packed structs with large fields",
......@@ -7884,7 +7891,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
78847891 );
78857892 }
78867893
7887 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(pt));
7894 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(zcu));
78887895 const elem_abi_bits = elem_abi_size * 8;
78897896 const elem_off = pt.structPackedFieldBitOffset(struct_obj, elem_i);
78907897 const elem_byte_off: i32 = @intCast(elem_off / elem_abi_bits * elem_abi_size);
......@@ -7910,7 +7917,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
79107917 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
79117918
79127919 const elem_ty = result_ty.structFieldType(elem_i, zcu);
7913 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, pt));
7920 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, zcu));
79147921 const elem_mcv = try func.resolveInst(elem);
79157922 try func.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, elem_mcv);
79167923 }
......@@ -7918,8 +7925,8 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
79187925 },
79197926 .Array => {
79207927 const elem_ty = result_ty.childType(zcu);
7921 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(result_ty, pt));
7922 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));
7928 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(result_ty, zcu));
7929 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
79237930
79247931 for (elements, 0..) |elem, elem_i| {
79257932 const elem_mcv = try func.resolveInst(elem);
......@@ -7979,10 +7986,11 @@ fn airMulAdd(func: *Func, inst: Air.Inst.Index) !void {
79797986
79807987fn resolveInst(func: *Func, ref: Air.Inst.Ref) InnerError!MCValue {
79817988 const pt = func.pt;
7989 const zcu = pt.zcu;
79827990
79837991 // If the type has no codegen bits, no need to store it.
79847992 const inst_ty = func.typeOf(ref);
7985 if (!inst_ty.hasRuntimeBits(pt))
7993 if (!inst_ty.hasRuntimeBits(zcu))
79867994 return .none;
79877995
79887996 const mcv = if (ref.toIndex()) |inst| mcv: {
......@@ -8100,14 +8108,14 @@ fn resolveCallingConventionValues(
81008108 // Return values
81018109 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
81028110 result.return_value = InstTracking.init(.unreach);
8103 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
8111 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
81048112 result.return_value = InstTracking.init(.none);
81058113 } else {
81068114 var ret_tracking: [2]InstTracking = undefined;
81078115 var ret_tracking_i: usize = 0;
81088116 var ret_float_reg_i: usize = 0;
81098117
8110 const classes = mem.sliceTo(&abi.classifySystem(ret_ty, pt), .none);
8118 const classes = mem.sliceTo(&abi.classifySystem(ret_ty, zcu), .none);
81118119
81128120 for (classes) |class| switch (class) {
81138121 .integer => {
......@@ -8151,7 +8159,7 @@ fn resolveCallingConventionValues(
81518159 var param_float_reg_i: usize = 0;
81528160
81538161 for (param_types, result.args) |ty, *arg| {
8154 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
8162 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
81558163 assert(cc == .Unspecified);
81568164 arg.* = .none;
81578165 continue;
......@@ -8160,7 +8168,7 @@ fn resolveCallingConventionValues(
81608168 var arg_mcv: [2]MCValue = undefined;
81618169 var arg_mcv_i: usize = 0;
81628170
8163 const classes = mem.sliceTo(&abi.classifySystem(ty, pt), .none);
8171 const classes = mem.sliceTo(&abi.classifySystem(ty, zcu), .none);
81648172
81658173 for (classes) |class| switch (class) {
81668174 .integer => {
......@@ -8244,8 +8252,7 @@ fn typeOf(func: *Func, inst: Air.Inst.Ref) Type {
82448252}
82458253
82468254fn typeOfIndex(func: *Func, inst: Air.Inst.Index) Type {
8247 const pt = func.pt;
8248 const zcu = pt.zcu;
8255 const zcu = func.pt.zcu;
82498256 return func.air.typeOfIndex(inst, &zcu.intern_pool);
82508257}
82518258
......@@ -8253,23 +8260,23 @@ fn hasFeature(func: *Func, feature: Target.riscv.Feature) bool {
82538260 return Target.riscv.featureSetHas(func.target.cpu.features, feature);
82548261}
82558262
8256pub fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {
8257 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;
8258 const payload_align = payload_ty.abiAlignment(pt);
8259 const error_align = Type.anyerror.abiAlignment(pt);
8260 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
8263pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
8264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
8265 const payload_align = payload_ty.abiAlignment(zcu);
8266 const error_align = Type.anyerror.abiAlignment(zcu);
8267 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
82618268 return 0;
82628269 } else {
8263 return payload_align.forward(Type.anyerror.abiSize(pt));
8270 return payload_align.forward(Type.anyerror.abiSize(zcu));
82648271 }
82658272}
82668273
8267pub fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {
8268 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;
8269 const payload_align = payload_ty.abiAlignment(pt);
8270 const error_align = Type.anyerror.abiAlignment(pt);
8271 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
8272 return error_align.forward(payload_ty.abiSize(pt));
8274pub fn errUnionErrorOffset(payload_ty: Type, zcu: *Zcu) u64 {
8275 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
8276 const payload_align = payload_ty.abiAlignment(zcu);
8277 const error_align = Type.anyerror.abiAlignment(zcu);
8278 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8279 return error_align.forward(payload_ty.abiSize(zcu));
82738280 } else {
82748281 return 0;
82758282 }
src/arch/riscv64/Lower.zig+4-3
......@@ -49,6 +49,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index, options: struct {
4949 relocs: []const Reloc,
5050} {
5151 const pt = lower.pt;
52 const zcu = pt.zcu;
5253
5354 lower.result_insts = undefined;
5455 lower.result_relocs = undefined;
......@@ -308,11 +309,11 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index, options: struct {
308309
309310 const class = rs1.class();
310311 const ty = compare.ty;
311 const size = std.math.ceilPowerOfTwo(u64, ty.bitSize(pt)) catch {
312 return lower.fail("pseudo_compare size {}", .{ty.bitSize(pt)});
312 const size = std.math.ceilPowerOfTwo(u64, ty.bitSize(zcu)) catch {
313 return lower.fail("pseudo_compare size {}", .{ty.bitSize(zcu)});
313314 };
314315
315 const is_unsigned = ty.isUnsignedInt(pt.zcu);
316 const is_unsigned = ty.isUnsignedInt(zcu);
316317 const less_than: Mnemonic = if (is_unsigned) .sltu else .slt;
317318
318319 switch (class) {
src/arch/riscv64/abi.zig+27-28
......@@ -9,15 +9,15 @@ const assert = std.debug.assert;
99
1010pub const Class = enum { memory, byval, integer, double_integer, fields };
1111
12pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
13 const target = pt.zcu.getTarget();
14 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(pt));
12pub fn classifyType(ty: Type, zcu: *Zcu) Class {
13 const target = zcu.getTarget();
14 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
1515
1616 const max_byval_size = target.ptrBitWidth() * 2;
17 switch (ty.zigTypeTag(pt.zcu)) {
17 switch (ty.zigTypeTag(zcu)) {
1818 .Struct => {
19 const bit_size = ty.bitSize(pt);
20 if (ty.containerLayout(pt.zcu) == .@"packed") {
19 const bit_size = ty.bitSize(zcu);
20 if (ty.containerLayout(zcu) == .@"packed") {
2121 if (bit_size > max_byval_size) return .memory;
2222 return .byval;
2323 }
......@@ -25,12 +25,12 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
2525 if (std.Target.riscv.featureSetHas(target.cpu.features, .d)) fields: {
2626 var any_fp = false;
2727 var field_count: usize = 0;
28 for (0..ty.structFieldCount(pt.zcu)) |field_index| {
29 const field_ty = ty.structFieldType(field_index, pt.zcu);
30 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
28 for (0..ty.structFieldCount(zcu)) |field_index| {
29 const field_ty = ty.structFieldType(field_index, zcu);
30 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
3131 if (field_ty.isRuntimeFloat())
3232 any_fp = true
33 else if (!field_ty.isAbiInt(pt.zcu))
33 else if (!field_ty.isAbiInt(zcu))
3434 break :fields;
3535 field_count += 1;
3636 if (field_count > 2) break :fields;
......@@ -45,8 +45,8 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
4545 return .integer;
4646 },
4747 .Union => {
48 const bit_size = ty.bitSize(pt);
49 if (ty.containerLayout(pt.zcu) == .@"packed") {
48 const bit_size = ty.bitSize(zcu);
49 if (ty.containerLayout(zcu) == .@"packed") {
5050 if (bit_size > max_byval_size) return .memory;
5151 return .byval;
5252 }
......@@ -58,21 +58,21 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
5858 .Bool => return .integer,
5959 .Float => return .byval,
6060 .Int, .Enum, .ErrorSet => {
61 const bit_size = ty.bitSize(pt);
61 const bit_size = ty.bitSize(zcu);
6262 if (bit_size > max_byval_size) return .memory;
6363 return .byval;
6464 },
6565 .Vector => {
66 const bit_size = ty.bitSize(pt);
66 const bit_size = ty.bitSize(zcu);
6767 if (bit_size > max_byval_size) return .memory;
6868 return .integer;
6969 },
7070 .Optional => {
71 std.debug.assert(ty.isPtrLikeOptional(pt.zcu));
71 std.debug.assert(ty.isPtrLikeOptional(zcu));
7272 return .byval;
7373 },
7474 .Pointer => {
75 std.debug.assert(!ty.isSlice(pt.zcu));
75 std.debug.assert(!ty.isSlice(zcu));
7676 return .byval;
7777 },
7878 .ErrorUnion,
......@@ -97,19 +97,18 @@ pub const SystemClass = enum { integer, float, memory, none };
9797
9898/// There are a maximum of 8 possible return slots. Returned values are in
9999/// the beginning of the array; unused slots are filled with .none.
100pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
101 const zcu = pt.zcu;
100pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass {
102101 var result = [1]SystemClass{.none} ** 8;
103102 const memory_class = [_]SystemClass{
104103 .memory, .none, .none, .none,
105104 .none, .none, .none, .none,
106105 };
107 switch (ty.zigTypeTag(pt.zcu)) {
106 switch (ty.zigTypeTag(zcu)) {
108107 .Bool, .Void, .NoReturn => {
109108 result[0] = .integer;
110109 return result;
111110 },
112 .Pointer => switch (ty.ptrSize(pt.zcu)) {
111 .Pointer => switch (ty.ptrSize(zcu)) {
113112 .Slice => {
114113 result[0] = .integer;
115114 result[1] = .integer;
......@@ -121,14 +120,14 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
121120 },
122121 },
123122 .Optional => {
124 if (ty.isPtrLikeOptional(pt.zcu)) {
123 if (ty.isPtrLikeOptional(zcu)) {
125124 result[0] = .integer;
126125 return result;
127126 }
128127 return memory_class;
129128 },
130129 .Int, .Enum, .ErrorSet => {
131 const int_bits = ty.intInfo(pt.zcu).bits;
130 const int_bits = ty.intInfo(zcu).bits;
132131 if (int_bits <= 64) {
133132 result[0] = .integer;
134133 return result;
......@@ -153,8 +152,8 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
153152 unreachable; // support split float args
154153 },
155154 .ErrorUnion => {
156 const payload_ty = ty.errorUnionPayload(pt.zcu);
157 const payload_bits = payload_ty.bitSize(pt);
155 const payload_ty = ty.errorUnionPayload(zcu);
156 const payload_bits = payload_ty.bitSize(zcu);
158157
159158 // the error union itself
160159 result[0] = .integer;
......@@ -165,8 +164,8 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
165164 return memory_class;
166165 },
167166 .Struct, .Union => {
168 const layout = ty.containerLayout(pt.zcu);
169 const ty_size = ty.abiSize(pt);
167 const layout = ty.containerLayout(zcu);
168 const ty_size = ty.abiSize(zcu);
170169
171170 if (layout == .@"packed") {
172171 assert(ty_size <= 16);
......@@ -178,7 +177,7 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
178177 return memory_class;
179178 },
180179 .Array => {
181 const ty_size = ty.abiSize(pt);
180 const ty_size = ty.abiSize(zcu);
182181 if (ty_size <= 8) {
183182 result[0] = .integer;
184183 return result;
......@@ -192,7 +191,7 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
192191 },
193192 .Vector => {
194193 // we pass vectors through integer registers if they are small enough to fit.
195 const vec_bits = ty.totalVectorBits(pt);
194 const vec_bits = ty.totalVectorBits(zcu);
196195 if (vec_bits <= 64) {
197196 result[0] = .integer;
198197 return result;
src/arch/sparc64/CodeGen.zig+99-96
......@@ -1012,6 +1012,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
10121012
10131013fn airArg(self: *Self, inst: Air.Inst.Index) !void {
10141014 const pt = self.pt;
1015 const zcu = pt.zcu;
10151016 const arg_index = self.arg_index;
10161017 self.arg_index += 1;
10171018
......@@ -1021,7 +1022,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
10211022 const mcv = blk: {
10221023 switch (arg) {
10231024 .stack_offset => |off| {
1024 const abi_size = math.cast(u32, ty.abiSize(pt)) orelse {
1025 const abi_size = math.cast(u32, ty.abiSize(zcu)) orelse {
10251026 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});
10261027 };
10271028 const offset = off + abi_size;
......@@ -1211,7 +1212,7 @@ fn airBreakpoint(self: *Self) !void {
12111212
12121213fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12131214 const pt = self.pt;
1214 const mod = pt.zcu;
1215 const zcu = pt.zcu;
12151216 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
12161217
12171218 // We have hardware byteswapper in SPARCv9, don't let mainstream compilers mislead you.
......@@ -1227,14 +1228,14 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
12271228 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
12281229 const operand = try self.resolveInst(ty_op.operand);
12291230 const operand_ty = self.typeOf(ty_op.operand);
1230 switch (operand_ty.zigTypeTag(mod)) {
1231 switch (operand_ty.zigTypeTag(zcu)) {
12311232 .Vector => return self.fail("TODO byteswap for vectors", .{}),
12321233 .Int => {
1233 const int_info = operand_ty.intInfo(mod);
1234 const int_info = operand_ty.intInfo(zcu);
12341235 if (int_info.bits == 8) break :result operand;
12351236
12361237 const abi_size = int_info.bits >> 3;
1237 const abi_align = operand_ty.abiAlignment(pt);
1238 const abi_align = operand_ty.abiAlignment(zcu);
12381239 const opposite_endian_asi = switch (self.target.cpu.arch.endian()) {
12391240 Endian.big => ASI.asi_primary_little,
12401241 Endian.little => ASI.asi_primary,
......@@ -1409,24 +1410,24 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
14091410fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
14101411 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
14111412 const pt = self.pt;
1412 const mod = pt.zcu;
1413 const zcu = pt.zcu;
14131414 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
14141415 const lhs = try self.resolveInst(bin_op.lhs);
14151416 const rhs = try self.resolveInst(bin_op.rhs);
14161417 const lhs_ty = self.typeOf(bin_op.lhs);
14171418
1418 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {
1419 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {
14191420 .Vector => unreachable, // Handled by cmp_vector.
1420 .Enum => lhs_ty.intTagType(mod),
1421 .Enum => lhs_ty.intTagType(zcu),
14211422 .Int => lhs_ty,
14221423 .Bool => Type.u1,
14231424 .Pointer => Type.usize,
14241425 .ErrorSet => Type.u16,
14251426 .Optional => blk: {
1426 const payload_ty = lhs_ty.optionalChild(mod);
1427 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1427 const payload_ty = lhs_ty.optionalChild(zcu);
1428 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
14281429 break :blk Type.u1;
1429 } else if (lhs_ty.isPtrLikeOptional(mod)) {
1430 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
14301431 break :blk Type.usize;
14311432 } else {
14321433 return self.fail("TODO SPARCv9 cmp non-pointer optionals", .{});
......@@ -1436,7 +1437,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
14361437 else => unreachable,
14371438 };
14381439
1439 const int_info = int_ty.intInfo(mod);
1440 const int_info = int_ty.intInfo(zcu);
14401441 if (int_info.bits <= 64) {
14411442 _ = try self.binOp(.cmp_eq, lhs, rhs, int_ty, int_ty, BinOpMetadata{
14421443 .lhs = bin_op.lhs,
......@@ -1797,16 +1798,16 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
17971798
17981799fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
17991800 const pt = self.pt;
1800 const mod = pt.zcu;
1801 const zcu = pt.zcu;
18011802 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
18021803 const elem_ty = self.typeOfIndex(inst);
1803 const elem_size = elem_ty.abiSize(pt);
1804 const elem_size = elem_ty.abiSize(zcu);
18041805 const result: MCValue = result: {
1805 if (!elem_ty.hasRuntimeBits(pt))
1806 if (!elem_ty.hasRuntimeBits(zcu))
18061807 break :result MCValue.none;
18071808
18081809 const ptr = try self.resolveInst(ty_op.operand);
1809 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(mod);
1810 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(zcu);
18101811 if (self.liveness.isUnused(inst) and !is_volatile)
18111812 break :result MCValue.dead;
18121813
......@@ -2428,7 +2429,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
24282429
24292430fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24302431 const pt = self.pt;
2431 const mod = pt.zcu;
2432 const zcu = pt.zcu;
24322433 const is_volatile = false; // TODO
24332434 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
24342435
......@@ -2438,10 +2439,10 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24382439 const index_mcv = try self.resolveInst(bin_op.rhs);
24392440
24402441 const slice_ty = self.typeOf(bin_op.lhs);
2441 const elem_ty = slice_ty.childType(mod);
2442 const elem_size = elem_ty.abiSize(pt);
2442 const elem_ty = slice_ty.childType(zcu);
2443 const elem_size = elem_ty.abiSize(zcu);
24432444
2444 const slice_ptr_field_type = slice_ty.slicePtrFieldType(mod);
2445 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
24452446
24462447 const index_lock: ?RegisterLock = if (index_mcv == .register)
24472448 self.register_manager.lockRegAssumeUnused(index_mcv.register)
......@@ -2553,10 +2554,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
25532554 const operand = extra.struct_operand;
25542555 const index = extra.field_index;
25552556 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2556 const pt = self.pt;
2557 const zcu = self.pt.zcu;
25572558 const mcv = try self.resolveInst(operand);
25582559 const struct_ty = self.typeOf(operand);
2559 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));
2560 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
25602561
25612562 switch (mcv) {
25622563 .dead, .unreach => unreachable,
......@@ -2687,13 +2688,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
26872688
26882689fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
26892690 const pt = self.pt;
2690 const mod = pt.zcu;
2691 const zcu = pt.zcu;
26912692 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
26922693 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
26932694 const error_union_ty = self.typeOf(ty_op.operand);
2694 const payload_ty = error_union_ty.errorUnionPayload(mod);
2695 const payload_ty = error_union_ty.errorUnionPayload(zcu);
26952696 const mcv = try self.resolveInst(ty_op.operand);
2696 if (!payload_ty.hasRuntimeBits(pt)) break :result mcv;
2697 if (!payload_ty.hasRuntimeBits(zcu)) break :result mcv;
26972698
26982699 return self.fail("TODO implement unwrap error union error for non-empty payloads", .{});
26992700 };
......@@ -2702,12 +2703,12 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27022703
27032704fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
27042705 const pt = self.pt;
2705 const mod = pt.zcu;
2706 const zcu = pt.zcu;
27062707 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
27072708 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
27082709 const error_union_ty = self.typeOf(ty_op.operand);
2709 const payload_ty = error_union_ty.errorUnionPayload(mod);
2710 if (!payload_ty.hasRuntimeBits(pt)) break :result MCValue.none;
2710 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2711 if (!payload_ty.hasRuntimeBits(zcu)) break :result MCValue.none;
27112712
27122713 return self.fail("TODO implement unwrap error union payload for non-empty payloads", .{});
27132714 };
......@@ -2717,13 +2718,13 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
27172718/// E to E!T
27182719fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
27192720 const pt = self.pt;
2720 const mod = pt.zcu;
2721 const zcu = pt.zcu;
27212722 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
27222723 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
27232724 const error_union_ty = ty_op.ty.toType();
2724 const payload_ty = error_union_ty.errorUnionPayload(mod);
2725 const payload_ty = error_union_ty.errorUnionPayload(zcu);
27252726 const mcv = try self.resolveInst(ty_op.operand);
2726 if (!payload_ty.hasRuntimeBits(pt)) break :result mcv;
2727 if (!payload_ty.hasRuntimeBits(zcu)) break :result mcv;
27272728
27282729 return self.fail("TODO implement wrap errunion error for non-empty payloads", .{});
27292730 };
......@@ -2744,7 +2745,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
27442745 const optional_ty = self.typeOfIndex(inst);
27452746
27462747 // Optional with a zero-bit payload type is just a boolean true
2747 if (optional_ty.abiSize(pt) == 1)
2748 if (optional_ty.abiSize(pt.zcu) == 1)
27482749 break :result MCValue{ .immediate = 1 };
27492750
27502751 return self.fail("TODO implement wrap optional for {}", .{self.target.cpu.arch});
......@@ -2779,10 +2780,10 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: Alignme
27792780/// Use a pointer instruction as the basis for allocating stack memory.
27802781fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
27812782 const pt = self.pt;
2782 const mod = pt.zcu;
2783 const elem_ty = self.typeOfIndex(inst).childType(mod);
2783 const zcu = pt.zcu;
2784 const elem_ty = self.typeOfIndex(inst).childType(zcu);
27842785
2785 if (!elem_ty.hasRuntimeBits(pt)) {
2786 if (!elem_ty.hasRuntimeBits(zcu)) {
27862787 // As this stack item will never be dereferenced at runtime,
27872788 // return the stack offset 0. Stack offset 0 will be where all
27882789 // zero-sized stack allocations live as non-zero-sized
......@@ -2790,21 +2791,22 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
27902791 return @as(u32, 0);
27912792 }
27922793
2793 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
2794 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
27942795 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
27952796 };
27962797 // TODO swap this for inst.ty.ptrAlign
2797 const abi_align = elem_ty.abiAlignment(pt);
2798 const abi_align = elem_ty.abiAlignment(zcu);
27982799 return self.allocMem(inst, abi_size, abi_align);
27992800}
28002801
28012802fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
28022803 const pt = self.pt;
2804 const zcu = pt.zcu;
28032805 const elem_ty = self.typeOfIndex(inst);
2804 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
2806 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
28052807 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
28062808 };
2807 const abi_align = elem_ty.abiAlignment(pt);
2809 const abi_align = elem_ty.abiAlignment(zcu);
28082810 self.stack_align = self.stack_align.max(abi_align);
28092811
28102812 if (reg_ok) {
......@@ -2847,7 +2849,7 @@ fn binOp(
28472849 metadata: ?BinOpMetadata,
28482850) InnerError!MCValue {
28492851 const pt = self.pt;
2850 const mod = pt.zcu;
2852 const zcu = pt.zcu;
28512853 switch (tag) {
28522854 .add,
28532855 .sub,
......@@ -2857,12 +2859,12 @@ fn binOp(
28572859 .xor,
28582860 .cmp_eq,
28592861 => {
2860 switch (lhs_ty.zigTypeTag(mod)) {
2862 switch (lhs_ty.zigTypeTag(zcu)) {
28612863 .Float => return self.fail("TODO binary operations on floats", .{}),
28622864 .Vector => return self.fail("TODO binary operations on vectors", .{}),
28632865 .Int => {
2864 assert(lhs_ty.eql(rhs_ty, mod));
2865 const int_info = lhs_ty.intInfo(mod);
2866 assert(lhs_ty.eql(rhs_ty, zcu));
2867 const int_info = lhs_ty.intInfo(zcu);
28662868 if (int_info.bits <= 64) {
28672869 // Only say yes if the operation is
28682870 // commutative, i.e. we can swap both of the
......@@ -2931,10 +2933,10 @@ fn binOp(
29312933 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);
29322934
29332935 // Truncate if necessary
2934 switch (lhs_ty.zigTypeTag(mod)) {
2936 switch (lhs_ty.zigTypeTag(zcu)) {
29352937 .Vector => return self.fail("TODO binary operations on vectors", .{}),
29362938 .Int => {
2937 const int_info = lhs_ty.intInfo(mod);
2939 const int_info = lhs_ty.intInfo(zcu);
29382940 if (int_info.bits <= 64) {
29392941 const result_reg = result.register;
29402942 try self.truncRegister(result_reg, result_reg, int_info.signedness, int_info.bits);
......@@ -2948,11 +2950,11 @@ fn binOp(
29482950 },
29492951
29502952 .div_trunc => {
2951 switch (lhs_ty.zigTypeTag(mod)) {
2953 switch (lhs_ty.zigTypeTag(zcu)) {
29522954 .Vector => return self.fail("TODO binary operations on vectors", .{}),
29532955 .Int => {
2954 assert(lhs_ty.eql(rhs_ty, mod));
2955 const int_info = lhs_ty.intInfo(mod);
2956 assert(lhs_ty.eql(rhs_ty, zcu));
2957 const int_info = lhs_ty.intInfo(zcu);
29562958 if (int_info.bits <= 64) {
29572959 const rhs_immediate_ok = switch (tag) {
29582960 .div_trunc => rhs == .immediate and rhs.immediate <= std.math.maxInt(u12),
......@@ -2981,14 +2983,14 @@ fn binOp(
29812983 },
29822984
29832985 .ptr_add => {
2984 switch (lhs_ty.zigTypeTag(mod)) {
2986 switch (lhs_ty.zigTypeTag(zcu)) {
29852987 .Pointer => {
29862988 const ptr_ty = lhs_ty;
2987 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
2988 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
2989 else => ptr_ty.childType(mod),
2989 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
2990 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
2991 else => ptr_ty.childType(zcu),
29902992 };
2991 const elem_size = elem_ty.abiSize(pt);
2993 const elem_size = elem_ty.abiSize(zcu);
29922994
29932995 if (elem_size == 1) {
29942996 const base_tag: Mir.Inst.Tag = switch (tag) {
......@@ -3013,7 +3015,7 @@ fn binOp(
30133015 .bool_and,
30143016 .bool_or,
30153017 => {
3016 switch (lhs_ty.zigTypeTag(mod)) {
3018 switch (lhs_ty.zigTypeTag(zcu)) {
30173019 .Bool => {
30183020 assert(lhs != .immediate); // should have been handled by Sema
30193021 assert(rhs != .immediate); // should have been handled by Sema
......@@ -3043,10 +3045,10 @@ fn binOp(
30433045 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);
30443046
30453047 // Truncate if necessary
3046 switch (lhs_ty.zigTypeTag(mod)) {
3048 switch (lhs_ty.zigTypeTag(zcu)) {
30473049 .Vector => return self.fail("TODO binary operations on vectors", .{}),
30483050 .Int => {
3049 const int_info = lhs_ty.intInfo(mod);
3051 const int_info = lhs_ty.intInfo(zcu);
30503052 if (int_info.bits <= 64) {
30513053 // 32 and 64 bit operands doesn't need truncating
30523054 if (int_info.bits == 32 or int_info.bits == 64) return result;
......@@ -3065,10 +3067,10 @@ fn binOp(
30653067 .shl_exact,
30663068 .shr_exact,
30673069 => {
3068 switch (lhs_ty.zigTypeTag(mod)) {
3070 switch (lhs_ty.zigTypeTag(zcu)) {
30693071 .Vector => return self.fail("TODO binary operations on vectors", .{}),
30703072 .Int => {
3071 const int_info = lhs_ty.intInfo(mod);
3073 const int_info = lhs_ty.intInfo(zcu);
30723074 if (int_info.bits <= 64) {
30733075 const rhs_immediate_ok = rhs == .immediate;
30743076
......@@ -3388,8 +3390,8 @@ fn binOpRegister(
33883390fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
33893391 const block_data = self.blocks.getPtr(block).?;
33903392
3391 const pt = self.pt;
3392 if (self.typeOf(operand).hasRuntimeBits(pt)) {
3393 const zcu = self.pt.zcu;
3394 if (self.typeOf(operand).hasRuntimeBits(zcu)) {
33933395 const operand_mcv = try self.resolveInst(operand);
33943396 const block_mcv = block_data.mcv;
33953397 if (block_mcv == .none) {
......@@ -3509,17 +3511,17 @@ fn ensureProcessDeathCapacity(self: *Self, additional_count: usize) !void {
35093511/// Given an error union, returns the payload
35103512fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) !MCValue {
35113513 const pt = self.pt;
3512 const mod = pt.zcu;
3513 const err_ty = error_union_ty.errorUnionSet(mod);
3514 const payload_ty = error_union_ty.errorUnionPayload(mod);
3515 if (err_ty.errorSetIsEmpty(mod)) {
3514 const zcu = pt.zcu;
3515 const err_ty = error_union_ty.errorUnionSet(zcu);
3516 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3517 if (err_ty.errorSetIsEmpty(zcu)) {
35163518 return error_union_mcv;
35173519 }
3518 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3520 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
35193521 return MCValue.none;
35203522 }
35213523
3522 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt)));
3524 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu)));
35233525 switch (error_union_mcv) {
35243526 .register => return self.fail("TODO errUnionPayload for registers", .{}),
35253527 .stack_offset => |off| {
......@@ -3731,6 +3733,7 @@ fn genLoadASI(self: *Self, value_reg: Register, addr_reg: Register, off_reg: Reg
37313733
37323734fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {
37333735 const pt = self.pt;
3736 const zcu = pt.zcu;
37343737 switch (mcv) {
37353738 .dead => unreachable,
37363739 .unreach, .none => return, // Nothing to do.
......@@ -3929,21 +3932,21 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
39293932 // The value is in memory at a hard-coded address.
39303933 // If the type is a pointer, it means the pointer address is at this memory location.
39313934 try self.genSetReg(ty, reg, .{ .immediate = addr });
3932 try self.genLoad(reg, reg, i13, 0, ty.abiSize(pt));
3935 try self.genLoad(reg, reg, i13, 0, ty.abiSize(zcu));
39333936 },
39343937 .stack_offset => |off| {
39353938 const real_offset = realStackOffset(off);
39363939 const simm13 = math.cast(i13, real_offset) orelse
39373940 return self.fail("TODO larger stack offsets: {}", .{real_offset});
3938 try self.genLoad(reg, .sp, i13, simm13, ty.abiSize(pt));
3941 try self.genLoad(reg, .sp, i13, simm13, ty.abiSize(zcu));
39393942 },
39403943 }
39413944}
39423945
39433946fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
39443947 const pt = self.pt;
3945 const mod = pt.zcu;
3946 const abi_size = ty.abiSize(pt);
3948 const zcu = pt.zcu;
3949 const abi_size = ty.abiSize(zcu);
39473950 switch (mcv) {
39483951 .dead => unreachable,
39493952 .unreach, .none => return, // Nothing to do.
......@@ -3951,7 +3954,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
39513954 if (!self.wantSafety())
39523955 return; // The already existing value will do just fine.
39533956 // TODO Upgrade this to a memset call when we have that available.
3954 switch (ty.abiSize(pt)) {
3957 switch (ty.abiSize(zcu)) {
39553958 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),
39563959 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),
39573960 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),
......@@ -3977,11 +3980,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
39773980 const reg_lock = self.register_manager.lockReg(rwo.reg);
39783981 defer if (reg_lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
39793982
3980 const wrapped_ty = ty.structFieldType(0, mod);
3983 const wrapped_ty = ty.structFieldType(0, zcu);
39813984 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
39823985
3983 const overflow_bit_ty = ty.structFieldType(1, mod);
3984 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, pt)));
3986 const overflow_bit_ty = ty.structFieldType(1, zcu);
3987 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, zcu)));
39853988 const cond_reg = try self.register_manager.allocReg(null, gp);
39863989
39873990 // TODO handle floating point CCRs
......@@ -4154,14 +4157,14 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue {
41544157
41554158fn isErr(self: *Self, ty: Type, operand: MCValue) !MCValue {
41564159 const pt = self.pt;
4157 const mod = pt.zcu;
4158 const error_type = ty.errorUnionSet(mod);
4159 const payload_type = ty.errorUnionPayload(mod);
4160 const zcu = pt.zcu;
4161 const error_type = ty.errorUnionSet(zcu);
4162 const payload_type = ty.errorUnionPayload(zcu);
41604163
4161 if (!error_type.hasRuntimeBits(pt)) {
4164 if (!error_type.hasRuntimeBits(zcu)) {
41624165 return MCValue{ .immediate = 0 }; // always false
4163 } else if (!payload_type.hasRuntimeBits(pt)) {
4164 if (error_type.abiSize(pt) <= 8) {
4166 } else if (!payload_type.hasRuntimeBits(zcu)) {
4167 if (error_type.abiSize(zcu) <= 8) {
41654168 const reg_mcv: MCValue = switch (operand) {
41664169 .register => operand,
41674170 else => .{ .register = try self.copyToTmpRegister(error_type, operand) },
......@@ -4253,9 +4256,9 @@ fn jump(self: *Self, inst: Mir.Inst.Index) !void {
42534256
42544257fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
42554258 const pt = self.pt;
4256 const mod = pt.zcu;
4257 const elem_ty = ptr_ty.childType(mod);
4258 const elem_size = elem_ty.abiSize(pt);
4259 const zcu = pt.zcu;
4260 const elem_ty = ptr_ty.childType(zcu);
4261 const elem_size = elem_ty.abiSize(zcu);
42594262
42604263 switch (ptr) {
42614264 .none => unreachable,
......@@ -4446,9 +4449,9 @@ fn realStackOffset(off: u32) u32 {
44464449/// Caller must call `CallMCValues.deinit`.
44474450fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) !CallMCValues {
44484451 const pt = self.pt;
4449 const mod = pt.zcu;
4450 const ip = &mod.intern_pool;
4451 const fn_info = mod.typeToFunc(fn_ty).?;
4452 const zcu = pt.zcu;
4453 const ip = &zcu.intern_pool;
4454 const fn_info = zcu.typeToFunc(fn_ty).?;
44524455 const cc = fn_info.cc;
44534456 var result: CallMCValues = .{
44544457 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),
......@@ -4459,7 +4462,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
44594462 };
44604463 errdefer self.gpa.free(result.args);
44614464
4462 const ret_ty = fn_ty.fnReturnType(mod);
4465 const ret_ty = fn_ty.fnReturnType(zcu);
44634466
44644467 switch (cc) {
44654468 .Naked => {
......@@ -4487,7 +4490,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
44874490 };
44884491
44894492 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
4490 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(pt)));
4493 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(zcu)));
44914494 if (param_size <= 8) {
44924495 if (next_register < argument_registers.len) {
44934496 result_arg.* = .{ .register = argument_registers[next_register] };
......@@ -4514,12 +4517,12 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
45144517 result.stack_byte_count = next_stack_offset;
45154518 result.stack_align = .@"16";
45164519
4517 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
4520 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
45184521 result.return_value = .{ .unreach = {} };
4519 } else if (!ret_ty.hasRuntimeBits(pt)) {
4522 } else if (!ret_ty.hasRuntimeBits(zcu)) {
45204523 result.return_value = .{ .none = {} };
45214524 } else {
4522 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));
4525 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
45234526 // The callee puts the return values in %i0-%i3, which becomes %o0-%o3 inside the caller.
45244527 if (ret_ty_size <= 8) {
45254528 result.return_value = switch (role) {
......@@ -4542,7 +4545,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45424545 const ty = self.typeOf(ref);
45434546
45444547 // If the type has no codegen bits, no need to store it.
4545 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
4548 if (!ty.hasRuntimeBitsIgnoreComptime(pt.zcu)) return .none;
45464549
45474550 if (ref.toIndex()) |inst| {
45484551 return self.getResolvedInstValue(inst);
......@@ -4656,7 +4659,7 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
46564659
46574660fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
46584661 const pt = self.pt;
4659 const abi_size = value_ty.abiSize(pt);
4662 const abi_size = value_ty.abiSize(pt.zcu);
46604663
46614664 switch (ptr) {
46624665 .none => unreachable,
......@@ -4698,11 +4701,11 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
46984701fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
46994702 return if (self.liveness.isUnused(inst)) .dead else result: {
47004703 const pt = self.pt;
4701 const mod = pt.zcu;
4704 const zcu = pt.zcu;
47024705 const mcv = try self.resolveInst(operand);
47034706 const ptr_ty = self.typeOf(operand);
4704 const struct_ty = ptr_ty.childType(mod);
4705 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));
4707 const struct_ty = ptr_ty.childType(zcu);
4708 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
47064709 switch (mcv) {
47074710 .ptr_stack_offset => |off| {
47084711 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
src/arch/wasm/CodeGen.zig+542-539
......@@ -788,10 +788,10 @@ fn resolveInst(func: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
788788 assert(!gop.found_existing);
789789
790790 const pt = func.pt;
791 const mod = pt.zcu;
791 const zcu = pt.zcu;
792792 const val = (try func.air.value(ref, pt)).?;
793793 const ty = func.typeOf(ref);
794 if (!ty.hasRuntimeBitsIgnoreComptime(pt) and !ty.isInt(mod) and !ty.isError(mod)) {
794 if (!ty.hasRuntimeBitsIgnoreComptime(zcu) and !ty.isInt(zcu) and !ty.isError(zcu)) {
795795 gop.value_ptr.* = .none;
796796 return gop.value_ptr.*;
797797 }
......@@ -1001,9 +1001,9 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32
10011001
10021002/// Using a given `Type`, returns the corresponding valtype for .auto callconv
10031003fn typeToValtype(ty: Type, pt: Zcu.PerThread, target: std.Target) wasm.Valtype {
1004 const mod = pt.zcu;
1005 const ip = &mod.intern_pool;
1006 return switch (ty.zigTypeTag(mod)) {
1004 const zcu = pt.zcu;
1005 const ip = &zcu.intern_pool;
1006 return switch (ty.zigTypeTag(zcu)) {
10071007 .Float => switch (ty.floatBits(target)) {
10081008 16 => .i32, // stored/loaded as u16
10091009 32 => .f32,
......@@ -1011,26 +1011,26 @@ fn typeToValtype(ty: Type, pt: Zcu.PerThread, target: std.Target) wasm.Valtype {
10111011 80, 128 => .i32,
10121012 else => unreachable,
10131013 },
1014 .Int, .Enum => switch (ty.intInfo(pt.zcu).bits) {
1014 .Int, .Enum => switch (ty.intInfo(zcu).bits) {
10151015 0...32 => .i32,
10161016 33...64 => .i64,
10171017 else => .i32,
10181018 },
10191019 .Struct => blk: {
1020 if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| {
1020 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
10211021 const backing_int_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
10221022 break :blk typeToValtype(backing_int_ty, pt, target);
10231023 } else {
10241024 break :blk .i32;
10251025 }
10261026 },
1027 .Vector => switch (determineSimdStoreStrategy(ty, pt, target)) {
1027 .Vector => switch (determineSimdStoreStrategy(ty, zcu, target)) {
10281028 .direct => .v128,
10291029 .unrolled => .i32,
10301030 },
1031 .Union => switch (ty.containerLayout(pt.zcu)) {
1031 .Union => switch (ty.containerLayout(zcu)) {
10321032 .@"packed" => blk: {
1033 const int_ty = pt.intType(.unsigned, @as(u16, @intCast(ty.bitSize(pt)))) catch @panic("out of memory");
1033 const int_ty = pt.intType(.unsigned, @as(u16, @intCast(ty.bitSize(zcu)))) catch @panic("out of memory");
10341034 break :blk typeToValtype(int_ty, pt, target);
10351035 },
10361036 else => .i32,
......@@ -1148,7 +1148,7 @@ fn genFunctype(
11481148 pt: Zcu.PerThread,
11491149 target: std.Target,
11501150) !wasm.Type {
1151 const mod = pt.zcu;
1151 const zcu = pt.zcu;
11521152 var temp_params = std.ArrayList(wasm.Valtype).init(gpa);
11531153 defer temp_params.deinit();
11541154 var returns = std.ArrayList(wasm.Valtype).init(gpa);
......@@ -1156,30 +1156,30 @@ fn genFunctype(
11561156
11571157 if (firstParamSRet(cc, return_type, pt, target)) {
11581158 try temp_params.append(.i32); // memory address is always a 32-bit handle
1159 } else if (return_type.hasRuntimeBitsIgnoreComptime(pt)) {
1159 } else if (return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
11601160 if (cc == .C) {
1161 const res_classes = abi.classifyType(return_type, pt);
1161 const res_classes = abi.classifyType(return_type, zcu);
11621162 assert(res_classes[0] == .direct and res_classes[1] == .none);
1163 const scalar_type = abi.scalarType(return_type, pt);
1163 const scalar_type = abi.scalarType(return_type, zcu);
11641164 try returns.append(typeToValtype(scalar_type, pt, target));
11651165 } else {
11661166 try returns.append(typeToValtype(return_type, pt, target));
11671167 }
1168 } else if (return_type.isError(mod)) {
1168 } else if (return_type.isError(zcu)) {
11691169 try returns.append(.i32);
11701170 }
11711171
11721172 // param types
11731173 for (params) |param_type_ip| {
11741174 const param_type = Type.fromInterned(param_type_ip);
1175 if (!param_type.hasRuntimeBitsIgnoreComptime(pt)) continue;
1175 if (!param_type.hasRuntimeBitsIgnoreComptime(zcu)) continue;
11761176
11771177 switch (cc) {
11781178 .C => {
1179 const param_classes = abi.classifyType(param_type, pt);
1179 const param_classes = abi.classifyType(param_type, zcu);
11801180 if (param_classes[1] == .none) {
11811181 if (param_classes[0] == .direct) {
1182 const scalar_type = abi.scalarType(param_type, pt);
1182 const scalar_type = abi.scalarType(param_type, zcu);
11831183 try temp_params.append(typeToValtype(scalar_type, pt, target));
11841184 } else {
11851185 try temp_params.append(typeToValtype(param_type, pt, target));
......@@ -1242,10 +1242,10 @@ pub fn generate(
12421242
12431243fn genFunc(func: *CodeGen) InnerError!void {
12441244 const pt = func.pt;
1245 const mod = pt.zcu;
1246 const ip = &mod.intern_pool;
1247 const fn_ty = mod.navValue(func.owner_nav).typeOf(mod);
1248 const fn_info = mod.typeToFunc(fn_ty).?;
1245 const zcu = pt.zcu;
1246 const ip = &zcu.intern_pool;
1247 const fn_ty = zcu.navValue(func.owner_nav).typeOf(zcu);
1248 const fn_info = zcu.typeToFunc(fn_ty).?;
12491249 var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), pt, func.target.*);
12501250 defer func_type.deinit(func.gpa);
12511251 _ = try func.bin_file.storeNavType(func.owner_nav, func_type);
......@@ -1273,7 +1273,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
12731273 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {
12741274 const inst: Air.Inst.Index = @enumFromInt(func.air.instructions.len - 1);
12751275 const last_inst_ty = func.typeOfIndex(inst);
1276 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(pt) or last_inst_ty.isNoReturn(mod)) {
1276 if (!last_inst_ty.hasRuntimeBitsIgnoreComptime(zcu) or last_inst_ty.isNoReturn(zcu)) {
12771277 try func.addTag(.@"unreachable");
12781278 }
12791279 }
......@@ -1356,9 +1356,9 @@ const CallWValues = struct {
13561356
13571357fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWValues {
13581358 const pt = func.pt;
1359 const mod = pt.zcu;
1360 const ip = &mod.intern_pool;
1361 const fn_info = mod.typeToFunc(fn_ty).?;
1359 const zcu = pt.zcu;
1360 const ip = &zcu.intern_pool;
1361 const fn_info = zcu.typeToFunc(fn_ty).?;
13621362 const cc = fn_info.cc;
13631363 var result: CallWValues = .{
13641364 .args = &.{},
......@@ -1381,7 +1381,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
13811381 switch (cc) {
13821382 .Unspecified => {
13831383 for (fn_info.param_types.get(ip)) |ty| {
1384 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(pt)) {
1384 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(zcu)) {
13851385 continue;
13861386 }
13871387
......@@ -1391,7 +1391,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
13911391 },
13921392 .C => {
13931393 for (fn_info.param_types.get(ip)) |ty| {
1394 const ty_classes = abi.classifyType(Type.fromInterned(ty), pt);
1394 const ty_classes = abi.classifyType(Type.fromInterned(ty), zcu);
13951395 for (ty_classes) |class| {
13961396 if (class == .none) continue;
13971397 try args.append(.{ .local = .{ .value = func.local_index, .references = 1 } });
......@@ -1409,7 +1409,7 @@ fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, pt: Zcu.
14091409 switch (cc) {
14101410 .Unspecified, .Inline => return isByRef(return_type, pt, target),
14111411 .C => {
1412 const ty_classes = abi.classifyType(return_type, pt);
1412 const ty_classes = abi.classifyType(return_type, pt.zcu);
14131413 if (ty_classes[0] == .indirect) return true;
14141414 if (ty_classes[0] == .direct and ty_classes[1] == .direct) return true;
14151415 return false;
......@@ -1426,16 +1426,16 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:
14261426 }
14271427
14281428 const pt = func.pt;
1429 const mod = pt.zcu;
1430 const ty_classes = abi.classifyType(ty, pt);
1429 const zcu = pt.zcu;
1430 const ty_classes = abi.classifyType(ty, zcu);
14311431 assert(ty_classes[0] != .none);
1432 switch (ty.zigTypeTag(mod)) {
1432 switch (ty.zigTypeTag(zcu)) {
14331433 .Struct, .Union => {
14341434 if (ty_classes[0] == .indirect) {
14351435 return func.lowerToStack(value);
14361436 }
14371437 assert(ty_classes[0] == .direct);
1438 const scalar_type = abi.scalarType(ty, pt);
1438 const scalar_type = abi.scalarType(ty, zcu);
14391439 switch (value) {
14401440 .memory,
14411441 .memory_offset,
......@@ -1450,7 +1450,7 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:
14501450 return func.lowerToStack(value);
14511451 }
14521452 assert(ty_classes[0] == .direct and ty_classes[1] == .direct);
1453 assert(ty.abiSize(pt) == 16);
1453 assert(ty.abiSize(zcu) == 16);
14541454 // in this case we have an integer or float that must be lowered as 2 i64's.
14551455 try func.emitWValue(value);
14561456 try func.addMemArg(.i64_load, .{ .offset = value.offset(), .alignment = 8 });
......@@ -1517,18 +1517,18 @@ fn restoreStackPointer(func: *CodeGen) !void {
15171517///
15181518/// Asserts Type has codegenbits
15191519fn allocStack(func: *CodeGen, ty: Type) !WValue {
1520 const pt = func.pt;
1521 assert(ty.hasRuntimeBitsIgnoreComptime(pt));
1520 const zcu = func.pt.zcu;
1521 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
15221522 if (func.initial_stack_value == .none) {
15231523 try func.initializeStack();
15241524 }
15251525
1526 const abi_size = std.math.cast(u32, ty.abiSize(pt)) orelse {
1526 const abi_size = std.math.cast(u32, ty.abiSize(zcu)) orelse {
15271527 return func.fail("Type {} with ABI size of {d} exceeds stack frame size", .{
1528 ty.fmt(pt), ty.abiSize(pt),
1528 ty.fmt(func.pt), ty.abiSize(zcu),
15291529 });
15301530 };
1531 const abi_align = ty.abiAlignment(pt);
1531 const abi_align = ty.abiAlignment(zcu);
15321532
15331533 func.stack_alignment = func.stack_alignment.max(abi_align);
15341534
......@@ -1544,22 +1544,22 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue {
15441544/// if it is set, to ensure the stack alignment will be set correctly.
15451545fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue {
15461546 const pt = func.pt;
1547 const mod = pt.zcu;
1547 const zcu = pt.zcu;
15481548 const ptr_ty = func.typeOfIndex(inst);
1549 const pointee_ty = ptr_ty.childType(mod);
1549 const pointee_ty = ptr_ty.childType(zcu);
15501550
15511551 if (func.initial_stack_value == .none) {
15521552 try func.initializeStack();
15531553 }
15541554
1555 if (!pointee_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1555 if (!pointee_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
15561556 return func.allocStack(Type.usize); // create a value containing just the stack pointer.
15571557 }
15581558
1559 const abi_alignment = ptr_ty.ptrAlignment(pt);
1560 const abi_size = std.math.cast(u32, pointee_ty.abiSize(pt)) orelse {
1559 const abi_alignment = ptr_ty.ptrAlignment(zcu);
1560 const abi_size = std.math.cast(u32, pointee_ty.abiSize(zcu)) orelse {
15611561 return func.fail("Type {} with ABI size of {d} exceeds stack frame size", .{
1562 pointee_ty.fmt(pt), pointee_ty.abiSize(pt),
1562 pointee_ty.fmt(pt), pointee_ty.abiSize(zcu),
15631563 });
15641564 };
15651565 func.stack_alignment = func.stack_alignment.max(abi_alignment);
......@@ -1716,9 +1716,9 @@ fn arch(func: *const CodeGen) std.Target.Cpu.Arch {
17161716/// For a given `Type`, will return true when the type will be passed
17171717/// by reference, rather than by value
17181718fn isByRef(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
1719 const mod = pt.zcu;
1720 const ip = &mod.intern_pool;
1721 switch (ty.zigTypeTag(mod)) {
1719 const zcu = pt.zcu;
1720 const ip = &zcu.intern_pool;
1721 switch (ty.zigTypeTag(zcu)) {
17221722 .Type,
17231723 .ComptimeInt,
17241724 .ComptimeFloat,
......@@ -1738,41 +1738,41 @@ fn isByRef(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
17381738
17391739 .Array,
17401740 .Frame,
1741 => return ty.hasRuntimeBitsIgnoreComptime(pt),
1741 => return ty.hasRuntimeBitsIgnoreComptime(zcu),
17421742 .Union => {
1743 if (mod.typeToUnion(ty)) |union_obj| {
1743 if (zcu.typeToUnion(ty)) |union_obj| {
17441744 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1745 return ty.abiSize(pt) > 8;
1745 return ty.abiSize(zcu) > 8;
17461746 }
17471747 }
1748 return ty.hasRuntimeBitsIgnoreComptime(pt);
1748 return ty.hasRuntimeBitsIgnoreComptime(zcu);
17491749 },
17501750 .Struct => {
1751 if (mod.typeToPackedStruct(ty)) |packed_struct| {
1751 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
17521752 return isByRef(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt, target);
17531753 }
1754 return ty.hasRuntimeBitsIgnoreComptime(pt);
1754 return ty.hasRuntimeBitsIgnoreComptime(zcu);
17551755 },
1756 .Vector => return determineSimdStoreStrategy(ty, pt, target) == .unrolled,
1757 .Int => return ty.intInfo(mod).bits > 64,
1758 .Enum => return ty.intInfo(mod).bits > 64,
1756 .Vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,
1757 .Int => return ty.intInfo(zcu).bits > 64,
1758 .Enum => return ty.intInfo(zcu).bits > 64,
17591759 .Float => return ty.floatBits(target) > 64,
17601760 .ErrorUnion => {
1761 const pl_ty = ty.errorUnionPayload(mod);
1762 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1761 const pl_ty = ty.errorUnionPayload(zcu);
1762 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
17631763 return false;
17641764 }
17651765 return true;
17661766 },
17671767 .Optional => {
1768 if (ty.isPtrLikeOptional(mod)) return false;
1769 const pl_type = ty.optionalChild(mod);
1770 if (pl_type.zigTypeTag(mod) == .ErrorSet) return false;
1771 return pl_type.hasRuntimeBitsIgnoreComptime(pt);
1768 if (ty.isPtrLikeOptional(zcu)) return false;
1769 const pl_type = ty.optionalChild(zcu);
1770 if (pl_type.zigTypeTag(zcu) == .ErrorSet) return false;
1771 return pl_type.hasRuntimeBitsIgnoreComptime(zcu);
17721772 },
17731773 .Pointer => {
17741774 // Slices act like struct and will be passed by reference
1775 if (ty.isSlice(mod)) return true;
1775 if (ty.isSlice(zcu)) return true;
17761776 return false;
17771777 },
17781778 }
......@@ -1787,9 +1787,9 @@ const SimdStoreStrategy = enum {
17871787/// This means when a given type is 128 bits and either the simd128 or relaxed-simd
17881788/// features are enabled, the function will return `.direct`. This would allow to store
17891789/// it using a instruction, rather than an unrolled version.
1790fn determineSimdStoreStrategy(ty: Type, pt: Zcu.PerThread, target: std.Target) SimdStoreStrategy {
1791 std.debug.assert(ty.zigTypeTag(pt.zcu) == .Vector);
1792 if (ty.bitSize(pt) != 128) return .unrolled;
1790fn determineSimdStoreStrategy(ty: Type, zcu: *Zcu, target: std.Target) SimdStoreStrategy {
1791 std.debug.assert(ty.zigTypeTag(zcu) == .Vector);
1792 if (ty.bitSize(zcu) != 128) return .unrolled;
17931793 const hasFeature = std.Target.wasm.featureSetHas;
17941794 const features = target.cpu.features;
17951795 if (hasFeature(features, .relaxed_simd) or hasFeature(features, .simd128)) {
......@@ -2069,8 +2069,8 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20692069
20702070fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20712071 const pt = func.pt;
2072 const mod = pt.zcu;
2073 const ip = &mod.intern_pool;
2072 const zcu = pt.zcu;
2073 const ip = &zcu.intern_pool;
20742074
20752075 for (body) |inst| {
20762076 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst, ip)) {
......@@ -2091,37 +2091,37 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20912091
20922092fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20932093 const pt = func.pt;
2094 const mod = pt.zcu;
2094 const zcu = pt.zcu;
20952095 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
20962096 const operand = try func.resolveInst(un_op);
2097 const fn_info = mod.typeToFunc(mod.navValue(func.owner_nav).typeOf(mod)).?;
2097 const fn_info = zcu.typeToFunc(zcu.navValue(func.owner_nav).typeOf(zcu)).?;
20982098 const ret_ty = Type.fromInterned(fn_info.return_type);
20992099
21002100 // result must be stored in the stack and we return a pointer
21012101 // to the stack instead
21022102 if (func.return_value != .none) {
21032103 try func.store(func.return_value, operand, ret_ty, 0);
2104 } else if (fn_info.cc == .C and ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2105 switch (ret_ty.zigTypeTag(mod)) {
2104 } else if (fn_info.cc == .C and ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2105 switch (ret_ty.zigTypeTag(zcu)) {
21062106 // Aggregate types can be lowered as a singular value
21072107 .Struct, .Union => {
2108 const scalar_type = abi.scalarType(ret_ty, pt);
2108 const scalar_type = abi.scalarType(ret_ty, zcu);
21092109 try func.emitWValue(operand);
21102110 const opcode = buildOpcode(.{
21112111 .op = .load,
2112 .width = @as(u8, @intCast(scalar_type.abiSize(pt) * 8)),
2113 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,
2112 .width = @as(u8, @intCast(scalar_type.abiSize(zcu) * 8)),
2113 .signedness = if (scalar_type.isSignedInt(zcu)) .signed else .unsigned,
21142114 .valtype1 = typeToValtype(scalar_type, pt, func.target.*),
21152115 });
21162116 try func.addMemArg(Mir.Inst.Tag.fromOpcode(opcode), .{
21172117 .offset = operand.offset(),
2118 .alignment = @intCast(scalar_type.abiAlignment(pt).toByteUnits().?),
2118 .alignment = @intCast(scalar_type.abiAlignment(zcu).toByteUnits().?),
21192119 });
21202120 },
21212121 else => try func.emitWValue(operand),
21222122 }
21232123 } else {
2124 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt) and ret_ty.isError(mod)) {
2124 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and ret_ty.isError(zcu)) {
21252125 try func.addImm32(0);
21262126 } else {
21272127 try func.emitWValue(operand);
......@@ -2135,15 +2135,15 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21352135
21362136fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21372137 const pt = func.pt;
2138 const mod = pt.zcu;
2139 const child_type = func.typeOfIndex(inst).childType(mod);
2138 const zcu = pt.zcu;
2139 const child_type = func.typeOfIndex(inst).childType(zcu);
21402140
21412141 const result = result: {
2142 if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
2142 if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
21432143 break :result try func.allocStack(Type.usize); // create pointer to void
21442144 }
21452145
2146 const fn_info = mod.typeToFunc(mod.navValue(func.owner_nav).typeOf(mod)).?;
2146 const fn_info = zcu.typeToFunc(zcu.navValue(func.owner_nav).typeOf(zcu)).?;
21472147 if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*)) {
21482148 break :result func.return_value;
21492149 }
......@@ -2156,14 +2156,14 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21562156
21572157fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21582158 const pt = func.pt;
2159 const mod = pt.zcu;
2159 const zcu = pt.zcu;
21602160 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
21612161 const operand = try func.resolveInst(un_op);
2162 const ret_ty = func.typeOf(un_op).childType(mod);
2162 const ret_ty = func.typeOf(un_op).childType(zcu);
21632163
2164 const fn_info = mod.typeToFunc(mod.navValue(func.owner_nav).typeOf(mod)).?;
2165 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2166 if (ret_ty.isError(mod)) {
2164 const fn_info = zcu.typeToFunc(zcu.navValue(func.owner_nav).typeOf(zcu)).?;
2165 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2166 if (ret_ty.isError(zcu)) {
21672167 try func.addImm32(0);
21682168 }
21692169 } else if (!firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*)) {
......@@ -2184,15 +2184,15 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21842184 const ty = func.typeOf(pl_op.operand);
21852185
21862186 const pt = func.pt;
2187 const mod = pt.zcu;
2188 const ip = &mod.intern_pool;
2189 const fn_ty = switch (ty.zigTypeTag(mod)) {
2187 const zcu = pt.zcu;
2188 const ip = &zcu.intern_pool;
2189 const fn_ty = switch (ty.zigTypeTag(zcu)) {
21902190 .Fn => ty,
2191 .Pointer => ty.childType(mod),
2191 .Pointer => ty.childType(zcu),
21922192 else => unreachable,
21932193 };
2194 const ret_ty = fn_ty.fnReturnType(mod);
2195 const fn_info = mod.typeToFunc(fn_ty).?;
2194 const ret_ty = fn_ty.fnReturnType(zcu);
2195 const fn_info = zcu.typeToFunc(fn_ty).?;
21962196 const first_param_sret = firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*);
21972197
21982198 const callee: ?InternPool.Nav.Index = blk: {
......@@ -2205,7 +2205,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22052205 },
22062206 .@"extern" => |@"extern"| {
22072207 const ext_nav = ip.getNav(@"extern".owner_nav);
2208 const ext_info = mod.typeToFunc(Type.fromInterned(@"extern".ty)).?;
2208 const ext_info = zcu.typeToFunc(Type.fromInterned(@"extern".ty)).?;
22092209 var func_type = try genFunctype(
22102210 func.gpa,
22112211 ext_info.cc,
......@@ -2248,9 +2248,9 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22482248 const arg_val = try func.resolveInst(arg);
22492249
22502250 const arg_ty = func.typeOf(arg);
2251 if (!arg_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2251 if (!arg_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
22522252
2253 try func.lowerArg(mod.typeToFunc(fn_ty).?.cc, arg_ty, arg_val);
2253 try func.lowerArg(zcu.typeToFunc(fn_ty).?.cc, arg_ty, arg_val);
22542254 }
22552255
22562256 if (callee) |direct| {
......@@ -2259,7 +2259,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22592259 } else {
22602260 // in this case we call a function pointer
22612261 // so load its value onto the stack
2262 std.debug.assert(ty.zigTypeTag(mod) == .Pointer);
2262 std.debug.assert(ty.zigTypeTag(zcu) == .Pointer);
22632263 const operand = try func.resolveInst(pl_op.operand);
22642264 try func.emitWValue(operand);
22652265
......@@ -2271,18 +2271,18 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22712271 }
22722272
22732273 const result_value = result_value: {
2274 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt) and !ret_ty.isError(mod)) {
2274 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and !ret_ty.isError(zcu)) {
22752275 break :result_value .none;
2276 } else if (ret_ty.isNoReturn(mod)) {
2276 } else if (ret_ty.isNoReturn(zcu)) {
22772277 try func.addTag(.@"unreachable");
22782278 break :result_value .none;
22792279 } else if (first_param_sret) {
22802280 break :result_value sret;
22812281 // TODO: Make this less fragile and optimize
2282 } else if (mod.typeToFunc(fn_ty).?.cc == .C and ret_ty.zigTypeTag(mod) == .Struct or ret_ty.zigTypeTag(mod) == .Union) {
2282 } else if (zcu.typeToFunc(fn_ty).?.cc == .C and ret_ty.zigTypeTag(zcu) == .Struct or ret_ty.zigTypeTag(zcu) == .Union) {
22832283 const result_local = try func.allocLocal(ret_ty);
22842284 try func.addLabel(.local_set, result_local.local.value);
2285 const scalar_type = abi.scalarType(ret_ty, pt);
2285 const scalar_type = abi.scalarType(ret_ty, zcu);
22862286 const result = try func.allocStack(scalar_type);
22872287 try func.store(result, result_local, scalar_type, 0);
22882288 break :result_value result;
......@@ -2306,7 +2306,7 @@ fn airAlloc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
23062306
23072307fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
23082308 const pt = func.pt;
2309 const mod = pt.zcu;
2309 const zcu = pt.zcu;
23102310 if (safety) {
23112311 // TODO if the value is undef, write 0xaa bytes to dest
23122312 } else {
......@@ -2317,8 +2317,8 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
23172317 const lhs = try func.resolveInst(bin_op.lhs);
23182318 const rhs = try func.resolveInst(bin_op.rhs);
23192319 const ptr_ty = func.typeOf(bin_op.lhs);
2320 const ptr_info = ptr_ty.ptrInfo(mod);
2321 const ty = ptr_ty.childType(mod);
2320 const ptr_info = ptr_ty.ptrInfo(zcu);
2321 const ty = ptr_ty.childType(zcu);
23222322
23232323 if (ptr_info.packed_offset.host_size == 0) {
23242324 try func.store(lhs, rhs, ty, 0);
......@@ -2331,7 +2331,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
23312331 return func.fail("TODO: airStore for pointers to bitfields with backing type larger than 64bits", .{});
23322332 }
23332333
2334 var mask = @as(u64, @intCast((@as(u65, 1) << @as(u7, @intCast(ty.bitSize(pt)))) - 1));
2334 var mask = @as(u64, @intCast((@as(u65, 1) << @as(u7, @intCast(ty.bitSize(zcu)))) - 1));
23352335 mask <<= @as(u6, @intCast(ptr_info.packed_offset.bit_offset));
23362336 mask ^= ~@as(u64, 0);
23372337 const shift_val: WValue = if (ptr_info.packed_offset.host_size <= 4)
......@@ -2343,9 +2343,9 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
23432343 else
23442344 .{ .imm64 = mask };
23452345 const wrap_mask_val: WValue = if (ptr_info.packed_offset.host_size <= 4)
2346 .{ .imm32 = @truncate(~@as(u64, 0) >> @intCast(64 - ty.bitSize(pt))) }
2346 .{ .imm32 = @truncate(~@as(u64, 0) >> @intCast(64 - ty.bitSize(zcu))) }
23472347 else
2348 .{ .imm64 = ~@as(u64, 0) >> @intCast(64 - ty.bitSize(pt)) };
2348 .{ .imm64 = ~@as(u64, 0) >> @intCast(64 - ty.bitSize(zcu)) };
23492349
23502350 try func.emitWValue(lhs);
23512351 const loaded = try func.load(lhs, int_elem_ty, 0);
......@@ -2366,12 +2366,12 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
23662366fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerError!void {
23672367 assert(!(lhs != .stack and rhs == .stack));
23682368 const pt = func.pt;
2369 const mod = pt.zcu;
2370 const abi_size = ty.abiSize(pt);
2371 switch (ty.zigTypeTag(mod)) {
2369 const zcu = pt.zcu;
2370 const abi_size = ty.abiSize(zcu);
2371 switch (ty.zigTypeTag(zcu)) {
23722372 .ErrorUnion => {
2373 const pl_ty = ty.errorUnionPayload(mod);
2374 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2373 const pl_ty = ty.errorUnionPayload(zcu);
2374 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
23752375 return func.store(lhs, rhs, Type.anyerror, 0);
23762376 }
23772377
......@@ -2379,14 +2379,14 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
23792379 return func.memcpy(lhs, rhs, .{ .imm32 = len });
23802380 },
23812381 .Optional => {
2382 if (ty.isPtrLikeOptional(mod)) {
2382 if (ty.isPtrLikeOptional(zcu)) {
23832383 return func.store(lhs, rhs, Type.usize, 0);
23842384 }
2385 const pl_ty = ty.optionalChild(mod);
2386 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2385 const pl_ty = ty.optionalChild(zcu);
2386 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
23872387 return func.store(lhs, rhs, Type.u8, 0);
23882388 }
2389 if (pl_ty.zigTypeTag(mod) == .ErrorSet) {
2389 if (pl_ty.zigTypeTag(zcu) == .ErrorSet) {
23902390 return func.store(lhs, rhs, Type.anyerror, 0);
23912391 }
23922392
......@@ -2397,7 +2397,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
23972397 const len = @as(u32, @intCast(abi_size));
23982398 return func.memcpy(lhs, rhs, .{ .imm32 = len });
23992399 },
2400 .Vector => switch (determineSimdStoreStrategy(ty, pt, func.target.*)) {
2400 .Vector => switch (determineSimdStoreStrategy(ty, zcu, func.target.*)) {
24012401 .unrolled => {
24022402 const len: u32 = @intCast(abi_size);
24032403 return func.memcpy(lhs, rhs, .{ .imm32 = len });
......@@ -2411,13 +2411,13 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
24112411 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
24122412 std.wasm.simdOpcode(.v128_store),
24132413 offset + lhs.offset(),
2414 @intCast(ty.abiAlignment(pt).toByteUnits() orelse 0),
2414 @intCast(ty.abiAlignment(zcu).toByteUnits() orelse 0),
24152415 });
24162416 return func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
24172417 },
24182418 },
24192419 .Pointer => {
2420 if (ty.isSlice(mod)) {
2420 if (ty.isSlice(zcu)) {
24212421 // store pointer first
24222422 // lower it to the stack so we do not have to store rhs into a local first
24232423 try func.emitWValue(lhs);
......@@ -2441,7 +2441,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
24412441 try func.store(.stack, msb, Type.u64, 8 + lhs.offset());
24422442 return;
24432443 } else if (abi_size > 16) {
2444 try func.memcpy(lhs, rhs, .{ .imm32 = @as(u32, @intCast(ty.abiSize(pt))) });
2444 try func.memcpy(lhs, rhs, .{ .imm32 = @as(u32, @intCast(ty.abiSize(zcu))) });
24452445 },
24462446 else => if (abi_size > 8) {
24472447 return func.fail("TODO: `store` for type `{}` with abisize `{d}`", .{
......@@ -2467,21 +2467,21 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
24672467 Mir.Inst.Tag.fromOpcode(opcode),
24682468 .{
24692469 .offset = offset + lhs.offset(),
2470 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),
2470 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
24712471 },
24722472 );
24732473}
24742474
24752475fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24762476 const pt = func.pt;
2477 const mod = pt.zcu;
2477 const zcu = pt.zcu;
24782478 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
24792479 const operand = try func.resolveInst(ty_op.operand);
24802480 const ty = ty_op.ty.toType();
24812481 const ptr_ty = func.typeOf(ty_op.operand);
2482 const ptr_info = ptr_ty.ptrInfo(mod);
2482 const ptr_info = ptr_ty.ptrInfo(zcu);
24832483
2484 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) return func.finishAir(inst, .none, &.{ty_op.operand});
2484 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return func.finishAir(inst, .none, &.{ty_op.operand});
24852485
24862486 const result = result: {
24872487 if (isByRef(ty, pt, func.target.*)) {
......@@ -2515,36 +2515,36 @@ fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25152515/// NOTE: Leaves the value on the stack.
25162516fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValue {
25172517 const pt = func.pt;
2518 const mod = pt.zcu;
2518 const zcu = pt.zcu;
25192519 // load local's value from memory by its stack position
25202520 try func.emitWValue(operand);
25212521
2522 if (ty.zigTypeTag(mod) == .Vector) {
2522 if (ty.zigTypeTag(zcu) == .Vector) {
25232523 // TODO: Add helper functions for simd opcodes
25242524 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
25252525 // stores as := opcode, offset, alignment (opcode::memarg)
25262526 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
25272527 std.wasm.simdOpcode(.v128_load),
25282528 offset + operand.offset(),
2529 @intCast(ty.abiAlignment(pt).toByteUnits().?),
2529 @intCast(ty.abiAlignment(zcu).toByteUnits().?),
25302530 });
25312531 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
25322532 return .stack;
25332533 }
25342534
2535 const abi_size: u8 = @intCast(ty.abiSize(pt));
2535 const abi_size: u8 = @intCast(ty.abiSize(zcu));
25362536 const opcode = buildOpcode(.{
25372537 .valtype1 = typeToValtype(ty, pt, func.target.*),
25382538 .width = abi_size * 8,
25392539 .op = .load,
2540 .signedness = if (ty.isSignedInt(mod)) .signed else .unsigned,
2540 .signedness = if (ty.isSignedInt(zcu)) .signed else .unsigned,
25412541 });
25422542
25432543 try func.addMemArg(
25442544 Mir.Inst.Tag.fromOpcode(opcode),
25452545 .{
25462546 .offset = offset + operand.offset(),
2547 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),
2547 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
25482548 },
25492549 );
25502550
......@@ -2553,13 +2553,13 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
25532553
25542554fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25552555 const pt = func.pt;
2556 const mod = pt.zcu;
2556 const zcu = pt.zcu;
25572557 const arg_index = func.arg_index;
25582558 const arg = func.args[arg_index];
2559 const cc = mod.typeToFunc(mod.navValue(func.owner_nav).typeOf(mod)).?.cc;
2559 const cc = zcu.typeToFunc(zcu.navValue(func.owner_nav).typeOf(zcu)).?.cc;
25602560 const arg_ty = func.typeOfIndex(inst);
25612561 if (cc == .C) {
2562 const arg_classes = abi.classifyType(arg_ty, pt);
2562 const arg_classes = abi.classifyType(arg_ty, zcu);
25632563 for (arg_classes) |class| {
25642564 if (class != .none) {
25652565 func.arg_index += 1;
......@@ -2569,7 +2569,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
25692569 // When we have an argument that's passed using more than a single parameter,
25702570 // we combine them into a single stack value
25712571 if (arg_classes[0] == .direct and arg_classes[1] == .direct) {
2572 if (arg_ty.zigTypeTag(mod) != .Int and arg_ty.zigTypeTag(mod) != .Float) {
2572 if (arg_ty.zigTypeTag(zcu) != .Int and arg_ty.zigTypeTag(zcu) != .Float) {
25732573 return func.fail(
25742574 "TODO: Implement C-ABI argument for type '{}'",
25752575 .{arg_ty.fmt(pt)},
......@@ -2602,6 +2602,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
26022602
26032603fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
26042604 const pt = func.pt;
2605 const zcu = pt.zcu;
26052606 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
26062607 const lhs = try func.resolveInst(bin_op.lhs);
26072608 const rhs = try func.resolveInst(bin_op.rhs);
......@@ -2615,10 +2616,10 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
26152616 // For big integers we can ignore this as we will call into compiler-rt which handles this.
26162617 const result = switch (op) {
26172618 .shr, .shl => result: {
2618 const lhs_wasm_bits = toWasmBits(@intCast(lhs_ty.bitSize(pt))) orelse {
2619 const lhs_wasm_bits = toWasmBits(@intCast(lhs_ty.bitSize(zcu))) orelse {
26192620 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
26202621 };
2621 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(pt))).?;
2622 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(zcu))).?;
26222623 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128)
26232624 try (try func.intcast(rhs, rhs_ty, lhs_ty)).toLocal(func, lhs_ty)
26242625 else
......@@ -2635,7 +2636,7 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
26352636/// NOTE: THis leaves the value on top of the stack.
26362637fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {
26372638 const pt = func.pt;
2638 const mod = pt.zcu;
2639 const zcu = pt.zcu;
26392640 assert(!(lhs != .stack and rhs == .stack));
26402641
26412642 if (ty.isAnyFloat()) {
......@@ -2644,7 +2645,7 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!
26442645 }
26452646
26462647 if (isByRef(ty, pt, func.target.*)) {
2647 if (ty.zigTypeTag(mod) == .Int) {
2648 if (ty.zigTypeTag(zcu) == .Int) {
26482649 return func.binOpBigInt(lhs, rhs, ty, op);
26492650 } else {
26502651 return func.fail(
......@@ -2657,7 +2658,7 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!
26572658 const opcode: wasm.Opcode = buildOpcode(.{
26582659 .op = op,
26592660 .valtype1 = typeToValtype(ty, pt, func.target.*),
2660 .signedness = if (ty.isSignedInt(mod)) .signed else .unsigned,
2661 .signedness = if (ty.isSignedInt(zcu)) .signed else .unsigned,
26612662 });
26622663 try func.emitWValue(lhs);
26632664 try func.emitWValue(rhs);
......@@ -2669,8 +2670,8 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!
26692670
26702671fn binOpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {
26712672 const pt = func.pt;
2672 const mod = pt.zcu;
2673 const int_info = ty.intInfo(mod);
2673 const zcu = pt.zcu;
2674 const int_info = ty.intInfo(zcu);
26742675 if (int_info.bits > 128) {
26752676 return func.fail("TODO: Implement binary operation for big integers larger than 128 bits", .{});
26762677 }
......@@ -2812,17 +2813,17 @@ const FloatOp = enum {
28122813
28132814fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
28142815 const pt = func.pt;
2815 const mod = pt.zcu;
2816 const zcu = pt.zcu;
28162817 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
28172818 const operand = try func.resolveInst(ty_op.operand);
28182819 const ty = func.typeOf(ty_op.operand);
2819 const scalar_ty = ty.scalarType(mod);
2820 const scalar_ty = ty.scalarType(zcu);
28202821
2821 switch (scalar_ty.zigTypeTag(mod)) {
2822 .Int => if (ty.zigTypeTag(mod) == .Vector) {
2822 switch (scalar_ty.zigTypeTag(zcu)) {
2823 .Int => if (ty.zigTypeTag(zcu) == .Vector) {
28232824 return func.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
28242825 } else {
2825 const int_bits = ty.intInfo(mod).bits;
2826 const int_bits = ty.intInfo(zcu).bits;
28262827 const wasm_bits = toWasmBits(int_bits) orelse {
28272828 return func.fail("TODO: airAbs for signed integers larger than '{d}' bits", .{int_bits});
28282829 };
......@@ -2903,8 +2904,8 @@ fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError
29032904
29042905fn floatOp(func: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) InnerError!WValue {
29052906 const pt = func.pt;
2906 const mod = pt.zcu;
2907 if (ty.zigTypeTag(mod) == .Vector) {
2907 const zcu = pt.zcu;
2908 if (ty.zigTypeTag(zcu) == .Vector) {
29082909 return func.fail("TODO: Implement floatOps for vectors", .{});
29092910 }
29102911
......@@ -3010,7 +3011,7 @@ fn floatNeg(func: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {
30103011
30113012fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
30123013 const pt = func.pt;
3013 const mod = pt.zcu;
3014 const zcu = pt.zcu;
30143015 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
30153016
30163017 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -3018,7 +3019,7 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
30183019 const lhs_ty = func.typeOf(bin_op.lhs);
30193020 const rhs_ty = func.typeOf(bin_op.rhs);
30203021
3021 if (lhs_ty.zigTypeTag(mod) == .Vector or rhs_ty.zigTypeTag(mod) == .Vector) {
3022 if (lhs_ty.zigTypeTag(zcu) == .Vector or rhs_ty.zigTypeTag(zcu) == .Vector) {
30223023 return func.fail("TODO: Implement wrapping arithmetic for vectors", .{});
30233024 }
30243025
......@@ -3029,10 +3030,10 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
30293030 // For big integers we can ignore this as we will call into compiler-rt which handles this.
30303031 const result = switch (op) {
30313032 .shr, .shl => result: {
3032 const lhs_wasm_bits = toWasmBits(@intCast(lhs_ty.bitSize(pt))) orelse {
3033 const lhs_wasm_bits = toWasmBits(@intCast(lhs_ty.bitSize(zcu))) orelse {
30333034 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
30343035 };
3035 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(pt))).?;
3036 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(zcu))).?;
30363037 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128)
30373038 try (try func.intcast(rhs, rhs_ty, lhs_ty)).toLocal(func, lhs_ty)
30383039 else
......@@ -3058,9 +3059,9 @@ fn wrapBinOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerEr
30583059/// NOTE: When the Type is <= 64 bits, leaves the value on top of the stack, if wrapping was needed.
30593060fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
30603061 const pt = func.pt;
3061 const mod = pt.zcu;
3062 assert(ty.abiSize(pt) <= 16);
3063 const int_bits: u16 = @intCast(ty.bitSize(pt)); // TODO use ty.intInfo(mod).bits
3062 const zcu = pt.zcu;
3063 assert(ty.abiSize(zcu) <= 16);
3064 const int_bits: u16 = @intCast(ty.bitSize(zcu)); // TODO use ty.intInfo(zcu).bits
30643065 const wasm_bits = toWasmBits(int_bits) orelse {
30653066 return func.fail("TODO: Implement wrapOperand for bitsize '{d}'", .{int_bits});
30663067 };
......@@ -3070,7 +3071,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
30703071 switch (wasm_bits) {
30713072 32 => {
30723073 try func.emitWValue(operand);
3073 if (ty.isSignedInt(mod)) {
3074 if (ty.isSignedInt(zcu)) {
30743075 try func.addImm32(32 - int_bits);
30753076 try func.addTag(.i32_shl);
30763077 try func.addImm32(32 - int_bits);
......@@ -3083,7 +3084,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
30833084 },
30843085 64 => {
30853086 try func.emitWValue(operand);
3086 if (ty.isSignedInt(mod)) {
3087 if (ty.isSignedInt(zcu)) {
30873088 try func.addImm64(64 - int_bits);
30883089 try func.addTag(.i64_shl);
30893090 try func.addImm64(64 - int_bits);
......@@ -3104,7 +3105,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
31043105
31053106 try func.emitWValue(result);
31063107 _ = try func.load(operand, Type.u64, 8);
3107 if (ty.isSignedInt(mod)) {
3108 if (ty.isSignedInt(zcu)) {
31083109 try func.addImm64(128 - int_bits);
31093110 try func.addTag(.i64_shl);
31103111 try func.addImm64(128 - int_bits);
......@@ -3145,13 +3146,13 @@ fn lowerPtr(func: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerEr
31453146 };
31463147 },
31473148 .Struct => switch (base_ty.containerLayout(zcu)) {
3148 .auto => base_ty.structFieldOffset(@intCast(field.index), pt),
3149 .auto => base_ty.structFieldOffset(@intCast(field.index), zcu),
31493150 .@"extern", .@"packed" => unreachable,
31503151 },
31513152 .Union => switch (base_ty.containerLayout(zcu)) {
31523153 .auto => off: {
31533154 // Keep in sync with the `un` case of `generateSymbol`.
3154 const layout = base_ty.unionGetLayout(pt);
3155 const layout = base_ty.unionGetLayout(zcu);
31553156 if (layout.payload_size == 0) break :off 0;
31563157 if (layout.tag_size == 0) break :off 0;
31573158 if (layout.tag_align.compare(.gte, layout.payload_align)) {
......@@ -3178,15 +3179,15 @@ fn lowerUavRef(
31783179 offset: u32,
31793180) InnerError!WValue {
31803181 const pt = func.pt;
3181 const mod = pt.zcu;
3182 const ty = Type.fromInterned(mod.intern_pool.typeOf(uav.val));
3182 const zcu = pt.zcu;
3183 const ty = Type.fromInterned(zcu.intern_pool.typeOf(uav.val));
31833184
3184 const is_fn_body = ty.zigTypeTag(mod) == .Fn;
3185 if (!is_fn_body and !ty.hasRuntimeBitsIgnoreComptime(pt)) {
3185 const is_fn_body = ty.zigTypeTag(zcu) == .Fn;
3186 if (!is_fn_body and !ty.hasRuntimeBitsIgnoreComptime(zcu)) {
31863187 return .{ .imm32 = 0xaaaaaaaa };
31873188 }
31883189
3189 const decl_align = mod.intern_pool.indexToKey(uav.orig_ty).ptr_type.flags.alignment;
3190 const decl_align = zcu.intern_pool.indexToKey(uav.orig_ty).ptr_type.flags.alignment;
31903191 const res = try func.bin_file.lowerUav(pt, uav.val, decl_align, func.src_loc);
31913192 const target_sym_index = switch (res) {
31923193 .mcv => |mcv| mcv.load_symbol,
......@@ -3204,19 +3205,19 @@ fn lowerUavRef(
32043205
32053206fn lowerNavRef(func: *CodeGen, nav_index: InternPool.Nav.Index, offset: u32) InnerError!WValue {
32063207 const pt = func.pt;
3207 const mod = pt.zcu;
3208 const ip = &mod.intern_pool;
3208 const zcu = pt.zcu;
3209 const ip = &zcu.intern_pool;
32093210
32103211 // check if decl is an alias to a function, in which case we
32113212 // want to lower the actual decl, rather than the alias itself.
3212 const owner_nav = switch (ip.indexToKey(mod.navValue(nav_index).toIntern())) {
3213 const owner_nav = switch (ip.indexToKey(zcu.navValue(nav_index).toIntern())) {
32133214 .func => |function| function.owner_nav,
32143215 .variable => |variable| variable.owner_nav,
32153216 .@"extern" => |@"extern"| @"extern".owner_nav,
32163217 else => nav_index,
32173218 };
32183219 const nav_ty = ip.getNav(owner_nav).typeOf(ip);
3219 if (!ip.isFunctionType(nav_ty) and !Type.fromInterned(nav_ty).hasRuntimeBitsIgnoreComptime(pt)) {
3220 if (!ip.isFunctionType(nav_ty) and !Type.fromInterned(nav_ty).hasRuntimeBitsIgnoreComptime(zcu)) {
32203221 return .{ .imm32 = 0xaaaaaaaa };
32213222 }
32223223
......@@ -3234,10 +3235,10 @@ fn lowerNavRef(func: *CodeGen, nav_index: InternPool.Nav.Index, offset: u32) Inn
32343235/// Asserts that `isByRef` returns `false` for `ty`.
32353236fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
32363237 const pt = func.pt;
3237 const mod = pt.zcu;
3238 const zcu = pt.zcu;
32383239 assert(!isByRef(ty, pt, func.target.*));
3239 const ip = &mod.intern_pool;
3240 if (val.isUndefDeep(mod)) return func.emitUndefined(ty);
3240 const ip = &zcu.intern_pool;
3241 if (val.isUndefDeep(zcu)) return func.emitUndefined(ty);
32413242
32423243 switch (ip.indexToKey(val.ip_index)) {
32433244 .int_type,
......@@ -3280,16 +3281,16 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
32803281 .empty_enum_value,
32813282 => unreachable, // non-runtime values
32823283 .int => {
3283 const int_info = ty.intInfo(mod);
3284 const int_info = ty.intInfo(zcu);
32843285 switch (int_info.signedness) {
32853286 .signed => switch (int_info.bits) {
3286 0...32 => return .{ .imm32 = @bitCast(@as(i32, @intCast(val.toSignedInt(pt)))) },
3287 33...64 => return .{ .imm64 = @bitCast(val.toSignedInt(pt)) },
3287 0...32 => return .{ .imm32 = @bitCast(@as(i32, @intCast(val.toSignedInt(zcu)))) },
3288 33...64 => return .{ .imm64 = @bitCast(val.toSignedInt(zcu)) },
32883289 else => unreachable,
32893290 },
32903291 .unsigned => switch (int_info.bits) {
3291 0...32 => return .{ .imm32 = @intCast(val.toUnsignedInt(pt)) },
3292 33...64 => return .{ .imm64 = val.toUnsignedInt(pt) },
3292 0...32 => return .{ .imm32 = @intCast(val.toUnsignedInt(zcu)) },
3293 33...64 => return .{ .imm64 = val.toUnsignedInt(zcu) },
32933294 else => unreachable,
32943295 },
32953296 }
......@@ -3302,9 +3303,9 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33023303 const err_int_ty = try pt.errorIntType();
33033304 const err_ty, const err_val = switch (error_union.val) {
33043305 .err_name => |err_name| .{
3305 ty.errorUnionSet(mod),
3306 ty.errorUnionSet(zcu),
33063307 Value.fromInterned(try pt.intern(.{ .err = .{
3307 .ty = ty.errorUnionSet(mod).toIntern(),
3308 .ty = ty.errorUnionSet(zcu).toIntern(),
33083309 .name = err_name,
33093310 } })),
33103311 },
......@@ -3313,8 +3314,8 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33133314 try pt.intValue(err_int_ty, 0),
33143315 },
33153316 };
3316 const payload_type = ty.errorUnionPayload(mod);
3317 if (!payload_type.hasRuntimeBitsIgnoreComptime(pt)) {
3317 const payload_type = ty.errorUnionPayload(zcu);
3318 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
33183319 // We use the error type directly as the type.
33193320 return func.lowerConstant(err_val, err_ty);
33203321 }
......@@ -3339,20 +3340,20 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33393340 },
33403341 },
33413342 .ptr => return func.lowerPtr(val.toIntern(), 0),
3342 .opt => if (ty.optionalReprIsPayload(mod)) {
3343 const pl_ty = ty.optionalChild(mod);
3344 if (val.optionalValue(mod)) |payload| {
3343 .opt => if (ty.optionalReprIsPayload(zcu)) {
3344 const pl_ty = ty.optionalChild(zcu);
3345 if (val.optionalValue(zcu)) |payload| {
33453346 return func.lowerConstant(payload, pl_ty);
33463347 } else {
33473348 return .{ .imm32 = 0 };
33483349 }
33493350 } else {
3350 return .{ .imm32 = @intFromBool(!val.isNull(mod)) };
3351 return .{ .imm32 = @intFromBool(!val.isNull(zcu)) };
33513352 },
33523353 .aggregate => switch (ip.indexToKey(ty.ip_index)) {
33533354 .array_type => return func.fail("Wasm TODO: LowerConstant for {}", .{ty.fmt(pt)}),
33543355 .vector_type => {
3355 assert(determineSimdStoreStrategy(ty, pt, func.target.*) == .direct);
3356 assert(determineSimdStoreStrategy(ty, zcu, func.target.*) == .direct);
33563357 var buf: [16]u8 = undefined;
33573358 val.writeToMemory(ty, pt, &buf) catch unreachable;
33583359 return func.storeSimdImmd(buf);
......@@ -3378,8 +3379,8 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33783379 const constant_ty = if (un.tag == .none)
33793380 try ty.unionBackingType(pt)
33803381 else field_ty: {
3381 const union_obj = mod.typeToUnion(ty).?;
3382 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3382 const union_obj = zcu.typeToUnion(ty).?;
3383 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
33833384 break :field_ty Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
33843385 };
33853386 return func.lowerConstant(Value.fromInterned(un.val), constant_ty);
......@@ -3398,11 +3399,11 @@ fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue {
33983399
33993400fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
34003401 const pt = func.pt;
3401 const mod = pt.zcu;
3402 const ip = &mod.intern_pool;
3403 switch (ty.zigTypeTag(mod)) {
3402 const zcu = pt.zcu;
3403 const ip = &zcu.intern_pool;
3404 switch (ty.zigTypeTag(zcu)) {
34043405 .Bool, .ErrorSet => return .{ .imm32 = 0xaaaaaaaa },
3405 .Int, .Enum => switch (ty.intInfo(mod).bits) {
3406 .Int, .Enum => switch (ty.intInfo(zcu).bits) {
34063407 0...32 => return .{ .imm32 = 0xaaaaaaaa },
34073408 33...64 => return .{ .imm64 = 0xaaaaaaaaaaaaaaaa },
34083409 else => unreachable,
......@@ -3419,8 +3420,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
34193420 else => unreachable,
34203421 },
34213422 .Optional => {
3422 const pl_ty = ty.optionalChild(mod);
3423 if (ty.optionalReprIsPayload(mod)) {
3423 const pl_ty = ty.optionalChild(zcu);
3424 if (ty.optionalReprIsPayload(zcu)) {
34243425 return func.emitUndefined(pl_ty);
34253426 }
34263427 return .{ .imm32 = 0xaaaaaaaa };
......@@ -3429,10 +3430,10 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
34293430 return .{ .imm32 = 0xaaaaaaaa };
34303431 },
34313432 .Struct => {
3432 const packed_struct = mod.typeToPackedStruct(ty).?;
3433 const packed_struct = zcu.typeToPackedStruct(ty).?;
34333434 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)));
34343435 },
3435 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),
3436 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(zcu)}),
34363437 }
34373438}
34383439
......@@ -3441,8 +3442,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
34413442/// as an integer value.
34423443fn valueAsI32(func: *const CodeGen, val: Value) i32 {
34433444 const pt = func.pt;
3444 const mod = pt.zcu;
3445 const ip = &mod.intern_pool;
3445 const zcu = pt.zcu;
3446 const ip = &zcu.intern_pool;
34463447
34473448 switch (val.toIntern()) {
34483449 .bool_true => return 1,
......@@ -3465,12 +3466,13 @@ fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, pt: Zcu.PerThread
34653466}
34663467
34673468fn intStorageAsI32(storage: InternPool.Key.Int.Storage, pt: Zcu.PerThread) i32 {
3469 const zcu = pt.zcu;
34683470 return switch (storage) {
34693471 .i64 => |x| @as(i32, @intCast(x)),
34703472 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
34713473 .big_int => unreachable,
3472 .lazy_align => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0)))),
3473 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiSize(pt))))),
3474 .lazy_align => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0)))),
3475 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiSize(zcu))))),
34743476 };
34753477}
34763478
......@@ -3599,10 +3601,10 @@ fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) In
35993601fn cmp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOperator) InnerError!WValue {
36003602 assert(!(lhs != .stack and rhs == .stack));
36013603 const pt = func.pt;
3602 const mod = pt.zcu;
3603 if (ty.zigTypeTag(mod) == .Optional and !ty.optionalReprIsPayload(mod)) {
3604 const payload_ty = ty.optionalChild(mod);
3605 if (payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3604 const zcu = pt.zcu;
3605 if (ty.zigTypeTag(zcu) == .Optional and !ty.optionalReprIsPayload(zcu)) {
3606 const payload_ty = ty.optionalChild(zcu);
3607 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
36063608 // When we hit this case, we must check the value of optionals
36073609 // that are not pointers. This means first checking against non-null for
36083610 // both lhs and rhs, as well as checking the payload are matching of lhs and rhs
......@@ -3616,10 +3618,10 @@ fn cmp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareO
36163618
36173619 const signedness: std.builtin.Signedness = blk: {
36183620 // by default we tell the operand type is unsigned (i.e. bools and enum values)
3619 if (ty.zigTypeTag(mod) != .Int) break :blk .unsigned;
3621 if (ty.zigTypeTag(zcu) != .Int) break :blk .unsigned;
36203622
36213623 // incase of an actual integer, we emit the correct signedness
3622 break :blk ty.intInfo(mod).signedness;
3624 break :blk ty.intInfo(zcu).signedness;
36233625 };
36243626
36253627 // ensure that when we compare pointers, we emit
......@@ -3708,12 +3710,12 @@ fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37083710}
37093711
37103712fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3711 const pt = func.pt;
3713 const zcu = func.pt.zcu;
37123714 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;
37133715 const block = func.blocks.get(br.block_inst).?;
37143716
37153717 // if operand has codegen bits we should break with a value
3716 if (func.typeOf(br.operand).hasRuntimeBitsIgnoreComptime(pt)) {
3718 if (func.typeOf(br.operand).hasRuntimeBitsIgnoreComptime(zcu)) {
37173719 const operand = try func.resolveInst(br.operand);
37183720 try func.lowerToStack(operand);
37193721
......@@ -3736,17 +3738,17 @@ fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
37363738 const operand = try func.resolveInst(ty_op.operand);
37373739 const operand_ty = func.typeOf(ty_op.operand);
37383740 const pt = func.pt;
3739 const mod = pt.zcu;
3741 const zcu = pt.zcu;
37403742
37413743 const result = result: {
3742 if (operand_ty.zigTypeTag(mod) == .Bool) {
3744 if (operand_ty.zigTypeTag(zcu) == .Bool) {
37433745 try func.emitWValue(operand);
37443746 try func.addTag(.i32_eqz);
37453747 const not_tmp = try func.allocLocal(operand_ty);
37463748 try func.addLabel(.local_set, not_tmp.local.value);
37473749 break :result not_tmp;
37483750 } else {
3749 const int_info = operand_ty.intInfo(mod);
3751 const int_info = operand_ty.intInfo(zcu);
37503752 const wasm_bits = toWasmBits(int_info.bits) orelse {
37513753 return func.fail("TODO: Implement binary NOT for {}", .{operand_ty.fmt(pt)});
37523754 };
......@@ -3816,14 +3818,14 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38163818
38173819fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38183820 const pt = func.pt;
3819 const mod = pt.zcu;
3821 const zcu = pt.zcu;
38203822 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
38213823 const operand = try func.resolveInst(ty_op.operand);
38223824 const wanted_ty = func.typeOfIndex(inst);
38233825 const given_ty = func.typeOf(ty_op.operand);
38243826
3825 const bit_size = given_ty.bitSize(pt);
3826 const needs_wrapping = (given_ty.isSignedInt(mod) != wanted_ty.isSignedInt(mod)) and
3827 const bit_size = given_ty.bitSize(zcu);
3828 const needs_wrapping = (given_ty.isSignedInt(zcu) != wanted_ty.isSignedInt(zcu)) and
38273829 bit_size != 32 and bit_size != 64 and bit_size != 128;
38283830
38293831 const result = result: {
......@@ -3860,12 +3862,12 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38603862
38613863fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) InnerError!WValue {
38623864 const pt = func.pt;
3863 const mod = pt.zcu;
3865 const zcu = pt.zcu;
38643866 // if we bitcast a float to or from an integer we must use the 'reinterpret' instruction
38653867 if (!(wanted_ty.isAnyFloat() or given_ty.isAnyFloat())) return operand;
38663868 if (wanted_ty.ip_index == .f16_type or given_ty.ip_index == .f16_type) return operand;
3867 if (wanted_ty.bitSize(pt) > 64) return operand;
3868 assert((wanted_ty.isInt(mod) and given_ty.isAnyFloat()) or (wanted_ty.isAnyFloat() and given_ty.isInt(mod)));
3869 if (wanted_ty.bitSize(zcu) > 64) return operand;
3870 assert((wanted_ty.isInt(zcu) and given_ty.isAnyFloat()) or (wanted_ty.isAnyFloat() and given_ty.isInt(zcu)));
38693871
38703872 const opcode = buildOpcode(.{
38713873 .op = .reinterpret,
......@@ -3879,24 +3881,24 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
38793881
38803882fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38813883 const pt = func.pt;
3882 const mod = pt.zcu;
3884 const zcu = pt.zcu;
38833885 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
38843886 const extra = func.air.extraData(Air.StructField, ty_pl.payload);
38853887
38863888 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
38873889 const struct_ptr_ty = func.typeOf(extra.data.struct_operand);
3888 const struct_ty = struct_ptr_ty.childType(mod);
3890 const struct_ty = struct_ptr_ty.childType(zcu);
38893891 const result = try func.structFieldPtr(inst, extra.data.struct_operand, struct_ptr, struct_ptr_ty, struct_ty, extra.data.field_index);
38903892 return func.finishAir(inst, result, &.{extra.data.struct_operand});
38913893}
38923894
38933895fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
38943896 const pt = func.pt;
3895 const mod = pt.zcu;
3897 const zcu = pt.zcu;
38963898 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
38973899 const struct_ptr = try func.resolveInst(ty_op.operand);
38983900 const struct_ptr_ty = func.typeOf(ty_op.operand);
3899 const struct_ty = struct_ptr_ty.childType(mod);
3901 const struct_ty = struct_ptr_ty.childType(zcu);
39003902
39013903 const result = try func.structFieldPtr(inst, ty_op.operand, struct_ptr, struct_ptr_ty, struct_ty, index);
39023904 return func.finishAir(inst, result, &.{ty_op.operand});
......@@ -3912,23 +3914,23 @@ fn structFieldPtr(
39123914 index: u32,
39133915) InnerError!WValue {
39143916 const pt = func.pt;
3915 const mod = pt.zcu;
3917 const zcu = pt.zcu;
39163918 const result_ty = func.typeOfIndex(inst);
3917 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(mod);
3919 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu);
39183920
3919 const offset = switch (struct_ty.containerLayout(mod)) {
3920 .@"packed" => switch (struct_ty.zigTypeTag(mod)) {
3921 const offset = switch (struct_ty.containerLayout(zcu)) {
3922 .@"packed" => switch (struct_ty.zigTypeTag(zcu)) {
39213923 .Struct => offset: {
3922 if (result_ty.ptrInfo(mod).packed_offset.host_size != 0) {
3924 if (result_ty.ptrInfo(zcu).packed_offset.host_size != 0) {
39233925 break :offset @as(u32, 0);
39243926 }
3925 const struct_type = mod.typeToStruct(struct_ty).?;
3927 const struct_type = zcu.typeToStruct(struct_ty).?;
39263928 break :offset @divExact(pt.structPackedFieldBitOffset(struct_type, index) + struct_ptr_ty_info.packed_offset.bit_offset, 8);
39273929 },
39283930 .Union => 0,
39293931 else => unreachable,
39303932 },
3931 else => struct_ty.structFieldOffset(index, pt),
3933 else => struct_ty.structFieldOffset(index, zcu),
39323934 };
39333935 // save a load and store when we can simply reuse the operand
39343936 if (offset == 0) {
......@@ -3944,24 +3946,24 @@ fn structFieldPtr(
39443946
39453947fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39463948 const pt = func.pt;
3947 const mod = pt.zcu;
3948 const ip = &mod.intern_pool;
3949 const zcu = pt.zcu;
3950 const ip = &zcu.intern_pool;
39493951 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
39503952 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;
39513953
39523954 const struct_ty = func.typeOf(struct_field.struct_operand);
39533955 const operand = try func.resolveInst(struct_field.struct_operand);
39543956 const field_index = struct_field.field_index;
3955 const field_ty = struct_ty.structFieldType(field_index, mod);
3956 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) return func.finishAir(inst, .none, &.{struct_field.struct_operand});
3957 const field_ty = struct_ty.structFieldType(field_index, zcu);
3958 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) return func.finishAir(inst, .none, &.{struct_field.struct_operand});
39573959
3958 const result: WValue = switch (struct_ty.containerLayout(mod)) {
3959 .@"packed" => switch (struct_ty.zigTypeTag(mod)) {
3960 const result: WValue = switch (struct_ty.containerLayout(zcu)) {
3961 .@"packed" => switch (struct_ty.zigTypeTag(zcu)) {
39603962 .Struct => result: {
3961 const packed_struct = mod.typeToPackedStruct(struct_ty).?;
3963 const packed_struct = zcu.typeToPackedStruct(struct_ty).?;
39623964 const offset = pt.structPackedFieldBitOffset(packed_struct, field_index);
39633965 const backing_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
3964 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {
3966 const wasm_bits = toWasmBits(backing_ty.intInfo(zcu).bits) orelse {
39653967 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});
39663968 };
39673969 const const_wvalue: WValue = if (wasm_bits == 32)
......@@ -3977,16 +3979,16 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39773979 else
39783980 try func.binOp(operand, const_wvalue, backing_ty, .shr);
39793981
3980 if (field_ty.zigTypeTag(mod) == .Float) {
3981 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));
3982 if (field_ty.zigTypeTag(zcu) == .Float) {
3983 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
39823984 const truncated = try func.trunc(shifted_value, int_type, backing_ty);
39833985 break :result try func.bitcast(field_ty, int_type, truncated);
3984 } else if (field_ty.isPtrAtRuntime(mod) and packed_struct.field_types.len == 1) {
3986 } else if (field_ty.isPtrAtRuntime(zcu) and packed_struct.field_types.len == 1) {
39853987 // In this case we do not have to perform any transformations,
39863988 // we can simply reuse the operand.
39873989 break :result func.reuseOperand(struct_field.struct_operand, operand);
3988 } else if (field_ty.isPtrAtRuntime(mod)) {
3989 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));
3990 } else if (field_ty.isPtrAtRuntime(zcu)) {
3991 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
39903992 break :result try func.trunc(shifted_value, int_type, backing_ty);
39913993 }
39923994 break :result try func.trunc(shifted_value, field_ty, backing_ty);
......@@ -4002,13 +4004,13 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40024004 }
40034005 }
40044006
4005 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(struct_ty.bitSize(pt))));
4006 if (field_ty.zigTypeTag(mod) == .Float) {
4007 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));
4007 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(struct_ty.bitSize(zcu))));
4008 if (field_ty.zigTypeTag(zcu) == .Float) {
4009 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
40084010 const truncated = try func.trunc(operand, int_type, union_int_type);
40094011 break :result try func.bitcast(field_ty, int_type, truncated);
4010 } else if (field_ty.isPtrAtRuntime(mod)) {
4011 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));
4012 } else if (field_ty.isPtrAtRuntime(zcu)) {
4013 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
40124014 break :result try func.trunc(operand, int_type, union_int_type);
40134015 }
40144016 break :result try func.trunc(operand, field_ty, union_int_type);
......@@ -4016,7 +4018,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40164018 else => unreachable,
40174019 },
40184020 else => result: {
4019 const offset = std.math.cast(u32, struct_ty.structFieldOffset(field_index, pt)) orelse {
4021 const offset = std.math.cast(u32, struct_ty.structFieldOffset(field_index, zcu)) orelse {
40204022 return func.fail("Field type '{}' too big to fit into stack frame", .{field_ty.fmt(pt)});
40214023 };
40224024 if (isByRef(field_ty, pt, func.target.*)) {
......@@ -4036,7 +4038,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40364038
40374039fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40384040 const pt = func.pt;
4039 const mod = pt.zcu;
4041 const zcu = pt.zcu;
40404042 // result type is always 'noreturn'
40414043 const blocktype = wasm.block_empty;
40424044 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
......@@ -4093,7 +4095,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40934095 // When the target is an integer size larger than u32, we have no way to use the value
40944096 // as an index, therefore we also use an if/else-chain for those cases.
40954097 // TODO: Benchmark this to find a proper value, LLVM seems to draw the line at '40~45'.
4096 const is_sparse = highest - lowest > 50 or target_ty.bitSize(pt) > 32;
4098 const is_sparse = highest - lowest > 50 or target_ty.bitSize(zcu) > 32;
40974099
40984100 const else_body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra_index..][0..switch_br.data.else_body_len]);
40994101 const has_else_body = else_body.len != 0;
......@@ -4138,7 +4140,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41384140 // for errors that are not present in any branch. This is fine as this default
41394141 // case will never be hit for those cases but we do save runtime cost and size
41404142 // by using a jump table for this instead of if-else chains.
4141 break :blk if (has_else_body or target_ty.zigTypeTag(mod) == .ErrorSet) case_i else unreachable;
4143 break :blk if (has_else_body or target_ty.zigTypeTag(zcu) == .ErrorSet) case_i else unreachable;
41424144 };
41434145 func.mir_extra.appendAssumeCapacity(idx);
41444146 } else if (has_else_body) {
......@@ -4149,10 +4151,10 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41494151
41504152 const signedness: std.builtin.Signedness = blk: {
41514153 // by default we tell the operand type is unsigned (i.e. bools and enum values)
4152 if (target_ty.zigTypeTag(mod) != .Int) break :blk .unsigned;
4154 if (target_ty.zigTypeTag(zcu) != .Int) break :blk .unsigned;
41534155
41544156 // incase of an actual integer, we emit the correct signedness
4155 break :blk target_ty.intInfo(mod).signedness;
4157 break :blk target_ty.intInfo(zcu).signedness;
41564158 };
41574159
41584160 try func.branches.ensureUnusedCapacity(func.gpa, case_list.items.len + @intFromBool(has_else_body));
......@@ -4217,14 +4219,14 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42174219
42184220fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {
42194221 const pt = func.pt;
4220 const mod = pt.zcu;
4222 const zcu = pt.zcu;
42214223 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
42224224 const operand = try func.resolveInst(un_op);
42234225 const err_union_ty = func.typeOf(un_op);
4224 const pl_ty = err_union_ty.errorUnionPayload(mod);
4226 const pl_ty = err_union_ty.errorUnionPayload(zcu);
42254227
42264228 const result: WValue = result: {
4227 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
4229 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
42284230 switch (opcode) {
42294231 .i32_ne => break :result .{ .imm32 = 0 },
42304232 .i32_eq => break :result .{ .imm32 = 1 },
......@@ -4233,10 +4235,10 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
42334235 }
42344236
42354237 try func.emitWValue(operand);
4236 if (pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4238 if (pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
42374239 try func.addMemArg(.i32_load16_u, .{
4238 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, pt))),
4239 .alignment = @intCast(Type.anyerror.abiAlignment(pt).toByteUnits().?),
4240 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, zcu))),
4241 .alignment = @intCast(Type.anyerror.abiAlignment(zcu).toByteUnits().?),
42404242 });
42414243 }
42424244
......@@ -4250,23 +4252,23 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
42504252
42514253fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
42524254 const pt = func.pt;
4253 const mod = pt.zcu;
4255 const zcu = pt.zcu;
42544256 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
42554257
42564258 const operand = try func.resolveInst(ty_op.operand);
42574259 const op_ty = func.typeOf(ty_op.operand);
4258 const err_ty = if (op_is_ptr) op_ty.childType(mod) else op_ty;
4259 const payload_ty = err_ty.errorUnionPayload(mod);
4260 const err_ty = if (op_is_ptr) op_ty.childType(zcu) else op_ty;
4261 const payload_ty = err_ty.errorUnionPayload(zcu);
42604262
42614263 const result: WValue = result: {
4262 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
42634265 if (op_is_ptr) {
42644266 break :result func.reuseOperand(ty_op.operand, operand);
42654267 }
42664268 break :result .none;
42674269 }
42684270
4269 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt)));
4271 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu)));
42704272 if (op_is_ptr or isByRef(payload_ty, pt, func.target.*)) {
42714273 break :result try func.buildPointerOffset(operand, pl_offset, .new);
42724274 }
......@@ -4278,30 +4280,30 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
42784280
42794281fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
42804282 const pt = func.pt;
4281 const mod = pt.zcu;
4283 const zcu = pt.zcu;
42824284 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
42834285
42844286 const operand = try func.resolveInst(ty_op.operand);
42854287 const op_ty = func.typeOf(ty_op.operand);
4286 const err_ty = if (op_is_ptr) op_ty.childType(mod) else op_ty;
4287 const payload_ty = err_ty.errorUnionPayload(mod);
4288 const err_ty = if (op_is_ptr) op_ty.childType(zcu) else op_ty;
4289 const payload_ty = err_ty.errorUnionPayload(zcu);
42884290
42894291 const result: WValue = result: {
4290 if (err_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
4292 if (err_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
42914293 break :result .{ .imm32 = 0 };
42924294 }
42934295
4294 if (op_is_ptr or !payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4296 if (op_is_ptr or !payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
42954297 break :result func.reuseOperand(ty_op.operand, operand);
42964298 }
42974299
4298 break :result try func.load(operand, Type.anyerror, @intCast(errUnionErrorOffset(payload_ty, pt)));
4300 break :result try func.load(operand, Type.anyerror, @intCast(errUnionErrorOffset(payload_ty, zcu)));
42994301 };
43004302 return func.finishAir(inst, result, &.{ty_op.operand});
43014303}
43024304
43034305fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4304 const pt = func.pt;
4306 const zcu = func.pt.zcu;
43054307 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
43064308
43074309 const operand = try func.resolveInst(ty_op.operand);
......@@ -4309,18 +4311,18 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
43094311
43104312 const pl_ty = func.typeOf(ty_op.operand);
43114313 const result = result: {
4312 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4314 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
43134315 break :result func.reuseOperand(ty_op.operand, operand);
43144316 }
43154317
43164318 const err_union = try func.allocStack(err_ty);
4317 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, pt))), .new);
4319 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, zcu))), .new);
43184320 try func.store(payload_ptr, operand, pl_ty, 0);
43194321
43204322 // ensure we also write '0' to the error part, so any present stack value gets overwritten by it.
43214323 try func.emitWValue(err_union);
43224324 try func.addImm32(0);
4323 const err_val_offset: u32 = @intCast(errUnionErrorOffset(pl_ty, pt));
4325 const err_val_offset: u32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
43244326 try func.addMemArg(.i32_store16, .{
43254327 .offset = err_union.offset() + err_val_offset,
43264328 .alignment = 2,
......@@ -4332,25 +4334,25 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
43324334
43334335fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43344336 const pt = func.pt;
4335 const mod = pt.zcu;
4337 const zcu = pt.zcu;
43364338 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
43374339
43384340 const operand = try func.resolveInst(ty_op.operand);
43394341 const err_ty = ty_op.ty.toType();
4340 const pl_ty = err_ty.errorUnionPayload(mod);
4342 const pl_ty = err_ty.errorUnionPayload(zcu);
43414343
43424344 const result = result: {
4343 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4345 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
43444346 break :result func.reuseOperand(ty_op.operand, operand);
43454347 }
43464348
43474349 const err_union = try func.allocStack(err_ty);
43484350 // store error value
4349 try func.store(err_union, operand, Type.anyerror, @intCast(errUnionErrorOffset(pl_ty, pt)));
4351 try func.store(err_union, operand, Type.anyerror, @intCast(errUnionErrorOffset(pl_ty, zcu)));
43504352
43514353 // write 'undefined' to the payload
4352 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, pt))), .new);
4353 const len = @as(u32, @intCast(err_ty.errorUnionPayload(mod).abiSize(pt)));
4354 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, zcu))), .new);
4355 const len = @as(u32, @intCast(err_ty.errorUnionPayload(zcu).abiSize(zcu)));
43544356 try func.memset(Type.u8, payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaa });
43554357
43564358 break :result err_union;
......@@ -4365,16 +4367,16 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43654367 const operand = try func.resolveInst(ty_op.operand);
43664368 const operand_ty = func.typeOf(ty_op.operand);
43674369 const pt = func.pt;
4368 const mod = pt.zcu;
4369 if (ty.zigTypeTag(mod) == .Vector or operand_ty.zigTypeTag(mod) == .Vector) {
4370 const zcu = pt.zcu;
4371 if (ty.zigTypeTag(zcu) == .Vector or operand_ty.zigTypeTag(zcu) == .Vector) {
43704372 return func.fail("todo Wasm intcast for vectors", .{});
43714373 }
4372 if (ty.abiSize(pt) > 16 or operand_ty.abiSize(pt) > 16) {
4374 if (ty.abiSize(zcu) > 16 or operand_ty.abiSize(zcu) > 16) {
43734375 return func.fail("todo Wasm intcast for bitsize > 128", .{});
43744376 }
43754377
4376 const op_bits = toWasmBits(@intCast(operand_ty.bitSize(pt))).?;
4377 const wanted_bits = toWasmBits(@intCast(ty.bitSize(pt))).?;
4378 const op_bits = toWasmBits(@intCast(operand_ty.bitSize(zcu))).?;
4379 const wanted_bits = toWasmBits(@intCast(ty.bitSize(zcu))).?;
43784380 const result = if (op_bits == wanted_bits)
43794381 func.reuseOperand(ty_op.operand, operand)
43804382 else
......@@ -4389,9 +4391,9 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43894391/// NOTE: May leave the result on the top of the stack.
43904392fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
43914393 const pt = func.pt;
4392 const mod = pt.zcu;
4393 const given_bitsize = @as(u16, @intCast(given.bitSize(pt)));
4394 const wanted_bitsize = @as(u16, @intCast(wanted.bitSize(pt)));
4394 const zcu = pt.zcu;
4395 const given_bitsize = @as(u16, @intCast(given.bitSize(zcu)));
4396 const wanted_bitsize = @as(u16, @intCast(wanted.bitSize(zcu)));
43954397 assert(given_bitsize <= 128);
43964398 assert(wanted_bitsize <= 128);
43974399
......@@ -4407,7 +4409,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
44074409 return .stack;
44084410 } else if (op_bits == 32 and wanted_bits == 64) {
44094411 try func.emitWValue(operand);
4410 try func.addTag(if (wanted.isSignedInt(mod)) .i64_extend_i32_s else .i64_extend_i32_u);
4412 try func.addTag(if (wanted.isSignedInt(zcu)) .i64_extend_i32_s else .i64_extend_i32_u);
44114413 return .stack;
44124414 } else if (wanted_bits == 128) {
44134415 // for 128bit integers we store the integer in the virtual stack, rather than a local
......@@ -4417,7 +4419,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
44174419 // for 32 bit integers, we first coerce the value into a 64 bit integer before storing it
44184420 // meaning less store operations are required.
44194421 const lhs = if (op_bits == 32) blk: {
4420 const sign_ty = if (wanted.isSignedInt(mod)) Type.i64 else Type.u64;
4422 const sign_ty = if (wanted.isSignedInt(zcu)) Type.i64 else Type.u64;
44214423 break :blk try (try func.intcast(operand, given, sign_ty)).toLocal(func, sign_ty);
44224424 } else operand;
44234425
......@@ -4425,7 +4427,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
44254427 try func.store(.stack, lhs, Type.u64, 0 + stack_ptr.offset());
44264428
44274429 // For signed integers we shift lsb by 63 (64bit integer - 1 sign bit) and store remaining value
4428 if (wanted.isSignedInt(mod)) {
4430 if (wanted.isSignedInt(zcu)) {
44294431 try func.emitWValue(stack_ptr);
44304432 const shr = try func.binOp(lhs, .{ .imm64 = 63 }, Type.i64, .shr);
44314433 try func.store(.stack, shr, Type.u64, 8 + stack_ptr.offset());
......@@ -4439,12 +4441,12 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
44394441
44404442fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
44414443 const pt = func.pt;
4442 const mod = pt.zcu;
4444 const zcu = pt.zcu;
44434445 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
44444446 const operand = try func.resolveInst(un_op);
44454447
44464448 const op_ty = func.typeOf(un_op);
4447 const optional_ty = if (op_kind == .ptr) op_ty.childType(mod) else op_ty;
4449 const optional_ty = if (op_kind == .ptr) op_ty.childType(zcu) else op_ty;
44484450 const result = try func.isNull(operand, optional_ty, opcode);
44494451 return func.finishAir(inst, result, &.{un_op});
44504452}
......@@ -4453,19 +4455,19 @@ fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind:
44534455/// NOTE: Leaves the result on the stack
44544456fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcode) InnerError!WValue {
44554457 const pt = func.pt;
4456 const mod = pt.zcu;
4458 const zcu = pt.zcu;
44574459 try func.emitWValue(operand);
4458 const payload_ty = optional_ty.optionalChild(mod);
4459 if (!optional_ty.optionalReprIsPayload(mod)) {
4460 const payload_ty = optional_ty.optionalChild(zcu);
4461 if (!optional_ty.optionalReprIsPayload(zcu)) {
44604462 // When payload is zero-bits, we can treat operand as a value, rather than
44614463 // a pointer to the stack value
4462 if (payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4463 const offset = std.math.cast(u32, payload_ty.abiSize(pt)) orelse {
4464 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4465 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
44644466 return func.fail("Optional type {} too big to fit into stack frame", .{optional_ty.fmt(pt)});
44654467 };
44664468 try func.addMemArg(.i32_load8_u, .{ .offset = operand.offset() + offset, .alignment = 1 });
44674469 }
4468 } else if (payload_ty.isSlice(mod)) {
4470 } else if (payload_ty.isSlice(zcu)) {
44694471 switch (func.arch()) {
44704472 .wasm32 => try func.addMemArg(.i32_load, .{ .offset = operand.offset(), .alignment = 4 }),
44714473 .wasm64 => try func.addMemArg(.i64_load, .{ .offset = operand.offset(), .alignment = 8 }),
......@@ -4482,17 +4484,17 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod
44824484
44834485fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44844486 const pt = func.pt;
4485 const mod = pt.zcu;
4487 const zcu = pt.zcu;
44864488 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
44874489 const opt_ty = func.typeOf(ty_op.operand);
44884490 const payload_ty = func.typeOfIndex(inst);
4489 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4491 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
44904492 return func.finishAir(inst, .none, &.{ty_op.operand});
44914493 }
44924494
44934495 const result = result: {
44944496 const operand = try func.resolveInst(ty_op.operand);
4495 if (opt_ty.optionalReprIsPayload(mod)) break :result func.reuseOperand(ty_op.operand, operand);
4497 if (opt_ty.optionalReprIsPayload(zcu)) break :result func.reuseOperand(ty_op.operand, operand);
44964498
44974499 if (isByRef(payload_ty, pt, func.target.*)) {
44984500 break :result try func.buildPointerOffset(operand, 0, .new);
......@@ -4505,14 +4507,14 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45054507
45064508fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45074509 const pt = func.pt;
4508 const mod = pt.zcu;
4510 const zcu = pt.zcu;
45094511 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
45104512 const operand = try func.resolveInst(ty_op.operand);
4511 const opt_ty = func.typeOf(ty_op.operand).childType(mod);
4513 const opt_ty = func.typeOf(ty_op.operand).childType(zcu);
45124514
45134515 const result = result: {
4514 const payload_ty = opt_ty.optionalChild(mod);
4515 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt) or opt_ty.optionalReprIsPayload(mod)) {
4516 const payload_ty = opt_ty.optionalChild(zcu);
4517 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu) or opt_ty.optionalReprIsPayload(zcu)) {
45164518 break :result func.reuseOperand(ty_op.operand, operand);
45174519 }
45184520
......@@ -4523,20 +4525,20 @@ fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45234525
45244526fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45254527 const pt = func.pt;
4526 const mod = pt.zcu;
4528 const zcu = pt.zcu;
45274529 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
45284530 const operand = try func.resolveInst(ty_op.operand);
4529 const opt_ty = func.typeOf(ty_op.operand).childType(mod);
4530 const payload_ty = opt_ty.optionalChild(mod);
4531 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4531 const opt_ty = func.typeOf(ty_op.operand).childType(zcu);
4532 const payload_ty = opt_ty.optionalChild(zcu);
4533 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
45324534 return func.fail("TODO: Implement OptionalPayloadPtrSet for optional with zero-sized type {}", .{payload_ty.fmtDebug()});
45334535 }
45344536
4535 if (opt_ty.optionalReprIsPayload(mod)) {
4537 if (opt_ty.optionalReprIsPayload(zcu)) {
45364538 return func.finishAir(inst, operand, &.{ty_op.operand});
45374539 }
45384540
4539 const offset = std.math.cast(u32, payload_ty.abiSize(pt)) orelse {
4541 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
45404542 return func.fail("Optional type {} too big to fit into stack frame", .{opt_ty.fmt(pt)});
45414543 };
45424544
......@@ -4552,10 +4554,10 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45524554 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
45534555 const payload_ty = func.typeOf(ty_op.operand);
45544556 const pt = func.pt;
4555 const mod = pt.zcu;
4557 const zcu = pt.zcu;
45564558
45574559 const result = result: {
4558 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4560 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
45594561 const non_null_bit = try func.allocStack(Type.u1);
45604562 try func.emitWValue(non_null_bit);
45614563 try func.addImm32(1);
......@@ -4565,10 +4567,10 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45654567
45664568 const operand = try func.resolveInst(ty_op.operand);
45674569 const op_ty = func.typeOfIndex(inst);
4568 if (op_ty.optionalReprIsPayload(mod)) {
4570 if (op_ty.optionalReprIsPayload(zcu)) {
45694571 break :result func.reuseOperand(ty_op.operand, operand);
45704572 }
4571 const offset = std.math.cast(u32, payload_ty.abiSize(pt)) orelse {
4573 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
45724574 return func.fail("Optional type {} too big to fit into stack frame", .{op_ty.fmt(pt)});
45734575 };
45744576
......@@ -4610,14 +4612,14 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46104612
46114613fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46124614 const pt = func.pt;
4613 const mod = pt.zcu;
4615 const zcu = pt.zcu;
46144616 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
46154617
46164618 const slice_ty = func.typeOf(bin_op.lhs);
46174619 const slice = try func.resolveInst(bin_op.lhs);
46184620 const index = try func.resolveInst(bin_op.rhs);
4619 const elem_ty = slice_ty.childType(mod);
4620 const elem_size = elem_ty.abiSize(pt);
4621 const elem_ty = slice_ty.childType(zcu);
4622 const elem_size = elem_ty.abiSize(zcu);
46214623
46224624 // load pointer onto stack
46234625 _ = try func.load(slice, Type.usize, 0);
......@@ -4638,12 +4640,12 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46384640
46394641fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46404642 const pt = func.pt;
4641 const mod = pt.zcu;
4643 const zcu = pt.zcu;
46424644 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
46434645 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
46444646
4645 const elem_ty = ty_pl.ty.toType().childType(mod);
4646 const elem_size = elem_ty.abiSize(pt);
4647 const elem_ty = ty_pl.ty.toType().childType(zcu);
4648 const elem_size = elem_ty.abiSize(zcu);
46474649
46484650 const slice = try func.resolveInst(bin_op.lhs);
46494651 const index = try func.resolveInst(bin_op.rhs);
......@@ -4682,13 +4684,13 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46824684 const wanted_ty: Type = ty_op.ty.toType();
46834685 const op_ty = func.typeOf(ty_op.operand);
46844686 const pt = func.pt;
4685 const mod = pt.zcu;
4687 const zcu = pt.zcu;
46864688
4687 if (wanted_ty.zigTypeTag(mod) == .Vector or op_ty.zigTypeTag(mod) == .Vector) {
4689 if (wanted_ty.zigTypeTag(zcu) == .Vector or op_ty.zigTypeTag(zcu) == .Vector) {
46884690 return func.fail("TODO: trunc for vectors", .{});
46894691 }
46904692
4691 const result = if (op_ty.bitSize(pt) == wanted_ty.bitSize(pt))
4693 const result = if (op_ty.bitSize(zcu) == wanted_ty.bitSize(zcu))
46924694 func.reuseOperand(ty_op.operand, operand)
46934695 else
46944696 try func.trunc(operand, wanted_ty, op_ty);
......@@ -4700,13 +4702,14 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47004702/// NOTE: Resulting value is left on the stack.
47014703fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) InnerError!WValue {
47024704 const pt = func.pt;
4703 const given_bits = @as(u16, @intCast(given_ty.bitSize(pt)));
4705 const zcu = pt.zcu;
4706 const given_bits = @as(u16, @intCast(given_ty.bitSize(zcu)));
47044707 if (toWasmBits(given_bits) == null) {
47054708 return func.fail("TODO: Implement wasm integer truncation for integer bitsize: {d}", .{given_bits});
47064709 }
47074710
47084711 var result = try func.intcast(operand, given_ty, wanted_ty);
4709 const wanted_bits = @as(u16, @intCast(wanted_ty.bitSize(pt)));
4712 const wanted_bits = @as(u16, @intCast(wanted_ty.bitSize(zcu)));
47104713 const wasm_bits = toWasmBits(wanted_bits).?;
47114714 if (wasm_bits != wanted_bits) {
47124715 result = try func.wrapOperand(result, wanted_ty);
......@@ -4724,23 +4727,23 @@ fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47244727
47254728fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47264729 const pt = func.pt;
4727 const mod = pt.zcu;
4730 const zcu = pt.zcu;
47284731 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
47294732
47304733 const operand = try func.resolveInst(ty_op.operand);
4731 const array_ty = func.typeOf(ty_op.operand).childType(mod);
4734 const array_ty = func.typeOf(ty_op.operand).childType(zcu);
47324735 const slice_ty = ty_op.ty.toType();
47334736
47344737 // create a slice on the stack
47354738 const slice_local = try func.allocStack(slice_ty);
47364739
47374740 // store the array ptr in the slice
4738 if (array_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4741 if (array_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
47394742 try func.store(slice_local, operand, Type.usize, 0);
47404743 }
47414744
47424745 // store the length of the array in the slice
4743 const array_len: u32 = @intCast(array_ty.arrayLen(mod));
4746 const array_len: u32 = @intCast(array_ty.arrayLen(zcu));
47444747 try func.store(slice_local, .{ .imm32 = array_len }, Type.usize, func.ptrSize());
47454748
47464749 return func.finishAir(inst, slice_local, &.{ty_op.operand});
......@@ -4748,11 +4751,11 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47484751
47494752fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47504753 const pt = func.pt;
4751 const mod = pt.zcu;
4754 const zcu = pt.zcu;
47524755 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
47534756 const operand = try func.resolveInst(un_op);
47544757 const ptr_ty = func.typeOf(un_op);
4755 const result = if (ptr_ty.isSlice(mod))
4758 const result = if (ptr_ty.isSlice(zcu))
47564759 try func.slicePtr(operand)
47574760 else switch (operand) {
47584761 // for stack offset, return a pointer to this offset.
......@@ -4764,17 +4767,17 @@ fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47644767
47654768fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47664769 const pt = func.pt;
4767 const mod = pt.zcu;
4770 const zcu = pt.zcu;
47684771 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
47694772
47704773 const ptr_ty = func.typeOf(bin_op.lhs);
47714774 const ptr = try func.resolveInst(bin_op.lhs);
47724775 const index = try func.resolveInst(bin_op.rhs);
4773 const elem_ty = ptr_ty.childType(mod);
4774 const elem_size = elem_ty.abiSize(pt);
4776 const elem_ty = ptr_ty.childType(zcu);
4777 const elem_size = elem_ty.abiSize(zcu);
47754778
47764779 // load pointer onto the stack
4777 if (ptr_ty.isSlice(mod)) {
4780 if (ptr_ty.isSlice(zcu)) {
47784781 _ = try func.load(ptr, Type.usize, 0);
47794782 } else {
47804783 try func.lowerToStack(ptr);
......@@ -4796,19 +4799,19 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47964799
47974800fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47984801 const pt = func.pt;
4799 const mod = pt.zcu;
4802 const zcu = pt.zcu;
48004803 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
48014804 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
48024805
48034806 const ptr_ty = func.typeOf(bin_op.lhs);
4804 const elem_ty = ty_pl.ty.toType().childType(mod);
4805 const elem_size = elem_ty.abiSize(pt);
4807 const elem_ty = ty_pl.ty.toType().childType(zcu);
4808 const elem_size = elem_ty.abiSize(zcu);
48064809
48074810 const ptr = try func.resolveInst(bin_op.lhs);
48084811 const index = try func.resolveInst(bin_op.rhs);
48094812
48104813 // load pointer onto the stack
4811 if (ptr_ty.isSlice(mod)) {
4814 if (ptr_ty.isSlice(zcu)) {
48124815 _ = try func.load(ptr, Type.usize, 0);
48134816 } else {
48144817 try func.lowerToStack(ptr);
......@@ -4825,16 +4828,16 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48254828
48264829fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
48274830 const pt = func.pt;
4828 const mod = pt.zcu;
4831 const zcu = pt.zcu;
48294832 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
48304833 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
48314834
48324835 const ptr = try func.resolveInst(bin_op.lhs);
48334836 const offset = try func.resolveInst(bin_op.rhs);
48344837 const ptr_ty = func.typeOf(bin_op.lhs);
4835 const pointee_ty = switch (ptr_ty.ptrSize(mod)) {
4836 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
4837 else => ptr_ty.childType(mod),
4838 const pointee_ty = switch (ptr_ty.ptrSize(zcu)) {
4839 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
4840 else => ptr_ty.childType(zcu),
48384841 };
48394842
48404843 const valtype = typeToValtype(Type.usize, pt, func.target.*);
......@@ -4843,7 +4846,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
48434846
48444847 try func.lowerToStack(ptr);
48454848 try func.emitWValue(offset);
4846 try func.addImm32(@intCast(pointee_ty.abiSize(pt)));
4849 try func.addImm32(@intCast(pointee_ty.abiSize(zcu)));
48474850 try func.addTag(Mir.Inst.Tag.fromOpcode(mul_opcode));
48484851 try func.addTag(Mir.Inst.Tag.fromOpcode(bin_opcode));
48494852
......@@ -4852,7 +4855,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
48524855
48534856fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
48544857 const pt = func.pt;
4855 const mod = pt.zcu;
4858 const zcu = pt.zcu;
48564859 if (safety) {
48574860 // TODO if the value is undef, write 0xaa bytes to dest
48584861 } else {
......@@ -4863,16 +4866,16 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
48634866 const ptr = try func.resolveInst(bin_op.lhs);
48644867 const ptr_ty = func.typeOf(bin_op.lhs);
48654868 const value = try func.resolveInst(bin_op.rhs);
4866 const len = switch (ptr_ty.ptrSize(mod)) {
4869 const len = switch (ptr_ty.ptrSize(zcu)) {
48674870 .Slice => try func.sliceLen(ptr),
4868 .One => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_ty.childType(mod).arrayLen(mod))) }),
4871 .One => @as(WValue, .{ .imm32 = @as(u32, @intCast(ptr_ty.childType(zcu).arrayLen(zcu))) }),
48694872 .C, .Many => unreachable,
48704873 };
48714874
4872 const elem_ty = if (ptr_ty.ptrSize(mod) == .One)
4873 ptr_ty.childType(mod).childType(mod)
4875 const elem_ty = if (ptr_ty.ptrSize(zcu) == .One)
4876 ptr_ty.childType(zcu).childType(zcu)
48744877 else
4875 ptr_ty.childType(mod);
4878 ptr_ty.childType(zcu);
48764879
48774880 const dst_ptr = try func.sliceOrArrayPtr(ptr, ptr_ty);
48784881 try func.memset(elem_ty, dst_ptr, len, value);
......@@ -4886,7 +4889,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
48864889/// we implement it manually.
48874890fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void {
48884891 const pt = func.pt;
4889 const abi_size = @as(u32, @intCast(elem_ty.abiSize(pt)));
4892 const abi_size = @as(u32, @intCast(elem_ty.abiSize(pt.zcu)));
48904893
48914894 // When bulk_memory is enabled, we lower it to wasm's memset instruction.
48924895 // If not, we lower it ourselves.
......@@ -4975,14 +4978,14 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue
49754978
49764979fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49774980 const pt = func.pt;
4978 const mod = pt.zcu;
4981 const zcu = pt.zcu;
49794982 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
49804983
49814984 const array_ty = func.typeOf(bin_op.lhs);
49824985 const array = try func.resolveInst(bin_op.lhs);
49834986 const index = try func.resolveInst(bin_op.rhs);
4984 const elem_ty = array_ty.childType(mod);
4985 const elem_size = elem_ty.abiSize(pt);
4987 const elem_ty = array_ty.childType(zcu);
4988 const elem_size = elem_ty.abiSize(zcu);
49864989
49874990 if (isByRef(array_ty, pt, func.target.*)) {
49884991 try func.lowerToStack(array);
......@@ -4991,15 +4994,15 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49914994 try func.addTag(.i32_mul);
49924995 try func.addTag(.i32_add);
49934996 } else {
4994 std.debug.assert(array_ty.zigTypeTag(mod) == .Vector);
4997 std.debug.assert(array_ty.zigTypeTag(zcu) == .Vector);
49954998
49964999 switch (index) {
49975000 inline .imm32, .imm64 => |lane| {
4998 const opcode: wasm.SimdOpcode = switch (elem_ty.bitSize(pt)) {
4999 8 => if (elem_ty.isSignedInt(mod)) .i8x16_extract_lane_s else .i8x16_extract_lane_u,
5000 16 => if (elem_ty.isSignedInt(mod)) .i16x8_extract_lane_s else .i16x8_extract_lane_u,
5001 32 => if (elem_ty.isInt(mod)) .i32x4_extract_lane else .f32x4_extract_lane,
5002 64 => if (elem_ty.isInt(mod)) .i64x2_extract_lane else .f64x2_extract_lane,
5001 const opcode: wasm.SimdOpcode = switch (elem_ty.bitSize(zcu)) {
5002 8 => if (elem_ty.isSignedInt(zcu)) .i8x16_extract_lane_s else .i8x16_extract_lane_u,
5003 16 => if (elem_ty.isSignedInt(zcu)) .i16x8_extract_lane_s else .i16x8_extract_lane_u,
5004 32 => if (elem_ty.isInt(zcu)) .i32x4_extract_lane else .f32x4_extract_lane,
5005 64 => if (elem_ty.isInt(zcu)) .i64x2_extract_lane else .f64x2_extract_lane,
50035006 else => unreachable,
50045007 };
50055008
......@@ -5037,7 +5040,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50375040
50385041fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50395042 const pt = func.pt;
5040 const mod = pt.zcu;
5043 const zcu = pt.zcu;
50415044 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50425045
50435046 const operand = try func.resolveInst(ty_op.operand);
......@@ -5045,7 +5048,7 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50455048 const op_bits = op_ty.floatBits(func.target.*);
50465049
50475050 const dest_ty = func.typeOfIndex(inst);
5048 const dest_info = dest_ty.intInfo(mod);
5051 const dest_info = dest_ty.intInfo(zcu);
50495052
50505053 if (dest_info.bits > 128) {
50515054 return func.fail("TODO: intFromFloat for integers/floats with bitsize {}", .{dest_info.bits});
......@@ -5082,12 +5085,12 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50825085
50835086fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50845087 const pt = func.pt;
5085 const mod = pt.zcu;
5088 const zcu = pt.zcu;
50865089 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50875090
50885091 const operand = try func.resolveInst(ty_op.operand);
50895092 const op_ty = func.typeOf(ty_op.operand);
5090 const op_info = op_ty.intInfo(mod);
5093 const op_info = op_ty.intInfo(zcu);
50915094
50925095 const dest_ty = func.typeOfIndex(inst);
50935096 const dest_bits = dest_ty.floatBits(func.target.*);
......@@ -5127,19 +5130,19 @@ fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51275130
51285131fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51295132 const pt = func.pt;
5130 const mod = pt.zcu;
5133 const zcu = pt.zcu;
51315134 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
51325135 const operand = try func.resolveInst(ty_op.operand);
51335136 const ty = func.typeOfIndex(inst);
5134 const elem_ty = ty.childType(mod);
5137 const elem_ty = ty.childType(zcu);
51355138
5136 if (determineSimdStoreStrategy(ty, pt, func.target.*) == .direct) blk: {
5139 if (determineSimdStoreStrategy(ty, zcu, func.target.*) == .direct) blk: {
51375140 switch (operand) {
51385141 // when the operand lives in the linear memory section, we can directly
51395142 // load and splat the value at once. Meaning we do not first have to load
51405143 // the scalar value onto the stack.
51415144 .stack_offset, .memory, .memory_offset => {
5142 const opcode = switch (elem_ty.bitSize(pt)) {
5145 const opcode = switch (elem_ty.bitSize(zcu)) {
51435146 8 => std.wasm.simdOpcode(.v128_load8_splat),
51445147 16 => std.wasm.simdOpcode(.v128_load16_splat),
51455148 32 => std.wasm.simdOpcode(.v128_load32_splat),
......@@ -5153,17 +5156,17 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51535156 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
51545157 opcode,
51555158 operand.offset(),
5156 @intCast(elem_ty.abiAlignment(pt).toByteUnits().?),
5159 @intCast(elem_ty.abiAlignment(zcu).toByteUnits().?),
51575160 });
51585161 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
51595162 return func.finishAir(inst, .stack, &.{ty_op.operand});
51605163 },
51615164 .local => {
5162 const opcode = switch (elem_ty.bitSize(pt)) {
5165 const opcode = switch (elem_ty.bitSize(zcu)) {
51635166 8 => std.wasm.simdOpcode(.i8x16_splat),
51645167 16 => std.wasm.simdOpcode(.i16x8_splat),
5165 32 => if (elem_ty.isInt(mod)) std.wasm.simdOpcode(.i32x4_splat) else std.wasm.simdOpcode(.f32x4_splat),
5166 64 => if (elem_ty.isInt(mod)) std.wasm.simdOpcode(.i64x2_splat) else std.wasm.simdOpcode(.f64x2_splat),
5168 32 => if (elem_ty.isInt(zcu)) std.wasm.simdOpcode(.i32x4_splat) else std.wasm.simdOpcode(.f32x4_splat),
5169 64 => if (elem_ty.isInt(zcu)) std.wasm.simdOpcode(.i64x2_splat) else std.wasm.simdOpcode(.f64x2_splat),
51675170 else => break :blk, // Cannot make use of simd-instructions
51685171 };
51695172 try func.emitWValue(operand);
......@@ -5175,14 +5178,14 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51755178 else => unreachable,
51765179 }
51775180 }
5178 const elem_size = elem_ty.bitSize(pt);
5179 const vector_len = @as(usize, @intCast(ty.vectorLen(mod)));
5181 const elem_size = elem_ty.bitSize(zcu);
5182 const vector_len = @as(usize, @intCast(ty.vectorLen(zcu)));
51805183 if ((!std.math.isPowerOfTwo(elem_size) or elem_size % 8 != 0) and vector_len > 1) {
51815184 return func.fail("TODO: WebAssembly `@splat` for arbitrary element bitsize {d}", .{elem_size});
51825185 }
51835186
51845187 const result = try func.allocStack(ty);
5185 const elem_byte_size = @as(u32, @intCast(elem_ty.abiSize(pt)));
5188 const elem_byte_size = @as(u32, @intCast(elem_ty.abiSize(zcu)));
51865189 var index: usize = 0;
51875190 var offset: u32 = 0;
51885191 while (index < vector_len) : (index += 1) {
......@@ -5203,7 +5206,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52035206
52045207fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52055208 const pt = func.pt;
5206 const mod = pt.zcu;
5209 const zcu = pt.zcu;
52075210 const inst_ty = func.typeOfIndex(inst);
52085211 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
52095212 const extra = func.air.extraData(Air.Shuffle, ty_pl.payload).data;
......@@ -5213,15 +5216,15 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52135216 const mask = Value.fromInterned(extra.mask);
52145217 const mask_len = extra.mask_len;
52155218
5216 const child_ty = inst_ty.childType(mod);
5217 const elem_size = child_ty.abiSize(pt);
5219 const child_ty = inst_ty.childType(zcu);
5220 const elem_size = child_ty.abiSize(zcu);
52185221
52195222 // TODO: One of them could be by ref; handle in loop
52205223 if (isByRef(func.typeOf(extra.a), pt, func.target.*) or isByRef(inst_ty, pt, func.target.*)) {
52215224 const result = try func.allocStack(inst_ty);
52225225
52235226 for (0..mask_len) |index| {
5224 const value = (try mask.elemValue(pt, index)).toSignedInt(pt);
5227 const value = (try mask.elemValue(pt, index)).toSignedInt(zcu);
52255228
52265229 try func.emitWValue(result);
52275230
......@@ -5241,7 +5244,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52415244
52425245 var lanes = mem.asBytes(operands[1..]);
52435246 for (0..@as(usize, @intCast(mask_len))) |index| {
5244 const mask_elem = (try mask.elemValue(pt, index)).toSignedInt(pt);
5247 const mask_elem = (try mask.elemValue(pt, index)).toSignedInt(zcu);
52455248 const base_index = if (mask_elem >= 0)
52465249 @as(u8, @intCast(@as(i64, @intCast(elem_size)) * mask_elem))
52475250 else
......@@ -5273,20 +5276,20 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52735276
52745277fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52755278 const pt = func.pt;
5276 const mod = pt.zcu;
5277 const ip = &mod.intern_pool;
5279 const zcu = pt.zcu;
5280 const ip = &zcu.intern_pool;
52785281 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
52795282 const result_ty = func.typeOfIndex(inst);
5280 const len = @as(usize, @intCast(result_ty.arrayLen(mod)));
5283 const len = @as(usize, @intCast(result_ty.arrayLen(zcu)));
52815284 const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len]));
52825285
52835286 const result: WValue = result_value: {
5284 switch (result_ty.zigTypeTag(mod)) {
5287 switch (result_ty.zigTypeTag(zcu)) {
52855288 .Array => {
52865289 const result = try func.allocStack(result_ty);
5287 const elem_ty = result_ty.childType(mod);
5288 const elem_size = @as(u32, @intCast(elem_ty.abiSize(pt)));
5289 const sentinel = if (result_ty.sentinel(mod)) |sent| blk: {
5290 const elem_ty = result_ty.childType(zcu);
5291 const elem_size = @as(u32, @intCast(elem_ty.abiSize(zcu)));
5292 const sentinel = if (result_ty.sentinel(zcu)) |sent| blk: {
52905293 break :blk try func.lowerConstant(sent, elem_ty);
52915294 } else null;
52925295
......@@ -5321,18 +5324,18 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53215324 }
53225325 break :result_value result;
53235326 },
5324 .Struct => switch (result_ty.containerLayout(mod)) {
5327 .Struct => switch (result_ty.containerLayout(zcu)) {
53255328 .@"packed" => {
53265329 if (isByRef(result_ty, pt, func.target.*)) {
53275330 return func.fail("TODO: airAggregateInit for packed structs larger than 64 bits", .{});
53285331 }
5329 const packed_struct = mod.typeToPackedStruct(result_ty).?;
5332 const packed_struct = zcu.typeToPackedStruct(result_ty).?;
53305333 const field_types = packed_struct.field_types;
53315334 const backing_type = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
53325335
53335336 // ensure the result is zero'd
53345337 const result = try func.allocLocal(backing_type);
5335 if (backing_type.bitSize(pt) <= 32)
5338 if (backing_type.bitSize(zcu) <= 32)
53365339 try func.addImm32(0)
53375340 else
53385341 try func.addImm64(0);
......@@ -5341,15 +5344,15 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53415344 var current_bit: u16 = 0;
53425345 for (elements, 0..) |elem, elem_index| {
53435346 const field_ty = Type.fromInterned(field_types.get(ip)[elem_index]);
5344 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
5347 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
53455348
5346 const shift_val: WValue = if (backing_type.bitSize(pt) <= 32)
5349 const shift_val: WValue = if (backing_type.bitSize(zcu) <= 32)
53475350 .{ .imm32 = current_bit }
53485351 else
53495352 .{ .imm64 = current_bit };
53505353
53515354 const value = try func.resolveInst(elem);
5352 const value_bit_size: u16 = @intCast(field_ty.bitSize(pt));
5355 const value_bit_size: u16 = @intCast(field_ty.bitSize(zcu));
53535356 const int_ty = try pt.intType(.unsigned, value_bit_size);
53545357
53555358 // load our current result on stack so we can perform all transformations
......@@ -5375,8 +5378,8 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53755378 for (elements, 0..) |elem, elem_index| {
53765379 if (try result_ty.structFieldValueComptime(pt, elem_index) != null) continue;
53775380
5378 const elem_ty = result_ty.structFieldType(elem_index, mod);
5379 const field_offset = result_ty.structFieldOffset(elem_index, pt);
5381 const elem_ty = result_ty.structFieldType(elem_index, zcu);
5382 const field_offset = result_ty.structFieldOffset(elem_index, zcu);
53805383 _ = try func.buildPointerOffset(offset, @intCast(field_offset - prev_field_offset), .modify);
53815384 prev_field_offset = field_offset;
53825385
......@@ -5404,21 +5407,21 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54045407
54055408fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54065409 const pt = func.pt;
5407 const mod = pt.zcu;
5408 const ip = &mod.intern_pool;
5410 const zcu = pt.zcu;
5411 const ip = &zcu.intern_pool;
54095412 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
54105413 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;
54115414
54125415 const result = result: {
54135416 const union_ty = func.typeOfIndex(inst);
5414 const layout = union_ty.unionGetLayout(pt);
5415 const union_obj = mod.typeToUnion(union_ty).?;
5417 const layout = union_ty.unionGetLayout(zcu);
5418 const union_obj = zcu.typeToUnion(union_ty).?;
54165419 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
54175420 const field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];
54185421
54195422 const tag_int = blk: {
5420 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
5421 const enum_field_index = tag_ty.enumFieldIndex(field_name, mod).?;
5423 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
5424 const enum_field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
54225425 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);
54235426 break :blk try func.lowerConstant(tag_val, tag_ty);
54245427 };
......@@ -5458,13 +5461,13 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54585461 break :result result_ptr;
54595462 } else {
54605463 const operand = try func.resolveInst(extra.init);
5461 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(union_ty.bitSize(pt))));
5462 if (field_ty.zigTypeTag(mod) == .Float) {
5463 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(pt)));
5464 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(union_ty.bitSize(zcu))));
5465 if (field_ty.zigTypeTag(zcu) == .Float) {
5466 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(zcu)));
54645467 const bitcasted = try func.bitcast(field_ty, int_type, operand);
54655468 break :result try func.trunc(bitcasted, int_type, union_int_type);
5466 } else if (field_ty.isPtrAtRuntime(mod)) {
5467 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(pt)));
5469 } else if (field_ty.isPtrAtRuntime(zcu)) {
5470 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(zcu)));
54685471 break :result try func.intcast(operand, int_type, union_int_type);
54695472 }
54705473 break :result try func.intcast(operand, field_ty, union_int_type);
......@@ -5497,10 +5500,10 @@ fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {
54975500
54985501fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {
54995502 const pt = func.pt;
5500 const mod = pt.zcu;
5501 assert(operand_ty.hasRuntimeBitsIgnoreComptime(pt));
5503 const zcu = pt.zcu;
5504 assert(operand_ty.hasRuntimeBitsIgnoreComptime(zcu));
55025505 assert(op == .eq or op == .neq);
5503 const payload_ty = operand_ty.optionalChild(mod);
5506 const payload_ty = operand_ty.optionalChild(zcu);
55045507
55055508 // We store the final result in here that will be validated
55065509 // if the optional is truly equal.
......@@ -5534,11 +5537,11 @@ fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op:
55345537/// TODO: Lower this to compiler_rt call when bitsize > 128
55355538fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {
55365539 const pt = func.pt;
5537 const mod = pt.zcu;
5538 assert(operand_ty.abiSize(pt) >= 16);
5540 const zcu = pt.zcu;
5541 assert(operand_ty.abiSize(zcu) >= 16);
55395542 assert(!(lhs != .stack and rhs == .stack));
5540 if (operand_ty.bitSize(pt) > 128) {
5541 return func.fail("TODO: Support cmpBigInt for integer bitsize: '{d}'", .{operand_ty.bitSize(pt)});
5543 if (operand_ty.bitSize(zcu) > 128) {
5544 return func.fail("TODO: Support cmpBigInt for integer bitsize: '{d}'", .{operand_ty.bitSize(zcu)});
55425545 }
55435546
55445547 var lhs_msb = try (try func.load(lhs, Type.u64, 8)).toLocal(func, Type.u64);
......@@ -5561,7 +5564,7 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std
55615564 }
55625565 },
55635566 else => {
5564 const ty = if (operand_ty.isSignedInt(mod)) Type.i64 else Type.u64;
5567 const ty = if (operand_ty.isSignedInt(zcu)) Type.i64 else Type.u64;
55655568 // leave those value on top of the stack for '.select'
55665569 const lhs_lsb = try func.load(lhs, Type.u64, 0);
55675570 const rhs_lsb = try func.load(rhs, Type.u64, 0);
......@@ -5577,11 +5580,11 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std
55775580
55785581fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55795582 const pt = func.pt;
5580 const mod = pt.zcu;
5583 const zcu = pt.zcu;
55815584 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5582 const un_ty = func.typeOf(bin_op.lhs).childType(mod);
5585 const un_ty = func.typeOf(bin_op.lhs).childType(zcu);
55835586 const tag_ty = func.typeOf(bin_op.rhs);
5584 const layout = un_ty.unionGetLayout(pt);
5587 const layout = un_ty.unionGetLayout(zcu);
55855588 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
55865589
55875590 const union_ptr = try func.resolveInst(bin_op.lhs);
......@@ -5601,12 +5604,12 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
56015604}
56025605
56035606fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5604 const pt = func.pt;
5607 const zcu = func.pt.zcu;
56055608 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56065609
56075610 const un_ty = func.typeOf(ty_op.operand);
56085611 const tag_ty = func.typeOfIndex(inst);
5609 const layout = un_ty.unionGetLayout(pt);
5612 const layout = un_ty.unionGetLayout(zcu);
56105613 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ty_op.operand});
56115614
56125615 const operand = try func.resolveInst(ty_op.operand);
......@@ -5705,11 +5708,11 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
57055708
57065709fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57075710 const pt = func.pt;
5708 const mod = pt.zcu;
5711 const zcu = pt.zcu;
57095712 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57105713
5711 const err_set_ty = func.typeOf(ty_op.operand).childType(mod);
5712 const payload_ty = err_set_ty.errorUnionPayload(mod);
5714 const err_set_ty = func.typeOf(ty_op.operand).childType(zcu);
5715 const payload_ty = err_set_ty.errorUnionPayload(zcu);
57135716 const operand = try func.resolveInst(ty_op.operand);
57145717
57155718 // set error-tag to '0' to annotate error union is non-error
......@@ -5717,28 +5720,28 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
57175720 operand,
57185721 .{ .imm32 = 0 },
57195722 Type.anyerror,
5720 @intCast(errUnionErrorOffset(payload_ty, pt)),
5723 @intCast(errUnionErrorOffset(payload_ty, zcu)),
57215724 );
57225725
57235726 const result = result: {
5724 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5727 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
57255728 break :result func.reuseOperand(ty_op.operand, operand);
57265729 }
57275730
5728 break :result try func.buildPointerOffset(operand, @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt))), .new);
5731 break :result try func.buildPointerOffset(operand, @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu))), .new);
57295732 };
57305733 return func.finishAir(inst, result, &.{ty_op.operand});
57315734}
57325735
57335736fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57345737 const pt = func.pt;
5735 const mod = pt.zcu;
5738 const zcu = pt.zcu;
57365739 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
57375740 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
57385741
57395742 const field_ptr = try func.resolveInst(extra.field_ptr);
5740 const parent_ty = ty_pl.ty.toType().childType(mod);
5741 const field_offset = parent_ty.structFieldOffset(extra.field_index, pt);
5743 const parent_ty = ty_pl.ty.toType().childType(zcu);
5744 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
57425745
57435746 const result = if (field_offset != 0) result: {
57445747 const base = try func.buildPointerOffset(field_ptr, 0, .new);
......@@ -5754,8 +5757,8 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57545757
57555758fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue {
57565759 const pt = func.pt;
5757 const mod = pt.zcu;
5758 if (ptr_ty.isSlice(mod)) {
5760 const zcu = pt.zcu;
5761 if (ptr_ty.isSlice(zcu)) {
57595762 return func.slicePtr(ptr);
57605763 } else {
57615764 return ptr;
......@@ -5764,26 +5767,26 @@ fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue
57645767
57655768fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57665769 const pt = func.pt;
5767 const mod = pt.zcu;
5770 const zcu = pt.zcu;
57685771 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
57695772 const dst = try func.resolveInst(bin_op.lhs);
57705773 const dst_ty = func.typeOf(bin_op.lhs);
5771 const ptr_elem_ty = dst_ty.childType(mod);
5774 const ptr_elem_ty = dst_ty.childType(zcu);
57725775 const src = try func.resolveInst(bin_op.rhs);
57735776 const src_ty = func.typeOf(bin_op.rhs);
5774 const len = switch (dst_ty.ptrSize(mod)) {
5777 const len = switch (dst_ty.ptrSize(zcu)) {
57755778 .Slice => blk: {
57765779 const slice_len = try func.sliceLen(dst);
5777 if (ptr_elem_ty.abiSize(pt) != 1) {
5780 if (ptr_elem_ty.abiSize(zcu) != 1) {
57785781 try func.emitWValue(slice_len);
5779 try func.emitWValue(.{ .imm32 = @as(u32, @intCast(ptr_elem_ty.abiSize(pt))) });
5782 try func.emitWValue(.{ .imm32 = @as(u32, @intCast(ptr_elem_ty.abiSize(zcu))) });
57805783 try func.addTag(.i32_mul);
57815784 try func.addLabel(.local_set, slice_len.local.value);
57825785 }
57835786 break :blk slice_len;
57845787 },
57855788 .One => @as(WValue, .{
5786 .imm32 = @as(u32, @intCast(ptr_elem_ty.arrayLen(mod) * ptr_elem_ty.childType(mod).abiSize(pt))),
5789 .imm32 = @as(u32, @intCast(ptr_elem_ty.arrayLen(zcu) * ptr_elem_ty.childType(zcu).abiSize(zcu))),
57875790 }),
57885791 .C, .Many => unreachable,
57895792 };
......@@ -5805,17 +5808,17 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58055808
58065809fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58075810 const pt = func.pt;
5808 const mod = pt.zcu;
5811 const zcu = pt.zcu;
58095812 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58105813
58115814 const operand = try func.resolveInst(ty_op.operand);
58125815 const op_ty = func.typeOf(ty_op.operand);
58135816
5814 if (op_ty.zigTypeTag(mod) == .Vector) {
5817 if (op_ty.zigTypeTag(zcu) == .Vector) {
58155818 return func.fail("TODO: Implement @popCount for vectors", .{});
58165819 }
58175820
5818 const int_info = op_ty.intInfo(mod);
5821 const int_info = op_ty.intInfo(zcu);
58195822 const bits = int_info.bits;
58205823 const wasm_bits = toWasmBits(bits) orelse {
58215824 return func.fail("TODO: Implement @popCount for integers with bitsize '{d}'", .{bits});
......@@ -5824,14 +5827,14 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58245827 switch (wasm_bits) {
58255828 32 => {
58265829 try func.emitWValue(operand);
5827 if (op_ty.isSignedInt(mod) and bits != wasm_bits) {
5830 if (op_ty.isSignedInt(zcu) and bits != wasm_bits) {
58285831 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits));
58295832 }
58305833 try func.addTag(.i32_popcnt);
58315834 },
58325835 64 => {
58335836 try func.emitWValue(operand);
5834 if (op_ty.isSignedInt(mod) and bits != wasm_bits) {
5837 if (op_ty.isSignedInt(zcu) and bits != wasm_bits) {
58355838 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits));
58365839 }
58375840 try func.addTag(.i64_popcnt);
......@@ -5842,7 +5845,7 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58425845 _ = try func.load(operand, Type.u64, 0);
58435846 try func.addTag(.i64_popcnt);
58445847 _ = try func.load(operand, Type.u64, 8);
5845 if (op_ty.isSignedInt(mod) and bits != wasm_bits) {
5848 if (op_ty.isSignedInt(zcu) and bits != wasm_bits) {
58465849 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits - 64));
58475850 }
58485851 try func.addTag(.i64_popcnt);
......@@ -5857,17 +5860,17 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58575860
58585861fn airBitReverse(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58595862 const pt = func.pt;
5860 const mod = pt.zcu;
5863 const zcu = pt.zcu;
58615864 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58625865
58635866 const operand = try func.resolveInst(ty_op.operand);
58645867 const ty = func.typeOf(ty_op.operand);
58655868
5866 if (ty.zigTypeTag(mod) == .Vector) {
5869 if (ty.zigTypeTag(zcu) == .Vector) {
58675870 return func.fail("TODO: Implement @bitReverse for vectors", .{});
58685871 }
58695872
5870 const int_info = ty.intInfo(mod);
5873 const int_info = ty.intInfo(zcu);
58715874 const bits = int_info.bits;
58725875 const wasm_bits = toWasmBits(bits) orelse {
58735876 return func.fail("TODO: Implement @bitReverse for integers with bitsize '{d}'", .{bits});
......@@ -5933,7 +5936,7 @@ fn airBitReverse(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59335936 defer tmp.free(func);
59345937 try func.addLabel(.local_tee, tmp.local.value);
59355938 try func.emitWValue(.{ .imm64 = 128 - bits });
5936 if (ty.isSignedInt(mod)) {
5939 if (ty.isSignedInt(zcu)) {
59375940 try func.addTag(.i64_shr_s);
59385941 } else {
59395942 try func.addTag(.i64_shr_u);
......@@ -5969,7 +5972,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59695972 const pt = func.pt;
59705973 const error_table_symbol = try func.bin_file.getErrorTableSymbol(pt);
59715974 const name_ty = Type.slice_const_u8_sentinel_0;
5972 const abi_size = name_ty.abiSize(pt);
5975 const abi_size = name_ty.abiSize(pt.zcu);
59735976
59745977 const error_name_value: WValue = .{ .memory = error_table_symbol }; // emitting this will create a relocation
59755978 try func.emitWValue(error_name_value);
......@@ -6000,8 +6003,8 @@ fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerE
60006003
60016004/// NOTE: Allocates place for result on virtual stack, when integer size > 64 bits
60026005fn intZeroValue(func: *CodeGen, ty: Type) InnerError!WValue {
6003 const mod = func.bin_file.base.comp.module.?;
6004 const int_info = ty.intInfo(mod);
6006 const zcu = func.bin_file.base.comp.module.?;
6007 const int_info = ty.intInfo(zcu);
60056008 const wasm_bits = toWasmBits(int_info.bits) orelse {
60066009 return func.fail("TODO: Implement intZeroValue for integer bitsize: {d}", .{int_info.bits});
60076010 };
......@@ -6027,13 +6030,13 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
60276030 const rhs = try func.resolveInst(extra.rhs);
60286031 const ty = func.typeOf(extra.lhs);
60296032 const pt = func.pt;
6030 const mod = pt.zcu;
6033 const zcu = pt.zcu;
60316034
6032 if (ty.zigTypeTag(mod) == .Vector) {
6035 if (ty.zigTypeTag(zcu) == .Vector) {
60336036 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});
60346037 }
60356038
6036 const int_info = ty.intInfo(mod);
6039 const int_info = ty.intInfo(zcu);
60376040 const is_signed = int_info.signedness == .signed;
60386041 if (int_info.bits > 128) {
60396042 return func.fail("TODO: Implement {{add/sub}}_with_overflow for integer bitsize: {d}", .{int_info.bits});
......@@ -6058,7 +6061,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
60586061 defer bit_tmp.free(func);
60596062
60606063 const result = try func.allocStack(func.typeOfIndex(inst));
6061 const offset: u32 = @intCast(ty.abiSize(pt));
6064 const offset: u32 = @intCast(ty.abiSize(zcu));
60626065 try func.store(result, op_tmp, ty, 0);
60636066 try func.store(result, bit_tmp, Type.u1, offset);
60646067
......@@ -6067,7 +6070,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
60676070
60686071fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60696072 const pt = func.pt;
6070 const mod = pt.zcu;
6073 const zcu = pt.zcu;
60716074 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
60726075 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
60736076
......@@ -6076,18 +6079,18 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
60766079 const ty = func.typeOf(extra.lhs);
60776080 const rhs_ty = func.typeOf(extra.rhs);
60786081
6079 if (ty.zigTypeTag(mod) == .Vector) {
6082 if (ty.zigTypeTag(zcu) == .Vector) {
60806083 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});
60816084 }
60826085
6083 const int_info = ty.intInfo(mod);
6086 const int_info = ty.intInfo(zcu);
60846087 const wasm_bits = toWasmBits(int_info.bits) orelse {
60856088 return func.fail("TODO: Implement shl_with_overflow for integer bitsize: {d}", .{int_info.bits});
60866089 };
60876090
60886091 // Ensure rhs is coerced to lhs as they must have the same WebAssembly types
60896092 // before we can perform any binary operation.
6090 const rhs_wasm_bits = toWasmBits(rhs_ty.intInfo(mod).bits).?;
6093 const rhs_wasm_bits = toWasmBits(rhs_ty.intInfo(zcu).bits).?;
60916094 // If wasm_bits == 128, compiler-rt expects i32 for shift
60926095 const rhs_final = if (wasm_bits != rhs_wasm_bits and wasm_bits == 64) blk: {
60936096 const rhs_casted = try func.intcast(rhs, rhs_ty, ty);
......@@ -6105,7 +6108,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61056108 defer overflow_local.free(func);
61066109
61076110 const result = try func.allocStack(func.typeOfIndex(inst));
6108 const offset: u32 = @intCast(ty.abiSize(pt));
6111 const offset: u32 = @intCast(ty.abiSize(zcu));
61096112 try func.store(result, shl, ty, 0);
61106113 try func.store(result, overflow_local, Type.u1, offset);
61116114
......@@ -6120,9 +6123,9 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61206123 const rhs = try func.resolveInst(extra.rhs);
61216124 const ty = func.typeOf(extra.lhs);
61226125 const pt = func.pt;
6123 const mod = pt.zcu;
6126 const zcu = pt.zcu;
61246127
6125 if (ty.zigTypeTag(mod) == .Vector) {
6128 if (ty.zigTypeTag(zcu) == .Vector) {
61266129 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});
61276130 }
61286131
......@@ -6131,7 +6134,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61316134 var overflow_bit = try func.ensureAllocLocal(Type.u1);
61326135 defer overflow_bit.free(func);
61336136
6134 const int_info = ty.intInfo(mod);
6137 const int_info = ty.intInfo(zcu);
61356138 const wasm_bits = toWasmBits(int_info.bits) orelse {
61366139 return func.fail("TODO: Implement `@mulWithOverflow` for integer bitsize: {d}", .{int_info.bits});
61376140 };
......@@ -6238,7 +6241,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
62386241 defer bin_op_local.free(func);
62396242
62406243 const result = try func.allocStack(func.typeOfIndex(inst));
6241 const offset: u32 = @intCast(ty.abiSize(pt));
6244 const offset: u32 = @intCast(ty.abiSize(zcu));
62426245 try func.store(result, bin_op_local, ty, 0);
62436246 try func.store(result, overflow_bit, Type.u1, offset);
62446247
......@@ -6248,22 +6251,22 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
62486251fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
62496252 assert(op == .max or op == .min);
62506253 const pt = func.pt;
6251 const mod = pt.zcu;
6254 const zcu = pt.zcu;
62526255 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
62536256
62546257 const ty = func.typeOfIndex(inst);
6255 if (ty.zigTypeTag(mod) == .Vector) {
6258 if (ty.zigTypeTag(zcu) == .Vector) {
62566259 return func.fail("TODO: `@maximum` and `@minimum` for vectors", .{});
62576260 }
62586261
6259 if (ty.abiSize(pt) > 16) {
6262 if (ty.abiSize(zcu) > 16) {
62606263 return func.fail("TODO: `@maximum` and `@minimum` for types larger than 16 bytes", .{});
62616264 }
62626265
62636266 const lhs = try func.resolveInst(bin_op.lhs);
62646267 const rhs = try func.resolveInst(bin_op.rhs);
62656268
6266 if (ty.zigTypeTag(mod) == .Float) {
6269 if (ty.zigTypeTag(zcu) == .Float) {
62676270 var fn_name_buf: [64]u8 = undefined;
62686271 const float_bits = ty.floatBits(func.target.*);
62696272 const fn_name = std.fmt.bufPrint(&fn_name_buf, "{s}f{s}{s}", .{
......@@ -6288,12 +6291,12 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
62886291
62896292fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
62906293 const pt = func.pt;
6291 const mod = pt.zcu;
6294 const zcu = pt.zcu;
62926295 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
62936296 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
62946297
62956298 const ty = func.typeOfIndex(inst);
6296 if (ty.zigTypeTag(mod) == .Vector) {
6299 if (ty.zigTypeTag(zcu) == .Vector) {
62976300 return func.fail("TODO: `@mulAdd` for vectors", .{});
62986301 }
62996302
......@@ -6323,16 +6326,16 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63236326
63246327fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63256328 const pt = func.pt;
6326 const mod = pt.zcu;
6329 const zcu = pt.zcu;
63276330 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63286331
63296332 const ty = func.typeOf(ty_op.operand);
6330 if (ty.zigTypeTag(mod) == .Vector) {
6333 if (ty.zigTypeTag(zcu) == .Vector) {
63316334 return func.fail("TODO: `@clz` for vectors", .{});
63326335 }
63336336
63346337 const operand = try func.resolveInst(ty_op.operand);
6335 const int_info = ty.intInfo(mod);
6338 const int_info = ty.intInfo(zcu);
63366339 const wasm_bits = toWasmBits(int_info.bits) orelse {
63376340 return func.fail("TODO: `@clz` for integers with bitsize '{d}'", .{int_info.bits});
63386341 };
......@@ -6374,17 +6377,17 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63746377
63756378fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63766379 const pt = func.pt;
6377 const mod = pt.zcu;
6380 const zcu = pt.zcu;
63786381 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63796382
63806383 const ty = func.typeOf(ty_op.operand);
63816384
6382 if (ty.zigTypeTag(mod) == .Vector) {
6385 if (ty.zigTypeTag(zcu) == .Vector) {
63836386 return func.fail("TODO: `@ctz` for vectors", .{});
63846387 }
63856388
63866389 const operand = try func.resolveInst(ty_op.operand);
6387 const int_info = ty.intInfo(mod);
6390 const int_info = ty.intInfo(zcu);
63886391 const wasm_bits = toWasmBits(int_info.bits) orelse {
63896392 return func.fail("TODO: `@clz` for integers with bitsize '{d}'", .{int_info.bits});
63906393 };
......@@ -6497,12 +6500,12 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64976500
64986501fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64996502 const pt = func.pt;
6500 const mod = pt.zcu;
6503 const zcu = pt.zcu;
65016504 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
65026505 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);
65036506 const err_union_ptr = try func.resolveInst(extra.data.ptr);
65046507 const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]);
6505 const err_union_ty = func.typeOf(extra.data.ptr).childType(mod);
6508 const err_union_ty = func.typeOf(extra.data.ptr).childType(zcu);
65066509 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);
65076510 return func.finishAir(inst, result, &.{extra.data.ptr});
65086511}
......@@ -6516,25 +6519,25 @@ fn lowerTry(
65166519 operand_is_ptr: bool,
65176520) InnerError!WValue {
65186521 const pt = func.pt;
6519 const mod = pt.zcu;
6522 const zcu = pt.zcu;
65206523 if (operand_is_ptr) {
65216524 return func.fail("TODO: lowerTry for pointers", .{});
65226525 }
65236526
6524 const pl_ty = err_union_ty.errorUnionPayload(mod);
6525 const pl_has_bits = pl_ty.hasRuntimeBitsIgnoreComptime(pt);
6527 const pl_ty = err_union_ty.errorUnionPayload(zcu);
6528 const pl_has_bits = pl_ty.hasRuntimeBitsIgnoreComptime(zcu);
65266529
6527 if (!err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
6530 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
65286531 // Block we can jump out of when error is not set
65296532 try func.startBlock(.block, wasm.block_empty);
65306533
65316534 // check if the error tag is set for the error union.
65326535 try func.emitWValue(err_union);
65336536 if (pl_has_bits) {
6534 const err_offset: u32 = @intCast(errUnionErrorOffset(pl_ty, pt));
6537 const err_offset: u32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
65356538 try func.addMemArg(.i32_load16_u, .{
65366539 .offset = err_union.offset() + err_offset,
6537 .alignment = @intCast(Type.anyerror.abiAlignment(pt).toByteUnits().?),
6540 .alignment = @intCast(Type.anyerror.abiAlignment(zcu).toByteUnits().?),
65386541 });
65396542 }
65406543 try func.addTag(.i32_eqz);
......@@ -6556,7 +6559,7 @@ fn lowerTry(
65566559 return .none;
65576560 }
65586561
6559 const pl_offset: u32 = @intCast(errUnionPayloadOffset(pl_ty, pt));
6562 const pl_offset: u32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
65606563 if (isByRef(pl_ty, pt, func.target.*)) {
65616564 return buildPointerOffset(func, err_union, pl_offset, .new);
65626565 }
......@@ -6566,16 +6569,16 @@ fn lowerTry(
65666569
65676570fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
65686571 const pt = func.pt;
6569 const mod = pt.zcu;
6572 const zcu = pt.zcu;
65706573 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
65716574
65726575 const ty = func.typeOfIndex(inst);
65736576 const operand = try func.resolveInst(ty_op.operand);
65746577
6575 if (ty.zigTypeTag(mod) == .Vector) {
6578 if (ty.zigTypeTag(zcu) == .Vector) {
65766579 return func.fail("TODO: @byteSwap for vectors", .{});
65776580 }
6578 const int_info = ty.intInfo(mod);
6581 const int_info = ty.intInfo(zcu);
65796582 const wasm_bits = toWasmBits(int_info.bits) orelse {
65806583 return func.fail("TODO: @byteSwap for integers with bitsize {d}", .{int_info.bits});
65816584 };
......@@ -6649,15 +6652,15 @@ fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
66496652 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
66506653
66516654 const pt = func.pt;
6652 const mod = pt.zcu;
6655 const zcu = pt.zcu;
66536656 const ty = func.typeOfIndex(inst);
66546657 const lhs = try func.resolveInst(bin_op.lhs);
66556658 const rhs = try func.resolveInst(bin_op.rhs);
66566659
6657 if (ty.isUnsignedInt(mod)) {
6660 if (ty.isUnsignedInt(zcu)) {
66586661 _ = try func.binOp(lhs, rhs, ty, .div);
6659 } else if (ty.isSignedInt(mod)) {
6660 const int_bits = ty.intInfo(mod).bits;
6662 } else if (ty.isSignedInt(zcu)) {
6663 const int_bits = ty.intInfo(zcu).bits;
66616664 const wasm_bits = toWasmBits(int_bits) orelse {
66626665 return func.fail("TODO: `@divFloor` for signed integers larger than 64 bits ({d} bits requested)", .{int_bits});
66636666 };
......@@ -6767,19 +6770,19 @@ fn airMod(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
67676770 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
67686771
67696772 const pt = func.pt;
6770 const mod = pt.zcu;
6773 const zcu = pt.zcu;
67716774 const ty = func.typeOfIndex(inst);
67726775 const lhs = try func.resolveInst(bin_op.lhs);
67736776 const rhs = try func.resolveInst(bin_op.rhs);
67746777
6775 if (ty.isUnsignedInt(mod)) {
6778 if (ty.isUnsignedInt(zcu)) {
67766779 _ = try func.binOp(lhs, rhs, ty, .rem);
6777 } else if (ty.isSignedInt(mod)) {
6780 } else if (ty.isSignedInt(zcu)) {
67786781 // The wasm rem instruction gives the remainder after truncating division (rounding towards
67796782 // 0), equivalent to @rem.
67806783 // We make use of the fact that:
67816784 // @mod(a, b) = @rem(@rem(a, b) + b, b)
6782 const int_bits = ty.intInfo(mod).bits;
6785 const int_bits = ty.intInfo(zcu).bits;
67836786 const wasm_bits = toWasmBits(int_bits) orelse {
67846787 return func.fail("TODO: `@mod` for signed integers larger than 64 bits ({d} bits requested)", .{int_bits});
67856788 };
......@@ -6802,9 +6805,9 @@ fn airSatMul(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
68026805 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
68036806
68046807 const pt = func.pt;
6805 const mod = pt.zcu;
6808 const zcu = pt.zcu;
68066809 const ty = func.typeOfIndex(inst);
6807 const int_info = ty.intInfo(mod);
6810 const int_info = ty.intInfo(zcu);
68086811 const is_signed = int_info.signedness == .signed;
68096812
68106813 const lhs = try func.resolveInst(bin_op.lhs);
......@@ -6903,12 +6906,12 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
69036906 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
69046907
69056908 const pt = func.pt;
6906 const mod = pt.zcu;
6909 const zcu = pt.zcu;
69076910 const ty = func.typeOfIndex(inst);
69086911 const lhs = try func.resolveInst(bin_op.lhs);
69096912 const rhs = try func.resolveInst(bin_op.rhs);
69106913
6911 const int_info = ty.intInfo(mod);
6914 const int_info = ty.intInfo(zcu);
69126915 const is_signed = int_info.signedness == .signed;
69136916
69146917 if (int_info.bits > 64) {
......@@ -6950,8 +6953,8 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
69506953
69516954fn signedSat(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {
69526955 const pt = func.pt;
6953 const mod = pt.zcu;
6954 const int_info = ty.intInfo(mod);
6956 const zcu = pt.zcu;
6957 const int_info = ty.intInfo(zcu);
69556958 const wasm_bits = toWasmBits(int_info.bits).?;
69566959 const is_wasm_bits = wasm_bits == int_info.bits;
69576960 const ext_ty = if (!is_wasm_bits) try pt.intType(int_info.signedness, wasm_bits) else ty;
......@@ -7009,9 +7012,9 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70097012 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
70107013
70117014 const pt = func.pt;
7012 const mod = pt.zcu;
7015 const zcu = pt.zcu;
70137016 const ty = func.typeOfIndex(inst);
7014 const int_info = ty.intInfo(mod);
7017 const int_info = ty.intInfo(zcu);
70157018 const is_signed = int_info.signedness == .signed;
70167019 if (int_info.bits > 64) {
70177020 return func.fail("TODO: Saturating shifting left for integers with bitsize '{d}'", .{int_info.bits});
......@@ -7130,7 +7133,7 @@ fn callIntrinsic(
71307133
71317134 // Always pass over C-ABI
71327135 const pt = func.pt;
7133 const mod = pt.zcu;
7136 const zcu = pt.zcu;
71347137 var func_type = try genFunctype(func.gpa, .C, param_types, return_type, pt, func.target.*);
71357138 defer func_type.deinit(func.gpa);
71367139 const func_type_index = try func.bin_file.zigObjectPtr().?.putOrGetFuncType(func.gpa, func_type);
......@@ -7148,16 +7151,16 @@ fn callIntrinsic(
71487151 // Lower all arguments to the stack before we call our function
71497152 for (args, 0..) |arg, arg_i| {
71507153 assert(!(want_sret_param and arg == .stack));
7151 assert(Type.fromInterned(param_types[arg_i]).hasRuntimeBitsIgnoreComptime(pt));
7154 assert(Type.fromInterned(param_types[arg_i]).hasRuntimeBitsIgnoreComptime(zcu));
71527155 try func.lowerArg(.C, Type.fromInterned(param_types[arg_i]), arg);
71537156 }
71547157
71557158 // Actually call our intrinsic
71567159 try func.addLabel(.call, @intFromEnum(symbol_index));
71577160
7158 if (!return_type.hasRuntimeBitsIgnoreComptime(pt)) {
7161 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
71597162 return .none;
7160 } else if (return_type.isNoReturn(mod)) {
7163 } else if (return_type.isNoReturn(zcu)) {
71617164 try func.addTag(.@"unreachable");
71627165 return .none;
71637166 } else if (want_sret_param) {
......@@ -7184,8 +7187,8 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
71847187
71857188fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
71867189 const pt = func.pt;
7187 const mod = pt.zcu;
7188 const ip = &mod.intern_pool;
7190 const zcu = pt.zcu;
7191 const ip = &zcu.intern_pool;
71897192
71907193 var arena_allocator = std.heap.ArenaAllocator.init(func.gpa);
71917194 defer arena_allocator.deinit();
......@@ -7198,9 +7201,9 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
71987201 return @intFromEnum(loc.index);
71997202 }
72007203
7201 const int_tag_ty = enum_ty.intTagType(mod);
7204 const int_tag_ty = enum_ty.intTagType(zcu);
72027205
7203 if (int_tag_ty.bitSize(pt) > 64) {
7206 if (int_tag_ty.bitSize(zcu) > 64) {
72047207 return func.fail("TODO: Implement @tagName for enums with tag size larger than 64 bits", .{});
72057208 }
72067209
......@@ -7220,7 +7223,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
72207223
72217224 // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse.
72227225 // generate an if-else chain for each tag value as well as constant.
7223 const tag_names = enum_ty.enumFields(mod);
7226 const tag_names = enum_ty.enumFields(zcu);
72247227 for (0..tag_names.len) |tag_index| {
72257228 const tag_name = tag_names.get(ip)[tag_index];
72267229 const tag_name_len = tag_name.length(ip);
......@@ -7345,15 +7348,15 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73457348
73467349fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73477350 const pt = func.pt;
7348 const mod = pt.zcu;
7349 const ip = &mod.intern_pool;
7351 const zcu = pt.zcu;
7352 const ip = &zcu.intern_pool;
73507353 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73517354
73527355 const operand = try func.resolveInst(ty_op.operand);
73537356 const error_set_ty = ty_op.ty.toType();
73547357 const result = try func.allocLocal(Type.bool);
73557358
7356 const names = error_set_ty.errorSetNames(mod);
7359 const names = error_set_ty.errorSetNames(zcu);
73577360 var values = try std.ArrayList(u32).initCapacity(func.gpa, names.len);
73587361 defer values.deinit();
73597362
......@@ -7432,12 +7435,12 @@ inline fn useAtomicFeature(func: *const CodeGen) bool {
74327435
74337436fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
74347437 const pt = func.pt;
7435 const mod = pt.zcu;
7438 const zcu = pt.zcu;
74367439 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
74377440 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
74387441
74397442 const ptr_ty = func.typeOf(extra.ptr);
7440 const ty = ptr_ty.childType(mod);
7443 const ty = ptr_ty.childType(zcu);
74417444 const result_ty = func.typeOfIndex(inst);
74427445
74437446 const ptr_operand = try func.resolveInst(extra.ptr);
......@@ -7451,7 +7454,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
74517454 try func.emitWValue(ptr_operand);
74527455 try func.lowerToStack(expected_val);
74537456 try func.lowerToStack(new_val);
7454 try func.addAtomicMemArg(switch (ty.abiSize(pt)) {
7457 try func.addAtomicMemArg(switch (ty.abiSize(zcu)) {
74557458 1 => .i32_atomic_rmw8_cmpxchg_u,
74567459 2 => .i32_atomic_rmw16_cmpxchg_u,
74577460 4 => .i32_atomic_rmw_cmpxchg,
......@@ -7459,14 +7462,14 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
74597462 else => |size| return func.fail("TODO: implement `@cmpxchg` for types with abi size '{d}'", .{size}),
74607463 }, .{
74617464 .offset = ptr_operand.offset(),
7462 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),
7465 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
74637466 });
74647467 try func.addLabel(.local_tee, val_local.local.value);
74657468 _ = try func.cmp(.stack, expected_val, ty, .eq);
74667469 try func.addLabel(.local_set, cmp_result.local.value);
74677470 break :val val_local;
74687471 } else val: {
7469 if (ty.abiSize(pt) > 8) {
7472 if (ty.abiSize(zcu) > 8) {
74707473 return func.fail("TODO: Implement `@cmpxchg` for types larger than abi size of 8 bytes", .{});
74717474 }
74727475 const ptr_val = try WValue.toLocal(try func.load(ptr_operand, ty, 0), func, ty);
......@@ -7490,7 +7493,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
74907493 try func.addTag(.i32_and);
74917494 const and_result = try WValue.toLocal(.stack, func, Type.bool);
74927495 const result_ptr = try func.allocStack(result_ty);
7493 try func.store(result_ptr, and_result, Type.bool, @as(u32, @intCast(ty.abiSize(pt))));
7496 try func.store(result_ptr, and_result, Type.bool, @as(u32, @intCast(ty.abiSize(zcu))));
74947497 try func.store(result_ptr, ptr_val, ty, 0);
74957498 break :val result_ptr;
74967499 } else val: {
......@@ -7511,7 +7514,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75117514 const ty = func.typeOfIndex(inst);
75127515
75137516 if (func.useAtomicFeature()) {
7514 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt)) {
7517 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt.zcu)) {
75157518 1 => .i32_atomic_load8_u,
75167519 2 => .i32_atomic_load16_u,
75177520 4 => .i32_atomic_load,
......@@ -7521,7 +7524,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75217524 try func.emitWValue(ptr);
75227525 try func.addAtomicMemArg(tag, .{
75237526 .offset = ptr.offset(),
7524 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),
7527 .alignment = @intCast(ty.abiAlignment(pt.zcu).toByteUnits().?),
75257528 });
75267529 } else {
75277530 _ = try func.load(ptr, ty, 0);
......@@ -7532,7 +7535,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75327535
75337536fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75347537 const pt = func.pt;
7535 const mod = pt.zcu;
7538 const zcu = pt.zcu;
75367539 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
75377540 const extra = func.air.extraData(Air.AtomicRmw, pl_op.payload).data;
75387541
......@@ -7556,7 +7559,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75567559 try func.emitWValue(ptr);
75577560 try func.emitWValue(value);
75587561 if (op == .Nand) {
7559 const wasm_bits = toWasmBits(@intCast(ty.bitSize(pt))).?;
7562 const wasm_bits = toWasmBits(@intCast(ty.bitSize(zcu))).?;
75607563
75617564 const and_res = try func.binOp(value, operand, ty, .@"and");
75627565 if (wasm_bits == 32)
......@@ -7573,7 +7576,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75737576 try func.addTag(.select);
75747577 }
75757578 try func.addAtomicMemArg(
7576 switch (ty.abiSize(pt)) {
7579 switch (ty.abiSize(zcu)) {
75777580 1 => .i32_atomic_rmw8_cmpxchg_u,
75787581 2 => .i32_atomic_rmw16_cmpxchg_u,
75797582 4 => .i32_atomic_rmw_cmpxchg,
......@@ -7582,7 +7585,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75827585 },
75837586 .{
75847587 .offset = ptr.offset(),
7585 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),
7588 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
75867589 },
75877590 );
75887591 const select_res = try func.allocLocal(ty);
......@@ -7601,7 +7604,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
76017604 else => {
76027605 try func.emitWValue(ptr);
76037606 try func.emitWValue(operand);
7604 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt)) {
7607 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(zcu)) {
76057608 1 => switch (op) {
76067609 .Xchg => .i32_atomic_rmw8_xchg_u,
76077610 .Add => .i32_atomic_rmw8_add_u,
......@@ -7642,7 +7645,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
76427645 };
76437646 try func.addAtomicMemArg(tag, .{
76447647 .offset = ptr.offset(),
7645 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),
7648 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
76467649 });
76477650 return func.finishAir(inst, .stack, &.{ pl_op.operand, extra.operand });
76487651 },
......@@ -7670,7 +7673,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
76707673 .Xor => .xor,
76717674 else => unreachable,
76727675 });
7673 if (ty.isInt(mod) and (op == .Add or op == .Sub)) {
7676 if (ty.isInt(zcu) and (op == .Add or op == .Sub)) {
76747677 _ = try func.wrapOperand(.stack, ty);
76757678 }
76767679 try func.store(.stack, .stack, ty, ptr.offset());
......@@ -7686,7 +7689,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
76867689 try func.store(.stack, .stack, ty, ptr.offset());
76877690 },
76887691 .Nand => {
7689 const wasm_bits = toWasmBits(@intCast(ty.bitSize(pt))).?;
7692 const wasm_bits = toWasmBits(@intCast(ty.bitSize(zcu))).?;
76907693
76917694 try func.emitWValue(ptr);
76927695 const and_res = try func.binOp(result, operand, ty, .@"and");
......@@ -7721,16 +7724,16 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77217724
77227725fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77237726 const pt = func.pt;
7724 const mod = pt.zcu;
7727 const zcu = pt.zcu;
77257728 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77267729
77277730 const ptr = try func.resolveInst(bin_op.lhs);
77287731 const operand = try func.resolveInst(bin_op.rhs);
77297732 const ptr_ty = func.typeOf(bin_op.lhs);
7730 const ty = ptr_ty.childType(mod);
7733 const ty = ptr_ty.childType(zcu);
77317734
77327735 if (func.useAtomicFeature()) {
7733 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt)) {
7736 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(zcu)) {
77347737 1 => .i32_atomic_store8,
77357738 2 => .i32_atomic_store16,
77367739 4 => .i32_atomic_store,
......@@ -7741,7 +7744,7 @@ fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77417744 try func.lowerToStack(operand);
77427745 try func.addAtomicMemArg(tag, .{
77437746 .offset = ptr.offset(),
7744 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),
7747 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
77457748 });
77467749 } else {
77477750 try func.store(ptr, operand, ty, 0);
......@@ -7760,12 +7763,12 @@ fn airFrameAddress(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77607763
77617764fn typeOf(func: *CodeGen, inst: Air.Inst.Ref) Type {
77627765 const pt = func.pt;
7763 const mod = pt.zcu;
7764 return func.air.typeOf(inst, &mod.intern_pool);
7766 const zcu = pt.zcu;
7767 return func.air.typeOf(inst, &zcu.intern_pool);
77657768}
77667769
77677770fn typeOfIndex(func: *CodeGen, inst: Air.Inst.Index) Type {
77687771 const pt = func.pt;
7769 const mod = pt.zcu;
7770 return func.air.typeOfIndex(inst, &mod.intern_pool);
7772 const zcu = pt.zcu;
7773 return func.air.typeOfIndex(inst, &zcu.intern_pool);
77717774}
src/arch/wasm/abi.zig+27-29
......@@ -22,16 +22,15 @@ const direct: [2]Class = .{ .direct, .none };
2222/// Classifies a given Zig type to determine how they must be passed
2323/// or returned as value within a wasm function.
2424/// When all elements result in `.none`, no value must be passed in or returned.
25pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
26 const mod = pt.zcu;
27 const ip = &mod.intern_pool;
28 const target = mod.getTarget();
29 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) return none;
30 switch (ty.zigTypeTag(mod)) {
25pub fn classifyType(ty: Type, zcu: *Zcu) [2]Class {
26 const ip = &zcu.intern_pool;
27 const target = zcu.getTarget();
28 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return none;
29 switch (ty.zigTypeTag(zcu)) {
3130 .Struct => {
32 const struct_type = pt.zcu.typeToStruct(ty).?;
31 const struct_type = zcu.typeToStruct(ty).?;
3332 if (struct_type.layout == .@"packed") {
34 if (ty.bitSize(pt) <= 64) return direct;
33 if (ty.bitSize(zcu) <= 64) return direct;
3534 return .{ .direct, .direct };
3635 }
3736 if (struct_type.field_types.len > 1) {
......@@ -41,13 +40,13 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
4140 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[0]);
4241 const explicit_align = struct_type.fieldAlign(ip, 0);
4342 if (explicit_align != .none) {
44 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(pt)))
43 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(zcu)))
4544 return memory;
4645 }
47 return classifyType(field_ty, pt);
46 return classifyType(field_ty, zcu);
4847 },
4948 .Int, .Enum, .ErrorSet => {
50 const int_bits = ty.intInfo(pt.zcu).bits;
49 const int_bits = ty.intInfo(zcu).bits;
5150 if (int_bits <= 64) return direct;
5251 if (int_bits <= 128) return .{ .direct, .direct };
5352 return memory;
......@@ -62,24 +61,24 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
6261 .Vector => return direct,
6362 .Array => return memory,
6463 .Optional => {
65 assert(ty.isPtrLikeOptional(pt.zcu));
64 assert(ty.isPtrLikeOptional(zcu));
6665 return direct;
6766 },
6867 .Pointer => {
69 assert(!ty.isSlice(pt.zcu));
68 assert(!ty.isSlice(zcu));
7069 return direct;
7170 },
7271 .Union => {
73 const union_obj = pt.zcu.typeToUnion(ty).?;
72 const union_obj = zcu.typeToUnion(ty).?;
7473 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
75 if (ty.bitSize(pt) <= 64) return direct;
74 if (ty.bitSize(zcu) <= 64) return direct;
7675 return .{ .direct, .direct };
7776 }
78 const layout = ty.unionGetLayout(pt);
77 const layout = ty.unionGetLayout(zcu);
7978 assert(layout.tag_size == 0);
8079 if (union_obj.field_types.len > 1) return memory;
8180 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
82 return classifyType(first_field_ty, pt);
81 return classifyType(first_field_ty, zcu);
8382 },
8483 .ErrorUnion,
8584 .Frame,
......@@ -101,29 +100,28 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
101100/// Returns the scalar type a given type can represent.
102101/// Asserts given type can be represented as scalar, such as
103102/// a struct with a single scalar field.
104pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {
105 const mod = pt.zcu;
106 const ip = &mod.intern_pool;
107 switch (ty.zigTypeTag(mod)) {
103pub fn scalarType(ty: Type, zcu: *Zcu) Type {
104 const ip = &zcu.intern_pool;
105 switch (ty.zigTypeTag(zcu)) {
108106 .Struct => {
109 if (mod.typeToPackedStruct(ty)) |packed_struct| {
110 return scalarType(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
107 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
108 return scalarType(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), zcu);
111109 } else {
112 assert(ty.structFieldCount(mod) == 1);
113 return scalarType(ty.structFieldType(0, mod), pt);
110 assert(ty.structFieldCount(zcu) == 1);
111 return scalarType(ty.structFieldType(0, zcu), zcu);
114112 }
115113 },
116114 .Union => {
117 const union_obj = mod.typeToUnion(ty).?;
115 const union_obj = zcu.typeToUnion(ty).?;
118116 if (union_obj.flagsUnordered(ip).layout != .@"packed") {
119 const layout = pt.getUnionLayout(union_obj);
117 const layout = Type.getUnionLayout(union_obj, zcu);
120118 if (layout.payload_size == 0 and layout.tag_size != 0) {
121 return scalarType(ty.unionTagTypeSafety(mod).?, pt);
119 return scalarType(ty.unionTagTypeSafety(zcu).?, zcu);
122120 }
123121 assert(union_obj.field_types.len == 1);
124122 }
125123 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
126 return scalarType(first_field_ty, pt);
124 return scalarType(first_field_ty, zcu);
127125 },
128126 else => return ty,
129127 }
src/arch/x86_64/CodeGen.zig+726-722
......@@ -732,14 +732,14 @@ const FrameAlloc = struct {
732732 .ref_count = 0,
733733 };
734734 }
735 fn initType(ty: Type, pt: Zcu.PerThread) FrameAlloc {
735 fn initType(ty: Type, zcu: *Zcu) FrameAlloc {
736736 return init(.{
737 .size = ty.abiSize(pt),
738 .alignment = ty.abiAlignment(pt),
737 .size = ty.abiSize(zcu),
738 .alignment = ty.abiAlignment(zcu),
739739 });
740740 }
741 fn initSpill(ty: Type, pt: Zcu.PerThread) FrameAlloc {
742 const abi_size = ty.abiSize(pt);
741 fn initSpill(ty: Type, zcu: *Zcu) FrameAlloc {
742 const abi_size = ty.abiSize(zcu);
743743 const spill_size = if (abi_size < 8)
744744 math.ceilPowerOfTwoAssert(u64, abi_size)
745745 else
......@@ -747,7 +747,7 @@ const FrameAlloc = struct {
747747 return init(.{
748748 .size = spill_size,
749749 .pad = @intCast(spill_size - abi_size),
750 .alignment = ty.abiAlignment(pt).maxStrict(
750 .alignment = ty.abiAlignment(zcu).maxStrict(
751751 Alignment.fromNonzeroByteUnits(@min(spill_size, 8)),
752752 ),
753753 });
......@@ -756,7 +756,7 @@ const FrameAlloc = struct {
756756
757757const StackAllocation = struct {
758758 inst: ?Air.Inst.Index,
759 /// TODO do we need size? should be determined by inst.ty.abiSize(pt)
759 /// TODO do we need size? should be determined by inst.ty.abiSize(zcu)
760760 size: u32,
761761};
762762
......@@ -859,11 +859,11 @@ pub fn generate(
859859 function.args = call_info.args;
860860 function.ret_mcv = call_info.return_value;
861861 function.frame_allocs.set(@intFromEnum(FrameIndex.ret_addr), FrameAlloc.init(.{
862 .size = Type.usize.abiSize(pt),
863 .alignment = Type.usize.abiAlignment(pt).min(call_info.stack_align),
862 .size = Type.usize.abiSize(zcu),
863 .alignment = Type.usize.abiAlignment(zcu).min(call_info.stack_align),
864864 }));
865865 function.frame_allocs.set(@intFromEnum(FrameIndex.base_ptr), FrameAlloc.init(.{
866 .size = Type.usize.abiSize(pt),
866 .size = Type.usize.abiSize(zcu),
867867 .alignment = Alignment.min(
868868 call_info.stack_align,
869869 Alignment.fromNonzeroByteUnits(function.target.stackAlignment()),
......@@ -1872,8 +1872,8 @@ fn asmMemoryRegisterImmediate(
18721872
18731873fn gen(self: *Self) InnerError!void {
18741874 const pt = self.pt;
1875 const mod = pt.zcu;
1876 const fn_info = mod.typeToFunc(self.fn_type).?;
1875 const zcu = pt.zcu;
1876 const fn_info = zcu.typeToFunc(self.fn_type).?;
18771877 const cc = abi.resolveCallingConvention(fn_info.cc, self.target.*);
18781878 if (cc != .Naked) {
18791879 try self.asmRegister(.{ ._, .push }, .rbp);
......@@ -1890,7 +1890,7 @@ fn gen(self: *Self) InnerError!void {
18901890 // The address where to store the return value for the caller is in a
18911891 // register which the callee is free to clobber. Therefore, we purposely
18921892 // spill it to stack immediately.
1893 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(Type.usize, pt));
1893 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(Type.usize, zcu));
18941894 try self.genSetMem(
18951895 .{ .frame = frame_index },
18961896 0,
......@@ -2099,8 +2099,8 @@ fn checkInvariantsAfterAirInst(self: *Self, inst: Air.Inst.Index, old_air_bookke
20992099
21002100fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
21012101 const pt = self.pt;
2102 const mod = pt.zcu;
2103 const ip = &mod.intern_pool;
2102 const zcu = pt.zcu;
2103 const ip = &zcu.intern_pool;
21042104 const air_tags = self.air.instructions.items(.tag);
21052105
21062106 self.arg_index = 0;
......@@ -2370,9 +2370,9 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
23702370
23712371fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
23722372 const pt = self.pt;
2373 const mod = pt.zcu;
2374 const ip = &mod.intern_pool;
2375 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(mod)) {
2373 const zcu = pt.zcu;
2374 const ip = &zcu.intern_pool;
2375 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {
23762376 .Enum => {
23772377 const enum_ty = Type.fromInterned(lazy_sym.ty);
23782378 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});
......@@ -2385,7 +2385,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
23852385 const ret_reg = param_regs[0];
23862386 const enum_mcv = MCValue{ .register = param_regs[1] };
23872387
2388 const exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(mod));
2388 const exitlude_jump_relocs = try self.gpa.alloc(Mir.Inst.Index, enum_ty.enumFieldCount(zcu));
23892389 defer self.gpa.free(exitlude_jump_relocs);
23902390
23912391 const data_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
......@@ -2394,7 +2394,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
23942394 try self.genLazySymbolRef(.lea, data_reg, .{ .kind = .const_data, .ty = enum_ty.toIntern() });
23952395
23962396 var data_off: i32 = 0;
2397 const tag_names = enum_ty.enumFields(mod);
2397 const tag_names = enum_ty.enumFields(zcu);
23982398 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {
23992399 const tag_name_len = tag_names.get(ip)[tag_index].length(ip);
24002400 const tag_val = try pt.enumValueFieldIndex(enum_ty, @intCast(tag_index));
......@@ -2630,14 +2630,14 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
26302630/// Use a pointer instruction as the basis for allocating stack memory.
26312631fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !FrameIndex {
26322632 const pt = self.pt;
2633 const mod = pt.zcu;
2633 const zcu = pt.zcu;
26342634 const ptr_ty = self.typeOfIndex(inst);
2635 const val_ty = ptr_ty.childType(mod);
2635 const val_ty = ptr_ty.childType(zcu);
26362636 return self.allocFrameIndex(FrameAlloc.init(.{
2637 .size = math.cast(u32, val_ty.abiSize(pt)) orelse {
2637 .size = math.cast(u32, val_ty.abiSize(zcu)) orelse {
26382638 return self.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});
26392639 },
2640 .alignment = ptr_ty.ptrAlignment(pt).max(.@"1"),
2640 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
26412641 }));
26422642}
26432643
......@@ -2651,20 +2651,20 @@ fn allocTempRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool) !MCValue {
26512651
26522652fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: bool) !MCValue {
26532653 const pt = self.pt;
2654 const mod = pt.zcu;
2655 const abi_size = math.cast(u32, ty.abiSize(pt)) orelse {
2654 const zcu = pt.zcu;
2655 const abi_size = math.cast(u32, ty.abiSize(zcu)) orelse {
26562656 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});
26572657 };
26582658
26592659 if (reg_ok) need_mem: {
2660 if (abi_size <= @as(u32, switch (ty.zigTypeTag(mod)) {
2660 if (abi_size <= @as(u32, switch (ty.zigTypeTag(zcu)) {
26612661 .Float => switch (ty.floatBits(self.target.*)) {
26622662 16, 32, 64, 128 => 16,
26632663 80 => break :need_mem,
26642664 else => unreachable,
26652665 },
2666 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
2667 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
2666 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
2667 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
26682668 16, 32, 64, 128 => if (self.hasFeature(.avx)) 32 else 16,
26692669 80 => break :need_mem,
26702670 else => unreachable,
......@@ -2679,21 +2679,21 @@ fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: b
26792679 }
26802680 }
26812681
2682 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, pt));
2682 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, zcu));
26832683 return .{ .load_frame = .{ .index = frame_index } };
26842684}
26852685
26862686fn regClassForType(self: *Self, ty: Type) RegisterManager.RegisterBitSet {
26872687 const pt = self.pt;
2688 const mod = pt.zcu;
2689 return switch (ty.zigTypeTag(mod)) {
2688 const zcu = pt.zcu;
2689 return switch (ty.zigTypeTag(zcu)) {
26902690 .Float => switch (ty.floatBits(self.target.*)) {
26912691 80 => abi.RegisterClass.x87,
26922692 else => abi.RegisterClass.sse,
26932693 },
2694 .Vector => switch (ty.childType(mod).toIntern()) {
2694 .Vector => switch (ty.childType(zcu).toIntern()) {
26952695 .bool_type, .u1_type => abi.RegisterClass.gp,
2696 else => if (ty.isAbiInt(mod) and ty.intInfo(mod).bits == 1)
2696 else => if (ty.isAbiInt(zcu) and ty.intInfo(zcu).bits == 1)
26972697 abi.RegisterClass.gp
26982698 else
26992699 abi.RegisterClass.sse,
......@@ -3001,13 +3001,13 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
30013001
30023002fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
30033003 const pt = self.pt;
3004 const mod = pt.zcu;
3004 const zcu = pt.zcu;
30053005 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
30063006 const dst_ty = self.typeOfIndex(inst);
3007 const dst_scalar_ty = dst_ty.scalarType(mod);
3007 const dst_scalar_ty = dst_ty.scalarType(zcu);
30083008 const dst_bits = dst_scalar_ty.floatBits(self.target.*);
30093009 const src_ty = self.typeOf(ty_op.operand);
3010 const src_scalar_ty = src_ty.scalarType(mod);
3010 const src_scalar_ty = src_ty.scalarType(zcu);
30113011 const src_bits = src_scalar_ty.floatBits(self.target.*);
30123012
30133013 const result = result: {
......@@ -3032,7 +3032,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
30323032 },
30333033 else => unreachable,
30343034 }) {
3035 if (dst_ty.isVector(mod)) break :result null;
3035 if (dst_ty.isVector(zcu)) break :result null;
30363036 var callee_buf: ["__extend?f?f2".len]u8 = undefined;
30373037 break :result try self.genCall(.{ .lib = .{
30383038 .return_type = self.floatCompilerRtAbiType(dst_scalar_ty, src_scalar_ty).toIntern(),
......@@ -3044,18 +3044,18 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
30443044 } }, &.{src_scalar_ty}, &.{.{ .air_ref = ty_op.operand }});
30453045 }
30463046
3047 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));
3047 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
30483048 const src_mcv = try self.resolveInst(ty_op.operand);
30493049 const dst_mcv = if (src_mcv.isRegister() and self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
30503050 src_mcv
30513051 else
30523052 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
30533053 const dst_reg = dst_mcv.getReg().?;
3054 const dst_alias = registerAlias(dst_reg, @intCast(@max(dst_ty.abiSize(pt), 16)));
3054 const dst_alias = registerAlias(dst_reg, @intCast(@max(dst_ty.abiSize(zcu), 16)));
30553055 const dst_lock = self.register_manager.lockReg(dst_reg);
30563056 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
30573057
3058 const vec_len = if (dst_ty.isVector(mod)) dst_ty.vectorLen(mod) else 1;
3058 const vec_len = if (dst_ty.isVector(zcu)) dst_ty.vectorLen(zcu) else 1;
30593059 if (src_bits == 16) {
30603060 assert(self.hasFeature(.f16c));
30613061 const mat_src_reg = if (src_mcv.isRegister())
......@@ -3137,30 +3137,30 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
31373137
31383138fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
31393139 const pt = self.pt;
3140 const mod = pt.zcu;
3140 const zcu = pt.zcu;
31413141 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
31423142 const src_ty = self.typeOf(ty_op.operand);
31433143 const dst_ty = self.typeOfIndex(inst);
31443144
31453145 const result = @as(?MCValue, result: {
3146 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));
3146 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
31473147
3148 const src_int_info = src_ty.intInfo(mod);
3149 const dst_int_info = dst_ty.intInfo(mod);
3148 const src_int_info = src_ty.intInfo(zcu);
3149 const dst_int_info = dst_ty.intInfo(zcu);
31503150 const extend = switch (src_int_info.signedness) {
31513151 .signed => dst_int_info,
31523152 .unsigned => src_int_info,
31533153 }.signedness;
31543154
31553155 const src_mcv = try self.resolveInst(ty_op.operand);
3156 if (dst_ty.isVector(mod)) {
3157 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));
3156 if (dst_ty.isVector(zcu)) {
3157 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
31583158 const max_abi_size = @max(dst_abi_size, src_abi_size);
31593159 if (max_abi_size > @as(u32, if (self.hasFeature(.avx2)) 32 else 16)) break :result null;
31603160 const has_avx = self.hasFeature(.avx);
31613161
3162 const dst_elem_abi_size = dst_ty.childType(mod).abiSize(pt);
3163 const src_elem_abi_size = src_ty.childType(mod).abiSize(pt);
3162 const dst_elem_abi_size = dst_ty.childType(zcu).abiSize(zcu);
3163 const src_elem_abi_size = src_ty.childType(zcu).abiSize(zcu);
31643164 switch (math.order(dst_elem_abi_size, src_elem_abi_size)) {
31653165 .lt => {
31663166 const mir_tag: Mir.Inst.FixedTag = switch (dst_elem_abi_size) {
......@@ -3396,13 +3396,13 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
33963396
33973397fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
33983398 const pt = self.pt;
3399 const mod = pt.zcu;
3399 const zcu = pt.zcu;
34003400 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
34013401
34023402 const dst_ty = self.typeOfIndex(inst);
3403 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));
3403 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
34043404 const src_ty = self.typeOf(ty_op.operand);
3405 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));
3405 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
34063406
34073407 const result = result: {
34083408 const src_mcv = try self.resolveInst(ty_op.operand);
......@@ -3414,7 +3414,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
34143414 src_mcv
34153415 else if (dst_abi_size <= 8)
34163416 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv)
3417 else if (dst_abi_size <= 16 and !dst_ty.isVector(mod)) dst: {
3417 else if (dst_abi_size <= 16 and !dst_ty.isVector(zcu)) dst: {
34183418 const dst_regs =
34193419 try self.register_manager.allocRegs(2, .{ inst, inst }, abi.RegisterClass.gp);
34203420 const dst_mcv: MCValue = .{ .register_pair = dst_regs };
......@@ -3429,16 +3429,16 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
34293429 break :dst dst_mcv;
34303430 };
34313431
3432 if (dst_ty.zigTypeTag(mod) == .Vector) {
3433 assert(src_ty.zigTypeTag(mod) == .Vector and dst_ty.vectorLen(mod) == src_ty.vectorLen(mod));
3434 const dst_elem_ty = dst_ty.childType(mod);
3435 const dst_elem_abi_size: u32 = @intCast(dst_elem_ty.abiSize(pt));
3436 const src_elem_ty = src_ty.childType(mod);
3437 const src_elem_abi_size: u32 = @intCast(src_elem_ty.abiSize(pt));
3432 if (dst_ty.zigTypeTag(zcu) == .Vector) {
3433 assert(src_ty.zigTypeTag(zcu) == .Vector and dst_ty.vectorLen(zcu) == src_ty.vectorLen(zcu));
3434 const dst_elem_ty = dst_ty.childType(zcu);
3435 const dst_elem_abi_size: u32 = @intCast(dst_elem_ty.abiSize(zcu));
3436 const src_elem_ty = src_ty.childType(zcu);
3437 const src_elem_abi_size: u32 = @intCast(src_elem_ty.abiSize(zcu));
34383438
34393439 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_elem_abi_size) {
34403440 1 => switch (src_elem_abi_size) {
3441 2 => switch (dst_ty.vectorLen(mod)) {
3441 2 => switch (dst_ty.vectorLen(zcu)) {
34423442 1...8 => if (self.hasFeature(.avx)) .{ .vp_b, .ackusw } else .{ .p_b, .ackusw },
34433443 9...16 => if (self.hasFeature(.avx2)) .{ .vp_b, .ackusw } else null,
34443444 else => null,
......@@ -3446,7 +3446,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
34463446 else => null,
34473447 },
34483448 2 => switch (src_elem_abi_size) {
3449 4 => switch (dst_ty.vectorLen(mod)) {
3449 4 => switch (dst_ty.vectorLen(zcu)) {
34503450 1...4 => if (self.hasFeature(.avx))
34513451 .{ .vp_w, .ackusd }
34523452 else if (self.hasFeature(.sse4_1))
......@@ -3461,8 +3461,8 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
34613461 else => null,
34623462 }) orelse return self.fail("TODO implement airTrunc for {}", .{dst_ty.fmt(pt)});
34633463
3464 const dst_info = dst_elem_ty.intInfo(mod);
3465 const src_info = src_elem_ty.intInfo(mod);
3464 const dst_info = dst_elem_ty.intInfo(zcu);
3465 const src_info = src_elem_ty.intInfo(zcu);
34663466
34673467 const mask_val = try pt.intValue(src_elem_ty, @as(u64, math.maxInt(u64)) >> @intCast(64 - dst_info.bits));
34683468
......@@ -3470,7 +3470,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
34703470 .len = @intCast(@divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits)),
34713471 .child = src_elem_ty.ip_index,
34723472 });
3473 const splat_abi_size: u32 = @intCast(splat_ty.abiSize(pt));
3473 const splat_abi_size: u32 = @intCast(splat_ty.abiSize(zcu));
34743474
34753475 const splat_val = try pt.intern(.{ .aggregate = .{
34763476 .ty = splat_ty.ip_index,
......@@ -3528,7 +3528,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
35283528 try self.truncateRegister(dst_ty, dst_mcv.register.to64());
35293529 }
35303530 } else if (dst_abi_size <= 16) {
3531 const dst_info = dst_ty.intInfo(mod);
3531 const dst_info = dst_ty.intInfo(zcu);
35323532 const high_ty = try pt.intType(dst_info.signedness, dst_info.bits - 64);
35333533 if (self.regExtraBits(high_ty) > 0) {
35343534 try self.truncateRegister(high_ty, dst_mcv.register_pair[1].to64());
......@@ -3554,12 +3554,12 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
35543554}
35553555
35563556fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
3557 const pt = self.pt;
3557 const zcu = self.pt.zcu;
35583558 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
35593559 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
35603560
35613561 const slice_ty = self.typeOfIndex(inst);
3562 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(slice_ty, pt));
3562 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(slice_ty, zcu));
35633563
35643564 const ptr_ty = self.typeOf(bin_op.lhs);
35653565 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, .{ .air_ref = bin_op.lhs }, .{});
......@@ -3567,7 +3567,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
35673567 const len_ty = self.typeOf(bin_op.rhs);
35683568 try self.genSetMem(
35693569 .{ .frame = frame_index },
3570 @intCast(ptr_ty.abiSize(pt)),
3570 @intCast(ptr_ty.abiSize(zcu)),
35713571 len_ty,
35723572 .{ .air_ref = bin_op.rhs },
35733573 .{},
......@@ -3585,14 +3585,14 @@ fn airUnOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
35853585
35863586fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
35873587 const pt = self.pt;
3588 const mod = pt.zcu;
3588 const zcu = pt.zcu;
35893589 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
35903590 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);
35913591
35923592 const dst_ty = self.typeOfIndex(inst);
3593 if (dst_ty.isAbiInt(mod)) {
3594 const abi_size: u32 = @intCast(dst_ty.abiSize(pt));
3595 const bit_size: u32 = @intCast(dst_ty.bitSize(pt));
3593 if (dst_ty.isAbiInt(zcu)) {
3594 const abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
3595 const bit_size: u32 = @intCast(dst_ty.bitSize(zcu));
35963596 if (abi_size * 8 > bit_size) {
35973597 const dst_lock = switch (dst_mcv) {
35983598 .register => |dst_reg| self.register_manager.lockRegAssumeUnused(dst_reg),
......@@ -3607,7 +3607,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
36073607 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
36083608 defer self.register_manager.unlockReg(tmp_lock);
36093609
3610 const hi_ty = try pt.intType(.unsigned, @intCast((dst_ty.bitSize(pt) - 1) % 64 + 1));
3610 const hi_ty = try pt.intType(.unsigned, @intCast((dst_ty.bitSize(zcu) - 1) % 64 + 1));
36113611 const hi_mcv = dst_mcv.address().offset(@intCast(bit_size / 64 * 8)).deref();
36123612 try self.genSetReg(tmp_reg, hi_ty, hi_mcv, .{});
36133613 try self.truncateRegister(dst_ty, tmp_reg);
......@@ -3627,17 +3627,17 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
36273627
36283628fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
36293629 const pt = self.pt;
3630 const mod = pt.zcu;
3630 const zcu = pt.zcu;
36313631 const air_tag = self.air.instructions.items(.tag);
36323632 const air_data = self.air.instructions.items(.data);
36333633
36343634 const dst_ty = self.typeOf(dst_air);
3635 const dst_info = dst_ty.intInfo(mod);
3635 const dst_info = dst_ty.intInfo(zcu);
36363636 if (dst_air.toIndex()) |inst| {
36373637 switch (air_tag[@intFromEnum(inst)]) {
36383638 .intcast => {
36393639 const src_ty = self.typeOf(air_data[@intFromEnum(inst)].ty_op.operand);
3640 const src_info = src_ty.intInfo(mod);
3640 const src_info = src_ty.intInfo(zcu);
36413641 return @min(switch (src_info.signedness) {
36423642 .signed => switch (dst_info.signedness) {
36433643 .signed => src_info.bits,
......@@ -3653,7 +3653,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
36533653 }
36543654 } else if (dst_air.toInterned()) |ip_index| {
36553655 var space: Value.BigIntSpace = undefined;
3656 const src_int = Value.fromInterned(ip_index).toBigInt(&space, pt);
3656 const src_int = Value.fromInterned(ip_index).toBigInt(&space, zcu);
36573657 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
36583658 @intFromBool(src_int.positive and dst_info.signedness == .signed);
36593659 }
......@@ -3662,18 +3662,18 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
36623662
36633663fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
36643664 const pt = self.pt;
3665 const mod = pt.zcu;
3665 const zcu = pt.zcu;
36663666 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
36673667 const result = result: {
36683668 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
36693669 const dst_ty = self.typeOfIndex(inst);
3670 switch (dst_ty.zigTypeTag(mod)) {
3670 switch (dst_ty.zigTypeTag(zcu)) {
36713671 .Float, .Vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),
36723672 else => {},
36733673 }
3674 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));
3674 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
36753675
3676 const dst_info = dst_ty.intInfo(mod);
3676 const dst_info = dst_ty.intInfo(zcu);
36773677 const src_ty = try pt.intType(dst_info.signedness, switch (tag) {
36783678 else => unreachable,
36793679 .mul, .mul_wrap => @max(
......@@ -3683,20 +3683,20 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
36833683 ),
36843684 .div_trunc, .div_floor, .div_exact, .rem, .mod => dst_info.bits,
36853685 });
3686 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));
3686 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
36873687
36883688 if (dst_abi_size == 16 and src_abi_size == 16) switch (tag) {
36893689 else => unreachable,
36903690 .mul, .mul_wrap => {},
36913691 .div_trunc, .div_floor, .div_exact, .rem, .mod => {
3692 const signed = dst_ty.isSignedInt(mod);
3692 const signed = dst_ty.isSignedInt(zcu);
36933693 var callee_buf: ["__udiv?i3".len]u8 = undefined;
36943694 const signed_div_floor_state: struct {
36953695 frame_index: FrameIndex,
36963696 state: State,
36973697 reloc: Mir.Inst.Index,
36983698 } = if (signed and tag == .div_floor) state: {
3699 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(Type.usize, pt));
3699 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(Type.usize, zcu));
37003700 try self.asmMemoryImmediate(
37013701 .{ ._, .mov },
37023702 .{ .base = .{ .frame = frame_index }, .mod = .{ .rm = .{ .size = .qword } } },
......@@ -3771,7 +3771,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
37713771 .rem, .mod => "mod",
37723772 else => unreachable,
37733773 },
3774 intCompilerRtAbiName(@intCast(dst_ty.bitSize(pt))),
3774 intCompilerRtAbiName(@intCast(dst_ty.bitSize(zcu))),
37753775 }) catch unreachable,
37763776 } },
37773777 &.{ src_ty, src_ty },
......@@ -3800,7 +3800,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
38003800 .return_type = dst_ty.toIntern(),
38013801 .param_types = &.{ src_ty.toIntern(), src_ty.toIntern() },
38023802 .callee = std.fmt.bufPrint(&callee_buf, "__div{c}i3", .{
3803 intCompilerRtAbiName(@intCast(dst_ty.bitSize(pt))),
3803 intCompilerRtAbiName(@intCast(dst_ty.bitSize(zcu))),
38043804 }) catch unreachable,
38053805 } },
38063806 &.{ src_ty, src_ty },
......@@ -3892,10 +3892,10 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
38923892
38933893fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
38943894 const pt = self.pt;
3895 const mod = pt.zcu;
3895 const zcu = pt.zcu;
38963896 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
38973897 const ty = self.typeOf(bin_op.lhs);
3898 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(pt) > 8) return self.fail(
3898 if (ty.zigTypeTag(zcu) == .Vector or ty.abiSize(zcu) > 8) return self.fail(
38993899 "TODO implement airAddSat for {}",
39003900 .{ty.fmt(pt)},
39013901 );
......@@ -3923,7 +3923,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
39233923
39243924 const reg_bits = self.regBitSize(ty);
39253925 const reg_extra_bits = self.regExtraBits(ty);
3926 const cc: Condition = if (ty.isSignedInt(mod)) cc: {
3926 const cc: Condition = if (ty.isSignedInt(zcu)) cc: {
39273927 if (reg_extra_bits > 0) {
39283928 try self.genShiftBinOpMir(
39293929 .{ ._l, .sa },
......@@ -3962,7 +3962,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
39623962 break :cc .o;
39633963 } else cc: {
39643964 try self.genSetReg(limit_reg, ty, .{
3965 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(64 - ty.bitSize(pt)),
3965 .immediate = @as(u64, math.maxInt(u64)) >> @intCast(64 - ty.bitSize(zcu)),
39663966 }, .{});
39673967
39683968 try self.genBinOpMir(.{ ._, .add }, ty, dst_mcv, rhs_mcv);
......@@ -3973,14 +3973,14 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
39733973 break :cc .c;
39743974 };
39753975
3976 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(pt))), 2);
3976 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(zcu))), 2);
39773977 try self.asmCmovccRegisterRegister(
39783978 cc,
39793979 registerAlias(dst_reg, cmov_abi_size),
39803980 registerAlias(limit_reg, cmov_abi_size),
39813981 );
39823982
3983 if (reg_extra_bits > 0 and ty.isSignedInt(mod)) try self.genShiftBinOpMir(
3983 if (reg_extra_bits > 0 and ty.isSignedInt(zcu)) try self.genShiftBinOpMir(
39843984 .{ ._r, .sa },
39853985 ty,
39863986 dst_mcv,
......@@ -3993,10 +3993,10 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
39933993
39943994fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
39953995 const pt = self.pt;
3996 const mod = pt.zcu;
3996 const zcu = pt.zcu;
39973997 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
39983998 const ty = self.typeOf(bin_op.lhs);
3999 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(pt) > 8) return self.fail(
3999 if (ty.zigTypeTag(zcu) == .Vector or ty.abiSize(zcu) > 8) return self.fail(
40004000 "TODO implement airSubSat for {}",
40014001 .{ty.fmt(pt)},
40024002 );
......@@ -4024,7 +4024,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
40244024
40254025 const reg_bits = self.regBitSize(ty);
40264026 const reg_extra_bits = self.regExtraBits(ty);
4027 const cc: Condition = if (ty.isSignedInt(mod)) cc: {
4027 const cc: Condition = if (ty.isSignedInt(zcu)) cc: {
40284028 if (reg_extra_bits > 0) {
40294029 try self.genShiftBinOpMir(
40304030 .{ ._l, .sa },
......@@ -4067,14 +4067,14 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
40674067 break :cc .c;
40684068 };
40694069
4070 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(pt))), 2);
4070 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(zcu))), 2);
40714071 try self.asmCmovccRegisterRegister(
40724072 cc,
40734073 registerAlias(dst_reg, cmov_abi_size),
40744074 registerAlias(limit_reg, cmov_abi_size),
40754075 );
40764076
4077 if (reg_extra_bits > 0 and ty.isSignedInt(mod)) try self.genShiftBinOpMir(
4077 if (reg_extra_bits > 0 and ty.isSignedInt(zcu)) try self.genShiftBinOpMir(
40784078 .{ ._r, .sa },
40794079 ty,
40804080 dst_mcv,
......@@ -4087,7 +4087,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
40874087
40884088fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
40894089 const pt = self.pt;
4090 const mod = pt.zcu;
4090 const zcu = pt.zcu;
40914091 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
40924092 const ty = self.typeOf(bin_op.lhs);
40934093
......@@ -4170,7 +4170,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
41704170 break :result dst_mcv;
41714171 }
41724172
4173 if (ty.zigTypeTag(mod) == .Vector or ty.abiSize(pt) > 8) return self.fail(
4173 if (ty.zigTypeTag(zcu) == .Vector or ty.abiSize(zcu) > 8) return self.fail(
41744174 "TODO implement airMulSat for {}",
41754175 .{ty.fmt(pt)},
41764176 );
......@@ -4199,7 +4199,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
41994199 defer self.register_manager.unlockReg(limit_lock);
42004200
42014201 const reg_bits = self.regBitSize(ty);
4202 const cc: Condition = if (ty.isSignedInt(mod)) cc: {
4202 const cc: Condition = if (ty.isSignedInt(zcu)) cc: {
42034203 try self.genSetReg(limit_reg, ty, lhs_mcv, .{});
42044204 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, rhs_mcv);
42054205 try self.genShiftBinOpMir(
......@@ -4221,7 +4221,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
42214221 };
42224222
42234223 const dst_mcv = try self.genMulDivBinOp(.mul, inst, ty, ty, lhs_mcv, rhs_mcv);
4224 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(pt))), 2);
4224 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(zcu))), 2);
42254225 try self.asmCmovccRegisterRegister(
42264226 cc,
42274227 registerAlias(dst_mcv.register, cmov_abi_size),
......@@ -4234,13 +4234,13 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
42344234
42354235fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
42364236 const pt = self.pt;
4237 const mod = pt.zcu;
4237 const zcu = pt.zcu;
42384238 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
42394239 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
42404240 const result: MCValue = result: {
42414241 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
42424242 const ty = self.typeOf(bin_op.lhs);
4243 switch (ty.zigTypeTag(mod)) {
4243 switch (ty.zigTypeTag(zcu)) {
42444244 .Vector => return self.fail("TODO implement add/sub with overflow for Vector type", .{}),
42454245 .Int => {
42464246 try self.spillEflagsIfOccupied();
......@@ -4253,7 +4253,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
42534253 .sub_with_overflow => .sub,
42544254 else => unreachable,
42554255 }, bin_op.lhs, bin_op.rhs);
4256 const int_info = ty.intInfo(mod);
4256 const int_info = ty.intInfo(zcu);
42574257 const cc: Condition = switch (int_info.signedness) {
42584258 .unsigned => .c,
42594259 .signed => .o,
......@@ -4270,17 +4270,17 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
42704270 }
42714271
42724272 const frame_index =
4273 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));
4273 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
42744274 try self.genSetMem(
42754275 .{ .frame = frame_index },
4276 @intCast(tuple_ty.structFieldOffset(1, pt)),
4276 @intCast(tuple_ty.structFieldOffset(1, zcu)),
42774277 Type.u1,
42784278 .{ .eflags = cc },
42794279 .{},
42804280 );
42814281 try self.genSetMem(
42824282 .{ .frame = frame_index },
4283 @intCast(tuple_ty.structFieldOffset(0, pt)),
4283 @intCast(tuple_ty.structFieldOffset(0, zcu)),
42844284 ty,
42854285 partial_mcv,
42864286 .{},
......@@ -4289,7 +4289,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
42894289 }
42904290
42914291 const frame_index =
4292 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));
4292 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
42934293 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);
42944294 break :result .{ .load_frame = .{ .index = frame_index } };
42954295 },
......@@ -4301,13 +4301,13 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
43014301
43024302fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
43034303 const pt = self.pt;
4304 const mod = pt.zcu;
4304 const zcu = pt.zcu;
43054305 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
43064306 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
43074307 const result: MCValue = result: {
43084308 const lhs_ty = self.typeOf(bin_op.lhs);
43094309 const rhs_ty = self.typeOf(bin_op.rhs);
4310 switch (lhs_ty.zigTypeTag(mod)) {
4310 switch (lhs_ty.zigTypeTag(zcu)) {
43114311 .Vector => return self.fail("TODO implement shl with overflow for Vector type", .{}),
43124312 .Int => {
43134313 try self.spillEflagsIfOccupied();
......@@ -4318,7 +4318,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
43184318 const lhs = try self.resolveInst(bin_op.lhs);
43194319 const rhs = try self.resolveInst(bin_op.rhs);
43204320
4321 const int_info = lhs_ty.intInfo(mod);
4321 const int_info = lhs_ty.intInfo(zcu);
43224322
43234323 const partial_mcv = try self.genShiftBinOp(.shl, null, lhs, rhs, lhs_ty, rhs_ty);
43244324 const partial_lock = switch (partial_mcv) {
......@@ -4348,18 +4348,18 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
43484348 }
43494349
43504350 const frame_index =
4351 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));
4351 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
43524352 try self.genSetMem(
43534353 .{ .frame = frame_index },
4354 @intCast(tuple_ty.structFieldOffset(1, pt)),
4355 tuple_ty.structFieldType(1, mod),
4354 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4355 tuple_ty.structFieldType(1, zcu),
43564356 .{ .eflags = cc },
43574357 .{},
43584358 );
43594359 try self.genSetMem(
43604360 .{ .frame = frame_index },
4361 @intCast(tuple_ty.structFieldOffset(0, pt)),
4362 tuple_ty.structFieldType(0, mod),
4361 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4362 tuple_ty.structFieldType(0, zcu),
43634363 partial_mcv,
43644364 .{},
43654365 );
......@@ -4367,7 +4367,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
43674367 }
43684368
43694369 const frame_index =
4370 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));
4370 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
43714371 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);
43724372 break :result .{ .load_frame = .{ .index = frame_index } };
43734373 },
......@@ -4385,15 +4385,15 @@ fn genSetFrameTruncatedOverflowCompare(
43854385 overflow_cc: ?Condition,
43864386) !void {
43874387 const pt = self.pt;
4388 const mod = pt.zcu;
4388 const zcu = pt.zcu;
43894389 const src_lock = switch (src_mcv) {
43904390 .register => |reg| self.register_manager.lockReg(reg),
43914391 else => null,
43924392 };
43934393 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
43944394
4395 const ty = tuple_ty.structFieldType(0, mod);
4396 const int_info = ty.intInfo(mod);
4395 const ty = tuple_ty.structFieldType(0, zcu);
4396 const int_info = ty.intInfo(zcu);
43974397
43984398 const hi_bits = (int_info.bits - 1) % 64 + 1;
43994399 const hi_ty = try pt.intType(int_info.signedness, hi_bits);
......@@ -4432,7 +4432,7 @@ fn genSetFrameTruncatedOverflowCompare(
44324432 );
44334433 }
44344434
4435 const payload_off: i32 = @intCast(tuple_ty.structFieldOffset(0, pt));
4435 const payload_off: i32 = @intCast(tuple_ty.structFieldOffset(0, zcu));
44364436 if (hi_limb_off > 0) try self.genSetMem(
44374437 .{ .frame = frame_index },
44384438 payload_off,
......@@ -4449,8 +4449,8 @@ fn genSetFrameTruncatedOverflowCompare(
44494449 );
44504450 try self.genSetMem(
44514451 .{ .frame = frame_index },
4452 @intCast(tuple_ty.structFieldOffset(1, pt)),
4453 tuple_ty.structFieldType(1, mod),
4452 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4453 tuple_ty.structFieldType(1, zcu),
44544454 if (overflow_cc) |_| .{ .register = overflow_reg.to8() } else .{ .eflags = .ne },
44554455 .{},
44564456 );
......@@ -4458,18 +4458,18 @@ fn genSetFrameTruncatedOverflowCompare(
44584458
44594459fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
44604460 const pt = self.pt;
4461 const mod = pt.zcu;
4461 const zcu = pt.zcu;
44624462 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
44634463 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
44644464 const tuple_ty = self.typeOfIndex(inst);
44654465 const dst_ty = self.typeOf(bin_op.lhs);
4466 const result: MCValue = switch (dst_ty.zigTypeTag(mod)) {
4466 const result: MCValue = switch (dst_ty.zigTypeTag(zcu)) {
44674467 .Vector => return self.fail("TODO implement airMulWithOverflow for {}", .{dst_ty.fmt(pt)}),
44684468 .Int => result: {
4469 const dst_info = dst_ty.intInfo(mod);
4469 const dst_info = dst_ty.intInfo(zcu);
44704470 if (dst_info.bits > 128 and dst_info.signedness == .unsigned) {
44714471 const slow_inc = self.hasFeature(.slow_incdec);
4472 const abi_size: u32 = @intCast(dst_ty.abiSize(pt));
4472 const abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
44734473 const limb_len = math.divCeil(u32, abi_size, 8) catch unreachable;
44744474
44754475 try self.spillRegisters(&.{ .rax, .rcx, .rdx });
......@@ -4480,7 +4480,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
44804480 try self.genInlineMemset(
44814481 dst_mcv.address(),
44824482 .{ .immediate = 0 },
4483 .{ .immediate = tuple_ty.abiSize(pt) },
4483 .{ .immediate = tuple_ty.abiSize(zcu) },
44844484 .{},
44854485 );
44864486 const lhs_mcv = try self.resolveInst(bin_op.lhs);
......@@ -4520,7 +4520,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
45204520 .index = temp_regs[3].to64(),
45214521 .scale = .@"8",
45224522 .disp = dst_mcv.load_frame.off +
4523 @as(i32, @intCast(tuple_ty.structFieldOffset(0, pt))),
4523 @as(i32, @intCast(tuple_ty.structFieldOffset(0, zcu))),
45244524 } },
45254525 }, .rdx);
45264526 try self.asmSetccRegister(.c, .cl);
......@@ -4544,7 +4544,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
45444544 .index = temp_regs[3].to64(),
45454545 .scale = .@"8",
45464546 .disp = dst_mcv.load_frame.off +
4547 @as(i32, @intCast(tuple_ty.structFieldOffset(0, pt))),
4547 @as(i32, @intCast(tuple_ty.structFieldOffset(0, zcu))),
45484548 } },
45494549 }, .rax);
45504550 try self.asmSetccRegister(.c, .ch);
......@@ -4593,7 +4593,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
45934593 .mod = .{ .rm = .{
45944594 .size = .byte,
45954595 .disp = dst_mcv.load_frame.off +
4596 @as(i32, @intCast(tuple_ty.structFieldOffset(1, pt))),
4596 @as(i32, @intCast(tuple_ty.structFieldOffset(1, zcu))),
45974597 } },
45984598 }, Immediate.u(1));
45994599 self.performReloc(no_overflow);
......@@ -4636,8 +4636,8 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
46364636 const dst_mcv = try self.allocRegOrMem(inst, false);
46374637 try self.genSetMem(
46384638 .{ .frame = dst_mcv.load_frame.index },
4639 @intCast(tuple_ty.structFieldOffset(0, pt)),
4640 tuple_ty.structFieldType(0, mod),
4639 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4640 tuple_ty.structFieldType(0, zcu),
46414641 result,
46424642 .{},
46434643 );
......@@ -4648,8 +4648,8 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
46484648 );
46494649 try self.genSetMem(
46504650 .{ .frame = dst_mcv.load_frame.index },
4651 @intCast(tuple_ty.structFieldOffset(1, pt)),
4652 tuple_ty.structFieldType(1, mod),
4651 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4652 tuple_ty.structFieldType(1, zcu),
46534653 .{ .eflags = .ne },
46544654 .{},
46554655 );
......@@ -4760,15 +4760,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
47604760 const dst_mcv = try self.allocRegOrMem(inst, false);
47614761 try self.genSetMem(
47624762 .{ .frame = dst_mcv.load_frame.index },
4763 @intCast(tuple_ty.structFieldOffset(0, pt)),
4764 tuple_ty.structFieldType(0, mod),
4763 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4764 tuple_ty.structFieldType(0, zcu),
47654765 .{ .register_pair = .{ .rax, .rdx } },
47664766 .{},
47674767 );
47684768 try self.genSetMem(
47694769 .{ .frame = dst_mcv.load_frame.index },
4770 @intCast(tuple_ty.structFieldOffset(1, pt)),
4771 tuple_ty.structFieldType(1, mod),
4770 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4771 tuple_ty.structFieldType(1, zcu),
47724772 .{ .register = tmp_regs[1] },
47734773 .{},
47744774 );
......@@ -4800,7 +4800,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
48004800 self.eflags_inst = inst;
48014801 break :result .{ .register_overflow = .{ .reg = reg, .eflags = cc } };
48024802 } else {
4803 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));
4803 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
48044804 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);
48054805 break :result .{ .load_frame = .{ .index = frame_index } };
48064806 },
......@@ -4811,19 +4811,19 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
48114811 src_ty.fmt(pt), dst_ty.fmt(pt),
48124812 });
48134813
4814 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));
4814 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
48154815 if (dst_info.bits >= lhs_active_bits + rhs_active_bits) {
48164816 try self.genSetMem(
48174817 .{ .frame = frame_index },
4818 @intCast(tuple_ty.structFieldOffset(0, pt)),
4819 tuple_ty.structFieldType(0, mod),
4818 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4819 tuple_ty.structFieldType(0, zcu),
48204820 partial_mcv,
48214821 .{},
48224822 );
48234823 try self.genSetMem(
48244824 .{ .frame = frame_index },
4825 @intCast(tuple_ty.structFieldOffset(1, pt)),
4826 tuple_ty.structFieldType(1, mod),
4825 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4826 tuple_ty.structFieldType(1, zcu),
48274827 .{ .immediate = 0 }, // cc being set is impossible
48284828 .{},
48294829 );
......@@ -4847,7 +4847,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
48474847/// Quotient is saved in .rax and remainder in .rdx.
48484848fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue, rhs: MCValue) !void {
48494849 const pt = self.pt;
4850 const abi_size: u32 = @intCast(ty.abiSize(pt));
4850 const abi_size: u32 = @intCast(ty.abiSize(pt.zcu));
48514851 const bit_size: u32 = @intCast(self.regBitSize(ty));
48524852 if (abi_size > 8) {
48534853 return self.fail("TODO implement genIntMulDivOpMir for ABI size larger than 8", .{});
......@@ -4897,9 +4897,9 @@ fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue
48974897/// Clobbers .rax and .rdx registers.
48984898fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCValue {
48994899 const pt = self.pt;
4900 const mod = pt.zcu;
4901 const abi_size: u32 = @intCast(ty.abiSize(pt));
4902 const int_info = ty.intInfo(mod);
4900 const zcu = pt.zcu;
4901 const abi_size: u32 = @intCast(ty.abiSize(zcu));
4902 const int_info = ty.intInfo(zcu);
49034903 const dividend = switch (lhs) {
49044904 .register => |reg| reg,
49054905 else => try self.copyToTmpRegister(ty, lhs),
......@@ -4950,7 +4950,7 @@ fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCVa
49504950
49514951fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
49524952 const pt = self.pt;
4953 const mod = pt.zcu;
4953 const zcu = pt.zcu;
49544954 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
49554955
49564956 const air_tags = self.air.instructions.items(.tag);
......@@ -4958,7 +4958,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
49584958 const lhs_ty = self.typeOf(bin_op.lhs);
49594959 const rhs_ty = self.typeOf(bin_op.rhs);
49604960 const result: MCValue = result: {
4961 switch (lhs_ty.zigTypeTag(mod)) {
4961 switch (lhs_ty.zigTypeTag(zcu)) {
49624962 .Int => {
49634963 try self.spillRegisters(&.{.rcx});
49644964 try self.register_manager.getKnownReg(.rcx, null);
......@@ -4977,7 +4977,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
49774977 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
49784978 defer self.register_manager.unlockReg(tmp_lock);
49794979
4980 const lhs_bits: u31 = @intCast(lhs_ty.bitSize(pt));
4980 const lhs_bits: u31 = @intCast(lhs_ty.bitSize(zcu));
49814981 const tmp_ty = if (lhs_bits > 64) Type.usize else lhs_ty;
49824982 const off = frame_addr.off + (lhs_bits - 1) / 64 * 8;
49834983 try self.genSetReg(
......@@ -5001,14 +5001,14 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
50015001 }
50025002 break :result dst_mcv;
50035003 },
5004 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
5005 .Int => if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.childType(mod).intInfo(mod).bits) {
5004 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
5005 .Int => if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.childType(zcu).intInfo(zcu).bits) {
50065006 else => null,
5007 16 => switch (lhs_ty.vectorLen(mod)) {
5007 16 => switch (lhs_ty.vectorLen(zcu)) {
50085008 else => null,
50095009 1...8 => switch (tag) {
50105010 else => unreachable,
5011 .shr, .shr_exact => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
5011 .shr, .shr_exact => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
50125012 .signed => if (self.hasFeature(.avx))
50135013 .{ .vp_w, .sra }
50145014 else
......@@ -5025,18 +5025,18 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
50255025 },
50265026 9...16 => switch (tag) {
50275027 else => unreachable,
5028 .shr, .shr_exact => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
5028 .shr, .shr_exact => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
50295029 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .sra } else null,
50305030 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_w, .srl } else null,
50315031 },
50325032 .shl, .shl_exact => if (self.hasFeature(.avx2)) .{ .vp_w, .sll } else null,
50335033 },
50345034 },
5035 32 => switch (lhs_ty.vectorLen(mod)) {
5035 32 => switch (lhs_ty.vectorLen(zcu)) {
50365036 else => null,
50375037 1...4 => switch (tag) {
50385038 else => unreachable,
5039 .shr, .shr_exact => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
5039 .shr, .shr_exact => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
50405040 .signed => if (self.hasFeature(.avx))
50415041 .{ .vp_d, .sra }
50425042 else
......@@ -5053,18 +5053,18 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
50535053 },
50545054 5...8 => switch (tag) {
50555055 else => unreachable,
5056 .shr, .shr_exact => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
5056 .shr, .shr_exact => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
50575057 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .sra } else null,
50585058 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_d, .srl } else null,
50595059 },
50605060 .shl, .shl_exact => if (self.hasFeature(.avx2)) .{ .vp_d, .sll } else null,
50615061 },
50625062 },
5063 64 => switch (lhs_ty.vectorLen(mod)) {
5063 64 => switch (lhs_ty.vectorLen(zcu)) {
50645064 else => null,
50655065 1...2 => switch (tag) {
50665066 else => unreachable,
5067 .shr, .shr_exact => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
5067 .shr, .shr_exact => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
50685068 .signed => if (self.hasFeature(.avx))
50695069 .{ .vp_q, .sra }
50705070 else
......@@ -5081,7 +5081,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
50815081 },
50825082 3...4 => switch (tag) {
50835083 else => unreachable,
5084 .shr, .shr_exact => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
5084 .shr, .shr_exact => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
50855085 .signed => if (self.hasFeature(.avx2)) .{ .vp_q, .sra } else null,
50865086 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_q, .srl } else null,
50875087 },
......@@ -5089,10 +5089,10 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
50895089 },
50905090 },
50915091 })) |mir_tag| if (try self.air.value(bin_op.rhs, pt)) |rhs_val| {
5092 switch (mod.intern_pool.indexToKey(rhs_val.toIntern())) {
5092 switch (zcu.intern_pool.indexToKey(rhs_val.toIntern())) {
50935093 .aggregate => |rhs_aggregate| switch (rhs_aggregate.storage) {
50945094 .repeated_elem => |rhs_elem| {
5095 const abi_size: u32 = @intCast(lhs_ty.abiSize(pt));
5095 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
50965096
50975097 const lhs_mcv = try self.resolveInst(bin_op.lhs);
50985098 const dst_reg, const lhs_reg = if (lhs_mcv.isRegister() and
......@@ -5112,7 +5112,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
51125112 self.register_manager.unlockReg(lock);
51135113
51145114 const shift_imm =
5115 Immediate.u(@intCast(Value.fromInterned(rhs_elem).toUnsignedInt(pt)));
5115 Immediate.u(@intCast(Value.fromInterned(rhs_elem).toUnsignedInt(zcu)));
51165116 if (self.hasFeature(.avx)) try self.asmRegisterRegisterImmediate(
51175117 mir_tag,
51185118 registerAlias(dst_reg, abi_size),
......@@ -5134,7 +5134,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
51345134 }
51355135 } else if (bin_op.rhs.toIndex()) |rhs_inst| switch (air_tags[@intFromEnum(rhs_inst)]) {
51365136 .splat => {
5137 const abi_size: u32 = @intCast(lhs_ty.abiSize(pt));
5137 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
51385138
51395139 const lhs_mcv = try self.resolveInst(bin_op.lhs);
51405140 const dst_reg, const lhs_reg = if (lhs_mcv.isRegister() and
......@@ -5161,7 +5161,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
51615161 const mask_mcv = try self.genTypedValue(Value.fromInterned(try pt.intern(.{ .aggregate = .{
51625162 .ty = mask_ty.toIntern(),
51635163 .storage = .{ .elems = &([1]InternPool.Index{
5164 (try rhs_ty.childType(mod).maxIntScalar(pt, Type.u8)).toIntern(),
5164 (try rhs_ty.childType(zcu).maxIntScalar(pt, Type.u8)).toIntern(),
51655165 } ++ [1]InternPool.Index{
51665166 (try pt.intValue(Type.u8, 0)).toIntern(),
51675167 } ** 15) },
......@@ -5224,11 +5224,11 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
52245224}
52255225
52265226fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
5227 const pt = self.pt;
5227 const zcu = self.pt.zcu;
52285228 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
52295229 const result: MCValue = result: {
52305230 const pl_ty = self.typeOfIndex(inst);
5231 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
5231 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
52325232
52335233 const opt_mcv = try self.resolveInst(ty_op.operand);
52345234 if (self.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {
......@@ -5271,15 +5271,15 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
52715271
52725272fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
52735273 const pt = self.pt;
5274 const mod = pt.zcu;
5274 const zcu = pt.zcu;
52755275 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
52765276 const result = result: {
52775277 const dst_ty = self.typeOfIndex(inst);
52785278 const src_ty = self.typeOf(ty_op.operand);
5279 const opt_ty = src_ty.childType(mod);
5279 const opt_ty = src_ty.childType(zcu);
52805280 const src_mcv = try self.resolveInst(ty_op.operand);
52815281
5282 if (opt_ty.optionalReprIsPayload(mod)) {
5282 if (opt_ty.optionalReprIsPayload(zcu)) {
52835283 break :result if (self.liveness.isUnused(inst))
52845284 .unreach
52855285 else if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
......@@ -5296,8 +5296,8 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
52965296 else
52975297 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
52985298
5299 const pl_ty = dst_ty.childType(mod);
5300 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(pt));
5299 const pl_ty = dst_ty.childType(zcu);
5300 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(zcu));
53015301 try self.genSetMem(
53025302 .{ .reg = dst_mcv.getReg().? },
53035303 pl_abi_size,
......@@ -5312,23 +5312,23 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
53125312
53135313fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
53145314 const pt = self.pt;
5315 const mod = pt.zcu;
5315 const zcu = pt.zcu;
53165316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
53175317 const err_union_ty = self.typeOf(ty_op.operand);
5318 const err_ty = err_union_ty.errorUnionSet(mod);
5319 const payload_ty = err_union_ty.errorUnionPayload(mod);
5318 const err_ty = err_union_ty.errorUnionSet(zcu);
5319 const payload_ty = err_union_ty.errorUnionPayload(zcu);
53205320 const operand = try self.resolveInst(ty_op.operand);
53215321
53225322 const result: MCValue = result: {
5323 if (err_ty.errorSetIsEmpty(mod)) {
5323 if (err_ty.errorSetIsEmpty(zcu)) {
53245324 break :result MCValue{ .immediate = 0 };
53255325 }
53265326
5327 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5327 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
53285328 break :result operand;
53295329 }
53305330
5331 const err_off = errUnionErrorOffset(payload_ty, pt);
5331 const err_off = errUnionErrorOffset(payload_ty, zcu);
53325332 switch (operand) {
53335333 .register => |reg| {
53345334 // TODO reuse operand
......@@ -5366,7 +5366,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
53665366// *(E!T) -> E
53675367fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
53685368 const pt = self.pt;
5369 const mod = pt.zcu;
5369 const zcu = pt.zcu;
53705370 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
53715371
53725372 const src_ty = self.typeOf(ty_op.operand);
......@@ -5383,11 +5383,11 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
53835383 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
53845384 defer self.register_manager.unlockReg(dst_lock);
53855385
5386 const eu_ty = src_ty.childType(mod);
5387 const pl_ty = eu_ty.errorUnionPayload(mod);
5388 const err_ty = eu_ty.errorUnionSet(mod);
5389 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));
5390 const err_abi_size: u32 = @intCast(err_ty.abiSize(pt));
5386 const eu_ty = src_ty.childType(zcu);
5387 const pl_ty = eu_ty.errorUnionPayload(zcu);
5388 const err_ty = eu_ty.errorUnionSet(zcu);
5389 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
5390 const err_abi_size: u32 = @intCast(err_ty.abiSize(zcu));
53915391 try self.asmRegisterMemory(
53925392 .{ ._, .mov },
53935393 registerAlias(dst_reg, err_abi_size),
......@@ -5414,7 +5414,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
54145414
54155415fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
54165416 const pt = self.pt;
5417 const mod = pt.zcu;
5417 const zcu = pt.zcu;
54185418 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
54195419 const result: MCValue = result: {
54205420 const src_ty = self.typeOf(ty_op.operand);
......@@ -5426,11 +5426,11 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
54265426 const src_lock = self.register_manager.lockRegAssumeUnused(src_reg);
54275427 defer self.register_manager.unlockReg(src_lock);
54285428
5429 const eu_ty = src_ty.childType(mod);
5430 const pl_ty = eu_ty.errorUnionPayload(mod);
5431 const err_ty = eu_ty.errorUnionSet(mod);
5432 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));
5433 const err_abi_size: u32 = @intCast(err_ty.abiSize(pt));
5429 const eu_ty = src_ty.childType(zcu);
5430 const pl_ty = eu_ty.errorUnionPayload(zcu);
5431 const err_ty = eu_ty.errorUnionSet(zcu);
5432 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
5433 const err_abi_size: u32 = @intCast(err_ty.abiSize(zcu));
54345434 try self.asmMemoryImmediate(
54355435 .{ ._, .mov },
54365436 .{
......@@ -5453,8 +5453,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
54535453 const dst_lock = self.register_manager.lockReg(dst_reg);
54545454 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
54555455
5456 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));
5457 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));
5456 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
5457 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
54585458 try self.asmRegisterMemory(
54595459 .{ ._, .lea },
54605460 registerAlias(dst_reg, dst_abi_size),
......@@ -5475,13 +5475,13 @@ fn genUnwrapErrUnionPayloadMir(
54755475 err_union: MCValue,
54765476) !MCValue {
54775477 const pt = self.pt;
5478 const mod = pt.zcu;
5479 const payload_ty = err_union_ty.errorUnionPayload(mod);
5478 const zcu = pt.zcu;
5479 const payload_ty = err_union_ty.errorUnionPayload(zcu);
54805480
54815481 const result: MCValue = result: {
5482 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
5482 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
54835483
5484 const payload_off: u31 = @intCast(errUnionPayloadOffset(payload_ty, pt));
5484 const payload_off: u31 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
54855485 switch (err_union) {
54865486 .load_frame => |frame_addr| break :result .{ .load_frame = .{
54875487 .index = frame_addr.index,
......@@ -5525,12 +5525,12 @@ fn genUnwrapErrUnionPayloadPtrMir(
55255525 ptr_mcv: MCValue,
55265526) !MCValue {
55275527 const pt = self.pt;
5528 const mod = pt.zcu;
5529 const err_union_ty = ptr_ty.childType(mod);
5530 const payload_ty = err_union_ty.errorUnionPayload(mod);
5528 const zcu = pt.zcu;
5529 const err_union_ty = ptr_ty.childType(zcu);
5530 const payload_ty = err_union_ty.errorUnionPayload(zcu);
55315531
55325532 const result: MCValue = result: {
5533 const payload_off = errUnionPayloadOffset(payload_ty, pt);
5533 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
55345534 const result_mcv: MCValue = if (maybe_inst) |inst|
55355535 try self.copyToRegisterWithInstTracking(inst, ptr_ty, ptr_mcv)
55365536 else
......@@ -5560,15 +5560,15 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
55605560
55615561fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
55625562 const pt = self.pt;
5563 const mod = pt.zcu;
5563 const zcu = pt.zcu;
55645564 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
55655565 const result: MCValue = result: {
55665566 const pl_ty = self.typeOf(ty_op.operand);
5567 if (!pl_ty.hasRuntimeBits(pt)) break :result .{ .immediate = 1 };
5567 if (!pl_ty.hasRuntimeBits(zcu)) break :result .{ .immediate = 1 };
55685568
55695569 const opt_ty = self.typeOfIndex(inst);
55705570 const pl_mcv = try self.resolveInst(ty_op.operand);
5571 const same_repr = opt_ty.optionalReprIsPayload(mod);
5571 const same_repr = opt_ty.optionalReprIsPayload(zcu);
55725572 if (same_repr and self.reuseOperand(inst, ty_op.operand, 0, pl_mcv)) break :result pl_mcv;
55735573
55745574 const pl_lock: ?RegisterLock = switch (pl_mcv) {
......@@ -5581,7 +5581,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
55815581 try self.genCopy(pl_ty, opt_mcv, pl_mcv, .{});
55825582
55835583 if (!same_repr) {
5584 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(pt));
5584 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(zcu));
55855585 switch (opt_mcv) {
55865586 else => unreachable,
55875587
......@@ -5615,20 +5615,20 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
56155615/// T to E!T
56165616fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
56175617 const pt = self.pt;
5618 const mod = pt.zcu;
5618 const zcu = pt.zcu;
56195619 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56205620
56215621 const eu_ty = ty_op.ty.toType();
5622 const pl_ty = eu_ty.errorUnionPayload(mod);
5623 const err_ty = eu_ty.errorUnionSet(mod);
5622 const pl_ty = eu_ty.errorUnionPayload(zcu);
5623 const err_ty = eu_ty.errorUnionSet(zcu);
56245624 const operand = try self.resolveInst(ty_op.operand);
56255625
56265626 const result: MCValue = result: {
5627 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .{ .immediate = 0 };
5627 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .{ .immediate = 0 };
56285628
5629 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(eu_ty, pt));
5630 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));
5631 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));
5629 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
5630 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
5631 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
56325632 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand, .{});
56335633 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 }, .{});
56345634 break :result .{ .load_frame = .{ .index = frame_index } };
......@@ -5639,19 +5639,19 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
56395639/// E to E!T
56405640fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
56415641 const pt = self.pt;
5642 const mod = pt.zcu;
5642 const zcu = pt.zcu;
56435643 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56445644
56455645 const eu_ty = ty_op.ty.toType();
5646 const pl_ty = eu_ty.errorUnionPayload(mod);
5647 const err_ty = eu_ty.errorUnionSet(mod);
5646 const pl_ty = eu_ty.errorUnionPayload(zcu);
5647 const err_ty = eu_ty.errorUnionSet(zcu);
56485648
56495649 const result: MCValue = result: {
5650 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result try self.resolveInst(ty_op.operand);
5650 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result try self.resolveInst(ty_op.operand);
56515651
5652 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(eu_ty, pt));
5653 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));
5654 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));
5652 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
5653 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
5654 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
56555655 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .undef, .{});
56565656 const operand = try self.resolveInst(ty_op.operand);
56575657 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand, .{});
......@@ -5719,7 +5719,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
57195719 const dst_lock = self.register_manager.lockReg(dst_reg);
57205720 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
57215721
5722 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));
5722 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu));
57235723 try self.asmRegisterMemory(
57245724 .{ ._, .lea },
57255725 registerAlias(dst_reg, dst_abi_size),
......@@ -5767,7 +5767,7 @@ fn elemOffset(self: *Self, index_ty: Type, index: MCValue, elem_size: u64) !Regi
57675767
57685768fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
57695769 const pt = self.pt;
5770 const mod = pt.zcu;
5770 const zcu = pt.zcu;
57715771 const slice_ty = self.typeOf(lhs);
57725772 const slice_mcv = try self.resolveInst(lhs);
57735773 const slice_mcv_lock: ?RegisterLock = switch (slice_mcv) {
......@@ -5776,9 +5776,9 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
57765776 };
57775777 defer if (slice_mcv_lock) |lock| self.register_manager.unlockReg(lock);
57785778
5779 const elem_ty = slice_ty.childType(mod);
5780 const elem_size = elem_ty.abiSize(pt);
5781 const slice_ptr_field_type = slice_ty.slicePtrFieldType(mod);
5779 const elem_ty = slice_ty.childType(zcu);
5780 const elem_size = elem_ty.abiSize(zcu);
5781 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
57825782
57835783 const index_ty = self.typeOf(rhs);
57845784 const index_mcv = try self.resolveInst(rhs);
......@@ -5804,15 +5804,15 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
58045804
58055805fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
58065806 const pt = self.pt;
5807 const mod = pt.zcu;
5807 const zcu = pt.zcu;
58085808 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
58095809
58105810 const result: MCValue = result: {
58115811 const elem_ty = self.typeOfIndex(inst);
5812 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
5812 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
58135813
58145814 const slice_ty = self.typeOf(bin_op.lhs);
5815 const slice_ptr_field_type = slice_ty.slicePtrFieldType(mod);
5815 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
58165816 const elem_ptr = try self.genSliceElemPtr(bin_op.lhs, bin_op.rhs);
58175817 const dst_mcv = try self.allocRegOrMem(inst, false);
58185818 try self.load(dst_mcv, slice_ptr_field_type, elem_ptr);
......@@ -5830,12 +5830,12 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
58305830
58315831fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
58325832 const pt = self.pt;
5833 const mod = pt.zcu;
5833 const zcu = pt.zcu;
58345834 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
58355835
58365836 const result: MCValue = result: {
58375837 const array_ty = self.typeOf(bin_op.lhs);
5838 const elem_ty = array_ty.childType(mod);
5838 const elem_ty = array_ty.childType(zcu);
58395839
58405840 const array_mcv = try self.resolveInst(bin_op.lhs);
58415841 const array_lock: ?RegisterLock = switch (array_mcv) {
......@@ -5853,7 +5853,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
58535853 defer if (index_lock) |lock| self.register_manager.unlockReg(lock);
58545854
58555855 try self.spillEflagsIfOccupied();
5856 if (array_ty.isVector(mod) and elem_ty.bitSize(pt) == 1) {
5856 if (array_ty.isVector(zcu) and elem_ty.bitSize(zcu) == 1) {
58575857 const index_reg = switch (index_mcv) {
58585858 .register => |reg| reg,
58595859 else => try self.copyToTmpRegister(index_ty, index_mcv),
......@@ -5866,7 +5866,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
58665866 index_reg.to64(),
58675867 ),
58685868 .sse => {
5869 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(array_ty, pt));
5869 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(array_ty, zcu));
58705870 try self.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv, .{});
58715871 try self.asmMemoryRegister(
58725872 .{ ._, .bt },
......@@ -5904,14 +5904,14 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
59045904 break :result .{ .register = dst_reg };
59055905 }
59065906
5907 const elem_abi_size = elem_ty.abiSize(pt);
5907 const elem_abi_size = elem_ty.abiSize(zcu);
59085908 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
59095909 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);
59105910 defer self.register_manager.unlockReg(addr_lock);
59115911
59125912 switch (array_mcv) {
59135913 .register => {
5914 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(array_ty, pt));
5914 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(array_ty, zcu));
59155915 try self.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv, .{});
59165916 try self.asmRegisterMemory(
59175917 .{ ._, .lea },
......@@ -5960,7 +5960,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
59605960
59615961fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
59625962 const pt = self.pt;
5963 const mod = pt.zcu;
5963 const zcu = pt.zcu;
59645964 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
59655965 const ptr_ty = self.typeOf(bin_op.lhs);
59665966
......@@ -5968,10 +5968,10 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
59685968 // additional `mov` is needed at the end to get the actual value
59695969
59705970 const result = result: {
5971 const elem_ty = ptr_ty.elemType2(mod);
5972 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
5971 const elem_ty = ptr_ty.elemType2(zcu);
5972 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
59735973
5974 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(pt));
5974 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(zcu));
59755975 const index_ty = self.typeOf(bin_op.rhs);
59765976 const index_mcv = try self.resolveInst(bin_op.rhs);
59775977 const index_lock = switch (index_mcv) {
......@@ -6011,7 +6011,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
60116011
60126012fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
60136013 const pt = self.pt;
6014 const mod = pt.zcu;
6014 const zcu = pt.zcu;
60156015 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
60166016 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
60176017
......@@ -6026,15 +6026,15 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
60266026 };
60276027 defer if (base_ptr_lock) |lock| self.register_manager.unlockReg(lock);
60286028
6029 if (elem_ptr_ty.ptrInfo(mod).flags.vector_index != .none) {
6029 if (elem_ptr_ty.ptrInfo(zcu).flags.vector_index != .none) {
60306030 break :result if (self.reuseOperand(inst, extra.lhs, 0, base_ptr_mcv))
60316031 base_ptr_mcv
60326032 else
60336033 try self.copyToRegisterWithInstTracking(inst, elem_ptr_ty, base_ptr_mcv);
60346034 }
60356035
6036 const elem_ty = base_ptr_ty.elemType2(mod);
6037 const elem_abi_size = elem_ty.abiSize(pt);
6036 const elem_ty = base_ptr_ty.elemType2(zcu);
6037 const elem_abi_size = elem_ty.abiSize(zcu);
60386038 const index_ty = self.typeOf(extra.rhs);
60396039 const index_mcv = try self.resolveInst(extra.rhs);
60406040 const index_lock: ?RegisterLock = switch (index_mcv) {
......@@ -6057,12 +6057,12 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
60576057
60586058fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
60596059 const pt = self.pt;
6060 const mod = pt.zcu;
6060 const zcu = pt.zcu;
60616061 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
60626062 const ptr_union_ty = self.typeOf(bin_op.lhs);
6063 const union_ty = ptr_union_ty.childType(mod);
6063 const union_ty = ptr_union_ty.childType(zcu);
60646064 const tag_ty = self.typeOf(bin_op.rhs);
6065 const layout = union_ty.unionGetLayout(pt);
6065 const layout = union_ty.unionGetLayout(zcu);
60666066
60676067 if (layout.tag_size == 0) {
60686068 return self.finishAir(inst, .none, .{ bin_op.lhs, bin_op.rhs, .none });
......@@ -6101,12 +6101,12 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
61016101}
61026102
61036103fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
6104 const pt = self.pt;
6104 const zcu = self.pt.zcu;
61056105 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61066106
61076107 const tag_ty = self.typeOfIndex(inst);
61086108 const union_ty = self.typeOf(ty_op.operand);
6109 const layout = union_ty.unionGetLayout(pt);
6109 const layout = union_ty.unionGetLayout(zcu);
61106110
61116111 if (layout.tag_size == 0) {
61126112 return self.finishAir(inst, .none, .{ ty_op.operand, .none, .none });
......@@ -6120,7 +6120,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
61206120 };
61216121 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
61226122
6123 const tag_abi_size = tag_ty.abiSize(pt);
6123 const tag_abi_size = tag_ty.abiSize(zcu);
61246124 const dst_mcv: MCValue = blk: {
61256125 switch (operand) {
61266126 .load_frame => |frame_addr| {
......@@ -6159,14 +6159,14 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
61596159
61606160fn airClz(self: *Self, inst: Air.Inst.Index) !void {
61616161 const pt = self.pt;
6162 const mod = pt.zcu;
6162 const zcu = pt.zcu;
61636163 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61646164 const result = result: {
61656165 try self.spillEflagsIfOccupied();
61666166
61676167 const dst_ty = self.typeOfIndex(inst);
61686168 const src_ty = self.typeOf(ty_op.operand);
6169 if (src_ty.zigTypeTag(mod) == .Vector) return self.fail("TODO implement airClz for {}", .{
6169 if (src_ty.zigTypeTag(zcu) == .Vector) return self.fail("TODO implement airClz for {}", .{
61706170 src_ty.fmt(pt),
61716171 });
61726172
......@@ -6186,8 +6186,8 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
61866186 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
61876187 defer self.register_manager.unlockReg(dst_lock);
61886188
6189 const abi_size: u31 = @intCast(src_ty.abiSize(pt));
6190 const src_bits: u31 = @intCast(src_ty.bitSize(pt));
6189 const abi_size: u31 = @intCast(src_ty.abiSize(zcu));
6190 const src_bits: u31 = @intCast(src_ty.bitSize(zcu));
61916191 const has_lzcnt = self.hasFeature(.lzcnt);
61926192 if (src_bits > @as(u32, if (has_lzcnt) 128 else 64)) {
61936193 const limbs_len = math.divCeil(u32, abi_size, 8) catch unreachable;
......@@ -6297,7 +6297,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
62976297 }
62986298
62996299 assert(src_bits <= 64);
6300 const cmov_abi_size = @max(@as(u32, @intCast(dst_ty.abiSize(pt))), 2);
6300 const cmov_abi_size = @max(@as(u32, @intCast(dst_ty.abiSize(zcu))), 2);
63016301 if (math.isPowerOfTwo(src_bits)) {
63026302 const imm_reg = try self.copyToTmpRegister(dst_ty, .{
63036303 .immediate = src_bits ^ (src_bits - 1),
......@@ -6356,14 +6356,14 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
63566356
63576357fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
63586358 const pt = self.pt;
6359 const mod = pt.zcu;
6359 const zcu = pt.zcu;
63606360 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63616361 const result = result: {
63626362 try self.spillEflagsIfOccupied();
63636363
63646364 const dst_ty = self.typeOfIndex(inst);
63656365 const src_ty = self.typeOf(ty_op.operand);
6366 if (src_ty.zigTypeTag(mod) == .Vector) return self.fail("TODO implement airCtz for {}", .{
6366 if (src_ty.zigTypeTag(zcu) == .Vector) return self.fail("TODO implement airCtz for {}", .{
63676367 src_ty.fmt(pt),
63686368 });
63696369
......@@ -6383,8 +6383,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
63836383 const dst_lock = self.register_manager.lockReg(dst_reg);
63846384 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
63856385
6386 const abi_size: u31 = @intCast(src_ty.abiSize(pt));
6387 const src_bits: u31 = @intCast(src_ty.bitSize(pt));
6386 const abi_size: u31 = @intCast(src_ty.abiSize(zcu));
6387 const src_bits: u31 = @intCast(src_ty.bitSize(zcu));
63886388 const has_bmi = self.hasFeature(.bmi);
63896389 if (src_bits > @as(u32, if (has_bmi) 128 else 64)) {
63906390 const limbs_len = math.divCeil(u32, abi_size, 8) catch unreachable;
......@@ -6505,7 +6505,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
65056505 try self.genBinOpMir(.{ ._, .bsf }, wide_ty, dst_mcv, .{ .register = wide_reg });
65066506 } else try self.genBinOpMir(.{ ._, .bsf }, src_ty, dst_mcv, mat_src_mcv);
65076507
6508 const cmov_abi_size = @max(@as(u32, @intCast(dst_ty.abiSize(pt))), 2);
6508 const cmov_abi_size = @max(@as(u32, @intCast(dst_ty.abiSize(zcu))), 2);
65096509 try self.asmCmovccRegisterRegister(
65106510 .z,
65116511 registerAlias(dst_reg, cmov_abi_size),
......@@ -6518,14 +6518,14 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
65186518
65196519fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {
65206520 const pt = self.pt;
6521 const mod = pt.zcu;
6521 const zcu = pt.zcu;
65226522 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
65236523 const result: MCValue = result: {
65246524 try self.spillEflagsIfOccupied();
65256525
65266526 const src_ty = self.typeOf(ty_op.operand);
6527 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));
6528 if (src_ty.zigTypeTag(mod) == .Vector or src_abi_size > 16)
6527 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
6528 if (src_ty.zigTypeTag(zcu) == .Vector or src_abi_size > 16)
65296529 return self.fail("TODO implement airPopCount for {}", .{src_ty.fmt(pt)});
65306530 const src_mcv = try self.resolveInst(ty_op.operand);
65316531
......@@ -6562,7 +6562,7 @@ fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {
65626562 mat_src_mcv
65636563 else
65646564 .{ .register = mat_src_mcv.register_pair[0] }, false);
6565 const src_info = src_ty.intInfo(mod);
6565 const src_info = src_ty.intInfo(zcu);
65666566 const hi_ty = try pt.intType(src_info.signedness, (src_info.bits - 1) % 64 + 1);
65676567 try self.genPopCount(tmp_regs[1], hi_ty, if (mat_src_mcv.isMemory())
65686568 mat_src_mcv.address().offset(8).deref()
......@@ -6583,7 +6583,7 @@ fn genPopCount(
65836583) !void {
65846584 const pt = self.pt;
65856585
6586 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));
6586 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt.zcu));
65876587 if (self.hasFeature(.popcnt)) return self.genBinOpMir(
65886588 .{ ._, .popcnt },
65896589 if (src_abi_size > 1) src_ty else Type.u32,
......@@ -6674,11 +6674,11 @@ fn genByteSwap(
66746674 mem_ok: bool,
66756675) !MCValue {
66766676 const pt = self.pt;
6677 const mod = pt.zcu;
6677 const zcu = pt.zcu;
66786678 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
66796679 const has_movbe = self.hasFeature(.movbe);
66806680
6681 if (src_ty.zigTypeTag(mod) == .Vector) return self.fail(
6681 if (src_ty.zigTypeTag(zcu) == .Vector) return self.fail(
66826682 "TODO implement genByteSwap for {}",
66836683 .{src_ty.fmt(pt)},
66846684 );
......@@ -6689,7 +6689,7 @@ fn genByteSwap(
66896689 };
66906690 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
66916691
6692 const abi_size: u32 = @intCast(src_ty.abiSize(pt));
6692 const abi_size: u32 = @intCast(src_ty.abiSize(zcu));
66936693 switch (abi_size) {
66946694 0 => unreachable,
66956695 1 => return if ((mem_ok or src_mcv.isRegister()) and
......@@ -6838,35 +6838,35 @@ fn genByteSwap(
68386838
68396839fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
68406840 const pt = self.pt;
6841 const mod = pt.zcu;
6841 const zcu = pt.zcu;
68426842 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68436843
68446844 const src_ty = self.typeOf(ty_op.operand);
6845 const src_bits: u32 = @intCast(src_ty.bitSize(pt));
6845 const src_bits: u32 = @intCast(src_ty.bitSize(zcu));
68466846 const src_mcv = try self.resolveInst(ty_op.operand);
68476847
68486848 const dst_mcv = try self.genByteSwap(inst, src_ty, src_mcv, true);
68496849 try self.genShiftBinOpMir(
6850 .{ ._r, switch (if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned) {
6850 .{ ._r, switch (if (src_ty.isAbiInt(zcu)) src_ty.intInfo(zcu).signedness else .unsigned) {
68516851 .signed => .sa,
68526852 .unsigned => .sh,
68536853 } },
68546854 src_ty,
68556855 dst_mcv,
68566856 if (src_bits > 256) Type.u16 else Type.u8,
6857 .{ .immediate = src_ty.abiSize(pt) * 8 - src_bits },
6857 .{ .immediate = src_ty.abiSize(zcu) * 8 - src_bits },
68586858 );
68596859 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
68606860}
68616861
68626862fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
68636863 const pt = self.pt;
6864 const mod = pt.zcu;
6864 const zcu = pt.zcu;
68656865 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68666866
68676867 const src_ty = self.typeOf(ty_op.operand);
6868 const abi_size: u32 = @intCast(src_ty.abiSize(pt));
6869 const bit_size: u32 = @intCast(src_ty.bitSize(pt));
6868 const abi_size: u32 = @intCast(src_ty.abiSize(zcu));
6869 const bit_size: u32 = @intCast(src_ty.bitSize(zcu));
68706870 const src_mcv = try self.resolveInst(ty_op.operand);
68716871
68726872 const dst_mcv = try self.genByteSwap(inst, src_ty, src_mcv, false);
......@@ -6973,7 +6973,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
69736973
69746974 const extra_bits = abi_size * 8 - bit_size;
69756975 const signedness: std.builtin.Signedness =
6976 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
6976 if (src_ty.isAbiInt(zcu)) src_ty.intInfo(zcu).signedness else .unsigned;
69776977 if (extra_bits > 0) try self.genShiftBinOpMir(switch (signedness) {
69786978 .signed => .{ ._r, .sa },
69796979 .unsigned => .{ ._r, .sh },
......@@ -6984,13 +6984,13 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
69846984
69856985fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void {
69866986 const pt = self.pt;
6987 const mod = pt.zcu;
6987 const zcu = pt.zcu;
69886988 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
69896989
69906990 const result = result: {
6991 const scalar_bits = ty.scalarType(mod).floatBits(self.target.*);
6991 const scalar_bits = ty.scalarType(zcu).floatBits(self.target.*);
69926992 if (scalar_bits == 80) {
6993 if (ty.zigTypeTag(mod) != .Float) return self.fail("TODO implement floatSign for {}", .{
6993 if (ty.zigTypeTag(zcu) != .Float) return self.fail("TODO implement floatSign for {}", .{
69946994 ty.fmt(pt),
69956995 });
69966996
......@@ -7011,7 +7011,7 @@ fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type)
70117011 break :result dst_mcv;
70127012 }
70137013
7014 const abi_size: u32 = switch (ty.abiSize(pt)) {
7014 const abi_size: u32 = switch (ty.abiSize(zcu)) {
70157015 1...16 => 16,
70167016 17...32 => 32,
70177017 else => return self.fail("TODO implement floatSign for {}", .{
......@@ -7161,23 +7161,23 @@ fn airRound(self: *Self, inst: Air.Inst.Index, mode: RoundMode) !void {
71617161
71627162fn getRoundTag(self: *Self, ty: Type) ?Mir.Inst.FixedTag {
71637163 const pt = self.pt;
7164 const mod = pt.zcu;
7165 return if (self.hasFeature(.sse4_1)) switch (ty.zigTypeTag(mod)) {
7164 const zcu = pt.zcu;
7165 return if (self.hasFeature(.sse4_1)) switch (ty.zigTypeTag(zcu)) {
71667166 .Float => switch (ty.floatBits(self.target.*)) {
71677167 32 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
71687168 64 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
71697169 16, 80, 128 => null,
71707170 else => unreachable,
71717171 },
7172 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
7173 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
7174 32 => switch (ty.vectorLen(mod)) {
7172 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
7173 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
7174 32 => switch (ty.vectorLen(zcu)) {
71757175 1 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
71767176 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else .{ ._ps, .round },
71777177 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else null,
71787178 else => null,
71797179 },
7180 64 => switch (ty.vectorLen(mod)) {
7180 64 => switch (ty.vectorLen(zcu)) {
71817181 1 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
71827182 2 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else .{ ._pd, .round },
71837183 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else null,
......@@ -7194,10 +7194,10 @@ fn getRoundTag(self: *Self, ty: Type) ?Mir.Inst.FixedTag {
71947194
71957195fn genRoundLibcall(self: *Self, ty: Type, src_mcv: MCValue, mode: RoundMode) !MCValue {
71967196 const pt = self.pt;
7197 const mod = pt.zcu;
7197 const zcu = pt.zcu;
71987198 if (self.getRoundTag(ty)) |_| return .none;
71997199
7200 if (ty.zigTypeTag(mod) != .Float)
7200 if (ty.zigTypeTag(zcu) != .Float)
72017201 return self.fail("TODO implement genRound for {}", .{ty.fmt(pt)});
72027202
72037203 var callee_buf: ["__trunc?".len]u8 = undefined;
......@@ -7223,7 +7223,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro
72237223 const result = try self.genRoundLibcall(ty, src_mcv, mode);
72247224 return self.genSetReg(dst_reg, ty, result, .{});
72257225 };
7226 const abi_size: u32 = @intCast(ty.abiSize(pt));
7226 const abi_size: u32 = @intCast(ty.abiSize(pt.zcu));
72277227 const dst_alias = registerAlias(dst_reg, abi_size);
72287228 switch (mir_tag[0]) {
72297229 .v_ss, .v_sd => if (src_mcv.isMemory()) try self.asmRegisterRegisterMemoryImmediate(
......@@ -7261,14 +7261,14 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro
72617261
72627262fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
72637263 const pt = self.pt;
7264 const mod = pt.zcu;
7264 const zcu = pt.zcu;
72657265 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
72667266 const ty = self.typeOf(ty_op.operand);
72677267
72687268 const result: MCValue = result: {
7269 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(mod)) {
7269 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(zcu)) {
72707270 else => null,
7271 .Int => switch (ty.abiSize(pt)) {
7271 .Int => switch (ty.abiSize(zcu)) {
72727272 0 => unreachable,
72737273 1...8 => {
72747274 try self.spillEflagsIfOccupied();
......@@ -7277,7 +7277,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
72777277
72787278 try self.genUnOpMir(.{ ._, .neg }, ty, dst_mcv);
72797279
7280 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(pt))), 2);
7280 const cmov_abi_size = @max(@as(u32, @intCast(ty.abiSize(zcu))), 2);
72817281 switch (src_mcv) {
72827282 .register => |val_reg| try self.asmCmovccRegisterRegister(
72837283 .l,
......@@ -7336,7 +7336,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
73367336 break :result dst_mcv;
73377337 },
73387338 else => {
7339 const abi_size: u31 = @intCast(ty.abiSize(pt));
7339 const abi_size: u31 = @intCast(ty.abiSize(zcu));
73407340 const limb_len = math.divCeil(u31, abi_size, 8) catch unreachable;
73417341
73427342 const tmp_regs =
......@@ -7397,11 +7397,11 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
73977397 },
73987398 },
73997399 .Float => return self.floatSign(inst, ty_op.operand, ty),
7400 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
7400 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
74017401 else => null,
7402 .Int => switch (ty.childType(mod).intInfo(mod).bits) {
7402 .Int => switch (ty.childType(zcu).intInfo(zcu).bits) {
74037403 else => null,
7404 8 => switch (ty.vectorLen(mod)) {
7404 8 => switch (ty.vectorLen(zcu)) {
74057405 else => null,
74067406 1...16 => if (self.hasFeature(.avx))
74077407 .{ .vp_b, .abs }
......@@ -7411,7 +7411,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
74117411 null,
74127412 17...32 => if (self.hasFeature(.avx2)) .{ .vp_b, .abs } else null,
74137413 },
7414 16 => switch (ty.vectorLen(mod)) {
7414 16 => switch (ty.vectorLen(zcu)) {
74157415 else => null,
74167416 1...8 => if (self.hasFeature(.avx))
74177417 .{ .vp_w, .abs }
......@@ -7421,7 +7421,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
74217421 null,
74227422 9...16 => if (self.hasFeature(.avx2)) .{ .vp_w, .abs } else null,
74237423 },
7424 32 => switch (ty.vectorLen(mod)) {
7424 32 => switch (ty.vectorLen(zcu)) {
74257425 else => null,
74267426 1...4 => if (self.hasFeature(.avx))
74277427 .{ .vp_d, .abs }
......@@ -7436,7 +7436,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
74367436 },
74377437 }) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
74387438
7439 const abi_size: u32 = @intCast(ty.abiSize(pt));
7439 const abi_size: u32 = @intCast(ty.abiSize(zcu));
74407440 const src_mcv = try self.resolveInst(ty_op.operand);
74417441 const dst_reg = if (src_mcv.isRegister() and self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
74427442 src_mcv.getReg().?
......@@ -7462,13 +7462,13 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
74627462
74637463fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
74647464 const pt = self.pt;
7465 const mod = pt.zcu;
7465 const zcu = pt.zcu;
74667466 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
74677467 const ty = self.typeOf(un_op);
7468 const abi_size: u32 = @intCast(ty.abiSize(pt));
7468 const abi_size: u32 = @intCast(ty.abiSize(zcu));
74697469
74707470 const result: MCValue = result: {
7471 switch (ty.zigTypeTag(mod)) {
7471 switch (ty.zigTypeTag(zcu)) {
74727472 .Float => {
74737473 const float_bits = ty.floatBits(self.target.*);
74747474 if (switch (float_bits) {
......@@ -7500,7 +7500,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
75007500 const dst_lock = self.register_manager.lockReg(dst_reg);
75017501 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
75027502
7503 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(mod)) {
7503 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.zigTypeTag(zcu)) {
75047504 .Float => switch (ty.floatBits(self.target.*)) {
75057505 16 => {
75067506 assert(self.hasFeature(.f16c));
......@@ -7522,9 +7522,9 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
75227522 64 => if (self.hasFeature(.avx)) .{ .v_sd, .sqrt } else .{ ._sd, .sqrt },
75237523 else => unreachable,
75247524 },
7525 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
7526 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
7527 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(mod)) {
7525 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
7526 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
7527 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(zcu)) {
75287528 1 => {
75297529 try self.asmRegisterRegister(
75307530 .{ .v_ps, .cvtph2 },
......@@ -7575,13 +7575,13 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
75757575 },
75767576 else => null,
75777577 } else null,
7578 32 => switch (ty.vectorLen(mod)) {
7578 32 => switch (ty.vectorLen(zcu)) {
75797579 1 => if (self.hasFeature(.avx)) .{ .v_ss, .sqrt } else .{ ._ss, .sqrt },
75807580 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else .{ ._ps, .sqrt },
75817581 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else null,
75827582 else => null,
75837583 },
7584 64 => switch (ty.vectorLen(mod)) {
7584 64 => switch (ty.vectorLen(zcu)) {
75857585 1 => if (self.hasFeature(.avx)) .{ .v_sd, .sqrt } else .{ ._sd, .sqrt },
75867586 2 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else .{ ._pd, .sqrt },
75877587 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else null,
......@@ -7708,14 +7708,14 @@ fn reuseOperandAdvanced(
77087708
77097709fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {
77107710 const pt = self.pt;
7711 const mod = pt.zcu;
7711 const zcu = pt.zcu;
77127712
7713 const ptr_info = ptr_ty.ptrInfo(mod);
7713 const ptr_info = ptr_ty.ptrInfo(zcu);
77147714 const val_ty = Type.fromInterned(ptr_info.child);
7715 if (!val_ty.hasRuntimeBitsIgnoreComptime(pt)) return;
7716 const val_abi_size: u32 = @intCast(val_ty.abiSize(pt));
7715 if (!val_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
7716 const val_abi_size: u32 = @intCast(val_ty.abiSize(zcu));
77177717
7718 const val_bit_size: u32 = @intCast(val_ty.bitSize(pt));
7718 const val_bit_size: u32 = @intCast(val_ty.bitSize(zcu));
77197719 const ptr_bit_off = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
77207720 .none => 0,
77217721 .runtime => unreachable,
......@@ -7821,9 +7821,9 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
78217821
78227822fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {
78237823 const pt = self.pt;
7824 const mod = pt.zcu;
7825 const dst_ty = ptr_ty.childType(mod);
7826 if (!dst_ty.hasRuntimeBitsIgnoreComptime(pt)) return;
7824 const zcu = pt.zcu;
7825 const dst_ty = ptr_ty.childType(zcu);
7826 if (!dst_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
78277827 switch (ptr_mcv) {
78287828 .none,
78297829 .unreach,
......@@ -7864,18 +7864,18 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro
78647864
78657865fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
78667866 const pt = self.pt;
7867 const mod = pt.zcu;
7867 const zcu = pt.zcu;
78687868 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
78697869 const elem_ty = self.typeOfIndex(inst);
78707870 const result: MCValue = result: {
7871 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
7871 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
78727872
78737873 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
78747874 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
78757875 defer for (reg_locks) |lock| self.register_manager.unlockReg(lock);
78767876
78777877 const ptr_ty = self.typeOf(ty_op.operand);
7878 const elem_size = elem_ty.abiSize(pt);
7878 const elem_size = elem_ty.abiSize(zcu);
78797879
78807880 const elem_rc = self.regClassForType(elem_ty);
78817881 const ptr_rc = self.regClassForType(ptr_ty);
......@@ -7888,14 +7888,14 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
78887888 else
78897889 try self.allocRegOrMem(inst, true);
78907890
7891 const ptr_info = ptr_ty.ptrInfo(mod);
7891 const ptr_info = ptr_ty.ptrInfo(zcu);
78927892 if (ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0) {
78937893 try self.packedLoad(dst_mcv, ptr_ty, ptr_mcv);
78947894 } else {
78957895 try self.load(dst_mcv, ptr_ty, ptr_mcv);
78967896 }
78977897
7898 if (elem_ty.isAbiInt(mod) and elem_size * 8 > elem_ty.bitSize(pt)) {
7898 if (elem_ty.isAbiInt(zcu) and elem_size * 8 > elem_ty.bitSize(zcu)) {
78997899 const high_mcv: MCValue = switch (dst_mcv) {
79007900 .register => |dst_reg| .{ .register = dst_reg },
79017901 .register_pair => |dst_regs| .{ .register = dst_regs[1] },
......@@ -7923,16 +7923,16 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
79237923
79247924fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) InnerError!void {
79257925 const pt = self.pt;
7926 const mod = pt.zcu;
7927 const ptr_info = ptr_ty.ptrInfo(mod);
7926 const zcu = pt.zcu;
7927 const ptr_info = ptr_ty.ptrInfo(zcu);
79287928 const src_ty = Type.fromInterned(ptr_info.child);
7929 if (!src_ty.hasRuntimeBitsIgnoreComptime(pt)) return;
7929 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
79307930
79317931 const limb_abi_size: u16 = @min(ptr_info.packed_offset.host_size, 8);
79327932 const limb_abi_bits = limb_abi_size * 8;
79337933 const limb_ty = try pt.intType(.unsigned, limb_abi_bits);
79347934
7935 const src_bit_size = src_ty.bitSize(pt);
7935 const src_bit_size = src_ty.bitSize(zcu);
79367936 const ptr_bit_off = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
79377937 .none => 0,
79387938 .runtime => unreachable,
......@@ -8029,9 +8029,9 @@ fn store(
80298029 opts: CopyOptions,
80308030) InnerError!void {
80318031 const pt = self.pt;
8032 const mod = pt.zcu;
8033 const src_ty = ptr_ty.childType(mod);
8034 if (!src_ty.hasRuntimeBitsIgnoreComptime(pt)) return;
8032 const zcu = pt.zcu;
8033 const src_ty = ptr_ty.childType(zcu);
8034 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
80358035 switch (ptr_mcv) {
80368036 .none,
80378037 .unreach,
......@@ -8072,7 +8072,7 @@ fn store(
80728072
80738073fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
80748074 const pt = self.pt;
8075 const mod = pt.zcu;
8075 const zcu = pt.zcu;
80768076 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
80778077
80788078 result: {
......@@ -8086,7 +8086,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
80868086 const ptr_mcv = try self.resolveInst(bin_op.lhs);
80878087 const ptr_ty = self.typeOf(bin_op.lhs);
80888088
8089 const ptr_info = ptr_ty.ptrInfo(mod);
8089 const ptr_info = ptr_ty.ptrInfo(zcu);
80908090 if (ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0) {
80918091 try self.packedStore(ptr_ty, ptr_mcv, src_mcv);
80928092 } else {
......@@ -8111,16 +8111,16 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
81118111
81128112fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
81138113 const pt = self.pt;
8114 const mod = pt.zcu;
8114 const zcu = pt.zcu;
81158115 const ptr_field_ty = self.typeOfIndex(inst);
81168116 const ptr_container_ty = self.typeOf(operand);
8117 const container_ty = ptr_container_ty.childType(mod);
8117 const container_ty = ptr_container_ty.childType(zcu);
81188118
8119 const field_off: i32 = switch (container_ty.containerLayout(mod)) {
8120 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(index, pt)),
8121 .@"packed" => @divExact(@as(i32, ptr_container_ty.ptrInfo(mod).packed_offset.bit_offset) +
8122 (if (mod.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, index) else 0) -
8123 ptr_field_ty.ptrInfo(mod).packed_offset.bit_offset, 8),
8119 const field_off: i32 = switch (container_ty.containerLayout(zcu)) {
8120 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(index, zcu)),
8121 .@"packed" => @divExact(@as(i32, ptr_container_ty.ptrInfo(zcu).packed_offset.bit_offset) +
8122 (if (zcu.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, index) else 0) -
8123 ptr_field_ty.ptrInfo(zcu).packed_offset.bit_offset, 8),
81248124 };
81258125
81268126 const src_mcv = try self.resolveInst(operand);
......@@ -8134,7 +8134,7 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
81348134
81358135fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
81368136 const pt = self.pt;
8137 const mod = pt.zcu;
8137 const zcu = pt.zcu;
81388138 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
81398139 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
81408140 const result: MCValue = result: {
......@@ -8143,15 +8143,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
81438143
81448144 const container_ty = self.typeOf(operand);
81458145 const container_rc = self.regClassForType(container_ty);
8146 const field_ty = container_ty.structFieldType(index, mod);
8147 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
8146 const field_ty = container_ty.structFieldType(index, zcu);
8147 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
81488148 const field_rc = self.regClassForType(field_ty);
81498149 const field_is_gp = field_rc.supersetOf(abi.RegisterClass.gp);
81508150
81518151 const src_mcv = try self.resolveInst(operand);
8152 const field_off: u32 = switch (container_ty.containerLayout(mod)) {
8153 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(extra.field_index, pt) * 8),
8154 .@"packed" => if (mod.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, extra.field_index) else 0,
8152 const field_off: u32 = switch (container_ty.containerLayout(zcu)) {
8153 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(extra.field_index, zcu) * 8),
8154 .@"packed" => if (zcu.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, extra.field_index) else 0,
81558155 };
81568156
81578157 switch (src_mcv) {
......@@ -8182,7 +8182,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
81828182 );
81838183 }
81848184 if (abi.RegisterClass.gp.isSet(RegisterManager.indexOfRegIntoTracked(dst_reg).?) and
8185 container_ty.abiSize(pt) * 8 > field_ty.bitSize(pt))
8185 container_ty.abiSize(zcu) * 8 > field_ty.bitSize(zcu))
81868186 try self.truncateRegister(field_ty, dst_reg);
81878187
81888188 break :result if (field_off == 0 or field_rc.supersetOf(abi.RegisterClass.gp))
......@@ -8194,7 +8194,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
81948194 const src_regs_lock = self.register_manager.lockRegsAssumeUnused(2, src_regs);
81958195 defer for (src_regs_lock) |lock| self.register_manager.unlockReg(lock);
81968196
8197 const field_bit_size: u32 = @intCast(field_ty.bitSize(pt));
8197 const field_bit_size: u32 = @intCast(field_ty.bitSize(zcu));
81988198 const src_reg = if (field_off + field_bit_size <= 64)
81998199 src_regs[0]
82008200 else if (field_off >= 64)
......@@ -8293,15 +8293,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
82938293 }
82948294 },
82958295 .load_frame => |frame_addr| {
8296 const field_abi_size: u32 = @intCast(field_ty.abiSize(pt));
8296 const field_abi_size: u32 = @intCast(field_ty.abiSize(zcu));
82978297 if (field_off % 8 == 0) {
82988298 const field_byte_off = @divExact(field_off, 8);
82998299 const off_mcv = src_mcv.address().offset(@intCast(field_byte_off)).deref();
8300 const field_bit_size = field_ty.bitSize(pt);
8300 const field_bit_size = field_ty.bitSize(zcu);
83018301
83028302 if (field_abi_size <= 8) {
83038303 const int_ty = try pt.intType(
8304 if (field_ty.isAbiInt(mod)) field_ty.intInfo(mod).signedness else .unsigned,
8304 if (field_ty.isAbiInt(zcu)) field_ty.intInfo(zcu).signedness else .unsigned,
83058305 @intCast(field_bit_size),
83068306 );
83078307
......@@ -8321,7 +8321,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
83218321 try self.copyToRegisterWithInstTracking(inst, field_ty, dst_mcv);
83228322 }
83238323
8324 const container_abi_size: u32 = @intCast(container_ty.abiSize(pt));
8324 const container_abi_size: u32 = @intCast(container_ty.abiSize(zcu));
83258325 const dst_mcv = if (field_byte_off + field_abi_size <= container_abi_size and
83268326 self.reuseOperand(inst, operand, 0, src_mcv))
83278327 off_mcv
......@@ -8423,17 +8423,17 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
84238423
84248424fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
84258425 const pt = self.pt;
8426 const mod = pt.zcu;
8426 const zcu = pt.zcu;
84278427 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
84288428 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
84298429
84308430 const inst_ty = self.typeOfIndex(inst);
8431 const parent_ty = inst_ty.childType(mod);
8432 const field_off: i32 = switch (parent_ty.containerLayout(mod)) {
8433 .auto, .@"extern" => @intCast(parent_ty.structFieldOffset(extra.field_index, pt)),
8434 .@"packed" => @divExact(@as(i32, inst_ty.ptrInfo(mod).packed_offset.bit_offset) +
8435 (if (mod.typeToStruct(parent_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, extra.field_index) else 0) -
8436 self.typeOf(extra.field_ptr).ptrInfo(mod).packed_offset.bit_offset, 8),
8431 const parent_ty = inst_ty.childType(zcu);
8432 const field_off: i32 = switch (parent_ty.containerLayout(zcu)) {
8433 .auto, .@"extern" => @intCast(parent_ty.structFieldOffset(extra.field_index, zcu)),
8434 .@"packed" => @divExact(@as(i32, inst_ty.ptrInfo(zcu).packed_offset.bit_offset) +
8435 (if (zcu.typeToStruct(parent_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, extra.field_index) else 0) -
8436 self.typeOf(extra.field_ptr).ptrInfo(zcu).packed_offset.bit_offset, 8),
84378437 };
84388438
84398439 const src_mcv = try self.resolveInst(extra.field_ptr);
......@@ -8448,9 +8448,9 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
84488448
84498449fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air: Air.Inst.Ref) !MCValue {
84508450 const pt = self.pt;
8451 const mod = pt.zcu;
8451 const zcu = pt.zcu;
84528452 const src_ty = self.typeOf(src_air);
8453 if (src_ty.zigTypeTag(mod) == .Vector)
8453 if (src_ty.zigTypeTag(zcu) == .Vector)
84548454 return self.fail("TODO implement genUnOp for {}", .{src_ty.fmt(pt)});
84558455
84568456 var src_mcv = try self.resolveInst(src_air);
......@@ -8486,14 +8486,14 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
84868486 };
84878487 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
84888488
8489 const abi_size: u16 = @intCast(src_ty.abiSize(pt));
8489 const abi_size: u16 = @intCast(src_ty.abiSize(zcu));
84908490 switch (tag) {
84918491 .not => {
84928492 const limb_abi_size: u16 = @min(abi_size, 8);
84938493 const int_info = if (src_ty.ip_index == .bool_type)
84948494 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }
84958495 else
8496 src_ty.intInfo(mod);
8496 src_ty.intInfo(zcu);
84978497 var byte_off: i32 = 0;
84988498 while (byte_off * 8 < int_info.bits) : (byte_off += limb_abi_size) {
84998499 const limb_bits: u16 = @intCast(@min(switch (int_info.signedness) {
......@@ -8514,7 +8514,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
85148514 },
85158515 .neg => {
85168516 try self.genUnOpMir(.{ ._, .neg }, src_ty, dst_mcv);
8517 const bit_size = src_ty.intInfo(mod).bits;
8517 const bit_size = src_ty.intInfo(zcu).bits;
85188518 if (abi_size * 8 > bit_size) {
85198519 if (dst_mcv.isRegister()) {
85208520 try self.truncateRegister(src_ty, dst_mcv.getReg().?);
......@@ -8537,7 +8537,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
85378537
85388538fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
85398539 const pt = self.pt;
8540 const abi_size: u32 = @intCast(dst_ty.abiSize(pt));
8540 const abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu));
85418541 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{ mir_tag, dst_ty.fmt(pt) });
85428542 switch (dst_mcv) {
85438543 .none,
......@@ -8586,8 +8586,9 @@ fn genShiftBinOpMir(
85868586 rhs_mcv: MCValue,
85878587) !void {
85888588 const pt = self.pt;
8589 const abi_size: u32 = @intCast(lhs_ty.abiSize(pt));
8590 const shift_abi_size: u32 = @intCast(rhs_ty.abiSize(pt));
8589 const zcu = pt.zcu;
8590 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
8591 const shift_abi_size: u32 = @intCast(rhs_ty.abiSize(zcu));
85918592 try self.spillEflagsIfOccupied();
85928593
85938594 if (abi_size > 16) {
......@@ -9243,8 +9244,8 @@ fn genShiftBinOp(
92439244 rhs_ty: Type,
92449245) !MCValue {
92459246 const pt = self.pt;
9246 const mod = pt.zcu;
9247 if (lhs_ty.zigTypeTag(mod) == .Vector) return self.fail("TODO implement genShiftBinOp for {}", .{
9247 const zcu = pt.zcu;
9248 if (lhs_ty.zigTypeTag(zcu) == .Vector) return self.fail("TODO implement genShiftBinOp for {}", .{
92489249 lhs_ty.fmt(pt),
92499250 });
92509251
......@@ -9274,7 +9275,7 @@ fn genShiftBinOp(
92749275 break :dst dst_mcv;
92759276 };
92769277
9277 const signedness = lhs_ty.intInfo(mod).signedness;
9278 const signedness = lhs_ty.intInfo(zcu).signedness;
92789279 try self.genShiftBinOpMir(switch (air_tag) {
92799280 .shl, .shl_exact => switch (signedness) {
92809281 .signed => .{ ._l, .sa },
......@@ -9302,13 +9303,13 @@ fn genMulDivBinOp(
93029303 rhs_mcv: MCValue,
93039304) !MCValue {
93049305 const pt = self.pt;
9305 const mod = pt.zcu;
9306 if (dst_ty.zigTypeTag(mod) == .Vector or dst_ty.zigTypeTag(mod) == .Float) return self.fail(
9306 const zcu = pt.zcu;
9307 if (dst_ty.zigTypeTag(zcu) == .Vector or dst_ty.zigTypeTag(zcu) == .Float) return self.fail(
93079308 "TODO implement genMulDivBinOp for {s} from {} to {}",
93089309 .{ @tagName(tag), src_ty.fmt(pt), dst_ty.fmt(pt) },
93099310 );
9310 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));
9311 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));
9311 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
9312 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
93129313
93139314 assert(self.register_manager.isRegFree(.rax));
93149315 assert(self.register_manager.isRegFree(.rcx));
......@@ -9384,7 +9385,7 @@ fn genMulDivBinOp(
93849385 .mul, .mul_wrap => dst_abi_size != src_abi_size and dst_abi_size != src_abi_size * 2,
93859386 .div_trunc, .div_floor, .div_exact, .rem, .mod => dst_abi_size != src_abi_size,
93869387 } or src_abi_size > 8) {
9387 const src_info = src_ty.intInfo(mod);
9388 const src_info = src_ty.intInfo(zcu);
93889389 switch (tag) {
93899390 .mul, .mul_wrap => {
93909391 const slow_inc = self.hasFeature(.slow_incdec);
......@@ -9555,7 +9556,7 @@ fn genMulDivBinOp(
95559556 const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx });
95569557 defer for (reg_locks) |reg_lock| if (reg_lock) |lock| self.register_manager.unlockReg(lock);
95579558
9558 const signedness = ty.intInfo(mod).signedness;
9559 const signedness = ty.intInfo(zcu).signedness;
95599560 switch (tag) {
95609561 .mul,
95619562 .mul_wrap,
......@@ -9714,10 +9715,10 @@ fn genBinOp(
97149715 rhs_air: Air.Inst.Ref,
97159716) !MCValue {
97169717 const pt = self.pt;
9717 const mod = pt.zcu;
9718 const zcu = pt.zcu;
97189719 const lhs_ty = self.typeOf(lhs_air);
97199720 const rhs_ty = self.typeOf(rhs_air);
9720 const abi_size: u32 = @intCast(lhs_ty.abiSize(pt));
9721 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
97219722
97229723 if (lhs_ty.isRuntimeFloat()) libcall: {
97239724 const float_bits = lhs_ty.floatBits(self.target.*);
......@@ -9889,23 +9890,23 @@ fn genBinOp(
98899890 };
98909891 }
98919892
9892 const sse_op = switch (lhs_ty.zigTypeTag(mod)) {
9893 const sse_op = switch (lhs_ty.zigTypeTag(zcu)) {
98939894 else => false,
98949895 .Float => true,
9895 .Vector => switch (lhs_ty.childType(mod).toIntern()) {
9896 .Vector => switch (lhs_ty.childType(zcu).toIntern()) {
98969897 .bool_type, .u1_type => false,
98979898 else => true,
98989899 },
98999900 };
9900 if (sse_op and ((lhs_ty.scalarType(mod).isRuntimeFloat() and
9901 lhs_ty.scalarType(mod).floatBits(self.target.*) == 80) or
9902 lhs_ty.abiSize(pt) > @as(u6, if (self.hasFeature(.avx)) 32 else 16)))
9901 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and
9902 lhs_ty.scalarType(zcu).floatBits(self.target.*) == 80) or
9903 lhs_ty.abiSize(zcu) > @as(u6, if (self.hasFeature(.avx)) 32 else 16)))
99039904 return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });
99049905
99059906 const maybe_mask_reg = switch (air_tag) {
99069907 else => null,
99079908 .rem, .mod => unreachable,
9908 .max, .min => if (lhs_ty.scalarType(mod).isRuntimeFloat()) registerAlias(
9909 .max, .min => if (lhs_ty.scalarType(zcu).isRuntimeFloat()) registerAlias(
99099910 if (!self.hasFeature(.avx) and self.hasFeature(.sse4_1)) mask: {
99109911 try self.register_manager.getKnownReg(.xmm0, null);
99119912 break :mask .xmm0;
......@@ -9917,8 +9918,8 @@ fn genBinOp(
99179918 if (maybe_mask_reg) |mask_reg| self.register_manager.lockRegAssumeUnused(mask_reg) else null;
99189919 defer if (mask_lock) |lock| self.register_manager.unlockReg(lock);
99199920
9920 const ordered_air: [2]Air.Inst.Ref = if (lhs_ty.isVector(mod) and
9921 switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
9921 const ordered_air: [2]Air.Inst.Ref = if (lhs_ty.isVector(zcu) and
9922 switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
99229923 .Bool => false,
99239924 .Int => switch (air_tag) {
99249925 .cmp_lt, .cmp_gte => true,
......@@ -9931,7 +9932,7 @@ fn genBinOp(
99319932 else => unreachable,
99329933 }) .{ rhs_air, lhs_air } else .{ lhs_air, rhs_air };
99339934
9934 if (lhs_ty.isAbiInt(mod)) for (ordered_air) |op_air| {
9935 if (lhs_ty.isAbiInt(zcu)) for (ordered_air) |op_air| {
99359936 switch (try self.resolveInst(op_air)) {
99369937 .register => |op_reg| switch (op_reg.class()) {
99379938 .sse => try self.register_manager.getReg(op_reg, null),
......@@ -10056,7 +10057,7 @@ fn genBinOp(
1005610057 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
1005710058 defer self.register_manager.unlockReg(tmp_lock);
1005810059
10059 const elem_size = lhs_ty.elemType2(mod).abiSize(pt);
10060 const elem_size = lhs_ty.elemType2(zcu).abiSize(zcu);
1006010061 try self.genIntMulComplexOpMir(rhs_ty, tmp_mcv, .{ .immediate = elem_size });
1006110062 try self.genBinOpMir(
1006210063 switch (air_tag) {
......@@ -10112,7 +10113,7 @@ fn genBinOp(
1011210113 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
1011310114 defer self.register_manager.unlockReg(tmp_lock);
1011410115
10115 const signed = lhs_ty.isSignedInt(mod);
10116 const signed = lhs_ty.isSignedInt(zcu);
1011610117 const cc: Condition = switch (air_tag) {
1011710118 .min => if (signed) .nl else .nb,
1011810119 .max => if (signed) .nge else .nae,
......@@ -10188,7 +10189,7 @@ fn genBinOp(
1018810189
1018910190 try self.genBinOpMir(.{ ._, .cmp }, lhs_ty, dst_mcv, mat_src_mcv);
1019010191
10191 const int_info = lhs_ty.intInfo(mod);
10192 const int_info = lhs_ty.intInfo(zcu);
1019210193 const cc: Condition = switch (int_info.signedness) {
1019310194 .unsigned => switch (air_tag) {
1019410195 .min => .a,
......@@ -10202,7 +10203,7 @@ fn genBinOp(
1020210203 },
1020310204 };
1020410205
10205 const cmov_abi_size = @max(@as(u32, @intCast(lhs_ty.abiSize(pt))), 2);
10206 const cmov_abi_size = @max(@as(u32, @intCast(lhs_ty.abiSize(zcu))), 2);
1020610207 const tmp_reg = switch (dst_mcv) {
1020710208 .register => |reg| reg,
1020810209 else => try self.copyToTmpRegister(lhs_ty, dst_mcv),
......@@ -10271,7 +10272,7 @@ fn genBinOp(
1027110272 },
1027210273
1027310274 .cmp_eq, .cmp_neq => {
10274 assert(lhs_ty.isVector(mod) and lhs_ty.childType(mod).toIntern() == .bool_type);
10275 assert(lhs_ty.isVector(zcu) and lhs_ty.childType(zcu).toIntern() == .bool_type);
1027510276 try self.genBinOpMir(.{ ._, .xor }, lhs_ty, dst_mcv, src_mcv);
1027610277 switch (air_tag) {
1027710278 .cmp_eq => try self.genUnOpMir(.{ ._, .not }, lhs_ty, dst_mcv),
......@@ -10288,7 +10289,7 @@ fn genBinOp(
1028810289 }
1028910290
1029010291 const dst_reg = registerAlias(dst_mcv.getReg().?, abi_size);
10291 const mir_tag = @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
10292 const mir_tag = @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
1029210293 else => unreachable,
1029310294 .Float => switch (lhs_ty.floatBits(self.target.*)) {
1029410295 16 => {
......@@ -10383,10 +10384,10 @@ fn genBinOp(
1038310384 80, 128 => null,
1038410385 else => unreachable,
1038510386 },
10386 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
10387 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
1038710388 else => null,
10388 .Int => switch (lhs_ty.childType(mod).intInfo(mod).bits) {
10389 8 => switch (lhs_ty.vectorLen(mod)) {
10389 .Int => switch (lhs_ty.childType(zcu).intInfo(zcu).bits) {
10390 8 => switch (lhs_ty.vectorLen(zcu)) {
1039010391 1...16 => switch (air_tag) {
1039110392 .add,
1039210393 .add_wrap,
......@@ -10400,7 +10401,7 @@ fn genBinOp(
1040010401 .{ .p_, .@"and" },
1040110402 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
1040210403 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },
10403 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10404 .min => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1040410405 .signed => if (self.hasFeature(.avx))
1040510406 .{ .vp_b, .mins }
1040610407 else if (self.hasFeature(.sse4_1))
......@@ -10414,7 +10415,7 @@ fn genBinOp(
1041410415 else
1041510416 null,
1041610417 },
10417 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10418 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1041810419 .signed => if (self.hasFeature(.avx))
1041910420 .{ .vp_b, .maxs }
1042010421 else if (self.hasFeature(.sse4_1))
......@@ -10432,7 +10433,7 @@ fn genBinOp(
1043210433 .cmp_lte,
1043310434 .cmp_gte,
1043410435 .cmp_gt,
10435 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10436 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1043610437 .signed => if (self.hasFeature(.avx))
1043710438 .{ .vp_b, .cmpgt }
1043810439 else
......@@ -10454,11 +10455,11 @@ fn genBinOp(
1045410455 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
1045510456 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
1045610457 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,
10457 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10458 .min => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1045810459 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .mins } else null,
1045910460 .unsigned => if (self.hasFeature(.avx)) .{ .vp_b, .minu } else null,
1046010461 },
10461 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10462 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1046210463 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .maxs } else null,
1046310464 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_b, .maxu } else null,
1046410465 },
......@@ -10466,7 +10467,7 @@ fn genBinOp(
1046610467 .cmp_lte,
1046710468 .cmp_gte,
1046810469 .cmp_gt,
10469 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10470 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1047010471 .signed => if (self.hasFeature(.avx)) .{ .vp_b, .cmpgt } else null,
1047110472 .unsigned => null,
1047210473 },
......@@ -10477,7 +10478,7 @@ fn genBinOp(
1047710478 },
1047810479 else => null,
1047910480 },
10480 16 => switch (lhs_ty.vectorLen(mod)) {
10481 16 => switch (lhs_ty.vectorLen(zcu)) {
1048110482 1...8 => switch (air_tag) {
1048210483 .add,
1048310484 .add_wrap,
......@@ -10494,7 +10495,7 @@ fn genBinOp(
1049410495 .{ .p_, .@"and" },
1049510496 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
1049610497 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },
10497 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10498 .min => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1049810499 .signed => if (self.hasFeature(.avx))
1049910500 .{ .vp_w, .mins }
1050010501 else
......@@ -10504,7 +10505,7 @@ fn genBinOp(
1050410505 else
1050510506 .{ .p_w, .minu },
1050610507 },
10507 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10508 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1050810509 .signed => if (self.hasFeature(.avx))
1050910510 .{ .vp_w, .maxs }
1051010511 else
......@@ -10518,7 +10519,7 @@ fn genBinOp(
1051810519 .cmp_lte,
1051910520 .cmp_gte,
1052010521 .cmp_gt,
10521 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10522 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1052210523 .signed => if (self.hasFeature(.avx))
1052310524 .{ .vp_w, .cmpgt }
1052410525 else
......@@ -10543,11 +10544,11 @@ fn genBinOp(
1054310544 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
1054410545 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
1054510546 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,
10546 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10547 .min => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1054710548 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .mins } else null,
1054810549 .unsigned => if (self.hasFeature(.avx)) .{ .vp_w, .minu } else null,
1054910550 },
10550 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10551 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1055110552 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .maxs } else null,
1055210553 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_w, .maxu } else null,
1055310554 },
......@@ -10555,7 +10556,7 @@ fn genBinOp(
1055510556 .cmp_lte,
1055610557 .cmp_gte,
1055710558 .cmp_gt,
10558 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10559 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1055910560 .signed => if (self.hasFeature(.avx)) .{ .vp_w, .cmpgt } else null,
1056010561 .unsigned => null,
1056110562 },
......@@ -10566,7 +10567,7 @@ fn genBinOp(
1056610567 },
1056710568 else => null,
1056810569 },
10569 32 => switch (lhs_ty.vectorLen(mod)) {
10570 32 => switch (lhs_ty.vectorLen(zcu)) {
1057010571 1...4 => switch (air_tag) {
1057110572 .add,
1057210573 .add_wrap,
......@@ -10588,7 +10589,7 @@ fn genBinOp(
1058810589 .{ .p_, .@"and" },
1058910590 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
1059010591 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },
10591 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10592 .min => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1059210593 .signed => if (self.hasFeature(.avx))
1059310594 .{ .vp_d, .mins }
1059410595 else if (self.hasFeature(.sse4_1))
......@@ -10602,7 +10603,7 @@ fn genBinOp(
1060210603 else
1060310604 null,
1060410605 },
10605 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10606 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1060610607 .signed => if (self.hasFeature(.avx))
1060710608 .{ .vp_d, .maxs }
1060810609 else if (self.hasFeature(.sse4_1))
......@@ -10620,7 +10621,7 @@ fn genBinOp(
1062010621 .cmp_lte,
1062110622 .cmp_gte,
1062210623 .cmp_gt,
10623 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10624 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1062410625 .signed => if (self.hasFeature(.avx))
1062510626 .{ .vp_d, .cmpgt }
1062610627 else
......@@ -10645,11 +10646,11 @@ fn genBinOp(
1064510646 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
1064610647 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
1064710648 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,
10648 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10649 .min => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1064910650 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .mins } else null,
1065010651 .unsigned => if (self.hasFeature(.avx)) .{ .vp_d, .minu } else null,
1065110652 },
10652 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10653 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1065310654 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .maxs } else null,
1065410655 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_d, .maxu } else null,
1065510656 },
......@@ -10657,7 +10658,7 @@ fn genBinOp(
1065710658 .cmp_lte,
1065810659 .cmp_gte,
1065910660 .cmp_gt,
10660 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10661 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1066110662 .signed => if (self.hasFeature(.avx)) .{ .vp_d, .cmpgt } else null,
1066210663 .unsigned => null,
1066310664 },
......@@ -10668,7 +10669,7 @@ fn genBinOp(
1066810669 },
1066910670 else => null,
1067010671 },
10671 64 => switch (lhs_ty.vectorLen(mod)) {
10672 64 => switch (lhs_ty.vectorLen(zcu)) {
1067210673 1...2 => switch (air_tag) {
1067310674 .add,
1067410675 .add_wrap,
......@@ -10686,7 +10687,7 @@ fn genBinOp(
1068610687 .cmp_lte,
1068710688 .cmp_gte,
1068810689 .cmp_gt,
10689 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10690 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1069010691 .signed => if (self.hasFeature(.avx))
1069110692 .{ .vp_q, .cmpgt }
1069210693 else if (self.hasFeature(.sse4_2))
......@@ -10722,7 +10723,7 @@ fn genBinOp(
1072210723 .cmp_lte,
1072310724 .cmp_gt,
1072410725 .cmp_gte,
10725 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
10726 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
1072610727 .signed => if (self.hasFeature(.avx)) .{ .vp_d, .cmpgt } else null,
1072710728 .unsigned => null,
1072810729 },
......@@ -10732,10 +10733,10 @@ fn genBinOp(
1073210733 },
1073310734 else => null,
1073410735 },
10735 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
10736 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
1073610737 16 => tag: {
1073710738 assert(self.hasFeature(.f16c));
10738 switch (lhs_ty.vectorLen(mod)) {
10739 switch (lhs_ty.vectorLen(zcu)) {
1073910740 1 => {
1074010741 const tmp_reg = (try self.register_manager.allocReg(
1074110742 null,
......@@ -10923,7 +10924,7 @@ fn genBinOp(
1092310924 else => break :tag null,
1092410925 }
1092510926 },
10926 32 => switch (lhs_ty.vectorLen(mod)) {
10927 32 => switch (lhs_ty.vectorLen(zcu)) {
1092710928 1 => switch (air_tag) {
1092810929 .add => if (self.hasFeature(.avx)) .{ .v_ss, .add } else .{ ._ss, .add },
1092910930 .sub => if (self.hasFeature(.avx)) .{ .v_ss, .sub } else .{ ._ss, .sub },
......@@ -10976,7 +10977,7 @@ fn genBinOp(
1097610977 } else null,
1097710978 else => null,
1097810979 },
10979 64 => switch (lhs_ty.vectorLen(mod)) {
10980 64 => switch (lhs_ty.vectorLen(zcu)) {
1098010981 1 => switch (air_tag) {
1098110982 .add => if (self.hasFeature(.avx)) .{ .v_sd, .add } else .{ ._sd, .add },
1098210983 .sub => if (self.hasFeature(.avx)) .{ .v_sd, .sub } else .{ ._sd, .sub },
......@@ -11052,7 +11053,7 @@ fn genBinOp(
1105211053 mir_tag,
1105311054 dst_reg,
1105411055 lhs_reg,
11055 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {
11056 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
1105611057 else => Memory.Size.fromSize(abi_size),
1105711058 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
1105811059 }),
......@@ -11070,7 +11071,7 @@ fn genBinOp(
1107011071 if (src_mcv.isMemory()) try self.asmRegisterMemory(
1107111072 mir_tag,
1107211073 dst_reg,
11073 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {
11074 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
1107411075 else => Memory.Size.fromSize(abi_size),
1107511076 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
1107611077 }),
......@@ -11098,7 +11099,7 @@ fn genBinOp(
1109811099 mir_tag,
1109911100 dst_reg,
1110011101 lhs_reg,
11101 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {
11102 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
1110211103 else => Memory.Size.fromSize(abi_size),
1110311104 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
1110411105 }),
......@@ -11118,7 +11119,7 @@ fn genBinOp(
1111811119 if (src_mcv.isMemory()) try self.asmRegisterMemoryImmediate(
1111911120 mir_tag,
1112011121 dst_reg,
11121 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {
11122 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
1112211123 else => Memory.Size.fromSize(abi_size),
1112311124 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
1112411125 }),
......@@ -11151,21 +11152,21 @@ fn genBinOp(
1115111152 const rhs_copy_reg = registerAlias(src_mcv.getReg().?, abi_size);
1115211153
1115311154 try self.asmRegisterRegisterRegisterImmediate(
11154 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
11155 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
1115511156 .Float => switch (lhs_ty.floatBits(self.target.*)) {
1115611157 32 => .{ .v_ss, .cmp },
1115711158 64 => .{ .v_sd, .cmp },
1115811159 16, 80, 128 => null,
1115911160 else => unreachable,
1116011161 },
11161 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
11162 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
11163 32 => switch (lhs_ty.vectorLen(mod)) {
11162 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11163 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11164 32 => switch (lhs_ty.vectorLen(zcu)) {
1116411165 1 => .{ .v_ss, .cmp },
1116511166 2...8 => .{ .v_ps, .cmp },
1116611167 else => null,
1116711168 },
11168 64 => switch (lhs_ty.vectorLen(mod)) {
11169 64 => switch (lhs_ty.vectorLen(zcu)) {
1116911170 1 => .{ .v_sd, .cmp },
1117011171 2...4 => .{ .v_pd, .cmp },
1117111172 else => null,
......@@ -11185,20 +11186,20 @@ fn genBinOp(
1118511186 Immediate.u(3), // unord
1118611187 );
1118711188 try self.asmRegisterRegisterRegisterRegister(
11188 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
11189 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
1118911190 .Float => switch (lhs_ty.floatBits(self.target.*)) {
1119011191 32 => .{ .v_ps, .blendv },
1119111192 64 => .{ .v_pd, .blendv },
1119211193 16, 80, 128 => null,
1119311194 else => unreachable,
1119411195 },
11195 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
11196 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
11197 32 => switch (lhs_ty.vectorLen(mod)) {
11196 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11197 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11198 32 => switch (lhs_ty.vectorLen(zcu)) {
1119811199 1...8 => .{ .v_ps, .blendv },
1119911200 else => null,
1120011201 },
11201 64 => switch (lhs_ty.vectorLen(mod)) {
11202 64 => switch (lhs_ty.vectorLen(zcu)) {
1120211203 1...4 => .{ .v_pd, .blendv },
1120311204 else => null,
1120411205 },
......@@ -11219,21 +11220,21 @@ fn genBinOp(
1121911220 } else {
1122011221 const has_blend = self.hasFeature(.sse4_1);
1122111222 try self.asmRegisterRegisterImmediate(
11222 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
11223 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
1122311224 .Float => switch (lhs_ty.floatBits(self.target.*)) {
1122411225 32 => .{ ._ss, .cmp },
1122511226 64 => .{ ._sd, .cmp },
1122611227 16, 80, 128 => null,
1122711228 else => unreachable,
1122811229 },
11229 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
11230 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
11231 32 => switch (lhs_ty.vectorLen(mod)) {
11230 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11231 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11232 32 => switch (lhs_ty.vectorLen(zcu)) {
1123211233 1 => .{ ._ss, .cmp },
1123311234 2...4 => .{ ._ps, .cmp },
1123411235 else => null,
1123511236 },
11236 64 => switch (lhs_ty.vectorLen(mod)) {
11237 64 => switch (lhs_ty.vectorLen(zcu)) {
1123711238 1 => .{ ._sd, .cmp },
1123811239 2 => .{ ._pd, .cmp },
1123911240 else => null,
......@@ -11252,20 +11253,20 @@ fn genBinOp(
1125211253 Immediate.u(if (has_blend) 3 else 7), // unord, ord
1125311254 );
1125411255 if (has_blend) try self.asmRegisterRegisterRegister(
11255 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {
11256 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
1125611257 .Float => switch (lhs_ty.floatBits(self.target.*)) {
1125711258 32 => .{ ._ps, .blendv },
1125811259 64 => .{ ._pd, .blendv },
1125911260 16, 80, 128 => null,
1126011261 else => unreachable,
1126111262 },
11262 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
11263 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
11264 32 => switch (lhs_ty.vectorLen(mod)) {
11263 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11264 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11265 32 => switch (lhs_ty.vectorLen(zcu)) {
1126511266 1...4 => .{ ._ps, .blendv },
1126611267 else => null,
1126711268 },
11268 64 => switch (lhs_ty.vectorLen(mod)) {
11269 64 => switch (lhs_ty.vectorLen(zcu)) {
1126911270 1...2 => .{ ._pd, .blendv },
1127011271 else => null,
1127111272 },
......@@ -11282,20 +11283,20 @@ fn genBinOp(
1128211283 lhs_copy_reg.?,
1128311284 mask_reg,
1128411285 ) else {
11285 const mir_fixes = @as(?Mir.Inst.Fixes, switch (lhs_ty.zigTypeTag(mod)) {
11286 const mir_fixes = @as(?Mir.Inst.Fixes, switch (lhs_ty.zigTypeTag(zcu)) {
1128611287 .Float => switch (lhs_ty.floatBits(self.target.*)) {
1128711288 32 => ._ps,
1128811289 64 => ._pd,
1128911290 16, 80, 128 => null,
1129011291 else => unreachable,
1129111292 },
11292 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
11293 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
11294 32 => switch (lhs_ty.vectorLen(mod)) {
11293 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11294 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11295 32 => switch (lhs_ty.vectorLen(zcu)) {
1129511296 1...4 => ._ps,
1129611297 else => null,
1129711298 },
11298 64 => switch (lhs_ty.vectorLen(mod)) {
11299 64 => switch (lhs_ty.vectorLen(zcu)) {
1129911300 1...2 => ._pd,
1130011301 else => null,
1130111302 },
......@@ -11314,7 +11315,7 @@ fn genBinOp(
1131411315 }
1131511316 },
1131611317 .cmp_lt, .cmp_lte, .cmp_eq, .cmp_gte, .cmp_gt, .cmp_neq => {
11317 switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
11318 switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
1131811319 .Int => switch (air_tag) {
1131911320 .cmp_lt,
1132011321 .cmp_eq,
......@@ -11395,8 +11396,8 @@ fn genBinOpMir(
1139511396 src_mcv: MCValue,
1139611397) !void {
1139711398 const pt = self.pt;
11398 const mod = pt.zcu;
11399 const abi_size: u32 = @intCast(ty.abiSize(pt));
11399 const zcu = pt.zcu;
11400 const abi_size: u32 = @intCast(ty.abiSize(zcu));
1140011401 try self.spillEflagsIfOccupied();
1140111402 switch (dst_mcv) {
1140211403 .none,
......@@ -11643,7 +11644,7 @@ fn genBinOpMir(
1164311644 defer if (src_info) |info| self.register_manager.unlockReg(info.addr_lock);
1164411645
1164511646 const ty_signedness =
11646 if (ty.isAbiInt(mod)) ty.intInfo(mod).signedness else .unsigned;
11647 if (ty.isAbiInt(zcu)) ty.intInfo(zcu).signedness else .unsigned;
1164711648 const limb_ty = if (abi_size <= 8) ty else switch (ty_signedness) {
1164811649 .signed => Type.usize,
1164911650 .unsigned => Type.isize,
......@@ -11820,7 +11821,7 @@ fn genBinOpMir(
1182011821/// Does not support byte-size operands.
1182111822fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {
1182211823 const pt = self.pt;
11823 const abi_size: u32 = @intCast(dst_ty.abiSize(pt));
11824 const abi_size: u32 = @intCast(dst_ty.abiSize(pt.zcu));
1182411825 try self.spillEflagsIfOccupied();
1182511826 switch (dst_mcv) {
1182611827 .none,
......@@ -12009,7 +12010,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1200912010 try self.genInlineMemset(
1201012011 dst_mcv.address().offset(@intFromBool(regs_frame_addr.regs > 0)),
1201112012 .{ .immediate = 0 },
12012 .{ .immediate = arg_ty.abiSize(pt) - @intFromBool(regs_frame_addr.regs > 0) },
12013 .{ .immediate = arg_ty.abiSize(zcu) - @intFromBool(regs_frame_addr.regs > 0) },
1201312014 .{},
1201412015 );
1201512016
......@@ -12296,7 +12297,7 @@ fn genCall(self: *Self, info: union(enum) {
1229612297 try reg_locks.appendSlice(&self.register_manager.lockRegs(2, regs));
1229712298 },
1229812299 .indirect => |reg_off| {
12299 frame_index.* = try self.allocFrameIndex(FrameAlloc.initType(arg_ty, pt));
12300 frame_index.* = try self.allocFrameIndex(FrameAlloc.initType(arg_ty, zcu));
1230012301 try self.genSetMem(.{ .frame = frame_index.* }, 0, arg_ty, src_arg, .{});
1230112302 try self.register_manager.getReg(reg_off.reg, null);
1230212303 try reg_locks.append(self.register_manager.lockReg(reg_off.reg));
......@@ -12368,7 +12369,7 @@ fn genCall(self: *Self, info: union(enum) {
1236812369 .none, .unreach => {},
1236912370 .indirect => |reg_off| {
1237012371 const ret_ty = Type.fromInterned(fn_info.return_type);
12371 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ret_ty, pt));
12372 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ret_ty, zcu));
1237212373 try self.genSetReg(reg_off.reg, Type.usize, .{
1237312374 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },
1237412375 }, .{});
......@@ -12383,14 +12384,14 @@ fn genCall(self: *Self, info: union(enum) {
1238312384 .none, .load_frame => {},
1238412385 .register => |dst_reg| switch (fn_info.cc) {
1238512386 else => try self.genSetReg(
12386 registerAlias(dst_reg, @intCast(arg_ty.abiSize(pt))),
12387 registerAlias(dst_reg, @intCast(arg_ty.abiSize(zcu))),
1238712388 arg_ty,
1238812389 src_arg,
1238912390 .{},
1239012391 ),
1239112392 .C, .SysV, .Win64 => {
1239212393 const promoted_ty = self.promoteInt(arg_ty);
12393 const promoted_abi_size: u32 = @intCast(promoted_ty.abiSize(pt));
12394 const promoted_abi_size: u32 = @intCast(promoted_ty.abiSize(zcu));
1239412395 const dst_alias = registerAlias(dst_reg, promoted_abi_size);
1239512396 try self.genSetReg(dst_alias, promoted_ty, src_arg, .{});
1239612397 if (promoted_ty.toIntern() != arg_ty.toIntern())
......@@ -12514,10 +12515,10 @@ fn genCall(self: *Self, info: union(enum) {
1251412515
1251512516fn airRet(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1251612517 const pt = self.pt;
12517 const mod = pt.zcu;
12518 const zcu = pt.zcu;
1251812519 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1251912520
12520 const ret_ty = self.fn_type.fnReturnType(mod);
12521 const ret_ty = self.fn_type.fnReturnType(zcu);
1252112522 switch (self.ret_mcv.short) {
1252212523 .none => {},
1252312524 .register,
......@@ -12570,7 +12571,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
1257012571
1257112572fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1257212573 const pt = self.pt;
12573 const mod = pt.zcu;
12574 const zcu = pt.zcu;
1257412575 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1257512576 var ty = self.typeOf(bin_op.lhs);
1257612577 var null_compare: ?Mir.Inst.Index = null;
......@@ -12602,7 +12603,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1260212603 };
1260312604 defer for (rhs_locks) |rhs_lock| if (rhs_lock) |lock| self.register_manager.unlockReg(lock);
1260412605
12605 switch (ty.zigTypeTag(mod)) {
12606 switch (ty.zigTypeTag(zcu)) {
1260612607 .Float => {
1260712608 const float_bits = ty.floatBits(self.target.*);
1260812609 if (switch (float_bits) {
......@@ -12638,11 +12639,11 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1263812639 };
1263912640 }
1264012641 },
12641 .Optional => if (!ty.optionalReprIsPayload(mod)) {
12642 .Optional => if (!ty.optionalReprIsPayload(zcu)) {
1264212643 const opt_ty = ty;
12643 const opt_abi_size: u31 = @intCast(opt_ty.abiSize(pt));
12644 ty = opt_ty.optionalChild(mod);
12645 const payload_abi_size: u31 = @intCast(ty.abiSize(pt));
12644 const opt_abi_size: u31 = @intCast(opt_ty.abiSize(zcu));
12645 ty = opt_ty.optionalChild(zcu);
12646 const payload_abi_size: u31 = @intCast(ty.abiSize(zcu));
1264612647
1264712648 const temp_lhs_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
1264812649 const temp_lhs_lock = self.register_manager.lockRegAssumeUnused(temp_lhs_reg);
......@@ -12699,9 +12700,9 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1269912700 else => {},
1270012701 }
1270112702
12702 switch (ty.zigTypeTag(mod)) {
12703 switch (ty.zigTypeTag(zcu)) {
1270312704 else => {
12704 const abi_size: u16 = @intCast(ty.abiSize(pt));
12705 const abi_size: u16 = @intCast(ty.abiSize(zcu));
1270512706 const may_flip: enum {
1270612707 may_flip,
1270712708 must_flip,
......@@ -12734,7 +12735,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1273412735 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
1273512736
1273612737 break :result Condition.fromCompareOperator(
12737 if (ty.isAbiInt(mod)) ty.intInfo(mod).signedness else .unsigned,
12738 if (ty.isAbiInt(zcu)) ty.intInfo(zcu).signedness else .unsigned,
1273812739 result_op: {
1273912740 const flipped_op = if (flipped) op.reverse() else op;
1274012741 if (abi_size > 8) switch (flipped_op) {
......@@ -13029,6 +13030,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
1302913030
1303013031fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1303113032 const pt = self.pt;
13033 const zcu = pt.zcu;
1303213034 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1303313035
1303413036 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
......@@ -13040,7 +13042,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
1304013042 try self.spillEflagsIfOccupied();
1304113043
1304213044 const op_ty = self.typeOf(un_op);
13043 const op_abi_size: u32 = @intCast(op_ty.abiSize(pt));
13045 const op_abi_size: u32 = @intCast(op_ty.abiSize(zcu));
1304413046 const op_mcv = try self.resolveInst(un_op);
1304513047 const dst_reg = switch (op_mcv) {
1304613048 .register => |reg| reg,
......@@ -13164,7 +13166,7 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
1316413166
1316513167fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !Mir.Inst.Index {
1316613168 const pt = self.pt;
13167 const abi_size = ty.abiSize(pt);
13169 const abi_size = ty.abiSize(pt.zcu);
1316813170 switch (mcv) {
1316913171 .eflags => |cc| {
1317013172 // Here we map the opposites since the jump is to the false branch.
......@@ -13237,7 +13239,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1323713239
1323813240fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MCValue {
1323913241 const pt = self.pt;
13240 const mod = pt.zcu;
13242 const zcu = pt.zcu;
1324113243 switch (opt_mcv) {
1324213244 .register_overflow => |ro| return .{ .eflags = ro.eflags.negate() },
1324313245 else => {},
......@@ -13245,12 +13247,12 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1324513247
1324613248 try self.spillEflagsIfOccupied();
1324713249
13248 const pl_ty = opt_ty.optionalChild(mod);
13250 const pl_ty = opt_ty.optionalChild(zcu);
1324913251
13250 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
13251 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
13252 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(zcu))
13253 .{ .off = 0, .ty = if (pl_ty.isSlice(zcu)) pl_ty.slicePtrFieldType(zcu) else pl_ty }
1325213254 else
13253 .{ .off = @intCast(pl_ty.abiSize(pt)), .ty = Type.bool };
13255 .{ .off = @intCast(pl_ty.abiSize(zcu)), .ty = Type.bool };
1325413256
1325513257 self.eflags_inst = inst;
1325613258 switch (opt_mcv) {
......@@ -13279,14 +13281,14 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1327913281
1328013282 .register => |opt_reg| {
1328113283 if (some_info.off == 0) {
13282 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(pt));
13284 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(zcu));
1328313285 const alias_reg = registerAlias(opt_reg, some_abi_size);
1328413286 assert(some_abi_size * 8 == alias_reg.bitSize());
1328513287 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);
1328613288 return .{ .eflags = .z };
1328713289 }
1328813290 assert(some_info.ty.ip_index == .bool_type);
13289 const opt_abi_size: u32 = @intCast(opt_ty.abiSize(pt));
13291 const opt_abi_size: u32 = @intCast(opt_ty.abiSize(zcu));
1329013292 try self.asmRegisterImmediate(
1329113293 .{ ._, .bt },
1329213294 registerAlias(opt_reg, opt_abi_size),
......@@ -13306,7 +13308,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1330613308 defer self.register_manager.unlockReg(addr_reg_lock);
1330713309
1330813310 try self.genSetReg(addr_reg, Type.usize, opt_mcv.address(), .{});
13309 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(pt));
13311 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(zcu));
1331013312 try self.asmMemoryImmediate(
1331113313 .{ ._, .cmp },
1331213314 .{
......@@ -13322,7 +13324,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1332213324 },
1332313325
1332413326 .indirect, .load_frame => {
13325 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(pt));
13327 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(zcu));
1332613328 try self.asmMemoryImmediate(
1332713329 .{ ._, .cmp },
1332813330 switch (opt_mcv) {
......@@ -13351,16 +13353,16 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1335113353
1335213354fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue) !MCValue {
1335313355 const pt = self.pt;
13354 const mod = pt.zcu;
13355 const opt_ty = ptr_ty.childType(mod);
13356 const pl_ty = opt_ty.optionalChild(mod);
13356 const zcu = pt.zcu;
13357 const opt_ty = ptr_ty.childType(zcu);
13358 const pl_ty = opt_ty.optionalChild(zcu);
1335713359
1335813360 try self.spillEflagsIfOccupied();
1335913361
13360 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
13361 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }
13362 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(zcu))
13363 .{ .off = 0, .ty = if (pl_ty.isSlice(zcu)) pl_ty.slicePtrFieldType(zcu) else pl_ty }
1336213364 else
13363 .{ .off = @intCast(pl_ty.abiSize(pt)), .ty = Type.bool };
13365 .{ .off = @intCast(pl_ty.abiSize(zcu)), .ty = Type.bool };
1336413366
1336513367 const ptr_reg = switch (ptr_mcv) {
1336613368 .register => |reg| reg,
......@@ -13369,7 +13371,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
1336913371 const ptr_lock = self.register_manager.lockReg(ptr_reg);
1337013372 defer if (ptr_lock) |lock| self.register_manager.unlockReg(lock);
1337113373
13372 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(pt));
13374 const some_abi_size: u32 = @intCast(some_info.ty.abiSize(zcu));
1337313375 try self.asmMemoryImmediate(
1337413376 .{ ._, .cmp },
1337513377 .{
......@@ -13388,13 +13390,13 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
1338813390
1338913391fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue) !MCValue {
1339013392 const pt = self.pt;
13391 const mod = pt.zcu;
13392 const err_ty = eu_ty.errorUnionSet(mod);
13393 if (err_ty.errorSetIsEmpty(mod)) return MCValue{ .immediate = 0 }; // always false
13393 const zcu = pt.zcu;
13394 const err_ty = eu_ty.errorUnionSet(zcu);
13395 if (err_ty.errorSetIsEmpty(zcu)) return MCValue{ .immediate = 0 }; // always false
1339413396
1339513397 try self.spillEflagsIfOccupied();
1339613398
13397 const err_off: u31 = @intCast(errUnionErrorOffset(eu_ty.errorUnionPayload(mod), pt));
13399 const err_off: u31 = @intCast(errUnionErrorOffset(eu_ty.errorUnionPayload(zcu), zcu));
1339813400 switch (eu_mcv) {
1339913401 .register => |reg| {
1340013402 const eu_lock = self.register_manager.lockReg(reg);
......@@ -13437,10 +13439,10 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue)
1343713439
1343813440fn isErrPtr(self: *Self, maybe_inst: ?Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue) !MCValue {
1343913441 const pt = self.pt;
13440 const mod = pt.zcu;
13441 const eu_ty = ptr_ty.childType(mod);
13442 const err_ty = eu_ty.errorUnionSet(mod);
13443 if (err_ty.errorSetIsEmpty(mod)) return MCValue{ .immediate = 0 }; // always false
13442 const zcu = pt.zcu;
13443 const eu_ty = ptr_ty.childType(zcu);
13444 const err_ty = eu_ty.errorUnionSet(zcu);
13445 if (err_ty.errorSetIsEmpty(zcu)) return MCValue{ .immediate = 0 }; // always false
1344413446
1344513447 try self.spillEflagsIfOccupied();
1344613448
......@@ -13451,7 +13453,7 @@ fn isErrPtr(self: *Self, maybe_inst: ?Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCV
1345113453 const ptr_lock = self.register_manager.lockReg(ptr_reg);
1345213454 defer if (ptr_lock) |lock| self.register_manager.unlockReg(lock);
1345313455
13454 const err_off: u31 = @intCast(errUnionErrorOffset(eu_ty.errorUnionPayload(mod), pt));
13456 const err_off: u31 = @intCast(errUnionErrorOffset(eu_ty.errorUnionPayload(zcu), zcu));
1345513457 try self.asmMemoryImmediate(
1345613458 .{ ._, .cmp },
1345713459 .{
......@@ -13724,12 +13726,12 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) void {
1372413726}
1372513727
1372613728fn airBr(self: *Self, inst: Air.Inst.Index) !void {
13727 const pt = self.pt;
13729 const zcu = self.pt.zcu;
1372813730 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
1372913731
1373013732 const block_ty = self.typeOfIndex(br.block_inst);
1373113733 const block_unused =
13732 !block_ty.hasRuntimeBitsIgnoreComptime(pt) or self.liveness.isUnused(br.block_inst);
13734 !block_ty.hasRuntimeBitsIgnoreComptime(zcu) or self.liveness.isUnused(br.block_inst);
1373313735 const block_tracking = self.inst_tracking.getPtr(br.block_inst).?;
1373413736 const block_data = self.blocks.getPtr(br.block_inst).?;
1373513737 const first_br = block_data.relocs.items.len == 0;
......@@ -13786,7 +13788,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1378613788
1378713789fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
1378813790 const pt = self.pt;
13789 const mod = pt.zcu;
13791 const zcu = pt.zcu;
1379013792 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1379113793 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
1379213794 const clobbers_len: u31 = @truncate(extra.data.flags);
......@@ -13825,7 +13827,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
1382513827 };
1382613828 const ty = switch (output) {
1382713829 .none => self.typeOfIndex(inst),
13828 else => self.typeOf(output).childType(mod),
13830 else => self.typeOf(output).childType(zcu),
1382913831 };
1383013832 const is_read = switch (constraint[0]) {
1383113833 '=' => false,
......@@ -13850,7 +13852,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
1385013852 'x' => abi.RegisterClass.sse,
1385113853 else => unreachable,
1385213854 }) orelse return self.fail("ran out of registers lowering inline asm", .{}),
13853 @intCast(ty.abiSize(pt)),
13855 @intCast(ty.abiSize(zcu)),
1385413856 )
1385513857 else if (mem.eql(u8, rest, "m"))
1385613858 if (output != .none) null else return self.fail(
......@@ -13920,7 +13922,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
1392013922 break :arg input_mcv;
1392113923 const reg = try self.register_manager.allocReg(null, rc);
1392213924 try self.genSetReg(reg, ty, input_mcv, .{});
13923 break :arg .{ .register = registerAlias(reg, @intCast(ty.abiSize(pt))) };
13925 break :arg .{ .register = registerAlias(reg, @intCast(ty.abiSize(zcu))) };
1392413926 } else if (mem.eql(u8, constraint, "i") or mem.eql(u8, constraint, "n"))
1392513927 switch (input_mcv) {
1392613928 .immediate => |imm| .{ .immediate = imm },
......@@ -14497,18 +14499,18 @@ const MoveStrategy = union(enum) {
1449714499};
1449814500fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !MoveStrategy {
1449914501 const pt = self.pt;
14500 const mod = pt.zcu;
14502 const zcu = pt.zcu;
1450114503 switch (class) {
1450214504 .general_purpose, .segment => return .{ .move = .{ ._, .mov } },
1450314505 .x87 => return .x87_load_store,
1450414506 .mmx => {},
14505 .sse => switch (ty.zigTypeTag(mod)) {
14507 .sse => switch (ty.zigTypeTag(zcu)) {
1450614508 else => {
14507 const classes = mem.sliceTo(&abi.classifySystemV(ty, pt, self.target.*, .other), .none);
14509 const classes = mem.sliceTo(&abi.classifySystemV(ty, zcu, self.target.*, .other), .none);
1450814510 assert(std.mem.indexOfNone(abi.Class, classes, &.{
1450914511 .integer, .sse, .sseup, .memory, .float, .float_combine,
1451014512 }) == null);
14511 const abi_size = ty.abiSize(pt);
14513 const abi_size = ty.abiSize(zcu);
1451214514 if (abi_size < 4 or
1451314515 std.mem.indexOfScalar(abi.Class, classes, .integer) != null) switch (abi_size) {
1451414516 1 => if (self.hasFeature(.avx)) return .{ .vex_insert_extract = .{
......@@ -14579,16 +14581,16 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1457914581 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
1458014582 else => {},
1458114583 },
14582 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
14583 .Bool => switch (ty.vectorLen(mod)) {
14584 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
14585 .Bool => switch (ty.vectorLen(zcu)) {
1458414586 33...64 => return .{ .move = if (self.hasFeature(.avx))
1458514587 .{ .v_q, .mov }
1458614588 else
1458714589 .{ ._q, .mov } },
1458814590 else => {},
1458914591 },
14590 .Int => switch (ty.childType(mod).intInfo(mod).bits) {
14591 1...8 => switch (ty.vectorLen(mod)) {
14592 .Int => switch (ty.childType(zcu).intInfo(zcu).bits) {
14593 1...8 => switch (ty.vectorLen(zcu)) {
1459214594 1...16 => return .{ .move = if (self.hasFeature(.avx))
1459314595 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1459414596 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14599,7 +14601,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1459914601 .{ .v_, .movdqu } },
1460014602 else => {},
1460114603 },
14602 9...16 => switch (ty.vectorLen(mod)) {
14604 9...16 => switch (ty.vectorLen(zcu)) {
1460314605 1...8 => return .{ .move = if (self.hasFeature(.avx))
1460414606 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1460514607 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14610,7 +14612,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1461014612 .{ .v_, .movdqu } },
1461114613 else => {},
1461214614 },
14613 17...32 => switch (ty.vectorLen(mod)) {
14615 17...32 => switch (ty.vectorLen(zcu)) {
1461414616 1...4 => return .{ .move = if (self.hasFeature(.avx))
1461514617 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1461614618 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14621,7 +14623,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1462114623 .{ .v_, .movdqu } },
1462214624 else => {},
1462314625 },
14624 33...64 => switch (ty.vectorLen(mod)) {
14626 33...64 => switch (ty.vectorLen(zcu)) {
1462514627 1...2 => return .{ .move = if (self.hasFeature(.avx))
1462614628 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1462714629 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14632,7 +14634,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1463214634 .{ .v_, .movdqu } },
1463314635 else => {},
1463414636 },
14635 65...128 => switch (ty.vectorLen(mod)) {
14637 65...128 => switch (ty.vectorLen(zcu)) {
1463614638 1 => return .{ .move = if (self.hasFeature(.avx))
1463714639 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1463814640 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14643,7 +14645,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1464314645 .{ .v_, .movdqu } },
1464414646 else => {},
1464514647 },
14646 129...256 => switch (ty.vectorLen(mod)) {
14648 129...256 => switch (ty.vectorLen(zcu)) {
1464714649 1 => if (self.hasFeature(.avx))
1464814650 return .{ .move = if (aligned)
1464914651 .{ .v_, .movdqa }
......@@ -14653,8 +14655,8 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1465314655 },
1465414656 else => {},
1465514657 },
14656 .Pointer, .Optional => if (ty.childType(mod).isPtrAtRuntime(mod))
14657 switch (ty.vectorLen(mod)) {
14658 .Pointer, .Optional => if (ty.childType(zcu).isPtrAtRuntime(zcu))
14659 switch (ty.vectorLen(zcu)) {
1465814660 1...2 => return .{ .move = if (self.hasFeature(.avx))
1465914661 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1466014662 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14667,8 +14669,8 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1466714669 }
1466814670 else
1466914671 unreachable,
14670 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
14671 16 => switch (ty.vectorLen(mod)) {
14672 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
14673 16 => switch (ty.vectorLen(zcu)) {
1467214674 1...8 => return .{ .move = if (self.hasFeature(.avx))
1467314675 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1467414676 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14679,7 +14681,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1467914681 .{ .v_, .movdqu } },
1468014682 else => {},
1468114683 },
14682 32 => switch (ty.vectorLen(mod)) {
14684 32 => switch (ty.vectorLen(zcu)) {
1468314685 1...4 => return .{ .move = if (self.hasFeature(.avx))
1468414686 if (aligned) .{ .v_ps, .mova } else .{ .v_ps, .movu }
1468514687 else if (aligned) .{ ._ps, .mova } else .{ ._ps, .movu } },
......@@ -14690,7 +14692,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1469014692 .{ .v_ps, .movu } },
1469114693 else => {},
1469214694 },
14693 64 => switch (ty.vectorLen(mod)) {
14695 64 => switch (ty.vectorLen(zcu)) {
1469414696 1...2 => return .{ .move = if (self.hasFeature(.avx))
1469514697 if (aligned) .{ .v_pd, .mova } else .{ .v_pd, .movu }
1469614698 else if (aligned) .{ ._pd, .mova } else .{ ._pd, .movu } },
......@@ -14701,7 +14703,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1470114703 .{ .v_pd, .movu } },
1470214704 else => {},
1470314705 },
14704 128 => switch (ty.vectorLen(mod)) {
14706 128 => switch (ty.vectorLen(zcu)) {
1470514707 1 => return .{ .move = if (self.hasFeature(.avx))
1470614708 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
1470714709 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -14804,7 +14806,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: Copy
1480414806 } },
1480514807 else => unreachable,
1480614808 }, opts);
14807 part_disp += @intCast(dst_ty.abiSize(pt));
14809 part_disp += @intCast(dst_ty.abiSize(pt.zcu));
1480814810 }
1480914811 },
1481014812 .indirect => |reg_off| try self.genSetMem(
......@@ -14846,9 +14848,9 @@ fn genSetReg(
1484614848 opts: CopyOptions,
1484714849) InnerError!void {
1484814850 const pt = self.pt;
14849 const mod = pt.zcu;
14850 const abi_size: u32 = @intCast(ty.abiSize(pt));
14851 if (ty.bitSize(pt) > dst_reg.bitSize())
14851 const zcu = pt.zcu;
14852 const abi_size: u32 = @intCast(ty.abiSize(zcu));
14853 if (ty.bitSize(zcu) > dst_reg.bitSize())
1485214854 return self.fail("genSetReg called with a value larger than dst_reg", .{});
1485314855 switch (src_mcv) {
1485414856 .none,
......@@ -14965,13 +14967,13 @@ fn genSetReg(
1496514967 ),
1496614968 .x87, .mmx, .ip => unreachable,
1496714969 .sse => try self.asmRegisterRegister(
14968 @as(?Mir.Inst.FixedTag, switch (ty.scalarType(mod).zigTypeTag(mod)) {
14970 @as(?Mir.Inst.FixedTag, switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
1496914971 else => switch (abi_size) {
1497014972 1...16 => if (self.hasFeature(.avx)) .{ .v_, .movdqa } else .{ ._, .movdqa },
1497114973 17...32 => if (self.hasFeature(.avx)) .{ .v_, .movdqa } else null,
1497214974 else => null,
1497314975 },
14974 .Float => switch (ty.scalarType(mod).floatBits(self.target.*)) {
14976 .Float => switch (ty.scalarType(zcu).floatBits(self.target.*)) {
1497514977 16, 128 => switch (abi_size) {
1497614978 2...16 => if (self.hasFeature(.avx))
1497714979 .{ .v_, .movdqa }
......@@ -15035,7 +15037,7 @@ fn genSetReg(
1503515037 return (try self.moveStrategy(
1503615038 ty,
1503715039 dst_reg.class(),
15038 ty.abiAlignment(pt).check(@as(u32, @bitCast(small_addr))),
15040 ty.abiAlignment(zcu).check(@as(u32, @bitCast(small_addr))),
1503915041 )).read(self, registerAlias(dst_reg, abi_size), .{
1504015042 .base = .{ .reg = .ds },
1504115043 .mod = .{ .rm = .{
......@@ -15136,8 +15138,8 @@ fn genSetMem(
1513615138 opts: CopyOptions,
1513715139) InnerError!void {
1513815140 const pt = self.pt;
15139 const mod = pt.zcu;
15140 const abi_size: u32 = @intCast(ty.abiSize(pt));
15141 const zcu = pt.zcu;
15142 const abi_size: u32 = @intCast(ty.abiSize(zcu));
1514115143 const dst_ptr_mcv: MCValue = switch (base) {
1514215144 .none => .{ .immediate = @bitCast(@as(i64, disp)) },
1514315145 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },
......@@ -15159,8 +15161,8 @@ fn genSetMem(
1515915161 ),
1516015162 .immediate => |imm| switch (abi_size) {
1516115163 1, 2, 4 => {
15162 const immediate = switch (if (ty.isAbiInt(mod))
15163 ty.intInfo(mod).signedness
15164 const immediate = switch (if (ty.isAbiInt(zcu))
15165 ty.intInfo(zcu).signedness
1516415166 else
1516515167 .unsigned) {
1516615168 .signed => Immediate.s(@truncate(@as(i64, @bitCast(imm)))),
......@@ -15193,7 +15195,7 @@ fn genSetMem(
1519315195 .size = .dword,
1519415196 .disp = disp + offset,
1519515197 } } },
15196 if (ty.isSignedInt(mod)) Immediate.s(
15198 if (ty.isSignedInt(zcu)) Immediate.s(
1519715199 @truncate(@as(i64, @bitCast(imm)) >> (math.cast(u6, offset * 8) orelse 63)),
1519815200 ) else Immediate.u(
1519915201 @as(u32, @truncate(if (math.cast(u6, offset * 8)) |shift| imm >> shift else 0)),
......@@ -15263,33 +15265,33 @@ fn genSetMem(
1526315265 var part_disp: i32 = disp;
1526415266 for (try self.splitType(ty), src_regs) |src_ty, src_reg| {
1526515267 try self.genSetMem(base, part_disp, src_ty, .{ .register = src_reg }, opts);
15266 part_disp += @intCast(src_ty.abiSize(pt));
15268 part_disp += @intCast(src_ty.abiSize(zcu));
1526715269 }
1526815270 },
15269 .register_overflow => |ro| switch (ty.zigTypeTag(mod)) {
15271 .register_overflow => |ro| switch (ty.zigTypeTag(zcu)) {
1527015272 .Struct => {
1527115273 try self.genSetMem(
1527215274 base,
15273 disp + @as(i32, @intCast(ty.structFieldOffset(0, pt))),
15274 ty.structFieldType(0, mod),
15275 disp + @as(i32, @intCast(ty.structFieldOffset(0, zcu))),
15276 ty.structFieldType(0, zcu),
1527515277 .{ .register = ro.reg },
1527615278 opts,
1527715279 );
1527815280 try self.genSetMem(
1527915281 base,
15280 disp + @as(i32, @intCast(ty.structFieldOffset(1, pt))),
15281 ty.structFieldType(1, mod),
15282 disp + @as(i32, @intCast(ty.structFieldOffset(1, zcu))),
15283 ty.structFieldType(1, zcu),
1528215284 .{ .eflags = ro.eflags },
1528315285 opts,
1528415286 );
1528515287 },
1528615288 .Optional => {
15287 assert(!ty.optionalReprIsPayload(mod));
15288 const child_ty = ty.optionalChild(mod);
15289 assert(!ty.optionalReprIsPayload(zcu));
15290 const child_ty = ty.optionalChild(zcu);
1528915291 try self.genSetMem(base, disp, child_ty, .{ .register = ro.reg }, opts);
1529015292 try self.genSetMem(
1529115293 base,
15292 disp + @as(i32, @intCast(child_ty.abiSize(pt))),
15294 disp + @as(i32, @intCast(child_ty.abiSize(zcu))),
1529315295 Type.bool,
1529415296 .{ .eflags = ro.eflags },
1529515297 opts,
......@@ -15521,14 +15523,14 @@ fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
1552115523
1552215524fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1552315525 const pt = self.pt;
15524 const mod = pt.zcu;
15526 const zcu = pt.zcu;
1552515527 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1552615528 const dst_ty = self.typeOfIndex(inst);
1552715529 const src_ty = self.typeOf(ty_op.operand);
1552815530
1552915531 const result = result: {
1553015532 const src_mcv = try self.resolveInst(ty_op.operand);
15531 if (dst_ty.isPtrAtRuntime(mod) and src_ty.isPtrAtRuntime(mod)) switch (src_mcv) {
15533 if (dst_ty.isPtrAtRuntime(zcu) and src_ty.isPtrAtRuntime(zcu)) switch (src_mcv) {
1553215534 .lea_frame => break :result src_mcv,
1553315535 else => if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv,
1553415536 };
......@@ -15539,10 +15541,10 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1553915541 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;
1554015542 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
1554115543
15542 const dst_mcv = if (dst_rc.supersetOf(src_rc) and dst_ty.abiSize(pt) <= src_ty.abiSize(pt) and
15544 const dst_mcv = if (dst_rc.supersetOf(src_rc) and dst_ty.abiSize(zcu) <= src_ty.abiSize(zcu) and
1554315545 self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {
1554415546 const dst_mcv = try self.allocRegOrMem(inst, true);
15545 try self.genCopy(switch (math.order(dst_ty.abiSize(pt), src_ty.abiSize(pt))) {
15547 try self.genCopy(switch (math.order(dst_ty.abiSize(zcu), src_ty.abiSize(zcu))) {
1554615548 .lt => dst_ty,
1554715549 .eq => if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,
1554815550 .gt => src_ty,
......@@ -15552,12 +15554,12 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1555215554
1555315555 if (dst_ty.isRuntimeFloat()) break :result dst_mcv;
1555415556
15555 if (dst_ty.isAbiInt(mod) and src_ty.isAbiInt(mod) and
15556 dst_ty.intInfo(mod).signedness == src_ty.intInfo(mod).signedness) break :result dst_mcv;
15557 if (dst_ty.isAbiInt(zcu) and src_ty.isAbiInt(zcu) and
15558 dst_ty.intInfo(zcu).signedness == src_ty.intInfo(zcu).signedness) break :result dst_mcv;
1555715559
15558 const abi_size = dst_ty.abiSize(pt);
15559 const bit_size = dst_ty.bitSize(pt);
15560 if (abi_size * 8 <= bit_size or dst_ty.isVector(mod)) break :result dst_mcv;
15560 const abi_size = dst_ty.abiSize(zcu);
15561 const bit_size = dst_ty.bitSize(zcu);
15562 if (abi_size * 8 <= bit_size or dst_ty.isVector(zcu)) break :result dst_mcv;
1556115563
1556215564 const dst_limbs_len = math.divCeil(i32, @intCast(bit_size), 64) catch unreachable;
1556315565 const high_mcv: MCValue = switch (dst_mcv) {
......@@ -15586,20 +15588,20 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1558615588
1558715589fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1558815590 const pt = self.pt;
15589 const mod = pt.zcu;
15591 const zcu = pt.zcu;
1559015592 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1559115593
1559215594 const slice_ty = self.typeOfIndex(inst);
1559315595 const ptr_ty = self.typeOf(ty_op.operand);
1559415596 const ptr = try self.resolveInst(ty_op.operand);
15595 const array_ty = ptr_ty.childType(mod);
15596 const array_len = array_ty.arrayLen(mod);
15597 const array_ty = ptr_ty.childType(zcu);
15598 const array_len = array_ty.arrayLen(zcu);
1559715599
15598 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(slice_ty, pt));
15600 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(slice_ty, zcu));
1559915601 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr, .{});
1560015602 try self.genSetMem(
1560115603 .{ .frame = frame_index },
15602 @intCast(ptr_ty.abiSize(pt)),
15604 @intCast(ptr_ty.abiSize(zcu)),
1560315605 Type.usize,
1560415606 .{ .immediate = array_len },
1560515607 .{},
......@@ -15611,16 +15613,16 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1561115613
1561215614fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1561315615 const pt = self.pt;
15614 const mod = pt.zcu;
15616 const zcu = pt.zcu;
1561515617 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1561615618
1561715619 const dst_ty = self.typeOfIndex(inst);
1561815620 const dst_bits = dst_ty.floatBits(self.target.*);
1561915621
1562015622 const src_ty = self.typeOf(ty_op.operand);
15621 const src_bits: u32 = @intCast(src_ty.bitSize(pt));
15623 const src_bits: u32 = @intCast(src_ty.bitSize(zcu));
1562215624 const src_signedness =
15623 if (src_ty.isAbiInt(mod)) src_ty.intInfo(mod).signedness else .unsigned;
15625 if (src_ty.isAbiInt(zcu)) src_ty.intInfo(zcu).signedness else .unsigned;
1562415626 const src_size = math.divCeil(u32, @max(switch (src_signedness) {
1562515627 .signed => src_bits,
1562615628 .unsigned => src_bits + 1,
......@@ -15666,7 +15668,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1566615668 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
1566715669 defer self.register_manager.unlockReg(dst_lock);
1566815670
15669 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_ty.zigTypeTag(mod)) {
15671 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_ty.zigTypeTag(zcu)) {
1567015672 .Float => switch (dst_ty.floatBits(self.target.*)) {
1567115673 32 => if (self.hasFeature(.avx)) .{ .v_ss, .cvtsi2 } else .{ ._ss, .cvtsi2 },
1567215674 64 => if (self.hasFeature(.avx)) .{ .v_sd, .cvtsi2 } else .{ ._sd, .cvtsi2 },
......@@ -15691,13 +15693,13 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1569115693
1569215694fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
1569315695 const pt = self.pt;
15694 const mod = pt.zcu;
15696 const zcu = pt.zcu;
1569515697 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1569615698
1569715699 const dst_ty = self.typeOfIndex(inst);
15698 const dst_bits: u32 = @intCast(dst_ty.bitSize(pt));
15700 const dst_bits: u32 = @intCast(dst_ty.bitSize(zcu));
1569915701 const dst_signedness =
15700 if (dst_ty.isAbiInt(mod)) dst_ty.intInfo(mod).signedness else .unsigned;
15702 if (dst_ty.isAbiInt(zcu)) dst_ty.intInfo(zcu).signedness else .unsigned;
1570115703 const dst_size = math.divCeil(u32, @max(switch (dst_signedness) {
1570215704 .signed => dst_bits,
1570315705 .unsigned => dst_bits + 1,
......@@ -15768,7 +15770,7 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1576815770
1576915771 const ptr_ty = self.typeOf(extra.ptr);
1577015772 const val_ty = self.typeOf(extra.expected_value);
15771 const val_abi_size: u32 = @intCast(val_ty.abiSize(pt));
15773 const val_abi_size: u32 = @intCast(val_ty.abiSize(pt.zcu));
1577215774
1577315775 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
1577415776 const regs_lock = self.register_manager.lockRegsAssumeUnused(4, .{ .rax, .rdx, .rbx, .rcx });
......@@ -15859,7 +15861,7 @@ fn atomicOp(
1585915861 order: std.builtin.AtomicOrder,
1586015862) InnerError!MCValue {
1586115863 const pt = self.pt;
15862 const mod = pt.zcu;
15864 const zcu = pt.zcu;
1586315865 const ptr_lock = switch (ptr_mcv) {
1586415866 .register => |reg| self.register_manager.lockReg(reg),
1586515867 else => null,
......@@ -15872,7 +15874,7 @@ fn atomicOp(
1587215874 };
1587315875 defer if (val_lock) |lock| self.register_manager.unlockReg(lock);
1587415876
15875 const val_abi_size: u32 = @intCast(val_ty.abiSize(pt));
15877 const val_abi_size: u32 = @intCast(val_ty.abiSize(zcu));
1587615878 const mem_size = Memory.Size.fromSize(val_abi_size);
1587715879 const ptr_mem: Memory = switch (ptr_mcv) {
1587815880 .immediate, .register, .register_offset, .lea_frame => try ptr_mcv.deref().mem(self, mem_size),
......@@ -16031,8 +16033,8 @@ fn atomicOp(
1603116033 .Or => try self.genBinOpMir(.{ ._, .@"or" }, val_ty, tmp_mcv, val_mcv),
1603216034 .Xor => try self.genBinOpMir(.{ ._, .xor }, val_ty, tmp_mcv, val_mcv),
1603316035 .Min, .Max => {
16034 const cc: Condition = switch (if (val_ty.isAbiInt(mod))
16035 val_ty.intInfo(mod).signedness
16036 const cc: Condition = switch (if (val_ty.isAbiInt(zcu))
16037 val_ty.intInfo(zcu).signedness
1603616038 else
1603716039 .unsigned) {
1603816040 .unsigned => switch (op) {
......@@ -16156,8 +16158,8 @@ fn atomicOp(
1615616158 try self.asmRegisterMemory(.{ ._, .xor }, .rcx, val_hi_mem);
1615716159 },
1615816160 .Min, .Max => {
16159 const cc: Condition = switch (if (val_ty.isAbiInt(mod))
16160 val_ty.intInfo(mod).signedness
16161 const cc: Condition = switch (if (val_ty.isAbiInt(zcu))
16162 val_ty.intInfo(zcu).signedness
1616116163 else
1616216164 .unsigned) {
1616316165 .unsigned => switch (op) {
......@@ -16264,7 +16266,7 @@ fn airAtomicStore(self: *Self, inst: Air.Inst.Index, order: std.builtin.AtomicOr
1626416266
1626516267fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1626616268 const pt = self.pt;
16267 const mod = pt.zcu;
16269 const zcu = pt.zcu;
1626816270 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1626916271
1627016272 result: {
......@@ -16290,19 +16292,19 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1629016292 };
1629116293 defer if (src_val_lock) |lock| self.register_manager.unlockReg(lock);
1629216294
16293 const elem_abi_size: u31 = @intCast(elem_ty.abiSize(pt));
16295 const elem_abi_size: u31 = @intCast(elem_ty.abiSize(zcu));
1629416296
1629516297 if (elem_abi_size == 1) {
16296 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
16298 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
1629716299 // TODO: this only handles slices stored in the stack
1629816300 .Slice => dst_ptr,
1629916301 .One => dst_ptr,
1630016302 .C, .Many => unreachable,
1630116303 };
16302 const len: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
16304 const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
1630316305 // TODO: this only handles slices stored in the stack
1630416306 .Slice => dst_ptr.address().offset(8).deref(),
16305 .One => .{ .immediate = dst_ptr_ty.childType(mod).arrayLen(mod) },
16307 .One => .{ .immediate = dst_ptr_ty.childType(zcu).arrayLen(zcu) },
1630616308 .C, .Many => unreachable,
1630716309 };
1630816310 const len_lock: ?RegisterLock = switch (len) {
......@@ -16318,9 +16320,9 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1631816320 // Store the first element, and then rely on memcpy copying forwards.
1631916321 // Length zero requires a runtime check - so we handle arrays specially
1632016322 // here to elide it.
16321 switch (dst_ptr_ty.ptrSize(mod)) {
16323 switch (dst_ptr_ty.ptrSize(zcu)) {
1632216324 .Slice => {
16323 const slice_ptr_ty = dst_ptr_ty.slicePtrFieldType(mod);
16325 const slice_ptr_ty = dst_ptr_ty.slicePtrFieldType(zcu);
1632416326
1632516327 // TODO: this only handles slices stored in the stack
1632616328 const ptr = dst_ptr;
......@@ -16365,7 +16367,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1636516367 .One => {
1636616368 const elem_ptr_ty = try pt.singleMutPtrType(elem_ty);
1636716369
16368 const len = dst_ptr_ty.childType(mod).arrayLen(mod);
16370 const len = dst_ptr_ty.childType(zcu).arrayLen(zcu);
1636916371
1637016372 assert(len != 0); // prevented by Sema
1637116373 try self.store(elem_ptr_ty, dst_ptr, src_val, .{ .safety = safety });
......@@ -16393,7 +16395,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1639316395
1639416396fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1639516397 const pt = self.pt;
16396 const mod = pt.zcu;
16398 const zcu = pt.zcu;
1639716399 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1639816400
1639916401 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
......@@ -16415,7 +16417,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1641516417 };
1641616418 defer if (src_ptr_lock) |lock| self.register_manager.unlockReg(lock);
1641716419
16418 const len: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
16420 const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
1641916421 .Slice => len: {
1642016422 const len_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
1642116423 const len_lock = self.register_manager.lockRegAssumeUnused(len_reg);
......@@ -16425,13 +16427,13 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1642516427 .{ .i_, .mul },
1642616428 len_reg,
1642716429 try dst_ptr.address().offset(8).deref().mem(self, .qword),
16428 Immediate.s(@intCast(dst_ptr_ty.childType(mod).abiSize(pt))),
16430 Immediate.s(@intCast(dst_ptr_ty.childType(zcu).abiSize(zcu))),
1642916431 );
1643016432 break :len .{ .register = len_reg };
1643116433 },
1643216434 .One => len: {
16433 const array_ty = dst_ptr_ty.childType(mod);
16434 break :len .{ .immediate = array_ty.arrayLen(mod) * array_ty.childType(mod).abiSize(pt) };
16435 const array_ty = dst_ptr_ty.childType(zcu);
16436 break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(zcu) };
1643516437 },
1643616438 .C, .Many => unreachable,
1643716439 };
......@@ -16449,6 +16451,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1644916451
1645016452fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
1645116453 const pt = self.pt;
16454 const zcu = pt.zcu;
1645216455 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1645316456 const inst_ty = self.typeOfIndex(inst);
1645416457 const enum_ty = self.typeOf(un_op);
......@@ -16457,8 +16460,8 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
1645716460 // We need a properly aligned and sized call frame to be able to call this function.
1645816461 {
1645916462 const needed_call_frame = FrameAlloc.init(.{
16460 .size = inst_ty.abiSize(pt),
16461 .alignment = inst_ty.abiAlignment(pt),
16463 .size = inst_ty.abiSize(zcu),
16464 .alignment = inst_ty.abiAlignment(zcu),
1646216465 });
1646316466 const frame_allocs_slice = self.frame_allocs.slice();
1646416467 const stack_frame_size =
......@@ -16590,15 +16593,15 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1659016593
1659116594fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1659216595 const pt = self.pt;
16593 const mod = pt.zcu;
16596 const zcu = pt.zcu;
1659416597 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1659516598 const vector_ty = self.typeOfIndex(inst);
16596 const vector_len = vector_ty.vectorLen(mod);
16599 const vector_len = vector_ty.vectorLen(zcu);
1659716600 const dst_rc = self.regClassForType(vector_ty);
1659816601 const scalar_ty = self.typeOf(ty_op.operand);
1659916602
1660016603 const result: MCValue = result: {
16601 switch (scalar_ty.zigTypeTag(mod)) {
16604 switch (scalar_ty.zigTypeTag(zcu)) {
1660216605 else => {},
1660316606 .Bool => {
1660416607 const regs =
......@@ -16641,7 +16644,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1664116644 break :result .{ .register = regs[0] };
1664216645 },
1664316646 .Int => if (self.hasFeature(.avx2)) avx2: {
16644 const mir_tag = @as(?Mir.Inst.FixedTag, switch (scalar_ty.intInfo(mod).bits) {
16647 const mir_tag = @as(?Mir.Inst.FixedTag, switch (scalar_ty.intInfo(zcu).bits) {
1664516648 else => null,
1664616649 1...8 => switch (vector_len) {
1664716650 else => null,
......@@ -16672,15 +16675,15 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1667216675 const src_mcv = try self.resolveInst(ty_op.operand);
1667316676 if (src_mcv.isMemory()) try self.asmRegisterMemory(
1667416677 mir_tag,
16675 registerAlias(dst_reg, @intCast(vector_ty.abiSize(pt))),
16678 registerAlias(dst_reg, @intCast(vector_ty.abiSize(zcu))),
1667616679 try src_mcv.mem(self, self.memSize(scalar_ty)),
1667716680 ) else {
1667816681 if (mir_tag[0] == .v_i128) break :avx2;
1667916682 try self.genSetReg(dst_reg, scalar_ty, src_mcv, .{});
1668016683 try self.asmRegisterRegister(
1668116684 mir_tag,
16682 registerAlias(dst_reg, @intCast(vector_ty.abiSize(pt))),
16683 registerAlias(dst_reg, @intCast(scalar_ty.abiSize(pt))),
16685 registerAlias(dst_reg, @intCast(vector_ty.abiSize(zcu))),
16686 registerAlias(dst_reg, @intCast(scalar_ty.abiSize(zcu))),
1668416687 );
1668516688 }
1668616689 break :result .{ .register = dst_reg };
......@@ -16692,8 +16695,8 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1669216695 try self.genSetReg(dst_reg, scalar_ty, .{ .air_ref = ty_op.operand }, .{});
1669316696 if (vector_len == 1) break :result .{ .register = dst_reg };
1669416697
16695 const dst_alias = registerAlias(dst_reg, @intCast(vector_ty.abiSize(pt)));
16696 const scalar_bits = scalar_ty.intInfo(mod).bits;
16698 const dst_alias = registerAlias(dst_reg, @intCast(vector_ty.abiSize(zcu)));
16699 const scalar_bits = scalar_ty.intInfo(zcu).bits;
1669716700 if (switch (scalar_bits) {
1669816701 1...8 => true,
1669916702 9...128 => false,
......@@ -16929,14 +16932,14 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1692916932
1693016933fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
1693116934 const pt = self.pt;
16932 const mod = pt.zcu;
16935 const zcu = pt.zcu;
1693316936 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1693416937 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
1693516938 const ty = self.typeOfIndex(inst);
16936 const vec_len = ty.vectorLen(mod);
16937 const elem_ty = ty.childType(mod);
16938 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(pt));
16939 const abi_size: u32 = @intCast(ty.abiSize(pt));
16939 const vec_len = ty.vectorLen(zcu);
16940 const elem_ty = ty.childType(zcu);
16941 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(zcu));
16942 const abi_size: u32 = @intCast(ty.abiSize(zcu));
1694016943 const pred_ty = self.typeOf(pl_op.operand);
1694116944
1694216945 const result = result: {
......@@ -17160,7 +17163,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
1716017163 const dst_lock = self.register_manager.lockReg(dst_reg);
1716117164 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
1716217165
17163 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.childType(mod).zigTypeTag(mod)) {
17166 const mir_tag = @as(?Mir.Inst.FixedTag, switch (ty.childType(zcu).zigTypeTag(zcu)) {
1716417167 else => null,
1716517168 .Int => switch (abi_size) {
1716617169 0 => unreachable,
......@@ -17176,7 +17179,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
1717617179 null,
1717717180 else => null,
1717817181 },
17179 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
17182 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
1718017183 else => unreachable,
1718117184 16, 80, 128 => null,
1718217185 32 => switch (vec_len) {
......@@ -17230,7 +17233,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
1723017233 try self.copyToTmpRegister(ty, lhs_mcv), abi_size),
1723117234 mask_alias,
1723217235 ) else {
17233 const mir_fixes = @as(?Mir.Inst.Fixes, switch (elem_ty.zigTypeTag(mod)) {
17236 const mir_fixes = @as(?Mir.Inst.Fixes, switch (elem_ty.zigTypeTag(zcu)) {
1723417237 else => null,
1723517238 .Int => .p_,
1723617239 .Float => switch (elem_ty.floatBits(self.target.*)) {
......@@ -17262,18 +17265,18 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
1726217265
1726317266fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1726417267 const pt = self.pt;
17265 const mod = pt.zcu;
17268 const zcu = pt.zcu;
1726617269 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1726717270 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
1726817271
1726917272 const dst_ty = self.typeOfIndex(inst);
17270 const elem_ty = dst_ty.childType(mod);
17271 const elem_abi_size: u16 = @intCast(elem_ty.abiSize(pt));
17272 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));
17273 const elem_ty = dst_ty.childType(zcu);
17274 const elem_abi_size: u16 = @intCast(elem_ty.abiSize(zcu));
17275 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
1727317276 const lhs_ty = self.typeOf(extra.a);
17274 const lhs_abi_size: u32 = @intCast(lhs_ty.abiSize(pt));
17277 const lhs_abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
1727517278 const rhs_ty = self.typeOf(extra.b);
17276 const rhs_abi_size: u32 = @intCast(rhs_ty.abiSize(pt));
17279 const rhs_abi_size: u32 = @intCast(rhs_ty.abiSize(zcu));
1727717280 const max_abi_size = @max(dst_abi_size, lhs_abi_size, rhs_abi_size);
1727817281
1727917282 const ExpectedContents = [32]?i32;
......@@ -17286,10 +17289,10 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1728617289 for (mask_elems, 0..) |*mask_elem, elem_index| {
1728717290 const mask_elem_val =
1728817291 Value.fromInterned(extra.mask).elemValue(pt, elem_index) catch unreachable;
17289 mask_elem.* = if (mask_elem_val.isUndef(mod))
17292 mask_elem.* = if (mask_elem_val.isUndef(zcu))
1729017293 null
1729117294 else
17292 @intCast(mask_elem_val.toSignedInt(pt));
17295 @intCast(mask_elem_val.toSignedInt(zcu));
1729317296 }
1729417297
1729517298 const has_avx = self.hasFeature(.avx);
......@@ -18028,7 +18031,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1802818031 );
1802918032
1803018033 if (has_avx) try self.asmRegisterRegisterRegister(
18031 .{ switch (elem_ty.zigTypeTag(mod)) {
18034 .{ switch (elem_ty.zigTypeTag(zcu)) {
1803218035 else => break :result null,
1803318036 .Int => .vp_,
1803418037 .Float => switch (elem_ty.floatBits(self.target.*)) {
......@@ -18042,7 +18045,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1804218045 lhs_temp_alias,
1804318046 rhs_temp_alias,
1804418047 ) else try self.asmRegisterRegister(
18045 .{ switch (elem_ty.zigTypeTag(mod)) {
18048 .{ switch (elem_ty.zigTypeTag(zcu)) {
1804618049 else => break :result null,
1804718050 .Int => .p_,
1804818051 .Float => switch (elem_ty.floatBits(self.target.*)) {
......@@ -18068,19 +18071,19 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1806818071
1806918072fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1807018073 const pt = self.pt;
18071 const mod = pt.zcu;
18074 const zcu = pt.zcu;
1807218075 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
1807318076
1807418077 const result: MCValue = result: {
1807518078 const operand_ty = self.typeOf(reduce.operand);
18076 if (operand_ty.isVector(mod) and operand_ty.childType(mod).toIntern() == .bool_type) {
18079 if (operand_ty.isVector(zcu) and operand_ty.childType(zcu).toIntern() == .bool_type) {
1807718080 try self.spillEflagsIfOccupied();
1807818081
1807918082 const operand_mcv = try self.resolveInst(reduce.operand);
18080 const mask_len = (math.cast(u6, operand_ty.vectorLen(mod)) orelse
18083 const mask_len = (math.cast(u6, operand_ty.vectorLen(zcu)) orelse
1808118084 return self.fail("TODO implement airReduce for {}", .{operand_ty.fmt(pt)}));
1808218085 const mask = (@as(u64, 1) << mask_len) - 1;
18083 const abi_size: u32 = @intCast(operand_ty.abiSize(pt));
18086 const abi_size: u32 = @intCast(operand_ty.abiSize(zcu));
1808418087 switch (reduce.operation) {
1808518088 .Or => {
1808618089 if (operand_mcv.isMemory()) try self.asmMemoryImmediate(
......@@ -18126,36 +18129,36 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1812618129
1812718130fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1812818131 const pt = self.pt;
18129 const mod = pt.zcu;
18132 const zcu = pt.zcu;
1813018133 const result_ty = self.typeOfIndex(inst);
18131 const len: usize = @intCast(result_ty.arrayLen(mod));
18134 const len: usize = @intCast(result_ty.arrayLen(zcu));
1813218135 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1813318136 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
1813418137 const result: MCValue = result: {
18135 switch (result_ty.zigTypeTag(mod)) {
18138 switch (result_ty.zigTypeTag(zcu)) {
1813618139 .Struct => {
18137 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, pt));
18138 if (result_ty.containerLayout(mod) == .@"packed") {
18139 const struct_obj = mod.typeToStruct(result_ty).?;
18140 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, zcu));
18141 if (result_ty.containerLayout(zcu) == .@"packed") {
18142 const struct_obj = zcu.typeToStruct(result_ty).?;
1814018143 try self.genInlineMemset(
1814118144 .{ .lea_frame = .{ .index = frame_index } },
1814218145 .{ .immediate = 0 },
18143 .{ .immediate = result_ty.abiSize(pt) },
18146 .{ .immediate = result_ty.abiSize(zcu) },
1814418147 .{},
1814518148 );
1814618149 for (elements, 0..) |elem, elem_i_usize| {
1814718150 const elem_i: u32 = @intCast(elem_i_usize);
1814818151 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
1814918152
18150 const elem_ty = result_ty.structFieldType(elem_i, mod);
18151 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(pt));
18153 const elem_ty = result_ty.structFieldType(elem_i, zcu);
18154 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(zcu));
1815218155 if (elem_bit_size > 64) {
1815318156 return self.fail(
1815418157 "TODO airAggregateInit implement packed structs with large fields",
1815518158 .{},
1815618159 );
1815718160 }
18158 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(pt));
18161 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(zcu));
1815918162 const elem_abi_bits = elem_abi_size * 8;
1816018163 const elem_off = pt.structPackedFieldBitOffset(struct_obj, elem_i);
1816118164 const elem_byte_off: i32 = @intCast(elem_off / elem_abi_bits * elem_abi_size);
......@@ -18229,8 +18232,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1822918232 } else for (elements, 0..) |elem, elem_i| {
1823018233 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
1823118234
18232 const elem_ty = result_ty.structFieldType(elem_i, mod);
18233 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, pt));
18235 const elem_ty = result_ty.structFieldType(elem_i, zcu);
18236 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, zcu));
1823418237 const elem_mcv = try self.resolveInst(elem);
1823518238 const mat_elem_mcv = switch (elem_mcv) {
1823618239 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
......@@ -18241,9 +18244,9 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1824118244 break :result .{ .load_frame = .{ .index = frame_index } };
1824218245 },
1824318246 .Array, .Vector => {
18244 const elem_ty = result_ty.childType(mod);
18245 if (result_ty.isVector(mod) and elem_ty.toIntern() == .bool_type) {
18246 const result_size: u32 = @intCast(result_ty.abiSize(pt));
18247 const elem_ty = result_ty.childType(zcu);
18248 if (result_ty.isVector(zcu) and elem_ty.toIntern() == .bool_type) {
18249 const result_size: u32 = @intCast(result_ty.abiSize(zcu));
1824718250 const dst_reg = try self.register_manager.allocReg(inst, abi.RegisterClass.gp);
1824818251 try self.asmRegisterRegister(
1824918252 .{ ._, .xor },
......@@ -18274,8 +18277,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1827418277 }
1827518278 break :result .{ .register = dst_reg };
1827618279 } else {
18277 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, pt));
18278 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));
18280 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, zcu));
18281 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
1827918282
1828018283 for (elements, 0..) |elem, elem_i| {
1828118284 const elem_mcv = try self.resolveInst(elem);
......@@ -18292,7 +18295,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1829218295 .{},
1829318296 );
1829418297 }
18295 if (result_ty.sentinel(mod)) |sentinel| try self.genSetMem(
18298 if (result_ty.sentinel(zcu)) |sentinel| try self.genSetMem(
1829618299 .{ .frame = frame_index },
1829718300 @intCast(elem_size * elements.len),
1829818301 elem_ty,
......@@ -18318,18 +18321,18 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1831818321
1831918322fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1832018323 const pt = self.pt;
18321 const mod = pt.zcu;
18322 const ip = &mod.intern_pool;
18324 const zcu = pt.zcu;
18325 const ip = &zcu.intern_pool;
1832318326 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1832418327 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1832518328 const result: MCValue = result: {
1832618329 const union_ty = self.typeOfIndex(inst);
18327 const layout = union_ty.unionGetLayout(pt);
18330 const layout = union_ty.unionGetLayout(zcu);
1832818331
1832918332 const src_ty = self.typeOf(extra.init);
1833018333 const src_mcv = try self.resolveInst(extra.init);
1833118334 if (layout.tag_size == 0) {
18332 if (layout.abi_size <= src_ty.abiSize(pt) and
18335 if (layout.abi_size <= src_ty.abiSize(zcu) and
1833318336 self.reuseOperand(inst, extra.init, 0, src_mcv)) break :result src_mcv;
1833418337
1833518338 const dst_mcv = try self.allocRegOrMem(inst, true);
......@@ -18339,13 +18342,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1833918342
1834018343 const dst_mcv = try self.allocRegOrMem(inst, false);
1834118344
18342 const union_obj = mod.typeToUnion(union_ty).?;
18345 const union_obj = zcu.typeToUnion(union_ty).?;
1834318346 const field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];
1834418347 const tag_ty = Type.fromInterned(union_obj.enum_tag_ty);
18345 const field_index = tag_ty.enumFieldIndex(field_name, mod).?;
18348 const field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
1834618349 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
1834718350 const tag_int_val = try tag_val.intFromEnum(tag_ty, pt);
18348 const tag_int = tag_int_val.toUnsignedInt(pt);
18351 const tag_int = tag_int_val.toUnsignedInt(zcu);
1834918352 const tag_off: i32 = @intCast(layout.tagOffset());
1835018353 try self.genCopy(
1835118354 tag_ty,
......@@ -18369,19 +18372,19 @@ fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {
1836918372
1837018373fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1837118374 const pt = self.pt;
18372 const mod = pt.zcu;
18375 const zcu = pt.zcu;
1837318376 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
1837418377 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
1837518378 const ty = self.typeOfIndex(inst);
1837618379
1837718380 const ops = [3]Air.Inst.Ref{ extra.lhs, extra.rhs, pl_op.operand };
1837818381 const result = result: {
18379 if (switch (ty.scalarType(mod).floatBits(self.target.*)) {
18382 if (switch (ty.scalarType(zcu).floatBits(self.target.*)) {
1838018383 16, 80, 128 => true,
1838118384 32, 64 => !self.hasFeature(.fma),
1838218385 else => unreachable,
1838318386 }) {
18384 if (ty.zigTypeTag(mod) != .Float) return self.fail("TODO implement airMulAdd for {}", .{
18387 if (ty.zigTypeTag(zcu) != .Float) return self.fail("TODO implement airMulAdd for {}", .{
1838518388 ty.fmt(pt),
1838618389 });
1838718390
......@@ -18430,21 +18433,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1843018433
1843118434 const mir_tag = @as(?Mir.Inst.FixedTag, if (mem.eql(u2, &order, &.{ 1, 3, 2 }) or
1843218435 mem.eql(u2, &order, &.{ 3, 1, 2 }))
18433 switch (ty.zigTypeTag(mod)) {
18436 switch (ty.zigTypeTag(zcu)) {
1843418437 .Float => switch (ty.floatBits(self.target.*)) {
1843518438 32 => .{ .v_ss, .fmadd132 },
1843618439 64 => .{ .v_sd, .fmadd132 },
1843718440 16, 80, 128 => null,
1843818441 else => unreachable,
1843918442 },
18440 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
18441 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
18442 32 => switch (ty.vectorLen(mod)) {
18443 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
18444 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
18445 32 => switch (ty.vectorLen(zcu)) {
1844318446 1 => .{ .v_ss, .fmadd132 },
1844418447 2...8 => .{ .v_ps, .fmadd132 },
1844518448 else => null,
1844618449 },
18447 64 => switch (ty.vectorLen(mod)) {
18450 64 => switch (ty.vectorLen(zcu)) {
1844818451 1 => .{ .v_sd, .fmadd132 },
1844918452 2...4 => .{ .v_pd, .fmadd132 },
1845018453 else => null,
......@@ -18457,21 +18460,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1845718460 else => unreachable,
1845818461 }
1845918462 else if (mem.eql(u2, &order, &.{ 2, 1, 3 }) or mem.eql(u2, &order, &.{ 1, 2, 3 }))
18460 switch (ty.zigTypeTag(mod)) {
18463 switch (ty.zigTypeTag(zcu)) {
1846118464 .Float => switch (ty.floatBits(self.target.*)) {
1846218465 32 => .{ .v_ss, .fmadd213 },
1846318466 64 => .{ .v_sd, .fmadd213 },
1846418467 16, 80, 128 => null,
1846518468 else => unreachable,
1846618469 },
18467 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
18468 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
18469 32 => switch (ty.vectorLen(mod)) {
18470 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
18471 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
18472 32 => switch (ty.vectorLen(zcu)) {
1847018473 1 => .{ .v_ss, .fmadd213 },
1847118474 2...8 => .{ .v_ps, .fmadd213 },
1847218475 else => null,
1847318476 },
18474 64 => switch (ty.vectorLen(mod)) {
18477 64 => switch (ty.vectorLen(zcu)) {
1847518478 1 => .{ .v_sd, .fmadd213 },
1847618479 2...4 => .{ .v_pd, .fmadd213 },
1847718480 else => null,
......@@ -18484,21 +18487,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1848418487 else => unreachable,
1848518488 }
1848618489 else if (mem.eql(u2, &order, &.{ 2, 3, 1 }) or mem.eql(u2, &order, &.{ 3, 2, 1 }))
18487 switch (ty.zigTypeTag(mod)) {
18490 switch (ty.zigTypeTag(zcu)) {
1848818491 .Float => switch (ty.floatBits(self.target.*)) {
1848918492 32 => .{ .v_ss, .fmadd231 },
1849018493 64 => .{ .v_sd, .fmadd231 },
1849118494 16, 80, 128 => null,
1849218495 else => unreachable,
1849318496 },
18494 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
18495 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
18496 32 => switch (ty.vectorLen(mod)) {
18497 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
18498 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
18499 32 => switch (ty.vectorLen(zcu)) {
1849718500 1 => .{ .v_ss, .fmadd231 },
1849818501 2...8 => .{ .v_ps, .fmadd231 },
1849918502 else => null,
1850018503 },
18501 64 => switch (ty.vectorLen(mod)) {
18504 64 => switch (ty.vectorLen(zcu)) {
1850218505 1 => .{ .v_sd, .fmadd231 },
1850318506 2...4 => .{ .v_pd, .fmadd231 },
1850418507 else => null,
......@@ -18516,7 +18519,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1851618519 var mops: [3]MCValue = undefined;
1851718520 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;
1851818521
18519 const abi_size: u32 = @intCast(ty.abiSize(pt));
18522 const abi_size: u32 = @intCast(ty.abiSize(zcu));
1852018523 const mop1_reg = registerAlias(mops[0].getReg().?, abi_size);
1852118524 const mop2_reg = registerAlias(mops[1].getReg().?, abi_size);
1852218525 if (mops[2].isRegister()) try self.asmRegisterRegisterRegister(
......@@ -18537,17 +18540,17 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1853718540
1853818541fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1853918542 const pt = self.pt;
18540 const mod = pt.zcu;
18543 const zcu = pt.zcu;
1854118544 const va_list_ty = self.air.instructions.items(.data)[@intFromEnum(inst)].ty;
1854218545 const ptr_anyopaque_ty = try pt.singleMutPtrType(Type.anyopaque);
1854318546
1854418547 const result: MCValue = switch (abi.resolveCallingConvention(
18545 self.fn_type.fnCallingConvention(mod),
18548 self.fn_type.fnCallingConvention(zcu),
1854618549 self.target.*,
1854718550 )) {
1854818551 .SysV => result: {
1854918552 const info = self.va_info.sysv;
18550 const dst_fi = try self.allocFrameIndex(FrameAlloc.initSpill(va_list_ty, pt));
18553 const dst_fi = try self.allocFrameIndex(FrameAlloc.initSpill(va_list_ty, zcu));
1855118554 var field_off: u31 = 0;
1855218555 // gp_offset: c_uint,
1855318556 try self.genSetMem(
......@@ -18557,7 +18560,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1855718560 .{ .immediate = info.gp_count * 8 },
1855818561 .{},
1855918562 );
18560 field_off += @intCast(Type.c_uint.abiSize(pt));
18563 field_off += @intCast(Type.c_uint.abiSize(zcu));
1856118564 // fp_offset: c_uint,
1856218565 try self.genSetMem(
1856318566 .{ .frame = dst_fi },
......@@ -18566,7 +18569,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1856618569 .{ .immediate = abi.SysV.c_abi_int_param_regs.len * 8 + info.fp_count * 16 },
1856718570 .{},
1856818571 );
18569 field_off += @intCast(Type.c_uint.abiSize(pt));
18572 field_off += @intCast(Type.c_uint.abiSize(zcu));
1857018573 // overflow_arg_area: *anyopaque,
1857118574 try self.genSetMem(
1857218575 .{ .frame = dst_fi },
......@@ -18575,7 +18578,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1857518578 .{ .lea_frame = info.overflow_arg_area },
1857618579 .{},
1857718580 );
18578 field_off += @intCast(ptr_anyopaque_ty.abiSize(pt));
18581 field_off += @intCast(ptr_anyopaque_ty.abiSize(zcu));
1857918582 // reg_save_area: *anyopaque,
1858018583 try self.genSetMem(
1858118584 .{ .frame = dst_fi },
......@@ -18584,7 +18587,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1858418587 .{ .lea_frame = info.reg_save_area },
1858518588 .{},
1858618589 );
18587 field_off += @intCast(ptr_anyopaque_ty.abiSize(pt));
18590 field_off += @intCast(ptr_anyopaque_ty.abiSize(zcu));
1858818591 break :result .{ .load_frame = .{ .index = dst_fi } };
1858918592 },
1859018593 .Win64 => return self.fail("TODO implement c_va_start for Win64", .{}),
......@@ -18595,7 +18598,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1859518598
1859618599fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1859718600 const pt = self.pt;
18598 const mod = pt.zcu;
18601 const zcu = pt.zcu;
1859918602 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1860018603 const ty = self.typeOfIndex(inst);
1860118604 const promote_ty = self.promoteVarArg(ty);
......@@ -18603,7 +18606,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1860318606 const unused = self.liveness.isUnused(inst);
1860418607
1860518608 const result: MCValue = switch (abi.resolveCallingConvention(
18606 self.fn_type.fnCallingConvention(mod),
18609 self.fn_type.fnCallingConvention(zcu),
1860718610 self.target.*,
1860818611 )) {
1860918612 .SysV => result: {
......@@ -18633,7 +18636,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1863318636 const overflow_arg_area: MCValue = .{ .indirect = .{ .reg = ptr_arg_list_reg, .off = 8 } };
1863418637 const reg_save_area: MCValue = .{ .indirect = .{ .reg = ptr_arg_list_reg, .off = 16 } };
1863518638
18636 const classes = mem.sliceTo(&abi.classifySystemV(promote_ty, pt, self.target.*, .arg), .none);
18639 const classes = mem.sliceTo(&abi.classifySystemV(promote_ty, zcu, self.target.*, .arg), .none);
1863718640 switch (classes[0]) {
1863818641 .integer => {
1863918642 assert(classes.len == 1);
......@@ -18668,7 +18671,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1866818671 .base = .{ .reg = addr_reg },
1866918672 .mod = .{ .rm = .{
1867018673 .size = .qword,
18671 .disp = @intCast(@max(promote_ty.abiSize(pt), 8)),
18674 .disp = @intCast(@max(promote_ty.abiSize(zcu), 8)),
1867218675 } },
1867318676 });
1867418677 try self.genCopy(
......@@ -18716,7 +18719,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1871618719 .base = .{ .reg = addr_reg },
1871718720 .mod = .{ .rm = .{
1871818721 .size = .qword,
18719 .disp = @intCast(@max(promote_ty.abiSize(pt), 8)),
18722 .disp = @intCast(@max(promote_ty.abiSize(zcu), 8)),
1872018723 } },
1872118724 });
1872218725 try self.genCopy(
......@@ -18806,11 +18809,11 @@ fn airVaEnd(self: *Self, inst: Air.Inst.Index) !void {
1880618809}
1880718810
1880818811fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
18809 const pt = self.pt;
18812 const zcu = self.pt.zcu;
1881018813 const ty = self.typeOf(ref);
1881118814
1881218815 // If the type has no codegen bits, no need to store it.
18813 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
18816 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
1881418817
1881518818 const mcv = if (ref.toIndex()) |inst| mcv: {
1881618819 break :mcv self.inst_tracking.getPtr(inst).?.short;
......@@ -18927,8 +18930,8 @@ fn resolveCallingConventionValues(
1892718930 stack_frame_base: FrameIndex,
1892818931) !CallMCValues {
1892918932 const pt = self.pt;
18930 const mod = pt.zcu;
18931 const ip = &mod.intern_pool;
18933 const zcu = pt.zcu;
18934 const ip = &zcu.intern_pool;
1893218935 const cc = fn_info.cc;
1893318936 const param_types = try self.gpa.alloc(Type, fn_info.param_types.len + var_args.len);
1893418937 defer self.gpa.free(param_types);
......@@ -18970,15 +18973,15 @@ fn resolveCallingConventionValues(
1897018973 .SysV => {},
1897118974 .Win64 => {
1897218975 // Align the stack to 16bytes before allocating shadow stack space (if any).
18973 result.stack_byte_count += @intCast(4 * Type.usize.abiSize(pt));
18976 result.stack_byte_count += @intCast(4 * Type.usize.abiSize(zcu));
1897418977 },
1897518978 else => unreachable,
1897618979 }
1897718980
1897818981 // Return values
18979 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
18982 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
1898018983 result.return_value = InstTracking.init(.unreach);
18981 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
18984 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1898218985 // TODO: is this even possible for C calling convention?
1898318986 result.return_value = InstTracking.init(.none);
1898418987 } else {
......@@ -18986,15 +18989,15 @@ fn resolveCallingConventionValues(
1898618989 var ret_tracking_i: usize = 0;
1898718990
1898818991 const classes = switch (resolved_cc) {
18989 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, pt, self.target.*, .ret), .none),
18990 .Win64 => &.{abi.classifyWindows(ret_ty, pt)},
18992 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, zcu, self.target.*, .ret), .none),
18993 .Win64 => &.{abi.classifyWindows(ret_ty, zcu)},
1899118994 else => unreachable,
1899218995 };
1899318996 for (classes) |class| switch (class) {
1899418997 .integer => {
1899518998 const ret_int_reg = registerAlias(
1899618999 abi.getCAbiIntReturnRegs(resolved_cc)[ret_int_reg_i],
18997 @intCast(@min(ret_ty.abiSize(pt), 8)),
19000 @intCast(@min(ret_ty.abiSize(zcu), 8)),
1899819001 );
1899919002 ret_int_reg_i += 1;
1900019003
......@@ -19004,7 +19007,7 @@ fn resolveCallingConventionValues(
1900419007 .sse, .float, .float_combine, .win_i128 => {
1900519008 const ret_sse_reg = registerAlias(
1900619009 abi.getCAbiSseReturnRegs(resolved_cc)[ret_sse_reg_i],
19007 @intCast(ret_ty.abiSize(pt)),
19010 @intCast(ret_ty.abiSize(zcu)),
1900819011 );
1900919012 ret_sse_reg_i += 1;
1901019013
......@@ -19047,7 +19050,7 @@ fn resolveCallingConventionValues(
1904719050
1904819051 // Input params
1904919052 for (param_types, result.args) |ty, *arg| {
19050 assert(ty.hasRuntimeBitsIgnoreComptime(pt));
19053 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
1905119054 switch (resolved_cc) {
1905219055 .SysV => {},
1905319056 .Win64 => {
......@@ -19061,8 +19064,8 @@ fn resolveCallingConventionValues(
1906119064 var arg_mcv_i: usize = 0;
1906219065
1906319066 const classes = switch (resolved_cc) {
19064 .SysV => mem.sliceTo(&abi.classifySystemV(ty, pt, self.target.*, .arg), .none),
19065 .Win64 => &.{abi.classifyWindows(ty, pt)},
19067 .SysV => mem.sliceTo(&abi.classifySystemV(ty, zcu, self.target.*, .arg), .none),
19068 .Win64 => &.{abi.classifyWindows(ty, zcu)},
1906619069 else => unreachable,
1906719070 };
1906819071 for (classes) |class| switch (class) {
......@@ -19072,7 +19075,7 @@ fn resolveCallingConventionValues(
1907219075
1907319076 const param_int_reg = registerAlias(
1907419077 abi.getCAbiIntParamRegs(resolved_cc)[param_int_reg_i],
19075 @intCast(@min(ty.abiSize(pt), 8)),
19078 @intCast(@min(ty.abiSize(zcu), 8)),
1907619079 );
1907719080 param_int_reg_i += 1;
1907819081
......@@ -19085,7 +19088,7 @@ fn resolveCallingConventionValues(
1908519088
1908619089 const param_sse_reg = registerAlias(
1908719090 abi.getCAbiSseParamRegs(resolved_cc)[param_sse_reg_i],
19088 @intCast(ty.abiSize(pt)),
19091 @intCast(ty.abiSize(zcu)),
1908919092 );
1909019093 param_sse_reg_i += 1;
1909119094
......@@ -19098,7 +19101,7 @@ fn resolveCallingConventionValues(
1909819101 .x87, .x87up, .complex_x87, .memory => break,
1909919102 else => unreachable,
1910019103 },
19101 .Win64 => if (ty.abiSize(pt) > 8) {
19104 .Win64 => if (ty.abiSize(zcu) > 8) {
1910219105 const param_int_reg =
1910319106 abi.getCAbiIntParamRegs(resolved_cc)[param_int_reg_i].to64();
1910419107 param_int_reg_i += 1;
......@@ -19117,10 +19120,10 @@ fn resolveCallingConventionValues(
1911719120 param_int_reg_i = param_int_regs_len;
1911819121
1911919122 const frame_elem_align = 8;
19120 const frame_elems_len = ty.vectorLen(mod) - remaining_param_int_regs;
19123 const frame_elems_len = ty.vectorLen(zcu) - remaining_param_int_regs;
1912119124 const frame_elem_size = mem.alignForward(
1912219125 u64,
19123 ty.childType(mod).abiSize(pt),
19126 ty.childType(zcu).abiSize(zcu),
1912419127 frame_elem_align,
1912519128 );
1912619129 const frame_size: u31 = @intCast(frame_elems_len * frame_elem_size);
......@@ -19144,9 +19147,9 @@ fn resolveCallingConventionValues(
1914419147 continue;
1914519148 }
1914619149
19147 const param_size: u31 = @intCast(ty.abiSize(pt));
19150 const param_size: u31 = @intCast(ty.abiSize(zcu));
1914819151 const param_align: u31 =
19149 @intCast(@max(ty.abiAlignment(pt).toByteUnits().?, 8));
19152 @intCast(@max(ty.abiAlignment(zcu).toByteUnits().?, 8));
1915019153 result.stack_byte_count =
1915119154 mem.alignForward(u31, result.stack_byte_count, param_align);
1915219155 arg.* = .{ .load_frame = .{
......@@ -19164,13 +19167,13 @@ fn resolveCallingConventionValues(
1916419167 result.stack_align = .@"16";
1916519168
1916619169 // Return values
19167 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
19170 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
1916819171 result.return_value = InstTracking.init(.unreach);
19169 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
19172 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1917019173 result.return_value = InstTracking.init(.none);
1917119174 } else {
1917219175 const ret_reg = abi.getCAbiIntReturnRegs(resolved_cc)[0];
19173 const ret_ty_size: u31 = @intCast(ret_ty.abiSize(pt));
19176 const ret_ty_size: u31 = @intCast(ret_ty.abiSize(zcu));
1917419177 if (ret_ty_size <= 8 and !ret_ty.isRuntimeFloat()) {
1917519178 const aliased_reg = registerAlias(ret_reg, ret_ty_size);
1917619179 result.return_value = .{ .short = .{ .register = aliased_reg }, .long = .none };
......@@ -19185,12 +19188,12 @@ fn resolveCallingConventionValues(
1918519188
1918619189 // Input params
1918719190 for (param_types, result.args) |ty, *arg| {
19188 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
19191 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1918919192 arg.* = .none;
1919019193 continue;
1919119194 }
19192 const param_size: u31 = @intCast(ty.abiSize(pt));
19193 const param_align: u31 = @intCast(ty.abiAlignment(pt).toByteUnits().?);
19195 const param_size: u31 = @intCast(ty.abiSize(zcu));
19196 const param_align: u31 = @intCast(ty.abiAlignment(zcu).toByteUnits().?);
1919419197 result.stack_byte_count =
1919519198 mem.alignForward(u31, result.stack_byte_count, param_align);
1919619199 arg.* = .{ .load_frame = .{
......@@ -19276,25 +19279,26 @@ fn registerAlias(reg: Register, size_bytes: u32) Register {
1927619279
1927719280fn memSize(self: *Self, ty: Type) Memory.Size {
1927819281 const pt = self.pt;
19279 const mod = pt.zcu;
19280 return switch (ty.zigTypeTag(mod)) {
19282 const zcu = pt.zcu;
19283 return switch (ty.zigTypeTag(zcu)) {
1928119284 .Float => Memory.Size.fromBitSize(ty.floatBits(self.target.*)),
19282 else => Memory.Size.fromSize(@intCast(ty.abiSize(pt))),
19285 else => Memory.Size.fromSize(@intCast(ty.abiSize(zcu))),
1928319286 };
1928419287}
1928519288
1928619289fn splitType(self: *Self, ty: Type) ![2]Type {
1928719290 const pt = self.pt;
19288 const classes = mem.sliceTo(&abi.classifySystemV(ty, pt, self.target.*, .other), .none);
19291 const zcu = pt.zcu;
19292 const classes = mem.sliceTo(&abi.classifySystemV(ty, zcu, self.target.*, .other), .none);
1928919293 var parts: [2]Type = undefined;
1929019294 if (classes.len == 2) for (&parts, classes, 0..) |*part, class, part_i| {
1929119295 part.* = switch (class) {
1929219296 .integer => switch (part_i) {
1929319297 0 => Type.u64,
1929419298 1 => part: {
19295 const elem_size = ty.abiAlignment(pt).minStrict(.@"8").toByteUnits().?;
19299 const elem_size = ty.abiAlignment(zcu).minStrict(.@"8").toByteUnits().?;
1929619300 const elem_ty = try pt.intType(.unsigned, @intCast(elem_size * 8));
19297 break :part switch (@divExact(ty.abiSize(pt) - 8, elem_size)) {
19301 break :part switch (@divExact(ty.abiSize(zcu) - 8, elem_size)) {
1929819302 1 => elem_ty,
1929919303 else => |len| try pt.arrayType(.{ .len = len, .child = elem_ty.toIntern() }),
1930019304 };
......@@ -19306,7 +19310,7 @@ fn splitType(self: *Self, ty: Type) ![2]Type {
1930619310 .sse => Type.f64,
1930719311 else => break,
1930819312 };
19309 } else if (parts[0].abiSize(pt) + parts[1].abiSize(pt) == ty.abiSize(pt)) return parts;
19313 } else if (parts[0].abiSize(zcu) + parts[1].abiSize(zcu) == ty.abiSize(zcu)) return parts;
1931019314 return self.fail("TODO implement splitType for {}", .{ty.fmt(pt)});
1931119315}
1931219316
......@@ -19314,10 +19318,10 @@ fn splitType(self: *Self, ty: Type) ![2]Type {
1931419318/// Clobbers any remaining bits.
1931519319fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
1931619320 const pt = self.pt;
19317 const mod = pt.zcu;
19318 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{
19321 const zcu = pt.zcu;
19322 const int_info = if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else std.builtin.Type.Int{
1931919323 .signedness = .unsigned,
19320 .bits = @intCast(ty.bitSize(pt)),
19324 .bits = @intCast(ty.bitSize(zcu)),
1932119325 };
1932219326 const shift = math.cast(u6, 64 - int_info.bits % 64) orelse return;
1932319327 try self.spillEflagsIfOccupied();
......@@ -19362,9 +19366,9 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
1936219366
1936319367fn regBitSize(self: *Self, ty: Type) u64 {
1936419368 const pt = self.pt;
19365 const mod = pt.zcu;
19366 const abi_size = ty.abiSize(pt);
19367 return switch (ty.zigTypeTag(mod)) {
19369 const zcu = pt.zcu;
19370 const abi_size = ty.abiSize(zcu);
19371 return switch (ty.zigTypeTag(zcu)) {
1936819372 else => switch (abi_size) {
1936919373 1 => 8,
1937019374 2 => 16,
......@@ -19381,7 +19385,7 @@ fn regBitSize(self: *Self, ty: Type) u64 {
1938119385}
1938219386
1938319387fn regExtraBits(self: *Self, ty: Type) u64 {
19384 return self.regBitSize(ty) - ty.bitSize(self.pt);
19388 return self.regBitSize(ty) - ty.bitSize(self.pt.zcu);
1938519389}
1938619390
1938719391fn hasFeature(self: *Self, feature: Target.x86.Feature) bool {
......@@ -19396,14 +19400,14 @@ fn hasAllFeatures(self: *Self, features: anytype) bool {
1939619400
1939719401fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
1939819402 const pt = self.pt;
19399 const mod = pt.zcu;
19400 return self.air.typeOf(inst, &mod.intern_pool);
19403 const zcu = pt.zcu;
19404 return self.air.typeOf(inst, &zcu.intern_pool);
1940119405}
1940219406
1940319407fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
1940419408 const pt = self.pt;
19405 const mod = pt.zcu;
19406 return self.air.typeOfIndex(inst, &mod.intern_pool);
19409 const zcu = pt.zcu;
19410 return self.air.typeOfIndex(inst, &zcu.intern_pool);
1940719411}
1940819412
1940919413fn intCompilerRtAbiName(int_bits: u32) u8 {
......@@ -19455,17 +19459,17 @@ fn floatLibcAbiSuffix(ty: Type) []const u8 {
1945519459
1945619460fn promoteInt(self: *Self, ty: Type) Type {
1945719461 const pt = self.pt;
19458 const mod = pt.zcu;
19462 const zcu = pt.zcu;
1945919463 const int_info: InternPool.Key.IntType = switch (ty.toIntern()) {
1946019464 .bool_type => .{ .signedness = .unsigned, .bits = 1 },
19461 else => if (ty.isAbiInt(mod)) ty.intInfo(mod) else return ty,
19465 else => if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else return ty,
1946219466 };
1946319467 for ([_]Type{
1946419468 Type.c_int, Type.c_uint,
1946519469 Type.c_long, Type.c_ulong,
1946619470 Type.c_longlong, Type.c_ulonglong,
1946719471 }) |promote_ty| {
19468 const promote_info = promote_ty.intInfo(mod);
19472 const promote_info = promote_ty.intInfo(zcu);
1946919473 if (int_info.signedness == .signed and promote_info.signedness == .unsigned) continue;
1947019474 if (int_info.bits + @intFromBool(int_info.signedness == .unsigned and
1947119475 promote_info.signedness == .signed) <= promote_info.bits) return promote_ty;
src/arch/x86_64/abi.zig+35-35
......@@ -44,7 +44,7 @@ pub const Class = enum {
4444 }
4545};
4646
47pub fn classifyWindows(ty: Type, pt: Zcu.PerThread) Class {
47pub fn classifyWindows(ty: Type, zcu: *Zcu) Class {
4848 // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-2017
4949 // "There's a strict one-to-one correspondence between a function call's arguments
5050 // and the registers used for those arguments. Any argument that doesn't fit in 8
......@@ -53,7 +53,7 @@ pub fn classifyWindows(ty: Type, pt: Zcu.PerThread) Class {
5353 // "All floating point operations are done using the 16 XMM registers."
5454 // "Structs and unions of size 8, 16, 32, or 64 bits, and __m64 types, are passed
5555 // as if they were integers of the same size."
56 switch (ty.zigTypeTag(pt.zcu)) {
56 switch (ty.zigTypeTag(zcu)) {
5757 .Pointer,
5858 .Int,
5959 .Bool,
......@@ -68,12 +68,12 @@ pub fn classifyWindows(ty: Type, pt: Zcu.PerThread) Class {
6868 .ErrorUnion,
6969 .AnyFrame,
7070 .Frame,
71 => switch (ty.abiSize(pt)) {
71 => switch (ty.abiSize(zcu)) {
7272 0 => unreachable,
7373 1, 2, 4, 8 => return .integer,
74 else => switch (ty.zigTypeTag(pt.zcu)) {
74 else => switch (ty.zigTypeTag(zcu)) {
7575 .Int => return .win_i128,
76 .Struct, .Union => if (ty.containerLayout(pt.zcu) == .@"packed") {
76 .Struct, .Union => if (ty.containerLayout(zcu) == .@"packed") {
7777 return .win_i128;
7878 } else {
7979 return .memory;
......@@ -100,14 +100,14 @@ pub const Context = enum { ret, arg, field, other };
100100
101101/// There are a maximum of 8 possible return slots. Returned values are in
102102/// the beginning of the array; unused slots are filled with .none.
103pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Context) [8]Class {
103pub fn classifySystemV(ty: Type, zcu: *Zcu, target: std.Target, ctx: Context) [8]Class {
104104 const memory_class = [_]Class{
105105 .memory, .none, .none, .none,
106106 .none, .none, .none, .none,
107107 };
108108 var result = [1]Class{.none} ** 8;
109 switch (ty.zigTypeTag(pt.zcu)) {
110 .Pointer => switch (ty.ptrSize(pt.zcu)) {
109 switch (ty.zigTypeTag(zcu)) {
110 .Pointer => switch (ty.ptrSize(zcu)) {
111111 .Slice => {
112112 result[0] = .integer;
113113 result[1] = .integer;
......@@ -119,7 +119,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
119119 },
120120 },
121121 .Int, .Enum, .ErrorSet => {
122 const bits = ty.intInfo(pt.zcu).bits;
122 const bits = ty.intInfo(zcu).bits;
123123 if (bits <= 64) {
124124 result[0] = .integer;
125125 return result;
......@@ -185,8 +185,8 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
185185 else => unreachable,
186186 },
187187 .Vector => {
188 const elem_ty = ty.childType(pt.zcu);
189 const bits = elem_ty.bitSize(pt) * ty.arrayLen(pt.zcu);
188 const elem_ty = ty.childType(zcu);
189 const bits = elem_ty.bitSize(zcu) * ty.arrayLen(zcu);
190190 if (elem_ty.toIntern() == .bool_type) {
191191 if (bits <= 32) return .{
192192 .integer, .none, .none, .none,
......@@ -250,7 +250,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
250250 return memory_class;
251251 },
252252 .Optional => {
253 if (ty.isPtrLikeOptional(pt.zcu)) {
253 if (ty.isPtrLikeOptional(zcu)) {
254254 result[0] = .integer;
255255 return result;
256256 }
......@@ -261,8 +261,8 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
261261 // it contains unaligned fields, it has class MEMORY"
262262 // "If the size of the aggregate exceeds a single eightbyte, each is classified
263263 // separately.".
264 const ty_size = ty.abiSize(pt);
265 switch (ty.containerLayout(pt.zcu)) {
264 const ty_size = ty.abiSize(zcu);
265 switch (ty.containerLayout(zcu)) {
266266 .auto, .@"extern" => {},
267267 .@"packed" => {
268268 assert(ty_size <= 16);
......@@ -274,10 +274,10 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
274274 if (ty_size > 64)
275275 return memory_class;
276276
277 _ = if (pt.zcu.typeToStruct(ty)) |loaded_struct|
278 classifySystemVStruct(&result, 0, loaded_struct, pt, target)
279 else if (pt.zcu.typeToUnion(ty)) |loaded_union|
280 classifySystemVUnion(&result, 0, loaded_union, pt, target)
277 _ = if (zcu.typeToStruct(ty)) |loaded_struct|
278 classifySystemVStruct(&result, 0, loaded_struct, zcu, target)
279 else if (zcu.typeToUnion(ty)) |loaded_union|
280 classifySystemVUnion(&result, 0, loaded_union, zcu, target)
281281 else
282282 unreachable;
283283
......@@ -306,7 +306,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
306306 return result;
307307 },
308308 .Array => {
309 const ty_size = ty.abiSize(pt);
309 const ty_size = ty.abiSize(zcu);
310310 if (ty_size <= 8) {
311311 result[0] = .integer;
312312 return result;
......@@ -326,10 +326,10 @@ fn classifySystemVStruct(
326326 result: *[8]Class,
327327 starting_byte_offset: u64,
328328 loaded_struct: InternPool.LoadedStructType,
329 pt: Zcu.PerThread,
329 zcu: *Zcu,
330330 target: std.Target,
331331) u64 {
332 const ip = &pt.zcu.intern_pool;
332 const ip = &zcu.intern_pool;
333333 var byte_offset = starting_byte_offset;
334334 var field_it = loaded_struct.iterateRuntimeOrder(ip);
335335 while (field_it.next()) |field_index| {
......@@ -338,29 +338,29 @@ fn classifySystemVStruct(
338338 byte_offset = std.mem.alignForward(
339339 u64,
340340 byte_offset,
341 field_align.toByteUnits() orelse field_ty.abiAlignment(pt).toByteUnits().?,
341 field_align.toByteUnits() orelse field_ty.abiAlignment(zcu).toByteUnits().?,
342342 );
343 if (pt.zcu.typeToStruct(field_ty)) |field_loaded_struct| {
343 if (zcu.typeToStruct(field_ty)) |field_loaded_struct| {
344344 switch (field_loaded_struct.layout) {
345345 .auto, .@"extern" => {
346 byte_offset = classifySystemVStruct(result, byte_offset, field_loaded_struct, pt, target);
346 byte_offset = classifySystemVStruct(result, byte_offset, field_loaded_struct, zcu, target);
347347 continue;
348348 },
349349 .@"packed" => {},
350350 }
351 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {
351 } else if (zcu.typeToUnion(field_ty)) |field_loaded_union| {
352352 switch (field_loaded_union.flagsUnordered(ip).layout) {
353353 .auto, .@"extern" => {
354 byte_offset = classifySystemVUnion(result, byte_offset, field_loaded_union, pt, target);
354 byte_offset = classifySystemVUnion(result, byte_offset, field_loaded_union, zcu, target);
355355 continue;
356356 },
357357 .@"packed" => {},
358358 }
359359 }
360 const field_classes = std.mem.sliceTo(&classifySystemV(field_ty, pt, target, .field), .none);
360 const field_classes = std.mem.sliceTo(&classifySystemV(field_ty, zcu, target, .field), .none);
361361 for (result[@intCast(byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
362362 result_class.* = result_class.combineSystemV(field_class);
363 byte_offset += field_ty.abiSize(pt);
363 byte_offset += field_ty.abiSize(zcu);
364364 }
365365 const final_byte_offset = starting_byte_offset + loaded_struct.sizeUnordered(ip);
366366 std.debug.assert(final_byte_offset == std.mem.alignForward(
......@@ -375,30 +375,30 @@ fn classifySystemVUnion(
375375 result: *[8]Class,
376376 starting_byte_offset: u64,
377377 loaded_union: InternPool.LoadedUnionType,
378 pt: Zcu.PerThread,
378 zcu: *Zcu,
379379 target: std.Target,
380380) u64 {
381 const ip = &pt.zcu.intern_pool;
381 const ip = &zcu.intern_pool;
382382 for (0..loaded_union.field_types.len) |field_index| {
383383 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
384 if (pt.zcu.typeToStruct(field_ty)) |field_loaded_struct| {
384 if (zcu.typeToStruct(field_ty)) |field_loaded_struct| {
385385 switch (field_loaded_struct.layout) {
386386 .auto, .@"extern" => {
387 _ = classifySystemVStruct(result, starting_byte_offset, field_loaded_struct, pt, target);
387 _ = classifySystemVStruct(result, starting_byte_offset, field_loaded_struct, zcu, target);
388388 continue;
389389 },
390390 .@"packed" => {},
391391 }
392 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {
392 } else if (zcu.typeToUnion(field_ty)) |field_loaded_union| {
393393 switch (field_loaded_union.flagsUnordered(ip).layout) {
394394 .auto, .@"extern" => {
395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, pt, target);
395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, zcu, target);
396396 continue;
397397 },
398398 .@"packed" => {},
399399 }
400400 }
401 const field_classes = std.mem.sliceTo(&classifySystemV(field_ty, pt, target, .field), .none);
401 const field_classes = std.mem.sliceTo(&classifySystemV(field_ty, zcu, target, .field), .none);
402402 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
403403 result_class.* = result_class.combineSystemV(field_class);
404404 }
src/codegen.zig+59-58
......@@ -198,17 +198,17 @@ pub fn generateSymbol(
198198 const tracy = trace(@src());
199199 defer tracy.end();
200200
201 const mod = pt.zcu;
202 const ip = &mod.intern_pool;
203 const ty = val.typeOf(mod);
201 const zcu = pt.zcu;
202 const ip = &zcu.intern_pool;
203 const ty = val.typeOf(zcu);
204204
205 const target = mod.getTarget();
205 const target = zcu.getTarget();
206206 const endian = target.cpu.arch.endian();
207207
208208 log.debug("generateSymbol: val = {}", .{val.fmtValue(pt)});
209209
210 if (val.isUndefDeep(mod)) {
211 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;
210 if (val.isUndefDeep(zcu)) {
211 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow;
212212 try code.appendNTimes(0xaa, abi_size);
213213 return .ok;
214214 }
......@@ -254,9 +254,9 @@ pub fn generateSymbol(
254254 .empty_enum_value,
255255 => unreachable, // non-runtime values
256256 .int => {
257 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;
257 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow;
258258 var space: Value.BigIntSpace = undefined;
259 const int_val = val.toBigInt(&space, pt);
259 const int_val = val.toBigInt(&space, zcu);
260260 int_val.writeTwosComplement(try code.addManyAsSlice(abi_size), endian);
261261 },
262262 .err => |err| {
......@@ -264,20 +264,20 @@ pub fn generateSymbol(
264264 try code.writer().writeInt(u16, @intCast(int), endian);
265265 },
266266 .error_union => |error_union| {
267 const payload_ty = ty.errorUnionPayload(mod);
267 const payload_ty = ty.errorUnionPayload(zcu);
268268 const err_val: u16 = switch (error_union.val) {
269269 .err_name => |err_name| @intCast(try pt.getErrorValue(err_name)),
270270 .payload => 0,
271271 };
272272
273 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
273 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
274274 try code.writer().writeInt(u16, err_val, endian);
275275 return .ok;
276276 }
277277
278 const payload_align = payload_ty.abiAlignment(pt);
279 const error_align = Type.anyerror.abiAlignment(pt);
280 const abi_align = ty.abiAlignment(pt);
278 const payload_align = payload_ty.abiAlignment(zcu);
279 const error_align = Type.anyerror.abiAlignment(zcu);
280 const abi_align = ty.abiAlignment(zcu);
281281
282282 // error value first when its type is larger than the error union's payload
283283 if (error_align.order(payload_align) == .gt) {
......@@ -317,7 +317,7 @@ pub fn generateSymbol(
317317 }
318318 },
319319 .enum_tag => |enum_tag| {
320 const int_tag_ty = ty.intTagType(mod);
320 const int_tag_ty = ty.intTagType(zcu);
321321 switch (try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, debug_output, reloc_info)) {
322322 .ok => {},
323323 .fail => |em| return .{ .fail = em },
......@@ -329,7 +329,7 @@ pub fn generateSymbol(
329329 .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(8)),
330330 .f80 => |f80_val| {
331331 writeFloat(f80, f80_val, target, endian, try code.addManyAsArray(10));
332 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;
332 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow;
333333 try code.appendNTimes(0, abi_size - 10);
334334 },
335335 .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)),
......@@ -349,11 +349,11 @@ pub fn generateSymbol(
349349 }
350350 },
351351 .opt => {
352 const payload_type = ty.optionalChild(mod);
353 const payload_val = val.optionalValue(mod);
354 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;
352 const payload_type = ty.optionalChild(zcu);
353 const payload_val = val.optionalValue(zcu);
354 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow;
355355
356 if (ty.optionalReprIsPayload(mod)) {
356 if (ty.optionalReprIsPayload(zcu)) {
357357 if (payload_val) |value| {
358358 switch (try generateSymbol(bin_file, pt, src_loc, value, code, debug_output, reloc_info)) {
359359 .ok => {},
......@@ -363,8 +363,8 @@ pub fn generateSymbol(
363363 try code.appendNTimes(0, abi_size);
364364 }
365365 } else {
366 const padding = abi_size - (math.cast(usize, payload_type.abiSize(pt)) orelse return error.Overflow) - 1;
367 if (payload_type.hasRuntimeBits(pt)) {
366 const padding = abi_size - (math.cast(usize, payload_type.abiSize(zcu)) orelse return error.Overflow) - 1;
367 if (payload_type.hasRuntimeBits(zcu)) {
368368 const value = payload_val orelse Value.fromInterned(try pt.intern(.{
369369 .undef = payload_type.toIntern(),
370370 }));
......@@ -398,7 +398,7 @@ pub fn generateSymbol(
398398 },
399399 },
400400 .vector_type => |vector_type| {
401 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;
401 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow;
402402 if (vector_type.child == .bool_type) {
403403 const bytes = try code.addManyAsSlice(abi_size);
404404 @memset(bytes, 0xaa);
......@@ -458,7 +458,7 @@ pub fn generateSymbol(
458458 }
459459
460460 const padding = abi_size -
461 (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(pt) * vector_type.len) orelse
461 (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(zcu) * vector_type.len) orelse
462462 return error.Overflow);
463463 if (padding > 0) try code.appendNTimes(0, padding);
464464 }
......@@ -471,7 +471,7 @@ pub fn generateSymbol(
471471 0..,
472472 ) |field_ty, comptime_val, index| {
473473 if (comptime_val != .none) continue;
474 if (!Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
474 if (!Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
475475
476476 const field_val = switch (aggregate.storage) {
477477 .bytes => |bytes| try pt.intern(.{ .int = .{
......@@ -489,7 +489,7 @@ pub fn generateSymbol(
489489 const unpadded_field_end = code.items.len - struct_begin;
490490
491491 // Pad struct members if required
492 const padded_field_end = ty.structFieldOffset(index + 1, pt);
492 const padded_field_end = ty.structFieldOffset(index + 1, zcu);
493493 const padding = math.cast(usize, padded_field_end - unpadded_field_end) orelse
494494 return error.Overflow;
495495
......@@ -502,7 +502,7 @@ pub fn generateSymbol(
502502 const struct_type = ip.loadStructType(ty.toIntern());
503503 switch (struct_type.layout) {
504504 .@"packed" => {
505 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;
505 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow;
506506 const current_pos = code.items.len;
507507 try code.appendNTimes(0, abi_size);
508508 var bits: u16 = 0;
......@@ -519,8 +519,8 @@ pub fn generateSymbol(
519519
520520 // pointer may point to a decl which must be marked used
521521 // but can also result in a relocation. Therefore we handle those separately.
522 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .Pointer) {
523 const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(pt)) orelse
522 if (Type.fromInterned(field_ty).zigTypeTag(zcu) == .Pointer) {
523 const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(zcu)) orelse
524524 return error.Overflow;
525525 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
526526 defer tmp_list.deinit();
......@@ -531,7 +531,7 @@ pub fn generateSymbol(
531531 } else {
532532 Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), pt, code.items[current_pos..], bits) catch unreachable;
533533 }
534 bits += @intCast(Type.fromInterned(field_ty).bitSize(pt));
534 bits += @intCast(Type.fromInterned(field_ty).bitSize(zcu));
535535 }
536536 },
537537 .auto, .@"extern" => {
......@@ -542,7 +542,7 @@ pub fn generateSymbol(
542542 var it = struct_type.iterateRuntimeOrder(ip);
543543 while (it.next()) |field_index| {
544544 const field_ty = field_types[field_index];
545 if (!Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
545 if (!Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
546546
547547 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
548548 .bytes => |bytes| try pt.intern(.{ .int = .{
......@@ -580,7 +580,7 @@ pub fn generateSymbol(
580580 else => unreachable,
581581 },
582582 .un => |un| {
583 const layout = ty.unionGetLayout(pt);
583 const layout = ty.unionGetLayout(zcu);
584584
585585 if (layout.payload_size == 0) {
586586 return generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info);
......@@ -594,11 +594,11 @@ pub fn generateSymbol(
594594 }
595595 }
596596
597 const union_obj = mod.typeToUnion(ty).?;
597 const union_obj = zcu.typeToUnion(ty).?;
598598 if (un.tag != .none) {
599 const field_index = ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?;
599 const field_index = ty.unionTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
600600 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
601 if (!field_ty.hasRuntimeBits(pt)) {
601 if (!field_ty.hasRuntimeBits(zcu)) {
602602 try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);
603603 } else {
604604 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) {
......@@ -606,7 +606,7 @@ pub fn generateSymbol(
606606 .fail => |em| return Result{ .fail = em },
607607 }
608608
609 const padding = math.cast(usize, layout.payload_size - field_ty.abiSize(pt)) orelse return error.Overflow;
609 const padding = math.cast(usize, layout.payload_size - field_ty.abiSize(zcu)) orelse return error.Overflow;
610610 if (padding > 0) {
611611 try code.appendNTimes(0, padding);
612612 }
......@@ -661,7 +661,7 @@ fn lowerPtr(
661661 reloc_info,
662662 offset + errUnionPayloadOffset(
663663 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu).errorUnionPayload(zcu),
664 pt,
664 zcu,
665665 ),
666666 ),
667667 .opt_payload => |opt_ptr| try lowerPtr(
......@@ -687,7 +687,7 @@ fn lowerPtr(
687687 };
688688 },
689689 .Struct, .Union => switch (base_ty.containerLayout(zcu)) {
690 .auto => base_ty.structFieldOffset(@intCast(field.index), pt),
690 .auto => base_ty.structFieldOffset(@intCast(field.index), zcu),
691691 .@"extern", .@"packed" => unreachable,
692692 },
693693 else => unreachable,
......@@ -713,15 +713,16 @@ fn lowerUavRef(
713713 offset: u64,
714714) CodeGenError!Result {
715715 _ = debug_output;
716 const ip = &pt.zcu.intern_pool;
716 const zcu = pt.zcu;
717 const ip = &zcu.intern_pool;
717718 const target = lf.comp.root_mod.resolved_target.result;
718719
719720 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
720721 const uav_val = uav.val;
721722 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));
722723 log.debug("lowerUavRef: ty = {}", .{uav_ty.fmt(pt)});
723 const is_fn_body = uav_ty.zigTypeTag(pt.zcu) == .Fn;
724 if (!is_fn_body and !uav_ty.hasRuntimeBits(pt)) {
724 const is_fn_body = uav_ty.zigTypeTag(zcu) == .Fn;
725 if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) {
725726 try code.appendNTimes(0xaa, ptr_width_bytes);
726727 return Result.ok;
727728 }
......@@ -768,7 +769,7 @@ fn lowerNavRef(
768769 const ptr_width = target.ptrBitWidth();
769770 const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));
770771 const is_fn_body = nav_ty.zigTypeTag(zcu) == .Fn;
771 if (!is_fn_body and !nav_ty.hasRuntimeBits(pt)) {
772 if (!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) {
772773 try code.appendNTimes(0xaa, @divExact(ptr_width, 8));
773774 return Result.ok;
774775 }
......@@ -860,7 +861,7 @@ fn genNavRef(
860861 const ty = val.typeOf(zcu);
861862 log.debug("genNavRef: val = {}", .{val.fmtValue(pt)});
862863
863 if (!ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
864 if (!ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
864865 const imm: u64 = switch (@divExact(target.ptrBitWidth(), 8)) {
865866 1 => 0xaa,
866867 2 => 0xaaaa,
......@@ -994,8 +995,8 @@ pub fn genTypedValue(
994995 const info = ty.intInfo(zcu);
995996 if (info.bits <= target.ptrBitWidth()) {
996997 const unsigned: u64 = switch (info.signedness) {
997 .signed => @bitCast(val.toSignedInt(pt)),
998 .unsigned => val.toUnsignedInt(pt),
998 .signed => @bitCast(val.toSignedInt(zcu)),
999 .unsigned => val.toUnsignedInt(zcu),
9991000 };
10001001 return .{ .mcv = .{ .immediate = unsigned } };
10011002 }
......@@ -1012,7 +1013,7 @@ pub fn genTypedValue(
10121013 val.optionalValue(zcu) orelse return .{ .mcv = .{ .immediate = 0 } },
10131014 target,
10141015 );
1015 } else if (ty.abiSize(pt) == 1) {
1016 } else if (ty.abiSize(zcu) == 1) {
10161017 return .{ .mcv = .{ .immediate = @intFromBool(!val.isNull(zcu)) } };
10171018 }
10181019 },
......@@ -1034,7 +1035,7 @@ pub fn genTypedValue(
10341035 .ErrorUnion => {
10351036 const err_type = ty.errorUnionSet(zcu);
10361037 const payload_type = ty.errorUnionPayload(zcu);
1037 if (!payload_type.hasRuntimeBitsIgnoreComptime(pt)) {
1038 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
10381039 // We use the error type directly as the type.
10391040 const err_int_ty = try pt.errorIntType();
10401041 switch (ip.indexToKey(val.toIntern()).error_union.val) {
......@@ -1074,23 +1075,23 @@ pub fn genTypedValue(
10741075 return lf.lowerUav(pt, val.toIntern(), .none, src_loc);
10751076}
10761077
1077pub fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {
1078 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;
1079 const payload_align = payload_ty.abiAlignment(pt);
1080 const error_align = Type.anyerror.abiAlignment(pt);
1081 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1078pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
1079 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
1080 const payload_align = payload_ty.abiAlignment(zcu);
1081 const error_align = Type.anyerror.abiAlignment(zcu);
1082 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
10821083 return 0;
10831084 } else {
1084 return payload_align.forward(Type.anyerror.abiSize(pt));
1085 return payload_align.forward(Type.anyerror.abiSize(zcu));
10851086 }
10861087}
10871088
1088pub fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {
1089 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;
1090 const payload_align = payload_ty.abiAlignment(pt);
1091 const error_align = Type.anyerror.abiAlignment(pt);
1092 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1093 return error_align.forward(payload_ty.abiSize(pt));
1089pub fn errUnionErrorOffset(payload_ty: Type, zcu: *Zcu) u64 {
1090 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
1091 const payload_align = payload_ty.abiAlignment(zcu);
1092 const error_align = Type.anyerror.abiAlignment(zcu);
1093 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1094 return error_align.forward(payload_ty.abiSize(zcu));
10941095 } else {
10951096 return 0;
10961097 }
src/codegen/c.zig+121-116
......@@ -334,7 +334,7 @@ pub const Function = struct {
334334 const writer = f.object.codeHeaderWriter();
335335 const decl_c_value = try f.allocLocalValue(.{
336336 .ctype = try f.ctypeFromType(ty, .complete),
337 .alignas = CType.AlignAs.fromAbiAlignment(ty.abiAlignment(pt)),
337 .alignas = CType.AlignAs.fromAbiAlignment(ty.abiAlignment(pt.zcu)),
338338 });
339339 const gpa = f.object.dg.gpa;
340340 try f.allocs.put(gpa, decl_c_value.new_local, false);
......@@ -372,7 +372,7 @@ pub const Function = struct {
372372 fn allocLocal(f: *Function, inst: ?Air.Inst.Index, ty: Type) !CValue {
373373 return f.allocAlignedLocal(inst, .{
374374 .ctype = try f.ctypeFromType(ty, .complete),
375 .alignas = CType.AlignAs.fromAbiAlignment(ty.abiAlignment(f.object.dg.pt)),
375 .alignas = CType.AlignAs.fromAbiAlignment(ty.abiAlignment(f.object.dg.pt.zcu)),
376376 });
377377 }
378378
......@@ -648,7 +648,7 @@ pub const DeclGen = struct {
648648
649649 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
650650 const ptr_ty = Type.fromInterned(uav.orig_ty);
651 if (ptr_ty.isPtrAtRuntime(zcu) and !uav_ty.isFnOrHasRuntimeBits(pt)) {
651 if (ptr_ty.isPtrAtRuntime(zcu) and !uav_ty.isFnOrHasRuntimeBits(zcu)) {
652652 return dg.writeCValue(writer, .{ .undef = ptr_ty });
653653 }
654654
......@@ -688,7 +688,7 @@ pub const DeclGen = struct {
688688 // alignment. If there is already an entry, keep the greater alignment.
689689 const explicit_alignment = ptr_type.flags.alignment;
690690 if (explicit_alignment != .none) {
691 const abi_alignment = Type.fromInterned(ptr_type.child).abiAlignment(pt);
691 const abi_alignment = Type.fromInterned(ptr_type.child).abiAlignment(zcu);
692692 if (explicit_alignment.order(abi_alignment).compare(.gt)) {
693693 const aligned_gop = try dg.aligned_uavs.getOrPut(dg.gpa, uav.val);
694694 aligned_gop.value_ptr.* = if (aligned_gop.found_existing)
......@@ -722,7 +722,7 @@ pub const DeclGen = struct {
722722 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
723723 const nav_ty = Type.fromInterned(ip.getNav(owner_nav).typeOf(ip));
724724 const ptr_ty = try pt.navPtrType(owner_nav);
725 if (!nav_ty.isFnOrHasRuntimeBits(pt)) {
725 if (!nav_ty.isFnOrHasRuntimeBits(zcu)) {
726726 return dg.writeCValue(writer, .{ .undef = ptr_ty });
727727 }
728728
......@@ -805,7 +805,7 @@ pub const DeclGen = struct {
805805 }
806806 },
807807
808 .elem_ptr => |elem| if (!(try elem.parent.ptrType(pt)).childType(zcu).hasRuntimeBits(pt)) {
808 .elem_ptr => |elem| if (!(try elem.parent.ptrType(pt)).childType(zcu).hasRuntimeBits(zcu)) {
809809 // Element type is zero-bit, so lowers to `void`. The index is irrelevant; just cast the pointer.
810810 const ptr_ctype = try dg.ctypeFromType(elem.result_ptr_ty, .complete);
811811 try writer.writeByte('(');
......@@ -923,7 +923,7 @@ pub const DeclGen = struct {
923923 try writer.writeAll("((");
924924 try dg.renderCType(writer, ctype);
925925 try writer.print("){x})", .{try dg.fmtIntLiteral(
926 try pt.intValue(Type.usize, val.toUnsignedInt(pt)),
926 try pt.intValue(Type.usize, val.toUnsignedInt(zcu)),
927927 .Other,
928928 )});
929929 },
......@@ -970,7 +970,7 @@ pub const DeclGen = struct {
970970 .enum_tag => |enum_tag| try dg.renderValue(writer, Value.fromInterned(enum_tag.int), location),
971971 .float => {
972972 const bits = ty.floatBits(target.*);
973 const f128_val = val.toFloat(f128, pt);
973 const f128_val = val.toFloat(f128, zcu);
974974
975975 // All unsigned ints matching float types are pre-allocated.
976976 const repr_ty = pt.intType(.unsigned, bits) catch unreachable;
......@@ -984,10 +984,10 @@ pub const DeclGen = struct {
984984 };
985985
986986 switch (bits) {
987 16 => repr_val_big.set(@as(u16, @bitCast(val.toFloat(f16, pt)))),
988 32 => repr_val_big.set(@as(u32, @bitCast(val.toFloat(f32, pt)))),
989 64 => repr_val_big.set(@as(u64, @bitCast(val.toFloat(f64, pt)))),
990 80 => repr_val_big.set(@as(u80, @bitCast(val.toFloat(f80, pt)))),
987 16 => repr_val_big.set(@as(u16, @bitCast(val.toFloat(f16, zcu)))),
988 32 => repr_val_big.set(@as(u32, @bitCast(val.toFloat(f32, zcu)))),
989 64 => repr_val_big.set(@as(u64, @bitCast(val.toFloat(f64, zcu)))),
990 80 => repr_val_big.set(@as(u80, @bitCast(val.toFloat(f80, zcu)))),
991991 128 => repr_val_big.set(@as(u128, @bitCast(f128_val))),
992992 else => unreachable,
993993 }
......@@ -998,10 +998,10 @@ pub const DeclGen = struct {
998998 try dg.renderTypeForBuiltinFnName(writer, ty);
999999 try writer.writeByte('(');
10001000 switch (bits) {
1001 16 => try writer.print("{x}", .{val.toFloat(f16, pt)}),
1002 32 => try writer.print("{x}", .{val.toFloat(f32, pt)}),
1003 64 => try writer.print("{x}", .{val.toFloat(f64, pt)}),
1004 80 => try writer.print("{x}", .{val.toFloat(f80, pt)}),
1001 16 => try writer.print("{x}", .{val.toFloat(f16, zcu)}),
1002 32 => try writer.print("{x}", .{val.toFloat(f32, zcu)}),
1003 64 => try writer.print("{x}", .{val.toFloat(f64, zcu)}),
1004 80 => try writer.print("{x}", .{val.toFloat(f80, zcu)}),
10051005 128 => try writer.print("{x}", .{f128_val}),
10061006 else => unreachable,
10071007 }
......@@ -1041,10 +1041,10 @@ pub const DeclGen = struct {
10411041 if (std.math.isNan(f128_val)) switch (bits) {
10421042 // We only actually need to pass the significand, but it will get
10431043 // properly masked anyway, so just pass the whole value.
1044 16 => try writer.print("\"0x{x}\"", .{@as(u16, @bitCast(val.toFloat(f16, pt)))}),
1045 32 => try writer.print("\"0x{x}\"", .{@as(u32, @bitCast(val.toFloat(f32, pt)))}),
1046 64 => try writer.print("\"0x{x}\"", .{@as(u64, @bitCast(val.toFloat(f64, pt)))}),
1047 80 => try writer.print("\"0x{x}\"", .{@as(u80, @bitCast(val.toFloat(f80, pt)))}),
1044 16 => try writer.print("\"0x{x}\"", .{@as(u16, @bitCast(val.toFloat(f16, zcu)))}),
1045 32 => try writer.print("\"0x{x}\"", .{@as(u32, @bitCast(val.toFloat(f32, zcu)))}),
1046 64 => try writer.print("\"0x{x}\"", .{@as(u64, @bitCast(val.toFloat(f64, zcu)))}),
1047 80 => try writer.print("\"0x{x}\"", .{@as(u80, @bitCast(val.toFloat(f80, zcu)))}),
10481048 128 => try writer.print("\"0x{x}\"", .{@as(u128, @bitCast(f128_val))}),
10491049 else => unreachable,
10501050 };
......@@ -1167,11 +1167,11 @@ pub const DeclGen = struct {
11671167 const elem_val_u8: u8 = if (elem_val.isUndef(zcu))
11681168 undefPattern(u8)
11691169 else
1170 @intCast(elem_val.toUnsignedInt(pt));
1170 @intCast(elem_val.toUnsignedInt(zcu));
11711171 try literal.writeChar(elem_val_u8);
11721172 }
11731173 if (ai.sentinel) |s| {
1174 const s_u8: u8 = @intCast(s.toUnsignedInt(pt));
1174 const s_u8: u8 = @intCast(s.toUnsignedInt(zcu));
11751175 if (s_u8 != 0) try literal.writeChar(s_u8);
11761176 }
11771177 try literal.end();
......@@ -1203,7 +1203,7 @@ pub const DeclGen = struct {
12031203 const comptime_val = tuple.values.get(ip)[field_index];
12041204 if (comptime_val != .none) continue;
12051205 const field_ty = Type.fromInterned(tuple.types.get(ip)[field_index]);
1206 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1206 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12071207
12081208 if (!empty) try writer.writeByte(',');
12091209
......@@ -1238,7 +1238,7 @@ pub const DeclGen = struct {
12381238 var need_comma = false;
12391239 while (field_it.next()) |field_index| {
12401240 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
1241 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1241 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12421242
12431243 if (need_comma) try writer.writeByte(',');
12441244 need_comma = true;
......@@ -1265,7 +1265,7 @@ pub const DeclGen = struct {
12651265
12661266 for (0..loaded_struct.field_types.len) |field_index| {
12671267 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
1268 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1268 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12691269 eff_num_fields += 1;
12701270 }
12711271
......@@ -1273,7 +1273,7 @@ pub const DeclGen = struct {
12731273 try writer.writeByte('(');
12741274 try dg.renderUndefValue(writer, ty, location);
12751275 try writer.writeByte(')');
1276 } else if (ty.bitSize(pt) > 64) {
1276 } else if (ty.bitSize(zcu) > 64) {
12771277 // zig_or_u128(zig_or_u128(zig_shl_u128(a, a_off), zig_shl_u128(b, b_off)), zig_shl_u128(c, c_off))
12781278 var num_or = eff_num_fields - 1;
12791279 while (num_or > 0) : (num_or -= 1) {
......@@ -1286,7 +1286,7 @@ pub const DeclGen = struct {
12861286 var needs_closing_paren = false;
12871287 for (0..loaded_struct.field_types.len) |field_index| {
12881288 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
1289 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1289 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
12901290
12911291 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
12921292 .bytes => |bytes| try pt.intern(.{ .int = .{
......@@ -1312,7 +1312,7 @@ pub const DeclGen = struct {
13121312 if (needs_closing_paren) try writer.writeByte(')');
13131313 if (eff_index != eff_num_fields - 1) try writer.writeAll(", ");
13141314
1315 bit_offset += field_ty.bitSize(pt);
1315 bit_offset += field_ty.bitSize(zcu);
13161316 needs_closing_paren = true;
13171317 eff_index += 1;
13181318 }
......@@ -1322,7 +1322,7 @@ pub const DeclGen = struct {
13221322 var empty = true;
13231323 for (0..loaded_struct.field_types.len) |field_index| {
13241324 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
1325 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1325 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
13261326
13271327 if (!empty) try writer.writeAll(" | ");
13281328 try writer.writeByte('(');
......@@ -1346,7 +1346,7 @@ pub const DeclGen = struct {
13461346 try dg.renderValue(writer, Value.fromInterned(field_val), .Other);
13471347 }
13481348
1349 bit_offset += field_ty.bitSize(pt);
1349 bit_offset += field_ty.bitSize(zcu);
13501350 empty = false;
13511351 }
13521352 try writer.writeByte(')');
......@@ -1396,7 +1396,7 @@ pub const DeclGen = struct {
13961396 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
13971397 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
13981398 if (loaded_union.flagsUnordered(ip).layout == .@"packed") {
1399 if (field_ty.hasRuntimeBits(pt)) {
1399 if (field_ty.hasRuntimeBits(zcu)) {
14001400 if (field_ty.isPtrAtRuntime(zcu)) {
14011401 try writer.writeByte('(');
14021402 try dg.renderCType(writer, ctype);
......@@ -1427,7 +1427,7 @@ pub const DeclGen = struct {
14271427 ),
14281428 .payload => {
14291429 try writer.writeByte('{');
1430 if (field_ty.hasRuntimeBits(pt)) {
1430 if (field_ty.hasRuntimeBits(zcu)) {
14311431 try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});
14321432 try dg.renderValue(
14331433 writer,
......@@ -1439,7 +1439,7 @@ pub const DeclGen = struct {
14391439 const inner_field_ty = Type.fromInterned(
14401440 loaded_union.field_types.get(ip)[inner_field_index],
14411441 );
1442 if (!inner_field_ty.hasRuntimeBits(pt)) continue;
1442 if (!inner_field_ty.hasRuntimeBits(zcu)) continue;
14431443 try dg.renderUndefValue(writer, inner_field_ty, initializer_type);
14441444 break;
14451445 }
......@@ -1588,7 +1588,7 @@ pub const DeclGen = struct {
15881588 var need_comma = false;
15891589 while (field_it.next()) |field_index| {
15901590 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
1591 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1591 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
15921592
15931593 if (need_comma) try writer.writeByte(',');
15941594 need_comma = true;
......@@ -1613,7 +1613,7 @@ pub const DeclGen = struct {
16131613 for (0..anon_struct_info.types.len) |field_index| {
16141614 if (anon_struct_info.values.get(ip)[field_index] != .none) continue;
16151615 const field_ty = Type.fromInterned(anon_struct_info.types.get(ip)[field_index]);
1616 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1616 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
16171617
16181618 if (need_comma) try writer.writeByte(',');
16191619 need_comma = true;
......@@ -1651,7 +1651,7 @@ pub const DeclGen = struct {
16511651 const inner_field_ty = Type.fromInterned(
16521652 loaded_union.field_types.get(ip)[inner_field_index],
16531653 );
1654 if (!inner_field_ty.hasRuntimeBits(pt)) continue;
1654 if (!inner_field_ty.hasRuntimeBits(pt.zcu)) continue;
16551655 try dg.renderUndefValue(
16561656 writer,
16571657 inner_field_ty,
......@@ -1902,7 +1902,8 @@ pub const DeclGen = struct {
19021902 };
19031903 fn intCastIsNoop(dg: *DeclGen, dest_ty: Type, src_ty: Type) bool {
19041904 const pt = dg.pt;
1905 const dest_bits = dest_ty.bitSize(pt);
1905 const zcu = pt.zcu;
1906 const dest_bits = dest_ty.bitSize(zcu);
19061907 const dest_int_info = dest_ty.intInfo(pt.zcu);
19071908
19081909 const src_is_ptr = src_ty.isPtrAtRuntime(pt.zcu);
......@@ -1911,7 +1912,7 @@ pub const DeclGen = struct {
19111912 .signed => Type.isize,
19121913 } else src_ty;
19131914
1914 const src_bits = src_eff_ty.bitSize(pt);
1915 const src_bits = src_eff_ty.bitSize(zcu);
19151916 const src_int_info = if (src_eff_ty.isAbiInt(pt.zcu)) src_eff_ty.intInfo(pt.zcu) else null;
19161917 if (dest_bits <= 64 and src_bits <= 64) {
19171918 const needs_cast = src_int_info == null or
......@@ -1943,7 +1944,7 @@ pub const DeclGen = struct {
19431944 ) !void {
19441945 const pt = dg.pt;
19451946 const zcu = pt.zcu;
1946 const dest_bits = dest_ty.bitSize(pt);
1947 const dest_bits = dest_ty.bitSize(zcu);
19471948 const dest_int_info = dest_ty.intInfo(zcu);
19481949
19491950 const src_is_ptr = src_ty.isPtrAtRuntime(zcu);
......@@ -1952,7 +1953,7 @@ pub const DeclGen = struct {
19521953 .signed => Type.isize,
19531954 } else src_ty;
19541955
1955 const src_bits = src_eff_ty.bitSize(pt);
1956 const src_bits = src_eff_ty.bitSize(zcu);
19561957 const src_int_info = if (src_eff_ty.isAbiInt(zcu)) src_eff_ty.intInfo(zcu) else null;
19571958 if (dest_bits <= 64 and src_bits <= 64) {
19581959 const needs_cast = src_int_info == null or
......@@ -2033,7 +2034,7 @@ pub const DeclGen = struct {
20332034 qualifiers,
20342035 CType.AlignAs.fromAlignment(.{
20352036 .@"align" = alignment,
2036 .abi = ty.abiAlignment(dg.pt),
2037 .abi = ty.abiAlignment(dg.pt.zcu),
20372038 }),
20382039 );
20392040 }
......@@ -2239,9 +2240,10 @@ pub const DeclGen = struct {
22392240 }
22402241
22412242 const pt = dg.pt;
2242 const int_info = if (ty.isAbiInt(pt.zcu)) ty.intInfo(pt.zcu) else std.builtin.Type.Int{
2243 const zcu = pt.zcu;
2244 const int_info = if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else std.builtin.Type.Int{
22432245 .signedness = .unsigned,
2244 .bits = @as(u16, @intCast(ty.bitSize(pt))),
2246 .bits = @as(u16, @intCast(ty.bitSize(zcu))),
22452247 };
22462248
22472249 if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});
......@@ -2891,7 +2893,7 @@ pub fn genDecl(o: *Object) !void {
28912893 const nav = ip.getNav(o.dg.pass.nav);
28922894 const nav_ty = Type.fromInterned(nav.typeOf(ip));
28932895
2894 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) return;
2896 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return;
28952897 switch (ip.indexToKey(nav.status.resolved.val)) {
28962898 .@"extern" => |@"extern"| {
28972899 if (!ip.isFunctionType(nav_ty.toIntern())) return o.dg.renderFwdDecl(o.dg.pass.nav, .{
......@@ -3420,10 +3422,10 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [
34203422}
34213423
34223424fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3423 const pt = f.object.dg.pt;
3425 const zcu = f.object.dg.pt.zcu;
34243426 const inst_ty = f.typeOfIndex(inst);
34253427 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3426 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3428 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
34273429 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
34283430 return .none;
34293431 }
......@@ -3453,7 +3455,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
34533455
34543456 const inst_ty = f.typeOfIndex(inst);
34553457 const ptr_ty = f.typeOf(bin_op.lhs);
3456 const elem_has_bits = ptr_ty.elemType2(zcu).hasRuntimeBitsIgnoreComptime(pt);
3458 const elem_has_bits = ptr_ty.elemType2(zcu).hasRuntimeBitsIgnoreComptime(zcu);
34573459
34583460 const ptr = try f.resolveInst(bin_op.lhs);
34593461 const index = try f.resolveInst(bin_op.rhs);
......@@ -3482,10 +3484,10 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
34823484}
34833485
34843486fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3485 const pt = f.object.dg.pt;
3487 const zcu = f.object.dg.pt.zcu;
34863488 const inst_ty = f.typeOfIndex(inst);
34873489 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3488 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3490 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
34893491 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
34903492 return .none;
34913493 }
......@@ -3516,7 +3518,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
35163518 const inst_ty = f.typeOfIndex(inst);
35173519 const slice_ty = f.typeOf(bin_op.lhs);
35183520 const elem_ty = slice_ty.elemType2(zcu);
3519 const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(pt);
3521 const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(zcu);
35203522
35213523 const slice = try f.resolveInst(bin_op.lhs);
35223524 const index = try f.resolveInst(bin_op.rhs);
......@@ -3539,10 +3541,10 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
35393541}
35403542
35413543fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3542 const pt = f.object.dg.pt;
3544 const zcu = f.object.dg.pt.zcu;
35433545 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
35443546 const inst_ty = f.typeOfIndex(inst);
3545 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3547 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
35463548 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
35473549 return .none;
35483550 }
......@@ -3569,13 +3571,13 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {
35693571 const zcu = pt.zcu;
35703572 const inst_ty = f.typeOfIndex(inst);
35713573 const elem_ty = inst_ty.childType(zcu);
3572 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) return .{ .undef = inst_ty };
3574 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .{ .undef = inst_ty };
35733575
35743576 const local = try f.allocLocalValue(.{
35753577 .ctype = try f.ctypeFromType(elem_ty, .complete),
35763578 .alignas = CType.AlignAs.fromAlignment(.{
35773579 .@"align" = inst_ty.ptrInfo(zcu).flags.alignment,
3578 .abi = elem_ty.abiAlignment(pt),
3580 .abi = elem_ty.abiAlignment(zcu),
35793581 }),
35803582 });
35813583 log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.new_local });
......@@ -3588,13 +3590,13 @@ fn airRetPtr(f: *Function, inst: Air.Inst.Index) !CValue {
35883590 const zcu = pt.zcu;
35893591 const inst_ty = f.typeOfIndex(inst);
35903592 const elem_ty = inst_ty.childType(zcu);
3591 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) return .{ .undef = inst_ty };
3593 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .{ .undef = inst_ty };
35923594
35933595 const local = try f.allocLocalValue(.{
35943596 .ctype = try f.ctypeFromType(elem_ty, .complete),
35953597 .alignas = CType.AlignAs.fromAlignment(.{
35963598 .@"align" = inst_ty.ptrInfo(zcu).flags.alignment,
3597 .abi = elem_ty.abiAlignment(pt),
3599 .abi = elem_ty.abiAlignment(zcu),
35983600 }),
35993601 });
36003602 log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.new_local });
......@@ -3636,7 +3638,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
36363638 const ptr_info = ptr_scalar_ty.ptrInfo(zcu);
36373639 const src_ty = Type.fromInterned(ptr_info.child);
36383640
3639 if (!src_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3641 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
36403642 try reap(f, inst, &.{ty_op.operand});
36413643 return .none;
36423644 }
......@@ -3646,7 +3648,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
36463648 try reap(f, inst, &.{ty_op.operand});
36473649
36483650 const is_aligned = if (ptr_info.flags.alignment != .none)
3649 ptr_info.flags.alignment.order(src_ty.abiAlignment(pt)).compare(.gte)
3651 ptr_info.flags.alignment.order(src_ty.abiAlignment(zcu)).compare(.gte)
36503652 else
36513653 true;
36523654 const is_array = lowersToArray(src_ty, pt);
......@@ -3674,7 +3676,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
36743676 const bit_offset_ty = try pt.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
36753677 const bit_offset_val = try pt.intValue(bit_offset_ty, ptr_info.packed_offset.bit_offset);
36763678
3677 const field_ty = try pt.intType(.unsigned, @as(u16, @intCast(src_ty.bitSize(pt))));
3679 const field_ty = try pt.intType(.unsigned, @as(u16, @intCast(src_ty.bitSize(zcu))));
36783680
36793681 try f.writeCValue(writer, local, .Other);
36803682 try v.elem(f, writer);
......@@ -3685,9 +3687,9 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
36853687 try writer.writeAll("((");
36863688 try f.renderType(writer, field_ty);
36873689 try writer.writeByte(')');
3688 const cant_cast = host_ty.isInt(zcu) and host_ty.bitSize(pt) > 64;
3690 const cant_cast = host_ty.isInt(zcu) and host_ty.bitSize(zcu) > 64;
36893691 if (cant_cast) {
3690 if (field_ty.bitSize(pt) > 64) return f.fail("TODO: C backend: implement casting between types > 64 bits", .{});
3692 if (field_ty.bitSize(zcu) > 64) return f.fail("TODO: C backend: implement casting between types > 64 bits", .{});
36913693 try writer.writeAll("zig_lo_");
36923694 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);
36933695 try writer.writeByte('(');
......@@ -3735,7 +3737,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
37353737 const ret_val = if (is_array) ret_val: {
37363738 const array_local = try f.allocAlignedLocal(inst, .{
37373739 .ctype = ret_ctype,
3738 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(pt)),
3740 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(zcu)),
37393741 });
37403742 try writer.writeAll("memcpy(");
37413743 try f.writeCValueMember(writer, array_local, .{ .identifier = "array" });
......@@ -3926,7 +3928,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
39263928 }
39273929
39283930 const is_aligned = if (ptr_info.flags.alignment != .none)
3929 ptr_info.flags.alignment.order(src_ty.abiAlignment(pt)).compare(.gte)
3931 ptr_info.flags.alignment.order(src_ty.abiAlignment(zcu)).compare(.gte)
39303932 else
39313933 true;
39323934 const is_array = lowersToArray(Type.fromInterned(ptr_info.child), pt);
......@@ -3976,7 +3978,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
39763978 const bit_offset_ty = try pt.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
39773979 const bit_offset_val = try pt.intValue(bit_offset_ty, ptr_info.packed_offset.bit_offset);
39783980
3979 const src_bits = src_ty.bitSize(pt);
3981 const src_bits = src_ty.bitSize(zcu);
39803982
39813983 const ExpectedContents = [BigInt.Managed.default_capacity]BigIntLimb;
39823984 var stack align(@alignOf(ExpectedContents)) =
......@@ -4006,9 +4008,9 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
40064008 try writer.print(", {x}), zig_shl_", .{try f.fmtIntLiteral(mask_val)});
40074009 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);
40084010 try writer.writeByte('(');
4009 const cant_cast = host_ty.isInt(zcu) and host_ty.bitSize(pt) > 64;
4011 const cant_cast = host_ty.isInt(zcu) and host_ty.bitSize(zcu) > 64;
40104012 if (cant_cast) {
4011 if (src_ty.bitSize(pt) > 64) return f.fail("TODO: C backend: implement casting between types > 64 bits", .{});
4013 if (src_ty.bitSize(zcu) > 64) return f.fail("TODO: C backend: implement casting between types > 64 bits", .{});
40124014 try writer.writeAll("zig_make_");
40134015 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);
40144016 try writer.writeAll("(0, ");
......@@ -4130,7 +4132,7 @@ fn airBinOp(
41304132 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
41314133 const operand_ty = f.typeOf(bin_op.lhs);
41324134 const scalar_ty = operand_ty.scalarType(zcu);
4133 if ((scalar_ty.isInt(zcu) and scalar_ty.bitSize(pt) > 64) or scalar_ty.isRuntimeFloat())
4135 if ((scalar_ty.isInt(zcu) and scalar_ty.bitSize(zcu) > 64) or scalar_ty.isRuntimeFloat())
41344136 return try airBinBuiltinCall(f, inst, operation, info);
41354137
41364138 const lhs = try f.resolveInst(bin_op.lhs);
......@@ -4169,7 +4171,7 @@ fn airCmpOp(
41694171 const lhs_ty = f.typeOf(data.lhs);
41704172 const scalar_ty = lhs_ty.scalarType(zcu);
41714173
4172 const scalar_bits = scalar_ty.bitSize(pt);
4174 const scalar_bits = scalar_ty.bitSize(zcu);
41734175 if (scalar_ty.isInt(zcu) and scalar_bits > 64)
41744176 return airCmpBuiltinCall(
41754177 f,
......@@ -4219,7 +4221,7 @@ fn airEquality(
42194221 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
42204222
42214223 const operand_ty = f.typeOf(bin_op.lhs);
4222 const operand_bits = operand_ty.bitSize(pt);
4224 const operand_bits = operand_ty.bitSize(zcu);
42234225 if (operand_ty.isAbiInt(zcu) and operand_bits > 64)
42244226 return airCmpBuiltinCall(
42254227 f,
......@@ -4312,7 +4314,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
43124314 const inst_ty = f.typeOfIndex(inst);
43134315 const inst_scalar_ty = inst_ty.scalarType(zcu);
43144316 const elem_ty = inst_scalar_ty.elemType2(zcu);
4315 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return f.moveCValue(inst, inst_ty, lhs);
4317 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return f.moveCValue(inst, inst_ty, lhs);
43164318 const inst_scalar_ctype = try f.ctypeFromType(inst_scalar_ty, .complete);
43174319
43184320 const local = try f.allocLocal(inst, inst_ty);
......@@ -4351,7 +4353,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons
43514353 const inst_ty = f.typeOfIndex(inst);
43524354 const inst_scalar_ty = inst_ty.scalarType(zcu);
43534355
4354 if ((inst_scalar_ty.isInt(zcu) and inst_scalar_ty.bitSize(pt) > 64) or inst_scalar_ty.isRuntimeFloat())
4356 if ((inst_scalar_ty.isInt(zcu) and inst_scalar_ty.bitSize(zcu) > 64) or inst_scalar_ty.isRuntimeFloat())
43554357 return try airBinBuiltinCall(f, inst, operation, .none);
43564358
43574359 const lhs = try f.resolveInst(bin_op.lhs);
......@@ -4446,7 +4448,7 @@ fn airCall(
44464448 if (!arg_ctype.eql(try f.ctypeFromType(arg_ty, .complete))) {
44474449 const array_local = try f.allocAlignedLocal(inst, .{
44484450 .ctype = arg_ctype,
4449 .alignas = CType.AlignAs.fromAbiAlignment(arg_ty.abiAlignment(pt)),
4451 .alignas = CType.AlignAs.fromAbiAlignment(arg_ty.abiAlignment(zcu)),
44504452 });
44514453 try writer.writeAll("memcpy(");
44524454 try f.writeCValueMember(writer, array_local, .{ .identifier = "array" });
......@@ -4493,7 +4495,7 @@ fn airCall(
44934495 } else {
44944496 const local = try f.allocAlignedLocal(inst, .{
44954497 .ctype = ret_ctype,
4496 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(pt)),
4498 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(zcu)),
44974499 });
44984500 try f.writeCValue(writer, local, .Other);
44994501 try writer.writeAll(" = ");
......@@ -4618,7 +4620,7 @@ fn lowerBlock(f: *Function, inst: Air.Inst.Index, body: []const Air.Inst.Index)
46184620 const writer = f.object.writer();
46194621
46204622 const inst_ty = f.typeOfIndex(inst);
4621 const result = if (inst_ty.hasRuntimeBitsIgnoreComptime(pt) and !f.liveness.isUnused(inst))
4623 const result = if (inst_ty.hasRuntimeBitsIgnoreComptime(zcu) and !f.liveness.isUnused(inst))
46224624 try f.allocLocal(inst, inst_ty)
46234625 else
46244626 .none;
......@@ -4681,7 +4683,7 @@ fn lowerTry(
46814683 const liveness_condbr = f.liveness.getCondBr(inst);
46824684 const writer = f.object.writer();
46834685 const payload_ty = err_union_ty.errorUnionPayload(zcu);
4684 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(pt);
4686 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
46854687
46864688 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
46874689 try writer.writeAll("if (");
......@@ -4820,7 +4822,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !CVal
48204822 try writer.writeAll(", sizeof(");
48214823 try f.renderType(
48224824 writer,
4823 if (dest_ty.abiSize(pt) <= operand_ty.abiSize(pt)) dest_ty else operand_ty,
4825 if (dest_ty.abiSize(zcu) <= operand_ty.abiSize(zcu)) dest_ty else operand_ty,
48244826 );
48254827 try writer.writeAll("));\n");
48264828
......@@ -5030,7 +5032,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
50305032 try f.object.indent_writer.insertNewline();
50315033 try writer.writeAll("case ");
50325034 const item_value = try f.air.value(item, pt);
5033 if (item_value.?.getUnsignedInt(pt)) |item_int| try writer.print("{}\n", .{
5035 if (item_value.?.getUnsignedInt(zcu)) |item_int| try writer.print("{}\n", .{
50345036 try f.fmtIntLiteral(try pt.intValue(lowered_condition_ty, item_int)),
50355037 }) else {
50365038 if (condition_ty.isPtrAtRuntime(zcu)) {
......@@ -5112,10 +5114,10 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
51125114 const result = result: {
51135115 const writer = f.object.writer();
51145116 const inst_ty = f.typeOfIndex(inst);
5115 const inst_local = if (inst_ty.hasRuntimeBitsIgnoreComptime(pt)) local: {
5117 const inst_local = if (inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) local: {
51165118 const inst_local = try f.allocLocalValue(.{
51175119 .ctype = try f.ctypeFromType(inst_ty, .complete),
5118 .alignas = CType.AlignAs.fromAbiAlignment(inst_ty.abiAlignment(pt)),
5120 .alignas = CType.AlignAs.fromAbiAlignment(inst_ty.abiAlignment(zcu)),
51195121 });
51205122 if (f.wantSafety()) {
51215123 try f.writeCValue(writer, inst_local, .Other);
......@@ -5148,7 +5150,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
51485150 try writer.writeAll("register ");
51495151 const output_local = try f.allocLocalValue(.{
51505152 .ctype = try f.ctypeFromType(output_ty, .complete),
5151 .alignas = CType.AlignAs.fromAbiAlignment(output_ty.abiAlignment(pt)),
5153 .alignas = CType.AlignAs.fromAbiAlignment(output_ty.abiAlignment(zcu)),
51525154 });
51535155 try f.allocs.put(gpa, output_local.new_local, false);
51545156 try f.object.dg.renderTypeAndName(writer, output_ty, output_local, .{}, .none, .complete);
......@@ -5183,7 +5185,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
51835185 if (is_reg) try writer.writeAll("register ");
51845186 const input_local = try f.allocLocalValue(.{
51855187 .ctype = try f.ctypeFromType(input_ty, .complete),
5186 .alignas = CType.AlignAs.fromAbiAlignment(input_ty.abiAlignment(pt)),
5188 .alignas = CType.AlignAs.fromAbiAlignment(input_ty.abiAlignment(zcu)),
51875189 });
51885190 try f.allocs.put(gpa, input_local.new_local, false);
51895191 try f.object.dg.renderTypeAndName(writer, input_ty, input_local, Const, .none, .complete);
......@@ -5526,9 +5528,9 @@ fn fieldLocation(
55265528 .struct_type => {
55275529 const loaded_struct = ip.loadStructType(container_ty.toIntern());
55285530 return switch (loaded_struct.layout) {
5529 .auto, .@"extern" => if (!container_ty.hasRuntimeBitsIgnoreComptime(pt))
5531 .auto, .@"extern" => if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu))
55305532 .begin
5531 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(pt))
5533 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))
55325534 .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] }
55335535 else
55345536 .{ .field = if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|
......@@ -5542,10 +5544,10 @@ fn fieldLocation(
55425544 .begin,
55435545 };
55445546 },
5545 .anon_struct_type => |anon_struct_info| return if (!container_ty.hasRuntimeBitsIgnoreComptime(pt))
5547 .anon_struct_type => |anon_struct_info| return if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu))
55465548 .begin
5547 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(pt))
5548 .{ .byte_offset = container_ty.structFieldOffset(field_index, pt) }
5549 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))
5550 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }
55495551 else
55505552 .{ .field = if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|
55515553 .{ .identifier = field_name.toSlice(ip) }
......@@ -5556,8 +5558,8 @@ fn fieldLocation(
55565558 switch (loaded_union.flagsUnordered(ip).layout) {
55575559 .auto, .@"extern" => {
55585560 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
5559 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt))
5560 return if (loaded_union.hasTag(ip) and !container_ty.unionHasAllZeroBitFieldTypes(pt))
5561 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu))
5562 return if (loaded_union.hasTag(ip) and !container_ty.unionHasAllZeroBitFieldTypes(zcu))
55615563 .{ .field = .{ .identifier = "payload" } }
55625564 else
55635565 .begin;
......@@ -5706,7 +5708,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
57065708 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
57075709
57085710 const inst_ty = f.typeOfIndex(inst);
5709 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5711 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
57105712 try reap(f, inst, &.{extra.struct_operand});
57115713 return .none;
57125714 }
......@@ -5738,7 +5740,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
57385740 inst_ty.intInfo(zcu).signedness
57395741 else
57405742 .unsigned;
5741 const field_int_ty = try pt.intType(field_int_signedness, @as(u16, @intCast(inst_ty.bitSize(pt))));
5743 const field_int_ty = try pt.intType(field_int_signedness, @as(u16, @intCast(inst_ty.bitSize(zcu))));
57425744
57435745 const temp_local = try f.allocLocal(inst, field_int_ty);
57445746 try f.writeCValue(writer, temp_local, .Other);
......@@ -5749,7 +5751,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
57495751 try writer.writeByte(')');
57505752 const cant_cast = int_info.bits > 64;
57515753 if (cant_cast) {
5752 if (field_int_ty.bitSize(pt) > 64) return f.fail("TODO: C backend: implement casting between types > 64 bits", .{});
5754 if (field_int_ty.bitSize(zcu) > 64) return f.fail("TODO: C backend: implement casting between types > 64 bits", .{});
57535755 try writer.writeAll("zig_lo_");
57545756 try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty);
57555757 try writer.writeByte('(');
......@@ -5857,7 +5859,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
58575859 const payload_ty = error_union_ty.errorUnionPayload(zcu);
58585860 const local = try f.allocLocal(inst, inst_ty);
58595861
5860 if (!payload_ty.hasRuntimeBits(pt) and operand == .local and operand.local == local.new_local) {
5862 if (!payload_ty.hasRuntimeBits(zcu) and operand == .local and operand.local == local.new_local) {
58615863 // The store will be 'x = x'; elide it.
58625864 return local;
58635865 }
......@@ -5866,7 +5868,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
58665868 try f.writeCValue(writer, local, .Other);
58675869 try writer.writeAll(" = ");
58685870
5869 if (!payload_ty.hasRuntimeBits(pt))
5871 if (!payload_ty.hasRuntimeBits(zcu))
58705872 try f.writeCValue(writer, operand, .Other)
58715873 else if (error_ty.errorSetIsEmpty(zcu))
58725874 try writer.print("{}", .{
......@@ -5892,7 +5894,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
58925894 const error_union_ty = if (is_ptr) operand_ty.childType(zcu) else operand_ty;
58935895
58945896 const writer = f.object.writer();
5895 if (!error_union_ty.errorUnionPayload(zcu).hasRuntimeBits(pt)) {
5897 if (!error_union_ty.errorUnionPayload(zcu).hasRuntimeBits(zcu)) {
58965898 if (!is_ptr) return .none;
58975899
58985900 const local = try f.allocLocal(inst, inst_ty);
......@@ -5963,7 +5965,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
59635965
59645966 const inst_ty = f.typeOfIndex(inst);
59655967 const payload_ty = inst_ty.errorUnionPayload(zcu);
5966 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(pt);
5968 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
59675969 const err_ty = inst_ty.errorUnionSet(zcu);
59685970 const err = try f.resolveInst(ty_op.operand);
59695971 try reap(f, inst, &.{ty_op.operand});
......@@ -6012,7 +6014,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
60126014 try reap(f, inst, &.{ty_op.operand});
60136015
60146016 // First, set the non-error value.
6015 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
6017 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
60166018 const a = try Assignment.start(f, writer, try f.ctypeFromType(operand_ty, .complete));
60176019 try f.writeCValueDeref(writer, operand);
60186020 try a.assign(f, writer);
......@@ -6064,7 +6066,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
60646066 const inst_ty = f.typeOfIndex(inst);
60656067 const payload_ty = inst_ty.errorUnionPayload(zcu);
60666068 const payload = try f.resolveInst(ty_op.operand);
6067 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(pt);
6069 const repr_is_err = !payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
60686070 const err_ty = inst_ty.errorUnionSet(zcu);
60696071 try reap(f, inst, &.{ty_op.operand});
60706072
......@@ -6109,7 +6111,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
61096111 try a.assign(f, writer);
61106112 const err_int_ty = try pt.errorIntType();
61116113 if (!error_ty.errorSetIsEmpty(zcu))
6112 if (payload_ty.hasRuntimeBits(pt))
6114 if (payload_ty.hasRuntimeBits(zcu))
61136115 if (is_ptr)
61146116 try f.writeCValueDerefMember(writer, operand, .{ .identifier = "error" })
61156117 else
......@@ -6430,7 +6432,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
64306432 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });
64316433
64326434 const repr_ty = if (ty.isRuntimeFloat())
6433 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(pt) * 8))) catch unreachable
6435 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(zcu) * 8))) catch unreachable
64346436 else
64356437 ty;
64366438
......@@ -6534,7 +6536,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
65346536 const operand_mat = try Materialize.start(f, inst, ty, operand);
65356537 try reap(f, inst, &.{ pl_op.operand, extra.operand });
65366538
6537 const repr_bits = @as(u16, @intCast(ty.abiSize(pt) * 8));
6539 const repr_bits = @as(u16, @intCast(ty.abiSize(zcu) * 8));
65386540 const is_float = ty.isRuntimeFloat();
65396541 const is_128 = repr_bits == 128;
65406542 const repr_ty = if (is_float) pt.intType(.unsigned, repr_bits) catch unreachable else ty;
......@@ -6585,7 +6587,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
65856587 const ty = ptr_ty.childType(zcu);
65866588
65876589 const repr_ty = if (ty.isRuntimeFloat())
6588 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(pt) * 8))) catch unreachable
6590 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(zcu) * 8))) catch unreachable
65896591 else
65906592 ty;
65916593
......@@ -6626,7 +6628,7 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
66266628 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
66276629
66286630 const repr_ty = if (ty.isRuntimeFloat())
6629 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(pt) * 8))) catch unreachable
6631 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(zcu) * 8))) catch unreachable
66306632 else
66316633 ty;
66326634
......@@ -6666,7 +6668,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
66666668 const dest_slice = try f.resolveInst(bin_op.lhs);
66676669 const value = try f.resolveInst(bin_op.rhs);
66686670 const elem_ty = f.typeOf(bin_op.rhs);
6669 const elem_abi_size = elem_ty.abiSize(pt);
6671 const elem_abi_size = elem_ty.abiSize(zcu);
66706672 const val_is_undef = if (try f.air.value(bin_op.rhs, pt)) |val| val.isUndefDeep(zcu) else false;
66716673 const writer = f.object.writer();
66726674
......@@ -6831,7 +6833,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
68316833 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
68326834
68336835 const union_ty = f.typeOf(bin_op.lhs).childType(zcu);
6834 const layout = union_ty.unionGetLayout(pt);
6836 const layout = union_ty.unionGetLayout(zcu);
68356837 if (layout.tag_size == 0) return .none;
68366838 const tag_ty = union_ty.unionTagTypeSafety(zcu).?;
68376839
......@@ -6846,13 +6848,14 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
68466848
68476849fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
68486850 const pt = f.object.dg.pt;
6851 const zcu = pt.zcu;
68496852 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68506853
68516854 const operand = try f.resolveInst(ty_op.operand);
68526855 try reap(f, inst, &.{ty_op.operand});
68536856
68546857 const union_ty = f.typeOf(ty_op.operand);
6855 const layout = union_ty.unionGetLayout(pt);
6858 const layout = union_ty.unionGetLayout(zcu);
68566859 if (layout.tag_size == 0) return .none;
68576860
68586861 const inst_ty = f.typeOfIndex(inst);
......@@ -6960,6 +6963,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {
69606963
69616964fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
69626965 const pt = f.object.dg.pt;
6966 const zcu = pt.zcu;
69636967 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
69646968 const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data;
69656969
......@@ -6978,7 +6982,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
69786982 try f.object.dg.renderValue(writer, try pt.intValue(Type.usize, index), .Other);
69796983 try writer.writeAll("] = ");
69806984
6981 const mask_elem = (try mask.elemValue(pt, index)).toSignedInt(pt);
6985 const mask_elem = (try mask.elemValue(pt, index)).toSignedInt(zcu);
69826986 const src_val = try pt.intValue(Type.usize, @as(u64, @intCast(mask_elem ^ mask_elem >> 63)));
69836987
69846988 try f.writeCValue(writer, if (mask_elem >= 0) lhs else rhs, .Other);
......@@ -7001,7 +7005,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
70017005 const operand_ty = f.typeOf(reduce.operand);
70027006 const writer = f.object.writer();
70037007
7004 const use_operator = scalar_ty.bitSize(pt) <= 64;
7008 const use_operator = scalar_ty.bitSize(zcu) <= 64;
70057009 const op: union(enum) {
70067010 const Func = struct { operation: []const u8, info: BuiltinInfo = .none };
70077011 builtin: Func,
......@@ -7178,7 +7182,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
71787182 var field_it = loaded_struct.iterateRuntimeOrder(ip);
71797183 while (field_it.next()) |field_index| {
71807184 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
7181 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
7185 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
71827186
71837187 const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));
71847188 try f.writeCValueMember(writer, local, if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|
......@@ -7203,7 +7207,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
72037207 for (0..elements.len) |field_index| {
72047208 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;
72057209 const field_ty = inst_ty.structFieldType(field_index, zcu);
7206 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
7210 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
72077211
72087212 if (!empty) {
72097213 try writer.writeAll("zig_or_");
......@@ -7216,7 +7220,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
72167220 for (resolved_elements, 0..) |element, field_index| {
72177221 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;
72187222 const field_ty = inst_ty.structFieldType(field_index, zcu);
7219 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
7223 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
72207224
72217225 if (!empty) try writer.writeAll(", ");
72227226 // TODO: Skip this entire shift if val is 0?
......@@ -7248,7 +7252,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
72487252 try writer.writeByte(')');
72497253 if (!empty) try writer.writeByte(')');
72507254
7251 bit_offset += field_ty.bitSize(pt);
7255 bit_offset += field_ty.bitSize(zcu);
72527256 empty = false;
72537257 }
72547258 try writer.writeAll(";\n");
......@@ -7258,7 +7262,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
72587262 .anon_struct_type => |anon_struct_info| for (0..anon_struct_info.types.len) |field_index| {
72597263 if (anon_struct_info.values.get(ip)[field_index] != .none) continue;
72607264 const field_ty = Type.fromInterned(anon_struct_info.types.get(ip)[field_index]);
7261 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
7265 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
72627266
72637267 const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));
72647268 try f.writeCValueMember(writer, local, if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|
......@@ -7294,7 +7298,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
72947298 if (loaded_union.flagsUnordered(ip).layout == .@"packed") return f.moveCValue(inst, union_ty, payload);
72957299
72967300 const field: CValue = if (union_ty.unionTagTypeSafety(zcu)) |tag_ty| field: {
7297 const layout = union_ty.unionGetLayout(pt);
7301 const layout = union_ty.unionGetLayout(zcu);
72987302 if (layout.tag_size != 0) {
72997303 const field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
73007304 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
......@@ -7818,7 +7822,7 @@ fn formatIntLiteral(
78187822 };
78197823 undef_int.truncate(undef_int.toConst(), data.int_info.signedness, data.int_info.bits);
78207824 break :blk undef_int.toConst();
7821 } else data.val.toBigInt(&int_buf, pt);
7825 } else data.val.toBigInt(&int_buf, zcu);
78227826 assert(int.fitsInTwosComp(data.int_info.signedness, data.int_info.bits));
78237827
78247828 const c_bits: usize = @intCast(data.ctype.byteSize(ctype_pool, data.dg.mod) * 8);
......@@ -8062,9 +8066,10 @@ const Vectorize = struct {
80628066};
80638067
80648068fn lowersToArray(ty: Type, pt: Zcu.PerThread) bool {
8065 return switch (ty.zigTypeTag(pt.zcu)) {
8069 const zcu = pt.zcu;
8070 return switch (ty.zigTypeTag(zcu)) {
80668071 .Array, .Vector => return true,
8067 else => return ty.isAbiInt(pt.zcu) and toCIntBits(@as(u32, @intCast(ty.bitSize(pt)))) == null,
8072 else => return ty.isAbiInt(zcu) and toCIntBits(@as(u32, @intCast(ty.bitSize(zcu)))) == null,
80688073 };
80698074}
80708075
src/codegen/c/Type.zig+13-12
......@@ -1344,6 +1344,7 @@ pub const Pool = struct {
13441344 kind: Kind,
13451345 ) !CType {
13461346 const ip = &pt.zcu.intern_pool;
1347 const zcu = pt.zcu;
13471348 switch (ty.toIntern()) {
13481349 .u0_type,
13491350 .i0_type,
......@@ -1476,7 +1477,7 @@ pub const Pool = struct {
14761477 ),
14771478 .alignas = AlignAs.fromAlignment(.{
14781479 .@"align" = ptr_info.flags.alignment,
1479 .abi = Type.fromInterned(ptr_info.child).abiAlignment(pt),
1480 .abi = Type.fromInterned(ptr_info.child).abiAlignment(zcu),
14801481 }),
14811482 };
14821483 break :elem_ctype if (elem.alignas.abiOrder().compare(.gte))
......@@ -1552,7 +1553,7 @@ pub const Pool = struct {
15521553 .{
15531554 .name = .{ .index = .array },
15541555 .ctype = array_ctype,
1555 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(pt)),
1556 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(zcu)),
15561557 },
15571558 };
15581559 return pool.fromFields(allocator, .@"struct", &fields, kind);
......@@ -1578,7 +1579,7 @@ pub const Pool = struct {
15781579 .{
15791580 .name = .{ .index = .array },
15801581 .ctype = vector_ctype,
1581 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(pt)),
1582 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(zcu)),
15821583 },
15831584 };
15841585 return pool.fromFields(allocator, .@"struct", &fields, kind);
......@@ -1613,7 +1614,7 @@ pub const Pool = struct {
16131614 .name = .{ .index = .payload },
16141615 .ctype = payload_ctype,
16151616 .alignas = AlignAs.fromAbiAlignment(
1616 Type.fromInterned(payload_type).abiAlignment(pt),
1617 Type.fromInterned(payload_type).abiAlignment(zcu),
16171618 ),
16181619 },
16191620 };
......@@ -1649,7 +1650,7 @@ pub const Pool = struct {
16491650 .{
16501651 .name = .{ .index = .payload },
16511652 .ctype = payload_ctype,
1652 .alignas = AlignAs.fromAbiAlignment(payload_type.abiAlignment(pt)),
1653 .alignas = AlignAs.fromAbiAlignment(payload_type.abiAlignment(zcu)),
16531654 },
16541655 };
16551656 return pool.fromFields(allocator, .@"struct", &fields, kind);
......@@ -1663,7 +1664,7 @@ pub const Pool = struct {
16631664 .tag = .@"struct",
16641665 .name = .{ .index = ip_index },
16651666 });
1666 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(pt))
1667 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
16671668 fwd_decl
16681669 else
16691670 CType.void;
......@@ -1696,7 +1697,7 @@ pub const Pool = struct {
16961697 String.fromUnnamed(@intCast(field_index));
16971698 const field_alignas = AlignAs.fromAlignment(.{
16981699 .@"align" = loaded_struct.fieldAlign(ip, field_index),
1699 .abi = field_type.abiAlignment(pt),
1700 .abi = field_type.abiAlignment(zcu),
17001701 });
17011702 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
17021703 .name = field_name.index,
......@@ -1758,7 +1759,7 @@ pub const Pool = struct {
17581759 .name = field_name.index,
17591760 .ctype = field_ctype.index,
17601761 .flags = .{ .alignas = AlignAs.fromAbiAlignment(
1761 field_type.abiAlignment(pt),
1762 field_type.abiAlignment(zcu),
17621763 ) },
17631764 });
17641765 }
......@@ -1802,7 +1803,7 @@ pub const Pool = struct {
18021803 .tag = if (has_tag) .@"struct" else .@"union",
18031804 .name = .{ .index = ip_index },
18041805 });
1805 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(pt))
1806 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
18061807 fwd_decl
18071808 else
18081809 CType.void;
......@@ -1836,7 +1837,7 @@ pub const Pool = struct {
18361837 );
18371838 const field_alignas = AlignAs.fromAlignment(.{
18381839 .@"align" = loaded_union.fieldAlign(ip, field_index),
1839 .abi = field_type.abiAlignment(pt),
1840 .abi = field_type.abiAlignment(zcu),
18401841 });
18411842 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
18421843 .name = field_name.index,
......@@ -1881,7 +1882,7 @@ pub const Pool = struct {
18811882 struct_fields[struct_fields_len] = .{
18821883 .name = .{ .index = .tag },
18831884 .ctype = tag_ctype,
1884 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(pt)),
1885 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(zcu)),
18851886 };
18861887 struct_fields_len += 1;
18871888 }
......@@ -1929,7 +1930,7 @@ pub const Pool = struct {
19291930 },
19301931 .@"packed" => return pool.fromIntInfo(allocator, .{
19311932 .signedness = .unsigned,
1932 .bits = @intCast(ty.bitSize(pt)),
1933 .bits = @intCast(ty.bitSize(zcu)),
19331934 }, mod, kind),
19341935 }
19351936 },
src/codegen/llvm.zig+840-831
......@@ -1001,12 +1001,12 @@ pub const Object = struct {
10011001 if (o.error_name_table == .none) return;
10021002
10031003 const pt = o.pt;
1004 const mod = pt.zcu;
1005 const ip = &mod.intern_pool;
1004 const zcu = pt.zcu;
1005 const ip = &zcu.intern_pool;
10061006
10071007 const error_name_list = ip.global_error_set.getNamesFromMainThread();
1008 const llvm_errors = try mod.gpa.alloc(Builder.Constant, 1 + error_name_list.len);
1009 defer mod.gpa.free(llvm_errors);
1008 const llvm_errors = try zcu.gpa.alloc(Builder.Constant, 1 + error_name_list.len);
1009 defer zcu.gpa.free(llvm_errors);
10101010
10111011 // TODO: Address space
10121012 const slice_ty = Type.slice_const_u8_sentinel_0;
......@@ -1041,7 +1041,7 @@ pub const Object = struct {
10411041 table_variable_index.setMutability(.constant, &o.builder);
10421042 table_variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
10431043 table_variable_index.setAlignment(
1044 slice_ty.abiAlignment(pt).toLlvm(),
1044 slice_ty.abiAlignment(zcu).toLlvm(),
10451045 &o.builder,
10461046 );
10471047
......@@ -1428,7 +1428,7 @@ pub const Object = struct {
14281428 var llvm_arg_i: u32 = 0;
14291429
14301430 // This gets the LLVM values from the function and stores them in `ng.args`.
1431 const sret = firstParamSRet(fn_info, pt, target);
1431 const sret = firstParamSRet(fn_info, zcu, target);
14321432 const ret_ptr: Builder.Value = if (sret) param: {
14331433 const param = wip.arg(llvm_arg_i);
14341434 llvm_arg_i += 1;
......@@ -1469,8 +1469,8 @@ pub const Object = struct {
14691469 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
14701470 const param = wip.arg(llvm_arg_i);
14711471
1472 if (isByRef(param_ty, pt)) {
1473 const alignment = param_ty.abiAlignment(pt).toLlvm();
1472 if (isByRef(param_ty, zcu)) {
1473 const alignment = param_ty.abiAlignment(zcu).toLlvm();
14741474 const param_llvm_ty = param.typeOfWip(&wip);
14751475 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
14761476 _ = try wip.store(.normal, param, arg_ptr, alignment);
......@@ -1486,12 +1486,12 @@ pub const Object = struct {
14861486 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
14871487 const param_llvm_ty = try o.lowerType(param_ty);
14881488 const param = wip.arg(llvm_arg_i);
1489 const alignment = param_ty.abiAlignment(pt).toLlvm();
1489 const alignment = param_ty.abiAlignment(zcu).toLlvm();
14901490
14911491 try o.addByRefParamAttrs(&attributes, llvm_arg_i, alignment, it.byval_attr, param_llvm_ty);
14921492 llvm_arg_i += 1;
14931493
1494 if (isByRef(param_ty, pt)) {
1494 if (isByRef(param_ty, zcu)) {
14951495 args.appendAssumeCapacity(param);
14961496 } else {
14971497 args.appendAssumeCapacity(try wip.load(.normal, param_llvm_ty, param, alignment, ""));
......@@ -1501,12 +1501,12 @@ pub const Object = struct {
15011501 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
15021502 const param_llvm_ty = try o.lowerType(param_ty);
15031503 const param = wip.arg(llvm_arg_i);
1504 const alignment = param_ty.abiAlignment(pt).toLlvm();
1504 const alignment = param_ty.abiAlignment(zcu).toLlvm();
15051505
15061506 try attributes.addParamAttr(llvm_arg_i, .noundef, &o.builder);
15071507 llvm_arg_i += 1;
15081508
1509 if (isByRef(param_ty, pt)) {
1509 if (isByRef(param_ty, zcu)) {
15101510 args.appendAssumeCapacity(param);
15111511 } else {
15121512 args.appendAssumeCapacity(try wip.load(.normal, param_llvm_ty, param, alignment, ""));
......@@ -1519,11 +1519,11 @@ pub const Object = struct {
15191519 llvm_arg_i += 1;
15201520
15211521 const param_llvm_ty = try o.lowerType(param_ty);
1522 const alignment = param_ty.abiAlignment(pt).toLlvm();
1522 const alignment = param_ty.abiAlignment(zcu).toLlvm();
15231523 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
15241524 _ = try wip.store(.normal, param, arg_ptr, alignment);
15251525
1526 args.appendAssumeCapacity(if (isByRef(param_ty, pt))
1526 args.appendAssumeCapacity(if (isByRef(param_ty, zcu))
15271527 arg_ptr
15281528 else
15291529 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
......@@ -1547,7 +1547,7 @@ pub const Object = struct {
15471547 const elem_align = (if (ptr_info.flags.alignment != .none)
15481548 @as(InternPool.Alignment, ptr_info.flags.alignment)
15491549 else
1550 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1")).toLlvm();
1550 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1")).toLlvm();
15511551 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
15521552 const ptr_param = wip.arg(llvm_arg_i);
15531553 llvm_arg_i += 1;
......@@ -1564,7 +1564,7 @@ pub const Object = struct {
15641564 const field_types = it.types_buffer[0..it.types_len];
15651565 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
15661566 const param_llvm_ty = try o.lowerType(param_ty);
1567 const param_alignment = param_ty.abiAlignment(pt).toLlvm();
1567 const param_alignment = param_ty.abiAlignment(zcu).toLlvm();
15681568 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, param_alignment, target);
15691569 const llvm_ty = try o.builder.structType(.normal, field_types);
15701570 for (0..field_types.len) |field_i| {
......@@ -1576,7 +1576,7 @@ pub const Object = struct {
15761576 _ = try wip.store(.normal, param, field_ptr, alignment);
15771577 }
15781578
1579 const is_by_ref = isByRef(param_ty, pt);
1579 const is_by_ref = isByRef(param_ty, zcu);
15801580 args.appendAssumeCapacity(if (is_by_ref)
15811581 arg_ptr
15821582 else
......@@ -1594,11 +1594,11 @@ pub const Object = struct {
15941594 const param = wip.arg(llvm_arg_i);
15951595 llvm_arg_i += 1;
15961596
1597 const alignment = param_ty.abiAlignment(pt).toLlvm();
1597 const alignment = param_ty.abiAlignment(zcu).toLlvm();
15981598 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
15991599 _ = try wip.store(.normal, param, arg_ptr, alignment);
16001600
1601 args.appendAssumeCapacity(if (isByRef(param_ty, pt))
1601 args.appendAssumeCapacity(if (isByRef(param_ty, zcu))
16021602 arg_ptr
16031603 else
16041604 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
......@@ -1609,11 +1609,11 @@ pub const Object = struct {
16091609 const param = wip.arg(llvm_arg_i);
16101610 llvm_arg_i += 1;
16111611
1612 const alignment = param_ty.abiAlignment(pt).toLlvm();
1612 const alignment = param_ty.abiAlignment(zcu).toLlvm();
16131613 const arg_ptr = try buildAllocaInner(&wip, param.typeOfWip(&wip), alignment, target);
16141614 _ = try wip.store(.normal, param, arg_ptr, alignment);
16151615
1616 args.appendAssumeCapacity(if (isByRef(param_ty, pt))
1616 args.appendAssumeCapacity(if (isByRef(param_ty, zcu))
16171617 arg_ptr
16181618 else
16191619 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
......@@ -1738,13 +1738,13 @@ pub const Object = struct {
17381738
17391739 fn updateExportedValue(
17401740 o: *Object,
1741 mod: *Zcu,
1741 zcu: *Zcu,
17421742 exported_value: InternPool.Index,
17431743 export_indices: []const u32,
17441744 ) link.File.UpdateExportsError!void {
1745 const gpa = mod.gpa;
1746 const ip = &mod.intern_pool;
1747 const main_exp_name = try o.builder.strtabString(mod.all_exports.items[export_indices[0]].opts.name.toSlice(ip));
1745 const gpa = zcu.gpa;
1746 const ip = &zcu.intern_pool;
1747 const main_exp_name = try o.builder.strtabString(zcu.all_exports.items[export_indices[0]].opts.name.toSlice(ip));
17481748 const global_index = i: {
17491749 const gop = try o.uav_map.getOrPut(gpa, exported_value);
17501750 if (gop.found_existing) {
......@@ -1768,18 +1768,18 @@ pub const Object = struct {
17681768 try variable_index.setInitializer(init_val, &o.builder);
17691769 break :i global_index;
17701770 };
1771 return updateExportedGlobal(o, mod, global_index, export_indices);
1771 return updateExportedGlobal(o, zcu, global_index, export_indices);
17721772 }
17731773
17741774 fn updateExportedGlobal(
17751775 o: *Object,
1776 mod: *Zcu,
1776 zcu: *Zcu,
17771777 global_index: Builder.Global.Index,
17781778 export_indices: []const u32,
17791779 ) link.File.UpdateExportsError!void {
1780 const comp = mod.comp;
1781 const ip = &mod.intern_pool;
1782 const first_export = mod.all_exports.items[export_indices[0]];
1780 const comp = zcu.comp;
1781 const ip = &zcu.intern_pool;
1782 const first_export = zcu.all_exports.items[export_indices[0]];
17831783
17841784 // We will rename this global to have a name matching `first_export`.
17851785 // Successive exports become aliases.
......@@ -1836,7 +1836,7 @@ pub const Object = struct {
18361836 // Until then we iterate over existing aliases and make them point
18371837 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.
18381838 for (export_indices[1..]) |export_idx| {
1839 const exp = mod.all_exports.items[export_idx];
1839 const exp = zcu.all_exports.items[export_idx];
18401840 const exp_name = try o.builder.strtabString(exp.opts.name.toSlice(ip));
18411841 if (o.builder.getGlobal(exp_name)) |global| {
18421842 switch (global.ptrConst(&o.builder).kind) {
......@@ -1923,7 +1923,7 @@ pub const Object = struct {
19231923 const name = try o.allocTypeName(ty);
19241924 defer gpa.free(name);
19251925 const builder_name = try o.builder.metadataString(name);
1926 const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types
1926 const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types
19271927 const debug_int_type = switch (info.signedness) {
19281928 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
19291929 .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),
......@@ -1932,7 +1932,7 @@ pub const Object = struct {
19321932 return debug_int_type;
19331933 },
19341934 .Enum => {
1935 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
1935 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
19361936 const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty);
19371937 try o.debug_type_map.put(gpa, ty, debug_enum_type);
19381938 return debug_enum_type;
......@@ -1949,7 +1949,7 @@ pub const Object = struct {
19491949 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
19501950 var bigint_space: Value.BigIntSpace = undefined;
19511951 const bigint = if (enum_type.values.len != 0)
1952 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, pt)
1952 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, zcu)
19531953 else
19541954 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
19551955
......@@ -1976,8 +1976,8 @@ pub const Object = struct {
19761976 scope,
19771977 ty.typeDeclSrcLine(zcu).? + 1, // Line
19781978 try o.lowerDebugType(int_ty),
1979 ty.abiSize(pt) * 8,
1980 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
1979 ty.abiSize(zcu) * 8,
1980 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
19811981 try o.builder.debugTuple(enumerators),
19821982 );
19831983
......@@ -2017,10 +2017,10 @@ pub const Object = struct {
20172017 ptr_info.flags.is_const or
20182018 ptr_info.flags.is_volatile or
20192019 ptr_info.flags.size == .Many or ptr_info.flags.size == .C or
2020 !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(pt))
2020 !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu))
20212021 {
20222022 const bland_ptr_ty = try pt.ptrType(.{
2023 .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(pt))
2023 .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu))
20242024 .anyopaque_type
20252025 else
20262026 ptr_info.child,
......@@ -2050,10 +2050,10 @@ pub const Object = struct {
20502050 defer gpa.free(name);
20512051 const line = 0;
20522052
2053 const ptr_size = ptr_ty.abiSize(pt);
2054 const ptr_align = ptr_ty.abiAlignment(pt);
2055 const len_size = len_ty.abiSize(pt);
2056 const len_align = len_ty.abiAlignment(pt);
2053 const ptr_size = ptr_ty.abiSize(zcu);
2054 const ptr_align = ptr_ty.abiAlignment(zcu);
2055 const len_size = len_ty.abiSize(zcu);
2056 const len_align = len_ty.abiAlignment(zcu);
20572057
20582058 const len_offset = len_align.forward(ptr_size);
20592059
......@@ -2085,8 +2085,8 @@ pub const Object = struct {
20852085 o.debug_compile_unit, // Scope
20862086 line,
20872087 .none, // Underlying type
2088 ty.abiSize(pt) * 8,
2089 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2088 ty.abiSize(zcu) * 8,
2089 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
20902090 try o.builder.debugTuple(&.{
20912091 debug_ptr_type,
20922092 debug_len_type,
......@@ -2114,7 +2114,7 @@ pub const Object = struct {
21142114 0, // Line
21152115 debug_elem_ty,
21162116 target.ptrBitWidth(),
2117 (ty.ptrAlignment(pt).toByteUnits() orelse 0) * 8,
2117 (ty.ptrAlignment(zcu).toByteUnits() orelse 0) * 8,
21182118 0, // Offset
21192119 );
21202120
......@@ -2165,8 +2165,8 @@ pub const Object = struct {
21652165 .none, // Scope
21662166 0, // Line
21672167 try o.lowerDebugType(ty.childType(zcu)),
2168 ty.abiSize(pt) * 8,
2169 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2168 ty.abiSize(zcu) * 8,
2169 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
21702170 try o.builder.debugTuple(&.{
21712171 try o.builder.debugSubrange(
21722172 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
......@@ -2208,8 +2208,8 @@ pub const Object = struct {
22082208 .none, // Scope
22092209 0, // Line
22102210 debug_elem_type,
2211 ty.abiSize(pt) * 8,
2212 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2211 ty.abiSize(zcu) * 8,
2212 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
22132213 try o.builder.debugTuple(&.{
22142214 try o.builder.debugSubrange(
22152215 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
......@@ -2225,7 +2225,7 @@ pub const Object = struct {
22252225 const name = try o.allocTypeName(ty);
22262226 defer gpa.free(name);
22272227 const child_ty = ty.optionalChild(zcu);
2228 if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2228 if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
22292229 const debug_bool_type = try o.builder.debugBoolType(
22302230 try o.builder.metadataString(name),
22312231 8,
......@@ -2252,10 +2252,10 @@ pub const Object = struct {
22522252 }
22532253
22542254 const non_null_ty = Type.u8;
2255 const payload_size = child_ty.abiSize(pt);
2256 const payload_align = child_ty.abiAlignment(pt);
2257 const non_null_size = non_null_ty.abiSize(pt);
2258 const non_null_align = non_null_ty.abiAlignment(pt);
2255 const payload_size = child_ty.abiSize(zcu);
2256 const payload_align = child_ty.abiAlignment(zcu);
2257 const non_null_size = non_null_ty.abiSize(zcu);
2258 const non_null_align = non_null_ty.abiAlignment(zcu);
22592259 const non_null_offset = non_null_align.forward(payload_size);
22602260
22612261 const debug_data_type = try o.builder.debugMemberType(
......@@ -2286,8 +2286,8 @@ pub const Object = struct {
22862286 o.debug_compile_unit, // Scope
22872287 0, // Line
22882288 .none, // Underlying type
2289 ty.abiSize(pt) * 8,
2290 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2289 ty.abiSize(zcu) * 8,
2290 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
22912291 try o.builder.debugTuple(&.{
22922292 debug_data_type,
22932293 debug_some_type,
......@@ -2304,7 +2304,7 @@ pub const Object = struct {
23042304 },
23052305 .ErrorUnion => {
23062306 const payload_ty = ty.errorUnionPayload(zcu);
2307 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
2307 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
23082308 // TODO: Maybe remove?
23092309 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
23102310 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
......@@ -2314,10 +2314,10 @@ pub const Object = struct {
23142314 const name = try o.allocTypeName(ty);
23152315 defer gpa.free(name);
23162316
2317 const error_size = Type.anyerror.abiSize(pt);
2318 const error_align = Type.anyerror.abiAlignment(pt);
2319 const payload_size = payload_ty.abiSize(pt);
2320 const payload_align = payload_ty.abiAlignment(pt);
2317 const error_size = Type.anyerror.abiSize(zcu);
2318 const error_align = Type.anyerror.abiAlignment(zcu);
2319 const payload_size = payload_ty.abiSize(zcu);
2320 const payload_align = payload_ty.abiAlignment(zcu);
23212321
23222322 var error_index: u32 = undefined;
23232323 var payload_index: u32 = undefined;
......@@ -2365,8 +2365,8 @@ pub const Object = struct {
23652365 o.debug_compile_unit, // Sope
23662366 0, // Line
23672367 .none, // Underlying type
2368 ty.abiSize(pt) * 8,
2369 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2368 ty.abiSize(zcu) * 8,
2369 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
23702370 try o.builder.debugTuple(&fields),
23712371 );
23722372
......@@ -2393,8 +2393,8 @@ pub const Object = struct {
23932393 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
23942394 const builder_name = try o.builder.metadataString(name);
23952395 const debug_int_type = switch (info.signedness) {
2396 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(pt) * 8),
2397 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(pt) * 8),
2396 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8),
2397 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8),
23982398 };
23992399 try o.debug_type_map.put(gpa, ty, debug_int_type);
24002400 return debug_int_type;
......@@ -2414,10 +2414,10 @@ pub const Object = struct {
24142414 const debug_fwd_ref = try o.builder.debugForwardReference();
24152415
24162416 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2417 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
2417 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
24182418
2419 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2420 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
2419 const field_size = Type.fromInterned(field_ty).abiSize(zcu);
2420 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
24212421 const field_offset = field_align.forward(offset);
24222422 offset = field_offset + field_size;
24232423
......@@ -2445,8 +2445,8 @@ pub const Object = struct {
24452445 o.debug_compile_unit, // Scope
24462446 0, // Line
24472447 .none, // Underlying type
2448 ty.abiSize(pt) * 8,
2449 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2448 ty.abiSize(zcu) * 8,
2449 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
24502450 try o.builder.debugTuple(fields.items),
24512451 );
24522452
......@@ -2472,7 +2472,7 @@ pub const Object = struct {
24722472 else => {},
24732473 }
24742474
2475 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
2475 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
24762476 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);
24772477 try o.debug_type_map.put(gpa, ty, debug_struct_type);
24782478 return debug_struct_type;
......@@ -2494,14 +2494,14 @@ pub const Object = struct {
24942494 var it = struct_type.iterateRuntimeOrder(ip);
24952495 while (it.next()) |field_index| {
24962496 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2497 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2498 const field_size = field_ty.abiSize(pt);
2497 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
2498 const field_size = field_ty.abiSize(zcu);
24992499 const field_align = pt.structFieldAlignment(
25002500 struct_type.fieldAlign(ip, field_index),
25012501 field_ty,
25022502 struct_type.layout,
25032503 );
2504 const field_offset = ty.structFieldOffset(field_index, pt);
2504 const field_offset = ty.structFieldOffset(field_index, zcu);
25052505
25062506 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
25072507 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
......@@ -2524,8 +2524,8 @@ pub const Object = struct {
25242524 o.debug_compile_unit, // Scope
25252525 0, // Line
25262526 .none, // Underlying type
2527 ty.abiSize(pt) * 8,
2528 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2527 ty.abiSize(zcu) * 8,
2528 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25292529 try o.builder.debugTuple(fields.items),
25302530 );
25312531
......@@ -2543,7 +2543,7 @@ pub const Object = struct {
25432543
25442544 const union_type = ip.loadUnionType(ty.toIntern());
25452545 if (!union_type.haveFieldTypes(ip) or
2546 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2546 !ty.hasRuntimeBitsIgnoreComptime(zcu) or
25472547 !union_type.haveLayout(ip))
25482548 {
25492549 const debug_union_type = try o.makeEmptyNamespaceDebugType(ty);
......@@ -2551,7 +2551,7 @@ pub const Object = struct {
25512551 return debug_union_type;
25522552 }
25532553
2554 const layout = pt.getUnionLayout(union_type);
2554 const layout = Type.getUnionLayout(union_type, zcu);
25552555
25562556 const debug_fwd_ref = try o.builder.debugForwardReference();
25572557
......@@ -2565,8 +2565,8 @@ pub const Object = struct {
25652565 o.debug_compile_unit, // Scope
25662566 0, // Line
25672567 .none, // Underlying type
2568 ty.abiSize(pt) * 8,
2569 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2568 ty.abiSize(zcu) * 8,
2569 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25702570 try o.builder.debugTuple(
25712571 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
25722572 ),
......@@ -2593,12 +2593,12 @@ pub const Object = struct {
25932593
25942594 for (0..tag_type.names.len) |field_index| {
25952595 const field_ty = union_type.field_types.get(ip)[field_index];
2596 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
2596 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
25972597
2598 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2598 const field_size = Type.fromInterned(field_ty).abiSize(zcu);
25992599 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
26002600 .@"packed" => .none,
2601 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2601 .auto, .@"extern" => Type.unionFieldNormalAlignment(union_type, @intCast(field_index), zcu),
26022602 };
26032603
26042604 const field_name = tag_type.names.get(ip)[field_index];
......@@ -2627,8 +2627,8 @@ pub const Object = struct {
26272627 o.debug_compile_unit, // Scope
26282628 0, // Line
26292629 .none, // Underlying type
2630 ty.abiSize(pt) * 8,
2631 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2630 ty.abiSize(zcu) * 8,
2631 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
26322632 try o.builder.debugTuple(fields.items),
26332633 );
26342634
......@@ -2686,8 +2686,8 @@ pub const Object = struct {
26862686 o.debug_compile_unit, // Scope
26872687 0, // Line
26882688 .none, // Underlying type
2689 ty.abiSize(pt) * 8,
2690 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2689 ty.abiSize(zcu) * 8,
2690 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
26912691 try o.builder.debugTuple(&full_fields),
26922692 );
26932693
......@@ -2708,8 +2708,8 @@ pub const Object = struct {
27082708 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
27092709
27102710 // Return type goes first.
2711 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2712 const sret = firstParamSRet(fn_info, pt, target);
2711 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
2712 const sret = firstParamSRet(fn_info, zcu, target);
27132713 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
27142714 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
27152715
......@@ -2730,9 +2730,9 @@ pub const Object = struct {
27302730
27312731 for (0..fn_info.param_types.len) |i| {
27322732 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2733 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2733 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
27342734
2735 if (isByRef(param_ty, pt)) {
2735 if (isByRef(param_ty, zcu)) {
27362736 const ptr_ty = try pt.singleMutPtrType(param_ty);
27372737 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
27382738 } else {
......@@ -2842,7 +2842,7 @@ pub const Object = struct {
28422842
28432843 const fn_info = zcu.typeToFunc(ty).?;
28442844 const target = owner_mod.resolved_target.result;
2845 const sret = firstParamSRet(fn_info, pt, target);
2845 const sret = firstParamSRet(fn_info, zcu, target);
28462846
28472847 const is_extern, const lib_name = switch (ip.indexToKey(val.toIntern())) {
28482848 .variable => |variable| .{ false, variable.lib_name },
......@@ -2934,14 +2934,14 @@ pub const Object = struct {
29342934 .byval => {
29352935 const param_index = it.zig_index - 1;
29362936 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
2937 if (!isByRef(param_ty, pt)) {
2937 if (!isByRef(param_ty, zcu)) {
29382938 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
29392939 }
29402940 },
29412941 .byref => {
29422942 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
29432943 const param_llvm_ty = try o.lowerType(param_ty);
2944 const alignment = param_ty.abiAlignment(pt);
2944 const alignment = param_ty.abiAlignment(zcu);
29452945 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
29462946 },
29472947 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
......@@ -3042,8 +3042,8 @@ pub const Object = struct {
30423042 }
30433043 errdefer assert(o.uav_map.remove(uav));
30443044
3045 const mod = o.pt.zcu;
3046 const decl_ty = mod.intern_pool.typeOf(uav);
3045 const zcu = o.pt.zcu;
3046 const decl_ty = zcu.intern_pool.typeOf(uav);
30473047
30483048 const variable_index = try o.builder.addVariable(
30493049 try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}),
......@@ -3106,9 +3106,9 @@ pub const Object = struct {
31063106
31073107 fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type {
31083108 const pt = o.pt;
3109 const mod = pt.zcu;
3110 const target = mod.getTarget();
3111 const ip = &mod.intern_pool;
3109 const zcu = pt.zcu;
3110 const target = zcu.getTarget();
3111 const ip = &zcu.intern_pool;
31123112 return switch (t.toIntern()) {
31133113 .u0_type, .i0_type => unreachable,
31143114 inline .u1_type,
......@@ -3230,16 +3230,16 @@ pub const Object = struct {
32303230 ),
32313231 .opt_type => |child_ty| {
32323232 // Must stay in sync with `opt_payload` logic in `lowerPtr`.
3233 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(pt)) return .i8;
3233 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8;
32343234
32353235 const payload_ty = try o.lowerType(Type.fromInterned(child_ty));
3236 if (t.optionalReprIsPayload(mod)) return payload_ty;
3236 if (t.optionalReprIsPayload(zcu)) return payload_ty;
32373237
32383238 comptime assert(optional_layout_version == 3);
32393239 var fields: [3]Builder.Type = .{ payload_ty, .i8, undefined };
32403240 var fields_len: usize = 2;
3241 const offset = Type.fromInterned(child_ty).abiSize(pt) + 1;
3242 const abi_size = t.abiSize(pt);
3241 const offset = Type.fromInterned(child_ty).abiSize(zcu) + 1;
3242 const abi_size = t.abiSize(zcu);
32433243 const padding_len = abi_size - offset;
32443244 if (padding_len > 0) {
32453245 fields[2] = try o.builder.arrayType(padding_len, .i8);
......@@ -3252,16 +3252,16 @@ pub const Object = struct {
32523252 // Must stay in sync with `codegen.errUnionPayloadOffset`.
32533253 // See logic in `lowerPtr`.
32543254 const error_type = try o.errorIntType();
3255 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(pt))
3255 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu))
32563256 return error_type;
32573257 const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type));
32583258 const err_int_ty = try o.pt.errorIntType();
32593259
3260 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(pt);
3261 const error_align = err_int_ty.abiAlignment(pt);
3260 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu);
3261 const error_align = err_int_ty.abiAlignment(zcu);
32623262
3263 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(pt);
3264 const error_size = err_int_ty.abiSize(pt);
3263 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu);
3264 const error_size = err_int_ty.abiSize(zcu);
32653265
32663266 var fields: [3]Builder.Type = undefined;
32673267 var fields_len: usize = 2;
......@@ -3320,7 +3320,7 @@ pub const Object = struct {
33203320 field_ty,
33213321 struct_type.layout,
33223322 );
3323 const field_ty_align = field_ty.abiAlignment(pt);
3323 const field_ty_align = field_ty.abiAlignment(zcu);
33243324 if (field_align.compare(.lt, field_ty_align)) struct_kind = .@"packed";
33253325 big_align = big_align.max(field_align);
33263326 const prev_offset = offset;
......@@ -3332,7 +3332,7 @@ pub const Object = struct {
33323332 try o.builder.arrayType(padding_len, .i8),
33333333 );
33343334
3335 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3335 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
33363336 // This is a zero-bit field. If there are runtime bits after this field,
33373337 // map to the next LLVM field (which we know exists): otherwise, don't
33383338 // map the field, indicating it's at the end of the struct.
......@@ -3351,7 +3351,7 @@ pub const Object = struct {
33513351 }, @intCast(llvm_field_types.items.len));
33523352 try llvm_field_types.append(o.gpa, try o.lowerType(field_ty));
33533353
3354 offset += field_ty.abiSize(pt);
3354 offset += field_ty.abiSize(zcu);
33553355 }
33563356 {
33573357 const prev_offset = offset;
......@@ -3384,7 +3384,7 @@ pub const Object = struct {
33843384 var offset: u64 = 0;
33853385 var big_align: InternPool.Alignment = .none;
33863386
3387 const struct_size = t.abiSize(pt);
3387 const struct_size = t.abiSize(zcu);
33883388
33893389 for (
33903390 anon_struct_type.types.get(ip),
......@@ -3393,7 +3393,7 @@ pub const Object = struct {
33933393 ) |field_ty, field_val, field_index| {
33943394 if (field_val != .none) continue;
33953395
3396 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
3396 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
33973397 big_align = big_align.max(field_align);
33983398 const prev_offset = offset;
33993399 offset = field_align.forward(offset);
......@@ -3403,7 +3403,7 @@ pub const Object = struct {
34033403 o.gpa,
34043404 try o.builder.arrayType(padding_len, .i8),
34053405 );
3406 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) {
3406 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) {
34073407 // This is a zero-bit field. If there are runtime bits after this field,
34083408 // map to the next LLVM field (which we know exists): otherwise, don't
34093409 // map the field, indicating it's at the end of the struct.
......@@ -3421,7 +3421,7 @@ pub const Object = struct {
34213421 }, @intCast(llvm_field_types.items.len));
34223422 try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty)));
34233423
3424 offset += Type.fromInterned(field_ty).abiSize(pt);
3424 offset += Type.fromInterned(field_ty).abiSize(zcu);
34253425 }
34263426 {
34273427 const prev_offset = offset;
......@@ -3438,10 +3438,10 @@ pub const Object = struct {
34383438 if (o.type_map.get(t.toIntern())) |value| return value;
34393439
34403440 const union_obj = ip.loadUnionType(t.toIntern());
3441 const layout = pt.getUnionLayout(union_obj);
3441 const layout = Type.getUnionLayout(union_obj, zcu);
34423442
34433443 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
3444 const int_ty = try o.builder.intType(@intCast(t.bitSize(pt)));
3444 const int_ty = try o.builder.intType(@intCast(t.bitSize(zcu)));
34453445 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
34463446 return int_ty;
34473447 }
......@@ -3547,32 +3547,32 @@ pub const Object = struct {
35473547 /// There are other similar cases handled here as well.
35483548 fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type {
35493549 const pt = o.pt;
3550 const mod = pt.zcu;
3551 const lower_elem_ty = switch (elem_ty.zigTypeTag(mod)) {
3550 const zcu = pt.zcu;
3551 const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) {
35523552 .Opaque => true,
3553 .Fn => !mod.typeToFunc(elem_ty).?.is_generic,
3554 .Array => elem_ty.childType(mod).hasRuntimeBitsIgnoreComptime(pt),
3555 else => elem_ty.hasRuntimeBitsIgnoreComptime(pt),
3553 .Fn => !zcu.typeToFunc(elem_ty).?.is_generic,
3554 .Array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu),
3555 else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu),
35563556 };
35573557 return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8;
35583558 }
35593559
35603560 fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
35613561 const pt = o.pt;
3562 const mod = pt.zcu;
3563 const ip = &mod.intern_pool;
3564 const target = mod.getTarget();
3562 const zcu = pt.zcu;
3563 const ip = &zcu.intern_pool;
3564 const target = zcu.getTarget();
35653565 const ret_ty = try lowerFnRetTy(o, fn_info);
35663566
35673567 var llvm_params = std.ArrayListUnmanaged(Builder.Type){};
35683568 defer llvm_params.deinit(o.gpa);
35693569
3570 if (firstParamSRet(fn_info, pt, target)) {
3570 if (firstParamSRet(fn_info, zcu, target)) {
35713571 try llvm_params.append(o.gpa, .ptr);
35723572 }
35733573
3574 if (Type.fromInterned(fn_info.return_type).isError(mod) and
3575 mod.comp.config.any_error_tracing)
3574 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
3575 zcu.comp.config.any_error_tracing)
35763576 {
35773577 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
35783578 try llvm_params.append(o.gpa, try o.lowerType(ptr_ty));
......@@ -3591,13 +3591,13 @@ pub const Object = struct {
35913591 .abi_sized_int => {
35923592 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
35933593 try llvm_params.append(o.gpa, try o.builder.intType(
3594 @intCast(param_ty.abiSize(pt) * 8),
3594 @intCast(param_ty.abiSize(zcu) * 8),
35953595 ));
35963596 },
35973597 .slice => {
35983598 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
35993599 try llvm_params.appendSlice(o.gpa, &.{
3600 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(mod), target)),
3600 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)),
36013601 try o.lowerType(Type.usize),
36023602 });
36033603 },
......@@ -3609,7 +3609,7 @@ pub const Object = struct {
36093609 },
36103610 .float_array => |count| {
36113611 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
3612 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, mod).?);
3612 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, zcu).?);
36133613 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
36143614 },
36153615 .i32_array, .i64_array => |arr_len| {
......@@ -3630,14 +3630,14 @@ pub const Object = struct {
36303630
36313631 fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
36323632 const pt = o.pt;
3633 const mod = pt.zcu;
3634 const ip = &mod.intern_pool;
3635 const target = mod.getTarget();
3633 const zcu = pt.zcu;
3634 const ip = &zcu.intern_pool;
3635 const target = zcu.getTarget();
36363636
36373637 const val = Value.fromInterned(arg_val);
36383638 const val_key = ip.indexToKey(val.toIntern());
36393639
3640 if (val.isUndefDeep(mod)) return o.builder.undefConst(llvm_int_ty);
3640 if (val.isUndefDeep(zcu)) return o.builder.undefConst(llvm_int_ty);
36413641
36423642 const ty = Type.fromInterned(val_key.typeOf());
36433643 switch (val_key) {
......@@ -3661,7 +3661,7 @@ pub const Object = struct {
36613661 var running_int = try o.builder.intConst(llvm_int_ty, 0);
36623662 var running_bits: u16 = 0;
36633663 for (struct_type.field_types.get(ip), 0..) |field_ty, field_index| {
3664 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
3664 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
36653665
36663666 const shift_rhs = try o.builder.intConst(llvm_int_ty, running_bits);
36673667 const field_val = try o.lowerValueToInt(llvm_int_ty, (try val.fieldValue(pt, field_index)).toIntern());
......@@ -3669,7 +3669,7 @@ pub const Object = struct {
36693669
36703670 running_int = try o.builder.binConst(.xor, running_int, shifted);
36713671
3672 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(pt));
3672 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(zcu));
36733673 running_bits += ty_bit_size;
36743674 }
36753675 return running_int;
......@@ -3678,10 +3678,10 @@ pub const Object = struct {
36783678 else => unreachable,
36793679 },
36803680 .un => |un| {
3681 const layout = ty.unionGetLayout(pt);
3681 const layout = ty.unionGetLayout(zcu);
36823682 if (layout.payload_size == 0) return o.lowerValue(un.tag);
36833683
3684 const union_obj = mod.typeToUnion(ty).?;
3684 const union_obj = zcu.typeToUnion(ty).?;
36853685 const container_layout = union_obj.flagsUnordered(ip).layout;
36863686
36873687 assert(container_layout == .@"packed");
......@@ -3694,9 +3694,9 @@ pub const Object = struct {
36943694 need_unnamed = true;
36953695 return union_val;
36963696 }
3697 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3697 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
36983698 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3699 if (!field_ty.hasRuntimeBits(pt)) return o.builder.intConst(llvm_int_ty, 0);
3699 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(llvm_int_ty, 0);
37003700 return o.lowerValueToInt(llvm_int_ty, un.val);
37013701 },
37023702 .simple_value => |simple_value| switch (simple_value) {
......@@ -3710,7 +3710,7 @@ pub const Object = struct {
37103710 .opt => {}, // pointer like optional expected
37113711 else => unreachable,
37123712 }
3713 const bits = ty.bitSize(pt);
3713 const bits = ty.bitSize(zcu);
37143714 const bytes: usize = @intCast(std.mem.alignForward(u64, bits, 8) / 8);
37153715
37163716 var stack = std.heap.stackFallback(32, o.gpa);
......@@ -3743,14 +3743,14 @@ pub const Object = struct {
37433743
37443744 fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant {
37453745 const pt = o.pt;
3746 const mod = pt.zcu;
3747 const ip = &mod.intern_pool;
3748 const target = mod.getTarget();
3746 const zcu = pt.zcu;
3747 const ip = &zcu.intern_pool;
3748 const target = zcu.getTarget();
37493749
37503750 const val = Value.fromInterned(arg_val);
37513751 const val_key = ip.indexToKey(val.toIntern());
37523752
3753 if (val.isUndefDeep(mod)) {
3753 if (val.isUndefDeep(zcu)) {
37543754 return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf())));
37553755 }
37563756
......@@ -3800,7 +3800,7 @@ pub const Object = struct {
38003800 },
38013801 .int => {
38023802 var bigint_space: Value.BigIntSpace = undefined;
3803 const bigint = val.toBigInt(&bigint_space, pt);
3803 const bigint = val.toBigInt(&bigint_space, zcu);
38043804 return lowerBigInt(o, ty, bigint);
38053805 },
38063806 .err => |err| {
......@@ -3811,20 +3811,20 @@ pub const Object = struct {
38113811 .error_union => |error_union| {
38123812 const err_val = switch (error_union.val) {
38133813 .err_name => |err_name| try pt.intern(.{ .err = .{
3814 .ty = ty.errorUnionSet(mod).toIntern(),
3814 .ty = ty.errorUnionSet(zcu).toIntern(),
38153815 .name = err_name,
38163816 } }),
38173817 .payload => (try pt.intValue(try pt.errorIntType(), 0)).toIntern(),
38183818 };
38193819 const err_int_ty = try pt.errorIntType();
3820 const payload_type = ty.errorUnionPayload(mod);
3821 if (!payload_type.hasRuntimeBitsIgnoreComptime(pt)) {
3820 const payload_type = ty.errorUnionPayload(zcu);
3821 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
38223822 // We use the error type directly as the type.
38233823 return o.lowerValue(err_val);
38243824 }
38253825
3826 const payload_align = payload_type.abiAlignment(pt);
3827 const error_align = err_int_ty.abiAlignment(pt);
3826 const payload_align = payload_type.abiAlignment(zcu);
3827 const error_align = err_int_ty.abiAlignment(zcu);
38283828 const llvm_error_value = try o.lowerValue(err_val);
38293829 const llvm_payload_value = try o.lowerValue(switch (error_union.val) {
38303830 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),
......@@ -3858,16 +3858,16 @@ pub const Object = struct {
38583858 .enum_tag => |enum_tag| o.lowerValue(enum_tag.int),
38593859 .float => switch (ty.floatBits(target)) {
38603860 16 => if (backendSupportsF16(target))
3861 try o.builder.halfConst(val.toFloat(f16, pt))
3861 try o.builder.halfConst(val.toFloat(f16, zcu))
38623862 else
3863 try o.builder.intConst(.i16, @as(i16, @bitCast(val.toFloat(f16, pt)))),
3864 32 => try o.builder.floatConst(val.toFloat(f32, pt)),
3865 64 => try o.builder.doubleConst(val.toFloat(f64, pt)),
3863 try o.builder.intConst(.i16, @as(i16, @bitCast(val.toFloat(f16, zcu)))),
3864 32 => try o.builder.floatConst(val.toFloat(f32, zcu)),
3865 64 => try o.builder.doubleConst(val.toFloat(f64, zcu)),
38663866 80 => if (backendSupportsF80(target))
3867 try o.builder.x86_fp80Const(val.toFloat(f80, pt))
3867 try o.builder.x86_fp80Const(val.toFloat(f80, zcu))
38683868 else
3869 try o.builder.intConst(.i80, @as(i80, @bitCast(val.toFloat(f80, pt)))),
3870 128 => try o.builder.fp128Const(val.toFloat(f128, pt)),
3869 try o.builder.intConst(.i80, @as(i80, @bitCast(val.toFloat(f80, zcu)))),
3870 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)),
38713871 else => unreachable,
38723872 },
38733873 .ptr => try o.lowerPtr(arg_val, 0),
......@@ -3877,14 +3877,14 @@ pub const Object = struct {
38773877 }),
38783878 .opt => |opt| {
38793879 comptime assert(optional_layout_version == 3);
3880 const payload_ty = ty.optionalChild(mod);
3880 const payload_ty = ty.optionalChild(zcu);
38813881
38823882 const non_null_bit = try o.builder.intConst(.i8, @intFromBool(opt.val != .none));
3883 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3883 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
38843884 return non_null_bit;
38853885 }
38863886 const llvm_ty = try o.lowerType(ty);
3887 if (ty.optionalReprIsPayload(mod)) return switch (opt.val) {
3887 if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) {
38883888 .none => switch (llvm_ty.tag(&o.builder)) {
38893889 .integer => try o.builder.intConst(llvm_ty, 0),
38903890 .pointer => try o.builder.nullConst(llvm_ty),
......@@ -3893,7 +3893,7 @@ pub const Object = struct {
38933893 },
38943894 else => |payload| try o.lowerValue(payload),
38953895 };
3896 assert(payload_ty.zigTypeTag(mod) != .Fn);
3896 assert(payload_ty.zigTypeTag(zcu) != .Fn);
38973897
38983898 var fields: [3]Builder.Type = undefined;
38993899 var vals: [3]Builder.Constant = undefined;
......@@ -4047,9 +4047,9 @@ pub const Object = struct {
40474047 0..,
40484048 ) |field_ty, field_val, field_index| {
40494049 if (field_val != .none) continue;
4050 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
4050 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
40514051
4052 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
4052 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
40534053 big_align = big_align.max(field_align);
40544054 const prev_offset = offset;
40554055 offset = field_align.forward(offset);
......@@ -4071,7 +4071,7 @@ pub const Object = struct {
40714071 need_unnamed = true;
40724072 llvm_index += 1;
40734073
4074 offset += Type.fromInterned(field_ty).abiSize(pt);
4074 offset += Type.fromInterned(field_ty).abiSize(zcu);
40754075 }
40764076 {
40774077 const prev_offset = offset;
......@@ -4098,7 +4098,7 @@ pub const Object = struct {
40984098 if (struct_type.layout == .@"packed") {
40994099 comptime assert(Type.packed_struct_layout_version == 2);
41004100
4101 const bits = ty.bitSize(pt);
4101 const bits = ty.bitSize(zcu);
41024102 const llvm_int_ty = try o.builder.intType(@intCast(bits));
41034103
41044104 return o.lowerValueToInt(llvm_int_ty, arg_val);
......@@ -4147,7 +4147,7 @@ pub const Object = struct {
41474147 llvm_index += 1;
41484148 }
41494149
4150 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4150 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
41514151 // This is a zero-bit field - we only needed it for the alignment.
41524152 continue;
41534153 }
......@@ -4160,7 +4160,7 @@ pub const Object = struct {
41604160 need_unnamed = true;
41614161 llvm_index += 1;
41624162
4163 offset += field_ty.abiSize(pt);
4163 offset += field_ty.abiSize(zcu);
41644164 }
41654165 {
41664166 const prev_offset = offset;
......@@ -4184,19 +4184,19 @@ pub const Object = struct {
41844184 },
41854185 .un => |un| {
41864186 const union_ty = try o.lowerType(ty);
4187 const layout = ty.unionGetLayout(pt);
4187 const layout = ty.unionGetLayout(zcu);
41884188 if (layout.payload_size == 0) return o.lowerValue(un.tag);
41894189
4190 const union_obj = mod.typeToUnion(ty).?;
4190 const union_obj = zcu.typeToUnion(ty).?;
41914191 const container_layout = union_obj.flagsUnordered(ip).layout;
41924192
41934193 var need_unnamed = false;
41944194 const payload = if (un.tag != .none) p: {
4195 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
4195 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
41964196 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
41974197 if (container_layout == .@"packed") {
4198 if (!field_ty.hasRuntimeBits(pt)) return o.builder.intConst(union_ty, 0);
4199 const bits = ty.bitSize(pt);
4198 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(union_ty, 0);
4199 const bits = ty.bitSize(zcu);
42004200 const llvm_int_ty = try o.builder.intType(@intCast(bits));
42014201
42024202 return o.lowerValueToInt(llvm_int_ty, arg_val);
......@@ -4208,7 +4208,7 @@ pub const Object = struct {
42084208 // must pointer cast to the expected type before accessing the union.
42094209 need_unnamed = layout.most_aligned_field != field_index;
42104210
4211 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4211 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
42124212 const padding_len = layout.payload_size;
42134213 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));
42144214 }
......@@ -4217,7 +4217,7 @@ pub const Object = struct {
42174217 if (payload_ty != union_ty.structFields(&o.builder)[
42184218 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))
42194219 ]) need_unnamed = true;
4220 const field_size = field_ty.abiSize(pt);
4220 const field_size = field_ty.abiSize(zcu);
42214221 if (field_size == layout.payload_size) break :p payload;
42224222 const padding_len = layout.payload_size - field_size;
42234223 const padding_ty = try o.builder.arrayType(padding_len, .i8);
......@@ -4228,7 +4228,7 @@ pub const Object = struct {
42284228 } else p: {
42294229 assert(layout.tag_size == 0);
42304230 if (container_layout == .@"packed") {
4231 const bits = ty.bitSize(pt);
4231 const bits = ty.bitSize(zcu);
42324232 const llvm_int_ty = try o.builder.intType(@intCast(bits));
42334233
42344234 return o.lowerValueToInt(llvm_int_ty, arg_val);
......@@ -4275,8 +4275,8 @@ pub const Object = struct {
42754275 ty: Type,
42764276 bigint: std.math.big.int.Const,
42774277 ) Allocator.Error!Builder.Constant {
4278 const mod = o.pt.zcu;
4279 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(mod).bits), bigint);
4278 const zcu = o.pt.zcu;
4279 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint);
42804280 }
42814281
42824282 fn lowerPtr(
......@@ -4310,7 +4310,7 @@ pub const Object = struct {
43104310 eu_ptr,
43114311 offset + @import("../codegen.zig").errUnionPayloadOffset(
43124312 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),
4313 pt,
4313 zcu,
43144314 ),
43154315 ),
43164316 .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset),
......@@ -4326,7 +4326,7 @@ pub const Object = struct {
43264326 };
43274327 },
43284328 .Struct, .Union => switch (agg_ty.containerLayout(zcu)) {
4329 .auto => agg_ty.structFieldOffset(@intCast(field.index), pt),
4329 .auto => agg_ty.structFieldOffset(@intCast(field.index), zcu),
43304330 .@"extern", .@"packed" => unreachable,
43314331 },
43324332 else => unreachable,
......@@ -4344,11 +4344,11 @@ pub const Object = struct {
43444344 uav: InternPool.Key.Ptr.BaseAddr.Uav,
43454345 ) Error!Builder.Constant {
43464346 const pt = o.pt;
4347 const mod = pt.zcu;
4348 const ip = &mod.intern_pool;
4347 const zcu = pt.zcu;
4348 const ip = &zcu.intern_pool;
43494349 const uav_val = uav.val;
43504350 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));
4351 const target = mod.getTarget();
4351 const target = zcu.getTarget();
43524352
43534353 switch (ip.indexToKey(uav_val)) {
43544354 .func => @panic("TODO"),
......@@ -4358,15 +4358,15 @@ pub const Object = struct {
43584358
43594359 const ptr_ty = Type.fromInterned(uav.orig_ty);
43604360
4361 const is_fn_body = uav_ty.zigTypeTag(mod) == .Fn;
4362 if ((!is_fn_body and !uav_ty.hasRuntimeBits(pt)) or
4363 (is_fn_body and mod.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty);
4361 const is_fn_body = uav_ty.zigTypeTag(zcu) == .Fn;
4362 if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or
4363 (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty);
43644364
43654365 if (is_fn_body)
43664366 @panic("TODO");
43674367
4368 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(mod), target);
4369 const alignment = ptr_ty.ptrAlignment(pt);
4368 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target);
4369 const alignment = ptr_ty.ptrAlignment(zcu);
43704370 const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
43714371
43724372 const llvm_val = try o.builder.convConst(
......@@ -4398,7 +4398,7 @@ pub const Object = struct {
43984398 const ptr_ty = try pt.navPtrType(owner_nav_index);
43994399
44004400 const is_fn_body = nav_ty.zigTypeTag(zcu) == .Fn;
4401 if ((!is_fn_body and !nav_ty.hasRuntimeBits(pt)) or
4401 if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or
44024402 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))
44034403 {
44044404 return o.lowerPtrToVoid(ptr_ty);
......@@ -4418,19 +4418,19 @@ pub const Object = struct {
44184418 }
44194419
44204420 fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant {
4421 const mod = o.pt.zcu;
4421 const zcu = o.pt.zcu;
44224422 // Even though we are pointing at something which has zero bits (e.g. `void`),
44234423 // Pointers are defined to have bits. So we must return something here.
44244424 // The value cannot be undefined, because we use the `nonnull` annotation
44254425 // for non-optional pointers. We also need to respect the alignment, even though
44264426 // the address will never be dereferenced.
4427 const int: u64 = ptr_ty.ptrInfo(mod).flags.alignment.toByteUnits() orelse
4427 const int: u64 = ptr_ty.ptrInfo(zcu).flags.alignment.toByteUnits() orelse
44284428 // Note that these 0xaa values are appropriate even in release-optimized builds
44294429 // because we need a well-defined value that is not null, and LLVM does not
44304430 // have an "undef_but_not_null" attribute. As an example, if this `alloc` AIR
44314431 // instruction is followed by a `wrap_optional`, it will return this value
44324432 // verbatim, and the result should test as non-null.
4433 switch (mod.getTarget().ptrBitWidth()) {
4433 switch (zcu.getTarget().ptrBitWidth()) {
44344434 16 => 0xaaaa,
44354435 32 => 0xaaaaaaaa,
44364436 64 => 0xaaaaaaaa_aaaaaaaa,
......@@ -4447,20 +4447,20 @@ pub const Object = struct {
44474447 /// types to work around a LLVM deficiency when targeting ARM/AArch64.
44484448 fn getAtomicAbiType(o: *Object, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
44494449 const pt = o.pt;
4450 const mod = pt.zcu;
4451 const int_ty = switch (ty.zigTypeTag(mod)) {
4450 const zcu = pt.zcu;
4451 const int_ty = switch (ty.zigTypeTag(zcu)) {
44524452 .Int => ty,
4453 .Enum => ty.intTagType(mod),
4453 .Enum => ty.intTagType(zcu),
44544454 .Float => {
44554455 if (!is_rmw_xchg) return .none;
4456 return o.builder.intType(@intCast(ty.abiSize(pt) * 8));
4456 return o.builder.intType(@intCast(ty.abiSize(zcu) * 8));
44574457 },
44584458 .Bool => return .i8,
44594459 else => return .none,
44604460 };
4461 const bit_count = int_ty.intInfo(mod).bits;
4461 const bit_count = int_ty.intInfo(zcu).bits;
44624462 if (!std.math.isPowerOfTwo(bit_count) or (bit_count % 8) != 0) {
4463 return o.builder.intType(@intCast(int_ty.abiSize(pt) * 8));
4463 return o.builder.intType(@intCast(int_ty.abiSize(zcu) * 8));
44644464 } else {
44654465 return .none;
44664466 }
......@@ -4475,15 +4475,15 @@ pub const Object = struct {
44754475 llvm_arg_i: u32,
44764476 ) Allocator.Error!void {
44774477 const pt = o.pt;
4478 const mod = pt.zcu;
4479 if (param_ty.isPtrAtRuntime(mod)) {
4480 const ptr_info = param_ty.ptrInfo(mod);
4478 const zcu = pt.zcu;
4479 if (param_ty.isPtrAtRuntime(zcu)) {
4480 const ptr_info = param_ty.ptrInfo(zcu);
44814481 if (math.cast(u5, param_index)) |i| {
44824482 if (@as(u1, @truncate(fn_info.noalias_bits >> i)) != 0) {
44834483 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
44844484 }
44854485 }
4486 if (!param_ty.isPtrLikeOptional(mod) and !ptr_info.flags.is_allowzero) {
4486 if (!param_ty.isPtrLikeOptional(zcu) and !ptr_info.flags.is_allowzero) {
44874487 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
44884488 }
44894489 if (fn_info.cc == .Interrupt) {
......@@ -4496,9 +4496,9 @@ pub const Object = struct {
44964496 const elem_align = if (ptr_info.flags.alignment != .none)
44974497 ptr_info.flags.alignment
44984498 else
4499 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1");
4499 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1");
45004500 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align.toLlvm() }, &o.builder);
4501 } else if (ccAbiPromoteInt(fn_info.cc, mod, param_ty)) |s| switch (s) {
4501 } else if (ccAbiPromoteInt(fn_info.cc, zcu, param_ty)) |s| switch (s) {
45024502 .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder),
45034503 .unsigned => try attributes.addParamAttr(llvm_arg_i, .zeroext, &o.builder),
45044504 };
......@@ -4814,14 +4814,14 @@ pub const FuncGen = struct {
48144814
48154815 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {
48164816 const o = self.ng.object;
4817 const pt = o.pt;
4818 const ty = val.typeOf(pt.zcu);
4817 const zcu = o.pt.zcu;
4818 const ty = val.typeOf(zcu);
48194819 const llvm_val = try o.lowerValue(val.toIntern());
4820 if (!isByRef(ty, pt)) return llvm_val;
4820 if (!isByRef(ty, zcu)) return llvm_val;
48214821
48224822 // We have an LLVM value but we need to create a global constant and
48234823 // set the value as its initializer, and then return a pointer to the global.
4824 const target = pt.zcu.getTarget();
4824 const target = zcu.getTarget();
48254825 const variable_index = try o.builder.addVariable(
48264826 .empty,
48274827 llvm_val.typeOf(&o.builder),
......@@ -4831,7 +4831,7 @@ pub const FuncGen = struct {
48314831 variable_index.setLinkage(.private, &o.builder);
48324832 variable_index.setMutability(.constant, &o.builder);
48334833 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
4834 variable_index.setAlignment(ty.abiAlignment(pt).toLlvm(), &o.builder);
4834 variable_index.setAlignment(ty.abiAlignment(zcu).toLlvm(), &o.builder);
48354835 return o.builder.convConst(
48364836 variable_index.toConst(&o.builder),
48374837 try o.builder.ptrType(toLlvmAddressSpace(.generic, target)),
......@@ -4852,8 +4852,8 @@ pub const FuncGen = struct {
48524852
48534853 fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void {
48544854 const o = self.ng.object;
4855 const mod = o.pt.zcu;
4856 const ip = &mod.intern_pool;
4855 const zcu = o.pt.zcu;
4856 const ip = &zcu.intern_pool;
48574857 const air_tags = self.air.instructions.items(.tag);
48584858 for (body, 0..) |inst, i| {
48594859 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;
......@@ -5200,19 +5200,19 @@ pub const FuncGen = struct {
52005200 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
52015201 const o = self.ng.object;
52025202 const pt = o.pt;
5203 const mod = pt.zcu;
5204 const ip = &mod.intern_pool;
5203 const zcu = pt.zcu;
5204 const ip = &zcu.intern_pool;
52055205 const callee_ty = self.typeOf(pl_op.operand);
5206 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
5206 const zig_fn_ty = switch (callee_ty.zigTypeTag(zcu)) {
52075207 .Fn => callee_ty,
5208 .Pointer => callee_ty.childType(mod),
5208 .Pointer => callee_ty.childType(zcu),
52095209 else => unreachable,
52105210 };
5211 const fn_info = mod.typeToFunc(zig_fn_ty).?;
5211 const fn_info = zcu.typeToFunc(zig_fn_ty).?;
52125212 const return_type = Type.fromInterned(fn_info.return_type);
52135213 const llvm_fn = try self.resolveInst(pl_op.operand);
5214 const target = mod.getTarget();
5215 const sret = firstParamSRet(fn_info, pt, target);
5214 const target = zcu.getTarget();
5215 const sret = firstParamSRet(fn_info, zcu, target);
52165216
52175217 var llvm_args = std.ArrayList(Builder.Value).init(self.gpa);
52185218 defer llvm_args.deinit();
......@@ -5230,13 +5230,13 @@ pub const FuncGen = struct {
52305230 const llvm_ret_ty = try o.lowerType(return_type);
52315231 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);
52325232
5233 const alignment = return_type.abiAlignment(pt).toLlvm();
5233 const alignment = return_type.abiAlignment(zcu).toLlvm();
52345234 const ret_ptr = try self.buildAllocaWorkaround(return_type, alignment);
52355235 try llvm_args.append(ret_ptr);
52365236 break :blk ret_ptr;
52375237 };
52385238
5239 const err_return_tracing = return_type.isError(mod) and mod.comp.config.any_error_tracing;
5239 const err_return_tracing = return_type.isError(zcu) and zcu.comp.config.any_error_tracing;
52405240 if (err_return_tracing) {
52415241 assert(self.err_ret_trace != .none);
52425242 try llvm_args.append(self.err_ret_trace);
......@@ -5250,8 +5250,8 @@ pub const FuncGen = struct {
52505250 const param_ty = self.typeOf(arg);
52515251 const llvm_arg = try self.resolveInst(arg);
52525252 const llvm_param_ty = try o.lowerType(param_ty);
5253 if (isByRef(param_ty, pt)) {
5254 const alignment = param_ty.abiAlignment(pt).toLlvm();
5253 if (isByRef(param_ty, zcu)) {
5254 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52555255 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");
52565256 try llvm_args.append(loaded);
52575257 } else {
......@@ -5262,10 +5262,10 @@ pub const FuncGen = struct {
52625262 const arg = args[it.zig_index - 1];
52635263 const param_ty = self.typeOf(arg);
52645264 const llvm_arg = try self.resolveInst(arg);
5265 if (isByRef(param_ty, pt)) {
5265 if (isByRef(param_ty, zcu)) {
52665266 try llvm_args.append(llvm_arg);
52675267 } else {
5268 const alignment = param_ty.abiAlignment(pt).toLlvm();
5268 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52695269 const param_llvm_ty = llvm_arg.typeOfWip(&self.wip);
52705270 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);
52715271 _ = try self.wip.store(.normal, llvm_arg, arg_ptr, alignment);
......@@ -5277,10 +5277,10 @@ pub const FuncGen = struct {
52775277 const param_ty = self.typeOf(arg);
52785278 const llvm_arg = try self.resolveInst(arg);
52795279
5280 const alignment = param_ty.abiAlignment(pt).toLlvm();
5280 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52815281 const param_llvm_ty = try o.lowerType(param_ty);
52825282 const arg_ptr = try self.buildAllocaWorkaround(param_ty, alignment);
5283 if (isByRef(param_ty, pt)) {
5283 if (isByRef(param_ty, zcu)) {
52845284 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");
52855285 _ = try self.wip.store(.normal, loaded, arg_ptr, alignment);
52865286 } else {
......@@ -5292,16 +5292,16 @@ pub const FuncGen = struct {
52925292 const arg = args[it.zig_index - 1];
52935293 const param_ty = self.typeOf(arg);
52945294 const llvm_arg = try self.resolveInst(arg);
5295 const int_llvm_ty = try o.builder.intType(@intCast(param_ty.abiSize(pt) * 8));
5295 const int_llvm_ty = try o.builder.intType(@intCast(param_ty.abiSize(zcu) * 8));
52965296
5297 if (isByRef(param_ty, pt)) {
5298 const alignment = param_ty.abiAlignment(pt).toLlvm();
5297 if (isByRef(param_ty, zcu)) {
5298 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52995299 const loaded = try self.wip.load(.normal, int_llvm_ty, llvm_arg, alignment, "");
53005300 try llvm_args.append(loaded);
53015301 } else {
53025302 // LLVM does not allow bitcasting structs so we must allocate
53035303 // a local, store as one type, and then load as another type.
5304 const alignment = param_ty.abiAlignment(pt).toLlvm();
5304 const alignment = param_ty.abiAlignment(zcu).toLlvm();
53055305 const int_ptr = try self.buildAllocaWorkaround(param_ty, alignment);
53065306 _ = try self.wip.store(.normal, llvm_arg, int_ptr, alignment);
53075307 const loaded = try self.wip.load(.normal, int_llvm_ty, int_ptr, alignment, "");
......@@ -5320,9 +5320,9 @@ pub const FuncGen = struct {
53205320 const param_ty = self.typeOf(arg);
53215321 const llvm_types = it.types_buffer[0..it.types_len];
53225322 const llvm_arg = try self.resolveInst(arg);
5323 const is_by_ref = isByRef(param_ty, pt);
5323 const is_by_ref = isByRef(param_ty, zcu);
53245324 const arg_ptr = if (is_by_ref) llvm_arg else ptr: {
5325 const alignment = param_ty.abiAlignment(pt).toLlvm();
5325 const alignment = param_ty.abiAlignment(zcu).toLlvm();
53265326 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
53275327 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
53285328 break :ptr ptr;
......@@ -5348,14 +5348,14 @@ pub const FuncGen = struct {
53485348 const arg = args[it.zig_index - 1];
53495349 const arg_ty = self.typeOf(arg);
53505350 var llvm_arg = try self.resolveInst(arg);
5351 const alignment = arg_ty.abiAlignment(pt).toLlvm();
5352 if (!isByRef(arg_ty, pt)) {
5351 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
5352 if (!isByRef(arg_ty, zcu)) {
53535353 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
53545354 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
53555355 llvm_arg = ptr;
53565356 }
53575357
5358 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, mod).?);
5358 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);
53595359 const array_ty = try o.builder.arrayType(count, float_ty);
53605360
53615361 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");
......@@ -5366,8 +5366,8 @@ pub const FuncGen = struct {
53665366 const arg = args[it.zig_index - 1];
53675367 const arg_ty = self.typeOf(arg);
53685368 var llvm_arg = try self.resolveInst(arg);
5369 const alignment = arg_ty.abiAlignment(pt).toLlvm();
5370 if (!isByRef(arg_ty, pt)) {
5369 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
5370 if (!isByRef(arg_ty, zcu)) {
53715371 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
53725372 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
53735373 llvm_arg = ptr;
......@@ -5389,7 +5389,7 @@ pub const FuncGen = struct {
53895389 .byval => {
53905390 const param_index = it.zig_index - 1;
53915391 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
5392 if (!isByRef(param_ty, pt)) {
5392 if (!isByRef(param_ty, zcu)) {
53935393 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
53945394 }
53955395 },
......@@ -5397,7 +5397,7 @@ pub const FuncGen = struct {
53975397 const param_index = it.zig_index - 1;
53985398 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
53995399 const param_llvm_ty = try o.lowerType(param_ty);
5400 const alignment = param_ty.abiAlignment(pt).toLlvm();
5400 const alignment = param_ty.abiAlignment(zcu).toLlvm();
54015401 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
54025402 },
54035403 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
......@@ -5414,7 +5414,7 @@ pub const FuncGen = struct {
54145414 .slice => {
54155415 assert(!it.byval_attr);
54165416 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
5417 const ptr_info = param_ty.ptrInfo(mod);
5417 const ptr_info = param_ty.ptrInfo(zcu);
54185418 const llvm_arg_i = it.llvm_index - 2;
54195419
54205420 if (math.cast(u5, it.zig_index - 1)) |i| {
......@@ -5422,7 +5422,7 @@ pub const FuncGen = struct {
54225422 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
54235423 }
54245424 }
5425 if (param_ty.zigTypeTag(mod) != .Optional) {
5425 if (param_ty.zigTypeTag(zcu) != .Optional) {
54265426 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
54275427 }
54285428 if (ptr_info.flags.is_const) {
......@@ -5431,7 +5431,7 @@ pub const FuncGen = struct {
54315431 const elem_align = (if (ptr_info.flags.alignment != .none)
54325432 @as(InternPool.Alignment, ptr_info.flags.alignment)
54335433 else
5434 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1")).toLlvm();
5434 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1")).toLlvm();
54355435 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
54365436 },
54375437 };
......@@ -5456,17 +5456,17 @@ pub const FuncGen = struct {
54565456 return .none;
54575457 }
54585458
5459 if (self.liveness.isUnused(inst) or !return_type.hasRuntimeBitsIgnoreComptime(pt)) {
5459 if (self.liveness.isUnused(inst) or !return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
54605460 return .none;
54615461 }
54625462
54635463 const llvm_ret_ty = try o.lowerType(return_type);
54645464 if (ret_ptr) |rp| {
5465 if (isByRef(return_type, pt)) {
5465 if (isByRef(return_type, zcu)) {
54665466 return rp;
54675467 } else {
54685468 // our by-ref status disagrees with sret so we must load.
5469 const return_alignment = return_type.abiAlignment(pt).toLlvm();
5469 const return_alignment = return_type.abiAlignment(zcu).toLlvm();
54705470 return self.wip.load(.normal, llvm_ret_ty, rp, return_alignment, "");
54715471 }
54725472 }
......@@ -5477,19 +5477,19 @@ pub const FuncGen = struct {
54775477 // In this case the function return type is honoring the calling convention by having
54785478 // a different LLVM type than the usual one. We solve this here at the callsite
54795479 // by using our canonical type, then loading it if necessary.
5480 const alignment = return_type.abiAlignment(pt).toLlvm();
5480 const alignment = return_type.abiAlignment(zcu).toLlvm();
54815481 const rp = try self.buildAlloca(abi_ret_ty, alignment);
54825482 _ = try self.wip.store(.normal, call, rp, alignment);
5483 return if (isByRef(return_type, pt))
5483 return if (isByRef(return_type, zcu))
54845484 rp
54855485 else
54865486 try self.wip.load(.normal, llvm_ret_ty, rp, alignment, "");
54875487 }
54885488
5489 if (isByRef(return_type, pt)) {
5489 if (isByRef(return_type, zcu)) {
54905490 // our by-ref status disagrees with sret so we must allocate, store,
54915491 // and return the allocation pointer.
5492 const alignment = return_type.abiAlignment(pt).toLlvm();
5492 const alignment = return_type.abiAlignment(zcu).toLlvm();
54935493 const rp = try self.buildAlloca(llvm_ret_ty, alignment);
54945494 _ = try self.wip.store(.normal, call, rp, alignment);
54955495 return rp;
......@@ -5540,8 +5540,8 @@ pub const FuncGen = struct {
55405540 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
55415541 const o = self.ng.object;
55425542 const pt = o.pt;
5543 const mod = pt.zcu;
5544 const ip = &mod.intern_pool;
5543 const zcu = pt.zcu;
5544 const ip = &zcu.intern_pool;
55455545 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
55465546 const ret_ty = self.typeOf(un_op);
55475547
......@@ -5549,9 +5549,9 @@ pub const FuncGen = struct {
55495549 const ptr_ty = try pt.singleMutPtrType(ret_ty);
55505550
55515551 const operand = try self.resolveInst(un_op);
5552 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(mod) else false;
5552 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
55535553 if (val_is_undef and safety) undef: {
5554 const ptr_info = ptr_ty.ptrInfo(mod);
5554 const ptr_info = ptr_ty.ptrInfo(zcu);
55555555 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);
55565556 if (needs_bitmask) {
55575557 // TODO: only some bits are to be undef, we cannot write with a simple memset.
......@@ -5559,13 +5559,13 @@ pub const FuncGen = struct {
55595559 // https://github.com/ziglang/zig/issues/15337
55605560 break :undef;
55615561 }
5562 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(pt));
5562 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu));
55635563 _ = try self.wip.callMemSet(
55645564 self.ret_ptr,
5565 ptr_ty.ptrAlignment(pt).toLlvm(),
5565 ptr_ty.ptrAlignment(zcu).toLlvm(),
55665566 try o.builder.intValue(.i8, 0xaa),
55675567 len,
5568 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,
5568 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
55695569 );
55705570 const owner_mod = self.ng.ownerModule();
55715571 if (owner_mod.valgrind) {
......@@ -5588,9 +5588,9 @@ pub const FuncGen = struct {
55885588 _ = try self.wip.retVoid();
55895589 return .none;
55905590 }
5591 const fn_info = mod.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5592 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5593 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
5591 const fn_info = zcu.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5592 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5593 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
55945594 // Functions with an empty error set are emitted with an error code
55955595 // return type and return zero so they can be function pointers coerced
55965596 // to functions that return anyerror.
......@@ -5603,13 +5603,13 @@ pub const FuncGen = struct {
56035603
56045604 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
56055605 const operand = try self.resolveInst(un_op);
5606 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(mod) else false;
5607 const alignment = ret_ty.abiAlignment(pt).toLlvm();
5606 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
5607 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
56085608
56095609 if (val_is_undef and safety) {
56105610 const llvm_ret_ty = operand.typeOfWip(&self.wip);
56115611 const rp = try self.buildAlloca(llvm_ret_ty, alignment);
5612 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(pt));
5612 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu));
56135613 _ = try self.wip.callMemSet(
56145614 rp,
56155615 alignment,
......@@ -5625,7 +5625,7 @@ pub const FuncGen = struct {
56255625 return .none;
56265626 }
56275627
5628 if (isByRef(ret_ty, pt)) {
5628 if (isByRef(ret_ty, zcu)) {
56295629 // operand is a pointer however self.ret_ptr is null so that means
56305630 // we need to return a value.
56315631 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, operand, alignment, ""));
......@@ -5647,14 +5647,14 @@ pub const FuncGen = struct {
56475647 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
56485648 const o = self.ng.object;
56495649 const pt = o.pt;
5650 const mod = pt.zcu;
5651 const ip = &mod.intern_pool;
5650 const zcu = pt.zcu;
5651 const ip = &zcu.intern_pool;
56525652 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
56535653 const ptr_ty = self.typeOf(un_op);
5654 const ret_ty = ptr_ty.childType(mod);
5655 const fn_info = mod.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5656 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5657 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
5654 const ret_ty = ptr_ty.childType(zcu);
5655 const fn_info = zcu.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5656 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5657 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
56585658 // Functions with an empty error set are emitted with an error code
56595659 // return type and return zero so they can be function pointers coerced
56605660 // to functions that return anyerror.
......@@ -5670,7 +5670,7 @@ pub const FuncGen = struct {
56705670 }
56715671 const ptr = try self.resolveInst(un_op);
56725672 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5673 const alignment = ret_ty.abiAlignment(pt).toLlvm();
5673 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
56745674 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));
56755675 return .none;
56765676 }
......@@ -5688,16 +5688,17 @@ pub const FuncGen = struct {
56885688 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
56895689 const o = self.ng.object;
56905690 const pt = o.pt;
5691 const zcu = pt.zcu;
56915692 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56925693 const src_list = try self.resolveInst(ty_op.operand);
56935694 const va_list_ty = ty_op.ty.toType();
56945695 const llvm_va_list_ty = try o.lowerType(va_list_ty);
56955696
5696 const result_alignment = va_list_ty.abiAlignment(pt).toLlvm();
5697 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
56975698 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);
56985699
56995700 _ = try self.wip.callIntrinsic(.normal, .none, .va_copy, &.{}, &.{ dest_list, src_list }, "");
5700 return if (isByRef(va_list_ty, pt))
5701 return if (isByRef(va_list_ty, zcu))
57015702 dest_list
57025703 else
57035704 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");
......@@ -5714,14 +5715,15 @@ pub const FuncGen = struct {
57145715 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57155716 const o = self.ng.object;
57165717 const pt = o.pt;
5718 const zcu = pt.zcu;
57175719 const va_list_ty = self.typeOfIndex(inst);
57185720 const llvm_va_list_ty = try o.lowerType(va_list_ty);
57195721
5720 const result_alignment = va_list_ty.abiAlignment(pt).toLlvm();
5722 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
57215723 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);
57225724
57235725 _ = try self.wip.callIntrinsic(.normal, .none, .va_start, &.{}, &.{dest_list}, "");
5724 return if (isByRef(va_list_ty, pt))
5726 return if (isByRef(va_list_ty, zcu))
57255727 dest_list
57265728 else
57275729 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");
......@@ -5779,21 +5781,21 @@ pub const FuncGen = struct {
57795781 ) Allocator.Error!Builder.Value {
57805782 const o = self.ng.object;
57815783 const pt = o.pt;
5782 const mod = pt.zcu;
5783 const scalar_ty = operand_ty.scalarType(mod);
5784 const int_ty = switch (scalar_ty.zigTypeTag(mod)) {
5785 .Enum => scalar_ty.intTagType(mod),
5784 const zcu = pt.zcu;
5785 const scalar_ty = operand_ty.scalarType(zcu);
5786 const int_ty = switch (scalar_ty.zigTypeTag(zcu)) {
5787 .Enum => scalar_ty.intTagType(zcu),
57865788 .Int, .Bool, .Pointer, .ErrorSet => scalar_ty,
57875789 .Optional => blk: {
5788 const payload_ty = operand_ty.optionalChild(mod);
5789 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt) or
5790 operand_ty.optionalReprIsPayload(mod))
5790 const payload_ty = operand_ty.optionalChild(zcu);
5791 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu) or
5792 operand_ty.optionalReprIsPayload(zcu))
57915793 {
57925794 break :blk operand_ty;
57935795 }
57945796 // We need to emit instructions to check for equality/inequality
57955797 // of optionals that are not pointers.
5796 const is_by_ref = isByRef(scalar_ty, pt);
5798 const is_by_ref = isByRef(scalar_ty, zcu);
57975799 const opt_llvm_ty = try o.lowerType(scalar_ty);
57985800 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref);
57995801 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref);
......@@ -5860,7 +5862,7 @@ pub const FuncGen = struct {
58605862 .Float => return self.buildFloatCmp(fast, op, operand_ty, .{ lhs, rhs }),
58615863 else => unreachable,
58625864 };
5863 const is_signed = int_ty.isSignedInt(mod);
5865 const is_signed = int_ty.isSignedInt(zcu);
58645866 const cond: Builder.IntegerCondition = switch (op) {
58655867 .eq => .eq,
58665868 .neq => .ne,
......@@ -5886,15 +5888,15 @@ pub const FuncGen = struct {
58865888 ) !Builder.Value {
58875889 const o = self.ng.object;
58885890 const pt = o.pt;
5889 const mod = pt.zcu;
5891 const zcu = pt.zcu;
58905892 const inst_ty = self.typeOfIndex(inst);
58915893
5892 if (inst_ty.isNoReturn(mod)) {
5894 if (inst_ty.isNoReturn(zcu)) {
58935895 try self.genBodyDebugScope(maybe_inline_func, body);
58945896 return .none;
58955897 }
58965898
5897 const have_block_result = inst_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt);
5899 const have_block_result = inst_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu);
58985900
58995901 var breaks: BreakList = if (have_block_result) .{ .list = .{} } else .{ .len = 0 };
59005902 defer if (have_block_result) breaks.list.deinit(self.gpa);
......@@ -5918,7 +5920,7 @@ pub const FuncGen = struct {
59185920 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead
59195921 // of function pointers, however the phi makes it a runtime value and therefore
59205922 // the LLVM type has to be wrapped in a pointer.
5921 if (inst_ty.zigTypeTag(mod) == .Fn or isByRef(inst_ty, pt)) {
5923 if (inst_ty.zigTypeTag(zcu) == .Fn or isByRef(inst_ty, zcu)) {
59225924 break :ty .ptr;
59235925 }
59245926 break :ty raw_llvm_ty;
......@@ -5936,13 +5938,13 @@ pub const FuncGen = struct {
59365938
59375939 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
59385940 const o = self.ng.object;
5939 const pt = o.pt;
5941 const zcu = o.pt.zcu;
59405942 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
59415943 const block = self.blocks.get(branch.block_inst).?;
59425944
59435945 // Add the values to the lists only if the break provides a value.
59445946 const operand_ty = self.typeOf(branch.operand);
5945 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
5947 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
59465948 const val = try self.resolveInst(branch.operand);
59475949
59485950 // For the phi node, we need the basic blocks and the values of the
......@@ -5977,6 +5979,7 @@ pub const FuncGen = struct {
59775979 fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
59785980 const o = self.ng.object;
59795981 const pt = o.pt;
5982 const zcu = pt.zcu;
59805983 const inst = body_tail[0];
59815984 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
59825985 const err_union = try self.resolveInst(pl_op.operand);
......@@ -5984,19 +5987,19 @@ pub const FuncGen = struct {
59845987 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
59855988 const err_union_ty = self.typeOf(pl_op.operand);
59865989 const payload_ty = self.typeOfIndex(inst);
5987 const can_elide_load = if (isByRef(payload_ty, pt)) self.canElideLoad(body_tail) else false;
5990 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;
59885991 const is_unused = self.liveness.isUnused(inst);
59895992 return lowerTry(self, err_union, body, err_union_ty, false, can_elide_load, is_unused);
59905993 }
59915994
59925995 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
59935996 const o = self.ng.object;
5994 const mod = o.pt.zcu;
5997 const zcu = o.pt.zcu;
59955998 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
59965999 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
59976000 const err_union_ptr = try self.resolveInst(extra.data.ptr);
59986001 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
5999 const err_union_ty = self.typeOf(extra.data.ptr).childType(mod);
6002 const err_union_ty = self.typeOf(extra.data.ptr).childType(zcu);
60006003 const is_unused = self.liveness.isUnused(inst);
60016004 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);
60026005 }
......@@ -6012,13 +6015,13 @@ pub const FuncGen = struct {
60126015 ) !Builder.Value {
60136016 const o = fg.ng.object;
60146017 const pt = o.pt;
6015 const mod = pt.zcu;
6016 const payload_ty = err_union_ty.errorUnionPayload(mod);
6017 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(pt);
6018 const zcu = pt.zcu;
6019 const payload_ty = err_union_ty.errorUnionPayload(zcu);
6020 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
60186021 const err_union_llvm_ty = try o.lowerType(err_union_ty);
60196022 const error_type = try o.errorIntType();
60206023
6021 if (!err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
6024 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
60226025 const loaded = loaded: {
60236026 if (!payload_has_bits) {
60246027 // TODO add alignment to this load
......@@ -6028,7 +6031,7 @@ pub const FuncGen = struct {
60286031 err_union;
60296032 }
60306033 const err_field_index = try errUnionErrorOffset(payload_ty, pt);
6031 if (operand_is_ptr or isByRef(err_union_ty, pt)) {
6034 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
60326035 const err_field_ptr =
60336036 try fg.wip.gepStruct(err_union_llvm_ty, err_union, err_field_index, "");
60346037 // TODO add alignment to this load
......@@ -6059,10 +6062,10 @@ pub const FuncGen = struct {
60596062 const offset = try errUnionPayloadOffset(payload_ty, pt);
60606063 if (operand_is_ptr) {
60616064 return fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");
6062 } else if (isByRef(err_union_ty, pt)) {
6065 } else if (isByRef(err_union_ty, zcu)) {
60636066 const payload_ptr = try fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");
6064 const payload_alignment = payload_ty.abiAlignment(pt).toLlvm();
6065 if (isByRef(payload_ty, pt)) {
6067 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
6068 if (isByRef(payload_ty, zcu)) {
60666069 if (can_elide_load)
60676070 return payload_ptr;
60686071
......@@ -6140,7 +6143,7 @@ pub const FuncGen = struct {
61406143
61416144 fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
61426145 const o = self.ng.object;
6143 const mod = o.pt.zcu;
6146 const zcu = o.pt.zcu;
61446147 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
61456148 const loop = self.air.extraData(Air.Block, ty_pl.payload);
61466149 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
......@@ -6156,7 +6159,7 @@ pub const FuncGen = struct {
61566159 // would have been emitted already. Also the main loop in genBody can
61576160 // be while(true) instead of for(body), which will eliminate 1 branch on
61586161 // a hot path.
6159 if (body.len == 0 or !self.typeOfIndex(body[body.len - 1]).isNoReturn(mod)) {
6162 if (body.len == 0 or !self.typeOfIndex(body[body.len - 1]).isNoReturn(zcu)) {
61606163 _ = try self.wip.br(loop_block);
61616164 }
61626165 return .none;
......@@ -6165,15 +6168,15 @@ pub const FuncGen = struct {
61656168 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
61666169 const o = self.ng.object;
61676170 const pt = o.pt;
6168 const mod = pt.zcu;
6171 const zcu = pt.zcu;
61696172 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61706173 const operand_ty = self.typeOf(ty_op.operand);
6171 const array_ty = operand_ty.childType(mod);
6174 const array_ty = operand_ty.childType(zcu);
61726175 const llvm_usize = try o.lowerType(Type.usize);
6173 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(mod));
6176 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu));
61746177 const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
61756178 const operand = try self.resolveInst(ty_op.operand);
6176 if (!array_ty.hasRuntimeBitsIgnoreComptime(pt))
6179 if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
61776180 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");
61786181 const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{
61796182 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),
......@@ -6184,17 +6187,17 @@ pub const FuncGen = struct {
61846187 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
61856188 const o = self.ng.object;
61866189 const pt = o.pt;
6187 const mod = pt.zcu;
6190 const zcu = pt.zcu;
61886191 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61896192
61906193 const workaround_operand = try self.resolveInst(ty_op.operand);
61916194 const operand_ty = self.typeOf(ty_op.operand);
6192 const operand_scalar_ty = operand_ty.scalarType(mod);
6193 const is_signed_int = operand_scalar_ty.isSignedInt(mod);
6195 const operand_scalar_ty = operand_ty.scalarType(zcu);
6196 const is_signed_int = operand_scalar_ty.isSignedInt(zcu);
61946197
61956198 const operand = o: {
61966199 // Work around LLVM bug. See https://github.com/ziglang/zig/issues/17381.
6197 const bit_size = operand_scalar_ty.bitSize(pt);
6200 const bit_size = operand_scalar_ty.bitSize(zcu);
61986201 for ([_]u8{ 8, 16, 32, 64, 128 }) |b| {
61996202 if (bit_size < b) {
62006203 break :o try self.wip.cast(
......@@ -6211,9 +6214,9 @@ pub const FuncGen = struct {
62116214 };
62126215
62136216 const dest_ty = self.typeOfIndex(inst);
6214 const dest_scalar_ty = dest_ty.scalarType(mod);
6217 const dest_scalar_ty = dest_ty.scalarType(zcu);
62156218 const dest_llvm_ty = try o.lowerType(dest_ty);
6216 const target = mod.getTarget();
6219 const target = zcu.getTarget();
62176220
62186221 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(
62196222 if (is_signed_int) .signed else .unsigned,
......@@ -6222,7 +6225,7 @@ pub const FuncGen = struct {
62226225 "",
62236226 );
62246227
6225 const rt_int_bits = compilerRtIntBits(@intCast(operand_scalar_ty.bitSize(pt)));
6228 const rt_int_bits = compilerRtIntBits(@intCast(operand_scalar_ty.bitSize(zcu)));
62266229 const rt_int_ty = try o.builder.intType(rt_int_bits);
62276230 var extended = try self.wip.conv(
62286231 if (is_signed_int) .signed else .unsigned,
......@@ -6269,29 +6272,29 @@ pub const FuncGen = struct {
62696272
62706273 const o = self.ng.object;
62716274 const pt = o.pt;
6272 const mod = pt.zcu;
6273 const target = mod.getTarget();
6275 const zcu = pt.zcu;
6276 const target = zcu.getTarget();
62746277 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
62756278
62766279 const operand = try self.resolveInst(ty_op.operand);
62776280 const operand_ty = self.typeOf(ty_op.operand);
6278 const operand_scalar_ty = operand_ty.scalarType(mod);
6281 const operand_scalar_ty = operand_ty.scalarType(zcu);
62796282
62806283 const dest_ty = self.typeOfIndex(inst);
6281 const dest_scalar_ty = dest_ty.scalarType(mod);
6284 const dest_scalar_ty = dest_ty.scalarType(zcu);
62826285 const dest_llvm_ty = try o.lowerType(dest_ty);
62836286
62846287 if (intrinsicsAllowed(operand_scalar_ty, target)) {
62856288 // TODO set fast math flag
62866289 return self.wip.conv(
6287 if (dest_scalar_ty.isSignedInt(mod)) .signed else .unsigned,
6290 if (dest_scalar_ty.isSignedInt(zcu)) .signed else .unsigned,
62886291 operand,
62896292 dest_llvm_ty,
62906293 "",
62916294 );
62926295 }
62936296
6294 const rt_int_bits = compilerRtIntBits(@intCast(dest_scalar_ty.bitSize(pt)));
6297 const rt_int_bits = compilerRtIntBits(@intCast(dest_scalar_ty.bitSize(zcu)));
62956298 const ret_ty = try o.builder.intType(rt_int_bits);
62966299 const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: {
62976300 // On Windows x86-64, "ti" functions must use Vector(2, u64) instead of the standard
......@@ -6303,7 +6306,7 @@ pub const FuncGen = struct {
63036306 const compiler_rt_operand_abbrev = compilerRtFloatAbbrev(operand_bits);
63046307
63056308 const compiler_rt_dest_abbrev = compilerRtIntAbbrev(rt_int_bits);
6306 const sign_prefix = if (dest_scalar_ty.isSignedInt(mod)) "" else "uns";
6309 const sign_prefix = if (dest_scalar_ty.isSignedInt(zcu)) "" else "uns";
63076310
63086311 const fn_name = try o.builder.strtabStringFmt("__fix{s}{s}f{s}i", .{
63096312 sign_prefix,
......@@ -6330,29 +6333,29 @@ pub const FuncGen = struct {
63306333
63316334 fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
63326335 const o = fg.ng.object;
6333 const mod = o.pt.zcu;
6334 return if (ty.isSlice(mod)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
6336 const zcu = o.pt.zcu;
6337 return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
63356338 }
63366339
63376340 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
63386341 const o = fg.ng.object;
63396342 const pt = o.pt;
6340 const mod = pt.zcu;
6343 const zcu = pt.zcu;
63416344 const llvm_usize = try o.lowerType(Type.usize);
6342 switch (ty.ptrSize(mod)) {
6345 switch (ty.ptrSize(zcu)) {
63436346 .Slice => {
63446347 const len = try fg.wip.extractValue(ptr, &.{1}, "");
6345 const elem_ty = ty.childType(mod);
6346 const abi_size = elem_ty.abiSize(pt);
6348 const elem_ty = ty.childType(zcu);
6349 const abi_size = elem_ty.abiSize(zcu);
63476350 if (abi_size == 1) return len;
63486351 const abi_size_llvm_val = try o.builder.intValue(llvm_usize, abi_size);
63496352 return fg.wip.bin(.@"mul nuw", len, abi_size_llvm_val, "");
63506353 },
63516354 .One => {
6352 const array_ty = ty.childType(mod);
6353 const elem_ty = array_ty.childType(mod);
6354 const abi_size = elem_ty.abiSize(pt);
6355 return o.builder.intValue(llvm_usize, array_ty.arrayLen(mod) * abi_size);
6355 const array_ty = ty.childType(zcu);
6356 const elem_ty = array_ty.childType(zcu);
6357 const abi_size = elem_ty.abiSize(zcu);
6358 return o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu) * abi_size);
63566359 },
63576360 .Many, .C => unreachable,
63586361 }
......@@ -6366,11 +6369,11 @@ pub const FuncGen = struct {
63666369
63676370 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
63686371 const o = self.ng.object;
6369 const mod = o.pt.zcu;
6372 const zcu = o.pt.zcu;
63706373 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63716374 const slice_ptr = try self.resolveInst(ty_op.operand);
63726375 const slice_ptr_ty = self.typeOf(ty_op.operand);
6373 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(mod));
6376 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(zcu));
63746377
63756378 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");
63766379 }
......@@ -6378,21 +6381,21 @@ pub const FuncGen = struct {
63786381 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
63796382 const o = self.ng.object;
63806383 const pt = o.pt;
6381 const mod = pt.zcu;
6384 const zcu = pt.zcu;
63826385 const inst = body_tail[0];
63836386 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
63846387 const slice_ty = self.typeOf(bin_op.lhs);
63856388 const slice = try self.resolveInst(bin_op.lhs);
63866389 const index = try self.resolveInst(bin_op.rhs);
6387 const elem_ty = slice_ty.childType(mod);
6390 const elem_ty = slice_ty.childType(zcu);
63886391 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
63896392 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
63906393 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
6391 if (isByRef(elem_ty, pt)) {
6394 if (isByRef(elem_ty, zcu)) {
63926395 if (self.canElideLoad(body_tail))
63936396 return ptr;
63946397
6395 const elem_alignment = elem_ty.abiAlignment(pt).toLlvm();
6398 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
63966399 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);
63976400 }
63986401
......@@ -6401,14 +6404,14 @@ pub const FuncGen = struct {
64016404
64026405 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
64036406 const o = self.ng.object;
6404 const mod = o.pt.zcu;
6407 const zcu = o.pt.zcu;
64056408 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
64066409 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
64076410 const slice_ty = self.typeOf(bin_op.lhs);
64086411
64096412 const slice = try self.resolveInst(bin_op.lhs);
64106413 const index = try self.resolveInst(bin_op.rhs);
6411 const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(mod));
6414 const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(zcu));
64126415 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
64136416 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
64146417 }
......@@ -6416,7 +6419,7 @@ pub const FuncGen = struct {
64166419 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
64176420 const o = self.ng.object;
64186421 const pt = o.pt;
6419 const mod = pt.zcu;
6422 const zcu = pt.zcu;
64206423 const inst = body_tail[0];
64216424
64226425 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
......@@ -6424,16 +6427,16 @@ pub const FuncGen = struct {
64246427 const array_llvm_val = try self.resolveInst(bin_op.lhs);
64256428 const rhs = try self.resolveInst(bin_op.rhs);
64266429 const array_llvm_ty = try o.lowerType(array_ty);
6427 const elem_ty = array_ty.childType(mod);
6428 if (isByRef(array_ty, pt)) {
6430 const elem_ty = array_ty.childType(zcu);
6431 if (isByRef(array_ty, zcu)) {
64296432 const indices: [2]Builder.Value = .{
64306433 try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs,
64316434 };
6432 if (isByRef(elem_ty, pt)) {
6435 if (isByRef(elem_ty, zcu)) {
64336436 const elem_ptr =
64346437 try self.wip.gep(.inbounds, array_llvm_ty, array_llvm_val, &indices, "");
64356438 if (canElideLoad(self, body_tail)) return elem_ptr;
6436 const elem_alignment = elem_ty.abiAlignment(pt).toLlvm();
6439 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
64376440 return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal);
64386441 } else {
64396442 const elem_ptr =
......@@ -6449,23 +6452,23 @@ pub const FuncGen = struct {
64496452 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
64506453 const o = self.ng.object;
64516454 const pt = o.pt;
6452 const mod = pt.zcu;
6455 const zcu = pt.zcu;
64536456 const inst = body_tail[0];
64546457 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
64556458 const ptr_ty = self.typeOf(bin_op.lhs);
6456 const elem_ty = ptr_ty.childType(mod);
6459 const elem_ty = ptr_ty.childType(zcu);
64576460 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
64586461 const base_ptr = try self.resolveInst(bin_op.lhs);
64596462 const rhs = try self.resolveInst(bin_op.rhs);
64606463 // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch
6461 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(mod))
6464 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
64626465 // If this is a single-item pointer to an array, we need another index in the GEP.
64636466 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
64646467 else
64656468 &.{rhs}, "");
6466 if (isByRef(elem_ty, pt)) {
6469 if (isByRef(elem_ty, zcu)) {
64676470 if (self.canElideLoad(body_tail)) return ptr;
6468 const elem_alignment = elem_ty.abiAlignment(pt).toLlvm();
6471 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
64696472 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);
64706473 }
64716474
......@@ -6475,21 +6478,21 @@ pub const FuncGen = struct {
64756478 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
64766479 const o = self.ng.object;
64776480 const pt = o.pt;
6478 const mod = pt.zcu;
6481 const zcu = pt.zcu;
64796482 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
64806483 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
64816484 const ptr_ty = self.typeOf(bin_op.lhs);
6482 const elem_ty = ptr_ty.childType(mod);
6483 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return self.resolveInst(bin_op.lhs);
6485 const elem_ty = ptr_ty.childType(zcu);
6486 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return self.resolveInst(bin_op.lhs);
64846487
64856488 const base_ptr = try self.resolveInst(bin_op.lhs);
64866489 const rhs = try self.resolveInst(bin_op.rhs);
64876490
64886491 const elem_ptr = ty_pl.ty.toType();
6489 if (elem_ptr.ptrInfo(mod).flags.vector_index != .none) return base_ptr;
6492 if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr;
64906493
64916494 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6492 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(mod))
6495 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
64936496 // If this is a single-item pointer to an array, we need another index in the GEP.
64946497 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
64956498 else
......@@ -6518,35 +6521,35 @@ pub const FuncGen = struct {
65186521 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
65196522 const o = self.ng.object;
65206523 const pt = o.pt;
6521 const mod = pt.zcu;
6524 const zcu = pt.zcu;
65226525 const inst = body_tail[0];
65236526 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
65246527 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
65256528 const struct_ty = self.typeOf(struct_field.struct_operand);
65266529 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);
65276530 const field_index = struct_field.field_index;
6528 const field_ty = struct_ty.structFieldType(field_index, mod);
6529 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
6531 const field_ty = struct_ty.structFieldType(field_index, zcu);
6532 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
65306533
6531 if (!isByRef(struct_ty, pt)) {
6532 assert(!isByRef(field_ty, pt));
6533 switch (struct_ty.zigTypeTag(mod)) {
6534 .Struct => switch (struct_ty.containerLayout(mod)) {
6534 if (!isByRef(struct_ty, zcu)) {
6535 assert(!isByRef(field_ty, zcu));
6536 switch (struct_ty.zigTypeTag(zcu)) {
6537 .Struct => switch (struct_ty.containerLayout(zcu)) {
65356538 .@"packed" => {
6536 const struct_type = mod.typeToStruct(struct_ty).?;
6539 const struct_type = zcu.typeToStruct(struct_ty).?;
65376540 const bit_offset = pt.structPackedFieldBitOffset(struct_type, field_index);
65386541 const containing_int = struct_llvm_val;
65396542 const shift_amt =
65406543 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);
65416544 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
65426545 const elem_llvm_ty = try o.lowerType(field_ty);
6543 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {
6544 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));
6546 if (field_ty.zigTypeTag(zcu) == .Float or field_ty.zigTypeTag(zcu) == .Vector) {
6547 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65456548 const truncated_int =
65466549 try self.wip.cast(.trunc, shifted_value, same_size_int, "");
65476550 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");
6548 } else if (field_ty.isPtrAtRuntime(mod)) {
6549 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));
6551 } else if (field_ty.isPtrAtRuntime(zcu)) {
6552 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65506553 const truncated_int =
65516554 try self.wip.cast(.trunc, shifted_value, same_size_int, "");
65526555 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
......@@ -6559,16 +6562,16 @@ pub const FuncGen = struct {
65596562 },
65606563 },
65616564 .Union => {
6562 assert(struct_ty.containerLayout(mod) == .@"packed");
6565 assert(struct_ty.containerLayout(zcu) == .@"packed");
65636566 const containing_int = struct_llvm_val;
65646567 const elem_llvm_ty = try o.lowerType(field_ty);
6565 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {
6566 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));
6568 if (field_ty.zigTypeTag(zcu) == .Float or field_ty.zigTypeTag(zcu) == .Vector) {
6569 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65676570 const truncated_int =
65686571 try self.wip.cast(.trunc, containing_int, same_size_int, "");
65696572 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");
6570 } else if (field_ty.isPtrAtRuntime(mod)) {
6571 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));
6573 } else if (field_ty.isPtrAtRuntime(zcu)) {
6574 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65726575 const truncated_int =
65736576 try self.wip.cast(.trunc, containing_int, same_size_int, "");
65746577 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
......@@ -6579,20 +6582,20 @@ pub const FuncGen = struct {
65796582 }
65806583 }
65816584
6582 switch (struct_ty.zigTypeTag(mod)) {
6585 switch (struct_ty.zigTypeTag(zcu)) {
65836586 .Struct => {
6584 const layout = struct_ty.containerLayout(mod);
6587 const layout = struct_ty.containerLayout(zcu);
65856588 assert(layout != .@"packed");
65866589 const struct_llvm_ty = try o.lowerType(struct_ty);
65876590 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
65886591 const field_ptr =
65896592 try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, "");
6590 const alignment = struct_ty.structFieldAlign(field_index, pt);
6593 const alignment = struct_ty.structFieldAlign(field_index, zcu);
65916594 const field_ptr_ty = try pt.ptrType(.{
65926595 .child = field_ty.toIntern(),
65936596 .flags = .{ .alignment = alignment },
65946597 });
6595 if (isByRef(field_ty, pt)) {
6598 if (isByRef(field_ty, zcu)) {
65966599 if (canElideLoad(self, body_tail))
65976600 return field_ptr;
65986601
......@@ -6605,12 +6608,12 @@ pub const FuncGen = struct {
66056608 },
66066609 .Union => {
66076610 const union_llvm_ty = try o.lowerType(struct_ty);
6608 const layout = struct_ty.unionGetLayout(pt);
6611 const layout = struct_ty.unionGetLayout(zcu);
66096612 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
66106613 const field_ptr =
66116614 try self.wip.gepStruct(union_llvm_ty, struct_llvm_val, payload_index, "");
66126615 const payload_alignment = layout.payload_align.toLlvm();
6613 if (isByRef(field_ty, pt)) {
6616 if (isByRef(field_ty, zcu)) {
66146617 if (canElideLoad(self, body_tail)) return field_ptr;
66156618 return self.loadByRef(field_ptr, field_ty, payload_alignment, .normal);
66166619 } else {
......@@ -6624,14 +6627,14 @@ pub const FuncGen = struct {
66246627 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66256628 const o = self.ng.object;
66266629 const pt = o.pt;
6627 const mod = pt.zcu;
6630 const zcu = pt.zcu;
66286631 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
66296632 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
66306633
66316634 const field_ptr = try self.resolveInst(extra.field_ptr);
66326635
6633 const parent_ty = ty_pl.ty.toType().childType(mod);
6634 const field_offset = parent_ty.structFieldOffset(extra.field_index, pt);
6636 const parent_ty = ty_pl.ty.toType().childType(zcu);
6637 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
66356638 if (field_offset == 0) return field_ptr;
66366639
66376640 const res_ty = try o.lowerType(ty_pl.ty.toType());
......@@ -6686,7 +6689,7 @@ pub const FuncGen = struct {
66866689
66876690 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66886691 const o = self.ng.object;
6689 const mod = o.pt.zcu;
6692 const zcu = o.pt.zcu;
66906693 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
66916694 const operand = try self.resolveInst(pl_op.operand);
66926695 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
......@@ -6697,7 +6700,7 @@ pub const FuncGen = struct {
66976700 self.file,
66986701 self.scope,
66996702 self.prev_dbg_line,
6700 try o.lowerDebugType(ptr_ty.childType(mod)),
6703 try o.lowerDebugType(ptr_ty.childType(zcu)),
67016704 );
67026705
67036706 _ = try self.wip.callIntrinsic(
......@@ -6741,9 +6744,9 @@ pub const FuncGen = struct {
67416744 try o.lowerDebugType(operand_ty),
67426745 );
67436746
6744 const pt = o.pt;
6747 const zcu = o.pt.zcu;
67456748 const owner_mod = self.ng.ownerModule();
6746 if (isByRef(operand_ty, pt)) {
6749 if (isByRef(operand_ty, zcu)) {
67476750 _ = try self.wip.callIntrinsic(
67486751 .normal,
67496752 .none,
......@@ -6760,7 +6763,7 @@ pub const FuncGen = struct {
67606763 // We avoid taking this path for naked functions because there's no guarantee that such
67616764 // functions even have a valid stack pointer, making the `alloca` + `store` unsafe.
67626765
6763 const alignment = operand_ty.abiAlignment(pt).toLlvm();
6766 const alignment = operand_ty.abiAlignment(zcu).toLlvm();
67646767 const alloca = try self.buildAlloca(operand.typeOfWip(&self.wip), alignment);
67656768 _ = try self.wip.store(.normal, operand, alloca, alignment);
67666769 _ = try self.wip.callIntrinsic(
......@@ -6832,8 +6835,8 @@ pub const FuncGen = struct {
68326835 // if so, the element type itself.
68336836 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);
68346837 const pt = o.pt;
6835 const mod = pt.zcu;
6836 const target = mod.getTarget();
6838 const zcu = pt.zcu;
6839 const target = zcu.getTarget();
68376840
68386841 var llvm_ret_i: usize = 0;
68396842 var llvm_param_i: usize = 0;
......@@ -6860,8 +6863,8 @@ pub const FuncGen = struct {
68606863 if (output != .none) {
68616864 const output_inst = try self.resolveInst(output);
68626865 const output_ty = self.typeOf(output);
6863 assert(output_ty.zigTypeTag(mod) == .Pointer);
6864 const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(mod));
6866 assert(output_ty.zigTypeTag(zcu) == .Pointer);
6867 const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(zcu));
68656868
68666869 switch (constraint[0]) {
68676870 '=' => {},
......@@ -6932,13 +6935,13 @@ pub const FuncGen = struct {
69326935
69336936 const arg_llvm_value = try self.resolveInst(input);
69346937 const arg_ty = self.typeOf(input);
6935 const is_by_ref = isByRef(arg_ty, pt);
6938 const is_by_ref = isByRef(arg_ty, zcu);
69366939 if (is_by_ref) {
69376940 if (constraintAllowsMemory(constraint)) {
69386941 llvm_param_values[llvm_param_i] = arg_llvm_value;
69396942 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
69406943 } else {
6941 const alignment = arg_ty.abiAlignment(pt).toLlvm();
6944 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
69426945 const arg_llvm_ty = try o.lowerType(arg_ty);
69436946 const load_inst =
69446947 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");
......@@ -6950,7 +6953,7 @@ pub const FuncGen = struct {
69506953 llvm_param_values[llvm_param_i] = arg_llvm_value;
69516954 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
69526955 } else {
6953 const alignment = arg_ty.abiAlignment(pt).toLlvm();
6956 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
69546957 const arg_ptr = try self.buildAlloca(arg_llvm_value.typeOfWip(&self.wip), alignment);
69556958 _ = try self.wip.store(.normal, arg_llvm_value, arg_ptr, alignment);
69566959 llvm_param_values[llvm_param_i] = arg_ptr;
......@@ -6978,7 +6981,7 @@ pub const FuncGen = struct {
69786981 // In the case of indirect inputs, LLVM requires the callsite to have
69796982 // an elementtype(<ty>) attribute.
69806983 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*')
6981 try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(mod))
6984 try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(zcu))
69826985 else
69836986 .none;
69846987
......@@ -6997,12 +7000,12 @@ pub const FuncGen = struct {
69977000 if (constraint[0] != '+') continue;
69987001
69997002 const rw_ty = self.typeOf(output);
7000 const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(mod));
7003 const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(zcu));
70017004 if (is_indirect) {
70027005 llvm_param_values[llvm_param_i] = llvm_rw_val;
70037006 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);
70047007 } else {
7005 const alignment = rw_ty.abiAlignment(pt).toLlvm();
7008 const alignment = rw_ty.abiAlignment(zcu).toLlvm();
70067009 const loaded = try self.wip.load(.normal, llvm_elem_ty, llvm_rw_val, alignment, "");
70077010 llvm_param_values[llvm_param_i] = loaded;
70087011 llvm_param_types[llvm_param_i] = llvm_elem_ty;
......@@ -7163,7 +7166,7 @@ pub const FuncGen = struct {
71637166 const output_ptr = try self.resolveInst(output);
71647167 const output_ptr_ty = self.typeOf(output);
71657168
7166 const alignment = output_ptr_ty.ptrAlignment(pt).toLlvm();
7169 const alignment = output_ptr_ty.ptrAlignment(zcu).toLlvm();
71677170 _ = try self.wip.store(.normal, output_value, output_ptr, alignment);
71687171 } else {
71697172 ret_val = output_value;
......@@ -7182,23 +7185,23 @@ pub const FuncGen = struct {
71827185 ) !Builder.Value {
71837186 const o = self.ng.object;
71847187 const pt = o.pt;
7185 const mod = pt.zcu;
7188 const zcu = pt.zcu;
71867189 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
71877190 const operand = try self.resolveInst(un_op);
71887191 const operand_ty = self.typeOf(un_op);
7189 const optional_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
7192 const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
71907193 const optional_llvm_ty = try o.lowerType(optional_ty);
7191 const payload_ty = optional_ty.optionalChild(mod);
7192 if (optional_ty.optionalReprIsPayload(mod)) {
7194 const payload_ty = optional_ty.optionalChild(zcu);
7195 if (optional_ty.optionalReprIsPayload(zcu)) {
71937196 const loaded = if (operand_is_ptr)
71947197 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")
71957198 else
71967199 operand;
7197 if (payload_ty.isSlice(mod)) {
7200 if (payload_ty.isSlice(zcu)) {
71987201 const slice_ptr = try self.wip.extractValue(loaded, &.{0}, "");
71997202 const ptr_ty = try o.builder.ptrType(toLlvmAddressSpace(
7200 payload_ty.ptrAddressSpace(mod),
7201 mod.getTarget(),
7203 payload_ty.ptrAddressSpace(zcu),
7204 zcu.getTarget(),
72027205 ));
72037206 return self.wip.icmp(cond, slice_ptr, try o.builder.nullValue(ptr_ty), "");
72047207 }
......@@ -7207,7 +7210,7 @@ pub const FuncGen = struct {
72077210
72087211 comptime assert(optional_layout_version == 3);
72097212
7210 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7213 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72117214 const loaded = if (operand_is_ptr)
72127215 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")
72137216 else
......@@ -7215,7 +7218,7 @@ pub const FuncGen = struct {
72157218 return self.wip.icmp(cond, loaded, try o.builder.intValue(.i8, 0), "");
72167219 }
72177220
7218 const is_by_ref = operand_is_ptr or isByRef(optional_ty, pt);
7221 const is_by_ref = operand_is_ptr or isByRef(optional_ty, zcu);
72197222 return self.optCmpNull(cond, optional_llvm_ty, operand, is_by_ref);
72207223 }
72217224
......@@ -7227,16 +7230,16 @@ pub const FuncGen = struct {
72277230 ) !Builder.Value {
72287231 const o = self.ng.object;
72297232 const pt = o.pt;
7230 const mod = pt.zcu;
7233 const zcu = pt.zcu;
72317234 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
72327235 const operand = try self.resolveInst(un_op);
72337236 const operand_ty = self.typeOf(un_op);
7234 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
7235 const payload_ty = err_union_ty.errorUnionPayload(mod);
7237 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7238 const payload_ty = err_union_ty.errorUnionPayload(zcu);
72367239 const error_type = try o.errorIntType();
72377240 const zero = try o.builder.intValue(error_type, 0);
72387241
7239 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
7242 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
72407243 const val: Builder.Constant = switch (cond) {
72417244 .eq => .true, // 0 == 0
72427245 .ne => .false, // 0 != 0
......@@ -7245,7 +7248,7 @@ pub const FuncGen = struct {
72457248 return val.toValue();
72467249 }
72477250
7248 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7251 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72497252 const loaded = if (operand_is_ptr)
72507253 try self.wip.load(.normal, try o.lowerType(err_union_ty), operand, .default, "")
72517254 else
......@@ -7255,7 +7258,7 @@ pub const FuncGen = struct {
72557258
72567259 const err_field_index = try errUnionErrorOffset(payload_ty, pt);
72577260
7258 const loaded = if (operand_is_ptr or isByRef(err_union_ty, pt)) loaded: {
7261 const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: {
72597262 const err_union_llvm_ty = try o.lowerType(err_union_ty);
72607263 const err_field_ptr =
72617264 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");
......@@ -7267,17 +7270,17 @@ pub const FuncGen = struct {
72677270 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
72687271 const o = self.ng.object;
72697272 const pt = o.pt;
7270 const mod = pt.zcu;
7273 const zcu = pt.zcu;
72717274 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
72727275 const operand = try self.resolveInst(ty_op.operand);
7273 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
7274 const payload_ty = optional_ty.optionalChild(mod);
7275 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7276 const optional_ty = self.typeOf(ty_op.operand).childType(zcu);
7277 const payload_ty = optional_ty.optionalChild(zcu);
7278 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72767279 // We have a pointer to a zero-bit value and we need to return
72777280 // a pointer to a zero-bit value.
72787281 return operand;
72797282 }
7280 if (optional_ty.optionalReprIsPayload(mod)) {
7283 if (optional_ty.optionalReprIsPayload(zcu)) {
72817284 // The payload and the optional are the same value.
72827285 return operand;
72837286 }
......@@ -7289,18 +7292,18 @@ pub const FuncGen = struct {
72897292
72907293 const o = self.ng.object;
72917294 const pt = o.pt;
7292 const mod = pt.zcu;
7295 const zcu = pt.zcu;
72937296 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
72947297 const operand = try self.resolveInst(ty_op.operand);
7295 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
7296 const payload_ty = optional_ty.optionalChild(mod);
7298 const optional_ty = self.typeOf(ty_op.operand).childType(zcu);
7299 const payload_ty = optional_ty.optionalChild(zcu);
72977300 const non_null_bit = try o.builder.intValue(.i8, 1);
7298 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7301 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72997302 // We have a pointer to a i8. We need to set it to 1 and then return the same pointer.
73007303 _ = try self.wip.store(.normal, non_null_bit, operand, .default);
73017304 return operand;
73027305 }
7303 if (optional_ty.optionalReprIsPayload(mod)) {
7306 if (optional_ty.optionalReprIsPayload(zcu)) {
73047307 // The payload and the optional are the same value.
73057308 // Setting to non-null will be done when the payload is set.
73067309 return operand;
......@@ -7321,21 +7324,21 @@ pub const FuncGen = struct {
73217324 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
73227325 const o = self.ng.object;
73237326 const pt = o.pt;
7324 const mod = pt.zcu;
7327 const zcu = pt.zcu;
73257328 const inst = body_tail[0];
73267329 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73277330 const operand = try self.resolveInst(ty_op.operand);
73287331 const optional_ty = self.typeOf(ty_op.operand);
73297332 const payload_ty = self.typeOfIndex(inst);
7330 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
7333 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
73317334
7332 if (optional_ty.optionalReprIsPayload(mod)) {
7335 if (optional_ty.optionalReprIsPayload(zcu)) {
73337336 // Payload value is the same as the optional value.
73347337 return operand;
73357338 }
73367339
73377340 const opt_llvm_ty = try o.lowerType(optional_ty);
7338 const can_elide_load = if (isByRef(payload_ty, pt)) self.canElideLoad(body_tail) else false;
7341 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;
73397342 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);
73407343 }
73417344
......@@ -7346,26 +7349,26 @@ pub const FuncGen = struct {
73467349 ) !Builder.Value {
73477350 const o = self.ng.object;
73487351 const pt = o.pt;
7349 const mod = pt.zcu;
7352 const zcu = pt.zcu;
73507353 const inst = body_tail[0];
73517354 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73527355 const operand = try self.resolveInst(ty_op.operand);
73537356 const operand_ty = self.typeOf(ty_op.operand);
7354 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
7357 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
73557358 const result_ty = self.typeOfIndex(inst);
7356 const payload_ty = if (operand_is_ptr) result_ty.childType(mod) else result_ty;
7359 const payload_ty = if (operand_is_ptr) result_ty.childType(zcu) else result_ty;
73577360
7358 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7361 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
73597362 return if (operand_is_ptr) operand else .none;
73607363 }
73617364 const offset = try errUnionPayloadOffset(payload_ty, pt);
73627365 const err_union_llvm_ty = try o.lowerType(err_union_ty);
73637366 if (operand_is_ptr) {
73647367 return self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
7365 } else if (isByRef(err_union_ty, pt)) {
7366 const payload_alignment = payload_ty.abiAlignment(pt).toLlvm();
7368 } else if (isByRef(err_union_ty, zcu)) {
7369 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
73677370 const payload_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
7368 if (isByRef(payload_ty, pt)) {
7371 if (isByRef(payload_ty, zcu)) {
73697372 if (self.canElideLoad(body_tail)) return payload_ptr;
73707373 return self.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal);
73717374 }
......@@ -7382,13 +7385,13 @@ pub const FuncGen = struct {
73827385 ) !Builder.Value {
73837386 const o = self.ng.object;
73847387 const pt = o.pt;
7385 const mod = pt.zcu;
7388 const zcu = pt.zcu;
73867389 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73877390 const operand = try self.resolveInst(ty_op.operand);
73887391 const operand_ty = self.typeOf(ty_op.operand);
73897392 const error_type = try o.errorIntType();
7390 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
7391 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
7393 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7394 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
73927395 if (operand_is_ptr) {
73937396 return operand;
73947397 } else {
......@@ -7396,15 +7399,15 @@ pub const FuncGen = struct {
73967399 }
73977400 }
73987401
7399 const payload_ty = err_union_ty.errorUnionPayload(mod);
7400 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7402 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7403 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
74017404 if (!operand_is_ptr) return operand;
74027405 return self.wip.load(.normal, error_type, operand, .default, "");
74037406 }
74047407
74057408 const offset = try errUnionErrorOffset(payload_ty, pt);
74067409
7407 if (operand_is_ptr or isByRef(err_union_ty, pt)) {
7410 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
74087411 const err_union_llvm_ty = try o.lowerType(err_union_ty);
74097412 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
74107413 return self.wip.load(.normal, error_type, err_field_ptr, .default, "");
......@@ -7416,21 +7419,21 @@ pub const FuncGen = struct {
74167419 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
74177420 const o = self.ng.object;
74187421 const pt = o.pt;
7419 const mod = pt.zcu;
7422 const zcu = pt.zcu;
74207423 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
74217424 const operand = try self.resolveInst(ty_op.operand);
7422 const err_union_ty = self.typeOf(ty_op.operand).childType(mod);
7425 const err_union_ty = self.typeOf(ty_op.operand).childType(zcu);
74237426
7424 const payload_ty = err_union_ty.errorUnionPayload(mod);
7427 const payload_ty = err_union_ty.errorUnionPayload(zcu);
74257428 const non_error_val = try o.builder.intValue(try o.errorIntType(), 0);
7426 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7429 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
74277430 _ = try self.wip.store(.normal, non_error_val, operand, .default);
74287431 return operand;
74297432 }
74307433 const err_union_llvm_ty = try o.lowerType(err_union_ty);
74317434 {
74327435 const err_int_ty = try pt.errorIntType();
7433 const error_alignment = err_int_ty.abiAlignment(pt).toLlvm();
7436 const error_alignment = err_int_ty.abiAlignment(zcu).toLlvm();
74347437 const error_offset = try errUnionErrorOffset(payload_ty, pt);
74357438 // First set the non-error value.
74367439 const non_null_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, error_offset, "");
......@@ -7457,7 +7460,7 @@ pub const FuncGen = struct {
74577460 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
74587461 const o = self.ng.object;
74597462 const pt = o.pt;
7460 const mod = pt.zcu;
7463 const zcu = pt.zcu;
74617464
74627465 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
74637466 const struct_ty = ty_pl.ty.toType();
......@@ -7468,8 +7471,8 @@ pub const FuncGen = struct {
74687471 assert(self.err_ret_trace != .none);
74697472 const field_ptr =
74707473 try self.wip.gepStruct(struct_llvm_ty, self.err_ret_trace, llvm_field_index, "");
7471 const field_alignment = struct_ty.structFieldAlign(field_index, pt);
7472 const field_ty = struct_ty.structFieldType(field_index, mod);
7474 const field_alignment = struct_ty.structFieldAlign(field_index, zcu);
7475 const field_ty = struct_ty.structFieldType(field_index, zcu);
74737476 const field_ptr_ty = try pt.ptrType(.{
74747477 .child = field_ty.toIntern(),
74757478 .flags = .{ .alignment = field_alignment },
......@@ -7503,23 +7506,23 @@ pub const FuncGen = struct {
75037506 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
75047507 const o = self.ng.object;
75057508 const pt = o.pt;
7506 const mod = pt.zcu;
7509 const zcu = pt.zcu;
75077510 const inst = body_tail[0];
75087511 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
75097512 const payload_ty = self.typeOf(ty_op.operand);
75107513 const non_null_bit = try o.builder.intValue(.i8, 1);
75117514 comptime assert(optional_layout_version == 3);
7512 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return non_null_bit;
7515 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return non_null_bit;
75137516 const operand = try self.resolveInst(ty_op.operand);
75147517 const optional_ty = self.typeOfIndex(inst);
7515 if (optional_ty.optionalReprIsPayload(mod)) return operand;
7518 if (optional_ty.optionalReprIsPayload(zcu)) return operand;
75167519 const llvm_optional_ty = try o.lowerType(optional_ty);
7517 if (isByRef(optional_ty, pt)) {
7520 if (isByRef(optional_ty, zcu)) {
75187521 const directReturn = self.isNextRet(body_tail);
75197522 const optional_ptr = if (directReturn)
75207523 self.ret_ptr
75217524 else brk: {
7522 const alignment = optional_ty.abiAlignment(pt).toLlvm();
7525 const alignment = optional_ty.abiAlignment(zcu).toLlvm();
75237526 const optional_ptr = try self.buildAllocaWorkaround(optional_ty, alignment);
75247527 break :brk optional_ptr;
75257528 };
......@@ -7537,12 +7540,13 @@ pub const FuncGen = struct {
75377540 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
75387541 const o = self.ng.object;
75397542 const pt = o.pt;
7543 const zcu = pt.zcu;
75407544 const inst = body_tail[0];
75417545 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
75427546 const err_un_ty = self.typeOfIndex(inst);
75437547 const operand = try self.resolveInst(ty_op.operand);
75447548 const payload_ty = self.typeOf(ty_op.operand);
7545 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7549 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
75467550 return operand;
75477551 }
75487552 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);
......@@ -7550,19 +7554,19 @@ pub const FuncGen = struct {
75507554
75517555 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
75527556 const error_offset = try errUnionErrorOffset(payload_ty, pt);
7553 if (isByRef(err_un_ty, pt)) {
7557 if (isByRef(err_un_ty, zcu)) {
75547558 const directReturn = self.isNextRet(body_tail);
75557559 const result_ptr = if (directReturn)
75567560 self.ret_ptr
75577561 else brk: {
7558 const alignment = err_un_ty.abiAlignment(pt).toLlvm();
7562 const alignment = err_un_ty.abiAlignment(pt.zcu).toLlvm();
75597563 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);
75607564 break :brk result_ptr;
75617565 };
75627566
75637567 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");
75647568 const err_int_ty = try pt.errorIntType();
7565 const error_alignment = err_int_ty.abiAlignment(pt).toLlvm();
7569 const error_alignment = err_int_ty.abiAlignment(pt.zcu).toLlvm();
75667570 _ = try self.wip.store(.normal, ok_err_code, err_ptr, error_alignment);
75677571 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");
75687572 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);
......@@ -7578,30 +7582,30 @@ pub const FuncGen = struct {
75787582 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
75797583 const o = self.ng.object;
75807584 const pt = o.pt;
7581 const mod = pt.zcu;
7585 const zcu = pt.zcu;
75827586 const inst = body_tail[0];
75837587 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
75847588 const err_un_ty = self.typeOfIndex(inst);
7585 const payload_ty = err_un_ty.errorUnionPayload(mod);
7589 const payload_ty = err_un_ty.errorUnionPayload(zcu);
75867590 const operand = try self.resolveInst(ty_op.operand);
7587 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return operand;
7591 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand;
75887592 const err_un_llvm_ty = try o.lowerType(err_un_ty);
75897593
75907594 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
75917595 const error_offset = try errUnionErrorOffset(payload_ty, pt);
7592 if (isByRef(err_un_ty, pt)) {
7596 if (isByRef(err_un_ty, zcu)) {
75937597 const directReturn = self.isNextRet(body_tail);
75947598 const result_ptr = if (directReturn)
75957599 self.ret_ptr
75967600 else brk: {
7597 const alignment = err_un_ty.abiAlignment(pt).toLlvm();
7601 const alignment = err_un_ty.abiAlignment(zcu).toLlvm();
75987602 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);
75997603 break :brk result_ptr;
76007604 };
76017605
76027606 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");
76037607 const err_int_ty = try pt.errorIntType();
7604 const error_alignment = err_int_ty.abiAlignment(pt).toLlvm();
7608 const error_alignment = err_int_ty.abiAlignment(zcu).toLlvm();
76057609 _ = try self.wip.store(.normal, operand, err_ptr, error_alignment);
76067610 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");
76077611 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);
......@@ -7639,7 +7643,7 @@ pub const FuncGen = struct {
76397643 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
76407644 const o = self.ng.object;
76417645 const pt = o.pt;
7642 const mod = pt.zcu;
7646 const zcu = pt.zcu;
76437647 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
76447648 const extra = self.air.extraData(Air.Bin, data.payload).data;
76457649
......@@ -7649,9 +7653,9 @@ pub const FuncGen = struct {
76497653 const operand = try self.resolveInst(extra.rhs);
76507654
76517655 const access_kind: Builder.MemoryAccessKind =
7652 if (vector_ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;
7653 const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(mod));
7654 const alignment = vector_ptr_ty.ptrAlignment(pt).toLlvm();
7656 if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
7657 const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(zcu));
7658 const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm();
76557659 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");
76567660
76577661 const new_vector = try self.wip.insertElement(loaded, operand, index, "");
......@@ -7661,18 +7665,18 @@ pub const FuncGen = struct {
76617665
76627666 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
76637667 const o = self.ng.object;
7664 const mod = o.pt.zcu;
7668 const zcu = o.pt.zcu;
76657669 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
76667670 const lhs = try self.resolveInst(bin_op.lhs);
76677671 const rhs = try self.resolveInst(bin_op.rhs);
76687672 const inst_ty = self.typeOfIndex(inst);
7669 const scalar_ty = inst_ty.scalarType(mod);
7673 const scalar_ty = inst_ty.scalarType(zcu);
76707674
76717675 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmin, .normal, inst_ty, 2, .{ lhs, rhs });
76727676 return self.wip.callIntrinsic(
76737677 .normal,
76747678 .none,
7675 if (scalar_ty.isSignedInt(mod)) .smin else .umin,
7679 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,
76767680 &.{try o.lowerType(inst_ty)},
76777681 &.{ lhs, rhs },
76787682 "",
......@@ -7681,18 +7685,18 @@ pub const FuncGen = struct {
76817685
76827686 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
76837687 const o = self.ng.object;
7684 const mod = o.pt.zcu;
7688 const zcu = o.pt.zcu;
76857689 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
76867690 const lhs = try self.resolveInst(bin_op.lhs);
76877691 const rhs = try self.resolveInst(bin_op.rhs);
76887692 const inst_ty = self.typeOfIndex(inst);
7689 const scalar_ty = inst_ty.scalarType(mod);
7693 const scalar_ty = inst_ty.scalarType(zcu);
76907694
76917695 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmax, .normal, inst_ty, 2, .{ lhs, rhs });
76927696 return self.wip.callIntrinsic(
76937697 .normal,
76947698 .none,
7695 if (scalar_ty.isSignedInt(mod)) .smax else .umax,
7699 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,
76967700 &.{try o.lowerType(inst_ty)},
76977701 &.{ lhs, rhs },
76987702 "",
......@@ -7711,15 +7715,15 @@ pub const FuncGen = struct {
77117715
77127716 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
77137717 const o = self.ng.object;
7714 const mod = o.pt.zcu;
7718 const zcu = o.pt.zcu;
77157719 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77167720 const lhs = try self.resolveInst(bin_op.lhs);
77177721 const rhs = try self.resolveInst(bin_op.rhs);
77187722 const inst_ty = self.typeOfIndex(inst);
7719 const scalar_ty = inst_ty.scalarType(mod);
7723 const scalar_ty = inst_ty.scalarType(zcu);
77207724
77217725 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.add, fast, inst_ty, 2, .{ lhs, rhs });
7722 return self.wip.bin(if (scalar_ty.isSignedInt(mod)) .@"add nsw" else .@"add nuw", lhs, rhs, "");
7726 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .@"add nsw" else .@"add nuw", lhs, rhs, "");
77237727 }
77247728
77257729 fn airSafeArithmetic(
......@@ -7729,15 +7733,15 @@ pub const FuncGen = struct {
77297733 unsigned_intrinsic: Builder.Intrinsic,
77307734 ) !Builder.Value {
77317735 const o = fg.ng.object;
7732 const mod = o.pt.zcu;
7736 const zcu = o.pt.zcu;
77337737
77347738 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77357739 const lhs = try fg.resolveInst(bin_op.lhs);
77367740 const rhs = try fg.resolveInst(bin_op.rhs);
77377741 const inst_ty = fg.typeOfIndex(inst);
7738 const scalar_ty = inst_ty.scalarType(mod);
7742 const scalar_ty = inst_ty.scalarType(zcu);
77397743
7740 const intrinsic = if (scalar_ty.isSignedInt(mod)) signed_intrinsic else unsigned_intrinsic;
7744 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
77417745 const llvm_inst_ty = try o.lowerType(inst_ty);
77427746 const results =
77437747 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");
......@@ -7777,18 +7781,18 @@ pub const FuncGen = struct {
77777781
77787782 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77797783 const o = self.ng.object;
7780 const mod = o.pt.zcu;
7784 const zcu = o.pt.zcu;
77817785 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77827786 const lhs = try self.resolveInst(bin_op.lhs);
77837787 const rhs = try self.resolveInst(bin_op.rhs);
77847788 const inst_ty = self.typeOfIndex(inst);
7785 const scalar_ty = inst_ty.scalarType(mod);
7789 const scalar_ty = inst_ty.scalarType(zcu);
77867790
77877791 if (scalar_ty.isAnyFloat()) return self.todo("saturating float add", .{});
77887792 return self.wip.callIntrinsic(
77897793 .normal,
77907794 .none,
7791 if (scalar_ty.isSignedInt(mod)) .@"sadd.sat" else .@"uadd.sat",
7795 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",
77927796 &.{try o.lowerType(inst_ty)},
77937797 &.{ lhs, rhs },
77947798 "",
......@@ -7797,15 +7801,15 @@ pub const FuncGen = struct {
77977801
77987802 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
77997803 const o = self.ng.object;
7800 const mod = o.pt.zcu;
7804 const zcu = o.pt.zcu;
78017805 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78027806 const lhs = try self.resolveInst(bin_op.lhs);
78037807 const rhs = try self.resolveInst(bin_op.rhs);
78047808 const inst_ty = self.typeOfIndex(inst);
7805 const scalar_ty = inst_ty.scalarType(mod);
7809 const scalar_ty = inst_ty.scalarType(zcu);
78067810
78077811 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.sub, fast, inst_ty, 2, .{ lhs, rhs });
7808 return self.wip.bin(if (scalar_ty.isSignedInt(mod)) .@"sub nsw" else .@"sub nuw", lhs, rhs, "");
7812 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .@"sub nsw" else .@"sub nuw", lhs, rhs, "");
78097813 }
78107814
78117815 fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
......@@ -7818,18 +7822,18 @@ pub const FuncGen = struct {
78187822
78197823 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
78207824 const o = self.ng.object;
7821 const mod = o.pt.zcu;
7825 const zcu = o.pt.zcu;
78227826 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78237827 const lhs = try self.resolveInst(bin_op.lhs);
78247828 const rhs = try self.resolveInst(bin_op.rhs);
78257829 const inst_ty = self.typeOfIndex(inst);
7826 const scalar_ty = inst_ty.scalarType(mod);
7830 const scalar_ty = inst_ty.scalarType(zcu);
78277831
78287832 if (scalar_ty.isAnyFloat()) return self.todo("saturating float sub", .{});
78297833 return self.wip.callIntrinsic(
78307834 .normal,
78317835 .none,
7832 if (scalar_ty.isSignedInt(mod)) .@"ssub.sat" else .@"usub.sat",
7836 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",
78337837 &.{try o.lowerType(inst_ty)},
78347838 &.{ lhs, rhs },
78357839 "",
......@@ -7838,15 +7842,15 @@ pub const FuncGen = struct {
78387842
78397843 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
78407844 const o = self.ng.object;
7841 const mod = o.pt.zcu;
7845 const zcu = o.pt.zcu;
78427846 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78437847 const lhs = try self.resolveInst(bin_op.lhs);
78447848 const rhs = try self.resolveInst(bin_op.rhs);
78457849 const inst_ty = self.typeOfIndex(inst);
7846 const scalar_ty = inst_ty.scalarType(mod);
7850 const scalar_ty = inst_ty.scalarType(zcu);
78477851
78487852 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.mul, fast, inst_ty, 2, .{ lhs, rhs });
7849 return self.wip.bin(if (scalar_ty.isSignedInt(mod)) .@"mul nsw" else .@"mul nuw", lhs, rhs, "");
7853 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .@"mul nsw" else .@"mul nuw", lhs, rhs, "");
78507854 }
78517855
78527856 fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
......@@ -7859,18 +7863,18 @@ pub const FuncGen = struct {
78597863
78607864 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
78617865 const o = self.ng.object;
7862 const mod = o.pt.zcu;
7866 const zcu = o.pt.zcu;
78637867 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78647868 const lhs = try self.resolveInst(bin_op.lhs);
78657869 const rhs = try self.resolveInst(bin_op.rhs);
78667870 const inst_ty = self.typeOfIndex(inst);
7867 const scalar_ty = inst_ty.scalarType(mod);
7871 const scalar_ty = inst_ty.scalarType(zcu);
78687872
78697873 if (scalar_ty.isAnyFloat()) return self.todo("saturating float mul", .{});
78707874 return self.wip.callIntrinsic(
78717875 .normal,
78727876 .none,
7873 if (scalar_ty.isSignedInt(mod)) .@"smul.fix.sat" else .@"umul.fix.sat",
7877 if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat",
78747878 &.{try o.lowerType(inst_ty)},
78757879 &.{ lhs, rhs, .@"0" },
78767880 "",
......@@ -7888,34 +7892,34 @@ pub const FuncGen = struct {
78887892
78897893 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
78907894 const o = self.ng.object;
7891 const mod = o.pt.zcu;
7895 const zcu = o.pt.zcu;
78927896 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78937897 const lhs = try self.resolveInst(bin_op.lhs);
78947898 const rhs = try self.resolveInst(bin_op.rhs);
78957899 const inst_ty = self.typeOfIndex(inst);
7896 const scalar_ty = inst_ty.scalarType(mod);
7900 const scalar_ty = inst_ty.scalarType(zcu);
78977901
78987902 if (scalar_ty.isRuntimeFloat()) {
78997903 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
79007904 return self.buildFloatOp(.trunc, fast, inst_ty, 1, .{result});
79017905 }
7902 return self.wip.bin(if (scalar_ty.isSignedInt(mod)) .sdiv else .udiv, lhs, rhs, "");
7906 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .sdiv else .udiv, lhs, rhs, "");
79037907 }
79047908
79057909 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79067910 const o = self.ng.object;
7907 const mod = o.pt.zcu;
7911 const zcu = o.pt.zcu;
79087912 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79097913 const lhs = try self.resolveInst(bin_op.lhs);
79107914 const rhs = try self.resolveInst(bin_op.rhs);
79117915 const inst_ty = self.typeOfIndex(inst);
7912 const scalar_ty = inst_ty.scalarType(mod);
7916 const scalar_ty = inst_ty.scalarType(zcu);
79137917
79147918 if (scalar_ty.isRuntimeFloat()) {
79157919 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
79167920 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});
79177921 }
7918 if (scalar_ty.isSignedInt(mod)) {
7922 if (scalar_ty.isSignedInt(zcu)) {
79197923 const inst_llvm_ty = try o.lowerType(inst_ty);
79207924 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(
79217925 inst_llvm_ty.scalarType(&o.builder),
......@@ -7936,16 +7940,16 @@ pub const FuncGen = struct {
79367940
79377941 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79387942 const o = self.ng.object;
7939 const mod = o.pt.zcu;
7943 const zcu = o.pt.zcu;
79407944 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79417945 const lhs = try self.resolveInst(bin_op.lhs);
79427946 const rhs = try self.resolveInst(bin_op.rhs);
79437947 const inst_ty = self.typeOfIndex(inst);
7944 const scalar_ty = inst_ty.scalarType(mod);
7948 const scalar_ty = inst_ty.scalarType(zcu);
79457949
79467950 if (scalar_ty.isRuntimeFloat()) return self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
79477951 return self.wip.bin(
7948 if (scalar_ty.isSignedInt(mod)) .@"sdiv exact" else .@"udiv exact",
7952 if (scalar_ty.isSignedInt(zcu)) .@"sdiv exact" else .@"udiv exact",
79497953 lhs,
79507954 rhs,
79517955 "",
......@@ -7954,16 +7958,16 @@ pub const FuncGen = struct {
79547958
79557959 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79567960 const o = self.ng.object;
7957 const mod = o.pt.zcu;
7961 const zcu = o.pt.zcu;
79587962 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79597963 const lhs = try self.resolveInst(bin_op.lhs);
79607964 const rhs = try self.resolveInst(bin_op.rhs);
79617965 const inst_ty = self.typeOfIndex(inst);
7962 const scalar_ty = inst_ty.scalarType(mod);
7966 const scalar_ty = inst_ty.scalarType(zcu);
79637967
79647968 if (scalar_ty.isRuntimeFloat())
79657969 return self.buildFloatOp(.fmod, fast, inst_ty, 2, .{ lhs, rhs });
7966 return self.wip.bin(if (scalar_ty.isSignedInt(mod))
7970 return self.wip.bin(if (scalar_ty.isSignedInt(zcu))
79677971 .srem
79687972 else
79697973 .urem, lhs, rhs, "");
......@@ -7971,13 +7975,13 @@ pub const FuncGen = struct {
79717975
79727976 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79737977 const o = self.ng.object;
7974 const mod = o.pt.zcu;
7978 const zcu = o.pt.zcu;
79757979 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79767980 const lhs = try self.resolveInst(bin_op.lhs);
79777981 const rhs = try self.resolveInst(bin_op.rhs);
79787982 const inst_ty = self.typeOfIndex(inst);
79797983 const inst_llvm_ty = try o.lowerType(inst_ty);
7980 const scalar_ty = inst_ty.scalarType(mod);
7984 const scalar_ty = inst_ty.scalarType(zcu);
79817985
79827986 if (scalar_ty.isRuntimeFloat()) {
79837987 const a = try self.buildFloatOp(.fmod, fast, inst_ty, 2, .{ lhs, rhs });
......@@ -7987,7 +7991,7 @@ pub const FuncGen = struct {
79877991 const ltz = try self.buildFloatCmp(fast, .lt, inst_ty, .{ lhs, zero });
79887992 return self.wip.select(fast, ltz, c, a, "");
79897993 }
7990 if (scalar_ty.isSignedInt(mod)) {
7994 if (scalar_ty.isSignedInt(zcu)) {
79917995 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(
79927996 inst_llvm_ty.scalarType(&o.builder),
79937997 inst_llvm_ty.scalarBits(&o.builder) - 1,
......@@ -8007,14 +8011,14 @@ pub const FuncGen = struct {
80078011
80088012 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
80098013 const o = self.ng.object;
8010 const mod = o.pt.zcu;
8014 const zcu = o.pt.zcu;
80118015 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
80128016 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
80138017 const ptr = try self.resolveInst(bin_op.lhs);
80148018 const offset = try self.resolveInst(bin_op.rhs);
80158019 const ptr_ty = self.typeOf(bin_op.lhs);
8016 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(mod));
8017 switch (ptr_ty.ptrSize(mod)) {
8020 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8021 switch (ptr_ty.ptrSize(zcu)) {
80188022 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
80198023 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
80208024 try o.builder.intValue(try o.lowerType(Type.usize), 0), offset,
......@@ -8029,15 +8033,15 @@ pub const FuncGen = struct {
80298033
80308034 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
80318035 const o = self.ng.object;
8032 const mod = o.pt.zcu;
8036 const zcu = o.pt.zcu;
80338037 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
80348038 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
80358039 const ptr = try self.resolveInst(bin_op.lhs);
80368040 const offset = try self.resolveInst(bin_op.rhs);
80378041 const negative_offset = try self.wip.neg(offset, "");
80388042 const ptr_ty = self.typeOf(bin_op.lhs);
8039 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(mod));
8040 switch (ptr_ty.ptrSize(mod)) {
8043 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8044 switch (ptr_ty.ptrSize(zcu)) {
80418045 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
80428046 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
80438047 try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset,
......@@ -8058,7 +8062,7 @@ pub const FuncGen = struct {
80588062 ) !Builder.Value {
80598063 const o = self.ng.object;
80608064 const pt = o.pt;
8061 const mod = pt.zcu;
8065 const zcu = pt.zcu;
80628066 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
80638067 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
80648068
......@@ -8066,10 +8070,10 @@ pub const FuncGen = struct {
80668070 const rhs = try self.resolveInst(extra.rhs);
80678071
80688072 const lhs_ty = self.typeOf(extra.lhs);
8069 const scalar_ty = lhs_ty.scalarType(mod);
8073 const scalar_ty = lhs_ty.scalarType(zcu);
80708074 const inst_ty = self.typeOfIndex(inst);
80718075
8072 const intrinsic = if (scalar_ty.isSignedInt(mod)) signed_intrinsic else unsigned_intrinsic;
8076 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
80738077 const llvm_inst_ty = try o.lowerType(inst_ty);
80748078 const llvm_lhs_ty = try o.lowerType(lhs_ty);
80758079 const results =
......@@ -8081,8 +8085,8 @@ pub const FuncGen = struct {
80818085 const result_index = o.llvmFieldIndex(inst_ty, 0).?;
80828086 const overflow_index = o.llvmFieldIndex(inst_ty, 1).?;
80838087
8084 if (isByRef(inst_ty, pt)) {
8085 const result_alignment = inst_ty.abiAlignment(pt).toLlvm();
8088 if (isByRef(inst_ty, zcu)) {
8089 const result_alignment = inst_ty.abiAlignment(zcu).toLlvm();
80868090 const alloca_inst = try self.buildAllocaWorkaround(inst_ty, result_alignment);
80878091 {
80888092 const field_ptr = try self.wip.gepStruct(llvm_inst_ty, alloca_inst, result_index, "");
......@@ -8165,9 +8169,9 @@ pub const FuncGen = struct {
81658169 params: [2]Builder.Value,
81668170 ) !Builder.Value {
81678171 const o = self.ng.object;
8168 const mod = o.pt.zcu;
8169 const target = mod.getTarget();
8170 const scalar_ty = ty.scalarType(mod);
8172 const zcu = o.pt.zcu;
8173 const target = zcu.getTarget();
8174 const scalar_ty = ty.scalarType(zcu);
81718175 const scalar_llvm_ty = try o.lowerType(scalar_ty);
81728176
81738177 if (intrinsicsAllowed(scalar_ty, target)) {
......@@ -8205,8 +8209,8 @@ pub const FuncGen = struct {
82058209 .gte => .sge,
82068210 };
82078211
8208 if (ty.zigTypeTag(mod) == .Vector) {
8209 const vec_len = ty.vectorLen(mod);
8212 if (ty.zigTypeTag(zcu) == .Vector) {
8213 const vec_len = ty.vectorLen(zcu);
82108214 const vector_result_ty = try o.builder.vectorType(.normal, vec_len, .i32);
82118215
82128216 const init = try o.builder.poisonValue(vector_result_ty);
......@@ -8271,9 +8275,9 @@ pub const FuncGen = struct {
82718275 params: [params_len]Builder.Value,
82728276 ) !Builder.Value {
82738277 const o = self.ng.object;
8274 const mod = o.pt.zcu;
8275 const target = mod.getTarget();
8276 const scalar_ty = ty.scalarType(mod);
8278 const zcu = o.pt.zcu;
8279 const target = zcu.getTarget();
8280 const scalar_ty = ty.scalarType(zcu);
82778281 const llvm_ty = try o.lowerType(ty);
82788282
82798283 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {
......@@ -8382,9 +8386,9 @@ pub const FuncGen = struct {
83828386 ([1]Builder.Type{scalar_llvm_ty} ** 3)[0..params.len],
83838387 scalar_llvm_ty,
83848388 );
8385 if (ty.zigTypeTag(mod) == .Vector) {
8389 if (ty.zigTypeTag(zcu) == .Vector) {
83868390 const result = try o.builder.poisonValue(llvm_ty);
8387 return self.buildElementwiseCall(libc_fn, &params, result, ty.vectorLen(mod));
8391 return self.buildElementwiseCall(libc_fn, &params, result, ty.vectorLen(zcu));
83888392 }
83898393
83908394 return self.wip.call(
......@@ -8413,7 +8417,7 @@ pub const FuncGen = struct {
84138417 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
84148418 const o = self.ng.object;
84158419 const pt = o.pt;
8416 const mod = pt.zcu;
8420 const zcu = pt.zcu;
84178421 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
84188422 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
84198423
......@@ -8421,7 +8425,7 @@ pub const FuncGen = struct {
84218425 const rhs = try self.resolveInst(extra.rhs);
84228426
84238427 const lhs_ty = self.typeOf(extra.lhs);
8424 const lhs_scalar_ty = lhs_ty.scalarType(mod);
8428 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
84258429
84268430 const dest_ty = self.typeOfIndex(inst);
84278431 const llvm_dest_ty = try o.lowerType(dest_ty);
......@@ -8429,7 +8433,7 @@ pub const FuncGen = struct {
84298433 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
84308434
84318435 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");
8432 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(mod))
8436 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
84338437 .ashr
84348438 else
84358439 .lshr, result, casted_rhs, "");
......@@ -8439,8 +8443,8 @@ pub const FuncGen = struct {
84398443 const result_index = o.llvmFieldIndex(dest_ty, 0).?;
84408444 const overflow_index = o.llvmFieldIndex(dest_ty, 1).?;
84418445
8442 if (isByRef(dest_ty, pt)) {
8443 const result_alignment = dest_ty.abiAlignment(pt).toLlvm();
8446 if (isByRef(dest_ty, zcu)) {
8447 const result_alignment = dest_ty.abiAlignment(zcu).toLlvm();
84448448 const alloca_inst = try self.buildAllocaWorkaround(dest_ty, result_alignment);
84458449 {
84468450 const field_ptr = try self.wip.gepStruct(llvm_dest_ty, alloca_inst, result_index, "");
......@@ -8483,17 +8487,17 @@ pub const FuncGen = struct {
84838487
84848488 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
84858489 const o = self.ng.object;
8486 const mod = o.pt.zcu;
8490 const zcu = o.pt.zcu;
84878491 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84888492
84898493 const lhs = try self.resolveInst(bin_op.lhs);
84908494 const rhs = try self.resolveInst(bin_op.rhs);
84918495
84928496 const lhs_ty = self.typeOf(bin_op.lhs);
8493 const lhs_scalar_ty = lhs_ty.scalarType(mod);
8497 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
84948498
84958499 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
8496 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(mod))
8500 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
84978501 .@"shl nsw"
84988502 else
84998503 .@"shl nuw", lhs, casted_rhs, "");
......@@ -8515,15 +8519,15 @@ pub const FuncGen = struct {
85158519 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85168520 const o = self.ng.object;
85178521 const pt = o.pt;
8518 const mod = pt.zcu;
8522 const zcu = pt.zcu;
85198523 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85208524
85218525 const lhs = try self.resolveInst(bin_op.lhs);
85228526 const rhs = try self.resolveInst(bin_op.rhs);
85238527
85248528 const lhs_ty = self.typeOf(bin_op.lhs);
8525 const lhs_scalar_ty = lhs_ty.scalarType(mod);
8526 const lhs_bits = lhs_scalar_ty.bitSize(pt);
8529 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
8530 const lhs_bits = lhs_scalar_ty.bitSize(zcu);
85278531
85288532 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
85298533
......@@ -8532,7 +8536,7 @@ pub const FuncGen = struct {
85328536 const result = try self.wip.callIntrinsic(
85338537 .normal,
85348538 .none,
8535 if (lhs_scalar_ty.isSignedInt(mod)) .@"sshl.sat" else .@"ushl.sat",
8539 if (lhs_scalar_ty.isSignedInt(zcu)) .@"sshl.sat" else .@"ushl.sat",
85368540 &.{llvm_lhs_ty},
85378541 &.{ lhs, casted_rhs },
85388542 "",
......@@ -8557,17 +8561,17 @@ pub const FuncGen = struct {
85578561
85588562 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
85598563 const o = self.ng.object;
8560 const mod = o.pt.zcu;
8564 const zcu = o.pt.zcu;
85618565 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85628566
85638567 const lhs = try self.resolveInst(bin_op.lhs);
85648568 const rhs = try self.resolveInst(bin_op.rhs);
85658569
85668570 const lhs_ty = self.typeOf(bin_op.lhs);
8567 const lhs_scalar_ty = lhs_ty.scalarType(mod);
8571 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
85688572
85698573 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
8570 const is_signed_int = lhs_scalar_ty.isSignedInt(mod);
8574 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);
85718575
85728576 return self.wip.bin(if (is_exact)
85738577 if (is_signed_int) .@"ashr exact" else .@"lshr exact"
......@@ -8576,13 +8580,13 @@ pub const FuncGen = struct {
85768580
85778581 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85788582 const o = self.ng.object;
8579 const mod = o.pt.zcu;
8583 const zcu = o.pt.zcu;
85808584 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
85818585 const operand = try self.resolveInst(ty_op.operand);
85828586 const operand_ty = self.typeOf(ty_op.operand);
8583 const scalar_ty = operand_ty.scalarType(mod);
8587 const scalar_ty = operand_ty.scalarType(zcu);
85848588
8585 switch (scalar_ty.zigTypeTag(mod)) {
8589 switch (scalar_ty.zigTypeTag(zcu)) {
85868590 .Int => return self.wip.callIntrinsic(
85878591 .normal,
85888592 .none,
......@@ -8598,13 +8602,13 @@ pub const FuncGen = struct {
85988602
85998603 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
86008604 const o = self.ng.object;
8601 const mod = o.pt.zcu;
8605 const zcu = o.pt.zcu;
86028606 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
86038607 const dest_ty = self.typeOfIndex(inst);
86048608 const dest_llvm_ty = try o.lowerType(dest_ty);
86058609 const operand = try self.resolveInst(ty_op.operand);
86068610 const operand_ty = self.typeOf(ty_op.operand);
8607 const operand_info = operand_ty.intInfo(mod);
8611 const operand_info = operand_ty.intInfo(zcu);
86088612
86098613 return self.wip.conv(switch (operand_info.signedness) {
86108614 .signed => .signed,
......@@ -8622,12 +8626,12 @@ pub const FuncGen = struct {
86228626
86238627 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
86248628 const o = self.ng.object;
8625 const mod = o.pt.zcu;
8629 const zcu = o.pt.zcu;
86268630 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
86278631 const operand = try self.resolveInst(ty_op.operand);
86288632 const operand_ty = self.typeOf(ty_op.operand);
86298633 const dest_ty = self.typeOfIndex(inst);
8630 const target = mod.getTarget();
8634 const target = zcu.getTarget();
86318635 const dest_bits = dest_ty.floatBits(target);
86328636 const src_bits = operand_ty.floatBits(target);
86338637
......@@ -8656,12 +8660,12 @@ pub const FuncGen = struct {
86568660
86578661 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
86588662 const o = self.ng.object;
8659 const mod = o.pt.zcu;
8663 const zcu = o.pt.zcu;
86608664 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
86618665 const operand = try self.resolveInst(ty_op.operand);
86628666 const operand_ty = self.typeOf(ty_op.operand);
86638667 const dest_ty = self.typeOfIndex(inst);
8664 const target = mod.getTarget();
8668 const target = zcu.getTarget();
86658669
86668670 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
86678671 return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), "");
......@@ -8669,18 +8673,18 @@ pub const FuncGen = struct {
86698673 const operand_llvm_ty = try o.lowerType(operand_ty);
86708674 const dest_llvm_ty = try o.lowerType(dest_ty);
86718675
8672 const dest_bits = dest_ty.scalarType(mod).floatBits(target);
8673 const src_bits = operand_ty.scalarType(mod).floatBits(target);
8676 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);
8677 const src_bits = operand_ty.scalarType(zcu).floatBits(target);
86748678 const fn_name = try o.builder.strtabStringFmt("__extend{s}f{s}f2", .{
86758679 compilerRtFloatAbbrev(src_bits), compilerRtFloatAbbrev(dest_bits),
86768680 });
86778681
86788682 const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, dest_llvm_ty);
8679 if (dest_ty.isVector(mod)) return self.buildElementwiseCall(
8683 if (dest_ty.isVector(zcu)) return self.buildElementwiseCall(
86808684 libc_fn,
86818685 &.{operand},
86828686 try o.builder.poisonValue(dest_llvm_ty),
8683 dest_ty.vectorLen(mod),
8687 dest_ty.vectorLen(zcu),
86848688 );
86858689 return self.wip.call(
86868690 .normal,
......@@ -8715,9 +8719,9 @@ pub const FuncGen = struct {
87158719 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {
87168720 const o = self.ng.object;
87178721 const pt = o.pt;
8718 const mod = pt.zcu;
8719 const operand_is_ref = isByRef(operand_ty, pt);
8720 const result_is_ref = isByRef(inst_ty, pt);
8722 const zcu = pt.zcu;
8723 const operand_is_ref = isByRef(operand_ty, zcu);
8724 const result_is_ref = isByRef(inst_ty, zcu);
87218725 const llvm_dest_ty = try o.lowerType(inst_ty);
87228726
87238727 if (operand_is_ref and result_is_ref) {
......@@ -8731,18 +8735,18 @@ pub const FuncGen = struct {
87318735 return self.wip.conv(.unsigned, operand, llvm_dest_ty, "");
87328736 }
87338737
8734 if (operand_ty.zigTypeTag(mod) == .Int and inst_ty.isPtrAtRuntime(mod)) {
8738 if (operand_ty.zigTypeTag(zcu) == .Int and inst_ty.isPtrAtRuntime(zcu)) {
87358739 return self.wip.cast(.inttoptr, operand, llvm_dest_ty, "");
87368740 }
87378741
8738 if (operand_ty.zigTypeTag(mod) == .Vector and inst_ty.zigTypeTag(mod) == .Array) {
8739 const elem_ty = operand_ty.childType(mod);
8742 if (operand_ty.zigTypeTag(zcu) == .Vector and inst_ty.zigTypeTag(zcu) == .Array) {
8743 const elem_ty = operand_ty.childType(zcu);
87408744 if (!result_is_ref) {
87418745 return self.ng.todo("implement bitcast vector to non-ref array", .{});
87428746 }
8743 const alignment = inst_ty.abiAlignment(pt).toLlvm();
8747 const alignment = inst_ty.abiAlignment(zcu).toLlvm();
87448748 const array_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
8745 const bitcast_ok = elem_ty.bitSize(pt) == elem_ty.abiSize(pt) * 8;
8749 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
87468750 if (bitcast_ok) {
87478751 _ = try self.wip.store(.normal, operand, array_ptr, alignment);
87488752 } else {
......@@ -8750,7 +8754,7 @@ pub const FuncGen = struct {
87508754 // a simple bitcast will not work, and we fall back to extractelement.
87518755 const llvm_usize = try o.lowerType(Type.usize);
87528756 const usize_zero = try o.builder.intValue(llvm_usize, 0);
8753 const vector_len = operand_ty.arrayLen(mod);
8757 const vector_len = operand_ty.arrayLen(zcu);
87548758 var i: u64 = 0;
87558759 while (i < vector_len) : (i += 1) {
87568760 const elem_ptr = try self.wip.gep(.inbounds, llvm_dest_ty, array_ptr, &.{
......@@ -8762,16 +8766,16 @@ pub const FuncGen = struct {
87628766 }
87638767 }
87648768 return array_ptr;
8765 } else if (operand_ty.zigTypeTag(mod) == .Array and inst_ty.zigTypeTag(mod) == .Vector) {
8766 const elem_ty = operand_ty.childType(mod);
8769 } else if (operand_ty.zigTypeTag(zcu) == .Array and inst_ty.zigTypeTag(zcu) == .Vector) {
8770 const elem_ty = operand_ty.childType(zcu);
87678771 const llvm_vector_ty = try o.lowerType(inst_ty);
87688772 if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{});
87698773
8770 const bitcast_ok = elem_ty.bitSize(pt) == elem_ty.abiSize(pt) * 8;
8774 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
87718775 if (bitcast_ok) {
87728776 // The array is aligned to the element's alignment, while the vector might have a completely
87738777 // different alignment. This means we need to enforce the alignment of this load.
8774 const alignment = elem_ty.abiAlignment(pt).toLlvm();
8778 const alignment = elem_ty.abiAlignment(zcu).toLlvm();
87758779 return self.wip.load(.normal, llvm_vector_ty, operand, alignment, "");
87768780 } else {
87778781 // If the ABI size of the element type is not evenly divisible by size in bits;
......@@ -8780,7 +8784,7 @@ pub const FuncGen = struct {
87808784 const elem_llvm_ty = try o.lowerType(elem_ty);
87818785 const llvm_usize = try o.lowerType(Type.usize);
87828786 const usize_zero = try o.builder.intValue(llvm_usize, 0);
8783 const vector_len = operand_ty.arrayLen(mod);
8787 const vector_len = operand_ty.arrayLen(zcu);
87848788 var vector = try o.builder.poisonValue(llvm_vector_ty);
87858789 var i: u64 = 0;
87868790 while (i < vector_len) : (i += 1) {
......@@ -8796,25 +8800,25 @@ pub const FuncGen = struct {
87968800 }
87978801
87988802 if (operand_is_ref) {
8799 const alignment = operand_ty.abiAlignment(pt).toLlvm();
8803 const alignment = operand_ty.abiAlignment(zcu).toLlvm();
88008804 return self.wip.load(.normal, llvm_dest_ty, operand, alignment, "");
88018805 }
88028806
88038807 if (result_is_ref) {
8804 const alignment = operand_ty.abiAlignment(pt).max(inst_ty.abiAlignment(pt)).toLlvm();
8808 const alignment = operand_ty.abiAlignment(zcu).max(inst_ty.abiAlignment(zcu)).toLlvm();
88058809 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
88068810 _ = try self.wip.store(.normal, operand, result_ptr, alignment);
88078811 return result_ptr;
88088812 }
88098813
88108814 if (llvm_dest_ty.isStruct(&o.builder) or
8811 ((operand_ty.zigTypeTag(mod) == .Vector or inst_ty.zigTypeTag(mod) == .Vector) and
8812 operand_ty.bitSize(pt) != inst_ty.bitSize(pt)))
8815 ((operand_ty.zigTypeTag(zcu) == .Vector or inst_ty.zigTypeTag(zcu) == .Vector) and
8816 operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu)))
88138817 {
88148818 // Both our operand and our result are values, not pointers,
88158819 // but LLVM won't let us bitcast struct values or vectors with padding bits.
88168820 // Therefore, we store operand to alloca, then load for result.
8817 const alignment = operand_ty.abiAlignment(pt).max(inst_ty.abiAlignment(pt)).toLlvm();
8821 const alignment = operand_ty.abiAlignment(zcu).max(inst_ty.abiAlignment(zcu)).toLlvm();
88188822 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
88198823 _ = try self.wip.store(.normal, operand, result_ptr, alignment);
88208824 return self.wip.load(.normal, llvm_dest_ty, result_ptr, alignment, "");
......@@ -8868,7 +8872,7 @@ pub const FuncGen = struct {
88688872 };
88698873
88708874 const mod = self.ng.ownerModule();
8871 if (isByRef(inst_ty, pt)) {
8875 if (isByRef(inst_ty, zcu)) {
88728876 _ = try self.wip.callIntrinsic(
88738877 .normal,
88748878 .none,
......@@ -8882,7 +8886,7 @@ pub const FuncGen = struct {
88828886 "",
88838887 );
88848888 } else if (mod.optimize_mode == .Debug) {
8885 const alignment = inst_ty.abiAlignment(pt).toLlvm();
8889 const alignment = inst_ty.abiAlignment(zcu).toLlvm();
88868890 const alloca = try self.buildAlloca(arg_val.typeOfWip(&self.wip), alignment);
88878891 _ = try self.wip.store(.normal, arg_val, alloca, alignment);
88888892 _ = try self.wip.callIntrinsic(
......@@ -8919,28 +8923,28 @@ pub const FuncGen = struct {
89198923 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
89208924 const o = self.ng.object;
89218925 const pt = o.pt;
8922 const mod = pt.zcu;
8926 const zcu = pt.zcu;
89238927 const ptr_ty = self.typeOfIndex(inst);
8924 const pointee_type = ptr_ty.childType(mod);
8925 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(pt))
8928 const pointee_type = ptr_ty.childType(zcu);
8929 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
89268930 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
89278931
89288932 //const pointee_llvm_ty = try o.lowerType(pointee_type);
8929 const alignment = ptr_ty.ptrAlignment(pt).toLlvm();
8933 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
89308934 return self.buildAllocaWorkaround(pointee_type, alignment);
89318935 }
89328936
89338937 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
89348938 const o = self.ng.object;
89358939 const pt = o.pt;
8936 const mod = pt.zcu;
8940 const zcu = pt.zcu;
89378941 const ptr_ty = self.typeOfIndex(inst);
8938 const ret_ty = ptr_ty.childType(mod);
8939 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt))
8942 const ret_ty = ptr_ty.childType(zcu);
8943 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
89408944 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
89418945 if (self.ret_ptr != .none) return self.ret_ptr;
89428946 //const ret_llvm_ty = try o.lowerType(ret_ty);
8943 const alignment = ptr_ty.ptrAlignment(pt).toLlvm();
8947 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
89448948 return self.buildAllocaWorkaround(ret_ty, alignment);
89458949 }
89468950
......@@ -8962,19 +8966,19 @@ pub const FuncGen = struct {
89628966 alignment: Builder.Alignment,
89638967 ) Allocator.Error!Builder.Value {
89648968 const o = self.ng.object;
8965 return self.buildAlloca(try o.builder.arrayType(ty.abiSize(o.pt), .i8), alignment);
8969 return self.buildAlloca(try o.builder.arrayType(ty.abiSize(o.pt.zcu), .i8), alignment);
89668970 }
89678971
89688972 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
89698973 const o = self.ng.object;
89708974 const pt = o.pt;
8971 const mod = pt.zcu;
8975 const zcu = pt.zcu;
89728976 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
89738977 const dest_ptr = try self.resolveInst(bin_op.lhs);
89748978 const ptr_ty = self.typeOf(bin_op.lhs);
8975 const operand_ty = ptr_ty.childType(mod);
8979 const operand_ty = ptr_ty.childType(zcu);
89768980
8977 const val_is_undef = if (try self.air.value(bin_op.rhs, pt)) |val| val.isUndefDeep(mod) else false;
8981 const val_is_undef = if (try self.air.value(bin_op.rhs, pt)) |val| val.isUndefDeep(zcu) else false;
89788982 if (val_is_undef) {
89798983 const owner_mod = self.ng.ownerModule();
89808984
......@@ -8991,7 +8995,7 @@ pub const FuncGen = struct {
89918995 return .none;
89928996 }
89938997
8994 const ptr_info = ptr_ty.ptrInfo(mod);
8998 const ptr_info = ptr_ty.ptrInfo(zcu);
89958999 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);
89969000 if (needs_bitmask) {
89979001 // TODO: only some bits are to be undef, we cannot write with a simple memset.
......@@ -9000,13 +9004,13 @@ pub const FuncGen = struct {
90009004 return .none;
90019005 }
90029006
9003 const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(pt));
9007 const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(zcu));
90049008 _ = try self.wip.callMemSet(
90059009 dest_ptr,
9006 ptr_ty.ptrAlignment(pt).toLlvm(),
9010 ptr_ty.ptrAlignment(zcu).toLlvm(),
90079011 if (safety) try o.builder.intValue(.i8, 0xaa) else try o.builder.undefValue(.i8),
90089012 len,
9009 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,
9013 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
90109014 );
90119015 if (safety and owner_mod.valgrind) {
90129016 try self.valgrindMarkUndef(dest_ptr, len);
......@@ -9027,8 +9031,8 @@ pub const FuncGen = struct {
90279031 /// The first instruction of `body_tail` is the one whose copy we want to elide.
90289032 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {
90299033 const o = fg.ng.object;
9030 const mod = o.pt.zcu;
9031 const ip = &mod.intern_pool;
9034 const zcu = o.pt.zcu;
9035 const ip = &zcu.intern_pool;
90329036 for (body_tail[1..]) |body_inst| {
90339037 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip)) {
90349038 .none => continue,
......@@ -9044,15 +9048,15 @@ pub const FuncGen = struct {
90449048 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
90459049 const o = fg.ng.object;
90469050 const pt = o.pt;
9047 const mod = pt.zcu;
9051 const zcu = pt.zcu;
90489052 const inst = body_tail[0];
90499053 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
90509054 const ptr_ty = fg.typeOf(ty_op.operand);
9051 const ptr_info = ptr_ty.ptrInfo(mod);
9055 const ptr_info = ptr_ty.ptrInfo(zcu);
90529056 const ptr = try fg.resolveInst(ty_op.operand);
90539057
90549058 elide: {
9055 if (!isByRef(Type.fromInterned(ptr_info.child), pt)) break :elide;
9059 if (!isByRef(Type.fromInterned(ptr_info.child), zcu)) break :elide;
90569060 if (!canElideLoad(fg, body_tail)) break :elide;
90579061 return ptr;
90589062 }
......@@ -9105,34 +9109,34 @@ pub const FuncGen = struct {
91059109 ) !Builder.Value {
91069110 const o = self.ng.object;
91079111 const pt = o.pt;
9108 const mod = pt.zcu;
9112 const zcu = pt.zcu;
91099113 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
91109114 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
91119115 const ptr = try self.resolveInst(extra.ptr);
91129116 const ptr_ty = self.typeOf(extra.ptr);
91139117 var expected_value = try self.resolveInst(extra.expected_value);
91149118 var new_value = try self.resolveInst(extra.new_value);
9115 const operand_ty = ptr_ty.childType(mod);
9119 const operand_ty = ptr_ty.childType(zcu);
91169120 const llvm_operand_ty = try o.lowerType(operand_ty);
91179121 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
91189122 if (llvm_abi_ty != .none) {
91199123 // operand needs widening and truncating
91209124 const signedness: Builder.Function.Instruction.Cast.Signedness =
9121 if (operand_ty.isSignedInt(mod)) .signed else .unsigned;
9125 if (operand_ty.isSignedInt(zcu)) .signed else .unsigned;
91229126 expected_value = try self.wip.conv(signedness, expected_value, llvm_abi_ty, "");
91239127 new_value = try self.wip.conv(signedness, new_value, llvm_abi_ty, "");
91249128 }
91259129
91269130 const result = try self.wip.cmpxchg(
91279131 kind,
9128 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,
9132 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
91299133 ptr,
91309134 expected_value,
91319135 new_value,
91329136 self.sync_scope,
91339137 toLlvmAtomicOrdering(extra.successOrder()),
91349138 toLlvmAtomicOrdering(extra.failureOrder()),
9135 ptr_ty.ptrAlignment(pt).toLlvm(),
9139 ptr_ty.ptrAlignment(zcu).toLlvm(),
91369140 "",
91379141 );
91389142
......@@ -9142,7 +9146,7 @@ pub const FuncGen = struct {
91429146 if (llvm_abi_ty != .none) payload = try self.wip.cast(.trunc, payload, llvm_operand_ty, "");
91439147 const success_bit = try self.wip.extractValue(result, &.{1}, "");
91449148
9145 if (optional_ty.optionalReprIsPayload(mod)) {
9149 if (optional_ty.optionalReprIsPayload(zcu)) {
91469150 const zero = try o.builder.zeroInitValue(payload.typeOfWip(&self.wip));
91479151 return self.wip.select(.normal, success_bit, zero, payload, "");
91489152 }
......@@ -9156,14 +9160,14 @@ pub const FuncGen = struct {
91569160 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
91579161 const o = self.ng.object;
91589162 const pt = o.pt;
9159 const mod = pt.zcu;
9163 const zcu = pt.zcu;
91609164 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
91619165 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
91629166 const ptr = try self.resolveInst(pl_op.operand);
91639167 const ptr_ty = self.typeOf(pl_op.operand);
9164 const operand_ty = ptr_ty.childType(mod);
9168 const operand_ty = ptr_ty.childType(zcu);
91659169 const operand = try self.resolveInst(extra.operand);
9166 const is_signed_int = operand_ty.isSignedInt(mod);
9170 const is_signed_int = operand_ty.isSignedInt(zcu);
91679171 const is_float = operand_ty.isRuntimeFloat();
91689172 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);
91699173 const ordering = toLlvmAtomicOrdering(extra.ordering());
......@@ -9171,8 +9175,8 @@ pub const FuncGen = struct {
91719175 const llvm_operand_ty = try o.lowerType(operand_ty);
91729176
91739177 const access_kind: Builder.MemoryAccessKind =
9174 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;
9175 const ptr_alignment = ptr_ty.ptrAlignment(pt).toLlvm();
9178 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
9179 const ptr_alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
91769180
91779181 if (llvm_abi_ty != .none) {
91789182 // operand needs widening and truncating or bitcasting.
......@@ -9220,19 +9224,19 @@ pub const FuncGen = struct {
92209224 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
92219225 const o = self.ng.object;
92229226 const pt = o.pt;
9223 const mod = pt.zcu;
9227 const zcu = pt.zcu;
92249228 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
92259229 const ptr = try self.resolveInst(atomic_load.ptr);
92269230 const ptr_ty = self.typeOf(atomic_load.ptr);
9227 const info = ptr_ty.ptrInfo(mod);
9231 const info = ptr_ty.ptrInfo(zcu);
92289232 const elem_ty = Type.fromInterned(info.child);
9229 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
9233 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
92309234 const ordering = toLlvmAtomicOrdering(atomic_load.order);
92319235 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);
92329236 const ptr_alignment = (if (info.flags.alignment != .none)
92339237 @as(InternPool.Alignment, info.flags.alignment)
92349238 else
9235 Type.fromInterned(info.child).abiAlignment(pt)).toLlvm();
9239 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();
92369240 const access_kind: Builder.MemoryAccessKind =
92379241 if (info.flags.is_volatile) .@"volatile" else .normal;
92389242 const elem_llvm_ty = try o.lowerType(elem_ty);
......@@ -9268,11 +9272,11 @@ pub const FuncGen = struct {
92689272 ) !Builder.Value {
92699273 const o = self.ng.object;
92709274 const pt = o.pt;
9271 const mod = pt.zcu;
9275 const zcu = pt.zcu;
92729276 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
92739277 const ptr_ty = self.typeOf(bin_op.lhs);
9274 const operand_ty = ptr_ty.childType(mod);
9275 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) return .none;
9278 const operand_ty = ptr_ty.childType(zcu);
9279 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;
92769280 const ptr = try self.resolveInst(bin_op.lhs);
92779281 var element = try self.resolveInst(bin_op.rhs);
92789282 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
......@@ -9280,7 +9284,7 @@ pub const FuncGen = struct {
92809284 if (llvm_abi_ty != .none) {
92819285 // operand needs widening
92829286 element = try self.wip.conv(
9283 if (operand_ty.isSignedInt(mod)) .signed else .unsigned,
9287 if (operand_ty.isSignedInt(zcu)) .signed else .unsigned,
92849288 element,
92859289 llvm_abi_ty,
92869290 "",
......@@ -9293,26 +9297,26 @@ pub const FuncGen = struct {
92939297 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
92949298 const o = self.ng.object;
92959299 const pt = o.pt;
9296 const mod = pt.zcu;
9300 const zcu = pt.zcu;
92979301 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
92989302 const dest_slice = try self.resolveInst(bin_op.lhs);
92999303 const ptr_ty = self.typeOf(bin_op.lhs);
93009304 const elem_ty = self.typeOf(bin_op.rhs);
9301 const dest_ptr_align = ptr_ty.ptrAlignment(pt).toLlvm();
9305 const dest_ptr_align = ptr_ty.ptrAlignment(zcu).toLlvm();
93029306 const dest_ptr = try self.sliceOrArrayPtr(dest_slice, ptr_ty);
93039307 const access_kind: Builder.MemoryAccessKind =
9304 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;
9308 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
93059309
93069310 // Any WebAssembly runtime will trap when the destination pointer is out-of-bounds, regardless
93079311 // of the length. This means we need to emit a check where we skip the memset when the length
93089312 // is 0 as we allow for undefined pointers in 0-sized slices.
93099313 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
93109314 const intrinsic_len0_traps = o.target.isWasm() and
9311 ptr_ty.isSlice(mod) and
9315 ptr_ty.isSlice(zcu) and
93129316 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory);
93139317
93149318 if (try self.air.value(bin_op.rhs, pt)) |elem_val| {
9315 if (elem_val.isUndefDeep(mod)) {
9319 if (elem_val.isUndefDeep(zcu)) {
93169320 // Even if safety is disabled, we still emit a memset to undefined since it conveys
93179321 // extra information to LLVM. However, safety makes the difference between using
93189322 // 0xaa or actual undefined for the fill byte.
......@@ -9350,7 +9354,7 @@ pub const FuncGen = struct {
93509354 }
93519355
93529356 const value = try self.resolveInst(bin_op.rhs);
9353 const elem_abi_size = elem_ty.abiSize(pt);
9357 const elem_abi_size = elem_ty.abiSize(zcu);
93549358
93559359 if (elem_abi_size == 1) {
93569360 // In this case we can take advantage of LLVM's intrinsic.
......@@ -9387,9 +9391,9 @@ pub const FuncGen = struct {
93879391 const end_block = try self.wip.block(1, "InlineMemsetEnd");
93889392
93899393 const llvm_usize_ty = try o.lowerType(Type.usize);
9390 const len = switch (ptr_ty.ptrSize(mod)) {
9394 const len = switch (ptr_ty.ptrSize(zcu)) {
93919395 .Slice => try self.wip.extractValue(dest_slice, &.{1}, ""),
9392 .One => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(mod).arrayLen(mod)),
9396 .One => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),
93939397 .Many, .C => unreachable,
93949398 };
93959399 const elem_llvm_ty = try o.lowerType(elem_ty);
......@@ -9402,9 +9406,9 @@ pub const FuncGen = struct {
94029406 _ = try self.wip.brCond(end, body_block, end_block);
94039407
94049408 self.wip.cursor = .{ .block = body_block };
9405 const elem_abi_align = elem_ty.abiAlignment(pt);
9409 const elem_abi_align = elem_ty.abiAlignment(zcu);
94069410 const it_ptr_align = InternPool.Alignment.fromLlvm(dest_ptr_align).min(elem_abi_align).toLlvm();
9407 if (isByRef(elem_ty, pt)) {
9411 if (isByRef(elem_ty, zcu)) {
94089412 _ = try self.wip.callMemCpy(
94099413 it_ptr.toValue(),
94109414 it_ptr_align,
......@@ -9447,7 +9451,7 @@ pub const FuncGen = struct {
94479451 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
94489452 const o = self.ng.object;
94499453 const pt = o.pt;
9450 const mod = pt.zcu;
9454 const zcu = pt.zcu;
94519455 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
94529456 const dest_slice = try self.resolveInst(bin_op.lhs);
94539457 const dest_ptr_ty = self.typeOf(bin_op.lhs);
......@@ -9456,8 +9460,8 @@ pub const FuncGen = struct {
94569460 const src_ptr = try self.sliceOrArrayPtr(src_slice, src_ptr_ty);
94579461 const len = try self.sliceOrArrayLenInBytes(dest_slice, dest_ptr_ty);
94589462 const dest_ptr = try self.sliceOrArrayPtr(dest_slice, dest_ptr_ty);
9459 const access_kind: Builder.MemoryAccessKind = if (src_ptr_ty.isVolatilePtr(mod) or
9460 dest_ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;
9463 const access_kind: Builder.MemoryAccessKind = if (src_ptr_ty.isVolatilePtr(zcu) or
9464 dest_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
94619465
94629466 // When bulk-memory is enabled, this will be lowered to WebAssembly's memory.copy instruction.
94639467 // This instruction will trap on an invalid address, regardless of the length.
......@@ -9466,7 +9470,7 @@ pub const FuncGen = struct {
94669470 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
94679471 if (o.target.isWasm() and
94689472 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory) and
9469 dest_ptr_ty.isSlice(mod))
9473 dest_ptr_ty.isSlice(zcu))
94709474 {
94719475 const usize_zero = try o.builder.intValue(try o.lowerType(Type.usize), 0);
94729476 const cond = try self.cmp(.normal, .neq, Type.usize, len, usize_zero);
......@@ -9476,9 +9480,9 @@ pub const FuncGen = struct {
94769480 self.wip.cursor = .{ .block = memcpy_block };
94779481 _ = try self.wip.callMemCpy(
94789482 dest_ptr,
9479 dest_ptr_ty.ptrAlignment(pt).toLlvm(),
9483 dest_ptr_ty.ptrAlignment(zcu).toLlvm(),
94809484 src_ptr,
9481 src_ptr_ty.ptrAlignment(pt).toLlvm(),
9485 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
94829486 len,
94839487 access_kind,
94849488 );
......@@ -9489,9 +9493,9 @@ pub const FuncGen = struct {
94899493
94909494 _ = try self.wip.callMemCpy(
94919495 dest_ptr,
9492 dest_ptr_ty.ptrAlignment(pt).toLlvm(),
9496 dest_ptr_ty.ptrAlignment(zcu).toLlvm(),
94939497 src_ptr,
9494 src_ptr_ty.ptrAlignment(pt).toLlvm(),
9498 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
94959499 len,
94969500 access_kind,
94979501 );
......@@ -9501,10 +9505,10 @@ pub const FuncGen = struct {
95019505 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95029506 const o = self.ng.object;
95039507 const pt = o.pt;
9504 const mod = pt.zcu;
9508 const zcu = pt.zcu;
95059509 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9506 const un_ty = self.typeOf(bin_op.lhs).childType(mod);
9507 const layout = un_ty.unionGetLayout(pt);
9510 const un_ty = self.typeOf(bin_op.lhs).childType(zcu);
9511 const layout = un_ty.unionGetLayout(zcu);
95089512 if (layout.tag_size == 0) return .none;
95099513 const union_ptr = try self.resolveInst(bin_op.lhs);
95109514 const new_tag = try self.resolveInst(bin_op.rhs);
......@@ -9523,12 +9527,13 @@ pub const FuncGen = struct {
95239527 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95249528 const o = self.ng.object;
95259529 const pt = o.pt;
9530 const zcu = pt.zcu;
95269531 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
95279532 const un_ty = self.typeOf(ty_op.operand);
9528 const layout = un_ty.unionGetLayout(pt);
9533 const layout = un_ty.unionGetLayout(zcu);
95299534 if (layout.tag_size == 0) return .none;
95309535 const union_handle = try self.resolveInst(ty_op.operand);
9531 if (isByRef(un_ty, pt)) {
9536 if (isByRef(un_ty, zcu)) {
95329537 const llvm_un_ty = try o.lowerType(un_ty);
95339538 if (layout.payload_size == 0)
95349539 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");
......@@ -9597,10 +9602,10 @@ pub const FuncGen = struct {
95979602
95989603 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95999604 const o = self.ng.object;
9600 const mod = o.pt.zcu;
9605 const zcu = o.pt.zcu;
96019606 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
96029607 const operand_ty = self.typeOf(ty_op.operand);
9603 var bits = operand_ty.intInfo(mod).bits;
9608 var bits = operand_ty.intInfo(zcu).bits;
96049609 assert(bits % 8 == 0);
96059610
96069611 const inst_ty = self.typeOfIndex(inst);
......@@ -9611,8 +9616,8 @@ pub const FuncGen = struct {
96119616 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
96129617 // The truncated result at the end will be the correct bswap
96139618 const scalar_ty = try o.builder.intType(@intCast(bits + 8));
9614 if (operand_ty.zigTypeTag(mod) == .Vector) {
9615 const vec_len = operand_ty.vectorLen(mod);
9619 if (operand_ty.zigTypeTag(zcu) == .Vector) {
9620 const vec_len = operand_ty.vectorLen(zcu);
96169621 llvm_operand_ty = try o.builder.vectorType(.normal, vec_len, scalar_ty);
96179622 } else llvm_operand_ty = scalar_ty;
96189623
......@@ -9631,13 +9636,13 @@ pub const FuncGen = struct {
96319636
96329637 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96339638 const o = self.ng.object;
9634 const mod = o.pt.zcu;
9635 const ip = &mod.intern_pool;
9639 const zcu = o.pt.zcu;
9640 const ip = &zcu.intern_pool;
96369641 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
96379642 const operand = try self.resolveInst(ty_op.operand);
96389643 const error_set_ty = ty_op.ty.toType();
96399644
9640 const names = error_set_ty.errorSetNames(mod);
9645 const names = error_set_ty.errorSetNames(zcu);
96419646 const valid_block = try self.wip.block(@intCast(names.len), "Valid");
96429647 const invalid_block = try self.wip.block(1, "Invalid");
96439648 const end_block = try self.wip.block(2, "End");
......@@ -9790,14 +9795,14 @@ pub const FuncGen = struct {
97909795 fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
97919796 const o = self.ng.object;
97929797 const pt = o.pt;
9793 const mod = pt.zcu;
9798 const zcu = pt.zcu;
97949799 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
97959800 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
97969801 const a = try self.resolveInst(extra.a);
97979802 const b = try self.resolveInst(extra.b);
97989803 const mask = Value.fromInterned(extra.mask);
97999804 const mask_len = extra.mask_len;
9800 const a_len = self.typeOf(extra.a).vectorLen(mod);
9805 const a_len = self.typeOf(extra.a).vectorLen(zcu);
98019806
98029807 // LLVM uses integers larger than the length of the first array to
98039808 // index into the second array. This was deemed unnecessarily fragile
......@@ -9809,10 +9814,10 @@ pub const FuncGen = struct {
98099814
98109815 for (values, 0..) |*val, i| {
98119816 const elem = try mask.elemValue(pt, i);
9812 if (elem.isUndef(mod)) {
9817 if (elem.isUndef(zcu)) {
98139818 val.* = try o.builder.undefConst(.i32);
98149819 } else {
9815 const int = elem.toSignedInt(pt);
9820 const int = elem.toSignedInt(zcu);
98169821 const unsigned: u32 = @intCast(if (int >= 0) int else ~int + a_len);
98179822 val.* = try o.builder.intConst(.i32, unsigned);
98189823 }
......@@ -9899,8 +9904,8 @@ pub const FuncGen = struct {
98999904
99009905 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
99019906 const o = self.ng.object;
9902 const mod = o.pt.zcu;
9903 const target = mod.getTarget();
9907 const zcu = o.pt.zcu;
9908 const target = zcu.getTarget();
99049909
99059910 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
99069911 const operand = try self.resolveInst(reduce.operand);
......@@ -9916,13 +9921,13 @@ pub const FuncGen = struct {
99169921 .Xor => .@"vector.reduce.xor",
99179922 else => unreachable,
99189923 }, &.{llvm_operand_ty}, &.{operand}, ""),
9919 .Min, .Max => switch (scalar_ty.zigTypeTag(mod)) {
9924 .Min, .Max => switch (scalar_ty.zigTypeTag(zcu)) {
99209925 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
9921 .Min => if (scalar_ty.isSignedInt(mod))
9926 .Min => if (scalar_ty.isSignedInt(zcu))
99229927 .@"vector.reduce.smin"
99239928 else
99249929 .@"vector.reduce.umin",
9925 .Max => if (scalar_ty.isSignedInt(mod))
9930 .Max => if (scalar_ty.isSignedInt(zcu))
99269931 .@"vector.reduce.smax"
99279932 else
99289933 .@"vector.reduce.umax",
......@@ -9936,7 +9941,7 @@ pub const FuncGen = struct {
99369941 }, &.{llvm_operand_ty}, &.{operand}, ""),
99379942 else => unreachable,
99389943 },
9939 .Add, .Mul => switch (scalar_ty.zigTypeTag(mod)) {
9944 .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
99409945 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
99419946 .Add => .@"vector.reduce.add",
99429947 .Mul => .@"vector.reduce.mul",
......@@ -10004,21 +10009,21 @@ pub const FuncGen = struct {
1000410009 ))),
1000510010 else => unreachable,
1000610011 };
10007 return self.buildReducedCall(libc_fn, operand, operand_ty.vectorLen(mod), init_val);
10012 return self.buildReducedCall(libc_fn, operand, operand_ty.vectorLen(zcu), init_val);
1000810013 }
1000910014
1001010015 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1001110016 const o = self.ng.object;
1001210017 const pt = o.pt;
10013 const mod = pt.zcu;
10014 const ip = &mod.intern_pool;
10018 const zcu = pt.zcu;
10019 const ip = &zcu.intern_pool;
1001510020 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1001610021 const result_ty = self.typeOfIndex(inst);
10017 const len: usize = @intCast(result_ty.arrayLen(mod));
10022 const len: usize = @intCast(result_ty.arrayLen(zcu));
1001810023 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
1001910024 const llvm_result_ty = try o.lowerType(result_ty);
1002010025
10021 switch (result_ty.zigTypeTag(mod)) {
10026 switch (result_ty.zigTypeTag(zcu)) {
1002210027 .Vector => {
1002310028 var vector = try o.builder.poisonValue(llvm_result_ty);
1002410029 for (elements, 0..) |elem, i| {
......@@ -10029,21 +10034,21 @@ pub const FuncGen = struct {
1002910034 return vector;
1003010035 },
1003110036 .Struct => {
10032 if (mod.typeToPackedStruct(result_ty)) |struct_type| {
10037 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {
1003310038 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
1003410039 assert(backing_int_ty != .none);
10035 const big_bits = Type.fromInterned(backing_int_ty).bitSize(pt);
10040 const big_bits = Type.fromInterned(backing_int_ty).bitSize(zcu);
1003610041 const int_ty = try o.builder.intType(@intCast(big_bits));
1003710042 comptime assert(Type.packed_struct_layout_version == 2);
1003810043 var running_int = try o.builder.intValue(int_ty, 0);
1003910044 var running_bits: u16 = 0;
1004010045 for (elements, struct_type.field_types.get(ip)) |elem, field_ty| {
10041 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
10046 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
1004210047
1004310048 const non_int_val = try self.resolveInst(elem);
10044 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(pt));
10049 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(zcu));
1004510050 const small_int_ty = try o.builder.intType(ty_bit_size);
10046 const small_int_val = if (Type.fromInterned(field_ty).isPtrAtRuntime(mod))
10051 const small_int_val = if (Type.fromInterned(field_ty).isPtrAtRuntime(zcu))
1004710052 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
1004810053 else
1004910054 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
......@@ -10057,12 +10062,12 @@ pub const FuncGen = struct {
1005710062 return running_int;
1005810063 }
1005910064
10060 assert(result_ty.containerLayout(mod) != .@"packed");
10065 assert(result_ty.containerLayout(zcu) != .@"packed");
1006110066
10062 if (isByRef(result_ty, pt)) {
10067 if (isByRef(result_ty, zcu)) {
1006310068 // TODO in debug builds init to undef so that the padding will be 0xaa
1006410069 // even if we fully populate the fields.
10065 const alignment = result_ty.abiAlignment(pt).toLlvm();
10070 const alignment = result_ty.abiAlignment(zcu).toLlvm();
1006610071 const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment);
1006710072
1006810073 for (elements, 0..) |elem, i| {
......@@ -10075,7 +10080,7 @@ pub const FuncGen = struct {
1007510080 const field_ptr_ty = try pt.ptrType(.{
1007610081 .child = self.typeOf(elem).toIntern(),
1007710082 .flags = .{
10078 .alignment = result_ty.structFieldAlign(i, pt),
10083 .alignment = result_ty.structFieldAlign(i, zcu),
1007910084 },
1008010085 });
1008110086 try self.store(field_ptr, field_ptr_ty, llvm_elem, .none);
......@@ -10095,14 +10100,14 @@ pub const FuncGen = struct {
1009510100 }
1009610101 },
1009710102 .Array => {
10098 assert(isByRef(result_ty, pt));
10103 assert(isByRef(result_ty, zcu));
1009910104
1010010105 const llvm_usize = try o.lowerType(Type.usize);
1010110106 const usize_zero = try o.builder.intValue(llvm_usize, 0);
10102 const alignment = result_ty.abiAlignment(pt).toLlvm();
10107 const alignment = result_ty.abiAlignment(zcu).toLlvm();
1010310108 const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment);
1010410109
10105 const array_info = result_ty.arrayInfo(mod);
10110 const array_info = result_ty.arrayInfo(zcu);
1010610111 const elem_ptr_ty = try pt.ptrType(.{
1010710112 .child = array_info.elem_type.toIntern(),
1010810113 });
......@@ -10131,22 +10136,22 @@ pub const FuncGen = struct {
1013110136 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1013210137 const o = self.ng.object;
1013310138 const pt = o.pt;
10134 const mod = pt.zcu;
10135 const ip = &mod.intern_pool;
10139 const zcu = pt.zcu;
10140 const ip = &zcu.intern_pool;
1013610141 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1013710142 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1013810143 const union_ty = self.typeOfIndex(inst);
1013910144 const union_llvm_ty = try o.lowerType(union_ty);
10140 const layout = union_ty.unionGetLayout(pt);
10141 const union_obj = mod.typeToUnion(union_ty).?;
10145 const layout = union_ty.unionGetLayout(zcu);
10146 const union_obj = zcu.typeToUnion(union_ty).?;
1014210147
1014310148 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
10144 const big_bits = union_ty.bitSize(pt);
10149 const big_bits = union_ty.bitSize(zcu);
1014510150 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));
1014610151 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
1014710152 const non_int_val = try self.resolveInst(extra.init);
10148 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(pt)));
10149 const small_int_val = if (field_ty.isPtrAtRuntime(mod))
10153 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
10154 const small_int_val = if (field_ty.isPtrAtRuntime(zcu))
1015010155 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
1015110156 else
1015210157 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
......@@ -10154,9 +10159,9 @@ pub const FuncGen = struct {
1015410159 }
1015510160
1015610161 const tag_int_val = blk: {
10157 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
10162 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
1015810163 const union_field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];
10159 const enum_field_index = tag_ty.enumFieldIndex(union_field_name, mod).?;
10164 const enum_field_index = tag_ty.enumFieldIndex(union_field_name, zcu).?;
1016010165 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);
1016110166 break :blk try tag_val.intFromEnum(tag_ty, pt);
1016210167 };
......@@ -10164,12 +10169,12 @@ pub const FuncGen = struct {
1016410169 if (layout.tag_size == 0) {
1016510170 return .none;
1016610171 }
10167 assert(!isByRef(union_ty, pt));
10172 assert(!isByRef(union_ty, zcu));
1016810173 var big_int_space: Value.BigIntSpace = undefined;
10169 const tag_big_int = tag_int_val.toBigInt(&big_int_space, pt);
10174 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);
1017010175 return try o.builder.bigIntValue(union_llvm_ty, tag_big_int);
1017110176 }
10172 assert(isByRef(union_ty, pt));
10177 assert(isByRef(union_ty, zcu));
1017310178 // The llvm type of the alloca will be the named LLVM union type, and will not
1017410179 // necessarily match the format that we need, depending on which tag is active.
1017510180 // We must construct the correct unnamed struct type here, in order to then set
......@@ -10179,14 +10184,14 @@ pub const FuncGen = struct {
1017910184 const llvm_payload = try self.resolveInst(extra.init);
1018010185 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
1018110186 const field_llvm_ty = try o.lowerType(field_ty);
10182 const field_size = field_ty.abiSize(pt);
10183 const field_align = pt.unionFieldNormalAlignment(union_obj, extra.field_index);
10187 const field_size = field_ty.abiSize(zcu);
10188 const field_align = Type.unionFieldNormalAlignment(union_obj, extra.field_index, zcu);
1018410189 const llvm_usize = try o.lowerType(Type.usize);
1018510190 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1018610191
1018710192 const llvm_union_ty = t: {
1018810193 const payload_ty = p: {
10189 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
10194 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1019010195 const padding_len = layout.payload_size;
1019110196 break :p try o.builder.arrayType(padding_len, .i8);
1019210197 }
......@@ -10242,9 +10247,9 @@ pub const FuncGen = struct {
1024210247 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");
1024310248 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
1024410249 var big_int_space: Value.BigIntSpace = undefined;
10245 const tag_big_int = tag_int_val.toBigInt(&big_int_space, pt);
10250 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);
1024610251 const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int);
10247 const tag_alignment = Type.fromInterned(union_obj.enum_tag_ty).abiAlignment(pt).toLlvm();
10252 const tag_alignment = Type.fromInterned(union_obj.enum_tag_ty).abiAlignment(zcu).toLlvm();
1024810253 _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment);
1024910254 }
1025010255
......@@ -10270,8 +10275,8 @@ pub const FuncGen = struct {
1027010275 // by the target.
1027110276 // To work around this, don't emit llvm.prefetch in this case.
1027210277 // See https://bugs.llvm.org/show_bug.cgi?id=21037
10273 const mod = o.pt.zcu;
10274 const target = mod.getTarget();
10278 const zcu = o.pt.zcu;
10279 const target = zcu.getTarget();
1027510280 switch (prefetch.cache) {
1027610281 .instruction => switch (target.cpu.arch) {
1027710282 .x86_64,
......@@ -10397,7 +10402,7 @@ pub const FuncGen = struct {
1039710402 variable_index.setMutability(.constant, &o.builder);
1039810403 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
1039910404 variable_index.setAlignment(
10400 Type.slice_const_u8_sentinel_0.abiAlignment(pt).toLlvm(),
10405 Type.slice_const_u8_sentinel_0.abiAlignment(pt.zcu).toLlvm(),
1040110406 &o.builder,
1040210407 );
1040310408
......@@ -10436,15 +10441,15 @@ pub const FuncGen = struct {
1043610441 ) !Builder.Value {
1043710442 const o = fg.ng.object;
1043810443 const pt = o.pt;
10439 const mod = pt.zcu;
10440 const payload_ty = opt_ty.optionalChild(mod);
10444 const zcu = pt.zcu;
10445 const payload_ty = opt_ty.optionalChild(zcu);
1044110446
10442 if (isByRef(opt_ty, pt)) {
10447 if (isByRef(opt_ty, zcu)) {
1044310448 // We have a pointer and we need to return a pointer to the first field.
1044410449 const payload_ptr = try fg.wip.gepStruct(opt_llvm_ty, opt_handle, 0, "");
1044510450
10446 const payload_alignment = payload_ty.abiAlignment(pt).toLlvm();
10447 if (isByRef(payload_ty, pt)) {
10451 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
10452 if (isByRef(payload_ty, zcu)) {
1044810453 if (can_elide_load)
1044910454 return payload_ptr;
1045010455
......@@ -10453,7 +10458,7 @@ pub const FuncGen = struct {
1045310458 return fg.loadTruncate(.normal, payload_ty, payload_ptr, payload_alignment);
1045410459 }
1045510460
10456 assert(!isByRef(payload_ty, pt));
10461 assert(!isByRef(payload_ty, zcu));
1045710462 return fg.wip.extractValue(opt_handle, &.{0}, "");
1045810463 }
1045910464
......@@ -10465,11 +10470,12 @@ pub const FuncGen = struct {
1046510470 ) !Builder.Value {
1046610471 const o = self.ng.object;
1046710472 const pt = o.pt;
10473 const zcu = pt.zcu;
1046810474 const optional_llvm_ty = try o.lowerType(optional_ty);
1046910475 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");
1047010476
10471 if (isByRef(optional_ty, pt)) {
10472 const payload_alignment = optional_ty.abiAlignment(pt).toLlvm();
10477 if (isByRef(optional_ty, zcu)) {
10478 const payload_alignment = optional_ty.abiAlignment(pt.zcu).toLlvm();
1047310479 const alloca_inst = try self.buildAllocaWorkaround(optional_ty, payload_alignment);
1047410480
1047510481 {
......@@ -10497,15 +10503,15 @@ pub const FuncGen = struct {
1049710503 ) !Builder.Value {
1049810504 const o = self.ng.object;
1049910505 const pt = o.pt;
10500 const mod = pt.zcu;
10501 const struct_ty = struct_ptr_ty.childType(mod);
10502 switch (struct_ty.zigTypeTag(mod)) {
10503 .Struct => switch (struct_ty.containerLayout(mod)) {
10506 const zcu = pt.zcu;
10507 const struct_ty = struct_ptr_ty.childType(zcu);
10508 switch (struct_ty.zigTypeTag(zcu)) {
10509 .Struct => switch (struct_ty.containerLayout(zcu)) {
1050410510 .@"packed" => {
1050510511 const result_ty = self.typeOfIndex(inst);
10506 const result_ty_info = result_ty.ptrInfo(mod);
10507 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(mod);
10508 const struct_type = mod.typeToStruct(struct_ty).?;
10512 const result_ty_info = result_ty.ptrInfo(zcu);
10513 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu);
10514 const struct_type = zcu.typeToStruct(struct_ty).?;
1050910515
1051010516 if (result_ty_info.packed_offset.host_size != 0) {
1051110517 // From LLVM's perspective, a pointer to a packed struct and a pointer
......@@ -10535,15 +10541,15 @@ pub const FuncGen = struct {
1053510541 // the struct.
1053610542 const llvm_index = try o.builder.intValue(
1053710543 try o.lowerType(Type.usize),
10538 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(pt)),
10544 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)),
1053910545 );
1054010546 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");
1054110547 }
1054210548 },
1054310549 },
1054410550 .Union => {
10545 const layout = struct_ty.unionGetLayout(pt);
10546 if (layout.payload_size == 0 or struct_ty.containerLayout(mod) == .@"packed") return struct_ptr;
10551 const layout = struct_ty.unionGetLayout(zcu);
10552 if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr;
1054710553 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
1054810554 const union_llvm_ty = try o.lowerType(struct_ty);
1054910555 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");
......@@ -10566,9 +10572,9 @@ pub const FuncGen = struct {
1056610572
1056710573 const o = fg.ng.object;
1056810574 const pt = o.pt;
10569 const mod = pt.zcu;
10575 const zcu = pt.zcu;
1057010576 const payload_llvm_ty = try o.lowerType(payload_ty);
10571 const abi_size = payload_ty.abiSize(pt);
10577 const abi_size = payload_ty.abiSize(zcu);
1057210578
1057310579 // llvm bug workarounds:
1057410580 const workaround_explicit_mask = o.target.cpu.arch == .powerpc and abi_size >= 4;
......@@ -10580,7 +10586,7 @@ pub const FuncGen = struct {
1058010586 return try fg.wip.load(access_kind, payload_llvm_ty, payload_ptr, payload_alignment, "");
1058110587 }
1058210588
10583 const load_llvm_ty = if (payload_ty.isAbiInt(mod))
10589 const load_llvm_ty = if (payload_ty.isAbiInt(zcu))
1058410590 try o.builder.intType(@intCast(abi_size * 8))
1058510591 else
1058610592 payload_llvm_ty;
......@@ -10588,7 +10594,7 @@ pub const FuncGen = struct {
1058810594 const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .big)
1058910595 try fg.wip.bin(.lshr, loaded, try o.builder.intValue(
1059010596 load_llvm_ty,
10591 (payload_ty.abiSize(pt) - (std.math.divCeil(u64, payload_ty.bitSize(pt), 8) catch unreachable)) * 8,
10597 (payload_ty.abiSize(zcu) - (std.math.divCeil(u64, payload_ty.bitSize(zcu), 8) catch unreachable)) * 8,
1059210598 ), "")
1059310599 else
1059410600 loaded;
......@@ -10614,9 +10620,10 @@ pub const FuncGen = struct {
1061410620 const o = fg.ng.object;
1061510621 const pt = o.pt;
1061610622 //const pointee_llvm_ty = try o.lowerType(pointee_type);
10617 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment).max(pointee_type.abiAlignment(pt)).toLlvm();
10623 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)
10624 .max(pointee_type.abiAlignment(pt.zcu)).toLlvm();
1061810625 const result_ptr = try fg.buildAllocaWorkaround(pointee_type, result_align);
10619 const size_bytes = pointee_type.abiSize(pt);
10626 const size_bytes = pointee_type.abiSize(pt.zcu);
1062010627 _ = try fg.wip.callMemCpy(
1062110628 result_ptr,
1062210629 result_align,
......@@ -10634,15 +10641,15 @@ pub const FuncGen = struct {
1063410641 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {
1063510642 const o = self.ng.object;
1063610643 const pt = o.pt;
10637 const mod = pt.zcu;
10638 const info = ptr_ty.ptrInfo(mod);
10644 const zcu = pt.zcu;
10645 const info = ptr_ty.ptrInfo(zcu);
1063910646 const elem_ty = Type.fromInterned(info.child);
10640 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
10647 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
1064110648
1064210649 const ptr_alignment = (if (info.flags.alignment != .none)
1064310650 @as(InternPool.Alignment, info.flags.alignment)
1064410651 else
10645 elem_ty.abiAlignment(pt)).toLlvm();
10652 elem_ty.abiAlignment(zcu)).toLlvm();
1064610653
1064710654 const access_kind: Builder.MemoryAccessKind =
1064810655 if (info.flags.is_volatile) .@"volatile" else .normal;
......@@ -10658,7 +10665,7 @@ pub const FuncGen = struct {
1065810665 }
1065910666
1066010667 if (info.packed_offset.host_size == 0) {
10661 if (isByRef(elem_ty, pt)) {
10668 if (isByRef(elem_ty, zcu)) {
1066210669 return self.loadByRef(ptr, elem_ty, ptr_alignment, access_kind);
1066310670 }
1066410671 return self.loadTruncate(access_kind, elem_ty, ptr, ptr_alignment);
......@@ -10668,13 +10675,13 @@ pub const FuncGen = struct {
1066810675 const containing_int =
1066910676 try self.wip.load(access_kind, containing_int_ty, ptr, ptr_alignment, "");
1067010677
10671 const elem_bits = ptr_ty.childType(mod).bitSize(pt);
10678 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
1067210679 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);
1067310680 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
1067410681 const elem_llvm_ty = try o.lowerType(elem_ty);
1067510682
10676 if (isByRef(elem_ty, pt)) {
10677 const result_align = elem_ty.abiAlignment(pt).toLlvm();
10683 if (isByRef(elem_ty, zcu)) {
10684 const result_align = elem_ty.abiAlignment(zcu).toLlvm();
1067810685 const result_ptr = try self.buildAllocaWorkaround(elem_ty, result_align);
1067910686
1068010687 const same_size_int = try o.builder.intType(@intCast(elem_bits));
......@@ -10683,13 +10690,13 @@ pub const FuncGen = struct {
1068310690 return result_ptr;
1068410691 }
1068510692
10686 if (elem_ty.zigTypeTag(mod) == .Float or elem_ty.zigTypeTag(mod) == .Vector) {
10693 if (elem_ty.zigTypeTag(zcu) == .Float or elem_ty.zigTypeTag(zcu) == .Vector) {
1068710694 const same_size_int = try o.builder.intType(@intCast(elem_bits));
1068810695 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");
1068910696 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");
1069010697 }
1069110698
10692 if (elem_ty.isPtrAtRuntime(mod)) {
10699 if (elem_ty.isPtrAtRuntime(zcu)) {
1069310700 const same_size_int = try o.builder.intType(@intCast(elem_bits));
1069410701 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");
1069510702 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
......@@ -10707,13 +10714,13 @@ pub const FuncGen = struct {
1070710714 ) !void {
1070810715 const o = self.ng.object;
1070910716 const pt = o.pt;
10710 const mod = pt.zcu;
10711 const info = ptr_ty.ptrInfo(mod);
10717 const zcu = pt.zcu;
10718 const info = ptr_ty.ptrInfo(zcu);
1071210719 const elem_ty = Type.fromInterned(info.child);
10713 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
10720 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
1071410721 return;
1071510722 }
10716 const ptr_alignment = ptr_ty.ptrAlignment(pt).toLlvm();
10723 const ptr_alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
1071710724 const access_kind: Builder.MemoryAccessKind =
1071810725 if (info.flags.is_volatile) .@"volatile" else .normal;
1071910726
......@@ -10737,12 +10744,12 @@ pub const FuncGen = struct {
1073710744 assert(ordering == .none);
1073810745 const containing_int =
1073910746 try self.wip.load(access_kind, containing_int_ty, ptr, ptr_alignment, "");
10740 const elem_bits = ptr_ty.childType(mod).bitSize(pt);
10747 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
1074110748 const shift_amt = try o.builder.intConst(containing_int_ty, info.packed_offset.bit_offset);
1074210749 // Convert to equally-sized integer type in order to perform the bit
1074310750 // operations on the value to store
1074410751 const value_bits_type = try o.builder.intType(@intCast(elem_bits));
10745 const value_bits = if (elem_ty.isPtrAtRuntime(mod))
10752 const value_bits = if (elem_ty.isPtrAtRuntime(zcu))
1074610753 try self.wip.cast(.ptrtoint, elem, value_bits_type, "")
1074710754 else
1074810755 try self.wip.cast(.bitcast, elem, value_bits_type, "");
......@@ -10772,7 +10779,7 @@ pub const FuncGen = struct {
1077210779 _ = try self.wip.store(access_kind, ored_value, ptr, ptr_alignment);
1077310780 return;
1077410781 }
10775 if (!isByRef(elem_ty, pt)) {
10782 if (!isByRef(elem_ty, zcu)) {
1077610783 _ = try self.wip.storeAtomic(
1077710784 access_kind,
1077810785 elem,
......@@ -10788,8 +10795,8 @@ pub const FuncGen = struct {
1078810795 ptr,
1078910796 ptr_alignment,
1079010797 elem,
10791 elem_ty.abiAlignment(pt).toLlvm(),
10792 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(pt)),
10798 elem_ty.abiAlignment(zcu).toLlvm(),
10799 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)),
1079310800 access_kind,
1079410801 );
1079510802 }
......@@ -10816,12 +10823,12 @@ pub const FuncGen = struct {
1081610823 ) Allocator.Error!Builder.Value {
1081710824 const o = fg.ng.object;
1081810825 const pt = o.pt;
10819 const mod = pt.zcu;
10820 const target = mod.getTarget();
10826 const zcu = pt.zcu;
10827 const target = zcu.getTarget();
1082110828 if (!target_util.hasValgrindSupport(target)) return default_value;
1082210829
1082310830 const llvm_usize = try o.lowerType(Type.usize);
10824 const usize_alignment = Type.usize.abiAlignment(pt).toLlvm();
10831 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
1082510832
1082610833 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);
1082710834 const array_ptr = if (fg.valgrind_client_request_array == .none) a: {
......@@ -10882,14 +10889,14 @@ pub const FuncGen = struct {
1088210889
1088310890 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
1088410891 const o = fg.ng.object;
10885 const mod = o.pt.zcu;
10886 return fg.air.typeOf(inst, &mod.intern_pool);
10892 const zcu = o.pt.zcu;
10893 return fg.air.typeOf(inst, &zcu.intern_pool);
1088710894 }
1088810895
1088910896 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
1089010897 const o = fg.ng.object;
10891 const mod = o.pt.zcu;
10892 return fg.air.typeOfIndex(inst, &mod.intern_pool);
10898 const zcu = o.pt.zcu;
10899 return fg.air.typeOfIndex(inst, &zcu.intern_pool);
1089310900 }
1089410901};
1089510902
......@@ -11059,12 +11066,12 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ
1105911066 };
1106011067}
1106111068
11062fn returnTypeByRef(pt: Zcu.PerThread, target: std.Target, ty: Type) bool {
11063 if (isByRef(ty, pt)) {
11069fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {
11070 if (isByRef(ty, zcu)) {
1106411071 return true;
1106511072 } else if (target.cpu.arch.isX86() and
1106611073 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and
11067 ty.totalVectorBits(pt) >= 512)
11074 ty.totalVectorBits(zcu) >= 512)
1106811075 {
1106911076 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns
1107011077 // "512-bit vector arguments require 'evex512' for AVX512"
......@@ -11074,38 +11081,38 @@ fn returnTypeByRef(pt: Zcu.PerThread, target: std.Target, ty: Type) bool {
1107411081 }
1107511082}
1107611083
11077fn firstParamSRet(fn_info: InternPool.Key.FuncType, pt: Zcu.PerThread, target: std.Target) bool {
11084fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Target) bool {
1107811085 const return_type = Type.fromInterned(fn_info.return_type);
11079 if (!return_type.hasRuntimeBitsIgnoreComptime(pt)) return false;
11086 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;
1108011087
1108111088 return switch (fn_info.cc) {
11082 .Unspecified, .Inline => returnTypeByRef(pt, target, return_type),
11089 .Unspecified, .Inline => returnTypeByRef(zcu, target, return_type),
1108311090 .C => switch (target.cpu.arch) {
1108411091 .mips, .mipsel => false,
11085 .x86 => isByRef(return_type, pt),
11092 .x86 => isByRef(return_type, zcu),
1108611093 .x86_64 => switch (target.os.tag) {
11087 .windows => x86_64_abi.classifyWindows(return_type, pt) == .memory,
11088 else => firstParamSRetSystemV(return_type, pt, target),
11094 .windows => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
11095 else => firstParamSRetSystemV(return_type, zcu, target),
1108911096 },
11090 .wasm32 => wasm_c_abi.classifyType(return_type, pt)[0] == .indirect,
11091 .aarch64, .aarch64_be => aarch64_c_abi.classifyType(return_type, pt) == .memory,
11092 .arm, .armeb => switch (arm_c_abi.classifyType(return_type, pt, .ret)) {
11097 .wasm32 => wasm_c_abi.classifyType(return_type, zcu)[0] == .indirect,
11098 .aarch64, .aarch64_be => aarch64_c_abi.classifyType(return_type, zcu) == .memory,
11099 .arm, .armeb => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1109311100 .memory, .i64_array => true,
1109411101 .i32_array => |size| size != 1,
1109511102 .byval => false,
1109611103 },
11097 .riscv32, .riscv64 => riscv_c_abi.classifyType(return_type, pt) == .memory,
11104 .riscv32, .riscv64 => riscv_c_abi.classifyType(return_type, zcu) == .memory,
1109811105 else => false, // TODO investigate C ABI for other architectures
1109911106 },
11100 .SysV => firstParamSRetSystemV(return_type, pt, target),
11101 .Win64 => x86_64_abi.classifyWindows(return_type, pt) == .memory,
11102 .Stdcall => !isScalar(pt.zcu, return_type),
11107 .SysV => firstParamSRetSystemV(return_type, zcu, target),
11108 .Win64 => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
11109 .Stdcall => !isScalar(zcu, return_type),
1110311110 else => false,
1110411111 };
1110511112}
1110611113
11107fn firstParamSRetSystemV(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
11108 const class = x86_64_abi.classifySystemV(ty, pt, target, .ret);
11114fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: std.Target) bool {
11115 const class = x86_64_abi.classifySystemV(ty, zcu, target, .ret);
1110911116 if (class[0] == .memory) return true;
1111011117 if (class[0] == .x87 and class[2] != .none) return true;
1111111118 return false;
......@@ -11116,62 +11123,62 @@ fn firstParamSRetSystemV(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
1111611123/// be effectively bitcasted to the actual return type.
1111711124fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1111811125 const pt = o.pt;
11119 const mod = pt.zcu;
11126 const zcu = pt.zcu;
1112011127 const return_type = Type.fromInterned(fn_info.return_type);
11121 if (!return_type.hasRuntimeBitsIgnoreComptime(pt)) {
11128 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
1112211129 // If the return type is an error set or an error union, then we make this
1112311130 // anyerror return type instead, so that it can be coerced into a function
1112411131 // pointer type which has anyerror as the return type.
11125 return if (return_type.isError(mod)) try o.errorIntType() else .void;
11132 return if (return_type.isError(zcu)) try o.errorIntType() else .void;
1112611133 }
11127 const target = mod.getTarget();
11134 const target = zcu.getTarget();
1112811135 switch (fn_info.cc) {
1112911136 .Unspecified,
1113011137 .Inline,
11131 => return if (returnTypeByRef(pt, target, return_type)) .void else o.lowerType(return_type),
11138 => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(return_type),
1113211139
1113311140 .C => {
1113411141 switch (target.cpu.arch) {
1113511142 .mips, .mipsel => return o.lowerType(return_type),
11136 .x86 => return if (isByRef(return_type, pt)) .void else o.lowerType(return_type),
11143 .x86 => return if (isByRef(return_type, zcu)) .void else o.lowerType(return_type),
1113711144 .x86_64 => switch (target.os.tag) {
1113811145 .windows => return lowerWin64FnRetTy(o, fn_info),
1113911146 else => return lowerSystemVFnRetTy(o, fn_info),
1114011147 },
1114111148 .wasm32 => {
11142 if (isScalar(mod, return_type)) {
11149 if (isScalar(zcu, return_type)) {
1114311150 return o.lowerType(return_type);
1114411151 }
11145 const classes = wasm_c_abi.classifyType(return_type, pt);
11152 const classes = wasm_c_abi.classifyType(return_type, zcu);
1114611153 if (classes[0] == .indirect or classes[0] == .none) {
1114711154 return .void;
1114811155 }
1114911156
1115011157 assert(classes[0] == .direct and classes[1] == .none);
11151 const scalar_type = wasm_c_abi.scalarType(return_type, pt);
11152 return o.builder.intType(@intCast(scalar_type.abiSize(pt) * 8));
11158 const scalar_type = wasm_c_abi.scalarType(return_type, zcu);
11159 return o.builder.intType(@intCast(scalar_type.abiSize(zcu) * 8));
1115311160 },
1115411161 .aarch64, .aarch64_be => {
11155 switch (aarch64_c_abi.classifyType(return_type, pt)) {
11162 switch (aarch64_c_abi.classifyType(return_type, zcu)) {
1115611163 .memory => return .void,
1115711164 .float_array => return o.lowerType(return_type),
1115811165 .byval => return o.lowerType(return_type),
11159 .integer => return o.builder.intType(@intCast(return_type.bitSize(pt))),
11166 .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))),
1116011167 .double_integer => return o.builder.arrayType(2, .i64),
1116111168 }
1116211169 },
1116311170 .arm, .armeb => {
11164 switch (arm_c_abi.classifyType(return_type, pt, .ret)) {
11171 switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1116511172 .memory, .i64_array => return .void,
1116611173 .i32_array => |len| return if (len == 1) .i32 else .void,
1116711174 .byval => return o.lowerType(return_type),
1116811175 }
1116911176 },
1117011177 .riscv32, .riscv64 => {
11171 switch (riscv_c_abi.classifyType(return_type, pt)) {
11178 switch (riscv_c_abi.classifyType(return_type, zcu)) {
1117211179 .memory => return .void,
1117311180 .integer => {
11174 return o.builder.intType(@intCast(return_type.bitSize(pt)));
11181 return o.builder.intType(@intCast(return_type.bitSize(zcu)));
1117511182 },
1117611183 .double_integer => {
1117711184 return o.builder.structType(.normal, &.{ .i64, .i64 });
......@@ -11180,9 +11187,9 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1118011187 .fields => {
1118111188 var types_len: usize = 0;
1118211189 var types: [8]Builder.Type = undefined;
11183 for (0..return_type.structFieldCount(mod)) |field_index| {
11184 const field_ty = return_type.structFieldType(field_index, mod);
11185 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
11190 for (0..return_type.structFieldCount(zcu)) |field_index| {
11191 const field_ty = return_type.structFieldType(field_index, zcu);
11192 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1118611193 types[types_len] = try o.lowerType(field_ty);
1118711194 types_len += 1;
1118811195 }
......@@ -11196,20 +11203,20 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1119611203 },
1119711204 .Win64 => return lowerWin64FnRetTy(o, fn_info),
1119811205 .SysV => return lowerSystemVFnRetTy(o, fn_info),
11199 .Stdcall => return if (isScalar(mod, return_type)) o.lowerType(return_type) else .void,
11206 .Stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void,
1120011207 else => return o.lowerType(return_type),
1120111208 }
1120211209}
1120311210
1120411211fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
11205 const pt = o.pt;
11212 const zcu = o.pt.zcu;
1120611213 const return_type = Type.fromInterned(fn_info.return_type);
11207 switch (x86_64_abi.classifyWindows(return_type, pt)) {
11214 switch (x86_64_abi.classifyWindows(return_type, zcu)) {
1120811215 .integer => {
11209 if (isScalar(pt.zcu, return_type)) {
11216 if (isScalar(zcu, return_type)) {
1121011217 return o.lowerType(return_type);
1121111218 } else {
11212 return o.builder.intType(@intCast(return_type.abiSize(pt) * 8));
11219 return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8));
1121311220 }
1121411221 },
1121511222 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),
......@@ -11221,14 +11228,14 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Err
1122111228
1122211229fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1122311230 const pt = o.pt;
11224 const mod = pt.zcu;
11225 const ip = &mod.intern_pool;
11231 const zcu = pt.zcu;
11232 const ip = &zcu.intern_pool;
1122611233 const return_type = Type.fromInterned(fn_info.return_type);
11227 if (isScalar(mod, return_type)) {
11234 if (isScalar(zcu, return_type)) {
1122811235 return o.lowerType(return_type);
1122911236 }
11230 const target = mod.getTarget();
11231 const classes = x86_64_abi.classifySystemV(return_type, pt, target, .ret);
11237 const target = zcu.getTarget();
11238 const classes = x86_64_abi.classifySystemV(return_type, zcu, target, .ret);
1123211239 if (classes[0] == .memory) return .void;
1123311240 var types_index: u32 = 0;
1123411241 var types_buffer: [8]Builder.Type = undefined;
......@@ -11345,7 +11352,7 @@ const ParamTypeIterator = struct {
1134511352 const zcu = pt.zcu;
1134611353 const target = zcu.getTarget();
1134711354
11348 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
11355 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1134911356 it.zig_index += 1;
1135011357 return .no_bits;
1135111358 }
......@@ -11358,11 +11365,11 @@ const ParamTypeIterator = struct {
1135811365 {
1135911366 it.llvm_index += 1;
1136011367 return .slice;
11361 } else if (isByRef(ty, pt)) {
11368 } else if (isByRef(ty, zcu)) {
1136211369 return .byref;
1136311370 } else if (target.cpu.arch.isX86() and
1136411371 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and
11365 ty.totalVectorBits(pt) >= 512)
11372 ty.totalVectorBits(zcu) >= 512)
1136611373 {
1136711374 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns
1136811375 // "512-bit vector arguments require 'evex512' for AVX512"
......@@ -11390,7 +11397,7 @@ const ParamTypeIterator = struct {
1139011397 if (isScalar(zcu, ty)) {
1139111398 return .byval;
1139211399 }
11393 const classes = wasm_c_abi.classifyType(ty, pt);
11400 const classes = wasm_c_abi.classifyType(ty, zcu);
1139411401 if (classes[0] == .indirect) {
1139511402 return .byref;
1139611403 }
......@@ -11399,7 +11406,7 @@ const ParamTypeIterator = struct {
1139911406 .aarch64, .aarch64_be => {
1140011407 it.zig_index += 1;
1140111408 it.llvm_index += 1;
11402 switch (aarch64_c_abi.classifyType(ty, pt)) {
11409 switch (aarch64_c_abi.classifyType(ty, zcu)) {
1140311410 .memory => return .byref_mut,
1140411411 .float_array => |len| return Lowering{ .float_array = len },
1140511412 .byval => return .byval,
......@@ -11414,7 +11421,7 @@ const ParamTypeIterator = struct {
1141411421 .arm, .armeb => {
1141511422 it.zig_index += 1;
1141611423 it.llvm_index += 1;
11417 switch (arm_c_abi.classifyType(ty, pt, .arg)) {
11424 switch (arm_c_abi.classifyType(ty, zcu, .arg)) {
1141811425 .memory => {
1141911426 it.byval_attr = true;
1142011427 return .byref;
......@@ -11429,7 +11436,7 @@ const ParamTypeIterator = struct {
1142911436 it.llvm_index += 1;
1143011437 if (ty.toIntern() == .f16_type and
1143111438 !std.Target.riscv.featureSetHas(target.cpu.features, .d)) return .as_u16;
11432 switch (riscv_c_abi.classifyType(ty, pt)) {
11439 switch (riscv_c_abi.classifyType(ty, zcu)) {
1143311440 .memory => return .byref_mut,
1143411441 .byval => return .byval,
1143511442 .integer => return .abi_sized_int,
......@@ -11438,7 +11445,7 @@ const ParamTypeIterator = struct {
1143811445 it.types_len = 0;
1143911446 for (0..ty.structFieldCount(zcu)) |field_index| {
1144011447 const field_ty = ty.structFieldType(field_index, zcu);
11441 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
11448 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1144211449 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);
1144311450 it.types_len += 1;
1144411451 }
......@@ -11476,10 +11483,10 @@ const ParamTypeIterator = struct {
1147611483 }
1147711484
1147811485 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {
11479 const pt = it.object.pt;
11480 switch (x86_64_abi.classifyWindows(ty, pt)) {
11486 const zcu = it.object.pt.zcu;
11487 switch (x86_64_abi.classifyWindows(ty, zcu)) {
1148111488 .integer => {
11482 if (isScalar(pt.zcu, ty)) {
11489 if (isScalar(zcu, ty)) {
1148311490 it.zig_index += 1;
1148411491 it.llvm_index += 1;
1148511492 return .byval;
......@@ -11509,17 +11516,17 @@ const ParamTypeIterator = struct {
1150911516 }
1151011517
1151111518 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
11512 const pt = it.object.pt;
11513 const ip = &pt.zcu.intern_pool;
11514 const target = pt.zcu.getTarget();
11515 const classes = x86_64_abi.classifySystemV(ty, pt, target, .arg);
11519 const zcu = it.object.pt.zcu;
11520 const ip = &zcu.intern_pool;
11521 const target = zcu.getTarget();
11522 const classes = x86_64_abi.classifySystemV(ty, zcu, target, .arg);
1151611523 if (classes[0] == .memory) {
1151711524 it.zig_index += 1;
1151811525 it.llvm_index += 1;
1151911526 it.byval_attr = true;
1152011527 return .byref;
1152111528 }
11522 if (isScalar(pt.zcu, ty)) {
11529 if (isScalar(zcu, ty)) {
1152311530 it.zig_index += 1;
1152411531 it.llvm_index += 1;
1152511532 return .byval;
......@@ -11620,17 +11627,17 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp
1162011627
1162111628fn ccAbiPromoteInt(
1162211629 cc: std.builtin.CallingConvention,
11623 mod: *Zcu,
11630 zcu: *Zcu,
1162411631 ty: Type,
1162511632) ?std.builtin.Signedness {
11626 const target = mod.getTarget();
11633 const target = zcu.getTarget();
1162711634 switch (cc) {
1162811635 .Unspecified, .Inline, .Async => return null,
1162911636 else => {},
1163011637 }
11631 const int_info = switch (ty.zigTypeTag(mod)) {
11632 .Bool => Type.u1.intInfo(mod),
11633 .Int, .Enum, .ErrorSet => ty.intInfo(mod),
11638 const int_info = switch (ty.zigTypeTag(zcu)) {
11639 .Bool => Type.u1.intInfo(zcu),
11640 .Int, .Enum, .ErrorSet => ty.intInfo(zcu),
1163411641 else => return null,
1163511642 };
1163611643 return switch (target.os.tag) {
......@@ -11668,13 +11675,13 @@ fn ccAbiPromoteInt(
1166811675
1166911676/// This is the one source of truth for whether a type is passed around as an LLVM pointer,
1167011677/// or as an LLVM value.
11671fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
11678fn isByRef(ty: Type, zcu: *Zcu) bool {
1167211679 // For tuples and structs, if there are more than this many non-void
1167311680 // fields, then we make it byref, otherwise byval.
1167411681 const max_fields_byval = 0;
11675 const ip = &pt.zcu.intern_pool;
11682 const ip = &zcu.intern_pool;
1167611683
11677 switch (ty.zigTypeTag(pt.zcu)) {
11684 switch (ty.zigTypeTag(zcu)) {
1167811685 .Type,
1167911686 .ComptimeInt,
1168011687 .ComptimeFloat,
......@@ -11697,17 +11704,17 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1169711704 .AnyFrame,
1169811705 => return false,
1169911706
11700 .Array, .Frame => return ty.hasRuntimeBits(pt),
11707 .Array, .Frame => return ty.hasRuntimeBits(zcu),
1170111708 .Struct => {
1170211709 const struct_type = switch (ip.indexToKey(ty.toIntern())) {
1170311710 .anon_struct_type => |tuple| {
1170411711 var count: usize = 0;
1170511712 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {
11706 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
11713 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
1170711714
1170811715 count += 1;
1170911716 if (count > max_fields_byval) return true;
11710 if (isByRef(Type.fromInterned(field_ty), pt)) return true;
11717 if (isByRef(Type.fromInterned(field_ty), zcu)) return true;
1171111718 }
1171211719 return false;
1171311720 },
......@@ -11725,27 +11732,27 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1172511732 count += 1;
1172611733 if (count > max_fields_byval) return true;
1172711734 const field_ty = Type.fromInterned(field_types[field_index]);
11728 if (isByRef(field_ty, pt)) return true;
11735 if (isByRef(field_ty, zcu)) return true;
1172911736 }
1173011737 return false;
1173111738 },
11732 .Union => switch (ty.containerLayout(pt.zcu)) {
11739 .Union => switch (ty.containerLayout(zcu)) {
1173311740 .@"packed" => return false,
11734 else => return ty.hasRuntimeBits(pt),
11741 else => return ty.hasRuntimeBits(zcu),
1173511742 },
1173611743 .ErrorUnion => {
11737 const payload_ty = ty.errorUnionPayload(pt.zcu);
11738 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
11744 const payload_ty = ty.errorUnionPayload(zcu);
11745 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1173911746 return false;
1174011747 }
1174111748 return true;
1174211749 },
1174311750 .Optional => {
11744 const payload_ty = ty.optionalChild(pt.zcu);
11745 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
11751 const payload_ty = ty.optionalChild(zcu);
11752 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1174611753 return false;
1174711754 }
11748 if (ty.optionalReprIsPayload(pt.zcu)) {
11755 if (ty.optionalReprIsPayload(zcu)) {
1174911756 return false;
1175011757 }
1175111758 return true;
......@@ -11753,8 +11760,8 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1175311760 }
1175411761}
1175511762
11756fn isScalar(mod: *Zcu, ty: Type) bool {
11757 return switch (ty.zigTypeTag(mod)) {
11763fn isScalar(zcu: *Zcu, ty: Type) bool {
11764 return switch (ty.zigTypeTag(zcu)) {
1175811765 .Void,
1175911766 .Bool,
1176011767 .NoReturn,
......@@ -11768,8 +11775,8 @@ fn isScalar(mod: *Zcu, ty: Type) bool {
1176811775 .Vector,
1176911776 => true,
1177011777
11771 .Struct => ty.containerLayout(mod) == .@"packed",
11772 .Union => ty.containerLayout(mod) == .@"packed",
11778 .Struct => ty.containerLayout(zcu) == .@"packed",
11779 .Union => ty.containerLayout(zcu) == .@"packed",
1177311780 else => false,
1177411781 };
1177511782}
......@@ -11892,13 +11899,15 @@ fn buildAllocaInner(
1189211899}
1189311900
1189411901fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {
11902 const zcu = pt.zcu;
1189511903 const err_int_ty = try pt.errorIntType();
11896 return @intFromBool(err_int_ty.abiAlignment(pt).compare(.gt, payload_ty.abiAlignment(pt)));
11904 return @intFromBool(err_int_ty.abiAlignment(zcu).compare(.gt, payload_ty.abiAlignment(zcu)));
1189711905}
1189811906
1189911907fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {
11908 const zcu = pt.zcu;
1190011909 const err_int_ty = try pt.errorIntType();
11901 return @intFromBool(err_int_ty.abiAlignment(pt).compare(.lte, payload_ty.abiAlignment(pt)));
11910 return @intFromBool(err_int_ty.abiAlignment(zcu).compare(.lte, payload_ty.abiAlignment(zcu)));
1190211911}
1190311912
1190411913/// Returns true for asm constraint (e.g. "=*m", "=r") if it accepts a memory location
src/codegen/spirv.zig+334-333
......@@ -436,16 +436,16 @@ const NavGen = struct {
436436 /// Fetch the result-id for a previously generated instruction or constant.
437437 fn resolve(self: *NavGen, inst: Air.Inst.Ref) !IdRef {
438438 const pt = self.pt;
439 const mod = pt.zcu;
439 const zcu = pt.zcu;
440440 if (try self.air.value(inst, pt)) |val| {
441441 const ty = self.typeOf(inst);
442 if (ty.zigTypeTag(mod) == .Fn) {
443 const fn_nav = switch (mod.intern_pool.indexToKey(val.ip_index)) {
442 if (ty.zigTypeTag(zcu) == .Fn) {
443 const fn_nav = switch (zcu.intern_pool.indexToKey(val.ip_index)) {
444444 .@"extern" => |@"extern"| @"extern".owner_nav,
445445 .func => |func| func.owner_nav,
446446 else => unreachable,
447447 };
448 const spv_decl_index = try self.object.resolveNav(mod, fn_nav);
448 const spv_decl_index = try self.object.resolveNav(zcu, fn_nav);
449449 try self.func.decl_deps.put(self.spv.gpa, spv_decl_index, {});
450450 return self.spv.declPtr(spv_decl_index).result_id;
451451 }
......@@ -459,8 +459,8 @@ const NavGen = struct {
459459 fn resolveUav(self: *NavGen, val: InternPool.Index) !IdRef {
460460 // TODO: This cannot be a function at this point, but it should probably be handled anyway.
461461
462 const mod = self.pt.zcu;
463 const ty = Type.fromInterned(mod.intern_pool.typeOf(val));
462 const zcu = self.pt.zcu;
463 const ty = Type.fromInterned(zcu.intern_pool.typeOf(val));
464464 const decl_ptr_ty_id = try self.ptrType(ty, .Generic);
465465
466466 const spv_decl_index = blk: {
......@@ -639,15 +639,15 @@ const NavGen = struct {
639639
640640 /// Checks whether the type can be directly translated to SPIR-V vectors
641641 fn isSpvVector(self: *NavGen, ty: Type) bool {
642 const mod = self.pt.zcu;
642 const zcu = self.pt.zcu;
643643 const target = self.getTarget();
644 if (ty.zigTypeTag(mod) != .Vector) return false;
644 if (ty.zigTypeTag(zcu) != .Vector) return false;
645645
646646 // TODO: This check must be expanded for types that can be represented
647647 // as integers (enums / packed structs?) and types that are represented
648648 // by multiple SPIR-V values.
649 const scalar_ty = ty.scalarType(mod);
650 switch (scalar_ty.zigTypeTag(mod)) {
649 const scalar_ty = ty.scalarType(zcu);
650 switch (scalar_ty.zigTypeTag(zcu)) {
651651 .Bool,
652652 .Int,
653653 .Float,
......@@ -655,24 +655,24 @@ const NavGen = struct {
655655 else => return false,
656656 }
657657
658 const elem_ty = ty.childType(mod);
658 const elem_ty = ty.childType(zcu);
659659
660 const len = ty.vectorLen(mod);
661 const is_scalar = elem_ty.isNumeric(mod) or elem_ty.toIntern() == .bool_type;
660 const len = ty.vectorLen(zcu);
661 const is_scalar = elem_ty.isNumeric(zcu) or elem_ty.toIntern() == .bool_type;
662662 const spirv_len = len > 1 and len <= 4;
663663 const opencl_len = if (target.os.tag == .opencl) (len == 8 or len == 16) else false;
664664 return is_scalar and (spirv_len or opencl_len);
665665 }
666666
667667 fn arithmeticTypeInfo(self: *NavGen, ty: Type) ArithmeticTypeInfo {
668 const mod = self.pt.zcu;
668 const zcu = self.pt.zcu;
669669 const target = self.getTarget();
670 var scalar_ty = ty.scalarType(mod);
671 if (scalar_ty.zigTypeTag(mod) == .Enum) {
672 scalar_ty = scalar_ty.intTagType(mod);
670 var scalar_ty = ty.scalarType(zcu);
671 if (scalar_ty.zigTypeTag(zcu) == .Enum) {
672 scalar_ty = scalar_ty.intTagType(zcu);
673673 }
674 const vector_len = if (ty.isVector(mod)) ty.vectorLen(mod) else null;
675 return switch (scalar_ty.zigTypeTag(mod)) {
674 const vector_len = if (ty.isVector(zcu)) ty.vectorLen(zcu) else null;
675 return switch (scalar_ty.zigTypeTag(zcu)) {
676676 .Bool => ArithmeticTypeInfo{
677677 .bits = 1, // Doesn't matter for this class.
678678 .backing_bits = self.backingIntBits(1).?,
......@@ -688,7 +688,7 @@ const NavGen = struct {
688688 .class = .float,
689689 },
690690 .Int => blk: {
691 const int_info = scalar_ty.intInfo(mod);
691 const int_info = scalar_ty.intInfo(zcu);
692692 // TODO: Maybe it's useful to also return this value.
693693 const maybe_backing_bits = self.backingIntBits(int_info.bits);
694694 break :blk ArithmeticTypeInfo{
......@@ -741,9 +741,9 @@ const NavGen = struct {
741741 /// the value to an unsigned int first for Kernels.
742742 fn constInt(self: *NavGen, ty: Type, value: anytype, repr: Repr) !IdRef {
743743 // TODO: Cache?
744 const mod = self.pt.zcu;
745 const scalar_ty = ty.scalarType(mod);
746 const int_info = scalar_ty.intInfo(mod);
744 const zcu = self.pt.zcu;
745 const scalar_ty = ty.scalarType(zcu);
746 const int_info = scalar_ty.intInfo(zcu);
747747 // Use backing bits so that negatives are sign extended
748748 const backing_bits = self.backingIntBits(int_info.bits).?; // Assertion failure means big int
749749
......@@ -783,11 +783,11 @@ const NavGen = struct {
783783 else => unreachable, // TODO: Large integer constants
784784 }
785785
786 if (!ty.isVector(mod)) {
786 if (!ty.isVector(zcu)) {
787787 return result_id;
788788 }
789789
790 const n = ty.vectorLen(mod);
790 const n = ty.vectorLen(zcu);
791791 const ids = try self.gpa.alloc(IdRef, n);
792792 defer self.gpa.free(ids);
793793 @memset(ids, result_id);
......@@ -821,8 +821,8 @@ const NavGen = struct {
821821 /// Construct a vector at runtime.
822822 /// ty must be an vector type.
823823 fn constructVector(self: *NavGen, ty: Type, constituents: []const IdRef) !IdRef {
824 const mod = self.pt.zcu;
825 assert(ty.vectorLen(mod) == constituents.len);
824 const zcu = self.pt.zcu;
825 assert(ty.vectorLen(zcu) == constituents.len);
826826
827827 // Note: older versions of the Khronos SPRIV-LLVM translator crash on this instruction
828828 // because it cannot construct structs which' operands are not constant.
......@@ -845,8 +845,8 @@ const NavGen = struct {
845845 /// Construct a vector at runtime with all lanes set to the same value.
846846 /// ty must be an vector type.
847847 fn constructVectorSplat(self: *NavGen, ty: Type, constituent: IdRef) !IdRef {
848 const mod = self.pt.zcu;
849 const n = ty.vectorLen(mod);
848 const zcu = self.pt.zcu;
849 const n = ty.vectorLen(zcu);
850850
851851 const constituents = try self.gpa.alloc(IdRef, n);
852852 defer self.gpa.free(constituents);
......@@ -884,13 +884,13 @@ const NavGen = struct {
884884 }
885885
886886 const pt = self.pt;
887 const mod = pt.zcu;
887 const zcu = pt.zcu;
888888 const target = self.getTarget();
889889 const result_ty_id = try self.resolveType(ty, repr);
890 const ip = &mod.intern_pool;
890 const ip = &zcu.intern_pool;
891891
892892 log.debug("lowering constant: ty = {}, val = {}", .{ ty.fmt(pt), val.fmtValue(pt) });
893 if (val.isUndefDeep(mod)) {
893 if (val.isUndefDeep(zcu)) {
894894 return self.spv.constUndef(result_ty_id);
895895 }
896896
......@@ -937,17 +937,17 @@ const NavGen = struct {
937937 .false, .true => break :cache try self.constBool(val.toBool(), repr),
938938 },
939939 .int => {
940 if (ty.isSignedInt(mod)) {
941 break :cache try self.constInt(ty, val.toSignedInt(pt), repr);
940 if (ty.isSignedInt(zcu)) {
941 break :cache try self.constInt(ty, val.toSignedInt(zcu), repr);
942942 } else {
943 break :cache try self.constInt(ty, val.toUnsignedInt(pt), repr);
943 break :cache try self.constInt(ty, val.toUnsignedInt(zcu), repr);
944944 }
945945 },
946946 .float => {
947947 const lit: spec.LiteralContextDependentNumber = switch (ty.floatBits(target)) {
948 16 => .{ .uint32 = @as(u16, @bitCast(val.toFloat(f16, pt))) },
949 32 => .{ .float32 = val.toFloat(f32, pt) },
950 64 => .{ .float64 = val.toFloat(f64, pt) },
948 16 => .{ .uint32 = @as(u16, @bitCast(val.toFloat(f16, zcu))) },
949 32 => .{ .float32 = val.toFloat(f32, zcu) },
950 64 => .{ .float64 = val.toFloat(f64, zcu) },
951951 80, 128 => unreachable, // TODO
952952 else => unreachable,
953953 };
......@@ -968,17 +968,17 @@ const NavGen = struct {
968968 // allows it. For now, just generate it here regardless.
969969 const err_int_ty = try pt.errorIntType();
970970 const err_ty = switch (error_union.val) {
971 .err_name => ty.errorUnionSet(mod),
971 .err_name => ty.errorUnionSet(zcu),
972972 .payload => err_int_ty,
973973 };
974974 const err_val = switch (error_union.val) {
975975 .err_name => |err_name| Value.fromInterned(try pt.intern(.{ .err = .{
976 .ty = ty.errorUnionSet(mod).toIntern(),
976 .ty = ty.errorUnionSet(zcu).toIntern(),
977977 .name = err_name,
978978 } })),
979979 .payload => try pt.intValue(err_int_ty, 0),
980980 };
981 const payload_ty = ty.errorUnionPayload(mod);
981 const payload_ty = ty.errorUnionPayload(zcu);
982982 const eu_layout = self.errorUnionLayout(payload_ty);
983983 if (!eu_layout.payload_has_bits) {
984984 // We use the error type directly as the type.
......@@ -1006,12 +1006,12 @@ const NavGen = struct {
10061006 },
10071007 .enum_tag => {
10081008 const int_val = try val.intFromEnum(ty, pt);
1009 const int_ty = ty.intTagType(mod);
1009 const int_ty = ty.intTagType(zcu);
10101010 break :cache try self.constant(int_ty, int_val, repr);
10111011 },
10121012 .ptr => return self.constantPtr(val),
10131013 .slice => |slice| {
1014 const ptr_ty = ty.slicePtrFieldType(mod);
1014 const ptr_ty = ty.slicePtrFieldType(zcu);
10151015 const ptr_id = try self.constantPtr(Value.fromInterned(slice.ptr));
10161016 const len_id = try self.constant(Type.usize, Value.fromInterned(slice.len), .indirect);
10171017 return self.constructStruct(
......@@ -1021,12 +1021,12 @@ const NavGen = struct {
10211021 );
10221022 },
10231023 .opt => {
1024 const payload_ty = ty.optionalChild(mod);
1025 const maybe_payload_val = val.optionalValue(mod);
1024 const payload_ty = ty.optionalChild(zcu);
1025 const maybe_payload_val = val.optionalValue(zcu);
10261026
1027 if (!payload_ty.hasRuntimeBits(pt)) {
1027 if (!payload_ty.hasRuntimeBits(zcu)) {
10281028 break :cache try self.constBool(maybe_payload_val != null, .indirect);
1029 } else if (ty.optionalReprIsPayload(mod)) {
1029 } else if (ty.optionalReprIsPayload(zcu)) {
10301030 // Optional representation is a nullable pointer or slice.
10311031 if (maybe_payload_val) |payload_val| {
10321032 return try self.constant(payload_ty, payload_val, .indirect);
......@@ -1054,7 +1054,7 @@ const NavGen = struct {
10541054 inline .array_type, .vector_type => |array_type, tag| {
10551055 const elem_ty = Type.fromInterned(array_type.child);
10561056
1057 const constituents = try self.gpa.alloc(IdRef, @intCast(ty.arrayLenIncludingSentinel(mod)));
1057 const constituents = try self.gpa.alloc(IdRef, @intCast(ty.arrayLenIncludingSentinel(zcu)));
10581058 defer self.gpa.free(constituents);
10591059
10601060 const child_repr: Repr = switch (tag) {
......@@ -1088,7 +1088,7 @@ const NavGen = struct {
10881088 }
10891089 },
10901090 .struct_type => {
1091 const struct_type = mod.typeToStruct(ty).?;
1091 const struct_type = zcu.typeToStruct(ty).?;
10921092 if (struct_type.layout == .@"packed") {
10931093 return self.todo("packed struct constants", .{});
10941094 }
......@@ -1102,7 +1102,7 @@ const NavGen = struct {
11021102 var it = struct_type.iterateRuntimeOrder(ip);
11031103 while (it.next()) |field_index| {
11041104 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
1105 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1105 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
11061106 // This is a zero-bit field - we only needed it for the alignment.
11071107 continue;
11081108 }
......@@ -1121,10 +1121,10 @@ const NavGen = struct {
11211121 else => unreachable,
11221122 },
11231123 .un => |un| {
1124 const active_field = ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?;
1125 const union_obj = mod.typeToUnion(ty).?;
1124 const active_field = ty.unionTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
1125 const union_obj = zcu.typeToUnion(ty).?;
11261126 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[active_field]);
1127 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(pt))
1127 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(zcu))
11281128 try self.constant(field_ty, Value.fromInterned(un.val), .direct)
11291129 else
11301130 null;
......@@ -1232,8 +1232,8 @@ const NavGen = struct {
12321232 // TODO: Merge this function with constantDeclRef.
12331233
12341234 const pt = self.pt;
1235 const mod = pt.zcu;
1236 const ip = &mod.intern_pool;
1235 const zcu = pt.zcu;
1236 const ip = &zcu.intern_pool;
12371237 const ty_id = try self.resolveType(ty, .direct);
12381238 const uav_ty = Type.fromInterned(ip.typeOf(uav.val));
12391239
......@@ -1243,14 +1243,14 @@ const NavGen = struct {
12431243 else => {},
12441244 }
12451245
1246 // const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;
1247 if (!uav_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
1246 // const is_fn_body = decl_ty.zigTypeTag(zcu) == .Fn;
1247 if (!uav_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
12481248 // Pointer to nothing - return undefined
12491249 return self.spv.constUndef(ty_id);
12501250 }
12511251
12521252 // Uav refs are always generic.
1253 assert(ty.ptrAddressSpace(mod) == .generic);
1253 assert(ty.ptrAddressSpace(zcu) == .generic);
12541254 const decl_ptr_ty_id = try self.ptrType(uav_ty, .Generic);
12551255 const ptr_id = try self.resolveUav(uav.val);
12561256
......@@ -1270,12 +1270,12 @@ const NavGen = struct {
12701270
12711271 fn constantNavRef(self: *NavGen, ty: Type, nav_index: InternPool.Nav.Index) !IdRef {
12721272 const pt = self.pt;
1273 const mod = pt.zcu;
1274 const ip = &mod.intern_pool;
1273 const zcu = pt.zcu;
1274 const ip = &zcu.intern_pool;
12751275 const ty_id = try self.resolveType(ty, .direct);
12761276 const nav = ip.getNav(nav_index);
1277 const nav_val = mod.navValue(nav_index);
1278 const nav_ty = nav_val.typeOf(mod);
1277 const nav_val = zcu.navValue(nav_index);
1278 const nav_ty = nav_val.typeOf(zcu);
12791279
12801280 switch (ip.indexToKey(nav_val.toIntern())) {
12811281 .func => {
......@@ -1287,12 +1287,12 @@ const NavGen = struct {
12871287 else => {},
12881288 }
12891289
1290 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
1290 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
12911291 // Pointer to nothing - return undefined.
12921292 return self.spv.constUndef(ty_id);
12931293 }
12941294
1295 const spv_decl_index = try self.object.resolveNav(mod, nav_index);
1295 const spv_decl_index = try self.object.resolveNav(zcu, nav_index);
12961296 const spv_decl = self.spv.declPtr(spv_decl_index);
12971297
12981298 const decl_id = switch (spv_decl.kind) {
......@@ -1452,9 +1452,9 @@ const NavGen = struct {
14521452 /// }
14531453 /// If any of the fields' size is 0, it will be omitted.
14541454 fn resolveUnionType(self: *NavGen, ty: Type) !IdRef {
1455 const mod = self.pt.zcu;
1456 const ip = &mod.intern_pool;
1457 const union_obj = mod.typeToUnion(ty).?;
1455 const zcu = self.pt.zcu;
1456 const ip = &zcu.intern_pool;
1457 const union_obj = zcu.typeToUnion(ty).?;
14581458
14591459 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
14601460 return self.todo("packed union types", .{});
......@@ -1503,12 +1503,12 @@ const NavGen = struct {
15031503 }
15041504
15051505 fn resolveFnReturnType(self: *NavGen, ret_ty: Type) !IdRef {
1506 const pt = self.pt;
1507 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1506 const zcu = self.pt.zcu;
1507 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
15081508 // If the return type is an error set or an error union, then we make this
15091509 // anyerror return type instead, so that it can be coerced into a function
15101510 // pointer type which has anyerror as the return type.
1511 if (ret_ty.isError(pt.zcu)) {
1511 if (ret_ty.isError(zcu)) {
15121512 return self.resolveType(Type.anyerror, .direct);
15131513 } else {
15141514 return self.resolveType(Type.void, .direct);
......@@ -1531,14 +1531,14 @@ const NavGen = struct {
15311531
15321532 fn resolveTypeInner(self: *NavGen, ty: Type, repr: Repr) Error!IdRef {
15331533 const pt = self.pt;
1534 const mod = pt.zcu;
1535 const ip = &mod.intern_pool;
1534 const zcu = pt.zcu;
1535 const ip = &zcu.intern_pool;
15361536 log.debug("resolveType: ty = {}", .{ty.fmt(pt)});
15371537 const target = self.getTarget();
15381538
15391539 const section = &self.spv.sections.types_globals_constants;
15401540
1541 switch (ty.zigTypeTag(mod)) {
1541 switch (ty.zigTypeTag(zcu)) {
15421542 .NoReturn => {
15431543 assert(repr == .direct);
15441544 return try self.spv.voidType();
......@@ -1562,7 +1562,7 @@ const NavGen = struct {
15621562 .indirect => return try self.resolveType(Type.u1, .indirect),
15631563 },
15641564 .Int => {
1565 const int_info = ty.intInfo(mod);
1565 const int_info = ty.intInfo(zcu);
15661566 if (int_info.bits == 0) {
15671567 // Some times, the backend will be asked to generate a pointer to i0. OpTypeInt
15681568 // with 0 bits is invalid, so return an opaque type in this case.
......@@ -1577,7 +1577,7 @@ const NavGen = struct {
15771577 return try self.intType(int_info.signedness, int_info.bits);
15781578 },
15791579 .Enum => {
1580 const tag_ty = ty.intTagType(mod);
1580 const tag_ty = ty.intTagType(zcu);
15811581 return try self.resolveType(tag_ty, repr);
15821582 },
15831583 .Float => {
......@@ -1599,13 +1599,13 @@ const NavGen = struct {
15991599 return try self.spv.floatType(bits);
16001600 },
16011601 .Array => {
1602 const elem_ty = ty.childType(mod);
1602 const elem_ty = ty.childType(zcu);
16031603 const elem_ty_id = try self.resolveType(elem_ty, .indirect);
1604 const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse {
1605 return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)});
1604 const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(zcu)) orelse {
1605 return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(zcu)});
16061606 };
16071607
1608 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1608 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
16091609 // The size of the array would be 0, but that is not allowed in SPIR-V.
16101610 // This path can be reached when the backend is asked to generate a pointer to
16111611 // an array of some zero-bit type. This should always be an indirect path.
......@@ -1635,7 +1635,7 @@ const NavGen = struct {
16351635 },
16361636 .Fn => switch (repr) {
16371637 .direct => {
1638 const fn_info = mod.typeToFunc(ty).?;
1638 const fn_info = zcu.typeToFunc(ty).?;
16391639
16401640 comptime assert(zig_call_abi_ver == 3);
16411641 switch (fn_info.cc) {
......@@ -1653,7 +1653,7 @@ const NavGen = struct {
16531653 var param_index: usize = 0;
16541654 for (fn_info.param_types.get(ip)) |param_ty_index| {
16551655 const param_ty = Type.fromInterned(param_ty_index);
1656 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
1656 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
16571657
16581658 param_ty_ids[param_index] = try self.resolveType(param_ty, .direct);
16591659 param_index += 1;
......@@ -1677,7 +1677,7 @@ const NavGen = struct {
16771677 },
16781678 },
16791679 .Pointer => {
1680 const ptr_info = ty.ptrInfo(mod);
1680 const ptr_info = ty.ptrInfo(zcu);
16811681
16821682 const storage_class = self.spvStorageClass(ptr_info.flags.address_space);
16831683 const ptr_ty_id = try self.ptrType(Type.fromInterned(ptr_info.child), storage_class);
......@@ -1693,9 +1693,9 @@ const NavGen = struct {
16931693 );
16941694 },
16951695 .Vector => {
1696 const elem_ty = ty.childType(mod);
1696 const elem_ty = ty.childType(zcu);
16971697 const elem_ty_id = try self.resolveType(elem_ty, repr);
1698 const len = ty.vectorLen(mod);
1698 const len = ty.vectorLen(zcu);
16991699
17001700 if (self.isSpvVector(ty)) {
17011701 return try self.spv.vectorType(len, elem_ty_id);
......@@ -1711,7 +1711,7 @@ const NavGen = struct {
17111711
17121712 var member_index: usize = 0;
17131713 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {
1714 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
1714 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
17151715
17161716 member_types[member_index] = try self.resolveType(Type.fromInterned(field_ty), .indirect);
17171717 member_index += 1;
......@@ -1740,13 +1740,13 @@ const NavGen = struct {
17401740 var it = struct_type.iterateRuntimeOrder(ip);
17411741 while (it.next()) |field_index| {
17421742 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
1743 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1743 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
17441744 // This is a zero-bit field - we only needed it for the alignment.
17451745 continue;
17461746 }
17471747
17481748 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
1749 try ip.getOrPutStringFmt(mod.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
1749 try ip.getOrPutStringFmt(zcu.gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
17501750 try member_types.append(try self.resolveType(field_ty, .indirect));
17511751 try member_names.append(field_name.toSlice(ip));
17521752 }
......@@ -1758,8 +1758,8 @@ const NavGen = struct {
17581758 return result_id;
17591759 },
17601760 .Optional => {
1761 const payload_ty = ty.optionalChild(mod);
1762 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
1761 const payload_ty = ty.optionalChild(zcu);
1762 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
17631763 // Just use a bool.
17641764 // Note: Always generate the bool with indirect format, to save on some sanity
17651765 // Perform the conversion to a direct bool when the field is extracted.
......@@ -1767,7 +1767,7 @@ const NavGen = struct {
17671767 }
17681768
17691769 const payload_ty_id = try self.resolveType(payload_ty, .indirect);
1770 if (ty.optionalReprIsPayload(mod)) {
1770 if (ty.optionalReprIsPayload(zcu)) {
17711771 // Optional is actually a pointer or a slice.
17721772 return payload_ty_id;
17731773 }
......@@ -1782,7 +1782,7 @@ const NavGen = struct {
17821782 .Union => return try self.resolveUnionType(ty),
17831783 .ErrorSet => return try self.resolveType(Type.u16, repr),
17841784 .ErrorUnion => {
1785 const payload_ty = ty.errorUnionPayload(mod);
1785 const payload_ty = ty.errorUnionPayload(zcu);
17861786 const error_ty_id = try self.resolveType(Type.anyerror, .indirect);
17871787
17881788 const eu_layout = self.errorUnionLayout(payload_ty);
......@@ -1877,13 +1877,14 @@ const NavGen = struct {
18771877
18781878 fn errorUnionLayout(self: *NavGen, payload_ty: Type) ErrorUnionLayout {
18791879 const pt = self.pt;
1880 const zcu = pt.zcu;
18801881
1881 const error_align = Type.anyerror.abiAlignment(pt);
1882 const payload_align = payload_ty.abiAlignment(pt);
1882 const error_align = Type.anyerror.abiAlignment(zcu);
1883 const payload_align = payload_ty.abiAlignment(zcu);
18831884
18841885 const error_first = error_align.compare(.gt, payload_align);
18851886 return .{
1886 .payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(pt),
1887 .payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu),
18871888 .error_first = error_first,
18881889 };
18891890 }
......@@ -1908,10 +1909,10 @@ const NavGen = struct {
19081909
19091910 fn unionLayout(self: *NavGen, ty: Type) UnionLayout {
19101911 const pt = self.pt;
1911 const mod = pt.zcu;
1912 const ip = &mod.intern_pool;
1913 const layout = ty.unionGetLayout(pt);
1914 const union_obj = mod.typeToUnion(ty).?;
1912 const zcu = pt.zcu;
1913 const ip = &zcu.intern_pool;
1914 const layout = ty.unionGetLayout(zcu);
1915 const union_obj = zcu.typeToUnion(ty).?;
19151916
19161917 var union_layout = UnionLayout{
19171918 .has_payload = layout.payload_size != 0,
......@@ -1931,7 +1932,7 @@ const NavGen = struct {
19311932 const most_aligned_field = layout.most_aligned_field;
19321933 const most_aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[most_aligned_field]);
19331934 union_layout.payload_ty = most_aligned_field_ty;
1934 union_layout.payload_size = @intCast(most_aligned_field_ty.abiSize(pt));
1935 union_layout.payload_size = @intCast(most_aligned_field_ty.abiSize(zcu));
19351936 } else {
19361937 union_layout.payload_size = 0;
19371938 }
......@@ -1998,12 +1999,12 @@ const NavGen = struct {
19981999 }
19992000
20002001 fn materialize(self: Temporary, ng: *NavGen) !IdResult {
2001 const mod = ng.pt.zcu;
2002 const zcu = ng.pt.zcu;
20022003 switch (self.value) {
20032004 .singleton => |id| return id,
20042005 .exploded_vector => |range| {
2005 assert(self.ty.isVector(mod));
2006 assert(self.ty.vectorLen(mod) == range.len);
2006 assert(self.ty.isVector(zcu));
2007 assert(self.ty.vectorLen(zcu) == range.len);
20072008 const consituents = try ng.gpa.alloc(IdRef, range.len);
20082009 defer ng.gpa.free(consituents);
20092010 for (consituents, 0..range.len) |*id, i| {
......@@ -2028,18 +2029,18 @@ const NavGen = struct {
20282029 /// 'Explode' a temporary into separate elements. This turns a vector
20292030 /// into a bag of elements.
20302031 fn explode(self: Temporary, ng: *NavGen) !IdRange {
2031 const mod = ng.pt.zcu;
2032 const zcu = ng.pt.zcu;
20322033
20332034 // If the value is a scalar, then this is a no-op.
2034 if (!self.ty.isVector(mod)) {
2035 if (!self.ty.isVector(zcu)) {
20352036 return switch (self.value) {
20362037 .singleton => |id| .{ .base = @intFromEnum(id), .len = 1 },
20372038 .exploded_vector => |range| range,
20382039 };
20392040 }
20402041
2041 const ty_id = try ng.resolveType(self.ty.scalarType(mod), .direct);
2042 const n = self.ty.vectorLen(mod);
2042 const ty_id = try ng.resolveType(self.ty.scalarType(zcu), .direct);
2043 const n = self.ty.vectorLen(zcu);
20432044 const results = ng.spv.allocIds(n);
20442045
20452046 const id = switch (self.value) {
......@@ -2087,13 +2088,13 @@ const NavGen = struct {
20872088 /// only checks the size, but the source-of-truth is implemented
20882089 /// by `isSpvVector()`.
20892090 fn fromType(ty: Type, ng: *NavGen) Vectorization {
2090 const mod = ng.pt.zcu;
2091 if (!ty.isVector(mod)) {
2091 const zcu = ng.pt.zcu;
2092 if (!ty.isVector(zcu)) {
20922093 return .scalar;
20932094 } else if (ng.isSpvVector(ty)) {
2094 return .{ .spv_vectorized = ty.vectorLen(mod) };
2095 return .{ .spv_vectorized = ty.vectorLen(zcu) };
20952096 } else {
2096 return .{ .unrolled = ty.vectorLen(mod) };
2097 return .{ .unrolled = ty.vectorLen(zcu) };
20972098 }
20982099 }
20992100
......@@ -2339,10 +2340,10 @@ const NavGen = struct {
23392340 /// This function builds an OpSConvert of OpUConvert depending on the
23402341 /// signedness of the types.
23412342 fn buildIntConvert(self: *NavGen, dst_ty: Type, src: Temporary) !Temporary {
2342 const mod = self.pt.zcu;
2343 const zcu = self.pt.zcu;
23432344
2344 const dst_ty_id = try self.resolveType(dst_ty.scalarType(mod), .direct);
2345 const src_ty_id = try self.resolveType(src.ty.scalarType(mod), .direct);
2345 const dst_ty_id = try self.resolveType(dst_ty.scalarType(zcu), .direct);
2346 const src_ty_id = try self.resolveType(src.ty.scalarType(zcu), .direct);
23462347
23472348 const v = self.vectorization(.{ dst_ty, src });
23482349 const result_ty = try v.resultType(self, dst_ty);
......@@ -2363,7 +2364,7 @@ const NavGen = struct {
23632364 const op_result_ty = try v.operationType(self, dst_ty);
23642365 const op_result_ty_id = try self.resolveType(op_result_ty, .direct);
23652366
2366 const opcode: Opcode = if (dst_ty.isSignedInt(mod)) .OpSConvert else .OpUConvert;
2367 const opcode: Opcode = if (dst_ty.isSignedInt(zcu)) .OpSConvert else .OpUConvert;
23672368
23682369 const op_src = try v.prepare(self, src);
23692370
......@@ -2418,7 +2419,7 @@ const NavGen = struct {
24182419 }
24192420
24202421 fn buildSelect(self: *NavGen, condition: Temporary, lhs: Temporary, rhs: Temporary) !Temporary {
2421 const mod = self.pt.zcu;
2422 const zcu = self.pt.zcu;
24222423
24232424 const v = self.vectorization(.{ condition, lhs, rhs });
24242425 const ops = v.operations();
......@@ -2428,7 +2429,7 @@ const NavGen = struct {
24282429 const op_result_ty_id = try self.resolveType(op_result_ty, .direct);
24292430 const result_ty = try v.resultType(self, lhs.ty);
24302431
2431 assert(condition.ty.scalarType(mod).zigTypeTag(mod) == .Bool);
2432 assert(condition.ty.scalarType(zcu).zigTypeTag(zcu) == .Bool);
24322433
24332434 const cond = try v.prepare(self, condition);
24342435 const object_1 = try v.prepare(self, lhs);
......@@ -2764,9 +2765,9 @@ const NavGen = struct {
27642765 rhs: Temporary,
27652766 ) !struct { Temporary, Temporary } {
27662767 const pt = self.pt;
2767 const mod = pt.zcu;
2768 const zcu = pt.zcu;
27682769 const target = self.getTarget();
2769 const ip = &mod.intern_pool;
2770 const ip = &zcu.intern_pool;
27702771
27712772 const v = lhs.vectorization(self).unify(rhs.vectorization(self));
27722773 const ops = v.operations();
......@@ -2814,7 +2815,7 @@ const NavGen = struct {
28142815 // where T is maybe vectorized.
28152816 const types = [2]InternPool.Index{ arith_op_ty.toIntern(), arith_op_ty.toIntern() };
28162817 const values = [2]InternPool.Index{ .none, .none };
2817 const index = try ip.getAnonStructType(mod.gpa, pt.tid, .{
2818 const index = try ip.getAnonStructType(zcu.gpa, pt.tid, .{
28182819 .types = &types,
28192820 .values = &values,
28202821 .names = &.{},
......@@ -2941,17 +2942,17 @@ const NavGen = struct {
29412942
29422943 fn genNav(self: *NavGen) !void {
29432944 const pt = self.pt;
2944 const mod = pt.zcu;
2945 const ip = &mod.intern_pool;
2946 const spv_decl_index = try self.object.resolveNav(mod, self.owner_nav);
2945 const zcu = pt.zcu;
2946 const ip = &zcu.intern_pool;
2947 const spv_decl_index = try self.object.resolveNav(zcu, self.owner_nav);
29472948 const result_id = self.spv.declPtr(spv_decl_index).result_id;
29482949
29492950 const nav = ip.getNav(self.owner_nav);
2950 const val = mod.navValue(self.owner_nav);
2951 const ty = val.typeOf(mod);
2951 const val = zcu.navValue(self.owner_nav);
2952 const ty = val.typeOf(zcu);
29522953 switch (self.spv.declPtr(spv_decl_index).kind) {
29532954 .func => {
2954 const fn_info = mod.typeToFunc(ty).?;
2955 const fn_info = zcu.typeToFunc(ty).?;
29552956 const return_ty_id = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));
29562957
29572958 const prototype_ty_id = try self.resolveType(ty, .direct);
......@@ -2969,7 +2970,7 @@ const NavGen = struct {
29692970 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);
29702971 for (fn_info.param_types.get(ip)) |param_ty_index| {
29712972 const param_ty = Type.fromInterned(param_ty_index);
2972 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2973 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
29732974
29742975 const param_type_id = try self.resolveType(param_ty, .direct);
29752976 const arg_result_id = self.spv.allocId();
......@@ -3116,8 +3117,8 @@ const NavGen = struct {
31163117 /// Convert representation from indirect (in memory) to direct (in 'register')
31173118 /// This converts the argument type from resolveType(ty, .indirect) to resolveType(ty, .direct).
31183119 fn convertToDirect(self: *NavGen, ty: Type, operand_id: IdRef) !IdRef {
3119 const mod = self.pt.zcu;
3120 switch (ty.scalarType(mod).zigTypeTag(mod)) {
3120 const zcu = self.pt.zcu;
3121 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
31213122 .Bool => {
31223123 const false_id = try self.constBool(false, .indirect);
31233124 // The operation below requires inputs in direct representation, but the operand
......@@ -3142,8 +3143,8 @@ const NavGen = struct {
31423143 /// Convert representation from direct (in 'register) to direct (in memory)
31433144 /// This converts the argument type from resolveType(ty, .direct) to resolveType(ty, .indirect).
31443145 fn convertToIndirect(self: *NavGen, ty: Type, operand_id: IdRef) !IdRef {
3145 const mod = self.pt.zcu;
3146 switch (ty.scalarType(mod).zigTypeTag(mod)) {
3146 const zcu = self.pt.zcu;
3147 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
31473148 .Bool => {
31483149 const result = try self.intFromBool(Temporary.init(ty, operand_id));
31493150 return try result.materialize(self);
......@@ -3219,8 +3220,8 @@ const NavGen = struct {
32193220 }
32203221
32213222 fn genInst(self: *NavGen, inst: Air.Inst.Index) !void {
3222 const mod = self.pt.zcu;
3223 const ip = &mod.intern_pool;
3223 const zcu = self.pt.zcu;
3224 const ip = &zcu.intern_pool;
32243225 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
32253226 return;
32263227
......@@ -3399,7 +3400,7 @@ const NavGen = struct {
33993400 }
34003401
34013402 fn airShift(self: *NavGen, inst: Air.Inst.Index, unsigned: BinaryOp, signed: BinaryOp) !?IdRef {
3402 const mod = self.pt.zcu;
3403 const zcu = self.pt.zcu;
34033404 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
34043405
34053406 const base = try self.temporary(bin_op.lhs);
......@@ -3420,7 +3421,7 @@ const NavGen = struct {
34203421 // Note: The sign may differ here between the shift and the base type, in case
34213422 // of an arithmetic right shift. SPIR-V still expects the same type,
34223423 // so in that case we have to cast convert to signed.
3423 const casted_shift = try self.buildIntConvert(base.ty.scalarType(mod), shift);
3424 const casted_shift = try self.buildIntConvert(base.ty.scalarType(zcu), shift);
34243425
34253426 const shifted = switch (info.signedness) {
34263427 .unsigned => try self.buildBinary(unsigned, base, casted_shift),
......@@ -3477,7 +3478,7 @@ const NavGen = struct {
34773478 /// All other values are returned unmodified (this makes strange integer
34783479 /// wrapping easier to use in generic operations).
34793480 fn normalize(self: *NavGen, value: Temporary, info: ArithmeticTypeInfo) !Temporary {
3480 const mod = self.pt.zcu;
3481 const zcu = self.pt.zcu;
34813482 const ty = value.ty;
34823483 switch (info.class) {
34833484 .integer, .bool, .float => return value,
......@@ -3485,13 +3486,13 @@ const NavGen = struct {
34853486 .strange_integer => switch (info.signedness) {
34863487 .unsigned => {
34873488 const mask_value = if (info.bits == 64) 0xFFFF_FFFF_FFFF_FFFF else (@as(u64, 1) << @as(u6, @intCast(info.bits))) - 1;
3488 const mask_id = try self.constInt(ty.scalarType(mod), mask_value, .direct);
3489 return try self.buildBinary(.bit_and, value, Temporary.init(ty.scalarType(mod), mask_id));
3489 const mask_id = try self.constInt(ty.scalarType(zcu), mask_value, .direct);
3490 return try self.buildBinary(.bit_and, value, Temporary.init(ty.scalarType(zcu), mask_id));
34903491 },
34913492 .signed => {
34923493 // Shift left and right so that we can copy the sight bit that way.
3493 const shift_amt_id = try self.constInt(ty.scalarType(mod), info.backing_bits - info.bits, .direct);
3494 const shift_amt = Temporary.init(ty.scalarType(mod), shift_amt_id);
3494 const shift_amt_id = try self.constInt(ty.scalarType(zcu), info.backing_bits - info.bits, .direct);
3495 const shift_amt = Temporary.init(ty.scalarType(zcu), shift_amt_id);
34953496 const left = try self.buildBinary(.sll, value, shift_amt);
34963497 return try self.buildBinary(.sra, left, shift_amt);
34973498 },
......@@ -3897,7 +3898,7 @@ const NavGen = struct {
38973898 }
38983899
38993900 fn airShlOverflow(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
3900 const mod = self.pt.zcu;
3901 const zcu = self.pt.zcu;
39013902
39023903 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
39033904 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
......@@ -3916,7 +3917,7 @@ const NavGen = struct {
39163917
39173918 // Sometimes Zig doesn't make both of the arguments the same types here. SPIR-V expects that,
39183919 // so just manually upcast it if required.
3919 const casted_shift = try self.buildIntConvert(base.ty.scalarType(mod), shift);
3920 const casted_shift = try self.buildIntConvert(base.ty.scalarType(zcu), shift);
39203921
39213922 const left = try self.buildBinary(.sll, base, casted_shift);
39223923 const result = try self.normalize(left, info);
......@@ -3955,12 +3956,12 @@ const NavGen = struct {
39553956 fn airClzCtz(self: *NavGen, inst: Air.Inst.Index, op: UnaryOp) !?IdRef {
39563957 if (self.liveness.isUnused(inst)) return null;
39573958
3958 const mod = self.pt.zcu;
3959 const zcu = self.pt.zcu;
39593960 const target = self.getTarget();
39603961 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
39613962 const operand = try self.temporary(ty_op.operand);
39623963
3963 const scalar_result_ty = self.typeOfIndex(inst).scalarType(mod);
3964 const scalar_result_ty = self.typeOfIndex(inst).scalarType(zcu);
39643965
39653966 const info = self.arithmeticTypeInfo(operand.ty);
39663967 switch (info.class) {
......@@ -4004,16 +4005,16 @@ const NavGen = struct {
40044005 }
40054006
40064007 fn airReduce(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4007 const mod = self.pt.zcu;
4008 const zcu = self.pt.zcu;
40084009 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
40094010 const operand = try self.resolve(reduce.operand);
40104011 const operand_ty = self.typeOf(reduce.operand);
4011 const scalar_ty = operand_ty.scalarType(mod);
4012 const scalar_ty = operand_ty.scalarType(zcu);
40124013 const scalar_ty_id = try self.resolveType(scalar_ty, .direct);
40134014
40144015 const info = self.arithmeticTypeInfo(operand_ty);
40154016
4016 const len = operand_ty.vectorLen(mod);
4017 const len = operand_ty.vectorLen(zcu);
40174018
40184019 const first = try self.extractVectorComponent(scalar_ty, operand, 0);
40194020
......@@ -4080,7 +4081,7 @@ const NavGen = struct {
40804081
40814082 fn airShuffle(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
40824083 const pt = self.pt;
4083 const mod = pt.zcu;
4084 const zcu = pt.zcu;
40844085 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
40854086 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
40864087 const a = try self.resolve(extra.a);
......@@ -4092,7 +4093,7 @@ const NavGen = struct {
40924093 const a_ty = self.typeOf(extra.a);
40934094 const b_ty = self.typeOf(extra.b);
40944095
4095 const scalar_ty = result_ty.scalarType(mod);
4096 const scalar_ty = result_ty.scalarType(zcu);
40964097 const scalar_ty_id = try self.resolveType(scalar_ty, .direct);
40974098
40984099 // If all of the types are SPIR-V vectors, we can use OpVectorShuffle.
......@@ -4100,20 +4101,20 @@ const NavGen = struct {
41004101 // The SPIR-V shuffle instruction is similar to the Air instruction, except that the elements are
41014102 // numbered consecutively instead of using negatives.
41024103
4103 const components = try self.gpa.alloc(Word, result_ty.vectorLen(mod));
4104 const components = try self.gpa.alloc(Word, result_ty.vectorLen(zcu));
41044105 defer self.gpa.free(components);
41054106
4106 const a_len = a_ty.vectorLen(mod);
4107 const a_len = a_ty.vectorLen(zcu);
41074108
41084109 for (components, 0..) |*component, i| {
41094110 const elem = try mask.elemValue(pt, i);
4110 if (elem.isUndef(mod)) {
4111 if (elem.isUndef(zcu)) {
41114112 // This is explicitly valid for OpVectorShuffle, it indicates undefined.
41124113 component.* = 0xFFFF_FFFF;
41134114 continue;
41144115 }
41154116
4116 const index = elem.toSignedInt(pt);
4117 const index = elem.toSignedInt(zcu);
41174118 if (index >= 0) {
41184119 component.* = @intCast(index);
41194120 } else {
......@@ -4134,17 +4135,17 @@ const NavGen = struct {
41344135
41354136 // Fall back to manually extracting and inserting components.
41364137
4137 const components = try self.gpa.alloc(IdRef, result_ty.vectorLen(mod));
4138 const components = try self.gpa.alloc(IdRef, result_ty.vectorLen(zcu));
41384139 defer self.gpa.free(components);
41394140
41404141 for (components, 0..) |*id, i| {
41414142 const elem = try mask.elemValue(pt, i);
4142 if (elem.isUndef(mod)) {
4143 if (elem.isUndef(zcu)) {
41434144 id.* = try self.spv.constUndef(scalar_ty_id);
41444145 continue;
41454146 }
41464147
4147 const index = elem.toSignedInt(pt);
4148 const index = elem.toSignedInt(zcu);
41484149 if (index >= 0) {
41494150 id.* = try self.extractVectorComponent(scalar_ty, a, @intCast(index));
41504151 } else {
......@@ -4218,10 +4219,10 @@ const NavGen = struct {
42184219 }
42194220
42204221 fn ptrAdd(self: *NavGen, result_ty: Type, ptr_ty: Type, ptr_id: IdRef, offset_id: IdRef) !IdRef {
4221 const mod = self.pt.zcu;
4222 const zcu = self.pt.zcu;
42224223 const result_ty_id = try self.resolveType(result_ty, .direct);
42234224
4224 switch (ptr_ty.ptrSize(mod)) {
4225 switch (ptr_ty.ptrSize(zcu)) {
42254226 .One => {
42264227 // Pointer to array
42274228 // TODO: Is this correct?
......@@ -4275,15 +4276,15 @@ const NavGen = struct {
42754276 rhs: Temporary,
42764277 ) !Temporary {
42774278 const pt = self.pt;
4278 const mod = pt.zcu;
4279 const scalar_ty = lhs.ty.scalarType(mod);
4280 const is_vector = lhs.ty.isVector(mod);
4279 const zcu = pt.zcu;
4280 const scalar_ty = lhs.ty.scalarType(zcu);
4281 const is_vector = lhs.ty.isVector(zcu);
42814282
4282 switch (scalar_ty.zigTypeTag(mod)) {
4283 switch (scalar_ty.zigTypeTag(zcu)) {
42834284 .Int, .Bool, .Float => {},
42844285 .Enum => {
42854286 assert(!is_vector);
4286 const ty = lhs.ty.intTagType(mod);
4287 const ty = lhs.ty.intTagType(zcu);
42874288 return try self.cmp(op, lhs.pun(ty), rhs.pun(ty));
42884289 },
42894290 .ErrorSet => {
......@@ -4321,10 +4322,10 @@ const NavGen = struct {
43214322
43224323 const ty = lhs.ty;
43234324
4324 const payload_ty = ty.optionalChild(mod);
4325 if (ty.optionalReprIsPayload(mod)) {
4326 assert(payload_ty.hasRuntimeBitsIgnoreComptime(pt));
4327 assert(!payload_ty.isSlice(mod));
4325 const payload_ty = ty.optionalChild(zcu);
4326 if (ty.optionalReprIsPayload(zcu)) {
4327 assert(payload_ty.hasRuntimeBitsIgnoreComptime(zcu));
4328 assert(!payload_ty.isSlice(zcu));
43284329
43294330 return try self.cmp(op, lhs.pun(payload_ty), rhs.pun(payload_ty));
43304331 }
......@@ -4332,12 +4333,12 @@ const NavGen = struct {
43324333 const lhs_id = try lhs.materialize(self);
43334334 const rhs_id = try rhs.materialize(self);
43344335
4335 const lhs_valid_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(pt))
4336 const lhs_valid_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
43364337 try self.extractField(Type.bool, lhs_id, 1)
43374338 else
43384339 try self.convertToDirect(Type.bool, lhs_id);
43394340
4340 const rhs_valid_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(pt))
4341 const rhs_valid_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
43414342 try self.extractField(Type.bool, rhs_id, 1)
43424343 else
43434344 try self.convertToDirect(Type.bool, rhs_id);
......@@ -4345,7 +4346,7 @@ const NavGen = struct {
43454346 const lhs_valid = Temporary.init(Type.bool, lhs_valid_id);
43464347 const rhs_valid = Temporary.init(Type.bool, rhs_valid_id);
43474348
4348 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4349 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
43494350 return try self.cmp(op, lhs_valid, rhs_valid);
43504351 }
43514352
......@@ -4465,7 +4466,7 @@ const NavGen = struct {
44654466 src_ty: Type,
44664467 src_id: IdRef,
44674468 ) !IdRef {
4468 const mod = self.pt.zcu;
4469 const zcu = self.pt.zcu;
44694470 const src_ty_id = try self.resolveType(src_ty, .direct);
44704471 const dst_ty_id = try self.resolveType(dst_ty, .direct);
44714472
......@@ -4477,7 +4478,7 @@ const NavGen = struct {
44774478 // TODO: Some more cases are missing here
44784479 // See fn bitCast in llvm.zig
44794480
4480 if (src_ty.zigTypeTag(mod) == .Int and dst_ty.isPtrAtRuntime(mod)) {
4481 if (src_ty.zigTypeTag(zcu) == .Int and dst_ty.isPtrAtRuntime(zcu)) {
44814482 const result_id = self.spv.allocId();
44824483 try self.func.body.emit(self.spv.gpa, .OpConvertUToPtr, .{
44834484 .id_result_type = dst_ty_id,
......@@ -4490,7 +4491,7 @@ const NavGen = struct {
44904491 // We can only use OpBitcast for specific conversions: between numerical types, and
44914492 // between pointers. If the resolved spir-v types fall into this category then emit OpBitcast,
44924493 // otherwise use a temporary and perform a pointer cast.
4493 const can_bitcast = (src_ty.isNumeric(mod) and dst_ty.isNumeric(mod)) or (src_ty.isPtrAtRuntime(mod) and dst_ty.isPtrAtRuntime(mod));
4494 const can_bitcast = (src_ty.isNumeric(zcu) and dst_ty.isNumeric(zcu)) or (src_ty.isPtrAtRuntime(zcu) and dst_ty.isPtrAtRuntime(zcu));
44944495 if (can_bitcast) {
44954496 const result_id = self.spv.allocId();
44964497 try self.func.body.emit(self.spv.gpa, .OpBitcast, .{
......@@ -4519,7 +4520,7 @@ const NavGen = struct {
45194520 // the result here.
45204521 // TODO: This detail could cause stuff like @as(*const i1, @ptrCast(&@as(u1, 1))) to break
45214522 // should we change the representation of strange integers?
4522 if (dst_ty.zigTypeTag(mod) == .Int) {
4523 if (dst_ty.zigTypeTag(zcu) == .Int) {
45234524 const info = self.arithmeticTypeInfo(dst_ty);
45244525 const result = try self.normalize(Temporary.init(dst_ty, result_id), info);
45254526 return try result.materialize(self);
......@@ -4675,19 +4676,19 @@ const NavGen = struct {
46754676
46764677 fn airArrayToSlice(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
46774678 const pt = self.pt;
4678 const mod = pt.zcu;
4679 const zcu = pt.zcu;
46794680 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
46804681 const array_ptr_ty = self.typeOf(ty_op.operand);
4681 const array_ty = array_ptr_ty.childType(mod);
4682 const array_ty = array_ptr_ty.childType(zcu);
46824683 const slice_ty = self.typeOfIndex(inst);
4683 const elem_ptr_ty = slice_ty.slicePtrFieldType(mod);
4684 const elem_ptr_ty = slice_ty.slicePtrFieldType(zcu);
46844685
46854686 const elem_ptr_ty_id = try self.resolveType(elem_ptr_ty, .direct);
46864687
46874688 const array_ptr_id = try self.resolve(ty_op.operand);
4688 const len_id = try self.constInt(Type.usize, array_ty.arrayLen(mod), .direct);
4689 const len_id = try self.constInt(Type.usize, array_ty.arrayLen(zcu), .direct);
46894690
4690 const elem_ptr_id = if (!array_ty.hasRuntimeBitsIgnoreComptime(pt))
4691 const elem_ptr_id = if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
46914692 // Note: The pointer is something like *opaque{}, so we need to bitcast it to the element type.
46924693 try self.bitCast(elem_ptr_ty, array_ptr_ty, array_ptr_id)
46934694 else
......@@ -4720,16 +4721,16 @@ const NavGen = struct {
47204721
47214722 fn airAggregateInit(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
47224723 const pt = self.pt;
4723 const mod = pt.zcu;
4724 const ip = &mod.intern_pool;
4724 const zcu = pt.zcu;
4725 const ip = &zcu.intern_pool;
47254726 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
47264727 const result_ty = self.typeOfIndex(inst);
4727 const len: usize = @intCast(result_ty.arrayLen(mod));
4728 const len: usize = @intCast(result_ty.arrayLen(zcu));
47284729 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
47294730
4730 switch (result_ty.zigTypeTag(mod)) {
4731 switch (result_ty.zigTypeTag(zcu)) {
47314732 .Struct => {
4732 if (mod.typeToPackedStruct(result_ty)) |struct_type| {
4733 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {
47334734 _ = struct_type;
47344735 unreachable; // TODO
47354736 }
......@@ -4744,7 +4745,7 @@ const NavGen = struct {
47444745 .anon_struct_type => |tuple| {
47454746 for (tuple.types.get(ip), elements, 0..) |field_ty, element, i| {
47464747 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;
4747 assert(Type.fromInterned(field_ty).hasRuntimeBits(pt));
4748 assert(Type.fromInterned(field_ty).hasRuntimeBits(zcu));
47484749
47494750 const id = try self.resolve(element);
47504751 types[index] = Type.fromInterned(field_ty);
......@@ -4759,7 +4760,7 @@ const NavGen = struct {
47594760 const field_index = it.next().?;
47604761 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;
47614762 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
4762 assert(field_ty.hasRuntimeBitsIgnoreComptime(pt));
4763 assert(field_ty.hasRuntimeBitsIgnoreComptime(zcu));
47634764
47644765 const id = try self.resolve(element);
47654766 types[index] = field_ty;
......@@ -4777,7 +4778,7 @@ const NavGen = struct {
47774778 );
47784779 },
47794780 .Vector => {
4780 const n_elems = result_ty.vectorLen(mod);
4781 const n_elems = result_ty.vectorLen(zcu);
47814782 const elem_ids = try self.gpa.alloc(IdRef, n_elems);
47824783 defer self.gpa.free(elem_ids);
47834784
......@@ -4788,8 +4789,8 @@ const NavGen = struct {
47884789 return try self.constructVector(result_ty, elem_ids);
47894790 },
47904791 .Array => {
4791 const array_info = result_ty.arrayInfo(mod);
4792 const n_elems: usize = @intCast(result_ty.arrayLenIncludingSentinel(mod));
4792 const array_info = result_ty.arrayInfo(zcu);
4793 const n_elems: usize = @intCast(result_ty.arrayLenIncludingSentinel(zcu));
47934794 const elem_ids = try self.gpa.alloc(IdRef, n_elems);
47944795 defer self.gpa.free(elem_ids);
47954796
......@@ -4810,14 +4811,14 @@ const NavGen = struct {
48104811
48114812 fn sliceOrArrayLen(self: *NavGen, operand_id: IdRef, ty: Type) !IdRef {
48124813 const pt = self.pt;
4813 const mod = pt.zcu;
4814 switch (ty.ptrSize(mod)) {
4814 const zcu = pt.zcu;
4815 switch (ty.ptrSize(zcu)) {
48154816 .Slice => return self.extractField(Type.usize, operand_id, 1),
48164817 .One => {
4817 const array_ty = ty.childType(mod);
4818 const elem_ty = array_ty.childType(mod);
4819 const abi_size = elem_ty.abiSize(pt);
4820 const size = array_ty.arrayLenIncludingSentinel(mod) * abi_size;
4818 const array_ty = ty.childType(zcu);
4819 const elem_ty = array_ty.childType(zcu);
4820 const abi_size = elem_ty.abiSize(zcu);
4821 const size = array_ty.arrayLenIncludingSentinel(zcu) * abi_size;
48214822 return try self.constInt(Type.usize, size, .direct);
48224823 },
48234824 .Many, .C => unreachable,
......@@ -4825,9 +4826,9 @@ const NavGen = struct {
48254826 }
48264827
48274828 fn sliceOrArrayPtr(self: *NavGen, operand_id: IdRef, ty: Type) !IdRef {
4828 const mod = self.pt.zcu;
4829 if (ty.isSlice(mod)) {
4830 const ptr_ty = ty.slicePtrFieldType(mod);
4829 const zcu = self.pt.zcu;
4830 if (ty.isSlice(zcu)) {
4831 const ptr_ty = ty.slicePtrFieldType(zcu);
48314832 return self.extractField(ptr_ty, operand_id, 0);
48324833 }
48334834 return operand_id;
......@@ -4857,11 +4858,11 @@ const NavGen = struct {
48574858 }
48584859
48594860 fn airSliceElemPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4860 const mod = self.pt.zcu;
4861 const zcu = self.pt.zcu;
48614862 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
48624863 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
48634864 const slice_ty = self.typeOf(bin_op.lhs);
4864 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;
4865 if (!slice_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) return null;
48654866
48664867 const slice_id = try self.resolve(bin_op.lhs);
48674868 const index_id = try self.resolve(bin_op.rhs);
......@@ -4874,28 +4875,28 @@ const NavGen = struct {
48744875 }
48754876
48764877 fn airSliceElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4877 const mod = self.pt.zcu;
4878 const zcu = self.pt.zcu;
48784879 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
48794880 const slice_ty = self.typeOf(bin_op.lhs);
4880 if (!slice_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;
4881 if (!slice_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) return null;
48814882
48824883 const slice_id = try self.resolve(bin_op.lhs);
48834884 const index_id = try self.resolve(bin_op.rhs);
48844885
4885 const ptr_ty = slice_ty.slicePtrFieldType(mod);
4886 const ptr_ty = slice_ty.slicePtrFieldType(zcu);
48864887 const ptr_ty_id = try self.resolveType(ptr_ty, .direct);
48874888
48884889 const slice_ptr = try self.extractField(ptr_ty, slice_id, 0);
48894890 const elem_ptr = try self.ptrAccessChain(ptr_ty_id, slice_ptr, index_id, &.{});
4890 return try self.load(slice_ty.childType(mod), elem_ptr, .{ .is_volatile = slice_ty.isVolatilePtr(mod) });
4891 return try self.load(slice_ty.childType(zcu), elem_ptr, .{ .is_volatile = slice_ty.isVolatilePtr(zcu) });
48914892 }
48924893
48934894 fn ptrElemPtr(self: *NavGen, ptr_ty: Type, ptr_id: IdRef, index_id: IdRef) !IdRef {
4894 const mod = self.pt.zcu;
4895 const zcu = self.pt.zcu;
48954896 // Construct new pointer type for the resulting pointer
4896 const elem_ty = ptr_ty.elemType2(mod); // use elemType() so that we get T for *[N]T.
4897 const elem_ptr_ty_id = try self.ptrType(elem_ty, self.spvStorageClass(ptr_ty.ptrAddressSpace(mod)));
4898 if (ptr_ty.isSinglePointer(mod)) {
4897 const elem_ty = ptr_ty.elemType2(zcu); // use elemType() so that we get T for *[N]T.
4898 const elem_ptr_ty_id = try self.ptrType(elem_ty, self.spvStorageClass(ptr_ty.ptrAddressSpace(zcu)));
4899 if (ptr_ty.isSinglePointer(zcu)) {
48994900 // Pointer-to-array. In this case, the resulting pointer is not of the same type
49004901 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.
49014902 return try self.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id});
......@@ -4907,14 +4908,14 @@ const NavGen = struct {
49074908
49084909 fn airPtrElemPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
49094910 const pt = self.pt;
4910 const mod = pt.zcu;
4911 const zcu = pt.zcu;
49114912 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
49124913 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
49134914 const src_ptr_ty = self.typeOf(bin_op.lhs);
4914 const elem_ty = src_ptr_ty.childType(mod);
4915 const elem_ty = src_ptr_ty.childType(zcu);
49154916 const ptr_id = try self.resolve(bin_op.lhs);
49164917
4917 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4918 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
49184919 const dst_ptr_ty = self.typeOfIndex(inst);
49194920 return try self.bitCast(dst_ptr_ty, src_ptr_ty, ptr_id);
49204921 }
......@@ -4924,10 +4925,10 @@ const NavGen = struct {
49244925 }
49254926
49264927 fn airArrayElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4927 const mod = self.pt.zcu;
4928 const zcu = self.pt.zcu;
49284929 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
49294930 const array_ty = self.typeOf(bin_op.lhs);
4930 const elem_ty = array_ty.childType(mod);
4931 const elem_ty = array_ty.childType(zcu);
49314932 const array_id = try self.resolve(bin_op.lhs);
49324933 const index_id = try self.resolve(bin_op.rhs);
49334934
......@@ -4946,7 +4947,7 @@ const NavGen = struct {
49464947 // For now, just generate a temporary and use that.
49474948 // TODO: This backend probably also should use isByRef from llvm...
49484949
4949 const is_vector = array_ty.isVector(mod);
4950 const is_vector = array_ty.isVector(zcu);
49504951
49514952 const elem_repr: Repr = if (is_vector) .direct else .indirect;
49524953 const ptr_array_ty_id = try self.ptrType2(array_ty, .Function, .direct);
......@@ -4985,26 +4986,26 @@ const NavGen = struct {
49854986 }
49864987
49874988 fn airPtrElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4988 const mod = self.pt.zcu;
4989 const zcu = self.pt.zcu;
49894990 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
49904991 const ptr_ty = self.typeOf(bin_op.lhs);
49914992 const elem_ty = self.typeOfIndex(inst);
49924993 const ptr_id = try self.resolve(bin_op.lhs);
49934994 const index_id = try self.resolve(bin_op.rhs);
49944995 const elem_ptr_id = try self.ptrElemPtr(ptr_ty, ptr_id, index_id);
4995 return try self.load(elem_ty, elem_ptr_id, .{ .is_volatile = ptr_ty.isVolatilePtr(mod) });
4996 return try self.load(elem_ty, elem_ptr_id, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) });
49964997 }
49974998
49984999 fn airVectorStoreElem(self: *NavGen, inst: Air.Inst.Index) !void {
4999 const mod = self.pt.zcu;
5000 const zcu = self.pt.zcu;
50005001 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
50015002 const extra = self.air.extraData(Air.Bin, data.payload).data;
50025003
50035004 const vector_ptr_ty = self.typeOf(data.vector_ptr);
5004 const vector_ty = vector_ptr_ty.childType(mod);
5005 const scalar_ty = vector_ty.scalarType(mod);
5005 const vector_ty = vector_ptr_ty.childType(zcu);
5006 const scalar_ty = vector_ty.scalarType(zcu);
50065007
5007 const storage_class = self.spvStorageClass(vector_ptr_ty.ptrAddressSpace(mod));
5008 const storage_class = self.spvStorageClass(vector_ptr_ty.ptrAddressSpace(zcu));
50085009 const scalar_ptr_ty_id = try self.ptrType(scalar_ty, storage_class);
50095010
50105011 const vector_ptr = try self.resolve(data.vector_ptr);
......@@ -5013,30 +5014,30 @@ const NavGen = struct {
50135014
50145015 const elem_ptr_id = try self.accessChainId(scalar_ptr_ty_id, vector_ptr, &.{index});
50155016 try self.store(scalar_ty, elem_ptr_id, operand, .{
5016 .is_volatile = vector_ptr_ty.isVolatilePtr(mod),
5017 .is_volatile = vector_ptr_ty.isVolatilePtr(zcu),
50175018 });
50185019 }
50195020
50205021 fn airSetUnionTag(self: *NavGen, inst: Air.Inst.Index) !void {
5021 const mod = self.pt.zcu;
5022 const zcu = self.pt.zcu;
50225023 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
50235024 const un_ptr_ty = self.typeOf(bin_op.lhs);
5024 const un_ty = un_ptr_ty.childType(mod);
5025 const un_ty = un_ptr_ty.childType(zcu);
50255026 const layout = self.unionLayout(un_ty);
50265027
50275028 if (layout.tag_size == 0) return;
50285029
5029 const tag_ty = un_ty.unionTagTypeSafety(mod).?;
5030 const tag_ptr_ty_id = try self.ptrType(tag_ty, self.spvStorageClass(un_ptr_ty.ptrAddressSpace(mod)));
5030 const tag_ty = un_ty.unionTagTypeSafety(zcu).?;
5031 const tag_ptr_ty_id = try self.ptrType(tag_ty, self.spvStorageClass(un_ptr_ty.ptrAddressSpace(zcu)));
50315032
50325033 const union_ptr_id = try self.resolve(bin_op.lhs);
50335034 const new_tag_id = try self.resolve(bin_op.rhs);
50345035
50355036 if (!layout.has_payload) {
5036 try self.store(tag_ty, union_ptr_id, new_tag_id, .{ .is_volatile = un_ptr_ty.isVolatilePtr(mod) });
5037 try self.store(tag_ty, union_ptr_id, new_tag_id, .{ .is_volatile = un_ptr_ty.isVolatilePtr(zcu) });
50375038 } else {
50385039 const ptr_id = try self.accessChain(tag_ptr_ty_id, union_ptr_id, &.{layout.tag_index});
5039 try self.store(tag_ty, ptr_id, new_tag_id, .{ .is_volatile = un_ptr_ty.isVolatilePtr(mod) });
5040 try self.store(tag_ty, ptr_id, new_tag_id, .{ .is_volatile = un_ptr_ty.isVolatilePtr(zcu) });
50405041 }
50415042 }
50425043
......@@ -5044,14 +5045,14 @@ const NavGen = struct {
50445045 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50455046 const un_ty = self.typeOf(ty_op.operand);
50465047
5047 const mod = self.pt.zcu;
5048 const zcu = self.pt.zcu;
50485049 const layout = self.unionLayout(un_ty);
50495050 if (layout.tag_size == 0) return null;
50505051
50515052 const union_handle = try self.resolve(ty_op.operand);
50525053 if (!layout.has_payload) return union_handle;
50535054
5054 const tag_ty = un_ty.unionTagTypeSafety(mod).?;
5055 const tag_ty = un_ty.unionTagTypeSafety(zcu).?;
50555056 return try self.extractField(tag_ty, union_handle, layout.tag_index);
50565057 }
50575058
......@@ -5068,9 +5069,9 @@ const NavGen = struct {
50685069 // Note: The result here is not cached, because it generates runtime code.
50695070
50705071 const pt = self.pt;
5071 const mod = pt.zcu;
5072 const ip = &mod.intern_pool;
5073 const union_ty = mod.typeToUnion(ty).?;
5072 const zcu = pt.zcu;
5073 const ip = &zcu.intern_pool;
5074 const union_ty = zcu.typeToUnion(ty).?;
50745075 const tag_ty = Type.fromInterned(union_ty.enum_tag_ty);
50755076
50765077 if (union_ty.flagsUnordered(ip).layout == .@"packed") {
......@@ -5082,7 +5083,7 @@ const NavGen = struct {
50825083 const tag_int = if (layout.tag_size != 0) blk: {
50835084 const tag_val = try pt.enumValueFieldIndex(tag_ty, active_field);
50845085 const tag_int_val = try tag_val.intFromEnum(tag_ty, pt);
5085 break :blk tag_int_val.toUnsignedInt(pt);
5086 break :blk tag_int_val.toUnsignedInt(zcu);
50865087 } else 0;
50875088
50885089 if (!layout.has_payload) {
......@@ -5099,7 +5100,7 @@ const NavGen = struct {
50995100 }
51005101
51015102 const payload_ty = Type.fromInterned(union_ty.field_types.get(ip)[active_field]);
5102 if (payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5103 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
51035104 const pl_ptr_ty_id = try self.ptrType(layout.payload_ty, .Function);
51045105 const pl_ptr_id = try self.accessChain(pl_ptr_ty_id, tmp_id, &.{layout.payload_index});
51055106 const active_pl_ptr_ty_id = try self.ptrType(payload_ty, .Function);
......@@ -5123,15 +5124,15 @@ const NavGen = struct {
51235124
51245125 fn airUnionInit(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
51255126 const pt = self.pt;
5126 const mod = pt.zcu;
5127 const ip = &mod.intern_pool;
5127 const zcu = pt.zcu;
5128 const ip = &zcu.intern_pool;
51285129 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
51295130 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
51305131 const ty = self.typeOfIndex(inst);
51315132
5132 const union_obj = mod.typeToUnion(ty).?;
5133 const union_obj = zcu.typeToUnion(ty).?;
51335134 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
5134 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(pt))
5135 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(zcu))
51355136 try self.resolve(extra.init)
51365137 else
51375138 null;
......@@ -5140,23 +5141,23 @@ const NavGen = struct {
51405141
51415142 fn airStructFieldVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
51425143 const pt = self.pt;
5143 const mod = pt.zcu;
5144 const zcu = pt.zcu;
51445145 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
51455146 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
51465147
51475148 const object_ty = self.typeOf(struct_field.struct_operand);
51485149 const object_id = try self.resolve(struct_field.struct_operand);
51495150 const field_index = struct_field.field_index;
5150 const field_ty = object_ty.structFieldType(field_index, mod);
5151 const field_ty = object_ty.structFieldType(field_index, zcu);
51515152
5152 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) return null;
5153 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) return null;
51535154
5154 switch (object_ty.zigTypeTag(mod)) {
5155 .Struct => switch (object_ty.containerLayout(mod)) {
5155 switch (object_ty.zigTypeTag(zcu)) {
5156 .Struct => switch (object_ty.containerLayout(zcu)) {
51565157 .@"packed" => unreachable, // TODO
51575158 else => return try self.extractField(field_ty, object_id, field_index),
51585159 },
5159 .Union => switch (object_ty.containerLayout(mod)) {
5160 .Union => switch (object_ty.containerLayout(zcu)) {
51605161 .@"packed" => unreachable, // TODO
51615162 else => {
51625163 // Store, ptr-elem-ptr, pointer-cast, load
......@@ -5185,16 +5186,16 @@ const NavGen = struct {
51855186
51865187 fn airFieldParentPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
51875188 const pt = self.pt;
5188 const mod = pt.zcu;
5189 const zcu = pt.zcu;
51895190 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
51905191 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
51915192
5192 const parent_ty = ty_pl.ty.toType().childType(mod);
5193 const parent_ty = ty_pl.ty.toType().childType(zcu);
51935194 const result_ty_id = try self.resolveType(ty_pl.ty.toType(), .indirect);
51945195
51955196 const field_ptr = try self.resolve(extra.field_ptr);
51965197 const field_ptr_int = try self.intFromPtr(field_ptr);
5197 const field_offset = parent_ty.structFieldOffset(extra.field_index, pt);
5198 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
51985199
51995200 const base_ptr_int = base_ptr_int: {
52005201 if (field_offset == 0) break :base_ptr_int field_ptr_int;
......@@ -5319,10 +5320,10 @@ const NavGen = struct {
53195320 }
53205321
53215322 fn airAlloc(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5322 const mod = self.pt.zcu;
5323 const zcu = self.pt.zcu;
53235324 const ptr_ty = self.typeOfIndex(inst);
5324 assert(ptr_ty.ptrAddressSpace(mod) == .generic);
5325 const child_ty = ptr_ty.childType(mod);
5325 assert(ptr_ty.ptrAddressSpace(zcu) == .generic);
5326 const child_ty = ptr_ty.childType(zcu);
53265327 return try self.alloc(child_ty, .{});
53275328 }
53285329
......@@ -5494,9 +5495,9 @@ const NavGen = struct {
54945495 // ir.Block in a different SPIR-V block.
54955496
54965497 const pt = self.pt;
5497 const mod = pt.zcu;
5498 const zcu = pt.zcu;
54985499 const ty = self.typeOfIndex(inst);
5499 const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(pt);
5500 const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu);
55005501
55015502 const cf = switch (self.control_flow) {
55025503 .structured => |*cf| cf,
......@@ -5570,7 +5571,7 @@ const NavGen = struct {
55705571
55715572 const sblock = cf.block_stack.getLast();
55725573
5573 if (ty.isNoReturn(mod)) {
5574 if (ty.isNoReturn(zcu)) {
55745575 // If this block is noreturn, this instruction is the last of a block,
55755576 // and we must simply jump to the block's merge unconditionally.
55765577 try self.structuredBreak(next_block);
......@@ -5626,13 +5627,13 @@ const NavGen = struct {
56265627 }
56275628
56285629 fn airBr(self: *NavGen, inst: Air.Inst.Index) !void {
5629 const pt = self.pt;
5630 const zcu = self.pt.zcu;
56305631 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
56315632 const operand_ty = self.typeOf(br.operand);
56325633
56335634 switch (self.control_flow) {
56345635 .structured => |*cf| {
5635 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
5636 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
56365637 const operand_id = try self.resolve(br.operand);
56375638 const block_result_var_id = cf.block_results.get(br.block_inst).?;
56385639 try self.store(operand_ty, block_result_var_id, operand_id, .{});
......@@ -5643,7 +5644,7 @@ const NavGen = struct {
56435644 },
56445645 .unstructured => |cf| {
56455646 const block = cf.blocks.get(br.block_inst).?;
5646 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
5647 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
56475648 const operand_id = try self.resolve(br.operand);
56485649 // current_block_label should not be undefined here, lest there
56495650 // is a br or br_void in the function's body.
......@@ -5770,35 +5771,35 @@ const NavGen = struct {
57705771 }
57715772
57725773 fn airLoad(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5773 const mod = self.pt.zcu;
5774 const zcu = self.pt.zcu;
57745775 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
57755776 const ptr_ty = self.typeOf(ty_op.operand);
57765777 const elem_ty = self.typeOfIndex(inst);
57775778 const operand = try self.resolve(ty_op.operand);
5778 if (!ptr_ty.isVolatilePtr(mod) and self.liveness.isUnused(inst)) return null;
5779 if (!ptr_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) return null;
57795780
5780 return try self.load(elem_ty, operand, .{ .is_volatile = ptr_ty.isVolatilePtr(mod) });
5781 return try self.load(elem_ty, operand, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) });
57815782 }
57825783
57835784 fn airStore(self: *NavGen, inst: Air.Inst.Index) !void {
5784 const mod = self.pt.zcu;
5785 const zcu = self.pt.zcu;
57855786 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
57865787 const ptr_ty = self.typeOf(bin_op.lhs);
5787 const elem_ty = ptr_ty.childType(mod);
5788 const elem_ty = ptr_ty.childType(zcu);
57885789 const ptr = try self.resolve(bin_op.lhs);
57895790 const value = try self.resolve(bin_op.rhs);
57905791
5791 try self.store(elem_ty, ptr, value, .{ .is_volatile = ptr_ty.isVolatilePtr(mod) });
5792 try self.store(elem_ty, ptr, value, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) });
57925793 }
57935794
57945795 fn airRet(self: *NavGen, inst: Air.Inst.Index) !void {
57955796 const pt = self.pt;
5796 const mod = pt.zcu;
5797 const zcu = pt.zcu;
57975798 const operand = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
57985799 const ret_ty = self.typeOf(operand);
5799 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5800 const fn_info = mod.typeToFunc(mod.navValue(self.owner_nav).typeOf(mod)).?;
5801 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
5800 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5801 const fn_info = zcu.typeToFunc(zcu.navValue(self.owner_nav).typeOf(zcu)).?;
5802 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
58025803 // Functions with an empty error set are emitted with an error code
58035804 // return type and return zero so they can be function pointers coerced
58045805 // to functions that return anyerror.
......@@ -5815,14 +5816,14 @@ const NavGen = struct {
58155816
58165817 fn airRetLoad(self: *NavGen, inst: Air.Inst.Index) !void {
58175818 const pt = self.pt;
5818 const mod = pt.zcu;
5819 const zcu = pt.zcu;
58195820 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
58205821 const ptr_ty = self.typeOf(un_op);
5821 const ret_ty = ptr_ty.childType(mod);
5822 const ret_ty = ptr_ty.childType(zcu);
58225823
5823 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {
5824 const fn_info = mod.typeToFunc(mod.navValue(self.owner_nav).typeOf(mod)).?;
5825 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
5824 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5825 const fn_info = zcu.typeToFunc(zcu.navValue(self.owner_nav).typeOf(zcu)).?;
5826 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
58265827 // Functions with an empty error set are emitted with an error code
58275828 // return type and return zero so they can be function pointers coerced
58285829 // to functions that return anyerror.
......@@ -5834,14 +5835,14 @@ const NavGen = struct {
58345835 }
58355836
58365837 const ptr = try self.resolve(un_op);
5837 const value = try self.load(ret_ty, ptr, .{ .is_volatile = ptr_ty.isVolatilePtr(mod) });
5838 const value = try self.load(ret_ty, ptr, .{ .is_volatile = ptr_ty.isVolatilePtr(zcu) });
58385839 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{
58395840 .value = value,
58405841 });
58415842 }
58425843
58435844 fn airTry(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5844 const mod = self.pt.zcu;
5845 const zcu = self.pt.zcu;
58455846 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
58465847 const err_union_id = try self.resolve(pl_op.operand);
58475848 const extra = self.air.extraData(Air.Try, pl_op.payload);
......@@ -5854,7 +5855,7 @@ const NavGen = struct {
58545855
58555856 const eu_layout = self.errorUnionLayout(payload_ty);
58565857
5857 if (!err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
5858 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
58585859 const err_id = if (eu_layout.payload_has_bits)
58595860 try self.extractField(Type.anyerror, err_union_id, eu_layout.errorFieldIndex())
58605861 else
......@@ -5911,18 +5912,18 @@ const NavGen = struct {
59115912 }
59125913
59135914 fn airErrUnionErr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5914 const mod = self.pt.zcu;
5915 const zcu = self.pt.zcu;
59155916 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59165917 const operand_id = try self.resolve(ty_op.operand);
59175918 const err_union_ty = self.typeOf(ty_op.operand);
59185919 const err_ty_id = try self.resolveType(Type.anyerror, .direct);
59195920
5920 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
5921 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
59215922 // No error possible, so just return undefined.
59225923 return try self.spv.constUndef(err_ty_id);
59235924 }
59245925
5925 const payload_ty = err_union_ty.errorUnionPayload(mod);
5926 const payload_ty = err_union_ty.errorUnionPayload(zcu);
59265927 const eu_layout = self.errorUnionLayout(payload_ty);
59275928
59285929 if (!eu_layout.payload_has_bits) {
......@@ -5947,10 +5948,10 @@ const NavGen = struct {
59475948 }
59485949
59495950 fn airWrapErrUnionErr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5950 const mod = self.pt.zcu;
5951 const zcu = self.pt.zcu;
59515952 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
59525953 const err_union_ty = self.typeOfIndex(inst);
5953 const payload_ty = err_union_ty.errorUnionPayload(mod);
5954 const payload_ty = err_union_ty.errorUnionPayload(zcu);
59545955 const operand_id = try self.resolve(ty_op.operand);
59555956 const eu_layout = self.errorUnionLayout(payload_ty);
59565957
......@@ -5995,28 +5996,28 @@ const NavGen = struct {
59955996
59965997 fn airIsNull(self: *NavGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum { is_null, is_non_null }) !?IdRef {
59975998 const pt = self.pt;
5998 const mod = pt.zcu;
5999 const zcu = pt.zcu;
59996000 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
60006001 const operand_id = try self.resolve(un_op);
60016002 const operand_ty = self.typeOf(un_op);
6002 const optional_ty = if (is_pointer) operand_ty.childType(mod) else operand_ty;
6003 const payload_ty = optional_ty.optionalChild(mod);
6003 const optional_ty = if (is_pointer) operand_ty.childType(zcu) else operand_ty;
6004 const payload_ty = optional_ty.optionalChild(zcu);
60046005
60056006 const bool_ty_id = try self.resolveType(Type.bool, .direct);
60066007
6007 if (optional_ty.optionalReprIsPayload(mod)) {
6008 if (optional_ty.optionalReprIsPayload(zcu)) {
60086009 // Pointer payload represents nullability: pointer or slice.
60096010 const loaded_id = if (is_pointer)
60106011 try self.load(optional_ty, operand_id, .{})
60116012 else
60126013 operand_id;
60136014
6014 const ptr_ty = if (payload_ty.isSlice(mod))
6015 payload_ty.slicePtrFieldType(mod)
6015 const ptr_ty = if (payload_ty.isSlice(zcu))
6016 payload_ty.slicePtrFieldType(zcu)
60166017 else
60176018 payload_ty;
60186019
6019 const ptr_id = if (payload_ty.isSlice(mod))
6020 const ptr_id = if (payload_ty.isSlice(zcu))
60206021 try self.extractField(ptr_ty, loaded_id, 0)
60216022 else
60226023 loaded_id;
......@@ -6036,8 +6037,8 @@ const NavGen = struct {
60366037
60376038 const is_non_null_id = blk: {
60386039 if (is_pointer) {
6039 if (payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
6040 const storage_class = self.spvStorageClass(operand_ty.ptrAddressSpace(mod));
6040 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6041 const storage_class = self.spvStorageClass(operand_ty.ptrAddressSpace(zcu));
60416042 const bool_ptr_ty_id = try self.ptrType(Type.bool, storage_class);
60426043 const tag_ptr_id = try self.accessChain(bool_ptr_ty_id, operand_id, &.{1});
60436044 break :blk try self.load(Type.bool, tag_ptr_id, .{});
......@@ -6046,7 +6047,7 @@ const NavGen = struct {
60466047 break :blk try self.load(Type.bool, operand_id, .{});
60476048 }
60486049
6049 break :blk if (payload_ty.hasRuntimeBitsIgnoreComptime(pt))
6050 break :blk if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
60506051 try self.extractField(Type.bool, operand_id, 1)
60516052 else
60526053 // Optional representation is bool indicating whether the optional is set
......@@ -6071,16 +6072,16 @@ const NavGen = struct {
60716072 }
60726073
60736074 fn airIsErr(self: *NavGen, inst: Air.Inst.Index, pred: enum { is_err, is_non_err }) !?IdRef {
6074 const mod = self.pt.zcu;
6075 const zcu = self.pt.zcu;
60756076 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
60766077 const operand_id = try self.resolve(un_op);
60776078 const err_union_ty = self.typeOf(un_op);
60786079
6079 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
6080 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
60806081 return try self.constBool(pred == .is_non_err, .direct);
60816082 }
60826083
6083 const payload_ty = err_union_ty.errorUnionPayload(mod);
6084 const payload_ty = err_union_ty.errorUnionPayload(zcu);
60846085 const eu_layout = self.errorUnionLayout(payload_ty);
60856086 const bool_ty_id = try self.resolveType(Type.bool, .direct);
60866087
......@@ -6105,15 +6106,15 @@ const NavGen = struct {
61056106
61066107 fn airUnwrapOptional(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
61076108 const pt = self.pt;
6108 const mod = pt.zcu;
6109 const zcu = pt.zcu;
61096110 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61106111 const operand_id = try self.resolve(ty_op.operand);
61116112 const optional_ty = self.typeOf(ty_op.operand);
61126113 const payload_ty = self.typeOfIndex(inst);
61136114
6114 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return null;
6115 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return null;
61156116
6116 if (optional_ty.optionalReprIsPayload(mod)) {
6117 if (optional_ty.optionalReprIsPayload(zcu)) {
61176118 return operand_id;
61186119 }
61196120
......@@ -6122,22 +6123,22 @@ const NavGen = struct {
61226123
61236124 fn airUnwrapOptionalPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
61246125 const pt = self.pt;
6125 const mod = pt.zcu;
6126 const zcu = pt.zcu;
61266127 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61276128 const operand_id = try self.resolve(ty_op.operand);
61286129 const operand_ty = self.typeOf(ty_op.operand);
6129 const optional_ty = operand_ty.childType(mod);
6130 const payload_ty = optional_ty.optionalChild(mod);
6130 const optional_ty = operand_ty.childType(zcu);
6131 const payload_ty = optional_ty.optionalChild(zcu);
61316132 const result_ty = self.typeOfIndex(inst);
61326133 const result_ty_id = try self.resolveType(result_ty, .direct);
61336134
6134 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
6135 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
61356136 // There is no payload, but we still need to return a valid pointer.
61366137 // We can just return anything here, so just return a pointer to the operand.
61376138 return try self.bitCast(result_ty, operand_ty, operand_id);
61386139 }
61396140
6140 if (optional_ty.optionalReprIsPayload(mod)) {
6141 if (optional_ty.optionalReprIsPayload(zcu)) {
61416142 // They are the same value.
61426143 return try self.bitCast(result_ty, operand_ty, operand_id);
61436144 }
......@@ -6147,18 +6148,18 @@ const NavGen = struct {
61476148
61486149 fn airWrapOptional(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
61496150 const pt = self.pt;
6150 const mod = pt.zcu;
6151 const zcu = pt.zcu;
61516152 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61526153 const payload_ty = self.typeOf(ty_op.operand);
61536154
6154 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
6155 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
61556156 return try self.constBool(true, .indirect);
61566157 }
61576158
61586159 const operand_id = try self.resolve(ty_op.operand);
61596160
61606161 const optional_ty = self.typeOfIndex(inst);
6161 if (optional_ty.optionalReprIsPayload(mod)) {
6162 if (optional_ty.optionalReprIsPayload(zcu)) {
61626163 return operand_id;
61636164 }
61646165
......@@ -6170,7 +6171,7 @@ const NavGen = struct {
61706171
61716172 fn airSwitchBr(self: *NavGen, inst: Air.Inst.Index) !void {
61726173 const pt = self.pt;
6173 const mod = pt.zcu;
6174 const zcu = pt.zcu;
61746175 const target = self.getTarget();
61756176 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
61766177 const cond_ty = self.typeOf(pl_op.operand);
......@@ -6178,18 +6179,18 @@ const NavGen = struct {
61786179 var cond_indirect = try self.convertToIndirect(cond_ty, cond);
61796180 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);
61806181
6181 const cond_words: u32 = switch (cond_ty.zigTypeTag(mod)) {
6182 const cond_words: u32 = switch (cond_ty.zigTypeTag(zcu)) {
61826183 .Bool, .ErrorSet => 1,
61836184 .Int => blk: {
6184 const bits = cond_ty.intInfo(mod).bits;
6185 const bits = cond_ty.intInfo(zcu).bits;
61856186 const backing_bits = self.backingIntBits(bits) orelse {
61866187 return self.todo("implement composite int switch", .{});
61876188 };
61886189 break :blk if (backing_bits <= 32) 1 else 2;
61896190 },
61906191 .Enum => blk: {
6191 const int_ty = cond_ty.intTagType(mod);
6192 const int_info = int_ty.intInfo(mod);
6192 const int_ty = cond_ty.intTagType(zcu);
6193 const int_info = int_ty.intInfo(zcu);
61936194 const backing_bits = self.backingIntBits(int_info.bits) orelse {
61946195 return self.todo("implement composite int switch", .{});
61956196 };
......@@ -6200,7 +6201,7 @@ const NavGen = struct {
62006201 break :blk target.ptrBitWidth() / 32;
62016202 },
62026203 // TODO: Figure out which types apply here, and work around them as we can only do integers.
6203 else => return self.todo("implement switch for type {s}", .{@tagName(cond_ty.zigTypeTag(mod))}),
6204 else => return self.todo("implement switch for type {s}", .{@tagName(cond_ty.zigTypeTag(zcu))}),
62046205 };
62056206
62066207 const num_cases = switch_br.data.cases_len;
......@@ -6255,14 +6256,14 @@ const NavGen = struct {
62556256
62566257 for (items) |item| {
62576258 const value = (try self.air.value(item, pt)) orelse unreachable;
6258 const int_val: u64 = switch (cond_ty.zigTypeTag(mod)) {
6259 .Bool, .Int => if (cond_ty.isSignedInt(mod)) @bitCast(value.toSignedInt(pt)) else value.toUnsignedInt(pt),
6259 const int_val: u64 = switch (cond_ty.zigTypeTag(zcu)) {
6260 .Bool, .Int => if (cond_ty.isSignedInt(zcu)) @bitCast(value.toSignedInt(zcu)) else value.toUnsignedInt(zcu),
62606261 .Enum => blk: {
62616262 // TODO: figure out of cond_ty is correct (something with enum literals)
6262 break :blk (try value.intFromEnum(cond_ty, pt)).toUnsignedInt(pt); // TODO: composite integer constants
6263 break :blk (try value.intFromEnum(cond_ty, pt)).toUnsignedInt(zcu); // TODO: composite integer constants
62636264 },
6264 .ErrorSet => value.getErrorInt(mod),
6265 .Pointer => value.toUnsignedInt(pt),
6265 .ErrorSet => value.getErrorInt(zcu),
6266 .Pointer => value.toUnsignedInt(zcu),
62666267 else => unreachable,
62676268 };
62686269 const int_lit: spec.LiteralContextDependentNumber = switch (cond_words) {
......@@ -6343,9 +6344,9 @@ const NavGen = struct {
63436344
63446345 fn airDbgStmt(self: *NavGen, inst: Air.Inst.Index) !void {
63456346 const pt = self.pt;
6346 const mod = pt.zcu;
6347 const zcu = pt.zcu;
63476348 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;
6348 const path = mod.navFileScope(self.owner_nav).sub_file_path;
6349 const path = zcu.navFileScope(self.owner_nav).sub_file_path;
63496350 try self.func.body.emit(self.spv.gpa, .OpLine, .{
63506351 .file = try self.spv.resolveString(path),
63516352 .line = self.base_line + dbg_stmt.line + 1,
......@@ -6354,12 +6355,12 @@ const NavGen = struct {
63546355 }
63556356
63566357 fn airDbgInlineBlock(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
6357 const mod = self.pt.zcu;
6358 const zcu = self.pt.zcu;
63586359 const inst_datas = self.air.instructions.items(.data);
63596360 const extra = self.air.extraData(Air.DbgInlineBlock, inst_datas[@intFromEnum(inst)].ty_pl.payload);
63606361 const old_base_line = self.base_line;
63616362 defer self.base_line = old_base_line;
6362 self.base_line = mod.navSrcLine(mod.funcInfo(extra.data.func).owner_nav);
6363 self.base_line = zcu.navSrcLine(zcu.funcInfo(extra.data.func).owner_nav);
63636364 return self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
63646365 }
63656366
......@@ -6371,7 +6372,7 @@ const NavGen = struct {
63716372 }
63726373
63736374 fn airAssembly(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
6374 const mod = self.pt.zcu;
6375 const zcu = self.pt.zcu;
63756376 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
63766377 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
63776378
......@@ -6453,20 +6454,20 @@ const NavGen = struct {
64536454 // TODO: Translate proper error locations.
64546455 assert(as.errors.items.len != 0);
64556456 assert(self.error_msg == null);
6456 const src_loc = mod.navSrcLoc(self.owner_nav);
6457 self.error_msg = try Zcu.ErrorMsg.create(mod.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
6458 const notes = try mod.gpa.alloc(Zcu.ErrorMsg, as.errors.items.len);
6457 const src_loc = zcu.navSrcLoc(self.owner_nav);
6458 self.error_msg = try Zcu.ErrorMsg.create(zcu.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
6459 const notes = try zcu.gpa.alloc(Zcu.ErrorMsg, as.errors.items.len);
64596460
64606461 // Sub-scope to prevent `return error.CodegenFail` from running the errdefers.
64616462 {
6462 errdefer mod.gpa.free(notes);
6463 errdefer zcu.gpa.free(notes);
64636464 var i: usize = 0;
64646465 errdefer for (notes[0..i]) |*note| {
6465 note.deinit(mod.gpa);
6466 note.deinit(zcu.gpa);
64666467 };
64676468
64686469 while (i < as.errors.items.len) : (i += 1) {
6469 notes[i] = try Zcu.ErrorMsg.init(mod.gpa, src_loc, "{s}", .{as.errors.items[i].msg});
6470 notes[i] = try Zcu.ErrorMsg.init(zcu.gpa, src_loc, "{s}", .{as.errors.items[i].msg});
64706471 }
64716472 }
64726473 self.error_msg.?.notes = notes;
......@@ -6503,17 +6504,17 @@ const NavGen = struct {
65036504 _ = modifier;
65046505
65056506 const pt = self.pt;
6506 const mod = pt.zcu;
6507 const zcu = pt.zcu;
65076508 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
65086509 const extra = self.air.extraData(Air.Call, pl_op.payload);
65096510 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
65106511 const callee_ty = self.typeOf(pl_op.operand);
6511 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
6512 const zig_fn_ty = switch (callee_ty.zigTypeTag(zcu)) {
65126513 .Fn => callee_ty,
65136514 .Pointer => return self.fail("cannot call function pointers", .{}),
65146515 else => unreachable,
65156516 };
6516 const fn_info = mod.typeToFunc(zig_fn_ty).?;
6517 const fn_info = zcu.typeToFunc(zig_fn_ty).?;
65176518 const return_type = fn_info.return_type;
65186519
65196520 const result_type_id = try self.resolveFnReturnType(Type.fromInterned(return_type));
......@@ -6529,7 +6530,7 @@ const NavGen = struct {
65296530 // before starting to emit OpFunctionCall instructions. Hence the
65306531 // temporary params buffer.
65316532 const arg_ty = self.typeOf(arg);
6532 if (!arg_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
6533 if (!arg_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
65336534 const arg_id = try self.resolve(arg);
65346535
65356536 params[n_params] = arg_id;
......@@ -6547,7 +6548,7 @@ const NavGen = struct {
65476548 try self.func.body.emit(self.spv.gpa, .OpUnreachable, {});
65486549 }
65496550
6550 if (self.liveness.isUnused(inst) or !Type.fromInterned(return_type).hasRuntimeBitsIgnoreComptime(pt)) {
6551 if (self.liveness.isUnused(inst) or !Type.fromInterned(return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
65516552 return null;
65526553 }
65536554
......@@ -6604,12 +6605,12 @@ const NavGen = struct {
66046605 }
66056606
66066607 fn typeOf(self: *NavGen, inst: Air.Inst.Ref) Type {
6607 const mod = self.pt.zcu;
6608 return self.air.typeOf(inst, &mod.intern_pool);
6608 const zcu = self.pt.zcu;
6609 return self.air.typeOf(inst, &zcu.intern_pool);
66096610 }
66106611
66116612 fn typeOfIndex(self: *NavGen, inst: Air.Inst.Index) Type {
6612 const mod = self.pt.zcu;
6613 return self.air.typeOfIndex(inst, &mod.intern_pool);
6613 const zcu = self.pt.zcu;
6614 return self.air.typeOfIndex(inst, &zcu.intern_pool);
66146615 }
66156616};
src/link/Coff.zig+4-4
......@@ -1259,8 +1259,8 @@ fn updateLazySymbolAtom(
12591259 atom_index: Atom.Index,
12601260 section_index: u16,
12611261) !void {
1262 const mod = pt.zcu;
1263 const gpa = mod.gpa;
1262 const zcu = pt.zcu;
1263 const gpa = zcu.gpa;
12641264
12651265 var required_alignment: InternPool.Alignment = .none;
12661266 var code_buffer = std.ArrayList(u8).init(gpa);
......@@ -1275,7 +1275,7 @@ fn updateLazySymbolAtom(
12751275 const atom = self.getAtomPtr(atom_index);
12761276 const local_sym_index = atom.getSymbolIndex().?;
12771277
1278 const src = Type.fromInterned(sym.ty).srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
1278 const src = Type.fromInterned(sym.ty).srcLocOrNull(zcu) orelse Zcu.LazySrcLoc.unneeded;
12791279 const res = try codegen.generateLazySymbol(
12801280 &self.base,
12811281 pt,
......@@ -1849,7 +1849,7 @@ pub fn lowerUav(
18491849 const gpa = zcu.gpa;
18501850 const val = Value.fromInterned(uav);
18511851 const uav_alignment = switch (explicit_alignment) {
1852 .none => val.typeOf(zcu).abiAlignment(pt),
1852 .none => val.typeOf(zcu).abiAlignment(zcu),
18531853 else => explicit_alignment,
18541854 };
18551855 if (self.uavs.get(uav)) |metadata| {
src/link/Elf/ZigObject.zig+1-1
......@@ -849,7 +849,7 @@ pub fn lowerUav(
849849 const gpa = zcu.gpa;
850850 const val = Value.fromInterned(uav);
851851 const uav_alignment = switch (explicit_alignment) {
852 .none => val.typeOf(zcu).abiAlignment(pt),
852 .none => val.typeOf(zcu).abiAlignment(zcu),
853853 else => explicit_alignment,
854854 };
855855 if (self.uavs.get(uav)) |metadata| {
src/link/MachO/ZigObject.zig+1-1
......@@ -688,7 +688,7 @@ pub fn lowerUav(
688688 const gpa = zcu.gpa;
689689 const val = Value.fromInterned(uav);
690690 const uav_alignment = switch (explicit_alignment) {
691 .none => val.typeOf(zcu).abiAlignment(pt),
691 .none => val.typeOf(zcu).abiAlignment(zcu),
692692 else => explicit_alignment,
693693 };
694694 if (self.uavs.get(uav)) |metadata| {
src/link/Wasm/ZigObject.zig+7-7
......@@ -487,9 +487,9 @@ fn lowerConst(
487487 src_loc: Zcu.LazySrcLoc,
488488) !LowerConstResult {
489489 const gpa = wasm_file.base.comp.gpa;
490 const mod = wasm_file.base.comp.module.?;
490 const zcu = wasm_file.base.comp.module.?;
491491
492 const ty = val.typeOf(mod);
492 const ty = val.typeOf(zcu);
493493
494494 // Create and initialize a new local symbol and atom
495495 const sym_index = try zig_object.allocateSymbol(gpa);
......@@ -499,7 +499,7 @@ fn lowerConst(
499499
500500 const code = code: {
501501 const atom = wasm_file.getAtomPtr(atom_index);
502 atom.alignment = ty.abiAlignment(pt);
502 atom.alignment = ty.abiAlignment(zcu);
503503 const segment_name = try std.mem.concat(gpa, u8, &.{ ".rodata.", name });
504504 errdefer gpa.free(segment_name);
505505 zig_object.symbol(sym_index).* = .{
......@@ -509,7 +509,7 @@ fn lowerConst(
509509 .index = try zig_object.createDataSegment(
510510 gpa,
511511 segment_name,
512 ty.abiAlignment(pt),
512 ty.abiAlignment(zcu),
513513 ),
514514 .virtual_address = undefined,
515515 };
......@@ -555,7 +555,7 @@ pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm, pt: Zcu.Per
555555 const atom_index = try wasm_file.createAtom(sym_index, zig_object.index);
556556 const atom = wasm_file.getAtomPtr(atom_index);
557557 const slice_ty = Type.slice_const_u8_sentinel_0;
558 atom.alignment = slice_ty.abiAlignment(pt);
558 atom.alignment = slice_ty.abiAlignment(pt.zcu);
559559
560560 const sym_name = try zig_object.string_table.insert(gpa, "__zig_err_name_table");
561561 const segment_name = try gpa.dupe(u8, ".rodata.__zig_err_name_table");
......@@ -611,7 +611,7 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per
611611 // TODO: remove this unreachable entry
612612 try atom.code.appendNTimes(gpa, 0, 4);
613613 try atom.code.writer(gpa).writeInt(u32, 0, .little);
614 atom.size += @intCast(slice_ty.abiSize(pt));
614 atom.size += @intCast(slice_ty.abiSize(pt.zcu));
615615 addend += 1;
616616
617617 try names_atom.code.append(gpa, 0);
......@@ -632,7 +632,7 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per
632632 .offset = offset,
633633 .addend = @intCast(addend),
634634 });
635 atom.size += @intCast(slice_ty.abiSize(pt));
635 atom.size += @intCast(slice_ty.abiSize(pt.zcu));
636636 addend += len;
637637
638638 // as we updated the error name table, we now store the actual name within the names atom
src/mutable_value.zig+4-4
......@@ -369,7 +369,7 @@ pub const MutableValue = union(enum) {
369369 .bytes => |b| {
370370 assert(is_trivial_int);
371371 assert(field_val.typeOf(zcu).toIntern() == .u8_type);
372 b.data[field_idx] = @intCast(Value.fromInterned(field_val.interned).toUnsignedInt(pt));
372 b.data[field_idx] = @intCast(Value.fromInterned(field_val.interned).toUnsignedInt(zcu));
373373 },
374374 .repeated => |r| {
375375 if (field_val.eqlTrivial(r.child.*)) return;
......@@ -382,9 +382,9 @@ pub const MutableValue = union(enum) {
382382 {
383383 // We can use the `bytes` representation.
384384 const bytes = try arena.alloc(u8, @intCast(len_inc_sent));
385 const repeated_byte = Value.fromInterned(r.child.interned).toUnsignedInt(pt);
385 const repeated_byte = Value.fromInterned(r.child.interned).toUnsignedInt(zcu);
386386 @memset(bytes, @intCast(repeated_byte));
387 bytes[field_idx] = @intCast(Value.fromInterned(field_val.interned).toUnsignedInt(pt));
387 bytes[field_idx] = @intCast(Value.fromInterned(field_val.interned).toUnsignedInt(zcu));
388388 mv.* = .{ .bytes = .{
389389 .ty = r.ty,
390390 .data = bytes,
......@@ -431,7 +431,7 @@ pub const MutableValue = union(enum) {
431431 } else {
432432 const bytes = try arena.alloc(u8, a.elems.len);
433433 for (a.elems, bytes) |elem_val, *b| {
434 b.* = @intCast(Value.fromInterned(elem_val.interned).toUnsignedInt(pt));
434 b.* = @intCast(Value.fromInterned(elem_val.interned).toUnsignedInt(zcu));
435435 }
436436 mv.* = .{ .bytes = .{
437437 .ty = a.ty,
src/print_value.zig+3-3
......@@ -95,11 +95,11 @@ pub fn print(
9595 .int => |int| switch (int.storage) {
9696 inline .u64, .i64, .big_int => |x| try writer.print("{}", .{x}),
9797 .lazy_align => |ty| if (have_sema) {
98 const a = (try Type.fromInterned(ty).abiAlignmentAdvanced(pt, .sema)).scalar;
98 const a = try Type.fromInterned(ty).abiAlignmentSema(pt);
9999 try writer.print("{}", .{a.toByteUnits() orelse 0});
100100 } else try writer.print("@alignOf({})", .{Type.fromInterned(ty).fmt(pt)}),
101101 .lazy_size => |ty| if (have_sema) {
102 const s = (try Type.fromInterned(ty).abiSizeAdvanced(pt, .sema)).scalar;
102 const s = try Type.fromInterned(ty).abiSizeSema(pt);
103103 try writer.print("{}", .{s});
104104 } else try writer.print("@sizeOf({})", .{Type.fromInterned(ty).fmt(pt)}),
105105 },
......@@ -245,7 +245,7 @@ fn printAggregate(
245245 if (ty.childType(zcu).toIntern() != .u8_type) break :one_byte_str;
246246 const elem_val = Value.fromInterned(aggregate.storage.values()[0]);
247247 if (elem_val.isUndef(zcu)) break :one_byte_str;
248 const byte = elem_val.toUnsignedInt(pt);
248 const byte = elem_val.toUnsignedInt(zcu);
249249 try writer.print("\"{}\"", .{std.zig.fmtEscapes(&.{@intCast(byte)})});
250250 if (!is_ref) try writer.writeAll(".*");
251251 return;