authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-26 23:53:01+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-26 23:53:01+01:00
log492cc2ef8d1d21d96e25541c22ab885a31c62770
tree68a56acd898e308845054123f0cf6816761d3fa1
parent849c31a6cc3d1e554f97c2ccf7aaa886070cfadd
parent61e8a6c0082778e9d7a120fb5b9c30ebf85d586b
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21208 from Rexicon226/pt-begone

Cleanup type resolution and finish `zcu` rename

46 files changed, 7794 insertions(+), 7609 deletions(-)

src/Compilation.zig+37-39
......@@ -50,8 +50,7 @@ gpa: Allocator,
5050/// be used for other things requiring the same lifetime as the `Compilation`.
5151arena: Allocator,
5252/// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`.
53/// TODO: rename to zcu: ?*Zcu
54module: ?*Zcu,
53zcu: ?*Zcu,
5554/// Contains different state depending on whether the Compilation uses
5655/// incremental or whole cache mode.
5756cache_use: CacheUse,
......@@ -1474,7 +1473,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
14741473 comp.* = .{
14751474 .gpa = gpa,
14761475 .arena = arena,
1477 .module = opt_zcu,
1476 .zcu = opt_zcu,
14781477 .cache_use = undefined, // populated below
14791478 .bin_file = null, // populated below
14801479 .implib_emit = null, // handled below
......@@ -1926,7 +1925,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
19261925
19271926pub fn destroy(comp: *Compilation) void {
19281927 if (comp.bin_file) |lf| lf.destroy();
1929 if (comp.module) |zcu| zcu.deinit();
1928 if (comp.zcu) |zcu| zcu.deinit();
19301929 comp.cache_use.deinit();
19311930 for (comp.work_queues) |work_queue| work_queue.deinit();
19321931 if (!InternPool.single_threaded) comp.codegen_work.queue.deinit();
......@@ -2198,7 +2197,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
21982197 };
21992198 }
22002199
2201 if (comp.module) |zcu| {
2200 if (comp.zcu) |zcu| {
22022201 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
22032202
22042203 zcu.compile_log_text.shrinkAndFree(gpa, 0);
......@@ -2268,7 +2267,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
22682267
22692268 try comp.performAllTheWork(main_progress_node);
22702269
2271 if (comp.module) |zcu| {
2270 if (comp.zcu) |zcu| {
22722271 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
22732272
22742273 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
......@@ -2447,7 +2446,7 @@ fn flush(
24472446 };
24482447 }
24492448
2450 if (comp.module) |zcu| {
2449 if (comp.zcu) |zcu| {
24512450 try link.File.C.flushEmitH(zcu);
24522451
24532452 if (zcu.llvm_object) |llvm_object| {
......@@ -2558,7 +2557,7 @@ fn addNonIncrementalStuffToCacheManifest(
25582557
25592558 comptime assert(link_hash_implementation_version == 14);
25602559
2561 if (comp.module) |mod| {
2560 if (comp.zcu) |mod| {
25622561 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.root_mod, mod.main_mod, .{ .files = man });
25632562
25642563 // Synchronize with other matching comments: ZigOnlyHashStuff
......@@ -2692,7 +2691,7 @@ fn addNonIncrementalStuffToCacheManifest(
26922691}
26932692
26942693fn emitOthers(comp: *Compilation) void {
2695 if (comp.config.output_mode != .Obj or comp.module != null or
2694 if (comp.config.output_mode != .Obj or comp.zcu != null or
26962695 comp.c_object_table.count() == 0)
26972696 {
26982697 return;
......@@ -2951,7 +2950,7 @@ pub fn saveState(comp: *Compilation) !void {
29512950 var pt_headers = std.ArrayList(Header.PerThread).init(gpa);
29522951 defer pt_headers.deinit();
29532952
2954 if (comp.module) |zcu| {
2953 if (comp.zcu) |zcu| {
29552954 const ip = &zcu.intern_pool;
29562955 const header: Header = .{
29572956 .intern_pool = .{
......@@ -3092,7 +3091,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30923091 var all_references: ?std.AutoHashMapUnmanaged(InternPool.AnalUnit, ?Zcu.ResolvedReference) = null;
30933092 defer if (all_references) |*a| a.deinit(gpa);
30943093
3095 if (comp.module) |zcu| {
3094 if (comp.zcu) |zcu| {
30963095 const ip = &zcu.intern_pool;
30973096
30983097 for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
......@@ -3246,7 +3245,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
32463245 }
32473246 }
32483247
3249 if (comp.module) |zcu| {
3248 if (comp.zcu) |zcu| {
32503249 if (bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {
32513250 const values = zcu.compile_log_sources.values();
32523251 // First one will be the error; subsequent ones will be notes.
......@@ -3269,7 +3268,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
32693268 }
32703269 }
32713270
3272 if (comp.module) |zcu| {
3271 if (comp.zcu) |zcu| {
32733272 if (comp.incremental and bundle.root_list.items.len == 0) {
32743273 const should_have_error = for (zcu.transitive_failed_analysis.keys()) |failed_unit| {
32753274 if (all_references == null) {
......@@ -3283,7 +3282,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
32833282 }
32843283 }
32853284
3286 const compile_log_text = if (comp.module) |m| m.compile_log_text.items else "";
3285 const compile_log_text = if (comp.zcu) |m| m.compile_log_text.items else "";
32873286 return bundle.toOwnedBundle(compile_log_text);
32883287}
32893288
......@@ -3497,7 +3496,7 @@ pub fn performAllTheWork(
34973496 comp: *Compilation,
34983497 main_progress_node: std.Progress.Node,
34993498) JobError!void {
3500 defer if (comp.module) |mod| {
3499 defer if (comp.zcu) |mod| {
35013500 mod.sema_prog_node.end();
35023501 mod.sema_prog_node = std.Progress.Node.none;
35033502 mod.codegen_prog_node.end();
......@@ -3543,8 +3542,7 @@ fn performAllTheWorkInner(
35433542 // in the `astgen_wait_group`.
35443543 if (comp.job_queued_update_builtin_zig) b: {
35453544 comp.job_queued_update_builtin_zig = false;
3546 const zcu = comp.module orelse break :b;
3547 _ = zcu;
3545 if (comp.zcu == null) break :b;
35483546 // TODO put all the modules in a flat array to make them easy to iterate.
35493547 var seen: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{};
35503548 defer seen.deinit(comp.gpa);
......@@ -3563,7 +3561,7 @@ fn performAllTheWorkInner(
35633561 }
35643562 }
35653563
3566 if (comp.module) |zcu| {
3564 if (comp.zcu) |zcu| {
35673565 {
35683566 // Worker threads may append to zcu.files and zcu.import_table
35693567 // so we must hold the lock while spawning those tasks, since
......@@ -3606,7 +3604,7 @@ fn performAllTheWorkInner(
36063604 if (comp.job_queued_compiler_rt_obj) work_queue_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", .compiler_rt, .Obj, &comp.compiler_rt_obj, main_progress_node });
36073605 if (comp.job_queued_fuzzer_lib) work_queue_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", .libfuzzer, .Lib, &comp.fuzzer_lib, main_progress_node });
36083606
3609 if (comp.module) |zcu| {
3607 if (comp.zcu) |zcu| {
36103608 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
36113609 if (comp.incremental) {
36123610 const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);
......@@ -3638,7 +3636,7 @@ fn performAllTheWorkInner(
36383636 try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job, main_progress_node);
36393637 continue :work;
36403638 };
3641 if (comp.module) |zcu| {
3639 if (comp.zcu) |zcu| {
36423640 // If there's no work queued, check if there's anything outdated
36433641 // which we need to work on, and queue it if so.
36443642 if (try zcu.findOutdatedToAnalyze()) |outdated| {
......@@ -3666,7 +3664,7 @@ pub fn queueJobs(comp: *Compilation, jobs: []const Job) !void {
36663664fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progress.Node) JobError!void {
36673665 switch (job) {
36683666 .codegen_nav => |nav_index| {
3669 const zcu = comp.module.?;
3667 const zcu = comp.zcu.?;
36703668 const nav = zcu.intern_pool.getNav(nav_index);
36713669 if (nav.analysis_owner.unwrap()) |cau| {
36723670 const unit = InternPool.AnalUnit.wrap(.{ .cau = cau });
......@@ -3689,14 +3687,14 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
36893687 const named_frame = tracy.namedFrame("analyze_func");
36903688 defer named_frame.end();
36913689
3692 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3690 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
36933691 pt.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
36943692 error.OutOfMemory => return error.OutOfMemory,
36953693 error.AnalysisFail => return,
36963694 };
36973695 },
36983696 .analyze_cau => |cau_index| {
3699 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3697 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
37003698 pt.ensureCauAnalyzed(cau_index) catch |err| switch (err) {
37013699 error.OutOfMemory => return error.OutOfMemory,
37023700 error.AnalysisFail => return,
......@@ -3725,7 +3723,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
37253723 const named_frame = tracy.namedFrame("resolve_type_fully");
37263724 defer named_frame.end();
37273725
3728 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3726 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
37293727 Type.fromInterned(ty).resolveFully(pt) catch |err| switch (err) {
37303728 error.OutOfMemory => return error.OutOfMemory,
37313729 error.AnalysisFail => return,
......@@ -3738,7 +3736,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
37383736 if (true) @panic("TODO: update_line_number");
37393737
37403738 const gpa = comp.gpa;
3741 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3739 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
37423740 const decl = pt.zcu.declPtr(decl_index);
37433741 const lf = comp.bin_file.?;
37443742 lf.updateDeclLineNumber(pt, decl_index) catch |err| {
......@@ -3760,7 +3758,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
37603758 const named_frame = tracy.namedFrame("analyze_mod");
37613759 defer named_frame.end();
37623760
3763 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3761 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
37643762 pt.semaPkg(mod) catch |err| switch (err) {
37653763 error.OutOfMemory => return error.OutOfMemory,
37663764 error.AnalysisFail => return,
......@@ -3924,7 +3922,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
39243922
39253923fn queueCodegenJob(comp: *Compilation, tid: usize, codegen_job: CodegenJob) !void {
39263924 if (InternPool.single_threaded or
3927 !comp.module.?.backendSupportsFeature(.separate_thread))
3925 !comp.zcu.?.backendSupportsFeature(.separate_thread))
39283926 return processOneCodegenJob(tid, comp, codegen_job);
39293927
39303928 {
......@@ -3963,14 +3961,14 @@ fn processOneCodegenJob(tid: usize, comp: *Compilation, codegen_job: CodegenJob)
39633961 const named_frame = tracy.namedFrame("codegen_nav");
39643962 defer named_frame.end();
39653963
3966 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3964 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
39673965 try pt.linkerUpdateNav(nav_index);
39683966 },
39693967 .func => |func| {
39703968 const named_frame = tracy.namedFrame("codegen_func");
39713969 defer named_frame.end();
39723970
3973 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3971 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
39743972 // This call takes ownership of `func.air`.
39753973 try pt.linkerUpdateFunc(func.func, func.air);
39763974 },
......@@ -3978,7 +3976,7 @@ fn processOneCodegenJob(tid: usize, comp: *Compilation, codegen_job: CodegenJob)
39783976 const named_frame = tracy.namedFrame("codegen_type");
39793977 defer named_frame.end();
39803978
3981 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
3979 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
39823980 try pt.linkerUpdateContainerType(ty);
39833981 },
39843982 }
......@@ -3995,7 +3993,7 @@ fn workerDocsCopy(comp: *Compilation) void {
39953993}
39963994
39973995fn docsCopyFallible(comp: *Compilation) anyerror!void {
3998 const zcu = comp.module orelse
3996 const zcu = comp.zcu orelse
39993997 return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{});
40003998
40013999 const emit = comp.docs_emit.?;
......@@ -4260,7 +4258,7 @@ fn workerAstGenFile(
42604258 const child_prog_node = prog_node.start(file.sub_file_path, 0);
42614259 defer child_prog_node.end();
42624260
4263 const pt: Zcu.PerThread = .{ .zcu = comp.module.?, .tid = @enumFromInt(tid) };
4261 const pt: Zcu.PerThread = .{ .zcu = comp.zcu.?, .tid = @enumFromInt(tid) };
42644262 pt.astGenFile(file, path_digest) catch |err| switch (err) {
42654263 error.AnalysisFail => return,
42664264 else => {
......@@ -4352,8 +4350,8 @@ fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Zcu.EmbedFile) void {
43524350}
43534351
43544352fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Zcu.EmbedFile) !void {
4355 const mod = comp.module.?;
4356 const ip = &mod.intern_pool;
4353 const zcu = comp.zcu.?;
4354 const ip = &zcu.intern_pool;
43574355 var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{});
43584356 defer file.close();
43594357
......@@ -4665,10 +4663,10 @@ fn reportRetryableEmbedFileError(
46654663 embed_file: *Zcu.EmbedFile,
46664664 err: anyerror,
46674665) error{OutOfMemory}!void {
4668 const mod = comp.module.?;
4669 const gpa = mod.gpa;
4666 const zcu = comp.zcu.?;
4667 const gpa = zcu.gpa;
46704668 const src_loc = embed_file.src_loc;
4671 const ip = &mod.intern_pool;
4669 const ip = &zcu.intern_pool;
46724670 const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}/{s}': {s}", .{
46734671 embed_file.owner.root,
46744672 embed_file.sub_file_path.toSlice(ip),
......@@ -4680,7 +4678,7 @@ fn reportRetryableEmbedFileError(
46804678 {
46814679 comp.mutex.lock();
46824680 defer comp.mutex.unlock();
4683 try mod.failed_embed_files.putNoClobber(gpa, embed_file, err_msg);
4681 try zcu.failed_embed_files.putNoClobber(gpa, embed_file, err_msg);
46844682 }
46854683}
46864684
......@@ -4730,7 +4728,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
47304728 // Special case when doing build-obj for just one C file. When there are more than one object
47314729 // file and building an object we need to link them together, but with just one it should go
47324730 // directly to the output file.
4733 const direct_o = comp.c_source_files.len == 1 and comp.module == null and
4731 const direct_o = comp.c_source_files.len == 1 and comp.zcu == null and
47344732 comp.config.output_mode == .Obj and comp.objects.len == 0;
47354733 const o_basename_noext = if (direct_o)
47364734 comp.root_name
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+2181-2266
......@@ -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
......@@ -3545,7 +3544,7 @@ fn zirAllocExtended(
35453544 }
35463545 const target = pt.zcu.getTarget();
35473546 try var_ty.resolveLayout(pt);
3548 if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {
3547 if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
35493548 const var_src = block.src(.{ .node_offset_store_ptr = extra.data.src_node });
35503549 return sema.fail(block, var_src, "local variable in naked function", .{});
35513550 }
......@@ -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;
......@@ -3989,7 +3988,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
39893988 if (block.is_comptime) {
39903989 return sema.analyzeComptimeAlloc(block, var_ty, .none);
39913990 }
3992 if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {
3991 if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
39933992 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
39943993 return sema.fail(block, mut_src, "local variable in naked function", .{});
39953994 }
......@@ -4017,7 +4016,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
40174016 if (block.is_comptime) {
40184017 return sema.analyzeComptimeAlloc(block, var_ty, .none);
40194018 }
4020 if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {
4019 if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
40214020 const var_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
40224021 return sema.fail(block, var_src, "local variable in naked function", .{});
40234022 }
......@@ -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,13 +4147,13 @@ 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
41554154 return sema.fail(block, src, "value with comptime-only type '{}' depends on runtime control flow", .{final_elem_ty.fmt(pt)});
41564155 }
4157 if (sema.func_is_naked and try sema.typeHasRuntimeBits(final_elem_ty)) {
4156 if (sema.func_is_naked and try final_elem_ty.hasRuntimeBitsSema(pt)) {
41584157 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
41594158 return sema.fail(block, mut_src, "local variable in naked function", .{});
41604159 }
......@@ -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.fieldType(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.fieldType(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.fieldType(@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.fieldType(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.fieldType(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.fieldType(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);
......@@ -17535,17 +17534,17 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1753517534 .AnyFrame,
1753617535 => {},
1753717536 }
17538 const val = try ty.lazyAbiSize(pt);
17537 const val = try ty.abiSizeLazy(pt);
1753917538 return Air.internedToRef(val.toIntern());
1754017539}
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,7 @@ 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 ty.fieldAlignmentSema(field_index, pt),
1847118470 .@"packed" => .none,
1847218471 };
1847318472
......@@ -18502,7 +18501,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1850218501 .is_const = true,
1850318502 },
1850418503 })).toIntern();
18505 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();
18504 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
1850618505 break :v try pt.intern(.{ .slice = .{
1850718506 .ty = slice_ty,
1850818507 .ptr = try pt.intern(.{ .ptr = .{
......@@ -18517,18 +18516,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1851718516 } });
1851818517 };
1851918518
18520 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(mod).toOptional());
18519 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespaceIndex(zcu).toOptional());
1852118520
1852218521 const enum_tag_ty_val = try pt.intern(.{ .opt = .{
1852318522 .ty = (try pt.optionalType(.type_type)).toIntern(),
18524 .val = if (ty.unionTagType(mod)) |tag_ty| tag_ty.toIntern() else .none,
18523 .val = if (ty.unionTagType(zcu)) |tag_ty| tag_ty.toIntern() else .none,
1852518524 } });
1852618525
1852718526 const container_layout_ty = t: {
1852818527 const nav = try sema.namespaceLookup(
1852918528 block,
1853018529 src,
18531 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
18530 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
1853218531 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
1853318532 ) orelse @panic("std.builtin.Type is corrupt");
1853418533 try sema.ensureNavResolved(src, nav);
......@@ -18560,7 +18559,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1856018559 const nav = try sema.namespaceLookup(
1856118560 block,
1856218561 src,
18563 type_info_ty.getNamespaceIndex(mod),
18562 type_info_ty.getNamespaceIndex(zcu),
1856418563 try ip.getOrPutString(gpa, pt.tid, "Struct", .no_embedded_nulls),
1856518564 ) orelse @panic("std.builtin.Type is corrupt");
1856618565 try sema.ensureNavResolved(src, nav);
......@@ -18571,7 +18570,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1857118570 const nav = try sema.namespaceLookup(
1857218571 block,
1857318572 src,
18574 type_info_ty.getNamespaceIndex(mod),
18573 type_info_ty.getNamespaceIndex(zcu),
1857518574 try ip.getOrPutString(gpa, pt.tid, "StructField", .no_embedded_nulls),
1857618575 ) orelse @panic("std.builtin.Type is corrupt");
1857718576 try sema.ensureNavResolved(src, nav);
......@@ -18633,7 +18632,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1863318632 // is_comptime: bool,
1863418633 Value.makeBool(is_comptime).toIntern(),
1863518634 // alignment: comptime_int,
18636 (try pt.intValue(Type.comptime_int, Type.fromInterned(field_ty).abiAlignment(pt).toByteUnits() orelse 0)).toIntern(),
18635 (try pt.intValue(Type.comptime_int, Type.fromInterned(field_ty).abiAlignment(zcu).toByteUnits() orelse 0)).toIntern(),
1863718636 };
1863818637 struct_field_val.* = try pt.intern(.{ .aggregate = .{
1863918638 .ty = struct_field_ty.toIntern(),
......@@ -18686,11 +18685,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1868618685 const default_val_ptr = try sema.optRefValue(opt_default_val);
1868718686 const alignment = switch (struct_type.layout) {
1868818687 .@"packed" => .none,
18689 else => try pt.structFieldAlignmentAdvanced(
18688 else => try field_ty.structFieldAlignmentSema(
1869018689 struct_type.fieldAlign(ip, field_index),
18691 field_ty,
1869218690 struct_type.layout,
18693 .sema,
18691 pt,
1869418692 ),
1869518693 };
1869618694
......@@ -18729,7 +18727,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1872918727 .is_const = true,
1873018728 },
1873118729 })).toIntern();
18732 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();
18730 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
1873318731 break :v try pt.intern(.{ .slice = .{
1873418732 .ty = slice_ty,
1873518733 .ptr = try pt.intern(.{ .ptr = .{
......@@ -18744,12 +18742,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1874418742 } });
1874518743 };
1874618744
18747 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod));
18745 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu));
1874818746
1874918747 const backing_integer_val = try pt.intern(.{ .opt = .{
1875018748 .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));
18749 .val = if (zcu.typeToPackedStruct(ty)) |packed_struct| val: {
18750 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(zcu));
1875318751 break :val packed_struct.backingIntTypeUnordered(ip);
1875418752 } else .none,
1875518753 } });
......@@ -18758,14 +18756,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1875818756 const nav = try sema.namespaceLookup(
1875918757 block,
1876018758 src,
18761 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),
18759 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
1876218760 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
1876318761 ) orelse @panic("std.builtin.Type is corrupt");
1876418762 try sema.ensureNavResolved(src, nav);
1876518763 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);
1876618764 };
1876718765
18768 const layout = ty.containerLayout(mod);
18766 const layout = ty.containerLayout(zcu);
1876918767
1877018768 const field_values = [_]InternPool.Index{
1877118769 // layout: ContainerLayout,
......@@ -18777,7 +18775,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1877718775 // decls: []const Declaration,
1877818776 decls_val,
1877918777 // is_tuple: bool,
18780 Value.makeBool(ty.isTuple(mod)).toIntern(),
18778 Value.makeBool(ty.isTuple(zcu)).toIntern(),
1878118779 };
1878218780 return Air.internedToRef((try pt.intern(.{ .un = .{
1878318781 .ty = type_info_ty.toIntern(),
......@@ -18793,7 +18791,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1879318791 const nav = try sema.namespaceLookup(
1879418792 block,
1879518793 src,
18796 type_info_ty.getNamespaceIndex(mod),
18794 type_info_ty.getNamespaceIndex(zcu),
1879718795 try ip.getOrPutString(gpa, pt.tid, "Opaque", .no_embedded_nulls),
1879818796 ) orelse @panic("std.builtin.Type is corrupt");
1879918797 try sema.ensureNavResolved(src, nav);
......@@ -18801,7 +18799,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1880118799 };
1880218800
1880318801 try ty.resolveFields(pt);
18804 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(mod));
18802 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace(zcu));
1880518803
1880618804 const field_values = .{
1880718805 // decls: []const Declaration,
......@@ -19000,11 +18998,11 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
1900018998
1900118999fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Type {
1900219000 const pt = sema.pt;
19003 const mod = pt.zcu;
19004 switch (operand.zigTypeTag(mod)) {
19001 const zcu = pt.zcu;
19002 switch (operand.zigTypeTag(zcu)) {
1900519003 .ComptimeInt => return Type.comptime_int,
1900619004 .Int => {
19007 const bits = operand.bitSize(pt);
19005 const bits = operand.bitSize(zcu);
1900819006 const count = if (bits == 0)
1900919007 0
1901019008 else blk: {
......@@ -19018,10 +19016,10 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1901819016 return pt.intType(.unsigned, count);
1901919017 },
1902019018 .Vector => {
19021 const elem_ty = operand.elemType2(mod);
19019 const elem_ty = operand.elemType2(zcu);
1902219020 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);
1902319021 return pt.vectorType(.{
19024 .len = operand.vectorLen(mod),
19022 .len = operand.vectorLen(zcu),
1902519023 .child = log2_elem_ty.toIntern(),
1902619024 });
1902719025 },
......@@ -19084,7 +19082,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1908419082 defer tracy.end();
1908519083
1908619084 const pt = sema.pt;
19087 const mod = pt.zcu;
19085 const zcu = pt.zcu;
1908819086 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1908919087 const src = block.nodeOffset(inst_data.src_node);
1909019088 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
......@@ -19092,7 +19090,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1909219090
1909319091 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
1909419092 if (try sema.resolveValue(operand)) |val| {
19095 return if (val.isUndef(mod))
19093 return if (val.isUndef(zcu))
1909619094 pt.undefRef(Type.bool)
1909719095 else if (val.toBool()) .bool_false else .bool_true;
1909819096 }
......@@ -19110,7 +19108,7 @@ fn zirBoolBr(
1911019108 defer tracy.end();
1911119109
1911219110 const pt = sema.pt;
19113 const mod = pt.zcu;
19111 const zcu = pt.zcu;
1911419112 const gpa = sema.gpa;
1911519113
1911619114 const datas = sema.code.instructions.items(.data);
......@@ -19134,7 +19132,7 @@ fn zirBoolBr(
1913419132 // is simply the rhs expression. Here we rely on there only being 1
1913519133 // break instruction (`break_inline`).
1913619134 const rhs_result = try sema.resolveInlineBody(parent_block, body, inst);
19137 if (sema.typeOf(rhs_result).isNoReturn(mod)) {
19135 if (sema.typeOf(rhs_result).isNoReturn(zcu)) {
1913819136 return rhs_result;
1913919137 }
1914019138 return sema.coerce(parent_block, Type.bool, rhs_result, rhs_src);
......@@ -19168,7 +19166,7 @@ fn zirBoolBr(
1916819166 _ = try lhs_block.addBr(block_inst, lhs_result);
1916919167
1917019168 const rhs_result = try sema.resolveInlineBody(rhs_block, body, inst);
19171 const rhs_noret = sema.typeOf(rhs_result).isNoReturn(mod);
19169 const rhs_noret = sema.typeOf(rhs_result).isNoReturn(zcu);
1917219170 const coerced_rhs_result = if (!rhs_noret) rhs: {
1917319171 const coerced_result = try sema.coerce(rhs_block, Type.bool, rhs_result, rhs_src);
1917419172 _ = try rhs_block.addBr(block_inst, coerced_result);
......@@ -19227,10 +19225,10 @@ fn finishCondBr(
1922719225
1922819226fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1922919227 const pt = sema.pt;
19230 const mod = pt.zcu;
19231 switch (ty.zigTypeTag(mod)) {
19228 const zcu = pt.zcu;
19229 switch (ty.zigTypeTag(zcu)) {
1923219230 .Optional, .Null, .Undefined => return,
19233 .Pointer => if (ty.isPtrLikeOptional(mod)) return,
19231 .Pointer => if (ty.isPtrLikeOptional(zcu)) return,
1923419232 else => {},
1923519233 }
1923619234 return sema.failWithExpectedOptionalType(block, src, ty);
......@@ -19260,11 +19258,11 @@ fn zirIsNonNullPtr(
1926019258 defer tracy.end();
1926119259
1926219260 const pt = sema.pt;
19263 const mod = pt.zcu;
19261 const zcu = pt.zcu;
1926419262 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1926519263 const src = block.nodeOffset(inst_data.src_node);
1926619264 const ptr = try sema.resolveInst(inst_data.operand);
19267 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));
19265 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(zcu));
1926819266 if ((try sema.resolveValue(ptr)) == null) {
1926919267 return block.addUnOp(.is_non_null_ptr, ptr);
1927019268 }
......@@ -19274,8 +19272,8 @@ fn zirIsNonNullPtr(
1927419272
1927519273fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1927619274 const pt = sema.pt;
19277 const mod = pt.zcu;
19278 switch (ty.zigTypeTag(mod)) {
19275 const zcu = pt.zcu;
19276 switch (ty.zigTypeTag(zcu)) {
1927919277 .ErrorSet, .ErrorUnion, .Undefined => return,
1928019278 else => return sema.fail(block, src, "expected error union type, found '{}'", .{
1928119279 ty.fmt(pt),
......@@ -19299,11 +19297,11 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1929919297 defer tracy.end();
1930019298
1930119299 const pt = sema.pt;
19302 const mod = pt.zcu;
19300 const zcu = pt.zcu;
1930319301 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1930419302 const src = block.nodeOffset(inst_data.src_node);
1930519303 const ptr = try sema.resolveInst(inst_data.operand);
19306 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod));
19304 try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(zcu));
1930719305 const loaded = try sema.analyzeLoad(block, src, ptr, src);
1930819306 return sema.analyzeIsNonErr(block, src, loaded);
1930919307}
......@@ -19327,7 +19325,7 @@ fn zirCondbr(
1932719325 defer tracy.end();
1932819326
1932919327 const pt = sema.pt;
19330 const mod = pt.zcu;
19328 const zcu = pt.zcu;
1933119329 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1933219330 const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node });
1933319331 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
......@@ -19368,8 +19366,8 @@ fn zirCondbr(
1936819366 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;
1936919367 const err_operand = try sema.resolveInst(err_inst_data.operand);
1937019368 const operand_ty = sema.typeOf(err_operand);
19371 assert(operand_ty.zigTypeTag(mod) == .ErrorUnion);
19372 const result_ty = operand_ty.errorUnionSet(mod);
19369 assert(operand_ty.zigTypeTag(zcu) == .ErrorUnion);
19370 const result_ty = operand_ty.errorUnionSet(zcu);
1937319371 break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand);
1937419372 };
1937519373
......@@ -19403,8 +19401,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1940319401 const err_union = try sema.resolveInst(extra.data.operand);
1940419402 const err_union_ty = sema.typeOf(err_union);
1940519403 const pt = sema.pt;
19406 const mod = pt.zcu;
19407 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
19404 const zcu = pt.zcu;
19405 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
1940819406 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
1940919407 err_union_ty.fmt(pt),
1941019408 });
......@@ -19452,8 +19450,8 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1945219450 const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src);
1945319451 const err_union_ty = sema.typeOf(err_union);
1945419452 const pt = sema.pt;
19455 const mod = pt.zcu;
19456 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
19453 const zcu = pt.zcu;
19454 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
1945719455 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
1945819456 err_union_ty.fmt(pt),
1945919457 });
......@@ -19477,9 +19475,9 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1947719475 try sema.analyzeBodyInner(&sub_block, body);
1947819476
1947919477 const operand_ty = sema.typeOf(operand);
19480 const ptr_info = operand_ty.ptrInfo(mod);
19478 const ptr_info = operand_ty.ptrInfo(zcu);
1948119479 const res_ty = try pt.ptrTypeSema(.{
19482 .child = err_union_ty.errorUnionPayload(mod).toIntern(),
19480 .child = err_union_ty.errorUnionPayload(zcu).toIntern(),
1948319481 .flags = .{
1948419482 .is_const = ptr_info.flags.is_const,
1948519483 .is_volatile = ptr_info.flags.is_volatile,
......@@ -19594,10 +19592,10 @@ fn zirRetErrValue(
1959419592 inst: Zir.Inst.Index,
1959519593) CompileError!void {
1959619594 const pt = sema.pt;
19597 const mod = pt.zcu;
19595 const zcu = pt.zcu;
1959819596 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
1959919597 const src = block.tokenOffset(inst_data.src_tok);
19600 const err_name = try mod.intern_pool.getOrPutString(
19598 const err_name = try zcu.intern_pool.getOrPutString(
1960119599 sema.gpa,
1960219600 pt.tid,
1960319601 inst_data.get(sema.code),
......@@ -19622,7 +19620,7 @@ fn zirRetImplicit(
1962219620 defer tracy.end();
1962319621
1962419622 const pt = sema.pt;
19625 const mod = pt.zcu;
19623 const zcu = pt.zcu;
1962619624 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
1962719625 const r_brace_src = block.tokenOffset(inst_data.src_tok);
1962819626 if (block.inlining == null and sema.func_is_naked) {
......@@ -19638,7 +19636,7 @@ fn zirRetImplicit(
1963819636
1963919637 const operand = try sema.resolveInst(inst_data.operand);
1964019638 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 });
19641 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);
19639 const base_tag = sema.fn_ret_ty.baseZigTypeTag(zcu);
1964219640 if (base_tag == .NoReturn) {
1964319641 const msg = msg: {
1964419642 const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{
......@@ -19755,13 +19753,13 @@ fn retWithErrTracing(
1975519753
1975619754fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool {
1975719755 const pt = sema.pt;
19758 const mod = pt.zcu;
19759 return fn_ret_ty.isError(mod) and mod.comp.config.any_error_tracing;
19756 const zcu = pt.zcu;
19757 return fn_ret_ty.isError(zcu) and zcu.comp.config.any_error_tracing;
1976019758}
1976119759
1976219760fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
1976319761 const pt = sema.pt;
19764 const mod = pt.zcu;
19762 const zcu = pt.zcu;
1976519763 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
1976619764
1976719765 if (!block.ownerModule().error_tracing) return;
......@@ -19772,7 +19770,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
1977219770 const save_index = inst_data.operand == .none or b: {
1977319771 const operand = try sema.resolveInst(inst_data.operand);
1977419772 const operand_ty = sema.typeOf(operand);
19775 break :b operand_ty.isError(mod);
19773 break :b operand_ty.isError(zcu);
1977619774 };
1977719775
1977819776 if (save_index)
......@@ -19792,7 +19790,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1979219790 defer tracy.end();
1979319791
1979419792 const pt = sema.pt;
19795 const mod = pt.zcu;
19793 const zcu = pt.zcu;
1979619794
1979719795 const saved_index = if (target_block.toIndexAllowNone()) |zir_block| b: {
1979819796 var block = start_block;
......@@ -19830,13 +19828,13 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1983019828 if (is_non_error) return;
1983119829
1983219830 const saved_index_val = try sema.resolveDefinedValue(start_block, src, saved_index);
19833 const saved_index_int = saved_index_val.?.toUnsignedInt(pt);
19831 const saved_index_int = saved_index_val.?.toUnsignedInt(zcu);
1983419832 assert(saved_index_int <= sema.comptime_err_ret_trace.items.len);
1983519833 sema.comptime_err_ret_trace.items.len = @intCast(saved_index_int);
1983619834 return;
1983719835 }
1983819836
19839 if (!mod.intern_pool.funcAnalysisUnordered(sema.owner.unwrap().func).calls_or_awaits_errorable_fn) return;
19837 if (!zcu.intern_pool.funcAnalysisUnordered(sema.owner.unwrap().func).calls_or_awaits_errorable_fn) return;
1984019838 if (!start_block.ownerModule().error_tracing) return;
1984119839
1984219840 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere
......@@ -19846,10 +19844,10 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1984619844
1984719845fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
1984819846 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();
19847 const zcu = pt.zcu;
19848 const ip = &zcu.intern_pool;
19849 assert(sema.fn_ret_ty.zigTypeTag(zcu) == .ErrorUnion);
19850 const err_set_ty = sema.fn_ret_ty.errorUnionSet(zcu).toIntern();
1985319851 switch (err_set_ty) {
1985419852 .adhoc_inferred_error_set_type => {
1985519853 const ies = sema.fn_ret_ty_ies.?;
......@@ -19867,11 +19865,11 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
1986719865fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void {
1986819866 const arena = sema.arena;
1986919867 const pt = sema.pt;
19870 const mod = pt.zcu;
19871 const ip = &mod.intern_pool;
19872 switch (op_ty.zigTypeTag(mod)) {
19868 const zcu = pt.zcu;
19869 const ip = &zcu.intern_pool;
19870 switch (op_ty.zigTypeTag(zcu)) {
1987319871 .ErrorSet => try ies.addErrorSet(op_ty, ip, arena),
19874 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(mod), ip, arena),
19872 .ErrorUnion => try ies.addErrorSet(op_ty.errorUnionSet(zcu), ip, arena),
1987519873 else => {},
1987619874 }
1987719875}
......@@ -19887,8 +19885,8 @@ fn analyzeRet(
1988719885 // add the error tag to the inferred error set of the in-scope function, so
1988819886 // that the coercion below works correctly.
1988919887 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) {
19888 const zcu = pt.zcu;
19889 if (sema.fn_ret_ty_ies != null and sema.fn_ret_ty.zigTypeTag(zcu) == .ErrorUnion) {
1989219890 try sema.addToInferredErrorSet(uncasted_operand);
1989319891 }
1989419892 const operand = sema.coerceExtra(block, sema.fn_ret_ty, uncasted_operand, operand_src, .{ .is_ret = true }) catch |err| switch (err) {
......@@ -19903,7 +19901,7 @@ fn analyzeRet(
1990319901 });
1990419902 inlining.comptime_result = operand;
1990519903
19906 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
19904 if (sema.fn_ret_ty.isError(zcu) and ret_val.getErrorName(zcu) != .none) {
1990719905 try sema.comptime_err_ret_trace.append(src);
1990819906 }
1990919907 return error.ComptimeReturn;
......@@ -19955,7 +19953,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1995519953 defer tracy.end();
1995619954
1995719955 const pt = sema.pt;
19958 const mod = pt.zcu;
19956 const zcu = pt.zcu;
1995919957 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
1996019958 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
1996119959 const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node });
......@@ -19968,7 +19966,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1996819966 const elem_ty = blk: {
1996919967 const air_inst = try sema.resolveInst(extra.data.elem_type);
1997019968 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)) {
19969 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(zcu)) {
1997219970 try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
1997319971 }
1997419972 return err;
......@@ -19977,10 +19975,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1997719975 break :blk ty;
1997819976 };
1997919977
19980 if (elem_ty.zigTypeTag(mod) == .NoReturn)
19978 if (elem_ty.zigTypeTag(zcu) == .NoReturn)
1998119979 return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});
1998219980
19983 const target = mod.getTarget();
19981 const target = zcu.getTarget();
1998419982
1998519983 var extra_i = extra.end;
1998619984
......@@ -20003,14 +20001,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2000320001 });
2000420002 // Check if this happens to be the lazy alignment of our element type, in
2000520003 // which case we can make this 0 without resolving it.
20006 switch (mod.intern_pool.indexToKey(val.toIntern())) {
20004 switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2000720005 .int => |int| switch (int.storage) {
2000820006 .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.toIntern()) break :blk .none,
2000920007 else => {},
2001020008 },
2001120009 else => {},
2001220010 }
20013 const align_bytes = (try val.getUnsignedIntAdvanced(pt, .sema)).?;
20011 const align_bytes = (try val.getUnsignedIntSema(pt)).?;
2001420012 break :blk try sema.validateAlignAllowZero(block, align_src, align_bytes);
2001520013 } else .none;
2001620014
......@@ -20018,7 +20016,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2001820016 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
2001920017 extra_i += 1;
2002020018 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;
20019 } else if (elem_ty.zigTypeTag(zcu) == .Fn and target.cpu.arch == .avr) .flash else .generic;
2002220020
2002320021 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {
2002420022 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
......@@ -20044,7 +20042,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2004420042 elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size,
2004520043 });
2004620044 }
20047 const elem_bit_size = try elem_ty.bitSizeAdvanced(pt, .sema);
20045 const elem_bit_size = try elem_ty.bitSizeSema(pt);
2004820046 if (elem_bit_size > host_size * 8 - bit_offset) {
2004920047 return sema.fail(block, bitoffset_src, "packed type '{}' at bit offset {} ends {} bits after the end of a {} byte host integer", .{
2005020048 elem_ty.fmt(pt), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,
......@@ -20052,11 +20050,11 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2005220050 }
2005320051 }
2005420052
20055 if (elem_ty.zigTypeTag(mod) == .Fn) {
20053 if (elem_ty.zigTypeTag(zcu) == .Fn) {
2005620054 if (inst_data.size != .One) {
2005720055 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
2005820056 }
20059 } else if (inst_data.size == .Many and elem_ty.zigTypeTag(mod) == .Opaque) {
20057 } else if (inst_data.size == .Many and elem_ty.zigTypeTag(zcu) == .Opaque) {
2006020058 return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{});
2006120059 } else if (inst_data.size == .C) {
2006220060 if (!try sema.validateExternType(elem_ty, .other)) {
......@@ -20071,7 +20069,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2007120069 };
2007220070 return sema.failWithOwnedErrorMsg(block, msg);
2007320071 }
20074 if (elem_ty.zigTypeTag(mod) == .Opaque) {
20072 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
2007520073 return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{});
2007620074 }
2007720075 }
......@@ -20113,9 +20111,9 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2011320111 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
2011420112 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
2011520113 const pt = sema.pt;
20116 const mod = pt.zcu;
20114 const zcu = pt.zcu;
2011720115
20118 switch (obj_ty.zigTypeTag(mod)) {
20116 switch (obj_ty.zigTypeTag(zcu)) {
2011920117 .Struct => return sema.structInitEmpty(block, obj_ty, src, src),
2012020118 .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty),
2012120119 .Void => return Air.internedToRef(Value.void.toIntern()),
......@@ -20129,7 +20127,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
2012920127 defer tracy.end();
2013020128
2013120129 const pt = sema.pt;
20132 const mod = pt.zcu;
20130 const zcu = pt.zcu;
2013320131 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2013420132 const src = block.nodeOffset(inst_data.src_node);
2013520133 const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
......@@ -20138,21 +20136,21 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
2013820136 else => |e| return e,
2013920137 };
2014020138 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);
20139 const ptr_ty = ty_operand.optEuBaseType(zcu);
20140 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
20141 if (!ptr_ty.isSlice(zcu)) {
20142 break :ty ptr_ty.childType(zcu);
2014520143 }
2014620144 // To make `&.{}` a `[:s]T`, the init should be a `[0:s]T`.
2014720145 break :ty try pt.arrayType(.{
2014820146 .len = 0,
20149 .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
20150 .child = ptr_ty.childType(mod).toIntern(),
20147 .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
20148 .child = ptr_ty.childType(zcu).toIntern(),
2015120149 });
2015220150 } else ty_operand;
20153 const obj_ty = init_ty.optEuBaseType(mod);
20151 const obj_ty = init_ty.optEuBaseType(zcu);
2015420152
20155 const empty_ref = switch (obj_ty.zigTypeTag(mod)) {
20153 const empty_ref = switch (obj_ty.zigTypeTag(zcu)) {
2015620154 .Struct => try sema.structInitEmpty(block, obj_ty, src, src),
2015720155 .Array, .Vector => try sema.arrayInitEmpty(block, src, obj_ty),
2015820156 .Union => return sema.fail(block, src, "union initializer must initialize one field", .{}),
......@@ -20176,13 +20174,13 @@ fn structInitEmpty(
2017620174 init_src: LazySrcLoc,
2017720175) CompileError!Air.Inst.Ref {
2017820176 const pt = sema.pt;
20179 const mod = pt.zcu;
20177 const zcu = pt.zcu;
2018020178 const gpa = sema.gpa;
2018120179 // This logic must be synchronized with that in `zirStructInit`.
2018220180 try struct_ty.resolveFields(pt);
2018320181
2018420182 // The init values to use for the struct instance.
20185 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount(mod));
20183 const field_inits = try gpa.alloc(Air.Inst.Ref, struct_ty.structFieldCount(zcu));
2018620184 defer gpa.free(field_inits);
2018720185 @memset(field_inits, .none);
2018820186
......@@ -20191,10 +20189,10 @@ fn structInitEmpty(
2019120189
2019220190fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) CompileError!Air.Inst.Ref {
2019320191 const pt = sema.pt;
20194 const mod = pt.zcu;
20195 const arr_len = obj_ty.arrayLen(mod);
20192 const zcu = pt.zcu;
20193 const arr_len = obj_ty.arrayLen(zcu);
2019620194 if (arr_len != 0) {
20197 if (obj_ty.zigTypeTag(mod) == .Array) {
20195 if (obj_ty.zigTypeTag(zcu) == .Array) {
2019820196 return sema.fail(block, src, "expected {d} array elements; found 0", .{arr_len});
2019920197 } else {
2020020198 return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len});
......@@ -20235,14 +20233,14 @@ fn unionInit(
2023520233 field_src: LazySrcLoc,
2023620234) CompileError!Air.Inst.Ref {
2023720235 const pt = sema.pt;
20238 const mod = pt.zcu;
20239 const ip = &mod.intern_pool;
20236 const zcu = pt.zcu;
20237 const ip = &zcu.intern_pool;
2024020238 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]);
20239 const field_ty = Type.fromInterned(zcu.typeToUnion(union_ty).?.field_types.get(ip)[field_index]);
2024220240 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
2024320241
2024420242 if (try sema.resolveValue(init)) |init_val| {
20245 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
20243 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
2024620244 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
2024720245 return Air.internedToRef((try pt.intern(.{ .un = .{
2024820246 .ty = union_ty.toIntern(),
......@@ -20269,8 +20267,8 @@ fn zirStructInit(
2026920267 const src = block.nodeOffset(inst_data.src_node);
2027020268
2027120269 const pt = sema.pt;
20272 const mod = pt.zcu;
20273 const ip = &mod.intern_pool;
20270 const zcu = pt.zcu;
20271 const ip = &zcu.intern_pool;
2027420272 const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data;
2027520273 const first_field_type_data = zir_datas[@intFromEnum(first_item.field_type)].pl_node;
2027620274 const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;
......@@ -20281,26 +20279,26 @@ fn zirStructInit(
2028120279 },
2028220280 else => |e| return e,
2028320281 };
20284 const resolved_ty = result_ty.optEuBaseType(mod);
20282 const resolved_ty = result_ty.optEuBaseType(zcu);
2028520283 try resolved_ty.resolveLayout(pt);
2028620284
20287 if (resolved_ty.zigTypeTag(mod) == .Struct) {
20285 if (resolved_ty.zigTypeTag(zcu) == .Struct) {
2028820286 // This logic must be synchronized with that in `zirStructInitEmpty`.
2028920287
2029020288 // Maps field index to field_type index of where it was already initialized.
2029120289 // 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));
20290 const found_fields = try gpa.alloc(Zir.Inst.Index, resolved_ty.structFieldCount(zcu));
2029320291 defer gpa.free(found_fields);
2029420292
2029520293 // The init values to use for the struct instance.
20296 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount(mod));
20294 const field_inits = try gpa.alloc(Air.Inst.Ref, resolved_ty.structFieldCount(zcu));
2029720295 defer gpa.free(field_inits);
2029820296 @memset(field_inits, .none);
2029920297
2030020298 var field_i: u32 = 0;
2030120299 var extra_index = extra.end;
2030220300
20303 const is_packed = resolved_ty.containerLayout(mod) == .@"packed";
20301 const is_packed = resolved_ty.containerLayout(zcu) == .@"packed";
2030420302 while (field_i < extra.data.fields_len) : (field_i += 1) {
2030520303 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index);
2030620304 extra_index = item.end;
......@@ -20314,14 +20312,14 @@ fn zirStructInit(
2031420312 sema.code.nullTerminatedString(field_type_extra.name_start),
2031520313 .no_embedded_nulls,
2031620314 );
20317 const field_index = if (resolved_ty.isTuple(mod))
20315 const field_index = if (resolved_ty.isTuple(zcu))
2031820316 try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src)
2031920317 else
2032020318 try sema.structFieldIndex(block, resolved_ty, field_name, field_src);
2032120319 assert(field_inits[field_index] == .none);
2032220320 found_fields[field_index] = item.data.field_type;
2032320321 const uncoerced_init = try sema.resolveInst(item.data.init);
20324 const field_ty = resolved_ty.structFieldType(field_index, mod);
20322 const field_ty = resolved_ty.fieldType(field_index, zcu);
2032520323 field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src);
2032620324 if (!is_packed) {
2032720325 try resolved_ty.resolveStructFieldInits(pt);
......@@ -20332,7 +20330,7 @@ fn zirStructInit(
2033220330 });
2033320331 };
2033420332
20335 if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) {
20333 if (!init_val.eql(default_value, resolved_ty.fieldType(field_index, zcu), zcu)) {
2033620334 return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index);
2033720335 }
2033820336 }
......@@ -20340,7 +20338,7 @@ fn zirStructInit(
2034020338 }
2034120339
2034220340 return sema.finishStructInit(block, src, src, field_inits, resolved_ty, result_ty, is_ref);
20343 } else if (resolved_ty.zigTypeTag(mod) == .Union) {
20341 } else if (resolved_ty.zigTypeTag(zcu) == .Union) {
2034420342 if (extra.data.fields_len != 1) {
2034520343 return sema.fail(block, src, "union initialization expects exactly one field", .{});
2034620344 }
......@@ -20357,11 +20355,11 @@ fn zirStructInit(
2035720355 .no_embedded_nulls,
2035820356 );
2035920357 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
20360 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
20358 const tag_ty = resolved_ty.unionTagTypeHypothetical(zcu);
2036120359 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]);
20360 const field_ty = Type.fromInterned(zcu.typeToUnion(resolved_ty).?.field_types.get(ip)[field_index]);
2036320361
20364 if (field_ty.zigTypeTag(mod) == .NoReturn) {
20362 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
2036520363 return sema.failWithOwnedErrorMsg(block, msg: {
2036620364 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2036720365 errdefer msg.destroy(sema.gpa);
......@@ -20388,7 +20386,7 @@ fn zirStructInit(
2038820386 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
2038920387 }
2039020388
20391 if (try sema.typeRequiresComptime(resolved_ty)) {
20389 if (try resolved_ty.comptimeOnlySema(pt)) {
2039220390 return sema.failWithNeededComptime(block, field_src, .{
2039320391 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
2039420392 });
......@@ -20397,7 +20395,7 @@ fn zirStructInit(
2039720395 try sema.validateRuntimeValue(block, field_src, init_inst);
2039820396
2039920397 if (is_ref) {
20400 const target = mod.getTarget();
20398 const target = zcu.getTarget();
2040120399 const alloc_ty = try pt.ptrTypeSema(.{
2040220400 .child = result_ty.toIntern(),
2040320401 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20429,10 +20427,10 @@ fn finishStructInit(
2042920427 is_ref: bool,
2043020428) CompileError!Air.Inst.Ref {
2043120429 const pt = sema.pt;
20432 const mod = pt.zcu;
20433 const ip = &mod.intern_pool;
20430 const zcu = pt.zcu;
20431 const ip = &zcu.intern_pool;
2043420432
20435 var root_msg: ?*Module.ErrorMsg = null;
20433 var root_msg: ?*Zcu.ErrorMsg = null;
2043620434 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
2043720435
2043820436 switch (ip.indexToKey(struct_ty.toIntern())) {
......@@ -20545,7 +20543,7 @@ fn finishStructInit(
2054520543 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
2054620544 };
2054720545
20548 if (try sema.typeRequiresComptime(struct_ty)) {
20546 if (try struct_ty.comptimeOnlySema(pt)) {
2054920547 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{
2055020548 .init_node_offset = init_src.offset.node_offset.x,
2055120549 .elem_index = @intCast(runtime_index),
......@@ -20560,7 +20558,7 @@ fn finishStructInit(
2056020558
2056120559 if (is_ref) {
2056220560 try struct_ty.resolveLayout(pt);
20563 const target = mod.getTarget();
20561 const target = zcu.getTarget();
2056420562 const alloc_ty = try pt.ptrTypeSema(.{
2056520563 .child = result_ty.toIntern(),
2056620564 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20612,9 +20610,9 @@ fn structInitAnon(
2061220610 is_ref: bool,
2061320611) CompileError!Air.Inst.Ref {
2061420612 const pt = sema.pt;
20615 const mod = pt.zcu;
20613 const zcu = pt.zcu;
2061620614 const gpa = sema.gpa;
20617 const ip = &mod.intern_pool;
20615 const ip = &zcu.intern_pool;
2061820616 const zir_datas = sema.code.instructions.items(.data);
2061920617
2062020618 const types = try sema.arena.alloc(InternPool.Index, extra_data.fields_len);
......@@ -20642,11 +20640,11 @@ fn structInitAnon(
2064220640 },
2064320641 };
2064420642
20645 field_name.* = try mod.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
20643 field_name.* = try zcu.intern_pool.getOrPutString(gpa, pt.tid, name, .no_embedded_nulls);
2064620644
2064720645 const init = try sema.resolveInst(item.data.init);
2064820646 field_ty.* = sema.typeOf(init).toIntern();
20649 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
20647 if (Type.fromInterned(field_ty.*).zigTypeTag(zcu) == .Opaque) {
2065020648 const msg = msg: {
2065120649 const field_src = block.src(.{ .init_elem = .{
2065220650 .init_node_offset = src.offset.node_offset.x,
......@@ -20690,7 +20688,7 @@ fn structInitAnon(
2069020688 } }));
2069120689
2069220690 if (is_ref) {
20693 const target = mod.getTarget();
20691 const target = zcu.getTarget();
2069420692 const alloc_ty = try pt.ptrTypeSema(.{
2069520693 .child = tuple_ty,
2069620694 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20740,7 +20738,7 @@ fn zirArrayInit(
2074020738 is_ref: bool,
2074120739) CompileError!Air.Inst.Ref {
2074220740 const pt = sema.pt;
20743 const mod = pt.zcu;
20741 const zcu = pt.zcu;
2074420742 const gpa = sema.gpa;
2074520743 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2074620744 const src = block.nodeOffset(inst_data.src_node);
......@@ -20756,14 +20754,14 @@ fn zirArrayInit(
2075620754 },
2075720755 else => |e| return e,
2075820756 };
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);
20757 const array_ty = result_ty.optEuBaseType(zcu);
20758 const is_tuple = array_ty.zigTypeTag(zcu) == .Struct;
20759 const sentinel_val = array_ty.sentinel(zcu);
2076220760
20763 var root_msg: ?*Module.ErrorMsg = null;
20761 var root_msg: ?*Zcu.ErrorMsg = null;
2076420762 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
2076520763
20766 const final_len = try sema.usizeCast(block, src, array_ty.arrayLenIncludingSentinel(mod));
20764 const final_len = try sema.usizeCast(block, src, array_ty.arrayLenIncludingSentinel(zcu));
2076720765 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);
2076820766 defer gpa.free(resolved_args);
2076920767 for (resolved_args, 0..) |*dest, i| {
......@@ -20773,7 +20771,7 @@ fn zirArrayInit(
2077320771 } });
2077420772 // Less inits than needed.
2077520773 if (i + 2 > args.len) if (is_tuple) {
20776 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();
20774 const default_val = array_ty.structFieldDefaultValue(i, zcu).toIntern();
2077720775 if (default_val == .unreachable_value) {
2077820776 const template = "missing tuple field with index {d}";
2077920777 if (root_msg) |msg| {
......@@ -20793,12 +20791,12 @@ fn zirArrayInit(
2079320791 const arg = args[i + 1];
2079420792 const resolved_arg = try sema.resolveInst(arg);
2079520793 const elem_ty = if (is_tuple)
20796 array_ty.structFieldType(i, mod)
20794 array_ty.fieldType(i, zcu)
2079720795 else
20798 array_ty.elemType2(mod);
20796 array_ty.elemType2(zcu);
2079920797 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
2080020798 if (is_tuple) {
20801 if (array_ty.structFieldIsComptime(i, mod))
20799 if (array_ty.structFieldIsComptime(i, zcu))
2080220800 try array_ty.resolveStructFieldInits(pt);
2080320801 if (try array_ty.structFieldValueComptime(pt, i)) |field_val| {
2080420802 const init_val = try sema.resolveValue(dest.*) orelse {
......@@ -20806,7 +20804,7 @@ fn zirArrayInit(
2080620804 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
2080720805 });
2080820806 };
20809 if (!field_val.eql(init_val, elem_ty, mod)) {
20807 if (!field_val.eql(init_val, elem_ty, zcu)) {
2081020808 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);
2081120809 }
2081220810 }
......@@ -20845,7 +20843,7 @@ fn zirArrayInit(
2084520843 } }));
2084620844
2084720845 if (is_ref) {
20848 const target = mod.getTarget();
20846 const target = zcu.getTarget();
2084920847 const alloc_ty = try pt.ptrTypeSema(.{
2085020848 .child = result_ty.toIntern(),
2085120849 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -20856,7 +20854,7 @@ fn zirArrayInit(
2085620854 if (is_tuple) {
2085720855 for (resolved_args, 0..) |arg, i| {
2085820856 const elem_ptr_ty = try pt.ptrTypeSema(.{
20859 .child = array_ty.structFieldType(i, mod).toIntern(),
20857 .child = array_ty.fieldType(i, zcu).toIntern(),
2086020858 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
2086120859 });
2086220860 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
......@@ -20869,7 +20867,7 @@ fn zirArrayInit(
2086920867 }
2087020868
2087120869 const elem_ptr_ty = try pt.ptrTypeSema(.{
20872 .child = array_ty.elemType2(mod).toIntern(),
20870 .child = array_ty.elemType2(zcu).toIntern(),
2087320871 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
2087420872 });
2087520873 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
......@@ -20906,9 +20904,9 @@ fn arrayInitAnon(
2090620904 is_ref: bool,
2090720905) CompileError!Air.Inst.Ref {
2090820906 const pt = sema.pt;
20909 const mod = pt.zcu;
20907 const zcu = pt.zcu;
2091020908 const gpa = sema.gpa;
20911 const ip = &mod.intern_pool;
20909 const ip = &zcu.intern_pool;
2091220910
2091320911 const types = try sema.arena.alloc(InternPool.Index, operands.len);
2091420912 const values = try sema.arena.alloc(InternPool.Index, operands.len);
......@@ -20919,7 +20917,7 @@ fn arrayInitAnon(
2091920917 const operand_src = src; // TODO better source location
2092020918 const elem = try sema.resolveInst(operand);
2092120919 types[i] = sema.typeOf(elem).toIntern();
20922 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
20920 if (Type.fromInterned(types[i]).zigTypeTag(zcu) == .Opaque) {
2092320921 const msg = msg: {
2092420922 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2092520923 errdefer msg.destroy(gpa);
......@@ -21003,8 +21001,8 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2100321001
2100421002fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2100521003 const pt = sema.pt;
21006 const mod = pt.zcu;
21007 const ip = &mod.intern_pool;
21004 const zcu = pt.zcu;
21005 const ip = &zcu.intern_pool;
2100821006 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2100921007 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
2101021008 const ty_src = block.nodeOffset(inst_data.src_node);
......@@ -21017,7 +21015,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
2101721015 error.GenericPoison => return .generic_poison_type,
2101821016 else => |e| return e,
2101921017 };
21020 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod);
21018 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(zcu);
2102121019 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);
2102221020 const field_name = try ip.getOrPutString(sema.gpa, pt.tid, zir_field_name, .no_embedded_nulls);
2102321021 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);
......@@ -21032,12 +21030,12 @@ fn fieldType(
2103221030 ty_src: LazySrcLoc,
2103321031) CompileError!Air.Inst.Ref {
2103421032 const pt = sema.pt;
21035 const mod = pt.zcu;
21036 const ip = &mod.intern_pool;
21033 const zcu = pt.zcu;
21034 const ip = &zcu.intern_pool;
2103721035 var cur_ty = aggregate_ty;
2103821036 while (true) {
2103921037 try cur_ty.resolveFields(pt);
21040 switch (cur_ty.zigTypeTag(mod)) {
21038 switch (cur_ty.zigTypeTag(zcu)) {
2104121039 .Struct => switch (ip.indexToKey(cur_ty.toIntern())) {
2104221040 .anon_struct_type => |anon_struct| {
2104321041 const field_index = if (anon_struct.names.len == 0)
......@@ -21056,7 +21054,7 @@ fn fieldType(
2105621054 else => unreachable,
2105721055 },
2105821056 .Union => {
21059 const union_obj = mod.typeToUnion(cur_ty).?;
21057 const union_obj = zcu.typeToUnion(cur_ty).?;
2106021058 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
2106121059 return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name);
2106221060 const field_ty = union_obj.field_types.get(ip)[field_index];
......@@ -21069,7 +21067,7 @@ fn fieldType(
2106921067 continue;
2107021068 },
2107121069 .ErrorUnion => {
21072 cur_ty = cur_ty.errorUnionPayload(mod);
21070 cur_ty = cur_ty.errorUnionPayload(zcu);
2107321071 continue;
2107421072 },
2107521073 else => {},
......@@ -21086,8 +21084,8 @@ fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
2108621084
2108721085fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
2108821086 const pt = sema.pt;
21089 const mod = pt.zcu;
21090 const ip = &mod.intern_pool;
21087 const zcu = pt.zcu;
21088 const ip = &zcu.intern_pool;
2109121089 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
2109221090 try stack_trace_ty.resolveFields(pt);
2109321091 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
......@@ -21115,42 +21113,42 @@ fn zirFrame(
2111521113}
2111621114
2111721115fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21118 const pt = sema.pt;
21116 const zcu = sema.pt.zcu;
2111921117 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2112021118 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2112121119 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)});
21120 if (ty.isNoReturn(zcu)) {
21121 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.pt)});
2112421122 }
21125 const val = try ty.lazyAbiAlignment(pt);
21123 const val = try ty.lazyAbiAlignment(sema.pt);
2112621124 return Air.internedToRef(val.toIntern());
2112721125}
2112821126
2112921127fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2113021128 const pt = sema.pt;
21131 const mod = pt.zcu;
21129 const zcu = pt.zcu;
2113221130 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2113321131 const src = block.nodeOffset(inst_data.src_node);
2113421132 const operand = try sema.resolveInst(inst_data.operand);
2113521133 const operand_ty = sema.typeOf(operand);
21136 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;
21137 const operand_scalar_ty = operand_ty.scalarType(mod);
21134 const is_vector = operand_ty.zigTypeTag(zcu) == .Vector;
21135 const operand_scalar_ty = operand_ty.scalarType(zcu);
2113821136 if (operand_scalar_ty.toIntern() != .bool_type) {
21139 return sema.fail(block, src, "expected 'bool', found '{}'", .{operand_scalar_ty.zigTypeTag(mod)});
21137 return sema.fail(block, src, "expected 'bool', found '{}'", .{operand_scalar_ty.zigTypeTag(zcu)});
2114021138 }
2114121139 if (try sema.resolveValue(operand)) |val| {
2114221140 if (!is_vector) {
21143 if (val.isUndef(mod)) return pt.undefRef(Type.u1);
21141 if (val.isUndef(zcu)) return pt.undefRef(Type.u1);
2114421142 if (val.toBool()) return Air.internedToRef((try pt.intValue(Type.u1, 1)).toIntern());
2114521143 return Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());
2114621144 }
21147 const len = operand_ty.vectorLen(mod);
21145 const len = operand_ty.vectorLen(zcu);
2114821146 const dest_ty = try pt.vectorType(.{ .child = .u1_type, .len = len });
21149 if (val.isUndef(mod)) return pt.undefRef(dest_ty);
21147 if (val.isUndef(zcu)) return pt.undefRef(dest_ty);
2115021148 const new_elems = try sema.arena.alloc(InternPool.Index, len);
2115121149 for (new_elems, 0..) |*new_elem, i| {
2115221150 const old_elem = try val.elemValue(pt, i);
21153 const new_val = if (old_elem.isUndef(mod))
21151 const new_val = if (old_elem.isUndef(zcu))
2115421152 try pt.undefValue(Type.u1)
2115521153 else if (old_elem.toBool())
2115621154 try pt.intValue(Type.u1, 1)
......@@ -21166,7 +21164,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2116621164 if (!is_vector) {
2116721165 return block.addUnOp(.int_from_bool, operand);
2116821166 }
21169 const len = operand_ty.vectorLen(mod);
21167 const len = operand_ty.vectorLen(zcu);
2117021168 const dest_ty = try pt.vectorType(.{ .child = .u1_type, .len = len });
2117121169 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2117221170 for (new_elems, 0..) |*new_elem, i| {
......@@ -21199,16 +21197,16 @@ fn zirAbs(
2119921197 inst: Zir.Inst.Index,
2120021198) CompileError!Air.Inst.Ref {
2120121199 const pt = sema.pt;
21202 const mod = pt.zcu;
21200 const zcu = pt.zcu;
2120321201 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2120421202 const operand = try sema.resolveInst(inst_data.operand);
2120521203 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2120621204 const operand_ty = sema.typeOf(operand);
21207 const scalar_ty = operand_ty.scalarType(mod);
21205 const scalar_ty = operand_ty.scalarType(zcu);
2120821206
21209 const result_ty = switch (scalar_ty.zigTypeTag(mod)) {
21207 const result_ty = switch (scalar_ty.zigTypeTag(zcu)) {
2121021208 .ComptimeFloat, .Float, .ComptimeInt => operand_ty,
21211 .Int => if (scalar_ty.isSignedInt(mod)) try operand_ty.toUnsigned(pt) else return operand,
21209 .Int => if (scalar_ty.isSignedInt(zcu)) try operand_ty.toUnsigned(pt) else return operand,
2121221210 else => return sema.fail(
2121321211 block,
2121421212 operand_src,
......@@ -21230,12 +21228,12 @@ fn maybeConstantUnaryMath(
2123021228 comptime eval: fn (Value, Type, Allocator, Zcu.PerThread) Allocator.Error!Value,
2123121229) CompileError!?Air.Inst.Ref {
2123221230 const pt = sema.pt;
21233 const mod = pt.zcu;
21234 switch (result_ty.zigTypeTag(mod)) {
21231 const zcu = pt.zcu;
21232 switch (result_ty.zigTypeTag(zcu)) {
2123521233 .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))
21234 const scalar_ty = result_ty.scalarType(zcu);
21235 const vec_len = result_ty.vectorLen(zcu);
21236 if (val.isUndef(zcu))
2123921237 return try pt.undefRef(result_ty);
2124021238
2124121239 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
......@@ -21249,7 +21247,7 @@ fn maybeConstantUnaryMath(
2124921247 } })));
2125021248 },
2125121249 else => if (try sema.resolveValue(operand)) |operand_val| {
21252 if (operand_val.isUndef(mod))
21250 if (operand_val.isUndef(zcu))
2125321251 return try pt.undefRef(result_ty);
2125421252 const result_val = try eval(operand_val, result_ty, sema.arena, pt);
2125521253 return Air.internedToRef(result_val.toIntern());
......@@ -21269,14 +21267,14 @@ fn zirUnaryMath(
2126921267 defer tracy.end();
2127021268
2127121269 const pt = sema.pt;
21272 const mod = pt.zcu;
21270 const zcu = pt.zcu;
2127321271 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2127421272 const operand = try sema.resolveInst(inst_data.operand);
2127521273 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2127621274 const operand_ty = sema.typeOf(operand);
21277 const scalar_ty = operand_ty.scalarType(mod);
21275 const scalar_ty = operand_ty.scalarType(zcu);
2127821276
21279 switch (scalar_ty.zigTypeTag(mod)) {
21277 switch (scalar_ty.zigTypeTag(zcu)) {
2128021278 .ComptimeFloat, .Float => {},
2128121279 else => return sema.fail(
2128221280 block,
......@@ -21359,9 +21357,9 @@ fn zirReify(
2135921357 inst: Zir.Inst.Index,
2136021358) CompileError!Air.Inst.Ref {
2136121359 const pt = sema.pt;
21362 const mod = pt.zcu;
21360 const zcu = pt.zcu;
2136321361 const gpa = sema.gpa;
21364 const ip = &mod.intern_pool;
21362 const ip = &zcu.intern_pool;
2136521363 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
2136621364 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
2136721365 const tracked_inst = try block.trackZir(inst);
......@@ -21388,7 +21386,7 @@ fn zirReify(
2138821386 if (try sema.anyUndef(block, operand_src, Value.fromInterned(union_val.val))) {
2138921387 return sema.failWithUseOfUndef(block, operand_src);
2139021388 }
21391 const tag_index = type_info_ty.unionTagFieldIndex(Value.fromInterned(union_val.tag), mod).?;
21389 const tag_index = type_info_ty.unionTagFieldIndex(Value.fromInterned(union_val.tag), zcu).?;
2139221390 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
2139321391 .Type => return .type_type,
2139421392 .Void => return .void_type,
......@@ -21411,7 +21409,7 @@ fn zirReify(
2141121409 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls)).?,
2141221410 );
2141321411
21414 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
21412 const signedness = zcu.toEnum(std.builtin.Signedness, signedness_val);
2141521413 const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt));
2141621414 const ty = try pt.intType(signedness, bits);
2141721415 return Air.internedToRef(ty.toIntern());
......@@ -21495,7 +21493,7 @@ fn zirReify(
2149521493 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
2149621494 }
2149721495
21498 const alignment_val_int = (try alignment_val.getUnsignedIntAdvanced(pt, .sema)).?;
21496 const alignment_val_int = try alignment_val.toUnsignedIntSema(pt);
2149921497 if (alignment_val_int > 0 and !math.isPowerOfTwo(alignment_val_int)) {
2150021498 return sema.fail(block, src, "alignment value '{d}' is not a power of two or zero", .{alignment_val_int});
2150121499 }
......@@ -21506,14 +21504,14 @@ fn zirReify(
2150621504 try elem_ty.resolveLayout(pt);
2150721505 }
2150821506
21509 const ptr_size = mod.toEnum(std.builtin.Type.Pointer.Size, size_val);
21507 const ptr_size = zcu.toEnum(std.builtin.Type.Pointer.Size, size_val);
2151021508
2151121509 const actual_sentinel: InternPool.Index = s: {
21512 if (!sentinel_val.isNull(mod)) {
21510 if (!sentinel_val.isNull(zcu)) {
2151321511 if (ptr_size == .One or ptr_size == .C) {
2151421512 return sema.fail(block, src, "sentinels are only allowed on slices and unknown-length pointers", .{});
2151521513 }
21516 const sentinel_ptr_val = sentinel_val.optionalValue(mod).?;
21514 const sentinel_ptr_val = sentinel_val.optionalValue(zcu).?;
2151721515 const ptr_ty = try pt.singleMutPtrType(elem_ty);
2151821516 const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?;
2151921517 break :s sent_val.toIntern();
......@@ -21521,13 +21519,13 @@ fn zirReify(
2152121519 break :s .none;
2152221520 };
2152321521
21524 if (elem_ty.zigTypeTag(mod) == .NoReturn) {
21522 if (elem_ty.zigTypeTag(zcu) == .NoReturn) {
2152521523 return sema.fail(block, src, "pointer to noreturn not allowed", .{});
21526 } else if (elem_ty.zigTypeTag(mod) == .Fn) {
21524 } else if (elem_ty.zigTypeTag(zcu) == .Fn) {
2152721525 if (ptr_size != .One) {
2152821526 return sema.fail(block, src, "function pointers must be single pointers", .{});
2152921527 }
21530 } else if (ptr_size == .Many and elem_ty.zigTypeTag(mod) == .Opaque) {
21528 } else if (ptr_size == .Many and elem_ty.zigTypeTag(zcu) == .Opaque) {
2153121529 return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{});
2153221530 } else if (ptr_size == .C) {
2153321531 if (!try sema.validateExternType(elem_ty, .other)) {
......@@ -21542,7 +21540,7 @@ fn zirReify(
2154221540 };
2154321541 return sema.failWithOwnedErrorMsg(block, msg);
2154421542 }
21545 if (elem_ty.zigTypeTag(mod) == .Opaque) {
21543 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
2154621544 return sema.fail(block, src, "C pointers cannot point to opaque types", .{});
2154721545 }
2154821546 }
......@@ -21555,7 +21553,7 @@ fn zirReify(
2155521553 .is_const = is_const_val.toBool(),
2155621554 .is_volatile = is_volatile_val.toBool(),
2155721555 .alignment = abi_align,
21558 .address_space = mod.toEnum(std.builtin.AddressSpace, address_space_val),
21556 .address_space = zcu.toEnum(std.builtin.AddressSpace, address_space_val),
2155921557 .is_allowzero = is_allowzero_val.toBool(),
2156021558 },
2156121559 });
......@@ -21578,7 +21576,7 @@ fn zirReify(
2157821576
2157921577 const len = try len_val.toUnsignedIntSema(pt);
2158021578 const child_ty = child_val.toType();
21581 const sentinel = if (sentinel_val.optionalValue(mod)) |p| blk: {
21579 const sentinel = if (sentinel_val.optionalValue(zcu)) |p| blk: {
2158221580 const ptr_ty = try pt.singleMutPtrType(child_ty);
2158321581 break :blk (try sema.pointerDeref(block, src, p, ptr_ty)).?;
2158421582 } else null;
......@@ -21616,7 +21614,7 @@ fn zirReify(
2161621614 const error_set_ty = error_set_val.toType();
2161721615 const payload_ty = payload_val.toType();
2161821616
21619 if (error_set_ty.zigTypeTag(mod) != .ErrorSet) {
21617 if (error_set_ty.zigTypeTag(zcu) != .ErrorSet) {
2162021618 return sema.fail(block, src, "Type.ErrorUnion.error_set must be an error set type", .{});
2162121619 }
2162221620
......@@ -21624,14 +21622,14 @@ fn zirReify(
2162421622 return Air.internedToRef(ty.toIntern());
2162521623 },
2162621624 .ErrorSet => {
21627 const payload_val = Value.fromInterned(union_val.val).optionalValue(mod) orelse
21625 const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse
2162821626 return Air.internedToRef(Type.anyerror.toIntern());
2162921627
2163021628 const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{
2163121629 .needed_comptime_reason = "error set contents must be comptime-known",
2163221630 });
2163321631
21634 const len = try sema.usizeCast(block, src, names_val.typeOf(mod).arrayLen(mod));
21632 const len = try sema.usizeCast(block, src, names_val.typeOf(zcu).arrayLen(zcu));
2163521633 var names: InferredErrorSet.NameMap = .{};
2163621634 try names.ensureUnusedCapacity(sema.arena, len);
2163721635 for (0..len) |i| {
......@@ -21680,14 +21678,14 @@ fn zirReify(
2168021678 try ip.getOrPutString(gpa, pt.tid, "is_tuple", .no_embedded_nulls),
2168121679 ).?);
2168221680
21683 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);
21681 const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val);
2168421682
2168521683 // Decls
2168621684 if (try decls_val.sliceLen(pt) > 0) {
2168721685 return sema.fail(block, src, "reified structs must have no decls", .{});
2168821686 }
2168921687
21690 if (layout != .@"packed" and !backing_integer_val.isNull(mod)) {
21688 if (layout != .@"packed" and !backing_integer_val.isNull(zcu)) {
2169121689 return sema.fail(block, src, "non-packed struct does not support backing integer type", .{});
2169221690 }
2169321691
......@@ -21762,8 +21760,8 @@ fn zirReify(
2176221760 const new_namespace_index = try pt.createNamespace(.{
2176321761 .parent = block.namespace.toOptional(),
2176421762 .owner_type = wip_ty.index,
21765 .file_scope = block.getFileScopeIndex(mod),
21766 .generation = mod.generation,
21763 .file_scope = block.getFileScopeIndex(zcu),
21764 .generation = zcu.generation,
2176721765 });
2176821766
2176921767 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -21791,7 +21789,7 @@ fn zirReify(
2179121789 if (try decls_val.sliceLen(pt) > 0) {
2179221790 return sema.fail(block, src, "reified unions must have no decls", .{});
2179321791 }
21794 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);
21792 const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val);
2179521793
2179621794 const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{
2179721795 .needed_comptime_reason = "union fields must be comptime-known",
......@@ -21828,19 +21826,19 @@ fn zirReify(
2182821826 }
2182921827
2183021828 const is_var_args = is_var_args_val.toBool();
21831 const cc = mod.toEnum(std.builtin.CallingConvention, calling_convention_val);
21829 const cc = zcu.toEnum(std.builtin.CallingConvention, calling_convention_val);
2183221830 if (is_var_args) {
2183321831 try sema.checkCallConvSupportsVarArgs(block, src, cc);
2183421832 }
2183521833
21836 const return_type = return_type_val.optionalValue(mod) orelse
21834 const return_type = return_type_val.optionalValue(zcu) orelse
2183721835 return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{});
2183821836
2183921837 const params_val = try sema.derefSliceAsArray(block, operand_src, params_slice_val, .{
2184021838 .needed_comptime_reason = "function parameters must be comptime-known",
2184121839 });
2184221840
21843 const args_len = try sema.usizeCast(block, src, params_val.typeOf(mod).arrayLen(mod));
21841 const args_len = try sema.usizeCast(block, src, params_val.typeOf(zcu).arrayLen(zcu));
2184421842 const param_types = try sema.arena.alloc(InternPool.Index, args_len);
2184521843
2184621844 var noalias_bits: u32 = 0;
......@@ -21864,12 +21862,12 @@ fn zirReify(
2186421862 return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{});
2186521863 }
2186621864
21867 const param_type_val = opt_param_type_val.optionalValue(mod) orelse
21865 const param_type_val = opt_param_type_val.optionalValue(zcu) orelse
2186821866 return sema.fail(block, src, "Type.Fn.Param.type must be non-null for @Type", .{});
2186921867 param_type.* = param_type_val.toIntern();
2187021868
2187121869 if (param_is_noalias_val.toBool()) {
21872 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(mod)) {
21870 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(zcu)) {
2187321871 return sema.fail(block, src, "non-pointer parameter declared noalias", .{});
2187421872 }
2187521873 noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse
......@@ -21901,13 +21899,13 @@ fn reifyEnum(
2190121899 name_strategy: Zir.Inst.NameStrategy,
2190221900) CompileError!Air.Inst.Ref {
2190321901 const pt = sema.pt;
21904 const mod = pt.zcu;
21902 const zcu = pt.zcu;
2190521903 const gpa = sema.gpa;
21906 const ip = &mod.intern_pool;
21904 const ip = &zcu.intern_pool;
2190721905
2190821906 // This logic must stay in sync with the structure of `std.builtin.Type.Enum` - search for `fieldValue`.
2190921907
21910 const fields_len: u32 = @intCast(fields_val.typeOf(mod).arrayLen(mod));
21908 const fields_len: u32 = @intCast(fields_val.typeOf(zcu).arrayLen(zcu));
2191121909
2191221910 // The validation work here is non-trivial, and it's possible the type already exists.
2191321911 // So in this first pass, let's just construct a hash to optimize for this case. If the
......@@ -21957,7 +21955,7 @@ fn reifyEnum(
2195721955 var done = false;
2195821956 errdefer if (!done) wip_ty.cancel(ip, pt.tid);
2195921957
21960 if (tag_ty.zigTypeTag(mod) != .Int) {
21958 if (tag_ty.zigTypeTag(zcu) != .Int) {
2196121959 return sema.fail(block, src, "Type.Enum.tag_type must be an integer type", .{});
2196221960 }
2196321961
......@@ -21972,8 +21970,8 @@ fn reifyEnum(
2197221970 const new_namespace_index = try pt.createNamespace(.{
2197321971 .parent = block.namespace.toOptional(),
2197421972 .owner_type = wip_ty.index,
21975 .file_scope = block.getFileScopeIndex(mod),
21976 .generation = mod.generation,
21973 .file_scope = block.getFileScopeIndex(zcu),
21974 .generation = zcu.generation,
2197721975 });
2197821976
2197921977 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
......@@ -22023,14 +22021,14 @@ fn reifyEnum(
2202322021 }
2202422022 }
2202522023
22026 if (!is_exhaustive and fields_len > 1 and std.math.log2_int(u64, fields_len) == tag_ty.bitSize(pt)) {
22024 if (!is_exhaustive and fields_len > 1 and std.math.log2_int(u64, fields_len) == tag_ty.bitSize(zcu)) {
2202722025 return sema.fail(block, src, "non-exhaustive enum specified every value", .{});
2202822026 }
2202922027
2203022028 codegen_type: {
22031 if (mod.comp.config.use_llvm) break :codegen_type;
22029 if (zcu.comp.config.use_llvm) break :codegen_type;
2203222030 if (block.ownerModule().strip) break :codegen_type;
22033 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
22031 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
2203422032 }
2203522033 return Air.internedToRef(wip_ty.index);
2203622034}
......@@ -22046,13 +22044,13 @@ fn reifyUnion(
2204622044 name_strategy: Zir.Inst.NameStrategy,
2204722045) CompileError!Air.Inst.Ref {
2204822046 const pt = sema.pt;
22049 const mod = pt.zcu;
22047 const zcu = pt.zcu;
2205022048 const gpa = sema.gpa;
22051 const ip = &mod.intern_pool;
22049 const ip = &zcu.intern_pool;
2205222050
2205322051 // This logic must stay in sync with the structure of `std.builtin.Type.Union` - search for `fieldValue`.
2205422052
22055 const fields_len: u32 = @intCast(fields_val.typeOf(mod).arrayLen(mod));
22053 const fields_len: u32 = @intCast(fields_val.typeOf(zcu).arrayLen(zcu));
2205622054
2205722055 // The validation work here is non-trivial, and it's possible the type already exists.
2205822056 // So in this first pass, let's just construct a hash to optimize for this case. If the
......@@ -22084,7 +22082,7 @@ fn reifyUnion(
2208422082 field_align_val.toIntern(),
2208522083 });
2208622084
22087 if (field_align_val.toUnsignedInt(pt) != 0) {
22085 if (field_align_val.toUnsignedInt(zcu) != 0) {
2208822086 any_aligns = true;
2208922087 }
2209022088 }
......@@ -22095,7 +22093,7 @@ fn reifyUnion(
2209522093 .flags = .{
2209622094 .layout = layout,
2209722095 .status = .none,
22098 .runtime_tag = if (opt_tag_type_val.optionalValue(mod) != null)
22096 .runtime_tag = if (opt_tag_type_val.optionalValue(zcu) != null)
2209922097 .tagged
2210022098 else if (layout != .auto)
2210122099 .none
......@@ -22139,7 +22137,7 @@ fn reifyUnion(
2213922137 const field_types = try sema.arena.alloc(InternPool.Index, fields_len);
2214022138 const field_aligns = if (any_aligns) try sema.arena.alloc(InternPool.Alignment, fields_len) else undefined;
2214122139
22142 const enum_tag_ty, const has_explicit_tag = if (opt_tag_type_val.optionalValue(mod)) |tag_type_val| tag_ty: {
22140 const enum_tag_ty, const has_explicit_tag = if (opt_tag_type_val.optionalValue(zcu)) |tag_type_val| tag_ty: {
2214322141 switch (ip.indexToKey(tag_type_val.toIntern())) {
2214422142 .enum_type => {},
2214522143 else => return sema.fail(block, src, "Type.Union.tag_type must be an enum type", .{}),
......@@ -22147,7 +22145,7 @@ fn reifyUnion(
2214722145 const enum_tag_ty = tag_type_val.toType();
2214822146
2214922147 // We simply track which fields of the tag type have been seen.
22150 const tag_ty_fields_len = enum_tag_ty.enumFieldCount(mod);
22148 const tag_ty_fields_len = enum_tag_ty.enumFieldCount(zcu);
2215122149 var seen_tags = try std.DynamicBitSetUnmanaged.initEmpty(sema.arena, tag_ty_fields_len);
2215222150
2215322151 for (field_types, 0..) |*field_ty, field_idx| {
......@@ -22159,7 +22157,7 @@ fn reifyUnion(
2215922157 // Don't pass a reason; first loop acts as an assertion that this is valid.
2216022158 const field_name = try sema.sliceToIpString(block, src, field_name_val, undefined);
2216122159
22162 const enum_index = enum_tag_ty.enumFieldIndex(field_name, mod) orelse {
22160 const enum_index = enum_tag_ty.enumFieldIndex(field_name, zcu) orelse {
2216322161 // TODO: better source location
2216422162 return sema.fail(block, src, "no field named '{}' in enum '{}'", .{
2216522163 field_name.fmt(ip), enum_tag_ty.fmt(pt),
......@@ -22187,7 +22185,7 @@ fn reifyUnion(
2218722185 errdefer msg.destroy(gpa);
2218822186 var it = seen_tags.iterator(.{ .kind = .unset });
2218922187 while (it.next()) |enum_index| {
22190 const field_name = enum_tag_ty.enumFieldName(enum_index, mod);
22188 const field_name = enum_tag_ty.enumFieldName(enum_index, zcu);
2219122189 try sema.addFieldErrNote(enum_tag_ty, enum_index, msg, "field '{}' missing, declared here", .{
2219222190 field_name.fmt(ip),
2219322191 });
......@@ -22234,7 +22232,7 @@ fn reifyUnion(
2223422232
2223522233 for (field_types) |field_ty_ip| {
2223622234 const field_ty = Type.fromInterned(field_ty_ip);
22237 if (field_ty.zigTypeTag(mod) == .Opaque) {
22235 if (field_ty.zigTypeTag(zcu) == .Opaque) {
2223822236 return sema.failWithOwnedErrorMsg(block, msg: {
2223922237 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
2224022238 errdefer msg.destroy(gpa);
......@@ -22277,17 +22275,17 @@ fn reifyUnion(
2227722275 const new_namespace_index = try pt.createNamespace(.{
2227822276 .parent = block.namespace.toOptional(),
2227922277 .owner_type = wip_ty.index,
22280 .file_scope = block.getFileScopeIndex(mod),
22281 .generation = mod.generation,
22278 .file_scope = block.getFileScopeIndex(zcu),
22279 .generation = zcu.generation,
2228222280 });
2228322281
2228422282 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
2228522283
22286 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
22284 try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
2228722285 codegen_type: {
22288 if (mod.comp.config.use_llvm) break :codegen_type;
22286 if (zcu.comp.config.use_llvm) break :codegen_type;
2228922287 if (block.ownerModule().strip) break :codegen_type;
22290 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
22288 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
2229122289 }
2229222290 try sema.declareDependency(.{ .interned = wip_ty.index });
2229322291 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -22306,13 +22304,13 @@ fn reifyStruct(
2230622304 is_tuple: bool,
2230722305) CompileError!Air.Inst.Ref {
2230822306 const pt = sema.pt;
22309 const mod = pt.zcu;
22307 const zcu = pt.zcu;
2231022308 const gpa = sema.gpa;
22311 const ip = &mod.intern_pool;
22309 const ip = &zcu.intern_pool;
2231222310
2231322311 // This logic must stay in sync with the structure of `std.builtin.Type.Struct` - search for `fieldValue`.
2231422312
22315 const fields_len: u32 = @intCast(fields_val.typeOf(mod).arrayLen(mod));
22313 const fields_len: u32 = @intCast(fields_val.typeOf(zcu).arrayLen(zcu));
2231622314
2231722315 // The validation work here is non-trivial, and it's possible the type already exists.
2231822316 // So in this first pass, let's just construct a hash to optimize for this case. If the
......@@ -22343,7 +22341,7 @@ fn reifyStruct(
2234322341 .needed_comptime_reason = "struct field name must be comptime-known",
2234422342 });
2234522343 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: {
22344 const field_default_value: InternPool.Index = if (field_default_value_val.optionalValue(zcu)) |ptr_val| d: {
2234722345 const ptr_ty = try pt.singleConstPtrType(field_type_val.toType());
2234822346 // We need to do this deref here, so we won't check for this error case later on.
2234922347 const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime(
......@@ -22365,7 +22363,7 @@ fn reifyStruct(
2236522363
2236622364 if (field_is_comptime) any_comptime_fields = true;
2236722365 if (field_default_value != .none) any_default_inits = true;
22368 switch (try field_alignment_val.orderAgainstZeroAdvanced(pt, .sema)) {
22366 switch (try field_alignment_val.orderAgainstZeroSema(pt)) {
2236922367 .eq => {},
2237022368 .gt => any_aligned_fields = true,
2237122369 .lt => unreachable,
......@@ -22475,7 +22473,7 @@ fn reifyStruct(
2247522473
2247622474 const field_default: InternPool.Index = d: {
2247722475 if (!any_default_inits) break :d .none;
22478 const ptr_val = field_default_value_val.optionalValue(mod) orelse break :d .none;
22476 const ptr_val = field_default_value_val.optionalValue(zcu) orelse break :d .none;
2247922477 const ptr_ty = try pt.singleConstPtrType(field_ty);
2248022478 // Asserted comptime-dereferencable above.
2248122479 const val = (try sema.pointerDeref(block, src, ptr_val, ptr_ty)).?;
......@@ -22492,7 +22490,7 @@ fn reifyStruct(
2249222490 struct_type.field_inits.get(ip)[field_idx] = field_default;
2249322491 }
2249422492
22495 if (field_ty.zigTypeTag(mod) == .Opaque) {
22493 if (field_ty.zigTypeTag(zcu) == .Opaque) {
2249622494 return sema.failWithOwnedErrorMsg(block, msg: {
2249722495 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2249822496 errdefer msg.destroy(gpa);
......@@ -22501,7 +22499,7 @@ fn reifyStruct(
2250122499 break :msg msg;
2250222500 });
2250322501 }
22504 if (field_ty.zigTypeTag(mod) == .NoReturn) {
22502 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
2250522503 return sema.failWithOwnedErrorMsg(block, msg: {
2250622504 const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{});
2250722505 errdefer msg.destroy(gpa);
......@@ -22545,10 +22543,10 @@ fn reifyStruct(
2254522543 },
2254622544 else => return err,
2254722545 };
22548 fields_bit_sum += field_ty.bitSize(pt);
22546 fields_bit_sum += field_ty.bitSize(zcu);
2254922547 }
2255022548
22551 if (opt_backing_int_val.optionalValue(mod)) |backing_int_val| {
22549 if (opt_backing_int_val.optionalValue(zcu)) |backing_int_val| {
2255222550 const backing_int_ty = backing_int_val.toType();
2255322551 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
2255422552 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
......@@ -22561,17 +22559,17 @@ fn reifyStruct(
2256122559 const new_namespace_index = try pt.createNamespace(.{
2256222560 .parent = block.namespace.toOptional(),
2256322561 .owner_type = wip_ty.index,
22564 .file_scope = block.getFileScopeIndex(mod),
22565 .generation = mod.generation,
22562 .file_scope = block.getFileScopeIndex(zcu),
22563 .generation = zcu.generation,
2256622564 });
2256722565
2256822566 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
2256922567
22570 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
22568 try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
2257122569 codegen_type: {
22572 if (mod.comp.config.use_llvm) break :codegen_type;
22570 if (zcu.comp.config.use_llvm) break :codegen_type;
2257322571 if (block.ownerModule().strip) break :codegen_type;
22574 try mod.comp.queueJob(.{ .codegen_type = wip_ty.index });
22572 try zcu.comp.queueJob(.{ .codegen_type = wip_ty.index });
2257522573 }
2257622574 try sema.declareDependency(.{ .interned = wip_ty.index });
2257722575 try sema.addTypeReferenceEntry(src, wip_ty.index);
......@@ -22649,8 +22647,8 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2264922647
2265022648fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2265122649 const pt = sema.pt;
22652 const mod = pt.zcu;
22653 const ip = &mod.intern_pool;
22650 const zcu = pt.zcu;
22651 const ip = &zcu.intern_pool;
2265422652
2265522653 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2265622654 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -22674,7 +22672,7 @@ fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2267422672
2267522673fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2267622674 const pt = sema.pt;
22677 const mod = pt.zcu;
22675 const zcu = pt.zcu;
2267822676 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2267922677 const src = block.nodeOffset(inst_data.src_node);
2268022678 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -22684,10 +22682,10 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2268422682 const operand_ty = sema.typeOf(operand);
2268522683
2268622684 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);
22687 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
22685 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2268822686
22689 const dest_scalar_ty = dest_ty.scalarType(mod);
22690 const operand_scalar_ty = operand_ty.scalarType(mod);
22687 const dest_scalar_ty = dest_ty.scalarType(zcu);
22688 const operand_scalar_ty = operand_ty.scalarType(zcu);
2269122689
2269222690 _ = try sema.checkIntType(block, src, dest_scalar_ty);
2269322691 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
......@@ -22695,14 +22693,14 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2269522693 if (try sema.resolveValue(operand)) |operand_val| {
2269622694 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate);
2269722695 return Air.internedToRef(result_val.toIntern());
22698 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
22696 } else if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
2269922697 return sema.failWithNeededComptime(block, operand_src, .{
2270022698 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
2270122699 });
2270222700 }
2270322701
2270422702 try sema.requireRuntimeBlock(block, src, operand_src);
22705 if (dest_scalar_ty.intInfo(mod).bits == 0) {
22703 if (dest_scalar_ty.intInfo(zcu).bits == 0) {
2270622704 if (!is_vector) {
2270722705 if (block.wantSafety()) {
2270822706 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 +22709,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2271122709 return Air.internedToRef((try pt.intValue(dest_ty, 0)).toIntern());
2271222710 }
2271322711 if (block.wantSafety()) {
22714 const len = dest_ty.vectorLen(mod);
22712 const len = dest_ty.vectorLen(zcu);
2271522713 for (0..len) |i| {
2271622714 const idx_ref = try pt.intRef(Type.usize, i);
2271722715 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);
......@@ -22736,7 +22734,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2273622734 }
2273722735 return result;
2273822736 }
22739 const len = dest_ty.vectorLen(mod);
22737 const len = dest_ty.vectorLen(zcu);
2274022738 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2274122739 for (new_elems, 0..) |*new_elem, i| {
2274222740 const idx_ref = try pt.intRef(Type.usize, i);
......@@ -22757,7 +22755,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2275722755
2275822756fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2275922757 const pt = sema.pt;
22760 const mod = pt.zcu;
22758 const zcu = pt.zcu;
2276122759 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2276222760 const src = block.nodeOffset(inst_data.src_node);
2276322761 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
......@@ -22767,10 +22765,10 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2276722765 const operand_ty = sema.typeOf(operand);
2276822766
2276922767 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);
22770 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
22768 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2277122769
22772 const dest_scalar_ty = dest_ty.scalarType(mod);
22773 const operand_scalar_ty = operand_ty.scalarType(mod);
22770 const dest_scalar_ty = dest_ty.scalarType(zcu);
22771 const operand_scalar_ty = operand_ty.scalarType(zcu);
2277422772
2277522773 try sema.checkFloatType(block, src, dest_scalar_ty);
2277622774 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
......@@ -22778,7 +22776,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2277822776 if (try sema.resolveValue(operand)) |operand_val| {
2277922777 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, pt, .sema);
2278022778 return Air.internedToRef(result_val.toIntern());
22781 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) {
22779 } else if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeFloat) {
2278222780 return sema.failWithNeededComptime(block, operand_src, .{
2278322781 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
2278422782 });
......@@ -22788,7 +22786,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2278822786 if (!is_vector) {
2278922787 return block.addTyOp(.float_from_int, dest_ty, operand);
2279022788 }
22791 const len = operand_ty.vectorLen(mod);
22789 const len = operand_ty.vectorLen(zcu);
2279222790 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
2279322791 for (new_elems, 0..) |*new_elem, i| {
2279422792 const idx_ref = try pt.intRef(Type.usize, i);
......@@ -22800,7 +22798,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2280022798
2280122799fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2280222800 const pt = sema.pt;
22803 const mod = pt.zcu;
22801 const zcu = pt.zcu;
2280422802 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2280522803 const src = block.nodeOffset(inst_data.src_node);
2280622804
......@@ -22813,21 +22811,21 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2281322811 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrFromInt");
2281422812 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, uncoerced_operand_ty, src, operand_src);
2281522813
22816 const is_vector = dest_ty.zigTypeTag(mod) == .Vector;
22814 const is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2281722815 const operand_ty = if (is_vector) operand_ty: {
22818 const len = dest_ty.vectorLen(mod);
22816 const len = dest_ty.vectorLen(zcu);
2281922817 break :operand_ty try pt.vectorType(.{ .child = .usize_type, .len = len });
2282022818 } else Type.usize;
2282122819
2282222820 const operand_coerced = try sema.coerce(block, operand_ty, operand_res, operand_src);
2282322821
22824 const ptr_ty = dest_ty.scalarType(mod);
22822 const ptr_ty = dest_ty.scalarType(zcu);
2282522823 try sema.checkPtrType(block, src, ptr_ty, true);
2282622824
22827 const elem_ty = ptr_ty.elemType2(mod);
22828 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(pt, .sema);
22825 const elem_ty = ptr_ty.elemType2(zcu);
22826 const ptr_align = try ptr_ty.ptrAlignmentSema(pt);
2282922827
22830 if (ptr_ty.isSlice(mod)) {
22828 if (ptr_ty.isSlice(zcu)) {
2283122829 const msg = msg: {
2283222830 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(pt)});
2283322831 errdefer msg.destroy(sema.gpa);
......@@ -22842,7 +22840,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2284222840 const ptr_val = try sema.ptrFromIntVal(block, operand_src, val, ptr_ty, ptr_align);
2284322841 return Air.internedToRef(ptr_val.toIntern());
2284422842 }
22845 const len = dest_ty.vectorLen(mod);
22843 const len = dest_ty.vectorLen(zcu);
2284622844 const new_elems = try sema.arena.alloc(InternPool.Index, len);
2284722845 for (new_elems, 0..) |*new_elem, i| {
2284822846 const elem = try val.elemValue(pt, i);
......@@ -22854,7 +22852,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2285422852 .storage = .{ .elems = new_elems },
2285522853 } }));
2285622854 }
22857 if (try sema.typeRequiresComptime(ptr_ty)) {
22855 if (try ptr_ty.comptimeOnlySema(pt)) {
2285822856 return sema.failWithOwnedErrorMsg(block, msg: {
2285922857 const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(pt)});
2286022858 errdefer msg.destroy(sema.gpa);
......@@ -22865,8 +22863,8 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2286522863 }
2286622864 try sema.requireRuntimeBlock(block, src, operand_src);
2286722865 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)) {
22866 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .Fn)) {
22867 if (!ptr_ty.isAllowzeroPtr(zcu)) {
2287022868 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
2287122869 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
2287222870 }
......@@ -22881,12 +22879,12 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2288122879 return block.addBitCast(dest_ty, operand_coerced);
2288222880 }
2288322881
22884 const len = dest_ty.vectorLen(mod);
22885 if (block.wantSafety() and (try sema.typeHasRuntimeBits(elem_ty) or elem_ty.zigTypeTag(mod) == .Fn)) {
22882 const len = dest_ty.vectorLen(zcu);
22883 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .Fn)) {
2288622884 for (0..len) |i| {
2288722885 const idx_ref = try pt.intRef(Type.usize, i);
2288822886 const elem_coerced = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);
22889 if (!ptr_ty.isAllowzeroPtr(mod)) {
22887 if (!ptr_ty.isAllowzeroPtr(zcu)) {
2289022888 const is_non_zero = try block.addBinOp(.cmp_neq, elem_coerced, .zero_usize);
2289122889 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
2289222890 }
......@@ -22943,16 +22941,16 @@ fn ptrFromIntVal(
2294322941
2294422942fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2294522943 const pt = sema.pt;
22946 const mod = pt.zcu;
22947 const ip = &mod.intern_pool;
22944 const zcu = pt.zcu;
22945 const ip = &zcu.intern_pool;
2294822946 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2294922947 const src = block.nodeOffset(extra.node);
2295022948 const operand_src = block.builtinCallArgSrc(extra.node, 0);
2295122949 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");
2295222950 const operand = try sema.resolveInst(extra.rhs);
2295322951 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);
22952 const dest_tag = base_dest_ty.zigTypeTag(zcu);
22953 const operand_tag = base_operand_ty.zigTypeTag(zcu);
2295622954
2295722955 if (dest_tag != .ErrorSet and dest_tag != .ErrorUnion) {
2295822956 return sema.fail(block, src, "expected error set or error union type, found '{s}'", .{@tagName(dest_tag)});
......@@ -22964,13 +22962,13 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2296422962 return sema.fail(block, src, "cannot cast an error union type to error set", .{});
2296522963 }
2296622964 if (dest_tag == .ErrorUnion and operand_tag == .ErrorUnion and
22967 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())
22965 base_dest_ty.errorUnionPayload(zcu).toIntern() != base_operand_ty.errorUnionPayload(zcu).toIntern())
2296822966 {
2296922967 return sema.failWithOwnedErrorMsg(block, msg: {
2297022968 const msg = try sema.errMsg(src, "payload types of error unions must match", .{});
2297122969 errdefer msg.destroy(sema.gpa);
22972 const dest_ty = base_dest_ty.errorUnionPayload(mod);
22973 const operand_ty = base_operand_ty.errorUnionPayload(mod);
22970 const dest_ty = base_dest_ty.errorUnionPayload(zcu);
22971 const operand_ty = base_operand_ty.errorUnionPayload(zcu);
2297422972 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(pt)});
2297522973 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(pt)});
2297622974 try addDeclaredHereNote(sema, msg, dest_ty);
......@@ -22978,19 +22976,19 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2297822976 break :msg msg;
2297922977 });
2298022978 }
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;
22979 const dest_ty = if (dest_tag == .ErrorUnion) base_dest_ty.errorUnionSet(zcu) else base_dest_ty;
22980 const operand_ty = if (operand_tag == .ErrorUnion) base_operand_ty.errorUnionSet(zcu) else base_operand_ty;
2298322981
2298422982 // operand must be defined since it can be an invalid error value
2298522983 const maybe_operand_val = try sema.resolveDefinedValue(block, operand_src, operand);
2298622984
2298722985 const disjoint = disjoint: {
2298822986 // 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);
22987 if (!dest_ty.isAnyError(zcu) and dest_ty.errorSetIsEmpty(zcu)) break :disjoint true;
22988 if (!operand_ty.isAnyError(zcu) and operand_ty.errorSetIsEmpty(zcu)) break :disjoint true;
22989 if (dest_ty.isAnyError(zcu)) break :disjoint false;
22990 if (operand_ty.isAnyError(zcu)) break :disjoint false;
22991 const dest_err_names = dest_ty.errorSetNames(zcu);
2299422992 for (0..dest_err_names.len) |dest_err_index| {
2299522993 if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_names.get(ip)[dest_err_index]))
2299622994 break :disjoint false;
......@@ -23018,8 +23016,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2301823016 }
2301923017
2302023018 if (maybe_operand_val) |val| {
23021 if (!dest_ty.isAnyError(mod)) check: {
23022 const operand_val = mod.intern_pool.indexToKey(val.toIntern());
23019 if (!dest_ty.isAnyError(zcu)) check: {
23020 const operand_val = zcu.intern_pool.indexToKey(val.toIntern());
2302323021 var error_name: InternPool.NullTerminatedString = undefined;
2302423022 if (operand_tag == .ErrorUnion) {
2302523023 if (operand_val.error_union.val != .err_name) break :check;
......@@ -23039,9 +23037,9 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2303923037
2304023038 try sema.requireRuntimeBlock(block, src, operand_src);
2304123039 const err_int_ty = try pt.errorIntType();
23042 if (block.wantSafety() and !dest_ty.isAnyError(mod) and
23040 if (block.wantSafety() and !dest_ty.isAnyError(zcu) and
2304323041 dest_ty.toIntern() != .adhoc_inferred_error_set_type and
23044 mod.backendSupportsFeature(.error_set_has_value))
23042 zcu.backendSupportsFeature(.error_set_has_value))
2304523043 {
2304623044 if (dest_tag == .ErrorUnion) {
2304723045 const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand);
......@@ -23116,23 +23114,23 @@ fn ptrCastFull(
2311623114 operation: []const u8,
2311723115) CompileError!Air.Inst.Ref {
2311823116 const pt = sema.pt;
23119 const mod = pt.zcu;
23117 const zcu = pt.zcu;
2312023118 const operand_ty = sema.typeOf(operand);
2312123119
2312223120 try sema.checkPtrType(block, src, dest_ty, true);
2312323121 try sema.checkPtrOperand(block, operand_src, operand_ty);
2312423122
23125 const src_info = operand_ty.ptrInfo(mod);
23126 const dest_info = dest_ty.ptrInfo(mod);
23123 const src_info = operand_ty.ptrInfo(zcu);
23124 const dest_info = dest_ty.ptrInfo(zcu);
2312723125
2312823126 try Type.fromInterned(src_info.child).resolveLayout(pt);
2312923127 try Type.fromInterned(dest_info.child).resolveLayout(pt);
2313023128
2313123129 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);
23130 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .Array);
2313323131
2313423132 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);
23133 (dest_info.flags.size == .One and Type.fromInterned(dest_info.child).zigTypeTag(zcu) == .Array);
2313623134
2313723135 if (dest_info.flags.size == .Slice and !src_slice_like) {
2313823136 return sema.fail(block, src, "illegal pointer cast to slice", .{});
......@@ -23140,12 +23138,12 @@ fn ptrCastFull(
2314023138
2314123139 if (dest_info.flags.size == .Slice) {
2314223140 const src_elem_size = switch (src_info.flags.size) {
23143 .Slice => Type.fromInterned(src_info.child).abiSize(pt),
23141 .Slice => Type.fromInterned(src_info.child).abiSize(zcu),
2314423142 // pointer to array
23145 .One => Type.fromInterned(src_info.child).childType(mod).abiSize(pt),
23143 .One => Type.fromInterned(src_info.child).childType(zcu).abiSize(zcu),
2314623144 else => unreachable,
2314723145 };
23148 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(pt);
23146 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(zcu);
2314923147 if (src_elem_size != dest_elem_size) {
2315023148 return sema.fail(block, src, "TODO: implement {s} between slices changing the length", .{operation});
2315123149 }
......@@ -23167,7 +23165,7 @@ fn ptrCastFull(
2316723165 errdefer msg.destroy(sema.gpa);
2316823166 if (dest_info.flags.size == .Many and
2316923167 (src_info.flags.size == .Slice or
23170 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))
23168 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(zcu) == .Array)))
2317123169 {
2317223170 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});
2317323171 } else {
......@@ -23180,7 +23178,7 @@ fn ptrCastFull(
2318023178 check_child: {
2318123179 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {
2318223180 // *[n]T -> []T
23183 break :blk Type.fromInterned(src_info.child).childType(mod);
23181 break :blk Type.fromInterned(src_info.child).childType(zcu);
2318423182 } else Type.fromInterned(src_info.child);
2318523183
2318623184 const dest_child = Type.fromInterned(dest_info.child);
......@@ -23190,7 +23188,7 @@ fn ptrCastFull(
2319023188 dest_child,
2319123189 src_child,
2319223190 !dest_info.flags.is_const,
23193 mod.getTarget(),
23191 zcu.getTarget(),
2319423192 src,
2319523193 operand_src,
2319623194 null,
......@@ -23211,14 +23209,14 @@ fn ptrCastFull(
2321123209 if (dest_info.sentinel == .none) break :check_sent;
2321223210 if (src_info.flags.size == .C) break :check_sent;
2321323211 if (src_info.sentinel != .none) {
23214 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, pt.tid, src_info.sentinel, dest_info.child);
23212 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_info.sentinel, dest_info.child);
2321523213 if (dest_info.sentinel == coerced_sent) break :check_sent;
2321623214 }
2321723215 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {
2321823216 // [*]nT -> []T
2321923217 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);
23218 if (arr_ty.sentinel(zcu)) |src_sentinel| {
23219 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);
2322223220 if (dest_info.sentinel == coerced_sent) break :check_sent;
2322323221 }
2322423222 }
......@@ -23264,8 +23262,8 @@ fn ptrCastFull(
2326423262 }
2326523263
2326623264 check_allowzero: {
23267 const src_allows_zero = operand_ty.ptrAllowsZero(mod);
23268 const dest_allows_zero = dest_ty.ptrAllowsZero(mod);
23265 const src_allows_zero = operand_ty.ptrAllowsZero(zcu);
23266 const dest_allows_zero = dest_ty.ptrAllowsZero(zcu);
2326923267 if (!src_allows_zero) break :check_allowzero;
2327023268 if (dest_allows_zero) break :check_allowzero;
2327123269
......@@ -23286,12 +23284,12 @@ fn ptrCastFull(
2328623284 const src_align = if (src_info.flags.alignment != .none)
2328723285 src_info.flags.alignment
2328823286 else
23289 Type.fromInterned(src_info.child).abiAlignment(pt);
23287 Type.fromInterned(src_info.child).abiAlignment(zcu);
2329023288
2329123289 const dest_align = if (dest_info.flags.alignment != .none)
2329223290 dest_info.flags.alignment
2329323291 else
23294 Type.fromInterned(dest_info.child).abiAlignment(pt);
23292 Type.fromInterned(dest_info.child).abiAlignment(zcu);
2329523293
2329623294 if (!flags.align_cast) {
2329723295 if (dest_align.compare(.gt, src_align)) {
......@@ -23327,7 +23325,7 @@ fn ptrCastFull(
2332723325 }
2332823326 } else {
2332923327 // Some address space casts are always disallowed
23330 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
23328 if (!target_util.addrSpaceCastIsValid(zcu.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
2333123329 return sema.failWithOwnedErrorMsg(block, msg: {
2333223330 const msg = try sema.errMsg(src, "invalid address space cast", .{});
2333323331 errdefer msg.destroy(sema.gpa);
......@@ -23363,7 +23361,7 @@ fn ptrCastFull(
2336323361 }
2336423362
2336523363 const ptr = if (src_info.flags.size == .Slice and dest_info.flags.size != .Slice) ptr: {
23366 if (operand_ty.zigTypeTag(mod) == .Optional) {
23364 if (operand_ty.zigTypeTag(zcu) == .Optional) {
2336723365 break :ptr try sema.analyzeOptionalSlicePtr(block, operand_src, operand, operand_ty);
2336823366 } else {
2336923367 break :ptr try sema.analyzeSlicePtr(block, operand_src, operand, operand_ty);
......@@ -23375,7 +23373,7 @@ fn ptrCastFull(
2337523373 var info = dest_info;
2337623374 info.flags.size = .Many;
2337723375 const ty = try pt.ptrTypeSema(info);
23378 if (dest_ty.zigTypeTag(mod) == .Optional) {
23376 if (dest_ty.zigTypeTag(zcu) == .Optional) {
2337923377 break :blk try pt.optionalType(ty.toIntern());
2338023378 } else {
2338123379 break :blk ty;
......@@ -23385,14 +23383,14 @@ fn ptrCastFull(
2338523383 // Cannot do @addrSpaceCast at comptime
2338623384 if (!flags.addrspace_cast) {
2338723385 if (try sema.resolveValue(ptr)) |ptr_val| {
23388 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isUndef(mod)) {
23386 if (!dest_ty.ptrAllowsZero(zcu) and ptr_val.isUndef(zcu)) {
2338923387 return sema.failWithUseOfUndef(block, operand_src);
2339023388 }
23391 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isNull(mod)) {
23389 if (!dest_ty.ptrAllowsZero(zcu) and ptr_val.isNull(zcu)) {
2339223390 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});
2339323391 }
2339423392 if (dest_align.compare(.gt, src_align)) {
23395 if (try ptr_val.getUnsignedIntAdvanced(pt, .sema)) |addr| {
23393 if (try ptr_val.getUnsignedIntSema(pt)) |addr| {
2339623394 if (!dest_align.check(addr)) {
2339723395 return sema.fail(block, operand_src, "pointer address 0x{X} is not aligned to {d} bytes", .{
2339823396 addr,
......@@ -23402,20 +23400,20 @@ fn ptrCastFull(
2340223400 }
2340323401 }
2340423402 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;
23403 if (ptr_val.isUndef(zcu)) return pt.undefRef(dest_ty);
23404 const arr_len = try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(zcu));
23405 const ptr_val_key = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
2340823406 return Air.internedToRef((try pt.intern(.{ .slice = .{
2340923407 .ty = dest_ty.toIntern(),
2341023408 .ptr = try pt.intern(.{ .ptr = .{
23411 .ty = dest_ty.slicePtrFieldType(mod).toIntern(),
23409 .ty = dest_ty.slicePtrFieldType(zcu).toIntern(),
2341223410 .base_addr = ptr_val_key.base_addr,
2341323411 .byte_offset = ptr_val_key.byte_offset,
2341423412 } }),
2341523413 .len = arr_len.toIntern(),
2341623414 } })));
2341723415 } else {
23418 assert(dest_ptr_ty.eql(dest_ty, mod));
23416 assert(dest_ptr_ty.eql(dest_ty, zcu));
2341923417 return Air.internedToRef((try pt.getCoerced(ptr_val, dest_ty)).toIntern());
2342023418 }
2342123419 }
......@@ -23424,8 +23422,8 @@ fn ptrCastFull(
2342423422 try sema.requireRuntimeBlock(block, src, null);
2342523423 try sema.validateRuntimeValue(block, operand_src, ptr);
2342623424
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))
23425 if (block.wantSafety() and operand_ty.ptrAllowsZero(zcu) and !dest_ty.ptrAllowsZero(zcu) and
23426 (try Type.fromInterned(dest_info.child).hasRuntimeBitsSema(pt) or Type.fromInterned(dest_info.child).zigTypeTag(zcu) == .Fn))
2342923427 {
2343023428 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
2343123429 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
......@@ -23439,7 +23437,7 @@ fn ptrCastFull(
2343923437
2344023438 if (block.wantSafety() and
2344123439 dest_align.compare(.gt, src_align) and
23442 try sema.typeHasRuntimeBits(Type.fromInterned(dest_info.child)))
23440 try Type.fromInterned(dest_info.child).hasRuntimeBitsSema(pt))
2344323441 {
2344423442 const align_bytes_minus_1 = dest_align.toByteUnits().? - 1;
2344523443 const align_minus_1 = Air.internedToRef((try pt.intValue(Type.usize, align_bytes_minus_1)).toIntern());
......@@ -23460,7 +23458,7 @@ fn ptrCastFull(
2346023458 var intermediate_info = src_info;
2346123459 intermediate_info.flags.address_space = dest_info.flags.address_space;
2346223460 const intermediate_ptr_ty = try pt.ptrTypeSema(intermediate_info);
23463 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(mod) == .Optional) blk: {
23461 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(zcu) == .Optional) blk: {
2346423462 break :blk try pt.optionalType(intermediate_ptr_ty.toIntern());
2346523463 } else intermediate_ptr_ty;
2346623464 const intermediate = try block.addInst(.{
......@@ -23470,7 +23468,7 @@ fn ptrCastFull(
2347023468 .operand = ptr,
2347123469 } },
2347223470 });
23473 if (intermediate_ty.eql(dest_ptr_ty, mod)) {
23471 if (intermediate_ty.eql(dest_ptr_ty, zcu)) {
2347423472 // We only changed the address space, so no need for a bitcast
2347523473 break :ptr intermediate;
2347623474 }
......@@ -23482,7 +23480,7 @@ fn ptrCastFull(
2348223480 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
2348323481 // We have to construct a slice using the operand's child's array length
2348423482 // 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());
23483 const arr_len = Air.internedToRef((try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(zcu))).toIntern());
2348623484 return block.addInst(.{
2348723485 .tag = .slice,
2348823486 .data = .{ .ty_pl = .{
......@@ -23494,7 +23492,7 @@ fn ptrCastFull(
2349423492 } },
2349523493 });
2349623494 } else {
23497 assert(dest_ptr_ty.eql(dest_ty, mod));
23495 assert(dest_ptr_ty.eql(dest_ty, zcu));
2349823496 try sema.checkKnownAllocPtr(block, operand, result_ptr);
2349923497 return result_ptr;
2350023498 }
......@@ -23502,7 +23500,7 @@ fn ptrCastFull(
2350223500
2350323501fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2350423502 const pt = sema.pt;
23505 const mod = pt.zcu;
23503 const zcu = pt.zcu;
2350623504 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
2350723505 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2350823506 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
......@@ -23512,13 +23510,13 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2351223510 const operand_ty = sema.typeOf(operand);
2351323511 try sema.checkPtrOperand(block, operand_src, operand_ty);
2351423512
23515 var ptr_info = operand_ty.ptrInfo(mod);
23513 var ptr_info = operand_ty.ptrInfo(zcu);
2351623514 if (flags.const_cast) ptr_info.flags.is_const = false;
2351723515 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;
2351823516
2351923517 const dest_ty = blk: {
2352023518 const dest_ty = try pt.ptrTypeSema(ptr_info);
23521 if (operand_ty.zigTypeTag(mod) == .Optional) {
23519 if (operand_ty.zigTypeTag(zcu) == .Optional) {
2352223520 break :blk try pt.optionalType(dest_ty.toIntern());
2352323521 }
2352423522 break :blk dest_ty;
......@@ -23536,7 +23534,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2353623534
2353723535fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2353823536 const pt = sema.pt;
23539 const mod = pt.zcu;
23537 const zcu = pt.zcu;
2354023538 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2354123539 const src = block.nodeOffset(inst_data.src_node);
2354223540 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -23547,24 +23545,24 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2354723545 const operand_ty = sema.typeOf(operand);
2354823546 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
2354923547
23550 const operand_is_vector = operand_ty.zigTypeTag(mod) == .Vector;
23551 const dest_is_vector = dest_ty.zigTypeTag(mod) == .Vector;
23548 const operand_is_vector = operand_ty.zigTypeTag(zcu) == .Vector;
23549 const dest_is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
2355223550 if (operand_is_vector != dest_is_vector) {
2355323551 return sema.fail(block, operand_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(pt), operand_ty.fmt(pt) });
2355423552 }
2355523553
23556 if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
23554 if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
2355723555 return sema.coerce(block, dest_ty, operand, operand_src);
2355823556 }
2355923557
23560 const dest_info = dest_scalar_ty.intInfo(mod);
23558 const dest_info = dest_scalar_ty.intInfo(zcu);
2356123559
2356223560 if (try sema.typeHasOnePossibleValue(dest_ty)) |val| {
2356323561 return Air.internedToRef(val.toIntern());
2356423562 }
2356523563
23566 if (operand_scalar_ty.zigTypeTag(mod) != .ComptimeInt) {
23567 const operand_info = operand_ty.intInfo(mod);
23564 if (operand_scalar_ty.zigTypeTag(zcu) != .ComptimeInt) {
23565 const operand_info = operand_ty.intInfo(zcu);
2356823566 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
2356923567 return Air.internedToRef(val.toIntern());
2357023568 }
......@@ -23595,14 +23593,14 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2359523593 }
2359623594
2359723595 if (try sema.resolveValueIntable(operand)) |val| {
23598 if (val.isUndef(mod)) return pt.undefRef(dest_ty);
23596 if (val.isUndef(zcu)) return pt.undefRef(dest_ty);
2359923597 if (!dest_is_vector) {
2360023598 return Air.internedToRef((try pt.getCoerced(
2360123599 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, pt),
2360223600 dest_ty,
2360323601 )).toIntern());
2360423602 }
23605 const elems = try sema.arena.alloc(InternPool.Index, operand_ty.vectorLen(mod));
23603 const elems = try sema.arena.alloc(InternPool.Index, operand_ty.vectorLen(zcu));
2360623604 for (elems, 0..) |*elem, i| {
2360723605 const elem_val = try val.elemValue(pt, i);
2360823606 const uncoerced_elem = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, pt);
......@@ -23623,38 +23621,38 @@ fn zirBitCount(
2362323621 block: *Block,
2362423622 inst: Zir.Inst.Index,
2362523623 air_tag: Air.Inst.Tag,
23626 comptime comptimeOp: fn (val: Value, ty: Type, pt: Zcu.PerThread) u64,
23624 comptime comptimeOp: fn (val: Value, ty: Type, zcu: *Zcu) u64,
2362723625) CompileError!Air.Inst.Ref {
2362823626 const pt = sema.pt;
23629 const mod = pt.zcu;
23627 const zcu = pt.zcu;
2363023628 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2363123629 const src = block.nodeOffset(inst_data.src_node);
2363223630 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2363323631 const operand = try sema.resolveInst(inst_data.operand);
2363423632 const operand_ty = sema.typeOf(operand);
2363523633 _ = try sema.checkIntOrVector(block, operand, operand_src);
23636 const bits = operand_ty.intInfo(mod).bits;
23634 const bits = operand_ty.intInfo(zcu).bits;
2363723635
2363823636 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
2363923637 return Air.internedToRef(val.toIntern());
2364023638 }
2364123639
2364223640 const result_scalar_ty = try pt.smallestUnsignedInt(bits);
23643 switch (operand_ty.zigTypeTag(mod)) {
23641 switch (operand_ty.zigTypeTag(zcu)) {
2364423642 .Vector => {
23645 const vec_len = operand_ty.vectorLen(mod);
23643 const vec_len = operand_ty.vectorLen(zcu);
2364623644 const result_ty = try pt.vectorType(.{
2364723645 .len = vec_len,
2364823646 .child = result_scalar_ty.toIntern(),
2364923647 });
2365023648 if (try sema.resolveValue(operand)) |val| {
23651 if (val.isUndef(mod)) return pt.undefRef(result_ty);
23649 if (val.isUndef(zcu)) return pt.undefRef(result_ty);
2365223650
2365323651 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
23654 const scalar_ty = operand_ty.scalarType(mod);
23652 const scalar_ty = operand_ty.scalarType(zcu);
2365523653 for (elems, 0..) |*elem, i| {
2365623654 const elem_val = try val.elemValue(pt, i);
23657 const count = comptimeOp(elem_val, scalar_ty, pt);
23655 const count = comptimeOp(elem_val, scalar_ty, zcu);
2365823656 elem.* = (try pt.intValue(result_scalar_ty, count)).toIntern();
2365923657 }
2366023658 return Air.internedToRef((try pt.intern(.{ .aggregate = .{
......@@ -23668,8 +23666,8 @@ fn zirBitCount(
2366823666 },
2366923667 .Int => {
2367023668 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));
23669 if (val.isUndef(zcu)) return pt.undefRef(result_scalar_ty);
23670 return pt.intRef(result_scalar_ty, comptimeOp(val, operand_ty, zcu));
2367323671 } else {
2367423672 try sema.requireRuntimeBlock(block, src, operand_src);
2367523673 return block.addTyOp(air_tag, result_scalar_ty, operand);
......@@ -23681,14 +23679,14 @@ fn zirBitCount(
2368123679
2368223680fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2368323681 const pt = sema.pt;
23684 const mod = pt.zcu;
23682 const zcu = pt.zcu;
2368523683 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2368623684 const src = block.nodeOffset(inst_data.src_node);
2368723685 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2368823686 const operand = try sema.resolveInst(inst_data.operand);
2368923687 const operand_ty = sema.typeOf(operand);
2369023688 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
23691 const bits = scalar_ty.intInfo(mod).bits;
23689 const bits = scalar_ty.intInfo(zcu).bits;
2369223690 if (bits % 8 != 0) {
2369323691 return sema.fail(
2369423692 block,
......@@ -23702,10 +23700,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2370223700 return Air.internedToRef(val.toIntern());
2370323701 }
2370423702
23705 switch (operand_ty.zigTypeTag(mod)) {
23703 switch (operand_ty.zigTypeTag(zcu)) {
2370623704 .Int => {
2370723705 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23708 if (val.isUndef(mod)) return pt.undefRef(operand_ty);
23706 if (val.isUndef(zcu)) return pt.undefRef(operand_ty);
2370923707 const result_val = try val.byteSwap(operand_ty, pt, sema.arena);
2371023708 return Air.internedToRef(result_val.toIntern());
2371123709 } else operand_src;
......@@ -23715,10 +23713,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2371523713 },
2371623714 .Vector => {
2371723715 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23718 if (val.isUndef(mod))
23716 if (val.isUndef(zcu))
2371923717 return pt.undefRef(operand_ty);
2372023718
23721 const vec_len = operand_ty.vectorLen(mod);
23719 const vec_len = operand_ty.vectorLen(zcu);
2372223720 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
2372323721 for (elems, 0..) |*elem, i| {
2372423722 const elem_val = try val.elemValue(pt, i);
......@@ -23750,11 +23748,11 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2375023748 }
2375123749
2375223750 const pt = sema.pt;
23753 const mod = pt.zcu;
23754 switch (operand_ty.zigTypeTag(mod)) {
23751 const zcu = pt.zcu;
23752 switch (operand_ty.zigTypeTag(zcu)) {
2375523753 .Int => {
2375623754 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23757 if (val.isUndef(mod)) return pt.undefRef(operand_ty);
23755 if (val.isUndef(zcu)) return pt.undefRef(operand_ty);
2375823756 const result_val = try val.bitReverse(operand_ty, pt, sema.arena);
2375923757 return Air.internedToRef(result_val.toIntern());
2376023758 } else operand_src;
......@@ -23764,10 +23762,10 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2376423762 },
2376523763 .Vector => {
2376623764 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23767 if (val.isUndef(mod))
23765 if (val.isUndef(zcu))
2376823766 return pt.undefRef(operand_ty);
2376923767
23770 const vec_len = operand_ty.vectorLen(mod);
23768 const vec_len = operand_ty.vectorLen(zcu);
2377123769 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
2377223770 for (elems, 0..) |*elem, i| {
2377323771 const elem_val = try val.elemValue(pt, i);
......@@ -23810,26 +23808,26 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2381023808 });
2381123809
2381223810 const pt = sema.pt;
23813 const mod = pt.zcu;
23814 const ip = &mod.intern_pool;
23811 const zcu = pt.zcu;
23812 const ip = &zcu.intern_pool;
2381523813 try ty.resolveLayout(pt);
23816 switch (ty.zigTypeTag(mod)) {
23814 switch (ty.zigTypeTag(zcu)) {
2381723815 .Struct => {},
2381823816 else => return sema.fail(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(pt)}),
2381923817 }
2382023818
23821 const field_index = if (ty.isTuple(mod)) blk: {
23819 const field_index = if (ty.isTuple(zcu)) blk: {
2382223820 if (field_name.eqlSlice("len", ip)) {
2382323821 return sema.fail(block, src, "no offset available for 'len' field of tuple", .{});
2382423822 }
2382523823 break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src);
2382623824 } else try sema.structFieldIndex(block, ty, field_name, rhs_src);
2382723825
23828 if (ty.structFieldIsComptime(field_index, mod)) {
23826 if (ty.structFieldIsComptime(field_index, zcu)) {
2382923827 return sema.fail(block, src, "no offset available for comptime field", .{});
2383023828 }
2383123829
23832 switch (ty.containerLayout(mod)) {
23830 switch (ty.containerLayout(zcu)) {
2383323831 .@"packed" => {
2383423832 var bit_sum: u64 = 0;
2383523833 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -23838,17 +23836,17 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2383823836 return bit_sum;
2383923837 }
2384023838 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
23841 bit_sum += field_ty.bitSize(pt);
23839 bit_sum += field_ty.bitSize(zcu);
2384223840 } else unreachable;
2384323841 },
23844 else => return ty.structFieldOffset(field_index, pt) * 8,
23842 else => return ty.structFieldOffset(field_index, zcu) * 8,
2384523843 }
2384623844}
2384723845
2384823846fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
2384923847 const pt = sema.pt;
23850 const mod = pt.zcu;
23851 switch (ty.zigTypeTag(mod)) {
23848 const zcu = pt.zcu;
23849 switch (ty.zigTypeTag(zcu)) {
2385223850 .Struct, .Enum, .Union, .Opaque => return,
2385323851 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(pt)}),
2385423852 }
......@@ -23857,8 +23855,8 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
2385723855/// Returns `true` if the type was a comptime_int.
2385823856fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
2385923857 const pt = sema.pt;
23860 const mod = pt.zcu;
23861 switch (try ty.zigTypeTagOrPoison(mod)) {
23858 const zcu = pt.zcu;
23859 switch (try ty.zigTypeTagOrPoison(zcu)) {
2386223860 .ComptimeInt => return true,
2386323861 .Int => return false,
2386423862 else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(pt)}),
......@@ -23872,9 +23870,9 @@ fn checkInvalidPtrIntArithmetic(
2387223870 ty: Type,
2387323871) CompileError!void {
2387423872 const pt = sema.pt;
23875 const mod = pt.zcu;
23876 switch (try ty.zigTypeTagOrPoison(mod)) {
23877 .Pointer => switch (ty.ptrSize(mod)) {
23873 const zcu = pt.zcu;
23874 switch (try ty.zigTypeTagOrPoison(zcu)) {
23875 .Pointer => switch (ty.ptrSize(zcu)) {
2387823876 .One, .Slice => return,
2387923877 .Many, .C => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"),
2388023878 },
......@@ -23908,8 +23906,8 @@ fn checkPtrOperand(
2390823906 ty: Type,
2390923907) CompileError!void {
2391023908 const pt = sema.pt;
23911 const mod = pt.zcu;
23912 switch (ty.zigTypeTag(mod)) {
23909 const zcu = pt.zcu;
23910 switch (ty.zigTypeTag(zcu)) {
2391323911 .Pointer => return,
2391423912 .Fn => {
2391523913 const msg = msg: {
......@@ -23926,7 +23924,7 @@ fn checkPtrOperand(
2392623924 };
2392723925 return sema.failWithOwnedErrorMsg(block, msg);
2392823926 },
23929 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
23927 .Optional => if (ty.childType(zcu).zigTypeTag(zcu) == .Pointer) return,
2393023928 else => {},
2393123929 }
2393223930 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});
......@@ -23940,9 +23938,9 @@ fn checkPtrType(
2394023938 allow_slice: bool,
2394123939) CompileError!void {
2394223940 const pt = sema.pt;
23943 const mod = pt.zcu;
23944 switch (ty.zigTypeTag(mod)) {
23945 .Pointer => if (allow_slice or !ty.isSlice(mod)) return,
23941 const zcu = pt.zcu;
23942 switch (ty.zigTypeTag(zcu)) {
23943 .Pointer => if (allow_slice or !ty.isSlice(zcu)) return,
2394623944 .Fn => {
2394723945 const msg = msg: {
2394823946 const msg = try sema.errMsg(
......@@ -23958,7 +23956,7 @@ fn checkPtrType(
2395823956 };
2395923957 return sema.failWithOwnedErrorMsg(block, msg);
2396023958 },
23961 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
23959 .Optional => if (ty.childType(zcu).zigTypeTag(zcu) == .Pointer) return,
2396223960 else => {},
2396323961 }
2396423962 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});
......@@ -23971,10 +23969,10 @@ fn checkVectorElemType(
2397123969 ty: Type,
2397223970) CompileError!void {
2397323971 const pt = sema.pt;
23974 const mod = pt.zcu;
23975 switch (ty.zigTypeTag(mod)) {
23972 const zcu = pt.zcu;
23973 switch (ty.zigTypeTag(zcu)) {
2397623974 .Int, .Float, .Bool => return,
23977 .Optional, .Pointer => if (ty.isPtrAtRuntime(mod)) return,
23975 .Optional, .Pointer => if (ty.isPtrAtRuntime(zcu)) return,
2397823976 else => {},
2397923977 }
2398023978 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{}'", .{ty.fmt(pt)});
......@@ -23987,8 +23985,8 @@ fn checkFloatType(
2398723985 ty: Type,
2398823986) CompileError!void {
2398923987 const pt = sema.pt;
23990 const mod = pt.zcu;
23991 switch (ty.zigTypeTag(mod)) {
23988 const zcu = pt.zcu;
23989 switch (ty.zigTypeTag(zcu)) {
2399223990 .ComptimeInt, .ComptimeFloat, .Float => {},
2399323991 else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(pt)}),
2399423992 }
......@@ -24001,10 +23999,10 @@ fn checkNumericType(
2400123999 ty: Type,
2400224000) CompileError!void {
2400324001 const pt = sema.pt;
24004 const mod = pt.zcu;
24005 switch (ty.zigTypeTag(mod)) {
24002 const zcu = pt.zcu;
24003 switch (ty.zigTypeTag(zcu)) {
2400624004 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
24007 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
24005 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
2400824006 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
2400924007 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),
2401024008 },
......@@ -24023,9 +24021,9 @@ fn checkAtomicPtrOperand(
2402324021 ptr_const: bool,
2402424022) CompileError!Air.Inst.Ref {
2402524023 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) {
24024 const zcu = pt.zcu;
24025 var diag: Zcu.AtomicPtrAlignmentDiagnostics = .{};
24026 const alignment = zcu.atomicPtrAlignment(elem_ty, &diag) catch |err| switch (err) {
2402924027 error.OutOfMemory => return error.OutOfMemory,
2403024028 error.FloatTooBig => return sema.fail(
2403124029 block,
......@@ -24056,8 +24054,8 @@ fn checkAtomicPtrOperand(
2405624054 };
2405724055
2405824056 const ptr_ty = sema.typeOf(ptr);
24059 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {
24060 .Pointer => ptr_ty.ptrInfo(mod),
24057 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(zcu)) {
24058 .Pointer => ptr_ty.ptrInfo(zcu),
2406124059 else => {
2406224060 const wanted_ptr_ty = try pt.ptrTypeSema(wanted_ptr_data);
2406324061 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
......@@ -24095,13 +24093,13 @@ fn checkIntOrVector(
2409524093 operand_src: LazySrcLoc,
2409624094) CompileError!Type {
2409724095 const pt = sema.pt;
24098 const mod = pt.zcu;
24096 const zcu = pt.zcu;
2409924097 const operand_ty = sema.typeOf(operand);
24100 switch (try operand_ty.zigTypeTagOrPoison(mod)) {
24098 switch (try operand_ty.zigTypeTagOrPoison(zcu)) {
2410124099 .Int => return operand_ty,
2410224100 .Vector => {
24103 const elem_ty = operand_ty.childType(mod);
24104 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
24101 const elem_ty = operand_ty.childType(zcu);
24102 switch (try elem_ty.zigTypeTagOrPoison(zcu)) {
2410524103 .Int => return elem_ty,
2410624104 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
2410724105 elem_ty.fmt(pt),
......@@ -24121,12 +24119,12 @@ fn checkIntOrVectorAllowComptime(
2412124119 operand_src: LazySrcLoc,
2412224120) CompileError!Type {
2412324121 const pt = sema.pt;
24124 const mod = pt.zcu;
24125 switch (try operand_ty.zigTypeTagOrPoison(mod)) {
24122 const zcu = pt.zcu;
24123 switch (try operand_ty.zigTypeTagOrPoison(zcu)) {
2412624124 .Int, .ComptimeInt => return operand_ty,
2412724125 .Vector => {
24128 const elem_ty = operand_ty.childType(mod);
24129 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
24126 const elem_ty = operand_ty.childType(zcu);
24127 switch (try elem_ty.zigTypeTagOrPoison(zcu)) {
2413024128 .Int, .ComptimeInt => return elem_ty,
2413124129 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
2413224130 elem_ty.fmt(pt),
......@@ -24162,12 +24160,12 @@ fn checkSimdBinOp(
2416224160 rhs_src: LazySrcLoc,
2416324161) CompileError!SimdBinOp {
2416424162 const pt = sema.pt;
24165 const mod = pt.zcu;
24163 const zcu = pt.zcu;
2416624164 const lhs_ty = sema.typeOf(uncasted_lhs);
2416724165 const rhs_ty = sema.typeOf(uncasted_rhs);
2416824166
2416924167 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;
24168 const vec_len: ?usize = if (lhs_ty.zigTypeTag(zcu) == .Vector) lhs_ty.vectorLen(zcu) else null;
2417124169 const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{
2417224170 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },
2417324171 });
......@@ -24181,7 +24179,7 @@ fn checkSimdBinOp(
2418124179 .lhs_val = try sema.resolveValue(lhs),
2418224180 .rhs_val = try sema.resolveValue(rhs),
2418324181 .result_ty = result_ty,
24184 .scalar_ty = result_ty.scalarType(mod),
24182 .scalar_ty = result_ty.scalarType(zcu),
2418524183 };
2418624184}
2418724185
......@@ -24195,9 +24193,9 @@ fn checkVectorizableBinaryOperands(
2419524193 rhs_src: LazySrcLoc,
2419624194) CompileError!void {
2419724195 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);
24196 const zcu = pt.zcu;
24197 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
24198 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
2420124199 if (lhs_zig_ty_tag != .Vector and rhs_zig_ty_tag != .Vector) return;
2420224200
2420324201 const lhs_is_vector = switch (lhs_zig_ty_tag) {
......@@ -24210,8 +24208,8 @@ fn checkVectorizableBinaryOperands(
2421024208 };
2421124209
2421224210 if (lhs_is_vector and rhs_is_vector) {
24213 const lhs_len = lhs_ty.arrayLen(mod);
24214 const rhs_len = rhs_ty.arrayLen(mod);
24211 const lhs_len = lhs_ty.arrayLen(zcu);
24212 const rhs_len = rhs_ty.arrayLen(zcu);
2421524213 if (lhs_len != rhs_len) {
2421624214 const msg = msg: {
2421724215 const msg = try sema.errMsg(src, "vector length mismatch", .{});
......@@ -24246,11 +24244,11 @@ fn resolveExportOptions(
2424624244 block: *Block,
2424724245 src: LazySrcLoc,
2424824246 zir_ref: Zir.Inst.Ref,
24249) CompileError!Module.Export.Options {
24247) CompileError!Zcu.Export.Options {
2425024248 const pt = sema.pt;
24251 const mod = pt.zcu;
24249 const zcu = pt.zcu;
2425224250 const gpa = sema.gpa;
24253 const ip = &mod.intern_pool;
24251 const ip = &zcu.intern_pool;
2425424252 const export_options_ty = try pt.getBuiltinType("ExportOptions");
2425524253 const air_ref = try sema.resolveInst(zir_ref);
2425624254 const options = try sema.coerce(block, export_options_ty, air_ref, src);
......@@ -24269,13 +24267,13 @@ fn resolveExportOptions(
2426924267 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
2427024268 .needed_comptime_reason = "linkage of exported value must be comptime-known",
2427124269 });
24272 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
24270 const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val);
2427324271
2427424272 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src);
2427524273 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
2427624274 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2427724275 });
24278 const section = if (section_opt_val.optionalValue(mod)) |section_val|
24276 const section = if (section_opt_val.optionalValue(zcu)) |section_val|
2427924277 try sema.toConstString(block, section_src, Air.internedToRef(section_val.toIntern()), .{
2428024278 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2428124279 })
......@@ -24286,7 +24284,7 @@ fn resolveExportOptions(
2428624284 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
2428724285 .needed_comptime_reason = "visibility of exported value must be comptime-known",
2428824286 });
24289 const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val);
24287 const visibility = zcu.toEnum(std.builtin.SymbolVisibility, visibility_val);
2429024288
2429124289 if (name.len < 1) {
2429224290 return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});
......@@ -24349,7 +24347,7 @@ fn zirCmpxchg(
2434924347 extended: Zir.Inst.Extended.InstData,
2435024348) CompileError!Air.Inst.Ref {
2435124349 const pt = sema.pt;
24352 const mod = pt.zcu;
24350 const zcu = pt.zcu;
2435324351 const extra = sema.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
2435424352 const air_tag: Air.Inst.Tag = switch (extended.small) {
2435524353 0 => .cmpxchg_weak,
......@@ -24367,7 +24365,7 @@ fn zirCmpxchg(
2436724365 // zig fmt: on
2436824366 const expected_value = try sema.resolveInst(extra.expected_value);
2436924367 const elem_ty = sema.typeOf(expected_value);
24370 if (elem_ty.zigTypeTag(mod) == .Float) {
24368 if (elem_ty.zigTypeTag(zcu) == .Float) {
2437124369 return sema.fail(
2437224370 block,
2437324371 elem_ty_src,
......@@ -24411,7 +24409,7 @@ fn zirCmpxchg(
2441124409 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
2441224410 if (try sema.resolveValue(expected_value)) |expected_val| {
2441324411 if (try sema.resolveValue(new_value)) |new_val| {
24414 if (expected_val.isUndef(mod) or new_val.isUndef(mod)) {
24412 if (expected_val.isUndef(zcu) or new_val.isUndef(zcu)) {
2441524413 // TODO: this should probably cause the memory stored at the pointer
2441624414 // to become undef as well
2441724415 return pt.undefRef(result_ty);
......@@ -24420,7 +24418,7 @@ fn zirCmpxchg(
2442024418 const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src;
2442124419 const result_val = try pt.intern(.{ .opt = .{
2442224420 .ty = result_ty.toIntern(),
24423 .val = if (stored_val.eql(expected_val, elem_ty, mod)) blk: {
24421 .val = if (stored_val.eql(expected_val, elem_ty, zcu)) blk: {
2442424422 try sema.storePtr(block, src, ptr, new_value);
2442524423 break :blk .none;
2442624424 } else stored_val.toIntern(),
......@@ -24450,16 +24448,16 @@ fn zirCmpxchg(
2445024448
2445124449fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2445224450 const pt = sema.pt;
24453 const mod = pt.zcu;
24451 const zcu = pt.zcu;
2445424452 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2445524453 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2445624454 const src = block.nodeOffset(inst_data.src_node);
2445724455 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2445824456 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");
2445924457
24460 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(pt)});
24458 if (!dest_ty.isVector(zcu)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(pt)});
2446124459
24462 if (!dest_ty.hasRuntimeBits(pt)) {
24460 if (!dest_ty.hasRuntimeBits(zcu)) {
2446324461 const empty_aggregate = try pt.intern(.{ .aggregate = .{
2446424462 .ty = dest_ty.toIntern(),
2446524463 .storage = .{ .elems = &[_]InternPool.Index{} },
......@@ -24468,10 +24466,10 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2446824466 }
2446924467
2447024468 const operand = try sema.resolveInst(extra.rhs);
24471 const scalar_ty = dest_ty.childType(mod);
24469 const scalar_ty = dest_ty.childType(zcu);
2447224470 const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src);
2447324471 if (try sema.resolveValue(scalar)) |scalar_val| {
24474 if (scalar_val.isUndef(mod)) return pt.undefRef(dest_ty);
24472 if (scalar_val.isUndef(zcu)) return pt.undefRef(dest_ty);
2447524473 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());
2447624474 }
2447724475
......@@ -24490,23 +24488,23 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2449024488 const operand = try sema.resolveInst(extra.rhs);
2449124489 const operand_ty = sema.typeOf(operand);
2449224490 const pt = sema.pt;
24493 const mod = pt.zcu;
24491 const zcu = pt.zcu;
2449424492
24495 if (operand_ty.zigTypeTag(mod) != .Vector) {
24493 if (operand_ty.zigTypeTag(zcu) != .Vector) {
2449624494 return sema.fail(block, operand_src, "expected vector, found '{}'", .{operand_ty.fmt(pt)});
2449724495 }
2449824496
24499 const scalar_ty = operand_ty.childType(mod);
24497 const scalar_ty = operand_ty.childType(zcu);
2450024498
2450124499 // Type-check depending on operation.
2450224500 switch (operation) {
24503 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(mod)) {
24501 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) {
2450424502 .Int, .Bool => {},
2450524503 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{}'", .{
2450624504 @tagName(operation), operand_ty.fmt(pt),
2450724505 }),
2450824506 },
24509 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(mod)) {
24507 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
2451024508 .Int, .Float => {},
2451124509 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{}'", .{
2451224510 @tagName(operation), operand_ty.fmt(pt),
......@@ -24514,7 +24512,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2451424512 },
2451524513 }
2451624514
24517 const vec_len = operand_ty.vectorLen(mod);
24515 const vec_len = operand_ty.vectorLen(zcu);
2451824516 if (vec_len == 0) {
2451924517 // TODO re-evaluate if we should introduce a "neutral value" for some operations,
2452024518 // e.g. zero for add and one for mul.
......@@ -24522,7 +24520,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2452224520 }
2452324521
2452424522 if (try sema.resolveValue(operand)) |operand_val| {
24525 if (operand_val.isUndef(mod)) return pt.undefRef(scalar_ty);
24523 if (operand_val.isUndef(zcu)) return pt.undefRef(scalar_ty);
2452624524
2452724525 var accum: Value = try operand_val.elemValue(pt, 0);
2452824526 var i: u32 = 1;
......@@ -24532,8 +24530,8 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2453224530 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, pt),
2453324531 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, pt),
2453424532 .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),
24533 .Min => accum = accum.numberMin(elem_val, zcu),
24534 .Max => accum = accum.numberMax(elem_val, zcu),
2453724535 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),
2453824536 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, pt),
2453924537 }
......@@ -24553,7 +24551,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2455324551
2455424552fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2455524553 const pt = sema.pt;
24556 const mod = pt.zcu;
24554 const zcu = pt.zcu;
2455724555 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2455824556 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
2455924557 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
......@@ -24566,8 +24564,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2456624564 var mask = try sema.resolveInst(extra.mask);
2456724565 var mask_ty = sema.typeOf(mask);
2456824566
24569 const mask_len = switch (sema.typeOf(mask).zigTypeTag(mod)) {
24570 .Array, .Vector => sema.typeOf(mask).arrayLen(mod),
24567 const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) {
24568 .Array, .Vector => sema.typeOf(mask).arrayLen(zcu),
2457124569 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(pt)}),
2457224570 };
2457324571 mask_ty = try pt.vectorType(.{
......@@ -24592,6 +24590,7 @@ fn analyzeShuffle(
2459224590 mask_len: u32,
2459324591) CompileError!Air.Inst.Ref {
2459424592 const pt = sema.pt;
24593 const zcu = pt.zcu;
2459524594 const a_src = block.builtinCallArgSrc(src_node, 1);
2459624595 const b_src = block.builtinCallArgSrc(src_node, 2);
2459724596 const mask_src = block.builtinCallArgSrc(src_node, 3);
......@@ -24603,16 +24602,16 @@ fn analyzeShuffle(
2460324602 .child = elem_ty.toIntern(),
2460424603 });
2460524604
24606 const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(pt.zcu)) {
24607 .Array, .Vector => sema.typeOf(a).arrayLen(pt.zcu),
24605 const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(zcu)) {
24606 .Array, .Vector => sema.typeOf(a).arrayLen(zcu),
2460824607 .Undefined => null,
2460924608 else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{
2461024609 elem_ty.fmt(pt),
2461124610 sema.typeOf(a).fmt(pt),
2461224611 }),
2461324612 };
24614 const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(pt.zcu)) {
24615 .Array, .Vector => sema.typeOf(b).arrayLen(pt.zcu),
24613 const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(zcu)) {
24614 .Array, .Vector => sema.typeOf(b).arrayLen(zcu),
2461624615 .Undefined => null,
2461724616 else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{
2461824617 elem_ty.fmt(pt),
......@@ -24644,9 +24643,9 @@ fn analyzeShuffle(
2464424643
2464524644 for (0..@intCast(mask_len)) |i| {
2464624645 const elem = try mask.elemValue(pt, i);
24647 if (elem.isUndef(pt.zcu)) continue;
24646 if (elem.isUndef(zcu)) continue;
2464824647 const elem_resolved = try sema.resolveLazyValue(elem);
24649 const int = elem_resolved.toSignedInt(pt);
24648 const int = elem_resolved.toSignedInt(zcu);
2465024649 var unsigned: u32 = undefined;
2465124650 var chosen: u32 = undefined;
2465224651 if (int >= 0) {
......@@ -24681,11 +24680,11 @@ fn analyzeShuffle(
2468124680 const values = try sema.arena.alloc(InternPool.Index, mask_len);
2468224681 for (values, 0..) |*value, i| {
2468324682 const mask_elem_val = try mask.elemValue(pt, i);
24684 if (mask_elem_val.isUndef(pt.zcu)) {
24683 if (mask_elem_val.isUndef(zcu)) {
2468524684 value.* = try pt.intern(.{ .undef = elem_ty.toIntern() });
2468624685 continue;
2468724686 }
24688 const int = mask_elem_val.toSignedInt(pt);
24687 const int = mask_elem_val.toSignedInt(zcu);
2468924688 const unsigned: u32 = @intCast(if (int >= 0) int else ~int);
2469024689 values[i] = (try (if (int >= 0) a_val else b_val).elemValue(pt, unsigned)).toIntern();
2469124690 }
......@@ -24743,7 +24742,7 @@ fn analyzeShuffle(
2474324742
2474424743fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2474524744 const pt = sema.pt;
24746 const mod = pt.zcu;
24745 const zcu = pt.zcu;
2474724746 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
2474824747
2474924748 const src = block.nodeOffset(extra.node);
......@@ -24757,8 +24756,8 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2475724756 const pred_uncoerced = try sema.resolveInst(extra.pred);
2475824757 const pred_ty = sema.typeOf(pred_uncoerced);
2475924758
24760 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) {
24761 .Vector, .Array => pred_ty.arrayLen(mod),
24759 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(zcu)) {
24760 .Vector, .Array => pred_ty.arrayLen(zcu),
2476224761 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(pt)}),
2476324762 };
2476424763 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));
......@@ -24781,13 +24780,13 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2478124780 const maybe_b = try sema.resolveValue(b);
2478224781
2478324782 const runtime_src = if (maybe_pred) |pred_val| rs: {
24784 if (pred_val.isUndef(mod)) return pt.undefRef(vec_ty);
24783 if (pred_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2478524784
2478624785 if (maybe_a) |a_val| {
24787 if (a_val.isUndef(mod)) return pt.undefRef(vec_ty);
24786 if (a_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2478824787
2478924788 if (maybe_b) |b_val| {
24790 if (b_val.isUndef(mod)) return pt.undefRef(vec_ty);
24789 if (b_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2479124790
2479224791 const elems = try sema.gpa.alloc(InternPool.Index, vec_len);
2479324792 defer sema.gpa.free(elems);
......@@ -24806,16 +24805,16 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2480624805 }
2480724806 } else {
2480824807 if (maybe_b) |b_val| {
24809 if (b_val.isUndef(mod)) return pt.undefRef(vec_ty);
24808 if (b_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2481024809 }
2481124810 break :rs a_src;
2481224811 }
2481324812 } else rs: {
2481424813 if (maybe_a) |a_val| {
24815 if (a_val.isUndef(mod)) return pt.undefRef(vec_ty);
24814 if (a_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2481624815 }
2481724816 if (maybe_b) |b_val| {
24818 if (b_val.isUndef(mod)) return pt.undefRef(vec_ty);
24817 if (b_val.isUndef(zcu)) return pt.undefRef(vec_ty);
2481924818 }
2482024819 break :rs pred_src;
2482124820 };
......@@ -24882,7 +24881,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2488224881
2488324882fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2488424883 const pt = sema.pt;
24885 const mod = pt.zcu;
24884 const zcu = pt.zcu;
2488624885 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2488724886 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
2488824887 const src = block.nodeOffset(inst_data.src_node);
......@@ -24899,7 +24898,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2489924898 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
2490024899 const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation);
2490124900
24902 switch (elem_ty.zigTypeTag(mod)) {
24901 switch (elem_ty.zigTypeTag(zcu)) {
2490324902 .Enum => if (op != .Xchg) {
2490424903 return sema.fail(block, op_src, "@atomicRmw with enum only allowed with .Xchg", .{});
2490524904 },
......@@ -24939,12 +24938,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2493924938 .Xchg => operand_val,
2494024939 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),
2494124940 .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),
24941 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, pt ),
24942 .Nand => try stored_val.bitwiseNand (operand_val, elem_ty, sema.arena, pt ),
24943 .Or => try stored_val.bitwiseOr (operand_val, elem_ty, sema.arena, pt ),
24944 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, pt ),
24945 .Max => stored_val.numberMax (operand_val, zcu),
24946 .Min => stored_val.numberMin (operand_val, zcu),
2494824947 // zig fmt: on
2494924948 };
2495024949 try sema.storePtrVal(block, src, ptr_val, new_val, elem_ty);
......@@ -25021,19 +25020,19 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2502125020 const maybe_mulend2 = try sema.resolveValue(mulend2);
2502225021 const maybe_addend = try sema.resolveValue(addend);
2502325022 const pt = sema.pt;
25024 const mod = pt.zcu;
25023 const zcu = pt.zcu;
2502525024
25026 switch (ty.scalarType(mod).zigTypeTag(mod)) {
25025 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
2502725026 .ComptimeFloat, .Float => {},
2502825027 else => return sema.fail(block, src, "expected vector of floats or float type, found '{}'", .{ty.fmt(pt)}),
2502925028 }
2503025029
2503125030 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {
2503225031 if (maybe_mulend2) |mulend2_val| {
25033 if (mulend2_val.isUndef(mod)) return pt.undefRef(ty);
25032 if (mulend2_val.isUndef(zcu)) return pt.undefRef(ty);
2503425033
2503525034 if (maybe_addend) |addend_val| {
25036 if (addend_val.isUndef(mod)) return pt.undefRef(ty);
25035 if (addend_val.isUndef(zcu)) return pt.undefRef(ty);
2503725036 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, pt);
2503825037 return Air.internedToRef(result_val.toIntern());
2503925038 } else {
......@@ -25041,16 +25040,16 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2504125040 }
2504225041 } else {
2504325042 if (maybe_addend) |addend_val| {
25044 if (addend_val.isUndef(mod)) return pt.undefRef(ty);
25043 if (addend_val.isUndef(zcu)) return pt.undefRef(ty);
2504525044 }
2504625045 break :rs mulend2_src;
2504725046 }
2504825047 } else rs: {
2504925048 if (maybe_mulend2) |mulend2_val| {
25050 if (mulend2_val.isUndef(mod)) return pt.undefRef(ty);
25049 if (mulend2_val.isUndef(zcu)) return pt.undefRef(ty);
2505125050 }
2505225051 if (maybe_addend) |addend_val| {
25053 if (addend_val.isUndef(mod)) return pt.undefRef(ty);
25052 if (addend_val.isUndef(zcu)) return pt.undefRef(ty);
2505425053 }
2505525054 break :rs mulend1_src;
2505625055 };
......@@ -25073,7 +25072,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2507325072 defer tracy.end();
2507425073
2507525074 const pt = sema.pt;
25076 const mod = pt.zcu;
25075 const zcu = pt.zcu;
2507725076 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2507825077 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2507925078 const func_src = block.builtinCallArgSrc(inst_data.src_node, 1);
......@@ -25089,7 +25088,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2508925088 const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{
2509025089 .needed_comptime_reason = "call modifier must be comptime-known",
2509125090 });
25092 var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val);
25091 var modifier = zcu.toEnum(std.builtin.CallModifier, modifier_val);
2509325092 switch (modifier) {
2509425093 // These can be upgraded to comptime or nosuspend calls.
2509525094 .auto, .never_tail, .no_async => {
......@@ -25135,11 +25134,11 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2513525134 const args = try sema.resolveInst(extra.args);
2513625135
2513725136 const args_ty = sema.typeOf(args);
25138 if (!args_ty.isTuple(mod) and args_ty.toIntern() != .empty_struct_type) {
25137 if (!args_ty.isTuple(zcu) and args_ty.toIntern() != .empty_struct_type) {
2513925138 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(pt)});
2514025139 }
2514125140
25142 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));
25141 const resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(zcu));
2514325142 for (resolved_args, 0..) |*resolved, i| {
2514425143 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty);
2514525144 }
......@@ -25219,7 +25218,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2521925218 var actual_parent_ptr_info: InternPool.Key.PtrType = .{
2522025219 .child = parent_ty.toIntern(),
2522125220 .flags = .{
25222 .alignment = try parent_ptr_ty.ptrAlignmentAdvanced(pt, .sema),
25221 .alignment = try parent_ptr_ty.ptrAlignmentSema(pt),
2522325222 .is_const = field_ptr_info.flags.is_const,
2522425223 .is_volatile = field_ptr_info.flags.is_volatile,
2522525224 .is_allowzero = field_ptr_info.flags.is_allowzero,
......@@ -25227,11 +25226,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2522725226 },
2522825227 .packed_offset = parent_ptr_info.packed_offset,
2522925228 };
25230 const field_ty = parent_ty.structFieldType(field_index, zcu);
25229 const field_ty = parent_ty.fieldType(field_index, zcu);
2523125230 var actual_field_ptr_info: InternPool.Key.PtrType = .{
2523225231 .child = field_ty.toIntern(),
2523325232 .flags = .{
25234 .alignment = try field_ptr_ty.ptrAlignmentAdvanced(pt, .sema),
25233 .alignment = try field_ptr_ty.ptrAlignmentSema(pt),
2523525234 .is_const = field_ptr_info.flags.is_const,
2523625235 .is_volatile = field_ptr_info.flags.is_volatile,
2523725236 .is_allowzero = field_ptr_info.flags.is_allowzero,
......@@ -25242,13 +25241,18 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2524225241 switch (parent_ty.containerLayout(zcu)) {
2524325242 .auto => {
2524425243 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(
25245 if (zcu.typeToStruct(parent_ty)) |struct_obj| try pt.structFieldAlignmentAdvanced(
25246 struct_obj.fieldAlign(ip, field_index),
25247 field_ty,
25248 struct_obj.layout,
25249 .sema,
25250 ) else if (zcu.typeToUnion(parent_ty)) |union_obj|
25251 try pt.unionFieldNormalAlignmentAdvanced(union_obj, field_index, .sema)
25244 if (zcu.typeToStruct(parent_ty)) |struct_obj|
25245 try field_ty.structFieldAlignmentSema(
25246 struct_obj.fieldAlign(ip, field_index),
25247 struct_obj.layout,
25248 pt,
25249 )
25250 else if (zcu.typeToUnion(parent_ty)) |union_obj|
25251 try field_ty.unionFieldAlignmentSema(
25252 union_obj.fieldAlign(ip, field_index),
25253 union_obj.flagsUnordered(ip).layout,
25254 pt,
25255 )
2525225256 else
2525325257 actual_field_ptr_info.flags.alignment,
2525425258 );
......@@ -25257,7 +25261,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2525725261 actual_field_ptr_info.packed_offset = .{ .bit_offset = 0, .host_size = 0 };
2525825262 },
2525925263 .@"extern" => {
25260 const field_offset = parent_ty.structFieldOffset(field_index, pt);
25264 const field_offset = parent_ty.structFieldOffset(field_index, zcu);
2526125265 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(if (field_offset > 0)
2526225266 Alignment.fromLog2Units(@ctz(field_offset))
2526325267 else
......@@ -25287,7 +25291,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2528725291 .Struct => switch (parent_ty.containerLayout(zcu)) {
2528825292 .auto => {},
2528925293 .@"extern" => {
25290 const byte_offset = parent_ty.structFieldOffset(field_index, pt);
25294 const byte_offset = parent_ty.structFieldOffset(field_index, zcu);
2529125295 const parent_ptr_val = try sema.ptrSubtract(block, field_ptr_src, field_ptr_val, byte_offset, actual_parent_ptr_ty);
2529225296 break :result Air.internedToRef(parent_ptr_val.toIntern());
2529325297 },
......@@ -25428,7 +25432,7 @@ fn analyzeMinMax(
2542825432 assert(operands.len == operand_srcs.len);
2542925433 assert(operands.len > 0);
2543025434 const pt = sema.pt;
25431 const mod = pt.zcu;
25435 const zcu = pt.zcu;
2543225436
2543325437 if (operands.len == 1) return operands[0];
2543425438
......@@ -25466,20 +25470,20 @@ fn analyzeMinMax(
2546625470 switch (bounds_status) {
2546725471 .unknown, .defined => refine_bounds: {
2546825472 const ty = sema.typeOf(operand);
25469 if (!ty.scalarType(mod).isInt(mod) and !ty.scalarType(mod).eql(Type.comptime_int, mod)) {
25473 if (!ty.scalarType(zcu).isInt(zcu) and !ty.scalarType(zcu).eql(Type.comptime_int, zcu)) {
2547025474 bounds_status = .non_integral;
2547125475 break :refine_bounds;
2547225476 }
2547325477 const scalar_bounds: ?[2]Value = bounds: {
25474 if (!ty.isVector(mod)) break :bounds try uncoerced_val.intValueBounds(pt);
25478 if (!ty.isVector(zcu)) break :bounds try uncoerced_val.intValueBounds(pt);
2547525479 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));
25480 const len = try sema.usizeCast(block, src, ty.vectorLen(zcu));
2547725481 for (1..len) |i| {
2547825482 const elem = try uncoerced_val.elemValue(pt, i);
2547925483 const elem_bounds = try elem.intValueBounds(pt) orelse break :bounds null;
2548025484 cur_bounds = .{
25481 Value.numberMin(elem_bounds[0], cur_bounds[0], pt),
25482 Value.numberMax(elem_bounds[1], cur_bounds[1], pt),
25485 Value.numberMin(elem_bounds[0], cur_bounds[0], zcu),
25486 Value.numberMax(elem_bounds[1], cur_bounds[1], zcu),
2548325487 };
2548425488 }
2548525489 break :bounds cur_bounds;
......@@ -25490,8 +25494,8 @@ fn analyzeMinMax(
2549025494 cur_max_scalar = bounds[1];
2549125495 bounds_status = .defined;
2549225496 } else {
25493 cur_min_scalar = opFunc(cur_min_scalar, bounds[0], pt);
25494 cur_max_scalar = opFunc(cur_max_scalar, bounds[1], pt);
25497 cur_min_scalar = opFunc(cur_min_scalar, bounds[0], zcu);
25498 cur_max_scalar = opFunc(cur_max_scalar, bounds[1], zcu);
2549525499 }
2549625500 }
2549725501 },
......@@ -25509,7 +25513,7 @@ fn analyzeMinMax(
2550925513 const operand_val = try sema.resolveLazyValue(simd_op.rhs_val.?); // we checked the operand was resolvable above
2551025514
2551125515 const vec_len = simd_op.len orelse {
25512 const result_val = opFunc(cur_val, operand_val, pt);
25516 const result_val = opFunc(cur_val, operand_val, zcu);
2551325517 cur_minmax = Air.internedToRef(result_val.toIntern());
2551425518 continue;
2551525519 };
......@@ -25517,7 +25521,7 @@ fn analyzeMinMax(
2551725521 for (elems, 0..) |*elem, i| {
2551825522 const lhs_elem_val = try cur_val.elemValue(pt, i);
2551925523 const rhs_elem_val = try operand_val.elemValue(pt, i);
25520 const uncoerced_elem = opFunc(lhs_elem_val, rhs_elem_val, pt);
25524 const uncoerced_elem = opFunc(lhs_elem_val, rhs_elem_val, zcu);
2552125525 elem.* = (try pt.getCoerced(uncoerced_elem, simd_op.scalar_ty)).toIntern();
2552225526 }
2552325527 cur_minmax = Air.internedToRef((try pt.intern(.{ .aggregate = .{
......@@ -25537,19 +25541,19 @@ fn analyzeMinMax(
2553725541 const val = (try sema.resolveValue(ct_minmax_ref)).?;
2553825542 const orig_ty = sema.typeOf(ct_minmax_ref);
2553925543
25540 if (opt_runtime_idx == null and orig_ty.scalarType(mod).eql(Type.comptime_int, mod)) {
25544 if (opt_runtime_idx == null and orig_ty.scalarType(zcu).eql(Type.comptime_int, zcu)) {
2554125545 // If all arguments were `comptime_int`, and there are no runtime args, we'll preserve that type
2554225546 break :refine;
2554325547 }
2554425548
2554525549 // We can't refine float types
25546 if (orig_ty.scalarType(mod).isAnyFloat()) break :refine;
25550 if (orig_ty.scalarType(zcu).isAnyFloat()) break :refine;
2554725551
2554825552 assert(bounds_status == .defined); // there was a non-comptime-int integral comptime-known arg
2554925553
2555025554 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),
25555 const refined_ty = if (orig_ty.isVector(zcu)) try pt.vectorType(.{
25556 .len = orig_ty.vectorLen(zcu),
2555325557 .child = refined_scalar_ty.toIntern(),
2555425558 }) else refined_scalar_ty;
2555525559
......@@ -25570,7 +25574,7 @@ fn analyzeMinMax(
2557025574 // If the comptime-known part is undef we can avoid emitting actual instructions later
2557125575 const known_undef = if (cur_minmax) |operand| blk: {
2557225576 const val = (try sema.resolveValue(operand)).?;
25573 break :blk val.isUndef(mod);
25577 break :blk val.isUndef(zcu);
2557425578 } else false;
2557525579
2557625580 if (cur_minmax == null) {
......@@ -25580,8 +25584,8 @@ fn analyzeMinMax(
2558025584 cur_minmax = operands[0];
2558125585 cur_minmax_src = runtime_src;
2558225586 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)) {
25587 const scalar_ty = sema.typeOf(cur_minmax.?).scalarType(zcu);
25588 if (scalar_ty.isInt(zcu)) {
2558525589 cur_min_scalar = try scalar_ty.minInt(pt, scalar_ty);
2558625590 cur_max_scalar = try scalar_ty.maxInt(pt, scalar_ty);
2558725591 bounds_status = .defined;
......@@ -25605,7 +25609,7 @@ fn analyzeMinMax(
2560525609 // Compute the bounds of this type
2560625610 switch (bounds_status) {
2560725611 .unknown, .defined => refine_bounds: {
25608 const scalar_ty = sema.typeOf(rhs).scalarType(mod);
25612 const scalar_ty = sema.typeOf(rhs).scalarType(zcu);
2560925613 if (scalar_ty.isAnyFloat()) {
2561025614 bounds_status = .non_integral;
2561125615 break :refine_bounds;
......@@ -25617,8 +25621,8 @@ fn analyzeMinMax(
2561725621 cur_max_scalar = scalar_max;
2561825622 bounds_status = .defined;
2561925623 } else {
25620 cur_min_scalar = opFunc(cur_min_scalar, scalar_min, pt);
25621 cur_max_scalar = opFunc(cur_max_scalar, scalar_max, pt);
25624 cur_min_scalar = opFunc(cur_min_scalar, scalar_min, zcu);
25625 cur_max_scalar = opFunc(cur_max_scalar, scalar_max, zcu);
2562225626 }
2562325627 },
2562425628 .non_integral => {},
......@@ -25627,18 +25631,18 @@ fn analyzeMinMax(
2562725631
2562825632 // Finally, refine the type based on the known bounds.
2562925633 const unrefined_ty = sema.typeOf(cur_minmax.?);
25630 if (unrefined_ty.scalarType(mod).isAnyFloat()) {
25634 if (unrefined_ty.scalarType(zcu).isAnyFloat()) {
2563125635 // We can't refine floats, so we're done.
2563225636 return cur_minmax.?;
2563325637 }
2563425638 assert(bounds_status == .defined); // there were integral runtime operands
2563525639 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),
25640 const refined_ty = if (unrefined_ty.isVector(zcu)) try pt.vectorType(.{
25641 .len = unrefined_ty.vectorLen(zcu),
2563825642 .child = refined_scalar_ty.toIntern(),
2563925643 }) else refined_scalar_ty;
2564025644
25641 if (!refined_ty.eql(unrefined_ty, mod)) {
25645 if (!refined_ty.eql(unrefined_ty, zcu)) {
2564225646 // We've reduced the type - cast the result down
2564325647 return block.addTyOp(.intcast, refined_ty, cur_minmax.?);
2564425648 }
......@@ -25648,9 +25652,9 @@ fn analyzeMinMax(
2564825652
2564925653fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !Air.Inst.Ref {
2565025654 const pt = sema.pt;
25651 const mod = pt.zcu;
25655 const zcu = pt.zcu;
2565225656 const ptr_ty = sema.typeOf(ptr);
25653 const info = ptr_ty.ptrInfo(mod);
25657 const info = ptr_ty.ptrInfo(zcu);
2565425658 if (info.flags.size == .One) {
2565525659 // Already an array pointer.
2565625660 return ptr;
......@@ -25670,7 +25674,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
2567025674 },
2567125675 });
2567225676 const non_slice_ptr = if (info.flags.size == .Slice)
25673 try block.addTyOp(.slice_ptr, ptr_ty.slicePtrFieldType(mod), ptr)
25677 try block.addTyOp(.slice_ptr, ptr_ty.slicePtrFieldType(zcu), ptr)
2567425678 else
2567525679 ptr;
2567625680 return block.addBitCast(new_ty, non_slice_ptr);
......@@ -25689,10 +25693,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2568925693 const dest_len = try indexablePtrLenOrNone(sema, block, dest_src, dest_ptr);
2569025694 const src_len = try indexablePtrLenOrNone(sema, block, src_src, src_ptr);
2569125695 const pt = sema.pt;
25692 const mod = pt.zcu;
25693 const target = mod.getTarget();
25696 const zcu = pt.zcu;
25697 const target = zcu.getTarget();
2569425698
25695 if (dest_ty.isConstPtr(mod)) {
25699 if (dest_ty.isConstPtr(zcu)) {
2569625700 return sema.fail(block, dest_src, "cannot memcpy to constant pointer", .{});
2569725701 }
2569825702
......@@ -25755,7 +25759,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2575525759 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {
2575625760 if (!sema.isComptimeMutablePtr(dest_ptr_val)) break :rs dest_src;
2575725761 if (try sema.resolveDefinedValue(block, src_src, src_ptr)) |_| {
25758 const len_u64 = (try len_val.?.getUnsignedIntAdvanced(pt, .sema)).?;
25762 const len_u64 = try len_val.?.toUnsignedIntSema(pt);
2575925763 const len = try sema.usizeCast(block, dest_src, len_u64);
2576025764 for (0..len) |i| {
2576125765 const elem_index = try pt.intRef(Type.usize, i);
......@@ -25798,12 +25802,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2579825802 // lowering. The AIR instruction requires pointers with element types of
2579925803 // equal ABI size.
2580025804
25801 if (dest_ty.zigTypeTag(mod) != .Pointer or src_ty.zigTypeTag(mod) != .Pointer) {
25805 if (dest_ty.zigTypeTag(zcu) != .Pointer or src_ty.zigTypeTag(zcu) != .Pointer) {
2580225806 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the source or destination iterable is a tuple", .{});
2580325807 }
2580425808
25805 const dest_elem_ty = dest_ty.elemType2(mod);
25806 const src_elem_ty = src_ty.elemType2(mod);
25809 const dest_elem_ty = dest_ty.elemType2(zcu);
25810 const src_elem_ty = src_ty.elemType2(zcu);
2580725811 if (.ok != try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, true, target, dest_src, src_src, null)) {
2580825812 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the element types have different ABI sizes", .{});
2580925813 }
......@@ -25827,7 +25831,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2582725831 // Change the src from slice to a many pointer, to avoid multiple ptr
2582825832 // slice extractions in AIR instructions.
2582925833 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25830 if (new_src_ptr_ty.isSlice(mod)) {
25834 if (new_src_ptr_ty.isSlice(zcu)) {
2583125835 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
2583225836 }
2583325837 } else if (dest_len == .none and len_val == null) {
......@@ -25835,7 +25839,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2583525839 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
2583625840 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);
2583725841 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25838 if (new_src_ptr_ty.isSlice(mod)) {
25842 if (new_src_ptr_ty.isSlice(zcu)) {
2583925843 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
2584025844 }
2584125845 }
......@@ -25854,10 +25858,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2585425858 // Extract raw pointer from dest slice. The AIR instructions could support them, but
2585525859 // it would cause redundant machine code instructions.
2585625860 const new_dest_ptr_ty = sema.typeOf(new_dest_ptr);
25857 const raw_dest_ptr = if (new_dest_ptr_ty.isSlice(mod))
25861 const raw_dest_ptr = if (new_dest_ptr_ty.isSlice(zcu))
2585825862 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;
25863 else if (new_dest_ptr_ty.ptrSize(zcu) == .One) ptr: {
25864 var dest_manyptr_ty_key = zcu.intern_pool.indexToKey(new_dest_ptr_ty.toIntern()).ptr_type;
2586125865 assert(dest_manyptr_ty_key.flags.size == .One);
2586225866 dest_manyptr_ty_key.child = dest_elem_ty.toIntern();
2586325867 dest_manyptr_ty_key.flags.size = .Many;
......@@ -25865,10 +25869,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2586525869 } else new_dest_ptr;
2586625870
2586725871 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25868 const raw_src_ptr = if (new_src_ptr_ty.isSlice(mod))
25872 const raw_src_ptr = if (new_src_ptr_ty.isSlice(zcu))
2586925873 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;
25874 else if (new_src_ptr_ty.ptrSize(zcu) == .One) ptr: {
25875 var src_manyptr_ty_key = zcu.intern_pool.indexToKey(new_src_ptr_ty.toIntern()).ptr_type;
2587225876 assert(src_manyptr_ty_key.flags.size == .One);
2587325877 src_manyptr_ty_key.child = src_elem_ty.toIntern();
2587425878 src_manyptr_ty_key.flags.size = .Many;
......@@ -25896,9 +25900,9 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2589625900
2589725901fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
2589825902 const pt = sema.pt;
25899 const mod = pt.zcu;
25903 const zcu = pt.zcu;
2590025904 const gpa = sema.gpa;
25901 const ip = &mod.intern_pool;
25905 const ip = &zcu.intern_pool;
2590225906 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2590325907 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2590425908 const src = block.nodeOffset(inst_data.src_node);
......@@ -25909,17 +25913,17 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2590925913 const dest_ptr_ty = sema.typeOf(dest_ptr);
2591025914 try checkMemOperand(sema, block, dest_src, dest_ptr_ty);
2591125915
25912 if (dest_ptr_ty.isConstPtr(mod)) {
25916 if (dest_ptr_ty.isConstPtr(zcu)) {
2591325917 return sema.fail(block, dest_src, "cannot memset constant pointer", .{});
2591425918 }
2591525919
2591625920 const dest_elem_ty: Type = dest_elem_ty: {
25917 const ptr_info = dest_ptr_ty.ptrInfo(mod);
25921 const ptr_info = dest_ptr_ty.ptrInfo(zcu);
2591825922 switch (ptr_info.flags.size) {
2591925923 .Slice => break :dest_elem_ty Type.fromInterned(ptr_info.child),
2592025924 .One => {
25921 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
25922 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(mod);
25925 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Array) {
25926 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(zcu);
2592325927 }
2592425928 },
2592525929 .Many, .C => {},
......@@ -25940,7 +25944,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2594025944 const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;
2594125945 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), dest_src);
2594225946 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)).?;
25947 const len_u64 = try len_val.toUnsignedIntSema(pt);
2594425948 const len = try sema.usizeCast(block, dest_src, len_u64);
2594525949 if (len == 0) {
2594625950 // This AIR instruction guarantees length > 0 if it is comptime-known.
......@@ -25958,12 +25962,12 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2595825962 .storage = .{ .repeated_elem = elem_val.toIntern() },
2595925963 } }));
2596025964 const array_ptr_ty = ty: {
25961 var info = dest_ptr_ty.ptrInfo(mod);
25965 var info = dest_ptr_ty.ptrInfo(zcu);
2596225966 info.flags.size = .One;
2596325967 info.child = array_ty.toIntern();
2596425968 break :ty try pt.ptrType(info);
2596525969 };
25966 const raw_ptr_val = if (dest_ptr_ty.isSlice(mod)) ptr_val.slicePtr(mod) else ptr_val;
25970 const raw_ptr_val = if (dest_ptr_ty.isSlice(zcu)) ptr_val.slicePtr(zcu) else ptr_val;
2596725971 const array_ptr_val = try pt.getCoerced(raw_ptr_val, array_ptr_ty);
2596825972 return sema.storePtrVal(block, src, array_ptr_val, array_val, array_ty);
2596925973 };
......@@ -26129,10 +26133,10 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2612926133 defer tracy.end();
2613026134
2613126135 const pt = sema.pt;
26132 const mod = pt.zcu;
26136 const zcu = pt.zcu;
2613326137 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2613426138 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
26135 const target = mod.getTarget();
26139 const target = zcu.getTarget();
2613626140
2613726141 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });
2613826142 const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node });
......@@ -26207,7 +26211,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2620726211 if (val.isGenericPoison()) {
2620826212 break :blk null;
2620926213 }
26210 break :blk mod.toEnum(std.builtin.AddressSpace, val);
26214 break :blk zcu.toEnum(std.builtin.AddressSpace, val);
2621126215 } else if (extra.data.bits.has_addrspace_ref) blk: {
2621226216 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2621326217 extra_index += 1;
......@@ -26226,7 +26230,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2622626230 error.GenericPoison => break :blk null,
2622726231 else => |e| return e,
2622826232 };
26229 break :blk mod.toEnum(std.builtin.AddressSpace, addrspace_val);
26233 break :blk zcu.toEnum(std.builtin.AddressSpace, addrspace_val);
2623026234 } else target_util.defaultAddressSpace(target, .function);
2623126235
2623226236 const section: Section = if (extra.data.bits.has_section_body) blk: {
......@@ -26272,7 +26276,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2627226276 if (val.isGenericPoison()) {
2627326277 break :blk null;
2627426278 }
26275 break :blk mod.toEnum(std.builtin.CallingConvention, val);
26279 break :blk zcu.toEnum(std.builtin.CallingConvention, val);
2627626280 } else if (extra.data.bits.has_cc_ref) blk: {
2627726281 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2627826282 extra_index += 1;
......@@ -26291,18 +26295,18 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2629126295 error.GenericPoison => break :blk null,
2629226296 else => |e| return e,
2629326297 };
26294 break :blk mod.toEnum(std.builtin.CallingConvention, cc_val);
26298 break :blk zcu.toEnum(std.builtin.CallingConvention, cc_val);
2629526299 } else cc: {
2629626300 if (has_body) {
2629726301 const decl_inst = if (sema.generic_owner != .none) decl_inst: {
2629826302 // Generic instance -- use the original function declaration to
2629926303 // 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().?);
26304 const nav = zcu.intern_pool.getNav(zcu.funcInfo(sema.generic_owner).owner_nav);
26305 const cau = zcu.intern_pool.getCau(nav.analysis_owner.unwrap().?);
2630226306 break :decl_inst cau.zir_index;
2630326307 } else sema.getOwnerCauDeclInst(); // not an instantiation so we're analyzing a function declaration Cau
2630426308
26305 const zir_decl = sema.code.getDeclaration(decl_inst.resolve(&mod.intern_pool) orelse return error.AnalysisFail)[0];
26309 const zir_decl = sema.code.getDeclaration(decl_inst.resolve(&zcu.intern_pool) orelse return error.AnalysisFail)[0];
2630626310 if (zir_decl.flags.is_export) {
2630726311 break :cc .C;
2630826312 }
......@@ -26408,7 +26412,7 @@ fn zirCDefine(
2640826412 extended: Zir.Inst.Extended.InstData,
2640926413) CompileError!Air.Inst.Ref {
2641026414 const pt = sema.pt;
26411 const mod = pt.zcu;
26415 const zcu = pt.zcu;
2641226416 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2641326417 const name_src = block.builtinCallArgSrc(extra.node, 0);
2641426418 const val_src = block.builtinCallArgSrc(extra.node, 1);
......@@ -26417,7 +26421,7 @@ fn zirCDefine(
2641726421 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
2641826422 });
2641926423 const rhs = try sema.resolveInst(extra.rhs);
26420 if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) {
26424 if (sema.typeOf(rhs).zigTypeTag(zcu) != .Void) {
2642126425 const value = try sema.resolveConstString(block, val_src, extra.rhs, .{
2642226426 .needed_comptime_reason = "value of macro being undefined must be comptime-known",
2642326427 });
......@@ -26490,9 +26494,9 @@ fn resolvePrefetchOptions(
2649026494 zir_ref: Zir.Inst.Ref,
2649126495) CompileError!std.builtin.PrefetchOptions {
2649226496 const pt = sema.pt;
26493 const mod = pt.zcu;
26497 const zcu = pt.zcu;
2649426498 const gpa = sema.gpa;
26495 const ip = &mod.intern_pool;
26499 const ip = &zcu.intern_pool;
2649626500 const options_ty = try pt.getBuiltinType("PrefetchOptions");
2649726501 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2649826502
......@@ -26516,9 +26520,9 @@ fn resolvePrefetchOptions(
2651626520 });
2651726521
2651826522 return std.builtin.PrefetchOptions{
26519 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
26523 .rw = zcu.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
2652026524 .locality = @intCast(try locality_val.toUnsignedIntSema(pt)),
26521 .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
26525 .cache = zcu.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
2652226526 };
2652326527}
2652426528
......@@ -26562,9 +26566,9 @@ fn resolveExternOptions(
2656226566 is_thread_local: bool = false,
2656326567} {
2656426568 const pt = sema.pt;
26565 const mod = pt.zcu;
26569 const zcu = pt.zcu;
2656626570 const gpa = sema.gpa;
26567 const ip = &mod.intern_pool;
26571 const ip = &zcu.intern_pool;
2656826572 const options_inst = try sema.resolveInst(zir_ref);
2656926573 const extern_options_ty = try pt.getBuiltinType("ExternOptions");
2657026574 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
......@@ -26588,14 +26592,14 @@ fn resolveExternOptions(
2658826592 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
2658926593 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
2659026594 });
26591 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
26595 const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val);
2659226596
2659326597 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);
2659426598 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
2659526599 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
2659626600 });
2659726601
26598 const library_name = if (library_name_val.optionalValue(mod)) |library_name_payload| library_name: {
26602 const library_name = if (library_name_val.optionalValue(zcu)) |library_name_payload| library_name: {
2659926603 const library_name = try sema.toConstString(block, library_src, Air.internedToRef(library_name_payload.toIntern()), .{
2660026604 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
2660126605 });
......@@ -26628,14 +26632,14 @@ fn zirBuiltinExtern(
2662826632 extended: Zir.Inst.Extended.InstData,
2662926633) CompileError!Air.Inst.Ref {
2663026634 const pt = sema.pt;
26631 const mod = pt.zcu;
26632 const ip = &mod.intern_pool;
26635 const zcu = pt.zcu;
26636 const ip = &zcu.intern_pool;
2663326637 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2663426638 const ty_src = block.builtinCallArgSrc(extra.node, 0);
2663526639 const options_src = block.builtinCallArgSrc(extra.node, 1);
2663626640
2663726641 var ty = try sema.resolveType(block, ty_src, extra.lhs);
26638 if (!ty.isPtrAtRuntime(mod)) {
26642 if (!ty.isPtrAtRuntime(zcu)) {
2663926643 return sema.fail(block, ty_src, "expected (optional) pointer", .{});
2664026644 }
2664126645 if (!try sema.validateExternType(ty, .other)) {
......@@ -26652,10 +26656,10 @@ fn zirBuiltinExtern(
2665226656
2665326657 // TODO: error for threadlocal functions, non-const functions, etc
2665426658
26655 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
26659 if (options.linkage == .weak and !ty.ptrAllowsZero(zcu)) {
2665626660 ty = try pt.optionalType(ty.toIntern());
2665726661 }
26658 const ptr_info = ty.ptrInfo(mod);
26662 const ptr_info = ty.ptrInfo(zcu);
2665926663
2666026664 const extern_val = try pt.getExtern(.{
2666126665 .name = options.name,
......@@ -26801,7 +26805,7 @@ fn validateVarType(
2680126805 is_extern: bool,
2680226806) CompileError!void {
2680326807 const pt = sema.pt;
26804 const mod = pt.zcu;
26808 const zcu = pt.zcu;
2680526809 if (is_extern) {
2680626810 if (!try sema.validateExternType(var_ty, .other)) {
2680726811 const msg = msg: {
......@@ -26813,7 +26817,7 @@ fn validateVarType(
2681326817 return sema.failWithOwnedErrorMsg(block, msg);
2681426818 }
2681526819 } else {
26816 if (var_ty.zigTypeTag(mod) == .Opaque) {
26820 if (var_ty.zigTypeTag(zcu) == .Opaque) {
2681726821 return sema.fail(
2681826822 block,
2681926823 src,
......@@ -26823,14 +26827,14 @@ fn validateVarType(
2682326827 }
2682426828 }
2682526829
26826 if (!try sema.typeRequiresComptime(var_ty)) return;
26830 if (!try var_ty.comptimeOnlySema(pt)) return;
2682726831
2682826832 const msg = msg: {
2682926833 const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(pt)});
2683026834 errdefer msg.destroy(sema.gpa);
2683126835
2683226836 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
26833 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
26837 if (var_ty.zigTypeTag(zcu) == .ComptimeInt or var_ty.zigTypeTag(zcu) == .ComptimeFloat) {
2683426838 try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
2683526839 }
2683626840
......@@ -26843,7 +26847,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
2684326847
2684426848fn explainWhyTypeIsComptime(
2684526849 sema: *Sema,
26846 msg: *Module.ErrorMsg,
26850 msg: *Zcu.ErrorMsg,
2684726851 src_loc: LazySrcLoc,
2684826852 ty: Type,
2684926853) CompileError!void {
......@@ -26856,15 +26860,15 @@ fn explainWhyTypeIsComptime(
2685626860
2685726861fn explainWhyTypeIsComptimeInner(
2685826862 sema: *Sema,
26859 msg: *Module.ErrorMsg,
26863 msg: *Zcu.ErrorMsg,
2686026864 src_loc: LazySrcLoc,
2686126865 ty: Type,
2686226866 type_set: *TypeSet,
2686326867) CompileError!void {
2686426868 const pt = sema.pt;
26865 const mod = pt.zcu;
26866 const ip = &mod.intern_pool;
26867 switch (ty.zigTypeTag(mod)) {
26869 const zcu = pt.zcu;
26870 const ip = &zcu.intern_pool;
26871 switch (ty.zigTypeTag(zcu)) {
2686826872 .Bool,
2686926873 .Int,
2687026874 .Float,
......@@ -26896,12 +26900,12 @@ fn explainWhyTypeIsComptimeInner(
2689626900 },
2689726901
2689826902 .Array, .Vector => {
26899 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(mod), type_set);
26903 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(zcu), type_set);
2690026904 },
2690126905 .Pointer => {
26902 const elem_ty = ty.elemType2(mod);
26903 if (elem_ty.zigTypeTag(mod) == .Fn) {
26904 const fn_info = mod.typeToFunc(elem_ty).?;
26906 const elem_ty = ty.elemType2(zcu);
26907 if (elem_ty.zigTypeTag(zcu) == .Fn) {
26908 const fn_info = zcu.typeToFunc(elem_ty).?;
2690526909 if (fn_info.is_generic) {
2690626910 try sema.errNote(src_loc, msg, "function is generic", .{});
2690726911 }
......@@ -26909,25 +26913,25 @@ fn explainWhyTypeIsComptimeInner(
2690926913 .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}),
2691026914 else => {},
2691126915 }
26912 if (Type.fromInterned(fn_info.return_type).comptimeOnly(pt)) {
26916 if (Type.fromInterned(fn_info.return_type).comptimeOnly(zcu)) {
2691326917 try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{});
2691426918 }
2691526919 return;
2691626920 }
26917 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(mod), type_set);
26921 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(zcu), type_set);
2691826922 },
2691926923
2692026924 .Optional => {
26921 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.optionalChild(mod), type_set);
26925 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.optionalChild(zcu), type_set);
2692226926 },
2692326927 .ErrorUnion => {
26924 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.errorUnionPayload(mod), type_set);
26928 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.errorUnionPayload(zcu), type_set);
2692526929 },
2692626930
2692726931 .Struct => {
2692826932 if ((try type_set.getOrPut(sema.gpa, ty.toIntern())).found_existing) return;
2692926933
26930 if (mod.typeToStruct(ty)) |struct_type| {
26934 if (zcu.typeToStruct(ty)) |struct_type| {
2693126935 for (0..struct_type.field_types.len) |i| {
2693226936 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
2693326937 const field_src: LazySrcLoc = .{
......@@ -26935,7 +26939,7 @@ fn explainWhyTypeIsComptimeInner(
2693526939 .offset = .{ .container_field_type = @intCast(i) },
2693626940 };
2693726941
26938 if (try sema.typeRequiresComptime(field_ty)) {
26942 if (try field_ty.comptimeOnlySema(pt)) {
2693926943 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});
2694026944 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2694126945 }
......@@ -26947,7 +26951,7 @@ fn explainWhyTypeIsComptimeInner(
2694726951 .Union => {
2694826952 if ((try type_set.getOrPut(sema.gpa, ty.toIntern())).found_existing) return;
2694926953
26950 if (mod.typeToUnion(ty)) |union_obj| {
26954 if (zcu.typeToUnion(ty)) |union_obj| {
2695126955 for (0..union_obj.field_types.len) |i| {
2695226956 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
2695326957 const field_src: LazySrcLoc = .{
......@@ -26955,7 +26959,7 @@ fn explainWhyTypeIsComptimeInner(
2695526959 .offset = .{ .container_field_type = @intCast(i) },
2695626960 };
2695726961
26958 if (try sema.typeRequiresComptime(field_ty)) {
26962 if (try field_ty.comptimeOnlySema(pt)) {
2695926963 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});
2696026964 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2696126965 }
......@@ -26983,8 +26987,8 @@ fn validateExternType(
2698326987 position: ExternPosition,
2698426988) !bool {
2698526989 const pt = sema.pt;
26986 const mod = pt.zcu;
26987 switch (ty.zigTypeTag(mod)) {
26990 const zcu = pt.zcu;
26991 switch (ty.zigTypeTag(zcu)) {
2698826992 .Type,
2698926993 .ComptimeFloat,
2699026994 .ComptimeInt,
......@@ -27003,58 +27007,58 @@ fn validateExternType(
2700327007 .AnyFrame,
2700427008 => return true,
2700527009 .Pointer => {
27006 if (ty.childType(mod).zigTypeTag(mod) == .Fn) {
27007 return ty.isConstPtr(mod) and try sema.validateExternType(ty.childType(mod), .other);
27010 if (ty.childType(zcu).zigTypeTag(zcu) == .Fn) {
27011 return ty.isConstPtr(zcu) and try sema.validateExternType(ty.childType(zcu), .other);
2700827012 }
27009 return !(ty.isSlice(mod) or try sema.typeRequiresComptime(ty));
27013 return !(ty.isSlice(zcu) or try ty.comptimeOnlySema(pt));
2701027014 },
27011 .Int => switch (ty.intInfo(mod).bits) {
27015 .Int => switch (ty.intInfo(zcu).bits) {
2701227016 0, 8, 16, 32, 64, 128 => return true,
2701327017 else => return false,
2701427018 },
2701527019 .Fn => {
2701627020 if (position != .other) return false;
27017 const target = mod.getTarget();
27021 const target = zcu.getTarget();
2701827022 // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI.
2701927023 // 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)) {
27024 if (ty.fnCallingConvention(zcu) == .Kernel and (target.cpu.arch == .nvptx or target.cpu.arch == .nvptx64)) {
2702127025 return true;
2702227026 }
27023 return !target_util.fnCallConvAllowsZigTypes(target, ty.fnCallingConvention(mod));
27027 return !target_util.fnCallConvAllowsZigTypes(target, ty.fnCallingConvention(zcu));
2702427028 },
2702527029 .Enum => {
27026 return sema.validateExternType(ty.intTagType(mod), position);
27030 return sema.validateExternType(ty.intTagType(zcu), position);
2702727031 },
27028 .Struct, .Union => switch (ty.containerLayout(mod)) {
27032 .Struct, .Union => switch (ty.containerLayout(zcu)) {
2702927033 .@"extern" => return true,
2703027034 .@"packed" => {
27031 const bit_size = try ty.bitSizeAdvanced(pt, .sema);
27035 const bit_size = try ty.bitSizeSema(pt);
2703227036 switch (bit_size) {
2703327037 0, 8, 16, 32, 64, 128 => return true,
2703427038 else => return false,
2703527039 }
2703627040 },
27037 .auto => return !(try sema.typeHasRuntimeBits(ty)),
27041 .auto => return !(try ty.hasRuntimeBitsSema(pt)),
2703827042 },
2703927043 .Array => {
2704027044 if (position == .ret_ty or position == .param_ty) return false;
27041 return sema.validateExternType(ty.elemType2(mod), .element);
27045 return sema.validateExternType(ty.elemType2(zcu), .element);
2704227046 },
27043 .Vector => return sema.validateExternType(ty.elemType2(mod), .element),
27044 .Optional => return ty.isPtrLikeOptional(mod),
27047 .Vector => return sema.validateExternType(ty.elemType2(zcu), .element),
27048 .Optional => return ty.isPtrLikeOptional(zcu),
2704527049 }
2704627050}
2704727051
2704827052fn explainWhyTypeIsNotExtern(
2704927053 sema: *Sema,
27050 msg: *Module.ErrorMsg,
27054 msg: *Zcu.ErrorMsg,
2705127055 src_loc: LazySrcLoc,
2705227056 ty: Type,
2705327057 position: ExternPosition,
2705427058) CompileError!void {
2705527059 const pt = sema.pt;
27056 const mod = pt.zcu;
27057 switch (ty.zigTypeTag(mod)) {
27060 const zcu = pt.zcu;
27061 switch (ty.zigTypeTag(zcu)) {
2705827062 .Opaque,
2705927063 .Bool,
2706027064 .Float,
......@@ -27073,13 +27077,13 @@ fn explainWhyTypeIsNotExtern(
2707327077 => return,
2707427078
2707527079 .Pointer => {
27076 if (ty.isSlice(mod)) {
27080 if (ty.isSlice(zcu)) {
2707727081 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2707827082 } else {
27079 const pointee_ty = ty.childType(mod);
27080 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {
27083 const pointee_ty = ty.childType(zcu);
27084 if (!ty.isConstPtr(zcu) and pointee_ty.zigTypeTag(zcu) == .Fn) {
2708127085 try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{});
27082 } else if (try sema.typeRequiresComptime(ty)) {
27086 } else if (try ty.comptimeOnlySema(pt)) {
2708327087 try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(pt)});
2708427088 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
2708527089 }
......@@ -27088,7 +27092,7 @@ fn explainWhyTypeIsNotExtern(
2708827092 },
2708927093 .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
2709027094 .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)) {
27095 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(zcu).bits)) {
2709227096 try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
2709327097 } else {
2709427098 try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});
......@@ -27099,7 +27103,7 @@ fn explainWhyTypeIsNotExtern(
2709927103 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
2710027104 return;
2710127105 }
27102 switch (ty.fnCallingConvention(mod)) {
27106 switch (ty.fnCallingConvention(zcu)) {
2710327107 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
2710427108 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
2710527109 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
......@@ -27107,7 +27111,7 @@ fn explainWhyTypeIsNotExtern(
2710727111 }
2710827112 },
2710927113 .Enum => {
27110 const tag_ty = ty.intTagType(mod);
27114 const tag_ty = ty.intTagType(zcu);
2711127115 try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(pt)});
2711227116 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
2711327117 },
......@@ -27119,9 +27123,9 @@ fn explainWhyTypeIsNotExtern(
2711927123 } else if (position == .param_ty) {
2712027124 return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{});
2712127125 }
27122 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);
27126 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(zcu), .element);
2712327127 },
27124 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),
27128 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(zcu), .element),
2712527129 .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
2712627130 }
2712727131}
......@@ -27158,20 +27162,20 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {
2715827162 .auto => false,
2715927163 .explicit, .nonexhaustive => true,
2716027164 },
27161 .Pointer => !ty.isSlice(zcu) and !try sema.typeRequiresComptime(ty),
27165 .Pointer => !ty.isSlice(zcu) and !try ty.comptimeOnlySema(pt),
2716227166 .Struct, .Union => ty.containerLayout(zcu) == .@"packed",
2716327167 };
2716427168}
2716527169
2716627170fn explainWhyTypeIsNotPacked(
2716727171 sema: *Sema,
27168 msg: *Module.ErrorMsg,
27172 msg: *Zcu.ErrorMsg,
2716927173 src_loc: LazySrcLoc,
2717027174 ty: Type,
2717127175) CompileError!void {
2717227176 const pt = sema.pt;
27173 const mod = pt.zcu;
27174 switch (ty.zigTypeTag(mod)) {
27177 const zcu = pt.zcu;
27178 switch (ty.zigTypeTag(zcu)) {
2717527179 .Void,
2717627180 .Bool,
2717727181 .Float,
......@@ -27194,7 +27198,7 @@ fn explainWhyTypeIsNotPacked(
2719427198 .Optional,
2719527199 .Array,
2719627200 => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
27197 .Pointer => if (ty.isSlice(mod)) {
27201 .Pointer => if (ty.isSlice(zcu)) {
2719827202 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2719927203 } else {
2720027204 try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
......@@ -27211,23 +27215,23 @@ fn explainWhyTypeIsNotPacked(
2721127215
2721227216fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2721327217 const pt = sema.pt;
27214 const mod = pt.zcu;
27218 const zcu = pt.zcu;
2721527219
27216 if (mod.panic_func_index == .none) {
27220 if (zcu.panic_func_index == .none) {
2721727221 const fn_ref = try sema.analyzeNavVal(block, src, try pt.getBuiltinNav("panic"));
2721827222 const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{
2721927223 .needed_comptime_reason = "panic handler must be comptime-known",
2722027224 });
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();
27225 assert(fn_val.typeOf(zcu).zigTypeTag(zcu) == .Fn);
27226 assert(try fn_val.typeOf(zcu).fnHasRuntimeBitsSema(pt));
27227 try zcu.ensureFuncBodyAnalysisQueued(fn_val.toIntern());
27228 zcu.panic_func_index = fn_val.toIntern();
2722527229 }
2722627230
27227 if (mod.null_stack_trace == .none) {
27231 if (zcu.null_stack_trace == .none) {
2722827232 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
2722927233 try stack_trace_ty.resolveFields(pt);
27230 const target = mod.getTarget();
27234 const target = zcu.getTarget();
2723127235 const ptr_stack_trace_ty = try pt.ptrTypeSema(.{
2723227236 .child = stack_trace_ty.toIntern(),
2723327237 .flags = .{
......@@ -27235,7 +27239,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2723527239 },
2723627240 });
2723727241 const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern());
27238 mod.null_stack_trace = try pt.intern(.{ .opt = .{
27242 zcu.null_stack_trace = try pt.intern(.{ .opt = .{
2723927243 .ty = opt_ptr_stack_trace_ty.toIntern(),
2724027244 .val = .none,
2724127245 } });
......@@ -27245,11 +27249,11 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2724527249/// Backends depend on panic decls being available when lowering safety-checked
2724627250/// instructions. This function ensures the panic function will be available to
2724727251/// be called during that time.
27248fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module.PanicId) !InternPool.Nav.Index {
27252fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) !InternPool.Nav.Index {
2724927253 const pt = sema.pt;
27250 const mod = pt.zcu;
27254 const zcu = pt.zcu;
2725127255 const gpa = sema.gpa;
27252 if (mod.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x;
27256 if (zcu.panic_messages[@intFromEnum(panic_id)].unwrap()) |x| return x;
2725327257
2725427258 try sema.prepareSimplePanic(block, src);
2725527259
......@@ -27257,15 +27261,15 @@ fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module.
2725727261 const msg_nav_index = (sema.namespaceLookup(
2725827262 block,
2725927263 LazySrcLoc.unneeded,
27260 panic_messages_ty.getNamespaceIndex(mod),
27261 try mod.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls),
27264 panic_messages_ty.getNamespaceIndex(zcu),
27265 try zcu.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls),
2726227266 ) catch |err| switch (err) {
2726327267 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),
2726427268 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
2726527269 error.OutOfMemory => |e| return e,
2726627270 }).?;
2726727271 try sema.ensureNavResolved(src, msg_nav_index);
27268 mod.panic_messages[@intFromEnum(panic_id)] = msg_nav_index.toOptional();
27272 zcu.panic_messages[@intFromEnum(panic_id)] = msg_nav_index.toOptional();
2726927273 return msg_nav_index;
2727027274}
2727127275
......@@ -27274,7 +27278,7 @@ fn addSafetyCheck(
2727427278 parent_block: *Block,
2727527279 src: LazySrcLoc,
2727627280 ok: Air.Inst.Ref,
27277 panic_id: Module.PanicId,
27281 panic_id: Zcu.PanicId,
2727827282) !void {
2727927283 const gpa = sema.gpa;
2728027284 assert(!parent_block.is_comptime);
......@@ -27353,18 +27357,18 @@ fn addSafetyCheckExtra(
2735327357
2735427358fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst.Ref, operation: CallOperation) !void {
2735527359 const pt = sema.pt;
27356 const mod = pt.zcu;
27360 const zcu = pt.zcu;
2735727361
27358 if (!mod.backendSupportsFeature(.panic_fn)) {
27362 if (!zcu.backendSupportsFeature(.panic_fn)) {
2735927363 _ = try block.addNoOp(.trap);
2736027364 return;
2736127365 }
2736227366
2736327367 try sema.prepareSimplePanic(block, src);
2736427368
27365 const panic_func = mod.funcInfo(mod.panic_func_index);
27369 const panic_func = zcu.funcInfo(zcu.panic_func_index);
2736627370 const panic_fn = try sema.analyzeNavVal(block, src, panic_func.owner_nav);
27367 const null_stack_trace = Air.internedToRef(mod.null_stack_trace);
27371 const null_stack_trace = Air.internedToRef(zcu.null_stack_trace);
2736827372
2736927373 const opt_usize_ty = try pt.optionalType(.usize_type);
2737027374 const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{
......@@ -27459,12 +27463,12 @@ fn panicSentinelMismatch(
2745927463) !void {
2746027464 assert(!parent_block.is_comptime);
2746127465 const pt = sema.pt;
27462 const mod = pt.zcu;
27466 const zcu = pt.zcu;
2746327467 const expected_sentinel_val = maybe_sentinel orelse return;
2746427468 const expected_sentinel = Air.internedToRef(expected_sentinel_val.toIntern());
2746527469
2746627470 const ptr_ty = sema.typeOf(ptr);
27467 const actual_sentinel = if (ptr_ty.isSlice(mod))
27471 const actual_sentinel = if (ptr_ty.isSlice(zcu))
2746827472 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)
2746927473 else blk: {
2747027474 const elem_ptr_ty = try ptr_ty.elemPtrType(null, pt);
......@@ -27472,7 +27476,7 @@ fn panicSentinelMismatch(
2747227476 break :blk try parent_block.addTyOp(.load, sentinel_ty, sentinel_ptr);
2747327477 };
2747427478
27475 const ok = if (sentinel_ty.zigTypeTag(mod) == .Vector) ok: {
27479 const ok = if (sentinel_ty.zigTypeTag(zcu) == .Vector) ok: {
2747627480 const eql =
2747727481 try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq);
2747827482 break :ok try parent_block.addInst(.{
......@@ -27482,7 +27486,7 @@ fn panicSentinelMismatch(
2748227486 .operation = .And,
2748327487 } },
2748427488 });
27485 } else if (sentinel_ty.isSelfComparable(mod, true))
27489 } else if (sentinel_ty.isSelfComparable(zcu, true))
2748627490 try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel)
2748727491 else {
2748827492 const panic_fn = try pt.getBuiltin("checkNonScalarSentinel");
......@@ -27532,7 +27536,7 @@ fn safetyCheckFormatted(
2753227536 try sema.addSafetyCheckExtra(parent_block, ok, &fail_block);
2753327537}
2753427538
27535fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module.PanicId) CompileError!void {
27539fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.PanicId) CompileError!void {
2753627540 const msg_nav_index = try sema.preparePanicId(block, src, panic_id);
2753727541 const msg_inst = try sema.analyzeNavVal(block, src, msg_nav_index);
2753827542 try sema.panicWithMsg(block, src, msg_inst, .@"safety check");
......@@ -27568,30 +27572,30 @@ fn fieldVal(
2756827572 // in `fieldPtr`. This function takes a value and returns a value.
2756927573
2757027574 const pt = sema.pt;
27571 const mod = pt.zcu;
27572 const ip = &mod.intern_pool;
27575 const zcu = pt.zcu;
27576 const ip = &zcu.intern_pool;
2757327577 const object_src = src; // TODO better source location
2757427578 const object_ty = sema.typeOf(object);
2757527579
2757627580 // Zig allows dereferencing a single pointer during field lookup. Note that
2757727581 // we don't actually need to generate the dereference some field lookups, like the
2757827582 // length of arrays and other comptime operations.
27579 const is_pointer_to = object_ty.isSinglePointer(mod);
27583 const is_pointer_to = object_ty.isSinglePointer(zcu);
2758027584
2758127585 const inner_ty = if (is_pointer_to)
27582 object_ty.childType(mod)
27586 object_ty.childType(zcu)
2758327587 else
2758427588 object_ty;
2758527589
27586 switch (inner_ty.zigTypeTag(mod)) {
27590 switch (inner_ty.zigTypeTag(zcu)) {
2758727591 .Array => {
2758827592 if (field_name.eqlSlice("len", ip)) {
27589 return Air.internedToRef((try pt.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern());
27593 return Air.internedToRef((try pt.intValue(Type.usize, inner_ty.arrayLen(zcu))).toIntern());
2759027594 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27591 const ptr_info = object_ty.ptrInfo(mod);
27595 const ptr_info = object_ty.ptrInfo(zcu);
2759227596 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,
27597 .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(),
27598 .sentinel = if (inner_ty.sentinel(zcu)) |s| s.toIntern() else .none,
2759527599 .flags = .{
2759627600 .size = .Many,
2759727601 .alignment = ptr_info.flags.alignment,
......@@ -27614,7 +27618,7 @@ fn fieldVal(
2761427618 }
2761527619 },
2761627620 .Pointer => {
27617 const ptr_info = inner_ty.ptrInfo(mod);
27621 const ptr_info = inner_ty.ptrInfo(zcu);
2761827622 if (ptr_info.flags.size == .Slice) {
2761927623 if (field_name.eqlSlice("ptr", ip)) {
2762027624 const slice = if (is_pointer_to)
......@@ -27647,7 +27651,7 @@ fn fieldVal(
2764727651 const val = (try sema.resolveDefinedValue(block, object_src, dereffed_type)).?;
2764827652 const child_type = val.toType();
2764927653
27650 switch (try child_type.zigTypeTagOrPoison(mod)) {
27654 switch (try child_type.zigTypeTagOrPoison(zcu)) {
2765127655 .ErrorSet => {
2765227656 switch (ip.indexToKey(child_type.toIntern())) {
2765327657 .error_set_type => |error_set_type| blk: {
......@@ -27666,7 +27670,7 @@ fn fieldVal(
2766627670 else => unreachable,
2766727671 }
2766827672
27669 const error_set_type = if (!child_type.isAnyError(mod))
27673 const error_set_type = if (!child_type.isAnyError(zcu))
2767027674 child_type
2767127675 else
2767227676 try pt.singleErrorSetType(field_name);
......@@ -27676,12 +27680,12 @@ fn fieldVal(
2767627680 } })));
2767727681 },
2767827682 .Union => {
27679 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27683 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2768027684 return inst;
2768127685 }
2768227686 try child_type.resolveFields(pt);
27683 if (child_type.unionTagType(mod)) |enum_ty| {
27684 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| {
27687 if (child_type.unionTagType(zcu)) |enum_ty| {
27688 if (enum_ty.enumFieldIndex(field_name, zcu)) |field_index_usize| {
2768527689 const field_index: u32 = @intCast(field_index_usize);
2768627690 return Air.internedToRef((try pt.enumValueFieldIndex(enum_ty, field_index)).toIntern());
2768727691 }
......@@ -27689,10 +27693,10 @@ fn fieldVal(
2768927693 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2769027694 },
2769127695 .Enum => {
27692 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27696 if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2769327697 return inst;
2769427698 }
27695 const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse
27699 const field_index_usize = child_type.enumFieldIndex(field_name, zcu) orelse
2769627700 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2769727701 const field_index: u32 = @intCast(field_index_usize);
2769827702 const enum_val = try pt.enumValueFieldIndex(child_type, field_index);
......@@ -27701,7 +27705,7 @@ fn fieldVal(
2770127705 .Struct, .Opaque => {
2770227706 switch (child_type.toIntern()) {
2770327707 .empty_struct_type, .anyopaque_type => {}, // no namespace
27704 else => if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27708 else => if (try sema.namespaceLookupVal(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2770527709 return inst;
2770627710 },
2770727711 }
......@@ -27710,8 +27714,8 @@ fn fieldVal(
2771027714 else => return sema.failWithOwnedErrorMsg(block, msg: {
2771127715 const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(pt)});
2771227716 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", .{});
27717 if (child_type.isSlice(zcu)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
27718 if (child_type.zigTypeTag(zcu) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
2771527719 break :msg msg;
2771627720 }),
2771727721 }
......@@ -27748,35 +27752,35 @@ fn fieldPtr(
2774827752 // in `fieldVal`. This function takes a pointer and returns a pointer.
2774927753
2775027754 const pt = sema.pt;
27751 const mod = pt.zcu;
27752 const ip = &mod.intern_pool;
27755 const zcu = pt.zcu;
27756 const ip = &zcu.intern_pool;
2775327757 const object_ptr_src = src; // TODO better source location
2775427758 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),
27759 const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) {
27760 .Pointer => object_ptr_ty.childType(zcu),
2775727761 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(pt)}),
2775827762 };
2775927763
2776027764 // Zig allows dereferencing a single pointer during field lookup. Note that
2776127765 // we don't actually need to generate the dereference some field lookups, like the
2776227766 // length of arrays and other comptime operations.
27763 const is_pointer_to = object_ty.isSinglePointer(mod);
27767 const is_pointer_to = object_ty.isSinglePointer(zcu);
2776427768
2776527769 const inner_ty = if (is_pointer_to)
27766 object_ty.childType(mod)
27770 object_ty.childType(zcu)
2776727771 else
2776827772 object_ty;
2776927773
27770 switch (inner_ty.zigTypeTag(mod)) {
27774 switch (inner_ty.zigTypeTag(zcu)) {
2777127775 .Array => {
2777227776 if (field_name.eqlSlice("len", ip)) {
27773 const int_val = try pt.intValue(Type.usize, inner_ty.arrayLen(mod));
27777 const int_val = try pt.intValue(Type.usize, inner_ty.arrayLen(zcu));
2777427778 return uavRef(sema, int_val.toIntern());
2777527779 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {
27776 const ptr_info = object_ty.ptrInfo(mod);
27780 const ptr_info = object_ty.ptrInfo(zcu);
2777727781 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,
27782 .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(),
27783 .sentinel = if (object_ty.sentinel(zcu)) |s| s.toIntern() else .none,
2778027784 .flags = .{
2778127785 .size = .Many,
2778227786 .alignment = ptr_info.flags.alignment,
......@@ -27788,10 +27792,10 @@ fn fieldPtr(
2778827792 },
2778927793 .packed_offset = ptr_info.packed_offset,
2779027794 });
27791 const ptr_ptr_info = object_ptr_ty.ptrInfo(mod);
27795 const ptr_ptr_info = object_ptr_ty.ptrInfo(zcu);
2779227796 const result_ty = try pt.ptrTypeSema(.{
2779327797 .child = new_ptr_ty.toIntern(),
27794 .sentinel = if (object_ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,
27798 .sentinel = if (object_ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
2779527799 .flags = .{
2779627800 .alignment = ptr_ptr_info.flags.alignment,
2779727801 .is_const = ptr_ptr_info.flags.is_const,
......@@ -27812,7 +27816,7 @@ fn fieldPtr(
2781227816 );
2781327817 }
2781427818 },
27815 .Pointer => if (inner_ty.isSlice(mod)) {
27819 .Pointer => if (inner_ty.isSlice(zcu)) {
2781627820 const inner_ptr = if (is_pointer_to)
2781727821 try sema.analyzeLoad(block, src, object_ptr, object_ptr_src)
2781827822 else
......@@ -27821,14 +27825,14 @@ fn fieldPtr(
2782127825 const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty;
2782227826
2782327827 if (field_name.eqlSlice("ptr", ip)) {
27824 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);
27828 const slice_ptr_ty = inner_ty.slicePtrFieldType(zcu);
2782527829
2782627830 const result_ty = try pt.ptrTypeSema(.{
2782727831 .child = slice_ptr_ty.toIntern(),
2782827832 .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),
27833 .is_const = !attr_ptr_ty.ptrIsMutable(zcu),
27834 .is_volatile = attr_ptr_ty.isVolatilePtr(zcu),
27835 .address_space = attr_ptr_ty.ptrAddressSpace(zcu),
2783227836 },
2783327837 });
2783427838
......@@ -27844,9 +27848,9 @@ fn fieldPtr(
2784427848 const result_ty = try pt.ptrTypeSema(.{
2784527849 .child = .usize_type,
2784627850 .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),
27851 .is_const = !attr_ptr_ty.ptrIsMutable(zcu),
27852 .is_volatile = attr_ptr_ty.isVolatilePtr(zcu),
27853 .address_space = attr_ptr_ty.ptrAddressSpace(zcu),
2785027854 },
2785127855 });
2785227856
......@@ -27878,7 +27882,7 @@ fn fieldPtr(
2787827882 const val = (sema.resolveDefinedValue(block, src, inner) catch unreachable).?;
2787927883 const child_type = val.toType();
2788027884
27881 switch (child_type.zigTypeTag(mod)) {
27885 switch (child_type.zigTypeTag(zcu)) {
2788227886 .ErrorSet => {
2788327887 switch (ip.indexToKey(child_type.toIntern())) {
2788427888 .error_set_type => |error_set_type| blk: {
......@@ -27899,7 +27903,7 @@ fn fieldPtr(
2789927903 else => unreachable,
2790027904 }
2790127905
27902 const error_set_type = if (!child_type.isAnyError(mod))
27906 const error_set_type = if (!child_type.isAnyError(zcu))
2790327907 child_type
2790427908 else
2790527909 try pt.singleErrorSetType(field_name);
......@@ -27909,12 +27913,12 @@ fn fieldPtr(
2790927913 } }));
2791027914 },
2791127915 .Union => {
27912 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27916 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2791327917 return inst;
2791427918 }
2791527919 try child_type.resolveFields(pt);
27916 if (child_type.unionTagType(mod)) |enum_ty| {
27917 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| {
27920 if (child_type.unionTagType(zcu)) |enum_ty| {
27921 if (enum_ty.enumFieldIndex(field_name, zcu)) |field_index| {
2791827922 const field_index_u32: u32 = @intCast(field_index);
2791927923 const idx_val = try pt.enumValueFieldIndex(enum_ty, field_index_u32);
2792027924 return uavRef(sema, idx_val.toIntern());
......@@ -27923,10 +27927,10 @@ fn fieldPtr(
2792327927 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2792427928 },
2792527929 .Enum => {
27926 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27930 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2792727931 return inst;
2792827932 }
27929 const field_index = child_type.enumFieldIndex(field_name, mod) orelse {
27933 const field_index = child_type.enumFieldIndex(field_name, zcu) orelse {
2793027934 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2793127935 };
2793227936 const field_index_u32: u32 = @intCast(field_index);
......@@ -27934,7 +27938,7 @@ fn fieldPtr(
2793427938 return uavRef(sema, idx_val.toIntern());
2793527939 },
2793627940 .Struct, .Opaque => {
27937 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(mod), field_name)) |inst| {
27941 if (try sema.namespaceLookupRef(block, src, child_type.getNamespaceIndex(zcu), field_name)) |inst| {
2793827942 return inst;
2793927943 }
2794027944 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
......@@ -28021,14 +28025,14 @@ fn fieldCallBind(
2802128025 }
2802228026 if (field_name.toUnsigned(ip)) |field_index| {
2802328027 if (field_index >= concrete_ty.structFieldCount(zcu)) break :find_field;
28024 return sema.finishFieldCallBind(block, src, ptr_ty, concrete_ty.structFieldType(field_index, zcu), field_index, object_ptr);
28028 return sema.finishFieldCallBind(block, src, ptr_ty, concrete_ty.fieldType(field_index, zcu), field_index, object_ptr);
2802528029 }
2802628030 } else {
2802728031 const max = concrete_ty.structFieldCount(zcu);
2802828032 for (0..max) |i_usize| {
2802928033 const i: u32 = @intCast(i_usize);
2803028034 if (field_name == concrete_ty.structFieldName(i, zcu).unwrap().?) {
28031 return sema.finishFieldCallBind(block, src, ptr_ty, concrete_ty.structFieldType(i, zcu), i, object_ptr);
28035 return sema.finishFieldCallBind(block, src, ptr_ty, concrete_ty.fieldType(i, zcu), i, object_ptr);
2803228036 }
2803328037 }
2803428038 }
......@@ -28149,18 +28153,18 @@ fn finishFieldCallBind(
2814928153 object_ptr: Air.Inst.Ref,
2815028154) CompileError!ResolvedFieldCallee {
2815128155 const pt = sema.pt;
28152 const mod = pt.zcu;
28156 const zcu = pt.zcu;
2815328157 const ptr_field_ty = try pt.ptrTypeSema(.{
2815428158 .child = field_ty.toIntern(),
2815528159 .flags = .{
28156 .is_const = !ptr_ty.ptrIsMutable(mod),
28157 .address_space = ptr_ty.ptrAddressSpace(mod),
28160 .is_const = !ptr_ty.ptrIsMutable(zcu),
28161 .address_space = ptr_ty.ptrAddressSpace(zcu),
2815828162 },
2815928163 });
2816028164
28161 const container_ty = ptr_ty.childType(mod);
28162 if (container_ty.zigTypeTag(mod) == .Struct) {
28163 if (container_ty.structFieldIsComptime(field_index, mod)) {
28165 const container_ty = ptr_ty.childType(zcu);
28166 if (container_ty.zigTypeTag(zcu) == .Struct) {
28167 if (container_ty.structFieldIsComptime(field_index, zcu)) {
2816428168 try container_ty.resolveStructFieldInits(pt);
2816528169 const default_val = (try container_ty.structFieldValueComptime(pt, field_index)).?;
2816628170 return .{ .direct = Air.internedToRef(default_val.toIntern()) };
......@@ -28237,26 +28241,26 @@ fn structFieldPtr(
2823728241 initializing: bool,
2823828242) CompileError!Air.Inst.Ref {
2823928243 const pt = sema.pt;
28240 const mod = pt.zcu;
28241 const ip = &mod.intern_pool;
28242 assert(struct_ty.zigTypeTag(mod) == .Struct);
28244 const zcu = pt.zcu;
28245 const ip = &zcu.intern_pool;
28246 assert(struct_ty.zigTypeTag(zcu) == .Struct);
2824328247
2824428248 try struct_ty.resolveFields(pt);
2824528249 try struct_ty.resolveLayout(pt);
2824628250
28247 if (struct_ty.isTuple(mod)) {
28251 if (struct_ty.isTuple(zcu)) {
2824828252 if (field_name.eqlSlice("len", ip)) {
28249 const len_inst = try pt.intRef(Type.usize, struct_ty.structFieldCount(mod));
28253 const len_inst = try pt.intRef(Type.usize, struct_ty.structFieldCount(zcu));
2825028254 return sema.analyzeRef(block, src, len_inst);
2825128255 }
2825228256 const field_index = try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);
2825328257 return sema.tupleFieldPtr(block, src, struct_ptr, field_name_src, field_index, initializing);
28254 } else if (struct_ty.isAnonStruct(mod)) {
28258 } else if (struct_ty.isAnonStruct(zcu)) {
2825528259 const field_index = try sema.anonStructFieldIndex(block, struct_ty, field_name, field_name_src);
2825628260 return sema.tupleFieldPtr(block, src, struct_ptr, field_name_src, field_index, initializing);
2825728261 }
2825828262
28259 const struct_type = mod.typeToStruct(struct_ty).?;
28263 const struct_type = zcu.typeToStruct(struct_ty).?;
2826028264
2826128265 const field_index = struct_type.nameIndex(ip, field_name) orelse
2826228266 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
......@@ -28275,9 +28279,9 @@ fn structFieldPtrByIndex(
2827528279 initializing: bool,
2827628280) CompileError!Air.Inst.Ref {
2827728281 const pt = sema.pt;
28278 const mod = pt.zcu;
28279 const ip = &mod.intern_pool;
28280 if (struct_ty.isAnonStruct(mod)) {
28282 const zcu = pt.zcu;
28283 const ip = &zcu.intern_pool;
28284 if (struct_ty.isAnonStruct(zcu)) {
2828128285 return sema.tupleFieldPtr(block, src, struct_ptr, field_src, field_index, initializing);
2828228286 }
2828328287
......@@ -28286,10 +28290,10 @@ fn structFieldPtrByIndex(
2828628290 return Air.internedToRef(val.toIntern());
2828728291 }
2828828292
28289 const struct_type = mod.typeToStruct(struct_ty).?;
28293 const struct_type = zcu.typeToStruct(struct_ty).?;
2829028294 const field_ty = struct_type.field_types.get(ip)[field_index];
2829128295 const struct_ptr_ty = sema.typeOf(struct_ptr);
28292 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(mod);
28296 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu);
2829328297
2829428298 var ptr_ty_data: InternPool.Key.PtrType = .{
2829528299 .child = field_ty,
......@@ -28303,7 +28307,7 @@ fn structFieldPtrByIndex(
2830328307 const parent_align = if (struct_ptr_ty_info.flags.alignment != .none)
2830428308 struct_ptr_ty_info.flags.alignment
2830528309 else
28306 try sema.typeAbiAlignment(Type.fromInterned(struct_ptr_ty_info.child));
28310 try Type.fromInterned(struct_ptr_ty_info.child).abiAlignmentSema(pt);
2830728311
2830828312 if (struct_type.layout == .@"packed") {
2830928313 switch (struct_ty.packedStructFieldPtrInfo(struct_ptr_ty, field_index, pt)) {
......@@ -28319,18 +28323,17 @@ fn structFieldPtrByIndex(
2831928323 // For extern structs, field alignment might be bigger than type's
2832028324 // natural alignment. Eg, in `extern struct { x: u32, y: u16 }` the
2832128325 // second field is aligned as u32.
28322 const field_offset = struct_ty.structFieldOffset(field_index, pt);
28326 const field_offset = struct_ty.structFieldOffset(field_index, zcu);
2832328327 ptr_ty_data.flags.alignment = if (parent_align == .none)
2832428328 .none
2832528329 else
2832628330 @enumFromInt(@min(@intFromEnum(parent_align), @ctz(field_offset)));
2832728331 } else {
2832828332 // Our alignment is capped at the field alignment.
28329 const field_align = try pt.structFieldAlignmentAdvanced(
28333 const field_align = try Type.fromInterned(field_ty).structFieldAlignmentSema(
2833028334 struct_type.fieldAlign(ip, field_index),
28331 Type.fromInterned(field_ty),
2833228335 struct_type.layout,
28333 .sema,
28336 pt,
2833428337 );
2833528338 ptr_ty_data.flags.alignment = if (struct_ptr_ty_info.flags.alignment == .none)
2833628339 field_align
......@@ -28364,9 +28367,9 @@ fn structFieldVal(
2836428367 struct_ty: Type,
2836528368) CompileError!Air.Inst.Ref {
2836628369 const pt = sema.pt;
28367 const mod = pt.zcu;
28368 const ip = &mod.intern_pool;
28369 assert(struct_ty.zigTypeTag(mod) == .Struct);
28370 const zcu = pt.zcu;
28371 const ip = &zcu.intern_pool;
28372 assert(struct_ty.zigTypeTag(zcu) == .Struct);
2837028373
2837128374 try struct_ty.resolveFields(pt);
2837228375
......@@ -28388,7 +28391,7 @@ fn structFieldVal(
2838828391 return Air.internedToRef(field_val.toIntern());
2838928392
2839028393 if (try sema.resolveValue(struct_byval)) |struct_val| {
28391 if (struct_val.isUndef(mod)) return pt.undefRef(field_ty);
28394 if (struct_val.isUndef(zcu)) return pt.undefRef(field_ty);
2839228395 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2839328396 return Air.internedToRef(opv.toIntern());
2839428397 }
......@@ -28421,9 +28424,9 @@ fn tupleFieldVal(
2842128424 tuple_ty: Type,
2842228425) CompileError!Air.Inst.Ref {
2842328426 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));
28427 const zcu = pt.zcu;
28428 if (field_name.eqlSlice("len", &zcu.intern_pool)) {
28429 return pt.intRef(Type.usize, tuple_ty.structFieldCount(zcu));
2842728430 }
2842828431 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
2842928432 return sema.tupleFieldValByIndex(block, src, tuple_byval, field_index, tuple_ty);
......@@ -28461,10 +28464,10 @@ fn tupleFieldValByIndex(
2846128464 tuple_ty: Type,
2846228465) CompileError!Air.Inst.Ref {
2846328466 const pt = sema.pt;
28464 const mod = pt.zcu;
28465 const field_ty = tuple_ty.structFieldType(field_index, mod);
28467 const zcu = pt.zcu;
28468 const field_ty = tuple_ty.fieldType(field_index, zcu);
2846628469
28467 if (tuple_ty.structFieldIsComptime(field_index, mod))
28470 if (tuple_ty.structFieldIsComptime(field_index, zcu))
2846828471 try tuple_ty.resolveStructFieldInits(pt);
2846928472 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {
2847028473 return Air.internedToRef(default_value.toIntern());
......@@ -28474,10 +28477,10 @@ fn tupleFieldValByIndex(
2847428477 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2847528478 return Air.internedToRef(opv.toIntern());
2847628479 }
28477 return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) {
28480 return switch (zcu.intern_pool.indexToKey(tuple_val.toIntern())) {
2847828481 .undef => pt.undefRef(field_ty),
2847928482 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {
28480 .bytes => |bytes| try pt.intValue(Type.u8, bytes.at(field_index, &mod.intern_pool)),
28483 .bytes => |bytes| try pt.intValue(Type.u8, bytes.at(field_index, &zcu.intern_pool)),
2848128484 .elems => |elems| Value.fromInterned(elems[field_index]),
2848228485 .repeated_elem => |elem| Value.fromInterned(elem),
2848328486 }.toIntern()),
......@@ -28501,15 +28504,15 @@ fn unionFieldPtr(
2850128504 initializing: bool,
2850228505) CompileError!Air.Inst.Ref {
2850328506 const pt = sema.pt;
28504 const mod = pt.zcu;
28505 const ip = &mod.intern_pool;
28507 const zcu = pt.zcu;
28508 const ip = &zcu.intern_pool;
2850628509
28507 assert(union_ty.zigTypeTag(mod) == .Union);
28510 assert(union_ty.zigTypeTag(zcu) == .Union);
2850828511
2850928512 const union_ptr_ty = sema.typeOf(union_ptr);
28510 const union_ptr_info = union_ptr_ty.ptrInfo(mod);
28513 const union_ptr_info = union_ptr_ty.ptrInfo(zcu);
2851128514 try union_ty.resolveFields(pt);
28512 const union_obj = mod.typeToUnion(union_ty).?;
28515 const union_obj = zcu.typeToUnion(union_ty).?;
2851328516 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
2851428517 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
2851528518 const ptr_field_ty = try pt.ptrTypeSema(.{
......@@ -28522,16 +28525,16 @@ fn unionFieldPtr(
2852228525 const union_align = if (union_ptr_info.flags.alignment != .none)
2852328526 union_ptr_info.flags.alignment
2852428527 else
28525 try sema.typeAbiAlignment(union_ty);
28526 const field_align = try pt.unionFieldNormalAlignmentAdvanced(union_obj, field_index, .sema);
28528 try union_ty.abiAlignmentSema(pt);
28529 const field_align = try union_ty.fieldAlignmentSema(field_index, pt);
2852728530 break :blk union_align.min(field_align);
2852828531 } else union_ptr_info.flags.alignment,
2852928532 },
2853028533 .packed_offset = union_ptr_info.packed_offset,
2853128534 });
28532 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, mod).?);
28535 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, zcu).?);
2853328536
28534 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
28537 if (initializing and field_ty.zigTypeTag(zcu) == .NoReturn) {
2853528538 const msg = msg: {
2853628539 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2853728540 errdefer msg.destroy(sema.gpa);
......@@ -28556,7 +28559,7 @@ fn unionFieldPtr(
2855628559 } else {
2855728560 const union_val = (try sema.pointerDeref(block, src, union_ptr_val, union_ptr_ty)) orelse
2855828561 break :ct;
28559 if (union_val.isUndef(mod)) {
28562 if (union_val.isUndef(zcu)) {
2856028563 return sema.failWithUseOfUndef(block, src);
2856128564 }
2856228565 const un = ip.indexToKey(union_val.toIntern()).un;
......@@ -28564,8 +28567,8 @@ fn unionFieldPtr(
2856428567 const tag_matches = un.tag == field_tag.toIntern();
2856528568 if (!tag_matches) {
2856628569 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);
28570 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
28571 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);
2856928572 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
2857028573 field_name.fmt(ip),
2857128574 active_field_name.fmt(ip),
......@@ -28585,7 +28588,7 @@ fn unionFieldPtr(
2858528588
2858628589 try sema.requireRuntimeBlock(block, src, null);
2858728590 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)
28591 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
2858928592 {
2859028593 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2859128594 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
......@@ -28594,7 +28597,7 @@ fn unionFieldPtr(
2859428597 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val);
2859528598 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);
2859628599 }
28597 if (field_ty.zigTypeTag(mod) == .NoReturn) {
28600 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
2859828601 _ = try block.addNoOp(.unreach);
2859928602 return .unreachable_value;
2860028603 }
......@@ -28654,7 +28657,7 @@ fn unionFieldVal(
2865428657 .@"packed" => if (tag_matches) {
2865528658 // Fast path - no need to use bitcast logic.
2865628659 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| {
28660 } else if (try sema.bitCastVal(union_val, field_ty, 0, try union_ty.bitSizeSema(pt), 0)) |field_val| {
2865828661 return Air.internedToRef(field_val.toIntern());
2865928662 },
2866028663 }
......@@ -28688,17 +28691,17 @@ fn elemPtr(
2868828691 oob_safety: bool,
2868928692) CompileError!Air.Inst.Ref {
2869028693 const pt = sema.pt;
28691 const mod = pt.zcu;
28694 const zcu = pt.zcu;
2869228695 const indexable_ptr_src = src; // TODO better source location
2869328696 const indexable_ptr_ty = sema.typeOf(indexable_ptr);
2869428697
28695 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(mod)) {
28696 .Pointer => indexable_ptr_ty.childType(mod),
28698 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) {
28699 .Pointer => indexable_ptr_ty.childType(zcu),
2869728700 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(pt)}),
2869828701 };
2869928702 try checkIndexable(sema, block, src, indexable_ty);
2870028703
28701 const elem_ptr = switch (indexable_ty.zigTypeTag(mod)) {
28704 const elem_ptr = switch (indexable_ty.zigTypeTag(zcu)) {
2870228705 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),
2870328706 .Struct => blk: {
2870428707 // Tuple field access.
......@@ -28732,11 +28735,11 @@ fn elemPtrOneLayerOnly(
2873228735 const indexable_src = src; // TODO better source location
2873328736 const indexable_ty = sema.typeOf(indexable);
2873428737 const pt = sema.pt;
28735 const mod = pt.zcu;
28738 const zcu = pt.zcu;
2873628739
2873728740 try checkIndexable(sema, block, src, indexable_ty);
2873828741
28739 switch (indexable_ty.ptrSize(mod)) {
28742 switch (indexable_ty.ptrSize(zcu)) {
2874028743 .Slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
2874128744 .Many, .C => {
2874228745 const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
......@@ -28754,11 +28757,11 @@ fn elemPtrOneLayerOnly(
2875428757 return block.addPtrElemPtr(indexable, elem_index, result_ty);
2875528758 },
2875628759 .One => {
28757 const child_ty = indexable_ty.childType(mod);
28758 const elem_ptr = switch (child_ty.zigTypeTag(mod)) {
28760 const child_ty = indexable_ty.childType(zcu);
28761 const elem_ptr = switch (child_ty.zigTypeTag(zcu)) {
2875928762 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety),
2876028763 .Struct => blk: {
28761 assert(child_ty.isTuple(mod));
28764 assert(child_ty.isTuple(zcu));
2876228765 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2876328766 .needed_comptime_reason = "tuple field access index must be comptime-known",
2876428767 });
......@@ -28785,7 +28788,7 @@ fn elemVal(
2878528788 const indexable_src = src; // TODO better source location
2878628789 const indexable_ty = sema.typeOf(indexable);
2878728790 const pt = sema.pt;
28788 const mod = pt.zcu;
28791 const zcu = pt.zcu;
2878928792
2879028793 try checkIndexable(sema, block, src, indexable_ty);
2879128794
......@@ -28793,8 +28796,8 @@ fn elemVal(
2879328796 // index is a scalar or vector instead of unconditionally casting to usize.
2879428797 const elem_index = try sema.coerce(block, Type.usize, elem_index_uncasted, elem_index_src);
2879528798
28796 switch (indexable_ty.zigTypeTag(mod)) {
28797 .Pointer => switch (indexable_ty.ptrSize(mod)) {
28799 switch (indexable_ty.zigTypeTag(zcu)) {
28800 .Pointer => switch (indexable_ty.ptrSize(zcu)) {
2879828801 .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
2879928802 .Many, .C => {
2880028803 const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
......@@ -28804,7 +28807,7 @@ fn elemVal(
2880428807 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
2880528808 const index_val = maybe_index_val orelse break :rs elem_index_src;
2880628809 const index: usize = @intCast(try index_val.toUnsignedIntSema(pt));
28807 const elem_ty = indexable_ty.elemType2(mod);
28810 const elem_ty = indexable_ty.elemType2(zcu);
2880828811 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);
2880928812 const many_ptr_val = try pt.getCoerced(indexable_val, many_ptr_ty);
2881028813 const elem_ptr_ty = try pt.singleConstPtrType(elem_ty);
......@@ -28820,12 +28823,12 @@ fn elemVal(
2882028823 },
2882128824 .One => {
2882228825 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;
28826 const inner_ty = indexable_ty.childType(zcu);
28827 if (inner_ty.zigTypeTag(zcu) != .Array) break :arr_sent;
28828 const sentinel = inner_ty.sentinel(zcu) orelse break :arr_sent;
2882628829 const index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index) orelse break :arr_sent;
2882728830 const index = try sema.usizeCast(block, src, try index_val.toUnsignedIntSema(pt));
28828 if (index != inner_ty.arrayLen(mod)) break :arr_sent;
28831 if (index != inner_ty.arrayLen(zcu)) break :arr_sent;
2882928832 return Air.internedToRef(sentinel.toIntern());
2883028833 }
2883128834 const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety);
......@@ -28857,7 +28860,7 @@ fn validateRuntimeElemAccess(
2885728860 parent_ty: Type,
2885828861 parent_src: LazySrcLoc,
2885928862) CompileError!void {
28860 if (try sema.typeRequiresComptime(elem_ty)) {
28863 if (try elem_ty.comptimeOnlySema(sema.pt)) {
2886128864 const msg = msg: {
2886228865 const msg = try sema.errMsg(
2886328866 elem_index_src,
......@@ -28884,11 +28887,11 @@ fn tupleFieldPtr(
2888428887 init: bool,
2888528888) CompileError!Air.Inst.Ref {
2888628889 const pt = sema.pt;
28887 const mod = pt.zcu;
28890 const zcu = pt.zcu;
2888828891 const tuple_ptr_ty = sema.typeOf(tuple_ptr);
28889 const tuple_ty = tuple_ptr_ty.childType(mod);
28892 const tuple_ty = tuple_ptr_ty.childType(zcu);
2889028893 try tuple_ty.resolveFields(pt);
28891 const field_count = tuple_ty.structFieldCount(mod);
28894 const field_count = tuple_ty.structFieldCount(zcu);
2889228895
2889328896 if (field_count == 0) {
2889428897 return sema.fail(block, tuple_ptr_src, "indexing into empty tuple is not allowed", .{});
......@@ -28900,17 +28903,17 @@ fn tupleFieldPtr(
2890028903 });
2890128904 }
2890228905
28903 const field_ty = tuple_ty.structFieldType(field_index, mod);
28906 const field_ty = tuple_ty.fieldType(field_index, zcu);
2890428907 const ptr_field_ty = try pt.ptrTypeSema(.{
2890528908 .child = field_ty.toIntern(),
2890628909 .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),
28910 .is_const = !tuple_ptr_ty.ptrIsMutable(zcu),
28911 .is_volatile = tuple_ptr_ty.isVolatilePtr(zcu),
28912 .address_space = tuple_ptr_ty.ptrAddressSpace(zcu),
2891028913 },
2891128914 });
2891228915
28913 if (tuple_ty.structFieldIsComptime(field_index, mod))
28916 if (tuple_ty.structFieldIsComptime(field_index, zcu))
2891428917 try tuple_ty.resolveStructFieldInits(pt);
2891528918
2891628919 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_val| {
......@@ -28943,10 +28946,10 @@ fn tupleField(
2894328946 field_index: u32,
2894428947) CompileError!Air.Inst.Ref {
2894528948 const pt = sema.pt;
28946 const mod = pt.zcu;
28949 const zcu = pt.zcu;
2894728950 const tuple_ty = sema.typeOf(tuple);
2894828951 try tuple_ty.resolveFields(pt);
28949 const field_count = tuple_ty.structFieldCount(mod);
28952 const field_count = tuple_ty.structFieldCount(zcu);
2895028953
2895128954 if (field_count == 0) {
2895228955 return sema.fail(block, tuple_src, "indexing into empty tuple is not allowed", .{});
......@@ -28958,16 +28961,16 @@ fn tupleField(
2895828961 });
2895928962 }
2896028963
28961 const field_ty = tuple_ty.structFieldType(field_index, mod);
28964 const field_ty = tuple_ty.fieldType(field_index, zcu);
2896228965
28963 if (tuple_ty.structFieldIsComptime(field_index, mod))
28966 if (tuple_ty.structFieldIsComptime(field_index, zcu))
2896428967 try tuple_ty.resolveStructFieldInits(pt);
2896528968 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {
2896628969 return Air.internedToRef(default_value.toIntern()); // comptime field
2896728970 }
2896828971
2896928972 if (try sema.resolveValue(tuple)) |tuple_val| {
28970 if (tuple_val.isUndef(mod)) return pt.undefRef(field_ty);
28973 if (tuple_val.isUndef(zcu)) return pt.undefRef(field_ty);
2897128974 return Air.internedToRef((try tuple_val.fieldValue(pt, field_index)).toIntern());
2897228975 }
2897328976
......@@ -28989,12 +28992,12 @@ fn elemValArray(
2898928992 oob_safety: bool,
2899028993) CompileError!Air.Inst.Ref {
2899128994 const pt = sema.pt;
28992 const mod = pt.zcu;
28995 const zcu = pt.zcu;
2899328996 const array_ty = sema.typeOf(array);
28994 const array_sent = array_ty.sentinel(mod);
28995 const array_len = array_ty.arrayLen(mod);
28997 const array_sent = array_ty.sentinel(zcu);
28998 const array_len = array_ty.arrayLen(zcu);
2899628999 const array_len_s = array_len + @intFromBool(array_sent != null);
28997 const elem_ty = array_ty.childType(mod);
29000 const elem_ty = array_ty.childType(zcu);
2899829001
2899929002 if (array_len_s == 0) {
2900029003 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});
......@@ -29017,7 +29020,7 @@ fn elemValArray(
2901729020 }
2901829021 }
2901929022 if (maybe_undef_array_val) |array_val| {
29020 if (array_val.isUndef(mod)) {
29023 if (array_val.isUndef(zcu)) {
2902129024 return pt.undefRef(elem_ty);
2902229025 }
2902329026 if (maybe_index_val) |index_val| {
......@@ -29058,11 +29061,11 @@ fn elemPtrArray(
2905829061 oob_safety: bool,
2905929062) CompileError!Air.Inst.Ref {
2906029063 const pt = sema.pt;
29061 const mod = pt.zcu;
29064 const zcu = pt.zcu;
2906229065 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);
29066 const array_ty = array_ptr_ty.childType(zcu);
29067 const array_sent = array_ty.sentinel(zcu) != null;
29068 const array_len = array_ty.arrayLen(zcu);
2906629069 const array_len_s = array_len + @intFromBool(array_sent);
2906729070
2906829071 if (array_len_s == 0) {
......@@ -29083,7 +29086,7 @@ fn elemPtrArray(
2908329086 const elem_ptr_ty = try array_ptr_ty.elemPtrType(offset, pt);
2908429087
2908529088 if (maybe_undef_array_ptr_val) |array_ptr_val| {
29086 if (array_ptr_val.isUndef(mod)) {
29089 if (array_ptr_val.isUndef(zcu)) {
2908729090 return pt.undefRef(elem_ptr_ty);
2908829091 }
2908929092 if (offset) |index| {
......@@ -29093,7 +29096,7 @@ fn elemPtrArray(
2909329096 }
2909429097
2909529098 if (!init) {
29096 try sema.validateRuntimeElemAccess(block, elem_index_src, array_ty.elemType2(mod), array_ty, array_ptr_src);
29099 try sema.validateRuntimeElemAccess(block, elem_index_src, array_ty.elemType2(zcu), array_ty, array_ptr_src);
2909729100 }
2909829101
2909929102 const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src;
......@@ -29120,10 +29123,10 @@ fn elemValSlice(
2912029123 oob_safety: bool,
2912129124) CompileError!Air.Inst.Ref {
2912229125 const pt = sema.pt;
29123 const mod = pt.zcu;
29126 const zcu = pt.zcu;
2912429127 const slice_ty = sema.typeOf(slice);
29125 const slice_sent = slice_ty.sentinel(mod) != null;
29126 const elem_ty = slice_ty.elemType2(mod);
29128 const slice_sent = slice_ty.sentinel(zcu) != null;
29129 const elem_ty = slice_ty.elemType2(zcu);
2912729130 var runtime_src = slice_src;
2912829131
2912929132 // slice must be defined since it can dereferenced as null
......@@ -29178,9 +29181,9 @@ fn elemPtrSlice(
2917829181 oob_safety: bool,
2917929182) CompileError!Air.Inst.Ref {
2918029183 const pt = sema.pt;
29181 const mod = pt.zcu;
29184 const zcu = pt.zcu;
2918229185 const slice_ty = sema.typeOf(slice);
29183 const slice_sent = slice_ty.sentinel(mod) != null;
29186 const slice_sent = slice_ty.sentinel(zcu) != null;
2918429187
2918529188 const maybe_undef_slice_val = try sema.resolveValue(slice);
2918629189 // The index must not be undefined since it can be out of bounds.
......@@ -29192,7 +29195,7 @@ fn elemPtrSlice(
2919229195 const elem_ptr_ty = try slice_ty.elemPtrType(offset, pt);
2919329196
2919429197 if (maybe_undef_slice_val) |slice_val| {
29195 if (slice_val.isUndef(mod)) {
29198 if (slice_val.isUndef(zcu)) {
2919629199 return pt.undefRef(elem_ptr_ty);
2919729200 }
2919829201 const slice_len = try slice_val.sliceLen(pt);
......@@ -29217,7 +29220,7 @@ fn elemPtrSlice(
2921729220 if (oob_safety and block.wantSafety()) {
2921829221 const len_inst = len: {
2921929222 if (maybe_undef_slice_val) |slice_val|
29220 if (!slice_val.isUndef(mod))
29223 if (!slice_val.isUndef(zcu))
2922129224 break :len try pt.intRef(Type.usize, try slice_val.sliceLen(pt));
2922229225 break :len try block.addTyOp(.slice_len, Type.usize, slice);
2922329226 };
......@@ -29600,7 +29603,7 @@ fn coerceExtra(
2960029603 // empty tuple to zero-length slice
2960129604 // note that this allows coercing to a mutable slice.
2960229605 if (inst_child_ty.structFieldCount(zcu) == 0) {
29603 const align_val = try dest_ty.ptrAlignmentAdvanced(pt, .sema);
29606 const align_val = try dest_ty.ptrAlignmentSema(pt);
2960429607 return Air.internedToRef(try pt.intern(.{ .slice = .{
2960529608 .ty = dest_ty.toIntern(),
2960629609 .ptr = try pt.intern(.{ .ptr = .{
......@@ -30098,7 +30101,7 @@ const InMemoryCoercionResult = union(enum) {
3009830101 return res;
3009930102 }
3010030103
30101 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Module.ErrorMsg) !void {
30104 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Zcu.ErrorMsg) !void {
3010230105 const pt = sema.pt;
3010330106 var cur = res;
3010430107 while (true) switch (cur.*) {
......@@ -30364,18 +30367,18 @@ pub fn coerceInMemoryAllowed(
3036430367 src_val: ?Value,
3036530368) CompileError!InMemoryCoercionResult {
3036630369 const pt = sema.pt;
30367 const mod = pt.zcu;
30370 const zcu = pt.zcu;
3036830371
30369 if (dest_ty.eql(src_ty, mod))
30372 if (dest_ty.eql(src_ty, zcu))
3037030373 return .ok;
3037130374
30372 const dest_tag = dest_ty.zigTypeTag(mod);
30373 const src_tag = src_ty.zigTypeTag(mod);
30375 const dest_tag = dest_ty.zigTypeTag(zcu);
30376 const src_tag = src_ty.zigTypeTag(zcu);
3037430377
3037530378 // Differently-named integers with the same number of bits.
3037630379 if (dest_tag == .Int and src_tag == .Int) {
30377 const dest_info = dest_ty.intInfo(mod);
30378 const src_info = src_ty.intInfo(mod);
30380 const dest_info = dest_ty.intInfo(zcu);
30381 const src_info = src_ty.intInfo(zcu);
3037930382
3038030383 if (dest_info.signedness == src_info.signedness and
3038130384 dest_info.bits == src_info.bits)
......@@ -30425,7 +30428,7 @@ pub fn coerceInMemoryAllowed(
3042530428 }
3042630429
3042730430 // Slices
30428 if (dest_ty.isSlice(mod) and src_ty.isSlice(mod)) {
30431 if (dest_ty.isSlice(zcu) and src_ty.isSlice(zcu)) {
3042930432 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src);
3043030433 }
3043130434
......@@ -30436,8 +30439,8 @@ pub fn coerceInMemoryAllowed(
3043630439
3043730440 // Error Unions
3043830441 if (dest_tag == .ErrorUnion and src_tag == .ErrorUnion) {
30439 const dest_payload = dest_ty.errorUnionPayload(mod);
30440 const src_payload = src_ty.errorUnionPayload(mod);
30442 const dest_payload = dest_ty.errorUnionPayload(zcu);
30443 const src_payload = src_ty.errorUnionPayload(zcu);
3044130444 const child = try sema.coerceInMemoryAllowed(block, dest_payload, src_payload, dest_is_mut, target, dest_src, src_src, null);
3044230445 if (child != .ok) {
3044330446 return InMemoryCoercionResult{ .error_union_payload = .{
......@@ -30446,7 +30449,7 @@ pub fn coerceInMemoryAllowed(
3044630449 .wanted = dest_payload,
3044730450 } };
3044830451 }
30449 return try sema.coerceInMemoryAllowed(block, dest_ty.errorUnionSet(mod), src_ty.errorUnionSet(mod), dest_is_mut, target, dest_src, src_src, null);
30452 return try sema.coerceInMemoryAllowed(block, dest_ty.errorUnionSet(zcu), src_ty.errorUnionSet(zcu), dest_is_mut, target, dest_src, src_src, null);
3045030453 }
3045130454
3045230455 // Error Sets
......@@ -30456,8 +30459,8 @@ pub fn coerceInMemoryAllowed(
3045630459
3045730460 // Arrays
3045830461 if (dest_tag == .Array and src_tag == .Array) {
30459 const dest_info = dest_ty.arrayInfo(mod);
30460 const src_info = src_ty.arrayInfo(mod);
30462 const dest_info = dest_ty.arrayInfo(zcu);
30463 const src_info = src_ty.arrayInfo(zcu);
3046130464 if (dest_info.len != src_info.len) {
3046230465 return InMemoryCoercionResult{ .array_len = .{
3046330466 .actual = src_info.len,
......@@ -30483,7 +30486,7 @@ pub fn coerceInMemoryAllowed(
3048330486 dest_info.sentinel.?.eql(
3048430487 try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type),
3048530488 dest_info.elem_type,
30486 mod,
30489 zcu,
3048730490 ));
3048830491 if (!ok_sent) {
3048930492 return InMemoryCoercionResult{ .array_sentinel = .{
......@@ -30497,8 +30500,8 @@ pub fn coerceInMemoryAllowed(
3049730500
3049830501 // Vectors
3049930502 if (dest_tag == .Vector and src_tag == .Vector) {
30500 const dest_len = dest_ty.vectorLen(mod);
30501 const src_len = src_ty.vectorLen(mod);
30503 const dest_len = dest_ty.vectorLen(zcu);
30504 const src_len = src_ty.vectorLen(zcu);
3050230505 if (dest_len != src_len) {
3050330506 return InMemoryCoercionResult{ .vector_len = .{
3050430507 .actual = src_len,
......@@ -30506,8 +30509,8 @@ pub fn coerceInMemoryAllowed(
3050630509 } };
3050730510 }
3050830511
30509 const dest_elem_ty = dest_ty.scalarType(mod);
30510 const src_elem_ty = src_ty.scalarType(mod);
30512 const dest_elem_ty = dest_ty.scalarType(zcu);
30513 const src_elem_ty = src_ty.scalarType(zcu);
3051130514 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);
3051230515 if (child != .ok) {
3051330516 return InMemoryCoercionResult{ .vector_elem = .{
......@@ -30524,8 +30527,8 @@ pub fn coerceInMemoryAllowed(
3052430527 if ((dest_tag == .Vector and src_tag == .Array) or
3052530528 (dest_tag == .Array and src_tag == .Vector))
3052630529 {
30527 const dest_len = dest_ty.arrayLen(mod);
30528 const src_len = src_ty.arrayLen(mod);
30530 const dest_len = dest_ty.arrayLen(zcu);
30531 const src_len = src_ty.arrayLen(zcu);
3052930532 if (dest_len != src_len) {
3053030533 return InMemoryCoercionResult{ .array_len = .{
3053130534 .actual = src_len,
......@@ -30533,8 +30536,8 @@ pub fn coerceInMemoryAllowed(
3053330536 } };
3053430537 }
3053530538
30536 const dest_elem_ty = dest_ty.childType(mod);
30537 const src_elem_ty = src_ty.childType(mod);
30539 const dest_elem_ty = dest_ty.childType(zcu);
30540 const src_elem_ty = src_ty.childType(zcu);
3053830541 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);
3053930542 if (child != .ok) {
3054030543 return InMemoryCoercionResult{ .array_elem = .{
......@@ -30545,7 +30548,7 @@ pub fn coerceInMemoryAllowed(
3054530548 }
3054630549
3054730550 if (dest_tag == .Array) {
30548 const dest_info = dest_ty.arrayInfo(mod);
30551 const dest_info = dest_ty.arrayInfo(zcu);
3054930552 if (dest_info.sentinel != null) {
3055030553 return InMemoryCoercionResult{ .array_sentinel = .{
3055130554 .actual = Value.@"unreachable",
......@@ -30558,8 +30561,8 @@ pub fn coerceInMemoryAllowed(
3055830561 // The memory layout of @Vector(N, iM) is the same as the integer type i(N*M),
3055930562 // that is to say, the padding bits are not in the same place as the array [N]iM.
3056030563 // 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);
30564 const elem_bit_size = dest_elem_ty.bitSize(zcu);
30565 const elem_abi_byte_size = dest_elem_ty.abiSize(zcu);
3056330566 if (elem_abi_byte_size * 8 == elem_bit_size)
3056430567 return .ok;
3056530568 }
......@@ -30572,8 +30575,8 @@ pub fn coerceInMemoryAllowed(
3057230575 .wanted = dest_ty,
3057330576 } };
3057430577 }
30575 const dest_child_type = dest_ty.optionalChild(mod);
30576 const src_child_type = src_ty.optionalChild(mod);
30578 const dest_child_type = dest_ty.optionalChild(zcu);
30579 const src_child_type = src_ty.optionalChild(zcu);
3057730580
3057830581 const child = try sema.coerceInMemoryAllowed(block, dest_child_type, src_child_type, dest_is_mut, target, dest_src, src_src, null);
3057930582 if (child != .ok) {
......@@ -30588,15 +30591,15 @@ pub fn coerceInMemoryAllowed(
3058830591 }
3058930592
3059030593 // 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);
30594 if (dest_ty.isTuple(zcu) and src_ty.isTuple(zcu)) tuple: {
30595 if (dest_ty.containerLayout(zcu) != src_ty.containerLayout(zcu)) break :tuple;
30596 if (dest_ty.structFieldCount(zcu) != src_ty.structFieldCount(zcu)) break :tuple;
30597 const field_count = dest_ty.structFieldCount(zcu);
3059530598 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);
30599 if (dest_ty.structFieldIsComptime(field_idx, zcu) != src_ty.structFieldIsComptime(field_idx, zcu)) break :tuple;
30600 if (dest_ty.fieldAlignment(field_idx, zcu) != src_ty.fieldAlignment(field_idx, zcu)) break :tuple;
30601 const dest_field_ty = dest_ty.fieldType(field_idx, zcu);
30602 const src_field_ty = src_ty.fieldType(field_idx, zcu);
3060030603 const field = try sema.coerceInMemoryAllowed(block, dest_field_ty, src_field_ty, dest_is_mut, target, dest_src, src_src, null);
3060130604 if (field != .ok) break :tuple;
3060230605 }
......@@ -30618,13 +30621,13 @@ fn coerceInMemoryAllowedErrorSets(
3061830621 src_src: LazySrcLoc,
3061930622) !InMemoryCoercionResult {
3062030623 const pt = sema.pt;
30621 const mod = pt.zcu;
30624 const zcu = pt.zcu;
3062230625 const gpa = sema.gpa;
30623 const ip = &mod.intern_pool;
30626 const ip = &zcu.intern_pool;
3062430627
3062530628 // Coercion to `anyerror`. Note that this check can return false negatives
3062630629 // in case the error sets did not get resolved.
30627 if (dest_ty.isAnyError(mod)) {
30630 if (dest_ty.isAnyError(zcu)) {
3062830631 return .ok;
3062930632 }
3063030633
......@@ -30669,7 +30672,7 @@ fn coerceInMemoryAllowedErrorSets(
3066930672 const resolved_src_ty = try sema.resolveInferredErrorSet(block, src_src, src_ty.toIntern());
3067030673 // src anyerror status might have changed after the resolution.
3067130674 if (resolved_src_ty == .anyerror_type) {
30672 // dest_ty.isAnyError(mod) == true is already checked for at this point.
30675 // dest_ty.isAnyError(zcu) == true is already checked for at this point.
3067330676 return .from_anyerror;
3067430677 }
3067530678
......@@ -30717,11 +30720,11 @@ fn coerceInMemoryAllowedFns(
3071730720 src_src: LazySrcLoc,
3071830721) !InMemoryCoercionResult {
3071930722 const pt = sema.pt;
30720 const mod = pt.zcu;
30721 const ip = &mod.intern_pool;
30723 const zcu = pt.zcu;
30724 const ip = &zcu.intern_pool;
3072230725
30723 const dest_info = mod.typeToFunc(dest_ty).?;
30724 const src_info = mod.typeToFunc(src_ty).?;
30726 const dest_info = zcu.typeToFunc(dest_ty).?;
30727 const src_info = zcu.typeToFunc(src_ty).?;
3072530728
3072630729 {
3072730730 if (dest_info.is_var_args != src_info.is_var_args) {
......@@ -30922,12 +30925,12 @@ fn coerceInMemoryAllowedPtrs(
3092230925 const src_align = if (src_info.flags.alignment != .none)
3092330926 src_info.flags.alignment
3092430927 else
30925 try sema.typeAbiAlignment(Type.fromInterned(src_info.child));
30928 try Type.fromInterned(src_info.child).abiAlignmentSema(pt);
3092630929
3092730930 const dest_align = if (dest_info.flags.alignment != .none)
3092830931 dest_info.flags.alignment
3092930932 else
30930 try sema.typeAbiAlignment(Type.fromInterned(dest_info.child));
30933 try Type.fromInterned(dest_info.child).abiAlignmentSema(pt);
3093130934
3093230935 if (dest_align.compare(.gt, src_align)) {
3093330936 return InMemoryCoercionResult{ .ptr_alignment = .{
......@@ -31044,12 +31047,12 @@ fn storePtr2(
3104431047 air_tag: Air.Inst.Tag,
3104531048) CompileError!void {
3104631049 const pt = sema.pt;
31047 const mod = pt.zcu;
31050 const zcu = pt.zcu;
3104831051 const ptr_ty = sema.typeOf(ptr);
31049 if (ptr_ty.isConstPtr(mod))
31052 if (ptr_ty.isConstPtr(zcu))
3105031053 return sema.fail(block, ptr_src, "cannot assign to constant", .{});
3105131054
31052 const elem_ty = ptr_ty.childType(mod);
31055 const elem_ty = ptr_ty.childType(zcu);
3105331056
3105431057 // To generate better code for tuples, we detect a tuple operand here, and
3105531058 // analyze field loads and stores directly. This avoids an extra allocation + memcpy
......@@ -31060,8 +31063,8 @@ fn storePtr2(
3106031063 // this code does not handle tuple-to-struct coercion which requires dealing with missing
3106131064 // fields.
3106231065 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);
31066 if (operand_ty.isTuple(zcu) and elem_ty.zigTypeTag(zcu) == .Array) {
31067 const field_count = operand_ty.structFieldCount(zcu);
3106531068 var i: u32 = 0;
3106631069 while (i < field_count) : (i += 1) {
3106731070 const elem_src = operand_src; // TODO better source location
......@@ -31085,7 +31088,7 @@ fn storePtr2(
3108531088 // as well as working around an LLVM bug:
3108631089 // https://github.com/ziglang/zig/issues/11154
3108731090 if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| {
31088 const vector_ty = sema.typeOf(vector_ptr).childType(mod);
31091 const vector_ty = sema.typeOf(vector_ptr).childType(zcu);
3108931092 const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
3109031093 error.NotCoercible => unreachable,
3109131094 else => |e| return e,
......@@ -31119,7 +31122,7 @@ fn storePtr2(
3111931122
3112031123 try sema.requireRuntimeBlock(block, src, runtime_src);
3112131124
31122 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
31125 if (ptr_ty.ptrInfo(zcu).flags.vector_index == .runtime) {
3112331126 const ptr_inst = ptr.toIndex().?;
3112431127 const air_tags = sema.air_instructions.items(.tag);
3112531128 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
......@@ -31253,9 +31256,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3125331256/// lengths match.
3125431257fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
3125531258 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;
31259 const zcu = pt.zcu;
31260 const array_ty = sema.typeOf(ptr).childType(zcu);
31261 if (array_ty.zigTypeTag(zcu) != .Array) return null;
3125931262 var ptr_ref = ptr;
3126031263 var ptr_inst = ptr_ref.toIndex() orelse return null;
3126131264 const air_datas = sema.air_instructions.items(.data);
......@@ -31263,15 +31266,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
3126331266 const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
3126431267 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
3126531268 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;
31269 const child_ty = sema.typeOf(ptr_ref).childType(zcu);
31270 if (child_ty.zigTypeTag(zcu) == .Vector) break child_ty;
3126831271 ptr_inst = ptr_ref.toIndex() orelse return null;
3126931272 } else return null;
3127031273
3127131274 // We have a pointer-to-array and a pointer-to-vector. If the elements and
3127231275 // 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))
31276 if (array_ty.childType(zcu).eql(vector_ty.childType(zcu), zcu) and
31277 array_ty.arrayLen(zcu) == vector_ty.vectorLen(zcu))
3127531278 {
3127631279 return ptr_ref;
3127731280 } else {
......@@ -31347,8 +31350,8 @@ fn bitCast(
3134731350 const old_ty = sema.typeOf(inst);
3134831351 try old_ty.resolveLayout(pt);
3134931352
31350 const dest_bits = dest_ty.bitSize(pt);
31351 const old_bits = old_ty.bitSize(pt);
31353 const dest_bits = dest_ty.bitSize(zcu);
31354 const old_bits = old_ty.bitSize(zcu);
3135231355
3135331356 if (old_bits != dest_bits) {
3135431357 return sema.fail(block, inst_src, "@bitCast size mismatch: destination type '{}' has {d} bits but source type '{}' has {d} bits", .{
......@@ -31384,16 +31387,16 @@ fn coerceArrayPtrToSlice(
3138431387 inst_src: LazySrcLoc,
3138531388) CompileError!Air.Inst.Ref {
3138631389 const pt = sema.pt;
31387 const mod = pt.zcu;
31390 const zcu = pt.zcu;
3138831391 if (try sema.resolveValue(inst)) |val| {
3138931392 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);
31393 const array_ty = ptr_array_ty.childType(zcu);
31394 const slice_ptr_ty = dest_ty.slicePtrFieldType(zcu);
3139231395 const slice_ptr = try pt.getCoerced(val, slice_ptr_ty);
3139331396 const slice_val = try pt.intern(.{ .slice = .{
3139431397 .ty = dest_ty.toIntern(),
3139531398 .ptr = slice_ptr.toIntern(),
31396 .len = (try pt.intValue(Type.usize, array_ty.arrayLen(mod))).toIntern(),
31399 .len = (try pt.intValue(Type.usize, array_ty.arrayLen(zcu))).toIntern(),
3139731400 } });
3139831401 return Air.internedToRef(slice_val);
3139931402 }
......@@ -31403,12 +31406,12 @@ fn coerceArrayPtrToSlice(
3140331406
3140431407fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_result: *InMemoryCoercionResult) bool {
3140531408 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);
31409 const zcu = pt.zcu;
31410 const dest_info = dest_ty.ptrInfo(zcu);
31411 const inst_info = inst_ty.ptrInfo(zcu);
31412 const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(zcu) == .Array and (Type.fromInterned(inst_info.child).arrayLenIncludingSentinel(zcu) == 0 or
31413 (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
31414 (Type.fromInterned(inst_info.child).isTuple(zcu) and Type.fromInterned(inst_info.child).structFieldCount(zcu) == 0);
3141231415
3141331416 const ok_cv_qualifiers =
3141431417 ((!inst_info.flags.is_const or dest_info.flags.is_const) or len0) and
......@@ -31436,12 +31439,12 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul
3143631439 const inst_align = if (inst_info.flags.alignment != .none)
3143731440 inst_info.flags.alignment
3143831441 else
31439 Type.fromInterned(inst_info.child).abiAlignment(pt);
31442 Type.fromInterned(inst_info.child).abiAlignment(zcu);
3144031443
3144131444 const dest_align = if (dest_info.flags.alignment != .none)
3144231445 dest_info.flags.alignment
3144331446 else
31444 Type.fromInterned(dest_info.child).abiAlignment(pt);
31447 Type.fromInterned(dest_info.child).abiAlignment(zcu);
3144531448
3144631449 if (dest_align.compare(.gt, inst_align)) {
3144731450 in_memory_result.* = .{ .ptr_alignment = .{
......@@ -31461,10 +31464,10 @@ fn coerceCompatiblePtrs(
3146131464 inst_src: LazySrcLoc,
3146231465) !Air.Inst.Ref {
3146331466 const pt = sema.pt;
31464 const mod = pt.zcu;
31467 const zcu = pt.zcu;
3146531468 const inst_ty = sema.typeOf(inst);
3146631469 if (try sema.resolveValue(inst)) |val| {
31467 if (!val.isUndef(mod) and val.isNull(mod) and !dest_ty.isAllowzeroPtr(mod)) {
31470 if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) {
3146831471 return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});
3146931472 }
3147031473 // The comptime Value representation is compatible with both types.
......@@ -31473,17 +31476,17 @@ fn coerceCompatiblePtrs(
3147331476 );
3147431477 }
3147531478 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))
31479 const inst_allows_zero = inst_ty.zigTypeTag(zcu) != .Pointer or inst_ty.ptrAllowsZero(zcu);
31480 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(zcu) and
31481 (try dest_ty.elemType2(zcu).hasRuntimeBitsSema(pt) or dest_ty.elemType2(zcu).zigTypeTag(zcu) == .Fn))
3147931482 {
31480 const actual_ptr = if (inst_ty.isSlice(mod))
31483 const actual_ptr = if (inst_ty.isSlice(zcu))
3148131484 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
3148231485 else
3148331486 inst;
3148431487 const ptr_int = try block.addUnOp(.int_from_ptr, actual_ptr);
3148531488 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
31486 const ok = if (inst_ty.isSlice(mod)) ok: {
31489 const ok = if (inst_ty.isSlice(zcu)) ok: {
3148731490 const len = try sema.analyzeSliceLen(block, inst_src, inst);
3148831491 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
3148931492 break :ok try block.addBinOp(.bool_or, len_zero, is_non_zero);
......@@ -31504,11 +31507,11 @@ fn coerceEnumToUnion(
3150431507 inst_src: LazySrcLoc,
3150531508) !Air.Inst.Ref {
3150631509 const pt = sema.pt;
31507 const mod = pt.zcu;
31508 const ip = &mod.intern_pool;
31510 const zcu = pt.zcu;
31511 const ip = &zcu.intern_pool;
3150931512 const inst_ty = sema.typeOf(inst);
3151031513
31511 const tag_ty = union_ty.unionTagType(mod) orelse {
31514 const tag_ty = union_ty.unionTagType(zcu) orelse {
3151231515 const msg = msg: {
3151331516 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3151431517 union_ty.fmt(pt), inst_ty.fmt(pt),
......@@ -31529,10 +31532,10 @@ fn coerceEnumToUnion(
3152931532 });
3153031533 };
3153131534
31532 const union_obj = mod.typeToUnion(union_ty).?;
31535 const union_obj = zcu.typeToUnion(union_ty).?;
3153331536 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3153431537 try field_ty.resolveFields(pt);
31535 if (field_ty.zigTypeTag(mod) == .NoReturn) {
31538 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
3153631539 const msg = msg: {
3153731540 const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{});
3153831541 errdefer msg.destroy(sema.gpa);
......@@ -31569,7 +31572,7 @@ fn coerceEnumToUnion(
3156931572
3157031573 try sema.requireRuntimeBlock(block, inst_src, null);
3157131574
31572 if (tag_ty.isNonexhaustiveEnum(mod)) {
31575 if (tag_ty.isNonexhaustiveEnum(zcu)) {
3157331576 const msg = msg: {
3157431577 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
3157531578 union_ty.fmt(pt),
......@@ -31581,13 +31584,13 @@ fn coerceEnumToUnion(
3158131584 return sema.failWithOwnedErrorMsg(block, msg);
3158231585 }
3158331586
31584 const union_obj = mod.typeToUnion(union_ty).?;
31587 const union_obj = zcu.typeToUnion(union_ty).?;
3158531588 {
31586 var msg: ?*Module.ErrorMsg = null;
31589 var msg: ?*Zcu.ErrorMsg = null;
3158731590 errdefer if (msg) |some| some.destroy(sema.gpa);
3158831591
3158931592 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
31590 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {
31593 if (Type.fromInterned(field_ty).zigTypeTag(zcu) == .NoReturn) {
3159131594 const err_msg = msg orelse try sema.errMsg(
3159231595 inst_src,
3159331596 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",
......@@ -31606,7 +31609,7 @@ fn coerceEnumToUnion(
3160631609 }
3160731610
3160831611 // If the union has all fields 0 bits, the union value is just the enum value.
31609 if (union_ty.unionHasAllZeroBitFieldTypes(pt)) {
31612 if (union_ty.unionHasAllZeroBitFieldTypes(zcu)) {
3161031613 return block.addBitCast(union_ty, enum_tag);
3161131614 }
3161231615
......@@ -31621,7 +31624,7 @@ fn coerceEnumToUnion(
3162131624 for (0..union_obj.field_types.len) |field_index| {
3162231625 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
3162331626 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
31624 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
31627 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
3162531628 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
3162631629 field_name.fmt(ip),
3162731630 field_ty.fmt(pt),
......@@ -31642,8 +31645,8 @@ fn coerceAnonStructToUnion(
3164231645 inst_src: LazySrcLoc,
3164331646) !Air.Inst.Ref {
3164431647 const pt = sema.pt;
31645 const mod = pt.zcu;
31646 const ip = &mod.intern_pool;
31648 const zcu = pt.zcu;
31649 const ip = &zcu.intern_pool;
3164731650 const inst_ty = sema.typeOf(inst);
3164831651 const field_info: union(enum) {
3164931652 name: InternPool.NullTerminatedString,
......@@ -31701,8 +31704,8 @@ fn coerceAnonStructToUnionPtrs(
3170131704 anon_struct_src: LazySrcLoc,
3170231705) !Air.Inst.Ref {
3170331706 const pt = sema.pt;
31704 const mod = pt.zcu;
31705 const union_ty = ptr_union_ty.childType(mod);
31707 const zcu = pt.zcu;
31708 const union_ty = ptr_union_ty.childType(zcu);
3170631709 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
3170731710 const union_inst = try sema.coerceAnonStructToUnion(block, union_ty, union_ty_src, anon_struct, anon_struct_src);
3170831711 return sema.analyzeRef(block, union_ty_src, union_inst);
......@@ -31717,8 +31720,8 @@ fn coerceAnonStructToStructPtrs(
3171731720 anon_struct_src: LazySrcLoc,
3171831721) !Air.Inst.Ref {
3171931722 const pt = sema.pt;
31720 const mod = pt.zcu;
31721 const struct_ty = ptr_struct_ty.childType(mod);
31723 const zcu = pt.zcu;
31724 const struct_ty = ptr_struct_ty.childType(zcu);
3172231725 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
3172331726 const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, anon_struct, anon_struct_src);
3172431727 return sema.analyzeRef(block, struct_ty_src, struct_inst);
......@@ -31734,9 +31737,9 @@ fn coerceArrayLike(
3173431737 inst_src: LazySrcLoc,
3173531738) !Air.Inst.Ref {
3173631739 const pt = sema.pt;
31737 const mod = pt.zcu;
31740 const zcu = pt.zcu;
3173831741 const inst_ty = sema.typeOf(inst);
31739 const target = mod.getTarget();
31742 const target = zcu.getTarget();
3174031743
3174131744 // try coercion of the whole array
3174231745 const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src, null);
......@@ -31750,8 +31753,8 @@ fn coerceArrayLike(
3175031753 }
3175131754
3175231755 // 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));
31756 const inst_len = inst_ty.arrayLen(zcu);
31757 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(zcu));
3175531758 if (dest_len != inst_len) {
3175631759 const msg = msg: {
3175731760 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
......@@ -31765,14 +31768,14 @@ fn coerceArrayLike(
3176531768 return sema.failWithOwnedErrorMsg(block, msg);
3176631769 }
3176731770
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)) {
31771 const dest_elem_ty = dest_ty.childType(zcu);
31772 if (dest_ty.isVector(zcu) and inst_ty.isVector(zcu) and (try sema.resolveValue(inst)) == null) {
31773 const inst_elem_ty = inst_ty.childType(zcu);
31774 switch (dest_elem_ty.zigTypeTag(zcu)) {
31775 .Int => if (inst_elem_ty.isInt(zcu)) {
3177331776 // integer widening
31774 const dst_info = dest_elem_ty.intInfo(mod);
31775 const src_info = inst_elem_ty.intInfo(mod);
31777 const dst_info = dest_elem_ty.intInfo(zcu);
31778 const src_info = inst_elem_ty.intInfo(zcu);
3177631779 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or
3177731780 // small enough unsigned ints can get casted to large enough signed ints
3177831781 (dst_info.signedness == .signed and dst_info.bits > src_info.bits))
......@@ -31835,10 +31838,10 @@ fn coerceTupleToArray(
3183531838 inst_src: LazySrcLoc,
3183631839) !Air.Inst.Ref {
3183731840 const pt = sema.pt;
31838 const mod = pt.zcu;
31841 const zcu = pt.zcu;
3183931842 const inst_ty = sema.typeOf(inst);
31840 const inst_len = inst_ty.arrayLen(mod);
31841 const dest_len = dest_ty.arrayLen(mod);
31843 const inst_len = inst_ty.arrayLen(zcu);
31844 const dest_len = dest_ty.arrayLen(zcu);
3184231845
3184331846 if (dest_len != inst_len) {
3184431847 const msg = msg: {
......@@ -31856,13 +31859,13 @@ fn coerceTupleToArray(
3185631859 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len);
3185731860 const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems);
3185831861 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
31859 const dest_elem_ty = dest_ty.childType(mod);
31862 const dest_elem_ty = dest_ty.childType(zcu);
3186031863
3186131864 var runtime_src: ?LazySrcLoc = null;
3186231865 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
3186331866 const i: u32 = @intCast(i_usize);
3186431867 if (i_usize == inst_len) {
31865 const sentinel_val = dest_ty.sentinel(mod).?;
31868 const sentinel_val = dest_ty.sentinel(zcu).?;
3186631869 val.* = sentinel_val.toIntern();
3186731870 ref.* = Air.internedToRef(sentinel_val.toIntern());
3186831871 break;
......@@ -31901,12 +31904,12 @@ fn coerceTupleToSlicePtrs(
3190131904 tuple_src: LazySrcLoc,
3190231905) !Air.Inst.Ref {
3190331906 const pt = sema.pt;
31904 const mod = pt.zcu;
31905 const tuple_ty = sema.typeOf(ptr_tuple).childType(mod);
31907 const zcu = pt.zcu;
31908 const tuple_ty = sema.typeOf(ptr_tuple).childType(zcu);
3190631909 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
31907 const slice_info = slice_ty.ptrInfo(mod);
31910 const slice_info = slice_ty.ptrInfo(zcu);
3190831911 const array_ty = try pt.arrayType(.{
31909 .len = tuple_ty.structFieldCount(mod),
31912 .len = tuple_ty.structFieldCount(zcu),
3191031913 .sentinel = slice_info.sentinel,
3191131914 .child = slice_info.child,
3191231915 });
......@@ -31928,9 +31931,9 @@ fn coerceTupleToArrayPtrs(
3192831931 tuple_src: LazySrcLoc,
3192931932) !Air.Inst.Ref {
3193031933 const pt = sema.pt;
31931 const mod = pt.zcu;
31934 const zcu = pt.zcu;
3193231935 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
31933 const ptr_info = ptr_array_ty.ptrInfo(mod);
31936 const ptr_info = ptr_array_ty.ptrInfo(zcu);
3193431937 const array_ty = Type.fromInterned(ptr_info.child);
3193531938 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
3193631939 if (ptr_info.flags.alignment != .none) {
......@@ -31950,16 +31953,16 @@ fn coerceTupleToStruct(
3195031953 inst_src: LazySrcLoc,
3195131954) !Air.Inst.Ref {
3195231955 const pt = sema.pt;
31953 const mod = pt.zcu;
31954 const ip = &mod.intern_pool;
31956 const zcu = pt.zcu;
31957 const ip = &zcu.intern_pool;
3195531958 try struct_ty.resolveFields(pt);
3195631959 try struct_ty.resolveStructFieldInits(pt);
3195731960
31958 if (struct_ty.isTupleOrAnonStruct(mod)) {
31961 if (struct_ty.isTupleOrAnonStruct(zcu)) {
3195931962 return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src);
3196031963 }
3196131964
31962 const struct_type = mod.typeToStruct(struct_ty).?;
31965 const struct_type = zcu.typeToStruct(struct_ty).?;
3196331966 const field_vals = try sema.arena.alloc(InternPool.Index, struct_type.field_types.len);
3196431967 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
3196531968 @memset(field_refs, .none);
......@@ -31973,7 +31976,7 @@ fn coerceTupleToStruct(
3197331976 };
3197431977 for (0..field_count) |tuple_field_index| {
3197531978 const field_src = inst_src; // TODO better source location
31976 const field_name = inst_ty.structFieldName(tuple_field_index, mod).unwrap() orelse
31979 const field_name = inst_ty.structFieldName(tuple_field_index, zcu).unwrap() orelse
3197731980 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{tuple_field_index}, .no_embedded_nulls);
3197831981
3197931982 const struct_field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);
......@@ -32003,7 +32006,7 @@ fn coerceTupleToStruct(
3200332006 }
3200432007
3200532008 // Populate default field values and report errors for missing fields.
32006 var root_msg: ?*Module.ErrorMsg = null;
32009 var root_msg: ?*Zcu.ErrorMsg = null;
3200732010 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
3200832011
3200932012 for (field_refs, 0..) |*field_ref, i| {
......@@ -32058,8 +32061,8 @@ fn coerceTupleToTuple(
3205832061 inst_src: LazySrcLoc,
3205932062) !Air.Inst.Ref {
3206032063 const pt = sema.pt;
32061 const mod = pt.zcu;
32062 const ip = &mod.intern_pool;
32064 const zcu = pt.zcu;
32065 const ip = &zcu.intern_pool;
3206332066 const dest_field_count = switch (ip.indexToKey(tuple_ty.toIntern())) {
3206432067 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,
3206532068 .struct_type => ip.loadStructType(tuple_ty.toIntern()).field_types.len,
......@@ -32081,7 +32084,7 @@ fn coerceTupleToTuple(
3208132084 for (0..dest_field_count) |field_index_usize| {
3208232085 const field_i: u32 = @intCast(field_index_usize);
3208332086 const field_src = inst_src; // TODO better source location
32084 const field_name = inst_ty.structFieldName(field_index_usize, mod).unwrap() orelse
32087 const field_name = inst_ty.structFieldName(field_index_usize, zcu).unwrap() orelse
3208532088 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_index_usize}, .no_embedded_nulls);
3208632089
3208732090 if (field_name.eqlSlice("len", ip))
......@@ -32124,7 +32127,7 @@ fn coerceTupleToTuple(
3212432127 }
3212532128
3212632129 // Populate default field values and report errors for missing fields.
32127 var root_msg: ?*Module.ErrorMsg = null;
32130 var root_msg: ?*Zcu.ErrorMsg = null;
3212832131 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
3212932132
3213032133 for (field_refs, 0..) |*field_ref, i_usize| {
......@@ -32139,7 +32142,7 @@ fn coerceTupleToTuple(
3213932142
3214032143 const field_src = inst_src; // TODO better source location
3214132144 if (default_val == .none) {
32142 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {
32145 const field_name = tuple_ty.structFieldName(i, zcu).unwrap() orelse {
3214332146 const template = "missing tuple field: {d}";
3214432147 if (root_msg) |msg| {
3214532148 try sema.errNote(field_src, msg, template, .{i});
......@@ -32308,7 +32311,7 @@ fn maybeQueueFuncBodyAnalysis(sema: *Sema, src: LazySrcLoc, nav_index: InternPoo
3230832311 const ip = &zcu.intern_pool;
3230932312 const nav_val = zcu.navValue(nav_index);
3231032313 if (!ip.isFuncBody(nav_val.toIntern())) return;
32311 if (!try sema.fnHasRuntimeBits(nav_val.typeOf(zcu))) return;
32314 if (!try nav_val.typeOf(zcu).fnHasRuntimeBitsSema(sema.pt)) return;
3231232315 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .func = nav_val.toIntern() }));
3231332316 try zcu.ensureFuncBodyAnalysisQueued(nav_val.toIntern());
3231432317}
......@@ -32320,11 +32323,11 @@ fn analyzeRef(
3232032323 operand: Air.Inst.Ref,
3232132324) CompileError!Air.Inst.Ref {
3232232325 const pt = sema.pt;
32323 const mod = pt.zcu;
32326 const zcu = pt.zcu;
3232432327 const operand_ty = sema.typeOf(operand);
3232532328
3232632329 if (try sema.resolveValue(operand)) |val| {
32327 switch (mod.intern_pool.indexToKey(val.toIntern())) {
32330 switch (zcu.intern_pool.indexToKey(val.toIntern())) {
3232832331 .@"extern" => |e| return sema.analyzeNavRef(src, e.owner_nav),
3232932332 .func => |f| return sema.analyzeNavRef(src, f.owner_nav),
3233032333 else => return uavRef(sema, val.toIntern()),
......@@ -32332,7 +32335,7 @@ fn analyzeRef(
3233232335 }
3233332336
3233432337 try sema.requireRuntimeBlock(block, src, null);
32335 const address_space = target_util.defaultAddressSpace(mod.getTarget(), .local);
32338 const address_space = target_util.defaultAddressSpace(zcu.getTarget(), .local);
3233632339 const ptr_type = try pt.ptrTypeSema(.{
3233732340 .child = operand_ty.toIntern(),
3233832341 .flags = .{
......@@ -32359,13 +32362,13 @@ fn analyzeLoad(
3235932362 ptr_src: LazySrcLoc,
3236032363) CompileError!Air.Inst.Ref {
3236132364 const pt = sema.pt;
32362 const mod = pt.zcu;
32365 const zcu = pt.zcu;
3236332366 const ptr_ty = sema.typeOf(ptr);
32364 const elem_ty = switch (ptr_ty.zigTypeTag(mod)) {
32365 .Pointer => ptr_ty.childType(mod),
32367 const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) {
32368 .Pointer => ptr_ty.childType(zcu),
3236632369 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(pt)}),
3236732370 };
32368 if (elem_ty.zigTypeTag(mod) == .Opaque) {
32371 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
3236932372 return sema.fail(block, ptr_src, "cannot load opaque type '{}'", .{elem_ty.fmt(pt)});
3237032373 }
3237132374
......@@ -32379,7 +32382,7 @@ fn analyzeLoad(
3237932382 }
3238032383 }
3238132384
32382 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {
32385 if (ptr_ty.ptrInfo(zcu).flags.vector_index == .runtime) {
3238332386 const ptr_inst = ptr.toIndex().?;
3238432387 const air_tags = sema.air_instructions.items(.tag);
3238532388 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
......@@ -32403,11 +32406,11 @@ fn analyzeSlicePtr(
3240332406 slice_ty: Type,
3240432407) CompileError!Air.Inst.Ref {
3240532408 const pt = sema.pt;
32406 const mod = pt.zcu;
32407 const result_ty = slice_ty.slicePtrFieldType(mod);
32409 const zcu = pt.zcu;
32410 const result_ty = slice_ty.slicePtrFieldType(zcu);
3240832411 if (try sema.resolveValue(slice)) |val| {
32409 if (val.isUndef(mod)) return pt.undefRef(result_ty);
32410 return Air.internedToRef(val.slicePtr(mod).toIntern());
32412 if (val.isUndef(zcu)) return pt.undefRef(result_ty);
32413 return Air.internedToRef(val.slicePtr(zcu).toIntern());
3241132414 }
3241232415 try sema.requireRuntimeBlock(block, slice_src, null);
3241332416 return block.addTyOp(.slice_ptr, result_ty, slice);
......@@ -32421,13 +32424,13 @@ fn analyzeOptionalSlicePtr(
3242132424 opt_slice_ty: Type,
3242232425) CompileError!Air.Inst.Ref {
3242332426 const pt = sema.pt;
32424 const mod = pt.zcu;
32425 const result_ty = opt_slice_ty.optionalChild(mod).slicePtrFieldType(mod);
32427 const zcu = pt.zcu;
32428 const result_ty = opt_slice_ty.optionalChild(zcu).slicePtrFieldType(zcu);
3242632429
3242732430 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()
32431 if (opt_val.isUndef(zcu)) return pt.undefRef(result_ty);
32432 const slice_ptr: InternPool.Index = if (opt_val.optionalValue(zcu)) |val|
32433 val.slicePtr(zcu).toIntern()
3243132434 else
3243232435 .null_value;
3243332436
......@@ -32447,9 +32450,9 @@ fn analyzeSliceLen(
3244732450 slice_inst: Air.Inst.Ref,
3244832451) CompileError!Air.Inst.Ref {
3244932452 const pt = sema.pt;
32450 const mod = pt.zcu;
32453 const zcu = pt.zcu;
3245132454 if (try sema.resolveValue(slice_inst)) |slice_val| {
32452 if (slice_val.isUndef(mod)) {
32455 if (slice_val.isUndef(zcu)) {
3245332456 return pt.undefRef(Type.usize);
3245432457 }
3245532458 return pt.intRef(Type.usize, try slice_val.sliceLen(pt));
......@@ -32466,23 +32469,23 @@ fn analyzeIsNull(
3246632469 invert_logic: bool,
3246732470) CompileError!Air.Inst.Ref {
3246832471 const pt = sema.pt;
32469 const mod = pt.zcu;
32472 const zcu = pt.zcu;
3247032473 const result_ty = Type.bool;
3247132474 if (try sema.resolveValue(operand)) |opt_val| {
32472 if (opt_val.isUndef(mod)) {
32475 if (opt_val.isUndef(zcu)) {
3247332476 return pt.undefRef(result_ty);
3247432477 }
32475 const is_null = opt_val.isNull(mod);
32478 const is_null = opt_val.isNull(zcu);
3247632479 const bool_value = if (invert_logic) !is_null else is_null;
3247732480 return if (bool_value) .bool_true else .bool_false;
3247832481 }
3247932482
3248032483 const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false;
3248132484 const operand_ty = sema.typeOf(operand);
32482 if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(mod).zigTypeTag(mod) == .NoReturn) {
32485 if (operand_ty.zigTypeTag(zcu) == .Optional and operand_ty.optionalChild(zcu).zigTypeTag(zcu) == .NoReturn) {
3248332486 return inverted_non_null_res;
3248432487 }
32485 if (operand_ty.zigTypeTag(mod) != .Optional and !operand_ty.isPtrLikeOptional(mod)) {
32488 if (operand_ty.zigTypeTag(zcu) != .Optional and !operand_ty.isPtrLikeOptional(zcu)) {
3248632489 return inverted_non_null_res;
3248732490 }
3248832491 try sema.requireRuntimeBlock(block, src, null);
......@@ -32497,12 +32500,12 @@ fn analyzePtrIsNonErrComptimeOnly(
3249732500 operand: Air.Inst.Ref,
3249832501) CompileError!Air.Inst.Ref {
3249932502 const pt = sema.pt;
32500 const mod = pt.zcu;
32503 const zcu = pt.zcu;
3250132504 const ptr_ty = sema.typeOf(operand);
32502 assert(ptr_ty.zigTypeTag(mod) == .Pointer);
32503 const child_ty = ptr_ty.childType(mod);
32505 assert(ptr_ty.zigTypeTag(zcu) == .Pointer);
32506 const child_ty = ptr_ty.childType(zcu);
3250432507
32505 const child_tag = child_ty.zigTypeTag(mod);
32508 const child_tag = child_ty.zigTypeTag(zcu);
3250632509 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return .bool_true;
3250732510 if (child_tag == .ErrorSet) return .bool_false;
3250832511 assert(child_tag == .ErrorUnion);
......@@ -32520,16 +32523,16 @@ fn analyzeIsNonErrComptimeOnly(
3252032523 operand: Air.Inst.Ref,
3252132524) CompileError!Air.Inst.Ref {
3252232525 const pt = sema.pt;
32523 const mod = pt.zcu;
32524 const ip = &mod.intern_pool;
32526 const zcu = pt.zcu;
32527 const ip = &zcu.intern_pool;
3252532528 const operand_ty = sema.typeOf(operand);
32526 const ot = operand_ty.zigTypeTag(mod);
32529 const ot = operand_ty.zigTypeTag(zcu);
3252732530 if (ot != .ErrorSet and ot != .ErrorUnion) return .bool_true;
3252832531 if (ot == .ErrorSet) return .bool_false;
3252932532 assert(ot == .ErrorUnion);
3253032533
32531 const payload_ty = operand_ty.errorUnionPayload(mod);
32532 if (payload_ty.zigTypeTag(mod) == .NoReturn) {
32534 const payload_ty = operand_ty.errorUnionPayload(zcu);
32535 if (payload_ty.zigTypeTag(zcu) == .NoReturn) {
3253332536 return .bool_false;
3253432537 }
3253532538
......@@ -32588,7 +32591,7 @@ fn analyzeIsNonErrComptimeOnly(
3258832591 // If the error set is empty, we must return a comptime true or false.
3258932592 // However we want to avoid unnecessarily resolving an inferred error set
3259032593 // in case it is already non-empty.
32591 try mod.maybeUnresolveIes(func_index);
32594 try zcu.maybeUnresolveIes(func_index);
3259232595 switch (ip.funcIesResolvedUnordered(func_index)) {
3259332596 .anyerror_type => break :blk,
3259432597 .none => {},
......@@ -32624,10 +32627,10 @@ fn analyzeIsNonErrComptimeOnly(
3262432627 }
3262532628
3262632629 if (maybe_operand_val) |err_union| {
32627 if (err_union.isUndef(mod)) {
32630 if (err_union.isUndef(zcu)) {
3262832631 return pt.undefRef(Type.bool);
3262932632 }
32630 if (err_union.getErrorName(mod) == .none) {
32633 if (err_union.getErrorName(zcu) == .none) {
3263132634 return .bool_true;
3263232635 } else {
3263332636 return .bool_false;
......@@ -32681,12 +32684,12 @@ fn analyzeSlice(
3268132684 by_length: bool,
3268232685) CompileError!Air.Inst.Ref {
3268332686 const pt = sema.pt;
32684 const mod = pt.zcu;
32687 const zcu = pt.zcu;
3268532688 // Slice expressions can operate on a variable whose type is an array. This requires
3268632689 // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer.
3268732690 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),
32691 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) {
32692 .Pointer => ptr_ptr_ty.childType(zcu),
3269032693 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ptr_ty.fmt(pt)}),
3269132694 };
3269232695
......@@ -32695,20 +32698,20 @@ fn analyzeSlice(
3269532698 var ptr_or_slice = ptr_ptr;
3269632699 var elem_ty: Type = undefined;
3269732700 var ptr_sentinel: ?Value = null;
32698 switch (ptr_ptr_child_ty.zigTypeTag(mod)) {
32701 switch (ptr_ptr_child_ty.zigTypeTag(zcu)) {
3269932702 .Array => {
32700 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
32701 elem_ty = ptr_ptr_child_ty.childType(mod);
32703 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
32704 elem_ty = ptr_ptr_child_ty.childType(zcu);
3270232705 },
32703 .Pointer => switch (ptr_ptr_child_ty.ptrSize(mod)) {
32706 .Pointer => switch (ptr_ptr_child_ty.ptrSize(zcu)) {
3270432707 .One => {
32705 const double_child_ty = ptr_ptr_child_ty.childType(mod);
32708 const double_child_ty = ptr_ptr_child_ty.childType(zcu);
3270632709 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);
32710 if (double_child_ty.zigTypeTag(zcu) == .Array) {
32711 ptr_sentinel = double_child_ty.sentinel(zcu);
3270932712 slice_ty = ptr_ptr_child_ty;
3271032713 array_ty = double_child_ty;
32711 elem_ty = double_child_ty.childType(mod);
32714 elem_ty = double_child_ty.childType(zcu);
3271232715 } else {
3271332716 const bounds_error_message = "slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1]";
3271432717 if (uncasted_end_opt == .none) {
......@@ -32777,7 +32780,7 @@ fn analyzeSlice(
3277732780 .len = 1,
3277832781 .child = double_child_ty.toIntern(),
3277932782 });
32780 const ptr_info = ptr_ptr_child_ty.ptrInfo(mod);
32783 const ptr_info = ptr_ptr_child_ty.ptrInfo(zcu);
3278132784 slice_ty = try pt.ptrType(.{
3278232785 .child = array_ty.toIntern(),
3278332786 .flags = .{
......@@ -32792,35 +32795,35 @@ fn analyzeSlice(
3279232795 }
3279332796 },
3279432797 .Many, .C => {
32795 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
32798 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
3279632799 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
3279732800 slice_ty = ptr_ptr_child_ty;
3279832801 array_ty = ptr_ptr_child_ty;
32799 elem_ty = ptr_ptr_child_ty.childType(mod);
32802 elem_ty = ptr_ptr_child_ty.childType(zcu);
3280032803
32801 if (ptr_ptr_child_ty.ptrSize(mod) == .C) {
32804 if (ptr_ptr_child_ty.ptrSize(zcu) == .C) {
3280232805 if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| {
32803 if (ptr_val.isNull(mod)) {
32806 if (ptr_val.isNull(zcu)) {
3280432807 return sema.fail(block, src, "slice of null pointer", .{});
3280532808 }
3280632809 }
3280732810 }
3280832811 },
3280932812 .Slice => {
32810 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
32813 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
3281132814 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
3281232815 slice_ty = ptr_ptr_child_ty;
3281332816 array_ty = ptr_ptr_child_ty;
32814 elem_ty = ptr_ptr_child_ty.childType(mod);
32817 elem_ty = ptr_ptr_child_ty.childType(zcu);
3281532818 },
3281632819 },
3281732820 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(pt)}),
3281832821 }
3281932822
32820 const ptr = if (slice_ty.isSlice(mod))
32823 const ptr = if (slice_ty.isSlice(zcu))
3282132824 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;
32825 else if (array_ty.zigTypeTag(zcu) == .Array) ptr: {
32826 var manyptr_ty_key = zcu.intern_pool.indexToKey(slice_ty.toIntern()).ptr_type;
3282432827 assert(manyptr_ty_key.child == array_ty.toIntern());
3282532828 assert(manyptr_ty_key.flags.size == .One);
3282632829 manyptr_ty_key.child = elem_ty.toIntern();
......@@ -32838,8 +32841,8 @@ fn analyzeSlice(
3283832841 // we might learn of the length because it is a comptime-known slice value.
3283932842 var end_is_len = uncasted_end_opt == .none;
3284032843 const end = e: {
32841 if (array_ty.zigTypeTag(mod) == .Array) {
32842 const len_val = try pt.intValue(Type.usize, array_ty.arrayLen(mod));
32844 if (array_ty.zigTypeTag(zcu) == .Array) {
32845 const len_val = try pt.intValue(Type.usize, array_ty.arrayLen(zcu));
3284332846
3284432847 if (!end_is_len) {
3284532848 const end = if (by_length) end: {
......@@ -32850,10 +32853,10 @@ fn analyzeSlice(
3285032853 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
3285132854 const len_s_val = try pt.intValue(
3285232855 Type.usize,
32853 array_ty.arrayLenIncludingSentinel(mod),
32856 array_ty.arrayLenIncludingSentinel(zcu),
3285432857 );
3285532858 if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) {
32856 const sentinel_label: []const u8 = if (array_ty.sentinel(mod) != null)
32859 const sentinel_label: []const u8 = if (array_ty.sentinel(zcu) != null)
3285732860 " +1 (sentinel)"
3285832861 else
3285932862 "";
......@@ -32873,7 +32876,7 @@ fn analyzeSlice(
3287332876 // end_is_len is only true if we are NOT using the sentinel
3287432877 // length. For sentinel-length, we don't want the type to
3287532878 // contain the sentinel.
32876 if (end_val.eql(len_val, Type.usize, mod)) {
32879 if (end_val.eql(len_val, Type.usize, zcu)) {
3287732880 end_is_len = true;
3287832881 }
3287932882 }
......@@ -32881,7 +32884,7 @@ fn analyzeSlice(
3288132884 }
3288232885
3288332886 break :e Air.internedToRef(len_val.toIntern());
32884 } else if (slice_ty.isSlice(mod)) {
32887 } else if (slice_ty.isSlice(zcu)) {
3288532888 if (!end_is_len) {
3288632889 const end = if (by_length) end: {
3288732890 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
......@@ -32890,10 +32893,10 @@ fn analyzeSlice(
3289032893 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
3289132894 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
3289232895 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {
32893 if (slice_val.isUndef(mod)) {
32896 if (slice_val.isUndef(zcu)) {
3289432897 return sema.fail(block, src, "slice of undefined", .{});
3289532898 }
32896 const has_sentinel = slice_ty.sentinel(mod) != null;
32899 const has_sentinel = slice_ty.sentinel(zcu) != null;
3289732900 const slice_len = try slice_val.sliceLen(pt);
3289832901 const len_plus_sent = slice_len + @intFromBool(has_sentinel);
3289932902 const slice_len_val_with_sentinel = try pt.intValue(Type.usize, len_plus_sent);
......@@ -32919,7 +32922,7 @@ fn analyzeSlice(
3291932922 // is only true if it equals the length WITHOUT the
3292032923 // sentinel, so we don't add a sentinel type.
3292132924 const slice_len_val = try pt.intValue(Type.usize, slice_len);
32922 if (end_val.eql(slice_len_val, Type.usize, mod)) {
32925 if (end_val.eql(slice_len_val, Type.usize, zcu)) {
3292332926 end_is_len = true;
3292432927 }
3292532928 }
......@@ -32976,8 +32979,8 @@ fn analyzeSlice(
3297632979 checked_start_lte_end = true;
3297732980 if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: {
3297832981 const expected_sentinel = sentinel orelse break :sentinel_check;
32979 const start_int = start_val.getUnsignedInt(pt).?;
32980 const end_int = end_val.getUnsignedInt(pt).?;
32982 const start_int = start_val.toUnsignedInt(zcu);
32983 const end_int = end_val.toUnsignedInt(zcu);
3298132984 const sentinel_index = try sema.usizeCast(block, end_src, end_int - start_int);
3298232985
3298332986 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);
......@@ -33001,7 +33004,7 @@ fn analyzeSlice(
3300133004 ),
3300233005 };
3300333006
33004 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {
33007 if (!actual_sentinel.eql(expected_sentinel, elem_ty, zcu)) {
3300533008 const msg = msg: {
3300633009 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
3300733010 errdefer msg.destroy(sema.gpa);
......@@ -33041,8 +33044,8 @@ fn analyzeSlice(
3304133044 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);
3304233045 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);
3304333046
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;
33047 const new_ptr_ty_info = new_ptr_ty.ptrInfo(zcu);
33048 const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(zcu) != .C;
3304633049
3304733050 if (opt_new_len_val) |new_len_val| {
3304833051 const new_len_int = try new_len_val.toUnsignedIntSema(pt);
......@@ -33067,17 +33070,17 @@ fn analyzeSlice(
3306733070 const result = try block.addBitCast(return_ty, new_ptr);
3306833071 if (block.wantSafety()) {
3306933072 // requirement: slicing C ptr is non-null
33070 if (ptr_ptr_child_ty.isCPtr(mod)) {
33073 if (ptr_ptr_child_ty.isCPtr(zcu)) {
3307133074 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);
3307233075 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);
3307333076 }
3307433077
3307533078 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: {
33079 const actual_len = if (array_ty.zigTypeTag(zcu) == .Array)
33080 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
33081 else if (slice_ty.isSlice(zcu)) l: {
3307933082 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
33080 break :l if (slice_ty.sentinel(mod) == null)
33083 break :l if (slice_ty.sentinel(zcu) == null)
3308133084 slice_len_inst
3308233085 else
3308333086 try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
......@@ -33097,7 +33100,7 @@ fn analyzeSlice(
3309733100 return result;
3309833101 };
3309933102
33100 if (!new_ptr_val.isUndef(mod)) {
33103 if (!new_ptr_val.isUndef(zcu)) {
3310133104 return Air.internedToRef((try pt.getCoerced(new_ptr_val, return_ty)).toIntern());
3310233105 }
3310333106
......@@ -33125,15 +33128,15 @@ fn analyzeSlice(
3312533128 try sema.requireRuntimeBlock(block, src, runtime_src.?);
3312633129 if (block.wantSafety()) {
3312733130 // requirement: slicing C ptr is non-null
33128 if (ptr_ptr_child_ty.isCPtr(mod)) {
33131 if (ptr_ptr_child_ty.isCPtr(zcu)) {
3312933132 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);
3313033133 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);
3313133134 }
3313233135
3313333136 // 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: {
33137 const opt_len_inst = if (array_ty.zigTypeTag(zcu) == .Array)
33138 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
33139 else if (slice_ty.isSlice(zcu)) blk: {
3313733140 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
3313833141 // we don't need to add one for sentinels because the
3313933142 // underlying value data includes the sentinel
......@@ -33141,7 +33144,7 @@ fn analyzeSlice(
3314133144 }
3314233145
3314333146 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;
33147 if (slice_ty.sentinel(zcu) == null) break :blk slice_len_inst;
3314533148
3314633149 // we have to add one because slice lengths don't include the sentinel
3314733150 break :blk try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
......@@ -33186,16 +33189,16 @@ fn cmpNumeric(
3318633189 rhs_src: LazySrcLoc,
3318733190) CompileError!Air.Inst.Ref {
3318833191 const pt = sema.pt;
33189 const mod = pt.zcu;
33192 const zcu = pt.zcu;
3319033193 const lhs_ty = sema.typeOf(uncasted_lhs);
3319133194 const rhs_ty = sema.typeOf(uncasted_rhs);
3319233195
33193 assert(lhs_ty.isNumeric(mod));
33194 assert(rhs_ty.isNumeric(mod));
33196 assert(lhs_ty.isNumeric(zcu));
33197 assert(rhs_ty.isNumeric(zcu));
3319533198
33196 const lhs_ty_tag = lhs_ty.zigTypeTag(mod);
33197 const rhs_ty_tag = rhs_ty.zigTypeTag(mod);
33198 const target = mod.getTarget();
33199 const lhs_ty_tag = lhs_ty.zigTypeTag(zcu);
33200 const rhs_ty_tag = rhs_ty.zigTypeTag(zcu);
33201 const target = zcu.getTarget();
3319933202
3320033203 // One exception to heterogeneous comparison: comptime_float needs to
3320133204 // coerce to fixed-width float.
......@@ -33214,28 +33217,28 @@ fn cmpNumeric(
3321433217 if (try sema.resolveValue(lhs)) |lhs_val| {
3321533218 if (try sema.resolveValue(rhs)) |rhs_val| {
3321633219 // 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)) {
33220 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)) {
3321833221 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
3321933222 return if (res) .bool_true else .bool_false;
3322033223 }
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)) {
33224 } 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)) {
3322233225 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
3322333226 return if (res) .bool_true else .bool_false;
3322433227 }
3322533228 }
3322633229
33227 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
33230 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
3322833231 return pt.undefRef(Type.bool);
3322933232 }
33230 if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) {
33233 if (lhs_val.isNan(zcu) or rhs_val.isNan(zcu)) {
3323133234 return if (op == std.math.CompareOperator.neq) .bool_true else .bool_false;
3323233235 }
33233 return if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, pt, .sema))
33236 return if (try Value.compareHeteroSema(lhs_val, op, rhs_val, pt))
3323433237 .bool_true
3323533238 else
3323633239 .bool_false;
3323733240 } else {
33238 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) {
33241 if (!lhs_val.isUndef(zcu) and (lhs_ty.isInt(zcu) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(zcu)) {
3323933242 // Compare ints: const vs. var
3324033243 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
3324133244 return if (res) .bool_true else .bool_false;
......@@ -33245,7 +33248,7 @@ fn cmpNumeric(
3324533248 }
3324633249 } else {
3324733250 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)) {
33251 if (!rhs_val.isUndef(zcu) and (rhs_ty.isInt(zcu) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(zcu)) {
3324933252 // Compare ints: var vs. const
3325033253 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
3325133254 return if (res) .bool_true else .bool_false;
......@@ -33301,31 +33304,31 @@ fn cmpNumeric(
3330133304 const lhs_is_signed = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val|
3330233305 !(try lhs_val.compareAllWithZeroSema(.gte, pt))
3330333306 else
33304 (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt(mod));
33307 (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt(zcu));
3330533308 const rhs_is_signed = if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val|
3330633309 !(try rhs_val.compareAllWithZeroSema(.gte, pt))
3330733310 else
33308 (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt(mod));
33311 (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt(zcu));
3330933312 const dest_int_is_signed = lhs_is_signed or rhs_is_signed;
3331033313
3331133314 var dest_float_type: ?Type = null;
3331233315
3331333316 var lhs_bits: usize = undefined;
3331433317 if (try sema.resolveValueResolveLazy(lhs)) |lhs_val| {
33315 if (lhs_val.isUndef(mod))
33318 if (lhs_val.isUndef(zcu))
3331633319 return pt.undefRef(Type.bool);
33317 if (lhs_val.isNan(mod)) switch (op) {
33320 if (lhs_val.isNan(zcu)) switch (op) {
3331833321 .neq => return .bool_true,
3331933322 else => return .bool_false,
3332033323 };
33321 if (lhs_val.isInf(mod)) switch (op) {
33324 if (lhs_val.isInf(zcu)) switch (op) {
3332233325 .neq => return .bool_true,
3332333326 .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,
33327 .gt, .gte => return if (lhs_val.isNegativeInf(zcu)) .bool_false else .bool_true,
33328 .lt, .lte => return if (lhs_val.isNegativeInf(zcu)) .bool_true else .bool_false,
3332633329 };
3332733330 if (!rhs_is_signed) {
33328 switch (lhs_val.orderAgainstZero(pt)) {
33331 switch (lhs_val.orderAgainstZero(zcu)) {
3332933332 .gt => {},
3333033333 .eq => switch (op) { // LHS = 0, RHS is unsigned
3333133334 .lte => return .bool_true,
......@@ -33339,7 +33342,7 @@ fn cmpNumeric(
3333933342 }
3334033343 }
3334133344 if (lhs_is_float) {
33342 if (lhs_val.floatHasFraction(mod)) {
33345 if (lhs_val.floatHasFraction(zcu)) {
3334333346 switch (op) {
3334433347 .eq => return .bool_false,
3334533348 .neq => return .bool_true,
......@@ -33347,9 +33350,9 @@ fn cmpNumeric(
3334733350 }
3334833351 }
3334933352
33350 var bigint = try float128IntPartToBigInt(sema.gpa, lhs_val.toFloat(f128, pt));
33353 var bigint = try float128IntPartToBigInt(sema.gpa, lhs_val.toFloat(f128, zcu));
3335133354 defer bigint.deinit();
33352 if (lhs_val.floatHasFraction(mod)) {
33355 if (lhs_val.floatHasFraction(zcu)) {
3335333356 if (lhs_is_signed) {
3335433357 try bigint.addScalar(&bigint, -1);
3335533358 } else {
......@@ -33358,32 +33361,32 @@ fn cmpNumeric(
3335833361 }
3335933362 lhs_bits = bigint.toConst().bitCountTwosComp();
3336033363 } else {
33361 lhs_bits = lhs_val.intBitCountTwosComp(pt);
33364 lhs_bits = lhs_val.intBitCountTwosComp(zcu);
3336233365 }
3336333366 lhs_bits += @intFromBool(!lhs_is_signed and dest_int_is_signed);
3336433367 } else if (lhs_is_float) {
3336533368 dest_float_type = lhs_ty;
3336633369 } else {
33367 const int_info = lhs_ty.intInfo(mod);
33370 const int_info = lhs_ty.intInfo(zcu);
3336833371 lhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);
3336933372 }
3337033373
3337133374 var rhs_bits: usize = undefined;
3337233375 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
33373 if (rhs_val.isUndef(mod))
33376 if (rhs_val.isUndef(zcu))
3337433377 return pt.undefRef(Type.bool);
33375 if (rhs_val.isNan(mod)) switch (op) {
33378 if (rhs_val.isNan(zcu)) switch (op) {
3337633379 .neq => return .bool_true,
3337733380 else => return .bool_false,
3337833381 };
33379 if (rhs_val.isInf(mod)) switch (op) {
33382 if (rhs_val.isInf(zcu)) switch (op) {
3338033383 .neq => return .bool_true,
3338133384 .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,
33385 .gt, .gte => return if (rhs_val.isNegativeInf(zcu)) .bool_true else .bool_false,
33386 .lt, .lte => return if (rhs_val.isNegativeInf(zcu)) .bool_false else .bool_true,
3338433387 };
3338533388 if (!lhs_is_signed) {
33386 switch (rhs_val.orderAgainstZero(pt)) {
33389 switch (rhs_val.orderAgainstZero(zcu)) {
3338733390 .gt => {},
3338833391 .eq => switch (op) { // RHS = 0, LHS is unsigned
3338933392 .gte => return .bool_true,
......@@ -33397,7 +33400,7 @@ fn cmpNumeric(
3339733400 }
3339833401 }
3339933402 if (rhs_is_float) {
33400 if (rhs_val.floatHasFraction(mod)) {
33403 if (rhs_val.floatHasFraction(zcu)) {
3340133404 switch (op) {
3340233405 .eq => return .bool_false,
3340333406 .neq => return .bool_true,
......@@ -33405,9 +33408,9 @@ fn cmpNumeric(
3340533408 }
3340633409 }
3340733410
33408 var bigint = try float128IntPartToBigInt(sema.gpa, rhs_val.toFloat(f128, pt));
33411 var bigint = try float128IntPartToBigInt(sema.gpa, rhs_val.toFloat(f128, zcu));
3340933412 defer bigint.deinit();
33410 if (rhs_val.floatHasFraction(mod)) {
33413 if (rhs_val.floatHasFraction(zcu)) {
3341133414 if (rhs_is_signed) {
3341233415 try bigint.addScalar(&bigint, -1);
3341333416 } else {
......@@ -33416,13 +33419,13 @@ fn cmpNumeric(
3341633419 }
3341733420 rhs_bits = bigint.toConst().bitCountTwosComp();
3341833421 } else {
33419 rhs_bits = rhs_val.intBitCountTwosComp(pt);
33422 rhs_bits = rhs_val.intBitCountTwosComp(zcu);
3342033423 }
3342133424 rhs_bits += @intFromBool(!rhs_is_signed and dest_int_is_signed);
3342233425 } else if (rhs_is_float) {
3342333426 dest_float_type = rhs_ty;
3342433427 } else {
33425 const int_info = rhs_ty.intInfo(mod);
33428 const int_info = rhs_ty.intInfo(zcu);
3342633429 rhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);
3342733430 }
3342833431
......@@ -33450,9 +33453,9 @@ fn compareIntsOnlyPossibleResult(
3345033453 rhs_ty: Type,
3345133454) Allocator.Error!?bool {
3345233455 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;
33456 const zcu = pt.zcu;
33457 const rhs_info = rhs_ty.intInfo(zcu);
33458 const vs_zero = lhs_val.orderAgainstZeroSema(pt) catch unreachable;
3345633459 const is_zero = vs_zero == .eq;
3345733460 const is_negative = vs_zero == .lt;
3345833461 const is_positive = vs_zero == .gt;
......@@ -33484,7 +33487,7 @@ fn compareIntsOnlyPossibleResult(
3348433487 };
3348533488
3348633489 const sign_adj = @intFromBool(!is_negative and rhs_info.signedness == .signed);
33487 const req_bits = lhs_val.intBitCountTwosComp(pt) + sign_adj;
33490 const req_bits = lhs_val.intBitCountTwosComp(zcu) + sign_adj;
3348833491
3348933492 // No sized type can have more than 65535 bits.
3349033493 // The RHS type operand is either a runtime value or sized (but undefined) constant.
......@@ -33515,7 +33518,7 @@ fn compareIntsOnlyPossibleResult(
3351533518 if (is_negative) .signed else .unsigned,
3351633519 @intCast(req_bits),
3351733520 );
33518 const pop_count = lhs_val.popCount(ty, pt);
33521 const pop_count = lhs_val.popCount(ty, zcu);
3351933522
3352033523 if (is_negative) {
3352133524 break :edge .{ pop_count == 1, false };
......@@ -33546,11 +33549,11 @@ fn cmpVector(
3354633549 rhs_src: LazySrcLoc,
3354733550) CompileError!Air.Inst.Ref {
3354833551 const pt = sema.pt;
33549 const mod = pt.zcu;
33552 const zcu = pt.zcu;
3355033553 const lhs_ty = sema.typeOf(lhs);
3355133554 const rhs_ty = sema.typeOf(rhs);
33552 assert(lhs_ty.zigTypeTag(mod) == .Vector);
33553 assert(rhs_ty.zigTypeTag(mod) == .Vector);
33555 assert(lhs_ty.zigTypeTag(zcu) == .Vector);
33556 assert(rhs_ty.zigTypeTag(zcu) == .Vector);
3355433557 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
3355533558
3355633559 const resolved_ty = try sema.resolvePeerTypes(block, src, &.{ lhs, rhs }, .{ .override = &.{ lhs_src, rhs_src } });
......@@ -33558,14 +33561,14 @@ fn cmpVector(
3355833561 const casted_rhs = try sema.coerce(block, resolved_ty, rhs, rhs_src);
3355933562
3356033563 const result_ty = try pt.vectorType(.{
33561 .len = lhs_ty.vectorLen(mod),
33564 .len = lhs_ty.vectorLen(zcu),
3356233565 .child = .bool_type,
3356333566 });
3356433567
3356533568 const runtime_src: LazySrcLoc = src: {
3356633569 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
3356733570 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
33568 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
33571 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
3356933572 return pt.undefRef(result_ty);
3357033573 }
3357133574 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty);
......@@ -33608,8 +33611,8 @@ fn wrapErrorUnionPayload(
3360833611 inst_src: LazySrcLoc,
3360933612) !Air.Inst.Ref {
3361033613 const pt = sema.pt;
33611 const mod = pt.zcu;
33612 const dest_payload_ty = dest_ty.errorUnionPayload(mod);
33614 const zcu = pt.zcu;
33615 const dest_payload_ty = dest_ty.errorUnionPayload(zcu);
3361333616 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
3361433617 if (try sema.resolveValue(coerced)) |val| {
3361533618 return Air.internedToRef((try pt.intern(.{ .error_union = .{
......@@ -33629,12 +33632,12 @@ fn wrapErrorUnionSet(
3362933632 inst_src: LazySrcLoc,
3363033633) !Air.Inst.Ref {
3363133634 const pt = sema.pt;
33632 const mod = pt.zcu;
33633 const ip = &mod.intern_pool;
33635 const zcu = pt.zcu;
33636 const ip = &zcu.intern_pool;
3363433637 const inst_ty = sema.typeOf(inst);
33635 const dest_err_set_ty = dest_ty.errorUnionSet(mod);
33638 const dest_err_set_ty = dest_ty.errorUnionSet(zcu);
3363633639 if (try sema.resolveValue(inst)) |val| {
33637 const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
33640 const expected_name = zcu.intern_pool.indexToKey(val.toIntern()).err.name;
3363833641 switch (dest_err_set_ty.toIntern()) {
3363933642 .anyerror_type => {},
3364033643 .adhoc_inferred_error_set_type => ok: {
......@@ -33658,7 +33661,7 @@ fn wrapErrorUnionSet(
3365833661 .inferred_error_set_type => |func_index| ok: {
3365933662 // We carefully do this in an order that avoids unnecessarily
3366033663 // resolving the destination error set type.
33661 try mod.maybeUnresolveIes(func_index);
33664 try zcu.maybeUnresolveIes(func_index);
3366233665 switch (ip.funcIesResolvedUnordered(func_index)) {
3366333666 .anyerror_type => break :ok,
3366433667 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
......@@ -33693,13 +33696,13 @@ fn unionToTag(
3369333696 un_src: LazySrcLoc,
3369433697) !Air.Inst.Ref {
3369533698 const pt = sema.pt;
33696 const mod = pt.zcu;
33699 const zcu = pt.zcu;
3369733700 if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| {
3369833701 return Air.internedToRef(opv.toIntern());
3369933702 }
3370033703 if (try sema.resolveValue(un)) |un_val| {
33701 const tag_val = un_val.unionTag(mod).?;
33702 if (tag_val.isUndef(mod))
33704 const tag_val = un_val.unionTag(zcu).?;
33705 if (tag_val.isUndef(zcu))
3370333706 return try pt.undefRef(enum_ty);
3370433707 return Air.internedToRef(tag_val.toIntern());
3370533708 }
......@@ -33861,8 +33864,8 @@ const PeerResolveStrategy = enum {
3386133864 return strat;
3386233865 }
3386333866
33864 fn select(ty: Type, mod: *Module) PeerResolveStrategy {
33865 return switch (ty.zigTypeTag(mod)) {
33867 fn select(ty: Type, zcu: *Zcu) PeerResolveStrategy {
33868 return switch (ty.zigTypeTag(zcu)) {
3386633869 .Type, .Void, .Bool, .Opaque, .Frame, .AnyFrame => .exact,
3386733870 .NoReturn, .Undefined => .unknown,
3386833871 .Null => .nullable,
......@@ -33870,14 +33873,14 @@ const PeerResolveStrategy = enum {
3387033873 .Int => .fixed_int,
3387133874 .ComptimeFloat => .comptime_float,
3387233875 .Float => .fixed_float,
33873 .Pointer => if (ty.ptrInfo(mod).flags.size == .C) .c_ptr else .ptr,
33876 .Pointer => if (ty.ptrInfo(zcu).flags.size == .C) .c_ptr else .ptr,
3387433877 .Array => .array,
3387533878 .Vector => .vector,
3387633879 .Optional => .optional,
3387733880 .ErrorSet => .error_set,
3387833881 .ErrorUnion => .error_union,
3387933882 .EnumLiteral, .Enum, .Union => .enum_or_union,
33880 .Struct => if (ty.isTupleOrAnonStruct(mod)) .coercible_struct else .exact,
33883 .Struct => if (ty.isTupleOrAnonStruct(zcu)) .coercible_struct else .exact,
3388133884 .Fn => .func,
3388233885 };
3388333886 }
......@@ -33933,10 +33936,10 @@ const PeerResolveResult = union(enum) {
3393333936 src: LazySrcLoc,
3393433937 instructions: []const Air.Inst.Ref,
3393533938 candidate_srcs: PeerTypeCandidateSrc,
33936 ) !*Module.ErrorMsg {
33939 ) !*Zcu.ErrorMsg {
3393733940 const pt = sema.pt;
3393833941
33939 var opt_msg: ?*Module.ErrorMsg = null;
33942 var opt_msg: ?*Zcu.ErrorMsg = null;
3394033943 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
3394133944
3394233945 // If we mention fields we'll want to include field types, so put peer types in a buffer
......@@ -34053,14 +34056,14 @@ fn resolvePeerTypesInner(
3405334056 peer_vals: []?Value,
3405434057) !PeerResolveResult {
3405534058 const pt = sema.pt;
34056 const mod = pt.zcu;
34057 const ip = &mod.intern_pool;
34059 const zcu = pt.zcu;
34060 const ip = &zcu.intern_pool;
3405834061
3405934062 var strat_reason: usize = 0;
3406034063 var s: PeerResolveStrategy = .unknown;
3406134064 for (peer_tys, 0..) |opt_ty, i| {
3406234065 const ty = opt_ty orelse continue;
34063 s = s.merge(PeerResolveStrategy.select(ty, mod), &strat_reason, i);
34066 s = s.merge(PeerResolveStrategy.select(ty, zcu), &strat_reason, i);
3406434067 }
3406534068
3406634069 if (s == .unknown) {
......@@ -34070,14 +34073,14 @@ fn resolvePeerTypesInner(
3407034073 // There was something other than noreturn and undefined, so we can ignore those peers
3407134074 for (peer_tys) |*ty_ptr| {
3407234075 const ty = ty_ptr.* orelse continue;
34073 switch (ty.zigTypeTag(mod)) {
34076 switch (ty.zigTypeTag(zcu)) {
3407434077 .NoReturn, .Undefined => ty_ptr.* = null,
3407534078 else => {},
3407634079 }
3407734080 }
3407834081 }
3407934082
34080 const target = mod.getTarget();
34083 const target = zcu.getTarget();
3408134084
3408234085 switch (s) {
3408334086 .unknown => unreachable,
......@@ -34086,7 +34089,7 @@ fn resolvePeerTypesInner(
3408634089 var final_set: ?Type = null;
3408734090 for (peer_tys, 0..) |opt_ty, i| {
3408834091 const ty = opt_ty orelse continue;
34089 if (ty.zigTypeTag(mod) != .ErrorSet) return .{ .conflict = .{
34092 if (ty.zigTypeTag(zcu) != .ErrorSet) return .{ .conflict = .{
3409034093 .peer_idx_a = strat_reason,
3409134094 .peer_idx_b = i,
3409234095 } };
......@@ -34103,15 +34106,15 @@ fn resolvePeerTypesInner(
3410334106 var final_set: ?Type = null;
3410434107 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {
3410534108 const ty = ty_ptr.* orelse continue;
34106 const set_ty = switch (ty.zigTypeTag(mod)) {
34109 const set_ty = switch (ty.zigTypeTag(zcu)) {
3410734110 .ErrorSet => blk: {
3410834111 ty_ptr.* = null; // no payload to decide on
3410934112 val_ptr.* = null;
3411034113 break :blk ty;
3411134114 },
3411234115 .ErrorUnion => blk: {
34113 const set_ty = ty.errorUnionSet(mod);
34114 ty_ptr.* = ty.errorUnionPayload(mod);
34116 const set_ty = ty.errorUnionSet(zcu);
34117 ty_ptr.* = ty.errorUnionPayload(zcu);
3411534118 if (val_ptr.*) |eu_val| switch (ip.indexToKey(eu_val.toIntern())) {
3411634119 .error_union => |eu| switch (eu.val) {
3411734120 .payload => |payload_ip| val_ptr.* = Value.fromInterned(payload_ip),
......@@ -34146,7 +34149,7 @@ fn resolvePeerTypesInner(
3414634149 .nullable => {
3414734150 for (peer_tys, 0..) |opt_ty, i| {
3414834151 const ty = opt_ty orelse continue;
34149 if (!ty.eql(Type.null, mod)) return .{ .conflict = .{
34152 if (!ty.eql(Type.null, zcu)) return .{ .conflict = .{
3415034153 .peer_idx_a = strat_reason,
3415134154 .peer_idx_b = i,
3415234155 } };
......@@ -34157,14 +34160,14 @@ fn resolvePeerTypesInner(
3415734160 .optional => {
3415834161 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {
3415934162 const ty = ty_ptr.* orelse continue;
34160 switch (ty.zigTypeTag(mod)) {
34163 switch (ty.zigTypeTag(zcu)) {
3416134164 .Null => {
3416234165 ty_ptr.* = null;
3416334166 val_ptr.* = null;
3416434167 },
3416534168 .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;
34169 ty_ptr.* = ty.optionalChild(zcu);
34170 if (val_ptr.*) |opt_val| val_ptr.* = if (!opt_val.isUndef(zcu)) opt_val.optionalValue(zcu) else null;
3416834171 },
3416934172 else => {},
3417034173 }
......@@ -34195,7 +34198,7 @@ fn resolvePeerTypesInner(
3419534198 for (peer_tys, 0..) |*ty_ptr, i| {
3419634199 const ty = ty_ptr.* orelse continue;
3419734200
34198 if (!ty.isArrayOrVector(mod)) {
34201 if (!ty.isArrayOrVector(zcu)) {
3419934202 // We allow tuples of the correct length. We won't validate their elem type, since the elements can be coerced.
3420034203 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{
3420134204 .peer_idx_a = strat_reason,
......@@ -34220,29 +34223,29 @@ fn resolvePeerTypesInner(
3422034223 const first_arr_idx = opt_first_arr_idx orelse {
3422134224 if (opt_first_idx == null) {
3422234225 opt_first_idx = i;
34223 len = ty.arrayLen(mod);
34224 sentinel = ty.sentinel(mod);
34226 len = ty.arrayLen(zcu);
34227 sentinel = ty.sentinel(zcu);
3422534228 }
3422634229 opt_first_arr_idx = i;
34227 elem_ty = ty.childType(mod);
34230 elem_ty = ty.childType(zcu);
3422834231 continue;
3422934232 };
3423034233
34231 if (ty.arrayLen(mod) != len) return .{ .conflict = .{
34234 if (ty.arrayLen(zcu) != len) return .{ .conflict = .{
3423234235 .peer_idx_a = first_arr_idx,
3423334236 .peer_idx_b = i,
3423434237 } };
3423534238
34236 const peer_elem_ty = ty.childType(mod);
34237 if (!peer_elem_ty.eql(elem_ty, mod)) coerce: {
34239 const peer_elem_ty = ty.childType(zcu);
34240 if (!peer_elem_ty.eql(elem_ty, zcu)) coerce: {
3423834241 const peer_elem_coerces_to_elem =
34239 try sema.coerceInMemoryAllowed(block, elem_ty, peer_elem_ty, false, mod.getTarget(), src, src, null);
34242 try sema.coerceInMemoryAllowed(block, elem_ty, peer_elem_ty, false, zcu.getTarget(), src, src, null);
3424034243 if (peer_elem_coerces_to_elem == .ok) {
3424134244 break :coerce;
3424234245 }
3424334246
3424434247 const elem_coerces_to_peer_elem =
34245 try sema.coerceInMemoryAllowed(block, peer_elem_ty, elem_ty, false, mod.getTarget(), src, src, null);
34248 try sema.coerceInMemoryAllowed(block, peer_elem_ty, elem_ty, false, zcu.getTarget(), src, src, null);
3424634249 if (elem_coerces_to_peer_elem == .ok) {
3424734250 elem_ty = peer_elem_ty;
3424834251 break :coerce;
......@@ -34255,8 +34258,8 @@ fn resolvePeerTypesInner(
3425534258 }
3425634259
3425734260 if (sentinel) |cur_sent| {
34258 if (ty.sentinel(mod)) |peer_sent| {
34259 if (!peer_sent.eql(cur_sent, elem_ty, mod)) sentinel = null;
34261 if (ty.sentinel(zcu)) |peer_sent| {
34262 if (!peer_sent.eql(cur_sent, elem_ty, zcu)) sentinel = null;
3426034263 } else {
3426134264 sentinel = null;
3426234265 }
......@@ -34279,7 +34282,7 @@ fn resolvePeerTypesInner(
3427934282 for (peer_tys, peer_vals, 0..) |*ty_ptr, *val_ptr, i| {
3428034283 const ty = ty_ptr.* orelse continue;
3428134284
34282 if (!ty.isArrayOrVector(mod)) {
34285 if (!ty.isArrayOrVector(zcu)) {
3428334286 // Allow tuples of the correct length
3428434287 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{
3428534288 .peer_idx_a = strat_reason,
......@@ -34305,16 +34308,16 @@ fn resolvePeerTypesInner(
3430534308 }
3430634309
3430734310 if (len) |expect_len| {
34308 if (ty.arrayLen(mod) != expect_len) return .{ .conflict = .{
34311 if (ty.arrayLen(zcu) != expect_len) return .{ .conflict = .{
3430934312 .peer_idx_a = first_idx,
3431034313 .peer_idx_b = i,
3431134314 } };
3431234315 } else {
34313 len = ty.arrayLen(mod);
34316 len = ty.arrayLen(zcu);
3431434317 first_idx = i;
3431534318 }
3431634319
34317 ty_ptr.* = ty.childType(mod);
34320 ty_ptr.* = ty.childType(zcu);
3431834321 val_ptr.* = null; // multiple child vals, so we can't easily use them in PTR
3431934322 }
3432034323
......@@ -34339,7 +34342,7 @@ fn resolvePeerTypesInner(
3433934342 var first_idx: usize = undefined;
3434034343 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {
3434134344 const ty = opt_ty orelse continue;
34342 switch (ty.zigTypeTag(mod)) {
34345 switch (ty.zigTypeTag(zcu)) {
3434334346 .ComptimeInt => continue, // comptime-known integers can always coerce to C pointers
3434434347 .Int => {
3434534348 if (opt_val != null) {
......@@ -34348,7 +34351,7 @@ fn resolvePeerTypesInner(
3434834351 } else {
3434934352 // Runtime-known, so check if the type is no bigger than a usize
3435034353 const ptr_bits = target.ptrBitWidth();
34351 const bits = ty.intInfo(mod).bits;
34354 const bits = ty.intInfo(zcu).bits;
3435234355 if (bits <= ptr_bits) continue;
3435334356 }
3435434357 },
......@@ -34356,13 +34359,13 @@ fn resolvePeerTypesInner(
3435634359 else => {},
3435734360 }
3435834361
34359 if (!ty.isPtrAtRuntime(mod)) return .{ .conflict = .{
34362 if (!ty.isPtrAtRuntime(zcu)) return .{ .conflict = .{
3436034363 .peer_idx_a = strat_reason,
3436134364 .peer_idx_b = i,
3436234365 } };
3436334366
3436434367 // Goes through optionals
34365 const peer_info = ty.ptrInfo(mod);
34368 const peer_info = ty.ptrInfo(zcu);
3436634369
3436734370 var ptr_info = opt_ptr_info orelse {
3436834371 opt_ptr_info = peer_info;
......@@ -34391,17 +34394,17 @@ fn resolvePeerTypesInner(
3439134394 ptr_info.sentinel = .none;
3439234395 }
3439334396
34394 // Note that the align can be always non-zero; Module.ptrType will canonicalize it
34397 // Note that the align can be always non-zero; Zcu.ptrType will canonicalize it
3439534398 ptr_info.flags.alignment = InternPool.Alignment.min(
3439634399 if (ptr_info.flags.alignment != .none)
3439734400 ptr_info.flags.alignment
3439834401 else
34399 Type.fromInterned(ptr_info.child).abiAlignment(pt),
34402 Type.fromInterned(ptr_info.child).abiAlignment(zcu),
3440034403
3440134404 if (peer_info.flags.alignment != .none)
3440234405 peer_info.flags.alignment
3440334406 else
34404 Type.fromInterned(peer_info.child).abiAlignment(pt),
34407 Type.fromInterned(peer_info.child).abiAlignment(zcu),
3440534408 );
3440634409 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
3440734410 return .{ .conflict = .{
......@@ -34438,8 +34441,8 @@ fn resolvePeerTypesInner(
3443834441
3443934442 for (peer_tys, 0..) |opt_ty, i| {
3444034443 const ty = opt_ty orelse continue;
34441 const peer_info: InternPool.Key.PtrType = switch (ty.zigTypeTag(mod)) {
34442 .Pointer => ty.ptrInfo(mod),
34444 const peer_info: InternPool.Key.PtrType = switch (ty.zigTypeTag(zcu)) {
34445 .Pointer => ty.ptrInfo(zcu),
3444334446 .Fn => .{
3444434447 .child = ty.toIntern(),
3444534448 .flags = .{
......@@ -34480,12 +34483,12 @@ fn resolvePeerTypesInner(
3448034483 if (ptr_info.flags.alignment != .none)
3448134484 ptr_info.flags.alignment
3448234485 else
34483 try sema.typeAbiAlignment(Type.fromInterned(ptr_info.child)),
34486 try Type.fromInterned(ptr_info.child).abiAlignmentSema(pt),
3448434487
3448534488 if (peer_info.flags.alignment != .none)
3448634489 peer_info.flags.alignment
3448734490 else
34488 try sema.typeAbiAlignment(Type.fromInterned(peer_info.child)),
34491 try Type.fromInterned(peer_info.child).abiAlignmentSema(pt),
3448934492 );
3449034493
3449134494 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
......@@ -34747,7 +34750,7 @@ fn resolvePeerTypesInner(
3474734750 first_idx = i;
3474834751 continue;
3474934752 };
34750 if (ty.zigTypeTag(mod) != .Fn) return .{ .conflict = .{
34753 if (ty.zigTypeTag(zcu) != .Fn) return .{ .conflict = .{
3475134754 .peer_idx_a = strat_reason,
3475234755 .peer_idx_b = i,
3475334756 } };
......@@ -34775,7 +34778,7 @@ fn resolvePeerTypesInner(
3477534778
3477634779 for (peer_tys, 0..) |opt_ty, i| {
3477734780 const ty = opt_ty orelse continue;
34778 switch (ty.zigTypeTag(mod)) {
34781 switch (ty.zigTypeTag(zcu)) {
3477934782 .EnumLiteral, .Enum, .Union => {},
3478034783 else => return .{ .conflict = .{
3478134784 .peer_idx_a = strat_reason,
......@@ -34794,32 +34797,32 @@ fn resolvePeerTypesInner(
3479434797 .peer_idx_b = i,
3479534798 } };
3479634799
34797 switch (cur_ty.zigTypeTag(mod)) {
34800 switch (cur_ty.zigTypeTag(zcu)) {
3479834801 .EnumLiteral => {
3479934802 opt_cur_ty = ty;
3480034803 cur_ty_idx = i;
3480134804 },
34802 .Enum => switch (ty.zigTypeTag(mod)) {
34805 .Enum => switch (ty.zigTypeTag(zcu)) {
3480334806 .EnumLiteral => {},
3480434807 .Enum => {
34805 if (!ty.eql(cur_ty, mod)) return generic_err;
34808 if (!ty.eql(cur_ty, zcu)) return generic_err;
3480634809 },
3480734810 .Union => {
34808 const tag_ty = ty.unionTagTypeHypothetical(mod);
34809 if (!tag_ty.eql(cur_ty, mod)) return generic_err;
34811 const tag_ty = ty.unionTagTypeHypothetical(zcu);
34812 if (!tag_ty.eql(cur_ty, zcu)) return generic_err;
3481034813 opt_cur_ty = ty;
3481134814 cur_ty_idx = i;
3481234815 },
3481334816 else => unreachable,
3481434817 },
34815 .Union => switch (ty.zigTypeTag(mod)) {
34818 .Union => switch (ty.zigTypeTag(zcu)) {
3481634819 .EnumLiteral => {},
3481734820 .Enum => {
34818 const cur_tag_ty = cur_ty.unionTagTypeHypothetical(mod);
34819 if (!ty.eql(cur_tag_ty, mod)) return generic_err;
34821 const cur_tag_ty = cur_ty.unionTagTypeHypothetical(zcu);
34822 if (!ty.eql(cur_tag_ty, zcu)) return generic_err;
3482034823 },
3482134824 .Union => {
34822 if (!ty.eql(cur_ty, mod)) return generic_err;
34825 if (!ty.eql(cur_ty, zcu)) return generic_err;
3482334826 },
3482434827 else => unreachable,
3482534828 },
......@@ -34832,7 +34835,7 @@ fn resolvePeerTypesInner(
3483234835 .comptime_int => {
3483334836 for (peer_tys, 0..) |opt_ty, i| {
3483434837 const ty = opt_ty orelse continue;
34835 switch (ty.zigTypeTag(mod)) {
34838 switch (ty.zigTypeTag(zcu)) {
3483634839 .ComptimeInt => {},
3483734840 else => return .{ .conflict = .{
3483834841 .peer_idx_a = strat_reason,
......@@ -34846,7 +34849,7 @@ fn resolvePeerTypesInner(
3484634849 .comptime_float => {
3484734850 for (peer_tys, 0..) |opt_ty, i| {
3484834851 const ty = opt_ty orelse continue;
34849 switch (ty.zigTypeTag(mod)) {
34852 switch (ty.zigTypeTag(zcu)) {
3485034853 .ComptimeInt, .ComptimeFloat => {},
3485134854 else => return .{ .conflict = .{
3485234855 .peer_idx_a = strat_reason,
......@@ -34868,11 +34871,11 @@ fn resolvePeerTypesInner(
3486834871 const ty = opt_ty orelse continue;
3486934872 const opt_val = ptr_opt_val.*;
3487034873
34871 const peer_tag = ty.zigTypeTag(mod);
34874 const peer_tag = ty.zigTypeTag(zcu);
3487234875 switch (peer_tag) {
3487334876 .ComptimeInt => {
3487434877 // 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 = .{
34878 if (opt_val == null or opt_val.?.isUndef(zcu)) return .{ .conflict = .{
3487634879 .peer_idx_a = strat_reason,
3487734880 .peer_idx_b = i,
3487834881 } };
......@@ -34889,7 +34892,7 @@ fn resolvePeerTypesInner(
3488934892
3489034893 if (opt_val != null) any_comptime_known = true;
3489134894
34892 const info = ty.intInfo(mod);
34895 const info = ty.intInfo(zcu);
3489334896
3489434897 const idx_ptr = switch (info.signedness) {
3489534898 .unsigned => &idx_unsigned,
......@@ -34901,7 +34904,7 @@ fn resolvePeerTypesInner(
3490134904 continue;
3490234905 };
3490334906
34904 const cur_info = peer_tys[largest_idx].?.intInfo(mod);
34907 const cur_info = peer_tys[largest_idx].?.intInfo(zcu);
3490534908 if (info.bits > cur_info.bits) {
3490634909 idx_ptr.* = i;
3490734910 }
......@@ -34915,8 +34918,8 @@ fn resolvePeerTypesInner(
3491534918 return .{ .success = peer_tys[idx_signed.?].? };
3491634919 }
3491734920
34918 const unsigned_info = peer_tys[idx_unsigned.?].?.intInfo(mod);
34919 const signed_info = peer_tys[idx_signed.?].?.intInfo(mod);
34921 const unsigned_info = peer_tys[idx_unsigned.?].?.intInfo(zcu);
34922 const signed_info = peer_tys[idx_signed.?].?.intInfo(zcu);
3492034923 if (signed_info.bits > unsigned_info.bits) {
3492134924 return .{ .success = peer_tys[idx_signed.?].? };
3492234925 }
......@@ -34948,7 +34951,7 @@ fn resolvePeerTypesInner(
3494834951
3494934952 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {
3495034953 const ty = opt_ty orelse continue;
34951 switch (ty.zigTypeTag(mod)) {
34954 switch (ty.zigTypeTag(zcu)) {
3495234955 .ComptimeFloat, .ComptimeInt => {},
3495334956 .Int => {
3495434957 if (opt_val == null) return .{ .conflict = .{
......@@ -34958,7 +34961,7 @@ fn resolvePeerTypesInner(
3495834961 },
3495934962 .Float => {
3496034963 if (opt_cur_ty) |cur_ty| {
34961 if (cur_ty.eql(ty, mod)) continue;
34964 if (cur_ty.eql(ty, zcu)) continue;
3496234965 // Recreate the type so we eliminate any c_longdouble
3496334966 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));
3496434967 opt_cur_ty = switch (bits) {
......@@ -34997,7 +35000,7 @@ fn resolvePeerTypesInner(
3499735000 for (peer_tys, 0..) |opt_ty, i| {
3499835001 const ty = opt_ty orelse continue;
3499935002
35000 if (!ty.isTupleOrAnonStruct(mod)) {
35003 if (!ty.isTupleOrAnonStruct(zcu)) {
3500135004 return .{ .conflict = .{
3500235005 .peer_idx_a = strat_reason,
3500335006 .peer_idx_b = i,
......@@ -35006,8 +35009,8 @@ fn resolvePeerTypesInner(
3500635009
3500735010 const first_idx = opt_first_idx orelse {
3500835011 opt_first_idx = i;
35009 is_tuple = ty.isTuple(mod);
35010 field_count = ty.structFieldCount(mod);
35012 is_tuple = ty.isTuple(zcu);
35013 field_count = ty.structFieldCount(zcu);
3501135014 if (!is_tuple) {
3501235015 const names = ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip);
3501335016 field_names = try sema.arena.dupe(InternPool.NullTerminatedString, names);
......@@ -35015,7 +35018,7 @@ fn resolvePeerTypesInner(
3501535018 continue;
3501635019 };
3501735020
35018 if (ty.isTuple(mod) != is_tuple or ty.structFieldCount(mod) != field_count) {
35021 if (ty.isTuple(zcu) != is_tuple or ty.structFieldCount(zcu) != field_count) {
3501935022 return .{ .conflict = .{
3502035023 .peer_idx_a = first_idx,
3502135024 .peer_idx_b = i,
......@@ -35025,7 +35028,7 @@ fn resolvePeerTypesInner(
3502535028 if (!is_tuple) {
3502635029 for (field_names, 0..) |expected, field_index_usize| {
3502735030 const field_index: u32 = @intCast(field_index_usize);
35028 const actual = ty.structFieldName(field_index, mod).unwrap().?;
35031 const actual = ty.structFieldName(field_index, zcu).unwrap().?;
3502935032 if (actual == expected) continue;
3503035033 return .{ .conflict = .{
3503135034 .peer_idx_a = first_idx,
......@@ -35052,7 +35055,7 @@ fn resolvePeerTypesInner(
3505235055 peer_field_val.* = null;
3505335056 continue;
3505435057 };
35055 peer_field_ty.* = ty.structFieldType(field_index, mod);
35058 peer_field_ty.* = ty.fieldType(field_index, zcu);
3505635059 peer_field_val.* = if (opt_val) |val| try val.fieldValue(pt, field_index) else null;
3505735060 }
3505835061
......@@ -35074,7 +35077,7 @@ fn resolvePeerTypesInner(
3507435077 // Already-resolved types won't be referenced by the error so it's fine
3507535078 // to leave them undefined.
3507635079 const ty = opt_ty orelse continue;
35077 peer_field_ty.* = ty.structFieldType(field_index, mod);
35080 peer_field_ty.* = ty.fieldType(field_index, zcu);
3507835081 }
3507935082
3508035083 return .{ .field_error = .{
......@@ -35111,7 +35114,7 @@ fn resolvePeerTypesInner(
3511135114 comptime_val = coerced_val;
3511235115 continue;
3511335116 };
35114 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), mod)) {
35117 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), zcu)) {
3511535118 comptime_val = null;
3511635119 break;
3511735120 }
......@@ -35120,7 +35123,7 @@ fn resolvePeerTypesInner(
3512035123 field_val.* = if (comptime_val) |v| v.toIntern() else .none;
3512135124 }
3512235125
35123 const final_ty = try ip.getAnonStructType(mod.gpa, pt.tid, .{
35126 const final_ty = try ip.getAnonStructType(zcu.gpa, pt.tid, .{
3512435127 .types = field_types,
3512535128 .names = if (is_tuple) &.{} else field_names,
3512635129 .values = field_vals,
......@@ -35135,7 +35138,7 @@ fn resolvePeerTypesInner(
3513535138 for (peer_tys, 0..) |opt_ty, i| {
3513635139 const ty = opt_ty orelse continue;
3513735140 if (expect_ty) |expect| {
35138 if (!ty.eql(expect, mod)) return .{ .conflict = .{
35141 if (!ty.eql(expect, zcu)) return .{ .conflict = .{
3513935142 .peer_idx_a = first_idx,
3514035143 .peer_idx_b = i,
3514135144 } };
......@@ -35186,22 +35189,22 @@ const ArrayLike = struct {
3518635189};
3518735190fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3518835191 const pt = sema.pt;
35189 const mod = pt.zcu;
35190 return switch (ty.zigTypeTag(mod)) {
35192 const zcu = pt.zcu;
35193 return switch (ty.zigTypeTag(zcu)) {
3519135194 .Array => .{
35192 .len = ty.arrayLen(mod),
35193 .elem_ty = ty.childType(mod),
35195 .len = ty.arrayLen(zcu),
35196 .elem_ty = ty.childType(zcu),
3519435197 },
3519535198 .Struct => {
35196 const field_count = ty.structFieldCount(mod);
35199 const field_count = ty.structFieldCount(zcu);
3519735200 if (field_count == 0) return .{
3519835201 .len = 0,
3519935202 .elem_ty = Type.noreturn,
3520035203 };
35201 if (!ty.isTuple(mod)) return null;
35202 const elem_ty = ty.structFieldType(0, mod);
35204 if (!ty.isTuple(zcu)) return null;
35205 const elem_ty = ty.fieldType(0, zcu);
3520335206 for (1..field_count) |i| {
35204 if (!ty.structFieldType(i, mod).eql(elem_ty, mod)) {
35207 if (!ty.fieldType(i, zcu).eql(elem_ty, zcu)) {
3520535208 return null;
3520635209 }
3520735210 }
......@@ -35216,8 +35219,8 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3521635219
3521735220pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void {
3521835221 const pt = sema.pt;
35219 const mod = pt.zcu;
35220 const ip = &mod.intern_pool;
35222 const zcu = pt.zcu;
35223 const ip = &zcu.intern_pool;
3522135224
3522235225 if (sema.fn_ret_ty_ies) |ies| {
3522335226 try sema.resolveInferredErrorSetPtr(block, src, ies);
......@@ -35228,14 +35231,14 @@ pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void
3522835231
3522935232pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void {
3523035233 const pt = sema.pt;
35231 const mod = pt.zcu;
35232 const ip = &mod.intern_pool;
35233 const fn_ty_info = mod.typeToFunc(fn_ty).?;
35234 const zcu = pt.zcu;
35235 const ip = &zcu.intern_pool;
35236 const fn_ty_info = zcu.typeToFunc(fn_ty).?;
3523435237
3523535238 try Type.fromInterned(fn_ty_info.return_type).resolveFully(pt);
3523635239
35237 if (mod.comp.config.any_error_tracing and
35238 Type.fromInterned(fn_ty_info.return_type).isError(mod))
35240 if (zcu.comp.config.any_error_tracing and
35241 Type.fromInterned(fn_ty_info.return_type).isError(zcu))
3523935242 {
3524035243 // Ensure the type exists so that backends can assume that.
3524135244 _ = try pt.getBuiltinType("StackTrace");
......@@ -35258,9 +35261,9 @@ pub fn resolveStructAlignment(
3525835261 struct_type: InternPool.LoadedStructType,
3525935262) SemaError!void {
3526035263 const pt = sema.pt;
35261 const mod = pt.zcu;
35262 const ip = &mod.intern_pool;
35263 const target = mod.getTarget();
35264 const zcu = pt.zcu;
35265 const ip = &zcu.intern_pool;
35266 const target = zcu.getTarget();
3526435267
3526535268 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);
3526635269
......@@ -35274,7 +35277,7 @@ pub fn resolveStructAlignment(
3527435277 // might require explicit alignment.
3527535278 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3527635279
35277 try sema.resolveTypeFieldsStruct(ty, struct_type);
35280 try sema.resolveStructFieldTypes(ty, struct_type);
3527835281
3527935282 // We'll guess "pointer-aligned", if the struct has an
3528035283 // underaligned pointer field then some allocations
......@@ -35286,13 +35289,12 @@ pub fn resolveStructAlignment(
3528635289
3528735290 for (0..struct_type.field_types.len) |i| {
3528835291 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))
35292 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt))
3529035293 continue;
35291 const field_align = try pt.structFieldAlignmentAdvanced(
35294 const field_align = try field_ty.structFieldAlignmentSema(
3529235295 struct_type.fieldAlign(ip, i),
35293 field_ty,
3529435296 struct_type.layout,
35295 .sema,
35297 pt,
3529635298 );
3529735299 alignment = alignment.maxStrict(field_align);
3529835300 }
......@@ -35311,10 +35313,10 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3531135313 if (struct_type.haveLayout(ip))
3531235314 return;
3531335315
35314 try sema.resolveTypeFieldsStruct(ty.toIntern(), struct_type);
35316 try sema.resolveStructFieldTypes(ty.toIntern(), struct_type);
3531535317
3531635318 if (struct_type.layout == .@"packed") {
35317 semaBackingIntType(pt, struct_type) catch |err| switch (err) {
35319 sema.backingIntType(struct_type) catch |err| switch (err) {
3531835320 error.OutOfMemory, error.AnalysisFail => |e| return e,
3531935321 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
3532035322 };
......@@ -35338,14 +35340,14 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3533835340
3533935341 for (aligns, sizes, 0..) |*field_align, *field_size, i| {
3534035342 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)) {
35343 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
3534235344 struct_type.offsets.get(ip)[i] = 0;
3534335345 field_size.* = 0;
3534435346 field_align.* = .none;
3534535347 continue;
3534635348 }
3534735349
35348 field_size.* = sema.typeAbiSize(field_ty) catch |err| switch (err) {
35350 field_size.* = field_ty.abiSizeSema(pt) catch |err| switch (err) {
3534935351 error.AnalysisFail => {
3535035352 const msg = sema.err orelse return err;
3535135353 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
......@@ -35353,16 +35355,15 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3535335355 },
3535435356 else => return err,
3535535357 };
35356 field_align.* = try pt.structFieldAlignmentAdvanced(
35358 field_align.* = try field_ty.structFieldAlignmentSema(
3535735359 struct_type.fieldAlign(ip, i),
35358 field_ty,
3535935360 struct_type.layout,
35360 .sema,
35361 pt,
3536135362 );
3536235363 big_align = big_align.maxStrict(field_align.*);
3536335364 }
3536435365
35365 if (struct_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35366 if (struct_type.flagsUnordered(ip).assumed_runtime_bits and !(try ty.hasRuntimeBitsSema(pt))) {
3536635367 const msg = try sema.errMsg(
3536735368 ty.srcLoc(zcu),
3536835369 "struct layout depends on it having runtime bits",
......@@ -35387,7 +35388,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3538735388
3538835389 for (runtime_order, 0..) |*ro, i| {
3538935390 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)) {
35391 if (struct_type.fieldIsComptime(ip, i) or try field_ty.comptimeOnlySema(pt)) {
3539135392 ro.* = .omitted;
3539235393 } else {
3539335394 ro.* = @enumFromInt(i);
......@@ -35440,41 +35441,26 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3544035441 offset = offsets[i] + sizes[i];
3544135442 }
3544235443 struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);
35443 _ = try sema.typeRequiresComptime(ty);
35444 _ = try ty.comptimeOnlySema(pt);
3544435445}
3544535446
35446fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructType) CompileError!void {
35447fn backingIntType(
35448 sema: *Sema,
35449 struct_type: InternPool.LoadedStructType,
35450) CompileError!void {
35451 const pt = sema.pt;
3544735452 const zcu = pt.zcu;
3544835453 const gpa = zcu.gpa;
3544935454 const ip = &zcu.intern_pool;
3545035455
3545135456 const cau_index = struct_type.cau.unwrap().?;
3545235457
35453 const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir;
35454
3545535458 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
3545635459 defer analysis_arena.deinit();
3545735460
35458 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
35459 defer comptime_err_ret_trace.deinit();
35460
35461 var sema: Sema = .{
35462 .pt = pt,
35463 .gpa = gpa,
35464 .arena = analysis_arena.allocator(),
35465 .code = zir,
35466 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
35467 .func_index = .none,
35468 .func_is_naked = false,
35469 .fn_ret_ty = Type.void,
35470 .fn_ret_ty_ies = null,
35471 .comptime_err_ret_trace = &comptime_err_ret_trace,
35472 };
35473 defer sema.deinit();
35474
3547535461 var block: Block = .{
3547635462 .parent = null,
35477 .sema = &sema,
35463 .sema = sema,
3547835464 .namespace = ip.getCau(cau_index).namespace,
3547935465 .instructions = .{},
3548035466 .inlining = null,
......@@ -35488,11 +35474,12 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
3548835474 var accumulator: u64 = 0;
3548935475 for (0..struct_type.field_types.len) |i| {
3549035476 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
35491 accumulator += try field_ty.bitSizeAdvanced(pt, .sema);
35477 accumulator += try field_ty.bitSizeSema(pt);
3549235478 }
3549335479 break :blk accumulator;
3549435480 };
3549535481
35482 const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir;
3549635483 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;
3549735484 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
3549835485 assert(extended.opcode == .struct_decl);
......@@ -35543,17 +35530,17 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
3554335530
3554435531fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ty: Type, fields_bit_sum: u64) CompileError!void {
3554535532 const pt = sema.pt;
35546 const mod = pt.zcu;
35533 const zcu = pt.zcu;
3554735534
35548 if (!backing_int_ty.isInt(mod)) {
35535 if (!backing_int_ty.isInt(zcu)) {
3554935536 return sema.fail(block, src, "expected backing integer type, found '{}'", .{backing_int_ty.fmt(pt)});
3555035537 }
35551 if (backing_int_ty.bitSize(pt) != fields_bit_sum) {
35538 if (backing_int_ty.bitSize(zcu) != fields_bit_sum) {
3555235539 return sema.fail(
3555335540 block,
3555435541 src,
3555535542 "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 },
35543 .{ backing_int_ty.fmt(pt), backing_int_ty.bitSize(zcu), fields_bit_sum },
3555735544 );
3555835545 }
3555935546}
......@@ -35573,13 +35560,13 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3557335560
3557435561fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3557535562 const pt = sema.pt;
35576 const mod = pt.zcu;
35577 if (ty.zigTypeTag(mod) == .Pointer) {
35578 switch (ty.ptrSize(mod)) {
35563 const zcu = pt.zcu;
35564 if (ty.zigTypeTag(zcu) == .Pointer) {
35565 switch (ty.ptrSize(zcu)) {
3557935566 .Slice, .Many, .C => return,
3558035567 .One => {
35581 const elem_ty = ty.childType(mod);
35582 if (elem_ty.zigTypeTag(mod) == .Array) return;
35568 const elem_ty = ty.childType(zcu);
35569 if (elem_ty.zigTypeTag(zcu) == .Array) return;
3558335570 // TODO https://github.com/ziglang/zig/issues/15479
3558435571 // if (elem_ty.isTuple()) return;
3558535572 },
......@@ -35601,7 +35588,8 @@ pub fn resolveUnionAlignment(
3560135588 ty: Type,
3560235589 union_type: InternPool.LoadedUnionType,
3560335590) SemaError!void {
35604 const zcu = sema.pt.zcu;
35591 const pt = sema.pt;
35592 const zcu = pt.zcu;
3560535593 const ip = &zcu.intern_pool;
3560635594 const target = zcu.getTarget();
3560735595
......@@ -35616,18 +35604,18 @@ pub fn resolveUnionAlignment(
3561635604 // might require explicit alignment.
3561735605 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3561835606
35619 try sema.resolveTypeFieldsUnion(ty, union_type);
35607 try sema.resolveUnionFieldTypes(ty, union_type);
3562035608
3562135609 var max_align: Alignment = .@"1";
3562235610 for (0..union_type.field_types.len) |field_index| {
3562335611 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
35624 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
35612 if (!(try field_ty.hasRuntimeBitsSema(pt))) continue;
3562535613
3562635614 const explicit_align = union_type.fieldAlign(ip, field_index);
3562735615 const field_align = if (explicit_align != .none)
3562835616 explicit_align
3562935617 else
35630 try sema.typeAbiAlignment(field_ty);
35618 try field_ty.abiAlignmentSema(sema.pt);
3563135619
3563235620 max_align = max_align.max(field_align);
3563335621 }
......@@ -35635,12 +35623,12 @@ pub fn resolveUnionAlignment(
3563535623 union_type.setAlignment(ip, max_align);
3563635624}
3563735625
35638/// This logic must be kept in sync with `Module.getUnionLayout`.
35626/// This logic must be kept in sync with `Zcu.getUnionLayout`.
3563935627pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3564035628 const pt = sema.pt;
3564135629 const ip = &pt.zcu.intern_pool;
3564235630
35643 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));
35631 try sema.resolveUnionFieldTypes(ty, ip.loadUnionType(ty.ip_index));
3564435632
3564535633 // Load again, since the tag type might have changed due to resolution.
3564635634 const union_type = ip.loadUnionType(ty.ip_index);
......@@ -35670,9 +35658,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3567035658 for (0..union_type.field_types.len) |field_index| {
3567135659 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
3567235660
35673 if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(pt.zcu) == .NoReturn) continue; // TODO: should this affect alignment?
35661 if (try field_ty.comptimeOnlySema(pt) or field_ty.zigTypeTag(pt.zcu) == .NoReturn) continue; // TODO: should this affect alignment?
3567435662
35675 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {
35663 max_size = @max(max_size, field_ty.abiSizeSema(pt) catch |err| switch (err) {
3567635664 error.AnalysisFail => {
3567735665 const msg = sema.err orelse return err;
3567835666 try sema.addFieldErrNote(ty, field_index, msg, "while checking this field", .{});
......@@ -35685,17 +35673,17 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3568535673 const field_align = if (explicit_align != .none)
3568635674 explicit_align
3568735675 else
35688 try sema.typeAbiAlignment(field_ty);
35676 try field_ty.abiAlignmentSema(pt);
3568935677
3569035678 max_align = max_align.max(field_align);
3569135679 }
3569235680
3569335681 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and
35694 try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));
35682 try Type.fromInterned(union_type.enum_tag_ty).hasRuntimeBitsSema(pt);
3569535683 const size, const alignment, const padding = if (has_runtime_tag) layout: {
3569635684 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);
35685 const tag_align = try enum_tag_type.abiAlignmentSema(pt);
35686 const tag_size = try enum_tag_type.abiSizeSema(pt);
3569935687
3570035688 // Put the tag before or after the payload depending on which one's
3570135689 // alignment is greater.
......@@ -35727,7 +35715,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3572735715
3572835716 union_type.setHaveLayout(ip, @intCast(size), padding, alignment);
3572935717
35730 if (union_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35718 if (union_type.flagsUnordered(ip).assumed_runtime_bits and !(try ty.hasRuntimeBitsSema(pt))) {
3573135719 const msg = try sema.errMsg(
3573235720 ty.srcLoc(pt.zcu),
3573335721 "union layout depends on it having runtime bits",
......@@ -35746,6 +35734,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3574635734 );
3574735735 return sema.failWithOwnedErrorMsg(null, msg);
3574835736 }
35737 _ = try ty.comptimeOnlySema(pt);
3574935738}
3575035739
3575135740/// Returns `error.AnalysisFail` if any of the types (recursively) failed to
......@@ -35754,9 +35743,9 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {
3575435743 try sema.resolveStructLayout(ty);
3575535744
3575635745 const pt = sema.pt;
35757 const mod = pt.zcu;
35758 const ip = &mod.intern_pool;
35759 const struct_type = mod.typeToStruct(ty).?;
35746 const zcu = pt.zcu;
35747 const ip = &zcu.intern_pool;
35748 const struct_type = zcu.typeToStruct(ty).?;
3576035749
3576135750 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);
3576235751
......@@ -35777,9 +35766,9 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3577735766 try sema.resolveUnionLayout(ty);
3577835767
3577935768 const pt = sema.pt;
35780 const mod = pt.zcu;
35781 const ip = &mod.intern_pool;
35782 const union_obj = mod.typeToUnion(ty).?;
35769 const zcu = pt.zcu;
35770 const ip = &zcu.intern_pool;
35771 const union_obj = zcu.typeToUnion(ty).?;
3578335772
3578435773 assert(sema.owner.unwrap().cau == union_obj.cau);
3578535774
......@@ -35804,10 +35793,10 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3580435793 }
3580535794
3580635795 // And let's not forget comptime-only status.
35807 _ = try sema.typeRequiresComptime(ty);
35796 _ = try ty.comptimeOnlySema(pt);
3580835797}
3580935798
35810pub fn resolveTypeFieldsStruct(
35799pub fn resolveStructFieldTypes(
3581135800 sema: *Sema,
3581235801 ty: InternPool.Index,
3581335802 struct_type: InternPool.LoadedStructType,
......@@ -35830,7 +35819,7 @@ pub fn resolveTypeFieldsStruct(
3583035819 }
3583135820 defer struct_type.clearFieldTypesWip(ip);
3583235821
35833 semaStructFields(pt, sema.arena, struct_type) catch |err| switch (err) {
35822 sema.structFields(struct_type) catch |err| switch (err) {
3583435823 error.AnalysisFail, error.OutOfMemory => |e| return e,
3583535824 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
3583635825 };
......@@ -35859,14 +35848,14 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {
3585935848 }
3586035849 defer struct_type.clearInitsWip(ip);
3586135850
35862 semaStructFieldInits(pt, sema.arena, struct_type) catch |err| switch (err) {
35851 sema.structFieldInits(struct_type) catch |err| switch (err) {
3586335852 error.AnalysisFail, error.OutOfMemory => |e| return e,
3586435853 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
3586535854 };
3586635855 struct_type.setHaveFieldInits(ip);
3586735856}
3586835857
35869pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) SemaError!void {
35858pub fn resolveUnionFieldTypes(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) SemaError!void {
3587035859 const pt = sema.pt;
3587135860 const zcu = pt.zcu;
3587235861 const ip = &zcu.intern_pool;
......@@ -35893,7 +35882,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3589335882
3589435883 union_type.setStatus(ip, .field_types_wip);
3589535884 errdefer union_type.setStatus(ip, .none);
35896 semaUnionFields(pt, sema.arena, ty.toIntern(), union_type) catch |err| switch (err) {
35885 sema.unionFields(ty.toIntern(), union_type) catch |err| switch (err) {
3589735886 error.AnalysisFail, error.OutOfMemory => |e| return e,
3589835887 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
3589935888 };
......@@ -35950,7 +35939,7 @@ fn resolveInferredErrorSet(
3595035939 try pt.ensureFuncBodyAnalyzed(func_index);
3595135940 }
3595235941
35953 // This will now have been resolved by the logic at the end of `Module.analyzeFnBody`
35942 // This will now have been resolved by the logic at the end of `Zcu.analyzeFnBody`
3595435943 // which calls `resolveInferredErrorSetPtr`.
3595535944 const final_resolved_ty = func.resolvedErrorSetUnordered(ip);
3595635945 assert(final_resolved_ty != .none);
......@@ -35997,9 +35986,9 @@ fn resolveAdHocInferredErrorSet(
3599735986 value: InternPool.Index,
3599835987) CompileError!InternPool.Index {
3599935988 const pt = sema.pt;
36000 const mod = pt.zcu;
35989 const zcu = pt.zcu;
3600135990 const gpa = sema.gpa;
36002 const ip = &mod.intern_pool;
35991 const ip = &zcu.intern_pool;
3600335992 const new_ty = try resolveAdHocInferredErrorSetTy(sema, block, src, ip.typeOf(value));
3600435993 if (new_ty == .none) return value;
3600535994 return ip.getCoerced(gpa, pt.tid, value, new_ty);
......@@ -36013,8 +36002,8 @@ fn resolveAdHocInferredErrorSetTy(
3601336002) CompileError!InternPool.Index {
3601436003 const ies = sema.fn_ret_ty_ies orelse return .none;
3601536004 const pt = sema.pt;
36016 const mod = pt.zcu;
36017 const ip = &mod.intern_pool;
36005 const zcu = pt.zcu;
36006 const ip = &zcu.intern_pool;
3601836007 const error_union_info = switch (ip.indexToKey(ty)) {
3601936008 .error_union_type => |x| x,
3602036009 else => return .none,
......@@ -36037,8 +36026,8 @@ fn resolveInferredErrorSetTy(
3603736026 ty: InternPool.Index,
3603836027) CompileError!InternPool.Index {
3603936028 const pt = sema.pt;
36040 const mod = pt.zcu;
36041 const ip = &mod.intern_pool;
36029 const zcu = pt.zcu;
36030 const ip = &zcu.intern_pool;
3604236031 if (ty == .anyerror_type) return ty;
3604336032 switch (ip.indexToKey(ty)) {
3604436033 .error_set_type => return ty,
......@@ -36096,11 +36085,11 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct {
3609636085 return .{ fields_len, small, extra_index };
3609736086}
3609836087
36099fn semaStructFields(
36100 pt: Zcu.PerThread,
36101 arena: Allocator,
36088fn structFields(
36089 sema: *Sema,
3610236090 struct_type: InternPool.LoadedStructType,
3610336091) CompileError!void {
36092 const pt = sema.pt;
3610436093 const zcu = pt.zcu;
3610536094 const gpa = zcu.gpa;
3610636095 const ip = &zcu.intern_pool;
......@@ -36113,7 +36102,7 @@ fn semaStructFields(
3611336102
3611436103 if (fields_len == 0) switch (struct_type.layout) {
3611536104 .@"packed" => {
36116 try semaBackingIntType(pt, struct_type);
36105 try sema.backingIntType(struct_type);
3611736106 return;
3611836107 },
3611936108 .auto, .@"extern" => {
......@@ -36122,26 +36111,9 @@ fn semaStructFields(
3612236111 },
3612336112 };
3612436113
36125 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36126 defer comptime_err_ret_trace.deinit();
36127
36128 var sema: Sema = .{
36129 .pt = pt,
36130 .gpa = gpa,
36131 .arena = arena,
36132 .code = zir,
36133 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
36134 .func_index = .none,
36135 .func_is_naked = false,
36136 .fn_ret_ty = Type.void,
36137 .fn_ret_ty_ies = null,
36138 .comptime_err_ret_trace = &comptime_err_ret_trace,
36139 };
36140 defer sema.deinit();
36141
3614236114 var block_scope: Block = .{
3614336115 .parent = null,
36144 .sema = &sema,
36116 .sema = sema,
3614536117 .namespace = namespace_index,
3614636118 .instructions = .{},
3614736119 .inlining = null,
......@@ -36315,14 +36287,13 @@ fn semaStructFields(
3631536287 try sema.flushExports();
3631636288}
3631736289
36318// This logic must be kept in sync with `semaStructFields`
36319fn semaStructFieldInits(
36320 pt: Zcu.PerThread,
36321 arena: Allocator,
36290// This logic must be kept in sync with `structFields`
36291fn structFieldInits(
36292 sema: *Sema,
3632236293 struct_type: InternPool.LoadedStructType,
3632336294) CompileError!void {
36295 const pt = sema.pt;
3632436296 const zcu = pt.zcu;
36325 const gpa = zcu.gpa;
3632636297 const ip = &zcu.intern_pool;
3632736298
3632836299 assert(!struct_type.haveFieldInits(ip));
......@@ -36333,26 +36304,9 @@ fn semaStructFieldInits(
3633336304 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;
3633436305 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
3633536306
36336 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36337 defer comptime_err_ret_trace.deinit();
36338
36339 var sema: Sema = .{
36340 .pt = pt,
36341 .gpa = gpa,
36342 .arena = arena,
36343 .code = zir,
36344 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
36345 .func_index = .none,
36346 .func_is_naked = false,
36347 .fn_ret_ty = Type.void,
36348 .fn_ret_ty_ies = null,
36349 .comptime_err_ret_trace = &comptime_err_ret_trace,
36350 };
36351 defer sema.deinit();
36352
3635336307 var block_scope: Block = .{
3635436308 .parent = null,
36355 .sema = &sema,
36309 .sema = sema,
3635636310 .namespace = namespace_index,
3635736311 .instructions = .{},
3635836312 .inlining = null,
......@@ -36455,14 +36409,18 @@ fn semaStructFieldInits(
3645536409 try sema.flushExports();
3645636410}
3645736411
36458fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Index, union_type: InternPool.LoadedUnionType) CompileError!void {
36412fn unionFields(
36413 sema: *Sema,
36414 union_ty: InternPool.Index,
36415 union_type: InternPool.LoadedUnionType,
36416) CompileError!void {
3645936417 const tracy = trace(@src());
3646036418 defer tracy.end();
3646136419
36420 const pt = sema.pt;
3646236421 const zcu = pt.zcu;
3646336422 const gpa = zcu.gpa;
3646436423 const ip = &zcu.intern_pool;
36465 const cau_index = union_type.cau;
3646636424 const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir;
3646736425 const zir_index = union_type.zir_index.resolve(ip) orelse return error.AnalysisFail;
3646836426 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
......@@ -36507,26 +36465,9 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
3650736465 const body = zir.bodySlice(extra_index, body_len);
3650836466 extra_index += body.len;
3650936467
36510 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36511 defer comptime_err_ret_trace.deinit();
36512
36513 var sema: Sema = .{
36514 .pt = pt,
36515 .gpa = gpa,
36516 .arena = arena,
36517 .code = zir,
36518 .owner = AnalUnit.wrap(.{ .cau = cau_index }),
36519 .func_index = .none,
36520 .func_is_naked = false,
36521 .fn_ret_ty = Type.void,
36522 .fn_ret_ty_ies = null,
36523 .comptime_err_ret_trace = &comptime_err_ret_trace,
36524 };
36525 defer sema.deinit();
36526
3652736468 var block_scope: Block = .{
3652836469 .parent = null,
36529 .sema = &sema,
36470 .sema = sema,
3653036471 .namespace = union_type.namespace,
3653136472 .instructions = .{},
3653236473 .inlining = null,
......@@ -36669,7 +36610,10 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
3666936610
3667036611 if (enum_field_vals.capacity() > 0) {
3667136612 const enum_tag_val = if (tag_ref != .none) blk: {
36672 const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref);
36613 const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, value_src);
36614 const val = try sema.resolveConstDefinedValue(&block_scope, value_src, coerced, .{
36615 .needed_comptime_reason = "enum tag value must be comptime-known",
36616 });
3667336617 last_tag_val = val;
3667436618
3667536619 break :blk val;
......@@ -36689,7 +36633,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
3668936633 .offset = .{ .container_field_value = @intCast(gop.index) },
3669036634 };
3669136635 const msg = msg: {
36692 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValueSema(pt, &sema)});
36636 const msg = try sema.errMsg(
36637 value_src,
36638 "enum tag value {} already taken",
36639 .{enum_tag_val.fmtValueSema(pt, sema)},
36640 );
3669336641 errdefer msg.destroy(gpa);
3669436642 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
3669536643 break :msg msg;
......@@ -36829,13 +36777,6 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
3682936777 try sema.flushExports();
3683036778}
3683136779
36832fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value {
36833 const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src);
36834 return sema.resolveConstDefinedValue(block, src, coerced, .{
36835 .needed_comptime_reason = "enum tag value must be comptime-known",
36836 });
36837}
36838
3683936780fn generateUnionTagTypeNumbered(
3684036781 sema: *Sema,
3684136782 block: *Block,
......@@ -36845,9 +36786,9 @@ fn generateUnionTagTypeNumbered(
3684536786 union_name: InternPool.NullTerminatedString,
3684636787) !InternPool.Index {
3684736788 const pt = sema.pt;
36848 const mod = pt.zcu;
36789 const zcu = pt.zcu;
3684936790 const gpa = sema.gpa;
36850 const ip = &mod.intern_pool;
36791 const ip = &zcu.intern_pool;
3685136792
3685236793 const name = try ip.getOrPutStringFmt(
3685336794 gpa,
......@@ -36881,8 +36822,8 @@ fn generateUnionTagTypeSimple(
3688136822 union_name: InternPool.NullTerminatedString,
3688236823) !InternPool.Index {
3688336824 const pt = sema.pt;
36884 const mod = pt.zcu;
36885 const ip = &mod.intern_pool;
36825 const zcu = pt.zcu;
36826 const ip = &zcu.intern_pool;
3688636827 const gpa = sema.gpa;
3688736828
3688836829 const name = try ip.getOrPutStringFmt(
......@@ -37192,7 +37133,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3719237133 return null;
3719337134 },
3719437135 .auto, .explicit => {
37195 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(pt)) return null;
37136 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null;
3719637137
3719737138 return Value.fromInterned(switch (enum_type.names.len) {
3719837139 0 => try pt.intern(.{ .empty_enum_value = ty.toIntern() }),
......@@ -37279,7 +37220,7 @@ fn analyzeComptimeAlloc(
3727937220 alignment: Alignment,
3728037221) CompileError!Air.Inst.Ref {
3728137222 const pt = sema.pt;
37282 const mod = pt.zcu;
37223 const zcu = pt.zcu;
3728337224
3728437225 // Needed to make an anon decl with type `var_type` (the `finish()` call below).
3728537226 _ = try sema.typeHasOnePossibleValue(var_type);
......@@ -37288,7 +37229,7 @@ fn analyzeComptimeAlloc(
3728837229 .child = var_type.toIntern(),
3728937230 .flags = .{
3729037231 .alignment = alignment,
37291 .address_space = target_util.defaultAddressSpace(mod.getTarget(), .global_constant),
37232 .address_space = target_util.defaultAddressSpace(zcu.getTarget(), .global_constant),
3729237233 },
3729337234 });
3729437235
......@@ -37338,13 +37279,13 @@ pub fn analyzeAsAddressSpace(
3733837279 ctx: AddressSpaceContext,
3733937280) !std.builtin.AddressSpace {
3734037281 const pt = sema.pt;
37341 const mod = pt.zcu;
37282 const zcu = pt.zcu;
3734237283 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
3734337284 const coerced = try sema.coerce(block, addrspace_ty, air_ref, src);
3734437285 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{
3734537286 .needed_comptime_reason = "address space must be comptime-known",
3734637287 });
37347 const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_val);
37288 const address_space = zcu.toEnum(std.builtin.AddressSpace, addrspace_val);
3734837289 const target = pt.zcu.getTarget();
3734937290 const arch = target.cpu.arch;
3735037291
......@@ -37446,13 +37387,13 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError
3744637387/// This logic must be kept in sync with `Type.isPtrLikeOptional`.
3744737388fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3744837389 const pt = sema.pt;
37449 const mod = pt.zcu;
37450 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
37390 const zcu = pt.zcu;
37391 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
3745137392 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
3745237393 .One, .Many, .C => ty,
3745337394 .Slice => null,
3745437395 },
37455 .opt_type => |opt_child| switch (mod.intern_pool.indexToKey(opt_child)) {
37396 .opt_type => |opt_child| switch (zcu.intern_pool.indexToKey(opt_child)) {
3745637397 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
3745737398 .Slice, .C => null,
3745837399 .Many, .One => {
......@@ -37473,33 +37414,6 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3747337414 };
3747437415}
3747537416
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
3750337417fn unionFieldIndex(
3750437418 sema: *Sema,
3750537419 block: *Block,
......@@ -37508,10 +37422,10 @@ fn unionFieldIndex(
3750837422 field_src: LazySrcLoc,
3750937423) !u32 {
3751037424 const pt = sema.pt;
37511 const mod = pt.zcu;
37512 const ip = &mod.intern_pool;
37425 const zcu = pt.zcu;
37426 const ip = &zcu.intern_pool;
3751337427 try union_ty.resolveFields(pt);
37514 const union_obj = mod.typeToUnion(union_ty).?;
37428 const union_obj = zcu.typeToUnion(union_ty).?;
3751537429 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
3751637430 return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name);
3751737431 return @intCast(field_index);
......@@ -37525,13 +37439,13 @@ fn structFieldIndex(
3752537439 field_src: LazySrcLoc,
3752637440) !u32 {
3752737441 const pt = sema.pt;
37528 const mod = pt.zcu;
37529 const ip = &mod.intern_pool;
37442 const zcu = pt.zcu;
37443 const ip = &zcu.intern_pool;
3753037444 try struct_ty.resolveFields(pt);
37531 if (struct_ty.isAnonStruct(mod)) {
37445 if (struct_ty.isAnonStruct(zcu)) {
3753237446 return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src);
3753337447 } else {
37534 const struct_type = mod.typeToStruct(struct_ty).?;
37448 const struct_type = zcu.typeToStruct(struct_ty).?;
3753537449 return struct_type.nameIndex(ip, field_name) orelse
3753637450 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name);
3753737451 }
......@@ -37545,8 +37459,8 @@ fn anonStructFieldIndex(
3754537459 field_src: LazySrcLoc,
3754637460) !u32 {
3754737461 const pt = sema.pt;
37548 const mod = pt.zcu;
37549 const ip = &mod.intern_pool;
37462 const zcu = pt.zcu;
37463 const ip = &zcu.intern_pool;
3755037464 switch (ip.indexToKey(struct_ty.toIntern())) {
3755137465 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names.get(ip), 0..) |name, i| {
3755237466 if (name == field_name) return @intCast(i);
......@@ -37583,10 +37497,10 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize)
3758337497
3758437498fn intAddInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize) !Value {
3758537499 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);
37500 const zcu = pt.zcu;
37501 if (ty.zigTypeTag(zcu) == .Vector) {
37502 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
37503 const scalar_ty = ty.scalarType(zcu);
3759037504 for (result_data, 0..) |*scalar, i| {
3759137505 const lhs_elem = try lhs.elemValue(pt, i);
3759237506 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -37611,15 +37525,15 @@ fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
3761137525 const pt = sema.pt;
3761237526 if (scalar_ty.toIntern() != .comptime_int_type) {
3761337527 const res = try sema.intAddWithOverflowScalar(lhs, rhs, scalar_ty);
37614 if (res.overflow_bit.compareAllWithZero(.neq, pt)) return error.Overflow;
37528 if (res.overflow_bit.compareAllWithZero(.neq, pt.zcu)) return error.Overflow;
3761537529 return res.wrapped_result;
3761637530 }
3761737531 // TODO is this a performance issue? maybe we should try the operation without
3761837532 // resorting to BigInt first.
3761937533 var lhs_space: Value.BigIntSpace = undefined;
3762037534 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);
37535 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37536 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3762337537 const limbs = try sema.arena.alloc(
3762437538 std.math.big.Limb,
3762537539 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
......@@ -37637,10 +37551,10 @@ fn numberAddWrapScalar(
3763737551 ty: Type,
3763837552) !Value {
3763937553 const pt = sema.pt;
37640 const mod = pt.zcu;
37641 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return pt.undefValue(ty);
37554 const zcu = pt.zcu;
37555 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return pt.undefValue(ty);
3764237556
37643 if (ty.zigTypeTag(mod) == .ComptimeInt) {
37557 if (ty.zigTypeTag(zcu) == .ComptimeInt) {
3764437558 return sema.intAdd(lhs, rhs, ty, undefined);
3764537559 }
3764637560
......@@ -37701,17 +37615,18 @@ fn intSubInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi
3770137615
3770237616fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
3770337617 const pt = sema.pt;
37618 const zcu = pt.zcu;
3770437619 if (scalar_ty.toIntern() != .comptime_int_type) {
3770537620 const res = try sema.intSubWithOverflowScalar(lhs, rhs, scalar_ty);
37706 if (res.overflow_bit.compareAllWithZero(.neq, pt)) return error.Overflow;
37621 if (res.overflow_bit.compareAllWithZero(.neq, zcu)) return error.Overflow;
3770737622 return res.wrapped_result;
3770837623 }
3770937624 // TODO is this a performance issue? maybe we should try the operation without
3771037625 // resorting to BigInt first.
3771137626 var lhs_space: Value.BigIntSpace = undefined;
3771237627 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);
37628 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37629 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3771537630 const limbs = try sema.arena.alloc(
3771637631 std.math.big.Limb,
3771737632 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
......@@ -37729,10 +37644,10 @@ fn numberSubWrapScalar(
3772937644 ty: Type,
3773037645) !Value {
3773137646 const pt = sema.pt;
37732 const mod = pt.zcu;
37733 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return pt.undefValue(ty);
37647 const zcu = pt.zcu;
37648 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return pt.undefValue(ty);
3773437649
37735 if (ty.zigTypeTag(mod) == .ComptimeInt) {
37650 if (ty.zigTypeTag(zcu) == .ComptimeInt) {
3773637651 return sema.intSub(lhs, rhs, ty, undefined);
3773737652 }
3773837653
......@@ -37751,12 +37666,12 @@ fn intSubWithOverflow(
3775137666 ty: Type,
3775237667) !Value.OverflowArithmeticResult {
3775337668 const pt = sema.pt;
37754 const mod = pt.zcu;
37755 if (ty.zigTypeTag(mod) == .Vector) {
37756 const vec_len = ty.vectorLen(mod);
37669 const zcu = pt.zcu;
37670 if (ty.zigTypeTag(zcu) == .Vector) {
37671 const vec_len = ty.vectorLen(zcu);
3775737672 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
3775837673 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);
37759 const scalar_ty = ty.scalarType(mod);
37674 const scalar_ty = ty.scalarType(zcu);
3776037675 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
3776137676 const lhs_elem = try lhs.elemValue(pt, i);
3776237677 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -37785,10 +37700,10 @@ fn intSubWithOverflowScalar(
3778537700 ty: Type,
3778637701) !Value.OverflowArithmeticResult {
3778737702 const pt = sema.pt;
37788 const mod = pt.zcu;
37789 const info = ty.intInfo(mod);
37703 const zcu = pt.zcu;
37704 const info = ty.intInfo(zcu);
3779037705
37791 if (lhs.isUndef(mod) or rhs.isUndef(mod)) {
37706 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) {
3779237707 return .{
3779337708 .overflow_bit = try pt.undefValue(Type.u1),
3779437709 .wrapped_result = try pt.undefValue(ty),
......@@ -37797,8 +37712,8 @@ fn intSubWithOverflowScalar(
3779737712
3779837713 var lhs_space: Value.BigIntSpace = undefined;
3779937714 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);
37715 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37716 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3780237717 const limbs = try sema.arena.alloc(
3780337718 std.math.big.Limb,
3780437719 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -37824,12 +37739,12 @@ fn intFromFloat(
3782437739 mode: IntFromFloatMode,
3782537740) CompileError!Value {
3782637741 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));
37742 const zcu = pt.zcu;
37743 if (float_ty.zigTypeTag(zcu) == .Vector) {
37744 const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(zcu));
3783037745 for (result_data, 0..) |*scalar, i| {
3783137746 const elem_val = try val.elemValue(pt, i);
37832 scalar.* = (try sema.intFromFloatScalar(block, src, elem_val, int_ty.scalarType(mod), mode)).toIntern();
37747 scalar.* = (try sema.intFromFloatScalar(block, src, elem_val, int_ty.scalarType(zcu), mode)).toIntern();
3783337748 }
3783437749 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
3783537750 .ty = int_ty.toIntern(),
......@@ -37873,18 +37788,18 @@ fn intFromFloatScalar(
3787337788 mode: IntFromFloatMode,
3787437789) CompileError!Value {
3787537790 const pt = sema.pt;
37876 const mod = pt.zcu;
37791 const zcu = pt.zcu;
3787737792
37878 if (val.isUndef(mod)) return sema.failWithUseOfUndef(block, src);
37793 if (val.isUndef(zcu)) return sema.failWithUseOfUndef(block, src);
3787937794
37880 if (mode == .exact and val.floatHasFraction(mod)) return sema.fail(
37795 if (mode == .exact and val.floatHasFraction(zcu)) return sema.fail(
3788137796 block,
3788237797 src,
3788337798 "fractional component prevents float value '{}' from coercion to type '{}'",
3788437799 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },
3788537800 );
3788637801
37887 const float = val.toFloat(f128, pt);
37802 const float = val.toFloat(f128, zcu);
3788837803 if (std.math.isNan(float)) {
3788937804 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{}'", .{
3789037805 int_ty.fmt(pt),
......@@ -37920,15 +37835,15 @@ fn intFitsInType(
3792037835 vector_index: ?*usize,
3792137836) CompileError!bool {
3792237837 const pt = sema.pt;
37923 const mod = pt.zcu;
37838 const zcu = pt.zcu;
3792437839 if (ty.toIntern() == .comptime_int_type) return true;
37925 const info = ty.intInfo(mod);
37840 const info = ty.intInfo(zcu);
3792637841 switch (val.toIntern()) {
3792737842 .zero_usize, .zero_u8 => return true,
37928 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
37843 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
3792937844 .undef => return true,
3793037845 .variable, .@"extern", .func, .ptr => {
37931 const target = mod.getTarget();
37846 const target = zcu.getTarget();
3793237847 const ptr_bits = target.ptrBitWidth();
3793337848 return switch (info.signedness) {
3793437849 .signed => info.bits > ptr_bits,
......@@ -37945,7 +37860,7 @@ fn intFitsInType(
3794537860 const max_needed_bits = @as(u16, 16) + @intFromBool(info.signedness == .signed);
3794637861 // If it is u16 or bigger we know the alignment fits without resolving it.
3794737862 if (info.bits >= max_needed_bits) return true;
37948 const x = try sema.typeAbiAlignment(Type.fromInterned(lazy_ty));
37863 const x = try Type.fromInterned(lazy_ty).abiAlignmentSema(pt);
3794937864 if (x == .none) return true;
3795037865 const actual_needed_bits = @as(usize, x.toLog2Units()) + 1 + @intFromBool(info.signedness == .signed);
3795137866 return info.bits >= actual_needed_bits;
......@@ -37954,16 +37869,16 @@ fn intFitsInType(
3795437869 const max_needed_bits = @as(u16, 64) + @intFromBool(info.signedness == .signed);
3795537870 // If it is u64 or bigger we know the size fits without resolving it.
3795637871 if (info.bits >= max_needed_bits) return true;
37957 const x = try sema.typeAbiSize(Type.fromInterned(lazy_ty));
37872 const x = try Type.fromInterned(lazy_ty).abiSizeSema(pt);
3795837873 if (x == 0) return true;
3795937874 const actual_needed_bits = std.math.log2(x) + 1 + @intFromBool(info.signedness == .signed);
3796037875 return info.bits >= actual_needed_bits;
3796137876 },
3796237877 },
3796337878 .aggregate => |aggregate| {
37964 assert(ty.zigTypeTag(mod) == .Vector);
37879 assert(ty.zigTypeTag(zcu) == .Vector);
3796537880 return switch (aggregate.storage) {
37966 .bytes => |bytes| for (bytes.toSlice(ty.vectorLen(mod), &mod.intern_pool), 0..) |byte, i| {
37881 .bytes => |bytes| for (bytes.toSlice(ty.vectorLen(zcu), &zcu.intern_pool), 0..) |byte, i| {
3796737882 if (byte == 0) continue;
3796837883 const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed);
3796937884 if (info.bits >= actual_needed_bits) continue;
......@@ -37975,7 +37890,7 @@ fn intFitsInType(
3797537890 .elems => |elems| elems,
3797637891 .repeated_elem => |elem| @as(*const [1]InternPool.Index, &elem),
3797737892 }, 0..) |elem, i| {
37978 if (try sema.intFitsInType(Value.fromInterned(elem), ty.scalarType(mod), null)) continue;
37893 if (try sema.intFitsInType(Value.fromInterned(elem), ty.scalarType(zcu), null)) continue;
3797937894 if (vector_index) |vi| vi.* = i;
3798037895 break false;
3798137896 } else true,
......@@ -37997,15 +37912,15 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {
3799737912/// Asserts the type is an enum.
3799837913fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
3799937914 const pt = sema.pt;
38000 const mod = pt.zcu;
38001 const enum_type = mod.intern_pool.loadEnumType(ty.toIntern());
37915 const zcu = pt.zcu;
37916 const enum_type = zcu.intern_pool.loadEnumType(ty.toIntern());
3800237917 assert(enum_type.tag_mode != .nonexhaustive);
3800337918 // The `tagValueIndex` function call below relies on the type being the integer tag type.
3800437919 // `getCoerced` assumes the value will fit the new type.
3800537920 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;
3800637921 const int_coerced = try pt.getCoerced(int, Type.fromInterned(enum_type.tag_ty));
3800737922
38008 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced.toIntern()) != null;
37923 return enum_type.tagValueIndex(&zcu.intern_pool, int_coerced.toIntern()) != null;
3800937924}
3801037925
3801137926fn intAddWithOverflow(
......@@ -38015,12 +37930,12 @@ fn intAddWithOverflow(
3801537930 ty: Type,
3801637931) !Value.OverflowArithmeticResult {
3801737932 const pt = sema.pt;
38018 const mod = pt.zcu;
38019 if (ty.zigTypeTag(mod) == .Vector) {
38020 const vec_len = ty.vectorLen(mod);
37933 const zcu = pt.zcu;
37934 if (ty.zigTypeTag(zcu) == .Vector) {
37935 const vec_len = ty.vectorLen(zcu);
3802137936 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
3802237937 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);
38023 const scalar_ty = ty.scalarType(mod);
37938 const scalar_ty = ty.scalarType(zcu);
3802437939 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
3802537940 const lhs_elem = try lhs.elemValue(pt, i);
3802637941 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -38049,10 +37964,10 @@ fn intAddWithOverflowScalar(
3804937964 ty: Type,
3805037965) !Value.OverflowArithmeticResult {
3805137966 const pt = sema.pt;
38052 const mod = pt.zcu;
38053 const info = ty.intInfo(mod);
37967 const zcu = pt.zcu;
37968 const info = ty.intInfo(zcu);
3805437969
38055 if (lhs.isUndef(mod) or rhs.isUndef(mod)) {
37970 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) {
3805637971 return .{
3805737972 .overflow_bit = try pt.undefValue(Type.u1),
3805837973 .wrapped_result = try pt.undefValue(ty),
......@@ -38061,8 +37976,8 @@ fn intAddWithOverflowScalar(
3806137976
3806237977 var lhs_space: Value.BigIntSpace = undefined;
3806337978 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);
37979 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37980 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
3806637981 const limbs = try sema.arena.alloc(
3806737982 std.math.big.Limb,
3806837983 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -38088,13 +38003,13 @@ fn compareAll(
3808838003 ty: Type,
3808938004) CompileError!bool {
3809038005 const pt = sema.pt;
38091 const mod = pt.zcu;
38092 if (ty.zigTypeTag(mod) == .Vector) {
38006 const zcu = pt.zcu;
38007 if (ty.zigTypeTag(zcu) == .Vector) {
3809338008 var i: usize = 0;
38094 while (i < ty.vectorLen(mod)) : (i += 1) {
38009 while (i < ty.vectorLen(zcu)) : (i += 1) {
3809538010 const lhs_elem = try lhs.elemValue(pt, i);
3809638011 const rhs_elem = try rhs.elemValue(pt, i);
38097 if (!(try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod)))) {
38012 if (!(try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(zcu)))) {
3809838013 return false;
3809938014 }
3810038015 }
......@@ -38117,7 +38032,7 @@ fn compareScalar(
3811738032 switch (op) {
3811838033 .eq => return sema.valuesEqual(coerced_lhs, coerced_rhs, ty),
3811938034 .neq => return !(try sema.valuesEqual(coerced_lhs, coerced_rhs, ty)),
38120 else => return Value.compareHeteroAdvanced(coerced_lhs, op, coerced_rhs, pt, .sema),
38035 else => return Value.compareHeteroSema(coerced_lhs, op, coerced_rhs, pt),
3812138036 }
3812238037}
3812338038
......@@ -38139,17 +38054,17 @@ fn compareVector(
3813938054 ty: Type,
3814038055) !Value {
3814138056 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));
38057 const zcu = pt.zcu;
38058 assert(ty.zigTypeTag(zcu) == .Vector);
38059 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
3814538060 for (result_data, 0..) |*scalar, i| {
3814638061 const lhs_elem = try lhs.elemValue(pt, i);
3814738062 const rhs_elem = try rhs.elemValue(pt, i);
38148 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));
38063 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(zcu));
3814938064 scalar.* = Value.makeBool(res_bool).toIntern();
3815038065 }
3815138066 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
38152 .ty = (try pt.vectorType(.{ .len = ty.vectorLen(mod), .child = .bool_type })).toIntern(),
38067 .ty = (try pt.vectorType(.{ .len = ty.vectorLen(zcu), .child = .bool_type })).toIntern(),
3815338068 .storage = .{ .elems = result_data },
3815438069 } }));
3815538070}
......@@ -38250,8 +38165,8 @@ fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Ai
3825038165/// Returns true if any value contained in `val` is undefined.
3825138166fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {
3825238167 const pt = sema.pt;
38253 const mod = pt.zcu;
38254 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
38168 const zcu = pt.zcu;
38169 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
3825538170 .undef => true,
3825638171 .simple_value => |v| v == .undefined,
3825738172 .slice => {
......@@ -38261,7 +38176,7 @@ fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {
3826138176 return sema.anyUndef(block, src, arr);
3826238177 },
3826338178 .aggregate => |aggregate| for (0..aggregate.storage.values().len) |i| {
38264 const elem = mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.values()[i];
38179 const elem = zcu.intern_pool.indexToKey(val.toIntern()).aggregate.storage.values()[i];
3826538180 if (try sema.anyUndef(block, src, Value.fromInterned(elem))) break true;
3826638181 } else false,
3826738182 else => false,
......@@ -38510,7 +38425,7 @@ pub fn resolveDeclaredEnum(
3851038425 wip_ty.setTagTy(ip, int_tag_ty.toIntern());
3851138426
3851238427 if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) {
38513 if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(pt)) {
38428 if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(zcu)) {
3851438429 return sema.fail(&block, src, "non-exhaustive enum specifies every value", .{});
3851538430 }
3851638431 }
src/Sema/bitcast.zig+51-47
......@@ -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);
543 const field_ty = ty.structFieldType(field_idx, zcu);
545 const field_ty = ty.fieldType(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| {
553 const field_ty = ty.structFieldType(field_idx, zcu);
554 const want_bit_off = ty.structFieldOffset(field_idx, pt) * 8 + field_ty.bitSize(pt);
555 const field_ty = ty.fieldType(field_idx, zcu);
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 },
......@@ -576,7 +578,7 @@ const PackValueBits = struct {
576578 // This is identical between LE and BE targets.
577579 const elems = try arena.alloc(InternPool.Index, ty.structFieldCount(zcu));
578580 for (elems, 0..) |*elem, i| {
579 const field_ty = ty.structFieldType(i, zcu);
581 const field_ty = ty.fieldType(i, zcu);
580582 elem.* = (try pack.get(field_ty)).toIntern();
581583 }
582584 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
......@@ -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.fieldType(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.fieldType(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+836-525
......@@ -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;
745}
746
747pub fn hasRuntimeBitsIgnoreComptime(ty: Type, pt: Zcu.PerThread) bool {
748 return hasRuntimeBitsAdvanced(ty, pt, true, .eager) catch unreachable;
773pub fn fnHasRuntimeBits(ty: Type, zcu: *Zcu) bool {
774 return ty.fnHasRuntimeBitsInner(.normal, zcu, {}) catch unreachable;
749775}
750776
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`.
1159pub fn lazyAbiSize(ty: Type, pt: Zcu.PerThread) !Value {
1160 switch (try ty.abiSizeAdvanced(pt, .lazy)) {
1262pub fn abiSizeLazy(ty: Type, pt: Zcu.PerThread) !Value {
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;
16051716}
16061717
1607pub fn bitSizeAdvanced(
1718pub fn bitSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {
1719 return bitSizeInner(ty, .sema, pt.zcu, pt.tid);
1720}
1721
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}
......@@ -2898,9 +3028,9 @@ pub fn getParentNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex
28983028
28993029// Works for vectors and vectors of integers.
29003030pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2901 const mod = pt.zcu;
2902 const scalar = try minIntScalar(ty.scalarType(mod), pt, dest_ty.scalarType(mod));
2903 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
3031 const zcu = pt.zcu;
3032 const scalar = try minIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
3033 return if (ty.zigTypeTag(zcu) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
29043034 .ty = dest_ty.toIntern(),
29053035 .storage = .{ .repeated_elem = scalar.toIntern() },
29063036 } })) else scalar;
......@@ -2908,8 +3038,8 @@ pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
29083038
29093039/// Asserts that the type is an integer.
29103040pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2911 const mod = pt.zcu;
2912 const info = ty.intInfo(mod);
3041 const zcu = pt.zcu;
3042 const info = ty.intInfo(zcu);
29133043 if (info.signedness == .unsigned) return pt.intValue(dest_ty, 0);
29143044 if (info.bits == 0) return pt.intValue(dest_ty, -1);
29153045
......@@ -2918,7 +3048,7 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
29183048 return pt.intValue(dest_ty, n);
29193049 }
29203050
2921 var res = try std.math.big.int.Managed.init(mod.gpa);
3051 var res = try std.math.big.int.Managed.init(zcu.gpa);
29223052 defer res.deinit();
29233053
29243054 try res.setTwosCompIntLimit(.min, info.signedness, info.bits);
......@@ -2929,9 +3059,9 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
29293059// Works for vectors and vectors of integers.
29303060/// The returned Value will have type dest_ty.
29313061pub fn maxInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2932 const mod = pt.zcu;
2933 const scalar = try maxIntScalar(ty.scalarType(mod), pt, dest_ty.scalarType(mod));
2934 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
3062 const zcu = pt.zcu;
3063 const scalar = try maxIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
3064 return if (ty.zigTypeTag(zcu) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
29353065 .ty = dest_ty.toIntern(),
29363066 .storage = .{ .repeated_elem = scalar.toIntern() },
29373067 } })) else scalar;
......@@ -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,
......@@ -3061,9 +3191,9 @@ pub fn structFieldCount(ty: Type, mod: *Module) u32 {
30613191 };
30623192}
30633193
3064/// Supports structs and unions.
3065pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {
3066 const ip = &mod.intern_pool;
3194/// Returns the field type. Supports structs and unions.
3195pub fn fieldType(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,150 @@ 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 fieldAlignment(ty: Type, index: usize, zcu: *Zcu) Alignment {
3209 return ty.fieldAlignmentInner(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 fieldAlignmentSema(ty: Type, index: usize, pt: Zcu.PerThread) SemaError!Alignment {
3213 return try ty.fieldAlignmentInner(index, .sema, pt.zcu, pt.tid);
3214}
3215
3216/// Returns the field alignment. Supports structs and unions.
3217/// If `strat` is `.sema`, may perform type resolution.
3218/// Asserts the layout is not packed.
3219///
3220/// Provide the struct field as the `ty`.
3221pub fn fieldAlignmentInner(
3222 ty: Type,
3223 index: usize,
3224 comptime strat: ResolveStrat,
3225 zcu: *Zcu,
3226 tid: strat.Tid(),
3227) SemaError!Alignment {
3228 const ip = &zcu.intern_pool;
30843229 switch (ip.indexToKey(ty.toIntern())) {
30853230 .struct_type => {
30863231 const struct_type = ip.loadStructType(ty.toIntern());
30873232 assert(struct_type.layout != .@"packed");
30883233 const explicit_align = struct_type.fieldAlign(ip, index);
30893234 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[index]);
3090 return pt.structFieldAlignmentAdvanced(explicit_align, field_ty, struct_type.layout, strat);
3235 return field_ty.structFieldAlignmentInner(explicit_align, struct_type.layout, strat, zcu, tid);
30913236 },
30923237 .anon_struct_type => |anon_struct| {
3093 return (try Type.fromInterned(anon_struct.types.get(ip)[index]).abiAlignmentAdvanced(pt, strat.toLazy())).scalar;
3238 return (try Type.fromInterned(anon_struct.types.get(ip)[index]).abiAlignmentInner(
3239 strat.toLazy(),
3240 zcu,
3241 tid,
3242 )).scalar;
30943243 },
30953244 .union_type => {
30963245 const union_obj = ip.loadUnionType(ty.toIntern());
3097 return pt.unionFieldNormalAlignmentAdvanced(union_obj, @intCast(index), strat);
3246 const layout = union_obj.flagsUnordered(ip).layout;
3247 assert(layout != .@"packed");
3248 const explicit_align = union_obj.fieldAlign(ip, index);
3249 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[index]);
3250 return field_ty.unionFieldAlignmentInner(explicit_align, layout, strat, zcu, tid);
30983251 },
30993252 else => unreachable,
31003253 }
31013254}
31023255
3103pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value {
3104 const ip = &mod.intern_pool;
3256/// Returns the alignment of a non-packed struct field. Assert the layout is not packed.
3257///
3258/// Asserts that all resolution needed was done.
3259pub fn structFieldAlignment(
3260 field_ty: Type,
3261 explicit_alignment: InternPool.Alignment,
3262 layout: std.builtin.Type.ContainerLayout,
3263 zcu: *Zcu,
3264) Alignment {
3265 return field_ty.structFieldAlignmentInner(
3266 explicit_alignment,
3267 layout,
3268 .normal,
3269 zcu,
3270 {},
3271 ) catch unreachable;
3272}
3273
3274/// Returns the alignment of a non-packed struct field. Assert the layout is not packed.
3275/// May do type resolution when needed.
3276/// Asserts that all resolution needed was done.
3277pub fn structFieldAlignmentSema(
3278 field_ty: Type,
3279 explicit_alignment: InternPool.Alignment,
3280 layout: std.builtin.Type.ContainerLayout,
3281 pt: Zcu.PerThread,
3282) SemaError!Alignment {
3283 return try field_ty.structFieldAlignmentInner(
3284 explicit_alignment,
3285 layout,
3286 .sema,
3287 pt.zcu,
3288 pt.tid,
3289 );
3290}
3291
3292/// Returns the alignment of a non-packed struct field. Asserts the layout is not packed.
3293/// If `strat` is `.sema`, may perform type resolution.
3294pub fn structFieldAlignmentInner(
3295 field_ty: Type,
3296 explicit_alignment: Alignment,
3297 layout: std.builtin.Type.ContainerLayout,
3298 comptime strat: Type.ResolveStrat,
3299 zcu: *Zcu,
3300 tid: strat.Tid(),
3301) SemaError!Alignment {
3302 assert(layout != .@"packed");
3303 if (explicit_alignment != .none) return explicit_alignment;
3304 const ty_abi_align = (try field_ty.abiAlignmentInner(
3305 strat.toLazy(),
3306 zcu,
3307 tid,
3308 )).scalar;
3309 switch (layout) {
3310 .@"packed" => unreachable,
3311 .auto => if (zcu.getTarget().ofmt != .c) return ty_abi_align,
3312 .@"extern" => {},
3313 }
3314 // extern
3315 if (field_ty.isAbiInt(zcu) and field_ty.intInfo(zcu).bits >= 128) {
3316 return ty_abi_align.maxStrict(.@"16");
3317 }
3318 return ty_abi_align;
3319}
3320
3321pub fn unionFieldAlignmentSema(
3322 field_ty: Type,
3323 explicit_alignment: Alignment,
3324 layout: std.builtin.Type.ContainerLayout,
3325 pt: Zcu.PerThread,
3326) SemaError!Alignment {
3327 return field_ty.unionFieldAlignmentInner(
3328 explicit_alignment,
3329 layout,
3330 .sema,
3331 pt.zcu,
3332 pt.tid,
3333 );
3334}
3335
3336pub fn unionFieldAlignmentInner(
3337 field_ty: Type,
3338 explicit_alignment: Alignment,
3339 layout: std.builtin.Type.ContainerLayout,
3340 comptime strat: Type.ResolveStrat,
3341 zcu: *Zcu,
3342 tid: strat.Tid(),
3343) SemaError!Alignment {
3344 assert(layout != .@"packed");
3345 if (explicit_alignment != .none) return explicit_alignment;
3346 if (field_ty.isNoReturn(zcu)) return .none;
3347 return (try field_ty.abiAlignmentInner(strat.toLazy(), zcu, tid)).scalar;
3348}
3349
3350pub fn structFieldDefaultValue(ty: Type, index: usize, zcu: *const Zcu) Value {
3351 const ip = &zcu.intern_pool;
31053352 switch (ip.indexToKey(ty.toIntern())) {
31063353 .struct_type => {
31073354 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3121,8 +3368,8 @@ pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value {
31213368}
31223369
31233370pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Value {
3124 const mod = pt.zcu;
3125 const ip = &mod.intern_pool;
3371 const zcu = pt.zcu;
3372 const ip = &zcu.intern_pool;
31263373 switch (ip.indexToKey(ty.toIntern())) {
31273374 .struct_type => {
31283375 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3145,8 +3392,8 @@ pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Val
31453392 }
31463393}
31473394
3148pub fn structFieldIsComptime(ty: Type, index: usize, mod: *Module) bool {
3149 const ip = &mod.intern_pool;
3395pub fn structFieldIsComptime(ty: Type, index: usize, zcu: *const Zcu) bool {
3396 const ip = &zcu.intern_pool;
31503397 return switch (ip.indexToKey(ty.toIntern())) {
31513398 .struct_type => ip.loadStructType(ty.toIntern()).fieldIsComptime(ip, index),
31523399 .anon_struct_type => |anon_struct| anon_struct.values.get(ip)[index] != .none,
......@@ -3160,9 +3407,12 @@ pub const FieldOffset = struct {
31603407};
31613408
31623409/// 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;
3410pub fn structFieldOffset(
3411 ty: Type,
3412 index: usize,
3413 zcu: *Zcu,
3414) u64 {
3415 const ip = &zcu.intern_pool;
31663416 switch (ip.indexToKey(ty.toIntern())) {
31673417 .struct_type => {
31683418 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3176,17 +3426,17 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
31763426 var big_align: Alignment = .none;
31773427
31783428 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)) {
3429 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) {
31803430 // comptime field
31813431 if (i == index) return offset;
31823432 continue;
31833433 }
31843434
3185 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
3435 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
31863436 big_align = big_align.max(field_align);
31873437 offset = field_align.forward(offset);
31883438 if (i == index) return offset;
3189 offset += Type.fromInterned(field_ty).abiSize(pt);
3439 offset += Type.fromInterned(field_ty).abiSize(zcu);
31903440 }
31913441 offset = big_align.max(.@"1").forward(offset);
31923442 return offset;
......@@ -3196,7 +3446,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
31963446 const union_type = ip.loadUnionType(ty.toIntern());
31973447 if (!union_type.hasTag(ip))
31983448 return 0;
3199 const layout = pt.getUnionLayout(union_type);
3449 const layout = Type.getUnionLayout(union_type, zcu);
32003450 if (layout.tag_align.compare(.gte, layout.payload_align)) {
32013451 // {Tag, Payload}
32023452 return layout.payload_align.forward(layout.tag_size);
......@@ -3210,7 +3460,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
32103460 }
32113461}
32123462
3213pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {
3463pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Zcu.LazySrcLoc {
32143464 const ip = &zcu.intern_pool;
32153465 return .{
32163466 .base_node_inst = switch (ip.indexToKey(ty.toIntern())) {
......@@ -3222,11 +3472,11 @@ pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {
32223472 },
32233473 else => return null,
32243474 },
3225 .offset = Module.LazySrcLoc.Offset.nodeOffset(0),
3475 .offset = Zcu.LazySrcLoc.Offset.nodeOffset(0),
32263476 };
32273477}
32283478
3229pub fn srcLoc(ty: Type, zcu: *Zcu) Module.LazySrcLoc {
3479pub fn srcLoc(ty: Type, zcu: *Zcu) Zcu.LazySrcLoc {
32303480 return ty.srcLocOrNull(zcu).?;
32313481}
32323482
......@@ -3234,8 +3484,8 @@ pub fn isGenericPoison(ty: Type) bool {
32343484 return ty.toIntern() == .generic_poison_type;
32353485}
32363486
3237pub fn isTuple(ty: Type, mod: *Module) bool {
3238 const ip = &mod.intern_pool;
3487pub fn isTuple(ty: Type, zcu: *const Zcu) bool {
3488 const ip = &zcu.intern_pool;
32393489 return switch (ip.indexToKey(ty.toIntern())) {
32403490 .struct_type => {
32413491 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3248,16 +3498,16 @@ pub fn isTuple(ty: Type, mod: *Module) bool {
32483498 };
32493499}
32503500
3251pub fn isAnonStruct(ty: Type, mod: *Module) bool {
3501pub fn isAnonStruct(ty: Type, zcu: *const Zcu) bool {
32523502 if (ty.toIntern() == .empty_struct_type) return true;
3253 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3503 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
32543504 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len > 0,
32553505 else => false,
32563506 };
32573507}
32583508
3259pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
3260 const ip = &mod.intern_pool;
3509pub fn isTupleOrAnonStruct(ty: Type, zcu: *const Zcu) bool {
3510 const ip = &zcu.intern_pool;
32613511 return switch (ip.indexToKey(ty.toIntern())) {
32623512 .struct_type => {
32633513 const struct_type = ip.loadStructType(ty.toIntern());
......@@ -3270,15 +3520,15 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
32703520 };
32713521}
32723522
3273pub fn isSimpleTuple(ty: Type, mod: *Module) bool {
3274 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3523pub fn isSimpleTuple(ty: Type, zcu: *const Zcu) bool {
3524 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
32753525 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len == 0,
32763526 else => false,
32773527 };
32783528}
32793529
3280pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool {
3281 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3530pub fn isSimpleTupleOrAnonStruct(ty: Type, zcu: *const Zcu) bool {
3531 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
32823532 .anon_struct_type => true,
32833533 else => false,
32843534 };
......@@ -3286,22 +3536,22 @@ pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool {
32863536
32873537/// Traverses optional child types and error union payloads until the type
32883538/// is not a pointer. For `E!?u32`, returns `u32`; for `*u8`, returns `*u8`.
3289pub fn optEuBaseType(ty: Type, mod: *Module) Type {
3539pub fn optEuBaseType(ty: Type, zcu: *const Zcu) Type {
32903540 var cur = ty;
3291 while (true) switch (cur.zigTypeTag(mod)) {
3292 .Optional => cur = cur.optionalChild(mod),
3293 .ErrorUnion => cur = cur.errorUnionPayload(mod),
3541 while (true) switch (cur.zigTypeTag(zcu)) {
3542 .Optional => cur = cur.optionalChild(zcu),
3543 .ErrorUnion => cur = cur.errorUnionPayload(zcu),
32943544 else => return cur,
32953545 };
32963546}
32973547
32983548pub fn toUnsigned(ty: Type, pt: Zcu.PerThread) !Type {
3299 const mod = pt.zcu;
3300 return switch (ty.zigTypeTag(mod)) {
3301 .Int => pt.intType(.unsigned, ty.intInfo(mod).bits),
3549 const zcu = pt.zcu;
3550 return switch (ty.zigTypeTag(zcu)) {
3551 .Int => pt.intType(.unsigned, ty.intInfo(zcu).bits),
33023552 .Vector => try pt.vectorType(.{
3303 .len = ty.vectorLen(mod),
3304 .child = (try ty.childType(mod).toUnsigned(pt)).toIntern(),
3553 .len = ty.vectorLen(zcu),
3554 .child = (try ty.childType(zcu).toUnsigned(pt)).toIntern(),
33053555 }),
33063556 else => unreachable,
33073557 };
......@@ -3397,16 +3647,16 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
33973647
33983648 const zcu = pt.zcu;
33993649 const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu);
3400 const field_ty = struct_ty.structFieldType(field_idx, zcu);
3650 const field_ty = struct_ty.fieldType(field_idx, zcu);
34013651
34023652 var bit_offset: u16 = 0;
34033653 var running_bits: u16 = 0;
34043654 for (0..struct_ty.structFieldCount(zcu)) |i| {
3405 const f_ty = struct_ty.structFieldType(i, zcu);
3655 const f_ty = struct_ty.fieldType(i, zcu);
34063656 if (i == field_idx) {
34073657 bit_offset = running_bits;
34083658 }
3409 running_bits += @intCast(f_ty.bitSize(pt));
3659 running_bits += @intCast(f_ty.bitSize(zcu));
34103660 }
34113661
34123662 const res_host_size: u16, const res_bit_offset: u16 = if (parent_ptr_info.packed_offset.host_size != 0)
......@@ -3423,9 +3673,9 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
34233673 // targets before adding the necessary complications to this code. This will not
34243674 // cause miscompilations; it only means the field pointer uses bit masking when it
34253675 // 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) {
3676 if (res_bit_offset % 8 == 0 and field_ty.bitSize(zcu) == field_ty.abiSize(zcu) * 8 and zcu.getTarget().cpu.arch.endian() == .little) {
34273677 const byte_offset = res_bit_offset / 8;
3428 const new_align = Alignment.fromLog2Units(@ctz(byte_offset | parent_ptr_ty.ptrAlignment(pt).toByteUnits().?));
3678 const new_align = Alignment.fromLog2Units(@ctz(byte_offset | parent_ptr_ty.ptrAlignment(zcu).toByteUnits().?));
34293679 return .{ .byte_ptr = .{
34303680 .offset = byte_offset,
34313681 .alignment = new_align,
......@@ -3661,11 +3911,12 @@ fn resolveStructInner(
36613911 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);
36623912 defer comptime_err_ret_trace.deinit();
36633913
3914 const zir = zcu.namespacePtr(struct_obj.namespace.unwrap().?).fileScope(zcu).zir;
36643915 var sema: Sema = .{
36653916 .pt = pt,
36663917 .gpa = gpa,
36673918 .arena = analysis_arena.allocator(),
3668 .code = undefined, // This ZIR will not be used.
3919 .code = zir,
36693920 .owner = owner,
36703921 .func_index = .none,
36713922 .func_is_naked = false,
......@@ -3676,7 +3927,7 @@ fn resolveStructInner(
36763927 defer sema.deinit();
36773928
36783929 (switch (resolution) {
3679 .fields => sema.resolveTypeFieldsStruct(ty.toIntern(), struct_obj),
3930 .fields => sema.resolveStructFieldTypes(ty.toIntern(), struct_obj),
36803931 .inits => sema.resolveStructFieldInits(ty),
36813932 .alignment => sema.resolveStructAlignment(ty.toIntern(), struct_obj),
36823933 .layout => sema.resolveStructLayout(ty),
......@@ -3714,11 +3965,12 @@ fn resolveUnionInner(
37143965 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);
37153966 defer comptime_err_ret_trace.deinit();
37163967
3968 const zir = zcu.namespacePtr(union_obj.namespace).fileScope(zcu).zir;
37173969 var sema: Sema = .{
37183970 .pt = pt,
37193971 .gpa = gpa,
37203972 .arena = analysis_arena.allocator(),
3721 .code = undefined, // This ZIR will not be used.
3973 .code = zir,
37223974 .owner = owner,
37233975 .func_index = .none,
37243976 .func_is_naked = false,
......@@ -3729,7 +3981,7 @@ fn resolveUnionInner(
37293981 defer sema.deinit();
37303982
37313983 (switch (resolution) {
3732 .fields => sema.resolveTypeFieldsUnion(ty, union_obj),
3984 .fields => sema.resolveUnionFieldTypes(ty, union_obj),
37333985 .alignment => sema.resolveUnionAlignment(ty, union_obj),
37343986 .layout => sema.resolveUnionLayout(ty),
37353987 .full => sema.resolveUnionFully(ty),
......@@ -3744,6 +3996,65 @@ fn resolveUnionInner(
37443996 };
37453997}
37463998
3999pub fn getUnionLayout(loaded_union: InternPool.LoadedUnionType, zcu: *Zcu) Zcu.UnionLayout {
4000 const ip = &zcu.intern_pool;
4001 assert(loaded_union.haveLayout(ip));
4002 var most_aligned_field: u32 = undefined;
4003 var most_aligned_field_size: u64 = undefined;
4004 var biggest_field: u32 = undefined;
4005 var payload_size: u64 = 0;
4006 var payload_align: InternPool.Alignment = .@"1";
4007 for (loaded_union.field_types.get(ip), 0..) |field_ty, field_index| {
4008 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
4009
4010 const explicit_align = loaded_union.fieldAlign(ip, field_index);
4011 const field_align = if (explicit_align != .none)
4012 explicit_align
4013 else
4014 Type.fromInterned(field_ty).abiAlignment(zcu);
4015 const field_size = Type.fromInterned(field_ty).abiSize(zcu);
4016 if (field_size > payload_size) {
4017 payload_size = field_size;
4018 biggest_field = @intCast(field_index);
4019 }
4020 if (field_align.compare(.gte, payload_align)) {
4021 payload_align = field_align;
4022 most_aligned_field = @intCast(field_index);
4023 most_aligned_field_size = field_size;
4024 }
4025 }
4026 const have_tag = loaded_union.flagsUnordered(ip).runtime_tag.hasTag();
4027 if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(zcu)) {
4028 return .{
4029 .abi_size = payload_align.forward(payload_size),
4030 .abi_align = payload_align,
4031 .most_aligned_field = most_aligned_field,
4032 .most_aligned_field_size = most_aligned_field_size,
4033 .biggest_field = biggest_field,
4034 .payload_size = payload_size,
4035 .payload_align = payload_align,
4036 .tag_align = .none,
4037 .tag_size = 0,
4038 .padding = 0,
4039 };
4040 }
4041
4042 const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(zcu);
4043 const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(zcu).max(.@"1");
4044 return .{
4045 .abi_size = loaded_union.sizeUnordered(ip),
4046 .abi_align = tag_align.max(payload_align),
4047 .most_aligned_field = most_aligned_field,
4048 .most_aligned_field_size = most_aligned_field_size,
4049 .biggest_field = biggest_field,
4050 .payload_size = payload_size,
4051 .payload_align = payload_align,
4052 .tag_align = tag_align,
4053 .tag_size = tag_size,
4054 .padding = loaded_union.paddingUnordered(ip),
4055 };
4056}
4057
37474058/// Returns the type of a pointer to an element.
37484059/// Asserts that the type is a pointer, and that the element type is indexable.
37494060/// If the element index is comptime-known, it must be passed in `offset`.
......@@ -3768,14 +4079,14 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {
37684079 alignment: Alignment = .none,
37694080 vector_index: VI = .none,
37704081 } = if (parent_ty.isVector(zcu) and ptr_info.flags.size == .One) blk: {
3771 const elem_bits = elem_ty.bitSize(pt);
4082 const elem_bits = elem_ty.bitSize(zcu);
37724083 if (elem_bits == 0) break :blk .{};
37734084 const is_packed = elem_bits < 8 or !std.math.isPowerOfTwo(elem_bits);
37744085 if (!is_packed) break :blk .{};
37754086
37764087 break :blk .{
37774088 .host_size = @intCast(parent_ty.arrayLen(zcu)),
3778 .alignment = parent_ty.abiAlignment(pt),
4089 .alignment = parent_ty.abiAlignment(zcu),
37794090 .vector_index = if (offset) |some| @enumFromInt(some) else .runtime,
37804091 };
37814092 } else .{};
......@@ -3789,7 +4100,7 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {
37894100 }
37904101 // If the addend is not a comptime-known value we can still count on
37914102 // it being a multiple of the type size.
3792 const elem_size = (try elem_ty.abiSizeAdvanced(pt, .sema)).scalar;
4103 const elem_size = (try elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar;
37934104 const addend = if (offset) |off| elem_size * off else elem_size;
37944105
37954106 // The resulting pointer is aligned to the lcd between the offset (an
src/Value.zig+767-699
......@@ -7,8 +7,6 @@ const BigIntMutable = std.math.big.int.Mutable;
77const Target = std.Target;
88const Allocator = std.mem.Allocator;
99const Zcu = @import("Zcu.zig");
10/// Deprecated.
11const Module = Zcu;
1210const Sema = @import("Sema.zig");
1311const InternPool = @import("InternPool.zig");
1412const print_value = @import("print_value.zig");
......@@ -65,19 +63,19 @@ pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_
6563/// Converts `val` to a null-terminated string stored in the InternPool.
6664/// Asserts `val` is an array of `u8`
6765pub 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),
66 const zcu = pt.zcu;
67 assert(ty.zigTypeTag(zcu) == .Array);
68 assert(ty.childType(zcu).toIntern() == .u8_type);
69 const ip = &zcu.intern_pool;
70 switch (zcu.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {
71 .bytes => |bytes| return bytes.toNullTerminatedString(ty.arrayLen(zcu), ip),
72 .elems => return arrayToIpString(val, ty.arrayLen(zcu), pt),
7573 .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);
74 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(zcu));
75 const len: u32 = @intCast(ty.arrayLen(zcu));
76 const strings = ip.getLocal(pt.tid).getMutableStrings(zcu.gpa);
7977 try strings.appendNTimes(.{byte}, len);
80 return ip.getOrPutTrailingString(mod.gpa, pt.tid, len, .no_embedded_nulls);
78 return ip.getOrPutTrailingString(zcu.gpa, pt.tid, len, .no_embedded_nulls);
8179 },
8280 }
8381}
......@@ -85,17 +83,17 @@ pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTermi
8583/// Asserts that the value is representable as an array of bytes.
8684/// Copies the value into a freshly allocated slice of memory, which is owned by the caller.
8785pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) ![]u8 {
88 const mod = pt.zcu;
89 const ip = &mod.intern_pool;
86 const zcu = pt.zcu;
87 const ip = &zcu.intern_pool;
9088 return switch (ip.indexToKey(val.toIntern())) {
9189 .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),
90 .slice => |slice| try arrayToAllocatedBytes(val, Value.fromInterned(slice.len).toUnsignedInt(zcu), allocator, pt),
9391 .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),
92 .bytes => |bytes| try allocator.dupe(u8, bytes.toSlice(ty.arrayLenIncludingSentinel(zcu), ip)),
93 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(zcu), allocator, pt),
9694 .repeated_elem => |elem| {
97 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt));
98 const result = try allocator.alloc(u8, @intCast(ty.arrayLen(mod)));
95 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(zcu));
96 const result = try allocator.alloc(u8, @intCast(ty.arrayLen(zcu)));
9997 @memset(result, byte);
10098 return result;
10199 },
......@@ -108,15 +106,15 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, pt: Zcu.Per
108106 const result = try allocator.alloc(u8, @intCast(len));
109107 for (result, 0..) |*elem, i| {
110108 const elem_val = try val.elemValue(pt, i);
111 elem.* = @intCast(elem_val.toUnsignedInt(pt));
109 elem.* = @intCast(elem_val.toUnsignedInt(pt.zcu));
112110 }
113111 return result;
114112}
115113
116114fn 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;
115 const zcu = pt.zcu;
116 const gpa = zcu.gpa;
117 const ip = &zcu.intern_pool;
120118 const len: u32 = @intCast(len_u64);
121119 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);
122120 try strings.ensureUnusedCapacity(len);
......@@ -126,7 +124,7 @@ fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.Null
126124 const prev_len = strings.mutate.len;
127125 const elem_val = try val.elemValue(pt, i);
128126 assert(strings.mutate.len == prev_len);
129 const byte: u8 = @intCast(elem_val.toUnsignedInt(pt));
127 const byte: u8 = @intCast(elem_val.toUnsignedInt(zcu));
130128 strings.appendAssumeCapacity(.{byte});
131129 }
132130 return ip.getOrPutTrailingString(gpa, pt.tid, len, .no_embedded_nulls);
......@@ -178,56 +176,61 @@ pub fn intFromEnum(val: Value, ty: Type, pt: Zcu.PerThread) Allocator.Error!Valu
178176pub const ResolveStrat = Type.ResolveStrat;
179177
180178/// 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;
179pub fn toBigInt(val: Value, space: *BigIntSpace, zcu: *Zcu) BigIntConst {
180 return val.toBigIntAdvanced(space, .normal, zcu, {}) catch unreachable;
181}
182
183pub fn toBigIntSema(val: Value, space: *BigIntSpace, pt: Zcu.PerThread) !BigIntConst {
184 return try val.toBigIntAdvanced(space, .sema, pt.zcu, pt.tid);
183185}
184186
185187/// Asserts the value is an integer.
186188pub fn toBigIntAdvanced(
187189 val: Value,
188190 space: *BigIntSpace,
189 pt: Zcu.PerThread,
190191 comptime strat: ResolveStrat,
191) Module.CompileError!BigIntConst {
192 zcu: *Zcu,
193 tid: strat.Tid(),
194) Zcu.CompileError!BigIntConst {
192195 return switch (val.toIntern()) {
193196 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
194197 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
195198 .null_value => BigIntMutable.init(&space.limbs, 0).toConst(),
196 else => switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
199 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
197200 .int => |int| switch (int.storage) {
198201 .u64, .i64, .big_int => int.storage.toBigInt(space),
199202 .lazy_align, .lazy_size => |ty| {
200 if (strat == .sema) try Type.fromInterned(ty).resolveLayout(pt);
203 if (strat == .sema) try Type.fromInterned(ty).resolveLayout(strat.pt(zcu, tid));
201204 const x = switch (int.storage) {
202205 else => unreachable,
203 .lazy_align => Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0,
204 .lazy_size => Type.fromInterned(ty).abiSize(pt),
206 .lazy_align => Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0,
207 .lazy_size => Type.fromInterned(ty).abiSize(zcu),
205208 };
206209 return BigIntMutable.init(&space.limbs, x).toConst();
207210 },
208211 },
209 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).toBigIntAdvanced(space, pt, strat),
212 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).toBigIntAdvanced(space, strat, zcu, tid),
210213 .opt, .ptr => BigIntMutable.init(
211214 &space.limbs,
212 (try val.getUnsignedIntAdvanced(pt, strat)).?,
215 (try val.getUnsignedIntInner(strat, zcu, tid)).?,
213216 ).toConst(),
214217 else => unreachable,
215218 },
216219 };
217220}
218221
219pub fn isFuncBody(val: Value, mod: *Module) bool {
220 return mod.intern_pool.isFuncBody(val.toIntern());
222pub fn isFuncBody(val: Value, zcu: *Zcu) bool {
223 return zcu.intern_pool.isFuncBody(val.toIntern());
221224}
222225
223pub fn getFunction(val: Value, mod: *Module) ?InternPool.Key.Func {
224 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
226pub fn getFunction(val: Value, zcu: *Zcu) ?InternPool.Key.Func {
227 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
225228 .func => |x| x,
226229 else => null,
227230 };
228231}
229232
230pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {
233pub fn getVariable(val: Value, mod: *Zcu) ?InternPool.Key.Variable {
231234 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
232235 .variable => |variable| variable,
233236 else => null,
......@@ -236,68 +239,79 @@ pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {
236239
237240/// If the value fits in a u64, return it, otherwise null.
238241/// Asserts not undefined.
239pub fn getUnsignedInt(val: Value, pt: Zcu.PerThread) ?u64 {
240 return getUnsignedIntAdvanced(val, pt, .normal) catch unreachable;
242pub fn getUnsignedInt(val: Value, zcu: *Zcu) ?u64 {
243 return getUnsignedIntInner(val, .normal, zcu, {}) catch unreachable;
244}
245
246/// Asserts the value is an integer and it fits in a u64
247pub fn toUnsignedInt(val: Value, zcu: *Zcu) u64 {
248 return getUnsignedInt(val, zcu).?;
249}
250
251pub fn getUnsignedIntSema(val: Value, pt: Zcu.PerThread) !?u64 {
252 return try val.getUnsignedIntInner(.sema, pt.zcu, pt.tid);
241253}
242254
243255/// If the value fits in a u64, return it, otherwise null.
244256/// Asserts not undefined.
245pub fn getUnsignedIntAdvanced(val: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !?u64 {
246 const mod = pt.zcu;
257pub fn getUnsignedIntInner(
258 val: Value,
259 comptime strat: ResolveStrat,
260 zcu: *Zcu,
261 tid: strat.Tid(),
262) !?u64 {
247263 return switch (val.toIntern()) {
248264 .undef => unreachable,
249265 .bool_false => 0,
250266 .bool_true => 1,
251 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
267 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
252268 .undef => unreachable,
253269 .int => |int| switch (int.storage) {
254270 .big_int => |big_int| big_int.to(u64) catch null,
255271 .u64 => |x| x,
256272 .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,
273 .lazy_align => |ty| (try Type.fromInterned(ty).abiAlignmentInner(strat.toLazy(), zcu, tid)).scalar.toByteUnits() orelse 0,
274 .lazy_size => |ty| (try Type.fromInterned(ty).abiSizeInner(strat.toLazy(), zcu, tid)).scalar,
259275 },
260276 .ptr => |ptr| switch (ptr.base_addr) {
261277 .int => ptr.byte_offset,
262278 .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;
279 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntInner(strat, zcu, tid)) orelse return null;
280 const struct_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu);
281 if (strat == .sema) {
282 const pt = strat.pt(zcu, tid);
283 try struct_ty.resolveLayout(pt);
284 }
285 return base_addr + struct_ty.structFieldOffset(@intCast(field.index), zcu) + ptr.byte_offset;
267286 },
268287 else => null,
269288 },
270289 .opt => |opt| switch (opt.val) {
271290 .none => 0,
272 else => |payload| Value.fromInterned(payload).getUnsignedIntAdvanced(pt, strat),
291 else => |payload| Value.fromInterned(payload).getUnsignedIntInner(strat, zcu, tid),
273292 },
274293 else => null,
275294 },
276295 };
277296}
278297
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
284298/// Asserts the value is an integer and it fits in a u64
285299pub fn toUnsignedIntSema(val: Value, pt: Zcu.PerThread) !u64 {
286 return (try getUnsignedIntAdvanced(val, pt, .sema)).?;
300 return (try getUnsignedIntInner(val, .sema, pt.zcu, pt.tid)).?;
287301}
288302
289303/// Asserts the value is an integer and it fits in a i64
290pub fn toSignedInt(val: Value, pt: Zcu.PerThread) i64 {
304pub fn toSignedInt(val: Value, zcu: *Zcu) i64 {
291305 return switch (val.toIntern()) {
292306 .bool_false => 0,
293307 .bool_true => 1,
294 else => switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
308 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
295309 .int => |int| switch (int.storage) {
296310 .big_int => |big_int| big_int.to(i64) catch unreachable,
297311 .i64 => |x| x,
298312 .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)),
313 .lazy_align => |ty| @intCast(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0),
314 .lazy_size => |ty| @intCast(Type.fromInterned(ty).abiSize(zcu)),
301315 },
302316 else => unreachable,
303317 },
......@@ -326,41 +340,41 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
326340 Unimplemented,
327341 OutOfMemory,
328342}!void {
329 const mod = pt.zcu;
330 const target = mod.getTarget();
343 const zcu = pt.zcu;
344 const target = zcu.getTarget();
331345 const endian = target.cpu.arch.endian();
332 if (val.isUndef(mod)) {
333 const size: usize = @intCast(ty.abiSize(pt));
346 if (val.isUndef(zcu)) {
347 const size: usize = @intCast(ty.abiSize(zcu));
334348 @memset(buffer[0..size], 0xaa);
335349 return;
336350 }
337 const ip = &mod.intern_pool;
338 switch (ty.zigTypeTag(mod)) {
351 const ip = &zcu.intern_pool;
352 switch (ty.zigTypeTag(zcu)) {
339353 .Void => {},
340354 .Bool => {
341355 buffer[0] = @intFromBool(val.toBool());
342356 },
343357 .Int, .Enum => {
344 const int_info = ty.intInfo(mod);
358 const int_info = ty.intInfo(zcu);
345359 const bits = int_info.bits;
346360 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
347361
348362 var bigint_buffer: BigIntSpace = undefined;
349 const bigint = val.toBigInt(&bigint_buffer, pt);
363 const bigint = val.toBigInt(&bigint_buffer, zcu);
350364 bigint.writeTwosComplement(buffer[0..byte_count], endian);
351365 },
352366 .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),
367 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(val.toFloat(f16, zcu)), endian),
368 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(val.toFloat(f32, zcu)), endian),
369 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(val.toFloat(f64, zcu)), endian),
370 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(val.toFloat(f80, zcu)), endian),
371 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(val.toFloat(f128, zcu)), endian),
358372 else => unreachable,
359373 },
360374 .Array => {
361 const len = ty.arrayLen(mod);
362 const elem_ty = ty.childType(mod);
363 const elem_size: usize = @intCast(elem_ty.abiSize(pt));
375 const len = ty.arrayLen(zcu);
376 const elem_ty = ty.childType(zcu);
377 const elem_size: usize = @intCast(elem_ty.abiSize(zcu));
364378 var elem_i: usize = 0;
365379 var buf_off: usize = 0;
366380 while (elem_i < len) : (elem_i += 1) {
......@@ -372,15 +386,15 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
372386 .Vector => {
373387 // We use byte_count instead of abi_size here, so that any padding bytes
374388 // follow the data bytes, on both big- and little-endian systems.
375 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
389 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
376390 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
377391 },
378392 .Struct => {
379 const struct_type = mod.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;
393 const struct_type = zcu.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;
380394 switch (struct_type.layout) {
381395 .auto => return error.IllDefinedMemoryLayout,
382396 .@"extern" => for (0..struct_type.field_types.len) |field_index| {
383 const off: usize = @intCast(ty.structFieldOffset(field_index, pt));
397 const off: usize = @intCast(ty.structFieldOffset(field_index, zcu));
384398 const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
385399 .bytes => |bytes| {
386400 buffer[off] = bytes.at(field_index, ip);
......@@ -393,13 +407,13 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
393407 try writeToMemory(field_val, field_ty, pt, buffer[off..]);
394408 },
395409 .@"packed" => {
396 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
410 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
397411 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
398412 },
399413 }
400414 },
401415 .ErrorSet => {
402 const bits = mod.errorSetBits();
416 const bits = zcu.errorSetBits();
403417 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
404418
405419 const name = switch (ip.indexToKey(val.toIntern())) {
......@@ -414,37 +428,37 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
414428 ).toConst();
415429 bigint.writeTwosComplement(buffer[0..byte_count], endian);
416430 },
417 .Union => switch (ty.containerLayout(mod)) {
431 .Union => switch (ty.containerLayout(zcu)) {
418432 .auto => return error.IllDefinedMemoryLayout, // Sema is supposed to have emitted a compile error already
419433 .@"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).?;
434 if (val.unionTag(zcu)) |union_tag| {
435 const union_obj = zcu.typeToUnion(ty).?;
436 const field_index = zcu.unionTagFieldIndex(union_obj, union_tag).?;
423437 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
424438 const field_val = try val.fieldValue(pt, field_index);
425 const byte_count: usize = @intCast(field_type.abiSize(pt));
439 const byte_count: usize = @intCast(field_type.abiSize(zcu));
426440 return writeToMemory(field_val, field_type, pt, buffer[0..byte_count]);
427441 } else {
428442 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]);
443 const byte_count: usize = @intCast(backing_ty.abiSize(zcu));
444 return writeToMemory(val.unionValue(zcu), backing_ty, pt, buffer[0..byte_count]);
431445 }
432446 },
433447 .@"packed" => {
434448 const backing_ty = try ty.unionBackingType(pt);
435 const byte_count: usize = @intCast(backing_ty.abiSize(pt));
449 const byte_count: usize = @intCast(backing_ty.abiSize(zcu));
436450 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
437451 },
438452 },
439453 .Pointer => {
440 if (ty.isSlice(mod)) return error.IllDefinedMemoryLayout;
441 if (!val.ptrHasIntAddr(mod)) return error.ReinterpretDeclRef;
454 if (ty.isSlice(zcu)) return error.IllDefinedMemoryLayout;
455 if (!val.ptrHasIntAddr(zcu)) return error.ReinterpretDeclRef;
442456 return val.writeToMemory(Type.usize, pt, buffer);
443457 },
444458 .Optional => {
445 if (!ty.isPtrLikeOptional(mod)) return error.IllDefinedMemoryLayout;
446 const child = ty.optionalChild(mod);
447 const opt_val = val.optionalValue(mod);
459 if (!ty.isPtrLikeOptional(zcu)) return error.IllDefinedMemoryLayout;
460 const child = ty.optionalChild(zcu);
461 const opt_val = val.optionalValue(zcu);
448462 if (opt_val) |some| {
449463 return some.writeToMemory(child, pt, buffer);
450464 } else {
......@@ -466,18 +480,18 @@ pub fn writeToPackedMemory(
466480 buffer: []u8,
467481 bit_offset: usize,
468482) error{ ReinterpretDeclRef, OutOfMemory }!void {
469 const mod = pt.zcu;
470 const ip = &mod.intern_pool;
471 const target = mod.getTarget();
483 const zcu = pt.zcu;
484 const ip = &zcu.intern_pool;
485 const target = zcu.getTarget();
472486 const endian = target.cpu.arch.endian();
473 if (val.isUndef(mod)) {
474 const bit_size: usize = @intCast(ty.bitSize(pt));
487 if (val.isUndef(zcu)) {
488 const bit_size: usize = @intCast(ty.bitSize(zcu));
475489 if (bit_size != 0) {
476490 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);
477491 }
478492 return;
479493 }
480 switch (ty.zigTypeTag(mod)) {
494 switch (ty.zigTypeTag(zcu)) {
481495 .Void => {},
482496 .Bool => {
483497 const byte_index = switch (endian) {
......@@ -492,34 +506,34 @@ pub fn writeToPackedMemory(
492506 },
493507 .Int, .Enum => {
494508 if (buffer.len == 0) return;
495 const bits = ty.intInfo(mod).bits;
509 const bits = ty.intInfo(zcu).bits;
496510 if (bits == 0) return;
497511
498512 switch (ip.indexToKey((try val.intFromEnum(ty, pt)).toIntern()).int.storage) {
499513 inline .u64, .i64 => |int| std.mem.writeVarPackedInt(buffer, bit_offset, bits, int, endian),
500514 .big_int => |bigint| bigint.writePackedTwosComplement(buffer, bit_offset, bits, endian),
501515 .lazy_align => |lazy_align| {
502 const num = Type.fromInterned(lazy_align).abiAlignment(pt).toByteUnits() orelse 0;
516 const num = Type.fromInterned(lazy_align).abiAlignment(zcu).toByteUnits() orelse 0;
503517 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
504518 },
505519 .lazy_size => |lazy_size| {
506 const num = Type.fromInterned(lazy_size).abiSize(pt);
520 const num = Type.fromInterned(lazy_size).abiSize(zcu);
507521 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
508522 },
509523 }
510524 },
511525 .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),
526 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(val.toFloat(f16, zcu)), endian),
527 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(val.toFloat(f32, zcu)), endian),
528 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(val.toFloat(f64, zcu)), endian),
529 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(val.toFloat(f80, zcu)), endian),
530 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(val.toFloat(f128, zcu)), endian),
517531 else => unreachable,
518532 },
519533 .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));
534 const elem_ty = ty.childType(zcu);
535 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(zcu));
536 const len: usize = @intCast(ty.arrayLen(zcu));
523537
524538 var bits: u16 = 0;
525539 var elem_i: usize = 0;
......@@ -544,37 +558,37 @@ pub fn writeToPackedMemory(
544558 .repeated_elem => |elem| elem,
545559 });
546560 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
547 const field_bits: u16 = @intCast(field_ty.bitSize(pt));
561 const field_bits: u16 = @intCast(field_ty.bitSize(zcu));
548562 try field_val.writeToPackedMemory(field_ty, pt, buffer, bit_offset + bits);
549563 bits += field_bits;
550564 }
551565 },
552566 .Union => {
553 const union_obj = mod.typeToUnion(ty).?;
567 const union_obj = zcu.typeToUnion(ty).?;
554568 switch (union_obj.flagsUnordered(ip).layout) {
555569 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory
556570 .@"packed" => {
557 if (val.unionTag(mod)) |union_tag| {
558 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;
571 if (val.unionTag(zcu)) |union_tag| {
572 const field_index = zcu.unionTagFieldIndex(union_obj, union_tag).?;
559573 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
560574 const field_val = try val.fieldValue(pt, field_index);
561575 return field_val.writeToPackedMemory(field_type, pt, buffer, bit_offset);
562576 } else {
563577 const backing_ty = try ty.unionBackingType(pt);
564 return val.unionValue(mod).writeToPackedMemory(backing_ty, pt, buffer, bit_offset);
578 return val.unionValue(zcu).writeToPackedMemory(backing_ty, pt, buffer, bit_offset);
565579 }
566580 },
567581 }
568582 },
569583 .Pointer => {
570 assert(!ty.isSlice(mod)); // No well defined layout.
571 if (!val.ptrHasIntAddr(mod)) return error.ReinterpretDeclRef;
584 assert(!ty.isSlice(zcu)); // No well defined layout.
585 if (!val.ptrHasIntAddr(zcu)) return error.ReinterpretDeclRef;
572586 return val.writeToPackedMemory(Type.usize, pt, buffer, bit_offset);
573587 },
574588 .Optional => {
575 assert(ty.isPtrLikeOptional(mod));
576 const child = ty.optionalChild(mod);
577 const opt_val = val.optionalValue(mod);
589 assert(ty.isPtrLikeOptional(zcu));
590 const child = ty.optionalChild(zcu);
591 const opt_val = val.optionalValue(zcu);
578592 if (opt_val) |some| {
579593 return some.writeToPackedMemory(child, pt, buffer, bit_offset);
580594 } else {
......@@ -599,11 +613,11 @@ pub fn readFromMemory(
599613 Unimplemented,
600614 OutOfMemory,
601615}!Value {
602 const mod = pt.zcu;
603 const ip = &mod.intern_pool;
604 const target = mod.getTarget();
616 const zcu = pt.zcu;
617 const ip = &zcu.intern_pool;
618 const target = zcu.getTarget();
605619 const endian = target.cpu.arch.endian();
606 switch (ty.zigTypeTag(mod)) {
620 switch (ty.zigTypeTag(zcu)) {
607621 .Void => return Value.void,
608622 .Bool => {
609623 if (buffer[0] == 0) {
......@@ -615,24 +629,24 @@ pub fn readFromMemory(
615629 .Int, .Enum => |ty_tag| {
616630 const int_ty = switch (ty_tag) {
617631 .Int => ty,
618 .Enum => ty.intTagType(mod),
632 .Enum => ty.intTagType(zcu),
619633 else => unreachable,
620634 };
621 const int_info = int_ty.intInfo(mod);
635 const int_info = int_ty.intInfo(zcu);
622636 const bits = int_info.bits;
623637 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);
638 if (bits == 0 or buffer.len == 0) return zcu.getCoerced(try zcu.intValue(int_ty, 0), ty);
625639
626640 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64
627641 .signed => {
628642 const val = std.mem.readVarInt(i64, buffer[0..byte_count], endian);
629643 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
630 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
644 return zcu.getCoerced(try zcu.intValue(int_ty, result), ty);
631645 },
632646 .unsigned => {
633647 const val = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
634648 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
635 return mod.getCoerced(try mod.intValue(int_ty, result), ty);
649 return zcu.getCoerced(try zcu.intValue(int_ty, result), ty);
636650 },
637651 } else { // Slow path, we have to construct a big-int
638652 const Limb = std.math.big.Limb;
......@@ -641,7 +655,7 @@ pub fn readFromMemory(
641655
642656 var bigint = BigIntMutable.init(limbs_buffer, 0);
643657 bigint.readTwosComplement(buffer[0..byte_count], bits, endian, int_info.signedness);
644 return mod.getCoerced(try mod.intValue_big(int_ty, bigint.toConst()), ty);
658 return zcu.getCoerced(try zcu.intValue_big(int_ty, bigint.toConst()), ty);
645659 }
646660 },
647661 .Float => return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -656,12 +670,12 @@ pub fn readFromMemory(
656670 },
657671 } })),
658672 .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)));
673 const elem_ty = ty.childType(zcu);
674 const elem_size = elem_ty.abiSize(zcu);
675 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(zcu)));
662676 var offset: usize = 0;
663677 for (elems) |*elem| {
664 elem.* = (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).toIntern();
678 elem.* = (try readFromMemory(elem_ty, zcu, buffer[offset..], arena)).toIntern();
665679 offset += @intCast(elem_size);
666680 }
667681 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
......@@ -672,11 +686,11 @@ pub fn readFromMemory(
672686 .Vector => {
673687 // We use byte_count instead of abi_size here, so that any padding bytes
674688 // 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);
689 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
690 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
677691 },
678692 .Struct => {
679 const struct_type = mod.typeToStruct(ty).?;
693 const struct_type = zcu.typeToStruct(ty).?;
680694 switch (struct_type.layout) {
681695 .auto => unreachable, // Sema is supposed to have emitted a compile error already
682696 .@"extern" => {
......@@ -684,9 +698,9 @@ pub fn readFromMemory(
684698 const field_vals = try arena.alloc(InternPool.Index, field_types.len);
685699 for (field_vals, 0..) |*field_val, i| {
686700 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();
701 const off: usize = @intCast(ty.structFieldOffset(i, zcu));
702 const sz: usize = @intCast(field_ty.abiSize(zcu));
703 field_val.* = (try readFromMemory(field_ty, zcu, buffer[off..(off + sz)], arena)).toIntern();
690704 }
691705 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
692706 .ty = ty.toIntern(),
......@@ -694,29 +708,29 @@ pub fn readFromMemory(
694708 } }));
695709 },
696710 .@"packed" => {
697 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
698 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
711 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
712 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
699713 },
700714 }
701715 },
702716 .ErrorSet => {
703 const bits = mod.errorSetBits();
717 const bits = zcu.errorSetBits();
704718 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
705719 const int = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
706720 const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
707 const name = mod.global_error_set.keys()[@intCast(index)];
721 const name = zcu.global_error_set.keys()[@intCast(index)];
708722
709723 return Value.fromInterned(try pt.intern(.{ .err = .{
710724 .ty = ty.toIntern(),
711725 .name = name,
712726 } }));
713727 },
714 .Union => switch (ty.containerLayout(mod)) {
728 .Union => switch (ty.containerLayout(zcu)) {
715729 .auto => return error.IllDefinedMemoryLayout,
716730 .@"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();
731 const union_size = ty.abiSize(zcu);
732 const array_ty = try zcu.arrayType(.{ .len = union_size, .child = .u8_type });
733 const val = (try readFromMemory(array_ty, zcu, buffer, arena)).toIntern();
720734 return Value.fromInterned(try pt.intern(.{ .un = .{
721735 .ty = ty.toIntern(),
722736 .tag = .none,
......@@ -724,23 +738,23 @@ pub fn readFromMemory(
724738 } }));
725739 },
726740 .@"packed" => {
727 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;
728 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);
741 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
742 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
729743 },
730744 },
731745 .Pointer => {
732 assert(!ty.isSlice(mod)); // No well defined layout.
733 const int_val = try readFromMemory(Type.usize, mod, buffer, arena);
746 assert(!ty.isSlice(zcu)); // No well defined layout.
747 const int_val = try readFromMemory(Type.usize, zcu, buffer, arena);
734748 return Value.fromInterned(try pt.intern(.{ .ptr = .{
735749 .ty = ty.toIntern(),
736750 .base_addr = .int,
737 .byte_offset = int_val.toUnsignedInt(pt),
751 .byte_offset = int_val.toUnsignedInt(zcu),
738752 } }));
739753 },
740754 .Optional => {
741 assert(ty.isPtrLikeOptional(mod));
742 const child_ty = ty.optionalChild(mod);
743 const child_val = try readFromMemory(child_ty, mod, buffer, arena);
755 assert(ty.isPtrLikeOptional(zcu));
756 const child_ty = ty.optionalChild(zcu);
757 const child_val = try readFromMemory(child_ty, zcu, buffer, arena);
744758 return Value.fromInterned(try pt.intern(.{ .opt = .{
745759 .ty = ty.toIntern(),
746760 .val = switch (child_val.orderAgainstZero(pt)) {
......@@ -768,11 +782,11 @@ pub fn readFromPackedMemory(
768782 IllDefinedMemoryLayout,
769783 OutOfMemory,
770784}!Value {
771 const mod = pt.zcu;
772 const ip = &mod.intern_pool;
773 const target = mod.getTarget();
785 const zcu = pt.zcu;
786 const ip = &zcu.intern_pool;
787 const target = zcu.getTarget();
774788 const endian = target.cpu.arch.endian();
775 switch (ty.zigTypeTag(mod)) {
789 switch (ty.zigTypeTag(zcu)) {
776790 .Void => return Value.void,
777791 .Bool => {
778792 const byte = switch (endian) {
......@@ -787,7 +801,7 @@ pub fn readFromPackedMemory(
787801 },
788802 .Int => {
789803 if (buffer.len == 0) return pt.intValue(ty, 0);
790 const int_info = ty.intInfo(mod);
804 const int_info = ty.intInfo(zcu);
791805 const bits = int_info.bits;
792806 if (bits == 0) return pt.intValue(ty, 0);
793807
......@@ -800,7 +814,7 @@ pub fn readFromPackedMemory(
800814 };
801815
802816 // Slow path, we have to construct a big-int
803 const abi_size: usize = @intCast(ty.abiSize(pt));
817 const abi_size: usize = @intCast(ty.abiSize(zcu));
804818 const Limb = std.math.big.Limb;
805819 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
806820 const limbs_buffer = try arena.alloc(Limb, limb_count);
......@@ -810,7 +824,7 @@ pub fn readFromPackedMemory(
810824 return pt.intValue_big(ty, bigint.toConst());
811825 },
812826 .Enum => {
813 const int_ty = ty.intTagType(mod);
827 const int_ty = ty.intTagType(zcu);
814828 const int_val = try Value.readFromPackedMemory(int_ty, pt, buffer, bit_offset, arena);
815829 return pt.getCoerced(int_val, ty);
816830 },
......@@ -826,11 +840,11 @@ pub fn readFromPackedMemory(
826840 },
827841 } })),
828842 .Vector => {
829 const elem_ty = ty.childType(mod);
830 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod)));
843 const elem_ty = ty.childType(zcu);
844 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(zcu)));
831845
832846 var bits: u16 = 0;
833 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(pt));
847 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(zcu));
834848 for (elems, 0..) |_, i| {
835849 // On big-endian systems, LLVM reverses the element order of vectors by default
836850 const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i;
......@@ -845,12 +859,12 @@ pub fn readFromPackedMemory(
845859 .Struct => {
846860 // Sema is supposed to have emitted a compile error already for Auto layout structs,
847861 // and Extern is handled by non-packed readFromMemory.
848 const struct_type = mod.typeToPackedStruct(ty).?;
862 const struct_type = zcu.typeToPackedStruct(ty).?;
849863 var bits: u16 = 0;
850864 const field_vals = try arena.alloc(InternPool.Index, struct_type.field_types.len);
851865 for (field_vals, 0..) |*field_val, i| {
852866 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
853 const field_bits: u16 = @intCast(field_ty.bitSize(pt));
867 const field_bits: u16 = @intCast(field_ty.bitSize(zcu));
854868 field_val.* = (try readFromPackedMemory(field_ty, pt, buffer, bit_offset + bits, arena)).toIntern();
855869 bits += field_bits;
856870 }
......@@ -859,7 +873,7 @@ pub fn readFromPackedMemory(
859873 .storage = .{ .elems = field_vals },
860874 } }));
861875 },
862 .Union => switch (ty.containerLayout(mod)) {
876 .Union => switch (ty.containerLayout(zcu)) {
863877 .auto, .@"extern" => unreachable, // Handled by non-packed readFromMemory
864878 .@"packed" => {
865879 const backing_ty = try ty.unionBackingType(pt);
......@@ -872,21 +886,21 @@ pub fn readFromPackedMemory(
872886 },
873887 },
874888 .Pointer => {
875 assert(!ty.isSlice(mod)); // No well defined layout.
889 assert(!ty.isSlice(zcu)); // No well defined layout.
876890 const int_val = try readFromPackedMemory(Type.usize, pt, buffer, bit_offset, arena);
877891 return Value.fromInterned(try pt.intern(.{ .ptr = .{
878892 .ty = ty.toIntern(),
879893 .base_addr = .int,
880 .byte_offset = int_val.toUnsignedInt(pt),
894 .byte_offset = int_val.toUnsignedInt(zcu),
881895 } }));
882896 },
883897 .Optional => {
884 assert(ty.isPtrLikeOptional(mod));
885 const child_ty = ty.optionalChild(mod);
898 assert(ty.isPtrLikeOptional(zcu));
899 const child_ty = ty.optionalChild(zcu);
886900 const child_val = try readFromPackedMemory(child_ty, pt, buffer, bit_offset, arena);
887901 return Value.fromInterned(try pt.intern(.{ .opt = .{
888902 .ty = ty.toIntern(),
889 .val = switch (child_val.orderAgainstZero(pt)) {
903 .val = switch (child_val.orderAgainstZero(zcu)) {
890904 .lt => unreachable,
891905 .eq => .none,
892906 .gt => child_val.toIntern(),
......@@ -898,8 +912,8 @@ pub fn readFromPackedMemory(
898912}
899913
900914/// 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())) {
915pub fn toFloat(val: Value, comptime T: type, zcu: *Zcu) T {
916 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
903917 .int => |int| switch (int.storage) {
904918 .big_int => |big_int| @floatCast(bigIntToFloat(big_int.limbs, big_int.positive)),
905919 inline .u64, .i64 => |x| {
......@@ -908,8 +922,8 @@ pub fn toFloat(val: Value, comptime T: type, pt: Zcu.PerThread) T {
908922 }
909923 return @floatFromInt(x);
910924 },
911 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0),
912 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(pt)),
925 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0),
926 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(zcu)),
913927 },
914928 .float => |float| switch (float.storage) {
915929 inline else => |x| @floatCast(x),
......@@ -937,30 +951,30 @@ fn bigIntToFloat(limbs: []const std.math.big.Limb, positive: bool) f128 {
937951 }
938952}
939953
940pub fn clz(val: Value, ty: Type, pt: Zcu.PerThread) u64 {
954pub fn clz(val: Value, ty: Type, zcu: *Zcu) u64 {
941955 var bigint_buf: BigIntSpace = undefined;
942 const bigint = val.toBigInt(&bigint_buf, pt);
943 return bigint.clz(ty.intInfo(pt.zcu).bits);
956 const bigint = val.toBigInt(&bigint_buf, zcu);
957 return bigint.clz(ty.intInfo(zcu).bits);
944958}
945959
946pub fn ctz(val: Value, ty: Type, pt: Zcu.PerThread) u64 {
960pub fn ctz(val: Value, ty: Type, zcu: *Zcu) u64 {
947961 var bigint_buf: BigIntSpace = undefined;
948 const bigint = val.toBigInt(&bigint_buf, pt);
949 return bigint.ctz(ty.intInfo(pt.zcu).bits);
962 const bigint = val.toBigInt(&bigint_buf, zcu);
963 return bigint.ctz(ty.intInfo(zcu).bits);
950964}
951965
952pub fn popCount(val: Value, ty: Type, pt: Zcu.PerThread) u64 {
966pub fn popCount(val: Value, ty: Type, zcu: *Zcu) u64 {
953967 var bigint_buf: BigIntSpace = undefined;
954 const bigint = val.toBigInt(&bigint_buf, pt);
955 return @intCast(bigint.popCount(ty.intInfo(pt.zcu).bits));
968 const bigint = val.toBigInt(&bigint_buf, zcu);
969 return @intCast(bigint.popCount(ty.intInfo(zcu).bits));
956970}
957971
958972pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {
959 const mod = pt.zcu;
960 const info = ty.intInfo(mod);
973 const zcu = pt.zcu;
974 const info = ty.intInfo(zcu);
961975
962976 var buffer: Value.BigIntSpace = undefined;
963 const operand_bigint = val.toBigInt(&buffer, pt);
977 const operand_bigint = val.toBigInt(&buffer, zcu);
964978
965979 const limbs = try arena.alloc(
966980 std.math.big.Limb,
......@@ -973,14 +987,14 @@ pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Va
973987}
974988
975989pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {
976 const mod = pt.zcu;
977 const info = ty.intInfo(mod);
990 const zcu = pt.zcu;
991 const info = ty.intInfo(zcu);
978992
979993 // Bit count must be evenly divisible by 8
980994 assert(info.bits % 8 == 0);
981995
982996 var buffer: Value.BigIntSpace = undefined;
983 const operand_bigint = val.toBigInt(&buffer, pt);
997 const operand_bigint = val.toBigInt(&buffer, zcu);
984998
985999 const limbs = try arena.alloc(
9861000 std.math.big.Limb,
......@@ -994,33 +1008,34 @@ pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Valu
9941008
9951009/// Asserts the value is an integer and not undefined.
9961010/// Returns the number of bits the value requires to represent stored in twos complement form.
997pub fn intBitCountTwosComp(self: Value, pt: Zcu.PerThread) usize {
1011pub fn intBitCountTwosComp(self: Value, zcu: *Zcu) usize {
9981012 var buffer: BigIntSpace = undefined;
999 const big_int = self.toBigInt(&buffer, pt);
1013 const big_int = self.toBigInt(&buffer, zcu);
10001014 return big_int.bitCountTwosComp();
10011015}
10021016
10031017/// Converts an integer or a float to a float. May result in a loss of information.
10041018/// Caller can find out by equality checking the result against the operand.
10051019pub 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);
1020 const zcu = pt.zcu;
1021 const target = zcu.getTarget();
1022 if (val.isUndef(zcu)) return pt.undefValue(dest_ty);
10081023 return Value.fromInterned(try pt.intern(.{ .float = .{
10091024 .ty = dest_ty.toIntern(),
10101025 .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) },
1026 16 => .{ .f16 = val.toFloat(f16, zcu) },
1027 32 => .{ .f32 = val.toFloat(f32, zcu) },
1028 64 => .{ .f64 = val.toFloat(f64, zcu) },
1029 80 => .{ .f80 = val.toFloat(f80, zcu) },
1030 128 => .{ .f128 = val.toFloat(f128, zcu) },
10161031 else => unreachable,
10171032 },
10181033 } }));
10191034}
10201035
10211036/// Asserts the value is a float
1022pub fn floatHasFraction(self: Value, mod: *const Module) bool {
1023 return switch (mod.intern_pool.indexToKey(self.toIntern())) {
1037pub fn floatHasFraction(self: Value, zcu: *const Zcu) bool {
1038 return switch (zcu.intern_pool.indexToKey(self.toIntern())) {
10241039 .float => |float| switch (float.storage) {
10251040 inline else => |x| @rem(x, 1) != 0,
10261041 },
......@@ -1028,19 +1043,24 @@ pub fn floatHasFraction(self: Value, mod: *const Module) bool {
10281043 };
10291044}
10301045
1031pub fn orderAgainstZero(lhs: Value, pt: Zcu.PerThread) std.math.Order {
1032 return orderAgainstZeroAdvanced(lhs, pt, .normal) catch unreachable;
1046pub fn orderAgainstZero(lhs: Value, zcu: *Zcu) std.math.Order {
1047 return orderAgainstZeroInner(lhs, .normal, zcu, {}) catch unreachable;
10331048}
10341049
1035pub fn orderAgainstZeroAdvanced(
1050pub fn orderAgainstZeroSema(lhs: Value, pt: Zcu.PerThread) !std.math.Order {
1051 return try orderAgainstZeroInner(lhs, .sema, pt.zcu, pt.tid);
1052}
1053
1054pub fn orderAgainstZeroInner(
10361055 lhs: Value,
1037 pt: Zcu.PerThread,
10381056 comptime strat: ResolveStrat,
1039) Module.CompileError!std.math.Order {
1057 zcu: *Zcu,
1058 tid: strat.Tid(),
1059) Zcu.CompileError!std.math.Order {
10401060 return switch (lhs.toIntern()) {
10411061 .bool_false => .eq,
10421062 .bool_true => .gt,
1043 else => switch (pt.zcu.intern_pool.indexToKey(lhs.toIntern())) {
1063 else => switch (zcu.intern_pool.indexToKey(lhs.toIntern())) {
10441064 .ptr => |ptr| if (ptr.byte_offset > 0) .gt else switch (ptr.base_addr) {
10451065 .nav, .comptime_alloc, .comptime_field => .gt,
10461066 .int => .eq,
......@@ -1050,16 +1070,17 @@ pub fn orderAgainstZeroAdvanced(
10501070 .big_int => |big_int| big_int.orderAgainstScalar(0),
10511071 inline .u64, .i64 => |x| std.math.order(x, 0),
10521072 .lazy_align => .gt, // alignment is never 0
1053 .lazy_size => |ty| return if (Type.fromInterned(ty).hasRuntimeBitsAdvanced(
1054 pt,
1073 .lazy_size => |ty| return if (Type.fromInterned(ty).hasRuntimeBitsInner(
10551074 false,
10561075 strat.toLazy(),
1076 zcu,
1077 tid,
10571078 ) catch |err| switch (err) {
10581079 error.NeedLazy => unreachable,
10591080 else => |e| return e,
10601081 }) .gt else .eq,
10611082 },
1062 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).orderAgainstZeroAdvanced(pt, strat),
1083 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).orderAgainstZeroInner(strat, zcu, tid),
10631084 .float => |float| switch (float.storage) {
10641085 inline else => |x| std.math.order(x, 0),
10651086 },
......@@ -1069,14 +1090,20 @@ pub fn orderAgainstZeroAdvanced(
10691090}
10701091
10711092/// 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;
1093pub fn order(lhs: Value, rhs: Value, zcu: *Zcu) std.math.Order {
1094 return orderAdvanced(lhs, rhs, .normal, zcu, {}) catch unreachable;
10741095}
10751096
10761097/// 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);
1098pub fn orderAdvanced(
1099 lhs: Value,
1100 rhs: Value,
1101 comptime strat: ResolveStrat,
1102 zcu: *Zcu,
1103 tid: strat.Tid(),
1104) !std.math.Order {
1105 const lhs_against_zero = try lhs.orderAgainstZeroInner(strat, zcu, tid);
1106 const rhs_against_zero = try rhs.orderAgainstZeroInner(strat, zcu, tid);
10801107 switch (lhs_against_zero) {
10811108 .lt => if (rhs_against_zero != .lt) return .lt,
10821109 .eq => return rhs_against_zero.invert(),
......@@ -1088,34 +1115,39 @@ pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat:
10881115 .gt => {},
10891116 }
10901117
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);
1118 if (lhs.isFloat(zcu) or rhs.isFloat(zcu)) {
1119 const lhs_f128 = lhs.toFloat(f128, zcu);
1120 const rhs_f128 = rhs.toFloat(f128, zcu);
10941121 return std.math.order(lhs_f128, rhs_f128);
10951122 }
10961123
10971124 var lhs_bigint_space: BigIntSpace = undefined;
10981125 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);
1126 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_bigint_space, strat, zcu, tid);
1127 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_bigint_space, strat, zcu, tid);
11011128 return lhs_bigint.order(rhs_bigint);
11021129}
11031130
11041131/// Asserts the value is comparable. Does not take a type parameter because it supports
11051132/// 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;
1133pub fn compareHetero(lhs: Value, op: std.math.CompareOperator, rhs: Value, zcu: *Zcu) bool {
1134 return compareHeteroAdvanced(lhs, op, rhs, .normal, zcu, {}) catch unreachable;
1135}
1136
1137pub fn compareHeteroSema(lhs: Value, op: std.math.CompareOperator, rhs: Value, pt: Zcu.PerThread) !bool {
1138 return try compareHeteroAdvanced(lhs, op, rhs, .sema, pt.zcu, pt.tid);
11081139}
11091140
11101141pub fn compareHeteroAdvanced(
11111142 lhs: Value,
11121143 op: std.math.CompareOperator,
11131144 rhs: Value,
1114 pt: Zcu.PerThread,
11151145 comptime strat: ResolveStrat,
1146 zcu: *Zcu,
1147 tid: strat.Tid(),
11161148) !bool {
1117 if (lhs.pointerNav(pt.zcu)) |lhs_nav| {
1118 if (rhs.pointerNav(pt.zcu)) |rhs_nav| {
1149 if (lhs.pointerNav(zcu)) |lhs_nav| {
1150 if (rhs.pointerNav(zcu)) |rhs_nav| {
11191151 switch (op) {
11201152 .eq => return lhs_nav == rhs_nav,
11211153 .neq => return lhs_nav != rhs_nav,
......@@ -1128,32 +1160,32 @@ pub fn compareHeteroAdvanced(
11281160 else => {},
11291161 }
11301162 }
1131 } else if (rhs.pointerNav(pt.zcu)) |_| {
1163 } else if (rhs.pointerNav(zcu)) |_| {
11321164 switch (op) {
11331165 .eq => return false,
11341166 .neq => return true,
11351167 else => {},
11361168 }
11371169 }
1138 return (try orderAdvanced(lhs, rhs, pt, strat)).compare(op);
1170 return (try orderAdvanced(lhs, rhs, strat, zcu, tid)).compare(op);
11391171}
11401172
11411173/// Asserts the values are comparable. Both operands have type `ty`.
11421174/// For vectors, returns true if comparison is true for ALL elements.
11431175pub 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| {
1176 const zcu = pt.zcu;
1177 if (ty.zigTypeTag(zcu) == .Vector) {
1178 const scalar_ty = ty.scalarType(zcu);
1179 for (0..ty.vectorLen(zcu)) |i| {
11481180 const lhs_elem = try lhs.elemValue(pt, i);
11491181 const rhs_elem = try rhs.elemValue(pt, i);
1150 if (!compareScalar(lhs_elem, op, rhs_elem, scalar_ty, pt)) {
1182 if (!compareScalar(lhs_elem, op, rhs_elem, scalar_ty, zcu)) {
11511183 return false;
11521184 }
11531185 }
11541186 return true;
11551187 }
1156 return compareScalar(lhs, op, rhs, ty, pt);
1188 return compareScalar(lhs, op, rhs, ty, zcu);
11571189}
11581190
11591191/// Asserts the values are comparable. Both operands have type `ty`.
......@@ -1162,12 +1194,12 @@ pub fn compareScalar(
11621194 op: std.math.CompareOperator,
11631195 rhs: Value,
11641196 ty: Type,
1165 pt: Zcu.PerThread,
1197 zcu: *Zcu,
11661198) bool {
11671199 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),
1200 .eq => lhs.eql(rhs, ty, zcu),
1201 .neq => !lhs.eql(rhs, ty, zcu),
1202 else => compareHetero(lhs, op, rhs, zcu),
11711203 };
11721204}
11731205
......@@ -1176,56 +1208,56 @@ pub fn compareScalar(
11761208/// Returns `false` if the value or any vector element is undefined.
11771209///
11781210/// 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;
1211pub fn compareAllWithZero(lhs: Value, op: std.math.CompareOperator, zcu: *Zcu) bool {
1212 return compareAllWithZeroAdvancedExtra(lhs, op, .normal, zcu, {}) catch unreachable;
11811213}
11821214
11831215pub fn compareAllWithZeroSema(
11841216 lhs: Value,
11851217 op: std.math.CompareOperator,
11861218 pt: Zcu.PerThread,
1187) Module.CompileError!bool {
1188 return compareAllWithZeroAdvancedExtra(lhs, op, pt, .sema);
1219) Zcu.CompileError!bool {
1220 return compareAllWithZeroAdvancedExtra(lhs, op, .sema, pt.zcu, pt.tid);
11891221}
11901222
11911223pub fn compareAllWithZeroAdvancedExtra(
11921224 lhs: Value,
11931225 op: std.math.CompareOperator,
1194 pt: Zcu.PerThread,
11951226 comptime strat: ResolveStrat,
1196) Module.CompileError!bool {
1197 const mod = pt.zcu;
1198 if (lhs.isInf(mod)) {
1227 zcu: *Zcu,
1228 tid: strat.Tid(),
1229) Zcu.CompileError!bool {
1230 if (lhs.isInf(zcu)) {
11991231 switch (op) {
12001232 .neq => return true,
12011233 .eq => return false,
1202 .gt, .gte => return !lhs.isNegativeInf(mod),
1203 .lt, .lte => return lhs.isNegativeInf(mod),
1234 .gt, .gte => return !lhs.isNegativeInf(zcu),
1235 .lt, .lte => return lhs.isNegativeInf(zcu),
12041236 }
12051237 }
12061238
1207 switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
1239 switch (zcu.intern_pool.indexToKey(lhs.toIntern())) {
12081240 .float => |float| switch (float.storage) {
12091241 inline else => |x| if (std.math.isNan(x)) return op == .neq,
12101242 },
12111243 .aggregate => |aggregate| return switch (aggregate.storage) {
1212 .bytes => |bytes| for (bytes.toSlice(lhs.typeOf(mod).arrayLenIncludingSentinel(mod), &mod.intern_pool)) |byte| {
1244 .bytes => |bytes| for (bytes.toSlice(lhs.typeOf(zcu).arrayLenIncludingSentinel(zcu), &zcu.intern_pool)) |byte| {
12131245 if (!std.math.order(byte, 0).compare(op)) break false;
12141246 } else true,
12151247 .elems => |elems| for (elems) |elem| {
1216 if (!try Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, pt, strat)) break false;
1248 if (!try Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, strat, zcu, tid)) break false;
12171249 } else true,
1218 .repeated_elem => |elem| Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, pt, strat),
1250 .repeated_elem => |elem| Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, strat, zcu, tid),
12191251 },
12201252 .undef => return false,
12211253 else => {},
12221254 }
1223 return (try orderAgainstZeroAdvanced(lhs, pt, strat)).compare(op);
1255 return (try orderAgainstZeroInner(lhs, strat, zcu, tid)).compare(op);
12241256}
12251257
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());
1258pub fn eql(a: Value, b: Value, ty: Type, zcu: *Zcu) bool {
1259 assert(zcu.intern_pool.typeOf(a.toIntern()) == ty.toIntern());
1260 assert(zcu.intern_pool.typeOf(b.toIntern()) == ty.toIntern());
12291261 return a.toIntern() == b.toIntern();
12301262}
12311263
......@@ -1260,8 +1292,8 @@ pub fn canMutateComptimeVarState(val: Value, zcu: *Zcu) bool {
12601292/// Gets the `Nav` referenced by this pointer. If the pointer does not point
12611293/// to a `Nav`, or if it points to some part of one (like a field or element),
12621294/// returns null.
1263pub fn pointerNav(val: Value, mod: *Module) ?InternPool.Nav.Index {
1264 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1295pub fn pointerNav(val: Value, zcu: *Zcu) ?InternPool.Nav.Index {
1296 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
12651297 // TODO: these 3 cases are weird; these aren't pointer values!
12661298 .variable => |v| v.owner_nav,
12671299 .@"extern" => |e| e.owner_nav,
......@@ -1277,8 +1309,8 @@ pub fn pointerNav(val: Value, mod: *Module) ?InternPool.Nav.Index {
12771309pub const slice_ptr_index = 0;
12781310pub const slice_len_index = 1;
12791311
1280pub fn slicePtr(val: Value, mod: *Module) Value {
1281 return Value.fromInterned(mod.intern_pool.slicePtr(val.toIntern()));
1312pub fn slicePtr(val: Value, zcu: *Zcu) Value {
1313 return Value.fromInterned(zcu.intern_pool.slicePtr(val.toIntern()));
12821314}
12831315
12841316/// Gets the `len` field of a slice value as a `u64`.
......@@ -1312,15 +1344,15 @@ pub fn elemValue(val: Value, pt: Zcu.PerThread, index: usize) Allocator.Error!Va
13121344 }
13131345}
13141346
1315pub fn isLazyAlign(val: Value, mod: *Module) bool {
1316 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1347pub fn isLazyAlign(val: Value, zcu: *Zcu) bool {
1348 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13171349 .int => |int| int.storage == .lazy_align,
13181350 else => false,
13191351 };
13201352}
13211353
1322pub fn isLazySize(val: Value, mod: *Module) bool {
1323 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1354pub fn isLazySize(val: Value, zcu: *Zcu) bool {
1355 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13241356 .int => |int| int.storage == .lazy_size,
13251357 else => false,
13261358 };
......@@ -1377,15 +1409,15 @@ pub fn sliceArray(
13771409}
13781410
13791411pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
1380 const mod = pt.zcu;
1381 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1412 const zcu = pt.zcu;
1413 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
13821414 .undef => |ty| Value.fromInterned(try pt.intern(.{
1383 .undef = Type.fromInterned(ty).structFieldType(index, mod).toIntern(),
1415 .undef = Type.fromInterned(ty).fieldType(index, zcu).toIntern(),
13841416 })),
13851417 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {
13861418 .bytes => |bytes| try pt.intern(.{ .int = .{
13871419 .ty = .u8_type,
1388 .storage = .{ .u64 = bytes.at(index, &mod.intern_pool) },
1420 .storage = .{ .u64 = bytes.at(index, &zcu.intern_pool) },
13891421 } }),
13901422 .elems => |elems| elems[index],
13911423 .repeated_elem => |elem| elem,
......@@ -1396,40 +1428,40 @@ pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
13961428 };
13971429}
13981430
1399pub fn unionTag(val: Value, mod: *Module) ?Value {
1400 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1431pub fn unionTag(val: Value, zcu: *Zcu) ?Value {
1432 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14011433 .undef, .enum_tag => val,
14021434 .un => |un| if (un.tag != .none) Value.fromInterned(un.tag) else return null,
14031435 else => unreachable,
14041436 };
14051437}
14061438
1407pub fn unionValue(val: Value, mod: *Module) Value {
1408 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1439pub fn unionValue(val: Value, zcu: *Zcu) Value {
1440 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14091441 .un => |un| Value.fromInterned(un.val),
14101442 else => unreachable,
14111443 };
14121444}
14131445
1414pub fn isUndef(val: Value, mod: *Module) bool {
1415 return mod.intern_pool.isUndef(val.toIntern());
1446pub fn isUndef(val: Value, zcu: *Zcu) bool {
1447 return zcu.intern_pool.isUndef(val.toIntern());
14161448}
14171449
14181450/// TODO: check for cases such as array that is not marked undef but all the element
14191451/// values are marked undef, or struct that is not marked undef but all fields are marked
14201452/// undef, etc.
1421pub fn isUndefDeep(val: Value, mod: *Module) bool {
1422 return val.isUndef(mod);
1453pub fn isUndefDeep(val: Value, zcu: *Zcu) bool {
1454 return val.isUndef(zcu);
14231455}
14241456
14251457/// Asserts the value is not undefined and not unreachable.
14261458/// C pointers with an integer value of 0 are also considered null.
1427pub fn isNull(val: Value, mod: *Module) bool {
1459pub fn isNull(val: Value, zcu: *Zcu) bool {
14281460 return switch (val.toIntern()) {
14291461 .undef => unreachable,
14301462 .unreachable_value => unreachable,
14311463 .null_value => true,
1432 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1464 else => return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14331465 .undef => unreachable,
14341466 .ptr => |ptr| switch (ptr.base_addr) {
14351467 .int => ptr.byte_offset == 0,
......@@ -1442,8 +1474,8 @@ pub fn isNull(val: Value, mod: *Module) bool {
14421474}
14431475
14441476/// 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())) {
1477pub fn getErrorName(val: Value, zcu: *const Zcu) InternPool.OptionalNullTerminatedString {
1478 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14471479 .err => |err| err.name.toOptional(),
14481480 .error_union => |error_union| switch (error_union.val) {
14491481 .err_name => |err_name| err_name.toOptional(),
......@@ -1453,7 +1485,7 @@ pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTermi
14531485 };
14541486}
14551487
1456pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {
1488pub fn getErrorInt(val: Value, zcu: *Zcu) Zcu.ErrorInt {
14571489 return if (getErrorName(val, zcu).unwrap()) |err_name|
14581490 zcu.intern_pool.getErrorValueIfExists(err_name).?
14591491 else
......@@ -1462,13 +1494,13 @@ pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {
14621494
14631495/// Assumes the type is an error union. Returns true if and only if the value is
14641496/// 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;
1497pub fn errorUnionIsPayload(val: Value, zcu: *const Zcu) bool {
1498 return zcu.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;
14671499}
14681500
14691501/// 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())) {
1502pub fn optionalValue(val: Value, zcu: *const Zcu) ?Value {
1503 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
14721504 .opt => |opt| switch (opt.val) {
14731505 .none => null,
14741506 else => |payload| Value.fromInterned(payload),
......@@ -1479,10 +1511,10 @@ pub fn optionalValue(val: Value, mod: *const Module) ?Value {
14791511}
14801512
14811513/// Valid for all types. Asserts the value is not undefined.
1482pub fn isFloat(self: Value, mod: *const Module) bool {
1514pub fn isFloat(self: Value, zcu: *const Zcu) bool {
14831515 return switch (self.toIntern()) {
14841516 .undef => unreachable,
1485 else => switch (mod.intern_pool.indexToKey(self.toIntern())) {
1517 else => switch (zcu.intern_pool.indexToKey(self.toIntern())) {
14861518 .undef => unreachable,
14871519 .float => true,
14881520 else => false,
......@@ -1490,8 +1522,8 @@ pub fn isFloat(self: Value, mod: *const Module) bool {
14901522 };
14911523}
14921524
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) {
1525pub fn floatFromInt(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, zcu: *Zcu) !Value {
1526 return floatFromIntAdvanced(val, arena, int_ty, float_ty, zcu, .normal) catch |err| switch (err) {
14951527 error.OutOfMemory => return error.OutOfMemory,
14961528 else => unreachable,
14971529 };
......@@ -1505,10 +1537,10 @@ pub fn floatFromIntAdvanced(
15051537 pt: Zcu.PerThread,
15061538 comptime strat: ResolveStrat,
15071539) !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);
1540 const zcu = pt.zcu;
1541 if (int_ty.zigTypeTag(zcu) == .Vector) {
1542 const result_data = try arena.alloc(InternPool.Index, int_ty.vectorLen(zcu));
1543 const scalar_ty = float_ty.scalarType(zcu);
15121544 for (result_data, 0..) |*scalar, i| {
15131545 const elem_val = try val.elemValue(pt, i);
15141546 scalar.* = (try floatFromIntScalar(elem_val, scalar_ty, pt, strat)).toIntern();
......@@ -1522,8 +1554,8 @@ pub fn floatFromIntAdvanced(
15221554}
15231555
15241556pub 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())) {
1557 const zcu = pt.zcu;
1558 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
15271559 .undef => try pt.undefValue(float_ty),
15281560 .int => |int| switch (int.storage) {
15291561 .big_int => |big_int| {
......@@ -1531,8 +1563,8 @@ pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptim
15311563 return pt.floatValue(float_ty, float);
15321564 },
15331565 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),
1566 .lazy_align => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiAlignmentInner(strat.toLazy(), pt.zcu, pt.tid)).scalar.toByteUnits() orelse 0, float_ty, pt),
1567 .lazy_size => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiSizeInner(strat.toLazy(), pt.zcu, pt.tid)).scalar, float_ty, pt),
15361568 },
15371569 else => unreachable,
15381570 };
......@@ -1600,15 +1632,16 @@ pub fn intAddSatScalar(
16001632 arena: Allocator,
16011633 pt: Zcu.PerThread,
16021634) !Value {
1603 assert(!lhs.isUndef(pt.zcu));
1604 assert(!rhs.isUndef(pt.zcu));
1635 const zcu = pt.zcu;
1636 assert(!lhs.isUndef(zcu));
1637 assert(!rhs.isUndef(zcu));
16051638
1606 const info = ty.intInfo(pt.zcu);
1639 const info = ty.intInfo(zcu);
16071640
16081641 var lhs_space: Value.BigIntSpace = undefined;
16091642 var rhs_space: Value.BigIntSpace = undefined;
1610 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1611 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1643 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1644 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
16121645 const limbs = try arena.alloc(
16131646 std.math.big.Limb,
16141647 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -1650,15 +1683,17 @@ pub fn intSubSatScalar(
16501683 arena: Allocator,
16511684 pt: Zcu.PerThread,
16521685) !Value {
1653 assert(!lhs.isUndef(pt.zcu));
1654 assert(!rhs.isUndef(pt.zcu));
1686 const zcu = pt.zcu;
16551687
1656 const info = ty.intInfo(pt.zcu);
1688 assert(!lhs.isUndef(zcu));
1689 assert(!rhs.isUndef(zcu));
1690
1691 const info = ty.intInfo(zcu);
16571692
16581693 var lhs_space: Value.BigIntSpace = undefined;
16591694 var rhs_space: Value.BigIntSpace = undefined;
1660 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1661 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1695 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1696 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
16621697 const limbs = try arena.alloc(
16631698 std.math.big.Limb,
16641699 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -1675,12 +1710,12 @@ pub fn intMulWithOverflow(
16751710 arena: Allocator,
16761711 pt: Zcu.PerThread,
16771712) !OverflowArithmeticResult {
1678 const mod = pt.zcu;
1679 if (ty.zigTypeTag(mod) == .Vector) {
1680 const vec_len = ty.vectorLen(mod);
1713 const zcu = pt.zcu;
1714 if (ty.zigTypeTag(zcu) == .Vector) {
1715 const vec_len = ty.vectorLen(zcu);
16811716 const overflowed_data = try arena.alloc(InternPool.Index, vec_len);
16821717 const result_data = try arena.alloc(InternPool.Index, vec_len);
1683 const scalar_ty = ty.scalarType(mod);
1718 const scalar_ty = ty.scalarType(zcu);
16841719 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
16851720 const lhs_elem = try lhs.elemValue(pt, i);
16861721 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -1709,10 +1744,10 @@ pub fn intMulWithOverflowScalar(
17091744 arena: Allocator,
17101745 pt: Zcu.PerThread,
17111746) !OverflowArithmeticResult {
1712 const mod = pt.zcu;
1713 const info = ty.intInfo(mod);
1747 const zcu = pt.zcu;
1748 const info = ty.intInfo(zcu);
17141749
1715 if (lhs.isUndef(mod) or rhs.isUndef(mod)) {
1750 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) {
17161751 return .{
17171752 .overflow_bit = try pt.undefValue(Type.u1),
17181753 .wrapped_result = try pt.undefValue(ty),
......@@ -1721,8 +1756,8 @@ pub fn intMulWithOverflowScalar(
17211756
17221757 var lhs_space: Value.BigIntSpace = undefined;
17231758 var rhs_space: Value.BigIntSpace = undefined;
1724 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1725 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1759 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1760 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
17261761 const limbs = try arena.alloc(
17271762 std.math.big.Limb,
17281763 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
......@@ -1753,10 +1788,10 @@ pub fn numberMulWrap(
17531788 arena: Allocator,
17541789 pt: Zcu.PerThread,
17551790) !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);
1791 const zcu = pt.zcu;
1792 if (ty.zigTypeTag(zcu) == .Vector) {
1793 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
1794 const scalar_ty = ty.scalarType(zcu);
17601795 for (result_data, 0..) |*scalar, i| {
17611796 const lhs_elem = try lhs.elemValue(pt, i);
17621797 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -1778,10 +1813,10 @@ pub fn numberMulWrapScalar(
17781813 arena: Allocator,
17791814 pt: Zcu.PerThread,
17801815) !Value {
1781 const mod = pt.zcu;
1782 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.undef;
1816 const zcu = pt.zcu;
1817 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.undef;
17831818
1784 if (ty.zigTypeTag(mod) == .ComptimeInt) {
1819 if (ty.zigTypeTag(zcu) == .ComptimeInt) {
17851820 return intMul(lhs, rhs, ty, undefined, arena, pt);
17861821 }
17871822
......@@ -1825,15 +1860,17 @@ pub fn intMulSatScalar(
18251860 arena: Allocator,
18261861 pt: Zcu.PerThread,
18271862) !Value {
1828 assert(!lhs.isUndef(pt.zcu));
1829 assert(!rhs.isUndef(pt.zcu));
1863 const zcu = pt.zcu;
1864
1865 assert(!lhs.isUndef(zcu));
1866 assert(!rhs.isUndef(zcu));
18301867
1831 const info = ty.intInfo(pt.zcu);
1868 const info = ty.intInfo(zcu);
18321869
18331870 var lhs_space: Value.BigIntSpace = undefined;
18341871 var rhs_space: Value.BigIntSpace = undefined;
1835 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1836 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
1872 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1873 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
18371874 const limbs = try arena.alloc(
18381875 std.math.big.Limb,
18391876 @max(
......@@ -1853,24 +1890,24 @@ pub fn intMulSatScalar(
18531890}
18541891
18551892/// 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;
1893pub fn numberMax(lhs: Value, rhs: Value, zcu: *Zcu) Value {
1894 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return undef;
1895 if (lhs.isNan(zcu)) return rhs;
1896 if (rhs.isNan(zcu)) return lhs;
18601897
1861 return switch (order(lhs, rhs, pt)) {
1898 return switch (order(lhs, rhs, zcu)) {
18621899 .lt => rhs,
18631900 .gt, .eq => lhs,
18641901 };
18651902}
18661903
18671904/// 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;
1905pub fn numberMin(lhs: Value, rhs: Value, zcu: *Zcu) Value {
1906 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return undef;
1907 if (lhs.isNan(zcu)) return rhs;
1908 if (rhs.isNan(zcu)) return lhs;
18721909
1873 return switch (order(lhs, rhs, pt)) {
1910 return switch (order(lhs, rhs, zcu)) {
18741911 .lt => lhs,
18751912 .gt, .eq => rhs,
18761913 };
......@@ -1878,10 +1915,10 @@ pub fn numberMin(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {
18781915
18791916/// operands must be (vectors of) integers; handles undefined scalars.
18801917pub 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);
1918 const zcu = pt.zcu;
1919 if (ty.zigTypeTag(zcu) == .Vector) {
1920 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
1921 const scalar_ty = ty.scalarType(zcu);
18851922 for (result_data, 0..) |*scalar, i| {
18861923 const elem_val = try val.elemValue(pt, i);
18871924 scalar.* = (try bitwiseNotScalar(elem_val, scalar_ty, arena, pt)).toIntern();
......@@ -1896,11 +1933,11 @@ pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Va
18961933
18971934/// operands must be integers; handles undefined.
18981935pub 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() }));
1936 const zcu = pt.zcu;
1937 if (val.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
19011938 if (ty.toIntern() == .bool_type) return makeBool(!val.toBool());
19021939
1903 const info = ty.intInfo(mod);
1940 const info = ty.intInfo(zcu);
19041941
19051942 if (info.bits == 0) {
19061943 return val;
......@@ -1909,7 +1946,7 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea
19091946 // TODO is this a performance issue? maybe we should try the operation without
19101947 // resorting to BigInt first.
19111948 var val_space: Value.BigIntSpace = undefined;
1912 const val_bigint = val.toBigInt(&val_space, pt);
1949 const val_bigint = val.toBigInt(&val_space, zcu);
19131950 const limbs = try arena.alloc(
19141951 std.math.big.Limb,
19151952 std.math.big.int.calcTwosCompLimbCount(info.bits),
......@@ -1922,10 +1959,10 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea
19221959
19231960/// operands must be (vectors of) integers; handles undefined scalars.
19241961pub 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);
1962 const zcu = pt.zcu;
1963 if (ty.zigTypeTag(zcu) == .Vector) {
1964 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
1965 const scalar_ty = ty.scalarType(zcu);
19291966 for (result_data, 0..) |*scalar, i| {
19301967 const lhs_elem = try lhs.elemValue(pt, i);
19311968 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -1962,8 +1999,8 @@ pub fn bitwiseAndScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloc
19621999 // resorting to BigInt first.
19632000 var lhs_space: Value.BigIntSpace = undefined;
19642001 var rhs_space: Value.BigIntSpace = undefined;
1965 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
1966 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2002 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2003 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
19672004 const limbs = try arena.alloc(
19682005 std.math.big.Limb,
19692006 // + 1 for negatives
......@@ -1995,10 +2032,10 @@ fn intValueAa(ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
19952032
19962033/// operands must be (vectors of) integers; handles undefined scalars.
19972034pub 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);
2035 const zcu = pt.zcu;
2036 if (ty.zigTypeTag(zcu) == .Vector) {
2037 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
2038 const scalar_ty = ty.scalarType(zcu);
20022039 for (result_data, 0..) |*scalar, i| {
20032040 const lhs_elem = try lhs.elemValue(pt, i);
20042041 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2014,21 +2051,21 @@ pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.P
20142051
20152052/// operands must be integers; handles undefined.
20162053pub 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() }));
2054 const zcu = pt.zcu;
2055 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
20192056 if (ty.toIntern() == .bool_type) return makeBool(!(lhs.toBool() and rhs.toBool()));
20202057
20212058 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);
2059 const all_ones = if (ty.isSignedInt(zcu)) try pt.intValue(ty, -1) else try ty.maxIntScalar(pt, ty);
20232060 return bitwiseXor(anded, all_ones, ty, arena, pt);
20242061}
20252062
20262063/// operands must be (vectors of) integers; handles undefined scalars.
20272064pub 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);
2065 const zcu = pt.zcu;
2066 if (ty.zigTypeTag(zcu) == .Vector) {
2067 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2068 const scalar_ty = ty.scalarType(zcu);
20322069 for (result_data, 0..) |*scalar, i| {
20332070 const lhs_elem = try lhs.elemValue(pt, i);
20342071 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2047,9 +2084,10 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
20472084 // If one operand is defined, we turn the other into `0xAA` so the bitwise AND can
20482085 // still zero out some bits.
20492086 // TODO: ideally we'd still like tracking for the undef bits. Related: #19634.
2087 const zcu = pt.zcu;
20502088 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);
2089 const lhs_undef = orig_lhs.isUndef(zcu);
2090 const rhs_undef = orig_rhs.isUndef(zcu);
20532091 break :make_defined switch ((@as(u2, @intFromBool(lhs_undef)) << 1) | @intFromBool(rhs_undef)) {
20542092 0b00 => .{ orig_lhs, orig_rhs },
20552093 0b01 => .{ orig_lhs, try intValueAa(ty, arena, pt) },
......@@ -2064,8 +2102,8 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
20642102 // resorting to BigInt first.
20652103 var lhs_space: Value.BigIntSpace = undefined;
20662104 var rhs_space: Value.BigIntSpace = undefined;
2067 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2068 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2105 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2106 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
20692107 const limbs = try arena.alloc(
20702108 std.math.big.Limb,
20712109 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len),
......@@ -2077,10 +2115,10 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
20772115
20782116/// operands must be (vectors of) integers; handles undefined scalars.
20792117pub 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);
2118 const zcu = pt.zcu;
2119 if (ty.zigTypeTag(zcu) == .Vector) {
2120 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2121 const scalar_ty = ty.scalarType(zcu);
20842122 for (result_data, 0..) |*scalar, i| {
20852123 const lhs_elem = try lhs.elemValue(pt, i);
20862124 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2096,16 +2134,16 @@ pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zc
20962134
20972135/// operands must be integers; handles undefined.
20982136pub 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() }));
2137 const zcu = pt.zcu;
2138 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
21012139 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() != rhs.toBool());
21022140
21032141 // TODO is this a performance issue? maybe we should try the operation without
21042142 // resorting to BigInt first.
21052143 var lhs_space: Value.BigIntSpace = undefined;
21062144 var rhs_space: Value.BigIntSpace = undefined;
2107 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2108 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2145 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2146 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
21092147 const limbs = try arena.alloc(
21102148 std.math.big.Limb,
21112149 // + 1 for negatives
......@@ -2164,10 +2202,11 @@ fn intDivInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator
21642202pub fn intDivScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
21652203 // TODO is this a performance issue? maybe we should try the operation without
21662204 // resorting to BigInt first.
2205 const zcu = pt.zcu;
21672206 var lhs_space: Value.BigIntSpace = undefined;
21682207 var rhs_space: Value.BigIntSpace = undefined;
2169 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2170 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2208 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2209 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
21712210 const limbs_q = try allocator.alloc(
21722211 std.math.big.Limb,
21732212 lhs_bigint.limbs.len,
......@@ -2212,10 +2251,11 @@ pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Z
22122251pub fn intDivFloorScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
22132252 // TODO is this a performance issue? maybe we should try the operation without
22142253 // resorting to BigInt first.
2254 const zcu = pt.zcu;
22152255 var lhs_space: Value.BigIntSpace = undefined;
22162256 var rhs_space: Value.BigIntSpace = undefined;
2217 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2218 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2257 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2258 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
22192259 const limbs_q = try allocator.alloc(
22202260 std.math.big.Limb,
22212261 lhs_bigint.limbs.len,
......@@ -2254,10 +2294,11 @@ pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.Pe
22542294pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
22552295 // TODO is this a performance issue? maybe we should try the operation without
22562296 // resorting to BigInt first.
2297 const zcu = pt.zcu;
22572298 var lhs_space: Value.BigIntSpace = undefined;
22582299 var rhs_space: Value.BigIntSpace = undefined;
2259 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2260 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2300 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2301 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
22612302 const limbs_q = try allocator.alloc(
22622303 std.math.big.Limb,
22632304 lhs_bigint.limbs.len,
......@@ -2277,8 +2318,8 @@ pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
22772318}
22782319
22792320/// 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())) {
2321pub fn isNan(val: Value, zcu: *const Zcu) bool {
2322 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
22822323 .float => |float| switch (float.storage) {
22832324 inline else => |x| std.math.isNan(x),
22842325 },
......@@ -2287,8 +2328,8 @@ pub fn isNan(val: Value, mod: *const Module) bool {
22872328}
22882329
22892330/// 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())) {
2331pub fn isInf(val: Value, zcu: *const Zcu) bool {
2332 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
22922333 .float => |float| switch (float.storage) {
22932334 inline else => |x| std.math.isInf(x),
22942335 },
......@@ -2296,8 +2337,8 @@ pub fn isInf(val: Value, mod: *const Module) bool {
22962337 };
22972338}
22982339
2299pub fn isNegativeInf(val: Value, mod: *const Module) bool {
2300 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2340pub fn isNegativeInf(val: Value, zcu: *const Zcu) bool {
2341 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
23012342 .float => |float| switch (float.storage) {
23022343 inline else => |x| std.math.isNegativeInf(x),
23032344 },
......@@ -2323,13 +2364,14 @@ pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:
23232364}
23242365
23252366pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThread) !Value {
2367 const zcu = pt.zcu;
23262368 const target = pt.zcu.getTarget();
23272369 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)) },
2370 16 => .{ .f16 = @rem(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
2371 32 => .{ .f32 = @rem(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
2372 64 => .{ .f64 = @rem(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
2373 80 => .{ .f80 = @rem(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
2374 128 => .{ .f128 = @rem(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
23332375 else => unreachable,
23342376 };
23352377 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2356,13 +2398,14 @@ pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:
23562398}
23572399
23582400pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThread) !Value {
2359 const target = pt.zcu.getTarget();
2401 const zcu = pt.zcu;
2402 const target = zcu.getTarget();
23602403 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)) },
2404 16 => .{ .f16 = @mod(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
2405 32 => .{ .f32 = @mod(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
2406 64 => .{ .f64 = @mod(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
2407 80 => .{ .f80 = @mod(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
2408 128 => .{ .f128 = @mod(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
23662409 else => unreachable,
23672410 };
23682411 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2374,14 +2417,14 @@ pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThrea
23742417/// If the value overflowed the type, returns a comptime_int (or vector thereof) instead, setting
23752418/// overflow_idx to the vector index the overflow was at (or 0 for a scalar).
23762419pub fn intMul(lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize, allocator: Allocator, pt: Zcu.PerThread) !Value {
2377 const mod = pt.zcu;
2420 const zcu = pt.zcu;
23782421 var overflow: usize = undefined;
23792422 return intMulInner(lhs, rhs, ty, &overflow, allocator, pt) catch |err| switch (err) {
23802423 error.Overflow => {
2381 const is_vec = ty.isVector(mod);
2424 const is_vec = ty.isVector(zcu);
23822425 overflow_idx.* = if (is_vec) overflow else 0;
23832426 const safe_ty = if (is_vec) try pt.vectorType(.{
2384 .len = ty.vectorLen(mod),
2427 .len = ty.vectorLen(zcu),
23852428 .child = .comptime_int_type,
23862429 }) else Type.comptime_int;
23872430 return intMulInner(lhs, rhs, safe_ty, undefined, allocator, pt) catch |err1| switch (err1) {
......@@ -2394,10 +2437,10 @@ pub fn intMul(lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize, allocator
23942437}
23952438
23962439fn 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);
2440 const zcu = pt.zcu;
2441 if (ty.zigTypeTag(zcu) == .Vector) {
2442 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2443 const scalar_ty = ty.scalarType(zcu);
24012444 for (result_data, 0..) |*scalar, i| {
24022445 const lhs_elem = try lhs.elemValue(pt, i);
24032446 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2419,17 +2462,18 @@ fn intMulInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator
24192462}
24202463
24212464pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2465 const zcu = pt.zcu;
24222466 if (ty.toIntern() != .comptime_int_type) {
24232467 const res = try intMulWithOverflowScalar(lhs, rhs, ty, allocator, pt);
2424 if (res.overflow_bit.compareAllWithZero(.neq, pt)) return error.Overflow;
2468 if (res.overflow_bit.compareAllWithZero(.neq, zcu)) return error.Overflow;
24252469 return res.wrapped_result;
24262470 }
24272471 // TODO is this a performance issue? maybe we should try the operation without
24282472 // resorting to BigInt first.
24292473 var lhs_space: Value.BigIntSpace = undefined;
24302474 var rhs_space: Value.BigIntSpace = undefined;
2431 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2432 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);
2475 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2476 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
24332477 const limbs = try allocator.alloc(
24342478 std.math.big.Limb,
24352479 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
......@@ -2445,10 +2489,10 @@ pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
24452489}
24462490
24472491pub 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);
2492 const zcu = pt.zcu;
2493 if (ty.zigTypeTag(zcu) == .Vector) {
2494 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2495 const scalar_ty = ty.scalarType(zcu);
24522496 for (result_data, 0..) |*scalar, i| {
24532497 const elem_val = try val.elemValue(pt, i);
24542498 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, pt)).toIntern();
......@@ -2470,20 +2514,21 @@ pub fn intTruncBitsAsValue(
24702514 bits: Value,
24712515 pt: Zcu.PerThread,
24722516) !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);
2517 const zcu = pt.zcu;
2518 if (ty.zigTypeTag(zcu) == .Vector) {
2519 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2520 const scalar_ty = ty.scalarType(zcu);
24762521 for (result_data, 0..) |*scalar, i| {
24772522 const elem_val = try val.elemValue(pt, i);
24782523 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();
2524 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(bits_elem.toUnsignedInt(zcu)), pt)).toIntern();
24802525 }
24812526 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
24822527 .ty = ty.toIntern(),
24832528 .storage = .{ .elems = result_data },
24842529 } }));
24852530 }
2486 return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(pt)), pt);
2531 return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(zcu)), pt);
24872532}
24882533
24892534pub fn intTruncScalar(
......@@ -2500,7 +2545,7 @@ pub fn intTruncScalar(
25002545 if (val.isUndef(zcu)) return pt.undefValue(ty);
25012546
25022547 var val_space: Value.BigIntSpace = undefined;
2503 const val_bigint = val.toBigInt(&val_space, pt);
2548 const val_bigint = val.toBigInt(&val_space, zcu);
25042549
25052550 const limbs = try allocator.alloc(
25062551 std.math.big.Limb,
......@@ -2513,10 +2558,10 @@ pub fn intTruncScalar(
25132558}
25142559
25152560pub 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);
2561 const zcu = pt.zcu;
2562 if (ty.zigTypeTag(zcu) == .Vector) {
2563 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2564 const scalar_ty = ty.scalarType(zcu);
25202565 for (result_data, 0..) |*scalar, i| {
25212566 const lhs_elem = try lhs.elemValue(pt, i);
25222567 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2533,9 +2578,10 @@ pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerTh
25332578pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
25342579 // TODO is this a performance issue? maybe we should try the operation without
25352580 // resorting to BigInt first.
2581 const zcu = pt.zcu;
25362582 var lhs_space: Value.BigIntSpace = undefined;
2537 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2538 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2583 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2584 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
25392585 const limbs = try allocator.alloc(
25402586 std.math.big.Limb,
25412587 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2547,7 +2593,7 @@ pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu
25472593 };
25482594 result_bigint.shiftLeft(lhs_bigint, shift);
25492595 if (ty.toIntern() != .comptime_int_type) {
2550 const int_info = ty.intInfo(pt.zcu);
2596 const int_info = ty.intInfo(zcu);
25512597 result_bigint.truncate(result_bigint.toConst(), int_info.signedness, int_info.bits);
25522598 }
25532599
......@@ -2594,10 +2640,11 @@ pub fn shlWithOverflowScalar(
25942640 allocator: Allocator,
25952641 pt: Zcu.PerThread,
25962642) !OverflowArithmeticResult {
2597 const info = ty.intInfo(pt.zcu);
2643 const zcu = pt.zcu;
2644 const info = ty.intInfo(zcu);
25982645 var lhs_space: Value.BigIntSpace = undefined;
2599 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2600 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2646 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2647 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
26012648 const limbs = try allocator.alloc(
26022649 std.math.big.Limb,
26032650 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
......@@ -2650,11 +2697,12 @@ pub fn shlSatScalar(
26502697) !Value {
26512698 // TODO is this a performance issue? maybe we should try the operation without
26522699 // resorting to BigInt first.
2653 const info = ty.intInfo(pt.zcu);
2700 const zcu = pt.zcu;
2701 const info = ty.intInfo(zcu);
26542702
26552703 var lhs_space: Value.BigIntSpace = undefined;
2656 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2657 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2704 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2705 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
26582706 const limbs = try arena.alloc(
26592707 std.math.big.Limb,
26602708 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,
......@@ -2724,9 +2772,10 @@ pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerTh
27242772pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
27252773 // TODO is this a performance issue? maybe we should try the operation without
27262774 // resorting to BigInt first.
2775 const zcu = pt.zcu;
27272776 var lhs_space: Value.BigIntSpace = undefined;
2728 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);
2729 const shift: usize = @intCast(rhs.toUnsignedInt(pt));
2777 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2778 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
27302779
27312780 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
27322781 if (result_limbs == 0) {
......@@ -2758,10 +2807,10 @@ pub fn floatNeg(
27582807 arena: Allocator,
27592808 pt: Zcu.PerThread,
27602809) !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);
2810 const zcu = pt.zcu;
2811 if (float_type.zigTypeTag(zcu) == .Vector) {
2812 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2813 const scalar_ty = float_type.scalarType(zcu);
27652814 for (result_data, 0..) |*scalar, i| {
27662815 const elem_val = try val.elemValue(pt, i);
27672816 scalar.* = (try floatNegScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -2775,13 +2824,14 @@ pub fn floatNeg(
27752824}
27762825
27772826pub fn floatNegScalar(val: Value, float_type: Type, pt: Zcu.PerThread) !Value {
2778 const target = pt.zcu.getTarget();
2827 const zcu = pt.zcu;
2828 const target = zcu.getTarget();
27792829 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) },
2830 16 => .{ .f16 = -val.toFloat(f16, zcu) },
2831 32 => .{ .f32 = -val.toFloat(f32, zcu) },
2832 64 => .{ .f64 = -val.toFloat(f64, zcu) },
2833 80 => .{ .f80 = -val.toFloat(f80, zcu) },
2834 128 => .{ .f128 = -val.toFloat(f128, zcu) },
27852835 else => unreachable,
27862836 };
27872837 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2797,10 +2847,10 @@ pub fn floatAdd(
27972847 arena: Allocator,
27982848 pt: Zcu.PerThread,
27992849) !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);
2850 const zcu = pt.zcu;
2851 if (float_type.zigTypeTag(zcu) == .Vector) {
2852 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2853 const scalar_ty = float_type.scalarType(zcu);
28042854 for (result_data, 0..) |*scalar, i| {
28052855 const lhs_elem = try lhs.elemValue(pt, i);
28062856 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2820,14 +2870,14 @@ pub fn floatAddScalar(
28202870 float_type: Type,
28212871 pt: Zcu.PerThread,
28222872) !Value {
2823 const mod = pt.zcu;
2824 const target = mod.getTarget();
2873 const zcu = pt.zcu;
2874 const target = zcu.getTarget();
28252875 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) },
2876 16 => .{ .f16 = lhs.toFloat(f16, zcu) + rhs.toFloat(f16, zcu) },
2877 32 => .{ .f32 = lhs.toFloat(f32, zcu) + rhs.toFloat(f32, zcu) },
2878 64 => .{ .f64 = lhs.toFloat(f64, zcu) + rhs.toFloat(f64, zcu) },
2879 80 => .{ .f80 = lhs.toFloat(f80, zcu) + rhs.toFloat(f80, zcu) },
2880 128 => .{ .f128 = lhs.toFloat(f128, zcu) + rhs.toFloat(f128, zcu) },
28312881 else => unreachable,
28322882 };
28332883 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2843,10 +2893,10 @@ pub fn floatSub(
28432893 arena: Allocator,
28442894 pt: Zcu.PerThread,
28452895) !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);
2896 const zcu = pt.zcu;
2897 if (float_type.zigTypeTag(zcu) == .Vector) {
2898 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2899 const scalar_ty = float_type.scalarType(zcu);
28502900 for (result_data, 0..) |*scalar, i| {
28512901 const lhs_elem = try lhs.elemValue(pt, i);
28522902 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -2866,14 +2916,14 @@ pub fn floatSubScalar(
28662916 float_type: Type,
28672917 pt: Zcu.PerThread,
28682918) !Value {
2869 const mod = pt.zcu;
2870 const target = mod.getTarget();
2919 const zcu = pt.zcu;
2920 const target = zcu.getTarget();
28712921 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) },
2922 16 => .{ .f16 = lhs.toFloat(f16, zcu) - rhs.toFloat(f16, zcu) },
2923 32 => .{ .f32 = lhs.toFloat(f32, zcu) - rhs.toFloat(f32, zcu) },
2924 64 => .{ .f64 = lhs.toFloat(f64, zcu) - rhs.toFloat(f64, zcu) },
2925 80 => .{ .f80 = lhs.toFloat(f80, zcu) - rhs.toFloat(f80, zcu) },
2926 128 => .{ .f128 = lhs.toFloat(f128, zcu) - rhs.toFloat(f128, zcu) },
28772927 else => unreachable,
28782928 };
28792929 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2911,13 +2961,14 @@ pub fn floatDivScalar(
29112961 float_type: Type,
29122962 pt: Zcu.PerThread,
29132963) !Value {
2914 const target = pt.zcu.getTarget();
2964 const zcu = pt.zcu;
2965 const target = zcu.getTarget();
29152966 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) },
2967 16 => .{ .f16 = lhs.toFloat(f16, zcu) / rhs.toFloat(f16, zcu) },
2968 32 => .{ .f32 = lhs.toFloat(f32, zcu) / rhs.toFloat(f32, zcu) },
2969 64 => .{ .f64 = lhs.toFloat(f64, zcu) / rhs.toFloat(f64, zcu) },
2970 80 => .{ .f80 = lhs.toFloat(f80, zcu) / rhs.toFloat(f80, zcu) },
2971 128 => .{ .f128 = lhs.toFloat(f128, zcu) / rhs.toFloat(f128, zcu) },
29212972 else => unreachable,
29222973 };
29232974 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2955,13 +3006,14 @@ pub fn floatDivFloorScalar(
29553006 float_type: Type,
29563007 pt: Zcu.PerThread,
29573008) !Value {
2958 const target = pt.zcu.getTarget();
3009 const zcu = pt.zcu;
3010 const target = zcu.getTarget();
29593011 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)) },
3012 16 => .{ .f16 = @divFloor(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
3013 32 => .{ .f32 = @divFloor(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
3014 64 => .{ .f64 = @divFloor(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
3015 80 => .{ .f80 = @divFloor(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
3016 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
29653017 else => unreachable,
29663018 };
29673019 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -2999,13 +3051,14 @@ pub fn floatDivTruncScalar(
29993051 float_type: Type,
30003052 pt: Zcu.PerThread,
30013053) !Value {
3002 const target = pt.zcu.getTarget();
3054 const zcu = pt.zcu;
3055 const target = zcu.getTarget();
30033056 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)) },
3057 16 => .{ .f16 = @divTrunc(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
3058 32 => .{ .f32 = @divTrunc(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
3059 64 => .{ .f64 = @divTrunc(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
3060 80 => .{ .f80 = @divTrunc(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
3061 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
30093062 else => unreachable,
30103063 };
30113064 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3021,10 +3074,10 @@ pub fn floatMul(
30213074 arena: Allocator,
30223075 pt: Zcu.PerThread,
30233076) !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);
3077 const zcu = pt.zcu;
3078 if (float_type.zigTypeTag(zcu) == .Vector) {
3079 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3080 const scalar_ty = float_type.scalarType(zcu);
30283081 for (result_data, 0..) |*scalar, i| {
30293082 const lhs_elem = try lhs.elemValue(pt, i);
30303083 const rhs_elem = try rhs.elemValue(pt, i);
......@@ -3044,14 +3097,14 @@ pub fn floatMulScalar(
30443097 float_type: Type,
30453098 pt: Zcu.PerThread,
30463099) !Value {
3047 const mod = pt.zcu;
3048 const target = mod.getTarget();
3100 const zcu = pt.zcu;
3101 const target = zcu.getTarget();
30493102 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) },
3103 16 => .{ .f16 = lhs.toFloat(f16, zcu) * rhs.toFloat(f16, zcu) },
3104 32 => .{ .f32 = lhs.toFloat(f32, zcu) * rhs.toFloat(f32, zcu) },
3105 64 => .{ .f64 = lhs.toFloat(f64, zcu) * rhs.toFloat(f64, zcu) },
3106 80 => .{ .f80 = lhs.toFloat(f80, zcu) * rhs.toFloat(f80, zcu) },
3107 128 => .{ .f128 = lhs.toFloat(f128, zcu) * rhs.toFloat(f128, zcu) },
30553108 else => unreachable,
30563109 };
30573110 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3077,14 +3130,14 @@ pub fn sqrt(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
30773130}
30783131
30793132pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3080 const mod = pt.zcu;
3081 const target = mod.getTarget();
3133 const zcu = pt.zcu;
3134 const target = zcu.getTarget();
30823135 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)) },
3136 16 => .{ .f16 = @sqrt(val.toFloat(f16, zcu)) },
3137 32 => .{ .f32 = @sqrt(val.toFloat(f32, zcu)) },
3138 64 => .{ .f64 = @sqrt(val.toFloat(f64, zcu)) },
3139 80 => .{ .f80 = @sqrt(val.toFloat(f80, zcu)) },
3140 128 => .{ .f128 = @sqrt(val.toFloat(f128, zcu)) },
30883141 else => unreachable,
30893142 };
30903143 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3094,10 +3147,10 @@ pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
30943147}
30953148
30963149pub 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);
3150 const zcu = pt.zcu;
3151 if (float_type.zigTypeTag(zcu) == .Vector) {
3152 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3153 const scalar_ty = float_type.scalarType(zcu);
31013154 for (result_data, 0..) |*scalar, i| {
31023155 const elem_val = try val.elemValue(pt, i);
31033156 scalar.* = (try sinScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3111,14 +3164,14 @@ pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
31113164}
31123165
31133166pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3114 const mod = pt.zcu;
3115 const target = mod.getTarget();
3167 const zcu = pt.zcu;
3168 const target = zcu.getTarget();
31163169 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)) },
3170 16 => .{ .f16 = @sin(val.toFloat(f16, zcu)) },
3171 32 => .{ .f32 = @sin(val.toFloat(f32, zcu)) },
3172 64 => .{ .f64 = @sin(val.toFloat(f64, zcu)) },
3173 80 => .{ .f80 = @sin(val.toFloat(f80, zcu)) },
3174 128 => .{ .f128 = @sin(val.toFloat(f128, zcu)) },
31223175 else => unreachable,
31233176 };
31243177 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3128,10 +3181,10 @@ pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
31283181}
31293182
31303183pub 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);
3184 const zcu = pt.zcu;
3185 if (float_type.zigTypeTag(zcu) == .Vector) {
3186 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3187 const scalar_ty = float_type.scalarType(zcu);
31353188 for (result_data, 0..) |*scalar, i| {
31363189 const elem_val = try val.elemValue(pt, i);
31373190 scalar.* = (try cosScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3145,14 +3198,14 @@ pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
31453198}
31463199
31473200pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3148 const mod = pt.zcu;
3149 const target = mod.getTarget();
3201 const zcu = pt.zcu;
3202 const target = zcu.getTarget();
31503203 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)) },
3204 16 => .{ .f16 = @cos(val.toFloat(f16, zcu)) },
3205 32 => .{ .f32 = @cos(val.toFloat(f32, zcu)) },
3206 64 => .{ .f64 = @cos(val.toFloat(f64, zcu)) },
3207 80 => .{ .f80 = @cos(val.toFloat(f80, zcu)) },
3208 128 => .{ .f128 = @cos(val.toFloat(f128, zcu)) },
31563209 else => unreachable,
31573210 };
31583211 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3162,10 +3215,10 @@ pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
31623215}
31633216
31643217pub 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);
3218 const zcu = pt.zcu;
3219 if (float_type.zigTypeTag(zcu) == .Vector) {
3220 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3221 const scalar_ty = float_type.scalarType(zcu);
31693222 for (result_data, 0..) |*scalar, i| {
31703223 const elem_val = try val.elemValue(pt, i);
31713224 scalar.* = (try tanScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3179,14 +3232,14 @@ pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
31793232}
31803233
31813234pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3182 const mod = pt.zcu;
3183 const target = mod.getTarget();
3235 const zcu = pt.zcu;
3236 const target = zcu.getTarget();
31843237 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)) },
3238 16 => .{ .f16 = @tan(val.toFloat(f16, zcu)) },
3239 32 => .{ .f32 = @tan(val.toFloat(f32, zcu)) },
3240 64 => .{ .f64 = @tan(val.toFloat(f64, zcu)) },
3241 80 => .{ .f80 = @tan(val.toFloat(f80, zcu)) },
3242 128 => .{ .f128 = @tan(val.toFloat(f128, zcu)) },
31903243 else => unreachable,
31913244 };
31923245 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3196,10 +3249,10 @@ pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
31963249}
31973250
31983251pub 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);
3252 const zcu = pt.zcu;
3253 if (float_type.zigTypeTag(zcu) == .Vector) {
3254 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3255 const scalar_ty = float_type.scalarType(zcu);
32033256 for (result_data, 0..) |*scalar, i| {
32043257 const elem_val = try val.elemValue(pt, i);
32053258 scalar.* = (try expScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3213,14 +3266,14 @@ pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
32133266}
32143267
32153268pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3216 const mod = pt.zcu;
3217 const target = mod.getTarget();
3269 const zcu = pt.zcu;
3270 const target = zcu.getTarget();
32183271 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)) },
3272 16 => .{ .f16 = @exp(val.toFloat(f16, zcu)) },
3273 32 => .{ .f32 = @exp(val.toFloat(f32, zcu)) },
3274 64 => .{ .f64 = @exp(val.toFloat(f64, zcu)) },
3275 80 => .{ .f80 = @exp(val.toFloat(f80, zcu)) },
3276 128 => .{ .f128 = @exp(val.toFloat(f128, zcu)) },
32243277 else => unreachable,
32253278 };
32263279 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3230,10 +3283,10 @@ pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
32303283}
32313284
32323285pub 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);
3286 const zcu = pt.zcu;
3287 if (float_type.zigTypeTag(zcu) == .Vector) {
3288 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3289 const scalar_ty = float_type.scalarType(zcu);
32373290 for (result_data, 0..) |*scalar, i| {
32383291 const elem_val = try val.elemValue(pt, i);
32393292 scalar.* = (try exp2Scalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3247,14 +3300,14 @@ pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
32473300}
32483301
32493302pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3250 const mod = pt.zcu;
3251 const target = mod.getTarget();
3303 const zcu = pt.zcu;
3304 const target = zcu.getTarget();
32523305 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)) },
3306 16 => .{ .f16 = @exp2(val.toFloat(f16, zcu)) },
3307 32 => .{ .f32 = @exp2(val.toFloat(f32, zcu)) },
3308 64 => .{ .f64 = @exp2(val.toFloat(f64, zcu)) },
3309 80 => .{ .f80 = @exp2(val.toFloat(f80, zcu)) },
3310 128 => .{ .f128 = @exp2(val.toFloat(f128, zcu)) },
32583311 else => unreachable,
32593312 };
32603313 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3264,10 +3317,10 @@ pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
32643317}
32653318
32663319pub 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);
3320 const zcu = pt.zcu;
3321 if (float_type.zigTypeTag(zcu) == .Vector) {
3322 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3323 const scalar_ty = float_type.scalarType(zcu);
32713324 for (result_data, 0..) |*scalar, i| {
32723325 const elem_val = try val.elemValue(pt, i);
32733326 scalar.* = (try logScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3281,14 +3334,14 @@ pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
32813334}
32823335
32833336pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3284 const mod = pt.zcu;
3285 const target = mod.getTarget();
3337 const zcu = pt.zcu;
3338 const target = zcu.getTarget();
32863339 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)) },
3340 16 => .{ .f16 = @log(val.toFloat(f16, zcu)) },
3341 32 => .{ .f32 = @log(val.toFloat(f32, zcu)) },
3342 64 => .{ .f64 = @log(val.toFloat(f64, zcu)) },
3343 80 => .{ .f80 = @log(val.toFloat(f80, zcu)) },
3344 128 => .{ .f128 = @log(val.toFloat(f128, zcu)) },
32923345 else => unreachable,
32933346 };
32943347 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3298,10 +3351,10 @@ pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
32983351}
32993352
33003353pub 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);
3354 const zcu = pt.zcu;
3355 if (float_type.zigTypeTag(zcu) == .Vector) {
3356 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3357 const scalar_ty = float_type.scalarType(zcu);
33053358 for (result_data, 0..) |*scalar, i| {
33063359 const elem_val = try val.elemValue(pt, i);
33073360 scalar.* = (try log2Scalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3315,14 +3368,14 @@ pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
33153368}
33163369
33173370pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3318 const mod = pt.zcu;
3319 const target = mod.getTarget();
3371 const zcu = pt.zcu;
3372 const target = zcu.getTarget();
33203373 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)) },
3374 16 => .{ .f16 = @log2(val.toFloat(f16, zcu)) },
3375 32 => .{ .f32 = @log2(val.toFloat(f32, zcu)) },
3376 64 => .{ .f64 = @log2(val.toFloat(f64, zcu)) },
3377 80 => .{ .f80 = @log2(val.toFloat(f80, zcu)) },
3378 128 => .{ .f128 = @log2(val.toFloat(f128, zcu)) },
33263379 else => unreachable,
33273380 };
33283381 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3332,10 +3385,10 @@ pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
33323385}
33333386
33343387pub 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);
3388 const zcu = pt.zcu;
3389 if (float_type.zigTypeTag(zcu) == .Vector) {
3390 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3391 const scalar_ty = float_type.scalarType(zcu);
33393392 for (result_data, 0..) |*scalar, i| {
33403393 const elem_val = try val.elemValue(pt, i);
33413394 scalar.* = (try log10Scalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3349,14 +3402,14 @@ pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
33493402}
33503403
33513404pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3352 const mod = pt.zcu;
3353 const target = mod.getTarget();
3405 const zcu = pt.zcu;
3406 const target = zcu.getTarget();
33543407 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)) },
3408 16 => .{ .f16 = @log10(val.toFloat(f16, zcu)) },
3409 32 => .{ .f32 = @log10(val.toFloat(f32, zcu)) },
3410 64 => .{ .f64 = @log10(val.toFloat(f64, zcu)) },
3411 80 => .{ .f80 = @log10(val.toFloat(f80, zcu)) },
3412 128 => .{ .f128 = @log10(val.toFloat(f128, zcu)) },
33603413 else => unreachable,
33613414 };
33623415 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3366,10 +3419,10 @@ pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
33663419}
33673420
33683421pub 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);
3422 const zcu = pt.zcu;
3423 if (ty.zigTypeTag(zcu) == .Vector) {
3424 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
3425 const scalar_ty = ty.scalarType(zcu);
33733426 for (result_data, 0..) |*scalar, i| {
33743427 const elem_val = try val.elemValue(pt, i);
33753428 scalar.* = (try absScalar(elem_val, scalar_ty, pt, arena)).toIntern();
......@@ -3383,30 +3436,30 @@ pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
33833436}
33843437
33853438pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allocator.Error!Value {
3386 const mod = pt.zcu;
3387 switch (ty.zigTypeTag(mod)) {
3439 const zcu = pt.zcu;
3440 switch (ty.zigTypeTag(zcu)) {
33883441 .Int => {
33893442 var buffer: Value.BigIntSpace = undefined;
3390 var operand_bigint = try val.toBigInt(&buffer, pt).toManaged(arena);
3443 var operand_bigint = try val.toBigInt(&buffer, zcu).toManaged(arena);
33913444 operand_bigint.abs();
33923445
33933446 return pt.intValue_big(try ty.toUnsigned(pt), operand_bigint.toConst());
33943447 },
33953448 .ComptimeInt => {
33963449 var buffer: Value.BigIntSpace = undefined;
3397 var operand_bigint = try val.toBigInt(&buffer, pt).toManaged(arena);
3450 var operand_bigint = try val.toBigInt(&buffer, zcu).toManaged(arena);
33983451 operand_bigint.abs();
33993452
34003453 return pt.intValue_big(ty, operand_bigint.toConst());
34013454 },
34023455 .ComptimeFloat, .Float => {
3403 const target = mod.getTarget();
3456 const target = zcu.getTarget();
34043457 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)) },
3458 16 => .{ .f16 = @abs(val.toFloat(f16, zcu)) },
3459 32 => .{ .f32 = @abs(val.toFloat(f32, zcu)) },
3460 64 => .{ .f64 = @abs(val.toFloat(f64, zcu)) },
3461 80 => .{ .f80 = @abs(val.toFloat(f80, zcu)) },
3462 128 => .{ .f128 = @abs(val.toFloat(f128, zcu)) },
34103463 else => unreachable,
34113464 };
34123465 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3419,10 +3472,10 @@ pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allo
34193472}
34203473
34213474pub 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);
3475 const zcu = pt.zcu;
3476 if (float_type.zigTypeTag(zcu) == .Vector) {
3477 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3478 const scalar_ty = float_type.scalarType(zcu);
34263479 for (result_data, 0..) |*scalar, i| {
34273480 const elem_val = try val.elemValue(pt, i);
34283481 scalar.* = (try floorScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3436,14 +3489,14 @@ pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
34363489}
34373490
34383491pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3439 const mod = pt.zcu;
3440 const target = mod.getTarget();
3492 const zcu = pt.zcu;
3493 const target = zcu.getTarget();
34413494 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)) },
3495 16 => .{ .f16 = @floor(val.toFloat(f16, zcu)) },
3496 32 => .{ .f32 = @floor(val.toFloat(f32, zcu)) },
3497 64 => .{ .f64 = @floor(val.toFloat(f64, zcu)) },
3498 80 => .{ .f80 = @floor(val.toFloat(f80, zcu)) },
3499 128 => .{ .f128 = @floor(val.toFloat(f128, zcu)) },
34473500 else => unreachable,
34483501 };
34493502 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3453,10 +3506,10 @@ pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
34533506}
34543507
34553508pub 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);
3509 const zcu = pt.zcu;
3510 if (float_type.zigTypeTag(zcu) == .Vector) {
3511 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3512 const scalar_ty = float_type.scalarType(zcu);
34603513 for (result_data, 0..) |*scalar, i| {
34613514 const elem_val = try val.elemValue(pt, i);
34623515 scalar.* = (try ceilScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3470,14 +3523,14 @@ pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
34703523}
34713524
34723525pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3473 const mod = pt.zcu;
3474 const target = mod.getTarget();
3526 const zcu = pt.zcu;
3527 const target = zcu.getTarget();
34753528 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)) },
3529 16 => .{ .f16 = @ceil(val.toFloat(f16, zcu)) },
3530 32 => .{ .f32 = @ceil(val.toFloat(f32, zcu)) },
3531 64 => .{ .f64 = @ceil(val.toFloat(f64, zcu)) },
3532 80 => .{ .f80 = @ceil(val.toFloat(f80, zcu)) },
3533 128 => .{ .f128 = @ceil(val.toFloat(f128, zcu)) },
34813534 else => unreachable,
34823535 };
34833536 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3487,10 +3540,10 @@ pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
34873540}
34883541
34893542pub 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);
3543 const zcu = pt.zcu;
3544 if (float_type.zigTypeTag(zcu) == .Vector) {
3545 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3546 const scalar_ty = float_type.scalarType(zcu);
34943547 for (result_data, 0..) |*scalar, i| {
34953548 const elem_val = try val.elemValue(pt, i);
34963549 scalar.* = (try roundScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3504,14 +3557,14 @@ pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
35043557}
35053558
35063559pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3507 const mod = pt.zcu;
3508 const target = mod.getTarget();
3560 const zcu = pt.zcu;
3561 const target = zcu.getTarget();
35093562 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)) },
3563 16 => .{ .f16 = @round(val.toFloat(f16, zcu)) },
3564 32 => .{ .f32 = @round(val.toFloat(f32, zcu)) },
3565 64 => .{ .f64 = @round(val.toFloat(f64, zcu)) },
3566 80 => .{ .f80 = @round(val.toFloat(f80, zcu)) },
3567 128 => .{ .f128 = @round(val.toFloat(f128, zcu)) },
35153568 else => unreachable,
35163569 };
35173570 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3521,10 +3574,10 @@ pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
35213574}
35223575
35233576pub 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);
3577 const zcu = pt.zcu;
3578 if (float_type.zigTypeTag(zcu) == .Vector) {
3579 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3580 const scalar_ty = float_type.scalarType(zcu);
35283581 for (result_data, 0..) |*scalar, i| {
35293582 const elem_val = try val.elemValue(pt, i);
35303583 scalar.* = (try truncScalar(elem_val, scalar_ty, pt)).toIntern();
......@@ -3538,14 +3591,14 @@ pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
35383591}
35393592
35403593pub fn truncScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3541 const mod = pt.zcu;
3542 const target = mod.getTarget();
3594 const zcu = pt.zcu;
3595 const target = zcu.getTarget();
35433596 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)) },
3597 16 => .{ .f16 = @trunc(val.toFloat(f16, zcu)) },
3598 32 => .{ .f32 = @trunc(val.toFloat(f32, zcu)) },
3599 64 => .{ .f64 = @trunc(val.toFloat(f64, zcu)) },
3600 80 => .{ .f80 = @trunc(val.toFloat(f80, zcu)) },
3601 128 => .{ .f128 = @trunc(val.toFloat(f128, zcu)) },
35493602 else => unreachable,
35503603 };
35513604 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3562,10 +3615,10 @@ pub fn mulAdd(
35623615 arena: Allocator,
35633616 pt: Zcu.PerThread,
35643617) !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);
3618 const zcu = pt.zcu;
3619 if (float_type.zigTypeTag(zcu) == .Vector) {
3620 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3621 const scalar_ty = float_type.scalarType(zcu);
35693622 for (result_data, 0..) |*scalar, i| {
35703623 const mulend1_elem = try mulend1.elemValue(pt, i);
35713624 const mulend2_elem = try mulend2.elemValue(pt, i);
......@@ -3587,14 +3640,14 @@ pub fn mulAddScalar(
35873640 addend: Value,
35883641 pt: Zcu.PerThread,
35893642) Allocator.Error!Value {
3590 const mod = pt.zcu;
3591 const target = mod.getTarget();
3643 const zcu = pt.zcu;
3644 const target = zcu.getTarget();
35923645 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)) },
3646 16 => .{ .f16 = @mulAdd(f16, mulend1.toFloat(f16, zcu), mulend2.toFloat(f16, zcu), addend.toFloat(f16, zcu)) },
3647 32 => .{ .f32 = @mulAdd(f32, mulend1.toFloat(f32, zcu), mulend2.toFloat(f32, zcu), addend.toFloat(f32, zcu)) },
3648 64 => .{ .f64 = @mulAdd(f64, mulend1.toFloat(f64, zcu), mulend2.toFloat(f64, zcu), addend.toFloat(f64, zcu)) },
3649 80 => .{ .f80 = @mulAdd(f80, mulend1.toFloat(f80, zcu), mulend2.toFloat(f80, zcu), addend.toFloat(f80, zcu)) },
3650 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, zcu), mulend2.toFloat(f128, zcu), addend.toFloat(f128, zcu)) },
35983651 else => unreachable,
35993652 };
36003653 return Value.fromInterned(try pt.intern(.{ .float = .{
......@@ -3606,10 +3659,11 @@ pub fn mulAddScalar(
36063659/// If the value is represented in-memory as a series of bytes that all
36073660/// have the same value, return that byte value, otherwise null.
36083661pub fn hasRepeatedByteRepr(val: Value, ty: Type, pt: Zcu.PerThread) !?u8 {
3609 const abi_size = std.math.cast(usize, ty.abiSize(pt)) orelse return null;
3662 const zcu = pt.zcu;
3663 const abi_size = std.math.cast(usize, ty.abiSize(zcu)) orelse return null;
36103664 assert(abi_size >= 1);
3611 const byte_buffer = try pt.zcu.gpa.alloc(u8, abi_size);
3612 defer pt.zcu.gpa.free(byte_buffer);
3665 const byte_buffer = try zcu.gpa.alloc(u8, abi_size);
3666 defer zcu.gpa.free(byte_buffer);
36133667
36143668 writeToMemory(val, ty, pt, byte_buffer) catch |err| switch (err) {
36153669 error.OutOfMemory => return error.OutOfMemory,
......@@ -3754,15 +3808,15 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
37543808 // `field_align` may be `.none` to represent the natural alignment of `field_ty`, but is not necessarily.
37553809 const field_ty: Type, const field_align: InternPool.Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {
37563810 .Struct => field: {
3757 const field_ty = aggregate_ty.structFieldType(field_idx, zcu);
3811 const field_ty = aggregate_ty.fieldType(field_idx, zcu);
37583812 switch (aggregate_ty.containerLayout(zcu)) {
3759 .auto => break :field .{ field_ty, try aggregate_ty.structFieldAlignAdvanced(@intCast(field_idx), pt, .sema) },
3813 .auto => break :field .{ field_ty, try aggregate_ty.fieldAlignmentSema(field_idx, pt) },
37603814 .@"extern" => {
37613815 // Well-defined layout, so just offset the pointer appropriately.
3762 const byte_off = aggregate_ty.structFieldOffset(field_idx, pt);
3816 const byte_off = aggregate_ty.structFieldOffset(field_idx, zcu);
37633817 const field_align = a: {
37643818 const parent_align = if (parent_ptr_info.flags.alignment == .none) pa: {
3765 break :pa (try aggregate_ty.abiAlignmentAdvanced(pt, .sema)).scalar;
3819 break :pa try aggregate_ty.abiAlignmentSema(pt);
37663820 } else parent_ptr_info.flags.alignment;
37673821 break :a InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(byte_off)));
37683822 };
......@@ -3781,7 +3835,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
37813835 new.packed_offset = packed_offset;
37823836 new.child = field_ty.toIntern();
37833837 if (new.flags.alignment == .none) {
3784 new.flags.alignment = (try aggregate_ty.abiAlignmentAdvanced(pt, .sema)).scalar;
3838 new.flags.alignment = try aggregate_ty.abiAlignmentSema(pt);
37853839 }
37863840 break :info new;
37873841 });
......@@ -3807,7 +3861,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38073861 const union_obj = zcu.typeToUnion(aggregate_ty).?;
38083862 const field_ty = Type.fromInterned(union_obj.field_types.get(&zcu.intern_pool)[field_idx]);
38093863 switch (aggregate_ty.containerLayout(zcu)) {
3810 .auto => break :field .{ field_ty, try aggregate_ty.structFieldAlignAdvanced(@intCast(field_idx), pt, .sema) },
3864 .auto => break :field .{ field_ty, try aggregate_ty.fieldAlignmentSema(field_idx, pt) },
38113865 .@"extern" => {
38123866 // Point to the same address.
38133867 const result_ty = try pt.ptrTypeSema(info: {
......@@ -3820,17 +3874,17 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38203874 .@"packed" => {
38213875 // If the field has an ABI size matching its bit size, then we can continue to use a
38223876 // 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)) {
3877 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)) {
38243878 // We must offset the pointer on big-endian targets, since the bits of packed memory don't align nicely.
38253879 const byte_offset = switch (zcu.getTarget().cpu.arch.endian()) {
38263880 .little => 0,
3827 .big => (try aggregate_ty.abiSizeAdvanced(pt, .sema)).scalar - (try field_ty.abiSizeAdvanced(pt, .sema)).scalar,
3881 .big => (try aggregate_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar - (try field_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar,
38283882 };
38293883 const result_ty = try pt.ptrTypeSema(info: {
38303884 var new = parent_ptr_info;
38313885 new.child = field_ty.toIntern();
38323886 new.flags.alignment = InternPool.Alignment.fromLog2Units(
3833 @ctz(byte_offset | (try parent_ptr_ty.ptrAlignmentAdvanced(pt, .sema)).toByteUnits().?),
3887 @ctz(byte_offset | (try parent_ptr_ty.ptrAlignmentSema(pt)).toByteUnits().?),
38343888 );
38353889 break :info new;
38363890 });
......@@ -3841,7 +3895,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38413895 var new = parent_ptr_info;
38423896 new.child = field_ty.toIntern();
38433897 if (new.packed_offset.host_size == 0) {
3844 new.packed_offset.host_size = @intCast(((try aggregate_ty.bitSizeAdvanced(pt, .sema)) + 7) / 8);
3898 new.packed_offset.host_size = @intCast(((try aggregate_ty.bitSizeSema(pt)) + 7) / 8);
38453899 assert(new.packed_offset.bit_offset == 0);
38463900 }
38473901 break :info new;
......@@ -3854,8 +3908,8 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38543908 .Pointer => field_ty: {
38553909 assert(aggregate_ty.isSlice(zcu));
38563910 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) },
3911 Value.slice_ptr_index => .{ aggregate_ty.slicePtrFieldType(zcu), Type.usize.abiAlignment(zcu) },
3912 Value.slice_len_index => .{ Type.usize, Type.usize.abiAlignment(zcu) },
38593913 else => unreachable,
38603914 };
38613915 },
......@@ -3863,7 +3917,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
38633917 };
38643918
38653919 const new_align: InternPool.Alignment = if (parent_ptr_info.flags.alignment != .none) a: {
3866 const ty_align = (try field_ty.abiAlignmentAdvanced(pt, .sema)).scalar;
3920 const ty_align = (try field_ty.abiAlignmentInner(.sema, zcu, pt.tid)).scalar;
38673921 const true_field_align = if (field_align == .none) ty_align else field_align;
38683922 const new_align = true_field_align.min(parent_ptr_info.flags.alignment);
38693923 if (new_align == ty_align) break :a .none;
......@@ -3919,21 +3973,21 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value
39193973
39203974 const strat: PtrStrat = switch (parent_ptr_ty.ptrSize(zcu)) {
39213975 .One => switch (elem_ty.zigTypeTag(zcu)) {
3922 .Vector => .{ .offset = field_idx * @divExact(try elem_ty.childType(zcu).bitSizeAdvanced(pt, .sema), 8) },
3976 .Vector => .{ .offset = field_idx * @divExact(try elem_ty.childType(zcu).bitSizeSema(pt), 8) },
39233977 .Array => strat: {
39243978 const arr_elem_ty = elem_ty.childType(zcu);
3925 if (try arr_elem_ty.comptimeOnlyAdvanced(pt, .sema)) {
3979 if (try arr_elem_ty.comptimeOnlySema(pt)) {
39263980 break :strat .{ .elem_ptr = arr_elem_ty };
39273981 }
3928 break :strat .{ .offset = field_idx * (try arr_elem_ty.abiSizeAdvanced(pt, .sema)).scalar };
3982 break :strat .{ .offset = field_idx * (try arr_elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar };
39293983 },
39303984 else => unreachable,
39313985 },
39323986
3933 .Many, .C => if (try elem_ty.comptimeOnlyAdvanced(pt, .sema))
3987 .Many, .C => if (try elem_ty.comptimeOnlySema(pt))
39343988 .{ .elem_ptr = elem_ty }
39353989 else
3936 .{ .offset = field_idx * (try elem_ty.abiSizeAdvanced(pt, .sema)).scalar },
3990 .{ .offset = field_idx * (try elem_ty.abiSizeInner(.sema, zcu, pt.tid)).scalar },
39373991
39383992 .Slice => unreachable,
39393993 };
......@@ -4142,22 +4196,32 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
41424196 const base_ptr_ty = base_ptr.typeOf(zcu);
41434197 const agg_ty = base_ptr_ty.childType(zcu);
41444198 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) },
4199 .Struct => .{ agg_ty.fieldType(@intCast(field.index), zcu), try agg_ty.fieldAlignmentInner(
4200 @intCast(field.index),
4201 if (have_sema) .sema else .normal,
4202 pt.zcu,
4203 if (have_sema) pt.tid else {},
4204 ) },
4205 .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.fieldAlignmentInner(
4206 @intCast(field.index),
4207 if (have_sema) .sema else .normal,
4208 pt.zcu,
4209 if (have_sema) pt.tid else {},
4210 ) },
41474211 .Pointer => .{ switch (field.index) {
41484212 Value.slice_ptr_index => agg_ty.slicePtrFieldType(zcu),
41494213 Value.slice_len_index => Type.usize,
41504214 else => unreachable,
4151 }, Type.usize.abiAlignment(pt) },
4215 }, Type.usize.abiAlignment(zcu) },
41524216 else => unreachable,
41534217 };
4154 const base_align = base_ptr_ty.ptrAlignment(pt);
4218 const base_align = base_ptr_ty.ptrAlignment(zcu);
41554219 const result_align = field_align.minStrict(base_align);
41564220 const result_ty = try pt.ptrType(.{
41574221 .child = field_ty.toIntern(),
41584222 .flags = flags: {
41594223 var flags = base_ptr_ty.ptrInfo(zcu).flags;
4160 if (result_align == field_ty.abiAlignment(pt)) {
4224 if (result_align == field_ty.abiAlignment(zcu)) {
41614225 flags.alignment = .none;
41624226 } else {
41634227 flags.alignment = result_align;
......@@ -4198,7 +4262,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
41984262 }
41994263
42004264 const need_child = Type.fromInterned(ptr.ty).childType(zcu);
4201 if (need_child.comptimeOnly(pt)) {
4265 if (need_child.comptimeOnly(zcu)) {
42024266 // No refinement can happen - this pointer is presumably invalid.
42034267 // Just offset it.
42044268 const parent = try arena.create(PointerDeriveStep);
......@@ -4209,7 +4273,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42094273 .new_ptr_ty = Type.fromInterned(ptr.ty),
42104274 } };
42114275 }
4212 const need_bytes = need_child.abiSize(pt);
4276 const need_bytes = need_child.abiSize(zcu);
42134277
42144278 var cur_derive = base_derive;
42154279 var cur_offset = ptr.byte_offset;
......@@ -4248,7 +4312,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42484312
42494313 .Array => {
42504314 const elem_ty = cur_ty.childType(zcu);
4251 const elem_size = elem_ty.abiSize(pt);
4315 const elem_size = elem_ty.abiSize(zcu);
42524316 const start_idx = cur_offset / elem_size;
42534317 const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;
42544318 if (end_idx == start_idx + 1) {
......@@ -4278,12 +4342,12 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42784342 .Struct => switch (cur_ty.containerLayout(zcu)) {
42794343 .auto, .@"packed" => break,
42804344 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
4281 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);
4345 const field_ty = cur_ty.fieldType(field_idx, zcu);
4346 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
4347 const end_off = start_off + field_ty.abiSize(zcu);
42844348 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
42854349 const old_ptr_ty = try cur_derive.ptrType(pt);
4286 const parent_align = old_ptr_ty.ptrAlignment(pt);
4350 const parent_align = old_ptr_ty.ptrAlignment(zcu);
42874351 const field_align = InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(start_off)));
42884352 const parent = try arena.create(PointerDeriveStep);
42894353 parent.* = cur_derive;
......@@ -4291,7 +4355,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42914355 .child = field_ty.toIntern(),
42924356 .flags = flags: {
42934357 var flags = old_ptr_ty.ptrInfo(zcu).flags;
4294 if (field_align == field_ty.abiAlignment(pt)) {
4358 if (field_align == field_ty.abiAlignment(zcu)) {
42954359 flags.alignment = .none;
42964360 } else {
42974361 flags.alignment = field_align;
......@@ -4325,13 +4389,17 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
43254389 } };
43264390}
43274391
4328pub fn resolveLazy(val: Value, arena: Allocator, pt: Zcu.PerThread) Zcu.SemaError!Value {
4392pub fn resolveLazy(
4393 val: Value,
4394 arena: Allocator,
4395 pt: Zcu.PerThread,
4396) Zcu.SemaError!Value {
43294397 switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
43304398 .int => |int| switch (int.storage) {
43314399 .u64, .i64, .big_int => return val,
43324400 .lazy_align, .lazy_size => return pt.intValue(
43334401 Type.fromInterned(int.ty),
4334 (try val.getUnsignedIntAdvanced(pt, .sema)).?,
4402 try val.toUnsignedIntSema(pt),
43354403 ),
43364404 },
43374405 .slice => |slice| {
src/Zcu.zig+51-38
......@@ -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;
......@@ -2840,22 +2840,22 @@ pub fn addTypeReference(zcu: *Zcu, src_unit: AnalUnit, referenced_type: InternPo
28402840 gop.value_ptr.* = @intCast(ref_idx);
28412841}
28422842
2843pub fn errorSetBits(mod: *Zcu) u16 {
2844 if (mod.error_limit == 0) return 0;
2845 return @as(u16, std.math.log2_int(ErrorInt, mod.error_limit)) + 1;
2843pub fn errorSetBits(zcu: *const Zcu) u16 {
2844 if (zcu.error_limit == 0) return 0;
2845 return @as(u16, std.math.log2_int(ErrorInt, zcu.error_limit)) + 1;
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 }
......@@ -2923,10 +2923,23 @@ pub fn addGlobalAssembly(zcu: *Zcu, cau: InternPool.Cau.Index, source: []const u
29232923}
29242924
29252925pub const Feature = enum {
2926 /// When this feature is enabled, Sema will emit calls to `std.builtin.panic`
2927 /// for things like safety checks and unreachables. Otherwise traps will be emitted.
29262928 panic_fn,
2929 /// When this feature is enabled, Sema will emit calls to `std.builtin.panicUnwrapError`.
2930 /// This error message requires more advanced formatting, hence it being seperate from `panic_fn`.
2931 /// Otherwise traps will be emitted.
29272932 panic_unwrap_error,
2933 /// When this feature is enabled, Sema will emit calls to the more complex panic functions
2934 /// that use formatting to add detail to error messages. Similar to `panic_unwrap_error`.
2935 /// Otherwise traps will be emitted.
29282936 safety_check_formatted,
2937 /// When this feature is enabled, Sema will insert tracer functions for gathering a stack
2938 /// trace for error returns.
29292939 error_return_trace,
2940 /// When this feature is enabled, Sema will emit the `is_named_enum_value` AIR instructions
2941 /// and use it to check for corrupt switches. Backends currently need to implement their own
2942 /// logic to determine whether an enum value is in the set of named values.
29302943 is_named_enum_value,
29312944 error_set_has_value,
29322945 field_reordering,
......@@ -2965,11 +2978,11 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
29652978// TODO this function does not take into account CPU features, which can affect
29662979// this value. Audit this!
29672980pub fn atomicPtrAlignment(
2968 mod: *Zcu,
2981 zcu: *Zcu,
29692982 ty: Type,
29702983 diags: *AtomicPtrAlignmentDiagnostics,
29712984) AtomicPtrAlignmentError!Alignment {
2972 const target = mod.getTarget();
2985 const target = zcu.getTarget();
29732986 const max_atomic_bits: u16 = switch (target.cpu.arch) {
29742987 .avr,
29752988 .msp430,
......@@ -3039,8 +3052,8 @@ pub fn atomicPtrAlignment(
30393052 }
30403053 return .none;
30413054 }
3042 if (ty.isAbiInt(mod)) {
3043 const bit_count = ty.intInfo(mod).bits;
3055 if (ty.isAbiInt(zcu)) {
3056 const bit_count = ty.intInfo(zcu).bits;
30443057 if (bit_count > max_atomic_bits) {
30453058 diags.* = .{
30463059 .bits = bit_count,
......@@ -3050,7 +3063,7 @@ pub fn atomicPtrAlignment(
30503063 }
30513064 return .none;
30523065 }
3053 if (ty.isPtrAtRuntime(mod)) return .none;
3066 if (ty.isPtrAtRuntime(zcu)) return .none;
30543067 return error.BadType;
30553068}
30563069
......@@ -3058,45 +3071,45 @@ pub fn atomicPtrAlignment(
30583071/// * `@TypeOf(.{})`
30593072/// * A struct which has no fields (`struct {}`).
30603073/// * Not a struct.
3061pub fn typeToStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3074pub fn typeToStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {
30623075 if (ty.ip_index == .none) return null;
3063 const ip = &mod.intern_pool;
3076 const ip = &zcu.intern_pool;
30643077 return switch (ip.indexToKey(ty.ip_index)) {
30653078 .struct_type => ip.loadStructType(ty.ip_index),
30663079 else => null,
30673080 };
30683081}
30693082
3070pub fn typeToPackedStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3071 const s = mod.typeToStruct(ty) orelse return null;
3083pub fn typeToPackedStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3084 const s = zcu.typeToStruct(ty) orelse return null;
30723085 if (s.layout != .@"packed") return null;
30733086 return s;
30743087}
30753088
3076pub fn typeToUnion(mod: *Zcu, ty: Type) ?InternPool.LoadedUnionType {
3089pub fn typeToUnion(zcu: *const Zcu, ty: Type) ?InternPool.LoadedUnionType {
30773090 if (ty.ip_index == .none) return null;
3078 const ip = &mod.intern_pool;
3091 const ip = &zcu.intern_pool;
30793092 return switch (ip.indexToKey(ty.ip_index)) {
30803093 .union_type => ip.loadUnionType(ty.ip_index),
30813094 else => null,
30823095 };
30833096}
30843097
3085pub fn typeToFunc(mod: *Zcu, ty: Type) ?InternPool.Key.FuncType {
3098pub fn typeToFunc(zcu: *const Zcu, ty: Type) ?InternPool.Key.FuncType {
30863099 if (ty.ip_index == .none) return null;
3087 return mod.intern_pool.indexToFuncType(ty.toIntern());
3100 return zcu.intern_pool.indexToFuncType(ty.toIntern());
30883101}
30893102
30903103pub fn iesFuncIndex(zcu: *const Zcu, ies_index: InternPool.Index) InternPool.Index {
30913104 return zcu.intern_pool.iesFuncIndex(ies_index);
30923105}
30933106
3094pub fn funcInfo(mod: *Zcu, func_index: InternPool.Index) InternPool.Key.Func {
3095 return mod.intern_pool.indexToKey(func_index).func;
3107pub fn funcInfo(zcu: *const Zcu, func_index: InternPool.Index) InternPool.Key.Func {
3108 return zcu.intern_pool.indexToKey(func_index).func;
30963109}
30973110
3098pub fn toEnum(mod: *Zcu, comptime E: type, val: Value) E {
3099 return mod.intern_pool.toEnum(E, val.toIntern());
3111pub fn toEnum(zcu: *const Zcu, comptime E: type, val: Value) E {
3112 return zcu.intern_pool.toEnum(E, val.toIntern());
31003113}
31013114
31023115pub const UnionLayout = struct {
......@@ -3121,8 +3134,8 @@ pub const UnionLayout = struct {
31213134};
31223135
31233136/// 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;
3137pub fn unionTagFieldIndex(zcu: *const Zcu, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
3138 const ip = &zcu.intern_pool;
31263139 if (enum_tag.toIntern() == .none) return null;
31273140 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);
31283141 return loaded_union.loadTagType(ip).tagValueIndex(ip, enum_tag.toIntern());
......@@ -3348,7 +3361,7 @@ pub fn resolveReferences(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolve
33483361 return result;
33493362}
33503363
3351pub fn fileByIndex(zcu: *Zcu, file_index: File.Index) *File {
3364pub fn fileByIndex(zcu: *const Zcu, file_index: File.Index) *File {
33523365 return zcu.intern_pool.filePtr(file_index);
33533366}
33543367
src/Zcu/PerThread.zig+32-172
......@@ -1326,7 +1326,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
13261326 try decl_ty.resolveFully(pt);
13271327 }
13281328
1329 if (!resolve_type or !decl_ty.hasRuntimeBits(pt)) {
1329 if (!resolve_type or !decl_ty.hasRuntimeBits(zcu)) {
13301330 if (zcu.comp.config.use_llvm) break :queue_codegen;
13311331 if (file.mod.strip) break :queue_codegen;
13321332 }
......@@ -1555,8 +1555,8 @@ pub fn embedFile(
15551555 import_string: []const u8,
15561556 src_loc: Zcu.LazySrcLoc,
15571557) !InternPool.Index {
1558 const mod = pt.zcu;
1559 const gpa = mod.gpa;
1558 const zcu = pt.zcu;
1559 const gpa = zcu.gpa;
15601560
15611561 if (cur_file.mod.deps.get(import_string)) |pkg| {
15621562 const resolved_path = try std.fs.path.resolve(gpa, &.{
......@@ -1567,9 +1567,9 @@ pub fn embedFile(
15671567 var keep_resolved_path = false;
15681568 defer if (!keep_resolved_path) gpa.free(resolved_path);
15691569
1570 const gop = try mod.embed_table.getOrPut(gpa, resolved_path);
1570 const gop = try zcu.embed_table.getOrPut(gpa, resolved_path);
15711571 errdefer {
1572 assert(std.mem.eql(u8, mod.embed_table.pop().key, resolved_path));
1572 assert(std.mem.eql(u8, zcu.embed_table.pop().key, resolved_path));
15731573 keep_resolved_path = false;
15741574 }
15751575 if (gop.found_existing) return gop.value_ptr.*.val;
......@@ -1594,9 +1594,9 @@ pub fn embedFile(
15941594 var keep_resolved_path = false;
15951595 defer if (!keep_resolved_path) gpa.free(resolved_path);
15961596
1597 const gop = try mod.embed_table.getOrPut(gpa, resolved_path);
1597 const gop = try zcu.embed_table.getOrPut(gpa, resolved_path);
15981598 errdefer {
1599 assert(std.mem.eql(u8, mod.embed_table.pop().key, resolved_path));
1599 assert(std.mem.eql(u8, zcu.embed_table.pop().key, resolved_path));
16001600 keep_resolved_path = false;
16011601 }
16021602 if (gop.found_existing) return gop.value_ptr.*.val;
......@@ -1631,9 +1631,9 @@ fn newEmbedFile(
16311631 result: **Zcu.EmbedFile,
16321632 src_loc: Zcu.LazySrcLoc,
16331633) !InternPool.Index {
1634 const mod = pt.zcu;
1635 const gpa = mod.gpa;
1636 const ip = &mod.intern_pool;
1634 const zcu = pt.zcu;
1635 const gpa = zcu.gpa;
1636 const ip = &zcu.intern_pool;
16371637
16381638 const new_file = try gpa.create(Zcu.EmbedFile);
16391639 errdefer gpa.destroy(new_file);
......@@ -1655,7 +1655,7 @@ fn newEmbedFile(
16551655 if (actual_read != size) return error.UnexpectedEndOfFile;
16561656 bytes[0][size] = 0;
16571657
1658 const comp = mod.comp;
1658 const comp = zcu.comp;
16591659 switch (comp.cache_use) {
16601660 .whole => |whole| if (whole.cache_manifest) |man| {
16611661 const copied_resolved_path = try gpa.dupe(u8, resolved_path);
......@@ -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}
......@@ -2857,9 +2857,9 @@ pub fn errorSetFromUnsortedNames(
28572857
28582858/// Supports only pointers, not pointer-like optionals.
28592859pub fn ptrIntValue(pt: Zcu.PerThread, ty: Type, x: u64) Allocator.Error!Value {
2860 const mod = pt.zcu;
2861 assert(ty.zigTypeTag(mod) == .Pointer and !ty.isSlice(mod));
2862 assert(x != 0 or ty.isAllowzeroPtr(mod));
2860 const zcu = pt.zcu;
2861 assert(ty.zigTypeTag(zcu) == .Pointer and !ty.isSlice(zcu));
2862 assert(x != 0 or ty.isAllowzeroPtr(zcu));
28632863 return Value.fromInterned(try pt.intern(.{ .ptr = .{
28642864 .ty = ty.toIntern(),
28652865 .base_addr = .int,
......@@ -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);
......@@ -3008,10 +3008,10 @@ pub fn intFittingRange(pt: Zcu.PerThread, min: Value, max: Value) !Type {
30083008/// twos-complement integer; otherwise in an unsigned integer.
30093009/// Asserts that `val` is not undef. If `val` is negative, asserts that `sign` is true.
30103010pub fn intBitsForValue(pt: Zcu.PerThread, val: Value, sign: bool) u16 {
3011 const mod = pt.zcu;
3012 assert(!val.isUndef(mod));
3011 const zcu = pt.zcu;
3012 assert(!val.isUndef(zcu));
30133013
3014 const key = mod.intern_pool.indexToKey(val.toIntern());
3014 const key = zcu.intern_pool.indexToKey(val.toIntern());
30153015 switch (key.int.storage) {
30163016 .i64 => |x| {
30173017 if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted) + @intFromBool(sign);
......@@ -3032,154 +3032,14 @@ 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
3107/// Returns 0 if the union is represented with 0 bits at runtime.
3108pub fn unionAbiAlignment(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionType) InternPool.Alignment {
3109 const mod = pt.zcu;
3110 const ip = &mod.intern_pool;
3111 const have_tag = loaded_union.flagsPtr(ip).runtime_tag.hasTag();
3112 var max_align: InternPool.Alignment = .none;
3113 if (have_tag) max_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(pt);
3114 for (loaded_union.field_types.get(ip), 0..) |field_ty, field_index| {
3115 if (!Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;
3116
3117 const field_align = mod.unionFieldNormalAlignment(loaded_union, @intCast(field_index));
3118 max_align = max_align.max(field_align);
3119 }
3120 return max_align;
3121}
3122
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
3149/// Returns the field alignment of a non-packed struct. Asserts the layout is not packed.
3150pub fn structFieldAlignment(
3151 pt: Zcu.PerThread,
3152 explicit_alignment: InternPool.Alignment,
3153 field_ty: Type,
3154 layout: std.builtin.Type.ContainerLayout,
3155) 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;
3181}
3182
31833043/// https://github.com/ziglang/zig/issues/17178 explored storing these bit offsets
31843044/// into the packed struct InternPool data rather than computing this on the
31853045/// fly, however it was found to perform worse when measured on real world
......@@ -3189,8 +3049,8 @@ pub fn structPackedFieldBitOffset(
31893049 struct_type: InternPool.LoadedStructType,
31903050 field_index: u32,
31913051) u16 {
3192 const mod = pt.zcu;
3193 const ip = &mod.intern_pool;
3052 const zcu = pt.zcu;
3053 const ip = &zcu.intern_pool;
31943054 assert(struct_type.layout == .@"packed");
31953055 assert(struct_type.haveLayout(ip));
31963056 var bit_sum: u64 = 0;
......@@ -3199,7 +3059,7 @@ pub fn structPackedFieldBitOffset(
31993059 return @intCast(bit_sum);
32003060 }
32013061 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3202 bit_sum += field_ty.bitSize(pt);
3062 bit_sum += field_ty.bitSize(zcu);
32033063 }
32043064 unreachable; // index out of bounds
32053065}
......@@ -3244,7 +3104,7 @@ pub fn navPtrType(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.
32443104 return pt.ptrType(.{
32453105 .child = ty.toIntern(),
32463106 .flags = .{
3247 .alignment = if (r.alignment == ty.abiAlignment(pt))
3107 .alignment = if (r.alignment == ty.abiAlignment(zcu))
32483108 .none
32493109 else
32503110 r.alignment,
......@@ -3274,7 +3134,7 @@ pub fn navAlignment(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) InternPo
32743134 const zcu = pt.zcu;
32753135 const r = zcu.intern_pool.getNav(nav_index).status.resolved;
32763136 if (r.alignment != .none) return r.alignment;
3277 return Value.fromInterned(r.val).typeOf(zcu).abiAlignment(pt);
3137 return Value.fromInterned(r.val).typeOf(zcu).abiAlignment(zcu);
32783138}
32793139
32803140/// 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.fieldType(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.fieldType(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.fieldType(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+14-14
......@@ -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,
......@@ -95,7 +95,7 @@ fn countFloats(ty: Type, zcu: *Zcu, maybe_float_bits: *?u16) u8 {
9595 var count: u8 = 0;
9696 var i: u32 = 0;
9797 while (i < fields_len) : (i += 1) {
98 const field_ty = ty.structFieldType(i, zcu);
98 const field_ty = ty.fieldType(i, zcu);
9999 const field_count = countFloats(field_ty, zcu, maybe_float_bits);
100100 if (field_count == invalid) return invalid;
101101 count += field_count;
......@@ -130,7 +130,7 @@ pub fn getFloatArrayType(ty: Type, zcu: *Zcu) ?Type {
130130 const fields_len = ty.structFieldCount(zcu);
131131 var i: u32 = 0;
132132 while (i < fields_len) : (i += 1) {
133 const field_ty = ty.structFieldType(i, zcu);
133 const field_ty = ty.fieldType(i, zcu);
134134 if (getFloatArrayType(field_ty, zcu)) |some| return some;
135135 }
136136 return null;
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.fieldType(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.fieldType(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.fieldType(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+22-22
......@@ -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.fieldType(i, zcu);
48 const field_alignment = ty.fieldAlignment(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 ty.fieldAlignment(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,
......@@ -141,7 +141,7 @@ fn countFloats(ty: Type, zcu: *Zcu, maybe_float_bits: *?u16) u32 {
141141 var count: u32 = 0;
142142 var i: u32 = 0;
143143 while (i < fields_len) : (i += 1) {
144 const field_ty = ty.structFieldType(i, zcu);
144 const field_ty = ty.fieldType(i, zcu);
145145 const field_count = countFloats(field_ty, zcu, maybe_float_bits);
146146 if (field_count == invalid) return invalid;
147147 count += field_count;
src/arch/riscv64/CodeGen.zig+168-161
......@@ -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),
......@@ -4571,11 +4576,11 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
45714576 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
45724577 const src_mcv = try func.resolveInst(operand);
45734578 const struct_ty = func.typeOf(operand);
4574 const field_ty = struct_ty.structFieldType(index, zcu);
4575 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;
4579 const field_ty = struct_ty.fieldType(index, zcu);
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,21 +7869,21 @@ 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| {
78757882 const elem_i: u32 = @intCast(elem_i_usize);
78767883 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
78777884
7878 const elem_ty = result_ty.structFieldType(elem_i, zcu);
7879 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(pt));
7885 const elem_ty = result_ty.fieldType(elem_i, zcu);
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);
......@@ -7909,8 +7916,8 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
79097916 } else for (elements, 0..) |elem, elem_i| {
79107917 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
79117918
7912 const elem_ty = result_ty.structFieldType(elem_i, zcu);
7913 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, pt));
7919 const elem_ty = result_ty.fieldType(elem_i, zcu);
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.fieldType(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+139-140
......@@ -365,8 +365,8 @@ pub fn generate(
365365
366366fn gen(self: *Self) !void {
367367 const pt = self.pt;
368 const mod = pt.zcu;
369 const cc = self.fn_type.fnCallingConvention(mod);
368 const zcu = pt.zcu;
369 const cc = self.fn_type.fnCallingConvention(zcu);
370370 if (cc != .Naked) {
371371 // TODO Finish function prologue and epilogue for sparc64.
372372
......@@ -494,8 +494,8 @@ fn gen(self: *Self) !void {
494494
495495fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
496496 const pt = self.pt;
497 const mod = pt.zcu;
498 const ip = &mod.intern_pool;
497 const zcu = pt.zcu;
498 const ip = &zcu.intern_pool;
499499 const air_tags = self.air.instructions.items(.tag);
500500
501501 for (body) |inst| {
......@@ -760,18 +760,18 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
760760 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
761761 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
762762 const pt = self.pt;
763 const mod = pt.zcu;
763 const zcu = pt.zcu;
764764 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
765765 const lhs = try self.resolveInst(extra.lhs);
766766 const rhs = try self.resolveInst(extra.rhs);
767767 const lhs_ty = self.typeOf(extra.lhs);
768768 const rhs_ty = self.typeOf(extra.rhs);
769769
770 switch (lhs_ty.zigTypeTag(mod)) {
770 switch (lhs_ty.zigTypeTag(zcu)) {
771771 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
772772 .Int => {
773 assert(lhs_ty.eql(rhs_ty, mod));
774 const int_info = lhs_ty.intInfo(mod);
773 assert(lhs_ty.eql(rhs_ty, zcu));
774 const int_info = lhs_ty.intInfo(zcu);
775775 switch (int_info.bits) {
776776 32, 64 => {
777777 // Only say yes if the operation is
......@@ -839,9 +839,9 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
839839
840840fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
841841 const pt = self.pt;
842 const mod = pt.zcu;
842 const zcu = pt.zcu;
843843 const vector_ty = self.typeOfIndex(inst);
844 const len = vector_ty.vectorLen(mod);
844 const len = vector_ty.vectorLen(zcu);
845845 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
846846 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
847847 const result: MCValue = res: {
......@@ -874,13 +874,13 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
874874
875875fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
876876 const pt = self.pt;
877 const mod = pt.zcu;
877 const zcu = pt.zcu;
878878 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
879879 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
880880 const ptr_ty = self.typeOf(ty_op.operand);
881881 const ptr = try self.resolveInst(ty_op.operand);
882 const array_ty = ptr_ty.childType(mod);
883 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));
882 const array_ty = ptr_ty.childType(zcu);
883 const array_len = @as(u32, @intCast(array_ty.arrayLen(zcu)));
884884 const ptr_bytes = 8;
885885 const stack_offset = try self.allocMem(inst, ptr_bytes * 2, .@"8");
886886 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -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,
......@@ -1304,11 +1305,11 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13041305 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len]));
13051306 const ty = self.typeOf(callee);
13061307 const pt = self.pt;
1307 const mod = pt.zcu;
1308 const ip = &mod.intern_pool;
1309 const fn_ty = switch (ty.zigTypeTag(mod)) {
1308 const zcu = pt.zcu;
1309 const ip = &zcu.intern_pool;
1310 const fn_ty = switch (ty.zigTypeTag(zcu)) {
13101311 .Fn => ty,
1311 .Pointer => ty.childType(mod),
1312 .Pointer => ty.childType(zcu),
13121313 else => unreachable,
13131314 };
13141315
......@@ -1360,7 +1361,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13601361 return self.fail("TODO implement calling bitcasted functions", .{});
13611362 },
13621363 } else {
1363 assert(ty.zigTypeTag(mod) == .Pointer);
1364 assert(ty.zigTypeTag(zcu) == .Pointer);
13641365 const mcv = try self.resolveInst(callee);
13651366 try self.genSetReg(ty, .o7, mcv);
13661367
......@@ -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,
......@@ -1635,13 +1636,9 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
16351636}
16361637
16371638fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {
1638 const pt = self.pt;
1639 const mod = pt.zcu;
16401639 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
16411640 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);
1642 const func = mod.funcInfo(extra.data.func);
16431641 // TODO emit debug info for function change
1644 _ = func;
16451642 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
16461643}
16471644
......@@ -1735,11 +1732,11 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
17351732 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
17361733
17371734 const pt = self.pt;
1738 const mod = pt.zcu;
1735 const zcu = pt.zcu;
17391736 const operand_ty = self.typeOf(ty_op.operand);
17401737 const operand = try self.resolveInst(ty_op.operand);
1741 const info_a = operand_ty.intInfo(mod);
1742 const info_b = self.typeOfIndex(inst).intInfo(mod);
1738 const info_a = operand_ty.intInfo(zcu);
1739 const info_b = self.typeOfIndex(inst).intInfo(zcu);
17431740 if (info_a.signedness != info_b.signedness)
17441741 return self.fail("TODO gen intcast sign safety in semantic analysis", .{});
17451742
......@@ -1797,16 +1794,16 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
17971794
17981795fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
17991796 const pt = self.pt;
1800 const mod = pt.zcu;
1797 const zcu = pt.zcu;
18011798 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
18021799 const elem_ty = self.typeOfIndex(inst);
1803 const elem_size = elem_ty.abiSize(pt);
1800 const elem_size = elem_ty.abiSize(zcu);
18041801 const result: MCValue = result: {
1805 if (!elem_ty.hasRuntimeBits(pt))
1802 if (!elem_ty.hasRuntimeBits(zcu))
18061803 break :result MCValue.none;
18071804
18081805 const ptr = try self.resolveInst(ty_op.operand);
1809 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(mod);
1806 const is_volatile = self.typeOf(ty_op.operand).isVolatilePtr(zcu);
18101807 if (self.liveness.isUnused(inst) and !is_volatile)
18111808 break :result MCValue.dead;
18121809
......@@ -2024,18 +2021,18 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
20242021 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
20252022 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
20262023 const pt = self.pt;
2027 const mod = pt.zcu;
2024 const zcu = pt.zcu;
20282025 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20292026 const lhs = try self.resolveInst(extra.lhs);
20302027 const rhs = try self.resolveInst(extra.rhs);
20312028 const lhs_ty = self.typeOf(extra.lhs);
20322029 const rhs_ty = self.typeOf(extra.rhs);
20332030
2034 switch (lhs_ty.zigTypeTag(mod)) {
2031 switch (lhs_ty.zigTypeTag(zcu)) {
20352032 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
20362033 .Int => {
2037 assert(lhs_ty.eql(rhs_ty, mod));
2038 const int_info = lhs_ty.intInfo(mod);
2034 assert(lhs_ty.eql(rhs_ty, zcu));
2035 const int_info = lhs_ty.intInfo(zcu);
20392036 switch (int_info.bits) {
20402037 1...32 => {
20412038 try self.spillConditionFlagsIfOccupied();
......@@ -2089,7 +2086,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
20892086fn airNot(self: *Self, inst: Air.Inst.Index) !void {
20902087 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
20912088 const pt = self.pt;
2092 const mod = pt.zcu;
2089 const zcu = pt.zcu;
20932090 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
20942091 const operand = try self.resolveInst(ty_op.operand);
20952092 const operand_ty = self.typeOf(ty_op.operand);
......@@ -2105,7 +2102,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
21052102 };
21062103 },
21072104 else => {
2108 switch (operand_ty.zigTypeTag(mod)) {
2105 switch (operand_ty.zigTypeTag(zcu)) {
21092106 .Bool => {
21102107 const op_reg = switch (operand) {
21112108 .register => |r| r,
......@@ -2139,7 +2136,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
21392136 },
21402137 .Vector => return self.fail("TODO bitwise not for vectors", .{}),
21412138 .Int => {
2142 const int_info = operand_ty.intInfo(mod);
2139 const int_info = operand_ty.intInfo(zcu);
21432140 if (int_info.bits <= 64) {
21442141 const op_reg = switch (operand) {
21452142 .register => |r| r,
......@@ -2322,17 +2319,17 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
23222319 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
23232320 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
23242321 const pt = self.pt;
2325 const mod = pt.zcu;
2322 const zcu = pt.zcu;
23262323 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
23272324 const lhs = try self.resolveInst(extra.lhs);
23282325 const rhs = try self.resolveInst(extra.rhs);
23292326 const lhs_ty = self.typeOf(extra.lhs);
23302327 const rhs_ty = self.typeOf(extra.rhs);
23312328
2332 switch (lhs_ty.zigTypeTag(mod)) {
2329 switch (lhs_ty.zigTypeTag(zcu)) {
23332330 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
23342331 .Int => {
2335 const int_info = lhs_ty.intInfo(mod);
2332 const int_info = lhs_ty.intInfo(zcu);
23362333 if (int_info.bits <= 64) {
23372334 try self.spillConditionFlagsIfOccupied();
23382335
......@@ -2428,7 +2425,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
24282425
24292426fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24302427 const pt = self.pt;
2431 const mod = pt.zcu;
2428 const zcu = pt.zcu;
24322429 const is_volatile = false; // TODO
24332430 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
24342431
......@@ -2438,10 +2435,10 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24382435 const index_mcv = try self.resolveInst(bin_op.rhs);
24392436
24402437 const slice_ty = self.typeOf(bin_op.lhs);
2441 const elem_ty = slice_ty.childType(mod);
2442 const elem_size = elem_ty.abiSize(pt);
2438 const elem_ty = slice_ty.childType(zcu);
2439 const elem_size = elem_ty.abiSize(zcu);
24432440
2444 const slice_ptr_field_type = slice_ty.slicePtrFieldType(mod);
2441 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
24452442
24462443 const index_lock: ?RegisterLock = if (index_mcv == .register)
24472444 self.register_manager.lockRegAssumeUnused(index_mcv.register)
......@@ -2553,10 +2550,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
25532550 const operand = extra.struct_operand;
25542551 const index = extra.field_index;
25552552 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2556 const pt = self.pt;
2553 const zcu = self.pt.zcu;
25572554 const mcv = try self.resolveInst(operand);
25582555 const struct_ty = self.typeOf(operand);
2559 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));
2556 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
25602557
25612558 switch (mcv) {
25622559 .dead, .unreach => unreachable,
......@@ -2687,13 +2684,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
26872684
26882685fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
26892686 const pt = self.pt;
2690 const mod = pt.zcu;
2687 const zcu = pt.zcu;
26912688 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
26922689 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
26932690 const error_union_ty = self.typeOf(ty_op.operand);
2694 const payload_ty = error_union_ty.errorUnionPayload(mod);
2691 const payload_ty = error_union_ty.errorUnionPayload(zcu);
26952692 const mcv = try self.resolveInst(ty_op.operand);
2696 if (!payload_ty.hasRuntimeBits(pt)) break :result mcv;
2693 if (!payload_ty.hasRuntimeBits(zcu)) break :result mcv;
26972694
26982695 return self.fail("TODO implement unwrap error union error for non-empty payloads", .{});
26992696 };
......@@ -2702,12 +2699,12 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27022699
27032700fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
27042701 const pt = self.pt;
2705 const mod = pt.zcu;
2702 const zcu = pt.zcu;
27062703 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
27072704 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
27082705 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;
2706 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2707 if (!payload_ty.hasRuntimeBits(zcu)) break :result MCValue.none;
27112708
27122709 return self.fail("TODO implement unwrap error union payload for non-empty payloads", .{});
27132710 };
......@@ -2717,13 +2714,13 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
27172714/// E to E!T
27182715fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
27192716 const pt = self.pt;
2720 const mod = pt.zcu;
2717 const zcu = pt.zcu;
27212718 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
27222719 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
27232720 const error_union_ty = ty_op.ty.toType();
2724 const payload_ty = error_union_ty.errorUnionPayload(mod);
2721 const payload_ty = error_union_ty.errorUnionPayload(zcu);
27252722 const mcv = try self.resolveInst(ty_op.operand);
2726 if (!payload_ty.hasRuntimeBits(pt)) break :result mcv;
2723 if (!payload_ty.hasRuntimeBits(zcu)) break :result mcv;
27272724
27282725 return self.fail("TODO implement wrap errunion error for non-empty payloads", .{});
27292726 };
......@@ -2744,7 +2741,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
27442741 const optional_ty = self.typeOfIndex(inst);
27452742
27462743 // Optional with a zero-bit payload type is just a boolean true
2747 if (optional_ty.abiSize(pt) == 1)
2744 if (optional_ty.abiSize(pt.zcu) == 1)
27482745 break :result MCValue{ .immediate = 1 };
27492746
27502747 return self.fail("TODO implement wrap optional for {}", .{self.target.cpu.arch});
......@@ -2779,10 +2776,10 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: Alignme
27792776/// Use a pointer instruction as the basis for allocating stack memory.
27802777fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
27812778 const pt = self.pt;
2782 const mod = pt.zcu;
2783 const elem_ty = self.typeOfIndex(inst).childType(mod);
2779 const zcu = pt.zcu;
2780 const elem_ty = self.typeOfIndex(inst).childType(zcu);
27842781
2785 if (!elem_ty.hasRuntimeBits(pt)) {
2782 if (!elem_ty.hasRuntimeBits(zcu)) {
27862783 // As this stack item will never be dereferenced at runtime,
27872784 // return the stack offset 0. Stack offset 0 will be where all
27882785 // zero-sized stack allocations live as non-zero-sized
......@@ -2790,21 +2787,22 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
27902787 return @as(u32, 0);
27912788 }
27922789
2793 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
2790 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
27942791 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
27952792 };
27962793 // TODO swap this for inst.ty.ptrAlign
2797 const abi_align = elem_ty.abiAlignment(pt);
2794 const abi_align = elem_ty.abiAlignment(zcu);
27982795 return self.allocMem(inst, abi_size, abi_align);
27992796}
28002797
28012798fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
28022799 const pt = self.pt;
2800 const zcu = pt.zcu;
28032801 const elem_ty = self.typeOfIndex(inst);
2804 const abi_size = math.cast(u32, elem_ty.abiSize(pt)) orelse {
2802 const abi_size = math.cast(u32, elem_ty.abiSize(zcu)) orelse {
28052803 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
28062804 };
2807 const abi_align = elem_ty.abiAlignment(pt);
2805 const abi_align = elem_ty.abiAlignment(zcu);
28082806 self.stack_align = self.stack_align.max(abi_align);
28092807
28102808 if (reg_ok) {
......@@ -2847,7 +2845,7 @@ fn binOp(
28472845 metadata: ?BinOpMetadata,
28482846) InnerError!MCValue {
28492847 const pt = self.pt;
2850 const mod = pt.zcu;
2848 const zcu = pt.zcu;
28512849 switch (tag) {
28522850 .add,
28532851 .sub,
......@@ -2857,12 +2855,12 @@ fn binOp(
28572855 .xor,
28582856 .cmp_eq,
28592857 => {
2860 switch (lhs_ty.zigTypeTag(mod)) {
2858 switch (lhs_ty.zigTypeTag(zcu)) {
28612859 .Float => return self.fail("TODO binary operations on floats", .{}),
28622860 .Vector => return self.fail("TODO binary operations on vectors", .{}),
28632861 .Int => {
2864 assert(lhs_ty.eql(rhs_ty, mod));
2865 const int_info = lhs_ty.intInfo(mod);
2862 assert(lhs_ty.eql(rhs_ty, zcu));
2863 const int_info = lhs_ty.intInfo(zcu);
28662864 if (int_info.bits <= 64) {
28672865 // Only say yes if the operation is
28682866 // commutative, i.e. we can swap both of the
......@@ -2931,10 +2929,10 @@ fn binOp(
29312929 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);
29322930
29332931 // Truncate if necessary
2934 switch (lhs_ty.zigTypeTag(mod)) {
2932 switch (lhs_ty.zigTypeTag(zcu)) {
29352933 .Vector => return self.fail("TODO binary operations on vectors", .{}),
29362934 .Int => {
2937 const int_info = lhs_ty.intInfo(mod);
2935 const int_info = lhs_ty.intInfo(zcu);
29382936 if (int_info.bits <= 64) {
29392937 const result_reg = result.register;
29402938 try self.truncRegister(result_reg, result_reg, int_info.signedness, int_info.bits);
......@@ -2948,11 +2946,11 @@ fn binOp(
29482946 },
29492947
29502948 .div_trunc => {
2951 switch (lhs_ty.zigTypeTag(mod)) {
2949 switch (lhs_ty.zigTypeTag(zcu)) {
29522950 .Vector => return self.fail("TODO binary operations on vectors", .{}),
29532951 .Int => {
2954 assert(lhs_ty.eql(rhs_ty, mod));
2955 const int_info = lhs_ty.intInfo(mod);
2952 assert(lhs_ty.eql(rhs_ty, zcu));
2953 const int_info = lhs_ty.intInfo(zcu);
29562954 if (int_info.bits <= 64) {
29572955 const rhs_immediate_ok = switch (tag) {
29582956 .div_trunc => rhs == .immediate and rhs.immediate <= std.math.maxInt(u12),
......@@ -2981,14 +2979,14 @@ fn binOp(
29812979 },
29822980
29832981 .ptr_add => {
2984 switch (lhs_ty.zigTypeTag(mod)) {
2982 switch (lhs_ty.zigTypeTag(zcu)) {
29852983 .Pointer => {
29862984 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),
2985 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
2986 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
2987 else => ptr_ty.childType(zcu),
29902988 };
2991 const elem_size = elem_ty.abiSize(pt);
2989 const elem_size = elem_ty.abiSize(zcu);
29922990
29932991 if (elem_size == 1) {
29942992 const base_tag: Mir.Inst.Tag = switch (tag) {
......@@ -3013,7 +3011,7 @@ fn binOp(
30133011 .bool_and,
30143012 .bool_or,
30153013 => {
3016 switch (lhs_ty.zigTypeTag(mod)) {
3014 switch (lhs_ty.zigTypeTag(zcu)) {
30173015 .Bool => {
30183016 assert(lhs != .immediate); // should have been handled by Sema
30193017 assert(rhs != .immediate); // should have been handled by Sema
......@@ -3043,10 +3041,10 @@ fn binOp(
30433041 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);
30443042
30453043 // Truncate if necessary
3046 switch (lhs_ty.zigTypeTag(mod)) {
3044 switch (lhs_ty.zigTypeTag(zcu)) {
30473045 .Vector => return self.fail("TODO binary operations on vectors", .{}),
30483046 .Int => {
3049 const int_info = lhs_ty.intInfo(mod);
3047 const int_info = lhs_ty.intInfo(zcu);
30503048 if (int_info.bits <= 64) {
30513049 // 32 and 64 bit operands doesn't need truncating
30523050 if (int_info.bits == 32 or int_info.bits == 64) return result;
......@@ -3065,10 +3063,10 @@ fn binOp(
30653063 .shl_exact,
30663064 .shr_exact,
30673065 => {
3068 switch (lhs_ty.zigTypeTag(mod)) {
3066 switch (lhs_ty.zigTypeTag(zcu)) {
30693067 .Vector => return self.fail("TODO binary operations on vectors", .{}),
30703068 .Int => {
3071 const int_info = lhs_ty.intInfo(mod);
3069 const int_info = lhs_ty.intInfo(zcu);
30723070 if (int_info.bits <= 64) {
30733071 const rhs_immediate_ok = rhs == .immediate;
30743072
......@@ -3388,8 +3386,8 @@ fn binOpRegister(
33883386fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
33893387 const block_data = self.blocks.getPtr(block).?;
33903388
3391 const pt = self.pt;
3392 if (self.typeOf(operand).hasRuntimeBits(pt)) {
3389 const zcu = self.pt.zcu;
3390 if (self.typeOf(operand).hasRuntimeBits(zcu)) {
33933391 const operand_mcv = try self.resolveInst(operand);
33943392 const block_mcv = block_data.mcv;
33953393 if (block_mcv == .none) {
......@@ -3509,17 +3507,17 @@ fn ensureProcessDeathCapacity(self: *Self, additional_count: usize) !void {
35093507/// Given an error union, returns the payload
35103508fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) !MCValue {
35113509 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)) {
3510 const zcu = pt.zcu;
3511 const err_ty = error_union_ty.errorUnionSet(zcu);
3512 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3513 if (err_ty.errorSetIsEmpty(zcu)) {
35163514 return error_union_mcv;
35173515 }
3518 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3516 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
35193517 return MCValue.none;
35203518 }
35213519
3522 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt)));
3520 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu)));
35233521 switch (error_union_mcv) {
35243522 .register => return self.fail("TODO errUnionPayload for registers", .{}),
35253523 .stack_offset => |off| {
......@@ -3731,6 +3729,7 @@ fn genLoadASI(self: *Self, value_reg: Register, addr_reg: Register, off_reg: Reg
37313729
37323730fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {
37333731 const pt = self.pt;
3732 const zcu = pt.zcu;
37343733 switch (mcv) {
37353734 .dead => unreachable,
37363735 .unreach, .none => return, // Nothing to do.
......@@ -3929,21 +3928,21 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
39293928 // The value is in memory at a hard-coded address.
39303929 // If the type is a pointer, it means the pointer address is at this memory location.
39313930 try self.genSetReg(ty, reg, .{ .immediate = addr });
3932 try self.genLoad(reg, reg, i13, 0, ty.abiSize(pt));
3931 try self.genLoad(reg, reg, i13, 0, ty.abiSize(zcu));
39333932 },
39343933 .stack_offset => |off| {
39353934 const real_offset = realStackOffset(off);
39363935 const simm13 = math.cast(i13, real_offset) orelse
39373936 return self.fail("TODO larger stack offsets: {}", .{real_offset});
3938 try self.genLoad(reg, .sp, i13, simm13, ty.abiSize(pt));
3937 try self.genLoad(reg, .sp, i13, simm13, ty.abiSize(zcu));
39393938 },
39403939 }
39413940}
39423941
39433942fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
39443943 const pt = self.pt;
3945 const mod = pt.zcu;
3946 const abi_size = ty.abiSize(pt);
3944 const zcu = pt.zcu;
3945 const abi_size = ty.abiSize(zcu);
39473946 switch (mcv) {
39483947 .dead => unreachable,
39493948 .unreach, .none => return, // Nothing to do.
......@@ -3951,7 +3950,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
39513950 if (!self.wantSafety())
39523951 return; // The already existing value will do just fine.
39533952 // TODO Upgrade this to a memset call when we have that available.
3954 switch (ty.abiSize(pt)) {
3953 switch (ty.abiSize(zcu)) {
39553954 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),
39563955 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),
39573956 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),
......@@ -3977,11 +3976,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
39773976 const reg_lock = self.register_manager.lockReg(rwo.reg);
39783977 defer if (reg_lock) |locked_reg| self.register_manager.unlockReg(locked_reg);
39793978
3980 const wrapped_ty = ty.structFieldType(0, mod);
3979 const wrapped_ty = ty.fieldType(0, zcu);
39813980 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
39823981
3983 const overflow_bit_ty = ty.structFieldType(1, mod);
3984 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, pt)));
3982 const overflow_bit_ty = ty.fieldType(1, zcu);
3983 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, zcu)));
39853984 const cond_reg = try self.register_manager.allocReg(null, gp);
39863985
39873986 // TODO handle floating point CCRs
......@@ -4154,14 +4153,14 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue {
41544153
41554154fn isErr(self: *Self, ty: Type, operand: MCValue) !MCValue {
41564155 const pt = self.pt;
4157 const mod = pt.zcu;
4158 const error_type = ty.errorUnionSet(mod);
4159 const payload_type = ty.errorUnionPayload(mod);
4156 const zcu = pt.zcu;
4157 const error_type = ty.errorUnionSet(zcu);
4158 const payload_type = ty.errorUnionPayload(zcu);
41604159
4161 if (!error_type.hasRuntimeBits(pt)) {
4160 if (!error_type.hasRuntimeBits(zcu)) {
41624161 return MCValue{ .immediate = 0 }; // always false
4163 } else if (!payload_type.hasRuntimeBits(pt)) {
4164 if (error_type.abiSize(pt) <= 8) {
4162 } else if (!payload_type.hasRuntimeBits(zcu)) {
4163 if (error_type.abiSize(zcu) <= 8) {
41654164 const reg_mcv: MCValue = switch (operand) {
41664165 .register => operand,
41674166 else => .{ .register = try self.copyToTmpRegister(error_type, operand) },
......@@ -4253,9 +4252,9 @@ fn jump(self: *Self, inst: Mir.Inst.Index) !void {
42534252
42544253fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
42554254 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);
4255 const zcu = pt.zcu;
4256 const elem_ty = ptr_ty.childType(zcu);
4257 const elem_size = elem_ty.abiSize(zcu);
42594258
42604259 switch (ptr) {
42614260 .none => unreachable,
......@@ -4325,13 +4324,13 @@ fn minMax(
43254324 rhs_ty: Type,
43264325) InnerError!MCValue {
43274326 const pt = self.pt;
4328 const mod = pt.zcu;
4329 assert(lhs_ty.eql(rhs_ty, mod));
4330 switch (lhs_ty.zigTypeTag(mod)) {
4327 const zcu = pt.zcu;
4328 assert(lhs_ty.eql(rhs_ty, zcu));
4329 switch (lhs_ty.zigTypeTag(zcu)) {
43314330 .Float => return self.fail("TODO min/max on floats", .{}),
43324331 .Vector => return self.fail("TODO min/max on vectors", .{}),
43334332 .Int => {
4334 const int_info = lhs_ty.intInfo(mod);
4333 const int_info = lhs_ty.intInfo(zcu);
43354334 if (int_info.bits <= 64) {
43364335 // TODO skip register setting when one of the operands
43374336 // is a small (fits in i13) immediate.
......@@ -4446,9 +4445,9 @@ fn realStackOffset(off: u32) u32 {
44464445/// Caller must call `CallMCValues.deinit`.
44474446fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) !CallMCValues {
44484447 const pt = self.pt;
4449 const mod = pt.zcu;
4450 const ip = &mod.intern_pool;
4451 const fn_info = mod.typeToFunc(fn_ty).?;
4448 const zcu = pt.zcu;
4449 const ip = &zcu.intern_pool;
4450 const fn_info = zcu.typeToFunc(fn_ty).?;
44524451 const cc = fn_info.cc;
44534452 var result: CallMCValues = .{
44544453 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),
......@@ -4459,7 +4458,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
44594458 };
44604459 errdefer self.gpa.free(result.args);
44614460
4462 const ret_ty = fn_ty.fnReturnType(mod);
4461 const ret_ty = fn_ty.fnReturnType(zcu);
44634462
44644463 switch (cc) {
44654464 .Naked => {
......@@ -4487,7 +4486,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
44874486 };
44884487
44894488 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
4490 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(pt)));
4489 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(zcu)));
44914490 if (param_size <= 8) {
44924491 if (next_register < argument_registers.len) {
44934492 result_arg.* = .{ .register = argument_registers[next_register] };
......@@ -4514,12 +4513,12 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
45144513 result.stack_byte_count = next_stack_offset;
45154514 result.stack_align = .@"16";
45164515
4517 if (ret_ty.zigTypeTag(mod) == .NoReturn) {
4516 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
45184517 result.return_value = .{ .unreach = {} };
4519 } else if (!ret_ty.hasRuntimeBits(pt)) {
4518 } else if (!ret_ty.hasRuntimeBits(zcu)) {
45204519 result.return_value = .{ .none = {} };
45214520 } else {
4522 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));
4521 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
45234522 // The callee puts the return values in %i0-%i3, which becomes %o0-%o3 inside the caller.
45244523 if (ret_ty_size <= 8) {
45254524 result.return_value = switch (role) {
......@@ -4542,7 +4541,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45424541 const ty = self.typeOf(ref);
45434542
45444543 // If the type has no codegen bits, no need to store it.
4545 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
4544 if (!ty.hasRuntimeBitsIgnoreComptime(pt.zcu)) return .none;
45464545
45474546 if (ref.toIndex()) |inst| {
45484547 return self.getResolvedInstValue(inst);
......@@ -4553,8 +4552,8 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45534552
45544553fn ret(self: *Self, mcv: MCValue) !void {
45554554 const pt = self.pt;
4556 const mod = pt.zcu;
4557 const ret_ty = self.fn_type.fnReturnType(mod);
4555 const zcu = pt.zcu;
4556 const ret_ty = self.fn_type.fnReturnType(zcu);
45584557 try self.setRegOrMem(ret_ty, self.ret_mcv, mcv);
45594558
45604559 // Just add space for a branch instruction, patch this later
......@@ -4656,7 +4655,7 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
46564655
46574656fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
46584657 const pt = self.pt;
4659 const abi_size = value_ty.abiSize(pt);
4658 const abi_size = value_ty.abiSize(pt.zcu);
46604659
46614660 switch (ptr) {
46624661 .none => unreachable,
......@@ -4698,11 +4697,11 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
46984697fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
46994698 return if (self.liveness.isUnused(inst)) .dead else result: {
47004699 const pt = self.pt;
4701 const mod = pt.zcu;
4700 const zcu = pt.zcu;
47024701 const mcv = try self.resolveInst(operand);
47034702 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)));
4703 const struct_ty = ptr_ty.childType(zcu);
4704 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
47064705 switch (mcv) {
47074706 .ptr_stack_offset => |off| {
47084707 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
......@@ -4741,9 +4740,9 @@ fn trunc(
47414740 dest_ty: Type,
47424741) !MCValue {
47434742 const pt = self.pt;
4744 const mod = pt.zcu;
4745 const info_a = operand_ty.intInfo(mod);
4746 const info_b = dest_ty.intInfo(mod);
4743 const zcu = pt.zcu;
4744 const info_a = operand_ty.intInfo(zcu);
4745 const info_b = dest_ty.intInfo(zcu);
47474746
47484747 if (info_b.bits <= 64) {
47494748 const operand_reg = switch (operand) {
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.fieldType(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.fieldType(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.zcu.?;
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/Emit.zig+1-1
......@@ -255,7 +255,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
255255 @setCold(true);
256256 std.debug.assert(emit.error_msg == null);
257257 const comp = emit.bin_file.base.comp;
258 const zcu = comp.module.?;
258 const zcu = comp.zcu.?;
259259 const gpa = comp.gpa;
260260 emit.error_msg = try Zcu.ErrorMsg.create(gpa, zcu.navSrcLoc(emit.owner_nav), format, args);
261261 return error.EmitFail;
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.fieldType(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+727-723
......@@ -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.fieldType(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.fieldType(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.fieldType(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.fieldType(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.fieldType(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.fieldType(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.fieldType(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.fieldType(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.fieldType(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.fieldType(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.fieldType(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
......@@ -12104,7 +12105,7 @@ fn genLocalDebugInfo(
1210412105 self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op.operand,
1210512106 ),
1210612107 };
12107 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, self.pt));
12108 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, self.pt.zcu));
1210812109 try self.genSetMem(.{ .frame = frame_index }, 0, ty, mcv, .{});
1210912110 try self.asmAirMemory(.dbg_local, inst, .{
1211012111 .base = .{ .frame = frame_index },
......@@ -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.fieldType(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.fieldType(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.fieldType(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.fieldType(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/Emit.zig+1-1
......@@ -357,7 +357,7 @@ pub fn emitMir(emit: *Emit) Error!void {
357357 } } };
358358 },
359359 };
360 const ip = &emit.lower.bin_file.comp.module.?.intern_pool;
360 const ip = &emit.lower.bin_file.comp.zcu.?.intern_pool;
361361 const air_inst = emit.air.instructions.get(@intFromEnum(air_inst_index));
362362 const name: Air.NullTerminatedString = switch (air_inst.tag) {
363363 else => unreachable,
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+66-65
......@@ -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,
......@@ -877,12 +878,12 @@ fn genNavRef(
877878 // TODO this feels clunky. Perhaps we should check for it in `genTypedValue`?
878879 if (ty.castPtrToFn(zcu)) |fn_ty| {
879880 if (zcu.typeToFunc(fn_ty).?.is_generic) {
880 return .{ .mcv = .{ .immediate = fn_ty.abiAlignment(pt).toByteUnits().? } };
881 return .{ .mcv = .{ .immediate = fn_ty.abiAlignment(zcu).toByteUnits().? } };
881882 }
882883 } else if (ty.zigTypeTag(zcu) == .Pointer) {
883884 const elem_ty = ty.elemType2(zcu);
884 if (!elem_ty.hasRuntimeBits(pt)) {
885 return .{ .mcv = .{ .immediate = elem_ty.abiAlignment(pt).toByteUnits().? } };
885 if (!elem_ty.hasRuntimeBits(zcu)) {
886 return .{ .mcv = .{ .immediate = elem_ty.abiAlignment(zcu).toByteUnits().? } };
886887 }
887888 }
888889
......@@ -963,15 +964,15 @@ pub fn genTypedValue(
963964 },
964965 else => switch (ip.indexToKey(val.toIntern())) {
965966 .int => {
966 return .{ .mcv = .{ .immediate = val.toUnsignedInt(pt) } };
967 return .{ .mcv = .{ .immediate = val.toUnsignedInt(zcu) } };
967968 },
968969 .ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) {
969970 .nav => |nav| return genNavRef(lf, pt, src_loc, val, nav, target),
970 .uav => |uav| if (Value.fromInterned(uav.val).typeOf(zcu).hasRuntimeBits(pt))
971 .uav => |uav| if (Value.fromInterned(uav.val).typeOf(zcu).hasRuntimeBits(zcu))
971972 return switch (try lf.lowerUav(
972973 pt,
973974 uav.val,
974 Type.fromInterned(uav.orig_ty).ptrAlignment(pt),
975 Type.fromInterned(uav.orig_ty).ptrAlignment(zcu),
975976 src_loc,
976977 )) {
977978 .mcv => |mcv| return .{ .mcv = switch (mcv) {
......@@ -982,7 +983,7 @@ pub fn genTypedValue(
982983 .fail => |em| return .{ .fail = em },
983984 }
984985 else
985 return .{ .mcv = .{ .immediate = Type.fromInterned(uav.orig_ty).ptrAlignment(pt)
986 return .{ .mcv = .{ .immediate = Type.fromInterned(uav.orig_ty).ptrAlignment(zcu)
986987 .forward(@intCast((@as(u66, 1) << @intCast(target.ptrBitWidth() | 1)) / 3)) } },
987988 else => {},
988989 },
......@@ -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+123-118
......@@ -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|
......@@ -7202,8 +7206,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
72027206 var empty = true;
72037207 for (0..elements.len) |field_index| {
72047208 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;
7205 const field_ty = inst_ty.structFieldType(field_index, zcu);
7206 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
7209 const field_ty = inst_ty.fieldType(field_index, zcu);
7210 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
72077211
72087212 if (!empty) {
72097213 try writer.writeAll("zig_or_");
......@@ -7215,8 +7219,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
72157219 empty = true;
72167220 for (resolved_elements, 0..) |element, field_index| {
72177221 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;
7218 const field_ty = inst_ty.structFieldType(field_index, zcu);
7219 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
7222 const field_ty = inst_ty.fieldType(field_index, zcu);
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+846-851
......@@ -864,7 +864,7 @@ pub const Object = struct {
864864 // into the garbage can by converting into absolute paths. What
865865 // a terrible tragedy.
866866 const compile_unit_dir = blk: {
867 if (comp.module) |zcu| m: {
867 if (comp.zcu) |zcu| m: {
868868 const d = try zcu.main_mod.root.joinString(arena, "");
869869 if (d.len == 0) break :m;
870870 if (std.fs.path.isAbsolute(d)) break :blk d;
......@@ -955,7 +955,7 @@ pub const Object = struct {
955955 .gpa = gpa,
956956 .builder = builder,
957957 .pt = .{
958 .zcu = comp.module.?,
958 .zcu = comp.zcu.?,
959959 .tid = .main,
960960 },
961961 .debug_compile_unit = debug_compile_unit,
......@@ -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,18 +2494,12 @@ 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);
2499 const field_align = pt.structFieldAlignment(
2500 struct_type.fieldAlign(ip, field_index),
2501 field_ty,
2502 struct_type.layout,
2503 );
2504 const field_offset = ty.structFieldOffset(field_index, pt);
2505
2497 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
2498 const field_size = field_ty.abiSize(zcu);
2499 const field_align = ty.fieldAlignment(field_index, zcu);
2500 const field_offset = ty.structFieldOffset(field_index, zcu);
25062501 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
25072502 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
2508
25092503 fields.appendAssumeCapacity(try o.builder.debugMemberType(
25102504 try o.builder.metadataString(field_name.toSlice(ip)),
25112505 .none, // File
......@@ -2524,8 +2518,8 @@ pub const Object = struct {
25242518 o.debug_compile_unit, // Scope
25252519 0, // Line
25262520 .none, // Underlying type
2527 ty.abiSize(pt) * 8,
2528 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2521 ty.abiSize(zcu) * 8,
2522 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25292523 try o.builder.debugTuple(fields.items),
25302524 );
25312525
......@@ -2543,7 +2537,7 @@ pub const Object = struct {
25432537
25442538 const union_type = ip.loadUnionType(ty.toIntern());
25452539 if (!union_type.haveFieldTypes(ip) or
2546 !ty.hasRuntimeBitsIgnoreComptime(pt) or
2540 !ty.hasRuntimeBitsIgnoreComptime(zcu) or
25472541 !union_type.haveLayout(ip))
25482542 {
25492543 const debug_union_type = try o.makeEmptyNamespaceDebugType(ty);
......@@ -2551,7 +2545,7 @@ pub const Object = struct {
25512545 return debug_union_type;
25522546 }
25532547
2554 const layout = pt.getUnionLayout(union_type);
2548 const layout = Type.getUnionLayout(union_type, zcu);
25552549
25562550 const debug_fwd_ref = try o.builder.debugForwardReference();
25572551
......@@ -2565,8 +2559,8 @@ pub const Object = struct {
25652559 o.debug_compile_unit, // Scope
25662560 0, // Line
25672561 .none, // Underlying type
2568 ty.abiSize(pt) * 8,
2569 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2562 ty.abiSize(zcu) * 8,
2563 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25702564 try o.builder.debugTuple(
25712565 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
25722566 ),
......@@ -2593,12 +2587,12 @@ pub const Object = struct {
25932587
25942588 for (0..tag_type.names.len) |field_index| {
25952589 const field_ty = union_type.field_types.get(ip)[field_index];
2596 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
2590 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
25972591
2598 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2592 const field_size = Type.fromInterned(field_ty).abiSize(zcu);
25992593 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
26002594 .@"packed" => .none,
2601 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2595 .auto, .@"extern" => ty.fieldAlignment(field_index, zcu),
26022596 };
26032597
26042598 const field_name = tag_type.names.get(ip)[field_index];
......@@ -2627,8 +2621,8 @@ pub const Object = struct {
26272621 o.debug_compile_unit, // Scope
26282622 0, // Line
26292623 .none, // Underlying type
2630 ty.abiSize(pt) * 8,
2631 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2624 ty.abiSize(zcu) * 8,
2625 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
26322626 try o.builder.debugTuple(fields.items),
26332627 );
26342628
......@@ -2686,8 +2680,8 @@ pub const Object = struct {
26862680 o.debug_compile_unit, // Scope
26872681 0, // Line
26882682 .none, // Underlying type
2689 ty.abiSize(pt) * 8,
2690 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,
2683 ty.abiSize(zcu) * 8,
2684 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
26912685 try o.builder.debugTuple(&full_fields),
26922686 );
26932687
......@@ -2708,8 +2702,8 @@ pub const Object = struct {
27082702 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
27092703
27102704 // Return type goes first.
2711 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {
2712 const sret = firstParamSRet(fn_info, pt, target);
2705 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
2706 const sret = firstParamSRet(fn_info, zcu, target);
27132707 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
27142708 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
27152709
......@@ -2730,9 +2724,9 @@ pub const Object = struct {
27302724
27312725 for (0..fn_info.param_types.len) |i| {
27322726 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2733 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
2727 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
27342728
2735 if (isByRef(param_ty, pt)) {
2729 if (isByRef(param_ty, zcu)) {
27362730 const ptr_ty = try pt.singleMutPtrType(param_ty);
27372731 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
27382732 } else {
......@@ -2842,7 +2836,7 @@ pub const Object = struct {
28422836
28432837 const fn_info = zcu.typeToFunc(ty).?;
28442838 const target = owner_mod.resolved_target.result;
2845 const sret = firstParamSRet(fn_info, pt, target);
2839 const sret = firstParamSRet(fn_info, zcu, target);
28462840
28472841 const is_extern, const lib_name = switch (ip.indexToKey(val.toIntern())) {
28482842 .variable => |variable| .{ false, variable.lib_name },
......@@ -2934,14 +2928,14 @@ pub const Object = struct {
29342928 .byval => {
29352929 const param_index = it.zig_index - 1;
29362930 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
2937 if (!isByRef(param_ty, pt)) {
2931 if (!isByRef(param_ty, zcu)) {
29382932 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
29392933 }
29402934 },
29412935 .byref => {
29422936 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
29432937 const param_llvm_ty = try o.lowerType(param_ty);
2944 const alignment = param_ty.abiAlignment(pt);
2938 const alignment = param_ty.abiAlignment(zcu);
29452939 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
29462940 },
29472941 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
......@@ -3042,8 +3036,8 @@ pub const Object = struct {
30423036 }
30433037 errdefer assert(o.uav_map.remove(uav));
30443038
3045 const mod = o.pt.zcu;
3046 const decl_ty = mod.intern_pool.typeOf(uav);
3039 const zcu = o.pt.zcu;
3040 const decl_ty = zcu.intern_pool.typeOf(uav);
30473041
30483042 const variable_index = try o.builder.addVariable(
30493043 try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}),
......@@ -3106,9 +3100,9 @@ pub const Object = struct {
31063100
31073101 fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type {
31083102 const pt = o.pt;
3109 const mod = pt.zcu;
3110 const target = mod.getTarget();
3111 const ip = &mod.intern_pool;
3103 const zcu = pt.zcu;
3104 const target = zcu.getTarget();
3105 const ip = &zcu.intern_pool;
31123106 return switch (t.toIntern()) {
31133107 .u0_type, .i0_type => unreachable,
31143108 inline .u1_type,
......@@ -3230,16 +3224,16 @@ pub const Object = struct {
32303224 ),
32313225 .opt_type => |child_ty| {
32323226 // Must stay in sync with `opt_payload` logic in `lowerPtr`.
3233 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(pt)) return .i8;
3227 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(zcu)) return .i8;
32343228
32353229 const payload_ty = try o.lowerType(Type.fromInterned(child_ty));
3236 if (t.optionalReprIsPayload(mod)) return payload_ty;
3230 if (t.optionalReprIsPayload(zcu)) return payload_ty;
32373231
32383232 comptime assert(optional_layout_version == 3);
32393233 var fields: [3]Builder.Type = .{ payload_ty, .i8, undefined };
32403234 var fields_len: usize = 2;
3241 const offset = Type.fromInterned(child_ty).abiSize(pt) + 1;
3242 const abi_size = t.abiSize(pt);
3235 const offset = Type.fromInterned(child_ty).abiSize(zcu) + 1;
3236 const abi_size = t.abiSize(zcu);
32433237 const padding_len = abi_size - offset;
32443238 if (padding_len > 0) {
32453239 fields[2] = try o.builder.arrayType(padding_len, .i8);
......@@ -3252,16 +3246,16 @@ pub const Object = struct {
32523246 // Must stay in sync with `codegen.errUnionPayloadOffset`.
32533247 // See logic in `lowerPtr`.
32543248 const error_type = try o.errorIntType();
3255 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(pt))
3249 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(zcu))
32563250 return error_type;
32573251 const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type));
32583252 const err_int_ty = try o.pt.errorIntType();
32593253
3260 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(pt);
3261 const error_align = err_int_ty.abiAlignment(pt);
3254 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu);
3255 const error_align = err_int_ty.abiAlignment(zcu);
32623256
3263 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(pt);
3264 const error_size = err_int_ty.abiSize(pt);
3257 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu);
3258 const error_size = err_int_ty.abiSize(zcu);
32653259
32663260 var fields: [3]Builder.Type = undefined;
32673261 var fields_len: usize = 2;
......@@ -3315,12 +3309,8 @@ pub const Object = struct {
33153309 var it = struct_type.iterateRuntimeOrder(ip);
33163310 while (it.next()) |field_index| {
33173311 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
3318 const field_align = pt.structFieldAlignment(
3319 struct_type.fieldAlign(ip, field_index),
3320 field_ty,
3321 struct_type.layout,
3322 );
3323 const field_ty_align = field_ty.abiAlignment(pt);
3312 const field_align = t.fieldAlignment(field_index, zcu);
3313 const field_ty_align = field_ty.abiAlignment(zcu);
33243314 if (field_align.compare(.lt, field_ty_align)) struct_kind = .@"packed";
33253315 big_align = big_align.max(field_align);
33263316 const prev_offset = offset;
......@@ -3332,7 +3322,7 @@ pub const Object = struct {
33323322 try o.builder.arrayType(padding_len, .i8),
33333323 );
33343324
3335 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3325 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
33363326 // This is a zero-bit field. If there are runtime bits after this field,
33373327 // map to the next LLVM field (which we know exists): otherwise, don't
33383328 // map the field, indicating it's at the end of the struct.
......@@ -3351,7 +3341,7 @@ pub const Object = struct {
33513341 }, @intCast(llvm_field_types.items.len));
33523342 try llvm_field_types.append(o.gpa, try o.lowerType(field_ty));
33533343
3354 offset += field_ty.abiSize(pt);
3344 offset += field_ty.abiSize(zcu);
33553345 }
33563346 {
33573347 const prev_offset = offset;
......@@ -3384,7 +3374,7 @@ pub const Object = struct {
33843374 var offset: u64 = 0;
33853375 var big_align: InternPool.Alignment = .none;
33863376
3387 const struct_size = t.abiSize(pt);
3377 const struct_size = t.abiSize(zcu);
33883378
33893379 for (
33903380 anon_struct_type.types.get(ip),
......@@ -3393,7 +3383,7 @@ pub const Object = struct {
33933383 ) |field_ty, field_val, field_index| {
33943384 if (field_val != .none) continue;
33953385
3396 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
3386 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
33973387 big_align = big_align.max(field_align);
33983388 const prev_offset = offset;
33993389 offset = field_align.forward(offset);
......@@ -3403,7 +3393,7 @@ pub const Object = struct {
34033393 o.gpa,
34043394 try o.builder.arrayType(padding_len, .i8),
34053395 );
3406 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) {
3396 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) {
34073397 // This is a zero-bit field. If there are runtime bits after this field,
34083398 // map to the next LLVM field (which we know exists): otherwise, don't
34093399 // map the field, indicating it's at the end of the struct.
......@@ -3421,7 +3411,7 @@ pub const Object = struct {
34213411 }, @intCast(llvm_field_types.items.len));
34223412 try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty)));
34233413
3424 offset += Type.fromInterned(field_ty).abiSize(pt);
3414 offset += Type.fromInterned(field_ty).abiSize(zcu);
34253415 }
34263416 {
34273417 const prev_offset = offset;
......@@ -3438,10 +3428,10 @@ pub const Object = struct {
34383428 if (o.type_map.get(t.toIntern())) |value| return value;
34393429
34403430 const union_obj = ip.loadUnionType(t.toIntern());
3441 const layout = pt.getUnionLayout(union_obj);
3431 const layout = Type.getUnionLayout(union_obj, zcu);
34423432
34433433 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
3444 const int_ty = try o.builder.intType(@intCast(t.bitSize(pt)));
3434 const int_ty = try o.builder.intType(@intCast(t.bitSize(zcu)));
34453435 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
34463436 return int_ty;
34473437 }
......@@ -3547,32 +3537,32 @@ pub const Object = struct {
35473537 /// There are other similar cases handled here as well.
35483538 fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type {
35493539 const pt = o.pt;
3550 const mod = pt.zcu;
3551 const lower_elem_ty = switch (elem_ty.zigTypeTag(mod)) {
3540 const zcu = pt.zcu;
3541 const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) {
35523542 .Opaque => true,
3553 .Fn => !mod.typeToFunc(elem_ty).?.is_generic,
3554 .Array => elem_ty.childType(mod).hasRuntimeBitsIgnoreComptime(pt),
3555 else => elem_ty.hasRuntimeBitsIgnoreComptime(pt),
3543 .Fn => !zcu.typeToFunc(elem_ty).?.is_generic,
3544 .Array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu),
3545 else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu),
35563546 };
35573547 return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8;
35583548 }
35593549
35603550 fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
35613551 const pt = o.pt;
3562 const mod = pt.zcu;
3563 const ip = &mod.intern_pool;
3564 const target = mod.getTarget();
3552 const zcu = pt.zcu;
3553 const ip = &zcu.intern_pool;
3554 const target = zcu.getTarget();
35653555 const ret_ty = try lowerFnRetTy(o, fn_info);
35663556
35673557 var llvm_params = std.ArrayListUnmanaged(Builder.Type){};
35683558 defer llvm_params.deinit(o.gpa);
35693559
3570 if (firstParamSRet(fn_info, pt, target)) {
3560 if (firstParamSRet(fn_info, zcu, target)) {
35713561 try llvm_params.append(o.gpa, .ptr);
35723562 }
35733563
3574 if (Type.fromInterned(fn_info.return_type).isError(mod) and
3575 mod.comp.config.any_error_tracing)
3564 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
3565 zcu.comp.config.any_error_tracing)
35763566 {
35773567 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
35783568 try llvm_params.append(o.gpa, try o.lowerType(ptr_ty));
......@@ -3591,13 +3581,13 @@ pub const Object = struct {
35913581 .abi_sized_int => {
35923582 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
35933583 try llvm_params.append(o.gpa, try o.builder.intType(
3594 @intCast(param_ty.abiSize(pt) * 8),
3584 @intCast(param_ty.abiSize(zcu) * 8),
35953585 ));
35963586 },
35973587 .slice => {
35983588 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
35993589 try llvm_params.appendSlice(o.gpa, &.{
3600 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(mod), target)),
3590 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(zcu), target)),
36013591 try o.lowerType(Type.usize),
36023592 });
36033593 },
......@@ -3609,7 +3599,7 @@ pub const Object = struct {
36093599 },
36103600 .float_array => |count| {
36113601 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).?);
3602 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, zcu).?);
36133603 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
36143604 },
36153605 .i32_array, .i64_array => |arr_len| {
......@@ -3630,14 +3620,14 @@ pub const Object = struct {
36303620
36313621 fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
36323622 const pt = o.pt;
3633 const mod = pt.zcu;
3634 const ip = &mod.intern_pool;
3635 const target = mod.getTarget();
3623 const zcu = pt.zcu;
3624 const ip = &zcu.intern_pool;
3625 const target = zcu.getTarget();
36363626
36373627 const val = Value.fromInterned(arg_val);
36383628 const val_key = ip.indexToKey(val.toIntern());
36393629
3640 if (val.isUndefDeep(mod)) return o.builder.undefConst(llvm_int_ty);
3630 if (val.isUndefDeep(zcu)) return o.builder.undefConst(llvm_int_ty);
36413631
36423632 const ty = Type.fromInterned(val_key.typeOf());
36433633 switch (val_key) {
......@@ -3661,7 +3651,7 @@ pub const Object = struct {
36613651 var running_int = try o.builder.intConst(llvm_int_ty, 0);
36623652 var running_bits: u16 = 0;
36633653 for (struct_type.field_types.get(ip), 0..) |field_ty, field_index| {
3664 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
3654 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
36653655
36663656 const shift_rhs = try o.builder.intConst(llvm_int_ty, running_bits);
36673657 const field_val = try o.lowerValueToInt(llvm_int_ty, (try val.fieldValue(pt, field_index)).toIntern());
......@@ -3669,7 +3659,7 @@ pub const Object = struct {
36693659
36703660 running_int = try o.builder.binConst(.xor, running_int, shifted);
36713661
3672 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(pt));
3662 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(zcu));
36733663 running_bits += ty_bit_size;
36743664 }
36753665 return running_int;
......@@ -3678,10 +3668,10 @@ pub const Object = struct {
36783668 else => unreachable,
36793669 },
36803670 .un => |un| {
3681 const layout = ty.unionGetLayout(pt);
3671 const layout = ty.unionGetLayout(zcu);
36823672 if (layout.payload_size == 0) return o.lowerValue(un.tag);
36833673
3684 const union_obj = mod.typeToUnion(ty).?;
3674 const union_obj = zcu.typeToUnion(ty).?;
36853675 const container_layout = union_obj.flagsUnordered(ip).layout;
36863676
36873677 assert(container_layout == .@"packed");
......@@ -3694,9 +3684,9 @@ pub const Object = struct {
36943684 need_unnamed = true;
36953685 return union_val;
36963686 }
3697 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3687 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
36983688 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);
3689 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(llvm_int_ty, 0);
37003690 return o.lowerValueToInt(llvm_int_ty, un.val);
37013691 },
37023692 .simple_value => |simple_value| switch (simple_value) {
......@@ -3710,7 +3700,7 @@ pub const Object = struct {
37103700 .opt => {}, // pointer like optional expected
37113701 else => unreachable,
37123702 }
3713 const bits = ty.bitSize(pt);
3703 const bits = ty.bitSize(zcu);
37143704 const bytes: usize = @intCast(std.mem.alignForward(u64, bits, 8) / 8);
37153705
37163706 var stack = std.heap.stackFallback(32, o.gpa);
......@@ -3743,14 +3733,14 @@ pub const Object = struct {
37433733
37443734 fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant {
37453735 const pt = o.pt;
3746 const mod = pt.zcu;
3747 const ip = &mod.intern_pool;
3748 const target = mod.getTarget();
3736 const zcu = pt.zcu;
3737 const ip = &zcu.intern_pool;
3738 const target = zcu.getTarget();
37493739
37503740 const val = Value.fromInterned(arg_val);
37513741 const val_key = ip.indexToKey(val.toIntern());
37523742
3753 if (val.isUndefDeep(mod)) {
3743 if (val.isUndefDeep(zcu)) {
37543744 return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf())));
37553745 }
37563746
......@@ -3800,7 +3790,7 @@ pub const Object = struct {
38003790 },
38013791 .int => {
38023792 var bigint_space: Value.BigIntSpace = undefined;
3803 const bigint = val.toBigInt(&bigint_space, pt);
3793 const bigint = val.toBigInt(&bigint_space, zcu);
38043794 return lowerBigInt(o, ty, bigint);
38053795 },
38063796 .err => |err| {
......@@ -3811,20 +3801,20 @@ pub const Object = struct {
38113801 .error_union => |error_union| {
38123802 const err_val = switch (error_union.val) {
38133803 .err_name => |err_name| try pt.intern(.{ .err = .{
3814 .ty = ty.errorUnionSet(mod).toIntern(),
3804 .ty = ty.errorUnionSet(zcu).toIntern(),
38153805 .name = err_name,
38163806 } }),
38173807 .payload => (try pt.intValue(try pt.errorIntType(), 0)).toIntern(),
38183808 };
38193809 const err_int_ty = try pt.errorIntType();
3820 const payload_type = ty.errorUnionPayload(mod);
3821 if (!payload_type.hasRuntimeBitsIgnoreComptime(pt)) {
3810 const payload_type = ty.errorUnionPayload(zcu);
3811 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
38223812 // We use the error type directly as the type.
38233813 return o.lowerValue(err_val);
38243814 }
38253815
3826 const payload_align = payload_type.abiAlignment(pt);
3827 const error_align = err_int_ty.abiAlignment(pt);
3816 const payload_align = payload_type.abiAlignment(zcu);
3817 const error_align = err_int_ty.abiAlignment(zcu);
38283818 const llvm_error_value = try o.lowerValue(err_val);
38293819 const llvm_payload_value = try o.lowerValue(switch (error_union.val) {
38303820 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),
......@@ -3858,16 +3848,16 @@ pub const Object = struct {
38583848 .enum_tag => |enum_tag| o.lowerValue(enum_tag.int),
38593849 .float => switch (ty.floatBits(target)) {
38603850 16 => if (backendSupportsF16(target))
3861 try o.builder.halfConst(val.toFloat(f16, pt))
3851 try o.builder.halfConst(val.toFloat(f16, zcu))
38623852 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)),
3853 try o.builder.intConst(.i16, @as(i16, @bitCast(val.toFloat(f16, zcu)))),
3854 32 => try o.builder.floatConst(val.toFloat(f32, zcu)),
3855 64 => try o.builder.doubleConst(val.toFloat(f64, zcu)),
38663856 80 => if (backendSupportsF80(target))
3867 try o.builder.x86_fp80Const(val.toFloat(f80, pt))
3857 try o.builder.x86_fp80Const(val.toFloat(f80, zcu))
38683858 else
3869 try o.builder.intConst(.i80, @as(i80, @bitCast(val.toFloat(f80, pt)))),
3870 128 => try o.builder.fp128Const(val.toFloat(f128, pt)),
3859 try o.builder.intConst(.i80, @as(i80, @bitCast(val.toFloat(f80, zcu)))),
3860 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)),
38713861 else => unreachable,
38723862 },
38733863 .ptr => try o.lowerPtr(arg_val, 0),
......@@ -3877,14 +3867,14 @@ pub const Object = struct {
38773867 }),
38783868 .opt => |opt| {
38793869 comptime assert(optional_layout_version == 3);
3880 const payload_ty = ty.optionalChild(mod);
3870 const payload_ty = ty.optionalChild(zcu);
38813871
38823872 const non_null_bit = try o.builder.intConst(.i8, @intFromBool(opt.val != .none));
3883 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
3873 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
38843874 return non_null_bit;
38853875 }
38863876 const llvm_ty = try o.lowerType(ty);
3887 if (ty.optionalReprIsPayload(mod)) return switch (opt.val) {
3877 if (ty.optionalReprIsPayload(zcu)) return switch (opt.val) {
38883878 .none => switch (llvm_ty.tag(&o.builder)) {
38893879 .integer => try o.builder.intConst(llvm_ty, 0),
38903880 .pointer => try o.builder.nullConst(llvm_ty),
......@@ -3893,7 +3883,7 @@ pub const Object = struct {
38933883 },
38943884 else => |payload| try o.lowerValue(payload),
38953885 };
3896 assert(payload_ty.zigTypeTag(mod) != .Fn);
3886 assert(payload_ty.zigTypeTag(zcu) != .Fn);
38973887
38983888 var fields: [3]Builder.Type = undefined;
38993889 var vals: [3]Builder.Constant = undefined;
......@@ -4047,9 +4037,9 @@ pub const Object = struct {
40474037 0..,
40484038 ) |field_ty, field_val, field_index| {
40494039 if (field_val != .none) continue;
4050 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
4040 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
40514041
4052 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);
4042 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
40534043 big_align = big_align.max(field_align);
40544044 const prev_offset = offset;
40554045 offset = field_align.forward(offset);
......@@ -4071,7 +4061,7 @@ pub const Object = struct {
40714061 need_unnamed = true;
40724062 llvm_index += 1;
40734063
4074 offset += Type.fromInterned(field_ty).abiSize(pt);
4064 offset += Type.fromInterned(field_ty).abiSize(zcu);
40754065 }
40764066 {
40774067 const prev_offset = offset;
......@@ -4098,7 +4088,7 @@ pub const Object = struct {
40984088 if (struct_type.layout == .@"packed") {
40994089 comptime assert(Type.packed_struct_layout_version == 2);
41004090
4101 const bits = ty.bitSize(pt);
4091 const bits = ty.bitSize(zcu);
41024092 const llvm_int_ty = try o.builder.intType(@intCast(bits));
41034093
41044094 return o.lowerValueToInt(llvm_int_ty, arg_val);
......@@ -4127,11 +4117,7 @@ pub const Object = struct {
41274117 var field_it = struct_type.iterateRuntimeOrder(ip);
41284118 while (field_it.next()) |field_index| {
41294119 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
4130 const field_align = pt.structFieldAlignment(
4131 struct_type.fieldAlign(ip, field_index),
4132 field_ty,
4133 struct_type.layout,
4134 );
4120 const field_align = ty.fieldAlignment(field_index, zcu);
41354121 big_align = big_align.max(field_align);
41364122 const prev_offset = offset;
41374123 offset = field_align.forward(offset);
......@@ -4147,7 +4133,7 @@ pub const Object = struct {
41474133 llvm_index += 1;
41484134 }
41494135
4150 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4136 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
41514137 // This is a zero-bit field - we only needed it for the alignment.
41524138 continue;
41534139 }
......@@ -4160,7 +4146,7 @@ pub const Object = struct {
41604146 need_unnamed = true;
41614147 llvm_index += 1;
41624148
4163 offset += field_ty.abiSize(pt);
4149 offset += field_ty.abiSize(zcu);
41644150 }
41654151 {
41664152 const prev_offset = offset;
......@@ -4184,19 +4170,19 @@ pub const Object = struct {
41844170 },
41854171 .un => |un| {
41864172 const union_ty = try o.lowerType(ty);
4187 const layout = ty.unionGetLayout(pt);
4173 const layout = ty.unionGetLayout(zcu);
41884174 if (layout.payload_size == 0) return o.lowerValue(un.tag);
41894175
4190 const union_obj = mod.typeToUnion(ty).?;
4176 const union_obj = zcu.typeToUnion(ty).?;
41914177 const container_layout = union_obj.flagsUnordered(ip).layout;
41924178
41934179 var need_unnamed = false;
41944180 const payload = if (un.tag != .none) p: {
4195 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
4181 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
41964182 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
41974183 if (container_layout == .@"packed") {
4198 if (!field_ty.hasRuntimeBits(pt)) return o.builder.intConst(union_ty, 0);
4199 const bits = ty.bitSize(pt);
4184 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(union_ty, 0);
4185 const bits = ty.bitSize(zcu);
42004186 const llvm_int_ty = try o.builder.intType(@intCast(bits));
42014187
42024188 return o.lowerValueToInt(llvm_int_ty, arg_val);
......@@ -4208,7 +4194,7 @@ pub const Object = struct {
42084194 // must pointer cast to the expected type before accessing the union.
42094195 need_unnamed = layout.most_aligned_field != field_index;
42104196
4211 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
4197 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
42124198 const padding_len = layout.payload_size;
42134199 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));
42144200 }
......@@ -4217,7 +4203,7 @@ pub const Object = struct {
42174203 if (payload_ty != union_ty.structFields(&o.builder)[
42184204 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))
42194205 ]) need_unnamed = true;
4220 const field_size = field_ty.abiSize(pt);
4206 const field_size = field_ty.abiSize(zcu);
42214207 if (field_size == layout.payload_size) break :p payload;
42224208 const padding_len = layout.payload_size - field_size;
42234209 const padding_ty = try o.builder.arrayType(padding_len, .i8);
......@@ -4228,7 +4214,7 @@ pub const Object = struct {
42284214 } else p: {
42294215 assert(layout.tag_size == 0);
42304216 if (container_layout == .@"packed") {
4231 const bits = ty.bitSize(pt);
4217 const bits = ty.bitSize(zcu);
42324218 const llvm_int_ty = try o.builder.intType(@intCast(bits));
42334219
42344220 return o.lowerValueToInt(llvm_int_ty, arg_val);
......@@ -4275,8 +4261,8 @@ pub const Object = struct {
42754261 ty: Type,
42764262 bigint: std.math.big.int.Const,
42774263 ) Allocator.Error!Builder.Constant {
4278 const mod = o.pt.zcu;
4279 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(mod).bits), bigint);
4264 const zcu = o.pt.zcu;
4265 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint);
42804266 }
42814267
42824268 fn lowerPtr(
......@@ -4310,7 +4296,7 @@ pub const Object = struct {
43104296 eu_ptr,
43114297 offset + @import("../codegen.zig").errUnionPayloadOffset(
43124298 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),
4313 pt,
4299 zcu,
43144300 ),
43154301 ),
43164302 .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset),
......@@ -4326,7 +4312,7 @@ pub const Object = struct {
43264312 };
43274313 },
43284314 .Struct, .Union => switch (agg_ty.containerLayout(zcu)) {
4329 .auto => agg_ty.structFieldOffset(@intCast(field.index), pt),
4315 .auto => agg_ty.structFieldOffset(@intCast(field.index), zcu),
43304316 .@"extern", .@"packed" => unreachable,
43314317 },
43324318 else => unreachable,
......@@ -4344,11 +4330,11 @@ pub const Object = struct {
43444330 uav: InternPool.Key.Ptr.BaseAddr.Uav,
43454331 ) Error!Builder.Constant {
43464332 const pt = o.pt;
4347 const mod = pt.zcu;
4348 const ip = &mod.intern_pool;
4333 const zcu = pt.zcu;
4334 const ip = &zcu.intern_pool;
43494335 const uav_val = uav.val;
43504336 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));
4351 const target = mod.getTarget();
4337 const target = zcu.getTarget();
43524338
43534339 switch (ip.indexToKey(uav_val)) {
43544340 .func => @panic("TODO"),
......@@ -4358,15 +4344,15 @@ pub const Object = struct {
43584344
43594345 const ptr_ty = Type.fromInterned(uav.orig_ty);
43604346
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);
4347 const is_fn_body = uav_ty.zigTypeTag(zcu) == .Fn;
4348 if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or
4349 (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty);
43644350
43654351 if (is_fn_body)
43664352 @panic("TODO");
43674353
4368 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(mod), target);
4369 const alignment = ptr_ty.ptrAlignment(pt);
4354 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target);
4355 const alignment = ptr_ty.ptrAlignment(zcu);
43704356 const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
43714357
43724358 const llvm_val = try o.builder.convConst(
......@@ -4398,7 +4384,7 @@ pub const Object = struct {
43984384 const ptr_ty = try pt.navPtrType(owner_nav_index);
43994385
44004386 const is_fn_body = nav_ty.zigTypeTag(zcu) == .Fn;
4401 if ((!is_fn_body and !nav_ty.hasRuntimeBits(pt)) or
4387 if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or
44024388 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))
44034389 {
44044390 return o.lowerPtrToVoid(ptr_ty);
......@@ -4418,19 +4404,19 @@ pub const Object = struct {
44184404 }
44194405
44204406 fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant {
4421 const mod = o.pt.zcu;
4407 const zcu = o.pt.zcu;
44224408 // Even though we are pointing at something which has zero bits (e.g. `void`),
44234409 // Pointers are defined to have bits. So we must return something here.
44244410 // The value cannot be undefined, because we use the `nonnull` annotation
44254411 // for non-optional pointers. We also need to respect the alignment, even though
44264412 // the address will never be dereferenced.
4427 const int: u64 = ptr_ty.ptrInfo(mod).flags.alignment.toByteUnits() orelse
4413 const int: u64 = ptr_ty.ptrInfo(zcu).flags.alignment.toByteUnits() orelse
44284414 // Note that these 0xaa values are appropriate even in release-optimized builds
44294415 // because we need a well-defined value that is not null, and LLVM does not
44304416 // have an "undef_but_not_null" attribute. As an example, if this `alloc` AIR
44314417 // instruction is followed by a `wrap_optional`, it will return this value
44324418 // verbatim, and the result should test as non-null.
4433 switch (mod.getTarget().ptrBitWidth()) {
4419 switch (zcu.getTarget().ptrBitWidth()) {
44344420 16 => 0xaaaa,
44354421 32 => 0xaaaaaaaa,
44364422 64 => 0xaaaaaaaa_aaaaaaaa,
......@@ -4447,20 +4433,20 @@ pub const Object = struct {
44474433 /// types to work around a LLVM deficiency when targeting ARM/AArch64.
44484434 fn getAtomicAbiType(o: *Object, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
44494435 const pt = o.pt;
4450 const mod = pt.zcu;
4451 const int_ty = switch (ty.zigTypeTag(mod)) {
4436 const zcu = pt.zcu;
4437 const int_ty = switch (ty.zigTypeTag(zcu)) {
44524438 .Int => ty,
4453 .Enum => ty.intTagType(mod),
4439 .Enum => ty.intTagType(zcu),
44544440 .Float => {
44554441 if (!is_rmw_xchg) return .none;
4456 return o.builder.intType(@intCast(ty.abiSize(pt) * 8));
4442 return o.builder.intType(@intCast(ty.abiSize(zcu) * 8));
44574443 },
44584444 .Bool => return .i8,
44594445 else => return .none,
44604446 };
4461 const bit_count = int_ty.intInfo(mod).bits;
4447 const bit_count = int_ty.intInfo(zcu).bits;
44624448 if (!std.math.isPowerOfTwo(bit_count) or (bit_count % 8) != 0) {
4463 return o.builder.intType(@intCast(int_ty.abiSize(pt) * 8));
4449 return o.builder.intType(@intCast(int_ty.abiSize(zcu) * 8));
44644450 } else {
44654451 return .none;
44664452 }
......@@ -4475,15 +4461,15 @@ pub const Object = struct {
44754461 llvm_arg_i: u32,
44764462 ) Allocator.Error!void {
44774463 const pt = o.pt;
4478 const mod = pt.zcu;
4479 if (param_ty.isPtrAtRuntime(mod)) {
4480 const ptr_info = param_ty.ptrInfo(mod);
4464 const zcu = pt.zcu;
4465 if (param_ty.isPtrAtRuntime(zcu)) {
4466 const ptr_info = param_ty.ptrInfo(zcu);
44814467 if (math.cast(u5, param_index)) |i| {
44824468 if (@as(u1, @truncate(fn_info.noalias_bits >> i)) != 0) {
44834469 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
44844470 }
44854471 }
4486 if (!param_ty.isPtrLikeOptional(mod) and !ptr_info.flags.is_allowzero) {
4472 if (!param_ty.isPtrLikeOptional(zcu) and !ptr_info.flags.is_allowzero) {
44874473 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
44884474 }
44894475 if (fn_info.cc == .Interrupt) {
......@@ -4496,9 +4482,9 @@ pub const Object = struct {
44964482 const elem_align = if (ptr_info.flags.alignment != .none)
44974483 ptr_info.flags.alignment
44984484 else
4499 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1");
4485 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1");
45004486 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) {
4487 } else if (ccAbiPromoteInt(fn_info.cc, zcu, param_ty)) |s| switch (s) {
45024488 .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder),
45034489 .unsigned => try attributes.addParamAttr(llvm_arg_i, .zeroext, &o.builder),
45044490 };
......@@ -4814,14 +4800,14 @@ pub const FuncGen = struct {
48144800
48154801 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {
48164802 const o = self.ng.object;
4817 const pt = o.pt;
4818 const ty = val.typeOf(pt.zcu);
4803 const zcu = o.pt.zcu;
4804 const ty = val.typeOf(zcu);
48194805 const llvm_val = try o.lowerValue(val.toIntern());
4820 if (!isByRef(ty, pt)) return llvm_val;
4806 if (!isByRef(ty, zcu)) return llvm_val;
48214807
48224808 // We have an LLVM value but we need to create a global constant and
48234809 // set the value as its initializer, and then return a pointer to the global.
4824 const target = pt.zcu.getTarget();
4810 const target = zcu.getTarget();
48254811 const variable_index = try o.builder.addVariable(
48264812 .empty,
48274813 llvm_val.typeOf(&o.builder),
......@@ -4831,7 +4817,7 @@ pub const FuncGen = struct {
48314817 variable_index.setLinkage(.private, &o.builder);
48324818 variable_index.setMutability(.constant, &o.builder);
48334819 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
4834 variable_index.setAlignment(ty.abiAlignment(pt).toLlvm(), &o.builder);
4820 variable_index.setAlignment(ty.abiAlignment(zcu).toLlvm(), &o.builder);
48354821 return o.builder.convConst(
48364822 variable_index.toConst(&o.builder),
48374823 try o.builder.ptrType(toLlvmAddressSpace(.generic, target)),
......@@ -4852,8 +4838,8 @@ pub const FuncGen = struct {
48524838
48534839 fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void {
48544840 const o = self.ng.object;
4855 const mod = o.pt.zcu;
4856 const ip = &mod.intern_pool;
4841 const zcu = o.pt.zcu;
4842 const ip = &zcu.intern_pool;
48574843 const air_tags = self.air.instructions.items(.tag);
48584844 for (body, 0..) |inst, i| {
48594845 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;
......@@ -5200,19 +5186,19 @@ pub const FuncGen = struct {
52005186 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
52015187 const o = self.ng.object;
52025188 const pt = o.pt;
5203 const mod = pt.zcu;
5204 const ip = &mod.intern_pool;
5189 const zcu = pt.zcu;
5190 const ip = &zcu.intern_pool;
52055191 const callee_ty = self.typeOf(pl_op.operand);
5206 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
5192 const zig_fn_ty = switch (callee_ty.zigTypeTag(zcu)) {
52075193 .Fn => callee_ty,
5208 .Pointer => callee_ty.childType(mod),
5194 .Pointer => callee_ty.childType(zcu),
52095195 else => unreachable,
52105196 };
5211 const fn_info = mod.typeToFunc(zig_fn_ty).?;
5197 const fn_info = zcu.typeToFunc(zig_fn_ty).?;
52125198 const return_type = Type.fromInterned(fn_info.return_type);
52135199 const llvm_fn = try self.resolveInst(pl_op.operand);
5214 const target = mod.getTarget();
5215 const sret = firstParamSRet(fn_info, pt, target);
5200 const target = zcu.getTarget();
5201 const sret = firstParamSRet(fn_info, zcu, target);
52165202
52175203 var llvm_args = std.ArrayList(Builder.Value).init(self.gpa);
52185204 defer llvm_args.deinit();
......@@ -5230,13 +5216,13 @@ pub const FuncGen = struct {
52305216 const llvm_ret_ty = try o.lowerType(return_type);
52315217 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);
52325218
5233 const alignment = return_type.abiAlignment(pt).toLlvm();
5219 const alignment = return_type.abiAlignment(zcu).toLlvm();
52345220 const ret_ptr = try self.buildAllocaWorkaround(return_type, alignment);
52355221 try llvm_args.append(ret_ptr);
52365222 break :blk ret_ptr;
52375223 };
52385224
5239 const err_return_tracing = return_type.isError(mod) and mod.comp.config.any_error_tracing;
5225 const err_return_tracing = return_type.isError(zcu) and zcu.comp.config.any_error_tracing;
52405226 if (err_return_tracing) {
52415227 assert(self.err_ret_trace != .none);
52425228 try llvm_args.append(self.err_ret_trace);
......@@ -5250,8 +5236,8 @@ pub const FuncGen = struct {
52505236 const param_ty = self.typeOf(arg);
52515237 const llvm_arg = try self.resolveInst(arg);
52525238 const llvm_param_ty = try o.lowerType(param_ty);
5253 if (isByRef(param_ty, pt)) {
5254 const alignment = param_ty.abiAlignment(pt).toLlvm();
5239 if (isByRef(param_ty, zcu)) {
5240 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52555241 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");
52565242 try llvm_args.append(loaded);
52575243 } else {
......@@ -5262,10 +5248,10 @@ pub const FuncGen = struct {
52625248 const arg = args[it.zig_index - 1];
52635249 const param_ty = self.typeOf(arg);
52645250 const llvm_arg = try self.resolveInst(arg);
5265 if (isByRef(param_ty, pt)) {
5251 if (isByRef(param_ty, zcu)) {
52665252 try llvm_args.append(llvm_arg);
52675253 } else {
5268 const alignment = param_ty.abiAlignment(pt).toLlvm();
5254 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52695255 const param_llvm_ty = llvm_arg.typeOfWip(&self.wip);
52705256 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);
52715257 _ = try self.wip.store(.normal, llvm_arg, arg_ptr, alignment);
......@@ -5277,10 +5263,10 @@ pub const FuncGen = struct {
52775263 const param_ty = self.typeOf(arg);
52785264 const llvm_arg = try self.resolveInst(arg);
52795265
5280 const alignment = param_ty.abiAlignment(pt).toLlvm();
5266 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52815267 const param_llvm_ty = try o.lowerType(param_ty);
52825268 const arg_ptr = try self.buildAllocaWorkaround(param_ty, alignment);
5283 if (isByRef(param_ty, pt)) {
5269 if (isByRef(param_ty, zcu)) {
52845270 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");
52855271 _ = try self.wip.store(.normal, loaded, arg_ptr, alignment);
52865272 } else {
......@@ -5292,16 +5278,16 @@ pub const FuncGen = struct {
52925278 const arg = args[it.zig_index - 1];
52935279 const param_ty = self.typeOf(arg);
52945280 const llvm_arg = try self.resolveInst(arg);
5295 const int_llvm_ty = try o.builder.intType(@intCast(param_ty.abiSize(pt) * 8));
5281 const int_llvm_ty = try o.builder.intType(@intCast(param_ty.abiSize(zcu) * 8));
52965282
5297 if (isByRef(param_ty, pt)) {
5298 const alignment = param_ty.abiAlignment(pt).toLlvm();
5283 if (isByRef(param_ty, zcu)) {
5284 const alignment = param_ty.abiAlignment(zcu).toLlvm();
52995285 const loaded = try self.wip.load(.normal, int_llvm_ty, llvm_arg, alignment, "");
53005286 try llvm_args.append(loaded);
53015287 } else {
53025288 // LLVM does not allow bitcasting structs so we must allocate
53035289 // a local, store as one type, and then load as another type.
5304 const alignment = param_ty.abiAlignment(pt).toLlvm();
5290 const alignment = param_ty.abiAlignment(zcu).toLlvm();
53055291 const int_ptr = try self.buildAllocaWorkaround(param_ty, alignment);
53065292 _ = try self.wip.store(.normal, llvm_arg, int_ptr, alignment);
53075293 const loaded = try self.wip.load(.normal, int_llvm_ty, int_ptr, alignment, "");
......@@ -5320,9 +5306,9 @@ pub const FuncGen = struct {
53205306 const param_ty = self.typeOf(arg);
53215307 const llvm_types = it.types_buffer[0..it.types_len];
53225308 const llvm_arg = try self.resolveInst(arg);
5323 const is_by_ref = isByRef(param_ty, pt);
5309 const is_by_ref = isByRef(param_ty, zcu);
53245310 const arg_ptr = if (is_by_ref) llvm_arg else ptr: {
5325 const alignment = param_ty.abiAlignment(pt).toLlvm();
5311 const alignment = param_ty.abiAlignment(zcu).toLlvm();
53265312 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
53275313 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
53285314 break :ptr ptr;
......@@ -5348,14 +5334,14 @@ pub const FuncGen = struct {
53485334 const arg = args[it.zig_index - 1];
53495335 const arg_ty = self.typeOf(arg);
53505336 var llvm_arg = try self.resolveInst(arg);
5351 const alignment = arg_ty.abiAlignment(pt).toLlvm();
5352 if (!isByRef(arg_ty, pt)) {
5337 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
5338 if (!isByRef(arg_ty, zcu)) {
53535339 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
53545340 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
53555341 llvm_arg = ptr;
53565342 }
53575343
5358 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, mod).?);
5344 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(arg_ty, zcu).?);
53595345 const array_ty = try o.builder.arrayType(count, float_ty);
53605346
53615347 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");
......@@ -5366,8 +5352,8 @@ pub const FuncGen = struct {
53665352 const arg = args[it.zig_index - 1];
53675353 const arg_ty = self.typeOf(arg);
53685354 var llvm_arg = try self.resolveInst(arg);
5369 const alignment = arg_ty.abiAlignment(pt).toLlvm();
5370 if (!isByRef(arg_ty, pt)) {
5355 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
5356 if (!isByRef(arg_ty, zcu)) {
53715357 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
53725358 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
53735359 llvm_arg = ptr;
......@@ -5389,7 +5375,7 @@ pub const FuncGen = struct {
53895375 .byval => {
53905376 const param_index = it.zig_index - 1;
53915377 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
5392 if (!isByRef(param_ty, pt)) {
5378 if (!isByRef(param_ty, zcu)) {
53935379 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
53945380 }
53955381 },
......@@ -5397,7 +5383,7 @@ pub const FuncGen = struct {
53975383 const param_index = it.zig_index - 1;
53985384 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
53995385 const param_llvm_ty = try o.lowerType(param_ty);
5400 const alignment = param_ty.abiAlignment(pt).toLlvm();
5386 const alignment = param_ty.abiAlignment(zcu).toLlvm();
54015387 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
54025388 },
54035389 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
......@@ -5414,7 +5400,7 @@ pub const FuncGen = struct {
54145400 .slice => {
54155401 assert(!it.byval_attr);
54165402 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
5417 const ptr_info = param_ty.ptrInfo(mod);
5403 const ptr_info = param_ty.ptrInfo(zcu);
54185404 const llvm_arg_i = it.llvm_index - 2;
54195405
54205406 if (math.cast(u5, it.zig_index - 1)) |i| {
......@@ -5422,7 +5408,7 @@ pub const FuncGen = struct {
54225408 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
54235409 }
54245410 }
5425 if (param_ty.zigTypeTag(mod) != .Optional) {
5411 if (param_ty.zigTypeTag(zcu) != .Optional) {
54265412 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
54275413 }
54285414 if (ptr_info.flags.is_const) {
......@@ -5431,7 +5417,7 @@ pub const FuncGen = struct {
54315417 const elem_align = (if (ptr_info.flags.alignment != .none)
54325418 @as(InternPool.Alignment, ptr_info.flags.alignment)
54335419 else
5434 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1")).toLlvm();
5420 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1")).toLlvm();
54355421 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
54365422 },
54375423 };
......@@ -5456,17 +5442,17 @@ pub const FuncGen = struct {
54565442 return .none;
54575443 }
54585444
5459 if (self.liveness.isUnused(inst) or !return_type.hasRuntimeBitsIgnoreComptime(pt)) {
5445 if (self.liveness.isUnused(inst) or !return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
54605446 return .none;
54615447 }
54625448
54635449 const llvm_ret_ty = try o.lowerType(return_type);
54645450 if (ret_ptr) |rp| {
5465 if (isByRef(return_type, pt)) {
5451 if (isByRef(return_type, zcu)) {
54665452 return rp;
54675453 } else {
54685454 // our by-ref status disagrees with sret so we must load.
5469 const return_alignment = return_type.abiAlignment(pt).toLlvm();
5455 const return_alignment = return_type.abiAlignment(zcu).toLlvm();
54705456 return self.wip.load(.normal, llvm_ret_ty, rp, return_alignment, "");
54715457 }
54725458 }
......@@ -5477,19 +5463,19 @@ pub const FuncGen = struct {
54775463 // In this case the function return type is honoring the calling convention by having
54785464 // a different LLVM type than the usual one. We solve this here at the callsite
54795465 // by using our canonical type, then loading it if necessary.
5480 const alignment = return_type.abiAlignment(pt).toLlvm();
5466 const alignment = return_type.abiAlignment(zcu).toLlvm();
54815467 const rp = try self.buildAlloca(abi_ret_ty, alignment);
54825468 _ = try self.wip.store(.normal, call, rp, alignment);
5483 return if (isByRef(return_type, pt))
5469 return if (isByRef(return_type, zcu))
54845470 rp
54855471 else
54865472 try self.wip.load(.normal, llvm_ret_ty, rp, alignment, "");
54875473 }
54885474
5489 if (isByRef(return_type, pt)) {
5475 if (isByRef(return_type, zcu)) {
54905476 // our by-ref status disagrees with sret so we must allocate, store,
54915477 // and return the allocation pointer.
5492 const alignment = return_type.abiAlignment(pt).toLlvm();
5478 const alignment = return_type.abiAlignment(zcu).toLlvm();
54935479 const rp = try self.buildAlloca(llvm_ret_ty, alignment);
54945480 _ = try self.wip.store(.normal, call, rp, alignment);
54955481 return rp;
......@@ -5540,8 +5526,8 @@ pub const FuncGen = struct {
55405526 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
55415527 const o = self.ng.object;
55425528 const pt = o.pt;
5543 const mod = pt.zcu;
5544 const ip = &mod.intern_pool;
5529 const zcu = pt.zcu;
5530 const ip = &zcu.intern_pool;
55455531 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
55465532 const ret_ty = self.typeOf(un_op);
55475533
......@@ -5549,9 +5535,9 @@ pub const FuncGen = struct {
55495535 const ptr_ty = try pt.singleMutPtrType(ret_ty);
55505536
55515537 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;
5538 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
55535539 if (val_is_undef and safety) undef: {
5554 const ptr_info = ptr_ty.ptrInfo(mod);
5540 const ptr_info = ptr_ty.ptrInfo(zcu);
55555541 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);
55565542 if (needs_bitmask) {
55575543 // TODO: only some bits are to be undef, we cannot write with a simple memset.
......@@ -5559,13 +5545,13 @@ pub const FuncGen = struct {
55595545 // https://github.com/ziglang/zig/issues/15337
55605546 break :undef;
55615547 }
5562 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(pt));
5548 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu));
55635549 _ = try self.wip.callMemSet(
55645550 self.ret_ptr,
5565 ptr_ty.ptrAlignment(pt).toLlvm(),
5551 ptr_ty.ptrAlignment(zcu).toLlvm(),
55665552 try o.builder.intValue(.i8, 0xaa),
55675553 len,
5568 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,
5554 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
55695555 );
55705556 const owner_mod = self.ng.ownerModule();
55715557 if (owner_mod.valgrind) {
......@@ -5588,9 +5574,9 @@ pub const FuncGen = struct {
55885574 _ = try self.wip.retVoid();
55895575 return .none;
55905576 }
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)) {
5577 const fn_info = zcu.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5578 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5579 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
55945580 // Functions with an empty error set are emitted with an error code
55955581 // return type and return zero so they can be function pointers coerced
55965582 // to functions that return anyerror.
......@@ -5603,13 +5589,13 @@ pub const FuncGen = struct {
56035589
56045590 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
56055591 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();
5592 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
5593 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
56085594
56095595 if (val_is_undef and safety) {
56105596 const llvm_ret_ty = operand.typeOfWip(&self.wip);
56115597 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));
5598 const len = try o.builder.intValue(try o.lowerType(Type.usize), ret_ty.abiSize(zcu));
56135599 _ = try self.wip.callMemSet(
56145600 rp,
56155601 alignment,
......@@ -5625,7 +5611,7 @@ pub const FuncGen = struct {
56255611 return .none;
56265612 }
56275613
5628 if (isByRef(ret_ty, pt)) {
5614 if (isByRef(ret_ty, zcu)) {
56295615 // operand is a pointer however self.ret_ptr is null so that means
56305616 // we need to return a value.
56315617 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, operand, alignment, ""));
......@@ -5647,14 +5633,14 @@ pub const FuncGen = struct {
56475633 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
56485634 const o = self.ng.object;
56495635 const pt = o.pt;
5650 const mod = pt.zcu;
5651 const ip = &mod.intern_pool;
5636 const zcu = pt.zcu;
5637 const ip = &zcu.intern_pool;
56525638 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
56535639 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)) {
5640 const ret_ty = ptr_ty.childType(zcu);
5641 const fn_info = zcu.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5642 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5643 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
56585644 // Functions with an empty error set are emitted with an error code
56595645 // return type and return zero so they can be function pointers coerced
56605646 // to functions that return anyerror.
......@@ -5670,7 +5656,7 @@ pub const FuncGen = struct {
56705656 }
56715657 const ptr = try self.resolveInst(un_op);
56725658 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5673 const alignment = ret_ty.abiAlignment(pt).toLlvm();
5659 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
56745660 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));
56755661 return .none;
56765662 }
......@@ -5688,16 +5674,17 @@ pub const FuncGen = struct {
56885674 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
56895675 const o = self.ng.object;
56905676 const pt = o.pt;
5677 const zcu = pt.zcu;
56915678 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56925679 const src_list = try self.resolveInst(ty_op.operand);
56935680 const va_list_ty = ty_op.ty.toType();
56945681 const llvm_va_list_ty = try o.lowerType(va_list_ty);
56955682
5696 const result_alignment = va_list_ty.abiAlignment(pt).toLlvm();
5683 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
56975684 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);
56985685
56995686 _ = try self.wip.callIntrinsic(.normal, .none, .va_copy, &.{}, &.{ dest_list, src_list }, "");
5700 return if (isByRef(va_list_ty, pt))
5687 return if (isByRef(va_list_ty, zcu))
57015688 dest_list
57025689 else
57035690 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");
......@@ -5714,14 +5701,15 @@ pub const FuncGen = struct {
57145701 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
57155702 const o = self.ng.object;
57165703 const pt = o.pt;
5704 const zcu = pt.zcu;
57175705 const va_list_ty = self.typeOfIndex(inst);
57185706 const llvm_va_list_ty = try o.lowerType(va_list_ty);
57195707
5720 const result_alignment = va_list_ty.abiAlignment(pt).toLlvm();
5708 const result_alignment = va_list_ty.abiAlignment(pt.zcu).toLlvm();
57215709 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);
57225710
57235711 _ = try self.wip.callIntrinsic(.normal, .none, .va_start, &.{}, &.{dest_list}, "");
5724 return if (isByRef(va_list_ty, pt))
5712 return if (isByRef(va_list_ty, zcu))
57255713 dest_list
57265714 else
57275715 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");
......@@ -5779,21 +5767,21 @@ pub const FuncGen = struct {
57795767 ) Allocator.Error!Builder.Value {
57805768 const o = self.ng.object;
57815769 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),
5770 const zcu = pt.zcu;
5771 const scalar_ty = operand_ty.scalarType(zcu);
5772 const int_ty = switch (scalar_ty.zigTypeTag(zcu)) {
5773 .Enum => scalar_ty.intTagType(zcu),
57865774 .Int, .Bool, .Pointer, .ErrorSet => scalar_ty,
57875775 .Optional => blk: {
5788 const payload_ty = operand_ty.optionalChild(mod);
5789 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt) or
5790 operand_ty.optionalReprIsPayload(mod))
5776 const payload_ty = operand_ty.optionalChild(zcu);
5777 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu) or
5778 operand_ty.optionalReprIsPayload(zcu))
57915779 {
57925780 break :blk operand_ty;
57935781 }
57945782 // We need to emit instructions to check for equality/inequality
57955783 // of optionals that are not pointers.
5796 const is_by_ref = isByRef(scalar_ty, pt);
5784 const is_by_ref = isByRef(scalar_ty, zcu);
57975785 const opt_llvm_ty = try o.lowerType(scalar_ty);
57985786 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref);
57995787 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref);
......@@ -5860,7 +5848,7 @@ pub const FuncGen = struct {
58605848 .Float => return self.buildFloatCmp(fast, op, operand_ty, .{ lhs, rhs }),
58615849 else => unreachable,
58625850 };
5863 const is_signed = int_ty.isSignedInt(mod);
5851 const is_signed = int_ty.isSignedInt(zcu);
58645852 const cond: Builder.IntegerCondition = switch (op) {
58655853 .eq => .eq,
58665854 .neq => .ne,
......@@ -5886,15 +5874,15 @@ pub const FuncGen = struct {
58865874 ) !Builder.Value {
58875875 const o = self.ng.object;
58885876 const pt = o.pt;
5889 const mod = pt.zcu;
5877 const zcu = pt.zcu;
58905878 const inst_ty = self.typeOfIndex(inst);
58915879
5892 if (inst_ty.isNoReturn(mod)) {
5880 if (inst_ty.isNoReturn(zcu)) {
58935881 try self.genBodyDebugScope(maybe_inline_func, body);
58945882 return .none;
58955883 }
58965884
5897 const have_block_result = inst_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt);
5885 const have_block_result = inst_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu);
58985886
58995887 var breaks: BreakList = if (have_block_result) .{ .list = .{} } else .{ .len = 0 };
59005888 defer if (have_block_result) breaks.list.deinit(self.gpa);
......@@ -5918,7 +5906,7 @@ pub const FuncGen = struct {
59185906 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead
59195907 // of function pointers, however the phi makes it a runtime value and therefore
59205908 // the LLVM type has to be wrapped in a pointer.
5921 if (inst_ty.zigTypeTag(mod) == .Fn or isByRef(inst_ty, pt)) {
5909 if (inst_ty.zigTypeTag(zcu) == .Fn or isByRef(inst_ty, zcu)) {
59225910 break :ty .ptr;
59235911 }
59245912 break :ty raw_llvm_ty;
......@@ -5936,13 +5924,13 @@ pub const FuncGen = struct {
59365924
59375925 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
59385926 const o = self.ng.object;
5939 const pt = o.pt;
5927 const zcu = o.pt.zcu;
59405928 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
59415929 const block = self.blocks.get(branch.block_inst).?;
59425930
59435931 // Add the values to the lists only if the break provides a value.
59445932 const operand_ty = self.typeOf(branch.operand);
5945 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
5933 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
59465934 const val = try self.resolveInst(branch.operand);
59475935
59485936 // For the phi node, we need the basic blocks and the values of the
......@@ -5977,6 +5965,7 @@ pub const FuncGen = struct {
59775965 fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
59785966 const o = self.ng.object;
59795967 const pt = o.pt;
5968 const zcu = pt.zcu;
59805969 const inst = body_tail[0];
59815970 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
59825971 const err_union = try self.resolveInst(pl_op.operand);
......@@ -5984,19 +5973,19 @@ pub const FuncGen = struct {
59845973 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
59855974 const err_union_ty = self.typeOf(pl_op.operand);
59865975 const payload_ty = self.typeOfIndex(inst);
5987 const can_elide_load = if (isByRef(payload_ty, pt)) self.canElideLoad(body_tail) else false;
5976 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;
59885977 const is_unused = self.liveness.isUnused(inst);
59895978 return lowerTry(self, err_union, body, err_union_ty, false, can_elide_load, is_unused);
59905979 }
59915980
59925981 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
59935982 const o = self.ng.object;
5994 const mod = o.pt.zcu;
5983 const zcu = o.pt.zcu;
59955984 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
59965985 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
59975986 const err_union_ptr = try self.resolveInst(extra.data.ptr);
59985987 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);
5988 const err_union_ty = self.typeOf(extra.data.ptr).childType(zcu);
60005989 const is_unused = self.liveness.isUnused(inst);
60015990 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);
60025991 }
......@@ -6012,13 +6001,13 @@ pub const FuncGen = struct {
60126001 ) !Builder.Value {
60136002 const o = fg.ng.object;
60146003 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);
6004 const zcu = pt.zcu;
6005 const payload_ty = err_union_ty.errorUnionPayload(zcu);
6006 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
60186007 const err_union_llvm_ty = try o.lowerType(err_union_ty);
60196008 const error_type = try o.errorIntType();
60206009
6021 if (!err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
6010 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
60226011 const loaded = loaded: {
60236012 if (!payload_has_bits) {
60246013 // TODO add alignment to this load
......@@ -6028,7 +6017,7 @@ pub const FuncGen = struct {
60286017 err_union;
60296018 }
60306019 const err_field_index = try errUnionErrorOffset(payload_ty, pt);
6031 if (operand_is_ptr or isByRef(err_union_ty, pt)) {
6020 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
60326021 const err_field_ptr =
60336022 try fg.wip.gepStruct(err_union_llvm_ty, err_union, err_field_index, "");
60346023 // TODO add alignment to this load
......@@ -6059,10 +6048,10 @@ pub const FuncGen = struct {
60596048 const offset = try errUnionPayloadOffset(payload_ty, pt);
60606049 if (operand_is_ptr) {
60616050 return fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");
6062 } else if (isByRef(err_union_ty, pt)) {
6051 } else if (isByRef(err_union_ty, zcu)) {
60636052 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)) {
6053 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
6054 if (isByRef(payload_ty, zcu)) {
60666055 if (can_elide_load)
60676056 return payload_ptr;
60686057
......@@ -6140,7 +6129,7 @@ pub const FuncGen = struct {
61406129
61416130 fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
61426131 const o = self.ng.object;
6143 const mod = o.pt.zcu;
6132 const zcu = o.pt.zcu;
61446133 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
61456134 const loop = self.air.extraData(Air.Block, ty_pl.payload);
61466135 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);
......@@ -6156,7 +6145,7 @@ pub const FuncGen = struct {
61566145 // would have been emitted already. Also the main loop in genBody can
61576146 // be while(true) instead of for(body), which will eliminate 1 branch on
61586147 // a hot path.
6159 if (body.len == 0 or !self.typeOfIndex(body[body.len - 1]).isNoReturn(mod)) {
6148 if (body.len == 0 or !self.typeOfIndex(body[body.len - 1]).isNoReturn(zcu)) {
61606149 _ = try self.wip.br(loop_block);
61616150 }
61626151 return .none;
......@@ -6165,15 +6154,15 @@ pub const FuncGen = struct {
61656154 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
61666155 const o = self.ng.object;
61676156 const pt = o.pt;
6168 const mod = pt.zcu;
6157 const zcu = pt.zcu;
61696158 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61706159 const operand_ty = self.typeOf(ty_op.operand);
6171 const array_ty = operand_ty.childType(mod);
6160 const array_ty = operand_ty.childType(zcu);
61726161 const llvm_usize = try o.lowerType(Type.usize);
6173 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(mod));
6162 const len = try o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu));
61746163 const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
61756164 const operand = try self.resolveInst(ty_op.operand);
6176 if (!array_ty.hasRuntimeBitsIgnoreComptime(pt))
6165 if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
61776166 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");
61786167 const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{
61796168 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),
......@@ -6184,17 +6173,17 @@ pub const FuncGen = struct {
61846173 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
61856174 const o = self.ng.object;
61866175 const pt = o.pt;
6187 const mod = pt.zcu;
6176 const zcu = pt.zcu;
61886177 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61896178
61906179 const workaround_operand = try self.resolveInst(ty_op.operand);
61916180 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);
6181 const operand_scalar_ty = operand_ty.scalarType(zcu);
6182 const is_signed_int = operand_scalar_ty.isSignedInt(zcu);
61946183
61956184 const operand = o: {
61966185 // Work around LLVM bug. See https://github.com/ziglang/zig/issues/17381.
6197 const bit_size = operand_scalar_ty.bitSize(pt);
6186 const bit_size = operand_scalar_ty.bitSize(zcu);
61986187 for ([_]u8{ 8, 16, 32, 64, 128 }) |b| {
61996188 if (bit_size < b) {
62006189 break :o try self.wip.cast(
......@@ -6211,9 +6200,9 @@ pub const FuncGen = struct {
62116200 };
62126201
62136202 const dest_ty = self.typeOfIndex(inst);
6214 const dest_scalar_ty = dest_ty.scalarType(mod);
6203 const dest_scalar_ty = dest_ty.scalarType(zcu);
62156204 const dest_llvm_ty = try o.lowerType(dest_ty);
6216 const target = mod.getTarget();
6205 const target = zcu.getTarget();
62176206
62186207 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(
62196208 if (is_signed_int) .signed else .unsigned,
......@@ -6222,7 +6211,7 @@ pub const FuncGen = struct {
62226211 "",
62236212 );
62246213
6225 const rt_int_bits = compilerRtIntBits(@intCast(operand_scalar_ty.bitSize(pt)));
6214 const rt_int_bits = compilerRtIntBits(@intCast(operand_scalar_ty.bitSize(zcu)));
62266215 const rt_int_ty = try o.builder.intType(rt_int_bits);
62276216 var extended = try self.wip.conv(
62286217 if (is_signed_int) .signed else .unsigned,
......@@ -6269,29 +6258,29 @@ pub const FuncGen = struct {
62696258
62706259 const o = self.ng.object;
62716260 const pt = o.pt;
6272 const mod = pt.zcu;
6273 const target = mod.getTarget();
6261 const zcu = pt.zcu;
6262 const target = zcu.getTarget();
62746263 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
62756264
62766265 const operand = try self.resolveInst(ty_op.operand);
62776266 const operand_ty = self.typeOf(ty_op.operand);
6278 const operand_scalar_ty = operand_ty.scalarType(mod);
6267 const operand_scalar_ty = operand_ty.scalarType(zcu);
62796268
62806269 const dest_ty = self.typeOfIndex(inst);
6281 const dest_scalar_ty = dest_ty.scalarType(mod);
6270 const dest_scalar_ty = dest_ty.scalarType(zcu);
62826271 const dest_llvm_ty = try o.lowerType(dest_ty);
62836272
62846273 if (intrinsicsAllowed(operand_scalar_ty, target)) {
62856274 // TODO set fast math flag
62866275 return self.wip.conv(
6287 if (dest_scalar_ty.isSignedInt(mod)) .signed else .unsigned,
6276 if (dest_scalar_ty.isSignedInt(zcu)) .signed else .unsigned,
62886277 operand,
62896278 dest_llvm_ty,
62906279 "",
62916280 );
62926281 }
62936282
6294 const rt_int_bits = compilerRtIntBits(@intCast(dest_scalar_ty.bitSize(pt)));
6283 const rt_int_bits = compilerRtIntBits(@intCast(dest_scalar_ty.bitSize(zcu)));
62956284 const ret_ty = try o.builder.intType(rt_int_bits);
62966285 const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: {
62976286 // On Windows x86-64, "ti" functions must use Vector(2, u64) instead of the standard
......@@ -6303,7 +6292,7 @@ pub const FuncGen = struct {
63036292 const compiler_rt_operand_abbrev = compilerRtFloatAbbrev(operand_bits);
63046293
63056294 const compiler_rt_dest_abbrev = compilerRtIntAbbrev(rt_int_bits);
6306 const sign_prefix = if (dest_scalar_ty.isSignedInt(mod)) "" else "uns";
6295 const sign_prefix = if (dest_scalar_ty.isSignedInt(zcu)) "" else "uns";
63076296
63086297 const fn_name = try o.builder.strtabStringFmt("__fix{s}{s}f{s}i", .{
63096298 sign_prefix,
......@@ -6330,29 +6319,29 @@ pub const FuncGen = struct {
63306319
63316320 fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
63326321 const o = fg.ng.object;
6333 const mod = o.pt.zcu;
6334 return if (ty.isSlice(mod)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
6322 const zcu = o.pt.zcu;
6323 return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
63356324 }
63366325
63376326 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
63386327 const o = fg.ng.object;
63396328 const pt = o.pt;
6340 const mod = pt.zcu;
6329 const zcu = pt.zcu;
63416330 const llvm_usize = try o.lowerType(Type.usize);
6342 switch (ty.ptrSize(mod)) {
6331 switch (ty.ptrSize(zcu)) {
63436332 .Slice => {
63446333 const len = try fg.wip.extractValue(ptr, &.{1}, "");
6345 const elem_ty = ty.childType(mod);
6346 const abi_size = elem_ty.abiSize(pt);
6334 const elem_ty = ty.childType(zcu);
6335 const abi_size = elem_ty.abiSize(zcu);
63476336 if (abi_size == 1) return len;
63486337 const abi_size_llvm_val = try o.builder.intValue(llvm_usize, abi_size);
63496338 return fg.wip.bin(.@"mul nuw", len, abi_size_llvm_val, "");
63506339 },
63516340 .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);
6341 const array_ty = ty.childType(zcu);
6342 const elem_ty = array_ty.childType(zcu);
6343 const abi_size = elem_ty.abiSize(zcu);
6344 return o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu) * abi_size);
63566345 },
63576346 .Many, .C => unreachable,
63586347 }
......@@ -6366,11 +6355,11 @@ pub const FuncGen = struct {
63666355
63676356 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
63686357 const o = self.ng.object;
6369 const mod = o.pt.zcu;
6358 const zcu = o.pt.zcu;
63706359 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63716360 const slice_ptr = try self.resolveInst(ty_op.operand);
63726361 const slice_ptr_ty = self.typeOf(ty_op.operand);
6373 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(mod));
6362 const slice_llvm_ty = try o.lowerPtrElemTy(slice_ptr_ty.childType(zcu));
63746363
63756364 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");
63766365 }
......@@ -6378,21 +6367,21 @@ pub const FuncGen = struct {
63786367 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
63796368 const o = self.ng.object;
63806369 const pt = o.pt;
6381 const mod = pt.zcu;
6370 const zcu = pt.zcu;
63826371 const inst = body_tail[0];
63836372 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
63846373 const slice_ty = self.typeOf(bin_op.lhs);
63856374 const slice = try self.resolveInst(bin_op.lhs);
63866375 const index = try self.resolveInst(bin_op.rhs);
6387 const elem_ty = slice_ty.childType(mod);
6376 const elem_ty = slice_ty.childType(zcu);
63886377 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
63896378 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
63906379 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
6391 if (isByRef(elem_ty, pt)) {
6380 if (isByRef(elem_ty, zcu)) {
63926381 if (self.canElideLoad(body_tail))
63936382 return ptr;
63946383
6395 const elem_alignment = elem_ty.abiAlignment(pt).toLlvm();
6384 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
63966385 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);
63976386 }
63986387
......@@ -6401,14 +6390,14 @@ pub const FuncGen = struct {
64016390
64026391 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
64036392 const o = self.ng.object;
6404 const mod = o.pt.zcu;
6393 const zcu = o.pt.zcu;
64056394 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
64066395 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
64076396 const slice_ty = self.typeOf(bin_op.lhs);
64086397
64096398 const slice = try self.resolveInst(bin_op.lhs);
64106399 const index = try self.resolveInst(bin_op.rhs);
6411 const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(mod));
6400 const llvm_elem_ty = try o.lowerPtrElemTy(slice_ty.childType(zcu));
64126401 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
64136402 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
64146403 }
......@@ -6416,7 +6405,7 @@ pub const FuncGen = struct {
64166405 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
64176406 const o = self.ng.object;
64186407 const pt = o.pt;
6419 const mod = pt.zcu;
6408 const zcu = pt.zcu;
64206409 const inst = body_tail[0];
64216410
64226411 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
......@@ -6424,16 +6413,16 @@ pub const FuncGen = struct {
64246413 const array_llvm_val = try self.resolveInst(bin_op.lhs);
64256414 const rhs = try self.resolveInst(bin_op.rhs);
64266415 const array_llvm_ty = try o.lowerType(array_ty);
6427 const elem_ty = array_ty.childType(mod);
6428 if (isByRef(array_ty, pt)) {
6416 const elem_ty = array_ty.childType(zcu);
6417 if (isByRef(array_ty, zcu)) {
64296418 const indices: [2]Builder.Value = .{
64306419 try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs,
64316420 };
6432 if (isByRef(elem_ty, pt)) {
6421 if (isByRef(elem_ty, zcu)) {
64336422 const elem_ptr =
64346423 try self.wip.gep(.inbounds, array_llvm_ty, array_llvm_val, &indices, "");
64356424 if (canElideLoad(self, body_tail)) return elem_ptr;
6436 const elem_alignment = elem_ty.abiAlignment(pt).toLlvm();
6425 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
64376426 return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal);
64386427 } else {
64396428 const elem_ptr =
......@@ -6449,23 +6438,23 @@ pub const FuncGen = struct {
64496438 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
64506439 const o = self.ng.object;
64516440 const pt = o.pt;
6452 const mod = pt.zcu;
6441 const zcu = pt.zcu;
64536442 const inst = body_tail[0];
64546443 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
64556444 const ptr_ty = self.typeOf(bin_op.lhs);
6456 const elem_ty = ptr_ty.childType(mod);
6445 const elem_ty = ptr_ty.childType(zcu);
64576446 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
64586447 const base_ptr = try self.resolveInst(bin_op.lhs);
64596448 const rhs = try self.resolveInst(bin_op.rhs);
64606449 // 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))
6450 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
64626451 // If this is a single-item pointer to an array, we need another index in the GEP.
64636452 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
64646453 else
64656454 &.{rhs}, "");
6466 if (isByRef(elem_ty, pt)) {
6455 if (isByRef(elem_ty, zcu)) {
64676456 if (self.canElideLoad(body_tail)) return ptr;
6468 const elem_alignment = elem_ty.abiAlignment(pt).toLlvm();
6457 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
64696458 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);
64706459 }
64716460
......@@ -6475,21 +6464,21 @@ pub const FuncGen = struct {
64756464 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
64766465 const o = self.ng.object;
64776466 const pt = o.pt;
6478 const mod = pt.zcu;
6467 const zcu = pt.zcu;
64796468 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
64806469 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
64816470 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);
6471 const elem_ty = ptr_ty.childType(zcu);
6472 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return self.resolveInst(bin_op.lhs);
64846473
64856474 const base_ptr = try self.resolveInst(bin_op.lhs);
64866475 const rhs = try self.resolveInst(bin_op.rhs);
64876476
64886477 const elem_ptr = ty_pl.ty.toType();
6489 if (elem_ptr.ptrInfo(mod).flags.vector_index != .none) return base_ptr;
6478 if (elem_ptr.ptrInfo(zcu).flags.vector_index != .none) return base_ptr;
64906479
64916480 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))
6481 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, if (ptr_ty.isSinglePointer(zcu))
64936482 // If this is a single-item pointer to an array, we need another index in the GEP.
64946483 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
64956484 else
......@@ -6518,35 +6507,35 @@ pub const FuncGen = struct {
65186507 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
65196508 const o = self.ng.object;
65206509 const pt = o.pt;
6521 const mod = pt.zcu;
6510 const zcu = pt.zcu;
65226511 const inst = body_tail[0];
65236512 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
65246513 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
65256514 const struct_ty = self.typeOf(struct_field.struct_operand);
65266515 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);
65276516 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;
6517 const field_ty = struct_ty.fieldType(field_index, zcu);
6518 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
65306519
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)) {
6520 if (!isByRef(struct_ty, zcu)) {
6521 assert(!isByRef(field_ty, zcu));
6522 switch (struct_ty.zigTypeTag(zcu)) {
6523 .Struct => switch (struct_ty.containerLayout(zcu)) {
65356524 .@"packed" => {
6536 const struct_type = mod.typeToStruct(struct_ty).?;
6525 const struct_type = zcu.typeToStruct(struct_ty).?;
65376526 const bit_offset = pt.structPackedFieldBitOffset(struct_type, field_index);
65386527 const containing_int = struct_llvm_val;
65396528 const shift_amt =
65406529 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);
65416530 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
65426531 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)));
6532 if (field_ty.zigTypeTag(zcu) == .Float or field_ty.zigTypeTag(zcu) == .Vector) {
6533 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65456534 const truncated_int =
65466535 try self.wip.cast(.trunc, shifted_value, same_size_int, "");
65476536 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)));
6537 } else if (field_ty.isPtrAtRuntime(zcu)) {
6538 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65506539 const truncated_int =
65516540 try self.wip.cast(.trunc, shifted_value, same_size_int, "");
65526541 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
......@@ -6559,16 +6548,16 @@ pub const FuncGen = struct {
65596548 },
65606549 },
65616550 .Union => {
6562 assert(struct_ty.containerLayout(mod) == .@"packed");
6551 assert(struct_ty.containerLayout(zcu) == .@"packed");
65636552 const containing_int = struct_llvm_val;
65646553 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)));
6554 if (field_ty.zigTypeTag(zcu) == .Float or field_ty.zigTypeTag(zcu) == .Vector) {
6555 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65676556 const truncated_int =
65686557 try self.wip.cast(.trunc, containing_int, same_size_int, "");
65696558 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)));
6559 } else if (field_ty.isPtrAtRuntime(zcu)) {
6560 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
65726561 const truncated_int =
65736562 try self.wip.cast(.trunc, containing_int, same_size_int, "");
65746563 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
......@@ -6579,20 +6568,20 @@ pub const FuncGen = struct {
65796568 }
65806569 }
65816570
6582 switch (struct_ty.zigTypeTag(mod)) {
6571 switch (struct_ty.zigTypeTag(zcu)) {
65836572 .Struct => {
6584 const layout = struct_ty.containerLayout(mod);
6573 const layout = struct_ty.containerLayout(zcu);
65856574 assert(layout != .@"packed");
65866575 const struct_llvm_ty = try o.lowerType(struct_ty);
65876576 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
65886577 const field_ptr =
65896578 try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, "");
6590 const alignment = struct_ty.structFieldAlign(field_index, pt);
6579 const alignment = struct_ty.fieldAlignment(field_index, zcu);
65916580 const field_ptr_ty = try pt.ptrType(.{
65926581 .child = field_ty.toIntern(),
65936582 .flags = .{ .alignment = alignment },
65946583 });
6595 if (isByRef(field_ty, pt)) {
6584 if (isByRef(field_ty, zcu)) {
65966585 if (canElideLoad(self, body_tail))
65976586 return field_ptr;
65986587
......@@ -6605,12 +6594,12 @@ pub const FuncGen = struct {
66056594 },
66066595 .Union => {
66076596 const union_llvm_ty = try o.lowerType(struct_ty);
6608 const layout = struct_ty.unionGetLayout(pt);
6597 const layout = struct_ty.unionGetLayout(zcu);
66096598 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
66106599 const field_ptr =
66116600 try self.wip.gepStruct(union_llvm_ty, struct_llvm_val, payload_index, "");
66126601 const payload_alignment = layout.payload_align.toLlvm();
6613 if (isByRef(field_ty, pt)) {
6602 if (isByRef(field_ty, zcu)) {
66146603 if (canElideLoad(self, body_tail)) return field_ptr;
66156604 return self.loadByRef(field_ptr, field_ty, payload_alignment, .normal);
66166605 } else {
......@@ -6624,14 +6613,14 @@ pub const FuncGen = struct {
66246613 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66256614 const o = self.ng.object;
66266615 const pt = o.pt;
6627 const mod = pt.zcu;
6616 const zcu = pt.zcu;
66286617 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
66296618 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
66306619
66316620 const field_ptr = try self.resolveInst(extra.field_ptr);
66326621
6633 const parent_ty = ty_pl.ty.toType().childType(mod);
6634 const field_offset = parent_ty.structFieldOffset(extra.field_index, pt);
6622 const parent_ty = ty_pl.ty.toType().childType(zcu);
6623 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
66356624 if (field_offset == 0) return field_ptr;
66366625
66376626 const res_ty = try o.lowerType(ty_pl.ty.toType());
......@@ -6686,7 +6675,7 @@ pub const FuncGen = struct {
66866675
66876676 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
66886677 const o = self.ng.object;
6689 const mod = o.pt.zcu;
6678 const zcu = o.pt.zcu;
66906679 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
66916680 const operand = try self.resolveInst(pl_op.operand);
66926681 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
......@@ -6697,7 +6686,7 @@ pub const FuncGen = struct {
66976686 self.file,
66986687 self.scope,
66996688 self.prev_dbg_line,
6700 try o.lowerDebugType(ptr_ty.childType(mod)),
6689 try o.lowerDebugType(ptr_ty.childType(zcu)),
67016690 );
67026691
67036692 _ = try self.wip.callIntrinsic(
......@@ -6741,9 +6730,9 @@ pub const FuncGen = struct {
67416730 try o.lowerDebugType(operand_ty),
67426731 );
67436732
6744 const pt = o.pt;
6733 const zcu = o.pt.zcu;
67456734 const owner_mod = self.ng.ownerModule();
6746 if (isByRef(operand_ty, pt)) {
6735 if (isByRef(operand_ty, zcu)) {
67476736 _ = try self.wip.callIntrinsic(
67486737 .normal,
67496738 .none,
......@@ -6760,7 +6749,7 @@ pub const FuncGen = struct {
67606749 // We avoid taking this path for naked functions because there's no guarantee that such
67616750 // functions even have a valid stack pointer, making the `alloca` + `store` unsafe.
67626751
6763 const alignment = operand_ty.abiAlignment(pt).toLlvm();
6752 const alignment = operand_ty.abiAlignment(zcu).toLlvm();
67646753 const alloca = try self.buildAlloca(operand.typeOfWip(&self.wip), alignment);
67656754 _ = try self.wip.store(.normal, operand, alloca, alignment);
67666755 _ = try self.wip.callIntrinsic(
......@@ -6832,8 +6821,8 @@ pub const FuncGen = struct {
68326821 // if so, the element type itself.
68336822 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);
68346823 const pt = o.pt;
6835 const mod = pt.zcu;
6836 const target = mod.getTarget();
6824 const zcu = pt.zcu;
6825 const target = zcu.getTarget();
68376826
68386827 var llvm_ret_i: usize = 0;
68396828 var llvm_param_i: usize = 0;
......@@ -6860,8 +6849,8 @@ pub const FuncGen = struct {
68606849 if (output != .none) {
68616850 const output_inst = try self.resolveInst(output);
68626851 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));
6852 assert(output_ty.zigTypeTag(zcu) == .Pointer);
6853 const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(zcu));
68656854
68666855 switch (constraint[0]) {
68676856 '=' => {},
......@@ -6932,13 +6921,13 @@ pub const FuncGen = struct {
69326921
69336922 const arg_llvm_value = try self.resolveInst(input);
69346923 const arg_ty = self.typeOf(input);
6935 const is_by_ref = isByRef(arg_ty, pt);
6924 const is_by_ref = isByRef(arg_ty, zcu);
69366925 if (is_by_ref) {
69376926 if (constraintAllowsMemory(constraint)) {
69386927 llvm_param_values[llvm_param_i] = arg_llvm_value;
69396928 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
69406929 } else {
6941 const alignment = arg_ty.abiAlignment(pt).toLlvm();
6930 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
69426931 const arg_llvm_ty = try o.lowerType(arg_ty);
69436932 const load_inst =
69446933 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");
......@@ -6950,7 +6939,7 @@ pub const FuncGen = struct {
69506939 llvm_param_values[llvm_param_i] = arg_llvm_value;
69516940 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
69526941 } else {
6953 const alignment = arg_ty.abiAlignment(pt).toLlvm();
6942 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
69546943 const arg_ptr = try self.buildAlloca(arg_llvm_value.typeOfWip(&self.wip), alignment);
69556944 _ = try self.wip.store(.normal, arg_llvm_value, arg_ptr, alignment);
69566945 llvm_param_values[llvm_param_i] = arg_ptr;
......@@ -6978,7 +6967,7 @@ pub const FuncGen = struct {
69786967 // In the case of indirect inputs, LLVM requires the callsite to have
69796968 // an elementtype(<ty>) attribute.
69806969 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*')
6981 try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(mod))
6970 try o.lowerPtrElemTy(if (is_by_ref) arg_ty else arg_ty.childType(zcu))
69826971 else
69836972 .none;
69846973
......@@ -6997,12 +6986,12 @@ pub const FuncGen = struct {
69976986 if (constraint[0] != '+') continue;
69986987
69996988 const rw_ty = self.typeOf(output);
7000 const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(mod));
6989 const llvm_elem_ty = try o.lowerPtrElemTy(rw_ty.childType(zcu));
70016990 if (is_indirect) {
70026991 llvm_param_values[llvm_param_i] = llvm_rw_val;
70036992 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);
70046993 } else {
7005 const alignment = rw_ty.abiAlignment(pt).toLlvm();
6994 const alignment = rw_ty.abiAlignment(zcu).toLlvm();
70066995 const loaded = try self.wip.load(.normal, llvm_elem_ty, llvm_rw_val, alignment, "");
70076996 llvm_param_values[llvm_param_i] = loaded;
70086997 llvm_param_types[llvm_param_i] = llvm_elem_ty;
......@@ -7163,7 +7152,7 @@ pub const FuncGen = struct {
71637152 const output_ptr = try self.resolveInst(output);
71647153 const output_ptr_ty = self.typeOf(output);
71657154
7166 const alignment = output_ptr_ty.ptrAlignment(pt).toLlvm();
7155 const alignment = output_ptr_ty.ptrAlignment(zcu).toLlvm();
71677156 _ = try self.wip.store(.normal, output_value, output_ptr, alignment);
71687157 } else {
71697158 ret_val = output_value;
......@@ -7182,23 +7171,23 @@ pub const FuncGen = struct {
71827171 ) !Builder.Value {
71837172 const o = self.ng.object;
71847173 const pt = o.pt;
7185 const mod = pt.zcu;
7174 const zcu = pt.zcu;
71867175 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
71877176 const operand = try self.resolveInst(un_op);
71887177 const operand_ty = self.typeOf(un_op);
7189 const optional_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
7178 const optional_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
71907179 const optional_llvm_ty = try o.lowerType(optional_ty);
7191 const payload_ty = optional_ty.optionalChild(mod);
7192 if (optional_ty.optionalReprIsPayload(mod)) {
7180 const payload_ty = optional_ty.optionalChild(zcu);
7181 if (optional_ty.optionalReprIsPayload(zcu)) {
71937182 const loaded = if (operand_is_ptr)
71947183 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")
71957184 else
71967185 operand;
7197 if (payload_ty.isSlice(mod)) {
7186 if (payload_ty.isSlice(zcu)) {
71987187 const slice_ptr = try self.wip.extractValue(loaded, &.{0}, "");
71997188 const ptr_ty = try o.builder.ptrType(toLlvmAddressSpace(
7200 payload_ty.ptrAddressSpace(mod),
7201 mod.getTarget(),
7189 payload_ty.ptrAddressSpace(zcu),
7190 zcu.getTarget(),
72027191 ));
72037192 return self.wip.icmp(cond, slice_ptr, try o.builder.nullValue(ptr_ty), "");
72047193 }
......@@ -7207,7 +7196,7 @@ pub const FuncGen = struct {
72077196
72087197 comptime assert(optional_layout_version == 3);
72097198
7210 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7199 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72117200 const loaded = if (operand_is_ptr)
72127201 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")
72137202 else
......@@ -7215,7 +7204,7 @@ pub const FuncGen = struct {
72157204 return self.wip.icmp(cond, loaded, try o.builder.intValue(.i8, 0), "");
72167205 }
72177206
7218 const is_by_ref = operand_is_ptr or isByRef(optional_ty, pt);
7207 const is_by_ref = operand_is_ptr or isByRef(optional_ty, zcu);
72197208 return self.optCmpNull(cond, optional_llvm_ty, operand, is_by_ref);
72207209 }
72217210
......@@ -7227,16 +7216,16 @@ pub const FuncGen = struct {
72277216 ) !Builder.Value {
72287217 const o = self.ng.object;
72297218 const pt = o.pt;
7230 const mod = pt.zcu;
7219 const zcu = pt.zcu;
72317220 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
72327221 const operand = try self.resolveInst(un_op);
72337222 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);
7223 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7224 const payload_ty = err_union_ty.errorUnionPayload(zcu);
72367225 const error_type = try o.errorIntType();
72377226 const zero = try o.builder.intValue(error_type, 0);
72387227
7239 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {
7228 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
72407229 const val: Builder.Constant = switch (cond) {
72417230 .eq => .true, // 0 == 0
72427231 .ne => .false, // 0 != 0
......@@ -7245,7 +7234,7 @@ pub const FuncGen = struct {
72457234 return val.toValue();
72467235 }
72477236
7248 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7237 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72497238 const loaded = if (operand_is_ptr)
72507239 try self.wip.load(.normal, try o.lowerType(err_union_ty), operand, .default, "")
72517240 else
......@@ -7255,7 +7244,7 @@ pub const FuncGen = struct {
72557244
72567245 const err_field_index = try errUnionErrorOffset(payload_ty, pt);
72577246
7258 const loaded = if (operand_is_ptr or isByRef(err_union_ty, pt)) loaded: {
7247 const loaded = if (operand_is_ptr or isByRef(err_union_ty, zcu)) loaded: {
72597248 const err_union_llvm_ty = try o.lowerType(err_union_ty);
72607249 const err_field_ptr =
72617250 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");
......@@ -7267,17 +7256,17 @@ pub const FuncGen = struct {
72677256 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
72687257 const o = self.ng.object;
72697258 const pt = o.pt;
7270 const mod = pt.zcu;
7259 const zcu = pt.zcu;
72717260 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
72727261 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)) {
7262 const optional_ty = self.typeOf(ty_op.operand).childType(zcu);
7263 const payload_ty = optional_ty.optionalChild(zcu);
7264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72767265 // We have a pointer to a zero-bit value and we need to return
72777266 // a pointer to a zero-bit value.
72787267 return operand;
72797268 }
7280 if (optional_ty.optionalReprIsPayload(mod)) {
7269 if (optional_ty.optionalReprIsPayload(zcu)) {
72817270 // The payload and the optional are the same value.
72827271 return operand;
72837272 }
......@@ -7289,18 +7278,18 @@ pub const FuncGen = struct {
72897278
72907279 const o = self.ng.object;
72917280 const pt = o.pt;
7292 const mod = pt.zcu;
7281 const zcu = pt.zcu;
72937282 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
72947283 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);
7284 const optional_ty = self.typeOf(ty_op.operand).childType(zcu);
7285 const payload_ty = optional_ty.optionalChild(zcu);
72977286 const non_null_bit = try o.builder.intValue(.i8, 1);
7298 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7287 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
72997288 // We have a pointer to a i8. We need to set it to 1 and then return the same pointer.
73007289 _ = try self.wip.store(.normal, non_null_bit, operand, .default);
73017290 return operand;
73027291 }
7303 if (optional_ty.optionalReprIsPayload(mod)) {
7292 if (optional_ty.optionalReprIsPayload(zcu)) {
73047293 // The payload and the optional are the same value.
73057294 // Setting to non-null will be done when the payload is set.
73067295 return operand;
......@@ -7321,21 +7310,21 @@ pub const FuncGen = struct {
73217310 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
73227311 const o = self.ng.object;
73237312 const pt = o.pt;
7324 const mod = pt.zcu;
7313 const zcu = pt.zcu;
73257314 const inst = body_tail[0];
73267315 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73277316 const operand = try self.resolveInst(ty_op.operand);
73287317 const optional_ty = self.typeOf(ty_op.operand);
73297318 const payload_ty = self.typeOfIndex(inst);
7330 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
7319 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
73317320
7332 if (optional_ty.optionalReprIsPayload(mod)) {
7321 if (optional_ty.optionalReprIsPayload(zcu)) {
73337322 // Payload value is the same as the optional value.
73347323 return operand;
73357324 }
73367325
73377326 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;
7327 const can_elide_load = if (isByRef(payload_ty, zcu)) self.canElideLoad(body_tail) else false;
73397328 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);
73407329 }
73417330
......@@ -7346,26 +7335,26 @@ pub const FuncGen = struct {
73467335 ) !Builder.Value {
73477336 const o = self.ng.object;
73487337 const pt = o.pt;
7349 const mod = pt.zcu;
7338 const zcu = pt.zcu;
73507339 const inst = body_tail[0];
73517340 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73527341 const operand = try self.resolveInst(ty_op.operand);
73537342 const operand_ty = self.typeOf(ty_op.operand);
7354 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
7343 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
73557344 const result_ty = self.typeOfIndex(inst);
7356 const payload_ty = if (operand_is_ptr) result_ty.childType(mod) else result_ty;
7345 const payload_ty = if (operand_is_ptr) result_ty.childType(zcu) else result_ty;
73577346
7358 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7347 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
73597348 return if (operand_is_ptr) operand else .none;
73607349 }
73617350 const offset = try errUnionPayloadOffset(payload_ty, pt);
73627351 const err_union_llvm_ty = try o.lowerType(err_union_ty);
73637352 if (operand_is_ptr) {
73647353 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();
7354 } else if (isByRef(err_union_ty, zcu)) {
7355 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
73677356 const payload_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
7368 if (isByRef(payload_ty, pt)) {
7357 if (isByRef(payload_ty, zcu)) {
73697358 if (self.canElideLoad(body_tail)) return payload_ptr;
73707359 return self.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal);
73717360 }
......@@ -7382,13 +7371,13 @@ pub const FuncGen = struct {
73827371 ) !Builder.Value {
73837372 const o = self.ng.object;
73847373 const pt = o.pt;
7385 const mod = pt.zcu;
7374 const zcu = pt.zcu;
73867375 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73877376 const operand = try self.resolveInst(ty_op.operand);
73887377 const operand_ty = self.typeOf(ty_op.operand);
73897378 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)) {
7379 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7380 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
73927381 if (operand_is_ptr) {
73937382 return operand;
73947383 } else {
......@@ -7396,15 +7385,15 @@ pub const FuncGen = struct {
73967385 }
73977386 }
73987387
7399 const payload_ty = err_union_ty.errorUnionPayload(mod);
7400 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7388 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7389 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
74017390 if (!operand_is_ptr) return operand;
74027391 return self.wip.load(.normal, error_type, operand, .default, "");
74037392 }
74047393
74057394 const offset = try errUnionErrorOffset(payload_ty, pt);
74067395
7407 if (operand_is_ptr or isByRef(err_union_ty, pt)) {
7396 if (operand_is_ptr or isByRef(err_union_ty, zcu)) {
74087397 const err_union_llvm_ty = try o.lowerType(err_union_ty);
74097398 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
74107399 return self.wip.load(.normal, error_type, err_field_ptr, .default, "");
......@@ -7416,21 +7405,21 @@ pub const FuncGen = struct {
74167405 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
74177406 const o = self.ng.object;
74187407 const pt = o.pt;
7419 const mod = pt.zcu;
7408 const zcu = pt.zcu;
74207409 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
74217410 const operand = try self.resolveInst(ty_op.operand);
7422 const err_union_ty = self.typeOf(ty_op.operand).childType(mod);
7411 const err_union_ty = self.typeOf(ty_op.operand).childType(zcu);
74237412
7424 const payload_ty = err_union_ty.errorUnionPayload(mod);
7413 const payload_ty = err_union_ty.errorUnionPayload(zcu);
74257414 const non_error_val = try o.builder.intValue(try o.errorIntType(), 0);
7426 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7415 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
74277416 _ = try self.wip.store(.normal, non_error_val, operand, .default);
74287417 return operand;
74297418 }
74307419 const err_union_llvm_ty = try o.lowerType(err_union_ty);
74317420 {
74327421 const err_int_ty = try pt.errorIntType();
7433 const error_alignment = err_int_ty.abiAlignment(pt).toLlvm();
7422 const error_alignment = err_int_ty.abiAlignment(zcu).toLlvm();
74347423 const error_offset = try errUnionErrorOffset(payload_ty, pt);
74357424 // First set the non-error value.
74367425 const non_null_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, error_offset, "");
......@@ -7457,7 +7446,7 @@ pub const FuncGen = struct {
74577446 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
74587447 const o = self.ng.object;
74597448 const pt = o.pt;
7460 const mod = pt.zcu;
7449 const zcu = pt.zcu;
74617450
74627451 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
74637452 const struct_ty = ty_pl.ty.toType();
......@@ -7468,8 +7457,8 @@ pub const FuncGen = struct {
74687457 assert(self.err_ret_trace != .none);
74697458 const field_ptr =
74707459 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);
7460 const field_alignment = struct_ty.fieldAlignment(field_index, zcu);
7461 const field_ty = struct_ty.fieldType(field_index, zcu);
74737462 const field_ptr_ty = try pt.ptrType(.{
74747463 .child = field_ty.toIntern(),
74757464 .flags = .{ .alignment = field_alignment },
......@@ -7503,23 +7492,23 @@ pub const FuncGen = struct {
75037492 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
75047493 const o = self.ng.object;
75057494 const pt = o.pt;
7506 const mod = pt.zcu;
7495 const zcu = pt.zcu;
75077496 const inst = body_tail[0];
75087497 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
75097498 const payload_ty = self.typeOf(ty_op.operand);
75107499 const non_null_bit = try o.builder.intValue(.i8, 1);
75117500 comptime assert(optional_layout_version == 3);
7512 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return non_null_bit;
7501 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return non_null_bit;
75137502 const operand = try self.resolveInst(ty_op.operand);
75147503 const optional_ty = self.typeOfIndex(inst);
7515 if (optional_ty.optionalReprIsPayload(mod)) return operand;
7504 if (optional_ty.optionalReprIsPayload(zcu)) return operand;
75167505 const llvm_optional_ty = try o.lowerType(optional_ty);
7517 if (isByRef(optional_ty, pt)) {
7506 if (isByRef(optional_ty, zcu)) {
75187507 const directReturn = self.isNextRet(body_tail);
75197508 const optional_ptr = if (directReturn)
75207509 self.ret_ptr
75217510 else brk: {
7522 const alignment = optional_ty.abiAlignment(pt).toLlvm();
7511 const alignment = optional_ty.abiAlignment(zcu).toLlvm();
75237512 const optional_ptr = try self.buildAllocaWorkaround(optional_ty, alignment);
75247513 break :brk optional_ptr;
75257514 };
......@@ -7537,12 +7526,13 @@ pub const FuncGen = struct {
75377526 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
75387527 const o = self.ng.object;
75397528 const pt = o.pt;
7529 const zcu = pt.zcu;
75407530 const inst = body_tail[0];
75417531 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
75427532 const err_un_ty = self.typeOfIndex(inst);
75437533 const operand = try self.resolveInst(ty_op.operand);
75447534 const payload_ty = self.typeOf(ty_op.operand);
7545 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
7535 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
75467536 return operand;
75477537 }
75487538 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);
......@@ -7550,19 +7540,19 @@ pub const FuncGen = struct {
75507540
75517541 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
75527542 const error_offset = try errUnionErrorOffset(payload_ty, pt);
7553 if (isByRef(err_un_ty, pt)) {
7543 if (isByRef(err_un_ty, zcu)) {
75547544 const directReturn = self.isNextRet(body_tail);
75557545 const result_ptr = if (directReturn)
75567546 self.ret_ptr
75577547 else brk: {
7558 const alignment = err_un_ty.abiAlignment(pt).toLlvm();
7548 const alignment = err_un_ty.abiAlignment(pt.zcu).toLlvm();
75597549 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);
75607550 break :brk result_ptr;
75617551 };
75627552
75637553 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");
75647554 const err_int_ty = try pt.errorIntType();
7565 const error_alignment = err_int_ty.abiAlignment(pt).toLlvm();
7555 const error_alignment = err_int_ty.abiAlignment(pt.zcu).toLlvm();
75667556 _ = try self.wip.store(.normal, ok_err_code, err_ptr, error_alignment);
75677557 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");
75687558 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);
......@@ -7578,30 +7568,30 @@ pub const FuncGen = struct {
75787568 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
75797569 const o = self.ng.object;
75807570 const pt = o.pt;
7581 const mod = pt.zcu;
7571 const zcu = pt.zcu;
75827572 const inst = body_tail[0];
75837573 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
75847574 const err_un_ty = self.typeOfIndex(inst);
7585 const payload_ty = err_un_ty.errorUnionPayload(mod);
7575 const payload_ty = err_un_ty.errorUnionPayload(zcu);
75867576 const operand = try self.resolveInst(ty_op.operand);
7587 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return operand;
7577 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand;
75887578 const err_un_llvm_ty = try o.lowerType(err_un_ty);
75897579
75907580 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
75917581 const error_offset = try errUnionErrorOffset(payload_ty, pt);
7592 if (isByRef(err_un_ty, pt)) {
7582 if (isByRef(err_un_ty, zcu)) {
75937583 const directReturn = self.isNextRet(body_tail);
75947584 const result_ptr = if (directReturn)
75957585 self.ret_ptr
75967586 else brk: {
7597 const alignment = err_un_ty.abiAlignment(pt).toLlvm();
7587 const alignment = err_un_ty.abiAlignment(zcu).toLlvm();
75987588 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);
75997589 break :brk result_ptr;
76007590 };
76017591
76027592 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");
76037593 const err_int_ty = try pt.errorIntType();
7604 const error_alignment = err_int_ty.abiAlignment(pt).toLlvm();
7594 const error_alignment = err_int_ty.abiAlignment(zcu).toLlvm();
76057595 _ = try self.wip.store(.normal, operand, err_ptr, error_alignment);
76067596 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");
76077597 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);
......@@ -7639,7 +7629,7 @@ pub const FuncGen = struct {
76397629 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
76407630 const o = self.ng.object;
76417631 const pt = o.pt;
7642 const mod = pt.zcu;
7632 const zcu = pt.zcu;
76437633 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
76447634 const extra = self.air.extraData(Air.Bin, data.payload).data;
76457635
......@@ -7649,9 +7639,9 @@ pub const FuncGen = struct {
76497639 const operand = try self.resolveInst(extra.rhs);
76507640
76517641 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();
7642 if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
7643 const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(zcu));
7644 const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm();
76557645 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");
76567646
76577647 const new_vector = try self.wip.insertElement(loaded, operand, index, "");
......@@ -7661,18 +7651,18 @@ pub const FuncGen = struct {
76617651
76627652 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
76637653 const o = self.ng.object;
7664 const mod = o.pt.zcu;
7654 const zcu = o.pt.zcu;
76657655 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
76667656 const lhs = try self.resolveInst(bin_op.lhs);
76677657 const rhs = try self.resolveInst(bin_op.rhs);
76687658 const inst_ty = self.typeOfIndex(inst);
7669 const scalar_ty = inst_ty.scalarType(mod);
7659 const scalar_ty = inst_ty.scalarType(zcu);
76707660
76717661 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmin, .normal, inst_ty, 2, .{ lhs, rhs });
76727662 return self.wip.callIntrinsic(
76737663 .normal,
76747664 .none,
7675 if (scalar_ty.isSignedInt(mod)) .smin else .umin,
7665 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,
76767666 &.{try o.lowerType(inst_ty)},
76777667 &.{ lhs, rhs },
76787668 "",
......@@ -7681,18 +7671,18 @@ pub const FuncGen = struct {
76817671
76827672 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
76837673 const o = self.ng.object;
7684 const mod = o.pt.zcu;
7674 const zcu = o.pt.zcu;
76857675 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
76867676 const lhs = try self.resolveInst(bin_op.lhs);
76877677 const rhs = try self.resolveInst(bin_op.rhs);
76887678 const inst_ty = self.typeOfIndex(inst);
7689 const scalar_ty = inst_ty.scalarType(mod);
7679 const scalar_ty = inst_ty.scalarType(zcu);
76907680
76917681 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmax, .normal, inst_ty, 2, .{ lhs, rhs });
76927682 return self.wip.callIntrinsic(
76937683 .normal,
76947684 .none,
7695 if (scalar_ty.isSignedInt(mod)) .smax else .umax,
7685 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,
76967686 &.{try o.lowerType(inst_ty)},
76977687 &.{ lhs, rhs },
76987688 "",
......@@ -7711,15 +7701,15 @@ pub const FuncGen = struct {
77117701
77127702 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
77137703 const o = self.ng.object;
7714 const mod = o.pt.zcu;
7704 const zcu = o.pt.zcu;
77157705 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77167706 const lhs = try self.resolveInst(bin_op.lhs);
77177707 const rhs = try self.resolveInst(bin_op.rhs);
77187708 const inst_ty = self.typeOfIndex(inst);
7719 const scalar_ty = inst_ty.scalarType(mod);
7709 const scalar_ty = inst_ty.scalarType(zcu);
77207710
77217711 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, "");
7712 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .@"add nsw" else .@"add nuw", lhs, rhs, "");
77237713 }
77247714
77257715 fn airSafeArithmetic(
......@@ -7729,15 +7719,15 @@ pub const FuncGen = struct {
77297719 unsigned_intrinsic: Builder.Intrinsic,
77307720 ) !Builder.Value {
77317721 const o = fg.ng.object;
7732 const mod = o.pt.zcu;
7722 const zcu = o.pt.zcu;
77337723
77347724 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77357725 const lhs = try fg.resolveInst(bin_op.lhs);
77367726 const rhs = try fg.resolveInst(bin_op.rhs);
77377727 const inst_ty = fg.typeOfIndex(inst);
7738 const scalar_ty = inst_ty.scalarType(mod);
7728 const scalar_ty = inst_ty.scalarType(zcu);
77397729
7740 const intrinsic = if (scalar_ty.isSignedInt(mod)) signed_intrinsic else unsigned_intrinsic;
7730 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
77417731 const llvm_inst_ty = try o.lowerType(inst_ty);
77427732 const results =
77437733 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");
......@@ -7777,18 +7767,18 @@ pub const FuncGen = struct {
77777767
77787768 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
77797769 const o = self.ng.object;
7780 const mod = o.pt.zcu;
7770 const zcu = o.pt.zcu;
77817771 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77827772 const lhs = try self.resolveInst(bin_op.lhs);
77837773 const rhs = try self.resolveInst(bin_op.rhs);
77847774 const inst_ty = self.typeOfIndex(inst);
7785 const scalar_ty = inst_ty.scalarType(mod);
7775 const scalar_ty = inst_ty.scalarType(zcu);
77867776
77877777 if (scalar_ty.isAnyFloat()) return self.todo("saturating float add", .{});
77887778 return self.wip.callIntrinsic(
77897779 .normal,
77907780 .none,
7791 if (scalar_ty.isSignedInt(mod)) .@"sadd.sat" else .@"uadd.sat",
7781 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",
77927782 &.{try o.lowerType(inst_ty)},
77937783 &.{ lhs, rhs },
77947784 "",
......@@ -7797,15 +7787,15 @@ pub const FuncGen = struct {
77977787
77987788 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
77997789 const o = self.ng.object;
7800 const mod = o.pt.zcu;
7790 const zcu = o.pt.zcu;
78017791 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78027792 const lhs = try self.resolveInst(bin_op.lhs);
78037793 const rhs = try self.resolveInst(bin_op.rhs);
78047794 const inst_ty = self.typeOfIndex(inst);
7805 const scalar_ty = inst_ty.scalarType(mod);
7795 const scalar_ty = inst_ty.scalarType(zcu);
78067796
78077797 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, "");
7798 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .@"sub nsw" else .@"sub nuw", lhs, rhs, "");
78097799 }
78107800
78117801 fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
......@@ -7818,18 +7808,18 @@ pub const FuncGen = struct {
78187808
78197809 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
78207810 const o = self.ng.object;
7821 const mod = o.pt.zcu;
7811 const zcu = o.pt.zcu;
78227812 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78237813 const lhs = try self.resolveInst(bin_op.lhs);
78247814 const rhs = try self.resolveInst(bin_op.rhs);
78257815 const inst_ty = self.typeOfIndex(inst);
7826 const scalar_ty = inst_ty.scalarType(mod);
7816 const scalar_ty = inst_ty.scalarType(zcu);
78277817
78287818 if (scalar_ty.isAnyFloat()) return self.todo("saturating float sub", .{});
78297819 return self.wip.callIntrinsic(
78307820 .normal,
78317821 .none,
7832 if (scalar_ty.isSignedInt(mod)) .@"ssub.sat" else .@"usub.sat",
7822 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",
78337823 &.{try o.lowerType(inst_ty)},
78347824 &.{ lhs, rhs },
78357825 "",
......@@ -7838,15 +7828,15 @@ pub const FuncGen = struct {
78387828
78397829 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
78407830 const o = self.ng.object;
7841 const mod = o.pt.zcu;
7831 const zcu = o.pt.zcu;
78427832 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78437833 const lhs = try self.resolveInst(bin_op.lhs);
78447834 const rhs = try self.resolveInst(bin_op.rhs);
78457835 const inst_ty = self.typeOfIndex(inst);
7846 const scalar_ty = inst_ty.scalarType(mod);
7836 const scalar_ty = inst_ty.scalarType(zcu);
78477837
78487838 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, "");
7839 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .@"mul nsw" else .@"mul nuw", lhs, rhs, "");
78507840 }
78517841
78527842 fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
......@@ -7859,18 +7849,18 @@ pub const FuncGen = struct {
78597849
78607850 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
78617851 const o = self.ng.object;
7862 const mod = o.pt.zcu;
7852 const zcu = o.pt.zcu;
78637853 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78647854 const lhs = try self.resolveInst(bin_op.lhs);
78657855 const rhs = try self.resolveInst(bin_op.rhs);
78667856 const inst_ty = self.typeOfIndex(inst);
7867 const scalar_ty = inst_ty.scalarType(mod);
7857 const scalar_ty = inst_ty.scalarType(zcu);
78687858
78697859 if (scalar_ty.isAnyFloat()) return self.todo("saturating float mul", .{});
78707860 return self.wip.callIntrinsic(
78717861 .normal,
78727862 .none,
7873 if (scalar_ty.isSignedInt(mod)) .@"smul.fix.sat" else .@"umul.fix.sat",
7863 if (scalar_ty.isSignedInt(zcu)) .@"smul.fix.sat" else .@"umul.fix.sat",
78747864 &.{try o.lowerType(inst_ty)},
78757865 &.{ lhs, rhs, .@"0" },
78767866 "",
......@@ -7888,34 +7878,34 @@ pub const FuncGen = struct {
78887878
78897879 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
78907880 const o = self.ng.object;
7891 const mod = o.pt.zcu;
7881 const zcu = o.pt.zcu;
78927882 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
78937883 const lhs = try self.resolveInst(bin_op.lhs);
78947884 const rhs = try self.resolveInst(bin_op.rhs);
78957885 const inst_ty = self.typeOfIndex(inst);
7896 const scalar_ty = inst_ty.scalarType(mod);
7886 const scalar_ty = inst_ty.scalarType(zcu);
78977887
78987888 if (scalar_ty.isRuntimeFloat()) {
78997889 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
79007890 return self.buildFloatOp(.trunc, fast, inst_ty, 1, .{result});
79017891 }
7902 return self.wip.bin(if (scalar_ty.isSignedInt(mod)) .sdiv else .udiv, lhs, rhs, "");
7892 return self.wip.bin(if (scalar_ty.isSignedInt(zcu)) .sdiv else .udiv, lhs, rhs, "");
79037893 }
79047894
79057895 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79067896 const o = self.ng.object;
7907 const mod = o.pt.zcu;
7897 const zcu = o.pt.zcu;
79087898 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79097899 const lhs = try self.resolveInst(bin_op.lhs);
79107900 const rhs = try self.resolveInst(bin_op.rhs);
79117901 const inst_ty = self.typeOfIndex(inst);
7912 const scalar_ty = inst_ty.scalarType(mod);
7902 const scalar_ty = inst_ty.scalarType(zcu);
79137903
79147904 if (scalar_ty.isRuntimeFloat()) {
79157905 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
79167906 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});
79177907 }
7918 if (scalar_ty.isSignedInt(mod)) {
7908 if (scalar_ty.isSignedInt(zcu)) {
79197909 const inst_llvm_ty = try o.lowerType(inst_ty);
79207910 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(
79217911 inst_llvm_ty.scalarType(&o.builder),
......@@ -7936,16 +7926,16 @@ pub const FuncGen = struct {
79367926
79377927 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79387928 const o = self.ng.object;
7939 const mod = o.pt.zcu;
7929 const zcu = o.pt.zcu;
79407930 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79417931 const lhs = try self.resolveInst(bin_op.lhs);
79427932 const rhs = try self.resolveInst(bin_op.rhs);
79437933 const inst_ty = self.typeOfIndex(inst);
7944 const scalar_ty = inst_ty.scalarType(mod);
7934 const scalar_ty = inst_ty.scalarType(zcu);
79457935
79467936 if (scalar_ty.isRuntimeFloat()) return self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
79477937 return self.wip.bin(
7948 if (scalar_ty.isSignedInt(mod)) .@"sdiv exact" else .@"udiv exact",
7938 if (scalar_ty.isSignedInt(zcu)) .@"sdiv exact" else .@"udiv exact",
79497939 lhs,
79507940 rhs,
79517941 "",
......@@ -7954,16 +7944,16 @@ pub const FuncGen = struct {
79547944
79557945 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79567946 const o = self.ng.object;
7957 const mod = o.pt.zcu;
7947 const zcu = o.pt.zcu;
79587948 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79597949 const lhs = try self.resolveInst(bin_op.lhs);
79607950 const rhs = try self.resolveInst(bin_op.rhs);
79617951 const inst_ty = self.typeOfIndex(inst);
7962 const scalar_ty = inst_ty.scalarType(mod);
7952 const scalar_ty = inst_ty.scalarType(zcu);
79637953
79647954 if (scalar_ty.isRuntimeFloat())
79657955 return self.buildFloatOp(.fmod, fast, inst_ty, 2, .{ lhs, rhs });
7966 return self.wip.bin(if (scalar_ty.isSignedInt(mod))
7956 return self.wip.bin(if (scalar_ty.isSignedInt(zcu))
79677957 .srem
79687958 else
79697959 .urem, lhs, rhs, "");
......@@ -7971,13 +7961,13 @@ pub const FuncGen = struct {
79717961
79727962 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
79737963 const o = self.ng.object;
7974 const mod = o.pt.zcu;
7964 const zcu = o.pt.zcu;
79757965 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
79767966 const lhs = try self.resolveInst(bin_op.lhs);
79777967 const rhs = try self.resolveInst(bin_op.rhs);
79787968 const inst_ty = self.typeOfIndex(inst);
79797969 const inst_llvm_ty = try o.lowerType(inst_ty);
7980 const scalar_ty = inst_ty.scalarType(mod);
7970 const scalar_ty = inst_ty.scalarType(zcu);
79817971
79827972 if (scalar_ty.isRuntimeFloat()) {
79837973 const a = try self.buildFloatOp(.fmod, fast, inst_ty, 2, .{ lhs, rhs });
......@@ -7987,7 +7977,7 @@ pub const FuncGen = struct {
79877977 const ltz = try self.buildFloatCmp(fast, .lt, inst_ty, .{ lhs, zero });
79887978 return self.wip.select(fast, ltz, c, a, "");
79897979 }
7990 if (scalar_ty.isSignedInt(mod)) {
7980 if (scalar_ty.isSignedInt(zcu)) {
79917981 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(
79927982 inst_llvm_ty.scalarType(&o.builder),
79937983 inst_llvm_ty.scalarBits(&o.builder) - 1,
......@@ -8007,14 +7997,14 @@ pub const FuncGen = struct {
80077997
80087998 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
80097999 const o = self.ng.object;
8010 const mod = o.pt.zcu;
8000 const zcu = o.pt.zcu;
80118001 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
80128002 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
80138003 const ptr = try self.resolveInst(bin_op.lhs);
80148004 const offset = try self.resolveInst(bin_op.rhs);
80158005 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)) {
8006 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8007 switch (ptr_ty.ptrSize(zcu)) {
80188008 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
80198009 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
80208010 try o.builder.intValue(try o.lowerType(Type.usize), 0), offset,
......@@ -8029,15 +8019,15 @@ pub const FuncGen = struct {
80298019
80308020 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
80318021 const o = self.ng.object;
8032 const mod = o.pt.zcu;
8022 const zcu = o.pt.zcu;
80338023 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
80348024 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
80358025 const ptr = try self.resolveInst(bin_op.lhs);
80368026 const offset = try self.resolveInst(bin_op.rhs);
80378027 const negative_offset = try self.wip.neg(offset, "");
80388028 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)) {
8029 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8030 switch (ptr_ty.ptrSize(zcu)) {
80418031 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
80428032 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
80438033 try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset,
......@@ -8058,7 +8048,7 @@ pub const FuncGen = struct {
80588048 ) !Builder.Value {
80598049 const o = self.ng.object;
80608050 const pt = o.pt;
8061 const mod = pt.zcu;
8051 const zcu = pt.zcu;
80628052 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
80638053 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
80648054
......@@ -8066,10 +8056,10 @@ pub const FuncGen = struct {
80668056 const rhs = try self.resolveInst(extra.rhs);
80678057
80688058 const lhs_ty = self.typeOf(extra.lhs);
8069 const scalar_ty = lhs_ty.scalarType(mod);
8059 const scalar_ty = lhs_ty.scalarType(zcu);
80708060 const inst_ty = self.typeOfIndex(inst);
80718061
8072 const intrinsic = if (scalar_ty.isSignedInt(mod)) signed_intrinsic else unsigned_intrinsic;
8062 const intrinsic = if (scalar_ty.isSignedInt(zcu)) signed_intrinsic else unsigned_intrinsic;
80738063 const llvm_inst_ty = try o.lowerType(inst_ty);
80748064 const llvm_lhs_ty = try o.lowerType(lhs_ty);
80758065 const results =
......@@ -8081,8 +8071,8 @@ pub const FuncGen = struct {
80818071 const result_index = o.llvmFieldIndex(inst_ty, 0).?;
80828072 const overflow_index = o.llvmFieldIndex(inst_ty, 1).?;
80838073
8084 if (isByRef(inst_ty, pt)) {
8085 const result_alignment = inst_ty.abiAlignment(pt).toLlvm();
8074 if (isByRef(inst_ty, zcu)) {
8075 const result_alignment = inst_ty.abiAlignment(zcu).toLlvm();
80868076 const alloca_inst = try self.buildAllocaWorkaround(inst_ty, result_alignment);
80878077 {
80888078 const field_ptr = try self.wip.gepStruct(llvm_inst_ty, alloca_inst, result_index, "");
......@@ -8165,9 +8155,9 @@ pub const FuncGen = struct {
81658155 params: [2]Builder.Value,
81668156 ) !Builder.Value {
81678157 const o = self.ng.object;
8168 const mod = o.pt.zcu;
8169 const target = mod.getTarget();
8170 const scalar_ty = ty.scalarType(mod);
8158 const zcu = o.pt.zcu;
8159 const target = zcu.getTarget();
8160 const scalar_ty = ty.scalarType(zcu);
81718161 const scalar_llvm_ty = try o.lowerType(scalar_ty);
81728162
81738163 if (intrinsicsAllowed(scalar_ty, target)) {
......@@ -8205,8 +8195,8 @@ pub const FuncGen = struct {
82058195 .gte => .sge,
82068196 };
82078197
8208 if (ty.zigTypeTag(mod) == .Vector) {
8209 const vec_len = ty.vectorLen(mod);
8198 if (ty.zigTypeTag(zcu) == .Vector) {
8199 const vec_len = ty.vectorLen(zcu);
82108200 const vector_result_ty = try o.builder.vectorType(.normal, vec_len, .i32);
82118201
82128202 const init = try o.builder.poisonValue(vector_result_ty);
......@@ -8271,9 +8261,9 @@ pub const FuncGen = struct {
82718261 params: [params_len]Builder.Value,
82728262 ) !Builder.Value {
82738263 const o = self.ng.object;
8274 const mod = o.pt.zcu;
8275 const target = mod.getTarget();
8276 const scalar_ty = ty.scalarType(mod);
8264 const zcu = o.pt.zcu;
8265 const target = zcu.getTarget();
8266 const scalar_ty = ty.scalarType(zcu);
82778267 const llvm_ty = try o.lowerType(ty);
82788268
82798269 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {
......@@ -8382,9 +8372,9 @@ pub const FuncGen = struct {
83828372 ([1]Builder.Type{scalar_llvm_ty} ** 3)[0..params.len],
83838373 scalar_llvm_ty,
83848374 );
8385 if (ty.zigTypeTag(mod) == .Vector) {
8375 if (ty.zigTypeTag(zcu) == .Vector) {
83868376 const result = try o.builder.poisonValue(llvm_ty);
8387 return self.buildElementwiseCall(libc_fn, &params, result, ty.vectorLen(mod));
8377 return self.buildElementwiseCall(libc_fn, &params, result, ty.vectorLen(zcu));
83888378 }
83898379
83908380 return self.wip.call(
......@@ -8413,7 +8403,7 @@ pub const FuncGen = struct {
84138403 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
84148404 const o = self.ng.object;
84158405 const pt = o.pt;
8416 const mod = pt.zcu;
8406 const zcu = pt.zcu;
84178407 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
84188408 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
84198409
......@@ -8421,7 +8411,7 @@ pub const FuncGen = struct {
84218411 const rhs = try self.resolveInst(extra.rhs);
84228412
84238413 const lhs_ty = self.typeOf(extra.lhs);
8424 const lhs_scalar_ty = lhs_ty.scalarType(mod);
8414 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
84258415
84268416 const dest_ty = self.typeOfIndex(inst);
84278417 const llvm_dest_ty = try o.lowerType(dest_ty);
......@@ -8429,7 +8419,7 @@ pub const FuncGen = struct {
84298419 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
84308420
84318421 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");
8432 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(mod))
8422 const reconstructed = try self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
84338423 .ashr
84348424 else
84358425 .lshr, result, casted_rhs, "");
......@@ -8439,8 +8429,8 @@ pub const FuncGen = struct {
84398429 const result_index = o.llvmFieldIndex(dest_ty, 0).?;
84408430 const overflow_index = o.llvmFieldIndex(dest_ty, 1).?;
84418431
8442 if (isByRef(dest_ty, pt)) {
8443 const result_alignment = dest_ty.abiAlignment(pt).toLlvm();
8432 if (isByRef(dest_ty, zcu)) {
8433 const result_alignment = dest_ty.abiAlignment(zcu).toLlvm();
84448434 const alloca_inst = try self.buildAllocaWorkaround(dest_ty, result_alignment);
84458435 {
84468436 const field_ptr = try self.wip.gepStruct(llvm_dest_ty, alloca_inst, result_index, "");
......@@ -8483,17 +8473,17 @@ pub const FuncGen = struct {
84838473
84848474 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
84858475 const o = self.ng.object;
8486 const mod = o.pt.zcu;
8476 const zcu = o.pt.zcu;
84878477 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84888478
84898479 const lhs = try self.resolveInst(bin_op.lhs);
84908480 const rhs = try self.resolveInst(bin_op.rhs);
84918481
84928482 const lhs_ty = self.typeOf(bin_op.lhs);
8493 const lhs_scalar_ty = lhs_ty.scalarType(mod);
8483 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
84948484
84958485 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))
8486 return self.wip.bin(if (lhs_scalar_ty.isSignedInt(zcu))
84978487 .@"shl nsw"
84988488 else
84998489 .@"shl nuw", lhs, casted_rhs, "");
......@@ -8515,15 +8505,15 @@ pub const FuncGen = struct {
85158505 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85168506 const o = self.ng.object;
85178507 const pt = o.pt;
8518 const mod = pt.zcu;
8508 const zcu = pt.zcu;
85198509 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85208510
85218511 const lhs = try self.resolveInst(bin_op.lhs);
85228512 const rhs = try self.resolveInst(bin_op.rhs);
85238513
85248514 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);
8515 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
8516 const lhs_bits = lhs_scalar_ty.bitSize(zcu);
85278517
85288518 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
85298519
......@@ -8532,7 +8522,7 @@ pub const FuncGen = struct {
85328522 const result = try self.wip.callIntrinsic(
85338523 .normal,
85348524 .none,
8535 if (lhs_scalar_ty.isSignedInt(mod)) .@"sshl.sat" else .@"ushl.sat",
8525 if (lhs_scalar_ty.isSignedInt(zcu)) .@"sshl.sat" else .@"ushl.sat",
85368526 &.{llvm_lhs_ty},
85378527 &.{ lhs, casted_rhs },
85388528 "",
......@@ -8557,17 +8547,17 @@ pub const FuncGen = struct {
85578547
85588548 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
85598549 const o = self.ng.object;
8560 const mod = o.pt.zcu;
8550 const zcu = o.pt.zcu;
85618551 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85628552
85638553 const lhs = try self.resolveInst(bin_op.lhs);
85648554 const rhs = try self.resolveInst(bin_op.rhs);
85658555
85668556 const lhs_ty = self.typeOf(bin_op.lhs);
8567 const lhs_scalar_ty = lhs_ty.scalarType(mod);
8557 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
85688558
85698559 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
8570 const is_signed_int = lhs_scalar_ty.isSignedInt(mod);
8560 const is_signed_int = lhs_scalar_ty.isSignedInt(zcu);
85718561
85728562 return self.wip.bin(if (is_exact)
85738563 if (is_signed_int) .@"ashr exact" else .@"lshr exact"
......@@ -8576,13 +8566,13 @@ pub const FuncGen = struct {
85768566
85778567 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
85788568 const o = self.ng.object;
8579 const mod = o.pt.zcu;
8569 const zcu = o.pt.zcu;
85808570 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
85818571 const operand = try self.resolveInst(ty_op.operand);
85828572 const operand_ty = self.typeOf(ty_op.operand);
8583 const scalar_ty = operand_ty.scalarType(mod);
8573 const scalar_ty = operand_ty.scalarType(zcu);
85848574
8585 switch (scalar_ty.zigTypeTag(mod)) {
8575 switch (scalar_ty.zigTypeTag(zcu)) {
85868576 .Int => return self.wip.callIntrinsic(
85878577 .normal,
85888578 .none,
......@@ -8598,13 +8588,13 @@ pub const FuncGen = struct {
85988588
85998589 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
86008590 const o = self.ng.object;
8601 const mod = o.pt.zcu;
8591 const zcu = o.pt.zcu;
86028592 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
86038593 const dest_ty = self.typeOfIndex(inst);
86048594 const dest_llvm_ty = try o.lowerType(dest_ty);
86058595 const operand = try self.resolveInst(ty_op.operand);
86068596 const operand_ty = self.typeOf(ty_op.operand);
8607 const operand_info = operand_ty.intInfo(mod);
8597 const operand_info = operand_ty.intInfo(zcu);
86088598
86098599 return self.wip.conv(switch (operand_info.signedness) {
86108600 .signed => .signed,
......@@ -8622,12 +8612,12 @@ pub const FuncGen = struct {
86228612
86238613 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
86248614 const o = self.ng.object;
8625 const mod = o.pt.zcu;
8615 const zcu = o.pt.zcu;
86268616 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
86278617 const operand = try self.resolveInst(ty_op.operand);
86288618 const operand_ty = self.typeOf(ty_op.operand);
86298619 const dest_ty = self.typeOfIndex(inst);
8630 const target = mod.getTarget();
8620 const target = zcu.getTarget();
86318621 const dest_bits = dest_ty.floatBits(target);
86328622 const src_bits = operand_ty.floatBits(target);
86338623
......@@ -8656,12 +8646,12 @@ pub const FuncGen = struct {
86568646
86578647 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
86588648 const o = self.ng.object;
8659 const mod = o.pt.zcu;
8649 const zcu = o.pt.zcu;
86608650 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
86618651 const operand = try self.resolveInst(ty_op.operand);
86628652 const operand_ty = self.typeOf(ty_op.operand);
86638653 const dest_ty = self.typeOfIndex(inst);
8664 const target = mod.getTarget();
8654 const target = zcu.getTarget();
86658655
86668656 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
86678657 return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), "");
......@@ -8669,18 +8659,18 @@ pub const FuncGen = struct {
86698659 const operand_llvm_ty = try o.lowerType(operand_ty);
86708660 const dest_llvm_ty = try o.lowerType(dest_ty);
86718661
8672 const dest_bits = dest_ty.scalarType(mod).floatBits(target);
8673 const src_bits = operand_ty.scalarType(mod).floatBits(target);
8662 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);
8663 const src_bits = operand_ty.scalarType(zcu).floatBits(target);
86748664 const fn_name = try o.builder.strtabStringFmt("__extend{s}f{s}f2", .{
86758665 compilerRtFloatAbbrev(src_bits), compilerRtFloatAbbrev(dest_bits),
86768666 });
86778667
86788668 const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, dest_llvm_ty);
8679 if (dest_ty.isVector(mod)) return self.buildElementwiseCall(
8669 if (dest_ty.isVector(zcu)) return self.buildElementwiseCall(
86808670 libc_fn,
86818671 &.{operand},
86828672 try o.builder.poisonValue(dest_llvm_ty),
8683 dest_ty.vectorLen(mod),
8673 dest_ty.vectorLen(zcu),
86848674 );
86858675 return self.wip.call(
86868676 .normal,
......@@ -8715,9 +8705,9 @@ pub const FuncGen = struct {
87158705 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {
87168706 const o = self.ng.object;
87178707 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);
8708 const zcu = pt.zcu;
8709 const operand_is_ref = isByRef(operand_ty, zcu);
8710 const result_is_ref = isByRef(inst_ty, zcu);
87218711 const llvm_dest_ty = try o.lowerType(inst_ty);
87228712
87238713 if (operand_is_ref and result_is_ref) {
......@@ -8731,18 +8721,18 @@ pub const FuncGen = struct {
87318721 return self.wip.conv(.unsigned, operand, llvm_dest_ty, "");
87328722 }
87338723
8734 if (operand_ty.zigTypeTag(mod) == .Int and inst_ty.isPtrAtRuntime(mod)) {
8724 if (operand_ty.zigTypeTag(zcu) == .Int and inst_ty.isPtrAtRuntime(zcu)) {
87358725 return self.wip.cast(.inttoptr, operand, llvm_dest_ty, "");
87368726 }
87378727
8738 if (operand_ty.zigTypeTag(mod) == .Vector and inst_ty.zigTypeTag(mod) == .Array) {
8739 const elem_ty = operand_ty.childType(mod);
8728 if (operand_ty.zigTypeTag(zcu) == .Vector and inst_ty.zigTypeTag(zcu) == .Array) {
8729 const elem_ty = operand_ty.childType(zcu);
87408730 if (!result_is_ref) {
87418731 return self.ng.todo("implement bitcast vector to non-ref array", .{});
87428732 }
8743 const alignment = inst_ty.abiAlignment(pt).toLlvm();
8733 const alignment = inst_ty.abiAlignment(zcu).toLlvm();
87448734 const array_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
8745 const bitcast_ok = elem_ty.bitSize(pt) == elem_ty.abiSize(pt) * 8;
8735 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
87468736 if (bitcast_ok) {
87478737 _ = try self.wip.store(.normal, operand, array_ptr, alignment);
87488738 } else {
......@@ -8750,7 +8740,7 @@ pub const FuncGen = struct {
87508740 // a simple bitcast will not work, and we fall back to extractelement.
87518741 const llvm_usize = try o.lowerType(Type.usize);
87528742 const usize_zero = try o.builder.intValue(llvm_usize, 0);
8753 const vector_len = operand_ty.arrayLen(mod);
8743 const vector_len = operand_ty.arrayLen(zcu);
87548744 var i: u64 = 0;
87558745 while (i < vector_len) : (i += 1) {
87568746 const elem_ptr = try self.wip.gep(.inbounds, llvm_dest_ty, array_ptr, &.{
......@@ -8762,16 +8752,16 @@ pub const FuncGen = struct {
87628752 }
87638753 }
87648754 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);
8755 } else if (operand_ty.zigTypeTag(zcu) == .Array and inst_ty.zigTypeTag(zcu) == .Vector) {
8756 const elem_ty = operand_ty.childType(zcu);
87678757 const llvm_vector_ty = try o.lowerType(inst_ty);
87688758 if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{});
87698759
8770 const bitcast_ok = elem_ty.bitSize(pt) == elem_ty.abiSize(pt) * 8;
8760 const bitcast_ok = elem_ty.bitSize(zcu) == elem_ty.abiSize(zcu) * 8;
87718761 if (bitcast_ok) {
87728762 // The array is aligned to the element's alignment, while the vector might have a completely
87738763 // different alignment. This means we need to enforce the alignment of this load.
8774 const alignment = elem_ty.abiAlignment(pt).toLlvm();
8764 const alignment = elem_ty.abiAlignment(zcu).toLlvm();
87758765 return self.wip.load(.normal, llvm_vector_ty, operand, alignment, "");
87768766 } else {
87778767 // If the ABI size of the element type is not evenly divisible by size in bits;
......@@ -8780,7 +8770,7 @@ pub const FuncGen = struct {
87808770 const elem_llvm_ty = try o.lowerType(elem_ty);
87818771 const llvm_usize = try o.lowerType(Type.usize);
87828772 const usize_zero = try o.builder.intValue(llvm_usize, 0);
8783 const vector_len = operand_ty.arrayLen(mod);
8773 const vector_len = operand_ty.arrayLen(zcu);
87848774 var vector = try o.builder.poisonValue(llvm_vector_ty);
87858775 var i: u64 = 0;
87868776 while (i < vector_len) : (i += 1) {
......@@ -8796,25 +8786,25 @@ pub const FuncGen = struct {
87968786 }
87978787
87988788 if (operand_is_ref) {
8799 const alignment = operand_ty.abiAlignment(pt).toLlvm();
8789 const alignment = operand_ty.abiAlignment(zcu).toLlvm();
88008790 return self.wip.load(.normal, llvm_dest_ty, operand, alignment, "");
88018791 }
88028792
88038793 if (result_is_ref) {
8804 const alignment = operand_ty.abiAlignment(pt).max(inst_ty.abiAlignment(pt)).toLlvm();
8794 const alignment = operand_ty.abiAlignment(zcu).max(inst_ty.abiAlignment(zcu)).toLlvm();
88058795 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
88068796 _ = try self.wip.store(.normal, operand, result_ptr, alignment);
88078797 return result_ptr;
88088798 }
88098799
88108800 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)))
8801 ((operand_ty.zigTypeTag(zcu) == .Vector or inst_ty.zigTypeTag(zcu) == .Vector) and
8802 operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu)))
88138803 {
88148804 // Both our operand and our result are values, not pointers,
88158805 // but LLVM won't let us bitcast struct values or vectors with padding bits.
88168806 // Therefore, we store operand to alloca, then load for result.
8817 const alignment = operand_ty.abiAlignment(pt).max(inst_ty.abiAlignment(pt)).toLlvm();
8807 const alignment = operand_ty.abiAlignment(zcu).max(inst_ty.abiAlignment(zcu)).toLlvm();
88188808 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
88198809 _ = try self.wip.store(.normal, operand, result_ptr, alignment);
88208810 return self.wip.load(.normal, llvm_dest_ty, result_ptr, alignment, "");
......@@ -8868,7 +8858,7 @@ pub const FuncGen = struct {
88688858 };
88698859
88708860 const mod = self.ng.ownerModule();
8871 if (isByRef(inst_ty, pt)) {
8861 if (isByRef(inst_ty, zcu)) {
88728862 _ = try self.wip.callIntrinsic(
88738863 .normal,
88748864 .none,
......@@ -8882,7 +8872,7 @@ pub const FuncGen = struct {
88828872 "",
88838873 );
88848874 } else if (mod.optimize_mode == .Debug) {
8885 const alignment = inst_ty.abiAlignment(pt).toLlvm();
8875 const alignment = inst_ty.abiAlignment(zcu).toLlvm();
88868876 const alloca = try self.buildAlloca(arg_val.typeOfWip(&self.wip), alignment);
88878877 _ = try self.wip.store(.normal, arg_val, alloca, alignment);
88888878 _ = try self.wip.callIntrinsic(
......@@ -8919,28 +8909,28 @@ pub const FuncGen = struct {
89198909 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
89208910 const o = self.ng.object;
89218911 const pt = o.pt;
8922 const mod = pt.zcu;
8912 const zcu = pt.zcu;
89238913 const ptr_ty = self.typeOfIndex(inst);
8924 const pointee_type = ptr_ty.childType(mod);
8925 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(pt))
8914 const pointee_type = ptr_ty.childType(zcu);
8915 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
89268916 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
89278917
89288918 //const pointee_llvm_ty = try o.lowerType(pointee_type);
8929 const alignment = ptr_ty.ptrAlignment(pt).toLlvm();
8919 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
89308920 return self.buildAllocaWorkaround(pointee_type, alignment);
89318921 }
89328922
89338923 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
89348924 const o = self.ng.object;
89358925 const pt = o.pt;
8936 const mod = pt.zcu;
8926 const zcu = pt.zcu;
89378927 const ptr_ty = self.typeOfIndex(inst);
8938 const ret_ty = ptr_ty.childType(mod);
8939 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt))
8928 const ret_ty = ptr_ty.childType(zcu);
8929 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
89408930 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
89418931 if (self.ret_ptr != .none) return self.ret_ptr;
89428932 //const ret_llvm_ty = try o.lowerType(ret_ty);
8943 const alignment = ptr_ty.ptrAlignment(pt).toLlvm();
8933 const alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
89448934 return self.buildAllocaWorkaround(ret_ty, alignment);
89458935 }
89468936
......@@ -8962,19 +8952,19 @@ pub const FuncGen = struct {
89628952 alignment: Builder.Alignment,
89638953 ) Allocator.Error!Builder.Value {
89648954 const o = self.ng.object;
8965 return self.buildAlloca(try o.builder.arrayType(ty.abiSize(o.pt), .i8), alignment);
8955 return self.buildAlloca(try o.builder.arrayType(ty.abiSize(o.pt.zcu), .i8), alignment);
89668956 }
89678957
89688958 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
89698959 const o = self.ng.object;
89708960 const pt = o.pt;
8971 const mod = pt.zcu;
8961 const zcu = pt.zcu;
89728962 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
89738963 const dest_ptr = try self.resolveInst(bin_op.lhs);
89748964 const ptr_ty = self.typeOf(bin_op.lhs);
8975 const operand_ty = ptr_ty.childType(mod);
8965 const operand_ty = ptr_ty.childType(zcu);
89768966
8977 const val_is_undef = if (try self.air.value(bin_op.rhs, pt)) |val| val.isUndefDeep(mod) else false;
8967 const val_is_undef = if (try self.air.value(bin_op.rhs, pt)) |val| val.isUndefDeep(zcu) else false;
89788968 if (val_is_undef) {
89798969 const owner_mod = self.ng.ownerModule();
89808970
......@@ -8991,7 +8981,7 @@ pub const FuncGen = struct {
89918981 return .none;
89928982 }
89938983
8994 const ptr_info = ptr_ty.ptrInfo(mod);
8984 const ptr_info = ptr_ty.ptrInfo(zcu);
89958985 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);
89968986 if (needs_bitmask) {
89978987 // TODO: only some bits are to be undef, we cannot write with a simple memset.
......@@ -9000,13 +8990,13 @@ pub const FuncGen = struct {
90008990 return .none;
90018991 }
90028992
9003 const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(pt));
8993 const len = try o.builder.intValue(try o.lowerType(Type.usize), operand_ty.abiSize(zcu));
90048994 _ = try self.wip.callMemSet(
90058995 dest_ptr,
9006 ptr_ty.ptrAlignment(pt).toLlvm(),
8996 ptr_ty.ptrAlignment(zcu).toLlvm(),
90078997 if (safety) try o.builder.intValue(.i8, 0xaa) else try o.builder.undefValue(.i8),
90088998 len,
9009 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,
8999 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
90109000 );
90119001 if (safety and owner_mod.valgrind) {
90129002 try self.valgrindMarkUndef(dest_ptr, len);
......@@ -9027,8 +9017,8 @@ pub const FuncGen = struct {
90279017 /// The first instruction of `body_tail` is the one whose copy we want to elide.
90289018 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {
90299019 const o = fg.ng.object;
9030 const mod = o.pt.zcu;
9031 const ip = &mod.intern_pool;
9020 const zcu = o.pt.zcu;
9021 const ip = &zcu.intern_pool;
90329022 for (body_tail[1..]) |body_inst| {
90339023 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip)) {
90349024 .none => continue,
......@@ -9044,15 +9034,15 @@ pub const FuncGen = struct {
90449034 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
90459035 const o = fg.ng.object;
90469036 const pt = o.pt;
9047 const mod = pt.zcu;
9037 const zcu = pt.zcu;
90489038 const inst = body_tail[0];
90499039 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
90509040 const ptr_ty = fg.typeOf(ty_op.operand);
9051 const ptr_info = ptr_ty.ptrInfo(mod);
9041 const ptr_info = ptr_ty.ptrInfo(zcu);
90529042 const ptr = try fg.resolveInst(ty_op.operand);
90539043
90549044 elide: {
9055 if (!isByRef(Type.fromInterned(ptr_info.child), pt)) break :elide;
9045 if (!isByRef(Type.fromInterned(ptr_info.child), zcu)) break :elide;
90569046 if (!canElideLoad(fg, body_tail)) break :elide;
90579047 return ptr;
90589048 }
......@@ -9105,34 +9095,34 @@ pub const FuncGen = struct {
91059095 ) !Builder.Value {
91069096 const o = self.ng.object;
91079097 const pt = o.pt;
9108 const mod = pt.zcu;
9098 const zcu = pt.zcu;
91099099 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
91109100 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
91119101 const ptr = try self.resolveInst(extra.ptr);
91129102 const ptr_ty = self.typeOf(extra.ptr);
91139103 var expected_value = try self.resolveInst(extra.expected_value);
91149104 var new_value = try self.resolveInst(extra.new_value);
9115 const operand_ty = ptr_ty.childType(mod);
9105 const operand_ty = ptr_ty.childType(zcu);
91169106 const llvm_operand_ty = try o.lowerType(operand_ty);
91179107 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
91189108 if (llvm_abi_ty != .none) {
91199109 // operand needs widening and truncating
91209110 const signedness: Builder.Function.Instruction.Cast.Signedness =
9121 if (operand_ty.isSignedInt(mod)) .signed else .unsigned;
9111 if (operand_ty.isSignedInt(zcu)) .signed else .unsigned;
91229112 expected_value = try self.wip.conv(signedness, expected_value, llvm_abi_ty, "");
91239113 new_value = try self.wip.conv(signedness, new_value, llvm_abi_ty, "");
91249114 }
91259115
91269116 const result = try self.wip.cmpxchg(
91279117 kind,
9128 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,
9118 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
91299119 ptr,
91309120 expected_value,
91319121 new_value,
91329122 self.sync_scope,
91339123 toLlvmAtomicOrdering(extra.successOrder()),
91349124 toLlvmAtomicOrdering(extra.failureOrder()),
9135 ptr_ty.ptrAlignment(pt).toLlvm(),
9125 ptr_ty.ptrAlignment(zcu).toLlvm(),
91369126 "",
91379127 );
91389128
......@@ -9142,7 +9132,7 @@ pub const FuncGen = struct {
91429132 if (llvm_abi_ty != .none) payload = try self.wip.cast(.trunc, payload, llvm_operand_ty, "");
91439133 const success_bit = try self.wip.extractValue(result, &.{1}, "");
91449134
9145 if (optional_ty.optionalReprIsPayload(mod)) {
9135 if (optional_ty.optionalReprIsPayload(zcu)) {
91469136 const zero = try o.builder.zeroInitValue(payload.typeOfWip(&self.wip));
91479137 return self.wip.select(.normal, success_bit, zero, payload, "");
91489138 }
......@@ -9156,14 +9146,14 @@ pub const FuncGen = struct {
91569146 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
91579147 const o = self.ng.object;
91589148 const pt = o.pt;
9159 const mod = pt.zcu;
9149 const zcu = pt.zcu;
91609150 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
91619151 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
91629152 const ptr = try self.resolveInst(pl_op.operand);
91639153 const ptr_ty = self.typeOf(pl_op.operand);
9164 const operand_ty = ptr_ty.childType(mod);
9154 const operand_ty = ptr_ty.childType(zcu);
91659155 const operand = try self.resolveInst(extra.operand);
9166 const is_signed_int = operand_ty.isSignedInt(mod);
9156 const is_signed_int = operand_ty.isSignedInt(zcu);
91679157 const is_float = operand_ty.isRuntimeFloat();
91689158 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);
91699159 const ordering = toLlvmAtomicOrdering(extra.ordering());
......@@ -9171,8 +9161,8 @@ pub const FuncGen = struct {
91719161 const llvm_operand_ty = try o.lowerType(operand_ty);
91729162
91739163 const access_kind: Builder.MemoryAccessKind =
9174 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;
9175 const ptr_alignment = ptr_ty.ptrAlignment(pt).toLlvm();
9164 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
9165 const ptr_alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
91769166
91779167 if (llvm_abi_ty != .none) {
91789168 // operand needs widening and truncating or bitcasting.
......@@ -9220,19 +9210,19 @@ pub const FuncGen = struct {
92209210 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
92219211 const o = self.ng.object;
92229212 const pt = o.pt;
9223 const mod = pt.zcu;
9213 const zcu = pt.zcu;
92249214 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
92259215 const ptr = try self.resolveInst(atomic_load.ptr);
92269216 const ptr_ty = self.typeOf(atomic_load.ptr);
9227 const info = ptr_ty.ptrInfo(mod);
9217 const info = ptr_ty.ptrInfo(zcu);
92289218 const elem_ty = Type.fromInterned(info.child);
9229 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
9219 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
92309220 const ordering = toLlvmAtomicOrdering(atomic_load.order);
92319221 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);
92329222 const ptr_alignment = (if (info.flags.alignment != .none)
92339223 @as(InternPool.Alignment, info.flags.alignment)
92349224 else
9235 Type.fromInterned(info.child).abiAlignment(pt)).toLlvm();
9225 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();
92369226 const access_kind: Builder.MemoryAccessKind =
92379227 if (info.flags.is_volatile) .@"volatile" else .normal;
92389228 const elem_llvm_ty = try o.lowerType(elem_ty);
......@@ -9268,11 +9258,11 @@ pub const FuncGen = struct {
92689258 ) !Builder.Value {
92699259 const o = self.ng.object;
92709260 const pt = o.pt;
9271 const mod = pt.zcu;
9261 const zcu = pt.zcu;
92729262 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
92739263 const ptr_ty = self.typeOf(bin_op.lhs);
9274 const operand_ty = ptr_ty.childType(mod);
9275 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) return .none;
9264 const operand_ty = ptr_ty.childType(zcu);
9265 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;
92769266 const ptr = try self.resolveInst(bin_op.lhs);
92779267 var element = try self.resolveInst(bin_op.rhs);
92789268 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
......@@ -9280,7 +9270,7 @@ pub const FuncGen = struct {
92809270 if (llvm_abi_ty != .none) {
92819271 // operand needs widening
92829272 element = try self.wip.conv(
9283 if (operand_ty.isSignedInt(mod)) .signed else .unsigned,
9273 if (operand_ty.isSignedInt(zcu)) .signed else .unsigned,
92849274 element,
92859275 llvm_abi_ty,
92869276 "",
......@@ -9293,26 +9283,26 @@ pub const FuncGen = struct {
92939283 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
92949284 const o = self.ng.object;
92959285 const pt = o.pt;
9296 const mod = pt.zcu;
9286 const zcu = pt.zcu;
92979287 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
92989288 const dest_slice = try self.resolveInst(bin_op.lhs);
92999289 const ptr_ty = self.typeOf(bin_op.lhs);
93009290 const elem_ty = self.typeOf(bin_op.rhs);
9301 const dest_ptr_align = ptr_ty.ptrAlignment(pt).toLlvm();
9291 const dest_ptr_align = ptr_ty.ptrAlignment(zcu).toLlvm();
93029292 const dest_ptr = try self.sliceOrArrayPtr(dest_slice, ptr_ty);
93039293 const access_kind: Builder.MemoryAccessKind =
9304 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;
9294 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
93059295
93069296 // Any WebAssembly runtime will trap when the destination pointer is out-of-bounds, regardless
93079297 // of the length. This means we need to emit a check where we skip the memset when the length
93089298 // is 0 as we allow for undefined pointers in 0-sized slices.
93099299 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
93109300 const intrinsic_len0_traps = o.target.isWasm() and
9311 ptr_ty.isSlice(mod) and
9301 ptr_ty.isSlice(zcu) and
93129302 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory);
93139303
93149304 if (try self.air.value(bin_op.rhs, pt)) |elem_val| {
9315 if (elem_val.isUndefDeep(mod)) {
9305 if (elem_val.isUndefDeep(zcu)) {
93169306 // Even if safety is disabled, we still emit a memset to undefined since it conveys
93179307 // extra information to LLVM. However, safety makes the difference between using
93189308 // 0xaa or actual undefined for the fill byte.
......@@ -9350,7 +9340,7 @@ pub const FuncGen = struct {
93509340 }
93519341
93529342 const value = try self.resolveInst(bin_op.rhs);
9353 const elem_abi_size = elem_ty.abiSize(pt);
9343 const elem_abi_size = elem_ty.abiSize(zcu);
93549344
93559345 if (elem_abi_size == 1) {
93569346 // In this case we can take advantage of LLVM's intrinsic.
......@@ -9387,9 +9377,9 @@ pub const FuncGen = struct {
93879377 const end_block = try self.wip.block(1, "InlineMemsetEnd");
93889378
93899379 const llvm_usize_ty = try o.lowerType(Type.usize);
9390 const len = switch (ptr_ty.ptrSize(mod)) {
9380 const len = switch (ptr_ty.ptrSize(zcu)) {
93919381 .Slice => try self.wip.extractValue(dest_slice, &.{1}, ""),
9392 .One => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(mod).arrayLen(mod)),
9382 .One => try o.builder.intValue(llvm_usize_ty, ptr_ty.childType(zcu).arrayLen(zcu)),
93939383 .Many, .C => unreachable,
93949384 };
93959385 const elem_llvm_ty = try o.lowerType(elem_ty);
......@@ -9402,9 +9392,9 @@ pub const FuncGen = struct {
94029392 _ = try self.wip.brCond(end, body_block, end_block);
94039393
94049394 self.wip.cursor = .{ .block = body_block };
9405 const elem_abi_align = elem_ty.abiAlignment(pt);
9395 const elem_abi_align = elem_ty.abiAlignment(zcu);
94069396 const it_ptr_align = InternPool.Alignment.fromLlvm(dest_ptr_align).min(elem_abi_align).toLlvm();
9407 if (isByRef(elem_ty, pt)) {
9397 if (isByRef(elem_ty, zcu)) {
94089398 _ = try self.wip.callMemCpy(
94099399 it_ptr.toValue(),
94109400 it_ptr_align,
......@@ -9447,7 +9437,7 @@ pub const FuncGen = struct {
94479437 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
94489438 const o = self.ng.object;
94499439 const pt = o.pt;
9450 const mod = pt.zcu;
9440 const zcu = pt.zcu;
94519441 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
94529442 const dest_slice = try self.resolveInst(bin_op.lhs);
94539443 const dest_ptr_ty = self.typeOf(bin_op.lhs);
......@@ -9456,8 +9446,8 @@ pub const FuncGen = struct {
94569446 const src_ptr = try self.sliceOrArrayPtr(src_slice, src_ptr_ty);
94579447 const len = try self.sliceOrArrayLenInBytes(dest_slice, dest_ptr_ty);
94589448 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;
9449 const access_kind: Builder.MemoryAccessKind = if (src_ptr_ty.isVolatilePtr(zcu) or
9450 dest_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
94619451
94629452 // When bulk-memory is enabled, this will be lowered to WebAssembly's memory.copy instruction.
94639453 // This instruction will trap on an invalid address, regardless of the length.
......@@ -9466,7 +9456,7 @@ pub const FuncGen = struct {
94669456 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
94679457 if (o.target.isWasm() and
94689458 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory) and
9469 dest_ptr_ty.isSlice(mod))
9459 dest_ptr_ty.isSlice(zcu))
94709460 {
94719461 const usize_zero = try o.builder.intValue(try o.lowerType(Type.usize), 0);
94729462 const cond = try self.cmp(.normal, .neq, Type.usize, len, usize_zero);
......@@ -9476,9 +9466,9 @@ pub const FuncGen = struct {
94769466 self.wip.cursor = .{ .block = memcpy_block };
94779467 _ = try self.wip.callMemCpy(
94789468 dest_ptr,
9479 dest_ptr_ty.ptrAlignment(pt).toLlvm(),
9469 dest_ptr_ty.ptrAlignment(zcu).toLlvm(),
94809470 src_ptr,
9481 src_ptr_ty.ptrAlignment(pt).toLlvm(),
9471 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
94829472 len,
94839473 access_kind,
94849474 );
......@@ -9489,9 +9479,9 @@ pub const FuncGen = struct {
94899479
94909480 _ = try self.wip.callMemCpy(
94919481 dest_ptr,
9492 dest_ptr_ty.ptrAlignment(pt).toLlvm(),
9482 dest_ptr_ty.ptrAlignment(zcu).toLlvm(),
94939483 src_ptr,
9494 src_ptr_ty.ptrAlignment(pt).toLlvm(),
9484 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
94959485 len,
94969486 access_kind,
94979487 );
......@@ -9501,10 +9491,10 @@ pub const FuncGen = struct {
95019491 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95029492 const o = self.ng.object;
95039493 const pt = o.pt;
9504 const mod = pt.zcu;
9494 const zcu = pt.zcu;
95059495 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);
9496 const un_ty = self.typeOf(bin_op.lhs).childType(zcu);
9497 const layout = un_ty.unionGetLayout(zcu);
95089498 if (layout.tag_size == 0) return .none;
95099499 const union_ptr = try self.resolveInst(bin_op.lhs);
95109500 const new_tag = try self.resolveInst(bin_op.rhs);
......@@ -9523,12 +9513,13 @@ pub const FuncGen = struct {
95239513 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95249514 const o = self.ng.object;
95259515 const pt = o.pt;
9516 const zcu = pt.zcu;
95269517 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
95279518 const un_ty = self.typeOf(ty_op.operand);
9528 const layout = un_ty.unionGetLayout(pt);
9519 const layout = un_ty.unionGetLayout(zcu);
95299520 if (layout.tag_size == 0) return .none;
95309521 const union_handle = try self.resolveInst(ty_op.operand);
9531 if (isByRef(un_ty, pt)) {
9522 if (isByRef(un_ty, zcu)) {
95329523 const llvm_un_ty = try o.lowerType(un_ty);
95339524 if (layout.payload_size == 0)
95349525 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");
......@@ -9597,10 +9588,10 @@ pub const FuncGen = struct {
95979588
95989589 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
95999590 const o = self.ng.object;
9600 const mod = o.pt.zcu;
9591 const zcu = o.pt.zcu;
96019592 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
96029593 const operand_ty = self.typeOf(ty_op.operand);
9603 var bits = operand_ty.intInfo(mod).bits;
9594 var bits = operand_ty.intInfo(zcu).bits;
96049595 assert(bits % 8 == 0);
96059596
96069597 const inst_ty = self.typeOfIndex(inst);
......@@ -9611,8 +9602,8 @@ pub const FuncGen = struct {
96119602 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
96129603 // The truncated result at the end will be the correct bswap
96139604 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);
9605 if (operand_ty.zigTypeTag(zcu) == .Vector) {
9606 const vec_len = operand_ty.vectorLen(zcu);
96169607 llvm_operand_ty = try o.builder.vectorType(.normal, vec_len, scalar_ty);
96179608 } else llvm_operand_ty = scalar_ty;
96189609
......@@ -9631,13 +9622,13 @@ pub const FuncGen = struct {
96319622
96329623 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
96339624 const o = self.ng.object;
9634 const mod = o.pt.zcu;
9635 const ip = &mod.intern_pool;
9625 const zcu = o.pt.zcu;
9626 const ip = &zcu.intern_pool;
96369627 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
96379628 const operand = try self.resolveInst(ty_op.operand);
96389629 const error_set_ty = ty_op.ty.toType();
96399630
9640 const names = error_set_ty.errorSetNames(mod);
9631 const names = error_set_ty.errorSetNames(zcu);
96419632 const valid_block = try self.wip.block(@intCast(names.len), "Valid");
96429633 const invalid_block = try self.wip.block(1, "Invalid");
96439634 const end_block = try self.wip.block(2, "End");
......@@ -9790,14 +9781,14 @@ pub const FuncGen = struct {
97909781 fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
97919782 const o = self.ng.object;
97929783 const pt = o.pt;
9793 const mod = pt.zcu;
9784 const zcu = pt.zcu;
97949785 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
97959786 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
97969787 const a = try self.resolveInst(extra.a);
97979788 const b = try self.resolveInst(extra.b);
97989789 const mask = Value.fromInterned(extra.mask);
97999790 const mask_len = extra.mask_len;
9800 const a_len = self.typeOf(extra.a).vectorLen(mod);
9791 const a_len = self.typeOf(extra.a).vectorLen(zcu);
98019792
98029793 // LLVM uses integers larger than the length of the first array to
98039794 // index into the second array. This was deemed unnecessarily fragile
......@@ -9809,10 +9800,10 @@ pub const FuncGen = struct {
98099800
98109801 for (values, 0..) |*val, i| {
98119802 const elem = try mask.elemValue(pt, i);
9812 if (elem.isUndef(mod)) {
9803 if (elem.isUndef(zcu)) {
98139804 val.* = try o.builder.undefConst(.i32);
98149805 } else {
9815 const int = elem.toSignedInt(pt);
9806 const int = elem.toSignedInt(zcu);
98169807 const unsigned: u32 = @intCast(if (int >= 0) int else ~int + a_len);
98179808 val.* = try o.builder.intConst(.i32, unsigned);
98189809 }
......@@ -9899,8 +9890,8 @@ pub const FuncGen = struct {
98999890
99009891 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
99019892 const o = self.ng.object;
9902 const mod = o.pt.zcu;
9903 const target = mod.getTarget();
9893 const zcu = o.pt.zcu;
9894 const target = zcu.getTarget();
99049895
99059896 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
99069897 const operand = try self.resolveInst(reduce.operand);
......@@ -9916,13 +9907,13 @@ pub const FuncGen = struct {
99169907 .Xor => .@"vector.reduce.xor",
99179908 else => unreachable,
99189909 }, &.{llvm_operand_ty}, &.{operand}, ""),
9919 .Min, .Max => switch (scalar_ty.zigTypeTag(mod)) {
9910 .Min, .Max => switch (scalar_ty.zigTypeTag(zcu)) {
99209911 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
9921 .Min => if (scalar_ty.isSignedInt(mod))
9912 .Min => if (scalar_ty.isSignedInt(zcu))
99229913 .@"vector.reduce.smin"
99239914 else
99249915 .@"vector.reduce.umin",
9925 .Max => if (scalar_ty.isSignedInt(mod))
9916 .Max => if (scalar_ty.isSignedInt(zcu))
99269917 .@"vector.reduce.smax"
99279918 else
99289919 .@"vector.reduce.umax",
......@@ -9936,7 +9927,7 @@ pub const FuncGen = struct {
99369927 }, &.{llvm_operand_ty}, &.{operand}, ""),
99379928 else => unreachable,
99389929 },
9939 .Add, .Mul => switch (scalar_ty.zigTypeTag(mod)) {
9930 .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
99409931 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
99419932 .Add => .@"vector.reduce.add",
99429933 .Mul => .@"vector.reduce.mul",
......@@ -10004,21 +9995,21 @@ pub const FuncGen = struct {
100049995 ))),
100059996 else => unreachable,
100069997 };
10007 return self.buildReducedCall(libc_fn, operand, operand_ty.vectorLen(mod), init_val);
9998 return self.buildReducedCall(libc_fn, operand, operand_ty.vectorLen(zcu), init_val);
100089999 }
1000910000
1001010001 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1001110002 const o = self.ng.object;
1001210003 const pt = o.pt;
10013 const mod = pt.zcu;
10014 const ip = &mod.intern_pool;
10004 const zcu = pt.zcu;
10005 const ip = &zcu.intern_pool;
1001510006 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1001610007 const result_ty = self.typeOfIndex(inst);
10017 const len: usize = @intCast(result_ty.arrayLen(mod));
10008 const len: usize = @intCast(result_ty.arrayLen(zcu));
1001810009 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
1001910010 const llvm_result_ty = try o.lowerType(result_ty);
1002010011
10021 switch (result_ty.zigTypeTag(mod)) {
10012 switch (result_ty.zigTypeTag(zcu)) {
1002210013 .Vector => {
1002310014 var vector = try o.builder.poisonValue(llvm_result_ty);
1002410015 for (elements, 0..) |elem, i| {
......@@ -10029,21 +10020,21 @@ pub const FuncGen = struct {
1002910020 return vector;
1003010021 },
1003110022 .Struct => {
10032 if (mod.typeToPackedStruct(result_ty)) |struct_type| {
10023 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {
1003310024 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
1003410025 assert(backing_int_ty != .none);
10035 const big_bits = Type.fromInterned(backing_int_ty).bitSize(pt);
10026 const big_bits = Type.fromInterned(backing_int_ty).bitSize(zcu);
1003610027 const int_ty = try o.builder.intType(@intCast(big_bits));
1003710028 comptime assert(Type.packed_struct_layout_version == 2);
1003810029 var running_int = try o.builder.intValue(int_ty, 0);
1003910030 var running_bits: u16 = 0;
1004010031 for (elements, struct_type.field_types.get(ip)) |elem, field_ty| {
10041 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
10032 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
1004210033
1004310034 const non_int_val = try self.resolveInst(elem);
10044 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(pt));
10035 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(zcu));
1004510036 const small_int_ty = try o.builder.intType(ty_bit_size);
10046 const small_int_val = if (Type.fromInterned(field_ty).isPtrAtRuntime(mod))
10037 const small_int_val = if (Type.fromInterned(field_ty).isPtrAtRuntime(zcu))
1004710038 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
1004810039 else
1004910040 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
......@@ -10057,12 +10048,12 @@ pub const FuncGen = struct {
1005710048 return running_int;
1005810049 }
1005910050
10060 assert(result_ty.containerLayout(mod) != .@"packed");
10051 assert(result_ty.containerLayout(zcu) != .@"packed");
1006110052
10062 if (isByRef(result_ty, pt)) {
10053 if (isByRef(result_ty, zcu)) {
1006310054 // TODO in debug builds init to undef so that the padding will be 0xaa
1006410055 // even if we fully populate the fields.
10065 const alignment = result_ty.abiAlignment(pt).toLlvm();
10056 const alignment = result_ty.abiAlignment(zcu).toLlvm();
1006610057 const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment);
1006710058
1006810059 for (elements, 0..) |elem, i| {
......@@ -10075,7 +10066,7 @@ pub const FuncGen = struct {
1007510066 const field_ptr_ty = try pt.ptrType(.{
1007610067 .child = self.typeOf(elem).toIntern(),
1007710068 .flags = .{
10078 .alignment = result_ty.structFieldAlign(i, pt),
10069 .alignment = result_ty.fieldAlignment(i, zcu),
1007910070 },
1008010071 });
1008110072 try self.store(field_ptr, field_ptr_ty, llvm_elem, .none);
......@@ -10095,14 +10086,14 @@ pub const FuncGen = struct {
1009510086 }
1009610087 },
1009710088 .Array => {
10098 assert(isByRef(result_ty, pt));
10089 assert(isByRef(result_ty, zcu));
1009910090
1010010091 const llvm_usize = try o.lowerType(Type.usize);
1010110092 const usize_zero = try o.builder.intValue(llvm_usize, 0);
10102 const alignment = result_ty.abiAlignment(pt).toLlvm();
10093 const alignment = result_ty.abiAlignment(zcu).toLlvm();
1010310094 const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment);
1010410095
10105 const array_info = result_ty.arrayInfo(mod);
10096 const array_info = result_ty.arrayInfo(zcu);
1010610097 const elem_ptr_ty = try pt.ptrType(.{
1010710098 .child = array_info.elem_type.toIntern(),
1010810099 });
......@@ -10131,22 +10122,22 @@ pub const FuncGen = struct {
1013110122 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
1013210123 const o = self.ng.object;
1013310124 const pt = o.pt;
10134 const mod = pt.zcu;
10135 const ip = &mod.intern_pool;
10125 const zcu = pt.zcu;
10126 const ip = &zcu.intern_pool;
1013610127 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1013710128 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
1013810129 const union_ty = self.typeOfIndex(inst);
1013910130 const union_llvm_ty = try o.lowerType(union_ty);
10140 const layout = union_ty.unionGetLayout(pt);
10141 const union_obj = mod.typeToUnion(union_ty).?;
10131 const layout = union_ty.unionGetLayout(zcu);
10132 const union_obj = zcu.typeToUnion(union_ty).?;
1014210133
1014310134 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
10144 const big_bits = union_ty.bitSize(pt);
10135 const big_bits = union_ty.bitSize(zcu);
1014510136 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));
1014610137 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
1014710138 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))
10139 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
10140 const small_int_val = if (field_ty.isPtrAtRuntime(zcu))
1015010141 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
1015110142 else
1015210143 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
......@@ -10154,9 +10145,9 @@ pub const FuncGen = struct {
1015410145 }
1015510146
1015610147 const tag_int_val = blk: {
10157 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
10148 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
1015810149 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).?;
10150 const enum_field_index = tag_ty.enumFieldIndex(union_field_name, zcu).?;
1016010151 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);
1016110152 break :blk try tag_val.intFromEnum(tag_ty, pt);
1016210153 };
......@@ -10164,12 +10155,12 @@ pub const FuncGen = struct {
1016410155 if (layout.tag_size == 0) {
1016510156 return .none;
1016610157 }
10167 assert(!isByRef(union_ty, pt));
10158 assert(!isByRef(union_ty, zcu));
1016810159 var big_int_space: Value.BigIntSpace = undefined;
10169 const tag_big_int = tag_int_val.toBigInt(&big_int_space, pt);
10160 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);
1017010161 return try o.builder.bigIntValue(union_llvm_ty, tag_big_int);
1017110162 }
10172 assert(isByRef(union_ty, pt));
10163 assert(isByRef(union_ty, zcu));
1017310164 // The llvm type of the alloca will be the named LLVM union type, and will not
1017410165 // necessarily match the format that we need, depending on which tag is active.
1017510166 // We must construct the correct unnamed struct type here, in order to then set
......@@ -10179,14 +10170,14 @@ pub const FuncGen = struct {
1017910170 const llvm_payload = try self.resolveInst(extra.init);
1018010171 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
1018110172 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);
10173 const field_size = field_ty.abiSize(zcu);
10174 const field_align = union_ty.fieldAlignment(extra.field_index, zcu);
1018410175 const llvm_usize = try o.lowerType(Type.usize);
1018510176 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1018610177
1018710178 const llvm_union_ty = t: {
1018810179 const payload_ty = p: {
10189 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {
10180 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1019010181 const padding_len = layout.payload_size;
1019110182 break :p try o.builder.arrayType(padding_len, .i8);
1019210183 }
......@@ -10242,9 +10233,9 @@ pub const FuncGen = struct {
1024210233 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");
1024310234 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
1024410235 var big_int_space: Value.BigIntSpace = undefined;
10245 const tag_big_int = tag_int_val.toBigInt(&big_int_space, pt);
10236 const tag_big_int = tag_int_val.toBigInt(&big_int_space, zcu);
1024610237 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();
10238 const tag_alignment = Type.fromInterned(union_obj.enum_tag_ty).abiAlignment(zcu).toLlvm();
1024810239 _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment);
1024910240 }
1025010241
......@@ -10270,8 +10261,8 @@ pub const FuncGen = struct {
1027010261 // by the target.
1027110262 // To work around this, don't emit llvm.prefetch in this case.
1027210263 // See https://bugs.llvm.org/show_bug.cgi?id=21037
10273 const mod = o.pt.zcu;
10274 const target = mod.getTarget();
10264 const zcu = o.pt.zcu;
10265 const target = zcu.getTarget();
1027510266 switch (prefetch.cache) {
1027610267 .instruction => switch (target.cpu.arch) {
1027710268 .x86_64,
......@@ -10397,7 +10388,7 @@ pub const FuncGen = struct {
1039710388 variable_index.setMutability(.constant, &o.builder);
1039810389 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
1039910390 variable_index.setAlignment(
10400 Type.slice_const_u8_sentinel_0.abiAlignment(pt).toLlvm(),
10391 Type.slice_const_u8_sentinel_0.abiAlignment(pt.zcu).toLlvm(),
1040110392 &o.builder,
1040210393 );
1040310394
......@@ -10436,15 +10427,15 @@ pub const FuncGen = struct {
1043610427 ) !Builder.Value {
1043710428 const o = fg.ng.object;
1043810429 const pt = o.pt;
10439 const mod = pt.zcu;
10440 const payload_ty = opt_ty.optionalChild(mod);
10430 const zcu = pt.zcu;
10431 const payload_ty = opt_ty.optionalChild(zcu);
1044110432
10442 if (isByRef(opt_ty, pt)) {
10433 if (isByRef(opt_ty, zcu)) {
1044310434 // We have a pointer and we need to return a pointer to the first field.
1044410435 const payload_ptr = try fg.wip.gepStruct(opt_llvm_ty, opt_handle, 0, "");
1044510436
10446 const payload_alignment = payload_ty.abiAlignment(pt).toLlvm();
10447 if (isByRef(payload_ty, pt)) {
10437 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
10438 if (isByRef(payload_ty, zcu)) {
1044810439 if (can_elide_load)
1044910440 return payload_ptr;
1045010441
......@@ -10453,7 +10444,7 @@ pub const FuncGen = struct {
1045310444 return fg.loadTruncate(.normal, payload_ty, payload_ptr, payload_alignment);
1045410445 }
1045510446
10456 assert(!isByRef(payload_ty, pt));
10447 assert(!isByRef(payload_ty, zcu));
1045710448 return fg.wip.extractValue(opt_handle, &.{0}, "");
1045810449 }
1045910450
......@@ -10465,11 +10456,12 @@ pub const FuncGen = struct {
1046510456 ) !Builder.Value {
1046610457 const o = self.ng.object;
1046710458 const pt = o.pt;
10459 const zcu = pt.zcu;
1046810460 const optional_llvm_ty = try o.lowerType(optional_ty);
1046910461 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");
1047010462
10471 if (isByRef(optional_ty, pt)) {
10472 const payload_alignment = optional_ty.abiAlignment(pt).toLlvm();
10463 if (isByRef(optional_ty, zcu)) {
10464 const payload_alignment = optional_ty.abiAlignment(pt.zcu).toLlvm();
1047310465 const alloca_inst = try self.buildAllocaWorkaround(optional_ty, payload_alignment);
1047410466
1047510467 {
......@@ -10497,15 +10489,15 @@ pub const FuncGen = struct {
1049710489 ) !Builder.Value {
1049810490 const o = self.ng.object;
1049910491 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)) {
10492 const zcu = pt.zcu;
10493 const struct_ty = struct_ptr_ty.childType(zcu);
10494 switch (struct_ty.zigTypeTag(zcu)) {
10495 .Struct => switch (struct_ty.containerLayout(zcu)) {
1050410496 .@"packed" => {
1050510497 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).?;
10498 const result_ty_info = result_ty.ptrInfo(zcu);
10499 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu);
10500 const struct_type = zcu.typeToStruct(struct_ty).?;
1050910501
1051010502 if (result_ty_info.packed_offset.host_size != 0) {
1051110503 // From LLVM's perspective, a pointer to a packed struct and a pointer
......@@ -10535,15 +10527,15 @@ pub const FuncGen = struct {
1053510527 // the struct.
1053610528 const llvm_index = try o.builder.intValue(
1053710529 try o.lowerType(Type.usize),
10538 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(pt)),
10530 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)),
1053910531 );
1054010532 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");
1054110533 }
1054210534 },
1054310535 },
1054410536 .Union => {
10545 const layout = struct_ty.unionGetLayout(pt);
10546 if (layout.payload_size == 0 or struct_ty.containerLayout(mod) == .@"packed") return struct_ptr;
10537 const layout = struct_ty.unionGetLayout(zcu);
10538 if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr;
1054710539 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
1054810540 const union_llvm_ty = try o.lowerType(struct_ty);
1054910541 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");
......@@ -10566,9 +10558,9 @@ pub const FuncGen = struct {
1056610558
1056710559 const o = fg.ng.object;
1056810560 const pt = o.pt;
10569 const mod = pt.zcu;
10561 const zcu = pt.zcu;
1057010562 const payload_llvm_ty = try o.lowerType(payload_ty);
10571 const abi_size = payload_ty.abiSize(pt);
10563 const abi_size = payload_ty.abiSize(zcu);
1057210564
1057310565 // llvm bug workarounds:
1057410566 const workaround_explicit_mask = o.target.cpu.arch == .powerpc and abi_size >= 4;
......@@ -10580,7 +10572,7 @@ pub const FuncGen = struct {
1058010572 return try fg.wip.load(access_kind, payload_llvm_ty, payload_ptr, payload_alignment, "");
1058110573 }
1058210574
10583 const load_llvm_ty = if (payload_ty.isAbiInt(mod))
10575 const load_llvm_ty = if (payload_ty.isAbiInt(zcu))
1058410576 try o.builder.intType(@intCast(abi_size * 8))
1058510577 else
1058610578 payload_llvm_ty;
......@@ -10588,7 +10580,7 @@ pub const FuncGen = struct {
1058810580 const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .big)
1058910581 try fg.wip.bin(.lshr, loaded, try o.builder.intValue(
1059010582 load_llvm_ty,
10591 (payload_ty.abiSize(pt) - (std.math.divCeil(u64, payload_ty.bitSize(pt), 8) catch unreachable)) * 8,
10583 (payload_ty.abiSize(zcu) - (std.math.divCeil(u64, payload_ty.bitSize(zcu), 8) catch unreachable)) * 8,
1059210584 ), "")
1059310585 else
1059410586 loaded;
......@@ -10614,9 +10606,10 @@ pub const FuncGen = struct {
1061410606 const o = fg.ng.object;
1061510607 const pt = o.pt;
1061610608 //const pointee_llvm_ty = try o.lowerType(pointee_type);
10617 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment).max(pointee_type.abiAlignment(pt)).toLlvm();
10609 const result_align = InternPool.Alignment.fromLlvm(ptr_alignment)
10610 .max(pointee_type.abiAlignment(pt.zcu)).toLlvm();
1061810611 const result_ptr = try fg.buildAllocaWorkaround(pointee_type, result_align);
10619 const size_bytes = pointee_type.abiSize(pt);
10612 const size_bytes = pointee_type.abiSize(pt.zcu);
1062010613 _ = try fg.wip.callMemCpy(
1062110614 result_ptr,
1062210615 result_align,
......@@ -10634,15 +10627,15 @@ pub const FuncGen = struct {
1063410627 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {
1063510628 const o = self.ng.object;
1063610629 const pt = o.pt;
10637 const mod = pt.zcu;
10638 const info = ptr_ty.ptrInfo(mod);
10630 const zcu = pt.zcu;
10631 const info = ptr_ty.ptrInfo(zcu);
1063910632 const elem_ty = Type.fromInterned(info.child);
10640 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;
10633 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
1064110634
1064210635 const ptr_alignment = (if (info.flags.alignment != .none)
1064310636 @as(InternPool.Alignment, info.flags.alignment)
1064410637 else
10645 elem_ty.abiAlignment(pt)).toLlvm();
10638 elem_ty.abiAlignment(zcu)).toLlvm();
1064610639
1064710640 const access_kind: Builder.MemoryAccessKind =
1064810641 if (info.flags.is_volatile) .@"volatile" else .normal;
......@@ -10658,7 +10651,7 @@ pub const FuncGen = struct {
1065810651 }
1065910652
1066010653 if (info.packed_offset.host_size == 0) {
10661 if (isByRef(elem_ty, pt)) {
10654 if (isByRef(elem_ty, zcu)) {
1066210655 return self.loadByRef(ptr, elem_ty, ptr_alignment, access_kind);
1066310656 }
1066410657 return self.loadTruncate(access_kind, elem_ty, ptr, ptr_alignment);
......@@ -10668,13 +10661,13 @@ pub const FuncGen = struct {
1066810661 const containing_int =
1066910662 try self.wip.load(access_kind, containing_int_ty, ptr, ptr_alignment, "");
1067010663
10671 const elem_bits = ptr_ty.childType(mod).bitSize(pt);
10664 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
1067210665 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);
1067310666 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
1067410667 const elem_llvm_ty = try o.lowerType(elem_ty);
1067510668
10676 if (isByRef(elem_ty, pt)) {
10677 const result_align = elem_ty.abiAlignment(pt).toLlvm();
10669 if (isByRef(elem_ty, zcu)) {
10670 const result_align = elem_ty.abiAlignment(zcu).toLlvm();
1067810671 const result_ptr = try self.buildAllocaWorkaround(elem_ty, result_align);
1067910672
1068010673 const same_size_int = try o.builder.intType(@intCast(elem_bits));
......@@ -10683,13 +10676,13 @@ pub const FuncGen = struct {
1068310676 return result_ptr;
1068410677 }
1068510678
10686 if (elem_ty.zigTypeTag(mod) == .Float or elem_ty.zigTypeTag(mod) == .Vector) {
10679 if (elem_ty.zigTypeTag(zcu) == .Float or elem_ty.zigTypeTag(zcu) == .Vector) {
1068710680 const same_size_int = try o.builder.intType(@intCast(elem_bits));
1068810681 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");
1068910682 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");
1069010683 }
1069110684
10692 if (elem_ty.isPtrAtRuntime(mod)) {
10685 if (elem_ty.isPtrAtRuntime(zcu)) {
1069310686 const same_size_int = try o.builder.intType(@intCast(elem_bits));
1069410687 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");
1069510688 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
......@@ -10707,13 +10700,13 @@ pub const FuncGen = struct {
1070710700 ) !void {
1070810701 const o = self.ng.object;
1070910702 const pt = o.pt;
10710 const mod = pt.zcu;
10711 const info = ptr_ty.ptrInfo(mod);
10703 const zcu = pt.zcu;
10704 const info = ptr_ty.ptrInfo(zcu);
1071210705 const elem_ty = Type.fromInterned(info.child);
10713 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {
10706 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
1071410707 return;
1071510708 }
10716 const ptr_alignment = ptr_ty.ptrAlignment(pt).toLlvm();
10709 const ptr_alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
1071710710 const access_kind: Builder.MemoryAccessKind =
1071810711 if (info.flags.is_volatile) .@"volatile" else .normal;
1071910712
......@@ -10737,12 +10730,12 @@ pub const FuncGen = struct {
1073710730 assert(ordering == .none);
1073810731 const containing_int =
1073910732 try self.wip.load(access_kind, containing_int_ty, ptr, ptr_alignment, "");
10740 const elem_bits = ptr_ty.childType(mod).bitSize(pt);
10733 const elem_bits = ptr_ty.childType(zcu).bitSize(zcu);
1074110734 const shift_amt = try o.builder.intConst(containing_int_ty, info.packed_offset.bit_offset);
1074210735 // Convert to equally-sized integer type in order to perform the bit
1074310736 // operations on the value to store
1074410737 const value_bits_type = try o.builder.intType(@intCast(elem_bits));
10745 const value_bits = if (elem_ty.isPtrAtRuntime(mod))
10738 const value_bits = if (elem_ty.isPtrAtRuntime(zcu))
1074610739 try self.wip.cast(.ptrtoint, elem, value_bits_type, "")
1074710740 else
1074810741 try self.wip.cast(.bitcast, elem, value_bits_type, "");
......@@ -10772,7 +10765,7 @@ pub const FuncGen = struct {
1077210765 _ = try self.wip.store(access_kind, ored_value, ptr, ptr_alignment);
1077310766 return;
1077410767 }
10775 if (!isByRef(elem_ty, pt)) {
10768 if (!isByRef(elem_ty, zcu)) {
1077610769 _ = try self.wip.storeAtomic(
1077710770 access_kind,
1077810771 elem,
......@@ -10788,8 +10781,8 @@ pub const FuncGen = struct {
1078810781 ptr,
1078910782 ptr_alignment,
1079010783 elem,
10791 elem_ty.abiAlignment(pt).toLlvm(),
10792 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(pt)),
10784 elem_ty.abiAlignment(zcu).toLlvm(),
10785 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)),
1079310786 access_kind,
1079410787 );
1079510788 }
......@@ -10816,12 +10809,12 @@ pub const FuncGen = struct {
1081610809 ) Allocator.Error!Builder.Value {
1081710810 const o = fg.ng.object;
1081810811 const pt = o.pt;
10819 const mod = pt.zcu;
10820 const target = mod.getTarget();
10812 const zcu = pt.zcu;
10813 const target = zcu.getTarget();
1082110814 if (!target_util.hasValgrindSupport(target)) return default_value;
1082210815
1082310816 const llvm_usize = try o.lowerType(Type.usize);
10824 const usize_alignment = Type.usize.abiAlignment(pt).toLlvm();
10817 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
1082510818
1082610819 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);
1082710820 const array_ptr = if (fg.valgrind_client_request_array == .none) a: {
......@@ -10882,14 +10875,14 @@ pub const FuncGen = struct {
1088210875
1088310876 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
1088410877 const o = fg.ng.object;
10885 const mod = o.pt.zcu;
10886 return fg.air.typeOf(inst, &mod.intern_pool);
10878 const zcu = o.pt.zcu;
10879 return fg.air.typeOf(inst, &zcu.intern_pool);
1088710880 }
1088810881
1088910882 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
1089010883 const o = fg.ng.object;
10891 const mod = o.pt.zcu;
10892 return fg.air.typeOfIndex(inst, &mod.intern_pool);
10884 const zcu = o.pt.zcu;
10885 return fg.air.typeOfIndex(inst, &zcu.intern_pool);
1089310886 }
1089410887};
1089510888
......@@ -11059,12 +11052,12 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ
1105911052 };
1106011053}
1106111054
11062fn returnTypeByRef(pt: Zcu.PerThread, target: std.Target, ty: Type) bool {
11063 if (isByRef(ty, pt)) {
11055fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {
11056 if (isByRef(ty, zcu)) {
1106411057 return true;
1106511058 } else if (target.cpu.arch.isX86() and
1106611059 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and
11067 ty.totalVectorBits(pt) >= 512)
11060 ty.totalVectorBits(zcu) >= 512)
1106811061 {
1106911062 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns
1107011063 // "512-bit vector arguments require 'evex512' for AVX512"
......@@ -11074,38 +11067,38 @@ fn returnTypeByRef(pt: Zcu.PerThread, target: std.Target, ty: Type) bool {
1107411067 }
1107511068}
1107611069
11077fn firstParamSRet(fn_info: InternPool.Key.FuncType, pt: Zcu.PerThread, target: std.Target) bool {
11070fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Target) bool {
1107811071 const return_type = Type.fromInterned(fn_info.return_type);
11079 if (!return_type.hasRuntimeBitsIgnoreComptime(pt)) return false;
11072 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;
1108011073
1108111074 return switch (fn_info.cc) {
11082 .Unspecified, .Inline => returnTypeByRef(pt, target, return_type),
11075 .Unspecified, .Inline => returnTypeByRef(zcu, target, return_type),
1108311076 .C => switch (target.cpu.arch) {
1108411077 .mips, .mipsel => false,
11085 .x86 => isByRef(return_type, pt),
11078 .x86 => isByRef(return_type, zcu),
1108611079 .x86_64 => switch (target.os.tag) {
11087 .windows => x86_64_abi.classifyWindows(return_type, pt) == .memory,
11088 else => firstParamSRetSystemV(return_type, pt, target),
11080 .windows => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
11081 else => firstParamSRetSystemV(return_type, zcu, target),
1108911082 },
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)) {
11083 .wasm32 => wasm_c_abi.classifyType(return_type, zcu)[0] == .indirect,
11084 .aarch64, .aarch64_be => aarch64_c_abi.classifyType(return_type, zcu) == .memory,
11085 .arm, .armeb => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1109311086 .memory, .i64_array => true,
1109411087 .i32_array => |size| size != 1,
1109511088 .byval => false,
1109611089 },
11097 .riscv32, .riscv64 => riscv_c_abi.classifyType(return_type, pt) == .memory,
11090 .riscv32, .riscv64 => riscv_c_abi.classifyType(return_type, zcu) == .memory,
1109811091 else => false, // TODO investigate C ABI for other architectures
1109911092 },
11100 .SysV => firstParamSRetSystemV(return_type, pt, target),
11101 .Win64 => x86_64_abi.classifyWindows(return_type, pt) == .memory,
11102 .Stdcall => !isScalar(pt.zcu, return_type),
11093 .SysV => firstParamSRetSystemV(return_type, zcu, target),
11094 .Win64 => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
11095 .Stdcall => !isScalar(zcu, return_type),
1110311096 else => false,
1110411097 };
1110511098}
1110611099
11107fn firstParamSRetSystemV(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
11108 const class = x86_64_abi.classifySystemV(ty, pt, target, .ret);
11100fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: std.Target) bool {
11101 const class = x86_64_abi.classifySystemV(ty, zcu, target, .ret);
1110911102 if (class[0] == .memory) return true;
1111011103 if (class[0] == .x87 and class[2] != .none) return true;
1111111104 return false;
......@@ -11116,62 +11109,62 @@ fn firstParamSRetSystemV(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
1111611109/// be effectively bitcasted to the actual return type.
1111711110fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1111811111 const pt = o.pt;
11119 const mod = pt.zcu;
11112 const zcu = pt.zcu;
1112011113 const return_type = Type.fromInterned(fn_info.return_type);
11121 if (!return_type.hasRuntimeBitsIgnoreComptime(pt)) {
11114 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
1112211115 // If the return type is an error set or an error union, then we make this
1112311116 // anyerror return type instead, so that it can be coerced into a function
1112411117 // pointer type which has anyerror as the return type.
11125 return if (return_type.isError(mod)) try o.errorIntType() else .void;
11118 return if (return_type.isError(zcu)) try o.errorIntType() else .void;
1112611119 }
11127 const target = mod.getTarget();
11120 const target = zcu.getTarget();
1112811121 switch (fn_info.cc) {
1112911122 .Unspecified,
1113011123 .Inline,
11131 => return if (returnTypeByRef(pt, target, return_type)) .void else o.lowerType(return_type),
11124 => return if (returnTypeByRef(zcu, target, return_type)) .void else o.lowerType(return_type),
1113211125
1113311126 .C => {
1113411127 switch (target.cpu.arch) {
1113511128 .mips, .mipsel => return o.lowerType(return_type),
11136 .x86 => return if (isByRef(return_type, pt)) .void else o.lowerType(return_type),
11129 .x86 => return if (isByRef(return_type, zcu)) .void else o.lowerType(return_type),
1113711130 .x86_64 => switch (target.os.tag) {
1113811131 .windows => return lowerWin64FnRetTy(o, fn_info),
1113911132 else => return lowerSystemVFnRetTy(o, fn_info),
1114011133 },
1114111134 .wasm32 => {
11142 if (isScalar(mod, return_type)) {
11135 if (isScalar(zcu, return_type)) {
1114311136 return o.lowerType(return_type);
1114411137 }
11145 const classes = wasm_c_abi.classifyType(return_type, pt);
11138 const classes = wasm_c_abi.classifyType(return_type, zcu);
1114611139 if (classes[0] == .indirect or classes[0] == .none) {
1114711140 return .void;
1114811141 }
1114911142
1115011143 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));
11144 const scalar_type = wasm_c_abi.scalarType(return_type, zcu);
11145 return o.builder.intType(@intCast(scalar_type.abiSize(zcu) * 8));
1115311146 },
1115411147 .aarch64, .aarch64_be => {
11155 switch (aarch64_c_abi.classifyType(return_type, pt)) {
11148 switch (aarch64_c_abi.classifyType(return_type, zcu)) {
1115611149 .memory => return .void,
1115711150 .float_array => return o.lowerType(return_type),
1115811151 .byval => return o.lowerType(return_type),
11159 .integer => return o.builder.intType(@intCast(return_type.bitSize(pt))),
11152 .integer => return o.builder.intType(@intCast(return_type.bitSize(zcu))),
1116011153 .double_integer => return o.builder.arrayType(2, .i64),
1116111154 }
1116211155 },
1116311156 .arm, .armeb => {
11164 switch (arm_c_abi.classifyType(return_type, pt, .ret)) {
11157 switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
1116511158 .memory, .i64_array => return .void,
1116611159 .i32_array => |len| return if (len == 1) .i32 else .void,
1116711160 .byval => return o.lowerType(return_type),
1116811161 }
1116911162 },
1117011163 .riscv32, .riscv64 => {
11171 switch (riscv_c_abi.classifyType(return_type, pt)) {
11164 switch (riscv_c_abi.classifyType(return_type, zcu)) {
1117211165 .memory => return .void,
1117311166 .integer => {
11174 return o.builder.intType(@intCast(return_type.bitSize(pt)));
11167 return o.builder.intType(@intCast(return_type.bitSize(zcu)));
1117511168 },
1117611169 .double_integer => {
1117711170 return o.builder.structType(.normal, &.{ .i64, .i64 });
......@@ -11180,9 +11173,9 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1118011173 .fields => {
1118111174 var types_len: usize = 0;
1118211175 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;
11176 for (0..return_type.structFieldCount(zcu)) |field_index| {
11177 const field_ty = return_type.fieldType(field_index, zcu);
11178 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1118611179 types[types_len] = try o.lowerType(field_ty);
1118711180 types_len += 1;
1118811181 }
......@@ -11196,20 +11189,20 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1119611189 },
1119711190 .Win64 => return lowerWin64FnRetTy(o, fn_info),
1119811191 .SysV => return lowerSystemVFnRetTy(o, fn_info),
11199 .Stdcall => return if (isScalar(mod, return_type)) o.lowerType(return_type) else .void,
11192 .Stdcall => return if (isScalar(zcu, return_type)) o.lowerType(return_type) else .void,
1120011193 else => return o.lowerType(return_type),
1120111194 }
1120211195}
1120311196
1120411197fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
11205 const pt = o.pt;
11198 const zcu = o.pt.zcu;
1120611199 const return_type = Type.fromInterned(fn_info.return_type);
11207 switch (x86_64_abi.classifyWindows(return_type, pt)) {
11200 switch (x86_64_abi.classifyWindows(return_type, zcu)) {
1120811201 .integer => {
11209 if (isScalar(pt.zcu, return_type)) {
11202 if (isScalar(zcu, return_type)) {
1121011203 return o.lowerType(return_type);
1121111204 } else {
11212 return o.builder.intType(@intCast(return_type.abiSize(pt) * 8));
11205 return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8));
1121311206 }
1121411207 },
1121511208 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),
......@@ -11221,14 +11214,14 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Err
1122111214
1122211215fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1122311216 const pt = o.pt;
11224 const mod = pt.zcu;
11225 const ip = &mod.intern_pool;
11217 const zcu = pt.zcu;
11218 const ip = &zcu.intern_pool;
1122611219 const return_type = Type.fromInterned(fn_info.return_type);
11227 if (isScalar(mod, return_type)) {
11220 if (isScalar(zcu, return_type)) {
1122811221 return o.lowerType(return_type);
1122911222 }
11230 const target = mod.getTarget();
11231 const classes = x86_64_abi.classifySystemV(return_type, pt, target, .ret);
11223 const target = zcu.getTarget();
11224 const classes = x86_64_abi.classifySystemV(return_type, zcu, target, .ret);
1123211225 if (classes[0] == .memory) return .void;
1123311226 var types_index: u32 = 0;
1123411227 var types_buffer: [8]Builder.Type = undefined;
......@@ -11345,7 +11338,7 @@ const ParamTypeIterator = struct {
1134511338 const zcu = pt.zcu;
1134611339 const target = zcu.getTarget();
1134711340
11348 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {
11341 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1134911342 it.zig_index += 1;
1135011343 return .no_bits;
1135111344 }
......@@ -11358,11 +11351,11 @@ const ParamTypeIterator = struct {
1135811351 {
1135911352 it.llvm_index += 1;
1136011353 return .slice;
11361 } else if (isByRef(ty, pt)) {
11354 } else if (isByRef(ty, zcu)) {
1136211355 return .byref;
1136311356 } else if (target.cpu.arch.isX86() and
1136411357 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and
11365 ty.totalVectorBits(pt) >= 512)
11358 ty.totalVectorBits(zcu) >= 512)
1136611359 {
1136711360 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns
1136811361 // "512-bit vector arguments require 'evex512' for AVX512"
......@@ -11390,7 +11383,7 @@ const ParamTypeIterator = struct {
1139011383 if (isScalar(zcu, ty)) {
1139111384 return .byval;
1139211385 }
11393 const classes = wasm_c_abi.classifyType(ty, pt);
11386 const classes = wasm_c_abi.classifyType(ty, zcu);
1139411387 if (classes[0] == .indirect) {
1139511388 return .byref;
1139611389 }
......@@ -11399,7 +11392,7 @@ const ParamTypeIterator = struct {
1139911392 .aarch64, .aarch64_be => {
1140011393 it.zig_index += 1;
1140111394 it.llvm_index += 1;
11402 switch (aarch64_c_abi.classifyType(ty, pt)) {
11395 switch (aarch64_c_abi.classifyType(ty, zcu)) {
1140311396 .memory => return .byref_mut,
1140411397 .float_array => |len| return Lowering{ .float_array = len },
1140511398 .byval => return .byval,
......@@ -11414,7 +11407,7 @@ const ParamTypeIterator = struct {
1141411407 .arm, .armeb => {
1141511408 it.zig_index += 1;
1141611409 it.llvm_index += 1;
11417 switch (arm_c_abi.classifyType(ty, pt, .arg)) {
11410 switch (arm_c_abi.classifyType(ty, zcu, .arg)) {
1141811411 .memory => {
1141911412 it.byval_attr = true;
1142011413 return .byref;
......@@ -11429,7 +11422,7 @@ const ParamTypeIterator = struct {
1142911422 it.llvm_index += 1;
1143011423 if (ty.toIntern() == .f16_type and
1143111424 !std.Target.riscv.featureSetHas(target.cpu.features, .d)) return .as_u16;
11432 switch (riscv_c_abi.classifyType(ty, pt)) {
11425 switch (riscv_c_abi.classifyType(ty, zcu)) {
1143311426 .memory => return .byref_mut,
1143411427 .byval => return .byval,
1143511428 .integer => return .abi_sized_int,
......@@ -11437,8 +11430,8 @@ const ParamTypeIterator = struct {
1143711430 .fields => {
1143811431 it.types_len = 0;
1143911432 for (0..ty.structFieldCount(zcu)) |field_index| {
11440 const field_ty = ty.structFieldType(field_index, zcu);
11441 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;
11433 const field_ty = ty.fieldType(field_index, zcu);
11434 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
1144211435 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);
1144311436 it.types_len += 1;
1144411437 }
......@@ -11476,10 +11469,10 @@ const ParamTypeIterator = struct {
1147611469 }
1147711470
1147811471 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {
11479 const pt = it.object.pt;
11480 switch (x86_64_abi.classifyWindows(ty, pt)) {
11472 const zcu = it.object.pt.zcu;
11473 switch (x86_64_abi.classifyWindows(ty, zcu)) {
1148111474 .integer => {
11482 if (isScalar(pt.zcu, ty)) {
11475 if (isScalar(zcu, ty)) {
1148311476 it.zig_index += 1;
1148411477 it.llvm_index += 1;
1148511478 return .byval;
......@@ -11509,17 +11502,17 @@ const ParamTypeIterator = struct {
1150911502 }
1151011503
1151111504 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);
11505 const zcu = it.object.pt.zcu;
11506 const ip = &zcu.intern_pool;
11507 const target = zcu.getTarget();
11508 const classes = x86_64_abi.classifySystemV(ty, zcu, target, .arg);
1151611509 if (classes[0] == .memory) {
1151711510 it.zig_index += 1;
1151811511 it.llvm_index += 1;
1151911512 it.byval_attr = true;
1152011513 return .byref;
1152111514 }
11522 if (isScalar(pt.zcu, ty)) {
11515 if (isScalar(zcu, ty)) {
1152311516 it.zig_index += 1;
1152411517 it.llvm_index += 1;
1152511518 return .byval;
......@@ -11620,17 +11613,17 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp
1162011613
1162111614fn ccAbiPromoteInt(
1162211615 cc: std.builtin.CallingConvention,
11623 mod: *Zcu,
11616 zcu: *Zcu,
1162411617 ty: Type,
1162511618) ?std.builtin.Signedness {
11626 const target = mod.getTarget();
11619 const target = zcu.getTarget();
1162711620 switch (cc) {
1162811621 .Unspecified, .Inline, .Async => return null,
1162911622 else => {},
1163011623 }
11631 const int_info = switch (ty.zigTypeTag(mod)) {
11632 .Bool => Type.u1.intInfo(mod),
11633 .Int, .Enum, .ErrorSet => ty.intInfo(mod),
11624 const int_info = switch (ty.zigTypeTag(zcu)) {
11625 .Bool => Type.u1.intInfo(zcu),
11626 .Int, .Enum, .ErrorSet => ty.intInfo(zcu),
1163411627 else => return null,
1163511628 };
1163611629 return switch (target.os.tag) {
......@@ -11668,13 +11661,13 @@ fn ccAbiPromoteInt(
1166811661
1166911662/// This is the one source of truth for whether a type is passed around as an LLVM pointer,
1167011663/// or as an LLVM value.
11671fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
11664fn isByRef(ty: Type, zcu: *Zcu) bool {
1167211665 // For tuples and structs, if there are more than this many non-void
1167311666 // fields, then we make it byref, otherwise byval.
1167411667 const max_fields_byval = 0;
11675 const ip = &pt.zcu.intern_pool;
11668 const ip = &zcu.intern_pool;
1167611669
11677 switch (ty.zigTypeTag(pt.zcu)) {
11670 switch (ty.zigTypeTag(zcu)) {
1167811671 .Type,
1167911672 .ComptimeInt,
1168011673 .ComptimeFloat,
......@@ -11697,17 +11690,17 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1169711690 .AnyFrame,
1169811691 => return false,
1169911692
11700 .Array, .Frame => return ty.hasRuntimeBits(pt),
11693 .Array, .Frame => return ty.hasRuntimeBits(zcu),
1170111694 .Struct => {
1170211695 const struct_type = switch (ip.indexToKey(ty.toIntern())) {
1170311696 .anon_struct_type => |tuple| {
1170411697 var count: usize = 0;
1170511698 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;
11699 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
1170711700
1170811701 count += 1;
1170911702 if (count > max_fields_byval) return true;
11710 if (isByRef(Type.fromInterned(field_ty), pt)) return true;
11703 if (isByRef(Type.fromInterned(field_ty), zcu)) return true;
1171111704 }
1171211705 return false;
1171311706 },
......@@ -11725,27 +11718,27 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1172511718 count += 1;
1172611719 if (count > max_fields_byval) return true;
1172711720 const field_ty = Type.fromInterned(field_types[field_index]);
11728 if (isByRef(field_ty, pt)) return true;
11721 if (isByRef(field_ty, zcu)) return true;
1172911722 }
1173011723 return false;
1173111724 },
11732 .Union => switch (ty.containerLayout(pt.zcu)) {
11725 .Union => switch (ty.containerLayout(zcu)) {
1173311726 .@"packed" => return false,
11734 else => return ty.hasRuntimeBits(pt),
11727 else => return ty.hasRuntimeBits(zcu),
1173511728 },
1173611729 .ErrorUnion => {
11737 const payload_ty = ty.errorUnionPayload(pt.zcu);
11738 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
11730 const payload_ty = ty.errorUnionPayload(zcu);
11731 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1173911732 return false;
1174011733 }
1174111734 return true;
1174211735 },
1174311736 .Optional => {
11744 const payload_ty = ty.optionalChild(pt.zcu);
11745 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {
11737 const payload_ty = ty.optionalChild(zcu);
11738 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1174611739 return false;
1174711740 }
11748 if (ty.optionalReprIsPayload(pt.zcu)) {
11741 if (ty.optionalReprIsPayload(zcu)) {
1174911742 return false;
1175011743 }
1175111744 return true;
......@@ -11753,8 +11746,8 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1175311746 }
1175411747}
1175511748
11756fn isScalar(mod: *Zcu, ty: Type) bool {
11757 return switch (ty.zigTypeTag(mod)) {
11749fn isScalar(zcu: *Zcu, ty: Type) bool {
11750 return switch (ty.zigTypeTag(zcu)) {
1175811751 .Void,
1175911752 .Bool,
1176011753 .NoReturn,
......@@ -11768,8 +11761,8 @@ fn isScalar(mod: *Zcu, ty: Type) bool {
1176811761 .Vector,
1176911762 => true,
1177011763
11771 .Struct => ty.containerLayout(mod) == .@"packed",
11772 .Union => ty.containerLayout(mod) == .@"packed",
11764 .Struct => ty.containerLayout(zcu) == .@"packed",
11765 .Union => ty.containerLayout(zcu) == .@"packed",
1177311766 else => false,
1177411767 };
1177511768}
......@@ -11892,13 +11885,15 @@ fn buildAllocaInner(
1189211885}
1189311886
1189411887fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {
11888 const zcu = pt.zcu;
1189511889 const err_int_ty = try pt.errorIntType();
11896 return @intFromBool(err_int_ty.abiAlignment(pt).compare(.gt, payload_ty.abiAlignment(pt)));
11890 return @intFromBool(err_int_ty.abiAlignment(zcu).compare(.gt, payload_ty.abiAlignment(zcu)));
1189711891}
1189811892
1189911893fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {
11894 const zcu = pt.zcu;
1190011895 const err_int_ty = try pt.errorIntType();
11901 return @intFromBool(err_int_ty.abiAlignment(pt).compare(.lte, payload_ty.abiAlignment(pt)));
11896 return @intFromBool(err_int_ty.abiAlignment(zcu).compare(.lte, payload_ty.abiAlignment(zcu)));
1190211897}
1190311898
1190411899/// 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.fieldType(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.zig+1-1
......@@ -755,7 +755,7 @@ pub const File = struct {
755755 const directory = base.emit.root_dir; // Just an alias to make it shorter to type.
756756 const full_out_path = try directory.join(arena, &[_][]const u8{base.emit.sub_path});
757757 const full_out_path_z = try arena.dupeZ(u8, full_out_path);
758 const opt_zcu = comp.module;
758 const opt_zcu = comp.zcu;
759759
760760 // If there is no Zig code to compile, then we should skip flushing the output file
761761 // because it will not be part of the linker line anyway.
src/link/C.zig+2-2
......@@ -327,7 +327,7 @@ pub fn updateNav(self: *C, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !
327327 .variable => |variable| variable.init,
328328 else => nav.status.resolved.val,
329329 };
330 if (nav_init != .none and !Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(pt)) return;
330 if (nav_init != .none and !Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(zcu)) return;
331331
332332 const gop = try self.navs.getOrPut(gpa, nav_index);
333333 errdefer _ = self.navs.pop();
......@@ -418,7 +418,7 @@ pub fn flushModule(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
418418
419419 const comp = self.base.comp;
420420 const gpa = comp.gpa;
421 const zcu = self.base.comp.module.?;
421 const zcu = self.base.comp.zcu.?;
422422 const ip = &zcu.intern_pool;
423423 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = tid };
424424
src/link/Coff.zig+34-36
......@@ -1141,7 +1141,7 @@ pub fn updateFunc(self: *Coff, pt: Zcu.PerThread, func_index: InternPool.Index,
11411141
11421142const LowerConstResult = union(enum) {
11431143 ok: Atom.Index,
1144 fail: *Module.ErrorMsg,
1144 fail: *Zcu.ErrorMsg,
11451145};
11461146
11471147fn lowerConst(
......@@ -1151,7 +1151,7 @@ fn lowerConst(
11511151 val: Value,
11521152 required_alignment: InternPool.Alignment,
11531153 sect_id: u16,
1154 src_loc: Module.LazySrcLoc,
1154 src_loc: Zcu.LazySrcLoc,
11551155) !LowerConstResult {
11561156 const gpa = self.base.comp.gpa;
11571157
......@@ -1221,7 +1221,7 @@ pub fn updateNav(
12211221 else => nav_val,
12221222 };
12231223
1224 if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {
1224 if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
12251225 const atom_index = try self.getOrCreateAtomForNav(nav_index);
12261226 Atom.freeRelocations(self, atom_index);
12271227 const atom = self.getAtom(atom_index);
......@@ -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,
......@@ -1354,7 +1354,7 @@ pub fn getOrCreateAtomForNav(self: *Coff, nav_index: InternPool.Nav.Index) !Atom
13541354}
13551355
13561356fn getNavOutputSection(self: *Coff, nav_index: InternPool.Nav.Index) u16 {
1357 const zcu = self.base.comp.module.?;
1357 const zcu = self.base.comp.zcu.?;
13581358 const ip = &zcu.intern_pool;
13591359 const nav = ip.getNav(nav_index);
13601360 const ty = Type.fromInterned(nav.typeOf(ip));
......@@ -1462,15 +1462,15 @@ pub fn freeNav(self: *Coff, nav_index: InternPool.NavIndex) void {
14621462pub fn updateExports(
14631463 self: *Coff,
14641464 pt: Zcu.PerThread,
1465 exported: Module.Exported,
1465 exported: Zcu.Exported,
14661466 export_indices: []const u32,
14671467) link.File.UpdateExportsError!void {
14681468 if (build_options.skip_non_native and builtin.object_format != .coff) {
14691469 @panic("Attempted to compile for object format that was disabled by build configuration");
14701470 }
14711471
1472 const mod = pt.zcu;
1473 const ip = &mod.intern_pool;
1472 const zcu = pt.zcu;
1473 const ip = &zcu.intern_pool;
14741474 const comp = self.base.comp;
14751475 const target = comp.root_mod.resolved_target.result;
14761476
......@@ -1478,7 +1478,7 @@ pub fn updateExports(
14781478 // Even in the case of LLVM, we need to notice certain exported symbols in order to
14791479 // detect the default subsystem.
14801480 for (export_indices) |export_idx| {
1481 const exp = mod.all_exports.items[export_idx];
1481 const exp = zcu.all_exports.items[export_idx];
14821482 const exported_nav_index = switch (exp.exported) {
14831483 .nav => |nav| nav,
14841484 .uav => continue,
......@@ -1490,20 +1490,20 @@ pub fn updateExports(
14901490 .x86 => .Stdcall,
14911491 else => .C,
14921492 };
1493 const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(mod);
1493 const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(zcu);
14941494 if (exported_cc == .C and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) {
1495 mod.stage1_flags.have_c_main = true;
1495 zcu.stage1_flags.have_c_main = true;
14961496 } else if (exported_cc == winapi_cc and target.os.tag == .windows) {
14971497 if (exp.opts.name.eqlSlice("WinMain", ip)) {
1498 mod.stage1_flags.have_winmain = true;
1498 zcu.stage1_flags.have_winmain = true;
14991499 } else if (exp.opts.name.eqlSlice("wWinMain", ip)) {
1500 mod.stage1_flags.have_wwinmain = true;
1500 zcu.stage1_flags.have_wwinmain = true;
15011501 } else if (exp.opts.name.eqlSlice("WinMainCRTStartup", ip)) {
1502 mod.stage1_flags.have_winmain_crt_startup = true;
1502 zcu.stage1_flags.have_winmain_crt_startup = true;
15031503 } else if (exp.opts.name.eqlSlice("wWinMainCRTStartup", ip)) {
1504 mod.stage1_flags.have_wwinmain_crt_startup = true;
1504 zcu.stage1_flags.have_wwinmain_crt_startup = true;
15051505 } else if (exp.opts.name.eqlSlice("DllMainCRTStartup", ip)) {
1506 mod.stage1_flags.have_dllmain_crt_startup = true;
1506 zcu.stage1_flags.have_dllmain_crt_startup = true;
15071507 }
15081508 }
15091509 }
......@@ -1519,15 +1519,15 @@ pub fn updateExports(
15191519 break :blk self.navs.getPtr(nav).?;
15201520 },
15211521 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {
1522 const first_exp = mod.all_exports.items[export_indices[0]];
1522 const first_exp = zcu.all_exports.items[export_indices[0]];
15231523 const res = try self.lowerUav(pt, uav, .none, first_exp.src);
15241524 switch (res) {
15251525 .mcv => {},
15261526 .fail => |em| {
15271527 // TODO maybe it's enough to return an error here and let Module.processExportsInner
15281528 // handle the error?
1529 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1530 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1529 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1530 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
15311531 return;
15321532 },
15331533 }
......@@ -1538,12 +1538,12 @@ pub fn updateExports(
15381538 const atom = self.getAtom(atom_index);
15391539
15401540 for (export_indices) |export_idx| {
1541 const exp = mod.all_exports.items[export_idx];
1542 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)});
1541 const exp = zcu.all_exports.items[export_idx];
1542 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&zcu.intern_pool)});
15431543
1544 if (exp.opts.section.toSlice(&mod.intern_pool)) |section_name| {
1544 if (exp.opts.section.toSlice(&zcu.intern_pool)) |section_name| {
15451545 if (!mem.eql(u8, section_name, ".text")) {
1546 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
1546 try zcu.failed_exports.putNoClobber(gpa, export_idx, try Zcu.ErrorMsg.create(
15471547 gpa,
15481548 exp.src,
15491549 "Unimplemented: ExportOptions.section",
......@@ -1554,7 +1554,7 @@ pub fn updateExports(
15541554 }
15551555
15561556 if (exp.opts.linkage == .link_once) {
1557 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
1557 try zcu.failed_exports.putNoClobber(gpa, export_idx, try Zcu.ErrorMsg.create(
15581558 gpa,
15591559 exp.src,
15601560 "Unimplemented: GlobalLinkage.link_once",
......@@ -1563,7 +1563,7 @@ pub fn updateExports(
15631563 continue;
15641564 }
15651565
1566 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1566 const exp_name = exp.opts.name.toSlice(&zcu.intern_pool);
15671567 const sym_index = metadata.getExport(self, exp_name) orelse blk: {
15681568 const sym_index = if (self.getGlobalIndex(exp_name)) |global_index| ind: {
15691569 const global = self.globals.items[global_index];
......@@ -1609,14 +1609,14 @@ pub fn deleteExport(
16091609 .nav => |nav| self.navs.getPtr(nav),
16101610 .uav => |uav| self.uavs.getPtr(uav),
16111611 } orelse return;
1612 const mod = self.base.comp.module.?;
1613 const name_slice = name.toSlice(&mod.intern_pool);
1612 const zcu = self.base.comp.zcu.?;
1613 const name_slice = name.toSlice(&zcu.intern_pool);
16141614 const sym_index = metadata.getExportPtr(self, name_slice) orelse return;
16151615
16161616 const gpa = self.base.comp.gpa;
16171617 const sym_loc = SymbolWithLoc{ .sym_index = sym_index.*, .file = null };
16181618 const sym = self.getSymbolPtr(sym_loc);
1619 log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)});
1619 log.debug("deleting export '{}'", .{name.fmt(&zcu.intern_pool)});
16201620 assert(sym.storage_class == .EXTERNAL and sym.section_number != .UNDEFINED);
16211621 sym.* = .{
16221622 .name = [_]u8{0} ** 8,
......@@ -1691,7 +1691,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
16911691 defer sub_prog_node.end();
16921692
16931693 const pt: Zcu.PerThread = .{
1694 .zcu = comp.module orelse return error.LinkingWithoutZigSourceUnimplemented,
1694 .zcu = comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
16951695 .tid = tid,
16961696 };
16971697
......@@ -1843,13 +1843,13 @@ pub fn lowerUav(
18431843 pt: Zcu.PerThread,
18441844 uav: InternPool.Index,
18451845 explicit_alignment: InternPool.Alignment,
1846 src_loc: Module.LazySrcLoc,
1846 src_loc: Zcu.LazySrcLoc,
18471847) !codegen.GenResult {
18481848 const zcu = pt.zcu;
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| {
......@@ -1872,7 +1872,7 @@ pub fn lowerUav(
18721872 src_loc,
18731873 ) catch |err| switch (err) {
18741874 error.OutOfMemory => return error.OutOfMemory,
1875 else => |e| return .{ .fail = try Module.ErrorMsg.create(
1875 else => |e| return .{ .fail = try Zcu.ErrorMsg.create(
18761876 gpa,
18771877 src_loc,
18781878 "lowerAnonDecl failed with error: {s}",
......@@ -2730,8 +2730,6 @@ const ImportTable = @import("Coff/ImportTable.zig");
27302730const Liveness = @import("../Liveness.zig");
27312731const LlvmObject = @import("../codegen/llvm.zig").Object;
27322732const Zcu = @import("../Zcu.zig");
2733/// Deprecated.
2734const Module = Zcu;
27352733const InternPool = @import("../InternPool.zig");
27362734const Object = @import("Coff/Object.zig");
27372735const Relocation = @import("Coff/Relocation.zig");
src/link/Coff/lld.zig+3-3
......@@ -32,7 +32,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
3232
3333 // If there is no Zig code to compile, then we should skip flushing the output file because it
3434 // will not be part of the linker line anyway.
35 const module_obj_path: ?[]const u8 = if (comp.module != null) blk: {
35 const module_obj_path: ?[]const u8 = if (comp.zcu != null) blk: {
3636 try self.flushModule(arena, tid, prog_node);
3737
3838 if (fs.path.dirname(full_out_path)) |dirname| {
......@@ -296,7 +296,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
296296 if (self.subsystem) |explicit| break :blk explicit;
297297 switch (target.os.tag) {
298298 .windows => {
299 if (comp.module) |module| {
299 if (comp.zcu) |module| {
300300 if (module.stage1_flags.have_dllmain_crt_startup or is_dyn_lib)
301301 break :blk null;
302302 if (module.stage1_flags.have_c_main or comp.config.is_test or
......@@ -440,7 +440,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
440440 } else {
441441 try argv.append("-NODEFAULTLIB");
442442 if (!is_lib and entry_name == null) {
443 if (comp.module) |module| {
443 if (comp.zcu) |module| {
444444 if (module.stage1_flags.have_winmain_crt_startup) {
445445 try argv.append("-ENTRY:WinMainCRTStartup");
446446 } else {
src/link/Dwarf.zig+43-43
......@@ -780,7 +780,7 @@ const Entry = struct {
780780 else
781781 "?", 0),
782782 });
783 const zcu = dwarf.bin_file.comp.module.?;
783 const zcu = dwarf.bin_file.comp.zcu.?;
784784 const ip = &zcu.intern_pool;
785785 for (dwarf.types.keys(), dwarf.types.values()) |ty, other_entry| {
786786 const ty_unit: Unit.Index = if (Type.fromInterned(ty).typeDeclInst(zcu)) |inst_index|
......@@ -1429,7 +1429,7 @@ pub const WipNav = struct {
14291429 }
14301430 } else {
14311431 try wip_nav.abbrevCode(abbrev_code.block);
1432 const bytes = Type.fromInterned(loaded_enum.tag_ty).abiSize(wip_nav.pt);
1432 const bytes = Type.fromInterned(loaded_enum.tag_ty).abiSize(wip_nav.pt.zcu);
14331433 try uleb128(diw, bytes);
14341434 big_int.writeTwosComplement(try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)), wip_nav.dwarf.endian);
14351435 }
......@@ -1770,7 +1770,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
17701770 const ty_reloc_index = try wip_nav.refForward();
17711771 try wip_nav.exprloc(.{ .addr = .{ .sym = sym_index } });
17721772 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
1773 ty.abiAlignment(pt).toByteUnits().?);
1773 ty.abiAlignment(zcu).toByteUnits().?);
17741774 try diw.writeByte(@intFromBool(false));
17751775 wip_nav.finishForward(ty_reloc_index);
17761776 try wip_nav.abbrevCode(.is_const);
......@@ -1821,7 +1821,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
18211821 const addr: Loc = .{ .addr = .{ .sym = sym_index } };
18221822 try wip_nav.exprloc(if (variable.is_threadlocal) .{ .form_tls_address = &addr } else addr);
18231823 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
1824 ty.abiAlignment(pt).toByteUnits().?);
1824 ty.abiAlignment(zcu).toByteUnits().?);
18251825 try diw.writeByte(@intFromBool(false));
18261826 },
18271827 .func => |func| {
......@@ -2158,8 +2158,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
21582158 try diw.writeByte(accessibility);
21592159 try wip_nav.strp(nav.name.toSlice(ip));
21602160 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
2161 try uleb128(diw, nav_val.toType().abiSize(pt));
2162 try uleb128(diw, nav_val.toType().abiAlignment(pt).toByteUnits().?);
2161 try uleb128(diw, nav_val.toType().abiSize(zcu));
2162 try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?);
21632163 for (0..loaded_struct.field_types.len) |field_index| {
21642164 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
21652165 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
......@@ -2173,7 +2173,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
21732173 if (!is_comptime) {
21742174 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
21752175 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2176 field_type.abiAlignment(pt).toByteUnits().?);
2176 field_type.abiAlignment(zcu).toByteUnits().?);
21772177 }
21782178 }
21792179 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -2195,7 +2195,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
21952195 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
21962196 try wip_nav.refType(field_type);
21972197 try uleb128(diw, field_bit_offset);
2198 field_bit_offset += @intCast(field_type.bitSize(pt));
2198 field_bit_offset += @intCast(field_type.bitSize(zcu));
21992199 }
22002200 try uleb128(diw, @intFromEnum(AbbrevCode.null));
22012201 },
......@@ -2360,7 +2360,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
23602360 try uleb128(diw, loc.column + 1);
23612361 try diw.writeByte(accessibility);
23622362 try wip_nav.strp(nav.name.toSlice(ip));
2363 const union_layout = pt.getUnionLayout(loaded_union);
2363 const union_layout = Type.getUnionLayout(loaded_union, zcu);
23642364 try uleb128(diw, union_layout.abi_size);
23652365 try uleb128(diw, union_layout.abi_align.toByteUnits().?);
23662366 const loaded_tag = loaded_union.loadTagType(ip);
......@@ -2391,7 +2391,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
23912391 try wip_nav.refType(field_type);
23922392 try uleb128(diw, union_layout.payloadOffset());
23932393 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2394 if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(pt).toByteUnits().?);
2394 if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?);
23952395 }
23962396 try uleb128(diw, @intFromEnum(AbbrevCode.null));
23972397 }
......@@ -2406,7 +2406,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
24062406 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
24072407 try wip_nav.refType(field_type);
24082408 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2409 field_type.abiAlignment(pt).toByteUnits().?);
2409 field_type.abiAlignment(zcu).toByteUnits().?);
24102410 }
24112411 try uleb128(diw, @intFromEnum(AbbrevCode.null));
24122412 break :done;
......@@ -2560,8 +2560,8 @@ fn updateType(
25602560 inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)),
25612561 });
25622562 try uleb128(diw, int_type.bits);
2563 try uleb128(diw, ty.abiSize(pt));
2564 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
2563 try uleb128(diw, ty.abiSize(zcu));
2564 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
25652565 },
25662566 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
25672567 .One, .Many, .C => {
......@@ -2569,7 +2569,7 @@ fn updateType(
25692569 try wip_nav.abbrevCode(.ptr_type);
25702570 try wip_nav.strp(name);
25712571 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
2572 ptr_child_type.abiAlignment(pt).toByteUnits().?);
2572 ptr_child_type.abiAlignment(zcu).toByteUnits().?);
25732573 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
25742574 if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset(
25752575 .debug_info,
......@@ -2594,8 +2594,8 @@ fn updateType(
25942594 .Slice => {
25952595 try wip_nav.abbrevCode(.struct_type);
25962596 try wip_nav.strp(name);
2597 try uleb128(diw, ty.abiSize(pt));
2598 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
2597 try uleb128(diw, ty.abiSize(zcu));
2598 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
25992599 try wip_nav.abbrevCode(.generated_field);
26002600 try wip_nav.strp("ptr");
26012601 const ptr_field_type = ty.slicePtrFieldType(zcu);
......@@ -2605,7 +2605,7 @@ fn updateType(
26052605 try wip_nav.strp("len");
26062606 const len_field_type = Type.usize;
26072607 try wip_nav.refType(len_field_type);
2608 try uleb128(diw, len_field_type.abiAlignment(pt).forward(ptr_field_type.abiSize(pt)));
2608 try uleb128(diw, len_field_type.abiAlignment(zcu).forward(ptr_field_type.abiSize(zcu)));
26092609 try uleb128(diw, @intFromEnum(AbbrevCode.null));
26102610 },
26112611 },
......@@ -2623,8 +2623,8 @@ fn updateType(
26232623 const opt_child_type = Type.fromInterned(opt_child_type_index);
26242624 try wip_nav.abbrevCode(.union_type);
26252625 try wip_nav.strp(name);
2626 try uleb128(diw, ty.abiSize(pt));
2627 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
2626 try uleb128(diw, ty.abiSize(zcu));
2627 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
26282628 if (opt_child_type.isNoReturn(zcu)) {
26292629 try wip_nav.abbrevCode(.generated_field);
26302630 try wip_nav.strp("null");
......@@ -2652,8 +2652,8 @@ fn updateType(
26522652 switch (repr) {
26532653 .unpacked => {
26542654 try wip_nav.refType(Type.bool);
2655 try uleb128(diw, if (opt_child_type.hasRuntimeBits(pt))
2656 opt_child_type.abiSize(pt)
2655 try uleb128(diw, if (opt_child_type.hasRuntimeBits(zcu))
2656 opt_child_type.abiSize(zcu)
26572657 else
26582658 0);
26592659 },
......@@ -2700,8 +2700,8 @@ fn updateType(
27002700 const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) {
27012701 .generic_poison_type => .{ 0, 0 },
27022702 else => .{
2703 codegen.errUnionErrorOffset(error_union_payload_type, pt),
2704 codegen.errUnionPayloadOffset(error_union_payload_type, pt),
2703 codegen.errUnionErrorOffset(error_union_payload_type, zcu),
2704 codegen.errUnionPayloadOffset(error_union_payload_type, zcu),
27052705 },
27062706 };
27072707
......@@ -2710,8 +2710,8 @@ fn updateType(
27102710 if (error_union_type.error_set_type != .generic_poison_type and
27112711 error_union_type.payload_type != .generic_poison_type)
27122712 {
2713 try uleb128(diw, ty.abiSize(pt));
2714 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
2713 try uleb128(diw, ty.abiSize(zcu));
2714 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
27152715 } else {
27162716 try uleb128(diw, 0);
27172717 try uleb128(diw, 1);
......@@ -2788,9 +2788,9 @@ fn updateType(
27882788 DW.ATE.unsigned
27892789 else
27902790 unreachable);
2791 try uleb128(diw, ty.bitSize(pt));
2792 try uleb128(diw, ty.abiSize(pt));
2793 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
2791 try uleb128(diw, ty.bitSize(zcu));
2792 try uleb128(diw, ty.abiSize(zcu));
2793 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
27942794 },
27952795 .anyopaque,
27962796 .void,
......@@ -2820,8 +2820,8 @@ fn updateType(
28202820 } else {
28212821 try wip_nav.abbrevCode(.struct_type);
28222822 try wip_nav.strp(name);
2823 try uleb128(diw, ty.abiSize(pt));
2824 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
2823 try uleb128(diw, ty.abiSize(zcu));
2824 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
28252825 var field_byte_offset: u64 = 0;
28262826 for (0..anon_struct_type.types.len) |field_index| {
28272827 const comptime_value = anon_struct_type.values.get(ip)[field_index];
......@@ -2834,11 +2834,11 @@ fn updateType(
28342834 const field_type = Type.fromInterned(anon_struct_type.types.get(ip)[field_index]);
28352835 try wip_nav.refType(field_type);
28362836 if (comptime_value == .none) {
2837 const field_align = field_type.abiAlignment(pt);
2837 const field_align = field_type.abiAlignment(zcu);
28382838 field_byte_offset = field_align.forward(field_byte_offset);
28392839 try uleb128(diw, field_byte_offset);
2840 try uleb128(diw, field_type.abiAlignment(pt).toByteUnits().?);
2841 field_byte_offset += field_type.abiSize(pt);
2840 try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?);
2841 field_byte_offset += field_type.abiSize(zcu);
28422842 }
28432843 }
28442844 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -2976,8 +2976,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
29762976 try uleb128(diw, file_gop.index);
29772977 try wip_nav.strp(loaded_struct.name.toSlice(ip));
29782978 if (loaded_struct.field_types.len > 0) {
2979 try uleb128(diw, ty.abiSize(pt));
2980 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
2979 try uleb128(diw, ty.abiSize(zcu));
2980 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
29812981 for (0..loaded_struct.field_types.len) |field_index| {
29822982 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
29832983 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
......@@ -2991,7 +2991,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
29912991 if (!is_comptime) {
29922992 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
29932993 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2994 field_type.abiAlignment(pt).toByteUnits().?);
2994 field_type.abiAlignment(zcu).toByteUnits().?);
29952995 }
29962996 }
29972997 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -3042,8 +3042,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
30423042 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_struct_type else .struct_type);
30433043 try wip_nav.strp(name);
30443044 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
3045 try uleb128(diw, ty.abiSize(pt));
3046 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);
3045 try uleb128(diw, ty.abiSize(zcu));
3046 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
30473047 for (0..loaded_struct.field_types.len) |field_index| {
30483048 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
30493049 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);
......@@ -3057,7 +3057,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
30573057 if (!is_comptime) {
30583058 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
30593059 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3060 field_type.abiAlignment(pt).toByteUnits().?);
3060 field_type.abiAlignment(zcu).toByteUnits().?);
30613061 }
30623062 }
30633063 try uleb128(diw, @intFromEnum(AbbrevCode.null));
......@@ -3074,7 +3074,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
30743074 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
30753075 try wip_nav.refType(field_type);
30763076 try uleb128(diw, field_bit_offset);
3077 field_bit_offset += @intCast(field_type.bitSize(pt));
3077 field_bit_offset += @intCast(field_type.bitSize(zcu));
30783078 }
30793079 if (loaded_struct.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
30803080 },
......@@ -3099,7 +3099,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
30993099 const loaded_union = ip.loadUnionType(type_index);
31003100 try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type);
31013101 try wip_nav.strp(name);
3102 const union_layout = pt.getUnionLayout(loaded_union);
3102 const union_layout = Type.getUnionLayout(loaded_union, zcu);
31033103 try uleb128(diw, union_layout.abi_size);
31043104 try uleb128(diw, union_layout.abi_align.toByteUnits().?);
31053105 const loaded_tag = loaded_union.loadTagType(ip);
......@@ -3130,7 +3130,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
31303130 try wip_nav.refType(field_type);
31313131 try uleb128(diw, union_layout.payloadOffset());
31323132 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
3133 if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(pt).toByteUnits().?);
3133 if (field_type.isNoReturn(zcu)) 1 else field_type.abiAlignment(zcu).toByteUnits().?);
31343134 }
31353135 try uleb128(diw, @intFromEnum(AbbrevCode.null));
31363136 }
......@@ -3145,7 +3145,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
31453145 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
31463146 try wip_nav.refType(field_type);
31473147 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
3148 field_type.abiAlignment(pt).toByteUnits().?);
3148 field_type.abiAlignment(zcu).toByteUnits().?);
31493149 }
31503150 if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
31513151 },
src/link/Elf.zig+2-2
......@@ -212,7 +212,7 @@ pub fn createEmpty(
212212
213213 const use_lld = build_options.have_llvm and comp.config.use_lld;
214214 const use_llvm = comp.config.use_llvm;
215 const opt_zcu = comp.module;
215 const opt_zcu = comp.zcu;
216216 const output_mode = comp.config.output_mode;
217217 const link_mode = comp.config.link_mode;
218218 const optimize_mode = comp.root_mod.optimize_mode;
......@@ -2084,7 +2084,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
20842084
20852085 // If there is no Zig code to compile, then we should skip flushing the output file because it
20862086 // will not be part of the linker line anyway.
2087 const module_obj_path: ?[]const u8 = if (comp.module != null) blk: {
2087 const module_obj_path: ?[]const u8 = if (comp.zcu != null) blk: {
20882088 try self.flushModule(arena, tid, prog_node);
20892089
20902090 if (fs.path.dirname(full_out_path)) |dirname| {
src/link/Elf/ZigObject.zig+22-22
......@@ -128,7 +128,7 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {
128128pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
129129 // Handle any lazy symbols that were emitted by incremental compilation.
130130 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {
131 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
131 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
132132
133133 // Most lazy symbols can be updated on first use, but
134134 // anyerror needs to wait for everything to be flushed.
......@@ -157,7 +157,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
157157 }
158158
159159 if (build_options.enable_logging) {
160 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
160 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
161161 for (self.navs.keys(), self.navs.values()) |nav_index, meta| {
162162 checkNavAllocated(pt, nav_index, meta);
163163 }
......@@ -167,7 +167,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
167167 }
168168
169169 if (self.dwarf) |*dwarf| {
170 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.module.?, .tid = tid };
170 const pt: Zcu.PerThread = .{ .zcu = elf_file.base.comp.zcu.?, .tid = tid };
171171 try dwarf.flushModule(pt);
172172
173173 const gpa = elf_file.base.comp.gpa;
......@@ -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| {
......@@ -949,7 +949,7 @@ pub fn getOrCreateMetadataForNav(
949949 if (!gop.found_existing) {
950950 const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;
951951 const symbol_index = try self.newSymbolWithAtom(gpa, 0);
952 const zcu = elf_file.base.comp.module.?;
952 const zcu = elf_file.base.comp.zcu.?;
953953 const nav_val = Value.fromInterned(zcu.intern_pool.getNav(nav_index).status.resolved.val);
954954 const sym = self.symbol(symbol_index);
955955 if (nav_val.getVariable(zcu)) |variable| {
......@@ -1306,7 +1306,7 @@ pub fn updateNav(
13061306 else => nav.status.resolved.val,
13071307 };
13081308
1309 if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(pt)) {
1309 if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(zcu)) {
13101310 const sym_index = try self.getOrCreateMetadataForNav(elf_file, nav_index);
13111311 self.symbol(sym_index).atom(elf_file).?.freeRelocs(self);
13121312
......@@ -1382,8 +1382,8 @@ fn updateLazySymbol(
13821382 sym: link.File.LazySymbol,
13831383 symbol_index: Symbol.Index,
13841384) !void {
1385 const mod = pt.zcu;
1386 const gpa = mod.gpa;
1385 const zcu = pt.zcu;
1386 const gpa = zcu.gpa;
13871387
13881388 var required_alignment: InternPool.Alignment = .none;
13891389 var code_buffer = std.ArrayList(u8).init(gpa);
......@@ -1398,7 +1398,7 @@ fn updateLazySymbol(
13981398 break :blk try self.strtab.insert(gpa, name);
13991399 };
14001400
1401 const src = Type.fromInterned(sym.ty).srcLocOrNull(mod) orelse Zcu.LazySrcLoc.unneeded;
1401 const src = Type.fromInterned(sym.ty).srcLocOrNull(zcu) orelse Zcu.LazySrcLoc.unneeded;
14021402 const res = try codegen.generateLazySymbol(
14031403 &elf_file.base,
14041404 pt,
......@@ -1513,7 +1513,7 @@ pub fn updateExports(
15131513 const tracy = trace(@src());
15141514 defer tracy.end();
15151515
1516 const mod = pt.zcu;
1516 const zcu = pt.zcu;
15171517 const gpa = elf_file.base.comp.gpa;
15181518 const metadata = switch (exported) {
15191519 .nav => |nav| blk: {
......@@ -1521,15 +1521,15 @@ pub fn updateExports(
15211521 break :blk self.navs.getPtr(nav).?;
15221522 },
15231523 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {
1524 const first_exp = mod.all_exports.items[export_indices[0]];
1524 const first_exp = zcu.all_exports.items[export_indices[0]];
15251525 const res = try self.lowerUav(elf_file, pt, uav, .none, first_exp.src);
15261526 switch (res) {
15271527 .mcv => {},
15281528 .fail => |em| {
15291529 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner
15301530 // handle the error?
1531 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1532 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1531 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1532 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
15331533 return;
15341534 },
15351535 }
......@@ -1542,11 +1542,11 @@ pub fn updateExports(
15421542 const esym_shndx = self.symtab.items(.shndx)[esym_index];
15431543
15441544 for (export_indices) |export_idx| {
1545 const exp = mod.all_exports.items[export_idx];
1545 const exp = zcu.all_exports.items[export_idx];
15461546 if (exp.opts.section.unwrap()) |section_name| {
1547 if (!section_name.eqlSlice(".text", &mod.intern_pool)) {
1548 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1549 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1547 if (!section_name.eqlSlice(".text", &zcu.intern_pool)) {
1548 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1549 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
15501550 gpa,
15511551 exp.src,
15521552 "Unimplemented: ExportOptions.section",
......@@ -1560,8 +1560,8 @@ pub fn updateExports(
15601560 .strong => elf.STB_GLOBAL,
15611561 .weak => elf.STB_WEAK,
15621562 .link_once => {
1563 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1564 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1563 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1564 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
15651565 gpa,
15661566 exp.src,
15671567 "Unimplemented: GlobalLinkage.LinkOnce",
......@@ -1571,7 +1571,7 @@ pub fn updateExports(
15711571 },
15721572 };
15731573 const stt_bits: u8 = @as(u4, @truncate(esym.st_info));
1574 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1574 const exp_name = exp.opts.name.toSlice(&zcu.intern_pool);
15751575 const name_off = try self.strtab.insert(gpa, exp_name);
15761576 const global_sym_index = if (metadata.@"export"(self, exp_name)) |exp_index|
15771577 exp_index.*
......@@ -1626,8 +1626,8 @@ pub fn deleteExport(
16261626 .nav => |nav| self.navs.getPtr(nav),
16271627 .uav => |uav| self.uavs.getPtr(uav),
16281628 } orelse return;
1629 const mod = elf_file.base.comp.module.?;
1630 const exp_name = name.toSlice(&mod.intern_pool);
1629 const zcu = elf_file.base.comp.zcu.?;
1630 const exp_name = name.toSlice(&zcu.intern_pool);
16311631 const esym_index = metadata.@"export"(self, exp_name) orelse return;
16321632 log.debug("deleting export '{s}'", .{exp_name});
16331633 const esym = &self.symtab.items(.elf_sym)[esym_index.*];
src/link/MachO.zig+3-5
......@@ -164,7 +164,7 @@ pub fn createEmpty(
164164
165165 const gpa = comp.gpa;
166166 const use_llvm = comp.config.use_llvm;
167 const opt_zcu = comp.module;
167 const opt_zcu = comp.zcu;
168168 const optimize_mode = comp.root_mod.optimize_mode;
169169 const output_mode = comp.config.output_mode;
170170 const link_mode = comp.config.link_mode;
......@@ -3026,7 +3026,7 @@ pub fn updateNavLineNumber(self: *MachO, pt: Zcu.PerThread, nav: InternPool.NavI
30263026pub fn updateExports(
30273027 self: *MachO,
30283028 pt: Zcu.PerThread,
3029 exported: Module.Exported,
3029 exported: Zcu.Exported,
30303030 export_indices: []const u32,
30313031) link.File.UpdateExportsError!void {
30323032 if (build_options.skip_non_native and builtin.object_format != .macho) {
......@@ -3060,7 +3060,7 @@ pub fn lowerUav(
30603060 pt: Zcu.PerThread,
30613061 uav: InternPool.Index,
30623062 explicit_alignment: InternPool.Alignment,
3063 src_loc: Module.LazySrcLoc,
3063 src_loc: Zcu.LazySrcLoc,
30643064) !codegen.GenResult {
30653065 return self.getZigObject().?.lowerUav(self, pt, uav, explicit_alignment, src_loc);
30663066}
......@@ -4634,8 +4634,6 @@ const Liveness = @import("../Liveness.zig");
46344634const LlvmObject = @import("../codegen/llvm.zig").Object;
46354635const Md5 = std.crypto.hash.Md5;
46364636const Zcu = @import("../Zcu.zig");
4637/// Deprecated.
4638const Module = Zcu;
46394637const InternPool = @import("../InternPool.zig");
46404638const Rebase = @import("MachO/dyld_info/Rebase.zig");
46414639pub const Relocation = @import("MachO/Relocation.zig");
src/link/MachO/ZigObject.zig+18-18
......@@ -566,7 +566,7 @@ pub fn getInputSection(self: ZigObject, atom: Atom, macho_file: *MachO) macho.se
566566pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) !void {
567567 // Handle any lazy symbols that were emitted by incremental compilation.
568568 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {
569 const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.module.?, .tid = tid };
569 const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.zcu.?, .tid = tid };
570570
571571 // Most lazy symbols can be updated on first use, but
572572 // anyerror needs to wait for everything to be flushed.
......@@ -595,7 +595,7 @@ pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id)
595595 }
596596
597597 if (self.dwarf) |*dwarf| {
598 const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.module.?, .tid = tid };
598 const pt: Zcu.PerThread = .{ .zcu = macho_file.base.comp.zcu.?, .tid = tid };
599599 try dwarf.flushModule(pt);
600600
601601 self.debug_abbrev_dirty = false;
......@@ -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| {
......@@ -887,7 +887,7 @@ pub fn updateNav(
887887 else => nav.status.resolved.val,
888888 };
889889
890 if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(pt)) {
890 if (nav_init != .none and Value.fromInterned(nav_init).typeOf(zcu).hasRuntimeBits(zcu)) {
891891 const sym_index = try self.getOrCreateMetadataForNav(macho_file, nav_index);
892892 self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file);
893893
......@@ -1256,7 +1256,7 @@ pub fn updateExports(
12561256 const tracy = trace(@src());
12571257 defer tracy.end();
12581258
1259 const mod = pt.zcu;
1259 const zcu = pt.zcu;
12601260 const gpa = macho_file.base.comp.gpa;
12611261 const metadata = switch (exported) {
12621262 .nav => |nav| blk: {
......@@ -1264,15 +1264,15 @@ pub fn updateExports(
12641264 break :blk self.navs.getPtr(nav).?;
12651265 },
12661266 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {
1267 const first_exp = mod.all_exports.items[export_indices[0]];
1267 const first_exp = zcu.all_exports.items[export_indices[0]];
12681268 const res = try self.lowerUav(macho_file, pt, uav, .none, first_exp.src);
12691269 switch (res) {
12701270 .mcv => {},
12711271 .fail => |em| {
12721272 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner
12731273 // handle the error?
1274 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1275 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1274 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1275 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
12761276 return;
12771277 },
12781278 }
......@@ -1284,11 +1284,11 @@ pub fn updateExports(
12841284 const nlist = self.symtab.items(.nlist)[nlist_idx];
12851285
12861286 for (export_indices) |export_idx| {
1287 const exp = mod.all_exports.items[export_idx];
1287 const exp = zcu.all_exports.items[export_idx];
12881288 if (exp.opts.section.unwrap()) |section_name| {
1289 if (!section_name.eqlSlice("__text", &mod.intern_pool)) {
1290 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1291 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1289 if (!section_name.eqlSlice("__text", &zcu.intern_pool)) {
1290 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1291 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
12921292 gpa,
12931293 exp.src,
12941294 "Unimplemented: ExportOptions.section",
......@@ -1298,7 +1298,7 @@ pub fn updateExports(
12981298 }
12991299 }
13001300 if (exp.opts.linkage == .link_once) {
1301 try mod.failed_exports.putNoClobber(mod.gpa, export_idx, try Zcu.ErrorMsg.create(
1301 try zcu.failed_exports.putNoClobber(zcu.gpa, export_idx, try Zcu.ErrorMsg.create(
13021302 gpa,
13031303 exp.src,
13041304 "Unimplemented: GlobalLinkage.link_once",
......@@ -1307,7 +1307,7 @@ pub fn updateExports(
13071307 continue;
13081308 }
13091309
1310 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);
1310 const exp_name = exp.opts.name.toSlice(&zcu.intern_pool);
13111311 const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index|
13121312 exp_index.*
13131313 else blk: {
......@@ -1437,15 +1437,15 @@ pub fn deleteExport(
14371437 exported: Zcu.Exported,
14381438 name: InternPool.NullTerminatedString,
14391439) void {
1440 const mod = macho_file.base.comp.module.?;
1440 const zcu = macho_file.base.comp.zcu.?;
14411441
14421442 const metadata = switch (exported) {
14431443 .nav => |nav| self.navs.getPtr(nav),
14441444 .uav => |uav| self.uavs.getPtr(uav),
14451445 } orelse return;
1446 const nlist_index = metadata.@"export"(self, name.toSlice(&mod.intern_pool)) orelse return;
1446 const nlist_index = metadata.@"export"(self, name.toSlice(&zcu.intern_pool)) orelse return;
14471447
1448 log.debug("deleting export '{}'", .{name.fmt(&mod.intern_pool)});
1448 log.debug("deleting export '{}'", .{name.fmt(&zcu.intern_pool)});
14491449
14501450 const nlist = &self.symtab.items(.nlist)[nlist_index.*];
14511451 self.symtab.items(.size)[nlist_index.*] = 0;
......@@ -1545,7 +1545,7 @@ pub fn getOrCreateMetadataForLazySymbol(
15451545fn isThreadlocal(macho_file: *MachO, nav_index: InternPool.Nav.Index) bool {
15461546 if (!macho_file.base.comp.config.any_non_single_threaded)
15471547 return false;
1548 const ip = &macho_file.base.comp.module.?.intern_pool;
1548 const ip = &macho_file.base.comp.zcu.?.intern_pool;
15491549 return switch (ip.indexToKey(ip.getNav(nav_index).status.resolved.val)) {
15501550 .variable => |variable| variable.is_threadlocal,
15511551 .@"extern" => |@"extern"| @"extern".is_threadlocal,
src/link/Plan9.zig+19-19
......@@ -152,7 +152,7 @@ pub const Atom = struct {
152152 return .{ .code_ptr = slice.ptr, .other = .{ .code_len = slice.len } };
153153 }
154154 fn getCode(self: CodePtr, plan9: *const Plan9) []u8 {
155 const zcu = plan9.base.comp.module.?;
155 const zcu = plan9.base.comp.zcu.?;
156156 const ip = &zcu.intern_pool;
157157 return if (self.code_ptr) |p| p[0..self.other.code_len] else blk: {
158158 const nav_index = self.other.nav_index;
......@@ -317,8 +317,8 @@ pub fn createEmpty(
317317
318318fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void {
319319 const gpa = self.base.comp.gpa;
320 const mod = self.base.comp.module.?;
321 const file_scope = mod.navFileScopeIndex(nav_index);
320 const zcu = self.base.comp.zcu.?;
321 const file_scope = zcu.navFileScopeIndex(nav_index);
322322 const fn_map_res = try self.fn_nav_table.getOrPut(gpa, file_scope);
323323 if (fn_map_res.found_existing) {
324324 if (try fn_map_res.value_ptr.functions.fetchPut(gpa, nav_index, out)) |old_entry| {
......@@ -326,7 +326,7 @@ fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void
326326 gpa.free(old_entry.value.lineinfo);
327327 }
328328 } else {
329 const file = mod.fileByIndex(file_scope);
329 const file = zcu.fileByIndex(file_scope);
330330 const arena = self.path_arena.allocator();
331331 // each file gets a symbol
332332 fn_map_res.value_ptr.* = .{
......@@ -391,10 +391,10 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
391391 @panic("Attempted to compile for object format that was disabled by build configuration");
392392 }
393393
394 const mod = pt.zcu;
395 const gpa = mod.gpa;
394 const zcu = pt.zcu;
395 const gpa = zcu.gpa;
396396 const target = self.base.comp.root_mod.resolved_target.result;
397 const func = mod.funcInfo(func_index);
397 const func = zcu.funcInfo(func_index);
398398
399399 const atom_idx = try self.seeNav(pt, func.owner_nav);
400400
......@@ -413,7 +413,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
413413 const res = try codegen.generateFunction(
414414 &self.base,
415415 pt,
416 mod.navSrcLoc(func.owner_nav),
416 zcu.navSrcLoc(func.owner_nav),
417417 func_index,
418418 air,
419419 liveness,
......@@ -423,7 +423,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
423423 const code = switch (res) {
424424 .ok => try code_buffer.toOwnedSlice(),
425425 .fail => |em| {
426 try mod.failed_codegen.put(gpa, func.owner_nav, em);
426 try zcu.failed_codegen.put(gpa, func.owner_nav, em);
427427 return;
428428 },
429429 };
......@@ -457,7 +457,7 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde
457457 else => nav_val,
458458 };
459459
460 if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {
460 if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
461461 const atom_idx = try self.seeNav(pt, nav_index);
462462
463463 var code_buffer = std.ArrayList(u8).init(gpa);
......@@ -607,7 +607,7 @@ pub fn flushModule(self: *Plan9, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
607607 defer assert(self.hdr.entry != 0x0);
608608
609609 const pt: Zcu.PerThread = .{
610 .zcu = self.base.comp.module orelse return error.LinkingWithoutZigSourceUnimplemented,
610 .zcu = self.base.comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
611611 .tid = tid,
612612 };
613613
......@@ -952,11 +952,11 @@ pub fn freeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) void {
952952 const gpa = self.base.comp.gpa;
953953 // TODO audit the lifetimes of decls table entries. It's possible to get
954954 // freeDecl without any updateDecl in between.
955 const mod = self.base.comp.module.?;
956 const decl = mod.declPtr(decl_index);
957 const is_fn = decl.val.isFuncBody(mod);
955 const zcu = self.base.comp.zcu.?;
956 const decl = zcu.declPtr(decl_index);
957 const is_fn = decl.val.isFuncBody(zcu);
958958 if (is_fn) {
959 const symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(mod)).?;
959 const symidx_and_submap = self.fn_decl_table.get(decl.getFileScope(zcu)).?;
960960 var submap = symidx_and_submap.functions;
961961 if (submap.fetchSwapRemove(decl_index)) |removed_entry| {
962962 gpa.free(removed_entry.value.code);
......@@ -1256,8 +1256,8 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {
12561256}
12571257
12581258pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1259 const mod = self.base.comp.module.?;
1260 const ip = &mod.intern_pool;
1259 const zcu = self.base.comp.zcu.?;
1260 const ip = &zcu.intern_pool;
12611261 const writer = buf.writer();
12621262 // write __GOT
12631263 try self.writeSym(writer, self.syms.items[0]);
......@@ -1284,7 +1284,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
12841284 try self.writeSym(writer, sym);
12851285 if (self.nav_exports.get(nav_index)) |export_indices| {
12861286 for (export_indices) |export_idx| {
1287 const exp = mod.all_exports.items[export_idx];
1287 const exp = zcu.all_exports.items[export_idx];
12881288 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {
12891289 try self.writeSym(writer, self.syms.items[exp_i]);
12901290 }
......@@ -1323,7 +1323,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
13231323 try self.writeSym(writer, sym);
13241324 if (self.nav_exports.get(nav_index)) |export_indices| {
13251325 for (export_indices) |export_idx| {
1326 const exp = mod.all_exports.items[export_idx];
1326 const exp = zcu.all_exports.items[export_idx];
13271327 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {
13281328 const s = self.syms.items[exp_i];
13291329 if (mem.eql(u8, s.name, "_start"))
src/link/SpirV.zig+1-1
......@@ -229,7 +229,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
229229 defer error_info.deinit();
230230
231231 try error_info.appendSlice("zig_errors:");
232 const ip = &self.base.comp.module.?.intern_pool;
232 const ip = &self.base.comp.zcu.?.intern_pool;
233233 for (ip.global_error_set.getNamesFromMainThread()) |name| {
234234 // Errors can contain pretty much any character - to encode them in a string we must escape
235235 // them somehow. Easiest here is to use some established scheme, one which also preseves the
src/link/Wasm.zig+2-2
......@@ -556,7 +556,7 @@ pub fn createEmpty(
556556 }
557557 }
558558
559 if (comp.module) |zcu| {
559 if (comp.zcu) |zcu| {
560560 if (!use_llvm) {
561561 const index: File.Index = @enumFromInt(wasm.files.len);
562562 var zig_object: ZigObject = .{
......@@ -3352,7 +3352,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
33523352
33533353 // If there is no Zig code to compile, then we should skip flushing the output file because it
33543354 // will not be part of the linker line anyway.
3355 const module_obj_path: ?[]const u8 = if (comp.module != null) blk: {
3355 const module_obj_path: ?[]const u8 = if (comp.zcu != null) blk: {
33563356 try wasm.flushModule(arena, tid, prog_node);
33573357
33583358 if (fs.path.dirname(full_out_path)) |dirname| {
src/link/Wasm/ZigObject.zig+18-18
......@@ -259,7 +259,7 @@ pub fn updateNav(
259259 else => .{ false, .none, nav_val },
260260 };
261261
262 if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {
262 if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
263263 const gpa = wasm_file.base.comp.gpa;
264264 const atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, nav_index);
265265 const atom = wasm_file.getAtomPtr(atom_index);
......@@ -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.zcu.?;
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");
......@@ -604,14 +604,14 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per
604604
605605 // Addend for each relocation to the table
606606 var addend: u32 = 0;
607 const pt: Zcu.PerThread = .{ .zcu = wasm_file.base.comp.module.?, .tid = tid };
607 const pt: Zcu.PerThread = .{ .zcu = wasm_file.base.comp.zcu.?, .tid = tid };
608608 const slice_ty = Type.slice_const_u8_sentinel_0;
609609 const atom = wasm_file.getAtomPtr(atom_index);
610610 {
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
......@@ -803,9 +803,9 @@ pub fn getUavVAddr(
803803 const parent_atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
804804 const parent_atom = wasm_file.getAtomPtr(parent_atom_index);
805805 const is_wasm32 = target.cpu.arch == .wasm32;
806 const mod = wasm_file.base.comp.module.?;
807 const ty = Type.fromInterned(mod.intern_pool.typeOf(uav));
808 if (ty.zigTypeTag(mod) == .Fn) {
806 const zcu = wasm_file.base.comp.zcu.?;
807 const ty = Type.fromInterned(zcu.intern_pool.typeOf(uav));
808 if (ty.zigTypeTag(zcu) == .Fn) {
809809 std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
810810 try parent_atom.relocs.append(gpa, .{
811811 .index = target_symbol_index,
......@@ -834,13 +834,13 @@ pub fn deleteExport(
834834 exported: Zcu.Exported,
835835 name: InternPool.NullTerminatedString,
836836) void {
837 const mod = wasm_file.base.comp.module.?;
837 const zcu = wasm_file.base.comp.zcu.?;
838838 const nav_index = switch (exported) {
839839 .nav => |nav_index| nav_index,
840840 .uav => @panic("TODO: implement Wasm linker code for exporting a constant value"),
841841 };
842842 const nav_info = zig_object.navs.getPtr(nav_index) orelse return;
843 if (nav_info.@"export"(zig_object, name.toSlice(&mod.intern_pool))) |sym_index| {
843 if (nav_info.@"export"(zig_object, name.toSlice(&zcu.intern_pool))) |sym_index| {
844844 const sym = zig_object.symbol(sym_index);
845845 nav_info.deleteExport(sym_index);
846846 std.debug.assert(zig_object.global_syms.remove(sym.name));
......@@ -930,8 +930,8 @@ pub fn updateExports(
930930
931931pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.Nav.Index) void {
932932 const gpa = wasm_file.base.comp.gpa;
933 const mod = wasm_file.base.comp.module.?;
934 const ip = &mod.intern_pool;
933 const zcu = wasm_file.base.comp.zcu.?;
934 const ip = &zcu.intern_pool;
935935 const nav_info = zig_object.navs.getPtr(nav_index).?;
936936 const atom_index = nav_info.atom;
937937 const atom = wasm_file.getAtomPtr(atom_index);
......@@ -956,7 +956,7 @@ pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.N
956956 segment.name = &.{}; // Ensure no accidental double free
957957 }
958958
959 const nav_val = mod.navValue(nav_index).toIntern();
959 const nav_val = zcu.navValue(nav_index).toIntern();
960960 if (ip.indexToKey(nav_val) == .@"extern") {
961961 std.debug.assert(zig_object.imports.remove(atom.sym_index));
962962 }
......@@ -1016,7 +1016,7 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {
10161016 const gpa = wasm_file.base.comp.gpa;
10171017 const sym_index = zig_object.findGlobalSymbol("__zig_errors_len") orelse return;
10181018
1019 const errors_len = 1 + wasm_file.base.comp.module.?.intern_pool.global_error_set.getNamesFromMainThread().len;
1019 const errors_len = 1 + wasm_file.base.comp.zcu.?.intern_pool.global_error_set.getNamesFromMainThread().len;
10201020 // overwrite existing atom if it already exists (maybe the error set has increased)
10211021 // if not, allocate a new atom.
10221022 const atom_index = if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index })) |index| blk: {
src/mutable_value.zig+5-5
......@@ -223,7 +223,7 @@ pub const MutableValue = union(enum) {
223223 @memset(elems[0..@intCast(len_no_sent)], .{ .interned = undef_elem });
224224 },
225225 .Struct => for (elems[0..@intCast(len_no_sent)], 0..) |*mut_elem, i| {
226 const field_ty = ty.structFieldType(i, zcu).toIntern();
226 const field_ty = ty.fieldType(i, zcu).toIntern();
227227 mut_elem.* = .{ .interned = try pt.intern(.{ .undef = field_ty }) };
228228 },
229229 else => unreachable,
......@@ -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_air.zig+6-6
......@@ -428,10 +428,10 @@ const Writer = struct {
428428 }
429429
430430 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
431 const mod = w.pt.zcu;
431 const zcu = w.pt.zcu;
432432 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
433433 const vector_ty = ty_pl.ty.toType();
434 const len = @as(usize, @intCast(vector_ty.arrayLen(mod)));
434 const len = @as(usize, @intCast(vector_ty.arrayLen(zcu)));
435435 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));
436436
437437 try w.writeType(s, vector_ty);
......@@ -508,11 +508,11 @@ const Writer = struct {
508508 }
509509
510510 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
511 const mod = w.pt.zcu;
511 const zcu = w.pt.zcu;
512512 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
513513 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
514514
515 const elem_ty = w.typeOfIndex(inst).childType(mod);
515 const elem_ty = w.typeOfIndex(inst).childType(zcu);
516516 try w.writeType(s, elem_ty);
517517 try s.writeAll(", ");
518518 try w.writeOperand(s, inst, 0, pl_op.operand);
......@@ -974,7 +974,7 @@ const Writer = struct {
974974 }
975975
976976 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {
977 const mod = w.pt.zcu;
978 return w.air.typeOfIndex(inst, &mod.intern_pool);
977 const zcu = w.pt.zcu;
978 return w.air.typeOfIndex(inst, &zcu.intern_pool);
979979 }
980980};
src/print_value.zig+7-7
......@@ -62,8 +62,8 @@ pub fn print(
6262 comptime have_sema: bool,
6363 sema: if (have_sema) *Sema else void,
6464) (@TypeOf(writer).Error || Zcu.CompileError)!void {
65 const mod = pt.zcu;
66 const ip = &mod.intern_pool;
65 const zcu = pt.zcu;
66 const ip = &zcu.intern_pool;
6767 switch (ip.indexToKey(val.toIntern())) {
6868 .int_type,
6969 .ptr_type,
......@@ -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 },
......@@ -116,7 +116,7 @@ pub fn print(
116116 enum_literal.fmt(ip),
117117 }),
118118 .enum_tag => |enum_tag| {
119 const enum_type = ip.loadEnumType(val.typeOf(mod).toIntern());
119 const enum_type = ip.loadEnumType(val.typeOf(zcu).toIntern());
120120 if (enum_type.tagValueIndex(ip, val.toIntern())) |tag_index| {
121121 return writer.print(".{i}", .{enum_type.names.get(ip)[tag_index].fmt(ip)});
122122 }
......@@ -173,7 +173,7 @@ pub fn print(
173173 return;
174174 }
175175 if (un.tag == .none) {
176 const backing_ty = try val.typeOf(mod).unionBackingType(pt);
176 const backing_ty = try val.typeOf(zcu).unionBackingType(pt);
177177 try writer.print("@bitCast(@as({}, ", .{backing_ty.fmt(pt)});
178178 try print(Value.fromInterned(un.val), writer, level - 1, pt, have_sema, sema);
179179 try writer.writeAll("))");
......@@ -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;
src/target.zig+5-1
......@@ -526,7 +526,11 @@ pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBacken
526526pub inline fn backendSupportsFeature(backend: std.builtin.CompilerBackend, comptime feature: Feature) bool {
527527 return switch (feature) {
528528 .panic_fn => switch (backend) {
529 .stage2_c, .stage2_llvm, .stage2_x86_64, .stage2_riscv64 => true,
529 .stage2_c,
530 .stage2_llvm,
531 .stage2_x86_64,
532 .stage2_riscv64,
533 => true,
530534 else => false,
531535 },
532536 .panic_unwrap_error => switch (backend) {