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,...@@ -50,8 +50,7 @@ gpa: Allocator,
50/// be used for other things requiring the same lifetime as the `Compilation`.50/// be used for other things requiring the same lifetime as the `Compilation`.
51arena: Allocator,51arena: Allocator,
52/// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`.52/// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`.
53/// TODO: rename to zcu: ?*Zcu53zcu: ?*Zcu,
54module: ?*Zcu,
55/// Contains different state depending on whether the Compilation uses54/// Contains different state depending on whether the Compilation uses
56/// incremental or whole cache mode.55/// incremental or whole cache mode.
57cache_use: CacheUse,56cache_use: CacheUse,
...@@ -1474,7 +1473,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1474,7 +1473,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1474 comp.* = .{1473 comp.* = .{
1475 .gpa = gpa,1474 .gpa = gpa,
1476 .arena = arena,1475 .arena = arena,
1477 .module = opt_zcu,1476 .zcu = opt_zcu,
1478 .cache_use = undefined, // populated below1477 .cache_use = undefined, // populated below
1479 .bin_file = null, // populated below1478 .bin_file = null, // populated below
1480 .implib_emit = null, // handled below1479 .implib_emit = null, // handled below
...@@ -1926,7 +1925,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1926,7 +1925,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
19261925
1927pub fn destroy(comp: *Compilation) void {1926pub fn destroy(comp: *Compilation) void {
1928 if (comp.bin_file) |lf| lf.destroy();1927 if (comp.bin_file) |lf| lf.destroy();
1929 if (comp.module) |zcu| zcu.deinit();1928 if (comp.zcu) |zcu| zcu.deinit();
1930 comp.cache_use.deinit();1929 comp.cache_use.deinit();
1931 for (comp.work_queues) |work_queue| work_queue.deinit();1930 for (comp.work_queues) |work_queue| work_queue.deinit();
1932 if (!InternPool.single_threaded) comp.codegen_work.queue.deinit();1931 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 {...@@ -2198,7 +2197,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
2198 };2197 };
2199 }2198 }
22002199
2201 if (comp.module) |zcu| {2200 if (comp.zcu) |zcu| {
2202 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };2201 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
22032202
2204 zcu.compile_log_text.shrinkAndFree(gpa, 0);2203 zcu.compile_log_text.shrinkAndFree(gpa, 0);
...@@ -2268,7 +2267,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {...@@ -2268,7 +2267,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
22682267
2269 try comp.performAllTheWork(main_progress_node);2268 try comp.performAllTheWork(main_progress_node);
22702269
2271 if (comp.module) |zcu| {2270 if (comp.zcu) |zcu| {
2272 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };2271 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
22732272
2274 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {2273 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
...@@ -2447,7 +2446,7 @@ fn flush(...@@ -2447,7 +2446,7 @@ fn flush(
2447 };2446 };
2448 }2447 }
24492448
2450 if (comp.module) |zcu| {2449 if (comp.zcu) |zcu| {
2451 try link.File.C.flushEmitH(zcu);2450 try link.File.C.flushEmitH(zcu);
24522451
2453 if (zcu.llvm_object) |llvm_object| {2452 if (zcu.llvm_object) |llvm_object| {
...@@ -2558,7 +2557,7 @@ fn addNonIncrementalStuffToCacheManifest(...@@ -2558,7 +2557,7 @@ fn addNonIncrementalStuffToCacheManifest(
25582557
2559 comptime assert(link_hash_implementation_version == 14);2558 comptime assert(link_hash_implementation_version == 14);
25602559
2561 if (comp.module) |mod| {2560 if (comp.zcu) |mod| {
2562 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.root_mod, mod.main_mod, .{ .files = man });2561 try addModuleTableToCacheHash(gpa, arena, &man.hash, mod.root_mod, mod.main_mod, .{ .files = man });
25632562
2564 // Synchronize with other matching comments: ZigOnlyHashStuff2563 // Synchronize with other matching comments: ZigOnlyHashStuff
...@@ -2692,7 +2691,7 @@ fn addNonIncrementalStuffToCacheManifest(...@@ -2692,7 +2691,7 @@ fn addNonIncrementalStuffToCacheManifest(
2692}2691}
26932692
2694fn emitOthers(comp: *Compilation) void {2693fn emitOthers(comp: *Compilation) void {
2695 if (comp.config.output_mode != .Obj or comp.module != null or2694 if (comp.config.output_mode != .Obj or comp.zcu != null or
2696 comp.c_object_table.count() == 0)2695 comp.c_object_table.count() == 0)
2697 {2696 {
2698 return;2697 return;
...@@ -2951,7 +2950,7 @@ pub fn saveState(comp: *Compilation) !void {...@@ -2951,7 +2950,7 @@ pub fn saveState(comp: *Compilation) !void {
2951 var pt_headers = std.ArrayList(Header.PerThread).init(gpa);2950 var pt_headers = std.ArrayList(Header.PerThread).init(gpa);
2952 defer pt_headers.deinit();2951 defer pt_headers.deinit();
29532952
2954 if (comp.module) |zcu| {2953 if (comp.zcu) |zcu| {
2955 const ip = &zcu.intern_pool;2954 const ip = &zcu.intern_pool;
2956 const header: Header = .{2955 const header: Header = .{
2957 .intern_pool = .{2956 .intern_pool = .{
...@@ -3092,7 +3091,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3092,7 +3091,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3092 var all_references: ?std.AutoHashMapUnmanaged(InternPool.AnalUnit, ?Zcu.ResolvedReference) = null;3091 var all_references: ?std.AutoHashMapUnmanaged(InternPool.AnalUnit, ?Zcu.ResolvedReference) = null;
3093 defer if (all_references) |*a| a.deinit(gpa);3092 defer if (all_references) |*a| a.deinit(gpa);
30943093
3095 if (comp.module) |zcu| {3094 if (comp.zcu) |zcu| {
3096 const ip = &zcu.intern_pool;3095 const ip = &zcu.intern_pool;
30973096
3098 for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {3097 for (zcu.failed_files.keys(), zcu.failed_files.values()) |file, error_msg| {
...@@ -3246,7 +3245,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3246,7 +3245,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3246 }3245 }
3247 }3246 }
32483247
3249 if (comp.module) |zcu| {3248 if (comp.zcu) |zcu| {
3250 if (bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {3249 if (bundle.root_list.items.len == 0 and zcu.compile_log_sources.count() != 0) {
3251 const values = zcu.compile_log_sources.values();3250 const values = zcu.compile_log_sources.values();
3252 // First one will be the error; subsequent ones will be notes.3251 // First one will be the error; subsequent ones will be notes.
...@@ -3269,7 +3268,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3269,7 +3268,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3269 }3268 }
3270 }3269 }
32713270
3272 if (comp.module) |zcu| {3271 if (comp.zcu) |zcu| {
3273 if (comp.incremental and bundle.root_list.items.len == 0) {3272 if (comp.incremental and bundle.root_list.items.len == 0) {
3274 const should_have_error = for (zcu.transitive_failed_analysis.keys()) |failed_unit| {3273 const should_have_error = for (zcu.transitive_failed_analysis.keys()) |failed_unit| {
3275 if (all_references == null) {3274 if (all_references == null) {
...@@ -3283,7 +3282,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3283,7 +3282,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3283 }3282 }
3284 }3283 }
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 "";
3287 return bundle.toOwnedBundle(compile_log_text);3286 return bundle.toOwnedBundle(compile_log_text);
3288}3287}
32893288
...@@ -3497,7 +3496,7 @@ pub fn performAllTheWork(...@@ -3497,7 +3496,7 @@ pub fn performAllTheWork(
3497 comp: *Compilation,3496 comp: *Compilation,
3498 main_progress_node: std.Progress.Node,3497 main_progress_node: std.Progress.Node,
3499) JobError!void {3498) JobError!void {
3500 defer if (comp.module) |mod| {3499 defer if (comp.zcu) |mod| {
3501 mod.sema_prog_node.end();3500 mod.sema_prog_node.end();
3502 mod.sema_prog_node = std.Progress.Node.none;3501 mod.sema_prog_node = std.Progress.Node.none;
3503 mod.codegen_prog_node.end();3502 mod.codegen_prog_node.end();
...@@ -3543,8 +3542,7 @@ fn performAllTheWorkInner(...@@ -3543,8 +3542,7 @@ fn performAllTheWorkInner(
3543 // in the `astgen_wait_group`.3542 // in the `astgen_wait_group`.
3544 if (comp.job_queued_update_builtin_zig) b: {3543 if (comp.job_queued_update_builtin_zig) b: {
3545 comp.job_queued_update_builtin_zig = false;3544 comp.job_queued_update_builtin_zig = false;
3546 const zcu = comp.module orelse break :b;3545 if (comp.zcu == null) break :b;
3547 _ = zcu;
3548 // TODO put all the modules in a flat array to make them easy to iterate.3546 // TODO put all the modules in a flat array to make them easy to iterate.
3549 var seen: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{};3547 var seen: std.AutoArrayHashMapUnmanaged(*Package.Module, void) = .{};
3550 defer seen.deinit(comp.gpa);3548 defer seen.deinit(comp.gpa);
...@@ -3563,7 +3561,7 @@ fn performAllTheWorkInner(...@@ -3563,7 +3561,7 @@ fn performAllTheWorkInner(
3563 }3561 }
3564 }3562 }
35653563
3566 if (comp.module) |zcu| {3564 if (comp.zcu) |zcu| {
3567 {3565 {
3568 // Worker threads may append to zcu.files and zcu.import_table3566 // Worker threads may append to zcu.files and zcu.import_table
3569 // so we must hold the lock while spawning those tasks, since3567 // so we must hold the lock while spawning those tasks, since
...@@ -3606,7 +3604,7 @@ fn performAllTheWorkInner(...@@ -3606,7 +3604,7 @@ fn performAllTheWorkInner(
3606 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 });3604 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 });
3607 if (comp.job_queued_fuzzer_lib) work_queue_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", .libfuzzer, .Lib, &comp.fuzzer_lib, main_progress_node });3605 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| {
3610 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };3608 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = .main };
3611 if (comp.incremental) {3609 if (comp.incremental) {
3612 const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);3610 const update_zir_refs_node = main_progress_node.start("Update ZIR References", 0);
...@@ -3638,7 +3636,7 @@ fn performAllTheWorkInner(...@@ -3638,7 +3636,7 @@ fn performAllTheWorkInner(
3638 try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job, main_progress_node);3636 try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job, main_progress_node);
3639 continue :work;3637 continue :work;
3640 };3638 };
3641 if (comp.module) |zcu| {3639 if (comp.zcu) |zcu| {
3642 // If there's no work queued, check if there's anything outdated3640 // If there's no work queued, check if there's anything outdated
3643 // which we need to work on, and queue it if so.3641 // which we need to work on, and queue it if so.
3644 if (try zcu.findOutdatedToAnalyze()) |outdated| {3642 if (try zcu.findOutdatedToAnalyze()) |outdated| {
...@@ -3666,7 +3664,7 @@ pub fn queueJobs(comp: *Compilation, jobs: []const Job) !void {...@@ -3666,7 +3664,7 @@ pub fn queueJobs(comp: *Compilation, jobs: []const Job) !void {
3666fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progress.Node) JobError!void {3664fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progress.Node) JobError!void {
3667 switch (job) {3665 switch (job) {
3668 .codegen_nav => |nav_index| {3666 .codegen_nav => |nav_index| {
3669 const zcu = comp.module.?;3667 const zcu = comp.zcu.?;
3670 const nav = zcu.intern_pool.getNav(nav_index);3668 const nav = zcu.intern_pool.getNav(nav_index);
3671 if (nav.analysis_owner.unwrap()) |cau| {3669 if (nav.analysis_owner.unwrap()) |cau| {
3672 const unit = InternPool.AnalUnit.wrap(.{ .cau = cau });3670 const unit = InternPool.AnalUnit.wrap(.{ .cau = cau });
...@@ -3689,14 +3687,14 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre...@@ -3689,14 +3687,14 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
3689 const named_frame = tracy.namedFrame("analyze_func");3687 const named_frame = tracy.namedFrame("analyze_func");
3690 defer named_frame.end();3688 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) };
3693 pt.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {3691 pt.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
3694 error.OutOfMemory => return error.OutOfMemory,3692 error.OutOfMemory => return error.OutOfMemory,
3695 error.AnalysisFail => return,3693 error.AnalysisFail => return,
3696 };3694 };
3697 },3695 },
3698 .analyze_cau => |cau_index| {3696 .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) };
3700 pt.ensureCauAnalyzed(cau_index) catch |err| switch (err) {3698 pt.ensureCauAnalyzed(cau_index) catch |err| switch (err) {
3701 error.OutOfMemory => return error.OutOfMemory,3699 error.OutOfMemory => return error.OutOfMemory,
3702 error.AnalysisFail => return,3700 error.AnalysisFail => return,
...@@ -3725,7 +3723,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre...@@ -3725,7 +3723,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
3725 const named_frame = tracy.namedFrame("resolve_type_fully");3723 const named_frame = tracy.namedFrame("resolve_type_fully");
3726 defer named_frame.end();3724 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) };
3729 Type.fromInterned(ty).resolveFully(pt) catch |err| switch (err) {3727 Type.fromInterned(ty).resolveFully(pt) catch |err| switch (err) {
3730 error.OutOfMemory => return error.OutOfMemory,3728 error.OutOfMemory => return error.OutOfMemory,
3731 error.AnalysisFail => return,3729 error.AnalysisFail => return,
...@@ -3738,7 +3736,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre...@@ -3738,7 +3736,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
3738 if (true) @panic("TODO: update_line_number");3736 if (true) @panic("TODO: update_line_number");
37393737
3740 const gpa = comp.gpa;3738 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) };
3742 const decl = pt.zcu.declPtr(decl_index);3740 const decl = pt.zcu.declPtr(decl_index);
3743 const lf = comp.bin_file.?;3741 const lf = comp.bin_file.?;
3744 lf.updateDeclLineNumber(pt, decl_index) catch |err| {3742 lf.updateDeclLineNumber(pt, decl_index) catch |err| {
...@@ -3760,7 +3758,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre...@@ -3760,7 +3758,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
3760 const named_frame = tracy.namedFrame("analyze_mod");3758 const named_frame = tracy.namedFrame("analyze_mod");
3761 defer named_frame.end();3759 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) };
3764 pt.semaPkg(mod) catch |err| switch (err) {3762 pt.semaPkg(mod) catch |err| switch (err) {
3765 error.OutOfMemory => return error.OutOfMemory,3763 error.OutOfMemory => return error.OutOfMemory,
3766 error.AnalysisFail => return,3764 error.AnalysisFail => return,
...@@ -3924,7 +3922,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre...@@ -3924,7 +3922,7 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
39243922
3925fn queueCodegenJob(comp: *Compilation, tid: usize, codegen_job: CodegenJob) !void {3923fn queueCodegenJob(comp: *Compilation, tid: usize, codegen_job: CodegenJob) !void {
3926 if (InternPool.single_threaded or3924 if (InternPool.single_threaded or
3927 !comp.module.?.backendSupportsFeature(.separate_thread))3925 !comp.zcu.?.backendSupportsFeature(.separate_thread))
3928 return processOneCodegenJob(tid, comp, codegen_job);3926 return processOneCodegenJob(tid, comp, codegen_job);
39293927
3930 {3928 {
...@@ -3963,14 +3961,14 @@ fn processOneCodegenJob(tid: usize, comp: *Compilation, codegen_job: CodegenJob)...@@ -3963,14 +3961,14 @@ fn processOneCodegenJob(tid: usize, comp: *Compilation, codegen_job: CodegenJob)
3963 const named_frame = tracy.namedFrame("codegen_nav");3961 const named_frame = tracy.namedFrame("codegen_nav");
3964 defer named_frame.end();3962 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) };
3967 try pt.linkerUpdateNav(nav_index);3965 try pt.linkerUpdateNav(nav_index);
3968 },3966 },
3969 .func => |func| {3967 .func => |func| {
3970 const named_frame = tracy.namedFrame("codegen_func");3968 const named_frame = tracy.namedFrame("codegen_func");
3971 defer named_frame.end();3969 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) };
3974 // This call takes ownership of `func.air`.3972 // This call takes ownership of `func.air`.
3975 try pt.linkerUpdateFunc(func.func, func.air);3973 try pt.linkerUpdateFunc(func.func, func.air);
3976 },3974 },
...@@ -3978,7 +3976,7 @@ fn processOneCodegenJob(tid: usize, comp: *Compilation, codegen_job: CodegenJob)...@@ -3978,7 +3976,7 @@ fn processOneCodegenJob(tid: usize, comp: *Compilation, codegen_job: CodegenJob)
3978 const named_frame = tracy.namedFrame("codegen_type");3976 const named_frame = tracy.namedFrame("codegen_type");
3979 defer named_frame.end();3977 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) };
3982 try pt.linkerUpdateContainerType(ty);3980 try pt.linkerUpdateContainerType(ty);
3983 },3981 },
3984 }3982 }
...@@ -3995,7 +3993,7 @@ fn workerDocsCopy(comp: *Compilation) void {...@@ -3995,7 +3993,7 @@ fn workerDocsCopy(comp: *Compilation) void {
3995}3993}
39963994
3997fn docsCopyFallible(comp: *Compilation) anyerror!void {3995fn docsCopyFallible(comp: *Compilation) anyerror!void {
3998 const zcu = comp.module orelse3996 const zcu = comp.zcu orelse
3999 return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{});3997 return comp.lockAndSetMiscFailure(.docs_copy, "no Zig code to document", .{});
40003998
4001 const emit = comp.docs_emit.?;3999 const emit = comp.docs_emit.?;
...@@ -4260,7 +4258,7 @@ fn workerAstGenFile(...@@ -4260,7 +4258,7 @@ fn workerAstGenFile(
4260 const child_prog_node = prog_node.start(file.sub_file_path, 0);4258 const child_prog_node = prog_node.start(file.sub_file_path, 0);
4261 defer child_prog_node.end();4259 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) };
4264 pt.astGenFile(file, path_digest) catch |err| switch (err) {4262 pt.astGenFile(file, path_digest) catch |err| switch (err) {
4265 error.AnalysisFail => return,4263 error.AnalysisFail => return,
4266 else => {4264 else => {
...@@ -4352,8 +4350,8 @@ fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Zcu.EmbedFile) void {...@@ -4352,8 +4350,8 @@ fn workerCheckEmbedFile(comp: *Compilation, embed_file: *Zcu.EmbedFile) void {
4352}4350}
43534351
4354fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Zcu.EmbedFile) !void {4352fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Zcu.EmbedFile) !void {
4355 const mod = comp.module.?;4353 const zcu = comp.zcu.?;
4356 const ip = &mod.intern_pool;4354 const ip = &zcu.intern_pool;
4357 var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{});4355 var file = try embed_file.owner.root.openFile(embed_file.sub_file_path.toSlice(ip), .{});
4358 defer file.close();4356 defer file.close();
43594357
...@@ -4665,10 +4663,10 @@ fn reportRetryableEmbedFileError(...@@ -4665,10 +4663,10 @@ fn reportRetryableEmbedFileError(
4665 embed_file: *Zcu.EmbedFile,4663 embed_file: *Zcu.EmbedFile,
4666 err: anyerror,4664 err: anyerror,
4667) error{OutOfMemory}!void {4665) error{OutOfMemory}!void {
4668 const mod = comp.module.?;4666 const zcu = comp.zcu.?;
4669 const gpa = mod.gpa;4667 const gpa = zcu.gpa;
4670 const src_loc = embed_file.src_loc;4668 const src_loc = embed_file.src_loc;
4671 const ip = &mod.intern_pool;4669 const ip = &zcu.intern_pool;
4672 const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}/{s}': {s}", .{4670 const err_msg = try Zcu.ErrorMsg.create(gpa, src_loc, "unable to load '{}/{s}': {s}", .{
4673 embed_file.owner.root,4671 embed_file.owner.root,
4674 embed_file.sub_file_path.toSlice(ip),4672 embed_file.sub_file_path.toSlice(ip),
...@@ -4680,7 +4678,7 @@ fn reportRetryableEmbedFileError(...@@ -4680,7 +4678,7 @@ fn reportRetryableEmbedFileError(
4680 {4678 {
4681 comp.mutex.lock();4679 comp.mutex.lock();
4682 defer comp.mutex.unlock();4680 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);
4684 }4682 }
4685}4683}
46864684
...@@ -4730,7 +4728,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr...@@ -4730,7 +4728,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
4730 // Special case when doing build-obj for just one C file. When there are more than one object4728 // Special case when doing build-obj for just one C file. When there are more than one object
4731 // file and building an object we need to link them together, but with just one it should go4729 // file and building an object we need to link them together, but with just one it should go
4732 // directly to the output file.4730 // directly to the output file.
4733 const direct_o = comp.c_source_files.len == 1 and comp.module == null and4731 const direct_o = comp.c_source_files.len == 1 and comp.zcu == null and
4734 comp.config.output_mode == .Obj and comp.objects.len == 0;4732 comp.config.output_mode == .Obj and comp.objects.len == 0;
4735 const o_basename_noext = if (direct_o)4733 const o_basename_noext = if (direct_o)
4736 comp.root_name4734 comp.root_name
src/InternPool.zig+2-2
...@@ -3483,7 +3483,7 @@ pub const LoadedStructType = struct {...@@ -3483,7 +3483,7 @@ pub const LoadedStructType = struct {
3483 return s.field_aligns.get(ip)[i];3483 return s.field_aligns.get(ip)[i];
3484 }3484 }
34853485
3486 pub fn fieldInit(s: LoadedStructType, ip: *InternPool, i: usize) Index {3486 pub fn fieldInit(s: LoadedStructType, ip: *const InternPool, i: usize) Index {
3487 if (s.field_inits.len == 0) return .none;3487 if (s.field_inits.len == 0) return .none;
3488 assert(s.haveFieldInits(ip));3488 assert(s.haveFieldInits(ip));
3489 return s.field_inits.get(ip)[i];3489 return s.field_inits.get(ip)[i];
...@@ -11066,7 +11066,7 @@ pub fn destroyNamespace(...@@ -11066,7 +11066,7 @@ pub fn destroyNamespace(
11066 local.mutate.namespaces.free_list = @intFromEnum(namespace_index);11066 local.mutate.namespaces.free_list = @intFromEnum(namespace_index);
11067}11067}
1106811068
11069pub fn filePtr(ip: *InternPool, file_index: FileIndex) *Zcu.File {11069pub fn filePtr(ip: *const InternPool, file_index: FileIndex) *Zcu.File {
11070 const file_index_unwrapped = file_index.unwrap(ip);11070 const file_index_unwrapped = file_index.unwrap(ip);
11071 const files = ip.getLocalShared(file_index_unwrapped.tid).files.acquire();11071 const files = ip.getLocalShared(file_index_unwrapped.tid).files.acquire();
11072 return files.view().items(.file)[file_index_unwrapped.index];11072 return files.view().items(.file)[file_index_unwrapped.index];
src/RangeSet.zig+15-15
...@@ -9,7 +9,7 @@ const Zcu = @import("Zcu.zig");...@@ -9,7 +9,7 @@ const Zcu = @import("Zcu.zig");
9const RangeSet = @This();9const RangeSet = @This();
10const LazySrcLoc = Zcu.LazySrcLoc;10const LazySrcLoc = Zcu.LazySrcLoc;
1111
12pt: Zcu.PerThread,12zcu: *Zcu,
13ranges: std.ArrayList(Range),13ranges: std.ArrayList(Range),
1414
15pub const Range = struct {15pub const Range = struct {
...@@ -18,9 +18,9 @@ pub const Range = struct {...@@ -18,9 +18,9 @@ pub const Range = struct {
18 src: LazySrcLoc,18 src: LazySrcLoc,
19};19};
2020
21pub fn init(allocator: std.mem.Allocator, pt: Zcu.PerThread) RangeSet {21pub fn init(allocator: std.mem.Allocator, zcu: *Zcu) RangeSet {
22 return .{22 return .{
23 .pt = pt,23 .zcu = zcu,
24 .ranges = std.ArrayList(Range).init(allocator),24 .ranges = std.ArrayList(Range).init(allocator),
25 };25 };
26}26}
...@@ -35,8 +35,8 @@ pub fn add(...@@ -35,8 +35,8 @@ pub fn add(
35 last: InternPool.Index,35 last: InternPool.Index,
36 src: LazySrcLoc,36 src: LazySrcLoc,
37) !?LazySrcLoc {37) !?LazySrcLoc {
38 const pt = self.pt;38 const zcu = self.zcu;
39 const ip = &pt.zcu.intern_pool;39 const ip = &zcu.intern_pool;
4040
41 const ty = ip.typeOf(first);41 const ty = ip.typeOf(first);
42 assert(ty == ip.typeOf(last));42 assert(ty == ip.typeOf(last));
...@@ -45,8 +45,8 @@ pub fn add(...@@ -45,8 +45,8 @@ pub fn add(
45 assert(ty == ip.typeOf(range.first));45 assert(ty == ip.typeOf(range.first));
46 assert(ty == ip.typeOf(range.last));46 assert(ty == ip.typeOf(range.last));
4747
48 if (Value.fromInterned(last).compareScalar(.gte, Value.fromInterned(range.first), Type.fromInterned(ty), pt) and48 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), pt))49 Value.fromInterned(first).compareScalar(.lte, Value.fromInterned(range.last), Type.fromInterned(ty), zcu))
50 {50 {
51 return range.src; // They overlap.51 return range.src; // They overlap.
52 }52 }
...@@ -61,20 +61,20 @@ pub fn add(...@@ -61,20 +61,20 @@ pub fn add(
61}61}
6262
63/// Assumes a and b do not overlap63/// Assumes a and b do not overlap
64fn lessThan(pt: Zcu.PerThread, a: Range, b: Range) bool {64fn lessThan(zcu: *Zcu, a: Range, b: Range) bool {
65 const ty = Type.fromInterned(pt.zcu.intern_pool.typeOf(a.first));65 const ty = Type.fromInterned(zcu.intern_pool.typeOf(a.first));
66 return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, pt);66 return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, zcu);
67}67}
6868
69pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !bool {69pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !bool {
70 const pt = self.pt;70 const zcu = self.zcu;
71 const ip = &pt.zcu.intern_pool;71 const ip = &zcu.intern_pool;
72 assert(ip.typeOf(first) == ip.typeOf(last));72 assert(ip.typeOf(first) == ip.typeOf(last));
7373
74 if (self.ranges.items.len == 0)74 if (self.ranges.items.len == 0)
75 return false;75 return false;
7676
77 std.mem.sort(Range, self.ranges.items, pt, lessThan);77 std.mem.sort(Range, self.ranges.items, zcu, lessThan);
7878
79 if (self.ranges.items[0].first != first or79 if (self.ranges.items[0].first != first or
80 self.ranges.items[self.ranges.items.len - 1].last != last)80 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) !...@@ -93,10 +93,10 @@ pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !
93 const prev = self.ranges.items[i];93 const prev = self.ranges.items[i];
9494
95 // prev.last + 1 == cur.first95 // 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));
97 try counter.addScalar(&counter, 1);97 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);
100 if (!cur_start_int.eql(counter.toConst())) {100 if (!cur_start_int.eql(counter.toConst())) {
101 return false;101 return false;
102 }102 }
src/Sema.zig+2181-2266
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6//! This is the the heart of the Zig compiler.6//! This is the the heart of the Zig compiler.
77
8pt: Zcu.PerThread,8pt: Zcu.PerThread,
9/// Alias to `mod.gpa`.9/// Alias to `zcu.gpa`.
10gpa: Allocator,10gpa: Allocator,
11/// Points to the temporary arena allocator of the Sema.11/// Points to the temporary arena allocator of the Sema.
12/// This arena will be cleared when the sema is destroyed.12/// This arena will be cleared when the sema is destroyed.
...@@ -67,7 +67,7 @@ generic_call_src: LazySrcLoc = LazySrcLoc.unneeded,...@@ -67,7 +67,7 @@ generic_call_src: LazySrcLoc = LazySrcLoc.unneeded,
67/// breaking from a block.67/// breaking from a block.
68post_hoc_blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, *LabeledBlock) = .{},68post_hoc_blocks: std.AutoHashMapUnmanaged(Air.Inst.Index, *LabeledBlock) = .{},
69/// Populated with the last compile error created.69/// Populated with the last compile error created.
70err: ?*Module.ErrorMsg = null,70err: ?*Zcu.ErrorMsg = null,
71/// Set to true when analyzing a func type instruction so that nested generic71/// Set to true when analyzing a func type instruction so that nested generic
72/// function types will emit generic poison instead of a partial type.72/// function types will emit generic poison instead of a partial type.
73no_partial_func_ty: bool = false,73no_partial_func_ty: bool = false,
...@@ -172,11 +172,10 @@ const Type = @import("Type.zig");...@@ -172,11 +172,10 @@ const Type = @import("Type.zig");
172const Air = @import("Air.zig");172const Air = @import("Air.zig");
173const Zir = std.zig.Zir;173const Zir = std.zig.Zir;
174const Zcu = @import("Zcu.zig");174const Zcu = @import("Zcu.zig");
175const Module = Zcu;
176const trace = @import("tracy.zig").trace;175const trace = @import("tracy.zig").trace;
177const Namespace = Module.Namespace;176const Namespace = Zcu.Namespace;
178const CompileError = Module.CompileError;177const CompileError = Zcu.CompileError;
179const SemaError = Module.SemaError;178const SemaError = Zcu.SemaError;
180const LazySrcLoc = Zcu.LazySrcLoc;179const LazySrcLoc = Zcu.LazySrcLoc;
181const RangeSet = @import("RangeSet.zig");180const RangeSet = @import("RangeSet.zig");
182const target_util = @import("target.zig");181const target_util = @import("target.zig");
...@@ -431,7 +430,7 @@ pub const Block = struct {...@@ -431,7 +430,7 @@ pub const Block = struct {
431 return_ty: Type,430 return_ty: Type,
432 },431 },
433432
434 fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Module.ErrorMsg) !void {433 fn explain(cr: ComptimeReason, sema: *Sema, msg: ?*Zcu.ErrorMsg) !void {
435 const parent = msg orelse return;434 const parent = msg orelse return;
436 const pt = sema.pt;435 const pt = sema.pt;
437 const prefix = "expression is evaluated at comptime because ";436 const prefix = "expression is evaluated at comptime because ";
...@@ -733,12 +732,12 @@ pub const Block = struct {...@@ -733,12 +732,12 @@ pub const Block = struct {
733 fn addCmpVector(block: *Block, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref, cmp_op: std.math.CompareOperator) !Air.Inst.Ref {732 fn addCmpVector(block: *Block, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref, cmp_op: std.math.CompareOperator) !Air.Inst.Ref {
734 const sema = block.sema;733 const sema = block.sema;
735 const pt = sema.pt;734 const pt = sema.pt;
736 const mod = pt.zcu;735 const zcu = pt.zcu;
737 return block.addInst(.{736 return block.addInst(.{
738 .tag = if (block.float_mode == .optimized) .cmp_vector_optimized else .cmp_vector,737 .tag = if (block.float_mode == .optimized) .cmp_vector_optimized else .cmp_vector,
739 .data = .{ .ty_pl = .{738 .data = .{ .ty_pl = .{
740 .ty = Air.internedToRef((try pt.vectorType(.{739 .ty = Air.internedToRef((try pt.vectorType(.{
741 .len = sema.typeOf(lhs).vectorLen(mod),740 .len = sema.typeOf(lhs).vectorLen(zcu),
742 .child = .bool_type,741 .child = .bool_type,
743 })).toIntern()),742 })).toIntern()),
744 .payload = try sema.addExtra(Air.VectorCmp{743 .payload = try sema.addExtra(Air.VectorCmp{
...@@ -852,7 +851,7 @@ const LabeledBlock = struct {...@@ -852,7 +851,7 @@ const LabeledBlock = struct {
852/// The value stored in the inferred allocation. This will go into851/// The value stored in the inferred allocation. This will go into
853/// peer type resolution. This is stored in a separate list so that852/// peer type resolution. This is stored in a separate list so that
854/// the items are contiguous in memory and thus can be passed to853/// the items are contiguous in memory and thus can be passed to
855/// `Module.resolvePeerTypes`.854/// `Zcu.resolvePeerTypes`.
856const InferredAlloc = struct {855const InferredAlloc = struct {
857 /// The placeholder `store` instructions used before the result pointer type856 /// The placeholder `store` instructions used before the result pointer type
858 /// is known. These should be rewritten to perform any required coercions857 /// is known. These should be rewritten to perform any required coercions
...@@ -1950,7 +1949,7 @@ fn resolveDestType(...@@ -1950,7 +1949,7 @@ fn resolveDestType(
1950 builtin_name: []const u8,1949 builtin_name: []const u8,
1951) !Type {1950) !Type {
1952 const pt = sema.pt;1951 const pt = sema.pt;
1953 const mod = pt.zcu;1952 const zcu = pt.zcu;
1954 const remove_eu = switch (strat) {1953 const remove_eu = switch (strat) {
1955 .remove_eu_opt, .remove_eu => true,1954 .remove_eu_opt, .remove_eu => true,
1956 .remove_opt => false,1955 .remove_opt => false,
...@@ -1980,15 +1979,15 @@ fn resolveDestType(...@@ -1980,15 +1979,15 @@ fn resolveDestType(
1980 else => |e| return e,1979 else => |e| return e,
1981 };1980 };
19821981
1983 if (remove_eu and raw_ty.zigTypeTag(mod) == .ErrorUnion) {1982 if (remove_eu and raw_ty.zigTypeTag(zcu) == .ErrorUnion) {
1984 const eu_child = raw_ty.errorUnionPayload(mod);1983 const eu_child = raw_ty.errorUnionPayload(zcu);
1985 if (remove_opt and eu_child.zigTypeTag(mod) == .Optional) {1984 if (remove_opt and eu_child.zigTypeTag(zcu) == .Optional) {
1986 return eu_child.childType(mod);1985 return eu_child.childType(zcu);
1987 }1986 }
1988 return eu_child;1987 return eu_child;
1989 }1988 }
1990 if (remove_opt and raw_ty.zigTypeTag(mod) == .Optional) {1989 if (remove_opt and raw_ty.zigTypeTag(zcu) == .Optional) {
1991 return raw_ty.childType(mod);1990 return raw_ty.childType(zcu);
1992 }1991 }
1993 return raw_ty;1992 return raw_ty;
1994}1993}
...@@ -2068,10 +2067,10 @@ fn analyzeAsType(...@@ -2068,10 +2067,10 @@ fn analyzeAsType(
20682067
2069pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void {2068pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void {
2070 const pt = sema.pt;2069 const pt = sema.pt;
2071 const mod = pt.zcu;2070 const zcu = pt.zcu;
2072 const comp = mod.comp;2071 const comp = zcu.comp;
2073 const gpa = sema.gpa;2072 const gpa = sema.gpa;
2074 const ip = &mod.intern_pool;2073 const ip = &zcu.intern_pool;
2075 if (!comp.config.any_error_tracing) return;2074 if (!comp.config.any_error_tracing) return;
20762075
2077 assert(!block.is_comptime);2076 assert(!block.is_comptime);
...@@ -2140,9 +2139,9 @@ fn resolveDefinedValue(...@@ -2140,9 +2139,9 @@ fn resolveDefinedValue(
2140 air_ref: Air.Inst.Ref,2139 air_ref: Air.Inst.Ref,
2141) CompileError!?Value {2140) CompileError!?Value {
2142 const pt = sema.pt;2141 const pt = sema.pt;
2143 const mod = pt.zcu;2142 const zcu = pt.zcu;
2144 const val = try sema.resolveValue(air_ref) orelse return null;2143 const val = try sema.resolveValue(air_ref) orelse return null;
2145 if (val.isUndef(mod)) {2144 if (val.isUndef(zcu)) {
2146 return sema.failWithUseOfUndef(block, src);2145 return sema.failWithUseOfUndef(block, src);
2147 }2146 }
2148 return val;2147 return val;
...@@ -2340,12 +2339,12 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:...@@ -2340,12 +2339,12 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
23402339
2341fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {2340fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {
2342 const pt = sema.pt;2341 const pt = sema.pt;
2343 const mod = pt.zcu;2342 const zcu = pt.zcu;
2344 const msg = msg: {2343 const msg = msg: {
2345 const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{});2344 const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{});
2346 errdefer msg.destroy(sema.gpa);2345 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;
2349 try sema.errNote(.{2348 try sema.errNote(.{
2350 .base_node_inst = struct_type.zir_index.unwrap().?,2349 .base_node_inst = struct_type.zir_index.unwrap().?,
2351 .offset = .{ .container_field_value = @intCast(field_index) },2350 .offset = .{ .container_field_value = @intCast(field_index) },
...@@ -2372,12 +2371,12 @@ fn failWithInvalidFieldAccess(...@@ -2372,12 +2371,12 @@ fn failWithInvalidFieldAccess(
2372 field_name: InternPool.NullTerminatedString,2371 field_name: InternPool.NullTerminatedString,
2373) CompileError {2372) CompileError {
2374 const pt = sema.pt;2373 const pt = sema.pt;
2375 const mod = pt.zcu;2374 const zcu = pt.zcu;
2376 const inner_ty = if (object_ty.isSinglePointer(mod)) object_ty.childType(mod) else object_ty;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: {2377 if (inner_ty.zigTypeTag(zcu) == .Optional) opt: {
2379 const child_ty = inner_ty.optionalChild(mod);2378 const child_ty = inner_ty.optionalChild(zcu);
2380 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;2379 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :opt;
2381 const msg = msg: {2380 const msg = msg: {
2382 const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(pt)});2381 const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(pt)});
2383 errdefer msg.destroy(sema.gpa);2382 errdefer msg.destroy(sema.gpa);
...@@ -2385,9 +2384,9 @@ fn failWithInvalidFieldAccess(...@@ -2385,9 +2384,9 @@ fn failWithInvalidFieldAccess(
2385 break :msg msg;2384 break :msg msg;
2386 };2385 };
2387 return sema.failWithOwnedErrorMsg(block, msg);2386 return sema.failWithOwnedErrorMsg(block, msg);
2388 } else if (inner_ty.zigTypeTag(mod) == .ErrorUnion) err: {2387 } else if (inner_ty.zigTypeTag(zcu) == .ErrorUnion) err: {
2389 const child_ty = inner_ty.errorUnionPayload(mod);2388 const child_ty = inner_ty.errorUnionPayload(zcu);
2390 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;2389 if (!typeSupportsFieldAccess(zcu, child_ty, field_name)) break :err;
2391 const msg = msg: {2390 const msg = msg: {
2392 const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(pt)});2391 const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(pt)});
2393 errdefer msg.destroy(sema.gpa);2392 errdefer msg.destroy(sema.gpa);
...@@ -2399,15 +2398,15 @@ fn failWithInvalidFieldAccess(...@@ -2399,15 +2398,15 @@ fn failWithInvalidFieldAccess(
2399 return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(pt)});2398 return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(pt)});
2400}2399}
24012400
2402fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.NullTerminatedString) bool {2401fn typeSupportsFieldAccess(zcu: *const Zcu, ty: Type, field_name: InternPool.NullTerminatedString) bool {
2403 const ip = &mod.intern_pool;2402 const ip = &zcu.intern_pool;
2404 switch (ty.zigTypeTag(mod)) {2403 switch (ty.zigTypeTag(zcu)) {
2405 .Array => return field_name.eqlSlice("len", ip),2404 .Array => return field_name.eqlSlice("len", ip),
2406 .Pointer => {2405 .Pointer => {
2407 const ptr_info = ty.ptrInfo(mod);2406 const ptr_info = ty.ptrInfo(zcu);
2408 if (ptr_info.flags.size == .Slice) {2407 if (ptr_info.flags.size == .Slice) {
2409 return field_name.eqlSlice("ptr", ip) or field_name.eqlSlice("len", ip);2408 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) {
2411 return field_name.eqlSlice("len", ip);2410 return field_name.eqlSlice("len", ip);
2412 } else return false;2411 } else return false;
2413 },2412 },
...@@ -2423,9 +2422,9 @@ fn failWithComptimeErrorRetTrace(...@@ -2423,9 +2422,9 @@ fn failWithComptimeErrorRetTrace(
2423 name: InternPool.NullTerminatedString,2422 name: InternPool.NullTerminatedString,
2424) CompileError {2423) CompileError {
2425 const pt = sema.pt;2424 const pt = sema.pt;
2426 const mod = pt.zcu;2425 const zcu = pt.zcu;
2427 const msg = msg: {2426 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)});
2429 errdefer msg.destroy(sema.gpa);2428 errdefer msg.destroy(sema.gpa);
24302429
2431 for (sema.comptime_err_ret_trace.items) |src_loc| {2430 for (sema.comptime_err_ret_trace.items) |src_loc| {
...@@ -2451,7 +2450,7 @@ fn failWithInvalidPtrArithmetic(sema: *Sema, block: *Block, src: LazySrcLoc, ari...@@ -2451,7 +2450,7 @@ fn failWithInvalidPtrArithmetic(sema: *Sema, block: *Block, src: LazySrcLoc, ari
2451pub fn errNote(2450pub fn errNote(
2452 sema: *Sema,2451 sema: *Sema,
2453 src: LazySrcLoc,2452 src: LazySrcLoc,
2454 parent: *Module.ErrorMsg,2453 parent: *Zcu.ErrorMsg,
2455 comptime format: []const u8,2454 comptime format: []const u8,
2456 args: anytype,2455 args: anytype,
2457) error{OutOfMemory}!void {2456) error{OutOfMemory}!void {
...@@ -2462,7 +2461,7 @@ fn addFieldErrNote(...@@ -2462,7 +2461,7 @@ fn addFieldErrNote(
2462 sema: *Sema,2461 sema: *Sema,
2463 container_ty: Type,2462 container_ty: Type,
2464 field_index: usize,2463 field_index: usize,
2465 parent: *Module.ErrorMsg,2464 parent: *Zcu.ErrorMsg,
2466 comptime format: []const u8,2465 comptime format: []const u8,
2467 args: anytype,2466 args: anytype,
2468) !void {2467) !void {
...@@ -2480,9 +2479,9 @@ pub fn errMsg(...@@ -2480,9 +2479,9 @@ pub fn errMsg(
2480 src: LazySrcLoc,2479 src: LazySrcLoc,
2481 comptime format: []const u8,2480 comptime format: []const u8,
2482 args: anytype,2481 args: anytype,
2483) Allocator.Error!*Module.ErrorMsg {2482) Allocator.Error!*Zcu.ErrorMsg {
2484 assert(src.offset != .unneeded);2483 assert(src.offset != .unneeded);
2485 return Module.ErrorMsg.create(sema.gpa, src, format, args);2484 return Zcu.ErrorMsg.create(sema.gpa, src, format, args);
2486}2485}
24872486
2488pub fn fail(2487pub fn fail(
...@@ -2501,16 +2500,16 @@ pub fn fail(...@@ -2501,16 +2500,16 @@ pub fn fail(
2501 return sema.failWithOwnedErrorMsg(block, err_msg);2500 return sema.failWithOwnedErrorMsg(block, err_msg);
2502}2501}
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 } {
2505 @setCold(true);2504 @setCold(true);
2506 const gpa = sema.gpa;2505 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) {
2510 var all_references: ?std.AutoHashMapUnmanaged(AnalUnit, ?Zcu.ResolvedReference) = null;2509 var all_references: ?std.AutoHashMapUnmanaged(AnalUnit, ?Zcu.ResolvedReference) = null;
2511 var wip_errors: std.zig.ErrorBundle.Wip = undefined;2510 var wip_errors: std.zig.ErrorBundle.Wip = undefined;
2512 wip_errors.init(gpa) catch @panic("out of memory");2511 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");
2514 std.debug.print("compile error during Sema:\n", .{});2513 std.debug.print("compile error during Sema:\n", .{});
2515 var error_bundle = wip_errors.toOwnedBundle("") catch @panic("out of memory");2514 var error_bundle = wip_errors.toOwnedBundle("") catch @panic("out of memory");
2516 error_bundle.renderToStdErr(.{ .ttyconf = .no_color });2515 error_bundle.renderToStdErr(.{ .ttyconf = .no_color });
...@@ -2530,12 +2529,12 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2530,12 +2529,12 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2530 }2529 }
2531 }2530 }
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;
2534 if (use_ref_trace) {2533 if (use_ref_trace) {
2535 err_msg.reference_trace_root = sema.owner.toOptional();2534 err_msg.reference_trace_root = sema.owner.toOptional();
2536 }2535 }
25372536
2538 const gop = try mod.failed_analysis.getOrPut(gpa, sema.owner);2537 const gop = try zcu.failed_analysis.getOrPut(gpa, sema.owner);
2539 if (gop.found_existing) {2538 if (gop.found_existing) {
2540 // If there are multiple errors for the same Decl, prefer the first one added.2539 // If there are multiple errors for the same Decl, prefer the first one added.
2541 sema.err = null;2540 sema.err = null;
...@@ -2554,7 +2553,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2554,7 +2553,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2554fn reparentOwnedErrorMsg(2553fn reparentOwnedErrorMsg(
2555 sema: *Sema,2554 sema: *Sema,
2556 src: LazySrcLoc,2555 src: LazySrcLoc,
2557 msg: *Module.ErrorMsg,2556 msg: *Zcu.ErrorMsg,
2558 comptime format: []const u8,2557 comptime format: []const u8,
2559 args: anytype,2558 args: anytype,
2560) !void {2559) !void {
...@@ -2562,7 +2561,7 @@ fn reparentOwnedErrorMsg(...@@ -2562,7 +2561,7 @@ fn reparentOwnedErrorMsg(
25622561
2563 const orig_notes = msg.notes.len;2562 const orig_notes = msg.notes.len;
2564 msg.notes = try sema.gpa.realloc(msg.notes, orig_notes + 1);2563 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]);
2566 msg.notes[0] = .{2565 msg.notes[0] = .{
2567 .src_loc = msg.src_loc,2566 .src_loc = msg.src_loc,
2568 .msg = msg.msg,2567 .msg = msg.msg,
...@@ -2644,7 +2643,7 @@ fn analyzeAsInt(...@@ -2644,7 +2643,7 @@ fn analyzeAsInt(
2644) !u64 {2643) !u64 {
2645 const coerced = try sema.coerce(block, dest_ty, air_ref, src);2644 const coerced = try sema.coerce(block, dest_ty, air_ref, src);
2646 const val = try sema.resolveConstDefinedValue(block, src, coerced, reason);2645 const val = try sema.resolveConstDefinedValue(block, src, coerced, reason);
2647 return (try val.getUnsignedIntAdvanced(sema.pt, .sema)).?;2646 return try val.toUnsignedIntSema(sema.pt);
2648}2647}
26492648
2650/// Given a ZIR extra index which points to a list of `Zir.Inst.Capture`,2649/// Given a ZIR extra index which points to a list of `Zir.Inst.Capture`,
...@@ -2722,9 +2721,9 @@ fn zirStructDecl(...@@ -2722,9 +2721,9 @@ fn zirStructDecl(
2722 inst: Zir.Inst.Index,2721 inst: Zir.Inst.Index,
2723) CompileError!Air.Inst.Ref {2722) CompileError!Air.Inst.Ref {
2724 const pt = sema.pt;2723 const pt = sema.pt;
2725 const mod = pt.zcu;2724 const zcu = pt.zcu;
2726 const gpa = sema.gpa;2725 const gpa = sema.gpa;
2727 const ip = &mod.intern_pool;2726 const ip = &zcu.intern_pool;
2728 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);2727 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
2729 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);2728 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);
27302729
...@@ -2786,7 +2785,7 @@ fn zirStructDecl(...@@ -2786,7 +2785,7 @@ fn zirStructDecl(
27862785
2787 // Make sure we update the namespace if the declaration is re-analyzed, to pick2786 // Make sure we update the namespace if the declaration is re-analyzed, to pick
2788 // up on e.g. changed comptime decls.2787 // 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
2791 try sema.declareDependency(.{ .interned = new_ty });2790 try sema.declareDependency(.{ .interned = new_ty });
2792 try sema.addTypeReferenceEntry(src, new_ty);2791 try sema.addTypeReferenceEntry(src, new_ty);
...@@ -2807,8 +2806,8 @@ fn zirStructDecl(...@@ -2807,8 +2806,8 @@ fn zirStructDecl(
2807 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{2806 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
2808 .parent = block.namespace.toOptional(),2807 .parent = block.namespace.toOptional(),
2809 .owner_type = wip_ty.index,2808 .owner_type = wip_ty.index,
2810 .file_scope = block.getFileScopeIndex(mod),2809 .file_scope = block.getFileScopeIndex(zcu),
2811 .generation = mod.generation,2810 .generation = zcu.generation,
2812 });2811 });
2813 errdefer pt.destroyNamespace(new_namespace_index);2812 errdefer pt.destroyNamespace(new_namespace_index);
28142813
...@@ -2825,11 +2824,11 @@ fn zirStructDecl(...@@ -2825,11 +2824,11 @@ fn zirStructDecl(
2825 const decls = sema.code.bodySlice(extra_index, decls_len);2824 const decls = sema.code.bodySlice(extra_index, decls_len);
2826 try pt.scanNamespace(new_namespace_index, decls);2825 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 });
2829 codegen_type: {2828 codegen_type: {
2830 if (mod.comp.config.use_llvm) break :codegen_type;2829 if (zcu.comp.config.use_llvm) break :codegen_type;
2831 if (block.ownerModule().strip) break :codegen_type;2830 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 });
2833 }2832 }
2834 try sema.declareDependency(.{ .interned = wip_ty.index });2833 try sema.declareDependency(.{ .interned = wip_ty.index });
2835 try sema.addTypeReferenceEntry(src, wip_ty.index);2834 try sema.addTypeReferenceEntry(src, wip_ty.index);
...@@ -2938,9 +2937,9 @@ fn zirEnumDecl(...@@ -2938,9 +2937,9 @@ fn zirEnumDecl(
2938 defer tracy.end();2937 defer tracy.end();
29392938
2940 const pt = sema.pt;2939 const pt = sema.pt;
2941 const mod = pt.zcu;2940 const zcu = pt.zcu;
2942 const gpa = sema.gpa;2941 const gpa = sema.gpa;
2943 const ip = &mod.intern_pool;2942 const ip = &zcu.intern_pool;
2944 const small: Zir.Inst.EnumDecl.Small = @bitCast(extended.small);2943 const small: Zir.Inst.EnumDecl.Small = @bitCast(extended.small);
2945 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);2944 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);
2946 var extra_index: usize = extra.end;2945 var extra_index: usize = extra.end;
...@@ -3015,7 +3014,7 @@ fn zirEnumDecl(...@@ -3015,7 +3014,7 @@ fn zirEnumDecl(
30153014
3016 // Make sure we update the namespace if the declaration is re-analyzed, to pick3015 // Make sure we update the namespace if the declaration is re-analyzed, to pick
3017 // up on e.g. changed comptime decls.3016 // 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
3020 try sema.declareDependency(.{ .interned = new_ty });3019 try sema.declareDependency(.{ .interned = new_ty });
3021 try sema.addTypeReferenceEntry(src, new_ty);3020 try sema.addTypeReferenceEntry(src, new_ty);
...@@ -3042,8 +3041,8 @@ fn zirEnumDecl(...@@ -3042,8 +3041,8 @@ fn zirEnumDecl(
3042 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{3041 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
3043 .parent = block.namespace.toOptional(),3042 .parent = block.namespace.toOptional(),
3044 .owner_type = wip_ty.index,3043 .owner_type = wip_ty.index,
3045 .file_scope = block.getFileScopeIndex(mod),3044 .file_scope = block.getFileScopeIndex(zcu),
3046 .generation = mod.generation,3045 .generation = zcu.generation,
3047 });3046 });
3048 errdefer if (!done) pt.destroyNamespace(new_namespace_index);3047 errdefer if (!done) pt.destroyNamespace(new_namespace_index);
30493048
...@@ -3077,9 +3076,9 @@ fn zirEnumDecl(...@@ -3077,9 +3076,9 @@ fn zirEnumDecl(
3077 );3076 );
30783077
3079 codegen_type: {3078 codegen_type: {
3080 if (mod.comp.config.use_llvm) break :codegen_type;3079 if (zcu.comp.config.use_llvm) break :codegen_type;
3081 if (block.ownerModule().strip) break :codegen_type;3080 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 });
3083 }3082 }
3084 return Air.internedToRef(wip_ty.index);3083 return Air.internedToRef(wip_ty.index);
3085}3084}
...@@ -3094,9 +3093,9 @@ fn zirUnionDecl(...@@ -3094,9 +3093,9 @@ fn zirUnionDecl(
3094 defer tracy.end();3093 defer tracy.end();
30953094
3096 const pt = sema.pt;3095 const pt = sema.pt;
3097 const mod = pt.zcu;3096 const zcu = pt.zcu;
3098 const gpa = sema.gpa;3097 const gpa = sema.gpa;
3099 const ip = &mod.intern_pool;3098 const ip = &zcu.intern_pool;
3100 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);3099 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
3101 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);3100 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);
3102 var extra_index: usize = extra.end;3101 var extra_index: usize = extra.end;
...@@ -3159,7 +3158,7 @@ fn zirUnionDecl(...@@ -3159,7 +3158,7 @@ fn zirUnionDecl(
31593158
3160 // Make sure we update the namespace if the declaration is re-analyzed, to pick3159 // Make sure we update the namespace if the declaration is re-analyzed, to pick
3161 // up on e.g. changed comptime decls.3160 // 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
3164 try sema.declareDependency(.{ .interned = new_ty });3163 try sema.declareDependency(.{ .interned = new_ty });
3165 try sema.addTypeReferenceEntry(src, new_ty);3164 try sema.addTypeReferenceEntry(src, new_ty);
...@@ -3180,15 +3179,15 @@ fn zirUnionDecl(...@@ -3180,15 +3179,15 @@ fn zirUnionDecl(
3180 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{3179 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
3181 .parent = block.namespace.toOptional(),3180 .parent = block.namespace.toOptional(),
3182 .owner_type = wip_ty.index,3181 .owner_type = wip_ty.index,
3183 .file_scope = block.getFileScopeIndex(mod),3182 .file_scope = block.getFileScopeIndex(zcu),
3184 .generation = mod.generation,3183 .generation = zcu.generation,
3185 });3184 });
3186 errdefer pt.destroyNamespace(new_namespace_index);3185 errdefer pt.destroyNamespace(new_namespace_index);
31873186
3188 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);3187 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
31893188
3190 if (pt.zcu.comp.incremental) {3189 if (pt.zcu.comp.incremental) {
3191 try mod.intern_pool.addDependency(3190 try zcu.intern_pool.addDependency(
3192 gpa,3191 gpa,
3193 AnalUnit.wrap(.{ .cau = new_cau_index }),3192 AnalUnit.wrap(.{ .cau = new_cau_index }),
3194 .{ .src_hash = tracked_inst },3193 .{ .src_hash = tracked_inst },
...@@ -3198,11 +3197,11 @@ fn zirUnionDecl(...@@ -3198,11 +3197,11 @@ fn zirUnionDecl(
3198 const decls = sema.code.bodySlice(extra_index, decls_len);3197 const decls = sema.code.bodySlice(extra_index, decls_len);
3199 try pt.scanNamespace(new_namespace_index, decls);3198 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 });
3202 codegen_type: {3201 codegen_type: {
3203 if (mod.comp.config.use_llvm) break :codegen_type;3202 if (zcu.comp.config.use_llvm) break :codegen_type;
3204 if (block.ownerModule().strip) break :codegen_type;3203 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 });
3206 }3205 }
3207 try sema.declareDependency(.{ .interned = wip_ty.index });3206 try sema.declareDependency(.{ .interned = wip_ty.index });
3208 try sema.addTypeReferenceEntry(src, wip_ty.index);3207 try sema.addTypeReferenceEntry(src, wip_ty.index);
...@@ -3219,9 +3218,9 @@ fn zirOpaqueDecl(...@@ -3219,9 +3218,9 @@ fn zirOpaqueDecl(
3219 defer tracy.end();3218 defer tracy.end();
32203219
3221 const pt = sema.pt;3220 const pt = sema.pt;
3222 const mod = pt.zcu;3221 const zcu = pt.zcu;
3223 const gpa = sema.gpa;3222 const gpa = sema.gpa;
3224 const ip = &mod.intern_pool;3223 const ip = &zcu.intern_pool;
32253224
3226 const small: Zir.Inst.OpaqueDecl.Small = @bitCast(extended.small);3225 const small: Zir.Inst.OpaqueDecl.Small = @bitCast(extended.small);
3227 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);3226 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
...@@ -3255,7 +3254,7 @@ fn zirOpaqueDecl(...@@ -3255,7 +3254,7 @@ fn zirOpaqueDecl(
3255 .existing => |ty| {3254 .existing => |ty| {
3256 // Make sure we update the namespace if the declaration is re-analyzed, to pick3255 // Make sure we update the namespace if the declaration is re-analyzed, to pick
3257 // up on e.g. changed comptime decls.3256 // 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
3260 try sema.declareDependency(.{ .interned = ty });3259 try sema.declareDependency(.{ .interned = ty });
3261 try sema.addTypeReferenceEntry(src, ty);3260 try sema.addTypeReferenceEntry(src, ty);
...@@ -3276,8 +3275,8 @@ fn zirOpaqueDecl(...@@ -3276,8 +3275,8 @@ fn zirOpaqueDecl(
3276 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{3275 const new_namespace_index: InternPool.NamespaceIndex = try pt.createNamespace(.{
3277 .parent = block.namespace.toOptional(),3276 .parent = block.namespace.toOptional(),
3278 .owner_type = wip_ty.index,3277 .owner_type = wip_ty.index,
3279 .file_scope = block.getFileScopeIndex(mod),3278 .file_scope = block.getFileScopeIndex(zcu),
3280 .generation = mod.generation,3279 .generation = zcu.generation,
3281 });3280 });
3282 errdefer pt.destroyNamespace(new_namespace_index);3281 errdefer pt.destroyNamespace(new_namespace_index);
32833282
...@@ -3285,9 +3284,9 @@ fn zirOpaqueDecl(...@@ -3285,9 +3284,9 @@ fn zirOpaqueDecl(
3285 try pt.scanNamespace(new_namespace_index, decls);3284 try pt.scanNamespace(new_namespace_index, decls);
32863285
3287 codegen_type: {3286 codegen_type: {
3288 if (mod.comp.config.use_llvm) break :codegen_type;3287 if (zcu.comp.config.use_llvm) break :codegen_type;
3289 if (block.ownerModule().strip) break :codegen_type;3288 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 });
3291 }3290 }
3292 try sema.addTypeReferenceEntry(src, wip_ty.index);3291 try sema.addTypeReferenceEntry(src, wip_ty.index);
3293 return Air.internedToRef(wip_ty.finish(ip, .none, new_namespace_index));3292 return Air.internedToRef(wip_ty.finish(ip, .none, new_namespace_index));
...@@ -3301,7 +3300,7 @@ fn zirErrorSetDecl(...@@ -3301,7 +3300,7 @@ fn zirErrorSetDecl(
3301 defer tracy.end();3300 defer tracy.end();
33023301
3303 const pt = sema.pt;3302 const pt = sema.pt;
3304 const mod = pt.zcu;3303 const zcu = pt.zcu;
3305 const gpa = sema.gpa;3304 const gpa = sema.gpa;
3306 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;3305 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
3307 const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);3306 const extra = sema.code.extraData(Zir.Inst.ErrorSetDecl, inst_data.payload_index);
...@@ -3314,7 +3313,7 @@ fn zirErrorSetDecl(...@@ -3314,7 +3313,7 @@ fn zirErrorSetDecl(
3314 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string3313 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
3315 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);3314 const name_index: Zir.NullTerminatedString = @enumFromInt(sema.code.extra[extra_index]);
3316 const name = sema.code.nullTerminatedString(name_index);3315 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);
3318 _ = try pt.getErrorValue(name_ip);3317 _ = try pt.getErrorValue(name_ip);
3319 const result = names.getOrPutAssumeCapacity(name_ip);3318 const result = names.getOrPutAssumeCapacity(name_ip);
3320 assert(!result.found_existing); // verified in AstGen3319 assert(!result.found_existing); // verified in AstGen
...@@ -3329,7 +3328,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {...@@ -3329,7 +3328,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
33293328
3330 const pt = sema.pt;3329 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)) {
3333 try sema.fn_ret_ty.resolveFields(pt);3332 try sema.fn_ret_ty.resolveFields(pt);
3334 return sema.analyzeComptimeAlloc(block, sema.fn_ret_ty, .none);3333 return sema.analyzeComptimeAlloc(block, sema.fn_ret_ty, .none);
3335 }3334 }
...@@ -3377,8 +3376,8 @@ fn ensureResultUsed(...@@ -3377,8 +3376,8 @@ fn ensureResultUsed(
3377 src: LazySrcLoc,3376 src: LazySrcLoc,
3378) CompileError!void {3377) CompileError!void {
3379 const pt = sema.pt;3378 const pt = sema.pt;
3380 const mod = pt.zcu;3379 const zcu = pt.zcu;
3381 switch (ty.zigTypeTag(mod)) {3380 switch (ty.zigTypeTag(zcu)) {
3382 .Void, .NoReturn => return,3381 .Void, .NoReturn => return,
3383 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),3382 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),
3384 .ErrorUnion => {3383 .ErrorUnion => {
...@@ -3408,12 +3407,12 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3408,12 +3407,12 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3408 defer tracy.end();3407 defer tracy.end();
34093408
3410 const pt = sema.pt;3409 const pt = sema.pt;
3411 const mod = pt.zcu;3410 const zcu = pt.zcu;
3412 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3411 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3413 const operand = try sema.resolveInst(inst_data.operand);3412 const operand = try sema.resolveInst(inst_data.operand);
3414 const src = block.nodeOffset(inst_data.src_node);3413 const src = block.nodeOffset(inst_data.src_node);
3415 const operand_ty = sema.typeOf(operand);3414 const operand_ty = sema.typeOf(operand);
3416 switch (operand_ty.zigTypeTag(mod)) {3415 switch (operand_ty.zigTypeTag(zcu)) {
3417 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),3416 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),
3418 .ErrorUnion => {3417 .ErrorUnion => {
3419 const msg = msg: {3418 const msg = msg: {
...@@ -3433,17 +3432,17 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index...@@ -3433,17 +3432,17 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
3433 defer tracy.end();3432 defer tracy.end();
34343433
3435 const pt = sema.pt;3434 const pt = sema.pt;
3436 const mod = pt.zcu;3435 const zcu = pt.zcu;
3437 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3436 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3438 const src = block.nodeOffset(inst_data.src_node);3437 const src = block.nodeOffset(inst_data.src_node);
3439 const operand = try sema.resolveInst(inst_data.operand);3438 const operand = try sema.resolveInst(inst_data.operand);
3440 const operand_ty = sema.typeOf(operand);3439 const operand_ty = sema.typeOf(operand);
3441 const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer)3440 const err_union_ty = if (operand_ty.zigTypeTag(zcu) == .Pointer)
3442 operand_ty.childType(mod)3441 operand_ty.childType(zcu)
3443 else3442 else
3444 operand_ty;3443 operand_ty;
3445 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) return;3444 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) return;
3446 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);3445 const payload_ty = err_union_ty.errorUnionPayload(zcu).zigTypeTag(zcu);
3447 if (payload_ty != .Void and payload_ty != .NoReturn) {3446 if (payload_ty != .Void and payload_ty != .NoReturn) {
3448 const msg = msg: {3447 const msg = msg: {
3449 const msg = try sema.errMsg(src, "error union payload is ignored", .{});3448 const msg = try sema.errMsg(src, "error union payload is ignored", .{});
...@@ -3473,12 +3472,12 @@ fn indexablePtrLen(...@@ -3473,12 +3472,12 @@ fn indexablePtrLen(
3473 object: Air.Inst.Ref,3472 object: Air.Inst.Ref,
3474) CompileError!Air.Inst.Ref {3473) CompileError!Air.Inst.Ref {
3475 const pt = sema.pt;3474 const pt = sema.pt;
3476 const mod = pt.zcu;3475 const zcu = pt.zcu;
3477 const object_ty = sema.typeOf(object);3476 const object_ty = sema.typeOf(object);
3478 const is_pointer_to = object_ty.isSinglePointer(mod);3477 const is_pointer_to = object_ty.isSinglePointer(zcu);
3479 const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty;3478 const indexable_ty = if (is_pointer_to) object_ty.childType(zcu) else object_ty;
3480 try checkIndexable(sema, block, src, indexable_ty);3479 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);
3482 return sema.fieldVal(block, src, object, field_name, src);3481 return sema.fieldVal(block, src, object, field_name, src);
3483}3482}
34843483
...@@ -3489,11 +3488,11 @@ fn indexablePtrLenOrNone(...@@ -3489,11 +3488,11 @@ fn indexablePtrLenOrNone(
3489 operand: Air.Inst.Ref,3488 operand: Air.Inst.Ref,
3490) CompileError!Air.Inst.Ref {3489) CompileError!Air.Inst.Ref {
3491 const pt = sema.pt;3490 const pt = sema.pt;
3492 const mod = pt.zcu;3491 const zcu = pt.zcu;
3493 const operand_ty = sema.typeOf(operand);3492 const operand_ty = sema.typeOf(operand);
3494 try checkMemOperand(sema, block, src, operand_ty);3493 try checkMemOperand(sema, block, src, operand_ty);
3495 if (operand_ty.ptrSize(mod) == .Many) return .none;3494 if (operand_ty.ptrSize(zcu) == .Many) return .none;
3496 const field_name = try mod.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);3495 const field_name = try zcu.intern_pool.getOrPutString(sema.gpa, pt.tid, "len", .no_embedded_nulls);
3497 return sema.fieldVal(block, src, operand, field_name, src);3496 return sema.fieldVal(block, src, operand, field_name, src);
3498}3497}
34993498
...@@ -3545,7 +3544,7 @@ fn zirAllocExtended(...@@ -3545,7 +3544,7 @@ fn zirAllocExtended(
3545 }3544 }
3546 const target = pt.zcu.getTarget();3545 const target = pt.zcu.getTarget();
3547 try var_ty.resolveLayout(pt);3546 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)) {
3549 const var_src = block.src(.{ .node_offset_store_ptr = extra.data.src_node });3548 const var_src = block.src(.{ .node_offset_store_ptr = extra.data.src_node });
3550 return sema.fail(block, var_src, "local variable in naked function", .{});3549 return sema.fail(block, var_src, "local variable in naked function", .{});
3551 }3550 }
...@@ -3592,11 +3591,11 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -3592,11 +3591,11 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
35923591
3593fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {3592fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3594 const pt = sema.pt;3593 const pt = sema.pt;
3595 const mod = pt.zcu;3594 const zcu = pt.zcu;
3596 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3595 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3597 const alloc = try sema.resolveInst(inst_data.operand);3596 const alloc = try sema.resolveInst(inst_data.operand);
3598 const alloc_ty = sema.typeOf(alloc);3597 const alloc_ty = sema.typeOf(alloc);
3599 const ptr_info = alloc_ty.ptrInfo(mod);3598 const ptr_info = alloc_ty.ptrInfo(zcu);
3600 const elem_ty = Type.fromInterned(ptr_info.child);3599 const elem_ty = Type.fromInterned(ptr_info.child);
36013600
3602 // If the alloc was created in a comptime scope, we already created a comptime alloc for it.3601 // 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...@@ -3607,7 +3606,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36073606
3608 // If this was a comptime inferred alloc, then `storeToInferredAllocComptime`3607 // If this was a comptime inferred alloc, then `storeToInferredAllocComptime`
3609 // might have already done our job and created an anon decl ref.3608 // 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())) {
3611 .ptr => |ptr| switch (ptr.base_addr) {3610 .ptr => |ptr| switch (ptr.base_addr) {
3612 .uav => {3611 .uav => {
3613 // The comptime-ification was already done for us.3612 // The comptime-ification was already done for us.
...@@ -3620,12 +3619,12 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -3620,12 +3619,12 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
3620 }3619 }
36213620
3622 if (!sema.isComptimeMutablePtr(ptr_val)) break :already_ct;3621 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;
3624 assert(ptr.byte_offset == 0);3623 assert(ptr.byte_offset == 0);
3625 const alloc_index = ptr.base_addr.comptime_alloc;3624 const alloc_index = ptr.base_addr.comptime_alloc;
3626 const ct_alloc = sema.getComptimeAlloc(alloc_index);3625 const ct_alloc = sema.getComptimeAlloc(alloc_index);
3627 const interned = try ct_alloc.val.intern(pt, sema.arena);3626 const interned = try ct_alloc.val.intern(pt, sema.arena);
3628 if (interned.canMutateComptimeVarState(mod)) {3627 if (interned.canMutateComptimeVarState(zcu)) {
3629 // Preserve the comptime alloc, just make the pointer const.3628 // Preserve the comptime alloc, just make the pointer const.
3630 ct_alloc.val = .{ .interned = interned.toIntern() };3629 ct_alloc.val = .{ .interned = interned.toIntern() };
3631 ct_alloc.is_const = true;3630 ct_alloc.is_const = true;
...@@ -3649,7 +3648,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -3649,7 +3648,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
3649 return sema.makePtrConst(block, Air.internedToRef(ptr_val));3648 return sema.makePtrConst(block, Air.internedToRef(ptr_val));
3650 }3649 }
36513650
3652 if (try sema.typeRequiresComptime(elem_ty)) {3651 if (try elem_ty.comptimeOnlySema(pt)) {
3653 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.3652 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
3654 // TODO: source location of runtime control flow3653 // TODO: source location of runtime control flow
3655 const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });3654 const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
...@@ -3918,7 +3917,7 @@ fn finishResolveComptimeKnownAllocPtr(...@@ -3918,7 +3917,7 @@ fn finishResolveComptimeKnownAllocPtr(
39183917
3919 if (Value.fromInterned(result_val).canMutateComptimeVarState(zcu)) {3918 if (Value.fromInterned(result_val).canMutateComptimeVarState(zcu)) {
3920 const alloc_index = existing_comptime_alloc orelse a: {3919 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));
3922 const alloc = sema.getComptimeAlloc(idx);3921 const alloc = sema.getComptimeAlloc(idx);
3923 alloc.val = .{ .interned = result_val };3922 alloc.val = .{ .interned = result_val };
3924 break :a idx;3923 break :a idx;
...@@ -3989,7 +3988,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -3989,7 +3988,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
3989 if (block.is_comptime) {3988 if (block.is_comptime) {
3990 return sema.analyzeComptimeAlloc(block, var_ty, .none);3989 return sema.analyzeComptimeAlloc(block, var_ty, .none);
3991 }3990 }
3992 if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {3991 if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
3993 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });3992 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
3994 return sema.fail(block, mut_src, "local variable in naked function", .{});3993 return sema.fail(block, mut_src, "local variable in naked function", .{});
3995 }3994 }
...@@ -4017,7 +4016,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -4017,7 +4016,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
4017 if (block.is_comptime) {4016 if (block.is_comptime) {
4018 return sema.analyzeComptimeAlloc(block, var_ty, .none);4017 return sema.analyzeComptimeAlloc(block, var_ty, .none);
4019 }4018 }
4020 if (sema.func_is_naked and try sema.typeHasRuntimeBits(var_ty)) {4019 if (sema.func_is_naked and try var_ty.hasRuntimeBitsSema(pt)) {
4021 const var_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });4020 const var_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
4022 return sema.fail(block, var_src, "local variable in naked function", .{});4021 return sema.fail(block, var_src, "local variable in naked function", .{});
4023 }4022 }
...@@ -4072,14 +4071,14 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4072,14 +4071,14 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4072 defer tracy.end();4071 defer tracy.end();
40734072
4074 const pt = sema.pt;4073 const pt = sema.pt;
4075 const mod = pt.zcu;4074 const zcu = pt.zcu;
4076 const gpa = sema.gpa;4075 const gpa = sema.gpa;
4077 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4076 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4078 const src = block.nodeOffset(inst_data.src_node);4077 const src = block.nodeOffset(inst_data.src_node);
4079 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });4078 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
4080 const ptr = try sema.resolveInst(inst_data.operand);4079 const ptr = try sema.resolveInst(inst_data.operand);
4081 const ptr_inst = ptr.toIndex().?;4080 const ptr_inst = ptr.toIndex().?;
4082 const target = mod.getTarget();4081 const target = zcu.getTarget();
40834082
4084 switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) {4083 switch (sema.air_instructions.items(.tag)[@intFromEnum(ptr_inst)]) {
4085 .inferred_alloc_comptime => {4084 .inferred_alloc_comptime => {
...@@ -4093,7 +4092,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4093,7 +4092,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4093 sema.air_instructions.set(@intFromEnum(ptr_inst), .{ .tag = undefined, .data = undefined });4092 sema.air_instructions.set(@intFromEnum(ptr_inst), .{ .tag = undefined, .data = undefined });
4094 }4093 }
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) {
4097 .uav => |a| a.val,4096 .uav => |a| a.val,
4098 .comptime_alloc => |i| val: {4097 .comptime_alloc => |i| val: {
4099 const alloc = sema.getComptimeAlloc(i);4098 const alloc = sema.getComptimeAlloc(i);
...@@ -4101,11 +4100,11 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4101,11 +4100,11 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4101 },4100 },
4102 else => unreachable,4101 else => unreachable,
4103 };4102 };
4104 if (mod.intern_pool.isFuncBody(val)) {4103 if (zcu.intern_pool.isFuncBody(val)) {
4105 const ty = Type.fromInterned(mod.intern_pool.typeOf(val));4104 const ty = Type.fromInterned(zcu.intern_pool.typeOf(val));
4106 if (try sema.fnHasRuntimeBits(ty)) {4105 if (try ty.fnHasRuntimeBitsSema(pt)) {
4107 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .func = val }));4106 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .func = val }));
4108 try mod.ensureFuncBodyAnalysisQueued(val);4107 try zcu.ensureFuncBodyAnalysisQueued(val);
4109 }4108 }
4110 }4109 }
41114110
...@@ -4148,13 +4147,13 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4148,13 +4147,13 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4148 return;4147 return;
4149 }4148 }
41504149
4151 if (try sema.typeRequiresComptime(final_elem_ty)) {4150 if (try final_elem_ty.comptimeOnlySema(pt)) {
4152 // The alloc wasn't comptime-known per the above logic, so the4151 // The alloc wasn't comptime-known per the above logic, so the
4153 // type cannot be comptime-only.4152 // type cannot be comptime-only.
4154 // TODO: source location of runtime control flow4153 // TODO: source location of runtime control flow
4155 return sema.fail(block, src, "value with comptime-only type '{}' depends on runtime control flow", .{final_elem_ty.fmt(pt)});4154 return sema.fail(block, src, "value with comptime-only type '{}' depends on runtime control flow", .{final_elem_ty.fmt(pt)});
4156 }4155 }
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)) {
4158 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });4157 const mut_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
4159 return sema.fail(block, mut_src, "local variable in naked function", .{});4158 return sema.fail(block, mut_src, "local variable in naked function", .{});
4160 }4159 }
...@@ -4213,9 +4212,9 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4213,9 +4212,9 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
42134212
4214fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4213fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4215 const pt = sema.pt;4214 const pt = sema.pt;
4216 const mod = pt.zcu;4215 const zcu = pt.zcu;
4217 const gpa = sema.gpa;4216 const gpa = sema.gpa;
4218 const ip = &mod.intern_pool;4217 const ip = &zcu.intern_pool;
4219 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4218 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4220 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);4219 const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index);
4221 const args = sema.code.refSlice(extra.end, extra.data.operands_len);4220 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....@@ -4238,7 +4237,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4238 const object_ty = sema.typeOf(object);4237 const object_ty = sema.typeOf(object);
4239 // Each arg could be an indexable, or a range, in which case the length4238 // Each arg could be an indexable, or a range, in which case the length
4240 // is passed directly as an integer.4239 // is passed directly as an integer.
4241 const is_int = switch (object_ty.zigTypeTag(mod)) {4240 const is_int = switch (object_ty.zigTypeTag(zcu)) {
4242 .Int, .ComptimeInt => true,4241 .Int, .ComptimeInt => true,
4243 else => false,4242 else => false,
4244 };4243 };
...@@ -4247,14 +4246,14 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4247,14 +4246,14 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4247 .input_index = i,4246 .input_index = i,
4248 } });4247 } });
4249 const arg_len_uncoerced = if (is_int) object else l: {4248 const arg_len_uncoerced = if (is_int) object else l: {
4250 if (!object_ty.isIndexable(mod)) {4249 if (!object_ty.isIndexable(zcu)) {
4251 // Instead of using checkIndexable we customize this error.4250 // Instead of using checkIndexable we customize this error.
4252 const msg = msg: {4251 const msg = msg: {
4253 const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(pt)});4252 const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(pt)});
4254 errdefer msg.destroy(sema.gpa);4253 errdefer msg.destroy(sema.gpa);
4255 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});4254 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) {
4258 try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});4257 try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});
4259 }4258 }
42604259
...@@ -4262,7 +4261,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4262,7 +4261,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4262 };4261 };
4263 return sema.failWithOwnedErrorMsg(block, msg);4262 return sema.failWithOwnedErrorMsg(block, msg);
4264 }4263 }
4265 if (!object_ty.indexableHasLen(mod)) continue;4264 if (!object_ty.indexableHasLen(zcu)) continue;
42664265
4267 break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), arg_src);4266 break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), arg_src);
4268 };4267 };
...@@ -4313,7 +4312,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4313,7 +4312,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4313 const object_ty = sema.typeOf(object);4312 const object_ty = sema.typeOf(object);
4314 // Each arg could be an indexable, or a range, in which case the length4313 // Each arg could be an indexable, or a range, in which case the length
4315 // is passed directly as an integer.4314 // is passed directly as an integer.
4316 switch (object_ty.zigTypeTag(mod)) {4315 switch (object_ty.zigTypeTag(zcu)) {
4317 .Int, .ComptimeInt => continue,4316 .Int, .ComptimeInt => continue,
4318 else => {},4317 else => {},
4319 }4318 }
...@@ -4349,9 +4348,9 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4349,9 +4348,9 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4349/// May invalidate already-stored payload data.4348/// May invalidate already-stored payload data.
4350fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcLoc) CompileError!Air.Inst.Ref {4349fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcLoc) CompileError!Air.Inst.Ref {
4351 const pt = sema.pt;4350 const pt = sema.pt;
4352 const mod = pt.zcu;4351 const zcu = pt.zcu;
4353 var base_ptr = ptr;4352 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)) {
4355 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),4354 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
4356 .Optional => base_ptr = try sema.analyzeOptionalPayloadPtr(block, src, base_ptr, false, true),4355 .Optional => base_ptr = try sema.analyzeOptionalPayloadPtr(block, src, base_ptr, false, true),
4357 else => break,4356 else => break,
...@@ -4368,7 +4367,7 @@ fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile...@@ -4368,7 +4367,7 @@ fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
43684367
4369fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {4368fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
4370 const pt = sema.pt;4369 const pt = sema.pt;
4371 const mod = pt.zcu;4370 const zcu = pt.zcu;
4372 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4371 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4373 const src = block.nodeOffset(pl_node.src_node);4372 const src = block.nodeOffset(pl_node.src_node);
4374 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;4373 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...@@ -4377,13 +4376,13 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
4377 error.GenericPoison => return uncoerced_val,4376 error.GenericPoison => return uncoerced_val,
4378 else => |e| return e,4377 else => |e| return e,
4379 };4378 };
4380 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(mod);4379 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu);
4381 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction4380 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
4382 const elem_ty = ptr_ty.childType(mod);4381 const elem_ty = ptr_ty.childType(zcu);
4383 switch (ptr_ty.ptrSize(mod)) {4382 switch (ptr_ty.ptrSize(zcu)) {
4384 .One => {4383 .One => {
4385 const uncoerced_ty = sema.typeOf(uncoerced_val);4384 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()) {
4387 // We're trying to initialize a *[1]T with a reference to a T - don't perform any coercion.4386 // We're trying to initialize a *[1]T with a reference to a T - don't perform any coercion.
4388 return uncoerced_val;4387 return uncoerced_val;
4389 }4388 }
...@@ -4397,16 +4396,16 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -4397,16 +4396,16 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
4397 .Slice, .Many => {4396 .Slice, .Many => {
4398 // Our goal is to coerce `uncoerced_val` to an array of `elem_ty`.4397 // Our goal is to coerce `uncoerced_val` to an array of `elem_ty`.
4399 const val_ty = sema.typeOf(uncoerced_val);4398 const val_ty = sema.typeOf(uncoerced_val);
4400 switch (val_ty.zigTypeTag(mod)) {4399 switch (val_ty.zigTypeTag(zcu)) {
4401 .Array, .Vector => {},4400 .Array, .Vector => {},
4402 else => if (!val_ty.isTuple(mod)) {4401 else => if (!val_ty.isTuple(zcu)) {
4403 return sema.fail(block, src, "expected array of '{}', found '{}'", .{ elem_ty.fmt(pt), val_ty.fmt(pt) });4402 return sema.fail(block, src, "expected array of '{}', found '{}'", .{ elem_ty.fmt(pt), val_ty.fmt(pt) });
4404 },4403 },
4405 }4404 }
4406 const want_ty = try pt.arrayType(.{4405 const want_ty = try pt.arrayType(.{
4407 .len = val_ty.arrayLen(mod),4406 .len = val_ty.arrayLen(zcu),
4408 .child = elem_ty.toIntern(),4407 .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,
4410 });4409 });
4411 return sema.coerce(block, want_ty, uncoerced_val, src);4410 return sema.coerce(block, want_ty, uncoerced_val, src);
4412 },4411 },
...@@ -4420,7 +4419,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -4420,7 +4419,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
44204419
4421fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {4420fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
4422 const pt = sema.pt;4421 const pt = sema.pt;
4423 const mod = pt.zcu;4422 const zcu = pt.zcu;
4424 const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;4423 const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
4425 const src = block.tokenOffset(un_tok.src_tok);4424 const src = block.tokenOffset(un_tok.src_tok);
4426 // In case of GenericPoison, we don't actually have a type, so this will be4425 // 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...@@ -4434,7 +4433,7 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
4434 else => |e| return e,4433 else => |e| return e,
4435 };4434 };
4436 if (ty_operand.isGenericPoison()) return;4435 if (ty_operand.isGenericPoison()) return;
4437 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {4436 if (ty_operand.optEuBaseType(zcu).zigTypeTag(zcu) != .Pointer) {
4438 return sema.failWithOwnedErrorMsg(block, msg: {4437 return sema.failWithOwnedErrorMsg(block, msg: {
4439 const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(pt)});4438 const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(pt)});
4440 errdefer msg.destroy(sema.gpa);4439 errdefer msg.destroy(sema.gpa);
...@@ -4450,7 +4449,7 @@ fn zirValidateArrayInitRefTy(...@@ -4450,7 +4449,7 @@ fn zirValidateArrayInitRefTy(
4450 inst: Zir.Inst.Index,4449 inst: Zir.Inst.Index,
4451) CompileError!Air.Inst.Ref {4450) CompileError!Air.Inst.Ref {
4452 const pt = sema.pt;4451 const pt = sema.pt;
4453 const mod = pt.zcu;4452 const zcu = pt.zcu;
4454 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4453 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4455 const src = block.nodeOffset(pl_node.src_node);4454 const src = block.nodeOffset(pl_node.src_node);
4456 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;4455 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;
...@@ -4458,16 +4457,16 @@ fn zirValidateArrayInitRefTy(...@@ -4458,16 +4457,16 @@ fn zirValidateArrayInitRefTy(
4458 error.GenericPoison => return .generic_poison_type,4457 error.GenericPoison => return .generic_poison_type,
4459 else => |e| return e,4458 else => |e| return e,
4460 };4459 };
4461 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(mod);4460 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu);
4462 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction4461 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
4463 switch (mod.intern_pool.indexToKey(ptr_ty.toIntern())) {4462 switch (zcu.intern_pool.indexToKey(ptr_ty.toIntern())) {
4464 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {4463 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
4465 .Slice, .Many => {4464 .Slice, .Many => {
4466 // Use array of correct length4465 // Use array of correct length
4467 const arr_ty = try pt.arrayType(.{4466 const arr_ty = try pt.arrayType(.{
4468 .len = extra.elem_count,4467 .len = extra.elem_count,
4469 .child = ptr_ty.childType(mod).toIntern(),4468 .child = ptr_ty.childType(zcu).toIntern(),
4470 .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,4469 .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
4471 });4470 });
4472 return Air.internedToRef(arr_ty.toIntern());4471 return Air.internedToRef(arr_ty.toIntern());
4473 },4472 },
...@@ -4476,12 +4475,12 @@ fn zirValidateArrayInitRefTy(...@@ -4476,12 +4475,12 @@ fn zirValidateArrayInitRefTy(
4476 else => {},4475 else => {},
4477 }4476 }
4478 // Otherwise, we just want the pointer child type4477 // Otherwise, we just want the pointer child type
4479 const ret_ty = ptr_ty.childType(mod);4478 const ret_ty = ptr_ty.childType(zcu);
4480 if (ret_ty.toIntern() == .anyopaque_type) {4479 if (ret_ty.toIntern() == .anyopaque_type) {
4481 // The actual array type is unknown, which we represent with a generic poison.4480 // The actual array type is unknown, which we represent with a generic poison.
4482 return .generic_poison_type;4481 return .generic_poison_type;
4483 }4482 }
4484 const arr_ty = ret_ty.optEuBaseType(mod);4483 const arr_ty = ret_ty.optEuBaseType(zcu);
4485 try sema.validateArrayInitTy(block, src, src, extra.elem_count, arr_ty);4484 try sema.validateArrayInitTy(block, src, src, extra.elem_count, arr_ty);
4486 return Air.internedToRef(ret_ty.toIntern());4485 return Air.internedToRef(ret_ty.toIntern());
4487}4486}
...@@ -4493,7 +4492,7 @@ fn zirValidateArrayInitTy(...@@ -4493,7 +4492,7 @@ fn zirValidateArrayInitTy(
4493 is_result_ty: bool,4492 is_result_ty: bool,
4494) CompileError!void {4493) CompileError!void {
4495 const pt = sema.pt;4494 const pt = sema.pt;
4496 const mod = pt.zcu;4495 const zcu = pt.zcu;
4497 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4496 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4498 const src = block.nodeOffset(inst_data.src_node);4497 const src = block.nodeOffset(inst_data.src_node);
4499 const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node });4498 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(...@@ -4503,7 +4502,7 @@ fn zirValidateArrayInitTy(
4503 error.GenericPoison => return,4502 error.GenericPoison => return,
4504 else => |e| return e,4503 else => |e| return e,
4505 };4504 };
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;
4507 return sema.validateArrayInitTy(block, src, ty_src, extra.init_count, arr_ty);4506 return sema.validateArrayInitTy(block, src, ty_src, extra.init_count, arr_ty);
4508}4507}
45094508
...@@ -4516,10 +4515,10 @@ fn validateArrayInitTy(...@@ -4516,10 +4515,10 @@ fn validateArrayInitTy(
4516 ty: Type,4515 ty: Type,
4517) CompileError!void {4516) CompileError!void {
4518 const pt = sema.pt;4517 const pt = sema.pt;
4519 const mod = pt.zcu;4518 const zcu = pt.zcu;
4520 switch (ty.zigTypeTag(mod)) {4519 switch (ty.zigTypeTag(zcu)) {
4521 .Array => {4520 .Array => {
4522 const array_len = ty.arrayLen(mod);4521 const array_len = ty.arrayLen(zcu);
4523 if (init_count != array_len) {4522 if (init_count != array_len) {
4524 return sema.fail(block, src, "expected {d} array elements; found {d}", .{4523 return sema.fail(block, src, "expected {d} array elements; found {d}", .{
4525 array_len, init_count,4524 array_len, init_count,
...@@ -4528,7 +4527,7 @@ fn validateArrayInitTy(...@@ -4528,7 +4527,7 @@ fn validateArrayInitTy(
4528 return;4527 return;
4529 },4528 },
4530 .Vector => {4529 .Vector => {
4531 const array_len = ty.arrayLen(mod);4530 const array_len = ty.arrayLen(zcu);
4532 if (init_count != array_len) {4531 if (init_count != array_len) {
4533 return sema.fail(block, src, "expected {d} vector elements; found {d}", .{4532 return sema.fail(block, src, "expected {d} vector elements; found {d}", .{
4534 array_len, init_count,4533 array_len, init_count,
...@@ -4536,9 +4535,9 @@ fn validateArrayInitTy(...@@ -4536,9 +4535,9 @@ fn validateArrayInitTy(
4536 }4535 }
4537 return;4536 return;
4538 },4537 },
4539 .Struct => if (ty.isTuple(mod)) {4538 .Struct => if (ty.isTuple(zcu)) {
4540 try ty.resolveFields(pt);4539 try ty.resolveFields(pt);
4541 const array_len = ty.arrayLen(mod);4540 const array_len = ty.arrayLen(zcu);
4542 if (init_count > array_len) {4541 if (init_count > array_len) {
4543 return sema.fail(block, src, "expected at most {d} tuple fields; found {d}", .{4542 return sema.fail(block, src, "expected at most {d} tuple fields; found {d}", .{
4544 array_len, init_count,4543 array_len, init_count,
...@@ -4558,7 +4557,7 @@ fn zirValidateStructInitTy(...@@ -4558,7 +4557,7 @@ fn zirValidateStructInitTy(
4558 is_result_ty: bool,4557 is_result_ty: bool,
4559) CompileError!void {4558) CompileError!void {
4560 const pt = sema.pt;4559 const pt = sema.pt;
4561 const mod = pt.zcu;4560 const zcu = pt.zcu;
4562 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4561 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4563 const src = block.nodeOffset(inst_data.src_node);4562 const src = block.nodeOffset(inst_data.src_node);
4564 const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {4563 const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {
...@@ -4566,9 +4565,9 @@ fn zirValidateStructInitTy(...@@ -4566,9 +4565,9 @@ fn zirValidateStructInitTy(
4566 error.GenericPoison => return,4565 error.GenericPoison => return,
4567 else => |e| return e,4566 else => |e| return e,
4568 };4567 };
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)) {
4572 .Struct, .Union => return,4571 .Struct, .Union => return,
4573 else => {},4572 else => {},
4574 }4573 }
...@@ -4584,7 +4583,7 @@ fn zirValidatePtrStructInit(...@@ -4584,7 +4583,7 @@ fn zirValidatePtrStructInit(
4584 defer tracy.end();4583 defer tracy.end();
45854584
4586 const pt = sema.pt;4585 const pt = sema.pt;
4587 const mod = pt.zcu;4586 const zcu = pt.zcu;
4588 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4587 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4589 const init_src = block.nodeOffset(validate_inst.src_node);4588 const init_src = block.nodeOffset(validate_inst.src_node);
4590 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);4589 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
...@@ -4592,8 +4591,8 @@ fn zirValidatePtrStructInit(...@@ -4592,8 +4591,8 @@ fn zirValidatePtrStructInit(
4592 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;4591 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
4593 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;4592 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
4594 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);4593 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);
4595 const agg_ty = sema.typeOf(object_ptr).childType(mod).optEuBaseType(mod);4594 const agg_ty = sema.typeOf(object_ptr).childType(zcu).optEuBaseType(zcu);
4596 switch (agg_ty.zigTypeTag(mod)) {4595 switch (agg_ty.zigTypeTag(zcu)) {
4597 .Struct => return sema.validateStructInit(4596 .Struct => return sema.validateStructInit(
4598 block,4597 block,
4599 agg_ty,4598 agg_ty,
...@@ -4620,7 +4619,7 @@ fn validateUnionInit(...@@ -4620,7 +4619,7 @@ fn validateUnionInit(
4620 union_ptr: Air.Inst.Ref,4619 union_ptr: Air.Inst.Ref,
4621) CompileError!void {4620) CompileError!void {
4622 const pt = sema.pt;4621 const pt = sema.pt;
4623 const mod = pt.zcu;4622 const zcu = pt.zcu;
4624 const gpa = sema.gpa;4623 const gpa = sema.gpa;
46254624
4626 if (instrs.len != 1) {4625 if (instrs.len != 1) {
...@@ -4654,7 +4653,7 @@ fn validateUnionInit(...@@ -4654,7 +4653,7 @@ fn validateUnionInit(
4654 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;4653 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4655 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });4654 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
4656 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;4655 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(
4658 gpa,4657 gpa,
4659 pt.tid,4658 pt.tid,
4660 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),4659 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
...@@ -4718,9 +4717,9 @@ fn validateUnionInit(...@@ -4718,9 +4717,9 @@ fn validateUnionInit(
4718 break;4717 break;
4719 }4718 }
47204719
4721 const tag_ty = union_ty.unionTagTypeHypothetical(mod);4720 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
4722 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);4721 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
4725 if (try sema.typeHasOnePossibleValue(field_type)) |field_only_value| {4724 if (try sema.typeHasOnePossibleValue(field_type)) |field_only_value| {
4726 init_val = field_only_value;4725 init_val = field_only_value;
...@@ -4761,7 +4760,7 @@ fn validateUnionInit(...@@ -4761,7 +4760,7 @@ fn validateUnionInit(
4761 const union_init = Air.internedToRef(union_val);4760 const union_init = Air.internedToRef(union_val);
4762 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);4761 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
4763 return;4762 return;
4764 } else if (try sema.typeRequiresComptime(union_ty)) {4763 } else if (try union_ty.comptimeOnlySema(pt)) {
4765 return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{4764 return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{
4766 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",4765 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
4767 });4766 });
...@@ -4781,15 +4780,15 @@ fn validateStructInit(...@@ -4781,15 +4780,15 @@ fn validateStructInit(
4781 instrs: []const Zir.Inst.Index,4780 instrs: []const Zir.Inst.Index,
4782) CompileError!void {4781) CompileError!void {
4783 const pt = sema.pt;4782 const pt = sema.pt;
4784 const mod = pt.zcu;4783 const zcu = pt.zcu;
4785 const gpa = sema.gpa;4784 const gpa = sema.gpa;
4786 const ip = &mod.intern_pool;4785 const ip = &zcu.intern_pool;
47874786
4788 const field_indices = try gpa.alloc(u32, instrs.len);4787 const field_indices = try gpa.alloc(u32, instrs.len);
4789 defer gpa.free(field_indices);4788 defer gpa.free(field_indices);
47904789
4791 // Maps field index to field_ptr index of where it was already initialized.4790 // 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));
4793 defer gpa.free(found_fields);4792 defer gpa.free(found_fields);
4794 @memset(found_fields, .none);4793 @memset(found_fields, .none);
47954794
...@@ -4806,7 +4805,7 @@ fn validateStructInit(...@@ -4806,7 +4805,7 @@ fn validateStructInit(
4806 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),4805 sema.code.nullTerminatedString(field_ptr_extra.field_name_start),
4807 .no_embedded_nulls,4806 .no_embedded_nulls,
4808 );4807 );
4809 field_index.* = if (struct_ty.isTuple(mod))4808 field_index.* = if (struct_ty.isTuple(zcu))
4810 try sema.tupleFieldIndex(block, struct_ty, field_name, field_src)4809 try sema.tupleFieldIndex(block, struct_ty, field_name, field_src)
4811 else4810 else
4812 try sema.structFieldIndex(block, struct_ty, field_name, field_src);4811 try sema.structFieldIndex(block, struct_ty, field_name, field_src);
...@@ -4814,7 +4813,7 @@ fn validateStructInit(...@@ -4814,7 +4813,7 @@ fn validateStructInit(
4814 found_fields[field_index.*] = field_ptr.toOptional();4813 found_fields[field_index.*] = field_ptr.toOptional();
4815 }4814 }
48164815
4817 var root_msg: ?*Module.ErrorMsg = null;4816 var root_msg: ?*Zcu.ErrorMsg = null;
4818 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);4817 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
48194818
4820 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);4819 const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref);
...@@ -4830,9 +4829,9 @@ fn validateStructInit(...@@ -4830,9 +4829,9 @@ fn validateStructInit(
4830 if (field_ptr != .none) continue;4829 if (field_ptr != .none) continue;
48314830
4832 try struct_ty.resolveStructFieldInits(pt);4831 try struct_ty.resolveStructFieldInits(pt);
4833 const default_val = struct_ty.structFieldDefaultValue(i, mod);4832 const default_val = struct_ty.structFieldDefaultValue(i, zcu);
4834 if (default_val.toIntern() == .unreachable_value) {4833 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 {
4836 const template = "missing tuple field with index {d}";4835 const template = "missing tuple field with index {d}";
4837 if (root_msg) |msg| {4836 if (root_msg) |msg| {
4838 try sema.errNote(init_src, msg, template, .{i});4837 try sema.errNote(init_src, msg, template, .{i});
...@@ -4852,7 +4851,7 @@ fn validateStructInit(...@@ -4852,7 +4851,7 @@ fn validateStructInit(
4852 }4851 }
48534852
4854 const field_src = init_src; // TODO better source location4853 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))
4856 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)4855 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)
4857 else4856 else
4858 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);4857 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);
...@@ -4874,7 +4873,7 @@ fn validateStructInit(...@@ -4874,7 +4873,7 @@ fn validateStructInit(
4874 var struct_is_comptime = true;4873 var struct_is_comptime = true;
4875 var first_block_index = block.instructions.items.len;4874 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);
4878 const air_tags = sema.air_instructions.items(.tag);4877 const air_tags = sema.air_instructions.items(.tag);
4879 const air_datas = sema.air_instructions.items(.data);4878 const air_datas = sema.air_instructions.items(.data);
48804879
...@@ -4882,13 +4881,13 @@ fn validateStructInit(...@@ -4882,13 +4881,13 @@ fn validateStructInit(
48824881
4883 // We collect the comptime field values in case the struct initialization4882 // We collect the comptime field values in case the struct initialization
4884 // ends up being comptime-known.4883 // 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
4887 field: for (found_fields, 0..) |opt_field_ptr, i_usize| {4886 field: for (found_fields, 0..) |opt_field_ptr, i_usize| {
4888 const i: u32 = @intCast(i_usize);4887 const i: u32 = @intCast(i_usize);
4889 if (opt_field_ptr.unwrap()) |field_ptr| {4888 if (opt_field_ptr.unwrap()) |field_ptr| {
4890 // Determine whether the value stored to this pointer is comptime-known.4889 // 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);
4892 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {4891 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {
4893 field_values[i] = opv.toIntern();4892 field_values[i] = opv.toIntern();
4894 continue;4893 continue;
...@@ -4958,9 +4957,9 @@ fn validateStructInit(...@@ -4958,9 +4957,9 @@ fn validateStructInit(
4958 continue :field;4957 continue :field;
4959 }4958 }
49604959
4961 const default_val = struct_ty.structFieldDefaultValue(i, mod);4960 const default_val = struct_ty.structFieldDefaultValue(i, zcu);
4962 if (default_val.toIntern() == .unreachable_value) {4961 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 {
4964 const template = "missing tuple field with index {d}";4963 const template = "missing tuple field with index {d}";
4965 if (root_msg) |msg| {4964 if (root_msg) |msg| {
4966 try sema.errNote(init_src, msg, template, .{i});4965 try sema.errNote(init_src, msg, template, .{i});
...@@ -5000,7 +4999,7 @@ fn validateStructInit(...@@ -5000,7 +4999,7 @@ fn validateStructInit(
5000 var block_index = first_block_index;4999 var block_index = first_block_index;
5001 for (block.instructions.items[first_block_index..]) |cur_inst| {5000 for (block.instructions.items[first_block_index..]) |cur_inst| {
5002 while (field_ptr_ref == .none and init_index < instrs.len) : (init_index += 1) {5001 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);
5004 if (try field_ty.onePossibleValue(pt)) |_| continue;5003 if (try field_ty.onePossibleValue(pt)) |_| continue;
5005 field_ptr_ref = sema.inst_map.get(instrs[init_index]).?;5004 field_ptr_ref = sema.inst_map.get(instrs[init_index]).?;
5006 }5005 }
...@@ -5044,7 +5043,7 @@ fn validateStructInit(...@@ -5044,7 +5043,7 @@ fn validateStructInit(
5044 if (field_ptr != .none) continue;5043 if (field_ptr != .none) continue;
50455044
5046 const field_src = init_src; // TODO better source location5045 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))
5048 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)5047 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)
5049 else5048 else
5050 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);5049 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);
...@@ -5060,7 +5059,7 @@ fn zirValidatePtrArrayInit(...@@ -5060,7 +5059,7 @@ fn zirValidatePtrArrayInit(
5060 inst: Zir.Inst.Index,5059 inst: Zir.Inst.Index,
5061) CompileError!void {5060) CompileError!void {
5062 const pt = sema.pt;5061 const pt = sema.pt;
5063 const mod = pt.zcu;5062 const zcu = pt.zcu;
5064 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5063 const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5065 const init_src = block.nodeOffset(validate_inst.src_node);5064 const init_src = block.nodeOffset(validate_inst.src_node);
5066 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);5065 const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index);
...@@ -5068,8 +5067,8 @@ fn zirValidatePtrArrayInit(...@@ -5068,8 +5067,8 @@ fn zirValidatePtrArrayInit(
5068 const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;5067 const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node;
5069 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;5068 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;
5070 const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr);5069 const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr);
5071 const array_ty = sema.typeOf(array_ptr).childType(mod).optEuBaseType(mod);5070 const array_ty = sema.typeOf(array_ptr).childType(zcu).optEuBaseType(zcu);
5072 const array_len = array_ty.arrayLen(mod);5071 const array_len = array_ty.arrayLen(zcu);
50735072
5074 // Collect the comptime element values in case the array literal ends up5073 // Collect the comptime element values in case the array literal ends up
5075 // being comptime-known.5074 // being comptime-known.
...@@ -5078,15 +5077,15 @@ fn zirValidatePtrArrayInit(...@@ -5078,15 +5077,15 @@ fn zirValidatePtrArrayInit(
5078 try sema.usizeCast(block, init_src, array_len),5077 try sema.usizeCast(block, init_src, array_len),
5079 );5078 );
50805079
5081 if (instrs.len != array_len) switch (array_ty.zigTypeTag(mod)) {5080 if (instrs.len != array_len) switch (array_ty.zigTypeTag(zcu)) {
5082 .Struct => {5081 .Struct => {
5083 var root_msg: ?*Module.ErrorMsg = null;5082 var root_msg: ?*Zcu.ErrorMsg = null;
5084 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);5083 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
50855084
5086 try array_ty.resolveStructFieldInits(pt);5085 try array_ty.resolveStructFieldInits(pt);
5087 var i = instrs.len;5086 var i = instrs.len;
5088 while (i < array_len) : (i += 1) {5087 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();
5090 if (default_val == .unreachable_value) {5089 if (default_val == .unreachable_value) {
5091 const template = "missing tuple field with index {d}";5090 const template = "missing tuple field with index {d}";
5092 if (root_msg) |msg| {5091 if (root_msg) |msg| {
...@@ -5125,7 +5124,7 @@ fn zirValidatePtrArrayInit(...@@ -5125,7 +5124,7 @@ fn zirValidatePtrArrayInit(
5125 // at comptime so we have almost nothing to do here. However, in case of a5124 // at comptime so we have almost nothing to do here. However, in case of a
5126 // sentinel-terminated array, the sentinel will not have been populated by5125 // sentinel-terminated array, the sentinel will not have been populated by
5127 // any ZIR instructions at comptime; we need to do that here.5126 // 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| {
5129 const array_len_ref = try pt.intRef(Type.usize, array_len);5128 const array_len_ref = try pt.intRef(Type.usize, array_len);
5130 const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true);5129 const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true);
5131 const sentinel = Air.internedToRef(sentinel_val.toIntern());5130 const sentinel = Air.internedToRef(sentinel_val.toIntern());
...@@ -5150,8 +5149,8 @@ fn zirValidatePtrArrayInit(...@@ -5150,8 +5149,8 @@ fn zirValidatePtrArrayInit(
5150 outer: for (instrs, 0..) |elem_ptr, i| {5149 outer: for (instrs, 0..) |elem_ptr, i| {
5151 // Determine whether the value stored to this pointer is comptime-known.5150 // Determine whether the value stored to this pointer is comptime-known.
51525151
5153 if (array_ty.isTuple(mod)) {5152 if (array_ty.isTuple(zcu)) {
5154 if (array_ty.structFieldIsComptime(i, mod))5153 if (array_ty.structFieldIsComptime(i, zcu))
5155 try array_ty.resolveStructFieldInits(pt);5154 try array_ty.resolveStructFieldInits(pt);
5156 if (try array_ty.structFieldValueComptime(pt, i)) |opv| {5155 if (try array_ty.structFieldValueComptime(pt, i)) |opv| {
5157 element_vals[i] = opv.toIntern();5156 element_vals[i] = opv.toIntern();
...@@ -5216,7 +5215,7 @@ fn zirValidatePtrArrayInit(...@@ -5216,7 +5215,7 @@ fn zirValidatePtrArrayInit(
52165215
5217 if (array_is_comptime) {5216 if (array_is_comptime) {
5218 if (try sema.resolveDefinedValue(block, init_src, array_ptr)) |ptr_val| {5217 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())) {
5220 .ptr => |ptr| switch (ptr.base_addr) {5219 .ptr => |ptr| switch (ptr.base_addr) {
5221 .comptime_field => return, // This store was validated by the individual elem ptrs.5220 .comptime_field => return, // This store was validated by the individual elem ptrs.
5222 else => {},5221 else => {},
...@@ -5232,7 +5231,7 @@ fn zirValidatePtrArrayInit(...@@ -5232,7 +5231,7 @@ fn zirValidatePtrArrayInit(
5232 var block_index = first_block_index;5231 var block_index = first_block_index;
5233 for (block.instructions.items[first_block_index..]) |cur_inst| {5232 for (block.instructions.items[first_block_index..]) |cur_inst| {
5234 while (elem_ptr_ref == .none and elem_index < instrs.len) : (elem_index += 1) {5233 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;
5236 elem_ptr_ref = sema.inst_map.get(instrs[elem_index]).?;5235 elem_ptr_ref = sema.inst_map.get(instrs[elem_index]).?;
5237 }5236 }
5238 switch (air_tags[@intFromEnum(cur_inst)]) {5237 switch (air_tags[@intFromEnum(cur_inst)]) {
...@@ -5266,31 +5265,31 @@ fn zirValidatePtrArrayInit(...@@ -5266,31 +5265,31 @@ fn zirValidatePtrArrayInit(
52665265
5267fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5266fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5268 const pt = sema.pt;5267 const pt = sema.pt;
5269 const mod = pt.zcu;5268 const zcu = pt.zcu;
5270 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;5269 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
5271 const src = block.nodeOffset(inst_data.src_node);5270 const src = block.nodeOffset(inst_data.src_node);
5272 const operand = try sema.resolveInst(inst_data.operand);5271 const operand = try sema.resolveInst(inst_data.operand);
5273 const operand_ty = sema.typeOf(operand);5272 const operand_ty = sema.typeOf(operand);
52745273
5275 if (operand_ty.zigTypeTag(mod) != .Pointer) {5274 if (operand_ty.zigTypeTag(zcu) != .Pointer) {
5276 return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(pt)});5275 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)) {
5278 .One, .C => {},5277 .One, .C => {},
5279 .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(pt)}),5278 .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(pt)}),
5280 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(pt)}),5279 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(pt)}),
5281 }5280 }
52825281
5283 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) {5282 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(zcu))) != null) {
5284 // No need to validate the actual pointer value, we don't need it!5283 // No need to validate the actual pointer value, we don't need it!
5285 return;5284 return;
5286 }5285 }
52875286
5288 const elem_ty = operand_ty.elemType2(mod);5287 const elem_ty = operand_ty.elemType2(zcu);
5289 if (try sema.resolveValue(operand)) |val| {5288 if (try sema.resolveValue(operand)) |val| {
5290 if (val.isUndef(mod)) {5289 if (val.isUndef(zcu)) {
5291 return sema.fail(block, src, "cannot dereference undefined value", .{});5290 return sema.fail(block, src, "cannot dereference undefined value", .{});
5292 }5291 }
5293 } else if (try sema.typeRequiresComptime(elem_ty)) {5292 } else if (try elem_ty.comptimeOnlySema(pt)) {
5294 const msg = msg: {5293 const msg = msg: {
5295 const msg = try sema.errMsg(5294 const msg = try sema.errMsg(
5296 src,5295 src,
...@@ -5308,7 +5307,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -5308,7 +5307,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
53085307
5309fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5308fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5310 const pt = sema.pt;5309 const pt = sema.pt;
5311 const mod = pt.zcu;5310 const zcu = pt.zcu;
5312 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5311 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5313 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;5312 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
5314 const src = block.nodeOffset(inst_data.src_node);5313 const src = block.nodeOffset(inst_data.src_node);
...@@ -5316,9 +5315,9 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -5316,9 +5315,9 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
5316 const operand = try sema.resolveInst(extra.operand);5315 const operand = try sema.resolveInst(extra.operand);
5317 const operand_ty = sema.typeOf(operand);5316 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)) {
5320 .Array, .Vector => true,5319 .Array, .Vector => true,
5321 .Struct => operand_ty.isTuple(mod),5320 .Struct => operand_ty.isTuple(zcu),
5322 else => false,5321 else => false,
5323 };5322 };
53245323
...@@ -5331,11 +5330,11 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -5331,11 +5330,11 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
5331 });5330 });
5332 }5331 }
53335332
5334 if (operand_ty.arrayLen(mod) != extra.expect_len) {5333 if (operand_ty.arrayLen(zcu) != extra.expect_len) {
5335 return sema.failWithOwnedErrorMsg(block, msg: {5334 return sema.failWithOwnedErrorMsg(block, msg: {
5336 const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{5335 const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{
5337 extra.expect_len,5336 extra.expect_len,
5338 operand_ty.arrayLen(mod),5337 operand_ty.arrayLen(zcu),
5339 });5338 });
5340 errdefer msg.destroy(sema.gpa);5339 errdefer msg.destroy(sema.gpa);
5341 try sema.errNote(destructure_src, msg, "result destructured here", .{});5340 try sema.errNote(destructure_src, msg, "result destructured here", .{});
...@@ -5423,7 +5422,7 @@ fn failWithBadUnionFieldAccess(...@@ -5423,7 +5422,7 @@ fn failWithBadUnionFieldAccess(
5423 return sema.failWithOwnedErrorMsg(block, msg);5422 return sema.failWithOwnedErrorMsg(block, msg);
5424}5423}
54255424
5426fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {5425fn addDeclaredHereNote(sema: *Sema, parent: *Zcu.ErrorMsg, decl_ty: Type) !void {
5427 const zcu = sema.pt.zcu;5426 const zcu = sema.pt.zcu;
5428 const src_loc = decl_ty.srcLocOrNull(zcu) orelse return;5427 const src_loc = decl_ty.srcLocOrNull(zcu) orelse return;
5429 const category = switch (decl_ty.zigTypeTag(zcu)) {5428 const category = switch (decl_ty.zigTypeTag(zcu)) {
...@@ -5537,7 +5536,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -5537,7 +5536,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
5537 defer tracy.end();5536 defer tracy.end();
55385537
5539 const pt = sema.pt;5538 const pt = sema.pt;
5540 const mod = pt.zcu;5539 const zcu = pt.zcu;
5541 const zir_tags = sema.code.instructions.items(.tag);5540 const zir_tags = sema.code.instructions.items(.tag);
5542 const zir_datas = sema.code.instructions.items(.data);5541 const zir_datas = sema.code.instructions.items(.data);
5543 const inst_data = zir_datas[@intFromEnum(inst)].pl_node;5542 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...@@ -5556,7 +5555,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
5556 // %b = store(%a, %c)5555 // %b = store(%a, %c)
5557 // Where %c is an error union or error set. In such case we need to add5556 // Where %c is an error union or error set. In such case we need to add
5558 // to the current function's inferred error set, if any.5557 // 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)) {
5560 .ErrorUnion, .ErrorSet => try sema.addToInferredErrorSet(operand),5559 .ErrorUnion, .ErrorSet => try sema.addToInferredErrorSet(operand),
5561 else => {},5560 else => {},
5562 };5561 };
...@@ -5688,9 +5687,9 @@ fn zirCompileLog(...@@ -5688,9 +5687,9 @@ fn zirCompileLog(
5688 extended: Zir.Inst.Extended.InstData,5687 extended: Zir.Inst.Extended.InstData,
5689) CompileError!Air.Inst.Ref {5688) CompileError!Air.Inst.Ref {
5690 const pt = sema.pt;5689 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);
5694 defer pt.zcu.compile_log_text = managed.moveToUnmanaged();5693 defer pt.zcu.compile_log_text = managed.moveToUnmanaged();
5695 const writer = managed.writer();5694 const writer = managed.writer();
56965695
...@@ -5713,7 +5712,7 @@ fn zirCompileLog(...@@ -5713,7 +5712,7 @@ fn zirCompileLog(
5713 }5712 }
5714 try writer.print("\n", .{});5713 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);
5717 if (!gop.found_existing) gop.value_ptr.* = .{5716 if (!gop.found_existing) gop.value_ptr.* = .{
5718 .base_node_inst = block.src_base_inst,5717 .base_node_inst = block.src_base_inst,
5719 .node_offset = src_node,5718 .node_offset = src_node,
...@@ -5749,7 +5748,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5749,7 +5748,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5749 defer tracy.end();5748 defer tracy.end();
57505749
5751 const pt = sema.pt;5750 const pt = sema.pt;
5752 const mod = pt.zcu;5751 const zcu = pt.zcu;
5753 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5752 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5754 const src = parent_block.nodeOffset(inst_data.src_node);5753 const src = parent_block.nodeOffset(inst_data.src_node);
5755 const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index);5754 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...@@ -5800,7 +5799,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5800 try sema.analyzeBodyInner(&loop_block, body);5799 try sema.analyzeBodyInner(&loop_block, body);
58015800
5802 const loop_block_len = loop_block.instructions.items.len;5801 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)) {
5804 // If the loop ended with a noreturn terminator, then there is no way for it to loop,5803 // If the loop ended with a noreturn terminator, then there is no way for it to loop,
5805 // so we can just use the block instead.5804 // so we can just use the block instead.
5806 try child_block.instructions.appendSlice(gpa, loop_block.instructions.items);5805 try child_block.instructions.appendSlice(gpa, loop_block.instructions.items);
...@@ -6069,11 +6068,11 @@ fn resolveAnalyzedBlock(...@@ -6069,11 +6068,11 @@ fn resolveAnalyzedBlock(
60696068
6070 const gpa = sema.gpa;6069 const gpa = sema.gpa;
6071 const pt = sema.pt;6070 const pt = sema.pt;
6072 const mod = pt.zcu;6071 const zcu = pt.zcu;
60736072
6074 // Blocks must terminate with noreturn instruction.6073 // Blocks must terminate with noreturn instruction.
6075 assert(child_block.instructions.items.len != 0);6074 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
6078 const block_tag = sema.air_instructions.items(.tag)[@intFromEnum(merges.block_inst)];6077 const block_tag = sema.air_instructions.items(.tag)[@intFromEnum(merges.block_inst)];
6079 switch (block_tag) {6078 switch (block_tag) {
...@@ -6178,7 +6177,7 @@ fn resolveAnalyzedBlock(...@@ -6178,7 +6177,7 @@ fn resolveAnalyzedBlock(
6178 // TODO add note "missing else causes void value"6177 // TODO add note "missing else causes void value"
61796178
6180 const type_src = src; // TODO: better source location6179 const type_src = src; // TODO: better source location
6181 if (try sema.typeRequiresComptime(resolved_ty)) {6180 if (try resolved_ty.comptimeOnlySema(pt)) {
6182 const msg = msg: {6181 const msg = msg: {
6183 const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(pt)});6182 const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(pt)});
6184 errdefer msg.destroy(sema.gpa);6183 errdefer msg.destroy(sema.gpa);
...@@ -6227,7 +6226,7 @@ fn resolveAnalyzedBlock(...@@ -6227,7 +6226,7 @@ fn resolveAnalyzedBlock(
6227 const br_operand = sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand;6226 const br_operand = sema.air_instructions.items(.data)[@intFromEnum(br)].br.operand;
6228 const br_operand_src = src;6227 const br_operand_src = src;
6229 const br_operand_ty = sema.typeOf(br_operand);6228 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)) {
6231 // No type coercion needed.6230 // No type coercion needed.
6232 continue;6231 continue;
6233 }6232 }
...@@ -6354,7 +6353,7 @@ pub fn analyzeExport(...@@ -6354,7 +6353,7 @@ pub fn analyzeExport(
6354 sema: *Sema,6353 sema: *Sema,
6355 block: *Block,6354 block: *Block,
6356 src: LazySrcLoc,6355 src: LazySrcLoc,
6357 options: Module.Export.Options,6356 options: Zcu.Export.Options,
6358 exported_nav_index: InternPool.Nav.Index,6357 exported_nav_index: InternPool.Nav.Index,
6359) !void {6358) !void {
6360 const gpa = sema.gpa;6359 const gpa = sema.gpa;
...@@ -6427,8 +6426,8 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -6427,8 +6426,8 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
64276426
6428fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {6427fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
6429 const pt = sema.pt;6428 const pt = sema.pt;
6430 const mod = pt.zcu;6429 const zcu = pt.zcu;
6431 const ip = &mod.intern_pool;6430 const ip = &zcu.intern_pool;
6432 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6431 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6433 const operand_src = block.builtinCallArgSrc(extra.node, 0);6432 const operand_src = block.builtinCallArgSrc(extra.node, 0);
6434 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{6433 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)...@@ -6446,8 +6445,8 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
64466445
6447fn zirDisableInstrumentation(sema: *Sema) CompileError!void {6446fn zirDisableInstrumentation(sema: *Sema) CompileError!void {
6448 const pt = sema.pt;6447 const pt = sema.pt;
6449 const mod = pt.zcu;6448 const zcu = pt.zcu;
6450 const ip = &mod.intern_pool;6449 const ip = &zcu.intern_pool;
6451 const func = switch (sema.owner.unwrap()) {6450 const func = switch (sema.owner.unwrap()) {
6452 .func => |func| func,6451 .func => |func| func,
6453 .cau => return, // does nothing outside a function6452 .cau => return, // does nothing outside a function
...@@ -6572,17 +6571,17 @@ fn addDbgVar(...@@ -6572,17 +6571,17 @@ fn addDbgVar(
6572 if (block.is_comptime or block.ownerModule().strip) return;6571 if (block.is_comptime or block.ownerModule().strip) return;
65736572
6574 const pt = sema.pt;6573 const pt = sema.pt;
6575 const mod = pt.zcu;6574 const zcu = pt.zcu;
6576 const operand_ty = sema.typeOf(operand);6575 const operand_ty = sema.typeOf(operand);
6577 const val_ty = switch (air_tag) {6576 const val_ty = switch (air_tag) {
6578 .dbg_var_ptr => operand_ty.childType(mod),6577 .dbg_var_ptr => operand_ty.childType(zcu),
6579 .dbg_var_val, .dbg_arg_inline => operand_ty,6578 .dbg_var_val, .dbg_arg_inline => operand_ty,
6580 else => unreachable,6579 else => unreachable,
6581 };6580 };
6582 if (try sema.typeRequiresComptime(val_ty)) return;6581 if (try val_ty.comptimeOnlySema(pt)) return;
6583 if (!(try sema.typeHasRuntimeBits(val_ty))) return;6582 if (!(try val_ty.hasRuntimeBitsSema(pt))) return;
6584 if (try sema.resolveValue(operand)) |operand_val| {6583 if (try sema.resolveValue(operand)) |operand_val| {
6585 if (operand_val.canMutateComptimeVarState(mod)) return;6584 if (operand_val.canMutateComptimeVarState(zcu)) return;
6586 }6585 }
65876586
6588 // To ensure the lexical scoping is known to backends, this alloc must be6587 // 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...@@ -6619,10 +6618,10 @@ pub fn appendAirString(sema: *Sema, str: []const u8) Allocator.Error!Air.NullTer
66196618
6620fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6619fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6621 const pt = sema.pt;6620 const pt = sema.pt;
6622 const mod = pt.zcu;6621 const zcu = pt.zcu;
6623 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;6622 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
6624 const src = block.tokenOffset(inst_data.src_tok);6623 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(
6626 sema.gpa,6625 sema.gpa,
6627 pt.tid,6626 pt.tid,
6628 inst_data.get(sema.code),6627 inst_data.get(sema.code),
...@@ -6634,10 +6633,10 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -6634,10 +6633,10 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
66346633
6635fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {6634fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
6636 const pt = sema.pt;6635 const pt = sema.pt;
6637 const mod = pt.zcu;6636 const zcu = pt.zcu;
6638 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;6637 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
6639 const src = block.tokenOffset(inst_data.src_tok);6638 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(
6641 sema.gpa,6640 sema.gpa,
6642 pt.tid,6641 pt.tid,
6643 inst_data.get(sema.code),6642 inst_data.get(sema.code),
...@@ -6649,14 +6648,14 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -6649,14 +6648,14 @@ fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
66496648
6650fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !InternPool.Nav.Index {6649fn lookupIdentifier(sema: *Sema, block: *Block, src: LazySrcLoc, name: InternPool.NullTerminatedString) !InternPool.Nav.Index {
6651 const pt = sema.pt;6650 const pt = sema.pt;
6652 const mod = pt.zcu;6651 const zcu = pt.zcu;
6653 var namespace = block.namespace;6652 var namespace = block.namespace;
6654 while (true) {6653 while (true) {
6655 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |lookup| {6654 if (try sema.lookupInNamespace(block, src, namespace, name, false)) |lookup| {
6656 assert(lookup.accessible);6655 assert(lookup.accessible);
6657 return lookup.nav;6656 return lookup.nav;
6658 }6657 }
6659 namespace = mod.namespacePtr(namespace).parent.unwrap() orelse break;6658 namespace = zcu.namespacePtr(namespace).parent.unwrap() orelse break;
6660 }6659 }
6661 unreachable; // AstGen detects use of undeclared identifiers.6660 unreachable; // AstGen detects use of undeclared identifiers.
6662}6661}
...@@ -6801,7 +6800,7 @@ fn funcDeclSrcInst(sema: *Sema, func_inst: Air.Inst.Ref) !?InternPool.TrackedIns...@@ -6801,7 +6800,7 @@ fn funcDeclSrcInst(sema: *Sema, func_inst: Air.Inst.Ref) !?InternPool.TrackedIns
68016800
6802pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref {6801pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref {
6803 const pt = sema.pt;6802 const pt = sema.pt;
6804 const mod = pt.zcu;6803 const zcu = pt.zcu;
6805 const gpa = sema.gpa;6804 const gpa = sema.gpa;
68066805
6807 if (block.is_comptime or block.is_typeof) {6806 if (block.is_comptime or block.is_typeof) {
...@@ -6813,7 +6812,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -6813,7 +6812,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
68136812
6814 const stack_trace_ty = try pt.getBuiltinType("StackTrace");6813 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
6815 try stack_trace_ty.resolveFields(pt);6814 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);
6817 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {6816 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
6818 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),6817 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
6819 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6818 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
...@@ -6839,7 +6838,7 @@ fn popErrorReturnTrace(...@@ -6839,7 +6838,7 @@ fn popErrorReturnTrace(
6839 saved_error_trace_index: Air.Inst.Ref,6838 saved_error_trace_index: Air.Inst.Ref,
6840) CompileError!void {6839) CompileError!void {
6841 const pt = sema.pt;6840 const pt = sema.pt;
6842 const mod = pt.zcu;6841 const zcu = pt.zcu;
6843 const gpa = sema.gpa;6842 const gpa = sema.gpa;
6844 var is_non_error: ?bool = null;6843 var is_non_error: ?bool = null;
6845 var is_non_error_inst: Air.Inst.Ref = undefined;6844 var is_non_error_inst: Air.Inst.Ref = undefined;
...@@ -6857,7 +6856,7 @@ fn popErrorReturnTrace(...@@ -6857,7 +6856,7 @@ fn popErrorReturnTrace(
6857 try stack_trace_ty.resolveFields(pt);6856 try stack_trace_ty.resolveFields(pt);
6858 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);6857 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
6859 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);6858 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);
6861 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true);6860 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, field_name, src, stack_trace_ty, true);
6862 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);6861 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);
6863 } else if (is_non_error == null) {6862 } else if (is_non_error == null) {
...@@ -6883,7 +6882,7 @@ fn popErrorReturnTrace(...@@ -6883,7 +6882,7 @@ fn popErrorReturnTrace(
6883 try stack_trace_ty.resolveFields(pt);6882 try stack_trace_ty.resolveFields(pt);
6884 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);6883 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
6885 const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty);6884 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);
6887 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);6886 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);
6888 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);6887 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
6889 _ = try then_block.addBr(cond_block_inst, .void_value);6888 _ = try then_block.addBr(cond_block_inst, .void_value);
...@@ -6923,7 +6922,7 @@ fn zirCall(...@@ -6923,7 +6922,7 @@ fn zirCall(
6923 defer tracy.end();6922 defer tracy.end();
69246923
6925 const pt = sema.pt;6924 const pt = sema.pt;
6926 const mod = pt.zcu;6925 const zcu = pt.zcu;
6927 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;6926 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
6928 const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node });6927 const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node });
6929 const call_src = block.nodeOffset(inst_data.src_node);6928 const call_src = block.nodeOffset(inst_data.src_node);
...@@ -6942,7 +6941,7 @@ fn zirCall(...@@ -6942,7 +6941,7 @@ fn zirCall(
6942 .direct => .{ .direct = try sema.resolveInst(extra.data.callee) },6941 .direct => .{ .direct = try sema.resolveInst(extra.data.callee) },
6943 .field => blk: {6942 .field => blk: {
6944 const object_ptr = try sema.resolveInst(extra.data.obj_ptr);6943 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(
6946 sema.gpa,6945 sema.gpa,
6947 pt.tid,6946 pt.tid,
6948 sema.code.nullTerminatedString(extra.data.field_name_start),6947 sema.code.nullTerminatedString(extra.data.field_name_start),
...@@ -6987,7 +6986,7 @@ fn zirCall(...@@ -6987,7 +6986,7 @@ fn zirCall(
69876986
6988 switch (sema.owner.unwrap()) {6987 switch (sema.owner.unwrap()) {
6989 .cau => input_is_error = false,6988 .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) {
6991 // No errorable fn actually called; we have no error return trace6990 // No errorable fn actually called; we have no error return trace
6992 input_is_error = false;6991 input_is_error = false;
6993 },6992 },
...@@ -6997,7 +6996,7 @@ fn zirCall(...@@ -6997,7 +6996,7 @@ fn zirCall(
6997 !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace))6996 !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace))
6998 {6997 {
6999 const return_ty = sema.typeOf(call_inst);6998 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))
7001 return call_inst; // call to "fn (...) noreturn", don't pop7000 return call_inst; // call to "fn (...) noreturn", don't pop
70027001
7003 // TODO: we don't fix up the error trace for always_tail correctly, we should be doing it7002 // TODO: we don't fix up the error trace for always_tail correctly, we should be doing it
...@@ -7008,10 +7007,10 @@ fn zirCall(...@@ -7008,10 +7007,10 @@ fn zirCall(
70087007
7009 // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only7008 // If any input is an error-type, we might need to pop any trace it generated. Otherwise, we only
7010 // need to clean-up our own trace if we were passed to a non-error-handling expression.7009 // 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))) {
7012 const stack_trace_ty = try pt.getBuiltinType("StackTrace");7011 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
7013 try stack_trace_ty.resolveFields(pt);7012 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);
7015 const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src);7014 const field_index = try sema.structFieldIndex(block, stack_trace_ty, field_name, call_src);
70167015
7017 // Insert a save instruction before the arg resolution + call instructions we just generated7016 // Insert a save instruction before the arg resolution + call instructions we just generated
...@@ -7044,20 +7043,20 @@ fn checkCallArgumentCount(...@@ -7044,20 +7043,20 @@ fn checkCallArgumentCount(
7044 member_fn: bool,7043 member_fn: bool,
7045) !Type {7044) !Type {
7046 const pt = sema.pt;7045 const pt = sema.pt;
7047 const mod = pt.zcu;7046 const zcu = pt.zcu;
7048 const func_ty = func_ty: {7047 const func_ty = func_ty: {
7049 switch (callee_ty.zigTypeTag(mod)) {7048 switch (callee_ty.zigTypeTag(zcu)) {
7050 .Fn => break :func_ty callee_ty,7049 .Fn => break :func_ty callee_ty,
7051 .Pointer => {7050 .Pointer => {
7052 const ptr_info = callee_ty.ptrInfo(mod);7051 const ptr_info = callee_ty.ptrInfo(zcu);
7053 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {7052 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Fn) {
7054 break :func_ty Type.fromInterned(ptr_info.child);7053 break :func_ty Type.fromInterned(ptr_info.child);
7055 }7054 }
7056 },7055 },
7057 .Optional => {7056 .Optional => {
7058 const opt_child = callee_ty.optionalChild(mod);7057 const opt_child = callee_ty.optionalChild(zcu);
7059 if (opt_child.zigTypeTag(mod) == .Fn or (opt_child.isSinglePointer(mod) and7058 if (opt_child.zigTypeTag(zcu) == .Fn or (opt_child.isSinglePointer(zcu) and
7060 opt_child.childType(mod).zigTypeTag(mod) == .Fn))7059 opt_child.childType(zcu).zigTypeTag(zcu) == .Fn))
7061 {7060 {
7062 const msg = msg: {7061 const msg = msg: {
7063 const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{7062 const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{
...@@ -7075,7 +7074,7 @@ fn checkCallArgumentCount(...@@ -7075,7 +7074,7 @@ fn checkCallArgumentCount(
7075 return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(pt)});7074 return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(pt)});
7076 };7075 };
70777076
7078 const func_ty_info = mod.typeToFunc(func_ty).?;7077 const func_ty_info = zcu.typeToFunc(func_ty).?;
7079 const fn_params_len = func_ty_info.param_types.len;7078 const fn_params_len = func_ty_info.param_types.len;
7080 const args_len = total_args - @intFromBool(member_fn);7079 const args_len = total_args - @intFromBool(member_fn);
7081 if (func_ty_info.is_var_args) {7080 if (func_ty_info.is_var_args) {
...@@ -7122,14 +7121,14 @@ fn callBuiltin(...@@ -7122,14 +7121,14 @@ fn callBuiltin(
7122 operation: CallOperation,7121 operation: CallOperation,
7123) !void {7122) !void {
7124 const pt = sema.pt;7123 const pt = sema.pt;
7125 const mod = pt.zcu;7124 const zcu = pt.zcu;
7126 const callee_ty = sema.typeOf(builtin_fn);7125 const callee_ty = sema.typeOf(builtin_fn);
7127 const func_ty = func_ty: {7126 const func_ty = func_ty: {
7128 switch (callee_ty.zigTypeTag(mod)) {7127 switch (callee_ty.zigTypeTag(zcu)) {
7129 .Fn => break :func_ty callee_ty,7128 .Fn => break :func_ty callee_ty,
7130 .Pointer => {7129 .Pointer => {
7131 const ptr_info = callee_ty.ptrInfo(mod);7130 const ptr_info = callee_ty.ptrInfo(zcu);
7132 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {7131 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Fn) {
7133 break :func_ty Type.fromInterned(ptr_info.child);7132 break :func_ty Type.fromInterned(ptr_info.child);
7134 }7133 }
7135 },7134 },
...@@ -7138,7 +7137,7 @@ fn callBuiltin(...@@ -7138,7 +7137,7 @@ fn callBuiltin(
7138 std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(pt)});7137 std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(pt)});
7139 };7138 };
71407139
7141 const func_ty_info = mod.typeToFunc(func_ty).?;7140 const func_ty_info = zcu.typeToFunc(func_ty).?;
7142 const fn_params_len = func_ty_info.param_types.len;7141 const fn_params_len = func_ty_info.param_types.len;
7143 if (args.len != fn_params_len or (func_ty_info.is_var_args and args.len < fn_params_len)) {7142 if (args.len != fn_params_len or (func_ty_info.is_var_args and args.len < fn_params_len)) {
7144 std.debug.panic("parameter count mismatch calling builtin fn, expected {d}, found {d}", .{ fn_params_len, args.len });7143 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) {...@@ -7242,7 +7241,7 @@ const CallArgsInfo = union(enum) {
7242 func_inst: Air.Inst.Ref,7241 func_inst: Air.Inst.Ref,
7243 ) CompileError!Air.Inst.Ref {7242 ) CompileError!Air.Inst.Ref {
7244 const pt = sema.pt;7243 const pt = sema.pt;
7245 const mod = pt.zcu;7244 const zcu = pt.zcu;
7246 const param_count = func_ty_info.param_types.len;7245 const param_count = func_ty_info.param_types.len;
7247 const uncoerced_arg: Air.Inst.Ref = switch (cai) {7246 const uncoerced_arg: Air.Inst.Ref = switch (cai) {
7248 inline .resolved, .call_builtin => |resolved| resolved.args[arg_index],7247 inline .resolved, .call_builtin => |resolved| resolved.args[arg_index],
...@@ -7277,13 +7276,13 @@ const CallArgsInfo = union(enum) {...@@ -7277,13 +7276,13 @@ const CallArgsInfo = union(enum) {
7277 // Resolve the arg!7276 // Resolve the arg!
7278 const uncoerced_arg = try sema.resolveInlineBody(block, arg_body, zir_call.call_inst);7277 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) {
7281 // This terminates resolution of arguments. The caller should7280 // This terminates resolution of arguments. The caller should
7282 // propagate this.7281 // propagate this.
7283 return uncoerced_arg;7282 return uncoerced_arg;
7284 }7283 }
72857284
7286 if (sema.typeOf(uncoerced_arg).isError(mod)) {7285 if (sema.typeOf(uncoerced_arg).isError(zcu)) {
7287 zir_call.any_arg_is_error.* = true;7286 zir_call.any_arg_is_error.* = true;
7288 }7287 }
72897288
...@@ -7476,7 +7475,7 @@ fn analyzeCall(...@@ -7476,7 +7475,7 @@ fn analyzeCall(
7476 var is_inline_call = is_comptime_call or modifier == .always_inline or func_ty_info.cc == .Inline;7475 var is_inline_call = is_comptime_call or modifier == .always_inline or func_ty_info.cc == .Inline;
7477 var comptime_reason: ?*const Block.ComptimeReason = null;7476 var comptime_reason: ?*const Block.ComptimeReason = null;
7478 if (!is_inline_call and !is_comptime_call) {7477 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)) {
7480 is_comptime_call = true;7479 is_comptime_call = true;
7481 is_inline_call = true;7480 is_inline_call = true;
7482 comptime_reason = &.{ .comptime_ret_ty = .{7481 comptime_reason = &.{ .comptime_ret_ty = .{
...@@ -7968,8 +7967,8 @@ fn analyzeInlineCallArg(...@@ -7968,8 +7967,8 @@ fn analyzeInlineCallArg(
7968 func_ty_info: InternPool.Key.FuncType,7967 func_ty_info: InternPool.Key.FuncType,
7969 func_inst: Air.Inst.Ref,7968 func_inst: Air.Inst.Ref,
7970) !?Air.Inst.Ref {7969) !?Air.Inst.Ref {
7971 const mod = ics.sema.pt.zcu;7970 const zcu = ics.sema.pt.zcu;
7972 const ip = &mod.intern_pool;7971 const ip = &zcu.intern_pool;
7973 const zir_tags = ics.callee().code.instructions.items(.tag);7972 const zir_tags = ics.callee().code.instructions.items(.tag);
7974 switch (zir_tags[@intFromEnum(inst)]) {7973 switch (zir_tags[@intFromEnum(inst)]) {
7975 .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true,7974 .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true,
...@@ -7992,11 +7991,11 @@ fn analyzeInlineCallArg(...@@ -7992,11 +7991,11 @@ fn analyzeInlineCallArg(
7992 };7991 };
7993 new_param_types[arg_i.*] = param_ty;7992 new_param_types[arg_i.*] = param_ty;
7994 const casted_arg = try args_info.analyzeArg(ics.caller(), arg_block, arg_i.*, Type.fromInterned(param_ty), func_ty_info, func_inst);7993 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) {
7996 return casted_arg;7995 return casted_arg;
7997 }7996 }
7998 const arg_src = args_info.argSrc(arg_block, arg_i.*);7997 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)) {
8000 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{7999 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
8001 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",8000 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
8002 .block_comptime_reason = param_block.comptime_reason,8001 .block_comptime_reason = param_block.comptime_reason,
...@@ -8025,7 +8024,7 @@ fn analyzeInlineCallArg(...@@ -8025,7 +8024,7 @@ fn analyzeInlineCallArg(
8025 // assertion due to type not being resolved8024 // assertion due to type not being resolved
8026 // when the hash function is called.8025 // when the hash function is called.
8027 const resolved_arg_val = try ics.caller().resolveLazyValue(arg_val);8026 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);
8029 memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern();8028 memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern();
8030 } else {8029 } else {
8031 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);8030 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
...@@ -8040,7 +8039,7 @@ fn analyzeInlineCallArg(...@@ -8040,7 +8039,7 @@ fn analyzeInlineCallArg(
8040 .param_anytype, .param_anytype_comptime => {8039 .param_anytype, .param_anytype_comptime => {
8041 // No coercion needed.8040 // No coercion needed.
8042 const uncasted_arg = try args_info.analyzeArg(ics.caller(), arg_block, arg_i.*, Type.generic_poison, func_ty_info, func_inst);8041 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) {
8044 return uncasted_arg;8043 return uncasted_arg;
8045 }8044 }
8046 const arg_src = args_info.argSrc(arg_block, arg_i.*);8045 const arg_src = args_info.argSrc(arg_block, arg_i.*);
...@@ -8064,7 +8063,7 @@ fn analyzeInlineCallArg(...@@ -8064,7 +8063,7 @@ fn analyzeInlineCallArg(
8064 // assertion due to type not being resolved8063 // assertion due to type not being resolved
8065 // when the hash function is called.8064 // when the hash function is called.
8066 const resolved_arg_val = try ics.caller().resolveLazyValue(arg_val);8065 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);
8068 memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern();8067 memoized_arg_values[arg_i.*] = resolved_arg_val.toIntern();
8069 } else {8068 } else {
8070 if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) {8069 if (zir_tags[@intFromEnum(inst)] == .param_anytype_comptime) {
...@@ -8236,7 +8235,7 @@ fn instantiateGenericCall(...@@ -8236,7 +8235,7 @@ fn instantiateGenericCall(
82368235
8237 const arg_is_comptime = switch (param_tag) {8236 const arg_is_comptime = switch (param_tag) {
8238 .param_comptime, .param_anytype_comptime => true,8237 .param_comptime, .param_anytype_comptime => true,
8239 .param, .param_anytype => try sema.typeRequiresComptime(arg_ty),8238 .param, .param_anytype => try arg_ty.comptimeOnlySema(pt),
8240 else => unreachable,8239 else => unreachable,
8241 };8240 };
82428241
...@@ -8325,7 +8324,7 @@ fn instantiateGenericCall(...@@ -8325,7 +8324,7 @@ fn instantiateGenericCall(
83258324
8326 // If the call evaluated to a return type that requires comptime, never mind8325 // If the call evaluated to a return type that requires comptime, never mind
8327 // our generic instantiation. Instead we need to perform a comptime call.8326 // 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)) {
8329 return error.ComptimeReturn;8328 return error.ComptimeReturn;
8330 }8329 }
8331 // Similarly, if the call evaluated to a generic type we need to instead8330 // Similarly, if the call evaluated to a generic type we need to instead
...@@ -8376,8 +8375,8 @@ fn instantiateGenericCall(...@@ -8376,8 +8375,8 @@ fn instantiateGenericCall(
83768375
8377fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {8376fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
8378 const pt = sema.pt;8377 const pt = sema.pt;
8379 const mod = pt.zcu;8378 const zcu = pt.zcu;
8380 const ip = &mod.intern_pool;8379 const ip = &zcu.intern_pool;
8381 const tuple = switch (ip.indexToKey(ty.toIntern())) {8380 const tuple = switch (ip.indexToKey(ty.toIntern())) {
8382 .anon_struct_type => |tuple| tuple,8381 .anon_struct_type => |tuple| tuple,
8383 else => return,8382 else => return,
...@@ -8401,13 +8400,13 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8401,13 +8400,13 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
8401 defer tracy.end();8400 defer tracy.end();
84028401
8403 const pt = sema.pt;8402 const pt = sema.pt;
8404 const mod = pt.zcu;8403 const zcu = pt.zcu;
8405 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8404 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8406 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });8405 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
8407 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);8406 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) {
8409 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(pt)});8408 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) {
8411 return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(pt)});8410 return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(pt)});
8412 }8411 }
8413 const opt_type = try pt.optionalType(child_type.toIntern());8412 const opt_type = try pt.optionalType(child_type.toIntern());
...@@ -8417,7 +8416,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8417,7 +8416,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
84178416
8418fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8417fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8419 const pt = sema.pt;8418 const pt = sema.pt;
8420 const mod = pt.zcu;8419 const zcu = pt.zcu;
8421 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;8420 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
8422 const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) {8421 const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) {
8423 // Since this is a ZIR instruction that returns a type, encountering8422 // 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...@@ -8427,40 +8426,40 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
8427 error.GenericPoison => return .generic_poison_type,8426 error.GenericPoison => return .generic_poison_type,
8428 else => |e| return e,8427 else => |e| return e,
8429 };8428 };
8430 const indexable_ty = maybe_wrapped_indexable_ty.optEuBaseType(mod);8429 const indexable_ty = maybe_wrapped_indexable_ty.optEuBaseType(zcu);
8431 try indexable_ty.resolveFields(pt);8430 try indexable_ty.resolveFields(pt);
8432 assert(indexable_ty.isIndexable(mod)); // validated by a previous instruction8431 assert(indexable_ty.isIndexable(zcu)); // validated by a previous instruction
8433 if (indexable_ty.zigTypeTag(mod) == .Struct) {8432 if (indexable_ty.zigTypeTag(zcu) == .Struct) {
8434 const elem_type = indexable_ty.structFieldType(@intFromEnum(bin.rhs), mod);8433 const elem_type = indexable_ty.fieldType(@intFromEnum(bin.rhs), zcu);
8435 return Air.internedToRef(elem_type.toIntern());8434 return Air.internedToRef(elem_type.toIntern());
8436 } else {8435 } else {
8437 const elem_type = indexable_ty.elemType2(mod);8436 const elem_type = indexable_ty.elemType2(zcu);
8438 return Air.internedToRef(elem_type.toIntern());8437 return Air.internedToRef(elem_type.toIntern());
8439 }8438 }
8440}8439}
84418440
8442fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8441fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8443 const pt = sema.pt;8442 const pt = sema.pt;
8444 const mod = pt.zcu;8443 const zcu = pt.zcu;
8445 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8444 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8446 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {8445 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
8447 error.GenericPoison => return .generic_poison_type,8446 error.GenericPoison => return .generic_poison_type,
8448 else => |e| return e,8447 else => |e| return e,
8449 };8448 };
8450 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(mod);8449 const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu);
8451 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction8450 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
8452 const elem_ty = ptr_ty.childType(mod);8451 const elem_ty = ptr_ty.childType(zcu);
8453 if (elem_ty.toIntern() == .anyopaque_type) {8452 if (elem_ty.toIntern() == .anyopaque_type) {
8454 // The pointer's actual child type is effectively unknown, so it makes8453 // The pointer's actual child type is effectively unknown, so it makes
8455 // sense to represent it with a generic poison.8454 // sense to represent it with a generic poison.
8456 return .generic_poison_type;8455 return .generic_poison_type;
8457 }8456 }
8458 return Air.internedToRef(ptr_ty.childType(mod).toIntern());8457 return Air.internedToRef(ptr_ty.childType(zcu).toIntern());
8459}8458}
84608459
8461fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8460fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8462 const pt = sema.pt;8461 const pt = sema.pt;
8463 const mod = pt.zcu;8462 const zcu = pt.zcu;
8464 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8463 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8465 const src = block.nodeOffset(un_node.src_node);8464 const src = block.nodeOffset(un_node.src_node);
8466 const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) {8465 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...@@ -8468,16 +8467,16 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
8468 else => |e| return e,8467 else => |e| return e,
8469 };8468 };
8470 try sema.checkMemOperand(block, src, ptr_ty);8469 try sema.checkMemOperand(block, src, ptr_ty);
8471 const elem_ty = switch (ptr_ty.ptrSize(mod)) {8470 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
8472 .Slice, .Many, .C => ptr_ty.childType(mod),8471 .Slice, .Many, .C => ptr_ty.childType(zcu),
8473 .One => ptr_ty.childType(mod).childType(mod),8472 .One => ptr_ty.childType(zcu).childType(zcu),
8474 };8473 };
8475 return Air.internedToRef(elem_ty.toIntern());8474 return Air.internedToRef(elem_ty.toIntern());
8476}8475}
84778476
8478fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8477fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8479 const pt = sema.pt;8478 const pt = sema.pt;
8480 const mod = pt.zcu;8479 const zcu = pt.zcu;
8481 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8480 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8482 const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {8481 const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
8483 // Since this is a ZIR instruction that returns a type, encountering8482 // 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...@@ -8487,10 +8486,10 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8487 error.GenericPoison => return .generic_poison_type,8486 error.GenericPoison => return .generic_poison_type,
8488 else => |e| return e,8487 else => |e| return e,
8489 };8488 };
8490 if (!vec_ty.isVector(mod)) {8489 if (!vec_ty.isVector(zcu)) {
8491 return sema.fail(block, block.nodeOffset(un_node.src_node), "expected vector type, found '{}'", .{vec_ty.fmt(pt)});8490 return sema.fail(block, block.nodeOffset(un_node.src_node), "expected vector type, found '{}'", .{vec_ty.fmt(pt)});
8492 }8491 }
8493 return Air.internedToRef(vec_ty.childType(mod).toIntern());8492 return Air.internedToRef(vec_ty.childType(zcu).toIntern());
8494}8493}
84958494
8496fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8495fn 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...@@ -8561,10 +8560,10 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
85618560
8562fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void {8561fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void {
8563 const pt = sema.pt;8562 const pt = sema.pt;
8564 const mod = pt.zcu;8563 const zcu = pt.zcu;
8565 if (elem_type.zigTypeTag(mod) == .Opaque) {8564 if (elem_type.zigTypeTag(zcu) == .Opaque) {
8566 return sema.fail(block, elem_src, "array of opaque type '{}' not allowed", .{elem_type.fmt(pt)});8565 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) {
8568 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});8567 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});
8569 }8568 }
8570}8569}
...@@ -8577,10 +8576,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8577,10 +8576,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
8577 if (true) {8576 if (true) {
8578 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));8577 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));
8579 }8578 }
8580 const mod = sema.mod;8579 const zcu = sema.zcu;
8581 const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node });8580 const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node });
8582 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);8581 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
8585 return Air.internedToRef(anyframe_type.toIntern());8584 return Air.internedToRef(anyframe_type.toIntern());
8586}8585}
...@@ -8590,7 +8589,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8590,7 +8589,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8590 defer tracy.end();8589 defer tracy.end();
85918590
8592 const pt = sema.pt;8591 const pt = sema.pt;
8593 const mod = pt.zcu;8592 const zcu = pt.zcu;
8594 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8593 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8595 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8594 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8596 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });8595 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...@@ -8598,7 +8597,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8598 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);8597 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);
8599 const payload = try sema.resolveType(block, rhs_src, extra.rhs);8598 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) {
8602 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{8601 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{
8603 error_set.fmt(pt),8602 error_set.fmt(pt),
8604 });8603 });
...@@ -8610,12 +8609,12 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8610,12 +8609,12 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
86108609
8611fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, payload_src: LazySrcLoc) !void {8610fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, payload_src: LazySrcLoc) !void {
8612 const pt = sema.pt;8611 const pt = sema.pt;
8613 const mod = pt.zcu;8612 const zcu = pt.zcu;
8614 if (payload_ty.zigTypeTag(mod) == .Opaque) {8613 if (payload_ty.zigTypeTag(zcu) == .Opaque) {
8615 return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{8614 return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{
8616 payload_ty.fmt(pt),8615 payload_ty.fmt(pt),
8617 });8616 });
8618 } else if (payload_ty.zigTypeTag(mod) == .ErrorSet) {8617 } else if (payload_ty.zigTypeTag(zcu) == .ErrorSet) {
8619 return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{8618 return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{
8620 payload_ty.fmt(pt),8619 payload_ty.fmt(pt),
8621 });8620 });
...@@ -8646,8 +8645,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8646,8 +8645,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8646 defer tracy.end();8645 defer tracy.end();
86478646
8648 const pt = sema.pt;8647 const pt = sema.pt;
8649 const mod = pt.zcu;8648 const zcu = pt.zcu;
8650 const ip = &mod.intern_pool;8649 const ip = &zcu.intern_pool;
8651 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;8650 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8652 const src = block.nodeOffset(extra.node);8651 const src = block.nodeOffset(extra.node);
8653 const operand_src = block.builtinCallArgSrc(extra.node, 0);8652 const operand_src = block.builtinCallArgSrc(extra.node, 0);
...@@ -8656,7 +8655,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8656,7 +8655,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8656 const err_int_ty = try pt.errorIntType();8655 const err_int_ty = try pt.errorIntType();
86578656
8658 if (try sema.resolveValue(operand)) |val| {8657 if (try sema.resolveValue(operand)) |val| {
8659 if (val.isUndef(mod)) {8658 if (val.isUndef(zcu)) {
8660 return pt.undefRef(err_int_ty);8659 return pt.undefRef(err_int_ty);
8661 }8660 }
8662 const err_name = ip.indexToKey(val.toIntern()).err.name;8661 const err_name = ip.indexToKey(val.toIntern()).err.name;
...@@ -8688,8 +8687,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8688,8 +8687,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8688 defer tracy.end();8687 defer tracy.end();
86898688
8690 const pt = sema.pt;8689 const pt = sema.pt;
8691 const mod = pt.zcu;8690 const zcu = pt.zcu;
8692 const ip = &mod.intern_pool;8691 const ip = &zcu.intern_pool;
8693 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;8692 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8694 const src = block.nodeOffset(extra.node);8693 const src = block.nodeOffset(extra.node);
8695 const operand_src = block.builtinCallArgSrc(extra.node, 0);8694 const operand_src = block.builtinCallArgSrc(extra.node, 0);
...@@ -8733,8 +8732,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8733,8 +8732,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8733 defer tracy.end();8732 defer tracy.end();
87348733
8735 const pt = sema.pt;8734 const pt = sema.pt;
8736 const mod = pt.zcu;8735 const zcu = pt.zcu;
8737 const ip = &mod.intern_pool;8736 const ip = &zcu.intern_pool;
8738 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8737 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8739 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8738 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8740 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });8739 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...@@ -8742,7 +8741,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8742 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });8741 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
8743 const lhs = try sema.resolveInst(extra.lhs);8742 const lhs = try sema.resolveInst(extra.lhs);
8744 const rhs = try sema.resolveInst(extra.rhs);8743 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) {
8746 const msg = msg: {8745 const msg = msg: {
8747 const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{});8746 const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{});
8748 errdefer msg.destroy(sema.gpa);8747 errdefer msg.destroy(sema.gpa);
...@@ -8753,9 +8752,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8753,9 +8752,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8753 }8752 }
8754 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);8753 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);
8755 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);8754 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);
8756 if (lhs_ty.zigTypeTag(mod) != .ErrorSet)8755 if (lhs_ty.zigTypeTag(zcu) != .ErrorSet)
8757 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{lhs_ty.fmt(pt)});8756 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)
8759 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(pt)});8758 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(pt)});
87608759
8761 // Anything merged with anyerror is anyerror.8760 // Anything merged with anyerror is anyerror.
...@@ -8790,28 +8789,28 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8790,28 +8789,28 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8790 defer tracy.end();8789 defer tracy.end();
87918790
8792 const pt = sema.pt;8791 const pt = sema.pt;
8793 const mod = pt.zcu;8792 const zcu = pt.zcu;
8794 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;8793 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
8795 const name = inst_data.get(sema.code);8794 const name = inst_data.get(sema.code);
8796 return Air.internedToRef((try pt.intern(.{8795 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),
8798 })));8797 })));
8799}8798}
88008799
8801fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8800fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8802 const pt = sema.pt;8801 const pt = sema.pt;
8803 const mod = pt.zcu;8802 const zcu = pt.zcu;
8804 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8803 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8805 const src = block.nodeOffset(inst_data.src_node);8804 const src = block.nodeOffset(inst_data.src_node);
8806 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);8805 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8807 const operand = try sema.resolveInst(inst_data.operand);8806 const operand = try sema.resolveInst(inst_data.operand);
8808 const operand_ty = sema.typeOf(operand);8807 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)) {
8811 .Enum => operand,8810 .Enum => operand,
8812 .Union => blk: {8811 .Union => blk: {
8813 try operand_ty.resolveFields(pt);8812 try operand_ty.resolveFields(pt);
8814 const tag_ty = operand_ty.unionTagType(mod) orelse {8813 const tag_ty = operand_ty.unionTagType(zcu) orelse {
8815 return sema.fail(8814 return sema.fail(
8816 block,8815 block,
8817 operand_src,8816 operand_src,
...@@ -8829,11 +8828,11 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8829,11 +8828,11 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8829 },8828 },
8830 };8829 };
8831 const enum_tag_ty = sema.typeOf(enum_tag);8830 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
8834 // TODO: use correct solution8833 // TODO: use correct solution
8835 // https://github.com/ziglang/zig/issues/159098834 // 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)) {
8837 return sema.fail(block, operand_src, "cannot use @intFromEnum on empty enum '{}'", .{8836 return sema.fail(block, operand_src, "cannot use @intFromEnum on empty enum '{}'", .{
8838 enum_tag_ty.fmt(pt),8837 enum_tag_ty.fmt(pt),
8839 });8838 });
...@@ -8844,7 +8843,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8844,7 +8843,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8844 }8843 }
88458844
8846 if (try sema.resolveValue(enum_tag)) |enum_tag_val| {8845 if (try sema.resolveValue(enum_tag)) |enum_tag_val| {
8847 if (enum_tag_val.isUndef(mod)) {8846 if (enum_tag_val.isUndef(zcu)) {
8848 return pt.undefRef(int_tag_ty);8847 return pt.undefRef(int_tag_ty);
8849 }8848 }
88508849
...@@ -8858,7 +8857,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8858,7 +8857,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
88588857
8859fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8858fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8860 const pt = sema.pt;8859 const pt = sema.pt;
8861 const mod = pt.zcu;8860 const zcu = pt.zcu;
8862 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8861 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8863 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8862 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8864 const src = block.nodeOffset(inst_data.src_node);8863 const src = block.nodeOffset(inst_data.src_node);
...@@ -8866,14 +8865,14 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8866,14 +8865,14 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8866 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");8865 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
8867 const operand = try sema.resolveInst(extra.rhs);8866 const operand = try sema.resolveInst(extra.rhs);
88688867
8869 if (dest_ty.zigTypeTag(mod) != .Enum) {8868 if (dest_ty.zigTypeTag(zcu) != .Enum) {
8870 return sema.fail(block, src, "expected enum, found '{}'", .{dest_ty.fmt(pt)});8869 return sema.fail(block, src, "expected enum, found '{}'", .{dest_ty.fmt(pt)});
8871 }8870 }
8872 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));8871 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
88738872
8874 if (try sema.resolveValue(operand)) |int_val| {8873 if (try sema.resolveValue(operand)) |int_val| {
8875 if (dest_ty.isNonexhaustiveEnum(mod)) {8874 if (dest_ty.isNonexhaustiveEnum(zcu)) {
8876 const int_tag_ty = dest_ty.intTagType(mod);8875 const int_tag_ty = dest_ty.intTagType(zcu);
8877 if (try sema.intFitsInType(int_val, int_tag_ty, null)) {8876 if (try sema.intFitsInType(int_val, int_tag_ty, null)) {
8878 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());8877 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
8879 }8878 }
...@@ -8881,7 +8880,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8881,7 +8880,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8881 int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt),8880 int_val.fmtValueSema(pt, sema), dest_ty.fmt(pt),
8882 });8881 });
8883 }8882 }
8884 if (int_val.isUndef(mod)) {8883 if (int_val.isUndef(zcu)) {
8885 return sema.failWithUseOfUndef(block, operand_src);8884 return sema.failWithUseOfUndef(block, operand_src);
8886 }8885 }
8887 if (!(try sema.enumHasInt(dest_ty, int_val))) {8886 if (!(try sema.enumHasInt(dest_ty, int_val))) {
...@@ -8892,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8892,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8892 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());8891 return Air.internedToRef((try pt.getCoerced(int_val, dest_ty)).toIntern());
8893 }8892 }
88948893
8895 if (dest_ty.intTagType(mod).zigTypeTag(mod) == .ComptimeInt) {8894 if (dest_ty.intTagType(zcu).zigTypeTag(zcu) == .ComptimeInt) {
8896 return sema.failWithNeededComptime(block, operand_src, .{8895 return sema.failWithNeededComptime(block, operand_src, .{
8897 .needed_comptime_reason = "value being casted to enum with 'comptime_int' tag type must be comptime-known",8896 .needed_comptime_reason = "value being casted to enum with 'comptime_int' tag type must be comptime-known",
8898 });8897 });
...@@ -8909,8 +8908,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8909,8 +8908,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
89098908
8910 try sema.requireRuntimeBlock(block, src, operand_src);8909 try sema.requireRuntimeBlock(block, src, operand_src);
8911 const result = try block.addTyOp(.intcast, dest_ty, operand);8910 const result = try block.addTyOp(.intcast, dest_ty, operand);
8912 if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(mod) and8911 if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(zcu) and
8913 mod.backendSupportsFeature(.is_named_enum_value))8912 zcu.backendSupportsFeature(.is_named_enum_value))
8914 {8913 {
8915 const ok = try block.addUnOp(.is_named_enum_value, result);8914 const ok = try block.addUnOp(.is_named_enum_value, result);
8916 try sema.addSafetyCheck(block, src, ok, .invalid_enum_value);8915 try sema.addSafetyCheck(block, src, ok, .invalid_enum_value);
...@@ -9014,20 +9013,20 @@ fn zirOptionalPayload(...@@ -9014,20 +9013,20 @@ fn zirOptionalPayload(
9014 defer tracy.end();9013 defer tracy.end();
90159014
9016 const pt = sema.pt;9015 const pt = sema.pt;
9017 const mod = pt.zcu;9016 const zcu = pt.zcu;
9018 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;9017 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9019 const src = block.nodeOffset(inst_data.src_node);9018 const src = block.nodeOffset(inst_data.src_node);
9020 const operand = try sema.resolveInst(inst_data.operand);9019 const operand = try sema.resolveInst(inst_data.operand);
9021 const operand_ty = sema.typeOf(operand);9020 const operand_ty = sema.typeOf(operand);
9022 const result_ty = switch (operand_ty.zigTypeTag(mod)) {9021 const result_ty = switch (operand_ty.zigTypeTag(zcu)) {
9023 .Optional => operand_ty.optionalChild(mod),9022 .Optional => operand_ty.optionalChild(zcu),
9024 .Pointer => t: {9023 .Pointer => t: {
9025 if (operand_ty.ptrSize(mod) != .C) {9024 if (operand_ty.ptrSize(zcu) != .C) {
9026 return sema.failWithExpectedOptionalType(block, src, operand_ty);9025 return sema.failWithExpectedOptionalType(block, src, operand_ty);
9027 }9026 }
9028 // TODO https://github.com/ziglang/zig/issues/65979027 // TODO https://github.com/ziglang/zig/issues/6597
9029 if (true) break :t operand_ty;9028 if (true) break :t operand_ty;
9030 const ptr_info = operand_ty.ptrInfo(mod);9029 const ptr_info = operand_ty.ptrInfo(zcu);
9031 break :t try pt.ptrTypeSema(.{9030 break :t try pt.ptrTypeSema(.{
9032 .child = ptr_info.child,9031 .child = ptr_info.child,
9033 .flags = .{9032 .flags = .{
...@@ -9043,7 +9042,7 @@ fn zirOptionalPayload(...@@ -9043,7 +9042,7 @@ fn zirOptionalPayload(
9043 };9042 };
90449043
9045 if (try sema.resolveDefinedValue(block, src, operand)) |val| {9044 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
9046 return if (val.optionalValue(mod)) |payload|9045 return if (val.optionalValue(zcu)) |payload|
9047 Air.internedToRef(payload.toIntern())9046 Air.internedToRef(payload.toIntern())
9048 else9047 else
9049 sema.fail(block, src, "unable to unwrap null", .{});9048 sema.fail(block, src, "unable to unwrap null", .{});
...@@ -9067,13 +9066,13 @@ fn zirErrUnionPayload(...@@ -9067,13 +9066,13 @@ fn zirErrUnionPayload(
9067 defer tracy.end();9066 defer tracy.end();
90689067
9069 const pt = sema.pt;9068 const pt = sema.pt;
9070 const mod = pt.zcu;9069 const zcu = pt.zcu;
9071 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;9070 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
9072 const src = block.nodeOffset(inst_data.src_node);9071 const src = block.nodeOffset(inst_data.src_node);
9073 const operand = try sema.resolveInst(inst_data.operand);9072 const operand = try sema.resolveInst(inst_data.operand);
9074 const operand_src = src;9073 const operand_src = src;
9075 const err_union_ty = sema.typeOf(operand);9074 const err_union_ty = sema.typeOf(operand);
9076 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {9075 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
9077 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{9076 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{
9078 err_union_ty.fmt(pt),9077 err_union_ty.fmt(pt),
9079 });9078 });
...@@ -9091,20 +9090,20 @@ fn analyzeErrUnionPayload(...@@ -9091,20 +9090,20 @@ fn analyzeErrUnionPayload(
9091 safety_check: bool,9090 safety_check: bool,
9092) CompileError!Air.Inst.Ref {9091) CompileError!Air.Inst.Ref {
9093 const pt = sema.pt;9092 const pt = sema.pt;
9094 const mod = pt.zcu;9093 const zcu = pt.zcu;
9095 const payload_ty = err_union_ty.errorUnionPayload(mod);9094 const payload_ty = err_union_ty.errorUnionPayload(zcu);
9096 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {9095 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
9097 if (val.getErrorName(mod).unwrap()) |name| {9096 if (val.getErrorName(zcu).unwrap()) |name| {
9098 return sema.failWithComptimeErrorRetTrace(block, src, name);9097 return sema.failWithComptimeErrorRetTrace(block, src, name);
9099 }9098 }
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);
9101 }9100 }
91029101
9103 try sema.requireRuntimeBlock(block, src, null);9102 try sema.requireRuntimeBlock(block, src, null);
91049103
9105 // If the error set has no fields then no safety check is needed.9104 // If the error set has no fields then no safety check is needed.
9106 if (safety_check and block.wantSafety() and9105 if (safety_check and block.wantSafety() and
9107 !err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod))9106 !err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu))
9108 {9107 {
9109 try sema.panicUnwrapError(block, src, operand, .unwrap_errunion_err, .is_non_err);9108 try sema.panicUnwrapError(block, src, operand, .unwrap_errunion_err, .is_non_err);
9110 }9109 }
...@@ -9215,20 +9214,20 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -9215,20 +9214,20 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
92159214
9216fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref) CompileError!Air.Inst.Ref {9215fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref) CompileError!Air.Inst.Ref {
9217 const pt = sema.pt;9216 const pt = sema.pt;
9218 const mod = pt.zcu;9217 const zcu = pt.zcu;
9219 const operand_ty = sema.typeOf(operand);9218 const operand_ty = sema.typeOf(operand);
9220 if (operand_ty.zigTypeTag(mod) != .ErrorUnion) {9219 if (operand_ty.zigTypeTag(zcu) != .ErrorUnion) {
9221 return sema.fail(block, src, "expected error union type, found '{}'", .{9220 return sema.fail(block, src, "expected error union type, found '{}'", .{
9222 operand_ty.fmt(pt),9221 operand_ty.fmt(pt),
9223 });9222 });
9224 }9223 }
92259224
9226 const result_ty = operand_ty.errorUnionSet(mod);9225 const result_ty = operand_ty.errorUnionSet(zcu);
92279226
9228 if (try sema.resolveDefinedValue(block, src, operand)) |val| {9227 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
9229 return Air.internedToRef((try pt.intern(.{ .err = .{9228 return Air.internedToRef((try pt.intern(.{ .err = .{
9230 .ty = result_ty.toIntern(),9229 .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,
9232 } })));9231 } })));
9233 }9232 }
92349233
...@@ -9249,24 +9248,24 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -9249,24 +9248,24 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
92499248
9250fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref) CompileError!Air.Inst.Ref {9249fn analyzeErrUnionCodePtr(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref) CompileError!Air.Inst.Ref {
9251 const pt = sema.pt;9250 const pt = sema.pt;
9252 const mod = pt.zcu;9251 const zcu = pt.zcu;
9253 const operand_ty = sema.typeOf(operand);9252 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) {
9257 return sema.fail(block, src, "expected error union type, found '{}'", .{9256 return sema.fail(block, src, "expected error union type, found '{}'", .{
9258 operand_ty.childType(mod).fmt(pt),9257 operand_ty.childType(zcu).fmt(pt),
9259 });9258 });
9260 }9259 }
92619260
9262 const result_ty = operand_ty.childType(mod).errorUnionSet(mod);9261 const result_ty = operand_ty.childType(zcu).errorUnionSet(zcu);
92639262
9264 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {9263 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
9265 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {9264 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {
9266 assert(val.getErrorName(mod) != .none);9265 assert(val.getErrorName(zcu) != .none);
9267 return Air.internedToRef((try pt.intern(.{ .err = .{9266 return Air.internedToRef((try pt.intern(.{ .err = .{
9268 .ty = result_ty.toIntern(),9267 .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,
9270 } })));9269 } })));
9271 }9270 }
9272 }9271 }
...@@ -9412,7 +9411,7 @@ fn resolveGenericBody(...@@ -9412,7 +9411,7 @@ fn resolveGenericBody(
9412/// and puts it there if it doesn't exist.9411/// and puts it there if it doesn't exist.
9413/// It also dupes the library name which can then be saved as part of the9412/// It also dupes the library name which can then be saved as part of the
9414/// respective `Decl` (either `ExternFn` or `Var`).9413/// 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`.
9416/// To deallocate, call `deinit` on the respective `Decl` (`ExternFn` or `Var`).9415/// To deallocate, call `deinit` on the respective `Decl` (`ExternFn` or `Var`).
9417fn handleExternLibName(9416fn handleExternLibName(
9418 sema: *Sema,9417 sema: *Sema,
...@@ -9422,9 +9421,9 @@ fn handleExternLibName(...@@ -9422,9 +9421,9 @@ fn handleExternLibName(
9422) CompileError!void {9421) CompileError!void {
9423 blk: {9422 blk: {
9424 const pt = sema.pt;9423 const pt = sema.pt;
9425 const mod = pt.zcu;9424 const zcu = pt.zcu;
9426 const comp = mod.comp;9425 const comp = zcu.comp;
9427 const target = mod.getTarget();9426 const target = zcu.getTarget();
9428 log.debug("extern fn symbol expected in lib '{s}'", .{lib_name});9427 log.debug("extern fn symbol expected in lib '{s}'", .{lib_name});
9429 if (target.is_libc_lib_name(lib_name)) {9428 if (target.is_libc_lib_name(lib_name)) {
9430 if (!comp.config.link_libc) {9429 if (!comp.config.link_libc) {
...@@ -9575,7 +9574,7 @@ fn funcCommon(...@@ -9575,7 +9574,7 @@ fn funcCommon(
9575 .fn_proto_node_offset = src_node_offset,9574 .fn_proto_node_offset = src_node_offset,
9576 .param_index = @intCast(i),9575 .param_index = @intCast(i),
9577 } });9576 } });
9578 const requires_comptime = try sema.typeRequiresComptime(param_ty);9577 const requires_comptime = try param_ty.comptimeOnlySema(pt);
9579 if (param_is_comptime or requires_comptime) {9578 if (param_is_comptime or requires_comptime) {
9580 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error9579 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error
9581 }9580 }
...@@ -9631,7 +9630,7 @@ fn funcCommon(...@@ -9631,7 +9630,7 @@ fn funcCommon(
9631 const err_code_size = target.ptrBitWidth();9630 const err_code_size = target.ptrBitWidth();
9632 switch (i) {9631 switch (i) {
9633 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", .{}),9632 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}),
9635 else => return sema.fail(block, param_src, "'Interrupt' calling convention supports up to 2 parameters, found {d}", .{i + 1}),9634 else => return sema.fail(block, param_src, "'Interrupt' calling convention supports up to 2 parameters, found {d}", .{i + 1}),
9636 }9635 }
9637 } else return sema.fail(block, param_src, "parameters are not allowed with 'Interrupt' calling convention", .{}),9636 } else return sema.fail(block, param_src, "parameters are not allowed with 'Interrupt' calling convention", .{}),
...@@ -9640,7 +9639,7 @@ fn funcCommon(...@@ -9640,7 +9639,7 @@ fn funcCommon(
9640 }9639 }
9641 }9640 }
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);
9644 const ret_poison = bare_return_type.isGenericPoison();9643 const ret_poison = bare_return_type.isGenericPoison();
9645 const final_is_generic = is_generic or comptime_bits != 0 or ret_ty_requires_comptime;9644 const final_is_generic = is_generic or comptime_bits != 0 or ret_ty_requires_comptime;
96469645
...@@ -9881,18 +9880,18 @@ fn finishFunc(...@@ -9881,18 +9880,18 @@ fn finishFunc(
9881 final_is_generic: bool,9880 final_is_generic: bool,
9882) CompileError!Air.Inst.Ref {9881) CompileError!Air.Inst.Ref {
9883 const pt = sema.pt;9882 const pt = sema.pt;
9884 const mod = pt.zcu;9883 const zcu = pt.zcu;
9885 const ip = &mod.intern_pool;9884 const ip = &zcu.intern_pool;
9886 const gpa = sema.gpa;9885 const gpa = sema.gpa;
9887 const target = mod.getTarget();9886 const target = zcu.getTarget();
98889887
9889 const return_type: Type = if (opt_func_index == .none or ret_poison)9888 const return_type: Type = if (opt_func_index == .none or ret_poison)
9890 bare_return_type9889 bare_return_type
9891 else9890 else
9892 Type.fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));9891 Type.fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));
98939892
9894 if (!return_type.isValidReturnType(mod)) {9893 if (!return_type.isValidReturnType(zcu)) {
9895 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";9894 const opaque_str = if (return_type.zigTypeTag(zcu) == .Opaque) "opaque " else "";
9896 return sema.fail(block, ret_ty_src, "{s}return type '{}' not allowed", .{9895 return sema.fail(block, ret_ty_src, "{s}return type '{}' not allowed", .{
9897 opaque_str, return_type.fmt(pt),9896 opaque_str, return_type.fmt(pt),
9898 });9897 });
...@@ -9954,7 +9953,7 @@ fn finishFunc(...@@ -9954,7 +9953,7 @@ fn finishFunc(
9954 }9953 }
99559954
9956 switch (cc_resolved) {9955 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) {
9958 return sema.fail(block, ret_ty_src, "function with calling convention '{s}' must return 'void' or 'noreturn'", .{@tagName(cc_resolved)});9957 return sema.fail(block, ret_ty_src, "function with calling convention '{s}' must return 'void' or 'noreturn'", .{@tagName(cc_resolved)});
9959 },9958 },
9960 .Inline => if (is_noinline) {9959 .Inline => if (is_noinline) {
...@@ -10070,7 +10069,7 @@ fn zirParam(...@@ -10070,7 +10069,7 @@ fn zirParam(
10070 }10069 }
10071 };10070 };
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
10075 try block.params.append(sema.arena, .{10074 try block.params.append(sema.arena, .{
10076 .ty = param_ty.toIntern(),10075 .ty = param_ty.toIntern(),
...@@ -10141,7 +10140,7 @@ fn analyzeAs(...@@ -10141,7 +10140,7 @@ fn analyzeAs(
10141 no_cast_to_comptime_int: bool,10140 no_cast_to_comptime_int: bool,
10142) CompileError!Air.Inst.Ref {10141) CompileError!Air.Inst.Ref {
10143 const pt = sema.pt;10142 const pt = sema.pt;
10144 const mod = pt.zcu;10143 const zcu = pt.zcu;
10145 const operand = try sema.resolveInst(zir_operand);10144 const operand = try sema.resolveInst(zir_operand);
10146 const operand_air_inst = sema.resolveInst(zir_dest_type) catch |err| switch (err) {10145 const operand_air_inst = sema.resolveInst(zir_dest_type) catch |err| switch (err) {
10147 error.GenericPoison => return operand,10146 error.GenericPoison => return operand,
...@@ -10151,7 +10150,7 @@ fn analyzeAs(...@@ -10151,7 +10150,7 @@ fn analyzeAs(
10151 error.GenericPoison => return operand,10150 error.GenericPoison => return operand,
10152 else => |e| return e,10151 else => |e| return e,
10153 };10152 };
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) {
10155 error.GenericPoison => return operand,10154 error.GenericPoison => return operand,
10156 };10155 };
1015710156
...@@ -10189,7 +10188,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10189,7 +10188,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10189 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(pt)});10188 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(pt)});
10190 }10189 }
10191 const pointee_ty = ptr_ty.childType(zcu);10190 const pointee_ty = ptr_ty.childType(zcu);
10192 if (try sema.typeRequiresComptime(ptr_ty)) {10191 if (try ptr_ty.comptimeOnlySema(pt)) {
10193 const msg = msg: {10192 const msg = msg: {
10194 const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(pt)});10193 const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(pt)});
10195 errdefer msg.destroy(sema.gpa);10194 errdefer msg.destroy(sema.gpa);
...@@ -10205,7 +10204,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10205,7 +10204,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10205 }10204 }
10206 return Air.internedToRef((try pt.intValue(10205 return Air.internedToRef((try pt.intValue(
10207 Type.usize,10206 Type.usize,
10208 (try operand_val.getUnsignedIntAdvanced(pt, .sema)).?,10207 (try operand_val.toUnsignedIntSema(pt)),
10209 )).toIntern());10208 )).toIntern());
10210 }10209 }
10211 const len = operand_ty.vectorLen(zcu);10210 const len = operand_ty.vectorLen(zcu);
...@@ -10217,7 +10216,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10217,7 +10216,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10217 new_elem.* = (try pt.undefValue(Type.usize)).toIntern();10216 new_elem.* = (try pt.undefValue(Type.usize)).toIntern();
10218 continue;10217 continue;
10219 }10218 }
10220 const addr = try ptr_val.getUnsignedIntAdvanced(pt, .sema) orelse {10219 const addr = try ptr_val.getUnsignedIntSema(pt) orelse {
10221 // A vector element wasn't an integer pointer. This is a runtime operation.10220 // A vector element wasn't an integer pointer. This is a runtime operation.
10222 break :ct;10221 break :ct;
10223 };10222 };
...@@ -10252,12 +10251,12 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10252,12 +10251,12 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10252 defer tracy.end();10251 defer tracy.end();
1025310252
10254 const pt = sema.pt;10253 const pt = sema.pt;
10255 const mod = pt.zcu;10254 const zcu = pt.zcu;
10256 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10255 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10257 const src = block.nodeOffset(inst_data.src_node);10256 const src = block.nodeOffset(inst_data.src_node);
10258 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });10257 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
10259 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10258 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(
10261 sema.gpa,10260 sema.gpa,
10262 pt.tid,10261 pt.tid,
10263 sema.code.nullTerminatedString(extra.field_name_start),10262 sema.code.nullTerminatedString(extra.field_name_start),
...@@ -10272,12 +10271,12 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10272,12 +10271,12 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10272 defer tracy.end();10271 defer tracy.end();
1027310272
10274 const pt = sema.pt;10273 const pt = sema.pt;
10275 const mod = pt.zcu;10274 const zcu = pt.zcu;
10276 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10275 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10277 const src = block.nodeOffset(inst_data.src_node);10276 const src = block.nodeOffset(inst_data.src_node);
10278 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });10277 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
10279 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10278 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(
10281 sema.gpa,10280 sema.gpa,
10282 pt.tid,10281 pt.tid,
10283 sema.code.nullTerminatedString(extra.field_name_start),10282 sema.code.nullTerminatedString(extra.field_name_start),
...@@ -10292,20 +10291,20 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -10292,20 +10291,20 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
10292 defer tracy.end();10291 defer tracy.end();
1029310292
10294 const pt = sema.pt;10293 const pt = sema.pt;
10295 const mod = pt.zcu;10294 const zcu = pt.zcu;
10296 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10295 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10297 const src = block.nodeOffset(inst_data.src_node);10296 const src = block.nodeOffset(inst_data.src_node);
10298 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });10297 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
10299 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10298 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(
10301 sema.gpa,10300 sema.gpa,
10302 pt.tid,10301 pt.tid,
10303 sema.code.nullTerminatedString(extra.field_name_start),10302 sema.code.nullTerminatedString(extra.field_name_start),
10304 .no_embedded_nulls,10303 .no_embedded_nulls,
10305 );10304 );
10306 const object_ptr = try sema.resolveInst(extra.lhs);10305 const object_ptr = try sema.resolveInst(extra.lhs);
10307 const struct_ty = sema.typeOf(object_ptr).childType(mod);10306 const struct_ty = sema.typeOf(object_ptr).childType(zcu);
10308 switch (struct_ty.zigTypeTag(mod)) {10307 switch (struct_ty.zigTypeTag(zcu)) {
10309 .Struct, .Union => {10308 .Struct, .Union => {
10310 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, true);10309 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, true);
10311 },10310 },
...@@ -10371,25 +10370,25 @@ fn intCast(...@@ -10371,25 +10370,25 @@ fn intCast(
10371 runtime_safety: bool,10370 runtime_safety: bool,
10372) CompileError!Air.Inst.Ref {10371) CompileError!Air.Inst.Ref {
10373 const pt = sema.pt;10372 const pt = sema.pt;
10374 const mod = pt.zcu;10373 const zcu = pt.zcu;
10375 const operand_ty = sema.typeOf(operand);10374 const operand_ty = sema.typeOf(operand);
10376 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, dest_ty_src);10375 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, dest_ty_src);
10377 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);10376 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
1037810377
10379 if (try sema.isComptimeKnown(operand)) {10378 if (try sema.isComptimeKnown(operand)) {
10380 return sema.coerce(block, dest_ty, operand, operand_src);10379 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) {
10382 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_int'", .{});10381 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_int'", .{});
10383 }10382 }
1038410383
10385 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, dest_ty_src, operand_src);10384 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
10388 if ((try sema.typeHasOnePossibleValue(dest_ty))) |opv| {10387 if ((try sema.typeHasOnePossibleValue(dest_ty))) |opv| {
10389 // requirement: intCast(u0, input) iff input == 010388 // requirement: intCast(u0, input) iff input == 0
10390 if (runtime_safety and block.wantSafety()) {10389 if (runtime_safety and block.wantSafety()) {
10391 try sema.requireRuntimeBlock(block, src, operand_src);10390 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);
10393 const wanted_bits = wanted_info.bits;10392 const wanted_bits = wanted_info.bits;
1039410393
10395 if (wanted_bits == 0) {10394 if (wanted_bits == 0) {
...@@ -10416,8 +10415,8 @@ fn intCast(...@@ -10416,8 +10415,8 @@ fn intCast(
1041610415
10417 try sema.requireRuntimeBlock(block, src, operand_src);10416 try sema.requireRuntimeBlock(block, src, operand_src);
10418 if (runtime_safety and block.wantSafety()) {10417 if (runtime_safety and block.wantSafety()) {
10419 const actual_info = operand_scalar_ty.intInfo(mod);10418 const actual_info = operand_scalar_ty.intInfo(zcu);
10420 const wanted_info = dest_scalar_ty.intInfo(mod);10419 const wanted_info = dest_scalar_ty.intInfo(zcu);
10421 const actual_bits = actual_info.bits;10420 const actual_bits = actual_info.bits;
10422 const wanted_bits = wanted_info.bits;10421 const wanted_bits = wanted_info.bits;
10423 const actual_value_bits = actual_bits - @intFromBool(actual_info.signedness == .signed);10422 const actual_value_bits = actual_bits - @intFromBool(actual_info.signedness == .signed);
...@@ -10437,7 +10436,7 @@ fn intCast(...@@ -10437,7 +10436,7 @@ fn intCast(
10437 // negative differences (`operand` > `dest_max`) appear too big.10436 // negative differences (`operand` > `dest_max`) appear too big.
10438 const unsigned_scalar_operand_ty = try pt.intType(.unsigned, actual_bits);10437 const unsigned_scalar_operand_ty = try pt.intType(.unsigned, actual_bits);
10439 const unsigned_operand_ty = if (is_vector) try pt.vectorType(.{10438 const unsigned_operand_ty = if (is_vector) try pt.vectorType(.{
10440 .len = dest_ty.vectorLen(mod),10439 .len = dest_ty.vectorLen(zcu),
10441 .child = unsigned_scalar_operand_ty.toIntern(),10440 .child = unsigned_scalar_operand_ty.toIntern(),
10442 }) else unsigned_scalar_operand_ty;10441 }) else unsigned_scalar_operand_ty;
10443 const diff_unsigned = try block.addBitCast(unsigned_operand_ty, diff);10442 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...@@ -10520,7 +10519,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10520 defer tracy.end();10519 defer tracy.end();
1052110520
10522 const pt = sema.pt;10521 const pt = sema.pt;
10523 const mod = pt.zcu;10522 const zcu = pt.zcu;
10524 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10523 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10525 const src = block.nodeOffset(inst_data.src_node);10524 const src = block.nodeOffset(inst_data.src_node);
10526 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);10525 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...@@ -10529,7 +10528,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10529 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");10528 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");
10530 const operand = try sema.resolveInst(extra.rhs);10529 const operand = try sema.resolveInst(extra.rhs);
10531 const operand_ty = sema.typeOf(operand);10530 const operand_ty = sema.typeOf(operand);
10532 switch (dest_ty.zigTypeTag(mod)) {10531 switch (dest_ty.zigTypeTag(zcu)) {
10533 .AnyFrame,10532 .AnyFrame,
10534 .ComptimeFloat,10533 .ComptimeFloat,
10535 .ComptimeInt,10534 .ComptimeInt,
...@@ -10551,7 +10550,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10551,7 +10550,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10551 const msg = msg: {10550 const msg = msg: {
10552 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(pt)});10551 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(pt)});
10553 errdefer msg.destroy(sema.gpa);10552 errdefer msg.destroy(sema.gpa);
10554 switch (operand_ty.zigTypeTag(mod)) {10553 switch (operand_ty.zigTypeTag(zcu)) {
10555 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(pt)}),10554 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(pt)}),
10556 else => {},10555 else => {},
10557 }10556 }
...@@ -10565,7 +10564,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10565,7 +10564,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10565 const msg = msg: {10564 const msg = msg: {
10566 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(pt)});10565 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(pt)});
10567 errdefer msg.destroy(sema.gpa);10566 errdefer msg.destroy(sema.gpa);
10568 switch (operand_ty.zigTypeTag(mod)) {10567 switch (operand_ty.zigTypeTag(zcu)) {
10569 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(pt)}),10568 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(pt)}),
10570 .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(pt)}),10569 .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(pt)}),
10571 else => {},10570 else => {},
...@@ -10575,8 +10574,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10575,8 +10574,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10575 };10574 };
10576 return sema.failWithOwnedErrorMsg(block, msg);10575 return sema.failWithOwnedErrorMsg(block, msg);
10577 },10576 },
10578 .Struct, .Union => if (dest_ty.containerLayout(mod) == .auto) {10577 .Struct, .Union => if (dest_ty.containerLayout(zcu) == .auto) {
10579 const container = switch (dest_ty.zigTypeTag(mod)) {10578 const container = switch (dest_ty.zigTypeTag(zcu)) {
10580 .Struct => "struct",10579 .Struct => "struct",
10581 .Union => "union",10580 .Union => "union",
10582 else => unreachable,10581 else => unreachable,
...@@ -10593,7 +10592,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10593,7 +10592,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10593 .Vector,10592 .Vector,
10594 => {},10593 => {},
10595 }10594 }
10596 switch (operand_ty.zigTypeTag(mod)) {10595 switch (operand_ty.zigTypeTag(zcu)) {
10597 .AnyFrame,10596 .AnyFrame,
10598 .ComptimeFloat,10597 .ComptimeFloat,
10599 .ComptimeInt,10598 .ComptimeInt,
...@@ -10615,7 +10614,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10615,7 +10614,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10615 const msg = msg: {10614 const msg = msg: {
10616 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(pt)});10615 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(pt)});
10617 errdefer msg.destroy(sema.gpa);10616 errdefer msg.destroy(sema.gpa);
10618 switch (dest_ty.zigTypeTag(mod)) {10617 switch (dest_ty.zigTypeTag(zcu)) {
10619 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(pt)}),10618 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(pt)}),
10620 else => {},10619 else => {},
10621 }10620 }
...@@ -10628,7 +10627,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10628,7 +10627,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10628 const msg = msg: {10627 const msg = msg: {
10629 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(pt)});10628 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(pt)});
10630 errdefer msg.destroy(sema.gpa);10629 errdefer msg.destroy(sema.gpa);
10631 switch (dest_ty.zigTypeTag(mod)) {10630 switch (dest_ty.zigTypeTag(zcu)) {
10632 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(pt)}),10631 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(pt)}),
10633 .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(pt)}),10632 .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(pt)}),
10634 else => {},10633 else => {},
...@@ -10638,8 +10637,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10638,8 +10637,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10638 };10637 };
10639 return sema.failWithOwnedErrorMsg(block, msg);10638 return sema.failWithOwnedErrorMsg(block, msg);
10640 },10639 },
10641 .Struct, .Union => if (operand_ty.containerLayout(mod) == .auto) {10640 .Struct, .Union => if (operand_ty.containerLayout(zcu) == .auto) {
10642 const container = switch (operand_ty.zigTypeTag(mod)) {10641 const container = switch (operand_ty.zigTypeTag(zcu)) {
10643 .Struct => "struct",10642 .Struct => "struct",
10644 .Union => "union",10643 .Union => "union",
10645 else => unreachable,10644 else => unreachable,
...@@ -10664,24 +10663,24 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -10664,24 +10663,24 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10664 defer tracy.end();10663 defer tracy.end();
1066510664
10666 const pt = sema.pt;10665 const pt = sema.pt;
10667 const mod = pt.zcu;10666 const zcu = pt.zcu;
10668 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10667 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10669 const src = block.nodeOffset(inst_data.src_node);10668 const src = block.nodeOffset(inst_data.src_node);
10670 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);10669 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10671 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10670 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1067210671
10673 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");10672 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
10676 const operand = try sema.resolveInst(extra.rhs);10675 const operand = try sema.resolveInst(extra.rhs);
10677 const operand_ty = sema.typeOf(operand);10676 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
10680 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);10679 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();10682 const target = zcu.getTarget();
10684 const dest_is_comptime_float = switch (dest_scalar_ty.zigTypeTag(mod)) {10683 const dest_is_comptime_float = switch (dest_scalar_ty.zigTypeTag(zcu)) {
10685 .ComptimeFloat => true,10684 .ComptimeFloat => true,
10686 .Float => false,10685 .Float => false,
10687 else => return sema.fail(10686 else => return sema.fail(
...@@ -10692,7 +10691,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -10692,7 +10691,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10692 ),10691 ),
10693 };10692 };
1069410693
10695 switch (operand_scalar_ty.zigTypeTag(mod)) {10694 switch (operand_scalar_ty.zigTypeTag(zcu)) {
10696 .ComptimeFloat, .Float, .ComptimeInt => {},10695 .ComptimeFloat, .Float, .ComptimeInt => {},
10697 else => return sema.fail(10696 else => return sema.fail(
10698 block,10697 block,
...@@ -10706,7 +10705,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -10706,7 +10705,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10706 if (!is_vector) {10705 if (!is_vector) {
10707 return Air.internedToRef((try operand_val.floatCast(dest_ty, pt)).toIntern());10706 return Air.internedToRef((try operand_val.floatCast(dest_ty, pt)).toIntern());
10708 }10707 }
10709 const vec_len = operand_ty.vectorLen(mod);10708 const vec_len = operand_ty.vectorLen(zcu);
10710 const new_elems = try sema.arena.alloc(InternPool.Index, vec_len);10709 const new_elems = try sema.arena.alloc(InternPool.Index, vec_len);
10711 for (new_elems, 0..) |*new_elem, i| {10710 for (new_elems, 0..) |*new_elem, i| {
10712 const old_elem = try operand_val.elemValue(pt, i);10711 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...@@ -10730,7 +10729,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10730 if (!is_vector) {10729 if (!is_vector) {
10731 return block.addTyOp(.fptrunc, dest_ty, operand);10730 return block.addTyOp(.fptrunc, dest_ty, operand);
10732 }10731 }
10733 const vec_len = operand_ty.vectorLen(mod);10732 const vec_len = operand_ty.vectorLen(zcu);
10734 const new_elems = try sema.arena.alloc(Air.Inst.Ref, vec_len);10733 const new_elems = try sema.arena.alloc(Air.Inst.Ref, vec_len);
10735 for (new_elems, 0..) |*new_elem, i| {10734 for (new_elems, 0..) |*new_elem, i| {
10736 const idx_ref = try pt.intRef(Type.usize, i);10735 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...@@ -10781,21 +10780,21 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10781 defer tracy.end();10780 defer tracy.end();
1078210781
10783 const pt = sema.pt;10782 const pt = sema.pt;
10784 const mod = pt.zcu;10783 const zcu = pt.zcu;
10785 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10784 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10786 const src = block.nodeOffset(inst_data.src_node);10785 const src = block.nodeOffset(inst_data.src_node);
10787 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10786 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10788 const array_ptr = try sema.resolveInst(extra.lhs);10787 const array_ptr = try sema.resolveInst(extra.lhs);
10789 const elem_index = try sema.resolveInst(extra.rhs);10788 const elem_index = try sema.resolveInst(extra.rhs);
10790 const indexable_ty = sema.typeOf(array_ptr);10789 const indexable_ty = sema.typeOf(array_ptr);
10791 if (indexable_ty.zigTypeTag(mod) != .Pointer) {10790 if (indexable_ty.zigTypeTag(zcu) != .Pointer) {
10792 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });10791 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
10793 const msg = msg: {10792 const msg = msg: {
10794 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{10793 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{
10795 indexable_ty.fmt(pt),10794 indexable_ty.fmt(pt),
10796 });10795 });
10797 errdefer msg.destroy(sema.gpa);10796 errdefer msg.destroy(sema.gpa);
10798 if (indexable_ty.isIndexable(mod)) {10797 if (indexable_ty.isIndexable(zcu)) {
10799 try sema.errNote(src, msg, "consider using '&' here", .{});10798 try sema.errNote(src, msg, "consider using '&' here", .{});
10800 }10799 }
10801 break :msg msg;10800 break :msg msg;
...@@ -10824,16 +10823,16 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile...@@ -10824,16 +10823,16 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
10824 defer tracy.end();10823 defer tracy.end();
1082510824
10826 const pt = sema.pt;10825 const pt = sema.pt;
10827 const mod = pt.zcu;10826 const zcu = pt.zcu;
10828 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10827 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10829 const src = block.nodeOffset(inst_data.src_node);10828 const src = block.nodeOffset(inst_data.src_node);
10830 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;10829 const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data;
10831 const array_ptr = try sema.resolveInst(extra.ptr);10830 const array_ptr = try sema.resolveInst(extra.ptr);
10832 const elem_index = try pt.intRef(Type.usize, extra.index);10831 const elem_index = try pt.intRef(Type.usize, extra.index);
10833 const array_ty = sema.typeOf(array_ptr).childType(mod);10832 const array_ty = sema.typeOf(array_ptr).childType(zcu);
10834 switch (array_ty.zigTypeTag(mod)) {10833 switch (array_ty.zigTypeTag(zcu)) {
10835 .Array, .Vector => {},10834 .Array, .Vector => {},
10836 else => if (!array_ty.isTuple(mod)) {10835 else => if (!array_ty.isTuple(zcu)) {
10837 return sema.failWithArrayInitNotSupported(block, src, array_ty);10836 return sema.failWithArrayInitNotSupported(block, src, array_ty);
10838 },10837 },
10839 }10838 }
...@@ -11059,9 +11058,9 @@ const SwitchProngAnalysis = struct {...@@ -11059,9 +11058,9 @@ const SwitchProngAnalysis = struct {
11059 ) CompileError!Air.Inst.Ref {11058 ) CompileError!Air.Inst.Ref {
11060 const sema = spa.sema;11059 const sema = spa.sema;
11061 const pt = sema.pt;11060 const pt = sema.pt;
11062 const mod = pt.zcu;11061 const zcu = pt.zcu;
11063 const operand_ty = sema.typeOf(spa.operand);11062 const operand_ty = sema.typeOf(spa.operand);
11064 if (operand_ty.zigTypeTag(mod) != .Union) {11063 if (operand_ty.zigTypeTag(zcu) != .Union) {
11065 const tag_capture_src: LazySrcLoc = .{11064 const tag_capture_src: LazySrcLoc = .{
11066 .base_node_inst = capture_src.base_node_inst,11065 .base_node_inst = capture_src.base_node_inst,
11067 .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture },11066 .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture },
...@@ -11429,9 +11428,9 @@ fn switchCond(...@@ -11429,9 +11428,9 @@ fn switchCond(
11429 operand: Air.Inst.Ref,11428 operand: Air.Inst.Ref,
11430) CompileError!Air.Inst.Ref {11429) CompileError!Air.Inst.Ref {
11431 const pt = sema.pt;11430 const pt = sema.pt;
11432 const mod = pt.zcu;11431 const zcu = pt.zcu;
11433 const operand_ty = sema.typeOf(operand);11432 const operand_ty = sema.typeOf(operand);
11434 switch (operand_ty.zigTypeTag(mod)) {11433 switch (operand_ty.zigTypeTag(zcu)) {
11435 .Type,11434 .Type,
11436 .Void,11435 .Void,
11437 .Bool,11436 .Bool,
...@@ -11445,7 +11444,7 @@ fn switchCond(...@@ -11445,7 +11444,7 @@ fn switchCond(
11445 .ErrorSet,11444 .ErrorSet,
11446 .Enum,11445 .Enum,
11447 => {11446 => {
11448 if (operand_ty.isSlice(mod)) {11447 if (operand_ty.isSlice(zcu)) {
11449 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(pt)});11448 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(pt)});
11450 }11449 }
11451 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {11450 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {
...@@ -11456,11 +11455,11 @@ fn switchCond(...@@ -11456,11 +11455,11 @@ fn switchCond(
1145611455
11457 .Union => {11456 .Union => {
11458 try operand_ty.resolveFields(pt);11457 try operand_ty.resolveFields(pt);
11459 const enum_ty = operand_ty.unionTagType(mod) orelse {11458 const enum_ty = operand_ty.unionTagType(zcu) orelse {
11460 const msg = msg: {11459 const msg = msg: {
11461 const msg = try sema.errMsg(src, "switch on union with no attached enum", .{});11460 const msg = try sema.errMsg(src, "switch on union with no attached enum", .{});
11462 errdefer msg.destroy(sema.gpa);11461 errdefer msg.destroy(sema.gpa);
11463 if (operand_ty.srcLocOrNull(mod)) |union_src| {11462 if (operand_ty.srcLocOrNull(zcu)) |union_src| {
11464 try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{});11463 try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{});
11465 }11464 }
11466 break :msg msg;11465 break :msg msg;
...@@ -11492,7 +11491,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11492,7 +11491,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11492 defer tracy.end();11491 defer tracy.end();
1149311492
11494 const pt = sema.pt;11493 const pt = sema.pt;
11495 const mod = pt.zcu;11494 const zcu = pt.zcu;
11496 const gpa = sema.gpa;11495 const gpa = sema.gpa;
11497 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;11496 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11498 const switch_src = block.nodeOffset(inst_data.src_node);11497 const switch_src = block.nodeOffset(inst_data.src_node);
...@@ -11577,17 +11576,17 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11577,17 +11576,17 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1157711576
11578 const operand_ty = sema.typeOf(raw_operand_val);11577 const operand_ty = sema.typeOf(raw_operand_val);
11579 const operand_err_set = if (extra.data.bits.payload_is_ref)11578 const operand_err_set = if (extra.data.bits.payload_is_ref)
11580 operand_ty.childType(mod)11579 operand_ty.childType(zcu)
11581 else11580 else
11582 operand_ty;11581 operand_ty;
1158311582
11584 if (operand_err_set.zigTypeTag(mod) != .ErrorUnion) {11583 if (operand_err_set.zigTypeTag(zcu) != .ErrorUnion) {
11585 return sema.fail(block, switch_src, "expected error union type, found '{}'", .{11584 return sema.fail(block, switch_src, "expected error union type, found '{}'", .{
11586 operand_ty.fmt(pt),11585 operand_ty.fmt(pt),
11587 });11586 });
11588 }11587 }
1158911588
11590 const operand_err_set_ty = operand_err_set.errorUnionSet(mod);11589 const operand_err_set_ty = operand_err_set.errorUnionSet(zcu);
1159111590
11592 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);11591 const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
11593 try sema.air_instructions.append(gpa, .{11592 try sema.air_instructions.append(gpa, .{
...@@ -11628,7 +11627,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11628,7 +11627,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11628 defer merges.deinit(gpa);11627 defer merges.deinit(gpa);
1162911628
11630 const resolved_err_set = try sema.resolveInferredErrorSetTy(block, main_src, operand_err_set_ty.toIntern());11629 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)) {
11632 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);11631 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);
11633 }11632 }
1163411633
...@@ -11662,13 +11661,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11662,13 +11661,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11662 else11661 else
11663 ov;11662 ov;
1166411663
11665 if (operand_val.errorUnionIsPayload(mod)) {11664 if (operand_val.errorUnionIsPayload(zcu)) {
11666 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);11665 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);
11667 } else {11666 } else {
11668 const err_val = Value.fromInterned(try pt.intern(.{11667 const err_val = Value.fromInterned(try pt.intern(.{
11669 .err = .{11668 .err = .{
11670 .ty = operand_err_set_ty.toIntern(),11669 .ty = operand_err_set_ty.toIntern(),
11671 .name = operand_val.getErrorName(mod).unwrap().?,11670 .name = operand_val.getErrorName(zcu).unwrap().?,
11672 },11671 },
11673 }));11672 }));
11674 spa.operand = if (extra.data.bits.payload_is_ref)11673 spa.operand = if (extra.data.bits.payload_is_ref)
...@@ -11706,7 +11705,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11706,7 +11705,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11706 }11705 }
1170711706
11708 if (scalar_cases_len + multi_cases_len == 0) {11707 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)) {
11710 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);11709 return sema.resolveBlockBody(block, main_operand_src, &child_block, non_error_case.body, inst, merges);
11711 };11710 };
11712 }11711 }
...@@ -11720,7 +11719,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11720,7 +11719,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11720 }11719 }
1172111720
11722 const cond = if (extra.data.bits.payload_is_ref) blk: {11721 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));
11724 const loaded = try sema.analyzeLoad(block, main_src, raw_operand_val, main_src);11723 const loaded = try sema.analyzeLoad(block, main_src, raw_operand_val, main_src);
11725 break :blk try sema.analyzeIsNonErr(block, main_src, loaded);11724 break :blk try sema.analyzeIsNonErr(block, main_src, loaded);
11726 } else blk: {11725 } else blk: {
...@@ -11803,7 +11802,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11803,7 +11802,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11803 defer tracy.end();11802 defer tracy.end();
1180411803
11805 const pt = sema.pt;11804 const pt = sema.pt;
11806 const mod = pt.zcu;11805 const zcu = pt.zcu;
11807 const gpa = sema.gpa;11806 const gpa = sema.gpa;
11808 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;11807 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11809 const src = block.nodeOffset(inst_data.src_node);11808 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...@@ -11873,12 +11872,12 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11873 };11872 };
1187411873
11875 const maybe_union_ty = sema.typeOf(raw_operand_val);11874 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
11878 // Duplicate checking variables later also used for `inline else`.11877 // Duplicate checking variables later also used for `inline else`.
11879 var seen_enum_fields: []?LazySrcLoc = &.{};11878 var seen_enum_fields: []?LazySrcLoc = &.{};
11880 var seen_errors = SwitchErrorSet.init(gpa);11879 var seen_errors = SwitchErrorSet.init(gpa);
11881 var range_set = RangeSet.init(gpa, pt);11880 var range_set = RangeSet.init(gpa, zcu);
11882 var true_count: u8 = 0;11881 var true_count: u8 = 0;
11883 var false_count: u8 = 0;11882 var false_count: u8 = 0;
1188411883
...@@ -11891,12 +11890,12 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11891,12 +11890,12 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11891 var empty_enum = false;11890 var empty_enum = false;
1189211891
11893 const operand_ty = sema.typeOf(operand);11892 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
11896 var else_error_ty: ?Type = null;11895 var else_error_ty: ?Type = null;
1189711896
11898 // Validate usage of '_' prongs.11897 // 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)) {
11900 const msg = msg: {11899 const msg = msg: {
11901 const msg = try sema.errMsg(11900 const msg = try sema.errMsg(
11902 src,11901 src,
...@@ -11922,11 +11921,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11922,11 +11921,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11922 }11921 }
1192311922
11924 // Validate for duplicate items, missing else prong, and invalid range.11923 // Validate for duplicate items, missing else prong, and invalid range.
11925 switch (operand_ty.zigTypeTag(mod)) {11924 switch (operand_ty.zigTypeTag(zcu)) {
11926 .Union => unreachable, // handled in `switchCond`11925 .Union => unreachable, // handled in `switchCond`
11927 .Enum => {11926 .Enum => {
11928 seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(mod));11927 seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(zcu));
11929 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);11928 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(zcu);
11930 @memset(seen_enum_fields, null);11929 @memset(seen_enum_fields, null);
11931 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.11930 // `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...@@ -11989,7 +11988,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11989 } else true;11988 } else true;
1199011989
11991 if (special_prong == .@"else") {11990 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(
11993 block,11992 block,
11994 special_prong_src,11993 special_prong_src,
11995 "unreachable else prong; all cases already handled",11994 "unreachable else prong; all cases already handled",
...@@ -12006,17 +12005,17 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12006,17 +12005,17 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12006 for (seen_enum_fields, 0..) |seen_src, i| {12005 for (seen_enum_fields, 0..) |seen_src, i| {
12007 if (seen_src != null) continue;12006 if (seen_src != null) continue;
1200812007
12009 const field_name = operand_ty.enumFieldName(i, mod);12008 const field_name = operand_ty.enumFieldName(i, zcu);
12010 try sema.addFieldErrNote(12009 try sema.addFieldErrNote(
12011 operand_ty,12010 operand_ty,
12012 i,12011 i,
12013 msg,12012 msg,
12014 "unhandled enumeration value: '{}'",12013 "unhandled enumeration value: '{}'",
12015 .{field_name.fmt(&mod.intern_pool)},12014 .{field_name.fmt(&zcu.intern_pool)},
12016 );12015 );
12017 }12016 }
12018 try sema.errNote(12017 try sema.errNote(
12019 operand_ty.srcLoc(mod),12018 operand_ty.srcLoc(zcu),
12020 msg,12019 msg,
12021 "enum '{}' declared here",12020 "enum '{}' declared here",
12022 .{operand_ty.fmt(pt)},12021 .{operand_ty.fmt(pt)},
...@@ -12024,7 +12023,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12024,7 +12023,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12024 break :msg msg;12023 break :msg msg;
12025 };12024 };
12026 return sema.failWithOwnedErrorMsg(block, msg);12025 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) {
12028 return sema.fail(12027 return sema.fail(
12029 block,12028 block,
12030 src,12029 src,
...@@ -12124,7 +12123,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12124,7 +12123,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12124 }12123 }
1212512124
12126 check_range: {12125 check_range: {
12127 if (operand_ty.zigTypeTag(mod) == .Int) {12126 if (operand_ty.zigTypeTag(zcu) == .Int) {
12128 const min_int = try operand_ty.minInt(pt, operand_ty);12127 const min_int = try operand_ty.minInt(pt, operand_ty);
12129 const max_int = try operand_ty.maxInt(pt, operand_ty);12128 const max_int = try operand_ty.maxInt(pt, operand_ty);
12130 if (try range_set.spans(min_int.toIntern(), max_int.toIntern())) {12129 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...@@ -12388,8 +12387,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12388 if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src, false)) {12387 if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src, false)) {
12389 return .unreachable_value;12388 return .unreachable_value;
12390 }12389 }
12391 if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and12390 if (zcu.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(zcu) == .Enum and
12392 (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))12391 (!operand_ty.isNonexhaustiveEnum(zcu) or union_originally))
12393 {12392 {
12394 try sema.zirDbgStmt(block, cond_dbg_node_index);12393 try sema.zirDbgStmt(block, cond_dbg_node_index);
12395 const ok = try block.addUnOp(.is_named_enum_value, operand);12394 const ok = try block.addUnOp(.is_named_enum_value, operand);
...@@ -12482,9 +12481,9 @@ fn analyzeSwitchRuntimeBlock(...@@ -12482,9 +12481,9 @@ fn analyzeSwitchRuntimeBlock(
12482 allow_err_code_unwrap: bool,12481 allow_err_code_unwrap: bool,
12483) CompileError!Air.Inst.Ref {12482) CompileError!Air.Inst.Ref {
12484 const pt = sema.pt;12483 const pt = sema.pt;
12485 const mod = pt.zcu;12484 const zcu = pt.zcu;
12486 const gpa = sema.gpa;12485 const gpa = sema.gpa;
12487 const ip = &mod.intern_pool;12486 const ip = &zcu.intern_pool;
1248812487
12489 const block = child_block.parent.?;12488 const block = child_block.parent.?;
1249012489
...@@ -12519,8 +12518,8 @@ fn analyzeSwitchRuntimeBlock(...@@ -12519,8 +12518,8 @@ fn analyzeSwitchRuntimeBlock(
12519 const analyze_body = if (union_originally) blk: {12518 const analyze_body = if (union_originally) blk: {
12520 const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;12519 const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12521 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;12520 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
12522 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12521 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12523 break :blk field_ty.zigTypeTag(mod) != .NoReturn;12522 break :blk field_ty.zigTypeTag(zcu) != .NoReturn;
12524 } else true;12523 } else true;
1252512524
12526 if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src, allow_err_code_unwrap)) {12525 if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src, allow_err_code_unwrap)) {
...@@ -12592,7 +12591,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12592,7 +12591,7 @@ fn analyzeSwitchRuntimeBlock(
12592 var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable;12591 var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable;
12593 const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable;12592 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)) : ({
12596 // Previous validation has resolved any possible lazy values.12595 // Previous validation has resolved any possible lazy values.
12597 item = sema.intAddScalar(item, try pt.intValue(operand_ty, 1), operand_ty) catch |err| switch (err) {12596 item = sema.intAddScalar(item, try pt.intValue(operand_ty, 1), operand_ty) catch |err| switch (err) {
12598 error.Overflow => unreachable,12597 error.Overflow => unreachable,
...@@ -12633,7 +12632,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12633,7 +12632,7 @@ fn analyzeSwitchRuntimeBlock(
12633 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));12632 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
12634 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));12633 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;
12637 }12636 }
12638 }12637 }
1263912638
...@@ -12645,8 +12644,8 @@ fn analyzeSwitchRuntimeBlock(...@@ -12645,8 +12644,8 @@ fn analyzeSwitchRuntimeBlock(
1264512644
12646 const analyze_body = if (union_originally) blk: {12645 const analyze_body = if (union_originally) blk: {
12647 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;12646 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12648 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12647 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12649 break :blk field_ty.zigTypeTag(mod) != .NoReturn;12648 break :blk field_ty.zigTypeTag(zcu) != .NoReturn;
12650 } else true;12649 } else true;
1265112650
12652 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{12651 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
...@@ -12696,8 +12695,8 @@ fn analyzeSwitchRuntimeBlock(...@@ -12696,8 +12695,8 @@ fn analyzeSwitchRuntimeBlock(
12696 const analyze_body = if (union_originally)12695 const analyze_body = if (union_originally)
12697 for (items) |item| {12696 for (items) |item| {
12698 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;12697 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12699 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12698 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12700 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;12699 if (field_ty.zigTypeTag(zcu) != .NoReturn) break true;
12701 } else false12700 } else false
12702 else12701 else
12703 true;12702 true;
...@@ -12836,9 +12835,9 @@ fn analyzeSwitchRuntimeBlock(...@@ -12836,9 +12835,9 @@ fn analyzeSwitchRuntimeBlock(
12836 var final_else_body: []const Air.Inst.Index = &.{};12835 var final_else_body: []const Air.Inst.Index = &.{};
12837 if (special.body.len != 0 or !is_first or case_block.wantSafety()) {12836 if (special.body.len != 0 or !is_first or case_block.wantSafety()) {
12838 var emit_bb = false;12837 var emit_bb = false;
12839 if (special.is_inline) switch (operand_ty.zigTypeTag(mod)) {12838 if (special.is_inline) switch (operand_ty.zigTypeTag(zcu)) {
12840 .Enum => {12839 .Enum => {
12841 if (operand_ty.isNonexhaustiveEnum(mod) and !union_originally) {12840 if (operand_ty.isNonexhaustiveEnum(zcu) and !union_originally) {
12842 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{12841 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
12843 operand_ty.fmt(pt),12842 operand_ty.fmt(pt),
12844 });12843 });
...@@ -12854,8 +12853,8 @@ fn analyzeSwitchRuntimeBlock(...@@ -12854,8 +12853,8 @@ fn analyzeSwitchRuntimeBlock(
12854 case_block.error_return_trace_index = child_block.error_return_trace_index;12853 case_block.error_return_trace_index = child_block.error_return_trace_index;
1285512854
12856 const analyze_body = if (union_originally) blk: {12855 const analyze_body = if (union_originally) blk: {
12857 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12856 const field_ty = maybe_union_ty.unionFieldType(item_val, zcu).?;
12858 break :blk field_ty.zigTypeTag(mod) != .NoReturn;12857 break :blk field_ty.zigTypeTag(zcu) != .NoReturn;
12859 } else true;12858 } else true;
1286012859
12861 if (emit_bb) try sema.emitBackwardBranch(block, special_prong_src);12860 if (emit_bb) try sema.emitBackwardBranch(block, special_prong_src);
...@@ -12887,12 +12886,12 @@ fn analyzeSwitchRuntimeBlock(...@@ -12887,12 +12886,12 @@ fn analyzeSwitchRuntimeBlock(
12887 }12886 }
12888 },12887 },
12889 .ErrorSet => {12888 .ErrorSet => {
12890 if (operand_ty.isAnyError(mod)) {12889 if (operand_ty.isAnyError(zcu)) {
12891 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{12890 return sema.fail(block, special_prong_src, "cannot enumerate values of type '{}' for 'inline else'", .{
12892 operand_ty.fmt(pt),12891 operand_ty.fmt(pt),
12893 });12892 });
12894 }12893 }
12895 const error_names = operand_ty.errorSetNames(mod);12894 const error_names = operand_ty.errorSetNames(zcu);
12896 for (0..error_names.len) |name_index| {12895 for (0..error_names.len) |name_index| {
12897 const error_name = error_names.get(ip)[name_index];12896 const error_name = error_names.get(ip)[name_index];
12898 if (seen_errors.contains(error_name)) continue;12897 if (seen_errors.contains(error_name)) continue;
...@@ -13033,10 +13032,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -13033,10 +13032,10 @@ fn analyzeSwitchRuntimeBlock(
13033 case_block.instructions.shrinkRetainingCapacity(0);13032 case_block.instructions.shrinkRetainingCapacity(0);
13034 case_block.error_return_trace_index = child_block.error_return_trace_index;13033 case_block.error_return_trace_index = child_block.error_return_trace_index;
1303513034
13036 if (mod.backendSupportsFeature(.is_named_enum_value) and13035 if (zcu.backendSupportsFeature(.is_named_enum_value) and
13037 special.body.len != 0 and block.wantSafety() and13036 special.body.len != 0 and block.wantSafety() and
13038 operand_ty.zigTypeTag(mod) == .Enum and13037 operand_ty.zigTypeTag(zcu) == .Enum and
13039 (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))13038 (!operand_ty.isNonexhaustiveEnum(zcu) or union_originally))
13040 {13039 {
13041 try sema.zirDbgStmt(&case_block, cond_dbg_node_index);13040 try sema.zirDbgStmt(&case_block, cond_dbg_node_index);
13042 const ok = try case_block.addUnOp(.is_named_enum_value, operand);13041 const ok = try case_block.addUnOp(.is_named_enum_value, operand);
...@@ -13046,9 +13045,9 @@ fn analyzeSwitchRuntimeBlock(...@@ -13046,9 +13045,9 @@ fn analyzeSwitchRuntimeBlock(
13046 const analyze_body = if (union_originally and !special.is_inline)13045 const analyze_body = if (union_originally and !special.is_inline)
13047 for (seen_enum_fields, 0..) |seen_field, index| {13046 for (seen_enum_fields, 0..) |seen_field, index| {
13048 if (seen_field != null) continue;13047 if (seen_field != null) continue;
13049 const union_obj = mod.typeToUnion(maybe_union_ty).?;13048 const union_obj = zcu.typeToUnion(maybe_union_ty).?;
13050 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[index]);13049 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;
13052 } else false13051 } else false
13053 else13052 else
13054 true;13053 true;
...@@ -13371,8 +13370,8 @@ fn validateErrSetSwitch(...@@ -13371,8 +13370,8 @@ fn validateErrSetSwitch(
13371) CompileError!?Type {13370) CompileError!?Type {
13372 const gpa = sema.gpa;13371 const gpa = sema.gpa;
13373 const pt = sema.pt;13372 const pt = sema.pt;
13374 const mod = pt.zcu;13373 const zcu = pt.zcu;
13375 const ip = &mod.intern_pool;13374 const ip = &zcu.intern_pool;
1337613375
13377 const src_node_offset = inst_data.src_node;13376 const src_node_offset = inst_data.src_node;
13378 const src = block.nodeOffset(src_node_offset);13377 const src = block.nodeOffset(src_node_offset);
...@@ -13444,7 +13443,7 @@ fn validateErrSetSwitch(...@@ -13444,7 +13443,7 @@ fn validateErrSetSwitch(
13444 },13443 },
13445 else => |err_set_ty_index| else_validation: {13444 else => |err_set_ty_index| else_validation: {
13446 const error_names = ip.indexToKey(err_set_ty_index).error_set_type.names;13445 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;
13448 errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa);13447 errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa);
1344913448
13450 for (error_names.get(ip)) |error_name| {13449 for (error_names.get(ip)) |error_name| {
...@@ -13711,8 +13710,8 @@ fn maybeErrorUnwrap(...@@ -13711,8 +13710,8 @@ fn maybeErrorUnwrap(
13711 allow_err_code_inst: bool,13710 allow_err_code_inst: bool,
13712) !bool {13711) !bool {
13713 const pt = sema.pt;13712 const pt = sema.pt;
13714 const mod = pt.zcu;13713 const zcu = pt.zcu;
13715 if (!mod.backendSupportsFeature(.panic_unwrap_error)) return false;13714 if (!zcu.backendSupportsFeature(.panic_unwrap_error)) return false;
1371613715
13717 const tags = sema.code.instructions.items(.tag);13716 const tags = sema.code.instructions.items(.tag);
13718 for (body) |inst| {13717 for (body) |inst| {
...@@ -13745,7 +13744,7 @@ fn maybeErrorUnwrap(...@@ -13745,7 +13744,7 @@ fn maybeErrorUnwrap(
13745 .as_node => try sema.zirAsNode(block, inst),13744 .as_node => try sema.zirAsNode(block, inst),
13746 .field_val => try sema.zirFieldVal(block, inst),13745 .field_val => try sema.zirFieldVal(block, inst),
13747 .@"unreachable" => {13746 .@"unreachable" => {
13748 if (!mod.comp.formatted_panics) {13747 if (!zcu.comp.formatted_panics) {
13749 try sema.safetyPanic(block, operand_src, .unwrap_error);13748 try sema.safetyPanic(block, operand_src, .unwrap_error);
13750 return true;13749 return true;
13751 }13750 }
...@@ -13768,7 +13767,7 @@ fn maybeErrorUnwrap(...@@ -13768,7 +13767,7 @@ fn maybeErrorUnwrap(
13768 },13767 },
13769 else => unreachable,13768 else => unreachable,
13770 };13769 };
13771 if (sema.typeOf(air_inst).isNoReturn(mod))13770 if (sema.typeOf(air_inst).isNoReturn(zcu))
13772 return true;13771 return true;
13773 sema.inst_map.putAssumeCapacity(inst, air_inst);13772 sema.inst_map.putAssumeCapacity(inst, air_inst);
13774 }13773 }
...@@ -13777,20 +13776,20 @@ fn maybeErrorUnwrap(...@@ -13777,20 +13776,20 @@ fn maybeErrorUnwrap(
1377713776
13778fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void {13777fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, cond: Zir.Inst.Ref, cond_src: LazySrcLoc) !void {
13779 const pt = sema.pt;13778 const pt = sema.pt;
13780 const mod = pt.zcu;13779 const zcu = pt.zcu;
13781 const index = cond.toIndex() orelse return;13780 const index = cond.toIndex() orelse return;
13782 if (sema.code.instructions.items(.tag)[@intFromEnum(index)] != .is_non_err) return;13781 if (sema.code.instructions.items(.tag)[@intFromEnum(index)] != .is_non_err) return;
1378313782
13784 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;13783 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;
13785 const err_operand = try sema.resolveInst(err_inst_data.operand);13784 const err_operand = try sema.resolveInst(err_inst_data.operand);
13786 const operand_ty = sema.typeOf(err_operand);13785 const operand_ty = sema.typeOf(err_operand);
13787 if (operand_ty.zigTypeTag(mod) == .ErrorSet) {13786 if (operand_ty.zigTypeTag(zcu) == .ErrorSet) {
13788 try sema.maybeErrorUnwrapComptime(block, body, err_operand);13787 try sema.maybeErrorUnwrapComptime(block, body, err_operand);
13789 return;13788 return;
13790 }13789 }
13791 if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| {13790 if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| {
13792 if (!operand_ty.isError(mod)) return;13791 if (!operand_ty.isError(zcu)) return;
13793 if (val.getErrorName(mod) == .none) return;13792 if (val.getErrorName(zcu) == .none) return;
13794 try sema.maybeErrorUnwrapComptime(block, body, err_operand);13793 try sema.maybeErrorUnwrapComptime(block, body, err_operand);
13795 }13794 }
13796}13795}
...@@ -13818,7 +13817,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I...@@ -13818,7 +13817,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
1381813817
13819fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13818fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
13820 const pt = sema.pt;13819 const pt = sema.pt;
13821 const mod = pt.zcu;13820 const zcu = pt.zcu;
13822 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13821 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13823 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13822 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13824 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);13823 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...@@ -13828,7 +13827,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13828 .needed_comptime_reason = "field name must be comptime-known",13827 .needed_comptime_reason = "field name must be comptime-known",
13829 });13828 });
13830 try ty.resolveFields(pt);13829 try ty.resolveFields(pt);
13831 const ip = &mod.intern_pool;13830 const ip = &zcu.intern_pool;
1383213831
13833 const has_field = hf: {13832 const has_field = hf: {
13834 switch (ip.indexToKey(ty.toIntern())) {13833 switch (ip.indexToKey(ty.toIntern())) {
...@@ -13845,7 +13844,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13845,7 +13844,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13845 break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names.get(ip), field_name) != null;13844 break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names.get(ip), field_name) != null;
13846 } else {13845 } else {
13847 const field_index = field_name.toUnsigned(ip) orelse break :hf false;13846 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);
13849 }13848 }
13850 },13849 },
13851 .struct_type => {13850 .struct_type => {
...@@ -13870,7 +13869,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13870,7 +13869,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1387013869
13871fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13870fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
13872 const pt = sema.pt;13871 const pt = sema.pt;
13873 const mod = pt.zcu;13872 const zcu = pt.zcu;
13874 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13873 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13875 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13874 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13876 const src = block.nodeOffset(inst_data.src_node);13875 const src = block.nodeOffset(inst_data.src_node);
...@@ -13883,7 +13882,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13883,7 +13882,7 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1388313882
13884 try sema.checkNamespaceType(block, lhs_src, container_type);13883 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;
13887 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| {13886 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |lookup| {
13888 if (lookup.accessible) {13887 if (lookup.accessible) {
13889 return .bool_true;13888 return .bool_true;
...@@ -13958,9 +13957,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13958,9 +13957,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1395813957
13959fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13958fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
13960 const pt = sema.pt;13959 const pt = sema.pt;
13961 const mod = pt.zcu;13960 const zcu = pt.zcu;
13962 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;13961 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(
13964 sema.gpa,13963 sema.gpa,
13965 pt.tid,13964 pt.tid,
13966 inst_data.get(sema.code),13965 inst_data.get(sema.code),
...@@ -13984,7 +13983,7 @@ fn zirShl(...@@ -13984,7 +13983,7 @@ fn zirShl(
13984 defer tracy.end();13983 defer tracy.end();
1398513984
13986 const pt = sema.pt;13985 const pt = sema.pt;
13987 const mod = pt.zcu;13986 const zcu = pt.zcu;
13988 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13987 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13989 const src = block.nodeOffset(inst_data.src_node);13988 const src = block.nodeOffset(inst_data.src_node);
13990 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });13989 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
...@@ -13996,8 +13995,8 @@ fn zirShl(...@@ -13996,8 +13995,8 @@ fn zirShl(
13996 const rhs_ty = sema.typeOf(rhs);13995 const rhs_ty = sema.typeOf(rhs);
13997 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);13996 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1399813997
13999 const scalar_ty = lhs_ty.scalarType(mod);13998 const scalar_ty = lhs_ty.scalarType(zcu);
14000 const scalar_rhs_ty = rhs_ty.scalarType(mod);13999 const scalar_rhs_ty = rhs_ty.scalarType(zcu);
1400114000
14002 // TODO coerce rhs if air_tag is not shl_sat14001 // TODO coerce rhs if air_tag is not shl_sat
14003 const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty);14002 const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty);
...@@ -14006,20 +14005,20 @@ fn zirShl(...@@ -14006,20 +14005,20 @@ fn zirShl(
14006 const maybe_rhs_val = try sema.resolveValueIntable(rhs);14005 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1400714006
14008 if (maybe_rhs_val) |rhs_val| {14007 if (maybe_rhs_val) |rhs_val| {
14009 if (rhs_val.isUndef(mod)) {14008 if (rhs_val.isUndef(zcu)) {
14010 return pt.undefRef(sema.typeOf(lhs));14009 return pt.undefRef(sema.typeOf(lhs));
14011 }14010 }
14012 // If rhs is 0, return lhs without doing any calculations.14011 // If rhs is 0, return lhs without doing any calculations.
14013 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {14012 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
14014 return lhs;14013 return lhs;
14015 }14014 }
14016 if (scalar_ty.zigTypeTag(mod) != .ComptimeInt and air_tag != .shl_sat) {14015 if (scalar_ty.zigTypeTag(zcu) != .ComptimeInt and air_tag != .shl_sat) {
14017 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(mod).bits);14016 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(zcu).bits);
14018 if (rhs_ty.zigTypeTag(mod) == .Vector) {14017 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
14019 var i: usize = 0;14018 var i: usize = 0;
14020 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {14019 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14021 const rhs_elem = try rhs_val.elemValue(pt, i);14020 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)) {
14023 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{14022 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
14024 rhs_elem.fmtValueSema(pt, sema),14023 rhs_elem.fmtValueSema(pt, sema),
14025 i,14024 i,
...@@ -14027,25 +14026,25 @@ fn zirShl(...@@ -14027,25 +14026,25 @@ fn zirShl(
14027 });14026 });
14028 }14027 }
14029 }14028 }
14030 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {14029 } else if (rhs_val.compareHetero(.gte, bit_value, zcu)) {
14031 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{14030 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
14032 rhs_val.fmtValueSema(pt, sema),14031 rhs_val.fmtValueSema(pt, sema),
14033 scalar_ty.fmt(pt),14032 scalar_ty.fmt(pt),
14034 });14033 });
14035 }14034 }
14036 }14035 }
14037 if (rhs_ty.zigTypeTag(mod) == .Vector) {14036 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
14038 var i: usize = 0;14037 var i: usize = 0;
14039 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {14038 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14040 const rhs_elem = try rhs_val.elemValue(pt, i);14039 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)) {
14042 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{14041 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
14043 rhs_elem.fmtValueSema(pt, sema),14042 rhs_elem.fmtValueSema(pt, sema),
14044 i,14043 i,
14045 });14044 });
14046 }14045 }
14047 }14046 }
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)) {
14049 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{14048 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
14050 rhs_val.fmtValueSema(pt, sema),14049 rhs_val.fmtValueSema(pt, sema),
14051 });14050 });
...@@ -14053,19 +14052,19 @@ fn zirShl(...@@ -14053,19 +14052,19 @@ fn zirShl(
14053 }14052 }
1405414053
14055 const runtime_src = if (maybe_lhs_val) |lhs_val| rs: {14054 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);
14057 const rhs_val = maybe_rhs_val orelse {14056 const rhs_val = maybe_rhs_val orelse {
14058 if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) {14057 if (scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
14059 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});14058 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
14060 }14059 }
14061 break :rs rhs_src;14060 break :rs rhs_src;
14062 };14061 };
14063 const val = if (scalar_ty.zigTypeTag(mod) == .ComptimeInt)14062 const val = if (scalar_ty.zigTypeTag(zcu) == .ComptimeInt)
14064 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, pt)14063 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, pt)
14065 else switch (air_tag) {14064 else switch (air_tag) {
14066 .shl_exact => val: {14065 .shl_exact => val: {
14067 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, pt);14066 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)) {
14069 break :val shifted.wrapped_result;14068 break :val shifted.wrapped_result;
14070 }14069 }
14071 return sema.fail(block, src, "operation caused overflow", .{});14070 return sema.fail(block, src, "operation caused overflow", .{});
...@@ -14080,7 +14079,7 @@ fn zirShl(...@@ -14080,7 +14079,7 @@ fn zirShl(
14080 const new_rhs = if (air_tag == .shl_sat) rhs: {14079 const new_rhs = if (air_tag == .shl_sat) rhs: {
14081 // Limit the RHS type for saturating shl to be an integer as small as the LHS.14080 // Limit the RHS type for saturating shl to be an integer as small as the LHS.
14082 if (rhs_is_comptime_int or14081 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)
14084 {14083 {
14085 const max_int = Air.internedToRef((try lhs_ty.maxInt(pt, lhs_ty)).toIntern());14084 const max_int = Air.internedToRef((try lhs_ty.maxInt(pt, lhs_ty)).toIntern());
14086 const rhs_limited = try sema.analyzeMinMax(block, rhs_src, .min, &.{ rhs, max_int }, &.{ rhs_src, rhs_src });14085 const rhs_limited = try sema.analyzeMinMax(block, rhs_src, .min, &.{ rhs, max_int }, &.{ rhs_src, rhs_src });
...@@ -14092,10 +14091,10 @@ fn zirShl(...@@ -14092,10 +14091,10 @@ fn zirShl(
1409214091
14093 try sema.requireRuntimeBlock(block, src, runtime_src);14092 try sema.requireRuntimeBlock(block, src, runtime_src);
14094 if (block.wantSafety()) {14093 if (block.wantSafety()) {
14095 const bit_count = scalar_ty.intInfo(mod).bits;14094 const bit_count = scalar_ty.intInfo(zcu).bits;
14096 if (!std.math.isPowerOfTwo(bit_count)) {14095 if (!std.math.isPowerOfTwo(bit_count)) {
14097 const bit_count_val = try pt.intValue(scalar_rhs_ty, bit_count);14096 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: {
14099 const bit_count_inst = Air.internedToRef((try sema.splat(rhs_ty, bit_count_val)).toIntern());14098 const bit_count_inst = Air.internedToRef((try sema.splat(rhs_ty, bit_count_val)).toIntern());
14100 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);14099 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);
14101 break :ok try block.addInst(.{14100 break :ok try block.addInst(.{
...@@ -14125,7 +14124,7 @@ fn zirShl(...@@ -14125,7 +14124,7 @@ fn zirShl(
14125 } },14124 } },
14126 });14125 });
14127 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);14126 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)
14129 try block.addInst(.{14128 try block.addInst(.{
14130 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,14129 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
14131 .data = .{ .reduce = .{14130 .data = .{ .reduce = .{
...@@ -14155,7 +14154,7 @@ fn zirShr(...@@ -14155,7 +14154,7 @@ fn zirShr(
14155 defer tracy.end();14154 defer tracy.end();
1415614155
14157 const pt = sema.pt;14156 const pt = sema.pt;
14158 const mod = pt.zcu;14157 const zcu = pt.zcu;
14159 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14158 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14160 const src = block.nodeOffset(inst_data.src_node);14159 const src = block.nodeOffset(inst_data.src_node);
14161 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });14160 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
...@@ -14166,26 +14165,26 @@ fn zirShr(...@@ -14166,26 +14165,26 @@ fn zirShr(
14166 const lhs_ty = sema.typeOf(lhs);14165 const lhs_ty = sema.typeOf(lhs);
14167 const rhs_ty = sema.typeOf(rhs);14166 const rhs_ty = sema.typeOf(rhs);
14168 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);14167 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
14171 const maybe_lhs_val = try sema.resolveValueIntable(lhs);14170 const maybe_lhs_val = try sema.resolveValueIntable(lhs);
14172 const maybe_rhs_val = try sema.resolveValueIntable(rhs);14171 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1417314172
14174 const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {14173 const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {
14175 if (rhs_val.isUndef(mod)) {14174 if (rhs_val.isUndef(zcu)) {
14176 return pt.undefRef(lhs_ty);14175 return pt.undefRef(lhs_ty);
14177 }14176 }
14178 // If rhs is 0, return lhs without doing any calculations.14177 // If rhs is 0, return lhs without doing any calculations.
14179 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {14178 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
14180 return lhs;14179 return lhs;
14181 }14180 }
14182 if (scalar_ty.zigTypeTag(mod) != .ComptimeInt) {14181 if (scalar_ty.zigTypeTag(zcu) != .ComptimeInt) {
14183 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(mod).bits);14182 const bit_value = try pt.intValue(Type.comptime_int, scalar_ty.intInfo(zcu).bits);
14184 if (rhs_ty.zigTypeTag(mod) == .Vector) {14183 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
14185 var i: usize = 0;14184 var i: usize = 0;
14186 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {14185 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14187 const rhs_elem = try rhs_val.elemValue(pt, i);14186 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)) {
14189 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{14188 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
14190 rhs_elem.fmtValueSema(pt, sema),14189 rhs_elem.fmtValueSema(pt, sema),
14191 i,14190 i,
...@@ -14193,31 +14192,31 @@ fn zirShr(...@@ -14193,31 +14192,31 @@ fn zirShr(
14193 });14192 });
14194 }14193 }
14195 }14194 }
14196 } else if (rhs_val.compareHetero(.gte, bit_value, pt)) {14195 } else if (rhs_val.compareHetero(.gte, bit_value, zcu)) {
14197 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{14196 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
14198 rhs_val.fmtValueSema(pt, sema),14197 rhs_val.fmtValueSema(pt, sema),
14199 scalar_ty.fmt(pt),14198 scalar_ty.fmt(pt),
14200 });14199 });
14201 }14200 }
14202 }14201 }
14203 if (rhs_ty.zigTypeTag(mod) == .Vector) {14202 if (rhs_ty.zigTypeTag(zcu) == .Vector) {
14204 var i: usize = 0;14203 var i: usize = 0;
14205 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {14204 while (i < rhs_ty.vectorLen(zcu)) : (i += 1) {
14206 const rhs_elem = try rhs_val.elemValue(pt, i);14205 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)) {
14208 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{14207 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
14209 rhs_elem.fmtValueSema(pt, sema),14208 rhs_elem.fmtValueSema(pt, sema),
14210 i,14209 i,
14211 });14210 });
14212 }14211 }
14213 }14212 }
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)) {
14215 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{14214 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
14216 rhs_val.fmtValueSema(pt, sema),14215 rhs_val.fmtValueSema(pt, sema),
14217 });14216 });
14218 }14217 }
14219 if (maybe_lhs_val) |lhs_val| {14218 if (maybe_lhs_val) |lhs_val| {
14220 if (lhs_val.isUndef(mod)) {14219 if (lhs_val.isUndef(zcu)) {
14221 return pt.undefRef(lhs_ty);14220 return pt.undefRef(lhs_ty);
14222 }14221 }
14223 if (air_tag == .shr_exact) {14222 if (air_tag == .shr_exact) {
...@@ -14234,18 +14233,18 @@ fn zirShr(...@@ -14234,18 +14233,18 @@ fn zirShr(
14234 }14233 }
14235 } else rhs_src;14234 } 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) {
14238 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});14237 return sema.fail(block, src, "LHS of shift must be a fixed-width integer type, or RHS must be comptime-known", .{});
14239 }14238 }
1424014239
14241 try sema.requireRuntimeBlock(block, src, runtime_src);14240 try sema.requireRuntimeBlock(block, src, runtime_src);
14242 const result = try block.addBinOp(air_tag, lhs, rhs);14241 const result = try block.addBinOp(air_tag, lhs, rhs);
14243 if (block.wantSafety()) {14242 if (block.wantSafety()) {
14244 const bit_count = scalar_ty.intInfo(mod).bits;14243 const bit_count = scalar_ty.intInfo(zcu).bits;
14245 if (!std.math.isPowerOfTwo(bit_count)) {14244 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: {
14249 const bit_count_inst = Air.internedToRef((try sema.splat(rhs_ty, bit_count_val)).toIntern());14248 const bit_count_inst = Air.internedToRef((try sema.splat(rhs_ty, bit_count_val)).toIntern());
14250 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);14249 const lt = try block.addCmpVector(rhs, bit_count_inst, .lt);
14251 break :ok try block.addInst(.{14250 break :ok try block.addInst(.{
...@@ -14265,7 +14264,7 @@ fn zirShr(...@@ -14265,7 +14264,7 @@ fn zirShr(
14265 if (air_tag == .shr_exact) {14264 if (air_tag == .shr_exact) {
14266 const back = try block.addBinOp(.shl, result, rhs);14265 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: {
14269 const eql = try block.addCmpVector(lhs, back, .eq);14268 const eql = try block.addCmpVector(lhs, back, .eq);
14270 break :ok try block.addInst(.{14269 break :ok try block.addInst(.{
14271 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,14270 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
...@@ -14291,7 +14290,7 @@ fn zirBitwise(...@@ -14291,7 +14290,7 @@ fn zirBitwise(
14291 defer tracy.end();14290 defer tracy.end();
1429214291
14293 const pt = sema.pt;14292 const pt = sema.pt;
14294 const mod = pt.zcu;14293 const zcu = pt.zcu;
14295 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14294 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14296 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });14295 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
14297 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });14296 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
...@@ -14305,8 +14304,8 @@ fn zirBitwise(...@@ -14305,8 +14304,8 @@ fn zirBitwise(
1430514304
14306 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };14305 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
14307 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });14306 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
14308 const scalar_type = resolved_type.scalarType(mod);14307 const scalar_type = resolved_type.scalarType(zcu);
14309 const scalar_tag = scalar_type.zigTypeTag(mod);14308 const scalar_tag = scalar_type.zigTypeTag(zcu);
1431014309
14311 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);14310 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
14312 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);14311 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
...@@ -14314,7 +14313,7 @@ fn zirBitwise(...@@ -14314,7 +14313,7 @@ fn zirBitwise(
14314 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;14313 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1431514314
14316 if (!is_int) {14315 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)) });
14318 }14317 }
1431914318
14320 const runtime_src = runtime: {14319 const runtime_src = runtime: {
...@@ -14346,26 +14345,26 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -14346,26 +14345,26 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
14346 defer tracy.end();14345 defer tracy.end();
1434714346
14348 const pt = sema.pt;14347 const pt = sema.pt;
14349 const mod = pt.zcu;14348 const zcu = pt.zcu;
14350 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;14349 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
14351 const src = block.nodeOffset(inst_data.src_node);14350 const src = block.nodeOffset(inst_data.src_node);
14352 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });14351 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1435314352
14354 const operand = try sema.resolveInst(inst_data.operand);14353 const operand = try sema.resolveInst(inst_data.operand);
14355 const operand_type = sema.typeOf(operand);14354 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) {
14359 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{14358 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{
14360 operand_type.fmt(pt),14359 operand_type.fmt(pt),
14361 });14360 });
14362 }14361 }
1436314362
14364 if (try sema.resolveValue(operand)) |val| {14363 if (try sema.resolveValue(operand)) |val| {
14365 if (val.isUndef(mod)) {14364 if (val.isUndef(zcu)) {
14366 return pt.undefRef(operand_type);14365 return pt.undefRef(operand_type);
14367 } else if (operand_type.zigTypeTag(mod) == .Vector) {14366 } else if (operand_type.zigTypeTag(zcu) == .Vector) {
14368 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));14367 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(zcu));
14369 const elems = try sema.arena.alloc(InternPool.Index, vec_len);14368 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
14370 for (elems, 0..) |*elem, i| {14369 for (elems, 0..) |*elem, i| {
14371 const elem_val = try val.elemValue(pt, i);14370 const elem_val = try val.elemValue(pt, i);
...@@ -14393,13 +14392,13 @@ fn analyzeTupleCat(...@@ -14393,13 +14392,13 @@ fn analyzeTupleCat(
14393 rhs: Air.Inst.Ref,14392 rhs: Air.Inst.Ref,
14394) CompileError!Air.Inst.Ref {14393) CompileError!Air.Inst.Ref {
14395 const pt = sema.pt;14394 const pt = sema.pt;
14396 const mod = pt.zcu;14395 const zcu = pt.zcu;
14397 const lhs_ty = sema.typeOf(lhs);14396 const lhs_ty = sema.typeOf(lhs);
14398 const rhs_ty = sema.typeOf(rhs);14397 const rhs_ty = sema.typeOf(rhs);
14399 const src = block.nodeOffset(src_node);14398 const src = block.nodeOffset(src_node);
1440014399
14401 const lhs_len = lhs_ty.structFieldCount(mod);14400 const lhs_len = lhs_ty.structFieldCount(zcu);
14402 const rhs_len = rhs_ty.structFieldCount(mod);14401 const rhs_len = rhs_ty.structFieldCount(zcu);
14403 const dest_fields = lhs_len + rhs_len;14402 const dest_fields = lhs_len + rhs_len;
1440414403
14405 if (dest_fields == 0) {14404 if (dest_fields == 0) {
...@@ -14420,8 +14419,8 @@ fn analyzeTupleCat(...@@ -14420,8 +14419,8 @@ fn analyzeTupleCat(
14420 var runtime_src: ?LazySrcLoc = null;14419 var runtime_src: ?LazySrcLoc = null;
14421 var i: u32 = 0;14420 var i: u32 = 0;
14422 while (i < lhs_len) : (i += 1) {14421 while (i < lhs_len) : (i += 1) {
14423 types[i] = lhs_ty.structFieldType(i, mod).toIntern();14422 types[i] = lhs_ty.fieldType(i, zcu).toIntern();
14424 const default_val = lhs_ty.structFieldDefaultValue(i, mod);14423 const default_val = lhs_ty.structFieldDefaultValue(i, zcu);
14425 values[i] = default_val.toIntern();14424 values[i] = default_val.toIntern();
14426 const operand_src = block.src(.{ .array_cat_lhs = .{14425 const operand_src = block.src(.{ .array_cat_lhs = .{
14427 .array_cat_offset = src_node,14426 .array_cat_offset = src_node,
...@@ -14434,8 +14433,8 @@ fn analyzeTupleCat(...@@ -14434,8 +14433,8 @@ fn analyzeTupleCat(
14434 }14433 }
14435 i = 0;14434 i = 0;
14436 while (i < rhs_len) : (i += 1) {14435 while (i < rhs_len) : (i += 1) {
14437 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();14436 types[i + lhs_len] = rhs_ty.fieldType(i, zcu).toIntern();
14438 const default_val = rhs_ty.structFieldDefaultValue(i, mod);14437 const default_val = rhs_ty.structFieldDefaultValue(i, zcu);
14439 values[i + lhs_len] = default_val.toIntern();14438 values[i + lhs_len] = default_val.toIntern();
14440 const operand_src = block.src(.{ .array_cat_rhs = .{14439 const operand_src = block.src(.{ .array_cat_rhs = .{
14441 .array_cat_offset = src_node,14440 .array_cat_offset = src_node,
...@@ -14449,7 +14448,7 @@ fn analyzeTupleCat(...@@ -14449,7 +14448,7 @@ fn analyzeTupleCat(
14449 break :rs runtime_src;14448 break :rs runtime_src;
14450 };14449 };
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, .{
14453 .types = types,14452 .types = types,
14454 .values = values,14453 .values = values,
14455 .names = &.{},14454 .names = &.{},
...@@ -14492,7 +14491,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14492,7 +14491,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14492 defer tracy.end();14491 defer tracy.end();
1449314492
14494 const pt = sema.pt;14493 const pt = sema.pt;
14495 const mod = pt.zcu;14494 const zcu = pt.zcu;
14496 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14495 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14497 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14496 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14498 const lhs = try sema.resolveInst(extra.lhs);14497 const lhs = try sema.resolveInst(extra.lhs);
...@@ -14501,8 +14500,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14501,8 +14500,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14501 const rhs_ty = sema.typeOf(rhs);14500 const rhs_ty = sema.typeOf(rhs);
14502 const src = block.nodeOffset(inst_data.src_node);14501 const src = block.nodeOffset(inst_data.src_node);
1450314502
14504 const lhs_is_tuple = lhs_ty.isTuple(mod);14503 const lhs_is_tuple = lhs_ty.isTuple(zcu);
14505 const rhs_is_tuple = rhs_ty.isTuple(mod);14504 const rhs_is_tuple = rhs_ty.isTuple(zcu);
14506 if (lhs_is_tuple and rhs_is_tuple) {14505 if (lhs_is_tuple and rhs_is_tuple) {
14507 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);14506 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);
14508 }14507 }
...@@ -14584,31 +14583,31 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14584,31 +14583,31 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14584 .child = resolved_elem_ty.toIntern(),14583 .child = resolved_elem_ty.toIntern(),
14585 });14584 });
14586 const ptr_addrspace = p: {14585 const ptr_addrspace = p: {
14587 if (lhs_ty.zigTypeTag(mod) == .Pointer) break :p lhs_ty.ptrAddressSpace(mod);14586 if (lhs_ty.zigTypeTag(zcu) == .Pointer) break :p lhs_ty.ptrAddressSpace(zcu);
14588 if (rhs_ty.zigTypeTag(mod) == .Pointer) break :p rhs_ty.ptrAddressSpace(mod);14587 if (rhs_ty.zigTypeTag(zcu) == .Pointer) break :p rhs_ty.ptrAddressSpace(zcu);
14589 break :p null;14588 break :p null;
14590 };14589 };
1459114590
14592 const runtime_src = if (switch (lhs_ty.zigTypeTag(mod)) {14591 const runtime_src = if (switch (lhs_ty.zigTypeTag(zcu)) {
14593 .Array, .Struct => try sema.resolveValue(lhs),14592 .Array, .Struct => try sema.resolveValue(lhs),
14594 .Pointer => try sema.resolveDefinedValue(block, lhs_src, lhs),14593 .Pointer => try sema.resolveDefinedValue(block, lhs_src, lhs),
14595 else => unreachable,14594 else => unreachable,
14596 }) |lhs_val| rs: {14595 }) |lhs_val| rs: {
14597 if (switch (rhs_ty.zigTypeTag(mod)) {14596 if (switch (rhs_ty.zigTypeTag(zcu)) {
14598 .Array, .Struct => try sema.resolveValue(rhs),14597 .Array, .Struct => try sema.resolveValue(rhs),
14599 .Pointer => try sema.resolveDefinedValue(block, rhs_src, rhs),14598 .Pointer => try sema.resolveDefinedValue(block, rhs_src, rhs),
14600 else => unreachable,14599 else => unreachable,
14601 }) |rhs_val| {14600 }) |rhs_val| {
14602 const lhs_sub_val = if (lhs_ty.isSinglePointer(mod))14601 const lhs_sub_val = if (lhs_ty.isSinglePointer(zcu))
14603 try sema.pointerDeref(block, lhs_src, lhs_val, lhs_ty) orelse break :rs lhs_src14602 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))
14605 try sema.maybeDerefSliceAsArray(block, lhs_src, lhs_val) orelse break :rs lhs_src14604 try sema.maybeDerefSliceAsArray(block, lhs_src, lhs_val) orelse break :rs lhs_src
14606 else14605 else
14607 lhs_val;14606 lhs_val;
1460814607
14609 const rhs_sub_val = if (rhs_ty.isSinglePointer(mod))14608 const rhs_sub_val = if (rhs_ty.isSinglePointer(zcu))
14610 try sema.pointerDeref(block, rhs_src, rhs_val, rhs_ty) orelse break :rs rhs_src14609 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))
14612 try sema.maybeDerefSliceAsArray(block, rhs_src, rhs_val) orelse break :rs rhs_src14611 try sema.maybeDerefSliceAsArray(block, rhs_src, rhs_val) orelse break :rs rhs_src
14613 else14612 else
14614 rhs_val;14613 rhs_val;
...@@ -14617,7 +14616,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14617,7 +14616,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14617 var elem_i: u32 = 0;14616 var elem_i: u32 = 0;
14618 while (elem_i < lhs_len) : (elem_i += 1) {14617 while (elem_i < lhs_len) : (elem_i += 1) {
14619 const lhs_elem_i = elem_i;14618 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";
14621 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(pt, lhs_elem_i) else elem_default_val;14620 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(pt, lhs_elem_i) else elem_default_val;
14622 const elem_val_inst = Air.internedToRef(elem_val.toIntern());14621 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14623 const operand_src = block.src(.{ .array_cat_lhs = .{14622 const operand_src = block.src(.{ .array_cat_lhs = .{
...@@ -14630,7 +14629,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14630,7 +14629,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14630 }14629 }
14631 while (elem_i < result_len) : (elem_i += 1) {14630 while (elem_i < result_len) : (elem_i += 1) {
14632 const rhs_elem_i = elem_i - lhs_len;14631 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";
14634 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(pt, rhs_elem_i) else elem_default_val;14633 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(pt, rhs_elem_i) else elem_default_val;
14635 const elem_val_inst = Air.internedToRef(elem_val.toIntern());14634 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14636 const operand_src = block.src(.{ .array_cat_rhs = .{14635 const operand_src = block.src(.{ .array_cat_rhs = .{
...@@ -14723,12 +14722,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14723,12 +14722,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1472314722
14724fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref, peer_ty: Type) !?Type.ArrayInfo {14723fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Inst.Ref, peer_ty: Type) !?Type.ArrayInfo {
14725 const pt = sema.pt;14724 const pt = sema.pt;
14726 const mod = pt.zcu;14725 const zcu = pt.zcu;
14727 const operand_ty = sema.typeOf(operand);14726 const operand_ty = sema.typeOf(operand);
14728 switch (operand_ty.zigTypeTag(mod)) {14727 switch (operand_ty.zigTypeTag(zcu)) {
14729 .Array => return operand_ty.arrayInfo(mod),14728 .Array => return operand_ty.arrayInfo(zcu),
14730 .Pointer => {14729 .Pointer => {
14731 const ptr_info = operand_ty.ptrInfo(mod);14730 const ptr_info = operand_ty.ptrInfo(zcu);
14732 switch (ptr_info.flags.size) {14731 switch (ptr_info.flags.size) {
14733 .Slice => {14732 .Slice => {
14734 const val = try sema.resolveConstDefinedValue(block, src, operand, .{14733 const val = try sema.resolveConstDefinedValue(block, src, operand, .{
...@@ -14744,20 +14743,20 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins...@@ -14744,20 +14743,20 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
14744 };14743 };
14745 },14744 },
14746 .One => {14745 .One => {
14747 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {14746 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Array) {
14748 return Type.fromInterned(ptr_info.child).arrayInfo(mod);14747 return Type.fromInterned(ptr_info.child).arrayInfo(zcu);
14749 }14748 }
14750 },14749 },
14751 .C, .Many => {},14750 .C, .Many => {},
14752 }14751 }
14753 },14752 },
14754 .Struct => {14753 .Struct => {
14755 if (operand_ty.isTuple(mod) and peer_ty.isIndexable(mod)) {14754 if (operand_ty.isTuple(zcu) and peer_ty.isIndexable(zcu)) {
14756 assert(!peer_ty.isTuple(mod));14755 assert(!peer_ty.isTuple(zcu));
14757 return .{14756 return .{
14758 .elem_type = peer_ty.elemType2(mod),14757 .elem_type = peer_ty.elemType2(zcu),
14759 .sentinel = null,14758 .sentinel = null,
14760 .len = operand_ty.arrayLen(mod),14759 .len = operand_ty.arrayLen(zcu),
14761 };14760 };
14762 }14761 }
14763 },14762 },
...@@ -14774,12 +14773,12 @@ fn analyzeTupleMul(...@@ -14774,12 +14773,12 @@ fn analyzeTupleMul(
14774 factor: usize,14773 factor: usize,
14775) CompileError!Air.Inst.Ref {14774) CompileError!Air.Inst.Ref {
14776 const pt = sema.pt;14775 const pt = sema.pt;
14777 const mod = pt.zcu;14776 const zcu = pt.zcu;
14778 const operand_ty = sema.typeOf(operand);14777 const operand_ty = sema.typeOf(operand);
14779 const src = block.nodeOffset(src_node);14778 const src = block.nodeOffset(src_node);
14780 const len_src = block.src(.{ .node_offset_bin_rhs = src_node });14779 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);
14783 const final_len = std.math.mul(usize, tuple_len, factor) catch14782 const final_len = std.math.mul(usize, tuple_len, factor) catch
14784 return sema.fail(block, len_src, "operation results in overflow", .{});14783 return sema.fail(block, len_src, "operation results in overflow", .{});
1478514784
...@@ -14792,8 +14791,8 @@ fn analyzeTupleMul(...@@ -14792,8 +14791,8 @@ fn analyzeTupleMul(
14792 const opt_runtime_src = rs: {14791 const opt_runtime_src = rs: {
14793 var runtime_src: ?LazySrcLoc = null;14792 var runtime_src: ?LazySrcLoc = null;
14794 for (0..tuple_len) |i| {14793 for (0..tuple_len) |i| {
14795 types[i] = operand_ty.structFieldType(i, mod).toIntern();14794 types[i] = operand_ty.fieldType(i, zcu).toIntern();
14796 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();14795 values[i] = operand_ty.structFieldDefaultValue(i, zcu).toIntern();
14797 const operand_src = block.src(.{ .array_cat_lhs = .{14796 const operand_src = block.src(.{ .array_cat_lhs = .{
14798 .array_cat_offset = src_node,14797 .array_cat_offset = src_node,
14799 .elem_index = @intCast(i),14798 .elem_index = @intCast(i),
...@@ -14810,7 +14809,7 @@ fn analyzeTupleMul(...@@ -14810,7 +14809,7 @@ fn analyzeTupleMul(
14810 break :rs runtime_src;14809 break :rs runtime_src;
14811 };14810 };
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, .{
14814 .types = types,14813 .types = types,
14815 .values = values,14814 .values = values,
14816 .names = &.{},14815 .names = &.{},
...@@ -14848,7 +14847,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14848,7 +14847,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14848 defer tracy.end();14847 defer tracy.end();
1484914848
14850 const pt = sema.pt;14849 const pt = sema.pt;
14851 const mod = pt.zcu;14850 const zcu = pt.zcu;
14852 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14851 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14853 const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;14852 const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data;
14854 const uncoerced_lhs = try sema.resolveInst(extra.lhs);14853 const uncoerced_lhs = try sema.resolveInst(extra.lhs);
...@@ -14867,17 +14866,17 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14867,17 +14866,17 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14867 const res_ty_inst = try sema.resolveInst(extra.res_ty);14866 const res_ty_inst = try sema.resolveInst(extra.res_ty);
14868 const res_ty = try sema.analyzeAsType(block, src, res_ty_inst);14867 const res_ty = try sema.analyzeAsType(block, src, res_ty_inst);
14869 if (res_ty.isGenericPoison()) break :no_coerce;14868 if (res_ty.isGenericPoison()) break :no_coerce;
14870 if (!uncoerced_lhs_ty.isTuple(mod)) break :no_coerce;14869 if (!uncoerced_lhs_ty.isTuple(zcu)) break :no_coerce;
14871 const lhs_len = uncoerced_lhs_ty.structFieldCount(mod);14870 const lhs_len = uncoerced_lhs_ty.structFieldCount(zcu);
14872 const lhs_dest_ty = switch (res_ty.zigTypeTag(mod)) {14871 const lhs_dest_ty = switch (res_ty.zigTypeTag(zcu)) {
14873 else => break :no_coerce,14872 else => break :no_coerce,
14874 .Array => try pt.arrayType(.{14873 .Array => try pt.arrayType(.{
14875 .child = res_ty.childType(mod).toIntern(),14874 .child = res_ty.childType(zcu).toIntern(),
14876 .len = lhs_len,14875 .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,
14878 }),14877 }),
14879 .Vector => try pt.vectorType(.{14878 .Vector => try pt.vectorType(.{
14880 .child = res_ty.childType(mod).toIntern(),14879 .child = res_ty.childType(zcu).toIntern(),
14881 .len = lhs_len,14880 .len = lhs_len,
14882 }),14881 }),
14883 };14882 };
...@@ -14893,7 +14892,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14893,7 +14892,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14893 break :coerced_lhs .{ uncoerced_lhs, uncoerced_lhs_ty };14892 break :coerced_lhs .{ uncoerced_lhs, uncoerced_lhs_ty };
14894 };14893 };
1489514894
14896 if (lhs_ty.isTuple(mod)) {14895 if (lhs_ty.isTuple(zcu)) {
14897 // In `**` rhs must be comptime-known, but lhs can be runtime-known14896 // In `**` rhs must be comptime-known, but lhs can be runtime-known
14898 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{14897 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{
14899 .needed_comptime_reason = "array multiplication factor must be comptime-known",14898 .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...@@ -14907,7 +14906,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14907 const msg = msg: {14906 const msg = msg: {
14908 const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(pt)});14907 const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(pt)});
14909 errdefer msg.destroy(sema.gpa);14908 errdefer msg.destroy(sema.gpa);
14910 switch (lhs_ty.zigTypeTag(mod)) {14909 switch (lhs_ty.zigTypeTag(zcu)) {
14911 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {14910 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {
14912 try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});14911 try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});
14913 },14912 },
...@@ -14933,13 +14932,13 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14933,13 +14932,13 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14933 .child = lhs_info.elem_type.toIntern(),14932 .child = lhs_info.elem_type.toIntern(),
14934 });14933 });
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;
14937 const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len);14936 const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len);
1493814937
14939 if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| ct: {14938 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))
14941 try sema.pointerDeref(block, lhs_src, lhs_val, lhs_ty) orelse break :ct14940 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))
14943 try sema.maybeDerefSliceAsArray(block, lhs_src, lhs_val) orelse break :ct14942 try sema.maybeDerefSliceAsArray(block, lhs_src, lhs_val) orelse break :ct
14944 else14943 else
14945 lhs_val;14944 lhs_val;
...@@ -15022,7 +15021,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15022,7 +15021,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1502215021
15023fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15022fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15024 const pt = sema.pt;15023 const pt = sema.pt;
15025 const mod = pt.zcu;15024 const zcu = pt.zcu;
15026 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;15025 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
15027 const src = block.nodeOffset(inst_data.src_node);15026 const src = block.nodeOffset(inst_data.src_node);
15028 const lhs_src = src;15027 const lhs_src = src;
...@@ -15030,9 +15029,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15030,9 +15029,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1503015029
15031 const rhs = try sema.resolveInst(inst_data.operand);15030 const rhs = try sema.resolveInst(inst_data.operand);
15032 const rhs_ty = sema.typeOf(rhs);15031 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)) {
15036 .Int, .ComptimeInt, .Float, .ComptimeFloat => false,15035 .Int, .ComptimeInt, .Float, .ComptimeFloat => false,
15037 else => true,15036 else => true,
15038 }) {15037 }) {
...@@ -15042,7 +15041,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15042,7 +15041,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15042 if (rhs_scalar_ty.isAnyFloat()) {15041 if (rhs_scalar_ty.isAnyFloat()) {
15043 // We handle float negation here to ensure negative zero is represented in the bits.15042 // We handle float negation here to ensure negative zero is represented in the bits.
15044 if (try sema.resolveValue(rhs)) |rhs_val| {15043 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);
15046 return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, pt)).toIntern());15045 return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, pt)).toIntern());
15047 }15046 }
15048 try sema.requireRuntimeBlock(block, src, null);15047 try sema.requireRuntimeBlock(block, src, null);
...@@ -15055,7 +15054,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15055,7 +15054,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1505515054
15056fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15055fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15057 const pt = sema.pt;15056 const pt = sema.pt;
15058 const mod = pt.zcu;15057 const zcu = pt.zcu;
15059 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;15058 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
15060 const src = block.nodeOffset(inst_data.src_node);15059 const src = block.nodeOffset(inst_data.src_node);
15061 const lhs_src = src;15060 const lhs_src = src;
...@@ -15063,9 +15062,9 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -15063,9 +15062,9 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1506315062
15064 const rhs = try sema.resolveInst(inst_data.operand);15063 const rhs = try sema.resolveInst(inst_data.operand);
15065 const rhs_ty = sema.typeOf(rhs);15064 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)) {
15069 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},15068 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},
15070 else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(pt)}),15069 else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(pt)}),
15071 }15070 }
...@@ -15097,7 +15096,7 @@ fn zirArithmetic(...@@ -15097,7 +15096,7 @@ fn zirArithmetic(
1509715096
15098fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15097fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15099 const pt = sema.pt;15098 const pt = sema.pt;
15100 const mod = pt.zcu;15099 const zcu = pt.zcu;
15101 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15100 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15102 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });15101 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15103 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });15102 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...@@ -15107,8 +15106,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15107 const rhs = try sema.resolveInst(extra.rhs);15106 const rhs = try sema.resolveInst(extra.rhs);
15108 const lhs_ty = sema.typeOf(lhs);15107 const lhs_ty = sema.typeOf(lhs);
15109 const rhs_ty = sema.typeOf(rhs);15108 const rhs_ty = sema.typeOf(rhs);
15110 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);15109 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15111 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);15110 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
15112 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);15111 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
15113 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);15112 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...@@ -15120,9 +15119,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15120 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15119 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
15121 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);15120 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1512215121
15123 const lhs_scalar_ty = lhs_ty.scalarType(mod);15122 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15124 const rhs_scalar_ty = rhs_ty.scalarType(mod);15123 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15125 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);15124 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1512615125
15127 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;15126 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...@@ -15131,15 +15130,15 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15131 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);15130 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
15132 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);15131 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1513315132
15134 if ((lhs_ty.zigTypeTag(mod) == .ComptimeFloat and rhs_ty.zigTypeTag(mod) == .ComptimeInt) or15133 if ((lhs_ty.zigTypeTag(zcu) == .ComptimeFloat and rhs_ty.zigTypeTag(zcu) == .ComptimeInt) or
15135 (lhs_ty.zigTypeTag(mod) == .ComptimeInt and rhs_ty.zigTypeTag(mod) == .ComptimeFloat))15134 (lhs_ty.zigTypeTag(zcu) == .ComptimeInt and rhs_ty.zigTypeTag(zcu) == .ComptimeFloat))
15136 {15135 {
15137 // If it makes a difference whether we coerce to ints or floats before doing the division, error.15136 // If it makes a difference whether we coerce to ints or floats before doing the division, error.
15138 // If lhs % rhs is 0, it doesn't matter.15137 // If lhs % rhs is 0, it doesn't matter.
15139 const lhs_val = maybe_lhs_val orelse unreachable;15138 const lhs_val = maybe_lhs_val orelse unreachable;
15140 const rhs_val = maybe_rhs_val orelse unreachable;15139 const rhs_val = maybe_rhs_val orelse unreachable;
15141 const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, pt) catch unreachable;15140 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)) {
15143 return sema.fail(15142 return sema.fail(
15144 block,15143 block,
15145 src,15144 src,
...@@ -15179,11 +15178,11 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15179,11 +15178,11 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15179 switch (scalar_tag) {15178 switch (scalar_tag) {
15180 .Int, .ComptimeInt, .ComptimeFloat => {15179 .Int, .ComptimeInt, .ComptimeFloat => {
15181 if (maybe_lhs_val) |lhs_val| {15180 if (maybe_lhs_val) |lhs_val| {
15182 if (!lhs_val.isUndef(mod)) {15181 if (!lhs_val.isUndef(zcu)) {
15183 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {15182 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
15184 const scalar_zero = switch (scalar_tag) {15183 const scalar_zero = switch (scalar_tag) {
15185 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),15184 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15186 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),15185 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
15187 else => unreachable,15186 else => unreachable,
15188 };15187 };
15189 const zero_val = try sema.splat(resolved_type, scalar_zero);15188 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...@@ -15192,7 +15191,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15192 }15191 }
15193 }15192 }
15194 if (maybe_rhs_val) |rhs_val| {15193 if (maybe_rhs_val) |rhs_val| {
15195 if (rhs_val.isUndef(mod)) {15194 if (rhs_val.isUndef(zcu)) {
15196 return sema.failWithUseOfUndef(block, rhs_src);15195 return sema.failWithUseOfUndef(block, rhs_src);
15197 }15196 }
15198 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {15197 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -15206,8 +15205,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15206,8 +15205,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1520615205
15207 const runtime_src = rs: {15206 const runtime_src = rs: {
15208 if (maybe_lhs_val) |lhs_val| {15207 if (maybe_lhs_val) |lhs_val| {
15209 if (lhs_val.isUndef(mod)) {15208 if (lhs_val.isUndef(zcu)) {
15210 if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) {15209 if (lhs_scalar_ty.isSignedInt(zcu) and rhs_scalar_ty.isSignedInt(zcu)) {
15211 if (maybe_rhs_val) |rhs_val| {15210 if (maybe_rhs_val) |rhs_val| {
15212 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {15211 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {
15213 return pt.undefRef(resolved_type);15212 return pt.undefRef(resolved_type);
...@@ -15245,7 +15244,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15245,7 +15244,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15245 }15244 }
1524615245
15247 const air_tag = if (is_int) blk: {15246 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)) {
15249 return sema.fail(15248 return sema.fail(
15250 block,15249 block,
15251 src,15250 src,
...@@ -15263,7 +15262,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15263,7 +15262,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1526315262
15264fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15263fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15265 const pt = sema.pt;15264 const pt = sema.pt;
15266 const mod = pt.zcu;15265 const zcu = pt.zcu;
15267 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15266 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15268 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });15267 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15269 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });15268 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...@@ -15273,8 +15272,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15273 const rhs = try sema.resolveInst(extra.rhs);15272 const rhs = try sema.resolveInst(extra.rhs);
15274 const lhs_ty = sema.typeOf(lhs);15273 const lhs_ty = sema.typeOf(lhs);
15275 const rhs_ty = sema.typeOf(rhs);15274 const rhs_ty = sema.typeOf(rhs);
15276 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);15275 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15277 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);15276 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
15278 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);15277 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
15279 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);15278 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1528015279
...@@ -15286,8 +15285,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15286,8 +15285,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15286 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15285 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
15287 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);15286 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1528815287
15289 const lhs_scalar_ty = lhs_ty.scalarType(mod);15288 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15290 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);15289 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1529115290
15292 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;15291 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...@@ -15314,13 +15313,13 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15314 // If the lhs is undefined, compile error because there is a possible15313 // If the lhs is undefined, compile error because there is a possible
15315 // value for which the division would result in a remainder.15314 // value for which the division would result in a remainder.
15316 if (maybe_lhs_val) |lhs_val| {15315 if (maybe_lhs_val) |lhs_val| {
15317 if (lhs_val.isUndef(mod)) {15316 if (lhs_val.isUndef(zcu)) {
15318 return sema.failWithUseOfUndef(block, rhs_src);15317 return sema.failWithUseOfUndef(block, rhs_src);
15319 } else {15318 } else {
15320 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {15319 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
15321 const scalar_zero = switch (scalar_tag) {15320 const scalar_zero = switch (scalar_tag) {
15322 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),15321 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15323 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),15322 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
15324 else => unreachable,15323 else => unreachable,
15325 };15324 };
15326 const zero_val = try sema.splat(resolved_type, scalar_zero);15325 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...@@ -15329,7 +15328,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15329 }15328 }
15330 }15329 }
15331 if (maybe_rhs_val) |rhs_val| {15330 if (maybe_rhs_val) |rhs_val| {
15332 if (rhs_val.isUndef(mod)) {15331 if (rhs_val.isUndef(zcu)) {
15333 return sema.failWithUseOfUndef(block, rhs_src);15332 return sema.failWithUseOfUndef(block, rhs_src);
15334 }15333 }
15335 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {15334 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -15341,7 +15340,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15341,7 +15340,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15341 if (maybe_rhs_val) |rhs_val| {15340 if (maybe_rhs_val) |rhs_val| {
15342 if (is_int) {15341 if (is_int) {
15343 const modulus_val = try lhs_val.intMod(rhs_val, resolved_type, sema.arena, pt);15342 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))) {
15345 return sema.fail(block, src, "exact division produced remainder", .{});15344 return sema.fail(block, src, "exact division produced remainder", .{});
15346 }15345 }
15347 var overflow_idx: ?usize = null;15346 var overflow_idx: ?usize = null;
...@@ -15352,7 +15351,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15352,7 +15351,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15352 return Air.internedToRef(res.toIntern());15351 return Air.internedToRef(res.toIntern());
15353 } else {15352 } else {
15354 const modulus_val = try lhs_val.floatMod(rhs_val, resolved_type, sema.arena, pt);15353 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))) {
15356 return sema.fail(block, src, "exact division produced remainder", .{});15355 return sema.fail(block, src, "exact division produced remainder", .{});
15357 }15356 }
15358 return Air.internedToRef((try lhs_val.floatDiv(rhs_val, resolved_type, sema.arena, pt)).toIntern());15357 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...@@ -15376,7 +15375,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15376 const ok = if (!is_int) ok: {15375 const ok = if (!is_int) ok: {
15377 const floored = try block.addUnOp(.floor, result);15376 const floored = try block.addUnOp(.floor, result);
1537815377
15379 if (resolved_type.zigTypeTag(mod) == .Vector) {15378 if (resolved_type.zigTypeTag(zcu) == .Vector) {
15380 const eql = try block.addCmpVector(result, floored, .eq);15379 const eql = try block.addCmpVector(result, floored, .eq);
15381 break :ok try block.addInst(.{15380 break :ok try block.addInst(.{
15382 .tag = switch (block.float_mode) {15381 .tag = switch (block.float_mode) {
...@@ -15399,11 +15398,11 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15399,11 +15398,11 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15399 const remainder = try block.addBinOp(.rem, casted_lhs, casted_rhs);15398 const remainder = try block.addBinOp(.rem, casted_lhs, casted_rhs);
1540015399
15401 const scalar_zero = switch (scalar_tag) {15400 const scalar_zero = switch (scalar_tag) {
15402 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),15401 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15403 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),15402 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
15404 else => unreachable,15403 else => unreachable,
15405 };15404 };
15406 if (resolved_type.zigTypeTag(mod) == .Vector) {15405 if (resolved_type.zigTypeTag(zcu) == .Vector) {
15407 const zero_val = try sema.splat(resolved_type, scalar_zero);15406 const zero_val = try sema.splat(resolved_type, scalar_zero);
15408 const zero = Air.internedToRef(zero_val.toIntern());15407 const zero = Air.internedToRef(zero_val.toIntern());
15409 const eql = try block.addCmpVector(remainder, zero, .eq);15408 const eql = try block.addCmpVector(remainder, zero, .eq);
...@@ -15429,7 +15428,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15429,7 +15428,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1542915428
15430fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15429fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15431 const pt = sema.pt;15430 const pt = sema.pt;
15432 const mod = pt.zcu;15431 const zcu = pt.zcu;
15433 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15432 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15434 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });15433 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15435 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });15434 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...@@ -15439,8 +15438,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15439 const rhs = try sema.resolveInst(extra.rhs);15438 const rhs = try sema.resolveInst(extra.rhs);
15440 const lhs_ty = sema.typeOf(lhs);15439 const lhs_ty = sema.typeOf(lhs);
15441 const rhs_ty = sema.typeOf(rhs);15440 const rhs_ty = sema.typeOf(rhs);
15442 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);15441 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15443 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);15442 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
15444 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);15443 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
15445 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);15444 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1544615445
...@@ -15452,9 +15451,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15452,9 +15451,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15452 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15451 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
15453 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);15452 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1545415453
15455 const lhs_scalar_ty = lhs_ty.scalarType(mod);15454 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15456 const rhs_scalar_ty = rhs_ty.scalarType(mod);15455 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15457 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);15456 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1545815457
15459 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;15458 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...@@ -15484,11 +15483,11 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15484 // value (zero) for which the division would be illegal behavior.15483 // value (zero) for which the division would be illegal behavior.
15485 // If the lhs is undefined, result is undefined.15484 // If the lhs is undefined, result is undefined.
15486 if (maybe_lhs_val) |lhs_val| {15485 if (maybe_lhs_val) |lhs_val| {
15487 if (!lhs_val.isUndef(mod)) {15486 if (!lhs_val.isUndef(zcu)) {
15488 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {15487 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
15489 const scalar_zero = switch (scalar_tag) {15488 const scalar_zero = switch (scalar_tag) {
15490 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),15489 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15491 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),15490 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
15492 else => unreachable,15491 else => unreachable,
15493 };15492 };
15494 const zero_val = try sema.splat(resolved_type, scalar_zero);15493 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...@@ -15497,7 +15496,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15497 }15496 }
15498 }15497 }
15499 if (maybe_rhs_val) |rhs_val| {15498 if (maybe_rhs_val) |rhs_val| {
15500 if (rhs_val.isUndef(mod)) {15499 if (rhs_val.isUndef(zcu)) {
15501 return sema.failWithUseOfUndef(block, rhs_src);15500 return sema.failWithUseOfUndef(block, rhs_src);
15502 }15501 }
15503 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {15502 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -15506,8 +15505,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15506,8 +15505,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15506 // TODO: if the RHS is one, return the LHS directly15505 // TODO: if the RHS is one, return the LHS directly
15507 }15506 }
15508 if (maybe_lhs_val) |lhs_val| {15507 if (maybe_lhs_val) |lhs_val| {
15509 if (lhs_val.isUndef(mod)) {15508 if (lhs_val.isUndef(zcu)) {
15510 if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) {15509 if (lhs_scalar_ty.isSignedInt(zcu) and rhs_scalar_ty.isSignedInt(zcu)) {
15511 if (maybe_rhs_val) |rhs_val| {15510 if (maybe_rhs_val) |rhs_val| {
15512 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {15511 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {
15513 return pt.undefRef(resolved_type);15512 return pt.undefRef(resolved_type);
...@@ -15540,7 +15539,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15540,7 +15539,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1554015539
15541fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15540fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15542 const pt = sema.pt;15541 const pt = sema.pt;
15543 const mod = pt.zcu;15542 const zcu = pt.zcu;
15544 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15543 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15545 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });15544 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15546 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });15545 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...@@ -15550,8 +15549,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15550 const rhs = try sema.resolveInst(extra.rhs);15549 const rhs = try sema.resolveInst(extra.rhs);
15551 const lhs_ty = sema.typeOf(lhs);15550 const lhs_ty = sema.typeOf(lhs);
15552 const rhs_ty = sema.typeOf(rhs);15551 const rhs_ty = sema.typeOf(rhs);
15553 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);15552 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15554 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);15553 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
15555 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);15554 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
15556 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);15555 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1555715556
...@@ -15563,9 +15562,9 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15563,9 +15562,9 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15563 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15562 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
15564 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);15563 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1556515564
15566 const lhs_scalar_ty = lhs_ty.scalarType(mod);15565 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15567 const rhs_scalar_ty = rhs_ty.scalarType(mod);15566 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15568 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);15567 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1556915568
15570 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;15569 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...@@ -15595,11 +15594,11 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15595 // value (zero) for which the division would be illegal behavior.15594 // value (zero) for which the division would be illegal behavior.
15596 // If the lhs is undefined, result is undefined.15595 // If the lhs is undefined, result is undefined.
15597 if (maybe_lhs_val) |lhs_val| {15596 if (maybe_lhs_val) |lhs_val| {
15598 if (!lhs_val.isUndef(mod)) {15597 if (!lhs_val.isUndef(zcu)) {
15599 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {15598 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
15600 const scalar_zero = switch (scalar_tag) {15599 const scalar_zero = switch (scalar_tag) {
15601 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),15600 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15602 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),15601 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
15603 else => unreachable,15602 else => unreachable,
15604 };15603 };
15605 const zero_val = try sema.splat(resolved_type, scalar_zero);15604 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...@@ -15608,7 +15607,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15608 }15607 }
15609 }15608 }
15610 if (maybe_rhs_val) |rhs_val| {15609 if (maybe_rhs_val) |rhs_val| {
15611 if (rhs_val.isUndef(mod)) {15610 if (rhs_val.isUndef(zcu)) {
15612 return sema.failWithUseOfUndef(block, rhs_src);15611 return sema.failWithUseOfUndef(block, rhs_src);
15613 }15612 }
15614 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {15613 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -15616,8 +15615,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15616,8 +15615,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15616 }15615 }
15617 }15616 }
15618 if (maybe_lhs_val) |lhs_val| {15617 if (maybe_lhs_val) |lhs_val| {
15619 if (lhs_val.isUndef(mod)) {15618 if (lhs_val.isUndef(zcu)) {
15620 if (lhs_scalar_ty.isSignedInt(mod) and rhs_scalar_ty.isSignedInt(mod)) {15619 if (lhs_scalar_ty.isSignedInt(zcu) and rhs_scalar_ty.isSignedInt(zcu)) {
15621 if (maybe_rhs_val) |rhs_val| {15620 if (maybe_rhs_val) |rhs_val| {
15622 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {15621 if (try sema.compareAll(rhs_val, .neq, try pt.intValue(resolved_type, -1), resolved_type)) {
15623 return pt.undefRef(resolved_type);15622 return pt.undefRef(resolved_type);
...@@ -15666,14 +15665,14 @@ fn addDivIntOverflowSafety(...@@ -15666,14 +15665,14 @@ fn addDivIntOverflowSafety(
15666 is_int: bool,15665 is_int: bool,
15667) CompileError!void {15666) CompileError!void {
15668 const pt = sema.pt;15667 const pt = sema.pt;
15669 const mod = pt.zcu;15668 const zcu = pt.zcu;
15670 if (!is_int) return;15669 if (!is_int) return;
1567115670
15672 // If the LHS is unsigned, it cannot cause overflow.15671 // 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
15675 // If the LHS is widened to a larger integer type, no overflow is possible.15674 // 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) {
15677 return;15676 return;
15678 }15677 }
1567915678
...@@ -15693,7 +15692,7 @@ fn addDivIntOverflowSafety(...@@ -15693,7 +15692,7 @@ fn addDivIntOverflowSafety(
15693 }15692 }
1569415693
15695 var ok: Air.Inst.Ref = .none;15694 var ok: Air.Inst.Ref = .none;
15696 if (resolved_type.zigTypeTag(mod) == .Vector) {15695 if (resolved_type.zigTypeTag(zcu) == .Vector) {
15697 if (maybe_lhs_val == null) {15696 if (maybe_lhs_val == null) {
15698 const min_int_ref = Air.internedToRef(min_int.toIntern());15697 const min_int_ref = Air.internedToRef(min_int.toIntern());
15699 ok = try block.addCmpVector(casted_lhs, min_int_ref, .neq);15698 ok = try block.addCmpVector(casted_lhs, min_int_ref, .neq);
...@@ -15751,12 +15750,12 @@ fn addDivByZeroSafety(...@@ -15751,12 +15750,12 @@ fn addDivByZeroSafety(
15751 if (maybe_rhs_val != null) return;15750 if (maybe_rhs_val != null) return;
1575215751
15753 const pt = sema.pt;15752 const pt = sema.pt;
15754 const mod = pt.zcu;15753 const zcu = pt.zcu;
15755 const scalar_zero = if (is_int)15754 const scalar_zero = if (is_int)
15756 try pt.intValue(resolved_type.scalarType(mod), 0)15755 try pt.intValue(resolved_type.scalarType(zcu), 0)
15757 else15756 else
15758 try pt.floatValue(resolved_type.scalarType(mod), 0.0);15757 try pt.floatValue(resolved_type.scalarType(zcu), 0.0);
15759 const ok = if (resolved_type.zigTypeTag(mod) == .Vector) ok: {15758 const ok = if (resolved_type.zigTypeTag(zcu) == .Vector) ok: {
15760 const zero_val = try sema.splat(resolved_type, scalar_zero);15759 const zero_val = try sema.splat(resolved_type, scalar_zero);
15761 const zero = Air.internedToRef(zero_val.toIntern());15760 const zero = Air.internedToRef(zero_val.toIntern());
15762 const ok = try block.addCmpVector(casted_rhs, zero, .neq);15761 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...@@ -15784,7 +15783,7 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst
1578415783
15785fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15784fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15786 const pt = sema.pt;15785 const pt = sema.pt;
15787 const mod = pt.zcu;15786 const zcu = pt.zcu;
15788 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15787 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15789 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });15788 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15790 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });15789 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....@@ -15794,8 +15793,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15794 const rhs = try sema.resolveInst(extra.rhs);15793 const rhs = try sema.resolveInst(extra.rhs);
15795 const lhs_ty = sema.typeOf(lhs);15794 const lhs_ty = sema.typeOf(lhs);
15796 const rhs_ty = sema.typeOf(rhs);15795 const rhs_ty = sema.typeOf(rhs);
15797 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);15796 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15798 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);15797 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
15799 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);15798 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
15800 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);15799 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);
1580115800
...@@ -15804,14 +15803,14 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15804,14 +15803,14 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15804 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },15803 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },
15805 });15804 });
1580615805
15807 const is_vector = resolved_type.zigTypeTag(mod) == .Vector;15806 const is_vector = resolved_type.zigTypeTag(zcu) == .Vector;
1580815807
15809 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15808 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
15810 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);15809 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1581115810
15812 const lhs_scalar_ty = lhs_ty.scalarType(mod);15811 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
15813 const rhs_scalar_ty = rhs_ty.scalarType(mod);15812 const rhs_scalar_ty = rhs_ty.scalarType(zcu);
15814 const scalar_tag = resolved_type.scalarType(mod).zigTypeTag(mod);15813 const scalar_tag = resolved_type.scalarType(zcu).zigTypeTag(zcu);
1581515814
15816 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;15815 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....@@ -15836,13 +15835,13 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15836 // then emit a compile error saying you have to pick one.15835 // then emit a compile error saying you have to pick one.
15837 if (is_int) {15836 if (is_int) {
15838 if (maybe_lhs_val) |lhs_val| {15837 if (maybe_lhs_val) |lhs_val| {
15839 if (lhs_val.isUndef(mod)) {15838 if (lhs_val.isUndef(zcu)) {
15840 return sema.failWithUseOfUndef(block, lhs_src);15839 return sema.failWithUseOfUndef(block, lhs_src);
15841 }15840 }
15842 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {15841 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
15843 const scalar_zero = switch (scalar_tag) {15842 const scalar_zero = switch (scalar_tag) {
15844 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(mod), 0.0),15843 .ComptimeFloat, .Float => try pt.floatValue(resolved_type.scalarType(zcu), 0.0),
15845 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(mod), 0),15844 .ComptimeInt, .Int => try pt.intValue(resolved_type.scalarType(zcu), 0),
15846 else => unreachable,15845 else => unreachable,
15847 };15846 };
15848 const zero_val = if (is_vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{15847 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....@@ -15851,11 +15850,11 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15851 } })) else scalar_zero;15850 } })) else scalar_zero;
15852 return Air.internedToRef(zero_val.toIntern());15851 return Air.internedToRef(zero_val.toIntern());
15853 }15852 }
15854 } else if (lhs_scalar_ty.isSignedInt(mod)) {15853 } else if (lhs_scalar_ty.isSignedInt(zcu)) {
15855 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);15854 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
15856 }15855 }
15857 if (maybe_rhs_val) |rhs_val| {15856 if (maybe_rhs_val) |rhs_val| {
15858 if (rhs_val.isUndef(mod)) {15857 if (rhs_val.isUndef(zcu)) {
15859 return sema.failWithUseOfUndef(block, rhs_src);15858 return sema.failWithUseOfUndef(block, rhs_src);
15860 }15859 }
15861 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {15860 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -15876,7 +15875,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15876,7 +15875,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15876 return Air.internedToRef(rem_result.toIntern());15875 return Air.internedToRef(rem_result.toIntern());
15877 }15876 }
15878 break :rs lhs_src;15877 break :rs lhs_src;
15879 } else if (rhs_scalar_ty.isSignedInt(mod)) {15878 } else if (rhs_scalar_ty.isSignedInt(zcu)) {
15880 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);15879 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);
15881 } else {15880 } else {
15882 break :rs rhs_src;15881 break :rs rhs_src;
...@@ -15884,7 +15883,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15884,7 +15883,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15884 }15883 }
15885 // float operands15884 // float operands
15886 if (maybe_rhs_val) |rhs_val| {15885 if (maybe_rhs_val) |rhs_val| {
15887 if (rhs_val.isUndef(mod)) {15886 if (rhs_val.isUndef(zcu)) {
15888 return sema.failWithUseOfUndef(block, rhs_src);15887 return sema.failWithUseOfUndef(block, rhs_src);
15889 }15888 }
15890 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {15889 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -15894,7 +15893,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15894,7 +15893,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15894 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);15893 return sema.failWithModRemNegative(block, rhs_src, lhs_ty, rhs_ty);
15895 }15894 }
15896 if (maybe_lhs_val) |lhs_val| {15895 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))) {
15898 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);15897 return sema.failWithModRemNegative(block, lhs_src, lhs_ty, rhs_ty);
15899 }15898 }
15900 return Air.internedToRef((try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, pt)).toIntern());15899 return Air.internedToRef((try lhs_val.floatRem(rhs_val, resolved_type, sema.arena, pt)).toIntern());
...@@ -15923,10 +15922,10 @@ fn intRem(...@@ -15923,10 +15922,10 @@ fn intRem(
15923 rhs: Value,15922 rhs: Value,
15924) CompileError!Value {15923) CompileError!Value {
15925 const pt = sema.pt;15924 const pt = sema.pt;
15926 const mod = pt.zcu;15925 const zcu = pt.zcu;
15927 if (ty.zigTypeTag(mod) == .Vector) {15926 if (ty.zigTypeTag(zcu) == .Vector) {
15928 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));15927 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
15929 const scalar_ty = ty.scalarType(mod);15928 const scalar_ty = ty.scalarType(zcu);
15930 for (result_data, 0..) |*scalar, i| {15929 for (result_data, 0..) |*scalar, i| {
15931 const lhs_elem = try lhs.elemValue(pt, i);15930 const lhs_elem = try lhs.elemValue(pt, i);
15932 const rhs_elem = try rhs.elemValue(pt, i);15931 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -15946,8 +15945,8 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr...@@ -15946,8 +15945,8 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
15946 // resorting to BigInt first.15945 // resorting to BigInt first.
15947 var lhs_space: Value.BigIntSpace = undefined;15946 var lhs_space: Value.BigIntSpace = undefined;
15948 var rhs_space: Value.BigIntSpace = undefined;15947 var rhs_space: Value.BigIntSpace = undefined;
15949 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);15948 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
15950 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);15949 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
15951 const limbs_q = try sema.arena.alloc(15950 const limbs_q = try sema.arena.alloc(
15952 math.big.Limb,15951 math.big.Limb,
15953 lhs_bigint.limbs.len,15952 lhs_bigint.limbs.len,
...@@ -15970,7 +15969,7 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr...@@ -15970,7 +15969,7 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
1597015969
15971fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15970fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15972 const pt = sema.pt;15971 const pt = sema.pt;
15973 const mod = pt.zcu;15972 const zcu = pt.zcu;
15974 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15973 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15975 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });15974 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15976 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });15975 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...@@ -15980,8 +15979,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15980 const rhs = try sema.resolveInst(extra.rhs);15979 const rhs = try sema.resolveInst(extra.rhs);
15981 const lhs_ty = sema.typeOf(lhs);15980 const lhs_ty = sema.typeOf(lhs);
15982 const rhs_ty = sema.typeOf(rhs);15981 const rhs_ty = sema.typeOf(rhs);
15983 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);15982 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
15984 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);15983 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
15985 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);15984 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
15986 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);15985 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...@@ -15993,7 +15992,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15993 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);15992 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
15994 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);15993 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
15998 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;15997 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...@@ -16016,12 +16015,12 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16016 // If the lhs is undefined, result is undefined.16015 // If the lhs is undefined, result is undefined.
16017 if (is_int) {16016 if (is_int) {
16018 if (maybe_lhs_val) |lhs_val| {16017 if (maybe_lhs_val) |lhs_val| {
16019 if (lhs_val.isUndef(mod)) {16018 if (lhs_val.isUndef(zcu)) {
16020 return sema.failWithUseOfUndef(block, lhs_src);16019 return sema.failWithUseOfUndef(block, lhs_src);
16021 }16020 }
16022 }16021 }
16023 if (maybe_rhs_val) |rhs_val| {16022 if (maybe_rhs_val) |rhs_val| {
16024 if (rhs_val.isUndef(mod)) {16023 if (rhs_val.isUndef(zcu)) {
16025 return sema.failWithUseOfUndef(block, rhs_src);16024 return sema.failWithUseOfUndef(block, rhs_src);
16026 }16025 }
16027 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {16026 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -16037,7 +16036,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -16037,7 +16036,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16037 }16036 }
16038 // float operands16037 // float operands
16039 if (maybe_rhs_val) |rhs_val| {16038 if (maybe_rhs_val) |rhs_val| {
16040 if (rhs_val.isUndef(mod)) {16039 if (rhs_val.isUndef(zcu)) {
16041 return sema.failWithUseOfUndef(block, rhs_src);16040 return sema.failWithUseOfUndef(block, rhs_src);
16042 }16041 }
16043 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {16042 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -16045,7 +16044,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -16045,7 +16044,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16045 }16044 }
16046 }16045 }
16047 if (maybe_lhs_val) |lhs_val| {16046 if (maybe_lhs_val) |lhs_val| {
16048 if (lhs_val.isUndef(mod)) {16047 if (lhs_val.isUndef(zcu)) {
16049 return pt.undefRef(resolved_type);16048 return pt.undefRef(resolved_type);
16050 }16049 }
16051 if (maybe_rhs_val) |rhs_val| {16050 if (maybe_rhs_val) |rhs_val| {
...@@ -16066,7 +16065,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -16066,7 +16065,7 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1606616065
16067fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16066fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
16068 const pt = sema.pt;16067 const pt = sema.pt;
16069 const mod = pt.zcu;16068 const zcu = pt.zcu;
16070 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;16069 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
16071 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });16070 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
16072 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });16071 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...@@ -16076,8 +16075,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16076 const rhs = try sema.resolveInst(extra.rhs);16075 const rhs = try sema.resolveInst(extra.rhs);
16077 const lhs_ty = sema.typeOf(lhs);16076 const lhs_ty = sema.typeOf(lhs);
16078 const rhs_ty = sema.typeOf(rhs);16077 const rhs_ty = sema.typeOf(rhs);
16079 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);16078 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
16080 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);16079 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
16081 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);16080 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
16082 try sema.checkInvalidPtrIntArithmetic(block, src, lhs_ty);16081 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...@@ -16089,7 +16088,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16089 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);16088 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
16090 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);16089 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
16094 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;16093 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...@@ -16112,12 +16111,12 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16112 // If the lhs is undefined, result is undefined.16111 // If the lhs is undefined, result is undefined.
16113 if (is_int) {16112 if (is_int) {
16114 if (maybe_lhs_val) |lhs_val| {16113 if (maybe_lhs_val) |lhs_val| {
16115 if (lhs_val.isUndef(mod)) {16114 if (lhs_val.isUndef(zcu)) {
16116 return sema.failWithUseOfUndef(block, lhs_src);16115 return sema.failWithUseOfUndef(block, lhs_src);
16117 }16116 }
16118 }16117 }
16119 if (maybe_rhs_val) |rhs_val| {16118 if (maybe_rhs_val) |rhs_val| {
16120 if (rhs_val.isUndef(mod)) {16119 if (rhs_val.isUndef(zcu)) {
16121 return sema.failWithUseOfUndef(block, rhs_src);16120 return sema.failWithUseOfUndef(block, rhs_src);
16122 }16121 }
16123 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {16122 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -16133,7 +16132,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -16133,7 +16132,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16133 }16132 }
16134 // float operands16133 // float operands
16135 if (maybe_rhs_val) |rhs_val| {16134 if (maybe_rhs_val) |rhs_val| {
16136 if (rhs_val.isUndef(mod)) {16135 if (rhs_val.isUndef(zcu)) {
16137 return sema.failWithUseOfUndef(block, rhs_src);16136 return sema.failWithUseOfUndef(block, rhs_src);
16138 }16137 }
16139 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {16138 if (!(try rhs_val.compareAllWithZeroSema(.neq, pt))) {
...@@ -16141,7 +16140,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -16141,7 +16140,7 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16141 }16140 }
16142 }16141 }
16143 if (maybe_lhs_val) |lhs_val| {16142 if (maybe_lhs_val) |lhs_val| {
16144 if (lhs_val.isUndef(mod)) {16143 if (lhs_val.isUndef(zcu)) {
16145 return pt.undefRef(resolved_type);16144 return pt.undefRef(resolved_type);
16146 }16145 }
16147 if (maybe_rhs_val) |rhs_val| {16146 if (maybe_rhs_val) |rhs_val| {
...@@ -16181,8 +16180,8 @@ fn zirOverflowArithmetic(...@@ -16181,8 +16180,8 @@ fn zirOverflowArithmetic(
16181 const lhs_ty = sema.typeOf(uncasted_lhs);16180 const lhs_ty = sema.typeOf(uncasted_lhs);
16182 const rhs_ty = sema.typeOf(uncasted_rhs);16181 const rhs_ty = sema.typeOf(uncasted_rhs);
16183 const pt = sema.pt;16182 const pt = sema.pt;
16184 const mod = pt.zcu;16183 const zcu = pt.zcu;
16185 const ip = &mod.intern_pool;16184 const ip = &zcu.intern_pool;
1618616185
16187 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);16186 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1618816187
...@@ -16202,7 +16201,7 @@ fn zirOverflowArithmetic(...@@ -16202,7 +16201,7 @@ fn zirOverflowArithmetic(
16202 const lhs = try sema.coerce(block, dest_ty, uncasted_lhs, lhs_src);16201 const lhs = try sema.coerce(block, dest_ty, uncasted_lhs, lhs_src);
16203 const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src);16202 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) {
16206 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(pt)});16205 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(pt)});
16207 }16206 }
1620816207
...@@ -16224,18 +16223,18 @@ fn zirOverflowArithmetic(...@@ -16224,18 +16223,18 @@ fn zirOverflowArithmetic(
16224 // to the result, even if it is undefined..16223 // to the result, even if it is undefined..
16225 // Otherwise, if either of the argument is undefined, undefined is returned.16224 // Otherwise, if either of the argument is undefined, undefined is returned.
16226 if (maybe_lhs_val) |lhs_val| {16225 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))) {
16228 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };16227 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };
16229 }16228 }
16230 }16229 }
16231 if (maybe_rhs_val) |rhs_val| {16230 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))) {
16233 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };16232 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16234 }16233 }
16235 }16234 }
16236 if (maybe_lhs_val) |lhs_val| {16235 if (maybe_lhs_val) |lhs_val| {
16237 if (maybe_rhs_val) |rhs_val| {16236 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)) {
16239 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };16238 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
16240 }16239 }
1624116240
...@@ -16248,12 +16247,12 @@ fn zirOverflowArithmetic(...@@ -16248,12 +16247,12 @@ fn zirOverflowArithmetic(
16248 // If the rhs is zero, then the result is lhs and no overflow occured.16247 // If the rhs is zero, then the result is lhs and no overflow occured.
16249 // Otherwise, if either result is undefined, both results are undefined.16248 // Otherwise, if either result is undefined, both results are undefined.
16250 if (maybe_rhs_val) |rhs_val| {16249 if (maybe_rhs_val) |rhs_val| {
16251 if (rhs_val.isUndef(mod)) {16250 if (rhs_val.isUndef(zcu)) {
16252 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };16251 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
16253 } else if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16252 } else if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
16254 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };16253 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16255 } else if (maybe_lhs_val) |lhs_val| {16254 } else if (maybe_lhs_val) |lhs_val| {
16256 if (lhs_val.isUndef(mod)) {16255 if (lhs_val.isUndef(zcu)) {
16257 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };16256 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
16258 }16257 }
1625916258
...@@ -16266,9 +16265,9 @@ fn zirOverflowArithmetic(...@@ -16266,9 +16265,9 @@ fn zirOverflowArithmetic(
16266 // If either of the arguments is zero, the result is zero and no overflow occured.16265 // If either of the arguments is zero, the result is zero and no overflow occured.
16267 // If either of the arguments is one, the result is the other and no overflow occured.16266 // If either of the arguments is one, the result is the other and no overflow occured.
16268 // Otherwise, if either of the arguments is undefined, both results are undefined.16267 // 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);
16270 if (maybe_lhs_val) |lhs_val| {16269 if (maybe_lhs_val) |lhs_val| {
16271 if (!lhs_val.isUndef(mod)) {16270 if (!lhs_val.isUndef(zcu)) {
16272 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {16271 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
16273 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };16272 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16274 } else if (try sema.compareAll(lhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {16273 } else if (try sema.compareAll(lhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
...@@ -16278,7 +16277,7 @@ fn zirOverflowArithmetic(...@@ -16278,7 +16277,7 @@ fn zirOverflowArithmetic(
16278 }16277 }
1627916278
16280 if (maybe_rhs_val) |rhs_val| {16279 if (maybe_rhs_val) |rhs_val| {
16281 if (!rhs_val.isUndef(mod)) {16280 if (!rhs_val.isUndef(zcu)) {
16282 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16281 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
16283 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };16282 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = rhs };
16284 } else if (try sema.compareAll(rhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {16283 } else if (try sema.compareAll(rhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
...@@ -16289,7 +16288,7 @@ fn zirOverflowArithmetic(...@@ -16289,7 +16288,7 @@ fn zirOverflowArithmetic(
1628916288
16290 if (maybe_lhs_val) |lhs_val| {16289 if (maybe_lhs_val) |lhs_val| {
16291 if (maybe_rhs_val) |rhs_val| {16290 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)) {
16293 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };16292 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
16294 }16293 }
1629516294
...@@ -16303,18 +16302,18 @@ fn zirOverflowArithmetic(...@@ -16303,18 +16302,18 @@ fn zirOverflowArithmetic(
16303 // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred.16302 // If rhs is zero, the result is lhs (even if undefined) and no overflow occurred.
16304 // Oterhwise if either of the arguments is undefined, both results are undefined.16303 // Oterhwise if either of the arguments is undefined, both results are undefined.
16305 if (maybe_lhs_val) |lhs_val| {16304 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))) {
16307 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };16306 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16308 }16307 }
16309 }16308 }
16310 if (maybe_rhs_val) |rhs_val| {16309 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))) {
16312 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };16311 break :result .{ .overflow_bit = try sema.splat(overflow_ty, zero_bit), .inst = lhs };
16313 }16312 }
16314 }16313 }
16315 if (maybe_lhs_val) |lhs_val| {16314 if (maybe_lhs_val) |lhs_val| {
16316 if (maybe_rhs_val) |rhs_val| {16315 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)) {
16318 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };16317 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
16319 }16318 }
1632016319
...@@ -16374,8 +16373,8 @@ fn zirOverflowArithmetic(...@@ -16374,8 +16373,8 @@ fn zirOverflowArithmetic(
1637416373
16375fn splat(sema: *Sema, ty: Type, val: Value) !Value {16374fn splat(sema: *Sema, ty: Type, val: Value) !Value {
16376 const pt = sema.pt;16375 const pt = sema.pt;
16377 const mod = pt.zcu;16376 const zcu = pt.zcu;
16378 if (ty.zigTypeTag(mod) != .Vector) return val;16377 if (ty.zigTypeTag(zcu) != .Vector) return val;
16379 const repeated = try pt.intern(.{ .aggregate = .{16378 const repeated = try pt.intern(.{ .aggregate = .{
16380 .ty = ty.toIntern(),16379 .ty = ty.toIntern(),
16381 .storage = .{ .repeated_elem = val.toIntern() },16380 .storage = .{ .repeated_elem = val.toIntern() },
...@@ -16385,16 +16384,16 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {...@@ -16385,16 +16384,16 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {
1638516384
16386fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {16385fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
16387 const pt = sema.pt;16386 const pt = sema.pt;
16388 const mod = pt.zcu;16387 const zcu = pt.zcu;
16389 const ip = &mod.intern_pool;16388 const ip = &zcu.intern_pool;
16390 const ov_ty = if (ty.zigTypeTag(mod) == .Vector) try pt.vectorType(.{16389 const ov_ty = if (ty.zigTypeTag(zcu) == .Vector) try pt.vectorType(.{
16391 .len = ty.vectorLen(mod),16390 .len = ty.vectorLen(zcu),
16392 .child = .u1_type,16391 .child = .u1_type,
16393 }) else Type.u1;16392 }) else Type.u1;
1639416393
16395 const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() };16394 const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() };
16396 const values = [2]InternPool.Index{ .none, .none };16395 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, .{
16398 .types = &types,16397 .types = &types,
16399 .values = &values,16398 .values = &values,
16400 .names = &.{},16399 .names = &.{},
...@@ -16415,41 +16414,41 @@ fn analyzeArithmetic(...@@ -16415,41 +16414,41 @@ fn analyzeArithmetic(
16415 want_safety: bool,16414 want_safety: bool,
16416) CompileError!Air.Inst.Ref {16415) CompileError!Air.Inst.Ref {
16417 const pt = sema.pt;16416 const pt = sema.pt;
16418 const mod = pt.zcu;16417 const zcu = pt.zcu;
16419 const lhs_ty = sema.typeOf(lhs);16418 const lhs_ty = sema.typeOf(lhs);
16420 const rhs_ty = sema.typeOf(rhs);16419 const rhs_ty = sema.typeOf(rhs);
16421 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);16420 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
16422 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);16421 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
16423 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);16422 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1642416423
16425 if (lhs_zig_ty_tag == .Pointer) {16424 if (lhs_zig_ty_tag == .Pointer) {
16426 if (rhs_zig_ty_tag == .Pointer) {16425 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) {
16428 if (zir_tag != .sub) {16427 if (zir_tag != .sub) {
16429 return sema.failWithInvalidPtrArithmetic(block, src, "pointer-pointer", "subtraction");16428 return sema.failWithInvalidPtrArithmetic(block, src, "pointer-pointer", "subtraction");
16430 }16429 }
16431 if (!lhs_ty.elemType2(mod).eql(rhs_ty.elemType2(mod), mod)) {16430 if (!lhs_ty.elemType2(zcu).eql(rhs_ty.elemType2(zcu), zcu)) {
16432 return sema.fail(block, src, "incompatible pointer arithmetic operands '{}' and '{}'", .{16431 return sema.fail(block, src, "incompatible pointer arithmetic operands '{}' and '{}'", .{
16433 lhs_ty.fmt(pt), rhs_ty.fmt(pt),16432 lhs_ty.fmt(pt), rhs_ty.fmt(pt),
16434 });16433 });
16435 }16434 }
1643616435
16437 const elem_size = lhs_ty.elemType2(mod).abiSize(pt);16436 const elem_size = lhs_ty.elemType2(zcu).abiSize(zcu);
16438 if (elem_size == 0) {16437 if (elem_size == 0) {
16439 return sema.fail(block, src, "pointer arithmetic requires element type '{}' to have runtime bits", .{16438 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),
16441 });16440 });
16442 }16441 }
1644316442
16444 const runtime_src = runtime_src: {16443 const runtime_src = runtime_src: {
16445 if (try sema.resolveValue(lhs)) |lhs_value| {16444 if (try sema.resolveValue(lhs)) |lhs_value| {
16446 if (try sema.resolveValue(rhs)) |rhs_value| {16445 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())) {
16448 .undef => return sema.failWithUseOfUndef(block, lhs_src),16447 .undef => return sema.failWithUseOfUndef(block, lhs_src),
16449 .ptr => |ptr| ptr,16448 .ptr => |ptr| ptr,
16450 else => unreachable,16449 else => unreachable,
16451 };16450 };
16452 const rhs_ptr = switch (mod.intern_pool.indexToKey(rhs_value.toIntern())) {16451 const rhs_ptr = switch (zcu.intern_pool.indexToKey(rhs_value.toIntern())) {
16453 .undef => return sema.failWithUseOfUndef(block, rhs_src),16452 .undef => return sema.failWithUseOfUndef(block, rhs_src),
16454 .ptr => |ptr| ptr,16453 .ptr => |ptr| ptr,
16455 else => unreachable,16454 else => unreachable,
...@@ -16475,7 +16474,7 @@ fn analyzeArithmetic(...@@ -16475,7 +16474,7 @@ fn analyzeArithmetic(
16475 return try block.addBinOp(.div_exact, address, try pt.intRef(Type.usize, elem_size));16474 return try block.addBinOp(.div_exact, address, try pt.intRef(Type.usize, elem_size));
16476 }16475 }
16477 } else {16476 } else {
16478 switch (lhs_ty.ptrSize(mod)) {16477 switch (lhs_ty.ptrSize(zcu)) {
16479 .One, .Slice => {},16478 .One, .Slice => {},
16480 .Many, .C => {16479 .Many, .C => {
16481 const air_tag: Air.Inst.Tag = switch (zir_tag) {16480 const air_tag: Air.Inst.Tag = switch (zir_tag) {
...@@ -16484,9 +16483,9 @@ fn analyzeArithmetic(...@@ -16484,9 +16483,9 @@ fn analyzeArithmetic(
16484 else => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"),16483 else => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"),
16485 };16484 };
1648616485
16487 if (!try sema.typeHasRuntimeBits(lhs_ty.elemType2(mod))) {16486 if (!try lhs_ty.elemType2(zcu).hasRuntimeBitsSema(pt)) {
16488 return sema.fail(block, src, "pointer arithmetic requires element type '{}' to have runtime bits", .{16487 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),
16490 });16489 });
16491 }16490 }
16492 return sema.analyzePtrArithmetic(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);16491 return sema.analyzePtrArithmetic(block, src, lhs, rhs, air_tag, lhs_src, rhs_src);
...@@ -16503,8 +16502,8 @@ fn analyzeArithmetic(...@@ -16503,8 +16502,8 @@ fn analyzeArithmetic(
16503 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);16502 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
16504 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);16503 const casted_rhs = try sema.coerce(block, resolved_type, rhs, rhs_src);
1650516504
16506 const scalar_type = resolved_type.scalarType(mod);16505 const scalar_type = resolved_type.scalarType(zcu);
16507 const scalar_tag = scalar_type.zigTypeTag(mod);16506 const scalar_tag = scalar_type.zigTypeTag(zcu);
1650816507
16509 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;16508 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
1651016509
...@@ -16523,12 +16522,12 @@ fn analyzeArithmetic(...@@ -16523,12 +16522,12 @@ fn analyzeArithmetic(
16523 // overflow (max_int), causing illegal behavior.16522 // overflow (max_int), causing illegal behavior.
16524 // For floats: either operand being undef makes the result undef.16523 // For floats: either operand being undef makes the result undef.
16525 if (maybe_lhs_val) |lhs_val| {16524 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))) {
16527 return casted_rhs;16526 return casted_rhs;
16528 }16527 }
16529 }16528 }
16530 if (maybe_rhs_val) |rhs_val| {16529 if (maybe_rhs_val) |rhs_val| {
16531 if (rhs_val.isUndef(mod)) {16530 if (rhs_val.isUndef(zcu)) {
16532 if (is_int) {16531 if (is_int) {
16533 return sema.failWithUseOfUndef(block, rhs_src);16532 return sema.failWithUseOfUndef(block, rhs_src);
16534 } else {16533 } else {
...@@ -16541,7 +16540,7 @@ fn analyzeArithmetic(...@@ -16541,7 +16540,7 @@ fn analyzeArithmetic(
16541 }16540 }
16542 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .add_optimized else .add;16541 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .add_optimized else .add;
16543 if (maybe_lhs_val) |lhs_val| {16542 if (maybe_lhs_val) |lhs_val| {
16544 if (lhs_val.isUndef(mod)) {16543 if (lhs_val.isUndef(zcu)) {
16545 if (is_int) {16544 if (is_int) {
16546 return sema.failWithUseOfUndef(block, lhs_src);16545 return sema.failWithUseOfUndef(block, lhs_src);
16547 } else {16546 } else {
...@@ -16567,12 +16566,12 @@ fn analyzeArithmetic(...@@ -16567,12 +16566,12 @@ fn analyzeArithmetic(
16567 // If either of the operands are zero, the other operand is returned.16566 // If either of the operands are zero, the other operand is returned.
16568 // If either of the operands are undefined, the result is undefined.16567 // If either of the operands are undefined, the result is undefined.
16569 if (maybe_lhs_val) |lhs_val| {16568 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))) {
16571 return casted_rhs;16570 return casted_rhs;
16572 }16571 }
16573 }16572 }
16574 if (maybe_rhs_val) |rhs_val| {16573 if (maybe_rhs_val) |rhs_val| {
16575 if (rhs_val.isUndef(mod)) {16574 if (rhs_val.isUndef(zcu)) {
16576 return pt.undefRef(resolved_type);16575 return pt.undefRef(resolved_type);
16577 }16576 }
16578 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16577 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
...@@ -16588,19 +16587,19 @@ fn analyzeArithmetic(...@@ -16588,19 +16587,19 @@ fn analyzeArithmetic(
16588 // If either of the operands are zero, then the other operand is returned.16587 // If either of the operands are zero, then the other operand is returned.
16589 // If either of the operands are undefined, the result is undefined.16588 // If either of the operands are undefined, the result is undefined.
16590 if (maybe_lhs_val) |lhs_val| {16589 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))) {
16592 return casted_rhs;16591 return casted_rhs;
16593 }16592 }
16594 }16593 }
16595 if (maybe_rhs_val) |rhs_val| {16594 if (maybe_rhs_val) |rhs_val| {
16596 if (rhs_val.isUndef(mod)) {16595 if (rhs_val.isUndef(zcu)) {
16597 return pt.undefRef(resolved_type);16596 return pt.undefRef(resolved_type);
16598 }16597 }
16599 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16598 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
16600 return casted_lhs;16599 return casted_lhs;
16601 }16600 }
16602 if (maybe_lhs_val) |lhs_val| {16601 if (maybe_lhs_val) |lhs_val| {
16603 if (lhs_val.isUndef(mod)) {16602 if (lhs_val.isUndef(zcu)) {
16604 return pt.undefRef(resolved_type);16603 return pt.undefRef(resolved_type);
16605 }16604 }
1660616605
...@@ -16630,7 +16629,7 @@ fn analyzeArithmetic(...@@ -16630,7 +16629,7 @@ fn analyzeArithmetic(
16630 // overflow, causing illegal behavior.16629 // overflow, causing illegal behavior.
16631 // For floats: either operand being undef makes the result undef.16630 // For floats: either operand being undef makes the result undef.
16632 if (maybe_rhs_val) |rhs_val| {16631 if (maybe_rhs_val) |rhs_val| {
16633 if (rhs_val.isUndef(mod)) {16632 if (rhs_val.isUndef(zcu)) {
16634 if (is_int) {16633 if (is_int) {
16635 return sema.failWithUseOfUndef(block, rhs_src);16634 return sema.failWithUseOfUndef(block, rhs_src);
16636 } else {16635 } else {
...@@ -16643,7 +16642,7 @@ fn analyzeArithmetic(...@@ -16643,7 +16642,7 @@ fn analyzeArithmetic(
16643 }16642 }
16644 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .sub_optimized else .sub;16643 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .sub_optimized else .sub;
16645 if (maybe_lhs_val) |lhs_val| {16644 if (maybe_lhs_val) |lhs_val| {
16646 if (lhs_val.isUndef(mod)) {16645 if (lhs_val.isUndef(zcu)) {
16647 if (is_int) {16646 if (is_int) {
16648 return sema.failWithUseOfUndef(block, lhs_src);16647 return sema.failWithUseOfUndef(block, lhs_src);
16649 } else {16648 } else {
...@@ -16669,7 +16668,7 @@ fn analyzeArithmetic(...@@ -16669,7 +16668,7 @@ fn analyzeArithmetic(
16669 // If the RHS is zero, then the LHS is returned, even if it is undefined.16668 // If the RHS is zero, then the LHS is returned, even if it is undefined.
16670 // If either of the operands are undefined, the result is undefined.16669 // If either of the operands are undefined, the result is undefined.
16671 if (maybe_rhs_val) |rhs_val| {16670 if (maybe_rhs_val) |rhs_val| {
16672 if (rhs_val.isUndef(mod)) {16671 if (rhs_val.isUndef(zcu)) {
16673 return pt.undefRef(resolved_type);16672 return pt.undefRef(resolved_type);
16674 }16673 }
16675 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16674 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
...@@ -16677,7 +16676,7 @@ fn analyzeArithmetic(...@@ -16677,7 +16676,7 @@ fn analyzeArithmetic(
16677 }16676 }
16678 }16677 }
16679 if (maybe_lhs_val) |lhs_val| {16678 if (maybe_lhs_val) |lhs_val| {
16680 if (lhs_val.isUndef(mod)) {16679 if (lhs_val.isUndef(zcu)) {
16681 return pt.undefRef(resolved_type);16680 return pt.undefRef(resolved_type);
16682 }16681 }
16683 if (maybe_rhs_val) |rhs_val| {16682 if (maybe_rhs_val) |rhs_val| {
...@@ -16690,7 +16689,7 @@ fn analyzeArithmetic(...@@ -16690,7 +16689,7 @@ fn analyzeArithmetic(
16690 // If the RHS is zero, then the LHS is returned, even if it is undefined.16689 // If the RHS is zero, then the LHS is returned, even if it is undefined.
16691 // If either of the operands are undefined, the result is undefined.16690 // If either of the operands are undefined, the result is undefined.
16692 if (maybe_rhs_val) |rhs_val| {16691 if (maybe_rhs_val) |rhs_val| {
16693 if (rhs_val.isUndef(mod)) {16692 if (rhs_val.isUndef(zcu)) {
16694 return pt.undefRef(resolved_type);16693 return pt.undefRef(resolved_type);
16695 }16694 }
16696 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16695 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
...@@ -16698,7 +16697,7 @@ fn analyzeArithmetic(...@@ -16698,7 +16697,7 @@ fn analyzeArithmetic(
16698 }16697 }
16699 }16698 }
16700 if (maybe_lhs_val) |lhs_val| {16699 if (maybe_lhs_val) |lhs_val| {
16701 if (lhs_val.isUndef(mod)) {16700 if (lhs_val.isUndef(zcu)) {
16702 return pt.undefRef(resolved_type);16701 return pt.undefRef(resolved_type);
16703 }16702 }
16704 if (maybe_rhs_val) |rhs_val| {16703 if (maybe_rhs_val) |rhs_val| {
...@@ -16736,16 +16735,16 @@ fn analyzeArithmetic(...@@ -16736,16 +16735,16 @@ fn analyzeArithmetic(
16736 else => unreachable,16735 else => unreachable,
16737 };16736 };
16738 if (maybe_lhs_val) |lhs_val| {16737 if (maybe_lhs_val) |lhs_val| {
16739 if (!lhs_val.isUndef(mod)) {16738 if (!lhs_val.isUndef(zcu)) {
16740 if (lhs_val.isNan(mod)) {16739 if (lhs_val.isNan(zcu)) {
16741 return Air.internedToRef(lhs_val.toIntern());16740 return Air.internedToRef(lhs_val.toIntern());
16742 }16741 }
16743 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) lz: {16742 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) lz: {
16744 if (maybe_rhs_val) |rhs_val| {16743 if (maybe_rhs_val) |rhs_val| {
16745 if (rhs_val.isNan(mod)) {16744 if (rhs_val.isNan(zcu)) {
16746 return Air.internedToRef(rhs_val.toIntern());16745 return Air.internedToRef(rhs_val.toIntern());
16747 }16746 }
16748 if (rhs_val.isInf(mod)) {16747 if (rhs_val.isInf(zcu)) {
16749 return Air.internedToRef((try pt.floatValue(resolved_type, std.math.nan(f128))).toIntern());16748 return Air.internedToRef((try pt.floatValue(resolved_type, std.math.nan(f128))).toIntern());
16750 }16749 }
16751 } else if (resolved_type.isAnyFloat()) {16750 } else if (resolved_type.isAnyFloat()) {
...@@ -16761,19 +16760,19 @@ fn analyzeArithmetic(...@@ -16761,19 +16760,19 @@ fn analyzeArithmetic(
16761 }16760 }
16762 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .mul_optimized else .mul;16761 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .mul_optimized else .mul;
16763 if (maybe_rhs_val) |rhs_val| {16762 if (maybe_rhs_val) |rhs_val| {
16764 if (rhs_val.isUndef(mod)) {16763 if (rhs_val.isUndef(zcu)) {
16765 if (is_int) {16764 if (is_int) {
16766 return sema.failWithUseOfUndef(block, rhs_src);16765 return sema.failWithUseOfUndef(block, rhs_src);
16767 } else {16766 } else {
16768 return pt.undefRef(resolved_type);16767 return pt.undefRef(resolved_type);
16769 }16768 }
16770 }16769 }
16771 if (rhs_val.isNan(mod)) {16770 if (rhs_val.isNan(zcu)) {
16772 return Air.internedToRef(rhs_val.toIntern());16771 return Air.internedToRef(rhs_val.toIntern());
16773 }16772 }
16774 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) rz: {16773 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) rz: {
16775 if (maybe_lhs_val) |lhs_val| {16774 if (maybe_lhs_val) |lhs_val| {
16776 if (lhs_val.isInf(mod)) {16775 if (lhs_val.isInf(zcu)) {
16777 return Air.internedToRef((try pt.floatValue(resolved_type, std.math.nan(f128))).toIntern());16776 return Air.internedToRef((try pt.floatValue(resolved_type, std.math.nan(f128))).toIntern());
16778 }16777 }
16779 } else if (resolved_type.isAnyFloat()) {16778 } else if (resolved_type.isAnyFloat()) {
...@@ -16786,7 +16785,7 @@ fn analyzeArithmetic(...@@ -16786,7 +16785,7 @@ fn analyzeArithmetic(
16786 return casted_lhs;16785 return casted_lhs;
16787 }16786 }
16788 if (maybe_lhs_val) |lhs_val| {16787 if (maybe_lhs_val) |lhs_val| {
16789 if (lhs_val.isUndef(mod)) {16788 if (lhs_val.isUndef(zcu)) {
16790 if (is_int) {16789 if (is_int) {
16791 return sema.failWithUseOfUndef(block, lhs_src);16790 return sema.failWithUseOfUndef(block, lhs_src);
16792 } else {16791 } else {
...@@ -16822,7 +16821,7 @@ fn analyzeArithmetic(...@@ -16822,7 +16821,7 @@ fn analyzeArithmetic(
16822 else => unreachable,16821 else => unreachable,
16823 };16822 };
16824 if (maybe_lhs_val) |lhs_val| {16823 if (maybe_lhs_val) |lhs_val| {
16825 if (!lhs_val.isUndef(mod)) {16824 if (!lhs_val.isUndef(zcu)) {
16826 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {16825 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
16827 const zero_val = try sema.splat(resolved_type, scalar_zero);16826 const zero_val = try sema.splat(resolved_type, scalar_zero);
16828 return Air.internedToRef(zero_val.toIntern());16827 return Air.internedToRef(zero_val.toIntern());
...@@ -16833,7 +16832,7 @@ fn analyzeArithmetic(...@@ -16833,7 +16832,7 @@ fn analyzeArithmetic(
16833 }16832 }
16834 }16833 }
16835 if (maybe_rhs_val) |rhs_val| {16834 if (maybe_rhs_val) |rhs_val| {
16836 if (rhs_val.isUndef(mod)) {16835 if (rhs_val.isUndef(zcu)) {
16837 return pt.undefRef(resolved_type);16836 return pt.undefRef(resolved_type);
16838 }16837 }
16839 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16838 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
...@@ -16844,7 +16843,7 @@ fn analyzeArithmetic(...@@ -16844,7 +16843,7 @@ fn analyzeArithmetic(
16844 return casted_lhs;16843 return casted_lhs;
16845 }16844 }
16846 if (maybe_lhs_val) |lhs_val| {16845 if (maybe_lhs_val) |lhs_val| {
16847 if (lhs_val.isUndef(mod)) {16846 if (lhs_val.isUndef(zcu)) {
16848 return pt.undefRef(resolved_type);16847 return pt.undefRef(resolved_type);
16849 }16848 }
16850 return Air.internedToRef((try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, pt)).toIntern());16849 return Air.internedToRef((try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, pt)).toIntern());
...@@ -16867,7 +16866,7 @@ fn analyzeArithmetic(...@@ -16867,7 +16866,7 @@ fn analyzeArithmetic(
16867 else => unreachable,16866 else => unreachable,
16868 };16867 };
16869 if (maybe_lhs_val) |lhs_val| {16868 if (maybe_lhs_val) |lhs_val| {
16870 if (!lhs_val.isUndef(mod)) {16869 if (!lhs_val.isUndef(zcu)) {
16871 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {16870 if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
16872 const zero_val = try sema.splat(resolved_type, scalar_zero);16871 const zero_val = try sema.splat(resolved_type, scalar_zero);
16873 return Air.internedToRef(zero_val.toIntern());16872 return Air.internedToRef(zero_val.toIntern());
...@@ -16878,7 +16877,7 @@ fn analyzeArithmetic(...@@ -16878,7 +16877,7 @@ fn analyzeArithmetic(
16878 }16877 }
16879 }16878 }
16880 if (maybe_rhs_val) |rhs_val| {16879 if (maybe_rhs_val) |rhs_val| {
16881 if (rhs_val.isUndef(mod)) {16880 if (rhs_val.isUndef(zcu)) {
16882 return pt.undefRef(resolved_type);16881 return pt.undefRef(resolved_type);
16883 }16882 }
16884 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {16883 if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
...@@ -16889,7 +16888,7 @@ fn analyzeArithmetic(...@@ -16889,7 +16888,7 @@ fn analyzeArithmetic(
16889 return casted_lhs;16888 return casted_lhs;
16890 }16889 }
16891 if (maybe_lhs_val) |lhs_val| {16890 if (maybe_lhs_val) |lhs_val| {
16892 if (lhs_val.isUndef(mod)) {16891 if (lhs_val.isUndef(zcu)) {
16893 return pt.undefRef(resolved_type);16892 return pt.undefRef(resolved_type);
16894 }16893 }
1689516894
...@@ -16909,7 +16908,7 @@ fn analyzeArithmetic(...@@ -16909,7 +16908,7 @@ fn analyzeArithmetic(
16909 try sema.requireRuntimeBlock(block, src, runtime_src);16908 try sema.requireRuntimeBlock(block, src, runtime_src);
1691016909
16911 if (block.wantSafety() and want_safety and scalar_tag == .Int) {16910 if (block.wantSafety() and want_safety and scalar_tag == .Int) {
16912 if (mod.backendSupportsFeature(.safety_checked_instructions)) {16911 if (zcu.backendSupportsFeature(.safety_checked_instructions)) {
16913 if (air_tag != air_tag_safe) {16912 if (air_tag != air_tag_safe) {
16914 _ = try sema.preparePanicId(block, src, .integer_overflow);16913 _ = try sema.preparePanicId(block, src, .integer_overflow);
16915 }16914 }
...@@ -16934,7 +16933,7 @@ fn analyzeArithmetic(...@@ -16934,7 +16933,7 @@ fn analyzeArithmetic(
16934 } },16933 } },
16935 });16934 });
16936 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);16935 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)
16938 try block.addInst(.{16937 try block.addInst(.{
16939 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,16938 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
16940 .data = .{ .reduce = .{16939 .data = .{ .reduce = .{
...@@ -16969,11 +16968,11 @@ fn analyzePtrArithmetic(...@@ -16969,11 +16968,11 @@ fn analyzePtrArithmetic(
16969 // coerce to isize instead of usize.16968 // coerce to isize instead of usize.
16970 const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src);16969 const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src);
16971 const pt = sema.pt;16970 const pt = sema.pt;
16972 const mod = pt.zcu;16971 const zcu = pt.zcu;
16973 const opt_ptr_val = try sema.resolveValue(ptr);16972 const opt_ptr_val = try sema.resolveValue(ptr);
16974 const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset);16973 const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset);
16975 const ptr_ty = sema.typeOf(ptr);16974 const ptr_ty = sema.typeOf(ptr);
16976 const ptr_info = ptr_ty.ptrInfo(mod);16975 const ptr_info = ptr_ty.ptrInfo(zcu);
16977 assert(ptr_info.flags.size == .Many or ptr_info.flags.size == .C);16976 assert(ptr_info.flags.size == .Many or ptr_info.flags.size == .C);
1697816977
16979 const new_ptr_ty = t: {16978 const new_ptr_ty = t: {
...@@ -16985,7 +16984,7 @@ fn analyzePtrArithmetic(...@@ -16985,7 +16984,7 @@ fn analyzePtrArithmetic(
16985 }16984 }
16986 // If the addend is not a comptime-known value we can still count on16985 // If the addend is not a comptime-known value we can still count on
16987 // it being a multiple of the type size.16986 // 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);
16989 const addend = if (opt_off_val) |off_val| a: {16988 const addend = if (opt_off_val) |off_val| a: {
16990 const off_int = try sema.usizeCast(block, offset_src, try off_val.toUnsignedIntSema(pt));16989 const off_int = try sema.usizeCast(block, offset_src, try off_val.toUnsignedIntSema(pt));
16991 break :a elem_size * off_int;16990 break :a elem_size * off_int;
...@@ -17017,12 +17016,12 @@ fn analyzePtrArithmetic(...@@ -17017,12 +17016,12 @@ fn analyzePtrArithmetic(
17017 const runtime_src = rs: {17016 const runtime_src = rs: {
17018 if (opt_ptr_val) |ptr_val| {17017 if (opt_ptr_val) |ptr_val| {
17019 if (opt_off_val) |offset_val| {17018 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
17022 const offset_int = try sema.usizeCast(block, offset_src, try offset_val.toUnsignedIntSema(pt));17021 const offset_int = try sema.usizeCast(block, offset_src, try offset_val.toUnsignedIntSema(pt));
17023 if (offset_int == 0) return ptr;17022 if (offset_int == 0) return ptr;
17024 if (air_tag == .ptr_sub) {17023 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);
17026 const new_ptr_val = try sema.ptrSubtract(block, op_src, ptr_val, offset_int * elem_size, new_ptr_ty);17025 const new_ptr_val = try sema.ptrSubtract(block, op_src, ptr_val, offset_int * elem_size, new_ptr_ty);
17027 return Air.internedToRef(new_ptr_val.toIntern());17026 return Air.internedToRef(new_ptr_val.toIntern());
17028 } else {17027 } else {
...@@ -17067,7 +17066,7 @@ fn zirAsm(...@@ -17067,7 +17066,7 @@ fn zirAsm(
17067 defer tracy.end();17066 defer tracy.end();
1706817067
17069 const pt = sema.pt;17068 const pt = sema.pt;
17070 const mod = pt.zcu;17069 const zcu = pt.zcu;
17071 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);17070 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
17072 const src = block.nodeOffset(extra.data.src_node);17071 const src = block.nodeOffset(extra.data.src_node);
17073 const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node });17072 const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node });
...@@ -17099,7 +17098,7 @@ fn zirAsm(...@@ -17099,7 +17098,7 @@ fn zirAsm(
17099 if (is_volatile) {17098 if (is_volatile) {
17100 return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{});17099 return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{});
17101 }17100 }
17102 try mod.addGlobalAssembly(sema.owner.unwrap().cau, asm_source);17101 try zcu.addGlobalAssembly(sema.owner.unwrap().cau, asm_source);
17103 return .void_value;17102 return .void_value;
17104 }17103 }
1710517104
...@@ -17153,7 +17152,7 @@ fn zirAsm(...@@ -17153,7 +17152,7 @@ fn zirAsm(
1715317152
17154 const uncasted_arg = try sema.resolveInst(input.data.operand);17153 const uncasted_arg = try sema.resolveInst(input.data.operand);
17155 const uncasted_arg_ty = sema.typeOf(uncasted_arg);17154 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
17156 switch (uncasted_arg_ty.zigTypeTag(mod)) {17155 switch (uncasted_arg_ty.zigTypeTag(zcu)) {
17157 .ComptimeInt => arg.* = try sema.coerce(block, Type.usize, uncasted_arg, src),17156 .ComptimeInt => arg.* = try sema.coerce(block, Type.usize, uncasted_arg, src),
17158 .ComptimeFloat => arg.* = try sema.coerce(block, Type.f64, uncasted_arg, src),17157 .ComptimeFloat => arg.* = try sema.coerce(block, Type.f64, uncasted_arg, src),
17159 else => {17158 else => {
...@@ -17236,7 +17235,7 @@ fn zirCmpEq(...@@ -17236,7 +17235,7 @@ fn zirCmpEq(
17236 defer tracy.end();17235 defer tracy.end();
1723717236
17238 const pt = sema.pt;17237 const pt = sema.pt;
17239 const mod = pt.zcu;17238 const zcu = pt.zcu;
17240 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;17239 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17241 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;17240 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
17242 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);17241 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
...@@ -17247,18 +17246,18 @@ fn zirCmpEq(...@@ -17247,18 +17246,18 @@ fn zirCmpEq(
1724717246
17248 const lhs_ty = sema.typeOf(lhs);17247 const lhs_ty = sema.typeOf(lhs);
17249 const rhs_ty = sema.typeOf(rhs);17248 const rhs_ty = sema.typeOf(rhs);
17250 const lhs_ty_tag = lhs_ty.zigTypeTag(mod);17249 const lhs_ty_tag = lhs_ty.zigTypeTag(zcu);
17251 const rhs_ty_tag = rhs_ty.zigTypeTag(mod);17250 const rhs_ty_tag = rhs_ty.zigTypeTag(zcu);
17252 if (lhs_ty_tag == .Null and rhs_ty_tag == .Null) {17251 if (lhs_ty_tag == .Null and rhs_ty_tag == .Null) {
17253 // null == null, null != null17252 // null == null, null != null
17254 return if (op == .eq) .bool_true else .bool_false;17253 return if (op == .eq) .bool_true else .bool_false;
17255 }17254 }
1725617255
17257 // comparing null with optionals17256 // 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))) {
17259 return sema.analyzeIsNull(block, src, rhs, op == .neq);17258 return sema.analyzeIsNull(block, src, rhs, op == .neq);
17260 }17259 }
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))) {
17262 return sema.analyzeIsNull(block, src, lhs, op == .neq);17261 return sema.analyzeIsNull(block, src, lhs, op == .neq);
17263 }17262 }
1726417263
...@@ -17278,11 +17277,11 @@ fn zirCmpEq(...@@ -17278,11 +17277,11 @@ fn zirCmpEq(
17278 const runtime_src: LazySrcLoc = src: {17277 const runtime_src: LazySrcLoc = src: {
17279 if (try sema.resolveValue(lhs)) |lval| {17278 if (try sema.resolveValue(lhs)) |lval| {
17280 if (try sema.resolveValue(rhs)) |rval| {17279 if (try sema.resolveValue(rhs)) |rval| {
17281 if (lval.isUndef(mod) or rval.isUndef(mod)) {17280 if (lval.isUndef(zcu) or rval.isUndef(zcu)) {
17282 return pt.undefRef(Type.bool);17281 return pt.undefRef(Type.bool);
17283 }17282 }
17284 const lkey = mod.intern_pool.indexToKey(lval.toIntern());17283 const lkey = zcu.intern_pool.indexToKey(lval.toIntern());
17285 const rkey = mod.intern_pool.indexToKey(rval.toIntern());17284 const rkey = zcu.intern_pool.indexToKey(rval.toIntern());
17286 return if ((lkey.err.name == rkey.err.name) == (op == .eq))17285 return if ((lkey.err.name == rkey.err.name) == (op == .eq))
17287 .bool_true17286 .bool_true
17288 else17287 else
...@@ -17300,7 +17299,7 @@ fn zirCmpEq(...@@ -17300,7 +17299,7 @@ fn zirCmpEq(
17300 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {17299 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {
17301 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);17300 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);
17302 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs);17301 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;
17304 }17303 }
17305 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true);17304 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true);
17306}17305}
...@@ -17316,14 +17315,14 @@ fn analyzeCmpUnionTag(...@@ -17316,14 +17315,14 @@ fn analyzeCmpUnionTag(
17316 op: std.math.CompareOperator,17315 op: std.math.CompareOperator,
17317) CompileError!Air.Inst.Ref {17316) CompileError!Air.Inst.Ref {
17318 const pt = sema.pt;17317 const pt = sema.pt;
17319 const mod = pt.zcu;17318 const zcu = pt.zcu;
17320 const union_ty = sema.typeOf(un);17319 const union_ty = sema.typeOf(un);
17321 try union_ty.resolveFields(pt);17320 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 {
17323 const msg = msg: {17322 const msg = msg: {
17324 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});17323 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
17325 errdefer msg.destroy(sema.gpa);17324 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)});
17327 break :msg msg;17326 break :msg msg;
17328 };17327 };
17329 return sema.failWithOwnedErrorMsg(block, msg);17328 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -17334,9 +17333,9 @@ fn analyzeCmpUnionTag(...@@ -17334,9 +17333,9 @@ fn analyzeCmpUnionTag(
17334 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);17333 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);
1733517334
17336 if (try sema.resolveValue(coerced_tag)) |enum_val| {17335 if (try sema.resolveValue(coerced_tag)) |enum_val| {
17337 if (enum_val.isUndef(mod)) return pt.undefRef(Type.bool);17336 if (enum_val.isUndef(zcu)) return pt.undefRef(Type.bool);
17338 const field_ty = union_ty.unionFieldType(enum_val, mod).?;17337 const field_ty = union_ty.unionFieldType(enum_val, zcu).?;
17339 if (field_ty.zigTypeTag(mod) == .NoReturn) {17338 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
17340 return .bool_false;17339 return .bool_false;
17341 }17340 }
17342 }17341 }
...@@ -17376,33 +17375,33 @@ fn analyzeCmp(...@@ -17376,33 +17375,33 @@ fn analyzeCmp(
17376 is_equality_cmp: bool,17375 is_equality_cmp: bool,
17377) CompileError!Air.Inst.Ref {17376) CompileError!Air.Inst.Ref {
17378 const pt = sema.pt;17377 const pt = sema.pt;
17379 const mod = pt.zcu;17378 const zcu = pt.zcu;
17380 const lhs_ty = sema.typeOf(lhs);17379 const lhs_ty = sema.typeOf(lhs);
17381 const rhs_ty = sema.typeOf(rhs);17380 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) {
17383 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);17382 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
17384 }17383 }
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) {
17387 return sema.cmpVector(block, src, lhs, rhs, op, lhs_src, rhs_src);17386 return sema.cmpVector(block, src, lhs, rhs, op, lhs_src, rhs_src);
17388 }17387 }
17389 if (lhs_ty.isNumeric(mod) and rhs_ty.isNumeric(mod)) {17388 if (lhs_ty.isNumeric(zcu) and rhs_ty.isNumeric(zcu)) {
17390 // This operation allows any combination of integer and float types, regardless of the17389 // This operation allows any combination of integer and float types, regardless of the
17391 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for17390 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
17392 // numeric types.17391 // numeric types.
17393 return sema.cmpNumeric(block, src, lhs, rhs, op, lhs_src, rhs_src);17392 return sema.cmpNumeric(block, src, lhs, rhs, op, lhs_src, rhs_src);
17394 }17393 }
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) {
17396 const casted_lhs = try sema.analyzeErrUnionCode(block, lhs_src, lhs);17395 const casted_lhs = try sema.analyzeErrUnionCode(block, lhs_src, lhs);
17397 return sema.cmpSelf(block, src, casted_lhs, rhs, op, lhs_src, rhs_src);17396 return sema.cmpSelf(block, src, casted_lhs, rhs, op, lhs_src, rhs_src);
17398 }17397 }
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) {
17400 const casted_rhs = try sema.analyzeErrUnionCode(block, rhs_src, rhs);17399 const casted_rhs = try sema.analyzeErrUnionCode(block, rhs_src, rhs);
17401 return sema.cmpSelf(block, src, lhs, casted_rhs, op, lhs_src, rhs_src);17400 return sema.cmpSelf(block, src, lhs, casted_rhs, op, lhs_src, rhs_src);
17402 }17401 }
17403 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };17402 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
17404 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });17403 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)) {
17406 return sema.fail(block, src, "operator {s} not allowed for type '{}'", .{17405 return sema.fail(block, src, "operator {s} not allowed for type '{}'", .{
17407 compareOperatorName(op), resolved_type.fmt(pt),17406 compareOperatorName(op), resolved_type.fmt(pt),
17408 });17407 });
...@@ -17434,15 +17433,15 @@ fn cmpSelf(...@@ -17434,15 +17433,15 @@ fn cmpSelf(
17434 rhs_src: LazySrcLoc,17433 rhs_src: LazySrcLoc,
17435) CompileError!Air.Inst.Ref {17434) CompileError!Air.Inst.Ref {
17436 const pt = sema.pt;17435 const pt = sema.pt;
17437 const mod = pt.zcu;17436 const zcu = pt.zcu;
17438 const resolved_type = sema.typeOf(casted_lhs);17437 const resolved_type = sema.typeOf(casted_lhs);
17439 const runtime_src: LazySrcLoc = src: {17438 const runtime_src: LazySrcLoc = src: {
17440 if (try sema.resolveValue(casted_lhs)) |lhs_val| {17439 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);
17442 if (try sema.resolveValue(casted_rhs)) |rhs_val| {17441 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) {
17446 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type);17445 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type);
17447 return Air.internedToRef(cmp_val.toIntern());17446 return Air.internedToRef(cmp_val.toIntern());
17448 }17447 }
...@@ -17452,7 +17451,7 @@ fn cmpSelf(...@@ -17452,7 +17451,7 @@ fn cmpSelf(
17452 else17451 else
17453 .bool_false;17452 .bool_false;
17454 } else {17453 } else {
17455 if (resolved_type.zigTypeTag(mod) == .Bool) {17454 if (resolved_type.zigTypeTag(zcu) == .Bool) {
17456 // We can lower bool eq/neq more efficiently.17455 // We can lower bool eq/neq more efficiently.
17457 return sema.runtimeBoolCmp(block, src, op, casted_rhs, lhs_val.toBool(), rhs_src);17456 return sema.runtimeBoolCmp(block, src, op, casted_rhs, lhs_val.toBool(), rhs_src);
17458 }17457 }
...@@ -17461,9 +17460,9 @@ fn cmpSelf(...@@ -17461,9 +17460,9 @@ fn cmpSelf(
17461 } else {17460 } else {
17462 // For bools, we still check the other operand, because we can lower17461 // For bools, we still check the other operand, because we can lower
17463 // bool eq/neq more efficiently.17462 // bool eq/neq more efficiently.
17464 if (resolved_type.zigTypeTag(mod) == .Bool) {17463 if (resolved_type.zigTypeTag(zcu) == .Bool) {
17465 if (try sema.resolveValue(casted_rhs)) |rhs_val| {17464 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);
17467 return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src);17466 return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src);
17468 }17467 }
17469 }17468 }
...@@ -17471,7 +17470,7 @@ fn cmpSelf(...@@ -17471,7 +17470,7 @@ fn cmpSelf(
17471 }17470 }
17472 };17471 };
17473 try sema.requireRuntimeBlock(block, src, runtime_src);17472 try sema.requireRuntimeBlock(block, src, runtime_src);
17474 if (resolved_type.zigTypeTag(mod) == .Vector) {17473 if (resolved_type.zigTypeTag(zcu) == .Vector) {
17475 return block.addCmpVector(casted_lhs, casted_rhs, op);17474 return block.addCmpVector(casted_lhs, casted_rhs, op);
17476 }17475 }
17477 const tag = Air.Inst.Tag.fromCmpOp(op, block.float_mode == .optimized);17476 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....@@ -17535,17 +17534,17 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
17535 .AnyFrame,17534 .AnyFrame,
17536 => {},17535 => {},
17537 }17536 }
17538 const val = try ty.lazyAbiSize(pt);17537 const val = try ty.abiSizeLazy(pt);
17539 return Air.internedToRef(val.toIntern());17538 return Air.internedToRef(val.toIntern());
17540}17539}
1754117540
17542fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {17541fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17543 const pt = sema.pt;17542 const pt = sema.pt;
17544 const mod = pt.zcu;17543 const zcu = pt.zcu;
17545 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;17544 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17546 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);17545 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
17547 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);17546 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
17548 switch (operand_ty.zigTypeTag(mod)) {17547 switch (operand_ty.zigTypeTag(zcu)) {
17549 .Fn,17548 .Fn,
17550 .NoReturn,17549 .NoReturn,
17551 .Undefined,17550 .Undefined,
...@@ -17576,7 +17575,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -17576,7 +17575,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
17576 .AnyFrame,17575 .AnyFrame,
17577 => {},17576 => {},
17578 }17577 }
17579 const bit_size = try operand_ty.bitSizeAdvanced(pt, .sema);17578 const bit_size = try operand_ty.bitSizeSema(pt);
17580 return pt.intRef(Type.comptime_int, bit_size);17579 return pt.intRef(Type.comptime_int, bit_size);
17581}17580}
1758217581
...@@ -17599,9 +17598,9 @@ fn zirThis(...@@ -17599,9 +17598,9 @@ fn zirThis(
1759917598
17600fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {17599fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
17601 const pt = sema.pt;17600 const pt = sema.pt;
17602 const mod = pt.zcu;17601 const zcu = pt.zcu;
17603 const ip = &mod.intern_pool;17602 const ip = &zcu.intern_pool;
17604 const captures = Type.fromInterned(mod.namespacePtr(block.namespace).owner_type).getCaptures(mod);17603 const captures = Type.fromInterned(zcu.namespacePtr(block.namespace).owner_type).getCaptures(zcu);
1760517604
17606 const src_node: i32 = @bitCast(extended.operand);17605 const src_node: i32 = @bitCast(extended.operand);
17607 const src = block.nodeOffset(src_node);17606 const src = block.nodeOffset(src_node);
...@@ -17619,7 +17618,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17619,7 +17618,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17619 const msg = msg: {17618 const msg = msg: {
17620 const name = name: {17619 const name = name: {
17621 // TODO: we should probably store this name in the ZIR to avoid this complexity.17620 // 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).?;
17623 const tree = file.getTree(sema.gpa) catch |err| {17622 const tree = file.getTree(sema.gpa) catch |err| {
17624 // In this case we emit a warning + a less precise source location.17623 // In this case we emit a warning + a less precise source location.
17625 log.warn("unable to load {s}: {s}", .{17624 log.warn("unable to load {s}: {s}", .{
...@@ -17647,7 +17646,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17647,7 +17646,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17647 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {17646 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {
17648 const msg = msg: {17647 const msg = msg: {
17649 const name = name: {17648 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).?;
17651 const tree = file.getTree(sema.gpa) catch |err| {17650 const tree = file.getTree(sema.gpa) catch |err| {
17652 // In this case we emit a warning + a less precise source location.17651 // In this case we emit a warning + a less precise source location.
17653 log.warn("unable to load {s}: {s}", .{17652 log.warn("unable to load {s}: {s}", .{
...@@ -17816,20 +17815,20 @@ fn zirBuiltinSrc(...@@ -17816,20 +17815,20 @@ fn zirBuiltinSrc(
1781617815
17817fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {17816fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17818 const pt = sema.pt;17817 const pt = sema.pt;
17819 const mod = pt.zcu;17818 const zcu = pt.zcu;
17820 const gpa = sema.gpa;17819 const gpa = sema.gpa;
17821 const ip = &mod.intern_pool;17820 const ip = &zcu.intern_pool;
17822 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;17821 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17823 const src = block.nodeOffset(inst_data.src_node);17822 const src = block.nodeOffset(inst_data.src_node);
17824 const ty = try sema.resolveType(block, src, inst_data.operand);17823 const ty = try sema.resolveType(block, src, inst_data.operand);
17825 const type_info_ty = try pt.getBuiltinType("Type");17824 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| {
17829 try sema.declareDependency(.{ .namespace = type_decl_inst });17828 try sema.declareDependency(.{ .namespace = type_decl_inst });
17830 }17829 }
1783117830
17832 switch (ty.zigTypeTag(mod)) {17831 switch (ty.zigTypeTag(zcu)) {
17833 .Type,17832 .Type,
17834 .Void,17833 .Void,
17835 .Bool,17834 .Bool,
...@@ -17848,7 +17847,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17848,7 +17847,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17848 const fn_info_nav = try sema.namespaceLookup(17847 const fn_info_nav = try sema.namespaceLookup(
17849 block,17848 block,
17850 src,17849 src,
17851 type_info_ty.getNamespaceIndex(mod),17850 type_info_ty.getNamespaceIndex(zcu),
17852 try ip.getOrPutString(gpa, pt.tid, "Fn", .no_embedded_nulls),17851 try ip.getOrPutString(gpa, pt.tid, "Fn", .no_embedded_nulls),
17853 ) orelse @panic("std.builtin.Type is corrupt");17852 ) orelse @panic("std.builtin.Type is corrupt");
17854 try sema.ensureNavResolved(src, fn_info_nav);17853 try sema.ensureNavResolved(src, fn_info_nav);
...@@ -17857,13 +17856,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17857,13 +17856,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17857 const param_info_nav = try sema.namespaceLookup(17856 const param_info_nav = try sema.namespaceLookup(
17858 block,17857 block,
17859 src,17858 src,
17860 fn_info_ty.getNamespaceIndex(mod),17859 fn_info_ty.getNamespaceIndex(zcu),
17861 try ip.getOrPutString(gpa, pt.tid, "Param", .no_embedded_nulls),17860 try ip.getOrPutString(gpa, pt.tid, "Param", .no_embedded_nulls),
17862 ) orelse @panic("std.builtin.Type is corrupt");17861 ) orelse @panic("std.builtin.Type is corrupt");
17863 try sema.ensureNavResolved(src, param_info_nav);17862 try sema.ensureNavResolved(src, param_info_nav);
17864 const param_info_ty = Type.fromInterned(ip.getNav(param_info_nav).status.resolved.val);17863 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).?;
17867 const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);17866 const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
17868 for (param_vals, 0..) |*param_val, i| {17867 for (param_vals, 0..) |*param_val, i| {
17869 const param_ty = func_ty_info.param_types.get(ip)[i];17868 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...@@ -17908,7 +17907,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17908 .is_const = true,17907 .is_const = true,
17909 },17908 },
17910 })).toIntern();17909 })).toIntern();
17911 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();17910 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
17912 break :v try pt.intern(.{ .slice = .{17911 break :v try pt.intern(.{ .slice = .{
17913 .ty = slice_ty,17912 .ty = slice_ty,
17914 .ptr = try pt.intern(.{ .ptr = .{17913 .ptr = try pt.intern(.{ .ptr = .{
...@@ -17958,14 +17957,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17958,14 +17957,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17958 const int_info_nav = try sema.namespaceLookup(17957 const int_info_nav = try sema.namespaceLookup(
17959 block,17958 block,
17960 src,17959 src,
17961 type_info_ty.getNamespaceIndex(mod),17960 type_info_ty.getNamespaceIndex(zcu),
17962 try ip.getOrPutString(gpa, pt.tid, "Int", .no_embedded_nulls),17961 try ip.getOrPutString(gpa, pt.tid, "Int", .no_embedded_nulls),
17963 ) orelse @panic("std.builtin.Type is corrupt");17962 ) orelse @panic("std.builtin.Type is corrupt");
17964 try sema.ensureNavResolved(src, int_info_nav);17963 try sema.ensureNavResolved(src, int_info_nav);
17965 const int_info_ty = Type.fromInterned(ip.getNav(int_info_nav).status.resolved.val);17964 const int_info_ty = Type.fromInterned(ip.getNav(int_info_nav).status.resolved.val);
1796617965
17967 const signedness_ty = try pt.getBuiltinType("Signedness");17966 const signedness_ty = try pt.getBuiltinType("Signedness");
17968 const info = ty.intInfo(mod);17967 const info = ty.intInfo(zcu);
17969 const field_values = .{17968 const field_values = .{
17970 // signedness: Signedness,17969 // signedness: Signedness,
17971 (try pt.enumValueFieldIndex(signedness_ty, @intFromEnum(info.signedness))).toIntern(),17970 (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...@@ -17985,7 +17984,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17985 const float_info_nav = try sema.namespaceLookup(17984 const float_info_nav = try sema.namespaceLookup(
17986 block,17985 block,
17987 src,17986 src,
17988 type_info_ty.getNamespaceIndex(mod),17987 type_info_ty.getNamespaceIndex(zcu),
17989 try ip.getOrPutString(gpa, pt.tid, "Float", .no_embedded_nulls),17988 try ip.getOrPutString(gpa, pt.tid, "Float", .no_embedded_nulls),
17990 ) orelse @panic("std.builtin.Type is corrupt");17989 ) orelse @panic("std.builtin.Type is corrupt");
17991 try sema.ensureNavResolved(src, float_info_nav);17990 try sema.ensureNavResolved(src, float_info_nav);
...@@ -17993,7 +17992,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17993,7 +17992,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1799317992
17994 const field_vals = .{17993 const field_vals = .{
17995 // bits: u16,17994 // bits: u16,
17996 (try pt.intValue(Type.u16, ty.bitSize(pt))).toIntern(),17995 (try pt.intValue(Type.u16, ty.bitSize(zcu))).toIntern(),
17997 };17996 };
17998 return Air.internedToRef((try pt.intern(.{ .un = .{17997 return Air.internedToRef((try pt.intern(.{ .un = .{
17999 .ty = type_info_ty.toIntern(),17998 .ty = type_info_ty.toIntern(),
...@@ -18005,7 +18004,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18005,7 +18004,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18005 } })));18004 } })));
18006 },18005 },
18007 .Pointer => {18006 .Pointer => {
18008 const info = ty.ptrInfo(mod);18007 const info = ty.ptrInfo(zcu);
18009 const alignment = if (info.flags.alignment.toByteUnits()) |alignment|18008 const alignment = if (info.flags.alignment.toByteUnits()) |alignment|
18010 try pt.intValue(Type.comptime_int, alignment)18009 try pt.intValue(Type.comptime_int, alignment)
18011 else18010 else
...@@ -18016,7 +18015,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18016,7 +18015,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18016 const nav = try sema.namespaceLookup(18015 const nav = try sema.namespaceLookup(
18017 block,18016 block,
18018 src,18017 src,
18019 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),18018 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
18020 try ip.getOrPutString(gpa, pt.tid, "Pointer", .no_embedded_nulls),18019 try ip.getOrPutString(gpa, pt.tid, "Pointer", .no_embedded_nulls),
18021 ) orelse @panic("std.builtin.Type is corrupt");18020 ) orelse @panic("std.builtin.Type is corrupt");
18022 try sema.ensureNavResolved(src, nav);18021 try sema.ensureNavResolved(src, nav);
...@@ -18026,7 +18025,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18026,7 +18025,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18026 const nav = try sema.namespaceLookup(18025 const nav = try sema.namespaceLookup(
18027 block,18026 block,
18028 src,18027 src,
18029 pointer_ty.getNamespaceIndex(mod),18028 pointer_ty.getNamespaceIndex(zcu),
18030 try ip.getOrPutString(gpa, pt.tid, "Size", .no_embedded_nulls),18029 try ip.getOrPutString(gpa, pt.tid, "Size", .no_embedded_nulls),
18031 ) orelse @panic("std.builtin.Type is corrupt");18030 ) orelse @panic("std.builtin.Type is corrupt");
18032 try sema.ensureNavResolved(src, nav);18031 try sema.ensureNavResolved(src, nav);
...@@ -18068,14 +18067,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18068,14 +18067,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18068 const nav = try sema.namespaceLookup(18067 const nav = try sema.namespaceLookup(
18069 block,18068 block,
18070 src,18069 src,
18071 type_info_ty.getNamespaceIndex(mod),18070 type_info_ty.getNamespaceIndex(zcu),
18072 try ip.getOrPutString(gpa, pt.tid, "Array", .no_embedded_nulls),18071 try ip.getOrPutString(gpa, pt.tid, "Array", .no_embedded_nulls),
18073 ) orelse @panic("std.builtin.Type is corrupt");18072 ) orelse @panic("std.builtin.Type is corrupt");
18074 try sema.ensureNavResolved(src, nav);18073 try sema.ensureNavResolved(src, nav);
18075 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);18074 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);
18076 };18075 };
1807718076
18078 const info = ty.arrayInfo(mod);18077 const info = ty.arrayInfo(zcu);
18079 const field_values = .{18078 const field_values = .{
18080 // len: comptime_int,18079 // len: comptime_int,
18081 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),18080 (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...@@ -18098,14 +18097,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18098 const nav = try sema.namespaceLookup(18097 const nav = try sema.namespaceLookup(
18099 block,18098 block,
18100 src,18099 src,
18101 type_info_ty.getNamespaceIndex(mod),18100 type_info_ty.getNamespaceIndex(zcu),
18102 try ip.getOrPutString(gpa, pt.tid, "Vector", .no_embedded_nulls),18101 try ip.getOrPutString(gpa, pt.tid, "Vector", .no_embedded_nulls),
18103 ) orelse @panic("std.builtin.Type is corrupt");18102 ) orelse @panic("std.builtin.Type is corrupt");
18104 try sema.ensureNavResolved(src, nav);18103 try sema.ensureNavResolved(src, nav);
18105 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);18104 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);
18106 };18105 };
1810718106
18108 const info = ty.arrayInfo(mod);18107 const info = ty.arrayInfo(zcu);
18109 const field_values = .{18108 const field_values = .{
18110 // len: comptime_int,18109 // len: comptime_int,
18111 (try pt.intValue(Type.comptime_int, info.len)).toIntern(),18110 (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...@@ -18126,7 +18125,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18126 const nav = try sema.namespaceLookup(18125 const nav = try sema.namespaceLookup(
18127 block,18126 block,
18128 src,18127 src,
18129 type_info_ty.getNamespaceIndex(mod),18128 type_info_ty.getNamespaceIndex(zcu),
18130 try ip.getOrPutString(gpa, pt.tid, "Optional", .no_embedded_nulls),18129 try ip.getOrPutString(gpa, pt.tid, "Optional", .no_embedded_nulls),
18131 ) orelse @panic("std.builtin.Type is corrupt");18130 ) orelse @panic("std.builtin.Type is corrupt");
18132 try sema.ensureNavResolved(src, nav);18131 try sema.ensureNavResolved(src, nav);
...@@ -18135,7 +18134,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18135,7 +18134,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1813518134
18136 const field_values = .{18135 const field_values = .{
18137 // child: type,18136 // child: type,
18138 ty.optionalChild(mod).toIntern(),18137 ty.optionalChild(zcu).toIntern(),
18139 };18138 };
18140 return Air.internedToRef((try pt.intern(.{ .un = .{18139 return Air.internedToRef((try pt.intern(.{ .un = .{
18141 .ty = type_info_ty.toIntern(),18140 .ty = type_info_ty.toIntern(),
...@@ -18152,7 +18151,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18152,7 +18151,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18152 const nav = try sema.namespaceLookup(18151 const nav = try sema.namespaceLookup(
18153 block,18152 block,
18154 src,18153 src,
18155 type_info_ty.getNamespaceIndex(mod),18154 type_info_ty.getNamespaceIndex(zcu),
18156 try ip.getOrPutString(gpa, pt.tid, "Error", .no_embedded_nulls),18155 try ip.getOrPutString(gpa, pt.tid, "Error", .no_embedded_nulls),
18157 ) orelse @panic("std.builtin.Type is corrupt");18156 ) orelse @panic("std.builtin.Type is corrupt");
18158 try sema.ensureNavResolved(src, nav);18157 try sema.ensureNavResolved(src, nav);
...@@ -18226,7 +18225,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18226,7 +18225,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18226 .ty = array_errors_ty.toIntern(),18225 .ty = array_errors_ty.toIntern(),
18227 .storage = .{ .elems = vals },18226 .storage = .{ .elems = vals },
18228 } });18227 } });
18229 const manyptr_errors_ty = slice_errors_ty.slicePtrFieldType(mod).toIntern();18228 const manyptr_errors_ty = slice_errors_ty.slicePtrFieldType(zcu).toIntern();
18230 break :v try pt.intern(.{ .slice = .{18229 break :v try pt.intern(.{ .slice = .{
18231 .ty = slice_errors_ty.toIntern(),18230 .ty = slice_errors_ty.toIntern(),
18232 .ptr = try pt.intern(.{ .ptr = .{18231 .ptr = try pt.intern(.{ .ptr = .{
...@@ -18257,7 +18256,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18257,7 +18256,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18257 const nav = try sema.namespaceLookup(18256 const nav = try sema.namespaceLookup(
18258 block,18257 block,
18259 src,18258 src,
18260 type_info_ty.getNamespaceIndex(mod),18259 type_info_ty.getNamespaceIndex(zcu),
18261 try ip.getOrPutString(gpa, pt.tid, "ErrorUnion", .no_embedded_nulls),18260 try ip.getOrPutString(gpa, pt.tid, "ErrorUnion", .no_embedded_nulls),
18262 ) orelse @panic("std.builtin.Type is corrupt");18261 ) orelse @panic("std.builtin.Type is corrupt");
18263 try sema.ensureNavResolved(src, nav);18262 try sema.ensureNavResolved(src, nav);
...@@ -18266,9 +18265,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18266,9 +18265,9 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1826618265
18267 const field_values = .{18266 const field_values = .{
18268 // error_set: type,18267 // error_set: type,
18269 ty.errorUnionSet(mod).toIntern(),18268 ty.errorUnionSet(zcu).toIntern(),
18270 // payload: type,18269 // payload: type,
18271 ty.errorUnionPayload(mod).toIntern(),18270 ty.errorUnionPayload(zcu).toIntern(),
18272 };18271 };
18273 return Air.internedToRef((try pt.intern(.{ .un = .{18272 return Air.internedToRef((try pt.intern(.{ .un = .{
18274 .ty = type_info_ty.toIntern(),18273 .ty = type_info_ty.toIntern(),
...@@ -18286,7 +18285,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18286,7 +18285,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18286 const nav = try sema.namespaceLookup(18285 const nav = try sema.namespaceLookup(
18287 block,18286 block,
18288 src,18287 src,
18289 type_info_ty.getNamespaceIndex(mod),18288 type_info_ty.getNamespaceIndex(zcu),
18290 try ip.getOrPutString(gpa, pt.tid, "EnumField", .no_embedded_nulls),18289 try ip.getOrPutString(gpa, pt.tid, "EnumField", .no_embedded_nulls),
18291 ) orelse @panic("std.builtin.Type is corrupt");18290 ) orelse @panic("std.builtin.Type is corrupt");
18292 try sema.ensureNavResolved(src, nav);18291 try sema.ensureNavResolved(src, nav);
...@@ -18298,7 +18297,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18298,7 +18297,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18298 const enum_type = ip.loadEnumType(ty.toIntern());18297 const enum_type = ip.loadEnumType(ty.toIntern());
18299 const value_val = if (enum_type.values.len > 0)18298 const value_val = if (enum_type.values.len > 0)
18300 try ip.getCoercedInts(18299 try ip.getCoercedInts(
18301 mod.gpa,18300 zcu.gpa,
18302 pt.tid,18301 pt.tid,
18303 ip.indexToKey(enum_type.values.get(ip)[tag_index]).int,18302 ip.indexToKey(enum_type.values.get(ip)[tag_index]).int,
18304 .comptime_int_type,18303 .comptime_int_type,
...@@ -18361,7 +18360,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18361,7 +18360,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18361 .is_const = true,18360 .is_const = true,
18362 },18361 },
18363 })).toIntern();18362 })).toIntern();
18364 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();18363 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
18365 break :v try pt.intern(.{ .slice = .{18364 break :v try pt.intern(.{ .slice = .{
18366 .ty = slice_ty,18365 .ty = slice_ty,
18367 .ptr = try pt.intern(.{ .ptr = .{18366 .ptr = try pt.intern(.{ .ptr = .{
...@@ -18382,7 +18381,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18382,7 +18381,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18382 const nav = try sema.namespaceLookup(18381 const nav = try sema.namespaceLookup(
18383 block,18382 block,
18384 src,18383 src,
18385 type_info_ty.getNamespaceIndex(mod),18384 type_info_ty.getNamespaceIndex(zcu),
18386 try ip.getOrPutString(gpa, pt.tid, "Enum", .no_embedded_nulls),18385 try ip.getOrPutString(gpa, pt.tid, "Enum", .no_embedded_nulls),
18387 ) orelse @panic("std.builtin.Type is corrupt");18386 ) orelse @panic("std.builtin.Type is corrupt");
18388 try sema.ensureNavResolved(src, nav);18387 try sema.ensureNavResolved(src, nav);
...@@ -18413,7 +18412,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18413,7 +18412,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18413 const nav = try sema.namespaceLookup(18412 const nav = try sema.namespaceLookup(
18414 block,18413 block,
18415 src,18414 src,
18416 type_info_ty.getNamespaceIndex(mod),18415 type_info_ty.getNamespaceIndex(zcu),
18417 try ip.getOrPutString(gpa, pt.tid, "Union", .no_embedded_nulls),18416 try ip.getOrPutString(gpa, pt.tid, "Union", .no_embedded_nulls),
18418 ) orelse @panic("std.builtin.Type is corrupt");18417 ) orelse @panic("std.builtin.Type is corrupt");
18419 try sema.ensureNavResolved(src, nav);18418 try sema.ensureNavResolved(src, nav);
...@@ -18424,7 +18423,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18424,7 +18423,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18424 const nav = try sema.namespaceLookup(18423 const nav = try sema.namespaceLookup(
18425 block,18424 block,
18426 src,18425 src,
18427 type_info_ty.getNamespaceIndex(mod),18426 type_info_ty.getNamespaceIndex(zcu),
18428 try ip.getOrPutString(gpa, pt.tid, "UnionField", .no_embedded_nulls),18427 try ip.getOrPutString(gpa, pt.tid, "UnionField", .no_embedded_nulls),
18429 ) orelse @panic("std.builtin.Type is corrupt");18428 ) orelse @panic("std.builtin.Type is corrupt");
18430 try sema.ensureNavResolved(src, nav);18429 try sema.ensureNavResolved(src, nav);
...@@ -18432,7 +18431,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18432,7 +18431,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18432 };18431 };
1843318432
18434 try ty.resolveLayout(pt); // Getting alignment requires type layout18433 try ty.resolveLayout(pt); // Getting alignment requires type layout
18435 const union_obj = mod.typeToUnion(ty).?;18434 const union_obj = zcu.typeToUnion(ty).?;
18436 const tag_type = union_obj.loadTagType(ip);18435 const tag_type = union_obj.loadTagType(ip);
18437 const layout = union_obj.flagsUnordered(ip).layout;18436 const layout = union_obj.flagsUnordered(ip).layout;
1843818437
...@@ -18467,7 +18466,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18467,7 +18466,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18467 };18466 };
1846818467
18469 const alignment = switch (layout) {18468 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),
18471 .@"packed" => .none,18470 .@"packed" => .none,
18472 };18471 };
1847318472
...@@ -18502,7 +18501,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18502,7 +18501,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18502 .is_const = true,18501 .is_const = true,
18503 },18502 },
18504 })).toIntern();18503 })).toIntern();
18505 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();18504 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
18506 break :v try pt.intern(.{ .slice = .{18505 break :v try pt.intern(.{ .slice = .{
18507 .ty = slice_ty,18506 .ty = slice_ty,
18508 .ptr = try pt.intern(.{ .ptr = .{18507 .ptr = try pt.intern(.{ .ptr = .{
...@@ -18517,18 +18516,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18517,18 +18516,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18517 } });18516 } });
18518 };18517 };
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
18522 const enum_tag_ty_val = try pt.intern(.{ .opt = .{18521 const enum_tag_ty_val = try pt.intern(.{ .opt = .{
18523 .ty = (try pt.optionalType(.type_type)).toIntern(),18522 .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,
18525 } });18524 } });
1852618525
18527 const container_layout_ty = t: {18526 const container_layout_ty = t: {
18528 const nav = try sema.namespaceLookup(18527 const nav = try sema.namespaceLookup(
18529 block,18528 block,
18530 src,18529 src,
18531 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),18530 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
18532 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),18531 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
18533 ) orelse @panic("std.builtin.Type is corrupt");18532 ) orelse @panic("std.builtin.Type is corrupt");
18534 try sema.ensureNavResolved(src, nav);18533 try sema.ensureNavResolved(src, nav);
...@@ -18560,7 +18559,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18560,7 +18559,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18560 const nav = try sema.namespaceLookup(18559 const nav = try sema.namespaceLookup(
18561 block,18560 block,
18562 src,18561 src,
18563 type_info_ty.getNamespaceIndex(mod),18562 type_info_ty.getNamespaceIndex(zcu),
18564 try ip.getOrPutString(gpa, pt.tid, "Struct", .no_embedded_nulls),18563 try ip.getOrPutString(gpa, pt.tid, "Struct", .no_embedded_nulls),
18565 ) orelse @panic("std.builtin.Type is corrupt");18564 ) orelse @panic("std.builtin.Type is corrupt");
18566 try sema.ensureNavResolved(src, nav);18565 try sema.ensureNavResolved(src, nav);
...@@ -18571,7 +18570,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18571,7 +18570,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18571 const nav = try sema.namespaceLookup(18570 const nav = try sema.namespaceLookup(
18572 block,18571 block,
18573 src,18572 src,
18574 type_info_ty.getNamespaceIndex(mod),18573 type_info_ty.getNamespaceIndex(zcu),
18575 try ip.getOrPutString(gpa, pt.tid, "StructField", .no_embedded_nulls),18574 try ip.getOrPutString(gpa, pt.tid, "StructField", .no_embedded_nulls),
18576 ) orelse @panic("std.builtin.Type is corrupt");18575 ) orelse @panic("std.builtin.Type is corrupt");
18577 try sema.ensureNavResolved(src, nav);18576 try sema.ensureNavResolved(src, nav);
...@@ -18633,7 +18632,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18633,7 +18632,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18633 // is_comptime: bool,18632 // is_comptime: bool,
18634 Value.makeBool(is_comptime).toIntern(),18633 Value.makeBool(is_comptime).toIntern(),
18635 // alignment: comptime_int,18634 // 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(),
18637 };18636 };
18638 struct_field_val.* = try pt.intern(.{ .aggregate = .{18637 struct_field_val.* = try pt.intern(.{ .aggregate = .{
18639 .ty = struct_field_ty.toIntern(),18638 .ty = struct_field_ty.toIntern(),
...@@ -18686,11 +18685,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18686,11 +18685,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18686 const default_val_ptr = try sema.optRefValue(opt_default_val);18685 const default_val_ptr = try sema.optRefValue(opt_default_val);
18687 const alignment = switch (struct_type.layout) {18686 const alignment = switch (struct_type.layout) {
18688 .@"packed" => .none,18687 .@"packed" => .none,
18689 else => try pt.structFieldAlignmentAdvanced(18688 else => try field_ty.structFieldAlignmentSema(
18690 struct_type.fieldAlign(ip, field_index),18689 struct_type.fieldAlign(ip, field_index),
18691 field_ty,
18692 struct_type.layout,18690 struct_type.layout,
18693 .sema,18691 pt,
18694 ),18692 ),
18695 };18693 };
1869618694
...@@ -18729,7 +18727,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18729,7 +18727,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18729 .is_const = true,18727 .is_const = true,
18730 },18728 },
18731 })).toIntern();18729 })).toIntern();
18732 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(mod).toIntern();18730 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
18733 break :v try pt.intern(.{ .slice = .{18731 break :v try pt.intern(.{ .slice = .{
18734 .ty = slice_ty,18732 .ty = slice_ty,
18735 .ptr = try pt.intern(.{ .ptr = .{18733 .ptr = try pt.intern(.{ .ptr = .{
...@@ -18744,12 +18742,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18744,12 +18742,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18744 } });18742 } });
18745 };18743 };
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
18749 const backing_integer_val = try pt.intern(.{ .opt = .{18747 const backing_integer_val = try pt.intern(.{ .opt = .{
18750 .ty = (try pt.optionalType(.type_type)).toIntern(),18748 .ty = (try pt.optionalType(.type_type)).toIntern(),
18751 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {18749 .val = if (zcu.typeToPackedStruct(ty)) |packed_struct| val: {
18752 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(mod));18750 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(zcu));
18753 break :val packed_struct.backingIntTypeUnordered(ip);18751 break :val packed_struct.backingIntTypeUnordered(ip);
18754 } else .none,18752 } else .none,
18755 } });18753 } });
...@@ -18758,14 +18756,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18758,14 +18756,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18758 const nav = try sema.namespaceLookup(18756 const nav = try sema.namespaceLookup(
18759 block,18757 block,
18760 src,18758 src,
18761 (try pt.getBuiltinType("Type")).getNamespaceIndex(mod),18759 (try pt.getBuiltinType("Type")).getNamespaceIndex(zcu),
18762 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),18760 try ip.getOrPutString(gpa, pt.tid, "ContainerLayout", .no_embedded_nulls),
18763 ) orelse @panic("std.builtin.Type is corrupt");18761 ) orelse @panic("std.builtin.Type is corrupt");
18764 try sema.ensureNavResolved(src, nav);18762 try sema.ensureNavResolved(src, nav);
18765 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);18763 break :t Type.fromInterned(ip.getNav(nav).status.resolved.val);
18766 };18764 };
1876718765
18768 const layout = ty.containerLayout(mod);18766 const layout = ty.containerLayout(zcu);
1876918767
18770 const field_values = [_]InternPool.Index{18768 const field_values = [_]InternPool.Index{
18771 // layout: ContainerLayout,18769 // layout: ContainerLayout,
...@@ -18777,7 +18775,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18777,7 +18775,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18777 // decls: []const Declaration,18775 // decls: []const Declaration,
18778 decls_val,18776 decls_val,
18779 // is_tuple: bool,18777 // is_tuple: bool,
18780 Value.makeBool(ty.isTuple(mod)).toIntern(),18778 Value.makeBool(ty.isTuple(zcu)).toIntern(),
18781 };18779 };
18782 return Air.internedToRef((try pt.intern(.{ .un = .{18780 return Air.internedToRef((try pt.intern(.{ .un = .{
18783 .ty = type_info_ty.toIntern(),18781 .ty = type_info_ty.toIntern(),
...@@ -18793,7 +18791,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18793,7 +18791,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18793 const nav = try sema.namespaceLookup(18791 const nav = try sema.namespaceLookup(
18794 block,18792 block,
18795 src,18793 src,
18796 type_info_ty.getNamespaceIndex(mod),18794 type_info_ty.getNamespaceIndex(zcu),
18797 try ip.getOrPutString(gpa, pt.tid, "Opaque", .no_embedded_nulls),18795 try ip.getOrPutString(gpa, pt.tid, "Opaque", .no_embedded_nulls),
18798 ) orelse @panic("std.builtin.Type is corrupt");18796 ) orelse @panic("std.builtin.Type is corrupt");
18799 try sema.ensureNavResolved(src, nav);18797 try sema.ensureNavResolved(src, nav);
...@@ -18801,7 +18799,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18801,7 +18799,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18801 };18799 };
1880218800
18803 try ty.resolveFields(pt);18801 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
18806 const field_values = .{18804 const field_values = .{
18807 // decls: []const Declaration,18805 // decls: []const Declaration,
...@@ -19000,11 +18998,11 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -19000,11 +18998,11 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
1900018998
19001fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Type {18999fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Type {
19002 const pt = sema.pt;19000 const pt = sema.pt;
19003 const mod = pt.zcu;19001 const zcu = pt.zcu;
19004 switch (operand.zigTypeTag(mod)) {19002 switch (operand.zigTypeTag(zcu)) {
19005 .ComptimeInt => return Type.comptime_int,19003 .ComptimeInt => return Type.comptime_int,
19006 .Int => {19004 .Int => {
19007 const bits = operand.bitSize(pt);19005 const bits = operand.bitSize(zcu);
19008 const count = if (bits == 0)19006 const count = if (bits == 0)
19009 019007 0
19010 else blk: {19008 else blk: {
...@@ -19018,10 +19016,10 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi...@@ -19018,10 +19016,10 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
19018 return pt.intType(.unsigned, count);19016 return pt.intType(.unsigned, count);
19019 },19017 },
19020 .Vector => {19018 .Vector => {
19021 const elem_ty = operand.elemType2(mod);19019 const elem_ty = operand.elemType2(zcu);
19022 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);19020 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);
19023 return pt.vectorType(.{19021 return pt.vectorType(.{
19024 .len = operand.vectorLen(mod),19022 .len = operand.vectorLen(zcu),
19025 .child = log2_elem_ty.toIntern(),19023 .child = log2_elem_ty.toIntern(),
19026 });19024 });
19027 },19025 },
...@@ -19084,7 +19082,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19084,7 +19082,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19084 defer tracy.end();19082 defer tracy.end();
1908519083
19086 const pt = sema.pt;19084 const pt = sema.pt;
19087 const mod = pt.zcu;19085 const zcu = pt.zcu;
19088 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19086 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19089 const src = block.nodeOffset(inst_data.src_node);19087 const src = block.nodeOffset(inst_data.src_node);
19090 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });19088 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...@@ -19092,7 +19090,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1909219090
19093 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);19091 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
19094 if (try sema.resolveValue(operand)) |val| {19092 if (try sema.resolveValue(operand)) |val| {
19095 return if (val.isUndef(mod))19093 return if (val.isUndef(zcu))
19096 pt.undefRef(Type.bool)19094 pt.undefRef(Type.bool)
19097 else if (val.toBool()) .bool_false else .bool_true;19095 else if (val.toBool()) .bool_false else .bool_true;
19098 }19096 }
...@@ -19110,7 +19108,7 @@ fn zirBoolBr(...@@ -19110,7 +19108,7 @@ fn zirBoolBr(
19110 defer tracy.end();19108 defer tracy.end();
1911119109
19112 const pt = sema.pt;19110 const pt = sema.pt;
19113 const mod = pt.zcu;19111 const zcu = pt.zcu;
19114 const gpa = sema.gpa;19112 const gpa = sema.gpa;
1911519113
19116 const datas = sema.code.instructions.items(.data);19114 const datas = sema.code.instructions.items(.data);
...@@ -19134,7 +19132,7 @@ fn zirBoolBr(...@@ -19134,7 +19132,7 @@ fn zirBoolBr(
19134 // is simply the rhs expression. Here we rely on there only being 119132 // is simply the rhs expression. Here we rely on there only being 1
19135 // break instruction (`break_inline`).19133 // break instruction (`break_inline`).
19136 const rhs_result = try sema.resolveInlineBody(parent_block, body, inst);19134 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)) {
19138 return rhs_result;19136 return rhs_result;
19139 }19137 }
19140 return sema.coerce(parent_block, Type.bool, rhs_result, rhs_src);19138 return sema.coerce(parent_block, Type.bool, rhs_result, rhs_src);
...@@ -19168,7 +19166,7 @@ fn zirBoolBr(...@@ -19168,7 +19166,7 @@ fn zirBoolBr(
19168 _ = try lhs_block.addBr(block_inst, lhs_result);19166 _ = try lhs_block.addBr(block_inst, lhs_result);
1916919167
19170 const rhs_result = try sema.resolveInlineBody(rhs_block, body, inst);19168 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);
19172 const coerced_rhs_result = if (!rhs_noret) rhs: {19170 const coerced_rhs_result = if (!rhs_noret) rhs: {
19173 const coerced_result = try sema.coerce(rhs_block, Type.bool, rhs_result, rhs_src);19171 const coerced_result = try sema.coerce(rhs_block, Type.bool, rhs_result, rhs_src);
19174 _ = try rhs_block.addBr(block_inst, coerced_result);19172 _ = try rhs_block.addBr(block_inst, coerced_result);
...@@ -19227,10 +19225,10 @@ fn finishCondBr(...@@ -19227,10 +19225,10 @@ fn finishCondBr(
1922719225
19228fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {19226fn checkNullableType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
19229 const pt = sema.pt;19227 const pt = sema.pt;
19230 const mod = pt.zcu;19228 const zcu = pt.zcu;
19231 switch (ty.zigTypeTag(mod)) {19229 switch (ty.zigTypeTag(zcu)) {
19232 .Optional, .Null, .Undefined => return,19230 .Optional, .Null, .Undefined => return,
19233 .Pointer => if (ty.isPtrLikeOptional(mod)) return,19231 .Pointer => if (ty.isPtrLikeOptional(zcu)) return,
19234 else => {},19232 else => {},
19235 }19233 }
19236 return sema.failWithExpectedOptionalType(block, src, ty);19234 return sema.failWithExpectedOptionalType(block, src, ty);
...@@ -19260,11 +19258,11 @@ fn zirIsNonNullPtr(...@@ -19260,11 +19258,11 @@ fn zirIsNonNullPtr(
19260 defer tracy.end();19258 defer tracy.end();
1926119259
19262 const pt = sema.pt;19260 const pt = sema.pt;
19263 const mod = pt.zcu;19261 const zcu = pt.zcu;
19264 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19262 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19265 const src = block.nodeOffset(inst_data.src_node);19263 const src = block.nodeOffset(inst_data.src_node);
19266 const ptr = try sema.resolveInst(inst_data.operand);19264 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));
19268 if ((try sema.resolveValue(ptr)) == null) {19266 if ((try sema.resolveValue(ptr)) == null) {
19269 return block.addUnOp(.is_non_null_ptr, ptr);19267 return block.addUnOp(.is_non_null_ptr, ptr);
19270 }19268 }
...@@ -19274,8 +19272,8 @@ fn zirIsNonNullPtr(...@@ -19274,8 +19272,8 @@ fn zirIsNonNullPtr(
1927419272
19275fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {19273fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
19276 const pt = sema.pt;19274 const pt = sema.pt;
19277 const mod = pt.zcu;19275 const zcu = pt.zcu;
19278 switch (ty.zigTypeTag(mod)) {19276 switch (ty.zigTypeTag(zcu)) {
19279 .ErrorSet, .ErrorUnion, .Undefined => return,19277 .ErrorSet, .ErrorUnion, .Undefined => return,
19280 else => return sema.fail(block, src, "expected error union type, found '{}'", .{19278 else => return sema.fail(block, src, "expected error union type, found '{}'", .{
19281 ty.fmt(pt),19279 ty.fmt(pt),
...@@ -19299,11 +19297,11 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -19299,11 +19297,11 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
19299 defer tracy.end();19297 defer tracy.end();
1930019298
19301 const pt = sema.pt;19299 const pt = sema.pt;
19302 const mod = pt.zcu;19300 const zcu = pt.zcu;
19303 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19301 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19304 const src = block.nodeOffset(inst_data.src_node);19302 const src = block.nodeOffset(inst_data.src_node);
19305 const ptr = try sema.resolveInst(inst_data.operand);19303 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));
19307 const loaded = try sema.analyzeLoad(block, src, ptr, src);19305 const loaded = try sema.analyzeLoad(block, src, ptr, src);
19308 return sema.analyzeIsNonErr(block, src, loaded);19306 return sema.analyzeIsNonErr(block, src, loaded);
19309}19307}
...@@ -19327,7 +19325,7 @@ fn zirCondbr(...@@ -19327,7 +19325,7 @@ fn zirCondbr(
19327 defer tracy.end();19325 defer tracy.end();
1932819326
19329 const pt = sema.pt;19327 const pt = sema.pt;
19330 const mod = pt.zcu;19328 const zcu = pt.zcu;
19331 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;19329 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19332 const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node });19330 const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node });
19333 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);19331 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
...@@ -19368,8 +19366,8 @@ fn zirCondbr(...@@ -19368,8 +19366,8 @@ fn zirCondbr(
19368 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;19366 const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node;
19369 const err_operand = try sema.resolveInst(err_inst_data.operand);19367 const err_operand = try sema.resolveInst(err_inst_data.operand);
19370 const operand_ty = sema.typeOf(err_operand);19368 const operand_ty = sema.typeOf(err_operand);
19371 assert(operand_ty.zigTypeTag(mod) == .ErrorUnion);19369 assert(operand_ty.zigTypeTag(zcu) == .ErrorUnion);
19372 const result_ty = operand_ty.errorUnionSet(mod);19370 const result_ty = operand_ty.errorUnionSet(zcu);
19373 break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand);19371 break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand);
19374 };19372 };
1937519373
...@@ -19403,8 +19401,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -19403,8 +19401,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
19403 const err_union = try sema.resolveInst(extra.data.operand);19401 const err_union = try sema.resolveInst(extra.data.operand);
19404 const err_union_ty = sema.typeOf(err_union);19402 const err_union_ty = sema.typeOf(err_union);
19405 const pt = sema.pt;19403 const pt = sema.pt;
19406 const mod = pt.zcu;19404 const zcu = pt.zcu;
19407 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {19405 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
19408 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{19406 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
19409 err_union_ty.fmt(pt),19407 err_union_ty.fmt(pt),
19410 });19408 });
...@@ -19452,8 +19450,8 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -19452,8 +19450,8 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
19452 const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src);19450 const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src);
19453 const err_union_ty = sema.typeOf(err_union);19451 const err_union_ty = sema.typeOf(err_union);
19454 const pt = sema.pt;19452 const pt = sema.pt;
19455 const mod = pt.zcu;19453 const zcu = pt.zcu;
19456 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {19454 if (err_union_ty.zigTypeTag(zcu) != .ErrorUnion) {
19457 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{19455 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
19458 err_union_ty.fmt(pt),19456 err_union_ty.fmt(pt),
19459 });19457 });
...@@ -19477,9 +19475,9 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -19477,9 +19475,9 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
19477 try sema.analyzeBodyInner(&sub_block, body);19475 try sema.analyzeBodyInner(&sub_block, body);
1947819476
19479 const operand_ty = sema.typeOf(operand);19477 const operand_ty = sema.typeOf(operand);
19480 const ptr_info = operand_ty.ptrInfo(mod);19478 const ptr_info = operand_ty.ptrInfo(zcu);
19481 const res_ty = try pt.ptrTypeSema(.{19479 const res_ty = try pt.ptrTypeSema(.{
19482 .child = err_union_ty.errorUnionPayload(mod).toIntern(),19480 .child = err_union_ty.errorUnionPayload(zcu).toIntern(),
19483 .flags = .{19481 .flags = .{
19484 .is_const = ptr_info.flags.is_const,19482 .is_const = ptr_info.flags.is_const,
19485 .is_volatile = ptr_info.flags.is_volatile,19483 .is_volatile = ptr_info.flags.is_volatile,
...@@ -19594,10 +19592,10 @@ fn zirRetErrValue(...@@ -19594,10 +19592,10 @@ fn zirRetErrValue(
19594 inst: Zir.Inst.Index,19592 inst: Zir.Inst.Index,
19595) CompileError!void {19593) CompileError!void {
19596 const pt = sema.pt;19594 const pt = sema.pt;
19597 const mod = pt.zcu;19595 const zcu = pt.zcu;
19598 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;19596 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
19599 const src = block.tokenOffset(inst_data.src_tok);19597 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(
19601 sema.gpa,19599 sema.gpa,
19602 pt.tid,19600 pt.tid,
19603 inst_data.get(sema.code),19601 inst_data.get(sema.code),
...@@ -19622,7 +19620,7 @@ fn zirRetImplicit(...@@ -19622,7 +19620,7 @@ fn zirRetImplicit(
19622 defer tracy.end();19620 defer tracy.end();
1962319621
19624 const pt = sema.pt;19622 const pt = sema.pt;
19625 const mod = pt.zcu;19623 const zcu = pt.zcu;
19626 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;19624 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok;
19627 const r_brace_src = block.tokenOffset(inst_data.src_tok);19625 const r_brace_src = block.tokenOffset(inst_data.src_tok);
19628 if (block.inlining == null and sema.func_is_naked) {19626 if (block.inlining == null and sema.func_is_naked) {
...@@ -19638,7 +19636,7 @@ fn zirRetImplicit(...@@ -19638,7 +19636,7 @@ fn zirRetImplicit(
1963819636
19639 const operand = try sema.resolveInst(inst_data.operand);19637 const operand = try sema.resolveInst(inst_data.operand);
19640 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 });19638 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);
19642 if (base_tag == .NoReturn) {19640 if (base_tag == .NoReturn) {
19643 const msg = msg: {19641 const msg = msg: {
19644 const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{19642 const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{
...@@ -19755,13 +19753,13 @@ fn retWithErrTracing(...@@ -19755,13 +19753,13 @@ fn retWithErrTracing(
1975519753
19756fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool {19754fn wantErrorReturnTracing(sema: *Sema, fn_ret_ty: Type) bool {
19757 const pt = sema.pt;19755 const pt = sema.pt;
19758 const mod = pt.zcu;19756 const zcu = pt.zcu;
19759 return fn_ret_ty.isError(mod) and mod.comp.config.any_error_tracing;19757 return fn_ret_ty.isError(zcu) and zcu.comp.config.any_error_tracing;
19760}19758}
1976119759
19762fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {19760fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
19763 const pt = sema.pt;19761 const pt = sema.pt;
19764 const mod = pt.zcu;19762 const zcu = pt.zcu;
19765 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;19763 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
1976619764
19767 if (!block.ownerModule().error_tracing) return;19765 if (!block.ownerModule().error_tracing) return;
...@@ -19772,7 +19770,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -19772,7 +19770,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
19772 const save_index = inst_data.operand == .none or b: {19770 const save_index = inst_data.operand == .none or b: {
19773 const operand = try sema.resolveInst(inst_data.operand);19771 const operand = try sema.resolveInst(inst_data.operand);
19774 const operand_ty = sema.typeOf(operand);19772 const operand_ty = sema.typeOf(operand);
19775 break :b operand_ty.isError(mod);19773 break :b operand_ty.isError(zcu);
19776 };19774 };
1977719775
19778 if (save_index)19776 if (save_index)
...@@ -19792,7 +19790,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_...@@ -19792,7 +19790,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
19792 defer tracy.end();19790 defer tracy.end();
1979319791
19794 const pt = sema.pt;19792 const pt = sema.pt;
19795 const mod = pt.zcu;19793 const zcu = pt.zcu;
1979619794
19797 const saved_index = if (target_block.toIndexAllowNone()) |zir_block| b: {19795 const saved_index = if (target_block.toIndexAllowNone()) |zir_block| b: {
19798 var block = start_block;19796 var block = start_block;
...@@ -19830,13 +19828,13 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_...@@ -19830,13 +19828,13 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
19830 if (is_non_error) return;19828 if (is_non_error) return;
1983119829
19832 const saved_index_val = try sema.resolveDefinedValue(start_block, src, saved_index);19830 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);
19834 assert(saved_index_int <= sema.comptime_err_ret_trace.items.len);19832 assert(saved_index_int <= sema.comptime_err_ret_trace.items.len);
19835 sema.comptime_err_ret_trace.items.len = @intCast(saved_index_int);19833 sema.comptime_err_ret_trace.items.len = @intCast(saved_index_int);
19836 return;19834 return;
19837 }19835 }
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;
19840 if (!start_block.ownerModule().error_tracing) return;19838 if (!start_block.ownerModule().error_tracing) return;
1984119839
19842 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere19840 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_...@@ -19846,10 +19844,10 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1984619844
19847fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {19845fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
19848 const pt = sema.pt;19846 const pt = sema.pt;
19849 const mod = pt.zcu;19847 const zcu = pt.zcu;
19850 const ip = &mod.intern_pool;19848 const ip = &zcu.intern_pool;
19851 assert(sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion);19849 assert(sema.fn_ret_ty.zigTypeTag(zcu) == .ErrorUnion);
19852 const err_set_ty = sema.fn_ret_ty.errorUnionSet(mod).toIntern();19850 const err_set_ty = sema.fn_ret_ty.errorUnionSet(zcu).toIntern();
19853 switch (err_set_ty) {19851 switch (err_set_ty) {
19854 .adhoc_inferred_error_set_type => {19852 .adhoc_inferred_error_set_type => {
19855 const ies = sema.fn_ret_ty_ies.?;19853 const ies = sema.fn_ret_ty_ies.?;
...@@ -19867,11 +19865,11 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {...@@ -19867,11 +19865,11 @@ fn addToInferredErrorSet(sema: *Sema, uncasted_operand: Air.Inst.Ref) !void {
19867fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void {19865fn addToInferredErrorSetPtr(sema: *Sema, ies: *InferredErrorSet, op_ty: Type) !void {
19868 const arena = sema.arena;19866 const arena = sema.arena;
19869 const pt = sema.pt;19867 const pt = sema.pt;
19870 const mod = pt.zcu;19868 const zcu = pt.zcu;
19871 const ip = &mod.intern_pool;19869 const ip = &zcu.intern_pool;
19872 switch (op_ty.zigTypeTag(mod)) {19870 switch (op_ty.zigTypeTag(zcu)) {
19873 .ErrorSet => try ies.addErrorSet(op_ty, ip, arena),19871 .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),
19875 else => {},19873 else => {},
19876 }19874 }
19877}19875}
...@@ -19887,8 +19885,8 @@ fn analyzeRet(...@@ -19887,8 +19885,8 @@ fn analyzeRet(
19887 // add the error tag to the inferred error set of the in-scope function, so19885 // add the error tag to the inferred error set of the in-scope function, so
19888 // that the coercion below works correctly.19886 // that the coercion below works correctly.
19889 const pt = sema.pt;19887 const pt = sema.pt;
19890 const mod = pt.zcu;19888 const zcu = pt.zcu;
19891 if (sema.fn_ret_ty_ies != null and sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion) {19889 if (sema.fn_ret_ty_ies != null and sema.fn_ret_ty.zigTypeTag(zcu) == .ErrorUnion) {
19892 try sema.addToInferredErrorSet(uncasted_operand);19890 try sema.addToInferredErrorSet(uncasted_operand);
19893 }19891 }
19894 const operand = sema.coerceExtra(block, sema.fn_ret_ty, uncasted_operand, operand_src, .{ .is_ret = true }) catch |err| switch (err) {19892 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(...@@ -19903,7 +19901,7 @@ fn analyzeRet(
19903 });19901 });
19904 inlining.comptime_result = operand;19902 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) {
19907 try sema.comptime_err_ret_trace.append(src);19905 try sema.comptime_err_ret_trace.append(src);
19908 }19906 }
19909 return error.ComptimeReturn;19907 return error.ComptimeReturn;
...@@ -19955,7 +19953,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19955,7 +19953,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19955 defer tracy.end();19953 defer tracy.end();
1995619954
19957 const pt = sema.pt;19955 const pt = sema.pt;
19958 const mod = pt.zcu;19956 const zcu = pt.zcu;
19959 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;19957 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
19960 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);19958 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
19961 const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node });19959 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...@@ -19968,7 +19966,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19968 const elem_ty = blk: {19966 const elem_ty = blk: {
19969 const air_inst = try sema.resolveInst(extra.data.elem_type);19967 const air_inst = try sema.resolveInst(extra.data.elem_type);
19970 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {19968 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)) {
19972 try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});19970 try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
19973 }19971 }
19974 return err;19972 return err;
...@@ -19977,10 +19975,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19977,10 +19975,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19977 break :blk ty;19975 break :blk ty;
19978 };19976 };
1997919977
19980 if (elem_ty.zigTypeTag(mod) == .NoReturn)19978 if (elem_ty.zigTypeTag(zcu) == .NoReturn)
19981 return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});19979 return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});
1998219980
19983 const target = mod.getTarget();19981 const target = zcu.getTarget();
1998419982
19985 var extra_i = extra.end;19983 var extra_i = extra.end;
1998619984
...@@ -20003,14 +20001,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -20003,14 +20001,14 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20003 });20001 });
20004 // Check if this happens to be the lazy alignment of our element type, in20002 // Check if this happens to be the lazy alignment of our element type, in
20005 // which case we can make this 0 without resolving it.20003 // 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())) {
20007 .int => |int| switch (int.storage) {20005 .int => |int| switch (int.storage) {
20008 .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.toIntern()) break :blk .none,20006 .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.toIntern()) break :blk .none,
20009 else => {},20007 else => {},
20010 },20008 },
20011 else => {},20009 else => {},
20012 }20010 }
20013 const align_bytes = (try val.getUnsignedIntAdvanced(pt, .sema)).?;20011 const align_bytes = (try val.getUnsignedIntSema(pt)).?;
20014 break :blk try sema.validateAlignAllowZero(block, align_src, align_bytes);20012 break :blk try sema.validateAlignAllowZero(block, align_src, align_bytes);
20015 } else .none;20013 } else .none;
2001620014
...@@ -20018,7 +20016,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -20018,7 +20016,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20018 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);20016 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
20019 extra_i += 1;20017 extra_i += 1;
20020 break :blk try sema.resolveAddressSpace(block, addrspace_src, ref, .pointer);20018 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
20023 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {20021 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {
20024 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);20022 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...@@ -20044,7 +20042,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20044 elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size,20042 elem_ty.fmt(pt), bit_offset, bit_offset - host_size * 8, host_size,
20045 });20043 });
20046 }20044 }
20047 const elem_bit_size = try elem_ty.bitSizeAdvanced(pt, .sema);20045 const elem_bit_size = try elem_ty.bitSizeSema(pt);
20048 if (elem_bit_size > host_size * 8 - bit_offset) {20046 if (elem_bit_size > host_size * 8 - bit_offset) {
20049 return sema.fail(block, bitoffset_src, "packed type '{}' at bit offset {} ends {} bits after the end of a {} byte host integer", .{20047 return sema.fail(block, bitoffset_src, "packed type '{}' at bit offset {} ends {} bits after the end of a {} byte host integer", .{
20050 elem_ty.fmt(pt), bit_offset, elem_bit_size - (host_size * 8 - bit_offset), host_size,20048 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...@@ -20052,11 +20050,11 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20052 }20050 }
20053 }20051 }
2005420052
20055 if (elem_ty.zigTypeTag(mod) == .Fn) {20053 if (elem_ty.zigTypeTag(zcu) == .Fn) {
20056 if (inst_data.size != .One) {20054 if (inst_data.size != .One) {
20057 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});20055 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
20058 }20056 }
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) {
20060 return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{});20058 return sema.fail(block, elem_ty_src, "unknown-length pointer to opaque not allowed", .{});
20061 } else if (inst_data.size == .C) {20059 } else if (inst_data.size == .C) {
20062 if (!try sema.validateExternType(elem_ty, .other)) {20060 if (!try sema.validateExternType(elem_ty, .other)) {
...@@ -20071,7 +20069,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -20071,7 +20069,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20071 };20069 };
20072 return sema.failWithOwnedErrorMsg(block, msg);20070 return sema.failWithOwnedErrorMsg(block, msg);
20073 }20071 }
20074 if (elem_ty.zigTypeTag(mod) == .Opaque) {20072 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
20075 return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{});20073 return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{});
20076 }20074 }
20077 }20075 }
...@@ -20113,9 +20111,9 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -20113,9 +20111,9 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
20113 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });20111 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
20114 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);20112 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
20115 const pt = sema.pt;20113 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)) {
20119 .Struct => return sema.structInitEmpty(block, obj_ty, src, src),20117 .Struct => return sema.structInitEmpty(block, obj_ty, src, src),
20120 .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty),20118 .Array, .Vector => return sema.arrayInitEmpty(block, src, obj_ty),
20121 .Void => return Air.internedToRef(Value.void.toIntern()),20119 .Void => return Air.internedToRef(Value.void.toIntern()),
...@@ -20129,7 +20127,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is...@@ -20129,7 +20127,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
20129 defer tracy.end();20127 defer tracy.end();
2013020128
20131 const pt = sema.pt;20129 const pt = sema.pt;
20132 const mod = pt.zcu;20130 const zcu = pt.zcu;
20133 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;20131 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
20134 const src = block.nodeOffset(inst_data.src_node);20132 const src = block.nodeOffset(inst_data.src_node);
20135 const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) {20133 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...@@ -20138,21 +20136,21 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
20138 else => |e| return e,20136 else => |e| return e,
20139 };20137 };
20140 const init_ty = if (is_byref) ty: {20138 const init_ty = if (is_byref) ty: {
20141 const ptr_ty = ty_operand.optEuBaseType(mod);20139 const ptr_ty = ty_operand.optEuBaseType(zcu);
20142 assert(ptr_ty.zigTypeTag(mod) == .Pointer); // validated by a previous instruction20140 assert(ptr_ty.zigTypeTag(zcu) == .Pointer); // validated by a previous instruction
20143 if (!ptr_ty.isSlice(mod)) {20141 if (!ptr_ty.isSlice(zcu)) {
20144 break :ty ptr_ty.childType(mod);20142 break :ty ptr_ty.childType(zcu);
20145 }20143 }
20146 // To make `&.{}` a `[:s]T`, the init should be a `[0:s]T`.20144 // To make `&.{}` a `[:s]T`, the init should be a `[0:s]T`.
20147 break :ty try pt.arrayType(.{20145 break :ty try pt.arrayType(.{
20148 .len = 0,20146 .len = 0,
20149 .sentinel = if (ptr_ty.sentinel(mod)) |s| s.toIntern() else .none,20147 .sentinel = if (ptr_ty.sentinel(zcu)) |s| s.toIntern() else .none,
20150 .child = ptr_ty.childType(mod).toIntern(),20148 .child = ptr_ty.childType(zcu).toIntern(),
20151 });20149 });
20152 } else ty_operand;20150 } 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)) {
20156 .Struct => try sema.structInitEmpty(block, obj_ty, src, src),20154 .Struct => try sema.structInitEmpty(block, obj_ty, src, src),
20157 .Array, .Vector => try sema.arrayInitEmpty(block, src, obj_ty),20155 .Array, .Vector => try sema.arrayInitEmpty(block, src, obj_ty),
20158 .Union => return sema.fail(block, src, "union initializer must initialize one field", .{}),20156 .Union => return sema.fail(block, src, "union initializer must initialize one field", .{}),
...@@ -20176,13 +20174,13 @@ fn structInitEmpty(...@@ -20176,13 +20174,13 @@ fn structInitEmpty(
20176 init_src: LazySrcLoc,20174 init_src: LazySrcLoc,
20177) CompileError!Air.Inst.Ref {20175) CompileError!Air.Inst.Ref {
20178 const pt = sema.pt;20176 const pt = sema.pt;
20179 const mod = pt.zcu;20177 const zcu = pt.zcu;
20180 const gpa = sema.gpa;20178 const gpa = sema.gpa;
20181 // This logic must be synchronized with that in `zirStructInit`.20179 // This logic must be synchronized with that in `zirStructInit`.
20182 try struct_ty.resolveFields(pt);20180 try struct_ty.resolveFields(pt);
2018320181
20184 // The init values to use for the struct instance.20182 // 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));
20186 defer gpa.free(field_inits);20184 defer gpa.free(field_inits);
20187 @memset(field_inits, .none);20185 @memset(field_inits, .none);
2018820186
...@@ -20191,10 +20189,10 @@ fn structInitEmpty(...@@ -20191,10 +20189,10 @@ fn structInitEmpty(
2019120189
20192fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) CompileError!Air.Inst.Ref {20190fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) CompileError!Air.Inst.Ref {
20193 const pt = sema.pt;20191 const pt = sema.pt;
20194 const mod = pt.zcu;20192 const zcu = pt.zcu;
20195 const arr_len = obj_ty.arrayLen(mod);20193 const arr_len = obj_ty.arrayLen(zcu);
20196 if (arr_len != 0) {20194 if (arr_len != 0) {
20197 if (obj_ty.zigTypeTag(mod) == .Array) {20195 if (obj_ty.zigTypeTag(zcu) == .Array) {
20198 return sema.fail(block, src, "expected {d} array elements; found 0", .{arr_len});20196 return sema.fail(block, src, "expected {d} array elements; found 0", .{arr_len});
20199 } else {20197 } else {
20200 return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len});20198 return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len});
...@@ -20235,14 +20233,14 @@ fn unionInit(...@@ -20235,14 +20233,14 @@ fn unionInit(
20235 field_src: LazySrcLoc,20233 field_src: LazySrcLoc,
20236) CompileError!Air.Inst.Ref {20234) CompileError!Air.Inst.Ref {
20237 const pt = sema.pt;20235 const pt = sema.pt;
20238 const mod = pt.zcu;20236 const zcu = pt.zcu;
20239 const ip = &mod.intern_pool;20237 const ip = &zcu.intern_pool;
20240 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);20238 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]);
20242 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);20240 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
2024320241
20244 if (try sema.resolveValue(init)) |init_val| {20242 if (try sema.resolveValue(init)) |init_val| {
20245 const tag_ty = union_ty.unionTagTypeHypothetical(mod);20243 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
20246 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);20244 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
20247 return Air.internedToRef((try pt.intern(.{ .un = .{20245 return Air.internedToRef((try pt.intern(.{ .un = .{
20248 .ty = union_ty.toIntern(),20246 .ty = union_ty.toIntern(),
...@@ -20269,8 +20267,8 @@ fn zirStructInit(...@@ -20269,8 +20267,8 @@ fn zirStructInit(
20269 const src = block.nodeOffset(inst_data.src_node);20267 const src = block.nodeOffset(inst_data.src_node);
2027020268
20271 const pt = sema.pt;20269 const pt = sema.pt;
20272 const mod = pt.zcu;20270 const zcu = pt.zcu;
20273 const ip = &mod.intern_pool;20271 const ip = &zcu.intern_pool;
20274 const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data;20272 const first_item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end).data;
20275 const first_field_type_data = zir_datas[@intFromEnum(first_item.field_type)].pl_node;20273 const first_field_type_data = zir_datas[@intFromEnum(first_item.field_type)].pl_node;
20276 const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;20274 const first_field_type_extra = sema.code.extraData(Zir.Inst.FieldType, first_field_type_data.payload_index).data;
...@@ -20281,26 +20279,26 @@ fn zirStructInit(...@@ -20281,26 +20279,26 @@ fn zirStructInit(
20281 },20279 },
20282 else => |e| return e,20280 else => |e| return e,
20283 };20281 };
20284 const resolved_ty = result_ty.optEuBaseType(mod);20282 const resolved_ty = result_ty.optEuBaseType(zcu);
20285 try resolved_ty.resolveLayout(pt);20283 try resolved_ty.resolveLayout(pt);
2028620284
20287 if (resolved_ty.zigTypeTag(mod) == .Struct) {20285 if (resolved_ty.zigTypeTag(zcu) == .Struct) {
20288 // This logic must be synchronized with that in `zirStructInitEmpty`.20286 // This logic must be synchronized with that in `zirStructInitEmpty`.
2028920287
20290 // Maps field index to field_type index of where it was already initialized.20288 // Maps field index to field_type index of where it was already initialized.
20291 // For making sure all fields are accounted for and no fields are duplicated.20289 // 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));
20293 defer gpa.free(found_fields);20291 defer gpa.free(found_fields);
2029420292
20295 // The init values to use for the struct instance.20293 // 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));
20297 defer gpa.free(field_inits);20295 defer gpa.free(field_inits);
20298 @memset(field_inits, .none);20296 @memset(field_inits, .none);
2029920297
20300 var field_i: u32 = 0;20298 var field_i: u32 = 0;
20301 var extra_index = extra.end;20299 var extra_index = extra.end;
2030220300
20303 const is_packed = resolved_ty.containerLayout(mod) == .@"packed";20301 const is_packed = resolved_ty.containerLayout(zcu) == .@"packed";
20304 while (field_i < extra.data.fields_len) : (field_i += 1) {20302 while (field_i < extra.data.fields_len) : (field_i += 1) {
20305 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index);20303 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra_index);
20306 extra_index = item.end;20304 extra_index = item.end;
...@@ -20314,14 +20312,14 @@ fn zirStructInit(...@@ -20314,14 +20312,14 @@ fn zirStructInit(
20314 sema.code.nullTerminatedString(field_type_extra.name_start),20312 sema.code.nullTerminatedString(field_type_extra.name_start),
20315 .no_embedded_nulls,20313 .no_embedded_nulls,
20316 );20314 );
20317 const field_index = if (resolved_ty.isTuple(mod))20315 const field_index = if (resolved_ty.isTuple(zcu))
20318 try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src)20316 try sema.tupleFieldIndex(block, resolved_ty, field_name, field_src)
20319 else20317 else
20320 try sema.structFieldIndex(block, resolved_ty, field_name, field_src);20318 try sema.structFieldIndex(block, resolved_ty, field_name, field_src);
20321 assert(field_inits[field_index] == .none);20319 assert(field_inits[field_index] == .none);
20322 found_fields[field_index] = item.data.field_type;20320 found_fields[field_index] = item.data.field_type;
20323 const uncoerced_init = try sema.resolveInst(item.data.init);20321 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);
20325 field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src);20323 field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src);
20326 if (!is_packed) {20324 if (!is_packed) {
20327 try resolved_ty.resolveStructFieldInits(pt);20325 try resolved_ty.resolveStructFieldInits(pt);
...@@ -20332,7 +20330,7 @@ fn zirStructInit(...@@ -20332,7 +20330,7 @@ fn zirStructInit(
20332 });20330 });
20333 };20331 };
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)) {
20336 return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index);20334 return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index);
20337 }20335 }
20338 }20336 }
...@@ -20340,7 +20338,7 @@ fn zirStructInit(...@@ -20340,7 +20338,7 @@ fn zirStructInit(
20340 }20338 }
2034120339
20342 return sema.finishStructInit(block, src, src, field_inits, resolved_ty, result_ty, is_ref);20340 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) {
20344 if (extra.data.fields_len != 1) {20342 if (extra.data.fields_len != 1) {
20345 return sema.fail(block, src, "union initialization expects exactly one field", .{});20343 return sema.fail(block, src, "union initialization expects exactly one field", .{});
20346 }20344 }
...@@ -20357,11 +20355,11 @@ fn zirStructInit(...@@ -20357,11 +20355,11 @@ fn zirStructInit(
20357 .no_embedded_nulls,20355 .no_embedded_nulls,
20358 );20356 );
20359 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);20357 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);
20361 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);20359 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) {
20365 return sema.failWithOwnedErrorMsg(block, msg: {20363 return sema.failWithOwnedErrorMsg(block, msg: {
20366 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});20364 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
20367 errdefer msg.destroy(sema.gpa);20365 errdefer msg.destroy(sema.gpa);
...@@ -20388,7 +20386,7 @@ fn zirStructInit(...@@ -20388,7 +20386,7 @@ fn zirStructInit(
20388 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);20386 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
20389 }20387 }
2039020388
20391 if (try sema.typeRequiresComptime(resolved_ty)) {20389 if (try resolved_ty.comptimeOnlySema(pt)) {
20392 return sema.failWithNeededComptime(block, field_src, .{20390 return sema.failWithNeededComptime(block, field_src, .{
20393 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",20391 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
20394 });20392 });
...@@ -20397,7 +20395,7 @@ fn zirStructInit(...@@ -20397,7 +20395,7 @@ fn zirStructInit(
20397 try sema.validateRuntimeValue(block, field_src, init_inst);20395 try sema.validateRuntimeValue(block, field_src, init_inst);
2039820396
20399 if (is_ref) {20397 if (is_ref) {
20400 const target = mod.getTarget();20398 const target = zcu.getTarget();
20401 const alloc_ty = try pt.ptrTypeSema(.{20399 const alloc_ty = try pt.ptrTypeSema(.{
20402 .child = result_ty.toIntern(),20400 .child = result_ty.toIntern(),
20403 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },20401 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
...@@ -20429,10 +20427,10 @@ fn finishStructInit(...@@ -20429,10 +20427,10 @@ fn finishStructInit(
20429 is_ref: bool,20427 is_ref: bool,
20430) CompileError!Air.Inst.Ref {20428) CompileError!Air.Inst.Ref {
20431 const pt = sema.pt;20429 const pt = sema.pt;
20432 const mod = pt.zcu;20430 const zcu = pt.zcu;
20433 const ip = &mod.intern_pool;20431 const ip = &zcu.intern_pool;
2043420432
20435 var root_msg: ?*Module.ErrorMsg = null;20433 var root_msg: ?*Zcu.ErrorMsg = null;
20436 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);20434 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
2043720435
20438 switch (ip.indexToKey(struct_ty.toIntern())) {20436 switch (ip.indexToKey(struct_ty.toIntern())) {
...@@ -20545,7 +20543,7 @@ fn finishStructInit(...@@ -20545,7 +20543,7 @@ fn finishStructInit(
20545 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);20543 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
20546 };20544 };
2054720545
20548 if (try sema.typeRequiresComptime(struct_ty)) {20546 if (try struct_ty.comptimeOnlySema(pt)) {
20549 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{20547 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{
20550 .init_node_offset = init_src.offset.node_offset.x,20548 .init_node_offset = init_src.offset.node_offset.x,
20551 .elem_index = @intCast(runtime_index),20549 .elem_index = @intCast(runtime_index),
...@@ -20560,7 +20558,7 @@ fn finishStructInit(...@@ -20560,7 +20558,7 @@ fn finishStructInit(
2056020558
20561 if (is_ref) {20559 if (is_ref) {
20562 try struct_ty.resolveLayout(pt);20560 try struct_ty.resolveLayout(pt);
20563 const target = mod.getTarget();20561 const target = zcu.getTarget();
20564 const alloc_ty = try pt.ptrTypeSema(.{20562 const alloc_ty = try pt.ptrTypeSema(.{
20565 .child = result_ty.toIntern(),20563 .child = result_ty.toIntern(),
20566 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },20564 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
...@@ -20612,9 +20610,9 @@ fn structInitAnon(...@@ -20612,9 +20610,9 @@ fn structInitAnon(
20612 is_ref: bool,20610 is_ref: bool,
20613) CompileError!Air.Inst.Ref {20611) CompileError!Air.Inst.Ref {
20614 const pt = sema.pt;20612 const pt = sema.pt;
20615 const mod = pt.zcu;20613 const zcu = pt.zcu;
20616 const gpa = sema.gpa;20614 const gpa = sema.gpa;
20617 const ip = &mod.intern_pool;20615 const ip = &zcu.intern_pool;
20618 const zir_datas = sema.code.instructions.items(.data);20616 const zir_datas = sema.code.instructions.items(.data);
2061920617
20620 const types = try sema.arena.alloc(InternPool.Index, extra_data.fields_len);20618 const types = try sema.arena.alloc(InternPool.Index, extra_data.fields_len);
...@@ -20642,11 +20640,11 @@ fn structInitAnon(...@@ -20642,11 +20640,11 @@ fn structInitAnon(
20642 },20640 },
20643 };20641 };
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
20647 const init = try sema.resolveInst(item.data.init);20645 const init = try sema.resolveInst(item.data.init);
20648 field_ty.* = sema.typeOf(init).toIntern();20646 field_ty.* = sema.typeOf(init).toIntern();
20649 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {20647 if (Type.fromInterned(field_ty.*).zigTypeTag(zcu) == .Opaque) {
20650 const msg = msg: {20648 const msg = msg: {
20651 const field_src = block.src(.{ .init_elem = .{20649 const field_src = block.src(.{ .init_elem = .{
20652 .init_node_offset = src.offset.node_offset.x,20650 .init_node_offset = src.offset.node_offset.x,
...@@ -20690,7 +20688,7 @@ fn structInitAnon(...@@ -20690,7 +20688,7 @@ fn structInitAnon(
20690 } }));20688 } }));
2069120689
20692 if (is_ref) {20690 if (is_ref) {
20693 const target = mod.getTarget();20691 const target = zcu.getTarget();
20694 const alloc_ty = try pt.ptrTypeSema(.{20692 const alloc_ty = try pt.ptrTypeSema(.{
20695 .child = tuple_ty,20693 .child = tuple_ty,
20696 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },20694 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
...@@ -20740,7 +20738,7 @@ fn zirArrayInit(...@@ -20740,7 +20738,7 @@ fn zirArrayInit(
20740 is_ref: bool,20738 is_ref: bool,
20741) CompileError!Air.Inst.Ref {20739) CompileError!Air.Inst.Ref {
20742 const pt = sema.pt;20740 const pt = sema.pt;
20743 const mod = pt.zcu;20741 const zcu = pt.zcu;
20744 const gpa = sema.gpa;20742 const gpa = sema.gpa;
20745 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20743 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20746 const src = block.nodeOffset(inst_data.src_node);20744 const src = block.nodeOffset(inst_data.src_node);
...@@ -20756,14 +20754,14 @@ fn zirArrayInit(...@@ -20756,14 +20754,14 @@ fn zirArrayInit(
20756 },20754 },
20757 else => |e| return e,20755 else => |e| return e,
20758 };20756 };
20759 const array_ty = result_ty.optEuBaseType(mod);20757 const array_ty = result_ty.optEuBaseType(zcu);
20760 const is_tuple = array_ty.zigTypeTag(mod) == .Struct;20758 const is_tuple = array_ty.zigTypeTag(zcu) == .Struct;
20761 const sentinel_val = array_ty.sentinel(mod);20759 const sentinel_val = array_ty.sentinel(zcu);
2076220760
20763 var root_msg: ?*Module.ErrorMsg = null;20761 var root_msg: ?*Zcu.ErrorMsg = null;
20764 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);20762 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));
20767 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);20765 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);
20768 defer gpa.free(resolved_args);20766 defer gpa.free(resolved_args);
20769 for (resolved_args, 0..) |*dest, i| {20767 for (resolved_args, 0..) |*dest, i| {
...@@ -20773,7 +20771,7 @@ fn zirArrayInit(...@@ -20773,7 +20771,7 @@ fn zirArrayInit(
20773 } });20771 } });
20774 // Less inits than needed.20772 // Less inits than needed.
20775 if (i + 2 > args.len) if (is_tuple) {20773 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();
20777 if (default_val == .unreachable_value) {20775 if (default_val == .unreachable_value) {
20778 const template = "missing tuple field with index {d}";20776 const template = "missing tuple field with index {d}";
20779 if (root_msg) |msg| {20777 if (root_msg) |msg| {
...@@ -20793,12 +20791,12 @@ fn zirArrayInit(...@@ -20793,12 +20791,12 @@ fn zirArrayInit(
20793 const arg = args[i + 1];20791 const arg = args[i + 1];
20794 const resolved_arg = try sema.resolveInst(arg);20792 const resolved_arg = try sema.resolveInst(arg);
20795 const elem_ty = if (is_tuple)20793 const elem_ty = if (is_tuple)
20796 array_ty.structFieldType(i, mod)20794 array_ty.fieldType(i, zcu)
20797 else20795 else
20798 array_ty.elemType2(mod);20796 array_ty.elemType2(zcu);
20799 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);20797 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
20800 if (is_tuple) {20798 if (is_tuple) {
20801 if (array_ty.structFieldIsComptime(i, mod))20799 if (array_ty.structFieldIsComptime(i, zcu))
20802 try array_ty.resolveStructFieldInits(pt);20800 try array_ty.resolveStructFieldInits(pt);
20803 if (try array_ty.structFieldValueComptime(pt, i)) |field_val| {20801 if (try array_ty.structFieldValueComptime(pt, i)) |field_val| {
20804 const init_val = try sema.resolveValue(dest.*) orelse {20802 const init_val = try sema.resolveValue(dest.*) orelse {
...@@ -20806,7 +20804,7 @@ fn zirArrayInit(...@@ -20806,7 +20804,7 @@ fn zirArrayInit(
20806 .needed_comptime_reason = "value stored in comptime field must be comptime-known",20804 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
20807 });20805 });
20808 };20806 };
20809 if (!field_val.eql(init_val, elem_ty, mod)) {20807 if (!field_val.eql(init_val, elem_ty, zcu)) {
20810 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);20808 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);
20811 }20809 }
20812 }20810 }
...@@ -20845,7 +20843,7 @@ fn zirArrayInit(...@@ -20845,7 +20843,7 @@ fn zirArrayInit(
20845 } }));20843 } }));
2084620844
20847 if (is_ref) {20845 if (is_ref) {
20848 const target = mod.getTarget();20846 const target = zcu.getTarget();
20849 const alloc_ty = try pt.ptrTypeSema(.{20847 const alloc_ty = try pt.ptrTypeSema(.{
20850 .child = result_ty.toIntern(),20848 .child = result_ty.toIntern(),
20851 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },20849 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
...@@ -20856,7 +20854,7 @@ fn zirArrayInit(...@@ -20856,7 +20854,7 @@ fn zirArrayInit(
20856 if (is_tuple) {20854 if (is_tuple) {
20857 for (resolved_args, 0..) |arg, i| {20855 for (resolved_args, 0..) |arg, i| {
20858 const elem_ptr_ty = try pt.ptrTypeSema(.{20856 const elem_ptr_ty = try pt.ptrTypeSema(.{
20859 .child = array_ty.structFieldType(i, mod).toIntern(),20857 .child = array_ty.fieldType(i, zcu).toIntern(),
20860 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },20858 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
20861 });20859 });
20862 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());20860 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
...@@ -20869,7 +20867,7 @@ fn zirArrayInit(...@@ -20869,7 +20867,7 @@ fn zirArrayInit(
20869 }20867 }
2087020868
20871 const elem_ptr_ty = try pt.ptrTypeSema(.{20869 const elem_ptr_ty = try pt.ptrTypeSema(.{
20872 .child = array_ty.elemType2(mod).toIntern(),20870 .child = array_ty.elemType2(zcu).toIntern(),
20873 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },20871 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
20874 });20872 });
20875 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());20873 const elem_ptr_ty_ref = Air.internedToRef(elem_ptr_ty.toIntern());
...@@ -20906,9 +20904,9 @@ fn arrayInitAnon(...@@ -20906,9 +20904,9 @@ fn arrayInitAnon(
20906 is_ref: bool,20904 is_ref: bool,
20907) CompileError!Air.Inst.Ref {20905) CompileError!Air.Inst.Ref {
20908 const pt = sema.pt;20906 const pt = sema.pt;
20909 const mod = pt.zcu;20907 const zcu = pt.zcu;
20910 const gpa = sema.gpa;20908 const gpa = sema.gpa;
20911 const ip = &mod.intern_pool;20909 const ip = &zcu.intern_pool;
2091220910
20913 const types = try sema.arena.alloc(InternPool.Index, operands.len);20911 const types = try sema.arena.alloc(InternPool.Index, operands.len);
20914 const values = try sema.arena.alloc(InternPool.Index, operands.len);20912 const values = try sema.arena.alloc(InternPool.Index, operands.len);
...@@ -20919,7 +20917,7 @@ fn arrayInitAnon(...@@ -20919,7 +20917,7 @@ fn arrayInitAnon(
20919 const operand_src = src; // TODO better source location20917 const operand_src = src; // TODO better source location
20920 const elem = try sema.resolveInst(operand);20918 const elem = try sema.resolveInst(operand);
20921 types[i] = sema.typeOf(elem).toIntern();20919 types[i] = sema.typeOf(elem).toIntern();
20922 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {20920 if (Type.fromInterned(types[i]).zigTypeTag(zcu) == .Opaque) {
20923 const msg = msg: {20921 const msg = msg: {
20924 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});20922 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20925 errdefer msg.destroy(gpa);20923 errdefer msg.destroy(gpa);
...@@ -21003,8 +21001,8 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -21003,8 +21001,8 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2100321001
21004fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21002fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21005 const pt = sema.pt;21003 const pt = sema.pt;
21006 const mod = pt.zcu;21004 const zcu = pt.zcu;
21007 const ip = &mod.intern_pool;21005 const ip = &zcu.intern_pool;
21008 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;21006 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
21009 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;21007 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
21010 const ty_src = block.nodeOffset(inst_data.src_node);21008 const ty_src = block.nodeOffset(inst_data.src_node);
...@@ -21017,7 +21015,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -21017,7 +21015,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
21017 error.GenericPoison => return .generic_poison_type,21015 error.GenericPoison => return .generic_poison_type,
21018 else => |e| return e,21016 else => |e| return e,
21019 };21017 };
21020 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(mod);21018 const aggregate_ty = wrapped_aggregate_ty.optEuBaseType(zcu);
21021 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);21019 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);
21022 const field_name = try ip.getOrPutString(sema.gpa, pt.tid, zir_field_name, .no_embedded_nulls);21020 const field_name = try ip.getOrPutString(sema.gpa, pt.tid, zir_field_name, .no_embedded_nulls);
21023 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);21021 return sema.fieldType(block, aggregate_ty, field_name, field_name_src, ty_src);
...@@ -21032,12 +21030,12 @@ fn fieldType(...@@ -21032,12 +21030,12 @@ fn fieldType(
21032 ty_src: LazySrcLoc,21030 ty_src: LazySrcLoc,
21033) CompileError!Air.Inst.Ref {21031) CompileError!Air.Inst.Ref {
21034 const pt = sema.pt;21032 const pt = sema.pt;
21035 const mod = pt.zcu;21033 const zcu = pt.zcu;
21036 const ip = &mod.intern_pool;21034 const ip = &zcu.intern_pool;
21037 var cur_ty = aggregate_ty;21035 var cur_ty = aggregate_ty;
21038 while (true) {21036 while (true) {
21039 try cur_ty.resolveFields(pt);21037 try cur_ty.resolveFields(pt);
21040 switch (cur_ty.zigTypeTag(mod)) {21038 switch (cur_ty.zigTypeTag(zcu)) {
21041 .Struct => switch (ip.indexToKey(cur_ty.toIntern())) {21039 .Struct => switch (ip.indexToKey(cur_ty.toIntern())) {
21042 .anon_struct_type => |anon_struct| {21040 .anon_struct_type => |anon_struct| {
21043 const field_index = if (anon_struct.names.len == 0)21041 const field_index = if (anon_struct.names.len == 0)
...@@ -21056,7 +21054,7 @@ fn fieldType(...@@ -21056,7 +21054,7 @@ fn fieldType(
21056 else => unreachable,21054 else => unreachable,
21057 },21055 },
21058 .Union => {21056 .Union => {
21059 const union_obj = mod.typeToUnion(cur_ty).?;21057 const union_obj = zcu.typeToUnion(cur_ty).?;
21060 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse21058 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
21061 return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name);21059 return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name);
21062 const field_ty = union_obj.field_types.get(ip)[field_index];21060 const field_ty = union_obj.field_types.get(ip)[field_index];
...@@ -21069,7 +21067,7 @@ fn fieldType(...@@ -21069,7 +21067,7 @@ fn fieldType(
21069 continue;21067 continue;
21070 },21068 },
21071 .ErrorUnion => {21069 .ErrorUnion => {
21072 cur_ty = cur_ty.errorUnionPayload(mod);21070 cur_ty = cur_ty.errorUnionPayload(zcu);
21073 continue;21071 continue;
21074 },21072 },
21075 else => {},21073 else => {},
...@@ -21086,8 +21084,8 @@ fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {...@@ -21086,8 +21084,8 @@ fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
2108621084
21087fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {21085fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
21088 const pt = sema.pt;21086 const pt = sema.pt;
21089 const mod = pt.zcu;21087 const zcu = pt.zcu;
21090 const ip = &mod.intern_pool;21088 const ip = &zcu.intern_pool;
21091 const stack_trace_ty = try pt.getBuiltinType("StackTrace");21089 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
21092 try stack_trace_ty.resolveFields(pt);21090 try stack_trace_ty.resolveFields(pt);
21093 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);21091 const ptr_stack_trace_ty = try pt.singleMutPtrType(stack_trace_ty);
...@@ -21115,42 +21113,42 @@ fn zirFrame(...@@ -21115,42 +21113,42 @@ fn zirFrame(
21115}21113}
2111621114
21117fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21115fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21118 const pt = sema.pt;21116 const zcu = sema.pt.zcu;
21119 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21117 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21120 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);21118 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21121 const ty = try sema.resolveType(block, operand_src, inst_data.operand);21119 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
21122 if (ty.isNoReturn(pt.zcu)) {21120 if (ty.isNoReturn(zcu)) {
21123 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(pt)});21121 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.pt)});
21124 }21122 }
21125 const val = try ty.lazyAbiAlignment(pt);21123 const val = try ty.lazyAbiAlignment(sema.pt);
21126 return Air.internedToRef(val.toIntern());21124 return Air.internedToRef(val.toIntern());
21127}21125}
2112821126
21129fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21127fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21130 const pt = sema.pt;21128 const pt = sema.pt;
21131 const mod = pt.zcu;21129 const zcu = pt.zcu;
21132 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21130 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21133 const src = block.nodeOffset(inst_data.src_node);21131 const src = block.nodeOffset(inst_data.src_node);
21134 const operand = try sema.resolveInst(inst_data.operand);21132 const operand = try sema.resolveInst(inst_data.operand);
21135 const operand_ty = sema.typeOf(operand);21133 const operand_ty = sema.typeOf(operand);
21136 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;21134 const is_vector = operand_ty.zigTypeTag(zcu) == .Vector;
21137 const operand_scalar_ty = operand_ty.scalarType(mod);21135 const operand_scalar_ty = operand_ty.scalarType(zcu);
21138 if (operand_scalar_ty.toIntern() != .bool_type) {21136 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)});
21140 }21138 }
21141 if (try sema.resolveValue(operand)) |val| {21139 if (try sema.resolveValue(operand)) |val| {
21142 if (!is_vector) {21140 if (!is_vector) {
21143 if (val.isUndef(mod)) return pt.undefRef(Type.u1);21141 if (val.isUndef(zcu)) return pt.undefRef(Type.u1);
21144 if (val.toBool()) return Air.internedToRef((try pt.intValue(Type.u1, 1)).toIntern());21142 if (val.toBool()) return Air.internedToRef((try pt.intValue(Type.u1, 1)).toIntern());
21145 return Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());21143 return Air.internedToRef((try pt.intValue(Type.u1, 0)).toIntern());
21146 }21144 }
21147 const len = operand_ty.vectorLen(mod);21145 const len = operand_ty.vectorLen(zcu);
21148 const dest_ty = try pt.vectorType(.{ .child = .u1_type, .len = len });21146 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);
21150 const new_elems = try sema.arena.alloc(InternPool.Index, len);21148 const new_elems = try sema.arena.alloc(InternPool.Index, len);
21151 for (new_elems, 0..) |*new_elem, i| {21149 for (new_elems, 0..) |*new_elem, i| {
21152 const old_elem = try val.elemValue(pt, i);21150 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))
21154 try pt.undefValue(Type.u1)21152 try pt.undefValue(Type.u1)
21155 else if (old_elem.toBool())21153 else if (old_elem.toBool())
21156 try pt.intValue(Type.u1, 1)21154 try pt.intValue(Type.u1, 1)
...@@ -21166,7 +21164,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -21166,7 +21164,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
21166 if (!is_vector) {21164 if (!is_vector) {
21167 return block.addUnOp(.int_from_bool, operand);21165 return block.addUnOp(.int_from_bool, operand);
21168 }21166 }
21169 const len = operand_ty.vectorLen(mod);21167 const len = operand_ty.vectorLen(zcu);
21170 const dest_ty = try pt.vectorType(.{ .child = .u1_type, .len = len });21168 const dest_ty = try pt.vectorType(.{ .child = .u1_type, .len = len });
21171 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);21169 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
21172 for (new_elems, 0..) |*new_elem, i| {21170 for (new_elems, 0..) |*new_elem, i| {
...@@ -21199,16 +21197,16 @@ fn zirAbs(...@@ -21199,16 +21197,16 @@ fn zirAbs(
21199 inst: Zir.Inst.Index,21197 inst: Zir.Inst.Index,
21200) CompileError!Air.Inst.Ref {21198) CompileError!Air.Inst.Ref {
21201 const pt = sema.pt;21199 const pt = sema.pt;
21202 const mod = pt.zcu;21200 const zcu = pt.zcu;
21203 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21201 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21204 const operand = try sema.resolveInst(inst_data.operand);21202 const operand = try sema.resolveInst(inst_data.operand);
21205 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);21203 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21206 const operand_ty = sema.typeOf(operand);21204 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)) {
21210 .ComptimeFloat, .Float, .ComptimeInt => operand_ty,21208 .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,
21212 else => return sema.fail(21210 else => return sema.fail(
21213 block,21211 block,
21214 operand_src,21212 operand_src,
...@@ -21230,12 +21228,12 @@ fn maybeConstantUnaryMath(...@@ -21230,12 +21228,12 @@ fn maybeConstantUnaryMath(
21230 comptime eval: fn (Value, Type, Allocator, Zcu.PerThread) Allocator.Error!Value,21228 comptime eval: fn (Value, Type, Allocator, Zcu.PerThread) Allocator.Error!Value,
21231) CompileError!?Air.Inst.Ref {21229) CompileError!?Air.Inst.Ref {
21232 const pt = sema.pt;21230 const pt = sema.pt;
21233 const mod = pt.zcu;21231 const zcu = pt.zcu;
21234 switch (result_ty.zigTypeTag(mod)) {21232 switch (result_ty.zigTypeTag(zcu)) {
21235 .Vector => if (try sema.resolveValue(operand)) |val| {21233 .Vector => if (try sema.resolveValue(operand)) |val| {
21236 const scalar_ty = result_ty.scalarType(mod);21234 const scalar_ty = result_ty.scalarType(zcu);
21237 const vec_len = result_ty.vectorLen(mod);21235 const vec_len = result_ty.vectorLen(zcu);
21238 if (val.isUndef(mod))21236 if (val.isUndef(zcu))
21239 return try pt.undefRef(result_ty);21237 return try pt.undefRef(result_ty);
2124021238
21241 const elems = try sema.arena.alloc(InternPool.Index, vec_len);21239 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
...@@ -21249,7 +21247,7 @@ fn maybeConstantUnaryMath(...@@ -21249,7 +21247,7 @@ fn maybeConstantUnaryMath(
21249 } })));21247 } })));
21250 },21248 },
21251 else => if (try sema.resolveValue(operand)) |operand_val| {21249 else => if (try sema.resolveValue(operand)) |operand_val| {
21252 if (operand_val.isUndef(mod))21250 if (operand_val.isUndef(zcu))
21253 return try pt.undefRef(result_ty);21251 return try pt.undefRef(result_ty);
21254 const result_val = try eval(operand_val, result_ty, sema.arena, pt);21252 const result_val = try eval(operand_val, result_ty, sema.arena, pt);
21255 return Air.internedToRef(result_val.toIntern());21253 return Air.internedToRef(result_val.toIntern());
...@@ -21269,14 +21267,14 @@ fn zirUnaryMath(...@@ -21269,14 +21267,14 @@ fn zirUnaryMath(
21269 defer tracy.end();21267 defer tracy.end();
2127021268
21271 const pt = sema.pt;21269 const pt = sema.pt;
21272 const mod = pt.zcu;21270 const zcu = pt.zcu;
21273 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21271 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21274 const operand = try sema.resolveInst(inst_data.operand);21272 const operand = try sema.resolveInst(inst_data.operand);
21275 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);21273 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21276 const operand_ty = sema.typeOf(operand);21274 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)) {
21280 .ComptimeFloat, .Float => {},21278 .ComptimeFloat, .Float => {},
21281 else => return sema.fail(21279 else => return sema.fail(
21282 block,21280 block,
...@@ -21359,9 +21357,9 @@ fn zirReify(...@@ -21359,9 +21357,9 @@ fn zirReify(
21359 inst: Zir.Inst.Index,21357 inst: Zir.Inst.Index,
21360) CompileError!Air.Inst.Ref {21358) CompileError!Air.Inst.Ref {
21361 const pt = sema.pt;21359 const pt = sema.pt;
21362 const mod = pt.zcu;21360 const zcu = pt.zcu;
21363 const gpa = sema.gpa;21361 const gpa = sema.gpa;
21364 const ip = &mod.intern_pool;21362 const ip = &zcu.intern_pool;
21365 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);21363 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
21366 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;21364 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
21367 const tracked_inst = try block.trackZir(inst);21365 const tracked_inst = try block.trackZir(inst);
...@@ -21388,7 +21386,7 @@ fn zirReify(...@@ -21388,7 +21386,7 @@ fn zirReify(
21388 if (try sema.anyUndef(block, operand_src, Value.fromInterned(union_val.val))) {21386 if (try sema.anyUndef(block, operand_src, Value.fromInterned(union_val.val))) {
21389 return sema.failWithUseOfUndef(block, operand_src);21387 return sema.failWithUseOfUndef(block, operand_src);
21390 }21388 }
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).?;
21392 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {21390 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
21393 .Type => return .type_type,21391 .Type => return .type_type,
21394 .Void => return .void_type,21392 .Void => return .void_type,
...@@ -21411,7 +21409,7 @@ fn zirReify(...@@ -21411,7 +21409,7 @@ fn zirReify(
21411 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls)).?,21409 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, pt.tid, "bits", .no_embedded_nulls)).?,
21412 );21410 );
2141321411
21414 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);21412 const signedness = zcu.toEnum(std.builtin.Signedness, signedness_val);
21415 const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt));21413 const bits: u16 = @intCast(try bits_val.toUnsignedIntSema(pt));
21416 const ty = try pt.intType(signedness, bits);21414 const ty = try pt.intType(signedness, bits);
21417 return Air.internedToRef(ty.toIntern());21415 return Air.internedToRef(ty.toIntern());
...@@ -21495,7 +21493,7 @@ fn zirReify(...@@ -21495,7 +21493,7 @@ fn zirReify(
21495 return sema.fail(block, src, "alignment must fit in 'u32'", .{});21493 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
21496 }21494 }
2149721495
21498 const alignment_val_int = (try alignment_val.getUnsignedIntAdvanced(pt, .sema)).?;21496 const alignment_val_int = try alignment_val.toUnsignedIntSema(pt);
21499 if (alignment_val_int > 0 and !math.isPowerOfTwo(alignment_val_int)) {21497 if (alignment_val_int > 0 and !math.isPowerOfTwo(alignment_val_int)) {
21500 return sema.fail(block, src, "alignment value '{d}' is not a power of two or zero", .{alignment_val_int});21498 return sema.fail(block, src, "alignment value '{d}' is not a power of two or zero", .{alignment_val_int});
21501 }21499 }
...@@ -21506,14 +21504,14 @@ fn zirReify(...@@ -21506,14 +21504,14 @@ fn zirReify(
21506 try elem_ty.resolveLayout(pt);21504 try elem_ty.resolveLayout(pt);
21507 }21505 }
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
21511 const actual_sentinel: InternPool.Index = s: {21509 const actual_sentinel: InternPool.Index = s: {
21512 if (!sentinel_val.isNull(mod)) {21510 if (!sentinel_val.isNull(zcu)) {
21513 if (ptr_size == .One or ptr_size == .C) {21511 if (ptr_size == .One or ptr_size == .C) {
21514 return sema.fail(block, src, "sentinels are only allowed on slices and unknown-length pointers", .{});21512 return sema.fail(block, src, "sentinels are only allowed on slices and unknown-length pointers", .{});
21515 }21513 }
21516 const sentinel_ptr_val = sentinel_val.optionalValue(mod).?;21514 const sentinel_ptr_val = sentinel_val.optionalValue(zcu).?;
21517 const ptr_ty = try pt.singleMutPtrType(elem_ty);21515 const ptr_ty = try pt.singleMutPtrType(elem_ty);
21518 const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?;21516 const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?;
21519 break :s sent_val.toIntern();21517 break :s sent_val.toIntern();
...@@ -21521,13 +21519,13 @@ fn zirReify(...@@ -21521,13 +21519,13 @@ fn zirReify(
21521 break :s .none;21519 break :s .none;
21522 };21520 };
2152321521
21524 if (elem_ty.zigTypeTag(mod) == .NoReturn) {21522 if (elem_ty.zigTypeTag(zcu) == .NoReturn) {
21525 return sema.fail(block, src, "pointer to noreturn not allowed", .{});21523 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) {
21527 if (ptr_size != .One) {21525 if (ptr_size != .One) {
21528 return sema.fail(block, src, "function pointers must be single pointers", .{});21526 return sema.fail(block, src, "function pointers must be single pointers", .{});
21529 }21527 }
21530 } else if (ptr_size == .Many and elem_ty.zigTypeTag(mod) == .Opaque) {21528 } else if (ptr_size == .Many and elem_ty.zigTypeTag(zcu) == .Opaque) {
21531 return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{});21529 return sema.fail(block, src, "unknown-length pointer to opaque not allowed", .{});
21532 } else if (ptr_size == .C) {21530 } else if (ptr_size == .C) {
21533 if (!try sema.validateExternType(elem_ty, .other)) {21531 if (!try sema.validateExternType(elem_ty, .other)) {
...@@ -21542,7 +21540,7 @@ fn zirReify(...@@ -21542,7 +21540,7 @@ fn zirReify(
21542 };21540 };
21543 return sema.failWithOwnedErrorMsg(block, msg);21541 return sema.failWithOwnedErrorMsg(block, msg);
21544 }21542 }
21545 if (elem_ty.zigTypeTag(mod) == .Opaque) {21543 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
21546 return sema.fail(block, src, "C pointers cannot point to opaque types", .{});21544 return sema.fail(block, src, "C pointers cannot point to opaque types", .{});
21547 }21545 }
21548 }21546 }
...@@ -21555,7 +21553,7 @@ fn zirReify(...@@ -21555,7 +21553,7 @@ fn zirReify(
21555 .is_const = is_const_val.toBool(),21553 .is_const = is_const_val.toBool(),
21556 .is_volatile = is_volatile_val.toBool(),21554 .is_volatile = is_volatile_val.toBool(),
21557 .alignment = abi_align,21555 .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),
21559 .is_allowzero = is_allowzero_val.toBool(),21557 .is_allowzero = is_allowzero_val.toBool(),
21560 },21558 },
21561 });21559 });
...@@ -21578,7 +21576,7 @@ fn zirReify(...@@ -21578,7 +21576,7 @@ fn zirReify(
2157821576
21579 const len = try len_val.toUnsignedIntSema(pt);21577 const len = try len_val.toUnsignedIntSema(pt);
21580 const child_ty = child_val.toType();21578 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: {
21582 const ptr_ty = try pt.singleMutPtrType(child_ty);21580 const ptr_ty = try pt.singleMutPtrType(child_ty);
21583 break :blk (try sema.pointerDeref(block, src, p, ptr_ty)).?;21581 break :blk (try sema.pointerDeref(block, src, p, ptr_ty)).?;
21584 } else null;21582 } else null;
...@@ -21616,7 +21614,7 @@ fn zirReify(...@@ -21616,7 +21614,7 @@ fn zirReify(
21616 const error_set_ty = error_set_val.toType();21614 const error_set_ty = error_set_val.toType();
21617 const payload_ty = payload_val.toType();21615 const payload_ty = payload_val.toType();
2161821616
21619 if (error_set_ty.zigTypeTag(mod) != .ErrorSet) {21617 if (error_set_ty.zigTypeTag(zcu) != .ErrorSet) {
21620 return sema.fail(block, src, "Type.ErrorUnion.error_set must be an error set type", .{});21618 return sema.fail(block, src, "Type.ErrorUnion.error_set must be an error set type", .{});
21621 }21619 }
2162221620
...@@ -21624,14 +21622,14 @@ fn zirReify(...@@ -21624,14 +21622,14 @@ fn zirReify(
21624 return Air.internedToRef(ty.toIntern());21622 return Air.internedToRef(ty.toIntern());
21625 },21623 },
21626 .ErrorSet => {21624 .ErrorSet => {
21627 const payload_val = Value.fromInterned(union_val.val).optionalValue(mod) orelse21625 const payload_val = Value.fromInterned(union_val.val).optionalValue(zcu) orelse
21628 return Air.internedToRef(Type.anyerror.toIntern());21626 return Air.internedToRef(Type.anyerror.toIntern());
2162921627
21630 const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{21628 const names_val = try sema.derefSliceAsArray(block, src, payload_val, .{
21631 .needed_comptime_reason = "error set contents must be comptime-known",21629 .needed_comptime_reason = "error set contents must be comptime-known",
21632 });21630 });
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));
21635 var names: InferredErrorSet.NameMap = .{};21633 var names: InferredErrorSet.NameMap = .{};
21636 try names.ensureUnusedCapacity(sema.arena, len);21634 try names.ensureUnusedCapacity(sema.arena, len);
21637 for (0..len) |i| {21635 for (0..len) |i| {
...@@ -21680,14 +21678,14 @@ fn zirReify(...@@ -21680,14 +21678,14 @@ fn zirReify(
21680 try ip.getOrPutString(gpa, pt.tid, "is_tuple", .no_embedded_nulls),21678 try ip.getOrPutString(gpa, pt.tid, "is_tuple", .no_embedded_nulls),
21681 ).?);21679 ).?);
2168221680
21683 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);21681 const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val);
2168421682
21685 // Decls21683 // Decls
21686 if (try decls_val.sliceLen(pt) > 0) {21684 if (try decls_val.sliceLen(pt) > 0) {
21687 return sema.fail(block, src, "reified structs must have no decls", .{});21685 return sema.fail(block, src, "reified structs must have no decls", .{});
21688 }21686 }
2168921687
21690 if (layout != .@"packed" and !backing_integer_val.isNull(mod)) {21688 if (layout != .@"packed" and !backing_integer_val.isNull(zcu)) {
21691 return sema.fail(block, src, "non-packed struct does not support backing integer type", .{});21689 return sema.fail(block, src, "non-packed struct does not support backing integer type", .{});
21692 }21690 }
2169321691
...@@ -21762,8 +21760,8 @@ fn zirReify(...@@ -21762,8 +21760,8 @@ fn zirReify(
21762 const new_namespace_index = try pt.createNamespace(.{21760 const new_namespace_index = try pt.createNamespace(.{
21763 .parent = block.namespace.toOptional(),21761 .parent = block.namespace.toOptional(),
21764 .owner_type = wip_ty.index,21762 .owner_type = wip_ty.index,
21765 .file_scope = block.getFileScopeIndex(mod),21763 .file_scope = block.getFileScopeIndex(zcu),
21766 .generation = mod.generation,21764 .generation = zcu.generation,
21767 });21765 });
2176821766
21769 try sema.addTypeReferenceEntry(src, wip_ty.index);21767 try sema.addTypeReferenceEntry(src, wip_ty.index);
...@@ -21791,7 +21789,7 @@ fn zirReify(...@@ -21791,7 +21789,7 @@ fn zirReify(
21791 if (try decls_val.sliceLen(pt) > 0) {21789 if (try decls_val.sliceLen(pt) > 0) {
21792 return sema.fail(block, src, "reified unions must have no decls", .{});21790 return sema.fail(block, src, "reified unions must have no decls", .{});
21793 }21791 }
21794 const layout = mod.toEnum(std.builtin.Type.ContainerLayout, layout_val);21792 const layout = zcu.toEnum(std.builtin.Type.ContainerLayout, layout_val);
2179521793
21796 const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{21794 const fields_arr = try sema.derefSliceAsArray(block, operand_src, fields_val, .{
21797 .needed_comptime_reason = "union fields must be comptime-known",21795 .needed_comptime_reason = "union fields must be comptime-known",
...@@ -21828,19 +21826,19 @@ fn zirReify(...@@ -21828,19 +21826,19 @@ fn zirReify(
21828 }21826 }
2182921827
21830 const is_var_args = is_var_args_val.toBool();21828 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);
21832 if (is_var_args) {21830 if (is_var_args) {
21833 try sema.checkCallConvSupportsVarArgs(block, src, cc);21831 try sema.checkCallConvSupportsVarArgs(block, src, cc);
21834 }21832 }
2183521833
21836 const return_type = return_type_val.optionalValue(mod) orelse21834 const return_type = return_type_val.optionalValue(zcu) orelse
21837 return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{});21835 return sema.fail(block, src, "Type.Fn.return_type must be non-null for @Type", .{});
2183821836
21839 const params_val = try sema.derefSliceAsArray(block, operand_src, params_slice_val, .{21837 const params_val = try sema.derefSliceAsArray(block, operand_src, params_slice_val, .{
21840 .needed_comptime_reason = "function parameters must be comptime-known",21838 .needed_comptime_reason = "function parameters must be comptime-known",
21841 });21839 });
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));
21844 const param_types = try sema.arena.alloc(InternPool.Index, args_len);21842 const param_types = try sema.arena.alloc(InternPool.Index, args_len);
2184521843
21846 var noalias_bits: u32 = 0;21844 var noalias_bits: u32 = 0;
...@@ -21864,12 +21862,12 @@ fn zirReify(...@@ -21864,12 +21862,12 @@ fn zirReify(
21864 return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{});21862 return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{});
21865 }21863 }
2186621864
21867 const param_type_val = opt_param_type_val.optionalValue(mod) orelse21865 const param_type_val = opt_param_type_val.optionalValue(zcu) orelse
21868 return sema.fail(block, src, "Type.Fn.Param.type must be non-null for @Type", .{});21866 return sema.fail(block, src, "Type.Fn.Param.type must be non-null for @Type", .{});
21869 param_type.* = param_type_val.toIntern();21867 param_type.* = param_type_val.toIntern();
2187021868
21871 if (param_is_noalias_val.toBool()) {21869 if (param_is_noalias_val.toBool()) {
21872 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(mod)) {21870 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(zcu)) {
21873 return sema.fail(block, src, "non-pointer parameter declared noalias", .{});21871 return sema.fail(block, src, "non-pointer parameter declared noalias", .{});
21874 }21872 }
21875 noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse21873 noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse
...@@ -21901,13 +21899,13 @@ fn reifyEnum(...@@ -21901,13 +21899,13 @@ fn reifyEnum(
21901 name_strategy: Zir.Inst.NameStrategy,21899 name_strategy: Zir.Inst.NameStrategy,
21902) CompileError!Air.Inst.Ref {21900) CompileError!Air.Inst.Ref {
21903 const pt = sema.pt;21901 const pt = sema.pt;
21904 const mod = pt.zcu;21902 const zcu = pt.zcu;
21905 const gpa = sema.gpa;21903 const gpa = sema.gpa;
21906 const ip = &mod.intern_pool;21904 const ip = &zcu.intern_pool;
2190721905
21908 // This logic must stay in sync with the structure of `std.builtin.Type.Enum` - search for `fieldValue`.21906 // 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
21912 // The validation work here is non-trivial, and it's possible the type already exists.21910 // The validation work here is non-trivial, and it's possible the type already exists.
21913 // So in this first pass, let's just construct a hash to optimize for this case. If the21911 // So in this first pass, let's just construct a hash to optimize for this case. If the
...@@ -21957,7 +21955,7 @@ fn reifyEnum(...@@ -21957,7 +21955,7 @@ fn reifyEnum(
21957 var done = false;21955 var done = false;
21958 errdefer if (!done) wip_ty.cancel(ip, pt.tid);21956 errdefer if (!done) wip_ty.cancel(ip, pt.tid);
2195921957
21960 if (tag_ty.zigTypeTag(mod) != .Int) {21958 if (tag_ty.zigTypeTag(zcu) != .Int) {
21961 return sema.fail(block, src, "Type.Enum.tag_type must be an integer type", .{});21959 return sema.fail(block, src, "Type.Enum.tag_type must be an integer type", .{});
21962 }21960 }
2196321961
...@@ -21972,8 +21970,8 @@ fn reifyEnum(...@@ -21972,8 +21970,8 @@ fn reifyEnum(
21972 const new_namespace_index = try pt.createNamespace(.{21970 const new_namespace_index = try pt.createNamespace(.{
21973 .parent = block.namespace.toOptional(),21971 .parent = block.namespace.toOptional(),
21974 .owner_type = wip_ty.index,21972 .owner_type = wip_ty.index,
21975 .file_scope = block.getFileScopeIndex(mod),21973 .file_scope = block.getFileScopeIndex(zcu),
21976 .generation = mod.generation,21974 .generation = zcu.generation,
21977 });21975 });
2197821976
21979 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);21977 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);
...@@ -22023,14 +22021,14 @@ fn reifyEnum(...@@ -22023,14 +22021,14 @@ fn reifyEnum(
22023 }22021 }
22024 }22022 }
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)) {
22027 return sema.fail(block, src, "non-exhaustive enum specified every value", .{});22025 return sema.fail(block, src, "non-exhaustive enum specified every value", .{});
22028 }22026 }
2202922027
22030 codegen_type: {22028 codegen_type: {
22031 if (mod.comp.config.use_llvm) break :codegen_type;22029 if (zcu.comp.config.use_llvm) break :codegen_type;
22032 if (block.ownerModule().strip) break :codegen_type;22030 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 });
22034 }22032 }
22035 return Air.internedToRef(wip_ty.index);22033 return Air.internedToRef(wip_ty.index);
22036}22034}
...@@ -22046,13 +22044,13 @@ fn reifyUnion(...@@ -22046,13 +22044,13 @@ fn reifyUnion(
22046 name_strategy: Zir.Inst.NameStrategy,22044 name_strategy: Zir.Inst.NameStrategy,
22047) CompileError!Air.Inst.Ref {22045) CompileError!Air.Inst.Ref {
22048 const pt = sema.pt;22046 const pt = sema.pt;
22049 const mod = pt.zcu;22047 const zcu = pt.zcu;
22050 const gpa = sema.gpa;22048 const gpa = sema.gpa;
22051 const ip = &mod.intern_pool;22049 const ip = &zcu.intern_pool;
2205222050
22053 // This logic must stay in sync with the structure of `std.builtin.Type.Union` - search for `fieldValue`.22051 // 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
22057 // The validation work here is non-trivial, and it's possible the type already exists.22055 // The validation work here is non-trivial, and it's possible the type already exists.
22058 // So in this first pass, let's just construct a hash to optimize for this case. If the22056 // So in this first pass, let's just construct a hash to optimize for this case. If the
...@@ -22084,7 +22082,7 @@ fn reifyUnion(...@@ -22084,7 +22082,7 @@ fn reifyUnion(
22084 field_align_val.toIntern(),22082 field_align_val.toIntern(),
22085 });22083 });
2208622084
22087 if (field_align_val.toUnsignedInt(pt) != 0) {22085 if (field_align_val.toUnsignedInt(zcu) != 0) {
22088 any_aligns = true;22086 any_aligns = true;
22089 }22087 }
22090 }22088 }
...@@ -22095,7 +22093,7 @@ fn reifyUnion(...@@ -22095,7 +22093,7 @@ fn reifyUnion(
22095 .flags = .{22093 .flags = .{
22096 .layout = layout,22094 .layout = layout,
22097 .status = .none,22095 .status = .none,
22098 .runtime_tag = if (opt_tag_type_val.optionalValue(mod) != null)22096 .runtime_tag = if (opt_tag_type_val.optionalValue(zcu) != null)
22099 .tagged22097 .tagged
22100 else if (layout != .auto)22098 else if (layout != .auto)
22101 .none22099 .none
...@@ -22139,7 +22137,7 @@ fn reifyUnion(...@@ -22139,7 +22137,7 @@ fn reifyUnion(
22139 const field_types = try sema.arena.alloc(InternPool.Index, fields_len);22137 const field_types = try sema.arena.alloc(InternPool.Index, fields_len);
22140 const field_aligns = if (any_aligns) try sema.arena.alloc(InternPool.Alignment, fields_len) else undefined;22138 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: {
22143 switch (ip.indexToKey(tag_type_val.toIntern())) {22141 switch (ip.indexToKey(tag_type_val.toIntern())) {
22144 .enum_type => {},22142 .enum_type => {},
22145 else => return sema.fail(block, src, "Type.Union.tag_type must be an enum type", .{}),22143 else => return sema.fail(block, src, "Type.Union.tag_type must be an enum type", .{}),
...@@ -22147,7 +22145,7 @@ fn reifyUnion(...@@ -22147,7 +22145,7 @@ fn reifyUnion(
22147 const enum_tag_ty = tag_type_val.toType();22145 const enum_tag_ty = tag_type_val.toType();
2214822146
22149 // We simply track which fields of the tag type have been seen.22147 // 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);
22151 var seen_tags = try std.DynamicBitSetUnmanaged.initEmpty(sema.arena, tag_ty_fields_len);22149 var seen_tags = try std.DynamicBitSetUnmanaged.initEmpty(sema.arena, tag_ty_fields_len);
2215222150
22153 for (field_types, 0..) |*field_ty, field_idx| {22151 for (field_types, 0..) |*field_ty, field_idx| {
...@@ -22159,7 +22157,7 @@ fn reifyUnion(...@@ -22159,7 +22157,7 @@ fn reifyUnion(
22159 // Don't pass a reason; first loop acts as an assertion that this is valid.22157 // Don't pass a reason; first loop acts as an assertion that this is valid.
22160 const field_name = try sema.sliceToIpString(block, src, field_name_val, undefined);22158 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 {
22163 // TODO: better source location22161 // TODO: better source location
22164 return sema.fail(block, src, "no field named '{}' in enum '{}'", .{22162 return sema.fail(block, src, "no field named '{}' in enum '{}'", .{
22165 field_name.fmt(ip), enum_tag_ty.fmt(pt),22163 field_name.fmt(ip), enum_tag_ty.fmt(pt),
...@@ -22187,7 +22185,7 @@ fn reifyUnion(...@@ -22187,7 +22185,7 @@ fn reifyUnion(
22187 errdefer msg.destroy(gpa);22185 errdefer msg.destroy(gpa);
22188 var it = seen_tags.iterator(.{ .kind = .unset });22186 var it = seen_tags.iterator(.{ .kind = .unset });
22189 while (it.next()) |enum_index| {22187 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);
22191 try sema.addFieldErrNote(enum_tag_ty, enum_index, msg, "field '{}' missing, declared here", .{22189 try sema.addFieldErrNote(enum_tag_ty, enum_index, msg, "field '{}' missing, declared here", .{
22192 field_name.fmt(ip),22190 field_name.fmt(ip),
22193 });22191 });
...@@ -22234,7 +22232,7 @@ fn reifyUnion(...@@ -22234,7 +22232,7 @@ fn reifyUnion(
2223422232
22235 for (field_types) |field_ty_ip| {22233 for (field_types) |field_ty_ip| {
22236 const field_ty = Type.fromInterned(field_ty_ip);22234 const field_ty = Type.fromInterned(field_ty_ip);
22237 if (field_ty.zigTypeTag(mod) == .Opaque) {22235 if (field_ty.zigTypeTag(zcu) == .Opaque) {
22238 return sema.failWithOwnedErrorMsg(block, msg: {22236 return sema.failWithOwnedErrorMsg(block, msg: {
22239 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});22237 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
22240 errdefer msg.destroy(gpa);22238 errdefer msg.destroy(gpa);
...@@ -22277,17 +22275,17 @@ fn reifyUnion(...@@ -22277,17 +22275,17 @@ fn reifyUnion(
22277 const new_namespace_index = try pt.createNamespace(.{22275 const new_namespace_index = try pt.createNamespace(.{
22278 .parent = block.namespace.toOptional(),22276 .parent = block.namespace.toOptional(),
22279 .owner_type = wip_ty.index,22277 .owner_type = wip_ty.index,
22280 .file_scope = block.getFileScopeIndex(mod),22278 .file_scope = block.getFileScopeIndex(zcu),
22281 .generation = mod.generation,22279 .generation = zcu.generation,
22282 });22280 });
2228322281
22284 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);22282 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 });
22287 codegen_type: {22285 codegen_type: {
22288 if (mod.comp.config.use_llvm) break :codegen_type;22286 if (zcu.comp.config.use_llvm) break :codegen_type;
22289 if (block.ownerModule().strip) break :codegen_type;22287 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 });
22291 }22289 }
22292 try sema.declareDependency(.{ .interned = wip_ty.index });22290 try sema.declareDependency(.{ .interned = wip_ty.index });
22293 try sema.addTypeReferenceEntry(src, wip_ty.index);22291 try sema.addTypeReferenceEntry(src, wip_ty.index);
...@@ -22306,13 +22304,13 @@ fn reifyStruct(...@@ -22306,13 +22304,13 @@ fn reifyStruct(
22306 is_tuple: bool,22304 is_tuple: bool,
22307) CompileError!Air.Inst.Ref {22305) CompileError!Air.Inst.Ref {
22308 const pt = sema.pt;22306 const pt = sema.pt;
22309 const mod = pt.zcu;22307 const zcu = pt.zcu;
22310 const gpa = sema.gpa;22308 const gpa = sema.gpa;
22311 const ip = &mod.intern_pool;22309 const ip = &zcu.intern_pool;
2231222310
22313 // This logic must stay in sync with the structure of `std.builtin.Type.Struct` - search for `fieldValue`.22311 // 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
22317 // The validation work here is non-trivial, and it's possible the type already exists.22315 // The validation work here is non-trivial, and it's possible the type already exists.
22318 // So in this first pass, let's just construct a hash to optimize for this case. If the22316 // So in this first pass, let's just construct a hash to optimize for this case. If the
...@@ -22343,7 +22341,7 @@ fn reifyStruct(...@@ -22343,7 +22341,7 @@ fn reifyStruct(
22343 .needed_comptime_reason = "struct field name must be comptime-known",22341 .needed_comptime_reason = "struct field name must be comptime-known",
22344 });22342 });
22345 const field_is_comptime = field_is_comptime_val.toBool();22343 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: {
22347 const ptr_ty = try pt.singleConstPtrType(field_type_val.toType());22345 const ptr_ty = try pt.singleConstPtrType(field_type_val.toType());
22348 // We need to do this deref here, so we won't check for this error case later on.22346 // We need to do this deref here, so we won't check for this error case later on.
22349 const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime(22347 const val = try sema.pointerDeref(block, src, ptr_val, ptr_ty) orelse return sema.failWithNeededComptime(
...@@ -22365,7 +22363,7 @@ fn reifyStruct(...@@ -22365,7 +22363,7 @@ fn reifyStruct(
2236522363
22366 if (field_is_comptime) any_comptime_fields = true;22364 if (field_is_comptime) any_comptime_fields = true;
22367 if (field_default_value != .none) any_default_inits = true;22365 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)) {
22369 .eq => {},22367 .eq => {},
22370 .gt => any_aligned_fields = true,22368 .gt => any_aligned_fields = true,
22371 .lt => unreachable,22369 .lt => unreachable,
...@@ -22475,7 +22473,7 @@ fn reifyStruct(...@@ -22475,7 +22473,7 @@ fn reifyStruct(
2247522473
22476 const field_default: InternPool.Index = d: {22474 const field_default: InternPool.Index = d: {
22477 if (!any_default_inits) break :d .none;22475 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;
22479 const ptr_ty = try pt.singleConstPtrType(field_ty);22477 const ptr_ty = try pt.singleConstPtrType(field_ty);
22480 // Asserted comptime-dereferencable above.22478 // Asserted comptime-dereferencable above.
22481 const val = (try sema.pointerDeref(block, src, ptr_val, ptr_ty)).?;22479 const val = (try sema.pointerDeref(block, src, ptr_val, ptr_ty)).?;
...@@ -22492,7 +22490,7 @@ fn reifyStruct(...@@ -22492,7 +22490,7 @@ fn reifyStruct(
22492 struct_type.field_inits.get(ip)[field_idx] = field_default;22490 struct_type.field_inits.get(ip)[field_idx] = field_default;
22493 }22491 }
2249422492
22495 if (field_ty.zigTypeTag(mod) == .Opaque) {22493 if (field_ty.zigTypeTag(zcu) == .Opaque) {
22496 return sema.failWithOwnedErrorMsg(block, msg: {22494 return sema.failWithOwnedErrorMsg(block, msg: {
22497 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});22495 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
22498 errdefer msg.destroy(gpa);22496 errdefer msg.destroy(gpa);
...@@ -22501,7 +22499,7 @@ fn reifyStruct(...@@ -22501,7 +22499,7 @@ fn reifyStruct(
22501 break :msg msg;22499 break :msg msg;
22502 });22500 });
22503 }22501 }
22504 if (field_ty.zigTypeTag(mod) == .NoReturn) {22502 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
22505 return sema.failWithOwnedErrorMsg(block, msg: {22503 return sema.failWithOwnedErrorMsg(block, msg: {
22506 const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{});22504 const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{});
22507 errdefer msg.destroy(gpa);22505 errdefer msg.destroy(gpa);
...@@ -22545,10 +22543,10 @@ fn reifyStruct(...@@ -22545,10 +22543,10 @@ fn reifyStruct(
22545 },22543 },
22546 else => return err,22544 else => return err,
22547 };22545 };
22548 fields_bit_sum += field_ty.bitSize(pt);22546 fields_bit_sum += field_ty.bitSize(zcu);
22549 }22547 }
2255022548
22551 if (opt_backing_int_val.optionalValue(mod)) |backing_int_val| {22549 if (opt_backing_int_val.optionalValue(zcu)) |backing_int_val| {
22552 const backing_int_ty = backing_int_val.toType();22550 const backing_int_ty = backing_int_val.toType();
22553 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);22551 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
22554 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());22552 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
...@@ -22561,17 +22559,17 @@ fn reifyStruct(...@@ -22561,17 +22559,17 @@ fn reifyStruct(
22561 const new_namespace_index = try pt.createNamespace(.{22559 const new_namespace_index = try pt.createNamespace(.{
22562 .parent = block.namespace.toOptional(),22560 .parent = block.namespace.toOptional(),
22563 .owner_type = wip_ty.index,22561 .owner_type = wip_ty.index,
22564 .file_scope = block.getFileScopeIndex(mod),22562 .file_scope = block.getFileScopeIndex(zcu),
22565 .generation = mod.generation,22563 .generation = zcu.generation,
22566 });22564 });
2256722565
22568 const new_cau_index = try ip.createTypeCau(gpa, pt.tid, tracked_inst, new_namespace_index, wip_ty.index);22566 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 });
22571 codegen_type: {22569 codegen_type: {
22572 if (mod.comp.config.use_llvm) break :codegen_type;22570 if (zcu.comp.config.use_llvm) break :codegen_type;
22573 if (block.ownerModule().strip) break :codegen_type;22571 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 });
22575 }22573 }
22576 try sema.declareDependency(.{ .interned = wip_ty.index });22574 try sema.declareDependency(.{ .interned = wip_ty.index });
22577 try sema.addTypeReferenceEntry(src, wip_ty.index);22575 try sema.addTypeReferenceEntry(src, wip_ty.index);
...@@ -22649,8 +22647,8 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -22649,8 +22647,8 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2264922647
22650fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22648fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22651 const pt = sema.pt;22649 const pt = sema.pt;
22652 const mod = pt.zcu;22650 const zcu = pt.zcu;
22653 const ip = &mod.intern_pool;22651 const ip = &zcu.intern_pool;
2265422652
22655 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;22653 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22656 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);22654 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...@@ -22674,7 +22672,7 @@ fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2267422672
22675fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22673fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22676 const pt = sema.pt;22674 const pt = sema.pt;
22677 const mod = pt.zcu;22675 const zcu = pt.zcu;
22678 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22676 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22679 const src = block.nodeOffset(inst_data.src_node);22677 const src = block.nodeOffset(inst_data.src_node);
22680 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22678 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...@@ -22684,10 +22682,10 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22684 const operand_ty = sema.typeOf(operand);22682 const operand_ty = sema.typeOf(operand);
2268522683
22686 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);22684 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);22687 const dest_scalar_ty = dest_ty.scalarType(zcu);
22690 const operand_scalar_ty = operand_ty.scalarType(mod);22688 const operand_scalar_ty = operand_ty.scalarType(zcu);
2269122689
22692 _ = try sema.checkIntType(block, src, dest_scalar_ty);22690 _ = try sema.checkIntType(block, src, dest_scalar_ty);
22693 try sema.checkFloatType(block, operand_src, operand_scalar_ty);22691 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
...@@ -22695,14 +22693,14 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22695,14 +22693,14 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22695 if (try sema.resolveValue(operand)) |operand_val| {22693 if (try sema.resolveValue(operand)) |operand_val| {
22696 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate);22694 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate);
22697 return Air.internedToRef(result_val.toIntern());22695 return Air.internedToRef(result_val.toIntern());
22698 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {22696 } else if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
22699 return sema.failWithNeededComptime(block, operand_src, .{22697 return sema.failWithNeededComptime(block, operand_src, .{
22700 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",22698 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
22701 });22699 });
22702 }22700 }
2270322701
22704 try sema.requireRuntimeBlock(block, src, operand_src);22702 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) {
22706 if (!is_vector) {22704 if (!is_vector) {
22707 if (block.wantSafety()) {22705 if (block.wantSafety()) {
22708 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()));22706 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...@@ -22711,7 +22709,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22711 return Air.internedToRef((try pt.intValue(dest_ty, 0)).toIntern());22709 return Air.internedToRef((try pt.intValue(dest_ty, 0)).toIntern());
22712 }22710 }
22713 if (block.wantSafety()) {22711 if (block.wantSafety()) {
22714 const len = dest_ty.vectorLen(mod);22712 const len = dest_ty.vectorLen(zcu);
22715 for (0..len) |i| {22713 for (0..len) |i| {
22716 const idx_ref = try pt.intRef(Type.usize, i);22714 const idx_ref = try pt.intRef(Type.usize, i);
22717 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);22715 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...@@ -22736,7 +22734,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22736 }22734 }
22737 return result;22735 return result;
22738 }22736 }
22739 const len = dest_ty.vectorLen(mod);22737 const len = dest_ty.vectorLen(zcu);
22740 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);22738 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22741 for (new_elems, 0..) |*new_elem, i| {22739 for (new_elems, 0..) |*new_elem, i| {
22742 const idx_ref = try pt.intRef(Type.usize, i);22740 const idx_ref = try pt.intRef(Type.usize, i);
...@@ -22757,7 +22755,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22757,7 +22755,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2275722755
22758fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22756fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22759 const pt = sema.pt;22757 const pt = sema.pt;
22760 const mod = pt.zcu;22758 const zcu = pt.zcu;
22761 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22759 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22762 const src = block.nodeOffset(inst_data.src_node);22760 const src = block.nodeOffset(inst_data.src_node);
22763 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22761 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...@@ -22767,10 +22765,10 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22767 const operand_ty = sema.typeOf(operand);22765 const operand_ty = sema.typeOf(operand);
2276822766
22769 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src);22767 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);22770 const dest_scalar_ty = dest_ty.scalarType(zcu);
22773 const operand_scalar_ty = operand_ty.scalarType(mod);22771 const operand_scalar_ty = operand_ty.scalarType(zcu);
2277422772
22775 try sema.checkFloatType(block, src, dest_scalar_ty);22773 try sema.checkFloatType(block, src, dest_scalar_ty);
22776 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);22774 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
...@@ -22778,7 +22776,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22778,7 +22776,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22778 if (try sema.resolveValue(operand)) |operand_val| {22776 if (try sema.resolveValue(operand)) |operand_val| {
22779 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, pt, .sema);22777 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, pt, .sema);
22780 return Air.internedToRef(result_val.toIntern());22778 return Air.internedToRef(result_val.toIntern());
22781 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) {22779 } else if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeFloat) {
22782 return sema.failWithNeededComptime(block, operand_src, .{22780 return sema.failWithNeededComptime(block, operand_src, .{
22783 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",22781 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
22784 });22782 });
...@@ -22788,7 +22786,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22788,7 +22786,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22788 if (!is_vector) {22786 if (!is_vector) {
22789 return block.addTyOp(.float_from_int, dest_ty, operand);22787 return block.addTyOp(.float_from_int, dest_ty, operand);
22790 }22788 }
22791 const len = operand_ty.vectorLen(mod);22789 const len = operand_ty.vectorLen(zcu);
22792 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);22790 const new_elems = try sema.arena.alloc(Air.Inst.Ref, len);
22793 for (new_elems, 0..) |*new_elem, i| {22791 for (new_elems, 0..) |*new_elem, i| {
22794 const idx_ref = try pt.intRef(Type.usize, i);22792 const idx_ref = try pt.intRef(Type.usize, i);
...@@ -22800,7 +22798,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22800,7 +22798,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2280022798
22801fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22799fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22802 const pt = sema.pt;22800 const pt = sema.pt;
22803 const mod = pt.zcu;22801 const zcu = pt.zcu;
22804 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22802 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22805 const src = block.nodeOffset(inst_data.src_node);22803 const src = block.nodeOffset(inst_data.src_node);
2280622804
...@@ -22813,21 +22811,21 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22813,21 +22811,21 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22813 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrFromInt");22811 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrFromInt");
22814 try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, uncoerced_operand_ty, src, operand_src);22812 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;
22817 const operand_ty = if (is_vector) operand_ty: {22815 const operand_ty = if (is_vector) operand_ty: {
22818 const len = dest_ty.vectorLen(mod);22816 const len = dest_ty.vectorLen(zcu);
22819 break :operand_ty try pt.vectorType(.{ .child = .usize_type, .len = len });22817 break :operand_ty try pt.vectorType(.{ .child = .usize_type, .len = len });
22820 } else Type.usize;22818 } else Type.usize;
2282122819
22822 const operand_coerced = try sema.coerce(block, operand_ty, operand_res, operand_src);22820 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);
22825 try sema.checkPtrType(block, src, ptr_ty, true);22823 try sema.checkPtrType(block, src, ptr_ty, true);
2282622824
22827 const elem_ty = ptr_ty.elemType2(mod);22825 const elem_ty = ptr_ty.elemType2(zcu);
22828 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(pt, .sema);22826 const ptr_align = try ptr_ty.ptrAlignmentSema(pt);
2282922827
22830 if (ptr_ty.isSlice(mod)) {22828 if (ptr_ty.isSlice(zcu)) {
22831 const msg = msg: {22829 const msg = msg: {
22832 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(pt)});22830 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(pt)});
22833 errdefer msg.destroy(sema.gpa);22831 errdefer msg.destroy(sema.gpa);
...@@ -22842,7 +22840,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22842,7 +22840,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22842 const ptr_val = try sema.ptrFromIntVal(block, operand_src, val, ptr_ty, ptr_align);22840 const ptr_val = try sema.ptrFromIntVal(block, operand_src, val, ptr_ty, ptr_align);
22843 return Air.internedToRef(ptr_val.toIntern());22841 return Air.internedToRef(ptr_val.toIntern());
22844 }22842 }
22845 const len = dest_ty.vectorLen(mod);22843 const len = dest_ty.vectorLen(zcu);
22846 const new_elems = try sema.arena.alloc(InternPool.Index, len);22844 const new_elems = try sema.arena.alloc(InternPool.Index, len);
22847 for (new_elems, 0..) |*new_elem, i| {22845 for (new_elems, 0..) |*new_elem, i| {
22848 const elem = try val.elemValue(pt, i);22846 const elem = try val.elemValue(pt, i);
...@@ -22854,7 +22852,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22854,7 +22852,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22854 .storage = .{ .elems = new_elems },22852 .storage = .{ .elems = new_elems },
22855 } }));22853 } }));
22856 }22854 }
22857 if (try sema.typeRequiresComptime(ptr_ty)) {22855 if (try ptr_ty.comptimeOnlySema(pt)) {
22858 return sema.failWithOwnedErrorMsg(block, msg: {22856 return sema.failWithOwnedErrorMsg(block, msg: {
22859 const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(pt)});22857 const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(pt)});
22860 errdefer msg.destroy(sema.gpa);22858 errdefer msg.destroy(sema.gpa);
...@@ -22865,8 +22863,8 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22865,8 +22863,8 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22865 }22863 }
22866 try sema.requireRuntimeBlock(block, src, operand_src);22864 try sema.requireRuntimeBlock(block, src, operand_src);
22867 if (!is_vector) {22865 if (!is_vector) {
22868 if (block.wantSafety() and (try sema.typeHasRuntimeBits(elem_ty) or elem_ty.zigTypeTag(mod) == .Fn)) {22866 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .Fn)) {
22869 if (!ptr_ty.isAllowzeroPtr(mod)) {22867 if (!ptr_ty.isAllowzeroPtr(zcu)) {
22870 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);22868 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
22871 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);22869 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
22872 }22870 }
...@@ -22881,12 +22879,12 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22881,12 +22879,12 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22881 return block.addBitCast(dest_ty, operand_coerced);22879 return block.addBitCast(dest_ty, operand_coerced);
22882 }22880 }
2288322881
22884 const len = dest_ty.vectorLen(mod);22882 const len = dest_ty.vectorLen(zcu);
22885 if (block.wantSafety() and (try sema.typeHasRuntimeBits(elem_ty) or elem_ty.zigTypeTag(mod) == .Fn)) {22883 if (block.wantSafety() and (try elem_ty.hasRuntimeBitsSema(pt) or elem_ty.zigTypeTag(zcu) == .Fn)) {
22886 for (0..len) |i| {22884 for (0..len) |i| {
22887 const idx_ref = try pt.intRef(Type.usize, i);22885 const idx_ref = try pt.intRef(Type.usize, i);
22888 const elem_coerced = try block.addBinOp(.array_elem_val, operand_coerced, idx_ref);22886 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)) {
22890 const is_non_zero = try block.addBinOp(.cmp_neq, elem_coerced, .zero_usize);22888 const is_non_zero = try block.addBinOp(.cmp_neq, elem_coerced, .zero_usize);
22891 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);22889 try sema.addSafetyCheck(block, src, is_non_zero, .cast_to_null);
22892 }22890 }
...@@ -22943,16 +22941,16 @@ fn ptrFromIntVal(...@@ -22943,16 +22941,16 @@ fn ptrFromIntVal(
2294322941
22944fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22942fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22945 const pt = sema.pt;22943 const pt = sema.pt;
22946 const mod = pt.zcu;22944 const zcu = pt.zcu;
22947 const ip = &mod.intern_pool;22945 const ip = &zcu.intern_pool;
22948 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;22946 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22949 const src = block.nodeOffset(extra.node);22947 const src = block.nodeOffset(extra.node);
22950 const operand_src = block.builtinCallArgSrc(extra.node, 0);22948 const operand_src = block.builtinCallArgSrc(extra.node, 0);
22951 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");22949 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");
22952 const operand = try sema.resolveInst(extra.rhs);22950 const operand = try sema.resolveInst(extra.rhs);
22953 const base_operand_ty = sema.typeOf(operand);22951 const base_operand_ty = sema.typeOf(operand);
22954 const dest_tag = base_dest_ty.zigTypeTag(mod);22952 const dest_tag = base_dest_ty.zigTypeTag(zcu);
22955 const operand_tag = base_operand_ty.zigTypeTag(mod);22953 const operand_tag = base_operand_ty.zigTypeTag(zcu);
2295622954
22957 if (dest_tag != .ErrorSet and dest_tag != .ErrorUnion) {22955 if (dest_tag != .ErrorSet and dest_tag != .ErrorUnion) {
22958 return sema.fail(block, src, "expected error set or error union type, found '{s}'", .{@tagName(dest_tag)});22956 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...@@ -22964,13 +22962,13 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
22964 return sema.fail(block, src, "cannot cast an error union type to error set", .{});22962 return sema.fail(block, src, "cannot cast an error union type to error set", .{});
22965 }22963 }
22966 if (dest_tag == .ErrorUnion and operand_tag == .ErrorUnion and22964 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())
22968 {22966 {
22969 return sema.failWithOwnedErrorMsg(block, msg: {22967 return sema.failWithOwnedErrorMsg(block, msg: {
22970 const msg = try sema.errMsg(src, "payload types of error unions must match", .{});22968 const msg = try sema.errMsg(src, "payload types of error unions must match", .{});
22971 errdefer msg.destroy(sema.gpa);22969 errdefer msg.destroy(sema.gpa);
22972 const dest_ty = base_dest_ty.errorUnionPayload(mod);22970 const dest_ty = base_dest_ty.errorUnionPayload(zcu);
22973 const operand_ty = base_operand_ty.errorUnionPayload(mod);22971 const operand_ty = base_operand_ty.errorUnionPayload(zcu);
22974 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(pt)});22972 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(pt)});
22975 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(pt)});22973 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(pt)});
22976 try addDeclaredHereNote(sema, msg, dest_ty);22974 try addDeclaredHereNote(sema, msg, dest_ty);
...@@ -22978,19 +22976,19 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -22978,19 +22976,19 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
22978 break :msg msg;22976 break :msg msg;
22979 });22977 });
22980 }22978 }
22981 const dest_ty = if (dest_tag == .ErrorUnion) base_dest_ty.errorUnionSet(mod) else base_dest_ty;22979 const dest_ty = if (dest_tag == .ErrorUnion) base_dest_ty.errorUnionSet(zcu) else base_dest_ty;
22982 const operand_ty = if (operand_tag == .ErrorUnion) base_operand_ty.errorUnionSet(mod) else base_operand_ty;22980 const operand_ty = if (operand_tag == .ErrorUnion) base_operand_ty.errorUnionSet(zcu) else base_operand_ty;
2298322981
22984 // operand must be defined since it can be an invalid error value22982 // operand must be defined since it can be an invalid error value
22985 const maybe_operand_val = try sema.resolveDefinedValue(block, operand_src, operand);22983 const maybe_operand_val = try sema.resolveDefinedValue(block, operand_src, operand);
2298622984
22987 const disjoint = disjoint: {22985 const disjoint = disjoint: {
22988 // Try avoiding resolving inferred error sets if we can22986 // Try avoiding resolving inferred error sets if we can
22989 if (!dest_ty.isAnyError(mod) and dest_ty.errorSetIsEmpty(mod)) break :disjoint true;22987 if (!dest_ty.isAnyError(zcu) and dest_ty.errorSetIsEmpty(zcu)) break :disjoint true;
22990 if (!operand_ty.isAnyError(mod) and operand_ty.errorSetIsEmpty(mod)) break :disjoint true;22988 if (!operand_ty.isAnyError(zcu) and operand_ty.errorSetIsEmpty(zcu)) break :disjoint true;
22991 if (dest_ty.isAnyError(mod)) break :disjoint false;22989 if (dest_ty.isAnyError(zcu)) break :disjoint false;
22992 if (operand_ty.isAnyError(mod)) break :disjoint false;22990 if (operand_ty.isAnyError(zcu)) break :disjoint false;
22993 const dest_err_names = dest_ty.errorSetNames(mod);22991 const dest_err_names = dest_ty.errorSetNames(zcu);
22994 for (0..dest_err_names.len) |dest_err_index| {22992 for (0..dest_err_names.len) |dest_err_index| {
22995 if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_names.get(ip)[dest_err_index]))22993 if (Type.errorSetHasFieldIp(ip, operand_ty.toIntern(), dest_err_names.get(ip)[dest_err_index]))
22996 break :disjoint false;22994 break :disjoint false;
...@@ -23018,8 +23016,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -23018,8 +23016,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
23018 }23016 }
2301923017
23020 if (maybe_operand_val) |val| {23018 if (maybe_operand_val) |val| {
23021 if (!dest_ty.isAnyError(mod)) check: {23019 if (!dest_ty.isAnyError(zcu)) check: {
23022 const operand_val = mod.intern_pool.indexToKey(val.toIntern());23020 const operand_val = zcu.intern_pool.indexToKey(val.toIntern());
23023 var error_name: InternPool.NullTerminatedString = undefined;23021 var error_name: InternPool.NullTerminatedString = undefined;
23024 if (operand_tag == .ErrorUnion) {23022 if (operand_tag == .ErrorUnion) {
23025 if (operand_val.error_union.val != .err_name) break :check;23023 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...@@ -23039,9 +23037,9 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2303923037
23040 try sema.requireRuntimeBlock(block, src, operand_src);23038 try sema.requireRuntimeBlock(block, src, operand_src);
23041 const err_int_ty = try pt.errorIntType();23039 const err_int_ty = try pt.errorIntType();
23042 if (block.wantSafety() and !dest_ty.isAnyError(mod) and23040 if (block.wantSafety() and !dest_ty.isAnyError(zcu) and
23043 dest_ty.toIntern() != .adhoc_inferred_error_set_type and23041 dest_ty.toIntern() != .adhoc_inferred_error_set_type and
23044 mod.backendSupportsFeature(.error_set_has_value))23042 zcu.backendSupportsFeature(.error_set_has_value))
23045 {23043 {
23046 if (dest_tag == .ErrorUnion) {23044 if (dest_tag == .ErrorUnion) {
23047 const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand);23045 const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand);
...@@ -23116,23 +23114,23 @@ fn ptrCastFull(...@@ -23116,23 +23114,23 @@ fn ptrCastFull(
23116 operation: []const u8,23114 operation: []const u8,
23117) CompileError!Air.Inst.Ref {23115) CompileError!Air.Inst.Ref {
23118 const pt = sema.pt;23116 const pt = sema.pt;
23119 const mod = pt.zcu;23117 const zcu = pt.zcu;
23120 const operand_ty = sema.typeOf(operand);23118 const operand_ty = sema.typeOf(operand);
2312123119
23122 try sema.checkPtrType(block, src, dest_ty, true);23120 try sema.checkPtrType(block, src, dest_ty, true);
23123 try sema.checkPtrOperand(block, operand_src, operand_ty);23121 try sema.checkPtrOperand(block, operand_src, operand_ty);
2312423122
23125 const src_info = operand_ty.ptrInfo(mod);23123 const src_info = operand_ty.ptrInfo(zcu);
23126 const dest_info = dest_ty.ptrInfo(mod);23124 const dest_info = dest_ty.ptrInfo(zcu);
2312723125
23128 try Type.fromInterned(src_info.child).resolveLayout(pt);23126 try Type.fromInterned(src_info.child).resolveLayout(pt);
23129 try Type.fromInterned(dest_info.child).resolveLayout(pt);23127 try Type.fromInterned(dest_info.child).resolveLayout(pt);
2313023128
23131 const src_slice_like = src_info.flags.size == .Slice or23129 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
23134 const dest_slice_like = dest_info.flags.size == .Slice or23132 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
23137 if (dest_info.flags.size == .Slice and !src_slice_like) {23135 if (dest_info.flags.size == .Slice and !src_slice_like) {
23138 return sema.fail(block, src, "illegal pointer cast to slice", .{});23136 return sema.fail(block, src, "illegal pointer cast to slice", .{});
...@@ -23140,12 +23138,12 @@ fn ptrCastFull(...@@ -23140,12 +23138,12 @@ fn ptrCastFull(
2314023138
23141 if (dest_info.flags.size == .Slice) {23139 if (dest_info.flags.size == .Slice) {
23142 const src_elem_size = switch (src_info.flags.size) {23140 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),
23144 // pointer to array23142 // 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),
23146 else => unreachable,23144 else => unreachable,
23147 };23145 };
23148 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(pt);23146 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(zcu);
23149 if (src_elem_size != dest_elem_size) {23147 if (src_elem_size != dest_elem_size) {
23150 return sema.fail(block, src, "TODO: implement {s} between slices changing the length", .{operation});23148 return sema.fail(block, src, "TODO: implement {s} between slices changing the length", .{operation});
23151 }23149 }
...@@ -23167,7 +23165,7 @@ fn ptrCastFull(...@@ -23167,7 +23165,7 @@ fn ptrCastFull(
23167 errdefer msg.destroy(sema.gpa);23165 errdefer msg.destroy(sema.gpa);
23168 if (dest_info.flags.size == .Many and23166 if (dest_info.flags.size == .Many and
23169 (src_info.flags.size == .Slice or23167 (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)))
23171 {23169 {
23172 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});23170 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});
23173 } else {23171 } else {
...@@ -23180,7 +23178,7 @@ fn ptrCastFull(...@@ -23180,7 +23178,7 @@ fn ptrCastFull(
23180 check_child: {23178 check_child: {
23181 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {23179 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {
23182 // *[n]T -> []T23180 // *[n]T -> []T
23183 break :blk Type.fromInterned(src_info.child).childType(mod);23181 break :blk Type.fromInterned(src_info.child).childType(zcu);
23184 } else Type.fromInterned(src_info.child);23182 } else Type.fromInterned(src_info.child);
2318523183
23186 const dest_child = Type.fromInterned(dest_info.child);23184 const dest_child = Type.fromInterned(dest_info.child);
...@@ -23190,7 +23188,7 @@ fn ptrCastFull(...@@ -23190,7 +23188,7 @@ fn ptrCastFull(
23190 dest_child,23188 dest_child,
23191 src_child,23189 src_child,
23192 !dest_info.flags.is_const,23190 !dest_info.flags.is_const,
23193 mod.getTarget(),23191 zcu.getTarget(),
23194 src,23192 src,
23195 operand_src,23193 operand_src,
23196 null,23194 null,
...@@ -23211,14 +23209,14 @@ fn ptrCastFull(...@@ -23211,14 +23209,14 @@ fn ptrCastFull(
23211 if (dest_info.sentinel == .none) break :check_sent;23209 if (dest_info.sentinel == .none) break :check_sent;
23212 if (src_info.flags.size == .C) break :check_sent;23210 if (src_info.flags.size == .C) break :check_sent;
23213 if (src_info.sentinel != .none) {23211 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);
23215 if (dest_info.sentinel == coerced_sent) break :check_sent;23213 if (dest_info.sentinel == coerced_sent) break :check_sent;
23216 }23214 }
23217 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {23215 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {
23218 // [*]nT -> []T23216 // [*]nT -> []T
23219 const arr_ty = Type.fromInterned(src_info.child);23217 const arr_ty = Type.fromInterned(src_info.child);
23220 if (arr_ty.sentinel(mod)) |src_sentinel| {23218 if (arr_ty.sentinel(zcu)) |src_sentinel| {
23221 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);23219 const coerced_sent = try zcu.intern_pool.getCoerced(sema.gpa, pt.tid, src_sentinel.toIntern(), dest_info.child);
23222 if (dest_info.sentinel == coerced_sent) break :check_sent;23220 if (dest_info.sentinel == coerced_sent) break :check_sent;
23223 }23221 }
23224 }23222 }
...@@ -23264,8 +23262,8 @@ fn ptrCastFull(...@@ -23264,8 +23262,8 @@ fn ptrCastFull(
23264 }23262 }
2326523263
23266 check_allowzero: {23264 check_allowzero: {
23267 const src_allows_zero = operand_ty.ptrAllowsZero(mod);23265 const src_allows_zero = operand_ty.ptrAllowsZero(zcu);
23268 const dest_allows_zero = dest_ty.ptrAllowsZero(mod);23266 const dest_allows_zero = dest_ty.ptrAllowsZero(zcu);
23269 if (!src_allows_zero) break :check_allowzero;23267 if (!src_allows_zero) break :check_allowzero;
23270 if (dest_allows_zero) break :check_allowzero;23268 if (dest_allows_zero) break :check_allowzero;
2327123269
...@@ -23286,12 +23284,12 @@ fn ptrCastFull(...@@ -23286,12 +23284,12 @@ fn ptrCastFull(
23286 const src_align = if (src_info.flags.alignment != .none)23284 const src_align = if (src_info.flags.alignment != .none)
23287 src_info.flags.alignment23285 src_info.flags.alignment
23288 else23286 else
23289 Type.fromInterned(src_info.child).abiAlignment(pt);23287 Type.fromInterned(src_info.child).abiAlignment(zcu);
2329023288
23291 const dest_align = if (dest_info.flags.alignment != .none)23289 const dest_align = if (dest_info.flags.alignment != .none)
23292 dest_info.flags.alignment23290 dest_info.flags.alignment
23293 else23291 else
23294 Type.fromInterned(dest_info.child).abiAlignment(pt);23292 Type.fromInterned(dest_info.child).abiAlignment(zcu);
2329523293
23296 if (!flags.align_cast) {23294 if (!flags.align_cast) {
23297 if (dest_align.compare(.gt, src_align)) {23295 if (dest_align.compare(.gt, src_align)) {
...@@ -23327,7 +23325,7 @@ fn ptrCastFull(...@@ -23327,7 +23325,7 @@ fn ptrCastFull(
23327 }23325 }
23328 } else {23326 } else {
23329 // Some address space casts are always disallowed23327 // 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)) {
23331 return sema.failWithOwnedErrorMsg(block, msg: {23329 return sema.failWithOwnedErrorMsg(block, msg: {
23332 const msg = try sema.errMsg(src, "invalid address space cast", .{});23330 const msg = try sema.errMsg(src, "invalid address space cast", .{});
23333 errdefer msg.destroy(sema.gpa);23331 errdefer msg.destroy(sema.gpa);
...@@ -23363,7 +23361,7 @@ fn ptrCastFull(...@@ -23363,7 +23361,7 @@ fn ptrCastFull(
23363 }23361 }
2336423362
23365 const ptr = if (src_info.flags.size == .Slice and dest_info.flags.size != .Slice) ptr: {23363 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) {
23367 break :ptr try sema.analyzeOptionalSlicePtr(block, operand_src, operand, operand_ty);23365 break :ptr try sema.analyzeOptionalSlicePtr(block, operand_src, operand, operand_ty);
23368 } else {23366 } else {
23369 break :ptr try sema.analyzeSlicePtr(block, operand_src, operand, operand_ty);23367 break :ptr try sema.analyzeSlicePtr(block, operand_src, operand, operand_ty);
...@@ -23375,7 +23373,7 @@ fn ptrCastFull(...@@ -23375,7 +23373,7 @@ fn ptrCastFull(
23375 var info = dest_info;23373 var info = dest_info;
23376 info.flags.size = .Many;23374 info.flags.size = .Many;
23377 const ty = try pt.ptrTypeSema(info);23375 const ty = try pt.ptrTypeSema(info);
23378 if (dest_ty.zigTypeTag(mod) == .Optional) {23376 if (dest_ty.zigTypeTag(zcu) == .Optional) {
23379 break :blk try pt.optionalType(ty.toIntern());23377 break :blk try pt.optionalType(ty.toIntern());
23380 } else {23378 } else {
23381 break :blk ty;23379 break :blk ty;
...@@ -23385,14 +23383,14 @@ fn ptrCastFull(...@@ -23385,14 +23383,14 @@ fn ptrCastFull(
23385 // Cannot do @addrSpaceCast at comptime23383 // Cannot do @addrSpaceCast at comptime
23386 if (!flags.addrspace_cast) {23384 if (!flags.addrspace_cast) {
23387 if (try sema.resolveValue(ptr)) |ptr_val| {23385 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)) {
23389 return sema.failWithUseOfUndef(block, operand_src);23387 return sema.failWithUseOfUndef(block, operand_src);
23390 }23388 }
23391 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isNull(mod)) {23389 if (!dest_ty.ptrAllowsZero(zcu) and ptr_val.isNull(zcu)) {
23392 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});23390 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});
23393 }23391 }
23394 if (dest_align.compare(.gt, src_align)) {23392 if (dest_align.compare(.gt, src_align)) {
23395 if (try ptr_val.getUnsignedIntAdvanced(pt, .sema)) |addr| {23393 if (try ptr_val.getUnsignedIntSema(pt)) |addr| {
23396 if (!dest_align.check(addr)) {23394 if (!dest_align.check(addr)) {
23397 return sema.fail(block, operand_src, "pointer address 0x{X} is not aligned to {d} bytes", .{23395 return sema.fail(block, operand_src, "pointer address 0x{X} is not aligned to {d} bytes", .{
23398 addr,23396 addr,
...@@ -23402,20 +23400,20 @@ fn ptrCastFull(...@@ -23402,20 +23400,20 @@ fn ptrCastFull(
23402 }23400 }
23403 }23401 }
23404 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {23402 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
23405 if (ptr_val.isUndef(mod)) return pt.undefRef(dest_ty);23403 if (ptr_val.isUndef(zcu)) return pt.undefRef(dest_ty);
23406 const arr_len = try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(mod));23404 const arr_len = try pt.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(zcu));
23407 const ptr_val_key = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr;23405 const ptr_val_key = zcu.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
23408 return Air.internedToRef((try pt.intern(.{ .slice = .{23406 return Air.internedToRef((try pt.intern(.{ .slice = .{
23409 .ty = dest_ty.toIntern(),23407 .ty = dest_ty.toIntern(),
23410 .ptr = try pt.intern(.{ .ptr = .{23408 .ptr = try pt.intern(.{ .ptr = .{
23411 .ty = dest_ty.slicePtrFieldType(mod).toIntern(),23409 .ty = dest_ty.slicePtrFieldType(zcu).toIntern(),
23412 .base_addr = ptr_val_key.base_addr,23410 .base_addr = ptr_val_key.base_addr,
23413 .byte_offset = ptr_val_key.byte_offset,23411 .byte_offset = ptr_val_key.byte_offset,
23414 } }),23412 } }),
23415 .len = arr_len.toIntern(),23413 .len = arr_len.toIntern(),
23416 } })));23414 } })));
23417 } else {23415 } else {
23418 assert(dest_ptr_ty.eql(dest_ty, mod));23416 assert(dest_ptr_ty.eql(dest_ty, zcu));
23419 return Air.internedToRef((try pt.getCoerced(ptr_val, dest_ty)).toIntern());23417 return Air.internedToRef((try pt.getCoerced(ptr_val, dest_ty)).toIntern());
23420 }23418 }
23421 }23419 }
...@@ -23424,8 +23422,8 @@ fn ptrCastFull(...@@ -23424,8 +23422,8 @@ fn ptrCastFull(
23424 try sema.requireRuntimeBlock(block, src, null);23422 try sema.requireRuntimeBlock(block, src, null);
23425 try sema.validateRuntimeValue(block, operand_src, ptr);23423 try sema.validateRuntimeValue(block, operand_src, ptr);
2342623424
23427 if (block.wantSafety() and operand_ty.ptrAllowsZero(mod) and !dest_ty.ptrAllowsZero(mod) and23425 if (block.wantSafety() and operand_ty.ptrAllowsZero(zcu) and !dest_ty.ptrAllowsZero(zcu) and
23428 (try sema.typeHasRuntimeBits(Type.fromInterned(dest_info.child)) or Type.fromInterned(dest_info.child).zigTypeTag(mod) == .Fn))23426 (try Type.fromInterned(dest_info.child).hasRuntimeBitsSema(pt) or Type.fromInterned(dest_info.child).zigTypeTag(zcu) == .Fn))
23429 {23427 {
23430 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);23428 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
23431 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);23429 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
...@@ -23439,7 +23437,7 @@ fn ptrCastFull(...@@ -23439,7 +23437,7 @@ fn ptrCastFull(
2343923437
23440 if (block.wantSafety() and23438 if (block.wantSafety() and
23441 dest_align.compare(.gt, src_align) and23439 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))
23443 {23441 {
23444 const align_bytes_minus_1 = dest_align.toByteUnits().? - 1;23442 const align_bytes_minus_1 = dest_align.toByteUnits().? - 1;
23445 const align_minus_1 = Air.internedToRef((try pt.intValue(Type.usize, align_bytes_minus_1)).toIntern());23443 const align_minus_1 = Air.internedToRef((try pt.intValue(Type.usize, align_bytes_minus_1)).toIntern());
...@@ -23460,7 +23458,7 @@ fn ptrCastFull(...@@ -23460,7 +23458,7 @@ fn ptrCastFull(
23460 var intermediate_info = src_info;23458 var intermediate_info = src_info;
23461 intermediate_info.flags.address_space = dest_info.flags.address_space;23459 intermediate_info.flags.address_space = dest_info.flags.address_space;
23462 const intermediate_ptr_ty = try pt.ptrTypeSema(intermediate_info);23460 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: {
23464 break :blk try pt.optionalType(intermediate_ptr_ty.toIntern());23462 break :blk try pt.optionalType(intermediate_ptr_ty.toIntern());
23465 } else intermediate_ptr_ty;23463 } else intermediate_ptr_ty;
23466 const intermediate = try block.addInst(.{23464 const intermediate = try block.addInst(.{
...@@ -23470,7 +23468,7 @@ fn ptrCastFull(...@@ -23470,7 +23468,7 @@ fn ptrCastFull(
23470 .operand = ptr,23468 .operand = ptr,
23471 } },23469 } },
23472 });23470 });
23473 if (intermediate_ty.eql(dest_ptr_ty, mod)) {23471 if (intermediate_ty.eql(dest_ptr_ty, zcu)) {
23474 // We only changed the address space, so no need for a bitcast23472 // We only changed the address space, so no need for a bitcast
23475 break :ptr intermediate;23473 break :ptr intermediate;
23476 }23474 }
...@@ -23482,7 +23480,7 @@ fn ptrCastFull(...@@ -23482,7 +23480,7 @@ fn ptrCastFull(
23482 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {23480 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
23483 // We have to construct a slice using the operand's child's array length23481 // We have to construct a slice using the operand's child's array length
23484 // Note that we know from the check at the start of the function that operand_ty is slice-like23482 // 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());
23486 return block.addInst(.{23484 return block.addInst(.{
23487 .tag = .slice,23485 .tag = .slice,
23488 .data = .{ .ty_pl = .{23486 .data = .{ .ty_pl = .{
...@@ -23494,7 +23492,7 @@ fn ptrCastFull(...@@ -23494,7 +23492,7 @@ fn ptrCastFull(
23494 } },23492 } },
23495 });23493 });
23496 } else {23494 } else {
23497 assert(dest_ptr_ty.eql(dest_ty, mod));23495 assert(dest_ptr_ty.eql(dest_ty, zcu));
23498 try sema.checkKnownAllocPtr(block, operand, result_ptr);23496 try sema.checkKnownAllocPtr(block, operand, result_ptr);
23499 return result_ptr;23497 return result_ptr;
23500 }23498 }
...@@ -23502,7 +23500,7 @@ fn ptrCastFull(...@@ -23502,7 +23500,7 @@ fn ptrCastFull(
2350223500
23503fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {23501fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
23504 const pt = sema.pt;23502 const pt = sema.pt;
23505 const mod = pt.zcu;23503 const zcu = pt.zcu;
23506 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;23504 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
23507 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));23505 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
23508 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;23506 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...@@ -23512,13 +23510,13 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
23512 const operand_ty = sema.typeOf(operand);23510 const operand_ty = sema.typeOf(operand);
23513 try sema.checkPtrOperand(block, operand_src, operand_ty);23511 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);
23516 if (flags.const_cast) ptr_info.flags.is_const = false;23514 if (flags.const_cast) ptr_info.flags.is_const = false;
23517 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;23515 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;
2351823516
23519 const dest_ty = blk: {23517 const dest_ty = blk: {
23520 const dest_ty = try pt.ptrTypeSema(ptr_info);23518 const dest_ty = try pt.ptrTypeSema(ptr_info);
23521 if (operand_ty.zigTypeTag(mod) == .Optional) {23519 if (operand_ty.zigTypeTag(zcu) == .Optional) {
23522 break :blk try pt.optionalType(dest_ty.toIntern());23520 break :blk try pt.optionalType(dest_ty.toIntern());
23523 }23521 }
23524 break :blk dest_ty;23522 break :blk dest_ty;
...@@ -23536,7 +23534,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -23536,7 +23534,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2353623534
23537fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23535fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23538 const pt = sema.pt;23536 const pt = sema.pt;
23539 const mod = pt.zcu;23537 const zcu = pt.zcu;
23540 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;23538 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23541 const src = block.nodeOffset(inst_data.src_node);23539 const src = block.nodeOffset(inst_data.src_node);
23542 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);23540 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...@@ -23547,24 +23545,24 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23547 const operand_ty = sema.typeOf(operand);23545 const operand_ty = sema.typeOf(operand);
23548 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);23546 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
2354923547
23550 const operand_is_vector = operand_ty.zigTypeTag(mod) == .Vector;23548 const operand_is_vector = operand_ty.zigTypeTag(zcu) == .Vector;
23551 const dest_is_vector = dest_ty.zigTypeTag(mod) == .Vector;23549 const dest_is_vector = dest_ty.zigTypeTag(zcu) == .Vector;
23552 if (operand_is_vector != dest_is_vector) {23550 if (operand_is_vector != dest_is_vector) {
23553 return sema.fail(block, operand_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(pt), operand_ty.fmt(pt) });23551 return sema.fail(block, operand_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(pt), operand_ty.fmt(pt) });
23554 }23552 }
2355523553
23556 if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {23554 if (dest_scalar_ty.zigTypeTag(zcu) == .ComptimeInt) {
23557 return sema.coerce(block, dest_ty, operand, operand_src);23555 return sema.coerce(block, dest_ty, operand, operand_src);
23558 }23556 }
2355923557
23560 const dest_info = dest_scalar_ty.intInfo(mod);23558 const dest_info = dest_scalar_ty.intInfo(zcu);
2356123559
23562 if (try sema.typeHasOnePossibleValue(dest_ty)) |val| {23560 if (try sema.typeHasOnePossibleValue(dest_ty)) |val| {
23563 return Air.internedToRef(val.toIntern());23561 return Air.internedToRef(val.toIntern());
23564 }23562 }
2356523563
23566 if (operand_scalar_ty.zigTypeTag(mod) != .ComptimeInt) {23564 if (operand_scalar_ty.zigTypeTag(zcu) != .ComptimeInt) {
23567 const operand_info = operand_ty.intInfo(mod);23565 const operand_info = operand_ty.intInfo(zcu);
23568 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {23566 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
23569 return Air.internedToRef(val.toIntern());23567 return Air.internedToRef(val.toIntern());
23570 }23568 }
...@@ -23595,14 +23593,14 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23595,14 +23593,14 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23595 }23593 }
2359623594
23597 if (try sema.resolveValueIntable(operand)) |val| {23595 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);
23599 if (!dest_is_vector) {23597 if (!dest_is_vector) {
23600 return Air.internedToRef((try pt.getCoerced(23598 return Air.internedToRef((try pt.getCoerced(
23601 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, pt),23599 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, pt),
23602 dest_ty,23600 dest_ty,
23603 )).toIntern());23601 )).toIntern());
23604 }23602 }
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));
23606 for (elems, 0..) |*elem, i| {23604 for (elems, 0..) |*elem, i| {
23607 const elem_val = try val.elemValue(pt, i);23605 const elem_val = try val.elemValue(pt, i);
23608 const uncoerced_elem = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, pt);23606 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(...@@ -23623,38 +23621,38 @@ fn zirBitCount(
23623 block: *Block,23621 block: *Block,
23624 inst: Zir.Inst.Index,23622 inst: Zir.Inst.Index,
23625 air_tag: Air.Inst.Tag,23623 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,
23627) CompileError!Air.Inst.Ref {23625) CompileError!Air.Inst.Ref {
23628 const pt = sema.pt;23626 const pt = sema.pt;
23629 const mod = pt.zcu;23627 const zcu = pt.zcu;
23630 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23628 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23631 const src = block.nodeOffset(inst_data.src_node);23629 const src = block.nodeOffset(inst_data.src_node);
23632 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);23630 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23633 const operand = try sema.resolveInst(inst_data.operand);23631 const operand = try sema.resolveInst(inst_data.operand);
23634 const operand_ty = sema.typeOf(operand);23632 const operand_ty = sema.typeOf(operand);
23635 _ = try sema.checkIntOrVector(block, operand, operand_src);23633 _ = try sema.checkIntOrVector(block, operand, operand_src);
23636 const bits = operand_ty.intInfo(mod).bits;23634 const bits = operand_ty.intInfo(zcu).bits;
2363723635
23638 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {23636 if (try sema.typeHasOnePossibleValue(operand_ty)) |val| {
23639 return Air.internedToRef(val.toIntern());23637 return Air.internedToRef(val.toIntern());
23640 }23638 }
2364123639
23642 const result_scalar_ty = try pt.smallestUnsignedInt(bits);23640 const result_scalar_ty = try pt.smallestUnsignedInt(bits);
23643 switch (operand_ty.zigTypeTag(mod)) {23641 switch (operand_ty.zigTypeTag(zcu)) {
23644 .Vector => {23642 .Vector => {
23645 const vec_len = operand_ty.vectorLen(mod);23643 const vec_len = operand_ty.vectorLen(zcu);
23646 const result_ty = try pt.vectorType(.{23644 const result_ty = try pt.vectorType(.{
23647 .len = vec_len,23645 .len = vec_len,
23648 .child = result_scalar_ty.toIntern(),23646 .child = result_scalar_ty.toIntern(),
23649 });23647 });
23650 if (try sema.resolveValue(operand)) |val| {23648 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
23653 const elems = try sema.arena.alloc(InternPool.Index, vec_len);23651 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);
23655 for (elems, 0..) |*elem, i| {23653 for (elems, 0..) |*elem, i| {
23656 const elem_val = try val.elemValue(pt, i);23654 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);
23658 elem.* = (try pt.intValue(result_scalar_ty, count)).toIntern();23656 elem.* = (try pt.intValue(result_scalar_ty, count)).toIntern();
23659 }23657 }
23660 return Air.internedToRef((try pt.intern(.{ .aggregate = .{23658 return Air.internedToRef((try pt.intern(.{ .aggregate = .{
...@@ -23668,8 +23666,8 @@ fn zirBitCount(...@@ -23668,8 +23666,8 @@ fn zirBitCount(
23668 },23666 },
23669 .Int => {23667 .Int => {
23670 if (try sema.resolveValueResolveLazy(operand)) |val| {23668 if (try sema.resolveValueResolveLazy(operand)) |val| {
23671 if (val.isUndef(mod)) return pt.undefRef(result_scalar_ty);23669 if (val.isUndef(zcu)) return pt.undefRef(result_scalar_ty);
23672 return pt.intRef(result_scalar_ty, comptimeOp(val, operand_ty, pt));23670 return pt.intRef(result_scalar_ty, comptimeOp(val, operand_ty, zcu));
23673 } else {23671 } else {
23674 try sema.requireRuntimeBlock(block, src, operand_src);23672 try sema.requireRuntimeBlock(block, src, operand_src);
23675 return block.addTyOp(air_tag, result_scalar_ty, operand);23673 return block.addTyOp(air_tag, result_scalar_ty, operand);
...@@ -23681,14 +23679,14 @@ fn zirBitCount(...@@ -23681,14 +23679,14 @@ fn zirBitCount(
2368123679
23682fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23680fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23683 const pt = sema.pt;23681 const pt = sema.pt;
23684 const mod = pt.zcu;23682 const zcu = pt.zcu;
23685 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23683 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23686 const src = block.nodeOffset(inst_data.src_node);23684 const src = block.nodeOffset(inst_data.src_node);
23687 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);23685 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23688 const operand = try sema.resolveInst(inst_data.operand);23686 const operand = try sema.resolveInst(inst_data.operand);
23689 const operand_ty = sema.typeOf(operand);23687 const operand_ty = sema.typeOf(operand);
23690 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);23688 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;
23692 if (bits % 8 != 0) {23690 if (bits % 8 != 0) {
23693 return sema.fail(23691 return sema.fail(
23694 block,23692 block,
...@@ -23702,10 +23700,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23702,10 +23700,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23702 return Air.internedToRef(val.toIntern());23700 return Air.internedToRef(val.toIntern());
23703 }23701 }
2370423702
23705 switch (operand_ty.zigTypeTag(mod)) {23703 switch (operand_ty.zigTypeTag(zcu)) {
23706 .Int => {23704 .Int => {
23707 const runtime_src = if (try sema.resolveValue(operand)) |val| {23705 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);
23709 const result_val = try val.byteSwap(operand_ty, pt, sema.arena);23707 const result_val = try val.byteSwap(operand_ty, pt, sema.arena);
23710 return Air.internedToRef(result_val.toIntern());23708 return Air.internedToRef(result_val.toIntern());
23711 } else operand_src;23709 } else operand_src;
...@@ -23715,10 +23713,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23715,10 +23713,10 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23715 },23713 },
23716 .Vector => {23714 .Vector => {
23717 const runtime_src = if (try sema.resolveValue(operand)) |val| {23715 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23718 if (val.isUndef(mod))23716 if (val.isUndef(zcu))
23719 return pt.undefRef(operand_ty);23717 return pt.undefRef(operand_ty);
2372023718
23721 const vec_len = operand_ty.vectorLen(mod);23719 const vec_len = operand_ty.vectorLen(zcu);
23722 const elems = try sema.arena.alloc(InternPool.Index, vec_len);23720 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
23723 for (elems, 0..) |*elem, i| {23721 for (elems, 0..) |*elem, i| {
23724 const elem_val = try val.elemValue(pt, i);23722 const elem_val = try val.elemValue(pt, i);
...@@ -23750,11 +23748,11 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -23750,11 +23748,11 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
23750 }23748 }
2375123749
23752 const pt = sema.pt;23750 const pt = sema.pt;
23753 const mod = pt.zcu;23751 const zcu = pt.zcu;
23754 switch (operand_ty.zigTypeTag(mod)) {23752 switch (operand_ty.zigTypeTag(zcu)) {
23755 .Int => {23753 .Int => {
23756 const runtime_src = if (try sema.resolveValue(operand)) |val| {23754 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);
23758 const result_val = try val.bitReverse(operand_ty, pt, sema.arena);23756 const result_val = try val.bitReverse(operand_ty, pt, sema.arena);
23759 return Air.internedToRef(result_val.toIntern());23757 return Air.internedToRef(result_val.toIntern());
23760 } else operand_src;23758 } else operand_src;
...@@ -23764,10 +23762,10 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -23764,10 +23762,10 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
23764 },23762 },
23765 .Vector => {23763 .Vector => {
23766 const runtime_src = if (try sema.resolveValue(operand)) |val| {23764 const runtime_src = if (try sema.resolveValue(operand)) |val| {
23767 if (val.isUndef(mod))23765 if (val.isUndef(zcu))
23768 return pt.undefRef(operand_ty);23766 return pt.undefRef(operand_ty);
2376923767
23770 const vec_len = operand_ty.vectorLen(mod);23768 const vec_len = operand_ty.vectorLen(zcu);
23771 const elems = try sema.arena.alloc(InternPool.Index, vec_len);23769 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
23772 for (elems, 0..) |*elem, i| {23770 for (elems, 0..) |*elem, i| {
23773 const elem_val = try val.elemValue(pt, i);23771 const elem_val = try val.elemValue(pt, i);
...@@ -23810,26 +23808,26 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6...@@ -23810,26 +23808,26 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
23810 });23808 });
2381123809
23812 const pt = sema.pt;23810 const pt = sema.pt;
23813 const mod = pt.zcu;23811 const zcu = pt.zcu;
23814 const ip = &mod.intern_pool;23812 const ip = &zcu.intern_pool;
23815 try ty.resolveLayout(pt);23813 try ty.resolveLayout(pt);
23816 switch (ty.zigTypeTag(mod)) {23814 switch (ty.zigTypeTag(zcu)) {
23817 .Struct => {},23815 .Struct => {},
23818 else => return sema.fail(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(pt)}),23816 else => return sema.fail(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(pt)}),
23819 }23817 }
2382023818
23821 const field_index = if (ty.isTuple(mod)) blk: {23819 const field_index = if (ty.isTuple(zcu)) blk: {
23822 if (field_name.eqlSlice("len", ip)) {23820 if (field_name.eqlSlice("len", ip)) {
23823 return sema.fail(block, src, "no offset available for 'len' field of tuple", .{});23821 return sema.fail(block, src, "no offset available for 'len' field of tuple", .{});
23824 }23822 }
23825 break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src);23823 break :blk try sema.tupleFieldIndex(block, ty, field_name, rhs_src);
23826 } else try sema.structFieldIndex(block, ty, field_name, rhs_src);23824 } 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)) {
23829 return sema.fail(block, src, "no offset available for comptime field", .{});23827 return sema.fail(block, src, "no offset available for comptime field", .{});
23830 }23828 }
2383123829
23832 switch (ty.containerLayout(mod)) {23830 switch (ty.containerLayout(zcu)) {
23833 .@"packed" => {23831 .@"packed" => {
23834 var bit_sum: u64 = 0;23832 var bit_sum: u64 = 0;
23835 const struct_type = ip.loadStructType(ty.toIntern());23833 const struct_type = ip.loadStructType(ty.toIntern());
...@@ -23838,17 +23836,17 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6...@@ -23838,17 +23836,17 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
23838 return bit_sum;23836 return bit_sum;
23839 }23837 }
23840 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);23838 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);
23842 } else unreachable;23840 } else unreachable;
23843 },23841 },
23844 else => return ty.structFieldOffset(field_index, pt) * 8,23842 else => return ty.structFieldOffset(field_index, zcu) * 8,
23845 }23843 }
23846}23844}
2384723845
23848fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {23846fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
23849 const pt = sema.pt;23847 const pt = sema.pt;
23850 const mod = pt.zcu;23848 const zcu = pt.zcu;
23851 switch (ty.zigTypeTag(mod)) {23849 switch (ty.zigTypeTag(zcu)) {
23852 .Struct, .Enum, .Union, .Opaque => return,23850 .Struct, .Enum, .Union, .Opaque => return,
23853 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(pt)}),23851 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(pt)}),
23854 }23852 }
...@@ -23857,8 +23855,8 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com...@@ -23857,8 +23855,8 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
23857/// Returns `true` if the type was a comptime_int.23855/// Returns `true` if the type was a comptime_int.
23858fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {23856fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
23859 const pt = sema.pt;23857 const pt = sema.pt;
23860 const mod = pt.zcu;23858 const zcu = pt.zcu;
23861 switch (try ty.zigTypeTagOrPoison(mod)) {23859 switch (try ty.zigTypeTagOrPoison(zcu)) {
23862 .ComptimeInt => return true,23860 .ComptimeInt => return true,
23863 .Int => return false,23861 .Int => return false,
23864 else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(pt)}),23862 else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(pt)}),
...@@ -23872,9 +23870,9 @@ fn checkInvalidPtrIntArithmetic(...@@ -23872,9 +23870,9 @@ fn checkInvalidPtrIntArithmetic(
23872 ty: Type,23870 ty: Type,
23873) CompileError!void {23871) CompileError!void {
23874 const pt = sema.pt;23872 const pt = sema.pt;
23875 const mod = pt.zcu;23873 const zcu = pt.zcu;
23876 switch (try ty.zigTypeTagOrPoison(mod)) {23874 switch (try ty.zigTypeTagOrPoison(zcu)) {
23877 .Pointer => switch (ty.ptrSize(mod)) {23875 .Pointer => switch (ty.ptrSize(zcu)) {
23878 .One, .Slice => return,23876 .One, .Slice => return,
23879 .Many, .C => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"),23877 .Many, .C => return sema.failWithInvalidPtrArithmetic(block, src, "pointer-integer", "addition and subtraction"),
23880 },23878 },
...@@ -23908,8 +23906,8 @@ fn checkPtrOperand(...@@ -23908,8 +23906,8 @@ fn checkPtrOperand(
23908 ty: Type,23906 ty: Type,
23909) CompileError!void {23907) CompileError!void {
23910 const pt = sema.pt;23908 const pt = sema.pt;
23911 const mod = pt.zcu;23909 const zcu = pt.zcu;
23912 switch (ty.zigTypeTag(mod)) {23910 switch (ty.zigTypeTag(zcu)) {
23913 .Pointer => return,23911 .Pointer => return,
23914 .Fn => {23912 .Fn => {
23915 const msg = msg: {23913 const msg = msg: {
...@@ -23926,7 +23924,7 @@ fn checkPtrOperand(...@@ -23926,7 +23924,7 @@ fn checkPtrOperand(
23926 };23924 };
23927 return sema.failWithOwnedErrorMsg(block, msg);23925 return sema.failWithOwnedErrorMsg(block, msg);
23928 },23926 },
23929 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,23927 .Optional => if (ty.childType(zcu).zigTypeTag(zcu) == .Pointer) return,
23930 else => {},23928 else => {},
23931 }23929 }
23932 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});23930 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});
...@@ -23940,9 +23938,9 @@ fn checkPtrType(...@@ -23940,9 +23938,9 @@ fn checkPtrType(
23940 allow_slice: bool,23938 allow_slice: bool,
23941) CompileError!void {23939) CompileError!void {
23942 const pt = sema.pt;23940 const pt = sema.pt;
23943 const mod = pt.zcu;23941 const zcu = pt.zcu;
23944 switch (ty.zigTypeTag(mod)) {23942 switch (ty.zigTypeTag(zcu)) {
23945 .Pointer => if (allow_slice or !ty.isSlice(mod)) return,23943 .Pointer => if (allow_slice or !ty.isSlice(zcu)) return,
23946 .Fn => {23944 .Fn => {
23947 const msg = msg: {23945 const msg = msg: {
23948 const msg = try sema.errMsg(23946 const msg = try sema.errMsg(
...@@ -23958,7 +23956,7 @@ fn checkPtrType(...@@ -23958,7 +23956,7 @@ fn checkPtrType(
23958 };23956 };
23959 return sema.failWithOwnedErrorMsg(block, msg);23957 return sema.failWithOwnedErrorMsg(block, msg);
23960 },23958 },
23961 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,23959 .Optional => if (ty.childType(zcu).zigTypeTag(zcu) == .Pointer) return,
23962 else => {},23960 else => {},
23963 }23961 }
23964 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});23962 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(pt)});
...@@ -23971,10 +23969,10 @@ fn checkVectorElemType(...@@ -23971,10 +23969,10 @@ fn checkVectorElemType(
23971 ty: Type,23969 ty: Type,
23972) CompileError!void {23970) CompileError!void {
23973 const pt = sema.pt;23971 const pt = sema.pt;
23974 const mod = pt.zcu;23972 const zcu = pt.zcu;
23975 switch (ty.zigTypeTag(mod)) {23973 switch (ty.zigTypeTag(zcu)) {
23976 .Int, .Float, .Bool => return,23974 .Int, .Float, .Bool => return,
23977 .Optional, .Pointer => if (ty.isPtrAtRuntime(mod)) return,23975 .Optional, .Pointer => if (ty.isPtrAtRuntime(zcu)) return,
23978 else => {},23976 else => {},
23979 }23977 }
23980 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{}'", .{ty.fmt(pt)});23978 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(...@@ -23987,8 +23985,8 @@ fn checkFloatType(
23987 ty: Type,23985 ty: Type,
23988) CompileError!void {23986) CompileError!void {
23989 const pt = sema.pt;23987 const pt = sema.pt;
23990 const mod = pt.zcu;23988 const zcu = pt.zcu;
23991 switch (ty.zigTypeTag(mod)) {23989 switch (ty.zigTypeTag(zcu)) {
23992 .ComptimeInt, .ComptimeFloat, .Float => {},23990 .ComptimeInt, .ComptimeFloat, .Float => {},
23993 else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(pt)}),23991 else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(pt)}),
23994 }23992 }
...@@ -24001,10 +23999,10 @@ fn checkNumericType(...@@ -24001,10 +23999,10 @@ fn checkNumericType(
24001 ty: Type,23999 ty: Type,
24002) CompileError!void {24000) CompileError!void {
24003 const pt = sema.pt;24001 const pt = sema.pt;
24004 const mod = pt.zcu;24002 const zcu = pt.zcu;
24005 switch (ty.zigTypeTag(mod)) {24003 switch (ty.zigTypeTag(zcu)) {
24006 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},24004 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
24007 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {24005 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
24008 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},24006 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
24009 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),24007 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),
24010 },24008 },
...@@ -24023,9 +24021,9 @@ fn checkAtomicPtrOperand(...@@ -24023,9 +24021,9 @@ fn checkAtomicPtrOperand(
24023 ptr_const: bool,24021 ptr_const: bool,
24024) CompileError!Air.Inst.Ref {24022) CompileError!Air.Inst.Ref {
24025 const pt = sema.pt;24023 const pt = sema.pt;
24026 const mod = pt.zcu;24024 const zcu = pt.zcu;
24027 var diag: Module.AtomicPtrAlignmentDiagnostics = .{};24025 var diag: Zcu.AtomicPtrAlignmentDiagnostics = .{};
24028 const alignment = mod.atomicPtrAlignment(elem_ty, &diag) catch |err| switch (err) {24026 const alignment = zcu.atomicPtrAlignment(elem_ty, &diag) catch |err| switch (err) {
24029 error.OutOfMemory => return error.OutOfMemory,24027 error.OutOfMemory => return error.OutOfMemory,
24030 error.FloatTooBig => return sema.fail(24028 error.FloatTooBig => return sema.fail(
24031 block,24029 block,
...@@ -24056,8 +24054,8 @@ fn checkAtomicPtrOperand(...@@ -24056,8 +24054,8 @@ fn checkAtomicPtrOperand(
24056 };24054 };
2405724055
24058 const ptr_ty = sema.typeOf(ptr);24056 const ptr_ty = sema.typeOf(ptr);
24059 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {24057 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(zcu)) {
24060 .Pointer => ptr_ty.ptrInfo(mod),24058 .Pointer => ptr_ty.ptrInfo(zcu),
24061 else => {24059 else => {
24062 const wanted_ptr_ty = try pt.ptrTypeSema(wanted_ptr_data);24060 const wanted_ptr_ty = try pt.ptrTypeSema(wanted_ptr_data);
24063 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);24061 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
...@@ -24095,13 +24093,13 @@ fn checkIntOrVector(...@@ -24095,13 +24093,13 @@ fn checkIntOrVector(
24095 operand_src: LazySrcLoc,24093 operand_src: LazySrcLoc,
24096) CompileError!Type {24094) CompileError!Type {
24097 const pt = sema.pt;24095 const pt = sema.pt;
24098 const mod = pt.zcu;24096 const zcu = pt.zcu;
24099 const operand_ty = sema.typeOf(operand);24097 const operand_ty = sema.typeOf(operand);
24100 switch (try operand_ty.zigTypeTagOrPoison(mod)) {24098 switch (try operand_ty.zigTypeTagOrPoison(zcu)) {
24101 .Int => return operand_ty,24099 .Int => return operand_ty,
24102 .Vector => {24100 .Vector => {
24103 const elem_ty = operand_ty.childType(mod);24101 const elem_ty = operand_ty.childType(zcu);
24104 switch (try elem_ty.zigTypeTagOrPoison(mod)) {24102 switch (try elem_ty.zigTypeTagOrPoison(zcu)) {
24105 .Int => return elem_ty,24103 .Int => return elem_ty,
24106 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{24104 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
24107 elem_ty.fmt(pt),24105 elem_ty.fmt(pt),
...@@ -24121,12 +24119,12 @@ fn checkIntOrVectorAllowComptime(...@@ -24121,12 +24119,12 @@ fn checkIntOrVectorAllowComptime(
24121 operand_src: LazySrcLoc,24119 operand_src: LazySrcLoc,
24122) CompileError!Type {24120) CompileError!Type {
24123 const pt = sema.pt;24121 const pt = sema.pt;
24124 const mod = pt.zcu;24122 const zcu = pt.zcu;
24125 switch (try operand_ty.zigTypeTagOrPoison(mod)) {24123 switch (try operand_ty.zigTypeTagOrPoison(zcu)) {
24126 .Int, .ComptimeInt => return operand_ty,24124 .Int, .ComptimeInt => return operand_ty,
24127 .Vector => {24125 .Vector => {
24128 const elem_ty = operand_ty.childType(mod);24126 const elem_ty = operand_ty.childType(zcu);
24129 switch (try elem_ty.zigTypeTagOrPoison(mod)) {24127 switch (try elem_ty.zigTypeTagOrPoison(zcu)) {
24130 .Int, .ComptimeInt => return elem_ty,24128 .Int, .ComptimeInt => return elem_ty,
24131 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{24129 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
24132 elem_ty.fmt(pt),24130 elem_ty.fmt(pt),
...@@ -24162,12 +24160,12 @@ fn checkSimdBinOp(...@@ -24162,12 +24160,12 @@ fn checkSimdBinOp(
24162 rhs_src: LazySrcLoc,24160 rhs_src: LazySrcLoc,
24163) CompileError!SimdBinOp {24161) CompileError!SimdBinOp {
24164 const pt = sema.pt;24162 const pt = sema.pt;
24165 const mod = pt.zcu;24163 const zcu = pt.zcu;
24166 const lhs_ty = sema.typeOf(uncasted_lhs);24164 const lhs_ty = sema.typeOf(uncasted_lhs);
24167 const rhs_ty = sema.typeOf(uncasted_rhs);24165 const rhs_ty = sema.typeOf(uncasted_rhs);
2416824166
24169 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);24167 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;
24171 const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{24169 const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{
24172 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },24170 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },
24173 });24171 });
...@@ -24181,7 +24179,7 @@ fn checkSimdBinOp(...@@ -24181,7 +24179,7 @@ fn checkSimdBinOp(
24181 .lhs_val = try sema.resolveValue(lhs),24179 .lhs_val = try sema.resolveValue(lhs),
24182 .rhs_val = try sema.resolveValue(rhs),24180 .rhs_val = try sema.resolveValue(rhs),
24183 .result_ty = result_ty,24181 .result_ty = result_ty,
24184 .scalar_ty = result_ty.scalarType(mod),24182 .scalar_ty = result_ty.scalarType(zcu),
24185 };24183 };
24186}24184}
2418724185
...@@ -24195,9 +24193,9 @@ fn checkVectorizableBinaryOperands(...@@ -24195,9 +24193,9 @@ fn checkVectorizableBinaryOperands(
24195 rhs_src: LazySrcLoc,24193 rhs_src: LazySrcLoc,
24196) CompileError!void {24194) CompileError!void {
24197 const pt = sema.pt;24195 const pt = sema.pt;
24198 const mod = pt.zcu;24196 const zcu = pt.zcu;
24199 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(mod);24197 const lhs_zig_ty_tag = try lhs_ty.zigTypeTagOrPoison(zcu);
24200 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);24198 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(zcu);
24201 if (lhs_zig_ty_tag != .Vector and rhs_zig_ty_tag != .Vector) return;24199 if (lhs_zig_ty_tag != .Vector and rhs_zig_ty_tag != .Vector) return;
2420224200
24203 const lhs_is_vector = switch (lhs_zig_ty_tag) {24201 const lhs_is_vector = switch (lhs_zig_ty_tag) {
...@@ -24210,8 +24208,8 @@ fn checkVectorizableBinaryOperands(...@@ -24210,8 +24208,8 @@ fn checkVectorizableBinaryOperands(
24210 };24208 };
2421124209
24212 if (lhs_is_vector and rhs_is_vector) {24210 if (lhs_is_vector and rhs_is_vector) {
24213 const lhs_len = lhs_ty.arrayLen(mod);24211 const lhs_len = lhs_ty.arrayLen(zcu);
24214 const rhs_len = rhs_ty.arrayLen(mod);24212 const rhs_len = rhs_ty.arrayLen(zcu);
24215 if (lhs_len != rhs_len) {24213 if (lhs_len != rhs_len) {
24216 const msg = msg: {24214 const msg = msg: {
24217 const msg = try sema.errMsg(src, "vector length mismatch", .{});24215 const msg = try sema.errMsg(src, "vector length mismatch", .{});
...@@ -24246,11 +24244,11 @@ fn resolveExportOptions(...@@ -24246,11 +24244,11 @@ fn resolveExportOptions(
24246 block: *Block,24244 block: *Block,
24247 src: LazySrcLoc,24245 src: LazySrcLoc,
24248 zir_ref: Zir.Inst.Ref,24246 zir_ref: Zir.Inst.Ref,
24249) CompileError!Module.Export.Options {24247) CompileError!Zcu.Export.Options {
24250 const pt = sema.pt;24248 const pt = sema.pt;
24251 const mod = pt.zcu;24249 const zcu = pt.zcu;
24252 const gpa = sema.gpa;24250 const gpa = sema.gpa;
24253 const ip = &mod.intern_pool;24251 const ip = &zcu.intern_pool;
24254 const export_options_ty = try pt.getBuiltinType("ExportOptions");24252 const export_options_ty = try pt.getBuiltinType("ExportOptions");
24255 const air_ref = try sema.resolveInst(zir_ref);24253 const air_ref = try sema.resolveInst(zir_ref);
24256 const options = try sema.coerce(block, export_options_ty, air_ref, src);24254 const options = try sema.coerce(block, export_options_ty, air_ref, src);
...@@ -24269,13 +24267,13 @@ fn resolveExportOptions(...@@ -24269,13 +24267,13 @@ fn resolveExportOptions(
24269 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{24267 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
24270 .needed_comptime_reason = "linkage of exported value must be comptime-known",24268 .needed_comptime_reason = "linkage of exported value must be comptime-known",
24271 });24269 });
24272 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);24270 const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val);
2427324271
24274 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src);24272 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, pt.tid, "section", .no_embedded_nulls), section_src);
24275 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{24273 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
24276 .needed_comptime_reason = "linksection of exported value must be comptime-known",24274 .needed_comptime_reason = "linksection of exported value must be comptime-known",
24277 });24275 });
24278 const section = if (section_opt_val.optionalValue(mod)) |section_val|24276 const section = if (section_opt_val.optionalValue(zcu)) |section_val|
24279 try sema.toConstString(block, section_src, Air.internedToRef(section_val.toIntern()), .{24277 try sema.toConstString(block, section_src, Air.internedToRef(section_val.toIntern()), .{
24280 .needed_comptime_reason = "linksection of exported value must be comptime-known",24278 .needed_comptime_reason = "linksection of exported value must be comptime-known",
24281 })24279 })
...@@ -24286,7 +24284,7 @@ fn resolveExportOptions(...@@ -24286,7 +24284,7 @@ fn resolveExportOptions(
24286 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{24284 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
24287 .needed_comptime_reason = "visibility of exported value must be comptime-known",24285 .needed_comptime_reason = "visibility of exported value must be comptime-known",
24288 });24286 });
24289 const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val);24287 const visibility = zcu.toEnum(std.builtin.SymbolVisibility, visibility_val);
2429024288
24291 if (name.len < 1) {24289 if (name.len < 1) {
24292 return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});24290 return sema.fail(block, name_src, "exported symbol name cannot be empty", .{});
...@@ -24349,7 +24347,7 @@ fn zirCmpxchg(...@@ -24349,7 +24347,7 @@ fn zirCmpxchg(
24349 extended: Zir.Inst.Extended.InstData,24347 extended: Zir.Inst.Extended.InstData,
24350) CompileError!Air.Inst.Ref {24348) CompileError!Air.Inst.Ref {
24351 const pt = sema.pt;24349 const pt = sema.pt;
24352 const mod = pt.zcu;24350 const zcu = pt.zcu;
24353 const extra = sema.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;24351 const extra = sema.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
24354 const air_tag: Air.Inst.Tag = switch (extended.small) {24352 const air_tag: Air.Inst.Tag = switch (extended.small) {
24355 0 => .cmpxchg_weak,24353 0 => .cmpxchg_weak,
...@@ -24367,7 +24365,7 @@ fn zirCmpxchg(...@@ -24367,7 +24365,7 @@ fn zirCmpxchg(
24367 // zig fmt: on24365 // zig fmt: on
24368 const expected_value = try sema.resolveInst(extra.expected_value);24366 const expected_value = try sema.resolveInst(extra.expected_value);
24369 const elem_ty = sema.typeOf(expected_value);24367 const elem_ty = sema.typeOf(expected_value);
24370 if (elem_ty.zigTypeTag(mod) == .Float) {24368 if (elem_ty.zigTypeTag(zcu) == .Float) {
24371 return sema.fail(24369 return sema.fail(
24372 block,24370 block,
24373 elem_ty_src,24371 elem_ty_src,
...@@ -24411,7 +24409,7 @@ fn zirCmpxchg(...@@ -24411,7 +24409,7 @@ fn zirCmpxchg(
24411 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {24409 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
24412 if (try sema.resolveValue(expected_value)) |expected_val| {24410 if (try sema.resolveValue(expected_value)) |expected_val| {
24413 if (try sema.resolveValue(new_value)) |new_val| {24411 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)) {
24415 // TODO: this should probably cause the memory stored at the pointer24413 // TODO: this should probably cause the memory stored at the pointer
24416 // to become undef as well24414 // to become undef as well
24417 return pt.undefRef(result_ty);24415 return pt.undefRef(result_ty);
...@@ -24420,7 +24418,7 @@ fn zirCmpxchg(...@@ -24420,7 +24418,7 @@ fn zirCmpxchg(
24420 const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src;24418 const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src;
24421 const result_val = try pt.intern(.{ .opt = .{24419 const result_val = try pt.intern(.{ .opt = .{
24422 .ty = result_ty.toIntern(),24420 .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: {
24424 try sema.storePtr(block, src, ptr, new_value);24422 try sema.storePtr(block, src, ptr, new_value);
24425 break :blk .none;24423 break :blk .none;
24426 } else stored_val.toIntern(),24424 } else stored_val.toIntern(),
...@@ -24450,16 +24448,16 @@ fn zirCmpxchg(...@@ -24450,16 +24448,16 @@ fn zirCmpxchg(
2445024448
24451fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {24449fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24452 const pt = sema.pt;24450 const pt = sema.pt;
24453 const mod = pt.zcu;24451 const zcu = pt.zcu;
24454 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24452 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24455 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;24453 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
24456 const src = block.nodeOffset(inst_data.src_node);24454 const src = block.nodeOffset(inst_data.src_node);
24457 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);24455 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24458 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");24456 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)) {
24463 const empty_aggregate = try pt.intern(.{ .aggregate = .{24461 const empty_aggregate = try pt.intern(.{ .aggregate = .{
24464 .ty = dest_ty.toIntern(),24462 .ty = dest_ty.toIntern(),
24465 .storage = .{ .elems = &[_]InternPool.Index{} },24463 .storage = .{ .elems = &[_]InternPool.Index{} },
...@@ -24468,10 +24466,10 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -24468,10 +24466,10 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
24468 }24466 }
2446924467
24470 const operand = try sema.resolveInst(extra.rhs);24468 const operand = try sema.resolveInst(extra.rhs);
24471 const scalar_ty = dest_ty.childType(mod);24469 const scalar_ty = dest_ty.childType(zcu);
24472 const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src);24470 const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src);
24473 if (try sema.resolveValue(scalar)) |scalar_val| {24471 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);
24475 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());24473 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());
24476 }24474 }
2447724475
...@@ -24490,23 +24488,23 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -24490,23 +24488,23 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
24490 const operand = try sema.resolveInst(extra.rhs);24488 const operand = try sema.resolveInst(extra.rhs);
24491 const operand_ty = sema.typeOf(operand);24489 const operand_ty = sema.typeOf(operand);
24492 const pt = sema.pt;24490 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) {
24496 return sema.fail(block, operand_src, "expected vector, found '{}'", .{operand_ty.fmt(pt)});24494 return sema.fail(block, operand_src, "expected vector, found '{}'", .{operand_ty.fmt(pt)});
24497 }24495 }
2449824496
24499 const scalar_ty = operand_ty.childType(mod);24497 const scalar_ty = operand_ty.childType(zcu);
2450024498
24501 // Type-check depending on operation.24499 // Type-check depending on operation.
24502 switch (operation) {24500 switch (operation) {
24503 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(mod)) {24501 .And, .Or, .Xor => switch (scalar_ty.zigTypeTag(zcu)) {
24504 .Int, .Bool => {},24502 .Int, .Bool => {},
24505 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{}'", .{24503 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or boolean operand; found '{}'", .{
24506 @tagName(operation), operand_ty.fmt(pt),24504 @tagName(operation), operand_ty.fmt(pt),
24507 }),24505 }),
24508 },24506 },
24509 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(mod)) {24507 .Min, .Max, .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
24510 .Int, .Float => {},24508 .Int, .Float => {},
24511 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{}'", .{24509 else => return sema.fail(block, operand_src, "@reduce operation '{s}' requires integer or float operand; found '{}'", .{
24512 @tagName(operation), operand_ty.fmt(pt),24510 @tagName(operation), operand_ty.fmt(pt),
...@@ -24514,7 +24512,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -24514,7 +24512,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
24514 },24512 },
24515 }24513 }
2451624514
24517 const vec_len = operand_ty.vectorLen(mod);24515 const vec_len = operand_ty.vectorLen(zcu);
24518 if (vec_len == 0) {24516 if (vec_len == 0) {
24519 // TODO re-evaluate if we should introduce a "neutral value" for some operations,24517 // TODO re-evaluate if we should introduce a "neutral value" for some operations,
24520 // e.g. zero for add and one for mul.24518 // 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....@@ -24522,7 +24520,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
24522 }24520 }
2452324521
24524 if (try sema.resolveValue(operand)) |operand_val| {24522 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
24527 var accum: Value = try operand_val.elemValue(pt, 0);24525 var accum: Value = try operand_val.elemValue(pt, 0);
24528 var i: u32 = 1;24526 var i: u32 = 1;
...@@ -24532,8 +24530,8 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -24532,8 +24530,8 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
24532 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, pt),24530 .And => accum = try accum.bitwiseAnd(elem_val, scalar_ty, sema.arena, pt),
24533 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, pt),24531 .Or => accum = try accum.bitwiseOr(elem_val, scalar_ty, sema.arena, pt),
24534 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, pt),24532 .Xor => accum = try accum.bitwiseXor(elem_val, scalar_ty, sema.arena, pt),
24535 .Min => accum = accum.numberMin(elem_val, pt),24533 .Min => accum = accum.numberMin(elem_val, zcu),
24536 .Max => accum = accum.numberMax(elem_val, pt),24534 .Max => accum = accum.numberMax(elem_val, zcu),
24537 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),24535 .Add => accum = try sema.numberAddWrapScalar(accum, elem_val, scalar_ty),
24538 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, pt),24536 .Mul => accum = try accum.numberMulWrap(elem_val, scalar_ty, sema.arena, pt),
24539 }24537 }
...@@ -24553,7 +24551,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -24553,7 +24551,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2455324551
24554fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {24552fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24555 const pt = sema.pt;24553 const pt = sema.pt;
24556 const mod = pt.zcu;24554 const zcu = pt.zcu;
24557 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24555 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24558 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;24556 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
24559 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);24557 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...@@ -24566,8 +24564,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
24566 var mask = try sema.resolveInst(extra.mask);24564 var mask = try sema.resolveInst(extra.mask);
24567 var mask_ty = sema.typeOf(mask);24565 var mask_ty = sema.typeOf(mask);
2456824566
24569 const mask_len = switch (sema.typeOf(mask).zigTypeTag(mod)) {24567 const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) {
24570 .Array, .Vector => sema.typeOf(mask).arrayLen(mod),24568 .Array, .Vector => sema.typeOf(mask).arrayLen(zcu),
24571 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(pt)}),24569 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(pt)}),
24572 };24570 };
24573 mask_ty = try pt.vectorType(.{24571 mask_ty = try pt.vectorType(.{
...@@ -24592,6 +24590,7 @@ fn analyzeShuffle(...@@ -24592,6 +24590,7 @@ fn analyzeShuffle(
24592 mask_len: u32,24590 mask_len: u32,
24593) CompileError!Air.Inst.Ref {24591) CompileError!Air.Inst.Ref {
24594 const pt = sema.pt;24592 const pt = sema.pt;
24593 const zcu = pt.zcu;
24595 const a_src = block.builtinCallArgSrc(src_node, 1);24594 const a_src = block.builtinCallArgSrc(src_node, 1);
24596 const b_src = block.builtinCallArgSrc(src_node, 2);24595 const b_src = block.builtinCallArgSrc(src_node, 2);
24597 const mask_src = block.builtinCallArgSrc(src_node, 3);24596 const mask_src = block.builtinCallArgSrc(src_node, 3);
...@@ -24603,16 +24602,16 @@ fn analyzeShuffle(...@@ -24603,16 +24602,16 @@ fn analyzeShuffle(
24603 .child = elem_ty.toIntern(),24602 .child = elem_ty.toIntern(),
24604 });24603 });
2460524604
24606 const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(pt.zcu)) {24605 const maybe_a_len = switch (sema.typeOf(a).zigTypeTag(zcu)) {
24607 .Array, .Vector => sema.typeOf(a).arrayLen(pt.zcu),24606 .Array, .Vector => sema.typeOf(a).arrayLen(zcu),
24608 .Undefined => null,24607 .Undefined => null,
24609 else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{24608 else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{
24610 elem_ty.fmt(pt),24609 elem_ty.fmt(pt),
24611 sema.typeOf(a).fmt(pt),24610 sema.typeOf(a).fmt(pt),
24612 }),24611 }),
24613 };24612 };
24614 const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(pt.zcu)) {24613 const maybe_b_len = switch (sema.typeOf(b).zigTypeTag(zcu)) {
24615 .Array, .Vector => sema.typeOf(b).arrayLen(pt.zcu),24614 .Array, .Vector => sema.typeOf(b).arrayLen(zcu),
24616 .Undefined => null,24615 .Undefined => null,
24617 else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{24616 else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{
24618 elem_ty.fmt(pt),24617 elem_ty.fmt(pt),
...@@ -24644,9 +24643,9 @@ fn analyzeShuffle(...@@ -24644,9 +24643,9 @@ fn analyzeShuffle(
2464424643
24645 for (0..@intCast(mask_len)) |i| {24644 for (0..@intCast(mask_len)) |i| {
24646 const elem = try mask.elemValue(pt, i);24645 const elem = try mask.elemValue(pt, i);
24647 if (elem.isUndef(pt.zcu)) continue;24646 if (elem.isUndef(zcu)) continue;
24648 const elem_resolved = try sema.resolveLazyValue(elem);24647 const elem_resolved = try sema.resolveLazyValue(elem);
24649 const int = elem_resolved.toSignedInt(pt);24648 const int = elem_resolved.toSignedInt(zcu);
24650 var unsigned: u32 = undefined;24649 var unsigned: u32 = undefined;
24651 var chosen: u32 = undefined;24650 var chosen: u32 = undefined;
24652 if (int >= 0) {24651 if (int >= 0) {
...@@ -24681,11 +24680,11 @@ fn analyzeShuffle(...@@ -24681,11 +24680,11 @@ fn analyzeShuffle(
24681 const values = try sema.arena.alloc(InternPool.Index, mask_len);24680 const values = try sema.arena.alloc(InternPool.Index, mask_len);
24682 for (values, 0..) |*value, i| {24681 for (values, 0..) |*value, i| {
24683 const mask_elem_val = try mask.elemValue(pt, i);24682 const mask_elem_val = try mask.elemValue(pt, i);
24684 if (mask_elem_val.isUndef(pt.zcu)) {24683 if (mask_elem_val.isUndef(zcu)) {
24685 value.* = try pt.intern(.{ .undef = elem_ty.toIntern() });24684 value.* = try pt.intern(.{ .undef = elem_ty.toIntern() });
24686 continue;24685 continue;
24687 }24686 }
24688 const int = mask_elem_val.toSignedInt(pt);24687 const int = mask_elem_val.toSignedInt(zcu);
24689 const unsigned: u32 = @intCast(if (int >= 0) int else ~int);24688 const unsigned: u32 = @intCast(if (int >= 0) int else ~int);
24690 values[i] = (try (if (int >= 0) a_val else b_val).elemValue(pt, unsigned)).toIntern();24689 values[i] = (try (if (int >= 0) a_val else b_val).elemValue(pt, unsigned)).toIntern();
24691 }24690 }
...@@ -24743,7 +24742,7 @@ fn analyzeShuffle(...@@ -24743,7 +24742,7 @@ fn analyzeShuffle(
2474324742
24744fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {24743fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
24745 const pt = sema.pt;24744 const pt = sema.pt;
24746 const mod = pt.zcu;24745 const zcu = pt.zcu;
24747 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;24746 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
2474824747
24749 const src = block.nodeOffset(extra.node);24748 const src = block.nodeOffset(extra.node);
...@@ -24757,8 +24756,8 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -24757,8 +24756,8 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
24757 const pred_uncoerced = try sema.resolveInst(extra.pred);24756 const pred_uncoerced = try sema.resolveInst(extra.pred);
24758 const pred_ty = sema.typeOf(pred_uncoerced);24757 const pred_ty = sema.typeOf(pred_uncoerced);
2475924758
24760 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) {24759 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(zcu)) {
24761 .Vector, .Array => pred_ty.arrayLen(mod),24760 .Vector, .Array => pred_ty.arrayLen(zcu),
24762 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(pt)}),24761 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(pt)}),
24763 };24762 };
24764 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));24763 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...@@ -24781,13 +24780,13 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
24781 const maybe_b = try sema.resolveValue(b);24780 const maybe_b = try sema.resolveValue(b);
2478224781
24783 const runtime_src = if (maybe_pred) |pred_val| rs: {24782 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
24786 if (maybe_a) |a_val| {24785 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
24789 if (maybe_b) |b_val| {24788 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
24792 const elems = try sema.gpa.alloc(InternPool.Index, vec_len);24791 const elems = try sema.gpa.alloc(InternPool.Index, vec_len);
24793 defer sema.gpa.free(elems);24792 defer sema.gpa.free(elems);
...@@ -24806,16 +24805,16 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -24806,16 +24805,16 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
24806 }24805 }
24807 } else {24806 } else {
24808 if (maybe_b) |b_val| {24807 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);
24810 }24809 }
24811 break :rs a_src;24810 break :rs a_src;
24812 }24811 }
24813 } else rs: {24812 } else rs: {
24814 if (maybe_a) |a_val| {24813 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);
24816 }24815 }
24817 if (maybe_b) |b_val| {24816 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);
24819 }24818 }
24820 break :rs pred_src;24819 break :rs pred_src;
24821 };24820 };
...@@ -24882,7 +24881,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -24882,7 +24881,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2488224881
24883fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {24882fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24884 const pt = sema.pt;24883 const pt = sema.pt;
24885 const mod = pt.zcu;24884 const zcu = pt.zcu;
24886 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24885 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24887 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;24886 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
24888 const src = block.nodeOffset(inst_data.src_node);24887 const src = block.nodeOffset(inst_data.src_node);
...@@ -24899,7 +24898,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -24899,7 +24898,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
24899 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);24898 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
24900 const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation);24899 const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation);
2490124900
24902 switch (elem_ty.zigTypeTag(mod)) {24901 switch (elem_ty.zigTypeTag(zcu)) {
24903 .Enum => if (op != .Xchg) {24902 .Enum => if (op != .Xchg) {
24904 return sema.fail(block, op_src, "@atomicRmw with enum only allowed with .Xchg", .{});24903 return sema.fail(block, op_src, "@atomicRmw with enum only allowed with .Xchg", .{});
24905 },24904 },
...@@ -24939,12 +24938,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -24939,12 +24938,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
24939 .Xchg => operand_val,24938 .Xchg => operand_val,
24940 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),24939 .Add => try sema.numberAddWrapScalar(stored_val, operand_val, elem_ty),
24941 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),24940 .Sub => try sema.numberSubWrapScalar(stored_val, operand_val, elem_ty),
24942 .And => try stored_val.bitwiseAnd (operand_val, elem_ty, sema.arena, pt),24941 .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),24942 .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),24943 .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),24944 .Xor => try stored_val.bitwiseXor (operand_val, elem_ty, sema.arena, pt ),
24946 .Max => stored_val.numberMax (operand_val, pt),24945 .Max => stored_val.numberMax (operand_val, zcu),
24947 .Min => stored_val.numberMin (operand_val, pt),24946 .Min => stored_val.numberMin (operand_val, zcu),
24948 // zig fmt: on24947 // zig fmt: on
24949 };24948 };
24950 try sema.storePtrVal(block, src, ptr_val, new_val, elem_ty);24949 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....@@ -25021,19 +25020,19 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
25021 const maybe_mulend2 = try sema.resolveValue(mulend2);25020 const maybe_mulend2 = try sema.resolveValue(mulend2);
25022 const maybe_addend = try sema.resolveValue(addend);25021 const maybe_addend = try sema.resolveValue(addend);
25023 const pt = sema.pt;25022 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)) {
25027 .ComptimeFloat, .Float => {},25026 .ComptimeFloat, .Float => {},
25028 else => return sema.fail(block, src, "expected vector of floats or float type, found '{}'", .{ty.fmt(pt)}),25027 else => return sema.fail(block, src, "expected vector of floats or float type, found '{}'", .{ty.fmt(pt)}),
25029 }25028 }
2503025029
25031 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {25030 const runtime_src = if (maybe_mulend1) |mulend1_val| rs: {
25032 if (maybe_mulend2) |mulend2_val| {25031 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
25035 if (maybe_addend) |addend_val| {25034 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);
25037 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, pt);25036 const result_val = try Value.mulAdd(ty, mulend1_val, mulend2_val, addend_val, sema.arena, pt);
25038 return Air.internedToRef(result_val.toIntern());25037 return Air.internedToRef(result_val.toIntern());
25039 } else {25038 } else {
...@@ -25041,16 +25040,16 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -25041,16 +25040,16 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
25041 }25040 }
25042 } else {25041 } else {
25043 if (maybe_addend) |addend_val| {25042 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);
25045 }25044 }
25046 break :rs mulend2_src;25045 break :rs mulend2_src;
25047 }25046 }
25048 } else rs: {25047 } else rs: {
25049 if (maybe_mulend2) |mulend2_val| {25048 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);
25051 }25050 }
25052 if (maybe_addend) |addend_val| {25051 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);
25054 }25053 }
25055 break :rs mulend1_src;25054 break :rs mulend1_src;
25056 };25055 };
...@@ -25073,7 +25072,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -25073,7 +25072,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
25073 defer tracy.end();25072 defer tracy.end();
2507425073
25075 const pt = sema.pt;25074 const pt = sema.pt;
25076 const mod = pt.zcu;25075 const zcu = pt.zcu;
25077 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25076 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25078 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);25077 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25079 const func_src = block.builtinCallArgSrc(inst_data.src_node, 1);25078 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...@@ -25089,7 +25088,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
25089 const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{25088 const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{
25090 .needed_comptime_reason = "call modifier must be comptime-known",25089 .needed_comptime_reason = "call modifier must be comptime-known",
25091 });25090 });
25092 var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val);25091 var modifier = zcu.toEnum(std.builtin.CallModifier, modifier_val);
25093 switch (modifier) {25092 switch (modifier) {
25094 // These can be upgraded to comptime or nosuspend calls.25093 // These can be upgraded to comptime or nosuspend calls.
25095 .auto, .never_tail, .no_async => {25094 .auto, .never_tail, .no_async => {
...@@ -25135,11 +25134,11 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -25135,11 +25134,11 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
25135 const args = try sema.resolveInst(extra.args);25134 const args = try sema.resolveInst(extra.args);
2513625135
25137 const args_ty = sema.typeOf(args);25136 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) {
25139 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(pt)});25138 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(pt)});
25140 }25139 }
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));
25143 for (resolved_args, 0..) |*resolved, i| {25142 for (resolved_args, 0..) |*resolved, i| {
25144 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty);25143 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty);
25145 }25144 }
...@@ -25219,7 +25218,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -25219,7 +25218,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25219 var actual_parent_ptr_info: InternPool.Key.PtrType = .{25218 var actual_parent_ptr_info: InternPool.Key.PtrType = .{
25220 .child = parent_ty.toIntern(),25219 .child = parent_ty.toIntern(),
25221 .flags = .{25220 .flags = .{
25222 .alignment = try parent_ptr_ty.ptrAlignmentAdvanced(pt, .sema),25221 .alignment = try parent_ptr_ty.ptrAlignmentSema(pt),
25223 .is_const = field_ptr_info.flags.is_const,25222 .is_const = field_ptr_info.flags.is_const,
25224 .is_volatile = field_ptr_info.flags.is_volatile,25223 .is_volatile = field_ptr_info.flags.is_volatile,
25225 .is_allowzero = field_ptr_info.flags.is_allowzero,25224 .is_allowzero = field_ptr_info.flags.is_allowzero,
...@@ -25227,11 +25226,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -25227,11 +25226,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25227 },25226 },
25228 .packed_offset = parent_ptr_info.packed_offset,25227 .packed_offset = parent_ptr_info.packed_offset,
25229 };25228 };
25230 const field_ty = parent_ty.structFieldType(field_index, zcu);25229 const field_ty = parent_ty.fieldType(field_index, zcu);
25231 var actual_field_ptr_info: InternPool.Key.PtrType = .{25230 var actual_field_ptr_info: InternPool.Key.PtrType = .{
25232 .child = field_ty.toIntern(),25231 .child = field_ty.toIntern(),
25233 .flags = .{25232 .flags = .{
25234 .alignment = try field_ptr_ty.ptrAlignmentAdvanced(pt, .sema),25233 .alignment = try field_ptr_ty.ptrAlignmentSema(pt),
25235 .is_const = field_ptr_info.flags.is_const,25234 .is_const = field_ptr_info.flags.is_const,
25236 .is_volatile = field_ptr_info.flags.is_volatile,25235 .is_volatile = field_ptr_info.flags.is_volatile,
25237 .is_allowzero = field_ptr_info.flags.is_allowzero,25236 .is_allowzero = field_ptr_info.flags.is_allowzero,
...@@ -25242,13 +25241,18 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -25242,13 +25241,18 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25242 switch (parent_ty.containerLayout(zcu)) {25241 switch (parent_ty.containerLayout(zcu)) {
25243 .auto => {25242 .auto => {
25244 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(25243 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(
25245 if (zcu.typeToStruct(parent_ty)) |struct_obj| try pt.structFieldAlignmentAdvanced(25244 if (zcu.typeToStruct(parent_ty)) |struct_obj|
25246 struct_obj.fieldAlign(ip, field_index),25245 try field_ty.structFieldAlignmentSema(
25247 field_ty,25246 struct_obj.fieldAlign(ip, field_index),
25248 struct_obj.layout,25247 struct_obj.layout,
25249 .sema,25248 pt,
25250 ) else if (zcu.typeToUnion(parent_ty)) |union_obj|25249 )
25251 try pt.unionFieldNormalAlignmentAdvanced(union_obj, field_index, .sema)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 )
25252 else25256 else
25253 actual_field_ptr_info.flags.alignment,25257 actual_field_ptr_info.flags.alignment,
25254 );25258 );
...@@ -25257,7 +25261,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -25257,7 +25261,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25257 actual_field_ptr_info.packed_offset = .{ .bit_offset = 0, .host_size = 0 };25261 actual_field_ptr_info.packed_offset = .{ .bit_offset = 0, .host_size = 0 };
25258 },25262 },
25259 .@"extern" => {25263 .@"extern" => {
25260 const field_offset = parent_ty.structFieldOffset(field_index, pt);25264 const field_offset = parent_ty.structFieldOffset(field_index, zcu);
25261 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(if (field_offset > 0)25265 actual_parent_ptr_info.flags.alignment = actual_field_ptr_info.flags.alignment.minStrict(if (field_offset > 0)
25262 Alignment.fromLog2Units(@ctz(field_offset))25266 Alignment.fromLog2Units(@ctz(field_offset))
25263 else25267 else
...@@ -25287,7 +25291,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -25287,7 +25291,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25287 .Struct => switch (parent_ty.containerLayout(zcu)) {25291 .Struct => switch (parent_ty.containerLayout(zcu)) {
25288 .auto => {},25292 .auto => {},
25289 .@"extern" => {25293 .@"extern" => {
25290 const byte_offset = parent_ty.structFieldOffset(field_index, pt);25294 const byte_offset = parent_ty.structFieldOffset(field_index, zcu);
25291 const parent_ptr_val = try sema.ptrSubtract(block, field_ptr_src, field_ptr_val, byte_offset, actual_parent_ptr_ty);25295 const parent_ptr_val = try sema.ptrSubtract(block, field_ptr_src, field_ptr_val, byte_offset, actual_parent_ptr_ty);
25292 break :result Air.internedToRef(parent_ptr_val.toIntern());25296 break :result Air.internedToRef(parent_ptr_val.toIntern());
25293 },25297 },
...@@ -25428,7 +25432,7 @@ fn analyzeMinMax(...@@ -25428,7 +25432,7 @@ fn analyzeMinMax(
25428 assert(operands.len == operand_srcs.len);25432 assert(operands.len == operand_srcs.len);
25429 assert(operands.len > 0);25433 assert(operands.len > 0);
25430 const pt = sema.pt;25434 const pt = sema.pt;
25431 const mod = pt.zcu;25435 const zcu = pt.zcu;
2543225436
25433 if (operands.len == 1) return operands[0];25437 if (operands.len == 1) return operands[0];
2543425438
...@@ -25466,20 +25470,20 @@ fn analyzeMinMax(...@@ -25466,20 +25470,20 @@ fn analyzeMinMax(
25466 switch (bounds_status) {25470 switch (bounds_status) {
25467 .unknown, .defined => refine_bounds: {25471 .unknown, .defined => refine_bounds: {
25468 const ty = sema.typeOf(operand);25472 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)) {
25470 bounds_status = .non_integral;25474 bounds_status = .non_integral;
25471 break :refine_bounds;25475 break :refine_bounds;
25472 }25476 }
25473 const scalar_bounds: ?[2]Value = bounds: {25477 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);
25475 var cur_bounds: [2]Value = try Value.intValueBounds(try uncoerced_val.elemValue(pt, 0), pt) orelse break :bounds null;25479 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));
25477 for (1..len) |i| {25481 for (1..len) |i| {
25478 const elem = try uncoerced_val.elemValue(pt, i);25482 const elem = try uncoerced_val.elemValue(pt, i);
25479 const elem_bounds = try elem.intValueBounds(pt) orelse break :bounds null;25483 const elem_bounds = try elem.intValueBounds(pt) orelse break :bounds null;
25480 cur_bounds = .{25484 cur_bounds = .{
25481 Value.numberMin(elem_bounds[0], cur_bounds[0], pt),25485 Value.numberMin(elem_bounds[0], cur_bounds[0], zcu),
25482 Value.numberMax(elem_bounds[1], cur_bounds[1], pt),25486 Value.numberMax(elem_bounds[1], cur_bounds[1], zcu),
25483 };25487 };
25484 }25488 }
25485 break :bounds cur_bounds;25489 break :bounds cur_bounds;
...@@ -25490,8 +25494,8 @@ fn analyzeMinMax(...@@ -25490,8 +25494,8 @@ fn analyzeMinMax(
25490 cur_max_scalar = bounds[1];25494 cur_max_scalar = bounds[1];
25491 bounds_status = .defined;25495 bounds_status = .defined;
25492 } else {25496 } else {
25493 cur_min_scalar = opFunc(cur_min_scalar, bounds[0], pt);25497 cur_min_scalar = opFunc(cur_min_scalar, bounds[0], zcu);
25494 cur_max_scalar = opFunc(cur_max_scalar, bounds[1], pt);25498 cur_max_scalar = opFunc(cur_max_scalar, bounds[1], zcu);
25495 }25499 }
25496 }25500 }
25497 },25501 },
...@@ -25509,7 +25513,7 @@ fn analyzeMinMax(...@@ -25509,7 +25513,7 @@ fn analyzeMinMax(
25509 const operand_val = try sema.resolveLazyValue(simd_op.rhs_val.?); // we checked the operand was resolvable above25513 const operand_val = try sema.resolveLazyValue(simd_op.rhs_val.?); // we checked the operand was resolvable above
2551025514
25511 const vec_len = simd_op.len orelse {25515 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);
25513 cur_minmax = Air.internedToRef(result_val.toIntern());25517 cur_minmax = Air.internedToRef(result_val.toIntern());
25514 continue;25518 continue;
25515 };25519 };
...@@ -25517,7 +25521,7 @@ fn analyzeMinMax(...@@ -25517,7 +25521,7 @@ fn analyzeMinMax(
25517 for (elems, 0..) |*elem, i| {25521 for (elems, 0..) |*elem, i| {
25518 const lhs_elem_val = try cur_val.elemValue(pt, i);25522 const lhs_elem_val = try cur_val.elemValue(pt, i);
25519 const rhs_elem_val = try operand_val.elemValue(pt, i);25523 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);
25521 elem.* = (try pt.getCoerced(uncoerced_elem, simd_op.scalar_ty)).toIntern();25525 elem.* = (try pt.getCoerced(uncoerced_elem, simd_op.scalar_ty)).toIntern();
25522 }25526 }
25523 cur_minmax = Air.internedToRef((try pt.intern(.{ .aggregate = .{25527 cur_minmax = Air.internedToRef((try pt.intern(.{ .aggregate = .{
...@@ -25537,19 +25541,19 @@ fn analyzeMinMax(...@@ -25537,19 +25541,19 @@ fn analyzeMinMax(
25537 const val = (try sema.resolveValue(ct_minmax_ref)).?;25541 const val = (try sema.resolveValue(ct_minmax_ref)).?;
25538 const orig_ty = sema.typeOf(ct_minmax_ref);25542 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)) {
25541 // If all arguments were `comptime_int`, and there are no runtime args, we'll preserve that type25545 // If all arguments were `comptime_int`, and there are no runtime args, we'll preserve that type
25542 break :refine;25546 break :refine;
25543 }25547 }
2554425548
25545 // We can't refine float types25549 // 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
25548 assert(bounds_status == .defined); // there was a non-comptime-int integral comptime-known arg25552 assert(bounds_status == .defined); // there was a non-comptime-int integral comptime-known arg
2554925553
25550 const refined_scalar_ty = try pt.intFittingRange(cur_min_scalar, cur_max_scalar);25554 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(.{25555 const refined_ty = if (orig_ty.isVector(zcu)) try pt.vectorType(.{
25552 .len = orig_ty.vectorLen(mod),25556 .len = orig_ty.vectorLen(zcu),
25553 .child = refined_scalar_ty.toIntern(),25557 .child = refined_scalar_ty.toIntern(),
25554 }) else refined_scalar_ty;25558 }) else refined_scalar_ty;
2555525559
...@@ -25570,7 +25574,7 @@ fn analyzeMinMax(...@@ -25570,7 +25574,7 @@ fn analyzeMinMax(
25570 // If the comptime-known part is undef we can avoid emitting actual instructions later25574 // If the comptime-known part is undef we can avoid emitting actual instructions later
25571 const known_undef = if (cur_minmax) |operand| blk: {25575 const known_undef = if (cur_minmax) |operand| blk: {
25572 const val = (try sema.resolveValue(operand)).?;25576 const val = (try sema.resolveValue(operand)).?;
25573 break :blk val.isUndef(mod);25577 break :blk val.isUndef(zcu);
25574 } else false;25578 } else false;
2557525579
25576 if (cur_minmax == null) {25580 if (cur_minmax == null) {
...@@ -25580,8 +25584,8 @@ fn analyzeMinMax(...@@ -25580,8 +25584,8 @@ fn analyzeMinMax(
25580 cur_minmax = operands[0];25584 cur_minmax = operands[0];
25581 cur_minmax_src = runtime_src;25585 cur_minmax_src = runtime_src;
25582 runtime_known.unset(0); // don't look at this operand in the loop below25586 runtime_known.unset(0); // don't look at this operand in the loop below
25583 const scalar_ty = sema.typeOf(cur_minmax.?).scalarType(mod);25587 const scalar_ty = sema.typeOf(cur_minmax.?).scalarType(zcu);
25584 if (scalar_ty.isInt(mod)) {25588 if (scalar_ty.isInt(zcu)) {
25585 cur_min_scalar = try scalar_ty.minInt(pt, scalar_ty);25589 cur_min_scalar = try scalar_ty.minInt(pt, scalar_ty);
25586 cur_max_scalar = try scalar_ty.maxInt(pt, scalar_ty);25590 cur_max_scalar = try scalar_ty.maxInt(pt, scalar_ty);
25587 bounds_status = .defined;25591 bounds_status = .defined;
...@@ -25605,7 +25609,7 @@ fn analyzeMinMax(...@@ -25605,7 +25609,7 @@ fn analyzeMinMax(
25605 // Compute the bounds of this type25609 // Compute the bounds of this type
25606 switch (bounds_status) {25610 switch (bounds_status) {
25607 .unknown, .defined => refine_bounds: {25611 .unknown, .defined => refine_bounds: {
25608 const scalar_ty = sema.typeOf(rhs).scalarType(mod);25612 const scalar_ty = sema.typeOf(rhs).scalarType(zcu);
25609 if (scalar_ty.isAnyFloat()) {25613 if (scalar_ty.isAnyFloat()) {
25610 bounds_status = .non_integral;25614 bounds_status = .non_integral;
25611 break :refine_bounds;25615 break :refine_bounds;
...@@ -25617,8 +25621,8 @@ fn analyzeMinMax(...@@ -25617,8 +25621,8 @@ fn analyzeMinMax(
25617 cur_max_scalar = scalar_max;25621 cur_max_scalar = scalar_max;
25618 bounds_status = .defined;25622 bounds_status = .defined;
25619 } else {25623 } else {
25620 cur_min_scalar = opFunc(cur_min_scalar, scalar_min, pt);25624 cur_min_scalar = opFunc(cur_min_scalar, scalar_min, zcu);
25621 cur_max_scalar = opFunc(cur_max_scalar, scalar_max, pt);25625 cur_max_scalar = opFunc(cur_max_scalar, scalar_max, zcu);
25622 }25626 }
25623 },25627 },
25624 .non_integral => {},25628 .non_integral => {},
...@@ -25627,18 +25631,18 @@ fn analyzeMinMax(...@@ -25627,18 +25631,18 @@ fn analyzeMinMax(
2562725631
25628 // Finally, refine the type based on the known bounds.25632 // Finally, refine the type based on the known bounds.
25629 const unrefined_ty = sema.typeOf(cur_minmax.?);25633 const unrefined_ty = sema.typeOf(cur_minmax.?);
25630 if (unrefined_ty.scalarType(mod).isAnyFloat()) {25634 if (unrefined_ty.scalarType(zcu).isAnyFloat()) {
25631 // We can't refine floats, so we're done.25635 // We can't refine floats, so we're done.
25632 return cur_minmax.?;25636 return cur_minmax.?;
25633 }25637 }
25634 assert(bounds_status == .defined); // there were integral runtime operands25638 assert(bounds_status == .defined); // there were integral runtime operands
25635 const refined_scalar_ty = try pt.intFittingRange(cur_min_scalar, cur_max_scalar);25639 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(.{25640 const refined_ty = if (unrefined_ty.isVector(zcu)) try pt.vectorType(.{
25637 .len = unrefined_ty.vectorLen(mod),25641 .len = unrefined_ty.vectorLen(zcu),
25638 .child = refined_scalar_ty.toIntern(),25642 .child = refined_scalar_ty.toIntern(),
25639 }) else refined_scalar_ty;25643 }) else refined_scalar_ty;
2564025644
25641 if (!refined_ty.eql(unrefined_ty, mod)) {25645 if (!refined_ty.eql(unrefined_ty, zcu)) {
25642 // We've reduced the type - cast the result down25646 // We've reduced the type - cast the result down
25643 return block.addTyOp(.intcast, refined_ty, cur_minmax.?);25647 return block.addTyOp(.intcast, refined_ty, cur_minmax.?);
25644 }25648 }
...@@ -25648,9 +25652,9 @@ fn analyzeMinMax(...@@ -25648,9 +25652,9 @@ fn analyzeMinMax(
2564825652
25649fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !Air.Inst.Ref {25653fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !Air.Inst.Ref {
25650 const pt = sema.pt;25654 const pt = sema.pt;
25651 const mod = pt.zcu;25655 const zcu = pt.zcu;
25652 const ptr_ty = sema.typeOf(ptr);25656 const ptr_ty = sema.typeOf(ptr);
25653 const info = ptr_ty.ptrInfo(mod);25657 const info = ptr_ty.ptrInfo(zcu);
25654 if (info.flags.size == .One) {25658 if (info.flags.size == .One) {
25655 // Already an array pointer.25659 // Already an array pointer.
25656 return ptr;25660 return ptr;
...@@ -25670,7 +25674,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A...@@ -25670,7 +25674,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
25670 },25674 },
25671 });25675 });
25672 const non_slice_ptr = if (info.flags.size == .Slice)25676 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)
25674 else25678 else
25675 ptr;25679 ptr;
25676 return block.addBitCast(new_ty, non_slice_ptr);25680 return block.addBitCast(new_ty, non_slice_ptr);
...@@ -25689,10 +25693,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25689,10 +25693,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25689 const dest_len = try indexablePtrLenOrNone(sema, block, dest_src, dest_ptr);25693 const dest_len = try indexablePtrLenOrNone(sema, block, dest_src, dest_ptr);
25690 const src_len = try indexablePtrLenOrNone(sema, block, src_src, src_ptr);25694 const src_len = try indexablePtrLenOrNone(sema, block, src_src, src_ptr);
25691 const pt = sema.pt;25695 const pt = sema.pt;
25692 const mod = pt.zcu;25696 const zcu = pt.zcu;
25693 const target = mod.getTarget();25697 const target = zcu.getTarget();
2569425698
25695 if (dest_ty.isConstPtr(mod)) {25699 if (dest_ty.isConstPtr(zcu)) {
25696 return sema.fail(block, dest_src, "cannot memcpy to constant pointer", .{});25700 return sema.fail(block, dest_src, "cannot memcpy to constant pointer", .{});
25697 }25701 }
2569825702
...@@ -25755,7 +25759,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25755,7 +25759,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25755 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {25759 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {
25756 if (!sema.isComptimeMutablePtr(dest_ptr_val)) break :rs dest_src;25760 if (!sema.isComptimeMutablePtr(dest_ptr_val)) break :rs dest_src;
25757 if (try sema.resolveDefinedValue(block, src_src, src_ptr)) |_| {25761 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);
25759 const len = try sema.usizeCast(block, dest_src, len_u64);25763 const len = try sema.usizeCast(block, dest_src, len_u64);
25760 for (0..len) |i| {25764 for (0..len) |i| {
25761 const elem_index = try pt.intRef(Type.usize, i);25765 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...@@ -25798,12 +25802,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25798 // lowering. The AIR instruction requires pointers with element types of25802 // lowering. The AIR instruction requires pointers with element types of
25799 // equal ABI size.25803 // 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) {
25802 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the source or destination iterable is a tuple", .{});25806 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the source or destination iterable is a tuple", .{});
25803 }25807 }
2580425808
25805 const dest_elem_ty = dest_ty.elemType2(mod);25809 const dest_elem_ty = dest_ty.elemType2(zcu);
25806 const src_elem_ty = src_ty.elemType2(mod);25810 const src_elem_ty = src_ty.elemType2(zcu);
25807 if (.ok != try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, true, target, dest_src, src_src, null)) {25811 if (.ok != try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, true, target, dest_src, src_src, null)) {
25808 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the element types have different ABI sizes", .{});25812 return sema.fail(block, src, "TODO: lower @memcpy to a for loop because the element types have different ABI sizes", .{});
25809 }25813 }
...@@ -25827,7 +25831,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25827,7 +25831,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25827 // Change the src from slice to a many pointer, to avoid multiple ptr25831 // Change the src from slice to a many pointer, to avoid multiple ptr
25828 // slice extractions in AIR instructions.25832 // slice extractions in AIR instructions.
25829 const new_src_ptr_ty = sema.typeOf(new_src_ptr);25833 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)) {
25831 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);25835 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
25832 }25836 }
25833 } else if (dest_len == .none and len_val == null) {25837 } 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...@@ -25835,7 +25839,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25835 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);25839 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
25836 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);25840 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);
25837 const new_src_ptr_ty = sema.typeOf(new_src_ptr);25841 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)) {
25839 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);25843 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
25840 }25844 }
25841 }25845 }
...@@ -25854,10 +25858,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25854,10 +25858,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25854 // Extract raw pointer from dest slice. The AIR instructions could support them, but25858 // Extract raw pointer from dest slice. The AIR instructions could support them, but
25855 // it would cause redundant machine code instructions.25859 // it would cause redundant machine code instructions.
25856 const new_dest_ptr_ty = sema.typeOf(new_dest_ptr);25860 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))
25858 try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty)25862 try sema.analyzeSlicePtr(block, dest_src, new_dest_ptr, new_dest_ptr_ty)
25859 else if (new_dest_ptr_ty.ptrSize(mod) == .One) ptr: {25863 else if (new_dest_ptr_ty.ptrSize(zcu) == .One) ptr: {
25860 var dest_manyptr_ty_key = mod.intern_pool.indexToKey(new_dest_ptr_ty.toIntern()).ptr_type;25864 var dest_manyptr_ty_key = zcu.intern_pool.indexToKey(new_dest_ptr_ty.toIntern()).ptr_type;
25861 assert(dest_manyptr_ty_key.flags.size == .One);25865 assert(dest_manyptr_ty_key.flags.size == .One);
25862 dest_manyptr_ty_key.child = dest_elem_ty.toIntern();25866 dest_manyptr_ty_key.child = dest_elem_ty.toIntern();
25863 dest_manyptr_ty_key.flags.size = .Many;25867 dest_manyptr_ty_key.flags.size = .Many;
...@@ -25865,10 +25869,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25865,10 +25869,10 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25865 } else new_dest_ptr;25869 } else new_dest_ptr;
2586625870
25867 const new_src_ptr_ty = sema.typeOf(new_src_ptr);25871 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))
25869 try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty)25873 try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty)
25870 else if (new_src_ptr_ty.ptrSize(mod) == .One) ptr: {25874 else if (new_src_ptr_ty.ptrSize(zcu) == .One) ptr: {
25871 var src_manyptr_ty_key = mod.intern_pool.indexToKey(new_src_ptr_ty.toIntern()).ptr_type;25875 var src_manyptr_ty_key = zcu.intern_pool.indexToKey(new_src_ptr_ty.toIntern()).ptr_type;
25872 assert(src_manyptr_ty_key.flags.size == .One);25876 assert(src_manyptr_ty_key.flags.size == .One);
25873 src_manyptr_ty_key.child = src_elem_ty.toIntern();25877 src_manyptr_ty_key.child = src_elem_ty.toIntern();
25874 src_manyptr_ty_key.flags.size = .Many;25878 src_manyptr_ty_key.flags.size = .Many;
...@@ -25896,9 +25900,9 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25896,9 +25900,9 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2589625900
25897fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {25901fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
25898 const pt = sema.pt;25902 const pt = sema.pt;
25899 const mod = pt.zcu;25903 const zcu = pt.zcu;
25900 const gpa = sema.gpa;25904 const gpa = sema.gpa;
25901 const ip = &mod.intern_pool;25905 const ip = &zcu.intern_pool;
25902 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25906 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25903 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25907 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25904 const src = block.nodeOffset(inst_data.src_node);25908 const src = block.nodeOffset(inst_data.src_node);
...@@ -25909,17 +25913,17 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25909,17 +25913,17 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25909 const dest_ptr_ty = sema.typeOf(dest_ptr);25913 const dest_ptr_ty = sema.typeOf(dest_ptr);
25910 try checkMemOperand(sema, block, dest_src, dest_ptr_ty);25914 try checkMemOperand(sema, block, dest_src, dest_ptr_ty);
2591125915
25912 if (dest_ptr_ty.isConstPtr(mod)) {25916 if (dest_ptr_ty.isConstPtr(zcu)) {
25913 return sema.fail(block, dest_src, "cannot memset constant pointer", .{});25917 return sema.fail(block, dest_src, "cannot memset constant pointer", .{});
25914 }25918 }
2591525919
25916 const dest_elem_ty: Type = dest_elem_ty: {25920 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);
25918 switch (ptr_info.flags.size) {25922 switch (ptr_info.flags.size) {
25919 .Slice => break :dest_elem_ty Type.fromInterned(ptr_info.child),25923 .Slice => break :dest_elem_ty Type.fromInterned(ptr_info.child),
25920 .One => {25924 .One => {
25921 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {25925 if (Type.fromInterned(ptr_info.child).zigTypeTag(zcu) == .Array) {
25922 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(mod);25926 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(zcu);
25923 }25927 }
25924 },25928 },
25925 .Many, .C => {},25929 .Many, .C => {},
...@@ -25940,7 +25944,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25940,7 +25944,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25940 const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;25944 const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src;
25941 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), dest_src);25945 const len_air_ref = try sema.fieldVal(block, src, dest_ptr, try ip.getOrPutString(gpa, pt.tid, "len", .no_embedded_nulls), dest_src);
25942 const len_val = (try sema.resolveDefinedValue(block, dest_src, len_air_ref)) orelse break :rs dest_src;25946 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);
25944 const len = try sema.usizeCast(block, dest_src, len_u64);25948 const len = try sema.usizeCast(block, dest_src, len_u64);
25945 if (len == 0) {25949 if (len == 0) {
25946 // This AIR instruction guarantees length > 0 if it is comptime-known.25950 // 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...@@ -25958,12 +25962,12 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25958 .storage = .{ .repeated_elem = elem_val.toIntern() },25962 .storage = .{ .repeated_elem = elem_val.toIntern() },
25959 } }));25963 } }));
25960 const array_ptr_ty = ty: {25964 const array_ptr_ty = ty: {
25961 var info = dest_ptr_ty.ptrInfo(mod);25965 var info = dest_ptr_ty.ptrInfo(zcu);
25962 info.flags.size = .One;25966 info.flags.size = .One;
25963 info.child = array_ty.toIntern();25967 info.child = array_ty.toIntern();
25964 break :ty try pt.ptrType(info);25968 break :ty try pt.ptrType(info);
25965 };25969 };
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;
25967 const array_ptr_val = try pt.getCoerced(raw_ptr_val, array_ptr_ty);25971 const array_ptr_val = try pt.getCoerced(raw_ptr_val, array_ptr_ty);
25968 return sema.storePtrVal(block, src, array_ptr_val, array_val, array_ty);25972 return sema.storePtrVal(block, src, array_ptr_val, array_val, array_ty);
25969 };25973 };
...@@ -26129,10 +26133,10 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26129,10 +26133,10 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26129 defer tracy.end();26133 defer tracy.end();
2613026134
26131 const pt = sema.pt;26135 const pt = sema.pt;
26132 const mod = pt.zcu;26136 const zcu = pt.zcu;
26133 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;26137 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
26134 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);26138 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
26135 const target = mod.getTarget();26139 const target = zcu.getTarget();
2613626140
26137 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });26141 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });
26138 const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node });26142 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...@@ -26207,7 +26211,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26207 if (val.isGenericPoison()) {26211 if (val.isGenericPoison()) {
26208 break :blk null;26212 break :blk null;
26209 }26213 }
26210 break :blk mod.toEnum(std.builtin.AddressSpace, val);26214 break :blk zcu.toEnum(std.builtin.AddressSpace, val);
26211 } else if (extra.data.bits.has_addrspace_ref) blk: {26215 } else if (extra.data.bits.has_addrspace_ref) blk: {
26212 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);26216 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
26213 extra_index += 1;26217 extra_index += 1;
...@@ -26226,7 +26230,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26226,7 +26230,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26226 error.GenericPoison => break :blk null,26230 error.GenericPoison => break :blk null,
26227 else => |e| return e,26231 else => |e| return e,
26228 };26232 };
26229 break :blk mod.toEnum(std.builtin.AddressSpace, addrspace_val);26233 break :blk zcu.toEnum(std.builtin.AddressSpace, addrspace_val);
26230 } else target_util.defaultAddressSpace(target, .function);26234 } else target_util.defaultAddressSpace(target, .function);
2623126235
26232 const section: Section = if (extra.data.bits.has_section_body) blk: {26236 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...@@ -26272,7 +26276,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26272 if (val.isGenericPoison()) {26276 if (val.isGenericPoison()) {
26273 break :blk null;26277 break :blk null;
26274 }26278 }
26275 break :blk mod.toEnum(std.builtin.CallingConvention, val);26279 break :blk zcu.toEnum(std.builtin.CallingConvention, val);
26276 } else if (extra.data.bits.has_cc_ref) blk: {26280 } else if (extra.data.bits.has_cc_ref) blk: {
26277 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);26281 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
26278 extra_index += 1;26282 extra_index += 1;
...@@ -26291,18 +26295,18 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26291,18 +26295,18 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
26291 error.GenericPoison => break :blk null,26295 error.GenericPoison => break :blk null,
26292 else => |e| return e,26296 else => |e| return e,
26293 };26297 };
26294 break :blk mod.toEnum(std.builtin.CallingConvention, cc_val);26298 break :blk zcu.toEnum(std.builtin.CallingConvention, cc_val);
26295 } else cc: {26299 } else cc: {
26296 if (has_body) {26300 if (has_body) {
26297 const decl_inst = if (sema.generic_owner != .none) decl_inst: {26301 const decl_inst = if (sema.generic_owner != .none) decl_inst: {
26298 // Generic instance -- use the original function declaration to26302 // Generic instance -- use the original function declaration to
26299 // look for the `export` syntax.26303 // look for the `export` syntax.
26300 const nav = mod.intern_pool.getNav(mod.funcInfo(sema.generic_owner).owner_nav);26304 const nav = zcu.intern_pool.getNav(zcu.funcInfo(sema.generic_owner).owner_nav);
26301 const cau = mod.intern_pool.getCau(nav.analysis_owner.unwrap().?);26305 const cau = zcu.intern_pool.getCau(nav.analysis_owner.unwrap().?);
26302 break :decl_inst cau.zir_index;26306 break :decl_inst cau.zir_index;
26303 } else sema.getOwnerCauDeclInst(); // not an instantiation so we're analyzing a function declaration Cau26307 } 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];
26306 if (zir_decl.flags.is_export) {26310 if (zir_decl.flags.is_export) {
26307 break :cc .C;26311 break :cc .C;
26308 }26312 }
...@@ -26408,7 +26412,7 @@ fn zirCDefine(...@@ -26408,7 +26412,7 @@ fn zirCDefine(
26408 extended: Zir.Inst.Extended.InstData,26412 extended: Zir.Inst.Extended.InstData,
26409) CompileError!Air.Inst.Ref {26413) CompileError!Air.Inst.Ref {
26410 const pt = sema.pt;26414 const pt = sema.pt;
26411 const mod = pt.zcu;26415 const zcu = pt.zcu;
26412 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26416 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26413 const name_src = block.builtinCallArgSrc(extra.node, 0);26417 const name_src = block.builtinCallArgSrc(extra.node, 0);
26414 const val_src = block.builtinCallArgSrc(extra.node, 1);26418 const val_src = block.builtinCallArgSrc(extra.node, 1);
...@@ -26417,7 +26421,7 @@ fn zirCDefine(...@@ -26417,7 +26421,7 @@ fn zirCDefine(
26417 .needed_comptime_reason = "name of macro being undefined must be comptime-known",26421 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
26418 });26422 });
26419 const rhs = try sema.resolveInst(extra.rhs);26423 const rhs = try sema.resolveInst(extra.rhs);
26420 if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) {26424 if (sema.typeOf(rhs).zigTypeTag(zcu) != .Void) {
26421 const value = try sema.resolveConstString(block, val_src, extra.rhs, .{26425 const value = try sema.resolveConstString(block, val_src, extra.rhs, .{
26422 .needed_comptime_reason = "value of macro being undefined must be comptime-known",26426 .needed_comptime_reason = "value of macro being undefined must be comptime-known",
26423 });26427 });
...@@ -26490,9 +26494,9 @@ fn resolvePrefetchOptions(...@@ -26490,9 +26494,9 @@ fn resolvePrefetchOptions(
26490 zir_ref: Zir.Inst.Ref,26494 zir_ref: Zir.Inst.Ref,
26491) CompileError!std.builtin.PrefetchOptions {26495) CompileError!std.builtin.PrefetchOptions {
26492 const pt = sema.pt;26496 const pt = sema.pt;
26493 const mod = pt.zcu;26497 const zcu = pt.zcu;
26494 const gpa = sema.gpa;26498 const gpa = sema.gpa;
26495 const ip = &mod.intern_pool;26499 const ip = &zcu.intern_pool;
26496 const options_ty = try pt.getBuiltinType("PrefetchOptions");26500 const options_ty = try pt.getBuiltinType("PrefetchOptions");
26497 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);26501 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2649826502
...@@ -26516,9 +26520,9 @@ fn resolvePrefetchOptions(...@@ -26516,9 +26520,9 @@ fn resolvePrefetchOptions(
26516 });26520 });
2651726521
26518 return std.builtin.PrefetchOptions{26522 return std.builtin.PrefetchOptions{
26519 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),26523 .rw = zcu.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
26520 .locality = @intCast(try locality_val.toUnsignedIntSema(pt)),26524 .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),
26522 };26526 };
26523}26527}
2652426528
...@@ -26562,9 +26566,9 @@ fn resolveExternOptions(...@@ -26562,9 +26566,9 @@ fn resolveExternOptions(
26562 is_thread_local: bool = false,26566 is_thread_local: bool = false,
26563} {26567} {
26564 const pt = sema.pt;26568 const pt = sema.pt;
26565 const mod = pt.zcu;26569 const zcu = pt.zcu;
26566 const gpa = sema.gpa;26570 const gpa = sema.gpa;
26567 const ip = &mod.intern_pool;26571 const ip = &zcu.intern_pool;
26568 const options_inst = try sema.resolveInst(zir_ref);26572 const options_inst = try sema.resolveInst(zir_ref);
26569 const extern_options_ty = try pt.getBuiltinType("ExternOptions");26573 const extern_options_ty = try pt.getBuiltinType("ExternOptions");
26570 const options = try sema.coerce(block, extern_options_ty, options_inst, src);26574 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
...@@ -26588,14 +26592,14 @@ fn resolveExternOptions(...@@ -26588,14 +26592,14 @@ fn resolveExternOptions(
26588 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{26592 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
26589 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",26593 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
26590 });26594 });
26591 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);26595 const linkage = zcu.toEnum(std.builtin.GlobalLinkage, linkage_val);
2659226596
26593 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);26597 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);
26594 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{26598 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
26595 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",26599 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
26596 });26600 });
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: {
26599 const library_name = try sema.toConstString(block, library_src, Air.internedToRef(library_name_payload.toIntern()), .{26603 const library_name = try sema.toConstString(block, library_src, Air.internedToRef(library_name_payload.toIntern()), .{
26600 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",26604 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
26601 });26605 });
...@@ -26628,14 +26632,14 @@ fn zirBuiltinExtern(...@@ -26628,14 +26632,14 @@ fn zirBuiltinExtern(
26628 extended: Zir.Inst.Extended.InstData,26632 extended: Zir.Inst.Extended.InstData,
26629) CompileError!Air.Inst.Ref {26633) CompileError!Air.Inst.Ref {
26630 const pt = sema.pt;26634 const pt = sema.pt;
26631 const mod = pt.zcu;26635 const zcu = pt.zcu;
26632 const ip = &mod.intern_pool;26636 const ip = &zcu.intern_pool;
26633 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26637 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26634 const ty_src = block.builtinCallArgSrc(extra.node, 0);26638 const ty_src = block.builtinCallArgSrc(extra.node, 0);
26635 const options_src = block.builtinCallArgSrc(extra.node, 1);26639 const options_src = block.builtinCallArgSrc(extra.node, 1);
2663626640
26637 var ty = try sema.resolveType(block, ty_src, extra.lhs);26641 var ty = try sema.resolveType(block, ty_src, extra.lhs);
26638 if (!ty.isPtrAtRuntime(mod)) {26642 if (!ty.isPtrAtRuntime(zcu)) {
26639 return sema.fail(block, ty_src, "expected (optional) pointer", .{});26643 return sema.fail(block, ty_src, "expected (optional) pointer", .{});
26640 }26644 }
26641 if (!try sema.validateExternType(ty, .other)) {26645 if (!try sema.validateExternType(ty, .other)) {
...@@ -26652,10 +26656,10 @@ fn zirBuiltinExtern(...@@ -26652,10 +26656,10 @@ fn zirBuiltinExtern(
2665226656
26653 // TODO: error for threadlocal functions, non-const functions, etc26657 // 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)) {
26656 ty = try pt.optionalType(ty.toIntern());26660 ty = try pt.optionalType(ty.toIntern());
26657 }26661 }
26658 const ptr_info = ty.ptrInfo(mod);26662 const ptr_info = ty.ptrInfo(zcu);
2665926663
26660 const extern_val = try pt.getExtern(.{26664 const extern_val = try pt.getExtern(.{
26661 .name = options.name,26665 .name = options.name,
...@@ -26801,7 +26805,7 @@ fn validateVarType(...@@ -26801,7 +26805,7 @@ fn validateVarType(
26801 is_extern: bool,26805 is_extern: bool,
26802) CompileError!void {26806) CompileError!void {
26803 const pt = sema.pt;26807 const pt = sema.pt;
26804 const mod = pt.zcu;26808 const zcu = pt.zcu;
26805 if (is_extern) {26809 if (is_extern) {
26806 if (!try sema.validateExternType(var_ty, .other)) {26810 if (!try sema.validateExternType(var_ty, .other)) {
26807 const msg = msg: {26811 const msg = msg: {
...@@ -26813,7 +26817,7 @@ fn validateVarType(...@@ -26813,7 +26817,7 @@ fn validateVarType(
26813 return sema.failWithOwnedErrorMsg(block, msg);26817 return sema.failWithOwnedErrorMsg(block, msg);
26814 }26818 }
26815 } else {26819 } else {
26816 if (var_ty.zigTypeTag(mod) == .Opaque) {26820 if (var_ty.zigTypeTag(zcu) == .Opaque) {
26817 return sema.fail(26821 return sema.fail(
26818 block,26822 block,
26819 src,26823 src,
...@@ -26823,14 +26827,14 @@ fn validateVarType(...@@ -26823,14 +26827,14 @@ fn validateVarType(
26823 }26827 }
26824 }26828 }
2682526829
26826 if (!try sema.typeRequiresComptime(var_ty)) return;26830 if (!try var_ty.comptimeOnlySema(pt)) return;
2682726831
26828 const msg = msg: {26832 const msg = msg: {
26829 const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(pt)});26833 const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(pt)});
26830 errdefer msg.destroy(sema.gpa);26834 errdefer msg.destroy(sema.gpa);
2683126835
26832 try sema.explainWhyTypeIsComptime(msg, src, var_ty);26836 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) {
26834 try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});26838 try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
26835 }26839 }
2683626840
...@@ -26843,7 +26847,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);...@@ -26843,7 +26847,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
2684326847
26844fn explainWhyTypeIsComptime(26848fn explainWhyTypeIsComptime(
26845 sema: *Sema,26849 sema: *Sema,
26846 msg: *Module.ErrorMsg,26850 msg: *Zcu.ErrorMsg,
26847 src_loc: LazySrcLoc,26851 src_loc: LazySrcLoc,
26848 ty: Type,26852 ty: Type,
26849) CompileError!void {26853) CompileError!void {
...@@ -26856,15 +26860,15 @@ fn explainWhyTypeIsComptime(...@@ -26856,15 +26860,15 @@ fn explainWhyTypeIsComptime(
2685626860
26857fn explainWhyTypeIsComptimeInner(26861fn explainWhyTypeIsComptimeInner(
26858 sema: *Sema,26862 sema: *Sema,
26859 msg: *Module.ErrorMsg,26863 msg: *Zcu.ErrorMsg,
26860 src_loc: LazySrcLoc,26864 src_loc: LazySrcLoc,
26861 ty: Type,26865 ty: Type,
26862 type_set: *TypeSet,26866 type_set: *TypeSet,
26863) CompileError!void {26867) CompileError!void {
26864 const pt = sema.pt;26868 const pt = sema.pt;
26865 const mod = pt.zcu;26869 const zcu = pt.zcu;
26866 const ip = &mod.intern_pool;26870 const ip = &zcu.intern_pool;
26867 switch (ty.zigTypeTag(mod)) {26871 switch (ty.zigTypeTag(zcu)) {
26868 .Bool,26872 .Bool,
26869 .Int,26873 .Int,
26870 .Float,26874 .Float,
...@@ -26896,12 +26900,12 @@ fn explainWhyTypeIsComptimeInner(...@@ -26896,12 +26900,12 @@ fn explainWhyTypeIsComptimeInner(
26896 },26900 },
2689726901
26898 .Array, .Vector => {26902 .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);
26900 },26904 },
26901 .Pointer => {26905 .Pointer => {
26902 const elem_ty = ty.elemType2(mod);26906 const elem_ty = ty.elemType2(zcu);
26903 if (elem_ty.zigTypeTag(mod) == .Fn) {26907 if (elem_ty.zigTypeTag(zcu) == .Fn) {
26904 const fn_info = mod.typeToFunc(elem_ty).?;26908 const fn_info = zcu.typeToFunc(elem_ty).?;
26905 if (fn_info.is_generic) {26909 if (fn_info.is_generic) {
26906 try sema.errNote(src_loc, msg, "function is generic", .{});26910 try sema.errNote(src_loc, msg, "function is generic", .{});
26907 }26911 }
...@@ -26909,25 +26913,25 @@ fn explainWhyTypeIsComptimeInner(...@@ -26909,25 +26913,25 @@ fn explainWhyTypeIsComptimeInner(
26909 .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}),26913 .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}),
26910 else => {},26914 else => {},
26911 }26915 }
26912 if (Type.fromInterned(fn_info.return_type).comptimeOnly(pt)) {26916 if (Type.fromInterned(fn_info.return_type).comptimeOnly(zcu)) {
26913 try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{});26917 try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{});
26914 }26918 }
26915 return;26919 return;
26916 }26920 }
26917 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(mod), type_set);26921 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(zcu), type_set);
26918 },26922 },
2691926923
26920 .Optional => {26924 .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);
26922 },26926 },
26923 .ErrorUnion => {26927 .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);
26925 },26929 },
2692626930
26927 .Struct => {26931 .Struct => {
26928 if ((try type_set.getOrPut(sema.gpa, ty.toIntern())).found_existing) return;26932 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| {
26931 for (0..struct_type.field_types.len) |i| {26935 for (0..struct_type.field_types.len) |i| {
26932 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);26936 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
26933 const field_src: LazySrcLoc = .{26937 const field_src: LazySrcLoc = .{
...@@ -26935,7 +26939,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -26935,7 +26939,7 @@ fn explainWhyTypeIsComptimeInner(
26935 .offset = .{ .container_field_type = @intCast(i) },26939 .offset = .{ .container_field_type = @intCast(i) },
26936 };26940 };
2693726941
26938 if (try sema.typeRequiresComptime(field_ty)) {26942 if (try field_ty.comptimeOnlySema(pt)) {
26939 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});26943 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});
26940 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);26944 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
26941 }26945 }
...@@ -26947,7 +26951,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -26947,7 +26951,7 @@ fn explainWhyTypeIsComptimeInner(
26947 .Union => {26951 .Union => {
26948 if ((try type_set.getOrPut(sema.gpa, ty.toIntern())).found_existing) return;26952 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| {
26951 for (0..union_obj.field_types.len) |i| {26955 for (0..union_obj.field_types.len) |i| {
26952 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);26956 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
26953 const field_src: LazySrcLoc = .{26957 const field_src: LazySrcLoc = .{
...@@ -26955,7 +26959,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -26955,7 +26959,7 @@ fn explainWhyTypeIsComptimeInner(
26955 .offset = .{ .container_field_type = @intCast(i) },26959 .offset = .{ .container_field_type = @intCast(i) },
26956 };26960 };
2695726961
26958 if (try sema.typeRequiresComptime(field_ty)) {26962 if (try field_ty.comptimeOnlySema(pt)) {
26959 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});26963 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});
26960 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);26964 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
26961 }26965 }
...@@ -26983,8 +26987,8 @@ fn validateExternType(...@@ -26983,8 +26987,8 @@ fn validateExternType(
26983 position: ExternPosition,26987 position: ExternPosition,
26984) !bool {26988) !bool {
26985 const pt = sema.pt;26989 const pt = sema.pt;
26986 const mod = pt.zcu;26990 const zcu = pt.zcu;
26987 switch (ty.zigTypeTag(mod)) {26991 switch (ty.zigTypeTag(zcu)) {
26988 .Type,26992 .Type,
26989 .ComptimeFloat,26993 .ComptimeFloat,
26990 .ComptimeInt,26994 .ComptimeInt,
...@@ -27003,58 +27007,58 @@ fn validateExternType(...@@ -27003,58 +27007,58 @@ fn validateExternType(
27003 .AnyFrame,27007 .AnyFrame,
27004 => return true,27008 => return true,
27005 .Pointer => {27009 .Pointer => {
27006 if (ty.childType(mod).zigTypeTag(mod) == .Fn) {27010 if (ty.childType(zcu).zigTypeTag(zcu) == .Fn) {
27007 return ty.isConstPtr(mod) and try sema.validateExternType(ty.childType(mod), .other);27011 return ty.isConstPtr(zcu) and try sema.validateExternType(ty.childType(zcu), .other);
27008 }27012 }
27009 return !(ty.isSlice(mod) or try sema.typeRequiresComptime(ty));27013 return !(ty.isSlice(zcu) or try ty.comptimeOnlySema(pt));
27010 },27014 },
27011 .Int => switch (ty.intInfo(mod).bits) {27015 .Int => switch (ty.intInfo(zcu).bits) {
27012 0, 8, 16, 32, 64, 128 => return true,27016 0, 8, 16, 32, 64, 128 => return true,
27013 else => return false,27017 else => return false,
27014 },27018 },
27015 .Fn => {27019 .Fn => {
27016 if (position != .other) return false;27020 if (position != .other) return false;
27017 const target = mod.getTarget();27021 const target = zcu.getTarget();
27018 // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI.27022 // For now we want to authorize PTX kernel to use zig objects, even if we end up exposing the ABI.
27019 // The goal is to experiment with more integrated CPU/GPU code.27023 // 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)) {
27021 return true;27025 return true;
27022 }27026 }
27023 return !target_util.fnCallConvAllowsZigTypes(target, ty.fnCallingConvention(mod));27027 return !target_util.fnCallConvAllowsZigTypes(target, ty.fnCallingConvention(zcu));
27024 },27028 },
27025 .Enum => {27029 .Enum => {
27026 return sema.validateExternType(ty.intTagType(mod), position);27030 return sema.validateExternType(ty.intTagType(zcu), position);
27027 },27031 },
27028 .Struct, .Union => switch (ty.containerLayout(mod)) {27032 .Struct, .Union => switch (ty.containerLayout(zcu)) {
27029 .@"extern" => return true,27033 .@"extern" => return true,
27030 .@"packed" => {27034 .@"packed" => {
27031 const bit_size = try ty.bitSizeAdvanced(pt, .sema);27035 const bit_size = try ty.bitSizeSema(pt);
27032 switch (bit_size) {27036 switch (bit_size) {
27033 0, 8, 16, 32, 64, 128 => return true,27037 0, 8, 16, 32, 64, 128 => return true,
27034 else => return false,27038 else => return false,
27035 }27039 }
27036 },27040 },
27037 .auto => return !(try sema.typeHasRuntimeBits(ty)),27041 .auto => return !(try ty.hasRuntimeBitsSema(pt)),
27038 },27042 },
27039 .Array => {27043 .Array => {
27040 if (position == .ret_ty or position == .param_ty) return false;27044 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);
27042 },27046 },
27043 .Vector => return sema.validateExternType(ty.elemType2(mod), .element),27047 .Vector => return sema.validateExternType(ty.elemType2(zcu), .element),
27044 .Optional => return ty.isPtrLikeOptional(mod),27048 .Optional => return ty.isPtrLikeOptional(zcu),
27045 }27049 }
27046}27050}
2704727051
27048fn explainWhyTypeIsNotExtern(27052fn explainWhyTypeIsNotExtern(
27049 sema: *Sema,27053 sema: *Sema,
27050 msg: *Module.ErrorMsg,27054 msg: *Zcu.ErrorMsg,
27051 src_loc: LazySrcLoc,27055 src_loc: LazySrcLoc,
27052 ty: Type,27056 ty: Type,
27053 position: ExternPosition,27057 position: ExternPosition,
27054) CompileError!void {27058) CompileError!void {
27055 const pt = sema.pt;27059 const pt = sema.pt;
27056 const mod = pt.zcu;27060 const zcu = pt.zcu;
27057 switch (ty.zigTypeTag(mod)) {27061 switch (ty.zigTypeTag(zcu)) {
27058 .Opaque,27062 .Opaque,
27059 .Bool,27063 .Bool,
27060 .Float,27064 .Float,
...@@ -27073,13 +27077,13 @@ fn explainWhyTypeIsNotExtern(...@@ -27073,13 +27077,13 @@ fn explainWhyTypeIsNotExtern(
27073 => return,27077 => return,
2707427078
27075 .Pointer => {27079 .Pointer => {
27076 if (ty.isSlice(mod)) {27080 if (ty.isSlice(zcu)) {
27077 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});27081 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
27078 } else {27082 } else {
27079 const pointee_ty = ty.childType(mod);27083 const pointee_ty = ty.childType(zcu);
27080 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {27084 if (!ty.isConstPtr(zcu) and pointee_ty.zigTypeTag(zcu) == .Fn) {
27081 try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{});27085 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)) {
27083 try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(pt)});27087 try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(pt)});
27084 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);27088 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
27085 }27089 }
...@@ -27088,7 +27092,7 @@ fn explainWhyTypeIsNotExtern(...@@ -27088,7 +27092,7 @@ fn explainWhyTypeIsNotExtern(
27088 },27092 },
27089 .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),27093 .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
27090 .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),27094 .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)) {
27092 try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});27096 try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
27093 } else {27097 } else {
27094 try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});27098 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(...@@ -27099,7 +27103,7 @@ fn explainWhyTypeIsNotExtern(
27099 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});27103 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
27100 return;27104 return;
27101 }27105 }
27102 switch (ty.fnCallingConvention(mod)) {27106 switch (ty.fnCallingConvention(zcu)) {
27103 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),27107 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
27104 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),27108 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
27105 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),27109 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
...@@ -27107,7 +27111,7 @@ fn explainWhyTypeIsNotExtern(...@@ -27107,7 +27111,7 @@ fn explainWhyTypeIsNotExtern(
27107 }27111 }
27108 },27112 },
27109 .Enum => {27113 .Enum => {
27110 const tag_ty = ty.intTagType(mod);27114 const tag_ty = ty.intTagType(zcu);
27111 try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(pt)});27115 try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(pt)});
27112 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);27116 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
27113 },27117 },
...@@ -27119,9 +27123,9 @@ fn explainWhyTypeIsNotExtern(...@@ -27119,9 +27123,9 @@ fn explainWhyTypeIsNotExtern(
27119 } else if (position == .param_ty) {27123 } else if (position == .param_ty) {
27120 return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{});27124 return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{});
27121 }27125 }
27122 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);27126 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(zcu), .element);
27123 },27127 },
27124 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),27128 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(zcu), .element),
27125 .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}),27129 .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
27126 }27130 }
27127}27131}
...@@ -27158,20 +27162,20 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {...@@ -27158,20 +27162,20 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {
27158 .auto => false,27162 .auto => false,
27159 .explicit, .nonexhaustive => true,27163 .explicit, .nonexhaustive => true,
27160 },27164 },
27161 .Pointer => !ty.isSlice(zcu) and !try sema.typeRequiresComptime(ty),27165 .Pointer => !ty.isSlice(zcu) and !try ty.comptimeOnlySema(pt),
27162 .Struct, .Union => ty.containerLayout(zcu) == .@"packed",27166 .Struct, .Union => ty.containerLayout(zcu) == .@"packed",
27163 };27167 };
27164}27168}
2716527169
27166fn explainWhyTypeIsNotPacked(27170fn explainWhyTypeIsNotPacked(
27167 sema: *Sema,27171 sema: *Sema,
27168 msg: *Module.ErrorMsg,27172 msg: *Zcu.ErrorMsg,
27169 src_loc: LazySrcLoc,27173 src_loc: LazySrcLoc,
27170 ty: Type,27174 ty: Type,
27171) CompileError!void {27175) CompileError!void {
27172 const pt = sema.pt;27176 const pt = sema.pt;
27173 const mod = pt.zcu;27177 const zcu = pt.zcu;
27174 switch (ty.zigTypeTag(mod)) {27178 switch (ty.zigTypeTag(zcu)) {
27175 .Void,27179 .Void,
27176 .Bool,27180 .Bool,
27177 .Float,27181 .Float,
...@@ -27194,7 +27198,7 @@ fn explainWhyTypeIsNotPacked(...@@ -27194,7 +27198,7 @@ fn explainWhyTypeIsNotPacked(
27194 .Optional,27198 .Optional,
27195 .Array,27199 .Array,
27196 => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}),27200 => 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)) {
27198 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});27202 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
27199 } else {27203 } else {
27200 try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});27204 try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
...@@ -27211,23 +27215,23 @@ fn explainWhyTypeIsNotPacked(...@@ -27211,23 +27215,23 @@ fn explainWhyTypeIsNotPacked(
2721127215
27212fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {27216fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
27213 const pt = sema.pt;27217 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) {
27217 const fn_ref = try sema.analyzeNavVal(block, src, try pt.getBuiltinNav("panic"));27221 const fn_ref = try sema.analyzeNavVal(block, src, try pt.getBuiltinNav("panic"));
27218 const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{27222 const fn_val = try sema.resolveConstValue(block, src, fn_ref, .{
27219 .needed_comptime_reason = "panic handler must be comptime-known",27223 .needed_comptime_reason = "panic handler must be comptime-known",
27220 });27224 });
27221 assert(fn_val.typeOf(mod).zigTypeTag(mod) == .Fn);27225 assert(fn_val.typeOf(zcu).zigTypeTag(zcu) == .Fn);
27222 assert(try sema.fnHasRuntimeBits(fn_val.typeOf(mod)));27226 assert(try fn_val.typeOf(zcu).fnHasRuntimeBitsSema(pt));
27223 try mod.ensureFuncBodyAnalysisQueued(fn_val.toIntern());27227 try zcu.ensureFuncBodyAnalysisQueued(fn_val.toIntern());
27224 mod.panic_func_index = fn_val.toIntern();27228 zcu.panic_func_index = fn_val.toIntern();
27225 }27229 }
2722627230
27227 if (mod.null_stack_trace == .none) {27231 if (zcu.null_stack_trace == .none) {
27228 const stack_trace_ty = try pt.getBuiltinType("StackTrace");27232 const stack_trace_ty = try pt.getBuiltinType("StackTrace");
27229 try stack_trace_ty.resolveFields(pt);27233 try stack_trace_ty.resolveFields(pt);
27230 const target = mod.getTarget();27234 const target = zcu.getTarget();
27231 const ptr_stack_trace_ty = try pt.ptrTypeSema(.{27235 const ptr_stack_trace_ty = try pt.ptrTypeSema(.{
27232 .child = stack_trace_ty.toIntern(),27236 .child = stack_trace_ty.toIntern(),
27233 .flags = .{27237 .flags = .{
...@@ -27235,7 +27239,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {...@@ -27235,7 +27239,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
27235 },27239 },
27236 });27240 });
27237 const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern());27241 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 = .{
27239 .ty = opt_ptr_stack_trace_ty.toIntern(),27243 .ty = opt_ptr_stack_trace_ty.toIntern(),
27240 .val = .none,27244 .val = .none,
27241 } });27245 } });
...@@ -27245,11 +27249,11 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {...@@ -27245,11 +27249,11 @@ fn prepareSimplePanic(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
27245/// Backends depend on panic decls being available when lowering safety-checked27249/// Backends depend on panic decls being available when lowering safety-checked
27246/// instructions. This function ensures the panic function will be available to27250/// instructions. This function ensures the panic function will be available to
27247/// be called during that time.27251/// 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 {
27249 const pt = sema.pt;27253 const pt = sema.pt;
27250 const mod = pt.zcu;27254 const zcu = pt.zcu;
27251 const gpa = sema.gpa;27255 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
27254 try sema.prepareSimplePanic(block, src);27258 try sema.prepareSimplePanic(block, src);
2725527259
...@@ -27257,15 +27261,15 @@ fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module....@@ -27257,15 +27261,15 @@ fn preparePanicId(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Module.
27257 const msg_nav_index = (sema.namespaceLookup(27261 const msg_nav_index = (sema.namespaceLookup(
27258 block,27262 block,
27259 LazySrcLoc.unneeded,27263 LazySrcLoc.unneeded,
27260 panic_messages_ty.getNamespaceIndex(mod),27264 panic_messages_ty.getNamespaceIndex(zcu),
27261 try mod.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls),27265 try zcu.intern_pool.getOrPutString(gpa, pt.tid, @tagName(panic_id), .no_embedded_nulls),
27262 ) catch |err| switch (err) {27266 ) catch |err| switch (err) {
27263 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),27267 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),
27264 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,27268 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
27265 error.OutOfMemory => |e| return e,27269 error.OutOfMemory => |e| return e,
27266 }).?;27270 }).?;
27267 try sema.ensureNavResolved(src, msg_nav_index);27271 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();
27269 return msg_nav_index;27273 return msg_nav_index;
27270}27274}
2727127275
...@@ -27274,7 +27278,7 @@ fn addSafetyCheck(...@@ -27274,7 +27278,7 @@ fn addSafetyCheck(
27274 parent_block: *Block,27278 parent_block: *Block,
27275 src: LazySrcLoc,27279 src: LazySrcLoc,
27276 ok: Air.Inst.Ref,27280 ok: Air.Inst.Ref,
27277 panic_id: Module.PanicId,27281 panic_id: Zcu.PanicId,
27278) !void {27282) !void {
27279 const gpa = sema.gpa;27283 const gpa = sema.gpa;
27280 assert(!parent_block.is_comptime);27284 assert(!parent_block.is_comptime);
...@@ -27353,18 +27357,18 @@ fn addSafetyCheckExtra(...@@ -27353,18 +27357,18 @@ fn addSafetyCheckExtra(
2735327357
27354fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst.Ref, operation: CallOperation) !void {27358fn panicWithMsg(sema: *Sema, block: *Block, src: LazySrcLoc, msg_inst: Air.Inst.Ref, operation: CallOperation) !void {
27355 const pt = sema.pt;27359 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)) {
27359 _ = try block.addNoOp(.trap);27363 _ = try block.addNoOp(.trap);
27360 return;27364 return;
27361 }27365 }
2736227366
27363 try sema.prepareSimplePanic(block, src);27367 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);
27366 const panic_fn = try sema.analyzeNavVal(block, src, panic_func.owner_nav);27370 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
27369 const opt_usize_ty = try pt.optionalType(.usize_type);27373 const opt_usize_ty = try pt.optionalType(.usize_type);
27370 const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{27374 const null_ret_addr = Air.internedToRef((try pt.intern(.{ .opt = .{
...@@ -27459,12 +27463,12 @@ fn panicSentinelMismatch(...@@ -27459,12 +27463,12 @@ fn panicSentinelMismatch(
27459) !void {27463) !void {
27460 assert(!parent_block.is_comptime);27464 assert(!parent_block.is_comptime);
27461 const pt = sema.pt;27465 const pt = sema.pt;
27462 const mod = pt.zcu;27466 const zcu = pt.zcu;
27463 const expected_sentinel_val = maybe_sentinel orelse return;27467 const expected_sentinel_val = maybe_sentinel orelse return;
27464 const expected_sentinel = Air.internedToRef(expected_sentinel_val.toIntern());27468 const expected_sentinel = Air.internedToRef(expected_sentinel_val.toIntern());
2746527469
27466 const ptr_ty = sema.typeOf(ptr);27470 const ptr_ty = sema.typeOf(ptr);
27467 const actual_sentinel = if (ptr_ty.isSlice(mod))27471 const actual_sentinel = if (ptr_ty.isSlice(zcu))
27468 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)27472 try parent_block.addBinOp(.slice_elem_val, ptr, sentinel_index)
27469 else blk: {27473 else blk: {
27470 const elem_ptr_ty = try ptr_ty.elemPtrType(null, pt);27474 const elem_ptr_ty = try ptr_ty.elemPtrType(null, pt);
...@@ -27472,7 +27476,7 @@ fn panicSentinelMismatch(...@@ -27472,7 +27476,7 @@ fn panicSentinelMismatch(
27472 break :blk try parent_block.addTyOp(.load, sentinel_ty, sentinel_ptr);27476 break :blk try parent_block.addTyOp(.load, sentinel_ty, sentinel_ptr);
27473 };27477 };
2747427478
27475 const ok = if (sentinel_ty.zigTypeTag(mod) == .Vector) ok: {27479 const ok = if (sentinel_ty.zigTypeTag(zcu) == .Vector) ok: {
27476 const eql =27480 const eql =
27477 try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq);27481 try parent_block.addCmpVector(expected_sentinel, actual_sentinel, .eq);
27478 break :ok try parent_block.addInst(.{27482 break :ok try parent_block.addInst(.{
...@@ -27482,7 +27486,7 @@ fn panicSentinelMismatch(...@@ -27482,7 +27486,7 @@ fn panicSentinelMismatch(
27482 .operation = .And,27486 .operation = .And,
27483 } },27487 } },
27484 });27488 });
27485 } else if (sentinel_ty.isSelfComparable(mod, true))27489 } else if (sentinel_ty.isSelfComparable(zcu, true))
27486 try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel)27490 try parent_block.addBinOp(.cmp_eq, expected_sentinel, actual_sentinel)
27487 else {27491 else {
27488 const panic_fn = try pt.getBuiltin("checkNonScalarSentinel");27492 const panic_fn = try pt.getBuiltin("checkNonScalarSentinel");
...@@ -27532,7 +27536,7 @@ fn safetyCheckFormatted(...@@ -27532,7 +27536,7 @@ fn safetyCheckFormatted(
27532 try sema.addSafetyCheckExtra(parent_block, ok, &fail_block);27536 try sema.addSafetyCheckExtra(parent_block, ok, &fail_block);
27533}27537}
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 {
27536 const msg_nav_index = try sema.preparePanicId(block, src, panic_id);27540 const msg_nav_index = try sema.preparePanicId(block, src, panic_id);
27537 const msg_inst = try sema.analyzeNavVal(block, src, msg_nav_index);27541 const msg_inst = try sema.analyzeNavVal(block, src, msg_nav_index);
27538 try sema.panicWithMsg(block, src, msg_inst, .@"safety check");27542 try sema.panicWithMsg(block, src, msg_inst, .@"safety check");
...@@ -27568,30 +27572,30 @@ fn fieldVal(...@@ -27568,30 +27572,30 @@ fn fieldVal(
27568 // in `fieldPtr`. This function takes a value and returns a value.27572 // in `fieldPtr`. This function takes a value and returns a value.
2756927573
27570 const pt = sema.pt;27574 const pt = sema.pt;
27571 const mod = pt.zcu;27575 const zcu = pt.zcu;
27572 const ip = &mod.intern_pool;27576 const ip = &zcu.intern_pool;
27573 const object_src = src; // TODO better source location27577 const object_src = src; // TODO better source location
27574 const object_ty = sema.typeOf(object);27578 const object_ty = sema.typeOf(object);
2757527579
27576 // Zig allows dereferencing a single pointer during field lookup. Note that27580 // Zig allows dereferencing a single pointer during field lookup. Note that
27577 // we don't actually need to generate the dereference some field lookups, like the27581 // we don't actually need to generate the dereference some field lookups, like the
27578 // length of arrays and other comptime operations.27582 // 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
27581 const inner_ty = if (is_pointer_to)27585 const inner_ty = if (is_pointer_to)
27582 object_ty.childType(mod)27586 object_ty.childType(zcu)
27583 else27587 else
27584 object_ty;27588 object_ty;
2758527589
27586 switch (inner_ty.zigTypeTag(mod)) {27590 switch (inner_ty.zigTypeTag(zcu)) {
27587 .Array => {27591 .Array => {
27588 if (field_name.eqlSlice("len", ip)) {27592 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());
27590 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {27594 } 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);
27592 const result_ty = try pt.ptrTypeSema(.{27596 const result_ty = try pt.ptrTypeSema(.{
27593 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),27597 .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(),
27594 .sentinel = if (inner_ty.sentinel(mod)) |s| s.toIntern() else .none,27598 .sentinel = if (inner_ty.sentinel(zcu)) |s| s.toIntern() else .none,
27595 .flags = .{27599 .flags = .{
27596 .size = .Many,27600 .size = .Many,
27597 .alignment = ptr_info.flags.alignment,27601 .alignment = ptr_info.flags.alignment,
...@@ -27614,7 +27618,7 @@ fn fieldVal(...@@ -27614,7 +27618,7 @@ fn fieldVal(
27614 }27618 }
27615 },27619 },
27616 .Pointer => {27620 .Pointer => {
27617 const ptr_info = inner_ty.ptrInfo(mod);27621 const ptr_info = inner_ty.ptrInfo(zcu);
27618 if (ptr_info.flags.size == .Slice) {27622 if (ptr_info.flags.size == .Slice) {
27619 if (field_name.eqlSlice("ptr", ip)) {27623 if (field_name.eqlSlice("ptr", ip)) {
27620 const slice = if (is_pointer_to)27624 const slice = if (is_pointer_to)
...@@ -27647,7 +27651,7 @@ fn fieldVal(...@@ -27647,7 +27651,7 @@ fn fieldVal(
27647 const val = (try sema.resolveDefinedValue(block, object_src, dereffed_type)).?;27651 const val = (try sema.resolveDefinedValue(block, object_src, dereffed_type)).?;
27648 const child_type = val.toType();27652 const child_type = val.toType();
2764927653
27650 switch (try child_type.zigTypeTagOrPoison(mod)) {27654 switch (try child_type.zigTypeTagOrPoison(zcu)) {
27651 .ErrorSet => {27655 .ErrorSet => {
27652 switch (ip.indexToKey(child_type.toIntern())) {27656 switch (ip.indexToKey(child_type.toIntern())) {
27653 .error_set_type => |error_set_type| blk: {27657 .error_set_type => |error_set_type| blk: {
...@@ -27666,7 +27670,7 @@ fn fieldVal(...@@ -27666,7 +27670,7 @@ fn fieldVal(
27666 else => unreachable,27670 else => unreachable,
27667 }27671 }
2766827672
27669 const error_set_type = if (!child_type.isAnyError(mod))27673 const error_set_type = if (!child_type.isAnyError(zcu))
27670 child_type27674 child_type
27671 else27675 else
27672 try pt.singleErrorSetType(field_name);27676 try pt.singleErrorSetType(field_name);
...@@ -27676,12 +27680,12 @@ fn fieldVal(...@@ -27676,12 +27680,12 @@ fn fieldVal(
27676 } })));27680 } })));
27677 },27681 },
27678 .Union => {27682 .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| {
27680 return inst;27684 return inst;
27681 }27685 }
27682 try child_type.resolveFields(pt);27686 try child_type.resolveFields(pt);
27683 if (child_type.unionTagType(mod)) |enum_ty| {27687 if (child_type.unionTagType(zcu)) |enum_ty| {
27684 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| {27688 if (enum_ty.enumFieldIndex(field_name, zcu)) |field_index_usize| {
27685 const field_index: u32 = @intCast(field_index_usize);27689 const field_index: u32 = @intCast(field_index_usize);
27686 return Air.internedToRef((try pt.enumValueFieldIndex(enum_ty, field_index)).toIntern());27690 return Air.internedToRef((try pt.enumValueFieldIndex(enum_ty, field_index)).toIntern());
27687 }27691 }
...@@ -27689,10 +27693,10 @@ fn fieldVal(...@@ -27689,10 +27693,10 @@ fn fieldVal(
27689 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);27693 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
27690 },27694 },
27691 .Enum => {27695 .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| {
27693 return inst;27697 return inst;
27694 }27698 }
27695 const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse27699 const field_index_usize = child_type.enumFieldIndex(field_name, zcu) orelse
27696 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);27700 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
27697 const field_index: u32 = @intCast(field_index_usize);27701 const field_index: u32 = @intCast(field_index_usize);
27698 const enum_val = try pt.enumValueFieldIndex(child_type, field_index);27702 const enum_val = try pt.enumValueFieldIndex(child_type, field_index);
...@@ -27701,7 +27705,7 @@ fn fieldVal(...@@ -27701,7 +27705,7 @@ fn fieldVal(
27701 .Struct, .Opaque => {27705 .Struct, .Opaque => {
27702 switch (child_type.toIntern()) {27706 switch (child_type.toIntern()) {
27703 .empty_struct_type, .anyopaque_type => {}, // no namespace27707 .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| {
27705 return inst;27709 return inst;
27706 },27710 },
27707 }27711 }
...@@ -27710,8 +27714,8 @@ fn fieldVal(...@@ -27710,8 +27714,8 @@ fn fieldVal(
27710 else => return sema.failWithOwnedErrorMsg(block, msg: {27714 else => return sema.failWithOwnedErrorMsg(block, msg: {
27711 const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(pt)});27715 const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(pt)});
27712 errdefer msg.destroy(sema.gpa);27716 errdefer msg.destroy(sema.gpa);
27713 if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});27717 if (child_type.isSlice(zcu)) 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", .{});27718 if (child_type.zigTypeTag(zcu) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
27715 break :msg msg;27719 break :msg msg;
27716 }),27720 }),
27717 }27721 }
...@@ -27748,35 +27752,35 @@ fn fieldPtr(...@@ -27748,35 +27752,35 @@ fn fieldPtr(
27748 // in `fieldVal`. This function takes a pointer and returns a pointer.27752 // in `fieldVal`. This function takes a pointer and returns a pointer.
2774927753
27750 const pt = sema.pt;27754 const pt = sema.pt;
27751 const mod = pt.zcu;27755 const zcu = pt.zcu;
27752 const ip = &mod.intern_pool;27756 const ip = &zcu.intern_pool;
27753 const object_ptr_src = src; // TODO better source location27757 const object_ptr_src = src; // TODO better source location
27754 const object_ptr_ty = sema.typeOf(object_ptr);27758 const object_ptr_ty = sema.typeOf(object_ptr);
27755 const object_ty = switch (object_ptr_ty.zigTypeTag(mod)) {27759 const object_ty = switch (object_ptr_ty.zigTypeTag(zcu)) {
27756 .Pointer => object_ptr_ty.childType(mod),27760 .Pointer => object_ptr_ty.childType(zcu),
27757 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(pt)}),27761 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(pt)}),
27758 };27762 };
2775927763
27760 // Zig allows dereferencing a single pointer during field lookup. Note that27764 // Zig allows dereferencing a single pointer during field lookup. Note that
27761 // we don't actually need to generate the dereference some field lookups, like the27765 // we don't actually need to generate the dereference some field lookups, like the
27762 // length of arrays and other comptime operations.27766 // 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
27765 const inner_ty = if (is_pointer_to)27769 const inner_ty = if (is_pointer_to)
27766 object_ty.childType(mod)27770 object_ty.childType(zcu)
27767 else27771 else
27768 object_ty;27772 object_ty;
2776927773
27770 switch (inner_ty.zigTypeTag(mod)) {27774 switch (inner_ty.zigTypeTag(zcu)) {
27771 .Array => {27775 .Array => {
27772 if (field_name.eqlSlice("len", ip)) {27776 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));
27774 return uavRef(sema, int_val.toIntern());27778 return uavRef(sema, int_val.toIntern());
27775 } else if (field_name.eqlSlice("ptr", ip) and is_pointer_to) {27779 } 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);
27777 const new_ptr_ty = try pt.ptrTypeSema(.{27781 const new_ptr_ty = try pt.ptrTypeSema(.{
27778 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),27782 .child = Type.fromInterned(ptr_info.child).childType(zcu).toIntern(),
27779 .sentinel = if (object_ty.sentinel(mod)) |s| s.toIntern() else .none,27783 .sentinel = if (object_ty.sentinel(zcu)) |s| s.toIntern() else .none,
27780 .flags = .{27784 .flags = .{
27781 .size = .Many,27785 .size = .Many,
27782 .alignment = ptr_info.flags.alignment,27786 .alignment = ptr_info.flags.alignment,
...@@ -27788,10 +27792,10 @@ fn fieldPtr(...@@ -27788,10 +27792,10 @@ fn fieldPtr(
27788 },27792 },
27789 .packed_offset = ptr_info.packed_offset,27793 .packed_offset = ptr_info.packed_offset,
27790 });27794 });
27791 const ptr_ptr_info = object_ptr_ty.ptrInfo(mod);27795 const ptr_ptr_info = object_ptr_ty.ptrInfo(zcu);
27792 const result_ty = try pt.ptrTypeSema(.{27796 const result_ty = try pt.ptrTypeSema(.{
27793 .child = new_ptr_ty.toIntern(),27797 .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,
27795 .flags = .{27799 .flags = .{
27796 .alignment = ptr_ptr_info.flags.alignment,27800 .alignment = ptr_ptr_info.flags.alignment,
27797 .is_const = ptr_ptr_info.flags.is_const,27801 .is_const = ptr_ptr_info.flags.is_const,
...@@ -27812,7 +27816,7 @@ fn fieldPtr(...@@ -27812,7 +27816,7 @@ fn fieldPtr(
27812 );27816 );
27813 }27817 }
27814 },27818 },
27815 .Pointer => if (inner_ty.isSlice(mod)) {27819 .Pointer => if (inner_ty.isSlice(zcu)) {
27816 const inner_ptr = if (is_pointer_to)27820 const inner_ptr = if (is_pointer_to)
27817 try sema.analyzeLoad(block, src, object_ptr, object_ptr_src)27821 try sema.analyzeLoad(block, src, object_ptr, object_ptr_src)
27818 else27822 else
...@@ -27821,14 +27825,14 @@ fn fieldPtr(...@@ -27821,14 +27825,14 @@ fn fieldPtr(
27821 const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty;27825 const attr_ptr_ty = if (is_pointer_to) object_ty else object_ptr_ty;
2782227826
27823 if (field_name.eqlSlice("ptr", ip)) {27827 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
27826 const result_ty = try pt.ptrTypeSema(.{27830 const result_ty = try pt.ptrTypeSema(.{
27827 .child = slice_ptr_ty.toIntern(),27831 .child = slice_ptr_ty.toIntern(),
27828 .flags = .{27832 .flags = .{
27829 .is_const = !attr_ptr_ty.ptrIsMutable(mod),27833 .is_const = !attr_ptr_ty.ptrIsMutable(zcu),
27830 .is_volatile = attr_ptr_ty.isVolatilePtr(mod),27834 .is_volatile = attr_ptr_ty.isVolatilePtr(zcu),
27831 .address_space = attr_ptr_ty.ptrAddressSpace(mod),27835 .address_space = attr_ptr_ty.ptrAddressSpace(zcu),
27832 },27836 },
27833 });27837 });
2783427838
...@@ -27844,9 +27848,9 @@ fn fieldPtr(...@@ -27844,9 +27848,9 @@ fn fieldPtr(
27844 const result_ty = try pt.ptrTypeSema(.{27848 const result_ty = try pt.ptrTypeSema(.{
27845 .child = .usize_type,27849 .child = .usize_type,
27846 .flags = .{27850 .flags = .{
27847 .is_const = !attr_ptr_ty.ptrIsMutable(mod),27851 .is_const = !attr_ptr_ty.ptrIsMutable(zcu),
27848 .is_volatile = attr_ptr_ty.isVolatilePtr(mod),27852 .is_volatile = attr_ptr_ty.isVolatilePtr(zcu),
27849 .address_space = attr_ptr_ty.ptrAddressSpace(mod),27853 .address_space = attr_ptr_ty.ptrAddressSpace(zcu),
27850 },27854 },
27851 });27855 });
2785227856
...@@ -27878,7 +27882,7 @@ fn fieldPtr(...@@ -27878,7 +27882,7 @@ fn fieldPtr(
27878 const val = (sema.resolveDefinedValue(block, src, inner) catch unreachable).?;27882 const val = (sema.resolveDefinedValue(block, src, inner) catch unreachable).?;
27879 const child_type = val.toType();27883 const child_type = val.toType();
2788027884
27881 switch (child_type.zigTypeTag(mod)) {27885 switch (child_type.zigTypeTag(zcu)) {
27882 .ErrorSet => {27886 .ErrorSet => {
27883 switch (ip.indexToKey(child_type.toIntern())) {27887 switch (ip.indexToKey(child_type.toIntern())) {
27884 .error_set_type => |error_set_type| blk: {27888 .error_set_type => |error_set_type| blk: {
...@@ -27899,7 +27903,7 @@ fn fieldPtr(...@@ -27899,7 +27903,7 @@ fn fieldPtr(
27899 else => unreachable,27903 else => unreachable,
27900 }27904 }
2790127905
27902 const error_set_type = if (!child_type.isAnyError(mod))27906 const error_set_type = if (!child_type.isAnyError(zcu))
27903 child_type27907 child_type
27904 else27908 else
27905 try pt.singleErrorSetType(field_name);27909 try pt.singleErrorSetType(field_name);
...@@ -27909,12 +27913,12 @@ fn fieldPtr(...@@ -27909,12 +27913,12 @@ fn fieldPtr(
27909 } }));27913 } }));
27910 },27914 },
27911 .Union => {27915 .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| {
27913 return inst;27917 return inst;
27914 }27918 }
27915 try child_type.resolveFields(pt);27919 try child_type.resolveFields(pt);
27916 if (child_type.unionTagType(mod)) |enum_ty| {27920 if (child_type.unionTagType(zcu)) |enum_ty| {
27917 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| {27921 if (enum_ty.enumFieldIndex(field_name, zcu)) |field_index| {
27918 const field_index_u32: u32 = @intCast(field_index);27922 const field_index_u32: u32 = @intCast(field_index);
27919 const idx_val = try pt.enumValueFieldIndex(enum_ty, field_index_u32);27923 const idx_val = try pt.enumValueFieldIndex(enum_ty, field_index_u32);
27920 return uavRef(sema, idx_val.toIntern());27924 return uavRef(sema, idx_val.toIntern());
...@@ -27923,10 +27927,10 @@ fn fieldPtr(...@@ -27923,10 +27927,10 @@ fn fieldPtr(
27923 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);27927 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
27924 },27928 },
27925 .Enum => {27929 .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| {
27927 return inst;27931 return inst;
27928 }27932 }
27929 const field_index = child_type.enumFieldIndex(field_name, mod) orelse {27933 const field_index = child_type.enumFieldIndex(field_name, zcu) orelse {
27930 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);27934 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
27931 };27935 };
27932 const field_index_u32: u32 = @intCast(field_index);27936 const field_index_u32: u32 = @intCast(field_index);
...@@ -27934,7 +27938,7 @@ fn fieldPtr(...@@ -27934,7 +27938,7 @@ fn fieldPtr(
27934 return uavRef(sema, idx_val.toIntern());27938 return uavRef(sema, idx_val.toIntern());
27935 },27939 },
27936 .Struct, .Opaque => {27940 .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| {
27938 return inst;27942 return inst;
27939 }27943 }
27940 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);27944 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
...@@ -28021,14 +28025,14 @@ fn fieldCallBind(...@@ -28021,14 +28025,14 @@ fn fieldCallBind(
28021 }28025 }
28022 if (field_name.toUnsigned(ip)) |field_index| {28026 if (field_name.toUnsigned(ip)) |field_index| {
28023 if (field_index >= concrete_ty.structFieldCount(zcu)) break :find_field;28027 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);
28025 }28029 }
28026 } else {28030 } else {
28027 const max = concrete_ty.structFieldCount(zcu);28031 const max = concrete_ty.structFieldCount(zcu);
28028 for (0..max) |i_usize| {28032 for (0..max) |i_usize| {
28029 const i: u32 = @intCast(i_usize);28033 const i: u32 = @intCast(i_usize);
28030 if (field_name == concrete_ty.structFieldName(i, zcu).unwrap().?) {28034 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);
28032 }28036 }
28033 }28037 }
28034 }28038 }
...@@ -28149,18 +28153,18 @@ fn finishFieldCallBind(...@@ -28149,18 +28153,18 @@ fn finishFieldCallBind(
28149 object_ptr: Air.Inst.Ref,28153 object_ptr: Air.Inst.Ref,
28150) CompileError!ResolvedFieldCallee {28154) CompileError!ResolvedFieldCallee {
28151 const pt = sema.pt;28155 const pt = sema.pt;
28152 const mod = pt.zcu;28156 const zcu = pt.zcu;
28153 const ptr_field_ty = try pt.ptrTypeSema(.{28157 const ptr_field_ty = try pt.ptrTypeSema(.{
28154 .child = field_ty.toIntern(),28158 .child = field_ty.toIntern(),
28155 .flags = .{28159 .flags = .{
28156 .is_const = !ptr_ty.ptrIsMutable(mod),28160 .is_const = !ptr_ty.ptrIsMutable(zcu),
28157 .address_space = ptr_ty.ptrAddressSpace(mod),28161 .address_space = ptr_ty.ptrAddressSpace(zcu),
28158 },28162 },
28159 });28163 });
2816028164
28161 const container_ty = ptr_ty.childType(mod);28165 const container_ty = ptr_ty.childType(zcu);
28162 if (container_ty.zigTypeTag(mod) == .Struct) {28166 if (container_ty.zigTypeTag(zcu) == .Struct) {
28163 if (container_ty.structFieldIsComptime(field_index, mod)) {28167 if (container_ty.structFieldIsComptime(field_index, zcu)) {
28164 try container_ty.resolveStructFieldInits(pt);28168 try container_ty.resolveStructFieldInits(pt);
28165 const default_val = (try container_ty.structFieldValueComptime(pt, field_index)).?;28169 const default_val = (try container_ty.structFieldValueComptime(pt, field_index)).?;
28166 return .{ .direct = Air.internedToRef(default_val.toIntern()) };28170 return .{ .direct = Air.internedToRef(default_val.toIntern()) };
...@@ -28237,26 +28241,26 @@ fn structFieldPtr(...@@ -28237,26 +28241,26 @@ fn structFieldPtr(
28237 initializing: bool,28241 initializing: bool,
28238) CompileError!Air.Inst.Ref {28242) CompileError!Air.Inst.Ref {
28239 const pt = sema.pt;28243 const pt = sema.pt;
28240 const mod = pt.zcu;28244 const zcu = pt.zcu;
28241 const ip = &mod.intern_pool;28245 const ip = &zcu.intern_pool;
28242 assert(struct_ty.zigTypeTag(mod) == .Struct);28246 assert(struct_ty.zigTypeTag(zcu) == .Struct);
2824328247
28244 try struct_ty.resolveFields(pt);28248 try struct_ty.resolveFields(pt);
28245 try struct_ty.resolveLayout(pt);28249 try struct_ty.resolveLayout(pt);
2824628250
28247 if (struct_ty.isTuple(mod)) {28251 if (struct_ty.isTuple(zcu)) {
28248 if (field_name.eqlSlice("len", ip)) {28252 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));
28250 return sema.analyzeRef(block, src, len_inst);28254 return sema.analyzeRef(block, src, len_inst);
28251 }28255 }
28252 const field_index = try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);28256 const field_index = try sema.tupleFieldIndex(block, struct_ty, field_name, field_name_src);
28253 return sema.tupleFieldPtr(block, src, struct_ptr, field_name_src, field_index, initializing);28257 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)) {
28255 const field_index = try sema.anonStructFieldIndex(block, struct_ty, field_name, field_name_src);28259 const field_index = try sema.anonStructFieldIndex(block, struct_ty, field_name, field_name_src);
28256 return sema.tupleFieldPtr(block, src, struct_ptr, field_name_src, field_index, initializing);28260 return sema.tupleFieldPtr(block, src, struct_ptr, field_name_src, field_index, initializing);
28257 }28261 }
2825828262
28259 const struct_type = mod.typeToStruct(struct_ty).?;28263 const struct_type = zcu.typeToStruct(struct_ty).?;
2826028264
28261 const field_index = struct_type.nameIndex(ip, field_name) orelse28265 const field_index = struct_type.nameIndex(ip, field_name) orelse
28262 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);28266 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
...@@ -28275,9 +28279,9 @@ fn structFieldPtrByIndex(...@@ -28275,9 +28279,9 @@ fn structFieldPtrByIndex(
28275 initializing: bool,28279 initializing: bool,
28276) CompileError!Air.Inst.Ref {28280) CompileError!Air.Inst.Ref {
28277 const pt = sema.pt;28281 const pt = sema.pt;
28278 const mod = pt.zcu;28282 const zcu = pt.zcu;
28279 const ip = &mod.intern_pool;28283 const ip = &zcu.intern_pool;
28280 if (struct_ty.isAnonStruct(mod)) {28284 if (struct_ty.isAnonStruct(zcu)) {
28281 return sema.tupleFieldPtr(block, src, struct_ptr, field_src, field_index, initializing);28285 return sema.tupleFieldPtr(block, src, struct_ptr, field_src, field_index, initializing);
28282 }28286 }
2828328287
...@@ -28286,10 +28290,10 @@ fn structFieldPtrByIndex(...@@ -28286,10 +28290,10 @@ fn structFieldPtrByIndex(
28286 return Air.internedToRef(val.toIntern());28290 return Air.internedToRef(val.toIntern());
28287 }28291 }
2828828292
28289 const struct_type = mod.typeToStruct(struct_ty).?;28293 const struct_type = zcu.typeToStruct(struct_ty).?;
28290 const field_ty = struct_type.field_types.get(ip)[field_index];28294 const field_ty = struct_type.field_types.get(ip)[field_index];
28291 const struct_ptr_ty = sema.typeOf(struct_ptr);28295 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
28294 var ptr_ty_data: InternPool.Key.PtrType = .{28298 var ptr_ty_data: InternPool.Key.PtrType = .{
28295 .child = field_ty,28299 .child = field_ty,
...@@ -28303,7 +28307,7 @@ fn structFieldPtrByIndex(...@@ -28303,7 +28307,7 @@ fn structFieldPtrByIndex(
28303 const parent_align = if (struct_ptr_ty_info.flags.alignment != .none)28307 const parent_align = if (struct_ptr_ty_info.flags.alignment != .none)
28304 struct_ptr_ty_info.flags.alignment28308 struct_ptr_ty_info.flags.alignment
28305 else28309 else
28306 try sema.typeAbiAlignment(Type.fromInterned(struct_ptr_ty_info.child));28310 try Type.fromInterned(struct_ptr_ty_info.child).abiAlignmentSema(pt);
2830728311
28308 if (struct_type.layout == .@"packed") {28312 if (struct_type.layout == .@"packed") {
28309 switch (struct_ty.packedStructFieldPtrInfo(struct_ptr_ty, field_index, pt)) {28313 switch (struct_ty.packedStructFieldPtrInfo(struct_ptr_ty, field_index, pt)) {
...@@ -28319,18 +28323,17 @@ fn structFieldPtrByIndex(...@@ -28319,18 +28323,17 @@ fn structFieldPtrByIndex(
28319 // For extern structs, field alignment might be bigger than type's28323 // For extern structs, field alignment might be bigger than type's
28320 // natural alignment. Eg, in `extern struct { x: u32, y: u16 }` the28324 // natural alignment. Eg, in `extern struct { x: u32, y: u16 }` the
28321 // second field is aligned as u32.28325 // 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);
28323 ptr_ty_data.flags.alignment = if (parent_align == .none)28327 ptr_ty_data.flags.alignment = if (parent_align == .none)
28324 .none28328 .none
28325 else28329 else
28326 @enumFromInt(@min(@intFromEnum(parent_align), @ctz(field_offset)));28330 @enumFromInt(@min(@intFromEnum(parent_align), @ctz(field_offset)));
28327 } else {28331 } else {
28328 // Our alignment is capped at the field alignment.28332 // 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(
28330 struct_type.fieldAlign(ip, field_index),28334 struct_type.fieldAlign(ip, field_index),
28331 Type.fromInterned(field_ty),
28332 struct_type.layout,28335 struct_type.layout,
28333 .sema,28336 pt,
28334 );28337 );
28335 ptr_ty_data.flags.alignment = if (struct_ptr_ty_info.flags.alignment == .none)28338 ptr_ty_data.flags.alignment = if (struct_ptr_ty_info.flags.alignment == .none)
28336 field_align28339 field_align
...@@ -28364,9 +28367,9 @@ fn structFieldVal(...@@ -28364,9 +28367,9 @@ fn structFieldVal(
28364 struct_ty: Type,28367 struct_ty: Type,
28365) CompileError!Air.Inst.Ref {28368) CompileError!Air.Inst.Ref {
28366 const pt = sema.pt;28369 const pt = sema.pt;
28367 const mod = pt.zcu;28370 const zcu = pt.zcu;
28368 const ip = &mod.intern_pool;28371 const ip = &zcu.intern_pool;
28369 assert(struct_ty.zigTypeTag(mod) == .Struct);28372 assert(struct_ty.zigTypeTag(zcu) == .Struct);
2837028373
28371 try struct_ty.resolveFields(pt);28374 try struct_ty.resolveFields(pt);
2837228375
...@@ -28388,7 +28391,7 @@ fn structFieldVal(...@@ -28388,7 +28391,7 @@ fn structFieldVal(
28388 return Air.internedToRef(field_val.toIntern());28391 return Air.internedToRef(field_val.toIntern());
2838928392
28390 if (try sema.resolveValue(struct_byval)) |struct_val| {28393 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);
28392 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {28395 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
28393 return Air.internedToRef(opv.toIntern());28396 return Air.internedToRef(opv.toIntern());
28394 }28397 }
...@@ -28421,9 +28424,9 @@ fn tupleFieldVal(...@@ -28421,9 +28424,9 @@ fn tupleFieldVal(
28421 tuple_ty: Type,28424 tuple_ty: Type,
28422) CompileError!Air.Inst.Ref {28425) CompileError!Air.Inst.Ref {
28423 const pt = sema.pt;28426 const pt = sema.pt;
28424 const mod = pt.zcu;28427 const zcu = pt.zcu;
28425 if (field_name.eqlSlice("len", &mod.intern_pool)) {28428 if (field_name.eqlSlice("len", &zcu.intern_pool)) {
28426 return pt.intRef(Type.usize, tuple_ty.structFieldCount(mod));28429 return pt.intRef(Type.usize, tuple_ty.structFieldCount(zcu));
28427 }28430 }
28428 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);28431 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_name_src);
28429 return sema.tupleFieldValByIndex(block, src, tuple_byval, field_index, tuple_ty);28432 return sema.tupleFieldValByIndex(block, src, tuple_byval, field_index, tuple_ty);
...@@ -28461,10 +28464,10 @@ fn tupleFieldValByIndex(...@@ -28461,10 +28464,10 @@ fn tupleFieldValByIndex(
28461 tuple_ty: Type,28464 tuple_ty: Type,
28462) CompileError!Air.Inst.Ref {28465) CompileError!Air.Inst.Ref {
28463 const pt = sema.pt;28466 const pt = sema.pt;
28464 const mod = pt.zcu;28467 const zcu = pt.zcu;
28465 const field_ty = tuple_ty.structFieldType(field_index, mod);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))
28468 try tuple_ty.resolveStructFieldInits(pt);28471 try tuple_ty.resolveStructFieldInits(pt);
28469 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {28472 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {
28470 return Air.internedToRef(default_value.toIntern());28473 return Air.internedToRef(default_value.toIntern());
...@@ -28474,10 +28477,10 @@ fn tupleFieldValByIndex(...@@ -28474,10 +28477,10 @@ fn tupleFieldValByIndex(
28474 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {28477 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
28475 return Air.internedToRef(opv.toIntern());28478 return Air.internedToRef(opv.toIntern());
28476 }28479 }
28477 return switch (mod.intern_pool.indexToKey(tuple_val.toIntern())) {28480 return switch (zcu.intern_pool.indexToKey(tuple_val.toIntern())) {
28478 .undef => pt.undefRef(field_ty),28481 .undef => pt.undefRef(field_ty),
28479 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {28482 .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)),
28481 .elems => |elems| Value.fromInterned(elems[field_index]),28484 .elems => |elems| Value.fromInterned(elems[field_index]),
28482 .repeated_elem => |elem| Value.fromInterned(elem),28485 .repeated_elem => |elem| Value.fromInterned(elem),
28483 }.toIntern()),28486 }.toIntern()),
...@@ -28501,15 +28504,15 @@ fn unionFieldPtr(...@@ -28501,15 +28504,15 @@ fn unionFieldPtr(
28501 initializing: bool,28504 initializing: bool,
28502) CompileError!Air.Inst.Ref {28505) CompileError!Air.Inst.Ref {
28503 const pt = sema.pt;28506 const pt = sema.pt;
28504 const mod = pt.zcu;28507 const zcu = pt.zcu;
28505 const ip = &mod.intern_pool;28508 const ip = &zcu.intern_pool;
2850628509
28507 assert(union_ty.zigTypeTag(mod) == .Union);28510 assert(union_ty.zigTypeTag(zcu) == .Union);
2850828511
28509 const union_ptr_ty = sema.typeOf(union_ptr);28512 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);
28511 try union_ty.resolveFields(pt);28514 try union_ty.resolveFields(pt);
28512 const union_obj = mod.typeToUnion(union_ty).?;28515 const union_obj = zcu.typeToUnion(union_ty).?;
28513 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);28516 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
28514 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);28517 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
28515 const ptr_field_ty = try pt.ptrTypeSema(.{28518 const ptr_field_ty = try pt.ptrTypeSema(.{
...@@ -28522,16 +28525,16 @@ fn unionFieldPtr(...@@ -28522,16 +28525,16 @@ fn unionFieldPtr(
28522 const union_align = if (union_ptr_info.flags.alignment != .none)28525 const union_align = if (union_ptr_info.flags.alignment != .none)
28523 union_ptr_info.flags.alignment28526 union_ptr_info.flags.alignment
28524 else28527 else
28525 try sema.typeAbiAlignment(union_ty);28528 try union_ty.abiAlignmentSema(pt);
28526 const field_align = try pt.unionFieldNormalAlignmentAdvanced(union_obj, field_index, .sema);28529 const field_align = try union_ty.fieldAlignmentSema(field_index, pt);
28527 break :blk union_align.min(field_align);28530 break :blk union_align.min(field_align);
28528 } else union_ptr_info.flags.alignment,28531 } else union_ptr_info.flags.alignment,
28529 },28532 },
28530 .packed_offset = union_ptr_info.packed_offset,28533 .packed_offset = union_ptr_info.packed_offset,
28531 });28534 });
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) {
28535 const msg = msg: {28538 const msg = msg: {
28536 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});28539 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
28537 errdefer msg.destroy(sema.gpa);28540 errdefer msg.destroy(sema.gpa);
...@@ -28556,7 +28559,7 @@ fn unionFieldPtr(...@@ -28556,7 +28559,7 @@ fn unionFieldPtr(
28556 } else {28559 } else {
28557 const union_val = (try sema.pointerDeref(block, src, union_ptr_val, union_ptr_ty)) orelse28560 const union_val = (try sema.pointerDeref(block, src, union_ptr_val, union_ptr_ty)) orelse
28558 break :ct;28561 break :ct;
28559 if (union_val.isUndef(mod)) {28562 if (union_val.isUndef(zcu)) {
28560 return sema.failWithUseOfUndef(block, src);28563 return sema.failWithUseOfUndef(block, src);
28561 }28564 }
28562 const un = ip.indexToKey(union_val.toIntern()).un;28565 const un = ip.indexToKey(union_val.toIntern()).un;
...@@ -28564,8 +28567,8 @@ fn unionFieldPtr(...@@ -28564,8 +28567,8 @@ fn unionFieldPtr(
28564 const tag_matches = un.tag == field_tag.toIntern();28567 const tag_matches = un.tag == field_tag.toIntern();
28565 if (!tag_matches) {28568 if (!tag_matches) {
28566 const msg = msg: {28569 const msg = msg: {
28567 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;28570 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
28568 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);28571 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);
28569 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{28572 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
28570 field_name.fmt(ip),28573 field_name.fmt(ip),
28571 active_field_name.fmt(ip),28574 active_field_name.fmt(ip),
...@@ -28585,7 +28588,7 @@ fn unionFieldPtr(...@@ -28585,7 +28588,7 @@ fn unionFieldPtr(
2858528588
28586 try sema.requireRuntimeBlock(block, src, null);28589 try sema.requireRuntimeBlock(block, src, null);
28587 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and28590 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)
28589 {28592 {
28590 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);28593 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28591 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());28594 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
...@@ -28594,7 +28597,7 @@ fn unionFieldPtr(...@@ -28594,7 +28597,7 @@ fn unionFieldPtr(
28594 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val);28597 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val);
28595 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);28598 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);
28596 }28599 }
28597 if (field_ty.zigTypeTag(mod) == .NoReturn) {28600 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
28598 _ = try block.addNoOp(.unreach);28601 _ = try block.addNoOp(.unreach);
28599 return .unreachable_value;28602 return .unreachable_value;
28600 }28603 }
...@@ -28654,7 +28657,7 @@ fn unionFieldVal(...@@ -28654,7 +28657,7 @@ fn unionFieldVal(
28654 .@"packed" => if (tag_matches) {28657 .@"packed" => if (tag_matches) {
28655 // Fast path - no need to use bitcast logic.28658 // Fast path - no need to use bitcast logic.
28656 return Air.internedToRef(un.val);28659 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| {
28658 return Air.internedToRef(field_val.toIntern());28661 return Air.internedToRef(field_val.toIntern());
28659 },28662 },
28660 }28663 }
...@@ -28688,17 +28691,17 @@ fn elemPtr(...@@ -28688,17 +28691,17 @@ fn elemPtr(
28688 oob_safety: bool,28691 oob_safety: bool,
28689) CompileError!Air.Inst.Ref {28692) CompileError!Air.Inst.Ref {
28690 const pt = sema.pt;28693 const pt = sema.pt;
28691 const mod = pt.zcu;28694 const zcu = pt.zcu;
28692 const indexable_ptr_src = src; // TODO better source location28695 const indexable_ptr_src = src; // TODO better source location
28693 const indexable_ptr_ty = sema.typeOf(indexable_ptr);28696 const indexable_ptr_ty = sema.typeOf(indexable_ptr);
2869428697
28695 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(mod)) {28698 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(zcu)) {
28696 .Pointer => indexable_ptr_ty.childType(mod),28699 .Pointer => indexable_ptr_ty.childType(zcu),
28697 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(pt)}),28700 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(pt)}),
28698 };28701 };
28699 try checkIndexable(sema, block, src, indexable_ty);28702 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)) {
28702 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),28705 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),
28703 .Struct => blk: {28706 .Struct => blk: {
28704 // Tuple field access.28707 // Tuple field access.
...@@ -28732,11 +28735,11 @@ fn elemPtrOneLayerOnly(...@@ -28732,11 +28735,11 @@ fn elemPtrOneLayerOnly(
28732 const indexable_src = src; // TODO better source location28735 const indexable_src = src; // TODO better source location
28733 const indexable_ty = sema.typeOf(indexable);28736 const indexable_ty = sema.typeOf(indexable);
28734 const pt = sema.pt;28737 const pt = sema.pt;
28735 const mod = pt.zcu;28738 const zcu = pt.zcu;
2873628739
28737 try checkIndexable(sema, block, src, indexable_ty);28740 try checkIndexable(sema, block, src, indexable_ty);
2873828741
28739 switch (indexable_ty.ptrSize(mod)) {28742 switch (indexable_ty.ptrSize(zcu)) {
28740 .Slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),28743 .Slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
28741 .Many, .C => {28744 .Many, .C => {
28742 const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_src, indexable);28745 const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
...@@ -28754,11 +28757,11 @@ fn elemPtrOneLayerOnly(...@@ -28754,11 +28757,11 @@ fn elemPtrOneLayerOnly(
28754 return block.addPtrElemPtr(indexable, elem_index, result_ty);28757 return block.addPtrElemPtr(indexable, elem_index, result_ty);
28755 },28758 },
28756 .One => {28759 .One => {
28757 const child_ty = indexable_ty.childType(mod);28760 const child_ty = indexable_ty.childType(zcu);
28758 const elem_ptr = switch (child_ty.zigTypeTag(mod)) {28761 const elem_ptr = switch (child_ty.zigTypeTag(zcu)) {
28759 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety),28762 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety),
28760 .Struct => blk: {28763 .Struct => blk: {
28761 assert(child_ty.isTuple(mod));28764 assert(child_ty.isTuple(zcu));
28762 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{28765 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
28763 .needed_comptime_reason = "tuple field access index must be comptime-known",28766 .needed_comptime_reason = "tuple field access index must be comptime-known",
28764 });28767 });
...@@ -28785,7 +28788,7 @@ fn elemVal(...@@ -28785,7 +28788,7 @@ fn elemVal(
28785 const indexable_src = src; // TODO better source location28788 const indexable_src = src; // TODO better source location
28786 const indexable_ty = sema.typeOf(indexable);28789 const indexable_ty = sema.typeOf(indexable);
28787 const pt = sema.pt;28790 const pt = sema.pt;
28788 const mod = pt.zcu;28791 const zcu = pt.zcu;
2878928792
28790 try checkIndexable(sema, block, src, indexable_ty);28793 try checkIndexable(sema, block, src, indexable_ty);
2879128794
...@@ -28793,8 +28796,8 @@ fn elemVal(...@@ -28793,8 +28796,8 @@ fn elemVal(
28793 // index is a scalar or vector instead of unconditionally casting to usize.28796 // index is a scalar or vector instead of unconditionally casting to usize.
28794 const elem_index = try sema.coerce(block, Type.usize, elem_index_uncasted, elem_index_src);28797 const elem_index = try sema.coerce(block, Type.usize, elem_index_uncasted, elem_index_src);
2879528798
28796 switch (indexable_ty.zigTypeTag(mod)) {28799 switch (indexable_ty.zigTypeTag(zcu)) {
28797 .Pointer => switch (indexable_ty.ptrSize(mod)) {28800 .Pointer => switch (indexable_ty.ptrSize(zcu)) {
28798 .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),28801 .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
28799 .Many, .C => {28802 .Many, .C => {
28800 const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable);28803 const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
...@@ -28804,7 +28807,7 @@ fn elemVal(...@@ -28804,7 +28807,7 @@ fn elemVal(
28804 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;28807 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
28805 const index_val = maybe_index_val orelse break :rs elem_index_src;28808 const index_val = maybe_index_val orelse break :rs elem_index_src;
28806 const index: usize = @intCast(try index_val.toUnsignedIntSema(pt));28809 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);
28808 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);28811 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);
28809 const many_ptr_val = try pt.getCoerced(indexable_val, many_ptr_ty);28812 const many_ptr_val = try pt.getCoerced(indexable_val, many_ptr_ty);
28810 const elem_ptr_ty = try pt.singleConstPtrType(elem_ty);28813 const elem_ptr_ty = try pt.singleConstPtrType(elem_ty);
...@@ -28820,12 +28823,12 @@ fn elemVal(...@@ -28820,12 +28823,12 @@ fn elemVal(
28820 },28823 },
28821 .One => {28824 .One => {
28822 arr_sent: {28825 arr_sent: {
28823 const inner_ty = indexable_ty.childType(mod);28826 const inner_ty = indexable_ty.childType(zcu);
28824 if (inner_ty.zigTypeTag(mod) != .Array) break :arr_sent;28827 if (inner_ty.zigTypeTag(zcu) != .Array) break :arr_sent;
28825 const sentinel = inner_ty.sentinel(mod) orelse break :arr_sent;28828 const sentinel = inner_ty.sentinel(zcu) orelse break :arr_sent;
28826 const index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index) orelse break :arr_sent;28829 const index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index) orelse break :arr_sent;
28827 const index = try sema.usizeCast(block, src, try index_val.toUnsignedIntSema(pt));28830 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;
28829 return Air.internedToRef(sentinel.toIntern());28832 return Air.internedToRef(sentinel.toIntern());
28830 }28833 }
28831 const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety);28834 const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety);
...@@ -28857,7 +28860,7 @@ fn validateRuntimeElemAccess(...@@ -28857,7 +28860,7 @@ fn validateRuntimeElemAccess(
28857 parent_ty: Type,28860 parent_ty: Type,
28858 parent_src: LazySrcLoc,28861 parent_src: LazySrcLoc,
28859) CompileError!void {28862) CompileError!void {
28860 if (try sema.typeRequiresComptime(elem_ty)) {28863 if (try elem_ty.comptimeOnlySema(sema.pt)) {
28861 const msg = msg: {28864 const msg = msg: {
28862 const msg = try sema.errMsg(28865 const msg = try sema.errMsg(
28863 elem_index_src,28866 elem_index_src,
...@@ -28884,11 +28887,11 @@ fn tupleFieldPtr(...@@ -28884,11 +28887,11 @@ fn tupleFieldPtr(
28884 init: bool,28887 init: bool,
28885) CompileError!Air.Inst.Ref {28888) CompileError!Air.Inst.Ref {
28886 const pt = sema.pt;28889 const pt = sema.pt;
28887 const mod = pt.zcu;28890 const zcu = pt.zcu;
28888 const tuple_ptr_ty = sema.typeOf(tuple_ptr);28891 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);
28890 try tuple_ty.resolveFields(pt);28893 try tuple_ty.resolveFields(pt);
28891 const field_count = tuple_ty.structFieldCount(mod);28894 const field_count = tuple_ty.structFieldCount(zcu);
2889228895
28893 if (field_count == 0) {28896 if (field_count == 0) {
28894 return sema.fail(block, tuple_ptr_src, "indexing into empty tuple is not allowed", .{});28897 return sema.fail(block, tuple_ptr_src, "indexing into empty tuple is not allowed", .{});
...@@ -28900,17 +28903,17 @@ fn tupleFieldPtr(...@@ -28900,17 +28903,17 @@ fn tupleFieldPtr(
28900 });28903 });
28901 }28904 }
2890228905
28903 const field_ty = tuple_ty.structFieldType(field_index, mod);28906 const field_ty = tuple_ty.fieldType(field_index, zcu);
28904 const ptr_field_ty = try pt.ptrTypeSema(.{28907 const ptr_field_ty = try pt.ptrTypeSema(.{
28905 .child = field_ty.toIntern(),28908 .child = field_ty.toIntern(),
28906 .flags = .{28909 .flags = .{
28907 .is_const = !tuple_ptr_ty.ptrIsMutable(mod),28910 .is_const = !tuple_ptr_ty.ptrIsMutable(zcu),
28908 .is_volatile = tuple_ptr_ty.isVolatilePtr(mod),28911 .is_volatile = tuple_ptr_ty.isVolatilePtr(zcu),
28909 .address_space = tuple_ptr_ty.ptrAddressSpace(mod),28912 .address_space = tuple_ptr_ty.ptrAddressSpace(zcu),
28910 },28913 },
28911 });28914 });
2891228915
28913 if (tuple_ty.structFieldIsComptime(field_index, mod))28916 if (tuple_ty.structFieldIsComptime(field_index, zcu))
28914 try tuple_ty.resolveStructFieldInits(pt);28917 try tuple_ty.resolveStructFieldInits(pt);
2891528918
28916 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_val| {28919 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_val| {
...@@ -28943,10 +28946,10 @@ fn tupleField(...@@ -28943,10 +28946,10 @@ fn tupleField(
28943 field_index: u32,28946 field_index: u32,
28944) CompileError!Air.Inst.Ref {28947) CompileError!Air.Inst.Ref {
28945 const pt = sema.pt;28948 const pt = sema.pt;
28946 const mod = pt.zcu;28949 const zcu = pt.zcu;
28947 const tuple_ty = sema.typeOf(tuple);28950 const tuple_ty = sema.typeOf(tuple);
28948 try tuple_ty.resolveFields(pt);28951 try tuple_ty.resolveFields(pt);
28949 const field_count = tuple_ty.structFieldCount(mod);28952 const field_count = tuple_ty.structFieldCount(zcu);
2895028953
28951 if (field_count == 0) {28954 if (field_count == 0) {
28952 return sema.fail(block, tuple_src, "indexing into empty tuple is not allowed", .{});28955 return sema.fail(block, tuple_src, "indexing into empty tuple is not allowed", .{});
...@@ -28958,16 +28961,16 @@ fn tupleField(...@@ -28958,16 +28961,16 @@ fn tupleField(
28958 });28961 });
28959 }28962 }
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))
28964 try tuple_ty.resolveStructFieldInits(pt);28967 try tuple_ty.resolveStructFieldInits(pt);
28965 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {28968 if (try tuple_ty.structFieldValueComptime(pt, field_index)) |default_value| {
28966 return Air.internedToRef(default_value.toIntern()); // comptime field28969 return Air.internedToRef(default_value.toIntern()); // comptime field
28967 }28970 }
2896828971
28969 if (try sema.resolveValue(tuple)) |tuple_val| {28972 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);
28971 return Air.internedToRef((try tuple_val.fieldValue(pt, field_index)).toIntern());28974 return Air.internedToRef((try tuple_val.fieldValue(pt, field_index)).toIntern());
28972 }28975 }
2897328976
...@@ -28989,12 +28992,12 @@ fn elemValArray(...@@ -28989,12 +28992,12 @@ fn elemValArray(
28989 oob_safety: bool,28992 oob_safety: bool,
28990) CompileError!Air.Inst.Ref {28993) CompileError!Air.Inst.Ref {
28991 const pt = sema.pt;28994 const pt = sema.pt;
28992 const mod = pt.zcu;28995 const zcu = pt.zcu;
28993 const array_ty = sema.typeOf(array);28996 const array_ty = sema.typeOf(array);
28994 const array_sent = array_ty.sentinel(mod);28997 const array_sent = array_ty.sentinel(zcu);
28995 const array_len = array_ty.arrayLen(mod);28998 const array_len = array_ty.arrayLen(zcu);
28996 const array_len_s = array_len + @intFromBool(array_sent != null);28999 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
28999 if (array_len_s == 0) {29002 if (array_len_s == 0) {
29000 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});29003 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});
...@@ -29017,7 +29020,7 @@ fn elemValArray(...@@ -29017,7 +29020,7 @@ fn elemValArray(
29017 }29020 }
29018 }29021 }
29019 if (maybe_undef_array_val) |array_val| {29022 if (maybe_undef_array_val) |array_val| {
29020 if (array_val.isUndef(mod)) {29023 if (array_val.isUndef(zcu)) {
29021 return pt.undefRef(elem_ty);29024 return pt.undefRef(elem_ty);
29022 }29025 }
29023 if (maybe_index_val) |index_val| {29026 if (maybe_index_val) |index_val| {
...@@ -29058,11 +29061,11 @@ fn elemPtrArray(...@@ -29058,11 +29061,11 @@ fn elemPtrArray(
29058 oob_safety: bool,29061 oob_safety: bool,
29059) CompileError!Air.Inst.Ref {29062) CompileError!Air.Inst.Ref {
29060 const pt = sema.pt;29063 const pt = sema.pt;
29061 const mod = pt.zcu;29064 const zcu = pt.zcu;
29062 const array_ptr_ty = sema.typeOf(array_ptr);29065 const array_ptr_ty = sema.typeOf(array_ptr);
29063 const array_ty = array_ptr_ty.childType(mod);29066 const array_ty = array_ptr_ty.childType(zcu);
29064 const array_sent = array_ty.sentinel(mod) != null;29067 const array_sent = array_ty.sentinel(zcu) != null;
29065 const array_len = array_ty.arrayLen(mod);29068 const array_len = array_ty.arrayLen(zcu);
29066 const array_len_s = array_len + @intFromBool(array_sent);29069 const array_len_s = array_len + @intFromBool(array_sent);
2906729070
29068 if (array_len_s == 0) {29071 if (array_len_s == 0) {
...@@ -29083,7 +29086,7 @@ fn elemPtrArray(...@@ -29083,7 +29086,7 @@ fn elemPtrArray(
29083 const elem_ptr_ty = try array_ptr_ty.elemPtrType(offset, pt);29086 const elem_ptr_ty = try array_ptr_ty.elemPtrType(offset, pt);
2908429087
29085 if (maybe_undef_array_ptr_val) |array_ptr_val| {29088 if (maybe_undef_array_ptr_val) |array_ptr_val| {
29086 if (array_ptr_val.isUndef(mod)) {29089 if (array_ptr_val.isUndef(zcu)) {
29087 return pt.undefRef(elem_ptr_ty);29090 return pt.undefRef(elem_ptr_ty);
29088 }29091 }
29089 if (offset) |index| {29092 if (offset) |index| {
...@@ -29093,7 +29096,7 @@ fn elemPtrArray(...@@ -29093,7 +29096,7 @@ fn elemPtrArray(
29093 }29096 }
2909429097
29095 if (!init) {29098 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);
29097 }29100 }
2909829101
29099 const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src;29102 const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src;
...@@ -29120,10 +29123,10 @@ fn elemValSlice(...@@ -29120,10 +29123,10 @@ fn elemValSlice(
29120 oob_safety: bool,29123 oob_safety: bool,
29121) CompileError!Air.Inst.Ref {29124) CompileError!Air.Inst.Ref {
29122 const pt = sema.pt;29125 const pt = sema.pt;
29123 const mod = pt.zcu;29126 const zcu = pt.zcu;
29124 const slice_ty = sema.typeOf(slice);29127 const slice_ty = sema.typeOf(slice);
29125 const slice_sent = slice_ty.sentinel(mod) != null;29128 const slice_sent = slice_ty.sentinel(zcu) != null;
29126 const elem_ty = slice_ty.elemType2(mod);29129 const elem_ty = slice_ty.elemType2(zcu);
29127 var runtime_src = slice_src;29130 var runtime_src = slice_src;
2912829131
29129 // slice must be defined since it can dereferenced as null29132 // slice must be defined since it can dereferenced as null
...@@ -29178,9 +29181,9 @@ fn elemPtrSlice(...@@ -29178,9 +29181,9 @@ fn elemPtrSlice(
29178 oob_safety: bool,29181 oob_safety: bool,
29179) CompileError!Air.Inst.Ref {29182) CompileError!Air.Inst.Ref {
29180 const pt = sema.pt;29183 const pt = sema.pt;
29181 const mod = pt.zcu;29184 const zcu = pt.zcu;
29182 const slice_ty = sema.typeOf(slice);29185 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
29185 const maybe_undef_slice_val = try sema.resolveValue(slice);29188 const maybe_undef_slice_val = try sema.resolveValue(slice);
29186 // The index must not be undefined since it can be out of bounds.29189 // The index must not be undefined since it can be out of bounds.
...@@ -29192,7 +29195,7 @@ fn elemPtrSlice(...@@ -29192,7 +29195,7 @@ fn elemPtrSlice(
29192 const elem_ptr_ty = try slice_ty.elemPtrType(offset, pt);29195 const elem_ptr_ty = try slice_ty.elemPtrType(offset, pt);
2919329196
29194 if (maybe_undef_slice_val) |slice_val| {29197 if (maybe_undef_slice_val) |slice_val| {
29195 if (slice_val.isUndef(mod)) {29198 if (slice_val.isUndef(zcu)) {
29196 return pt.undefRef(elem_ptr_ty);29199 return pt.undefRef(elem_ptr_ty);
29197 }29200 }
29198 const slice_len = try slice_val.sliceLen(pt);29201 const slice_len = try slice_val.sliceLen(pt);
...@@ -29217,7 +29220,7 @@ fn elemPtrSlice(...@@ -29217,7 +29220,7 @@ fn elemPtrSlice(
29217 if (oob_safety and block.wantSafety()) {29220 if (oob_safety and block.wantSafety()) {
29218 const len_inst = len: {29221 const len_inst = len: {
29219 if (maybe_undef_slice_val) |slice_val|29222 if (maybe_undef_slice_val) |slice_val|
29220 if (!slice_val.isUndef(mod))29223 if (!slice_val.isUndef(zcu))
29221 break :len try pt.intRef(Type.usize, try slice_val.sliceLen(pt));29224 break :len try pt.intRef(Type.usize, try slice_val.sliceLen(pt));
29222 break :len try block.addTyOp(.slice_len, Type.usize, slice);29225 break :len try block.addTyOp(.slice_len, Type.usize, slice);
29223 };29226 };
...@@ -29600,7 +29603,7 @@ fn coerceExtra(...@@ -29600,7 +29603,7 @@ fn coerceExtra(
29600 // empty tuple to zero-length slice29603 // empty tuple to zero-length slice
29601 // note that this allows coercing to a mutable slice.29604 // note that this allows coercing to a mutable slice.
29602 if (inst_child_ty.structFieldCount(zcu) == 0) {29605 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);
29604 return Air.internedToRef(try pt.intern(.{ .slice = .{29607 return Air.internedToRef(try pt.intern(.{ .slice = .{
29605 .ty = dest_ty.toIntern(),29608 .ty = dest_ty.toIntern(),
29606 .ptr = try pt.intern(.{ .ptr = .{29609 .ptr = try pt.intern(.{ .ptr = .{
...@@ -30098,7 +30101,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -30098,7 +30101,7 @@ const InMemoryCoercionResult = union(enum) {
30098 return res;30101 return res;
30099 }30102 }
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 {
30102 const pt = sema.pt;30105 const pt = sema.pt;
30103 var cur = res;30106 var cur = res;
30104 while (true) switch (cur.*) {30107 while (true) switch (cur.*) {
...@@ -30364,18 +30367,18 @@ pub fn coerceInMemoryAllowed(...@@ -30364,18 +30367,18 @@ pub fn coerceInMemoryAllowed(
30364 src_val: ?Value,30367 src_val: ?Value,
30365) CompileError!InMemoryCoercionResult {30368) CompileError!InMemoryCoercionResult {
30366 const pt = sema.pt;30369 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))
30370 return .ok;30373 return .ok;
3037130374
30372 const dest_tag = dest_ty.zigTypeTag(mod);30375 const dest_tag = dest_ty.zigTypeTag(zcu);
30373 const src_tag = src_ty.zigTypeTag(mod);30376 const src_tag = src_ty.zigTypeTag(zcu);
3037430377
30375 // Differently-named integers with the same number of bits.30378 // Differently-named integers with the same number of bits.
30376 if (dest_tag == .Int and src_tag == .Int) {30379 if (dest_tag == .Int and src_tag == .Int) {
30377 const dest_info = dest_ty.intInfo(mod);30380 const dest_info = dest_ty.intInfo(zcu);
30378 const src_info = src_ty.intInfo(mod);30381 const src_info = src_ty.intInfo(zcu);
3037930382
30380 if (dest_info.signedness == src_info.signedness and30383 if (dest_info.signedness == src_info.signedness and
30381 dest_info.bits == src_info.bits)30384 dest_info.bits == src_info.bits)
...@@ -30425,7 +30428,7 @@ pub fn coerceInMemoryAllowed(...@@ -30425,7 +30428,7 @@ pub fn coerceInMemoryAllowed(
30425 }30428 }
3042630429
30427 // Slices30430 // Slices
30428 if (dest_ty.isSlice(mod) and src_ty.isSlice(mod)) {30431 if (dest_ty.isSlice(zcu) and src_ty.isSlice(zcu)) {
30429 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src);30432 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ty, src_ty, dest_is_mut, target, dest_src, src_src);
30430 }30433 }
3043130434
...@@ -30436,8 +30439,8 @@ pub fn coerceInMemoryAllowed(...@@ -30436,8 +30439,8 @@ pub fn coerceInMemoryAllowed(
3043630439
30437 // Error Unions30440 // Error Unions
30438 if (dest_tag == .ErrorUnion and src_tag == .ErrorUnion) {30441 if (dest_tag == .ErrorUnion and src_tag == .ErrorUnion) {
30439 const dest_payload = dest_ty.errorUnionPayload(mod);30442 const dest_payload = dest_ty.errorUnionPayload(zcu);
30440 const src_payload = src_ty.errorUnionPayload(mod);30443 const src_payload = src_ty.errorUnionPayload(zcu);
30441 const child = try sema.coerceInMemoryAllowed(block, dest_payload, src_payload, dest_is_mut, target, dest_src, src_src, null);30444 const child = try sema.coerceInMemoryAllowed(block, dest_payload, src_payload, dest_is_mut, target, dest_src, src_src, null);
30442 if (child != .ok) {30445 if (child != .ok) {
30443 return InMemoryCoercionResult{ .error_union_payload = .{30446 return InMemoryCoercionResult{ .error_union_payload = .{
...@@ -30446,7 +30449,7 @@ pub fn coerceInMemoryAllowed(...@@ -30446,7 +30449,7 @@ pub fn coerceInMemoryAllowed(
30446 .wanted = dest_payload,30449 .wanted = dest_payload,
30447 } };30450 } };
30448 }30451 }
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);
30450 }30453 }
3045130454
30452 // Error Sets30455 // Error Sets
...@@ -30456,8 +30459,8 @@ pub fn coerceInMemoryAllowed(...@@ -30456,8 +30459,8 @@ pub fn coerceInMemoryAllowed(
3045630459
30457 // Arrays30460 // Arrays
30458 if (dest_tag == .Array and src_tag == .Array) {30461 if (dest_tag == .Array and src_tag == .Array) {
30459 const dest_info = dest_ty.arrayInfo(mod);30462 const dest_info = dest_ty.arrayInfo(zcu);
30460 const src_info = src_ty.arrayInfo(mod);30463 const src_info = src_ty.arrayInfo(zcu);
30461 if (dest_info.len != src_info.len) {30464 if (dest_info.len != src_info.len) {
30462 return InMemoryCoercionResult{ .array_len = .{30465 return InMemoryCoercionResult{ .array_len = .{
30463 .actual = src_info.len,30466 .actual = src_info.len,
...@@ -30483,7 +30486,7 @@ pub fn coerceInMemoryAllowed(...@@ -30483,7 +30486,7 @@ pub fn coerceInMemoryAllowed(
30483 dest_info.sentinel.?.eql(30486 dest_info.sentinel.?.eql(
30484 try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type),30487 try pt.getCoerced(src_info.sentinel.?, dest_info.elem_type),
30485 dest_info.elem_type,30488 dest_info.elem_type,
30486 mod,30489 zcu,
30487 ));30490 ));
30488 if (!ok_sent) {30491 if (!ok_sent) {
30489 return InMemoryCoercionResult{ .array_sentinel = .{30492 return InMemoryCoercionResult{ .array_sentinel = .{
...@@ -30497,8 +30500,8 @@ pub fn coerceInMemoryAllowed(...@@ -30497,8 +30500,8 @@ pub fn coerceInMemoryAllowed(
3049730500
30498 // Vectors30501 // Vectors
30499 if (dest_tag == .Vector and src_tag == .Vector) {30502 if (dest_tag == .Vector and src_tag == .Vector) {
30500 const dest_len = dest_ty.vectorLen(mod);30503 const dest_len = dest_ty.vectorLen(zcu);
30501 const src_len = src_ty.vectorLen(mod);30504 const src_len = src_ty.vectorLen(zcu);
30502 if (dest_len != src_len) {30505 if (dest_len != src_len) {
30503 return InMemoryCoercionResult{ .vector_len = .{30506 return InMemoryCoercionResult{ .vector_len = .{
30504 .actual = src_len,30507 .actual = src_len,
...@@ -30506,8 +30509,8 @@ pub fn coerceInMemoryAllowed(...@@ -30506,8 +30509,8 @@ pub fn coerceInMemoryAllowed(
30506 } };30509 } };
30507 }30510 }
3050830511
30509 const dest_elem_ty = dest_ty.scalarType(mod);30512 const dest_elem_ty = dest_ty.scalarType(zcu);
30510 const src_elem_ty = src_ty.scalarType(mod);30513 const src_elem_ty = src_ty.scalarType(zcu);
30511 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);30514 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);
30512 if (child != .ok) {30515 if (child != .ok) {
30513 return InMemoryCoercionResult{ .vector_elem = .{30516 return InMemoryCoercionResult{ .vector_elem = .{
...@@ -30524,8 +30527,8 @@ pub fn coerceInMemoryAllowed(...@@ -30524,8 +30527,8 @@ pub fn coerceInMemoryAllowed(
30524 if ((dest_tag == .Vector and src_tag == .Array) or30527 if ((dest_tag == .Vector and src_tag == .Array) or
30525 (dest_tag == .Array and src_tag == .Vector))30528 (dest_tag == .Array and src_tag == .Vector))
30526 {30529 {
30527 const dest_len = dest_ty.arrayLen(mod);30530 const dest_len = dest_ty.arrayLen(zcu);
30528 const src_len = src_ty.arrayLen(mod);30531 const src_len = src_ty.arrayLen(zcu);
30529 if (dest_len != src_len) {30532 if (dest_len != src_len) {
30530 return InMemoryCoercionResult{ .array_len = .{30533 return InMemoryCoercionResult{ .array_len = .{
30531 .actual = src_len,30534 .actual = src_len,
...@@ -30533,8 +30536,8 @@ pub fn coerceInMemoryAllowed(...@@ -30533,8 +30536,8 @@ pub fn coerceInMemoryAllowed(
30533 } };30536 } };
30534 }30537 }
3053530538
30536 const dest_elem_ty = dest_ty.childType(mod);30539 const dest_elem_ty = dest_ty.childType(zcu);
30537 const src_elem_ty = src_ty.childType(mod);30540 const src_elem_ty = src_ty.childType(zcu);
30538 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);30541 const child = try sema.coerceInMemoryAllowed(block, dest_elem_ty, src_elem_ty, dest_is_mut, target, dest_src, src_src, null);
30539 if (child != .ok) {30542 if (child != .ok) {
30540 return InMemoryCoercionResult{ .array_elem = .{30543 return InMemoryCoercionResult{ .array_elem = .{
...@@ -30545,7 +30548,7 @@ pub fn coerceInMemoryAllowed(...@@ -30545,7 +30548,7 @@ pub fn coerceInMemoryAllowed(
30545 }30548 }
3054630549
30547 if (dest_tag == .Array) {30550 if (dest_tag == .Array) {
30548 const dest_info = dest_ty.arrayInfo(mod);30551 const dest_info = dest_ty.arrayInfo(zcu);
30549 if (dest_info.sentinel != null) {30552 if (dest_info.sentinel != null) {
30550 return InMemoryCoercionResult{ .array_sentinel = .{30553 return InMemoryCoercionResult{ .array_sentinel = .{
30551 .actual = Value.@"unreachable",30554 .actual = Value.@"unreachable",
...@@ -30558,8 +30561,8 @@ pub fn coerceInMemoryAllowed(...@@ -30558,8 +30561,8 @@ pub fn coerceInMemoryAllowed(
30558 // The memory layout of @Vector(N, iM) is the same as the integer type i(N*M),30561 // The memory layout of @Vector(N, iM) is the same as the integer type i(N*M),
30559 // that is to say, the padding bits are not in the same place as the array [N]iM.30562 // that is to say, the padding bits are not in the same place as the array [N]iM.
30560 // If there's no padding, the bitcast is possible.30563 // If there's no padding, the bitcast is possible.
30561 const elem_bit_size = dest_elem_ty.bitSize(pt);30564 const elem_bit_size = dest_elem_ty.bitSize(zcu);
30562 const elem_abi_byte_size = dest_elem_ty.abiSize(pt);30565 const elem_abi_byte_size = dest_elem_ty.abiSize(zcu);
30563 if (elem_abi_byte_size * 8 == elem_bit_size)30566 if (elem_abi_byte_size * 8 == elem_bit_size)
30564 return .ok;30567 return .ok;
30565 }30568 }
...@@ -30572,8 +30575,8 @@ pub fn coerceInMemoryAllowed(...@@ -30572,8 +30575,8 @@ pub fn coerceInMemoryAllowed(
30572 .wanted = dest_ty,30575 .wanted = dest_ty,
30573 } };30576 } };
30574 }30577 }
30575 const dest_child_type = dest_ty.optionalChild(mod);30578 const dest_child_type = dest_ty.optionalChild(zcu);
30576 const src_child_type = src_ty.optionalChild(mod);30579 const src_child_type = src_ty.optionalChild(zcu);
3057730580
30578 const child = try sema.coerceInMemoryAllowed(block, dest_child_type, src_child_type, dest_is_mut, target, dest_src, src_src, null);30581 const child = try sema.coerceInMemoryAllowed(block, dest_child_type, src_child_type, dest_is_mut, target, dest_src, src_src, null);
30579 if (child != .ok) {30582 if (child != .ok) {
...@@ -30588,15 +30591,15 @@ pub fn coerceInMemoryAllowed(...@@ -30588,15 +30591,15 @@ pub fn coerceInMemoryAllowed(
30588 }30591 }
3058930592
30590 // Tuples (with in-memory-coercible fields)30593 // Tuples (with in-memory-coercible fields)
30591 if (dest_ty.isTuple(mod) and src_ty.isTuple(mod)) tuple: {30594 if (dest_ty.isTuple(zcu) and src_ty.isTuple(zcu)) tuple: {
30592 if (dest_ty.containerLayout(mod) != src_ty.containerLayout(mod)) break :tuple;30595 if (dest_ty.containerLayout(zcu) != src_ty.containerLayout(zcu)) break :tuple;
30593 if (dest_ty.structFieldCount(mod) != src_ty.structFieldCount(mod)) break :tuple;30596 if (dest_ty.structFieldCount(zcu) != src_ty.structFieldCount(zcu)) break :tuple;
30594 const field_count = dest_ty.structFieldCount(mod);30597 const field_count = dest_ty.structFieldCount(zcu);
30595 for (0..field_count) |field_idx| {30598 for (0..field_count) |field_idx| {
30596 if (dest_ty.structFieldIsComptime(field_idx, mod) != src_ty.structFieldIsComptime(field_idx, mod)) break :tuple;30599 if (dest_ty.structFieldIsComptime(field_idx, zcu) != src_ty.structFieldIsComptime(field_idx, zcu)) break :tuple;
30597 if (dest_ty.structFieldAlign(field_idx, pt) != src_ty.structFieldAlign(field_idx, pt)) break :tuple;30600 if (dest_ty.fieldAlignment(field_idx, zcu) != src_ty.fieldAlignment(field_idx, zcu)) break :tuple;
30598 const dest_field_ty = dest_ty.structFieldType(field_idx, mod);30601 const dest_field_ty = dest_ty.fieldType(field_idx, zcu);
30599 const src_field_ty = src_ty.structFieldType(field_idx, mod);30602 const src_field_ty = src_ty.fieldType(field_idx, zcu);
30600 const field = try sema.coerceInMemoryAllowed(block, dest_field_ty, src_field_ty, dest_is_mut, target, dest_src, src_src, null);30603 const field = try sema.coerceInMemoryAllowed(block, dest_field_ty, src_field_ty, dest_is_mut, target, dest_src, src_src, null);
30601 if (field != .ok) break :tuple;30604 if (field != .ok) break :tuple;
30602 }30605 }
...@@ -30618,13 +30621,13 @@ fn coerceInMemoryAllowedErrorSets(...@@ -30618,13 +30621,13 @@ fn coerceInMemoryAllowedErrorSets(
30618 src_src: LazySrcLoc,30621 src_src: LazySrcLoc,
30619) !InMemoryCoercionResult {30622) !InMemoryCoercionResult {
30620 const pt = sema.pt;30623 const pt = sema.pt;
30621 const mod = pt.zcu;30624 const zcu = pt.zcu;
30622 const gpa = sema.gpa;30625 const gpa = sema.gpa;
30623 const ip = &mod.intern_pool;30626 const ip = &zcu.intern_pool;
3062430627
30625 // Coercion to `anyerror`. Note that this check can return false negatives30628 // Coercion to `anyerror`. Note that this check can return false negatives
30626 // in case the error sets did not get resolved.30629 // in case the error sets did not get resolved.
30627 if (dest_ty.isAnyError(mod)) {30630 if (dest_ty.isAnyError(zcu)) {
30628 return .ok;30631 return .ok;
30629 }30632 }
3063030633
...@@ -30669,7 +30672,7 @@ fn coerceInMemoryAllowedErrorSets(...@@ -30669,7 +30672,7 @@ fn coerceInMemoryAllowedErrorSets(
30669 const resolved_src_ty = try sema.resolveInferredErrorSet(block, src_src, src_ty.toIntern());30672 const resolved_src_ty = try sema.resolveInferredErrorSet(block, src_src, src_ty.toIntern());
30670 // src anyerror status might have changed after the resolution.30673 // src anyerror status might have changed after the resolution.
30671 if (resolved_src_ty == .anyerror_type) {30674 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.
30673 return .from_anyerror;30676 return .from_anyerror;
30674 }30677 }
3067530678
...@@ -30717,11 +30720,11 @@ fn coerceInMemoryAllowedFns(...@@ -30717,11 +30720,11 @@ fn coerceInMemoryAllowedFns(
30717 src_src: LazySrcLoc,30720 src_src: LazySrcLoc,
30718) !InMemoryCoercionResult {30721) !InMemoryCoercionResult {
30719 const pt = sema.pt;30722 const pt = sema.pt;
30720 const mod = pt.zcu;30723 const zcu = pt.zcu;
30721 const ip = &mod.intern_pool;30724 const ip = &zcu.intern_pool;
3072230725
30723 const dest_info = mod.typeToFunc(dest_ty).?;30726 const dest_info = zcu.typeToFunc(dest_ty).?;
30724 const src_info = mod.typeToFunc(src_ty).?;30727 const src_info = zcu.typeToFunc(src_ty).?;
3072530728
30726 {30729 {
30727 if (dest_info.is_var_args != src_info.is_var_args) {30730 if (dest_info.is_var_args != src_info.is_var_args) {
...@@ -30922,12 +30925,12 @@ fn coerceInMemoryAllowedPtrs(...@@ -30922,12 +30925,12 @@ fn coerceInMemoryAllowedPtrs(
30922 const src_align = if (src_info.flags.alignment != .none)30925 const src_align = if (src_info.flags.alignment != .none)
30923 src_info.flags.alignment30926 src_info.flags.alignment
30924 else30927 else
30925 try sema.typeAbiAlignment(Type.fromInterned(src_info.child));30928 try Type.fromInterned(src_info.child).abiAlignmentSema(pt);
3092630929
30927 const dest_align = if (dest_info.flags.alignment != .none)30930 const dest_align = if (dest_info.flags.alignment != .none)
30928 dest_info.flags.alignment30931 dest_info.flags.alignment
30929 else30932 else
30930 try sema.typeAbiAlignment(Type.fromInterned(dest_info.child));30933 try Type.fromInterned(dest_info.child).abiAlignmentSema(pt);
3093130934
30932 if (dest_align.compare(.gt, src_align)) {30935 if (dest_align.compare(.gt, src_align)) {
30933 return InMemoryCoercionResult{ .ptr_alignment = .{30936 return InMemoryCoercionResult{ .ptr_alignment = .{
...@@ -31044,12 +31047,12 @@ fn storePtr2(...@@ -31044,12 +31047,12 @@ fn storePtr2(
31044 air_tag: Air.Inst.Tag,31047 air_tag: Air.Inst.Tag,
31045) CompileError!void {31048) CompileError!void {
31046 const pt = sema.pt;31049 const pt = sema.pt;
31047 const mod = pt.zcu;31050 const zcu = pt.zcu;
31048 const ptr_ty = sema.typeOf(ptr);31051 const ptr_ty = sema.typeOf(ptr);
31049 if (ptr_ty.isConstPtr(mod))31052 if (ptr_ty.isConstPtr(zcu))
31050 return sema.fail(block, ptr_src, "cannot assign to constant", .{});31053 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
31054 // To generate better code for tuples, we detect a tuple operand here, and31057 // To generate better code for tuples, we detect a tuple operand here, and
31055 // analyze field loads and stores directly. This avoids an extra allocation + memcpy31058 // analyze field loads and stores directly. This avoids an extra allocation + memcpy
...@@ -31060,8 +31063,8 @@ fn storePtr2(...@@ -31060,8 +31063,8 @@ fn storePtr2(
31060 // this code does not handle tuple-to-struct coercion which requires dealing with missing31063 // this code does not handle tuple-to-struct coercion which requires dealing with missing
31061 // fields.31064 // fields.
31062 const operand_ty = sema.typeOf(uncasted_operand);31065 const operand_ty = sema.typeOf(uncasted_operand);
31063 if (operand_ty.isTuple(mod) and elem_ty.zigTypeTag(mod) == .Array) {31066 if (operand_ty.isTuple(zcu) and elem_ty.zigTypeTag(zcu) == .Array) {
31064 const field_count = operand_ty.structFieldCount(mod);31067 const field_count = operand_ty.structFieldCount(zcu);
31065 var i: u32 = 0;31068 var i: u32 = 0;
31066 while (i < field_count) : (i += 1) {31069 while (i < field_count) : (i += 1) {
31067 const elem_src = operand_src; // TODO better source location31070 const elem_src = operand_src; // TODO better source location
...@@ -31085,7 +31088,7 @@ fn storePtr2(...@@ -31085,7 +31088,7 @@ fn storePtr2(
31085 // as well as working around an LLVM bug:31088 // as well as working around an LLVM bug:
31086 // https://github.com/ziglang/zig/issues/1115431089 // https://github.com/ziglang/zig/issues/11154
31087 if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| {31090 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);
31089 const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {31092 const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
31090 error.NotCoercible => unreachable,31093 error.NotCoercible => unreachable,
31091 else => |e| return e,31094 else => |e| return e,
...@@ -31119,7 +31122,7 @@ fn storePtr2(...@@ -31119,7 +31122,7 @@ fn storePtr2(
3111931122
31120 try sema.requireRuntimeBlock(block, src, runtime_src);31123 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) {
31123 const ptr_inst = ptr.toIndex().?;31126 const ptr_inst = ptr.toIndex().?;
31124 const air_tags = sema.air_instructions.items(.tag);31127 const air_tags = sema.air_instructions.items(.tag);
31125 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {31128 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
...@@ -31253,9 +31256,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins...@@ -31253,9 +31256,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
31253/// lengths match.31256/// lengths match.
31254fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {31257fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
31255 const pt = sema.pt;31258 const pt = sema.pt;
31256 const mod = pt.zcu;31259 const zcu = pt.zcu;
31257 const array_ty = sema.typeOf(ptr).childType(mod);31260 const array_ty = sema.typeOf(ptr).childType(zcu);
31258 if (array_ty.zigTypeTag(mod) != .Array) return null;31261 if (array_ty.zigTypeTag(zcu) != .Array) return null;
31259 var ptr_ref = ptr;31262 var ptr_ref = ptr;
31260 var ptr_inst = ptr_ref.toIndex() orelse return null;31263 var ptr_inst = ptr_ref.toIndex() orelse return null;
31261 const air_datas = sema.air_instructions.items(.data);31264 const air_datas = sema.air_instructions.items(.data);
...@@ -31263,15 +31266,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {...@@ -31263,15 +31266,15 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
31263 const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {31266 const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
31264 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;31267 ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
31265 if (!sema.isKnownZigType(ptr_ref, .Pointer)) return null;31268 if (!sema.isKnownZigType(ptr_ref, .Pointer)) return null;
31266 const child_ty = sema.typeOf(ptr_ref).childType(mod);31269 const child_ty = sema.typeOf(ptr_ref).childType(zcu);
31267 if (child_ty.zigTypeTag(mod) == .Vector) break child_ty;31270 if (child_ty.zigTypeTag(zcu) == .Vector) break child_ty;
31268 ptr_inst = ptr_ref.toIndex() orelse return null;31271 ptr_inst = ptr_ref.toIndex() orelse return null;
31269 } else return null;31272 } else return null;
3127031273
31271 // We have a pointer-to-array and a pointer-to-vector. If the elements and31274 // We have a pointer-to-array and a pointer-to-vector. If the elements and
31272 // lengths match, return the result.31275 // lengths match, return the result.
31273 if (array_ty.childType(mod).eql(vector_ty.childType(mod), mod) and31276 if (array_ty.childType(zcu).eql(vector_ty.childType(zcu), zcu) and
31274 array_ty.arrayLen(mod) == vector_ty.vectorLen(mod))31277 array_ty.arrayLen(zcu) == vector_ty.vectorLen(zcu))
31275 {31278 {
31276 return ptr_ref;31279 return ptr_ref;
31277 } else {31280 } else {
...@@ -31347,8 +31350,8 @@ fn bitCast(...@@ -31347,8 +31350,8 @@ fn bitCast(
31347 const old_ty = sema.typeOf(inst);31350 const old_ty = sema.typeOf(inst);
31348 try old_ty.resolveLayout(pt);31351 try old_ty.resolveLayout(pt);
3134931352
31350 const dest_bits = dest_ty.bitSize(pt);31353 const dest_bits = dest_ty.bitSize(zcu);
31351 const old_bits = old_ty.bitSize(pt);31354 const old_bits = old_ty.bitSize(zcu);
3135231355
31353 if (old_bits != dest_bits) {31356 if (old_bits != dest_bits) {
31354 return sema.fail(block, inst_src, "@bitCast size mismatch: destination type '{}' has {d} bits but source type '{}' has {d} bits", .{31357 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(...@@ -31384,16 +31387,16 @@ fn coerceArrayPtrToSlice(
31384 inst_src: LazySrcLoc,31387 inst_src: LazySrcLoc,
31385) CompileError!Air.Inst.Ref {31388) CompileError!Air.Inst.Ref {
31386 const pt = sema.pt;31389 const pt = sema.pt;
31387 const mod = pt.zcu;31390 const zcu = pt.zcu;
31388 if (try sema.resolveValue(inst)) |val| {31391 if (try sema.resolveValue(inst)) |val| {
31389 const ptr_array_ty = sema.typeOf(inst);31392 const ptr_array_ty = sema.typeOf(inst);
31390 const array_ty = ptr_array_ty.childType(mod);31393 const array_ty = ptr_array_ty.childType(zcu);
31391 const slice_ptr_ty = dest_ty.slicePtrFieldType(mod);31394 const slice_ptr_ty = dest_ty.slicePtrFieldType(zcu);
31392 const slice_ptr = try pt.getCoerced(val, slice_ptr_ty);31395 const slice_ptr = try pt.getCoerced(val, slice_ptr_ty);
31393 const slice_val = try pt.intern(.{ .slice = .{31396 const slice_val = try pt.intern(.{ .slice = .{
31394 .ty = dest_ty.toIntern(),31397 .ty = dest_ty.toIntern(),
31395 .ptr = slice_ptr.toIntern(),31398 .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(),
31397 } });31400 } });
31398 return Air.internedToRef(slice_val);31401 return Air.internedToRef(slice_val);
31399 }31402 }
...@@ -31403,12 +31406,12 @@ fn coerceArrayPtrToSlice(...@@ -31403,12 +31406,12 @@ fn coerceArrayPtrToSlice(
3140331406
31404fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_result: *InMemoryCoercionResult) bool {31407fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_result: *InMemoryCoercionResult) bool {
31405 const pt = sema.pt;31408 const pt = sema.pt;
31406 const mod = pt.zcu;31409 const zcu = pt.zcu;
31407 const dest_info = dest_ty.ptrInfo(mod);31410 const dest_info = dest_ty.ptrInfo(zcu);
31408 const inst_info = inst_ty.ptrInfo(mod);31411 const inst_info = inst_ty.ptrInfo(zcu);
31409 const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(mod) == .Array and (Type.fromInterned(inst_info.child).arrayLenIncludingSentinel(mod) == 0 or31412 const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(zcu) == .Array and (Type.fromInterned(inst_info.child).arrayLenIncludingSentinel(zcu) == 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))) or31413 (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
31411 (Type.fromInterned(inst_info.child).isTuple(mod) and Type.fromInterned(inst_info.child).structFieldCount(mod) == 0);31414 (Type.fromInterned(inst_info.child).isTuple(zcu) and Type.fromInterned(inst_info.child).structFieldCount(zcu) == 0);
3141231415
31413 const ok_cv_qualifiers =31416 const ok_cv_qualifiers =
31414 ((!inst_info.flags.is_const or dest_info.flags.is_const) or len0) and31417 ((!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...@@ -31436,12 +31439,12 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul
31436 const inst_align = if (inst_info.flags.alignment != .none)31439 const inst_align = if (inst_info.flags.alignment != .none)
31437 inst_info.flags.alignment31440 inst_info.flags.alignment
31438 else31441 else
31439 Type.fromInterned(inst_info.child).abiAlignment(pt);31442 Type.fromInterned(inst_info.child).abiAlignment(zcu);
3144031443
31441 const dest_align = if (dest_info.flags.alignment != .none)31444 const dest_align = if (dest_info.flags.alignment != .none)
31442 dest_info.flags.alignment31445 dest_info.flags.alignment
31443 else31446 else
31444 Type.fromInterned(dest_info.child).abiAlignment(pt);31447 Type.fromInterned(dest_info.child).abiAlignment(zcu);
3144531448
31446 if (dest_align.compare(.gt, inst_align)) {31449 if (dest_align.compare(.gt, inst_align)) {
31447 in_memory_result.* = .{ .ptr_alignment = .{31450 in_memory_result.* = .{ .ptr_alignment = .{
...@@ -31461,10 +31464,10 @@ fn coerceCompatiblePtrs(...@@ -31461,10 +31464,10 @@ fn coerceCompatiblePtrs(
31461 inst_src: LazySrcLoc,31464 inst_src: LazySrcLoc,
31462) !Air.Inst.Ref {31465) !Air.Inst.Ref {
31463 const pt = sema.pt;31466 const pt = sema.pt;
31464 const mod = pt.zcu;31467 const zcu = pt.zcu;
31465 const inst_ty = sema.typeOf(inst);31468 const inst_ty = sema.typeOf(inst);
31466 if (try sema.resolveValue(inst)) |val| {31469 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)) {
31468 return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});31471 return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(pt)});
31469 }31472 }
31470 // The comptime Value representation is compatible with both types.31473 // The comptime Value representation is compatible with both types.
...@@ -31473,17 +31476,17 @@ fn coerceCompatiblePtrs(...@@ -31473,17 +31476,17 @@ fn coerceCompatiblePtrs(
31473 );31476 );
31474 }31477 }
31475 try sema.requireRuntimeBlock(block, inst_src, null);31478 try sema.requireRuntimeBlock(block, inst_src, null);
31476 const inst_allows_zero = inst_ty.zigTypeTag(mod) != .Pointer or inst_ty.ptrAllowsZero(mod);31479 const inst_allows_zero = inst_ty.zigTypeTag(zcu) != .Pointer or inst_ty.ptrAllowsZero(zcu);
31477 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(mod) and31480 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero(zcu) and
31478 (try sema.typeHasRuntimeBits(dest_ty.elemType2(mod)) or dest_ty.elemType2(mod).zigTypeTag(mod) == .Fn))31481 (try dest_ty.elemType2(zcu).hasRuntimeBitsSema(pt) or dest_ty.elemType2(zcu).zigTypeTag(zcu) == .Fn))
31479 {31482 {
31480 const actual_ptr = if (inst_ty.isSlice(mod))31483 const actual_ptr = if (inst_ty.isSlice(zcu))
31481 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)31484 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
31482 else31485 else
31483 inst;31486 inst;
31484 const ptr_int = try block.addUnOp(.int_from_ptr, actual_ptr);31487 const ptr_int = try block.addUnOp(.int_from_ptr, actual_ptr);
31485 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);31488 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: {
31487 const len = try sema.analyzeSliceLen(block, inst_src, inst);31490 const len = try sema.analyzeSliceLen(block, inst_src, inst);
31488 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);31491 const len_zero = try block.addBinOp(.cmp_eq, len, .zero_usize);
31489 break :ok try block.addBinOp(.bool_or, len_zero, is_non_zero);31492 break :ok try block.addBinOp(.bool_or, len_zero, is_non_zero);
...@@ -31504,11 +31507,11 @@ fn coerceEnumToUnion(...@@ -31504,11 +31507,11 @@ fn coerceEnumToUnion(
31504 inst_src: LazySrcLoc,31507 inst_src: LazySrcLoc,
31505) !Air.Inst.Ref {31508) !Air.Inst.Ref {
31506 const pt = sema.pt;31509 const pt = sema.pt;
31507 const mod = pt.zcu;31510 const zcu = pt.zcu;
31508 const ip = &mod.intern_pool;31511 const ip = &zcu.intern_pool;
31509 const inst_ty = sema.typeOf(inst);31512 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 {
31512 const msg = msg: {31515 const msg = msg: {
31513 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{31516 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
31514 union_ty.fmt(pt), inst_ty.fmt(pt),31517 union_ty.fmt(pt), inst_ty.fmt(pt),
...@@ -31529,10 +31532,10 @@ fn coerceEnumToUnion(...@@ -31529,10 +31532,10 @@ fn coerceEnumToUnion(
31529 });31532 });
31530 };31533 };
3153131534
31532 const union_obj = mod.typeToUnion(union_ty).?;31535 const union_obj = zcu.typeToUnion(union_ty).?;
31533 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);31536 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
31534 try field_ty.resolveFields(pt);31537 try field_ty.resolveFields(pt);
31535 if (field_ty.zigTypeTag(mod) == .NoReturn) {31538 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
31536 const msg = msg: {31539 const msg = msg: {
31537 const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{});31540 const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{});
31538 errdefer msg.destroy(sema.gpa);31541 errdefer msg.destroy(sema.gpa);
...@@ -31569,7 +31572,7 @@ fn coerceEnumToUnion(...@@ -31569,7 +31572,7 @@ fn coerceEnumToUnion(
3156931572
31570 try sema.requireRuntimeBlock(block, inst_src, null);31573 try sema.requireRuntimeBlock(block, inst_src, null);
3157131574
31572 if (tag_ty.isNonexhaustiveEnum(mod)) {31575 if (tag_ty.isNonexhaustiveEnum(zcu)) {
31573 const msg = msg: {31576 const msg = msg: {
31574 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{31577 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
31575 union_ty.fmt(pt),31578 union_ty.fmt(pt),
...@@ -31581,13 +31584,13 @@ fn coerceEnumToUnion(...@@ -31581,13 +31584,13 @@ fn coerceEnumToUnion(
31581 return sema.failWithOwnedErrorMsg(block, msg);31584 return sema.failWithOwnedErrorMsg(block, msg);
31582 }31585 }
3158331586
31584 const union_obj = mod.typeToUnion(union_ty).?;31587 const union_obj = zcu.typeToUnion(union_ty).?;
31585 {31588 {
31586 var msg: ?*Module.ErrorMsg = null;31589 var msg: ?*Zcu.ErrorMsg = null;
31587 errdefer if (msg) |some| some.destroy(sema.gpa);31590 errdefer if (msg) |some| some.destroy(sema.gpa);
3158831591
31589 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {31592 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) {
31591 const err_msg = msg orelse try sema.errMsg(31594 const err_msg = msg orelse try sema.errMsg(
31592 inst_src,31595 inst_src,
31593 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",31596 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",
...@@ -31606,7 +31609,7 @@ fn coerceEnumToUnion(...@@ -31606,7 +31609,7 @@ fn coerceEnumToUnion(
31606 }31609 }
3160731610
31608 // If the union has all fields 0 bits, the union value is just the enum value.31611 // 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)) {
31610 return block.addBitCast(union_ty, enum_tag);31613 return block.addBitCast(union_ty, enum_tag);
31611 }31614 }
3161231615
...@@ -31621,7 +31624,7 @@ fn coerceEnumToUnion(...@@ -31621,7 +31624,7 @@ fn coerceEnumToUnion(
31621 for (0..union_obj.field_types.len) |field_index| {31624 for (0..union_obj.field_types.len) |field_index| {
31622 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];31625 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
31623 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);31626 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;
31625 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{31628 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
31626 field_name.fmt(ip),31629 field_name.fmt(ip),
31627 field_ty.fmt(pt),31630 field_ty.fmt(pt),
...@@ -31642,8 +31645,8 @@ fn coerceAnonStructToUnion(...@@ -31642,8 +31645,8 @@ fn coerceAnonStructToUnion(
31642 inst_src: LazySrcLoc,31645 inst_src: LazySrcLoc,
31643) !Air.Inst.Ref {31646) !Air.Inst.Ref {
31644 const pt = sema.pt;31647 const pt = sema.pt;
31645 const mod = pt.zcu;31648 const zcu = pt.zcu;
31646 const ip = &mod.intern_pool;31649 const ip = &zcu.intern_pool;
31647 const inst_ty = sema.typeOf(inst);31650 const inst_ty = sema.typeOf(inst);
31648 const field_info: union(enum) {31651 const field_info: union(enum) {
31649 name: InternPool.NullTerminatedString,31652 name: InternPool.NullTerminatedString,
...@@ -31701,8 +31704,8 @@ fn coerceAnonStructToUnionPtrs(...@@ -31701,8 +31704,8 @@ fn coerceAnonStructToUnionPtrs(
31701 anon_struct_src: LazySrcLoc,31704 anon_struct_src: LazySrcLoc,
31702) !Air.Inst.Ref {31705) !Air.Inst.Ref {
31703 const pt = sema.pt;31706 const pt = sema.pt;
31704 const mod = pt.zcu;31707 const zcu = pt.zcu;
31705 const union_ty = ptr_union_ty.childType(mod);31708 const union_ty = ptr_union_ty.childType(zcu);
31706 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);31709 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
31707 const union_inst = try sema.coerceAnonStructToUnion(block, union_ty, union_ty_src, anon_struct, anon_struct_src);31710 const union_inst = try sema.coerceAnonStructToUnion(block, union_ty, union_ty_src, anon_struct, anon_struct_src);
31708 return sema.analyzeRef(block, union_ty_src, union_inst);31711 return sema.analyzeRef(block, union_ty_src, union_inst);
...@@ -31717,8 +31720,8 @@ fn coerceAnonStructToStructPtrs(...@@ -31717,8 +31720,8 @@ fn coerceAnonStructToStructPtrs(
31717 anon_struct_src: LazySrcLoc,31720 anon_struct_src: LazySrcLoc,
31718) !Air.Inst.Ref {31721) !Air.Inst.Ref {
31719 const pt = sema.pt;31722 const pt = sema.pt;
31720 const mod = pt.zcu;31723 const zcu = pt.zcu;
31721 const struct_ty = ptr_struct_ty.childType(mod);31724 const struct_ty = ptr_struct_ty.childType(zcu);
31722 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);31725 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
31723 const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, anon_struct, anon_struct_src);31726 const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, anon_struct, anon_struct_src);
31724 return sema.analyzeRef(block, struct_ty_src, struct_inst);31727 return sema.analyzeRef(block, struct_ty_src, struct_inst);
...@@ -31734,9 +31737,9 @@ fn coerceArrayLike(...@@ -31734,9 +31737,9 @@ fn coerceArrayLike(
31734 inst_src: LazySrcLoc,31737 inst_src: LazySrcLoc,
31735) !Air.Inst.Ref {31738) !Air.Inst.Ref {
31736 const pt = sema.pt;31739 const pt = sema.pt;
31737 const mod = pt.zcu;31740 const zcu = pt.zcu;
31738 const inst_ty = sema.typeOf(inst);31741 const inst_ty = sema.typeOf(inst);
31739 const target = mod.getTarget();31742 const target = zcu.getTarget();
3174031743
31741 // try coercion of the whole array31744 // try coercion of the whole array
31742 const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src, null);31745 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(...@@ -31750,8 +31753,8 @@ fn coerceArrayLike(
31750 }31753 }
3175131754
31752 // otherwise, try element by element31755 // otherwise, try element by element
31753 const inst_len = inst_ty.arrayLen(mod);31756 const inst_len = inst_ty.arrayLen(zcu);
31754 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));31757 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(zcu));
31755 if (dest_len != inst_len) {31758 if (dest_len != inst_len) {
31756 const msg = msg: {31759 const msg = msg: {
31757 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{31760 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
...@@ -31765,14 +31768,14 @@ fn coerceArrayLike(...@@ -31765,14 +31768,14 @@ fn coerceArrayLike(
31765 return sema.failWithOwnedErrorMsg(block, msg);31768 return sema.failWithOwnedErrorMsg(block, msg);
31766 }31769 }
3176731770
31768 const dest_elem_ty = dest_ty.childType(mod);31771 const dest_elem_ty = dest_ty.childType(zcu);
31769 if (dest_ty.isVector(mod) and inst_ty.isVector(mod) and (try sema.resolveValue(inst)) == null) {31772 if (dest_ty.isVector(zcu) and inst_ty.isVector(zcu) and (try sema.resolveValue(inst)) == null) {
31770 const inst_elem_ty = inst_ty.childType(mod);31773 const inst_elem_ty = inst_ty.childType(zcu);
31771 switch (dest_elem_ty.zigTypeTag(mod)) {31774 switch (dest_elem_ty.zigTypeTag(zcu)) {
31772 .Int => if (inst_elem_ty.isInt(mod)) {31775 .Int => if (inst_elem_ty.isInt(zcu)) {
31773 // integer widening31776 // integer widening
31774 const dst_info = dest_elem_ty.intInfo(mod);31777 const dst_info = dest_elem_ty.intInfo(zcu);
31775 const src_info = inst_elem_ty.intInfo(mod);31778 const src_info = inst_elem_ty.intInfo(zcu);
31776 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or31779 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or
31777 // small enough unsigned ints can get casted to large enough signed ints31780 // small enough unsigned ints can get casted to large enough signed ints
31778 (dst_info.signedness == .signed and dst_info.bits > src_info.bits))31781 (dst_info.signedness == .signed and dst_info.bits > src_info.bits))
...@@ -31835,10 +31838,10 @@ fn coerceTupleToArray(...@@ -31835,10 +31838,10 @@ fn coerceTupleToArray(
31835 inst_src: LazySrcLoc,31838 inst_src: LazySrcLoc,
31836) !Air.Inst.Ref {31839) !Air.Inst.Ref {
31837 const pt = sema.pt;31840 const pt = sema.pt;
31838 const mod = pt.zcu;31841 const zcu = pt.zcu;
31839 const inst_ty = sema.typeOf(inst);31842 const inst_ty = sema.typeOf(inst);
31840 const inst_len = inst_ty.arrayLen(mod);31843 const inst_len = inst_ty.arrayLen(zcu);
31841 const dest_len = dest_ty.arrayLen(mod);31844 const dest_len = dest_ty.arrayLen(zcu);
3184231845
31843 if (dest_len != inst_len) {31846 if (dest_len != inst_len) {
31844 const msg = msg: {31847 const msg = msg: {
...@@ -31856,13 +31859,13 @@ fn coerceTupleToArray(...@@ -31856,13 +31859,13 @@ fn coerceTupleToArray(
31856 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len);31859 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len);
31857 const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems);31860 const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems);
31858 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);31861 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
31861 var runtime_src: ?LazySrcLoc = null;31864 var runtime_src: ?LazySrcLoc = null;
31862 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {31865 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
31863 const i: u32 = @intCast(i_usize);31866 const i: u32 = @intCast(i_usize);
31864 if (i_usize == inst_len) {31867 if (i_usize == inst_len) {
31865 const sentinel_val = dest_ty.sentinel(mod).?;31868 const sentinel_val = dest_ty.sentinel(zcu).?;
31866 val.* = sentinel_val.toIntern();31869 val.* = sentinel_val.toIntern();
31867 ref.* = Air.internedToRef(sentinel_val.toIntern());31870 ref.* = Air.internedToRef(sentinel_val.toIntern());
31868 break;31871 break;
...@@ -31901,12 +31904,12 @@ fn coerceTupleToSlicePtrs(...@@ -31901,12 +31904,12 @@ fn coerceTupleToSlicePtrs(
31901 tuple_src: LazySrcLoc,31904 tuple_src: LazySrcLoc,
31902) !Air.Inst.Ref {31905) !Air.Inst.Ref {
31903 const pt = sema.pt;31906 const pt = sema.pt;
31904 const mod = pt.zcu;31907 const zcu = pt.zcu;
31905 const tuple_ty = sema.typeOf(ptr_tuple).childType(mod);31908 const tuple_ty = sema.typeOf(ptr_tuple).childType(zcu);
31906 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);31909 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);
31908 const array_ty = try pt.arrayType(.{31911 const array_ty = try pt.arrayType(.{
31909 .len = tuple_ty.structFieldCount(mod),31912 .len = tuple_ty.structFieldCount(zcu),
31910 .sentinel = slice_info.sentinel,31913 .sentinel = slice_info.sentinel,
31911 .child = slice_info.child,31914 .child = slice_info.child,
31912 });31915 });
...@@ -31928,9 +31931,9 @@ fn coerceTupleToArrayPtrs(...@@ -31928,9 +31931,9 @@ fn coerceTupleToArrayPtrs(
31928 tuple_src: LazySrcLoc,31931 tuple_src: LazySrcLoc,
31929) !Air.Inst.Ref {31932) !Air.Inst.Ref {
31930 const pt = sema.pt;31933 const pt = sema.pt;
31931 const mod = pt.zcu;31934 const zcu = pt.zcu;
31932 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);31935 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);
31934 const array_ty = Type.fromInterned(ptr_info.child);31937 const array_ty = Type.fromInterned(ptr_info.child);
31935 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);31938 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
31936 if (ptr_info.flags.alignment != .none) {31939 if (ptr_info.flags.alignment != .none) {
...@@ -31950,16 +31953,16 @@ fn coerceTupleToStruct(...@@ -31950,16 +31953,16 @@ fn coerceTupleToStruct(
31950 inst_src: LazySrcLoc,31953 inst_src: LazySrcLoc,
31951) !Air.Inst.Ref {31954) !Air.Inst.Ref {
31952 const pt = sema.pt;31955 const pt = sema.pt;
31953 const mod = pt.zcu;31956 const zcu = pt.zcu;
31954 const ip = &mod.intern_pool;31957 const ip = &zcu.intern_pool;
31955 try struct_ty.resolveFields(pt);31958 try struct_ty.resolveFields(pt);
31956 try struct_ty.resolveStructFieldInits(pt);31959 try struct_ty.resolveStructFieldInits(pt);
3195731960
31958 if (struct_ty.isTupleOrAnonStruct(mod)) {31961 if (struct_ty.isTupleOrAnonStruct(zcu)) {
31959 return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src);31962 return sema.coerceTupleToTuple(block, struct_ty, inst, inst_src);
31960 }31963 }
3196131964
31962 const struct_type = mod.typeToStruct(struct_ty).?;31965 const struct_type = zcu.typeToStruct(struct_ty).?;
31963 const field_vals = try sema.arena.alloc(InternPool.Index, struct_type.field_types.len);31966 const field_vals = try sema.arena.alloc(InternPool.Index, struct_type.field_types.len);
31964 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);31967 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
31965 @memset(field_refs, .none);31968 @memset(field_refs, .none);
...@@ -31973,7 +31976,7 @@ fn coerceTupleToStruct(...@@ -31973,7 +31976,7 @@ fn coerceTupleToStruct(
31973 };31976 };
31974 for (0..field_count) |tuple_field_index| {31977 for (0..field_count) |tuple_field_index| {
31975 const field_src = inst_src; // TODO better source location31978 const field_src = inst_src; // TODO better source location
31976 const field_name = inst_ty.structFieldName(tuple_field_index, mod).unwrap() orelse31979 const field_name = inst_ty.structFieldName(tuple_field_index, zcu).unwrap() orelse
31977 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{tuple_field_index}, .no_embedded_nulls);31980 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{tuple_field_index}, .no_embedded_nulls);
3197831981
31979 const struct_field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);31982 const struct_field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);
...@@ -32003,7 +32006,7 @@ fn coerceTupleToStruct(...@@ -32003,7 +32006,7 @@ fn coerceTupleToStruct(
32003 }32006 }
3200432007
32005 // Populate default field values and report errors for missing fields.32008 // Populate default field values and report errors for missing fields.
32006 var root_msg: ?*Module.ErrorMsg = null;32009 var root_msg: ?*Zcu.ErrorMsg = null;
32007 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);32010 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
3200832011
32009 for (field_refs, 0..) |*field_ref, i| {32012 for (field_refs, 0..) |*field_ref, i| {
...@@ -32058,8 +32061,8 @@ fn coerceTupleToTuple(...@@ -32058,8 +32061,8 @@ fn coerceTupleToTuple(
32058 inst_src: LazySrcLoc,32061 inst_src: LazySrcLoc,
32059) !Air.Inst.Ref {32062) !Air.Inst.Ref {
32060 const pt = sema.pt;32063 const pt = sema.pt;
32061 const mod = pt.zcu;32064 const zcu = pt.zcu;
32062 const ip = &mod.intern_pool;32065 const ip = &zcu.intern_pool;
32063 const dest_field_count = switch (ip.indexToKey(tuple_ty.toIntern())) {32066 const dest_field_count = switch (ip.indexToKey(tuple_ty.toIntern())) {
32064 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,32067 .anon_struct_type => |anon_struct_type| anon_struct_type.types.len,
32065 .struct_type => ip.loadStructType(tuple_ty.toIntern()).field_types.len,32068 .struct_type => ip.loadStructType(tuple_ty.toIntern()).field_types.len,
...@@ -32081,7 +32084,7 @@ fn coerceTupleToTuple(...@@ -32081,7 +32084,7 @@ fn coerceTupleToTuple(
32081 for (0..dest_field_count) |field_index_usize| {32084 for (0..dest_field_count) |field_index_usize| {
32082 const field_i: u32 = @intCast(field_index_usize);32085 const field_i: u32 = @intCast(field_index_usize);
32083 const field_src = inst_src; // TODO better source location32086 const field_src = inst_src; // TODO better source location
32084 const field_name = inst_ty.structFieldName(field_index_usize, mod).unwrap() orelse32087 const field_name = inst_ty.structFieldName(field_index_usize, zcu).unwrap() orelse
32085 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_index_usize}, .no_embedded_nulls);32088 try ip.getOrPutStringFmt(sema.gpa, pt.tid, "{d}", .{field_index_usize}, .no_embedded_nulls);
3208632089
32087 if (field_name.eqlSlice("len", ip))32090 if (field_name.eqlSlice("len", ip))
...@@ -32124,7 +32127,7 @@ fn coerceTupleToTuple(...@@ -32124,7 +32127,7 @@ fn coerceTupleToTuple(
32124 }32127 }
3212532128
32126 // Populate default field values and report errors for missing fields.32129 // Populate default field values and report errors for missing fields.
32127 var root_msg: ?*Module.ErrorMsg = null;32130 var root_msg: ?*Zcu.ErrorMsg = null;
32128 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);32131 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
3212932132
32130 for (field_refs, 0..) |*field_ref, i_usize| {32133 for (field_refs, 0..) |*field_ref, i_usize| {
...@@ -32139,7 +32142,7 @@ fn coerceTupleToTuple(...@@ -32139,7 +32142,7 @@ fn coerceTupleToTuple(
3213932142
32140 const field_src = inst_src; // TODO better source location32143 const field_src = inst_src; // TODO better source location
32141 if (default_val == .none) {32144 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 {
32143 const template = "missing tuple field: {d}";32146 const template = "missing tuple field: {d}";
32144 if (root_msg) |msg| {32147 if (root_msg) |msg| {
32145 try sema.errNote(field_src, msg, template, .{i});32148 try sema.errNote(field_src, msg, template, .{i});
...@@ -32308,7 +32311,7 @@ fn maybeQueueFuncBodyAnalysis(sema: *Sema, src: LazySrcLoc, nav_index: InternPoo...@@ -32308,7 +32311,7 @@ fn maybeQueueFuncBodyAnalysis(sema: *Sema, src: LazySrcLoc, nav_index: InternPoo
32308 const ip = &zcu.intern_pool;32311 const ip = &zcu.intern_pool;
32309 const nav_val = zcu.navValue(nav_index);32312 const nav_val = zcu.navValue(nav_index);
32310 if (!ip.isFuncBody(nav_val.toIntern())) return;32313 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;
32312 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .func = nav_val.toIntern() }));32315 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .func = nav_val.toIntern() }));
32313 try zcu.ensureFuncBodyAnalysisQueued(nav_val.toIntern());32316 try zcu.ensureFuncBodyAnalysisQueued(nav_val.toIntern());
32314}32317}
...@@ -32320,11 +32323,11 @@ fn analyzeRef(...@@ -32320,11 +32323,11 @@ fn analyzeRef(
32320 operand: Air.Inst.Ref,32323 operand: Air.Inst.Ref,
32321) CompileError!Air.Inst.Ref {32324) CompileError!Air.Inst.Ref {
32322 const pt = sema.pt;32325 const pt = sema.pt;
32323 const mod = pt.zcu;32326 const zcu = pt.zcu;
32324 const operand_ty = sema.typeOf(operand);32327 const operand_ty = sema.typeOf(operand);
3232532328
32326 if (try sema.resolveValue(operand)) |val| {32329 if (try sema.resolveValue(operand)) |val| {
32327 switch (mod.intern_pool.indexToKey(val.toIntern())) {32330 switch (zcu.intern_pool.indexToKey(val.toIntern())) {
32328 .@"extern" => |e| return sema.analyzeNavRef(src, e.owner_nav),32331 .@"extern" => |e| return sema.analyzeNavRef(src, e.owner_nav),
32329 .func => |f| return sema.analyzeNavRef(src, f.owner_nav),32332 .func => |f| return sema.analyzeNavRef(src, f.owner_nav),
32330 else => return uavRef(sema, val.toIntern()),32333 else => return uavRef(sema, val.toIntern()),
...@@ -32332,7 +32335,7 @@ fn analyzeRef(...@@ -32332,7 +32335,7 @@ fn analyzeRef(
32332 }32335 }
3233332336
32334 try sema.requireRuntimeBlock(block, src, null);32337 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);
32336 const ptr_type = try pt.ptrTypeSema(.{32339 const ptr_type = try pt.ptrTypeSema(.{
32337 .child = operand_ty.toIntern(),32340 .child = operand_ty.toIntern(),
32338 .flags = .{32341 .flags = .{
...@@ -32359,13 +32362,13 @@ fn analyzeLoad(...@@ -32359,13 +32362,13 @@ fn analyzeLoad(
32359 ptr_src: LazySrcLoc,32362 ptr_src: LazySrcLoc,
32360) CompileError!Air.Inst.Ref {32363) CompileError!Air.Inst.Ref {
32361 const pt = sema.pt;32364 const pt = sema.pt;
32362 const mod = pt.zcu;32365 const zcu = pt.zcu;
32363 const ptr_ty = sema.typeOf(ptr);32366 const ptr_ty = sema.typeOf(ptr);
32364 const elem_ty = switch (ptr_ty.zigTypeTag(mod)) {32367 const elem_ty = switch (ptr_ty.zigTypeTag(zcu)) {
32365 .Pointer => ptr_ty.childType(mod),32368 .Pointer => ptr_ty.childType(zcu),
32366 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(pt)}),32369 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(pt)}),
32367 };32370 };
32368 if (elem_ty.zigTypeTag(mod) == .Opaque) {32371 if (elem_ty.zigTypeTag(zcu) == .Opaque) {
32369 return sema.fail(block, ptr_src, "cannot load opaque type '{}'", .{elem_ty.fmt(pt)});32372 return sema.fail(block, ptr_src, "cannot load opaque type '{}'", .{elem_ty.fmt(pt)});
32370 }32373 }
3237132374
...@@ -32379,7 +32382,7 @@ fn analyzeLoad(...@@ -32379,7 +32382,7 @@ fn analyzeLoad(
32379 }32382 }
32380 }32383 }
3238132384
32382 if (ptr_ty.ptrInfo(mod).flags.vector_index == .runtime) {32385 if (ptr_ty.ptrInfo(zcu).flags.vector_index == .runtime) {
32383 const ptr_inst = ptr.toIndex().?;32386 const ptr_inst = ptr.toIndex().?;
32384 const air_tags = sema.air_instructions.items(.tag);32387 const air_tags = sema.air_instructions.items(.tag);
32385 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {32388 if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
...@@ -32403,11 +32406,11 @@ fn analyzeSlicePtr(...@@ -32403,11 +32406,11 @@ fn analyzeSlicePtr(
32403 slice_ty: Type,32406 slice_ty: Type,
32404) CompileError!Air.Inst.Ref {32407) CompileError!Air.Inst.Ref {
32405 const pt = sema.pt;32408 const pt = sema.pt;
32406 const mod = pt.zcu;32409 const zcu = pt.zcu;
32407 const result_ty = slice_ty.slicePtrFieldType(mod);32410 const result_ty = slice_ty.slicePtrFieldType(zcu);
32408 if (try sema.resolveValue(slice)) |val| {32411 if (try sema.resolveValue(slice)) |val| {
32409 if (val.isUndef(mod)) return pt.undefRef(result_ty);32412 if (val.isUndef(zcu)) return pt.undefRef(result_ty);
32410 return Air.internedToRef(val.slicePtr(mod).toIntern());32413 return Air.internedToRef(val.slicePtr(zcu).toIntern());
32411 }32414 }
32412 try sema.requireRuntimeBlock(block, slice_src, null);32415 try sema.requireRuntimeBlock(block, slice_src, null);
32413 return block.addTyOp(.slice_ptr, result_ty, slice);32416 return block.addTyOp(.slice_ptr, result_ty, slice);
...@@ -32421,13 +32424,13 @@ fn analyzeOptionalSlicePtr(...@@ -32421,13 +32424,13 @@ fn analyzeOptionalSlicePtr(
32421 opt_slice_ty: Type,32424 opt_slice_ty: Type,
32422) CompileError!Air.Inst.Ref {32425) CompileError!Air.Inst.Ref {
32423 const pt = sema.pt;32426 const pt = sema.pt;
32424 const mod = pt.zcu;32427 const zcu = pt.zcu;
32425 const result_ty = opt_slice_ty.optionalChild(mod).slicePtrFieldType(mod);32428 const result_ty = opt_slice_ty.optionalChild(zcu).slicePtrFieldType(zcu);
3242632429
32427 if (try sema.resolveValue(opt_slice)) |opt_val| {32430 if (try sema.resolveValue(opt_slice)) |opt_val| {
32428 if (opt_val.isUndef(mod)) return pt.undefRef(result_ty);32431 if (opt_val.isUndef(zcu)) return pt.undefRef(result_ty);
32429 const slice_ptr: InternPool.Index = if (opt_val.optionalValue(mod)) |val|32432 const slice_ptr: InternPool.Index = if (opt_val.optionalValue(zcu)) |val|
32430 val.slicePtr(mod).toIntern()32433 val.slicePtr(zcu).toIntern()
32431 else32434 else
32432 .null_value;32435 .null_value;
3243332436
...@@ -32447,9 +32450,9 @@ fn analyzeSliceLen(...@@ -32447,9 +32450,9 @@ fn analyzeSliceLen(
32447 slice_inst: Air.Inst.Ref,32450 slice_inst: Air.Inst.Ref,
32448) CompileError!Air.Inst.Ref {32451) CompileError!Air.Inst.Ref {
32449 const pt = sema.pt;32452 const pt = sema.pt;
32450 const mod = pt.zcu;32453 const zcu = pt.zcu;
32451 if (try sema.resolveValue(slice_inst)) |slice_val| {32454 if (try sema.resolveValue(slice_inst)) |slice_val| {
32452 if (slice_val.isUndef(mod)) {32455 if (slice_val.isUndef(zcu)) {
32453 return pt.undefRef(Type.usize);32456 return pt.undefRef(Type.usize);
32454 }32457 }
32455 return pt.intRef(Type.usize, try slice_val.sliceLen(pt));32458 return pt.intRef(Type.usize, try slice_val.sliceLen(pt));
...@@ -32466,23 +32469,23 @@ fn analyzeIsNull(...@@ -32466,23 +32469,23 @@ fn analyzeIsNull(
32466 invert_logic: bool,32469 invert_logic: bool,
32467) CompileError!Air.Inst.Ref {32470) CompileError!Air.Inst.Ref {
32468 const pt = sema.pt;32471 const pt = sema.pt;
32469 const mod = pt.zcu;32472 const zcu = pt.zcu;
32470 const result_ty = Type.bool;32473 const result_ty = Type.bool;
32471 if (try sema.resolveValue(operand)) |opt_val| {32474 if (try sema.resolveValue(operand)) |opt_val| {
32472 if (opt_val.isUndef(mod)) {32475 if (opt_val.isUndef(zcu)) {
32473 return pt.undefRef(result_ty);32476 return pt.undefRef(result_ty);
32474 }32477 }
32475 const is_null = opt_val.isNull(mod);32478 const is_null = opt_val.isNull(zcu);
32476 const bool_value = if (invert_logic) !is_null else is_null;32479 const bool_value = if (invert_logic) !is_null else is_null;
32477 return if (bool_value) .bool_true else .bool_false;32480 return if (bool_value) .bool_true else .bool_false;
32478 }32481 }
3247932482
32480 const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false;32483 const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false;
32481 const operand_ty = sema.typeOf(operand);32484 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) {
32483 return inverted_non_null_res;32486 return inverted_non_null_res;
32484 }32487 }
32485 if (operand_ty.zigTypeTag(mod) != .Optional and !operand_ty.isPtrLikeOptional(mod)) {32488 if (operand_ty.zigTypeTag(zcu) != .Optional and !operand_ty.isPtrLikeOptional(zcu)) {
32486 return inverted_non_null_res;32489 return inverted_non_null_res;
32487 }32490 }
32488 try sema.requireRuntimeBlock(block, src, null);32491 try sema.requireRuntimeBlock(block, src, null);
...@@ -32497,12 +32500,12 @@ fn analyzePtrIsNonErrComptimeOnly(...@@ -32497,12 +32500,12 @@ fn analyzePtrIsNonErrComptimeOnly(
32497 operand: Air.Inst.Ref,32500 operand: Air.Inst.Ref,
32498) CompileError!Air.Inst.Ref {32501) CompileError!Air.Inst.Ref {
32499 const pt = sema.pt;32502 const pt = sema.pt;
32500 const mod = pt.zcu;32503 const zcu = pt.zcu;
32501 const ptr_ty = sema.typeOf(operand);32504 const ptr_ty = sema.typeOf(operand);
32502 assert(ptr_ty.zigTypeTag(mod) == .Pointer);32505 assert(ptr_ty.zigTypeTag(zcu) == .Pointer);
32503 const child_ty = ptr_ty.childType(mod);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);
32506 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return .bool_true;32509 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return .bool_true;
32507 if (child_tag == .ErrorSet) return .bool_false;32510 if (child_tag == .ErrorSet) return .bool_false;
32508 assert(child_tag == .ErrorUnion);32511 assert(child_tag == .ErrorUnion);
...@@ -32520,16 +32523,16 @@ fn analyzeIsNonErrComptimeOnly(...@@ -32520,16 +32523,16 @@ fn analyzeIsNonErrComptimeOnly(
32520 operand: Air.Inst.Ref,32523 operand: Air.Inst.Ref,
32521) CompileError!Air.Inst.Ref {32524) CompileError!Air.Inst.Ref {
32522 const pt = sema.pt;32525 const pt = sema.pt;
32523 const mod = pt.zcu;32526 const zcu = pt.zcu;
32524 const ip = &mod.intern_pool;32527 const ip = &zcu.intern_pool;
32525 const operand_ty = sema.typeOf(operand);32528 const operand_ty = sema.typeOf(operand);
32526 const ot = operand_ty.zigTypeTag(mod);32529 const ot = operand_ty.zigTypeTag(zcu);
32527 if (ot != .ErrorSet and ot != .ErrorUnion) return .bool_true;32530 if (ot != .ErrorSet and ot != .ErrorUnion) return .bool_true;
32528 if (ot == .ErrorSet) return .bool_false;32531 if (ot == .ErrorSet) return .bool_false;
32529 assert(ot == .ErrorUnion);32532 assert(ot == .ErrorUnion);
3253032533
32531 const payload_ty = operand_ty.errorUnionPayload(mod);32534 const payload_ty = operand_ty.errorUnionPayload(zcu);
32532 if (payload_ty.zigTypeTag(mod) == .NoReturn) {32535 if (payload_ty.zigTypeTag(zcu) == .NoReturn) {
32533 return .bool_false;32536 return .bool_false;
32534 }32537 }
3253532538
...@@ -32588,7 +32591,7 @@ fn analyzeIsNonErrComptimeOnly(...@@ -32588,7 +32591,7 @@ fn analyzeIsNonErrComptimeOnly(
32588 // If the error set is empty, we must return a comptime true or false.32591 // If the error set is empty, we must return a comptime true or false.
32589 // However we want to avoid unnecessarily resolving an inferred error set32592 // However we want to avoid unnecessarily resolving an inferred error set
32590 // in case it is already non-empty.32593 // in case it is already non-empty.
32591 try mod.maybeUnresolveIes(func_index);32594 try zcu.maybeUnresolveIes(func_index);
32592 switch (ip.funcIesResolvedUnordered(func_index)) {32595 switch (ip.funcIesResolvedUnordered(func_index)) {
32593 .anyerror_type => break :blk,32596 .anyerror_type => break :blk,
32594 .none => {},32597 .none => {},
...@@ -32624,10 +32627,10 @@ fn analyzeIsNonErrComptimeOnly(...@@ -32624,10 +32627,10 @@ fn analyzeIsNonErrComptimeOnly(
32624 }32627 }
3262532628
32626 if (maybe_operand_val) |err_union| {32629 if (maybe_operand_val) |err_union| {
32627 if (err_union.isUndef(mod)) {32630 if (err_union.isUndef(zcu)) {
32628 return pt.undefRef(Type.bool);32631 return pt.undefRef(Type.bool);
32629 }32632 }
32630 if (err_union.getErrorName(mod) == .none) {32633 if (err_union.getErrorName(zcu) == .none) {
32631 return .bool_true;32634 return .bool_true;
32632 } else {32635 } else {
32633 return .bool_false;32636 return .bool_false;
...@@ -32681,12 +32684,12 @@ fn analyzeSlice(...@@ -32681,12 +32684,12 @@ fn analyzeSlice(
32681 by_length: bool,32684 by_length: bool,
32682) CompileError!Air.Inst.Ref {32685) CompileError!Air.Inst.Ref {
32683 const pt = sema.pt;32686 const pt = sema.pt;
32684 const mod = pt.zcu;32687 const zcu = pt.zcu;
32685 // Slice expressions can operate on a variable whose type is an array. This requires32688 // Slice expressions can operate on a variable whose type is an array. This requires
32686 // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer.32689 // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer.
32687 const ptr_ptr_ty = sema.typeOf(ptr_ptr);32690 const ptr_ptr_ty = sema.typeOf(ptr_ptr);
32688 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(mod)) {32691 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(zcu)) {
32689 .Pointer => ptr_ptr_ty.childType(mod),32692 .Pointer => ptr_ptr_ty.childType(zcu),
32690 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ptr_ty.fmt(pt)}),32693 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ptr_ty.fmt(pt)}),
32691 };32694 };
3269232695
...@@ -32695,20 +32698,20 @@ fn analyzeSlice(...@@ -32695,20 +32698,20 @@ fn analyzeSlice(
32695 var ptr_or_slice = ptr_ptr;32698 var ptr_or_slice = ptr_ptr;
32696 var elem_ty: Type = undefined;32699 var elem_ty: Type = undefined;
32697 var ptr_sentinel: ?Value = null;32700 var ptr_sentinel: ?Value = null;
32698 switch (ptr_ptr_child_ty.zigTypeTag(mod)) {32701 switch (ptr_ptr_child_ty.zigTypeTag(zcu)) {
32699 .Array => {32702 .Array => {
32700 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);32703 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
32701 elem_ty = ptr_ptr_child_ty.childType(mod);32704 elem_ty = ptr_ptr_child_ty.childType(zcu);
32702 },32705 },
32703 .Pointer => switch (ptr_ptr_child_ty.ptrSize(mod)) {32706 .Pointer => switch (ptr_ptr_child_ty.ptrSize(zcu)) {
32704 .One => {32707 .One => {
32705 const double_child_ty = ptr_ptr_child_ty.childType(mod);32708 const double_child_ty = ptr_ptr_child_ty.childType(zcu);
32706 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);32709 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
32707 if (double_child_ty.zigTypeTag(mod) == .Array) {32710 if (double_child_ty.zigTypeTag(zcu) == .Array) {
32708 ptr_sentinel = double_child_ty.sentinel(mod);32711 ptr_sentinel = double_child_ty.sentinel(zcu);
32709 slice_ty = ptr_ptr_child_ty;32712 slice_ty = ptr_ptr_child_ty;
32710 array_ty = double_child_ty;32713 array_ty = double_child_ty;
32711 elem_ty = double_child_ty.childType(mod);32714 elem_ty = double_child_ty.childType(zcu);
32712 } else {32715 } else {
32713 const bounds_error_message = "slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1]";32716 const bounds_error_message = "slice of single-item pointer must have comptime-known bounds [0..0], [0..1], or [1..1]";
32714 if (uncasted_end_opt == .none) {32717 if (uncasted_end_opt == .none) {
...@@ -32777,7 +32780,7 @@ fn analyzeSlice(...@@ -32777,7 +32780,7 @@ fn analyzeSlice(
32777 .len = 1,32780 .len = 1,
32778 .child = double_child_ty.toIntern(),32781 .child = double_child_ty.toIntern(),
32779 });32782 });
32780 const ptr_info = ptr_ptr_child_ty.ptrInfo(mod);32783 const ptr_info = ptr_ptr_child_ty.ptrInfo(zcu);
32781 slice_ty = try pt.ptrType(.{32784 slice_ty = try pt.ptrType(.{
32782 .child = array_ty.toIntern(),32785 .child = array_ty.toIntern(),
32783 .flags = .{32786 .flags = .{
...@@ -32792,35 +32795,35 @@ fn analyzeSlice(...@@ -32792,35 +32795,35 @@ fn analyzeSlice(
32792 }32795 }
32793 },32796 },
32794 .Many, .C => {32797 .Many, .C => {
32795 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);32798 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
32796 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);32799 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
32797 slice_ty = ptr_ptr_child_ty;32800 slice_ty = ptr_ptr_child_ty;
32798 array_ty = ptr_ptr_child_ty;32801 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) {
32802 if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| {32805 if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| {
32803 if (ptr_val.isNull(mod)) {32806 if (ptr_val.isNull(zcu)) {
32804 return sema.fail(block, src, "slice of null pointer", .{});32807 return sema.fail(block, src, "slice of null pointer", .{});
32805 }32808 }
32806 }32809 }
32807 }32810 }
32808 },32811 },
32809 .Slice => {32812 .Slice => {
32810 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);32813 ptr_sentinel = ptr_ptr_child_ty.sentinel(zcu);
32811 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);32814 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
32812 slice_ty = ptr_ptr_child_ty;32815 slice_ty = ptr_ptr_child_ty;
32813 array_ty = ptr_ptr_child_ty;32816 array_ty = ptr_ptr_child_ty;
32814 elem_ty = ptr_ptr_child_ty.childType(mod);32817 elem_ty = ptr_ptr_child_ty.childType(zcu);
32815 },32818 },
32816 },32819 },
32817 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(pt)}),32820 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(pt)}),
32818 }32821 }
3281932822
32820 const ptr = if (slice_ty.isSlice(mod))32823 const ptr = if (slice_ty.isSlice(zcu))
32821 try sema.analyzeSlicePtr(block, ptr_src, ptr_or_slice, slice_ty)32824 try sema.analyzeSlicePtr(block, ptr_src, ptr_or_slice, slice_ty)
32822 else if (array_ty.zigTypeTag(mod) == .Array) ptr: {32825 else if (array_ty.zigTypeTag(zcu) == .Array) ptr: {
32823 var manyptr_ty_key = mod.intern_pool.indexToKey(slice_ty.toIntern()).ptr_type;32826 var manyptr_ty_key = zcu.intern_pool.indexToKey(slice_ty.toIntern()).ptr_type;
32824 assert(manyptr_ty_key.child == array_ty.toIntern());32827 assert(manyptr_ty_key.child == array_ty.toIntern());
32825 assert(manyptr_ty_key.flags.size == .One);32828 assert(manyptr_ty_key.flags.size == .One);
32826 manyptr_ty_key.child = elem_ty.toIntern();32829 manyptr_ty_key.child = elem_ty.toIntern();
...@@ -32838,8 +32841,8 @@ fn analyzeSlice(...@@ -32838,8 +32841,8 @@ fn analyzeSlice(
32838 // we might learn of the length because it is a comptime-known slice value.32841 // we might learn of the length because it is a comptime-known slice value.
32839 var end_is_len = uncasted_end_opt == .none;32842 var end_is_len = uncasted_end_opt == .none;
32840 const end = e: {32843 const end = e: {
32841 if (array_ty.zigTypeTag(mod) == .Array) {32844 if (array_ty.zigTypeTag(zcu) == .Array) {
32842 const len_val = try pt.intValue(Type.usize, array_ty.arrayLen(mod));32845 const len_val = try pt.intValue(Type.usize, array_ty.arrayLen(zcu));
3284332846
32844 if (!end_is_len) {32847 if (!end_is_len) {
32845 const end = if (by_length) end: {32848 const end = if (by_length) end: {
...@@ -32850,10 +32853,10 @@ fn analyzeSlice(...@@ -32850,10 +32853,10 @@ fn analyzeSlice(
32850 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {32853 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
32851 const len_s_val = try pt.intValue(32854 const len_s_val = try pt.intValue(
32852 Type.usize,32855 Type.usize,
32853 array_ty.arrayLenIncludingSentinel(mod),32856 array_ty.arrayLenIncludingSentinel(zcu),
32854 );32857 );
32855 if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) {32858 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)
32857 " +1 (sentinel)"32860 " +1 (sentinel)"
32858 else32861 else
32859 "";32862 "";
...@@ -32873,7 +32876,7 @@ fn analyzeSlice(...@@ -32873,7 +32876,7 @@ fn analyzeSlice(
32873 // end_is_len is only true if we are NOT using the sentinel32876 // end_is_len is only true if we are NOT using the sentinel
32874 // length. For sentinel-length, we don't want the type to32877 // length. For sentinel-length, we don't want the type to
32875 // contain the sentinel.32878 // contain the sentinel.
32876 if (end_val.eql(len_val, Type.usize, mod)) {32879 if (end_val.eql(len_val, Type.usize, zcu)) {
32877 end_is_len = true;32880 end_is_len = true;
32878 }32881 }
32879 }32882 }
...@@ -32881,7 +32884,7 @@ fn analyzeSlice(...@@ -32881,7 +32884,7 @@ fn analyzeSlice(
32881 }32884 }
3288232885
32883 break :e Air.internedToRef(len_val.toIntern());32886 break :e Air.internedToRef(len_val.toIntern());
32884 } else if (slice_ty.isSlice(mod)) {32887 } else if (slice_ty.isSlice(zcu)) {
32885 if (!end_is_len) {32888 if (!end_is_len) {
32886 const end = if (by_length) end: {32889 const end = if (by_length) end: {
32887 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);32890 const len = try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
...@@ -32890,10 +32893,10 @@ fn analyzeSlice(...@@ -32890,10 +32893,10 @@ fn analyzeSlice(
32890 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);32893 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32891 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {32894 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
32892 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {32895 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {
32893 if (slice_val.isUndef(mod)) {32896 if (slice_val.isUndef(zcu)) {
32894 return sema.fail(block, src, "slice of undefined", .{});32897 return sema.fail(block, src, "slice of undefined", .{});
32895 }32898 }
32896 const has_sentinel = slice_ty.sentinel(mod) != null;32899 const has_sentinel = slice_ty.sentinel(zcu) != null;
32897 const slice_len = try slice_val.sliceLen(pt);32900 const slice_len = try slice_val.sliceLen(pt);
32898 const len_plus_sent = slice_len + @intFromBool(has_sentinel);32901 const len_plus_sent = slice_len + @intFromBool(has_sentinel);
32899 const slice_len_val_with_sentinel = try pt.intValue(Type.usize, len_plus_sent);32902 const slice_len_val_with_sentinel = try pt.intValue(Type.usize, len_plus_sent);
...@@ -32919,7 +32922,7 @@ fn analyzeSlice(...@@ -32919,7 +32922,7 @@ fn analyzeSlice(
32919 // is only true if it equals the length WITHOUT the32922 // is only true if it equals the length WITHOUT the
32920 // sentinel, so we don't add a sentinel type.32923 // sentinel, so we don't add a sentinel type.
32921 const slice_len_val = try pt.intValue(Type.usize, slice_len);32924 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)) {
32923 end_is_len = true;32926 end_is_len = true;
32924 }32927 }
32925 }32928 }
...@@ -32976,8 +32979,8 @@ fn analyzeSlice(...@@ -32976,8 +32979,8 @@ fn analyzeSlice(
32976 checked_start_lte_end = true;32979 checked_start_lte_end = true;
32977 if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: {32980 if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: {
32978 const expected_sentinel = sentinel orelse break :sentinel_check;32981 const expected_sentinel = sentinel orelse break :sentinel_check;
32979 const start_int = start_val.getUnsignedInt(pt).?;32982 const start_int = start_val.toUnsignedInt(zcu);
32980 const end_int = end_val.getUnsignedInt(pt).?;32983 const end_int = end_val.toUnsignedInt(zcu);
32981 const sentinel_index = try sema.usizeCast(block, end_src, end_int - start_int);32984 const sentinel_index = try sema.usizeCast(block, end_src, end_int - start_int);
3298232985
32983 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);32986 const many_ptr_ty = try pt.manyConstPtrType(elem_ty);
...@@ -33001,7 +33004,7 @@ fn analyzeSlice(...@@ -33001,7 +33004,7 @@ fn analyzeSlice(
33001 ),33004 ),
33002 };33005 };
3300333006
33004 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {33007 if (!actual_sentinel.eql(expected_sentinel, elem_ty, zcu)) {
33005 const msg = msg: {33008 const msg = msg: {
33006 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});33009 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
33007 errdefer msg.destroy(sema.gpa);33010 errdefer msg.destroy(sema.gpa);
...@@ -33041,8 +33044,8 @@ fn analyzeSlice(...@@ -33041,8 +33044,8 @@ fn analyzeSlice(
33041 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);33044 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);
33042 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);33045 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);
3304333046
33044 const new_ptr_ty_info = new_ptr_ty.ptrInfo(mod);33047 const new_ptr_ty_info = new_ptr_ty.ptrInfo(zcu);
33045 const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(mod) != .C;33048 const new_allowzero = new_ptr_ty_info.flags.is_allowzero and sema.typeOf(ptr).ptrSize(zcu) != .C;
3304633049
33047 if (opt_new_len_val) |new_len_val| {33050 if (opt_new_len_val) |new_len_val| {
33048 const new_len_int = try new_len_val.toUnsignedIntSema(pt);33051 const new_len_int = try new_len_val.toUnsignedIntSema(pt);
...@@ -33067,17 +33070,17 @@ fn analyzeSlice(...@@ -33067,17 +33070,17 @@ fn analyzeSlice(
33067 const result = try block.addBitCast(return_ty, new_ptr);33070 const result = try block.addBitCast(return_ty, new_ptr);
33068 if (block.wantSafety()) {33071 if (block.wantSafety()) {
33069 // requirement: slicing C ptr is non-null33072 // requirement: slicing C ptr is non-null
33070 if (ptr_ptr_child_ty.isCPtr(mod)) {33073 if (ptr_ptr_child_ty.isCPtr(zcu)) {
33071 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);33074 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);
33072 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);33075 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);
33073 }33076 }
3307433077
33075 bounds_check: {33078 bounds_check: {
33076 const actual_len = if (array_ty.zigTypeTag(mod) == .Array)33079 const actual_len = if (array_ty.zigTypeTag(zcu) == .Array)
33077 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(mod))33080 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
33078 else if (slice_ty.isSlice(mod)) l: {33081 else if (slice_ty.isSlice(zcu)) l: {
33079 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);33082 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)
33081 slice_len_inst33084 slice_len_inst
33082 else33085 else
33083 try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);33086 try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
...@@ -33097,7 +33100,7 @@ fn analyzeSlice(...@@ -33097,7 +33100,7 @@ fn analyzeSlice(
33097 return result;33100 return result;
33098 };33101 };
3309933102
33100 if (!new_ptr_val.isUndef(mod)) {33103 if (!new_ptr_val.isUndef(zcu)) {
33101 return Air.internedToRef((try pt.getCoerced(new_ptr_val, return_ty)).toIntern());33104 return Air.internedToRef((try pt.getCoerced(new_ptr_val, return_ty)).toIntern());
33102 }33105 }
3310333106
...@@ -33125,15 +33128,15 @@ fn analyzeSlice(...@@ -33125,15 +33128,15 @@ fn analyzeSlice(
33125 try sema.requireRuntimeBlock(block, src, runtime_src.?);33128 try sema.requireRuntimeBlock(block, src, runtime_src.?);
33126 if (block.wantSafety()) {33129 if (block.wantSafety()) {
33127 // requirement: slicing C ptr is non-null33130 // requirement: slicing C ptr is non-null
33128 if (ptr_ptr_child_ty.isCPtr(mod)) {33131 if (ptr_ptr_child_ty.isCPtr(zcu)) {
33129 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);33132 const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true);
33130 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);33133 try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null);
33131 }33134 }
3313233135
33133 // requirement: end <= len33136 // requirement: end <= len
33134 const opt_len_inst = if (array_ty.zigTypeTag(mod) == .Array)33137 const opt_len_inst = if (array_ty.zigTypeTag(zcu) == .Array)
33135 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(mod))33138 try pt.intRef(Type.usize, array_ty.arrayLenIncludingSentinel(zcu))
33136 else if (slice_ty.isSlice(mod)) blk: {33139 else if (slice_ty.isSlice(zcu)) blk: {
33137 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {33140 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
33138 // we don't need to add one for sentinels because the33141 // we don't need to add one for sentinels because the
33139 // underlying value data includes the sentinel33142 // underlying value data includes the sentinel
...@@ -33141,7 +33144,7 @@ fn analyzeSlice(...@@ -33141,7 +33144,7 @@ fn analyzeSlice(
33141 }33144 }
3314233145
33143 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);33146 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
33146 // we have to add one because slice lengths don't include the sentinel33149 // we have to add one because slice lengths don't include the sentinel
33147 break :blk try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);33150 break :blk try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
...@@ -33186,16 +33189,16 @@ fn cmpNumeric(...@@ -33186,16 +33189,16 @@ fn cmpNumeric(
33186 rhs_src: LazySrcLoc,33189 rhs_src: LazySrcLoc,
33187) CompileError!Air.Inst.Ref {33190) CompileError!Air.Inst.Ref {
33188 const pt = sema.pt;33191 const pt = sema.pt;
33189 const mod = pt.zcu;33192 const zcu = pt.zcu;
33190 const lhs_ty = sema.typeOf(uncasted_lhs);33193 const lhs_ty = sema.typeOf(uncasted_lhs);
33191 const rhs_ty = sema.typeOf(uncasted_rhs);33194 const rhs_ty = sema.typeOf(uncasted_rhs);
3319233195
33193 assert(lhs_ty.isNumeric(mod));33196 assert(lhs_ty.isNumeric(zcu));
33194 assert(rhs_ty.isNumeric(mod));33197 assert(rhs_ty.isNumeric(zcu));
3319533198
33196 const lhs_ty_tag = lhs_ty.zigTypeTag(mod);33199 const lhs_ty_tag = lhs_ty.zigTypeTag(zcu);
33197 const rhs_ty_tag = rhs_ty.zigTypeTag(mod);33200 const rhs_ty_tag = rhs_ty.zigTypeTag(zcu);
33198 const target = mod.getTarget();33201 const target = zcu.getTarget();
3319933202
33200 // One exception to heterogeneous comparison: comptime_float needs to33203 // One exception to heterogeneous comparison: comptime_float needs to
33201 // coerce to fixed-width float.33204 // coerce to fixed-width float.
...@@ -33214,28 +33217,28 @@ fn cmpNumeric(...@@ -33214,28 +33217,28 @@ fn cmpNumeric(
33214 if (try sema.resolveValue(lhs)) |lhs_val| {33217 if (try sema.resolveValue(lhs)) |lhs_val| {
33215 if (try sema.resolveValue(rhs)) |rhs_val| {33218 if (try sema.resolveValue(rhs)) |rhs_val| {
33216 // Compare ints: const vs. undefined (or vice versa)33219 // 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)) {
33218 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {33221 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
33219 return if (res) .bool_true else .bool_false;33222 return if (res) .bool_true else .bool_false;
33220 }33223 }
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)) {
33222 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {33225 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
33223 return if (res) .bool_true else .bool_false;33226 return if (res) .bool_true else .bool_false;
33224 }33227 }
33225 }33228 }
3322633229
33227 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {33230 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
33228 return pt.undefRef(Type.bool);33231 return pt.undefRef(Type.bool);
33229 }33232 }
33230 if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) {33233 if (lhs_val.isNan(zcu) or rhs_val.isNan(zcu)) {
33231 return if (op == std.math.CompareOperator.neq) .bool_true else .bool_false;33234 return if (op == std.math.CompareOperator.neq) .bool_true else .bool_false;
33232 }33235 }
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))
33234 .bool_true33237 .bool_true
33235 else33238 else
33236 .bool_false;33239 .bool_false;
33237 } else {33240 } 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)) {
33239 // Compare ints: const vs. var33242 // Compare ints: const vs. var
33240 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {33243 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
33241 return if (res) .bool_true else .bool_false;33244 return if (res) .bool_true else .bool_false;
...@@ -33245,7 +33248,7 @@ fn cmpNumeric(...@@ -33245,7 +33248,7 @@ fn cmpNumeric(
33245 }33248 }
33246 } else {33249 } else {
33247 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {33250 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)) {
33249 // Compare ints: var vs. const33252 // Compare ints: var vs. const
33250 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {33253 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
33251 return if (res) .bool_true else .bool_false;33254 return if (res) .bool_true else .bool_false;
...@@ -33301,31 +33304,31 @@ fn cmpNumeric(...@@ -33301,31 +33304,31 @@ fn cmpNumeric(
33301 const lhs_is_signed = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val|33304 const lhs_is_signed = if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val|
33302 !(try lhs_val.compareAllWithZeroSema(.gte, pt))33305 !(try lhs_val.compareAllWithZeroSema(.gte, pt))
33303 else33306 else
33304 (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt(mod));33307 (lhs_ty.isRuntimeFloat() or lhs_ty.isSignedInt(zcu));
33305 const rhs_is_signed = if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val|33308 const rhs_is_signed = if (try sema.resolveDefinedValue(block, rhs_src, rhs)) |rhs_val|
33306 !(try rhs_val.compareAllWithZeroSema(.gte, pt))33309 !(try rhs_val.compareAllWithZeroSema(.gte, pt))
33307 else33310 else
33308 (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt(mod));33311 (rhs_ty.isRuntimeFloat() or rhs_ty.isSignedInt(zcu));
33309 const dest_int_is_signed = lhs_is_signed or rhs_is_signed;33312 const dest_int_is_signed = lhs_is_signed or rhs_is_signed;
3331033313
33311 var dest_float_type: ?Type = null;33314 var dest_float_type: ?Type = null;
3331233315
33313 var lhs_bits: usize = undefined;33316 var lhs_bits: usize = undefined;
33314 if (try sema.resolveValueResolveLazy(lhs)) |lhs_val| {33317 if (try sema.resolveValueResolveLazy(lhs)) |lhs_val| {
33315 if (lhs_val.isUndef(mod))33318 if (lhs_val.isUndef(zcu))
33316 return pt.undefRef(Type.bool);33319 return pt.undefRef(Type.bool);
33317 if (lhs_val.isNan(mod)) switch (op) {33320 if (lhs_val.isNan(zcu)) switch (op) {
33318 .neq => return .bool_true,33321 .neq => return .bool_true,
33319 else => return .bool_false,33322 else => return .bool_false,
33320 };33323 };
33321 if (lhs_val.isInf(mod)) switch (op) {33324 if (lhs_val.isInf(zcu)) switch (op) {
33322 .neq => return .bool_true,33325 .neq => return .bool_true,
33323 .eq => return .bool_false,33326 .eq => return .bool_false,
33324 .gt, .gte => return if (lhs_val.isNegativeInf(mod)) .bool_false else .bool_true,33327 .gt, .gte => return if (lhs_val.isNegativeInf(zcu)) .bool_false else .bool_true,
33325 .lt, .lte => return if (lhs_val.isNegativeInf(mod)) .bool_true else .bool_false,33328 .lt, .lte => return if (lhs_val.isNegativeInf(zcu)) .bool_true else .bool_false,
33326 };33329 };
33327 if (!rhs_is_signed) {33330 if (!rhs_is_signed) {
33328 switch (lhs_val.orderAgainstZero(pt)) {33331 switch (lhs_val.orderAgainstZero(zcu)) {
33329 .gt => {},33332 .gt => {},
33330 .eq => switch (op) { // LHS = 0, RHS is unsigned33333 .eq => switch (op) { // LHS = 0, RHS is unsigned
33331 .lte => return .bool_true,33334 .lte => return .bool_true,
...@@ -33339,7 +33342,7 @@ fn cmpNumeric(...@@ -33339,7 +33342,7 @@ fn cmpNumeric(
33339 }33342 }
33340 }33343 }
33341 if (lhs_is_float) {33344 if (lhs_is_float) {
33342 if (lhs_val.floatHasFraction(mod)) {33345 if (lhs_val.floatHasFraction(zcu)) {
33343 switch (op) {33346 switch (op) {
33344 .eq => return .bool_false,33347 .eq => return .bool_false,
33345 .neq => return .bool_true,33348 .neq => return .bool_true,
...@@ -33347,9 +33350,9 @@ fn cmpNumeric(...@@ -33347,9 +33350,9 @@ fn cmpNumeric(
33347 }33350 }
33348 }33351 }
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));
33351 defer bigint.deinit();33354 defer bigint.deinit();
33352 if (lhs_val.floatHasFraction(mod)) {33355 if (lhs_val.floatHasFraction(zcu)) {
33353 if (lhs_is_signed) {33356 if (lhs_is_signed) {
33354 try bigint.addScalar(&bigint, -1);33357 try bigint.addScalar(&bigint, -1);
33355 } else {33358 } else {
...@@ -33358,32 +33361,32 @@ fn cmpNumeric(...@@ -33358,32 +33361,32 @@ fn cmpNumeric(
33358 }33361 }
33359 lhs_bits = bigint.toConst().bitCountTwosComp();33362 lhs_bits = bigint.toConst().bitCountTwosComp();
33360 } else {33363 } else {
33361 lhs_bits = lhs_val.intBitCountTwosComp(pt);33364 lhs_bits = lhs_val.intBitCountTwosComp(zcu);
33362 }33365 }
33363 lhs_bits += @intFromBool(!lhs_is_signed and dest_int_is_signed);33366 lhs_bits += @intFromBool(!lhs_is_signed and dest_int_is_signed);
33364 } else if (lhs_is_float) {33367 } else if (lhs_is_float) {
33365 dest_float_type = lhs_ty;33368 dest_float_type = lhs_ty;
33366 } else {33369 } else {
33367 const int_info = lhs_ty.intInfo(mod);33370 const int_info = lhs_ty.intInfo(zcu);
33368 lhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);33371 lhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);
33369 }33372 }
3337033373
33371 var rhs_bits: usize = undefined;33374 var rhs_bits: usize = undefined;
33372 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {33375 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
33373 if (rhs_val.isUndef(mod))33376 if (rhs_val.isUndef(zcu))
33374 return pt.undefRef(Type.bool);33377 return pt.undefRef(Type.bool);
33375 if (rhs_val.isNan(mod)) switch (op) {33378 if (rhs_val.isNan(zcu)) switch (op) {
33376 .neq => return .bool_true,33379 .neq => return .bool_true,
33377 else => return .bool_false,33380 else => return .bool_false,
33378 };33381 };
33379 if (rhs_val.isInf(mod)) switch (op) {33382 if (rhs_val.isInf(zcu)) switch (op) {
33380 .neq => return .bool_true,33383 .neq => return .bool_true,
33381 .eq => return .bool_false,33384 .eq => return .bool_false,
33382 .gt, .gte => return if (rhs_val.isNegativeInf(mod)) .bool_true else .bool_false,33385 .gt, .gte => return if (rhs_val.isNegativeInf(zcu)) .bool_true else .bool_false,
33383 .lt, .lte => return if (rhs_val.isNegativeInf(mod)) .bool_false else .bool_true,33386 .lt, .lte => return if (rhs_val.isNegativeInf(zcu)) .bool_false else .bool_true,
33384 };33387 };
33385 if (!lhs_is_signed) {33388 if (!lhs_is_signed) {
33386 switch (rhs_val.orderAgainstZero(pt)) {33389 switch (rhs_val.orderAgainstZero(zcu)) {
33387 .gt => {},33390 .gt => {},
33388 .eq => switch (op) { // RHS = 0, LHS is unsigned33391 .eq => switch (op) { // RHS = 0, LHS is unsigned
33389 .gte => return .bool_true,33392 .gte => return .bool_true,
...@@ -33397,7 +33400,7 @@ fn cmpNumeric(...@@ -33397,7 +33400,7 @@ fn cmpNumeric(
33397 }33400 }
33398 }33401 }
33399 if (rhs_is_float) {33402 if (rhs_is_float) {
33400 if (rhs_val.floatHasFraction(mod)) {33403 if (rhs_val.floatHasFraction(zcu)) {
33401 switch (op) {33404 switch (op) {
33402 .eq => return .bool_false,33405 .eq => return .bool_false,
33403 .neq => return .bool_true,33406 .neq => return .bool_true,
...@@ -33405,9 +33408,9 @@ fn cmpNumeric(...@@ -33405,9 +33408,9 @@ fn cmpNumeric(
33405 }33408 }
33406 }33409 }
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));
33409 defer bigint.deinit();33412 defer bigint.deinit();
33410 if (rhs_val.floatHasFraction(mod)) {33413 if (rhs_val.floatHasFraction(zcu)) {
33411 if (rhs_is_signed) {33414 if (rhs_is_signed) {
33412 try bigint.addScalar(&bigint, -1);33415 try bigint.addScalar(&bigint, -1);
33413 } else {33416 } else {
...@@ -33416,13 +33419,13 @@ fn cmpNumeric(...@@ -33416,13 +33419,13 @@ fn cmpNumeric(
33416 }33419 }
33417 rhs_bits = bigint.toConst().bitCountTwosComp();33420 rhs_bits = bigint.toConst().bitCountTwosComp();
33418 } else {33421 } else {
33419 rhs_bits = rhs_val.intBitCountTwosComp(pt);33422 rhs_bits = rhs_val.intBitCountTwosComp(zcu);
33420 }33423 }
33421 rhs_bits += @intFromBool(!rhs_is_signed and dest_int_is_signed);33424 rhs_bits += @intFromBool(!rhs_is_signed and dest_int_is_signed);
33422 } else if (rhs_is_float) {33425 } else if (rhs_is_float) {
33423 dest_float_type = rhs_ty;33426 dest_float_type = rhs_ty;
33424 } else {33427 } else {
33425 const int_info = rhs_ty.intInfo(mod);33428 const int_info = rhs_ty.intInfo(zcu);
33426 rhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);33429 rhs_bits = int_info.bits + @intFromBool(int_info.signedness == .unsigned and dest_int_is_signed);
33427 }33430 }
3342833431
...@@ -33450,9 +33453,9 @@ fn compareIntsOnlyPossibleResult(...@@ -33450,9 +33453,9 @@ fn compareIntsOnlyPossibleResult(
33450 rhs_ty: Type,33453 rhs_ty: Type,
33451) Allocator.Error!?bool {33454) Allocator.Error!?bool {
33452 const pt = sema.pt;33455 const pt = sema.pt;
33453 const mod = pt.zcu;33456 const zcu = pt.zcu;
33454 const rhs_info = rhs_ty.intInfo(mod);33457 const rhs_info = rhs_ty.intInfo(zcu);
33455 const vs_zero = lhs_val.orderAgainstZeroAdvanced(pt, .sema) catch unreachable;33458 const vs_zero = lhs_val.orderAgainstZeroSema(pt) catch unreachable;
33456 const is_zero = vs_zero == .eq;33459 const is_zero = vs_zero == .eq;
33457 const is_negative = vs_zero == .lt;33460 const is_negative = vs_zero == .lt;
33458 const is_positive = vs_zero == .gt;33461 const is_positive = vs_zero == .gt;
...@@ -33484,7 +33487,7 @@ fn compareIntsOnlyPossibleResult(...@@ -33484,7 +33487,7 @@ fn compareIntsOnlyPossibleResult(
33484 };33487 };
3348533488
33486 const sign_adj = @intFromBool(!is_negative and rhs_info.signedness == .signed);33489 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
33489 // No sized type can have more than 65535 bits.33492 // No sized type can have more than 65535 bits.
33490 // The RHS type operand is either a runtime value or sized (but undefined) constant.33493 // The RHS type operand is either a runtime value or sized (but undefined) constant.
...@@ -33515,7 +33518,7 @@ fn compareIntsOnlyPossibleResult(...@@ -33515,7 +33518,7 @@ fn compareIntsOnlyPossibleResult(
33515 if (is_negative) .signed else .unsigned,33518 if (is_negative) .signed else .unsigned,
33516 @intCast(req_bits),33519 @intCast(req_bits),
33517 );33520 );
33518 const pop_count = lhs_val.popCount(ty, pt);33521 const pop_count = lhs_val.popCount(ty, zcu);
3351933522
33520 if (is_negative) {33523 if (is_negative) {
33521 break :edge .{ pop_count == 1, false };33524 break :edge .{ pop_count == 1, false };
...@@ -33546,11 +33549,11 @@ fn cmpVector(...@@ -33546,11 +33549,11 @@ fn cmpVector(
33546 rhs_src: LazySrcLoc,33549 rhs_src: LazySrcLoc,
33547) CompileError!Air.Inst.Ref {33550) CompileError!Air.Inst.Ref {
33548 const pt = sema.pt;33551 const pt = sema.pt;
33549 const mod = pt.zcu;33552 const zcu = pt.zcu;
33550 const lhs_ty = sema.typeOf(lhs);33553 const lhs_ty = sema.typeOf(lhs);
33551 const rhs_ty = sema.typeOf(rhs);33554 const rhs_ty = sema.typeOf(rhs);
33552 assert(lhs_ty.zigTypeTag(mod) == .Vector);33555 assert(lhs_ty.zigTypeTag(zcu) == .Vector);
33553 assert(rhs_ty.zigTypeTag(mod) == .Vector);33556 assert(rhs_ty.zigTypeTag(zcu) == .Vector);
33554 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);33557 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
3355533558
33556 const resolved_ty = try sema.resolvePeerTypes(block, src, &.{ lhs, rhs }, .{ .override = &.{ lhs_src, rhs_src } });33559 const resolved_ty = try sema.resolvePeerTypes(block, src, &.{ lhs, rhs }, .{ .override = &.{ lhs_src, rhs_src } });
...@@ -33558,14 +33561,14 @@ fn cmpVector(...@@ -33558,14 +33561,14 @@ fn cmpVector(
33558 const casted_rhs = try sema.coerce(block, resolved_ty, rhs, rhs_src);33561 const casted_rhs = try sema.coerce(block, resolved_ty, rhs, rhs_src);
3355933562
33560 const result_ty = try pt.vectorType(.{33563 const result_ty = try pt.vectorType(.{
33561 .len = lhs_ty.vectorLen(mod),33564 .len = lhs_ty.vectorLen(zcu),
33562 .child = .bool_type,33565 .child = .bool_type,
33563 });33566 });
3356433567
33565 const runtime_src: LazySrcLoc = src: {33568 const runtime_src: LazySrcLoc = src: {
33566 if (try sema.resolveValue(casted_lhs)) |lhs_val| {33569 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
33567 if (try sema.resolveValue(casted_rhs)) |rhs_val| {33570 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)) {
33569 return pt.undefRef(result_ty);33572 return pt.undefRef(result_ty);
33570 }33573 }
33571 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty);33574 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_ty);
...@@ -33608,8 +33611,8 @@ fn wrapErrorUnionPayload(...@@ -33608,8 +33611,8 @@ fn wrapErrorUnionPayload(
33608 inst_src: LazySrcLoc,33611 inst_src: LazySrcLoc,
33609) !Air.Inst.Ref {33612) !Air.Inst.Ref {
33610 const pt = sema.pt;33613 const pt = sema.pt;
33611 const mod = pt.zcu;33614 const zcu = pt.zcu;
33612 const dest_payload_ty = dest_ty.errorUnionPayload(mod);33615 const dest_payload_ty = dest_ty.errorUnionPayload(zcu);
33613 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });33616 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
33614 if (try sema.resolveValue(coerced)) |val| {33617 if (try sema.resolveValue(coerced)) |val| {
33615 return Air.internedToRef((try pt.intern(.{ .error_union = .{33618 return Air.internedToRef((try pt.intern(.{ .error_union = .{
...@@ -33629,12 +33632,12 @@ fn wrapErrorUnionSet(...@@ -33629,12 +33632,12 @@ fn wrapErrorUnionSet(
33629 inst_src: LazySrcLoc,33632 inst_src: LazySrcLoc,
33630) !Air.Inst.Ref {33633) !Air.Inst.Ref {
33631 const pt = sema.pt;33634 const pt = sema.pt;
33632 const mod = pt.zcu;33635 const zcu = pt.zcu;
33633 const ip = &mod.intern_pool;33636 const ip = &zcu.intern_pool;
33634 const inst_ty = sema.typeOf(inst);33637 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);
33636 if (try sema.resolveValue(inst)) |val| {33639 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;
33638 switch (dest_err_set_ty.toIntern()) {33641 switch (dest_err_set_ty.toIntern()) {
33639 .anyerror_type => {},33642 .anyerror_type => {},
33640 .adhoc_inferred_error_set_type => ok: {33643 .adhoc_inferred_error_set_type => ok: {
...@@ -33658,7 +33661,7 @@ fn wrapErrorUnionSet(...@@ -33658,7 +33661,7 @@ fn wrapErrorUnionSet(
33658 .inferred_error_set_type => |func_index| ok: {33661 .inferred_error_set_type => |func_index| ok: {
33659 // We carefully do this in an order that avoids unnecessarily33662 // We carefully do this in an order that avoids unnecessarily
33660 // resolving the destination error set type.33663 // resolving the destination error set type.
33661 try mod.maybeUnresolveIes(func_index);33664 try zcu.maybeUnresolveIes(func_index);
33662 switch (ip.funcIesResolvedUnordered(func_index)) {33665 switch (ip.funcIesResolvedUnordered(func_index)) {
33663 .anyerror_type => break :ok,33666 .anyerror_type => break :ok,
33664 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {33667 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
...@@ -33693,13 +33696,13 @@ fn unionToTag(...@@ -33693,13 +33696,13 @@ fn unionToTag(
33693 un_src: LazySrcLoc,33696 un_src: LazySrcLoc,
33694) !Air.Inst.Ref {33697) !Air.Inst.Ref {
33695 const pt = sema.pt;33698 const pt = sema.pt;
33696 const mod = pt.zcu;33699 const zcu = pt.zcu;
33697 if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| {33700 if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| {
33698 return Air.internedToRef(opv.toIntern());33701 return Air.internedToRef(opv.toIntern());
33699 }33702 }
33700 if (try sema.resolveValue(un)) |un_val| {33703 if (try sema.resolveValue(un)) |un_val| {
33701 const tag_val = un_val.unionTag(mod).?;33704 const tag_val = un_val.unionTag(zcu).?;
33702 if (tag_val.isUndef(mod))33705 if (tag_val.isUndef(zcu))
33703 return try pt.undefRef(enum_ty);33706 return try pt.undefRef(enum_ty);
33704 return Air.internedToRef(tag_val.toIntern());33707 return Air.internedToRef(tag_val.toIntern());
33705 }33708 }
...@@ -33861,8 +33864,8 @@ const PeerResolveStrategy = enum {...@@ -33861,8 +33864,8 @@ const PeerResolveStrategy = enum {
33861 return strat;33864 return strat;
33862 }33865 }
3386333866
33864 fn select(ty: Type, mod: *Module) PeerResolveStrategy {33867 fn select(ty: Type, zcu: *Zcu) PeerResolveStrategy {
33865 return switch (ty.zigTypeTag(mod)) {33868 return switch (ty.zigTypeTag(zcu)) {
33866 .Type, .Void, .Bool, .Opaque, .Frame, .AnyFrame => .exact,33869 .Type, .Void, .Bool, .Opaque, .Frame, .AnyFrame => .exact,
33867 .NoReturn, .Undefined => .unknown,33870 .NoReturn, .Undefined => .unknown,
33868 .Null => .nullable,33871 .Null => .nullable,
...@@ -33870,14 +33873,14 @@ const PeerResolveStrategy = enum {...@@ -33870,14 +33873,14 @@ const PeerResolveStrategy = enum {
33870 .Int => .fixed_int,33873 .Int => .fixed_int,
33871 .ComptimeFloat => .comptime_float,33874 .ComptimeFloat => .comptime_float,
33872 .Float => .fixed_float,33875 .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,
33874 .Array => .array,33877 .Array => .array,
33875 .Vector => .vector,33878 .Vector => .vector,
33876 .Optional => .optional,33879 .Optional => .optional,
33877 .ErrorSet => .error_set,33880 .ErrorSet => .error_set,
33878 .ErrorUnion => .error_union,33881 .ErrorUnion => .error_union,
33879 .EnumLiteral, .Enum, .Union => .enum_or_union,33882 .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,
33881 .Fn => .func,33884 .Fn => .func,
33882 };33885 };
33883 }33886 }
...@@ -33933,10 +33936,10 @@ const PeerResolveResult = union(enum) {...@@ -33933,10 +33936,10 @@ const PeerResolveResult = union(enum) {
33933 src: LazySrcLoc,33936 src: LazySrcLoc,
33934 instructions: []const Air.Inst.Ref,33937 instructions: []const Air.Inst.Ref,
33935 candidate_srcs: PeerTypeCandidateSrc,33938 candidate_srcs: PeerTypeCandidateSrc,
33936 ) !*Module.ErrorMsg {33939 ) !*Zcu.ErrorMsg {
33937 const pt = sema.pt;33940 const pt = sema.pt;
3393833941
33939 var opt_msg: ?*Module.ErrorMsg = null;33942 var opt_msg: ?*Zcu.ErrorMsg = null;
33940 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);33943 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
3394133944
33942 // If we mention fields we'll want to include field types, so put peer types in a buffer33945 // If we mention fields we'll want to include field types, so put peer types in a buffer
...@@ -34053,14 +34056,14 @@ fn resolvePeerTypesInner(...@@ -34053,14 +34056,14 @@ fn resolvePeerTypesInner(
34053 peer_vals: []?Value,34056 peer_vals: []?Value,
34054) !PeerResolveResult {34057) !PeerResolveResult {
34055 const pt = sema.pt;34058 const pt = sema.pt;
34056 const mod = pt.zcu;34059 const zcu = pt.zcu;
34057 const ip = &mod.intern_pool;34060 const ip = &zcu.intern_pool;
3405834061
34059 var strat_reason: usize = 0;34062 var strat_reason: usize = 0;
34060 var s: PeerResolveStrategy = .unknown;34063 var s: PeerResolveStrategy = .unknown;
34061 for (peer_tys, 0..) |opt_ty, i| {34064 for (peer_tys, 0..) |opt_ty, i| {
34062 const ty = opt_ty orelse continue;34065 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);
34064 }34067 }
3406534068
34066 if (s == .unknown) {34069 if (s == .unknown) {
...@@ -34070,14 +34073,14 @@ fn resolvePeerTypesInner(...@@ -34070,14 +34073,14 @@ fn resolvePeerTypesInner(
34070 // There was something other than noreturn and undefined, so we can ignore those peers34073 // There was something other than noreturn and undefined, so we can ignore those peers
34071 for (peer_tys) |*ty_ptr| {34074 for (peer_tys) |*ty_ptr| {
34072 const ty = ty_ptr.* orelse continue;34075 const ty = ty_ptr.* orelse continue;
34073 switch (ty.zigTypeTag(mod)) {34076 switch (ty.zigTypeTag(zcu)) {
34074 .NoReturn, .Undefined => ty_ptr.* = null,34077 .NoReturn, .Undefined => ty_ptr.* = null,
34075 else => {},34078 else => {},
34076 }34079 }
34077 }34080 }
34078 }34081 }
3407934082
34080 const target = mod.getTarget();34083 const target = zcu.getTarget();
3408134084
34082 switch (s) {34085 switch (s) {
34083 .unknown => unreachable,34086 .unknown => unreachable,
...@@ -34086,7 +34089,7 @@ fn resolvePeerTypesInner(...@@ -34086,7 +34089,7 @@ fn resolvePeerTypesInner(
34086 var final_set: ?Type = null;34089 var final_set: ?Type = null;
34087 for (peer_tys, 0..) |opt_ty, i| {34090 for (peer_tys, 0..) |opt_ty, i| {
34088 const ty = opt_ty orelse continue;34091 const ty = opt_ty orelse continue;
34089 if (ty.zigTypeTag(mod) != .ErrorSet) return .{ .conflict = .{34092 if (ty.zigTypeTag(zcu) != .ErrorSet) return .{ .conflict = .{
34090 .peer_idx_a = strat_reason,34093 .peer_idx_a = strat_reason,
34091 .peer_idx_b = i,34094 .peer_idx_b = i,
34092 } };34095 } };
...@@ -34103,15 +34106,15 @@ fn resolvePeerTypesInner(...@@ -34103,15 +34106,15 @@ fn resolvePeerTypesInner(
34103 var final_set: ?Type = null;34106 var final_set: ?Type = null;
34104 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {34107 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {
34105 const ty = ty_ptr.* orelse continue;34108 const ty = ty_ptr.* orelse continue;
34106 const set_ty = switch (ty.zigTypeTag(mod)) {34109 const set_ty = switch (ty.zigTypeTag(zcu)) {
34107 .ErrorSet => blk: {34110 .ErrorSet => blk: {
34108 ty_ptr.* = null; // no payload to decide on34111 ty_ptr.* = null; // no payload to decide on
34109 val_ptr.* = null;34112 val_ptr.* = null;
34110 break :blk ty;34113 break :blk ty;
34111 },34114 },
34112 .ErrorUnion => blk: {34115 .ErrorUnion => blk: {
34113 const set_ty = ty.errorUnionSet(mod);34116 const set_ty = ty.errorUnionSet(zcu);
34114 ty_ptr.* = ty.errorUnionPayload(mod);34117 ty_ptr.* = ty.errorUnionPayload(zcu);
34115 if (val_ptr.*) |eu_val| switch (ip.indexToKey(eu_val.toIntern())) {34118 if (val_ptr.*) |eu_val| switch (ip.indexToKey(eu_val.toIntern())) {
34116 .error_union => |eu| switch (eu.val) {34119 .error_union => |eu| switch (eu.val) {
34117 .payload => |payload_ip| val_ptr.* = Value.fromInterned(payload_ip),34120 .payload => |payload_ip| val_ptr.* = Value.fromInterned(payload_ip),
...@@ -34146,7 +34149,7 @@ fn resolvePeerTypesInner(...@@ -34146,7 +34149,7 @@ fn resolvePeerTypesInner(
34146 .nullable => {34149 .nullable => {
34147 for (peer_tys, 0..) |opt_ty, i| {34150 for (peer_tys, 0..) |opt_ty, i| {
34148 const ty = opt_ty orelse continue;34151 const ty = opt_ty orelse continue;
34149 if (!ty.eql(Type.null, mod)) return .{ .conflict = .{34152 if (!ty.eql(Type.null, zcu)) return .{ .conflict = .{
34150 .peer_idx_a = strat_reason,34153 .peer_idx_a = strat_reason,
34151 .peer_idx_b = i,34154 .peer_idx_b = i,
34152 } };34155 } };
...@@ -34157,14 +34160,14 @@ fn resolvePeerTypesInner(...@@ -34157,14 +34160,14 @@ fn resolvePeerTypesInner(
34157 .optional => {34160 .optional => {
34158 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {34161 for (peer_tys, peer_vals) |*ty_ptr, *val_ptr| {
34159 const ty = ty_ptr.* orelse continue;34162 const ty = ty_ptr.* orelse continue;
34160 switch (ty.zigTypeTag(mod)) {34163 switch (ty.zigTypeTag(zcu)) {
34161 .Null => {34164 .Null => {
34162 ty_ptr.* = null;34165 ty_ptr.* = null;
34163 val_ptr.* = null;34166 val_ptr.* = null;
34164 },34167 },
34165 .Optional => {34168 .Optional => {
34166 ty_ptr.* = ty.optionalChild(mod);34169 ty_ptr.* = ty.optionalChild(zcu);
34167 if (val_ptr.*) |opt_val| val_ptr.* = if (!opt_val.isUndef(mod)) opt_val.optionalValue(mod) else null;34170 if (val_ptr.*) |opt_val| val_ptr.* = if (!opt_val.isUndef(zcu)) opt_val.optionalValue(zcu) else null;
34168 },34171 },
34169 else => {},34172 else => {},
34170 }34173 }
...@@ -34195,7 +34198,7 @@ fn resolvePeerTypesInner(...@@ -34195,7 +34198,7 @@ fn resolvePeerTypesInner(
34195 for (peer_tys, 0..) |*ty_ptr, i| {34198 for (peer_tys, 0..) |*ty_ptr, i| {
34196 const ty = ty_ptr.* orelse continue;34199 const ty = ty_ptr.* orelse continue;
3419734200
34198 if (!ty.isArrayOrVector(mod)) {34201 if (!ty.isArrayOrVector(zcu)) {
34199 // We allow tuples of the correct length. We won't validate their elem type, since the elements can be coerced.34202 // We allow tuples of the correct length. We won't validate their elem type, since the elements can be coerced.
34200 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{34203 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{
34201 .peer_idx_a = strat_reason,34204 .peer_idx_a = strat_reason,
...@@ -34220,29 +34223,29 @@ fn resolvePeerTypesInner(...@@ -34220,29 +34223,29 @@ fn resolvePeerTypesInner(
34220 const first_arr_idx = opt_first_arr_idx orelse {34223 const first_arr_idx = opt_first_arr_idx orelse {
34221 if (opt_first_idx == null) {34224 if (opt_first_idx == null) {
34222 opt_first_idx = i;34225 opt_first_idx = i;
34223 len = ty.arrayLen(mod);34226 len = ty.arrayLen(zcu);
34224 sentinel = ty.sentinel(mod);34227 sentinel = ty.sentinel(zcu);
34225 }34228 }
34226 opt_first_arr_idx = i;34229 opt_first_arr_idx = i;
34227 elem_ty = ty.childType(mod);34230 elem_ty = ty.childType(zcu);
34228 continue;34231 continue;
34229 };34232 };
3423034233
34231 if (ty.arrayLen(mod) != len) return .{ .conflict = .{34234 if (ty.arrayLen(zcu) != len) return .{ .conflict = .{
34232 .peer_idx_a = first_arr_idx,34235 .peer_idx_a = first_arr_idx,
34233 .peer_idx_b = i,34236 .peer_idx_b = i,
34234 } };34237 } };
3423534238
34236 const peer_elem_ty = ty.childType(mod);34239 const peer_elem_ty = ty.childType(zcu);
34237 if (!peer_elem_ty.eql(elem_ty, mod)) coerce: {34240 if (!peer_elem_ty.eql(elem_ty, zcu)) coerce: {
34238 const peer_elem_coerces_to_elem =34241 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);
34240 if (peer_elem_coerces_to_elem == .ok) {34243 if (peer_elem_coerces_to_elem == .ok) {
34241 break :coerce;34244 break :coerce;
34242 }34245 }
3424334246
34244 const elem_coerces_to_peer_elem =34247 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);
34246 if (elem_coerces_to_peer_elem == .ok) {34249 if (elem_coerces_to_peer_elem == .ok) {
34247 elem_ty = peer_elem_ty;34250 elem_ty = peer_elem_ty;
34248 break :coerce;34251 break :coerce;
...@@ -34255,8 +34258,8 @@ fn resolvePeerTypesInner(...@@ -34255,8 +34258,8 @@ fn resolvePeerTypesInner(
34255 }34258 }
3425634259
34257 if (sentinel) |cur_sent| {34260 if (sentinel) |cur_sent| {
34258 if (ty.sentinel(mod)) |peer_sent| {34261 if (ty.sentinel(zcu)) |peer_sent| {
34259 if (!peer_sent.eql(cur_sent, elem_ty, mod)) sentinel = null;34262 if (!peer_sent.eql(cur_sent, elem_ty, zcu)) sentinel = null;
34260 } else {34263 } else {
34261 sentinel = null;34264 sentinel = null;
34262 }34265 }
...@@ -34279,7 +34282,7 @@ fn resolvePeerTypesInner(...@@ -34279,7 +34282,7 @@ fn resolvePeerTypesInner(
34279 for (peer_tys, peer_vals, 0..) |*ty_ptr, *val_ptr, i| {34282 for (peer_tys, peer_vals, 0..) |*ty_ptr, *val_ptr, i| {
34280 const ty = ty_ptr.* orelse continue;34283 const ty = ty_ptr.* orelse continue;
3428134284
34282 if (!ty.isArrayOrVector(mod)) {34285 if (!ty.isArrayOrVector(zcu)) {
34283 // Allow tuples of the correct length34286 // Allow tuples of the correct length
34284 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{34287 const arr_like = sema.typeIsArrayLike(ty) orelse return .{ .conflict = .{
34285 .peer_idx_a = strat_reason,34288 .peer_idx_a = strat_reason,
...@@ -34305,16 +34308,16 @@ fn resolvePeerTypesInner(...@@ -34305,16 +34308,16 @@ fn resolvePeerTypesInner(
34305 }34308 }
3430634309
34307 if (len) |expect_len| {34310 if (len) |expect_len| {
34308 if (ty.arrayLen(mod) != expect_len) return .{ .conflict = .{34311 if (ty.arrayLen(zcu) != expect_len) return .{ .conflict = .{
34309 .peer_idx_a = first_idx,34312 .peer_idx_a = first_idx,
34310 .peer_idx_b = i,34313 .peer_idx_b = i,
34311 } };34314 } };
34312 } else {34315 } else {
34313 len = ty.arrayLen(mod);34316 len = ty.arrayLen(zcu);
34314 first_idx = i;34317 first_idx = i;
34315 }34318 }
3431634319
34317 ty_ptr.* = ty.childType(mod);34320 ty_ptr.* = ty.childType(zcu);
34318 val_ptr.* = null; // multiple child vals, so we can't easily use them in PTR34321 val_ptr.* = null; // multiple child vals, so we can't easily use them in PTR
34319 }34322 }
3432034323
...@@ -34339,7 +34342,7 @@ fn resolvePeerTypesInner(...@@ -34339,7 +34342,7 @@ fn resolvePeerTypesInner(
34339 var first_idx: usize = undefined;34342 var first_idx: usize = undefined;
34340 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {34343 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {
34341 const ty = opt_ty orelse continue;34344 const ty = opt_ty orelse continue;
34342 switch (ty.zigTypeTag(mod)) {34345 switch (ty.zigTypeTag(zcu)) {
34343 .ComptimeInt => continue, // comptime-known integers can always coerce to C pointers34346 .ComptimeInt => continue, // comptime-known integers can always coerce to C pointers
34344 .Int => {34347 .Int => {
34345 if (opt_val != null) {34348 if (opt_val != null) {
...@@ -34348,7 +34351,7 @@ fn resolvePeerTypesInner(...@@ -34348,7 +34351,7 @@ fn resolvePeerTypesInner(
34348 } else {34351 } else {
34349 // Runtime-known, so check if the type is no bigger than a usize34352 // Runtime-known, so check if the type is no bigger than a usize
34350 const ptr_bits = target.ptrBitWidth();34353 const ptr_bits = target.ptrBitWidth();
34351 const bits = ty.intInfo(mod).bits;34354 const bits = ty.intInfo(zcu).bits;
34352 if (bits <= ptr_bits) continue;34355 if (bits <= ptr_bits) continue;
34353 }34356 }
34354 },34357 },
...@@ -34356,13 +34359,13 @@ fn resolvePeerTypesInner(...@@ -34356,13 +34359,13 @@ fn resolvePeerTypesInner(
34356 else => {},34359 else => {},
34357 }34360 }
3435834361
34359 if (!ty.isPtrAtRuntime(mod)) return .{ .conflict = .{34362 if (!ty.isPtrAtRuntime(zcu)) return .{ .conflict = .{
34360 .peer_idx_a = strat_reason,34363 .peer_idx_a = strat_reason,
34361 .peer_idx_b = i,34364 .peer_idx_b = i,
34362 } };34365 } };
3436334366
34364 // Goes through optionals34367 // Goes through optionals
34365 const peer_info = ty.ptrInfo(mod);34368 const peer_info = ty.ptrInfo(zcu);
3436634369
34367 var ptr_info = opt_ptr_info orelse {34370 var ptr_info = opt_ptr_info orelse {
34368 opt_ptr_info = peer_info;34371 opt_ptr_info = peer_info;
...@@ -34391,17 +34394,17 @@ fn resolvePeerTypesInner(...@@ -34391,17 +34394,17 @@ fn resolvePeerTypesInner(
34391 ptr_info.sentinel = .none;34394 ptr_info.sentinel = .none;
34392 }34395 }
3439334396
34394 // Note that the align can be always non-zero; Module.ptrType will canonicalize it34397 // Note that the align can be always non-zero; Zcu.ptrType will canonicalize it
34395 ptr_info.flags.alignment = InternPool.Alignment.min(34398 ptr_info.flags.alignment = InternPool.Alignment.min(
34396 if (ptr_info.flags.alignment != .none)34399 if (ptr_info.flags.alignment != .none)
34397 ptr_info.flags.alignment34400 ptr_info.flags.alignment
34398 else34401 else
34399 Type.fromInterned(ptr_info.child).abiAlignment(pt),34402 Type.fromInterned(ptr_info.child).abiAlignment(zcu),
3440034403
34401 if (peer_info.flags.alignment != .none)34404 if (peer_info.flags.alignment != .none)
34402 peer_info.flags.alignment34405 peer_info.flags.alignment
34403 else34406 else
34404 Type.fromInterned(peer_info.child).abiAlignment(pt),34407 Type.fromInterned(peer_info.child).abiAlignment(zcu),
34405 );34408 );
34406 if (ptr_info.flags.address_space != peer_info.flags.address_space) {34409 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
34407 return .{ .conflict = .{34410 return .{ .conflict = .{
...@@ -34438,8 +34441,8 @@ fn resolvePeerTypesInner(...@@ -34438,8 +34441,8 @@ fn resolvePeerTypesInner(
3443834441
34439 for (peer_tys, 0..) |opt_ty, i| {34442 for (peer_tys, 0..) |opt_ty, i| {
34440 const ty = opt_ty orelse continue;34443 const ty = opt_ty orelse continue;
34441 const peer_info: InternPool.Key.PtrType = switch (ty.zigTypeTag(mod)) {34444 const peer_info: InternPool.Key.PtrType = switch (ty.zigTypeTag(zcu)) {
34442 .Pointer => ty.ptrInfo(mod),34445 .Pointer => ty.ptrInfo(zcu),
34443 .Fn => .{34446 .Fn => .{
34444 .child = ty.toIntern(),34447 .child = ty.toIntern(),
34445 .flags = .{34448 .flags = .{
...@@ -34480,12 +34483,12 @@ fn resolvePeerTypesInner(...@@ -34480,12 +34483,12 @@ fn resolvePeerTypesInner(
34480 if (ptr_info.flags.alignment != .none)34483 if (ptr_info.flags.alignment != .none)
34481 ptr_info.flags.alignment34484 ptr_info.flags.alignment
34482 else34485 else
34483 try sema.typeAbiAlignment(Type.fromInterned(ptr_info.child)),34486 try Type.fromInterned(ptr_info.child).abiAlignmentSema(pt),
3448434487
34485 if (peer_info.flags.alignment != .none)34488 if (peer_info.flags.alignment != .none)
34486 peer_info.flags.alignment34489 peer_info.flags.alignment
34487 else34490 else
34488 try sema.typeAbiAlignment(Type.fromInterned(peer_info.child)),34491 try Type.fromInterned(peer_info.child).abiAlignmentSema(pt),
34489 );34492 );
3449034493
34491 if (ptr_info.flags.address_space != peer_info.flags.address_space) {34494 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
...@@ -34747,7 +34750,7 @@ fn resolvePeerTypesInner(...@@ -34747,7 +34750,7 @@ fn resolvePeerTypesInner(
34747 first_idx = i;34750 first_idx = i;
34748 continue;34751 continue;
34749 };34752 };
34750 if (ty.zigTypeTag(mod) != .Fn) return .{ .conflict = .{34753 if (ty.zigTypeTag(zcu) != .Fn) return .{ .conflict = .{
34751 .peer_idx_a = strat_reason,34754 .peer_idx_a = strat_reason,
34752 .peer_idx_b = i,34755 .peer_idx_b = i,
34753 } };34756 } };
...@@ -34775,7 +34778,7 @@ fn resolvePeerTypesInner(...@@ -34775,7 +34778,7 @@ fn resolvePeerTypesInner(
3477534778
34776 for (peer_tys, 0..) |opt_ty, i| {34779 for (peer_tys, 0..) |opt_ty, i| {
34777 const ty = opt_ty orelse continue;34780 const ty = opt_ty orelse continue;
34778 switch (ty.zigTypeTag(mod)) {34781 switch (ty.zigTypeTag(zcu)) {
34779 .EnumLiteral, .Enum, .Union => {},34782 .EnumLiteral, .Enum, .Union => {},
34780 else => return .{ .conflict = .{34783 else => return .{ .conflict = .{
34781 .peer_idx_a = strat_reason,34784 .peer_idx_a = strat_reason,
...@@ -34794,32 +34797,32 @@ fn resolvePeerTypesInner(...@@ -34794,32 +34797,32 @@ fn resolvePeerTypesInner(
34794 .peer_idx_b = i,34797 .peer_idx_b = i,
34795 } };34798 } };
3479634799
34797 switch (cur_ty.zigTypeTag(mod)) {34800 switch (cur_ty.zigTypeTag(zcu)) {
34798 .EnumLiteral => {34801 .EnumLiteral => {
34799 opt_cur_ty = ty;34802 opt_cur_ty = ty;
34800 cur_ty_idx = i;34803 cur_ty_idx = i;
34801 },34804 },
34802 .Enum => switch (ty.zigTypeTag(mod)) {34805 .Enum => switch (ty.zigTypeTag(zcu)) {
34803 .EnumLiteral => {},34806 .EnumLiteral => {},
34804 .Enum => {34807 .Enum => {
34805 if (!ty.eql(cur_ty, mod)) return generic_err;34808 if (!ty.eql(cur_ty, zcu)) return generic_err;
34806 },34809 },
34807 .Union => {34810 .Union => {
34808 const tag_ty = ty.unionTagTypeHypothetical(mod);34811 const tag_ty = ty.unionTagTypeHypothetical(zcu);
34809 if (!tag_ty.eql(cur_ty, mod)) return generic_err;34812 if (!tag_ty.eql(cur_ty, zcu)) return generic_err;
34810 opt_cur_ty = ty;34813 opt_cur_ty = ty;
34811 cur_ty_idx = i;34814 cur_ty_idx = i;
34812 },34815 },
34813 else => unreachable,34816 else => unreachable,
34814 },34817 },
34815 .Union => switch (ty.zigTypeTag(mod)) {34818 .Union => switch (ty.zigTypeTag(zcu)) {
34816 .EnumLiteral => {},34819 .EnumLiteral => {},
34817 .Enum => {34820 .Enum => {
34818 const cur_tag_ty = cur_ty.unionTagTypeHypothetical(mod);34821 const cur_tag_ty = cur_ty.unionTagTypeHypothetical(zcu);
34819 if (!ty.eql(cur_tag_ty, mod)) return generic_err;34822 if (!ty.eql(cur_tag_ty, zcu)) return generic_err;
34820 },34823 },
34821 .Union => {34824 .Union => {
34822 if (!ty.eql(cur_ty, mod)) return generic_err;34825 if (!ty.eql(cur_ty, zcu)) return generic_err;
34823 },34826 },
34824 else => unreachable,34827 else => unreachable,
34825 },34828 },
...@@ -34832,7 +34835,7 @@ fn resolvePeerTypesInner(...@@ -34832,7 +34835,7 @@ fn resolvePeerTypesInner(
34832 .comptime_int => {34835 .comptime_int => {
34833 for (peer_tys, 0..) |opt_ty, i| {34836 for (peer_tys, 0..) |opt_ty, i| {
34834 const ty = opt_ty orelse continue;34837 const ty = opt_ty orelse continue;
34835 switch (ty.zigTypeTag(mod)) {34838 switch (ty.zigTypeTag(zcu)) {
34836 .ComptimeInt => {},34839 .ComptimeInt => {},
34837 else => return .{ .conflict = .{34840 else => return .{ .conflict = .{
34838 .peer_idx_a = strat_reason,34841 .peer_idx_a = strat_reason,
...@@ -34846,7 +34849,7 @@ fn resolvePeerTypesInner(...@@ -34846,7 +34849,7 @@ fn resolvePeerTypesInner(
34846 .comptime_float => {34849 .comptime_float => {
34847 for (peer_tys, 0..) |opt_ty, i| {34850 for (peer_tys, 0..) |opt_ty, i| {
34848 const ty = opt_ty orelse continue;34851 const ty = opt_ty orelse continue;
34849 switch (ty.zigTypeTag(mod)) {34852 switch (ty.zigTypeTag(zcu)) {
34850 .ComptimeInt, .ComptimeFloat => {},34853 .ComptimeInt, .ComptimeFloat => {},
34851 else => return .{ .conflict = .{34854 else => return .{ .conflict = .{
34852 .peer_idx_a = strat_reason,34855 .peer_idx_a = strat_reason,
...@@ -34868,11 +34871,11 @@ fn resolvePeerTypesInner(...@@ -34868,11 +34871,11 @@ fn resolvePeerTypesInner(
34868 const ty = opt_ty orelse continue;34871 const ty = opt_ty orelse continue;
34869 const opt_val = ptr_opt_val.*;34872 const opt_val = ptr_opt_val.*;
3487034873
34871 const peer_tag = ty.zigTypeTag(mod);34874 const peer_tag = ty.zigTypeTag(zcu);
34872 switch (peer_tag) {34875 switch (peer_tag) {
34873 .ComptimeInt => {34876 .ComptimeInt => {
34874 // If the value is undefined, we can't refine to a fixed-width int34877 // 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 = .{
34876 .peer_idx_a = strat_reason,34879 .peer_idx_a = strat_reason,
34877 .peer_idx_b = i,34880 .peer_idx_b = i,
34878 } };34881 } };
...@@ -34889,7 +34892,7 @@ fn resolvePeerTypesInner(...@@ -34889,7 +34892,7 @@ fn resolvePeerTypesInner(
3488934892
34890 if (opt_val != null) any_comptime_known = true;34893 if (opt_val != null) any_comptime_known = true;
3489134894
34892 const info = ty.intInfo(mod);34895 const info = ty.intInfo(zcu);
3489334896
34894 const idx_ptr = switch (info.signedness) {34897 const idx_ptr = switch (info.signedness) {
34895 .unsigned => &idx_unsigned,34898 .unsigned => &idx_unsigned,
...@@ -34901,7 +34904,7 @@ fn resolvePeerTypesInner(...@@ -34901,7 +34904,7 @@ fn resolvePeerTypesInner(
34901 continue;34904 continue;
34902 };34905 };
3490334906
34904 const cur_info = peer_tys[largest_idx].?.intInfo(mod);34907 const cur_info = peer_tys[largest_idx].?.intInfo(zcu);
34905 if (info.bits > cur_info.bits) {34908 if (info.bits > cur_info.bits) {
34906 idx_ptr.* = i;34909 idx_ptr.* = i;
34907 }34910 }
...@@ -34915,8 +34918,8 @@ fn resolvePeerTypesInner(...@@ -34915,8 +34918,8 @@ fn resolvePeerTypesInner(
34915 return .{ .success = peer_tys[idx_signed.?].? };34918 return .{ .success = peer_tys[idx_signed.?].? };
34916 }34919 }
3491734920
34918 const unsigned_info = peer_tys[idx_unsigned.?].?.intInfo(mod);34921 const unsigned_info = peer_tys[idx_unsigned.?].?.intInfo(zcu);
34919 const signed_info = peer_tys[idx_signed.?].?.intInfo(mod);34922 const signed_info = peer_tys[idx_signed.?].?.intInfo(zcu);
34920 if (signed_info.bits > unsigned_info.bits) {34923 if (signed_info.bits > unsigned_info.bits) {
34921 return .{ .success = peer_tys[idx_signed.?].? };34924 return .{ .success = peer_tys[idx_signed.?].? };
34922 }34925 }
...@@ -34948,7 +34951,7 @@ fn resolvePeerTypesInner(...@@ -34948,7 +34951,7 @@ fn resolvePeerTypesInner(
3494834951
34949 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {34952 for (peer_tys, peer_vals, 0..) |opt_ty, opt_val, i| {
34950 const ty = opt_ty orelse continue;34953 const ty = opt_ty orelse continue;
34951 switch (ty.zigTypeTag(mod)) {34954 switch (ty.zigTypeTag(zcu)) {
34952 .ComptimeFloat, .ComptimeInt => {},34955 .ComptimeFloat, .ComptimeInt => {},
34953 .Int => {34956 .Int => {
34954 if (opt_val == null) return .{ .conflict = .{34957 if (opt_val == null) return .{ .conflict = .{
...@@ -34958,7 +34961,7 @@ fn resolvePeerTypesInner(...@@ -34958,7 +34961,7 @@ fn resolvePeerTypesInner(
34958 },34961 },
34959 .Float => {34962 .Float => {
34960 if (opt_cur_ty) |cur_ty| {34963 if (opt_cur_ty) |cur_ty| {
34961 if (cur_ty.eql(ty, mod)) continue;34964 if (cur_ty.eql(ty, zcu)) continue;
34962 // Recreate the type so we eliminate any c_longdouble34965 // Recreate the type so we eliminate any c_longdouble
34963 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));34966 const bits = @max(cur_ty.floatBits(target), ty.floatBits(target));
34964 opt_cur_ty = switch (bits) {34967 opt_cur_ty = switch (bits) {
...@@ -34997,7 +35000,7 @@ fn resolvePeerTypesInner(...@@ -34997,7 +35000,7 @@ fn resolvePeerTypesInner(
34997 for (peer_tys, 0..) |opt_ty, i| {35000 for (peer_tys, 0..) |opt_ty, i| {
34998 const ty = opt_ty orelse continue;35001 const ty = opt_ty orelse continue;
3499935002
35000 if (!ty.isTupleOrAnonStruct(mod)) {35003 if (!ty.isTupleOrAnonStruct(zcu)) {
35001 return .{ .conflict = .{35004 return .{ .conflict = .{
35002 .peer_idx_a = strat_reason,35005 .peer_idx_a = strat_reason,
35003 .peer_idx_b = i,35006 .peer_idx_b = i,
...@@ -35006,8 +35009,8 @@ fn resolvePeerTypesInner(...@@ -35006,8 +35009,8 @@ fn resolvePeerTypesInner(
3500635009
35007 const first_idx = opt_first_idx orelse {35010 const first_idx = opt_first_idx orelse {
35008 opt_first_idx = i;35011 opt_first_idx = i;
35009 is_tuple = ty.isTuple(mod);35012 is_tuple = ty.isTuple(zcu);
35010 field_count = ty.structFieldCount(mod);35013 field_count = ty.structFieldCount(zcu);
35011 if (!is_tuple) {35014 if (!is_tuple) {
35012 const names = ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip);35015 const names = ip.indexToKey(ty.toIntern()).anon_struct_type.names.get(ip);
35013 field_names = try sema.arena.dupe(InternPool.NullTerminatedString, names);35016 field_names = try sema.arena.dupe(InternPool.NullTerminatedString, names);
...@@ -35015,7 +35018,7 @@ fn resolvePeerTypesInner(...@@ -35015,7 +35018,7 @@ fn resolvePeerTypesInner(
35015 continue;35018 continue;
35016 };35019 };
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) {
35019 return .{ .conflict = .{35022 return .{ .conflict = .{
35020 .peer_idx_a = first_idx,35023 .peer_idx_a = first_idx,
35021 .peer_idx_b = i,35024 .peer_idx_b = i,
...@@ -35025,7 +35028,7 @@ fn resolvePeerTypesInner(...@@ -35025,7 +35028,7 @@ fn resolvePeerTypesInner(
35025 if (!is_tuple) {35028 if (!is_tuple) {
35026 for (field_names, 0..) |expected, field_index_usize| {35029 for (field_names, 0..) |expected, field_index_usize| {
35027 const field_index: u32 = @intCast(field_index_usize);35030 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().?;
35029 if (actual == expected) continue;35032 if (actual == expected) continue;
35030 return .{ .conflict = .{35033 return .{ .conflict = .{
35031 .peer_idx_a = first_idx,35034 .peer_idx_a = first_idx,
...@@ -35052,7 +35055,7 @@ fn resolvePeerTypesInner(...@@ -35052,7 +35055,7 @@ fn resolvePeerTypesInner(
35052 peer_field_val.* = null;35055 peer_field_val.* = null;
35053 continue;35056 continue;
35054 };35057 };
35055 peer_field_ty.* = ty.structFieldType(field_index, mod);35058 peer_field_ty.* = ty.fieldType(field_index, zcu);
35056 peer_field_val.* = if (opt_val) |val| try val.fieldValue(pt, field_index) else null;35059 peer_field_val.* = if (opt_val) |val| try val.fieldValue(pt, field_index) else null;
35057 }35060 }
3505835061
...@@ -35074,7 +35077,7 @@ fn resolvePeerTypesInner(...@@ -35074,7 +35077,7 @@ fn resolvePeerTypesInner(
35074 // Already-resolved types won't be referenced by the error so it's fine35077 // Already-resolved types won't be referenced by the error so it's fine
35075 // to leave them undefined.35078 // to leave them undefined.
35076 const ty = opt_ty orelse continue;35079 const ty = opt_ty orelse continue;
35077 peer_field_ty.* = ty.structFieldType(field_index, mod);35080 peer_field_ty.* = ty.fieldType(field_index, zcu);
35078 }35081 }
3507935082
35080 return .{ .field_error = .{35083 return .{ .field_error = .{
...@@ -35111,7 +35114,7 @@ fn resolvePeerTypesInner(...@@ -35111,7 +35114,7 @@ fn resolvePeerTypesInner(
35111 comptime_val = coerced_val;35114 comptime_val = coerced_val;
35112 continue;35115 continue;
35113 };35116 };
35114 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), mod)) {35117 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), zcu)) {
35115 comptime_val = null;35118 comptime_val = null;
35116 break;35119 break;
35117 }35120 }
...@@ -35120,7 +35123,7 @@ fn resolvePeerTypesInner(...@@ -35120,7 +35123,7 @@ fn resolvePeerTypesInner(
35120 field_val.* = if (comptime_val) |v| v.toIntern() else .none;35123 field_val.* = if (comptime_val) |v| v.toIntern() else .none;
35121 }35124 }
3512235125
35123 const final_ty = try ip.getAnonStructType(mod.gpa, pt.tid, .{35126 const final_ty = try ip.getAnonStructType(zcu.gpa, pt.tid, .{
35124 .types = field_types,35127 .types = field_types,
35125 .names = if (is_tuple) &.{} else field_names,35128 .names = if (is_tuple) &.{} else field_names,
35126 .values = field_vals,35129 .values = field_vals,
...@@ -35135,7 +35138,7 @@ fn resolvePeerTypesInner(...@@ -35135,7 +35138,7 @@ fn resolvePeerTypesInner(
35135 for (peer_tys, 0..) |opt_ty, i| {35138 for (peer_tys, 0..) |opt_ty, i| {
35136 const ty = opt_ty orelse continue;35139 const ty = opt_ty orelse continue;
35137 if (expect_ty) |expect| {35140 if (expect_ty) |expect| {
35138 if (!ty.eql(expect, mod)) return .{ .conflict = .{35141 if (!ty.eql(expect, zcu)) return .{ .conflict = .{
35139 .peer_idx_a = first_idx,35142 .peer_idx_a = first_idx,
35140 .peer_idx_b = i,35143 .peer_idx_b = i,
35141 } };35144 } };
...@@ -35186,22 +35189,22 @@ const ArrayLike = struct {...@@ -35186,22 +35189,22 @@ const ArrayLike = struct {
35186};35189};
35187fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {35190fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
35188 const pt = sema.pt;35191 const pt = sema.pt;
35189 const mod = pt.zcu;35192 const zcu = pt.zcu;
35190 return switch (ty.zigTypeTag(mod)) {35193 return switch (ty.zigTypeTag(zcu)) {
35191 .Array => .{35194 .Array => .{
35192 .len = ty.arrayLen(mod),35195 .len = ty.arrayLen(zcu),
35193 .elem_ty = ty.childType(mod),35196 .elem_ty = ty.childType(zcu),
35194 },35197 },
35195 .Struct => {35198 .Struct => {
35196 const field_count = ty.structFieldCount(mod);35199 const field_count = ty.structFieldCount(zcu);
35197 if (field_count == 0) return .{35200 if (field_count == 0) return .{
35198 .len = 0,35201 .len = 0,
35199 .elem_ty = Type.noreturn,35202 .elem_ty = Type.noreturn,
35200 };35203 };
35201 if (!ty.isTuple(mod)) return null;35204 if (!ty.isTuple(zcu)) return null;
35202 const elem_ty = ty.structFieldType(0, mod);35205 const elem_ty = ty.fieldType(0, zcu);
35203 for (1..field_count) |i| {35206 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)) {
35205 return null;35208 return null;
35206 }35209 }
35207 }35210 }
...@@ -35216,8 +35219,8 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {...@@ -35216,8 +35219,8 @@ fn typeIsArrayLike(sema: *Sema, ty: Type) ?ArrayLike {
3521635219
35217pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void {35220pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void {
35218 const pt = sema.pt;35221 const pt = sema.pt;
35219 const mod = pt.zcu;35222 const zcu = pt.zcu;
35220 const ip = &mod.intern_pool;35223 const ip = &zcu.intern_pool;
3522135224
35222 if (sema.fn_ret_ty_ies) |ies| {35225 if (sema.fn_ret_ty_ies) |ies| {
35223 try sema.resolveInferredErrorSetPtr(block, src, ies);35226 try sema.resolveInferredErrorSetPtr(block, src, ies);
...@@ -35228,14 +35231,14 @@ pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void...@@ -35228,14 +35231,14 @@ pub fn resolveIes(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError!void
3522835231
35229pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void {35232pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void {
35230 const pt = sema.pt;35233 const pt = sema.pt;
35231 const mod = pt.zcu;35234 const zcu = pt.zcu;
35232 const ip = &mod.intern_pool;35235 const ip = &zcu.intern_pool;
35233 const fn_ty_info = mod.typeToFunc(fn_ty).?;35236 const fn_ty_info = zcu.typeToFunc(fn_ty).?;
3523435237
35235 try Type.fromInterned(fn_ty_info.return_type).resolveFully(pt);35238 try Type.fromInterned(fn_ty_info.return_type).resolveFully(pt);
3523635239
35237 if (mod.comp.config.any_error_tracing and35240 if (zcu.comp.config.any_error_tracing and
35238 Type.fromInterned(fn_ty_info.return_type).isError(mod))35241 Type.fromInterned(fn_ty_info.return_type).isError(zcu))
35239 {35242 {
35240 // Ensure the type exists so that backends can assume that.35243 // Ensure the type exists so that backends can assume that.
35241 _ = try pt.getBuiltinType("StackTrace");35244 _ = try pt.getBuiltinType("StackTrace");
...@@ -35258,9 +35261,9 @@ pub fn resolveStructAlignment(...@@ -35258,9 +35261,9 @@ pub fn resolveStructAlignment(
35258 struct_type: InternPool.LoadedStructType,35261 struct_type: InternPool.LoadedStructType,
35259) SemaError!void {35262) SemaError!void {
35260 const pt = sema.pt;35263 const pt = sema.pt;
35261 const mod = pt.zcu;35264 const zcu = pt.zcu;
35262 const ip = &mod.intern_pool;35265 const ip = &zcu.intern_pool;
35263 const target = mod.getTarget();35266 const target = zcu.getTarget();
3526435267
35265 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);35268 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);
3526635269
...@@ -35274,7 +35277,7 @@ pub fn resolveStructAlignment(...@@ -35274,7 +35277,7 @@ pub fn resolveStructAlignment(
35274 // might require explicit alignment.35277 // might require explicit alignment.
35275 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;35278 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3527635279
35277 try sema.resolveTypeFieldsStruct(ty, struct_type);35280 try sema.resolveStructFieldTypes(ty, struct_type);
3527835281
35279 // We'll guess "pointer-aligned", if the struct has an35282 // We'll guess "pointer-aligned", if the struct has an
35280 // underaligned pointer field then some allocations35283 // underaligned pointer field then some allocations
...@@ -35286,13 +35289,12 @@ pub fn resolveStructAlignment(...@@ -35286,13 +35289,12 @@ pub fn resolveStructAlignment(
3528635289
35287 for (0..struct_type.field_types.len) |i| {35290 for (0..struct_type.field_types.len) |i| {
35288 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);35291 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))
35290 continue;35293 continue;
35291 const field_align = try pt.structFieldAlignmentAdvanced(35294 const field_align = try field_ty.structFieldAlignmentSema(
35292 struct_type.fieldAlign(ip, i),35295 struct_type.fieldAlign(ip, i),
35293 field_ty,
35294 struct_type.layout,35296 struct_type.layout,
35295 .sema,35297 pt,
35296 );35298 );
35297 alignment = alignment.maxStrict(field_align);35299 alignment = alignment.maxStrict(field_align);
35298 }35300 }
...@@ -35311,10 +35313,10 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35311,10 +35313,10 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35311 if (struct_type.haveLayout(ip))35313 if (struct_type.haveLayout(ip))
35312 return;35314 return;
3531335315
35314 try sema.resolveTypeFieldsStruct(ty.toIntern(), struct_type);35316 try sema.resolveStructFieldTypes(ty.toIntern(), struct_type);
3531535317
35316 if (struct_type.layout == .@"packed") {35318 if (struct_type.layout == .@"packed") {
35317 semaBackingIntType(pt, struct_type) catch |err| switch (err) {35319 sema.backingIntType(struct_type) catch |err| switch (err) {
35318 error.OutOfMemory, error.AnalysisFail => |e| return e,35320 error.OutOfMemory, error.AnalysisFail => |e| return e,
35319 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35321 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35320 };35322 };
...@@ -35338,14 +35340,14 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35338,14 +35340,14 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3533835340
35339 for (aligns, sizes, 0..) |*field_align, *field_size, i| {35341 for (aligns, sizes, 0..) |*field_align, *field_size, i| {
35340 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);35342 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)) {
35342 struct_type.offsets.get(ip)[i] = 0;35344 struct_type.offsets.get(ip)[i] = 0;
35343 field_size.* = 0;35345 field_size.* = 0;
35344 field_align.* = .none;35346 field_align.* = .none;
35345 continue;35347 continue;
35346 }35348 }
3534735349
35348 field_size.* = sema.typeAbiSize(field_ty) catch |err| switch (err) {35350 field_size.* = field_ty.abiSizeSema(pt) catch |err| switch (err) {
35349 error.AnalysisFail => {35351 error.AnalysisFail => {
35350 const msg = sema.err orelse return err;35352 const msg = sema.err orelse return err;
35351 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});35353 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
...@@ -35353,16 +35355,15 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35353,16 +35355,15 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35353 },35355 },
35354 else => return err,35356 else => return err,
35355 };35357 };
35356 field_align.* = try pt.structFieldAlignmentAdvanced(35358 field_align.* = try field_ty.structFieldAlignmentSema(
35357 struct_type.fieldAlign(ip, i),35359 struct_type.fieldAlign(ip, i),
35358 field_ty,
35359 struct_type.layout,35360 struct_type.layout,
35360 .sema,35361 pt,
35361 );35362 );
35362 big_align = big_align.maxStrict(field_align.*);35363 big_align = big_align.maxStrict(field_align.*);
35363 }35364 }
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))) {
35366 const msg = try sema.errMsg(35367 const msg = try sema.errMsg(
35367 ty.srcLoc(zcu),35368 ty.srcLoc(zcu),
35368 "struct layout depends on it having runtime bits",35369 "struct layout depends on it having runtime bits",
...@@ -35387,7 +35388,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35387,7 +35388,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3538735388
35388 for (runtime_order, 0..) |*ro, i| {35389 for (runtime_order, 0..) |*ro, i| {
35389 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);35390 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)) {
35391 ro.* = .omitted;35392 ro.* = .omitted;
35392 } else {35393 } else {
35393 ro.* = @enumFromInt(i);35394 ro.* = @enumFromInt(i);
...@@ -35440,41 +35441,26 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35440,41 +35441,26 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35440 offset = offsets[i] + sizes[i];35441 offset = offsets[i] + sizes[i];
35441 }35442 }
35442 struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);35443 struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);
35443 _ = try sema.typeRequiresComptime(ty);35444 _ = try ty.comptimeOnlySema(pt);
35444}35445}
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;
35447 const zcu = pt.zcu;35452 const zcu = pt.zcu;
35448 const gpa = zcu.gpa;35453 const gpa = zcu.gpa;
35449 const ip = &zcu.intern_pool;35454 const ip = &zcu.intern_pool;
3545035455
35451 const cau_index = struct_type.cau.unwrap().?;35456 const cau_index = struct_type.cau.unwrap().?;
3545235457
35453 const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir;
35454
35455 var analysis_arena = std.heap.ArenaAllocator.init(gpa);35458 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
35456 defer analysis_arena.deinit();35459 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
35475 var block: Block = .{35461 var block: Block = .{
35476 .parent = null,35462 .parent = null,
35477 .sema = &sema,35463 .sema = sema,
35478 .namespace = ip.getCau(cau_index).namespace,35464 .namespace = ip.getCau(cau_index).namespace,
35479 .instructions = .{},35465 .instructions = .{},
35480 .inlining = null,35466 .inlining = null,
...@@ -35488,11 +35474,12 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp...@@ -35488,11 +35474,12 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
35488 var accumulator: u64 = 0;35474 var accumulator: u64 = 0;
35489 for (0..struct_type.field_types.len) |i| {35475 for (0..struct_type.field_types.len) |i| {
35490 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);35476 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);
35492 }35478 }
35493 break :blk accumulator;35479 break :blk accumulator;
35494 };35480 };
3549535481
35482 const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir;
35496 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;35483 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;
35497 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;35484 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
35498 assert(extended.opcode == .struct_decl);35485 assert(extended.opcode == .struct_decl);
...@@ -35543,17 +35530,17 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp...@@ -35543,17 +35530,17 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
3554335530
35544fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ty: Type, fields_bit_sum: u64) CompileError!void {35531fn checkBackingIntType(sema: *Sema, block: *Block, src: LazySrcLoc, backing_int_ty: Type, fields_bit_sum: u64) CompileError!void {
35545 const pt = sema.pt;35532 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)) {
35549 return sema.fail(block, src, "expected backing integer type, found '{}'", .{backing_int_ty.fmt(pt)});35536 return sema.fail(block, src, "expected backing integer type, found '{}'", .{backing_int_ty.fmt(pt)});
35550 }35537 }
35551 if (backing_int_ty.bitSize(pt) != fields_bit_sum) {35538 if (backing_int_ty.bitSize(zcu) != fields_bit_sum) {
35552 return sema.fail(35539 return sema.fail(
35553 block,35540 block,
35554 src,35541 src,
35555 "backing integer type '{}' has bit size {} but the struct fields have a total bit size of {}",35542 "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 },
35557 );35544 );
35558 }35545 }
35559}35546}
...@@ -35573,13 +35560,13 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {...@@ -35573,13 +35560,13 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3557335560
35574fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {35561fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
35575 const pt = sema.pt;35562 const pt = sema.pt;
35576 const mod = pt.zcu;35563 const zcu = pt.zcu;
35577 if (ty.zigTypeTag(mod) == .Pointer) {35564 if (ty.zigTypeTag(zcu) == .Pointer) {
35578 switch (ty.ptrSize(mod)) {35565 switch (ty.ptrSize(zcu)) {
35579 .Slice, .Many, .C => return,35566 .Slice, .Many, .C => return,
35580 .One => {35567 .One => {
35581 const elem_ty = ty.childType(mod);35568 const elem_ty = ty.childType(zcu);
35582 if (elem_ty.zigTypeTag(mod) == .Array) return;35569 if (elem_ty.zigTypeTag(zcu) == .Array) return;
35583 // TODO https://github.com/ziglang/zig/issues/1547935570 // TODO https://github.com/ziglang/zig/issues/15479
35584 // if (elem_ty.isTuple()) return;35571 // if (elem_ty.isTuple()) return;
35585 },35572 },
...@@ -35601,7 +35588,8 @@ pub fn resolveUnionAlignment(...@@ -35601,7 +35588,8 @@ pub fn resolveUnionAlignment(
35601 ty: Type,35588 ty: Type,
35602 union_type: InternPool.LoadedUnionType,35589 union_type: InternPool.LoadedUnionType,
35603) SemaError!void {35590) SemaError!void {
35604 const zcu = sema.pt.zcu;35591 const pt = sema.pt;
35592 const zcu = pt.zcu;
35605 const ip = &zcu.intern_pool;35593 const ip = &zcu.intern_pool;
35606 const target = zcu.getTarget();35594 const target = zcu.getTarget();
3560735595
...@@ -35616,18 +35604,18 @@ pub fn resolveUnionAlignment(...@@ -35616,18 +35604,18 @@ pub fn resolveUnionAlignment(
35616 // might require explicit alignment.35604 // might require explicit alignment.
35617 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;35605 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3561835606
35619 try sema.resolveTypeFieldsUnion(ty, union_type);35607 try sema.resolveUnionFieldTypes(ty, union_type);
3562035608
35621 var max_align: Alignment = .@"1";35609 var max_align: Alignment = .@"1";
35622 for (0..union_type.field_types.len) |field_index| {35610 for (0..union_type.field_types.len) |field_index| {
35623 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);35611 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
35626 const explicit_align = union_type.fieldAlign(ip, field_index);35614 const explicit_align = union_type.fieldAlign(ip, field_index);
35627 const field_align = if (explicit_align != .none)35615 const field_align = if (explicit_align != .none)
35628 explicit_align35616 explicit_align
35629 else35617 else
35630 try sema.typeAbiAlignment(field_ty);35618 try field_ty.abiAlignmentSema(sema.pt);
3563135619
35632 max_align = max_align.max(field_align);35620 max_align = max_align.max(field_align);
35633 }35621 }
...@@ -35635,12 +35623,12 @@ pub fn resolveUnionAlignment(...@@ -35635,12 +35623,12 @@ pub fn resolveUnionAlignment(
35635 union_type.setAlignment(ip, max_align);35623 union_type.setAlignment(ip, max_align);
35636}35624}
3563735625
35638/// This logic must be kept in sync with `Module.getUnionLayout`.35626/// This logic must be kept in sync with `Zcu.getUnionLayout`.
35639pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {35627pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35640 const pt = sema.pt;35628 const pt = sema.pt;
35641 const ip = &pt.zcu.intern_pool;35629 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
35645 // Load again, since the tag type might have changed due to resolution.35633 // Load again, since the tag type might have changed due to resolution.
35646 const union_type = ip.loadUnionType(ty.ip_index);35634 const union_type = ip.loadUnionType(ty.ip_index);
...@@ -35670,9 +35658,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35670,9 +35658,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35670 for (0..union_type.field_types.len) |field_index| {35658 for (0..union_type.field_types.len) |field_index| {
35671 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);35659 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) {
35676 error.AnalysisFail => {35664 error.AnalysisFail => {
35677 const msg = sema.err orelse return err;35665 const msg = sema.err orelse return err;
35678 try sema.addFieldErrNote(ty, field_index, msg, "while checking this field", .{});35666 try sema.addFieldErrNote(ty, field_index, msg, "while checking this field", .{});
...@@ -35685,17 +35673,17 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35685,17 +35673,17 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35685 const field_align = if (explicit_align != .none)35673 const field_align = if (explicit_align != .none)
35686 explicit_align35674 explicit_align
35687 else35675 else
35688 try sema.typeAbiAlignment(field_ty);35676 try field_ty.abiAlignmentSema(pt);
3568935677
35690 max_align = max_align.max(field_align);35678 max_align = max_align.max(field_align);
35691 }35679 }
3569235680
35693 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and35681 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);
35695 const size, const alignment, const padding = if (has_runtime_tag) layout: {35683 const size, const alignment, const padding = if (has_runtime_tag) layout: {
35696 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);35684 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);
35697 const tag_align = try sema.typeAbiAlignment(enum_tag_type);35685 const tag_align = try enum_tag_type.abiAlignmentSema(pt);
35698 const tag_size = try sema.typeAbiSize(enum_tag_type);35686 const tag_size = try enum_tag_type.abiSizeSema(pt);
3569935687
35700 // Put the tag before or after the payload depending on which one's35688 // Put the tag before or after the payload depending on which one's
35701 // alignment is greater.35689 // alignment is greater.
...@@ -35727,7 +35715,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35727,7 +35715,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3572735715
35728 union_type.setHaveLayout(ip, @intCast(size), padding, alignment);35716 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))) {
35731 const msg = try sema.errMsg(35719 const msg = try sema.errMsg(
35732 ty.srcLoc(pt.zcu),35720 ty.srcLoc(pt.zcu),
35733 "union layout depends on it having runtime bits",35721 "union layout depends on it having runtime bits",
...@@ -35746,6 +35734,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35746,6 +35734,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35746 );35734 );
35747 return sema.failWithOwnedErrorMsg(null, msg);35735 return sema.failWithOwnedErrorMsg(null, msg);
35748 }35736 }
35737 _ = try ty.comptimeOnlySema(pt);
35749}35738}
3575035739
35751/// Returns `error.AnalysisFail` if any of the types (recursively) failed to35740/// Returns `error.AnalysisFail` if any of the types (recursively) failed to
...@@ -35754,9 +35743,9 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35754,9 +35743,9 @@ pub fn resolveStructFully(sema: *Sema, ty: Type) SemaError!void {
35754 try sema.resolveStructLayout(ty);35743 try sema.resolveStructLayout(ty);
3575535744
35756 const pt = sema.pt;35745 const pt = sema.pt;
35757 const mod = pt.zcu;35746 const zcu = pt.zcu;
35758 const ip = &mod.intern_pool;35747 const ip = &zcu.intern_pool;
35759 const struct_type = mod.typeToStruct(ty).?;35748 const struct_type = zcu.typeToStruct(ty).?;
3576035749
35761 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);35750 assert(sema.owner.unwrap().cau == struct_type.cau.unwrap().?);
3576235751
...@@ -35777,9 +35766,9 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35777,9 +35766,9 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
35777 try sema.resolveUnionLayout(ty);35766 try sema.resolveUnionLayout(ty);
3577835767
35779 const pt = sema.pt;35768 const pt = sema.pt;
35780 const mod = pt.zcu;35769 const zcu = pt.zcu;
35781 const ip = &mod.intern_pool;35770 const ip = &zcu.intern_pool;
35782 const union_obj = mod.typeToUnion(ty).?;35771 const union_obj = zcu.typeToUnion(ty).?;
3578335772
35784 assert(sema.owner.unwrap().cau == union_obj.cau);35773 assert(sema.owner.unwrap().cau == union_obj.cau);
3578535774
...@@ -35804,10 +35793,10 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35804,10 +35793,10 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
35804 }35793 }
3580535794
35806 // And let's not forget comptime-only status.35795 // And let's not forget comptime-only status.
35807 _ = try sema.typeRequiresComptime(ty);35796 _ = try ty.comptimeOnlySema(pt);
35808}35797}
3580935798
35810pub fn resolveTypeFieldsStruct(35799pub fn resolveStructFieldTypes(
35811 sema: *Sema,35800 sema: *Sema,
35812 ty: InternPool.Index,35801 ty: InternPool.Index,
35813 struct_type: InternPool.LoadedStructType,35802 struct_type: InternPool.LoadedStructType,
...@@ -35830,7 +35819,7 @@ pub fn resolveTypeFieldsStruct(...@@ -35830,7 +35819,7 @@ pub fn resolveTypeFieldsStruct(
35830 }35819 }
35831 defer struct_type.clearFieldTypesWip(ip);35820 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) {
35834 error.AnalysisFail, error.OutOfMemory => |e| return e,35823 error.AnalysisFail, error.OutOfMemory => |e| return e,
35835 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35824 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35836 };35825 };
...@@ -35859,14 +35848,14 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {...@@ -35859,14 +35848,14 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) SemaError!void {
35859 }35848 }
35860 defer struct_type.clearInitsWip(ip);35849 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) {
35863 error.AnalysisFail, error.OutOfMemory => |e| return e,35852 error.AnalysisFail, error.OutOfMemory => |e| return e,
35864 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35853 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35865 };35854 };
35866 struct_type.setHaveFieldInits(ip);35855 struct_type.setHaveFieldInits(ip);
35867}35856}
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 {
35870 const pt = sema.pt;35859 const pt = sema.pt;
35871 const zcu = pt.zcu;35860 const zcu = pt.zcu;
35872 const ip = &zcu.intern_pool;35861 const ip = &zcu.intern_pool;
...@@ -35893,7 +35882,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35893,7 +35882,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3589335882
35894 union_type.setStatus(ip, .field_types_wip);35883 union_type.setStatus(ip, .field_types_wip);
35895 errdefer union_type.setStatus(ip, .none);35884 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) {
35897 error.AnalysisFail, error.OutOfMemory => |e| return e,35886 error.AnalysisFail, error.OutOfMemory => |e| return e,
35898 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35887 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35899 };35888 };
...@@ -35950,7 +35939,7 @@ fn resolveInferredErrorSet(...@@ -35950,7 +35939,7 @@ fn resolveInferredErrorSet(
35950 try pt.ensureFuncBodyAnalyzed(func_index);35939 try pt.ensureFuncBodyAnalyzed(func_index);
35951 }35940 }
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`
35954 // which calls `resolveInferredErrorSetPtr`.35943 // which calls `resolveInferredErrorSetPtr`.
35955 const final_resolved_ty = func.resolvedErrorSetUnordered(ip);35944 const final_resolved_ty = func.resolvedErrorSetUnordered(ip);
35956 assert(final_resolved_ty != .none);35945 assert(final_resolved_ty != .none);
...@@ -35997,9 +35986,9 @@ fn resolveAdHocInferredErrorSet(...@@ -35997,9 +35986,9 @@ fn resolveAdHocInferredErrorSet(
35997 value: InternPool.Index,35986 value: InternPool.Index,
35998) CompileError!InternPool.Index {35987) CompileError!InternPool.Index {
35999 const pt = sema.pt;35988 const pt = sema.pt;
36000 const mod = pt.zcu;35989 const zcu = pt.zcu;
36001 const gpa = sema.gpa;35990 const gpa = sema.gpa;
36002 const ip = &mod.intern_pool;35991 const ip = &zcu.intern_pool;
36003 const new_ty = try resolveAdHocInferredErrorSetTy(sema, block, src, ip.typeOf(value));35992 const new_ty = try resolveAdHocInferredErrorSetTy(sema, block, src, ip.typeOf(value));
36004 if (new_ty == .none) return value;35993 if (new_ty == .none) return value;
36005 return ip.getCoerced(gpa, pt.tid, value, new_ty);35994 return ip.getCoerced(gpa, pt.tid, value, new_ty);
...@@ -36013,8 +36002,8 @@ fn resolveAdHocInferredErrorSetTy(...@@ -36013,8 +36002,8 @@ fn resolveAdHocInferredErrorSetTy(
36013) CompileError!InternPool.Index {36002) CompileError!InternPool.Index {
36014 const ies = sema.fn_ret_ty_ies orelse return .none;36003 const ies = sema.fn_ret_ty_ies orelse return .none;
36015 const pt = sema.pt;36004 const pt = sema.pt;
36016 const mod = pt.zcu;36005 const zcu = pt.zcu;
36017 const ip = &mod.intern_pool;36006 const ip = &zcu.intern_pool;
36018 const error_union_info = switch (ip.indexToKey(ty)) {36007 const error_union_info = switch (ip.indexToKey(ty)) {
36019 .error_union_type => |x| x,36008 .error_union_type => |x| x,
36020 else => return .none,36009 else => return .none,
...@@ -36037,8 +36026,8 @@ fn resolveInferredErrorSetTy(...@@ -36037,8 +36026,8 @@ fn resolveInferredErrorSetTy(
36037 ty: InternPool.Index,36026 ty: InternPool.Index,
36038) CompileError!InternPool.Index {36027) CompileError!InternPool.Index {
36039 const pt = sema.pt;36028 const pt = sema.pt;
36040 const mod = pt.zcu;36029 const zcu = pt.zcu;
36041 const ip = &mod.intern_pool;36030 const ip = &zcu.intern_pool;
36042 if (ty == .anyerror_type) return ty;36031 if (ty == .anyerror_type) return ty;
36043 switch (ip.indexToKey(ty)) {36032 switch (ip.indexToKey(ty)) {
36044 .error_set_type => return ty,36033 .error_set_type => return ty,
...@@ -36096,11 +36085,11 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct {...@@ -36096,11 +36085,11 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct {
36096 return .{ fields_len, small, extra_index };36085 return .{ fields_len, small, extra_index };
36097}36086}
3609836087
36099fn semaStructFields(36088fn structFields(
36100 pt: Zcu.PerThread,36089 sema: *Sema,
36101 arena: Allocator,
36102 struct_type: InternPool.LoadedStructType,36090 struct_type: InternPool.LoadedStructType,
36103) CompileError!void {36091) CompileError!void {
36092 const pt = sema.pt;
36104 const zcu = pt.zcu;36093 const zcu = pt.zcu;
36105 const gpa = zcu.gpa;36094 const gpa = zcu.gpa;
36106 const ip = &zcu.intern_pool;36095 const ip = &zcu.intern_pool;
...@@ -36113,7 +36102,7 @@ fn semaStructFields(...@@ -36113,7 +36102,7 @@ fn semaStructFields(
3611336102
36114 if (fields_len == 0) switch (struct_type.layout) {36103 if (fields_len == 0) switch (struct_type.layout) {
36115 .@"packed" => {36104 .@"packed" => {
36116 try semaBackingIntType(pt, struct_type);36105 try sema.backingIntType(struct_type);
36117 return;36106 return;
36118 },36107 },
36119 .auto, .@"extern" => {36108 .auto, .@"extern" => {
...@@ -36122,26 +36111,9 @@ fn semaStructFields(...@@ -36122,26 +36111,9 @@ fn semaStructFields(
36122 },36111 },
36123 };36112 };
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
36142 var block_scope: Block = .{36114 var block_scope: Block = .{
36143 .parent = null,36115 .parent = null,
36144 .sema = &sema,36116 .sema = sema,
36145 .namespace = namespace_index,36117 .namespace = namespace_index,
36146 .instructions = .{},36118 .instructions = .{},
36147 .inlining = null,36119 .inlining = null,
...@@ -36315,14 +36287,13 @@ fn semaStructFields(...@@ -36315,14 +36287,13 @@ fn semaStructFields(
36315 try sema.flushExports();36287 try sema.flushExports();
36316}36288}
3631736289
36318// This logic must be kept in sync with `semaStructFields`36290// This logic must be kept in sync with `structFields`
36319fn semaStructFieldInits(36291fn structFieldInits(
36320 pt: Zcu.PerThread,36292 sema: *Sema,
36321 arena: Allocator,
36322 struct_type: InternPool.LoadedStructType,36293 struct_type: InternPool.LoadedStructType,
36323) CompileError!void {36294) CompileError!void {
36295 const pt = sema.pt;
36324 const zcu = pt.zcu;36296 const zcu = pt.zcu;
36325 const gpa = zcu.gpa;
36326 const ip = &zcu.intern_pool;36297 const ip = &zcu.intern_pool;
3632736298
36328 assert(!struct_type.haveFieldInits(ip));36299 assert(!struct_type.haveFieldInits(ip));
...@@ -36333,26 +36304,9 @@ fn semaStructFieldInits(...@@ -36333,26 +36304,9 @@ fn semaStructFieldInits(
36333 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;36304 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip) orelse return error.AnalysisFail;
36334 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);36305 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
36353 var block_scope: Block = .{36307 var block_scope: Block = .{
36354 .parent = null,36308 .parent = null,
36355 .sema = &sema,36309 .sema = sema,
36356 .namespace = namespace_index,36310 .namespace = namespace_index,
36357 .instructions = .{},36311 .instructions = .{},
36358 .inlining = null,36312 .inlining = null,
...@@ -36455,14 +36409,18 @@ fn semaStructFieldInits(...@@ -36455,14 +36409,18 @@ fn semaStructFieldInits(
36455 try sema.flushExports();36409 try sema.flushExports();
36456}36410}
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 {
36459 const tracy = trace(@src());36417 const tracy = trace(@src());
36460 defer tracy.end();36418 defer tracy.end();
3646136419
36420 const pt = sema.pt;
36462 const zcu = pt.zcu;36421 const zcu = pt.zcu;
36463 const gpa = zcu.gpa;36422 const gpa = zcu.gpa;
36464 const ip = &zcu.intern_pool;36423 const ip = &zcu.intern_pool;
36465 const cau_index = union_type.cau;
36466 const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir;36424 const zir = zcu.namespacePtr(union_type.namespace).fileScope(zcu).zir;
36467 const zir_index = union_type.zir_index.resolve(ip) orelse return error.AnalysisFail;36425 const zir_index = union_type.zir_index.resolve(ip) orelse return error.AnalysisFail;
36468 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;36426 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...@@ -36507,26 +36465,9 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
36507 const body = zir.bodySlice(extra_index, body_len);36465 const body = zir.bodySlice(extra_index, body_len);
36508 extra_index += body.len;36466 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
36527 var block_scope: Block = .{36468 var block_scope: Block = .{
36528 .parent = null,36469 .parent = null,
36529 .sema = &sema,36470 .sema = sema,
36530 .namespace = union_type.namespace,36471 .namespace = union_type.namespace,
36531 .instructions = .{},36472 .instructions = .{},
36532 .inlining = null,36473 .inlining = null,
...@@ -36669,7 +36610,10 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36669,7 +36610,10 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
3666936610
36670 if (enum_field_vals.capacity() > 0) {36611 if (enum_field_vals.capacity() > 0) {
36671 const enum_tag_val = if (tag_ref != .none) blk: {36612 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 });
36673 last_tag_val = val;36617 last_tag_val = val;
3667436618
36675 break :blk val;36619 break :blk val;
...@@ -36689,7 +36633,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36689,7 +36633,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
36689 .offset = .{ .container_field_value = @intCast(gop.index) },36633 .offset = .{ .container_field_value = @intCast(gop.index) },
36690 };36634 };
36691 const msg = msg: {36635 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 );
36693 errdefer msg.destroy(gpa);36641 errdefer msg.destroy(gpa);
36694 try sema.errNote(other_value_src, msg, "other occurrence here", .{});36642 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
36695 break :msg msg;36643 break :msg msg;
...@@ -36829,13 +36777,6 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind...@@ -36829,13 +36777,6 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_ty: InternPool.Ind
36829 try sema.flushExports();36777 try sema.flushExports();
36830}36778}
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
36839fn generateUnionTagTypeNumbered(36780fn generateUnionTagTypeNumbered(
36840 sema: *Sema,36781 sema: *Sema,
36841 block: *Block,36782 block: *Block,
...@@ -36845,9 +36786,9 @@ fn generateUnionTagTypeNumbered(...@@ -36845,9 +36786,9 @@ fn generateUnionTagTypeNumbered(
36845 union_name: InternPool.NullTerminatedString,36786 union_name: InternPool.NullTerminatedString,
36846) !InternPool.Index {36787) !InternPool.Index {
36847 const pt = sema.pt;36788 const pt = sema.pt;
36848 const mod = pt.zcu;36789 const zcu = pt.zcu;
36849 const gpa = sema.gpa;36790 const gpa = sema.gpa;
36850 const ip = &mod.intern_pool;36791 const ip = &zcu.intern_pool;
3685136792
36852 const name = try ip.getOrPutStringFmt(36793 const name = try ip.getOrPutStringFmt(
36853 gpa,36794 gpa,
...@@ -36881,8 +36822,8 @@ fn generateUnionTagTypeSimple(...@@ -36881,8 +36822,8 @@ fn generateUnionTagTypeSimple(
36881 union_name: InternPool.NullTerminatedString,36822 union_name: InternPool.NullTerminatedString,
36882) !InternPool.Index {36823) !InternPool.Index {
36883 const pt = sema.pt;36824 const pt = sema.pt;
36884 const mod = pt.zcu;36825 const zcu = pt.zcu;
36885 const ip = &mod.intern_pool;36826 const ip = &zcu.intern_pool;
36886 const gpa = sema.gpa;36827 const gpa = sema.gpa;
3688736828
36888 const name = try ip.getOrPutStringFmt(36829 const name = try ip.getOrPutStringFmt(
...@@ -37192,7 +37133,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37192,7 +37133,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37192 return null;37133 return null;
37193 },37134 },
37194 .auto, .explicit => {37135 .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
37197 return Value.fromInterned(switch (enum_type.names.len) {37138 return Value.fromInterned(switch (enum_type.names.len) {
37198 0 => try pt.intern(.{ .empty_enum_value = ty.toIntern() }),37139 0 => try pt.intern(.{ .empty_enum_value = ty.toIntern() }),
...@@ -37279,7 +37220,7 @@ fn analyzeComptimeAlloc(...@@ -37279,7 +37220,7 @@ fn analyzeComptimeAlloc(
37279 alignment: Alignment,37220 alignment: Alignment,
37280) CompileError!Air.Inst.Ref {37221) CompileError!Air.Inst.Ref {
37281 const pt = sema.pt;37222 const pt = sema.pt;
37282 const mod = pt.zcu;37223 const zcu = pt.zcu;
3728337224
37284 // Needed to make an anon decl with type `var_type` (the `finish()` call below).37225 // Needed to make an anon decl with type `var_type` (the `finish()` call below).
37285 _ = try sema.typeHasOnePossibleValue(var_type);37226 _ = try sema.typeHasOnePossibleValue(var_type);
...@@ -37288,7 +37229,7 @@ fn analyzeComptimeAlloc(...@@ -37288,7 +37229,7 @@ fn analyzeComptimeAlloc(
37288 .child = var_type.toIntern(),37229 .child = var_type.toIntern(),
37289 .flags = .{37230 .flags = .{
37290 .alignment = alignment,37231 .alignment = alignment,
37291 .address_space = target_util.defaultAddressSpace(mod.getTarget(), .global_constant),37232 .address_space = target_util.defaultAddressSpace(zcu.getTarget(), .global_constant),
37292 },37233 },
37293 });37234 });
3729437235
...@@ -37338,13 +37279,13 @@ pub fn analyzeAsAddressSpace(...@@ -37338,13 +37279,13 @@ pub fn analyzeAsAddressSpace(
37338 ctx: AddressSpaceContext,37279 ctx: AddressSpaceContext,
37339) !std.builtin.AddressSpace {37280) !std.builtin.AddressSpace {
37340 const pt = sema.pt;37281 const pt = sema.pt;
37341 const mod = pt.zcu;37282 const zcu = pt.zcu;
37342 const addrspace_ty = try pt.getBuiltinType("AddressSpace");37283 const addrspace_ty = try pt.getBuiltinType("AddressSpace");
37343 const coerced = try sema.coerce(block, addrspace_ty, air_ref, src);37284 const coerced = try sema.coerce(block, addrspace_ty, air_ref, src);
37344 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{37285 const addrspace_val = try sema.resolveConstDefinedValue(block, src, coerced, .{
37345 .needed_comptime_reason = "address space must be comptime-known",37286 .needed_comptime_reason = "address space must be comptime-known",
37346 });37287 });
37347 const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_val);37288 const address_space = zcu.toEnum(std.builtin.AddressSpace, addrspace_val);
37348 const target = pt.zcu.getTarget();37289 const target = pt.zcu.getTarget();
37349 const arch = target.cpu.arch;37290 const arch = target.cpu.arch;
3735037291
...@@ -37446,13 +37387,13 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError...@@ -37446,13 +37387,13 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError
37446/// This logic must be kept in sync with `Type.isPtrLikeOptional`.37387/// This logic must be kept in sync with `Type.isPtrLikeOptional`.
37447fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {37388fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
37448 const pt = sema.pt;37389 const pt = sema.pt;
37449 const mod = pt.zcu;37390 const zcu = pt.zcu;
37450 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {37391 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
37451 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {37392 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
37452 .One, .Many, .C => ty,37393 .One, .Many, .C => ty,
37453 .Slice => null,37394 .Slice => null,
37454 },37395 },
37455 .opt_type => |opt_child| switch (mod.intern_pool.indexToKey(opt_child)) {37396 .opt_type => |opt_child| switch (zcu.intern_pool.indexToKey(opt_child)) {
37456 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {37397 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
37457 .Slice, .C => null,37398 .Slice, .C => null,
37458 .Many, .One => {37399 .Many, .One => {
...@@ -37473,33 +37414,6 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {...@@ -37473,33 +37414,6 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
37473 };37414 };
37474}37415}
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
37503fn unionFieldIndex(37417fn unionFieldIndex(
37504 sema: *Sema,37418 sema: *Sema,
37505 block: *Block,37419 block: *Block,
...@@ -37508,10 +37422,10 @@ fn unionFieldIndex(...@@ -37508,10 +37422,10 @@ fn unionFieldIndex(
37508 field_src: LazySrcLoc,37422 field_src: LazySrcLoc,
37509) !u32 {37423) !u32 {
37510 const pt = sema.pt;37424 const pt = sema.pt;
37511 const mod = pt.zcu;37425 const zcu = pt.zcu;
37512 const ip = &mod.intern_pool;37426 const ip = &zcu.intern_pool;
37513 try union_ty.resolveFields(pt);37427 try union_ty.resolveFields(pt);
37514 const union_obj = mod.typeToUnion(union_ty).?;37428 const union_obj = zcu.typeToUnion(union_ty).?;
37515 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse37429 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
37516 return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name);37430 return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name);
37517 return @intCast(field_index);37431 return @intCast(field_index);
...@@ -37525,13 +37439,13 @@ fn structFieldIndex(...@@ -37525,13 +37439,13 @@ fn structFieldIndex(
37525 field_src: LazySrcLoc,37439 field_src: LazySrcLoc,
37526) !u32 {37440) !u32 {
37527 const pt = sema.pt;37441 const pt = sema.pt;
37528 const mod = pt.zcu;37442 const zcu = pt.zcu;
37529 const ip = &mod.intern_pool;37443 const ip = &zcu.intern_pool;
37530 try struct_ty.resolveFields(pt);37444 try struct_ty.resolveFields(pt);
37531 if (struct_ty.isAnonStruct(mod)) {37445 if (struct_ty.isAnonStruct(zcu)) {
37532 return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src);37446 return sema.anonStructFieldIndex(block, struct_ty, field_name, field_src);
37533 } else {37447 } else {
37534 const struct_type = mod.typeToStruct(struct_ty).?;37448 const struct_type = zcu.typeToStruct(struct_ty).?;
37535 return struct_type.nameIndex(ip, field_name) orelse37449 return struct_type.nameIndex(ip, field_name) orelse
37536 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name);37450 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name);
37537 }37451 }
...@@ -37545,8 +37459,8 @@ fn anonStructFieldIndex(...@@ -37545,8 +37459,8 @@ fn anonStructFieldIndex(
37545 field_src: LazySrcLoc,37459 field_src: LazySrcLoc,
37546) !u32 {37460) !u32 {
37547 const pt = sema.pt;37461 const pt = sema.pt;
37548 const mod = pt.zcu;37462 const zcu = pt.zcu;
37549 const ip = &mod.intern_pool;37463 const ip = &zcu.intern_pool;
37550 switch (ip.indexToKey(struct_ty.toIntern())) {37464 switch (ip.indexToKey(struct_ty.toIntern())) {
37551 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names.get(ip), 0..) |name, i| {37465 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names.get(ip), 0..) |name, i| {
37552 if (name == field_name) return @intCast(i);37466 if (name == field_name) return @intCast(i);
...@@ -37583,10 +37497,10 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize)...@@ -37583,10 +37497,10 @@ fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize)
3758337497
37584fn intAddInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize) !Value {37498fn intAddInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize) !Value {
37585 const pt = sema.pt;37499 const pt = sema.pt;
37586 const mod = pt.zcu;37500 const zcu = pt.zcu;
37587 if (ty.zigTypeTag(mod) == .Vector) {37501 if (ty.zigTypeTag(zcu) == .Vector) {
37588 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));37502 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
37589 const scalar_ty = ty.scalarType(mod);37503 const scalar_ty = ty.scalarType(zcu);
37590 for (result_data, 0..) |*scalar, i| {37504 for (result_data, 0..) |*scalar, i| {
37591 const lhs_elem = try lhs.elemValue(pt, i);37505 const lhs_elem = try lhs.elemValue(pt, i);
37592 const rhs_elem = try rhs.elemValue(pt, i);37506 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -37611,15 +37525,15 @@ fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {...@@ -37611,15 +37525,15 @@ fn intAddScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
37611 const pt = sema.pt;37525 const pt = sema.pt;
37612 if (scalar_ty.toIntern() != .comptime_int_type) {37526 if (scalar_ty.toIntern() != .comptime_int_type) {
37613 const res = try sema.intAddWithOverflowScalar(lhs, rhs, scalar_ty);37527 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;
37615 return res.wrapped_result;37529 return res.wrapped_result;
37616 }37530 }
37617 // TODO is this a performance issue? maybe we should try the operation without37531 // TODO is this a performance issue? maybe we should try the operation without
37618 // resorting to BigInt first.37532 // resorting to BigInt first.
37619 var lhs_space: Value.BigIntSpace = undefined;37533 var lhs_space: Value.BigIntSpace = undefined;
37620 var rhs_space: Value.BigIntSpace = undefined;37534 var rhs_space: Value.BigIntSpace = undefined;
37621 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);37535 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37622 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);37536 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
37623 const limbs = try sema.arena.alloc(37537 const limbs = try sema.arena.alloc(
37624 std.math.big.Limb,37538 std.math.big.Limb,
37625 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,37539 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
...@@ -37637,10 +37551,10 @@ fn numberAddWrapScalar(...@@ -37637,10 +37551,10 @@ fn numberAddWrapScalar(
37637 ty: Type,37551 ty: Type,
37638) !Value {37552) !Value {
37639 const pt = sema.pt;37553 const pt = sema.pt;
37640 const mod = pt.zcu;37554 const zcu = pt.zcu;
37641 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return pt.undefValue(ty);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) {
37644 return sema.intAdd(lhs, rhs, ty, undefined);37558 return sema.intAdd(lhs, rhs, ty, undefined);
37645 }37559 }
3764637560
...@@ -37701,17 +37615,18 @@ fn intSubInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi...@@ -37701,17 +37615,18 @@ fn intSubInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi
3770137615
37702fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {37616fn intSubScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) !Value {
37703 const pt = sema.pt;37617 const pt = sema.pt;
37618 const zcu = pt.zcu;
37704 if (scalar_ty.toIntern() != .comptime_int_type) {37619 if (scalar_ty.toIntern() != .comptime_int_type) {
37705 const res = try sema.intSubWithOverflowScalar(lhs, rhs, scalar_ty);37620 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;
37707 return res.wrapped_result;37622 return res.wrapped_result;
37708 }37623 }
37709 // TODO is this a performance issue? maybe we should try the operation without37624 // TODO is this a performance issue? maybe we should try the operation without
37710 // resorting to BigInt first.37625 // resorting to BigInt first.
37711 var lhs_space: Value.BigIntSpace = undefined;37626 var lhs_space: Value.BigIntSpace = undefined;
37712 var rhs_space: Value.BigIntSpace = undefined;37627 var rhs_space: Value.BigIntSpace = undefined;
37713 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);37628 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37714 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);37629 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
37715 const limbs = try sema.arena.alloc(37630 const limbs = try sema.arena.alloc(
37716 std.math.big.Limb,37631 std.math.big.Limb,
37717 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,37632 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len) + 1,
...@@ -37729,10 +37644,10 @@ fn numberSubWrapScalar(...@@ -37729,10 +37644,10 @@ fn numberSubWrapScalar(
37729 ty: Type,37644 ty: Type,
37730) !Value {37645) !Value {
37731 const pt = sema.pt;37646 const pt = sema.pt;
37732 const mod = pt.zcu;37647 const zcu = pt.zcu;
37733 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return pt.undefValue(ty);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) {
37736 return sema.intSub(lhs, rhs, ty, undefined);37651 return sema.intSub(lhs, rhs, ty, undefined);
37737 }37652 }
3773837653
...@@ -37751,12 +37666,12 @@ fn intSubWithOverflow(...@@ -37751,12 +37666,12 @@ fn intSubWithOverflow(
37751 ty: Type,37666 ty: Type,
37752) !Value.OverflowArithmeticResult {37667) !Value.OverflowArithmeticResult {
37753 const pt = sema.pt;37668 const pt = sema.pt;
37754 const mod = pt.zcu;37669 const zcu = pt.zcu;
37755 if (ty.zigTypeTag(mod) == .Vector) {37670 if (ty.zigTypeTag(zcu) == .Vector) {
37756 const vec_len = ty.vectorLen(mod);37671 const vec_len = ty.vectorLen(zcu);
37757 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);37672 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
37758 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);37673 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);
37760 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {37675 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
37761 const lhs_elem = try lhs.elemValue(pt, i);37676 const lhs_elem = try lhs.elemValue(pt, i);
37762 const rhs_elem = try rhs.elemValue(pt, i);37677 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -37785,10 +37700,10 @@ fn intSubWithOverflowScalar(...@@ -37785,10 +37700,10 @@ fn intSubWithOverflowScalar(
37785 ty: Type,37700 ty: Type,
37786) !Value.OverflowArithmeticResult {37701) !Value.OverflowArithmeticResult {
37787 const pt = sema.pt;37702 const pt = sema.pt;
37788 const mod = pt.zcu;37703 const zcu = pt.zcu;
37789 const info = ty.intInfo(mod);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)) {
37792 return .{37707 return .{
37793 .overflow_bit = try pt.undefValue(Type.u1),37708 .overflow_bit = try pt.undefValue(Type.u1),
37794 .wrapped_result = try pt.undefValue(ty),37709 .wrapped_result = try pt.undefValue(ty),
...@@ -37797,8 +37712,8 @@ fn intSubWithOverflowScalar(...@@ -37797,8 +37712,8 @@ fn intSubWithOverflowScalar(
3779737712
37798 var lhs_space: Value.BigIntSpace = undefined;37713 var lhs_space: Value.BigIntSpace = undefined;
37799 var rhs_space: Value.BigIntSpace = undefined;37714 var rhs_space: Value.BigIntSpace = undefined;
37800 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);37715 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
37801 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);37716 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
37802 const limbs = try sema.arena.alloc(37717 const limbs = try sema.arena.alloc(
37803 std.math.big.Limb,37718 std.math.big.Limb,
37804 std.math.big.int.calcTwosCompLimbCount(info.bits),37719 std.math.big.int.calcTwosCompLimbCount(info.bits),
...@@ -37824,12 +37739,12 @@ fn intFromFloat(...@@ -37824,12 +37739,12 @@ fn intFromFloat(
37824 mode: IntFromFloatMode,37739 mode: IntFromFloatMode,
37825) CompileError!Value {37740) CompileError!Value {
37826 const pt = sema.pt;37741 const pt = sema.pt;
37827 const mod = pt.zcu;37742 const zcu = pt.zcu;
37828 if (float_ty.zigTypeTag(mod) == .Vector) {37743 if (float_ty.zigTypeTag(zcu) == .Vector) {
37829 const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(mod));37744 const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(zcu));
37830 for (result_data, 0..) |*scalar, i| {37745 for (result_data, 0..) |*scalar, i| {
37831 const elem_val = try val.elemValue(pt, i);37746 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();
37833 }37748 }
37834 return Value.fromInterned(try pt.intern(.{ .aggregate = .{37749 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
37835 .ty = int_ty.toIntern(),37750 .ty = int_ty.toIntern(),
...@@ -37873,18 +37788,18 @@ fn intFromFloatScalar(...@@ -37873,18 +37788,18 @@ fn intFromFloatScalar(
37873 mode: IntFromFloatMode,37788 mode: IntFromFloatMode,
37874) CompileError!Value {37789) CompileError!Value {
37875 const pt = sema.pt;37790 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(
37881 block,37796 block,
37882 src,37797 src,
37883 "fractional component prevents float value '{}' from coercion to type '{}'",37798 "fractional component prevents float value '{}' from coercion to type '{}'",
37884 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },37799 .{ val.fmtValueSema(pt, sema), int_ty.fmt(pt) },
37885 );37800 );
3788637801
37887 const float = val.toFloat(f128, pt);37802 const float = val.toFloat(f128, zcu);
37888 if (std.math.isNan(float)) {37803 if (std.math.isNan(float)) {
37889 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{}'", .{37804 return sema.fail(block, src, "float value NaN cannot be stored in integer type '{}'", .{
37890 int_ty.fmt(pt),37805 int_ty.fmt(pt),
...@@ -37920,15 +37835,15 @@ fn intFitsInType(...@@ -37920,15 +37835,15 @@ fn intFitsInType(
37920 vector_index: ?*usize,37835 vector_index: ?*usize,
37921) CompileError!bool {37836) CompileError!bool {
37922 const pt = sema.pt;37837 const pt = sema.pt;
37923 const mod = pt.zcu;37838 const zcu = pt.zcu;
37924 if (ty.toIntern() == .comptime_int_type) return true;37839 if (ty.toIntern() == .comptime_int_type) return true;
37925 const info = ty.intInfo(mod);37840 const info = ty.intInfo(zcu);
37926 switch (val.toIntern()) {37841 switch (val.toIntern()) {
37927 .zero_usize, .zero_u8 => return true,37842 .zero_usize, .zero_u8 => return true,
37928 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {37843 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
37929 .undef => return true,37844 .undef => return true,
37930 .variable, .@"extern", .func, .ptr => {37845 .variable, .@"extern", .func, .ptr => {
37931 const target = mod.getTarget();37846 const target = zcu.getTarget();
37932 const ptr_bits = target.ptrBitWidth();37847 const ptr_bits = target.ptrBitWidth();
37933 return switch (info.signedness) {37848 return switch (info.signedness) {
37934 .signed => info.bits > ptr_bits,37849 .signed => info.bits > ptr_bits,
...@@ -37945,7 +37860,7 @@ fn intFitsInType(...@@ -37945,7 +37860,7 @@ fn intFitsInType(
37945 const max_needed_bits = @as(u16, 16) + @intFromBool(info.signedness == .signed);37860 const max_needed_bits = @as(u16, 16) + @intFromBool(info.signedness == .signed);
37946 // If it is u16 or bigger we know the alignment fits without resolving it.37861 // If it is u16 or bigger we know the alignment fits without resolving it.
37947 if (info.bits >= max_needed_bits) return true;37862 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);
37949 if (x == .none) return true;37864 if (x == .none) return true;
37950 const actual_needed_bits = @as(usize, x.toLog2Units()) + 1 + @intFromBool(info.signedness == .signed);37865 const actual_needed_bits = @as(usize, x.toLog2Units()) + 1 + @intFromBool(info.signedness == .signed);
37951 return info.bits >= actual_needed_bits;37866 return info.bits >= actual_needed_bits;
...@@ -37954,16 +37869,16 @@ fn intFitsInType(...@@ -37954,16 +37869,16 @@ fn intFitsInType(
37954 const max_needed_bits = @as(u16, 64) + @intFromBool(info.signedness == .signed);37869 const max_needed_bits = @as(u16, 64) + @intFromBool(info.signedness == .signed);
37955 // If it is u64 or bigger we know the size fits without resolving it.37870 // If it is u64 or bigger we know the size fits without resolving it.
37956 if (info.bits >= max_needed_bits) return true;37871 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);
37958 if (x == 0) return true;37873 if (x == 0) return true;
37959 const actual_needed_bits = std.math.log2(x) + 1 + @intFromBool(info.signedness == .signed);37874 const actual_needed_bits = std.math.log2(x) + 1 + @intFromBool(info.signedness == .signed);
37960 return info.bits >= actual_needed_bits;37875 return info.bits >= actual_needed_bits;
37961 },37876 },
37962 },37877 },
37963 .aggregate => |aggregate| {37878 .aggregate => |aggregate| {
37964 assert(ty.zigTypeTag(mod) == .Vector);37879 assert(ty.zigTypeTag(zcu) == .Vector);
37965 return switch (aggregate.storage) {37880 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| {
37967 if (byte == 0) continue;37882 if (byte == 0) continue;
37968 const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed);37883 const actual_needed_bits = std.math.log2(byte) + 1 + @intFromBool(info.signedness == .signed);
37969 if (info.bits >= actual_needed_bits) continue;37884 if (info.bits >= actual_needed_bits) continue;
...@@ -37975,7 +37890,7 @@ fn intFitsInType(...@@ -37975,7 +37890,7 @@ fn intFitsInType(
37975 .elems => |elems| elems,37890 .elems => |elems| elems,
37976 .repeated_elem => |elem| @as(*const [1]InternPool.Index, &elem),37891 .repeated_elem => |elem| @as(*const [1]InternPool.Index, &elem),
37977 }, 0..) |elem, i| {37892 }, 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;
37979 if (vector_index) |vi| vi.* = i;37894 if (vector_index) |vi| vi.* = i;
37980 break false;37895 break false;
37981 } else true,37896 } else true,
...@@ -37997,15 +37912,15 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {...@@ -37997,15 +37912,15 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {
37997/// Asserts the type is an enum.37912/// Asserts the type is an enum.
37998fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {37913fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
37999 const pt = sema.pt;37914 const pt = sema.pt;
38000 const mod = pt.zcu;37915 const zcu = pt.zcu;
38001 const enum_type = mod.intern_pool.loadEnumType(ty.toIntern());37916 const enum_type = zcu.intern_pool.loadEnumType(ty.toIntern());
38002 assert(enum_type.tag_mode != .nonexhaustive);37917 assert(enum_type.tag_mode != .nonexhaustive);
38003 // The `tagValueIndex` function call below relies on the type being the integer tag type.37918 // The `tagValueIndex` function call below relies on the type being the integer tag type.
38004 // `getCoerced` assumes the value will fit the new type.37919 // `getCoerced` assumes the value will fit the new type.
38005 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;37920 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;
38006 const int_coerced = try pt.getCoerced(int, Type.fromInterned(enum_type.tag_ty));37921 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;
38009}37924}
3801037925
38011fn intAddWithOverflow(37926fn intAddWithOverflow(
...@@ -38015,12 +37930,12 @@ fn intAddWithOverflow(...@@ -38015,12 +37930,12 @@ fn intAddWithOverflow(
38015 ty: Type,37930 ty: Type,
38016) !Value.OverflowArithmeticResult {37931) !Value.OverflowArithmeticResult {
38017 const pt = sema.pt;37932 const pt = sema.pt;
38018 const mod = pt.zcu;37933 const zcu = pt.zcu;
38019 if (ty.zigTypeTag(mod) == .Vector) {37934 if (ty.zigTypeTag(zcu) == .Vector) {
38020 const vec_len = ty.vectorLen(mod);37935 const vec_len = ty.vectorLen(zcu);
38021 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);37936 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
38022 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);37937 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);
38024 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {37939 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
38025 const lhs_elem = try lhs.elemValue(pt, i);37940 const lhs_elem = try lhs.elemValue(pt, i);
38026 const rhs_elem = try rhs.elemValue(pt, i);37941 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -38049,10 +37964,10 @@ fn intAddWithOverflowScalar(...@@ -38049,10 +37964,10 @@ fn intAddWithOverflowScalar(
38049 ty: Type,37964 ty: Type,
38050) !Value.OverflowArithmeticResult {37965) !Value.OverflowArithmeticResult {
38051 const pt = sema.pt;37966 const pt = sema.pt;
38052 const mod = pt.zcu;37967 const zcu = pt.zcu;
38053 const info = ty.intInfo(mod);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)) {
38056 return .{37971 return .{
38057 .overflow_bit = try pt.undefValue(Type.u1),37972 .overflow_bit = try pt.undefValue(Type.u1),
38058 .wrapped_result = try pt.undefValue(ty),37973 .wrapped_result = try pt.undefValue(ty),
...@@ -38061,8 +37976,8 @@ fn intAddWithOverflowScalar(...@@ -38061,8 +37976,8 @@ fn intAddWithOverflowScalar(
3806137976
38062 var lhs_space: Value.BigIntSpace = undefined;37977 var lhs_space: Value.BigIntSpace = undefined;
38063 var rhs_space: Value.BigIntSpace = undefined;37978 var rhs_space: Value.BigIntSpace = undefined;
38064 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_space, pt, .sema);37979 const lhs_bigint = try lhs.toBigIntSema(&lhs_space, pt);
38065 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_space, pt, .sema);37980 const rhs_bigint = try rhs.toBigIntSema(&rhs_space, pt);
38066 const limbs = try sema.arena.alloc(37981 const limbs = try sema.arena.alloc(
38067 std.math.big.Limb,37982 std.math.big.Limb,
38068 std.math.big.int.calcTwosCompLimbCount(info.bits),37983 std.math.big.int.calcTwosCompLimbCount(info.bits),
...@@ -38088,13 +38003,13 @@ fn compareAll(...@@ -38088,13 +38003,13 @@ fn compareAll(
38088 ty: Type,38003 ty: Type,
38089) CompileError!bool {38004) CompileError!bool {
38090 const pt = sema.pt;38005 const pt = sema.pt;
38091 const mod = pt.zcu;38006 const zcu = pt.zcu;
38092 if (ty.zigTypeTag(mod) == .Vector) {38007 if (ty.zigTypeTag(zcu) == .Vector) {
38093 var i: usize = 0;38008 var i: usize = 0;
38094 while (i < ty.vectorLen(mod)) : (i += 1) {38009 while (i < ty.vectorLen(zcu)) : (i += 1) {
38095 const lhs_elem = try lhs.elemValue(pt, i);38010 const lhs_elem = try lhs.elemValue(pt, i);
38096 const rhs_elem = try rhs.elemValue(pt, i);38011 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)))) {
38098 return false;38013 return false;
38099 }38014 }
38100 }38015 }
...@@ -38117,7 +38032,7 @@ fn compareScalar(...@@ -38117,7 +38032,7 @@ fn compareScalar(
38117 switch (op) {38032 switch (op) {
38118 .eq => return sema.valuesEqual(coerced_lhs, coerced_rhs, ty),38033 .eq => return sema.valuesEqual(coerced_lhs, coerced_rhs, ty),
38119 .neq => return !(try sema.valuesEqual(coerced_lhs, coerced_rhs, ty)),38034 .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),
38121 }38036 }
38122}38037}
3812338038
...@@ -38139,17 +38054,17 @@ fn compareVector(...@@ -38139,17 +38054,17 @@ fn compareVector(
38139 ty: Type,38054 ty: Type,
38140) !Value {38055) !Value {
38141 const pt = sema.pt;38056 const pt = sema.pt;
38142 const mod = pt.zcu;38057 const zcu = pt.zcu;
38143 assert(ty.zigTypeTag(mod) == .Vector);38058 assert(ty.zigTypeTag(zcu) == .Vector);
38144 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));38059 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(zcu));
38145 for (result_data, 0..) |*scalar, i| {38060 for (result_data, 0..) |*scalar, i| {
38146 const lhs_elem = try lhs.elemValue(pt, i);38061 const lhs_elem = try lhs.elemValue(pt, i);
38147 const rhs_elem = try rhs.elemValue(pt, i);38062 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));
38149 scalar.* = Value.makeBool(res_bool).toIntern();38064 scalar.* = Value.makeBool(res_bool).toIntern();
38150 }38065 }
38151 return Value.fromInterned(try pt.intern(.{ .aggregate = .{38066 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(),
38153 .storage = .{ .elems = result_data },38068 .storage = .{ .elems = result_data },
38154 } }));38069 } }));
38155}38070}
...@@ -38250,8 +38165,8 @@ fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Ai...@@ -38250,8 +38165,8 @@ fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Ai
38250/// Returns true if any value contained in `val` is undefined.38165/// Returns true if any value contained in `val` is undefined.
38251fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {38166fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {
38252 const pt = sema.pt;38167 const pt = sema.pt;
38253 const mod = pt.zcu;38168 const zcu = pt.zcu;
38254 return switch (mod.intern_pool.indexToKey(val.toIntern())) {38169 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
38255 .undef => true,38170 .undef => true,
38256 .simple_value => |v| v == .undefined,38171 .simple_value => |v| v == .undefined,
38257 .slice => {38172 .slice => {
...@@ -38261,7 +38176,7 @@ fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {...@@ -38261,7 +38176,7 @@ fn anyUndef(sema: *Sema, block: *Block, src: LazySrcLoc, val: Value) !bool {
38261 return sema.anyUndef(block, src, arr);38176 return sema.anyUndef(block, src, arr);
38262 },38177 },
38263 .aggregate => |aggregate| for (0..aggregate.storage.values().len) |i| {38178 .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];
38265 if (try sema.anyUndef(block, src, Value.fromInterned(elem))) break true;38180 if (try sema.anyUndef(block, src, Value.fromInterned(elem))) break true;
38266 } else false,38181 } else false,
38267 else => false,38182 else => false,
...@@ -38510,7 +38425,7 @@ pub fn resolveDeclaredEnum(...@@ -38510,7 +38425,7 @@ pub fn resolveDeclaredEnum(
38510 wip_ty.setTagTy(ip, int_tag_ty.toIntern());38425 wip_ty.setTagTy(ip, int_tag_ty.toIntern());
3851138426
38512 if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) {38427 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)) {
38514 return sema.fail(&block, src, "non-exhaustive enum specifies every value", .{});38429 return sema.fail(&block, src, "non-exhaustive enum specifies every value", .{});
38515 }38430 }
38516 }38431 }
src/Sema/bitcast.zig+51-47
...@@ -85,23 +85,23 @@ fn bitCastInner(...@@ -85,23 +85,23 @@ fn bitCastInner(
85 assert(val_ty.hasWellDefinedLayout(zcu));85 assert(val_ty.hasWellDefinedLayout(zcu));
8686
87 const abi_pad_bits, const host_pad_bits = if (host_bits > 0)87 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) }
89 else89 else
90 .{ val_ty.abiSize(pt) * 8 - val_ty.bitSize(pt), 0 };90 .{ val_ty.abiSize(zcu) * 8 - val_ty.bitSize(zcu), 0 };
9191
92 const skip_bits = switch (endian) {92 const skip_bits = switch (endian) {
93 .little => bit_offset + byte_offset * 8,93 .little => bit_offset + byte_offset * 8,
94 .big => if (host_bits > 0)94 .big => if (host_bits > 0)
95 val_ty.abiSize(pt) * 8 - byte_offset * 8 - host_bits + bit_offset95 val_ty.abiSize(zcu) * 8 - byte_offset * 8 - host_bits + bit_offset
96 else96 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),
98 };98 };
9999
100 var unpack: UnpackValueBits = .{100 var unpack: UnpackValueBits = .{
101 .pt = sema.pt,101 .pt = sema.pt,
102 .arena = sema.arena,102 .arena = sema.arena,
103 .skip_bits = skip_bits,103 .skip_bits = skip_bits,
104 .remaining_bits = dest_ty.bitSize(pt),104 .remaining_bits = dest_ty.bitSize(zcu),
105 .unpacked = std.ArrayList(InternPool.Index).init(sema.arena),105 .unpacked = std.ArrayList(InternPool.Index).init(sema.arena),
106 };106 };
107 switch (endian) {107 switch (endian) {
...@@ -141,22 +141,22 @@ fn bitCastSpliceInner(...@@ -141,22 +141,22 @@ fn bitCastSpliceInner(
141 try val_ty.resolveLayout(pt);141 try val_ty.resolveLayout(pt);
142 try splice_val_ty.resolveLayout(pt);142 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
146 const splice_offset = switch (endian) {146 const splice_offset = switch (endian) {
147 .little => bit_offset + byte_offset * 8,147 .little => bit_offset + byte_offset * 8,
148 .big => if (host_bits > 0)148 .big => if (host_bits > 0)
149 val_ty.abiSize(pt) * 8 - byte_offset * 8 - host_bits + bit_offset149 val_ty.abiSize(zcu) * 8 - byte_offset * 8 - host_bits + bit_offset
150 else150 else
151 val_ty.abiSize(pt) * 8 - byte_offset * 8 - splice_bits,151 val_ty.abiSize(zcu) * 8 - byte_offset * 8 - splice_bits,
152 };152 };
153153
154 assert(splice_offset + splice_bits <= val_ty.abiSize(pt) * 8);154 assert(splice_offset + splice_bits <= val_ty.abiSize(zcu) * 8);
155155
156 const abi_pad_bits, const host_pad_bits = if (host_bits > 0)156 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) }
158 else158 else
159 .{ val_ty.abiSize(pt) * 8 - val_ty.bitSize(pt), 0 };159 .{ val_ty.abiSize(zcu) * 8 - val_ty.bitSize(zcu), 0 };
160160
161 var unpack: UnpackValueBits = .{161 var unpack: UnpackValueBits = .{
162 .pt = pt,162 .pt = pt,
...@@ -181,7 +181,7 @@ fn bitCastSpliceInner(...@@ -181,7 +181,7 @@ fn bitCastSpliceInner(
181 try unpack.add(splice_val);181 try unpack.add(splice_val);
182182
183 unpack.skip_bits = splice_offset + splice_bits;183 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;
185 switch (endian) {185 switch (endian) {
186 .little => {186 .little => {
187 try unpack.add(val);187 try unpack.add(val);
...@@ -229,7 +229,7 @@ const UnpackValueBits = struct {...@@ -229,7 +229,7 @@ const UnpackValueBits = struct {
229 }229 }
230230
231 const ty = val.typeOf(zcu);231 const ty = val.typeOf(zcu);
232 const bit_size = ty.bitSize(pt);232 const bit_size = ty.bitSize(zcu);
233233
234 if (unpack.skip_bits >= bit_size) {234 if (unpack.skip_bits >= bit_size) {
235 unpack.skip_bits -= bit_size;235 unpack.skip_bits -= bit_size;
...@@ -291,7 +291,7 @@ const UnpackValueBits = struct {...@@ -291,7 +291,7 @@ const UnpackValueBits = struct {
291 // The final element does not have trailing padding.291 // The final element does not have trailing padding.
292 // Elements are reversed in packed memory on BE targets.292 // Elements are reversed in packed memory on BE targets.
293 const elem_ty = ty.childType(zcu);293 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);
295 const len = ty.arrayLen(zcu);295 const len = ty.arrayLen(zcu);
296 const maybe_sent = ty.sentinel(zcu);296 const maybe_sent = ty.sentinel(zcu);
297297
...@@ -323,12 +323,12 @@ const UnpackValueBits = struct {...@@ -323,12 +323,12 @@ const UnpackValueBits = struct {
323 var cur_bit_off: u64 = 0;323 var cur_bit_off: u64 = 0;
324 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrder(ip);324 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrder(ip);
325 while (it.next()) |field_idx| {325 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;
327 const pad_bits = want_bit_off - cur_bit_off;327 const pad_bits = want_bit_off - cur_bit_off;
328 const field_val = try val.fieldValue(pt, field_idx);328 const field_val = try val.fieldValue(pt, field_idx);
329 try unpack.padding(pad_bits);329 try unpack.padding(pad_bits);
330 try unpack.add(field_val);330 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);
332 }332 }
333 // Add trailing padding bits.333 // Add trailing padding bits.
334 try unpack.padding(bit_size - cur_bit_off);334 try unpack.padding(bit_size - cur_bit_off);
...@@ -339,11 +339,11 @@ const UnpackValueBits = struct {...@@ -339,11 +339,11 @@ const UnpackValueBits = struct {
339 while (it.next()) |field_idx| {339 while (it.next()) |field_idx| {
340 const field_val = try val.fieldValue(pt, field_idx);340 const field_val = try val.fieldValue(pt, field_idx);
341 const field_ty = field_val.typeOf(zcu);341 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);
343 const pad_bits = cur_bit_off - want_bit_off;343 const pad_bits = cur_bit_off - want_bit_off;
344 try unpack.padding(pad_bits);344 try unpack.padding(pad_bits);
345 try unpack.add(field_val);345 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);
347 }347 }
348 assert(cur_bit_off == 0);348 assert(cur_bit_off == 0);
349 },349 },
...@@ -366,7 +366,7 @@ const UnpackValueBits = struct {...@@ -366,7 +366,7 @@ const UnpackValueBits = struct {
366 // This correctly handles the case where `tag == .none`, since the payload is then366 // This correctly handles the case where `tag == .none`, since the payload is then
367 // either an integer or a byte array, both of which we can unpack.367 // either an integer or a byte array, both of which we can unpack.
368 const payload_val = Value.fromInterned(un.val);368 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);
370 if (endian == .little or ty.containerLayout(zcu) == .@"packed") {370 if (endian == .little or ty.containerLayout(zcu) == .@"packed") {
371 try unpack.add(payload_val);371 try unpack.add(payload_val);
372 try unpack.padding(pad_bits);372 try unpack.padding(pad_bits);
...@@ -398,13 +398,14 @@ const UnpackValueBits = struct {...@@ -398,13 +398,14 @@ const UnpackValueBits = struct {
398398
399 fn primitive(unpack: *UnpackValueBits, val: Value) BitCastError!void {399 fn primitive(unpack: *UnpackValueBits, val: Value) BitCastError!void {
400 const pt = unpack.pt;400 const pt = unpack.pt;
401 const zcu = pt.zcu;
401402
402 if (unpack.remaining_bits == 0) {403 if (unpack.remaining_bits == 0) {
403 return;404 return;
404 }405 }
405406
406 const ty = val.typeOf(pt.zcu);407 const ty = val.typeOf(pt.zcu);
407 const bit_size = ty.bitSize(pt);408 const bit_size = ty.bitSize(zcu);
408409
409 // Note that this skips all zero-bit types.410 // Note that this skips all zero-bit types.
410 if (unpack.skip_bits >= bit_size) {411 if (unpack.skip_bits >= bit_size) {
...@@ -429,9 +430,10 @@ const UnpackValueBits = struct {...@@ -429,9 +430,10 @@ const UnpackValueBits = struct {
429430
430 fn splitPrimitive(unpack: *UnpackValueBits, val: Value, bit_offset: u64, bit_count: u64) BitCastError!void {431 fn splitPrimitive(unpack: *UnpackValueBits, val: Value, bit_offset: u64, bit_count: u64) BitCastError!void {
431 const pt = unpack.pt;432 const pt = unpack.pt;
433 const zcu = pt.zcu;
432 const ty = val.typeOf(pt.zcu);434 const ty = val.typeOf(pt.zcu);
433435
434 const val_bits = ty.bitSize(pt);436 const val_bits = ty.bitSize(zcu);
435 assert(bit_offset + bit_count <= val_bits);437 assert(bit_offset + bit_count <= val_bits);
436438
437 switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {439 switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
...@@ -499,12 +501,12 @@ const PackValueBits = struct {...@@ -499,12 +501,12 @@ const PackValueBits = struct {
499 const len = ty.arrayLen(zcu);501 const len = ty.arrayLen(zcu);
500 const elem_ty = ty.childType(zcu);502 const elem_ty = ty.childType(zcu);
501 const maybe_sent = ty.sentinel(zcu);503 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);
503 const elems = try arena.alloc(InternPool.Index, @intCast(len));505 const elems = try arena.alloc(InternPool.Index, @intCast(len));
504506
505 if (endian == .big and maybe_sent != null) {507 if (endian == .big and maybe_sent != null) {
506 // TODO: validate sentinel was preserved!508 // TODO: validate sentinel was preserved!
507 try pack.padding(elem_ty.bitSize(pt));509 try pack.padding(elem_ty.bitSize(zcu));
508 if (len != 0) try pack.padding(pad_bits);510 if (len != 0) try pack.padding(pad_bits);
509 }511 }
510512
...@@ -520,7 +522,7 @@ const PackValueBits = struct {...@@ -520,7 +522,7 @@ const PackValueBits = struct {
520 if (endian == .little and maybe_sent != null) {522 if (endian == .little and maybe_sent != null) {
521 // TODO: validate sentinel was preserved!523 // TODO: validate sentinel was preserved!
522 if (len != 0) try pack.padding(pad_bits);524 if (len != 0) try pack.padding(pad_bits);
523 try pack.padding(elem_ty.bitSize(pt));525 try pack.padding(elem_ty.bitSize(zcu));
524 }526 }
525527
526 return Value.fromInterned(try pt.intern(.{ .aggregate = .{528 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
...@@ -538,23 +540,23 @@ const PackValueBits = struct {...@@ -538,23 +540,23 @@ const PackValueBits = struct {
538 var cur_bit_off: u64 = 0;540 var cur_bit_off: u64 = 0;
539 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrder(ip);541 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrder(ip);
540 while (it.next()) |field_idx| {542 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;
542 try pack.padding(want_bit_off - cur_bit_off);544 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);
544 elems[field_idx] = (try pack.get(field_ty)).toIntern();546 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);
546 }548 }
547 try pack.padding(ty.bitSize(pt) - cur_bit_off);549 try pack.padding(ty.bitSize(zcu) - cur_bit_off);
548 },550 },
549 .big => {551 .big => {
550 var cur_bit_off: u64 = ty.bitSize(pt);552 var cur_bit_off: u64 = ty.bitSize(zcu);
551 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrderReverse(ip);553 var it = zcu.typeToStruct(ty).?.iterateRuntimeOrderReverse(ip);
552 while (it.next()) |field_idx| {554 while (it.next()) |field_idx| {
553 const field_ty = ty.structFieldType(field_idx, zcu);555 const field_ty = ty.fieldType(field_idx, zcu);
554 const want_bit_off = ty.structFieldOffset(field_idx, pt) * 8 + field_ty.bitSize(pt);556 const want_bit_off = ty.structFieldOffset(field_idx, zcu) * 8 + field_ty.bitSize(zcu);
555 try pack.padding(cur_bit_off - want_bit_off);557 try pack.padding(cur_bit_off - want_bit_off);
556 elems[field_idx] = (try pack.get(field_ty)).toIntern();558 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);
558 }560 }
559 assert(cur_bit_off == 0);561 assert(cur_bit_off == 0);
560 },562 },
...@@ -576,7 +578,7 @@ const PackValueBits = struct {...@@ -576,7 +578,7 @@ const PackValueBits = struct {
576 // This is identical between LE and BE targets.578 // This is identical between LE and BE targets.
577 const elems = try arena.alloc(InternPool.Index, ty.structFieldCount(zcu));579 const elems = try arena.alloc(InternPool.Index, ty.structFieldCount(zcu));
578 for (elems, 0..) |*elem, i| {580 for (elems, 0..) |*elem, i| {
579 const field_ty = ty.structFieldType(i, zcu);581 const field_ty = ty.fieldType(i, zcu);
580 elem.* = (try pack.get(field_ty)).toIntern();582 elem.* = (try pack.get(field_ty)).toIntern();
581 }583 }
582 return Value.fromInterned(try pt.intern(.{ .aggregate = .{584 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
...@@ -622,16 +624,16 @@ const PackValueBits = struct {...@@ -622,16 +624,16 @@ const PackValueBits = struct {
622 for (field_order, 0..) |*f, i| f.* = @intCast(i);624 for (field_order, 0..) |*f, i| f.* = @intCast(i);
623 // Sort `field_order` to put the fields with the largest bit sizes first.625 // Sort `field_order` to put the fields with the largest bit sizes first.
624 const SizeSortCtx = struct {626 const SizeSortCtx = struct {
625 pt: Zcu.PerThread,627 zcu: *Zcu,
626 field_types: []const InternPool.Index,628 field_types: []const InternPool.Index,
627 fn lessThan(ctx: @This(), a_idx: u32, b_idx: u32) bool {629 fn lessThan(ctx: @This(), a_idx: u32, b_idx: u32) bool {
628 const a_ty = Type.fromInterned(ctx.field_types[a_idx]);630 const a_ty = Type.fromInterned(ctx.field_types[a_idx]);
629 const b_ty = Type.fromInterned(ctx.field_types[b_idx]);631 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);
631 }633 }
632 };634 };
633 std.mem.sortUnstable(u32, field_order, SizeSortCtx{635 std.mem.sortUnstable(u32, field_order, SizeSortCtx{
634 .pt = pt,636 .zcu = zcu,
635 .field_types = zcu.typeToUnion(ty).?.field_types.get(ip),637 .field_types = zcu.typeToUnion(ty).?.field_types.get(ip),
636 }, SizeSortCtx.lessThan);638 }, SizeSortCtx.lessThan);
637639
...@@ -639,7 +641,7 @@ const PackValueBits = struct {...@@ -639,7 +641,7 @@ const PackValueBits = struct {
639641
640 for (field_order) |field_idx| {642 for (field_order) |field_idx| {
641 const field_ty = Type.fromInterned(zcu.typeToUnion(ty).?.field_types.get(ip)[field_idx]);643 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);
643 if (!padding_after) try pack.padding(pad_bits);645 if (!padding_after) try pack.padding(pad_bits);
644 const field_val = pack.get(field_ty) catch |err| switch (err) {646 const field_val = pack.get(field_ty) catch |err| switch (err) {
645 error.ReinterpretDeclRef => {647 error.ReinterpretDeclRef => {
...@@ -682,10 +684,11 @@ const PackValueBits = struct {...@@ -682,10 +684,11 @@ const PackValueBits = struct {
682684
683 fn primitive(pack: *PackValueBits, want_ty: Type) BitCastError!Value {685 fn primitive(pack: *PackValueBits, want_ty: Type) BitCastError!Value {
684 const pt = pack.pt;686 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
687 for (vals) |val| {690 for (vals) |val| {
688 if (!Value.fromInterned(val).isUndef(pt.zcu)) break;691 if (!Value.fromInterned(val).isUndef(zcu)) break;
689 } else {692 } else {
690 // All bits of the value are `undefined`.693 // All bits of the value are `undefined`.
691 return pt.undefValue(want_ty);694 return pt.undefValue(want_ty);
...@@ -706,8 +709,8 @@ const PackValueBits = struct {...@@ -706,8 +709,8 @@ const PackValueBits = struct {
706 ptr_cast: {709 ptr_cast: {
707 if (vals.len != 1) break :ptr_cast;710 if (vals.len != 1) break :ptr_cast;
708 const val = Value.fromInterned(vals[0]);711 const val = Value.fromInterned(vals[0]);
709 if (!val.typeOf(pt.zcu).isPtrAtRuntime(pt.zcu)) break :ptr_cast;712 if (!val.typeOf(zcu).isPtrAtRuntime(zcu)) break :ptr_cast;
710 if (!want_ty.isPtrAtRuntime(pt.zcu)) break :ptr_cast;713 if (!want_ty.isPtrAtRuntime(zcu)) break :ptr_cast;
711 return pt.getCoerced(val, want_ty);714 return pt.getCoerced(val, want_ty);
712 }715 }
713716
...@@ -717,7 +720,7 @@ const PackValueBits = struct {...@@ -717,7 +720,7 @@ const PackValueBits = struct {
717 for (vals) |ip_val| {720 for (vals) |ip_val| {
718 const val = Value.fromInterned(ip_val);721 const val = Value.fromInterned(ip_val);
719 const ty = val.typeOf(pt.zcu);722 const ty = val.typeOf(pt.zcu);
720 buf_bits += ty.bitSize(pt);723 buf_bits += ty.bitSize(zcu);
721 }724 }
722725
723 const buf = try pack.arena.alloc(u8, @intCast((buf_bits + 7) / 8));726 const buf = try pack.arena.alloc(u8, @intCast((buf_bits + 7) / 8));
...@@ -726,11 +729,11 @@ const PackValueBits = struct {...@@ -726,11 +729,11 @@ const PackValueBits = struct {
726 var cur_bit_off: usize = 0;729 var cur_bit_off: usize = 0;
727 for (vals) |ip_val| {730 for (vals) |ip_val| {
728 const val = Value.fromInterned(ip_val);731 const val = Value.fromInterned(ip_val);
729 const ty = val.typeOf(pt.zcu);732 const ty = val.typeOf(zcu);
730 if (!val.isUndef(pt.zcu)) {733 if (!val.isUndef(zcu)) {
731 try val.writeToPackedMemory(ty, pt, buf, cur_bit_off);734 try val.writeToPackedMemory(ty, pt, buf, cur_bit_off);
732 }735 }
733 cur_bit_off += @intCast(ty.bitSize(pt));736 cur_bit_off += @intCast(ty.bitSize(zcu));
734 }737 }
735738
736 return Value.readFromPackedMemory(want_ty, pt, buf, @intCast(bit_offset), pack.arena);739 return Value.readFromPackedMemory(want_ty, pt, buf, @intCast(bit_offset), pack.arena);
...@@ -740,11 +743,12 @@ const PackValueBits = struct {...@@ -740,11 +743,12 @@ const PackValueBits = struct {
740 if (need_bits == 0) return .{ &.{}, 0 };743 if (need_bits == 0) return .{ &.{}, 0 };
741744
742 const pt = pack.pt;745 const pt = pack.pt;
746 const zcu = pt.zcu;
743747
744 var bits: u64 = 0;748 var bits: u64 = 0;
745 var len: usize = 0;749 var len: usize = 0;
746 while (bits < pack.bit_offset + need_bits) {750 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);
748 len += 1;752 len += 1;
749 }753 }
750754
...@@ -757,7 +761,7 @@ const PackValueBits = struct {...@@ -757,7 +761,7 @@ const PackValueBits = struct {
757 pack.bit_offset = 0;761 pack.bit_offset = 0;
758 } else {762 } else {
759 pack.unpacked = pack.unpacked[len - 1 ..];763 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;
761 }765 }
762766
763 return .{ result_vals, result_offset };767 return .{ result_vals, result_offset };
src/Sema/comptime_ptr_access.zig+29-28
...@@ -13,14 +13,15 @@ pub const ComptimeLoadResult = union(enum) {...@@ -13,14 +13,15 @@ pub const ComptimeLoadResult = union(enum) {
1313
14pub fn loadComptimePtr(sema: *Sema, block: *Block, src: LazySrcLoc, ptr: Value) !ComptimeLoadResult {14pub fn loadComptimePtr(sema: *Sema, block: *Block, src: LazySrcLoc, ptr: Value) !ComptimeLoadResult {
15 const pt = sema.pt;15 const pt = sema.pt;
16 const zcu = pt.zcu;
16 const ptr_info = ptr.typeOf(pt.zcu).ptrInfo(pt.zcu);17 const ptr_info = ptr.typeOf(pt.zcu).ptrInfo(pt.zcu);
17 // TODO: host size for vectors is terrible18 // TODO: host size for vectors is terrible
18 const host_bits = switch (ptr_info.flags.vector_index) {19 const host_bits = switch (ptr_info.flags.vector_index) {
19 .none => ptr_info.packed_offset.host_size * 8,20 .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),
21 };22 };
22 const bit_offset = if (host_bits != 0) bit_offset: {23 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);
24 const bit_offset = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {25 const bit_offset = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
25 .none => 0,26 .none => 0,
26 .runtime => return .runtime_load,27 .runtime => return .runtime_load,
...@@ -67,18 +68,18 @@ pub fn storeComptimePtr(...@@ -67,18 +68,18 @@ pub fn storeComptimePtr(
67 // TODO: host size for vectors is terrible68 // TODO: host size for vectors is terrible
68 const host_bits = switch (ptr_info.flags.vector_index) {69 const host_bits = switch (ptr_info.flags.vector_index) {
69 .none => ptr_info.packed_offset.host_size * 8,70 .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),
71 };72 };
72 const bit_offset = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {73 const bit_offset = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
73 .none => 0,74 .none => 0,
74 .runtime => return .runtime_store,75 .runtime => return .runtime_store,
75 else => |idx| switch (zcu.getTarget().cpu.arch.endian()) {76 else => |idx| switch (zcu.getTarget().cpu.arch.endian()) {
76 .little => Type.fromInterned(ptr_info.child).bitSize(pt) * @intFromEnum(idx),77 .little => Type.fromInterned(ptr_info.child).bitSize(zcu) * @intFromEnum(idx),
77 .big => host_bits - Type.fromInterned(ptr_info.child).bitSize(pt) * (@intFromEnum(idx) + 1), // element order reversed on big endian78 .big => host_bits - Type.fromInterned(ptr_info.child).bitSize(zcu) * (@intFromEnum(idx) + 1), // element order reversed on big endian
78 },79 },
79 };80 };
80 const pseudo_store_ty = if (host_bits > 0) t: {81 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);
82 if (need_bits + bit_offset > host_bits) {83 if (need_bits + bit_offset > host_bits) {
83 return .exceeds_host_size;84 return .exceeds_host_size;
84 }85 }
...@@ -166,9 +167,9 @@ pub fn storeComptimePtr(...@@ -166,9 +167,9 @@ pub fn storeComptimePtr(
166 .direct => |direct| .{ direct.val, 0 },167 .direct => |direct| .{ direct.val, 0 },
167 .index => |index| .{168 .index => |index| .{
168 index.val,169 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),
170 },171 },
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) },
172 .reinterpret => |reinterpret| .{ reinterpret.val, reinterpret.byte_offset },173 .reinterpret => |reinterpret| .{ reinterpret.val, reinterpret.byte_offset },
173 else => unreachable,174 else => unreachable,
174 };175 };
...@@ -347,8 +348,8 @@ fn loadComptimePtrInner(...@@ -347,8 +348,8 @@ fn loadComptimePtrInner(
347 const load_one_ty, const load_count = load_ty.arrayBase(zcu);348 const load_one_ty, const load_count = load_ty.arrayBase(zcu);
348349
349 const extra_base_index: u64 = if (ptr.byte_offset == 0) 0 else idx: {350 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 if (try load_one_ty.comptimeOnlySema(pt)) break :restructure_array;
351 const elem_len = try sema.typeAbiSize(load_one_ty);352 const elem_len = try load_one_ty.abiSizeSema(pt);
352 if (ptr.byte_offset % elem_len != 0) break :restructure_array;353 if (ptr.byte_offset % elem_len != 0) break :restructure_array;
353 break :idx @divExact(ptr.byte_offset, elem_len);354 break :idx @divExact(ptr.byte_offset, elem_len);
354 };355 };
...@@ -394,12 +395,12 @@ fn loadComptimePtrInner(...@@ -394,12 +395,12 @@ fn loadComptimePtrInner(
394 var cur_offset = ptr.byte_offset;395 var cur_offset = ptr.byte_offset;
395396
396 if (load_ty.zigTypeTag(zcu) == .Array and array_offset > 0) {397 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;
398 }399 }
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)) {
403 return .{ .out_of_bounds = cur_val.typeOf(zcu) };404 return .{ .out_of_bounds = cur_val.typeOf(zcu) };
404 }405 }
405406
...@@ -434,7 +435,7 @@ fn loadComptimePtrInner(...@@ -434,7 +435,7 @@ fn loadComptimePtrInner(
434 .Optional => break, // this can only be a pointer-like optional so is terminal435 .Optional => break, // this can only be a pointer-like optional so is terminal
435 .Array => {436 .Array => {
436 const elem_ty = cur_ty.childType(zcu);437 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);
438 const elem_idx = cur_offset / elem_size;439 const elem_idx = cur_offset / elem_size;
439 const next_elem_off = elem_size * (elem_idx + 1);440 const next_elem_off = elem_size * (elem_idx + 1);
440 if (cur_offset + need_bytes <= next_elem_off) {441 if (cur_offset + need_bytes <= next_elem_off) {
...@@ -449,8 +450,8 @@ fn loadComptimePtrInner(...@@ -449,8 +450,8 @@ fn loadComptimePtrInner(
449 .auto => unreachable, // ill-defined layout450 .auto => unreachable, // ill-defined layout
450 .@"packed" => break, // let the bitcast logic handle this451 .@"packed" => break, // let the bitcast logic handle this
451 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {452 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
452 const start_off = cur_ty.structFieldOffset(field_idx, pt);453 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
453 const end_off = start_off + try sema.typeAbiSize(cur_ty.structFieldType(field_idx, zcu));454 const end_off = start_off + try cur_ty.fieldType(field_idx, zcu).abiSizeSema(pt);
454 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {455 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
455 cur_val = try cur_val.getElem(sema.pt, field_idx);456 cur_val = try cur_val.getElem(sema.pt, field_idx);
456 cur_offset -= start_off;457 cur_offset -= start_off;
...@@ -477,7 +478,7 @@ fn loadComptimePtrInner(...@@ -477,7 +478,7 @@ fn loadComptimePtrInner(
477 };478 };
478 // The payload always has offset 0. If it's big enough479 // The payload always has offset 0. If it's big enough
479 // to represent the whole load type, we can use it.480 // 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) {
481 cur_val = payload;482 cur_val = payload;
482 } else {483 } else {
483 break;484 break;
...@@ -746,8 +747,8 @@ fn prepareComptimePtrStore(...@@ -746,8 +747,8 @@ fn prepareComptimePtrStore(
746747
747 const store_one_ty, const store_count = store_ty.arrayBase(zcu);748 const store_one_ty, const store_count = store_ty.arrayBase(zcu);
748 const extra_base_index: u64 = if (ptr.byte_offset == 0) 0 else idx: {749 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 if (try store_one_ty.comptimeOnlySema(pt)) break :restructure_array;
750 const elem_len = try sema.typeAbiSize(store_one_ty);751 const elem_len = try store_one_ty.abiSizeSema(pt);
751 if (ptr.byte_offset % elem_len != 0) break :restructure_array;752 if (ptr.byte_offset % elem_len != 0) break :restructure_array;
752 break :idx @divExact(ptr.byte_offset, elem_len);753 break :idx @divExact(ptr.byte_offset, elem_len);
753 };754 };
...@@ -800,11 +801,11 @@ fn prepareComptimePtrStore(...@@ -800,11 +801,11 @@ fn prepareComptimePtrStore(
800 var cur_val: *MutableValue, var cur_offset: u64 = switch (base_strat) {801 var cur_val: *MutableValue, var cur_offset: u64 = switch (base_strat) {
801 .direct => |direct| .{ direct.val, 0 },802 .direct => |direct| .{ direct.val, 0 },
802 // It's okay to do `abiSize` - the comptime-only case will be caught below.803 // 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) },
804 .flat_index => |flat_index| .{805 .flat_index => |flat_index| .{
805 flat_index.val,806 flat_index.val,
806 // It's okay to do `abiSize` - the comptime-only case will be caught below.807 // 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),
808 },809 },
809 .reinterpret => |r| .{ r.val, r.byte_offset },810 .reinterpret => |r| .{ r.val, r.byte_offset },
810 else => unreachable,811 else => unreachable,
...@@ -816,12 +817,12 @@ fn prepareComptimePtrStore(...@@ -816,12 +817,12 @@ fn prepareComptimePtrStore(
816 }817 }
817818
818 if (store_ty.zigTypeTag(zcu) == .Array and array_offset > 0) {819 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;
820 }821 }
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)) {
825 return .{ .out_of_bounds = cur_val.typeOf(zcu) };826 return .{ .out_of_bounds = cur_val.typeOf(zcu) };
826 }827 }
827828
...@@ -856,7 +857,7 @@ fn prepareComptimePtrStore(...@@ -856,7 +857,7 @@ fn prepareComptimePtrStore(
856 .Optional => break, // this can only be a pointer-like optional so is terminal857 .Optional => break, // this can only be a pointer-like optional so is terminal
857 .Array => {858 .Array => {
858 const elem_ty = cur_ty.childType(zcu);859 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);
860 const elem_idx = cur_offset / elem_size;861 const elem_idx = cur_offset / elem_size;
861 const next_elem_off = elem_size * (elem_idx + 1);862 const next_elem_off = elem_size * (elem_idx + 1);
862 if (cur_offset + need_bytes <= next_elem_off) {863 if (cur_offset + need_bytes <= next_elem_off) {
...@@ -871,8 +872,8 @@ fn prepareComptimePtrStore(...@@ -871,8 +872,8 @@ fn prepareComptimePtrStore(
871 .auto => unreachable, // ill-defined layout872 .auto => unreachable, // ill-defined layout
872 .@"packed" => break, // let the bitcast logic handle this873 .@"packed" => break, // let the bitcast logic handle this
873 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {874 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
874 const start_off = cur_ty.structFieldOffset(field_idx, pt);875 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
875 const end_off = start_off + try sema.typeAbiSize(cur_ty.structFieldType(field_idx, zcu));876 const end_off = start_off + try cur_ty.fieldType(field_idx, zcu).abiSizeSema(pt);
876 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {877 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
877 cur_val = try cur_val.elem(pt, sema.arena, field_idx);878 cur_val = try cur_val.elem(pt, sema.arena, field_idx);
878 cur_offset -= start_off;879 cur_offset -= start_off;
...@@ -895,7 +896,7 @@ fn prepareComptimePtrStore(...@@ -895,7 +896,7 @@ fn prepareComptimePtrStore(
895 };896 };
896 // The payload always has offset 0. If it's big enough897 // The payload always has offset 0. If it's big enough
897 // to represent the whole load type, we can use it.898 // 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) {
899 cur_val = payload;900 cur_val = payload;
900 } else {901 } else {
901 break;902 break;
src/Type.zig+836-525
...@@ -10,8 +10,6 @@ const Value = @import("Value.zig");...@@ -10,8 +10,6 @@ const Value = @import("Value.zig");
10const assert = std.debug.assert;10const assert = std.debug.assert;
11const Target = std.Target;11const Target = std.Target;
12const Zcu = @import("Zcu.zig");12const Zcu = @import("Zcu.zig");
13/// Deprecated.
14const Module = Zcu;
15const log = std.log.scoped(.Type);13const log = std.log.scoped(.Type);
16const target_util = @import("target.zig");14const target_util = @import("target.zig");
17const Sema = @import("Sema.zig");15const Sema = @import("Sema.zig");
...@@ -23,15 +21,15 @@ const SemaError = Zcu.SemaError;...@@ -23,15 +21,15 @@ const SemaError = Zcu.SemaError;
2321
24ip_index: InternPool.Index,22ip_index: InternPool.Index,
2523
26pub fn zigTypeTag(ty: Type, mod: *const Module) std.builtin.TypeId {24pub fn zigTypeTag(ty: Type, zcu: *const Zcu) std.builtin.TypeId {
27 return ty.zigTypeTagOrPoison(mod) catch unreachable;25 return ty.zigTypeTagOrPoison(zcu) catch unreachable;
28}26}
2927
30pub fn zigTypeTagOrPoison(ty: Type, mod: *const Module) error{GenericPoison}!std.builtin.TypeId {28pub fn zigTypeTagOrPoison(ty: Type, zcu: *const Zcu) error{GenericPoison}!std.builtin.TypeId {
31 return mod.intern_pool.zigTypeTagOrPoison(ty.toIntern());29 return zcu.intern_pool.zigTypeTagOrPoison(ty.toIntern());
32}30}
3331
34pub fn baseZigTypeTag(self: Type, mod: *Module) std.builtin.TypeId {32pub fn baseZigTypeTag(self: Type, mod: *Zcu) std.builtin.TypeId {
35 return switch (self.zigTypeTag(mod)) {33 return switch (self.zigTypeTag(mod)) {
36 .ErrorUnion => self.errorUnionPayload(mod).baseZigTypeTag(mod),34 .ErrorUnion => self.errorUnionPayload(mod).baseZigTypeTag(mod),
37 .Optional => {35 .Optional => {
...@@ -41,15 +39,15 @@ pub fn baseZigTypeTag(self: Type, mod: *Module) std.builtin.TypeId {...@@ -41,15 +39,15 @@ pub fn baseZigTypeTag(self: Type, mod: *Module) std.builtin.TypeId {
41 };39 };
42}40}
4341
44pub fn isSelfComparable(ty: Type, mod: *const Module, is_equality_cmp: bool) bool {42pub fn isSelfComparable(ty: Type, zcu: *const Zcu, is_equality_cmp: bool) bool {
45 return switch (ty.zigTypeTag(mod)) {43 return switch (ty.zigTypeTag(zcu)) {
46 .Int,44 .Int,
47 .Float,45 .Float,
48 .ComptimeFloat,46 .ComptimeFloat,
49 .ComptimeInt,47 .ComptimeInt,
50 => true,48 => true,
5149
52 .Vector => ty.elemType2(mod).isSelfComparable(mod, is_equality_cmp),50 .Vector => ty.elemType2(zcu).isSelfComparable(zcu, is_equality_cmp),
5351
54 .Bool,52 .Bool,
55 .Type,53 .Type,
...@@ -72,25 +70,25 @@ pub fn isSelfComparable(ty: Type, mod: *const Module, is_equality_cmp: bool) boo...@@ -72,25 +70,25 @@ pub fn isSelfComparable(ty: Type, mod: *const Module, is_equality_cmp: bool) boo
72 .Frame,70 .Frame,
73 => false,71 => 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)),
76 .Optional => {74 .Optional => {
77 if (!is_equality_cmp) return false;75 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);
79 },77 },
80 };78 };
81}79}
8280
83/// If it is a function pointer, returns the function type. Otherwise returns null.81/// If it is a function pointer, returns the function type. Otherwise returns null.
84pub fn castPtrToFn(ty: Type, mod: *const Module) ?Type {82pub fn castPtrToFn(ty: Type, zcu: *const Zcu) ?Type {
85 if (ty.zigTypeTag(mod) != .Pointer) return null;83 if (ty.zigTypeTag(zcu) != .Pointer) return null;
86 const elem_ty = ty.childType(mod);84 const elem_ty = ty.childType(zcu);
87 if (elem_ty.zigTypeTag(mod) != .Fn) return null;85 if (elem_ty.zigTypeTag(zcu) != .Fn) return null;
88 return elem_ty;86 return elem_ty;
89}87}
9088
91/// Asserts the type is a pointer.89/// Asserts the type is a pointer.
92pub fn ptrIsMutable(ty: Type, mod: *const Module) bool {90pub fn ptrIsMutable(ty: Type, zcu: *const Zcu) bool {
93 return !mod.intern_pool.indexToKey(ty.toIntern()).ptr_type.flags.is_const;91 return !zcu.intern_pool.indexToKey(ty.toIntern()).ptr_type.flags.is_const;
94}92}
9593
96pub const ArrayInfo = struct {94pub const ArrayInfo = struct {
...@@ -99,18 +97,18 @@ pub const ArrayInfo = struct {...@@ -99,18 +97,18 @@ pub const ArrayInfo = struct {
99 len: u64,97 len: u64,
100};98};
10199
102pub fn arrayInfo(self: Type, mod: *const Module) ArrayInfo {100pub fn arrayInfo(self: Type, zcu: *const Zcu) ArrayInfo {
103 return .{101 return .{
104 .len = self.arrayLen(mod),102 .len = self.arrayLen(zcu),
105 .sentinel = self.sentinel(mod),103 .sentinel = self.sentinel(zcu),
106 .elem_type = self.childType(mod),104 .elem_type = self.childType(zcu),
107 };105 };
108}106}
109107
110pub fn ptrInfo(ty: Type, mod: *const Module) InternPool.Key.PtrType {108pub fn ptrInfo(ty: Type, zcu: *const Zcu) InternPool.Key.PtrType {
111 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {109 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
112 .ptr_type => |p| p,110 .ptr_type => |p| p,
113 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {111 .opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) {
114 .ptr_type => |p| p,112 .ptr_type => |p| p,
115 else => unreachable,113 else => unreachable,
116 },114 },
...@@ -118,8 +116,8 @@ pub fn ptrInfo(ty: Type, mod: *const Module) InternPool.Key.PtrType {...@@ -118,8 +116,8 @@ pub fn ptrInfo(ty: Type, mod: *const Module) InternPool.Key.PtrType {
118 };116 };
119}117}
120118
121pub fn eql(a: Type, b: Type, mod: *const Module) bool {119pub fn eql(a: Type, b: Type, zcu: *const Zcu) bool {
122 _ = mod; // TODO: remove this parameter120 _ = zcu; // TODO: remove this parameter
123 // The InternPool data structure hashes based on Key to make interned objects121 // The InternPool data structure hashes based on Key to make interned objects
124 // unique. An Index can be treated simply as u32 value for the122 // unique. An Index can be treated simply as u32 value for the
125 // purpose of Type/Value hashing and equality.123 // purpose of Type/Value hashing and equality.
...@@ -179,8 +177,8 @@ pub fn dump(...@@ -179,8 +177,8 @@ pub fn dump(
179/// Prints a name suitable for `@typeName`.177/// Prints a name suitable for `@typeName`.
180/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.178/// TODO: take an `opt_sema` to pass to `fmtValue` when printing sentinels.
181pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error!void {179pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error!void {
182 const mod = pt.zcu;180 const zcu = pt.zcu;
183 const ip = &mod.intern_pool;181 const ip = &zcu.intern_pool;
184 switch (ip.indexToKey(ty.toIntern())) {182 switch (ip.indexToKey(ty.toIntern())) {
185 .int_type => |int_type| {183 .int_type => |int_type| {
186 const sign_char: u8 = switch (int_type.signedness) {184 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...@@ -190,7 +188,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
190 return writer.print("{c}{d}", .{ sign_char, int_type.bits });188 return writer.print("{c}{d}", .{ sign_char, int_type.bits });
191 },189 },
192 .ptr_type => {190 .ptr_type => {
193 const info = ty.ptrInfo(mod);191 const info = ty.ptrInfo(zcu);
194192
195 if (info.sentinel != .none) switch (info.flags.size) {193 if (info.sentinel != .none) switch (info.flags.size) {
196 .One, .C => unreachable,194 .One, .C => unreachable,
...@@ -210,7 +208,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -210,7 +208,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
210 const alignment = if (info.flags.alignment != .none)208 const alignment = if (info.flags.alignment != .none)
211 info.flags.alignment209 info.flags.alignment
212 else210 else
213 Type.fromInterned(info.child).abiAlignment(pt);211 Type.fromInterned(info.child).abiAlignment(pt.zcu);
214 try writer.print("align({d}", .{alignment.toByteUnits() orelse 0});212 try writer.print("align({d}", .{alignment.toByteUnits() orelse 0});
215213
216 if (info.packed_offset.bit_offset != 0 or info.packed_offset.host_size != 0) {214 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...@@ -268,7 +266,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
268 return;266 return;
269 },267 },
270 .inferred_error_set_type => |func_index| {268 .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);
272 try writer.print("@typeInfo(@typeInfo(@TypeOf({})).Fn.return_type.?).ErrorUnion.error_set", .{270 try writer.print("@typeInfo(@typeInfo(@TypeOf({})).Fn.return_type.?).ErrorUnion.error_set", .{
273 func_nav.fqn.fmt(ip),271 func_nav.fqn.fmt(ip),
274 });272 });
...@@ -338,7 +336,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error...@@ -338,7 +336,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
338 try writer.writeAll("comptime ");336 try writer.writeAll("comptime ");
339 }337 }
340 if (anon_struct.names.len != 0) {338 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)});
342 }340 }
343341
344 try print(Type.fromInterned(field_ty), writer, pt);342 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...@@ -367,7 +365,7 @@ pub fn print(ty: Type, writer: anytype, pt: Zcu.PerThread) @TypeOf(writer).Error
367 try writer.writeAll("noinline ");365 try writer.writeAll("noinline ");
368 }366 }
369 try writer.writeAll("fn (");367 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);
371 for (param_types, 0..) |param_ty, i| {369 for (param_types, 0..) |param_ty, i| {
372 if (i != 0) try writer.writeAll(", ");370 if (i != 0) try writer.writeAll(", ");
373 if (std.math.cast(u5, i)) |index| {371 if (std.math.cast(u5, i)) |index| {
...@@ -448,6 +446,21 @@ pub fn toValue(self: Type) Value {...@@ -448,6 +446,21 @@ pub fn toValue(self: Type) Value {
448446
449const RuntimeBitsError = SemaError || error{NeedLazy};447const 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
451/// true if and only if the type takes up space in memory at runtime.464/// true if and only if the type takes up space in memory at runtime.
452/// There are two reasons a type will return false:465/// There are two reasons a type will return false:
453/// * the type is a comptime-only type. For example, the type `type` itself.466/// * the type is a comptime-only type. For example, the type `type` itself.
...@@ -459,14 +472,14 @@ const RuntimeBitsError = SemaError || error{NeedLazy};...@@ -459,14 +472,14 @@ const RuntimeBitsError = SemaError || error{NeedLazy};
459/// making it one-possible-value only if the integer tag type has 0 bits.472/// making it one-possible-value only if the integer tag type has 0 bits.
460/// When `ignore_comptime_only` is true, then types that are comptime-only473/// When `ignore_comptime_only` is true, then types that are comptime-only
461/// may return false positives.474/// may return false positives.
462pub fn hasRuntimeBitsAdvanced(475pub fn hasRuntimeBitsInner(
463 ty: Type,476 ty: Type,
464 pt: Zcu.PerThread,
465 ignore_comptime_only: bool,477 ignore_comptime_only: bool,
466 comptime strat: ResolveStratLazy,478 comptime strat: ResolveStratLazy,
479 zcu: *Zcu,
480 tid: strat.Tid(),
467) RuntimeBitsError!bool {481) RuntimeBitsError!bool {
468 const mod = pt.zcu;482 const ip = &zcu.intern_pool;
469 const ip = &mod.intern_pool;
470 return switch (ty.toIntern()) {483 return switch (ty.toIntern()) {
471 // False because it is a comptime-only type.484 // False because it is a comptime-only type.
472 .empty_struct_type => false,485 .empty_struct_type => false,
...@@ -477,26 +490,29 @@ pub fn hasRuntimeBitsAdvanced(...@@ -477,26 +490,29 @@ pub fn hasRuntimeBitsAdvanced(
477 // to comptime-only types do not, with the exception of function pointers.490 // to comptime-only types do not, with the exception of function pointers.
478 if (ignore_comptime_only) return true;491 if (ignore_comptime_only) return true;
479 return switch (strat) {492 return switch (strat) {
480 .sema => !try ty.comptimeOnlyAdvanced(pt, .sema),493 .sema => {
481 .eager => !ty.comptimeOnly(pt),494 const pt = strat.pt(zcu, tid);
495 return !try ty.comptimeOnlySema(pt);
496 },
497 .eager => !ty.comptimeOnly(zcu),
482 .lazy => error.NeedLazy,498 .lazy => error.NeedLazy,
483 };499 };
484 },500 },
485 .anyframe_type => true,501 .anyframe_type => true,
486 .array_type => |array_type| return array_type.lenIncludingSentinel() > 0 and502 .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),
488 .vector_type => |vector_type| return vector_type.len > 0 and504 .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),
490 .opt_type => |child| {506 .opt_type => |child| {
491 const child_ty = Type.fromInterned(child);507 const child_ty = Type.fromInterned(child);
492 if (child_ty.isNoReturn(mod)) {508 if (child_ty.isNoReturn(zcu)) {
493 // Then the optional is comptime-known to be null.509 // Then the optional is comptime-known to be null.
494 return false;510 return false;
495 }511 }
496 if (ignore_comptime_only) return true;512 if (ignore_comptime_only) return true;
497 return switch (strat) {513 return switch (strat) {
498 .sema => !try child_ty.comptimeOnlyAdvanced(pt, .sema),514 .sema => !try child_ty.comptimeOnlyInner(.sema, zcu, tid),
499 .eager => !child_ty.comptimeOnly(pt),515 .eager => !child_ty.comptimeOnly(zcu),
500 .lazy => error.NeedLazy,516 .lazy => error.NeedLazy,
501 };517 };
502 },518 },
...@@ -556,14 +572,14 @@ pub fn hasRuntimeBitsAdvanced(...@@ -556,14 +572,14 @@ pub fn hasRuntimeBitsAdvanced(
556 return true;572 return true;
557 }573 }
558 switch (strat) {574 switch (strat) {
559 .sema => try ty.resolveFields(pt),575 .sema => try ty.resolveFields(strat.pt(zcu, tid)),
560 .eager => assert(struct_type.haveFieldTypes(ip)),576 .eager => assert(struct_type.haveFieldTypes(ip)),
561 .lazy => if (!struct_type.haveFieldTypes(ip)) return error.NeedLazy,577 .lazy => if (!struct_type.haveFieldTypes(ip)) return error.NeedLazy,
562 }578 }
563 for (0..struct_type.field_types.len) |i| {579 for (0..struct_type.field_types.len) |i| {
564 if (struct_type.comptime_bits.getBit(ip, i)) continue;580 if (struct_type.comptime_bits.getBit(ip, i)) continue;
565 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);581 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))
567 return true;583 return true;
568 } else {584 } else {
569 return false;585 return false;
...@@ -572,7 +588,12 @@ pub fn hasRuntimeBitsAdvanced(...@@ -572,7 +588,12 @@ pub fn hasRuntimeBitsAdvanced(
572 .anon_struct_type => |tuple| {588 .anon_struct_type => |tuple| {
573 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {589 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
574 if (val != .none) continue; // comptime field590 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;
576 }597 }
577 return false;598 return false;
578 },599 },
...@@ -591,21 +612,25 @@ pub fn hasRuntimeBitsAdvanced(...@@ -591,21 +612,25 @@ pub fn hasRuntimeBitsAdvanced(
591 // tag_ty will be `none` if this union's tag type is not resolved yet,612 // tag_ty will be `none` if this union's tag type is not resolved yet,
592 // in which case we want control flow to continue down below.613 // in which case we want control flow to continue down below.
593 if (tag_ty != .none and614 if (tag_ty != .none and
594 try Type.fromInterned(tag_ty).hasRuntimeBitsAdvanced(pt, ignore_comptime_only, strat))615 try Type.fromInterned(tag_ty).hasRuntimeBitsInner(
595 {616 ignore_comptime_only,
617 strat,
618 zcu,
619 tid,
620 )) {
596 return true;621 return true;
597 }622 }
598 },623 },
599 }624 }
600 switch (strat) {625 switch (strat) {
601 .sema => try ty.resolveFields(pt),626 .sema => try ty.resolveFields(strat.pt(zcu, tid)),
602 .eager => assert(union_flags.status.haveFieldTypes()),627 .eager => assert(union_flags.status.haveFieldTypes()),
603 .lazy => if (!union_flags.status.haveFieldTypes())628 .lazy => if (!union_flags.status.haveFieldTypes())
604 return error.NeedLazy,629 return error.NeedLazy,
605 }630 }
606 for (0..union_type.field_types.len) |field_index| {631 for (0..union_type.field_types.len) |field_index| {
607 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);632 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))
609 return true;634 return true;
610 } else {635 } else {
611 return false;636 return false;
...@@ -613,7 +638,12 @@ pub fn hasRuntimeBitsAdvanced(...@@ -613,7 +638,12 @@ pub fn hasRuntimeBitsAdvanced(
613 },638 },
614639
615 .opaque_type => true,640 .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
618 // values, not types648 // values, not types
619 .undef,649 .undef,
...@@ -643,8 +673,8 @@ pub fn hasRuntimeBitsAdvanced(...@@ -643,8 +673,8 @@ pub fn hasRuntimeBitsAdvanced(
643/// true if and only if the type has a well-defined memory layout673/// true if and only if the type has a well-defined memory layout
644/// readFrom/writeToMemory are supported only for types with a well-674/// readFrom/writeToMemory are supported only for types with a well-
645/// defined memory layout675/// defined memory layout
646pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {676pub fn hasWellDefinedLayout(ty: Type, zcu: *const Zcu) bool {
647 const ip = &mod.intern_pool;677 const ip = &zcu.intern_pool;
648 return switch (ip.indexToKey(ty.toIntern())) {678 return switch (ip.indexToKey(ty.toIntern())) {
649 .int_type,679 .int_type,
650 .vector_type,680 .vector_type,
...@@ -660,8 +690,8 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {...@@ -660,8 +690,8 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
660 .func_type,690 .func_type,
661 => false,691 => false,
662692
663 .array_type => |array_type| Type.fromInterned(array_type.child).hasWellDefinedLayout(mod),693 .array_type => |array_type| Type.fromInterned(array_type.child).hasWellDefinedLayout(zcu),
664 .opt_type => ty.isPtrLikeOptional(mod),694 .opt_type => ty.isPtrLikeOptional(zcu),
665 .ptr_type => |ptr_type| ptr_type.flags.size != .Slice,695 .ptr_type => |ptr_type| ptr_type.flags.size != .Slice,
666696
667 .simple_type => |t| switch (t) {697 .simple_type => |t| switch (t) {
...@@ -740,94 +770,99 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {...@@ -740,94 +770,99 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
740 };770 };
741}771}
742772
743pub fn hasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool {773pub fn fnHasRuntimeBits(ty: Type, zcu: *Zcu) bool {
744 return hasRuntimeBitsAdvanced(ty, pt, false, .eager) catch unreachable;774 return ty.fnHasRuntimeBitsInner(.normal, zcu, {}) catch unreachable;
745}
746
747pub fn hasRuntimeBitsIgnoreComptime(ty: Type, pt: Zcu.PerThread) bool {
748 return hasRuntimeBitsAdvanced(ty, pt, true, .eager) catch unreachable;
749}775}
750776
751pub fn fnHasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool {777pub fn fnHasRuntimeBitsSema(ty: Type, pt: Zcu.PerThread) SemaError!bool {
752 return ty.fnHasRuntimeBitsAdvanced(pt, .normal) catch unreachable;778 return try ty.fnHasRuntimeBitsInner(.sema, pt.zcu, pt.tid);
753}779}
754780
755/// Determines whether a function type has runtime bits, i.e. whether a781/// Determines whether a function type has runtime bits, i.e. whether a
756/// function with this type can exist at runtime.782/// function with this type can exist at runtime.
757/// Asserts that `ty` is a function type.783/// Asserts that `ty` is a function type.
758pub fn fnHasRuntimeBitsAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) SemaError!bool {784pub fn fnHasRuntimeBitsInner(
759 const fn_info = pt.zcu.typeToFunc(ty).?;785 ty: Type,
786 comptime strat: ResolveStrat,
787 zcu: *Zcu,
788 tid: strat.Tid(),
789) SemaError!bool {
790 const fn_info = zcu.typeToFunc(ty).?;
760 if (fn_info.is_generic) return false;791 if (fn_info.is_generic) return false;
761 if (fn_info.is_var_args) return true;792 if (fn_info.is_var_args) return true;
762 if (fn_info.cc == .Inline) return false;793 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);
764}795}
765796
766pub fn isFnOrHasRuntimeBits(ty: Type, pt: Zcu.PerThread) bool {797pub fn isFnOrHasRuntimeBits(ty: Type, zcu: *Zcu) bool {
767 switch (ty.zigTypeTag(pt.zcu)) {798 switch (ty.zigTypeTag(zcu)) {
768 .Fn => return ty.fnHasRuntimeBits(pt),799 .Fn => return ty.fnHasRuntimeBits(zcu),
769 else => return ty.hasRuntimeBits(pt),800 else => return ty.hasRuntimeBits(zcu),
770 }801 }
771}802}
772803
773/// Same as `isFnOrHasRuntimeBits` but comptime-only types may return a false positive.804/// Same as `isFnOrHasRuntimeBits` but comptime-only types may return a false positive.
774pub fn isFnOrHasRuntimeBitsIgnoreComptime(ty: Type, pt: Zcu.PerThread) bool {805pub fn isFnOrHasRuntimeBitsIgnoreComptime(ty: Type, zcu: *Zcu) bool {
775 return switch (ty.zigTypeTag(pt.zcu)) {806 return switch (ty.zigTypeTag(zcu)) {
776 .Fn => true,807 .Fn => true,
777 else => return ty.hasRuntimeBitsIgnoreComptime(pt),808 else => return ty.hasRuntimeBitsIgnoreComptime(zcu),
778 };809 };
779}810}
780811
781pub fn isNoReturn(ty: Type, mod: *Module) bool {812pub fn isNoReturn(ty: Type, zcu: *const Zcu) bool {
782 return mod.intern_pool.isNoReturn(ty.toIntern());813 return zcu.intern_pool.isNoReturn(ty.toIntern());
783}814}
784815
785/// Returns `none` if the pointer is naturally aligned and the element type is 0-bit.816/// Returns `none` if the pointer is naturally aligned and the element type is 0-bit.
786pub fn ptrAlignment(ty: Type, pt: Zcu.PerThread) Alignment {817pub fn ptrAlignment(ty: Type, zcu: *Zcu) Alignment {
787 return ptrAlignmentAdvanced(ty, pt, .normal) catch unreachable;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);
788}823}
789824
790pub fn ptrAlignmentAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment {825pub fn ptrAlignmentInner(
791 return switch (pt.zcu.intern_pool.indexToKey(ty.toIntern())) {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())) {
792 .ptr_type => |ptr_type| {832 .ptr_type => |ptr_type| {
793 if (ptr_type.flags.alignment != .none)833 if (ptr_type.flags.alignment != .none)
794 return ptr_type.flags.alignment;834 return ptr_type.flags.alignment;
795835
796 if (strat == .sema) {836 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);
798 return res.scalar;838 return res.scalar;
799 }839 }
800840
801 return (Type.fromInterned(ptr_type.child).abiAlignmentAdvanced(pt, .eager) catch unreachable).scalar;841 return Type.fromInterned(ptr_type.child).abiAlignment(zcu);
802 },842 },
803 .opt_type => |child| Type.fromInterned(child).ptrAlignmentAdvanced(pt, strat),843 .opt_type => |child| Type.fromInterned(child).ptrAlignmentInner(strat, zcu, tid),
804 else => unreachable,844 else => unreachable,
805 };845 };
806}846}
807847
808pub fn ptrAddressSpace(ty: Type, mod: *const Module) std.builtin.AddressSpace {848pub fn ptrAddressSpace(ty: Type, zcu: *const Zcu) std.builtin.AddressSpace {
809 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {849 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
810 .ptr_type => |ptr_type| ptr_type.flags.address_space,850 .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,
812 else => unreachable,852 else => unreachable,
813 };853 };
814}854}
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
821/// May capture a reference to `ty`.856/// May capture a reference to `ty`.
822/// Returned value has type `comptime_int`.857/// Returned value has type `comptime_int`.
823pub fn lazyAbiAlignment(ty: Type, pt: Zcu.PerThread) !Value {858pub 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)) {
825 .val => |val| return val,860 .val => |val| return val,
826 .scalar => |x| return pt.intValue(Type.comptime_int, x.toByteUnits() orelse 0),861 .scalar => |x| return pt.intValue(Type.comptime_int, x.toByteUnits() orelse 0),
827 }862 }
828}863}
829864
830pub const AbiAlignmentAdvanced = union(enum) {865pub const AbiAlignmentInner = union(enum) {
831 scalar: Alignment,866 scalar: Alignment,
832 val: Value,867 val: Value,
833};868};
...@@ -842,6 +877,23 @@ pub const ResolveStratLazy = enum {...@@ -842,6 +877,23 @@ pub const ResolveStratLazy = enum {
842 /// Return a scalar result, performing type resolution as necessary.877 /// Return a scalar result, performing type resolution as necessary.
843 /// This should typically be used from semantic analysis.878 /// This should typically be used from semantic analysis.
844 sema,879 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 }
845};897};
846898
847/// The chosen strategy can be easily optimized away in release builds.899/// The chosen strategy can be easily optimized away in release builds.
...@@ -854,6 +906,23 @@ pub const ResolveStrat = enum {...@@ -854,6 +906,23 @@ pub const ResolveStrat = enum {
854 /// This should typically be used from semantic analysis.906 /// This should typically be used from semantic analysis.
855 sema,907 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
857 pub inline fn toLazy(strat: ResolveStrat) ResolveStratLazy {926 pub inline fn toLazy(strat: ResolveStrat) ResolveStratLazy {
858 return switch (strat) {927 return switch (strat) {
859 .normal => .eager,928 .normal => .eager,
...@@ -862,21 +931,31 @@ pub const ResolveStrat = enum {...@@ -862,21 +931,31 @@ pub const ResolveStrat = enum {
862 }931 }
863};932};
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
865/// If you pass `eager` you will get back `scalar` and assert the type is resolved.943/// If you pass `eager` you will get back `scalar` and assert the type is resolved.
866/// In this case there will be no error, guaranteed.944/// In this case there will be no error, guaranteed.
867/// If you pass `lazy` you may get back `scalar` or `val`.945/// If you pass `lazy` you may get back `scalar` or `val`.
868/// If `val` is returned, a reference to `ty` has been captured.946/// If `val` is returned, a reference to `ty` has been captured.
869/// If you pass `sema` you will get back `scalar` and resolve the type if947/// If you pass `sema` you will get back `scalar` and resolve the type if
870/// necessary, possibly returning a CompileError.948/// necessary, possibly returning a CompileError.
871pub fn abiAlignmentAdvanced(949pub fn abiAlignmentInner(
872 ty: Type,950 ty: Type,
873 pt: Zcu.PerThread,
874 comptime strat: ResolveStratLazy,951 comptime strat: ResolveStratLazy,
875) SemaError!AbiAlignmentAdvanced {952 zcu: *Zcu,
876 const mod = pt.zcu;953 tid: strat.Tid(),
877 const target = mod.getTarget();954) SemaError!AbiAlignmentInner {
878 const use_llvm = mod.comp.config.use_llvm;955 const pt = strat.pt(zcu, tid);
879 const ip = &mod.intern_pool;956 const target = zcu.getTarget();
957 const use_llvm = zcu.comp.config.use_llvm;
958 const ip = &zcu.intern_pool;
880959
881 switch (ty.toIntern()) {960 switch (ty.toIntern()) {
882 .empty_struct_type => return .{ .scalar = .@"1" },961 .empty_struct_type => return .{ .scalar = .@"1" },
...@@ -889,22 +968,22 @@ pub fn abiAlignmentAdvanced(...@@ -889,22 +968,22 @@ pub fn abiAlignmentAdvanced(
889 return .{ .scalar = ptrAbiAlignment(target) };968 return .{ .scalar = ptrAbiAlignment(target) };
890 },969 },
891 .array_type => |array_type| {970 .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);
893 },972 },
894 .vector_type => |vector_type| {973 .vector_type => |vector_type| {
895 if (vector_type.len == 0) return .{ .scalar = .@"1" };974 if (vector_type.len == 0) return .{ .scalar = .@"1" };
896 switch (mod.comp.getZigBackend()) {975 switch (zcu.comp.getZigBackend()) {
897 else => {976 else => {
898 // This is fine because the child type of a vector always has a bit-size known977 // This is fine because the child type of a vector always has a bit-size known
899 // without needing any type resolution.978 // 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));
901 if (elem_bits == 0) return .{ .scalar = .@"1" };980 if (elem_bits == 0) return .{ .scalar = .@"1" };
902 const bytes = ((elem_bits * vector_type.len) + 7) / 8;981 const bytes = ((elem_bits * vector_type.len) + 7) / 8;
903 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);982 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
904 return .{ .scalar = Alignment.fromByteUnits(alignment) };983 return .{ .scalar = Alignment.fromByteUnits(alignment) };
905 },984 },
906 .stage2_c => {985 .stage2_c => {
907 return Type.fromInterned(vector_type.child).abiAlignmentAdvanced(pt, strat);986 return Type.fromInterned(vector_type.child).abiAlignmentInner(strat, zcu, tid);
908 },987 },
909 .stage2_x86_64 => {988 .stage2_x86_64 => {
910 if (vector_type.child == .bool_type) {989 if (vector_type.child == .bool_type) {
...@@ -915,7 +994,7 @@ pub fn abiAlignmentAdvanced(...@@ -915,7 +994,7 @@ pub fn abiAlignmentAdvanced(
915 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);994 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
916 return .{ .scalar = Alignment.fromByteUnits(alignment) };995 return .{ .scalar = Alignment.fromByteUnits(alignment) };
917 }996 }
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);
919 if (elem_bytes == 0) return .{ .scalar = .@"1" };998 if (elem_bytes == 0) return .{ .scalar = .@"1" };
920 const bytes = elem_bytes * vector_type.len;999 const bytes = elem_bytes * vector_type.len;
921 if (bytes > 32 and std.Target.x86.featureSetHas(target.cpu.features, .avx512f)) return .{ .scalar = .@"64" };1000 if (bytes > 32 and std.Target.x86.featureSetHas(target.cpu.features, .avx512f)) return .{ .scalar = .@"64" };
...@@ -925,11 +1004,16 @@ pub fn abiAlignmentAdvanced(...@@ -925,11 +1004,16 @@ pub fn abiAlignmentAdvanced(
925 }1004 }
926 },1005 },
9271006
928 .opt_type => return ty.abiAlignmentAdvancedOptional(pt, strat),1007 .opt_type => return ty.abiAlignmentInnerOptional(strat, zcu, tid),
929 .error_union_type => |info| return ty.abiAlignmentAdvancedErrorUnion(pt, strat, Type.fromInterned(info.payload_type)),1008 .error_union_type => |info| return ty.abiAlignmentInnerErrorUnion(
1009 strat,
1010 zcu,
1011 tid,
1012 Type.fromInterned(info.payload_type),
1013 ),
9301014
931 .error_set_type, .inferred_error_set_type => {1015 .error_set_type, .inferred_error_set_type => {
932 const bits = mod.errorSetBits();1016 const bits = zcu.errorSetBits();
933 if (bits == 0) return .{ .scalar = .@"1" };1017 if (bits == 0) return .{ .scalar = .@"1" };
934 return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };1018 return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };
935 },1019 },
...@@ -965,7 +1049,7 @@ pub fn abiAlignmentAdvanced(...@@ -965,7 +1049,7 @@ pub fn abiAlignmentAdvanced(
965 },1049 },
966 .f80 => switch (target.cTypeBitSize(.longdouble)) {1050 .f80 => switch (target.cTypeBitSize(.longdouble)) {
967 80 => return .{ .scalar = cTypeAlign(target, .longdouble) },1051 80 => return .{ .scalar = cTypeAlign(target, .longdouble) },
968 else => return .{ .scalar = Type.u80.abiAlignment(pt) },1052 else => return .{ .scalar = Type.u80.abiAlignment(zcu) },
969 },1053 },
970 .f128 => switch (target.cTypeBitSize(.longdouble)) {1054 .f128 => switch (target.cTypeBitSize(.longdouble)) {
971 128 => return .{ .scalar = cTypeAlign(target, .longdouble) },1055 128 => return .{ .scalar = cTypeAlign(target, .longdouble) },
...@@ -973,7 +1057,7 @@ pub fn abiAlignmentAdvanced(...@@ -973,7 +1057,7 @@ pub fn abiAlignmentAdvanced(
973 },1057 },
9741058
975 .anyerror, .adhoc_inferred_error_set => {1059 .anyerror, .adhoc_inferred_error_set => {
976 const bits = mod.errorSetBits();1060 const bits = zcu.errorSetBits();
977 if (bits == 0) return .{ .scalar = .@"1" };1061 if (bits == 0) return .{ .scalar = .@"1" };
978 return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };1062 return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };
979 },1063 },
...@@ -1003,7 +1087,7 @@ pub fn abiAlignmentAdvanced(...@@ -1003,7 +1087,7 @@ pub fn abiAlignmentAdvanced(
1003 },1087 },
1004 .eager => {},1088 .eager => {},
1005 }1089 }
1006 return .{ .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiAlignment(pt) };1090 return .{ .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiAlignment(zcu) };
1007 }1091 }
10081092
1009 if (struct_type.flagsUnordered(ip).alignment == .none) switch (strat) {1093 if (struct_type.flagsUnordered(ip).alignment == .none) switch (strat) {
...@@ -1021,11 +1105,11 @@ pub fn abiAlignmentAdvanced(...@@ -1021,11 +1105,11 @@ pub fn abiAlignmentAdvanced(
1021 var big_align: Alignment = .@"1";1105 var big_align: Alignment = .@"1";
1022 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {1106 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
1023 if (val != .none) continue; // comptime field1107 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)) {
1025 .scalar => |field_align| big_align = big_align.max(field_align),1109 .scalar => |field_align| big_align = big_align.max(field_align),
1026 .val => switch (strat) {1110 .val => switch (strat) {
1027 .eager => unreachable, // field type alignment not resolved1111 .eager => unreachable, // field type alignment not resolved
1028 .sema => unreachable, // passed to abiAlignmentAdvanced above1112 .sema => unreachable, // passed to abiAlignmentInner above
1029 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1113 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1030 .ty = .comptime_int_type,1114 .ty = .comptime_int_type,
1031 .storage = .{ .lazy_align = ty.toIntern() },1115 .storage = .{ .lazy_align = ty.toIntern() },
...@@ -1051,7 +1135,7 @@ pub fn abiAlignmentAdvanced(...@@ -1051,7 +1135,7 @@ pub fn abiAlignmentAdvanced(
1051 },1135 },
1052 .opaque_type => return .{ .scalar = .@"1" },1136 .opaque_type => return .{ .scalar = .@"1" },
1053 .enum_type => return .{1137 .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),
1055 },1139 },
10561140
1057 // values, not types1141 // values, not types
...@@ -1079,32 +1163,37 @@ pub fn abiAlignmentAdvanced(...@@ -1079,32 +1163,37 @@ pub fn abiAlignmentAdvanced(
1079 }1163 }
1080}1164}
10811165
1082fn abiAlignmentAdvancedErrorUnion(1166fn abiAlignmentInnerErrorUnion(
1083 ty: Type,1167 ty: Type,
1084 pt: Zcu.PerThread,
1085 comptime strat: ResolveStratLazy,1168 comptime strat: ResolveStratLazy,
1169 zcu: *Zcu,
1170 tid: strat.Tid(),
1086 payload_ty: Type,1171 payload_ty: Type,
1087) SemaError!AbiAlignmentAdvanced {1172) SemaError!AbiAlignmentInner {
1088 // This code needs to be kept in sync with the equivalent switch prong1173 // This code needs to be kept in sync with the equivalent switch prong
1089 // in abiSizeAdvanced.1174 // in abiSizeInner.
1090 const code_align = Type.anyerror.abiAlignment(pt);1175 const code_align = Type.anyerror.abiAlignment(zcu);
1091 switch (strat) {1176 switch (strat) {
1092 .eager, .sema => {1177 .eager, .sema => {
1093 if (!(payload_ty.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {1178 if (!(payload_ty.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1094 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1179 error.NeedLazy => if (strat == .lazy) {
1095 .ty = .comptime_int_type,1180 const pt = strat.pt(zcu, tid);
1096 .storage = .{ .lazy_align = ty.toIntern() },1181 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1097 } })) },1182 .ty = .comptime_int_type,
1183 .storage = .{ .lazy_align = ty.toIntern() },
1184 } })) };
1185 } else unreachable,
1098 else => |e| return e,1186 else => |e| return e,
1099 })) {1187 })) {
1100 return .{ .scalar = code_align };1188 return .{ .scalar = code_align };
1101 }1189 }
1102 return .{ .scalar = code_align.max(1190 return .{ .scalar = code_align.max(
1103 (try payload_ty.abiAlignmentAdvanced(pt, strat)).scalar,1191 (try payload_ty.abiAlignmentInner(strat, zcu, tid)).scalar,
1104 ) };1192 ) };
1105 },1193 },
1106 .lazy => {1194 .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)) {
1108 .scalar => |payload_align| return .{ .scalar = code_align.max(payload_align) },1197 .scalar => |payload_align| return .{ .scalar = code_align.max(payload_align) },
1109 .val => {},1198 .val => {},
1110 }1199 }
...@@ -1116,36 +1205,39 @@ fn abiAlignmentAdvancedErrorUnion(...@@ -1116,36 +1205,39 @@ fn abiAlignmentAdvancedErrorUnion(
1116 }1205 }
1117}1206}
11181207
1119fn abiAlignmentAdvancedOptional(1208fn abiAlignmentInnerOptional(
1120 ty: Type,1209 ty: Type,
1121 pt: Zcu.PerThread,
1122 comptime strat: ResolveStratLazy,1210 comptime strat: ResolveStratLazy,
1123) SemaError!AbiAlignmentAdvanced {1211 zcu: *Zcu,
1124 const mod = pt.zcu;1212 tid: strat.Tid(),
1125 const target = mod.getTarget();1213) SemaError!AbiAlignmentInner {
1126 const child_type = ty.optionalChild(mod);1214 const pt = strat.pt(zcu, tid);
11271215 const target = zcu.getTarget();
1128 switch (child_type.zigTypeTag(mod)) {1216 const child_type = ty.optionalChild(zcu);
1217
1218 switch (child_type.zigTypeTag(zcu)) {
1129 .Pointer => return .{ .scalar = ptrAbiAlignment(target) },1219 .Pointer => return .{ .scalar = ptrAbiAlignment(target) },
1130 .ErrorSet => return Type.anyerror.abiAlignmentAdvanced(pt, strat),1220 .ErrorSet => return Type.anyerror.abiAlignmentInner(strat, zcu, tid),
1131 .NoReturn => return .{ .scalar = .@"1" },1221 .NoReturn => return .{ .scalar = .@"1" },
1132 else => {},1222 else => {},
1133 }1223 }
11341224
1135 switch (strat) {1225 switch (strat) {
1136 .eager, .sema => {1226 .eager, .sema => {
1137 if (!(child_type.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {1227 if (!(child_type.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1138 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1228 error.NeedLazy => if (strat == .lazy) {
1139 .ty = .comptime_int_type,1229 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1140 .storage = .{ .lazy_align = ty.toIntern() },1230 .ty = .comptime_int_type,
1141 } })) },1231 .storage = .{ .lazy_align = ty.toIntern() },
1232 } })) };
1233 } else unreachable,
1142 else => |e| return e,1234 else => |e| return e,
1143 })) {1235 })) {
1144 return .{ .scalar = .@"1" };1236 return .{ .scalar = .@"1" };
1145 }1237 }
1146 return child_type.abiAlignmentAdvanced(pt, strat);1238 return child_type.abiAlignmentInner(strat, zcu, tid);
1147 },1239 },
1148 .lazy => switch (try child_type.abiAlignmentAdvanced(pt, strat)) {1240 .lazy => switch (try child_type.abiAlignmentInner(strat, zcu, tid)) {
1149 .scalar => |x| return .{ .scalar = x.max(.@"1") },1241 .scalar => |x| return .{ .scalar = x.max(.@"1") },
1150 .val => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1242 .val => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1151 .ty = .comptime_int_type,1243 .ty = .comptime_int_type,
...@@ -1155,40 +1247,44 @@ fn abiAlignmentAdvancedOptional(...@@ -1155,40 +1247,44 @@ fn abiAlignmentAdvancedOptional(
1155 }1247 }
1156}1248}
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
1158/// May capture a reference to `ty`.1261/// May capture a reference to `ty`.
1159pub fn lazyAbiSize(ty: Type, pt: Zcu.PerThread) !Value {1262pub fn abiSizeLazy(ty: Type, pt: Zcu.PerThread) !Value {
1160 switch (try ty.abiSizeAdvanced(pt, .lazy)) {1263 switch (try ty.abiSizeInner(.lazy, pt.zcu, pt.tid)) {
1161 .val => |val| return val,1264 .val => |val| return val,
1162 .scalar => |x| return pt.intValue(Type.comptime_int, x),1265 .scalar => |x| return pt.intValue(Type.comptime_int, x),
1163 }1266 }
1164}1267}
11651268
1166/// Asserts the type has the ABI size already resolved.1269pub fn abiSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {
1167/// Types that return false for hasRuntimeBits() return 0.1270 return (try abiSizeInner(ty, .sema, pt.zcu, pt.tid)).scalar;
1168pub fn abiSize(ty: Type, pt: Zcu.PerThread) u64 {
1169 return (abiSizeAdvanced(ty, pt, .eager) catch unreachable).scalar;
1170}1271}
11711272
1172const AbiSizeAdvanced = union(enum) {
1173 scalar: u64,
1174 val: Value,
1175};
1176
1177/// If you pass `eager` you will get back `scalar` and assert the type is resolved.1273/// If you pass `eager` you will get back `scalar` and assert the type is resolved.
1178/// In this case there will be no error, guaranteed.1274/// In this case there will be no error, guaranteed.
1179/// If you pass `lazy` you may get back `scalar` or `val`.1275/// If you pass `lazy` you may get back `scalar` or `val`.
1180/// If `val` is returned, a reference to `ty` has been captured.1276/// If `val` is returned, a reference to `ty` has been captured.
1181/// If you pass `sema` you will get back `scalar` and resolve the type if1277/// If you pass `sema` you will get back `scalar` and resolve the type if
1182/// necessary, possibly returning a CompileError.1278/// necessary, possibly returning a CompileError.
1183pub fn abiSizeAdvanced(1279pub fn abiSizeInner(
1184 ty: Type,1280 ty: Type,
1185 pt: Zcu.PerThread,
1186 comptime strat: ResolveStratLazy,1281 comptime strat: ResolveStratLazy,
1187) SemaError!AbiSizeAdvanced {1282 zcu: *Zcu,
1188 const mod = pt.zcu;1283 tid: strat.Tid(),
1189 const target = mod.getTarget();1284) SemaError!AbiSizeInner {
1190 const use_llvm = mod.comp.config.use_llvm;1285 const target = zcu.getTarget();
1191 const ip = &mod.intern_pool;1286 const use_llvm = zcu.comp.config.use_llvm;
1287 const ip = &zcu.intern_pool;
11921288
1193 switch (ty.toIntern()) {1289 switch (ty.toIntern()) {
1194 .empty_struct_type => return .{ .scalar = 0 },1290 .empty_struct_type => return .{ .scalar = 0 },
...@@ -1207,14 +1303,17 @@ pub fn abiSizeAdvanced(...@@ -1207,14 +1303,17 @@ pub fn abiSizeAdvanced(
1207 .array_type => |array_type| {1303 .array_type => |array_type| {
1208 const len = array_type.lenIncludingSentinel();1304 const len = array_type.lenIncludingSentinel();
1209 if (len == 0) return .{ .scalar = 0 };1305 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)) {
1211 .scalar => |elem_size| return .{ .scalar = len * elem_size },1307 .scalar => |elem_size| return .{ .scalar = len * elem_size },
1212 .val => switch (strat) {1308 .val => switch (strat) {
1213 .sema, .eager => unreachable,1309 .sema, .eager => unreachable,
1214 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1310 .lazy => {
1215 .ty = .comptime_int_type,1311 const pt = strat.pt(zcu, tid);
1216 .storage = .{ .lazy_size = ty.toIntern() },1312 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1217 } })) },1313 .ty = .comptime_int_type,
1314 .storage = .{ .lazy_size = ty.toIntern() },
1315 } })) };
1316 },
1218 },1317 },
1219 }1318 }
1220 },1319 },
...@@ -1222,41 +1321,38 @@ pub fn abiSizeAdvanced(...@@ -1222,41 +1321,38 @@ pub fn abiSizeAdvanced(
1222 const sub_strat: ResolveStrat = switch (strat) {1321 const sub_strat: ResolveStrat = switch (strat) {
1223 .sema => .sema,1322 .sema => .sema,
1224 .eager => .normal,1323 .eager => .normal,
1225 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1324 .lazy => {
1226 .ty = .comptime_int_type,1325 const pt = strat.pt(zcu, tid);
1227 .storage = .{ .lazy_size = ty.toIntern() },1326 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1228 } })) },1327 .ty = .comptime_int_type,
1229 };1328 .storage = .{ .lazy_size = ty.toIntern() },
1230 const alignment = switch (try ty.abiAlignmentAdvanced(pt, strat)) {1329 } })) };
1231 .scalar => |x| x,1330 },
1232 .val => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1233 .ty = .comptime_int_type,
1234 .storage = .{ .lazy_size = ty.toIntern() },
1235 } })) },
1236 };1331 };
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()) {
1238 else => total_bytes: {1334 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);
1240 const total_bits = elem_bits * vector_type.len;1336 const total_bits = elem_bits * vector_type.len;
1241 break :total_bytes (total_bits + 7) / 8;1337 break :total_bytes (total_bits + 7) / 8;
1242 },1338 },
1243 .stage2_c => total_bytes: {1339 .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);
1245 break :total_bytes elem_bytes * vector_type.len;1341 break :total_bytes elem_bytes * vector_type.len;
1246 },1342 },
1247 .stage2_x86_64 => total_bytes: {1343 .stage2_x86_64 => total_bytes: {
1248 if (vector_type.child == .bool_type) break :total_bytes std.math.divCeil(u32, vector_type.len, 8) catch unreachable;1344 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);
1250 break :total_bytes elem_bytes * vector_type.len;1346 break :total_bytes elem_bytes * vector_type.len;
1251 },1347 },
1252 };1348 };
1253 return .{ .scalar = alignment.forward(total_bytes) };1349 return .{ .scalar = alignment.forward(total_bytes) };
1254 },1350 },
12551351
1256 .opt_type => return ty.abiSizeAdvancedOptional(pt, strat),1352 .opt_type => return ty.abiSizeInnerOptional(strat, zcu, tid),
12571353
1258 .error_set_type, .inferred_error_set_type => {1354 .error_set_type, .inferred_error_set_type => {
1259 const bits = mod.errorSetBits();1355 const bits = zcu.errorSetBits();
1260 if (bits == 0) return .{ .scalar = 0 };1356 if (bits == 0) return .{ .scalar = 0 };
1261 return .{ .scalar = intAbiSize(bits, target, use_llvm) };1357 return .{ .scalar = intAbiSize(bits, target, use_llvm) };
1262 },1358 },
...@@ -1264,29 +1360,35 @@ pub fn abiSizeAdvanced(...@@ -1264,29 +1360,35 @@ pub fn abiSizeAdvanced(
1264 .error_union_type => |error_union_type| {1360 .error_union_type => |error_union_type| {
1265 const payload_ty = Type.fromInterned(error_union_type.payload_type);1361 const payload_ty = Type.fromInterned(error_union_type.payload_type);
1266 // This code needs to be kept in sync with the equivalent switch prong1362 // This code needs to be kept in sync with the equivalent switch prong
1267 // in abiAlignmentAdvanced.1363 // in abiAlignmentInner.
1268 const code_size = Type.anyerror.abiSize(pt);1364 const code_size = Type.anyerror.abiSize(zcu);
1269 if (!(payload_ty.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {1365 if (!(payload_ty.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1270 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1366 error.NeedLazy => if (strat == .lazy) {
1271 .ty = .comptime_int_type,1367 const pt = strat.pt(zcu, tid);
1272 .storage = .{ .lazy_size = ty.toIntern() },1368 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1273 } })) },1369 .ty = .comptime_int_type,
1370 .storage = .{ .lazy_size = ty.toIntern() },
1371 } })) };
1372 } else unreachable,
1274 else => |e| return e,1373 else => |e| return e,
1275 })) {1374 })) {
1276 // Same as anyerror.1375 // Same as anyerror.
1277 return .{ .scalar = code_size };1376 return .{ .scalar = code_size };
1278 }1377 }
1279 const code_align = Type.anyerror.abiAlignment(pt);1378 const code_align = Type.anyerror.abiAlignment(zcu);
1280 const payload_align = payload_ty.abiAlignment(pt);1379 const payload_align = (try payload_ty.abiAlignmentInner(strat, zcu, tid)).scalar;
1281 const payload_size = switch (try payload_ty.abiSizeAdvanced(pt, strat)) {1380 const payload_size = switch (try payload_ty.abiSizeInner(strat, zcu, tid)) {
1282 .scalar => |elem_size| elem_size,1381 .scalar => |elem_size| elem_size,
1283 .val => switch (strat) {1382 .val => switch (strat) {
1284 .sema => unreachable,1383 .sema => unreachable,
1285 .eager => unreachable,1384 .eager => unreachable,
1286 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1385 .lazy => {
1287 .ty = .comptime_int_type,1386 const pt = strat.pt(zcu, tid);
1288 .storage = .{ .lazy_size = ty.toIntern() },1387 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1289 } })) },1388 .ty = .comptime_int_type,
1389 .storage = .{ .lazy_size = ty.toIntern() },
1390 } })) };
1391 },
1290 },1392 },
1291 };1393 };
12921394
...@@ -1314,7 +1416,7 @@ pub fn abiSizeAdvanced(...@@ -1314,7 +1416,7 @@ pub fn abiSizeAdvanced(
1314 .f128 => return .{ .scalar = 16 },1416 .f128 => return .{ .scalar = 16 },
1315 .f80 => switch (target.cTypeBitSize(.longdouble)) {1417 .f80 => switch (target.cTypeBitSize(.longdouble)) {
1316 80 => return .{ .scalar = target.cTypeByteSize(.longdouble) },1418 80 => return .{ .scalar = target.cTypeByteSize(.longdouble) },
1317 else => return .{ .scalar = Type.u80.abiSize(pt) },1419 else => return .{ .scalar = Type.u80.abiSize(zcu) },
1318 },1420 },
13191421
1320 .usize,1422 .usize,
...@@ -1343,7 +1445,7 @@ pub fn abiSizeAdvanced(...@@ -1343,7 +1445,7 @@ pub fn abiSizeAdvanced(
1343 => return .{ .scalar = 0 },1445 => return .{ .scalar = 0 },
13441446
1345 .anyerror, .adhoc_inferred_error_set => {1447 .anyerror, .adhoc_inferred_error_set => {
1346 const bits = mod.errorSetBits();1448 const bits = zcu.errorSetBits();
1347 if (bits == 0) return .{ .scalar = 0 };1449 if (bits == 0) return .{ .scalar = 0 };
1348 return .{ .scalar = intAbiSize(bits, target, use_llvm) };1450 return .{ .scalar = intAbiSize(bits, target, use_llvm) };
1349 },1451 },
...@@ -1354,30 +1456,33 @@ pub fn abiSizeAdvanced(...@@ -1354,30 +1456,33 @@ pub fn abiSizeAdvanced(
1354 .struct_type => {1456 .struct_type => {
1355 const struct_type = ip.loadStructType(ty.toIntern());1457 const struct_type = ip.loadStructType(ty.toIntern());
1356 switch (strat) {1458 switch (strat) {
1357 .sema => try ty.resolveLayout(pt),1459 .sema => try ty.resolveLayout(strat.pt(zcu, tid)),
1358 .lazy => switch (struct_type.layout) {1460 .lazy => {
1359 .@"packed" => {1461 const pt = strat.pt(zcu, tid);
1360 if (struct_type.backingIntTypeUnordered(ip) == .none) return .{1462 switch (struct_type.layout) {
1361 .val = Value.fromInterned(try pt.intern(.{ .int = .{1463 .@"packed" => {
1362 .ty = .comptime_int_type,1464 if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
1363 .storage = .{ .lazy_size = ty.toIntern() },1465 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1364 } })),1466 .ty = .comptime_int_type,
1365 };1467 .storage = .{ .lazy_size = ty.toIntern() },
1366 },1468 } })),
1367 .auto, .@"extern" => {1469 };
1368 if (!struct_type.haveLayout(ip)) return .{1470 },
1369 .val = Value.fromInterned(try pt.intern(.{ .int = .{1471 .auto, .@"extern" => {
1370 .ty = .comptime_int_type,1472 if (!struct_type.haveLayout(ip)) return .{
1371 .storage = .{ .lazy_size = ty.toIntern() },1473 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1372 } })),1474 .ty = .comptime_int_type,
1373 };1475 .storage = .{ .lazy_size = ty.toIntern() },
1374 },1476 } })),
1477 };
1478 },
1479 }
1375 },1480 },
1376 .eager => {},1481 .eager => {},
1377 }1482 }
1378 switch (struct_type.layout) {1483 switch (struct_type.layout) {
1379 .@"packed" => return .{1484 .@"packed" => return .{
1380 .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiSize(pt),1485 .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiSize(zcu),
1381 },1486 },
1382 .auto, .@"extern" => {1487 .auto, .@"extern" => {
1383 assert(struct_type.haveLayout(ip));1488 assert(struct_type.haveLayout(ip));
...@@ -1387,25 +1492,28 @@ pub fn abiSizeAdvanced(...@@ -1387,25 +1492,28 @@ pub fn abiSizeAdvanced(
1387 },1492 },
1388 .anon_struct_type => |tuple| {1493 .anon_struct_type => |tuple| {
1389 switch (strat) {1494 switch (strat) {
1390 .sema => try ty.resolveLayout(pt),1495 .sema => try ty.resolveLayout(strat.pt(zcu, tid)),
1391 .lazy, .eager => {},1496 .lazy, .eager => {},
1392 }1497 }
1393 const field_count = tuple.types.len;1498 const field_count = tuple.types.len;
1394 if (field_count == 0) {1499 if (field_count == 0) {
1395 return .{ .scalar = 0 };1500 return .{ .scalar = 0 };
1396 }1501 }
1397 return .{ .scalar = ty.structFieldOffset(field_count, pt) };1502 return .{ .scalar = ty.structFieldOffset(field_count, zcu) };
1398 },1503 },
13991504
1400 .union_type => {1505 .union_type => {
1401 const union_type = ip.loadUnionType(ty.toIntern());1506 const union_type = ip.loadUnionType(ty.toIntern());
1402 switch (strat) {1507 switch (strat) {
1403 .sema => try ty.resolveLayout(pt),1508 .sema => try ty.resolveLayout(strat.pt(zcu, tid)),
1404 .lazy => if (!union_type.flagsUnordered(ip).status.haveLayout()) return .{1509 .lazy => {
1405 .val = Value.fromInterned(try pt.intern(.{ .int = .{1510 const pt = strat.pt(zcu, tid);
1406 .ty = .comptime_int_type,1511 if (!union_type.flagsUnordered(ip).status.haveLayout()) return .{
1407 .storage = .{ .lazy_size = ty.toIntern() },1512 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1408 } })),1513 .ty = .comptime_int_type,
1514 .storage = .{ .lazy_size = ty.toIntern() },
1515 } })),
1516 };
1409 },1517 },
1410 .eager => {},1518 .eager => {},
1411 }1519 }
...@@ -1414,7 +1522,7 @@ pub fn abiSizeAdvanced(...@@ -1414,7 +1522,7 @@ pub fn abiSizeAdvanced(
1414 return .{ .scalar = union_type.sizeUnordered(ip) };1522 return .{ .scalar = union_type.sizeUnordered(ip) };
1415 },1523 },
1416 .opaque_type => unreachable, // no size available1524 .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
1419 // values, not types1527 // values, not types
1420 .undef,1528 .undef,
...@@ -1441,36 +1549,39 @@ pub fn abiSizeAdvanced(...@@ -1441,36 +1549,39 @@ pub fn abiSizeAdvanced(
1441 }1549 }
1442}1550}
14431551
1444fn abiSizeAdvancedOptional(1552fn abiSizeInnerOptional(
1445 ty: Type,1553 ty: Type,
1446 pt: Zcu.PerThread,
1447 comptime strat: ResolveStratLazy,1554 comptime strat: ResolveStratLazy,
1448) SemaError!AbiSizeAdvanced {1555 zcu: *Zcu,
1449 const mod = pt.zcu;1556 tid: strat.Tid(),
1450 const child_ty = ty.optionalChild(mod);1557) SemaError!AbiSizeInner {
1558 const child_ty = ty.optionalChild(zcu);
14511559
1452 if (child_ty.isNoReturn(mod)) {1560 if (child_ty.isNoReturn(zcu)) {
1453 return .{ .scalar = 0 };1561 return .{ .scalar = 0 };
1454 }1562 }
14551563
1456 if (!(child_ty.hasRuntimeBitsAdvanced(pt, false, strat) catch |err| switch (err) {1564 if (!(child_ty.hasRuntimeBitsInner(false, strat, zcu, tid) catch |err| switch (err) {
1457 error.NeedLazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1565 error.NeedLazy => if (strat == .lazy) {
1458 .ty = .comptime_int_type,1566 const pt = strat.pt(zcu, tid);
1459 .storage = .{ .lazy_size = ty.toIntern() },1567 return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
1460 } })) },1568 .ty = .comptime_int_type,
1569 .storage = .{ .lazy_size = ty.toIntern() },
1570 } })) };
1571 } else unreachable,
1461 else => |e| return e,1572 else => |e| return e,
1462 })) return .{ .scalar = 1 };1573 })) return .{ .scalar = 1 };
14631574
1464 if (ty.optionalReprIsPayload(mod)) {1575 if (ty.optionalReprIsPayload(zcu)) {
1465 return child_ty.abiSizeAdvanced(pt, strat);1576 return child_ty.abiSizeInner(strat, zcu, tid);
1466 }1577 }
14671578
1468 const payload_size = switch (try child_ty.abiSizeAdvanced(pt, strat)) {1579 const payload_size = switch (try child_ty.abiSizeInner(strat, zcu, tid)) {
1469 .scalar => |elem_size| elem_size,1580 .scalar => |elem_size| elem_size,
1470 .val => switch (strat) {1581 .val => switch (strat) {
1471 .sema => unreachable,1582 .sema => unreachable,
1472 .eager => unreachable,1583 .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 = .{
1474 .ty = .comptime_int_type,1585 .ty = .comptime_int_type,
1475 .storage = .{ .lazy_size = ty.toIntern() },1586 .storage = .{ .lazy_size = ty.toIntern() },
1476 } })) },1587 } })) },
...@@ -1482,7 +1593,7 @@ fn abiSizeAdvancedOptional(...@@ -1482,7 +1593,7 @@ fn abiSizeAdvancedOptional(
1482 // guaranteed to be >= that of bool's (1 byte) the added size is exactly equal1593 // guaranteed to be >= that of bool's (1 byte) the added size is exactly equal
1483 // to the child type's ABI alignment.1594 // to the child type's ABI alignment.
1484 return .{1595 return .{
1485 .scalar = (child_ty.abiAlignment(pt).toByteUnits() orelse 0) + payload_size,1596 .scalar = (child_ty.abiAlignment(zcu).toByteUnits() orelse 0) + payload_size,
1486 };1597 };
1487}1598}
14881599
...@@ -1600,18 +1711,22 @@ pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {...@@ -1600,18 +1711,22 @@ pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {
1600 };1711 };
1601}1712}
16021713
1603pub fn bitSize(ty: Type, pt: Zcu.PerThread) u64 {1714pub fn bitSize(ty: Type, zcu: *Zcu) u64 {
1604 return bitSizeAdvanced(ty, pt, .normal) catch unreachable;1715 return bitSizeInner(ty, .normal, zcu, {}) catch unreachable;
1605}1716}
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(
1608 ty: Type,1723 ty: Type,
1609 pt: Zcu.PerThread,
1610 comptime strat: ResolveStrat,1724 comptime strat: ResolveStrat,
1725 zcu: *Zcu,
1726 tid: strat.Tid(),
1611) SemaError!u64 {1727) SemaError!u64 {
1612 const mod = pt.zcu;1728 const target = zcu.getTarget();
1613 const target = mod.getTarget();1729 const ip = &zcu.intern_pool;
1614 const ip = &mod.intern_pool;
16151730
1616 const strat_lazy: ResolveStratLazy = strat.toLazy();1731 const strat_lazy: ResolveStratLazy = strat.toLazy();
16171732
...@@ -1628,30 +1743,30 @@ pub fn bitSizeAdvanced(...@@ -1628,30 +1743,30 @@ pub fn bitSizeAdvanced(
1628 if (len == 0) return 0;1743 if (len == 0) return 0;
1629 const elem_ty = Type.fromInterned(array_type.child);1744 const elem_ty = Type.fromInterned(array_type.child);
1630 const elem_size = @max(1745 const elem_size = @max(
1631 (try elem_ty.abiAlignmentAdvanced(pt, strat_lazy)).scalar.toByteUnits() orelse 0,1746 (try elem_ty.abiAlignmentInner(strat_lazy, zcu, tid)).scalar.toByteUnits() orelse 0,
1632 (try elem_ty.abiSizeAdvanced(pt, strat_lazy)).scalar,1747 (try elem_ty.abiSizeInner(strat_lazy, zcu, tid)).scalar,
1633 );1748 );
1634 if (elem_size == 0) return 0;1749 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);
1636 return (len - 1) * 8 * elem_size + elem_bit_size;1751 return (len - 1) * 8 * elem_size + elem_bit_size;
1637 },1752 },
1638 .vector_type => |vector_type| {1753 .vector_type => |vector_type| {
1639 const child_ty = Type.fromInterned(vector_type.child);1754 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);
1641 return elem_bit_size * vector_type.len;1756 return elem_bit_size * vector_type.len;
1642 },1757 },
1643 .opt_type => {1758 .opt_type => {
1644 // Optionals and error unions are not packed so their bitsize1759 // Optionals and error unions are not packed so their bitsize
1645 // includes padding bits.1760 // includes padding bits.
1646 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;1761 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
1647 },1762 },
16481763
1649 .error_set_type, .inferred_error_set_type => return mod.errorSetBits(),1764 .error_set_type, .inferred_error_set_type => return zcu.errorSetBits(),
16501765
1651 .error_union_type => {1766 .error_union_type => {
1652 // Optionals and error unions are not packed so their bitsize1767 // Optionals and error unions are not packed so their bitsize
1653 // includes padding bits.1768 // includes padding bits.
1654 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;1769 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
1655 },1770 },
1656 .func_type => unreachable, // represents machine code; not a pointer1771 .func_type => unreachable, // represents machine code; not a pointer
1657 .simple_type => |t| switch (t) {1772 .simple_type => |t| switch (t) {
...@@ -1681,7 +1796,7 @@ pub fn bitSizeAdvanced(...@@ -1681,7 +1796,7 @@ pub fn bitSizeAdvanced(
16811796
1682 .anyerror,1797 .anyerror,
1683 .adhoc_inferred_error_set,1798 .adhoc_inferred_error_set,
1684 => return mod.errorSetBits(),1799 => return zcu.errorSetBits(),
16851800
1686 .anyopaque => unreachable,1801 .anyopaque => unreachable,
1687 .type => unreachable,1802 .type => unreachable,
...@@ -1697,42 +1812,46 @@ pub fn bitSizeAdvanced(...@@ -1697,42 +1812,46 @@ pub fn bitSizeAdvanced(
1697 const struct_type = ip.loadStructType(ty.toIntern());1812 const struct_type = ip.loadStructType(ty.toIntern());
1698 const is_packed = struct_type.layout == .@"packed";1813 const is_packed = struct_type.layout == .@"packed";
1699 if (strat == .sema) {1814 if (strat == .sema) {
1815 const pt = strat.pt(zcu, tid);
1700 try ty.resolveFields(pt);1816 try ty.resolveFields(pt);
1701 if (is_packed) try ty.resolveLayout(pt);1817 if (is_packed) try ty.resolveLayout(pt);
1702 }1818 }
1703 if (is_packed) {1819 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);
1705 }1822 }
1706 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;1823 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
1707 },1824 },
17081825
1709 .anon_struct_type => {1826 .anon_struct_type => {
1710 if (strat == .sema) try ty.resolveFields(pt);1827 if (strat == .sema) try ty.resolveFields(strat.pt(zcu, tid));
1711 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;1828 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
1712 },1829 },
17131830
1714 .union_type => {1831 .union_type => {
1715 const union_type = ip.loadUnionType(ty.toIntern());1832 const union_type = ip.loadUnionType(ty.toIntern());
1716 const is_packed = ty.containerLayout(mod) == .@"packed";1833 const is_packed = ty.containerLayout(zcu) == .@"packed";
1717 if (strat == .sema) {1834 if (strat == .sema) {
1835 const pt = strat.pt(zcu, tid);
1718 try ty.resolveFields(pt);1836 try ty.resolveFields(pt);
1719 if (is_packed) try ty.resolveLayout(pt);1837 if (is_packed) try ty.resolveLayout(pt);
1720 }1838 }
1721 if (!is_packed) {1839 if (!is_packed) {
1722 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;1840 return (try ty.abiSizeInner(strat_lazy, zcu, tid)).scalar * 8;
1723 }1841 }
1724 assert(union_type.flagsUnordered(ip).status.haveFieldTypes());1842 assert(union_type.flagsUnordered(ip).status.haveFieldTypes());
17251843
1726 var size: u64 = 0;1844 var size: u64 = 0;
1727 for (0..union_type.field_types.len) |field_index| {1845 for (0..union_type.field_types.len) |field_index| {
1728 const field_ty = union_type.field_types.get(ip)[field_index];1846 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));
1730 }1848 }
17311849
1732 return size;1850 return size;
1733 },1851 },
1734 .opaque_type => unreachable,1852 .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
1737 // values, not types1856 // values, not types
1738 .undef,1857 .undef,
...@@ -1760,61 +1879,61 @@ pub fn bitSizeAdvanced(...@@ -1760,61 +1879,61 @@ pub fn bitSizeAdvanced(
17601879
1761/// Returns true if the type's layout is already resolved and it is safe1880/// Returns true if the type's layout is already resolved and it is safe
1762/// to use `abiSize`, `abiAlignment` and `bitSize` on it.1881/// to use `abiSize`, `abiAlignment` and `bitSize` on it.
1763pub fn layoutIsResolved(ty: Type, mod: *Module) bool {1882pub fn layoutIsResolved(ty: Type, zcu: *const Zcu) bool {
1764 const ip = &mod.intern_pool;1883 const ip = &zcu.intern_pool;
1765 return switch (ip.indexToKey(ty.toIntern())) {1884 return switch (ip.indexToKey(ty.toIntern())) {
1766 .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip),1885 .struct_type => ip.loadStructType(ty.toIntern()).haveLayout(ip),
1767 .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip),1886 .union_type => ip.loadUnionType(ty.toIntern()).haveLayout(ip),
1768 .array_type => |array_type| {1887 .array_type => |array_type| {
1769 if (array_type.lenIncludingSentinel() == 0) return true;1888 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);
1771 },1890 },
1772 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod),1891 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(zcu),
1773 .error_union_type => |k| Type.fromInterned(k.payload_type).layoutIsResolved(mod),1892 .error_union_type => |k| Type.fromInterned(k.payload_type).layoutIsResolved(zcu),
1774 else => true,1893 else => true,
1775 };1894 };
1776}1895}
17771896
1778pub fn isSinglePointer(ty: Type, mod: *const Module) bool {1897pub fn isSinglePointer(ty: Type, zcu: *const Zcu) bool {
1779 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1898 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1780 .ptr_type => |ptr_info| ptr_info.flags.size == .One,1899 .ptr_type => |ptr_info| ptr_info.flags.size == .One,
1781 else => false,1900 else => false,
1782 };1901 };
1783}1902}
17841903
1785/// Asserts `ty` is a pointer.1904/// Asserts `ty` is a pointer.
1786pub fn ptrSize(ty: Type, mod: *const Module) std.builtin.Type.Pointer.Size {1905pub fn ptrSize(ty: Type, zcu: *const Zcu) std.builtin.Type.Pointer.Size {
1787 return ty.ptrSizeOrNull(mod).?;1906 return ty.ptrSizeOrNull(zcu).?;
1788}1907}
17891908
1790/// Returns `null` if `ty` is not a pointer.1909/// Returns `null` if `ty` is not a pointer.
1791pub fn ptrSizeOrNull(ty: Type, mod: *const Module) ?std.builtin.Type.Pointer.Size {1910pub fn ptrSizeOrNull(ty: Type, zcu: *const Zcu) ?std.builtin.Type.Pointer.Size {
1792 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1911 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1793 .ptr_type => |ptr_info| ptr_info.flags.size,1912 .ptr_type => |ptr_info| ptr_info.flags.size,
1794 else => null,1913 else => null,
1795 };1914 };
1796}1915}
17971916
1798pub fn isSlice(ty: Type, mod: *const Module) bool {1917pub fn isSlice(ty: Type, zcu: *const Zcu) bool {
1799 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1918 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1800 .ptr_type => |ptr_type| ptr_type.flags.size == .Slice,1919 .ptr_type => |ptr_type| ptr_type.flags.size == .Slice,
1801 else => false,1920 else => false,
1802 };1921 };
1803}1922}
18041923
1805pub fn slicePtrFieldType(ty: Type, mod: *const Module) Type {1924pub fn slicePtrFieldType(ty: Type, zcu: *const Zcu) Type {
1806 return Type.fromInterned(mod.intern_pool.slicePtrType(ty.toIntern()));1925 return Type.fromInterned(zcu.intern_pool.slicePtrType(ty.toIntern()));
1807}1926}
18081927
1809pub fn isConstPtr(ty: Type, mod: *const Module) bool {1928pub fn isConstPtr(ty: Type, zcu: *const Zcu) bool {
1810 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1929 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1811 .ptr_type => |ptr_type| ptr_type.flags.is_const,1930 .ptr_type => |ptr_type| ptr_type.flags.is_const,
1812 else => false,1931 else => false,
1813 };1932 };
1814}1933}
18151934
1816pub fn isVolatilePtr(ty: Type, mod: *const Module) bool {1935pub fn isVolatilePtr(ty: Type, zcu: *const Zcu) bool {
1817 return isVolatilePtrIp(ty, &mod.intern_pool);1936 return isVolatilePtrIp(ty, &zcu.intern_pool);
1818}1937}
18191938
1820pub fn isVolatilePtrIp(ty: Type, ip: *const InternPool) bool {1939pub fn isVolatilePtrIp(ty: Type, ip: *const InternPool) bool {
...@@ -1824,28 +1943,28 @@ pub fn isVolatilePtrIp(ty: Type, ip: *const InternPool) bool {...@@ -1824,28 +1943,28 @@ pub fn isVolatilePtrIp(ty: Type, ip: *const InternPool) bool {
1824 };1943 };
1825}1944}
18261945
1827pub fn isAllowzeroPtr(ty: Type, mod: *const Module) bool {1946pub fn isAllowzeroPtr(ty: Type, zcu: *const Zcu) bool {
1828 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1947 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1829 .ptr_type => |ptr_type| ptr_type.flags.is_allowzero,1948 .ptr_type => |ptr_type| ptr_type.flags.is_allowzero,
1830 .opt_type => true,1949 .opt_type => true,
1831 else => false,1950 else => false,
1832 };1951 };
1833}1952}
18341953
1835pub fn isCPtr(ty: Type, mod: *const Module) bool {1954pub fn isCPtr(ty: Type, zcu: *const Zcu) bool {
1836 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1955 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1837 .ptr_type => |ptr_type| ptr_type.flags.size == .C,1956 .ptr_type => |ptr_type| ptr_type.flags.size == .C,
1838 else => false,1957 else => false,
1839 };1958 };
1840}1959}
18411960
1842pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool {1961pub fn isPtrAtRuntime(ty: Type, zcu: *const Zcu) bool {
1843 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1962 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1844 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {1963 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
1845 .Slice => false,1964 .Slice => false,
1846 .One, .Many, .C => true,1965 .One, .Many, .C => true,
1847 },1966 },
1848 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {1967 .opt_type => |child| switch (zcu.intern_pool.indexToKey(child)) {
1849 .ptr_type => |p| switch (p.flags.size) {1968 .ptr_type => |p| switch (p.flags.size) {
1850 .Slice, .C => false,1969 .Slice, .C => false,
1851 .Many, .One => !p.flags.is_allowzero,1970 .Many, .One => !p.flags.is_allowzero,
...@@ -1858,17 +1977,17 @@ pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool {...@@ -1858,17 +1977,17 @@ pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool {
18581977
1859/// For pointer-like optionals, returns true, otherwise returns the allowzero property1978/// For pointer-like optionals, returns true, otherwise returns the allowzero property
1860/// of pointers.1979/// of pointers.
1861pub fn ptrAllowsZero(ty: Type, mod: *const Module) bool {1980pub fn ptrAllowsZero(ty: Type, zcu: *const Zcu) bool {
1862 if (ty.isPtrLikeOptional(mod)) {1981 if (ty.isPtrLikeOptional(zcu)) {
1863 return true;1982 return true;
1864 }1983 }
1865 return ty.ptrInfo(mod).flags.is_allowzero;1984 return ty.ptrInfo(zcu).flags.is_allowzero;
1866}1985}
18671986
1868/// See also `isPtrLikeOptional`.1987/// See also `isPtrLikeOptional`.
1869pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool {1988pub fn optionalReprIsPayload(ty: Type, zcu: *const Zcu) bool {
1870 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1989 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1871 .opt_type => |child_type| child_type == .anyerror_type or switch (mod.intern_pool.indexToKey(child_type)) {1990 .opt_type => |child_type| child_type == .anyerror_type or switch (zcu.intern_pool.indexToKey(child_type)) {
1872 .ptr_type => |ptr_type| ptr_type.flags.size != .C and !ptr_type.flags.is_allowzero,1991 .ptr_type => |ptr_type| ptr_type.flags.size != .C and !ptr_type.flags.is_allowzero,
1873 .error_set_type, .inferred_error_set_type => true,1992 .error_set_type, .inferred_error_set_type => true,
1874 else => false,1993 else => false,
...@@ -1881,10 +2000,10 @@ pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool {...@@ -1881,10 +2000,10 @@ pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool {
1881/// Returns true if the type is optional and would be lowered to a single pointer2000/// Returns true if the type is optional and would be lowered to a single pointer
1882/// address value, using 0 for null. Note that this returns true for C pointers.2001/// address value, using 0 for null. Note that this returns true for C pointers.
1883/// This function must be kept in sync with `Sema.typePtrOrOptionalPtrTy`.2002/// This function must be kept in sync with `Sema.typePtrOrOptionalPtrTy`.
1884pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool {2003pub fn isPtrLikeOptional(ty: Type, zcu: *const Zcu) bool {
1885 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {2004 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1886 .ptr_type => |ptr_type| ptr_type.flags.size == .C,2005 .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)) {
1888 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {2007 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
1889 .Slice, .C => false,2008 .Slice, .C => false,
1890 .Many, .One => !ptr_type.flags.is_allowzero,2009 .Many, .One => !ptr_type.flags.is_allowzero,
...@@ -1898,8 +2017,8 @@ pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool {...@@ -1898,8 +2017,8 @@ pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool {
1898/// For *[N]T, returns [N]T.2017/// For *[N]T, returns [N]T.
1899/// For *T, returns T.2018/// For *T, returns T.
1900/// For [*]T, returns T.2019/// For [*]T, returns T.
1901pub fn childType(ty: Type, mod: *const Module) Type {2020pub fn childType(ty: Type, zcu: *const Zcu) Type {
1902 return childTypeIp(ty, &mod.intern_pool);2021 return childTypeIp(ty, &zcu.intern_pool);
1903}2022}
19042023
1905pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {2024pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
...@@ -1915,10 +2034,10 @@ pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {...@@ -1915,10 +2034,10 @@ pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
1915/// For [N]T, returns T.2034/// For [N]T, returns T.
1916/// For []T, returns T.2035/// For []T, returns T.
1917/// For anyframe->T, returns T.2036/// For anyframe->T, returns T.
1918pub fn elemType2(ty: Type, mod: *const Module) Type {2037pub fn elemType2(ty: Type, zcu: *const Zcu) Type {
1919 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {2038 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1920 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {2039 .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),
1922 .Many, .C, .Slice => Type.fromInterned(ptr_type.child),2041 .Many, .C, .Slice => Type.fromInterned(ptr_type.child),
1923 },2042 },
1924 .anyframe_type => |child| {2043 .anyframe_type => |child| {
...@@ -1927,30 +2046,30 @@ pub fn elemType2(ty: Type, mod: *const Module) Type {...@@ -1927,30 +2046,30 @@ pub fn elemType2(ty: Type, mod: *const Module) Type {
1927 },2046 },
1928 .vector_type => |vector_type| Type.fromInterned(vector_type.child),2047 .vector_type => |vector_type| Type.fromInterned(vector_type.child),
1929 .array_type => |array_type| Type.fromInterned(array_type.child),2048 .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)),
1931 else => unreachable,2050 else => unreachable,
1932 };2051 };
1933}2052}
19342053
1935fn shallowElemType(child_ty: Type, mod: *const Module) Type {2054fn shallowElemType(child_ty: Type, zcu: *const Zcu) Type {
1936 return switch (child_ty.zigTypeTag(mod)) {2055 return switch (child_ty.zigTypeTag(zcu)) {
1937 .Array, .Vector => child_ty.childType(mod),2056 .Array, .Vector => child_ty.childType(zcu),
1938 else => child_ty,2057 else => child_ty,
1939 };2058 };
1940}2059}
19412060
1942/// For vectors, returns the element type. Otherwise returns self.2061/// For vectors, returns the element type. Otherwise returns self.
1943pub fn scalarType(ty: Type, mod: *Module) Type {2062pub fn scalarType(ty: Type, zcu: *const Zcu) Type {
1944 return switch (ty.zigTypeTag(mod)) {2063 return switch (ty.zigTypeTag(zcu)) {
1945 .Vector => ty.childType(mod),2064 .Vector => ty.childType(zcu),
1946 else => ty,2065 else => ty,
1947 };2066 };
1948}2067}
19492068
1950/// Asserts that the type is an optional.2069/// Asserts that the type is an optional.
1951/// Note that for C pointers this returns the type unmodified.2070/// Note that for C pointers this returns the type unmodified.
1952pub fn optionalChild(ty: Type, mod: *const Module) Type {2071pub fn optionalChild(ty: Type, zcu: *const Zcu) Type {
1953 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {2072 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
1954 .opt_type => |child| Type.fromInterned(child),2073 .opt_type => |child| Type.fromInterned(child),
1955 .ptr_type => |ptr_type| b: {2074 .ptr_type => |ptr_type| b: {
1956 assert(ptr_type.flags.size == .C);2075 assert(ptr_type.flags.size == .C);
...@@ -1962,8 +2081,8 @@ pub fn optionalChild(ty: Type, mod: *const Module) Type {...@@ -1962,8 +2081,8 @@ pub fn optionalChild(ty: Type, mod: *const Module) Type {
19622081
1963/// Returns the tag type of a union, if the type is a union and it has a tag type.2082/// Returns the tag type of a union, if the type is a union and it has a tag type.
1964/// Otherwise, returns `null`.2083/// Otherwise, returns `null`.
1965pub fn unionTagType(ty: Type, mod: *Module) ?Type {2084pub fn unionTagType(ty: Type, zcu: *const Zcu) ?Type {
1966 const ip = &mod.intern_pool;2085 const ip = &zcu.intern_pool;
1967 switch (ip.indexToKey(ty.toIntern())) {2086 switch (ip.indexToKey(ty.toIntern())) {
1968 .union_type => {},2087 .union_type => {},
1969 else => return null,2088 else => return null,
...@@ -1981,8 +2100,8 @@ pub fn unionTagType(ty: Type, mod: *Module) ?Type {...@@ -1981,8 +2100,8 @@ pub fn unionTagType(ty: Type, mod: *Module) ?Type {
19812100
1982/// Same as `unionTagType` but includes safety tag.2101/// Same as `unionTagType` but includes safety tag.
1983/// Codegen should use this version.2102/// Codegen should use this version.
1984pub fn unionTagTypeSafety(ty: Type, mod: *Module) ?Type {2103pub fn unionTagTypeSafety(ty: Type, zcu: *const Zcu) ?Type {
1985 const ip = &mod.intern_pool;2104 const ip = &zcu.intern_pool;
1986 return switch (ip.indexToKey(ty.toIntern())) {2105 return switch (ip.indexToKey(ty.toIntern())) {
1987 .union_type => {2106 .union_type => {
1988 const union_type = ip.loadUnionType(ty.toIntern());2107 const union_type = ip.loadUnionType(ty.toIntern());
...@@ -1996,35 +2115,35 @@ pub fn unionTagTypeSafety(ty: Type, mod: *Module) ?Type {...@@ -1996,35 +2115,35 @@ pub fn unionTagTypeSafety(ty: Type, mod: *Module) ?Type {
19962115
1997/// Asserts the type is a union; returns the tag type, even if the tag will2116/// Asserts the type is a union; returns the tag type, even if the tag will
1998/// not be stored at runtime.2117/// not be stored at runtime.
1999pub fn unionTagTypeHypothetical(ty: Type, mod: *Module) Type {2118pub fn unionTagTypeHypothetical(ty: Type, zcu: *const Zcu) Type {
2000 const union_obj = mod.typeToUnion(ty).?;2119 const union_obj = zcu.typeToUnion(ty).?;
2001 return Type.fromInterned(union_obj.enum_tag_ty);2120 return Type.fromInterned(union_obj.enum_tag_ty);
2002}2121}
20032122
2004pub fn unionFieldType(ty: Type, enum_tag: Value, mod: *Module) ?Type {2123pub fn unionFieldType(ty: Type, enum_tag: Value, zcu: *const Zcu) ?Type {
2005 const ip = &mod.intern_pool;2124 const ip = &zcu.intern_pool;
2006 const union_obj = mod.typeToUnion(ty).?;2125 const union_obj = zcu.typeToUnion(ty).?;
2007 const union_fields = union_obj.field_types.get(ip);2126 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;
2009 return Type.fromInterned(union_fields[index]);2128 return Type.fromInterned(union_fields[index]);
2010}2129}
20112130
2012pub fn unionFieldTypeByIndex(ty: Type, index: usize, mod: *Module) Type {2131pub fn unionFieldTypeByIndex(ty: Type, index: usize, zcu: *const Zcu) Type {
2013 const ip = &mod.intern_pool;2132 const ip = &zcu.intern_pool;
2014 const union_obj = mod.typeToUnion(ty).?;2133 const union_obj = zcu.typeToUnion(ty).?;
2015 return Type.fromInterned(union_obj.field_types.get(ip)[index]);2134 return Type.fromInterned(union_obj.field_types.get(ip)[index]);
2016}2135}
20172136
2018pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {2137pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, zcu: *const Zcu) ?u32 {
2019 const union_obj = mod.typeToUnion(ty).?;2138 const union_obj = zcu.typeToUnion(ty).?;
2020 return mod.unionTagFieldIndex(union_obj, enum_tag);2139 return zcu.unionTagFieldIndex(union_obj, enum_tag);
2021}2140}
20222141
2023pub fn unionHasAllZeroBitFieldTypes(ty: Type, pt: Zcu.PerThread) bool {2142pub fn unionHasAllZeroBitFieldTypes(ty: Type, zcu: *Zcu) bool {
2024 const ip = &pt.zcu.intern_pool;2143 const ip = &zcu.intern_pool;
2025 const union_obj = pt.zcu.typeToUnion(ty).?;2144 const union_obj = zcu.typeToUnion(ty).?;
2026 for (union_obj.field_types.get(ip)) |field_ty| {2145 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;
2028 }2147 }
2029 return true;2148 return true;
2030}2149}
...@@ -2032,20 +2151,21 @@ pub fn unionHasAllZeroBitFieldTypes(ty: Type, pt: Zcu.PerThread) bool {...@@ -2032,20 +2151,21 @@ pub fn unionHasAllZeroBitFieldTypes(ty: Type, pt: Zcu.PerThread) bool {
2032/// Returns the type used for backing storage of this union during comptime operations.2151/// Returns the type used for backing storage of this union during comptime operations.
2033/// Asserts the type is either an extern or packed union.2152/// Asserts the type is either an extern or packed union.
2034pub fn unionBackingType(ty: Type, pt: Zcu.PerThread) !Type {2153pub fn unionBackingType(ty: Type, pt: Zcu.PerThread) !Type {
2035 return switch (ty.containerLayout(pt.zcu)) {2154 const zcu = pt.zcu;
2036 .@"extern" => try pt.arrayType(.{ .len = ty.abiSize(pt), .child = .u8_type }),2155 return switch (ty.containerLayout(zcu)) {
2037 .@"packed" => try pt.intType(.unsigned, @intCast(ty.bitSize(pt))),2156 .@"extern" => try pt.arrayType(.{ .len = ty.abiSize(zcu), .child = .u8_type }),
2157 .@"packed" => try pt.intType(.unsigned, @intCast(ty.bitSize(zcu))),
2038 .auto => unreachable,2158 .auto => unreachable,
2039 };2159 };
2040}2160}
20412161
2042pub fn unionGetLayout(ty: Type, pt: Zcu.PerThread) Module.UnionLayout {2162pub fn unionGetLayout(ty: Type, zcu: *Zcu) Zcu.UnionLayout {
2043 const union_obj = pt.zcu.intern_pool.loadUnionType(ty.toIntern());2163 const union_obj = zcu.intern_pool.loadUnionType(ty.toIntern());
2044 return pt.getUnionLayout(union_obj);2164 return Type.getUnionLayout(union_obj, zcu);
2045}2165}
20462166
2047pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout {2167pub fn containerLayout(ty: Type, zcu: *const Zcu) std.builtin.Type.ContainerLayout {
2048 const ip = &mod.intern_pool;2168 const ip = &zcu.intern_pool;
2049 return switch (ip.indexToKey(ty.toIntern())) {2169 return switch (ip.indexToKey(ty.toIntern())) {
2050 .struct_type => ip.loadStructType(ty.toIntern()).layout,2170 .struct_type => ip.loadStructType(ty.toIntern()).layout,
2051 .anon_struct_type => .auto,2171 .anon_struct_type => .auto,
...@@ -2055,18 +2175,18 @@ pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout...@@ -2055,18 +2175,18 @@ pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout
2055}2175}
20562176
2057/// Asserts that the type is an error union.2177/// Asserts that the type is an error union.
2058pub fn errorUnionPayload(ty: Type, mod: *Module) Type {2178pub fn errorUnionPayload(ty: Type, zcu: *const Zcu) Type {
2059 return Type.fromInterned(mod.intern_pool.indexToKey(ty.toIntern()).error_union_type.payload_type);2179 return Type.fromInterned(zcu.intern_pool.indexToKey(ty.toIntern()).error_union_type.payload_type);
2060}2180}
20612181
2062/// Asserts that the type is an error union.2182/// Asserts that the type is an error union.
2063pub fn errorUnionSet(ty: Type, mod: *Module) Type {2183pub fn errorUnionSet(ty: Type, zcu: *const Zcu) Type {
2064 return Type.fromInterned(mod.intern_pool.errorUnionSet(ty.toIntern()));2184 return Type.fromInterned(zcu.intern_pool.errorUnionSet(ty.toIntern()));
2065}2185}
20662186
2067/// Returns false for unresolved inferred error sets.2187/// Returns false for unresolved inferred error sets.
2068pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {2188pub fn errorSetIsEmpty(ty: Type, zcu: *const Zcu) bool {
2069 const ip = &mod.intern_pool;2189 const ip = &zcu.intern_pool;
2070 return switch (ty.toIntern()) {2190 return switch (ty.toIntern()) {
2071 .anyerror_type, .adhoc_inferred_error_set_type => false,2191 .anyerror_type, .adhoc_inferred_error_set_type => false,
2072 else => switch (ip.indexToKey(ty.toIntern())) {2192 else => switch (ip.indexToKey(ty.toIntern())) {
...@@ -2083,20 +2203,20 @@ pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {...@@ -2083,20 +2203,20 @@ pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
2083/// Returns true if it is an error set that includes anyerror, false otherwise.2203/// Returns true if it is an error set that includes anyerror, false otherwise.
2084/// Note that the result may be a false negative if the type did not get error set2204/// Note that the result may be a false negative if the type did not get error set
2085/// resolution prior to this call.2205/// resolution prior to this call.
2086pub fn isAnyError(ty: Type, mod: *Module) bool {2206pub fn isAnyError(ty: Type, zcu: *const Zcu) bool {
2087 const ip = &mod.intern_pool;2207 const ip = &zcu.intern_pool;
2088 return switch (ty.toIntern()) {2208 return switch (ty.toIntern()) {
2089 .anyerror_type => true,2209 .anyerror_type => true,
2090 .adhoc_inferred_error_set_type => false,2210 .adhoc_inferred_error_set_type => false,
2091 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {2211 else => switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
2092 .inferred_error_set_type => |i| ip.funcIesResolvedUnordered(i) == .anyerror_type,2212 .inferred_error_set_type => |i| ip.funcIesResolvedUnordered(i) == .anyerror_type,
2093 else => false,2213 else => false,
2094 },2214 },
2095 };2215 };
2096}2216}
20972217
2098pub fn isError(ty: Type, mod: *const Module) bool {2218pub fn isError(ty: Type, zcu: *const Zcu) bool {
2099 return switch (ty.zigTypeTag(mod)) {2219 return switch (ty.zigTypeTag(zcu)) {
2100 .ErrorUnion, .ErrorSet => true,2220 .ErrorUnion, .ErrorSet => true,
2101 else => false,2221 else => false,
2102 };2222 };
...@@ -2127,8 +2247,8 @@ pub fn errorSetHasFieldIp(...@@ -2127,8 +2247,8 @@ pub fn errorSetHasFieldIp(
2127/// Returns whether ty, which must be an error set, includes an error `name`.2247/// Returns whether ty, which must be an error set, includes an error `name`.
2128/// Might return a false negative if `ty` is an inferred error set and not fully2248/// Might return a false negative if `ty` is an inferred error set and not fully
2129/// resolved yet.2249/// resolved yet.
2130pub fn errorSetHasField(ty: Type, name: []const u8, mod: *Module) bool {2250pub fn errorSetHasField(ty: Type, name: []const u8, zcu: *const Zcu) bool {
2131 const ip = &mod.intern_pool;2251 const ip = &zcu.intern_pool;
2132 return switch (ty.toIntern()) {2252 return switch (ty.toIntern()) {
2133 .anyerror_type => true,2253 .anyerror_type => true,
2134 else => switch (ip.indexToKey(ty.toIntern())) {2254 else => switch (ip.indexToKey(ty.toIntern())) {
...@@ -2152,20 +2272,20 @@ pub fn errorSetHasField(ty: Type, name: []const u8, mod: *Module) bool {...@@ -2152,20 +2272,20 @@ pub fn errorSetHasField(ty: Type, name: []const u8, mod: *Module) bool {
2152}2272}
21532273
2154/// Asserts the type is an array or vector or struct.2274/// Asserts the type is an array or vector or struct.
2155pub fn arrayLen(ty: Type, mod: *const Module) u64 {2275pub fn arrayLen(ty: Type, zcu: *const Zcu) u64 {
2156 return ty.arrayLenIp(&mod.intern_pool);2276 return ty.arrayLenIp(&zcu.intern_pool);
2157}2277}
21582278
2159pub fn arrayLenIp(ty: Type, ip: *const InternPool) u64 {2279pub fn arrayLenIp(ty: Type, ip: *const InternPool) u64 {
2160 return ip.aggregateTypeLen(ty.toIntern());2280 return ip.aggregateTypeLen(ty.toIntern());
2161}2281}
21622282
2163pub fn arrayLenIncludingSentinel(ty: Type, mod: *const Module) u64 {2283pub fn arrayLenIncludingSentinel(ty: Type, zcu: *const Zcu) u64 {
2164 return mod.intern_pool.aggregateTypeLenIncludingSentinel(ty.toIntern());2284 return zcu.intern_pool.aggregateTypeLenIncludingSentinel(ty.toIntern());
2165}2285}
21662286
2167pub fn vectorLen(ty: Type, mod: *const Module) u32 {2287pub fn vectorLen(ty: Type, zcu: *const Zcu) u32 {
2168 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {2288 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
2169 .vector_type => |vector_type| vector_type.len,2289 .vector_type => |vector_type| vector_type.len,
2170 .anon_struct_type => |tuple| @intCast(tuple.types.len),2290 .anon_struct_type => |tuple| @intCast(tuple.types.len),
2171 else => unreachable,2291 else => unreachable,
...@@ -2173,8 +2293,8 @@ pub fn vectorLen(ty: Type, mod: *const Module) u32 {...@@ -2173,8 +2293,8 @@ pub fn vectorLen(ty: Type, mod: *const Module) u32 {
2173}2293}
21742294
2175/// Asserts the type is an array, pointer or vector.2295/// Asserts the type is an array, pointer or vector.
2176pub fn sentinel(ty: Type, mod: *const Module) ?Value {2296pub fn sentinel(ty: Type, zcu: *const Zcu) ?Value {
2177 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {2297 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
2178 .vector_type,2298 .vector_type,
2179 .struct_type,2299 .struct_type,
2180 .anon_struct_type,2300 .anon_struct_type,
...@@ -2188,17 +2308,17 @@ pub fn sentinel(ty: Type, mod: *const Module) ?Value {...@@ -2188,17 +2308,17 @@ pub fn sentinel(ty: Type, mod: *const Module) ?Value {
2188}2308}
21892309
2190/// Returns true if and only if the type is a fixed-width integer.2310/// 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 {
2192 return self.toIntern() != .comptime_int_type and2312 return self.toIntern() != .comptime_int_type and
2193 mod.intern_pool.isIntegerType(self.toIntern());2313 zcu.intern_pool.isIntegerType(self.toIntern());
2194}2314}
21952315
2196/// Returns true if and only if the type is a fixed-width, signed integer.2316/// 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 {
2198 return switch (ty.toIntern()) {2318 return switch (ty.toIntern()) {
2199 .c_char_type => mod.getTarget().charSignedness() == .signed,2319 .c_char_type => zcu.getTarget().charSignedness() == .signed,
2200 .isize_type, .c_short_type, .c_int_type, .c_long_type, .c_longlong_type => true,2320 .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())) {
2202 .int_type => |int_type| int_type.signedness == .signed,2322 .int_type => |int_type| int_type.signedness == .signed,
2203 else => false,2323 else => false,
2204 },2324 },
...@@ -2206,11 +2326,11 @@ pub fn isSignedInt(ty: Type, mod: *const Module) bool {...@@ -2206,11 +2326,11 @@ pub fn isSignedInt(ty: Type, mod: *const Module) bool {
2206}2326}
22072327
2208/// Returns true if and only if the type is a fixed-width, unsigned integer.2328/// 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 {
2210 return switch (ty.toIntern()) {2330 return switch (ty.toIntern()) {
2211 .c_char_type => mod.getTarget().charSignedness() == .unsigned,2331 .c_char_type => zcu.getTarget().charSignedness() == .unsigned,
2212 .usize_type, .c_ushort_type, .c_uint_type, .c_ulong_type, .c_ulonglong_type => true,2332 .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())) {
2214 .int_type => |int_type| int_type.signedness == .unsigned,2334 .int_type => |int_type| int_type.signedness == .unsigned,
2215 else => false,2335 else => false,
2216 },2336 },
...@@ -2219,27 +2339,27 @@ pub fn isUnsignedInt(ty: Type, mod: *const Module) bool {...@@ -2219,27 +2339,27 @@ pub fn isUnsignedInt(ty: Type, mod: *const Module) bool {
22192339
2220/// Returns true for integers, enums, error sets, and packed structs.2340/// Returns true for integers, enums, error sets, and packed structs.
2221/// If this function returns true, then intInfo() can be called on the type.2341/// If this function returns true, then intInfo() can be called on the type.
2222pub fn isAbiInt(ty: Type, mod: *Module) bool {2342pub fn isAbiInt(ty: Type, zcu: *const Zcu) bool {
2223 return switch (ty.zigTypeTag(mod)) {2343 return switch (ty.zigTypeTag(zcu)) {
2224 .Int, .Enum, .ErrorSet => true,2344 .Int, .Enum, .ErrorSet => true,
2225 .Struct => ty.containerLayout(mod) == .@"packed",2345 .Struct => ty.containerLayout(zcu) == .@"packed",
2226 else => false,2346 else => false,
2227 };2347 };
2228}2348}
22292349
2230/// Asserts the type is an integer, enum, error set, or vector of one of them.2350/// 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 {2351pub fn intInfo(starting_ty: Type, zcu: *const Zcu) InternPool.Key.IntType {
2232 const ip = &mod.intern_pool;2352 const ip = &zcu.intern_pool;
2233 const target = mod.getTarget();2353 const target = zcu.getTarget();
2234 var ty = starting_ty;2354 var ty = starting_ty;
22352355
2236 while (true) switch (ty.toIntern()) {2356 while (true) switch (ty.toIntern()) {
2237 .anyerror_type, .adhoc_inferred_error_set_type => {2357 .anyerror_type, .adhoc_inferred_error_set_type => {
2238 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };2358 return .{ .signedness = .unsigned, .bits = zcu.errorSetBits() };
2239 },2359 },
2240 .usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },2360 .usize_type => return .{ .signedness = .unsigned, .bits = target.ptrBitWidth() },
2241 .isize_type => return .{ .signedness = .signed, .bits = target.ptrBitWidth() },2361 .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) },
2243 .c_short_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.short) },2363 .c_short_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.short) },
2244 .c_ushort_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ushort) },2364 .c_ushort_type => return .{ .signedness = .unsigned, .bits = target.cTypeBitSize(.ushort) },
2245 .c_int_type => return .{ .signedness = .signed, .bits = target.cTypeBitSize(.int) },2365 .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 {...@@ -2255,7 +2375,7 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
2255 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),2375 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),
22562376
2257 .error_set_type, .inferred_error_set_type => {2377 .error_set_type, .inferred_error_set_type => {
2258 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };2378 return .{ .signedness = .unsigned, .bits = zcu.errorSetBits() };
2259 },2379 },
22602380
2261 .anon_struct_type => unreachable,2381 .anon_struct_type => unreachable,
...@@ -2363,35 +2483,35 @@ pub fn floatBits(ty: Type, target: Target) u16 {...@@ -2363,35 +2483,35 @@ pub fn floatBits(ty: Type, target: Target) u16 {
2363}2483}
23642484
2365/// Asserts the type is a function or a function pointer.2485/// Asserts the type is a function or a function pointer.
2366pub fn fnReturnType(ty: Type, mod: *Module) Type {2486pub fn fnReturnType(ty: Type, zcu: *const Zcu) Type {
2367 return Type.fromInterned(mod.intern_pool.funcTypeReturnType(ty.toIntern()));2487 return Type.fromInterned(zcu.intern_pool.funcTypeReturnType(ty.toIntern()));
2368}2488}
23692489
2370/// Asserts the type is a function.2490/// Asserts the type is a function.
2371pub fn fnCallingConvention(ty: Type, mod: *Module) std.builtin.CallingConvention {2491pub fn fnCallingConvention(ty: Type, zcu: *const Zcu) std.builtin.CallingConvention {
2372 return mod.intern_pool.indexToKey(ty.toIntern()).func_type.cc;2492 return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.cc;
2373}2493}
23742494
2375pub fn isValidParamType(self: Type, mod: *const Module) bool {2495pub fn isValidParamType(self: Type, zcu: *const Zcu) bool {
2376 return switch (self.zigTypeTagOrPoison(mod) catch return true) {2496 return switch (self.zigTypeTagOrPoison(zcu) catch return true) {
2377 .Opaque, .NoReturn => false,2497 .Opaque, .NoReturn => false,
2378 else => true,2498 else => true,
2379 };2499 };
2380}2500}
23812501
2382pub fn isValidReturnType(self: Type, mod: *const Module) bool {2502pub fn isValidReturnType(self: Type, zcu: *const Zcu) bool {
2383 return switch (self.zigTypeTagOrPoison(mod) catch return true) {2503 return switch (self.zigTypeTagOrPoison(zcu) catch return true) {
2384 .Opaque => false,2504 .Opaque => false,
2385 else => true,2505 else => true,
2386 };2506 };
2387}2507}
23882508
2389/// Asserts the type is a function.2509/// Asserts the type is a function.
2390pub fn fnIsVarArgs(ty: Type, mod: *Module) bool {2510pub fn fnIsVarArgs(ty: Type, zcu: *const Zcu) bool {
2391 return mod.intern_pool.indexToKey(ty.toIntern()).func_type.is_var_args;2511 return zcu.intern_pool.indexToKey(ty.toIntern()).func_type.is_var_args;
2392}2512}
23932513
2394pub fn isNumeric(ty: Type, mod: *const Module) bool {2514pub fn isNumeric(ty: Type, zcu: *const Zcu) bool {
2395 return switch (ty.toIntern()) {2515 return switch (ty.toIntern()) {
2396 .f16_type,2516 .f16_type,
2397 .f32_type,2517 .f32_type,
...@@ -2414,7 +2534,7 @@ pub fn isNumeric(ty: Type, mod: *const Module) bool {...@@ -2414,7 +2534,7 @@ pub fn isNumeric(ty: Type, mod: *const Module) bool {
2414 .c_ulonglong_type,2534 .c_ulonglong_type,
2415 => true,2535 => true,
24162536
2417 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {2537 else => switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
2418 .int_type => true,2538 .int_type => true,
2419 else => false,2539 else => false,
2420 },2540 },
...@@ -2424,9 +2544,9 @@ pub fn isNumeric(ty: Type, mod: *const Module) bool {...@@ -2424,9 +2544,9 @@ pub fn isNumeric(ty: Type, mod: *const Module) bool {
2424/// During semantic analysis, instead call `Sema.typeHasOnePossibleValue` which2544/// During semantic analysis, instead call `Sema.typeHasOnePossibleValue` which
2425/// resolves field types rather than asserting they are already resolved.2545/// resolves field types rather than asserting they are already resolved.
2426pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {2546pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2427 const mod = pt.zcu;2547 const zcu = pt.zcu;
2428 var ty = starting_type;2548 var ty = starting_type;
2429 const ip = &mod.intern_pool;2549 const ip = &zcu.intern_pool;
2430 while (true) switch (ty.toIntern()) {2550 while (true) switch (ty.toIntern()) {
2431 .empty_struct_type => return Value.empty_struct,2551 .empty_struct_type => return Value.empty_struct,
24322552
...@@ -2509,8 +2629,8 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2509,8 +2629,8 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2509 assert(struct_type.haveFieldTypes(ip));2629 assert(struct_type.haveFieldTypes(ip));
2510 if (struct_type.knownNonOpv(ip))2630 if (struct_type.knownNonOpv(ip))
2511 return null;2631 return null;
2512 const field_vals = try mod.gpa.alloc(InternPool.Index, struct_type.field_types.len);2632 const field_vals = try zcu.gpa.alloc(InternPool.Index, struct_type.field_types.len);
2513 defer mod.gpa.free(field_vals);2633 defer zcu.gpa.free(field_vals);
2514 for (field_vals, 0..) |*field_val, i_usize| {2634 for (field_vals, 0..) |*field_val, i_usize| {
2515 const i: u32 = @intCast(i_usize);2635 const i: u32 = @intCast(i_usize);
2516 if (struct_type.fieldIsComptime(ip, i)) {2636 if (struct_type.fieldIsComptime(ip, i)) {
...@@ -2539,8 +2659,8 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2539,8 +2659,8 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2539 // In this case the struct has all comptime-known fields and2659 // In this case the struct has all comptime-known fields and
2540 // therefore has one possible value.2660 // therefore has one possible value.
2541 // TODO: write something like getCoercedInts to avoid needing to dupe2661 // TODO: write something like getCoercedInts to avoid needing to dupe
2542 const duped_values = try mod.gpa.dupe(InternPool.Index, tuple.values.get(ip));2662 const duped_values = try zcu.gpa.dupe(InternPool.Index, tuple.values.get(ip));
2543 defer mod.gpa.free(duped_values);2663 defer zcu.gpa.free(duped_values);
2544 return Value.fromInterned(try pt.intern(.{ .aggregate = .{2664 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
2545 .ty = ty.toIntern(),2665 .ty = ty.toIntern(),
2546 .storage = .{ .elems = duped_values },2666 .storage = .{ .elems = duped_values },
...@@ -2583,7 +2703,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2583,7 +2703,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2583 return null;2703 return null;
2584 },2704 },
2585 .auto, .explicit => {2705 .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
2588 switch (enum_type.names.len) {2708 switch (enum_type.names.len) {
2589 0 => {2709 0 => {
...@@ -2635,17 +2755,25 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2635,17 +2755,25 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
2635 };2755 };
2636}2756}
26372757
2638/// During semantic analysis, instead call `Sema.typeRequiresComptime` which2758/// During semantic analysis, instead call `ty.comptimeOnlySema` which
2639/// resolves field types rather than asserting they are already resolved.2759/// resolves field types rather than asserting they are already resolved.
2640pub fn comptimeOnly(ty: Type, pt: Zcu.PerThread) bool {2760pub fn comptimeOnly(ty: Type, zcu: *Zcu) bool {
2641 return ty.comptimeOnlyAdvanced(pt, .normal) catch unreachable;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);
2642}2766}
26432767
2644/// `generic_poison` will return false.2768/// `generic_poison` will return false.
2645/// May return false negatives when structs and unions are having their field types resolved.2769/// 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 {2770pub fn comptimeOnlyInner(
2647 const mod = pt.zcu;2771 ty: Type,
2648 const ip = &mod.intern_pool;2772 comptime strat: ResolveStrat,
2773 zcu: *Zcu,
2774 tid: strat.Tid(),
2775) SemaError!bool {
2776 const ip = &zcu.intern_pool;
2649 return switch (ty.toIntern()) {2777 return switch (ty.toIntern()) {
2650 .empty_struct_type => false,2778 .empty_struct_type => false,
26512779
...@@ -2653,20 +2781,20 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2653,20 +2781,20 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
2653 .int_type => false,2781 .int_type => false,
2654 .ptr_type => |ptr_type| {2782 .ptr_type => |ptr_type| {
2655 const child_ty = Type.fromInterned(ptr_type.child);2783 const child_ty = Type.fromInterned(ptr_type.child);
2656 switch (child_ty.zigTypeTag(mod)) {2784 switch (child_ty.zigTypeTag(zcu)) {
2657 .Fn => return !try child_ty.fnHasRuntimeBitsAdvanced(pt, strat),2785 .Fn => return !try child_ty.fnHasRuntimeBitsInner(strat, zcu, tid),
2658 .Opaque => return false,2786 .Opaque => return false,
2659 else => return child_ty.comptimeOnlyAdvanced(pt, strat),2787 else => return child_ty.comptimeOnlyInner(strat, zcu, tid),
2660 }2788 }
2661 },2789 },
2662 .anyframe_type => |child| {2790 .anyframe_type => |child| {
2663 if (child == .none) return false;2791 if (child == .none) return false;
2664 return Type.fromInterned(child).comptimeOnlyAdvanced(pt, strat);2792 return Type.fromInterned(child).comptimeOnlyInner(strat, zcu, tid);
2665 },2793 },
2666 .array_type => |array_type| return Type.fromInterned(array_type.child).comptimeOnlyAdvanced(pt, strat),2794 .array_type => |array_type| return Type.fromInterned(array_type.child).comptimeOnlyInner(strat, zcu, tid),
2667 .vector_type => |vector_type| return Type.fromInterned(vector_type.child).comptimeOnlyAdvanced(pt, strat),2795 .vector_type => |vector_type| return Type.fromInterned(vector_type.child).comptimeOnlyInner(strat, zcu, tid),
2668 .opt_type => |child| return Type.fromInterned(child).comptimeOnlyAdvanced(pt, strat),2796 .opt_type => |child| return Type.fromInterned(child).comptimeOnlyInner(strat, zcu, tid),
2669 .error_union_type => |error_union_type| return Type.fromInterned(error_union_type.payload_type).comptimeOnlyAdvanced(pt, strat),2797 .error_union_type => |error_union_type| return Type.fromInterned(error_union_type.payload_type).comptimeOnlyInner(strat, zcu, tid),
26702798
2671 .error_set_type,2799 .error_set_type,
2672 .inferred_error_set_type,2800 .inferred_error_set_type,
...@@ -2732,13 +2860,14 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2732,13 +2860,14 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27322860
2733 errdefer struct_type.setRequiresComptime(ip, .unknown);2861 errdefer struct_type.setRequiresComptime(ip, .unknown);
27342862
2863 const pt = strat.pt(zcu, tid);
2735 try ty.resolveFields(pt);2864 try ty.resolveFields(pt);
27362865
2737 for (0..struct_type.field_types.len) |i_usize| {2866 for (0..struct_type.field_types.len) |i_usize| {
2738 const i: u32 = @intCast(i_usize);2867 const i: u32 = @intCast(i_usize);
2739 if (struct_type.fieldIsComptime(ip, i)) continue;2868 if (struct_type.fieldIsComptime(ip, i)) continue;
2740 const field_ty = struct_type.field_types.get(ip)[i];2869 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)) {
2742 // Note that this does not cause the layout to2871 // Note that this does not cause the layout to
2743 // be considered resolved. Comptime-only types2872 // be considered resolved. Comptime-only types
2744 // still maintain a layout of their2873 // still maintain a layout of their
...@@ -2757,7 +2886,7 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2757,7 +2886,7 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
2757 .anon_struct_type => |tuple| {2886 .anon_struct_type => |tuple| {
2758 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {2887 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
2759 const have_comptime_val = val != .none;2888 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;
2761 }2890 }
2762 return false;2891 return false;
2763 },2892 },
...@@ -2778,11 +2907,12 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2778,11 +2907,12 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27782907
2779 errdefer union_type.setRequiresComptime(ip, .unknown);2908 errdefer union_type.setRequiresComptime(ip, .unknown);
27802909
2910 const pt = strat.pt(zcu, tid);
2781 try ty.resolveFields(pt);2911 try ty.resolveFields(pt);
27822912
2783 for (0..union_type.field_types.len) |field_idx| {2913 for (0..union_type.field_types.len) |field_idx| {
2784 const field_ty = union_type.field_types.get(ip)[field_idx];2914 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)) {
2786 union_type.setRequiresComptime(ip, .yes);2916 union_type.setRequiresComptime(ip, .yes);
2787 return true;2917 return true;
2788 }2918 }
...@@ -2796,7 +2926,7 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2796,7 +2926,7 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
27962926
2797 .opaque_type => false,2927 .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
2801 // values, not types2931 // values, not types
2802 .undef,2932 .undef,
...@@ -2823,53 +2953,53 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve...@@ -2823,53 +2953,53 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, comptime strat: Resolve
2823 };2953 };
2824}2954}
28252955
2826pub fn isVector(ty: Type, mod: *const Module) bool {2956pub fn isVector(ty: Type, zcu: *const Zcu) bool {
2827 return ty.zigTypeTag(mod) == .Vector;2957 return ty.zigTypeTag(zcu) == .Vector;
2828}2958}
28292959
2830/// Returns 0 if not a vector, otherwise returns @bitSizeOf(Element) * vector_len.2960/// Returns 0 if not a vector, otherwise returns @bitSizeOf(Element) * vector_len.
2831pub fn totalVectorBits(ty: Type, pt: Zcu.PerThread) u64 {2961pub fn totalVectorBits(ty: Type, zcu: *Zcu) u64 {
2832 if (!ty.isVector(pt.zcu)) return 0;2962 if (!ty.isVector(zcu)) return 0;
2833 const v = pt.zcu.intern_pool.indexToKey(ty.toIntern()).vector_type;2963 const v = zcu.intern_pool.indexToKey(ty.toIntern()).vector_type;
2834 return v.len * Type.fromInterned(v.child).bitSize(pt);2964 return v.len * Type.fromInterned(v.child).bitSize(zcu);
2835}2965}
28362966
2837pub fn isArrayOrVector(ty: Type, mod: *const Module) bool {2967pub fn isArrayOrVector(ty: Type, zcu: *const Zcu) bool {
2838 return switch (ty.zigTypeTag(mod)) {2968 return switch (ty.zigTypeTag(zcu)) {
2839 .Array, .Vector => true,2969 .Array, .Vector => true,
2840 else => false,2970 else => false,
2841 };2971 };
2842}2972}
28432973
2844pub fn isIndexable(ty: Type, mod: *Module) bool {2974pub fn isIndexable(ty: Type, zcu: *const Zcu) bool {
2845 return switch (ty.zigTypeTag(mod)) {2975 return switch (ty.zigTypeTag(zcu)) {
2846 .Array, .Vector => true,2976 .Array, .Vector => true,
2847 .Pointer => switch (ty.ptrSize(mod)) {2977 .Pointer => switch (ty.ptrSize(zcu)) {
2848 .Slice, .Many, .C => true,2978 .Slice, .Many, .C => true,
2849 .One => switch (ty.childType(mod).zigTypeTag(mod)) {2979 .One => switch (ty.childType(zcu).zigTypeTag(zcu)) {
2850 .Array, .Vector => true,2980 .Array, .Vector => true,
2851 .Struct => ty.childType(mod).isTuple(mod),2981 .Struct => ty.childType(zcu).isTuple(zcu),
2852 else => false,2982 else => false,
2853 },2983 },
2854 },2984 },
2855 .Struct => ty.isTuple(mod),2985 .Struct => ty.isTuple(zcu),
2856 else => false,2986 else => false,
2857 };2987 };
2858}2988}
28592989
2860pub fn indexableHasLen(ty: Type, mod: *Module) bool {2990pub fn indexableHasLen(ty: Type, zcu: *const Zcu) bool {
2861 return switch (ty.zigTypeTag(mod)) {2991 return switch (ty.zigTypeTag(zcu)) {
2862 .Array, .Vector => true,2992 .Array, .Vector => true,
2863 .Pointer => switch (ty.ptrSize(mod)) {2993 .Pointer => switch (ty.ptrSize(zcu)) {
2864 .Many, .C => false,2994 .Many, .C => false,
2865 .Slice => true,2995 .Slice => true,
2866 .One => switch (ty.childType(mod).zigTypeTag(mod)) {2996 .One => switch (ty.childType(zcu).zigTypeTag(zcu)) {
2867 .Array, .Vector => true,2997 .Array, .Vector => true,
2868 .Struct => ty.childType(mod).isTuple(mod),2998 .Struct => ty.childType(zcu).isTuple(zcu),
2869 else => false,2999 else => false,
2870 },3000 },
2871 },3001 },
2872 .Struct => ty.isTuple(mod),3002 .Struct => ty.isTuple(zcu),
2873 else => false,3003 else => false,
2874 };3004 };
2875}3005}
...@@ -2898,9 +3028,9 @@ pub fn getParentNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex...@@ -2898,9 +3028,9 @@ pub fn getParentNamespace(ty: Type, zcu: *Zcu) InternPool.OptionalNamespaceIndex
28983028
2899// Works for vectors and vectors of integers.3029// Works for vectors and vectors of integers.
2900pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {3030pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2901 const mod = pt.zcu;3031 const zcu = pt.zcu;
2902 const scalar = try minIntScalar(ty.scalarType(mod), pt, dest_ty.scalarType(mod));3032 const scalar = try minIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
2903 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{3033 return if (ty.zigTypeTag(zcu) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
2904 .ty = dest_ty.toIntern(),3034 .ty = dest_ty.toIntern(),
2905 .storage = .{ .repeated_elem = scalar.toIntern() },3035 .storage = .{ .repeated_elem = scalar.toIntern() },
2906 } })) else scalar;3036 } })) else scalar;
...@@ -2908,8 +3038,8 @@ pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {...@@ -2908,8 +3038,8 @@ pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
29083038
2909/// Asserts that the type is an integer.3039/// Asserts that the type is an integer.
2910pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {3040pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2911 const mod = pt.zcu;3041 const zcu = pt.zcu;
2912 const info = ty.intInfo(mod);3042 const info = ty.intInfo(zcu);
2913 if (info.signedness == .unsigned) return pt.intValue(dest_ty, 0);3043 if (info.signedness == .unsigned) return pt.intValue(dest_ty, 0);
2914 if (info.bits == 0) return pt.intValue(dest_ty, -1);3044 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 {...@@ -2918,7 +3048,7 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2918 return pt.intValue(dest_ty, n);3048 return pt.intValue(dest_ty, n);
2919 }3049 }
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);
2922 defer res.deinit();3052 defer res.deinit();
29233053
2924 try res.setTwosCompIntLimit(.min, info.signedness, info.bits);3054 try res.setTwosCompIntLimit(.min, info.signedness, info.bits);
...@@ -2929,9 +3059,9 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {...@@ -2929,9 +3059,9 @@ pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2929// Works for vectors and vectors of integers.3059// Works for vectors and vectors of integers.
2930/// The returned Value will have type dest_ty.3060/// The returned Value will have type dest_ty.
2931pub fn maxInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {3061pub fn maxInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2932 const mod = pt.zcu;3062 const zcu = pt.zcu;
2933 const scalar = try maxIntScalar(ty.scalarType(mod), pt, dest_ty.scalarType(mod));3063 const scalar = try maxIntScalar(ty.scalarType(zcu), pt, dest_ty.scalarType(zcu));
2934 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{3064 return if (ty.zigTypeTag(zcu) == .Vector) Value.fromInterned(try pt.intern(.{ .aggregate = .{
2935 .ty = dest_ty.toIntern(),3065 .ty = dest_ty.toIntern(),
2936 .storage = .{ .repeated_elem = scalar.toIntern() },3066 .storage = .{ .repeated_elem = scalar.toIntern() },
2937 } })) else scalar;3067 } })) else scalar;
...@@ -2973,17 +3103,17 @@ pub fn maxIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {...@@ -2973,17 +3103,17 @@ pub fn maxIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value {
2973}3103}
29743104
2975/// Asserts the type is an enum or a union.3105/// Asserts the type is an enum or a union.
2976pub fn intTagType(ty: Type, mod: *Module) Type {3106pub fn intTagType(ty: Type, zcu: *const Zcu) Type {
2977 const ip = &mod.intern_pool;3107 const ip = &zcu.intern_pool;
2978 return switch (ip.indexToKey(ty.toIntern())) {3108 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),
2980 .enum_type => Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty),3110 .enum_type => Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty),
2981 else => unreachable,3111 else => unreachable,
2982 };3112 };
2983}3113}
29843114
2985pub fn isNonexhaustiveEnum(ty: Type, mod: *Module) bool {3115pub fn isNonexhaustiveEnum(ty: Type, zcu: *const Zcu) bool {
2986 const ip = &mod.intern_pool;3116 const ip = &zcu.intern_pool;
2987 return switch (ip.indexToKey(ty.toIntern())) {3117 return switch (ip.indexToKey(ty.toIntern())) {
2988 .enum_type => switch (ip.loadEnumType(ty.toIntern()).tag_mode) {3118 .enum_type => switch (ip.loadEnumType(ty.toIntern()).tag_mode) {
2989 .nonexhaustive => true,3119 .nonexhaustive => true,
...@@ -2995,8 +3125,8 @@ pub fn isNonexhaustiveEnum(ty: Type, mod: *Module) bool {...@@ -2995,8 +3125,8 @@ pub fn isNonexhaustiveEnum(ty: Type, mod: *Module) bool {
29953125
2996// Asserts that `ty` is an error set and not `anyerror`.3126// Asserts that `ty` is an error set and not `anyerror`.
2997// Asserts that `ty` is resolved if it is an inferred error set.3127// Asserts that `ty` is resolved if it is an inferred error set.
2998pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Slice {3128pub fn errorSetNames(ty: Type, zcu: *const Zcu) InternPool.NullTerminatedString.Slice {
2999 const ip = &mod.intern_pool;3129 const ip = &zcu.intern_pool;
3000 return switch (ip.indexToKey(ty.toIntern())) {3130 return switch (ip.indexToKey(ty.toIntern())) {
3001 .error_set_type => |x| x.names,3131 .error_set_type => |x| x.names,
3002 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {3132 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
...@@ -3008,21 +3138,21 @@ pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Sli...@@ -3008,21 +3138,21 @@ pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Sli
3008 };3138 };
3009}3139}
30103140
3011pub fn enumFields(ty: Type, mod: *Module) InternPool.NullTerminatedString.Slice {3141pub fn enumFields(ty: Type, zcu: *const Zcu) InternPool.NullTerminatedString.Slice {
3012 return mod.intern_pool.loadEnumType(ty.toIntern()).names;3142 return zcu.intern_pool.loadEnumType(ty.toIntern()).names;
3013}3143}
30143144
3015pub fn enumFieldCount(ty: Type, mod: *Module) usize {3145pub fn enumFieldCount(ty: Type, zcu: *const Zcu) usize {
3016 return mod.intern_pool.loadEnumType(ty.toIntern()).names.len;3146 return zcu.intern_pool.loadEnumType(ty.toIntern()).names.len;
3017}3147}
30183148
3019pub fn enumFieldName(ty: Type, field_index: usize, mod: *Module) InternPool.NullTerminatedString {3149pub fn enumFieldName(ty: Type, field_index: usize, zcu: *const Zcu) InternPool.NullTerminatedString {
3020 const ip = &mod.intern_pool;3150 const ip = &zcu.intern_pool;
3021 return ip.loadEnumType(ty.toIntern()).names.get(ip)[field_index];3151 return ip.loadEnumType(ty.toIntern()).names.get(ip)[field_index];
3022}3152}
30233153
3024pub fn enumFieldIndex(ty: Type, field_name: InternPool.NullTerminatedString, mod: *Module) ?u32 {3154pub fn enumFieldIndex(ty: Type, field_name: InternPool.NullTerminatedString, zcu: *const Zcu) ?u32 {
3025 const ip = &mod.intern_pool;3155 const ip = &zcu.intern_pool;
3026 const enum_type = ip.loadEnumType(ty.toIntern());3156 const enum_type = ip.loadEnumType(ty.toIntern());
3027 return enum_type.nameIndex(ip, field_name);3157 return enum_type.nameIndex(ip, field_name);
3028}3158}
...@@ -3030,8 +3160,8 @@ pub fn enumFieldIndex(ty: Type, field_name: InternPool.NullTerminatedString, mod...@@ -3030,8 +3160,8 @@ pub fn enumFieldIndex(ty: Type, field_name: InternPool.NullTerminatedString, mod
3030/// Asserts `ty` is an enum. `enum_tag` can either be `enum_field_index` or3160/// Asserts `ty` is an enum. `enum_tag` can either be `enum_field_index` or
3031/// an integer which represents the enum value. Returns the field index in3161/// an integer which represents the enum value. Returns the field index in
3032/// declaration order, or `null` if `enum_tag` does not match any field.3162/// declaration order, or `null` if `enum_tag` does not match any field.
3033pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {3163pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, zcu: *const Zcu) ?u32 {
3034 const ip = &mod.intern_pool;3164 const ip = &zcu.intern_pool;
3035 const enum_type = ip.loadEnumType(ty.toIntern());3165 const enum_type = ip.loadEnumType(ty.toIntern());
3036 const int_tag = switch (ip.indexToKey(enum_tag.toIntern())) {3166 const int_tag = switch (ip.indexToKey(enum_tag.toIntern())) {
3037 .int => enum_tag.toIntern(),3167 .int => enum_tag.toIntern(),
...@@ -3043,8 +3173,8 @@ pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {...@@ -3043,8 +3173,8 @@ pub fn enumTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {
3043}3173}
30443174
3045/// Returns none in the case of a tuple which uses the integer index as the field name.3175/// 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 {3176pub fn structFieldName(ty: Type, index: usize, zcu: *const Zcu) InternPool.OptionalNullTerminatedString {
3047 const ip = &mod.intern_pool;3177 const ip = &zcu.intern_pool;
3048 return switch (ip.indexToKey(ty.toIntern())) {3178 return switch (ip.indexToKey(ty.toIntern())) {
3049 .struct_type => ip.loadStructType(ty.toIntern()).fieldName(ip, index),3179 .struct_type => ip.loadStructType(ty.toIntern()).fieldName(ip, index),
3050 .anon_struct_type => |anon_struct| anon_struct.fieldName(ip, index),3180 .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...@@ -3052,8 +3182,8 @@ pub fn structFieldName(ty: Type, index: usize, mod: *Module) InternPool.Optional
3052 };3182 };
3053}3183}
30543184
3055pub fn structFieldCount(ty: Type, mod: *Module) u32 {3185pub fn structFieldCount(ty: Type, zcu: *const Zcu) u32 {
3056 const ip = &mod.intern_pool;3186 const ip = &zcu.intern_pool;
3057 return switch (ip.indexToKey(ty.toIntern())) {3187 return switch (ip.indexToKey(ty.toIntern())) {
3058 .struct_type => ip.loadStructType(ty.toIntern()).field_types.len,3188 .struct_type => ip.loadStructType(ty.toIntern()).field_types.len,
3059 .anon_struct_type => |anon_struct| anon_struct.types.len,3189 .anon_struct_type => |anon_struct| anon_struct.types.len,
...@@ -3061,9 +3191,9 @@ pub fn structFieldCount(ty: Type, mod: *Module) u32 {...@@ -3061,9 +3191,9 @@ pub fn structFieldCount(ty: Type, mod: *Module) u32 {
3061 };3191 };
3062}3192}
30633193
3064/// Supports structs and unions.3194/// Returns the field type. Supports structs and unions.
3065pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {3195pub fn fieldType(ty: Type, index: usize, zcu: *const Zcu) Type {
3066 const ip = &mod.intern_pool;3196 const ip = &zcu.intern_pool;
3067 return switch (ip.indexToKey(ty.toIntern())) {3197 return switch (ip.indexToKey(ty.toIntern())) {
3068 .struct_type => Type.fromInterned(ip.loadStructType(ty.toIntern()).field_types.get(ip)[index]),3198 .struct_type => Type.fromInterned(ip.loadStructType(ty.toIntern()).field_types.get(ip)[index]),
3069 .union_type => {3199 .union_type => {
...@@ -3075,33 +3205,150 @@ pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {...@@ -3075,33 +3205,150 @@ pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {
3075 };3205 };
3076}3206}
30773207
3078pub fn structFieldAlign(ty: Type, index: usize, pt: Zcu.PerThread) Alignment {3208pub fn fieldAlignment(ty: Type, index: usize, zcu: *Zcu) Alignment {
3079 return ty.structFieldAlignAdvanced(index, pt, .normal) catch unreachable;3209 return ty.fieldAlignmentInner(index, .normal, zcu, {}) catch unreachable;
3080}3210}
30813211
3082pub fn structFieldAlignAdvanced(ty: Type, index: usize, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Alignment {3212pub fn fieldAlignmentSema(ty: Type, index: usize, pt: Zcu.PerThread) SemaError!Alignment {
3083 const ip = &pt.zcu.intern_pool;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;
3084 switch (ip.indexToKey(ty.toIntern())) {3229 switch (ip.indexToKey(ty.toIntern())) {
3085 .struct_type => {3230 .struct_type => {
3086 const struct_type = ip.loadStructType(ty.toIntern());3231 const struct_type = ip.loadStructType(ty.toIntern());
3087 assert(struct_type.layout != .@"packed");3232 assert(struct_type.layout != .@"packed");
3088 const explicit_align = struct_type.fieldAlign(ip, index);3233 const explicit_align = struct_type.fieldAlign(ip, index);
3089 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[index]);3234 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);
3091 },3236 },
3092 .anon_struct_type => |anon_struct| {3237 .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;
3094 },3243 },
3095 .union_type => {3244 .union_type => {
3096 const union_obj = ip.loadUnionType(ty.toIntern());3245 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);
3098 },3251 },
3099 else => unreachable,3252 else => unreachable,
3100 }3253 }
3101}3254}
31023255
3103pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value {3256/// Returns the alignment of a non-packed struct field. Assert the layout is not packed.
3104 const ip = &mod.intern_pool;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;
3105 switch (ip.indexToKey(ty.toIntern())) {3352 switch (ip.indexToKey(ty.toIntern())) {
3106 .struct_type => {3353 .struct_type => {
3107 const struct_type = ip.loadStructType(ty.toIntern());3354 const struct_type = ip.loadStructType(ty.toIntern());
...@@ -3121,8 +3368,8 @@ pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value {...@@ -3121,8 +3368,8 @@ pub fn structFieldDefaultValue(ty: Type, index: usize, mod: *Module) Value {
3121}3368}
31223369
3123pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Value {3370pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Value {
3124 const mod = pt.zcu;3371 const zcu = pt.zcu;
3125 const ip = &mod.intern_pool;3372 const ip = &zcu.intern_pool;
3126 switch (ip.indexToKey(ty.toIntern())) {3373 switch (ip.indexToKey(ty.toIntern())) {
3127 .struct_type => {3374 .struct_type => {
3128 const struct_type = ip.loadStructType(ty.toIntern());3375 const struct_type = ip.loadStructType(ty.toIntern());
...@@ -3145,8 +3392,8 @@ pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Val...@@ -3145,8 +3392,8 @@ pub fn structFieldValueComptime(ty: Type, pt: Zcu.PerThread, index: usize) !?Val
3145 }3392 }
3146}3393}
31473394
3148pub fn structFieldIsComptime(ty: Type, index: usize, mod: *Module) bool {3395pub fn structFieldIsComptime(ty: Type, index: usize, zcu: *const Zcu) bool {
3149 const ip = &mod.intern_pool;3396 const ip = &zcu.intern_pool;
3150 return switch (ip.indexToKey(ty.toIntern())) {3397 return switch (ip.indexToKey(ty.toIntern())) {
3151 .struct_type => ip.loadStructType(ty.toIntern()).fieldIsComptime(ip, index),3398 .struct_type => ip.loadStructType(ty.toIntern()).fieldIsComptime(ip, index),
3152 .anon_struct_type => |anon_struct| anon_struct.values.get(ip)[index] != .none,3399 .anon_struct_type => |anon_struct| anon_struct.values.get(ip)[index] != .none,
...@@ -3160,9 +3407,12 @@ pub const FieldOffset = struct {...@@ -3160,9 +3407,12 @@ pub const FieldOffset = struct {
3160};3407};
31613408
3162/// Supports structs and unions.3409/// Supports structs and unions.
3163pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {3410pub fn structFieldOffset(
3164 const mod = pt.zcu;3411 ty: Type,
3165 const ip = &mod.intern_pool;3412 index: usize,
3413 zcu: *Zcu,
3414) u64 {
3415 const ip = &zcu.intern_pool;
3166 switch (ip.indexToKey(ty.toIntern())) {3416 switch (ip.indexToKey(ty.toIntern())) {
3167 .struct_type => {3417 .struct_type => {
3168 const struct_type = ip.loadStructType(ty.toIntern());3418 const struct_type = ip.loadStructType(ty.toIntern());
...@@ -3176,17 +3426,17 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {...@@ -3176,17 +3426,17 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
3176 var big_align: Alignment = .none;3426 var big_align: Alignment = .none;
31773427
3178 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {3428 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)) {
3180 // comptime field3430 // comptime field
3181 if (i == index) return offset;3431 if (i == index) return offset;
3182 continue;3432 continue;
3183 }3433 }
31843434
3185 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);3435 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
3186 big_align = big_align.max(field_align);3436 big_align = big_align.max(field_align);
3187 offset = field_align.forward(offset);3437 offset = field_align.forward(offset);
3188 if (i == index) return offset;3438 if (i == index) return offset;
3189 offset += Type.fromInterned(field_ty).abiSize(pt);3439 offset += Type.fromInterned(field_ty).abiSize(zcu);
3190 }3440 }
3191 offset = big_align.max(.@"1").forward(offset);3441 offset = big_align.max(.@"1").forward(offset);
3192 return offset;3442 return offset;
...@@ -3196,7 +3446,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {...@@ -3196,7 +3446,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
3196 const union_type = ip.loadUnionType(ty.toIntern());3446 const union_type = ip.loadUnionType(ty.toIntern());
3197 if (!union_type.hasTag(ip))3447 if (!union_type.hasTag(ip))
3198 return 0;3448 return 0;
3199 const layout = pt.getUnionLayout(union_type);3449 const layout = Type.getUnionLayout(union_type, zcu);
3200 if (layout.tag_align.compare(.gte, layout.payload_align)) {3450 if (layout.tag_align.compare(.gte, layout.payload_align)) {
3201 // {Tag, Payload}3451 // {Tag, Payload}
3202 return layout.payload_align.forward(layout.tag_size);3452 return layout.payload_align.forward(layout.tag_size);
...@@ -3210,7 +3460,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {...@@ -3210,7 +3460,7 @@ pub fn structFieldOffset(ty: Type, index: usize, pt: Zcu.PerThread) u64 {
3210 }3460 }
3211}3461}
32123462
3213pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {3463pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Zcu.LazySrcLoc {
3214 const ip = &zcu.intern_pool;3464 const ip = &zcu.intern_pool;
3215 return .{3465 return .{
3216 .base_node_inst = switch (ip.indexToKey(ty.toIntern())) {3466 .base_node_inst = switch (ip.indexToKey(ty.toIntern())) {
...@@ -3222,11 +3472,11 @@ pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {...@@ -3222,11 +3472,11 @@ pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {
3222 },3472 },
3223 else => return null,3473 else => return null,
3224 },3474 },
3225 .offset = Module.LazySrcLoc.Offset.nodeOffset(0),3475 .offset = Zcu.LazySrcLoc.Offset.nodeOffset(0),
3226 };3476 };
3227}3477}
32283478
3229pub fn srcLoc(ty: Type, zcu: *Zcu) Module.LazySrcLoc {3479pub fn srcLoc(ty: Type, zcu: *Zcu) Zcu.LazySrcLoc {
3230 return ty.srcLocOrNull(zcu).?;3480 return ty.srcLocOrNull(zcu).?;
3231}3481}
32323482
...@@ -3234,8 +3484,8 @@ pub fn isGenericPoison(ty: Type) bool {...@@ -3234,8 +3484,8 @@ pub fn isGenericPoison(ty: Type) bool {
3234 return ty.toIntern() == .generic_poison_type;3484 return ty.toIntern() == .generic_poison_type;
3235}3485}
32363486
3237pub fn isTuple(ty: Type, mod: *Module) bool {3487pub fn isTuple(ty: Type, zcu: *const Zcu) bool {
3238 const ip = &mod.intern_pool;3488 const ip = &zcu.intern_pool;
3239 return switch (ip.indexToKey(ty.toIntern())) {3489 return switch (ip.indexToKey(ty.toIntern())) {
3240 .struct_type => {3490 .struct_type => {
3241 const struct_type = ip.loadStructType(ty.toIntern());3491 const struct_type = ip.loadStructType(ty.toIntern());
...@@ -3248,16 +3498,16 @@ pub fn isTuple(ty: Type, mod: *Module) bool {...@@ -3248,16 +3498,16 @@ pub fn isTuple(ty: Type, mod: *Module) bool {
3248 };3498 };
3249}3499}
32503500
3251pub fn isAnonStruct(ty: Type, mod: *Module) bool {3501pub fn isAnonStruct(ty: Type, zcu: *const Zcu) bool {
3252 if (ty.toIntern() == .empty_struct_type) return true;3502 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())) {
3254 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len > 0,3504 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len > 0,
3255 else => false,3505 else => false,
3256 };3506 };
3257}3507}
32583508
3259pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {3509pub fn isTupleOrAnonStruct(ty: Type, zcu: *const Zcu) bool {
3260 const ip = &mod.intern_pool;3510 const ip = &zcu.intern_pool;
3261 return switch (ip.indexToKey(ty.toIntern())) {3511 return switch (ip.indexToKey(ty.toIntern())) {
3262 .struct_type => {3512 .struct_type => {
3263 const struct_type = ip.loadStructType(ty.toIntern());3513 const struct_type = ip.loadStructType(ty.toIntern());
...@@ -3270,15 +3520,15 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {...@@ -3270,15 +3520,15 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
3270 };3520 };
3271}3521}
32723522
3273pub fn isSimpleTuple(ty: Type, mod: *Module) bool {3523pub fn isSimpleTuple(ty: Type, zcu: *const Zcu) bool {
3274 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {3524 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
3275 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len == 0,3525 .anon_struct_type => |anon_struct_type| anon_struct_type.names.len == 0,
3276 else => false,3526 else => false,
3277 };3527 };
3278}3528}
32793529
3280pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool {3530pub fn isSimpleTupleOrAnonStruct(ty: Type, zcu: *const Zcu) bool {
3281 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {3531 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
3282 .anon_struct_type => true,3532 .anon_struct_type => true,
3283 else => false,3533 else => false,
3284 };3534 };
...@@ -3286,22 +3536,22 @@ pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool {...@@ -3286,22 +3536,22 @@ pub fn isSimpleTupleOrAnonStruct(ty: Type, mod: *Module) bool {
32863536
3287/// Traverses optional child types and error union payloads until the type3537/// Traverses optional child types and error union payloads until the type
3288/// is not a pointer. For `E!?u32`, returns `u32`; for `*u8`, returns `*u8`.3538/// 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 {
3290 var cur = ty;3540 var cur = ty;
3291 while (true) switch (cur.zigTypeTag(mod)) {3541 while (true) switch (cur.zigTypeTag(zcu)) {
3292 .Optional => cur = cur.optionalChild(mod),3542 .Optional => cur = cur.optionalChild(zcu),
3293 .ErrorUnion => cur = cur.errorUnionPayload(mod),3543 .ErrorUnion => cur = cur.errorUnionPayload(zcu),
3294 else => return cur,3544 else => return cur,
3295 };3545 };
3296}3546}
32973547
3298pub fn toUnsigned(ty: Type, pt: Zcu.PerThread) !Type {3548pub fn toUnsigned(ty: Type, pt: Zcu.PerThread) !Type {
3299 const mod = pt.zcu;3549 const zcu = pt.zcu;
3300 return switch (ty.zigTypeTag(mod)) {3550 return switch (ty.zigTypeTag(zcu)) {
3301 .Int => pt.intType(.unsigned, ty.intInfo(mod).bits),3551 .Int => pt.intType(.unsigned, ty.intInfo(zcu).bits),
3302 .Vector => try pt.vectorType(.{3552 .Vector => try pt.vectorType(.{
3303 .len = ty.vectorLen(mod),3553 .len = ty.vectorLen(zcu),
3304 .child = (try ty.childType(mod).toUnsigned(pt)).toIntern(),3554 .child = (try ty.childType(zcu).toUnsigned(pt)).toIntern(),
3305 }),3555 }),
3306 else => unreachable,3556 else => unreachable,
3307 };3557 };
...@@ -3397,16 +3647,16 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:...@@ -3397,16 +3647,16 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
33973647
3398 const zcu = pt.zcu;3648 const zcu = pt.zcu;
3399 const parent_ptr_info = parent_ptr_ty.ptrInfo(zcu);3649 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
3402 var bit_offset: u16 = 0;3652 var bit_offset: u16 = 0;
3403 var running_bits: u16 = 0;3653 var running_bits: u16 = 0;
3404 for (0..struct_ty.structFieldCount(zcu)) |i| {3654 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);
3406 if (i == field_idx) {3656 if (i == field_idx) {
3407 bit_offset = running_bits;3657 bit_offset = running_bits;
3408 }3658 }
3409 running_bits += @intCast(f_ty.bitSize(pt));3659 running_bits += @intCast(f_ty.bitSize(zcu));
3410 }3660 }
34113661
3412 const res_host_size: u16, const res_bit_offset: u16 = if (parent_ptr_info.packed_offset.host_size != 0)3662 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:...@@ -3423,9 +3673,9 @@ pub fn packedStructFieldPtrInfo(struct_ty: Type, parent_ptr_ty: Type, field_idx:
3423 // targets before adding the necessary complications to this code. This will not3673 // targets before adding the necessary complications to this code. This will not
3424 // cause miscompilations; it only means the field pointer uses bit masking when it3674 // cause miscompilations; it only means the field pointer uses bit masking when it
3425 // might not be strictly necessary.3675 // 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) {
3427 const byte_offset = res_bit_offset / 8;3677 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().?));
3429 return .{ .byte_ptr = .{3679 return .{ .byte_ptr = .{
3430 .offset = byte_offset,3680 .offset = byte_offset,
3431 .alignment = new_align,3681 .alignment = new_align,
...@@ -3661,11 +3911,12 @@ fn resolveStructInner(...@@ -3661,11 +3911,12 @@ fn resolveStructInner(
3661 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);3911 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);
3662 defer comptime_err_ret_trace.deinit();3912 defer comptime_err_ret_trace.deinit();
36633913
3914 const zir = zcu.namespacePtr(struct_obj.namespace.unwrap().?).fileScope(zcu).zir;
3664 var sema: Sema = .{3915 var sema: Sema = .{
3665 .pt = pt,3916 .pt = pt,
3666 .gpa = gpa,3917 .gpa = gpa,
3667 .arena = analysis_arena.allocator(),3918 .arena = analysis_arena.allocator(),
3668 .code = undefined, // This ZIR will not be used.3919 .code = zir,
3669 .owner = owner,3920 .owner = owner,
3670 .func_index = .none,3921 .func_index = .none,
3671 .func_is_naked = false,3922 .func_is_naked = false,
...@@ -3676,7 +3927,7 @@ fn resolveStructInner(...@@ -3676,7 +3927,7 @@ fn resolveStructInner(
3676 defer sema.deinit();3927 defer sema.deinit();
36773928
3678 (switch (resolution) {3929 (switch (resolution) {
3679 .fields => sema.resolveTypeFieldsStruct(ty.toIntern(), struct_obj),3930 .fields => sema.resolveStructFieldTypes(ty.toIntern(), struct_obj),
3680 .inits => sema.resolveStructFieldInits(ty),3931 .inits => sema.resolveStructFieldInits(ty),
3681 .alignment => sema.resolveStructAlignment(ty.toIntern(), struct_obj),3932 .alignment => sema.resolveStructAlignment(ty.toIntern(), struct_obj),
3682 .layout => sema.resolveStructLayout(ty),3933 .layout => sema.resolveStructLayout(ty),
...@@ -3714,11 +3965,12 @@ fn resolveUnionInner(...@@ -3714,11 +3965,12 @@ fn resolveUnionInner(
3714 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);3965 var comptime_err_ret_trace = std.ArrayList(Zcu.LazySrcLoc).init(gpa);
3715 defer comptime_err_ret_trace.deinit();3966 defer comptime_err_ret_trace.deinit();
37163967
3968 const zir = zcu.namespacePtr(union_obj.namespace).fileScope(zcu).zir;
3717 var sema: Sema = .{3969 var sema: Sema = .{
3718 .pt = pt,3970 .pt = pt,
3719 .gpa = gpa,3971 .gpa = gpa,
3720 .arena = analysis_arena.allocator(),3972 .arena = analysis_arena.allocator(),
3721 .code = undefined, // This ZIR will not be used.3973 .code = zir,
3722 .owner = owner,3974 .owner = owner,
3723 .func_index = .none,3975 .func_index = .none,
3724 .func_is_naked = false,3976 .func_is_naked = false,
...@@ -3729,7 +3981,7 @@ fn resolveUnionInner(...@@ -3729,7 +3981,7 @@ fn resolveUnionInner(
3729 defer sema.deinit();3981 defer sema.deinit();
37303982
3731 (switch (resolution) {3983 (switch (resolution) {
3732 .fields => sema.resolveTypeFieldsUnion(ty, union_obj),3984 .fields => sema.resolveUnionFieldTypes(ty, union_obj),
3733 .alignment => sema.resolveUnionAlignment(ty, union_obj),3985 .alignment => sema.resolveUnionAlignment(ty, union_obj),
3734 .layout => sema.resolveUnionLayout(ty),3986 .layout => sema.resolveUnionLayout(ty),
3735 .full => sema.resolveUnionFully(ty),3987 .full => sema.resolveUnionFully(ty),
...@@ -3744,6 +3996,65 @@ fn resolveUnionInner(...@@ -3744,6 +3996,65 @@ fn resolveUnionInner(
3744 };3996 };
3745}3997}
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
3747/// Returns the type of a pointer to an element.4058/// Returns the type of a pointer to an element.
3748/// Asserts that the type is a pointer, and that the element type is indexable.4059/// Asserts that the type is a pointer, and that the element type is indexable.
3749/// If the element index is comptime-known, it must be passed in `offset`.4060/// 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 {...@@ -3768,14 +4079,14 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {
3768 alignment: Alignment = .none,4079 alignment: Alignment = .none,
3769 vector_index: VI = .none,4080 vector_index: VI = .none,
3770 } = if (parent_ty.isVector(zcu) and ptr_info.flags.size == .One) blk: {4081 } = 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);
3772 if (elem_bits == 0) break :blk .{};4083 if (elem_bits == 0) break :blk .{};
3773 const is_packed = elem_bits < 8 or !std.math.isPowerOfTwo(elem_bits);4084 const is_packed = elem_bits < 8 or !std.math.isPowerOfTwo(elem_bits);
3774 if (!is_packed) break :blk .{};4085 if (!is_packed) break :blk .{};
37754086
3776 break :blk .{4087 break :blk .{
3777 .host_size = @intCast(parent_ty.arrayLen(zcu)),4088 .host_size = @intCast(parent_ty.arrayLen(zcu)),
3778 .alignment = parent_ty.abiAlignment(pt),4089 .alignment = parent_ty.abiAlignment(zcu),
3779 .vector_index = if (offset) |some| @enumFromInt(some) else .runtime,4090 .vector_index = if (offset) |some| @enumFromInt(some) else .runtime,
3780 };4091 };
3781 } else .{};4092 } else .{};
...@@ -3789,7 +4100,7 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {...@@ -3789,7 +4100,7 @@ pub fn elemPtrType(ptr_ty: Type, offset: ?usize, pt: Zcu.PerThread) !Type {
3789 }4100 }
3790 // If the addend is not a comptime-known value we can still count on4101 // If the addend is not a comptime-known value we can still count on
3791 // it being a multiple of the type size.4102 // 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;
3793 const addend = if (offset) |off| elem_size * off else elem_size;4104 const addend = if (offset) |off| elem_size * off else elem_size;
37944105
3795 // The resulting pointer is aligned to the lcd between the offset (an4106 // 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;...@@ -7,8 +7,6 @@ const BigIntMutable = std.math.big.int.Mutable;
7const Target = std.Target;7const Target = std.Target;
8const Allocator = std.mem.Allocator;8const Allocator = std.mem.Allocator;
9const Zcu = @import("Zcu.zig");9const Zcu = @import("Zcu.zig");
10/// Deprecated.
11const Module = Zcu;
12const Sema = @import("Sema.zig");10const Sema = @import("Sema.zig");
13const InternPool = @import("InternPool.zig");11const InternPool = @import("InternPool.zig");
14const print_value = @import("print_value.zig");12const print_value = @import("print_value.zig");
...@@ -65,19 +63,19 @@ pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_...@@ -65,19 +63,19 @@ pub fn fmtValueSemaFull(ctx: print_value.FormatContext) std.fmt.Formatter(print_
65/// Converts `val` to a null-terminated string stored in the InternPool.63/// Converts `val` to a null-terminated string stored in the InternPool.
66/// Asserts `val` is an array of `u8`64/// Asserts `val` is an array of `u8`
67pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTerminatedString {65pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
68 const mod = pt.zcu;66 const zcu = pt.zcu;
69 assert(ty.zigTypeTag(mod) == .Array);67 assert(ty.zigTypeTag(zcu) == .Array);
70 assert(ty.childType(mod).toIntern() == .u8_type);68 assert(ty.childType(zcu).toIntern() == .u8_type);
71 const ip = &mod.intern_pool;69 const ip = &zcu.intern_pool;
72 switch (mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {70 switch (zcu.intern_pool.indexToKey(val.toIntern()).aggregate.storage) {
73 .bytes => |bytes| return bytes.toNullTerminatedString(ty.arrayLen(mod), ip),71 .bytes => |bytes| return bytes.toNullTerminatedString(ty.arrayLen(zcu), ip),
74 .elems => return arrayToIpString(val, ty.arrayLen(mod), pt),72 .elems => return arrayToIpString(val, ty.arrayLen(zcu), pt),
75 .repeated_elem => |elem| {73 .repeated_elem => |elem| {
76 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt));74 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(zcu));
77 const len: u32 = @intCast(ty.arrayLen(mod));75 const len: u32 = @intCast(ty.arrayLen(zcu));
78 const strings = ip.getLocal(pt.tid).getMutableStrings(mod.gpa);76 const strings = ip.getLocal(pt.tid).getMutableStrings(zcu.gpa);
79 try strings.appendNTimes(.{byte}, len);77 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);
81 },79 },
82 }80 }
83}81}
...@@ -85,17 +83,17 @@ pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTermi...@@ -85,17 +83,17 @@ pub fn toIpString(val: Value, ty: Type, pt: Zcu.PerThread) !InternPool.NullTermi
85/// Asserts that the value is representable as an array of bytes.83/// Asserts that the value is representable as an array of bytes.
86/// Copies the value into a freshly allocated slice of memory, which is owned by the caller.84/// Copies the value into a freshly allocated slice of memory, which is owned by the caller.
87pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) ![]u8 {85pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) ![]u8 {
88 const mod = pt.zcu;86 const zcu = pt.zcu;
89 const ip = &mod.intern_pool;87 const ip = &zcu.intern_pool;
90 return switch (ip.indexToKey(val.toIntern())) {88 return switch (ip.indexToKey(val.toIntern())) {
91 .enum_literal => |enum_literal| allocator.dupe(u8, enum_literal.toSlice(ip)),89 .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),
93 .aggregate => |aggregate| switch (aggregate.storage) {91 .aggregate => |aggregate| switch (aggregate.storage) {
94 .bytes => |bytes| try allocator.dupe(u8, bytes.toSlice(ty.arrayLenIncludingSentinel(mod), ip)),92 .bytes => |bytes| try allocator.dupe(u8, bytes.toSlice(ty.arrayLenIncludingSentinel(zcu), ip)),
95 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, pt),93 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(zcu), allocator, pt),
96 .repeated_elem => |elem| {94 .repeated_elem => |elem| {
97 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(pt));95 const byte: u8 = @intCast(Value.fromInterned(elem).toUnsignedInt(zcu));
98 const result = try allocator.alloc(u8, @intCast(ty.arrayLen(mod)));96 const result = try allocator.alloc(u8, @intCast(ty.arrayLen(zcu)));
99 @memset(result, byte);97 @memset(result, byte);
100 return result;98 return result;
101 },99 },
...@@ -108,15 +106,15 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, pt: Zcu.Per...@@ -108,15 +106,15 @@ fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, pt: Zcu.Per
108 const result = try allocator.alloc(u8, @intCast(len));106 const result = try allocator.alloc(u8, @intCast(len));
109 for (result, 0..) |*elem, i| {107 for (result, 0..) |*elem, i| {
110 const elem_val = try val.elemValue(pt, i);108 const elem_val = try val.elemValue(pt, i);
111 elem.* = @intCast(elem_val.toUnsignedInt(pt));109 elem.* = @intCast(elem_val.toUnsignedInt(pt.zcu));
112 }110 }
113 return result;111 return result;
114}112}
115113
116fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.NullTerminatedString {114fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.NullTerminatedString {
117 const mod = pt.zcu;115 const zcu = pt.zcu;
118 const gpa = mod.gpa;116 const gpa = zcu.gpa;
119 const ip = &mod.intern_pool;117 const ip = &zcu.intern_pool;
120 const len: u32 = @intCast(len_u64);118 const len: u32 = @intCast(len_u64);
121 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);119 const strings = ip.getLocal(pt.tid).getMutableStrings(gpa);
122 try strings.ensureUnusedCapacity(len);120 try strings.ensureUnusedCapacity(len);
...@@ -126,7 +124,7 @@ fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.Null...@@ -126,7 +124,7 @@ fn arrayToIpString(val: Value, len_u64: u64, pt: Zcu.PerThread) !InternPool.Null
126 const prev_len = strings.mutate.len;124 const prev_len = strings.mutate.len;
127 const elem_val = try val.elemValue(pt, i);125 const elem_val = try val.elemValue(pt, i);
128 assert(strings.mutate.len == prev_len);126 assert(strings.mutate.len == prev_len);
129 const byte: u8 = @intCast(elem_val.toUnsignedInt(pt));127 const byte: u8 = @intCast(elem_val.toUnsignedInt(zcu));
130 strings.appendAssumeCapacity(.{byte});128 strings.appendAssumeCapacity(.{byte});
131 }129 }
132 return ip.getOrPutTrailingString(gpa, pt.tid, len, .no_embedded_nulls);130 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...@@ -178,56 +176,61 @@ pub fn intFromEnum(val: Value, ty: Type, pt: Zcu.PerThread) Allocator.Error!Valu
178pub const ResolveStrat = Type.ResolveStrat;176pub const ResolveStrat = Type.ResolveStrat;
179177
180/// Asserts the value is an integer.178/// Asserts the value is an integer.
181pub fn toBigInt(val: Value, space: *BigIntSpace, pt: Zcu.PerThread) BigIntConst {179pub fn toBigInt(val: Value, space: *BigIntSpace, zcu: *Zcu) BigIntConst {
182 return val.toBigIntAdvanced(space, pt, .normal) catch unreachable;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);
183}185}
184186
185/// Asserts the value is an integer.187/// Asserts the value is an integer.
186pub fn toBigIntAdvanced(188pub fn toBigIntAdvanced(
187 val: Value,189 val: Value,
188 space: *BigIntSpace,190 space: *BigIntSpace,
189 pt: Zcu.PerThread,
190 comptime strat: ResolveStrat,191 comptime strat: ResolveStrat,
191) Module.CompileError!BigIntConst {192 zcu: *Zcu,
193 tid: strat.Tid(),
194) Zcu.CompileError!BigIntConst {
192 return switch (val.toIntern()) {195 return switch (val.toIntern()) {
193 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),196 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
194 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),197 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
195 .null_value => BigIntMutable.init(&space.limbs, 0).toConst(),198 .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())) {
197 .int => |int| switch (int.storage) {200 .int => |int| switch (int.storage) {
198 .u64, .i64, .big_int => int.storage.toBigInt(space),201 .u64, .i64, .big_int => int.storage.toBigInt(space),
199 .lazy_align, .lazy_size => |ty| {202 .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));
201 const x = switch (int.storage) {204 const x = switch (int.storage) {
202 else => unreachable,205 else => unreachable,
203 .lazy_align => Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0,206 .lazy_align => Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0,
204 .lazy_size => Type.fromInterned(ty).abiSize(pt),207 .lazy_size => Type.fromInterned(ty).abiSize(zcu),
205 };208 };
206 return BigIntMutable.init(&space.limbs, x).toConst();209 return BigIntMutable.init(&space.limbs, x).toConst();
207 },210 },
208 },211 },
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),
210 .opt, .ptr => BigIntMutable.init(213 .opt, .ptr => BigIntMutable.init(
211 &space.limbs,214 &space.limbs,
212 (try val.getUnsignedIntAdvanced(pt, strat)).?,215 (try val.getUnsignedIntInner(strat, zcu, tid)).?,
213 ).toConst(),216 ).toConst(),
214 else => unreachable,217 else => unreachable,
215 },218 },
216 };219 };
217}220}
218221
219pub fn isFuncBody(val: Value, mod: *Module) bool {222pub fn isFuncBody(val: Value, zcu: *Zcu) bool {
220 return mod.intern_pool.isFuncBody(val.toIntern());223 return zcu.intern_pool.isFuncBody(val.toIntern());
221}224}
222225
223pub fn getFunction(val: Value, mod: *Module) ?InternPool.Key.Func {226pub fn getFunction(val: Value, zcu: *Zcu) ?InternPool.Key.Func {
224 return switch (mod.intern_pool.indexToKey(val.toIntern())) {227 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
225 .func => |x| x,228 .func => |x| x,
226 else => null,229 else => null,
227 };230 };
228}231}
229232
230pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {233pub fn getVariable(val: Value, mod: *Zcu) ?InternPool.Key.Variable {
231 return switch (mod.intern_pool.indexToKey(val.toIntern())) {234 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
232 .variable => |variable| variable,235 .variable => |variable| variable,
233 else => null,236 else => null,
...@@ -236,68 +239,79 @@ pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {...@@ -236,68 +239,79 @@ pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {
236239
237/// If the value fits in a u64, return it, otherwise null.240/// If the value fits in a u64, return it, otherwise null.
238/// Asserts not undefined.241/// Asserts not undefined.
239pub fn getUnsignedInt(val: Value, pt: Zcu.PerThread) ?u64 {242pub fn getUnsignedInt(val: Value, zcu: *Zcu) ?u64 {
240 return getUnsignedIntAdvanced(val, pt, .normal) catch unreachable;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);
241}253}
242254
243/// If the value fits in a u64, return it, otherwise null.255/// If the value fits in a u64, return it, otherwise null.
244/// Asserts not undefined.256/// Asserts not undefined.
245pub fn getUnsignedIntAdvanced(val: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !?u64 {257pub fn getUnsignedIntInner(
246 const mod = pt.zcu;258 val: Value,
259 comptime strat: ResolveStrat,
260 zcu: *Zcu,
261 tid: strat.Tid(),
262) !?u64 {
247 return switch (val.toIntern()) {263 return switch (val.toIntern()) {
248 .undef => unreachable,264 .undef => unreachable,
249 .bool_false => 0,265 .bool_false => 0,
250 .bool_true => 1,266 .bool_true => 1,
251 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {267 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
252 .undef => unreachable,268 .undef => unreachable,
253 .int => |int| switch (int.storage) {269 .int => |int| switch (int.storage) {
254 .big_int => |big_int| big_int.to(u64) catch null,270 .big_int => |big_int| big_int.to(u64) catch null,
255 .u64 => |x| x,271 .u64 => |x| x,
256 .i64 => |x| std.math.cast(u64, x),272 .i64 => |x| std.math.cast(u64, x),
257 .lazy_align => |ty| (try Type.fromInterned(ty).abiAlignmentAdvanced(pt, strat.toLazy())).scalar.toByteUnits() orelse 0,273 .lazy_align => |ty| (try Type.fromInterned(ty).abiAlignmentInner(strat.toLazy(), zcu, tid)).scalar.toByteUnits() orelse 0,
258 .lazy_size => |ty| (try Type.fromInterned(ty).abiSizeAdvanced(pt, strat.toLazy())).scalar,274 .lazy_size => |ty| (try Type.fromInterned(ty).abiSizeInner(strat.toLazy(), zcu, tid)).scalar,
259 },275 },
260 .ptr => |ptr| switch (ptr.base_addr) {276 .ptr => |ptr| switch (ptr.base_addr) {
261 .int => ptr.byte_offset,277 .int => ptr.byte_offset,
262 .field => |field| {278 .field => |field| {
263 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(pt, strat)) orelse return null;279 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntInner(strat, zcu, tid)) orelse return null;
264 const struct_ty = Value.fromInterned(field.base).typeOf(mod).childType(mod);280 const struct_ty = Value.fromInterned(field.base).typeOf(zcu).childType(zcu);
265 if (strat == .sema) try struct_ty.resolveLayout(pt);281 if (strat == .sema) {
266 return base_addr + struct_ty.structFieldOffset(@intCast(field.index), pt) + ptr.byte_offset;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;
267 },286 },
268 else => null,287 else => null,
269 },288 },
270 .opt => |opt| switch (opt.val) {289 .opt => |opt| switch (opt.val) {
271 .none => 0,290 .none => 0,
272 else => |payload| Value.fromInterned(payload).getUnsignedIntAdvanced(pt, strat),291 else => |payload| Value.fromInterned(payload).getUnsignedIntInner(strat, zcu, tid),
273 },292 },
274 else => null,293 else => null,
275 },294 },
276 };295 };
277}296}
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
284/// Asserts the value is an integer and it fits in a u64298/// Asserts the value is an integer and it fits in a u64
285pub fn toUnsignedIntSema(val: Value, pt: Zcu.PerThread) !u64 {299pub 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)).?;
287}301}
288302
289/// Asserts the value is an integer and it fits in a i64303/// 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 {
291 return switch (val.toIntern()) {305 return switch (val.toIntern()) {
292 .bool_false => 0,306 .bool_false => 0,
293 .bool_true => 1,307 .bool_true => 1,
294 else => switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {308 else => switch (zcu.intern_pool.indexToKey(val.toIntern())) {
295 .int => |int| switch (int.storage) {309 .int => |int| switch (int.storage) {
296 .big_int => |big_int| big_int.to(i64) catch unreachable,310 .big_int => |big_int| big_int.to(i64) catch unreachable,
297 .i64 => |x| x,311 .i64 => |x| x,
298 .u64 => |x| @intCast(x),312 .u64 => |x| @intCast(x),
299 .lazy_align => |ty| @intCast(Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0),313 .lazy_align => |ty| @intCast(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0),
300 .lazy_size => |ty| @intCast(Type.fromInterned(ty).abiSize(pt)),314 .lazy_size => |ty| @intCast(Type.fromInterned(ty).abiSize(zcu)),
301 },315 },
302 else => unreachable,316 else => unreachable,
303 },317 },
...@@ -326,41 +340,41 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro...@@ -326,41 +340,41 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
326 Unimplemented,340 Unimplemented,
327 OutOfMemory,341 OutOfMemory,
328}!void {342}!void {
329 const mod = pt.zcu;343 const zcu = pt.zcu;
330 const target = mod.getTarget();344 const target = zcu.getTarget();
331 const endian = target.cpu.arch.endian();345 const endian = target.cpu.arch.endian();
332 if (val.isUndef(mod)) {346 if (val.isUndef(zcu)) {
333 const size: usize = @intCast(ty.abiSize(pt));347 const size: usize = @intCast(ty.abiSize(zcu));
334 @memset(buffer[0..size], 0xaa);348 @memset(buffer[0..size], 0xaa);
335 return;349 return;
336 }350 }
337 const ip = &mod.intern_pool;351 const ip = &zcu.intern_pool;
338 switch (ty.zigTypeTag(mod)) {352 switch (ty.zigTypeTag(zcu)) {
339 .Void => {},353 .Void => {},
340 .Bool => {354 .Bool => {
341 buffer[0] = @intFromBool(val.toBool());355 buffer[0] = @intFromBool(val.toBool());
342 },356 },
343 .Int, .Enum => {357 .Int, .Enum => {
344 const int_info = ty.intInfo(mod);358 const int_info = ty.intInfo(zcu);
345 const bits = int_info.bits;359 const bits = int_info.bits;
346 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);360 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
347361
348 var bigint_buffer: BigIntSpace = undefined;362 var bigint_buffer: BigIntSpace = undefined;
349 const bigint = val.toBigInt(&bigint_buffer, pt);363 const bigint = val.toBigInt(&bigint_buffer, zcu);
350 bigint.writeTwosComplement(buffer[0..byte_count], endian);364 bigint.writeTwosComplement(buffer[0..byte_count], endian);
351 },365 },
352 .Float => switch (ty.floatBits(target)) {366 .Float => switch (ty.floatBits(target)) {
353 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(val.toFloat(f16, pt)), endian),367 16 => std.mem.writeInt(u16, buffer[0..2], @bitCast(val.toFloat(f16, zcu)), endian),
354 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(val.toFloat(f32, pt)), endian),368 32 => std.mem.writeInt(u32, buffer[0..4], @bitCast(val.toFloat(f32, zcu)), endian),
355 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(val.toFloat(f64, pt)), endian),369 64 => std.mem.writeInt(u64, buffer[0..8], @bitCast(val.toFloat(f64, zcu)), endian),
356 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(val.toFloat(f80, pt)), endian),370 80 => std.mem.writeInt(u80, buffer[0..10], @bitCast(val.toFloat(f80, zcu)), endian),
357 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(val.toFloat(f128, pt)), endian),371 128 => std.mem.writeInt(u128, buffer[0..16], @bitCast(val.toFloat(f128, zcu)), endian),
358 else => unreachable,372 else => unreachable,
359 },373 },
360 .Array => {374 .Array => {
361 const len = ty.arrayLen(mod);375 const len = ty.arrayLen(zcu);
362 const elem_ty = ty.childType(mod);376 const elem_ty = ty.childType(zcu);
363 const elem_size: usize = @intCast(elem_ty.abiSize(pt));377 const elem_size: usize = @intCast(elem_ty.abiSize(zcu));
364 var elem_i: usize = 0;378 var elem_i: usize = 0;
365 var buf_off: usize = 0;379 var buf_off: usize = 0;
366 while (elem_i < len) : (elem_i += 1) {380 while (elem_i < len) : (elem_i += 1) {
...@@ -372,15 +386,15 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro...@@ -372,15 +386,15 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
372 .Vector => {386 .Vector => {
373 // We use byte_count instead of abi_size here, so that any padding bytes387 // We use byte_count instead of abi_size here, so that any padding bytes
374 // follow the data bytes, on both big- and little-endian systems.388 // 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;
376 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);390 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
377 },391 },
378 .Struct => {392 .Struct => {
379 const struct_type = mod.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;393 const struct_type = zcu.typeToStruct(ty) orelse return error.IllDefinedMemoryLayout;
380 switch (struct_type.layout) {394 switch (struct_type.layout) {
381 .auto => return error.IllDefinedMemoryLayout,395 .auto => return error.IllDefinedMemoryLayout,
382 .@"extern" => for (0..struct_type.field_types.len) |field_index| {396 .@"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));
384 const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {398 const field_val = Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
385 .bytes => |bytes| {399 .bytes => |bytes| {
386 buffer[off] = bytes.at(field_index, ip);400 buffer[off] = bytes.at(field_index, ip);
...@@ -393,13 +407,13 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro...@@ -393,13 +407,13 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
393 try writeToMemory(field_val, field_ty, pt, buffer[off..]);407 try writeToMemory(field_val, field_ty, pt, buffer[off..]);
394 },408 },
395 .@"packed" => {409 .@"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;
397 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);411 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
398 },412 },
399 }413 }
400 },414 },
401 .ErrorSet => {415 .ErrorSet => {
402 const bits = mod.errorSetBits();416 const bits = zcu.errorSetBits();
403 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);417 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
404418
405 const name = switch (ip.indexToKey(val.toIntern())) {419 const name = switch (ip.indexToKey(val.toIntern())) {
...@@ -414,37 +428,37 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro...@@ -414,37 +428,37 @@ pub fn writeToMemory(val: Value, ty: Type, pt: Zcu.PerThread, buffer: []u8) erro
414 ).toConst();428 ).toConst();
415 bigint.writeTwosComplement(buffer[0..byte_count], endian);429 bigint.writeTwosComplement(buffer[0..byte_count], endian);
416 },430 },
417 .Union => switch (ty.containerLayout(mod)) {431 .Union => switch (ty.containerLayout(zcu)) {
418 .auto => return error.IllDefinedMemoryLayout, // Sema is supposed to have emitted a compile error already432 .auto => return error.IllDefinedMemoryLayout, // Sema is supposed to have emitted a compile error already
419 .@"extern" => {433 .@"extern" => {
420 if (val.unionTag(mod)) |union_tag| {434 if (val.unionTag(zcu)) |union_tag| {
421 const union_obj = mod.typeToUnion(ty).?;435 const union_obj = zcu.typeToUnion(ty).?;
422 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;436 const field_index = zcu.unionTagFieldIndex(union_obj, union_tag).?;
423 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);437 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
424 const field_val = try val.fieldValue(pt, field_index);438 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));
426 return writeToMemory(field_val, field_type, pt, buffer[0..byte_count]);440 return writeToMemory(field_val, field_type, pt, buffer[0..byte_count]);
427 } else {441 } else {
428 const backing_ty = try ty.unionBackingType(pt);442 const backing_ty = try ty.unionBackingType(pt);
429 const byte_count: usize = @intCast(backing_ty.abiSize(pt));443 const byte_count: usize = @intCast(backing_ty.abiSize(zcu));
430 return writeToMemory(val.unionValue(mod), backing_ty, pt, buffer[0..byte_count]);444 return writeToMemory(val.unionValue(zcu), backing_ty, pt, buffer[0..byte_count]);
431 }445 }
432 },446 },
433 .@"packed" => {447 .@"packed" => {
434 const backing_ty = try ty.unionBackingType(pt);448 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));
436 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);450 return writeToPackedMemory(val, ty, pt, buffer[0..byte_count], 0);
437 },451 },
438 },452 },
439 .Pointer => {453 .Pointer => {
440 if (ty.isSlice(mod)) return error.IllDefinedMemoryLayout;454 if (ty.isSlice(zcu)) return error.IllDefinedMemoryLayout;
441 if (!val.ptrHasIntAddr(mod)) return error.ReinterpretDeclRef;455 if (!val.ptrHasIntAddr(zcu)) return error.ReinterpretDeclRef;
442 return val.writeToMemory(Type.usize, pt, buffer);456 return val.writeToMemory(Type.usize, pt, buffer);
443 },457 },
444 .Optional => {458 .Optional => {
445 if (!ty.isPtrLikeOptional(mod)) return error.IllDefinedMemoryLayout;459 if (!ty.isPtrLikeOptional(zcu)) return error.IllDefinedMemoryLayout;
446 const child = ty.optionalChild(mod);460 const child = ty.optionalChild(zcu);
447 const opt_val = val.optionalValue(mod);461 const opt_val = val.optionalValue(zcu);
448 if (opt_val) |some| {462 if (opt_val) |some| {
449 return some.writeToMemory(child, pt, buffer);463 return some.writeToMemory(child, pt, buffer);
450 } else {464 } else {
...@@ -466,18 +480,18 @@ pub fn writeToPackedMemory(...@@ -466,18 +480,18 @@ pub fn writeToPackedMemory(
466 buffer: []u8,480 buffer: []u8,
467 bit_offset: usize,481 bit_offset: usize,
468) error{ ReinterpretDeclRef, OutOfMemory }!void {482) error{ ReinterpretDeclRef, OutOfMemory }!void {
469 const mod = pt.zcu;483 const zcu = pt.zcu;
470 const ip = &mod.intern_pool;484 const ip = &zcu.intern_pool;
471 const target = mod.getTarget();485 const target = zcu.getTarget();
472 const endian = target.cpu.arch.endian();486 const endian = target.cpu.arch.endian();
473 if (val.isUndef(mod)) {487 if (val.isUndef(zcu)) {
474 const bit_size: usize = @intCast(ty.bitSize(pt));488 const bit_size: usize = @intCast(ty.bitSize(zcu));
475 if (bit_size != 0) {489 if (bit_size != 0) {
476 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);490 std.mem.writeVarPackedInt(buffer, bit_offset, bit_size, @as(u1, 0), endian);
477 }491 }
478 return;492 return;
479 }493 }
480 switch (ty.zigTypeTag(mod)) {494 switch (ty.zigTypeTag(zcu)) {
481 .Void => {},495 .Void => {},
482 .Bool => {496 .Bool => {
483 const byte_index = switch (endian) {497 const byte_index = switch (endian) {
...@@ -492,34 +506,34 @@ pub fn writeToPackedMemory(...@@ -492,34 +506,34 @@ pub fn writeToPackedMemory(
492 },506 },
493 .Int, .Enum => {507 .Int, .Enum => {
494 if (buffer.len == 0) return;508 if (buffer.len == 0) return;
495 const bits = ty.intInfo(mod).bits;509 const bits = ty.intInfo(zcu).bits;
496 if (bits == 0) return;510 if (bits == 0) return;
497511
498 switch (ip.indexToKey((try val.intFromEnum(ty, pt)).toIntern()).int.storage) {512 switch (ip.indexToKey((try val.intFromEnum(ty, pt)).toIntern()).int.storage) {
499 inline .u64, .i64 => |int| std.mem.writeVarPackedInt(buffer, bit_offset, bits, int, endian),513 inline .u64, .i64 => |int| std.mem.writeVarPackedInt(buffer, bit_offset, bits, int, endian),
500 .big_int => |bigint| bigint.writePackedTwosComplement(buffer, bit_offset, bits, endian),514 .big_int => |bigint| bigint.writePackedTwosComplement(buffer, bit_offset, bits, endian),
501 .lazy_align => |lazy_align| {515 .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;
503 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);517 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
504 },518 },
505 .lazy_size => |lazy_size| {519 .lazy_size => |lazy_size| {
506 const num = Type.fromInterned(lazy_size).abiSize(pt);520 const num = Type.fromInterned(lazy_size).abiSize(zcu);
507 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);521 std.mem.writeVarPackedInt(buffer, bit_offset, bits, num, endian);
508 },522 },
509 }523 }
510 },524 },
511 .Float => switch (ty.floatBits(target)) {525 .Float => switch (ty.floatBits(target)) {
512 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(val.toFloat(f16, pt)), endian),526 16 => std.mem.writePackedInt(u16, buffer, bit_offset, @bitCast(val.toFloat(f16, zcu)), endian),
513 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(val.toFloat(f32, pt)), endian),527 32 => std.mem.writePackedInt(u32, buffer, bit_offset, @bitCast(val.toFloat(f32, zcu)), endian),
514 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(val.toFloat(f64, pt)), endian),528 64 => std.mem.writePackedInt(u64, buffer, bit_offset, @bitCast(val.toFloat(f64, zcu)), endian),
515 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(val.toFloat(f80, pt)), endian),529 80 => std.mem.writePackedInt(u80, buffer, bit_offset, @bitCast(val.toFloat(f80, zcu)), endian),
516 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(val.toFloat(f128, pt)), endian),530 128 => std.mem.writePackedInt(u128, buffer, bit_offset, @bitCast(val.toFloat(f128, zcu)), endian),
517 else => unreachable,531 else => unreachable,
518 },532 },
519 .Vector => {533 .Vector => {
520 const elem_ty = ty.childType(mod);534 const elem_ty = ty.childType(zcu);
521 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(pt));535 const elem_bit_size: u16 = @intCast(elem_ty.bitSize(zcu));
522 const len: usize = @intCast(ty.arrayLen(mod));536 const len: usize = @intCast(ty.arrayLen(zcu));
523537
524 var bits: u16 = 0;538 var bits: u16 = 0;
525 var elem_i: usize = 0;539 var elem_i: usize = 0;
...@@ -544,37 +558,37 @@ pub fn writeToPackedMemory(...@@ -544,37 +558,37 @@ pub fn writeToPackedMemory(
544 .repeated_elem => |elem| elem,558 .repeated_elem => |elem| elem,
545 });559 });
546 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);560 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));
548 try field_val.writeToPackedMemory(field_ty, pt, buffer, bit_offset + bits);562 try field_val.writeToPackedMemory(field_ty, pt, buffer, bit_offset + bits);
549 bits += field_bits;563 bits += field_bits;
550 }564 }
551 },565 },
552 .Union => {566 .Union => {
553 const union_obj = mod.typeToUnion(ty).?;567 const union_obj = zcu.typeToUnion(ty).?;
554 switch (union_obj.flagsUnordered(ip).layout) {568 switch (union_obj.flagsUnordered(ip).layout) {
555 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory569 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory
556 .@"packed" => {570 .@"packed" => {
557 if (val.unionTag(mod)) |union_tag| {571 if (val.unionTag(zcu)) |union_tag| {
558 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;572 const field_index = zcu.unionTagFieldIndex(union_obj, union_tag).?;
559 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);573 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
560 const field_val = try val.fieldValue(pt, field_index);574 const field_val = try val.fieldValue(pt, field_index);
561 return field_val.writeToPackedMemory(field_type, pt, buffer, bit_offset);575 return field_val.writeToPackedMemory(field_type, pt, buffer, bit_offset);
562 } else {576 } else {
563 const backing_ty = try ty.unionBackingType(pt);577 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);
565 }579 }
566 },580 },
567 }581 }
568 },582 },
569 .Pointer => {583 .Pointer => {
570 assert(!ty.isSlice(mod)); // No well defined layout.584 assert(!ty.isSlice(zcu)); // No well defined layout.
571 if (!val.ptrHasIntAddr(mod)) return error.ReinterpretDeclRef;585 if (!val.ptrHasIntAddr(zcu)) return error.ReinterpretDeclRef;
572 return val.writeToPackedMemory(Type.usize, pt, buffer, bit_offset);586 return val.writeToPackedMemory(Type.usize, pt, buffer, bit_offset);
573 },587 },
574 .Optional => {588 .Optional => {
575 assert(ty.isPtrLikeOptional(mod));589 assert(ty.isPtrLikeOptional(zcu));
576 const child = ty.optionalChild(mod);590 const child = ty.optionalChild(zcu);
577 const opt_val = val.optionalValue(mod);591 const opt_val = val.optionalValue(zcu);
578 if (opt_val) |some| {592 if (opt_val) |some| {
579 return some.writeToPackedMemory(child, pt, buffer, bit_offset);593 return some.writeToPackedMemory(child, pt, buffer, bit_offset);
580 } else {594 } else {
...@@ -599,11 +613,11 @@ pub fn readFromMemory(...@@ -599,11 +613,11 @@ pub fn readFromMemory(
599 Unimplemented,613 Unimplemented,
600 OutOfMemory,614 OutOfMemory,
601}!Value {615}!Value {
602 const mod = pt.zcu;616 const zcu = pt.zcu;
603 const ip = &mod.intern_pool;617 const ip = &zcu.intern_pool;
604 const target = mod.getTarget();618 const target = zcu.getTarget();
605 const endian = target.cpu.arch.endian();619 const endian = target.cpu.arch.endian();
606 switch (ty.zigTypeTag(mod)) {620 switch (ty.zigTypeTag(zcu)) {
607 .Void => return Value.void,621 .Void => return Value.void,
608 .Bool => {622 .Bool => {
609 if (buffer[0] == 0) {623 if (buffer[0] == 0) {
...@@ -615,24 +629,24 @@ pub fn readFromMemory(...@@ -615,24 +629,24 @@ pub fn readFromMemory(
615 .Int, .Enum => |ty_tag| {629 .Int, .Enum => |ty_tag| {
616 const int_ty = switch (ty_tag) {630 const int_ty = switch (ty_tag) {
617 .Int => ty,631 .Int => ty,
618 .Enum => ty.intTagType(mod),632 .Enum => ty.intTagType(zcu),
619 else => unreachable,633 else => unreachable,
620 };634 };
621 const int_info = int_ty.intInfo(mod);635 const int_info = int_ty.intInfo(zcu);
622 const bits = int_info.bits;636 const bits = int_info.bits;
623 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);637 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
626 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64640 if (bits <= 64) switch (int_info.signedness) { // Fast path for integers <= u64
627 .signed => {641 .signed => {
628 const val = std.mem.readVarInt(i64, buffer[0..byte_count], endian);642 const val = std.mem.readVarInt(i64, buffer[0..byte_count], endian);
629 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));643 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);
631 },645 },
632 .unsigned => {646 .unsigned => {
633 const val = std.mem.readVarInt(u64, buffer[0..byte_count], endian);647 const val = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
634 const result = (val << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));648 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);
636 },650 },
637 } else { // Slow path, we have to construct a big-int651 } else { // Slow path, we have to construct a big-int
638 const Limb = std.math.big.Limb;652 const Limb = std.math.big.Limb;
...@@ -641,7 +655,7 @@ pub fn readFromMemory(...@@ -641,7 +655,7 @@ pub fn readFromMemory(
641655
642 var bigint = BigIntMutable.init(limbs_buffer, 0);656 var bigint = BigIntMutable.init(limbs_buffer, 0);
643 bigint.readTwosComplement(buffer[0..byte_count], bits, endian, int_info.signedness);657 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);
645 }659 }
646 },660 },
647 .Float => return Value.fromInterned(try pt.intern(.{ .float = .{661 .Float => return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -656,12 +670,12 @@ pub fn readFromMemory(...@@ -656,12 +670,12 @@ pub fn readFromMemory(
656 },670 },
657 } })),671 } })),
658 .Array => {672 .Array => {
659 const elem_ty = ty.childType(mod);673 const elem_ty = ty.childType(zcu);
660 const elem_size = elem_ty.abiSize(pt);674 const elem_size = elem_ty.abiSize(zcu);
661 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod)));675 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(zcu)));
662 var offset: usize = 0;676 var offset: usize = 0;
663 for (elems) |*elem| {677 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();
665 offset += @intCast(elem_size);679 offset += @intCast(elem_size);
666 }680 }
667 return Value.fromInterned(try pt.intern(.{ .aggregate = .{681 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
...@@ -672,11 +686,11 @@ pub fn readFromMemory(...@@ -672,11 +686,11 @@ pub fn readFromMemory(
672 .Vector => {686 .Vector => {
673 // We use byte_count instead of abi_size here, so that any padding bytes687 // We use byte_count instead of abi_size here, so that any padding bytes
674 // follow the data bytes, on both big- and little-endian systems.688 // follow the data bytes, on both big- and little-endian systems.
675 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;689 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
676 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);690 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
677 },691 },
678 .Struct => {692 .Struct => {
679 const struct_type = mod.typeToStruct(ty).?;693 const struct_type = zcu.typeToStruct(ty).?;
680 switch (struct_type.layout) {694 switch (struct_type.layout) {
681 .auto => unreachable, // Sema is supposed to have emitted a compile error already695 .auto => unreachable, // Sema is supposed to have emitted a compile error already
682 .@"extern" => {696 .@"extern" => {
...@@ -684,9 +698,9 @@ pub fn readFromMemory(...@@ -684,9 +698,9 @@ pub fn readFromMemory(
684 const field_vals = try arena.alloc(InternPool.Index, field_types.len);698 const field_vals = try arena.alloc(InternPool.Index, field_types.len);
685 for (field_vals, 0..) |*field_val, i| {699 for (field_vals, 0..) |*field_val, i| {
686 const field_ty = Type.fromInterned(field_types.get(ip)[i]);700 const field_ty = Type.fromInterned(field_types.get(ip)[i]);
687 const off: usize = @intCast(ty.structFieldOffset(i, mod));701 const off: usize = @intCast(ty.structFieldOffset(i, zcu));
688 const sz: usize = @intCast(field_ty.abiSize(pt));702 const sz: usize = @intCast(field_ty.abiSize(zcu));
689 field_val.* = (try readFromMemory(field_ty, mod, buffer[off..(off + sz)], arena)).toIntern();703 field_val.* = (try readFromMemory(field_ty, zcu, buffer[off..(off + sz)], arena)).toIntern();
690 }704 }
691 return Value.fromInterned(try pt.intern(.{ .aggregate = .{705 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
692 .ty = ty.toIntern(),706 .ty = ty.toIntern(),
...@@ -694,29 +708,29 @@ pub fn readFromMemory(...@@ -694,29 +708,29 @@ pub fn readFromMemory(
694 } }));708 } }));
695 },709 },
696 .@"packed" => {710 .@"packed" => {
697 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;711 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
698 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);712 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
699 },713 },
700 }714 }
701 },715 },
702 .ErrorSet => {716 .ErrorSet => {
703 const bits = mod.errorSetBits();717 const bits = zcu.errorSetBits();
704 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);718 const byte_count: u16 = @intCast((@as(u17, bits) + 7) / 8);
705 const int = std.mem.readVarInt(u64, buffer[0..byte_count], endian);719 const int = std.mem.readVarInt(u64, buffer[0..byte_count], endian);
706 const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));720 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
709 return Value.fromInterned(try pt.intern(.{ .err = .{723 return Value.fromInterned(try pt.intern(.{ .err = .{
710 .ty = ty.toIntern(),724 .ty = ty.toIntern(),
711 .name = name,725 .name = name,
712 } }));726 } }));
713 },727 },
714 .Union => switch (ty.containerLayout(mod)) {728 .Union => switch (ty.containerLayout(zcu)) {
715 .auto => return error.IllDefinedMemoryLayout,729 .auto => return error.IllDefinedMemoryLayout,
716 .@"extern" => {730 .@"extern" => {
717 const union_size = ty.abiSize(pt);731 const union_size = ty.abiSize(zcu);
718 const array_ty = try mod.arrayType(.{ .len = union_size, .child = .u8_type });732 const array_ty = try zcu.arrayType(.{ .len = union_size, .child = .u8_type });
719 const val = (try readFromMemory(array_ty, mod, buffer, arena)).toIntern();733 const val = (try readFromMemory(array_ty, zcu, buffer, arena)).toIntern();
720 return Value.fromInterned(try pt.intern(.{ .un = .{734 return Value.fromInterned(try pt.intern(.{ .un = .{
721 .ty = ty.toIntern(),735 .ty = ty.toIntern(),
722 .tag = .none,736 .tag = .none,
...@@ -724,23 +738,23 @@ pub fn readFromMemory(...@@ -724,23 +738,23 @@ pub fn readFromMemory(
724 } }));738 } }));
725 },739 },
726 .@"packed" => {740 .@"packed" => {
727 const byte_count = (@as(usize, @intCast(ty.bitSize(pt))) + 7) / 8;741 const byte_count = (@as(usize, @intCast(ty.bitSize(zcu))) + 7) / 8;
728 return readFromPackedMemory(ty, mod, buffer[0..byte_count], 0, arena);742 return readFromPackedMemory(ty, zcu, buffer[0..byte_count], 0, arena);
729 },743 },
730 },744 },
731 .Pointer => {745 .Pointer => {
732 assert(!ty.isSlice(mod)); // No well defined layout.746 assert(!ty.isSlice(zcu)); // No well defined layout.
733 const int_val = try readFromMemory(Type.usize, mod, buffer, arena);747 const int_val = try readFromMemory(Type.usize, zcu, buffer, arena);
734 return Value.fromInterned(try pt.intern(.{ .ptr = .{748 return Value.fromInterned(try pt.intern(.{ .ptr = .{
735 .ty = ty.toIntern(),749 .ty = ty.toIntern(),
736 .base_addr = .int,750 .base_addr = .int,
737 .byte_offset = int_val.toUnsignedInt(pt),751 .byte_offset = int_val.toUnsignedInt(zcu),
738 } }));752 } }));
739 },753 },
740 .Optional => {754 .Optional => {
741 assert(ty.isPtrLikeOptional(mod));755 assert(ty.isPtrLikeOptional(zcu));
742 const child_ty = ty.optionalChild(mod);756 const child_ty = ty.optionalChild(zcu);
743 const child_val = try readFromMemory(child_ty, mod, buffer, arena);757 const child_val = try readFromMemory(child_ty, zcu, buffer, arena);
744 return Value.fromInterned(try pt.intern(.{ .opt = .{758 return Value.fromInterned(try pt.intern(.{ .opt = .{
745 .ty = ty.toIntern(),759 .ty = ty.toIntern(),
746 .val = switch (child_val.orderAgainstZero(pt)) {760 .val = switch (child_val.orderAgainstZero(pt)) {
...@@ -768,11 +782,11 @@ pub fn readFromPackedMemory(...@@ -768,11 +782,11 @@ pub fn readFromPackedMemory(
768 IllDefinedMemoryLayout,782 IllDefinedMemoryLayout,
769 OutOfMemory,783 OutOfMemory,
770}!Value {784}!Value {
771 const mod = pt.zcu;785 const zcu = pt.zcu;
772 const ip = &mod.intern_pool;786 const ip = &zcu.intern_pool;
773 const target = mod.getTarget();787 const target = zcu.getTarget();
774 const endian = target.cpu.arch.endian();788 const endian = target.cpu.arch.endian();
775 switch (ty.zigTypeTag(mod)) {789 switch (ty.zigTypeTag(zcu)) {
776 .Void => return Value.void,790 .Void => return Value.void,
777 .Bool => {791 .Bool => {
778 const byte = switch (endian) {792 const byte = switch (endian) {
...@@ -787,7 +801,7 @@ pub fn readFromPackedMemory(...@@ -787,7 +801,7 @@ pub fn readFromPackedMemory(
787 },801 },
788 .Int => {802 .Int => {
789 if (buffer.len == 0) return pt.intValue(ty, 0);803 if (buffer.len == 0) return pt.intValue(ty, 0);
790 const int_info = ty.intInfo(mod);804 const int_info = ty.intInfo(zcu);
791 const bits = int_info.bits;805 const bits = int_info.bits;
792 if (bits == 0) return pt.intValue(ty, 0);806 if (bits == 0) return pt.intValue(ty, 0);
793807
...@@ -800,7 +814,7 @@ pub fn readFromPackedMemory(...@@ -800,7 +814,7 @@ pub fn readFromPackedMemory(
800 };814 };
801815
802 // Slow path, we have to construct a big-int816 // 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));
804 const Limb = std.math.big.Limb;818 const Limb = std.math.big.Limb;
805 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);819 const limb_count = (abi_size + @sizeOf(Limb) - 1) / @sizeOf(Limb);
806 const limbs_buffer = try arena.alloc(Limb, limb_count);820 const limbs_buffer = try arena.alloc(Limb, limb_count);
...@@ -810,7 +824,7 @@ pub fn readFromPackedMemory(...@@ -810,7 +824,7 @@ pub fn readFromPackedMemory(
810 return pt.intValue_big(ty, bigint.toConst());824 return pt.intValue_big(ty, bigint.toConst());
811 },825 },
812 .Enum => {826 .Enum => {
813 const int_ty = ty.intTagType(mod);827 const int_ty = ty.intTagType(zcu);
814 const int_val = try Value.readFromPackedMemory(int_ty, pt, buffer, bit_offset, arena);828 const int_val = try Value.readFromPackedMemory(int_ty, pt, buffer, bit_offset, arena);
815 return pt.getCoerced(int_val, ty);829 return pt.getCoerced(int_val, ty);
816 },830 },
...@@ -826,11 +840,11 @@ pub fn readFromPackedMemory(...@@ -826,11 +840,11 @@ pub fn readFromPackedMemory(
826 },840 },
827 } })),841 } })),
828 .Vector => {842 .Vector => {
829 const elem_ty = ty.childType(mod);843 const elem_ty = ty.childType(zcu);
830 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(mod)));844 const elems = try arena.alloc(InternPool.Index, @intCast(ty.arrayLen(zcu)));
831845
832 var bits: u16 = 0;846 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));
834 for (elems, 0..) |_, i| {848 for (elems, 0..) |_, i| {
835 // On big-endian systems, LLVM reverses the element order of vectors by default849 // On big-endian systems, LLVM reverses the element order of vectors by default
836 const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i;850 const tgt_elem_i = if (endian == .big) elems.len - i - 1 else i;
...@@ -845,12 +859,12 @@ pub fn readFromPackedMemory(...@@ -845,12 +859,12 @@ pub fn readFromPackedMemory(
845 .Struct => {859 .Struct => {
846 // Sema is supposed to have emitted a compile error already for Auto layout structs,860 // Sema is supposed to have emitted a compile error already for Auto layout structs,
847 // and Extern is handled by non-packed readFromMemory.861 // and Extern is handled by non-packed readFromMemory.
848 const struct_type = mod.typeToPackedStruct(ty).?;862 const struct_type = zcu.typeToPackedStruct(ty).?;
849 var bits: u16 = 0;863 var bits: u16 = 0;
850 const field_vals = try arena.alloc(InternPool.Index, struct_type.field_types.len);864 const field_vals = try arena.alloc(InternPool.Index, struct_type.field_types.len);
851 for (field_vals, 0..) |*field_val, i| {865 for (field_vals, 0..) |*field_val, i| {
852 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);866 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));
854 field_val.* = (try readFromPackedMemory(field_ty, pt, buffer, bit_offset + bits, arena)).toIntern();868 field_val.* = (try readFromPackedMemory(field_ty, pt, buffer, bit_offset + bits, arena)).toIntern();
855 bits += field_bits;869 bits += field_bits;
856 }870 }
...@@ -859,7 +873,7 @@ pub fn readFromPackedMemory(...@@ -859,7 +873,7 @@ pub fn readFromPackedMemory(
859 .storage = .{ .elems = field_vals },873 .storage = .{ .elems = field_vals },
860 } }));874 } }));
861 },875 },
862 .Union => switch (ty.containerLayout(mod)) {876 .Union => switch (ty.containerLayout(zcu)) {
863 .auto, .@"extern" => unreachable, // Handled by non-packed readFromMemory877 .auto, .@"extern" => unreachable, // Handled by non-packed readFromMemory
864 .@"packed" => {878 .@"packed" => {
865 const backing_ty = try ty.unionBackingType(pt);879 const backing_ty = try ty.unionBackingType(pt);
...@@ -872,21 +886,21 @@ pub fn readFromPackedMemory(...@@ -872,21 +886,21 @@ pub fn readFromPackedMemory(
872 },886 },
873 },887 },
874 .Pointer => {888 .Pointer => {
875 assert(!ty.isSlice(mod)); // No well defined layout.889 assert(!ty.isSlice(zcu)); // No well defined layout.
876 const int_val = try readFromPackedMemory(Type.usize, pt, buffer, bit_offset, arena);890 const int_val = try readFromPackedMemory(Type.usize, pt, buffer, bit_offset, arena);
877 return Value.fromInterned(try pt.intern(.{ .ptr = .{891 return Value.fromInterned(try pt.intern(.{ .ptr = .{
878 .ty = ty.toIntern(),892 .ty = ty.toIntern(),
879 .base_addr = .int,893 .base_addr = .int,
880 .byte_offset = int_val.toUnsignedInt(pt),894 .byte_offset = int_val.toUnsignedInt(zcu),
881 } }));895 } }));
882 },896 },
883 .Optional => {897 .Optional => {
884 assert(ty.isPtrLikeOptional(mod));898 assert(ty.isPtrLikeOptional(zcu));
885 const child_ty = ty.optionalChild(mod);899 const child_ty = ty.optionalChild(zcu);
886 const child_val = try readFromPackedMemory(child_ty, pt, buffer, bit_offset, arena);900 const child_val = try readFromPackedMemory(child_ty, pt, buffer, bit_offset, arena);
887 return Value.fromInterned(try pt.intern(.{ .opt = .{901 return Value.fromInterned(try pt.intern(.{ .opt = .{
888 .ty = ty.toIntern(),902 .ty = ty.toIntern(),
889 .val = switch (child_val.orderAgainstZero(pt)) {903 .val = switch (child_val.orderAgainstZero(zcu)) {
890 .lt => unreachable,904 .lt => unreachable,
891 .eq => .none,905 .eq => .none,
892 .gt => child_val.toIntern(),906 .gt => child_val.toIntern(),
...@@ -898,8 +912,8 @@ pub fn readFromPackedMemory(...@@ -898,8 +912,8 @@ pub fn readFromPackedMemory(
898}912}
899913
900/// Asserts that the value is a float or an integer.914/// Asserts that the value is a float or an integer.
901pub fn toFloat(val: Value, comptime T: type, pt: Zcu.PerThread) T {915pub fn toFloat(val: Value, comptime T: type, zcu: *Zcu) T {
902 return switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {916 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
903 .int => |int| switch (int.storage) {917 .int => |int| switch (int.storage) {
904 .big_int => |big_int| @floatCast(bigIntToFloat(big_int.limbs, big_int.positive)),918 .big_int => |big_int| @floatCast(bigIntToFloat(big_int.limbs, big_int.positive)),
905 inline .u64, .i64 => |x| {919 inline .u64, .i64 => |x| {
...@@ -908,8 +922,8 @@ pub fn toFloat(val: Value, comptime T: type, pt: Zcu.PerThread) T {...@@ -908,8 +922,8 @@ pub fn toFloat(val: Value, comptime T: type, pt: Zcu.PerThread) T {
908 }922 }
909 return @floatFromInt(x);923 return @floatFromInt(x);
910 },924 },
911 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0),925 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0),
912 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(pt)),926 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(zcu)),
913 },927 },
914 .float => |float| switch (float.storage) {928 .float => |float| switch (float.storage) {
915 inline else => |x| @floatCast(x),929 inline else => |x| @floatCast(x),
...@@ -937,30 +951,30 @@ fn bigIntToFloat(limbs: []const std.math.big.Limb, positive: bool) f128 {...@@ -937,30 +951,30 @@ fn bigIntToFloat(limbs: []const std.math.big.Limb, positive: bool) f128 {
937 }951 }
938}952}
939953
940pub fn clz(val: Value, ty: Type, pt: Zcu.PerThread) u64 {954pub fn clz(val: Value, ty: Type, zcu: *Zcu) u64 {
941 var bigint_buf: BigIntSpace = undefined;955 var bigint_buf: BigIntSpace = undefined;
942 const bigint = val.toBigInt(&bigint_buf, pt);956 const bigint = val.toBigInt(&bigint_buf, zcu);
943 return bigint.clz(ty.intInfo(pt.zcu).bits);957 return bigint.clz(ty.intInfo(zcu).bits);
944}958}
945959
946pub fn ctz(val: Value, ty: Type, pt: Zcu.PerThread) u64 {960pub fn ctz(val: Value, ty: Type, zcu: *Zcu) u64 {
947 var bigint_buf: BigIntSpace = undefined;961 var bigint_buf: BigIntSpace = undefined;
948 const bigint = val.toBigInt(&bigint_buf, pt);962 const bigint = val.toBigInt(&bigint_buf, zcu);
949 return bigint.ctz(ty.intInfo(pt.zcu).bits);963 return bigint.ctz(ty.intInfo(zcu).bits);
950}964}
951965
952pub fn popCount(val: Value, ty: Type, pt: Zcu.PerThread) u64 {966pub fn popCount(val: Value, ty: Type, zcu: *Zcu) u64 {
953 var bigint_buf: BigIntSpace = undefined;967 var bigint_buf: BigIntSpace = undefined;
954 const bigint = val.toBigInt(&bigint_buf, pt);968 const bigint = val.toBigInt(&bigint_buf, zcu);
955 return @intCast(bigint.popCount(ty.intInfo(pt.zcu).bits));969 return @intCast(bigint.popCount(ty.intInfo(zcu).bits));
956}970}
957971
958pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {972pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {
959 const mod = pt.zcu;973 const zcu = pt.zcu;
960 const info = ty.intInfo(mod);974 const info = ty.intInfo(zcu);
961975
962 var buffer: Value.BigIntSpace = undefined;976 var buffer: Value.BigIntSpace = undefined;
963 const operand_bigint = val.toBigInt(&buffer, pt);977 const operand_bigint = val.toBigInt(&buffer, zcu);
964978
965 const limbs = try arena.alloc(979 const limbs = try arena.alloc(
966 std.math.big.Limb,980 std.math.big.Limb,
...@@ -973,14 +987,14 @@ pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Va...@@ -973,14 +987,14 @@ pub fn bitReverse(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Va
973}987}
974988
975pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {989pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Value {
976 const mod = pt.zcu;990 const zcu = pt.zcu;
977 const info = ty.intInfo(mod);991 const info = ty.intInfo(zcu);
978992
979 // Bit count must be evenly divisible by 8993 // Bit count must be evenly divisible by 8
980 assert(info.bits % 8 == 0);994 assert(info.bits % 8 == 0);
981995
982 var buffer: Value.BigIntSpace = undefined;996 var buffer: Value.BigIntSpace = undefined;
983 const operand_bigint = val.toBigInt(&buffer, pt);997 const operand_bigint = val.toBigInt(&buffer, zcu);
984998
985 const limbs = try arena.alloc(999 const limbs = try arena.alloc(
986 std.math.big.Limb,1000 std.math.big.Limb,
...@@ -994,33 +1008,34 @@ pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Valu...@@ -994,33 +1008,34 @@ pub fn byteSwap(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) !Valu
9941008
995/// Asserts the value is an integer and not undefined.1009/// Asserts the value is an integer and not undefined.
996/// Returns the number of bits the value requires to represent stored in twos complement form.1010/// 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 {
998 var buffer: BigIntSpace = undefined;1012 var buffer: BigIntSpace = undefined;
999 const big_int = self.toBigInt(&buffer, pt);1013 const big_int = self.toBigInt(&buffer, zcu);
1000 return big_int.bitCountTwosComp();1014 return big_int.bitCountTwosComp();
1001}1015}
10021016
1003/// Converts an integer or a float to a float. May result in a loss of information.1017/// Converts an integer or a float to a float. May result in a loss of information.
1004/// Caller can find out by equality checking the result against the operand.1018/// Caller can find out by equality checking the result against the operand.
1005pub fn floatCast(val: Value, dest_ty: Type, pt: Zcu.PerThread) !Value {1019pub fn floatCast(val: Value, dest_ty: Type, pt: Zcu.PerThread) !Value {
1006 const target = pt.zcu.getTarget();1020 const zcu = pt.zcu;
1007 if (val.isUndef(pt.zcu)) return pt.undefValue(dest_ty);1021 const target = zcu.getTarget();
1022 if (val.isUndef(zcu)) return pt.undefValue(dest_ty);
1008 return Value.fromInterned(try pt.intern(.{ .float = .{1023 return Value.fromInterned(try pt.intern(.{ .float = .{
1009 .ty = dest_ty.toIntern(),1024 .ty = dest_ty.toIntern(),
1010 .storage = switch (dest_ty.floatBits(target)) {1025 .storage = switch (dest_ty.floatBits(target)) {
1011 16 => .{ .f16 = val.toFloat(f16, pt) },1026 16 => .{ .f16 = val.toFloat(f16, zcu) },
1012 32 => .{ .f32 = val.toFloat(f32, pt) },1027 32 => .{ .f32 = val.toFloat(f32, zcu) },
1013 64 => .{ .f64 = val.toFloat(f64, pt) },1028 64 => .{ .f64 = val.toFloat(f64, zcu) },
1014 80 => .{ .f80 = val.toFloat(f80, pt) },1029 80 => .{ .f80 = val.toFloat(f80, zcu) },
1015 128 => .{ .f128 = val.toFloat(f128, pt) },1030 128 => .{ .f128 = val.toFloat(f128, zcu) },
1016 else => unreachable,1031 else => unreachable,
1017 },1032 },
1018 } }));1033 } }));
1019}1034}
10201035
1021/// Asserts the value is a float1036/// Asserts the value is a float
1022pub fn floatHasFraction(self: Value, mod: *const Module) bool {1037pub fn floatHasFraction(self: Value, zcu: *const Zcu) bool {
1023 return switch (mod.intern_pool.indexToKey(self.toIntern())) {1038 return switch (zcu.intern_pool.indexToKey(self.toIntern())) {
1024 .float => |float| switch (float.storage) {1039 .float => |float| switch (float.storage) {
1025 inline else => |x| @rem(x, 1) != 0,1040 inline else => |x| @rem(x, 1) != 0,
1026 },1041 },
...@@ -1028,19 +1043,24 @@ pub fn floatHasFraction(self: Value, mod: *const Module) bool {...@@ -1028,19 +1043,24 @@ pub fn floatHasFraction(self: Value, mod: *const Module) bool {
1028 };1043 };
1029}1044}
10301045
1031pub fn orderAgainstZero(lhs: Value, pt: Zcu.PerThread) std.math.Order {1046pub fn orderAgainstZero(lhs: Value, zcu: *Zcu) std.math.Order {
1032 return orderAgainstZeroAdvanced(lhs, pt, .normal) catch unreachable;1047 return orderAgainstZeroInner(lhs, .normal, zcu, {}) catch unreachable;
1033}1048}
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(
1036 lhs: Value,1055 lhs: Value,
1037 pt: Zcu.PerThread,
1038 comptime strat: ResolveStrat,1056 comptime strat: ResolveStrat,
1039) Module.CompileError!std.math.Order {1057 zcu: *Zcu,
1058 tid: strat.Tid(),
1059) Zcu.CompileError!std.math.Order {
1040 return switch (lhs.toIntern()) {1060 return switch (lhs.toIntern()) {
1041 .bool_false => .eq,1061 .bool_false => .eq,
1042 .bool_true => .gt,1062 .bool_true => .gt,
1043 else => switch (pt.zcu.intern_pool.indexToKey(lhs.toIntern())) {1063 else => switch (zcu.intern_pool.indexToKey(lhs.toIntern())) {
1044 .ptr => |ptr| if (ptr.byte_offset > 0) .gt else switch (ptr.base_addr) {1064 .ptr => |ptr| if (ptr.byte_offset > 0) .gt else switch (ptr.base_addr) {
1045 .nav, .comptime_alloc, .comptime_field => .gt,1065 .nav, .comptime_alloc, .comptime_field => .gt,
1046 .int => .eq,1066 .int => .eq,
...@@ -1050,16 +1070,17 @@ pub fn orderAgainstZeroAdvanced(...@@ -1050,16 +1070,17 @@ pub fn orderAgainstZeroAdvanced(
1050 .big_int => |big_int| big_int.orderAgainstScalar(0),1070 .big_int => |big_int| big_int.orderAgainstScalar(0),
1051 inline .u64, .i64 => |x| std.math.order(x, 0),1071 inline .u64, .i64 => |x| std.math.order(x, 0),
1052 .lazy_align => .gt, // alignment is never 01072 .lazy_align => .gt, // alignment is never 0
1053 .lazy_size => |ty| return if (Type.fromInterned(ty).hasRuntimeBitsAdvanced(1073 .lazy_size => |ty| return if (Type.fromInterned(ty).hasRuntimeBitsInner(
1054 pt,
1055 false,1074 false,
1056 strat.toLazy(),1075 strat.toLazy(),
1076 zcu,
1077 tid,
1057 ) catch |err| switch (err) {1078 ) catch |err| switch (err) {
1058 error.NeedLazy => unreachable,1079 error.NeedLazy => unreachable,
1059 else => |e| return e,1080 else => |e| return e,
1060 }) .gt else .eq,1081 }) .gt else .eq,
1061 },1082 },
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),
1063 .float => |float| switch (float.storage) {1084 .float => |float| switch (float.storage) {
1064 inline else => |x| std.math.order(x, 0),1085 inline else => |x| std.math.order(x, 0),
1065 },1086 },
...@@ -1069,14 +1090,20 @@ pub fn orderAgainstZeroAdvanced(...@@ -1069,14 +1090,20 @@ pub fn orderAgainstZeroAdvanced(
1069}1090}
10701091
1071/// Asserts the value is comparable.1092/// Asserts the value is comparable.
1072pub fn order(lhs: Value, rhs: Value, pt: Zcu.PerThread) std.math.Order {1093pub fn order(lhs: Value, rhs: Value, zcu: *Zcu) std.math.Order {
1073 return orderAdvanced(lhs, rhs, pt, .normal) catch unreachable;1094 return orderAdvanced(lhs, rhs, .normal, zcu, {}) catch unreachable;
1074}1095}
10751096
1076/// Asserts the value is comparable.1097/// Asserts the value is comparable.
1077pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat: ResolveStrat) !std.math.Order {1098pub fn orderAdvanced(
1078 const lhs_against_zero = try lhs.orderAgainstZeroAdvanced(pt, strat);1099 lhs: Value,
1079 const rhs_against_zero = try rhs.orderAgainstZeroAdvanced(pt, strat);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);
1080 switch (lhs_against_zero) {1107 switch (lhs_against_zero) {
1081 .lt => if (rhs_against_zero != .lt) return .lt,1108 .lt => if (rhs_against_zero != .lt) return .lt,
1082 .eq => return rhs_against_zero.invert(),1109 .eq => return rhs_against_zero.invert(),
...@@ -1088,34 +1115,39 @@ pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat:...@@ -1088,34 +1115,39 @@ pub fn orderAdvanced(lhs: Value, rhs: Value, pt: Zcu.PerThread, comptime strat:
1088 .gt => {},1115 .gt => {},
1089 }1116 }
10901117
1091 if (lhs.isFloat(pt.zcu) or rhs.isFloat(pt.zcu)) {1118 if (lhs.isFloat(zcu) or rhs.isFloat(zcu)) {
1092 const lhs_f128 = lhs.toFloat(f128, pt);1119 const lhs_f128 = lhs.toFloat(f128, zcu);
1093 const rhs_f128 = rhs.toFloat(f128, pt);1120 const rhs_f128 = rhs.toFloat(f128, zcu);
1094 return std.math.order(lhs_f128, rhs_f128);1121 return std.math.order(lhs_f128, rhs_f128);
1095 }1122 }
10961123
1097 var lhs_bigint_space: BigIntSpace = undefined;1124 var lhs_bigint_space: BigIntSpace = undefined;
1098 var rhs_bigint_space: BigIntSpace = undefined;1125 var rhs_bigint_space: BigIntSpace = undefined;
1099 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_bigint_space, pt, strat);1126 const lhs_bigint = try lhs.toBigIntAdvanced(&lhs_bigint_space, strat, zcu, tid);
1100 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_bigint_space, pt, strat);1127 const rhs_bigint = try rhs.toBigIntAdvanced(&rhs_bigint_space, strat, zcu, tid);
1101 return lhs_bigint.order(rhs_bigint);1128 return lhs_bigint.order(rhs_bigint);
1102}1129}
11031130
1104/// Asserts the value is comparable. Does not take a type parameter because it supports1131/// Asserts the value is comparable. Does not take a type parameter because it supports
1105/// comparisons between heterogeneous types.1132/// comparisons between heterogeneous types.
1106pub fn compareHetero(lhs: Value, op: std.math.CompareOperator, rhs: Value, pt: Zcu.PerThread) bool {1133pub fn compareHetero(lhs: Value, op: std.math.CompareOperator, rhs: Value, zcu: *Zcu) bool {
1107 return compareHeteroAdvanced(lhs, op, rhs, pt, .normal) catch unreachable;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);
1108}1139}
11091140
1110pub fn compareHeteroAdvanced(1141pub fn compareHeteroAdvanced(
1111 lhs: Value,1142 lhs: Value,
1112 op: std.math.CompareOperator,1143 op: std.math.CompareOperator,
1113 rhs: Value,1144 rhs: Value,
1114 pt: Zcu.PerThread,
1115 comptime strat: ResolveStrat,1145 comptime strat: ResolveStrat,
1146 zcu: *Zcu,
1147 tid: strat.Tid(),
1116) !bool {1148) !bool {
1117 if (lhs.pointerNav(pt.zcu)) |lhs_nav| {1149 if (lhs.pointerNav(zcu)) |lhs_nav| {
1118 if (rhs.pointerNav(pt.zcu)) |rhs_nav| {1150 if (rhs.pointerNav(zcu)) |rhs_nav| {
1119 switch (op) {1151 switch (op) {
1120 .eq => return lhs_nav == rhs_nav,1152 .eq => return lhs_nav == rhs_nav,
1121 .neq => return lhs_nav != rhs_nav,1153 .neq => return lhs_nav != rhs_nav,
...@@ -1128,32 +1160,32 @@ pub fn compareHeteroAdvanced(...@@ -1128,32 +1160,32 @@ pub fn compareHeteroAdvanced(
1128 else => {},1160 else => {},
1129 }1161 }
1130 }1162 }
1131 } else if (rhs.pointerNav(pt.zcu)) |_| {1163 } else if (rhs.pointerNav(zcu)) |_| {
1132 switch (op) {1164 switch (op) {
1133 .eq => return false,1165 .eq => return false,
1134 .neq => return true,1166 .neq => return true,
1135 else => {},1167 else => {},
1136 }1168 }
1137 }1169 }
1138 return (try orderAdvanced(lhs, rhs, pt, strat)).compare(op);1170 return (try orderAdvanced(lhs, rhs, strat, zcu, tid)).compare(op);
1139}1171}
11401172
1141/// Asserts the values are comparable. Both operands have type `ty`.1173/// Asserts the values are comparable. Both operands have type `ty`.
1142/// For vectors, returns true if comparison is true for ALL elements.1174/// For vectors, returns true if comparison is true for ALL elements.
1143pub fn compareAll(lhs: Value, op: std.math.CompareOperator, rhs: Value, ty: Type, pt: Zcu.PerThread) !bool {1175pub fn compareAll(lhs: Value, op: std.math.CompareOperator, rhs: Value, ty: Type, pt: Zcu.PerThread) !bool {
1144 const mod = pt.zcu;1176 const zcu = pt.zcu;
1145 if (ty.zigTypeTag(mod) == .Vector) {1177 if (ty.zigTypeTag(zcu) == .Vector) {
1146 const scalar_ty = ty.scalarType(mod);1178 const scalar_ty = ty.scalarType(zcu);
1147 for (0..ty.vectorLen(mod)) |i| {1179 for (0..ty.vectorLen(zcu)) |i| {
1148 const lhs_elem = try lhs.elemValue(pt, i);1180 const lhs_elem = try lhs.elemValue(pt, i);
1149 const rhs_elem = try rhs.elemValue(pt, i);1181 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)) {
1151 return false;1183 return false;
1152 }1184 }
1153 }1185 }
1154 return true;1186 return true;
1155 }1187 }
1156 return compareScalar(lhs, op, rhs, ty, pt);1188 return compareScalar(lhs, op, rhs, ty, zcu);
1157}1189}
11581190
1159/// Asserts the values are comparable. Both operands have type `ty`.1191/// Asserts the values are comparable. Both operands have type `ty`.
...@@ -1162,12 +1194,12 @@ pub fn compareScalar(...@@ -1162,12 +1194,12 @@ pub fn compareScalar(
1162 op: std.math.CompareOperator,1194 op: std.math.CompareOperator,
1163 rhs: Value,1195 rhs: Value,
1164 ty: Type,1196 ty: Type,
1165 pt: Zcu.PerThread,1197 zcu: *Zcu,
1166) bool {1198) bool {
1167 return switch (op) {1199 return switch (op) {
1168 .eq => lhs.eql(rhs, ty, pt.zcu),1200 .eq => lhs.eql(rhs, ty, zcu),
1169 .neq => !lhs.eql(rhs, ty, pt.zcu),1201 .neq => !lhs.eql(rhs, ty, zcu),
1170 else => compareHetero(lhs, op, rhs, pt),1202 else => compareHetero(lhs, op, rhs, zcu),
1171 };1203 };
1172}1204}
11731205
...@@ -1176,56 +1208,56 @@ pub fn compareScalar(...@@ -1176,56 +1208,56 @@ pub fn compareScalar(
1176/// Returns `false` if the value or any vector element is undefined.1208/// Returns `false` if the value or any vector element is undefined.
1177///1209///
1178/// Note that `!compareAllWithZero(.eq, ...) != compareAllWithZero(.neq, ...)`1210/// Note that `!compareAllWithZero(.eq, ...) != compareAllWithZero(.neq, ...)`
1179pub fn compareAllWithZero(lhs: Value, op: std.math.CompareOperator, pt: Zcu.PerThread) bool {1211pub fn compareAllWithZero(lhs: Value, op: std.math.CompareOperator, zcu: *Zcu) bool {
1180 return compareAllWithZeroAdvancedExtra(lhs, op, pt, .normal) catch unreachable;1212 return compareAllWithZeroAdvancedExtra(lhs, op, .normal, zcu, {}) catch unreachable;
1181}1213}
11821214
1183pub fn compareAllWithZeroSema(1215pub fn compareAllWithZeroSema(
1184 lhs: Value,1216 lhs: Value,
1185 op: std.math.CompareOperator,1217 op: std.math.CompareOperator,
1186 pt: Zcu.PerThread,1218 pt: Zcu.PerThread,
1187) Module.CompileError!bool {1219) Zcu.CompileError!bool {
1188 return compareAllWithZeroAdvancedExtra(lhs, op, pt, .sema);1220 return compareAllWithZeroAdvancedExtra(lhs, op, .sema, pt.zcu, pt.tid);
1189}1221}
11901222
1191pub fn compareAllWithZeroAdvancedExtra(1223pub fn compareAllWithZeroAdvancedExtra(
1192 lhs: Value,1224 lhs: Value,
1193 op: std.math.CompareOperator,1225 op: std.math.CompareOperator,
1194 pt: Zcu.PerThread,
1195 comptime strat: ResolveStrat,1226 comptime strat: ResolveStrat,
1196) Module.CompileError!bool {1227 zcu: *Zcu,
1197 const mod = pt.zcu;1228 tid: strat.Tid(),
1198 if (lhs.isInf(mod)) {1229) Zcu.CompileError!bool {
1230 if (lhs.isInf(zcu)) {
1199 switch (op) {1231 switch (op) {
1200 .neq => return true,1232 .neq => return true,
1201 .eq => return false,1233 .eq => return false,
1202 .gt, .gte => return !lhs.isNegativeInf(mod),1234 .gt, .gte => return !lhs.isNegativeInf(zcu),
1203 .lt, .lte => return lhs.isNegativeInf(mod),1235 .lt, .lte => return lhs.isNegativeInf(zcu),
1204 }1236 }
1205 }1237 }
12061238
1207 switch (mod.intern_pool.indexToKey(lhs.toIntern())) {1239 switch (zcu.intern_pool.indexToKey(lhs.toIntern())) {
1208 .float => |float| switch (float.storage) {1240 .float => |float| switch (float.storage) {
1209 inline else => |x| if (std.math.isNan(x)) return op == .neq,1241 inline else => |x| if (std.math.isNan(x)) return op == .neq,
1210 },1242 },
1211 .aggregate => |aggregate| return switch (aggregate.storage) {1243 .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| {
1213 if (!std.math.order(byte, 0).compare(op)) break false;1245 if (!std.math.order(byte, 0).compare(op)) break false;
1214 } else true,1246 } else true,
1215 .elems => |elems| for (elems) |elem| {1247 .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;
1217 } else true,1249 } 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),
1219 },1251 },
1220 .undef => return false,1252 .undef => return false,
1221 else => {},1253 else => {},
1222 }1254 }
1223 return (try orderAgainstZeroAdvanced(lhs, pt, strat)).compare(op);1255 return (try orderAgainstZeroInner(lhs, strat, zcu, tid)).compare(op);
1224}1256}
12251257
1226pub fn eql(a: Value, b: Value, ty: Type, mod: *Module) bool {1258pub fn eql(a: Value, b: Value, ty: Type, zcu: *Zcu) bool {
1227 assert(mod.intern_pool.typeOf(a.toIntern()) == ty.toIntern());1259 assert(zcu.intern_pool.typeOf(a.toIntern()) == ty.toIntern());
1228 assert(mod.intern_pool.typeOf(b.toIntern()) == ty.toIntern());1260 assert(zcu.intern_pool.typeOf(b.toIntern()) == ty.toIntern());
1229 return a.toIntern() == b.toIntern();1261 return a.toIntern() == b.toIntern();
1230}1262}
12311263
...@@ -1260,8 +1292,8 @@ pub fn canMutateComptimeVarState(val: Value, zcu: *Zcu) bool {...@@ -1260,8 +1292,8 @@ pub fn canMutateComptimeVarState(val: Value, zcu: *Zcu) bool {
1260/// Gets the `Nav` referenced by this pointer. If the pointer does not point1292/// Gets the `Nav` referenced by this pointer. If the pointer does not point
1261/// to a `Nav`, or if it points to some part of one (like a field or element),1293/// to a `Nav`, or if it points to some part of one (like a field or element),
1262/// returns null.1294/// returns null.
1263pub fn pointerNav(val: Value, mod: *Module) ?InternPool.Nav.Index {1295pub fn pointerNav(val: Value, zcu: *Zcu) ?InternPool.Nav.Index {
1264 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1296 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1265 // TODO: these 3 cases are weird; these aren't pointer values!1297 // TODO: these 3 cases are weird; these aren't pointer values!
1266 .variable => |v| v.owner_nav,1298 .variable => |v| v.owner_nav,
1267 .@"extern" => |e| e.owner_nav,1299 .@"extern" => |e| e.owner_nav,
...@@ -1277,8 +1309,8 @@ pub fn pointerNav(val: Value, mod: *Module) ?InternPool.Nav.Index {...@@ -1277,8 +1309,8 @@ pub fn pointerNav(val: Value, mod: *Module) ?InternPool.Nav.Index {
1277pub const slice_ptr_index = 0;1309pub const slice_ptr_index = 0;
1278pub const slice_len_index = 1;1310pub const slice_len_index = 1;
12791311
1280pub fn slicePtr(val: Value, mod: *Module) Value {1312pub fn slicePtr(val: Value, zcu: *Zcu) Value {
1281 return Value.fromInterned(mod.intern_pool.slicePtr(val.toIntern()));1313 return Value.fromInterned(zcu.intern_pool.slicePtr(val.toIntern()));
1282}1314}
12831315
1284/// Gets the `len` field of a slice value as a `u64`.1316/// 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...@@ -1312,15 +1344,15 @@ pub fn elemValue(val: Value, pt: Zcu.PerThread, index: usize) Allocator.Error!Va
1312 }1344 }
1313}1345}
13141346
1315pub fn isLazyAlign(val: Value, mod: *Module) bool {1347pub fn isLazyAlign(val: Value, zcu: *Zcu) bool {
1316 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1348 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1317 .int => |int| int.storage == .lazy_align,1349 .int => |int| int.storage == .lazy_align,
1318 else => false,1350 else => false,
1319 };1351 };
1320}1352}
13211353
1322pub fn isLazySize(val: Value, mod: *Module) bool {1354pub fn isLazySize(val: Value, zcu: *Zcu) bool {
1323 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1355 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1324 .int => |int| int.storage == .lazy_size,1356 .int => |int| int.storage == .lazy_size,
1325 else => false,1357 else => false,
1326 };1358 };
...@@ -1377,15 +1409,15 @@ pub fn sliceArray(...@@ -1377,15 +1409,15 @@ pub fn sliceArray(
1377}1409}
13781410
1379pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {1411pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
1380 const mod = pt.zcu;1412 const zcu = pt.zcu;
1381 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1413 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1382 .undef => |ty| Value.fromInterned(try pt.intern(.{1414 .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(),
1384 })),1416 })),
1385 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {1417 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {
1386 .bytes => |bytes| try pt.intern(.{ .int = .{1418 .bytes => |bytes| try pt.intern(.{ .int = .{
1387 .ty = .u8_type,1419 .ty = .u8_type,
1388 .storage = .{ .u64 = bytes.at(index, &mod.intern_pool) },1420 .storage = .{ .u64 = bytes.at(index, &zcu.intern_pool) },
1389 } }),1421 } }),
1390 .elems => |elems| elems[index],1422 .elems => |elems| elems[index],
1391 .repeated_elem => |elem| elem,1423 .repeated_elem => |elem| elem,
...@@ -1396,40 +1428,40 @@ pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {...@@ -1396,40 +1428,40 @@ pub fn fieldValue(val: Value, pt: Zcu.PerThread, index: usize) !Value {
1396 };1428 };
1397}1429}
13981430
1399pub fn unionTag(val: Value, mod: *Module) ?Value {1431pub fn unionTag(val: Value, zcu: *Zcu) ?Value {
1400 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1432 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1401 .undef, .enum_tag => val,1433 .undef, .enum_tag => val,
1402 .un => |un| if (un.tag != .none) Value.fromInterned(un.tag) else return null,1434 .un => |un| if (un.tag != .none) Value.fromInterned(un.tag) else return null,
1403 else => unreachable,1435 else => unreachable,
1404 };1436 };
1405}1437}
14061438
1407pub fn unionValue(val: Value, mod: *Module) Value {1439pub fn unionValue(val: Value, zcu: *Zcu) Value {
1408 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1440 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1409 .un => |un| Value.fromInterned(un.val),1441 .un => |un| Value.fromInterned(un.val),
1410 else => unreachable,1442 else => unreachable,
1411 };1443 };
1412}1444}
14131445
1414pub fn isUndef(val: Value, mod: *Module) bool {1446pub fn isUndef(val: Value, zcu: *Zcu) bool {
1415 return mod.intern_pool.isUndef(val.toIntern());1447 return zcu.intern_pool.isUndef(val.toIntern());
1416}1448}
14171449
1418/// TODO: check for cases such as array that is not marked undef but all the element1450/// TODO: check for cases such as array that is not marked undef but all the element
1419/// values are marked undef, or struct that is not marked undef but all fields are marked1451/// values are marked undef, or struct that is not marked undef but all fields are marked
1420/// undef, etc.1452/// undef, etc.
1421pub fn isUndefDeep(val: Value, mod: *Module) bool {1453pub fn isUndefDeep(val: Value, zcu: *Zcu) bool {
1422 return val.isUndef(mod);1454 return val.isUndef(zcu);
1423}1455}
14241456
1425/// Asserts the value is not undefined and not unreachable.1457/// Asserts the value is not undefined and not unreachable.
1426/// C pointers with an integer value of 0 are also considered null.1458/// 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 {
1428 return switch (val.toIntern()) {1460 return switch (val.toIntern()) {
1429 .undef => unreachable,1461 .undef => unreachable,
1430 .unreachable_value => unreachable,1462 .unreachable_value => unreachable,
1431 .null_value => true,1463 .null_value => true,
1432 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {1464 else => return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1433 .undef => unreachable,1465 .undef => unreachable,
1434 .ptr => |ptr| switch (ptr.base_addr) {1466 .ptr => |ptr| switch (ptr.base_addr) {
1435 .int => ptr.byte_offset == 0,1467 .int => ptr.byte_offset == 0,
...@@ -1442,8 +1474,8 @@ pub fn isNull(val: Value, mod: *Module) bool {...@@ -1442,8 +1474,8 @@ pub fn isNull(val: Value, mod: *Module) bool {
1442}1474}
14431475
1444/// Valid only for error (union) types. Asserts the value is not undefined and not unreachable.1476/// 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 {1477pub fn getErrorName(val: Value, zcu: *const Zcu) InternPool.OptionalNullTerminatedString {
1446 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1478 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1447 .err => |err| err.name.toOptional(),1479 .err => |err| err.name.toOptional(),
1448 .error_union => |error_union| switch (error_union.val) {1480 .error_union => |error_union| switch (error_union.val) {
1449 .err_name => |err_name| err_name.toOptional(),1481 .err_name => |err_name| err_name.toOptional(),
...@@ -1453,7 +1485,7 @@ pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTermi...@@ -1453,7 +1485,7 @@ pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTermi
1453 };1485 };
1454}1486}
14551487
1456pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {1488pub fn getErrorInt(val: Value, zcu: *Zcu) Zcu.ErrorInt {
1457 return if (getErrorName(val, zcu).unwrap()) |err_name|1489 return if (getErrorName(val, zcu).unwrap()) |err_name|
1458 zcu.intern_pool.getErrorValueIfExists(err_name).?1490 zcu.intern_pool.getErrorValueIfExists(err_name).?
1459 else1491 else
...@@ -1462,13 +1494,13 @@ pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {...@@ -1462,13 +1494,13 @@ pub fn getErrorInt(val: Value, zcu: *Zcu) Module.ErrorInt {
14621494
1463/// Assumes the type is an error union. Returns true if and only if the value is1495/// Assumes the type is an error union. Returns true if and only if the value is
1464/// the error union payload, not an error.1496/// the error union payload, not an error.
1465pub fn errorUnionIsPayload(val: Value, mod: *const Module) bool {1497pub fn errorUnionIsPayload(val: Value, zcu: *const Zcu) bool {
1466 return mod.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;1498 return zcu.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;
1467}1499}
14681500
1469/// Value of the optional, null if optional has no payload.1501/// Value of the optional, null if optional has no payload.
1470pub fn optionalValue(val: Value, mod: *const Module) ?Value {1502pub fn optionalValue(val: Value, zcu: *const Zcu) ?Value {
1471 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1503 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1472 .opt => |opt| switch (opt.val) {1504 .opt => |opt| switch (opt.val) {
1473 .none => null,1505 .none => null,
1474 else => |payload| Value.fromInterned(payload),1506 else => |payload| Value.fromInterned(payload),
...@@ -1479,10 +1511,10 @@ pub fn optionalValue(val: Value, mod: *const Module) ?Value {...@@ -1479,10 +1511,10 @@ pub fn optionalValue(val: Value, mod: *const Module) ?Value {
1479}1511}
14801512
1481/// Valid for all types. Asserts the value is not undefined.1513/// 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 {
1483 return switch (self.toIntern()) {1515 return switch (self.toIntern()) {
1484 .undef => unreachable,1516 .undef => unreachable,
1485 else => switch (mod.intern_pool.indexToKey(self.toIntern())) {1517 else => switch (zcu.intern_pool.indexToKey(self.toIntern())) {
1486 .undef => unreachable,1518 .undef => unreachable,
1487 .float => true,1519 .float => true,
1488 else => false,1520 else => false,
...@@ -1490,8 +1522,8 @@ pub fn isFloat(self: Value, mod: *const Module) bool {...@@ -1490,8 +1522,8 @@ pub fn isFloat(self: Value, mod: *const Module) bool {
1490 };1522 };
1491}1523}
14921524
1493pub fn floatFromInt(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module) !Value {1525pub fn floatFromInt(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, zcu: *Zcu) !Value {
1494 return floatFromIntAdvanced(val, arena, int_ty, float_ty, mod, .normal) catch |err| switch (err) {1526 return floatFromIntAdvanced(val, arena, int_ty, float_ty, zcu, .normal) catch |err| switch (err) {
1495 error.OutOfMemory => return error.OutOfMemory,1527 error.OutOfMemory => return error.OutOfMemory,
1496 else => unreachable,1528 else => unreachable,
1497 };1529 };
...@@ -1505,10 +1537,10 @@ pub fn floatFromIntAdvanced(...@@ -1505,10 +1537,10 @@ pub fn floatFromIntAdvanced(
1505 pt: Zcu.PerThread,1537 pt: Zcu.PerThread,
1506 comptime strat: ResolveStrat,1538 comptime strat: ResolveStrat,
1507) !Value {1539) !Value {
1508 const mod = pt.zcu;1540 const zcu = pt.zcu;
1509 if (int_ty.zigTypeTag(mod) == .Vector) {1541 if (int_ty.zigTypeTag(zcu) == .Vector) {
1510 const result_data = try arena.alloc(InternPool.Index, int_ty.vectorLen(mod));1542 const result_data = try arena.alloc(InternPool.Index, int_ty.vectorLen(zcu));
1511 const scalar_ty = float_ty.scalarType(mod);1543 const scalar_ty = float_ty.scalarType(zcu);
1512 for (result_data, 0..) |*scalar, i| {1544 for (result_data, 0..) |*scalar, i| {
1513 const elem_val = try val.elemValue(pt, i);1545 const elem_val = try val.elemValue(pt, i);
1514 scalar.* = (try floatFromIntScalar(elem_val, scalar_ty, pt, strat)).toIntern();1546 scalar.* = (try floatFromIntScalar(elem_val, scalar_ty, pt, strat)).toIntern();
...@@ -1522,8 +1554,8 @@ pub fn floatFromIntAdvanced(...@@ -1522,8 +1554,8 @@ pub fn floatFromIntAdvanced(
1522}1554}
15231555
1524pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Value {1556pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptime strat: ResolveStrat) !Value {
1525 const mod = pt.zcu;1557 const zcu = pt.zcu;
1526 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1558 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
1527 .undef => try pt.undefValue(float_ty),1559 .undef => try pt.undefValue(float_ty),
1528 .int => |int| switch (int.storage) {1560 .int => |int| switch (int.storage) {
1529 .big_int => |big_int| {1561 .big_int => |big_int| {
...@@ -1531,8 +1563,8 @@ pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptim...@@ -1531,8 +1563,8 @@ pub fn floatFromIntScalar(val: Value, float_ty: Type, pt: Zcu.PerThread, comptim
1531 return pt.floatValue(float_ty, float);1563 return pt.floatValue(float_ty, float);
1532 },1564 },
1533 inline .u64, .i64 => |x| floatFromIntInner(x, float_ty, pt),1565 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),1566 .lazy_align => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiAlignmentInner(strat.toLazy(), pt.zcu, pt.tid)).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),1567 .lazy_size => |ty| return floatFromIntInner((try Type.fromInterned(ty).abiSizeInner(strat.toLazy(), pt.zcu, pt.tid)).scalar, float_ty, pt),
1536 },1568 },
1537 else => unreachable,1569 else => unreachable,
1538 };1570 };
...@@ -1600,15 +1632,16 @@ pub fn intAddSatScalar(...@@ -1600,15 +1632,16 @@ pub fn intAddSatScalar(
1600 arena: Allocator,1632 arena: Allocator,
1601 pt: Zcu.PerThread,1633 pt: Zcu.PerThread,
1602) !Value {1634) !Value {
1603 assert(!lhs.isUndef(pt.zcu));1635 const zcu = pt.zcu;
1604 assert(!rhs.isUndef(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
1608 var lhs_space: Value.BigIntSpace = undefined;1641 var lhs_space: Value.BigIntSpace = undefined;
1609 var rhs_space: Value.BigIntSpace = undefined;1642 var rhs_space: Value.BigIntSpace = undefined;
1610 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);1643 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1611 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);1644 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
1612 const limbs = try arena.alloc(1645 const limbs = try arena.alloc(
1613 std.math.big.Limb,1646 std.math.big.Limb,
1614 std.math.big.int.calcTwosCompLimbCount(info.bits),1647 std.math.big.int.calcTwosCompLimbCount(info.bits),
...@@ -1650,15 +1683,17 @@ pub fn intSubSatScalar(...@@ -1650,15 +1683,17 @@ pub fn intSubSatScalar(
1650 arena: Allocator,1683 arena: Allocator,
1651 pt: Zcu.PerThread,1684 pt: Zcu.PerThread,
1652) !Value {1685) !Value {
1653 assert(!lhs.isUndef(pt.zcu));1686 const zcu = pt.zcu;
1654 assert(!rhs.isUndef(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
1658 var lhs_space: Value.BigIntSpace = undefined;1693 var lhs_space: Value.BigIntSpace = undefined;
1659 var rhs_space: Value.BigIntSpace = undefined;1694 var rhs_space: Value.BigIntSpace = undefined;
1660 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);1695 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1661 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);1696 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
1662 const limbs = try arena.alloc(1697 const limbs = try arena.alloc(
1663 std.math.big.Limb,1698 std.math.big.Limb,
1664 std.math.big.int.calcTwosCompLimbCount(info.bits),1699 std.math.big.int.calcTwosCompLimbCount(info.bits),
...@@ -1675,12 +1710,12 @@ pub fn intMulWithOverflow(...@@ -1675,12 +1710,12 @@ pub fn intMulWithOverflow(
1675 arena: Allocator,1710 arena: Allocator,
1676 pt: Zcu.PerThread,1711 pt: Zcu.PerThread,
1677) !OverflowArithmeticResult {1712) !OverflowArithmeticResult {
1678 const mod = pt.zcu;1713 const zcu = pt.zcu;
1679 if (ty.zigTypeTag(mod) == .Vector) {1714 if (ty.zigTypeTag(zcu) == .Vector) {
1680 const vec_len = ty.vectorLen(mod);1715 const vec_len = ty.vectorLen(zcu);
1681 const overflowed_data = try arena.alloc(InternPool.Index, vec_len);1716 const overflowed_data = try arena.alloc(InternPool.Index, vec_len);
1682 const result_data = try arena.alloc(InternPool.Index, vec_len);1717 const result_data = try arena.alloc(InternPool.Index, vec_len);
1683 const scalar_ty = ty.scalarType(mod);1718 const scalar_ty = ty.scalarType(zcu);
1684 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {1719 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
1685 const lhs_elem = try lhs.elemValue(pt, i);1720 const lhs_elem = try lhs.elemValue(pt, i);
1686 const rhs_elem = try rhs.elemValue(pt, i);1721 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -1709,10 +1744,10 @@ pub fn intMulWithOverflowScalar(...@@ -1709,10 +1744,10 @@ pub fn intMulWithOverflowScalar(
1709 arena: Allocator,1744 arena: Allocator,
1710 pt: Zcu.PerThread,1745 pt: Zcu.PerThread,
1711) !OverflowArithmeticResult {1746) !OverflowArithmeticResult {
1712 const mod = pt.zcu;1747 const zcu = pt.zcu;
1713 const info = ty.intInfo(mod);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)) {
1716 return .{1751 return .{
1717 .overflow_bit = try pt.undefValue(Type.u1),1752 .overflow_bit = try pt.undefValue(Type.u1),
1718 .wrapped_result = try pt.undefValue(ty),1753 .wrapped_result = try pt.undefValue(ty),
...@@ -1721,8 +1756,8 @@ pub fn intMulWithOverflowScalar(...@@ -1721,8 +1756,8 @@ pub fn intMulWithOverflowScalar(
17211756
1722 var lhs_space: Value.BigIntSpace = undefined;1757 var lhs_space: Value.BigIntSpace = undefined;
1723 var rhs_space: Value.BigIntSpace = undefined;1758 var rhs_space: Value.BigIntSpace = undefined;
1724 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);1759 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1725 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);1760 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
1726 const limbs = try arena.alloc(1761 const limbs = try arena.alloc(
1727 std.math.big.Limb,1762 std.math.big.Limb,
1728 lhs_bigint.limbs.len + rhs_bigint.limbs.len,1763 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
...@@ -1753,10 +1788,10 @@ pub fn numberMulWrap(...@@ -1753,10 +1788,10 @@ pub fn numberMulWrap(
1753 arena: Allocator,1788 arena: Allocator,
1754 pt: Zcu.PerThread,1789 pt: Zcu.PerThread,
1755) !Value {1790) !Value {
1756 const mod = pt.zcu;1791 const zcu = pt.zcu;
1757 if (ty.zigTypeTag(mod) == .Vector) {1792 if (ty.zigTypeTag(zcu) == .Vector) {
1758 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));1793 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
1759 const scalar_ty = ty.scalarType(mod);1794 const scalar_ty = ty.scalarType(zcu);
1760 for (result_data, 0..) |*scalar, i| {1795 for (result_data, 0..) |*scalar, i| {
1761 const lhs_elem = try lhs.elemValue(pt, i);1796 const lhs_elem = try lhs.elemValue(pt, i);
1762 const rhs_elem = try rhs.elemValue(pt, i);1797 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -1778,10 +1813,10 @@ pub fn numberMulWrapScalar(...@@ -1778,10 +1813,10 @@ pub fn numberMulWrapScalar(
1778 arena: Allocator,1813 arena: Allocator,
1779 pt: Zcu.PerThread,1814 pt: Zcu.PerThread,
1780) !Value {1815) !Value {
1781 const mod = pt.zcu;1816 const zcu = pt.zcu;
1782 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.undef;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) {
1785 return intMul(lhs, rhs, ty, undefined, arena, pt);1820 return intMul(lhs, rhs, ty, undefined, arena, pt);
1786 }1821 }
17871822
...@@ -1825,15 +1860,17 @@ pub fn intMulSatScalar(...@@ -1825,15 +1860,17 @@ pub fn intMulSatScalar(
1825 arena: Allocator,1860 arena: Allocator,
1826 pt: Zcu.PerThread,1861 pt: Zcu.PerThread,
1827) !Value {1862) !Value {
1828 assert(!lhs.isUndef(pt.zcu));1863 const zcu = pt.zcu;
1829 assert(!rhs.isUndef(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
1833 var lhs_space: Value.BigIntSpace = undefined;1870 var lhs_space: Value.BigIntSpace = undefined;
1834 var rhs_space: Value.BigIntSpace = undefined;1871 var rhs_space: Value.BigIntSpace = undefined;
1835 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);1872 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1836 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);1873 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
1837 const limbs = try arena.alloc(1874 const limbs = try arena.alloc(
1838 std.math.big.Limb,1875 std.math.big.Limb,
1839 @max(1876 @max(
...@@ -1853,24 +1890,24 @@ pub fn intMulSatScalar(...@@ -1853,24 +1890,24 @@ pub fn intMulSatScalar(
1853}1890}
18541891
1855/// Supports both floats and ints; handles undefined.1892/// Supports both floats and ints; handles undefined.
1856pub fn numberMax(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {1893pub fn numberMax(lhs: Value, rhs: Value, zcu: *Zcu) Value {
1857 if (lhs.isUndef(pt.zcu) or rhs.isUndef(pt.zcu)) return undef;1894 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return undef;
1858 if (lhs.isNan(pt.zcu)) return rhs;1895 if (lhs.isNan(zcu)) return rhs;
1859 if (rhs.isNan(pt.zcu)) return lhs;1896 if (rhs.isNan(zcu)) return lhs;
18601897
1861 return switch (order(lhs, rhs, pt)) {1898 return switch (order(lhs, rhs, zcu)) {
1862 .lt => rhs,1899 .lt => rhs,
1863 .gt, .eq => lhs,1900 .gt, .eq => lhs,
1864 };1901 };
1865}1902}
18661903
1867/// Supports both floats and ints; handles undefined.1904/// Supports both floats and ints; handles undefined.
1868pub fn numberMin(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {1905pub fn numberMin(lhs: Value, rhs: Value, zcu: *Zcu) Value {
1869 if (lhs.isUndef(pt.zcu) or rhs.isUndef(pt.zcu)) return undef;1906 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return undef;
1870 if (lhs.isNan(pt.zcu)) return rhs;1907 if (lhs.isNan(zcu)) return rhs;
1871 if (rhs.isNan(pt.zcu)) return lhs;1908 if (rhs.isNan(zcu)) return lhs;
18721909
1873 return switch (order(lhs, rhs, pt)) {1910 return switch (order(lhs, rhs, zcu)) {
1874 .lt => lhs,1911 .lt => lhs,
1875 .gt, .eq => rhs,1912 .gt, .eq => rhs,
1876 };1913 };
...@@ -1878,10 +1915,10 @@ pub fn numberMin(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {...@@ -1878,10 +1915,10 @@ pub fn numberMin(lhs: Value, rhs: Value, pt: Zcu.PerThread) Value {
18781915
1879/// operands must be (vectors of) integers; handles undefined scalars.1916/// operands must be (vectors of) integers; handles undefined scalars.
1880pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {1917pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
1881 const mod = pt.zcu;1918 const zcu = pt.zcu;
1882 if (ty.zigTypeTag(mod) == .Vector) {1919 if (ty.zigTypeTag(zcu) == .Vector) {
1883 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));1920 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
1884 const scalar_ty = ty.scalarType(mod);1921 const scalar_ty = ty.scalarType(zcu);
1885 for (result_data, 0..) |*scalar, i| {1922 for (result_data, 0..) |*scalar, i| {
1886 const elem_val = try val.elemValue(pt, i);1923 const elem_val = try val.elemValue(pt, i);
1887 scalar.* = (try bitwiseNotScalar(elem_val, scalar_ty, arena, pt)).toIntern();1924 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...@@ -1896,11 +1933,11 @@ pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Va
18961933
1897/// operands must be integers; handles undefined.1934/// operands must be integers; handles undefined.
1898pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {1935pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
1899 const mod = pt.zcu;1936 const zcu = pt.zcu;
1900 if (val.isUndef(mod)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));1937 if (val.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
1901 if (ty.toIntern() == .bool_type) return makeBool(!val.toBool());1938 if (ty.toIntern() == .bool_type) return makeBool(!val.toBool());
19021939
1903 const info = ty.intInfo(mod);1940 const info = ty.intInfo(zcu);
19041941
1905 if (info.bits == 0) {1942 if (info.bits == 0) {
1906 return val;1943 return val;
...@@ -1909,7 +1946,7 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea...@@ -1909,7 +1946,7 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea
1909 // TODO is this a performance issue? maybe we should try the operation without1946 // TODO is this a performance issue? maybe we should try the operation without
1910 // resorting to BigInt first.1947 // resorting to BigInt first.
1911 var val_space: Value.BigIntSpace = undefined;1948 var val_space: Value.BigIntSpace = undefined;
1912 const val_bigint = val.toBigInt(&val_space, pt);1949 const val_bigint = val.toBigInt(&val_space, zcu);
1913 const limbs = try arena.alloc(1950 const limbs = try arena.alloc(
1914 std.math.big.Limb,1951 std.math.big.Limb,
1915 std.math.big.int.calcTwosCompLimbCount(info.bits),1952 std.math.big.int.calcTwosCompLimbCount(info.bits),
...@@ -1922,10 +1959,10 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea...@@ -1922,10 +1959,10 @@ pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThrea
19221959
1923/// operands must be (vectors of) integers; handles undefined scalars.1960/// operands must be (vectors of) integers; handles undefined scalars.
1924pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {1961pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
1925 const mod = pt.zcu;1962 const zcu = pt.zcu;
1926 if (ty.zigTypeTag(mod) == .Vector) {1963 if (ty.zigTypeTag(zcu) == .Vector) {
1927 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));1964 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
1928 const scalar_ty = ty.scalarType(mod);1965 const scalar_ty = ty.scalarType(zcu);
1929 for (result_data, 0..) |*scalar, i| {1966 for (result_data, 0..) |*scalar, i| {
1930 const lhs_elem = try lhs.elemValue(pt, i);1967 const lhs_elem = try lhs.elemValue(pt, i);
1931 const rhs_elem = try rhs.elemValue(pt, i);1968 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...@@ -1962,8 +1999,8 @@ pub fn bitwiseAndScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloc
1962 // resorting to BigInt first.1999 // resorting to BigInt first.
1963 var lhs_space: Value.BigIntSpace = undefined;2000 var lhs_space: Value.BigIntSpace = undefined;
1964 var rhs_space: Value.BigIntSpace = undefined;2001 var rhs_space: Value.BigIntSpace = undefined;
1965 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2002 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
1966 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);2003 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
1967 const limbs = try arena.alloc(2004 const limbs = try arena.alloc(
1968 std.math.big.Limb,2005 std.math.big.Limb,
1969 // + 1 for negatives2006 // + 1 for negatives
...@@ -1995,10 +2032,10 @@ fn intValueAa(ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {...@@ -1995,10 +2032,10 @@ fn intValueAa(ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
19952032
1996/// operands must be (vectors of) integers; handles undefined scalars.2033/// operands must be (vectors of) integers; handles undefined scalars.
1997pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {2034pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
1998 const mod = pt.zcu;2035 const zcu = pt.zcu;
1999 if (ty.zigTypeTag(mod) == .Vector) {2036 if (ty.zigTypeTag(zcu) == .Vector) {
2000 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));2037 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
2001 const scalar_ty = ty.scalarType(mod);2038 const scalar_ty = ty.scalarType(zcu);
2002 for (result_data, 0..) |*scalar, i| {2039 for (result_data, 0..) |*scalar, i| {
2003 const lhs_elem = try lhs.elemValue(pt, i);2040 const lhs_elem = try lhs.elemValue(pt, i);
2004 const rhs_elem = try rhs.elemValue(pt, i);2041 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...@@ -2014,21 +2051,21 @@ pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.P
20142051
2015/// operands must be integers; handles undefined.2052/// operands must be integers; handles undefined.
2016pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {2053pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
2017 const mod = pt.zcu;2054 const zcu = pt.zcu;
2018 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));2055 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
2019 if (ty.toIntern() == .bool_type) return makeBool(!(lhs.toBool() and rhs.toBool()));2056 if (ty.toIntern() == .bool_type) return makeBool(!(lhs.toBool() and rhs.toBool()));
20202057
2021 const anded = try bitwiseAnd(lhs, rhs, ty, arena, pt);2058 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);
2023 return bitwiseXor(anded, all_ones, ty, arena, pt);2060 return bitwiseXor(anded, all_ones, ty, arena, pt);
2024}2061}
20252062
2026/// operands must be (vectors of) integers; handles undefined scalars.2063/// operands must be (vectors of) integers; handles undefined scalars.
2027pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2064pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2028 const mod = pt.zcu;2065 const zcu = pt.zcu;
2029 if (ty.zigTypeTag(mod) == .Vector) {2066 if (ty.zigTypeTag(zcu) == .Vector) {
2030 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));2067 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2031 const scalar_ty = ty.scalarType(mod);2068 const scalar_ty = ty.scalarType(zcu);
2032 for (result_data, 0..) |*scalar, i| {2069 for (result_data, 0..) |*scalar, i| {
2033 const lhs_elem = try lhs.elemValue(pt, i);2070 const lhs_elem = try lhs.elemValue(pt, i);
2034 const rhs_elem = try rhs.elemValue(pt, i);2071 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...@@ -2047,9 +2084,10 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
2047 // If one operand is defined, we turn the other into `0xAA` so the bitwise AND can2084 // If one operand is defined, we turn the other into `0xAA` so the bitwise AND can
2048 // still zero out some bits.2085 // still zero out some bits.
2049 // TODO: ideally we'd still like tracking for the undef bits. Related: #19634.2086 // TODO: ideally we'd still like tracking for the undef bits. Related: #19634.
2087 const zcu = pt.zcu;
2050 const lhs: Value, const rhs: Value = make_defined: {2088 const lhs: Value, const rhs: Value = make_defined: {
2051 const lhs_undef = orig_lhs.isUndef(pt.zcu);2089 const lhs_undef = orig_lhs.isUndef(zcu);
2052 const rhs_undef = orig_rhs.isUndef(pt.zcu);2090 const rhs_undef = orig_rhs.isUndef(zcu);
2053 break :make_defined switch ((@as(u2, @intFromBool(lhs_undef)) << 1) | @intFromBool(rhs_undef)) {2091 break :make_defined switch ((@as(u2, @intFromBool(lhs_undef)) << 1) | @intFromBool(rhs_undef)) {
2054 0b00 => .{ orig_lhs, orig_rhs },2092 0b00 => .{ orig_lhs, orig_rhs },
2055 0b01 => .{ orig_lhs, try intValueAa(ty, arena, pt) },2093 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...@@ -2064,8 +2102,8 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
2064 // resorting to BigInt first.2102 // resorting to BigInt first.
2065 var lhs_space: Value.BigIntSpace = undefined;2103 var lhs_space: Value.BigIntSpace = undefined;
2066 var rhs_space: Value.BigIntSpace = undefined;2104 var rhs_space: Value.BigIntSpace = undefined;
2067 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2105 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2068 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);2106 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
2069 const limbs = try arena.alloc(2107 const limbs = try arena.alloc(
2070 std.math.big.Limb,2108 std.math.big.Limb,
2071 @max(lhs_bigint.limbs.len, rhs_bigint.limbs.len),2109 @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...@@ -2077,10 +2115,10 @@ pub fn bitwiseOrScalar(orig_lhs: Value, orig_rhs: Value, ty: Type, arena: Alloca
20772115
2078/// operands must be (vectors of) integers; handles undefined scalars.2116/// operands must be (vectors of) integers; handles undefined scalars.
2079pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2117pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2080 const mod = pt.zcu;2118 const zcu = pt.zcu;
2081 if (ty.zigTypeTag(mod) == .Vector) {2119 if (ty.zigTypeTag(zcu) == .Vector) {
2082 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));2120 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2083 const scalar_ty = ty.scalarType(mod);2121 const scalar_ty = ty.scalarType(zcu);
2084 for (result_data, 0..) |*scalar, i| {2122 for (result_data, 0..) |*scalar, i| {
2085 const lhs_elem = try lhs.elemValue(pt, i);2123 const lhs_elem = try lhs.elemValue(pt, i);
2086 const rhs_elem = try rhs.elemValue(pt, i);2124 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...@@ -2096,16 +2134,16 @@ pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zc
20962134
2097/// operands must be integers; handles undefined.2135/// operands must be integers; handles undefined.
2098pub fn bitwiseXorScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {2136pub fn bitwiseXorScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
2099 const mod = pt.zcu;2137 const zcu = pt.zcu;
2100 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));2138 if (lhs.isUndef(zcu) or rhs.isUndef(zcu)) return Value.fromInterned(try pt.intern(.{ .undef = ty.toIntern() }));
2101 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() != rhs.toBool());2139 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() != rhs.toBool());
21022140
2103 // TODO is this a performance issue? maybe we should try the operation without2141 // TODO is this a performance issue? maybe we should try the operation without
2104 // resorting to BigInt first.2142 // resorting to BigInt first.
2105 var lhs_space: Value.BigIntSpace = undefined;2143 var lhs_space: Value.BigIntSpace = undefined;
2106 var rhs_space: Value.BigIntSpace = undefined;2144 var rhs_space: Value.BigIntSpace = undefined;
2107 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2145 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2108 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);2146 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
2109 const limbs = try arena.alloc(2147 const limbs = try arena.alloc(
2110 std.math.big.Limb,2148 std.math.big.Limb,
2111 // + 1 for negatives2149 // + 1 for negatives
...@@ -2164,10 +2202,11 @@ fn intDivInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator...@@ -2164,10 +2202,11 @@ fn intDivInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator
2164pub fn intDivScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2202pub fn intDivScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2165 // TODO is this a performance issue? maybe we should try the operation without2203 // TODO is this a performance issue? maybe we should try the operation without
2166 // resorting to BigInt first.2204 // resorting to BigInt first.
2205 const zcu = pt.zcu;
2167 var lhs_space: Value.BigIntSpace = undefined;2206 var lhs_space: Value.BigIntSpace = undefined;
2168 var rhs_space: Value.BigIntSpace = undefined;2207 var rhs_space: Value.BigIntSpace = undefined;
2169 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2208 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2170 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);2209 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
2171 const limbs_q = try allocator.alloc(2210 const limbs_q = try allocator.alloc(
2172 std.math.big.Limb,2211 std.math.big.Limb,
2173 lhs_bigint.limbs.len,2212 lhs_bigint.limbs.len,
...@@ -2212,10 +2251,11 @@ pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Z...@@ -2212,10 +2251,11 @@ pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Z
2212pub fn intDivFloorScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2251pub fn intDivFloorScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2213 // TODO is this a performance issue? maybe we should try the operation without2252 // TODO is this a performance issue? maybe we should try the operation without
2214 // resorting to BigInt first.2253 // resorting to BigInt first.
2254 const zcu = pt.zcu;
2215 var lhs_space: Value.BigIntSpace = undefined;2255 var lhs_space: Value.BigIntSpace = undefined;
2216 var rhs_space: Value.BigIntSpace = undefined;2256 var rhs_space: Value.BigIntSpace = undefined;
2217 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2257 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2218 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);2258 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
2219 const limbs_q = try allocator.alloc(2259 const limbs_q = try allocator.alloc(
2220 std.math.big.Limb,2260 std.math.big.Limb,
2221 lhs_bigint.limbs.len,2261 lhs_bigint.limbs.len,
...@@ -2254,10 +2294,11 @@ pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.Pe...@@ -2254,10 +2294,11 @@ pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.Pe
2254pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2294pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2255 // TODO is this a performance issue? maybe we should try the operation without2295 // TODO is this a performance issue? maybe we should try the operation without
2256 // resorting to BigInt first.2296 // resorting to BigInt first.
2297 const zcu = pt.zcu;
2257 var lhs_space: Value.BigIntSpace = undefined;2298 var lhs_space: Value.BigIntSpace = undefined;
2258 var rhs_space: Value.BigIntSpace = undefined;2299 var rhs_space: Value.BigIntSpace = undefined;
2259 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2300 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2260 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);2301 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
2261 const limbs_q = try allocator.alloc(2302 const limbs_q = try allocator.alloc(
2262 std.math.big.Limb,2303 std.math.big.Limb,
2263 lhs_bigint.limbs.len,2304 lhs_bigint.limbs.len,
...@@ -2277,8 +2318,8 @@ pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:...@@ -2277,8 +2318,8 @@ pub fn intModScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
2277}2318}
22782319
2279/// Returns true if the value is a floating point type and is NaN. Returns false otherwise.2320/// 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 {2321pub fn isNan(val: Value, zcu: *const Zcu) bool {
2281 return switch (mod.intern_pool.indexToKey(val.toIntern())) {2322 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2282 .float => |float| switch (float.storage) {2323 .float => |float| switch (float.storage) {
2283 inline else => |x| std.math.isNan(x),2324 inline else => |x| std.math.isNan(x),
2284 },2325 },
...@@ -2287,8 +2328,8 @@ pub fn isNan(val: Value, mod: *const Module) bool {...@@ -2287,8 +2328,8 @@ pub fn isNan(val: Value, mod: *const Module) bool {
2287}2328}
22882329
2289/// Returns true if the value is a floating point type and is infinite. Returns false otherwise.2330/// 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 {2331pub fn isInf(val: Value, zcu: *const Zcu) bool {
2291 return switch (mod.intern_pool.indexToKey(val.toIntern())) {2332 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2292 .float => |float| switch (float.storage) {2333 .float => |float| switch (float.storage) {
2293 inline else => |x| std.math.isInf(x),2334 inline else => |x| std.math.isInf(x),
2294 },2335 },
...@@ -2296,8 +2337,8 @@ pub fn isInf(val: Value, mod: *const Module) bool {...@@ -2296,8 +2337,8 @@ pub fn isInf(val: Value, mod: *const Module) bool {
2296 };2337 };
2297}2338}
22982339
2299pub fn isNegativeInf(val: Value, mod: *const Module) bool {2340pub fn isNegativeInf(val: Value, zcu: *const Zcu) bool {
2300 return switch (mod.intern_pool.indexToKey(val.toIntern())) {2341 return switch (zcu.intern_pool.indexToKey(val.toIntern())) {
2301 .float => |float| switch (float.storage) {2342 .float => |float| switch (float.storage) {
2302 inline else => |x| std.math.isNegativeInf(x),2343 inline else => |x| std.math.isNegativeInf(x),
2303 },2344 },
...@@ -2323,13 +2364,14 @@ pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:...@@ -2323,13 +2364,14 @@ pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:
2323}2364}
23242365
2325pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThread) !Value {2366pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThread) !Value {
2367 const zcu = pt.zcu;
2326 const target = pt.zcu.getTarget();2368 const target = pt.zcu.getTarget();
2327 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {2369 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2328 16 => .{ .f16 = @rem(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },2370 16 => .{ .f16 = @rem(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
2329 32 => .{ .f32 = @rem(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },2371 32 => .{ .f32 = @rem(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
2330 64 => .{ .f64 = @rem(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },2372 64 => .{ .f64 = @rem(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
2331 80 => .{ .f80 = @rem(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },2373 80 => .{ .f80 = @rem(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
2332 128 => .{ .f128 = @rem(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },2374 128 => .{ .f128 = @rem(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
2333 else => unreachable,2375 else => unreachable,
2334 };2376 };
2335 return Value.fromInterned(try pt.intern(.{ .float = .{2377 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -2356,13 +2398,14 @@ pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:...@@ -2356,13 +2398,14 @@ pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, pt:
2356}2398}
23572399
2358pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThread) !Value {2400pub 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();
2360 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {2403 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2361 16 => .{ .f16 = @mod(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },2404 16 => .{ .f16 = @mod(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
2362 32 => .{ .f32 = @mod(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },2405 32 => .{ .f32 = @mod(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
2363 64 => .{ .f64 = @mod(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },2406 64 => .{ .f64 = @mod(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
2364 80 => .{ .f80 = @mod(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },2407 80 => .{ .f80 = @mod(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
2365 128 => .{ .f128 = @mod(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },2408 128 => .{ .f128 = @mod(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
2366 else => unreachable,2409 else => unreachable,
2367 };2410 };
2368 return Value.fromInterned(try pt.intern(.{ .float = .{2411 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -2374,14 +2417,14 @@ pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThrea...@@ -2374,14 +2417,14 @@ pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, pt: Zcu.PerThrea
2374/// If the value overflowed the type, returns a comptime_int (or vector thereof) instead, setting2417/// If the value overflowed the type, returns a comptime_int (or vector thereof) instead, setting
2375/// overflow_idx to the vector index the overflow was at (or 0 for a scalar).2418/// overflow_idx to the vector index the overflow was at (or 0 for a scalar).
2376pub fn intMul(lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize, allocator: Allocator, pt: Zcu.PerThread) !Value {2419pub 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;
2378 var overflow: usize = undefined;2421 var overflow: usize = undefined;
2379 return intMulInner(lhs, rhs, ty, &overflow, allocator, pt) catch |err| switch (err) {2422 return intMulInner(lhs, rhs, ty, &overflow, allocator, pt) catch |err| switch (err) {
2380 error.Overflow => {2423 error.Overflow => {
2381 const is_vec = ty.isVector(mod);2424 const is_vec = ty.isVector(zcu);
2382 overflow_idx.* = if (is_vec) overflow else 0;2425 overflow_idx.* = if (is_vec) overflow else 0;
2383 const safe_ty = if (is_vec) try pt.vectorType(.{2426 const safe_ty = if (is_vec) try pt.vectorType(.{
2384 .len = ty.vectorLen(mod),2427 .len = ty.vectorLen(zcu),
2385 .child = .comptime_int_type,2428 .child = .comptime_int_type,
2386 }) else Type.comptime_int;2429 }) else Type.comptime_int;
2387 return intMulInner(lhs, rhs, safe_ty, undefined, allocator, pt) catch |err1| switch (err1) {2430 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...@@ -2394,10 +2437,10 @@ pub fn intMul(lhs: Value, rhs: Value, ty: Type, overflow_idx: *?usize, allocator
2394}2437}
23952438
2396fn intMulInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator: Allocator, pt: Zcu.PerThread) !Value {2439fn intMulInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator: Allocator, pt: Zcu.PerThread) !Value {
2397 const mod = pt.zcu;2440 const zcu = pt.zcu;
2398 if (ty.zigTypeTag(mod) == .Vector) {2441 if (ty.zigTypeTag(zcu) == .Vector) {
2399 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));2442 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2400 const scalar_ty = ty.scalarType(mod);2443 const scalar_ty = ty.scalarType(zcu);
2401 for (result_data, 0..) |*scalar, i| {2444 for (result_data, 0..) |*scalar, i| {
2402 const lhs_elem = try lhs.elemValue(pt, i);2445 const lhs_elem = try lhs.elemValue(pt, i);
2403 const rhs_elem = try rhs.elemValue(pt, i);2446 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -2419,17 +2462,18 @@ fn intMulInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator...@@ -2419,17 +2462,18 @@ fn intMulInner(lhs: Value, rhs: Value, ty: Type, overflow_idx: *usize, allocator
2419}2462}
24202463
2421pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2464pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2465 const zcu = pt.zcu;
2422 if (ty.toIntern() != .comptime_int_type) {2466 if (ty.toIntern() != .comptime_int_type) {
2423 const res = try intMulWithOverflowScalar(lhs, rhs, ty, allocator, pt);2467 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;
2425 return res.wrapped_result;2469 return res.wrapped_result;
2426 }2470 }
2427 // TODO is this a performance issue? maybe we should try the operation without2471 // TODO is this a performance issue? maybe we should try the operation without
2428 // resorting to BigInt first.2472 // resorting to BigInt first.
2429 var lhs_space: Value.BigIntSpace = undefined;2473 var lhs_space: Value.BigIntSpace = undefined;
2430 var rhs_space: Value.BigIntSpace = undefined;2474 var rhs_space: Value.BigIntSpace = undefined;
2431 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2475 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2432 const rhs_bigint = rhs.toBigInt(&rhs_space, pt);2476 const rhs_bigint = rhs.toBigInt(&rhs_space, zcu);
2433 const limbs = try allocator.alloc(2477 const limbs = try allocator.alloc(
2434 std.math.big.Limb,2478 std.math.big.Limb,
2435 lhs_bigint.limbs.len + rhs_bigint.limbs.len,2479 lhs_bigint.limbs.len + rhs_bigint.limbs.len,
...@@ -2445,10 +2489,10 @@ pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:...@@ -2445,10 +2489,10 @@ pub fn intMulScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt:
2445}2489}
24462490
2447pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, pt: Zcu.PerThread) !Value {2491pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, pt: Zcu.PerThread) !Value {
2448 const mod = pt.zcu;2492 const zcu = pt.zcu;
2449 if (ty.zigTypeTag(mod) == .Vector) {2493 if (ty.zigTypeTag(zcu) == .Vector) {
2450 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));2494 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2451 const scalar_ty = ty.scalarType(mod);2495 const scalar_ty = ty.scalarType(zcu);
2452 for (result_data, 0..) |*scalar, i| {2496 for (result_data, 0..) |*scalar, i| {
2453 const elem_val = try val.elemValue(pt, i);2497 const elem_val = try val.elemValue(pt, i);
2454 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, pt)).toIntern();2498 scalar.* = (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, pt)).toIntern();
...@@ -2470,20 +2514,21 @@ pub fn intTruncBitsAsValue(...@@ -2470,20 +2514,21 @@ pub fn intTruncBitsAsValue(
2470 bits: Value,2514 bits: Value,
2471 pt: Zcu.PerThread,2515 pt: Zcu.PerThread,
2472) !Value {2516) !Value {
2473 if (ty.zigTypeTag(pt.zcu) == .Vector) {2517 const zcu = pt.zcu;
2474 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(pt.zcu));2518 if (ty.zigTypeTag(zcu) == .Vector) {
2475 const scalar_ty = ty.scalarType(pt.zcu);2519 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2520 const scalar_ty = ty.scalarType(zcu);
2476 for (result_data, 0..) |*scalar, i| {2521 for (result_data, 0..) |*scalar, i| {
2477 const elem_val = try val.elemValue(pt, i);2522 const elem_val = try val.elemValue(pt, i);
2478 const bits_elem = try bits.elemValue(pt, i);2523 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();
2480 }2525 }
2481 return Value.fromInterned(try pt.intern(.{ .aggregate = .{2526 return Value.fromInterned(try pt.intern(.{ .aggregate = .{
2482 .ty = ty.toIntern(),2527 .ty = ty.toIntern(),
2483 .storage = .{ .elems = result_data },2528 .storage = .{ .elems = result_data },
2484 } }));2529 } }));
2485 }2530 }
2486 return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(pt)), pt);2531 return intTruncScalar(val, ty, allocator, signedness, @intCast(bits.toUnsignedInt(zcu)), pt);
2487}2532}
24882533
2489pub fn intTruncScalar(2534pub fn intTruncScalar(
...@@ -2500,7 +2545,7 @@ pub fn intTruncScalar(...@@ -2500,7 +2545,7 @@ pub fn intTruncScalar(
2500 if (val.isUndef(zcu)) return pt.undefValue(ty);2545 if (val.isUndef(zcu)) return pt.undefValue(ty);
25012546
2502 var val_space: Value.BigIntSpace = undefined;2547 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
2505 const limbs = try allocator.alloc(2550 const limbs = try allocator.alloc(
2506 std.math.big.Limb,2551 std.math.big.Limb,
...@@ -2513,10 +2558,10 @@ pub fn intTruncScalar(...@@ -2513,10 +2558,10 @@ pub fn intTruncScalar(
2513}2558}
25142559
2515pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2560pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2516 const mod = pt.zcu;2561 const zcu = pt.zcu;
2517 if (ty.zigTypeTag(mod) == .Vector) {2562 if (ty.zigTypeTag(zcu) == .Vector) {
2518 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));2563 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(zcu));
2519 const scalar_ty = ty.scalarType(mod);2564 const scalar_ty = ty.scalarType(zcu);
2520 for (result_data, 0..) |*scalar, i| {2565 for (result_data, 0..) |*scalar, i| {
2521 const lhs_elem = try lhs.elemValue(pt, i);2566 const lhs_elem = try lhs.elemValue(pt, i);
2522 const rhs_elem = try rhs.elemValue(pt, i);2567 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...@@ -2533,9 +2578,10 @@ pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerTh
2533pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2578pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2534 // TODO is this a performance issue? maybe we should try the operation without2579 // TODO is this a performance issue? maybe we should try the operation without
2535 // resorting to BigInt first.2580 // resorting to BigInt first.
2581 const zcu = pt.zcu;
2536 var lhs_space: Value.BigIntSpace = undefined;2582 var lhs_space: Value.BigIntSpace = undefined;
2537 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2583 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2538 const shift: usize = @intCast(rhs.toUnsignedInt(pt));2584 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
2539 const limbs = try allocator.alloc(2585 const limbs = try allocator.alloc(
2540 std.math.big.Limb,2586 std.math.big.Limb,
2541 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,2587 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...@@ -2547,7 +2593,7 @@ pub fn shlScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu
2547 };2593 };
2548 result_bigint.shiftLeft(lhs_bigint, shift);2594 result_bigint.shiftLeft(lhs_bigint, shift);
2549 if (ty.toIntern() != .comptime_int_type) {2595 if (ty.toIntern() != .comptime_int_type) {
2550 const int_info = ty.intInfo(pt.zcu);2596 const int_info = ty.intInfo(zcu);
2551 result_bigint.truncate(result_bigint.toConst(), int_info.signedness, int_info.bits);2597 result_bigint.truncate(result_bigint.toConst(), int_info.signedness, int_info.bits);
2552 }2598 }
25532599
...@@ -2594,10 +2640,11 @@ pub fn shlWithOverflowScalar(...@@ -2594,10 +2640,11 @@ pub fn shlWithOverflowScalar(
2594 allocator: Allocator,2640 allocator: Allocator,
2595 pt: Zcu.PerThread,2641 pt: Zcu.PerThread,
2596) !OverflowArithmeticResult {2642) !OverflowArithmeticResult {
2597 const info = ty.intInfo(pt.zcu);2643 const zcu = pt.zcu;
2644 const info = ty.intInfo(zcu);
2598 var lhs_space: Value.BigIntSpace = undefined;2645 var lhs_space: Value.BigIntSpace = undefined;
2599 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2646 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2600 const shift: usize = @intCast(rhs.toUnsignedInt(pt));2647 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
2601 const limbs = try allocator.alloc(2648 const limbs = try allocator.alloc(
2602 std.math.big.Limb,2649 std.math.big.Limb,
2603 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,2650 lhs_bigint.limbs.len + (shift / (@sizeOf(std.math.big.Limb) * 8)) + 1,
...@@ -2650,11 +2697,12 @@ pub fn shlSatScalar(...@@ -2650,11 +2697,12 @@ pub fn shlSatScalar(
2650) !Value {2697) !Value {
2651 // TODO is this a performance issue? maybe we should try the operation without2698 // TODO is this a performance issue? maybe we should try the operation without
2652 // resorting to BigInt first.2699 // resorting to BigInt first.
2653 const info = ty.intInfo(pt.zcu);2700 const zcu = pt.zcu;
2701 const info = ty.intInfo(zcu);
26542702
2655 var lhs_space: Value.BigIntSpace = undefined;2703 var lhs_space: Value.BigIntSpace = undefined;
2656 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2704 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2657 const shift: usize = @intCast(rhs.toUnsignedInt(pt));2705 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
2658 const limbs = try arena.alloc(2706 const limbs = try arena.alloc(
2659 std.math.big.Limb,2707 std.math.big.Limb,
2660 std.math.big.int.calcTwosCompLimbCount(info.bits) + 1,2708 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...@@ -2724,9 +2772,10 @@ pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerTh
2724pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {2772pub fn shrScalar(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, pt: Zcu.PerThread) !Value {
2725 // TODO is this a performance issue? maybe we should try the operation without2773 // TODO is this a performance issue? maybe we should try the operation without
2726 // resorting to BigInt first.2774 // resorting to BigInt first.
2775 const zcu = pt.zcu;
2727 var lhs_space: Value.BigIntSpace = undefined;2776 var lhs_space: Value.BigIntSpace = undefined;
2728 const lhs_bigint = lhs.toBigInt(&lhs_space, pt);2777 const lhs_bigint = lhs.toBigInt(&lhs_space, zcu);
2729 const shift: usize = @intCast(rhs.toUnsignedInt(pt));2778 const shift: usize = @intCast(rhs.toUnsignedInt(zcu));
27302779
2731 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));2780 const result_limbs = lhs_bigint.limbs.len -| (shift / (@sizeOf(std.math.big.Limb) * 8));
2732 if (result_limbs == 0) {2781 if (result_limbs == 0) {
...@@ -2758,10 +2807,10 @@ pub fn floatNeg(...@@ -2758,10 +2807,10 @@ pub fn floatNeg(
2758 arena: Allocator,2807 arena: Allocator,
2759 pt: Zcu.PerThread,2808 pt: Zcu.PerThread,
2760) !Value {2809) !Value {
2761 const mod = pt.zcu;2810 const zcu = pt.zcu;
2762 if (float_type.zigTypeTag(mod) == .Vector) {2811 if (float_type.zigTypeTag(zcu) == .Vector) {
2763 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));2812 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2764 const scalar_ty = float_type.scalarType(mod);2813 const scalar_ty = float_type.scalarType(zcu);
2765 for (result_data, 0..) |*scalar, i| {2814 for (result_data, 0..) |*scalar, i| {
2766 const elem_val = try val.elemValue(pt, i);2815 const elem_val = try val.elemValue(pt, i);
2767 scalar.* = (try floatNegScalar(elem_val, scalar_ty, pt)).toIntern();2816 scalar.* = (try floatNegScalar(elem_val, scalar_ty, pt)).toIntern();
...@@ -2775,13 +2824,14 @@ pub fn floatNeg(...@@ -2775,13 +2824,14 @@ pub fn floatNeg(
2775}2824}
27762825
2777pub fn floatNegScalar(val: Value, float_type: Type, pt: Zcu.PerThread) !Value {2826pub 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();
2779 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {2829 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2780 16 => .{ .f16 = -val.toFloat(f16, pt) },2830 16 => .{ .f16 = -val.toFloat(f16, zcu) },
2781 32 => .{ .f32 = -val.toFloat(f32, pt) },2831 32 => .{ .f32 = -val.toFloat(f32, zcu) },
2782 64 => .{ .f64 = -val.toFloat(f64, pt) },2832 64 => .{ .f64 = -val.toFloat(f64, zcu) },
2783 80 => .{ .f80 = -val.toFloat(f80, pt) },2833 80 => .{ .f80 = -val.toFloat(f80, zcu) },
2784 128 => .{ .f128 = -val.toFloat(f128, pt) },2834 128 => .{ .f128 = -val.toFloat(f128, zcu) },
2785 else => unreachable,2835 else => unreachable,
2786 };2836 };
2787 return Value.fromInterned(try pt.intern(.{ .float = .{2837 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -2797,10 +2847,10 @@ pub fn floatAdd(...@@ -2797,10 +2847,10 @@ pub fn floatAdd(
2797 arena: Allocator,2847 arena: Allocator,
2798 pt: Zcu.PerThread,2848 pt: Zcu.PerThread,
2799) !Value {2849) !Value {
2800 const mod = pt.zcu;2850 const zcu = pt.zcu;
2801 if (float_type.zigTypeTag(mod) == .Vector) {2851 if (float_type.zigTypeTag(zcu) == .Vector) {
2802 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));2852 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2803 const scalar_ty = float_type.scalarType(mod);2853 const scalar_ty = float_type.scalarType(zcu);
2804 for (result_data, 0..) |*scalar, i| {2854 for (result_data, 0..) |*scalar, i| {
2805 const lhs_elem = try lhs.elemValue(pt, i);2855 const lhs_elem = try lhs.elemValue(pt, i);
2806 const rhs_elem = try rhs.elemValue(pt, i);2856 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -2820,14 +2870,14 @@ pub fn floatAddScalar(...@@ -2820,14 +2870,14 @@ pub fn floatAddScalar(
2820 float_type: Type,2870 float_type: Type,
2821 pt: Zcu.PerThread,2871 pt: Zcu.PerThread,
2822) !Value {2872) !Value {
2823 const mod = pt.zcu;2873 const zcu = pt.zcu;
2824 const target = mod.getTarget();2874 const target = zcu.getTarget();
2825 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {2875 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2826 16 => .{ .f16 = lhs.toFloat(f16, pt) + rhs.toFloat(f16, pt) },2876 16 => .{ .f16 = lhs.toFloat(f16, zcu) + rhs.toFloat(f16, zcu) },
2827 32 => .{ .f32 = lhs.toFloat(f32, pt) + rhs.toFloat(f32, pt) },2877 32 => .{ .f32 = lhs.toFloat(f32, zcu) + rhs.toFloat(f32, zcu) },
2828 64 => .{ .f64 = lhs.toFloat(f64, pt) + rhs.toFloat(f64, pt) },2878 64 => .{ .f64 = lhs.toFloat(f64, zcu) + rhs.toFloat(f64, zcu) },
2829 80 => .{ .f80 = lhs.toFloat(f80, pt) + rhs.toFloat(f80, pt) },2879 80 => .{ .f80 = lhs.toFloat(f80, zcu) + rhs.toFloat(f80, zcu) },
2830 128 => .{ .f128 = lhs.toFloat(f128, pt) + rhs.toFloat(f128, pt) },2880 128 => .{ .f128 = lhs.toFloat(f128, zcu) + rhs.toFloat(f128, zcu) },
2831 else => unreachable,2881 else => unreachable,
2832 };2882 };
2833 return Value.fromInterned(try pt.intern(.{ .float = .{2883 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -2843,10 +2893,10 @@ pub fn floatSub(...@@ -2843,10 +2893,10 @@ pub fn floatSub(
2843 arena: Allocator,2893 arena: Allocator,
2844 pt: Zcu.PerThread,2894 pt: Zcu.PerThread,
2845) !Value {2895) !Value {
2846 const mod = pt.zcu;2896 const zcu = pt.zcu;
2847 if (float_type.zigTypeTag(mod) == .Vector) {2897 if (float_type.zigTypeTag(zcu) == .Vector) {
2848 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));2898 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
2849 const scalar_ty = float_type.scalarType(mod);2899 const scalar_ty = float_type.scalarType(zcu);
2850 for (result_data, 0..) |*scalar, i| {2900 for (result_data, 0..) |*scalar, i| {
2851 const lhs_elem = try lhs.elemValue(pt, i);2901 const lhs_elem = try lhs.elemValue(pt, i);
2852 const rhs_elem = try rhs.elemValue(pt, i);2902 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -2866,14 +2916,14 @@ pub fn floatSubScalar(...@@ -2866,14 +2916,14 @@ pub fn floatSubScalar(
2866 float_type: Type,2916 float_type: Type,
2867 pt: Zcu.PerThread,2917 pt: Zcu.PerThread,
2868) !Value {2918) !Value {
2869 const mod = pt.zcu;2919 const zcu = pt.zcu;
2870 const target = mod.getTarget();2920 const target = zcu.getTarget();
2871 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {2921 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2872 16 => .{ .f16 = lhs.toFloat(f16, pt) - rhs.toFloat(f16, pt) },2922 16 => .{ .f16 = lhs.toFloat(f16, zcu) - rhs.toFloat(f16, zcu) },
2873 32 => .{ .f32 = lhs.toFloat(f32, pt) - rhs.toFloat(f32, pt) },2923 32 => .{ .f32 = lhs.toFloat(f32, zcu) - rhs.toFloat(f32, zcu) },
2874 64 => .{ .f64 = lhs.toFloat(f64, pt) - rhs.toFloat(f64, pt) },2924 64 => .{ .f64 = lhs.toFloat(f64, zcu) - rhs.toFloat(f64, zcu) },
2875 80 => .{ .f80 = lhs.toFloat(f80, pt) - rhs.toFloat(f80, pt) },2925 80 => .{ .f80 = lhs.toFloat(f80, zcu) - rhs.toFloat(f80, zcu) },
2876 128 => .{ .f128 = lhs.toFloat(f128, pt) - rhs.toFloat(f128, pt) },2926 128 => .{ .f128 = lhs.toFloat(f128, zcu) - rhs.toFloat(f128, zcu) },
2877 else => unreachable,2927 else => unreachable,
2878 };2928 };
2879 return Value.fromInterned(try pt.intern(.{ .float = .{2929 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -2911,13 +2961,14 @@ pub fn floatDivScalar(...@@ -2911,13 +2961,14 @@ pub fn floatDivScalar(
2911 float_type: Type,2961 float_type: Type,
2912 pt: Zcu.PerThread,2962 pt: Zcu.PerThread,
2913) !Value {2963) !Value {
2914 const target = pt.zcu.getTarget();2964 const zcu = pt.zcu;
2965 const target = zcu.getTarget();
2915 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {2966 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2916 16 => .{ .f16 = lhs.toFloat(f16, pt) / rhs.toFloat(f16, pt) },2967 16 => .{ .f16 = lhs.toFloat(f16, zcu) / rhs.toFloat(f16, zcu) },
2917 32 => .{ .f32 = lhs.toFloat(f32, pt) / rhs.toFloat(f32, pt) },2968 32 => .{ .f32 = lhs.toFloat(f32, zcu) / rhs.toFloat(f32, zcu) },
2918 64 => .{ .f64 = lhs.toFloat(f64, pt) / rhs.toFloat(f64, pt) },2969 64 => .{ .f64 = lhs.toFloat(f64, zcu) / rhs.toFloat(f64, zcu) },
2919 80 => .{ .f80 = lhs.toFloat(f80, pt) / rhs.toFloat(f80, pt) },2970 80 => .{ .f80 = lhs.toFloat(f80, zcu) / rhs.toFloat(f80, zcu) },
2920 128 => .{ .f128 = lhs.toFloat(f128, pt) / rhs.toFloat(f128, pt) },2971 128 => .{ .f128 = lhs.toFloat(f128, zcu) / rhs.toFloat(f128, zcu) },
2921 else => unreachable,2972 else => unreachable,
2922 };2973 };
2923 return Value.fromInterned(try pt.intern(.{ .float = .{2974 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -2955,13 +3006,14 @@ pub fn floatDivFloorScalar(...@@ -2955,13 +3006,14 @@ pub fn floatDivFloorScalar(
2955 float_type: Type,3006 float_type: Type,
2956 pt: Zcu.PerThread,3007 pt: Zcu.PerThread,
2957) !Value {3008) !Value {
2958 const target = pt.zcu.getTarget();3009 const zcu = pt.zcu;
3010 const target = zcu.getTarget();
2959 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3011 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
2960 16 => .{ .f16 = @divFloor(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },3012 16 => .{ .f16 = @divFloor(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
2961 32 => .{ .f32 = @divFloor(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },3013 32 => .{ .f32 = @divFloor(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
2962 64 => .{ .f64 = @divFloor(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },3014 64 => .{ .f64 = @divFloor(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
2963 80 => .{ .f80 = @divFloor(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },3015 80 => .{ .f80 = @divFloor(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
2964 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },3016 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
2965 else => unreachable,3017 else => unreachable,
2966 };3018 };
2967 return Value.fromInterned(try pt.intern(.{ .float = .{3019 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -2999,13 +3051,14 @@ pub fn floatDivTruncScalar(...@@ -2999,13 +3051,14 @@ pub fn floatDivTruncScalar(
2999 float_type: Type,3051 float_type: Type,
3000 pt: Zcu.PerThread,3052 pt: Zcu.PerThread,
3001) !Value {3053) !Value {
3002 const target = pt.zcu.getTarget();3054 const zcu = pt.zcu;
3055 const target = zcu.getTarget();
3003 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3056 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3004 16 => .{ .f16 = @divTrunc(lhs.toFloat(f16, pt), rhs.toFloat(f16, pt)) },3057 16 => .{ .f16 = @divTrunc(lhs.toFloat(f16, zcu), rhs.toFloat(f16, zcu)) },
3005 32 => .{ .f32 = @divTrunc(lhs.toFloat(f32, pt), rhs.toFloat(f32, pt)) },3058 32 => .{ .f32 = @divTrunc(lhs.toFloat(f32, zcu), rhs.toFloat(f32, zcu)) },
3006 64 => .{ .f64 = @divTrunc(lhs.toFloat(f64, pt), rhs.toFloat(f64, pt)) },3059 64 => .{ .f64 = @divTrunc(lhs.toFloat(f64, zcu), rhs.toFloat(f64, zcu)) },
3007 80 => .{ .f80 = @divTrunc(lhs.toFloat(f80, pt), rhs.toFloat(f80, pt)) },3060 80 => .{ .f80 = @divTrunc(lhs.toFloat(f80, zcu), rhs.toFloat(f80, zcu)) },
3008 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, pt), rhs.toFloat(f128, pt)) },3061 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, zcu), rhs.toFloat(f128, zcu)) },
3009 else => unreachable,3062 else => unreachable,
3010 };3063 };
3011 return Value.fromInterned(try pt.intern(.{ .float = .{3064 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3021,10 +3074,10 @@ pub fn floatMul(...@@ -3021,10 +3074,10 @@ pub fn floatMul(
3021 arena: Allocator,3074 arena: Allocator,
3022 pt: Zcu.PerThread,3075 pt: Zcu.PerThread,
3023) !Value {3076) !Value {
3024 const mod = pt.zcu;3077 const zcu = pt.zcu;
3025 if (float_type.zigTypeTag(mod) == .Vector) {3078 if (float_type.zigTypeTag(zcu) == .Vector) {
3026 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3079 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3027 const scalar_ty = float_type.scalarType(mod);3080 const scalar_ty = float_type.scalarType(zcu);
3028 for (result_data, 0..) |*scalar, i| {3081 for (result_data, 0..) |*scalar, i| {
3029 const lhs_elem = try lhs.elemValue(pt, i);3082 const lhs_elem = try lhs.elemValue(pt, i);
3030 const rhs_elem = try rhs.elemValue(pt, i);3083 const rhs_elem = try rhs.elemValue(pt, i);
...@@ -3044,14 +3097,14 @@ pub fn floatMulScalar(...@@ -3044,14 +3097,14 @@ pub fn floatMulScalar(
3044 float_type: Type,3097 float_type: Type,
3045 pt: Zcu.PerThread,3098 pt: Zcu.PerThread,
3046) !Value {3099) !Value {
3047 const mod = pt.zcu;3100 const zcu = pt.zcu;
3048 const target = mod.getTarget();3101 const target = zcu.getTarget();
3049 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3102 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3050 16 => .{ .f16 = lhs.toFloat(f16, pt) * rhs.toFloat(f16, pt) },3103 16 => .{ .f16 = lhs.toFloat(f16, zcu) * rhs.toFloat(f16, zcu) },
3051 32 => .{ .f32 = lhs.toFloat(f32, pt) * rhs.toFloat(f32, pt) },3104 32 => .{ .f32 = lhs.toFloat(f32, zcu) * rhs.toFloat(f32, zcu) },
3052 64 => .{ .f64 = lhs.toFloat(f64, pt) * rhs.toFloat(f64, pt) },3105 64 => .{ .f64 = lhs.toFloat(f64, zcu) * rhs.toFloat(f64, zcu) },
3053 80 => .{ .f80 = lhs.toFloat(f80, pt) * rhs.toFloat(f80, pt) },3106 80 => .{ .f80 = lhs.toFloat(f80, zcu) * rhs.toFloat(f80, zcu) },
3054 128 => .{ .f128 = lhs.toFloat(f128, pt) * rhs.toFloat(f128, pt) },3107 128 => .{ .f128 = lhs.toFloat(f128, zcu) * rhs.toFloat(f128, zcu) },
3055 else => unreachable,3108 else => unreachable,
3056 };3109 };
3057 return Value.fromInterned(try pt.intern(.{ .float = .{3110 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3077,14 +3130,14 @@ pub fn sqrt(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !...@@ -3077,14 +3130,14 @@ pub fn sqrt(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
3077}3130}
30783131
3079pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3132pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3080 const mod = pt.zcu;3133 const zcu = pt.zcu;
3081 const target = mod.getTarget();3134 const target = zcu.getTarget();
3082 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3135 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3083 16 => .{ .f16 = @sqrt(val.toFloat(f16, pt)) },3136 16 => .{ .f16 = @sqrt(val.toFloat(f16, zcu)) },
3084 32 => .{ .f32 = @sqrt(val.toFloat(f32, pt)) },3137 32 => .{ .f32 = @sqrt(val.toFloat(f32, zcu)) },
3085 64 => .{ .f64 = @sqrt(val.toFloat(f64, pt)) },3138 64 => .{ .f64 = @sqrt(val.toFloat(f64, zcu)) },
3086 80 => .{ .f80 = @sqrt(val.toFloat(f80, pt)) },3139 80 => .{ .f80 = @sqrt(val.toFloat(f80, zcu)) },
3087 128 => .{ .f128 = @sqrt(val.toFloat(f128, pt)) },3140 128 => .{ .f128 = @sqrt(val.toFloat(f128, zcu)) },
3088 else => unreachable,3141 else => unreachable,
3089 };3142 };
3090 return Value.fromInterned(try pt.intern(.{ .float = .{3143 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3094,10 +3147,10 @@ pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err...@@ -3094,10 +3147,10 @@ pub fn sqrtScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
3094}3147}
30953148
3096pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3149pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3097 const mod = pt.zcu;3150 const zcu = pt.zcu;
3098 if (float_type.zigTypeTag(mod) == .Vector) {3151 if (float_type.zigTypeTag(zcu) == .Vector) {
3099 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3152 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3100 const scalar_ty = float_type.scalarType(mod);3153 const scalar_ty = float_type.scalarType(zcu);
3101 for (result_data, 0..) |*scalar, i| {3154 for (result_data, 0..) |*scalar, i| {
3102 const elem_val = try val.elemValue(pt, i);3155 const elem_val = try val.elemValue(pt, i);
3103 scalar.* = (try sinScalar(elem_val, scalar_ty, pt)).toIntern();3156 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...@@ -3111,14 +3164,14 @@ pub fn sin(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
3111}3164}
31123165
3113pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3166pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3114 const mod = pt.zcu;3167 const zcu = pt.zcu;
3115 const target = mod.getTarget();3168 const target = zcu.getTarget();
3116 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3169 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3117 16 => .{ .f16 = @sin(val.toFloat(f16, pt)) },3170 16 => .{ .f16 = @sin(val.toFloat(f16, zcu)) },
3118 32 => .{ .f32 = @sin(val.toFloat(f32, pt)) },3171 32 => .{ .f32 = @sin(val.toFloat(f32, zcu)) },
3119 64 => .{ .f64 = @sin(val.toFloat(f64, pt)) },3172 64 => .{ .f64 = @sin(val.toFloat(f64, zcu)) },
3120 80 => .{ .f80 = @sin(val.toFloat(f80, pt)) },3173 80 => .{ .f80 = @sin(val.toFloat(f80, zcu)) },
3121 128 => .{ .f128 = @sin(val.toFloat(f128, pt)) },3174 128 => .{ .f128 = @sin(val.toFloat(f128, zcu)) },
3122 else => unreachable,3175 else => unreachable,
3123 };3176 };
3124 return Value.fromInterned(try pt.intern(.{ .float = .{3177 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3128,10 +3181,10 @@ pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro...@@ -3128,10 +3181,10 @@ pub fn sinScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
3128}3181}
31293182
3130pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3183pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3131 const mod = pt.zcu;3184 const zcu = pt.zcu;
3132 if (float_type.zigTypeTag(mod) == .Vector) {3185 if (float_type.zigTypeTag(zcu) == .Vector) {
3133 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3186 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3134 const scalar_ty = float_type.scalarType(mod);3187 const scalar_ty = float_type.scalarType(zcu);
3135 for (result_data, 0..) |*scalar, i| {3188 for (result_data, 0..) |*scalar, i| {
3136 const elem_val = try val.elemValue(pt, i);3189 const elem_val = try val.elemValue(pt, i);
3137 scalar.* = (try cosScalar(elem_val, scalar_ty, pt)).toIntern();3190 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...@@ -3145,14 +3198,14 @@ pub fn cos(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
3145}3198}
31463199
3147pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3200pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3148 const mod = pt.zcu;3201 const zcu = pt.zcu;
3149 const target = mod.getTarget();3202 const target = zcu.getTarget();
3150 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3203 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3151 16 => .{ .f16 = @cos(val.toFloat(f16, pt)) },3204 16 => .{ .f16 = @cos(val.toFloat(f16, zcu)) },
3152 32 => .{ .f32 = @cos(val.toFloat(f32, pt)) },3205 32 => .{ .f32 = @cos(val.toFloat(f32, zcu)) },
3153 64 => .{ .f64 = @cos(val.toFloat(f64, pt)) },3206 64 => .{ .f64 = @cos(val.toFloat(f64, zcu)) },
3154 80 => .{ .f80 = @cos(val.toFloat(f80, pt)) },3207 80 => .{ .f80 = @cos(val.toFloat(f80, zcu)) },
3155 128 => .{ .f128 = @cos(val.toFloat(f128, pt)) },3208 128 => .{ .f128 = @cos(val.toFloat(f128, zcu)) },
3156 else => unreachable,3209 else => unreachable,
3157 };3210 };
3158 return Value.fromInterned(try pt.intern(.{ .float = .{3211 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3162,10 +3215,10 @@ pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro...@@ -3162,10 +3215,10 @@ pub fn cosScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
3162}3215}
31633216
3164pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3217pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3165 const mod = pt.zcu;3218 const zcu = pt.zcu;
3166 if (float_type.zigTypeTag(mod) == .Vector) {3219 if (float_type.zigTypeTag(zcu) == .Vector) {
3167 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3220 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3168 const scalar_ty = float_type.scalarType(mod);3221 const scalar_ty = float_type.scalarType(zcu);
3169 for (result_data, 0..) |*scalar, i| {3222 for (result_data, 0..) |*scalar, i| {
3170 const elem_val = try val.elemValue(pt, i);3223 const elem_val = try val.elemValue(pt, i);
3171 scalar.* = (try tanScalar(elem_val, scalar_ty, pt)).toIntern();3224 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...@@ -3179,14 +3232,14 @@ pub fn tan(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
3179}3232}
31803233
3181pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3234pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3182 const mod = pt.zcu;3235 const zcu = pt.zcu;
3183 const target = mod.getTarget();3236 const target = zcu.getTarget();
3184 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3237 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3185 16 => .{ .f16 = @tan(val.toFloat(f16, pt)) },3238 16 => .{ .f16 = @tan(val.toFloat(f16, zcu)) },
3186 32 => .{ .f32 = @tan(val.toFloat(f32, pt)) },3239 32 => .{ .f32 = @tan(val.toFloat(f32, zcu)) },
3187 64 => .{ .f64 = @tan(val.toFloat(f64, pt)) },3240 64 => .{ .f64 = @tan(val.toFloat(f64, zcu)) },
3188 80 => .{ .f80 = @tan(val.toFloat(f80, pt)) },3241 80 => .{ .f80 = @tan(val.toFloat(f80, zcu)) },
3189 128 => .{ .f128 = @tan(val.toFloat(f128, pt)) },3242 128 => .{ .f128 = @tan(val.toFloat(f128, zcu)) },
3190 else => unreachable,3243 else => unreachable,
3191 };3244 };
3192 return Value.fromInterned(try pt.intern(.{ .float = .{3245 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3196,10 +3249,10 @@ pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro...@@ -3196,10 +3249,10 @@ pub fn tanScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
3196}3249}
31973250
3198pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3251pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3199 const mod = pt.zcu;3252 const zcu = pt.zcu;
3200 if (float_type.zigTypeTag(mod) == .Vector) {3253 if (float_type.zigTypeTag(zcu) == .Vector) {
3201 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3254 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3202 const scalar_ty = float_type.scalarType(mod);3255 const scalar_ty = float_type.scalarType(zcu);
3203 for (result_data, 0..) |*scalar, i| {3256 for (result_data, 0..) |*scalar, i| {
3204 const elem_val = try val.elemValue(pt, i);3257 const elem_val = try val.elemValue(pt, i);
3205 scalar.* = (try expScalar(elem_val, scalar_ty, pt)).toIntern();3258 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...@@ -3213,14 +3266,14 @@ pub fn exp(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
3213}3266}
32143267
3215pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3268pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3216 const mod = pt.zcu;3269 const zcu = pt.zcu;
3217 const target = mod.getTarget();3270 const target = zcu.getTarget();
3218 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3271 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3219 16 => .{ .f16 = @exp(val.toFloat(f16, pt)) },3272 16 => .{ .f16 = @exp(val.toFloat(f16, zcu)) },
3220 32 => .{ .f32 = @exp(val.toFloat(f32, pt)) },3273 32 => .{ .f32 = @exp(val.toFloat(f32, zcu)) },
3221 64 => .{ .f64 = @exp(val.toFloat(f64, pt)) },3274 64 => .{ .f64 = @exp(val.toFloat(f64, zcu)) },
3222 80 => .{ .f80 = @exp(val.toFloat(f80, pt)) },3275 80 => .{ .f80 = @exp(val.toFloat(f80, zcu)) },
3223 128 => .{ .f128 = @exp(val.toFloat(f128, pt)) },3276 128 => .{ .f128 = @exp(val.toFloat(f128, zcu)) },
3224 else => unreachable,3277 else => unreachable,
3225 };3278 };
3226 return Value.fromInterned(try pt.intern(.{ .float = .{3279 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3230,10 +3283,10 @@ pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro...@@ -3230,10 +3283,10 @@ pub fn expScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
3230}3283}
32313284
3232pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3285pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3233 const mod = pt.zcu;3286 const zcu = pt.zcu;
3234 if (float_type.zigTypeTag(mod) == .Vector) {3287 if (float_type.zigTypeTag(zcu) == .Vector) {
3235 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3288 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3236 const scalar_ty = float_type.scalarType(mod);3289 const scalar_ty = float_type.scalarType(zcu);
3237 for (result_data, 0..) |*scalar, i| {3290 for (result_data, 0..) |*scalar, i| {
3238 const elem_val = try val.elemValue(pt, i);3291 const elem_val = try val.elemValue(pt, i);
3239 scalar.* = (try exp2Scalar(elem_val, scalar_ty, pt)).toIntern();3292 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) !...@@ -3247,14 +3300,14 @@ pub fn exp2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
3247}3300}
32483301
3249pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3302pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3250 const mod = pt.zcu;3303 const zcu = pt.zcu;
3251 const target = mod.getTarget();3304 const target = zcu.getTarget();
3252 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3305 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3253 16 => .{ .f16 = @exp2(val.toFloat(f16, pt)) },3306 16 => .{ .f16 = @exp2(val.toFloat(f16, zcu)) },
3254 32 => .{ .f32 = @exp2(val.toFloat(f32, pt)) },3307 32 => .{ .f32 = @exp2(val.toFloat(f32, zcu)) },
3255 64 => .{ .f64 = @exp2(val.toFloat(f64, pt)) },3308 64 => .{ .f64 = @exp2(val.toFloat(f64, zcu)) },
3256 80 => .{ .f80 = @exp2(val.toFloat(f80, pt)) },3309 80 => .{ .f80 = @exp2(val.toFloat(f80, zcu)) },
3257 128 => .{ .f128 = @exp2(val.toFloat(f128, pt)) },3310 128 => .{ .f128 = @exp2(val.toFloat(f128, zcu)) },
3258 else => unreachable,3311 else => unreachable,
3259 };3312 };
3260 return Value.fromInterned(try pt.intern(.{ .float = .{3313 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3264,10 +3317,10 @@ pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err...@@ -3264,10 +3317,10 @@ pub fn exp2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
3264}3317}
32653318
3266pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3319pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3267 const mod = pt.zcu;3320 const zcu = pt.zcu;
3268 if (float_type.zigTypeTag(mod) == .Vector) {3321 if (float_type.zigTypeTag(zcu) == .Vector) {
3269 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3322 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3270 const scalar_ty = float_type.scalarType(mod);3323 const scalar_ty = float_type.scalarType(zcu);
3271 for (result_data, 0..) |*scalar, i| {3324 for (result_data, 0..) |*scalar, i| {
3272 const elem_val = try val.elemValue(pt, i);3325 const elem_val = try val.elemValue(pt, i);
3273 scalar.* = (try logScalar(elem_val, scalar_ty, pt)).toIntern();3326 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...@@ -3281,14 +3334,14 @@ pub fn log(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !V
3281}3334}
32823335
3283pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3336pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3284 const mod = pt.zcu;3337 const zcu = pt.zcu;
3285 const target = mod.getTarget();3338 const target = zcu.getTarget();
3286 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3339 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3287 16 => .{ .f16 = @log(val.toFloat(f16, pt)) },3340 16 => .{ .f16 = @log(val.toFloat(f16, zcu)) },
3288 32 => .{ .f32 = @log(val.toFloat(f32, pt)) },3341 32 => .{ .f32 = @log(val.toFloat(f32, zcu)) },
3289 64 => .{ .f64 = @log(val.toFloat(f64, pt)) },3342 64 => .{ .f64 = @log(val.toFloat(f64, zcu)) },
3290 80 => .{ .f80 = @log(val.toFloat(f80, pt)) },3343 80 => .{ .f80 = @log(val.toFloat(f80, zcu)) },
3291 128 => .{ .f128 = @log(val.toFloat(f128, pt)) },3344 128 => .{ .f128 = @log(val.toFloat(f128, zcu)) },
3292 else => unreachable,3345 else => unreachable,
3293 };3346 };
3294 return Value.fromInterned(try pt.intern(.{ .float = .{3347 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3298,10 +3351,10 @@ pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro...@@ -3298,10 +3351,10 @@ pub fn logScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Erro
3298}3351}
32993352
3300pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3353pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3301 const mod = pt.zcu;3354 const zcu = pt.zcu;
3302 if (float_type.zigTypeTag(mod) == .Vector) {3355 if (float_type.zigTypeTag(zcu) == .Vector) {
3303 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3356 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3304 const scalar_ty = float_type.scalarType(mod);3357 const scalar_ty = float_type.scalarType(zcu);
3305 for (result_data, 0..) |*scalar, i| {3358 for (result_data, 0..) |*scalar, i| {
3306 const elem_val = try val.elemValue(pt, i);3359 const elem_val = try val.elemValue(pt, i);
3307 scalar.* = (try log2Scalar(elem_val, scalar_ty, pt)).toIntern();3360 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) !...@@ -3315,14 +3368,14 @@ pub fn log2(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
3315}3368}
33163369
3317pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3370pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3318 const mod = pt.zcu;3371 const zcu = pt.zcu;
3319 const target = mod.getTarget();3372 const target = zcu.getTarget();
3320 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3373 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3321 16 => .{ .f16 = @log2(val.toFloat(f16, pt)) },3374 16 => .{ .f16 = @log2(val.toFloat(f16, zcu)) },
3322 32 => .{ .f32 = @log2(val.toFloat(f32, pt)) },3375 32 => .{ .f32 = @log2(val.toFloat(f32, zcu)) },
3323 64 => .{ .f64 = @log2(val.toFloat(f64, pt)) },3376 64 => .{ .f64 = @log2(val.toFloat(f64, zcu)) },
3324 80 => .{ .f80 = @log2(val.toFloat(f80, pt)) },3377 80 => .{ .f80 = @log2(val.toFloat(f80, zcu)) },
3325 128 => .{ .f128 = @log2(val.toFloat(f128, pt)) },3378 128 => .{ .f128 = @log2(val.toFloat(f128, zcu)) },
3326 else => unreachable,3379 else => unreachable,
3327 };3380 };
3328 return Value.fromInterned(try pt.intern(.{ .float = .{3381 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3332,10 +3385,10 @@ pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err...@@ -3332,10 +3385,10 @@ pub fn log2Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
3332}3385}
33333386
3334pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3387pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3335 const mod = pt.zcu;3388 const zcu = pt.zcu;
3336 if (float_type.zigTypeTag(mod) == .Vector) {3389 if (float_type.zigTypeTag(zcu) == .Vector) {
3337 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3390 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3338 const scalar_ty = float_type.scalarType(mod);3391 const scalar_ty = float_type.scalarType(zcu);
3339 for (result_data, 0..) |*scalar, i| {3392 for (result_data, 0..) |*scalar, i| {
3340 const elem_val = try val.elemValue(pt, i);3393 const elem_val = try val.elemValue(pt, i);
3341 scalar.* = (try log10Scalar(elem_val, scalar_ty, pt)).toIntern();3394 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)...@@ -3349,14 +3402,14 @@ pub fn log10(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
3349}3402}
33503403
3351pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3404pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3352 const mod = pt.zcu;3405 const zcu = pt.zcu;
3353 const target = mod.getTarget();3406 const target = zcu.getTarget();
3354 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3407 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3355 16 => .{ .f16 = @log10(val.toFloat(f16, pt)) },3408 16 => .{ .f16 = @log10(val.toFloat(f16, zcu)) },
3356 32 => .{ .f32 = @log10(val.toFloat(f32, pt)) },3409 32 => .{ .f32 = @log10(val.toFloat(f32, zcu)) },
3357 64 => .{ .f64 = @log10(val.toFloat(f64, pt)) },3410 64 => .{ .f64 = @log10(val.toFloat(f64, zcu)) },
3358 80 => .{ .f80 = @log10(val.toFloat(f80, pt)) },3411 80 => .{ .f80 = @log10(val.toFloat(f80, zcu)) },
3359 128 => .{ .f128 = @log10(val.toFloat(f128, pt)) },3412 128 => .{ .f128 = @log10(val.toFloat(f128, zcu)) },
3360 else => unreachable,3413 else => unreachable,
3361 };3414 };
3362 return Value.fromInterned(try pt.intern(.{ .float = .{3415 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3366,10 +3419,10 @@ pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er...@@ -3366,10 +3419,10 @@ pub fn log10Scalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
3366}3419}
33673420
3368pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3421pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3369 const mod = pt.zcu;3422 const zcu = pt.zcu;
3370 if (ty.zigTypeTag(mod) == .Vector) {3423 if (ty.zigTypeTag(zcu) == .Vector) {
3371 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));3424 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(zcu));
3372 const scalar_ty = ty.scalarType(mod);3425 const scalar_ty = ty.scalarType(zcu);
3373 for (result_data, 0..) |*scalar, i| {3426 for (result_data, 0..) |*scalar, i| {
3374 const elem_val = try val.elemValue(pt, i);3427 const elem_val = try val.elemValue(pt, i);
3375 scalar.* = (try absScalar(elem_val, scalar_ty, pt, arena)).toIntern();3428 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 {...@@ -3383,30 +3436,30 @@ pub fn abs(val: Value, ty: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3383}3436}
33843437
3385pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allocator.Error!Value {3438pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allocator.Error!Value {
3386 const mod = pt.zcu;3439 const zcu = pt.zcu;
3387 switch (ty.zigTypeTag(mod)) {3440 switch (ty.zigTypeTag(zcu)) {
3388 .Int => {3441 .Int => {
3389 var buffer: Value.BigIntSpace = undefined;3442 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);
3391 operand_bigint.abs();3444 operand_bigint.abs();
33923445
3393 return pt.intValue_big(try ty.toUnsigned(pt), operand_bigint.toConst());3446 return pt.intValue_big(try ty.toUnsigned(pt), operand_bigint.toConst());
3394 },3447 },
3395 .ComptimeInt => {3448 .ComptimeInt => {
3396 var buffer: Value.BigIntSpace = undefined;3449 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);
3398 operand_bigint.abs();3451 operand_bigint.abs();
33993452
3400 return pt.intValue_big(ty, operand_bigint.toConst());3453 return pt.intValue_big(ty, operand_bigint.toConst());
3401 },3454 },
3402 .ComptimeFloat, .Float => {3455 .ComptimeFloat, .Float => {
3403 const target = mod.getTarget();3456 const target = zcu.getTarget();
3404 const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(target)) {3457 const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(target)) {
3405 16 => .{ .f16 = @abs(val.toFloat(f16, pt)) },3458 16 => .{ .f16 = @abs(val.toFloat(f16, zcu)) },
3406 32 => .{ .f32 = @abs(val.toFloat(f32, pt)) },3459 32 => .{ .f32 = @abs(val.toFloat(f32, zcu)) },
3407 64 => .{ .f64 = @abs(val.toFloat(f64, pt)) },3460 64 => .{ .f64 = @abs(val.toFloat(f64, zcu)) },
3408 80 => .{ .f80 = @abs(val.toFloat(f80, pt)) },3461 80 => .{ .f80 = @abs(val.toFloat(f80, zcu)) },
3409 128 => .{ .f128 = @abs(val.toFloat(f128, pt)) },3462 128 => .{ .f128 = @abs(val.toFloat(f128, zcu)) },
3410 else => unreachable,3463 else => unreachable,
3411 };3464 };
3412 return Value.fromInterned(try pt.intern(.{ .float = .{3465 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3419,10 +3472,10 @@ pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allo...@@ -3419,10 +3472,10 @@ pub fn absScalar(val: Value, ty: Type, pt: Zcu.PerThread, arena: Allocator) Allo
3419}3472}
34203473
3421pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3474pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3422 const mod = pt.zcu;3475 const zcu = pt.zcu;
3423 if (float_type.zigTypeTag(mod) == .Vector) {3476 if (float_type.zigTypeTag(zcu) == .Vector) {
3424 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3477 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3425 const scalar_ty = float_type.scalarType(mod);3478 const scalar_ty = float_type.scalarType(zcu);
3426 for (result_data, 0..) |*scalar, i| {3479 for (result_data, 0..) |*scalar, i| {
3427 const elem_val = try val.elemValue(pt, i);3480 const elem_val = try val.elemValue(pt, i);
3428 scalar.* = (try floorScalar(elem_val, scalar_ty, pt)).toIntern();3481 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)...@@ -3436,14 +3489,14 @@ pub fn floor(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
3436}3489}
34373490
3438pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3491pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3439 const mod = pt.zcu;3492 const zcu = pt.zcu;
3440 const target = mod.getTarget();3493 const target = zcu.getTarget();
3441 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3494 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3442 16 => .{ .f16 = @floor(val.toFloat(f16, pt)) },3495 16 => .{ .f16 = @floor(val.toFloat(f16, zcu)) },
3443 32 => .{ .f32 = @floor(val.toFloat(f32, pt)) },3496 32 => .{ .f32 = @floor(val.toFloat(f32, zcu)) },
3444 64 => .{ .f64 = @floor(val.toFloat(f64, pt)) },3497 64 => .{ .f64 = @floor(val.toFloat(f64, zcu)) },
3445 80 => .{ .f80 = @floor(val.toFloat(f80, pt)) },3498 80 => .{ .f80 = @floor(val.toFloat(f80, zcu)) },
3446 128 => .{ .f128 = @floor(val.toFloat(f128, pt)) },3499 128 => .{ .f128 = @floor(val.toFloat(f128, zcu)) },
3447 else => unreachable,3500 else => unreachable,
3448 };3501 };
3449 return Value.fromInterned(try pt.intern(.{ .float = .{3502 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3453,10 +3506,10 @@ pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er...@@ -3453,10 +3506,10 @@ pub fn floorScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
3453}3506}
34543507
3455pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3508pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3456 const mod = pt.zcu;3509 const zcu = pt.zcu;
3457 if (float_type.zigTypeTag(mod) == .Vector) {3510 if (float_type.zigTypeTag(zcu) == .Vector) {
3458 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3511 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3459 const scalar_ty = float_type.scalarType(mod);3512 const scalar_ty = float_type.scalarType(zcu);
3460 for (result_data, 0..) |*scalar, i| {3513 for (result_data, 0..) |*scalar, i| {
3461 const elem_val = try val.elemValue(pt, i);3514 const elem_val = try val.elemValue(pt, i);
3462 scalar.* = (try ceilScalar(elem_val, scalar_ty, pt)).toIntern();3515 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) !...@@ -3470,14 +3523,14 @@ pub fn ceil(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !
3470}3523}
34713524
3472pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3525pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3473 const mod = pt.zcu;3526 const zcu = pt.zcu;
3474 const target = mod.getTarget();3527 const target = zcu.getTarget();
3475 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3528 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3476 16 => .{ .f16 = @ceil(val.toFloat(f16, pt)) },3529 16 => .{ .f16 = @ceil(val.toFloat(f16, zcu)) },
3477 32 => .{ .f32 = @ceil(val.toFloat(f32, pt)) },3530 32 => .{ .f32 = @ceil(val.toFloat(f32, zcu)) },
3478 64 => .{ .f64 = @ceil(val.toFloat(f64, pt)) },3531 64 => .{ .f64 = @ceil(val.toFloat(f64, zcu)) },
3479 80 => .{ .f80 = @ceil(val.toFloat(f80, pt)) },3532 80 => .{ .f80 = @ceil(val.toFloat(f80, zcu)) },
3480 128 => .{ .f128 = @ceil(val.toFloat(f128, pt)) },3533 128 => .{ .f128 = @ceil(val.toFloat(f128, zcu)) },
3481 else => unreachable,3534 else => unreachable,
3482 };3535 };
3483 return Value.fromInterned(try pt.intern(.{ .float = .{3536 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3487,10 +3540,10 @@ pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err...@@ -3487,10 +3540,10 @@ pub fn ceilScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Err
3487}3540}
34883541
3489pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3542pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3490 const mod = pt.zcu;3543 const zcu = pt.zcu;
3491 if (float_type.zigTypeTag(mod) == .Vector) {3544 if (float_type.zigTypeTag(zcu) == .Vector) {
3492 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3545 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3493 const scalar_ty = float_type.scalarType(mod);3546 const scalar_ty = float_type.scalarType(zcu);
3494 for (result_data, 0..) |*scalar, i| {3547 for (result_data, 0..) |*scalar, i| {
3495 const elem_val = try val.elemValue(pt, i);3548 const elem_val = try val.elemValue(pt, i);
3496 scalar.* = (try roundScalar(elem_val, scalar_ty, pt)).toIntern();3549 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)...@@ -3504,14 +3557,14 @@ pub fn round(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
3504}3557}
35053558
3506pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3559pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3507 const mod = pt.zcu;3560 const zcu = pt.zcu;
3508 const target = mod.getTarget();3561 const target = zcu.getTarget();
3509 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3562 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3510 16 => .{ .f16 = @round(val.toFloat(f16, pt)) },3563 16 => .{ .f16 = @round(val.toFloat(f16, zcu)) },
3511 32 => .{ .f32 = @round(val.toFloat(f32, pt)) },3564 32 => .{ .f32 = @round(val.toFloat(f32, zcu)) },
3512 64 => .{ .f64 = @round(val.toFloat(f64, pt)) },3565 64 => .{ .f64 = @round(val.toFloat(f64, zcu)) },
3513 80 => .{ .f80 = @round(val.toFloat(f80, pt)) },3566 80 => .{ .f80 = @round(val.toFloat(f80, zcu)) },
3514 128 => .{ .f128 = @round(val.toFloat(f128, pt)) },3567 128 => .{ .f128 = @round(val.toFloat(f128, zcu)) },
3515 else => unreachable,3568 else => unreachable,
3516 };3569 };
3517 return Value.fromInterned(try pt.intern(.{ .float = .{3570 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3521,10 +3574,10 @@ pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er...@@ -3521,10 +3574,10 @@ pub fn roundScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Er
3521}3574}
35223575
3523pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {3576pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread) !Value {
3524 const mod = pt.zcu;3577 const zcu = pt.zcu;
3525 if (float_type.zigTypeTag(mod) == .Vector) {3578 if (float_type.zigTypeTag(zcu) == .Vector) {
3526 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3579 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3527 const scalar_ty = float_type.scalarType(mod);3580 const scalar_ty = float_type.scalarType(zcu);
3528 for (result_data, 0..) |*scalar, i| {3581 for (result_data, 0..) |*scalar, i| {
3529 const elem_val = try val.elemValue(pt, i);3582 const elem_val = try val.elemValue(pt, i);
3530 scalar.* = (try truncScalar(elem_val, scalar_ty, pt)).toIntern();3583 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)...@@ -3538,14 +3591,14 @@ pub fn trunc(val: Value, float_type: Type, arena: Allocator, pt: Zcu.PerThread)
3538}3591}
35393592
3540pub fn truncScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {3593pub fn truncScalar(val: Value, float_type: Type, pt: Zcu.PerThread) Allocator.Error!Value {
3541 const mod = pt.zcu;3594 const zcu = pt.zcu;
3542 const target = mod.getTarget();3595 const target = zcu.getTarget();
3543 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3596 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3544 16 => .{ .f16 = @trunc(val.toFloat(f16, pt)) },3597 16 => .{ .f16 = @trunc(val.toFloat(f16, zcu)) },
3545 32 => .{ .f32 = @trunc(val.toFloat(f32, pt)) },3598 32 => .{ .f32 = @trunc(val.toFloat(f32, zcu)) },
3546 64 => .{ .f64 = @trunc(val.toFloat(f64, pt)) },3599 64 => .{ .f64 = @trunc(val.toFloat(f64, zcu)) },
3547 80 => .{ .f80 = @trunc(val.toFloat(f80, pt)) },3600 80 => .{ .f80 = @trunc(val.toFloat(f80, zcu)) },
3548 128 => .{ .f128 = @trunc(val.toFloat(f128, pt)) },3601 128 => .{ .f128 = @trunc(val.toFloat(f128, zcu)) },
3549 else => unreachable,3602 else => unreachable,
3550 };3603 };
3551 return Value.fromInterned(try pt.intern(.{ .float = .{3604 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3562,10 +3615,10 @@ pub fn mulAdd(...@@ -3562,10 +3615,10 @@ pub fn mulAdd(
3562 arena: Allocator,3615 arena: Allocator,
3563 pt: Zcu.PerThread,3616 pt: Zcu.PerThread,
3564) !Value {3617) !Value {
3565 const mod = pt.zcu;3618 const zcu = pt.zcu;
3566 if (float_type.zigTypeTag(mod) == .Vector) {3619 if (float_type.zigTypeTag(zcu) == .Vector) {
3567 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));3620 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(zcu));
3568 const scalar_ty = float_type.scalarType(mod);3621 const scalar_ty = float_type.scalarType(zcu);
3569 for (result_data, 0..) |*scalar, i| {3622 for (result_data, 0..) |*scalar, i| {
3570 const mulend1_elem = try mulend1.elemValue(pt, i);3623 const mulend1_elem = try mulend1.elemValue(pt, i);
3571 const mulend2_elem = try mulend2.elemValue(pt, i);3624 const mulend2_elem = try mulend2.elemValue(pt, i);
...@@ -3587,14 +3640,14 @@ pub fn mulAddScalar(...@@ -3587,14 +3640,14 @@ pub fn mulAddScalar(
3587 addend: Value,3640 addend: Value,
3588 pt: Zcu.PerThread,3641 pt: Zcu.PerThread,
3589) Allocator.Error!Value {3642) Allocator.Error!Value {
3590 const mod = pt.zcu;3643 const zcu = pt.zcu;
3591 const target = mod.getTarget();3644 const target = zcu.getTarget();
3592 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {3645 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)) },3646 16 => .{ .f16 = @mulAdd(f16, mulend1.toFloat(f16, zcu), mulend2.toFloat(f16, zcu), addend.toFloat(f16, zcu)) },
3594 32 => .{ .f32 = @mulAdd(f32, mulend1.toFloat(f32, pt), mulend2.toFloat(f32, pt), addend.toFloat(f32, pt)) },3647 32 => .{ .f32 = @mulAdd(f32, mulend1.toFloat(f32, zcu), mulend2.toFloat(f32, zcu), addend.toFloat(f32, zcu)) },
3595 64 => .{ .f64 = @mulAdd(f64, mulend1.toFloat(f64, pt), mulend2.toFloat(f64, pt), addend.toFloat(f64, pt)) },3648 64 => .{ .f64 = @mulAdd(f64, mulend1.toFloat(f64, zcu), mulend2.toFloat(f64, zcu), addend.toFloat(f64, zcu)) },
3596 80 => .{ .f80 = @mulAdd(f80, mulend1.toFloat(f80, pt), mulend2.toFloat(f80, pt), addend.toFloat(f80, pt)) },3649 80 => .{ .f80 = @mulAdd(f80, mulend1.toFloat(f80, zcu), mulend2.toFloat(f80, zcu), addend.toFloat(f80, zcu)) },
3597 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, pt), mulend2.toFloat(f128, pt), addend.toFloat(f128, pt)) },3650 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, zcu), mulend2.toFloat(f128, zcu), addend.toFloat(f128, zcu)) },
3598 else => unreachable,3651 else => unreachable,
3599 };3652 };
3600 return Value.fromInterned(try pt.intern(.{ .float = .{3653 return Value.fromInterned(try pt.intern(.{ .float = .{
...@@ -3606,10 +3659,11 @@ pub fn mulAddScalar(...@@ -3606,10 +3659,11 @@ pub fn mulAddScalar(
3606/// If the value is represented in-memory as a series of bytes that all3659/// If the value is represented in-memory as a series of bytes that all
3607/// have the same value, return that byte value, otherwise null.3660/// have the same value, return that byte value, otherwise null.
3608pub fn hasRepeatedByteRepr(val: Value, ty: Type, pt: Zcu.PerThread) !?u8 {3661pub 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;
3610 assert(abi_size >= 1);3664 assert(abi_size >= 1);
3611 const byte_buffer = try pt.zcu.gpa.alloc(u8, abi_size);3665 const byte_buffer = try zcu.gpa.alloc(u8, abi_size);
3612 defer pt.zcu.gpa.free(byte_buffer);3666 defer zcu.gpa.free(byte_buffer);
36133667
3614 writeToMemory(val, ty, pt, byte_buffer) catch |err| switch (err) {3668 writeToMemory(val, ty, pt, byte_buffer) catch |err| switch (err) {
3615 error.OutOfMemory => return error.OutOfMemory,3669 error.OutOfMemory => return error.OutOfMemory,
...@@ -3754,15 +3808,15 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {...@@ -3754,15 +3808,15 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
3754 // `field_align` may be `.none` to represent the natural alignment of `field_ty`, but is not necessarily.3808 // `field_align` may be `.none` to represent the natural alignment of `field_ty`, but is not necessarily.
3755 const field_ty: Type, const field_align: InternPool.Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {3809 const field_ty: Type, const field_align: InternPool.Alignment = switch (aggregate_ty.zigTypeTag(zcu)) {
3756 .Struct => field: {3810 .Struct => field: {
3757 const field_ty = aggregate_ty.structFieldType(field_idx, zcu);3811 const field_ty = aggregate_ty.fieldType(field_idx, zcu);
3758 switch (aggregate_ty.containerLayout(zcu)) {3812 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) },
3760 .@"extern" => {3814 .@"extern" => {
3761 // Well-defined layout, so just offset the pointer appropriately.3815 // 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);
3763 const field_align = a: {3817 const field_align = a: {
3764 const parent_align = if (parent_ptr_info.flags.alignment == .none) pa: {3818 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);
3766 } else parent_ptr_info.flags.alignment;3820 } else parent_ptr_info.flags.alignment;
3767 break :a InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(byte_off)));3821 break :a InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(byte_off)));
3768 };3822 };
...@@ -3781,7 +3835,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {...@@ -3781,7 +3835,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
3781 new.packed_offset = packed_offset;3835 new.packed_offset = packed_offset;
3782 new.child = field_ty.toIntern();3836 new.child = field_ty.toIntern();
3783 if (new.flags.alignment == .none) {3837 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);
3785 }3839 }
3786 break :info new;3840 break :info new;
3787 });3841 });
...@@ -3807,7 +3861,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {...@@ -3807,7 +3861,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
3807 const union_obj = zcu.typeToUnion(aggregate_ty).?;3861 const union_obj = zcu.typeToUnion(aggregate_ty).?;
3808 const field_ty = Type.fromInterned(union_obj.field_types.get(&zcu.intern_pool)[field_idx]);3862 const field_ty = Type.fromInterned(union_obj.field_types.get(&zcu.intern_pool)[field_idx]);
3809 switch (aggregate_ty.containerLayout(zcu)) {3863 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) },
3811 .@"extern" => {3865 .@"extern" => {
3812 // Point to the same address.3866 // Point to the same address.
3813 const result_ty = try pt.ptrTypeSema(info: {3867 const result_ty = try pt.ptrTypeSema(info: {
...@@ -3820,17 +3874,17 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {...@@ -3820,17 +3874,17 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
3820 .@"packed" => {3874 .@"packed" => {
3821 // If the field has an ABI size matching its bit size, then we can continue to use a3875 // If the field has an ABI size matching its bit size, then we can continue to use a
3822 // non-bit pointer if the parent pointer is also a non-bit pointer.3876 // 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)) {
3824 // We must offset the pointer on big-endian targets, since the bits of packed memory don't align nicely.3878 // We must offset the pointer on big-endian targets, since the bits of packed memory don't align nicely.
3825 const byte_offset = switch (zcu.getTarget().cpu.arch.endian()) {3879 const byte_offset = switch (zcu.getTarget().cpu.arch.endian()) {
3826 .little => 0,3880 .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,
3828 };3882 };
3829 const result_ty = try pt.ptrTypeSema(info: {3883 const result_ty = try pt.ptrTypeSema(info: {
3830 var new = parent_ptr_info;3884 var new = parent_ptr_info;
3831 new.child = field_ty.toIntern();3885 new.child = field_ty.toIntern();
3832 new.flags.alignment = InternPool.Alignment.fromLog2Units(3886 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().?),
3834 );3888 );
3835 break :info new;3889 break :info new;
3836 });3890 });
...@@ -3841,7 +3895,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {...@@ -3841,7 +3895,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
3841 var new = parent_ptr_info;3895 var new = parent_ptr_info;
3842 new.child = field_ty.toIntern();3896 new.child = field_ty.toIntern();
3843 if (new.packed_offset.host_size == 0) {3897 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);
3845 assert(new.packed_offset.bit_offset == 0);3899 assert(new.packed_offset.bit_offset == 0);
3846 }3900 }
3847 break :info new;3901 break :info new;
...@@ -3854,8 +3908,8 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {...@@ -3854,8 +3908,8 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
3854 .Pointer => field_ty: {3908 .Pointer => field_ty: {
3855 assert(aggregate_ty.isSlice(zcu));3909 assert(aggregate_ty.isSlice(zcu));
3856 break :field_ty switch (field_idx) {3910 break :field_ty switch (field_idx) {
3857 Value.slice_ptr_index => .{ aggregate_ty.slicePtrFieldType(zcu), Type.usize.abiAlignment(pt) },3911 Value.slice_ptr_index => .{ aggregate_ty.slicePtrFieldType(zcu), Type.usize.abiAlignment(zcu) },
3858 Value.slice_len_index => .{ Type.usize, Type.usize.abiAlignment(pt) },3912 Value.slice_len_index => .{ Type.usize, Type.usize.abiAlignment(zcu) },
3859 else => unreachable,3913 else => unreachable,
3860 };3914 };
3861 },3915 },
...@@ -3863,7 +3917,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {...@@ -3863,7 +3917,7 @@ pub fn ptrField(parent_ptr: Value, field_idx: u32, pt: Zcu.PerThread) !Value {
3863 };3917 };
38643918
3865 const new_align: InternPool.Alignment = if (parent_ptr_info.flags.alignment != .none) a: {3919 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;
3867 const true_field_align = if (field_align == .none) ty_align else field_align;3921 const true_field_align = if (field_align == .none) ty_align else field_align;
3868 const new_align = true_field_align.min(parent_ptr_info.flags.alignment);3922 const new_align = true_field_align.min(parent_ptr_info.flags.alignment);
3869 if (new_align == ty_align) break :a .none;3923 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...@@ -3919,21 +3973,21 @@ pub fn ptrElem(orig_parent_ptr: Value, field_idx: u64, pt: Zcu.PerThread) !Value
39193973
3920 const strat: PtrStrat = switch (parent_ptr_ty.ptrSize(zcu)) {3974 const strat: PtrStrat = switch (parent_ptr_ty.ptrSize(zcu)) {
3921 .One => switch (elem_ty.zigTypeTag(zcu)) {3975 .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) },
3923 .Array => strat: {3977 .Array => strat: {
3924 const arr_elem_ty = elem_ty.childType(zcu);3978 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)) {
3926 break :strat .{ .elem_ptr = arr_elem_ty };3980 break :strat .{ .elem_ptr = arr_elem_ty };
3927 }3981 }
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 };
3929 },3983 },
3930 else => unreachable,3984 else => unreachable,
3931 },3985 },
39323986
3933 .Many, .C => if (try elem_ty.comptimeOnlyAdvanced(pt, .sema))3987 .Many, .C => if (try elem_ty.comptimeOnlySema(pt))
3934 .{ .elem_ptr = elem_ty }3988 .{ .elem_ptr = elem_ty }
3935 else3989 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
3938 .Slice => unreachable,3992 .Slice => unreachable,
3939 };3993 };
...@@ -4142,22 +4196,32 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4142,22 +4196,32 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4142 const base_ptr_ty = base_ptr.typeOf(zcu);4196 const base_ptr_ty = base_ptr.typeOf(zcu);
4143 const agg_ty = base_ptr_ty.childType(zcu);4197 const agg_ty = base_ptr_ty.childType(zcu);
4144 const field_ty, const field_align = switch (agg_ty.zigTypeTag(zcu)) {4198 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) },4199 .Struct => .{ agg_ty.fieldType(@intCast(field.index), zcu), try agg_ty.fieldAlignmentInner(
4146 .Union => .{ agg_ty.unionFieldTypeByIndex(@intCast(field.index), zcu), try agg_ty.structFieldAlignAdvanced(@intCast(field.index), pt, if (have_sema) .sema else .normal) },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 ) },
4147 .Pointer => .{ switch (field.index) {4211 .Pointer => .{ switch (field.index) {
4148 Value.slice_ptr_index => agg_ty.slicePtrFieldType(zcu),4212 Value.slice_ptr_index => agg_ty.slicePtrFieldType(zcu),
4149 Value.slice_len_index => Type.usize,4213 Value.slice_len_index => Type.usize,
4150 else => unreachable,4214 else => unreachable,
4151 }, Type.usize.abiAlignment(pt) },4215 }, Type.usize.abiAlignment(zcu) },
4152 else => unreachable,4216 else => unreachable,
4153 };4217 };
4154 const base_align = base_ptr_ty.ptrAlignment(pt);4218 const base_align = base_ptr_ty.ptrAlignment(zcu);
4155 const result_align = field_align.minStrict(base_align);4219 const result_align = field_align.minStrict(base_align);
4156 const result_ty = try pt.ptrType(.{4220 const result_ty = try pt.ptrType(.{
4157 .child = field_ty.toIntern(),4221 .child = field_ty.toIntern(),
4158 .flags = flags: {4222 .flags = flags: {
4159 var flags = base_ptr_ty.ptrInfo(zcu).flags;4223 var flags = base_ptr_ty.ptrInfo(zcu).flags;
4160 if (result_align == field_ty.abiAlignment(pt)) {4224 if (result_align == field_ty.abiAlignment(zcu)) {
4161 flags.alignment = .none;4225 flags.alignment = .none;
4162 } else {4226 } else {
4163 flags.alignment = result_align;4227 flags.alignment = result_align;
...@@ -4198,7 +4262,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4198,7 +4262,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4198 }4262 }
41994263
4200 const need_child = Type.fromInterned(ptr.ty).childType(zcu);4264 const need_child = Type.fromInterned(ptr.ty).childType(zcu);
4201 if (need_child.comptimeOnly(pt)) {4265 if (need_child.comptimeOnly(zcu)) {
4202 // No refinement can happen - this pointer is presumably invalid.4266 // No refinement can happen - this pointer is presumably invalid.
4203 // Just offset it.4267 // Just offset it.
4204 const parent = try arena.create(PointerDeriveStep);4268 const parent = try arena.create(PointerDeriveStep);
...@@ -4209,7 +4273,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4209,7 +4273,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4209 .new_ptr_ty = Type.fromInterned(ptr.ty),4273 .new_ptr_ty = Type.fromInterned(ptr.ty),
4210 } };4274 } };
4211 }4275 }
4212 const need_bytes = need_child.abiSize(pt);4276 const need_bytes = need_child.abiSize(zcu);
42134277
4214 var cur_derive = base_derive;4278 var cur_derive = base_derive;
4215 var cur_offset = ptr.byte_offset;4279 var cur_offset = ptr.byte_offset;
...@@ -4248,7 +4312,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4248,7 +4312,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
42484312
4249 .Array => {4313 .Array => {
4250 const elem_ty = cur_ty.childType(zcu);4314 const elem_ty = cur_ty.childType(zcu);
4251 const elem_size = elem_ty.abiSize(pt);4315 const elem_size = elem_ty.abiSize(zcu);
4252 const start_idx = cur_offset / elem_size;4316 const start_idx = cur_offset / elem_size;
4253 const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;4317 const end_idx = (cur_offset + need_bytes + elem_size - 1) / elem_size;
4254 if (end_idx == start_idx + 1) {4318 if (end_idx == start_idx + 1) {
...@@ -4278,12 +4342,12 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4278,12 +4342,12 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4278 .Struct => switch (cur_ty.containerLayout(zcu)) {4342 .Struct => switch (cur_ty.containerLayout(zcu)) {
4279 .auto, .@"packed" => break,4343 .auto, .@"packed" => break,
4280 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {4344 .@"extern" => for (0..cur_ty.structFieldCount(zcu)) |field_idx| {
4281 const field_ty = cur_ty.structFieldType(field_idx, zcu);4345 const field_ty = cur_ty.fieldType(field_idx, zcu);
4282 const start_off = cur_ty.structFieldOffset(field_idx, pt);4346 const start_off = cur_ty.structFieldOffset(field_idx, zcu);
4283 const end_off = start_off + field_ty.abiSize(pt);4347 const end_off = start_off + field_ty.abiSize(zcu);
4284 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {4348 if (cur_offset >= start_off and cur_offset + need_bytes <= end_off) {
4285 const old_ptr_ty = try cur_derive.ptrType(pt);4349 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);
4287 const field_align = InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(start_off)));4351 const field_align = InternPool.Alignment.fromLog2Units(@min(parent_align.toLog2Units(), @ctz(start_off)));
4288 const parent = try arena.create(PointerDeriveStep);4352 const parent = try arena.create(PointerDeriveStep);
4289 parent.* = cur_derive;4353 parent.* = cur_derive;
...@@ -4291,7 +4355,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4291,7 +4355,7 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4291 .child = field_ty.toIntern(),4355 .child = field_ty.toIntern(),
4292 .flags = flags: {4356 .flags = flags: {
4293 var flags = old_ptr_ty.ptrInfo(zcu).flags;4357 var flags = old_ptr_ty.ptrInfo(zcu).flags;
4294 if (field_align == field_ty.abiAlignment(pt)) {4358 if (field_align == field_ty.abiAlignment(zcu)) {
4295 flags.alignment = .none;4359 flags.alignment = .none;
4296 } else {4360 } else {
4297 flags.alignment = field_align;4361 flags.alignment = field_align;
...@@ -4325,13 +4389,17 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh...@@ -4325,13 +4389,17 @@ pub fn pointerDerivationAdvanced(ptr_val: Value, arena: Allocator, pt: Zcu.PerTh
4325 } };4389 } };
4326}4390}
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 {
4329 switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {4397 switch (pt.zcu.intern_pool.indexToKey(val.toIntern())) {
4330 .int => |int| switch (int.storage) {4398 .int => |int| switch (int.storage) {
4331 .u64, .i64, .big_int => return val,4399 .u64, .i64, .big_int => return val,
4332 .lazy_align, .lazy_size => return pt.intValue(4400 .lazy_align, .lazy_size => return pt.intValue(
4333 Type.fromInterned(int.ty),4401 Type.fromInterned(int.ty),
4334 (try val.getUnsignedIntAdvanced(pt, .sema)).?,4402 try val.toUnsignedIntSema(pt),
4335 ),4403 ),
4336 },4404 },
4337 .slice => |slice| {4405 .slice => |slice| {
src/Zcu.zig+51-38
...@@ -2109,9 +2109,9 @@ pub const CompileError = error{...@@ -2109,9 +2109,9 @@ pub const CompileError = error{
2109 ComptimeBreak,2109 ComptimeBreak,
2110};2110};
21112111
2112pub fn init(mod: *Zcu, thread_count: usize) !void {2112pub fn init(zcu: *Zcu, thread_count: usize) !void {
2113 const gpa = mod.gpa;2113 const gpa = zcu.gpa;
2114 try mod.intern_pool.init(gpa, thread_count);2114 try zcu.intern_pool.init(gpa, thread_count);
2115}2115}
21162116
2117pub fn deinit(zcu: *Zcu) void {2117pub fn deinit(zcu: *Zcu) void {
...@@ -2204,8 +2204,8 @@ pub fn namespacePtr(zcu: *Zcu, index: Namespace.Index) *Namespace {...@@ -2204,8 +2204,8 @@ pub fn namespacePtr(zcu: *Zcu, index: Namespace.Index) *Namespace {
2204 return zcu.intern_pool.namespacePtr(index);2204 return zcu.intern_pool.namespacePtr(index);
2205}2205}
22062206
2207pub fn namespacePtrUnwrap(mod: *Zcu, index: Namespace.OptionalIndex) ?*Namespace {2207pub fn namespacePtrUnwrap(zcu: *Zcu, index: Namespace.OptionalIndex) ?*Namespace {
2208 return mod.namespacePtr(index.unwrap() orelse return null);2208 return zcu.namespacePtr(index.unwrap() orelse return null);
2209}2209}
22102210
2211// TODO https://github.com/ziglang/zig/issues/86432211// TODO https://github.com/ziglang/zig/issues/8643
...@@ -2682,7 +2682,7 @@ pub fn mapOldZirToNew(...@@ -2682,7 +2682,7 @@ pub fn mapOldZirToNew(
2682///2682///
2683/// The caller is responsible for ensuring the function decl itself is already2683/// The caller is responsible for ensuring the function decl itself is already
2684/// analyzed, and for ensuring it can exist at runtime (see2684/// analyzed, and for ensuring it can exist at runtime (see
2685/// `sema.fnHasRuntimeBits`). This function does *not* guarantee that the body2685/// `Type.fnHasRuntimeBitsSema`). This function does *not* guarantee that the body
2686/// will be analyzed when it returns: for that, see `ensureFuncBodyAnalyzed`.2686/// will be analyzed when it returns: for that, see `ensureFuncBodyAnalyzed`.
2687pub fn ensureFuncBodyAnalysisQueued(zcu: *Zcu, func_index: InternPool.Index) !void {2687pub fn ensureFuncBodyAnalysisQueued(zcu: *Zcu, func_index: InternPool.Index) !void {
2688 const ip = &zcu.intern_pool;2688 const ip = &zcu.intern_pool;
...@@ -2840,22 +2840,22 @@ pub fn addTypeReference(zcu: *Zcu, src_unit: AnalUnit, referenced_type: InternPo...@@ -2840,22 +2840,22 @@ pub fn addTypeReference(zcu: *Zcu, src_unit: AnalUnit, referenced_type: InternPo
2840 gop.value_ptr.* = @intCast(ref_idx);2840 gop.value_ptr.* = @intCast(ref_idx);
2841}2841}
28422842
2843pub fn errorSetBits(mod: *Zcu) u16 {2843pub fn errorSetBits(zcu: *const Zcu) u16 {
2844 if (mod.error_limit == 0) return 0;2844 if (zcu.error_limit == 0) return 0;
2845 return @as(u16, std.math.log2_int(ErrorInt, mod.error_limit)) + 1;2845 return @as(u16, std.math.log2_int(ErrorInt, zcu.error_limit)) + 1;
2846}2846}
28472847
2848pub fn errNote(2848pub fn errNote(
2849 mod: *Zcu,2849 zcu: *Zcu,
2850 src_loc: LazySrcLoc,2850 src_loc: LazySrcLoc,
2851 parent: *ErrorMsg,2851 parent: *ErrorMsg,
2852 comptime format: []const u8,2852 comptime format: []const u8,
2853 args: anytype,2853 args: anytype,
2854) error{OutOfMemory}!void {2854) error{OutOfMemory}!void {
2855 const msg = try std.fmt.allocPrint(mod.gpa, format, args);2855 const msg = try std.fmt.allocPrint(zcu.gpa, format, args);
2856 errdefer mod.gpa.free(msg);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);
2859 parent.notes[parent.notes.len - 1] = .{2859 parent.notes[parent.notes.len - 1] = .{
2860 .src_loc = src_loc,2860 .src_loc = src_loc,
2861 .msg = msg,2861 .msg = msg,
...@@ -2876,14 +2876,14 @@ pub fn optimizeMode(zcu: *const Zcu) std.builtin.OptimizeMode {...@@ -2876,14 +2876,14 @@ pub fn optimizeMode(zcu: *const Zcu) std.builtin.OptimizeMode {
2876 return zcu.root_mod.optimize_mode;2876 return zcu.root_mod.optimize_mode;
2877}2877}
28782878
2879fn lockAndClearFileCompileError(mod: *Zcu, file: *File) void {2879fn lockAndClearFileCompileError(zcu: *Zcu, file: *File) void {
2880 switch (file.status) {2880 switch (file.status) {
2881 .success_zir, .retryable_failure => {},2881 .success_zir, .retryable_failure => {},
2882 .never_loaded, .parse_failure, .astgen_failure => {2882 .never_loaded, .parse_failure, .astgen_failure => {
2883 mod.comp.mutex.lock();2883 zcu.comp.mutex.lock();
2884 defer mod.comp.mutex.unlock();2884 defer zcu.comp.mutex.unlock();
2885 if (mod.failed_files.fetchSwapRemove(file)) |kv| {2885 if (zcu.failed_files.fetchSwapRemove(file)) |kv| {
2886 if (kv.value) |msg| msg.destroy(mod.gpa); // Delete previous error message.2886 if (kv.value) |msg| msg.destroy(zcu.gpa); // Delete previous error message.
2887 }2887 }
2888 },2888 },
2889 }2889 }
...@@ -2923,10 +2923,23 @@ pub fn addGlobalAssembly(zcu: *Zcu, cau: InternPool.Cau.Index, source: []const u...@@ -2923,10 +2923,23 @@ pub fn addGlobalAssembly(zcu: *Zcu, cau: InternPool.Cau.Index, source: []const u
2923}2923}
29242924
2925pub const Feature = enum {2925pub 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.
2926 panic_fn,2928 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.
2927 panic_unwrap_error,2932 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.
2928 safety_check_formatted,2936 safety_check_formatted,
2937 /// When this feature is enabled, Sema will insert tracer functions for gathering a stack
2938 /// trace for error returns.
2929 error_return_trace,2939 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.
2930 is_named_enum_value,2943 is_named_enum_value,
2931 error_set_has_value,2944 error_set_has_value,
2932 field_reordering,2945 field_reordering,
...@@ -2965,11 +2978,11 @@ pub const AtomicPtrAlignmentDiagnostics = struct {...@@ -2965,11 +2978,11 @@ pub const AtomicPtrAlignmentDiagnostics = struct {
2965// TODO this function does not take into account CPU features, which can affect2978// TODO this function does not take into account CPU features, which can affect
2966// this value. Audit this!2979// this value. Audit this!
2967pub fn atomicPtrAlignment(2980pub fn atomicPtrAlignment(
2968 mod: *Zcu,2981 zcu: *Zcu,
2969 ty: Type,2982 ty: Type,
2970 diags: *AtomicPtrAlignmentDiagnostics,2983 diags: *AtomicPtrAlignmentDiagnostics,
2971) AtomicPtrAlignmentError!Alignment {2984) AtomicPtrAlignmentError!Alignment {
2972 const target = mod.getTarget();2985 const target = zcu.getTarget();
2973 const max_atomic_bits: u16 = switch (target.cpu.arch) {2986 const max_atomic_bits: u16 = switch (target.cpu.arch) {
2974 .avr,2987 .avr,
2975 .msp430,2988 .msp430,
...@@ -3039,8 +3052,8 @@ pub fn atomicPtrAlignment(...@@ -3039,8 +3052,8 @@ pub fn atomicPtrAlignment(
3039 }3052 }
3040 return .none;3053 return .none;
3041 }3054 }
3042 if (ty.isAbiInt(mod)) {3055 if (ty.isAbiInt(zcu)) {
3043 const bit_count = ty.intInfo(mod).bits;3056 const bit_count = ty.intInfo(zcu).bits;
3044 if (bit_count > max_atomic_bits) {3057 if (bit_count > max_atomic_bits) {
3045 diags.* = .{3058 diags.* = .{
3046 .bits = bit_count,3059 .bits = bit_count,
...@@ -3050,7 +3063,7 @@ pub fn atomicPtrAlignment(...@@ -3050,7 +3063,7 @@ pub fn atomicPtrAlignment(
3050 }3063 }
3051 return .none;3064 return .none;
3052 }3065 }
3053 if (ty.isPtrAtRuntime(mod)) return .none;3066 if (ty.isPtrAtRuntime(zcu)) return .none;
3054 return error.BadType;3067 return error.BadType;
3055}3068}
30563069
...@@ -3058,45 +3071,45 @@ pub fn atomicPtrAlignment(...@@ -3058,45 +3071,45 @@ pub fn atomicPtrAlignment(
3058/// * `@TypeOf(.{})`3071/// * `@TypeOf(.{})`
3059/// * A struct which has no fields (`struct {}`).3072/// * A struct which has no fields (`struct {}`).
3060/// * Not a struct.3073/// * Not a struct.
3061pub fn typeToStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {3074pub fn typeToStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3062 if (ty.ip_index == .none) return null;3075 if (ty.ip_index == .none) return null;
3063 const ip = &mod.intern_pool;3076 const ip = &zcu.intern_pool;
3064 return switch (ip.indexToKey(ty.ip_index)) {3077 return switch (ip.indexToKey(ty.ip_index)) {
3065 .struct_type => ip.loadStructType(ty.ip_index),3078 .struct_type => ip.loadStructType(ty.ip_index),
3066 else => null,3079 else => null,
3067 };3080 };
3068}3081}
30693082
3070pub fn typeToPackedStruct(mod: *Zcu, ty: Type) ?InternPool.LoadedStructType {3083pub fn typeToPackedStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3071 const s = mod.typeToStruct(ty) orelse return null;3084 const s = zcu.typeToStruct(ty) orelse return null;
3072 if (s.layout != .@"packed") return null;3085 if (s.layout != .@"packed") return null;
3073 return s;3086 return s;
3074}3087}
30753088
3076pub fn typeToUnion(mod: *Zcu, ty: Type) ?InternPool.LoadedUnionType {3089pub fn typeToUnion(zcu: *const Zcu, ty: Type) ?InternPool.LoadedUnionType {
3077 if (ty.ip_index == .none) return null;3090 if (ty.ip_index == .none) return null;
3078 const ip = &mod.intern_pool;3091 const ip = &zcu.intern_pool;
3079 return switch (ip.indexToKey(ty.ip_index)) {3092 return switch (ip.indexToKey(ty.ip_index)) {
3080 .union_type => ip.loadUnionType(ty.ip_index),3093 .union_type => ip.loadUnionType(ty.ip_index),
3081 else => null,3094 else => null,
3082 };3095 };
3083}3096}
30843097
3085pub fn typeToFunc(mod: *Zcu, ty: Type) ?InternPool.Key.FuncType {3098pub fn typeToFunc(zcu: *const Zcu, ty: Type) ?InternPool.Key.FuncType {
3086 if (ty.ip_index == .none) return null;3099 if (ty.ip_index == .none) return null;
3087 return mod.intern_pool.indexToFuncType(ty.toIntern());3100 return zcu.intern_pool.indexToFuncType(ty.toIntern());
3088}3101}
30893102
3090pub fn iesFuncIndex(zcu: *const Zcu, ies_index: InternPool.Index) InternPool.Index {3103pub fn iesFuncIndex(zcu: *const Zcu, ies_index: InternPool.Index) InternPool.Index {
3091 return zcu.intern_pool.iesFuncIndex(ies_index);3104 return zcu.intern_pool.iesFuncIndex(ies_index);
3092}3105}
30933106
3094pub fn funcInfo(mod: *Zcu, func_index: InternPool.Index) InternPool.Key.Func {3107pub fn funcInfo(zcu: *const Zcu, func_index: InternPool.Index) InternPool.Key.Func {
3095 return mod.intern_pool.indexToKey(func_index).func;3108 return zcu.intern_pool.indexToKey(func_index).func;
3096}3109}
30973110
3098pub fn toEnum(mod: *Zcu, comptime E: type, val: Value) E {3111pub fn toEnum(zcu: *const Zcu, comptime E: type, val: Value) E {
3099 return mod.intern_pool.toEnum(E, val.toIntern());3112 return zcu.intern_pool.toEnum(E, val.toIntern());
3100}3113}
31013114
3102pub const UnionLayout = struct {3115pub const UnionLayout = struct {
...@@ -3121,8 +3134,8 @@ pub const UnionLayout = struct {...@@ -3121,8 +3134,8 @@ pub const UnionLayout = struct {
3121};3134};
31223135
3123/// Returns the index of the active field, given the current tag value3136/// 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 {3137pub fn unionTagFieldIndex(zcu: *const Zcu, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
3125 const ip = &mod.intern_pool;3138 const ip = &zcu.intern_pool;
3126 if (enum_tag.toIntern() == .none) return null;3139 if (enum_tag.toIntern() == .none) return null;
3127 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);3140 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);
3128 return loaded_union.loadTagType(ip).tagValueIndex(ip, enum_tag.toIntern());3141 return loaded_union.loadTagType(ip).tagValueIndex(ip, enum_tag.toIntern());
...@@ -3348,7 +3361,7 @@ pub fn resolveReferences(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolve...@@ -3348,7 +3361,7 @@ pub fn resolveReferences(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolve
3348 return result;3361 return result;
3349}3362}
33503363
3351pub fn fileByIndex(zcu: *Zcu, file_index: File.Index) *File {3364pub fn fileByIndex(zcu: *const Zcu, file_index: File.Index) *File {
3352 return zcu.intern_pool.filePtr(file_index);3365 return zcu.intern_pool.filePtr(file_index);
3353}3366}
33543367
src/Zcu/PerThread.zig+32-172
...@@ -1326,7 +1326,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {...@@ -1326,7 +1326,7 @@ fn semaCau(pt: Zcu.PerThread, cau_index: InternPool.Cau.Index) !SemaCauResult {
1326 try decl_ty.resolveFully(pt);1326 try decl_ty.resolveFully(pt);
1327 }1327 }
13281328
1329 if (!resolve_type or !decl_ty.hasRuntimeBits(pt)) {1329 if (!resolve_type or !decl_ty.hasRuntimeBits(zcu)) {
1330 if (zcu.comp.config.use_llvm) break :queue_codegen;1330 if (zcu.comp.config.use_llvm) break :queue_codegen;
1331 if (file.mod.strip) break :queue_codegen;1331 if (file.mod.strip) break :queue_codegen;
1332 }1332 }
...@@ -1555,8 +1555,8 @@ pub fn embedFile(...@@ -1555,8 +1555,8 @@ pub fn embedFile(
1555 import_string: []const u8,1555 import_string: []const u8,
1556 src_loc: Zcu.LazySrcLoc,1556 src_loc: Zcu.LazySrcLoc,
1557) !InternPool.Index {1557) !InternPool.Index {
1558 const mod = pt.zcu;1558 const zcu = pt.zcu;
1559 const gpa = mod.gpa;1559 const gpa = zcu.gpa;
15601560
1561 if (cur_file.mod.deps.get(import_string)) |pkg| {1561 if (cur_file.mod.deps.get(import_string)) |pkg| {
1562 const resolved_path = try std.fs.path.resolve(gpa, &.{1562 const resolved_path = try std.fs.path.resolve(gpa, &.{
...@@ -1567,9 +1567,9 @@ pub fn embedFile(...@@ -1567,9 +1567,9 @@ pub fn embedFile(
1567 var keep_resolved_path = false;1567 var keep_resolved_path = false;
1568 defer if (!keep_resolved_path) gpa.free(resolved_path);1568 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);
1571 errdefer {1571 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));
1573 keep_resolved_path = false;1573 keep_resolved_path = false;
1574 }1574 }
1575 if (gop.found_existing) return gop.value_ptr.*.val;1575 if (gop.found_existing) return gop.value_ptr.*.val;
...@@ -1594,9 +1594,9 @@ pub fn embedFile(...@@ -1594,9 +1594,9 @@ pub fn embedFile(
1594 var keep_resolved_path = false;1594 var keep_resolved_path = false;
1595 defer if (!keep_resolved_path) gpa.free(resolved_path);1595 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);
1598 errdefer {1598 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));
1600 keep_resolved_path = false;1600 keep_resolved_path = false;
1601 }1601 }
1602 if (gop.found_existing) return gop.value_ptr.*.val;1602 if (gop.found_existing) return gop.value_ptr.*.val;
...@@ -1631,9 +1631,9 @@ fn newEmbedFile(...@@ -1631,9 +1631,9 @@ fn newEmbedFile(
1631 result: **Zcu.EmbedFile,1631 result: **Zcu.EmbedFile,
1632 src_loc: Zcu.LazySrcLoc,1632 src_loc: Zcu.LazySrcLoc,
1633) !InternPool.Index {1633) !InternPool.Index {
1634 const mod = pt.zcu;1634 const zcu = pt.zcu;
1635 const gpa = mod.gpa;1635 const gpa = zcu.gpa;
1636 const ip = &mod.intern_pool;1636 const ip = &zcu.intern_pool;
16371637
1638 const new_file = try gpa.create(Zcu.EmbedFile);1638 const new_file = try gpa.create(Zcu.EmbedFile);
1639 errdefer gpa.destroy(new_file);1639 errdefer gpa.destroy(new_file);
...@@ -1655,7 +1655,7 @@ fn newEmbedFile(...@@ -1655,7 +1655,7 @@ fn newEmbedFile(
1655 if (actual_read != size) return error.UnexpectedEndOfFile;1655 if (actual_read != size) return error.UnexpectedEndOfFile;
1656 bytes[0][size] = 0;1656 bytes[0][size] = 0;
16571657
1658 const comp = mod.comp;1658 const comp = zcu.comp;
1659 switch (comp.cache_use) {1659 switch (comp.cache_use) {
1660 .whole => |whole| if (whole.cache_manifest) |man| {1660 .whole => |whole| if (whole.cache_manifest) |man| {
1661 const copied_resolved_path = try gpa.dupe(u8, resolved_path);1661 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!...@@ -2756,7 +2756,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!
2756 // pointee type needs to be resolved more, that needs to be done before calling2756 // pointee type needs to be resolved more, that needs to be done before calling
2757 // this ptr() function.2757 // this ptr() function.
2758 if (info.flags.alignment != .none and2758 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))
2760 {2760 {
2761 canon_info.flags.alignment = .none;2761 canon_info.flags.alignment = .none;
2762 }2762 }
...@@ -2766,7 +2766,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!...@@ -2766,7 +2766,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!
2766 // we change it to 0 here. If this causes an assertion trip, the pointee type2766 // we change it to 0 here. If this causes an assertion trip, the pointee type
2767 // needs to be resolved before calling this ptr() function.2767 // needs to be resolved before calling this ptr() function.
2768 .none => if (info.packed_offset.host_size != 0) {2768 .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);
2770 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);2770 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);
2771 if (info.packed_offset.host_size * 8 == elem_bit_size) {2771 if (info.packed_offset.host_size * 8 == elem_bit_size) {
2772 canon_info.packed_offset.host_size = 0;2772 canon_info.packed_offset.host_size = 0;
...@@ -2784,7 +2784,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!...@@ -2784,7 +2784,7 @@ pub fn ptrType(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Allocator.Error!
2784/// In general, prefer this function during semantic analysis.2784/// In general, prefer this function during semantic analysis.
2785pub fn ptrTypeSema(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Zcu.SemaError!Type {2785pub fn ptrTypeSema(pt: Zcu.PerThread, info: InternPool.Key.PtrType) Zcu.SemaError!Type {
2786 if (info.flags.alignment != .none) {2786 if (info.flags.alignment != .none) {
2787 _ = try Type.fromInterned(info.child).abiAlignmentAdvanced(pt, .sema);2787 _ = try Type.fromInterned(info.child).abiAlignmentSema(pt);
2788 }2788 }
2789 return pt.ptrType(info);2789 return pt.ptrType(info);
2790}2790}
...@@ -2857,9 +2857,9 @@ pub fn errorSetFromUnsortedNames(...@@ -2857,9 +2857,9 @@ pub fn errorSetFromUnsortedNames(
28572857
2858/// Supports only pointers, not pointer-like optionals.2858/// Supports only pointers, not pointer-like optionals.
2859pub fn ptrIntValue(pt: Zcu.PerThread, ty: Type, x: u64) Allocator.Error!Value {2859pub fn ptrIntValue(pt: Zcu.PerThread, ty: Type, x: u64) Allocator.Error!Value {
2860 const mod = pt.zcu;2860 const zcu = pt.zcu;
2861 assert(ty.zigTypeTag(mod) == .Pointer and !ty.isSlice(mod));2861 assert(ty.zigTypeTag(zcu) == .Pointer and !ty.isSlice(zcu));
2862 assert(x != 0 or ty.isAllowzeroPtr(mod));2862 assert(x != 0 or ty.isAllowzeroPtr(zcu));
2863 return Value.fromInterned(try pt.intern(.{ .ptr = .{2863 return Value.fromInterned(try pt.intern(.{ .ptr = .{
2864 .ty = ty.toIntern(),2864 .ty = ty.toIntern(),
2865 .base_addr = .int,2865 .base_addr = .int,
...@@ -2984,15 +2984,15 @@ pub fn smallestUnsignedInt(pt: Zcu.PerThread, max: u64) Allocator.Error!Type {...@@ -2984,15 +2984,15 @@ pub fn smallestUnsignedInt(pt: Zcu.PerThread, max: u64) Allocator.Error!Type {
2984/// `max`. Asserts that neither value is undef.2984/// `max`. Asserts that neither value is undef.
2985/// TODO: if #3806 is implemented, this becomes trivial2985/// TODO: if #3806 is implemented, this becomes trivial
2986pub fn intFittingRange(pt: Zcu.PerThread, min: Value, max: Value) !Type {2986pub fn intFittingRange(pt: Zcu.PerThread, min: Value, max: Value) !Type {
2987 const mod = pt.zcu;2987 const zcu = pt.zcu;
2988 assert(!min.isUndef(mod));2988 assert(!min.isUndef(zcu));
2989 assert(!max.isUndef(mod));2989 assert(!max.isUndef(zcu));
29902990
2991 if (std.debug.runtime_safety) {2991 if (std.debug.runtime_safety) {
2992 assert(Value.order(min, max, pt).compare(.lte));2992 assert(Value.order(min, max, zcu).compare(.lte));
2993 }2993 }
29942994
2995 const sign = min.orderAgainstZero(pt) == .lt;2995 const sign = min.orderAgainstZero(zcu) == .lt;
29962996
2997 const min_val_bits = pt.intBitsForValue(min, sign);2997 const min_val_bits = pt.intBitsForValue(min, sign);
2998 const max_val_bits = pt.intBitsForValue(max, sign);2998 const max_val_bits = pt.intBitsForValue(max, sign);
...@@ -3008,10 +3008,10 @@ pub fn intFittingRange(pt: Zcu.PerThread, min: Value, max: Value) !Type {...@@ -3008,10 +3008,10 @@ pub fn intFittingRange(pt: Zcu.PerThread, min: Value, max: Value) !Type {
3008/// twos-complement integer; otherwise in an unsigned integer.3008/// twos-complement integer; otherwise in an unsigned integer.
3009/// Asserts that `val` is not undef. If `val` is negative, asserts that `sign` is true.3009/// Asserts that `val` is not undef. If `val` is negative, asserts that `sign` is true.
3010pub fn intBitsForValue(pt: Zcu.PerThread, val: Value, sign: bool) u16 {3010pub fn intBitsForValue(pt: Zcu.PerThread, val: Value, sign: bool) u16 {
3011 const mod = pt.zcu;3011 const zcu = pt.zcu;
3012 assert(!val.isUndef(mod));3012 assert(!val.isUndef(zcu));
30133013
3014 const key = mod.intern_pool.indexToKey(val.toIntern());3014 const key = zcu.intern_pool.indexToKey(val.toIntern());
3015 switch (key.int.storage) {3015 switch (key.int.storage) {
3016 .i64 => |x| {3016 .i64 => |x| {
3017 if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted) + @intFromBool(sign);3017 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 {...@@ -3032,154 +3032,14 @@ pub fn intBitsForValue(pt: Zcu.PerThread, val: Value, sign: bool) u16 {
3032 return @as(u16, @intCast(big.bitCountTwosComp()));3032 return @as(u16, @intCast(big.bitCountTwosComp()));
3033 },3033 },
3034 .lazy_align => |lazy_ty| {3034 .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);
3036 },3036 },
3037 .lazy_size => |lazy_ty| {3037 .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);
3039 },3039 },
3040 }3040 }
3041}3041}
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
3183/// https://github.com/ziglang/zig/issues/17178 explored storing these bit offsets3043/// https://github.com/ziglang/zig/issues/17178 explored storing these bit offsets
3184/// into the packed struct InternPool data rather than computing this on the3044/// into the packed struct InternPool data rather than computing this on the
3185/// fly, however it was found to perform worse when measured on real world3045/// fly, however it was found to perform worse when measured on real world
...@@ -3189,8 +3049,8 @@ pub fn structPackedFieldBitOffset(...@@ -3189,8 +3049,8 @@ pub fn structPackedFieldBitOffset(
3189 struct_type: InternPool.LoadedStructType,3049 struct_type: InternPool.LoadedStructType,
3190 field_index: u32,3050 field_index: u32,
3191) u16 {3051) u16 {
3192 const mod = pt.zcu;3052 const zcu = pt.zcu;
3193 const ip = &mod.intern_pool;3053 const ip = &zcu.intern_pool;
3194 assert(struct_type.layout == .@"packed");3054 assert(struct_type.layout == .@"packed");
3195 assert(struct_type.haveLayout(ip));3055 assert(struct_type.haveLayout(ip));
3196 var bit_sum: u64 = 0;3056 var bit_sum: u64 = 0;
...@@ -3199,7 +3059,7 @@ pub fn structPackedFieldBitOffset(...@@ -3199,7 +3059,7 @@ pub fn structPackedFieldBitOffset(
3199 return @intCast(bit_sum);3059 return @intCast(bit_sum);
3200 }3060 }
3201 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);3061 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);
3203 }3063 }
3204 unreachable; // index out of bounds3064 unreachable; // index out of bounds
3205}3065}
...@@ -3244,7 +3104,7 @@ pub fn navPtrType(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator....@@ -3244,7 +3104,7 @@ pub fn navPtrType(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) Allocator.
3244 return pt.ptrType(.{3104 return pt.ptrType(.{
3245 .child = ty.toIntern(),3105 .child = ty.toIntern(),
3246 .flags = .{3106 .flags = .{
3247 .alignment = if (r.alignment == ty.abiAlignment(pt))3107 .alignment = if (r.alignment == ty.abiAlignment(zcu))
3248 .none3108 .none
3249 else3109 else
3250 r.alignment,3110 r.alignment,
...@@ -3274,7 +3134,7 @@ pub fn navAlignment(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) InternPo...@@ -3274,7 +3134,7 @@ pub fn navAlignment(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) InternPo
3274 const zcu = pt.zcu;3134 const zcu = pt.zcu;
3275 const r = zcu.intern_pool.getNav(nav_index).status.resolved;3135 const r = zcu.intern_pool.getNav(nav_index).status.resolved;
3276 if (r.alignment != .none) return r.alignment;3136 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);
3278}3138}
32793139
3280/// Given a container type requiring resolution, ensures that it is up-to-date.3140/// 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 {...@@ -467,8 +467,8 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
467467
468fn gen(self: *Self) !void {468fn gen(self: *Self) !void {
469 const pt = self.pt;469 const pt = self.pt;
470 const mod = pt.zcu;470 const zcu = pt.zcu;
471 const cc = self.fn_type.fnCallingConvention(mod);471 const cc = self.fn_type.fnCallingConvention(zcu);
472 if (cc != .Naked) {472 if (cc != .Naked) {
473 // stp fp, lr, [sp, #-16]!473 // stp fp, lr, [sp, #-16]!
474 _ = try self.addInst(.{474 _ = try self.addInst(.{
...@@ -517,8 +517,8 @@ fn gen(self: *Self) !void {...@@ -517,8 +517,8 @@ fn gen(self: *Self) !void {
517517
518 const ty = self.typeOfIndex(inst);518 const ty = self.typeOfIndex(inst);
519519
520 const abi_size = @as(u32, @intCast(ty.abiSize(pt)));520 const abi_size = @as(u32, @intCast(ty.abiSize(zcu)));
521 const abi_align = ty.abiAlignment(pt);521 const abi_align = ty.abiAlignment(zcu);
522 const stack_offset = try self.allocMem(abi_size, abi_align, inst);522 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
523 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });523 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
524524
...@@ -648,8 +648,8 @@ fn gen(self: *Self) !void {...@@ -648,8 +648,8 @@ fn gen(self: *Self) !void {
648648
649fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {649fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
650 const pt = self.pt;650 const pt = self.pt;
651 const mod = pt.zcu;651 const zcu = pt.zcu;
652 const ip = &mod.intern_pool;652 const ip = &zcu.intern_pool;
653 const air_tags = self.air.instructions.items(.tag);653 const air_tags = self.air.instructions.items(.tag);
654654
655 for (body) |inst| {655 for (body) |inst| {
...@@ -1016,31 +1016,31 @@ fn allocMem(...@@ -1016,31 +1016,31 @@ fn allocMem(
1016/// Use a pointer instruction as the basis for allocating stack memory.1016/// Use a pointer instruction as the basis for allocating stack memory.
1017fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {1017fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
1018 const pt = self.pt;1018 const pt = self.pt;
1019 const mod = pt.zcu;1019 const zcu = pt.zcu;
1020 const elem_ty = self.typeOfIndex(inst).childType(mod);1020 const elem_ty = self.typeOfIndex(inst).childType(zcu);
10211021
1022 if (!elem_ty.hasRuntimeBits(pt)) {1022 if (!elem_ty.hasRuntimeBits(zcu)) {
1023 // return the stack offset 0. Stack offset 0 will be where all1023 // return the stack offset 0. Stack offset 0 will be where all
1024 // zero-sized stack allocations live as non-zero-sized1024 // zero-sized stack allocations live as non-zero-sized
1025 // allocations will always have an offset > 0.1025 // allocations will always have an offset > 0.
1026 return @as(u32, 0);1026 return @as(u32, 0);
1027 }1027 }
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 {
1030 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});1030 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
1031 };1031 };
1032 // TODO swap this for inst.ty.ptrAlign1032 // TODO swap this for inst.ty.ptrAlign
1033 const abi_align = elem_ty.abiAlignment(pt);1033 const abi_align = elem_ty.abiAlignment(zcu);
10341034
1035 return self.allocMem(abi_size, abi_align, inst);1035 return self.allocMem(abi_size, abi_align, inst);
1036}1036}
10371037
1038fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst.Index) !MCValue {1038fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst.Index) !MCValue {
1039 const pt = self.pt;1039 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 {
1041 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});1041 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
1042 };1042 };
1043 const abi_align = elem_ty.abiAlignment(pt);1043 const abi_align = elem_ty.abiAlignment(pt.zcu);
10441044
1045 if (reg_ok) {1045 if (reg_ok) {
1046 // Make sure the type can fit in a register before we try to allocate one.1046 // 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 {...@@ -1128,13 +1128,13 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
11281128
1129fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {1129fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
1130 const pt = self.pt;1130 const pt = self.pt;
1131 const mod = pt.zcu;1131 const zcu = pt.zcu;
1132 const result: MCValue = switch (self.ret_mcv) {1132 const result: MCValue = switch (self.ret_mcv) {
1133 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },1133 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },
1134 .stack_offset => blk: {1134 .stack_offset => blk: {
1135 // self.ret_mcv is an address to where this function1135 // self.ret_mcv is an address to where this function
1136 // should store its result into1136 // should store its result into
1137 const ret_ty = self.fn_type.fnReturnType(mod);1137 const ret_ty = self.fn_type.fnReturnType(zcu);
1138 const ptr_ty = try pt.singleMutPtrType(ret_ty);1138 const ptr_ty = try pt.singleMutPtrType(ret_ty);
11391139
1140 // addr_reg will contain the address of where to store the1140 // addr_reg will contain the address of where to store the
...@@ -1166,14 +1166,14 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -1166,14 +1166,14 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1166 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });1166 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
11671167
1168 const pt = self.pt;1168 const pt = self.pt;
1169 const mod = pt.zcu;1169 const zcu = pt.zcu;
1170 const operand = ty_op.operand;1170 const operand = ty_op.operand;
1171 const operand_mcv = try self.resolveInst(operand);1171 const operand_mcv = try self.resolveInst(operand);
1172 const operand_ty = self.typeOf(operand);1172 const operand_ty = self.typeOf(operand);
1173 const operand_info = operand_ty.intInfo(mod);1173 const operand_info = operand_ty.intInfo(zcu);
11741174
1175 const dest_ty = self.typeOfIndex(inst);1175 const dest_ty = self.typeOfIndex(inst);
1176 const dest_info = dest_ty.intInfo(mod);1176 const dest_info = dest_ty.intInfo(zcu);
11771177
1178 const result: MCValue = result: {1178 const result: MCValue = result: {
1179 const operand_lock: ?RegisterLock = switch (operand_mcv) {1179 const operand_lock: ?RegisterLock = switch (operand_mcv) {
...@@ -1248,9 +1248,9 @@ fn trunc(...@@ -1248,9 +1248,9 @@ fn trunc(
1248 dest_ty: Type,1248 dest_ty: Type,
1249) !MCValue {1249) !MCValue {
1250 const pt = self.pt;1250 const pt = self.pt;
1251 const mod = pt.zcu;1251 const zcu = pt.zcu;
1252 const info_a = operand_ty.intInfo(mod);1252 const info_a = operand_ty.intInfo(zcu);
1253 const info_b = dest_ty.intInfo(mod);1253 const info_b = dest_ty.intInfo(zcu);
12541254
1255 if (info_b.bits <= 64) {1255 if (info_b.bits <= 64) {
1256 const operand_reg = switch (operand) {1256 const operand_reg = switch (operand) {
...@@ -1312,7 +1312,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {...@@ -1312,7 +1312,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
1312fn airNot(self: *Self, inst: Air.Inst.Index) !void {1312fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1313 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1313 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1314 const pt = self.pt;1314 const pt = self.pt;
1315 const mod = pt.zcu;1315 const zcu = pt.zcu;
1316 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1316 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1317 const operand = try self.resolveInst(ty_op.operand);1317 const operand = try self.resolveInst(ty_op.operand);
1318 const operand_ty = self.typeOf(ty_op.operand);1318 const operand_ty = self.typeOf(ty_op.operand);
...@@ -1321,7 +1321,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {...@@ -1321,7 +1321,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1321 .unreach => unreachable,1321 .unreach => unreachable,
1322 .compare_flags => |cond| break :result MCValue{ .compare_flags = cond.negate() },1322 .compare_flags => |cond| break :result MCValue{ .compare_flags = cond.negate() },
1323 else => {1323 else => {
1324 switch (operand_ty.zigTypeTag(mod)) {1324 switch (operand_ty.zigTypeTag(zcu)) {
1325 .Bool => {1325 .Bool => {
1326 // TODO convert this to mvn + and1326 // TODO convert this to mvn + and
1327 const op_reg = switch (operand) {1327 const op_reg = switch (operand) {
...@@ -1355,7 +1355,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {...@@ -1355,7 +1355,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1355 },1355 },
1356 .Vector => return self.fail("TODO bitwise not for vectors", .{}),1356 .Vector => return self.fail("TODO bitwise not for vectors", .{}),
1357 .Int => {1357 .Int => {
1358 const int_info = operand_ty.intInfo(mod);1358 const int_info = operand_ty.intInfo(zcu);
1359 if (int_info.bits <= 64) {1359 if (int_info.bits <= 64) {
1360 const op_reg = switch (operand) {1360 const op_reg = switch (operand) {
1361 .register => |r| r,1361 .register => |r| r,
...@@ -1408,13 +1408,13 @@ fn minMax(...@@ -1408,13 +1408,13 @@ fn minMax(
1408 maybe_inst: ?Air.Inst.Index,1408 maybe_inst: ?Air.Inst.Index,
1409) !MCValue {1409) !MCValue {
1410 const pt = self.pt;1410 const pt = self.pt;
1411 const mod = pt.zcu;1411 const zcu = pt.zcu;
1412 switch (lhs_ty.zigTypeTag(mod)) {1412 switch (lhs_ty.zigTypeTag(zcu)) {
1413 .Float => return self.fail("TODO ARM min/max on floats", .{}),1413 .Float => return self.fail("TODO ARM min/max on floats", .{}),
1414 .Vector => return self.fail("TODO ARM min/max on vectors", .{}),1414 .Vector => return self.fail("TODO ARM min/max on vectors", .{}),
1415 .Int => {1415 .Int => {
1416 assert(lhs_ty.eql(rhs_ty, mod));1416 assert(lhs_ty.eql(rhs_ty, zcu));
1417 const int_info = lhs_ty.intInfo(mod);1417 const int_info = lhs_ty.intInfo(zcu);
1418 if (int_info.bits <= 64) {1418 if (int_info.bits <= 64) {
1419 var lhs_reg: Register = undefined;1419 var lhs_reg: Register = undefined;
1420 var rhs_reg: Register = undefined;1420 var rhs_reg: Register = undefined;
...@@ -1899,13 +1899,13 @@ fn addSub(...@@ -1899,13 +1899,13 @@ fn addSub(
1899 maybe_inst: ?Air.Inst.Index,1899 maybe_inst: ?Air.Inst.Index,
1900) InnerError!MCValue {1900) InnerError!MCValue {
1901 const pt = self.pt;1901 const pt = self.pt;
1902 const mod = pt.zcu;1902 const zcu = pt.zcu;
1903 switch (lhs_ty.zigTypeTag(mod)) {1903 switch (lhs_ty.zigTypeTag(zcu)) {
1904 .Float => return self.fail("TODO binary operations on floats", .{}),1904 .Float => return self.fail("TODO binary operations on floats", .{}),
1905 .Vector => return self.fail("TODO binary operations on vectors", .{}),1905 .Vector => return self.fail("TODO binary operations on vectors", .{}),
1906 .Int => {1906 .Int => {
1907 assert(lhs_ty.eql(rhs_ty, mod));1907 assert(lhs_ty.eql(rhs_ty, zcu));
1908 const int_info = lhs_ty.intInfo(mod);1908 const int_info = lhs_ty.intInfo(zcu);
1909 if (int_info.bits <= 64) {1909 if (int_info.bits <= 64) {
1910 const lhs_immediate = try lhs_bind.resolveToImmediate(self);1910 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
1911 const rhs_immediate = try rhs_bind.resolveToImmediate(self);1911 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
...@@ -1961,12 +1961,12 @@ fn mul(...@@ -1961,12 +1961,12 @@ fn mul(
1961 maybe_inst: ?Air.Inst.Index,1961 maybe_inst: ?Air.Inst.Index,
1962) InnerError!MCValue {1962) InnerError!MCValue {
1963 const pt = self.pt;1963 const pt = self.pt;
1964 const mod = pt.zcu;1964 const zcu = pt.zcu;
1965 switch (lhs_ty.zigTypeTag(mod)) {1965 switch (lhs_ty.zigTypeTag(zcu)) {
1966 .Vector => return self.fail("TODO binary operations on vectors", .{}),1966 .Vector => return self.fail("TODO binary operations on vectors", .{}),
1967 .Int => {1967 .Int => {
1968 assert(lhs_ty.eql(rhs_ty, mod));1968 assert(lhs_ty.eql(rhs_ty, zcu));
1969 const int_info = lhs_ty.intInfo(mod);1969 const int_info = lhs_ty.intInfo(zcu);
1970 if (int_info.bits <= 64) {1970 if (int_info.bits <= 64) {
1971 // TODO add optimisations for multiplication1971 // TODO add optimisations for multiplication
1972 // with immediates, for example a * 2 can be1972 // with immediates, for example a * 2 can be
...@@ -1994,8 +1994,8 @@ fn divFloat(...@@ -1994,8 +1994,8 @@ fn divFloat(
1994 _ = maybe_inst;1994 _ = maybe_inst;
19951995
1996 const pt = self.pt;1996 const pt = self.pt;
1997 const mod = pt.zcu;1997 const zcu = pt.zcu;
1998 switch (lhs_ty.zigTypeTag(mod)) {1998 switch (lhs_ty.zigTypeTag(zcu)) {
1999 .Float => return self.fail("TODO div_float", .{}),1999 .Float => return self.fail("TODO div_float", .{}),
2000 .Vector => return self.fail("TODO div_float on vectors", .{}),2000 .Vector => return self.fail("TODO div_float on vectors", .{}),
2001 else => unreachable,2001 else => unreachable,
...@@ -2011,13 +2011,13 @@ fn divTrunc(...@@ -2011,13 +2011,13 @@ fn divTrunc(
2011 maybe_inst: ?Air.Inst.Index,2011 maybe_inst: ?Air.Inst.Index,
2012) InnerError!MCValue {2012) InnerError!MCValue {
2013 const pt = self.pt;2013 const pt = self.pt;
2014 const mod = pt.zcu;2014 const zcu = pt.zcu;
2015 switch (lhs_ty.zigTypeTag(mod)) {2015 switch (lhs_ty.zigTypeTag(zcu)) {
2016 .Float => return self.fail("TODO div on floats", .{}),2016 .Float => return self.fail("TODO div on floats", .{}),
2017 .Vector => return self.fail("TODO div on vectors", .{}),2017 .Vector => return self.fail("TODO div on vectors", .{}),
2018 .Int => {2018 .Int => {
2019 assert(lhs_ty.eql(rhs_ty, mod));2019 assert(lhs_ty.eql(rhs_ty, zcu));
2020 const int_info = lhs_ty.intInfo(mod);2020 const int_info = lhs_ty.intInfo(zcu);
2021 if (int_info.bits <= 64) {2021 if (int_info.bits <= 64) {
2022 switch (int_info.signedness) {2022 switch (int_info.signedness) {
2023 .signed => {2023 .signed => {
...@@ -2046,13 +2046,13 @@ fn divFloor(...@@ -2046,13 +2046,13 @@ fn divFloor(
2046 maybe_inst: ?Air.Inst.Index,2046 maybe_inst: ?Air.Inst.Index,
2047) InnerError!MCValue {2047) InnerError!MCValue {
2048 const pt = self.pt;2048 const pt = self.pt;
2049 const mod = pt.zcu;2049 const zcu = pt.zcu;
2050 switch (lhs_ty.zigTypeTag(mod)) {2050 switch (lhs_ty.zigTypeTag(zcu)) {
2051 .Float => return self.fail("TODO div on floats", .{}),2051 .Float => return self.fail("TODO div on floats", .{}),
2052 .Vector => return self.fail("TODO div on vectors", .{}),2052 .Vector => return self.fail("TODO div on vectors", .{}),
2053 .Int => {2053 .Int => {
2054 assert(lhs_ty.eql(rhs_ty, mod));2054 assert(lhs_ty.eql(rhs_ty, zcu));
2055 const int_info = lhs_ty.intInfo(mod);2055 const int_info = lhs_ty.intInfo(zcu);
2056 if (int_info.bits <= 64) {2056 if (int_info.bits <= 64) {
2057 switch (int_info.signedness) {2057 switch (int_info.signedness) {
2058 .signed => {2058 .signed => {
...@@ -2080,13 +2080,13 @@ fn divExact(...@@ -2080,13 +2080,13 @@ fn divExact(
2080 maybe_inst: ?Air.Inst.Index,2080 maybe_inst: ?Air.Inst.Index,
2081) InnerError!MCValue {2081) InnerError!MCValue {
2082 const pt = self.pt;2082 const pt = self.pt;
2083 const mod = pt.zcu;2083 const zcu = pt.zcu;
2084 switch (lhs_ty.zigTypeTag(mod)) {2084 switch (lhs_ty.zigTypeTag(zcu)) {
2085 .Float => return self.fail("TODO div on floats", .{}),2085 .Float => return self.fail("TODO div on floats", .{}),
2086 .Vector => return self.fail("TODO div on vectors", .{}),2086 .Vector => return self.fail("TODO div on vectors", .{}),
2087 .Int => {2087 .Int => {
2088 assert(lhs_ty.eql(rhs_ty, mod));2088 assert(lhs_ty.eql(rhs_ty, zcu));
2089 const int_info = lhs_ty.intInfo(mod);2089 const int_info = lhs_ty.intInfo(zcu);
2090 if (int_info.bits <= 64) {2090 if (int_info.bits <= 64) {
2091 switch (int_info.signedness) {2091 switch (int_info.signedness) {
2092 .signed => {2092 .signed => {
...@@ -2117,13 +2117,13 @@ fn rem(...@@ -2117,13 +2117,13 @@ fn rem(
2117 _ = maybe_inst;2117 _ = maybe_inst;
21182118
2119 const pt = self.pt;2119 const pt = self.pt;
2120 const mod = pt.zcu;2120 const zcu = pt.zcu;
2121 switch (lhs_ty.zigTypeTag(mod)) {2121 switch (lhs_ty.zigTypeTag(zcu)) {
2122 .Float => return self.fail("TODO rem/mod on floats", .{}),2122 .Float => return self.fail("TODO rem/zcu on floats", .{}),
2123 .Vector => return self.fail("TODO rem/mod on vectors", .{}),2123 .Vector => return self.fail("TODO rem/zcu on vectors", .{}),
2124 .Int => {2124 .Int => {
2125 assert(lhs_ty.eql(rhs_ty, mod));2125 assert(lhs_ty.eql(rhs_ty, zcu));
2126 const int_info = lhs_ty.intInfo(mod);2126 const int_info = lhs_ty.intInfo(zcu);
2127 if (int_info.bits <= 64) {2127 if (int_info.bits <= 64) {
2128 var lhs_reg: Register = undefined;2128 var lhs_reg: Register = undefined;
2129 var rhs_reg: Register = undefined;2129 var rhs_reg: Register = undefined;
...@@ -2168,7 +2168,7 @@ fn rem(...@@ -2168,7 +2168,7 @@ fn rem(
21682168
2169 return MCValue{ .register = remainder_reg };2169 return MCValue{ .register = remainder_reg };
2170 } else {2170 } 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", .{});
2172 }2172 }
2173 },2173 },
2174 else => unreachable,2174 else => unreachable,
...@@ -2189,11 +2189,11 @@ fn modulo(...@@ -2189,11 +2189,11 @@ fn modulo(
2189 _ = maybe_inst;2189 _ = maybe_inst;
21902190
2191 const pt = self.pt;2191 const pt = self.pt;
2192 const mod = pt.zcu;2192 const zcu = pt.zcu;
2193 switch (lhs_ty.zigTypeTag(mod)) {2193 switch (lhs_ty.zigTypeTag(zcu)) {
2194 .Float => return self.fail("TODO mod on floats", .{}),2194 .Float => return self.fail("TODO zcu on floats", .{}),
2195 .Vector => return self.fail("TODO mod on vectors", .{}),2195 .Vector => return self.fail("TODO zcu on vectors", .{}),
2196 .Int => return self.fail("TODO mod on ints", .{}),2196 .Int => return self.fail("TODO zcu on ints", .{}),
2197 else => unreachable,2197 else => unreachable,
2198 }2198 }
2199}2199}
...@@ -2208,11 +2208,11 @@ fn wrappingArithmetic(...@@ -2208,11 +2208,11 @@ fn wrappingArithmetic(
2208 maybe_inst: ?Air.Inst.Index,2208 maybe_inst: ?Air.Inst.Index,
2209) InnerError!MCValue {2209) InnerError!MCValue {
2210 const pt = self.pt;2210 const pt = self.pt;
2211 const mod = pt.zcu;2211 const zcu = pt.zcu;
2212 switch (lhs_ty.zigTypeTag(mod)) {2212 switch (lhs_ty.zigTypeTag(zcu)) {
2213 .Vector => return self.fail("TODO binary operations on vectors", .{}),2213 .Vector => return self.fail("TODO binary operations on vectors", .{}),
2214 .Int => {2214 .Int => {
2215 const int_info = lhs_ty.intInfo(mod);2215 const int_info = lhs_ty.intInfo(zcu);
2216 if (int_info.bits <= 64) {2216 if (int_info.bits <= 64) {
2217 // Generate an add/sub/mul2217 // Generate an add/sub/mul
2218 const result: MCValue = switch (tag) {2218 const result: MCValue = switch (tag) {
...@@ -2244,12 +2244,12 @@ fn bitwise(...@@ -2244,12 +2244,12 @@ fn bitwise(
2244 maybe_inst: ?Air.Inst.Index,2244 maybe_inst: ?Air.Inst.Index,
2245) InnerError!MCValue {2245) InnerError!MCValue {
2246 const pt = self.pt;2246 const pt = self.pt;
2247 const mod = pt.zcu;2247 const zcu = pt.zcu;
2248 switch (lhs_ty.zigTypeTag(mod)) {2248 switch (lhs_ty.zigTypeTag(zcu)) {
2249 .Vector => return self.fail("TODO binary operations on vectors", .{}),2249 .Vector => return self.fail("TODO binary operations on vectors", .{}),
2250 .Int => {2250 .Int => {
2251 assert(lhs_ty.eql(rhs_ty, mod));2251 assert(lhs_ty.eql(rhs_ty, zcu));
2252 const int_info = lhs_ty.intInfo(mod);2252 const int_info = lhs_ty.intInfo(zcu);
2253 if (int_info.bits <= 64) {2253 if (int_info.bits <= 64) {
2254 // TODO implement bitwise operations with immediates2254 // TODO implement bitwise operations with immediates
2255 const mir_tag: Mir.Inst.Tag = switch (tag) {2255 const mir_tag: Mir.Inst.Tag = switch (tag) {
...@@ -2280,11 +2280,11 @@ fn shiftExact(...@@ -2280,11 +2280,11 @@ fn shiftExact(
2280 _ = rhs_ty;2280 _ = rhs_ty;
22812281
2282 const pt = self.pt;2282 const pt = self.pt;
2283 const mod = pt.zcu;2283 const zcu = pt.zcu;
2284 switch (lhs_ty.zigTypeTag(mod)) {2284 switch (lhs_ty.zigTypeTag(zcu)) {
2285 .Vector => return self.fail("TODO binary operations on vectors", .{}),2285 .Vector => return self.fail("TODO binary operations on vectors", .{}),
2286 .Int => {2286 .Int => {
2287 const int_info = lhs_ty.intInfo(mod);2287 const int_info = lhs_ty.intInfo(zcu);
2288 if (int_info.bits <= 64) {2288 if (int_info.bits <= 64) {
2289 const rhs_immediate = try rhs_bind.resolveToImmediate(self);2289 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
22902290
...@@ -2331,11 +2331,11 @@ fn shiftNormal(...@@ -2331,11 +2331,11 @@ fn shiftNormal(
2331 maybe_inst: ?Air.Inst.Index,2331 maybe_inst: ?Air.Inst.Index,
2332) InnerError!MCValue {2332) InnerError!MCValue {
2333 const pt = self.pt;2333 const pt = self.pt;
2334 const mod = pt.zcu;2334 const zcu = pt.zcu;
2335 switch (lhs_ty.zigTypeTag(mod)) {2335 switch (lhs_ty.zigTypeTag(zcu)) {
2336 .Vector => return self.fail("TODO binary operations on vectors", .{}),2336 .Vector => return self.fail("TODO binary operations on vectors", .{}),
2337 .Int => {2337 .Int => {
2338 const int_info = lhs_ty.intInfo(mod);2338 const int_info = lhs_ty.intInfo(zcu);
2339 if (int_info.bits <= 64) {2339 if (int_info.bits <= 64) {
2340 // Generate a shl_exact/shr_exact2340 // Generate a shl_exact/shr_exact
2341 const result: MCValue = switch (tag) {2341 const result: MCValue = switch (tag) {
...@@ -2372,8 +2372,8 @@ fn booleanOp(...@@ -2372,8 +2372,8 @@ fn booleanOp(
2372 maybe_inst: ?Air.Inst.Index,2372 maybe_inst: ?Air.Inst.Index,
2373) InnerError!MCValue {2373) InnerError!MCValue {
2374 const pt = self.pt;2374 const pt = self.pt;
2375 const mod = pt.zcu;2375 const zcu = pt.zcu;
2376 switch (lhs_ty.zigTypeTag(mod)) {2376 switch (lhs_ty.zigTypeTag(zcu)) {
2377 .Bool => {2377 .Bool => {
2378 assert((try lhs_bind.resolveToImmediate(self)) == null); // should have been handled by Sema2378 assert((try lhs_bind.resolveToImmediate(self)) == null); // should have been handled by Sema
2379 assert((try rhs_bind.resolveToImmediate(self)) == null); // should have been handled by Sema2379 assert((try rhs_bind.resolveToImmediate(self)) == null); // should have been handled by Sema
...@@ -2400,17 +2400,17 @@ fn ptrArithmetic(...@@ -2400,17 +2400,17 @@ fn ptrArithmetic(
2400 maybe_inst: ?Air.Inst.Index,2400 maybe_inst: ?Air.Inst.Index,
2401) InnerError!MCValue {2401) InnerError!MCValue {
2402 const pt = self.pt;2402 const pt = self.pt;
2403 const mod = pt.zcu;2403 const zcu = pt.zcu;
2404 switch (lhs_ty.zigTypeTag(mod)) {2404 switch (lhs_ty.zigTypeTag(zcu)) {
2405 .Pointer => {2405 .Pointer => {
2406 assert(rhs_ty.eql(Type.usize, mod));2406 assert(rhs_ty.eql(Type.usize, zcu));
24072407
2408 const ptr_ty = lhs_ty;2408 const ptr_ty = lhs_ty;
2409 const elem_ty = switch (ptr_ty.ptrSize(mod)) {2409 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
2410 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type2410 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
2411 else => ptr_ty.childType(mod),2411 else => ptr_ty.childType(zcu),
2412 };2412 };
2413 const elem_size = elem_ty.abiSize(pt);2413 const elem_size = elem_ty.abiSize(zcu);
24142414
2415 const base_tag: Air.Inst.Tag = switch (tag) {2415 const base_tag: Air.Inst.Tag = switch (tag) {
2416 .ptr_add => .add,2416 .ptr_add => .add,
...@@ -2524,7 +2524,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2524,7 +2524,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
2524 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2524 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2525 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2525 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2526 const pt = self.pt;2526 const pt = self.pt;
2527 const mod = pt.zcu;2527 const zcu = pt.zcu;
2528 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2528 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2529 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };2529 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
2530 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };2530 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
...@@ -2532,15 +2532,15 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2532,15 +2532,15 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
2532 const rhs_ty = self.typeOf(extra.rhs);2532 const rhs_ty = self.typeOf(extra.rhs);
25332533
2534 const tuple_ty = self.typeOfIndex(inst);2534 const tuple_ty = self.typeOfIndex(inst);
2535 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(pt)));2535 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(zcu)));
2536 const tuple_align = tuple_ty.abiAlignment(pt);2536 const tuple_align = tuple_ty.abiAlignment(zcu);
2537 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, pt)));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)) {
2540 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),2540 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
2541 .Int => {2541 .Int => {
2542 assert(lhs_ty.eql(rhs_ty, mod));2542 assert(lhs_ty.eql(rhs_ty, zcu));
2543 const int_info = lhs_ty.intInfo(mod);2543 const int_info = lhs_ty.intInfo(zcu);
2544 switch (int_info.bits) {2544 switch (int_info.bits) {
2545 1...31, 33...63 => {2545 1...31, 33...63 => {
2546 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);2546 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);
...@@ -2652,8 +2652,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2652,8 +2652,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2652 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2652 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2653 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2653 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2654 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });2654 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
2655 const pt = self.pt;2655 const zcu = self.pt.zcu;
2656 const mod = pt.zcu;
2657 const result: MCValue = result: {2656 const result: MCValue = result: {
2658 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };2657 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
2659 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };2658 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
...@@ -2661,15 +2660,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2661,15 +2660,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2661 const rhs_ty = self.typeOf(extra.rhs);2660 const rhs_ty = self.typeOf(extra.rhs);
26622661
2663 const tuple_ty = self.typeOfIndex(inst);2662 const tuple_ty = self.typeOfIndex(inst);
2664 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(pt)));2663 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(zcu)));
2665 const tuple_align = tuple_ty.abiAlignment(pt);2664 const tuple_align = tuple_ty.abiAlignment(zcu);
2666 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, pt)));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)) {
2669 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),2668 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
2670 .Int => {2669 .Int => {
2671 assert(lhs_ty.eql(rhs_ty, mod));2670 assert(lhs_ty.eql(rhs_ty, zcu));
2672 const int_info = lhs_ty.intInfo(mod);2671 const int_info = lhs_ty.intInfo(zcu);
2673 if (int_info.bits <= 32) {2672 if (int_info.bits <= 32) {
2674 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);2673 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 {...@@ -2878,7 +2877,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2878 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2877 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2879 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });2878 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
2880 const pt = self.pt;2879 const pt = self.pt;
2881 const mod = pt.zcu;2880 const zcu = pt.zcu;
2882 const result: MCValue = result: {2881 const result: MCValue = result: {
2883 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };2882 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
2884 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };2883 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
...@@ -2886,14 +2885,14 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2886,14 +2885,14 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2886 const rhs_ty = self.typeOf(extra.rhs);2885 const rhs_ty = self.typeOf(extra.rhs);
28872886
2888 const tuple_ty = self.typeOfIndex(inst);2887 const tuple_ty = self.typeOfIndex(inst);
2889 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(pt)));2888 const tuple_size = @as(u32, @intCast(tuple_ty.abiSize(zcu)));
2890 const tuple_align = tuple_ty.abiAlignment(pt);2889 const tuple_align = tuple_ty.abiAlignment(zcu);
2891 const overflow_bit_offset = @as(u32, @intCast(tuple_ty.structFieldOffset(1, pt)));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)) {
2894 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),2893 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
2895 .Int => {2894 .Int => {
2896 const int_info = lhs_ty.intInfo(mod);2895 const int_info = lhs_ty.intInfo(zcu);
2897 if (int_info.bits <= 64) {2896 if (int_info.bits <= 64) {
2898 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);2897 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 {...@@ -3027,10 +3026,10 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
30273026
3028fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty: Type) !MCValue {3027fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty: Type) !MCValue {
3029 const pt = self.pt;3028 const pt = self.pt;
3030 const mod = pt.zcu;3029 const zcu = pt.zcu;
3031 const payload_ty = optional_ty.optionalChild(mod);3030 const payload_ty = optional_ty.optionalChild(zcu);
3032 if (!payload_ty.hasRuntimeBits(pt)) return MCValue.none;3031 if (!payload_ty.hasRuntimeBits(zcu)) return MCValue.none;
3033 if (optional_ty.isPtrLikeOptional(mod)) {3032 if (optional_ty.isPtrLikeOptional(zcu)) {
3034 // TODO should we reuse the operand here?3033 // TODO should we reuse the operand here?
3035 const raw_reg = try self.register_manager.allocReg(inst, gp);3034 const raw_reg = try self.register_manager.allocReg(inst, gp);
3036 const reg = self.registerAlias(raw_reg, payload_ty);3035 const reg = self.registerAlias(raw_reg, payload_ty);
...@@ -3072,17 +3071,17 @@ fn errUnionErr(...@@ -3072,17 +3071,17 @@ fn errUnionErr(
3072 maybe_inst: ?Air.Inst.Index,3071 maybe_inst: ?Air.Inst.Index,
3073) !MCValue {3072) !MCValue {
3074 const pt = self.pt;3073 const pt = self.pt;
3075 const mod = pt.zcu;3074 const zcu = pt.zcu;
3076 const err_ty = error_union_ty.errorUnionSet(mod);3075 const err_ty = error_union_ty.errorUnionSet(zcu);
3077 const payload_ty = error_union_ty.errorUnionPayload(mod);3076 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3078 if (err_ty.errorSetIsEmpty(mod)) {3077 if (err_ty.errorSetIsEmpty(zcu)) {
3079 return MCValue{ .immediate = 0 };3078 return MCValue{ .immediate = 0 };
3080 }3079 }
3081 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {3080 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3082 return try error_union_bind.resolveToMcv(self);3081 return try error_union_bind.resolveToMcv(self);
3083 }3082 }
30843083
3085 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, pt));3084 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, zcu));
3086 switch (try error_union_bind.resolveToMcv(self)) {3085 switch (try error_union_bind.resolveToMcv(self)) {
3087 .register => {3086 .register => {
3088 var operand_reg: Register = undefined;3087 var operand_reg: Register = undefined;
...@@ -3104,7 +3103,7 @@ fn errUnionErr(...@@ -3104,7 +3103,7 @@ fn errUnionErr(
3104 );3103 );
31053104
3106 const err_bit_offset = err_offset * 8;3105 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
3109 _ = try self.addInst(.{3108 _ = try self.addInst(.{
3110 .tag = .ubfx, // errors are unsigned integers3109 .tag = .ubfx, // errors are unsigned integers
...@@ -3153,17 +3152,17 @@ fn errUnionPayload(...@@ -3153,17 +3152,17 @@ fn errUnionPayload(
3153 maybe_inst: ?Air.Inst.Index,3152 maybe_inst: ?Air.Inst.Index,
3154) !MCValue {3153) !MCValue {
3155 const pt = self.pt;3154 const pt = self.pt;
3156 const mod = pt.zcu;3155 const zcu = pt.zcu;
3157 const err_ty = error_union_ty.errorUnionSet(mod);3156 const err_ty = error_union_ty.errorUnionSet(zcu);
3158 const payload_ty = error_union_ty.errorUnionPayload(mod);3157 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3159 if (err_ty.errorSetIsEmpty(mod)) {3158 if (err_ty.errorSetIsEmpty(zcu)) {
3160 return try error_union_bind.resolveToMcv(self);3159 return try error_union_bind.resolveToMcv(self);
3161 }3160 }
3162 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {3161 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3163 return MCValue.none;3162 return MCValue.none;
3164 }3163 }
31653164
3166 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt)));3165 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu)));
3167 switch (try error_union_bind.resolveToMcv(self)) {3166 switch (try error_union_bind.resolveToMcv(self)) {
3168 .register => {3167 .register => {
3169 var operand_reg: Register = undefined;3168 var operand_reg: Register = undefined;
...@@ -3185,10 +3184,10 @@ fn errUnionPayload(...@@ -3185,10 +3184,10 @@ fn errUnionPayload(
3185 );3184 );
31863185
3187 const payload_bit_offset = payload_offset * 8;3186 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
3190 _ = try self.addInst(.{3189 _ = 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,
3192 .data = .{3191 .data = .{
3193 .rr_lsb_width = .{3192 .rr_lsb_width = .{
3194 // Set both registers to the X variant to get the full width3193 // 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 {...@@ -3266,7 +3265,7 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
32663265
3267fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {3266fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3268 const pt = self.pt;3267 const pt = self.pt;
3269 const mod = pt.zcu;3268 const zcu = pt.zcu;
3270 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3269 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
32713270
3272 if (self.liveness.isUnused(inst)) {3271 if (self.liveness.isUnused(inst)) {
...@@ -3275,7 +3274,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -3275,7 +3274,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
32753274
3276 const result: MCValue = result: {3275 const result: MCValue = result: {
3277 const payload_ty = self.typeOf(ty_op.operand);3276 const payload_ty = self.typeOf(ty_op.operand);
3278 if (!payload_ty.hasRuntimeBits(pt)) {3277 if (!payload_ty.hasRuntimeBits(zcu)) {
3279 break :result MCValue{ .immediate = 1 };3278 break :result MCValue{ .immediate = 1 };
3280 }3279 }
32813280
...@@ -3287,7 +3286,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -3287,7 +3286,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3287 };3286 };
3288 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);3287 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);
32893288
3290 if (optional_ty.isPtrLikeOptional(mod)) {3289 if (optional_ty.isPtrLikeOptional(zcu)) {
3291 // TODO should we check if we can reuse the operand?3290 // TODO should we check if we can reuse the operand?
3292 const raw_reg = try self.register_manager.allocReg(inst, gp);3291 const raw_reg = try self.register_manager.allocReg(inst, gp);
3293 const reg = self.registerAlias(raw_reg, payload_ty);3292 const reg = self.registerAlias(raw_reg, payload_ty);
...@@ -3295,9 +3294,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -3295,9 +3294,9 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3295 break :result MCValue{ .register = reg };3294 break :result MCValue{ .register = reg };
3296 }3295 }
32973296
3298 const optional_abi_size: u32 = @intCast(optional_ty.abiSize(pt));3297 const optional_abi_size: u32 = @intCast(optional_ty.abiSize(zcu));
3299 const optional_abi_align = optional_ty.abiAlignment(pt);3298 const optional_abi_align = optional_ty.abiAlignment(zcu);
3300 const offset: u32 = @intCast(payload_ty.abiSize(pt));3299 const offset: u32 = @intCast(payload_ty.abiSize(zcu));
33013300
3302 const stack_offset = try self.allocMem(optional_abi_size, optional_abi_align, inst);3301 const stack_offset = try self.allocMem(optional_abi_size, optional_abi_align, inst);
3303 try self.genSetStack(payload_ty, stack_offset, operand);3302 try self.genSetStack(payload_ty, stack_offset, operand);
...@@ -3312,20 +3311,20 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -3312,20 +3311,20 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
3312/// T to E!T3311/// T to E!T
3313fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {3312fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
3314 const pt = self.pt;3313 const pt = self.pt;
3315 const mod = pt.zcu;3314 const zcu = pt.zcu;
3316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3315 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3317 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3316 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3318 const error_union_ty = ty_op.ty.toType();3317 const error_union_ty = ty_op.ty.toType();
3319 const error_ty = error_union_ty.errorUnionSet(mod);3318 const error_ty = error_union_ty.errorUnionSet(zcu);
3320 const payload_ty = error_union_ty.errorUnionPayload(mod);3319 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3321 const operand = try self.resolveInst(ty_op.operand);3320 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)));3323 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(zcu)));
3325 const abi_align = error_union_ty.abiAlignment(pt);3324 const abi_align = error_union_ty.abiAlignment(zcu);
3326 const stack_offset = try self.allocMem(abi_size, abi_align, inst);3325 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
3327 const payload_off = errUnionPayloadOffset(payload_ty, pt);3326 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
3328 const err_off = errUnionErrorOffset(payload_ty, pt);3327 const err_off = errUnionErrorOffset(payload_ty, zcu);
3329 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);3328 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
3330 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });3329 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 {...@@ -3339,18 +3338,18 @@ fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
3339 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3338 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3340 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3339 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3341 const pt = self.pt;3340 const pt = self.pt;
3342 const mod = pt.zcu;3341 const zcu = pt.zcu;
3343 const error_union_ty = ty_op.ty.toType();3342 const error_union_ty = ty_op.ty.toType();
3344 const error_ty = error_union_ty.errorUnionSet(mod);3343 const error_ty = error_union_ty.errorUnionSet(zcu);
3345 const payload_ty = error_union_ty.errorUnionPayload(mod);3344 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3346 const operand = try self.resolveInst(ty_op.operand);3345 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)));3348 const abi_size = @as(u32, @intCast(error_union_ty.abiSize(zcu)));
3350 const abi_align = error_union_ty.abiAlignment(pt);3349 const abi_align = error_union_ty.abiAlignment(zcu);
3351 const stack_offset = try self.allocMem(abi_size, abi_align, inst);3350 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
3352 const payload_off = errUnionPayloadOffset(payload_ty, pt);3351 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
3353 const err_off = errUnionErrorOffset(payload_ty, pt);3352 const err_off = errUnionErrorOffset(payload_ty, zcu);
3354 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);3353 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
3355 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);3354 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 {...@@ -3443,11 +3442,11 @@ fn airPtrSlicePtrPtr(self: *Self, inst: Air.Inst.Index) !void {
34433442
3444fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {3443fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
3445 const pt = self.pt;3444 const pt = self.pt;
3446 const mod = pt.zcu;3445 const zcu = pt.zcu;
3447 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3446 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3448 const slice_ty = self.typeOf(bin_op.lhs);3447 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: {3448 const result: MCValue = if (!slice_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) .dead else result: {
3450 const ptr_ty = slice_ty.slicePtrFieldType(mod);3449 const ptr_ty = slice_ty.slicePtrFieldType(zcu);
34513450
3452 const slice_mcv = try self.resolveInst(bin_op.lhs);3451 const slice_mcv = try self.resolveInst(bin_op.lhs);
3453 const base_mcv = slicePtr(slice_mcv);3452 const base_mcv = slicePtr(slice_mcv);
...@@ -3468,9 +3467,9 @@ fn ptrElemVal(...@@ -3468,9 +3467,9 @@ fn ptrElemVal(
3468 maybe_inst: ?Air.Inst.Index,3467 maybe_inst: ?Air.Inst.Index,
3469) !MCValue {3468) !MCValue {
3470 const pt = self.pt;3469 const pt = self.pt;
3471 const mod = pt.zcu;3470 const zcu = pt.zcu;
3472 const elem_ty = ptr_ty.childType(mod);3471 const elem_ty = ptr_ty.childType(zcu);
3473 const elem_size = @as(u32, @intCast(elem_ty.abiSize(pt)));3472 const elem_size = @as(u32, @intCast(elem_ty.abiSize(zcu)));
34743473
3475 // TODO optimize for elem_sizes of 1, 2, 4, 83474 // TODO optimize for elem_sizes of 1, 2, 4, 8
3476 switch (elem_size) {3475 switch (elem_size) {
...@@ -3511,10 +3510,10 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -3511,10 +3510,10 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
35113510
3512fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {3511fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
3513 const pt = self.pt;3512 const pt = self.pt;
3514 const mod = pt.zcu;3513 const zcu = pt.zcu;
3515 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3514 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3516 const ptr_ty = self.typeOf(bin_op.lhs);3515 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: {
3518 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };3517 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
3519 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };3518 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
35203519
...@@ -3635,9 +3634,9 @@ fn reuseOperand(...@@ -3635,9 +3634,9 @@ fn reuseOperand(
36353634
3636fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {3635fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
3637 const pt = self.pt;3636 const pt = self.pt;
3638 const mod = pt.zcu;3637 const zcu = pt.zcu;
3639 const elem_ty = ptr_ty.childType(mod);3638 const elem_ty = ptr_ty.childType(zcu);
3640 const elem_size = elem_ty.abiSize(pt);3639 const elem_size = elem_ty.abiSize(zcu);
36413640
3642 switch (ptr) {3641 switch (ptr) {
3643 .none => unreachable,3642 .none => unreachable,
...@@ -3884,16 +3883,16 @@ fn genInlineMemsetCode(...@@ -3884,16 +3883,16 @@ fn genInlineMemsetCode(
38843883
3885fn airLoad(self: *Self, inst: Air.Inst.Index) !void {3884fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
3886 const pt = self.pt;3885 const pt = self.pt;
3887 const mod = pt.zcu;3886 const zcu = pt.zcu;
3888 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3887 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3889 const elem_ty = self.typeOfIndex(inst);3888 const elem_ty = self.typeOfIndex(inst);
3890 const elem_size = elem_ty.abiSize(pt);3889 const elem_size = elem_ty.abiSize(zcu);
3891 const result: MCValue = result: {3890 const result: MCValue = result: {
3892 if (!elem_ty.hasRuntimeBits(pt))3891 if (!elem_ty.hasRuntimeBits(zcu))
3893 break :result MCValue.none;3892 break :result MCValue.none;
38943893
3895 const ptr = try self.resolveInst(ty_op.operand);3894 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);
3897 if (self.liveness.isUnused(inst) and !is_volatile)3896 if (self.liveness.isUnused(inst) and !is_volatile)
3898 break :result MCValue.dead;3897 break :result MCValue.dead;
38993898
...@@ -3916,12 +3915,12 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -3916,12 +3915,12 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
39163915
3917fn genLdrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type) !void {3916fn genLdrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type) !void {
3918 const pt = self.pt;3917 const pt = self.pt;
3919 const mod = pt.zcu;3918 const zcu = pt.zcu;
3920 const abi_size = ty.abiSize(pt);3919 const abi_size = ty.abiSize(zcu);
39213920
3922 const tag: Mir.Inst.Tag = switch (abi_size) {3921 const tag: Mir.Inst.Tag = switch (abi_size) {
3923 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_immediate else .ldrb_immediate,3922 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb_immediate else .ldrb_immediate,
3924 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh_immediate else .ldrh_immediate,3923 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_immediate else .ldrh_immediate,
3925 4 => .ldr_immediate,3924 4 => .ldr_immediate,
3926 8 => .ldr_immediate,3925 8 => .ldr_immediate,
3927 3, 5, 6, 7 => return self.fail("TODO: genLdrRegister for more abi_sizes", .{}),3926 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...@@ -3940,7 +3939,7 @@ fn genLdrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type
39403939
3941fn genStrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type) !void {3940fn genStrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type) !void {
3942 const pt = self.pt;3941 const pt = self.pt;
3943 const abi_size = ty.abiSize(pt);3942 const abi_size = ty.abiSize(pt.zcu);
39443943
3945 const tag: Mir.Inst.Tag = switch (abi_size) {3944 const tag: Mir.Inst.Tag = switch (abi_size) {
3946 1 => .strb_immediate,3945 1 => .strb_immediate,
...@@ -3963,7 +3962,7 @@ fn genStrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type...@@ -3963,7 +3962,7 @@ fn genStrRegister(self: *Self, value_reg: Register, addr_reg: Register, ty: Type
3963fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {3962fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
3964 const pt = self.pt;3963 const pt = self.pt;
3965 log.debug("store: storing {} to {}", .{ value, ptr });3964 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
3968 switch (ptr) {3967 switch (ptr) {
3969 .none => unreachable,3968 .none => unreachable,
...@@ -4116,11 +4115,11 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {...@@ -4116,11 +4115,11 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
4116fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {4115fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
4117 return if (self.liveness.isUnused(inst)) .dead else result: {4116 return if (self.liveness.isUnused(inst)) .dead else result: {
4118 const pt = self.pt;4117 const pt = self.pt;
4119 const mod = pt.zcu;4118 const zcu = pt.zcu;
4120 const mcv = try self.resolveInst(operand);4119 const mcv = try self.resolveInst(operand);
4121 const ptr_ty = self.typeOf(operand);4120 const ptr_ty = self.typeOf(operand);
4122 const struct_ty = ptr_ty.childType(mod);4121 const struct_ty = ptr_ty.childType(zcu);
4123 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));4122 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
4124 switch (mcv) {4123 switch (mcv) {
4125 .ptr_stack_offset => |off| {4124 .ptr_stack_offset => |off| {
4126 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };4125 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
...@@ -4142,11 +4141,11 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -4142,11 +4141,11 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
4142 const index = extra.field_index;4141 const index = extra.field_index;
4143 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4142 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4144 const pt = self.pt;4143 const pt = self.pt;
4145 const mod = pt.zcu;4144 const zcu = pt.zcu;
4146 const mcv = try self.resolveInst(operand);4145 const mcv = try self.resolveInst(operand);
4147 const struct_ty = self.typeOf(operand);4146 const struct_ty = self.typeOf(operand);
4148 const struct_field_ty = struct_ty.structFieldType(index, mod);4147 const struct_field_ty = struct_ty.fieldType(index, zcu);
4149 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));4148 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
41504149
4151 switch (mcv) {4150 switch (mcv) {
4152 .dead, .unreach => unreachable,4151 .dead, .unreach => unreachable,
...@@ -4193,13 +4192,13 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -4193,13 +4192,13 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
41934192
4194fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {4193fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
4195 const pt = self.pt;4194 const pt = self.pt;
4196 const mod = pt.zcu;4195 const zcu = pt.zcu;
4197 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4196 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4198 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;4197 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
4199 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4198 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4200 const field_ptr = try self.resolveInst(extra.field_ptr);4199 const field_ptr = try self.resolveInst(extra.field_ptr);
4201 const struct_ty = ty_pl.ty.toType().childType(mod);4200 const struct_ty = ty_pl.ty.toType().childType(zcu);
4202 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, pt)));4201 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(extra.field_index, zcu)));
4203 switch (field_ptr) {4202 switch (field_ptr) {
4204 .ptr_stack_offset => |off| {4203 .ptr_stack_offset => |off| {
4205 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };4204 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...@@ -4274,12 +4273,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4274 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));4273 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]));
4275 const ty = self.typeOf(callee);4274 const ty = self.typeOf(callee);
4276 const pt = self.pt;4275 const pt = self.pt;
4277 const mod = pt.zcu;4276 const zcu = pt.zcu;
4278 const ip = &mod.intern_pool;4277 const ip = &zcu.intern_pool;
42794278
4280 const fn_ty = switch (ty.zigTypeTag(mod)) {4279 const fn_ty = switch (ty.zigTypeTag(zcu)) {
4281 .Fn => ty,4280 .Fn => ty,
4282 .Pointer => ty.childType(mod),4281 .Pointer => ty.childType(zcu),
4283 else => unreachable,4282 else => unreachable,
4284 };4283 };
42854284
...@@ -4298,9 +4297,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4298,9 +4297,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42984297
4299 if (info.return_value == .stack_offset) {4298 if (info.return_value == .stack_offset) {
4300 log.debug("airCall: return by reference", .{});4299 log.debug("airCall: return by reference", .{});
4301 const ret_ty = fn_ty.fnReturnType(mod);4300 const ret_ty = fn_ty.fnReturnType(zcu);
4302 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(pt));4301 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(zcu));
4303 const ret_abi_align = ret_ty.abiAlignment(pt);4302 const ret_abi_align = ret_ty.abiAlignment(zcu);
4304 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);4303 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
43054304
4306 const ret_ptr_reg = self.registerAlias(.x0, Type.usize);4305 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...@@ -4387,7 +4386,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4387 },4386 },
4388 else => return self.fail("TODO implement calling bitcasted functions", .{}),4387 else => return self.fail("TODO implement calling bitcasted functions", .{}),
4389 } else {4388 } else {
4390 assert(ty.zigTypeTag(mod) == .Pointer);4389 assert(ty.zigTypeTag(zcu) == .Pointer);
4391 const mcv = try self.resolveInst(callee);4390 const mcv = try self.resolveInst(callee);
4392 try self.genSetReg(ty, .x30, mcv);4391 try self.genSetReg(ty, .x30, mcv);
43934392
...@@ -4426,15 +4425,15 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4426,15 +4425,15 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
44264425
4427fn airRet(self: *Self, inst: Air.Inst.Index) !void {4426fn airRet(self: *Self, inst: Air.Inst.Index) !void {
4428 const pt = self.pt;4427 const pt = self.pt;
4429 const mod = pt.zcu;4428 const zcu = pt.zcu;
4430 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4429 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4431 const operand = try self.resolveInst(un_op);4430 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
4434 switch (self.ret_mcv) {4433 switch (self.ret_mcv) {
4435 .none => {},4434 .none => {},
4436 .immediate => {4435 .immediate => {
4437 assert(ret_ty.isError(mod));4436 assert(ret_ty.isError(zcu));
4438 },4437 },
4439 .register => |reg| {4438 .register => |reg| {
4440 // Return result by value4439 // Return result by value
...@@ -4459,11 +4458,11 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {...@@ -4459,11 +4458,11 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44594458
4460fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {4459fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4461 const pt = self.pt;4460 const pt = self.pt;
4462 const mod = pt.zcu;4461 const zcu = pt.zcu;
4463 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4462 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4464 const ptr = try self.resolveInst(un_op);4463 const ptr = try self.resolveInst(un_op);
4465 const ptr_ty = self.typeOf(un_op);4464 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
4468 switch (self.ret_mcv) {4467 switch (self.ret_mcv) {
4469 .none => {},4468 .none => {},
...@@ -4483,8 +4482,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4483,8 +4482,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4483 // location.4482 // location.
4484 const op_inst = un_op.toIndex().?;4483 const op_inst = un_op.toIndex().?;
4485 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {4484 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
4486 const abi_size = @as(u32, @intCast(ret_ty.abiSize(pt)));4485 const abi_size = @as(u32, @intCast(ret_ty.abiSize(zcu)));
4487 const abi_align = ret_ty.abiAlignment(pt);4486 const abi_align = ret_ty.abiAlignment(zcu);
44884487
4489 const offset = try self.allocMem(abi_size, abi_align, null);4488 const offset = try self.allocMem(abi_size, abi_align, null);
44904489
...@@ -4520,20 +4519,20 @@ fn cmp(...@@ -4520,20 +4519,20 @@ fn cmp(
4520 op: math.CompareOperator,4519 op: math.CompareOperator,
4521) !MCValue {4520) !MCValue {
4522 const pt = self.pt;4521 const pt = self.pt;
4523 const mod = pt.zcu;4522 const zcu = pt.zcu;
4524 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {4523 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {
4525 .Optional => blk: {4524 .Optional => blk: {
4526 const payload_ty = lhs_ty.optionalChild(mod);4525 const payload_ty = lhs_ty.optionalChild(zcu);
4527 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4526 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4528 break :blk Type.u1;4527 break :blk Type.u1;
4529 } else if (lhs_ty.isPtrLikeOptional(mod)) {4528 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
4530 break :blk Type.usize;4529 break :blk Type.usize;
4531 } else {4530 } else {
4532 return self.fail("TODO ARM cmp non-pointer optionals", .{});4531 return self.fail("TODO ARM cmp non-pointer optionals", .{});
4533 }4532 }
4534 },4533 },
4535 .Float => return self.fail("TODO ARM cmp floats", .{}),4534 .Float => return self.fail("TODO ARM cmp floats", .{}),
4536 .Enum => lhs_ty.intTagType(mod),4535 .Enum => lhs_ty.intTagType(zcu),
4537 .Int => lhs_ty,4536 .Int => lhs_ty,
4538 .Bool => Type.u1,4537 .Bool => Type.u1,
4539 .Pointer => Type.usize,4538 .Pointer => Type.usize,
...@@ -4541,7 +4540,7 @@ fn cmp(...@@ -4541,7 +4540,7 @@ fn cmp(
4541 else => unreachable,4540 else => unreachable,
4542 };4541 };
45434542
4544 const int_info = int_ty.intInfo(mod);4543 const int_info = int_ty.intInfo(zcu);
4545 if (int_info.bits <= 64) {4544 if (int_info.bits <= 64) {
4546 try self.spillCompareFlagsIfOccupied();4545 try self.spillCompareFlagsIfOccupied();
45474546
...@@ -4628,10 +4627,10 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {...@@ -4628,10 +4627,10 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
46284627
4629fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {4628fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {
4630 const pt = self.pt;4629 const pt = self.pt;
4631 const mod = pt.zcu;4630 const zcu = pt.zcu;
4632 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4631 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4633 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);4632 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);
4635 // TODO emit debug info for function change4634 // TODO emit debug info for function change
4636 _ = func;4635 _ = func;
4637 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));4636 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 {...@@ -4834,13 +4833,13 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
48344833
4835fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {4834fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
4836 const pt = self.pt;4835 const pt = self.pt;
4837 const mod = pt.zcu;4836 const zcu = pt.zcu;
4838 const sentinel: struct { ty: Type, bind: ReadArg.Bind } = if (!operand_ty.isPtrLikeOptional(mod)) blk: {4837 const sentinel: struct { ty: Type, bind: ReadArg.Bind } = if (!operand_ty.isPtrLikeOptional(zcu)) blk: {
4839 const payload_ty = operand_ty.optionalChild(mod);4838 const payload_ty = operand_ty.optionalChild(zcu);
4840 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt))4839 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
4841 break :blk .{ .ty = operand_ty, .bind = operand_bind };4840 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)));
4844 const operand_mcv = try operand_bind.resolveToMcv(self);4843 const operand_mcv = try operand_bind.resolveToMcv(self);
4845 const new_mcv: MCValue = switch (operand_mcv) {4844 const new_mcv: MCValue = switch (operand_mcv) {
4846 .register => |source_reg| new: {4845 .register => |source_reg| new: {
...@@ -4853,7 +4852,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {...@@ -4853,7 +4852,7 @@ fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
4853 try self.genSetReg(payload_ty, dest_reg, operand_mcv);4852 try self.genSetReg(payload_ty, dest_reg, operand_mcv);
4854 } else {4853 } else {
4855 _ = try self.addInst(.{4854 _ = try self.addInst(.{
4856 .tag = if (payload_ty.isSignedInt(mod))4855 .tag = if (payload_ty.isSignedInt(zcu))
4857 Mir.Inst.Tag.asr_immediate4856 Mir.Inst.Tag.asr_immediate
4858 else4857 else
4859 Mir.Inst.Tag.lsr_immediate,4858 Mir.Inst.Tag.lsr_immediate,
...@@ -4891,10 +4890,10 @@ fn isErr(...@@ -4891,10 +4890,10 @@ fn isErr(
4891 error_union_ty: Type,4890 error_union_ty: Type,
4892) !MCValue {4891) !MCValue {
4893 const pt = self.pt;4892 const pt = self.pt;
4894 const mod = pt.zcu;4893 const zcu = pt.zcu;
4895 const error_type = error_union_ty.errorUnionSet(mod);4894 const error_type = error_union_ty.errorUnionSet(zcu);
48964895
4897 if (error_type.errorSetIsEmpty(mod)) {4896 if (error_type.errorSetIsEmpty(zcu)) {
4898 return MCValue{ .immediate = 0 }; // always false4897 return MCValue{ .immediate = 0 }; // always false
4899 }4898 }
49004899
...@@ -4934,12 +4933,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4934,12 +4933,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
49344933
4935fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {4934fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4936 const pt = self.pt;4935 const pt = self.pt;
4937 const mod = pt.zcu;4936 const zcu = pt.zcu;
4938 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4937 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4939 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4938 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4940 const operand_ptr = try self.resolveInst(un_op);4939 const operand_ptr = try self.resolveInst(un_op);
4941 const ptr_ty = self.typeOf(un_op);4940 const ptr_ty = self.typeOf(un_op);
4942 const elem_ty = ptr_ty.childType(mod);4941 const elem_ty = ptr_ty.childType(zcu);
49434942
4944 const operand = try self.allocRegOrMem(elem_ty, true, null);4943 const operand = try self.allocRegOrMem(elem_ty, true, null);
4945 try self.load(operand, operand_ptr, ptr_ty);4944 try self.load(operand, operand_ptr, ptr_ty);
...@@ -4962,12 +4961,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4962,12 +4961,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
49624961
4963fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {4962fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4964 const pt = self.pt;4963 const pt = self.pt;
4965 const mod = pt.zcu;4964 const zcu = pt.zcu;
4966 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4965 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4967 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4966 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4968 const operand_ptr = try self.resolveInst(un_op);4967 const operand_ptr = try self.resolveInst(un_op);
4969 const ptr_ty = self.typeOf(un_op);4968 const ptr_ty = self.typeOf(un_op);
4970 const elem_ty = ptr_ty.childType(mod);4969 const elem_ty = ptr_ty.childType(zcu);
49714970
4972 const operand = try self.allocRegOrMem(elem_ty, true, null);4971 const operand = try self.allocRegOrMem(elem_ty, true, null);
4973 try self.load(operand, operand_ptr, ptr_ty);4972 try self.load(operand, operand_ptr, ptr_ty);
...@@ -4990,12 +4989,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4990,12 +4989,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49904989
4991fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {4990fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4992 const pt = self.pt;4991 const pt = self.pt;
4993 const mod = pt.zcu;4992 const zcu = pt.zcu;
4994 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4993 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4995 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4994 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4996 const operand_ptr = try self.resolveInst(un_op);4995 const operand_ptr = try self.resolveInst(un_op);
4997 const ptr_ty = self.typeOf(un_op);4996 const ptr_ty = self.typeOf(un_op);
4998 const elem_ty = ptr_ty.childType(mod);4997 const elem_ty = ptr_ty.childType(zcu);
49994998
5000 const operand = try self.allocRegOrMem(elem_ty, true, null);4999 const operand = try self.allocRegOrMem(elem_ty, true, null);
5001 try self.load(operand, operand_ptr, ptr_ty);5000 try self.load(operand, operand_ptr, ptr_ty);
...@@ -5018,12 +5017,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5018,12 +5017,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
50185017
5019fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {5018fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
5020 const pt = self.pt;5019 const pt = self.pt;
5021 const mod = pt.zcu;5020 const zcu = pt.zcu;
5022 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5021 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5023 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {5022 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5024 const operand_ptr = try self.resolveInst(un_op);5023 const operand_ptr = try self.resolveInst(un_op);
5025 const ptr_ty = self.typeOf(un_op);5024 const ptr_ty = self.typeOf(un_op);
5026 const elem_ty = ptr_ty.childType(mod);5025 const elem_ty = ptr_ty.childType(zcu);
50275026
5028 const operand = try self.allocRegOrMem(elem_ty, true, null);5027 const operand = try self.allocRegOrMem(elem_ty, true, null);
5029 try self.load(operand, operand_ptr, ptr_ty);5028 try self.load(operand, operand_ptr, ptr_ty);
...@@ -5240,9 +5239,10 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5240,9 +5239,10 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
52405239
5241fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {5240fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
5242 const pt = self.pt;5241 const pt = self.pt;
5242 const zcu = pt.zcu;
5243 const block_data = self.blocks.getPtr(block).?;5243 const block_data = self.blocks.getPtr(block).?;
52445244
5245 if (self.typeOf(operand).hasRuntimeBits(pt)) {5245 if (self.typeOf(operand).hasRuntimeBits(zcu)) {
5246 const operand_mcv = try self.resolveInst(operand);5246 const operand_mcv = try self.resolveInst(operand);
5247 const block_mcv = block_data.mcv;5247 const block_mcv = block_data.mcv;
5248 if (block_mcv == .none) {5248 if (block_mcv == .none) {
...@@ -5417,8 +5417,8 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {...@@ -5417,8 +5417,8 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
54175417
5418fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5418fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5419 const pt = self.pt;5419 const pt = self.pt;
5420 const mod = pt.zcu;5420 const zcu = pt.zcu;
5421 const abi_size = @as(u32, @intCast(ty.abiSize(pt)));5421 const abi_size = @as(u32, @intCast(ty.abiSize(zcu)));
5422 switch (mcv) {5422 switch (mcv) {
5423 .dead => unreachable,5423 .dead => unreachable,
5424 .unreach, .none => return, // Nothing to do.5424 .unreach, .none => return, // Nothing to do.
...@@ -5473,11 +5473,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5473,11 +5473,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5473 const reg_lock = self.register_manager.lockReg(rwo.reg);5473 const reg_lock = self.register_manager.lockReg(rwo.reg);
5474 defer if (reg_lock) |locked_reg| self.register_manager.unlockReg(locked_reg);5474 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);
5477 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });5477 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
54785478
5479 const overflow_bit_ty = ty.structFieldType(1, mod);5479 const overflow_bit_ty = ty.fieldType(1, zcu);
5480 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, pt)));5480 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, zcu)));
5481 const raw_cond_reg = try self.register_manager.allocReg(null, gp);5481 const raw_cond_reg = try self.register_manager.allocReg(null, gp);
5482 const cond_reg = self.registerAlias(raw_cond_reg, overflow_bit_ty);5482 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...@@ -5589,7 +5589,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
55895589
5590fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {5590fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {
5591 const pt = self.pt;5591 const pt = self.pt;
5592 const mod = pt.zcu;5592 const zcu = pt.zcu;
5593 switch (mcv) {5593 switch (mcv) {
5594 .dead => unreachable,5594 .dead => unreachable,
5595 .unreach, .none => return, // Nothing to do.5595 .unreach, .none => return, // Nothing to do.
...@@ -5701,13 +5701,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5701,13 +5701,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5701 try self.genLdrRegister(reg, reg.toX(), ty);5701 try self.genLdrRegister(reg, reg.toX(), ty);
5702 },5702 },
5703 .stack_offset => |off| {5703 .stack_offset => |off| {
5704 const abi_size = ty.abiSize(pt);5704 const abi_size = ty.abiSize(zcu);
57055705
5706 switch (abi_size) {5706 switch (abi_size) {
5707 1, 2, 4, 8 => {5707 1, 2, 4, 8 => {
5708 const tag: Mir.Inst.Tag = switch (abi_size) {5708 const tag: Mir.Inst.Tag = switch (abi_size) {
5709 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_stack else .ldrb_stack,5709 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb_stack else .ldrb_stack,
5710 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh_stack else .ldrh_stack,5710 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_stack else .ldrh_stack,
5711 4, 8 => .ldr_stack,5711 4, 8 => .ldr_stack,
5712 else => unreachable, // unexpected abi size5712 else => unreachable, // unexpected abi size
5713 };5713 };
...@@ -5725,13 +5725,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5725,13 +5725,13 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5725 }5725 }
5726 },5726 },
5727 .stack_argument_offset => |off| {5727 .stack_argument_offset => |off| {
5728 const abi_size = ty.abiSize(pt);5728 const abi_size = ty.abiSize(zcu);
57295729
5730 switch (abi_size) {5730 switch (abi_size) {
5731 1, 2, 4, 8 => {5731 1, 2, 4, 8 => {
5732 const tag: Mir.Inst.Tag = switch (abi_size) {5732 const tag: Mir.Inst.Tag = switch (abi_size) {
5733 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_stack_argument else .ldrb_stack_argument,5733 1 => if (ty.isSignedInt(zcu)) 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,5734 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_stack_argument else .ldrh_stack_argument,
5735 4, 8 => .ldr_stack_argument,5735 4, 8 => .ldr_stack_argument,
5736 else => unreachable, // unexpected abi size5736 else => unreachable, // unexpected abi size
5737 };5737 };
...@@ -5753,7 +5753,8 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5753,7 +5753,8 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57535753
5754fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5754fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5755 const pt = self.pt;5755 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)));
5757 switch (mcv) {5758 switch (mcv) {
5758 .dead => unreachable,5759 .dead => unreachable,
5759 .none, .unreach => return,5760 .none, .unreach => return,
...@@ -5761,7 +5762,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I...@@ -5761,7 +5762,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
5761 if (!self.wantSafety())5762 if (!self.wantSafety())
5762 return; // The already existing value will do just fine.5763 return; // The already existing value will do just fine.
5763 // TODO Upgrade this to a memset call when we have that available.5764 // TODO Upgrade this to a memset call when we have that available.
5764 switch (ty.abiSize(pt)) {5765 switch (ty.abiSize(pt.zcu)) {
5765 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),5766 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),
5766 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),5767 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),
5767 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),5768 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),
...@@ -5953,13 +5954,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -5953,13 +5954,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59535954
5954fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {5955fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5955 const pt = self.pt;5956 const pt = self.pt;
5956 const mod = pt.zcu;5957 const zcu = pt.zcu;
5957 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5958 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5958 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {5959 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5959 const ptr_ty = self.typeOf(ty_op.operand);5960 const ptr_ty = self.typeOf(ty_op.operand);
5960 const ptr = try self.resolveInst(ty_op.operand);5961 const ptr = try self.resolveInst(ty_op.operand);
5961 const array_ty = ptr_ty.childType(mod);5962 const array_ty = ptr_ty.childType(zcu);
5962 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));5963 const array_len = @as(u32, @intCast(array_ty.arrayLen(zcu)));
5963 const ptr_bytes = 8;5964 const ptr_bytes = 8;
5964 const stack_offset = try self.allocMem(ptr_bytes * 2, .@"8", inst);5965 const stack_offset = try self.allocMem(ptr_bytes * 2, .@"8", inst);
5965 try self.genSetStack(ptr_ty, stack_offset, ptr);5966 try self.genSetStack(ptr_ty, stack_offset, ptr);
...@@ -6074,9 +6075,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {...@@ -6074,9 +6075,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60746075
6075fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {6076fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6076 const pt = self.pt;6077 const pt = self.pt;
6077 const mod = pt.zcu;6078 const zcu = pt.zcu;
6078 const vector_ty = self.typeOfIndex(inst);6079 const vector_ty = self.typeOfIndex(inst);
6079 const len = vector_ty.vectorLen(mod);6080 const len = vector_ty.vectorLen(zcu);
6080 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6081 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6081 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));6082 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
6082 const result: MCValue = res: {6083 const result: MCValue = res: {
...@@ -6125,8 +6126,8 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {...@@ -6125,8 +6126,8 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6125 const result: MCValue = result: {6126 const result: MCValue = result: {
6126 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };6127 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6127 const error_union_ty = self.typeOf(pl_op.operand);6128 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_size = @as(u32, @intCast(error_union_ty.abiSize(pt.zcu)));
6129 const error_union_align = error_union_ty.abiAlignment(pt);6130 const error_union_align = error_union_ty.abiAlignment(pt.zcu);
61306131
6131 // The error union will die in the body. However, we need the6132 // The error union will die in the body. However, we need the
6132 // error union after the body in order to extract the payload6133 // error union after the body in order to extract the payload
...@@ -6156,11 +6157,11 @@ fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -6156,11 +6157,11 @@ fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
61566157
6157fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {6158fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
6158 const pt = self.pt;6159 const pt = self.pt;
6159 const mod = pt.zcu;6160 const zcu = pt.zcu;
61606161
6161 // If the type has no codegen bits, no need to store it.6162 // If the type has no codegen bits, no need to store it.
6162 const inst_ty = self.typeOf(inst);6163 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))
6164 return MCValue{ .none = {} };6165 return MCValue{ .none = {} };
61656166
6166 const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, pt)).?);6167 const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, pt)).?);
...@@ -6220,9 +6221,9 @@ const CallMCValues = struct {...@@ -6220,9 +6221,9 @@ const CallMCValues = struct {
6220/// Caller must call `CallMCValues.deinit`.6221/// Caller must call `CallMCValues.deinit`.
6221fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {6222fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6222 const pt = self.pt;6223 const pt = self.pt;
6223 const mod = pt.zcu;6224 const zcu = pt.zcu;
6224 const ip = &mod.intern_pool;6225 const ip = &zcu.intern_pool;
6225 const fn_info = mod.typeToFunc(fn_ty).?;6226 const fn_info = zcu.typeToFunc(fn_ty).?;
6226 const cc = fn_info.cc;6227 const cc = fn_info.cc;
6227 var result: CallMCValues = .{6228 var result: CallMCValues = .{
6228 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),6229 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),
...@@ -6233,7 +6234,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6233,7 +6234,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6233 };6234 };
6234 errdefer self.gpa.free(result.args);6235 errdefer self.gpa.free(result.args);
62356236
6236 const ret_ty = fn_ty.fnReturnType(mod);6237 const ret_ty = fn_ty.fnReturnType(zcu);
62376238
6238 switch (cc) {6239 switch (cc) {
6239 .Naked => {6240 .Naked => {
...@@ -6248,14 +6249,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6248,14 +6249,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6248 var ncrn: usize = 0; // Next Core Register Number6249 var ncrn: usize = 0; // Next Core Register Number
6249 var nsaa: u32 = 0; // Next stacked argument address6250 var nsaa: u32 = 0; // Next stacked argument address
62506251
6251 if (ret_ty.zigTypeTag(mod) == .NoReturn) {6252 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
6252 result.return_value = .{ .unreach = {} };6253 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)) {
6254 result.return_value = .{ .none = {} };6255 result.return_value = .{ .none = {} };
6255 } else {6256 } else {
6256 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));6257 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
6257 if (ret_ty_size == 0) {6258 if (ret_ty_size == 0) {
6258 assert(ret_ty.isError(mod));6259 assert(ret_ty.isError(zcu));
6259 result.return_value = .{ .immediate = 0 };6260 result.return_value = .{ .immediate = 0 };
6260 } else if (ret_ty_size <= 8) {6261 } else if (ret_ty_size <= 8) {
6261 result.return_value = .{ .register = self.registerAlias(c_abi_int_return_regs[0], ret_ty) };6262 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 {...@@ -6265,7 +6266,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6265 }6266 }
62666267
6267 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6268 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)));
6269 if (param_size == 0) {6270 if (param_size == 0) {
6270 result_arg.* = .{ .none = {} };6271 result_arg.* = .{ .none = {} };
6271 continue;6272 continue;
...@@ -6273,7 +6274,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6273,7 +6274,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62736274
6274 // We round up NCRN only for non-Apple platforms which allow the 16-byte aligned6275 // We round up NCRN only for non-Apple platforms which allow the 16-byte aligned
6275 // values to spread across odd-numbered registers.6276 // 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()) {
6277 // Round up NCRN to the next even number6278 // Round up NCRN to the next even number
6278 ncrn += ncrn % 2;6279 ncrn += ncrn % 2;
6279 }6280 }
...@@ -6291,7 +6292,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6291,7 +6292,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6291 ncrn = 8;6292 ncrn = 8;
6292 // TODO Apple allows the arguments on the stack to be non-8-byte aligned provided6293 // TODO Apple allows the arguments on the stack to be non-8-byte aligned provided
6293 // that the entire stack space consumed by the arguments is 8-byte aligned.6294 // 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") {
6295 if (nsaa % 8 != 0) {6296 if (nsaa % 8 != 0) {
6296 nsaa += 8 - (nsaa % 8);6297 nsaa += 8 - (nsaa % 8);
6297 }6298 }
...@@ -6306,14 +6307,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6306,14 +6307,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6306 result.stack_align = 16;6307 result.stack_align = 16;
6307 },6308 },
6308 .Unspecified => {6309 .Unspecified => {
6309 if (ret_ty.zigTypeTag(mod) == .NoReturn) {6310 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
6310 result.return_value = .{ .unreach = {} };6311 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)) {
6312 result.return_value = .{ .none = {} };6313 result.return_value = .{ .none = {} };
6313 } else {6314 } 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)));
6315 if (ret_ty_size == 0) {6316 if (ret_ty_size == 0) {
6316 assert(ret_ty.isError(mod));6317 assert(ret_ty.isError(zcu));
6317 result.return_value = .{ .immediate = 0 };6318 result.return_value = .{ .immediate = 0 };
6318 } else if (ret_ty_size <= 8) {6319 } else if (ret_ty_size <= 8) {
6319 result.return_value = .{ .register = self.registerAlias(.x0, ret_ty) };6320 result.return_value = .{ .register = self.registerAlias(.x0, ret_ty) };
...@@ -6330,9 +6331,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6330,9 +6331,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6330 var stack_offset: u32 = 0;6331 var stack_offset: u32 = 0;
63316332
6332 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6333 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6333 if (Type.fromInterned(ty).abiSize(pt) > 0) {6334 if (Type.fromInterned(ty).abiSize(zcu) > 0) {
6334 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(pt));6335 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(zcu));
6335 const param_alignment = Type.fromInterned(ty).abiAlignment(pt);6336 const param_alignment = Type.fromInterned(ty).abiAlignment(zcu);
63366337
6337 stack_offset = @intCast(param_alignment.forward(stack_offset));6338 stack_offset = @intCast(param_alignment.forward(stack_offset));
6338 result_arg.* = .{ .stack_argument_offset = stack_offset };6339 result_arg.* = .{ .stack_argument_offset = stack_offset };
...@@ -6383,7 +6384,7 @@ fn parseRegName(name: []const u8) ?Register {...@@ -6383,7 +6384,7 @@ fn parseRegName(name: []const u8) ?Register {
6383}6384}
63846385
6385fn registerAlias(self: *Self, reg: Register, ty: Type) Register {6386fn 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
6388 switch (reg.class()) {6389 switch (reg.class()) {
6389 .general_purpose => {6390 .general_purpose => {
src/arch/aarch64/abi.zig+14-14
...@@ -15,44 +15,44 @@ pub const Class = union(enum) {...@@ -15,44 +15,44 @@ pub const Class = union(enum) {
15};15};
1616
17/// For `float_array` the second element will be the amount of floats.17/// For `float_array` the second element will be the amount of floats.
18pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {18pub fn classifyType(ty: Type, zcu: *Zcu) Class {
19 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(pt));19 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
2020
21 var maybe_float_bits: ?u16 = null;21 var maybe_float_bits: ?u16 = null;
22 switch (ty.zigTypeTag(pt.zcu)) {22 switch (ty.zigTypeTag(zcu)) {
23 .Struct => {23 .Struct => {
24 if (ty.containerLayout(pt.zcu) == .@"packed") return .byval;24 if (ty.containerLayout(zcu) == .@"packed") return .byval;
25 const float_count = countFloats(ty, pt.zcu, &maybe_float_bits);25 const float_count = countFloats(ty, zcu, &maybe_float_bits);
26 if (float_count <= sret_float_count) return .{ .float_array = float_count };26 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);
29 if (bit_size > 128) return .memory;29 if (bit_size > 128) return .memory;
30 if (bit_size > 64) return .double_integer;30 if (bit_size > 64) return .double_integer;
31 return .integer;31 return .integer;
32 },32 },
33 .Union => {33 .Union => {
34 if (ty.containerLayout(pt.zcu) == .@"packed") return .byval;34 if (ty.containerLayout(zcu) == .@"packed") return .byval;
35 const float_count = countFloats(ty, pt.zcu, &maybe_float_bits);35 const float_count = countFloats(ty, zcu, &maybe_float_bits);
36 if (float_count <= sret_float_count) return .{ .float_array = float_count };36 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);
39 if (bit_size > 128) return .memory;39 if (bit_size > 128) return .memory;
40 if (bit_size > 64) return .double_integer;40 if (bit_size > 64) return .double_integer;
41 return .integer;41 return .integer;
42 },42 },
43 .Int, .Enum, .ErrorSet, .Float, .Bool => return .byval,43 .Int, .Enum, .ErrorSet, .Float, .Bool => return .byval,
44 .Vector => {44 .Vector => {
45 const bit_size = ty.bitSize(pt);45 const bit_size = ty.bitSize(zcu);
46 // TODO is this controlled by a cpu feature?46 // TODO is this controlled by a cpu feature?
47 if (bit_size > 128) return .memory;47 if (bit_size > 128) return .memory;
48 return .byval;48 return .byval;
49 },49 },
50 .Optional => {50 .Optional => {
51 std.debug.assert(ty.isPtrLikeOptional(pt.zcu));51 std.debug.assert(ty.isPtrLikeOptional(zcu));
52 return .byval;52 return .byval;
53 },53 },
54 .Pointer => {54 .Pointer => {
55 std.debug.assert(!ty.isSlice(pt.zcu));55 std.debug.assert(!ty.isSlice(zcu));
56 return .byval;56 return .byval;
57 },57 },
58 .ErrorUnion,58 .ErrorUnion,
...@@ -95,7 +95,7 @@ fn countFloats(ty: Type, zcu: *Zcu, maybe_float_bits: *?u16) u8 {...@@ -95,7 +95,7 @@ fn countFloats(ty: Type, zcu: *Zcu, maybe_float_bits: *?u16) u8 {
95 var count: u8 = 0;95 var count: u8 = 0;
96 var i: u32 = 0;96 var i: u32 = 0;
97 while (i < fields_len) : (i += 1) {97 while (i < fields_len) : (i += 1) {
98 const field_ty = ty.structFieldType(i, zcu);98 const field_ty = ty.fieldType(i, zcu);
99 const field_count = countFloats(field_ty, zcu, maybe_float_bits);99 const field_count = countFloats(field_ty, zcu, maybe_float_bits);
100 if (field_count == invalid) return invalid;100 if (field_count == invalid) return invalid;
101 count += field_count;101 count += field_count;
...@@ -130,7 +130,7 @@ pub fn getFloatArrayType(ty: Type, zcu: *Zcu) ?Type {...@@ -130,7 +130,7 @@ pub fn getFloatArrayType(ty: Type, zcu: *Zcu) ?Type {
130 const fields_len = ty.structFieldCount(zcu);130 const fields_len = ty.structFieldCount(zcu);
131 var i: u32 = 0;131 var i: u32 = 0;
132 while (i < fields_len) : (i += 1) {132 while (i < fields_len) : (i += 1) {
133 const field_ty = ty.structFieldType(i, zcu);133 const field_ty = ty.fieldType(i, zcu);
134 if (getFloatArrayType(field_ty, zcu)) |some| return some;134 if (getFloatArrayType(field_ty, zcu)) |some| return some;
135 }135 }
136 return null;136 return null;
src/arch/arm/CodeGen.zig+252-252
...@@ -474,8 +474,8 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {...@@ -474,8 +474,8 @@ pub fn addExtraAssumeCapacity(self: *Self, extra: anytype) u32 {
474474
475fn gen(self: *Self) !void {475fn gen(self: *Self) !void {
476 const pt = self.pt;476 const pt = self.pt;
477 const mod = pt.zcu;477 const zcu = pt.zcu;
478 const cc = self.fn_type.fnCallingConvention(mod);478 const cc = self.fn_type.fnCallingConvention(zcu);
479 if (cc != .Naked) {479 if (cc != .Naked) {
480 // push {fp, lr}480 // push {fp, lr}
481 const push_reloc = try self.addNop();481 const push_reloc = try self.addNop();
...@@ -518,8 +518,8 @@ fn gen(self: *Self) !void {...@@ -518,8 +518,8 @@ fn gen(self: *Self) !void {
518518
519 const ty = self.typeOfIndex(inst);519 const ty = self.typeOfIndex(inst);
520520
521 const abi_size: u32 = @intCast(ty.abiSize(pt));521 const abi_size: u32 = @intCast(ty.abiSize(zcu));
522 const abi_align = ty.abiAlignment(pt);522 const abi_align = ty.abiAlignment(zcu);
523 const stack_offset = try self.allocMem(abi_size, abi_align, inst);523 const stack_offset = try self.allocMem(abi_size, abi_align, inst);
524 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });524 try self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
525525
...@@ -635,8 +635,8 @@ fn gen(self: *Self) !void {...@@ -635,8 +635,8 @@ fn gen(self: *Self) !void {
635635
636fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {636fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
637 const pt = self.pt;637 const pt = self.pt;
638 const mod = pt.zcu;638 const zcu = pt.zcu;
639 const ip = &mod.intern_pool;639 const ip = &zcu.intern_pool;
640 const air_tags = self.air.instructions.items(.tag);640 const air_tags = self.air.instructions.items(.tag);
641641
642 for (body) |inst| {642 for (body) |inst| {
...@@ -999,10 +999,10 @@ fn allocMem(...@@ -999,10 +999,10 @@ fn allocMem(
999/// Use a pointer instruction as the basis for allocating stack memory.999/// Use a pointer instruction as the basis for allocating stack memory.
1000fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {1000fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
1001 const pt = self.pt;1001 const pt = self.pt;
1002 const mod = pt.zcu;1002 const zcu = pt.zcu;
1003 const elem_ty = self.typeOfIndex(inst).childType(mod);1003 const elem_ty = self.typeOfIndex(inst).childType(zcu);
10041004
1005 if (!elem_ty.hasRuntimeBits(pt)) {1005 if (!elem_ty.hasRuntimeBits(zcu)) {
1006 // As this stack item will never be dereferenced at runtime,1006 // As this stack item will never be dereferenced at runtime,
1007 // return the stack offset 0. Stack offset 0 will be where all1007 // return the stack offset 0. Stack offset 0 will be where all
1008 // zero-sized stack allocations live as non-zero-sized1008 // zero-sized stack allocations live as non-zero-sized
...@@ -1010,21 +1010,21 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {...@@ -1010,21 +1010,21 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
1010 return 0;1010 return 0;
1011 }1011 }
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 {
1014 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});1014 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
1015 };1015 };
1016 // TODO swap this for inst.ty.ptrAlign1016 // TODO swap this for inst.ty.ptrAlign
1017 const abi_align = elem_ty.abiAlignment(pt);1017 const abi_align = elem_ty.abiAlignment(zcu);
10181018
1019 return self.allocMem(abi_size, abi_align, inst);1019 return self.allocMem(abi_size, abi_align, inst);
1020}1020}
10211021
1022fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst.Index) !MCValue {1022fn allocRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool, maybe_inst: ?Air.Inst.Index) !MCValue {
1023 const pt = self.pt;1023 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 {
1025 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});1025 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
1026 };1026 };
1027 const abi_align = elem_ty.abiAlignment(pt);1027 const abi_align = elem_ty.abiAlignment(pt.zcu);
10281028
1029 if (reg_ok) {1029 if (reg_ok) {
1030 // Make sure the type can fit in a register before we try to allocate one.1030 // 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 {...@@ -1108,13 +1108,13 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
11081108
1109fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {1109fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
1110 const pt = self.pt;1110 const pt = self.pt;
1111 const mod = pt.zcu;1111 const zcu = pt.zcu;
1112 const result: MCValue = switch (self.ret_mcv) {1112 const result: MCValue = switch (self.ret_mcv) {
1113 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },1113 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },
1114 .stack_offset => blk: {1114 .stack_offset => blk: {
1115 // self.ret_mcv is an address to where this function1115 // self.ret_mcv is an address to where this function
1116 // should store its result into1116 // should store its result into
1117 const ret_ty = self.fn_type.fnReturnType(mod);1117 const ret_ty = self.fn_type.fnReturnType(zcu);
1118 const ptr_ty = try pt.singleMutPtrType(ret_ty);1118 const ptr_ty = try pt.singleMutPtrType(ret_ty);
11191119
1120 // addr_reg will contain the address of where to store the1120 // addr_reg will contain the address of where to store the
...@@ -1142,7 +1142,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {...@@ -1142,7 +1142,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
11421142
1143fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {1143fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1144 const pt = self.pt;1144 const pt = self.pt;
1145 const mod = pt.zcu;1145 const zcu = pt.zcu;
1146 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1146 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1147 if (self.liveness.isUnused(inst))1147 if (self.liveness.isUnused(inst))
1148 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });1148 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
...@@ -1151,10 +1151,10 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -1151,10 +1151,10 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1151 const operand_ty = self.typeOf(ty_op.operand);1151 const operand_ty = self.typeOf(ty_op.operand);
1152 const dest_ty = self.typeOfIndex(inst);1152 const dest_ty = self.typeOfIndex(inst);
11531153
1154 const operand_abi_size = operand_ty.abiSize(pt);1154 const operand_abi_size = operand_ty.abiSize(zcu);
1155 const dest_abi_size = dest_ty.abiSize(pt);1155 const dest_abi_size = dest_ty.abiSize(zcu);
1156 const info_a = operand_ty.intInfo(mod);1156 const info_a = operand_ty.intInfo(zcu);
1157 const info_b = dest_ty.intInfo(mod);1157 const info_b = dest_ty.intInfo(zcu);
11581158
1159 const dst_mcv: MCValue = blk: {1159 const dst_mcv: MCValue = blk: {
1160 if (info_a.bits == info_b.bits) {1160 if (info_a.bits == info_b.bits) {
...@@ -1209,9 +1209,9 @@ fn trunc(...@@ -1209,9 +1209,9 @@ fn trunc(
1209 dest_ty: Type,1209 dest_ty: Type,
1210) !MCValue {1210) !MCValue {
1211 const pt = self.pt;1211 const pt = self.pt;
1212 const mod = pt.zcu;1212 const zcu = pt.zcu;
1213 const info_a = operand_ty.intInfo(mod);1213 const info_a = operand_ty.intInfo(zcu);
1214 const info_b = dest_ty.intInfo(mod);1214 const info_b = dest_ty.intInfo(zcu);
12151215
1216 if (info_b.bits <= 32) {1216 if (info_b.bits <= 32) {
1217 if (info_a.bits > 32) {1217 if (info_a.bits > 32) {
...@@ -1274,7 +1274,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {...@@ -1274,7 +1274,7 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
1274fn airNot(self: *Self, inst: Air.Inst.Index) !void {1274fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1275 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1275 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1276 const pt = self.pt;1276 const pt = self.pt;
1277 const mod = pt.zcu;1277 const zcu = pt.zcu;
1278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1278 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1279 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };1279 const operand_bind: ReadArg.Bind = .{ .inst = ty_op.operand };
1280 const operand_ty = self.typeOf(ty_op.operand);1280 const operand_ty = self.typeOf(ty_op.operand);
...@@ -1283,7 +1283,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {...@@ -1283,7 +1283,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1283 .unreach => unreachable,1283 .unreach => unreachable,
1284 .cpsr_flags => |cond| break :result MCValue{ .cpsr_flags = cond.negate() },1284 .cpsr_flags => |cond| break :result MCValue{ .cpsr_flags = cond.negate() },
1285 else => {1285 else => {
1286 switch (operand_ty.zigTypeTag(mod)) {1286 switch (operand_ty.zigTypeTag(zcu)) {
1287 .Bool => {1287 .Bool => {
1288 var op_reg: Register = undefined;1288 var op_reg: Register = undefined;
1289 var dest_reg: Register = undefined;1289 var dest_reg: Register = undefined;
...@@ -1316,7 +1316,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {...@@ -1316,7 +1316,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
1316 },1316 },
1317 .Vector => return self.fail("TODO bitwise not for vectors", .{}),1317 .Vector => return self.fail("TODO bitwise not for vectors", .{}),
1318 .Int => {1318 .Int => {
1319 const int_info = operand_ty.intInfo(mod);1319 const int_info = operand_ty.intInfo(zcu);
1320 if (int_info.bits <= 32) {1320 if (int_info.bits <= 32) {
1321 var op_reg: Register = undefined;1321 var op_reg: Register = undefined;
1322 var dest_reg: Register = undefined;1322 var dest_reg: Register = undefined;
...@@ -1371,13 +1371,13 @@ fn minMax(...@@ -1371,13 +1371,13 @@ fn minMax(
1371 maybe_inst: ?Air.Inst.Index,1371 maybe_inst: ?Air.Inst.Index,
1372) !MCValue {1372) !MCValue {
1373 const pt = self.pt;1373 const pt = self.pt;
1374 const mod = pt.zcu;1374 const zcu = pt.zcu;
1375 switch (lhs_ty.zigTypeTag(mod)) {1375 switch (lhs_ty.zigTypeTag(zcu)) {
1376 .Float => return self.fail("TODO ARM min/max on floats", .{}),1376 .Float => return self.fail("TODO ARM min/max on floats", .{}),
1377 .Vector => return self.fail("TODO ARM min/max on vectors", .{}),1377 .Vector => return self.fail("TODO ARM min/max on vectors", .{}),
1378 .Int => {1378 .Int => {
1379 assert(lhs_ty.eql(rhs_ty, mod));1379 assert(lhs_ty.eql(rhs_ty, zcu));
1380 const int_info = lhs_ty.intInfo(mod);1380 const int_info = lhs_ty.intInfo(zcu);
1381 if (int_info.bits <= 32) {1381 if (int_info.bits <= 32) {
1382 var lhs_reg: Register = undefined;1382 var lhs_reg: Register = undefined;
1383 var rhs_reg: Register = undefined;1383 var rhs_reg: Register = undefined;
...@@ -1581,7 +1581,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1581,7 +1581,7 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
1581 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;1581 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1582 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1582 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1583 const pt = self.pt;1583 const pt = self.pt;
1584 const mod = pt.zcu;1584 const zcu = pt.zcu;
1585 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1585 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1586 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };1586 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
1587 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };1587 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
...@@ -1589,15 +1589,15 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1589,15 +1589,15 @@ fn airOverflow(self: *Self, inst: Air.Inst.Index) !void {
1589 const rhs_ty = self.typeOf(extra.rhs);1589 const rhs_ty = self.typeOf(extra.rhs);
15901590
1591 const tuple_ty = self.typeOfIndex(inst);1591 const tuple_ty = self.typeOfIndex(inst);
1592 const tuple_size: u32 = @intCast(tuple_ty.abiSize(pt));1592 const tuple_size: u32 = @intCast(tuple_ty.abiSize(zcu));
1593 const tuple_align = tuple_ty.abiAlignment(pt);1593 const tuple_align = tuple_ty.abiAlignment(zcu);
1594 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, pt));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)) {
1597 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),1597 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
1598 .Int => {1598 .Int => {
1599 assert(lhs_ty.eql(rhs_ty, mod));1599 assert(lhs_ty.eql(rhs_ty, zcu));
1600 const int_info = lhs_ty.intInfo(mod);1600 const int_info = lhs_ty.intInfo(zcu);
1601 if (int_info.bits < 32) {1601 if (int_info.bits < 32) {
1602 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);1602 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 {...@@ -1695,7 +1695,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1695 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1695 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1696 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });1696 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
1697 const pt = self.pt;1697 const pt = self.pt;
1698 const mod = pt.zcu;1698 const zcu = pt.zcu;
1699 const result: MCValue = result: {1699 const result: MCValue = result: {
1700 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };1700 const lhs_bind: ReadArg.Bind = .{ .inst = extra.lhs };
1701 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };1701 const rhs_bind: ReadArg.Bind = .{ .inst = extra.rhs };
...@@ -1703,15 +1703,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -1703,15 +1703,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1703 const rhs_ty = self.typeOf(extra.rhs);1703 const rhs_ty = self.typeOf(extra.rhs);
17041704
1705 const tuple_ty = self.typeOfIndex(inst);1705 const tuple_ty = self.typeOfIndex(inst);
1706 const tuple_size: u32 = @intCast(tuple_ty.abiSize(pt));1706 const tuple_size: u32 = @intCast(tuple_ty.abiSize(zcu));
1707 const tuple_align = tuple_ty.abiAlignment(pt);1707 const tuple_align = tuple_ty.abiAlignment(zcu);
1708 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, pt));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)) {
1711 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),1711 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
1712 .Int => {1712 .Int => {
1713 assert(lhs_ty.eql(rhs_ty, mod));1713 assert(lhs_ty.eql(rhs_ty, zcu));
1714 const int_info = lhs_ty.intInfo(mod);1714 const int_info = lhs_ty.intInfo(zcu);
1715 if (int_info.bits <= 16) {1715 if (int_info.bits <= 16) {
1716 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);1716 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 {...@@ -1860,20 +1860,20 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
1860 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;1860 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
1861 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });1861 if (self.liveness.isUnused(inst)) return self.finishAir(inst, .dead, .{ extra.lhs, extra.rhs, .none });
1862 const pt = self.pt;1862 const pt = self.pt;
1863 const mod = pt.zcu;1863 const zcu = pt.zcu;
1864 const result: MCValue = result: {1864 const result: MCValue = result: {
1865 const lhs_ty = self.typeOf(extra.lhs);1865 const lhs_ty = self.typeOf(extra.lhs);
1866 const rhs_ty = self.typeOf(extra.rhs);1866 const rhs_ty = self.typeOf(extra.rhs);
18671867
1868 const tuple_ty = self.typeOfIndex(inst);1868 const tuple_ty = self.typeOfIndex(inst);
1869 const tuple_size: u32 = @intCast(tuple_ty.abiSize(pt));1869 const tuple_size: u32 = @intCast(tuple_ty.abiSize(zcu));
1870 const tuple_align = tuple_ty.abiAlignment(pt);1870 const tuple_align = tuple_ty.abiAlignment(zcu);
1871 const overflow_bit_offset: u32 = @intCast(tuple_ty.structFieldOffset(1, pt));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)) {
1874 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),1874 .Vector => return self.fail("TODO implement shl_with_overflow for vectors", .{}),
1875 .Int => {1875 .Int => {
1876 const int_info = lhs_ty.intInfo(mod);1876 const int_info = lhs_ty.intInfo(zcu);
1877 if (int_info.bits <= 32) {1877 if (int_info.bits <= 32) {
1878 const stack_offset = try self.allocMem(tuple_size, tuple_align, inst);1878 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 {...@@ -2020,7 +2020,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2020 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2020 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2021 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2021 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2022 const optional_ty = self.typeOfIndex(inst);2022 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
2025 // Optional with a zero-bit payload type is just a boolean true2025 // Optional with a zero-bit payload type is just a boolean true
2026 if (abi_size == 1) {2026 if (abi_size == 1) {
...@@ -2040,17 +2040,17 @@ fn errUnionErr(...@@ -2040,17 +2040,17 @@ fn errUnionErr(
2040 maybe_inst: ?Air.Inst.Index,2040 maybe_inst: ?Air.Inst.Index,
2041) !MCValue {2041) !MCValue {
2042 const pt = self.pt;2042 const pt = self.pt;
2043 const mod = pt.zcu;2043 const zcu = pt.zcu;
2044 const err_ty = error_union_ty.errorUnionSet(mod);2044 const err_ty = error_union_ty.errorUnionSet(zcu);
2045 const payload_ty = error_union_ty.errorUnionPayload(mod);2045 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2046 if (err_ty.errorSetIsEmpty(mod)) {2046 if (err_ty.errorSetIsEmpty(zcu)) {
2047 return MCValue{ .immediate = 0 };2047 return MCValue{ .immediate = 0 };
2048 }2048 }
2049 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {2049 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2050 return try error_union_bind.resolveToMcv(self);2050 return try error_union_bind.resolveToMcv(self);
2051 }2051 }
20522052
2053 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, pt));2053 const err_offset: u32 = @intCast(errUnionErrorOffset(payload_ty, zcu));
2054 switch (try error_union_bind.resolveToMcv(self)) {2054 switch (try error_union_bind.resolveToMcv(self)) {
2055 .register => {2055 .register => {
2056 var operand_reg: Register = undefined;2056 var operand_reg: Register = undefined;
...@@ -2072,7 +2072,7 @@ fn errUnionErr(...@@ -2072,7 +2072,7 @@ fn errUnionErr(
2072 );2072 );
20732073
2074 const err_bit_offset = err_offset * 8;2074 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
2077 _ = try self.addInst(.{2077 _ = try self.addInst(.{
2078 .tag = .ubfx, // errors are unsigned integers2078 .tag = .ubfx, // errors are unsigned integers
...@@ -2118,17 +2118,17 @@ fn errUnionPayload(...@@ -2118,17 +2118,17 @@ fn errUnionPayload(
2118 maybe_inst: ?Air.Inst.Index,2118 maybe_inst: ?Air.Inst.Index,
2119) !MCValue {2119) !MCValue {
2120 const pt = self.pt;2120 const pt = self.pt;
2121 const mod = pt.zcu;2121 const zcu = pt.zcu;
2122 const err_ty = error_union_ty.errorUnionSet(mod);2122 const err_ty = error_union_ty.errorUnionSet(zcu);
2123 const payload_ty = error_union_ty.errorUnionPayload(mod);2123 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2124 if (err_ty.errorSetIsEmpty(mod)) {2124 if (err_ty.errorSetIsEmpty(zcu)) {
2125 return try error_union_bind.resolveToMcv(self);2125 return try error_union_bind.resolveToMcv(self);
2126 }2126 }
2127 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {2127 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2128 return MCValue.none;2128 return MCValue.none;
2129 }2129 }
21302130
2131 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, pt));2131 const payload_offset: u32 = @intCast(errUnionPayloadOffset(payload_ty, zcu));
2132 switch (try error_union_bind.resolveToMcv(self)) {2132 switch (try error_union_bind.resolveToMcv(self)) {
2133 .register => {2133 .register => {
2134 var operand_reg: Register = undefined;2134 var operand_reg: Register = undefined;
...@@ -2150,10 +2150,10 @@ fn errUnionPayload(...@@ -2150,10 +2150,10 @@ fn errUnionPayload(
2150 );2150 );
21512151
2152 const payload_bit_offset = payload_offset * 8;2152 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
2155 _ = try self.addInst(.{2155 _ = 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,
2157 .data = .{ .rr_lsb_width = .{2157 .data = .{ .rr_lsb_width = .{
2158 .rd = dest_reg,2158 .rd = dest_reg,
2159 .rn = operand_reg,2159 .rn = operand_reg,
...@@ -2229,20 +2229,20 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {...@@ -2229,20 +2229,20 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
2229/// T to E!T2229/// T to E!T
2230fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {2230fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
2231 const pt = self.pt;2231 const pt = self.pt;
2232 const mod = pt.zcu;2232 const zcu = pt.zcu;
2233 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2233 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2234 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2234 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2235 const error_union_ty = ty_op.ty.toType();2235 const error_union_ty = ty_op.ty.toType();
2236 const error_ty = error_union_ty.errorUnionSet(mod);2236 const error_ty = error_union_ty.errorUnionSet(zcu);
2237 const payload_ty = error_union_ty.errorUnionPayload(mod);2237 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2238 const operand = try self.resolveInst(ty_op.operand);2238 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));2241 const abi_size: u32 = @intCast(error_union_ty.abiSize(zcu));
2242 const abi_align = error_union_ty.abiAlignment(pt);2242 const abi_align = error_union_ty.abiAlignment(zcu);
2243 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));2243 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));
2244 const payload_off = errUnionPayloadOffset(payload_ty, pt);2244 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
2245 const err_off = errUnionErrorOffset(payload_ty, pt);2245 const err_off = errUnionErrorOffset(payload_ty, zcu);
2246 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);2246 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), operand);
2247 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), .{ .immediate = 0 });2247 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 {...@@ -2254,20 +2254,20 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
2254/// E to E!T2254/// E to E!T
2255fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {2255fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
2256 const pt = self.pt;2256 const pt = self.pt;
2257 const mod = pt.zcu;2257 const zcu = pt.zcu;
2258 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2258 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2259 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2259 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2260 const error_union_ty = ty_op.ty.toType();2260 const error_union_ty = ty_op.ty.toType();
2261 const error_ty = error_union_ty.errorUnionSet(mod);2261 const error_ty = error_union_ty.errorUnionSet(zcu);
2262 const payload_ty = error_union_ty.errorUnionPayload(mod);2262 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2263 const operand = try self.resolveInst(ty_op.operand);2263 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));2266 const abi_size: u32 = @intCast(error_union_ty.abiSize(zcu));
2267 const abi_align = error_union_ty.abiAlignment(pt);2267 const abi_align = error_union_ty.abiAlignment(zcu);
2268 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));2268 const stack_offset: u32 = @intCast(try self.allocMem(abi_size, abi_align, inst));
2269 const payload_off = errUnionPayloadOffset(payload_ty, pt);2269 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
2270 const err_off = errUnionErrorOffset(payload_ty, pt);2270 const err_off = errUnionErrorOffset(payload_ty, zcu);
2271 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);2271 try self.genSetStack(error_ty, stack_offset - @as(u32, @intCast(err_off)), operand);
2272 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);2272 try self.genSetStack(payload_ty, stack_offset - @as(u32, @intCast(payload_off)), .undef);
22732273
...@@ -2372,9 +2372,9 @@ fn ptrElemVal(...@@ -2372,9 +2372,9 @@ fn ptrElemVal(
2372 maybe_inst: ?Air.Inst.Index,2372 maybe_inst: ?Air.Inst.Index,
2373) !MCValue {2373) !MCValue {
2374 const pt = self.pt;2374 const pt = self.pt;
2375 const mod = pt.zcu;2375 const zcu = pt.zcu;
2376 const elem_ty = ptr_ty.childType(mod);2376 const elem_ty = ptr_ty.childType(zcu);
2377 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));2377 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
23782378
2379 switch (elem_size) {2379 switch (elem_size) {
2380 1, 4 => {2380 1, 4 => {
...@@ -2432,11 +2432,11 @@ fn ptrElemVal(...@@ -2432,11 +2432,11 @@ fn ptrElemVal(
24322432
2433fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {2433fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2434 const pt = self.pt;2434 const pt = self.pt;
2435 const mod = pt.zcu;2435 const zcu = pt.zcu;
2436 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2436 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2437 const slice_ty = self.typeOf(bin_op.lhs);2437 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: {2438 const result: MCValue = if (!slice_ty.isVolatilePtr(zcu) and self.liveness.isUnused(inst)) .dead else result: {
2439 const ptr_ty = slice_ty.slicePtrFieldType(mod);2439 const ptr_ty = slice_ty.slicePtrFieldType(zcu);
24402440
2441 const slice_mcv = try self.resolveInst(bin_op.lhs);2441 const slice_mcv = try self.resolveInst(bin_op.lhs);
2442 const base_mcv = slicePtr(slice_mcv);2442 const base_mcv = slicePtr(slice_mcv);
...@@ -2476,8 +2476,8 @@ fn arrayElemVal(...@@ -2476,8 +2476,8 @@ fn arrayElemVal(
2476 maybe_inst: ?Air.Inst.Index,2476 maybe_inst: ?Air.Inst.Index,
2477) InnerError!MCValue {2477) InnerError!MCValue {
2478 const pt = self.pt;2478 const pt = self.pt;
2479 const mod = pt.zcu;2479 const zcu = pt.zcu;
2480 const elem_ty = array_ty.childType(mod);2480 const elem_ty = array_ty.childType(zcu);
24812481
2482 const mcv = try array_bind.resolveToMcv(self);2482 const mcv = try array_bind.resolveToMcv(self);
2483 switch (mcv) {2483 switch (mcv) {
...@@ -2533,10 +2533,10 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2533,10 +2533,10 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
25332533
2534fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {2534fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
2535 const pt = self.pt;2535 const pt = self.pt;
2536 const mod = pt.zcu;2536 const zcu = pt.zcu;
2537 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2537 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2538 const ptr_ty = self.typeOf(bin_op.lhs);2538 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: {
2540 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };2540 const base_bind: ReadArg.Bind = .{ .inst = bin_op.lhs };
2541 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };2541 const index_bind: ReadArg.Bind = .{ .inst = bin_op.rhs };
25422542
...@@ -2668,9 +2668,9 @@ fn reuseOperand(...@@ -2668,9 +2668,9 @@ fn reuseOperand(
26682668
2669fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {2669fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
2670 const pt = self.pt;2670 const pt = self.pt;
2671 const mod = pt.zcu;2671 const zcu = pt.zcu;
2672 const elem_ty = ptr_ty.childType(mod);2672 const elem_ty = ptr_ty.childType(zcu);
2673 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));2673 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
26742674
2675 switch (ptr) {2675 switch (ptr) {
2676 .none => unreachable,2676 .none => unreachable,
...@@ -2746,20 +2746,20 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo...@@ -2746,20 +2746,20 @@ fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!vo
27462746
2747fn airLoad(self: *Self, inst: Air.Inst.Index) !void {2747fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
2748 const pt = self.pt;2748 const pt = self.pt;
2749 const mod = pt.zcu;2749 const zcu = pt.zcu;
2750 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2750 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2751 const elem_ty = self.typeOfIndex(inst);2751 const elem_ty = self.typeOfIndex(inst);
2752 const result: MCValue = result: {2752 const result: MCValue = result: {
2753 if (!elem_ty.hasRuntimeBits(pt))2753 if (!elem_ty.hasRuntimeBits(zcu))
2754 break :result MCValue.none;2754 break :result MCValue.none;
27552755
2756 const ptr = try self.resolveInst(ty_op.operand);2756 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);
2758 if (self.liveness.isUnused(inst) and !is_volatile)2758 if (self.liveness.isUnused(inst) and !is_volatile)
2759 break :result MCValue.dead;2759 break :result MCValue.dead;
27602760
2761 const dest_mcv: MCValue = blk: {2761 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;
2763 if (ptr_fits_dest and self.reuseOperand(inst, ty_op.operand, 0, ptr)) {2763 if (ptr_fits_dest and self.reuseOperand(inst, ty_op.operand, 0, ptr)) {
2764 // The MCValue that holds the pointer can be re-used as the value.2764 // The MCValue that holds the pointer can be re-used as the value.
2765 break :blk ptr;2765 break :blk ptr;
...@@ -2776,7 +2776,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -2776,7 +2776,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
27762776
2777fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {2777fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
2778 const pt = self.pt;2778 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
2781 switch (ptr) {2781 switch (ptr) {
2782 .none => unreachable,2782 .none => unreachable,
...@@ -2896,11 +2896,11 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {...@@ -2896,11 +2896,11 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
2896fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {2896fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
2897 return if (self.liveness.isUnused(inst)) .dead else result: {2897 return if (self.liveness.isUnused(inst)) .dead else result: {
2898 const pt = self.pt;2898 const pt = self.pt;
2899 const mod = pt.zcu;2899 const zcu = pt.zcu;
2900 const mcv = try self.resolveInst(operand);2900 const mcv = try self.resolveInst(operand);
2901 const ptr_ty = self.typeOf(operand);2901 const ptr_ty = self.typeOf(operand);
2902 const struct_ty = ptr_ty.childType(mod);2902 const struct_ty = ptr_ty.childType(zcu);
2903 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, pt));2903 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, zcu));
2904 switch (mcv) {2904 switch (mcv) {
2905 .ptr_stack_offset => |off| {2905 .ptr_stack_offset => |off| {
2906 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };2906 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
...@@ -2921,12 +2921,12 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2921,12 +2921,12 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2921 const operand = extra.struct_operand;2921 const operand = extra.struct_operand;
2922 const index = extra.field_index;2922 const index = extra.field_index;
2923 const pt = self.pt;2923 const pt = self.pt;
2924 const mod = pt.zcu;2924 const zcu = pt.zcu;
2925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2925 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2926 const mcv = try self.resolveInst(operand);2926 const mcv = try self.resolveInst(operand);
2927 const struct_ty = self.typeOf(operand);2927 const struct_ty = self.typeOf(operand);
2928 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, pt));2928 const struct_field_offset: u32 = @intCast(struct_ty.structFieldOffset(index, zcu));
2929 const struct_field_ty = struct_ty.structFieldType(index, mod);2929 const struct_field_ty = struct_ty.fieldType(index, zcu);
29302930
2931 switch (mcv) {2931 switch (mcv) {
2932 .dead, .unreach => unreachable,2932 .dead, .unreach => unreachable,
...@@ -2989,10 +2989,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2989,10 +2989,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2989 );2989 );
29902990
2991 const field_bit_offset = struct_field_offset * 8;2991 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
2994 _ = try self.addInst(.{2994 _ = 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,
2996 .data = .{ .rr_lsb_width = .{2996 .data = .{ .rr_lsb_width = .{
2997 .rd = dest_reg,2997 .rd = dest_reg,
2998 .rn = operand_reg,2998 .rn = operand_reg,
...@@ -3012,18 +3012,18 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -3012,18 +3012,18 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
30123012
3013fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {3013fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
3014 const pt = self.pt;3014 const pt = self.pt;
3015 const mod = pt.zcu;3015 const zcu = pt.zcu;
3016 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3016 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3017 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;3017 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
3018 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {3018 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
3019 const field_ptr = try self.resolveInst(extra.field_ptr);3019 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) {
3023 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});3023 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});
3024 }3024 }
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));
3027 switch (field_ptr) {3027 switch (field_ptr) {
3028 .ptr_stack_offset => |off| {3028 .ptr_stack_offset => |off| {
3029 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };3029 break :result MCValue{ .ptr_stack_offset = off + struct_field_offset };
...@@ -3407,13 +3407,13 @@ fn addSub(...@@ -3407,13 +3407,13 @@ fn addSub(
3407 maybe_inst: ?Air.Inst.Index,3407 maybe_inst: ?Air.Inst.Index,
3408) InnerError!MCValue {3408) InnerError!MCValue {
3409 const pt = self.pt;3409 const pt = self.pt;
3410 const mod = pt.zcu;3410 const zcu = pt.zcu;
3411 switch (lhs_ty.zigTypeTag(mod)) {3411 switch (lhs_ty.zigTypeTag(zcu)) {
3412 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3412 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3413 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3413 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3414 .Int => {3414 .Int => {
3415 assert(lhs_ty.eql(rhs_ty, mod));3415 assert(lhs_ty.eql(rhs_ty, zcu));
3416 const int_info = lhs_ty.intInfo(mod);3416 const int_info = lhs_ty.intInfo(zcu);
3417 if (int_info.bits <= 32) {3417 if (int_info.bits <= 32) {
3418 const lhs_immediate = try lhs_bind.resolveToImmediate(self);3418 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
3419 const rhs_immediate = try rhs_bind.resolveToImmediate(self);3419 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
...@@ -3464,13 +3464,13 @@ fn mul(...@@ -3464,13 +3464,13 @@ fn mul(
3464 maybe_inst: ?Air.Inst.Index,3464 maybe_inst: ?Air.Inst.Index,
3465) InnerError!MCValue {3465) InnerError!MCValue {
3466 const pt = self.pt;3466 const pt = self.pt;
3467 const mod = pt.zcu;3467 const zcu = pt.zcu;
3468 switch (lhs_ty.zigTypeTag(mod)) {3468 switch (lhs_ty.zigTypeTag(zcu)) {
3469 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3469 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3470 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3470 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3471 .Int => {3471 .Int => {
3472 assert(lhs_ty.eql(rhs_ty, mod));3472 assert(lhs_ty.eql(rhs_ty, zcu));
3473 const int_info = lhs_ty.intInfo(mod);3473 const int_info = lhs_ty.intInfo(zcu);
3474 if (int_info.bits <= 32) {3474 if (int_info.bits <= 32) {
3475 // TODO add optimisations for multiplication3475 // TODO add optimisations for multiplication
3476 // with immediates, for example a * 2 can be3476 // with immediates, for example a * 2 can be
...@@ -3498,8 +3498,8 @@ fn divFloat(...@@ -3498,8 +3498,8 @@ fn divFloat(
3498 _ = maybe_inst;3498 _ = maybe_inst;
34993499
3500 const pt = self.pt;3500 const pt = self.pt;
3501 const mod = pt.zcu;3501 const zcu = pt.zcu;
3502 switch (lhs_ty.zigTypeTag(mod)) {3502 switch (lhs_ty.zigTypeTag(zcu)) {
3503 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3503 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3504 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3504 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3505 else => unreachable,3505 else => unreachable,
...@@ -3515,13 +3515,13 @@ fn divTrunc(...@@ -3515,13 +3515,13 @@ fn divTrunc(
3515 maybe_inst: ?Air.Inst.Index,3515 maybe_inst: ?Air.Inst.Index,
3516) InnerError!MCValue {3516) InnerError!MCValue {
3517 const pt = self.pt;3517 const pt = self.pt;
3518 const mod = pt.zcu;3518 const zcu = pt.zcu;
3519 switch (lhs_ty.zigTypeTag(mod)) {3519 switch (lhs_ty.zigTypeTag(zcu)) {
3520 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3520 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3521 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3521 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3522 .Int => {3522 .Int => {
3523 assert(lhs_ty.eql(rhs_ty, mod));3523 assert(lhs_ty.eql(rhs_ty, zcu));
3524 const int_info = lhs_ty.intInfo(mod);3524 const int_info = lhs_ty.intInfo(zcu);
3525 if (int_info.bits <= 32) {3525 if (int_info.bits <= 32) {
3526 switch (int_info.signedness) {3526 switch (int_info.signedness) {
3527 .signed => {3527 .signed => {
...@@ -3559,13 +3559,13 @@ fn divFloor(...@@ -3559,13 +3559,13 @@ fn divFloor(
3559 maybe_inst: ?Air.Inst.Index,3559 maybe_inst: ?Air.Inst.Index,
3560) InnerError!MCValue {3560) InnerError!MCValue {
3561 const pt = self.pt;3561 const pt = self.pt;
3562 const mod = pt.zcu;3562 const zcu = pt.zcu;
3563 switch (lhs_ty.zigTypeTag(mod)) {3563 switch (lhs_ty.zigTypeTag(zcu)) {
3564 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3564 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3565 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3565 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3566 .Int => {3566 .Int => {
3567 assert(lhs_ty.eql(rhs_ty, mod));3567 assert(lhs_ty.eql(rhs_ty, zcu));
3568 const int_info = lhs_ty.intInfo(mod);3568 const int_info = lhs_ty.intInfo(zcu);
3569 if (int_info.bits <= 32) {3569 if (int_info.bits <= 32) {
3570 switch (int_info.signedness) {3570 switch (int_info.signedness) {
3571 .signed => {3571 .signed => {
...@@ -3608,8 +3608,8 @@ fn divExact(...@@ -3608,8 +3608,8 @@ fn divExact(
3608 _ = maybe_inst;3608 _ = maybe_inst;
36093609
3610 const pt = self.pt;3610 const pt = self.pt;
3611 const mod = pt.zcu;3611 const zcu = pt.zcu;
3612 switch (lhs_ty.zigTypeTag(mod)) {3612 switch (lhs_ty.zigTypeTag(zcu)) {
3613 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3613 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3614 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3614 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3615 .Int => return self.fail("TODO ARM div_exact", .{}),3615 .Int => return self.fail("TODO ARM div_exact", .{}),
...@@ -3626,17 +3626,17 @@ fn rem(...@@ -3626,17 +3626,17 @@ fn rem(
3626 maybe_inst: ?Air.Inst.Index,3626 maybe_inst: ?Air.Inst.Index,
3627) InnerError!MCValue {3627) InnerError!MCValue {
3628 const pt = self.pt;3628 const pt = self.pt;
3629 const mod = pt.zcu;3629 const zcu = pt.zcu;
3630 switch (lhs_ty.zigTypeTag(mod)) {3630 switch (lhs_ty.zigTypeTag(zcu)) {
3631 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3631 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3632 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3632 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3633 .Int => {3633 .Int => {
3634 assert(lhs_ty.eql(rhs_ty, mod));3634 assert(lhs_ty.eql(rhs_ty, zcu));
3635 const int_info = lhs_ty.intInfo(mod);3635 const int_info = lhs_ty.intInfo(zcu);
3636 if (int_info.bits <= 32) {3636 if (int_info.bits <= 32) {
3637 switch (int_info.signedness) {3637 switch (int_info.signedness) {
3638 .signed => {3638 .signed => {
3639 return self.fail("TODO ARM signed integer mod", .{});3639 return self.fail("TODO ARM signed integer zcu", .{});
3640 },3640 },
3641 .unsigned => {3641 .unsigned => {
3642 const rhs_immediate = try rhs_bind.resolveToImmediate(self);3642 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
...@@ -3667,10 +3667,10 @@ fn rem(...@@ -3667,10 +3667,10 @@ fn rem(
36673667
3668 return MCValue{ .register = dest_reg };3668 return MCValue{ .register = dest_reg };
3669 } else {3669 } else {
3670 return self.fail("TODO ARM integer mod by constants", .{});3670 return self.fail("TODO ARM integer zcu by constants", .{});
3671 }3671 }
3672 } else {3672 } else {
3673 return self.fail("TODO ARM integer mod", .{});3673 return self.fail("TODO ARM integer zcu", .{});
3674 }3674 }
3675 },3675 },
3676 }3676 }
...@@ -3696,11 +3696,11 @@ fn modulo(...@@ -3696,11 +3696,11 @@ fn modulo(
3696 _ = maybe_inst;3696 _ = maybe_inst;
36973697
3698 const pt = self.pt;3698 const pt = self.pt;
3699 const mod = pt.zcu;3699 const zcu = pt.zcu;
3700 switch (lhs_ty.zigTypeTag(mod)) {3700 switch (lhs_ty.zigTypeTag(zcu)) {
3701 .Float => return self.fail("TODO ARM binary operations on floats", .{}),3701 .Float => return self.fail("TODO ARM binary operations on floats", .{}),
3702 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3702 .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", .{}),
3704 else => unreachable,3704 else => unreachable,
3705 }3705 }
3706}3706}
...@@ -3715,11 +3715,11 @@ fn wrappingArithmetic(...@@ -3715,11 +3715,11 @@ fn wrappingArithmetic(
3715 maybe_inst: ?Air.Inst.Index,3715 maybe_inst: ?Air.Inst.Index,
3716) InnerError!MCValue {3716) InnerError!MCValue {
3717 const pt = self.pt;3717 const pt = self.pt;
3718 const mod = pt.zcu;3718 const zcu = pt.zcu;
3719 switch (lhs_ty.zigTypeTag(mod)) {3719 switch (lhs_ty.zigTypeTag(zcu)) {
3720 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3720 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3721 .Int => {3721 .Int => {
3722 const int_info = lhs_ty.intInfo(mod);3722 const int_info = lhs_ty.intInfo(zcu);
3723 if (int_info.bits <= 32) {3723 if (int_info.bits <= 32) {
3724 // Generate an add/sub/mul3724 // Generate an add/sub/mul
3725 const result: MCValue = switch (tag) {3725 const result: MCValue = switch (tag) {
...@@ -3754,12 +3754,12 @@ fn bitwise(...@@ -3754,12 +3754,12 @@ fn bitwise(
3754 maybe_inst: ?Air.Inst.Index,3754 maybe_inst: ?Air.Inst.Index,
3755) InnerError!MCValue {3755) InnerError!MCValue {
3756 const pt = self.pt;3756 const pt = self.pt;
3757 const mod = pt.zcu;3757 const zcu = pt.zcu;
3758 switch (lhs_ty.zigTypeTag(mod)) {3758 switch (lhs_ty.zigTypeTag(zcu)) {
3759 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3759 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3760 .Int => {3760 .Int => {
3761 assert(lhs_ty.eql(rhs_ty, mod));3761 assert(lhs_ty.eql(rhs_ty, zcu));
3762 const int_info = lhs_ty.intInfo(mod);3762 const int_info = lhs_ty.intInfo(zcu);
3763 if (int_info.bits <= 32) {3763 if (int_info.bits <= 32) {
3764 const lhs_immediate = try lhs_bind.resolveToImmediate(self);3764 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
3765 const rhs_immediate = try rhs_bind.resolveToImmediate(self);3765 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
...@@ -3800,17 +3800,17 @@ fn shiftExact(...@@ -3800,17 +3800,17 @@ fn shiftExact(
3800 maybe_inst: ?Air.Inst.Index,3800 maybe_inst: ?Air.Inst.Index,
3801) InnerError!MCValue {3801) InnerError!MCValue {
3802 const pt = self.pt;3802 const pt = self.pt;
3803 const mod = pt.zcu;3803 const zcu = pt.zcu;
3804 switch (lhs_ty.zigTypeTag(mod)) {3804 switch (lhs_ty.zigTypeTag(zcu)) {
3805 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3805 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3806 .Int => {3806 .Int => {
3807 const int_info = lhs_ty.intInfo(mod);3807 const int_info = lhs_ty.intInfo(zcu);
3808 if (int_info.bits <= 32) {3808 if (int_info.bits <= 32) {
3809 const rhs_immediate = try rhs_bind.resolveToImmediate(self);3809 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
38103810
3811 const mir_tag: Mir.Inst.Tag = switch (tag) {3811 const mir_tag: Mir.Inst.Tag = switch (tag) {
3812 .shl_exact => .lsl,3812 .shl_exact => .lsl,
3813 .shr_exact => switch (lhs_ty.intInfo(mod).signedness) {3813 .shr_exact => switch (lhs_ty.intInfo(zcu).signedness) {
3814 .signed => Mir.Inst.Tag.asr,3814 .signed => Mir.Inst.Tag.asr,
3815 .unsigned => Mir.Inst.Tag.lsr,3815 .unsigned => Mir.Inst.Tag.lsr,
3816 },3816 },
...@@ -3840,11 +3840,11 @@ fn shiftNormal(...@@ -3840,11 +3840,11 @@ fn shiftNormal(
3840 maybe_inst: ?Air.Inst.Index,3840 maybe_inst: ?Air.Inst.Index,
3841) InnerError!MCValue {3841) InnerError!MCValue {
3842 const pt = self.pt;3842 const pt = self.pt;
3843 const mod = pt.zcu;3843 const zcu = pt.zcu;
3844 switch (lhs_ty.zigTypeTag(mod)) {3844 switch (lhs_ty.zigTypeTag(zcu)) {
3845 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),3845 .Vector => return self.fail("TODO ARM binary operations on vectors", .{}),
3846 .Int => {3846 .Int => {
3847 const int_info = lhs_ty.intInfo(mod);3847 const int_info = lhs_ty.intInfo(zcu);
3848 if (int_info.bits <= 32) {3848 if (int_info.bits <= 32) {
3849 // Generate a shl_exact/shr_exact3849 // Generate a shl_exact/shr_exact
3850 const result: MCValue = switch (tag) {3850 const result: MCValue = switch (tag) {
...@@ -3884,8 +3884,8 @@ fn booleanOp(...@@ -3884,8 +3884,8 @@ fn booleanOp(
3884 maybe_inst: ?Air.Inst.Index,3884 maybe_inst: ?Air.Inst.Index,
3885) InnerError!MCValue {3885) InnerError!MCValue {
3886 const pt = self.pt;3886 const pt = self.pt;
3887 const mod = pt.zcu;3887 const zcu = pt.zcu;
3888 switch (lhs_ty.zigTypeTag(mod)) {3888 switch (lhs_ty.zigTypeTag(zcu)) {
3889 .Bool => {3889 .Bool => {
3890 const lhs_immediate = try lhs_bind.resolveToImmediate(self);3890 const lhs_immediate = try lhs_bind.resolveToImmediate(self);
3891 const rhs_immediate = try rhs_bind.resolveToImmediate(self);3891 const rhs_immediate = try rhs_bind.resolveToImmediate(self);
...@@ -3919,17 +3919,17 @@ fn ptrArithmetic(...@@ -3919,17 +3919,17 @@ fn ptrArithmetic(
3919 maybe_inst: ?Air.Inst.Index,3919 maybe_inst: ?Air.Inst.Index,
3920) InnerError!MCValue {3920) InnerError!MCValue {
3921 const pt = self.pt;3921 const pt = self.pt;
3922 const mod = pt.zcu;3922 const zcu = pt.zcu;
3923 switch (lhs_ty.zigTypeTag(mod)) {3923 switch (lhs_ty.zigTypeTag(zcu)) {
3924 .Pointer => {3924 .Pointer => {
3925 assert(rhs_ty.eql(Type.usize, mod));3925 assert(rhs_ty.eql(Type.usize, zcu));
39263926
3927 const ptr_ty = lhs_ty;3927 const ptr_ty = lhs_ty;
3928 const elem_ty = switch (ptr_ty.ptrSize(mod)) {3928 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
3929 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type3929 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
3930 else => ptr_ty.childType(mod),3930 else => ptr_ty.childType(zcu),
3931 };3931 };
3932 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));3932 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
39333933
3934 const base_tag: Air.Inst.Tag = switch (tag) {3934 const base_tag: Air.Inst.Tag = switch (tag) {
3935 .ptr_add => .add,3935 .ptr_add => .add,
...@@ -3957,12 +3957,12 @@ fn ptrArithmetic(...@@ -3957,12 +3957,12 @@ fn ptrArithmetic(
39573957
3958fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type) !void {3958fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type) !void {
3959 const pt = self.pt;3959 const pt = self.pt;
3960 const mod = pt.zcu;3960 const zcu = pt.zcu;
3961 const abi_size = ty.abiSize(pt);3961 const abi_size = ty.abiSize(zcu);
39623962
3963 const tag: Mir.Inst.Tag = switch (abi_size) {3963 const tag: Mir.Inst.Tag = switch (abi_size) {
3964 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,3964 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb else .ldrb,
3965 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh else .ldrh,3965 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh else .ldrh,
3966 3, 4 => .ldr,3966 3, 4 => .ldr,
3967 else => unreachable,3967 else => unreachable,
3968 };3968 };
...@@ -3979,7 +3979,7 @@ fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type)...@@ -3979,7 +3979,7 @@ fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type)
3979 } };3979 } };
39803980
3981 const data: Mir.Inst.Data = switch (abi_size) {3981 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,
3983 2 => rr_extra_offset,3983 2 => rr_extra_offset,
3984 3, 4 => rr_offset,3984 3, 4 => rr_offset,
3985 else => unreachable,3985 else => unreachable,
...@@ -3993,7 +3993,7 @@ fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type)...@@ -3993,7 +3993,7 @@ fn genLdrRegister(self: *Self, dest_reg: Register, addr_reg: Register, ty: Type)
39933993
3994fn genStrRegister(self: *Self, source_reg: Register, addr_reg: Register, ty: Type) !void {3994fn genStrRegister(self: *Self, source_reg: Register, addr_reg: Register, ty: Type) !void {
3995 const pt = self.pt;3995 const pt = self.pt;
3996 const abi_size = ty.abiSize(pt);3996 const abi_size = ty.abiSize(pt.zcu);
39973997
3998 const tag: Mir.Inst.Tag = switch (abi_size) {3998 const tag: Mir.Inst.Tag = switch (abi_size) {
3999 1 => .strb,3999 1 => .strb,
...@@ -4253,12 +4253,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4253,12 +4253,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4253 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);4253 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
4254 const ty = self.typeOf(callee);4254 const ty = self.typeOf(callee);
4255 const pt = self.pt;4255 const pt = self.pt;
4256 const mod = pt.zcu;4256 const zcu = pt.zcu;
4257 const ip = &mod.intern_pool;4257 const ip = &zcu.intern_pool;
42584258
4259 const fn_ty = switch (ty.zigTypeTag(mod)) {4259 const fn_ty = switch (ty.zigTypeTag(zcu)) {
4260 .Fn => ty,4260 .Fn => ty,
4261 .Pointer => ty.childType(mod),4261 .Pointer => ty.childType(zcu),
4262 else => unreachable,4262 else => unreachable,
4263 };4263 };
42644264
...@@ -4283,9 +4283,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4283,9 +4283,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4283 // untouched by the parameter passing code4283 // untouched by the parameter passing code
4284 const r0_lock: ?RegisterLock = if (info.return_value == .stack_offset) blk: {4284 const r0_lock: ?RegisterLock = if (info.return_value == .stack_offset) blk: {
4285 log.debug("airCall: return by reference", .{});4285 log.debug("airCall: return by reference", .{});
4286 const ret_ty = fn_ty.fnReturnType(mod);4286 const ret_ty = fn_ty.fnReturnType(zcu);
4287 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(pt));4287 const ret_abi_size: u32 = @intCast(ret_ty.abiSize(zcu));
4288 const ret_abi_align = ret_ty.abiAlignment(pt);4288 const ret_abi_align = ret_ty.abiAlignment(zcu);
4289 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);4289 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
42904290
4291 const ptr_ty = try pt.singleMutPtrType(ret_ty);4291 const ptr_ty = try pt.singleMutPtrType(ret_ty);
...@@ -4335,7 +4335,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4335,7 +4335,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4335 return self.fail("TODO implement calling bitcasted functions", .{});4335 return self.fail("TODO implement calling bitcasted functions", .{});
4336 },4336 },
4337 } else {4337 } else {
4338 assert(ty.zigTypeTag(mod) == .Pointer);4338 assert(ty.zigTypeTag(zcu) == .Pointer);
4339 const mcv = try self.resolveInst(callee);4339 const mcv = try self.resolveInst(callee);
43404340
4341 try self.genSetReg(Type.usize, .lr, mcv);4341 try self.genSetReg(Type.usize, .lr, mcv);
...@@ -4370,7 +4370,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4370,7 +4370,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
4370 if (RegisterManager.indexOfRegIntoTracked(reg) == null) {4370 if (RegisterManager.indexOfRegIntoTracked(reg) == null) {
4371 // Save function return value into a tracked register4371 // Save function return value into a tracked register
4372 log.debug("airCall: copying {} as it is not tracked", .{reg});4372 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);
4374 break :result MCValue{ .register = new_reg };4374 break :result MCValue{ .register = new_reg };
4375 }4375 }
4376 },4376 },
...@@ -4395,15 +4395,15 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -4395,15 +4395,15 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
43954395
4396fn airRet(self: *Self, inst: Air.Inst.Index) !void {4396fn airRet(self: *Self, inst: Air.Inst.Index) !void {
4397 const pt = self.pt;4397 const pt = self.pt;
4398 const mod = pt.zcu;4398 const zcu = pt.zcu;
4399 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4399 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4400 const operand = try self.resolveInst(un_op);4400 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
4403 switch (self.ret_mcv) {4403 switch (self.ret_mcv) {
4404 .none => {},4404 .none => {},
4405 .immediate => {4405 .immediate => {
4406 assert(ret_ty.isError(mod));4406 assert(ret_ty.isError(zcu));
4407 },4407 },
4408 .register => |reg| {4408 .register => |reg| {
4409 // Return result by value4409 // Return result by value
...@@ -4428,11 +4428,11 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {...@@ -4428,11 +4428,11 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44284428
4429fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {4429fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4430 const pt = self.pt;4430 const pt = self.pt;
4431 const mod = pt.zcu;4431 const zcu = pt.zcu;
4432 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4432 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4433 const ptr = try self.resolveInst(un_op);4433 const ptr = try self.resolveInst(un_op);
4434 const ptr_ty = self.typeOf(un_op);4434 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
4437 switch (self.ret_mcv) {4437 switch (self.ret_mcv) {
4438 .none => {},4438 .none => {},
...@@ -4452,8 +4452,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -4452,8 +4452,8 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
4452 // location.4452 // location.
4453 const op_inst = un_op.toIndex().?;4453 const op_inst = un_op.toIndex().?;
4454 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {4454 if (self.air.instructions.items(.tag)[@intFromEnum(op_inst)] != .ret_ptr) {
4455 const abi_size: u32 = @intCast(ret_ty.abiSize(pt));4455 const abi_size: u32 = @intCast(ret_ty.abiSize(zcu));
4456 const abi_align = ret_ty.abiAlignment(pt);4456 const abi_align = ret_ty.abiAlignment(zcu);
44574457
4458 const offset = try self.allocMem(abi_size, abi_align, null);4458 const offset = try self.allocMem(abi_size, abi_align, null);
44594459
...@@ -4490,20 +4490,20 @@ fn cmp(...@@ -4490,20 +4490,20 @@ fn cmp(
4490 op: math.CompareOperator,4490 op: math.CompareOperator,
4491) !MCValue {4491) !MCValue {
4492 const pt = self.pt;4492 const pt = self.pt;
4493 const mod = pt.zcu;4493 const zcu = pt.zcu;
4494 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {4494 const int_ty = switch (lhs_ty.zigTypeTag(zcu)) {
4495 .Optional => blk: {4495 .Optional => blk: {
4496 const payload_ty = lhs_ty.optionalChild(mod);4496 const payload_ty = lhs_ty.optionalChild(zcu);
4497 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4497 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4498 break :blk Type.u1;4498 break :blk Type.u1;
4499 } else if (lhs_ty.isPtrLikeOptional(mod)) {4499 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
4500 break :blk Type.usize;4500 break :blk Type.usize;
4501 } else {4501 } else {
4502 return self.fail("TODO ARM cmp non-pointer optionals", .{});4502 return self.fail("TODO ARM cmp non-pointer optionals", .{});
4503 }4503 }
4504 },4504 },
4505 .Float => return self.fail("TODO ARM cmp floats", .{}),4505 .Float => return self.fail("TODO ARM cmp floats", .{}),
4506 .Enum => lhs_ty.intTagType(mod),4506 .Enum => lhs_ty.intTagType(zcu),
4507 .Int => lhs_ty,4507 .Int => lhs_ty,
4508 .Bool => Type.u1,4508 .Bool => Type.u1,
4509 .Pointer => Type.usize,4509 .Pointer => Type.usize,
...@@ -4511,7 +4511,7 @@ fn cmp(...@@ -4511,7 +4511,7 @@ fn cmp(
4511 else => unreachable,4511 else => unreachable,
4512 };4512 };
45134513
4514 const int_info = int_ty.intInfo(mod);4514 const int_info = int_ty.intInfo(zcu);
4515 if (int_info.bits <= 32) {4515 if (int_info.bits <= 32) {
4516 try self.spillCompareFlagsIfOccupied();4516 try self.spillCompareFlagsIfOccupied();
45174517
...@@ -4597,10 +4597,10 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {...@@ -4597,10 +4597,10 @@ fn airDbgStmt(self: *Self, inst: Air.Inst.Index) !void {
45974597
4598fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {4598fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {
4599 const pt = self.pt;4599 const pt = self.pt;
4600 const mod = pt.zcu;4600 const zcu = pt.zcu;
4601 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4601 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4602 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);4602 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);
4604 // TODO emit debug info for function change4604 // TODO emit debug info for function change
4605 _ = func;4605 _ = func;
4606 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));4606 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
...@@ -4810,9 +4810,9 @@ fn isNull(...@@ -4810,9 +4810,9 @@ fn isNull(
4810 operand_ty: Type,4810 operand_ty: Type,
4811) !MCValue {4811) !MCValue {
4812 const pt = self.pt;4812 const pt = self.pt;
4813 const mod = pt.zcu;4813 const zcu = pt.zcu;
4814 if (operand_ty.isPtrLikeOptional(mod)) {4814 if (operand_ty.isPtrLikeOptional(zcu)) {
4815 assert(operand_ty.abiSize(pt) == 4);4815 assert(operand_ty.abiSize(zcu) == 4);
48164816
4817 const imm_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = 0 } };4817 const imm_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = 0 } };
4818 return self.cmp(operand_bind, imm_bind, Type.usize, .eq);4818 return self.cmp(operand_bind, imm_bind, Type.usize, .eq);
...@@ -4845,12 +4845,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4845,12 +4845,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
48454845
4846fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {4846fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4847 const pt = self.pt;4847 const pt = self.pt;
4848 const mod = pt.zcu;4848 const zcu = pt.zcu;
4849 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4849 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4850 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4850 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4851 const operand_ptr = try self.resolveInst(un_op);4851 const operand_ptr = try self.resolveInst(un_op);
4852 const ptr_ty = self.typeOf(un_op);4852 const ptr_ty = self.typeOf(un_op);
4853 const elem_ty = ptr_ty.childType(mod);4853 const elem_ty = ptr_ty.childType(zcu);
48544854
4855 const operand = try self.allocRegOrMem(elem_ty, true, null);4855 const operand = try self.allocRegOrMem(elem_ty, true, null);
4856 try self.load(operand, operand_ptr, ptr_ty);4856 try self.load(operand, operand_ptr, ptr_ty);
...@@ -4873,12 +4873,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {...@@ -4873,12 +4873,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
48734873
4874fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {4874fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4875 const pt = self.pt;4875 const pt = self.pt;
4876 const mod = pt.zcu;4876 const zcu = pt.zcu;
4877 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4877 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4878 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4878 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4879 const operand_ptr = try self.resolveInst(un_op);4879 const operand_ptr = try self.resolveInst(un_op);
4880 const ptr_ty = self.typeOf(un_op);4880 const ptr_ty = self.typeOf(un_op);
4881 const elem_ty = ptr_ty.childType(mod);4881 const elem_ty = ptr_ty.childType(zcu);
48824882
4883 const operand = try self.allocRegOrMem(elem_ty, true, null);4883 const operand = try self.allocRegOrMem(elem_ty, true, null);
4884 try self.load(operand, operand_ptr, ptr_ty);4884 try self.load(operand, operand_ptr, ptr_ty);
...@@ -4894,10 +4894,10 @@ fn isErr(...@@ -4894,10 +4894,10 @@ fn isErr(
4894 error_union_ty: Type,4894 error_union_ty: Type,
4895) !MCValue {4895) !MCValue {
4896 const pt = self.pt;4896 const pt = self.pt;
4897 const mod = pt.zcu;4897 const zcu = pt.zcu;
4898 const error_type = error_union_ty.errorUnionSet(mod);4898 const error_type = error_union_ty.errorUnionSet(zcu);
48994899
4900 if (error_type.errorSetIsEmpty(mod)) {4900 if (error_type.errorSetIsEmpty(zcu)) {
4901 return MCValue{ .immediate = 0 }; // always false4901 return MCValue{ .immediate = 0 }; // always false
4902 }4902 }
49034903
...@@ -4937,12 +4937,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4937,12 +4937,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49374937
4938fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {4938fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4939 const pt = self.pt;4939 const pt = self.pt;
4940 const mod = pt.zcu;4940 const zcu = pt.zcu;
4941 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4941 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4942 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4942 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4943 const operand_ptr = try self.resolveInst(un_op);4943 const operand_ptr = try self.resolveInst(un_op);
4944 const ptr_ty = self.typeOf(un_op);4944 const ptr_ty = self.typeOf(un_op);
4945 const elem_ty = ptr_ty.childType(mod);4945 const elem_ty = ptr_ty.childType(zcu);
49464946
4947 const operand = try self.allocRegOrMem(elem_ty, true, null);4947 const operand = try self.allocRegOrMem(elem_ty, true, null);
4948 try self.load(operand, operand_ptr, ptr_ty);4948 try self.load(operand, operand_ptr, ptr_ty);
...@@ -4965,12 +4965,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -4965,12 +4965,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
49654965
4966fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {4966fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4967 const pt = self.pt;4967 const pt = self.pt;
4968 const mod = pt.zcu;4968 const zcu = pt.zcu;
4969 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4969 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4970 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {4970 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4971 const operand_ptr = try self.resolveInst(un_op);4971 const operand_ptr = try self.resolveInst(un_op);
4972 const ptr_ty = self.typeOf(un_op);4972 const ptr_ty = self.typeOf(un_op);
4973 const elem_ty = ptr_ty.childType(mod);4973 const elem_ty = ptr_ty.childType(zcu);
49744974
4975 const operand = try self.allocRegOrMem(elem_ty, true, null);4975 const operand = try self.allocRegOrMem(elem_ty, true, null);
4976 try self.load(operand, operand_ptr, ptr_ty);4976 try self.load(operand, operand_ptr, ptr_ty);
...@@ -5184,10 +5184,10 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5184,10 +5184,10 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
5184}5184}
51855185
5186fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {5186fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
5187 const pt = self.pt;5187 const zcu = self.pt.zcu;
5188 const block_data = self.blocks.getPtr(block).?;5188 const block_data = self.blocks.getPtr(block).?;
51895189
5190 if (self.typeOf(operand).hasRuntimeBits(pt)) {5190 if (self.typeOf(operand).hasRuntimeBits(zcu)) {
5191 const operand_mcv = try self.resolveInst(operand);5191 const operand_mcv = try self.resolveInst(operand);
5192 const block_mcv = block_data.mcv;5192 const block_mcv = block_data.mcv;
5193 if (block_mcv == .none) {5193 if (block_mcv == .none) {
...@@ -5356,8 +5356,8 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {...@@ -5356,8 +5356,8 @@ fn setRegOrMem(self: *Self, ty: Type, loc: MCValue, val: MCValue) !void {
53565356
5357fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5357fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5358 const pt = self.pt;5358 const pt = self.pt;
5359 const mod = pt.zcu;5359 const zcu = pt.zcu;
5360 const abi_size: u32 = @intCast(ty.abiSize(pt));5360 const abi_size: u32 = @intCast(ty.abiSize(zcu));
5361 switch (mcv) {5361 switch (mcv) {
5362 .dead => unreachable,5362 .dead => unreachable,
5363 .unreach, .none => return, // Nothing to do.5363 .unreach, .none => return, // Nothing to do.
...@@ -5434,11 +5434,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5434,11 +5434,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
5434 const reg_lock = self.register_manager.lockReg(reg);5434 const reg_lock = self.register_manager.lockReg(reg);
5435 defer if (reg_lock) |locked_reg| self.register_manager.unlockReg(locked_reg);5435 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);
5438 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });5438 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = reg });
54395439
5440 const overflow_bit_ty = ty.structFieldType(1, mod);5440 const overflow_bit_ty = ty.fieldType(1, zcu);
5441 const overflow_bit_offset: u32 = @intCast(ty.structFieldOffset(1, pt));5441 const overflow_bit_offset: u32 = @intCast(ty.structFieldOffset(1, zcu));
5442 const cond_reg = try self.register_manager.allocReg(null, gp);5442 const cond_reg = try self.register_manager.allocReg(null, gp);
54435443
5444 // C flag: movcs reg, #15444 // C flag: movcs reg, #1
...@@ -5519,7 +5519,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -5519,7 +5519,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
55195519
5520fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {5520fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {
5521 const pt = self.pt;5521 const pt = self.pt;
5522 const mod = pt.zcu;5522 const zcu = pt.zcu;
5523 switch (mcv) {5523 switch (mcv) {
5524 .dead => unreachable,5524 .dead => unreachable,
5525 .unreach, .none => return, // Nothing to do.5525 .unreach, .none => return, // Nothing to do.
...@@ -5694,17 +5694,17 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5694,17 +5694,17 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5694 },5694 },
5695 .stack_offset => |off| {5695 .stack_offset => |off| {
5696 // TODO: maybe addressing from sp instead of fp5696 // 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
5699 const tag: Mir.Inst.Tag = switch (abi_size) {5699 const tag: Mir.Inst.Tag = switch (abi_size) {
5700 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb else .ldrb,5700 1 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsb else .ldrb,
5701 2 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsh else .ldrh,5701 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh else .ldrh,
5702 3, 4 => .ldr,5702 3, 4 => .ldr,
5703 else => unreachable,5703 else => unreachable,
5704 };5704 };
57055705
5706 const extra_offset = switch (abi_size) {5706 const extra_offset = switch (abi_size) {
5707 1 => ty.isSignedInt(mod),5707 1 => ty.isSignedInt(zcu),
5708 2 => true,5708 2 => true,
5709 3, 4 => false,5709 3, 4 => false,
5710 else => unreachable,5710 else => unreachable,
...@@ -5745,11 +5745,11 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5745,11 +5745,11 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
5745 }5745 }
5746 },5746 },
5747 .stack_argument_offset => |off| {5747 .stack_argument_offset => |off| {
5748 const abi_size = ty.abiSize(pt);5748 const abi_size = ty.abiSize(zcu);
57495749
5750 const tag: Mir.Inst.Tag = switch (abi_size) {5750 const tag: Mir.Inst.Tag = switch (abi_size) {
5751 1 => if (ty.isSignedInt(mod)) Mir.Inst.Tag.ldrsb_stack_argument else .ldrb_stack_argument,5751 1 => if (ty.isSignedInt(zcu)) 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,5752 2 => if (ty.isSignedInt(zcu)) Mir.Inst.Tag.ldrsh_stack_argument else .ldrh_stack_argument,
5753 3, 4 => .ldr_stack_argument,5753 3, 4 => .ldr_stack_argument,
5754 else => unreachable,5754 else => unreachable,
5755 };5755 };
...@@ -5767,7 +5767,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -5767,7 +5767,7 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
57675767
5768fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {5768fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
5769 const pt = self.pt;5769 const pt = self.pt;
5770 const abi_size: u32 = @intCast(ty.abiSize(pt));5770 const abi_size: u32 = @intCast(ty.abiSize(pt.zcu));
5771 switch (mcv) {5771 switch (mcv) {
5772 .dead => unreachable,5772 .dead => unreachable,
5773 .none, .unreach => return,5773 .none, .unreach => return,
...@@ -5923,13 +5923,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -5923,13 +5923,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59235923
5924fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {5924fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5925 const pt = self.pt;5925 const pt = self.pt;
5926 const mod = pt.zcu;5926 const zcu = pt.zcu;
5927 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5927 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5928 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {5928 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
5929 const ptr_ty = self.typeOf(ty_op.operand);5929 const ptr_ty = self.typeOf(ty_op.operand);
5930 const ptr = try self.resolveInst(ty_op.operand);5930 const ptr = try self.resolveInst(ty_op.operand);
5931 const array_ty = ptr_ty.childType(mod);5931 const array_ty = ptr_ty.childType(zcu);
5932 const array_len: u32 = @intCast(array_ty.arrayLen(mod));5932 const array_len: u32 = @intCast(array_ty.arrayLen(zcu));
59335933
5934 const stack_offset = try self.allocMem(8, .@"8", inst);5934 const stack_offset = try self.allocMem(8, .@"8", inst);
5935 try self.genSetStack(ptr_ty, stack_offset, ptr);5935 try self.genSetStack(ptr_ty, stack_offset, ptr);
...@@ -6043,9 +6043,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {...@@ -6043,9 +6043,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60436043
6044fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {6044fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6045 const pt = self.pt;6045 const pt = self.pt;
6046 const mod = pt.zcu;6046 const zcu = pt.zcu;
6047 const vector_ty = self.typeOfIndex(inst);6047 const vector_ty = self.typeOfIndex(inst);
6048 const len = vector_ty.vectorLen(mod);6048 const len = vector_ty.vectorLen(zcu);
6049 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6049 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6050 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);6050 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
6051 const result: MCValue = res: {6051 const result: MCValue = res: {
...@@ -6095,8 +6095,8 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {...@@ -6095,8 +6095,8 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
6095 const result: MCValue = result: {6095 const result: MCValue = result: {
6096 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };6096 const error_union_bind: ReadArg.Bind = .{ .inst = pl_op.operand };
6097 const error_union_ty = self.typeOf(pl_op.operand);6097 const error_union_ty = self.typeOf(pl_op.operand);
6098 const error_union_size: u32 = @intCast(error_union_ty.abiSize(pt));6098 const error_union_size: u32 = @intCast(error_union_ty.abiSize(pt.zcu));
6099 const error_union_align = error_union_ty.abiAlignment(pt);6099 const error_union_align = error_union_ty.abiAlignment(pt.zcu);
61006100
6101 // The error union will die in the body. However, we need the6101 // The error union will die in the body. However, we need the
6102 // error union after the body in order to extract the payload6102 // error union after the body in order to extract the payload
...@@ -6126,11 +6126,11 @@ fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -6126,11 +6126,11 @@ fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
61266126
6127fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {6127fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
6128 const pt = self.pt;6128 const pt = self.pt;
6129 const mod = pt.zcu;6129 const zcu = pt.zcu;
61306130
6131 // If the type has no codegen bits, no need to store it.6131 // If the type has no codegen bits, no need to store it.
6132 const inst_ty = self.typeOf(inst);6132 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))
6134 return MCValue{ .none = {} };6134 return MCValue{ .none = {} };
61356135
6136 const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, pt)).?);6136 const inst_index = inst.toIndex() orelse return self.genTypedValue((try self.air.value(inst, pt)).?);
...@@ -6189,9 +6189,9 @@ const CallMCValues = struct {...@@ -6189,9 +6189,9 @@ const CallMCValues = struct {
6189/// Caller must call `CallMCValues.deinit`.6189/// Caller must call `CallMCValues.deinit`.
6190fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {6190fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6191 const pt = self.pt;6191 const pt = self.pt;
6192 const mod = pt.zcu;6192 const zcu = pt.zcu;
6193 const ip = &mod.intern_pool;6193 const ip = &zcu.intern_pool;
6194 const fn_info = mod.typeToFunc(fn_ty).?;6194 const fn_info = zcu.typeToFunc(fn_ty).?;
6195 const cc = fn_info.cc;6195 const cc = fn_info.cc;
6196 var result: CallMCValues = .{6196 var result: CallMCValues = .{
6197 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),6197 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),
...@@ -6202,7 +6202,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6202,7 +6202,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6202 };6202 };
6203 errdefer self.gpa.free(result.args);6203 errdefer self.gpa.free(result.args);
62046204
6205 const ret_ty = fn_ty.fnReturnType(mod);6205 const ret_ty = fn_ty.fnReturnType(zcu);
62066206
6207 switch (cc) {6207 switch (cc) {
6208 .Naked => {6208 .Naked => {
...@@ -6217,12 +6217,12 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6217,12 +6217,12 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6217 var ncrn: usize = 0; // Next Core Register Number6217 var ncrn: usize = 0; // Next Core Register Number
6218 var nsaa: u32 = 0; // Next stacked argument address6218 var nsaa: u32 = 0; // Next stacked argument address
62196219
6220 if (ret_ty.zigTypeTag(mod) == .NoReturn) {6220 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
6221 result.return_value = .{ .unreach = {} };6221 result.return_value = .{ .unreach = {} };
6222 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {6222 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6223 result.return_value = .{ .none = {} };6223 result.return_value = .{ .none = {} };
6224 } else {6224 } else {
6225 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));6225 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
6226 // TODO handle cases where multiple registers are used6226 // TODO handle cases where multiple registers are used
6227 if (ret_ty_size <= 4) {6227 if (ret_ty_size <= 4) {
6228 result.return_value = .{ .register = c_abi_int_return_regs[0] };6228 result.return_value = .{ .register = c_abi_int_return_regs[0] };
...@@ -6237,10 +6237,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6237,10 +6237,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6237 }6237 }
62386238
6239 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6239 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")
6241 ncrn = std.mem.alignForward(usize, ncrn, 2);6241 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));
6244 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {6244 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
6245 if (param_size <= 4) {6245 if (param_size <= 4) {
6246 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };6246 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };
...@@ -6252,7 +6252,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6252,7 +6252,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6252 return self.fail("TODO MCValues split between registers and stack", .{});6252 return self.fail("TODO MCValues split between registers and stack", .{});
6253 } else {6253 } else {
6254 ncrn = 4;6254 ncrn = 4;
6255 if (Type.fromInterned(ty).abiAlignment(pt) == .@"8")6255 if (Type.fromInterned(ty).abiAlignment(zcu) == .@"8")
6256 nsaa = std.mem.alignForward(u32, nsaa, 8);6256 nsaa = std.mem.alignForward(u32, nsaa, 8);
62576257
6258 result_arg.* = .{ .stack_argument_offset = nsaa };6258 result_arg.* = .{ .stack_argument_offset = nsaa };
...@@ -6264,14 +6264,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6264,14 +6264,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6264 result.stack_align = 8;6264 result.stack_align = 8;
6265 },6265 },
6266 .Unspecified => {6266 .Unspecified => {
6267 if (ret_ty.zigTypeTag(mod) == .NoReturn) {6267 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
6268 result.return_value = .{ .unreach = {} };6268 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)) {
6270 result.return_value = .{ .none = {} };6270 result.return_value = .{ .none = {} };
6271 } else {6271 } else {
6272 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));6272 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
6273 if (ret_ty_size == 0) {6273 if (ret_ty_size == 0) {
6274 assert(ret_ty.isError(mod));6274 assert(ret_ty.isError(zcu));
6275 result.return_value = .{ .immediate = 0 };6275 result.return_value = .{ .immediate = 0 };
6276 } else if (ret_ty_size <= 4) {6276 } else if (ret_ty_size <= 4) {
6277 result.return_value = .{ .register = .r0 };6277 result.return_value = .{ .register = .r0 };
...@@ -6287,9 +6287,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6287,9 +6287,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6287 var stack_offset: u32 = 0;6287 var stack_offset: u32 = 0;
62886288
6289 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6289 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6290 if (Type.fromInterned(ty).abiSize(pt) > 0) {6290 if (Type.fromInterned(ty).abiSize(zcu) > 0) {
6291 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(pt));6291 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(zcu));
6292 const param_alignment = Type.fromInterned(ty).abiAlignment(pt);6292 const param_alignment = Type.fromInterned(ty).abiAlignment(zcu);
62936293
6294 stack_offset = @intCast(param_alignment.forward(stack_offset));6294 stack_offset = @intCast(param_alignment.forward(stack_offset));
6295 result_arg.* = .{ .stack_argument_offset = stack_offset };6295 result_arg.* = .{ .stack_argument_offset = stack_offset };
src/arch/arm/abi.zig+22-22
...@@ -24,29 +24,29 @@ pub const Class = union(enum) {...@@ -24,29 +24,29 @@ pub const Class = union(enum) {
2424
25pub const Context = enum { ret, arg };25pub const Context = enum { ret, arg };
2626
27pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {27pub fn classifyType(ty: Type, zcu: *Zcu, ctx: Context) Class {
28 assert(ty.hasRuntimeBitsIgnoreComptime(pt));28 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
2929
30 var maybe_float_bits: ?u16 = null;30 var maybe_float_bits: ?u16 = null;
31 const max_byval_size = 512;31 const max_byval_size = 512;
32 const ip = &pt.zcu.intern_pool;32 const ip = &zcu.intern_pool;
33 switch (ty.zigTypeTag(pt.zcu)) {33 switch (ty.zigTypeTag(zcu)) {
34 .Struct => {34 .Struct => {
35 const bit_size = ty.bitSize(pt);35 const bit_size = ty.bitSize(zcu);
36 if (ty.containerLayout(pt.zcu) == .@"packed") {36 if (ty.containerLayout(zcu) == .@"packed") {
37 if (bit_size > 64) return .memory;37 if (bit_size > 64) return .memory;
38 return .byval;38 return .byval;
39 }39 }
40 if (bit_size > max_byval_size) return .memory;40 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);
42 if (float_count <= byval_float_count) return .byval;42 if (float_count <= byval_float_count) return .byval;
4343
44 const fields = ty.structFieldCount(pt.zcu);44 const fields = ty.structFieldCount(zcu);
45 var i: u32 = 0;45 var i: u32 = 0;
46 while (i < fields) : (i += 1) {46 while (i < fields) : (i += 1) {
47 const field_ty = ty.structFieldType(i, pt.zcu);47 const field_ty = ty.fieldType(i, zcu);
48 const field_alignment = ty.structFieldAlign(i, pt);48 const field_alignment = ty.fieldAlignment(i, zcu);
49 const field_size = field_ty.bitSize(pt);49 const field_size = field_ty.bitSize(zcu);
50 if (field_size > 32 or field_alignment.compare(.gt, .@"32")) {50 if (field_size > 32 or field_alignment.compare(.gt, .@"32")) {
51 return Class.arrSize(bit_size, 64);51 return Class.arrSize(bit_size, 64);
52 }52 }
...@@ -54,19 +54,19 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {...@@ -54,19 +54,19 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
54 return Class.arrSize(bit_size, 32);54 return Class.arrSize(bit_size, 32);
55 },55 },
56 .Union => {56 .Union => {
57 const bit_size = ty.bitSize(pt);57 const bit_size = ty.bitSize(zcu);
58 const union_obj = pt.zcu.typeToUnion(ty).?;58 const union_obj = zcu.typeToUnion(ty).?;
59 if (union_obj.flagsUnordered(ip).layout == .@"packed") {59 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
60 if (bit_size > 64) return .memory;60 if (bit_size > 64) return .memory;
61 return .byval;61 return .byval;
62 }62 }
63 if (bit_size > max_byval_size) return .memory;63 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);
65 if (float_count <= byval_float_count) return .byval;65 if (float_count <= byval_float_count) return .byval;
6666
67 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {67 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
68 if (Type.fromInterned(field_ty).bitSize(pt) > 32 or68 if (Type.fromInterned(field_ty).bitSize(zcu) > 32 or
69 pt.unionFieldNormalAlignment(union_obj, @intCast(field_index)).compare(.gt, .@"32"))69 ty.fieldAlignment(field_index, zcu).compare(.gt, .@"32"))
70 {70 {
71 return Class.arrSize(bit_size, 64);71 return Class.arrSize(bit_size, 64);
72 }72 }
...@@ -77,28 +77,28 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {...@@ -77,28 +77,28 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
77 .Int => {77 .Int => {
78 // TODO this is incorrect for _BitInt(128) but implementing78 // TODO this is incorrect for _BitInt(128) but implementing
79 // this correctly makes implementing compiler-rt impossible.79 // this correctly makes implementing compiler-rt impossible.
80 // const bit_size = ty.bitSize(pt);80 // const bit_size = ty.bitSize(zcu);
81 // if (bit_size > 64) return .memory;81 // if (bit_size > 64) return .memory;
82 return .byval;82 return .byval;
83 },83 },
84 .Enum, .ErrorSet => {84 .Enum, .ErrorSet => {
85 const bit_size = ty.bitSize(pt);85 const bit_size = ty.bitSize(zcu);
86 if (bit_size > 64) return .memory;86 if (bit_size > 64) return .memory;
87 return .byval;87 return .byval;
88 },88 },
89 .Vector => {89 .Vector => {
90 const bit_size = ty.bitSize(pt);90 const bit_size = ty.bitSize(zcu);
91 // TODO is this controlled by a cpu feature?91 // TODO is this controlled by a cpu feature?
92 if (ctx == .ret and bit_size > 128) return .memory;92 if (ctx == .ret and bit_size > 128) return .memory;
93 if (bit_size > 512) return .memory;93 if (bit_size > 512) return .memory;
94 return .byval;94 return .byval;
95 },95 },
96 .Optional => {96 .Optional => {
97 assert(ty.isPtrLikeOptional(pt.zcu));97 assert(ty.isPtrLikeOptional(zcu));
98 return .byval;98 return .byval;
99 },99 },
100 .Pointer => {100 .Pointer => {
101 assert(!ty.isSlice(pt.zcu));101 assert(!ty.isSlice(zcu));
102 return .byval;102 return .byval;
103 },103 },
104 .ErrorUnion,104 .ErrorUnion,
...@@ -141,7 +141,7 @@ fn countFloats(ty: Type, zcu: *Zcu, maybe_float_bits: *?u16) u32 {...@@ -141,7 +141,7 @@ fn countFloats(ty: Type, zcu: *Zcu, maybe_float_bits: *?u16) u32 {
141 var count: u32 = 0;141 var count: u32 = 0;
142 var i: u32 = 0;142 var i: u32 = 0;
143 while (i < fields_len) : (i += 1) {143 while (i < fields_len) : (i += 1) {
144 const field_ty = ty.structFieldType(i, zcu);144 const field_ty = ty.fieldType(i, zcu);
145 const field_count = countFloats(field_ty, zcu, maybe_float_bits);145 const field_count = countFloats(field_ty, zcu, maybe_float_bits);
146 if (field_count == invalid) return invalid;146 if (field_count == invalid) return invalid;
147 count += field_count;147 count += field_count;
src/arch/riscv64/CodeGen.zig+168-161
...@@ -591,14 +591,14 @@ const FrameAlloc = struct {...@@ -591,14 +591,14 @@ const FrameAlloc = struct {
591 .ref_count = 0,591 .ref_count = 0,
592 };592 };
593 }593 }
594 fn initType(ty: Type, pt: Zcu.PerThread) FrameAlloc {594 fn initType(ty: Type, zcu: *Zcu) FrameAlloc {
595 return init(.{595 return init(.{
596 .size = ty.abiSize(pt),596 .size = ty.abiSize(zcu),
597 .alignment = ty.abiAlignment(pt),597 .alignment = ty.abiAlignment(zcu),
598 });598 });
599 }599 }
600 fn initSpill(ty: Type, pt: Zcu.PerThread) FrameAlloc {600 fn initSpill(ty: Type, zcu: *Zcu) FrameAlloc {
601 const abi_size = ty.abiSize(pt);601 const abi_size = ty.abiSize(zcu);
602 const spill_size = if (abi_size < 8)602 const spill_size = if (abi_size < 8)
603 math.ceilPowerOfTwoAssert(u64, abi_size)603 math.ceilPowerOfTwoAssert(u64, abi_size)
604 else604 else
...@@ -606,7 +606,7 @@ const FrameAlloc = struct {...@@ -606,7 +606,7 @@ const FrameAlloc = struct {
606 return init(.{606 return init(.{
607 .size = spill_size,607 .size = spill_size,
608 .pad = @intCast(spill_size - abi_size),608 .pad = @intCast(spill_size - abi_size),
609 .alignment = ty.abiAlignment(pt).maxStrict(609 .alignment = ty.abiAlignment(zcu).maxStrict(
610 Alignment.fromNonzeroByteUnits(@min(spill_size, 8)),610 Alignment.fromNonzeroByteUnits(@min(spill_size, 8)),
611 ),611 ),
612 });612 });
...@@ -835,11 +835,11 @@ pub fn generate(...@@ -835,11 +835,11 @@ pub fn generate(
835 function.args = call_info.args;835 function.args = call_info.args;
836 function.ret_mcv = call_info.return_value;836 function.ret_mcv = call_info.return_value;
837 function.frame_allocs.set(@intFromEnum(FrameIndex.ret_addr), FrameAlloc.init(.{837 function.frame_allocs.set(@intFromEnum(FrameIndex.ret_addr), FrameAlloc.init(.{
838 .size = Type.u64.abiSize(pt),838 .size = Type.u64.abiSize(zcu),
839 .alignment = Type.u64.abiAlignment(pt).min(call_info.stack_align),839 .alignment = Type.u64.abiAlignment(zcu).min(call_info.stack_align),
840 }));840 }));
841 function.frame_allocs.set(@intFromEnum(FrameIndex.base_ptr), FrameAlloc.init(.{841 function.frame_allocs.set(@intFromEnum(FrameIndex.base_ptr), FrameAlloc.init(.{
842 .size = Type.u64.abiSize(pt),842 .size = Type.u64.abiSize(zcu),
843 .alignment = Alignment.min(843 .alignment = Alignment.min(
844 call_info.stack_align,844 call_info.stack_align,
845 Alignment.fromNonzeroByteUnits(function.target.stackAlignment()),845 Alignment.fromNonzeroByteUnits(function.target.stackAlignment()),
...@@ -851,7 +851,7 @@ pub fn generate(...@@ -851,7 +851,7 @@ pub fn generate(
851 }));851 }));
852 function.frame_allocs.set(@intFromEnum(FrameIndex.spill_frame), FrameAlloc.init(.{852 function.frame_allocs.set(@intFromEnum(FrameIndex.spill_frame), FrameAlloc.init(.{
853 .size = 0,853 .size = 0,
854 .alignment = Type.u64.abiAlignment(pt),854 .alignment = Type.u64.abiAlignment(zcu),
855 }));855 }));
856856
857 function.gen() catch |err| switch (err) {857 function.gen() catch |err| switch (err) {
...@@ -1245,7 +1245,7 @@ fn gen(func: *Func) !void {...@@ -1245,7 +1245,7 @@ fn gen(func: *Func) !void {
1245 // The address where to store the return value for the caller is in a1245 // The address where to store the return value for the caller is in a
1246 // register which the callee is free to clobber. Therefore, we purposely1246 // register which the callee is free to clobber. Therefore, we purposely
1247 // spill it to stack immediately.1247 // 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));
1249 try func.genSetMem(1249 try func.genSetMem(
1250 .{ .frame = frame_index },1250 .{ .frame = frame_index },
1251 0,1251 0,
...@@ -1379,9 +1379,9 @@ fn gen(func: *Func) !void {...@@ -1379,9 +1379,9 @@ fn gen(func: *Func) !void {
13791379
1380fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {1380fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
1381 const pt = func.pt;1381 const pt = func.pt;
1382 const mod = pt.zcu;1382 const zcu = pt.zcu;
1383 const ip = &mod.intern_pool;1383 const ip = &zcu.intern_pool;
1384 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(mod)) {1384 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {
1385 .Enum => {1385 .Enum => {
1386 const enum_ty = Type.fromInterned(lazy_sym.ty);1386 const enum_ty = Type.fromInterned(lazy_sym.ty);
1387 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});1387 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});
...@@ -1390,7 +1390,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -1390,7 +1390,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
1390 const ret_reg = param_regs[0];1390 const ret_reg = param_regs[0];
1391 const enum_mcv: MCValue = .{ .register = param_regs[1] };1391 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));
1394 defer func.gpa.free(exitlude_jump_relocs);1394 defer func.gpa.free(exitlude_jump_relocs);
13951395
1396 const data_reg, const data_lock = try func.allocReg(.int);1396 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 {...@@ -1410,7 +1410,7 @@ fn genLazy(func: *Func, lazy_sym: link.File.LazySymbol) InnerError!void {
1410 defer func.register_manager.unlockReg(cmp_lock);1410 defer func.register_manager.unlockReg(cmp_lock);
14111411
1412 var data_off: i32 = 0;1412 var data_off: i32 = 0;
1413 const tag_names = enum_ty.enumFields(mod);1413 const tag_names = enum_ty.enumFields(zcu);
1414 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {1414 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {
1415 const tag_name_len = tag_names.get(ip)[tag_index].length(ip);1415 const tag_name_len = tag_names.get(ip)[tag_index].length(ip);
1416 const tag_val = try pt.enumValueFieldIndex(enum_ty, @intCast(tag_index));1416 const tag_val = try pt.enumValueFieldIndex(enum_ty, @intCast(tag_index));
...@@ -1944,32 +1944,32 @@ fn memSize(func: *Func, ty: Type) Memory.Size {...@@ -1944,32 +1944,32 @@ fn memSize(func: *Func, ty: Type) Memory.Size {
1944 const zcu = pt.zcu;1944 const zcu = pt.zcu;
1945 return switch (ty.zigTypeTag(zcu)) {1945 return switch (ty.zigTypeTag(zcu)) {
1946 .Float => Memory.Size.fromBitSize(ty.floatBits(func.target.*)),1946 .Float => Memory.Size.fromBitSize(ty.floatBits(func.target.*)),
1947 else => Memory.Size.fromByteSize(ty.abiSize(pt)),1947 else => Memory.Size.fromByteSize(ty.abiSize(zcu)),
1948 };1948 };
1949}1949}
19501950
1951fn splitType(func: *Func, ty: Type) ![2]Type {1951fn splitType(func: *Func, ty: Type) ![2]Type {
1952 const pt = func.pt;1952 const zcu = func.pt.zcu;
1953 const classes = mem.sliceTo(&abi.classifySystem(ty, pt), .none);1953 const classes = mem.sliceTo(&abi.classifySystem(ty, zcu), .none);
1954 var parts: [2]Type = undefined;1954 var parts: [2]Type = undefined;
1955 if (classes.len == 2) for (&parts, classes, 0..) |*part, class, part_i| {1955 if (classes.len == 2) for (&parts, classes, 0..) |*part, class, part_i| {
1956 part.* = switch (class) {1956 part.* = switch (class) {
1957 .integer => switch (part_i) {1957 .integer => switch (part_i) {
1958 0 => Type.u64,1958 0 => Type.u64,
1959 1 => part: {1959 1 => part: {
1960 const elem_size = ty.abiAlignment(pt).minStrict(.@"8").toByteUnits().?;1960 const elem_size = ty.abiAlignment(zcu).minStrict(.@"8").toByteUnits().?;
1961 const elem_ty = try pt.intType(.unsigned, @intCast(elem_size * 8));1961 const elem_ty = try func.pt.intType(.unsigned, @intCast(elem_size * 8));
1962 break :part switch (@divExact(ty.abiSize(pt) - 8, elem_size)) {1962 break :part switch (@divExact(ty.abiSize(zcu) - 8, elem_size)) {
1963 1 => elem_ty,1963 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() }),
1965 };1965 };
1966 },1966 },
1967 else => unreachable,1967 else => unreachable,
1968 },1968 },
1969 else => return func.fail("TODO: splitType class {}", .{class}),1969 else => return func.fail("TODO: splitType class {}", .{class}),
1970 };1970 };
1971 } else if (parts[0].abiSize(pt) + parts[1].abiSize(pt) == ty.abiSize(pt)) return parts;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(pt)});1972 return func.fail("TODO implement splitType for {}", .{ty.fmt(func.pt)});
1973}1973}
19741974
1975/// Truncates the value in the register in place.1975/// Truncates the value in the register in place.
...@@ -1979,7 +1979,7 @@ fn truncateRegister(func: *Func, ty: Type, reg: Register) !void {...@@ -1979,7 +1979,7 @@ fn truncateRegister(func: *Func, ty: Type, reg: Register) !void {
1979 const zcu = pt.zcu;1979 const zcu = pt.zcu;
1980 const int_info = if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else std.builtin.Type.Int{1980 const int_info = if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else std.builtin.Type.Int{
1981 .signedness = .unsigned,1981 .signedness = .unsigned,
1982 .bits = @intCast(ty.bitSize(pt)),1982 .bits = @intCast(ty.bitSize(zcu)),
1983 };1983 };
1984 assert(reg.class() == .int);1984 assert(reg.class() == .int);
19851985
...@@ -2081,10 +2081,10 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex {...@@ -2081,10 +2081,10 @@ fn allocMemPtr(func: *Func, inst: Air.Inst.Index) !FrameIndex {
2081 const ptr_ty = func.typeOfIndex(inst);2081 const ptr_ty = func.typeOfIndex(inst);
2082 const val_ty = ptr_ty.childType(zcu);2082 const val_ty = ptr_ty.childType(zcu);
2083 return func.allocFrameIndex(FrameAlloc.init(.{2083 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 {
2085 return func.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});2085 return func.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});
2086 },2086 },
2087 .alignment = ptr_ty.ptrAlignment(pt).max(.@"1"),2087 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
2088 }));2088 }));
2089}2089}
20902090
...@@ -2118,7 +2118,7 @@ fn allocRegOrMem(func: *Func, elem_ty: Type, inst: ?Air.Inst.Index, reg_ok: bool...@@ -2118,7 +2118,7 @@ fn allocRegOrMem(func: *Func, elem_ty: Type, inst: ?Air.Inst.Index, reg_ok: bool
2118 const pt = func.pt;2118 const pt = func.pt;
2119 const zcu = pt.zcu;2119 const zcu = pt.zcu;
21202120
2121 const bit_size = elem_ty.bitSize(pt);2121 const bit_size = elem_ty.bitSize(zcu);
2122 const min_size: u64 = switch (elem_ty.zigTypeTag(zcu)) {2122 const min_size: u64 = switch (elem_ty.zigTypeTag(zcu)) {
2123 .Float => if (func.hasFeature(.d)) 64 else 32,2123 .Float => if (func.hasFeature(.d)) 64 else 32,
2124 .Vector => 256, // TODO: calculate it from avl * vsew2124 .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...@@ -2133,7 +2133,7 @@ fn allocRegOrMem(func: *Func, elem_ty: Type, inst: ?Air.Inst.Index, reg_ok: bool
2133 return func.fail("did you forget to extend vector registers before allocating", .{});2133 return func.fail("did you forget to extend vector registers before allocating", .{});
2134 }2134 }
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));
2137 return .{ .load_frame = .{ .index = frame_index } };2137 return .{ .load_frame = .{ .index = frame_index } };
2138}2138}
21392139
...@@ -2368,7 +2368,7 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void {...@@ -2368,7 +2368,7 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void {
2368 });2368 });
2369 },2369 },
2370 .Int => {2370 .Int => {
2371 const size = ty.bitSize(pt);2371 const size = ty.bitSize(zcu);
2372 if (!math.isPowerOfTwo(size))2372 if (!math.isPowerOfTwo(size))
2373 return func.fail("TODO: airNot non-pow 2 int size", .{});2373 return func.fail("TODO: airNot non-pow 2 int size", .{});
23742374
...@@ -2399,11 +2399,12 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void {...@@ -2399,11 +2399,12 @@ fn airNot(func: *Func, inst: Air.Inst.Index) !void {
23992399
2400fn airSlice(func: *Func, inst: Air.Inst.Index) !void {2400fn airSlice(func: *Func, inst: Air.Inst.Index) !void {
2401 const pt = func.pt;2401 const pt = func.pt;
2402 const zcu = pt.zcu;
2402 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2403 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2403 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;2404 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
24042405
2405 const slice_ty = func.typeOfIndex(inst);2406 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
2408 const ptr_ty = func.typeOf(bin_op.lhs);2409 const ptr_ty = func.typeOf(bin_op.lhs);
2409 try func.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, .{ .air_ref = bin_op.lhs });2410 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 {...@@ -2411,7 +2412,7 @@ fn airSlice(func: *Func, inst: Air.Inst.Index) !void {
2411 const len_ty = func.typeOf(bin_op.rhs);2412 const len_ty = func.typeOf(bin_op.rhs);
2412 try func.genSetMem(2413 try func.genSetMem(
2413 .{ .frame = frame_index },2414 .{ .frame = frame_index },
2414 @intCast(ptr_ty.abiSize(pt)),2415 @intCast(ptr_ty.abiSize(zcu)),
2415 len_ty,2416 len_ty,
2416 .{ .air_ref = bin_op.rhs },2417 .{ .air_ref = bin_op.rhs },
2417 );2418 );
...@@ -2428,8 +2429,8 @@ fn airBinOp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -2428,8 +2429,8 @@ fn airBinOp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
24282429
2429 const dst_ty = func.typeOfIndex(inst);2430 const dst_ty = func.typeOfIndex(inst);
2430 if (dst_ty.isAbiInt(zcu)) {2431 if (dst_ty.isAbiInt(zcu)) {
2431 const abi_size: u32 = @intCast(dst_ty.abiSize(pt));2432 const abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
2432 const bit_size: u32 = @intCast(dst_ty.bitSize(pt));2433 const bit_size: u32 = @intCast(dst_ty.bitSize(zcu));
2433 if (abi_size * 8 > bit_size) {2434 if (abi_size * 8 > bit_size) {
2434 const dst_lock = switch (dst_mcv) {2435 const dst_lock = switch (dst_mcv) {
2435 .register => |dst_reg| func.register_manager.lockRegAssumeUnused(dst_reg),2436 .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 {...@@ -2443,7 +2444,7 @@ fn airBinOp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
2443 const tmp_reg, const tmp_lock = try func.allocReg(.int);2444 const tmp_reg, const tmp_lock = try func.allocReg(.int);
2444 defer func.register_manager.unlockReg(tmp_lock);2445 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));
2447 const hi_mcv = dst_mcv.address().offset(@intCast(bit_size / 64 * 8)).deref();2448 const hi_mcv = dst_mcv.address().offset(@intCast(bit_size / 64 * 8)).deref();
2448 try func.genSetReg(hi_ty, tmp_reg, hi_mcv);2449 try func.genSetReg(hi_ty, tmp_reg, hi_mcv);
2449 try func.truncateRegister(dst_ty, tmp_reg);2450 try func.truncateRegister(dst_ty, tmp_reg);
...@@ -2464,6 +2465,7 @@ fn binOp(...@@ -2464,6 +2465,7 @@ fn binOp(
2464) !MCValue {2465) !MCValue {
2465 _ = maybe_inst;2466 _ = maybe_inst;
2466 const pt = func.pt;2467 const pt = func.pt;
2468 const zcu = pt.zcu;
2467 const lhs_ty = func.typeOf(lhs_air);2469 const lhs_ty = func.typeOf(lhs_air);
2468 const rhs_ty = func.typeOf(rhs_air);2470 const rhs_ty = func.typeOf(rhs_air);
24692471
...@@ -2480,9 +2482,9 @@ fn binOp(...@@ -2480,9 +2482,9 @@ fn binOp(
2480 }2482 }
24812483
2482 // don't have support for certain sizes of addition2484 // don't have support for certain sizes of addition
2483 switch (lhs_ty.zigTypeTag(pt.zcu)) {2485 switch (lhs_ty.zigTypeTag(zcu)) {
2484 .Vector => {}, // works differently and fails in a different place2486 .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", .{}),
2486 }2488 }
24872489
2488 const lhs_mcv = try func.resolveInst(lhs_air);2490 const lhs_mcv = try func.resolveInst(lhs_air);
...@@ -2533,7 +2535,7 @@ fn genBinOp(...@@ -2533,7 +2535,7 @@ fn genBinOp(
2533) !void {2535) !void {
2534 const pt = func.pt;2536 const pt = func.pt;
2535 const zcu = pt.zcu;2537 const zcu = pt.zcu;
2536 const bit_size = lhs_ty.bitSize(pt);2538 const bit_size = lhs_ty.bitSize(zcu);
25372539
2538 const is_unsigned = lhs_ty.isUnsignedInt(zcu);2540 const is_unsigned = lhs_ty.isUnsignedInt(zcu);
25392541
...@@ -2646,7 +2648,7 @@ fn genBinOp(...@@ -2646,7 +2648,7 @@ fn genBinOp(
2646 },2648 },
2647 .Vector => {2649 .Vector => {
2648 const num_elem = lhs_ty.vectorLen(zcu);2650 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
2651 const child_ty = lhs_ty.childType(zcu);2653 const child_ty = lhs_ty.childType(zcu);
26522654
...@@ -2753,7 +2755,7 @@ fn genBinOp(...@@ -2753,7 +2755,7 @@ fn genBinOp(
2753 defer func.register_manager.unlockReg(tmp_lock);2755 defer func.register_manager.unlockReg(tmp_lock);
27542756
2755 // RISC-V has no immediate mul, so we copy the size to a temporary register2757 // 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);
2757 const elem_size_reg = try func.copyToTmpRegister(Type.u64, .{ .immediate = elem_size });2759 const elem_size_reg = try func.copyToTmpRegister(Type.u64, .{ .immediate = elem_size });
27582760
2759 try func.genBinOp(2761 try func.genBinOp(
...@@ -2990,7 +2992,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -2990,7 +2992,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
29902992
2991 try func.genSetMem(2993 try func.genSetMem(
2992 .{ .frame = offset.index },2994 .{ .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))),
2994 lhs_ty,2996 lhs_ty,
2995 add_result,2997 add_result,
2996 );2998 );
...@@ -3016,7 +3018,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -3016,7 +3018,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
30163018
3017 try func.genSetMem(3019 try func.genSetMem(
3018 .{ .frame = offset.index },3020 .{ .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))),
3020 Type.u1,3022 Type.u1,
3021 .{ .register = overflow_reg },3023 .{ .register = overflow_reg },
3022 );3024 );
...@@ -3053,7 +3055,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -3053,7 +3055,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
30533055
3054 try func.genSetMem(3056 try func.genSetMem(
3055 .{ .frame = offset.index },3057 .{ .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))),
3057 lhs_ty,3059 lhs_ty,
3058 add_result,3060 add_result,
3059 );3061 );
...@@ -3079,7 +3081,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -3079,7 +3081,7 @@ fn airAddWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
30793081
3080 try func.genSetMem(3082 try func.genSetMem(
3081 .{ .frame = offset.index },3083 .{ .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))),
3083 Type.u1,3085 Type.u1,
3084 .{ .register = overflow_reg },3086 .{ .register = overflow_reg },
3085 );3087 );
...@@ -3126,7 +3128,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -3126,7 +3128,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
31263128
3127 try func.genSetMem(3129 try func.genSetMem(
3128 .{ .frame = offset.index },3130 .{ .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))),
3130 lhs_ty,3132 lhs_ty,
3131 .{ .register = dest_reg },3133 .{ .register = dest_reg },
3132 );3134 );
...@@ -3155,7 +3157,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -3155,7 +3157,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
31553157
3156 try func.genSetMem(3158 try func.genSetMem(
3157 .{ .frame = offset.index },3159 .{ .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))),
3159 Type.u1,3161 Type.u1,
3160 .{ .register = overflow_reg },3162 .{ .register = overflow_reg },
3161 );3163 );
...@@ -3203,7 +3205,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -3203,7 +3205,7 @@ fn airSubWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
32033205
3204 try func.genSetMem(3206 try func.genSetMem(
3205 .{ .frame = offset.index },3207 .{ .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))),
3207 Type.u1,3209 Type.u1,
3208 .{ .register = overflow_reg },3210 .{ .register = overflow_reg },
3209 );3211 );
...@@ -3236,8 +3238,8 @@ fn airMulWithOverflow(func: *Func, inst: Air.Inst.Index) !void {...@@ -3236,8 +3238,8 @@ fn airMulWithOverflow(func: *Func, inst: Air.Inst.Index) !void {
3236 // genSetReg needs to support register_offset src_mcv for this to be true.3238 // genSetReg needs to support register_offset src_mcv for this to be true.
3237 const result_mcv = try func.allocRegOrMem(tuple_ty, inst, false);3239 const result_mcv = try func.allocRegOrMem(tuple_ty, inst, false);
32383240
3239 const result_off: i32 = @intCast(tuple_ty.structFieldOffset(0, pt));3241 const result_off: i32 = @intCast(tuple_ty.structFieldOffset(0, zcu));
3240 const overflow_off: i32 = @intCast(tuple_ty.structFieldOffset(1, pt));3242 const overflow_off: i32 = @intCast(tuple_ty.structFieldOffset(1, zcu));
32413243
3242 const dest_reg, const dest_lock = try func.allocReg(.int);3244 const dest_reg, const dest_lock = try func.allocReg(.int);
3243 defer func.register_manager.unlockReg(dest_lock);3245 defer func.register_manager.unlockReg(dest_lock);
...@@ -3320,11 +3322,11 @@ fn airShlSat(func: *Func, inst: Air.Inst.Index) !void {...@@ -3320,11 +3322,11 @@ fn airShlSat(func: *Func, inst: Air.Inst.Index) !void {
3320}3322}
33213323
3322fn airOptionalPayload(func: *Func, inst: Air.Inst.Index) !void {3324fn airOptionalPayload(func: *Func, inst: Air.Inst.Index) !void {
3323 const pt = func.pt;3325 const zcu = func.pt.zcu;
3324 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3326 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3325 const result: MCValue = result: {3327 const result: MCValue = result: {
3326 const pl_ty = func.typeOfIndex(inst);3328 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
3329 const opt_mcv = try func.resolveInst(ty_op.operand);3331 const opt_mcv = try func.resolveInst(ty_op.operand);
3330 if (func.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {3332 if (func.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {
...@@ -3368,11 +3370,11 @@ fn airUnwrapErrErr(func: *Func, inst: Air.Inst.Index) !void {...@@ -3368,11 +3370,11 @@ fn airUnwrapErrErr(func: *Func, inst: Air.Inst.Index) !void {
3368 break :result .{ .immediate = 0 };3370 break :result .{ .immediate = 0 };
3369 }3371 }
33703372
3371 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {3373 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3372 break :result operand;3374 break :result operand;
3373 }3375 }
33743376
3375 const err_off: u32 = @intCast(errUnionErrorOffset(payload_ty, pt));3377 const err_off: u32 = @intCast(errUnionErrorOffset(payload_ty, zcu));
33763378
3377 switch (operand) {3379 switch (operand) {
3378 .register => |reg| {3380 .register => |reg| {
...@@ -3421,9 +3423,9 @@ fn genUnwrapErrUnionPayloadMir(...@@ -3421,9 +3423,9 @@ fn genUnwrapErrUnionPayloadMir(
3421 const payload_ty = err_union_ty.errorUnionPayload(zcu);3423 const payload_ty = err_union_ty.errorUnionPayload(zcu);
34223424
3423 const result: MCValue = result: {3425 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));
3427 switch (err_union) {3429 switch (err_union) {
3428 .load_frame => |frame_addr| break :result .{ .load_frame = .{3430 .load_frame => |frame_addr| break :result .{ .load_frame = .{
3429 .index = frame_addr.index,3431 .index = frame_addr.index,
...@@ -3497,7 +3499,7 @@ fn airWrapOptional(func: *Func, inst: Air.Inst.Index) !void {...@@ -3497,7 +3499,7 @@ fn airWrapOptional(func: *Func, inst: Air.Inst.Index) !void {
3497 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3499 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3498 const result: MCValue = result: {3500 const result: MCValue = result: {
3499 const pl_ty = func.typeOf(ty_op.operand);3501 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
3502 const opt_ty = func.typeOfIndex(inst);3504 const opt_ty = func.typeOfIndex(inst);
3503 const pl_mcv = try func.resolveInst(ty_op.operand);3505 const pl_mcv = try func.resolveInst(ty_op.operand);
...@@ -3514,7 +3516,7 @@ fn airWrapOptional(func: *Func, inst: Air.Inst.Index) !void {...@@ -3514,7 +3516,7 @@ fn airWrapOptional(func: *Func, inst: Air.Inst.Index) !void {
3514 try func.genCopy(pl_ty, opt_mcv, pl_mcv);3516 try func.genCopy(pl_ty, opt_mcv, pl_mcv);
35153517
3516 if (!same_repr) {3518 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));
3518 switch (opt_mcv) {3520 switch (opt_mcv) {
3519 .load_frame => |frame_addr| {3521 .load_frame => |frame_addr| {
3520 try func.genCopy(pl_ty, opt_mcv, pl_mcv);3522 try func.genCopy(pl_ty, opt_mcv, pl_mcv);
...@@ -3545,11 +3547,11 @@ fn airWrapErrUnionPayload(func: *Func, inst: Air.Inst.Index) !void {...@@ -3545,11 +3547,11 @@ fn airWrapErrUnionPayload(func: *Func, inst: Air.Inst.Index) !void {
3545 const operand = try func.resolveInst(ty_op.operand);3547 const operand = try func.resolveInst(ty_op.operand);
35463548
3547 const result: MCValue = result: {3549 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));3552 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
3551 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));3553 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
3552 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));3554 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
3553 try func.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand);3555 try func.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand);
3554 try func.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 });3556 try func.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 });
3555 break :result .{ .load_frame = .{ .index = frame_index } };3557 break :result .{ .load_frame = .{ .index = frame_index } };
...@@ -3569,11 +3571,11 @@ fn airWrapErrUnionErr(func: *Func, inst: Air.Inst.Index) !void {...@@ -3569,11 +3571,11 @@ fn airWrapErrUnionErr(func: *Func, inst: Air.Inst.Index) !void {
3569 const err_ty = eu_ty.errorUnionSet(zcu);3571 const err_ty = eu_ty.errorUnionSet(zcu);
35703572
3571 const result: MCValue = result: {3573 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));3576 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
3575 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));3577 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
3576 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));3578 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
3577 try func.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .{ .undef = null });3579 try func.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .{ .undef = null });
3578 const operand = try func.resolveInst(ty_op.operand);3580 const operand = try func.resolveInst(ty_op.operand);
3579 try func.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand);3581 try func.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand);
...@@ -3717,7 +3719,7 @@ fn airSliceElemVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -3717,7 +3719,7 @@ fn airSliceElemVal(func: *Func, inst: Air.Inst.Index) !void {
37173719
3718 const result: MCValue = result: {3720 const result: MCValue = result: {
3719 const elem_ty = func.typeOfIndex(inst);3721 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
3722 const slice_ty = func.typeOf(bin_op.lhs);3724 const slice_ty = func.typeOf(bin_op.lhs);
3723 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);3725 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 {...@@ -3748,7 +3750,7 @@ fn genSliceElemPtr(func: *Func, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
3748 defer if (slice_mcv_lock) |lock| func.register_manager.unlockReg(lock);3750 defer if (slice_mcv_lock) |lock| func.register_manager.unlockReg(lock);
37493751
3750 const elem_ty = slice_ty.childType(zcu);3752 const elem_ty = slice_ty.childType(zcu);
3751 const elem_size = elem_ty.abiSize(pt);3753 const elem_size = elem_ty.abiSize(zcu);
37523754
3753 const index_ty = func.typeOf(rhs);3755 const index_ty = func.typeOf(rhs);
3754 const index_mcv = try func.resolveInst(rhs);3756 const index_mcv = try func.resolveInst(rhs);
...@@ -3792,14 +3794,14 @@ fn airArrayElemVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -3792,14 +3794,14 @@ fn airArrayElemVal(func: *Func, inst: Air.Inst.Index) !void {
3792 const index_ty = func.typeOf(bin_op.rhs);3794 const index_ty = func.typeOf(bin_op.rhs);
37933795
3794 const elem_ty = array_ty.childType(zcu);3796 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
3797 const addr_reg, const addr_reg_lock = try func.allocReg(.int);3799 const addr_reg, const addr_reg_lock = try func.allocReg(.int);
3798 defer func.register_manager.unlockReg(addr_reg_lock);3800 defer func.register_manager.unlockReg(addr_reg_lock);
37993801
3800 switch (array_mcv) {3802 switch (array_mcv) {
3801 .register => {3803 .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));
3803 try func.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv);3805 try func.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv);
3804 try func.genSetReg(Type.u64, addr_reg, .{ .lea_frame = .{ .index = frame_index } });3806 try func.genSetReg(Type.u64, addr_reg, .{ .lea_frame = .{ .index = frame_index } });
3805 },3807 },
...@@ -3870,7 +3872,7 @@ fn airPtrElemVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -3870,7 +3872,7 @@ fn airPtrElemVal(func: *Func, inst: Air.Inst.Index) !void {
38703872
3871 const result: MCValue = if (!is_volatile and func.liveness.isUnused(inst)) .unreach else result: {3873 const result: MCValue = if (!is_volatile and func.liveness.isUnused(inst)) .unreach else result: {
3872 const elem_ty = base_ptr_ty.elemType2(zcu);3874 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
3875 const base_ptr_mcv = try func.resolveInst(bin_op.lhs);3877 const base_ptr_mcv = try func.resolveInst(bin_op.lhs);
3876 const base_ptr_lock: ?RegisterLock = switch (base_ptr_mcv) {3878 const base_ptr_lock: ?RegisterLock = switch (base_ptr_mcv) {
...@@ -3970,11 +3972,12 @@ fn airSetUnionTag(func: *Func, inst: Air.Inst.Index) !void {...@@ -3970,11 +3972,12 @@ fn airSetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
39703972
3971fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {3973fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
3972 const pt = func.pt;3974 const pt = func.pt;
3975 const zcu = pt.zcu;
3973 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3976 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
39743977
3975 const tag_ty = func.typeOfIndex(inst);3978 const tag_ty = func.typeOfIndex(inst);
3976 const union_ty = func.typeOf(ty_op.operand);3979 const union_ty = func.typeOf(ty_op.operand);
3977 const layout = union_ty.unionGetLayout(pt);3980 const layout = union_ty.unionGetLayout(zcu);
39783981
3979 if (layout.tag_size == 0) {3982 if (layout.tag_size == 0) {
3980 return func.finishAir(inst, .none, .{ ty_op.operand, .none, .none });3983 return func.finishAir(inst, .none, .{ ty_op.operand, .none, .none });
...@@ -3985,7 +3988,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {...@@ -3985,7 +3988,7 @@ fn airGetUnionTag(func: *Func, inst: Air.Inst.Index) !void {
3985 const frame_mcv = try func.allocRegOrMem(union_ty, null, false);3988 const frame_mcv = try func.allocRegOrMem(union_ty, null, false);
3986 try func.genCopy(union_ty, frame_mcv, operand);3989 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);
3989 const result_reg, const result_lock = try func.allocReg(.int);3992 const result_reg, const result_lock = try func.allocReg(.int);
3990 defer func.register_manager.unlockReg(result_lock);3993 defer func.register_manager.unlockReg(result_lock);
39913994
...@@ -4034,7 +4037,7 @@ fn airClz(func: *Func, inst: Air.Inst.Index) !void {...@@ -4034,7 +4037,7 @@ fn airClz(func: *Func, inst: Air.Inst.Index) !void {
4034 else4037 else
4035 (try func.allocRegOrMem(func.typeOfIndex(inst), inst, true)).register;4038 (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);
4038 if (!math.isPowerOfTwo(bit_size)) try func.truncateRegister(ty, src_reg);4041 if (!math.isPowerOfTwo(bit_size)) try func.truncateRegister(ty, src_reg);
40394042
4040 if (bit_size > 64) {4043 if (bit_size > 64) {
...@@ -4081,6 +4084,7 @@ fn airPopcount(func: *Func, inst: Air.Inst.Index) !void {...@@ -4081,6 +4084,7 @@ fn airPopcount(func: *Func, inst: Air.Inst.Index) !void {
4081 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4084 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4082 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {4085 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
4083 const pt = func.pt;4086 const pt = func.pt;
4087 const zcu = pt.zcu;
40844088
4085 const operand = try func.resolveInst(ty_op.operand);4089 const operand = try func.resolveInst(ty_op.operand);
4086 const src_ty = func.typeOf(ty_op.operand);4090 const src_ty = func.typeOf(ty_op.operand);
...@@ -4090,7 +4094,7 @@ fn airPopcount(func: *Func, inst: Air.Inst.Index) !void {...@@ -4090,7 +4094,7 @@ fn airPopcount(func: *Func, inst: Air.Inst.Index) !void {
4090 const dst_reg, const dst_lock = try func.allocReg(.int);4094 const dst_reg, const dst_lock = try func.allocReg(.int);
4091 defer func.register_manager.unlockReg(dst_lock);4095 defer func.register_manager.unlockReg(dst_lock);
40924096
4093 const bit_size = src_ty.bitSize(pt);4097 const bit_size = src_ty.bitSize(zcu);
4094 switch (bit_size) {4098 switch (bit_size) {
4095 32, 64 => {},4099 32, 64 => {},
4096 1...31, 33...63 => try func.truncateRegister(src_ty, operand_reg),4100 1...31, 33...63 => try func.truncateRegister(src_ty, operand_reg),
...@@ -4283,12 +4287,13 @@ fn airBitReverse(func: *Func, inst: Air.Inst.Index) !void {...@@ -4283,12 +4287,13 @@ fn airBitReverse(func: *Func, inst: Air.Inst.Index) !void {
42834287
4284fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {4288fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
4285 const pt = func.pt;4289 const pt = func.pt;
4290 const zcu = pt.zcu;
4286 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4291 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4287 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {4292 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
4288 const ty = func.typeOf(un_op);4293 const ty = func.typeOf(un_op);
42894294
4290 const operand = try func.resolveInst(un_op);4295 const operand = try func.resolveInst(un_op);
4291 const operand_bit_size = ty.bitSize(pt);4296 const operand_bit_size = ty.bitSize(zcu);
42924297
4293 if (!math.isPowerOfTwo(operand_bit_size))4298 if (!math.isPowerOfTwo(operand_bit_size))
4294 return func.fail("TODO: airUnaryMath non-pow 2", .{});4299 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 {...@@ -4300,7 +4305,7 @@ fn airUnaryMath(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
4300 const dst_reg, const dst_lock = try func.allocReg(dst_class);4305 const dst_reg, const dst_lock = try func.allocReg(dst_class);
4301 defer func.register_manager.unlockReg(dst_lock);4306 defer func.register_manager.unlockReg(dst_lock);
43024307
4303 switch (ty.zigTypeTag(pt.zcu)) {4308 switch (ty.zigTypeTag(zcu)) {
4304 .Float => {4309 .Float => {
4305 assert(dst_class == .float);4310 assert(dst_class == .float);
43064311
...@@ -4397,7 +4402,7 @@ fn airLoad(func: *Func, inst: Air.Inst.Index) !void {...@@ -4397,7 +4402,7 @@ fn airLoad(func: *Func, inst: Air.Inst.Index) !void {
4397 const elem_ty = func.typeOfIndex(inst);4402 const elem_ty = func.typeOfIndex(inst);
43984403
4399 const result: MCValue = result: {4404 const result: MCValue = result: {
4400 if (!elem_ty.hasRuntimeBits(pt))4405 if (!elem_ty.hasRuntimeBits(zcu))
4401 break :result .none;4406 break :result .none;
44024407
4403 const ptr = try func.resolveInst(ty_op.operand);4408 const ptr = try func.resolveInst(ty_op.operand);
...@@ -4405,7 +4410,7 @@ fn airLoad(func: *Func, inst: Air.Inst.Index) !void {...@@ -4405,7 +4410,7 @@ fn airLoad(func: *Func, inst: Air.Inst.Index) !void {
4405 if (func.liveness.isUnused(inst) and !is_volatile)4410 if (func.liveness.isUnused(inst) and !is_volatile)
4406 break :result .unreach;4411 break :result .unreach;
44074412
4408 const elem_size = elem_ty.abiSize(pt);4413 const elem_size = elem_ty.abiSize(zcu);
44094414
4410 const dst_mcv: MCValue = blk: {4415 const dst_mcv: MCValue = blk: {
4411 // The MCValue that holds the pointer can be re-used as the value.4416 // 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...@@ -4544,7 +4549,7 @@ fn structFieldPtr(func: *Func, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
4544 const container_ty = ptr_container_ty.childType(zcu);4549 const container_ty = ptr_container_ty.childType(zcu);
45454550
4546 const field_offset: i32 = switch (container_ty.containerLayout(zcu)) {4551 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)),
4548 .@"packed" => @divExact(@as(i32, ptr_container_ty.ptrInfo(zcu).packed_offset.bit_offset) +4553 .@"packed" => @divExact(@as(i32, ptr_container_ty.ptrInfo(zcu).packed_offset.bit_offset) +
4549 (if (zcu.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, index) else 0) -4554 (if (zcu.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, index) else 0) -
4550 ptr_field_ty.ptrInfo(zcu).packed_offset.bit_offset, 8),4555 ptr_field_ty.ptrInfo(zcu).packed_offset.bit_offset, 8),
...@@ -4571,11 +4576,11 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -4571,11 +4576,11 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
4571 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {4576 const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
4572 const src_mcv = try func.resolveInst(operand);4577 const src_mcv = try func.resolveInst(operand);
4573 const struct_ty = func.typeOf(operand);4578 const struct_ty = func.typeOf(operand);
4574 const field_ty = struct_ty.structFieldType(index, zcu);4579 const field_ty = struct_ty.fieldType(index, zcu);
4575 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;4580 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
45764581
4577 const field_off: u32 = switch (struct_ty.containerLayout(zcu)) {4582 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),
4579 .@"packed" => if (zcu.typeToStruct(struct_ty)) |struct_type|4584 .@"packed" => if (zcu.typeToStruct(struct_ty)) |struct_type|
4580 pt.structPackedFieldBitOffset(struct_type, index)4585 pt.structPackedFieldBitOffset(struct_type, index)
4581 else4586 else
...@@ -4615,11 +4620,11 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -4615,11 +4620,11 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
4615 break :result if (field_off == 0) dst_mcv else try func.copyToNewRegister(inst, dst_mcv);4620 break :result if (field_off == 0) dst_mcv else try func.copyToNewRegister(inst, dst_mcv);
4616 },4621 },
4617 .load_frame => {4622 .load_frame => {
4618 const field_abi_size: u32 = @intCast(field_ty.abiSize(pt));4623 const field_abi_size: u32 = @intCast(field_ty.abiSize(zcu));
4619 if (field_off % 8 == 0) {4624 if (field_off % 8 == 0) {
4620 const field_byte_off = @divExact(field_off, 8);4625 const field_byte_off = @divExact(field_off, 8);
4621 const off_mcv = src_mcv.address().offset(@intCast(field_byte_off)).deref();4626 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
4624 if (field_abi_size <= 8) {4629 if (field_abi_size <= 8) {
4625 const int_ty = try pt.intType(4630 const int_ty = try pt.intType(
...@@ -4635,7 +4640,7 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {...@@ -4635,7 +4640,7 @@ fn airStructFieldVal(func: *Func, inst: Air.Inst.Index) !void {
4635 break :result try func.copyToNewRegister(inst, dst_mcv);4640 break :result try func.copyToNewRegister(inst, dst_mcv);
4636 }4641 }
46374642
4638 const container_abi_size: u32 = @intCast(struct_ty.abiSize(pt));4643 const container_abi_size: u32 = @intCast(struct_ty.abiSize(zcu));
4639 const dst_mcv = if (field_byte_off + field_abi_size <= container_abi_size and4644 const dst_mcv = if (field_byte_off + field_abi_size <= container_abi_size and
4640 func.reuseOperand(inst, operand, 0, src_mcv))4645 func.reuseOperand(inst, operand, 0, src_mcv))
4641 off_mcv4646 off_mcv
...@@ -4880,7 +4885,7 @@ fn genCall(...@@ -4880,7 +4885,7 @@ fn genCall(
4880 try reg_locks.appendSlice(&func.register_manager.lockRegs(2, regs));4885 try reg_locks.appendSlice(&func.register_manager.lockRegs(2, regs));
4881 },4886 },
4882 .indirect => |reg_off| {4887 .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));
4884 try func.genSetMem(.{ .frame = frame_index.* }, 0, arg_ty, src_arg);4889 try func.genSetMem(.{ .frame = frame_index.* }, 0, arg_ty, src_arg);
4885 try func.register_manager.getReg(reg_off.reg, null);4890 try func.register_manager.getReg(reg_off.reg, null);
4886 try reg_locks.append(func.register_manager.lockReg(reg_off.reg));4891 try reg_locks.append(func.register_manager.lockReg(reg_off.reg));
...@@ -4893,7 +4898,7 @@ fn genCall(...@@ -4893,7 +4898,7 @@ fn genCall(
4893 .none, .unreach => {},4898 .none, .unreach => {},
4894 .indirect => |reg_off| {4899 .indirect => |reg_off| {
4895 const ret_ty = Type.fromInterned(fn_info.return_type);4900 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));
4897 try func.genSetReg(Type.u64, reg_off.reg, .{4902 try func.genSetReg(Type.u64, reg_off.reg, .{
4898 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },4903 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },
4899 });4904 });
...@@ -5013,7 +5018,7 @@ fn airRet(func: *Func, inst: Air.Inst.Index, safety: bool) !void {...@@ -5013,7 +5018,7 @@ fn airRet(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
5013 .register_pair,5018 .register_pair,
5014 => {5019 => {
5015 if (ret_ty.isVector(zcu)) {5020 if (ret_ty.isVector(zcu)) {
5016 const bit_size = ret_ty.totalVectorBits(pt);5021 const bit_size = ret_ty.totalVectorBits(zcu);
50175022
5018 // set the vtype to hold the entire vector's contents in a single element5023 // set the vtype to hold the entire vector's contents in a single element
5019 try func.setVl(.zero, 0, .{5024 try func.setVl(.zero, 0, .{
...@@ -5113,7 +5118,7 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -5113,7 +5118,7 @@ fn airCmp(func: *Func, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
5113 .ErrorSet => Type.anyerror,5118 .ErrorSet => Type.anyerror,
5114 .Optional => blk: {5119 .Optional => blk: {
5115 const payload_ty = lhs_ty.optionalChild(zcu);5120 const payload_ty = lhs_ty.optionalChild(zcu);
5116 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {5121 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5117 break :blk Type.u1;5122 break :blk Type.u1;
5118 } else if (lhs_ty.isPtrLikeOptional(zcu)) {5123 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
5119 break :blk Type.u64;5124 break :blk Type.u64;
...@@ -5289,7 +5294,7 @@ fn isNull(func: *Func, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -5289,7 +5294,7 @@ fn isNull(func: *Func, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
5289 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(zcu))5294 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(zcu))
5290 .{ .off = 0, .ty = if (pl_ty.isSlice(zcu)) pl_ty.slicePtrFieldType(zcu) else pl_ty }5295 .{ .off = 0, .ty = if (pl_ty.isSlice(zcu)) pl_ty.slicePtrFieldType(zcu) else pl_ty }
5291 else5296 else
5292 .{ .off = @intCast(pl_ty.abiSize(pt)), .ty = Type.bool };5297 .{ .off = @intCast(pl_ty.abiSize(zcu)), .ty = Type.bool };
52935298
5294 const return_mcv = try func.allocRegOrMem(func.typeOfIndex(inst), inst, true);5299 const return_mcv = try func.allocRegOrMem(func.typeOfIndex(inst), inst, true);
5295 assert(return_mcv == .register); // should not be larger 8 bytes5300 assert(return_mcv == .register); // should not be larger 8 bytes
...@@ -5472,11 +5477,10 @@ fn airIsErrPtr(func: *Func, inst: Air.Inst.Index) !void {...@@ -5472,11 +5477,10 @@ fn airIsErrPtr(func: *Func, inst: Air.Inst.Index) !void {
5472/// Result is in the return register.5477/// Result is in the return register.
5473fn isErr(func: *Func, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue) !MCValue {5478fn isErr(func: *Func, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue) !MCValue {
5474 _ = maybe_inst;5479 _ = maybe_inst;
5475 const pt = func.pt;5480 const zcu = func.pt.zcu;
5476 const zcu = pt.zcu;
5477 const err_ty = eu_ty.errorUnionSet(zcu);5481 const err_ty = eu_ty.errorUnionSet(zcu);
5478 if (err_ty.errorSetIsEmpty(zcu)) return MCValue{ .immediate = 0 }; // always false5482 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
5481 const return_reg, const return_lock = try func.allocReg(.int);5485 const return_reg, const return_lock = try func.allocReg(.int);
5482 defer func.register_manager.unlockReg(return_lock);5486 defer func.register_manager.unlockReg(return_lock);
...@@ -5769,12 +5773,12 @@ fn performReloc(func: *Func, inst: Mir.Inst.Index) void {...@@ -5769,12 +5773,12 @@ fn performReloc(func: *Func, inst: Mir.Inst.Index) void {
5769}5773}
57705774
5771fn airBr(func: *Func, inst: Air.Inst.Index) !void {5775fn airBr(func: *Func, inst: Air.Inst.Index) !void {
5772 const pt = func.pt;5776 const zcu = func.pt.zcu;
5773 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;5777 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;
57745778
5775 const block_ty = func.typeOfIndex(br.block_inst);5779 const block_ty = func.typeOfIndex(br.block_inst);
5776 const block_unused =5780 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);
5778 const block_tracking = func.inst_tracking.getPtr(br.block_inst).?;5782 const block_tracking = func.inst_tracking.getPtr(br.block_inst).?;
5779 const block_data = func.blocks.getPtr(br.block_inst).?;5783 const block_data = func.blocks.getPtr(br.block_inst).?;
5780 const first_br = block_data.relocs.items.len == 0;5784 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 {...@@ -6354,6 +6358,8 @@ fn genCopy(func: *Func, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {
6354 return std.debug.panic("tried to genCopy immutable: {s}", .{@tagName(dst_mcv)});6358 return std.debug.panic("tried to genCopy immutable: {s}", .{@tagName(dst_mcv)});
6355 }6359 }
63566360
6361 const zcu = func.pt.zcu;
6362
6357 switch (dst_mcv) {6363 switch (dst_mcv) {
6358 .register => |reg| return func.genSetReg(ty, reg, src_mcv),6364 .register => |reg| return func.genSetReg(ty, reg, src_mcv),
6359 .register_offset => |dst_reg_off| try func.genSetReg(ty, dst_reg_off.reg, switch (src_mcv) {6365 .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 {...@@ -6425,7 +6431,7 @@ fn genCopy(func: *Func, ty: Type, dst_mcv: MCValue, src_mcv: MCValue) !void {
6425 } },6431 } },
6426 else => unreachable,6432 else => unreachable,
6427 });6433 });
6428 part_disp += @intCast(dst_ty.abiSize(func.pt));6434 part_disp += @intCast(dst_ty.abiSize(zcu));
6429 }6435 }
6430 },6436 },
6431 else => return std.debug.panic("TODO: genCopy to {s} from {s}", .{ @tagName(dst_mcv), @tagName(src_mcv) }),6437 else => return std.debug.panic("TODO: genCopy to {s} from {s}", .{ @tagName(dst_mcv), @tagName(src_mcv) }),
...@@ -6622,7 +6628,7 @@ fn genInlineMemset(...@@ -6622,7 +6628,7 @@ fn genInlineMemset(
6622fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!void {6628fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!void {
6623 const pt = func.pt;6629 const pt = func.pt;
6624 const zcu = pt.zcu;6630 const zcu = pt.zcu;
6625 const abi_size: u32 = @intCast(ty.abiSize(pt));6631 const abi_size: u32 = @intCast(ty.abiSize(zcu));
66266632
6627 const max_size: u32 = switch (reg.class()) {6633 const max_size: u32 = switch (reg.class()) {
6628 .int => 64,6634 .int => 64,
...@@ -6729,7 +6735,7 @@ fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!...@@ -6729,7 +6735,7 @@ fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!
6729 // size to the total size of the vector, and vmv.x.s will work then6735 // size to the total size of the vector, and vmv.x.s will work then
6730 if (src_reg.class() == .vector) {6736 if (src_reg.class() == .vector) {
6731 try func.setVl(.zero, 0, .{6737 try func.setVl(.zero, 0, .{
6732 .vsew = switch (ty.totalVectorBits(pt)) {6738 .vsew = switch (ty.totalVectorBits(zcu)) {
6733 8 => .@"8",6739 8 => .@"8",
6734 16 => .@"16",6740 16 => .@"16",
6735 32 => .@"32",6741 32 => .@"32",
...@@ -6848,7 +6854,7 @@ fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!...@@ -6848,7 +6854,7 @@ fn genSetReg(func: *Func, ty: Type, reg: Register, src_mcv: MCValue) InnerError!
6848 // and load from it.6854 // and load from it.
6849 const len = ty.vectorLen(zcu);6855 const len = ty.vectorLen(zcu);
6850 const elem_ty = ty.childType(zcu);6856 const elem_ty = ty.childType(zcu);
6851 const elem_size = elem_ty.abiSize(pt);6857 const elem_size = elem_ty.abiSize(zcu);
68526858
6853 try func.setVl(.zero, len, .{6859 try func.setVl(.zero, len, .{
6854 .vsew = switch (elem_size) {6860 .vsew = switch (elem_size) {
...@@ -6945,7 +6951,7 @@ fn genSetMem(...@@ -6945,7 +6951,7 @@ fn genSetMem(
6945 const pt = func.pt;6951 const pt = func.pt;
6946 const zcu = pt.zcu;6952 const zcu = pt.zcu;
69476953
6948 const abi_size: u32 = @intCast(ty.abiSize(pt));6954 const abi_size: u32 = @intCast(ty.abiSize(zcu));
6949 const dst_ptr_mcv: MCValue = switch (base) {6955 const dst_ptr_mcv: MCValue = switch (base) {
6950 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },6956 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },
6951 .frame => |base_frame_index| .{ .lea_frame = .{ .index = base_frame_index, .off = disp } },6957 .frame => |base_frame_index| .{ .lea_frame = .{ .index = base_frame_index, .off = disp } },
...@@ -6995,7 +7001,7 @@ fn genSetMem(...@@ -6995,7 +7001,7 @@ fn genSetMem(
6995 const addr_reg = try func.copyToTmpRegister(Type.u64, dst_ptr_mcv);7001 const addr_reg = try func.copyToTmpRegister(Type.u64, dst_ptr_mcv);
69967002
6997 const num_elem = ty.vectorLen(zcu);7003 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
7000 try func.setVl(.zero, num_elem, .{7006 try func.setVl(.zero, num_elem, .{
7001 .vsew = switch (elem_size) {7007 .vsew = switch (elem_size) {
...@@ -7083,7 +7089,7 @@ fn genSetMem(...@@ -7083,7 +7089,7 @@ fn genSetMem(
7083 var part_disp: i32 = disp;7089 var part_disp: i32 = disp;
7084 for (try func.splitType(ty), src_regs) |src_ty, src_reg| {7090 for (try func.splitType(ty), src_regs) |src_ty, src_reg| {
7085 try func.genSetMem(base, part_disp, src_ty, .{ .register = src_reg });7091 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));
7087 }7093 }
7088 },7094 },
7089 .immediate => {7095 .immediate => {
...@@ -7128,10 +7134,10 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {...@@ -7128,10 +7134,10 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
7128 const src_lock = if (src_mcv.getReg()) |reg| func.register_manager.lockReg(reg) else null;7134 const src_lock = if (src_mcv.getReg()) |reg| func.register_manager.lockReg(reg) else null;
7129 defer if (src_lock) |lock| func.register_manager.unlockReg(lock);7135 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 and7137 const dst_mcv = if (dst_ty.abiSize(zcu) <= src_ty.abiSize(zcu) and src_mcv != .register_pair and
7132 func.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {7138 func.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {
7133 const dst_mcv = try func.allocRegOrMem(dst_ty, inst, true);7139 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))) {
7135 .lt => dst_ty,7141 .lt => dst_ty,
7136 .eq => if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,7142 .eq => if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,
7137 .gt => src_ty,7143 .gt => src_ty,
...@@ -7142,8 +7148,8 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {...@@ -7142,8 +7148,8 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
7142 if (dst_ty.isAbiInt(zcu) and src_ty.isAbiInt(zcu) and7148 if (dst_ty.isAbiInt(zcu) and src_ty.isAbiInt(zcu) and
7143 dst_ty.intInfo(zcu).signedness == src_ty.intInfo(zcu).signedness) break :result dst_mcv;7149 dst_ty.intInfo(zcu).signedness == src_ty.intInfo(zcu).signedness) break :result dst_mcv;
71447150
7145 const abi_size = dst_ty.abiSize(pt);7151 const abi_size = dst_ty.abiSize(zcu);
7146 const bit_size = dst_ty.bitSize(pt);7152 const bit_size = dst_ty.bitSize(zcu);
7147 if (abi_size * 8 <= bit_size) break :result dst_mcv;7153 if (abi_size * 8 <= bit_size) break :result dst_mcv;
71487154
7149 return func.fail("TODO: airBitCast {} to {}", .{ src_ty.fmt(pt), dst_ty.fmt(pt) });7155 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 {...@@ -7162,11 +7168,11 @@ fn airArrayToSlice(func: *Func, inst: Air.Inst.Index) !void {
7162 const array_ty = ptr_ty.childType(zcu);7168 const array_ty = ptr_ty.childType(zcu);
7163 const array_len = array_ty.arrayLen(zcu);7169 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));
7166 try func.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);7172 try func.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
7167 try func.genSetMem(7173 try func.genSetMem(
7168 .{ .frame = frame_index },7174 .{ .frame = frame_index },
7169 @intCast(ptr_ty.abiSize(pt)),7175 @intCast(ptr_ty.abiSize(zcu)),
7170 Type.u64,7176 Type.u64,
7171 .{ .immediate = array_len },7177 .{ .immediate = array_len },
7172 );7178 );
...@@ -7190,21 +7196,21 @@ fn airFloatFromInt(func: *Func, inst: Air.Inst.Index) !void {...@@ -7190,21 +7196,21 @@ fn airFloatFromInt(func: *Func, inst: Air.Inst.Index) !void {
7190 defer if (src_lock) |lock| func.register_manager.unlockReg(lock);7196 defer if (src_lock) |lock| func.register_manager.unlockReg(lock);
71917197
7192 const is_unsigned = dst_ty.isUnsignedInt(zcu);7198 const is_unsigned = dst_ty.isUnsignedInt(zcu);
7193 const src_bits = src_ty.bitSize(pt);7199 const src_bits = src_ty.bitSize(zcu);
7194 const dst_bits = dst_ty.bitSize(pt);7200 const dst_bits = dst_ty.bitSize(zcu);
71957201
7196 switch (src_bits) {7202 switch (src_bits) {
7197 32, 64 => {},7203 32, 64 => {},
7198 else => try func.truncateRegister(src_ty, src_reg),7204 else => try func.truncateRegister(src_ty, src_reg),
7199 }7205 }
72007206
7201 const int_mod: Mir.FcvtOp = switch (src_bits) {7207 const int_zcu: Mir.FcvtOp = switch (src_bits) {
7202 8, 16, 32 => if (is_unsigned) .wu else .w,7208 8, 16, 32 => if (is_unsigned) .wu else .w,
7203 64 => if (is_unsigned) .lu else .l,7209 64 => if (is_unsigned) .lu else .l,
7204 else => return func.fail("TODO: airFloatFromInt src size: {d}", .{src_bits}),7210 else => return func.fail("TODO: airFloatFromInt src size: {d}", .{src_bits}),
7205 };7211 };
72067212
7207 const float_mod: enum { s, d } = switch (dst_bits) {7213 const float_zcu: enum { s, d } = switch (dst_bits) {
7208 32 => .s,7214 32 => .s,
7209 64 => .d,7215 64 => .d,
7210 else => return func.fail("TODO: airFloatFromInt dst size {d}", .{dst_bits}),7216 else => return func.fail("TODO: airFloatFromInt dst size {d}", .{dst_bits}),
...@@ -7214,14 +7220,14 @@ fn airFloatFromInt(func: *Func, inst: Air.Inst.Index) !void {...@@ -7214,14 +7220,14 @@ fn airFloatFromInt(func: *Func, inst: Air.Inst.Index) !void {
7214 defer func.register_manager.unlockReg(dst_lock);7220 defer func.register_manager.unlockReg(dst_lock);
72157221
7216 _ = try func.addInst(.{7222 _ = try func.addInst(.{
7217 .tag = switch (float_mod) {7223 .tag = switch (float_zcu) {
7218 .s => switch (int_mod) {7224 .s => switch (int_zcu) {
7219 .l => .fcvtsl,7225 .l => .fcvtsl,
7220 .lu => .fcvtslu,7226 .lu => .fcvtslu,
7221 .w => .fcvtsw,7227 .w => .fcvtsw,
7222 .wu => .fcvtswu,7228 .wu => .fcvtswu,
7223 },7229 },
7224 .d => switch (int_mod) {7230 .d => switch (int_zcu) {
7225 .l => .fcvtdl,7231 .l => .fcvtdl,
7226 .lu => .fcvtdlu,7232 .lu => .fcvtdlu,
7227 .w => .fcvtdw,7233 .w => .fcvtdw,
...@@ -7250,16 +7256,16 @@ fn airIntFromFloat(func: *Func, inst: Air.Inst.Index) !void {...@@ -7250,16 +7256,16 @@ fn airIntFromFloat(func: *Func, inst: Air.Inst.Index) !void {
7250 const dst_ty = ty_op.ty.toType();7256 const dst_ty = ty_op.ty.toType();
72517257
7252 const is_unsigned = dst_ty.isUnsignedInt(zcu);7258 const is_unsigned = dst_ty.isUnsignedInt(zcu);
7253 const src_bits = src_ty.bitSize(pt);7259 const src_bits = src_ty.bitSize(zcu);
7254 const dst_bits = dst_ty.bitSize(pt);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) {
7257 32 => .s,7263 32 => .s,
7258 64 => .d,7264 64 => .d,
7259 else => return func.fail("TODO: airIntFromFloat src size {d}", .{src_bits}),7265 else => return func.fail("TODO: airIntFromFloat src size {d}", .{src_bits}),
7260 };7266 };
72617267
7262 const int_mod: Mir.FcvtOp = switch (dst_bits) {7268 const int_zcu: Mir.FcvtOp = switch (dst_bits) {
7263 32 => if (is_unsigned) .wu else .w,7269 32 => if (is_unsigned) .wu else .w,
7264 8, 16, 64 => if (is_unsigned) .lu else .l,7270 8, 16, 64 => if (is_unsigned) .lu else .l,
7265 else => return func.fail("TODO: airIntFromFloat dst size: {d}", .{dst_bits}),7271 else => return func.fail("TODO: airIntFromFloat dst size: {d}", .{dst_bits}),
...@@ -7272,14 +7278,14 @@ fn airIntFromFloat(func: *Func, inst: Air.Inst.Index) !void {...@@ -7272,14 +7278,14 @@ fn airIntFromFloat(func: *Func, inst: Air.Inst.Index) !void {
7272 defer func.register_manager.unlockReg(dst_lock);7278 defer func.register_manager.unlockReg(dst_lock);
72737279
7274 _ = try func.addInst(.{7280 _ = try func.addInst(.{
7275 .tag = switch (float_mod) {7281 .tag = switch (float_zcu) {
7276 .s => switch (int_mod) {7282 .s => switch (int_zcu) {
7277 .l => .fcvtls,7283 .l => .fcvtls,
7278 .lu => .fcvtlus,7284 .lu => .fcvtlus,
7279 .w => .fcvtws,7285 .w => .fcvtws,
7280 .wu => .fcvtwus,7286 .wu => .fcvtwus,
7281 },7287 },
7282 .d => switch (int_mod) {7288 .d => switch (int_zcu) {
7283 .l => .fcvtld,7289 .l => .fcvtld,
7284 .lu => .fcvtlud,7290 .lu => .fcvtlud,
7285 .w => .fcvtwd,7291 .w => .fcvtwd,
...@@ -7301,12 +7307,13 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }...@@ -7301,12 +7307,13 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
7301 _ = strength; // TODO: do something with this7307 _ = strength; // TODO: do something with this
73027308
7303 const pt = func.pt;7309 const pt = func.pt;
7310 const zcu = pt.zcu;
7304 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;7311 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7305 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;7312 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
73067313
7307 const ptr_ty = func.typeOf(extra.ptr);7314 const ptr_ty = func.typeOf(extra.ptr);
7308 const val_ty = func.typeOf(extra.expected_value);7315 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
7311 switch (val_abi_size) {7318 switch (val_abi_size) {
7312 1, 2, 4, 8 => {},7319 1, 2, 4, 8 => {},
...@@ -7364,7 +7371,7 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }...@@ -7364,7 +7371,7 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
7364 defer func.register_manager.unlockReg(fallthrough_lock);7371 defer func.register_manager.unlockReg(fallthrough_lock);
73657372
7366 const jump_back = try func.addInst(.{7373 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,
7368 .data = .{ .amo = .{7375 .data = .{ .amo = .{
7369 .aq = lr_order.aq,7376 .aq = lr_order.aq,
7370 .rl = lr_order.rl,7377 .rl = lr_order.rl,
...@@ -7385,7 +7392,7 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }...@@ -7385,7 +7392,7 @@ fn airCmpxchg(func: *Func, inst: Air.Inst.Index, strength: enum { weak, strong }
7385 });7392 });
73867393
7387 _ = try func.addInst(.{7394 _ = 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,
7389 .data = .{ .amo = .{7396 .data = .{ .amo = .{
7390 .aq = sc_order.aq,7397 .aq = sc_order.aq,
7391 .rl = sc_order.rl,7398 .rl = sc_order.rl,
...@@ -7449,7 +7456,7 @@ fn airAtomicRmw(func: *Func, inst: Air.Inst.Index) !void {...@@ -7449,7 +7456,7 @@ fn airAtomicRmw(func: *Func, inst: Air.Inst.Index) !void {
7449 const ptr_mcv = try func.resolveInst(pl_op.operand);7456 const ptr_mcv = try func.resolveInst(pl_op.operand);
74507457
7451 const val_ty = func.typeOf(extra.operand);7458 const val_ty = func.typeOf(extra.operand);
7452 const val_size = val_ty.abiSize(pt);7459 const val_size = val_ty.abiSize(zcu);
7453 const val_mcv = try func.resolveInst(extra.operand);7460 const val_mcv = try func.resolveInst(extra.operand);
74547461
7455 if (!math.isPowerOfTwo(val_size))7462 if (!math.isPowerOfTwo(val_size))
...@@ -7488,7 +7495,7 @@ fn airAtomicRmw(func: *Func, inst: Air.Inst.Index) !void {...@@ -7488,7 +7495,7 @@ fn airAtomicRmw(func: *Func, inst: Air.Inst.Index) !void {
74887495
7489 switch (method) {7496 switch (method) {
7490 .amo => {7497 .amo => {
7491 const is_d = val_ty.abiSize(pt) == 8;7498 const is_d = val_ty.abiSize(zcu) == 8;
7492 const is_un = val_ty.isUnsignedInt(zcu);7499 const is_un = val_ty.isUnsignedInt(zcu);
74937500
7494 const mnem: Mnemonic = switch (op) {7501 const mnem: Mnemonic = switch (op) {
...@@ -7587,7 +7594,7 @@ fn airAtomicLoad(func: *Func, inst: Air.Inst.Index) !void {...@@ -7587,7 +7594,7 @@ fn airAtomicLoad(func: *Func, inst: Air.Inst.Index) !void {
7587 const elem_ty = ptr_ty.childType(zcu);7594 const elem_ty = ptr_ty.childType(zcu);
7588 const ptr_mcv = try func.resolveInst(atomic_load.ptr);7595 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);
7591 if (bit_size > 64) return func.fail("TODO: airAtomicStore > 64 bits", .{});7598 if (bit_size > 64) return func.fail("TODO: airAtomicStore > 64 bits", .{});
75927599
7593 const result_mcv = try func.allocRegOrMem(elem_ty, inst, true);7600 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...@@ -7634,7 +7641,7 @@ fn airAtomicStore(func: *Func, inst: Air.Inst.Index, order: std.builtin.AtomicOr
7634 const val_ty = func.typeOf(bin_op.rhs);7641 const val_ty = func.typeOf(bin_op.rhs);
7635 const val_mcv = try func.resolveInst(bin_op.rhs);7642 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);
7638 if (bit_size > 64) return func.fail("TODO: airAtomicStore > 64 bits", .{});7645 if (bit_size > 64) return func.fail("TODO: airAtomicStore > 64 bits", .{});
76397646
7640 switch (order) {7647 switch (order) {
...@@ -7679,7 +7686,7 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void {...@@ -7679,7 +7686,7 @@ fn airMemset(func: *Func, inst: Air.Inst.Index, safety: bool) !void {
7679 };7686 };
7680 defer if (src_val_lock) |lock| func.register_manager.unlockReg(lock);7687 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
7684 if (elem_abi_size == 1) {7691 if (elem_abi_size == 1) {
7685 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {7692 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
...@@ -7751,7 +7758,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {...@@ -7751,7 +7758,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {
7751 const len_reg, const len_lock = try func.allocReg(.int);7758 const len_reg, const len_lock = try func.allocReg(.int);
7752 defer func.register_manager.unlockReg(len_lock);7759 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);
7755 try func.genBinOp(7762 try func.genBinOp(
7756 .mul,7763 .mul,
7757 .{ .immediate = elem_size },7764 .{ .immediate = elem_size },
...@@ -7764,7 +7771,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {...@@ -7764,7 +7771,7 @@ fn airMemcpy(func: *Func, inst: Air.Inst.Index) !void {
7764 },7771 },
7765 .One => len: {7772 .One => len: {
7766 const array_ty = dst_ty.childType(zcu);7773 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) };
7768 },7775 },
7769 else => |size| return func.fail("TODO: airMemcpy size {s}", .{@tagName(size)}),7776 else => |size| return func.fail("TODO: airMemcpy size {s}", .{@tagName(size)}),
7770 };7777 };
...@@ -7862,21 +7869,21 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {...@@ -7862,21 +7869,21 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
7862 const result: MCValue = result: {7869 const result: MCValue = result: {
7863 switch (result_ty.zigTypeTag(zcu)) {7870 switch (result_ty.zigTypeTag(zcu)) {
7864 .Struct => {7871 .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));
7866 if (result_ty.containerLayout(zcu) == .@"packed") {7873 if (result_ty.containerLayout(zcu) == .@"packed") {
7867 const struct_obj = zcu.typeToStruct(result_ty).?;7874 const struct_obj = zcu.typeToStruct(result_ty).?;
7868 try func.genInlineMemset(7875 try func.genInlineMemset(
7869 .{ .lea_frame = .{ .index = frame_index } },7876 .{ .lea_frame = .{ .index = frame_index } },
7870 .{ .immediate = 0 },7877 .{ .immediate = 0 },
7871 .{ .immediate = result_ty.abiSize(pt) },7878 .{ .immediate = result_ty.abiSize(zcu) },
7872 );7879 );
78737880
7874 for (elements, 0..) |elem, elem_i_usize| {7881 for (elements, 0..) |elem, elem_i_usize| {
7875 const elem_i: u32 = @intCast(elem_i_usize);7882 const elem_i: u32 = @intCast(elem_i_usize);
7876 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;7883 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
78777884
7878 const elem_ty = result_ty.structFieldType(elem_i, zcu);7885 const elem_ty = result_ty.fieldType(elem_i, zcu);
7879 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(pt));7886 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(zcu));
7880 if (elem_bit_size > 64) {7887 if (elem_bit_size > 64) {
7881 return func.fail(7888 return func.fail(
7882 "TODO airAggregateInit implement packed structs with large fields",7889 "TODO airAggregateInit implement packed structs with large fields",
...@@ -7884,7 +7891,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {...@@ -7884,7 +7891,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
7884 );7891 );
7885 }7892 }
78867893
7887 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(pt));7894 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(zcu));
7888 const elem_abi_bits = elem_abi_size * 8;7895 const elem_abi_bits = elem_abi_size * 8;
7889 const elem_off = pt.structPackedFieldBitOffset(struct_obj, elem_i);7896 const elem_off = pt.structPackedFieldBitOffset(struct_obj, elem_i);
7890 const elem_byte_off: i32 = @intCast(elem_off / elem_abi_bits * elem_abi_size);7897 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 {...@@ -7909,8 +7916,8 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
7909 } else for (elements, 0..) |elem, elem_i| {7916 } else for (elements, 0..) |elem, elem_i| {
7910 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;7917 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
79117918
7912 const elem_ty = result_ty.structFieldType(elem_i, zcu);7919 const elem_ty = result_ty.fieldType(elem_i, zcu);
7913 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, pt));7920 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, zcu));
7914 const elem_mcv = try func.resolveInst(elem);7921 const elem_mcv = try func.resolveInst(elem);
7915 try func.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, elem_mcv);7922 try func.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, elem_mcv);
7916 }7923 }
...@@ -7918,8 +7925,8 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {...@@ -7918,8 +7925,8 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void {
7918 },7925 },
7919 .Array => {7926 .Array => {
7920 const elem_ty = result_ty.childType(zcu);7927 const elem_ty = result_ty.childType(zcu);
7921 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(result_ty, pt));7928 const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(result_ty, zcu));
7922 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));7929 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
79237930
7924 for (elements, 0..) |elem, elem_i| {7931 for (elements, 0..) |elem, elem_i| {
7925 const elem_mcv = try func.resolveInst(elem);7932 const elem_mcv = try func.resolveInst(elem);
...@@ -7979,10 +7986,11 @@ fn airMulAdd(func: *Func, inst: Air.Inst.Index) !void {...@@ -7979,10 +7986,11 @@ fn airMulAdd(func: *Func, inst: Air.Inst.Index) !void {
79797986
7980fn resolveInst(func: *Func, ref: Air.Inst.Ref) InnerError!MCValue {7987fn resolveInst(func: *Func, ref: Air.Inst.Ref) InnerError!MCValue {
7981 const pt = func.pt;7988 const pt = func.pt;
7989 const zcu = pt.zcu;
79827990
7983 // If the type has no codegen bits, no need to store it.7991 // If the type has no codegen bits, no need to store it.
7984 const inst_ty = func.typeOf(ref);7992 const inst_ty = func.typeOf(ref);
7985 if (!inst_ty.hasRuntimeBits(pt))7993 if (!inst_ty.hasRuntimeBits(zcu))
7986 return .none;7994 return .none;
79877995
7988 const mcv = if (ref.toIndex()) |inst| mcv: {7996 const mcv = if (ref.toIndex()) |inst| mcv: {
...@@ -8100,14 +8108,14 @@ fn resolveCallingConventionValues(...@@ -8100,14 +8108,14 @@ fn resolveCallingConventionValues(
8100 // Return values8108 // Return values
8101 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {8109 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
8102 result.return_value = InstTracking.init(.unreach);8110 result.return_value = InstTracking.init(.unreach);
8103 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {8111 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8104 result.return_value = InstTracking.init(.none);8112 result.return_value = InstTracking.init(.none);
8105 } else {8113 } else {
8106 var ret_tracking: [2]InstTracking = undefined;8114 var ret_tracking: [2]InstTracking = undefined;
8107 var ret_tracking_i: usize = 0;8115 var ret_tracking_i: usize = 0;
8108 var ret_float_reg_i: usize = 0;8116 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
8112 for (classes) |class| switch (class) {8120 for (classes) |class| switch (class) {
8113 .integer => {8121 .integer => {
...@@ -8151,7 +8159,7 @@ fn resolveCallingConventionValues(...@@ -8151,7 +8159,7 @@ fn resolveCallingConventionValues(
8151 var param_float_reg_i: usize = 0;8159 var param_float_reg_i: usize = 0;
81528160
8153 for (param_types, result.args) |ty, *arg| {8161 for (param_types, result.args) |ty, *arg| {
8154 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {8162 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8155 assert(cc == .Unspecified);8163 assert(cc == .Unspecified);
8156 arg.* = .none;8164 arg.* = .none;
8157 continue;8165 continue;
...@@ -8160,7 +8168,7 @@ fn resolveCallingConventionValues(...@@ -8160,7 +8168,7 @@ fn resolveCallingConventionValues(
8160 var arg_mcv: [2]MCValue = undefined;8168 var arg_mcv: [2]MCValue = undefined;
8161 var arg_mcv_i: usize = 0;8169 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
8165 for (classes) |class| switch (class) {8173 for (classes) |class| switch (class) {
8166 .integer => {8174 .integer => {
...@@ -8244,8 +8252,7 @@ fn typeOf(func: *Func, inst: Air.Inst.Ref) Type {...@@ -8244,8 +8252,7 @@ fn typeOf(func: *Func, inst: Air.Inst.Ref) Type {
8244}8252}
82458253
8246fn typeOfIndex(func: *Func, inst: Air.Inst.Index) Type {8254fn typeOfIndex(func: *Func, inst: Air.Inst.Index) Type {
8247 const pt = func.pt;8255 const zcu = func.pt.zcu;
8248 const zcu = pt.zcu;
8249 return func.air.typeOfIndex(inst, &zcu.intern_pool);8256 return func.air.typeOfIndex(inst, &zcu.intern_pool);
8250}8257}
82518258
...@@ -8253,23 +8260,23 @@ fn hasFeature(func: *Func, feature: Target.riscv.Feature) bool {...@@ -8253,23 +8260,23 @@ fn hasFeature(func: *Func, feature: Target.riscv.Feature) bool {
8253 return Target.riscv.featureSetHas(func.target.cpu.features, feature);8260 return Target.riscv.featureSetHas(func.target.cpu.features, feature);
8254}8261}
82558262
8256pub fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {8263pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
8257 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;8264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
8258 const payload_align = payload_ty.abiAlignment(pt);8265 const payload_align = payload_ty.abiAlignment(zcu);
8259 const error_align = Type.anyerror.abiAlignment(pt);8266 const error_align = Type.anyerror.abiAlignment(zcu);
8260 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {8267 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8261 return 0;8268 return 0;
8262 } else {8269 } else {
8263 return payload_align.forward(Type.anyerror.abiSize(pt));8270 return payload_align.forward(Type.anyerror.abiSize(zcu));
8264 }8271 }
8265}8272}
82668273
8267pub fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {8274pub fn errUnionErrorOffset(payload_ty: Type, zcu: *Zcu) u64 {
8268 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;8275 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
8269 const payload_align = payload_ty.abiAlignment(pt);8276 const payload_align = payload_ty.abiAlignment(zcu);
8270 const error_align = Type.anyerror.abiAlignment(pt);8277 const error_align = Type.anyerror.abiAlignment(zcu);
8271 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {8278 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
8272 return error_align.forward(payload_ty.abiSize(pt));8279 return error_align.forward(payload_ty.abiSize(zcu));
8273 } else {8280 } else {
8274 return 0;8281 return 0;
8275 }8282 }
src/arch/riscv64/Lower.zig+4-3
...@@ -49,6 +49,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index, options: struct {...@@ -49,6 +49,7 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index, options: struct {
49 relocs: []const Reloc,49 relocs: []const Reloc,
50} {50} {
51 const pt = lower.pt;51 const pt = lower.pt;
52 const zcu = pt.zcu;
5253
53 lower.result_insts = undefined;54 lower.result_insts = undefined;
54 lower.result_relocs = undefined;55 lower.result_relocs = undefined;
...@@ -308,11 +309,11 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index, options: struct {...@@ -308,11 +309,11 @@ pub fn lowerMir(lower: *Lower, index: Mir.Inst.Index, options: struct {
308309
309 const class = rs1.class();310 const class = rs1.class();
310 const ty = compare.ty;311 const ty = compare.ty;
311 const size = std.math.ceilPowerOfTwo(u64, ty.bitSize(pt)) catch {312 const size = std.math.ceilPowerOfTwo(u64, ty.bitSize(zcu)) catch {
312 return lower.fail("pseudo_compare size {}", .{ty.bitSize(pt)});313 return lower.fail("pseudo_compare size {}", .{ty.bitSize(zcu)});
313 };314 };
314315
315 const is_unsigned = ty.isUnsignedInt(pt.zcu);316 const is_unsigned = ty.isUnsignedInt(zcu);
316 const less_than: Mnemonic = if (is_unsigned) .sltu else .slt;317 const less_than: Mnemonic = if (is_unsigned) .sltu else .slt;
317318
318 switch (class) {319 switch (class) {
src/arch/riscv64/abi.zig+27-28
...@@ -9,15 +9,15 @@ const assert = std.debug.assert;...@@ -9,15 +9,15 @@ const assert = std.debug.assert;
99
10pub const Class = enum { memory, byval, integer, double_integer, fields };10pub const Class = enum { memory, byval, integer, double_integer, fields };
1111
12pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {12pub fn classifyType(ty: Type, zcu: *Zcu) Class {
13 const target = pt.zcu.getTarget();13 const target = zcu.getTarget();
14 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(pt));14 std.debug.assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
1515
16 const max_byval_size = target.ptrBitWidth() * 2;16 const max_byval_size = target.ptrBitWidth() * 2;
17 switch (ty.zigTypeTag(pt.zcu)) {17 switch (ty.zigTypeTag(zcu)) {
18 .Struct => {18 .Struct => {
19 const bit_size = ty.bitSize(pt);19 const bit_size = ty.bitSize(zcu);
20 if (ty.containerLayout(pt.zcu) == .@"packed") {20 if (ty.containerLayout(zcu) == .@"packed") {
21 if (bit_size > max_byval_size) return .memory;21 if (bit_size > max_byval_size) return .memory;
22 return .byval;22 return .byval;
23 }23 }
...@@ -25,12 +25,12 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {...@@ -25,12 +25,12 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
25 if (std.Target.riscv.featureSetHas(target.cpu.features, .d)) fields: {25 if (std.Target.riscv.featureSetHas(target.cpu.features, .d)) fields: {
26 var any_fp = false;26 var any_fp = false;
27 var field_count: usize = 0;27 var field_count: usize = 0;
28 for (0..ty.structFieldCount(pt.zcu)) |field_index| {28 for (0..ty.structFieldCount(zcu)) |field_index| {
29 const field_ty = ty.structFieldType(field_index, pt.zcu);29 const field_ty = ty.fieldType(field_index, zcu);
30 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;30 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
31 if (field_ty.isRuntimeFloat())31 if (field_ty.isRuntimeFloat())
32 any_fp = true32 any_fp = true
33 else if (!field_ty.isAbiInt(pt.zcu))33 else if (!field_ty.isAbiInt(zcu))
34 break :fields;34 break :fields;
35 field_count += 1;35 field_count += 1;
36 if (field_count > 2) break :fields;36 if (field_count > 2) break :fields;
...@@ -45,8 +45,8 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {...@@ -45,8 +45,8 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
45 return .integer;45 return .integer;
46 },46 },
47 .Union => {47 .Union => {
48 const bit_size = ty.bitSize(pt);48 const bit_size = ty.bitSize(zcu);
49 if (ty.containerLayout(pt.zcu) == .@"packed") {49 if (ty.containerLayout(zcu) == .@"packed") {
50 if (bit_size > max_byval_size) return .memory;50 if (bit_size > max_byval_size) return .memory;
51 return .byval;51 return .byval;
52 }52 }
...@@ -58,21 +58,21 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {...@@ -58,21 +58,21 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) Class {
58 .Bool => return .integer,58 .Bool => return .integer,
59 .Float => return .byval,59 .Float => return .byval,
60 .Int, .Enum, .ErrorSet => {60 .Int, .Enum, .ErrorSet => {
61 const bit_size = ty.bitSize(pt);61 const bit_size = ty.bitSize(zcu);
62 if (bit_size > max_byval_size) return .memory;62 if (bit_size > max_byval_size) return .memory;
63 return .byval;63 return .byval;
64 },64 },
65 .Vector => {65 .Vector => {
66 const bit_size = ty.bitSize(pt);66 const bit_size = ty.bitSize(zcu);
67 if (bit_size > max_byval_size) return .memory;67 if (bit_size > max_byval_size) return .memory;
68 return .integer;68 return .integer;
69 },69 },
70 .Optional => {70 .Optional => {
71 std.debug.assert(ty.isPtrLikeOptional(pt.zcu));71 std.debug.assert(ty.isPtrLikeOptional(zcu));
72 return .byval;72 return .byval;
73 },73 },
74 .Pointer => {74 .Pointer => {
75 std.debug.assert(!ty.isSlice(pt.zcu));75 std.debug.assert(!ty.isSlice(zcu));
76 return .byval;76 return .byval;
77 },77 },
78 .ErrorUnion,78 .ErrorUnion,
...@@ -97,19 +97,18 @@ pub const SystemClass = enum { integer, float, memory, none };...@@ -97,19 +97,18 @@ pub const SystemClass = enum { integer, float, memory, none };
9797
98/// There are a maximum of 8 possible return slots. Returned values are in98/// There are a maximum of 8 possible return slots. Returned values are in
99/// the beginning of the array; unused slots are filled with .none.99/// the beginning of the array; unused slots are filled with .none.
100pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {100pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass {
101 const zcu = pt.zcu;
102 var result = [1]SystemClass{.none} ** 8;101 var result = [1]SystemClass{.none} ** 8;
103 const memory_class = [_]SystemClass{102 const memory_class = [_]SystemClass{
104 .memory, .none, .none, .none,103 .memory, .none, .none, .none,
105 .none, .none, .none, .none,104 .none, .none, .none, .none,
106 };105 };
107 switch (ty.zigTypeTag(pt.zcu)) {106 switch (ty.zigTypeTag(zcu)) {
108 .Bool, .Void, .NoReturn => {107 .Bool, .Void, .NoReturn => {
109 result[0] = .integer;108 result[0] = .integer;
110 return result;109 return result;
111 },110 },
112 .Pointer => switch (ty.ptrSize(pt.zcu)) {111 .Pointer => switch (ty.ptrSize(zcu)) {
113 .Slice => {112 .Slice => {
114 result[0] = .integer;113 result[0] = .integer;
115 result[1] = .integer;114 result[1] = .integer;
...@@ -121,14 +120,14 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {...@@ -121,14 +120,14 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
121 },120 },
122 },121 },
123 .Optional => {122 .Optional => {
124 if (ty.isPtrLikeOptional(pt.zcu)) {123 if (ty.isPtrLikeOptional(zcu)) {
125 result[0] = .integer;124 result[0] = .integer;
126 return result;125 return result;
127 }126 }
128 return memory_class;127 return memory_class;
129 },128 },
130 .Int, .Enum, .ErrorSet => {129 .Int, .Enum, .ErrorSet => {
131 const int_bits = ty.intInfo(pt.zcu).bits;130 const int_bits = ty.intInfo(zcu).bits;
132 if (int_bits <= 64) {131 if (int_bits <= 64) {
133 result[0] = .integer;132 result[0] = .integer;
134 return result;133 return result;
...@@ -153,8 +152,8 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {...@@ -153,8 +152,8 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
153 unreachable; // support split float args152 unreachable; // support split float args
154 },153 },
155 .ErrorUnion => {154 .ErrorUnion => {
156 const payload_ty = ty.errorUnionPayload(pt.zcu);155 const payload_ty = ty.errorUnionPayload(zcu);
157 const payload_bits = payload_ty.bitSize(pt);156 const payload_bits = payload_ty.bitSize(zcu);
158157
159 // the error union itself158 // the error union itself
160 result[0] = .integer;159 result[0] = .integer;
...@@ -165,8 +164,8 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {...@@ -165,8 +164,8 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
165 return memory_class;164 return memory_class;
166 },165 },
167 .Struct, .Union => {166 .Struct, .Union => {
168 const layout = ty.containerLayout(pt.zcu);167 const layout = ty.containerLayout(zcu);
169 const ty_size = ty.abiSize(pt);168 const ty_size = ty.abiSize(zcu);
170169
171 if (layout == .@"packed") {170 if (layout == .@"packed") {
172 assert(ty_size <= 16);171 assert(ty_size <= 16);
...@@ -178,7 +177,7 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {...@@ -178,7 +177,7 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
178 return memory_class;177 return memory_class;
179 },178 },
180 .Array => {179 .Array => {
181 const ty_size = ty.abiSize(pt);180 const ty_size = ty.abiSize(zcu);
182 if (ty_size <= 8) {181 if (ty_size <= 8) {
183 result[0] = .integer;182 result[0] = .integer;
184 return result;183 return result;
...@@ -192,7 +191,7 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {...@@ -192,7 +191,7 @@ pub fn classifySystem(ty: Type, pt: Zcu.PerThread) [8]SystemClass {
192 },191 },
193 .Vector => {192 .Vector => {
194 // we pass vectors through integer registers if they are small enough to fit.193 // 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);
196 if (vec_bits <= 64) {195 if (vec_bits <= 64) {
197 result[0] = .integer;196 result[0] = .integer;
198 return result;197 return result;
src/arch/sparc64/CodeGen.zig+139-140
...@@ -365,8 +365,8 @@ pub fn generate(...@@ -365,8 +365,8 @@ pub fn generate(
365365
366fn gen(self: *Self) !void {366fn gen(self: *Self) !void {
367 const pt = self.pt;367 const pt = self.pt;
368 const mod = pt.zcu;368 const zcu = pt.zcu;
369 const cc = self.fn_type.fnCallingConvention(mod);369 const cc = self.fn_type.fnCallingConvention(zcu);
370 if (cc != .Naked) {370 if (cc != .Naked) {
371 // TODO Finish function prologue and epilogue for sparc64.371 // TODO Finish function prologue and epilogue for sparc64.
372372
...@@ -494,8 +494,8 @@ fn gen(self: *Self) !void {...@@ -494,8 +494,8 @@ fn gen(self: *Self) !void {
494494
495fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {495fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
496 const pt = self.pt;496 const pt = self.pt;
497 const mod = pt.zcu;497 const zcu = pt.zcu;
498 const ip = &mod.intern_pool;498 const ip = &zcu.intern_pool;
499 const air_tags = self.air.instructions.items(.tag);499 const air_tags = self.air.instructions.items(.tag);
500500
501 for (body) |inst| {501 for (body) |inst| {
...@@ -760,18 +760,18 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -760,18 +760,18 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
760 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;760 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
761 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;761 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
762 const pt = self.pt;762 const pt = self.pt;
763 const mod = pt.zcu;763 const zcu = pt.zcu;
764 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {764 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
765 const lhs = try self.resolveInst(extra.lhs);765 const lhs = try self.resolveInst(extra.lhs);
766 const rhs = try self.resolveInst(extra.rhs);766 const rhs = try self.resolveInst(extra.rhs);
767 const lhs_ty = self.typeOf(extra.lhs);767 const lhs_ty = self.typeOf(extra.lhs);
768 const rhs_ty = self.typeOf(extra.rhs);768 const rhs_ty = self.typeOf(extra.rhs);
769769
770 switch (lhs_ty.zigTypeTag(mod)) {770 switch (lhs_ty.zigTypeTag(zcu)) {
771 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),771 .Vector => return self.fail("TODO implement add_with_overflow/sub_with_overflow for vectors", .{}),
772 .Int => {772 .Int => {
773 assert(lhs_ty.eql(rhs_ty, mod));773 assert(lhs_ty.eql(rhs_ty, zcu));
774 const int_info = lhs_ty.intInfo(mod);774 const int_info = lhs_ty.intInfo(zcu);
775 switch (int_info.bits) {775 switch (int_info.bits) {
776 32, 64 => {776 32, 64 => {
777 // Only say yes if the operation is777 // Only say yes if the operation is
...@@ -839,9 +839,9 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -839,9 +839,9 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
839839
840fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {840fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
841 const pt = self.pt;841 const pt = self.pt;
842 const mod = pt.zcu;842 const zcu = pt.zcu;
843 const vector_ty = self.typeOfIndex(inst);843 const vector_ty = self.typeOfIndex(inst);
844 const len = vector_ty.vectorLen(mod);844 const len = vector_ty.vectorLen(zcu);
845 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;845 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
846 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));846 const elements = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[ty_pl.payload..][0..len]));
847 const result: MCValue = res: {847 const result: MCValue = res: {
...@@ -874,13 +874,13 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -874,13 +874,13 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
874874
875fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {875fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
876 const pt = self.pt;876 const pt = self.pt;
877 const mod = pt.zcu;877 const zcu = pt.zcu;
878 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;878 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
879 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {879 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
880 const ptr_ty = self.typeOf(ty_op.operand);880 const ptr_ty = self.typeOf(ty_op.operand);
881 const ptr = try self.resolveInst(ty_op.operand);881 const ptr = try self.resolveInst(ty_op.operand);
882 const array_ty = ptr_ty.childType(mod);882 const array_ty = ptr_ty.childType(zcu);
883 const array_len = @as(u32, @intCast(array_ty.arrayLen(mod)));883 const array_len = @as(u32, @intCast(array_ty.arrayLen(zcu)));
884 const ptr_bytes = 8;884 const ptr_bytes = 8;
885 const stack_offset = try self.allocMem(inst, ptr_bytes * 2, .@"8");885 const stack_offset = try self.allocMem(inst, ptr_bytes * 2, .@"8");
886 try self.genSetStack(ptr_ty, stack_offset, ptr);886 try self.genSetStack(ptr_ty, stack_offset, ptr);
...@@ -1012,6 +1012,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -1012,6 +1012,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
10121012
1013fn airArg(self: *Self, inst: Air.Inst.Index) !void {1013fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1014 const pt = self.pt;1014 const pt = self.pt;
1015 const zcu = pt.zcu;
1015 const arg_index = self.arg_index;1016 const arg_index = self.arg_index;
1016 self.arg_index += 1;1017 self.arg_index += 1;
10171018
...@@ -1021,7 +1022,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -1021,7 +1022,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
1021 const mcv = blk: {1022 const mcv = blk: {
1022 switch (arg) {1023 switch (arg) {
1023 .stack_offset => |off| {1024 .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 {
1025 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});1026 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});
1026 };1027 };
1027 const offset = off + abi_size;1028 const offset = off + abi_size;
...@@ -1211,7 +1212,7 @@ fn airBreakpoint(self: *Self) !void {...@@ -1211,7 +1212,7 @@ fn airBreakpoint(self: *Self) !void {
12111212
1212fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {1213fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
1213 const pt = self.pt;1214 const pt = self.pt;
1214 const mod = pt.zcu;1215 const zcu = pt.zcu;
1215 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1216 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
12161217
1217 // We have hardware byteswapper in SPARCv9, don't let mainstream compilers mislead you.1218 // 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 {...@@ -1227,14 +1228,14 @@ fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
1227 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1228 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1228 const operand = try self.resolveInst(ty_op.operand);1229 const operand = try self.resolveInst(ty_op.operand);
1229 const operand_ty = self.typeOf(ty_op.operand);1230 const operand_ty = self.typeOf(ty_op.operand);
1230 switch (operand_ty.zigTypeTag(mod)) {1231 switch (operand_ty.zigTypeTag(zcu)) {
1231 .Vector => return self.fail("TODO byteswap for vectors", .{}),1232 .Vector => return self.fail("TODO byteswap for vectors", .{}),
1232 .Int => {1233 .Int => {
1233 const int_info = operand_ty.intInfo(mod);1234 const int_info = operand_ty.intInfo(zcu);
1234 if (int_info.bits == 8) break :result operand;1235 if (int_info.bits == 8) break :result operand;
12351236
1236 const abi_size = int_info.bits >> 3;1237 const abi_size = int_info.bits >> 3;
1237 const abi_align = operand_ty.abiAlignment(pt);1238 const abi_align = operand_ty.abiAlignment(zcu);
1238 const opposite_endian_asi = switch (self.target.cpu.arch.endian()) {1239 const opposite_endian_asi = switch (self.target.cpu.arch.endian()) {
1239 Endian.big => ASI.asi_primary_little,1240 Endian.big => ASI.asi_primary_little,
1240 Endian.little => ASI.asi_primary,1241 Endian.little => ASI.asi_primary,
...@@ -1304,11 +1305,11 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1304,11 +1305,11 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1304 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len]));1305 const args = @as([]const Air.Inst.Ref, @ptrCast(self.air.extra[extra.end .. extra.end + extra.data.args_len]));
1305 const ty = self.typeOf(callee);1306 const ty = self.typeOf(callee);
1306 const pt = self.pt;1307 const pt = self.pt;
1307 const mod = pt.zcu;1308 const zcu = pt.zcu;
1308 const ip = &mod.intern_pool;1309 const ip = &zcu.intern_pool;
1309 const fn_ty = switch (ty.zigTypeTag(mod)) {1310 const fn_ty = switch (ty.zigTypeTag(zcu)) {
1310 .Fn => ty,1311 .Fn => ty,
1311 .Pointer => ty.childType(mod),1312 .Pointer => ty.childType(zcu),
1312 else => unreachable,1313 else => unreachable,
1313 };1314 };
13141315
...@@ -1360,7 +1361,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier...@@ -1360,7 +1361,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
1360 return self.fail("TODO implement calling bitcasted functions", .{});1361 return self.fail("TODO implement calling bitcasted functions", .{});
1361 },1362 },
1362 } else {1363 } else {
1363 assert(ty.zigTypeTag(mod) == .Pointer);1364 assert(ty.zigTypeTag(zcu) == .Pointer);
1364 const mcv = try self.resolveInst(callee);1365 const mcv = try self.resolveInst(callee);
1365 try self.genSetReg(ty, .o7, mcv);1366 try self.genSetReg(ty, .o7, mcv);
13661367
...@@ -1409,24 +1410,24 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -1409,24 +1410,24 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
1409fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {1410fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1410 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;1411 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1411 const pt = self.pt;1412 const pt = self.pt;
1412 const mod = pt.zcu;1413 const zcu = pt.zcu;
1413 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {1414 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
1414 const lhs = try self.resolveInst(bin_op.lhs);1415 const lhs = try self.resolveInst(bin_op.lhs);
1415 const rhs = try self.resolveInst(bin_op.rhs);1416 const rhs = try self.resolveInst(bin_op.rhs);
1416 const lhs_ty = self.typeOf(bin_op.lhs);1417 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)) {
1419 .Vector => unreachable, // Handled by cmp_vector.1420 .Vector => unreachable, // Handled by cmp_vector.
1420 .Enum => lhs_ty.intTagType(mod),1421 .Enum => lhs_ty.intTagType(zcu),
1421 .Int => lhs_ty,1422 .Int => lhs_ty,
1422 .Bool => Type.u1,1423 .Bool => Type.u1,
1423 .Pointer => Type.usize,1424 .Pointer => Type.usize,
1424 .ErrorSet => Type.u16,1425 .ErrorSet => Type.u16,
1425 .Optional => blk: {1426 .Optional => blk: {
1426 const payload_ty = lhs_ty.optionalChild(mod);1427 const payload_ty = lhs_ty.optionalChild(zcu);
1427 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {1428 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1428 break :blk Type.u1;1429 break :blk Type.u1;
1429 } else if (lhs_ty.isPtrLikeOptional(mod)) {1430 } else if (lhs_ty.isPtrLikeOptional(zcu)) {
1430 break :blk Type.usize;1431 break :blk Type.usize;
1431 } else {1432 } else {
1432 return self.fail("TODO SPARCv9 cmp non-pointer optionals", .{});1433 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 {...@@ -1436,7 +1437,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
1436 else => unreachable,1437 else => unreachable,
1437 };1438 };
14381439
1439 const int_info = int_ty.intInfo(mod);1440 const int_info = int_ty.intInfo(zcu);
1440 if (int_info.bits <= 64) {1441 if (int_info.bits <= 64) {
1441 _ = try self.binOp(.cmp_eq, lhs, rhs, int_ty, int_ty, BinOpMetadata{1442 _ = try self.binOp(.cmp_eq, lhs, rhs, int_ty, int_ty, BinOpMetadata{
1442 .lhs = bin_op.lhs,1443 .lhs = bin_op.lhs,
...@@ -1635,13 +1636,9 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -1635,13 +1636,9 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
1635}1636}
16361637
1637fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {1638fn airDbgInlineBlock(self: *Self, inst: Air.Inst.Index) !void {
1638 const pt = self.pt;
1639 const mod = pt.zcu;
1640 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;1639 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
1641 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);1640 const extra = self.air.extraData(Air.DbgInlineBlock, ty_pl.payload);
1642 const func = mod.funcInfo(extra.data.func);
1643 // TODO emit debug info for function change1641 // TODO emit debug info for function change
1644 _ = func;
1645 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));1642 try self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
1646}1643}
16471644
...@@ -1735,11 +1732,11 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -1735,11 +1732,11 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
1735 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });1732 return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
17361733
1737 const pt = self.pt;1734 const pt = self.pt;
1738 const mod = pt.zcu;1735 const zcu = pt.zcu;
1739 const operand_ty = self.typeOf(ty_op.operand);1736 const operand_ty = self.typeOf(ty_op.operand);
1740 const operand = try self.resolveInst(ty_op.operand);1737 const operand = try self.resolveInst(ty_op.operand);
1741 const info_a = operand_ty.intInfo(mod);1738 const info_a = operand_ty.intInfo(zcu);
1742 const info_b = self.typeOfIndex(inst).intInfo(mod);1739 const info_b = self.typeOfIndex(inst).intInfo(zcu);
1743 if (info_a.signedness != info_b.signedness)1740 if (info_a.signedness != info_b.signedness)
1744 return self.fail("TODO gen intcast sign safety in semantic analysis", .{});1741 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 {...@@ -1797,16 +1794,16 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
17971794
1798fn airLoad(self: *Self, inst: Air.Inst.Index) !void {1795fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
1799 const pt = self.pt;1796 const pt = self.pt;
1800 const mod = pt.zcu;1797 const zcu = pt.zcu;
1801 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;1798 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1802 const elem_ty = self.typeOfIndex(inst);1799 const elem_ty = self.typeOfIndex(inst);
1803 const elem_size = elem_ty.abiSize(pt);1800 const elem_size = elem_ty.abiSize(zcu);
1804 const result: MCValue = result: {1801 const result: MCValue = result: {
1805 if (!elem_ty.hasRuntimeBits(pt))1802 if (!elem_ty.hasRuntimeBits(zcu))
1806 break :result MCValue.none;1803 break :result MCValue.none;
18071804
1808 const ptr = try self.resolveInst(ty_op.operand);1805 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);
1810 if (self.liveness.isUnused(inst) and !is_volatile)1807 if (self.liveness.isUnused(inst) and !is_volatile)
1811 break :result MCValue.dead;1808 break :result MCValue.dead;
18121809
...@@ -2024,18 +2021,18 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2024,18 +2021,18 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2024 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2021 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2025 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2022 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2026 const pt = self.pt;2023 const pt = self.pt;
2027 const mod = pt.zcu;2024 const zcu = pt.zcu;
2028 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2025 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2029 const lhs = try self.resolveInst(extra.lhs);2026 const lhs = try self.resolveInst(extra.lhs);
2030 const rhs = try self.resolveInst(extra.rhs);2027 const rhs = try self.resolveInst(extra.rhs);
2031 const lhs_ty = self.typeOf(extra.lhs);2028 const lhs_ty = self.typeOf(extra.lhs);
2032 const rhs_ty = self.typeOf(extra.rhs);2029 const rhs_ty = self.typeOf(extra.rhs);
20332030
2034 switch (lhs_ty.zigTypeTag(mod)) {2031 switch (lhs_ty.zigTypeTag(zcu)) {
2035 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),2032 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
2036 .Int => {2033 .Int => {
2037 assert(lhs_ty.eql(rhs_ty, mod));2034 assert(lhs_ty.eql(rhs_ty, zcu));
2038 const int_info = lhs_ty.intInfo(mod);2035 const int_info = lhs_ty.intInfo(zcu);
2039 switch (int_info.bits) {2036 switch (int_info.bits) {
2040 1...32 => {2037 1...32 => {
2041 try self.spillConditionFlagsIfOccupied();2038 try self.spillConditionFlagsIfOccupied();
...@@ -2089,7 +2086,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2089,7 +2086,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2089fn airNot(self: *Self, inst: Air.Inst.Index) !void {2086fn airNot(self: *Self, inst: Air.Inst.Index) !void {
2090 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2087 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2091 const pt = self.pt;2088 const pt = self.pt;
2092 const mod = pt.zcu;2089 const zcu = pt.zcu;
2093 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2090 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2094 const operand = try self.resolveInst(ty_op.operand);2091 const operand = try self.resolveInst(ty_op.operand);
2095 const operand_ty = self.typeOf(ty_op.operand);2092 const operand_ty = self.typeOf(ty_op.operand);
...@@ -2105,7 +2102,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {...@@ -2105,7 +2102,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
2105 };2102 };
2106 },2103 },
2107 else => {2104 else => {
2108 switch (operand_ty.zigTypeTag(mod)) {2105 switch (operand_ty.zigTypeTag(zcu)) {
2109 .Bool => {2106 .Bool => {
2110 const op_reg = switch (operand) {2107 const op_reg = switch (operand) {
2111 .register => |r| r,2108 .register => |r| r,
...@@ -2139,7 +2136,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {...@@ -2139,7 +2136,7 @@ fn airNot(self: *Self, inst: Air.Inst.Index) !void {
2139 },2136 },
2140 .Vector => return self.fail("TODO bitwise not for vectors", .{}),2137 .Vector => return self.fail("TODO bitwise not for vectors", .{}),
2141 .Int => {2138 .Int => {
2142 const int_info = operand_ty.intInfo(mod);2139 const int_info = operand_ty.intInfo(zcu);
2143 if (int_info.bits <= 64) {2140 if (int_info.bits <= 64) {
2144 const op_reg = switch (operand) {2141 const op_reg = switch (operand) {
2145 .register => |r| r,2142 .register => |r| r,
...@@ -2322,17 +2319,17 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -2322,17 +2319,17 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
2322 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;2319 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
2323 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;2320 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
2324 const pt = self.pt;2321 const pt = self.pt;
2325 const mod = pt.zcu;2322 const zcu = pt.zcu;
2326 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2323 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2327 const lhs = try self.resolveInst(extra.lhs);2324 const lhs = try self.resolveInst(extra.lhs);
2328 const rhs = try self.resolveInst(extra.rhs);2325 const rhs = try self.resolveInst(extra.rhs);
2329 const lhs_ty = self.typeOf(extra.lhs);2326 const lhs_ty = self.typeOf(extra.lhs);
2330 const rhs_ty = self.typeOf(extra.rhs);2327 const rhs_ty = self.typeOf(extra.rhs);
23312328
2332 switch (lhs_ty.zigTypeTag(mod)) {2329 switch (lhs_ty.zigTypeTag(zcu)) {
2333 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),2330 .Vector => return self.fail("TODO implement mul_with_overflow for vectors", .{}),
2334 .Int => {2331 .Int => {
2335 const int_info = lhs_ty.intInfo(mod);2332 const int_info = lhs_ty.intInfo(zcu);
2336 if (int_info.bits <= 64) {2333 if (int_info.bits <= 64) {
2337 try self.spillConditionFlagsIfOccupied();2334 try self.spillConditionFlagsIfOccupied();
23382335
...@@ -2428,7 +2425,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -2428,7 +2425,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
24282425
2429fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {2426fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2430 const pt = self.pt;2427 const pt = self.pt;
2431 const mod = pt.zcu;2428 const zcu = pt.zcu;
2432 const is_volatile = false; // TODO2429 const is_volatile = false; // TODO
2433 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2430 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 {...@@ -2438,10 +2435,10 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2438 const index_mcv = try self.resolveInst(bin_op.rhs);2435 const index_mcv = try self.resolveInst(bin_op.rhs);
24392436
2440 const slice_ty = self.typeOf(bin_op.lhs);2437 const slice_ty = self.typeOf(bin_op.lhs);
2441 const elem_ty = slice_ty.childType(mod);2438 const elem_ty = slice_ty.childType(zcu);
2442 const elem_size = elem_ty.abiSize(pt);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
2446 const index_lock: ?RegisterLock = if (index_mcv == .register)2443 const index_lock: ?RegisterLock = if (index_mcv == .register)
2447 self.register_manager.lockRegAssumeUnused(index_mcv.register)2444 self.register_manager.lockRegAssumeUnused(index_mcv.register)
...@@ -2553,10 +2550,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -2553,10 +2550,10 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
2553 const operand = extra.struct_operand;2550 const operand = extra.struct_operand;
2554 const index = extra.field_index;2551 const index = extra.field_index;
2555 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2552 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2556 const pt = self.pt;2553 const zcu = self.pt.zcu;
2557 const mcv = try self.resolveInst(operand);2554 const mcv = try self.resolveInst(operand);
2558 const struct_ty = self.typeOf(operand);2555 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
2561 switch (mcv) {2558 switch (mcv) {
2562 .dead, .unreach => unreachable,2559 .dead, .unreach => unreachable,
...@@ -2687,13 +2684,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -2687,13 +2684,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
26872684
2688fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {2685fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
2689 const pt = self.pt;2686 const pt = self.pt;
2690 const mod = pt.zcu;2687 const zcu = pt.zcu;
2691 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2688 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2692 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2689 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2693 const error_union_ty = self.typeOf(ty_op.operand);2690 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);
2695 const mcv = try self.resolveInst(ty_op.operand);2692 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
2698 return self.fail("TODO implement unwrap error union error for non-empty payloads", .{});2695 return self.fail("TODO implement unwrap error union error for non-empty payloads", .{});
2699 };2696 };
...@@ -2702,12 +2699,12 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {...@@ -2702,12 +2699,12 @@ fn airUnwrapErrErr(self: *Self, inst: Air.Inst.Index) !void {
27022699
2703fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {2700fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
2704 const pt = self.pt;2701 const pt = self.pt;
2705 const mod = pt.zcu;2702 const zcu = pt.zcu;
2706 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2703 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2707 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2704 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2708 const error_union_ty = self.typeOf(ty_op.operand);2705 const error_union_ty = self.typeOf(ty_op.operand);
2709 const payload_ty = error_union_ty.errorUnionPayload(mod);2706 const payload_ty = error_union_ty.errorUnionPayload(zcu);
2710 if (!payload_ty.hasRuntimeBits(pt)) break :result MCValue.none;2707 if (!payload_ty.hasRuntimeBits(zcu)) break :result MCValue.none;
27112708
2712 return self.fail("TODO implement unwrap error union payload for non-empty payloads", .{});2709 return self.fail("TODO implement unwrap error union payload for non-empty payloads", .{});
2713 };2710 };
...@@ -2717,13 +2714,13 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -2717,13 +2714,13 @@ fn airUnwrapErrPayload(self: *Self, inst: Air.Inst.Index) !void {
2717/// E to E!T2714/// E to E!T
2718fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {2715fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
2719 const pt = self.pt;2716 const pt = self.pt;
2720 const mod = pt.zcu;2717 const zcu = pt.zcu;
2721 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2718 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2722 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {2719 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
2723 const error_union_ty = ty_op.ty.toType();2720 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);
2725 const mcv = try self.resolveInst(ty_op.operand);2722 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
2728 return self.fail("TODO implement wrap errunion error for non-empty payloads", .{});2725 return self.fail("TODO implement wrap errunion error for non-empty payloads", .{});
2729 };2726 };
...@@ -2744,7 +2741,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -2744,7 +2741,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
2744 const optional_ty = self.typeOfIndex(inst);2741 const optional_ty = self.typeOfIndex(inst);
27452742
2746 // Optional with a zero-bit payload type is just a boolean true2743 // 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)
2748 break :result MCValue{ .immediate = 1 };2745 break :result MCValue{ .immediate = 1 };
27492746
2750 return self.fail("TODO implement wrap optional for {}", .{self.target.cpu.arch});2747 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...@@ -2779,10 +2776,10 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: Alignme
2779/// Use a pointer instruction as the basis for allocating stack memory.2776/// Use a pointer instruction as the basis for allocating stack memory.
2780fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {2777fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
2781 const pt = self.pt;2778 const pt = self.pt;
2782 const mod = pt.zcu;2779 const zcu = pt.zcu;
2783 const elem_ty = self.typeOfIndex(inst).childType(mod);2780 const elem_ty = self.typeOfIndex(inst).childType(zcu);
27842781
2785 if (!elem_ty.hasRuntimeBits(pt)) {2782 if (!elem_ty.hasRuntimeBits(zcu)) {
2786 // As this stack item will never be dereferenced at runtime,2783 // As this stack item will never be dereferenced at runtime,
2787 // return the stack offset 0. Stack offset 0 will be where all2784 // return the stack offset 0. Stack offset 0 will be where all
2788 // zero-sized stack allocations live as non-zero-sized2785 // zero-sized stack allocations live as non-zero-sized
...@@ -2790,21 +2787,22 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {...@@ -2790,21 +2787,22 @@ fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
2790 return @as(u32, 0);2787 return @as(u32, 0);
2791 }2788 }
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 {
2794 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});2791 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
2795 };2792 };
2796 // TODO swap this for inst.ty.ptrAlign2793 // TODO swap this for inst.ty.ptrAlign
2797 const abi_align = elem_ty.abiAlignment(pt);2794 const abi_align = elem_ty.abiAlignment(zcu);
2798 return self.allocMem(inst, abi_size, abi_align);2795 return self.allocMem(inst, abi_size, abi_align);
2799}2796}
28002797
2801fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {2798fn allocRegOrMem(self: *Self, inst: Air.Inst.Index, reg_ok: bool) !MCValue {
2802 const pt = self.pt;2799 const pt = self.pt;
2800 const zcu = pt.zcu;
2803 const elem_ty = self.typeOfIndex(inst);2801 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 {
2805 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});2803 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(pt)});
2806 };2804 };
2807 const abi_align = elem_ty.abiAlignment(pt);2805 const abi_align = elem_ty.abiAlignment(zcu);
2808 self.stack_align = self.stack_align.max(abi_align);2806 self.stack_align = self.stack_align.max(abi_align);
28092807
2810 if (reg_ok) {2808 if (reg_ok) {
...@@ -2847,7 +2845,7 @@ fn binOp(...@@ -2847,7 +2845,7 @@ fn binOp(
2847 metadata: ?BinOpMetadata,2845 metadata: ?BinOpMetadata,
2848) InnerError!MCValue {2846) InnerError!MCValue {
2849 const pt = self.pt;2847 const pt = self.pt;
2850 const mod = pt.zcu;2848 const zcu = pt.zcu;
2851 switch (tag) {2849 switch (tag) {
2852 .add,2850 .add,
2853 .sub,2851 .sub,
...@@ -2857,12 +2855,12 @@ fn binOp(...@@ -2857,12 +2855,12 @@ fn binOp(
2857 .xor,2855 .xor,
2858 .cmp_eq,2856 .cmp_eq,
2859 => {2857 => {
2860 switch (lhs_ty.zigTypeTag(mod)) {2858 switch (lhs_ty.zigTypeTag(zcu)) {
2861 .Float => return self.fail("TODO binary operations on floats", .{}),2859 .Float => return self.fail("TODO binary operations on floats", .{}),
2862 .Vector => return self.fail("TODO binary operations on vectors", .{}),2860 .Vector => return self.fail("TODO binary operations on vectors", .{}),
2863 .Int => {2861 .Int => {
2864 assert(lhs_ty.eql(rhs_ty, mod));2862 assert(lhs_ty.eql(rhs_ty, zcu));
2865 const int_info = lhs_ty.intInfo(mod);2863 const int_info = lhs_ty.intInfo(zcu);
2866 if (int_info.bits <= 64) {2864 if (int_info.bits <= 64) {
2867 // Only say yes if the operation is2865 // Only say yes if the operation is
2868 // commutative, i.e. we can swap both of the2866 // commutative, i.e. we can swap both of the
...@@ -2931,10 +2929,10 @@ fn binOp(...@@ -2931,10 +2929,10 @@ fn binOp(
2931 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);2929 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);
29322930
2933 // Truncate if necessary2931 // Truncate if necessary
2934 switch (lhs_ty.zigTypeTag(mod)) {2932 switch (lhs_ty.zigTypeTag(zcu)) {
2935 .Vector => return self.fail("TODO binary operations on vectors", .{}),2933 .Vector => return self.fail("TODO binary operations on vectors", .{}),
2936 .Int => {2934 .Int => {
2937 const int_info = lhs_ty.intInfo(mod);2935 const int_info = lhs_ty.intInfo(zcu);
2938 if (int_info.bits <= 64) {2936 if (int_info.bits <= 64) {
2939 const result_reg = result.register;2937 const result_reg = result.register;
2940 try self.truncRegister(result_reg, result_reg, int_info.signedness, int_info.bits);2938 try self.truncRegister(result_reg, result_reg, int_info.signedness, int_info.bits);
...@@ -2948,11 +2946,11 @@ fn binOp(...@@ -2948,11 +2946,11 @@ fn binOp(
2948 },2946 },
29492947
2950 .div_trunc => {2948 .div_trunc => {
2951 switch (lhs_ty.zigTypeTag(mod)) {2949 switch (lhs_ty.zigTypeTag(zcu)) {
2952 .Vector => return self.fail("TODO binary operations on vectors", .{}),2950 .Vector => return self.fail("TODO binary operations on vectors", .{}),
2953 .Int => {2951 .Int => {
2954 assert(lhs_ty.eql(rhs_ty, mod));2952 assert(lhs_ty.eql(rhs_ty, zcu));
2955 const int_info = lhs_ty.intInfo(mod);2953 const int_info = lhs_ty.intInfo(zcu);
2956 if (int_info.bits <= 64) {2954 if (int_info.bits <= 64) {
2957 const rhs_immediate_ok = switch (tag) {2955 const rhs_immediate_ok = switch (tag) {
2958 .div_trunc => rhs == .immediate and rhs.immediate <= std.math.maxInt(u12),2956 .div_trunc => rhs == .immediate and rhs.immediate <= std.math.maxInt(u12),
...@@ -2981,14 +2979,14 @@ fn binOp(...@@ -2981,14 +2979,14 @@ fn binOp(
2981 },2979 },
29822980
2983 .ptr_add => {2981 .ptr_add => {
2984 switch (lhs_ty.zigTypeTag(mod)) {2982 switch (lhs_ty.zigTypeTag(zcu)) {
2985 .Pointer => {2983 .Pointer => {
2986 const ptr_ty = lhs_ty;2984 const ptr_ty = lhs_ty;
2987 const elem_ty = switch (ptr_ty.ptrSize(mod)) {2985 const elem_ty = switch (ptr_ty.ptrSize(zcu)) {
2988 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type2986 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
2989 else => ptr_ty.childType(mod),2987 else => ptr_ty.childType(zcu),
2990 };2988 };
2991 const elem_size = elem_ty.abiSize(pt);2989 const elem_size = elem_ty.abiSize(zcu);
29922990
2993 if (elem_size == 1) {2991 if (elem_size == 1) {
2994 const base_tag: Mir.Inst.Tag = switch (tag) {2992 const base_tag: Mir.Inst.Tag = switch (tag) {
...@@ -3013,7 +3011,7 @@ fn binOp(...@@ -3013,7 +3011,7 @@ fn binOp(
3013 .bool_and,3011 .bool_and,
3014 .bool_or,3012 .bool_or,
3015 => {3013 => {
3016 switch (lhs_ty.zigTypeTag(mod)) {3014 switch (lhs_ty.zigTypeTag(zcu)) {
3017 .Bool => {3015 .Bool => {
3018 assert(lhs != .immediate); // should have been handled by Sema3016 assert(lhs != .immediate); // should have been handled by Sema
3019 assert(rhs != .immediate); // should have been handled by Sema3017 assert(rhs != .immediate); // should have been handled by Sema
...@@ -3043,10 +3041,10 @@ fn binOp(...@@ -3043,10 +3041,10 @@ fn binOp(
3043 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);3041 const result = try self.binOp(base_tag, lhs, rhs, lhs_ty, rhs_ty, metadata);
30443042
3045 // Truncate if necessary3043 // Truncate if necessary
3046 switch (lhs_ty.zigTypeTag(mod)) {3044 switch (lhs_ty.zigTypeTag(zcu)) {
3047 .Vector => return self.fail("TODO binary operations on vectors", .{}),3045 .Vector => return self.fail("TODO binary operations on vectors", .{}),
3048 .Int => {3046 .Int => {
3049 const int_info = lhs_ty.intInfo(mod);3047 const int_info = lhs_ty.intInfo(zcu);
3050 if (int_info.bits <= 64) {3048 if (int_info.bits <= 64) {
3051 // 32 and 64 bit operands doesn't need truncating3049 // 32 and 64 bit operands doesn't need truncating
3052 if (int_info.bits == 32 or int_info.bits == 64) return result;3050 if (int_info.bits == 32 or int_info.bits == 64) return result;
...@@ -3065,10 +3063,10 @@ fn binOp(...@@ -3065,10 +3063,10 @@ fn binOp(
3065 .shl_exact,3063 .shl_exact,
3066 .shr_exact,3064 .shr_exact,
3067 => {3065 => {
3068 switch (lhs_ty.zigTypeTag(mod)) {3066 switch (lhs_ty.zigTypeTag(zcu)) {
3069 .Vector => return self.fail("TODO binary operations on vectors", .{}),3067 .Vector => return self.fail("TODO binary operations on vectors", .{}),
3070 .Int => {3068 .Int => {
3071 const int_info = lhs_ty.intInfo(mod);3069 const int_info = lhs_ty.intInfo(zcu);
3072 if (int_info.bits <= 64) {3070 if (int_info.bits <= 64) {
3073 const rhs_immediate_ok = rhs == .immediate;3071 const rhs_immediate_ok = rhs == .immediate;
30743072
...@@ -3388,8 +3386,8 @@ fn binOpRegister(...@@ -3388,8 +3386,8 @@ fn binOpRegister(
3388fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {3386fn br(self: *Self, block: Air.Inst.Index, operand: Air.Inst.Ref) !void {
3389 const block_data = self.blocks.getPtr(block).?;3387 const block_data = self.blocks.getPtr(block).?;
33903388
3391 const pt = self.pt;3389 const zcu = self.pt.zcu;
3392 if (self.typeOf(operand).hasRuntimeBits(pt)) {3390 if (self.typeOf(operand).hasRuntimeBits(zcu)) {
3393 const operand_mcv = try self.resolveInst(operand);3391 const operand_mcv = try self.resolveInst(operand);
3394 const block_mcv = block_data.mcv;3392 const block_mcv = block_data.mcv;
3395 if (block_mcv == .none) {3393 if (block_mcv == .none) {
...@@ -3509,17 +3507,17 @@ fn ensureProcessDeathCapacity(self: *Self, additional_count: usize) !void {...@@ -3509,17 +3507,17 @@ fn ensureProcessDeathCapacity(self: *Self, additional_count: usize) !void {
3509/// Given an error union, returns the payload3507/// Given an error union, returns the payload
3510fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) !MCValue {3508fn errUnionPayload(self: *Self, error_union_mcv: MCValue, error_union_ty: Type) !MCValue {
3511 const pt = self.pt;3509 const pt = self.pt;
3512 const mod = pt.zcu;3510 const zcu = pt.zcu;
3513 const err_ty = error_union_ty.errorUnionSet(mod);3511 const err_ty = error_union_ty.errorUnionSet(zcu);
3514 const payload_ty = error_union_ty.errorUnionPayload(mod);3512 const payload_ty = error_union_ty.errorUnionPayload(zcu);
3515 if (err_ty.errorSetIsEmpty(mod)) {3513 if (err_ty.errorSetIsEmpty(zcu)) {
3516 return error_union_mcv;3514 return error_union_mcv;
3517 }3515 }
3518 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {3516 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3519 return MCValue.none;3517 return MCValue.none;
3520 }3518 }
35213519
3522 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt)));3520 const payload_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu)));
3523 switch (error_union_mcv) {3521 switch (error_union_mcv) {
3524 .register => return self.fail("TODO errUnionPayload for registers", .{}),3522 .register => return self.fail("TODO errUnionPayload for registers", .{}),
3525 .stack_offset => |off| {3523 .stack_offset => |off| {
...@@ -3731,6 +3729,7 @@ fn genLoadASI(self: *Self, value_reg: Register, addr_reg: Register, off_reg: Reg...@@ -3731,6 +3729,7 @@ fn genLoadASI(self: *Self, value_reg: Register, addr_reg: Register, off_reg: Reg
37313729
3732fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {3730fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void {
3733 const pt = self.pt;3731 const pt = self.pt;
3732 const zcu = pt.zcu;
3734 switch (mcv) {3733 switch (mcv) {
3735 .dead => unreachable,3734 .dead => unreachable,
3736 .unreach, .none => return, // Nothing to do.3735 .unreach, .none => return, // Nothing to do.
...@@ -3929,21 +3928,21 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void...@@ -3929,21 +3928,21 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
3929 // The value is in memory at a hard-coded address.3928 // The value is in memory at a hard-coded address.
3930 // If the type is a pointer, it means the pointer address is at this memory location.3929 // If the type is a pointer, it means the pointer address is at this memory location.
3931 try self.genSetReg(ty, reg, .{ .immediate = addr });3930 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));
3933 },3932 },
3934 .stack_offset => |off| {3933 .stack_offset => |off| {
3935 const real_offset = realStackOffset(off);3934 const real_offset = realStackOffset(off);
3936 const simm13 = math.cast(i13, real_offset) orelse3935 const simm13 = math.cast(i13, real_offset) orelse
3937 return self.fail("TODO larger stack offsets: {}", .{real_offset});3936 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));
3939 },3938 },
3940 }3939 }
3941}3940}
39423941
3943fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {3942fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerError!void {
3944 const pt = self.pt;3943 const pt = self.pt;
3945 const mod = pt.zcu;3944 const zcu = pt.zcu;
3946 const abi_size = ty.abiSize(pt);3945 const abi_size = ty.abiSize(zcu);
3947 switch (mcv) {3946 switch (mcv) {
3948 .dead => unreachable,3947 .dead => unreachable,
3949 .unreach, .none => return, // Nothing to do.3948 .unreach, .none => return, // Nothing to do.
...@@ -3951,7 +3950,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro...@@ -3951,7 +3950,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
3951 if (!self.wantSafety())3950 if (!self.wantSafety())
3952 return; // The already existing value will do just fine.3951 return; // The already existing value will do just fine.
3953 // TODO Upgrade this to a memset call when we have that available.3952 // TODO Upgrade this to a memset call when we have that available.
3954 switch (ty.abiSize(pt)) {3953 switch (ty.abiSize(zcu)) {
3955 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),3954 1 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaa }),
3956 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),3955 2 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaa }),
3957 4 => return self.genSetStack(ty, stack_offset, .{ .immediate = 0xaaaaaaaa }),3956 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...@@ -3977,11 +3976,11 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
3977 const reg_lock = self.register_manager.lockReg(rwo.reg);3976 const reg_lock = self.register_manager.lockReg(rwo.reg);
3978 defer if (reg_lock) |locked_reg| self.register_manager.unlockReg(locked_reg);3977 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);
3981 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });3980 try self.genSetStack(wrapped_ty, stack_offset, .{ .register = rwo.reg });
39823981
3983 const overflow_bit_ty = ty.structFieldType(1, mod);3982 const overflow_bit_ty = ty.fieldType(1, zcu);
3984 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, pt)));3983 const overflow_bit_offset = @as(u32, @intCast(ty.structFieldOffset(1, zcu)));
3985 const cond_reg = try self.register_manager.allocReg(null, gp);3984 const cond_reg = try self.register_manager.allocReg(null, gp);
39863985
3987 // TODO handle floating point CCRs3986 // TODO handle floating point CCRs
...@@ -4154,14 +4153,14 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue {...@@ -4154,14 +4153,14 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue {
41544153
4155fn isErr(self: *Self, ty: Type, operand: MCValue) !MCValue {4154fn isErr(self: *Self, ty: Type, operand: MCValue) !MCValue {
4156 const pt = self.pt;4155 const pt = self.pt;
4157 const mod = pt.zcu;4156 const zcu = pt.zcu;
4158 const error_type = ty.errorUnionSet(mod);4157 const error_type = ty.errorUnionSet(zcu);
4159 const payload_type = ty.errorUnionPayload(mod);4158 const payload_type = ty.errorUnionPayload(zcu);
41604159
4161 if (!error_type.hasRuntimeBits(pt)) {4160 if (!error_type.hasRuntimeBits(zcu)) {
4162 return MCValue{ .immediate = 0 }; // always false4161 return MCValue{ .immediate = 0 }; // always false
4163 } else if (!payload_type.hasRuntimeBits(pt)) {4162 } else if (!payload_type.hasRuntimeBits(zcu)) {
4164 if (error_type.abiSize(pt) <= 8) {4163 if (error_type.abiSize(zcu) <= 8) {
4165 const reg_mcv: MCValue = switch (operand) {4164 const reg_mcv: MCValue = switch (operand) {
4166 .register => operand,4165 .register => operand,
4167 else => .{ .register = try self.copyToTmpRegister(error_type, operand) },4166 else => .{ .register = try self.copyToTmpRegister(error_type, operand) },
...@@ -4253,9 +4252,9 @@ fn jump(self: *Self, inst: Mir.Inst.Index) !void {...@@ -4253,9 +4252,9 @@ fn jump(self: *Self, inst: Mir.Inst.Index) !void {
42534252
4254fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {4253fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
4255 const pt = self.pt;4254 const pt = self.pt;
4256 const mod = pt.zcu;4255 const zcu = pt.zcu;
4257 const elem_ty = ptr_ty.childType(mod);4256 const elem_ty = ptr_ty.childType(zcu);
4258 const elem_size = elem_ty.abiSize(pt);4257 const elem_size = elem_ty.abiSize(zcu);
42594258
4260 switch (ptr) {4259 switch (ptr) {
4261 .none => unreachable,4260 .none => unreachable,
...@@ -4325,13 +4324,13 @@ fn minMax(...@@ -4325,13 +4324,13 @@ fn minMax(
4325 rhs_ty: Type,4324 rhs_ty: Type,
4326) InnerError!MCValue {4325) InnerError!MCValue {
4327 const pt = self.pt;4326 const pt = self.pt;
4328 const mod = pt.zcu;4327 const zcu = pt.zcu;
4329 assert(lhs_ty.eql(rhs_ty, mod));4328 assert(lhs_ty.eql(rhs_ty, zcu));
4330 switch (lhs_ty.zigTypeTag(mod)) {4329 switch (lhs_ty.zigTypeTag(zcu)) {
4331 .Float => return self.fail("TODO min/max on floats", .{}),4330 .Float => return self.fail("TODO min/max on floats", .{}),
4332 .Vector => return self.fail("TODO min/max on vectors", .{}),4331 .Vector => return self.fail("TODO min/max on vectors", .{}),
4333 .Int => {4332 .Int => {
4334 const int_info = lhs_ty.intInfo(mod);4333 const int_info = lhs_ty.intInfo(zcu);
4335 if (int_info.bits <= 64) {4334 if (int_info.bits <= 64) {
4336 // TODO skip register setting when one of the operands4335 // TODO skip register setting when one of the operands
4337 // is a small (fits in i13) immediate.4336 // is a small (fits in i13) immediate.
...@@ -4446,9 +4445,9 @@ fn realStackOffset(off: u32) u32 {...@@ -4446,9 +4445,9 @@ fn realStackOffset(off: u32) u32 {
4446/// Caller must call `CallMCValues.deinit`.4445/// Caller must call `CallMCValues.deinit`.
4447fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) !CallMCValues {4446fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView) !CallMCValues {
4448 const pt = self.pt;4447 const pt = self.pt;
4449 const mod = pt.zcu;4448 const zcu = pt.zcu;
4450 const ip = &mod.intern_pool;4449 const ip = &zcu.intern_pool;
4451 const fn_info = mod.typeToFunc(fn_ty).?;4450 const fn_info = zcu.typeToFunc(fn_ty).?;
4452 const cc = fn_info.cc;4451 const cc = fn_info.cc;
4453 var result: CallMCValues = .{4452 var result: CallMCValues = .{
4454 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),4453 .args = try self.gpa.alloc(MCValue, fn_info.param_types.len),
...@@ -4459,7 +4458,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)...@@ -4459,7 +4458,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
4459 };4458 };
4460 errdefer self.gpa.free(result.args);4459 errdefer self.gpa.free(result.args);
44614460
4462 const ret_ty = fn_ty.fnReturnType(mod);4461 const ret_ty = fn_ty.fnReturnType(zcu);
44634462
4464 switch (cc) {4463 switch (cc) {
4465 .Naked => {4464 .Naked => {
...@@ -4487,7 +4486,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)...@@ -4487,7 +4486,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
4487 };4486 };
44884487
4489 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {4488 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)));
4491 if (param_size <= 8) {4490 if (param_size <= 8) {
4492 if (next_register < argument_registers.len) {4491 if (next_register < argument_registers.len) {
4493 result_arg.* = .{ .register = argument_registers[next_register] };4492 result_arg.* = .{ .register = argument_registers[next_register] };
...@@ -4514,12 +4513,12 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)...@@ -4514,12 +4513,12 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
4514 result.stack_byte_count = next_stack_offset;4513 result.stack_byte_count = next_stack_offset;
4515 result.stack_align = .@"16";4514 result.stack_align = .@"16";
45164515
4517 if (ret_ty.zigTypeTag(mod) == .NoReturn) {4516 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
4518 result.return_value = .{ .unreach = {} };4517 result.return_value = .{ .unreach = {} };
4519 } else if (!ret_ty.hasRuntimeBits(pt)) {4518 } else if (!ret_ty.hasRuntimeBits(zcu)) {
4520 result.return_value = .{ .none = {} };4519 result.return_value = .{ .none = {} };
4521 } else {4520 } else {
4522 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(pt));4521 const ret_ty_size: u32 = @intCast(ret_ty.abiSize(zcu));
4523 // The callee puts the return values in %i0-%i3, which becomes %o0-%o3 inside the caller.4522 // The callee puts the return values in %i0-%i3, which becomes %o0-%o3 inside the caller.
4524 if (ret_ty_size <= 8) {4523 if (ret_ty_size <= 8) {
4525 result.return_value = switch (role) {4524 result.return_value = switch (role) {
...@@ -4542,7 +4541,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -4542,7 +4541,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
4542 const ty = self.typeOf(ref);4541 const ty = self.typeOf(ref);
45434542
4544 // If the type has no codegen bits, no need to store it.4543 // 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
4547 if (ref.toIndex()) |inst| {4546 if (ref.toIndex()) |inst| {
4548 return self.getResolvedInstValue(inst);4547 return self.getResolvedInstValue(inst);
...@@ -4553,8 +4552,8 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -4553,8 +4552,8 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45534552
4554fn ret(self: *Self, mcv: MCValue) !void {4553fn ret(self: *Self, mcv: MCValue) !void {
4555 const pt = self.pt;4554 const pt = self.pt;
4556 const mod = pt.zcu;4555 const zcu = pt.zcu;
4557 const ret_ty = self.fn_type.fnReturnType(mod);4556 const ret_ty = self.fn_type.fnReturnType(zcu);
4558 try self.setRegOrMem(ret_ty, self.ret_mcv, mcv);4557 try self.setRegOrMem(ret_ty, self.ret_mcv, mcv);
45594558
4560 // Just add space for a branch instruction, patch this later4559 // 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...@@ -4656,7 +4655,7 @@ pub fn spillInstruction(self: *Self, reg: Register, inst: Air.Inst.Index) !void
46564655
4657fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {4656fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type) InnerError!void {
4658 const pt = self.pt;4657 const pt = self.pt;
4659 const abi_size = value_ty.abiSize(pt);4658 const abi_size = value_ty.abiSize(pt.zcu);
46604659
4661 switch (ptr) {4660 switch (ptr) {
4662 .none => unreachable,4661 .none => unreachable,
...@@ -4698,11 +4697,11 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type...@@ -4698,11 +4697,11 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
4698fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {4697fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
4699 return if (self.liveness.isUnused(inst)) .dead else result: {4698 return if (self.liveness.isUnused(inst)) .dead else result: {
4700 const pt = self.pt;4699 const pt = self.pt;
4701 const mod = pt.zcu;4700 const zcu = pt.zcu;
4702 const mcv = try self.resolveInst(operand);4701 const mcv = try self.resolveInst(operand);
4703 const ptr_ty = self.typeOf(operand);4702 const ptr_ty = self.typeOf(operand);
4704 const struct_ty = ptr_ty.childType(mod);4703 const struct_ty = ptr_ty.childType(zcu);
4705 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, pt)));4704 const struct_field_offset = @as(u32, @intCast(struct_ty.structFieldOffset(index, zcu)));
4706 switch (mcv) {4705 switch (mcv) {
4707 .ptr_stack_offset => |off| {4706 .ptr_stack_offset => |off| {
4708 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };4707 break :result MCValue{ .ptr_stack_offset = off - struct_field_offset };
...@@ -4741,9 +4740,9 @@ fn trunc(...@@ -4741,9 +4740,9 @@ fn trunc(
4741 dest_ty: Type,4740 dest_ty: Type,
4742) !MCValue {4741) !MCValue {
4743 const pt = self.pt;4742 const pt = self.pt;
4744 const mod = pt.zcu;4743 const zcu = pt.zcu;
4745 const info_a = operand_ty.intInfo(mod);4744 const info_a = operand_ty.intInfo(zcu);
4746 const info_b = dest_ty.intInfo(mod);4745 const info_b = dest_ty.intInfo(zcu);
47474746
4748 if (info_b.bits <= 64) {4747 if (info_b.bits <= 64) {
4749 const operand_reg = switch (operand) {4748 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 {...@@ -788,10 +788,10 @@ fn resolveInst(func: *CodeGen, ref: Air.Inst.Ref) InnerError!WValue {
788 assert(!gop.found_existing);788 assert(!gop.found_existing);
789789
790 const pt = func.pt;790 const pt = func.pt;
791 const mod = pt.zcu;791 const zcu = pt.zcu;
792 const val = (try func.air.value(ref, pt)).?;792 const val = (try func.air.value(ref, pt)).?;
793 const ty = func.typeOf(ref);793 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)) {
795 gop.value_ptr.* = .none;795 gop.value_ptr.* = .none;
796 return gop.value_ptr.*;796 return gop.value_ptr.*;
797 }797 }
...@@ -1001,9 +1001,9 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32...@@ -1001,9 +1001,9 @@ fn addExtraAssumeCapacity(func: *CodeGen, extra: anytype) error{OutOfMemory}!u32
10011001
1002/// Using a given `Type`, returns the corresponding valtype for .auto callconv1002/// Using a given `Type`, returns the corresponding valtype for .auto callconv
1003fn typeToValtype(ty: Type, pt: Zcu.PerThread, target: std.Target) wasm.Valtype {1003fn typeToValtype(ty: Type, pt: Zcu.PerThread, target: std.Target) wasm.Valtype {
1004 const mod = pt.zcu;1004 const zcu = pt.zcu;
1005 const ip = &mod.intern_pool;1005 const ip = &zcu.intern_pool;
1006 return switch (ty.zigTypeTag(mod)) {1006 return switch (ty.zigTypeTag(zcu)) {
1007 .Float => switch (ty.floatBits(target)) {1007 .Float => switch (ty.floatBits(target)) {
1008 16 => .i32, // stored/loaded as u161008 16 => .i32, // stored/loaded as u16
1009 32 => .f32,1009 32 => .f32,
...@@ -1011,26 +1011,26 @@ fn typeToValtype(ty: Type, pt: Zcu.PerThread, target: std.Target) wasm.Valtype {...@@ -1011,26 +1011,26 @@ fn typeToValtype(ty: Type, pt: Zcu.PerThread, target: std.Target) wasm.Valtype {
1011 80, 128 => .i32,1011 80, 128 => .i32,
1012 else => unreachable,1012 else => unreachable,
1013 },1013 },
1014 .Int, .Enum => switch (ty.intInfo(pt.zcu).bits) {1014 .Int, .Enum => switch (ty.intInfo(zcu).bits) {
1015 0...32 => .i32,1015 0...32 => .i32,
1016 33...64 => .i64,1016 33...64 => .i64,
1017 else => .i32,1017 else => .i32,
1018 },1018 },
1019 .Struct => blk: {1019 .Struct => blk: {
1020 if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| {1020 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
1021 const backing_int_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));1021 const backing_int_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
1022 break :blk typeToValtype(backing_int_ty, pt, target);1022 break :blk typeToValtype(backing_int_ty, pt, target);
1023 } else {1023 } else {
1024 break :blk .i32;1024 break :blk .i32;
1025 }1025 }
1026 },1026 },
1027 .Vector => switch (determineSimdStoreStrategy(ty, pt, target)) {1027 .Vector => switch (determineSimdStoreStrategy(ty, zcu, target)) {
1028 .direct => .v128,1028 .direct => .v128,
1029 .unrolled => .i32,1029 .unrolled => .i32,
1030 },1030 },
1031 .Union => switch (ty.containerLayout(pt.zcu)) {1031 .Union => switch (ty.containerLayout(zcu)) {
1032 .@"packed" => blk: {1032 .@"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");
1034 break :blk typeToValtype(int_ty, pt, target);1034 break :blk typeToValtype(int_ty, pt, target);
1035 },1035 },
1036 else => .i32,1036 else => .i32,
...@@ -1148,7 +1148,7 @@ fn genFunctype(...@@ -1148,7 +1148,7 @@ fn genFunctype(
1148 pt: Zcu.PerThread,1148 pt: Zcu.PerThread,
1149 target: std.Target,1149 target: std.Target,
1150) !wasm.Type {1150) !wasm.Type {
1151 const mod = pt.zcu;1151 const zcu = pt.zcu;
1152 var temp_params = std.ArrayList(wasm.Valtype).init(gpa);1152 var temp_params = std.ArrayList(wasm.Valtype).init(gpa);
1153 defer temp_params.deinit();1153 defer temp_params.deinit();
1154 var returns = std.ArrayList(wasm.Valtype).init(gpa);1154 var returns = std.ArrayList(wasm.Valtype).init(gpa);
...@@ -1156,30 +1156,30 @@ fn genFunctype(...@@ -1156,30 +1156,30 @@ fn genFunctype(
11561156
1157 if (firstParamSRet(cc, return_type, pt, target)) {1157 if (firstParamSRet(cc, return_type, pt, target)) {
1158 try temp_params.append(.i32); // memory address is always a 32-bit handle1158 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)) {
1160 if (cc == .C) {1160 if (cc == .C) {
1161 const res_classes = abi.classifyType(return_type, pt);1161 const res_classes = abi.classifyType(return_type, zcu);
1162 assert(res_classes[0] == .direct and res_classes[1] == .none);1162 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);
1164 try returns.append(typeToValtype(scalar_type, pt, target));1164 try returns.append(typeToValtype(scalar_type, pt, target));
1165 } else {1165 } else {
1166 try returns.append(typeToValtype(return_type, pt, target));1166 try returns.append(typeToValtype(return_type, pt, target));
1167 }1167 }
1168 } else if (return_type.isError(mod)) {1168 } else if (return_type.isError(zcu)) {
1169 try returns.append(.i32);1169 try returns.append(.i32);
1170 }1170 }
11711171
1172 // param types1172 // param types
1173 for (params) |param_type_ip| {1173 for (params) |param_type_ip| {
1174 const param_type = Type.fromInterned(param_type_ip);1174 const param_type = Type.fromInterned(param_type_ip);
1175 if (!param_type.hasRuntimeBitsIgnoreComptime(pt)) continue;1175 if (!param_type.hasRuntimeBitsIgnoreComptime(zcu)) continue;
11761176
1177 switch (cc) {1177 switch (cc) {
1178 .C => {1178 .C => {
1179 const param_classes = abi.classifyType(param_type, pt);1179 const param_classes = abi.classifyType(param_type, zcu);
1180 if (param_classes[1] == .none) {1180 if (param_classes[1] == .none) {
1181 if (param_classes[0] == .direct) {1181 if (param_classes[0] == .direct) {
1182 const scalar_type = abi.scalarType(param_type, pt);1182 const scalar_type = abi.scalarType(param_type, zcu);
1183 try temp_params.append(typeToValtype(scalar_type, pt, target));1183 try temp_params.append(typeToValtype(scalar_type, pt, target));
1184 } else {1184 } else {
1185 try temp_params.append(typeToValtype(param_type, pt, target));1185 try temp_params.append(typeToValtype(param_type, pt, target));
...@@ -1242,10 +1242,10 @@ pub fn generate(...@@ -1242,10 +1242,10 @@ pub fn generate(
12421242
1243fn genFunc(func: *CodeGen) InnerError!void {1243fn genFunc(func: *CodeGen) InnerError!void {
1244 const pt = func.pt;1244 const pt = func.pt;
1245 const mod = pt.zcu;1245 const zcu = pt.zcu;
1246 const ip = &mod.intern_pool;1246 const ip = &zcu.intern_pool;
1247 const fn_ty = mod.navValue(func.owner_nav).typeOf(mod);1247 const fn_ty = zcu.navValue(func.owner_nav).typeOf(zcu);
1248 const fn_info = mod.typeToFunc(fn_ty).?;1248 const fn_info = zcu.typeToFunc(fn_ty).?;
1249 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.*);1249 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.*);
1250 defer func_type.deinit(func.gpa);1250 defer func_type.deinit(func.gpa);
1251 _ = try func.bin_file.storeNavType(func.owner_nav, func_type);1251 _ = try func.bin_file.storeNavType(func.owner_nav, func_type);
...@@ -1273,7 +1273,7 @@ fn genFunc(func: *CodeGen) InnerError!void {...@@ -1273,7 +1273,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
1273 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {1273 if (func_type.returns.len != 0 and func.air.instructions.len > 0) {
1274 const inst: Air.Inst.Index = @enumFromInt(func.air.instructions.len - 1);1274 const inst: Air.Inst.Index = @enumFromInt(func.air.instructions.len - 1);
1275 const last_inst_ty = func.typeOfIndex(inst);1275 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)) {
1277 try func.addTag(.@"unreachable");1277 try func.addTag(.@"unreachable");
1278 }1278 }
1279 }1279 }
...@@ -1356,9 +1356,9 @@ const CallWValues = struct {...@@ -1356,9 +1356,9 @@ const CallWValues = struct {
13561356
1357fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWValues {1357fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWValues {
1358 const pt = func.pt;1358 const pt = func.pt;
1359 const mod = pt.zcu;1359 const zcu = pt.zcu;
1360 const ip = &mod.intern_pool;1360 const ip = &zcu.intern_pool;
1361 const fn_info = mod.typeToFunc(fn_ty).?;1361 const fn_info = zcu.typeToFunc(fn_ty).?;
1362 const cc = fn_info.cc;1362 const cc = fn_info.cc;
1363 var result: CallWValues = .{1363 var result: CallWValues = .{
1364 .args = &.{},1364 .args = &.{},
...@@ -1381,7 +1381,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV...@@ -1381,7 +1381,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
1381 switch (cc) {1381 switch (cc) {
1382 .Unspecified => {1382 .Unspecified => {
1383 for (fn_info.param_types.get(ip)) |ty| {1383 for (fn_info.param_types.get(ip)) |ty| {
1384 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(pt)) {1384 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(zcu)) {
1385 continue;1385 continue;
1386 }1386 }
13871387
...@@ -1391,7 +1391,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV...@@ -1391,7 +1391,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
1391 },1391 },
1392 .C => {1392 .C => {
1393 for (fn_info.param_types.get(ip)) |ty| {1393 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);
1395 for (ty_classes) |class| {1395 for (ty_classes) |class| {
1396 if (class == .none) continue;1396 if (class == .none) continue;
1397 try args.append(.{ .local = .{ .value = func.local_index, .references = 1 } });1397 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....@@ -1409,7 +1409,7 @@ fn firstParamSRet(cc: std.builtin.CallingConvention, return_type: Type, pt: Zcu.
1409 switch (cc) {1409 switch (cc) {
1410 .Unspecified, .Inline => return isByRef(return_type, pt, target),1410 .Unspecified, .Inline => return isByRef(return_type, pt, target),
1411 .C => {1411 .C => {
1412 const ty_classes = abi.classifyType(return_type, pt);1412 const ty_classes = abi.classifyType(return_type, pt.zcu);
1413 if (ty_classes[0] == .indirect) return true;1413 if (ty_classes[0] == .indirect) return true;
1414 if (ty_classes[0] == .direct and ty_classes[1] == .direct) return true;1414 if (ty_classes[0] == .direct and ty_classes[1] == .direct) return true;
1415 return false;1415 return false;
...@@ -1426,16 +1426,16 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:...@@ -1426,16 +1426,16 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:
1426 }1426 }
14271427
1428 const pt = func.pt;1428 const pt = func.pt;
1429 const mod = pt.zcu;1429 const zcu = pt.zcu;
1430 const ty_classes = abi.classifyType(ty, pt);1430 const ty_classes = abi.classifyType(ty, zcu);
1431 assert(ty_classes[0] != .none);1431 assert(ty_classes[0] != .none);
1432 switch (ty.zigTypeTag(mod)) {1432 switch (ty.zigTypeTag(zcu)) {
1433 .Struct, .Union => {1433 .Struct, .Union => {
1434 if (ty_classes[0] == .indirect) {1434 if (ty_classes[0] == .indirect) {
1435 return func.lowerToStack(value);1435 return func.lowerToStack(value);
1436 }1436 }
1437 assert(ty_classes[0] == .direct);1437 assert(ty_classes[0] == .direct);
1438 const scalar_type = abi.scalarType(ty, pt);1438 const scalar_type = abi.scalarType(ty, zcu);
1439 switch (value) {1439 switch (value) {
1440 .memory,1440 .memory,
1441 .memory_offset,1441 .memory_offset,
...@@ -1450,7 +1450,7 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:...@@ -1450,7 +1450,7 @@ fn lowerArg(func: *CodeGen, cc: std.builtin.CallingConvention, ty: Type, value:
1450 return func.lowerToStack(value);1450 return func.lowerToStack(value);
1451 }1451 }
1452 assert(ty_classes[0] == .direct and ty_classes[1] == .direct);1452 assert(ty_classes[0] == .direct and ty_classes[1] == .direct);
1453 assert(ty.abiSize(pt) == 16);1453 assert(ty.abiSize(zcu) == 16);
1454 // in this case we have an integer or float that must be lowered as 2 i64's.1454 // in this case we have an integer or float that must be lowered as 2 i64's.
1455 try func.emitWValue(value);1455 try func.emitWValue(value);
1456 try func.addMemArg(.i64_load, .{ .offset = value.offset(), .alignment = 8 });1456 try func.addMemArg(.i64_load, .{ .offset = value.offset(), .alignment = 8 });
...@@ -1517,18 +1517,18 @@ fn restoreStackPointer(func: *CodeGen) !void {...@@ -1517,18 +1517,18 @@ fn restoreStackPointer(func: *CodeGen) !void {
1517///1517///
1518/// Asserts Type has codegenbits1518/// Asserts Type has codegenbits
1519fn allocStack(func: *CodeGen, ty: Type) !WValue {1519fn allocStack(func: *CodeGen, ty: Type) !WValue {
1520 const pt = func.pt;1520 const zcu = func.pt.zcu;
1521 assert(ty.hasRuntimeBitsIgnoreComptime(pt));1521 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
1522 if (func.initial_stack_value == .none) {1522 if (func.initial_stack_value == .none) {
1523 try func.initializeStack();1523 try func.initializeStack();
1524 }1524 }
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 {
1527 return func.fail("Type {} with ABI size of {d} exceeds stack frame size", .{1527 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),
1529 });1529 });
1530 };1530 };
1531 const abi_align = ty.abiAlignment(pt);1531 const abi_align = ty.abiAlignment(zcu);
15321532
1533 func.stack_alignment = func.stack_alignment.max(abi_align);1533 func.stack_alignment = func.stack_alignment.max(abi_align);
15341534
...@@ -1544,22 +1544,22 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue {...@@ -1544,22 +1544,22 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue {
1544/// if it is set, to ensure the stack alignment will be set correctly.1544/// if it is set, to ensure the stack alignment will be set correctly.
1545fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue {1545fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue {
1546 const pt = func.pt;1546 const pt = func.pt;
1547 const mod = pt.zcu;1547 const zcu = pt.zcu;
1548 const ptr_ty = func.typeOfIndex(inst);1548 const ptr_ty = func.typeOfIndex(inst);
1549 const pointee_ty = ptr_ty.childType(mod);1549 const pointee_ty = ptr_ty.childType(zcu);
15501550
1551 if (func.initial_stack_value == .none) {1551 if (func.initial_stack_value == .none) {
1552 try func.initializeStack();1552 try func.initializeStack();
1553 }1553 }
15541554
1555 if (!pointee_ty.hasRuntimeBitsIgnoreComptime(pt)) {1555 if (!pointee_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1556 return func.allocStack(Type.usize); // create a value containing just the stack pointer.1556 return func.allocStack(Type.usize); // create a value containing just the stack pointer.
1557 }1557 }
15581558
1559 const abi_alignment = ptr_ty.ptrAlignment(pt);1559 const abi_alignment = ptr_ty.ptrAlignment(zcu);
1560 const abi_size = std.math.cast(u32, pointee_ty.abiSize(pt)) orelse {1560 const abi_size = std.math.cast(u32, pointee_ty.abiSize(zcu)) orelse {
1561 return func.fail("Type {} with ABI size of {d} exceeds stack frame size", .{1561 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),
1563 });1563 });
1564 };1564 };
1565 func.stack_alignment = func.stack_alignment.max(abi_alignment);1565 func.stack_alignment = func.stack_alignment.max(abi_alignment);
...@@ -1716,9 +1716,9 @@ fn arch(func: *const CodeGen) std.Target.Cpu.Arch {...@@ -1716,9 +1716,9 @@ fn arch(func: *const CodeGen) std.Target.Cpu.Arch {
1716/// For a given `Type`, will return true when the type will be passed1716/// For a given `Type`, will return true when the type will be passed
1717/// by reference, rather than by value1717/// by reference, rather than by value
1718fn isByRef(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {1718fn isByRef(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
1719 const mod = pt.zcu;1719 const zcu = pt.zcu;
1720 const ip = &mod.intern_pool;1720 const ip = &zcu.intern_pool;
1721 switch (ty.zigTypeTag(mod)) {1721 switch (ty.zigTypeTag(zcu)) {
1722 .Type,1722 .Type,
1723 .ComptimeInt,1723 .ComptimeInt,
1724 .ComptimeFloat,1724 .ComptimeFloat,
...@@ -1738,41 +1738,41 @@ fn isByRef(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {...@@ -1738,41 +1738,41 @@ fn isByRef(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
17381738
1739 .Array,1739 .Array,
1740 .Frame,1740 .Frame,
1741 => return ty.hasRuntimeBitsIgnoreComptime(pt),1741 => return ty.hasRuntimeBitsIgnoreComptime(zcu),
1742 .Union => {1742 .Union => {
1743 if (mod.typeToUnion(ty)) |union_obj| {1743 if (zcu.typeToUnion(ty)) |union_obj| {
1744 if (union_obj.flagsUnordered(ip).layout == .@"packed") {1744 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1745 return ty.abiSize(pt) > 8;1745 return ty.abiSize(zcu) > 8;
1746 }1746 }
1747 }1747 }
1748 return ty.hasRuntimeBitsIgnoreComptime(pt);1748 return ty.hasRuntimeBitsIgnoreComptime(zcu);
1749 },1749 },
1750 .Struct => {1750 .Struct => {
1751 if (mod.typeToPackedStruct(ty)) |packed_struct| {1751 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
1752 return isByRef(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt, target);1752 return isByRef(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt, target);
1753 }1753 }
1754 return ty.hasRuntimeBitsIgnoreComptime(pt);1754 return ty.hasRuntimeBitsIgnoreComptime(zcu);
1755 },1755 },
1756 .Vector => return determineSimdStoreStrategy(ty, pt, target) == .unrolled,1756 .Vector => return determineSimdStoreStrategy(ty, zcu, target) == .unrolled,
1757 .Int => return ty.intInfo(mod).bits > 64,1757 .Int => return ty.intInfo(zcu).bits > 64,
1758 .Enum => return ty.intInfo(mod).bits > 64,1758 .Enum => return ty.intInfo(zcu).bits > 64,
1759 .Float => return ty.floatBits(target) > 64,1759 .Float => return ty.floatBits(target) > 64,
1760 .ErrorUnion => {1760 .ErrorUnion => {
1761 const pl_ty = ty.errorUnionPayload(mod);1761 const pl_ty = ty.errorUnionPayload(zcu);
1762 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {1762 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1763 return false;1763 return false;
1764 }1764 }
1765 return true;1765 return true;
1766 },1766 },
1767 .Optional => {1767 .Optional => {
1768 if (ty.isPtrLikeOptional(mod)) return false;1768 if (ty.isPtrLikeOptional(zcu)) return false;
1769 const pl_type = ty.optionalChild(mod);1769 const pl_type = ty.optionalChild(zcu);
1770 if (pl_type.zigTypeTag(mod) == .ErrorSet) return false;1770 if (pl_type.zigTypeTag(zcu) == .ErrorSet) return false;
1771 return pl_type.hasRuntimeBitsIgnoreComptime(pt);1771 return pl_type.hasRuntimeBitsIgnoreComptime(zcu);
1772 },1772 },
1773 .Pointer => {1773 .Pointer => {
1774 // Slices act like struct and will be passed by reference1774 // Slices act like struct and will be passed by reference
1775 if (ty.isSlice(mod)) return true;1775 if (ty.isSlice(zcu)) return true;
1776 return false;1776 return false;
1777 },1777 },
1778 }1778 }
...@@ -1787,9 +1787,9 @@ const SimdStoreStrategy = enum {...@@ -1787,9 +1787,9 @@ const SimdStoreStrategy = enum {
1787/// This means when a given type is 128 bits and either the simd128 or relaxed-simd1787/// This means when a given type is 128 bits and either the simd128 or relaxed-simd
1788/// features are enabled, the function will return `.direct`. This would allow to store1788/// features are enabled, the function will return `.direct`. This would allow to store
1789/// it using a instruction, rather than an unrolled version.1789/// it using a instruction, rather than an unrolled version.
1790fn determineSimdStoreStrategy(ty: Type, pt: Zcu.PerThread, target: std.Target) SimdStoreStrategy {1790fn determineSimdStoreStrategy(ty: Type, zcu: *Zcu, target: std.Target) SimdStoreStrategy {
1791 std.debug.assert(ty.zigTypeTag(pt.zcu) == .Vector);1791 std.debug.assert(ty.zigTypeTag(zcu) == .Vector);
1792 if (ty.bitSize(pt) != 128) return .unrolled;1792 if (ty.bitSize(zcu) != 128) return .unrolled;
1793 const hasFeature = std.Target.wasm.featureSetHas;1793 const hasFeature = std.Target.wasm.featureSetHas;
1794 const features = target.cpu.features;1794 const features = target.cpu.features;
1795 if (hasFeature(features, .relaxed_simd) or hasFeature(features, .simd128)) {1795 if (hasFeature(features, .relaxed_simd) or hasFeature(features, .simd128)) {
...@@ -2069,8 +2069,8 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2069,8 +2069,8 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20692069
2070fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {2070fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
2071 const pt = func.pt;2071 const pt = func.pt;
2072 const mod = pt.zcu;2072 const zcu = pt.zcu;
2073 const ip = &mod.intern_pool;2073 const ip = &zcu.intern_pool;
20742074
2075 for (body) |inst| {2075 for (body) |inst| {
2076 if (func.liveness.isUnused(inst) and !func.air.mustLower(inst, ip)) {2076 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 {...@@ -2091,37 +2091,37 @@ fn genBody(func: *CodeGen, body: []const Air.Inst.Index) InnerError!void {
20912091
2092fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2092fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2093 const pt = func.pt;2093 const pt = func.pt;
2094 const mod = pt.zcu;2094 const zcu = pt.zcu;
2095 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;2095 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2096 const operand = try func.resolveInst(un_op);2096 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)).?;
2098 const ret_ty = Type.fromInterned(fn_info.return_type);2098 const ret_ty = Type.fromInterned(fn_info.return_type);
20992099
2100 // result must be stored in the stack and we return a pointer2100 // result must be stored in the stack and we return a pointer
2101 // to the stack instead2101 // to the stack instead
2102 if (func.return_value != .none) {2102 if (func.return_value != .none) {
2103 try func.store(func.return_value, operand, ret_ty, 0);2103 try func.store(func.return_value, operand, ret_ty, 0);
2104 } else if (fn_info.cc == .C and ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {2104 } else if (fn_info.cc == .C and ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2105 switch (ret_ty.zigTypeTag(mod)) {2105 switch (ret_ty.zigTypeTag(zcu)) {
2106 // Aggregate types can be lowered as a singular value2106 // Aggregate types can be lowered as a singular value
2107 .Struct, .Union => {2107 .Struct, .Union => {
2108 const scalar_type = abi.scalarType(ret_ty, pt);2108 const scalar_type = abi.scalarType(ret_ty, zcu);
2109 try func.emitWValue(operand);2109 try func.emitWValue(operand);
2110 const opcode = buildOpcode(.{2110 const opcode = buildOpcode(.{
2111 .op = .load,2111 .op = .load,
2112 .width = @as(u8, @intCast(scalar_type.abiSize(pt) * 8)),2112 .width = @as(u8, @intCast(scalar_type.abiSize(zcu) * 8)),
2113 .signedness = if (scalar_type.isSignedInt(mod)) .signed else .unsigned,2113 .signedness = if (scalar_type.isSignedInt(zcu)) .signed else .unsigned,
2114 .valtype1 = typeToValtype(scalar_type, pt, func.target.*),2114 .valtype1 = typeToValtype(scalar_type, pt, func.target.*),
2115 });2115 });
2116 try func.addMemArg(Mir.Inst.Tag.fromOpcode(opcode), .{2116 try func.addMemArg(Mir.Inst.Tag.fromOpcode(opcode), .{
2117 .offset = operand.offset(),2117 .offset = operand.offset(),
2118 .alignment = @intCast(scalar_type.abiAlignment(pt).toByteUnits().?),2118 .alignment = @intCast(scalar_type.abiAlignment(zcu).toByteUnits().?),
2119 });2119 });
2120 },2120 },
2121 else => try func.emitWValue(operand),2121 else => try func.emitWValue(operand),
2122 }2122 }
2123 } else {2123 } else {
2124 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt) and ret_ty.isError(mod)) {2124 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu) and ret_ty.isError(zcu)) {
2125 try func.addImm32(0);2125 try func.addImm32(0);
2126 } else {2126 } else {
2127 try func.emitWValue(operand);2127 try func.emitWValue(operand);
...@@ -2135,15 +2135,15 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2135,15 +2135,15 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21352135
2136fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2136fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2137 const pt = func.pt;2137 const pt = func.pt;
2138 const mod = pt.zcu;2138 const zcu = pt.zcu;
2139 const child_type = func.typeOfIndex(inst).childType(mod);2139 const child_type = func.typeOfIndex(inst).childType(zcu);
21402140
2141 const result = result: {2141 const result = result: {
2142 if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {2142 if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
2143 break :result try func.allocStack(Type.usize); // create pointer to void2143 break :result try func.allocStack(Type.usize); // create pointer to void
2144 }2144 }
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)).?;
2147 if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*)) {2147 if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*)) {
2148 break :result func.return_value;2148 break :result func.return_value;
2149 }2149 }
...@@ -2156,14 +2156,14 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2156,14 +2156,14 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21562156
2157fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2157fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2158 const pt = func.pt;2158 const pt = func.pt;
2159 const mod = pt.zcu;2159 const zcu = pt.zcu;
2160 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;2160 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
2161 const operand = try func.resolveInst(un_op);2161 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)).?;2164 const fn_info = zcu.typeToFunc(zcu.navValue(func.owner_nav).typeOf(zcu)).?;
2165 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {2165 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2166 if (ret_ty.isError(mod)) {2166 if (ret_ty.isError(zcu)) {
2167 try func.addImm32(0);2167 try func.addImm32(0);
2168 }2168 }
2169 } else if (!firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*)) {2169 } 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...@@ -2184,15 +2184,15 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2184 const ty = func.typeOf(pl_op.operand);2184 const ty = func.typeOf(pl_op.operand);
21852185
2186 const pt = func.pt;2186 const pt = func.pt;
2187 const mod = pt.zcu;2187 const zcu = pt.zcu;
2188 const ip = &mod.intern_pool;2188 const ip = &zcu.intern_pool;
2189 const fn_ty = switch (ty.zigTypeTag(mod)) {2189 const fn_ty = switch (ty.zigTypeTag(zcu)) {
2190 .Fn => ty,2190 .Fn => ty,
2191 .Pointer => ty.childType(mod),2191 .Pointer => ty.childType(zcu),
2192 else => unreachable,2192 else => unreachable,
2193 };2193 };
2194 const ret_ty = fn_ty.fnReturnType(mod);2194 const ret_ty = fn_ty.fnReturnType(zcu);
2195 const fn_info = mod.typeToFunc(fn_ty).?;2195 const fn_info = zcu.typeToFunc(fn_ty).?;
2196 const first_param_sret = firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*);2196 const first_param_sret = firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), pt, func.target.*);
21972197
2198 const callee: ?InternPool.Nav.Index = blk: {2198 const callee: ?InternPool.Nav.Index = blk: {
...@@ -2205,7 +2205,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2205,7 +2205,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2205 },2205 },
2206 .@"extern" => |@"extern"| {2206 .@"extern" => |@"extern"| {
2207 const ext_nav = ip.getNav(@"extern".owner_nav);2207 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)).?;
2209 var func_type = try genFunctype(2209 var func_type = try genFunctype(
2210 func.gpa,2210 func.gpa,
2211 ext_info.cc,2211 ext_info.cc,
...@@ -2248,9 +2248,9 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2248,9 +2248,9 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2248 const arg_val = try func.resolveInst(arg);2248 const arg_val = try func.resolveInst(arg);
22492249
2250 const arg_ty = func.typeOf(arg);2250 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);
2254 }2254 }
22552255
2256 if (callee) |direct| {2256 if (callee) |direct| {
...@@ -2259,7 +2259,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2259,7 +2259,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2259 } else {2259 } else {
2260 // in this case we call a function pointer2260 // in this case we call a function pointer
2261 // so load its value onto the stack2261 // so load its value onto the stack
2262 std.debug.assert(ty.zigTypeTag(mod) == .Pointer);2262 std.debug.assert(ty.zigTypeTag(zcu) == .Pointer);
2263 const operand = try func.resolveInst(pl_op.operand);2263 const operand = try func.resolveInst(pl_op.operand);
2264 try func.emitWValue(operand);2264 try func.emitWValue(operand);
22652265
...@@ -2271,18 +2271,18 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2271,18 +2271,18 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2271 }2271 }
22722272
2273 const result_value = result_value: {2273 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)) {
2275 break :result_value .none;2275 break :result_value .none;
2276 } else if (ret_ty.isNoReturn(mod)) {2276 } else if (ret_ty.isNoReturn(zcu)) {
2277 try func.addTag(.@"unreachable");2277 try func.addTag(.@"unreachable");
2278 break :result_value .none;2278 break :result_value .none;
2279 } else if (first_param_sret) {2279 } else if (first_param_sret) {
2280 break :result_value sret;2280 break :result_value sret;
2281 // TODO: Make this less fragile and optimize2281 // 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) {
2283 const result_local = try func.allocLocal(ret_ty);2283 const result_local = try func.allocLocal(ret_ty);
2284 try func.addLabel(.local_set, result_local.local.value);2284 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);
2286 const result = try func.allocStack(scalar_type);2286 const result = try func.allocStack(scalar_type);
2287 try func.store(result, result_local, scalar_type, 0);2287 try func.store(result, result_local, scalar_type, 0);
2288 break :result_value result;2288 break :result_value result;
...@@ -2306,7 +2306,7 @@ fn airAlloc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2306,7 +2306,7 @@ fn airAlloc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
23062306
2307fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {2307fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
2308 const pt = func.pt;2308 const pt = func.pt;
2309 const mod = pt.zcu;2309 const zcu = pt.zcu;
2310 if (safety) {2310 if (safety) {
2311 // TODO if the value is undef, write 0xaa bytes to dest2311 // TODO if the value is undef, write 0xaa bytes to dest
2312 } else {2312 } else {
...@@ -2317,8 +2317,8 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -2317,8 +2317,8 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
2317 const lhs = try func.resolveInst(bin_op.lhs);2317 const lhs = try func.resolveInst(bin_op.lhs);
2318 const rhs = try func.resolveInst(bin_op.rhs);2318 const rhs = try func.resolveInst(bin_op.rhs);
2319 const ptr_ty = func.typeOf(bin_op.lhs);2319 const ptr_ty = func.typeOf(bin_op.lhs);
2320 const ptr_info = ptr_ty.ptrInfo(mod);2320 const ptr_info = ptr_ty.ptrInfo(zcu);
2321 const ty = ptr_ty.childType(mod);2321 const ty = ptr_ty.childType(zcu);
23222322
2323 if (ptr_info.packed_offset.host_size == 0) {2323 if (ptr_info.packed_offset.host_size == 0) {
2324 try func.store(lhs, rhs, ty, 0);2324 try func.store(lhs, rhs, ty, 0);
...@@ -2331,7 +2331,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -2331,7 +2331,7 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
2331 return func.fail("TODO: airStore for pointers to bitfields with backing type larger than 64bits", .{});2331 return func.fail("TODO: airStore for pointers to bitfields with backing type larger than 64bits", .{});
2332 }2332 }
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));
2335 mask <<= @as(u6, @intCast(ptr_info.packed_offset.bit_offset));2335 mask <<= @as(u6, @intCast(ptr_info.packed_offset.bit_offset));
2336 mask ^= ~@as(u64, 0);2336 mask ^= ~@as(u64, 0);
2337 const shift_val: WValue = if (ptr_info.packed_offset.host_size <= 4)2337 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...@@ -2343,9 +2343,9 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
2343 else2343 else
2344 .{ .imm64 = mask };2344 .{ .imm64 = mask };
2345 const wrap_mask_val: WValue = if (ptr_info.packed_offset.host_size <= 4)2345 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))) }
2347 else2347 else
2348 .{ .imm64 = ~@as(u64, 0) >> @intCast(64 - ty.bitSize(pt)) };2348 .{ .imm64 = ~@as(u64, 0) >> @intCast(64 - ty.bitSize(zcu)) };
23492349
2350 try func.emitWValue(lhs);2350 try func.emitWValue(lhs);
2351 const loaded = try func.load(lhs, int_elem_ty, 0);2351 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...@@ -2366,12 +2366,12 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
2366fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerError!void {2366fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerError!void {
2367 assert(!(lhs != .stack and rhs == .stack));2367 assert(!(lhs != .stack and rhs == .stack));
2368 const pt = func.pt;2368 const pt = func.pt;
2369 const mod = pt.zcu;2369 const zcu = pt.zcu;
2370 const abi_size = ty.abiSize(pt);2370 const abi_size = ty.abiSize(zcu);
2371 switch (ty.zigTypeTag(mod)) {2371 switch (ty.zigTypeTag(zcu)) {
2372 .ErrorUnion => {2372 .ErrorUnion => {
2373 const pl_ty = ty.errorUnionPayload(mod);2373 const pl_ty = ty.errorUnionPayload(zcu);
2374 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {2374 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2375 return func.store(lhs, rhs, Type.anyerror, 0);2375 return func.store(lhs, rhs, Type.anyerror, 0);
2376 }2376 }
23772377
...@@ -2379,14 +2379,14 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2379,14 +2379,14 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2379 return func.memcpy(lhs, rhs, .{ .imm32 = len });2379 return func.memcpy(lhs, rhs, .{ .imm32 = len });
2380 },2380 },
2381 .Optional => {2381 .Optional => {
2382 if (ty.isPtrLikeOptional(mod)) {2382 if (ty.isPtrLikeOptional(zcu)) {
2383 return func.store(lhs, rhs, Type.usize, 0);2383 return func.store(lhs, rhs, Type.usize, 0);
2384 }2384 }
2385 const pl_ty = ty.optionalChild(mod);2385 const pl_ty = ty.optionalChild(zcu);
2386 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {2386 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2387 return func.store(lhs, rhs, Type.u8, 0);2387 return func.store(lhs, rhs, Type.u8, 0);
2388 }2388 }
2389 if (pl_ty.zigTypeTag(mod) == .ErrorSet) {2389 if (pl_ty.zigTypeTag(zcu) == .ErrorSet) {
2390 return func.store(lhs, rhs, Type.anyerror, 0);2390 return func.store(lhs, rhs, Type.anyerror, 0);
2391 }2391 }
23922392
...@@ -2397,7 +2397,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2397,7 +2397,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2397 const len = @as(u32, @intCast(abi_size));2397 const len = @as(u32, @intCast(abi_size));
2398 return func.memcpy(lhs, rhs, .{ .imm32 = len });2398 return func.memcpy(lhs, rhs, .{ .imm32 = len });
2399 },2399 },
2400 .Vector => switch (determineSimdStoreStrategy(ty, pt, func.target.*)) {2400 .Vector => switch (determineSimdStoreStrategy(ty, zcu, func.target.*)) {
2401 .unrolled => {2401 .unrolled => {
2402 const len: u32 = @intCast(abi_size);2402 const len: u32 = @intCast(abi_size);
2403 return func.memcpy(lhs, rhs, .{ .imm32 = len });2403 return func.memcpy(lhs, rhs, .{ .imm32 = len });
...@@ -2411,13 +2411,13 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2411,13 +2411,13 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2411 try func.mir_extra.appendSlice(func.gpa, &[_]u32{2411 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
2412 std.wasm.simdOpcode(.v128_store),2412 std.wasm.simdOpcode(.v128_store),
2413 offset + lhs.offset(),2413 offset + lhs.offset(),
2414 @intCast(ty.abiAlignment(pt).toByteUnits() orelse 0),2414 @intCast(ty.abiAlignment(zcu).toByteUnits() orelse 0),
2415 });2415 });
2416 return func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });2416 return func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
2417 },2417 },
2418 },2418 },
2419 .Pointer => {2419 .Pointer => {
2420 if (ty.isSlice(mod)) {2420 if (ty.isSlice(zcu)) {
2421 // store pointer first2421 // store pointer first
2422 // lower it to the stack so we do not have to store rhs into a local first2422 // lower it to the stack so we do not have to store rhs into a local first
2423 try func.emitWValue(lhs);2423 try func.emitWValue(lhs);
...@@ -2441,7 +2441,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE...@@ -2441,7 +2441,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2441 try func.store(.stack, msb, Type.u64, 8 + lhs.offset());2441 try func.store(.stack, msb, Type.u64, 8 + lhs.offset());
2442 return;2442 return;
2443 } else if (abi_size > 16) {2443 } 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))) });
2445 },2445 },
2446 else => if (abi_size > 8) {2446 else => if (abi_size > 8) {
2447 return func.fail("TODO: `store` for type `{}` with abisize `{d}`", .{2447 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...@@ -2467,21 +2467,21 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
2467 Mir.Inst.Tag.fromOpcode(opcode),2467 Mir.Inst.Tag.fromOpcode(opcode),
2468 .{2468 .{
2469 .offset = offset + lhs.offset(),2469 .offset = offset + lhs.offset(),
2470 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),2470 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
2471 },2471 },
2472 );2472 );
2473}2473}
24742474
2475fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2475fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2476 const pt = func.pt;2476 const pt = func.pt;
2477 const mod = pt.zcu;2477 const zcu = pt.zcu;
2478 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2478 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2479 const operand = try func.resolveInst(ty_op.operand);2479 const operand = try func.resolveInst(ty_op.operand);
2480 const ty = ty_op.ty.toType();2480 const ty = ty_op.ty.toType();
2481 const ptr_ty = func.typeOf(ty_op.operand);2481 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
2486 const result = result: {2486 const result = result: {
2487 if (isByRef(ty, pt, func.target.*)) {2487 if (isByRef(ty, pt, func.target.*)) {
...@@ -2515,36 +2515,36 @@ fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2515,36 +2515,36 @@ fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2515/// NOTE: Leaves the value on the stack.2515/// NOTE: Leaves the value on the stack.
2516fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValue {2516fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValue {
2517 const pt = func.pt;2517 const pt = func.pt;
2518 const mod = pt.zcu;2518 const zcu = pt.zcu;
2519 // load local's value from memory by its stack position2519 // load local's value from memory by its stack position
2520 try func.emitWValue(operand);2520 try func.emitWValue(operand);
25212521
2522 if (ty.zigTypeTag(mod) == .Vector) {2522 if (ty.zigTypeTag(zcu) == .Vector) {
2523 // TODO: Add helper functions for simd opcodes2523 // TODO: Add helper functions for simd opcodes
2524 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));2524 const extra_index = @as(u32, @intCast(func.mir_extra.items.len));
2525 // stores as := opcode, offset, alignment (opcode::memarg)2525 // stores as := opcode, offset, alignment (opcode::memarg)
2526 try func.mir_extra.appendSlice(func.gpa, &[_]u32{2526 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
2527 std.wasm.simdOpcode(.v128_load),2527 std.wasm.simdOpcode(.v128_load),
2528 offset + operand.offset(),2528 offset + operand.offset(),
2529 @intCast(ty.abiAlignment(pt).toByteUnits().?),2529 @intCast(ty.abiAlignment(zcu).toByteUnits().?),
2530 });2530 });
2531 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });2531 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
2532 return .stack;2532 return .stack;
2533 }2533 }
25342534
2535 const abi_size: u8 = @intCast(ty.abiSize(pt));2535 const abi_size: u8 = @intCast(ty.abiSize(zcu));
2536 const opcode = buildOpcode(.{2536 const opcode = buildOpcode(.{
2537 .valtype1 = typeToValtype(ty, pt, func.target.*),2537 .valtype1 = typeToValtype(ty, pt, func.target.*),
2538 .width = abi_size * 8,2538 .width = abi_size * 8,
2539 .op = .load,2539 .op = .load,
2540 .signedness = if (ty.isSignedInt(mod)) .signed else .unsigned,2540 .signedness = if (ty.isSignedInt(zcu)) .signed else .unsigned,
2541 });2541 });
25422542
2543 try func.addMemArg(2543 try func.addMemArg(
2544 Mir.Inst.Tag.fromOpcode(opcode),2544 Mir.Inst.Tag.fromOpcode(opcode),
2545 .{2545 .{
2546 .offset = offset + operand.offset(),2546 .offset = offset + operand.offset(),
2547 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),2547 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
2548 },2548 },
2549 );2549 );
25502550
...@@ -2553,13 +2553,13 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu...@@ -2553,13 +2553,13 @@ fn load(func: *CodeGen, operand: WValue, ty: Type, offset: u32) InnerError!WValu
25532553
2554fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2554fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2555 const pt = func.pt;2555 const pt = func.pt;
2556 const mod = pt.zcu;2556 const zcu = pt.zcu;
2557 const arg_index = func.arg_index;2557 const arg_index = func.arg_index;
2558 const arg = func.args[arg_index];2558 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;
2560 const arg_ty = func.typeOfIndex(inst);2560 const arg_ty = func.typeOfIndex(inst);
2561 if (cc == .C) {2561 if (cc == .C) {
2562 const arg_classes = abi.classifyType(arg_ty, pt);2562 const arg_classes = abi.classifyType(arg_ty, zcu);
2563 for (arg_classes) |class| {2563 for (arg_classes) |class| {
2564 if (class != .none) {2564 if (class != .none) {
2565 func.arg_index += 1;2565 func.arg_index += 1;
...@@ -2569,7 +2569,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2569,7 +2569,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2569 // When we have an argument that's passed using more than a single parameter,2569 // When we have an argument that's passed using more than a single parameter,
2570 // we combine them into a single stack value2570 // we combine them into a single stack value
2571 if (arg_classes[0] == .direct and arg_classes[1] == .direct) {2571 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) {
2573 return func.fail(2573 return func.fail(
2574 "TODO: Implement C-ABI argument for type '{}'",2574 "TODO: Implement C-ABI argument for type '{}'",
2575 .{arg_ty.fmt(pt)},2575 .{arg_ty.fmt(pt)},
...@@ -2602,6 +2602,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2602,6 +2602,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
26022602
2603fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {2603fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2604 const pt = func.pt;2604 const pt = func.pt;
2605 const zcu = pt.zcu;
2605 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;2606 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
2606 const lhs = try func.resolveInst(bin_op.lhs);2607 const lhs = try func.resolveInst(bin_op.lhs);
2607 const rhs = try func.resolveInst(bin_op.rhs);2608 const rhs = try func.resolveInst(bin_op.rhs);
...@@ -2615,10 +2616,10 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -2615,10 +2616,10 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2615 // For big integers we can ignore this as we will call into compiler-rt which handles this.2616 // For big integers we can ignore this as we will call into compiler-rt which handles this.
2616 const result = switch (op) {2617 const result = switch (op) {
2617 .shr, .shl => result: {2618 .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 {
2619 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});2620 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
2620 };2621 };
2621 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(pt))).?;2622 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(zcu))).?;
2622 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128)2623 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128)
2623 try (try func.intcast(rhs, rhs_ty, lhs_ty)).toLocal(func, lhs_ty)2624 try (try func.intcast(rhs, rhs_ty, lhs_ty)).toLocal(func, lhs_ty)
2624 else2625 else
...@@ -2635,7 +2636,7 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -2635,7 +2636,7 @@ fn airBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
2635/// NOTE: THis leaves the value on top of the stack.2636/// NOTE: THis leaves the value on top of the stack.
2636fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {2637fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {
2637 const pt = func.pt;2638 const pt = func.pt;
2638 const mod = pt.zcu;2639 const zcu = pt.zcu;
2639 assert(!(lhs != .stack and rhs == .stack));2640 assert(!(lhs != .stack and rhs == .stack));
26402641
2641 if (ty.isAnyFloat()) {2642 if (ty.isAnyFloat()) {
...@@ -2644,7 +2645,7 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!...@@ -2644,7 +2645,7 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!
2644 }2645 }
26452646
2646 if (isByRef(ty, pt, func.target.*)) {2647 if (isByRef(ty, pt, func.target.*)) {
2647 if (ty.zigTypeTag(mod) == .Int) {2648 if (ty.zigTypeTag(zcu) == .Int) {
2648 return func.binOpBigInt(lhs, rhs, ty, op);2649 return func.binOpBigInt(lhs, rhs, ty, op);
2649 } else {2650 } else {
2650 return func.fail(2651 return func.fail(
...@@ -2657,7 +2658,7 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!...@@ -2657,7 +2658,7 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!
2657 const opcode: wasm.Opcode = buildOpcode(.{2658 const opcode: wasm.Opcode = buildOpcode(.{
2658 .op = op,2659 .op = op,
2659 .valtype1 = typeToValtype(ty, pt, func.target.*),2660 .valtype1 = typeToValtype(ty, pt, func.target.*),
2660 .signedness = if (ty.isSignedInt(mod)) .signed else .unsigned,2661 .signedness = if (ty.isSignedInt(zcu)) .signed else .unsigned,
2661 });2662 });
2662 try func.emitWValue(lhs);2663 try func.emitWValue(lhs);
2663 try func.emitWValue(rhs);2664 try func.emitWValue(rhs);
...@@ -2669,8 +2670,8 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!...@@ -2669,8 +2670,8 @@ fn binOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!
26692670
2670fn binOpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {2671fn binOpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {
2671 const pt = func.pt;2672 const pt = func.pt;
2672 const mod = pt.zcu;2673 const zcu = pt.zcu;
2673 const int_info = ty.intInfo(mod);2674 const int_info = ty.intInfo(zcu);
2674 if (int_info.bits > 128) {2675 if (int_info.bits > 128) {
2675 return func.fail("TODO: Implement binary operation for big integers larger than 128 bits", .{});2676 return func.fail("TODO: Implement binary operation for big integers larger than 128 bits", .{});
2676 }2677 }
...@@ -2812,17 +2813,17 @@ const FloatOp = enum {...@@ -2812,17 +2813,17 @@ const FloatOp = enum {
28122813
2813fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {2814fn airAbs(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2814 const pt = func.pt;2815 const pt = func.pt;
2815 const mod = pt.zcu;2816 const zcu = pt.zcu;
2816 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;2817 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
2817 const operand = try func.resolveInst(ty_op.operand);2818 const operand = try func.resolveInst(ty_op.operand);
2818 const ty = func.typeOf(ty_op.operand);2819 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 switch (scalar_ty.zigTypeTag(zcu)) {
2822 .Int => if (ty.zigTypeTag(mod) == .Vector) {2823 .Int => if (ty.zigTypeTag(zcu) == .Vector) {
2823 return func.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});2824 return func.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});
2824 } else {2825 } else {
2825 const int_bits = ty.intInfo(mod).bits;2826 const int_bits = ty.intInfo(zcu).bits;
2826 const wasm_bits = toWasmBits(int_bits) orelse {2827 const wasm_bits = toWasmBits(int_bits) orelse {
2827 return func.fail("TODO: airAbs for signed integers larger than '{d}' bits", .{int_bits});2828 return func.fail("TODO: airAbs for signed integers larger than '{d}' bits", .{int_bits});
2828 };2829 };
...@@ -2903,8 +2904,8 @@ fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError...@@ -2903,8 +2904,8 @@ fn airUnaryFloatOp(func: *CodeGen, inst: Air.Inst.Index, op: FloatOp) InnerError
29032904
2904fn floatOp(func: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) InnerError!WValue {2905fn floatOp(func: *CodeGen, float_op: FloatOp, ty: Type, args: []const WValue) InnerError!WValue {
2905 const pt = func.pt;2906 const pt = func.pt;
2906 const mod = pt.zcu;2907 const zcu = pt.zcu;
2907 if (ty.zigTypeTag(mod) == .Vector) {2908 if (ty.zigTypeTag(zcu) == .Vector) {
2908 return func.fail("TODO: Implement floatOps for vectors", .{});2909 return func.fail("TODO: Implement floatOps for vectors", .{});
2909 }2910 }
29102911
...@@ -3010,7 +3011,7 @@ fn floatNeg(func: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {...@@ -3010,7 +3011,7 @@ fn floatNeg(func: *CodeGen, ty: Type, arg: WValue) InnerError!WValue {
30103011
3011fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {3012fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
3012 const pt = func.pt;3013 const pt = func.pt;
3013 const mod = pt.zcu;3014 const zcu = pt.zcu;
3014 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3015 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
30153016
3016 const lhs = try func.resolveInst(bin_op.lhs);3017 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -3018,7 +3019,7 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -3018,7 +3019,7 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
3018 const lhs_ty = func.typeOf(bin_op.lhs);3019 const lhs_ty = func.typeOf(bin_op.lhs);
3019 const rhs_ty = func.typeOf(bin_op.rhs);3020 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) {
3022 return func.fail("TODO: Implement wrapping arithmetic for vectors", .{});3023 return func.fail("TODO: Implement wrapping arithmetic for vectors", .{});
3023 }3024 }
30243025
...@@ -3029,10 +3030,10 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -3029,10 +3030,10 @@ fn airWrapBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
3029 // For big integers we can ignore this as we will call into compiler-rt which handles this.3030 // For big integers we can ignore this as we will call into compiler-rt which handles this.
3030 const result = switch (op) {3031 const result = switch (op) {
3031 .shr, .shl => result: {3032 .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 {
3033 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});3034 return func.fail("TODO: implement '{s}' for types larger than 128 bits", .{@tagName(op)});
3034 };3035 };
3035 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(pt))).?;3036 const rhs_wasm_bits = toWasmBits(@intCast(rhs_ty.bitSize(zcu))).?;
3036 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128)3037 const new_rhs = if (lhs_wasm_bits != rhs_wasm_bits and lhs_wasm_bits != 128)
3037 try (try func.intcast(rhs, rhs_ty, lhs_ty)).toLocal(func, lhs_ty)3038 try (try func.intcast(rhs, rhs_ty, lhs_ty)).toLocal(func, lhs_ty)
3038 else3039 else
...@@ -3058,9 +3059,9 @@ fn wrapBinOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerEr...@@ -3058,9 +3059,9 @@ fn wrapBinOp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerEr
3058/// NOTE: When the Type is <= 64 bits, leaves the value on top of the stack, if wrapping was needed.3059/// NOTE: When the Type is <= 64 bits, leaves the value on top of the stack, if wrapping was needed.
3059fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {3060fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
3060 const pt = func.pt;3061 const pt = func.pt;
3061 const mod = pt.zcu;3062 const zcu = pt.zcu;
3062 assert(ty.abiSize(pt) <= 16);3063 assert(ty.abiSize(zcu) <= 16);
3063 const int_bits: u16 = @intCast(ty.bitSize(pt)); // TODO use ty.intInfo(mod).bits3064 const int_bits: u16 = @intCast(ty.bitSize(zcu)); // TODO use ty.intInfo(zcu).bits
3064 const wasm_bits = toWasmBits(int_bits) orelse {3065 const wasm_bits = toWasmBits(int_bits) orelse {
3065 return func.fail("TODO: Implement wrapOperand for bitsize '{d}'", .{int_bits});3066 return func.fail("TODO: Implement wrapOperand for bitsize '{d}'", .{int_bits});
3066 };3067 };
...@@ -3070,7 +3071,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {...@@ -3070,7 +3071,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
3070 switch (wasm_bits) {3071 switch (wasm_bits) {
3071 32 => {3072 32 => {
3072 try func.emitWValue(operand);3073 try func.emitWValue(operand);
3073 if (ty.isSignedInt(mod)) {3074 if (ty.isSignedInt(zcu)) {
3074 try func.addImm32(32 - int_bits);3075 try func.addImm32(32 - int_bits);
3075 try func.addTag(.i32_shl);3076 try func.addTag(.i32_shl);
3076 try func.addImm32(32 - int_bits);3077 try func.addImm32(32 - int_bits);
...@@ -3083,7 +3084,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {...@@ -3083,7 +3084,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
3083 },3084 },
3084 64 => {3085 64 => {
3085 try func.emitWValue(operand);3086 try func.emitWValue(operand);
3086 if (ty.isSignedInt(mod)) {3087 if (ty.isSignedInt(zcu)) {
3087 try func.addImm64(64 - int_bits);3088 try func.addImm64(64 - int_bits);
3088 try func.addTag(.i64_shl);3089 try func.addTag(.i64_shl);
3089 try func.addImm64(64 - int_bits);3090 try func.addImm64(64 - int_bits);
...@@ -3104,7 +3105,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {...@@ -3104,7 +3105,7 @@ fn wrapOperand(func: *CodeGen, operand: WValue, ty: Type) InnerError!WValue {
31043105
3105 try func.emitWValue(result);3106 try func.emitWValue(result);
3106 _ = try func.load(operand, Type.u64, 8);3107 _ = try func.load(operand, Type.u64, 8);
3107 if (ty.isSignedInt(mod)) {3108 if (ty.isSignedInt(zcu)) {
3108 try func.addImm64(128 - int_bits);3109 try func.addImm64(128 - int_bits);
3109 try func.addTag(.i64_shl);3110 try func.addTag(.i64_shl);
3110 try func.addImm64(128 - int_bits);3111 try func.addImm64(128 - int_bits);
...@@ -3145,13 +3146,13 @@ fn lowerPtr(func: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerEr...@@ -3145,13 +3146,13 @@ fn lowerPtr(func: *CodeGen, ptr_val: InternPool.Index, prev_offset: u64) InnerEr
3145 };3146 };
3146 },3147 },
3147 .Struct => switch (base_ty.containerLayout(zcu)) {3148 .Struct => switch (base_ty.containerLayout(zcu)) {
3148 .auto => base_ty.structFieldOffset(@intCast(field.index), pt),3149 .auto => base_ty.structFieldOffset(@intCast(field.index), zcu),
3149 .@"extern", .@"packed" => unreachable,3150 .@"extern", .@"packed" => unreachable,
3150 },3151 },
3151 .Union => switch (base_ty.containerLayout(zcu)) {3152 .Union => switch (base_ty.containerLayout(zcu)) {
3152 .auto => off: {3153 .auto => off: {
3153 // Keep in sync with the `un` case of `generateSymbol`.3154 // Keep in sync with the `un` case of `generateSymbol`.
3154 const layout = base_ty.unionGetLayout(pt);3155 const layout = base_ty.unionGetLayout(zcu);
3155 if (layout.payload_size == 0) break :off 0;3156 if (layout.payload_size == 0) break :off 0;
3156 if (layout.tag_size == 0) break :off 0;3157 if (layout.tag_size == 0) break :off 0;
3157 if (layout.tag_align.compare(.gte, layout.payload_align)) {3158 if (layout.tag_align.compare(.gte, layout.payload_align)) {
...@@ -3178,15 +3179,15 @@ fn lowerUavRef(...@@ -3178,15 +3179,15 @@ fn lowerUavRef(
3178 offset: u32,3179 offset: u32,
3179) InnerError!WValue {3180) InnerError!WValue {
3180 const pt = func.pt;3181 const pt = func.pt;
3181 const mod = pt.zcu;3182 const zcu = pt.zcu;
3182 const ty = Type.fromInterned(mod.intern_pool.typeOf(uav.val));3183 const ty = Type.fromInterned(zcu.intern_pool.typeOf(uav.val));
31833184
3184 const is_fn_body = ty.zigTypeTag(mod) == .Fn;3185 const is_fn_body = ty.zigTypeTag(zcu) == .Fn;
3185 if (!is_fn_body and !ty.hasRuntimeBitsIgnoreComptime(pt)) {3186 if (!is_fn_body and !ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3186 return .{ .imm32 = 0xaaaaaaaa };3187 return .{ .imm32 = 0xaaaaaaaa };
3187 }3188 }
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;
3190 const res = try func.bin_file.lowerUav(pt, uav.val, decl_align, func.src_loc);3191 const res = try func.bin_file.lowerUav(pt, uav.val, decl_align, func.src_loc);
3191 const target_sym_index = switch (res) {3192 const target_sym_index = switch (res) {
3192 .mcv => |mcv| mcv.load_symbol,3193 .mcv => |mcv| mcv.load_symbol,
...@@ -3204,19 +3205,19 @@ fn lowerUavRef(...@@ -3204,19 +3205,19 @@ fn lowerUavRef(
32043205
3205fn lowerNavRef(func: *CodeGen, nav_index: InternPool.Nav.Index, offset: u32) InnerError!WValue {3206fn lowerNavRef(func: *CodeGen, nav_index: InternPool.Nav.Index, offset: u32) InnerError!WValue {
3206 const pt = func.pt;3207 const pt = func.pt;
3207 const mod = pt.zcu;3208 const zcu = pt.zcu;
3208 const ip = &mod.intern_pool;3209 const ip = &zcu.intern_pool;
32093210
3210 // check if decl is an alias to a function, in which case we3211 // check if decl is an alias to a function, in which case we
3211 // want to lower the actual decl, rather than the alias itself.3212 // 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())) {
3213 .func => |function| function.owner_nav,3214 .func => |function| function.owner_nav,
3214 .variable => |variable| variable.owner_nav,3215 .variable => |variable| variable.owner_nav,
3215 .@"extern" => |@"extern"| @"extern".owner_nav,3216 .@"extern" => |@"extern"| @"extern".owner_nav,
3216 else => nav_index,3217 else => nav_index,
3217 };3218 };
3218 const nav_ty = ip.getNav(owner_nav).typeOf(ip);3219 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)) {
3220 return .{ .imm32 = 0xaaaaaaaa };3221 return .{ .imm32 = 0xaaaaaaaa };
3221 }3222 }
32223223
...@@ -3234,10 +3235,10 @@ fn lowerNavRef(func: *CodeGen, nav_index: InternPool.Nav.Index, offset: u32) Inn...@@ -3234,10 +3235,10 @@ fn lowerNavRef(func: *CodeGen, nav_index: InternPool.Nav.Index, offset: u32) Inn
3234/// Asserts that `isByRef` returns `false` for `ty`.3235/// Asserts that `isByRef` returns `false` for `ty`.
3235fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {3236fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3236 const pt = func.pt;3237 const pt = func.pt;
3237 const mod = pt.zcu;3238 const zcu = pt.zcu;
3238 assert(!isByRef(ty, pt, func.target.*));3239 assert(!isByRef(ty, pt, func.target.*));
3239 const ip = &mod.intern_pool;3240 const ip = &zcu.intern_pool;
3240 if (val.isUndefDeep(mod)) return func.emitUndefined(ty);3241 if (val.isUndefDeep(zcu)) return func.emitUndefined(ty);
32413242
3242 switch (ip.indexToKey(val.ip_index)) {3243 switch (ip.indexToKey(val.ip_index)) {
3243 .int_type,3244 .int_type,
...@@ -3280,16 +3281,16 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3280,16 +3281,16 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3280 .empty_enum_value,3281 .empty_enum_value,
3281 => unreachable, // non-runtime values3282 => unreachable, // non-runtime values
3282 .int => {3283 .int => {
3283 const int_info = ty.intInfo(mod);3284 const int_info = ty.intInfo(zcu);
3284 switch (int_info.signedness) {3285 switch (int_info.signedness) {
3285 .signed => switch (int_info.bits) {3286 .signed => switch (int_info.bits) {
3286 0...32 => return .{ .imm32 = @bitCast(@as(i32, @intCast(val.toSignedInt(pt)))) },3287 0...32 => return .{ .imm32 = @bitCast(@as(i32, @intCast(val.toSignedInt(zcu)))) },
3287 33...64 => return .{ .imm64 = @bitCast(val.toSignedInt(pt)) },3288 33...64 => return .{ .imm64 = @bitCast(val.toSignedInt(zcu)) },
3288 else => unreachable,3289 else => unreachable,
3289 },3290 },
3290 .unsigned => switch (int_info.bits) {3291 .unsigned => switch (int_info.bits) {
3291 0...32 => return .{ .imm32 = @intCast(val.toUnsignedInt(pt)) },3292 0...32 => return .{ .imm32 = @intCast(val.toUnsignedInt(zcu)) },
3292 33...64 => return .{ .imm64 = val.toUnsignedInt(pt) },3293 33...64 => return .{ .imm64 = val.toUnsignedInt(zcu) },
3293 else => unreachable,3294 else => unreachable,
3294 },3295 },
3295 }3296 }
...@@ -3302,9 +3303,9 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3302,9 +3303,9 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3302 const err_int_ty = try pt.errorIntType();3303 const err_int_ty = try pt.errorIntType();
3303 const err_ty, const err_val = switch (error_union.val) {3304 const err_ty, const err_val = switch (error_union.val) {
3304 .err_name => |err_name| .{3305 .err_name => |err_name| .{
3305 ty.errorUnionSet(mod),3306 ty.errorUnionSet(zcu),
3306 Value.fromInterned(try pt.intern(.{ .err = .{3307 Value.fromInterned(try pt.intern(.{ .err = .{
3307 .ty = ty.errorUnionSet(mod).toIntern(),3308 .ty = ty.errorUnionSet(zcu).toIntern(),
3308 .name = err_name,3309 .name = err_name,
3309 } })),3310 } })),
3310 },3311 },
...@@ -3313,8 +3314,8 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3313,8 +3314,8 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3313 try pt.intValue(err_int_ty, 0),3314 try pt.intValue(err_int_ty, 0),
3314 },3315 },
3315 };3316 };
3316 const payload_type = ty.errorUnionPayload(mod);3317 const payload_type = ty.errorUnionPayload(zcu);
3317 if (!payload_type.hasRuntimeBitsIgnoreComptime(pt)) {3318 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
3318 // We use the error type directly as the type.3319 // We use the error type directly as the type.
3319 return func.lowerConstant(err_val, err_ty);3320 return func.lowerConstant(err_val, err_ty);
3320 }3321 }
...@@ -3339,20 +3340,20 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3339,20 +3340,20 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3339 },3340 },
3340 },3341 },
3341 .ptr => return func.lowerPtr(val.toIntern(), 0),3342 .ptr => return func.lowerPtr(val.toIntern(), 0),
3342 .opt => if (ty.optionalReprIsPayload(mod)) {3343 .opt => if (ty.optionalReprIsPayload(zcu)) {
3343 const pl_ty = ty.optionalChild(mod);3344 const pl_ty = ty.optionalChild(zcu);
3344 if (val.optionalValue(mod)) |payload| {3345 if (val.optionalValue(zcu)) |payload| {
3345 return func.lowerConstant(payload, pl_ty);3346 return func.lowerConstant(payload, pl_ty);
3346 } else {3347 } else {
3347 return .{ .imm32 = 0 };3348 return .{ .imm32 = 0 };
3348 }3349 }
3349 } else {3350 } else {
3350 return .{ .imm32 = @intFromBool(!val.isNull(mod)) };3351 return .{ .imm32 = @intFromBool(!val.isNull(zcu)) };
3351 },3352 },
3352 .aggregate => switch (ip.indexToKey(ty.ip_index)) {3353 .aggregate => switch (ip.indexToKey(ty.ip_index)) {
3353 .array_type => return func.fail("Wasm TODO: LowerConstant for {}", .{ty.fmt(pt)}),3354 .array_type => return func.fail("Wasm TODO: LowerConstant for {}", .{ty.fmt(pt)}),
3354 .vector_type => {3355 .vector_type => {
3355 assert(determineSimdStoreStrategy(ty, pt, func.target.*) == .direct);3356 assert(determineSimdStoreStrategy(ty, zcu, func.target.*) == .direct);
3356 var buf: [16]u8 = undefined;3357 var buf: [16]u8 = undefined;
3357 val.writeToMemory(ty, pt, &buf) catch unreachable;3358 val.writeToMemory(ty, pt, &buf) catch unreachable;
3358 return func.storeSimdImmd(buf);3359 return func.storeSimdImmd(buf);
...@@ -3378,8 +3379,8 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3378,8 +3379,8 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3378 const constant_ty = if (un.tag == .none)3379 const constant_ty = if (un.tag == .none)
3379 try ty.unionBackingType(pt)3380 try ty.unionBackingType(pt)
3380 else field_ty: {3381 else field_ty: {
3381 const union_obj = mod.typeToUnion(ty).?;3382 const union_obj = zcu.typeToUnion(ty).?;
3382 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;3383 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3383 break :field_ty Type.fromInterned(union_obj.field_types.get(ip)[field_index]);3384 break :field_ty Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3384 };3385 };
3385 return func.lowerConstant(Value.fromInterned(un.val), constant_ty);3386 return func.lowerConstant(Value.fromInterned(un.val), constant_ty);
...@@ -3398,11 +3399,11 @@ fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue {...@@ -3398,11 +3399,11 @@ fn storeSimdImmd(func: *CodeGen, value: [16]u8) !WValue {
33983399
3399fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {3400fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3400 const pt = func.pt;3401 const pt = func.pt;
3401 const mod = pt.zcu;3402 const zcu = pt.zcu;
3402 const ip = &mod.intern_pool;3403 const ip = &zcu.intern_pool;
3403 switch (ty.zigTypeTag(mod)) {3404 switch (ty.zigTypeTag(zcu)) {
3404 .Bool, .ErrorSet => return .{ .imm32 = 0xaaaaaaaa },3405 .Bool, .ErrorSet => return .{ .imm32 = 0xaaaaaaaa },
3405 .Int, .Enum => switch (ty.intInfo(mod).bits) {3406 .Int, .Enum => switch (ty.intInfo(zcu).bits) {
3406 0...32 => return .{ .imm32 = 0xaaaaaaaa },3407 0...32 => return .{ .imm32 = 0xaaaaaaaa },
3407 33...64 => return .{ .imm64 = 0xaaaaaaaaaaaaaaaa },3408 33...64 => return .{ .imm64 = 0xaaaaaaaaaaaaaaaa },
3408 else => unreachable,3409 else => unreachable,
...@@ -3419,8 +3420,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {...@@ -3419,8 +3420,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3419 else => unreachable,3420 else => unreachable,
3420 },3421 },
3421 .Optional => {3422 .Optional => {
3422 const pl_ty = ty.optionalChild(mod);3423 const pl_ty = ty.optionalChild(zcu);
3423 if (ty.optionalReprIsPayload(mod)) {3424 if (ty.optionalReprIsPayload(zcu)) {
3424 return func.emitUndefined(pl_ty);3425 return func.emitUndefined(pl_ty);
3425 }3426 }
3426 return .{ .imm32 = 0xaaaaaaaa };3427 return .{ .imm32 = 0xaaaaaaaa };
...@@ -3429,10 +3430,10 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {...@@ -3429,10 +3430,10 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3429 return .{ .imm32 = 0xaaaaaaaa };3430 return .{ .imm32 = 0xaaaaaaaa };
3430 },3431 },
3431 .Struct => {3432 .Struct => {
3432 const packed_struct = mod.typeToPackedStruct(ty).?;3433 const packed_struct = zcu.typeToPackedStruct(ty).?;
3433 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)));3434 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)));
3434 },3435 },
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)}),
3436 }3437 }
3437}3438}
34383439
...@@ -3441,8 +3442,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {...@@ -3441,8 +3442,8 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3441/// as an integer value.3442/// as an integer value.
3442fn valueAsI32(func: *const CodeGen, val: Value) i32 {3443fn valueAsI32(func: *const CodeGen, val: Value) i32 {
3443 const pt = func.pt;3444 const pt = func.pt;
3444 const mod = pt.zcu;3445 const zcu = pt.zcu;
3445 const ip = &mod.intern_pool;3446 const ip = &zcu.intern_pool;
34463447
3447 switch (val.toIntern()) {3448 switch (val.toIntern()) {
3448 .bool_true => return 1,3449 .bool_true => return 1,
...@@ -3465,12 +3466,13 @@ fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, pt: Zcu.PerThread...@@ -3465,12 +3466,13 @@ fn intIndexAsI32(ip: *const InternPool, int: InternPool.Index, pt: Zcu.PerThread
3465}3466}
34663467
3467fn intStorageAsI32(storage: InternPool.Key.Int.Storage, pt: Zcu.PerThread) i32 {3468fn intStorageAsI32(storage: InternPool.Key.Int.Storage, pt: Zcu.PerThread) i32 {
3469 const zcu = pt.zcu;
3468 return switch (storage) {3470 return switch (storage) {
3469 .i64 => |x| @as(i32, @intCast(x)),3471 .i64 => |x| @as(i32, @intCast(x)),
3470 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),3472 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
3471 .big_int => unreachable,3473 .big_int => unreachable,
3472 .lazy_align => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiAlignment(pt).toByteUnits() orelse 0)))),3474 .lazy_align => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiAlignment(zcu).toByteUnits() orelse 0)))),
3473 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiSize(pt))))),3475 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiSize(zcu))))),
3474 };3476 };
3475}3477}
34763478
...@@ -3599,10 +3601,10 @@ fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) In...@@ -3599,10 +3601,10 @@ fn airCmp(func: *CodeGen, inst: Air.Inst.Index, op: std.math.CompareOperator) In
3599fn cmp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOperator) InnerError!WValue {3601fn cmp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareOperator) InnerError!WValue {
3600 assert(!(lhs != .stack and rhs == .stack));3602 assert(!(lhs != .stack and rhs == .stack));
3601 const pt = func.pt;3603 const pt = func.pt;
3602 const mod = pt.zcu;3604 const zcu = pt.zcu;
3603 if (ty.zigTypeTag(mod) == .Optional and !ty.optionalReprIsPayload(mod)) {3605 if (ty.zigTypeTag(zcu) == .Optional and !ty.optionalReprIsPayload(zcu)) {
3604 const payload_ty = ty.optionalChild(mod);3606 const payload_ty = ty.optionalChild(zcu);
3605 if (payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {3607 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3606 // When we hit this case, we must check the value of optionals3608 // When we hit this case, we must check the value of optionals
3607 // that are not pointers. This means first checking against non-null for3609 // that are not pointers. This means first checking against non-null for
3608 // both lhs and rhs, as well as checking the payload are matching of lhs and rhs3610 // 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...@@ -3616,10 +3618,10 @@ fn cmp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareO
36163618
3617 const signedness: std.builtin.Signedness = blk: {3619 const signedness: std.builtin.Signedness = blk: {
3618 // by default we tell the operand type is unsigned (i.e. bools and enum values)3620 // 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
3621 // incase of an actual integer, we emit the correct signedness3623 // incase of an actual integer, we emit the correct signedness
3622 break :blk ty.intInfo(mod).signedness;3624 break :blk ty.intInfo(zcu).signedness;
3623 };3625 };
36243626
3625 // ensure that when we compare pointers, we emit3627 // ensure that when we compare pointers, we emit
...@@ -3708,12 +3710,12 @@ fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3708,12 +3710,12 @@ fn airCmpLtErrorsLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3708}3710}
37093711
3710fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3712fn airBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3711 const pt = func.pt;3713 const zcu = func.pt.zcu;
3712 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;3714 const br = func.air.instructions.items(.data)[@intFromEnum(inst)].br;
3713 const block = func.blocks.get(br.block_inst).?;3715 const block = func.blocks.get(br.block_inst).?;
37143716
3715 // if operand has codegen bits we should break with a value3717 // 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)) {
3717 const operand = try func.resolveInst(br.operand);3719 const operand = try func.resolveInst(br.operand);
3718 try func.lowerToStack(operand);3720 try func.lowerToStack(operand);
37193721
...@@ -3736,17 +3738,17 @@ fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3736,17 +3738,17 @@ fn airNot(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3736 const operand = try func.resolveInst(ty_op.operand);3738 const operand = try func.resolveInst(ty_op.operand);
3737 const operand_ty = func.typeOf(ty_op.operand);3739 const operand_ty = func.typeOf(ty_op.operand);
3738 const pt = func.pt;3740 const pt = func.pt;
3739 const mod = pt.zcu;3741 const zcu = pt.zcu;
37403742
3741 const result = result: {3743 const result = result: {
3742 if (operand_ty.zigTypeTag(mod) == .Bool) {3744 if (operand_ty.zigTypeTag(zcu) == .Bool) {
3743 try func.emitWValue(operand);3745 try func.emitWValue(operand);
3744 try func.addTag(.i32_eqz);3746 try func.addTag(.i32_eqz);
3745 const not_tmp = try func.allocLocal(operand_ty);3747 const not_tmp = try func.allocLocal(operand_ty);
3746 try func.addLabel(.local_set, not_tmp.local.value);3748 try func.addLabel(.local_set, not_tmp.local.value);
3747 break :result not_tmp;3749 break :result not_tmp;
3748 } else {3750 } else {
3749 const int_info = operand_ty.intInfo(mod);3751 const int_info = operand_ty.intInfo(zcu);
3750 const wasm_bits = toWasmBits(int_info.bits) orelse {3752 const wasm_bits = toWasmBits(int_info.bits) orelse {
3751 return func.fail("TODO: Implement binary NOT for {}", .{operand_ty.fmt(pt)});3753 return func.fail("TODO: Implement binary NOT for {}", .{operand_ty.fmt(pt)});
3752 };3754 };
...@@ -3816,14 +3818,14 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3816,14 +3818,14 @@ fn airUnreachable(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38163818
3817fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3819fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3818 const pt = func.pt;3820 const pt = func.pt;
3819 const mod = pt.zcu;3821 const zcu = pt.zcu;
3820 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3822 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3821 const operand = try func.resolveInst(ty_op.operand);3823 const operand = try func.resolveInst(ty_op.operand);
3822 const wanted_ty = func.typeOfIndex(inst);3824 const wanted_ty = func.typeOfIndex(inst);
3823 const given_ty = func.typeOf(ty_op.operand);3825 const given_ty = func.typeOf(ty_op.operand);
38243826
3825 const bit_size = given_ty.bitSize(pt);3827 const bit_size = given_ty.bitSize(zcu);
3826 const needs_wrapping = (given_ty.isSignedInt(mod) != wanted_ty.isSignedInt(mod)) and3828 const needs_wrapping = (given_ty.isSignedInt(zcu) != wanted_ty.isSignedInt(zcu)) and
3827 bit_size != 32 and bit_size != 64 and bit_size != 128;3829 bit_size != 32 and bit_size != 64 and bit_size != 128;
38283830
3829 const result = result: {3831 const result = result: {
...@@ -3860,12 +3862,12 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3860,12 +3862,12 @@ fn airBitcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
38603862
3861fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) InnerError!WValue {3863fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) InnerError!WValue {
3862 const pt = func.pt;3864 const pt = func.pt;
3863 const mod = pt.zcu;3865 const zcu = pt.zcu;
3864 // if we bitcast a float to or from an integer we must use the 'reinterpret' instruction3866 // if we bitcast a float to or from an integer we must use the 'reinterpret' instruction
3865 if (!(wanted_ty.isAnyFloat() or given_ty.isAnyFloat())) return operand;3867 if (!(wanted_ty.isAnyFloat() or given_ty.isAnyFloat())) return operand;
3866 if (wanted_ty.ip_index == .f16_type or given_ty.ip_index == .f16_type) return operand;3868 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;3869 if (wanted_ty.bitSize(zcu) > 64) return operand;
3868 assert((wanted_ty.isInt(mod) and given_ty.isAnyFloat()) or (wanted_ty.isAnyFloat() and given_ty.isInt(mod)));3870 assert((wanted_ty.isInt(zcu) and given_ty.isAnyFloat()) or (wanted_ty.isAnyFloat() and given_ty.isInt(zcu)));
38693871
3870 const opcode = buildOpcode(.{3872 const opcode = buildOpcode(.{
3871 .op = .reinterpret,3873 .op = .reinterpret,
...@@ -3879,24 +3881,24 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn...@@ -3879,24 +3881,24 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
38793881
3880fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3882fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3881 const pt = func.pt;3883 const pt = func.pt;
3882 const mod = pt.zcu;3884 const zcu = pt.zcu;
3883 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3885 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3884 const extra = func.air.extraData(Air.StructField, ty_pl.payload);3886 const extra = func.air.extraData(Air.StructField, ty_pl.payload);
38853887
3886 const struct_ptr = try func.resolveInst(extra.data.struct_operand);3888 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
3887 const struct_ptr_ty = func.typeOf(extra.data.struct_operand);3889 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);
3889 const result = try func.structFieldPtr(inst, extra.data.struct_operand, struct_ptr, struct_ptr_ty, struct_ty, extra.data.field_index);3891 const result = try func.structFieldPtr(inst, extra.data.struct_operand, struct_ptr, struct_ptr_ty, struct_ty, extra.data.field_index);
3890 return func.finishAir(inst, result, &.{extra.data.struct_operand});3892 return func.finishAir(inst, result, &.{extra.data.struct_operand});
3891}3893}
38923894
3893fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {3895fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
3894 const pt = func.pt;3896 const pt = func.pt;
3895 const mod = pt.zcu;3897 const zcu = pt.zcu;
3896 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3898 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3897 const struct_ptr = try func.resolveInst(ty_op.operand);3899 const struct_ptr = try func.resolveInst(ty_op.operand);
3898 const struct_ptr_ty = func.typeOf(ty_op.operand);3900 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
3901 const result = try func.structFieldPtr(inst, ty_op.operand, struct_ptr, struct_ptr_ty, struct_ty, index);3903 const result = try func.structFieldPtr(inst, ty_op.operand, struct_ptr, struct_ptr_ty, struct_ty, index);
3902 return func.finishAir(inst, result, &.{ty_op.operand});3904 return func.finishAir(inst, result, &.{ty_op.operand});
...@@ -3912,23 +3914,23 @@ fn structFieldPtr(...@@ -3912,23 +3914,23 @@ fn structFieldPtr(
3912 index: u32,3914 index: u32,
3913) InnerError!WValue {3915) InnerError!WValue {
3914 const pt = func.pt;3916 const pt = func.pt;
3915 const mod = pt.zcu;3917 const zcu = pt.zcu;
3916 const result_ty = func.typeOfIndex(inst);3918 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)) {3921 const offset = switch (struct_ty.containerLayout(zcu)) {
3920 .@"packed" => switch (struct_ty.zigTypeTag(mod)) {3922 .@"packed" => switch (struct_ty.zigTypeTag(zcu)) {
3921 .Struct => offset: {3923 .Struct => offset: {
3922 if (result_ty.ptrInfo(mod).packed_offset.host_size != 0) {3924 if (result_ty.ptrInfo(zcu).packed_offset.host_size != 0) {
3923 break :offset @as(u32, 0);3925 break :offset @as(u32, 0);
3924 }3926 }
3925 const struct_type = mod.typeToStruct(struct_ty).?;3927 const struct_type = zcu.typeToStruct(struct_ty).?;
3926 break :offset @divExact(pt.structPackedFieldBitOffset(struct_type, index) + struct_ptr_ty_info.packed_offset.bit_offset, 8);3928 break :offset @divExact(pt.structPackedFieldBitOffset(struct_type, index) + struct_ptr_ty_info.packed_offset.bit_offset, 8);
3927 },3929 },
3928 .Union => 0,3930 .Union => 0,
3929 else => unreachable,3931 else => unreachable,
3930 },3932 },
3931 else => struct_ty.structFieldOffset(index, pt),3933 else => struct_ty.structFieldOffset(index, zcu),
3932 };3934 };
3933 // save a load and store when we can simply reuse the operand3935 // save a load and store when we can simply reuse the operand
3934 if (offset == 0) {3936 if (offset == 0) {
...@@ -3944,24 +3946,24 @@ fn structFieldPtr(...@@ -3944,24 +3946,24 @@ fn structFieldPtr(
39443946
3945fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {3947fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3946 const pt = func.pt;3948 const pt = func.pt;
3947 const mod = pt.zcu;3949 const zcu = pt.zcu;
3948 const ip = &mod.intern_pool;3950 const ip = &zcu.intern_pool;
3949 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3951 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3950 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;3952 const struct_field = func.air.extraData(Air.StructField, ty_pl.payload).data;
39513953
3952 const struct_ty = func.typeOf(struct_field.struct_operand);3954 const struct_ty = func.typeOf(struct_field.struct_operand);
3953 const operand = try func.resolveInst(struct_field.struct_operand);3955 const operand = try func.resolveInst(struct_field.struct_operand);
3954 const field_index = struct_field.field_index;3956 const field_index = struct_field.field_index;
3955 const field_ty = struct_ty.structFieldType(field_index, mod);3957 const field_ty = struct_ty.fieldType(field_index, zcu);
3956 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) return func.finishAir(inst, .none, &.{struct_field.struct_operand});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)) {3960 const result: WValue = switch (struct_ty.containerLayout(zcu)) {
3959 .@"packed" => switch (struct_ty.zigTypeTag(mod)) {3961 .@"packed" => switch (struct_ty.zigTypeTag(zcu)) {
3960 .Struct => result: {3962 .Struct => result: {
3961 const packed_struct = mod.typeToPackedStruct(struct_ty).?;3963 const packed_struct = zcu.typeToPackedStruct(struct_ty).?;
3962 const offset = pt.structPackedFieldBitOffset(packed_struct, field_index);3964 const offset = pt.structPackedFieldBitOffset(packed_struct, field_index);
3963 const backing_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));3965 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 {
3965 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});3967 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});
3966 };3968 };
3967 const const_wvalue: WValue = if (wasm_bits == 32)3969 const const_wvalue: WValue = if (wasm_bits == 32)
...@@ -3977,16 +3979,16 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3977,16 +3979,16 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3977 else3979 else
3978 try func.binOp(operand, const_wvalue, backing_ty, .shr);3980 try func.binOp(operand, const_wvalue, backing_ty, .shr);
39793981
3980 if (field_ty.zigTypeTag(mod) == .Float) {3982 if (field_ty.zigTypeTag(zcu) == .Float) {
3981 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));3983 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
3982 const truncated = try func.trunc(shifted_value, int_type, backing_ty);3984 const truncated = try func.trunc(shifted_value, int_type, backing_ty);
3983 break :result try func.bitcast(field_ty, int_type, truncated);3985 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) {
3985 // In this case we do not have to perform any transformations,3987 // In this case we do not have to perform any transformations,
3986 // we can simply reuse the operand.3988 // we can simply reuse the operand.
3987 break :result func.reuseOperand(struct_field.struct_operand, operand);3989 break :result func.reuseOperand(struct_field.struct_operand, operand);
3988 } else if (field_ty.isPtrAtRuntime(mod)) {3990 } else if (field_ty.isPtrAtRuntime(zcu)) {
3989 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));3991 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
3990 break :result try func.trunc(shifted_value, int_type, backing_ty);3992 break :result try func.trunc(shifted_value, int_type, backing_ty);
3991 }3993 }
3992 break :result try func.trunc(shifted_value, field_ty, backing_ty);3994 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 {...@@ -4002,13 +4004,13 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4002 }4004 }
4003 }4005 }
40044006
4005 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(struct_ty.bitSize(pt))));4007 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(struct_ty.bitSize(zcu))));
4006 if (field_ty.zigTypeTag(mod) == .Float) {4008 if (field_ty.zigTypeTag(zcu) == .Float) {
4007 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));4009 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
4008 const truncated = try func.trunc(operand, int_type, union_int_type);4010 const truncated = try func.trunc(operand, int_type, union_int_type);
4009 break :result try func.bitcast(field_ty, int_type, truncated);4011 break :result try func.bitcast(field_ty, int_type, truncated);
4010 } else if (field_ty.isPtrAtRuntime(mod)) {4012 } else if (field_ty.isPtrAtRuntime(zcu)) {
4011 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(pt))));4013 const int_type = try pt.intType(.unsigned, @as(u16, @intCast(field_ty.bitSize(zcu))));
4012 break :result try func.trunc(operand, int_type, union_int_type);4014 break :result try func.trunc(operand, int_type, union_int_type);
4013 }4015 }
4014 break :result try func.trunc(operand, field_ty, union_int_type);4016 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 {...@@ -4016,7 +4018,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4016 else => unreachable,4018 else => unreachable,
4017 },4019 },
4018 else => result: {4020 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 {
4020 return func.fail("Field type '{}' too big to fit into stack frame", .{field_ty.fmt(pt)});4022 return func.fail("Field type '{}' too big to fit into stack frame", .{field_ty.fmt(pt)});
4021 };4023 };
4022 if (isByRef(field_ty, pt, func.target.*)) {4024 if (isByRef(field_ty, pt, func.target.*)) {
...@@ -4036,7 +4038,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4036,7 +4038,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
40364038
4037fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4039fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4038 const pt = func.pt;4040 const pt = func.pt;
4039 const mod = pt.zcu;4041 const zcu = pt.zcu;
4040 // result type is always 'noreturn'4042 // result type is always 'noreturn'
4041 const blocktype = wasm.block_empty;4043 const blocktype = wasm.block_empty;
4042 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;4044 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 {...@@ -4093,7 +4095,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4093 // When the target is an integer size larger than u32, we have no way to use the value4095 // When the target is an integer size larger than u32, we have no way to use the value
4094 // as an index, therefore we also use an if/else-chain for those cases.4096 // as an index, therefore we also use an if/else-chain for those cases.
4095 // TODO: Benchmark this to find a proper value, LLVM seems to draw the line at '40~45'.4097 // 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
4098 const else_body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra_index..][0..switch_br.data.else_body_len]);4100 const else_body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra_index..][0..switch_br.data.else_body_len]);
4099 const has_else_body = else_body.len != 0;4101 const has_else_body = else_body.len != 0;
...@@ -4138,7 +4140,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4138,7 +4140,7 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4138 // for errors that are not present in any branch. This is fine as this default4140 // for errors that are not present in any branch. This is fine as this default
4139 // case will never be hit for those cases but we do save runtime cost and size4141 // case will never be hit for those cases but we do save runtime cost and size
4140 // by using a jump table for this instead of if-else chains.4142 // 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;
4142 };4144 };
4143 func.mir_extra.appendAssumeCapacity(idx);4145 func.mir_extra.appendAssumeCapacity(idx);
4144 } else if (has_else_body) {4146 } else if (has_else_body) {
...@@ -4149,10 +4151,10 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4149,10 +4151,10 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
41494151
4150 const signedness: std.builtin.Signedness = blk: {4152 const signedness: std.builtin.Signedness = blk: {
4151 // by default we tell the operand type is unsigned (i.e. bools and enum values)4153 // 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
4154 // incase of an actual integer, we emit the correct signedness4156 // 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;
4156 };4158 };
41574159
4158 try func.branches.ensureUnusedCapacity(func.gpa, case_list.items.len + @intFromBool(has_else_body));4160 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 {...@@ -4217,14 +4219,14 @@ fn airSwitchBr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42174219
4218fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {4220fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!void {
4219 const pt = func.pt;4221 const pt = func.pt;
4220 const mod = pt.zcu;4222 const zcu = pt.zcu;
4221 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4223 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4222 const operand = try func.resolveInst(un_op);4224 const operand = try func.resolveInst(un_op);
4223 const err_union_ty = func.typeOf(un_op);4225 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
4226 const result: WValue = result: {4228 const result: WValue = result: {
4227 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {4229 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
4228 switch (opcode) {4230 switch (opcode) {
4229 .i32_ne => break :result .{ .imm32 = 0 },4231 .i32_ne => break :result .{ .imm32 = 0 },
4230 .i32_eq => break :result .{ .imm32 = 1 },4232 .i32_eq => break :result .{ .imm32 = 1 },
...@@ -4233,10 +4235,10 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro...@@ -4233,10 +4235,10 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
4233 }4235 }
42344236
4235 try func.emitWValue(operand);4237 try func.emitWValue(operand);
4236 if (pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {4238 if (pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4237 try func.addMemArg(.i32_load16_u, .{4239 try func.addMemArg(.i32_load16_u, .{
4238 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, pt))),4240 .offset = operand.offset() + @as(u32, @intCast(errUnionErrorOffset(pl_ty, zcu))),
4239 .alignment = @intCast(Type.anyerror.abiAlignment(pt).toByteUnits().?),4241 .alignment = @intCast(Type.anyerror.abiAlignment(zcu).toByteUnits().?),
4240 });4242 });
4241 }4243 }
42424244
...@@ -4250,23 +4252,23 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro...@@ -4250,23 +4252,23 @@ fn airIsErr(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerErro
42504252
4251fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {4253fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
4252 const pt = func.pt;4254 const pt = func.pt;
4253 const mod = pt.zcu;4255 const zcu = pt.zcu;
4254 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4256 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
42554257
4256 const operand = try func.resolveInst(ty_op.operand);4258 const operand = try func.resolveInst(ty_op.operand);
4257 const op_ty = func.typeOf(ty_op.operand);4259 const op_ty = func.typeOf(ty_op.operand);
4258 const err_ty = if (op_is_ptr) op_ty.childType(mod) else op_ty;4260 const err_ty = if (op_is_ptr) op_ty.childType(zcu) else op_ty;
4259 const payload_ty = err_ty.errorUnionPayload(mod);4261 const payload_ty = err_ty.errorUnionPayload(zcu);
42604262
4261 const result: WValue = result: {4263 const result: WValue = result: {
4262 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4263 if (op_is_ptr) {4265 if (op_is_ptr) {
4264 break :result func.reuseOperand(ty_op.operand, operand);4266 break :result func.reuseOperand(ty_op.operand, operand);
4265 }4267 }
4266 break :result .none;4268 break :result .none;
4267 }4269 }
42684270
4269 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, pt)));4271 const pl_offset = @as(u32, @intCast(errUnionPayloadOffset(payload_ty, zcu)));
4270 if (op_is_ptr or isByRef(payload_ty, pt, func.target.*)) {4272 if (op_is_ptr or isByRef(payload_ty, pt, func.target.*)) {
4271 break :result try func.buildPointerOffset(operand, pl_offset, .new);4273 break :result try func.buildPointerOffset(operand, pl_offset, .new);
4272 }4274 }
...@@ -4278,30 +4280,30 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo...@@ -4278,30 +4280,30 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
42784280
4279fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {4281fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool) InnerError!void {
4280 const pt = func.pt;4282 const pt = func.pt;
4281 const mod = pt.zcu;4283 const zcu = pt.zcu;
4282 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4284 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
42834285
4284 const operand = try func.resolveInst(ty_op.operand);4286 const operand = try func.resolveInst(ty_op.operand);
4285 const op_ty = func.typeOf(ty_op.operand);4287 const op_ty = func.typeOf(ty_op.operand);
4286 const err_ty = if (op_is_ptr) op_ty.childType(mod) else op_ty;4288 const err_ty = if (op_is_ptr) op_ty.childType(zcu) else op_ty;
4287 const payload_ty = err_ty.errorUnionPayload(mod);4289 const payload_ty = err_ty.errorUnionPayload(zcu);
42884290
4289 const result: WValue = result: {4291 const result: WValue = result: {
4290 if (err_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {4292 if (err_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
4291 break :result .{ .imm32 = 0 };4293 break :result .{ .imm32 = 0 };
4292 }4294 }
42934295
4294 if (op_is_ptr or !payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4296 if (op_is_ptr or !payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4295 break :result func.reuseOperand(ty_op.operand, operand);4297 break :result func.reuseOperand(ty_op.operand, operand);
4296 }4298 }
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)));
4299 };4301 };
4300 return func.finishAir(inst, result, &.{ty_op.operand});4302 return func.finishAir(inst, result, &.{ty_op.operand});
4301}4303}
43024304
4303fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4305fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4304 const pt = func.pt;4306 const zcu = func.pt.zcu;
4305 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4307 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
43064308
4307 const operand = try func.resolveInst(ty_op.operand);4309 const operand = try func.resolveInst(ty_op.operand);
...@@ -4309,18 +4311,18 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void...@@ -4309,18 +4311,18 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
43094311
4310 const pl_ty = func.typeOf(ty_op.operand);4312 const pl_ty = func.typeOf(ty_op.operand);
4311 const result = result: {4313 const result = result: {
4312 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {4314 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4313 break :result func.reuseOperand(ty_op.operand, operand);4315 break :result func.reuseOperand(ty_op.operand, operand);
4314 }4316 }
43154317
4316 const err_union = try func.allocStack(err_ty);4318 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);
4318 try func.store(payload_ptr, operand, pl_ty, 0);4320 try func.store(payload_ptr, operand, pl_ty, 0);
43194321
4320 // ensure we also write '0' to the error part, so any present stack value gets overwritten by it.4322 // ensure we also write '0' to the error part, so any present stack value gets overwritten by it.
4321 try func.emitWValue(err_union);4323 try func.emitWValue(err_union);
4322 try func.addImm32(0);4324 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));
4324 try func.addMemArg(.i32_store16, .{4326 try func.addMemArg(.i32_store16, .{
4325 .offset = err_union.offset() + err_val_offset,4327 .offset = err_union.offset() + err_val_offset,
4326 .alignment = 2,4328 .alignment = 2,
...@@ -4332,25 +4334,25 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void...@@ -4332,25 +4334,25 @@ fn airWrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void
43324334
4333fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4335fn airWrapErrUnionErr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4334 const pt = func.pt;4336 const pt = func.pt;
4335 const mod = pt.zcu;4337 const zcu = pt.zcu;
4336 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4338 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
43374339
4338 const operand = try func.resolveInst(ty_op.operand);4340 const operand = try func.resolveInst(ty_op.operand);
4339 const err_ty = ty_op.ty.toType();4341 const err_ty = ty_op.ty.toType();
4340 const pl_ty = err_ty.errorUnionPayload(mod);4342 const pl_ty = err_ty.errorUnionPayload(zcu);
43414343
4342 const result = result: {4344 const result = result: {
4343 if (!pl_ty.hasRuntimeBitsIgnoreComptime(pt)) {4345 if (!pl_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4344 break :result func.reuseOperand(ty_op.operand, operand);4346 break :result func.reuseOperand(ty_op.operand, operand);
4345 }4347 }
43464348
4347 const err_union = try func.allocStack(err_ty);4349 const err_union = try func.allocStack(err_ty);
4348 // store error value4350 // 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
4351 // write 'undefined' to the payload4353 // write 'undefined' to the payload
4352 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, pt))), .new);4354 const payload_ptr = try func.buildPointerOffset(err_union, @as(u32, @intCast(errUnionPayloadOffset(pl_ty, zcu))), .new);
4353 const len = @as(u32, @intCast(err_ty.errorUnionPayload(mod).abiSize(pt)));4355 const len = @as(u32, @intCast(err_ty.errorUnionPayload(zcu).abiSize(zcu)));
4354 try func.memset(Type.u8, payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaa });4356 try func.memset(Type.u8, payload_ptr, .{ .imm32 = len }, .{ .imm32 = 0xaa });
43554357
4356 break :result err_union;4358 break :result err_union;
...@@ -4365,16 +4367,16 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4365,16 +4367,16 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4365 const operand = try func.resolveInst(ty_op.operand);4367 const operand = try func.resolveInst(ty_op.operand);
4366 const operand_ty = func.typeOf(ty_op.operand);4368 const operand_ty = func.typeOf(ty_op.operand);
4367 const pt = func.pt;4369 const pt = func.pt;
4368 const mod = pt.zcu;4370 const zcu = pt.zcu;
4369 if (ty.zigTypeTag(mod) == .Vector or operand_ty.zigTypeTag(mod) == .Vector) {4371 if (ty.zigTypeTag(zcu) == .Vector or operand_ty.zigTypeTag(zcu) == .Vector) {
4370 return func.fail("todo Wasm intcast for vectors", .{});4372 return func.fail("todo Wasm intcast for vectors", .{});
4371 }4373 }
4372 if (ty.abiSize(pt) > 16 or operand_ty.abiSize(pt) > 16) {4374 if (ty.abiSize(zcu) > 16 or operand_ty.abiSize(zcu) > 16) {
4373 return func.fail("todo Wasm intcast for bitsize > 128", .{});4375 return func.fail("todo Wasm intcast for bitsize > 128", .{});
4374 }4376 }
43754377
4376 const op_bits = toWasmBits(@intCast(operand_ty.bitSize(pt))).?;4378 const op_bits = toWasmBits(@intCast(operand_ty.bitSize(zcu))).?;
4377 const wanted_bits = toWasmBits(@intCast(ty.bitSize(pt))).?;4379 const wanted_bits = toWasmBits(@intCast(ty.bitSize(zcu))).?;
4378 const result = if (op_bits == wanted_bits)4380 const result = if (op_bits == wanted_bits)
4379 func.reuseOperand(ty_op.operand, operand)4381 func.reuseOperand(ty_op.operand, operand)
4380 else4382 else
...@@ -4389,9 +4391,9 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4389,9 +4391,9 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4389/// NOTE: May leave the result on the top of the stack.4391/// NOTE: May leave the result on the top of the stack.
4390fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {4392fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerError!WValue {
4391 const pt = func.pt;4393 const pt = func.pt;
4392 const mod = pt.zcu;4394 const zcu = pt.zcu;
4393 const given_bitsize = @as(u16, @intCast(given.bitSize(pt)));4395 const given_bitsize = @as(u16, @intCast(given.bitSize(zcu)));
4394 const wanted_bitsize = @as(u16, @intCast(wanted.bitSize(pt)));4396 const wanted_bitsize = @as(u16, @intCast(wanted.bitSize(zcu)));
4395 assert(given_bitsize <= 128);4397 assert(given_bitsize <= 128);
4396 assert(wanted_bitsize <= 128);4398 assert(wanted_bitsize <= 128);
43974399
...@@ -4407,7 +4409,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro...@@ -4407,7 +4409,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
4407 return .stack;4409 return .stack;
4408 } else if (op_bits == 32 and wanted_bits == 64) {4410 } else if (op_bits == 32 and wanted_bits == 64) {
4409 try func.emitWValue(operand);4411 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);
4411 return .stack;4413 return .stack;
4412 } else if (wanted_bits == 128) {4414 } else if (wanted_bits == 128) {
4413 // for 128bit integers we store the integer in the virtual stack, rather than a local4415 // 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...@@ -4417,7 +4419,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
4417 // for 32 bit integers, we first coerce the value into a 64 bit integer before storing it4419 // for 32 bit integers, we first coerce the value into a 64 bit integer before storing it
4418 // meaning less store operations are required.4420 // meaning less store operations are required.
4419 const lhs = if (op_bits == 32) blk: {4421 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;
4421 break :blk try (try func.intcast(operand, given, sign_ty)).toLocal(func, sign_ty);4423 break :blk try (try func.intcast(operand, given, sign_ty)).toLocal(func, sign_ty);
4422 } else operand;4424 } else operand;
44234425
...@@ -4425,7 +4427,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro...@@ -4425,7 +4427,7 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
4425 try func.store(.stack, lhs, Type.u64, 0 + stack_ptr.offset());4427 try func.store(.stack, lhs, Type.u64, 0 + stack_ptr.offset());
44264428
4427 // For signed integers we shift lsb by 63 (64bit integer - 1 sign bit) and store remaining value4429 // 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)) {
4429 try func.emitWValue(stack_ptr);4431 try func.emitWValue(stack_ptr);
4430 const shr = try func.binOp(lhs, .{ .imm64 = 63 }, Type.i64, .shr);4432 const shr = try func.binOp(lhs, .{ .imm64 = 63 }, Type.i64, .shr);
4431 try func.store(.stack, shr, Type.u64, 8 + stack_ptr.offset());4433 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...@@ -4439,12 +4441,12 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
44394441
4440fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {4442fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
4441 const pt = func.pt;4443 const pt = func.pt;
4442 const mod = pt.zcu;4444 const zcu = pt.zcu;
4443 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4445 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4444 const operand = try func.resolveInst(un_op);4446 const operand = try func.resolveInst(un_op);
44454447
4446 const op_ty = func.typeOf(un_op);4448 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;
4448 const result = try func.isNull(operand, optional_ty, opcode);4450 const result = try func.isNull(operand, optional_ty, opcode);
4449 return func.finishAir(inst, result, &.{un_op});4451 return func.finishAir(inst, result, &.{un_op});
4450}4452}
...@@ -4453,19 +4455,19 @@ fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind:...@@ -4453,19 +4455,19 @@ fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind:
4453/// NOTE: Leaves the result on the stack4455/// NOTE: Leaves the result on the stack
4454fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcode) InnerError!WValue {4456fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcode) InnerError!WValue {
4455 const pt = func.pt;4457 const pt = func.pt;
4456 const mod = pt.zcu;4458 const zcu = pt.zcu;
4457 try func.emitWValue(operand);4459 try func.emitWValue(operand);
4458 const payload_ty = optional_ty.optionalChild(mod);4460 const payload_ty = optional_ty.optionalChild(zcu);
4459 if (!optional_ty.optionalReprIsPayload(mod)) {4461 if (!optional_ty.optionalReprIsPayload(zcu)) {
4460 // When payload is zero-bits, we can treat operand as a value, rather than4462 // When payload is zero-bits, we can treat operand as a value, rather than
4461 // a pointer to the stack value4463 // a pointer to the stack value
4462 if (payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4464 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4463 const offset = std.math.cast(u32, payload_ty.abiSize(pt)) orelse {4465 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
4464 return func.fail("Optional type {} too big to fit into stack frame", .{optional_ty.fmt(pt)});4466 return func.fail("Optional type {} too big to fit into stack frame", .{optional_ty.fmt(pt)});
4465 };4467 };
4466 try func.addMemArg(.i32_load8_u, .{ .offset = operand.offset() + offset, .alignment = 1 });4468 try func.addMemArg(.i32_load8_u, .{ .offset = operand.offset() + offset, .alignment = 1 });
4467 }4469 }
4468 } else if (payload_ty.isSlice(mod)) {4470 } else if (payload_ty.isSlice(zcu)) {
4469 switch (func.arch()) {4471 switch (func.arch()) {
4470 .wasm32 => try func.addMemArg(.i32_load, .{ .offset = operand.offset(), .alignment = 4 }),4472 .wasm32 => try func.addMemArg(.i32_load, .{ .offset = operand.offset(), .alignment = 4 }),
4471 .wasm64 => try func.addMemArg(.i64_load, .{ .offset = operand.offset(), .alignment = 8 }),4473 .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...@@ -4482,17 +4484,17 @@ fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcod
44824484
4483fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4485fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4484 const pt = func.pt;4486 const pt = func.pt;
4485 const mod = pt.zcu;4487 const zcu = pt.zcu;
4486 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4488 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4487 const opt_ty = func.typeOf(ty_op.operand);4489 const opt_ty = func.typeOf(ty_op.operand);
4488 const payload_ty = func.typeOfIndex(inst);4490 const payload_ty = func.typeOfIndex(inst);
4489 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4491 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4490 return func.finishAir(inst, .none, &.{ty_op.operand});4492 return func.finishAir(inst, .none, &.{ty_op.operand});
4491 }4493 }
44924494
4493 const result = result: {4495 const result = result: {
4494 const operand = try func.resolveInst(ty_op.operand);4496 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
4497 if (isByRef(payload_ty, pt, func.target.*)) {4499 if (isByRef(payload_ty, pt, func.target.*)) {
4498 break :result try func.buildPointerOffset(operand, 0, .new);4500 break :result try func.buildPointerOffset(operand, 0, .new);
...@@ -4505,14 +4507,14 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4505,14 +4507,14 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45054507
4506fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4508fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4507 const pt = func.pt;4509 const pt = func.pt;
4508 const mod = pt.zcu;4510 const zcu = pt.zcu;
4509 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4511 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4510 const operand = try func.resolveInst(ty_op.operand);4512 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
4513 const result = result: {4515 const result = result: {
4514 const payload_ty = opt_ty.optionalChild(mod);4516 const payload_ty = opt_ty.optionalChild(zcu);
4515 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt) or opt_ty.optionalReprIsPayload(mod)) {4517 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu) or opt_ty.optionalReprIsPayload(zcu)) {
4516 break :result func.reuseOperand(ty_op.operand, operand);4518 break :result func.reuseOperand(ty_op.operand, operand);
4517 }4519 }
45184520
...@@ -4523,20 +4525,20 @@ fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4523,20 +4525,20 @@ fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45234525
4524fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4526fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4525 const pt = func.pt;4527 const pt = func.pt;
4526 const mod = pt.zcu;4528 const zcu = pt.zcu;
4527 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4529 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4528 const operand = try func.resolveInst(ty_op.operand);4530 const operand = try func.resolveInst(ty_op.operand);
4529 const opt_ty = func.typeOf(ty_op.operand).childType(mod);4531 const opt_ty = func.typeOf(ty_op.operand).childType(zcu);
4530 const payload_ty = opt_ty.optionalChild(mod);4532 const payload_ty = opt_ty.optionalChild(zcu);
4531 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4533 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4532 return func.fail("TODO: Implement OptionalPayloadPtrSet for optional with zero-sized type {}", .{payload_ty.fmtDebug()});4534 return func.fail("TODO: Implement OptionalPayloadPtrSet for optional with zero-sized type {}", .{payload_ty.fmtDebug()});
4533 }4535 }
45344536
4535 if (opt_ty.optionalReprIsPayload(mod)) {4537 if (opt_ty.optionalReprIsPayload(zcu)) {
4536 return func.finishAir(inst, operand, &.{ty_op.operand});4538 return func.finishAir(inst, operand, &.{ty_op.operand});
4537 }4539 }
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 {
4540 return func.fail("Optional type {} too big to fit into stack frame", .{opt_ty.fmt(pt)});4542 return func.fail("Optional type {} too big to fit into stack frame", .{opt_ty.fmt(pt)});
4541 };4543 };
45424544
...@@ -4552,10 +4554,10 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4552,10 +4554,10 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4552 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4554 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4553 const payload_ty = func.typeOf(ty_op.operand);4555 const payload_ty = func.typeOf(ty_op.operand);
4554 const pt = func.pt;4556 const pt = func.pt;
4555 const mod = pt.zcu;4557 const zcu = pt.zcu;
45564558
4557 const result = result: {4559 const result = result: {
4558 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4560 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4559 const non_null_bit = try func.allocStack(Type.u1);4561 const non_null_bit = try func.allocStack(Type.u1);
4560 try func.emitWValue(non_null_bit);4562 try func.emitWValue(non_null_bit);
4561 try func.addImm32(1);4563 try func.addImm32(1);
...@@ -4565,10 +4567,10 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4565,10 +4567,10 @@ fn airWrapOptional(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45654567
4566 const operand = try func.resolveInst(ty_op.operand);4568 const operand = try func.resolveInst(ty_op.operand);
4567 const op_ty = func.typeOfIndex(inst);4569 const op_ty = func.typeOfIndex(inst);
4568 if (op_ty.optionalReprIsPayload(mod)) {4570 if (op_ty.optionalReprIsPayload(zcu)) {
4569 break :result func.reuseOperand(ty_op.operand, operand);4571 break :result func.reuseOperand(ty_op.operand, operand);
4570 }4572 }
4571 const offset = std.math.cast(u32, payload_ty.abiSize(pt)) orelse {4573 const offset = std.math.cast(u32, payload_ty.abiSize(zcu)) orelse {
4572 return func.fail("Optional type {} too big to fit into stack frame", .{op_ty.fmt(pt)});4574 return func.fail("Optional type {} too big to fit into stack frame", .{op_ty.fmt(pt)});
4573 };4575 };
45744576
...@@ -4610,14 +4612,14 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4610,14 +4612,14 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46104612
4611fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4613fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4612 const pt = func.pt;4614 const pt = func.pt;
4613 const mod = pt.zcu;4615 const zcu = pt.zcu;
4614 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4616 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
46154617
4616 const slice_ty = func.typeOf(bin_op.lhs);4618 const slice_ty = func.typeOf(bin_op.lhs);
4617 const slice = try func.resolveInst(bin_op.lhs);4619 const slice = try func.resolveInst(bin_op.lhs);
4618 const index = try func.resolveInst(bin_op.rhs);4620 const index = try func.resolveInst(bin_op.rhs);
4619 const elem_ty = slice_ty.childType(mod);4621 const elem_ty = slice_ty.childType(zcu);
4620 const elem_size = elem_ty.abiSize(pt);4622 const elem_size = elem_ty.abiSize(zcu);
46214623
4622 // load pointer onto stack4624 // load pointer onto stack
4623 _ = try func.load(slice, Type.usize, 0);4625 _ = try func.load(slice, Type.usize, 0);
...@@ -4638,12 +4640,12 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4638,12 +4640,12 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
46384640
4639fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4641fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4640 const pt = func.pt;4642 const pt = func.pt;
4641 const mod = pt.zcu;4643 const zcu = pt.zcu;
4642 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4644 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4643 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4645 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
46444646
4645 const elem_ty = ty_pl.ty.toType().childType(mod);4647 const elem_ty = ty_pl.ty.toType().childType(zcu);
4646 const elem_size = elem_ty.abiSize(pt);4648 const elem_size = elem_ty.abiSize(zcu);
46474649
4648 const slice = try func.resolveInst(bin_op.lhs);4650 const slice = try func.resolveInst(bin_op.lhs);
4649 const index = try func.resolveInst(bin_op.rhs);4651 const index = try func.resolveInst(bin_op.rhs);
...@@ -4682,13 +4684,13 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4682,13 +4684,13 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4682 const wanted_ty: Type = ty_op.ty.toType();4684 const wanted_ty: Type = ty_op.ty.toType();
4683 const op_ty = func.typeOf(ty_op.operand);4685 const op_ty = func.typeOf(ty_op.operand);
4684 const pt = func.pt;4686 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) {
4688 return func.fail("TODO: trunc for vectors", .{});4690 return func.fail("TODO: trunc for vectors", .{});
4689 }4691 }
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))
4692 func.reuseOperand(ty_op.operand, operand)4694 func.reuseOperand(ty_op.operand, operand)
4693 else4695 else
4694 try func.trunc(operand, wanted_ty, op_ty);4696 try func.trunc(operand, wanted_ty, op_ty);
...@@ -4700,13 +4702,14 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4700,13 +4702,14 @@ fn airTrunc(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4700/// NOTE: Resulting value is left on the stack.4702/// NOTE: Resulting value is left on the stack.
4701fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) InnerError!WValue {4703fn trunc(func: *CodeGen, operand: WValue, wanted_ty: Type, given_ty: Type) InnerError!WValue {
4702 const pt = func.pt;4704 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)));
4704 if (toWasmBits(given_bits) == null) {4707 if (toWasmBits(given_bits) == null) {
4705 return func.fail("TODO: Implement wasm integer truncation for integer bitsize: {d}", .{given_bits});4708 return func.fail("TODO: Implement wasm integer truncation for integer bitsize: {d}", .{given_bits});
4706 }4709 }
47074710
4708 var result = try func.intcast(operand, given_ty, wanted_ty);4711 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)));
4710 const wasm_bits = toWasmBits(wanted_bits).?;4713 const wasm_bits = toWasmBits(wanted_bits).?;
4711 if (wasm_bits != wanted_bits) {4714 if (wasm_bits != wanted_bits) {
4712 result = try func.wrapOperand(result, wanted_ty);4715 result = try func.wrapOperand(result, wanted_ty);
...@@ -4724,23 +4727,23 @@ fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4724,23 +4727,23 @@ fn airIntFromBool(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47244727
4725fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4728fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4726 const pt = func.pt;4729 const pt = func.pt;
4727 const mod = pt.zcu;4730 const zcu = pt.zcu;
4728 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4731 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
47294732
4730 const operand = try func.resolveInst(ty_op.operand);4733 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);
4732 const slice_ty = ty_op.ty.toType();4735 const slice_ty = ty_op.ty.toType();
47334736
4734 // create a slice on the stack4737 // create a slice on the stack
4735 const slice_local = try func.allocStack(slice_ty);4738 const slice_local = try func.allocStack(slice_ty);
47364739
4737 // store the array ptr in the slice4740 // store the array ptr in the slice
4738 if (array_ty.hasRuntimeBitsIgnoreComptime(pt)) {4741 if (array_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4739 try func.store(slice_local, operand, Type.usize, 0);4742 try func.store(slice_local, operand, Type.usize, 0);
4740 }4743 }
47414744
4742 // store the length of the array in the slice4745 // 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));
4744 try func.store(slice_local, .{ .imm32 = array_len }, Type.usize, func.ptrSize());4747 try func.store(slice_local, .{ .imm32 = array_len }, Type.usize, func.ptrSize());
47454748
4746 return func.finishAir(inst, slice_local, &.{ty_op.operand});4749 return func.finishAir(inst, slice_local, &.{ty_op.operand});
...@@ -4748,11 +4751,11 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4748,11 +4751,11 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47484751
4749fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4752fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4750 const pt = func.pt;4753 const pt = func.pt;
4751 const mod = pt.zcu;4754 const zcu = pt.zcu;
4752 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;4755 const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
4753 const operand = try func.resolveInst(un_op);4756 const operand = try func.resolveInst(un_op);
4754 const ptr_ty = func.typeOf(un_op);4757 const ptr_ty = func.typeOf(un_op);
4755 const result = if (ptr_ty.isSlice(mod))4758 const result = if (ptr_ty.isSlice(zcu))
4756 try func.slicePtr(operand)4759 try func.slicePtr(operand)
4757 else switch (operand) {4760 else switch (operand) {
4758 // for stack offset, return a pointer to this offset.4761 // for stack offset, return a pointer to this offset.
...@@ -4764,17 +4767,17 @@ fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4764,17 +4767,17 @@ fn airIntFromPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47644767
4765fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4768fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4766 const pt = func.pt;4769 const pt = func.pt;
4767 const mod = pt.zcu;4770 const zcu = pt.zcu;
4768 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4771 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
47694772
4770 const ptr_ty = func.typeOf(bin_op.lhs);4773 const ptr_ty = func.typeOf(bin_op.lhs);
4771 const ptr = try func.resolveInst(bin_op.lhs);4774 const ptr = try func.resolveInst(bin_op.lhs);
4772 const index = try func.resolveInst(bin_op.rhs);4775 const index = try func.resolveInst(bin_op.rhs);
4773 const elem_ty = ptr_ty.childType(mod);4776 const elem_ty = ptr_ty.childType(zcu);
4774 const elem_size = elem_ty.abiSize(pt);4777 const elem_size = elem_ty.abiSize(zcu);
47754778
4776 // load pointer onto the stack4779 // load pointer onto the stack
4777 if (ptr_ty.isSlice(mod)) {4780 if (ptr_ty.isSlice(zcu)) {
4778 _ = try func.load(ptr, Type.usize, 0);4781 _ = try func.load(ptr, Type.usize, 0);
4779 } else {4782 } else {
4780 try func.lowerToStack(ptr);4783 try func.lowerToStack(ptr);
...@@ -4796,19 +4799,19 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4796,19 +4799,19 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
47964799
4797fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4800fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4798 const pt = func.pt;4801 const pt = func.pt;
4799 const mod = pt.zcu;4802 const zcu = pt.zcu;
4800 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4803 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4801 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4804 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
48024805
4803 const ptr_ty = func.typeOf(bin_op.lhs);4806 const ptr_ty = func.typeOf(bin_op.lhs);
4804 const elem_ty = ty_pl.ty.toType().childType(mod);4807 const elem_ty = ty_pl.ty.toType().childType(zcu);
4805 const elem_size = elem_ty.abiSize(pt);4808 const elem_size = elem_ty.abiSize(zcu);
48064809
4807 const ptr = try func.resolveInst(bin_op.lhs);4810 const ptr = try func.resolveInst(bin_op.lhs);
4808 const index = try func.resolveInst(bin_op.rhs);4811 const index = try func.resolveInst(bin_op.rhs);
48094812
4810 // load pointer onto the stack4813 // load pointer onto the stack
4811 if (ptr_ty.isSlice(mod)) {4814 if (ptr_ty.isSlice(zcu)) {
4812 _ = try func.load(ptr, Type.usize, 0);4815 _ = try func.load(ptr, Type.usize, 0);
4813 } else {4816 } else {
4814 try func.lowerToStack(ptr);4817 try func.lowerToStack(ptr);
...@@ -4825,16 +4828,16 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4825,16 +4828,16 @@ fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48254828
4826fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {4829fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
4827 const pt = func.pt;4830 const pt = func.pt;
4828 const mod = pt.zcu;4831 const zcu = pt.zcu;
4829 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4832 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4830 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;4833 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
48314834
4832 const ptr = try func.resolveInst(bin_op.lhs);4835 const ptr = try func.resolveInst(bin_op.lhs);
4833 const offset = try func.resolveInst(bin_op.rhs);4836 const offset = try func.resolveInst(bin_op.rhs);
4834 const ptr_ty = func.typeOf(bin_op.lhs);4837 const ptr_ty = func.typeOf(bin_op.lhs);
4835 const pointee_ty = switch (ptr_ty.ptrSize(mod)) {4838 const pointee_ty = switch (ptr_ty.ptrSize(zcu)) {
4836 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type4839 .One => ptr_ty.childType(zcu).childType(zcu), // ptr to array, so get array element type
4837 else => ptr_ty.childType(mod),4840 else => ptr_ty.childType(zcu),
4838 };4841 };
48394842
4840 const valtype = typeToValtype(Type.usize, pt, func.target.*);4843 const valtype = typeToValtype(Type.usize, pt, func.target.*);
...@@ -4843,7 +4846,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -4843,7 +4846,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
48434846
4844 try func.lowerToStack(ptr);4847 try func.lowerToStack(ptr);
4845 try func.emitWValue(offset);4848 try func.emitWValue(offset);
4846 try func.addImm32(@intCast(pointee_ty.abiSize(pt)));4849 try func.addImm32(@intCast(pointee_ty.abiSize(zcu)));
4847 try func.addTag(Mir.Inst.Tag.fromOpcode(mul_opcode));4850 try func.addTag(Mir.Inst.Tag.fromOpcode(mul_opcode));
4848 try func.addTag(Mir.Inst.Tag.fromOpcode(bin_opcode));4851 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 {...@@ -4852,7 +4855,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
48524855
4853fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {4856fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
4854 const pt = func.pt;4857 const pt = func.pt;
4855 const mod = pt.zcu;4858 const zcu = pt.zcu;
4856 if (safety) {4859 if (safety) {
4857 // TODO if the value is undef, write 0xaa bytes to dest4860 // TODO if the value is undef, write 0xaa bytes to dest
4858 } else {4861 } else {
...@@ -4863,16 +4866,16 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void...@@ -4863,16 +4866,16 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
4863 const ptr = try func.resolveInst(bin_op.lhs);4866 const ptr = try func.resolveInst(bin_op.lhs);
4864 const ptr_ty = func.typeOf(bin_op.lhs);4867 const ptr_ty = func.typeOf(bin_op.lhs);
4865 const value = try func.resolveInst(bin_op.rhs);4868 const value = try func.resolveInst(bin_op.rhs);
4866 const len = switch (ptr_ty.ptrSize(mod)) {4869 const len = switch (ptr_ty.ptrSize(zcu)) {
4867 .Slice => try func.sliceLen(ptr),4870 .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))) }),
4869 .C, .Many => unreachable,4872 .C, .Many => unreachable,
4870 };4873 };
48714874
4872 const elem_ty = if (ptr_ty.ptrSize(mod) == .One)4875 const elem_ty = if (ptr_ty.ptrSize(zcu) == .One)
4873 ptr_ty.childType(mod).childType(mod)4876 ptr_ty.childType(zcu).childType(zcu)
4874 else4877 else
4875 ptr_ty.childType(mod);4878 ptr_ty.childType(zcu);
48764879
4877 const dst_ptr = try func.sliceOrArrayPtr(ptr, ptr_ty);4880 const dst_ptr = try func.sliceOrArrayPtr(ptr, ptr_ty);
4878 try func.memset(elem_ty, dst_ptr, len, value);4881 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...@@ -4886,7 +4889,7 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
4886/// we implement it manually.4889/// we implement it manually.
4887fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void {4890fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue) InnerError!void {
4888 const pt = func.pt;4891 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
4891 // When bulk_memory is enabled, we lower it to wasm's memset instruction.4894 // When bulk_memory is enabled, we lower it to wasm's memset instruction.
4892 // If not, we lower it ourselves.4895 // If not, we lower it ourselves.
...@@ -4975,14 +4978,14 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue...@@ -4975,14 +4978,14 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue
49754978
4976fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {4979fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4977 const pt = func.pt;4980 const pt = func.pt;
4978 const mod = pt.zcu;4981 const zcu = pt.zcu;
4979 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4982 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
49804983
4981 const array_ty = func.typeOf(bin_op.lhs);4984 const array_ty = func.typeOf(bin_op.lhs);
4982 const array = try func.resolveInst(bin_op.lhs);4985 const array = try func.resolveInst(bin_op.lhs);
4983 const index = try func.resolveInst(bin_op.rhs);4986 const index = try func.resolveInst(bin_op.rhs);
4984 const elem_ty = array_ty.childType(mod);4987 const elem_ty = array_ty.childType(zcu);
4985 const elem_size = elem_ty.abiSize(pt);4988 const elem_size = elem_ty.abiSize(zcu);
49864989
4987 if (isByRef(array_ty, pt, func.target.*)) {4990 if (isByRef(array_ty, pt, func.target.*)) {
4988 try func.lowerToStack(array);4991 try func.lowerToStack(array);
...@@ -4991,15 +4994,15 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -4991,15 +4994,15 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4991 try func.addTag(.i32_mul);4994 try func.addTag(.i32_mul);
4992 try func.addTag(.i32_add);4995 try func.addTag(.i32_add);
4993 } else {4996 } else {
4994 std.debug.assert(array_ty.zigTypeTag(mod) == .Vector);4997 std.debug.assert(array_ty.zigTypeTag(zcu) == .Vector);
49954998
4996 switch (index) {4999 switch (index) {
4997 inline .imm32, .imm64 => |lane| {5000 inline .imm32, .imm64 => |lane| {
4998 const opcode: wasm.SimdOpcode = switch (elem_ty.bitSize(pt)) {5001 const opcode: wasm.SimdOpcode = switch (elem_ty.bitSize(zcu)) {
4999 8 => if (elem_ty.isSignedInt(mod)) .i8x16_extract_lane_s else .i8x16_extract_lane_u,5002 8 => if (elem_ty.isSignedInt(zcu)) .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,5003 16 => if (elem_ty.isSignedInt(zcu)) .i16x8_extract_lane_s else .i16x8_extract_lane_u,
5001 32 => if (elem_ty.isInt(mod)) .i32x4_extract_lane else .f32x4_extract_lane,5004 32 => if (elem_ty.isInt(zcu)) .i32x4_extract_lane else .f32x4_extract_lane,
5002 64 => if (elem_ty.isInt(mod)) .i64x2_extract_lane else .f64x2_extract_lane,5005 64 => if (elem_ty.isInt(zcu)) .i64x2_extract_lane else .f64x2_extract_lane,
5003 else => unreachable,5006 else => unreachable,
5004 };5007 };
50055008
...@@ -5037,7 +5040,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5037,7 +5040,7 @@ fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50375040
5038fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5041fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5039 const pt = func.pt;5042 const pt = func.pt;
5040 const mod = pt.zcu;5043 const zcu = pt.zcu;
5041 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5044 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50425045
5043 const operand = try func.resolveInst(ty_op.operand);5046 const operand = try func.resolveInst(ty_op.operand);
...@@ -5045,7 +5048,7 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5045,7 +5048,7 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5045 const op_bits = op_ty.floatBits(func.target.*);5048 const op_bits = op_ty.floatBits(func.target.*);
50465049
5047 const dest_ty = func.typeOfIndex(inst);5050 const dest_ty = func.typeOfIndex(inst);
5048 const dest_info = dest_ty.intInfo(mod);5051 const dest_info = dest_ty.intInfo(zcu);
50495052
5050 if (dest_info.bits > 128) {5053 if (dest_info.bits > 128) {
5051 return func.fail("TODO: intFromFloat for integers/floats with bitsize {}", .{dest_info.bits});5054 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 {...@@ -5082,12 +5085,12 @@ fn airIntFromFloat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
50825085
5083fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5086fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5084 const pt = func.pt;5087 const pt = func.pt;
5085 const mod = pt.zcu;5088 const zcu = pt.zcu;
5086 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5089 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
50875090
5088 const operand = try func.resolveInst(ty_op.operand);5091 const operand = try func.resolveInst(ty_op.operand);
5089 const op_ty = func.typeOf(ty_op.operand);5092 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
5092 const dest_ty = func.typeOfIndex(inst);5095 const dest_ty = func.typeOfIndex(inst);
5093 const dest_bits = dest_ty.floatBits(func.target.*);5096 const dest_bits = dest_ty.floatBits(func.target.*);
...@@ -5127,19 +5130,19 @@ fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5127,19 +5130,19 @@ fn airFloatFromInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
51275130
5128fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5131fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5129 const pt = func.pt;5132 const pt = func.pt;
5130 const mod = pt.zcu;5133 const zcu = pt.zcu;
5131 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5134 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5132 const operand = try func.resolveInst(ty_op.operand);5135 const operand = try func.resolveInst(ty_op.operand);
5133 const ty = func.typeOfIndex(inst);5136 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: {
5137 switch (operand) {5140 switch (operand) {
5138 // when the operand lives in the linear memory section, we can directly5141 // when the operand lives in the linear memory section, we can directly
5139 // load and splat the value at once. Meaning we do not first have to load5142 // load and splat the value at once. Meaning we do not first have to load
5140 // the scalar value onto the stack.5143 // the scalar value onto the stack.
5141 .stack_offset, .memory, .memory_offset => {5144 .stack_offset, .memory, .memory_offset => {
5142 const opcode = switch (elem_ty.bitSize(pt)) {5145 const opcode = switch (elem_ty.bitSize(zcu)) {
5143 8 => std.wasm.simdOpcode(.v128_load8_splat),5146 8 => std.wasm.simdOpcode(.v128_load8_splat),
5144 16 => std.wasm.simdOpcode(.v128_load16_splat),5147 16 => std.wasm.simdOpcode(.v128_load16_splat),
5145 32 => std.wasm.simdOpcode(.v128_load32_splat),5148 32 => std.wasm.simdOpcode(.v128_load32_splat),
...@@ -5153,17 +5156,17 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5153,17 +5156,17 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5153 try func.mir_extra.appendSlice(func.gpa, &[_]u32{5156 try func.mir_extra.appendSlice(func.gpa, &[_]u32{
5154 opcode,5157 opcode,
5155 operand.offset(),5158 operand.offset(),
5156 @intCast(elem_ty.abiAlignment(pt).toByteUnits().?),5159 @intCast(elem_ty.abiAlignment(zcu).toByteUnits().?),
5157 });5160 });
5158 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });5161 try func.addInst(.{ .tag = .simd_prefix, .data = .{ .payload = extra_index } });
5159 return func.finishAir(inst, .stack, &.{ty_op.operand});5162 return func.finishAir(inst, .stack, &.{ty_op.operand});
5160 },5163 },
5161 .local => {5164 .local => {
5162 const opcode = switch (elem_ty.bitSize(pt)) {5165 const opcode = switch (elem_ty.bitSize(zcu)) {
5163 8 => std.wasm.simdOpcode(.i8x16_splat),5166 8 => std.wasm.simdOpcode(.i8x16_splat),
5164 16 => std.wasm.simdOpcode(.i16x8_splat),5167 16 => std.wasm.simdOpcode(.i16x8_splat),
5165 32 => if (elem_ty.isInt(mod)) std.wasm.simdOpcode(.i32x4_splat) else std.wasm.simdOpcode(.f32x4_splat),5168 32 => if (elem_ty.isInt(zcu)) 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),5169 64 => if (elem_ty.isInt(zcu)) std.wasm.simdOpcode(.i64x2_splat) else std.wasm.simdOpcode(.f64x2_splat),
5167 else => break :blk, // Cannot make use of simd-instructions5170 else => break :blk, // Cannot make use of simd-instructions
5168 };5171 };
5169 try func.emitWValue(operand);5172 try func.emitWValue(operand);
...@@ -5175,14 +5178,14 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5175,14 +5178,14 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5175 else => unreachable,5178 else => unreachable,
5176 }5179 }
5177 }5180 }
5178 const elem_size = elem_ty.bitSize(pt);5181 const elem_size = elem_ty.bitSize(zcu);
5179 const vector_len = @as(usize, @intCast(ty.vectorLen(mod)));5182 const vector_len = @as(usize, @intCast(ty.vectorLen(zcu)));
5180 if ((!std.math.isPowerOfTwo(elem_size) or elem_size % 8 != 0) and vector_len > 1) {5183 if ((!std.math.isPowerOfTwo(elem_size) or elem_size % 8 != 0) and vector_len > 1) {
5181 return func.fail("TODO: WebAssembly `@splat` for arbitrary element bitsize {d}", .{elem_size});5184 return func.fail("TODO: WebAssembly `@splat` for arbitrary element bitsize {d}", .{elem_size});
5182 }5185 }
51835186
5184 const result = try func.allocStack(ty);5187 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)));
5186 var index: usize = 0;5189 var index: usize = 0;
5187 var offset: u32 = 0;5190 var offset: u32 = 0;
5188 while (index < vector_len) : (index += 1) {5191 while (index < vector_len) : (index += 1) {
...@@ -5203,7 +5206,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5203,7 +5206,7 @@ fn airSelect(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52035206
5204fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5207fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5205 const pt = func.pt;5208 const pt = func.pt;
5206 const mod = pt.zcu;5209 const zcu = pt.zcu;
5207 const inst_ty = func.typeOfIndex(inst);5210 const inst_ty = func.typeOfIndex(inst);
5208 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5211 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5209 const extra = func.air.extraData(Air.Shuffle, ty_pl.payload).data;5212 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 {...@@ -5213,15 +5216,15 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5213 const mask = Value.fromInterned(extra.mask);5216 const mask = Value.fromInterned(extra.mask);
5214 const mask_len = extra.mask_len;5217 const mask_len = extra.mask_len;
52155218
5216 const child_ty = inst_ty.childType(mod);5219 const child_ty = inst_ty.childType(zcu);
5217 const elem_size = child_ty.abiSize(pt);5220 const elem_size = child_ty.abiSize(zcu);
52185221
5219 // TODO: One of them could be by ref; handle in loop5222 // TODO: One of them could be by ref; handle in loop
5220 if (isByRef(func.typeOf(extra.a), pt, func.target.*) or isByRef(inst_ty, pt, func.target.*)) {5223 if (isByRef(func.typeOf(extra.a), pt, func.target.*) or isByRef(inst_ty, pt, func.target.*)) {
5221 const result = try func.allocStack(inst_ty);5224 const result = try func.allocStack(inst_ty);
52225225
5223 for (0..mask_len) |index| {5226 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
5226 try func.emitWValue(result);5229 try func.emitWValue(result);
52275230
...@@ -5241,7 +5244,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5241,7 +5244,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52415244
5242 var lanes = mem.asBytes(operands[1..]);5245 var lanes = mem.asBytes(operands[1..]);
5243 for (0..@as(usize, @intCast(mask_len))) |index| {5246 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);
5245 const base_index = if (mask_elem >= 0)5248 const base_index = if (mask_elem >= 0)
5246 @as(u8, @intCast(@as(i64, @intCast(elem_size)) * mask_elem))5249 @as(u8, @intCast(@as(i64, @intCast(elem_size)) * mask_elem))
5247 else5250 else
...@@ -5273,20 +5276,20 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5273,20 +5276,20 @@ fn airReduce(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52735276
5274fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5277fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5275 const pt = func.pt;5278 const pt = func.pt;
5276 const mod = pt.zcu;5279 const zcu = pt.zcu;
5277 const ip = &mod.intern_pool;5280 const ip = &zcu.intern_pool;
5278 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5281 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5279 const result_ty = func.typeOfIndex(inst);5282 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)));
5281 const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len]));5284 const elements = @as([]const Air.Inst.Ref, @ptrCast(func.air.extra[ty_pl.payload..][0..len]));
52825285
5283 const result: WValue = result_value: {5286 const result: WValue = result_value: {
5284 switch (result_ty.zigTypeTag(mod)) {5287 switch (result_ty.zigTypeTag(zcu)) {
5285 .Array => {5288 .Array => {
5286 const result = try func.allocStack(result_ty);5289 const result = try func.allocStack(result_ty);
5287 const elem_ty = result_ty.childType(mod);5290 const elem_ty = result_ty.childType(zcu);
5288 const elem_size = @as(u32, @intCast(elem_ty.abiSize(pt)));5291 const elem_size = @as(u32, @intCast(elem_ty.abiSize(zcu)));
5289 const sentinel = if (result_ty.sentinel(mod)) |sent| blk: {5292 const sentinel = if (result_ty.sentinel(zcu)) |sent| blk: {
5290 break :blk try func.lowerConstant(sent, elem_ty);5293 break :blk try func.lowerConstant(sent, elem_ty);
5291 } else null;5294 } else null;
52925295
...@@ -5321,18 +5324,18 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5321,18 +5324,18 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5321 }5324 }
5322 break :result_value result;5325 break :result_value result;
5323 },5326 },
5324 .Struct => switch (result_ty.containerLayout(mod)) {5327 .Struct => switch (result_ty.containerLayout(zcu)) {
5325 .@"packed" => {5328 .@"packed" => {
5326 if (isByRef(result_ty, pt, func.target.*)) {5329 if (isByRef(result_ty, pt, func.target.*)) {
5327 return func.fail("TODO: airAggregateInit for packed structs larger than 64 bits", .{});5330 return func.fail("TODO: airAggregateInit for packed structs larger than 64 bits", .{});
5328 }5331 }
5329 const packed_struct = mod.typeToPackedStruct(result_ty).?;5332 const packed_struct = zcu.typeToPackedStruct(result_ty).?;
5330 const field_types = packed_struct.field_types;5333 const field_types = packed_struct.field_types;
5331 const backing_type = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));5334 const backing_type = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
53325335
5333 // ensure the result is zero'd5336 // ensure the result is zero'd
5334 const result = try func.allocLocal(backing_type);5337 const result = try func.allocLocal(backing_type);
5335 if (backing_type.bitSize(pt) <= 32)5338 if (backing_type.bitSize(zcu) <= 32)
5336 try func.addImm32(0)5339 try func.addImm32(0)
5337 else5340 else
5338 try func.addImm64(0);5341 try func.addImm64(0);
...@@ -5341,15 +5344,15 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5341,15 +5344,15 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5341 var current_bit: u16 = 0;5344 var current_bit: u16 = 0;
5342 for (elements, 0..) |elem, elem_index| {5345 for (elements, 0..) |elem, elem_index| {
5343 const field_ty = Type.fromInterned(field_types.get(ip)[elem_index]);5346 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)
5347 .{ .imm32 = current_bit }5350 .{ .imm32 = current_bit }
5348 else5351 else
5349 .{ .imm64 = current_bit };5352 .{ .imm64 = current_bit };
53505353
5351 const value = try func.resolveInst(elem);5354 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));
5353 const int_ty = try pt.intType(.unsigned, value_bit_size);5356 const int_ty = try pt.intType(.unsigned, value_bit_size);
53545357
5355 // load our current result on stack so we can perform all transformations5358 // 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 {...@@ -5375,8 +5378,8 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5375 for (elements, 0..) |elem, elem_index| {5378 for (elements, 0..) |elem, elem_index| {
5376 if (try result_ty.structFieldValueComptime(pt, elem_index) != null) continue;5379 if (try result_ty.structFieldValueComptime(pt, elem_index) != null) continue;
53775380
5378 const elem_ty = result_ty.structFieldType(elem_index, mod);5381 const elem_ty = result_ty.fieldType(elem_index, zcu);
5379 const field_offset = result_ty.structFieldOffset(elem_index, pt);5382 const field_offset = result_ty.structFieldOffset(elem_index, zcu);
5380 _ = try func.buildPointerOffset(offset, @intCast(field_offset - prev_field_offset), .modify);5383 _ = try func.buildPointerOffset(offset, @intCast(field_offset - prev_field_offset), .modify);
5381 prev_field_offset = field_offset;5384 prev_field_offset = field_offset;
53825385
...@@ -5404,21 +5407,21 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5404,21 +5407,21 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54045407
5405fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5408fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5406 const pt = func.pt;5409 const pt = func.pt;
5407 const mod = pt.zcu;5410 const zcu = pt.zcu;
5408 const ip = &mod.intern_pool;5411 const ip = &zcu.intern_pool;
5409 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5412 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5410 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;5413 const extra = func.air.extraData(Air.UnionInit, ty_pl.payload).data;
54115414
5412 const result = result: {5415 const result = result: {
5413 const union_ty = func.typeOfIndex(inst);5416 const union_ty = func.typeOfIndex(inst);
5414 const layout = union_ty.unionGetLayout(pt);5417 const layout = union_ty.unionGetLayout(zcu);
5415 const union_obj = mod.typeToUnion(union_ty).?;5418 const union_obj = zcu.typeToUnion(union_ty).?;
5416 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);5419 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
5417 const field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];5420 const field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];
54185421
5419 const tag_int = blk: {5422 const tag_int = blk: {
5420 const tag_ty = union_ty.unionTagTypeHypothetical(mod);5423 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
5421 const enum_field_index = tag_ty.enumFieldIndex(field_name, mod).?;5424 const enum_field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
5422 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);5425 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);
5423 break :blk try func.lowerConstant(tag_val, tag_ty);5426 break :blk try func.lowerConstant(tag_val, tag_ty);
5424 };5427 };
...@@ -5458,13 +5461,13 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5458,13 +5461,13 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5458 break :result result_ptr;5461 break :result result_ptr;
5459 } else {5462 } else {
5460 const operand = try func.resolveInst(extra.init);5463 const operand = try func.resolveInst(extra.init);
5461 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(union_ty.bitSize(pt))));5464 const union_int_type = try pt.intType(.unsigned, @as(u16, @intCast(union_ty.bitSize(zcu))));
5462 if (field_ty.zigTypeTag(mod) == .Float) {5465 if (field_ty.zigTypeTag(zcu) == .Float) {
5463 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(pt)));5466 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(zcu)));
5464 const bitcasted = try func.bitcast(field_ty, int_type, operand);5467 const bitcasted = try func.bitcast(field_ty, int_type, operand);
5465 break :result try func.trunc(bitcasted, int_type, union_int_type);5468 break :result try func.trunc(bitcasted, int_type, union_int_type);
5466 } else if (field_ty.isPtrAtRuntime(mod)) {5469 } else if (field_ty.isPtrAtRuntime(zcu)) {
5467 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(pt)));5470 const int_type = try pt.intType(.unsigned, @intCast(field_ty.bitSize(zcu)));
5468 break :result try func.intcast(operand, int_type, union_int_type);5471 break :result try func.intcast(operand, int_type, union_int_type);
5469 }5472 }
5470 break :result try func.intcast(operand, field_ty, union_int_type);5473 break :result try func.intcast(operand, field_ty, union_int_type);
...@@ -5497,10 +5500,10 @@ fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {...@@ -5497,10 +5500,10 @@ fn airWasmMemoryGrow(func: *CodeGen, inst: Air.Inst.Index) !void {
54975500
5498fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {5501fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {
5499 const pt = func.pt;5502 const pt = func.pt;
5500 const mod = pt.zcu;5503 const zcu = pt.zcu;
5501 assert(operand_ty.hasRuntimeBitsIgnoreComptime(pt));5504 assert(operand_ty.hasRuntimeBitsIgnoreComptime(zcu));
5502 assert(op == .eq or op == .neq);5505 assert(op == .eq or op == .neq);
5503 const payload_ty = operand_ty.optionalChild(mod);5506 const payload_ty = operand_ty.optionalChild(zcu);
55045507
5505 // We store the final result in here that will be validated5508 // We store the final result in here that will be validated
5506 // if the optional is truly equal.5509 // if the optional is truly equal.
...@@ -5534,11 +5537,11 @@ fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op:...@@ -5534,11 +5537,11 @@ fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op:
5534/// TODO: Lower this to compiler_rt call when bitsize > 1285537/// TODO: Lower this to compiler_rt call when bitsize > 128
5535fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {5538fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std.math.CompareOperator) InnerError!WValue {
5536 const pt = func.pt;5539 const pt = func.pt;
5537 const mod = pt.zcu;5540 const zcu = pt.zcu;
5538 assert(operand_ty.abiSize(pt) >= 16);5541 assert(operand_ty.abiSize(zcu) >= 16);
5539 assert(!(lhs != .stack and rhs == .stack));5542 assert(!(lhs != .stack and rhs == .stack));
5540 if (operand_ty.bitSize(pt) > 128) {5543 if (operand_ty.bitSize(zcu) > 128) {
5541 return func.fail("TODO: Support cmpBigInt for integer bitsize: '{d}'", .{operand_ty.bitSize(pt)});5544 return func.fail("TODO: Support cmpBigInt for integer bitsize: '{d}'", .{operand_ty.bitSize(zcu)});
5542 }5545 }
55435546
5544 var lhs_msb = try (try func.load(lhs, Type.u64, 8)).toLocal(func, Type.u64);5547 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...@@ -5561,7 +5564,7 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std
5561 }5564 }
5562 },5565 },
5563 else => {5566 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;
5565 // leave those value on top of the stack for '.select'5568 // leave those value on top of the stack for '.select'
5566 const lhs_lsb = try func.load(lhs, Type.u64, 0);5569 const lhs_lsb = try func.load(lhs, Type.u64, 0);
5567 const rhs_lsb = try func.load(rhs, Type.u64, 0);5570 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...@@ -5577,11 +5580,11 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std
55775580
5578fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5581fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5579 const pt = func.pt;5582 const pt = func.pt;
5580 const mod = pt.zcu;5583 const zcu = pt.zcu;
5581 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5584 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);
5583 const tag_ty = func.typeOf(bin_op.rhs);5586 const tag_ty = func.typeOf(bin_op.rhs);
5584 const layout = un_ty.unionGetLayout(pt);5587 const layout = un_ty.unionGetLayout(zcu);
5585 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });5588 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
55865589
5587 const union_ptr = try func.resolveInst(bin_op.lhs);5590 const union_ptr = try func.resolveInst(bin_op.lhs);
...@@ -5601,12 +5604,12 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5601,12 +5604,12 @@ fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5601}5604}
56025605
5603fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5606fn airGetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5604 const pt = func.pt;5607 const zcu = func.pt.zcu;
5605 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5608 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56065609
5607 const un_ty = func.typeOf(ty_op.operand);5610 const un_ty = func.typeOf(ty_op.operand);
5608 const tag_ty = func.typeOfIndex(inst);5611 const tag_ty = func.typeOfIndex(inst);
5609 const layout = un_ty.unionGetLayout(pt);5612 const layout = un_ty.unionGetLayout(zcu);
5610 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ty_op.operand});5613 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ty_op.operand});
56115614
5612 const operand = try func.resolveInst(ty_op.operand);5615 const operand = try func.resolveInst(ty_op.operand);
...@@ -5705,11 +5708,11 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro...@@ -5705,11 +5708,11 @@ fn fptrunc(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
57055708
5706fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5709fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5707 const pt = func.pt;5710 const pt = func.pt;
5708 const mod = pt.zcu;5711 const zcu = pt.zcu;
5709 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5712 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);5714 const err_set_ty = func.typeOf(ty_op.operand).childType(zcu);
5712 const payload_ty = err_set_ty.errorUnionPayload(mod);5715 const payload_ty = err_set_ty.errorUnionPayload(zcu);
5713 const operand = try func.resolveInst(ty_op.operand);5716 const operand = try func.resolveInst(ty_op.operand);
57145717
5715 // set error-tag to '0' to annotate error union is non-error5718 // 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...@@ -5717,28 +5720,28 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
5717 operand,5720 operand,
5718 .{ .imm32 = 0 },5721 .{ .imm32 = 0 },
5719 Type.anyerror,5722 Type.anyerror,
5720 @intCast(errUnionErrorOffset(payload_ty, pt)),5723 @intCast(errUnionErrorOffset(payload_ty, zcu)),
5721 );5724 );
57225725
5723 const result = result: {5726 const result = result: {
5724 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {5727 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5725 break :result func.reuseOperand(ty_op.operand, operand);5728 break :result func.reuseOperand(ty_op.operand, operand);
5726 }5729 }
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);
5729 };5732 };
5730 return func.finishAir(inst, result, &.{ty_op.operand});5733 return func.finishAir(inst, result, &.{ty_op.operand});
5731}5734}
57325735
5733fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5736fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5734 const pt = func.pt;5737 const pt = func.pt;
5735 const mod = pt.zcu;5738 const zcu = pt.zcu;
5736 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5739 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5737 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;5740 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
57385741
5739 const field_ptr = try func.resolveInst(extra.field_ptr);5742 const field_ptr = try func.resolveInst(extra.field_ptr);
5740 const parent_ty = ty_pl.ty.toType().childType(mod);5743 const parent_ty = ty_pl.ty.toType().childType(zcu);
5741 const field_offset = parent_ty.structFieldOffset(extra.field_index, pt);5744 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
57425745
5743 const result = if (field_offset != 0) result: {5746 const result = if (field_offset != 0) result: {
5744 const base = try func.buildPointerOffset(field_ptr, 0, .new);5747 const base = try func.buildPointerOffset(field_ptr, 0, .new);
...@@ -5754,8 +5757,8 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5754,8 +5757,8 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
57545757
5755fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue {5758fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue {
5756 const pt = func.pt;5759 const pt = func.pt;
5757 const mod = pt.zcu;5760 const zcu = pt.zcu;
5758 if (ptr_ty.isSlice(mod)) {5761 if (ptr_ty.isSlice(zcu)) {
5759 return func.slicePtr(ptr);5762 return func.slicePtr(ptr);
5760 } else {5763 } else {
5761 return ptr;5764 return ptr;
...@@ -5764,26 +5767,26 @@ fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue...@@ -5764,26 +5767,26 @@ fn sliceOrArrayPtr(func: *CodeGen, ptr: WValue, ptr_ty: Type) InnerError!WValue
57645767
5765fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5768fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5766 const pt = func.pt;5769 const pt = func.pt;
5767 const mod = pt.zcu;5770 const zcu = pt.zcu;
5768 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5771 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5769 const dst = try func.resolveInst(bin_op.lhs);5772 const dst = try func.resolveInst(bin_op.lhs);
5770 const dst_ty = func.typeOf(bin_op.lhs);5773 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);
5772 const src = try func.resolveInst(bin_op.rhs);5775 const src = try func.resolveInst(bin_op.rhs);
5773 const src_ty = func.typeOf(bin_op.rhs);5776 const src_ty = func.typeOf(bin_op.rhs);
5774 const len = switch (dst_ty.ptrSize(mod)) {5777 const len = switch (dst_ty.ptrSize(zcu)) {
5775 .Slice => blk: {5778 .Slice => blk: {
5776 const slice_len = try func.sliceLen(dst);5779 const slice_len = try func.sliceLen(dst);
5777 if (ptr_elem_ty.abiSize(pt) != 1) {5780 if (ptr_elem_ty.abiSize(zcu) != 1) {
5778 try func.emitWValue(slice_len);5781 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))) });
5780 try func.addTag(.i32_mul);5783 try func.addTag(.i32_mul);
5781 try func.addLabel(.local_set, slice_len.local.value);5784 try func.addLabel(.local_set, slice_len.local.value);
5782 }5785 }
5783 break :blk slice_len;5786 break :blk slice_len;
5784 },5787 },
5785 .One => @as(WValue, .{5788 .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))),
5787 }),5790 }),
5788 .C, .Many => unreachable,5791 .C, .Many => unreachable,
5789 };5792 };
...@@ -5805,17 +5808,17 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5805,17 +5808,17 @@ fn airRetAddr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58055808
5806fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5809fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5807 const pt = func.pt;5810 const pt = func.pt;
5808 const mod = pt.zcu;5811 const zcu = pt.zcu;
5809 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5812 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58105813
5811 const operand = try func.resolveInst(ty_op.operand);5814 const operand = try func.resolveInst(ty_op.operand);
5812 const op_ty = func.typeOf(ty_op.operand);5815 const op_ty = func.typeOf(ty_op.operand);
58135816
5814 if (op_ty.zigTypeTag(mod) == .Vector) {5817 if (op_ty.zigTypeTag(zcu) == .Vector) {
5815 return func.fail("TODO: Implement @popCount for vectors", .{});5818 return func.fail("TODO: Implement @popCount for vectors", .{});
5816 }5819 }
58175820
5818 const int_info = op_ty.intInfo(mod);5821 const int_info = op_ty.intInfo(zcu);
5819 const bits = int_info.bits;5822 const bits = int_info.bits;
5820 const wasm_bits = toWasmBits(bits) orelse {5823 const wasm_bits = toWasmBits(bits) orelse {
5821 return func.fail("TODO: Implement @popCount for integers with bitsize '{d}'", .{bits});5824 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 {...@@ -5824,14 +5827,14 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5824 switch (wasm_bits) {5827 switch (wasm_bits) {
5825 32 => {5828 32 => {
5826 try func.emitWValue(operand);5829 try func.emitWValue(operand);
5827 if (op_ty.isSignedInt(mod) and bits != wasm_bits) {5830 if (op_ty.isSignedInt(zcu) and bits != wasm_bits) {
5828 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits));5831 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits));
5829 }5832 }
5830 try func.addTag(.i32_popcnt);5833 try func.addTag(.i32_popcnt);
5831 },5834 },
5832 64 => {5835 64 => {
5833 try func.emitWValue(operand);5836 try func.emitWValue(operand);
5834 if (op_ty.isSignedInt(mod) and bits != wasm_bits) {5837 if (op_ty.isSignedInt(zcu) and bits != wasm_bits) {
5835 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits));5838 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits));
5836 }5839 }
5837 try func.addTag(.i64_popcnt);5840 try func.addTag(.i64_popcnt);
...@@ -5842,7 +5845,7 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5842,7 +5845,7 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5842 _ = try func.load(operand, Type.u64, 0);5845 _ = try func.load(operand, Type.u64, 0);
5843 try func.addTag(.i64_popcnt);5846 try func.addTag(.i64_popcnt);
5844 _ = try func.load(operand, Type.u64, 8);5847 _ = 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) {
5846 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits - 64));5849 _ = try func.wrapOperand(.stack, try pt.intType(.unsigned, bits - 64));
5847 }5850 }
5848 try func.addTag(.i64_popcnt);5851 try func.addTag(.i64_popcnt);
...@@ -5857,17 +5860,17 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5857,17 +5860,17 @@ fn airPopcount(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58575860
5858fn airBitReverse(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {5861fn airBitReverse(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5859 const pt = func.pt;5862 const pt = func.pt;
5860 const mod = pt.zcu;5863 const zcu = pt.zcu;
5861 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5864 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
58625865
5863 const operand = try func.resolveInst(ty_op.operand);5866 const operand = try func.resolveInst(ty_op.operand);
5864 const ty = func.typeOf(ty_op.operand);5867 const ty = func.typeOf(ty_op.operand);
58655868
5866 if (ty.zigTypeTag(mod) == .Vector) {5869 if (ty.zigTypeTag(zcu) == .Vector) {
5867 return func.fail("TODO: Implement @bitReverse for vectors", .{});5870 return func.fail("TODO: Implement @bitReverse for vectors", .{});
5868 }5871 }
58695872
5870 const int_info = ty.intInfo(mod);5873 const int_info = ty.intInfo(zcu);
5871 const bits = int_info.bits;5874 const bits = int_info.bits;
5872 const wasm_bits = toWasmBits(bits) orelse {5875 const wasm_bits = toWasmBits(bits) orelse {
5873 return func.fail("TODO: Implement @bitReverse for integers with bitsize '{d}'", .{bits});5876 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 {...@@ -5933,7 +5936,7 @@ fn airBitReverse(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5933 defer tmp.free(func);5936 defer tmp.free(func);
5934 try func.addLabel(.local_tee, tmp.local.value);5937 try func.addLabel(.local_tee, tmp.local.value);
5935 try func.emitWValue(.{ .imm64 = 128 - bits });5938 try func.emitWValue(.{ .imm64 = 128 - bits });
5936 if (ty.isSignedInt(mod)) {5939 if (ty.isSignedInt(zcu)) {
5937 try func.addTag(.i64_shr_s);5940 try func.addTag(.i64_shr_s);
5938 } else {5941 } else {
5939 try func.addTag(.i64_shr_u);5942 try func.addTag(.i64_shr_u);
...@@ -5969,7 +5972,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5969,7 +5972,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5969 const pt = func.pt;5972 const pt = func.pt;
5970 const error_table_symbol = try func.bin_file.getErrorTableSymbol(pt);5973 const error_table_symbol = try func.bin_file.getErrorTableSymbol(pt);
5971 const name_ty = Type.slice_const_u8_sentinel_0;5974 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
5974 const error_name_value: WValue = .{ .memory = error_table_symbol }; // emitting this will create a relocation5977 const error_name_value: WValue = .{ .memory = error_table_symbol }; // emitting this will create a relocation
5975 try func.emitWValue(error_name_value);5978 try func.emitWValue(error_name_value);
...@@ -6000,8 +6003,8 @@ fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerE...@@ -6000,8 +6003,8 @@ fn airPtrSliceFieldPtr(func: *CodeGen, inst: Air.Inst.Index, offset: u32) InnerE
60006003
6001/// NOTE: Allocates place for result on virtual stack, when integer size > 64 bits6004/// NOTE: Allocates place for result on virtual stack, when integer size > 64 bits
6002fn intZeroValue(func: *CodeGen, ty: Type) InnerError!WValue {6005fn intZeroValue(func: *CodeGen, ty: Type) InnerError!WValue {
6003 const mod = func.bin_file.base.comp.module.?;6006 const zcu = func.bin_file.base.comp.zcu.?;
6004 const int_info = ty.intInfo(mod);6007 const int_info = ty.intInfo(zcu);
6005 const wasm_bits = toWasmBits(int_info.bits) orelse {6008 const wasm_bits = toWasmBits(int_info.bits) orelse {
6006 return func.fail("TODO: Implement intZeroValue for integer bitsize: {d}", .{int_info.bits});6009 return func.fail("TODO: Implement intZeroValue for integer bitsize: {d}", .{int_info.bits});
6007 };6010 };
...@@ -6027,13 +6030,13 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro...@@ -6027,13 +6030,13 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
6027 const rhs = try func.resolveInst(extra.rhs);6030 const rhs = try func.resolveInst(extra.rhs);
6028 const ty = func.typeOf(extra.lhs);6031 const ty = func.typeOf(extra.lhs);
6029 const pt = func.pt;6032 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) {
6033 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});6036 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});
6034 }6037 }
60356038
6036 const int_info = ty.intInfo(mod);6039 const int_info = ty.intInfo(zcu);
6037 const is_signed = int_info.signedness == .signed;6040 const is_signed = int_info.signedness == .signed;
6038 if (int_info.bits > 128) {6041 if (int_info.bits > 128) {
6039 return func.fail("TODO: Implement {{add/sub}}_with_overflow for integer bitsize: {d}", .{int_info.bits});6042 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...@@ -6058,7 +6061,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
6058 defer bit_tmp.free(func);6061 defer bit_tmp.free(func);
60596062
6060 const result = try func.allocStack(func.typeOfIndex(inst));6063 const result = try func.allocStack(func.typeOfIndex(inst));
6061 const offset: u32 = @intCast(ty.abiSize(pt));6064 const offset: u32 = @intCast(ty.abiSize(zcu));
6062 try func.store(result, op_tmp, ty, 0);6065 try func.store(result, op_tmp, ty, 0);
6063 try func.store(result, bit_tmp, Type.u1, offset);6066 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...@@ -6067,7 +6070,7 @@ fn airAddSubWithOverflow(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerErro
60676070
6068fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6071fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6069 const pt = func.pt;6072 const pt = func.pt;
6070 const mod = pt.zcu;6073 const zcu = pt.zcu;
6071 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6074 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6072 const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;6075 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 {...@@ -6076,18 +6079,18 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6076 const ty = func.typeOf(extra.lhs);6079 const ty = func.typeOf(extra.lhs);
6077 const rhs_ty = func.typeOf(extra.rhs);6080 const rhs_ty = func.typeOf(extra.rhs);
60786081
6079 if (ty.zigTypeTag(mod) == .Vector) {6082 if (ty.zigTypeTag(zcu) == .Vector) {
6080 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});6083 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});
6081 }6084 }
60826085
6083 const int_info = ty.intInfo(mod);6086 const int_info = ty.intInfo(zcu);
6084 const wasm_bits = toWasmBits(int_info.bits) orelse {6087 const wasm_bits = toWasmBits(int_info.bits) orelse {
6085 return func.fail("TODO: Implement shl_with_overflow for integer bitsize: {d}", .{int_info.bits});6088 return func.fail("TODO: Implement shl_with_overflow for integer bitsize: {d}", .{int_info.bits});
6086 };6089 };
60876090
6088 // Ensure rhs is coerced to lhs as they must have the same WebAssembly types6091 // Ensure rhs is coerced to lhs as they must have the same WebAssembly types
6089 // before we can perform any binary operation.6092 // 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).?;
6091 // If wasm_bits == 128, compiler-rt expects i32 for shift6094 // If wasm_bits == 128, compiler-rt expects i32 for shift
6092 const rhs_final = if (wasm_bits != rhs_wasm_bits and wasm_bits == 64) blk: {6095 const rhs_final = if (wasm_bits != rhs_wasm_bits and wasm_bits == 64) blk: {
6093 const rhs_casted = try func.intcast(rhs, rhs_ty, ty);6096 const rhs_casted = try func.intcast(rhs, rhs_ty, ty);
...@@ -6105,7 +6108,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6105,7 +6108,7 @@ fn airShlWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6105 defer overflow_local.free(func);6108 defer overflow_local.free(func);
61066109
6107 const result = try func.allocStack(func.typeOfIndex(inst));6110 const result = try func.allocStack(func.typeOfIndex(inst));
6108 const offset: u32 = @intCast(ty.abiSize(pt));6111 const offset: u32 = @intCast(ty.abiSize(zcu));
6109 try func.store(result, shl, ty, 0);6112 try func.store(result, shl, ty, 0);
6110 try func.store(result, overflow_local, Type.u1, offset);6113 try func.store(result, overflow_local, Type.u1, offset);
61116114
...@@ -6120,9 +6123,9 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6120,9 +6123,9 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6120 const rhs = try func.resolveInst(extra.rhs);6123 const rhs = try func.resolveInst(extra.rhs);
6121 const ty = func.typeOf(extra.lhs);6124 const ty = func.typeOf(extra.lhs);
6122 const pt = func.pt;6125 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) {
6126 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});6129 return func.fail("TODO: Implement overflow arithmetic for vectors", .{});
6127 }6130 }
61286131
...@@ -6131,7 +6134,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6131,7 +6134,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6131 var overflow_bit = try func.ensureAllocLocal(Type.u1);6134 var overflow_bit = try func.ensureAllocLocal(Type.u1);
6132 defer overflow_bit.free(func);6135 defer overflow_bit.free(func);
61336136
6134 const int_info = ty.intInfo(mod);6137 const int_info = ty.intInfo(zcu);
6135 const wasm_bits = toWasmBits(int_info.bits) orelse {6138 const wasm_bits = toWasmBits(int_info.bits) orelse {
6136 return func.fail("TODO: Implement `@mulWithOverflow` for integer bitsize: {d}", .{int_info.bits});6139 return func.fail("TODO: Implement `@mulWithOverflow` for integer bitsize: {d}", .{int_info.bits});
6137 };6140 };
...@@ -6238,7 +6241,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6238,7 +6241,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6238 defer bin_op_local.free(func);6241 defer bin_op_local.free(func);
62396242
6240 const result = try func.allocStack(func.typeOfIndex(inst));6243 const result = try func.allocStack(func.typeOfIndex(inst));
6241 const offset: u32 = @intCast(ty.abiSize(pt));6244 const offset: u32 = @intCast(ty.abiSize(zcu));
6242 try func.store(result, bin_op_local, ty, 0);6245 try func.store(result, bin_op_local, ty, 0);
6243 try func.store(result, overflow_bit, Type.u1, offset);6246 try func.store(result, overflow_bit, Type.u1, offset);
62446247
...@@ -6248,22 +6251,22 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6248,22 +6251,22 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6248fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {6251fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
6249 assert(op == .max or op == .min);6252 assert(op == .max or op == .min);
6250 const pt = func.pt;6253 const pt = func.pt;
6251 const mod = pt.zcu;6254 const zcu = pt.zcu;
6252 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6255 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
62536256
6254 const ty = func.typeOfIndex(inst);6257 const ty = func.typeOfIndex(inst);
6255 if (ty.zigTypeTag(mod) == .Vector) {6258 if (ty.zigTypeTag(zcu) == .Vector) {
6256 return func.fail("TODO: `@maximum` and `@minimum` for vectors", .{});6259 return func.fail("TODO: `@maximum` and `@minimum` for vectors", .{});
6257 }6260 }
62586261
6259 if (ty.abiSize(pt) > 16) {6262 if (ty.abiSize(zcu) > 16) {
6260 return func.fail("TODO: `@maximum` and `@minimum` for types larger than 16 bytes", .{});6263 return func.fail("TODO: `@maximum` and `@minimum` for types larger than 16 bytes", .{});
6261 }6264 }
62626265
6263 const lhs = try func.resolveInst(bin_op.lhs);6266 const lhs = try func.resolveInst(bin_op.lhs);
6264 const rhs = try func.resolveInst(bin_op.rhs);6267 const rhs = try func.resolveInst(bin_op.rhs);
62656268
6266 if (ty.zigTypeTag(mod) == .Float) {6269 if (ty.zigTypeTag(zcu) == .Float) {
6267 var fn_name_buf: [64]u8 = undefined;6270 var fn_name_buf: [64]u8 = undefined;
6268 const float_bits = ty.floatBits(func.target.*);6271 const float_bits = ty.floatBits(func.target.*);
6269 const fn_name = std.fmt.bufPrint(&fn_name_buf, "{s}f{s}{s}", .{6272 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 {...@@ -6288,12 +6291,12 @@ fn airMaxMin(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
62886291
6289fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6292fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6290 const pt = func.pt;6293 const pt = func.pt;
6291 const mod = pt.zcu;6294 const zcu = pt.zcu;
6292 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;6295 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6293 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;6296 const bin_op = func.air.extraData(Air.Bin, pl_op.payload).data;
62946297
6295 const ty = func.typeOfIndex(inst);6298 const ty = func.typeOfIndex(inst);
6296 if (ty.zigTypeTag(mod) == .Vector) {6299 if (ty.zigTypeTag(zcu) == .Vector) {
6297 return func.fail("TODO: `@mulAdd` for vectors", .{});6300 return func.fail("TODO: `@mulAdd` for vectors", .{});
6298 }6301 }
62996302
...@@ -6323,16 +6326,16 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6323,16 +6326,16 @@ fn airMulAdd(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63236326
6324fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6327fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6325 const pt = func.pt;6328 const pt = func.pt;
6326 const mod = pt.zcu;6329 const zcu = pt.zcu;
6327 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6330 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63286331
6329 const ty = func.typeOf(ty_op.operand);6332 const ty = func.typeOf(ty_op.operand);
6330 if (ty.zigTypeTag(mod) == .Vector) {6333 if (ty.zigTypeTag(zcu) == .Vector) {
6331 return func.fail("TODO: `@clz` for vectors", .{});6334 return func.fail("TODO: `@clz` for vectors", .{});
6332 }6335 }
63336336
6334 const operand = try func.resolveInst(ty_op.operand);6337 const operand = try func.resolveInst(ty_op.operand);
6335 const int_info = ty.intInfo(mod);6338 const int_info = ty.intInfo(zcu);
6336 const wasm_bits = toWasmBits(int_info.bits) orelse {6339 const wasm_bits = toWasmBits(int_info.bits) orelse {
6337 return func.fail("TODO: `@clz` for integers with bitsize '{d}'", .{int_info.bits});6340 return func.fail("TODO: `@clz` for integers with bitsize '{d}'", .{int_info.bits});
6338 };6341 };
...@@ -6374,17 +6377,17 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6374,17 +6377,17 @@ fn airClz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
63746377
6375fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6378fn airCtz(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6376 const pt = func.pt;6379 const pt = func.pt;
6377 const mod = pt.zcu;6380 const zcu = pt.zcu;
6378 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6381 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
63796382
6380 const ty = func.typeOf(ty_op.operand);6383 const ty = func.typeOf(ty_op.operand);
63816384
6382 if (ty.zigTypeTag(mod) == .Vector) {6385 if (ty.zigTypeTag(zcu) == .Vector) {
6383 return func.fail("TODO: `@ctz` for vectors", .{});6386 return func.fail("TODO: `@ctz` for vectors", .{});
6384 }6387 }
63856388
6386 const operand = try func.resolveInst(ty_op.operand);6389 const operand = try func.resolveInst(ty_op.operand);
6387 const int_info = ty.intInfo(mod);6390 const int_info = ty.intInfo(zcu);
6388 const wasm_bits = toWasmBits(int_info.bits) orelse {6391 const wasm_bits = toWasmBits(int_info.bits) orelse {
6389 return func.fail("TODO: `@clz` for integers with bitsize '{d}'", .{int_info.bits});6392 return func.fail("TODO: `@clz` for integers with bitsize '{d}'", .{int_info.bits});
6390 };6393 };
...@@ -6497,12 +6500,12 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6497,12 +6500,12 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
64976500
6498fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6501fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6499 const pt = func.pt;6502 const pt = func.pt;
6500 const mod = pt.zcu;6503 const zcu = pt.zcu;
6501 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6504 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6502 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);6505 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);
6503 const err_union_ptr = try func.resolveInst(extra.data.ptr);6506 const err_union_ptr = try func.resolveInst(extra.data.ptr);
6504 const body: []const Air.Inst.Index = @ptrCast(func.air.extra[extra.end..][0..extra.data.body_len]);6507 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);
6506 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);6509 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);
6507 return func.finishAir(inst, result, &.{extra.data.ptr});6510 return func.finishAir(inst, result, &.{extra.data.ptr});
6508}6511}
...@@ -6516,25 +6519,25 @@ fn lowerTry(...@@ -6516,25 +6519,25 @@ fn lowerTry(
6516 operand_is_ptr: bool,6519 operand_is_ptr: bool,
6517) InnerError!WValue {6520) InnerError!WValue {
6518 const pt = func.pt;6521 const pt = func.pt;
6519 const mod = pt.zcu;6522 const zcu = pt.zcu;
6520 if (operand_is_ptr) {6523 if (operand_is_ptr) {
6521 return func.fail("TODO: lowerTry for pointers", .{});6524 return func.fail("TODO: lowerTry for pointers", .{});
6522 }6525 }
65236526
6524 const pl_ty = err_union_ty.errorUnionPayload(mod);6527 const pl_ty = err_union_ty.errorUnionPayload(zcu);
6525 const pl_has_bits = pl_ty.hasRuntimeBitsIgnoreComptime(pt);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)) {
6528 // Block we can jump out of when error is not set6531 // Block we can jump out of when error is not set
6529 try func.startBlock(.block, wasm.block_empty);6532 try func.startBlock(.block, wasm.block_empty);
65306533
6531 // check if the error tag is set for the error union.6534 // check if the error tag is set for the error union.
6532 try func.emitWValue(err_union);6535 try func.emitWValue(err_union);
6533 if (pl_has_bits) {6536 if (pl_has_bits) {
6534 const err_offset: u32 = @intCast(errUnionErrorOffset(pl_ty, pt));6537 const err_offset: u32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
6535 try func.addMemArg(.i32_load16_u, .{6538 try func.addMemArg(.i32_load16_u, .{
6536 .offset = err_union.offset() + err_offset,6539 .offset = err_union.offset() + err_offset,
6537 .alignment = @intCast(Type.anyerror.abiAlignment(pt).toByteUnits().?),6540 .alignment = @intCast(Type.anyerror.abiAlignment(zcu).toByteUnits().?),
6538 });6541 });
6539 }6542 }
6540 try func.addTag(.i32_eqz);6543 try func.addTag(.i32_eqz);
...@@ -6556,7 +6559,7 @@ fn lowerTry(...@@ -6556,7 +6559,7 @@ fn lowerTry(
6556 return .none;6559 return .none;
6557 }6560 }
65586561
6559 const pl_offset: u32 = @intCast(errUnionPayloadOffset(pl_ty, pt));6562 const pl_offset: u32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
6560 if (isByRef(pl_ty, pt, func.target.*)) {6563 if (isByRef(pl_ty, pt, func.target.*)) {
6561 return buildPointerOffset(func, err_union, pl_offset, .new);6564 return buildPointerOffset(func, err_union, pl_offset, .new);
6562 }6565 }
...@@ -6566,16 +6569,16 @@ fn lowerTry(...@@ -6566,16 +6569,16 @@ fn lowerTry(
65666569
6567fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {6570fn airByteSwap(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6568 const pt = func.pt;6571 const pt = func.pt;
6569 const mod = pt.zcu;6572 const zcu = pt.zcu;
6570 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6573 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
65716574
6572 const ty = func.typeOfIndex(inst);6575 const ty = func.typeOfIndex(inst);
6573 const operand = try func.resolveInst(ty_op.operand);6576 const operand = try func.resolveInst(ty_op.operand);
65746577
6575 if (ty.zigTypeTag(mod) == .Vector) {6578 if (ty.zigTypeTag(zcu) == .Vector) {
6576 return func.fail("TODO: @byteSwap for vectors", .{});6579 return func.fail("TODO: @byteSwap for vectors", .{});
6577 }6580 }
6578 const int_info = ty.intInfo(mod);6581 const int_info = ty.intInfo(zcu);
6579 const wasm_bits = toWasmBits(int_info.bits) orelse {6582 const wasm_bits = toWasmBits(int_info.bits) orelse {
6580 return func.fail("TODO: @byteSwap for integers with bitsize {d}", .{int_info.bits});6583 return func.fail("TODO: @byteSwap for integers with bitsize {d}", .{int_info.bits});
6581 };6584 };
...@@ -6649,15 +6652,15 @@ fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6649,15 +6652,15 @@ fn airDivFloor(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6649 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6652 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
66506653
6651 const pt = func.pt;6654 const pt = func.pt;
6652 const mod = pt.zcu;6655 const zcu = pt.zcu;
6653 const ty = func.typeOfIndex(inst);6656 const ty = func.typeOfIndex(inst);
6654 const lhs = try func.resolveInst(bin_op.lhs);6657 const lhs = try func.resolveInst(bin_op.lhs);
6655 const rhs = try func.resolveInst(bin_op.rhs);6658 const rhs = try func.resolveInst(bin_op.rhs);
66566659
6657 if (ty.isUnsignedInt(mod)) {6660 if (ty.isUnsignedInt(zcu)) {
6658 _ = try func.binOp(lhs, rhs, ty, .div);6661 _ = try func.binOp(lhs, rhs, ty, .div);
6659 } else if (ty.isSignedInt(mod)) {6662 } else if (ty.isSignedInt(zcu)) {
6660 const int_bits = ty.intInfo(mod).bits;6663 const int_bits = ty.intInfo(zcu).bits;
6661 const wasm_bits = toWasmBits(int_bits) orelse {6664 const wasm_bits = toWasmBits(int_bits) orelse {
6662 return func.fail("TODO: `@divFloor` for signed integers larger than 64 bits ({d} bits requested)", .{int_bits});6665 return func.fail("TODO: `@divFloor` for signed integers larger than 64 bits ({d} bits requested)", .{int_bits});
6663 };6666 };
...@@ -6767,19 +6770,19 @@ fn airMod(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6767,19 +6770,19 @@ fn airMod(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6767 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6770 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
67686771
6769 const pt = func.pt;6772 const pt = func.pt;
6770 const mod = pt.zcu;6773 const zcu = pt.zcu;
6771 const ty = func.typeOfIndex(inst);6774 const ty = func.typeOfIndex(inst);
6772 const lhs = try func.resolveInst(bin_op.lhs);6775 const lhs = try func.resolveInst(bin_op.lhs);
6773 const rhs = try func.resolveInst(bin_op.rhs);6776 const rhs = try func.resolveInst(bin_op.rhs);
67746777
6775 if (ty.isUnsignedInt(mod)) {6778 if (ty.isUnsignedInt(zcu)) {
6776 _ = try func.binOp(lhs, rhs, ty, .rem);6779 _ = try func.binOp(lhs, rhs, ty, .rem);
6777 } else if (ty.isSignedInt(mod)) {6780 } else if (ty.isSignedInt(zcu)) {
6778 // The wasm rem instruction gives the remainder after truncating division (rounding towards6781 // The wasm rem instruction gives the remainder after truncating division (rounding towards
6779 // 0), equivalent to @rem.6782 // 0), equivalent to @rem.
6780 // We make use of the fact that:6783 // We make use of the fact that:
6781 // @mod(a, b) = @rem(@rem(a, b) + b, b)6784 // @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;
6783 const wasm_bits = toWasmBits(int_bits) orelse {6786 const wasm_bits = toWasmBits(int_bits) orelse {
6784 return func.fail("TODO: `@mod` for signed integers larger than 64 bits ({d} bits requested)", .{int_bits});6787 return func.fail("TODO: `@mod` for signed integers larger than 64 bits ({d} bits requested)", .{int_bits});
6785 };6788 };
...@@ -6802,9 +6805,9 @@ fn airSatMul(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -6802,9 +6805,9 @@ fn airSatMul(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6802 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6805 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
68036806
6804 const pt = func.pt;6807 const pt = func.pt;
6805 const mod = pt.zcu;6808 const zcu = pt.zcu;
6806 const ty = func.typeOfIndex(inst);6809 const ty = func.typeOfIndex(inst);
6807 const int_info = ty.intInfo(mod);6810 const int_info = ty.intInfo(zcu);
6808 const is_signed = int_info.signedness == .signed;6811 const is_signed = int_info.signedness == .signed;
68096812
6810 const lhs = try func.resolveInst(bin_op.lhs);6813 const lhs = try func.resolveInst(bin_op.lhs);
...@@ -6903,12 +6906,12 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -6903,12 +6906,12 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
6903 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6906 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
69046907
6905 const pt = func.pt;6908 const pt = func.pt;
6906 const mod = pt.zcu;6909 const zcu = pt.zcu;
6907 const ty = func.typeOfIndex(inst);6910 const ty = func.typeOfIndex(inst);
6908 const lhs = try func.resolveInst(bin_op.lhs);6911 const lhs = try func.resolveInst(bin_op.lhs);
6909 const rhs = try func.resolveInst(bin_op.rhs);6912 const rhs = try func.resolveInst(bin_op.rhs);
69106913
6911 const int_info = ty.intInfo(mod);6914 const int_info = ty.intInfo(zcu);
6912 const is_signed = int_info.signedness == .signed;6915 const is_signed = int_info.signedness == .signed;
69136916
6914 if (int_info.bits > 64) {6917 if (int_info.bits > 64) {
...@@ -6950,8 +6953,8 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {...@@ -6950,8 +6953,8 @@ fn airSatBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
69506953
6951fn signedSat(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {6954fn signedSat(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: Op) InnerError!WValue {
6952 const pt = func.pt;6955 const pt = func.pt;
6953 const mod = pt.zcu;6956 const zcu = pt.zcu;
6954 const int_info = ty.intInfo(mod);6957 const int_info = ty.intInfo(zcu);
6955 const wasm_bits = toWasmBits(int_info.bits).?;6958 const wasm_bits = toWasmBits(int_info.bits).?;
6956 const is_wasm_bits = wasm_bits == int_info.bits;6959 const is_wasm_bits = wasm_bits == int_info.bits;
6957 const ext_ty = if (!is_wasm_bits) try pt.intType(int_info.signedness, wasm_bits) else ty;6960 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 {...@@ -7009,9 +7012,9 @@ fn airShlSat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7009 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7012 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
70107013
7011 const pt = func.pt;7014 const pt = func.pt;
7012 const mod = pt.zcu;7015 const zcu = pt.zcu;
7013 const ty = func.typeOfIndex(inst);7016 const ty = func.typeOfIndex(inst);
7014 const int_info = ty.intInfo(mod);7017 const int_info = ty.intInfo(zcu);
7015 const is_signed = int_info.signedness == .signed;7018 const is_signed = int_info.signedness == .signed;
7016 if (int_info.bits > 64) {7019 if (int_info.bits > 64) {
7017 return func.fail("TODO: Saturating shifting left for integers with bitsize '{d}'", .{int_info.bits});7020 return func.fail("TODO: Saturating shifting left for integers with bitsize '{d}'", .{int_info.bits});
...@@ -7130,7 +7133,7 @@ fn callIntrinsic(...@@ -7130,7 +7133,7 @@ fn callIntrinsic(
71307133
7131 // Always pass over C-ABI7134 // Always pass over C-ABI
7132 const pt = func.pt;7135 const pt = func.pt;
7133 const mod = pt.zcu;7136 const zcu = pt.zcu;
7134 var func_type = try genFunctype(func.gpa, .C, param_types, return_type, pt, func.target.*);7137 var func_type = try genFunctype(func.gpa, .C, param_types, return_type, pt, func.target.*);
7135 defer func_type.deinit(func.gpa);7138 defer func_type.deinit(func.gpa);
7136 const func_type_index = try func.bin_file.zigObjectPtr().?.putOrGetFuncType(func.gpa, func_type);7139 const func_type_index = try func.bin_file.zigObjectPtr().?.putOrGetFuncType(func.gpa, func_type);
...@@ -7148,16 +7151,16 @@ fn callIntrinsic(...@@ -7148,16 +7151,16 @@ fn callIntrinsic(
7148 // Lower all arguments to the stack before we call our function7151 // Lower all arguments to the stack before we call our function
7149 for (args, 0..) |arg, arg_i| {7152 for (args, 0..) |arg, arg_i| {
7150 assert(!(want_sret_param and arg == .stack));7153 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));
7152 try func.lowerArg(.C, Type.fromInterned(param_types[arg_i]), arg);7155 try func.lowerArg(.C, Type.fromInterned(param_types[arg_i]), arg);
7153 }7156 }
71547157
7155 // Actually call our intrinsic7158 // Actually call our intrinsic
7156 try func.addLabel(.call, @intFromEnum(symbol_index));7159 try func.addLabel(.call, @intFromEnum(symbol_index));
71577160
7158 if (!return_type.hasRuntimeBitsIgnoreComptime(pt)) {7161 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
7159 return .none;7162 return .none;
7160 } else if (return_type.isNoReturn(mod)) {7163 } else if (return_type.isNoReturn(zcu)) {
7161 try func.addTag(.@"unreachable");7164 try func.addTag(.@"unreachable");
7162 return .none;7165 return .none;
7163 } else if (want_sret_param) {7166 } else if (want_sret_param) {
...@@ -7184,8 +7187,8 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7184,8 +7187,8 @@ fn airTagName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
71847187
7185fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {7188fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
7186 const pt = func.pt;7189 const pt = func.pt;
7187 const mod = pt.zcu;7190 const zcu = pt.zcu;
7188 const ip = &mod.intern_pool;7191 const ip = &zcu.intern_pool;
71897192
7190 var arena_allocator = std.heap.ArenaAllocator.init(func.gpa);7193 var arena_allocator = std.heap.ArenaAllocator.init(func.gpa);
7191 defer arena_allocator.deinit();7194 defer arena_allocator.deinit();
...@@ -7198,9 +7201,9 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7198,9 +7201,9 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
7198 return @intFromEnum(loc.index);7201 return @intFromEnum(loc.index);
7199 }7202 }
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) {
7204 return func.fail("TODO: Implement @tagName for enums with tag size larger than 64 bits", .{});7207 return func.fail("TODO: Implement @tagName for enums with tag size larger than 64 bits", .{});
7205 }7208 }
72067209
...@@ -7220,7 +7223,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7220,7 +7223,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
72207223
7221 // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse.7224 // TODO: Make switch implementation generic so we can use a jump table for this when the tags are not sparse.
7222 // generate an if-else chain for each tag value as well as constant.7225 // 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);
7224 for (0..tag_names.len) |tag_index| {7227 for (0..tag_names.len) |tag_index| {
7225 const tag_name = tag_names.get(ip)[tag_index];7228 const tag_name = tag_names.get(ip)[tag_index];
7226 const tag_name_len = tag_name.length(ip);7229 const tag_name_len = tag_name.length(ip);
...@@ -7345,15 +7348,15 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7345,15 +7348,15 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
73457348
7346fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7349fn airErrorSetHasValue(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7347 const pt = func.pt;7350 const pt = func.pt;
7348 const mod = pt.zcu;7351 const zcu = pt.zcu;
7349 const ip = &mod.intern_pool;7352 const ip = &zcu.intern_pool;
7350 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7353 const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
73517354
7352 const operand = try func.resolveInst(ty_op.operand);7355 const operand = try func.resolveInst(ty_op.operand);
7353 const error_set_ty = ty_op.ty.toType();7356 const error_set_ty = ty_op.ty.toType();
7354 const result = try func.allocLocal(Type.bool);7357 const result = try func.allocLocal(Type.bool);
73557358
7356 const names = error_set_ty.errorSetNames(mod);7359 const names = error_set_ty.errorSetNames(zcu);
7357 var values = try std.ArrayList(u32).initCapacity(func.gpa, names.len);7360 var values = try std.ArrayList(u32).initCapacity(func.gpa, names.len);
7358 defer values.deinit();7361 defer values.deinit();
73597362
...@@ -7432,12 +7435,12 @@ inline fn useAtomicFeature(func: *const CodeGen) bool {...@@ -7432,12 +7435,12 @@ inline fn useAtomicFeature(func: *const CodeGen) bool {
74327435
7433fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7436fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7434 const pt = func.pt;7437 const pt = func.pt;
7435 const mod = pt.zcu;7438 const zcu = pt.zcu;
7436 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;7439 const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7437 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;7440 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
74387441
7439 const ptr_ty = func.typeOf(extra.ptr);7442 const ptr_ty = func.typeOf(extra.ptr);
7440 const ty = ptr_ty.childType(mod);7443 const ty = ptr_ty.childType(zcu);
7441 const result_ty = func.typeOfIndex(inst);7444 const result_ty = func.typeOfIndex(inst);
74427445
7443 const ptr_operand = try func.resolveInst(extra.ptr);7446 const ptr_operand = try func.resolveInst(extra.ptr);
...@@ -7451,7 +7454,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7451,7 +7454,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7451 try func.emitWValue(ptr_operand);7454 try func.emitWValue(ptr_operand);
7452 try func.lowerToStack(expected_val);7455 try func.lowerToStack(expected_val);
7453 try func.lowerToStack(new_val);7456 try func.lowerToStack(new_val);
7454 try func.addAtomicMemArg(switch (ty.abiSize(pt)) {7457 try func.addAtomicMemArg(switch (ty.abiSize(zcu)) {
7455 1 => .i32_atomic_rmw8_cmpxchg_u,7458 1 => .i32_atomic_rmw8_cmpxchg_u,
7456 2 => .i32_atomic_rmw16_cmpxchg_u,7459 2 => .i32_atomic_rmw16_cmpxchg_u,
7457 4 => .i32_atomic_rmw_cmpxchg,7460 4 => .i32_atomic_rmw_cmpxchg,
...@@ -7459,14 +7462,14 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7459,14 +7462,14 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7459 else => |size| return func.fail("TODO: implement `@cmpxchg` for types with abi size '{d}'", .{size}),7462 else => |size| return func.fail("TODO: implement `@cmpxchg` for types with abi size '{d}'", .{size}),
7460 }, .{7463 }, .{
7461 .offset = ptr_operand.offset(),7464 .offset = ptr_operand.offset(),
7462 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),7465 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
7463 });7466 });
7464 try func.addLabel(.local_tee, val_local.local.value);7467 try func.addLabel(.local_tee, val_local.local.value);
7465 _ = try func.cmp(.stack, expected_val, ty, .eq);7468 _ = try func.cmp(.stack, expected_val, ty, .eq);
7466 try func.addLabel(.local_set, cmp_result.local.value);7469 try func.addLabel(.local_set, cmp_result.local.value);
7467 break :val val_local;7470 break :val val_local;
7468 } else val: {7471 } else val: {
7469 if (ty.abiSize(pt) > 8) {7472 if (ty.abiSize(zcu) > 8) {
7470 return func.fail("TODO: Implement `@cmpxchg` for types larger than abi size of 8 bytes", .{});7473 return func.fail("TODO: Implement `@cmpxchg` for types larger than abi size of 8 bytes", .{});
7471 }7474 }
7472 const ptr_val = try WValue.toLocal(try func.load(ptr_operand, ty, 0), func, ty);7475 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 {...@@ -7490,7 +7493,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7490 try func.addTag(.i32_and);7493 try func.addTag(.i32_and);
7491 const and_result = try WValue.toLocal(.stack, func, Type.bool);7494 const and_result = try WValue.toLocal(.stack, func, Type.bool);
7492 const result_ptr = try func.allocStack(result_ty);7495 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))));
7494 try func.store(result_ptr, ptr_val, ty, 0);7497 try func.store(result_ptr, ptr_val, ty, 0);
7495 break :val result_ptr;7498 break :val result_ptr;
7496 } else val: {7499 } else val: {
...@@ -7511,7 +7514,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7511,7 +7514,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7511 const ty = func.typeOfIndex(inst);7514 const ty = func.typeOfIndex(inst);
75127515
7513 if (func.useAtomicFeature()) {7516 if (func.useAtomicFeature()) {
7514 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt)) {7517 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt.zcu)) {
7515 1 => .i32_atomic_load8_u,7518 1 => .i32_atomic_load8_u,
7516 2 => .i32_atomic_load16_u,7519 2 => .i32_atomic_load16_u,
7517 4 => .i32_atomic_load,7520 4 => .i32_atomic_load,
...@@ -7521,7 +7524,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7521,7 +7524,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7521 try func.emitWValue(ptr);7524 try func.emitWValue(ptr);
7522 try func.addAtomicMemArg(tag, .{7525 try func.addAtomicMemArg(tag, .{
7523 .offset = ptr.offset(),7526 .offset = ptr.offset(),
7524 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),7527 .alignment = @intCast(ty.abiAlignment(pt.zcu).toByteUnits().?),
7525 });7528 });
7526 } else {7529 } else {
7527 _ = try func.load(ptr, ty, 0);7530 _ = try func.load(ptr, ty, 0);
...@@ -7532,7 +7535,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7532,7 +7535,7 @@ fn airAtomicLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
75327535
7533fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7536fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7534 const pt = func.pt;7537 const pt = func.pt;
7535 const mod = pt.zcu;7538 const zcu = pt.zcu;
7536 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;7539 const pl_op = func.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
7537 const extra = func.air.extraData(Air.AtomicRmw, pl_op.payload).data;7540 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 {...@@ -7556,7 +7559,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7556 try func.emitWValue(ptr);7559 try func.emitWValue(ptr);
7557 try func.emitWValue(value);7560 try func.emitWValue(value);
7558 if (op == .Nand) {7561 if (op == .Nand) {
7559 const wasm_bits = toWasmBits(@intCast(ty.bitSize(pt))).?;7562 const wasm_bits = toWasmBits(@intCast(ty.bitSize(zcu))).?;
75607563
7561 const and_res = try func.binOp(value, operand, ty, .@"and");7564 const and_res = try func.binOp(value, operand, ty, .@"and");
7562 if (wasm_bits == 32)7565 if (wasm_bits == 32)
...@@ -7573,7 +7576,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7573,7 +7576,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7573 try func.addTag(.select);7576 try func.addTag(.select);
7574 }7577 }
7575 try func.addAtomicMemArg(7578 try func.addAtomicMemArg(
7576 switch (ty.abiSize(pt)) {7579 switch (ty.abiSize(zcu)) {
7577 1 => .i32_atomic_rmw8_cmpxchg_u,7580 1 => .i32_atomic_rmw8_cmpxchg_u,
7578 2 => .i32_atomic_rmw16_cmpxchg_u,7581 2 => .i32_atomic_rmw16_cmpxchg_u,
7579 4 => .i32_atomic_rmw_cmpxchg,7582 4 => .i32_atomic_rmw_cmpxchg,
...@@ -7582,7 +7585,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7582,7 +7585,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7582 },7585 },
7583 .{7586 .{
7584 .offset = ptr.offset(),7587 .offset = ptr.offset(),
7585 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),7588 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
7586 },7589 },
7587 );7590 );
7588 const select_res = try func.allocLocal(ty);7591 const select_res = try func.allocLocal(ty);
...@@ -7601,7 +7604,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7601,7 +7604,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7601 else => {7604 else => {
7602 try func.emitWValue(ptr);7605 try func.emitWValue(ptr);
7603 try func.emitWValue(operand);7606 try func.emitWValue(operand);
7604 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt)) {7607 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(zcu)) {
7605 1 => switch (op) {7608 1 => switch (op) {
7606 .Xchg => .i32_atomic_rmw8_xchg_u,7609 .Xchg => .i32_atomic_rmw8_xchg_u,
7607 .Add => .i32_atomic_rmw8_add_u,7610 .Add => .i32_atomic_rmw8_add_u,
...@@ -7642,7 +7645,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7642,7 +7645,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7642 };7645 };
7643 try func.addAtomicMemArg(tag, .{7646 try func.addAtomicMemArg(tag, .{
7644 .offset = ptr.offset(),7647 .offset = ptr.offset(),
7645 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),7648 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
7646 });7649 });
7647 return func.finishAir(inst, .stack, &.{ pl_op.operand, extra.operand });7650 return func.finishAir(inst, .stack, &.{ pl_op.operand, extra.operand });
7648 },7651 },
...@@ -7670,7 +7673,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7670,7 +7673,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7670 .Xor => .xor,7673 .Xor => .xor,
7671 else => unreachable,7674 else => unreachable,
7672 });7675 });
7673 if (ty.isInt(mod) and (op == .Add or op == .Sub)) {7676 if (ty.isInt(zcu) and (op == .Add or op == .Sub)) {
7674 _ = try func.wrapOperand(.stack, ty);7677 _ = try func.wrapOperand(.stack, ty);
7675 }7678 }
7676 try func.store(.stack, .stack, ty, ptr.offset());7679 try func.store(.stack, .stack, ty, ptr.offset());
...@@ -7686,7 +7689,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7686,7 +7689,7 @@ fn airAtomicRmw(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7686 try func.store(.stack, .stack, ty, ptr.offset());7689 try func.store(.stack, .stack, ty, ptr.offset());
7687 },7690 },
7688 .Nand => {7691 .Nand => {
7689 const wasm_bits = toWasmBits(@intCast(ty.bitSize(pt))).?;7692 const wasm_bits = toWasmBits(@intCast(ty.bitSize(zcu))).?;
76907693
7691 try func.emitWValue(ptr);7694 try func.emitWValue(ptr);
7692 const and_res = try func.binOp(result, operand, ty, .@"and");7695 const and_res = try func.binOp(result, operand, ty, .@"and");
...@@ -7721,16 +7724,16 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7721,16 +7724,16 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77217724
7722fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {7725fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7723 const pt = func.pt;7726 const pt = func.pt;
7724 const mod = pt.zcu;7727 const zcu = pt.zcu;
7725 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7728 const bin_op = func.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
77267729
7727 const ptr = try func.resolveInst(bin_op.lhs);7730 const ptr = try func.resolveInst(bin_op.lhs);
7728 const operand = try func.resolveInst(bin_op.rhs);7731 const operand = try func.resolveInst(bin_op.rhs);
7729 const ptr_ty = func.typeOf(bin_op.lhs);7732 const ptr_ty = func.typeOf(bin_op.lhs);
7730 const ty = ptr_ty.childType(mod);7733 const ty = ptr_ty.childType(zcu);
77317734
7732 if (func.useAtomicFeature()) {7735 if (func.useAtomicFeature()) {
7733 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(pt)) {7736 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(zcu)) {
7734 1 => .i32_atomic_store8,7737 1 => .i32_atomic_store8,
7735 2 => .i32_atomic_store16,7738 2 => .i32_atomic_store16,
7736 4 => .i32_atomic_store,7739 4 => .i32_atomic_store,
...@@ -7741,7 +7744,7 @@ fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7741,7 +7744,7 @@ fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
7741 try func.lowerToStack(operand);7744 try func.lowerToStack(operand);
7742 try func.addAtomicMemArg(tag, .{7745 try func.addAtomicMemArg(tag, .{
7743 .offset = ptr.offset(),7746 .offset = ptr.offset(),
7744 .alignment = @intCast(ty.abiAlignment(pt).toByteUnits().?),7747 .alignment = @intCast(ty.abiAlignment(zcu).toByteUnits().?),
7745 });7748 });
7746 } else {7749 } else {
7747 try func.store(ptr, operand, ty, 0);7750 try func.store(ptr, operand, ty, 0);
...@@ -7760,12 +7763,12 @@ fn airFrameAddress(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -7760,12 +7763,12 @@ fn airFrameAddress(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77607763
7761fn typeOf(func: *CodeGen, inst: Air.Inst.Ref) Type {7764fn typeOf(func: *CodeGen, inst: Air.Inst.Ref) Type {
7762 const pt = func.pt;7765 const pt = func.pt;
7763 const mod = pt.zcu;7766 const zcu = pt.zcu;
7764 return func.air.typeOf(inst, &mod.intern_pool);7767 return func.air.typeOf(inst, &zcu.intern_pool);
7765}7768}
77667769
7767fn typeOfIndex(func: *CodeGen, inst: Air.Inst.Index) Type {7770fn typeOfIndex(func: *CodeGen, inst: Air.Inst.Index) Type {
7768 const pt = func.pt;7771 const pt = func.pt;
7769 const mod = pt.zcu;7772 const zcu = pt.zcu;
7770 return func.air.typeOfIndex(inst, &mod.intern_pool);7773 return func.air.typeOfIndex(inst, &zcu.intern_pool);
7771}7774}
src/arch/wasm/Emit.zig+1-1
...@@ -255,7 +255,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -255,7 +255,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
255 @setCold(true);255 @setCold(true);
256 std.debug.assert(emit.error_msg == null);256 std.debug.assert(emit.error_msg == null);
257 const comp = emit.bin_file.base.comp;257 const comp = emit.bin_file.base.comp;
258 const zcu = comp.module.?;258 const zcu = comp.zcu.?;
259 const gpa = comp.gpa;259 const gpa = comp.gpa;
260 emit.error_msg = try Zcu.ErrorMsg.create(gpa, zcu.navSrcLoc(emit.owner_nav), format, args);260 emit.error_msg = try Zcu.ErrorMsg.create(gpa, zcu.navSrcLoc(emit.owner_nav), format, args);
261 return error.EmitFail;261 return error.EmitFail;
src/arch/wasm/abi.zig+27-29
...@@ -22,16 +22,15 @@ const direct: [2]Class = .{ .direct, .none };...@@ -22,16 +22,15 @@ const direct: [2]Class = .{ .direct, .none };
22/// Classifies a given Zig type to determine how they must be passed22/// Classifies a given Zig type to determine how they must be passed
23/// or returned as value within a wasm function.23/// or returned as value within a wasm function.
24/// When all elements result in `.none`, no value must be passed in or returned.24/// When all elements result in `.none`, no value must be passed in or returned.
25pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {25pub fn classifyType(ty: Type, zcu: *Zcu) [2]Class {
26 const mod = pt.zcu;26 const ip = &zcu.intern_pool;
27 const ip = &mod.intern_pool;27 const target = zcu.getTarget();
28 const target = mod.getTarget();28 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) return none;
29 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) return none;29 switch (ty.zigTypeTag(zcu)) {
30 switch (ty.zigTypeTag(mod)) {
31 .Struct => {30 .Struct => {
32 const struct_type = pt.zcu.typeToStruct(ty).?;31 const struct_type = zcu.typeToStruct(ty).?;
33 if (struct_type.layout == .@"packed") {32 if (struct_type.layout == .@"packed") {
34 if (ty.bitSize(pt) <= 64) return direct;33 if (ty.bitSize(zcu) <= 64) return direct;
35 return .{ .direct, .direct };34 return .{ .direct, .direct };
36 }35 }
37 if (struct_type.field_types.len > 1) {36 if (struct_type.field_types.len > 1) {
...@@ -41,13 +40,13 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {...@@ -41,13 +40,13 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
41 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[0]);40 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[0]);
42 const explicit_align = struct_type.fieldAlign(ip, 0);41 const explicit_align = struct_type.fieldAlign(ip, 0);
43 if (explicit_align != .none) {42 if (explicit_align != .none) {
44 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(pt)))43 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(zcu)))
45 return memory;44 return memory;
46 }45 }
47 return classifyType(field_ty, pt);46 return classifyType(field_ty, zcu);
48 },47 },
49 .Int, .Enum, .ErrorSet => {48 .Int, .Enum, .ErrorSet => {
50 const int_bits = ty.intInfo(pt.zcu).bits;49 const int_bits = ty.intInfo(zcu).bits;
51 if (int_bits <= 64) return direct;50 if (int_bits <= 64) return direct;
52 if (int_bits <= 128) return .{ .direct, .direct };51 if (int_bits <= 128) return .{ .direct, .direct };
53 return memory;52 return memory;
...@@ -62,24 +61,24 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {...@@ -62,24 +61,24 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
62 .Vector => return direct,61 .Vector => return direct,
63 .Array => return memory,62 .Array => return memory,
64 .Optional => {63 .Optional => {
65 assert(ty.isPtrLikeOptional(pt.zcu));64 assert(ty.isPtrLikeOptional(zcu));
66 return direct;65 return direct;
67 },66 },
68 .Pointer => {67 .Pointer => {
69 assert(!ty.isSlice(pt.zcu));68 assert(!ty.isSlice(zcu));
70 return direct;69 return direct;
71 },70 },
72 .Union => {71 .Union => {
73 const union_obj = pt.zcu.typeToUnion(ty).?;72 const union_obj = zcu.typeToUnion(ty).?;
74 if (union_obj.flagsUnordered(ip).layout == .@"packed") {73 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
75 if (ty.bitSize(pt) <= 64) return direct;74 if (ty.bitSize(zcu) <= 64) return direct;
76 return .{ .direct, .direct };75 return .{ .direct, .direct };
77 }76 }
78 const layout = ty.unionGetLayout(pt);77 const layout = ty.unionGetLayout(zcu);
79 assert(layout.tag_size == 0);78 assert(layout.tag_size == 0);
80 if (union_obj.field_types.len > 1) return memory;79 if (union_obj.field_types.len > 1) return memory;
81 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);80 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);
83 },82 },
84 .ErrorUnion,83 .ErrorUnion,
85 .Frame,84 .Frame,
...@@ -101,29 +100,28 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {...@@ -101,29 +100,28 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
101/// Returns the scalar type a given type can represent.100/// Returns the scalar type a given type can represent.
102/// Asserts given type can be represented as scalar, such as101/// Asserts given type can be represented as scalar, such as
103/// a struct with a single scalar field.102/// a struct with a single scalar field.
104pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {103pub fn scalarType(ty: Type, zcu: *Zcu) Type {
105 const mod = pt.zcu;104 const ip = &zcu.intern_pool;
106 const ip = &mod.intern_pool;105 switch (ty.zigTypeTag(zcu)) {
107 switch (ty.zigTypeTag(mod)) {
108 .Struct => {106 .Struct => {
109 if (mod.typeToPackedStruct(ty)) |packed_struct| {107 if (zcu.typeToPackedStruct(ty)) |packed_struct| {
110 return scalarType(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);108 return scalarType(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), zcu);
111 } else {109 } else {
112 assert(ty.structFieldCount(mod) == 1);110 assert(ty.structFieldCount(zcu) == 1);
113 return scalarType(ty.structFieldType(0, mod), pt);111 return scalarType(ty.fieldType(0, zcu), zcu);
114 }112 }
115 },113 },
116 .Union => {114 .Union => {
117 const union_obj = mod.typeToUnion(ty).?;115 const union_obj = zcu.typeToUnion(ty).?;
118 if (union_obj.flagsUnordered(ip).layout != .@"packed") {116 if (union_obj.flagsUnordered(ip).layout != .@"packed") {
119 const layout = pt.getUnionLayout(union_obj);117 const layout = Type.getUnionLayout(union_obj, zcu);
120 if (layout.payload_size == 0 and layout.tag_size != 0) {118 if (layout.payload_size == 0 and layout.tag_size != 0) {
121 return scalarType(ty.unionTagTypeSafety(mod).?, pt);119 return scalarType(ty.unionTagTypeSafety(zcu).?, zcu);
122 }120 }
123 assert(union_obj.field_types.len == 1);121 assert(union_obj.field_types.len == 1);
124 }122 }
125 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);123 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);
127 },125 },
128 else => return ty,126 else => return ty,
129 }127 }
src/arch/x86_64/CodeGen.zig+727-723
...@@ -732,14 +732,14 @@ const FrameAlloc = struct {...@@ -732,14 +732,14 @@ const FrameAlloc = struct {
732 .ref_count = 0,732 .ref_count = 0,
733 };733 };
734 }734 }
735 fn initType(ty: Type, pt: Zcu.PerThread) FrameAlloc {735 fn initType(ty: Type, zcu: *Zcu) FrameAlloc {
736 return init(.{736 return init(.{
737 .size = ty.abiSize(pt),737 .size = ty.abiSize(zcu),
738 .alignment = ty.abiAlignment(pt),738 .alignment = ty.abiAlignment(zcu),
739 });739 });
740 }740 }
741 fn initSpill(ty: Type, pt: Zcu.PerThread) FrameAlloc {741 fn initSpill(ty: Type, zcu: *Zcu) FrameAlloc {
742 const abi_size = ty.abiSize(pt);742 const abi_size = ty.abiSize(zcu);
743 const spill_size = if (abi_size < 8)743 const spill_size = if (abi_size < 8)
744 math.ceilPowerOfTwoAssert(u64, abi_size)744 math.ceilPowerOfTwoAssert(u64, abi_size)
745 else745 else
...@@ -747,7 +747,7 @@ const FrameAlloc = struct {...@@ -747,7 +747,7 @@ const FrameAlloc = struct {
747 return init(.{747 return init(.{
748 .size = spill_size,748 .size = spill_size,
749 .pad = @intCast(spill_size - abi_size),749 .pad = @intCast(spill_size - abi_size),
750 .alignment = ty.abiAlignment(pt).maxStrict(750 .alignment = ty.abiAlignment(zcu).maxStrict(
751 Alignment.fromNonzeroByteUnits(@min(spill_size, 8)),751 Alignment.fromNonzeroByteUnits(@min(spill_size, 8)),
752 ),752 ),
753 });753 });
...@@ -756,7 +756,7 @@ const FrameAlloc = struct {...@@ -756,7 +756,7 @@ const FrameAlloc = struct {
756756
757const StackAllocation = struct {757const StackAllocation = struct {
758 inst: ?Air.Inst.Index,758 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)
760 size: u32,760 size: u32,
761};761};
762762
...@@ -859,11 +859,11 @@ pub fn generate(...@@ -859,11 +859,11 @@ pub fn generate(
859 function.args = call_info.args;859 function.args = call_info.args;
860 function.ret_mcv = call_info.return_value;860 function.ret_mcv = call_info.return_value;
861 function.frame_allocs.set(@intFromEnum(FrameIndex.ret_addr), FrameAlloc.init(.{861 function.frame_allocs.set(@intFromEnum(FrameIndex.ret_addr), FrameAlloc.init(.{
862 .size = Type.usize.abiSize(pt),862 .size = Type.usize.abiSize(zcu),
863 .alignment = Type.usize.abiAlignment(pt).min(call_info.stack_align),863 .alignment = Type.usize.abiAlignment(zcu).min(call_info.stack_align),
864 }));864 }));
865 function.frame_allocs.set(@intFromEnum(FrameIndex.base_ptr), FrameAlloc.init(.{865 function.frame_allocs.set(@intFromEnum(FrameIndex.base_ptr), FrameAlloc.init(.{
866 .size = Type.usize.abiSize(pt),866 .size = Type.usize.abiSize(zcu),
867 .alignment = Alignment.min(867 .alignment = Alignment.min(
868 call_info.stack_align,868 call_info.stack_align,
869 Alignment.fromNonzeroByteUnits(function.target.stackAlignment()),869 Alignment.fromNonzeroByteUnits(function.target.stackAlignment()),
...@@ -1872,8 +1872,8 @@ fn asmMemoryRegisterImmediate(...@@ -1872,8 +1872,8 @@ fn asmMemoryRegisterImmediate(
18721872
1873fn gen(self: *Self) InnerError!void {1873fn gen(self: *Self) InnerError!void {
1874 const pt = self.pt;1874 const pt = self.pt;
1875 const mod = pt.zcu;1875 const zcu = pt.zcu;
1876 const fn_info = mod.typeToFunc(self.fn_type).?;1876 const fn_info = zcu.typeToFunc(self.fn_type).?;
1877 const cc = abi.resolveCallingConvention(fn_info.cc, self.target.*);1877 const cc = abi.resolveCallingConvention(fn_info.cc, self.target.*);
1878 if (cc != .Naked) {1878 if (cc != .Naked) {
1879 try self.asmRegister(.{ ._, .push }, .rbp);1879 try self.asmRegister(.{ ._, .push }, .rbp);
...@@ -1890,7 +1890,7 @@ fn gen(self: *Self) InnerError!void {...@@ -1890,7 +1890,7 @@ fn gen(self: *Self) InnerError!void {
1890 // The address where to store the return value for the caller is in a1890 // The address where to store the return value for the caller is in a
1891 // register which the callee is free to clobber. Therefore, we purposely1891 // register which the callee is free to clobber. Therefore, we purposely
1892 // spill it to stack immediately.1892 // 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));
1894 try self.genSetMem(1894 try self.genSetMem(
1895 .{ .frame = frame_index },1895 .{ .frame = frame_index },
1896 0,1896 0,
...@@ -2099,8 +2099,8 @@ fn checkInvariantsAfterAirInst(self: *Self, inst: Air.Inst.Index, old_air_bookke...@@ -2099,8 +2099,8 @@ fn checkInvariantsAfterAirInst(self: *Self, inst: Air.Inst.Index, old_air_bookke
20992099
2100fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {2100fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
2101 const pt = self.pt;2101 const pt = self.pt;
2102 const mod = pt.zcu;2102 const zcu = pt.zcu;
2103 const ip = &mod.intern_pool;2103 const ip = &zcu.intern_pool;
2104 const air_tags = self.air.instructions.items(.tag);2104 const air_tags = self.air.instructions.items(.tag);
21052105
2106 self.arg_index = 0;2106 self.arg_index = 0;
...@@ -2370,9 +2370,9 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -2370,9 +2370,9 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
23702370
2371fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {2371fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
2372 const pt = self.pt;2372 const pt = self.pt;
2373 const mod = pt.zcu;2373 const zcu = pt.zcu;
2374 const ip = &mod.intern_pool;2374 const ip = &zcu.intern_pool;
2375 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(mod)) {2375 switch (Type.fromInterned(lazy_sym.ty).zigTypeTag(zcu)) {
2376 .Enum => {2376 .Enum => {
2377 const enum_ty = Type.fromInterned(lazy_sym.ty);2377 const enum_ty = Type.fromInterned(lazy_sym.ty);
2378 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});2378 wip_mir_log.debug("{}.@tagName:", .{enum_ty.fmt(pt)});
...@@ -2385,7 +2385,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {...@@ -2385,7 +2385,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
2385 const ret_reg = param_regs[0];2385 const ret_reg = param_regs[0];
2386 const enum_mcv = MCValue{ .register = param_regs[1] };2386 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));
2389 defer self.gpa.free(exitlude_jump_relocs);2389 defer self.gpa.free(exitlude_jump_relocs);
23902390
2391 const data_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);2391 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 {...@@ -2394,7 +2394,7 @@ fn genLazy(self: *Self, lazy_sym: link.File.LazySymbol) InnerError!void {
2394 try self.genLazySymbolRef(.lea, data_reg, .{ .kind = .const_data, .ty = enum_ty.toIntern() });2394 try self.genLazySymbolRef(.lea, data_reg, .{ .kind = .const_data, .ty = enum_ty.toIntern() });
23952395
2396 var data_off: i32 = 0;2396 var data_off: i32 = 0;
2397 const tag_names = enum_ty.enumFields(mod);2397 const tag_names = enum_ty.enumFields(zcu);
2398 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {2398 for (exitlude_jump_relocs, 0..) |*exitlude_jump_reloc, tag_index| {
2399 const tag_name_len = tag_names.get(ip)[tag_index].length(ip);2399 const tag_name_len = tag_names.get(ip)[tag_index].length(ip);
2400 const tag_val = try pt.enumValueFieldIndex(enum_ty, @intCast(tag_index));2400 const tag_val = try pt.enumValueFieldIndex(enum_ty, @intCast(tag_index));
...@@ -2630,14 +2630,14 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {...@@ -2630,14 +2630,14 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
2630/// Use a pointer instruction as the basis for allocating stack memory.2630/// Use a pointer instruction as the basis for allocating stack memory.
2631fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !FrameIndex {2631fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !FrameIndex {
2632 const pt = self.pt;2632 const pt = self.pt;
2633 const mod = pt.zcu;2633 const zcu = pt.zcu;
2634 const ptr_ty = self.typeOfIndex(inst);2634 const ptr_ty = self.typeOfIndex(inst);
2635 const val_ty = ptr_ty.childType(mod);2635 const val_ty = ptr_ty.childType(zcu);
2636 return self.allocFrameIndex(FrameAlloc.init(.{2636 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 {
2638 return self.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});2638 return self.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(pt)});
2639 },2639 },
2640 .alignment = ptr_ty.ptrAlignment(pt).max(.@"1"),2640 .alignment = ptr_ty.ptrAlignment(zcu).max(.@"1"),
2641 }));2641 }));
2642}2642}
26432643
...@@ -2651,20 +2651,20 @@ fn allocTempRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool) !MCValue {...@@ -2651,20 +2651,20 @@ fn allocTempRegOrMem(self: *Self, elem_ty: Type, reg_ok: bool) !MCValue {
26512651
2652fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: bool) !MCValue {2652fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: bool) !MCValue {
2653 const pt = self.pt;2653 const pt = self.pt;
2654 const mod = pt.zcu;2654 const zcu = pt.zcu;
2655 const abi_size = math.cast(u32, ty.abiSize(pt)) orelse {2655 const abi_size = math.cast(u32, ty.abiSize(zcu)) orelse {
2656 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});2656 return self.fail("type '{}' too big to fit into stack frame", .{ty.fmt(pt)});
2657 };2657 };
26582658
2659 if (reg_ok) need_mem: {2659 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)) {
2661 .Float => switch (ty.floatBits(self.target.*)) {2661 .Float => switch (ty.floatBits(self.target.*)) {
2662 16, 32, 64, 128 => 16,2662 16, 32, 64, 128 => 16,
2663 80 => break :need_mem,2663 80 => break :need_mem,
2664 else => unreachable,2664 else => unreachable,
2665 },2665 },
2666 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {2666 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
2667 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {2667 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
2668 16, 32, 64, 128 => if (self.hasFeature(.avx)) 32 else 16,2668 16, 32, 64, 128 => if (self.hasFeature(.avx)) 32 else 16,
2669 80 => break :need_mem,2669 80 => break :need_mem,
2670 else => unreachable,2670 else => unreachable,
...@@ -2679,21 +2679,21 @@ fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: b...@@ -2679,21 +2679,21 @@ fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: b
2679 }2679 }
2680 }2680 }
26812681
2682 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, pt));2682 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ty, zcu));
2683 return .{ .load_frame = .{ .index = frame_index } };2683 return .{ .load_frame = .{ .index = frame_index } };
2684}2684}
26852685
2686fn regClassForType(self: *Self, ty: Type) RegisterManager.RegisterBitSet {2686fn regClassForType(self: *Self, ty: Type) RegisterManager.RegisterBitSet {
2687 const pt = self.pt;2687 const pt = self.pt;
2688 const mod = pt.zcu;2688 const zcu = pt.zcu;
2689 return switch (ty.zigTypeTag(mod)) {2689 return switch (ty.zigTypeTag(zcu)) {
2690 .Float => switch (ty.floatBits(self.target.*)) {2690 .Float => switch (ty.floatBits(self.target.*)) {
2691 80 => abi.RegisterClass.x87,2691 80 => abi.RegisterClass.x87,
2692 else => abi.RegisterClass.sse,2692 else => abi.RegisterClass.sse,
2693 },2693 },
2694 .Vector => switch (ty.childType(mod).toIntern()) {2694 .Vector => switch (ty.childType(zcu).toIntern()) {
2695 .bool_type, .u1_type => abi.RegisterClass.gp,2695 .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)
2697 abi.RegisterClass.gp2697 abi.RegisterClass.gp
2698 else2698 else
2699 abi.RegisterClass.sse,2699 abi.RegisterClass.sse,
...@@ -3001,13 +3001,13 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3001,13 +3001,13 @@ fn airFptrunc(self: *Self, inst: Air.Inst.Index) !void {
30013001
3002fn airFpext(self: *Self, inst: Air.Inst.Index) !void {3002fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
3003 const pt = self.pt;3003 const pt = self.pt;
3004 const mod = pt.zcu;3004 const zcu = pt.zcu;
3005 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3005 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3006 const dst_ty = self.typeOfIndex(inst);3006 const dst_ty = self.typeOfIndex(inst);
3007 const dst_scalar_ty = dst_ty.scalarType(mod);3007 const dst_scalar_ty = dst_ty.scalarType(zcu);
3008 const dst_bits = dst_scalar_ty.floatBits(self.target.*);3008 const dst_bits = dst_scalar_ty.floatBits(self.target.*);
3009 const src_ty = self.typeOf(ty_op.operand);3009 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);
3011 const src_bits = src_scalar_ty.floatBits(self.target.*);3011 const src_bits = src_scalar_ty.floatBits(self.target.*);
30123012
3013 const result = result: {3013 const result = result: {
...@@ -3032,7 +3032,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {...@@ -3032,7 +3032,7 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
3032 },3032 },
3033 else => unreachable,3033 else => unreachable,
3034 }) {3034 }) {
3035 if (dst_ty.isVector(mod)) break :result null;3035 if (dst_ty.isVector(zcu)) break :result null;
3036 var callee_buf: ["__extend?f?f2".len]u8 = undefined;3036 var callee_buf: ["__extend?f?f2".len]u8 = undefined;
3037 break :result try self.genCall(.{ .lib = .{3037 break :result try self.genCall(.{ .lib = .{
3038 .return_type = self.floatCompilerRtAbiType(dst_scalar_ty, src_scalar_ty).toIntern(),3038 .return_type = self.floatCompilerRtAbiType(dst_scalar_ty, src_scalar_ty).toIntern(),
...@@ -3044,18 +3044,18 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {...@@ -3044,18 +3044,18 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
3044 } }, &.{src_scalar_ty}, &.{.{ .air_ref = ty_op.operand }});3044 } }, &.{src_scalar_ty}, &.{.{ .air_ref = ty_op.operand }});
3045 }3045 }
30463046
3047 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));3047 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
3048 const src_mcv = try self.resolveInst(ty_op.operand);3048 const src_mcv = try self.resolveInst(ty_op.operand);
3049 const dst_mcv = if (src_mcv.isRegister() and self.reuseOperand(inst, ty_op.operand, 0, src_mcv))3049 const dst_mcv = if (src_mcv.isRegister() and self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
3050 src_mcv3050 src_mcv
3051 else3051 else
3052 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);3052 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
3053 const dst_reg = dst_mcv.getReg().?;3053 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)));
3055 const dst_lock = self.register_manager.lockReg(dst_reg);3055 const dst_lock = self.register_manager.lockReg(dst_reg);
3056 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);3056 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;
3059 if (src_bits == 16) {3059 if (src_bits == 16) {
3060 assert(self.hasFeature(.f16c));3060 assert(self.hasFeature(.f16c));
3061 const mat_src_reg = if (src_mcv.isRegister())3061 const mat_src_reg = if (src_mcv.isRegister())
...@@ -3137,30 +3137,30 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {...@@ -3137,30 +3137,30 @@ fn airFpext(self: *Self, inst: Air.Inst.Index) !void {
31373137
3138fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {3138fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
3139 const pt = self.pt;3139 const pt = self.pt;
3140 const mod = pt.zcu;3140 const zcu = pt.zcu;
3141 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3141 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3142 const src_ty = self.typeOf(ty_op.operand);3142 const src_ty = self.typeOf(ty_op.operand);
3143 const dst_ty = self.typeOfIndex(inst);3143 const dst_ty = self.typeOfIndex(inst);
31443144
3145 const result = @as(?MCValue, result: {3145 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);3148 const src_int_info = src_ty.intInfo(zcu);
3149 const dst_int_info = dst_ty.intInfo(mod);3149 const dst_int_info = dst_ty.intInfo(zcu);
3150 const extend = switch (src_int_info.signedness) {3150 const extend = switch (src_int_info.signedness) {
3151 .signed => dst_int_info,3151 .signed => dst_int_info,
3152 .unsigned => src_int_info,3152 .unsigned => src_int_info,
3153 }.signedness;3153 }.signedness;
31543154
3155 const src_mcv = try self.resolveInst(ty_op.operand);3155 const src_mcv = try self.resolveInst(ty_op.operand);
3156 if (dst_ty.isVector(mod)) {3156 if (dst_ty.isVector(zcu)) {
3157 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));3157 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
3158 const max_abi_size = @max(dst_abi_size, src_abi_size);3158 const max_abi_size = @max(dst_abi_size, src_abi_size);
3159 if (max_abi_size > @as(u32, if (self.hasFeature(.avx2)) 32 else 16)) break :result null;3159 if (max_abi_size > @as(u32, if (self.hasFeature(.avx2)) 32 else 16)) break :result null;
3160 const has_avx = self.hasFeature(.avx);3160 const has_avx = self.hasFeature(.avx);
31613161
3162 const dst_elem_abi_size = dst_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(mod).abiSize(pt);3163 const src_elem_abi_size = src_ty.childType(zcu).abiSize(zcu);
3164 switch (math.order(dst_elem_abi_size, src_elem_abi_size)) {3164 switch (math.order(dst_elem_abi_size, src_elem_abi_size)) {
3165 .lt => {3165 .lt => {
3166 const mir_tag: Mir.Inst.FixedTag = switch (dst_elem_abi_size) {3166 const mir_tag: Mir.Inst.FixedTag = switch (dst_elem_abi_size) {
...@@ -3396,13 +3396,13 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -3396,13 +3396,13 @@ fn airIntCast(self: *Self, inst: Air.Inst.Index) !void {
33963396
3397fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {3397fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3398 const pt = self.pt;3398 const pt = self.pt;
3399 const mod = pt.zcu;3399 const zcu = pt.zcu;
3400 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3400 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
34013401
3402 const dst_ty = self.typeOfIndex(inst);3402 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));
3404 const src_ty = self.typeOf(ty_op.operand);3404 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
3407 const result = result: {3407 const result = result: {
3408 const src_mcv = try self.resolveInst(ty_op.operand);3408 const src_mcv = try self.resolveInst(ty_op.operand);
...@@ -3414,7 +3414,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3414,7 +3414,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3414 src_mcv3414 src_mcv
3415 else if (dst_abi_size <= 8)3415 else if (dst_abi_size <= 8)
3416 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv)3416 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: {
3418 const dst_regs =3418 const dst_regs =
3419 try self.register_manager.allocRegs(2, .{ inst, inst }, abi.RegisterClass.gp);3419 try self.register_manager.allocRegs(2, .{ inst, inst }, abi.RegisterClass.gp);
3420 const dst_mcv: MCValue = .{ .register_pair = dst_regs };3420 const dst_mcv: MCValue = .{ .register_pair = dst_regs };
...@@ -3429,16 +3429,16 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3429,16 +3429,16 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3429 break :dst dst_mcv;3429 break :dst dst_mcv;
3430 };3430 };
34313431
3432 if (dst_ty.zigTypeTag(mod) == .Vector) {3432 if (dst_ty.zigTypeTag(zcu) == .Vector) {
3433 assert(src_ty.zigTypeTag(mod) == .Vector and dst_ty.vectorLen(mod) == src_ty.vectorLen(mod));3433 assert(src_ty.zigTypeTag(zcu) == .Vector and dst_ty.vectorLen(zcu) == src_ty.vectorLen(zcu));
3434 const dst_elem_ty = dst_ty.childType(mod);3434 const dst_elem_ty = dst_ty.childType(zcu);
3435 const dst_elem_abi_size: u32 = @intCast(dst_elem_ty.abiSize(pt));3435 const dst_elem_abi_size: u32 = @intCast(dst_elem_ty.abiSize(zcu));
3436 const src_elem_ty = src_ty.childType(mod);3436 const src_elem_ty = src_ty.childType(zcu);
3437 const src_elem_abi_size: u32 = @intCast(src_elem_ty.abiSize(pt));3437 const src_elem_abi_size: u32 = @intCast(src_elem_ty.abiSize(zcu));
34383438
3439 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_elem_abi_size) {3439 const mir_tag = @as(?Mir.Inst.FixedTag, switch (dst_elem_abi_size) {
3440 1 => switch (src_elem_abi_size) {3440 1 => switch (src_elem_abi_size) {
3441 2 => switch (dst_ty.vectorLen(mod)) {3441 2 => switch (dst_ty.vectorLen(zcu)) {
3442 1...8 => if (self.hasFeature(.avx)) .{ .vp_b, .ackusw } else .{ .p_b, .ackusw },3442 1...8 => if (self.hasFeature(.avx)) .{ .vp_b, .ackusw } else .{ .p_b, .ackusw },
3443 9...16 => if (self.hasFeature(.avx2)) .{ .vp_b, .ackusw } else null,3443 9...16 => if (self.hasFeature(.avx2)) .{ .vp_b, .ackusw } else null,
3444 else => null,3444 else => null,
...@@ -3446,7 +3446,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3446,7 +3446,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3446 else => null,3446 else => null,
3447 },3447 },
3448 2 => switch (src_elem_abi_size) {3448 2 => switch (src_elem_abi_size) {
3449 4 => switch (dst_ty.vectorLen(mod)) {3449 4 => switch (dst_ty.vectorLen(zcu)) {
3450 1...4 => if (self.hasFeature(.avx))3450 1...4 => if (self.hasFeature(.avx))
3451 .{ .vp_w, .ackusd }3451 .{ .vp_w, .ackusd }
3452 else if (self.hasFeature(.sse4_1))3452 else if (self.hasFeature(.sse4_1))
...@@ -3461,8 +3461,8 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3461,8 +3461,8 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3461 else => null,3461 else => null,
3462 }) orelse return self.fail("TODO implement airTrunc for {}", .{dst_ty.fmt(pt)});3462 }) orelse return self.fail("TODO implement airTrunc for {}", .{dst_ty.fmt(pt)});
34633463
3464 const dst_info = dst_elem_ty.intInfo(mod);3464 const dst_info = dst_elem_ty.intInfo(zcu);
3465 const src_info = src_elem_ty.intInfo(mod);3465 const src_info = src_elem_ty.intInfo(zcu);
34663466
3467 const mask_val = try pt.intValue(src_elem_ty, @as(u64, math.maxInt(u64)) >> @intCast(64 - dst_info.bits));3467 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 {...@@ -3470,7 +3470,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3470 .len = @intCast(@divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits)),3470 .len = @intCast(@divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits)),
3471 .child = src_elem_ty.ip_index,3471 .child = src_elem_ty.ip_index,
3472 });3472 });
3473 const splat_abi_size: u32 = @intCast(splat_ty.abiSize(pt));3473 const splat_abi_size: u32 = @intCast(splat_ty.abiSize(zcu));
34743474
3475 const splat_val = try pt.intern(.{ .aggregate = .{3475 const splat_val = try pt.intern(.{ .aggregate = .{
3476 .ty = splat_ty.ip_index,3476 .ty = splat_ty.ip_index,
...@@ -3528,7 +3528,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3528,7 +3528,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3528 try self.truncateRegister(dst_ty, dst_mcv.register.to64());3528 try self.truncateRegister(dst_ty, dst_mcv.register.to64());
3529 }3529 }
3530 } else if (dst_abi_size <= 16) {3530 } else if (dst_abi_size <= 16) {
3531 const dst_info = dst_ty.intInfo(mod);3531 const dst_info = dst_ty.intInfo(zcu);
3532 const high_ty = try pt.intType(dst_info.signedness, dst_info.bits - 64);3532 const high_ty = try pt.intType(dst_info.signedness, dst_info.bits - 64);
3533 if (self.regExtraBits(high_ty) > 0) {3533 if (self.regExtraBits(high_ty) > 0) {
3534 try self.truncateRegister(high_ty, dst_mcv.register_pair[1].to64());3534 try self.truncateRegister(high_ty, dst_mcv.register_pair[1].to64());
...@@ -3554,12 +3554,12 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {...@@ -3554,12 +3554,12 @@ fn airIntFromBool(self: *Self, inst: Air.Inst.Index) !void {
3554}3554}
35553555
3556fn airSlice(self: *Self, inst: Air.Inst.Index) !void {3556fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
3557 const pt = self.pt;3557 const zcu = self.pt.zcu;
3558 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3558 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3559 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;3559 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
35603560
3561 const slice_ty = self.typeOfIndex(inst);3561 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
3564 const ptr_ty = self.typeOf(bin_op.lhs);3564 const ptr_ty = self.typeOf(bin_op.lhs);
3565 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, .{ .air_ref = bin_op.lhs }, .{});3565 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 {...@@ -3567,7 +3567,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
3567 const len_ty = self.typeOf(bin_op.rhs);3567 const len_ty = self.typeOf(bin_op.rhs);
3568 try self.genSetMem(3568 try self.genSetMem(
3569 .{ .frame = frame_index },3569 .{ .frame = frame_index },
3570 @intCast(ptr_ty.abiSize(pt)),3570 @intCast(ptr_ty.abiSize(zcu)),
3571 len_ty,3571 len_ty,
3572 .{ .air_ref = bin_op.rhs },3572 .{ .air_ref = bin_op.rhs },
3573 .{},3573 .{},
...@@ -3585,14 +3585,14 @@ fn airUnOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {...@@ -3585,14 +3585,14 @@ fn airUnOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
35853585
3586fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {3586fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
3587 const pt = self.pt;3587 const pt = self.pt;
3588 const mod = pt.zcu;3588 const zcu = pt.zcu;
3589 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3589 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3590 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);3590 const dst_mcv = try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs);
35913591
3592 const dst_ty = self.typeOfIndex(inst);3592 const dst_ty = self.typeOfIndex(inst);
3593 if (dst_ty.isAbiInt(mod)) {3593 if (dst_ty.isAbiInt(zcu)) {
3594 const abi_size: u32 = @intCast(dst_ty.abiSize(pt));3594 const abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
3595 const bit_size: u32 = @intCast(dst_ty.bitSize(pt));3595 const bit_size: u32 = @intCast(dst_ty.bitSize(zcu));
3596 if (abi_size * 8 > bit_size) {3596 if (abi_size * 8 > bit_size) {
3597 const dst_lock = switch (dst_mcv) {3597 const dst_lock = switch (dst_mcv) {
3598 .register => |dst_reg| self.register_manager.lockRegAssumeUnused(dst_reg),3598 .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 {...@@ -3607,7 +3607,7 @@ fn airBinOp(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void {
3607 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);3607 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
3608 defer self.register_manager.unlockReg(tmp_lock);3608 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));
3611 const hi_mcv = dst_mcv.address().offset(@intCast(bit_size / 64 * 8)).deref();3611 const hi_mcv = dst_mcv.address().offset(@intCast(bit_size / 64 * 8)).deref();
3612 try self.genSetReg(tmp_reg, hi_ty, hi_mcv, .{});3612 try self.genSetReg(tmp_reg, hi_ty, hi_mcv, .{});
3613 try self.truncateRegister(dst_ty, tmp_reg);3613 try self.truncateRegister(dst_ty, tmp_reg);
...@@ -3627,17 +3627,17 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void...@@ -3627,17 +3627,17 @@ fn airPtrArithmetic(self: *Self, inst: Air.Inst.Index, tag: Air.Inst.Tag) !void
36273627
3628fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {3628fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
3629 const pt = self.pt;3629 const pt = self.pt;
3630 const mod = pt.zcu;3630 const zcu = pt.zcu;
3631 const air_tag = self.air.instructions.items(.tag);3631 const air_tag = self.air.instructions.items(.tag);
3632 const air_data = self.air.instructions.items(.data);3632 const air_data = self.air.instructions.items(.data);
36333633
3634 const dst_ty = self.typeOf(dst_air);3634 const dst_ty = self.typeOf(dst_air);
3635 const dst_info = dst_ty.intInfo(mod);3635 const dst_info = dst_ty.intInfo(zcu);
3636 if (dst_air.toIndex()) |inst| {3636 if (dst_air.toIndex()) |inst| {
3637 switch (air_tag[@intFromEnum(inst)]) {3637 switch (air_tag[@intFromEnum(inst)]) {
3638 .intcast => {3638 .intcast => {
3639 const src_ty = self.typeOf(air_data[@intFromEnum(inst)].ty_op.operand);3639 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);
3641 return @min(switch (src_info.signedness) {3641 return @min(switch (src_info.signedness) {
3642 .signed => switch (dst_info.signedness) {3642 .signed => switch (dst_info.signedness) {
3643 .signed => src_info.bits,3643 .signed => src_info.bits,
...@@ -3653,7 +3653,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {...@@ -3653,7 +3653,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
3653 }3653 }
3654 } else if (dst_air.toInterned()) |ip_index| {3654 } else if (dst_air.toInterned()) |ip_index| {
3655 var space: Value.BigIntSpace = undefined;3655 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);
3657 return @as(u16, @intCast(src_int.bitCountTwosComp())) +3657 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
3658 @intFromBool(src_int.positive and dst_info.signedness == .signed);3658 @intFromBool(src_int.positive and dst_info.signedness == .signed);
3659 }3659 }
...@@ -3662,18 +3662,18 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {...@@ -3662,18 +3662,18 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
36623662
3663fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {3663fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3664 const pt = self.pt;3664 const pt = self.pt;
3665 const mod = pt.zcu;3665 const zcu = pt.zcu;
3666 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3666 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3667 const result = result: {3667 const result = result: {
3668 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];3668 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
3669 const dst_ty = self.typeOfIndex(inst);3669 const dst_ty = self.typeOfIndex(inst);
3670 switch (dst_ty.zigTypeTag(mod)) {3670 switch (dst_ty.zigTypeTag(zcu)) {
3671 .Float, .Vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),3671 .Float, .Vector => break :result try self.genBinOp(inst, tag, bin_op.lhs, bin_op.rhs),
3672 else => {},3672 else => {},
3673 }3673 }
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);
3677 const src_ty = try pt.intType(dst_info.signedness, switch (tag) {3677 const src_ty = try pt.intType(dst_info.signedness, switch (tag) {
3678 else => unreachable,3678 else => unreachable,
3679 .mul, .mul_wrap => @max(3679 .mul, .mul_wrap => @max(
...@@ -3683,20 +3683,20 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3683,20 +3683,20 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3683 ),3683 ),
3684 .div_trunc, .div_floor, .div_exact, .rem, .mod => dst_info.bits,3684 .div_trunc, .div_floor, .div_exact, .rem, .mod => dst_info.bits,
3685 });3685 });
3686 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));3686 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
36873687
3688 if (dst_abi_size == 16 and src_abi_size == 16) switch (tag) {3688 if (dst_abi_size == 16 and src_abi_size == 16) switch (tag) {
3689 else => unreachable,3689 else => unreachable,
3690 .mul, .mul_wrap => {},3690 .mul, .mul_wrap => {},
3691 .div_trunc, .div_floor, .div_exact, .rem, .mod => {3691 .div_trunc, .div_floor, .div_exact, .rem, .mod => {
3692 const signed = dst_ty.isSignedInt(mod);3692 const signed = dst_ty.isSignedInt(zcu);
3693 var callee_buf: ["__udiv?i3".len]u8 = undefined;3693 var callee_buf: ["__udiv?i3".len]u8 = undefined;
3694 const signed_div_floor_state: struct {3694 const signed_div_floor_state: struct {
3695 frame_index: FrameIndex,3695 frame_index: FrameIndex,
3696 state: State,3696 state: State,
3697 reloc: Mir.Inst.Index,3697 reloc: Mir.Inst.Index,
3698 } = if (signed and tag == .div_floor) state: {3698 } = 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));
3700 try self.asmMemoryImmediate(3700 try self.asmMemoryImmediate(
3701 .{ ._, .mov },3701 .{ ._, .mov },
3702 .{ .base = .{ .frame = frame_index }, .mod = .{ .rm = .{ .size = .qword } } },3702 .{ .base = .{ .frame = frame_index }, .mod = .{ .rm = .{ .size = .qword } } },
...@@ -3771,7 +3771,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3771,7 +3771,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3771 .rem, .mod => "mod",3771 .rem, .mod => "mod",
3772 else => unreachable,3772 else => unreachable,
3773 },3773 },
3774 intCompilerRtAbiName(@intCast(dst_ty.bitSize(pt))),3774 intCompilerRtAbiName(@intCast(dst_ty.bitSize(zcu))),
3775 }) catch unreachable,3775 }) catch unreachable,
3776 } },3776 } },
3777 &.{ src_ty, src_ty },3777 &.{ src_ty, src_ty },
...@@ -3800,7 +3800,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3800,7 +3800,7 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
3800 .return_type = dst_ty.toIntern(),3800 .return_type = dst_ty.toIntern(),
3801 .param_types = &.{ src_ty.toIntern(), src_ty.toIntern() },3801 .param_types = &.{ src_ty.toIntern(), src_ty.toIntern() },
3802 .callee = std.fmt.bufPrint(&callee_buf, "__div{c}i3", .{3802 .callee = std.fmt.bufPrint(&callee_buf, "__div{c}i3", .{
3803 intCompilerRtAbiName(@intCast(dst_ty.bitSize(pt))),3803 intCompilerRtAbiName(@intCast(dst_ty.bitSize(zcu))),
3804 }) catch unreachable,3804 }) catch unreachable,
3805 } },3805 } },
3806 &.{ src_ty, src_ty },3806 &.{ src_ty, src_ty },
...@@ -3892,10 +3892,10 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -3892,10 +3892,10 @@ fn airMulDivBinOp(self: *Self, inst: Air.Inst.Index) !void {
38923892
3893fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {3893fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
3894 const pt = self.pt;3894 const pt = self.pt;
3895 const mod = pt.zcu;3895 const zcu = pt.zcu;
3896 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3896 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3897 const ty = self.typeOf(bin_op.lhs);3897 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(
3899 "TODO implement airAddSat for {}",3899 "TODO implement airAddSat for {}",
3900 .{ty.fmt(pt)},3900 .{ty.fmt(pt)},
3901 );3901 );
...@@ -3923,7 +3923,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3923,7 +3923,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
39233923
3924 const reg_bits = self.regBitSize(ty);3924 const reg_bits = self.regBitSize(ty);
3925 const reg_extra_bits = self.regExtraBits(ty);3925 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: {
3927 if (reg_extra_bits > 0) {3927 if (reg_extra_bits > 0) {
3928 try self.genShiftBinOpMir(3928 try self.genShiftBinOpMir(
3929 .{ ._l, .sa },3929 .{ ._l, .sa },
...@@ -3962,7 +3962,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3962,7 +3962,7 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
3962 break :cc .o;3962 break :cc .o;
3963 } else cc: {3963 } else cc: {
3964 try self.genSetReg(limit_reg, ty, .{3964 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)),
3966 }, .{});3966 }, .{});
39673967
3968 try self.genBinOpMir(.{ ._, .add }, ty, dst_mcv, rhs_mcv);3968 try self.genBinOpMir(.{ ._, .add }, ty, dst_mcv, rhs_mcv);
...@@ -3973,14 +3973,14 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3973,14 +3973,14 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
3973 break :cc .c;3973 break :cc .c;
3974 };3974 };
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);
3977 try self.asmCmovccRegisterRegister(3977 try self.asmCmovccRegisterRegister(
3978 cc,3978 cc,
3979 registerAlias(dst_reg, cmov_abi_size),3979 registerAlias(dst_reg, cmov_abi_size),
3980 registerAlias(limit_reg, cmov_abi_size),3980 registerAlias(limit_reg, cmov_abi_size),
3981 );3981 );
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(
3984 .{ ._r, .sa },3984 .{ ._r, .sa },
3985 ty,3985 ty,
3986 dst_mcv,3986 dst_mcv,
...@@ -3993,10 +3993,10 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -3993,10 +3993,10 @@ fn airAddSat(self: *Self, inst: Air.Inst.Index) !void {
39933993
3994fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {3994fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
3995 const pt = self.pt;3995 const pt = self.pt;
3996 const mod = pt.zcu;3996 const zcu = pt.zcu;
3997 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3997 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3998 const ty = self.typeOf(bin_op.lhs);3998 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(
4000 "TODO implement airSubSat for {}",4000 "TODO implement airSubSat for {}",
4001 .{ty.fmt(pt)},4001 .{ty.fmt(pt)},
4002 );4002 );
...@@ -4024,7 +4024,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4024,7 +4024,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
40244024
4025 const reg_bits = self.regBitSize(ty);4025 const reg_bits = self.regBitSize(ty);
4026 const reg_extra_bits = self.regExtraBits(ty);4026 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: {
4028 if (reg_extra_bits > 0) {4028 if (reg_extra_bits > 0) {
4029 try self.genShiftBinOpMir(4029 try self.genShiftBinOpMir(
4030 .{ ._l, .sa },4030 .{ ._l, .sa },
...@@ -4067,14 +4067,14 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4067,14 +4067,14 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
4067 break :cc .c;4067 break :cc .c;
4068 };4068 };
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);
4071 try self.asmCmovccRegisterRegister(4071 try self.asmCmovccRegisterRegister(
4072 cc,4072 cc,
4073 registerAlias(dst_reg, cmov_abi_size),4073 registerAlias(dst_reg, cmov_abi_size),
4074 registerAlias(limit_reg, cmov_abi_size),4074 registerAlias(limit_reg, cmov_abi_size),
4075 );4075 );
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(
4078 .{ ._r, .sa },4078 .{ ._r, .sa },
4079 ty,4079 ty,
4080 dst_mcv,4080 dst_mcv,
...@@ -4087,7 +4087,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4087,7 +4087,7 @@ fn airSubSat(self: *Self, inst: Air.Inst.Index) !void {
40874087
4088fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {4088fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
4089 const pt = self.pt;4089 const pt = self.pt;
4090 const mod = pt.zcu;4090 const zcu = pt.zcu;
4091 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4091 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4092 const ty = self.typeOf(bin_op.lhs);4092 const ty = self.typeOf(bin_op.lhs);
40934093
...@@ -4170,7 +4170,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4170,7 +4170,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
4170 break :result dst_mcv;4170 break :result dst_mcv;
4171 }4171 }
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(
4174 "TODO implement airMulSat for {}",4174 "TODO implement airMulSat for {}",
4175 .{ty.fmt(pt)},4175 .{ty.fmt(pt)},
4176 );4176 );
...@@ -4199,7 +4199,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4199,7 +4199,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
4199 defer self.register_manager.unlockReg(limit_lock);4199 defer self.register_manager.unlockReg(limit_lock);
42004200
4201 const reg_bits = self.regBitSize(ty);4201 const reg_bits = self.regBitSize(ty);
4202 const cc: Condition = if (ty.isSignedInt(mod)) cc: {4202 const cc: Condition = if (ty.isSignedInt(zcu)) cc: {
4203 try self.genSetReg(limit_reg, ty, lhs_mcv, .{});4203 try self.genSetReg(limit_reg, ty, lhs_mcv, .{});
4204 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, rhs_mcv);4204 try self.genBinOpMir(.{ ._, .xor }, ty, limit_mcv, rhs_mcv);
4205 try self.genShiftBinOpMir(4205 try self.genShiftBinOpMir(
...@@ -4221,7 +4221,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4221,7 +4221,7 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
4221 };4221 };
42224222
4223 const dst_mcv = try self.genMulDivBinOp(.mul, inst, ty, ty, lhs_mcv, rhs_mcv);4223 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);
4225 try self.asmCmovccRegisterRegister(4225 try self.asmCmovccRegisterRegister(
4226 cc,4226 cc,
4227 registerAlias(dst_mcv.register, cmov_abi_size),4227 registerAlias(dst_mcv.register, cmov_abi_size),
...@@ -4234,13 +4234,13 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -4234,13 +4234,13 @@ fn airMulSat(self: *Self, inst: Air.Inst.Index) !void {
42344234
4235fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {4235fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4236 const pt = self.pt;4236 const pt = self.pt;
4237 const mod = pt.zcu;4237 const zcu = pt.zcu;
4238 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4238 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4239 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;4239 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
4240 const result: MCValue = result: {4240 const result: MCValue = result: {
4241 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];4241 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
4242 const ty = self.typeOf(bin_op.lhs);4242 const ty = self.typeOf(bin_op.lhs);
4243 switch (ty.zigTypeTag(mod)) {4243 switch (ty.zigTypeTag(zcu)) {
4244 .Vector => return self.fail("TODO implement add/sub with overflow for Vector type", .{}),4244 .Vector => return self.fail("TODO implement add/sub with overflow for Vector type", .{}),
4245 .Int => {4245 .Int => {
4246 try self.spillEflagsIfOccupied();4246 try self.spillEflagsIfOccupied();
...@@ -4253,7 +4253,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4253,7 +4253,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4253 .sub_with_overflow => .sub,4253 .sub_with_overflow => .sub,
4254 else => unreachable,4254 else => unreachable,
4255 }, bin_op.lhs, bin_op.rhs);4255 }, bin_op.lhs, bin_op.rhs);
4256 const int_info = ty.intInfo(mod);4256 const int_info = ty.intInfo(zcu);
4257 const cc: Condition = switch (int_info.signedness) {4257 const cc: Condition = switch (int_info.signedness) {
4258 .unsigned => .c,4258 .unsigned => .c,
4259 .signed => .o,4259 .signed => .o,
...@@ -4270,17 +4270,17 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4270,17 +4270,17 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4270 }4270 }
42714271
4272 const frame_index =4272 const frame_index =
4273 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));4273 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
4274 try self.genSetMem(4274 try self.genSetMem(
4275 .{ .frame = frame_index },4275 .{ .frame = frame_index },
4276 @intCast(tuple_ty.structFieldOffset(1, pt)),4276 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4277 Type.u1,4277 Type.u1,
4278 .{ .eflags = cc },4278 .{ .eflags = cc },
4279 .{},4279 .{},
4280 );4280 );
4281 try self.genSetMem(4281 try self.genSetMem(
4282 .{ .frame = frame_index },4282 .{ .frame = frame_index },
4283 @intCast(tuple_ty.structFieldOffset(0, pt)),4283 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4284 ty,4284 ty,
4285 partial_mcv,4285 partial_mcv,
4286 .{},4286 .{},
...@@ -4289,7 +4289,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4289,7 +4289,7 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4289 }4289 }
42904290
4291 const frame_index =4291 const frame_index =
4292 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));4292 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
4293 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);4293 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);
4294 break :result .{ .load_frame = .{ .index = frame_index } };4294 break :result .{ .load_frame = .{ .index = frame_index } };
4295 },4295 },
...@@ -4301,13 +4301,13 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4301,13 +4301,13 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
43014301
4302fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {4302fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4303 const pt = self.pt;4303 const pt = self.pt;
4304 const mod = pt.zcu;4304 const zcu = pt.zcu;
4305 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4305 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4306 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;4306 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
4307 const result: MCValue = result: {4307 const result: MCValue = result: {
4308 const lhs_ty = self.typeOf(bin_op.lhs);4308 const lhs_ty = self.typeOf(bin_op.lhs);
4309 const rhs_ty = self.typeOf(bin_op.rhs);4309 const rhs_ty = self.typeOf(bin_op.rhs);
4310 switch (lhs_ty.zigTypeTag(mod)) {4310 switch (lhs_ty.zigTypeTag(zcu)) {
4311 .Vector => return self.fail("TODO implement shl with overflow for Vector type", .{}),4311 .Vector => return self.fail("TODO implement shl with overflow for Vector type", .{}),
4312 .Int => {4312 .Int => {
4313 try self.spillEflagsIfOccupied();4313 try self.spillEflagsIfOccupied();
...@@ -4318,7 +4318,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4318,7 +4318,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4318 const lhs = try self.resolveInst(bin_op.lhs);4318 const lhs = try self.resolveInst(bin_op.lhs);
4319 const rhs = try self.resolveInst(bin_op.rhs);4319 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
4323 const partial_mcv = try self.genShiftBinOp(.shl, null, lhs, rhs, lhs_ty, rhs_ty);4323 const partial_mcv = try self.genShiftBinOp(.shl, null, lhs, rhs, lhs_ty, rhs_ty);
4324 const partial_lock = switch (partial_mcv) {4324 const partial_lock = switch (partial_mcv) {
...@@ -4348,18 +4348,18 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4348,18 +4348,18 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4348 }4348 }
43494349
4350 const frame_index =4350 const frame_index =
4351 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));4351 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
4352 try self.genSetMem(4352 try self.genSetMem(
4353 .{ .frame = frame_index },4353 .{ .frame = frame_index },
4354 @intCast(tuple_ty.structFieldOffset(1, pt)),4354 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4355 tuple_ty.structFieldType(1, mod),4355 tuple_ty.fieldType(1, zcu),
4356 .{ .eflags = cc },4356 .{ .eflags = cc },
4357 .{},4357 .{},
4358 );4358 );
4359 try self.genSetMem(4359 try self.genSetMem(
4360 .{ .frame = frame_index },4360 .{ .frame = frame_index },
4361 @intCast(tuple_ty.structFieldOffset(0, pt)),4361 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4362 tuple_ty.structFieldType(0, mod),4362 tuple_ty.fieldType(0, zcu),
4363 partial_mcv,4363 partial_mcv,
4364 .{},4364 .{},
4365 );4365 );
...@@ -4367,7 +4367,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4367,7 +4367,7 @@ fn airShlWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4367 }4367 }
43684368
4369 const frame_index =4369 const frame_index =
4370 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, pt));4370 try self.allocFrameIndex(FrameAlloc.initSpill(tuple_ty, zcu));
4371 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);4371 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);
4372 break :result .{ .load_frame = .{ .index = frame_index } };4372 break :result .{ .load_frame = .{ .index = frame_index } };
4373 },4373 },
...@@ -4385,15 +4385,15 @@ fn genSetFrameTruncatedOverflowCompare(...@@ -4385,15 +4385,15 @@ fn genSetFrameTruncatedOverflowCompare(
4385 overflow_cc: ?Condition,4385 overflow_cc: ?Condition,
4386) !void {4386) !void {
4387 const pt = self.pt;4387 const pt = self.pt;
4388 const mod = pt.zcu;4388 const zcu = pt.zcu;
4389 const src_lock = switch (src_mcv) {4389 const src_lock = switch (src_mcv) {
4390 .register => |reg| self.register_manager.lockReg(reg),4390 .register => |reg| self.register_manager.lockReg(reg),
4391 else => null,4391 else => null,
4392 };4392 };
4393 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);4393 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
43944394
4395 const ty = tuple_ty.structFieldType(0, mod);4395 const ty = tuple_ty.fieldType(0, zcu);
4396 const int_info = ty.intInfo(mod);4396 const int_info = ty.intInfo(zcu);
43974397
4398 const hi_bits = (int_info.bits - 1) % 64 + 1;4398 const hi_bits = (int_info.bits - 1) % 64 + 1;
4399 const hi_ty = try pt.intType(int_info.signedness, hi_bits);4399 const hi_ty = try pt.intType(int_info.signedness, hi_bits);
...@@ -4432,7 +4432,7 @@ fn genSetFrameTruncatedOverflowCompare(...@@ -4432,7 +4432,7 @@ fn genSetFrameTruncatedOverflowCompare(
4432 );4432 );
4433 }4433 }
44344434
4435 const payload_off: i32 = @intCast(tuple_ty.structFieldOffset(0, pt));4435 const payload_off: i32 = @intCast(tuple_ty.structFieldOffset(0, zcu));
4436 if (hi_limb_off > 0) try self.genSetMem(4436 if (hi_limb_off > 0) try self.genSetMem(
4437 .{ .frame = frame_index },4437 .{ .frame = frame_index },
4438 payload_off,4438 payload_off,
...@@ -4449,8 +4449,8 @@ fn genSetFrameTruncatedOverflowCompare(...@@ -4449,8 +4449,8 @@ fn genSetFrameTruncatedOverflowCompare(
4449 );4449 );
4450 try self.genSetMem(4450 try self.genSetMem(
4451 .{ .frame = frame_index },4451 .{ .frame = frame_index },
4452 @intCast(tuple_ty.structFieldOffset(1, pt)),4452 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4453 tuple_ty.structFieldType(1, mod),4453 tuple_ty.fieldType(1, zcu),
4454 if (overflow_cc) |_| .{ .register = overflow_reg.to8() } else .{ .eflags = .ne },4454 if (overflow_cc) |_| .{ .register = overflow_reg.to8() } else .{ .eflags = .ne },
4455 .{},4455 .{},
4456 );4456 );
...@@ -4458,18 +4458,18 @@ fn genSetFrameTruncatedOverflowCompare(...@@ -4458,18 +4458,18 @@ fn genSetFrameTruncatedOverflowCompare(
44584458
4459fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {4459fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4460 const pt = self.pt;4460 const pt = self.pt;
4461 const mod = pt.zcu;4461 const zcu = pt.zcu;
4462 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4462 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4463 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;4463 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
4464 const tuple_ty = self.typeOfIndex(inst);4464 const tuple_ty = self.typeOfIndex(inst);
4465 const dst_ty = self.typeOf(bin_op.lhs);4465 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)) {
4467 .Vector => return self.fail("TODO implement airMulWithOverflow for {}", .{dst_ty.fmt(pt)}),4467 .Vector => return self.fail("TODO implement airMulWithOverflow for {}", .{dst_ty.fmt(pt)}),
4468 .Int => result: {4468 .Int => result: {
4469 const dst_info = dst_ty.intInfo(mod);4469 const dst_info = dst_ty.intInfo(zcu);
4470 if (dst_info.bits > 128 and dst_info.signedness == .unsigned) {4470 if (dst_info.bits > 128 and dst_info.signedness == .unsigned) {
4471 const slow_inc = self.hasFeature(.slow_incdec);4471 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));
4473 const limb_len = math.divCeil(u32, abi_size, 8) catch unreachable;4473 const limb_len = math.divCeil(u32, abi_size, 8) catch unreachable;
44744474
4475 try self.spillRegisters(&.{ .rax, .rcx, .rdx });4475 try self.spillRegisters(&.{ .rax, .rcx, .rdx });
...@@ -4480,7 +4480,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4480,7 +4480,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4480 try self.genInlineMemset(4480 try self.genInlineMemset(
4481 dst_mcv.address(),4481 dst_mcv.address(),
4482 .{ .immediate = 0 },4482 .{ .immediate = 0 },
4483 .{ .immediate = tuple_ty.abiSize(pt) },4483 .{ .immediate = tuple_ty.abiSize(zcu) },
4484 .{},4484 .{},
4485 );4485 );
4486 const lhs_mcv = try self.resolveInst(bin_op.lhs);4486 const lhs_mcv = try self.resolveInst(bin_op.lhs);
...@@ -4520,7 +4520,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4520,7 +4520,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4520 .index = temp_regs[3].to64(),4520 .index = temp_regs[3].to64(),
4521 .scale = .@"8",4521 .scale = .@"8",
4522 .disp = dst_mcv.load_frame.off +4522 .disp = dst_mcv.load_frame.off +
4523 @as(i32, @intCast(tuple_ty.structFieldOffset(0, pt))),4523 @as(i32, @intCast(tuple_ty.structFieldOffset(0, zcu))),
4524 } },4524 } },
4525 }, .rdx);4525 }, .rdx);
4526 try self.asmSetccRegister(.c, .cl);4526 try self.asmSetccRegister(.c, .cl);
...@@ -4544,7 +4544,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4544,7 +4544,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4544 .index = temp_regs[3].to64(),4544 .index = temp_regs[3].to64(),
4545 .scale = .@"8",4545 .scale = .@"8",
4546 .disp = dst_mcv.load_frame.off +4546 .disp = dst_mcv.load_frame.off +
4547 @as(i32, @intCast(tuple_ty.structFieldOffset(0, pt))),4547 @as(i32, @intCast(tuple_ty.structFieldOffset(0, zcu))),
4548 } },4548 } },
4549 }, .rax);4549 }, .rax);
4550 try self.asmSetccRegister(.c, .ch);4550 try self.asmSetccRegister(.c, .ch);
...@@ -4593,7 +4593,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4593,7 +4593,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4593 .mod = .{ .rm = .{4593 .mod = .{ .rm = .{
4594 .size = .byte,4594 .size = .byte,
4595 .disp = dst_mcv.load_frame.off +4595 .disp = dst_mcv.load_frame.off +
4596 @as(i32, @intCast(tuple_ty.structFieldOffset(1, pt))),4596 @as(i32, @intCast(tuple_ty.structFieldOffset(1, zcu))),
4597 } },4597 } },
4598 }, Immediate.u(1));4598 }, Immediate.u(1));
4599 self.performReloc(no_overflow);4599 self.performReloc(no_overflow);
...@@ -4636,8 +4636,8 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4636,8 +4636,8 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4636 const dst_mcv = try self.allocRegOrMem(inst, false);4636 const dst_mcv = try self.allocRegOrMem(inst, false);
4637 try self.genSetMem(4637 try self.genSetMem(
4638 .{ .frame = dst_mcv.load_frame.index },4638 .{ .frame = dst_mcv.load_frame.index },
4639 @intCast(tuple_ty.structFieldOffset(0, pt)),4639 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4640 tuple_ty.structFieldType(0, mod),4640 tuple_ty.fieldType(0, zcu),
4641 result,4641 result,
4642 .{},4642 .{},
4643 );4643 );
...@@ -4648,8 +4648,8 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4648,8 +4648,8 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4648 );4648 );
4649 try self.genSetMem(4649 try self.genSetMem(
4650 .{ .frame = dst_mcv.load_frame.index },4650 .{ .frame = dst_mcv.load_frame.index },
4651 @intCast(tuple_ty.structFieldOffset(1, pt)),4651 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4652 tuple_ty.structFieldType(1, mod),4652 tuple_ty.fieldType(1, zcu),
4653 .{ .eflags = .ne },4653 .{ .eflags = .ne },
4654 .{},4654 .{},
4655 );4655 );
...@@ -4760,15 +4760,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4760,15 +4760,15 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4760 const dst_mcv = try self.allocRegOrMem(inst, false);4760 const dst_mcv = try self.allocRegOrMem(inst, false);
4761 try self.genSetMem(4761 try self.genSetMem(
4762 .{ .frame = dst_mcv.load_frame.index },4762 .{ .frame = dst_mcv.load_frame.index },
4763 @intCast(tuple_ty.structFieldOffset(0, pt)),4763 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4764 tuple_ty.structFieldType(0, mod),4764 tuple_ty.fieldType(0, zcu),
4765 .{ .register_pair = .{ .rax, .rdx } },4765 .{ .register_pair = .{ .rax, .rdx } },
4766 .{},4766 .{},
4767 );4767 );
4768 try self.genSetMem(4768 try self.genSetMem(
4769 .{ .frame = dst_mcv.load_frame.index },4769 .{ .frame = dst_mcv.load_frame.index },
4770 @intCast(tuple_ty.structFieldOffset(1, pt)),4770 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4771 tuple_ty.structFieldType(1, mod),4771 tuple_ty.fieldType(1, zcu),
4772 .{ .register = tmp_regs[1] },4772 .{ .register = tmp_regs[1] },
4773 .{},4773 .{},
4774 );4774 );
...@@ -4800,7 +4800,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4800,7 +4800,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4800 self.eflags_inst = inst;4800 self.eflags_inst = inst;
4801 break :result .{ .register_overflow = .{ .reg = reg, .eflags = cc } };4801 break :result .{ .register_overflow = .{ .reg = reg, .eflags = cc } };
4802 } else {4802 } 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));
4804 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);4804 try self.genSetFrameTruncatedOverflowCompare(tuple_ty, frame_index, partial_mcv, cc);
4805 break :result .{ .load_frame = .{ .index = frame_index } };4805 break :result .{ .load_frame = .{ .index = frame_index } };
4806 },4806 },
...@@ -4811,19 +4811,19 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4811,19 +4811,19 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4811 src_ty.fmt(pt), dst_ty.fmt(pt),4811 src_ty.fmt(pt), dst_ty.fmt(pt),
4812 });4812 });
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));
4815 if (dst_info.bits >= lhs_active_bits + rhs_active_bits) {4815 if (dst_info.bits >= lhs_active_bits + rhs_active_bits) {
4816 try self.genSetMem(4816 try self.genSetMem(
4817 .{ .frame = frame_index },4817 .{ .frame = frame_index },
4818 @intCast(tuple_ty.structFieldOffset(0, pt)),4818 @intCast(tuple_ty.structFieldOffset(0, zcu)),
4819 tuple_ty.structFieldType(0, mod),4819 tuple_ty.fieldType(0, zcu),
4820 partial_mcv,4820 partial_mcv,
4821 .{},4821 .{},
4822 );4822 );
4823 try self.genSetMem(4823 try self.genSetMem(
4824 .{ .frame = frame_index },4824 .{ .frame = frame_index },
4825 @intCast(tuple_ty.structFieldOffset(1, pt)),4825 @intCast(tuple_ty.structFieldOffset(1, zcu)),
4826 tuple_ty.structFieldType(1, mod),4826 tuple_ty.fieldType(1, zcu),
4827 .{ .immediate = 0 }, // cc being set is impossible4827 .{ .immediate = 0 }, // cc being set is impossible
4828 .{},4828 .{},
4829 );4829 );
...@@ -4847,7 +4847,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {...@@ -4847,7 +4847,7 @@ fn airMulWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
4847/// Quotient is saved in .rax and remainder in .rdx.4847/// Quotient is saved in .rax and remainder in .rdx.
4848fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue, rhs: MCValue) !void {4848fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue, rhs: MCValue) !void {
4849 const pt = self.pt;4849 const pt = self.pt;
4850 const abi_size: u32 = @intCast(ty.abiSize(pt));4850 const abi_size: u32 = @intCast(ty.abiSize(pt.zcu));
4851 const bit_size: u32 = @intCast(self.regBitSize(ty));4851 const bit_size: u32 = @intCast(self.regBitSize(ty));
4852 if (abi_size > 8) {4852 if (abi_size > 8) {
4853 return self.fail("TODO implement genIntMulDivOpMir for ABI size larger than 8", .{});4853 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...@@ -4897,9 +4897,9 @@ fn genIntMulDivOpMir(self: *Self, tag: Mir.Inst.FixedTag, ty: Type, lhs: MCValue
4897/// Clobbers .rax and .rdx registers.4897/// Clobbers .rax and .rdx registers.
4898fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCValue {4898fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCValue {
4899 const pt = self.pt;4899 const pt = self.pt;
4900 const mod = pt.zcu;4900 const zcu = pt.zcu;
4901 const abi_size: u32 = @intCast(ty.abiSize(pt));4901 const abi_size: u32 = @intCast(ty.abiSize(zcu));
4902 const int_info = ty.intInfo(mod);4902 const int_info = ty.intInfo(zcu);
4903 const dividend = switch (lhs) {4903 const dividend = switch (lhs) {
4904 .register => |reg| reg,4904 .register => |reg| reg,
4905 else => try self.copyToTmpRegister(ty, lhs),4905 else => try self.copyToTmpRegister(ty, lhs),
...@@ -4950,7 +4950,7 @@ fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCVa...@@ -4950,7 +4950,7 @@ fn genInlineIntDivFloor(self: *Self, ty: Type, lhs: MCValue, rhs: MCValue) !MCVa
49504950
4951fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {4951fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4952 const pt = self.pt;4952 const pt = self.pt;
4953 const mod = pt.zcu;4953 const zcu = pt.zcu;
4954 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4954 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
49554955
4956 const air_tags = self.air.instructions.items(.tag);4956 const air_tags = self.air.instructions.items(.tag);
...@@ -4958,7 +4958,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -4958,7 +4958,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4958 const lhs_ty = self.typeOf(bin_op.lhs);4958 const lhs_ty = self.typeOf(bin_op.lhs);
4959 const rhs_ty = self.typeOf(bin_op.rhs);4959 const rhs_ty = self.typeOf(bin_op.rhs);
4960 const result: MCValue = result: {4960 const result: MCValue = result: {
4961 switch (lhs_ty.zigTypeTag(mod)) {4961 switch (lhs_ty.zigTypeTag(zcu)) {
4962 .Int => {4962 .Int => {
4963 try self.spillRegisters(&.{.rcx});4963 try self.spillRegisters(&.{.rcx});
4964 try self.register_manager.getKnownReg(.rcx, null);4964 try self.register_manager.getKnownReg(.rcx, null);
...@@ -4977,7 +4977,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -4977,7 +4977,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4977 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);4977 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
4978 defer self.register_manager.unlockReg(tmp_lock);4978 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));
4981 const tmp_ty = if (lhs_bits > 64) Type.usize else lhs_ty;4981 const tmp_ty = if (lhs_bits > 64) Type.usize else lhs_ty;
4982 const off = frame_addr.off + (lhs_bits - 1) / 64 * 8;4982 const off = frame_addr.off + (lhs_bits - 1) / 64 * 8;
4983 try self.genSetReg(4983 try self.genSetReg(
...@@ -5001,14 +5001,14 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5001,14 +5001,14 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5001 }5001 }
5002 break :result dst_mcv;5002 break :result dst_mcv;
5003 },5003 },
5004 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {5004 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
5005 .Int => if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.childType(mod).intInfo(mod).bits) {5005 .Int => if (@as(?Mir.Inst.FixedTag, switch (lhs_ty.childType(zcu).intInfo(zcu).bits) {
5006 else => null,5006 else => null,
5007 16 => switch (lhs_ty.vectorLen(mod)) {5007 16 => switch (lhs_ty.vectorLen(zcu)) {
5008 else => null,5008 else => null,
5009 1...8 => switch (tag) {5009 1...8 => switch (tag) {
5010 else => unreachable,5010 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) {
5012 .signed => if (self.hasFeature(.avx))5012 .signed => if (self.hasFeature(.avx))
5013 .{ .vp_w, .sra }5013 .{ .vp_w, .sra }
5014 else5014 else
...@@ -5025,18 +5025,18 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5025,18 +5025,18 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5025 },5025 },
5026 9...16 => switch (tag) {5026 9...16 => switch (tag) {
5027 else => unreachable,5027 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) {
5029 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .sra } else null,5029 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .sra } else null,
5030 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_w, .srl } else null,5030 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_w, .srl } else null,
5031 },5031 },
5032 .shl, .shl_exact => if (self.hasFeature(.avx2)) .{ .vp_w, .sll } else null,5032 .shl, .shl_exact => if (self.hasFeature(.avx2)) .{ .vp_w, .sll } else null,
5033 },5033 },
5034 },5034 },
5035 32 => switch (lhs_ty.vectorLen(mod)) {5035 32 => switch (lhs_ty.vectorLen(zcu)) {
5036 else => null,5036 else => null,
5037 1...4 => switch (tag) {5037 1...4 => switch (tag) {
5038 else => unreachable,5038 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) {
5040 .signed => if (self.hasFeature(.avx))5040 .signed => if (self.hasFeature(.avx))
5041 .{ .vp_d, .sra }5041 .{ .vp_d, .sra }
5042 else5042 else
...@@ -5053,18 +5053,18 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5053,18 +5053,18 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5053 },5053 },
5054 5...8 => switch (tag) {5054 5...8 => switch (tag) {
5055 else => unreachable,5055 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) {
5057 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .sra } else null,5057 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .sra } else null,
5058 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_d, .srl } else null,5058 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_d, .srl } else null,
5059 },5059 },
5060 .shl, .shl_exact => if (self.hasFeature(.avx2)) .{ .vp_d, .sll } else null,5060 .shl, .shl_exact => if (self.hasFeature(.avx2)) .{ .vp_d, .sll } else null,
5061 },5061 },
5062 },5062 },
5063 64 => switch (lhs_ty.vectorLen(mod)) {5063 64 => switch (lhs_ty.vectorLen(zcu)) {
5064 else => null,5064 else => null,
5065 1...2 => switch (tag) {5065 1...2 => switch (tag) {
5066 else => unreachable,5066 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) {
5068 .signed => if (self.hasFeature(.avx))5068 .signed => if (self.hasFeature(.avx))
5069 .{ .vp_q, .sra }5069 .{ .vp_q, .sra }
5070 else5070 else
...@@ -5081,7 +5081,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5081,7 +5081,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5081 },5081 },
5082 3...4 => switch (tag) {5082 3...4 => switch (tag) {
5083 else => unreachable,5083 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) {
5085 .signed => if (self.hasFeature(.avx2)) .{ .vp_q, .sra } else null,5085 .signed => if (self.hasFeature(.avx2)) .{ .vp_q, .sra } else null,
5086 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_q, .srl } else null,5086 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_q, .srl } else null,
5087 },5087 },
...@@ -5089,10 +5089,10 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5089,10 +5089,10 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5089 },5089 },
5090 },5090 },
5091 })) |mir_tag| if (try self.air.value(bin_op.rhs, pt)) |rhs_val| {5091 })) |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())) {
5093 .aggregate => |rhs_aggregate| switch (rhs_aggregate.storage) {5093 .aggregate => |rhs_aggregate| switch (rhs_aggregate.storage) {
5094 .repeated_elem => |rhs_elem| {5094 .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
5097 const lhs_mcv = try self.resolveInst(bin_op.lhs);5097 const lhs_mcv = try self.resolveInst(bin_op.lhs);
5098 const dst_reg, const lhs_reg = if (lhs_mcv.isRegister() and5098 const dst_reg, const lhs_reg = if (lhs_mcv.isRegister() and
...@@ -5112,7 +5112,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5112,7 +5112,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5112 self.register_manager.unlockReg(lock);5112 self.register_manager.unlockReg(lock);
51135113
5114 const shift_imm =5114 const shift_imm =
5115 Immediate.u(@intCast(Value.fromInterned(rhs_elem).toUnsignedInt(pt)));5115 Immediate.u(@intCast(Value.fromInterned(rhs_elem).toUnsignedInt(zcu)));
5116 if (self.hasFeature(.avx)) try self.asmRegisterRegisterImmediate(5116 if (self.hasFeature(.avx)) try self.asmRegisterRegisterImmediate(
5117 mir_tag,5117 mir_tag,
5118 registerAlias(dst_reg, abi_size),5118 registerAlias(dst_reg, abi_size),
...@@ -5134,7 +5134,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5134,7 +5134,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5134 }5134 }
5135 } else if (bin_op.rhs.toIndex()) |rhs_inst| switch (air_tags[@intFromEnum(rhs_inst)]) {5135 } else if (bin_op.rhs.toIndex()) |rhs_inst| switch (air_tags[@intFromEnum(rhs_inst)]) {
5136 .splat => {5136 .splat => {
5137 const abi_size: u32 = @intCast(lhs_ty.abiSize(pt));5137 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
51385138
5139 const lhs_mcv = try self.resolveInst(bin_op.lhs);5139 const lhs_mcv = try self.resolveInst(bin_op.lhs);
5140 const dst_reg, const lhs_reg = if (lhs_mcv.isRegister() and5140 const dst_reg, const lhs_reg = if (lhs_mcv.isRegister() and
...@@ -5161,7 +5161,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -5161,7 +5161,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
5161 const mask_mcv = try self.genTypedValue(Value.fromInterned(try pt.intern(.{ .aggregate = .{5161 const mask_mcv = try self.genTypedValue(Value.fromInterned(try pt.intern(.{ .aggregate = .{
5162 .ty = mask_ty.toIntern(),5162 .ty = mask_ty.toIntern(),
5163 .storage = .{ .elems = &([1]InternPool.Index{5163 .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(),
5165 } ++ [1]InternPool.Index{5165 } ++ [1]InternPool.Index{
5166 (try pt.intValue(Type.u8, 0)).toIntern(),5166 (try pt.intValue(Type.u8, 0)).toIntern(),
5167 } ** 15) },5167 } ** 15) },
...@@ -5224,11 +5224,11 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {...@@ -5224,11 +5224,11 @@ fn airShlSat(self: *Self, inst: Air.Inst.Index) !void {
5224}5224}
52255225
5226fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {5226fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
5227 const pt = self.pt;5227 const zcu = self.pt.zcu;
5228 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5228 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5229 const result: MCValue = result: {5229 const result: MCValue = result: {
5230 const pl_ty = self.typeOfIndex(inst);5230 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
5233 const opt_mcv = try self.resolveInst(ty_op.operand);5233 const opt_mcv = try self.resolveInst(ty_op.operand);
5234 if (self.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {5234 if (self.reuseOperand(inst, ty_op.operand, 0, opt_mcv)) {
...@@ -5271,15 +5271,15 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5271,15 +5271,15 @@ fn airOptionalPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
52715271
5272fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {5272fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
5273 const pt = self.pt;5273 const pt = self.pt;
5274 const mod = pt.zcu;5274 const zcu = pt.zcu;
5275 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5275 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5276 const result = result: {5276 const result = result: {
5277 const dst_ty = self.typeOfIndex(inst);5277 const dst_ty = self.typeOfIndex(inst);
5278 const src_ty = self.typeOf(ty_op.operand);5278 const src_ty = self.typeOf(ty_op.operand);
5279 const opt_ty = src_ty.childType(mod);5279 const opt_ty = src_ty.childType(zcu);
5280 const src_mcv = try self.resolveInst(ty_op.operand);5280 const src_mcv = try self.resolveInst(ty_op.operand);
52815281
5282 if (opt_ty.optionalReprIsPayload(mod)) {5282 if (opt_ty.optionalReprIsPayload(zcu)) {
5283 break :result if (self.liveness.isUnused(inst))5283 break :result if (self.liveness.isUnused(inst))
5284 .unreach5284 .unreach
5285 else if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv))5285 else if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
...@@ -5296,8 +5296,8 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -5296,8 +5296,8 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
5296 else5296 else
5297 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);5297 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
52985298
5299 const pl_ty = dst_ty.childType(mod);5299 const pl_ty = dst_ty.childType(zcu);
5300 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(pt));5300 const pl_abi_size: i32 = @intCast(pl_ty.abiSize(zcu));
5301 try self.genSetMem(5301 try self.genSetMem(
5302 .{ .reg = dst_mcv.getReg().? },5302 .{ .reg = dst_mcv.getReg().? },
5303 pl_abi_size,5303 pl_abi_size,
...@@ -5312,23 +5312,23 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -5312,23 +5312,23 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
53125312
5313fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {5313fn airUnwrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
5314 const pt = self.pt;5314 const pt = self.pt;
5315 const mod = pt.zcu;5315 const zcu = pt.zcu;
5316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5316 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5317 const err_union_ty = self.typeOf(ty_op.operand);5317 const err_union_ty = self.typeOf(ty_op.operand);
5318 const err_ty = err_union_ty.errorUnionSet(mod);5318 const err_ty = err_union_ty.errorUnionSet(zcu);
5319 const payload_ty = err_union_ty.errorUnionPayload(mod);5319 const payload_ty = err_union_ty.errorUnionPayload(zcu);
5320 const operand = try self.resolveInst(ty_op.operand);5320 const operand = try self.resolveInst(ty_op.operand);
53215321
5322 const result: MCValue = result: {5322 const result: MCValue = result: {
5323 if (err_ty.errorSetIsEmpty(mod)) {5323 if (err_ty.errorSetIsEmpty(zcu)) {
5324 break :result MCValue{ .immediate = 0 };5324 break :result MCValue{ .immediate = 0 };
5325 }5325 }
53265326
5327 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {5327 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5328 break :result operand;5328 break :result operand;
5329 }5329 }
53305330
5331 const err_off = errUnionErrorOffset(payload_ty, pt);5331 const err_off = errUnionErrorOffset(payload_ty, zcu);
5332 switch (operand) {5332 switch (operand) {
5333 .register => |reg| {5333 .register => |reg| {
5334 // TODO reuse operand5334 // TODO reuse operand
...@@ -5366,7 +5366,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -5366,7 +5366,7 @@ fn airUnwrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
5366// *(E!T) -> E5366// *(E!T) -> E
5367fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {5367fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
5368 const pt = self.pt;5368 const pt = self.pt;
5369 const mod = pt.zcu;5369 const zcu = pt.zcu;
5370 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5370 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
53715371
5372 const src_ty = self.typeOf(ty_op.operand);5372 const src_ty = self.typeOf(ty_op.operand);
...@@ -5383,11 +5383,11 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5383,11 +5383,11 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
5383 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);5383 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
5384 defer self.register_manager.unlockReg(dst_lock);5384 defer self.register_manager.unlockReg(dst_lock);
53855385
5386 const eu_ty = src_ty.childType(mod);5386 const eu_ty = src_ty.childType(zcu);
5387 const pl_ty = eu_ty.errorUnionPayload(mod);5387 const pl_ty = eu_ty.errorUnionPayload(zcu);
5388 const err_ty = eu_ty.errorUnionSet(mod);5388 const err_ty = eu_ty.errorUnionSet(zcu);
5389 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));5389 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
5390 const err_abi_size: u32 = @intCast(err_ty.abiSize(pt));5390 const err_abi_size: u32 = @intCast(err_ty.abiSize(zcu));
5391 try self.asmRegisterMemory(5391 try self.asmRegisterMemory(
5392 .{ ._, .mov },5392 .{ ._, .mov },
5393 registerAlias(dst_reg, err_abi_size),5393 registerAlias(dst_reg, err_abi_size),
...@@ -5414,7 +5414,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5414,7 +5414,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
54145414
5415fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {5415fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
5416 const pt = self.pt;5416 const pt = self.pt;
5417 const mod = pt.zcu;5417 const zcu = pt.zcu;
5418 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5418 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5419 const result: MCValue = result: {5419 const result: MCValue = result: {
5420 const src_ty = self.typeOf(ty_op.operand);5420 const src_ty = self.typeOf(ty_op.operand);
...@@ -5426,11 +5426,11 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -5426,11 +5426,11 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
5426 const src_lock = self.register_manager.lockRegAssumeUnused(src_reg);5426 const src_lock = self.register_manager.lockRegAssumeUnused(src_reg);
5427 defer self.register_manager.unlockReg(src_lock);5427 defer self.register_manager.unlockReg(src_lock);
54285428
5429 const eu_ty = src_ty.childType(mod);5429 const eu_ty = src_ty.childType(zcu);
5430 const pl_ty = eu_ty.errorUnionPayload(mod);5430 const pl_ty = eu_ty.errorUnionPayload(zcu);
5431 const err_ty = eu_ty.errorUnionSet(mod);5431 const err_ty = eu_ty.errorUnionSet(zcu);
5432 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));5432 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
5433 const err_abi_size: u32 = @intCast(err_ty.abiSize(pt));5433 const err_abi_size: u32 = @intCast(err_ty.abiSize(zcu));
5434 try self.asmMemoryImmediate(5434 try self.asmMemoryImmediate(
5435 .{ ._, .mov },5435 .{ ._, .mov },
5436 .{5436 .{
...@@ -5453,8 +5453,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {...@@ -5453,8 +5453,8 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
5453 const dst_lock = self.register_manager.lockReg(dst_reg);5453 const dst_lock = self.register_manager.lockReg(dst_reg);
5454 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);5454 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
54555455
5456 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));5456 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
5457 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));5457 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
5458 try self.asmRegisterMemory(5458 try self.asmRegisterMemory(
5459 .{ ._, .lea },5459 .{ ._, .lea },
5460 registerAlias(dst_reg, dst_abi_size),5460 registerAlias(dst_reg, dst_abi_size),
...@@ -5475,13 +5475,13 @@ fn genUnwrapErrUnionPayloadMir(...@@ -5475,13 +5475,13 @@ fn genUnwrapErrUnionPayloadMir(
5475 err_union: MCValue,5475 err_union: MCValue,
5476) !MCValue {5476) !MCValue {
5477 const pt = self.pt;5477 const pt = self.pt;
5478 const mod = pt.zcu;5478 const zcu = pt.zcu;
5479 const payload_ty = err_union_ty.errorUnionPayload(mod);5479 const payload_ty = err_union_ty.errorUnionPayload(zcu);
54805480
5481 const result: MCValue = result: {5481 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));
5485 switch (err_union) {5485 switch (err_union) {
5486 .load_frame => |frame_addr| break :result .{ .load_frame = .{5486 .load_frame => |frame_addr| break :result .{ .load_frame = .{
5487 .index = frame_addr.index,5487 .index = frame_addr.index,
...@@ -5525,12 +5525,12 @@ fn genUnwrapErrUnionPayloadPtrMir(...@@ -5525,12 +5525,12 @@ fn genUnwrapErrUnionPayloadPtrMir(
5525 ptr_mcv: MCValue,5525 ptr_mcv: MCValue,
5526) !MCValue {5526) !MCValue {
5527 const pt = self.pt;5527 const pt = self.pt;
5528 const mod = pt.zcu;5528 const zcu = pt.zcu;
5529 const err_union_ty = ptr_ty.childType(mod);5529 const err_union_ty = ptr_ty.childType(zcu);
5530 const payload_ty = err_union_ty.errorUnionPayload(mod);5530 const payload_ty = err_union_ty.errorUnionPayload(zcu);
55315531
5532 const result: MCValue = result: {5532 const result: MCValue = result: {
5533 const payload_off = errUnionPayloadOffset(payload_ty, pt);5533 const payload_off = errUnionPayloadOffset(payload_ty, zcu);
5534 const result_mcv: MCValue = if (maybe_inst) |inst|5534 const result_mcv: MCValue = if (maybe_inst) |inst|
5535 try self.copyToRegisterWithInstTracking(inst, ptr_ty, ptr_mcv)5535 try self.copyToRegisterWithInstTracking(inst, ptr_ty, ptr_mcv)
5536 else5536 else
...@@ -5560,15 +5560,15 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {...@@ -5560,15 +5560,15 @@ fn airSaveErrReturnTraceIndex(self: *Self, inst: Air.Inst.Index) !void {
55605560
5561fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {5561fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
5562 const pt = self.pt;5562 const pt = self.pt;
5563 const mod = pt.zcu;5563 const zcu = pt.zcu;
5564 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5564 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5565 const result: MCValue = result: {5565 const result: MCValue = result: {
5566 const pl_ty = self.typeOf(ty_op.operand);5566 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
5569 const opt_ty = self.typeOfIndex(inst);5569 const opt_ty = self.typeOfIndex(inst);
5570 const pl_mcv = try self.resolveInst(ty_op.operand);5570 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);
5572 if (same_repr and self.reuseOperand(inst, ty_op.operand, 0, pl_mcv)) break :result pl_mcv;5572 if (same_repr and self.reuseOperand(inst, ty_op.operand, 0, pl_mcv)) break :result pl_mcv;
55735573
5574 const pl_lock: ?RegisterLock = switch (pl_mcv) {5574 const pl_lock: ?RegisterLock = switch (pl_mcv) {
...@@ -5581,7 +5581,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -5581,7 +5581,7 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
5581 try self.genCopy(pl_ty, opt_mcv, pl_mcv, .{});5581 try self.genCopy(pl_ty, opt_mcv, pl_mcv, .{});
55825582
5583 if (!same_repr) {5583 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));
5585 switch (opt_mcv) {5585 switch (opt_mcv) {
5586 else => unreachable,5586 else => unreachable,
55875587
...@@ -5615,20 +5615,20 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {...@@ -5615,20 +5615,20 @@ fn airWrapOptional(self: *Self, inst: Air.Inst.Index) !void {
5615/// T to E!T5615/// T to E!T
5616fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {5616fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
5617 const pt = self.pt;5617 const pt = self.pt;
5618 const mod = pt.zcu;5618 const zcu = pt.zcu;
5619 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5619 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56205620
5621 const eu_ty = ty_op.ty.toType();5621 const eu_ty = ty_op.ty.toType();
5622 const pl_ty = eu_ty.errorUnionPayload(mod);5622 const pl_ty = eu_ty.errorUnionPayload(zcu);
5623 const err_ty = eu_ty.errorUnionSet(mod);5623 const err_ty = eu_ty.errorUnionSet(zcu);
5624 const operand = try self.resolveInst(ty_op.operand);5624 const operand = try self.resolveInst(ty_op.operand);
56255625
5626 const result: MCValue = result: {5626 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));5629 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
5630 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));5630 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
5631 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));5631 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
5632 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand, .{});5632 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, operand, .{});
5633 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 }, .{});5633 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, .{ .immediate = 0 }, .{});
5634 break :result .{ .load_frame = .{ .index = frame_index } };5634 break :result .{ .load_frame = .{ .index = frame_index } };
...@@ -5639,19 +5639,19 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {...@@ -5639,19 +5639,19 @@ fn airWrapErrUnionPayload(self: *Self, inst: Air.Inst.Index) !void {
5639/// E to E!T5639/// E to E!T
5640fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {5640fn airWrapErrUnionErr(self: *Self, inst: Air.Inst.Index) !void {
5641 const pt = self.pt;5641 const pt = self.pt;
5642 const mod = pt.zcu;5642 const zcu = pt.zcu;
5643 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5643 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
56445644
5645 const eu_ty = ty_op.ty.toType();5645 const eu_ty = ty_op.ty.toType();
5646 const pl_ty = eu_ty.errorUnionPayload(mod);5646 const pl_ty = eu_ty.errorUnionPayload(zcu);
5647 const err_ty = eu_ty.errorUnionSet(mod);5647 const err_ty = eu_ty.errorUnionSet(zcu);
56485648
5649 const result: MCValue = result: {5649 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));5652 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(eu_ty, zcu));
5653 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, pt));5653 const pl_off: i32 = @intCast(errUnionPayloadOffset(pl_ty, zcu));
5654 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, pt));5654 const err_off: i32 = @intCast(errUnionErrorOffset(pl_ty, zcu));
5655 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .undef, .{});5655 try self.genSetMem(.{ .frame = frame_index }, pl_off, pl_ty, .undef, .{});
5656 const operand = try self.resolveInst(ty_op.operand);5656 const operand = try self.resolveInst(ty_op.operand);
5657 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand, .{});5657 try self.genSetMem(.{ .frame = frame_index }, err_off, err_ty, operand, .{});
...@@ -5719,7 +5719,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5719,7 +5719,7 @@ fn airPtrSliceLenPtr(self: *Self, inst: Air.Inst.Index) !void {
5719 const dst_lock = self.register_manager.lockReg(dst_reg);5719 const dst_lock = self.register_manager.lockReg(dst_reg);
5720 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);5720 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));
5723 try self.asmRegisterMemory(5723 try self.asmRegisterMemory(
5724 .{ ._, .lea },5724 .{ ._, .lea },
5725 registerAlias(dst_reg, dst_abi_size),5725 registerAlias(dst_reg, dst_abi_size),
...@@ -5767,7 +5767,7 @@ fn elemOffset(self: *Self, index_ty: Type, index: MCValue, elem_size: u64) !Regi...@@ -5767,7 +5767,7 @@ fn elemOffset(self: *Self, index_ty: Type, index: MCValue, elem_size: u64) !Regi
57675767
5768fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {5768fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
5769 const pt = self.pt;5769 const pt = self.pt;
5770 const mod = pt.zcu;5770 const zcu = pt.zcu;
5771 const slice_ty = self.typeOf(lhs);5771 const slice_ty = self.typeOf(lhs);
5772 const slice_mcv = try self.resolveInst(lhs);5772 const slice_mcv = try self.resolveInst(lhs);
5773 const slice_mcv_lock: ?RegisterLock = switch (slice_mcv) {5773 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 {...@@ -5776,9 +5776,9 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
5776 };5776 };
5777 defer if (slice_mcv_lock) |lock| self.register_manager.unlockReg(lock);5777 defer if (slice_mcv_lock) |lock| self.register_manager.unlockReg(lock);
57785778
5779 const elem_ty = slice_ty.childType(mod);5779 const elem_ty = slice_ty.childType(zcu);
5780 const elem_size = elem_ty.abiSize(pt);5780 const elem_size = elem_ty.abiSize(zcu);
5781 const slice_ptr_field_type = slice_ty.slicePtrFieldType(mod);5781 const slice_ptr_field_type = slice_ty.slicePtrFieldType(zcu);
57825782
5783 const index_ty = self.typeOf(rhs);5783 const index_ty = self.typeOf(rhs);
5784 const index_mcv = try self.resolveInst(rhs);5784 const index_mcv = try self.resolveInst(rhs);
...@@ -5804,15 +5804,15 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {...@@ -5804,15 +5804,15 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
58045804
5805fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {5805fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
5806 const pt = self.pt;5806 const pt = self.pt;
5807 const mod = pt.zcu;5807 const zcu = pt.zcu;
5808 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5808 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
58095809
5810 const result: MCValue = result: {5810 const result: MCValue = result: {
5811 const elem_ty = self.typeOfIndex(inst);5811 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
5814 const slice_ty = self.typeOf(bin_op.lhs);5814 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);
5816 const elem_ptr = try self.genSliceElemPtr(bin_op.lhs, bin_op.rhs);5816 const elem_ptr = try self.genSliceElemPtr(bin_op.lhs, bin_op.rhs);
5817 const dst_mcv = try self.allocRegOrMem(inst, false);5817 const dst_mcv = try self.allocRegOrMem(inst, false);
5818 try self.load(dst_mcv, slice_ptr_field_type, elem_ptr);5818 try self.load(dst_mcv, slice_ptr_field_type, elem_ptr);
...@@ -5830,12 +5830,12 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -5830,12 +5830,12 @@ fn airSliceElemPtr(self: *Self, inst: Air.Inst.Index) !void {
58305830
5831fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {5831fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
5832 const pt = self.pt;5832 const pt = self.pt;
5833 const mod = pt.zcu;5833 const zcu = pt.zcu;
5834 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5834 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
58355835
5836 const result: MCValue = result: {5836 const result: MCValue = result: {
5837 const array_ty = self.typeOf(bin_op.lhs);5837 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
5840 const array_mcv = try self.resolveInst(bin_op.lhs);5840 const array_mcv = try self.resolveInst(bin_op.lhs);
5841 const array_lock: ?RegisterLock = switch (array_mcv) {5841 const array_lock: ?RegisterLock = switch (array_mcv) {
...@@ -5853,7 +5853,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5853,7 +5853,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
5853 defer if (index_lock) |lock| self.register_manager.unlockReg(lock);5853 defer if (index_lock) |lock| self.register_manager.unlockReg(lock);
58545854
5855 try self.spillEflagsIfOccupied();5855 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) {
5857 const index_reg = switch (index_mcv) {5857 const index_reg = switch (index_mcv) {
5858 .register => |reg| reg,5858 .register => |reg| reg,
5859 else => try self.copyToTmpRegister(index_ty, index_mcv),5859 else => try self.copyToTmpRegister(index_ty, index_mcv),
...@@ -5866,7 +5866,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5866,7 +5866,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
5866 index_reg.to64(),5866 index_reg.to64(),
5867 ),5867 ),
5868 .sse => {5868 .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));
5870 try self.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv, .{});5870 try self.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv, .{});
5871 try self.asmMemoryRegister(5871 try self.asmMemoryRegister(
5872 .{ ._, .bt },5872 .{ ._, .bt },
...@@ -5904,14 +5904,14 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5904,14 +5904,14 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
5904 break :result .{ .register = dst_reg };5904 break :result .{ .register = dst_reg };
5905 }5905 }
59065906
5907 const elem_abi_size = elem_ty.abiSize(pt);5907 const elem_abi_size = elem_ty.abiSize(zcu);
5908 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);5908 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
5909 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);5909 const addr_lock = self.register_manager.lockRegAssumeUnused(addr_reg);
5910 defer self.register_manager.unlockReg(addr_lock);5910 defer self.register_manager.unlockReg(addr_lock);
59115911
5912 switch (array_mcv) {5912 switch (array_mcv) {
5913 .register => {5913 .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));
5915 try self.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv, .{});5915 try self.genSetMem(.{ .frame = frame_index }, 0, array_ty, array_mcv, .{});
5916 try self.asmRegisterMemory(5916 try self.asmRegisterMemory(
5917 .{ ._, .lea },5917 .{ ._, .lea },
...@@ -5960,7 +5960,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5960,7 +5960,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
59605960
5961fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {5961fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
5962 const pt = self.pt;5962 const pt = self.pt;
5963 const mod = pt.zcu;5963 const zcu = pt.zcu;
5964 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5964 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5965 const ptr_ty = self.typeOf(bin_op.lhs);5965 const ptr_ty = self.typeOf(bin_op.lhs);
59665966
...@@ -5968,10 +5968,10 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -5968,10 +5968,10 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
5968 // additional `mov` is needed at the end to get the actual value5968 // additional `mov` is needed at the end to get the actual value
59695969
5970 const result = result: {5970 const result = result: {
5971 const elem_ty = ptr_ty.elemType2(mod);5971 const elem_ty = ptr_ty.elemType2(zcu);
5972 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;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));
5975 const index_ty = self.typeOf(bin_op.rhs);5975 const index_ty = self.typeOf(bin_op.rhs);
5976 const index_mcv = try self.resolveInst(bin_op.rhs);5976 const index_mcv = try self.resolveInst(bin_op.rhs);
5977 const index_lock = switch (index_mcv) {5977 const index_lock = switch (index_mcv) {
...@@ -6011,7 +6011,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -6011,7 +6011,7 @@ fn airPtrElemVal(self: *Self, inst: Air.Inst.Index) !void {
60116011
6012fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {6012fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
6013 const pt = self.pt;6013 const pt = self.pt;
6014 const mod = pt.zcu;6014 const zcu = pt.zcu;
6015 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6015 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6016 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;6016 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 {...@@ -6026,15 +6026,15 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
6026 };6026 };
6027 defer if (base_ptr_lock) |lock| self.register_manager.unlockReg(lock);6027 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) {
6030 break :result if (self.reuseOperand(inst, extra.lhs, 0, base_ptr_mcv))6030 break :result if (self.reuseOperand(inst, extra.lhs, 0, base_ptr_mcv))
6031 base_ptr_mcv6031 base_ptr_mcv
6032 else6032 else
6033 try self.copyToRegisterWithInstTracking(inst, elem_ptr_ty, base_ptr_mcv);6033 try self.copyToRegisterWithInstTracking(inst, elem_ptr_ty, base_ptr_mcv);
6034 }6034 }
60356035
6036 const elem_ty = base_ptr_ty.elemType2(mod);6036 const elem_ty = base_ptr_ty.elemType2(zcu);
6037 const elem_abi_size = elem_ty.abiSize(pt);6037 const elem_abi_size = elem_ty.abiSize(zcu);
6038 const index_ty = self.typeOf(extra.rhs);6038 const index_ty = self.typeOf(extra.rhs);
6039 const index_mcv = try self.resolveInst(extra.rhs);6039 const index_mcv = try self.resolveInst(extra.rhs);
6040 const index_lock: ?RegisterLock = switch (index_mcv) {6040 const index_lock: ?RegisterLock = switch (index_mcv) {
...@@ -6057,12 +6057,12 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -6057,12 +6057,12 @@ fn airPtrElemPtr(self: *Self, inst: Air.Inst.Index) !void {
60576057
6058fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {6058fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
6059 const pt = self.pt;6059 const pt = self.pt;
6060 const mod = pt.zcu;6060 const zcu = pt.zcu;
6061 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6061 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6062 const ptr_union_ty = self.typeOf(bin_op.lhs);6062 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);
6064 const tag_ty = self.typeOf(bin_op.rhs);6064 const tag_ty = self.typeOf(bin_op.rhs);
6065 const layout = union_ty.unionGetLayout(pt);6065 const layout = union_ty.unionGetLayout(zcu);
60666066
6067 if (layout.tag_size == 0) {6067 if (layout.tag_size == 0) {
6068 return self.finishAir(inst, .none, .{ bin_op.lhs, bin_op.rhs, .none });6068 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 {...@@ -6101,12 +6101,12 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
6101}6101}
61026102
6103fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {6103fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
6104 const pt = self.pt;6104 const zcu = self.pt.zcu;
6105 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6105 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61066106
6107 const tag_ty = self.typeOfIndex(inst);6107 const tag_ty = self.typeOfIndex(inst);
6108 const union_ty = self.typeOf(ty_op.operand);6108 const union_ty = self.typeOf(ty_op.operand);
6109 const layout = union_ty.unionGetLayout(pt);6109 const layout = union_ty.unionGetLayout(zcu);
61106110
6111 if (layout.tag_size == 0) {6111 if (layout.tag_size == 0) {
6112 return self.finishAir(inst, .none, .{ ty_op.operand, .none, .none });6112 return self.finishAir(inst, .none, .{ ty_op.operand, .none, .none });
...@@ -6120,7 +6120,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {...@@ -6120,7 +6120,7 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
6120 };6120 };
6121 defer if (operand_lock) |lock| self.register_manager.unlockReg(lock);6121 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);
6124 const dst_mcv: MCValue = blk: {6124 const dst_mcv: MCValue = blk: {
6125 switch (operand) {6125 switch (operand) {
6126 .load_frame => |frame_addr| {6126 .load_frame => |frame_addr| {
...@@ -6159,14 +6159,14 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {...@@ -6159,14 +6159,14 @@ fn airGetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
61596159
6160fn airClz(self: *Self, inst: Air.Inst.Index) !void {6160fn airClz(self: *Self, inst: Air.Inst.Index) !void {
6161 const pt = self.pt;6161 const pt = self.pt;
6162 const mod = pt.zcu;6162 const zcu = pt.zcu;
6163 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6163 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6164 const result = result: {6164 const result = result: {
6165 try self.spillEflagsIfOccupied();6165 try self.spillEflagsIfOccupied();
61666166
6167 const dst_ty = self.typeOfIndex(inst);6167 const dst_ty = self.typeOfIndex(inst);
6168 const src_ty = self.typeOf(ty_op.operand);6168 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 {}", .{
6170 src_ty.fmt(pt),6170 src_ty.fmt(pt),
6171 });6171 });
61726172
...@@ -6186,8 +6186,8 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -6186,8 +6186,8 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
6186 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);6186 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
6187 defer self.register_manager.unlockReg(dst_lock);6187 defer self.register_manager.unlockReg(dst_lock);
61886188
6189 const abi_size: u31 = @intCast(src_ty.abiSize(pt));6189 const abi_size: u31 = @intCast(src_ty.abiSize(zcu));
6190 const src_bits: u31 = @intCast(src_ty.bitSize(pt));6190 const src_bits: u31 = @intCast(src_ty.bitSize(zcu));
6191 const has_lzcnt = self.hasFeature(.lzcnt);6191 const has_lzcnt = self.hasFeature(.lzcnt);
6192 if (src_bits > @as(u32, if (has_lzcnt) 128 else 64)) {6192 if (src_bits > @as(u32, if (has_lzcnt) 128 else 64)) {
6193 const limbs_len = math.divCeil(u32, abi_size, 8) catch unreachable;6193 const limbs_len = math.divCeil(u32, abi_size, 8) catch unreachable;
...@@ -6297,7 +6297,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -6297,7 +6297,7 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
6297 }6297 }
62986298
6299 assert(src_bits <= 64);6299 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);
6301 if (math.isPowerOfTwo(src_bits)) {6301 if (math.isPowerOfTwo(src_bits)) {
6302 const imm_reg = try self.copyToTmpRegister(dst_ty, .{6302 const imm_reg = try self.copyToTmpRegister(dst_ty, .{
6303 .immediate = src_bits ^ (src_bits - 1),6303 .immediate = src_bits ^ (src_bits - 1),
...@@ -6356,14 +6356,14 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {...@@ -6356,14 +6356,14 @@ fn airClz(self: *Self, inst: Air.Inst.Index) !void {
63566356
6357fn airCtz(self: *Self, inst: Air.Inst.Index) !void {6357fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
6358 const pt = self.pt;6358 const pt = self.pt;
6359 const mod = pt.zcu;6359 const zcu = pt.zcu;
6360 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6360 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6361 const result = result: {6361 const result = result: {
6362 try self.spillEflagsIfOccupied();6362 try self.spillEflagsIfOccupied();
63636363
6364 const dst_ty = self.typeOfIndex(inst);6364 const dst_ty = self.typeOfIndex(inst);
6365 const src_ty = self.typeOf(ty_op.operand);6365 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 {}", .{
6367 src_ty.fmt(pt),6367 src_ty.fmt(pt),
6368 });6368 });
63696369
...@@ -6383,8 +6383,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -6383,8 +6383,8 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
6383 const dst_lock = self.register_manager.lockReg(dst_reg);6383 const dst_lock = self.register_manager.lockReg(dst_reg);
6384 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);6384 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
63856385
6386 const abi_size: u31 = @intCast(src_ty.abiSize(pt));6386 const abi_size: u31 = @intCast(src_ty.abiSize(zcu));
6387 const src_bits: u31 = @intCast(src_ty.bitSize(pt));6387 const src_bits: u31 = @intCast(src_ty.bitSize(zcu));
6388 const has_bmi = self.hasFeature(.bmi);6388 const has_bmi = self.hasFeature(.bmi);
6389 if (src_bits > @as(u32, if (has_bmi) 128 else 64)) {6389 if (src_bits > @as(u32, if (has_bmi) 128 else 64)) {
6390 const limbs_len = math.divCeil(u32, abi_size, 8) catch unreachable;6390 const limbs_len = math.divCeil(u32, abi_size, 8) catch unreachable;
...@@ -6505,7 +6505,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -6505,7 +6505,7 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
6505 try self.genBinOpMir(.{ ._, .bsf }, wide_ty, dst_mcv, .{ .register = wide_reg });6505 try self.genBinOpMir(.{ ._, .bsf }, wide_ty, dst_mcv, .{ .register = wide_reg });
6506 } else try self.genBinOpMir(.{ ._, .bsf }, src_ty, dst_mcv, mat_src_mcv);6506 } 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);
6509 try self.asmCmovccRegisterRegister(6509 try self.asmCmovccRegisterRegister(
6510 .z,6510 .z,
6511 registerAlias(dst_reg, cmov_abi_size),6511 registerAlias(dst_reg, cmov_abi_size),
...@@ -6518,14 +6518,14 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {...@@ -6518,14 +6518,14 @@ fn airCtz(self: *Self, inst: Air.Inst.Index) !void {
65186518
6519fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {6519fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {
6520 const pt = self.pt;6520 const pt = self.pt;
6521 const mod = pt.zcu;6521 const zcu = pt.zcu;
6522 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6522 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6523 const result: MCValue = result: {6523 const result: MCValue = result: {
6524 try self.spillEflagsIfOccupied();6524 try self.spillEflagsIfOccupied();
65256525
6526 const src_ty = self.typeOf(ty_op.operand);6526 const src_ty = self.typeOf(ty_op.operand);
6527 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));6527 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
6528 if (src_ty.zigTypeTag(mod) == .Vector or src_abi_size > 16)6528 if (src_ty.zigTypeTag(zcu) == .Vector or src_abi_size > 16)
6529 return self.fail("TODO implement airPopCount for {}", .{src_ty.fmt(pt)});6529 return self.fail("TODO implement airPopCount for {}", .{src_ty.fmt(pt)});
6530 const src_mcv = try self.resolveInst(ty_op.operand);6530 const src_mcv = try self.resolveInst(ty_op.operand);
65316531
...@@ -6562,7 +6562,7 @@ fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {...@@ -6562,7 +6562,7 @@ fn airPopCount(self: *Self, inst: Air.Inst.Index) !void {
6562 mat_src_mcv6562 mat_src_mcv
6563 else6563 else
6564 .{ .register = mat_src_mcv.register_pair[0] }, false);6564 .{ .register = mat_src_mcv.register_pair[0] }, false);
6565 const src_info = src_ty.intInfo(mod);6565 const src_info = src_ty.intInfo(zcu);
6566 const hi_ty = try pt.intType(src_info.signedness, (src_info.bits - 1) % 64 + 1);6566 const hi_ty = try pt.intType(src_info.signedness, (src_info.bits - 1) % 64 + 1);
6567 try self.genPopCount(tmp_regs[1], hi_ty, if (mat_src_mcv.isMemory())6567 try self.genPopCount(tmp_regs[1], hi_ty, if (mat_src_mcv.isMemory())
6568 mat_src_mcv.address().offset(8).deref()6568 mat_src_mcv.address().offset(8).deref()
...@@ -6583,7 +6583,7 @@ fn genPopCount(...@@ -6583,7 +6583,7 @@ fn genPopCount(
6583) !void {6583) !void {
6584 const pt = self.pt;6584 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));
6587 if (self.hasFeature(.popcnt)) return self.genBinOpMir(6587 if (self.hasFeature(.popcnt)) return self.genBinOpMir(
6588 .{ ._, .popcnt },6588 .{ ._, .popcnt },
6589 if (src_abi_size > 1) src_ty else Type.u32,6589 if (src_abi_size > 1) src_ty else Type.u32,
...@@ -6674,11 +6674,11 @@ fn genByteSwap(...@@ -6674,11 +6674,11 @@ fn genByteSwap(
6674 mem_ok: bool,6674 mem_ok: bool,
6675) !MCValue {6675) !MCValue {
6676 const pt = self.pt;6676 const pt = self.pt;
6677 const mod = pt.zcu;6677 const zcu = pt.zcu;
6678 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6678 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6679 const has_movbe = self.hasFeature(.movbe);6679 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(
6682 "TODO implement genByteSwap for {}",6682 "TODO implement genByteSwap for {}",
6683 .{src_ty.fmt(pt)},6683 .{src_ty.fmt(pt)},
6684 );6684 );
...@@ -6689,7 +6689,7 @@ fn genByteSwap(...@@ -6689,7 +6689,7 @@ fn genByteSwap(
6689 };6689 };
6690 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);6690 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));
6693 switch (abi_size) {6693 switch (abi_size) {
6694 0 => unreachable,6694 0 => unreachable,
6695 1 => return if ((mem_ok or src_mcv.isRegister()) and6695 1 => return if ((mem_ok or src_mcv.isRegister()) and
...@@ -6838,35 +6838,35 @@ fn genByteSwap(...@@ -6838,35 +6838,35 @@ fn genByteSwap(
68386838
6839fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {6839fn airByteSwap(self: *Self, inst: Air.Inst.Index) !void {
6840 const pt = self.pt;6840 const pt = self.pt;
6841 const mod = pt.zcu;6841 const zcu = pt.zcu;
6842 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6842 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68436843
6844 const src_ty = self.typeOf(ty_op.operand);6844 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));
6846 const src_mcv = try self.resolveInst(ty_op.operand);6846 const src_mcv = try self.resolveInst(ty_op.operand);
68476847
6848 const dst_mcv = try self.genByteSwap(inst, src_ty, src_mcv, true);6848 const dst_mcv = try self.genByteSwap(inst, src_ty, src_mcv, true);
6849 try self.genShiftBinOpMir(6849 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) {
6851 .signed => .sa,6851 .signed => .sa,
6852 .unsigned => .sh,6852 .unsigned => .sh,
6853 } },6853 } },
6854 src_ty,6854 src_ty,
6855 dst_mcv,6855 dst_mcv,
6856 if (src_bits > 256) Type.u16 else Type.u8,6856 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 },
6858 );6858 );
6859 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });6859 return self.finishAir(inst, dst_mcv, .{ ty_op.operand, .none, .none });
6860}6860}
68616861
6862fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {6862fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
6863 const pt = self.pt;6863 const pt = self.pt;
6864 const mod = pt.zcu;6864 const zcu = pt.zcu;
6865 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6865 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68666866
6867 const src_ty = self.typeOf(ty_op.operand);6867 const src_ty = self.typeOf(ty_op.operand);
6868 const abi_size: u32 = @intCast(src_ty.abiSize(pt));6868 const abi_size: u32 = @intCast(src_ty.abiSize(zcu));
6869 const bit_size: u32 = @intCast(src_ty.bitSize(pt));6869 const bit_size: u32 = @intCast(src_ty.bitSize(zcu));
6870 const src_mcv = try self.resolveInst(ty_op.operand);6870 const src_mcv = try self.resolveInst(ty_op.operand);
68716871
6872 const dst_mcv = try self.genByteSwap(inst, src_ty, src_mcv, false);6872 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 {...@@ -6973,7 +6973,7 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
69736973
6974 const extra_bits = abi_size * 8 - bit_size;6974 const extra_bits = abi_size * 8 - bit_size;
6975 const signedness: std.builtin.Signedness =6975 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;
6977 if (extra_bits > 0) try self.genShiftBinOpMir(switch (signedness) {6977 if (extra_bits > 0) try self.genShiftBinOpMir(switch (signedness) {
6978 .signed => .{ ._r, .sa },6978 .signed => .{ ._r, .sa },
6979 .unsigned => .{ ._r, .sh },6979 .unsigned => .{ ._r, .sh },
...@@ -6984,13 +6984,13 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {...@@ -6984,13 +6984,13 @@ fn airBitReverse(self: *Self, inst: Air.Inst.Index) !void {
69846984
6985fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void {6985fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type) !void {
6986 const pt = self.pt;6986 const pt = self.pt;
6987 const mod = pt.zcu;6987 const zcu = pt.zcu;
6988 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];6988 const tag = self.air.instructions.items(.tag)[@intFromEnum(inst)];
69896989
6990 const result = result: {6990 const result = result: {
6991 const scalar_bits = ty.scalarType(mod).floatBits(self.target.*);6991 const scalar_bits = ty.scalarType(zcu).floatBits(self.target.*);
6992 if (scalar_bits == 80) {6992 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 {}", .{
6994 ty.fmt(pt),6994 ty.fmt(pt),
6995 });6995 });
69966996
...@@ -7011,7 +7011,7 @@ fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type)...@@ -7011,7 +7011,7 @@ fn floatSign(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, ty: Type)
7011 break :result dst_mcv;7011 break :result dst_mcv;
7012 }7012 }
70137013
7014 const abi_size: u32 = switch (ty.abiSize(pt)) {7014 const abi_size: u32 = switch (ty.abiSize(zcu)) {
7015 1...16 => 16,7015 1...16 => 16,
7016 17...32 => 32,7016 17...32 => 32,
7017 else => return self.fail("TODO implement floatSign for {}", .{7017 else => return self.fail("TODO implement floatSign for {}", .{
...@@ -7161,23 +7161,23 @@ fn airRound(self: *Self, inst: Air.Inst.Index, mode: RoundMode) !void {...@@ -7161,23 +7161,23 @@ fn airRound(self: *Self, inst: Air.Inst.Index, mode: RoundMode) !void {
71617161
7162fn getRoundTag(self: *Self, ty: Type) ?Mir.Inst.FixedTag {7162fn getRoundTag(self: *Self, ty: Type) ?Mir.Inst.FixedTag {
7163 const pt = self.pt;7163 const pt = self.pt;
7164 const mod = pt.zcu;7164 const zcu = pt.zcu;
7165 return if (self.hasFeature(.sse4_1)) switch (ty.zigTypeTag(mod)) {7165 return if (self.hasFeature(.sse4_1)) switch (ty.zigTypeTag(zcu)) {
7166 .Float => switch (ty.floatBits(self.target.*)) {7166 .Float => switch (ty.floatBits(self.target.*)) {
7167 32 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },7167 32 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
7168 64 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },7168 64 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
7169 16, 80, 128 => null,7169 16, 80, 128 => null,
7170 else => unreachable,7170 else => unreachable,
7171 },7171 },
7172 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {7172 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
7173 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {7173 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
7174 32 => switch (ty.vectorLen(mod)) {7174 32 => switch (ty.vectorLen(zcu)) {
7175 1 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },7175 1 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
7176 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else .{ ._ps, .round },7176 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else .{ ._ps, .round },
7177 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else null,7177 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else null,
7178 else => null,7178 else => null,
7179 },7179 },
7180 64 => switch (ty.vectorLen(mod)) {7180 64 => switch (ty.vectorLen(zcu)) {
7181 1 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },7181 1 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
7182 2 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else .{ ._pd, .round },7182 2 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else .{ ._pd, .round },
7183 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else null,7183 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else null,
...@@ -7194,10 +7194,10 @@ fn getRoundTag(self: *Self, ty: Type) ?Mir.Inst.FixedTag {...@@ -7194,10 +7194,10 @@ fn getRoundTag(self: *Self, ty: Type) ?Mir.Inst.FixedTag {
71947194
7195fn genRoundLibcall(self: *Self, ty: Type, src_mcv: MCValue, mode: RoundMode) !MCValue {7195fn genRoundLibcall(self: *Self, ty: Type, src_mcv: MCValue, mode: RoundMode) !MCValue {
7196 const pt = self.pt;7196 const pt = self.pt;
7197 const mod = pt.zcu;7197 const zcu = pt.zcu;
7198 if (self.getRoundTag(ty)) |_| return .none;7198 if (self.getRoundTag(ty)) |_| return .none;
71997199
7200 if (ty.zigTypeTag(mod) != .Float)7200 if (ty.zigTypeTag(zcu) != .Float)
7201 return self.fail("TODO implement genRound for {}", .{ty.fmt(pt)});7201 return self.fail("TODO implement genRound for {}", .{ty.fmt(pt)});
72027202
7203 var callee_buf: ["__trunc?".len]u8 = undefined;7203 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...@@ -7223,7 +7223,7 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro
7223 const result = try self.genRoundLibcall(ty, src_mcv, mode);7223 const result = try self.genRoundLibcall(ty, src_mcv, mode);
7224 return self.genSetReg(dst_reg, ty, result, .{});7224 return self.genSetReg(dst_reg, ty, result, .{});
7225 };7225 };
7226 const abi_size: u32 = @intCast(ty.abiSize(pt));7226 const abi_size: u32 = @intCast(ty.abiSize(pt.zcu));
7227 const dst_alias = registerAlias(dst_reg, abi_size);7227 const dst_alias = registerAlias(dst_reg, abi_size);
7228 switch (mir_tag[0]) {7228 switch (mir_tag[0]) {
7229 .v_ss, .v_sd => if (src_mcv.isMemory()) try self.asmRegisterRegisterMemoryImmediate(7229 .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...@@ -7261,14 +7261,14 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: Ro
72617261
7262fn airAbs(self: *Self, inst: Air.Inst.Index) !void {7262fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
7263 const pt = self.pt;7263 const pt = self.pt;
7264 const mod = pt.zcu;7264 const zcu = pt.zcu;
7265 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7265 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7266 const ty = self.typeOf(ty_op.operand);7266 const ty = self.typeOf(ty_op.operand);
72677267
7268 const result: MCValue = result: {7268 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)) {
7270 else => null,7270 else => null,
7271 .Int => switch (ty.abiSize(pt)) {7271 .Int => switch (ty.abiSize(zcu)) {
7272 0 => unreachable,7272 0 => unreachable,
7273 1...8 => {7273 1...8 => {
7274 try self.spillEflagsIfOccupied();7274 try self.spillEflagsIfOccupied();
...@@ -7277,7 +7277,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -7277,7 +7277,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
72777277
7278 try self.genUnOpMir(.{ ._, .neg }, ty, dst_mcv);7278 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);
7281 switch (src_mcv) {7281 switch (src_mcv) {
7282 .register => |val_reg| try self.asmCmovccRegisterRegister(7282 .register => |val_reg| try self.asmCmovccRegisterRegister(
7283 .l,7283 .l,
...@@ -7336,7 +7336,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -7336,7 +7336,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
7336 break :result dst_mcv;7336 break :result dst_mcv;
7337 },7337 },
7338 else => {7338 else => {
7339 const abi_size: u31 = @intCast(ty.abiSize(pt));7339 const abi_size: u31 = @intCast(ty.abiSize(zcu));
7340 const limb_len = math.divCeil(u31, abi_size, 8) catch unreachable;7340 const limb_len = math.divCeil(u31, abi_size, 8) catch unreachable;
73417341
7342 const tmp_regs =7342 const tmp_regs =
...@@ -7397,11 +7397,11 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -7397,11 +7397,11 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
7397 },7397 },
7398 },7398 },
7399 .Float => return self.floatSign(inst, ty_op.operand, ty),7399 .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)) {
7401 else => null,7401 else => null,
7402 .Int => switch (ty.childType(mod).intInfo(mod).bits) {7402 .Int => switch (ty.childType(zcu).intInfo(zcu).bits) {
7403 else => null,7403 else => null,
7404 8 => switch (ty.vectorLen(mod)) {7404 8 => switch (ty.vectorLen(zcu)) {
7405 else => null,7405 else => null,
7406 1...16 => if (self.hasFeature(.avx))7406 1...16 => if (self.hasFeature(.avx))
7407 .{ .vp_b, .abs }7407 .{ .vp_b, .abs }
...@@ -7411,7 +7411,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -7411,7 +7411,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
7411 null,7411 null,
7412 17...32 => if (self.hasFeature(.avx2)) .{ .vp_b, .abs } else null,7412 17...32 => if (self.hasFeature(.avx2)) .{ .vp_b, .abs } else null,
7413 },7413 },
7414 16 => switch (ty.vectorLen(mod)) {7414 16 => switch (ty.vectorLen(zcu)) {
7415 else => null,7415 else => null,
7416 1...8 => if (self.hasFeature(.avx))7416 1...8 => if (self.hasFeature(.avx))
7417 .{ .vp_w, .abs }7417 .{ .vp_w, .abs }
...@@ -7421,7 +7421,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -7421,7 +7421,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
7421 null,7421 null,
7422 9...16 => if (self.hasFeature(.avx2)) .{ .vp_w, .abs } else null,7422 9...16 => if (self.hasFeature(.avx2)) .{ .vp_w, .abs } else null,
7423 },7423 },
7424 32 => switch (ty.vectorLen(mod)) {7424 32 => switch (ty.vectorLen(zcu)) {
7425 else => null,7425 else => null,
7426 1...4 => if (self.hasFeature(.avx))7426 1...4 => if (self.hasFeature(.avx))
7427 .{ .vp_d, .abs }7427 .{ .vp_d, .abs }
...@@ -7436,7 +7436,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -7436,7 +7436,7 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
7436 },7436 },
7437 }) orelse return self.fail("TODO implement airAbs for {}", .{ty.fmt(pt)});7437 }) 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));
7440 const src_mcv = try self.resolveInst(ty_op.operand);7440 const src_mcv = try self.resolveInst(ty_op.operand);
7441 const dst_reg = if (src_mcv.isRegister() and self.reuseOperand(inst, ty_op.operand, 0, src_mcv))7441 const dst_reg = if (src_mcv.isRegister() and self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
7442 src_mcv.getReg().?7442 src_mcv.getReg().?
...@@ -7462,13 +7462,13 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {...@@ -7462,13 +7462,13 @@ fn airAbs(self: *Self, inst: Air.Inst.Index) !void {
74627462
7463fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {7463fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
7464 const pt = self.pt;7464 const pt = self.pt;
7465 const mod = pt.zcu;7465 const zcu = pt.zcu;
7466 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;7466 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7467 const ty = self.typeOf(un_op);7467 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
7470 const result: MCValue = result: {7470 const result: MCValue = result: {
7471 switch (ty.zigTypeTag(mod)) {7471 switch (ty.zigTypeTag(zcu)) {
7472 .Float => {7472 .Float => {
7473 const float_bits = ty.floatBits(self.target.*);7473 const float_bits = ty.floatBits(self.target.*);
7474 if (switch (float_bits) {7474 if (switch (float_bits) {
...@@ -7500,7 +7500,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {...@@ -7500,7 +7500,7 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
7500 const dst_lock = self.register_manager.lockReg(dst_reg);7500 const dst_lock = self.register_manager.lockReg(dst_reg);
7501 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);7501 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)) {
7504 .Float => switch (ty.floatBits(self.target.*)) {7504 .Float => switch (ty.floatBits(self.target.*)) {
7505 16 => {7505 16 => {
7506 assert(self.hasFeature(.f16c));7506 assert(self.hasFeature(.f16c));
...@@ -7522,9 +7522,9 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {...@@ -7522,9 +7522,9 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
7522 64 => if (self.hasFeature(.avx)) .{ .v_sd, .sqrt } else .{ ._sd, .sqrt },7522 64 => if (self.hasFeature(.avx)) .{ .v_sd, .sqrt } else .{ ._sd, .sqrt },
7523 else => unreachable,7523 else => unreachable,
7524 },7524 },
7525 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {7525 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
7526 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {7526 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
7527 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(mod)) {7527 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(zcu)) {
7528 1 => {7528 1 => {
7529 try self.asmRegisterRegister(7529 try self.asmRegisterRegister(
7530 .{ .v_ps, .cvtph2 },7530 .{ .v_ps, .cvtph2 },
...@@ -7575,13 +7575,13 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {...@@ -7575,13 +7575,13 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
7575 },7575 },
7576 else => null,7576 else => null,
7577 } else null,7577 } else null,
7578 32 => switch (ty.vectorLen(mod)) {7578 32 => switch (ty.vectorLen(zcu)) {
7579 1 => if (self.hasFeature(.avx)) .{ .v_ss, .sqrt } else .{ ._ss, .sqrt },7579 1 => if (self.hasFeature(.avx)) .{ .v_ss, .sqrt } else .{ ._ss, .sqrt },
7580 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else .{ ._ps, .sqrt },7580 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else .{ ._ps, .sqrt },
7581 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else null,7581 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else null,
7582 else => null,7582 else => null,
7583 },7583 },
7584 64 => switch (ty.vectorLen(mod)) {7584 64 => switch (ty.vectorLen(zcu)) {
7585 1 => if (self.hasFeature(.avx)) .{ .v_sd, .sqrt } else .{ ._sd, .sqrt },7585 1 => if (self.hasFeature(.avx)) .{ .v_sd, .sqrt } else .{ ._sd, .sqrt },
7586 2 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else .{ ._pd, .sqrt },7586 2 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else .{ ._pd, .sqrt },
7587 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else null,7587 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else null,
...@@ -7708,14 +7708,14 @@ fn reuseOperandAdvanced(...@@ -7708,14 +7708,14 @@ fn reuseOperandAdvanced(
77087708
7709fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {7709fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {
7710 const pt = self.pt;7710 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);
7714 const val_ty = Type.fromInterned(ptr_info.child);7714 const val_ty = Type.fromInterned(ptr_info.child);
7715 if (!val_ty.hasRuntimeBitsIgnoreComptime(pt)) return;7715 if (!val_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
7716 const val_abi_size: u32 = @intCast(val_ty.abiSize(pt));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));
7719 const ptr_bit_off = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {7719 const ptr_bit_off = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
7720 .none => 0,7720 .none => 0,
7721 .runtime => unreachable,7721 .runtime => unreachable,
...@@ -7821,9 +7821,9 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn...@@ -7821,9 +7821,9 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
78217821
7822fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {7822fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {
7823 const pt = self.pt;7823 const pt = self.pt;
7824 const mod = pt.zcu;7824 const zcu = pt.zcu;
7825 const dst_ty = ptr_ty.childType(mod);7825 const dst_ty = ptr_ty.childType(zcu);
7826 if (!dst_ty.hasRuntimeBitsIgnoreComptime(pt)) return;7826 if (!dst_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
7827 switch (ptr_mcv) {7827 switch (ptr_mcv) {
7828 .none,7828 .none,
7829 .unreach,7829 .unreach,
...@@ -7864,18 +7864,18 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro...@@ -7864,18 +7864,18 @@ fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerErro
78647864
7865fn airLoad(self: *Self, inst: Air.Inst.Index) !void {7865fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
7866 const pt = self.pt;7866 const pt = self.pt;
7867 const mod = pt.zcu;7867 const zcu = pt.zcu;
7868 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7868 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7869 const elem_ty = self.typeOfIndex(inst);7869 const elem_ty = self.typeOfIndex(inst);
7870 const result: MCValue = result: {7870 const result: MCValue = result: {
7871 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;7871 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
78727872
7873 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });7873 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
7874 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });7874 const reg_locks = self.register_manager.lockRegsAssumeUnused(3, .{ .rdi, .rsi, .rcx });
7875 defer for (reg_locks) |lock| self.register_manager.unlockReg(lock);7875 defer for (reg_locks) |lock| self.register_manager.unlockReg(lock);
78767876
7877 const ptr_ty = self.typeOf(ty_op.operand);7877 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
7880 const elem_rc = self.regClassForType(elem_ty);7880 const elem_rc = self.regClassForType(elem_ty);
7881 const ptr_rc = self.regClassForType(ptr_ty);7881 const ptr_rc = self.regClassForType(ptr_ty);
...@@ -7888,14 +7888,14 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -7888,14 +7888,14 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
7888 else7888 else
7889 try self.allocRegOrMem(inst, true);7889 try self.allocRegOrMem(inst, true);
78907890
7891 const ptr_info = ptr_ty.ptrInfo(mod);7891 const ptr_info = ptr_ty.ptrInfo(zcu);
7892 if (ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0) {7892 if (ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0) {
7893 try self.packedLoad(dst_mcv, ptr_ty, ptr_mcv);7893 try self.packedLoad(dst_mcv, ptr_ty, ptr_mcv);
7894 } else {7894 } else {
7895 try self.load(dst_mcv, ptr_ty, ptr_mcv);7895 try self.load(dst_mcv, ptr_ty, ptr_mcv);
7896 }7896 }
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)) {
7899 const high_mcv: MCValue = switch (dst_mcv) {7899 const high_mcv: MCValue = switch (dst_mcv) {
7900 .register => |dst_reg| .{ .register = dst_reg },7900 .register => |dst_reg| .{ .register = dst_reg },
7901 .register_pair => |dst_regs| .{ .register = dst_regs[1] },7901 .register_pair => |dst_regs| .{ .register = dst_regs[1] },
...@@ -7923,16 +7923,16 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -7923,16 +7923,16 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
79237923
7924fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) InnerError!void {7924fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) InnerError!void {
7925 const pt = self.pt;7925 const pt = self.pt;
7926 const mod = pt.zcu;7926 const zcu = pt.zcu;
7927 const ptr_info = ptr_ty.ptrInfo(mod);7927 const ptr_info = ptr_ty.ptrInfo(zcu);
7928 const src_ty = Type.fromInterned(ptr_info.child);7928 const src_ty = Type.fromInterned(ptr_info.child);
7929 if (!src_ty.hasRuntimeBitsIgnoreComptime(pt)) return;7929 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
79307930
7931 const limb_abi_size: u16 = @min(ptr_info.packed_offset.host_size, 8);7931 const limb_abi_size: u16 = @min(ptr_info.packed_offset.host_size, 8);
7932 const limb_abi_bits = limb_abi_size * 8;7932 const limb_abi_bits = limb_abi_size * 8;
7933 const limb_ty = try pt.intType(.unsigned, limb_abi_bits);7933 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);
7936 const ptr_bit_off = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {7936 const ptr_bit_off = ptr_info.packed_offset.bit_offset + switch (ptr_info.flags.vector_index) {
7937 .none => 0,7937 .none => 0,
7938 .runtime => unreachable,7938 .runtime => unreachable,
...@@ -8029,9 +8029,9 @@ fn store(...@@ -8029,9 +8029,9 @@ fn store(
8029 opts: CopyOptions,8029 opts: CopyOptions,
8030) InnerError!void {8030) InnerError!void {
8031 const pt = self.pt;8031 const pt = self.pt;
8032 const mod = pt.zcu;8032 const zcu = pt.zcu;
8033 const src_ty = ptr_ty.childType(mod);8033 const src_ty = ptr_ty.childType(zcu);
8034 if (!src_ty.hasRuntimeBitsIgnoreComptime(pt)) return;8034 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) return;
8035 switch (ptr_mcv) {8035 switch (ptr_mcv) {
8036 .none,8036 .none,
8037 .unreach,8037 .unreach,
...@@ -8072,7 +8072,7 @@ fn store(...@@ -8072,7 +8072,7 @@ fn store(
80728072
8073fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {8073fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
8074 const pt = self.pt;8074 const pt = self.pt;
8075 const mod = pt.zcu;8075 const zcu = pt.zcu;
8076 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8076 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
80778077
8078 result: {8078 result: {
...@@ -8086,7 +8086,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -8086,7 +8086,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
8086 const ptr_mcv = try self.resolveInst(bin_op.lhs);8086 const ptr_mcv = try self.resolveInst(bin_op.lhs);
8087 const ptr_ty = self.typeOf(bin_op.lhs);8087 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);
8090 if (ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0) {8090 if (ptr_info.flags.vector_index != .none or ptr_info.packed_offset.host_size > 0) {
8091 try self.packedStore(ptr_ty, ptr_mcv, src_mcv);8091 try self.packedStore(ptr_ty, ptr_mcv, src_mcv);
8092 } else {8092 } else {
...@@ -8111,16 +8111,16 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {...@@ -8111,16 +8111,16 @@ fn airStructFieldPtrIndex(self: *Self, inst: Air.Inst.Index, index: u8) !void {
81118111
8112fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {8112fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32) !MCValue {
8113 const pt = self.pt;8113 const pt = self.pt;
8114 const mod = pt.zcu;8114 const zcu = pt.zcu;
8115 const ptr_field_ty = self.typeOfIndex(inst);8115 const ptr_field_ty = self.typeOfIndex(inst);
8116 const ptr_container_ty = self.typeOf(operand);8116 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)) {8119 const field_off: i32 = switch (container_ty.containerLayout(zcu)) {
8120 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(index, pt)),8120 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(index, zcu)),
8121 .@"packed" => @divExact(@as(i32, ptr_container_ty.ptrInfo(mod).packed_offset.bit_offset) +8121 .@"packed" => @divExact(@as(i32, ptr_container_ty.ptrInfo(zcu).packed_offset.bit_offset) +
8122 (if (mod.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, index) else 0) -8122 (if (zcu.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, index) else 0) -
8123 ptr_field_ty.ptrInfo(mod).packed_offset.bit_offset, 8),8123 ptr_field_ty.ptrInfo(zcu).packed_offset.bit_offset, 8),
8124 };8124 };
81258125
8126 const src_mcv = try self.resolveInst(operand);8126 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...@@ -8134,7 +8134,7 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
81348134
8135fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {8135fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
8136 const pt = self.pt;8136 const pt = self.pt;
8137 const mod = pt.zcu;8137 const zcu = pt.zcu;
8138 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8138 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8139 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;8139 const extra = self.air.extraData(Air.StructField, ty_pl.payload).data;
8140 const result: MCValue = result: {8140 const result: MCValue = result: {
...@@ -8143,15 +8143,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -8143,15 +8143,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
81438143
8144 const container_ty = self.typeOf(operand);8144 const container_ty = self.typeOf(operand);
8145 const container_rc = self.regClassForType(container_ty);8145 const container_rc = self.regClassForType(container_ty);
8146 const field_ty = container_ty.structFieldType(index, mod);8146 const field_ty = container_ty.fieldType(index, zcu);
8147 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) break :result .none;8147 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) break :result .none;
8148 const field_rc = self.regClassForType(field_ty);8148 const field_rc = self.regClassForType(field_ty);
8149 const field_is_gp = field_rc.supersetOf(abi.RegisterClass.gp);8149 const field_is_gp = field_rc.supersetOf(abi.RegisterClass.gp);
81508150
8151 const src_mcv = try self.resolveInst(operand);8151 const src_mcv = try self.resolveInst(operand);
8152 const field_off: u32 = switch (container_ty.containerLayout(mod)) {8152 const field_off: u32 = switch (container_ty.containerLayout(zcu)) {
8153 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(extra.field_index, pt) * 8),8153 .auto, .@"extern" => @intCast(container_ty.structFieldOffset(extra.field_index, zcu) * 8),
8154 .@"packed" => if (mod.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, extra.field_index) else 0,8154 .@"packed" => if (zcu.typeToStruct(container_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, extra.field_index) else 0,
8155 };8155 };
81568156
8157 switch (src_mcv) {8157 switch (src_mcv) {
...@@ -8182,7 +8182,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -8182,7 +8182,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
8182 );8182 );
8183 }8183 }
8184 if (abi.RegisterClass.gp.isSet(RegisterManager.indexOfRegIntoTracked(dst_reg).?) and8184 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))
8186 try self.truncateRegister(field_ty, dst_reg);8186 try self.truncateRegister(field_ty, dst_reg);
81878187
8188 break :result if (field_off == 0 or field_rc.supersetOf(abi.RegisterClass.gp))8188 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 {...@@ -8194,7 +8194,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
8194 const src_regs_lock = self.register_manager.lockRegsAssumeUnused(2, src_regs);8194 const src_regs_lock = self.register_manager.lockRegsAssumeUnused(2, src_regs);
8195 defer for (src_regs_lock) |lock| self.register_manager.unlockReg(lock);8195 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));
8198 const src_reg = if (field_off + field_bit_size <= 64)8198 const src_reg = if (field_off + field_bit_size <= 64)
8199 src_regs[0]8199 src_regs[0]
8200 else if (field_off >= 64)8200 else if (field_off >= 64)
...@@ -8293,15 +8293,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -8293,15 +8293,15 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
8293 }8293 }
8294 },8294 },
8295 .load_frame => |frame_addr| {8295 .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));
8297 if (field_off % 8 == 0) {8297 if (field_off % 8 == 0) {
8298 const field_byte_off = @divExact(field_off, 8);8298 const field_byte_off = @divExact(field_off, 8);
8299 const off_mcv = src_mcv.address().offset(@intCast(field_byte_off)).deref();8299 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
8302 if (field_abi_size <= 8) {8302 if (field_abi_size <= 8) {
8303 const int_ty = try pt.intType(8303 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,
8305 @intCast(field_bit_size),8305 @intCast(field_bit_size),
8306 );8306 );
83078307
...@@ -8321,7 +8321,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -8321,7 +8321,7 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
8321 try self.copyToRegisterWithInstTracking(inst, field_ty, dst_mcv);8321 try self.copyToRegisterWithInstTracking(inst, field_ty, dst_mcv);
8322 }8322 }
83238323
8324 const container_abi_size: u32 = @intCast(container_ty.abiSize(pt));8324 const container_abi_size: u32 = @intCast(container_ty.abiSize(zcu));
8325 const dst_mcv = if (field_byte_off + field_abi_size <= container_abi_size and8325 const dst_mcv = if (field_byte_off + field_abi_size <= container_abi_size and
8326 self.reuseOperand(inst, operand, 0, src_mcv))8326 self.reuseOperand(inst, operand, 0, src_mcv))
8327 off_mcv8327 off_mcv
...@@ -8423,17 +8423,17 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {...@@ -8423,17 +8423,17 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void {
84238423
8424fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {8424fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
8425 const pt = self.pt;8425 const pt = self.pt;
8426 const mod = pt.zcu;8426 const zcu = pt.zcu;
8427 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8427 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8428 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;8428 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
84298429
8430 const inst_ty = self.typeOfIndex(inst);8430 const inst_ty = self.typeOfIndex(inst);
8431 const parent_ty = inst_ty.childType(mod);8431 const parent_ty = inst_ty.childType(zcu);
8432 const field_off: i32 = switch (parent_ty.containerLayout(mod)) {8432 const field_off: i32 = switch (parent_ty.containerLayout(zcu)) {
8433 .auto, .@"extern" => @intCast(parent_ty.structFieldOffset(extra.field_index, pt)),8433 .auto, .@"extern" => @intCast(parent_ty.structFieldOffset(extra.field_index, zcu)),
8434 .@"packed" => @divExact(@as(i32, inst_ty.ptrInfo(mod).packed_offset.bit_offset) +8434 .@"packed" => @divExact(@as(i32, inst_ty.ptrInfo(zcu).packed_offset.bit_offset) +
8435 (if (mod.typeToStruct(parent_ty)) |struct_obj| pt.structPackedFieldBitOffset(struct_obj, extra.field_index) else 0) -8435 (if (zcu.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),8436 self.typeOf(extra.field_ptr).ptrInfo(zcu).packed_offset.bit_offset, 8),
8437 };8437 };
84388438
8439 const src_mcv = try self.resolveInst(extra.field_ptr);8439 const src_mcv = try self.resolveInst(extra.field_ptr);
...@@ -8448,9 +8448,9 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -8448,9 +8448,9 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
84488448
8449fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air: Air.Inst.Ref) !MCValue {8449fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air: Air.Inst.Ref) !MCValue {
8450 const pt = self.pt;8450 const pt = self.pt;
8451 const mod = pt.zcu;8451 const zcu = pt.zcu;
8452 const src_ty = self.typeOf(src_air);8452 const src_ty = self.typeOf(src_air);
8453 if (src_ty.zigTypeTag(mod) == .Vector)8453 if (src_ty.zigTypeTag(zcu) == .Vector)
8454 return self.fail("TODO implement genUnOp for {}", .{src_ty.fmt(pt)});8454 return self.fail("TODO implement genUnOp for {}", .{src_ty.fmt(pt)});
84558455
8456 var src_mcv = try self.resolveInst(src_air);8456 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:...@@ -8486,14 +8486,14 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
8486 };8486 };
8487 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);8487 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));
8490 switch (tag) {8490 switch (tag) {
8491 .not => {8491 .not => {
8492 const limb_abi_size: u16 = @min(abi_size, 8);8492 const limb_abi_size: u16 = @min(abi_size, 8);
8493 const int_info = if (src_ty.ip_index == .bool_type)8493 const int_info = if (src_ty.ip_index == .bool_type)
8494 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }8494 std.builtin.Type.Int{ .signedness = .unsigned, .bits = 1 }
8495 else8495 else
8496 src_ty.intInfo(mod);8496 src_ty.intInfo(zcu);
8497 var byte_off: i32 = 0;8497 var byte_off: i32 = 0;
8498 while (byte_off * 8 < int_info.bits) : (byte_off += limb_abi_size) {8498 while (byte_off * 8 < int_info.bits) : (byte_off += limb_abi_size) {
8499 const limb_bits: u16 = @intCast(@min(switch (int_info.signedness) {8499 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:...@@ -8514,7 +8514,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
8514 },8514 },
8515 .neg => {8515 .neg => {
8516 try self.genUnOpMir(.{ ._, .neg }, src_ty, dst_mcv);8516 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;
8518 if (abi_size * 8 > bit_size) {8518 if (abi_size * 8 > bit_size) {
8519 if (dst_mcv.isRegister()) {8519 if (dst_mcv.isRegister()) {
8520 try self.truncateRegister(src_ty, dst_mcv.getReg().?);8520 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:...@@ -8537,7 +8537,7 @@ fn genUnOp(self: *Self, maybe_inst: ?Air.Inst.Index, tag: Air.Inst.Tag, src_air:
85378537
8538fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {8538fn genUnOpMir(self: *Self, mir_tag: Mir.Inst.FixedTag, dst_ty: Type, dst_mcv: MCValue) !void {
8539 const pt = self.pt;8539 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));
8541 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{ mir_tag, dst_ty.fmt(pt) });8541 if (abi_size > 8) return self.fail("TODO implement {} for {}", .{ mir_tag, dst_ty.fmt(pt) });
8542 switch (dst_mcv) {8542 switch (dst_mcv) {
8543 .none,8543 .none,
...@@ -8586,8 +8586,9 @@ fn genShiftBinOpMir(...@@ -8586,8 +8586,9 @@ fn genShiftBinOpMir(
8586 rhs_mcv: MCValue,8586 rhs_mcv: MCValue,
8587) !void {8587) !void {
8588 const pt = self.pt;8588 const pt = self.pt;
8589 const abi_size: u32 = @intCast(lhs_ty.abiSize(pt));8589 const zcu = pt.zcu;
8590 const shift_abi_size: u32 = @intCast(rhs_ty.abiSize(pt));8590 const abi_size: u32 = @intCast(lhs_ty.abiSize(zcu));
8591 const shift_abi_size: u32 = @intCast(rhs_ty.abiSize(zcu));
8591 try self.spillEflagsIfOccupied();8592 try self.spillEflagsIfOccupied();
85928593
8593 if (abi_size > 16) {8594 if (abi_size > 16) {
...@@ -9243,8 +9244,8 @@ fn genShiftBinOp(...@@ -9243,8 +9244,8 @@ fn genShiftBinOp(
9243 rhs_ty: Type,9244 rhs_ty: Type,
9244) !MCValue {9245) !MCValue {
9245 const pt = self.pt;9246 const pt = self.pt;
9246 const mod = pt.zcu;9247 const zcu = pt.zcu;
9247 if (lhs_ty.zigTypeTag(mod) == .Vector) return self.fail("TODO implement genShiftBinOp for {}", .{9248 if (lhs_ty.zigTypeTag(zcu) == .Vector) return self.fail("TODO implement genShiftBinOp for {}", .{
9248 lhs_ty.fmt(pt),9249 lhs_ty.fmt(pt),
9249 });9250 });
92509251
...@@ -9274,7 +9275,7 @@ fn genShiftBinOp(...@@ -9274,7 +9275,7 @@ fn genShiftBinOp(
9274 break :dst dst_mcv;9275 break :dst dst_mcv;
9275 };9276 };
92769277
9277 const signedness = lhs_ty.intInfo(mod).signedness;9278 const signedness = lhs_ty.intInfo(zcu).signedness;
9278 try self.genShiftBinOpMir(switch (air_tag) {9279 try self.genShiftBinOpMir(switch (air_tag) {
9279 .shl, .shl_exact => switch (signedness) {9280 .shl, .shl_exact => switch (signedness) {
9280 .signed => .{ ._l, .sa },9281 .signed => .{ ._l, .sa },
...@@ -9302,13 +9303,13 @@ fn genMulDivBinOp(...@@ -9302,13 +9303,13 @@ fn genMulDivBinOp(
9302 rhs_mcv: MCValue,9303 rhs_mcv: MCValue,
9303) !MCValue {9304) !MCValue {
9304 const pt = self.pt;9305 const pt = self.pt;
9305 const mod = pt.zcu;9306 const zcu = pt.zcu;
9306 if (dst_ty.zigTypeTag(mod) == .Vector or dst_ty.zigTypeTag(mod) == .Float) return self.fail(9307 if (dst_ty.zigTypeTag(zcu) == .Vector or dst_ty.zigTypeTag(zcu) == .Float) return self.fail(
9307 "TODO implement genMulDivBinOp for {s} from {} to {}",9308 "TODO implement genMulDivBinOp for {s} from {} to {}",
9308 .{ @tagName(tag), src_ty.fmt(pt), dst_ty.fmt(pt) },9309 .{ @tagName(tag), src_ty.fmt(pt), dst_ty.fmt(pt) },
9309 );9310 );
9310 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));9311 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
9311 const src_abi_size: u32 = @intCast(src_ty.abiSize(pt));9312 const src_abi_size: u32 = @intCast(src_ty.abiSize(zcu));
93129313
9313 assert(self.register_manager.isRegFree(.rax));9314 assert(self.register_manager.isRegFree(.rax));
9314 assert(self.register_manager.isRegFree(.rcx));9315 assert(self.register_manager.isRegFree(.rcx));
...@@ -9384,7 +9385,7 @@ fn genMulDivBinOp(...@@ -9384,7 +9385,7 @@ fn genMulDivBinOp(
9384 .mul, .mul_wrap => dst_abi_size != src_abi_size and dst_abi_size != src_abi_size * 2,9385 .mul, .mul_wrap => dst_abi_size != src_abi_size and dst_abi_size != src_abi_size * 2,
9385 .div_trunc, .div_floor, .div_exact, .rem, .mod => dst_abi_size != src_abi_size,9386 .div_trunc, .div_floor, .div_exact, .rem, .mod => dst_abi_size != src_abi_size,
9386 } or src_abi_size > 8) {9387 } or src_abi_size > 8) {
9387 const src_info = src_ty.intInfo(mod);9388 const src_info = src_ty.intInfo(zcu);
9388 switch (tag) {9389 switch (tag) {
9389 .mul, .mul_wrap => {9390 .mul, .mul_wrap => {
9390 const slow_inc = self.hasFeature(.slow_incdec);9391 const slow_inc = self.hasFeature(.slow_incdec);
...@@ -9555,7 +9556,7 @@ fn genMulDivBinOp(...@@ -9555,7 +9556,7 @@ fn genMulDivBinOp(
9555 const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx });9556 const reg_locks = self.register_manager.lockRegs(2, .{ .rax, .rdx });
9556 defer for (reg_locks) |reg_lock| if (reg_lock) |lock| self.register_manager.unlockReg(lock);9557 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;
9559 switch (tag) {9560 switch (tag) {
9560 .mul,9561 .mul,
9561 .mul_wrap,9562 .mul_wrap,
...@@ -9714,10 +9715,10 @@ fn genBinOp(...@@ -9714,10 +9715,10 @@ fn genBinOp(
9714 rhs_air: Air.Inst.Ref,9715 rhs_air: Air.Inst.Ref,
9715) !MCValue {9716) !MCValue {
9716 const pt = self.pt;9717 const pt = self.pt;
9717 const mod = pt.zcu;9718 const zcu = pt.zcu;
9718 const lhs_ty = self.typeOf(lhs_air);9719 const lhs_ty = self.typeOf(lhs_air);
9719 const rhs_ty = self.typeOf(rhs_air);9720 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
9722 if (lhs_ty.isRuntimeFloat()) libcall: {9723 if (lhs_ty.isRuntimeFloat()) libcall: {
9723 const float_bits = lhs_ty.floatBits(self.target.*);9724 const float_bits = lhs_ty.floatBits(self.target.*);
...@@ -9889,23 +9890,23 @@ fn genBinOp(...@@ -9889,23 +9890,23 @@ fn genBinOp(
9889 };9890 };
9890 }9891 }
98919892
9892 const sse_op = switch (lhs_ty.zigTypeTag(mod)) {9893 const sse_op = switch (lhs_ty.zigTypeTag(zcu)) {
9893 else => false,9894 else => false,
9894 .Float => true,9895 .Float => true,
9895 .Vector => switch (lhs_ty.childType(mod).toIntern()) {9896 .Vector => switch (lhs_ty.childType(zcu).toIntern()) {
9896 .bool_type, .u1_type => false,9897 .bool_type, .u1_type => false,
9897 else => true,9898 else => true,
9898 },9899 },
9899 };9900 };
9900 if (sse_op and ((lhs_ty.scalarType(mod).isRuntimeFloat() and9901 if (sse_op and ((lhs_ty.scalarType(zcu).isRuntimeFloat() and
9901 lhs_ty.scalarType(mod).floatBits(self.target.*) == 80) or9902 lhs_ty.scalarType(zcu).floatBits(self.target.*) == 80) or
9902 lhs_ty.abiSize(pt) > @as(u6, if (self.hasFeature(.avx)) 32 else 16)))9903 lhs_ty.abiSize(zcu) > @as(u6, if (self.hasFeature(.avx)) 32 else 16)))
9903 return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });9904 return self.fail("TODO implement genBinOp for {s} {}", .{ @tagName(air_tag), lhs_ty.fmt(pt) });
99049905
9905 const maybe_mask_reg = switch (air_tag) {9906 const maybe_mask_reg = switch (air_tag) {
9906 else => null,9907 else => null,
9907 .rem, .mod => unreachable,9908 .rem, .mod => unreachable,
9908 .max, .min => if (lhs_ty.scalarType(mod).isRuntimeFloat()) registerAlias(9909 .max, .min => if (lhs_ty.scalarType(zcu).isRuntimeFloat()) registerAlias(
9909 if (!self.hasFeature(.avx) and self.hasFeature(.sse4_1)) mask: {9910 if (!self.hasFeature(.avx) and self.hasFeature(.sse4_1)) mask: {
9910 try self.register_manager.getKnownReg(.xmm0, null);9911 try self.register_manager.getKnownReg(.xmm0, null);
9911 break :mask .xmm0;9912 break :mask .xmm0;
...@@ -9917,8 +9918,8 @@ fn genBinOp(...@@ -9917,8 +9918,8 @@ fn genBinOp(
9917 if (maybe_mask_reg) |mask_reg| self.register_manager.lockRegAssumeUnused(mask_reg) else null;9918 if (maybe_mask_reg) |mask_reg| self.register_manager.lockRegAssumeUnused(mask_reg) else null;
9918 defer if (mask_lock) |lock| self.register_manager.unlockReg(lock);9919 defer if (mask_lock) |lock| self.register_manager.unlockReg(lock);
99199920
9920 const ordered_air: [2]Air.Inst.Ref = if (lhs_ty.isVector(mod) and9921 const ordered_air: [2]Air.Inst.Ref = if (lhs_ty.isVector(zcu) and
9921 switch (lhs_ty.childType(mod).zigTypeTag(mod)) {9922 switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
9922 .Bool => false,9923 .Bool => false,
9923 .Int => switch (air_tag) {9924 .Int => switch (air_tag) {
9924 .cmp_lt, .cmp_gte => true,9925 .cmp_lt, .cmp_gte => true,
...@@ -9931,7 +9932,7 @@ fn genBinOp(...@@ -9931,7 +9932,7 @@ fn genBinOp(
9931 else => unreachable,9932 else => unreachable,
9932 }) .{ rhs_air, lhs_air } else .{ lhs_air, rhs_air };9933 }) .{ 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| {
9935 switch (try self.resolveInst(op_air)) {9936 switch (try self.resolveInst(op_air)) {
9936 .register => |op_reg| switch (op_reg.class()) {9937 .register => |op_reg| switch (op_reg.class()) {
9937 .sse => try self.register_manager.getReg(op_reg, null),9938 .sse => try self.register_manager.getReg(op_reg, null),
...@@ -10056,7 +10057,7 @@ fn genBinOp(...@@ -10056,7 +10057,7 @@ fn genBinOp(
10056 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);10057 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
10057 defer self.register_manager.unlockReg(tmp_lock);10058 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);
10060 try self.genIntMulComplexOpMir(rhs_ty, tmp_mcv, .{ .immediate = elem_size });10061 try self.genIntMulComplexOpMir(rhs_ty, tmp_mcv, .{ .immediate = elem_size });
10061 try self.genBinOpMir(10062 try self.genBinOpMir(
10062 switch (air_tag) {10063 switch (air_tag) {
...@@ -10112,7 +10113,7 @@ fn genBinOp(...@@ -10112,7 +10113,7 @@ fn genBinOp(
10112 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);10113 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
10113 defer self.register_manager.unlockReg(tmp_lock);10114 defer self.register_manager.unlockReg(tmp_lock);
1011410115
10115 const signed = lhs_ty.isSignedInt(mod);10116 const signed = lhs_ty.isSignedInt(zcu);
10116 const cc: Condition = switch (air_tag) {10117 const cc: Condition = switch (air_tag) {
10117 .min => if (signed) .nl else .nb,10118 .min => if (signed) .nl else .nb,
10118 .max => if (signed) .nge else .nae,10119 .max => if (signed) .nge else .nae,
...@@ -10188,7 +10189,7 @@ fn genBinOp(...@@ -10188,7 +10189,7 @@ fn genBinOp(
1018810189
10189 try self.genBinOpMir(.{ ._, .cmp }, lhs_ty, dst_mcv, mat_src_mcv);10190 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);
10192 const cc: Condition = switch (int_info.signedness) {10193 const cc: Condition = switch (int_info.signedness) {
10193 .unsigned => switch (air_tag) {10194 .unsigned => switch (air_tag) {
10194 .min => .a,10195 .min => .a,
...@@ -10202,7 +10203,7 @@ fn genBinOp(...@@ -10202,7 +10203,7 @@ fn genBinOp(
10202 },10203 },
10203 };10204 };
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);
10206 const tmp_reg = switch (dst_mcv) {10207 const tmp_reg = switch (dst_mcv) {
10207 .register => |reg| reg,10208 .register => |reg| reg,
10208 else => try self.copyToTmpRegister(lhs_ty, dst_mcv),10209 else => try self.copyToTmpRegister(lhs_ty, dst_mcv),
...@@ -10271,7 +10272,7 @@ fn genBinOp(...@@ -10271,7 +10272,7 @@ fn genBinOp(
10271 },10272 },
1027210273
10273 .cmp_eq, .cmp_neq => {10274 .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);
10275 try self.genBinOpMir(.{ ._, .xor }, lhs_ty, dst_mcv, src_mcv);10276 try self.genBinOpMir(.{ ._, .xor }, lhs_ty, dst_mcv, src_mcv);
10276 switch (air_tag) {10277 switch (air_tag) {
10277 .cmp_eq => try self.genUnOpMir(.{ ._, .not }, lhs_ty, dst_mcv),10278 .cmp_eq => try self.genUnOpMir(.{ ._, .not }, lhs_ty, dst_mcv),
...@@ -10288,7 +10289,7 @@ fn genBinOp(...@@ -10288,7 +10289,7 @@ fn genBinOp(
10288 }10289 }
1028910290
10290 const dst_reg = registerAlias(dst_mcv.getReg().?, abi_size);10291 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)) {
10292 else => unreachable,10293 else => unreachable,
10293 .Float => switch (lhs_ty.floatBits(self.target.*)) {10294 .Float => switch (lhs_ty.floatBits(self.target.*)) {
10294 16 => {10295 16 => {
...@@ -10383,10 +10384,10 @@ fn genBinOp(...@@ -10383,10 +10384,10 @@ fn genBinOp(
10383 80, 128 => null,10384 80, 128 => null,
10384 else => unreachable,10385 else => unreachable,
10385 },10386 },
10386 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {10387 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
10387 else => null,10388 else => null,
10388 .Int => switch (lhs_ty.childType(mod).intInfo(mod).bits) {10389 .Int => switch (lhs_ty.childType(zcu).intInfo(zcu).bits) {
10389 8 => switch (lhs_ty.vectorLen(mod)) {10390 8 => switch (lhs_ty.vectorLen(zcu)) {
10390 1...16 => switch (air_tag) {10391 1...16 => switch (air_tag) {
10391 .add,10392 .add,
10392 .add_wrap,10393 .add_wrap,
...@@ -10400,7 +10401,7 @@ fn genBinOp(...@@ -10400,7 +10401,7 @@ fn genBinOp(
10400 .{ .p_, .@"and" },10401 .{ .p_, .@"and" },
10401 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },10402 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
10402 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },10403 .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) {
10404 .signed => if (self.hasFeature(.avx))10405 .signed => if (self.hasFeature(.avx))
10405 .{ .vp_b, .mins }10406 .{ .vp_b, .mins }
10406 else if (self.hasFeature(.sse4_1))10407 else if (self.hasFeature(.sse4_1))
...@@ -10414,7 +10415,7 @@ fn genBinOp(...@@ -10414,7 +10415,7 @@ fn genBinOp(
10414 else10415 else
10415 null,10416 null,
10416 },10417 },
10417 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10418 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10418 .signed => if (self.hasFeature(.avx))10419 .signed => if (self.hasFeature(.avx))
10419 .{ .vp_b, .maxs }10420 .{ .vp_b, .maxs }
10420 else if (self.hasFeature(.sse4_1))10421 else if (self.hasFeature(.sse4_1))
...@@ -10432,7 +10433,7 @@ fn genBinOp(...@@ -10432,7 +10433,7 @@ fn genBinOp(
10432 .cmp_lte,10433 .cmp_lte,
10433 .cmp_gte,10434 .cmp_gte,
10434 .cmp_gt,10435 .cmp_gt,
10435 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10436 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10436 .signed => if (self.hasFeature(.avx))10437 .signed => if (self.hasFeature(.avx))
10437 .{ .vp_b, .cmpgt }10438 .{ .vp_b, .cmpgt }
10438 else10439 else
...@@ -10454,11 +10455,11 @@ fn genBinOp(...@@ -10454,11 +10455,11 @@ fn genBinOp(
10454 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,10455 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
10455 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,10456 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
10456 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,10457 .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) {
10458 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .mins } else null,10459 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .mins } else null,
10459 .unsigned => if (self.hasFeature(.avx)) .{ .vp_b, .minu } else null,10460 .unsigned => if (self.hasFeature(.avx)) .{ .vp_b, .minu } else null,
10460 },10461 },
10461 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10462 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10462 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .maxs } else null,10463 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .maxs } else null,
10463 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_b, .maxu } else null,10464 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_b, .maxu } else null,
10464 },10465 },
...@@ -10466,7 +10467,7 @@ fn genBinOp(...@@ -10466,7 +10467,7 @@ fn genBinOp(
10466 .cmp_lte,10467 .cmp_lte,
10467 .cmp_gte,10468 .cmp_gte,
10468 .cmp_gt,10469 .cmp_gt,
10469 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10470 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10470 .signed => if (self.hasFeature(.avx)) .{ .vp_b, .cmpgt } else null,10471 .signed => if (self.hasFeature(.avx)) .{ .vp_b, .cmpgt } else null,
10471 .unsigned => null,10472 .unsigned => null,
10472 },10473 },
...@@ -10477,7 +10478,7 @@ fn genBinOp(...@@ -10477,7 +10478,7 @@ fn genBinOp(
10477 },10478 },
10478 else => null,10479 else => null,
10479 },10480 },
10480 16 => switch (lhs_ty.vectorLen(mod)) {10481 16 => switch (lhs_ty.vectorLen(zcu)) {
10481 1...8 => switch (air_tag) {10482 1...8 => switch (air_tag) {
10482 .add,10483 .add,
10483 .add_wrap,10484 .add_wrap,
...@@ -10494,7 +10495,7 @@ fn genBinOp(...@@ -10494,7 +10495,7 @@ fn genBinOp(
10494 .{ .p_, .@"and" },10495 .{ .p_, .@"and" },
10495 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },10496 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
10496 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },10497 .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) {
10498 .signed => if (self.hasFeature(.avx))10499 .signed => if (self.hasFeature(.avx))
10499 .{ .vp_w, .mins }10500 .{ .vp_w, .mins }
10500 else10501 else
...@@ -10504,7 +10505,7 @@ fn genBinOp(...@@ -10504,7 +10505,7 @@ fn genBinOp(
10504 else10505 else
10505 .{ .p_w, .minu },10506 .{ .p_w, .minu },
10506 },10507 },
10507 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10508 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10508 .signed => if (self.hasFeature(.avx))10509 .signed => if (self.hasFeature(.avx))
10509 .{ .vp_w, .maxs }10510 .{ .vp_w, .maxs }
10510 else10511 else
...@@ -10518,7 +10519,7 @@ fn genBinOp(...@@ -10518,7 +10519,7 @@ fn genBinOp(
10518 .cmp_lte,10519 .cmp_lte,
10519 .cmp_gte,10520 .cmp_gte,
10520 .cmp_gt,10521 .cmp_gt,
10521 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10522 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10522 .signed => if (self.hasFeature(.avx))10523 .signed => if (self.hasFeature(.avx))
10523 .{ .vp_w, .cmpgt }10524 .{ .vp_w, .cmpgt }
10524 else10525 else
...@@ -10543,11 +10544,11 @@ fn genBinOp(...@@ -10543,11 +10544,11 @@ fn genBinOp(
10543 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,10544 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
10544 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,10545 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
10545 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,10546 .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) {
10547 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .mins } else null,10548 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .mins } else null,
10548 .unsigned => if (self.hasFeature(.avx)) .{ .vp_w, .minu } else null,10549 .unsigned => if (self.hasFeature(.avx)) .{ .vp_w, .minu } else null,
10549 },10550 },
10550 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10551 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10551 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .maxs } else null,10552 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .maxs } else null,
10552 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_w, .maxu } else null,10553 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_w, .maxu } else null,
10553 },10554 },
...@@ -10555,7 +10556,7 @@ fn genBinOp(...@@ -10555,7 +10556,7 @@ fn genBinOp(
10555 .cmp_lte,10556 .cmp_lte,
10556 .cmp_gte,10557 .cmp_gte,
10557 .cmp_gt,10558 .cmp_gt,
10558 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10559 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10559 .signed => if (self.hasFeature(.avx)) .{ .vp_w, .cmpgt } else null,10560 .signed => if (self.hasFeature(.avx)) .{ .vp_w, .cmpgt } else null,
10560 .unsigned => null,10561 .unsigned => null,
10561 },10562 },
...@@ -10566,7 +10567,7 @@ fn genBinOp(...@@ -10566,7 +10567,7 @@ fn genBinOp(
10566 },10567 },
10567 else => null,10568 else => null,
10568 },10569 },
10569 32 => switch (lhs_ty.vectorLen(mod)) {10570 32 => switch (lhs_ty.vectorLen(zcu)) {
10570 1...4 => switch (air_tag) {10571 1...4 => switch (air_tag) {
10571 .add,10572 .add,
10572 .add_wrap,10573 .add_wrap,
...@@ -10588,7 +10589,7 @@ fn genBinOp(...@@ -10588,7 +10589,7 @@ fn genBinOp(
10588 .{ .p_, .@"and" },10589 .{ .p_, .@"and" },
10589 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },10590 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
10590 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },10591 .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) {
10592 .signed => if (self.hasFeature(.avx))10593 .signed => if (self.hasFeature(.avx))
10593 .{ .vp_d, .mins }10594 .{ .vp_d, .mins }
10594 else if (self.hasFeature(.sse4_1))10595 else if (self.hasFeature(.sse4_1))
...@@ -10602,7 +10603,7 @@ fn genBinOp(...@@ -10602,7 +10603,7 @@ fn genBinOp(
10602 else10603 else
10603 null,10604 null,
10604 },10605 },
10605 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10606 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10606 .signed => if (self.hasFeature(.avx))10607 .signed => if (self.hasFeature(.avx))
10607 .{ .vp_d, .maxs }10608 .{ .vp_d, .maxs }
10608 else if (self.hasFeature(.sse4_1))10609 else if (self.hasFeature(.sse4_1))
...@@ -10620,7 +10621,7 @@ fn genBinOp(...@@ -10620,7 +10621,7 @@ fn genBinOp(
10620 .cmp_lte,10621 .cmp_lte,
10621 .cmp_gte,10622 .cmp_gte,
10622 .cmp_gt,10623 .cmp_gt,
10623 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10624 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10624 .signed => if (self.hasFeature(.avx))10625 .signed => if (self.hasFeature(.avx))
10625 .{ .vp_d, .cmpgt }10626 .{ .vp_d, .cmpgt }
10626 else10627 else
...@@ -10645,11 +10646,11 @@ fn genBinOp(...@@ -10645,11 +10646,11 @@ fn genBinOp(
10645 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,10646 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
10646 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,10647 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
10647 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,10648 .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) {
10649 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .mins } else null,10650 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .mins } else null,
10650 .unsigned => if (self.hasFeature(.avx)) .{ .vp_d, .minu } else null,10651 .unsigned => if (self.hasFeature(.avx)) .{ .vp_d, .minu } else null,
10651 },10652 },
10652 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10653 .max => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10653 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .maxs } else null,10654 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .maxs } else null,
10654 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_d, .maxu } else null,10655 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_d, .maxu } else null,
10655 },10656 },
...@@ -10657,7 +10658,7 @@ fn genBinOp(...@@ -10657,7 +10658,7 @@ fn genBinOp(
10657 .cmp_lte,10658 .cmp_lte,
10658 .cmp_gte,10659 .cmp_gte,
10659 .cmp_gt,10660 .cmp_gt,
10660 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10661 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10661 .signed => if (self.hasFeature(.avx)) .{ .vp_d, .cmpgt } else null,10662 .signed => if (self.hasFeature(.avx)) .{ .vp_d, .cmpgt } else null,
10662 .unsigned => null,10663 .unsigned => null,
10663 },10664 },
...@@ -10668,7 +10669,7 @@ fn genBinOp(...@@ -10668,7 +10669,7 @@ fn genBinOp(
10668 },10669 },
10669 else => null,10670 else => null,
10670 },10671 },
10671 64 => switch (lhs_ty.vectorLen(mod)) {10672 64 => switch (lhs_ty.vectorLen(zcu)) {
10672 1...2 => switch (air_tag) {10673 1...2 => switch (air_tag) {
10673 .add,10674 .add,
10674 .add_wrap,10675 .add_wrap,
...@@ -10686,7 +10687,7 @@ fn genBinOp(...@@ -10686,7 +10687,7 @@ fn genBinOp(
10686 .cmp_lte,10687 .cmp_lte,
10687 .cmp_gte,10688 .cmp_gte,
10688 .cmp_gt,10689 .cmp_gt,
10689 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10690 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10690 .signed => if (self.hasFeature(.avx))10691 .signed => if (self.hasFeature(.avx))
10691 .{ .vp_q, .cmpgt }10692 .{ .vp_q, .cmpgt }
10692 else if (self.hasFeature(.sse4_2))10693 else if (self.hasFeature(.sse4_2))
...@@ -10722,7 +10723,7 @@ fn genBinOp(...@@ -10722,7 +10723,7 @@ fn genBinOp(
10722 .cmp_lte,10723 .cmp_lte,
10723 .cmp_gt,10724 .cmp_gt,
10724 .cmp_gte,10725 .cmp_gte,
10725 => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {10726 => switch (lhs_ty.childType(zcu).intInfo(zcu).signedness) {
10726 .signed => if (self.hasFeature(.avx)) .{ .vp_d, .cmpgt } else null,10727 .signed => if (self.hasFeature(.avx)) .{ .vp_d, .cmpgt } else null,
10727 .unsigned => null,10728 .unsigned => null,
10728 },10729 },
...@@ -10732,10 +10733,10 @@ fn genBinOp(...@@ -10732,10 +10733,10 @@ fn genBinOp(
10732 },10733 },
10733 else => null,10734 else => null,
10734 },10735 },
10735 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {10736 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
10736 16 => tag: {10737 16 => tag: {
10737 assert(self.hasFeature(.f16c));10738 assert(self.hasFeature(.f16c));
10738 switch (lhs_ty.vectorLen(mod)) {10739 switch (lhs_ty.vectorLen(zcu)) {
10739 1 => {10740 1 => {
10740 const tmp_reg = (try self.register_manager.allocReg(10741 const tmp_reg = (try self.register_manager.allocReg(
10741 null,10742 null,
...@@ -10923,7 +10924,7 @@ fn genBinOp(...@@ -10923,7 +10924,7 @@ fn genBinOp(
10923 else => break :tag null,10924 else => break :tag null,
10924 }10925 }
10925 },10926 },
10926 32 => switch (lhs_ty.vectorLen(mod)) {10927 32 => switch (lhs_ty.vectorLen(zcu)) {
10927 1 => switch (air_tag) {10928 1 => switch (air_tag) {
10928 .add => if (self.hasFeature(.avx)) .{ .v_ss, .add } else .{ ._ss, .add },10929 .add => if (self.hasFeature(.avx)) .{ .v_ss, .add } else .{ ._ss, .add },
10929 .sub => if (self.hasFeature(.avx)) .{ .v_ss, .sub } else .{ ._ss, .sub },10930 .sub => if (self.hasFeature(.avx)) .{ .v_ss, .sub } else .{ ._ss, .sub },
...@@ -10976,7 +10977,7 @@ fn genBinOp(...@@ -10976,7 +10977,7 @@ fn genBinOp(
10976 } else null,10977 } else null,
10977 else => null,10978 else => null,
10978 },10979 },
10979 64 => switch (lhs_ty.vectorLen(mod)) {10980 64 => switch (lhs_ty.vectorLen(zcu)) {
10980 1 => switch (air_tag) {10981 1 => switch (air_tag) {
10981 .add => if (self.hasFeature(.avx)) .{ .v_sd, .add } else .{ ._sd, .add },10982 .add => if (self.hasFeature(.avx)) .{ .v_sd, .add } else .{ ._sd, .add },
10982 .sub => if (self.hasFeature(.avx)) .{ .v_sd, .sub } else .{ ._sd, .sub },10983 .sub => if (self.hasFeature(.avx)) .{ .v_sd, .sub } else .{ ._sd, .sub },
...@@ -11052,7 +11053,7 @@ fn genBinOp(...@@ -11052,7 +11053,7 @@ fn genBinOp(
11052 mir_tag,11053 mir_tag,
11053 dst_reg,11054 dst_reg,
11054 lhs_reg,11055 lhs_reg,
11055 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {11056 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
11056 else => Memory.Size.fromSize(abi_size),11057 else => Memory.Size.fromSize(abi_size),
11057 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),11058 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
11058 }),11059 }),
...@@ -11070,7 +11071,7 @@ fn genBinOp(...@@ -11070,7 +11071,7 @@ fn genBinOp(
11070 if (src_mcv.isMemory()) try self.asmRegisterMemory(11071 if (src_mcv.isMemory()) try self.asmRegisterMemory(
11071 mir_tag,11072 mir_tag,
11072 dst_reg,11073 dst_reg,
11073 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {11074 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
11074 else => Memory.Size.fromSize(abi_size),11075 else => Memory.Size.fromSize(abi_size),
11075 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),11076 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
11076 }),11077 }),
...@@ -11098,7 +11099,7 @@ fn genBinOp(...@@ -11098,7 +11099,7 @@ fn genBinOp(
11098 mir_tag,11099 mir_tag,
11099 dst_reg,11100 dst_reg,
11100 lhs_reg,11101 lhs_reg,
11101 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {11102 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
11102 else => Memory.Size.fromSize(abi_size),11103 else => Memory.Size.fromSize(abi_size),
11103 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),11104 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
11104 }),11105 }),
...@@ -11118,7 +11119,7 @@ fn genBinOp(...@@ -11118,7 +11119,7 @@ fn genBinOp(
11118 if (src_mcv.isMemory()) try self.asmRegisterMemoryImmediate(11119 if (src_mcv.isMemory()) try self.asmRegisterMemoryImmediate(
11119 mir_tag,11120 mir_tag,
11120 dst_reg,11121 dst_reg,
11121 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(mod)) {11122 try src_mcv.mem(self, switch (lhs_ty.zigTypeTag(zcu)) {
11122 else => Memory.Size.fromSize(abi_size),11123 else => Memory.Size.fromSize(abi_size),
11123 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),11124 .Vector => Memory.Size.fromBitSize(dst_reg.bitSize()),
11124 }),11125 }),
...@@ -11151,21 +11152,21 @@ fn genBinOp(...@@ -11151,21 +11152,21 @@ fn genBinOp(
11151 const rhs_copy_reg = registerAlias(src_mcv.getReg().?, abi_size);11152 const rhs_copy_reg = registerAlias(src_mcv.getReg().?, abi_size);
1115211153
11153 try self.asmRegisterRegisterRegisterImmediate(11154 try self.asmRegisterRegisterRegisterImmediate(
11154 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {11155 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
11155 .Float => switch (lhs_ty.floatBits(self.target.*)) {11156 .Float => switch (lhs_ty.floatBits(self.target.*)) {
11156 32 => .{ .v_ss, .cmp },11157 32 => .{ .v_ss, .cmp },
11157 64 => .{ .v_sd, .cmp },11158 64 => .{ .v_sd, .cmp },
11158 16, 80, 128 => null,11159 16, 80, 128 => null,
11159 else => unreachable,11160 else => unreachable,
11160 },11161 },
11161 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {11162 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11162 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {11163 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11163 32 => switch (lhs_ty.vectorLen(mod)) {11164 32 => switch (lhs_ty.vectorLen(zcu)) {
11164 1 => .{ .v_ss, .cmp },11165 1 => .{ .v_ss, .cmp },
11165 2...8 => .{ .v_ps, .cmp },11166 2...8 => .{ .v_ps, .cmp },
11166 else => null,11167 else => null,
11167 },11168 },
11168 64 => switch (lhs_ty.vectorLen(mod)) {11169 64 => switch (lhs_ty.vectorLen(zcu)) {
11169 1 => .{ .v_sd, .cmp },11170 1 => .{ .v_sd, .cmp },
11170 2...4 => .{ .v_pd, .cmp },11171 2...4 => .{ .v_pd, .cmp },
11171 else => null,11172 else => null,
...@@ -11185,20 +11186,20 @@ fn genBinOp(...@@ -11185,20 +11186,20 @@ fn genBinOp(
11185 Immediate.u(3), // unord11186 Immediate.u(3), // unord
11186 );11187 );
11187 try self.asmRegisterRegisterRegisterRegister(11188 try self.asmRegisterRegisterRegisterRegister(
11188 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {11189 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
11189 .Float => switch (lhs_ty.floatBits(self.target.*)) {11190 .Float => switch (lhs_ty.floatBits(self.target.*)) {
11190 32 => .{ .v_ps, .blendv },11191 32 => .{ .v_ps, .blendv },
11191 64 => .{ .v_pd, .blendv },11192 64 => .{ .v_pd, .blendv },
11192 16, 80, 128 => null,11193 16, 80, 128 => null,
11193 else => unreachable,11194 else => unreachable,
11194 },11195 },
11195 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {11196 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11196 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {11197 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11197 32 => switch (lhs_ty.vectorLen(mod)) {11198 32 => switch (lhs_ty.vectorLen(zcu)) {
11198 1...8 => .{ .v_ps, .blendv },11199 1...8 => .{ .v_ps, .blendv },
11199 else => null,11200 else => null,
11200 },11201 },
11201 64 => switch (lhs_ty.vectorLen(mod)) {11202 64 => switch (lhs_ty.vectorLen(zcu)) {
11202 1...4 => .{ .v_pd, .blendv },11203 1...4 => .{ .v_pd, .blendv },
11203 else => null,11204 else => null,
11204 },11205 },
...@@ -11219,21 +11220,21 @@ fn genBinOp(...@@ -11219,21 +11220,21 @@ fn genBinOp(
11219 } else {11220 } else {
11220 const has_blend = self.hasFeature(.sse4_1);11221 const has_blend = self.hasFeature(.sse4_1);
11221 try self.asmRegisterRegisterImmediate(11222 try self.asmRegisterRegisterImmediate(
11222 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(mod)) {11223 @as(?Mir.Inst.FixedTag, switch (lhs_ty.zigTypeTag(zcu)) {
11223 .Float => switch (lhs_ty.floatBits(self.target.*)) {11224 .Float => switch (lhs_ty.floatBits(self.target.*)) {
11224 32 => .{ ._ss, .cmp },11225 32 => .{ ._ss, .cmp },
11225 64 => .{ ._sd, .cmp },11226 64 => .{ ._sd, .cmp },
11226 16, 80, 128 => null,11227 16, 80, 128 => null,
11227 else => unreachable,11228 else => unreachable,
11228 },11229 },
11229 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {11230 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11230 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {11231 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11231 32 => switch (lhs_ty.vectorLen(mod)) {11232 32 => switch (lhs_ty.vectorLen(zcu)) {
11232 1 => .{ ._ss, .cmp },11233 1 => .{ ._ss, .cmp },
11233 2...4 => .{ ._ps, .cmp },11234 2...4 => .{ ._ps, .cmp },
11234 else => null,11235 else => null,
11235 },11236 },
11236 64 => switch (lhs_ty.vectorLen(mod)) {11237 64 => switch (lhs_ty.vectorLen(zcu)) {
11237 1 => .{ ._sd, .cmp },11238 1 => .{ ._sd, .cmp },
11238 2 => .{ ._pd, .cmp },11239 2 => .{ ._pd, .cmp },
11239 else => null,11240 else => null,
...@@ -11252,20 +11253,20 @@ fn genBinOp(...@@ -11252,20 +11253,20 @@ fn genBinOp(
11252 Immediate.u(if (has_blend) 3 else 7), // unord, ord11253 Immediate.u(if (has_blend) 3 else 7), // unord, ord
11253 );11254 );
11254 if (has_blend) try self.asmRegisterRegisterRegister(11255 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)) {
11256 .Float => switch (lhs_ty.floatBits(self.target.*)) {11257 .Float => switch (lhs_ty.floatBits(self.target.*)) {
11257 32 => .{ ._ps, .blendv },11258 32 => .{ ._ps, .blendv },
11258 64 => .{ ._pd, .blendv },11259 64 => .{ ._pd, .blendv },
11259 16, 80, 128 => null,11260 16, 80, 128 => null,
11260 else => unreachable,11261 else => unreachable,
11261 },11262 },
11262 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {11263 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11263 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {11264 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11264 32 => switch (lhs_ty.vectorLen(mod)) {11265 32 => switch (lhs_ty.vectorLen(zcu)) {
11265 1...4 => .{ ._ps, .blendv },11266 1...4 => .{ ._ps, .blendv },
11266 else => null,11267 else => null,
11267 },11268 },
11268 64 => switch (lhs_ty.vectorLen(mod)) {11269 64 => switch (lhs_ty.vectorLen(zcu)) {
11269 1...2 => .{ ._pd, .blendv },11270 1...2 => .{ ._pd, .blendv },
11270 else => null,11271 else => null,
11271 },11272 },
...@@ -11282,20 +11283,20 @@ fn genBinOp(...@@ -11282,20 +11283,20 @@ fn genBinOp(
11282 lhs_copy_reg.?,11283 lhs_copy_reg.?,
11283 mask_reg,11284 mask_reg,
11284 ) else {11285 ) 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)) {
11286 .Float => switch (lhs_ty.floatBits(self.target.*)) {11287 .Float => switch (lhs_ty.floatBits(self.target.*)) {
11287 32 => ._ps,11288 32 => ._ps,
11288 64 => ._pd,11289 64 => ._pd,
11289 16, 80, 128 => null,11290 16, 80, 128 => null,
11290 else => unreachable,11291 else => unreachable,
11291 },11292 },
11292 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {11293 .Vector => switch (lhs_ty.childType(zcu).zigTypeTag(zcu)) {
11293 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {11294 .Float => switch (lhs_ty.childType(zcu).floatBits(self.target.*)) {
11294 32 => switch (lhs_ty.vectorLen(mod)) {11295 32 => switch (lhs_ty.vectorLen(zcu)) {
11295 1...4 => ._ps,11296 1...4 => ._ps,
11296 else => null,11297 else => null,
11297 },11298 },
11298 64 => switch (lhs_ty.vectorLen(mod)) {11299 64 => switch (lhs_ty.vectorLen(zcu)) {
11299 1...2 => ._pd,11300 1...2 => ._pd,
11300 else => null,11301 else => null,
11301 },11302 },
...@@ -11314,7 +11315,7 @@ fn genBinOp(...@@ -11314,7 +11315,7 @@ fn genBinOp(
11314 }11315 }
11315 },11316 },
11316 .cmp_lt, .cmp_lte, .cmp_eq, .cmp_gte, .cmp_gt, .cmp_neq => {11317 .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)) {
11318 .Int => switch (air_tag) {11319 .Int => switch (air_tag) {
11319 .cmp_lt,11320 .cmp_lt,
11320 .cmp_eq,11321 .cmp_eq,
...@@ -11395,8 +11396,8 @@ fn genBinOpMir(...@@ -11395,8 +11396,8 @@ fn genBinOpMir(
11395 src_mcv: MCValue,11396 src_mcv: MCValue,
11396) !void {11397) !void {
11397 const pt = self.pt;11398 const pt = self.pt;
11398 const mod = pt.zcu;11399 const zcu = pt.zcu;
11399 const abi_size: u32 = @intCast(ty.abiSize(pt));11400 const abi_size: u32 = @intCast(ty.abiSize(zcu));
11400 try self.spillEflagsIfOccupied();11401 try self.spillEflagsIfOccupied();
11401 switch (dst_mcv) {11402 switch (dst_mcv) {
11402 .none,11403 .none,
...@@ -11643,7 +11644,7 @@ fn genBinOpMir(...@@ -11643,7 +11644,7 @@ fn genBinOpMir(
11643 defer if (src_info) |info| self.register_manager.unlockReg(info.addr_lock);11644 defer if (src_info) |info| self.register_manager.unlockReg(info.addr_lock);
1164411645
11645 const ty_signedness =11646 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;
11647 const limb_ty = if (abi_size <= 8) ty else switch (ty_signedness) {11648 const limb_ty = if (abi_size <= 8) ty else switch (ty_signedness) {
11648 .signed => Type.usize,11649 .signed => Type.usize,
11649 .unsigned => Type.isize,11650 .unsigned => Type.isize,
...@@ -11820,7 +11821,7 @@ fn genBinOpMir(...@@ -11820,7 +11821,7 @@ fn genBinOpMir(
11820/// Does not support byte-size operands.11821/// Does not support byte-size operands.
11821fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {11822fn genIntMulComplexOpMir(self: *Self, dst_ty: Type, dst_mcv: MCValue, src_mcv: MCValue) InnerError!void {
11822 const pt = self.pt;11823 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));
11824 try self.spillEflagsIfOccupied();11825 try self.spillEflagsIfOccupied();
11825 switch (dst_mcv) {11826 switch (dst_mcv) {
11826 .none,11827 .none,
...@@ -12009,7 +12010,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -12009,7 +12010,7 @@ fn airArg(self: *Self, inst: Air.Inst.Index) !void {
12009 try self.genInlineMemset(12010 try self.genInlineMemset(
12010 dst_mcv.address().offset(@intFromBool(regs_frame_addr.regs > 0)),12011 dst_mcv.address().offset(@intFromBool(regs_frame_addr.regs > 0)),
12011 .{ .immediate = 0 },12012 .{ .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) },
12013 .{},12014 .{},
12014 );12015 );
1201512016
...@@ -12104,7 +12105,7 @@ fn genLocalDebugInfo(...@@ -12104,7 +12105,7 @@ fn genLocalDebugInfo(
12104 self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op.operand,12105 self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op.operand,
12105 ),12106 ),
12106 };12107 };
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));
12108 try self.genSetMem(.{ .frame = frame_index }, 0, ty, mcv, .{});12109 try self.genSetMem(.{ .frame = frame_index }, 0, ty, mcv, .{});
12109 try self.asmAirMemory(.dbg_local, inst, .{12110 try self.asmAirMemory(.dbg_local, inst, .{
12110 .base = .{ .frame = frame_index },12111 .base = .{ .frame = frame_index },
...@@ -12296,7 +12297,7 @@ fn genCall(self: *Self, info: union(enum) {...@@ -12296,7 +12297,7 @@ fn genCall(self: *Self, info: union(enum) {
12296 try reg_locks.appendSlice(&self.register_manager.lockRegs(2, regs));12297 try reg_locks.appendSlice(&self.register_manager.lockRegs(2, regs));
12297 },12298 },
12298 .indirect => |reg_off| {12299 .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));
12300 try self.genSetMem(.{ .frame = frame_index.* }, 0, arg_ty, src_arg, .{});12301 try self.genSetMem(.{ .frame = frame_index.* }, 0, arg_ty, src_arg, .{});
12301 try self.register_manager.getReg(reg_off.reg, null);12302 try self.register_manager.getReg(reg_off.reg, null);
12302 try reg_locks.append(self.register_manager.lockReg(reg_off.reg));12303 try reg_locks.append(self.register_manager.lockReg(reg_off.reg));
...@@ -12368,7 +12369,7 @@ fn genCall(self: *Self, info: union(enum) {...@@ -12368,7 +12369,7 @@ fn genCall(self: *Self, info: union(enum) {
12368 .none, .unreach => {},12369 .none, .unreach => {},
12369 .indirect => |reg_off| {12370 .indirect => |reg_off| {
12370 const ret_ty = Type.fromInterned(fn_info.return_type);12371 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));
12372 try self.genSetReg(reg_off.reg, Type.usize, .{12373 try self.genSetReg(reg_off.reg, Type.usize, .{
12373 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },12374 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },
12374 }, .{});12375 }, .{});
...@@ -12383,14 +12384,14 @@ fn genCall(self: *Self, info: union(enum) {...@@ -12383,14 +12384,14 @@ fn genCall(self: *Self, info: union(enum) {
12383 .none, .load_frame => {},12384 .none, .load_frame => {},
12384 .register => |dst_reg| switch (fn_info.cc) {12385 .register => |dst_reg| switch (fn_info.cc) {
12385 else => try self.genSetReg(12386 else => try self.genSetReg(
12386 registerAlias(dst_reg, @intCast(arg_ty.abiSize(pt))),12387 registerAlias(dst_reg, @intCast(arg_ty.abiSize(zcu))),
12387 arg_ty,12388 arg_ty,
12388 src_arg,12389 src_arg,
12389 .{},12390 .{},
12390 ),12391 ),
12391 .C, .SysV, .Win64 => {12392 .C, .SysV, .Win64 => {
12392 const promoted_ty = self.promoteInt(arg_ty);12393 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));
12394 const dst_alias = registerAlias(dst_reg, promoted_abi_size);12395 const dst_alias = registerAlias(dst_reg, promoted_abi_size);
12395 try self.genSetReg(dst_alias, promoted_ty, src_arg, .{});12396 try self.genSetReg(dst_alias, promoted_ty, src_arg, .{});
12396 if (promoted_ty.toIntern() != arg_ty.toIntern())12397 if (promoted_ty.toIntern() != arg_ty.toIntern())
...@@ -12514,10 +12515,10 @@ fn genCall(self: *Self, info: union(enum) {...@@ -12514,10 +12515,10 @@ fn genCall(self: *Self, info: union(enum) {
1251412515
12515fn airRet(self: *Self, inst: Air.Inst.Index, safety: bool) !void {12516fn airRet(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
12516 const pt = self.pt;12517 const pt = self.pt;
12517 const mod = pt.zcu;12518 const zcu = pt.zcu;
12518 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;12519 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);
12521 switch (self.ret_mcv.short) {12522 switch (self.ret_mcv.short) {
12522 .none => {},12523 .none => {},
12523 .register,12524 .register,
...@@ -12570,7 +12571,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {...@@ -12570,7 +12571,7 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
1257012571
12571fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {12572fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
12572 const pt = self.pt;12573 const pt = self.pt;
12573 const mod = pt.zcu;12574 const zcu = pt.zcu;
12574 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;12575 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
12575 var ty = self.typeOf(bin_op.lhs);12576 var ty = self.typeOf(bin_op.lhs);
12576 var null_compare: ?Mir.Inst.Index = null;12577 var null_compare: ?Mir.Inst.Index = null;
...@@ -12602,7 +12603,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {...@@ -12602,7 +12603,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
12602 };12603 };
12603 defer for (rhs_locks) |rhs_lock| if (rhs_lock) |lock| self.register_manager.unlockReg(lock);12604 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)) {
12606 .Float => {12607 .Float => {
12607 const float_bits = ty.floatBits(self.target.*);12608 const float_bits = ty.floatBits(self.target.*);
12608 if (switch (float_bits) {12609 if (switch (float_bits) {
...@@ -12638,11 +12639,11 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {...@@ -12638,11 +12639,11 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
12638 };12639 };
12639 }12640 }
12640 },12641 },
12641 .Optional => if (!ty.optionalReprIsPayload(mod)) {12642 .Optional => if (!ty.optionalReprIsPayload(zcu)) {
12642 const opt_ty = ty;12643 const opt_ty = ty;
12643 const opt_abi_size: u31 = @intCast(opt_ty.abiSize(pt));12644 const opt_abi_size: u31 = @intCast(opt_ty.abiSize(zcu));
12644 ty = opt_ty.optionalChild(mod);12645 ty = opt_ty.optionalChild(zcu);
12645 const payload_abi_size: u31 = @intCast(ty.abiSize(pt));12646 const payload_abi_size: u31 = @intCast(ty.abiSize(zcu));
1264612647
12647 const temp_lhs_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);12648 const temp_lhs_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
12648 const temp_lhs_lock = self.register_manager.lockRegAssumeUnused(temp_lhs_reg);12649 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 {...@@ -12699,9 +12700,9 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
12699 else => {},12700 else => {},
12700 }12701 }
1270112702
12702 switch (ty.zigTypeTag(mod)) {12703 switch (ty.zigTypeTag(zcu)) {
12703 else => {12704 else => {
12704 const abi_size: u16 = @intCast(ty.abiSize(pt));12705 const abi_size: u16 = @intCast(ty.abiSize(zcu));
12705 const may_flip: enum {12706 const may_flip: enum {
12706 may_flip,12707 may_flip,
12707 must_flip,12708 must_flip,
...@@ -12734,7 +12735,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {...@@ -12734,7 +12735,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
12734 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);12735 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);
1273512736
12736 break :result Condition.fromCompareOperator(12737 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,
12738 result_op: {12739 result_op: {
12739 const flipped_op = if (flipped) op.reverse() else op;12740 const flipped_op = if (flipped) op.reverse() else op;
12740 if (abi_size > 8) switch (flipped_op) {12741 if (abi_size > 8) switch (flipped_op) {
...@@ -13029,6 +13030,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {...@@ -13029,6 +13030,7 @@ fn airCmpVector(self: *Self, inst: Air.Inst.Index) !void {
1302913030
13030fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {13031fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
13031 const pt = self.pt;13032 const pt = self.pt;
13033 const zcu = pt.zcu;
13032 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;13034 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
1303313035
13034 const addr_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);13036 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 {...@@ -13040,7 +13042,7 @@ fn airCmpLtErrorsLen(self: *Self, inst: Air.Inst.Index) !void {
13040 try self.spillEflagsIfOccupied();13042 try self.spillEflagsIfOccupied();
1304113043
13042 const op_ty = self.typeOf(un_op);13044 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));
13044 const op_mcv = try self.resolveInst(un_op);13046 const op_mcv = try self.resolveInst(un_op);
13045 const dst_reg = switch (op_mcv) {13047 const dst_reg = switch (op_mcv) {
13046 .register => |reg| reg,13048 .register => |reg| reg,
...@@ -13164,7 +13166,7 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {...@@ -13164,7 +13166,7 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
1316413166
13165fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !Mir.Inst.Index {13167fn genCondBrMir(self: *Self, ty: Type, mcv: MCValue) !Mir.Inst.Index {
13166 const pt = self.pt;13168 const pt = self.pt;
13167 const abi_size = ty.abiSize(pt);13169 const abi_size = ty.abiSize(pt.zcu);
13168 switch (mcv) {13170 switch (mcv) {
13169 .eflags => |cc| {13171 .eflags => |cc| {
13170 // Here we map the opposites since the jump is to the false branch.13172 // 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 {...@@ -13237,7 +13239,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
1323713239
13238fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MCValue {13240fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MCValue {
13239 const pt = self.pt;13241 const pt = self.pt;
13240 const mod = pt.zcu;13242 const zcu = pt.zcu;
13241 switch (opt_mcv) {13243 switch (opt_mcv) {
13242 .register_overflow => |ro| return .{ .eflags = ro.eflags.negate() },13244 .register_overflow => |ro| return .{ .eflags = ro.eflags.negate() },
13243 else => {},13245 else => {},
...@@ -13245,12 +13247,12 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -13245,12 +13247,12 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1324513247
13246 try self.spillEflagsIfOccupied();13248 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))13252 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(zcu))
13251 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }13253 .{ .off = 0, .ty = if (pl_ty.isSlice(zcu)) pl_ty.slicePtrFieldType(zcu) else pl_ty }
13252 else13254 else
13253 .{ .off = @intCast(pl_ty.abiSize(pt)), .ty = Type.bool };13255 .{ .off = @intCast(pl_ty.abiSize(zcu)), .ty = Type.bool };
1325413256
13255 self.eflags_inst = inst;13257 self.eflags_inst = inst;
13256 switch (opt_mcv) {13258 switch (opt_mcv) {
...@@ -13279,14 +13281,14 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -13279,14 +13281,14 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1327913281
13280 .register => |opt_reg| {13282 .register => |opt_reg| {
13281 if (some_info.off == 0) {13283 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));
13283 const alias_reg = registerAlias(opt_reg, some_abi_size);13285 const alias_reg = registerAlias(opt_reg, some_abi_size);
13284 assert(some_abi_size * 8 == alias_reg.bitSize());13286 assert(some_abi_size * 8 == alias_reg.bitSize());
13285 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);13287 try self.asmRegisterRegister(.{ ._, .@"test" }, alias_reg, alias_reg);
13286 return .{ .eflags = .z };13288 return .{ .eflags = .z };
13287 }13289 }
13288 assert(some_info.ty.ip_index == .bool_type);13290 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));
13290 try self.asmRegisterImmediate(13292 try self.asmRegisterImmediate(
13291 .{ ._, .bt },13293 .{ ._, .bt },
13292 registerAlias(opt_reg, opt_abi_size),13294 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...@@ -13306,7 +13308,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
13306 defer self.register_manager.unlockReg(addr_reg_lock);13308 defer self.register_manager.unlockReg(addr_reg_lock);
1330713309
13308 try self.genSetReg(addr_reg, Type.usize, opt_mcv.address(), .{});13310 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));
13310 try self.asmMemoryImmediate(13312 try self.asmMemoryImmediate(
13311 .{ ._, .cmp },13313 .{ ._, .cmp },
13312 .{13314 .{
...@@ -13322,7 +13324,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -13322,7 +13324,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
13322 },13324 },
1332313325
13324 .indirect, .load_frame => {13326 .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));
13326 try self.asmMemoryImmediate(13328 try self.asmMemoryImmediate(
13327 .{ ._, .cmp },13329 .{ ._, .cmp },
13328 switch (opt_mcv) {13330 switch (opt_mcv) {
...@@ -13351,16 +13353,16 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC...@@ -13351,16 +13353,16 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
1335113353
13352fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue) !MCValue {13354fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue) !MCValue {
13353 const pt = self.pt;13355 const pt = self.pt;
13354 const mod = pt.zcu;13356 const zcu = pt.zcu;
13355 const opt_ty = ptr_ty.childType(mod);13357 const opt_ty = ptr_ty.childType(zcu);
13356 const pl_ty = opt_ty.optionalChild(mod);13358 const pl_ty = opt_ty.optionalChild(zcu);
1335713359
13358 try self.spillEflagsIfOccupied();13360 try self.spillEflagsIfOccupied();
1335913361
13360 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))13362 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(zcu))
13361 .{ .off = 0, .ty = if (pl_ty.isSlice(mod)) pl_ty.slicePtrFieldType(mod) else pl_ty }13363 .{ .off = 0, .ty = if (pl_ty.isSlice(zcu)) pl_ty.slicePtrFieldType(zcu) else pl_ty }
13362 else13364 else
13363 .{ .off = @intCast(pl_ty.abiSize(pt)), .ty = Type.bool };13365 .{ .off = @intCast(pl_ty.abiSize(zcu)), .ty = Type.bool };
1336413366
13365 const ptr_reg = switch (ptr_mcv) {13367 const ptr_reg = switch (ptr_mcv) {
13366 .register => |reg| reg,13368 .register => |reg| reg,
...@@ -13369,7 +13371,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)...@@ -13369,7 +13371,7 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
13369 const ptr_lock = self.register_manager.lockReg(ptr_reg);13371 const ptr_lock = self.register_manager.lockReg(ptr_reg);
13370 defer if (ptr_lock) |lock| self.register_manager.unlockReg(lock);13372 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));
13373 try self.asmMemoryImmediate(13375 try self.asmMemoryImmediate(
13374 .{ ._, .cmp },13376 .{ ._, .cmp },
13375 .{13377 .{
...@@ -13388,13 +13390,13 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)...@@ -13388,13 +13390,13 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
1338813390
13389fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue) !MCValue {13391fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue) !MCValue {
13390 const pt = self.pt;13392 const pt = self.pt;
13391 const mod = pt.zcu;13393 const zcu = pt.zcu;
13392 const err_ty = eu_ty.errorUnionSet(mod);13394 const err_ty = eu_ty.errorUnionSet(zcu);
13393 if (err_ty.errorSetIsEmpty(mod)) return MCValue{ .immediate = 0 }; // always false13395 if (err_ty.errorSetIsEmpty(zcu)) return MCValue{ .immediate = 0 }; // always false
1339413396
13395 try self.spillEflagsIfOccupied();13397 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));
13398 switch (eu_mcv) {13400 switch (eu_mcv) {
13399 .register => |reg| {13401 .register => |reg| {
13400 const eu_lock = self.register_manager.lockReg(reg);13402 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)...@@ -13437,10 +13439,10 @@ fn isErr(self: *Self, maybe_inst: ?Air.Inst.Index, eu_ty: Type, eu_mcv: MCValue)
1343713439
13438fn isErrPtr(self: *Self, maybe_inst: ?Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue) !MCValue {13440fn isErrPtr(self: *Self, maybe_inst: ?Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue) !MCValue {
13439 const pt = self.pt;13441 const pt = self.pt;
13440 const mod = pt.zcu;13442 const zcu = pt.zcu;
13441 const eu_ty = ptr_ty.childType(mod);13443 const eu_ty = ptr_ty.childType(zcu);
13442 const err_ty = eu_ty.errorUnionSet(mod);13444 const err_ty = eu_ty.errorUnionSet(zcu);
13443 if (err_ty.errorSetIsEmpty(mod)) return MCValue{ .immediate = 0 }; // always false13445 if (err_ty.errorSetIsEmpty(zcu)) return MCValue{ .immediate = 0 }; // always false
1344413446
13445 try self.spillEflagsIfOccupied();13447 try self.spillEflagsIfOccupied();
1344613448
...@@ -13451,7 +13453,7 @@ fn isErrPtr(self: *Self, maybe_inst: ?Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCV...@@ -13451,7 +13453,7 @@ fn isErrPtr(self: *Self, maybe_inst: ?Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCV
13451 const ptr_lock = self.register_manager.lockReg(ptr_reg);13453 const ptr_lock = self.register_manager.lockReg(ptr_reg);
13452 defer if (ptr_lock) |lock| self.register_manager.unlockReg(lock);13454 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));
13455 try self.asmMemoryImmediate(13457 try self.asmMemoryImmediate(
13456 .{ ._, .cmp },13458 .{ ._, .cmp },
13457 .{13459 .{
...@@ -13724,12 +13726,12 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) void {...@@ -13724,12 +13726,12 @@ fn performReloc(self: *Self, reloc: Mir.Inst.Index) void {
13724}13726}
1372513727
13726fn airBr(self: *Self, inst: Air.Inst.Index) !void {13728fn airBr(self: *Self, inst: Air.Inst.Index) !void {
13727 const pt = self.pt;13729 const zcu = self.pt.zcu;
13728 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;13730 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
1372913731
13730 const block_ty = self.typeOfIndex(br.block_inst);13732 const block_ty = self.typeOfIndex(br.block_inst);
13731 const block_unused =13733 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);
13733 const block_tracking = self.inst_tracking.getPtr(br.block_inst).?;13735 const block_tracking = self.inst_tracking.getPtr(br.block_inst).?;
13734 const block_data = self.blocks.getPtr(br.block_inst).?;13736 const block_data = self.blocks.getPtr(br.block_inst).?;
13735 const first_br = block_data.relocs.items.len == 0;13737 const first_br = block_data.relocs.items.len == 0;
...@@ -13786,7 +13788,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {...@@ -13786,7 +13788,7 @@ fn airBr(self: *Self, inst: Air.Inst.Index) !void {
1378613788
13787fn airAsm(self: *Self, inst: Air.Inst.Index) !void {13789fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
13788 const pt = self.pt;13790 const pt = self.pt;
13789 const mod = pt.zcu;13791 const zcu = pt.zcu;
13790 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;13792 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
13791 const extra = self.air.extraData(Air.Asm, ty_pl.payload);13793 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
13792 const clobbers_len: u31 = @truncate(extra.data.flags);13794 const clobbers_len: u31 = @truncate(extra.data.flags);
...@@ -13825,7 +13827,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -13825,7 +13827,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
13825 };13827 };
13826 const ty = switch (output) {13828 const ty = switch (output) {
13827 .none => self.typeOfIndex(inst),13829 .none => self.typeOfIndex(inst),
13828 else => self.typeOf(output).childType(mod),13830 else => self.typeOf(output).childType(zcu),
13829 };13831 };
13830 const is_read = switch (constraint[0]) {13832 const is_read = switch (constraint[0]) {
13831 '=' => false,13833 '=' => false,
...@@ -13850,7 +13852,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -13850,7 +13852,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
13850 'x' => abi.RegisterClass.sse,13852 'x' => abi.RegisterClass.sse,
13851 else => unreachable,13853 else => unreachable,
13852 }) orelse return self.fail("ran out of registers lowering inline asm", .{}),13854 }) orelse return self.fail("ran out of registers lowering inline asm", .{}),
13853 @intCast(ty.abiSize(pt)),13855 @intCast(ty.abiSize(zcu)),
13854 )13856 )
13855 else if (mem.eql(u8, rest, "m"))13857 else if (mem.eql(u8, rest, "m"))
13856 if (output != .none) null else return self.fail(13858 if (output != .none) null else return self.fail(
...@@ -13920,7 +13922,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {...@@ -13920,7 +13922,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
13920 break :arg input_mcv;13922 break :arg input_mcv;
13921 const reg = try self.register_manager.allocReg(null, rc);13923 const reg = try self.register_manager.allocReg(null, rc);
13922 try self.genSetReg(reg, ty, input_mcv, .{});13924 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))) };
13924 } else if (mem.eql(u8, constraint, "i") or mem.eql(u8, constraint, "n"))13926 } else if (mem.eql(u8, constraint, "i") or mem.eql(u8, constraint, "n"))
13925 switch (input_mcv) {13927 switch (input_mcv) {
13926 .immediate => |imm| .{ .immediate = imm },13928 .immediate => |imm| .{ .immediate = imm },
...@@ -14497,18 +14499,18 @@ const MoveStrategy = union(enum) {...@@ -14497,18 +14499,18 @@ const MoveStrategy = union(enum) {
14497};14499};
14498fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !MoveStrategy {14500fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !MoveStrategy {
14499 const pt = self.pt;14501 const pt = self.pt;
14500 const mod = pt.zcu;14502 const zcu = pt.zcu;
14501 switch (class) {14503 switch (class) {
14502 .general_purpose, .segment => return .{ .move = .{ ._, .mov } },14504 .general_purpose, .segment => return .{ .move = .{ ._, .mov } },
14503 .x87 => return .x87_load_store,14505 .x87 => return .x87_load_store,
14504 .mmx => {},14506 .mmx => {},
14505 .sse => switch (ty.zigTypeTag(mod)) {14507 .sse => switch (ty.zigTypeTag(zcu)) {
14506 else => {14508 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);
14508 assert(std.mem.indexOfNone(abi.Class, classes, &.{14510 assert(std.mem.indexOfNone(abi.Class, classes, &.{
14509 .integer, .sse, .sseup, .memory, .float, .float_combine,14511 .integer, .sse, .sseup, .memory, .float, .float_combine,
14510 }) == null);14512 }) == null);
14511 const abi_size = ty.abiSize(pt);14513 const abi_size = ty.abiSize(zcu);
14512 if (abi_size < 4 or14514 if (abi_size < 4 or
14513 std.mem.indexOfScalar(abi.Class, classes, .integer) != null) switch (abi_size) {14515 std.mem.indexOfScalar(abi.Class, classes, .integer) != null) switch (abi_size) {
14514 1 => if (self.hasFeature(.avx)) return .{ .vex_insert_extract = .{14516 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...@@ -14579,16 +14581,16 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14579 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14581 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
14580 else => {},14582 else => {},
14581 },14583 },
14582 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {14584 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
14583 .Bool => switch (ty.vectorLen(mod)) {14585 .Bool => switch (ty.vectorLen(zcu)) {
14584 33...64 => return .{ .move = if (self.hasFeature(.avx))14586 33...64 => return .{ .move = if (self.hasFeature(.avx))
14585 .{ .v_q, .mov }14587 .{ .v_q, .mov }
14586 else14588 else
14587 .{ ._q, .mov } },14589 .{ ._q, .mov } },
14588 else => {},14590 else => {},
14589 },14591 },
14590 .Int => switch (ty.childType(mod).intInfo(mod).bits) {14592 .Int => switch (ty.childType(zcu).intInfo(zcu).bits) {
14591 1...8 => switch (ty.vectorLen(mod)) {14593 1...8 => switch (ty.vectorLen(zcu)) {
14592 1...16 => return .{ .move = if (self.hasFeature(.avx))14594 1...16 => return .{ .move = if (self.hasFeature(.avx))
14593 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14595 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14594 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14596 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14599,7 +14601,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14599,7 +14601,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14599 .{ .v_, .movdqu } },14601 .{ .v_, .movdqu } },
14600 else => {},14602 else => {},
14601 },14603 },
14602 9...16 => switch (ty.vectorLen(mod)) {14604 9...16 => switch (ty.vectorLen(zcu)) {
14603 1...8 => return .{ .move = if (self.hasFeature(.avx))14605 1...8 => return .{ .move = if (self.hasFeature(.avx))
14604 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14606 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14605 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14607 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14610,7 +14612,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14610,7 +14612,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14610 .{ .v_, .movdqu } },14612 .{ .v_, .movdqu } },
14611 else => {},14613 else => {},
14612 },14614 },
14613 17...32 => switch (ty.vectorLen(mod)) {14615 17...32 => switch (ty.vectorLen(zcu)) {
14614 1...4 => return .{ .move = if (self.hasFeature(.avx))14616 1...4 => return .{ .move = if (self.hasFeature(.avx))
14615 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14617 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14616 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14618 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14621,7 +14623,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14621,7 +14623,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14621 .{ .v_, .movdqu } },14623 .{ .v_, .movdqu } },
14622 else => {},14624 else => {},
14623 },14625 },
14624 33...64 => switch (ty.vectorLen(mod)) {14626 33...64 => switch (ty.vectorLen(zcu)) {
14625 1...2 => return .{ .move = if (self.hasFeature(.avx))14627 1...2 => return .{ .move = if (self.hasFeature(.avx))
14626 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14628 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14627 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14629 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14632,7 +14634,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14632,7 +14634,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14632 .{ .v_, .movdqu } },14634 .{ .v_, .movdqu } },
14633 else => {},14635 else => {},
14634 },14636 },
14635 65...128 => switch (ty.vectorLen(mod)) {14637 65...128 => switch (ty.vectorLen(zcu)) {
14636 1 => return .{ .move = if (self.hasFeature(.avx))14638 1 => return .{ .move = if (self.hasFeature(.avx))
14637 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14639 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14638 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14640 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14643,7 +14645,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14643,7 +14645,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14643 .{ .v_, .movdqu } },14645 .{ .v_, .movdqu } },
14644 else => {},14646 else => {},
14645 },14647 },
14646 129...256 => switch (ty.vectorLen(mod)) {14648 129...256 => switch (ty.vectorLen(zcu)) {
14647 1 => if (self.hasFeature(.avx))14649 1 => if (self.hasFeature(.avx))
14648 return .{ .move = if (aligned)14650 return .{ .move = if (aligned)
14649 .{ .v_, .movdqa }14651 .{ .v_, .movdqa }
...@@ -14653,8 +14655,8 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14653,8 +14655,8 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14653 },14655 },
14654 else => {},14656 else => {},
14655 },14657 },
14656 .Pointer, .Optional => if (ty.childType(mod).isPtrAtRuntime(mod))14658 .Pointer, .Optional => if (ty.childType(zcu).isPtrAtRuntime(zcu))
14657 switch (ty.vectorLen(mod)) {14659 switch (ty.vectorLen(zcu)) {
14658 1...2 => return .{ .move = if (self.hasFeature(.avx))14660 1...2 => return .{ .move = if (self.hasFeature(.avx))
14659 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14661 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14660 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14662 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14667,8 +14669,8 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14667,8 +14669,8 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14667 }14669 }
14668 else14670 else
14669 unreachable,14671 unreachable,
14670 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {14672 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
14671 16 => switch (ty.vectorLen(mod)) {14673 16 => switch (ty.vectorLen(zcu)) {
14672 1...8 => return .{ .move = if (self.hasFeature(.avx))14674 1...8 => return .{ .move = if (self.hasFeature(.avx))
14673 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14675 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14674 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14676 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14679,7 +14681,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14679,7 +14681,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14679 .{ .v_, .movdqu } },14681 .{ .v_, .movdqu } },
14680 else => {},14682 else => {},
14681 },14683 },
14682 32 => switch (ty.vectorLen(mod)) {14684 32 => switch (ty.vectorLen(zcu)) {
14683 1...4 => return .{ .move = if (self.hasFeature(.avx))14685 1...4 => return .{ .move = if (self.hasFeature(.avx))
14684 if (aligned) .{ .v_ps, .mova } else .{ .v_ps, .movu }14686 if (aligned) .{ .v_ps, .mova } else .{ .v_ps, .movu }
14685 else if (aligned) .{ ._ps, .mova } else .{ ._ps, .movu } },14687 else if (aligned) .{ ._ps, .mova } else .{ ._ps, .movu } },
...@@ -14690,7 +14692,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14690,7 +14692,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14690 .{ .v_ps, .movu } },14692 .{ .v_ps, .movu } },
14691 else => {},14693 else => {},
14692 },14694 },
14693 64 => switch (ty.vectorLen(mod)) {14695 64 => switch (ty.vectorLen(zcu)) {
14694 1...2 => return .{ .move = if (self.hasFeature(.avx))14696 1...2 => return .{ .move = if (self.hasFeature(.avx))
14695 if (aligned) .{ .v_pd, .mova } else .{ .v_pd, .movu }14697 if (aligned) .{ .v_pd, .mova } else .{ .v_pd, .movu }
14696 else if (aligned) .{ ._pd, .mova } else .{ ._pd, .movu } },14698 else if (aligned) .{ ._pd, .mova } else .{ ._pd, .movu } },
...@@ -14701,7 +14703,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo...@@ -14701,7 +14703,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
14701 .{ .v_pd, .movu } },14703 .{ .v_pd, .movu } },
14702 else => {},14704 else => {},
14703 },14705 },
14704 128 => switch (ty.vectorLen(mod)) {14706 128 => switch (ty.vectorLen(zcu)) {
14705 1 => return .{ .move = if (self.hasFeature(.avx))14707 1 => return .{ .move = if (self.hasFeature(.avx))
14706 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }14708 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
14707 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },14709 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
...@@ -14804,7 +14806,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: Copy...@@ -14804,7 +14806,7 @@ fn genCopy(self: *Self, ty: Type, dst_mcv: MCValue, src_mcv: MCValue, opts: Copy
14804 } },14806 } },
14805 else => unreachable,14807 else => unreachable,
14806 }, opts);14808 }, opts);
14807 part_disp += @intCast(dst_ty.abiSize(pt));14809 part_disp += @intCast(dst_ty.abiSize(pt.zcu));
14808 }14810 }
14809 },14811 },
14810 .indirect => |reg_off| try self.genSetMem(14812 .indirect => |reg_off| try self.genSetMem(
...@@ -14846,9 +14848,9 @@ fn genSetReg(...@@ -14846,9 +14848,9 @@ fn genSetReg(
14846 opts: CopyOptions,14848 opts: CopyOptions,
14847) InnerError!void {14849) InnerError!void {
14848 const pt = self.pt;14850 const pt = self.pt;
14849 const mod = pt.zcu;14851 const zcu = pt.zcu;
14850 const abi_size: u32 = @intCast(ty.abiSize(pt));14852 const abi_size: u32 = @intCast(ty.abiSize(zcu));
14851 if (ty.bitSize(pt) > dst_reg.bitSize())14853 if (ty.bitSize(zcu) > dst_reg.bitSize())
14852 return self.fail("genSetReg called with a value larger than dst_reg", .{});14854 return self.fail("genSetReg called with a value larger than dst_reg", .{});
14853 switch (src_mcv) {14855 switch (src_mcv) {
14854 .none,14856 .none,
...@@ -14965,13 +14967,13 @@ fn genSetReg(...@@ -14965,13 +14967,13 @@ fn genSetReg(
14965 ),14967 ),
14966 .x87, .mmx, .ip => unreachable,14968 .x87, .mmx, .ip => unreachable,
14967 .sse => try self.asmRegisterRegister(14969 .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)) {
14969 else => switch (abi_size) {14971 else => switch (abi_size) {
14970 1...16 => if (self.hasFeature(.avx)) .{ .v_, .movdqa } else .{ ._, .movdqa },14972 1...16 => if (self.hasFeature(.avx)) .{ .v_, .movdqa } else .{ ._, .movdqa },
14971 17...32 => if (self.hasFeature(.avx)) .{ .v_, .movdqa } else null,14973 17...32 => if (self.hasFeature(.avx)) .{ .v_, .movdqa } else null,
14972 else => null,14974 else => null,
14973 },14975 },
14974 .Float => switch (ty.scalarType(mod).floatBits(self.target.*)) {14976 .Float => switch (ty.scalarType(zcu).floatBits(self.target.*)) {
14975 16, 128 => switch (abi_size) {14977 16, 128 => switch (abi_size) {
14976 2...16 => if (self.hasFeature(.avx))14978 2...16 => if (self.hasFeature(.avx))
14977 .{ .v_, .movdqa }14979 .{ .v_, .movdqa }
...@@ -15035,7 +15037,7 @@ fn genSetReg(...@@ -15035,7 +15037,7 @@ fn genSetReg(
15035 return (try self.moveStrategy(15037 return (try self.moveStrategy(
15036 ty,15038 ty,
15037 dst_reg.class(),15039 dst_reg.class(),
15038 ty.abiAlignment(pt).check(@as(u32, @bitCast(small_addr))),15040 ty.abiAlignment(zcu).check(@as(u32, @bitCast(small_addr))),
15039 )).read(self, registerAlias(dst_reg, abi_size), .{15041 )).read(self, registerAlias(dst_reg, abi_size), .{
15040 .base = .{ .reg = .ds },15042 .base = .{ .reg = .ds },
15041 .mod = .{ .rm = .{15043 .mod = .{ .rm = .{
...@@ -15136,8 +15138,8 @@ fn genSetMem(...@@ -15136,8 +15138,8 @@ fn genSetMem(
15136 opts: CopyOptions,15138 opts: CopyOptions,
15137) InnerError!void {15139) InnerError!void {
15138 const pt = self.pt;15140 const pt = self.pt;
15139 const mod = pt.zcu;15141 const zcu = pt.zcu;
15140 const abi_size: u32 = @intCast(ty.abiSize(pt));15142 const abi_size: u32 = @intCast(ty.abiSize(zcu));
15141 const dst_ptr_mcv: MCValue = switch (base) {15143 const dst_ptr_mcv: MCValue = switch (base) {
15142 .none => .{ .immediate = @bitCast(@as(i64, disp)) },15144 .none => .{ .immediate = @bitCast(@as(i64, disp)) },
15143 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },15145 .reg => |base_reg| .{ .register_offset = .{ .reg = base_reg, .off = disp } },
...@@ -15159,8 +15161,8 @@ fn genSetMem(...@@ -15159,8 +15161,8 @@ fn genSetMem(
15159 ),15161 ),
15160 .immediate => |imm| switch (abi_size) {15162 .immediate => |imm| switch (abi_size) {
15161 1, 2, 4 => {15163 1, 2, 4 => {
15162 const immediate = switch (if (ty.isAbiInt(mod))15164 const immediate = switch (if (ty.isAbiInt(zcu))
15163 ty.intInfo(mod).signedness15165 ty.intInfo(zcu).signedness
15164 else15166 else
15165 .unsigned) {15167 .unsigned) {
15166 .signed => Immediate.s(@truncate(@as(i64, @bitCast(imm)))),15168 .signed => Immediate.s(@truncate(@as(i64, @bitCast(imm)))),
...@@ -15193,7 +15195,7 @@ fn genSetMem(...@@ -15193,7 +15195,7 @@ fn genSetMem(
15193 .size = .dword,15195 .size = .dword,
15194 .disp = disp + offset,15196 .disp = disp + offset,
15195 } } },15197 } } },
15196 if (ty.isSignedInt(mod)) Immediate.s(15198 if (ty.isSignedInt(zcu)) Immediate.s(
15197 @truncate(@as(i64, @bitCast(imm)) >> (math.cast(u6, offset * 8) orelse 63)),15199 @truncate(@as(i64, @bitCast(imm)) >> (math.cast(u6, offset * 8) orelse 63)),
15198 ) else Immediate.u(15200 ) else Immediate.u(
15199 @as(u32, @truncate(if (math.cast(u6, offset * 8)) |shift| imm >> shift else 0)),15201 @as(u32, @truncate(if (math.cast(u6, offset * 8)) |shift| imm >> shift else 0)),
...@@ -15263,33 +15265,33 @@ fn genSetMem(...@@ -15263,33 +15265,33 @@ fn genSetMem(
15263 var part_disp: i32 = disp;15265 var part_disp: i32 = disp;
15264 for (try self.splitType(ty), src_regs) |src_ty, src_reg| {15266 for (try self.splitType(ty), src_regs) |src_ty, src_reg| {
15265 try self.genSetMem(base, part_disp, src_ty, .{ .register = src_reg }, opts);15267 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));
15267 }15269 }
15268 },15270 },
15269 .register_overflow => |ro| switch (ty.zigTypeTag(mod)) {15271 .register_overflow => |ro| switch (ty.zigTypeTag(zcu)) {
15270 .Struct => {15272 .Struct => {
15271 try self.genSetMem(15273 try self.genSetMem(
15272 base,15274 base,
15273 disp + @as(i32, @intCast(ty.structFieldOffset(0, pt))),15275 disp + @as(i32, @intCast(ty.structFieldOffset(0, zcu))),
15274 ty.structFieldType(0, mod),15276 ty.fieldType(0, zcu),
15275 .{ .register = ro.reg },15277 .{ .register = ro.reg },
15276 opts,15278 opts,
15277 );15279 );
15278 try self.genSetMem(15280 try self.genSetMem(
15279 base,15281 base,
15280 disp + @as(i32, @intCast(ty.structFieldOffset(1, pt))),15282 disp + @as(i32, @intCast(ty.structFieldOffset(1, zcu))),
15281 ty.structFieldType(1, mod),15283 ty.fieldType(1, zcu),
15282 .{ .eflags = ro.eflags },15284 .{ .eflags = ro.eflags },
15283 opts,15285 opts,
15284 );15286 );
15285 },15287 },
15286 .Optional => {15288 .Optional => {
15287 assert(!ty.optionalReprIsPayload(mod));15289 assert(!ty.optionalReprIsPayload(zcu));
15288 const child_ty = ty.optionalChild(mod);15290 const child_ty = ty.optionalChild(zcu);
15289 try self.genSetMem(base, disp, child_ty, .{ .register = ro.reg }, opts);15291 try self.genSetMem(base, disp, child_ty, .{ .register = ro.reg }, opts);
15290 try self.genSetMem(15292 try self.genSetMem(
15291 base,15293 base,
15292 disp + @as(i32, @intCast(child_ty.abiSize(pt))),15294 disp + @as(i32, @intCast(child_ty.abiSize(zcu))),
15293 Type.bool,15295 Type.bool,
15294 .{ .eflags = ro.eflags },15296 .{ .eflags = ro.eflags },
15295 opts,15297 opts,
...@@ -15521,14 +15523,14 @@ fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {...@@ -15521,14 +15523,14 @@ fn airIntFromPtr(self: *Self, inst: Air.Inst.Index) !void {
1552115523
15522fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {15524fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
15523 const pt = self.pt;15525 const pt = self.pt;
15524 const mod = pt.zcu;15526 const zcu = pt.zcu;
15525 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;15527 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
15526 const dst_ty = self.typeOfIndex(inst);15528 const dst_ty = self.typeOfIndex(inst);
15527 const src_ty = self.typeOf(ty_op.operand);15529 const src_ty = self.typeOf(ty_op.operand);
1552815530
15529 const result = result: {15531 const result = result: {
15530 const src_mcv = try self.resolveInst(ty_op.operand);15532 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) {
15532 .lea_frame => break :result src_mcv,15534 .lea_frame => break :result src_mcv,
15533 else => if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv,15535 else => if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv,
15534 };15536 };
...@@ -15539,10 +15541,10 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -15539,10 +15541,10 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
15539 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;15541 const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;
15540 defer if (src_lock) |lock| self.register_manager.unlockReg(lock);15542 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) and15544 const dst_mcv = if (dst_rc.supersetOf(src_rc) and dst_ty.abiSize(zcu) <= src_ty.abiSize(zcu) and
15543 self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {15545 self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) src_mcv else dst: {
15544 const dst_mcv = try self.allocRegOrMem(inst, true);15546 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))) {
15546 .lt => dst_ty,15548 .lt => dst_ty,
15547 .eq => if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,15549 .eq => if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,
15548 .gt => src_ty,15550 .gt => src_ty,
...@@ -15552,12 +15554,12 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -15552,12 +15554,12 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1555215554
15553 if (dst_ty.isRuntimeFloat()) break :result dst_mcv;15555 if (dst_ty.isRuntimeFloat()) break :result dst_mcv;
1555415556
15555 if (dst_ty.isAbiInt(mod) and src_ty.isAbiInt(mod) and15557 if (dst_ty.isAbiInt(zcu) and src_ty.isAbiInt(zcu) and
15556 dst_ty.intInfo(mod).signedness == src_ty.intInfo(mod).signedness) break :result dst_mcv;15558 dst_ty.intInfo(zcu).signedness == src_ty.intInfo(zcu).signedness) break :result dst_mcv;
1555715559
15558 const abi_size = dst_ty.abiSize(pt);15560 const abi_size = dst_ty.abiSize(zcu);
15559 const bit_size = dst_ty.bitSize(pt);15561 const bit_size = dst_ty.bitSize(zcu);
15560 if (abi_size * 8 <= bit_size or dst_ty.isVector(mod)) break :result dst_mcv;15562 if (abi_size * 8 <= bit_size or dst_ty.isVector(zcu)) break :result dst_mcv;
1556115563
15562 const dst_limbs_len = math.divCeil(i32, @intCast(bit_size), 64) catch unreachable;15564 const dst_limbs_len = math.divCeil(i32, @intCast(bit_size), 64) catch unreachable;
15563 const high_mcv: MCValue = switch (dst_mcv) {15565 const high_mcv: MCValue = switch (dst_mcv) {
...@@ -15586,20 +15588,20 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {...@@ -15586,20 +15588,20 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
1558615588
15587fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {15589fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
15588 const pt = self.pt;15590 const pt = self.pt;
15589 const mod = pt.zcu;15591 const zcu = pt.zcu;
15590 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;15592 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1559115593
15592 const slice_ty = self.typeOfIndex(inst);15594 const slice_ty = self.typeOfIndex(inst);
15593 const ptr_ty = self.typeOf(ty_op.operand);15595 const ptr_ty = self.typeOf(ty_op.operand);
15594 const ptr = try self.resolveInst(ty_op.operand);15596 const ptr = try self.resolveInst(ty_op.operand);
15595 const array_ty = ptr_ty.childType(mod);15597 const array_ty = ptr_ty.childType(zcu);
15596 const array_len = array_ty.arrayLen(mod);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));
15599 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr, .{});15601 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr, .{});
15600 try self.genSetMem(15602 try self.genSetMem(
15601 .{ .frame = frame_index },15603 .{ .frame = frame_index },
15602 @intCast(ptr_ty.abiSize(pt)),15604 @intCast(ptr_ty.abiSize(zcu)),
15603 Type.usize,15605 Type.usize,
15604 .{ .immediate = array_len },15606 .{ .immediate = array_len },
15605 .{},15607 .{},
...@@ -15611,16 +15613,16 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {...@@ -15611,16 +15613,16 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1561115613
15612fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {15614fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
15613 const pt = self.pt;15615 const pt = self.pt;
15614 const mod = pt.zcu;15616 const zcu = pt.zcu;
15615 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;15617 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1561615618
15617 const dst_ty = self.typeOfIndex(inst);15619 const dst_ty = self.typeOfIndex(inst);
15618 const dst_bits = dst_ty.floatBits(self.target.*);15620 const dst_bits = dst_ty.floatBits(self.target.*);
1561915621
15620 const src_ty = self.typeOf(ty_op.operand);15622 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));
15622 const src_signedness =15624 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;
15624 const src_size = math.divCeil(u32, @max(switch (src_signedness) {15626 const src_size = math.divCeil(u32, @max(switch (src_signedness) {
15625 .signed => src_bits,15627 .signed => src_bits,
15626 .unsigned => src_bits + 1,15628 .unsigned => src_bits + 1,
...@@ -15666,7 +15668,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -15666,7 +15668,7 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
15666 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);15668 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
15667 defer self.register_manager.unlockReg(dst_lock);15669 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)) {
15670 .Float => switch (dst_ty.floatBits(self.target.*)) {15672 .Float => switch (dst_ty.floatBits(self.target.*)) {
15671 32 => if (self.hasFeature(.avx)) .{ .v_ss, .cvtsi2 } else .{ ._ss, .cvtsi2 },15673 32 => if (self.hasFeature(.avx)) .{ .v_ss, .cvtsi2 } else .{ ._ss, .cvtsi2 },
15672 64 => if (self.hasFeature(.avx)) .{ .v_sd, .cvtsi2 } else .{ ._sd, .cvtsi2 },15674 64 => if (self.hasFeature(.avx)) .{ .v_sd, .cvtsi2 } else .{ ._sd, .cvtsi2 },
...@@ -15691,13 +15693,13 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {...@@ -15691,13 +15693,13 @@ fn airFloatFromInt(self: *Self, inst: Air.Inst.Index) !void {
1569115693
15692fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {15694fn airIntFromFloat(self: *Self, inst: Air.Inst.Index) !void {
15693 const pt = self.pt;15695 const pt = self.pt;
15694 const mod = pt.zcu;15696 const zcu = pt.zcu;
15695 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;15697 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
1569615698
15697 const dst_ty = self.typeOfIndex(inst);15699 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));
15699 const dst_signedness =15701 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;
15701 const dst_size = math.divCeil(u32, @max(switch (dst_signedness) {15703 const dst_size = math.divCeil(u32, @max(switch (dst_signedness) {
15702 .signed => dst_bits,15704 .signed => dst_bits,
15703 .unsigned => dst_bits + 1,15705 .unsigned => dst_bits + 1,
...@@ -15768,7 +15770,7 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {...@@ -15768,7 +15770,7 @@ fn airCmpxchg(self: *Self, inst: Air.Inst.Index) !void {
1576815770
15769 const ptr_ty = self.typeOf(extra.ptr);15771 const ptr_ty = self.typeOf(extra.ptr);
15770 const val_ty = self.typeOf(extra.expected_value);15772 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
15773 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });15775 try self.spillRegisters(&.{ .rax, .rdx, .rbx, .rcx });
15774 const regs_lock = self.register_manager.lockRegsAssumeUnused(4, .{ .rax, .rdx, .rbx, .rcx });15776 const regs_lock = self.register_manager.lockRegsAssumeUnused(4, .{ .rax, .rdx, .rbx, .rcx });
...@@ -15859,7 +15861,7 @@ fn atomicOp(...@@ -15859,7 +15861,7 @@ fn atomicOp(
15859 order: std.builtin.AtomicOrder,15861 order: std.builtin.AtomicOrder,
15860) InnerError!MCValue {15862) InnerError!MCValue {
15861 const pt = self.pt;15863 const pt = self.pt;
15862 const mod = pt.zcu;15864 const zcu = pt.zcu;
15863 const ptr_lock = switch (ptr_mcv) {15865 const ptr_lock = switch (ptr_mcv) {
15864 .register => |reg| self.register_manager.lockReg(reg),15866 .register => |reg| self.register_manager.lockReg(reg),
15865 else => null,15867 else => null,
...@@ -15872,7 +15874,7 @@ fn atomicOp(...@@ -15872,7 +15874,7 @@ fn atomicOp(
15872 };15874 };
15873 defer if (val_lock) |lock| self.register_manager.unlockReg(lock);15875 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));
15876 const mem_size = Memory.Size.fromSize(val_abi_size);15878 const mem_size = Memory.Size.fromSize(val_abi_size);
15877 const ptr_mem: Memory = switch (ptr_mcv) {15879 const ptr_mem: Memory = switch (ptr_mcv) {
15878 .immediate, .register, .register_offset, .lea_frame => try ptr_mcv.deref().mem(self, mem_size),15880 .immediate, .register, .register_offset, .lea_frame => try ptr_mcv.deref().mem(self, mem_size),
...@@ -16031,8 +16033,8 @@ fn atomicOp(...@@ -16031,8 +16033,8 @@ fn atomicOp(
16031 .Or => try self.genBinOpMir(.{ ._, .@"or" }, val_ty, tmp_mcv, val_mcv),16033 .Or => try self.genBinOpMir(.{ ._, .@"or" }, val_ty, tmp_mcv, val_mcv),
16032 .Xor => try self.genBinOpMir(.{ ._, .xor }, val_ty, tmp_mcv, val_mcv),16034 .Xor => try self.genBinOpMir(.{ ._, .xor }, val_ty, tmp_mcv, val_mcv),
16033 .Min, .Max => {16035 .Min, .Max => {
16034 const cc: Condition = switch (if (val_ty.isAbiInt(mod))16036 const cc: Condition = switch (if (val_ty.isAbiInt(zcu))
16035 val_ty.intInfo(mod).signedness16037 val_ty.intInfo(zcu).signedness
16036 else16038 else
16037 .unsigned) {16039 .unsigned) {
16038 .unsigned => switch (op) {16040 .unsigned => switch (op) {
...@@ -16156,8 +16158,8 @@ fn atomicOp(...@@ -16156,8 +16158,8 @@ fn atomicOp(
16156 try self.asmRegisterMemory(.{ ._, .xor }, .rcx, val_hi_mem);16158 try self.asmRegisterMemory(.{ ._, .xor }, .rcx, val_hi_mem);
16157 },16159 },
16158 .Min, .Max => {16160 .Min, .Max => {
16159 const cc: Condition = switch (if (val_ty.isAbiInt(mod))16161 const cc: Condition = switch (if (val_ty.isAbiInt(zcu))
16160 val_ty.intInfo(mod).signedness16162 val_ty.intInfo(zcu).signedness
16161 else16163 else
16162 .unsigned) {16164 .unsigned) {
16163 .unsigned => switch (op) {16165 .unsigned => switch (op) {
...@@ -16264,7 +16266,7 @@ fn airAtomicStore(self: *Self, inst: Air.Inst.Index, order: std.builtin.AtomicOr...@@ -16264,7 +16266,7 @@ fn airAtomicStore(self: *Self, inst: Air.Inst.Index, order: std.builtin.AtomicOr
1626416266
16265fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {16267fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
16266 const pt = self.pt;16268 const pt = self.pt;
16267 const mod = pt.zcu;16269 const zcu = pt.zcu;
16268 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;16270 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1626916271
16270 result: {16272 result: {
...@@ -16290,19 +16292,19 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -16290,19 +16292,19 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
16290 };16292 };
16291 defer if (src_val_lock) |lock| self.register_manager.unlockReg(lock);16293 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
16295 if (elem_abi_size == 1) {16297 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)) {
16297 // TODO: this only handles slices stored in the stack16299 // TODO: this only handles slices stored in the stack
16298 .Slice => dst_ptr,16300 .Slice => dst_ptr,
16299 .One => dst_ptr,16301 .One => dst_ptr,
16300 .C, .Many => unreachable,16302 .C, .Many => unreachable,
16301 };16303 };
16302 const len: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {16304 const len: MCValue = switch (dst_ptr_ty.ptrSize(zcu)) {
16303 // TODO: this only handles slices stored in the stack16305 // TODO: this only handles slices stored in the stack
16304 .Slice => dst_ptr.address().offset(8).deref(),16306 .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) },
16306 .C, .Many => unreachable,16308 .C, .Many => unreachable,
16307 };16309 };
16308 const len_lock: ?RegisterLock = switch (len) {16310 const len_lock: ?RegisterLock = switch (len) {
...@@ -16318,9 +16320,9 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -16318,9 +16320,9 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
16318 // Store the first element, and then rely on memcpy copying forwards.16320 // Store the first element, and then rely on memcpy copying forwards.
16319 // Length zero requires a runtime check - so we handle arrays specially16321 // Length zero requires a runtime check - so we handle arrays specially
16320 // here to elide it.16322 // here to elide it.
16321 switch (dst_ptr_ty.ptrSize(mod)) {16323 switch (dst_ptr_ty.ptrSize(zcu)) {
16322 .Slice => {16324 .Slice => {
16323 const slice_ptr_ty = dst_ptr_ty.slicePtrFieldType(mod);16325 const slice_ptr_ty = dst_ptr_ty.slicePtrFieldType(zcu);
1632416326
16325 // TODO: this only handles slices stored in the stack16327 // TODO: this only handles slices stored in the stack
16326 const ptr = dst_ptr;16328 const ptr = dst_ptr;
...@@ -16365,7 +16367,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {...@@ -16365,7 +16367,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
16365 .One => {16367 .One => {
16366 const elem_ptr_ty = try pt.singleMutPtrType(elem_ty);16368 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
16370 assert(len != 0); // prevented by Sema16372 assert(len != 0); // prevented by Sema
16371 try self.store(elem_ptr_ty, dst_ptr, src_val, .{ .safety = safety });16373 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 {...@@ -16393,7 +16395,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1639316395
16394fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {16396fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
16395 const pt = self.pt;16397 const pt = self.pt;
16396 const mod = pt.zcu;16398 const zcu = pt.zcu;
16397 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;16399 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
1639816400
16399 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });16401 try self.spillRegisters(&.{ .rdi, .rsi, .rcx });
...@@ -16415,7 +16417,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -16415,7 +16417,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
16415 };16417 };
16416 defer if (src_ptr_lock) |lock| self.register_manager.unlockReg(lock);16418 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)) {
16419 .Slice => len: {16421 .Slice => len: {
16420 const len_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);16422 const len_reg = try self.register_manager.allocReg(null, abi.RegisterClass.gp);
16421 const len_lock = self.register_manager.lockRegAssumeUnused(len_reg);16423 const len_lock = self.register_manager.lockRegAssumeUnused(len_reg);
...@@ -16425,13 +16427,13 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -16425,13 +16427,13 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
16425 .{ .i_, .mul },16427 .{ .i_, .mul },
16426 len_reg,16428 len_reg,
16427 try dst_ptr.address().offset(8).deref().mem(self, .qword),16429 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))),
16429 );16431 );
16430 break :len .{ .register = len_reg };16432 break :len .{ .register = len_reg };
16431 },16433 },
16432 .One => len: {16434 .One => len: {
16433 const array_ty = dst_ptr_ty.childType(mod);16435 const array_ty = dst_ptr_ty.childType(zcu);
16434 break :len .{ .immediate = array_ty.arrayLen(mod) * array_ty.childType(mod).abiSize(pt) };16436 break :len .{ .immediate = array_ty.arrayLen(zcu) * array_ty.childType(zcu).abiSize(zcu) };
16435 },16437 },
16436 .C, .Many => unreachable,16438 .C, .Many => unreachable,
16437 };16439 };
...@@ -16449,6 +16451,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {...@@ -16449,6 +16451,7 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1644916451
16450fn airTagName(self: *Self, inst: Air.Inst.Index) !void {16452fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
16451 const pt = self.pt;16453 const pt = self.pt;
16454 const zcu = pt.zcu;
16452 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;16455 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
16453 const inst_ty = self.typeOfIndex(inst);16456 const inst_ty = self.typeOfIndex(inst);
16454 const enum_ty = self.typeOf(un_op);16457 const enum_ty = self.typeOf(un_op);
...@@ -16457,8 +16460,8 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {...@@ -16457,8 +16460,8 @@ fn airTagName(self: *Self, inst: Air.Inst.Index) !void {
16457 // We need a properly aligned and sized call frame to be able to call this function.16460 // We need a properly aligned and sized call frame to be able to call this function.
16458 {16461 {
16459 const needed_call_frame = FrameAlloc.init(.{16462 const needed_call_frame = FrameAlloc.init(.{
16460 .size = inst_ty.abiSize(pt),16463 .size = inst_ty.abiSize(zcu),
16461 .alignment = inst_ty.abiAlignment(pt),16464 .alignment = inst_ty.abiAlignment(zcu),
16462 });16465 });
16463 const frame_allocs_slice = self.frame_allocs.slice();16466 const frame_allocs_slice = self.frame_allocs.slice();
16464 const stack_frame_size =16467 const stack_frame_size =
...@@ -16590,15 +16593,15 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {...@@ -16590,15 +16593,15 @@ fn airErrorName(self: *Self, inst: Air.Inst.Index) !void {
1659016593
16591fn airSplat(self: *Self, inst: Air.Inst.Index) !void {16594fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
16592 const pt = self.pt;16595 const pt = self.pt;
16593 const mod = pt.zcu;16596 const zcu = pt.zcu;
16594 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;16597 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
16595 const vector_ty = self.typeOfIndex(inst);16598 const vector_ty = self.typeOfIndex(inst);
16596 const vector_len = vector_ty.vectorLen(mod);16599 const vector_len = vector_ty.vectorLen(zcu);
16597 const dst_rc = self.regClassForType(vector_ty);16600 const dst_rc = self.regClassForType(vector_ty);
16598 const scalar_ty = self.typeOf(ty_op.operand);16601 const scalar_ty = self.typeOf(ty_op.operand);
1659916602
16600 const result: MCValue = result: {16603 const result: MCValue = result: {
16601 switch (scalar_ty.zigTypeTag(mod)) {16604 switch (scalar_ty.zigTypeTag(zcu)) {
16602 else => {},16605 else => {},
16603 .Bool => {16606 .Bool => {
16604 const regs =16607 const regs =
...@@ -16641,7 +16644,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {...@@ -16641,7 +16644,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
16641 break :result .{ .register = regs[0] };16644 break :result .{ .register = regs[0] };
16642 },16645 },
16643 .Int => if (self.hasFeature(.avx2)) avx2: {16646 .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) {
16645 else => null,16648 else => null,
16646 1...8 => switch (vector_len) {16649 1...8 => switch (vector_len) {
16647 else => null,16650 else => null,
...@@ -16672,15 +16675,15 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {...@@ -16672,15 +16675,15 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
16672 const src_mcv = try self.resolveInst(ty_op.operand);16675 const src_mcv = try self.resolveInst(ty_op.operand);
16673 if (src_mcv.isMemory()) try self.asmRegisterMemory(16676 if (src_mcv.isMemory()) try self.asmRegisterMemory(
16674 mir_tag,16677 mir_tag,
16675 registerAlias(dst_reg, @intCast(vector_ty.abiSize(pt))),16678 registerAlias(dst_reg, @intCast(vector_ty.abiSize(zcu))),
16676 try src_mcv.mem(self, self.memSize(scalar_ty)),16679 try src_mcv.mem(self, self.memSize(scalar_ty)),
16677 ) else {16680 ) else {
16678 if (mir_tag[0] == .v_i128) break :avx2;16681 if (mir_tag[0] == .v_i128) break :avx2;
16679 try self.genSetReg(dst_reg, scalar_ty, src_mcv, .{});16682 try self.genSetReg(dst_reg, scalar_ty, src_mcv, .{});
16680 try self.asmRegisterRegister(16683 try self.asmRegisterRegister(
16681 mir_tag,16684 mir_tag,
16682 registerAlias(dst_reg, @intCast(vector_ty.abiSize(pt))),16685 registerAlias(dst_reg, @intCast(vector_ty.abiSize(zcu))),
16683 registerAlias(dst_reg, @intCast(scalar_ty.abiSize(pt))),16686 registerAlias(dst_reg, @intCast(scalar_ty.abiSize(zcu))),
16684 );16687 );
16685 }16688 }
16686 break :result .{ .register = dst_reg };16689 break :result .{ .register = dst_reg };
...@@ -16692,8 +16695,8 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {...@@ -16692,8 +16695,8 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
16692 try self.genSetReg(dst_reg, scalar_ty, .{ .air_ref = ty_op.operand }, .{});16695 try self.genSetReg(dst_reg, scalar_ty, .{ .air_ref = ty_op.operand }, .{});
16693 if (vector_len == 1) break :result .{ .register = dst_reg };16696 if (vector_len == 1) break :result .{ .register = dst_reg };
1669416697
16695 const dst_alias = registerAlias(dst_reg, @intCast(vector_ty.abiSize(pt)));16698 const dst_alias = registerAlias(dst_reg, @intCast(vector_ty.abiSize(zcu)));
16696 const scalar_bits = scalar_ty.intInfo(mod).bits;16699 const scalar_bits = scalar_ty.intInfo(zcu).bits;
16697 if (switch (scalar_bits) {16700 if (switch (scalar_bits) {
16698 1...8 => true,16701 1...8 => true,
16699 9...128 => false,16702 9...128 => false,
...@@ -16929,14 +16932,14 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {...@@ -16929,14 +16932,14 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1692916932
16930fn airSelect(self: *Self, inst: Air.Inst.Index) !void {16933fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
16931 const pt = self.pt;16934 const pt = self.pt;
16932 const mod = pt.zcu;16935 const zcu = pt.zcu;
16933 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;16936 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
16934 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;16937 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
16935 const ty = self.typeOfIndex(inst);16938 const ty = self.typeOfIndex(inst);
16936 const vec_len = ty.vectorLen(mod);16939 const vec_len = ty.vectorLen(zcu);
16937 const elem_ty = ty.childType(mod);16940 const elem_ty = ty.childType(zcu);
16938 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(pt));16941 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(zcu));
16939 const abi_size: u32 = @intCast(ty.abiSize(pt));16942 const abi_size: u32 = @intCast(ty.abiSize(zcu));
16940 const pred_ty = self.typeOf(pl_op.operand);16943 const pred_ty = self.typeOf(pl_op.operand);
1694116944
16942 const result = result: {16945 const result = result: {
...@@ -17160,7 +17163,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {...@@ -17160,7 +17163,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
17160 const dst_lock = self.register_manager.lockReg(dst_reg);17163 const dst_lock = self.register_manager.lockReg(dst_reg);
17161 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);17164 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)) {
17164 else => null,17167 else => null,
17165 .Int => switch (abi_size) {17168 .Int => switch (abi_size) {
17166 0 => unreachable,17169 0 => unreachable,
...@@ -17176,7 +17179,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {...@@ -17176,7 +17179,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
17176 null,17179 null,
17177 else => null,17180 else => null,
17178 },17181 },
17179 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {17182 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
17180 else => unreachable,17183 else => unreachable,
17181 16, 80, 128 => null,17184 16, 80, 128 => null,
17182 32 => switch (vec_len) {17185 32 => switch (vec_len) {
...@@ -17230,7 +17233,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {...@@ -17230,7 +17233,7 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
17230 try self.copyToTmpRegister(ty, lhs_mcv), abi_size),17233 try self.copyToTmpRegister(ty, lhs_mcv), abi_size),
17231 mask_alias,17234 mask_alias,
17232 ) else {17235 ) 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)) {
17234 else => null,17237 else => null,
17235 .Int => .p_,17238 .Int => .p_,
17236 .Float => switch (elem_ty.floatBits(self.target.*)) {17239 .Float => switch (elem_ty.floatBits(self.target.*)) {
...@@ -17262,18 +17265,18 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {...@@ -17262,18 +17265,18 @@ fn airSelect(self: *Self, inst: Air.Inst.Index) !void {
1726217265
17263fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {17266fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
17264 const pt = self.pt;17267 const pt = self.pt;
17265 const mod = pt.zcu;17268 const zcu = pt.zcu;
17266 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;17269 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
17267 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;17270 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
1726817271
17269 const dst_ty = self.typeOfIndex(inst);17272 const dst_ty = self.typeOfIndex(inst);
17270 const elem_ty = dst_ty.childType(mod);17273 const elem_ty = dst_ty.childType(zcu);
17271 const elem_abi_size: u16 = @intCast(elem_ty.abiSize(pt));17274 const elem_abi_size: u16 = @intCast(elem_ty.abiSize(zcu));
17272 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(pt));17275 const dst_abi_size: u32 = @intCast(dst_ty.abiSize(zcu));
17273 const lhs_ty = self.typeOf(extra.a);17276 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));
17275 const rhs_ty = self.typeOf(extra.b);17278 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));
17277 const max_abi_size = @max(dst_abi_size, lhs_abi_size, rhs_abi_size);17280 const max_abi_size = @max(dst_abi_size, lhs_abi_size, rhs_abi_size);
1727817281
17279 const ExpectedContents = [32]?i32;17282 const ExpectedContents = [32]?i32;
...@@ -17286,10 +17289,10 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {...@@ -17286,10 +17289,10 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
17286 for (mask_elems, 0..) |*mask_elem, elem_index| {17289 for (mask_elems, 0..) |*mask_elem, elem_index| {
17287 const mask_elem_val =17290 const mask_elem_val =
17288 Value.fromInterned(extra.mask).elemValue(pt, elem_index) catch unreachable;17291 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))
17290 null17293 null
17291 else17294 else
17292 @intCast(mask_elem_val.toSignedInt(pt));17295 @intCast(mask_elem_val.toSignedInt(zcu));
17293 }17296 }
1729417297
17295 const has_avx = self.hasFeature(.avx);17298 const has_avx = self.hasFeature(.avx);
...@@ -18028,7 +18031,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {...@@ -18028,7 +18031,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
18028 );18031 );
1802918032
18030 if (has_avx) try self.asmRegisterRegisterRegister(18033 if (has_avx) try self.asmRegisterRegisterRegister(
18031 .{ switch (elem_ty.zigTypeTag(mod)) {18034 .{ switch (elem_ty.zigTypeTag(zcu)) {
18032 else => break :result null,18035 else => break :result null,
18033 .Int => .vp_,18036 .Int => .vp_,
18034 .Float => switch (elem_ty.floatBits(self.target.*)) {18037 .Float => switch (elem_ty.floatBits(self.target.*)) {
...@@ -18042,7 +18045,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {...@@ -18042,7 +18045,7 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
18042 lhs_temp_alias,18045 lhs_temp_alias,
18043 rhs_temp_alias,18046 rhs_temp_alias,
18044 ) else try self.asmRegisterRegister(18047 ) else try self.asmRegisterRegister(
18045 .{ switch (elem_ty.zigTypeTag(mod)) {18048 .{ switch (elem_ty.zigTypeTag(zcu)) {
18046 else => break :result null,18049 else => break :result null,
18047 .Int => .p_,18050 .Int => .p_,
18048 .Float => switch (elem_ty.floatBits(self.target.*)) {18051 .Float => switch (elem_ty.floatBits(self.target.*)) {
...@@ -18068,19 +18071,19 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {...@@ -18068,19 +18071,19 @@ fn airShuffle(self: *Self, inst: Air.Inst.Index) !void {
1806818071
18069fn airReduce(self: *Self, inst: Air.Inst.Index) !void {18072fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
18070 const pt = self.pt;18073 const pt = self.pt;
18071 const mod = pt.zcu;18074 const zcu = pt.zcu;
18072 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;18075 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
1807318076
18074 const result: MCValue = result: {18077 const result: MCValue = result: {
18075 const operand_ty = self.typeOf(reduce.operand);18078 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) {
18077 try self.spillEflagsIfOccupied();18080 try self.spillEflagsIfOccupied();
1807818081
18079 const operand_mcv = try self.resolveInst(reduce.operand);18082 const operand_mcv = try self.resolveInst(reduce.operand);
18080 const mask_len = (math.cast(u6, operand_ty.vectorLen(mod)) orelse18083 const mask_len = (math.cast(u6, operand_ty.vectorLen(zcu)) orelse
18081 return self.fail("TODO implement airReduce for {}", .{operand_ty.fmt(pt)}));18084 return self.fail("TODO implement airReduce for {}", .{operand_ty.fmt(pt)}));
18082 const mask = (@as(u64, 1) << mask_len) - 1;18085 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));
18084 switch (reduce.operation) {18087 switch (reduce.operation) {
18085 .Or => {18088 .Or => {
18086 if (operand_mcv.isMemory()) try self.asmMemoryImmediate(18089 if (operand_mcv.isMemory()) try self.asmMemoryImmediate(
...@@ -18126,36 +18129,36 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {...@@ -18126,36 +18129,36 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1812618129
18127fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {18130fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
18128 const pt = self.pt;18131 const pt = self.pt;
18129 const mod = pt.zcu;18132 const zcu = pt.zcu;
18130 const result_ty = self.typeOfIndex(inst);18133 const result_ty = self.typeOfIndex(inst);
18131 const len: usize = @intCast(result_ty.arrayLen(mod));18134 const len: usize = @intCast(result_ty.arrayLen(zcu));
18132 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;18135 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
18133 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);18136 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
18134 const result: MCValue = result: {18137 const result: MCValue = result: {
18135 switch (result_ty.zigTypeTag(mod)) {18138 switch (result_ty.zigTypeTag(zcu)) {
18136 .Struct => {18139 .Struct => {
18137 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, pt));18140 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, zcu));
18138 if (result_ty.containerLayout(mod) == .@"packed") {18141 if (result_ty.containerLayout(zcu) == .@"packed") {
18139 const struct_obj = mod.typeToStruct(result_ty).?;18142 const struct_obj = zcu.typeToStruct(result_ty).?;
18140 try self.genInlineMemset(18143 try self.genInlineMemset(
18141 .{ .lea_frame = .{ .index = frame_index } },18144 .{ .lea_frame = .{ .index = frame_index } },
18142 .{ .immediate = 0 },18145 .{ .immediate = 0 },
18143 .{ .immediate = result_ty.abiSize(pt) },18146 .{ .immediate = result_ty.abiSize(zcu) },
18144 .{},18147 .{},
18145 );18148 );
18146 for (elements, 0..) |elem, elem_i_usize| {18149 for (elements, 0..) |elem, elem_i_usize| {
18147 const elem_i: u32 = @intCast(elem_i_usize);18150 const elem_i: u32 = @intCast(elem_i_usize);
18148 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;18151 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
1814918152
18150 const elem_ty = result_ty.structFieldType(elem_i, mod);18153 const elem_ty = result_ty.fieldType(elem_i, zcu);
18151 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(pt));18154 const elem_bit_size: u32 = @intCast(elem_ty.bitSize(zcu));
18152 if (elem_bit_size > 64) {18155 if (elem_bit_size > 64) {
18153 return self.fail(18156 return self.fail(
18154 "TODO airAggregateInit implement packed structs with large fields",18157 "TODO airAggregateInit implement packed structs with large fields",
18155 .{},18158 .{},
18156 );18159 );
18157 }18160 }
18158 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(pt));18161 const elem_abi_size: u32 = @intCast(elem_ty.abiSize(zcu));
18159 const elem_abi_bits = elem_abi_size * 8;18162 const elem_abi_bits = elem_abi_size * 8;
18160 const elem_off = pt.structPackedFieldBitOffset(struct_obj, elem_i);18163 const elem_off = pt.structPackedFieldBitOffset(struct_obj, elem_i);
18161 const elem_byte_off: i32 = @intCast(elem_off / elem_abi_bits * elem_abi_size);18164 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 {...@@ -18229,8 +18232,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
18229 } else for (elements, 0..) |elem, elem_i| {18232 } else for (elements, 0..) |elem, elem_i| {
18230 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;18233 if ((try result_ty.structFieldValueComptime(pt, elem_i)) != null) continue;
1823118234
18232 const elem_ty = result_ty.structFieldType(elem_i, mod);18235 const elem_ty = result_ty.fieldType(elem_i, zcu);
18233 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, pt));18236 const elem_off: i32 = @intCast(result_ty.structFieldOffset(elem_i, zcu));
18234 const elem_mcv = try self.resolveInst(elem);18237 const elem_mcv = try self.resolveInst(elem);
18235 const mat_elem_mcv = switch (elem_mcv) {18238 const mat_elem_mcv = switch (elem_mcv) {
18236 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },18239 .load_tlv => |sym_index| MCValue{ .lea_tlv = sym_index },
...@@ -18241,9 +18244,9 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -18241,9 +18244,9 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
18241 break :result .{ .load_frame = .{ .index = frame_index } };18244 break :result .{ .load_frame = .{ .index = frame_index } };
18242 },18245 },
18243 .Array, .Vector => {18246 .Array, .Vector => {
18244 const elem_ty = result_ty.childType(mod);18247 const elem_ty = result_ty.childType(zcu);
18245 if (result_ty.isVector(mod) and elem_ty.toIntern() == .bool_type) {18248 if (result_ty.isVector(zcu) and elem_ty.toIntern() == .bool_type) {
18246 const result_size: u32 = @intCast(result_ty.abiSize(pt));18249 const result_size: u32 = @intCast(result_ty.abiSize(zcu));
18247 const dst_reg = try self.register_manager.allocReg(inst, abi.RegisterClass.gp);18250 const dst_reg = try self.register_manager.allocReg(inst, abi.RegisterClass.gp);
18248 try self.asmRegisterRegister(18251 try self.asmRegisterRegister(
18249 .{ ._, .xor },18252 .{ ._, .xor },
...@@ -18274,8 +18277,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -18274,8 +18277,8 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
18274 }18277 }
18275 break :result .{ .register = dst_reg };18278 break :result .{ .register = dst_reg };
18276 } else {18279 } else {
18277 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, pt));18280 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(result_ty, zcu));
18278 const elem_size: u32 = @intCast(elem_ty.abiSize(pt));18281 const elem_size: u32 = @intCast(elem_ty.abiSize(zcu));
1827918282
18280 for (elements, 0..) |elem, elem_i| {18283 for (elements, 0..) |elem, elem_i| {
18281 const elem_mcv = try self.resolveInst(elem);18284 const elem_mcv = try self.resolveInst(elem);
...@@ -18292,7 +18295,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -18292,7 +18295,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
18292 .{},18295 .{},
18293 );18296 );
18294 }18297 }
18295 if (result_ty.sentinel(mod)) |sentinel| try self.genSetMem(18298 if (result_ty.sentinel(zcu)) |sentinel| try self.genSetMem(
18296 .{ .frame = frame_index },18299 .{ .frame = frame_index },
18297 @intCast(elem_size * elements.len),18300 @intCast(elem_size * elements.len),
18298 elem_ty,18301 elem_ty,
...@@ -18318,18 +18321,18 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -18318,18 +18321,18 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1831818321
18319fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {18322fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
18320 const pt = self.pt;18323 const pt = self.pt;
18321 const mod = pt.zcu;18324 const zcu = pt.zcu;
18322 const ip = &mod.intern_pool;18325 const ip = &zcu.intern_pool;
18323 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;18326 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
18324 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;18327 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
18325 const result: MCValue = result: {18328 const result: MCValue = result: {
18326 const union_ty = self.typeOfIndex(inst);18329 const union_ty = self.typeOfIndex(inst);
18327 const layout = union_ty.unionGetLayout(pt);18330 const layout = union_ty.unionGetLayout(zcu);
1832818331
18329 const src_ty = self.typeOf(extra.init);18332 const src_ty = self.typeOf(extra.init);
18330 const src_mcv = try self.resolveInst(extra.init);18333 const src_mcv = try self.resolveInst(extra.init);
18331 if (layout.tag_size == 0) {18334 if (layout.tag_size == 0) {
18332 if (layout.abi_size <= src_ty.abiSize(pt) and18335 if (layout.abi_size <= src_ty.abiSize(zcu) and
18333 self.reuseOperand(inst, extra.init, 0, src_mcv)) break :result src_mcv;18336 self.reuseOperand(inst, extra.init, 0, src_mcv)) break :result src_mcv;
1833418337
18335 const dst_mcv = try self.allocRegOrMem(inst, true);18338 const dst_mcv = try self.allocRegOrMem(inst, true);
...@@ -18339,13 +18342,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -18339,13 +18342,13 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1833918342
18340 const dst_mcv = try self.allocRegOrMem(inst, false);18343 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).?;
18343 const field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];18346 const field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];
18344 const tag_ty = Type.fromInterned(union_obj.enum_tag_ty);18347 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).?;
18346 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);18349 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
18347 const tag_int_val = try tag_val.intFromEnum(tag_ty, pt);18350 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);
18349 const tag_off: i32 = @intCast(layout.tagOffset());18352 const tag_off: i32 = @intCast(layout.tagOffset());
18350 try self.genCopy(18353 try self.genCopy(
18351 tag_ty,18354 tag_ty,
...@@ -18369,19 +18372,19 @@ fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {...@@ -18369,19 +18372,19 @@ fn airPrefetch(self: *Self, inst: Air.Inst.Index) !void {
1836918372
18370fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {18373fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
18371 const pt = self.pt;18374 const pt = self.pt;
18372 const mod = pt.zcu;18375 const zcu = pt.zcu;
18373 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;18376 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
18374 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;18377 const extra = self.air.extraData(Air.Bin, pl_op.payload).data;
18375 const ty = self.typeOfIndex(inst);18378 const ty = self.typeOfIndex(inst);
1837618379
18377 const ops = [3]Air.Inst.Ref{ extra.lhs, extra.rhs, pl_op.operand };18380 const ops = [3]Air.Inst.Ref{ extra.lhs, extra.rhs, pl_op.operand };
18378 const result = result: {18381 const result = result: {
18379 if (switch (ty.scalarType(mod).floatBits(self.target.*)) {18382 if (switch (ty.scalarType(zcu).floatBits(self.target.*)) {
18380 16, 80, 128 => true,18383 16, 80, 128 => true,
18381 32, 64 => !self.hasFeature(.fma),18384 32, 64 => !self.hasFeature(.fma),
18382 else => unreachable,18385 else => unreachable,
18383 }) {18386 }) {
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 {}", .{
18385 ty.fmt(pt),18388 ty.fmt(pt),
18386 });18389 });
1838718390
...@@ -18430,21 +18433,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -18430,21 +18433,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1843018433
18431 const mir_tag = @as(?Mir.Inst.FixedTag, if (mem.eql(u2, &order, &.{ 1, 3, 2 }) or18434 const mir_tag = @as(?Mir.Inst.FixedTag, if (mem.eql(u2, &order, &.{ 1, 3, 2 }) or
18432 mem.eql(u2, &order, &.{ 3, 1, 2 }))18435 mem.eql(u2, &order, &.{ 3, 1, 2 }))
18433 switch (ty.zigTypeTag(mod)) {18436 switch (ty.zigTypeTag(zcu)) {
18434 .Float => switch (ty.floatBits(self.target.*)) {18437 .Float => switch (ty.floatBits(self.target.*)) {
18435 32 => .{ .v_ss, .fmadd132 },18438 32 => .{ .v_ss, .fmadd132 },
18436 64 => .{ .v_sd, .fmadd132 },18439 64 => .{ .v_sd, .fmadd132 },
18437 16, 80, 128 => null,18440 16, 80, 128 => null,
18438 else => unreachable,18441 else => unreachable,
18439 },18442 },
18440 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {18443 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
18441 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {18444 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
18442 32 => switch (ty.vectorLen(mod)) {18445 32 => switch (ty.vectorLen(zcu)) {
18443 1 => .{ .v_ss, .fmadd132 },18446 1 => .{ .v_ss, .fmadd132 },
18444 2...8 => .{ .v_ps, .fmadd132 },18447 2...8 => .{ .v_ps, .fmadd132 },
18445 else => null,18448 else => null,
18446 },18449 },
18447 64 => switch (ty.vectorLen(mod)) {18450 64 => switch (ty.vectorLen(zcu)) {
18448 1 => .{ .v_sd, .fmadd132 },18451 1 => .{ .v_sd, .fmadd132 },
18449 2...4 => .{ .v_pd, .fmadd132 },18452 2...4 => .{ .v_pd, .fmadd132 },
18450 else => null,18453 else => null,
...@@ -18457,21 +18460,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -18457,21 +18460,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
18457 else => unreachable,18460 else => unreachable,
18458 }18461 }
18459 else if (mem.eql(u2, &order, &.{ 2, 1, 3 }) or mem.eql(u2, &order, &.{ 1, 2, 3 }))18462 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)) {
18461 .Float => switch (ty.floatBits(self.target.*)) {18464 .Float => switch (ty.floatBits(self.target.*)) {
18462 32 => .{ .v_ss, .fmadd213 },18465 32 => .{ .v_ss, .fmadd213 },
18463 64 => .{ .v_sd, .fmadd213 },18466 64 => .{ .v_sd, .fmadd213 },
18464 16, 80, 128 => null,18467 16, 80, 128 => null,
18465 else => unreachable,18468 else => unreachable,
18466 },18469 },
18467 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {18470 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
18468 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {18471 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
18469 32 => switch (ty.vectorLen(mod)) {18472 32 => switch (ty.vectorLen(zcu)) {
18470 1 => .{ .v_ss, .fmadd213 },18473 1 => .{ .v_ss, .fmadd213 },
18471 2...8 => .{ .v_ps, .fmadd213 },18474 2...8 => .{ .v_ps, .fmadd213 },
18472 else => null,18475 else => null,
18473 },18476 },
18474 64 => switch (ty.vectorLen(mod)) {18477 64 => switch (ty.vectorLen(zcu)) {
18475 1 => .{ .v_sd, .fmadd213 },18478 1 => .{ .v_sd, .fmadd213 },
18476 2...4 => .{ .v_pd, .fmadd213 },18479 2...4 => .{ .v_pd, .fmadd213 },
18477 else => null,18480 else => null,
...@@ -18484,21 +18487,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -18484,21 +18487,21 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
18484 else => unreachable,18487 else => unreachable,
18485 }18488 }
18486 else if (mem.eql(u2, &order, &.{ 2, 3, 1 }) or mem.eql(u2, &order, &.{ 3, 2, 1 }))18489 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)) {
18488 .Float => switch (ty.floatBits(self.target.*)) {18491 .Float => switch (ty.floatBits(self.target.*)) {
18489 32 => .{ .v_ss, .fmadd231 },18492 32 => .{ .v_ss, .fmadd231 },
18490 64 => .{ .v_sd, .fmadd231 },18493 64 => .{ .v_sd, .fmadd231 },
18491 16, 80, 128 => null,18494 16, 80, 128 => null,
18492 else => unreachable,18495 else => unreachable,
18493 },18496 },
18494 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {18497 .Vector => switch (ty.childType(zcu).zigTypeTag(zcu)) {
18495 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {18498 .Float => switch (ty.childType(zcu).floatBits(self.target.*)) {
18496 32 => switch (ty.vectorLen(mod)) {18499 32 => switch (ty.vectorLen(zcu)) {
18497 1 => .{ .v_ss, .fmadd231 },18500 1 => .{ .v_ss, .fmadd231 },
18498 2...8 => .{ .v_ps, .fmadd231 },18501 2...8 => .{ .v_ps, .fmadd231 },
18499 else => null,18502 else => null,
18500 },18503 },
18501 64 => switch (ty.vectorLen(mod)) {18504 64 => switch (ty.vectorLen(zcu)) {
18502 1 => .{ .v_sd, .fmadd231 },18505 1 => .{ .v_sd, .fmadd231 },
18503 2...4 => .{ .v_pd, .fmadd231 },18506 2...4 => .{ .v_pd, .fmadd231 },
18504 else => null,18507 else => null,
...@@ -18516,7 +18519,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -18516,7 +18519,7 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
18516 var mops: [3]MCValue = undefined;18519 var mops: [3]MCValue = undefined;
18517 for (order, mcvs) |mop_index, mcv| mops[mop_index - 1] = mcv;18520 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));
18520 const mop1_reg = registerAlias(mops[0].getReg().?, abi_size);18523 const mop1_reg = registerAlias(mops[0].getReg().?, abi_size);
18521 const mop2_reg = registerAlias(mops[1].getReg().?, abi_size);18524 const mop2_reg = registerAlias(mops[1].getReg().?, abi_size);
18522 if (mops[2].isRegister()) try self.asmRegisterRegisterRegister(18525 if (mops[2].isRegister()) try self.asmRegisterRegisterRegister(
...@@ -18537,17 +18540,17 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {...@@ -18537,17 +18540,17 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1853718540
18538fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {18541fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
18539 const pt = self.pt;18542 const pt = self.pt;
18540 const mod = pt.zcu;18543 const zcu = pt.zcu;
18541 const va_list_ty = self.air.instructions.items(.data)[@intFromEnum(inst)].ty;18544 const va_list_ty = self.air.instructions.items(.data)[@intFromEnum(inst)].ty;
18542 const ptr_anyopaque_ty = try pt.singleMutPtrType(Type.anyopaque);18545 const ptr_anyopaque_ty = try pt.singleMutPtrType(Type.anyopaque);
1854318546
18544 const result: MCValue = switch (abi.resolveCallingConvention(18547 const result: MCValue = switch (abi.resolveCallingConvention(
18545 self.fn_type.fnCallingConvention(mod),18548 self.fn_type.fnCallingConvention(zcu),
18546 self.target.*,18549 self.target.*,
18547 )) {18550 )) {
18548 .SysV => result: {18551 .SysV => result: {
18549 const info = self.va_info.sysv;18552 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));
18551 var field_off: u31 = 0;18554 var field_off: u31 = 0;
18552 // gp_offset: c_uint,18555 // gp_offset: c_uint,
18553 try self.genSetMem(18556 try self.genSetMem(
...@@ -18557,7 +18560,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {...@@ -18557,7 +18560,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
18557 .{ .immediate = info.gp_count * 8 },18560 .{ .immediate = info.gp_count * 8 },
18558 .{},18561 .{},
18559 );18562 );
18560 field_off += @intCast(Type.c_uint.abiSize(pt));18563 field_off += @intCast(Type.c_uint.abiSize(zcu));
18561 // fp_offset: c_uint,18564 // fp_offset: c_uint,
18562 try self.genSetMem(18565 try self.genSetMem(
18563 .{ .frame = dst_fi },18566 .{ .frame = dst_fi },
...@@ -18566,7 +18569,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {...@@ -18566,7 +18569,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
18566 .{ .immediate = abi.SysV.c_abi_int_param_regs.len * 8 + info.fp_count * 16 },18569 .{ .immediate = abi.SysV.c_abi_int_param_regs.len * 8 + info.fp_count * 16 },
18567 .{},18570 .{},
18568 );18571 );
18569 field_off += @intCast(Type.c_uint.abiSize(pt));18572 field_off += @intCast(Type.c_uint.abiSize(zcu));
18570 // overflow_arg_area: *anyopaque,18573 // overflow_arg_area: *anyopaque,
18571 try self.genSetMem(18574 try self.genSetMem(
18572 .{ .frame = dst_fi },18575 .{ .frame = dst_fi },
...@@ -18575,7 +18578,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {...@@ -18575,7 +18578,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
18575 .{ .lea_frame = info.overflow_arg_area },18578 .{ .lea_frame = info.overflow_arg_area },
18576 .{},18579 .{},
18577 );18580 );
18578 field_off += @intCast(ptr_anyopaque_ty.abiSize(pt));18581 field_off += @intCast(ptr_anyopaque_ty.abiSize(zcu));
18579 // reg_save_area: *anyopaque,18582 // reg_save_area: *anyopaque,
18580 try self.genSetMem(18583 try self.genSetMem(
18581 .{ .frame = dst_fi },18584 .{ .frame = dst_fi },
...@@ -18584,7 +18587,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {...@@ -18584,7 +18587,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
18584 .{ .lea_frame = info.reg_save_area },18587 .{ .lea_frame = info.reg_save_area },
18585 .{},18588 .{},
18586 );18589 );
18587 field_off += @intCast(ptr_anyopaque_ty.abiSize(pt));18590 field_off += @intCast(ptr_anyopaque_ty.abiSize(zcu));
18588 break :result .{ .load_frame = .{ .index = dst_fi } };18591 break :result .{ .load_frame = .{ .index = dst_fi } };
18589 },18592 },
18590 .Win64 => return self.fail("TODO implement c_va_start for Win64", .{}),18593 .Win64 => return self.fail("TODO implement c_va_start for Win64", .{}),
...@@ -18595,7 +18598,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {...@@ -18595,7 +18598,7 @@ fn airVaStart(self: *Self, inst: Air.Inst.Index) !void {
1859518598
18596fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {18599fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
18597 const pt = self.pt;18600 const pt = self.pt;
18598 const mod = pt.zcu;18601 const zcu = pt.zcu;
18599 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;18602 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
18600 const ty = self.typeOfIndex(inst);18603 const ty = self.typeOfIndex(inst);
18601 const promote_ty = self.promoteVarArg(ty);18604 const promote_ty = self.promoteVarArg(ty);
...@@ -18603,7 +18606,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -18603,7 +18606,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
18603 const unused = self.liveness.isUnused(inst);18606 const unused = self.liveness.isUnused(inst);
1860418607
18605 const result: MCValue = switch (abi.resolveCallingConvention(18608 const result: MCValue = switch (abi.resolveCallingConvention(
18606 self.fn_type.fnCallingConvention(mod),18609 self.fn_type.fnCallingConvention(zcu),
18607 self.target.*,18610 self.target.*,
18608 )) {18611 )) {
18609 .SysV => result: {18612 .SysV => result: {
...@@ -18633,7 +18636,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -18633,7 +18636,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
18633 const overflow_arg_area: MCValue = .{ .indirect = .{ .reg = ptr_arg_list_reg, .off = 8 } };18636 const overflow_arg_area: MCValue = .{ .indirect = .{ .reg = ptr_arg_list_reg, .off = 8 } };
18634 const reg_save_area: MCValue = .{ .indirect = .{ .reg = ptr_arg_list_reg, .off = 16 } };18637 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);
18637 switch (classes[0]) {18640 switch (classes[0]) {
18638 .integer => {18641 .integer => {
18639 assert(classes.len == 1);18642 assert(classes.len == 1);
...@@ -18668,7 +18671,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -18668,7 +18671,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
18668 .base = .{ .reg = addr_reg },18671 .base = .{ .reg = addr_reg },
18669 .mod = .{ .rm = .{18672 .mod = .{ .rm = .{
18670 .size = .qword,18673 .size = .qword,
18671 .disp = @intCast(@max(promote_ty.abiSize(pt), 8)),18674 .disp = @intCast(@max(promote_ty.abiSize(zcu), 8)),
18672 } },18675 } },
18673 });18676 });
18674 try self.genCopy(18677 try self.genCopy(
...@@ -18716,7 +18719,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {...@@ -18716,7 +18719,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
18716 .base = .{ .reg = addr_reg },18719 .base = .{ .reg = addr_reg },
18717 .mod = .{ .rm = .{18720 .mod = .{ .rm = .{
18718 .size = .qword,18721 .size = .qword,
18719 .disp = @intCast(@max(promote_ty.abiSize(pt), 8)),18722 .disp = @intCast(@max(promote_ty.abiSize(zcu), 8)),
18720 } },18723 } },
18721 });18724 });
18722 try self.genCopy(18725 try self.genCopy(
...@@ -18806,11 +18809,11 @@ fn airVaEnd(self: *Self, inst: Air.Inst.Index) !void {...@@ -18806,11 +18809,11 @@ fn airVaEnd(self: *Self, inst: Air.Inst.Index) !void {
18806}18809}
1880718810
18808fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {18811fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
18809 const pt = self.pt;18812 const zcu = self.pt.zcu;
18810 const ty = self.typeOf(ref);18813 const ty = self.typeOf(ref);
1881118814
18812 // If the type has no codegen bits, no need to store it.18815 // 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
18815 const mcv = if (ref.toIndex()) |inst| mcv: {18818 const mcv = if (ref.toIndex()) |inst| mcv: {
18816 break :mcv self.inst_tracking.getPtr(inst).?.short;18819 break :mcv self.inst_tracking.getPtr(inst).?.short;
...@@ -18927,8 +18930,8 @@ fn resolveCallingConventionValues(...@@ -18927,8 +18930,8 @@ fn resolveCallingConventionValues(
18927 stack_frame_base: FrameIndex,18930 stack_frame_base: FrameIndex,
18928) !CallMCValues {18931) !CallMCValues {
18929 const pt = self.pt;18932 const pt = self.pt;
18930 const mod = pt.zcu;18933 const zcu = pt.zcu;
18931 const ip = &mod.intern_pool;18934 const ip = &zcu.intern_pool;
18932 const cc = fn_info.cc;18935 const cc = fn_info.cc;
18933 const param_types = try self.gpa.alloc(Type, fn_info.param_types.len + var_args.len);18936 const param_types = try self.gpa.alloc(Type, fn_info.param_types.len + var_args.len);
18934 defer self.gpa.free(param_types);18937 defer self.gpa.free(param_types);
...@@ -18970,15 +18973,15 @@ fn resolveCallingConventionValues(...@@ -18970,15 +18973,15 @@ fn resolveCallingConventionValues(
18970 .SysV => {},18973 .SysV => {},
18971 .Win64 => {18974 .Win64 => {
18972 // Align the stack to 16bytes before allocating shadow stack space (if any).18975 // 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));
18974 },18977 },
18975 else => unreachable,18978 else => unreachable,
18976 }18979 }
1897718980
18978 // Return values18981 // Return values
18979 if (ret_ty.zigTypeTag(mod) == .NoReturn) {18982 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
18980 result.return_value = InstTracking.init(.unreach);18983 result.return_value = InstTracking.init(.unreach);
18981 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {18984 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
18982 // TODO: is this even possible for C calling convention?18985 // TODO: is this even possible for C calling convention?
18983 result.return_value = InstTracking.init(.none);18986 result.return_value = InstTracking.init(.none);
18984 } else {18987 } else {
...@@ -18986,15 +18989,15 @@ fn resolveCallingConventionValues(...@@ -18986,15 +18989,15 @@ fn resolveCallingConventionValues(
18986 var ret_tracking_i: usize = 0;18989 var ret_tracking_i: usize = 0;
1898718990
18988 const classes = switch (resolved_cc) {18991 const classes = switch (resolved_cc) {
18989 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, pt, self.target.*, .ret), .none),18992 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, zcu, self.target.*, .ret), .none),
18990 .Win64 => &.{abi.classifyWindows(ret_ty, pt)},18993 .Win64 => &.{abi.classifyWindows(ret_ty, zcu)},
18991 else => unreachable,18994 else => unreachable,
18992 };18995 };
18993 for (classes) |class| switch (class) {18996 for (classes) |class| switch (class) {
18994 .integer => {18997 .integer => {
18995 const ret_int_reg = registerAlias(18998 const ret_int_reg = registerAlias(
18996 abi.getCAbiIntReturnRegs(resolved_cc)[ret_int_reg_i],18999 abi.getCAbiIntReturnRegs(resolved_cc)[ret_int_reg_i],
18997 @intCast(@min(ret_ty.abiSize(pt), 8)),19000 @intCast(@min(ret_ty.abiSize(zcu), 8)),
18998 );19001 );
18999 ret_int_reg_i += 1;19002 ret_int_reg_i += 1;
1900019003
...@@ -19004,7 +19007,7 @@ fn resolveCallingConventionValues(...@@ -19004,7 +19007,7 @@ fn resolveCallingConventionValues(
19004 .sse, .float, .float_combine, .win_i128 => {19007 .sse, .float, .float_combine, .win_i128 => {
19005 const ret_sse_reg = registerAlias(19008 const ret_sse_reg = registerAlias(
19006 abi.getCAbiSseReturnRegs(resolved_cc)[ret_sse_reg_i],19009 abi.getCAbiSseReturnRegs(resolved_cc)[ret_sse_reg_i],
19007 @intCast(ret_ty.abiSize(pt)),19010 @intCast(ret_ty.abiSize(zcu)),
19008 );19011 );
19009 ret_sse_reg_i += 1;19012 ret_sse_reg_i += 1;
1901019013
...@@ -19047,7 +19050,7 @@ fn resolveCallingConventionValues(...@@ -19047,7 +19050,7 @@ fn resolveCallingConventionValues(
1904719050
19048 // Input params19051 // Input params
19049 for (param_types, result.args) |ty, *arg| {19052 for (param_types, result.args) |ty, *arg| {
19050 assert(ty.hasRuntimeBitsIgnoreComptime(pt));19053 assert(ty.hasRuntimeBitsIgnoreComptime(zcu));
19051 switch (resolved_cc) {19054 switch (resolved_cc) {
19052 .SysV => {},19055 .SysV => {},
19053 .Win64 => {19056 .Win64 => {
...@@ -19061,8 +19064,8 @@ fn resolveCallingConventionValues(...@@ -19061,8 +19064,8 @@ fn resolveCallingConventionValues(
19061 var arg_mcv_i: usize = 0;19064 var arg_mcv_i: usize = 0;
1906219065
19063 const classes = switch (resolved_cc) {19066 const classes = switch (resolved_cc) {
19064 .SysV => mem.sliceTo(&abi.classifySystemV(ty, pt, self.target.*, .arg), .none),19067 .SysV => mem.sliceTo(&abi.classifySystemV(ty, zcu, self.target.*, .arg), .none),
19065 .Win64 => &.{abi.classifyWindows(ty, pt)},19068 .Win64 => &.{abi.classifyWindows(ty, zcu)},
19066 else => unreachable,19069 else => unreachable,
19067 };19070 };
19068 for (classes) |class| switch (class) {19071 for (classes) |class| switch (class) {
...@@ -19072,7 +19075,7 @@ fn resolveCallingConventionValues(...@@ -19072,7 +19075,7 @@ fn resolveCallingConventionValues(
1907219075
19073 const param_int_reg = registerAlias(19076 const param_int_reg = registerAlias(
19074 abi.getCAbiIntParamRegs(resolved_cc)[param_int_reg_i],19077 abi.getCAbiIntParamRegs(resolved_cc)[param_int_reg_i],
19075 @intCast(@min(ty.abiSize(pt), 8)),19078 @intCast(@min(ty.abiSize(zcu), 8)),
19076 );19079 );
19077 param_int_reg_i += 1;19080 param_int_reg_i += 1;
1907819081
...@@ -19085,7 +19088,7 @@ fn resolveCallingConventionValues(...@@ -19085,7 +19088,7 @@ fn resolveCallingConventionValues(
1908519088
19086 const param_sse_reg = registerAlias(19089 const param_sse_reg = registerAlias(
19087 abi.getCAbiSseParamRegs(resolved_cc)[param_sse_reg_i],19090 abi.getCAbiSseParamRegs(resolved_cc)[param_sse_reg_i],
19088 @intCast(ty.abiSize(pt)),19091 @intCast(ty.abiSize(zcu)),
19089 );19092 );
19090 param_sse_reg_i += 1;19093 param_sse_reg_i += 1;
1909119094
...@@ -19098,7 +19101,7 @@ fn resolveCallingConventionValues(...@@ -19098,7 +19101,7 @@ fn resolveCallingConventionValues(
19098 .x87, .x87up, .complex_x87, .memory => break,19101 .x87, .x87up, .complex_x87, .memory => break,
19099 else => unreachable,19102 else => unreachable,
19100 },19103 },
19101 .Win64 => if (ty.abiSize(pt) > 8) {19104 .Win64 => if (ty.abiSize(zcu) > 8) {
19102 const param_int_reg =19105 const param_int_reg =
19103 abi.getCAbiIntParamRegs(resolved_cc)[param_int_reg_i].to64();19106 abi.getCAbiIntParamRegs(resolved_cc)[param_int_reg_i].to64();
19104 param_int_reg_i += 1;19107 param_int_reg_i += 1;
...@@ -19117,10 +19120,10 @@ fn resolveCallingConventionValues(...@@ -19117,10 +19120,10 @@ fn resolveCallingConventionValues(
19117 param_int_reg_i = param_int_regs_len;19120 param_int_reg_i = param_int_regs_len;
1911819121
19119 const frame_elem_align = 8;19122 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;
19121 const frame_elem_size = mem.alignForward(19124 const frame_elem_size = mem.alignForward(
19122 u64,19125 u64,
19123 ty.childType(mod).abiSize(pt),19126 ty.childType(zcu).abiSize(zcu),
19124 frame_elem_align,19127 frame_elem_align,
19125 );19128 );
19126 const frame_size: u31 = @intCast(frame_elems_len * frame_elem_size);19129 const frame_size: u31 = @intCast(frame_elems_len * frame_elem_size);
...@@ -19144,9 +19147,9 @@ fn resolveCallingConventionValues(...@@ -19144,9 +19147,9 @@ fn resolveCallingConventionValues(
19144 continue;19147 continue;
19145 }19148 }
1914619149
19147 const param_size: u31 = @intCast(ty.abiSize(pt));19150 const param_size: u31 = @intCast(ty.abiSize(zcu));
19148 const param_align: u31 =19151 const param_align: u31 =
19149 @intCast(@max(ty.abiAlignment(pt).toByteUnits().?, 8));19152 @intCast(@max(ty.abiAlignment(zcu).toByteUnits().?, 8));
19150 result.stack_byte_count =19153 result.stack_byte_count =
19151 mem.alignForward(u31, result.stack_byte_count, param_align);19154 mem.alignForward(u31, result.stack_byte_count, param_align);
19152 arg.* = .{ .load_frame = .{19155 arg.* = .{ .load_frame = .{
...@@ -19164,13 +19167,13 @@ fn resolveCallingConventionValues(...@@ -19164,13 +19167,13 @@ fn resolveCallingConventionValues(
19164 result.stack_align = .@"16";19167 result.stack_align = .@"16";
1916519168
19166 // Return values19169 // Return values
19167 if (ret_ty.zigTypeTag(mod) == .NoReturn) {19170 if (ret_ty.zigTypeTag(zcu) == .NoReturn) {
19168 result.return_value = InstTracking.init(.unreach);19171 result.return_value = InstTracking.init(.unreach);
19169 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {19172 } else if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
19170 result.return_value = InstTracking.init(.none);19173 result.return_value = InstTracking.init(.none);
19171 } else {19174 } else {
19172 const ret_reg = abi.getCAbiIntReturnRegs(resolved_cc)[0];19175 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));
19174 if (ret_ty_size <= 8 and !ret_ty.isRuntimeFloat()) {19177 if (ret_ty_size <= 8 and !ret_ty.isRuntimeFloat()) {
19175 const aliased_reg = registerAlias(ret_reg, ret_ty_size);19178 const aliased_reg = registerAlias(ret_reg, ret_ty_size);
19176 result.return_value = .{ .short = .{ .register = aliased_reg }, .long = .none };19179 result.return_value = .{ .short = .{ .register = aliased_reg }, .long = .none };
...@@ -19185,12 +19188,12 @@ fn resolveCallingConventionValues(...@@ -19185,12 +19188,12 @@ fn resolveCallingConventionValues(
1918519188
19186 // Input params19189 // Input params
19187 for (param_types, result.args) |ty, *arg| {19190 for (param_types, result.args) |ty, *arg| {
19188 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {19191 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
19189 arg.* = .none;19192 arg.* = .none;
19190 continue;19193 continue;
19191 }19194 }
19192 const param_size: u31 = @intCast(ty.abiSize(pt));19195 const param_size: u31 = @intCast(ty.abiSize(zcu));
19193 const param_align: u31 = @intCast(ty.abiAlignment(pt).toByteUnits().?);19196 const param_align: u31 = @intCast(ty.abiAlignment(zcu).toByteUnits().?);
19194 result.stack_byte_count =19197 result.stack_byte_count =
19195 mem.alignForward(u31, result.stack_byte_count, param_align);19198 mem.alignForward(u31, result.stack_byte_count, param_align);
19196 arg.* = .{ .load_frame = .{19199 arg.* = .{ .load_frame = .{
...@@ -19276,25 +19279,26 @@ fn registerAlias(reg: Register, size_bytes: u32) Register {...@@ -19276,25 +19279,26 @@ fn registerAlias(reg: Register, size_bytes: u32) Register {
1927619279
19277fn memSize(self: *Self, ty: Type) Memory.Size {19280fn memSize(self: *Self, ty: Type) Memory.Size {
19278 const pt = self.pt;19281 const pt = self.pt;
19279 const mod = pt.zcu;19282 const zcu = pt.zcu;
19280 return switch (ty.zigTypeTag(mod)) {19283 return switch (ty.zigTypeTag(zcu)) {
19281 .Float => Memory.Size.fromBitSize(ty.floatBits(self.target.*)),19284 .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))),
19283 };19286 };
19284}19287}
1928519288
19286fn splitType(self: *Self, ty: Type) ![2]Type {19289fn splitType(self: *Self, ty: Type) ![2]Type {
19287 const pt = self.pt;19290 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);
19289 var parts: [2]Type = undefined;19293 var parts: [2]Type = undefined;
19290 if (classes.len == 2) for (&parts, classes, 0..) |*part, class, part_i| {19294 if (classes.len == 2) for (&parts, classes, 0..) |*part, class, part_i| {
19291 part.* = switch (class) {19295 part.* = switch (class) {
19292 .integer => switch (part_i) {19296 .integer => switch (part_i) {
19293 0 => Type.u64,19297 0 => Type.u64,
19294 1 => part: {19298 1 => part: {
19295 const elem_size = ty.abiAlignment(pt).minStrict(.@"8").toByteUnits().?;19299 const elem_size = ty.abiAlignment(zcu).minStrict(.@"8").toByteUnits().?;
19296 const elem_ty = try pt.intType(.unsigned, @intCast(elem_size * 8));19300 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)) {
19298 1 => elem_ty,19302 1 => elem_ty,
19299 else => |len| try pt.arrayType(.{ .len = len, .child = elem_ty.toIntern() }),19303 else => |len| try pt.arrayType(.{ .len = len, .child = elem_ty.toIntern() }),
19300 };19304 };
...@@ -19306,7 +19310,7 @@ fn splitType(self: *Self, ty: Type) ![2]Type {...@@ -19306,7 +19310,7 @@ fn splitType(self: *Self, ty: Type) ![2]Type {
19306 .sse => Type.f64,19310 .sse => Type.f64,
19307 else => break,19311 else => break,
19308 };19312 };
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;
19310 return self.fail("TODO implement splitType for {}", .{ty.fmt(pt)});19314 return self.fail("TODO implement splitType for {}", .{ty.fmt(pt)});
19311}19315}
1931219316
...@@ -19314,10 +19318,10 @@ fn splitType(self: *Self, ty: Type) ![2]Type {...@@ -19314,10 +19318,10 @@ fn splitType(self: *Self, ty: Type) ![2]Type {
19314/// Clobbers any remaining bits.19318/// Clobbers any remaining bits.
19315fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {19319fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
19316 const pt = self.pt;19320 const pt = self.pt;
19317 const mod = pt.zcu;19321 const zcu = pt.zcu;
19318 const int_info = if (ty.isAbiInt(mod)) ty.intInfo(mod) else std.builtin.Type.Int{19322 const int_info = if (ty.isAbiInt(zcu)) ty.intInfo(zcu) else std.builtin.Type.Int{
19319 .signedness = .unsigned,19323 .signedness = .unsigned,
19320 .bits = @intCast(ty.bitSize(pt)),19324 .bits = @intCast(ty.bitSize(zcu)),
19321 };19325 };
19322 const shift = math.cast(u6, 64 - int_info.bits % 64) orelse return;19326 const shift = math.cast(u6, 64 - int_info.bits % 64) orelse return;
19323 try self.spillEflagsIfOccupied();19327 try self.spillEflagsIfOccupied();
...@@ -19362,9 +19366,9 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {...@@ -19362,9 +19366,9 @@ fn truncateRegister(self: *Self, ty: Type, reg: Register) !void {
1936219366
19363fn regBitSize(self: *Self, ty: Type) u64 {19367fn regBitSize(self: *Self, ty: Type) u64 {
19364 const pt = self.pt;19368 const pt = self.pt;
19365 const mod = pt.zcu;19369 const zcu = pt.zcu;
19366 const abi_size = ty.abiSize(pt);19370 const abi_size = ty.abiSize(zcu);
19367 return switch (ty.zigTypeTag(mod)) {19371 return switch (ty.zigTypeTag(zcu)) {
19368 else => switch (abi_size) {19372 else => switch (abi_size) {
19369 1 => 8,19373 1 => 8,
19370 2 => 16,19374 2 => 16,
...@@ -19381,7 +19385,7 @@ fn regBitSize(self: *Self, ty: Type) u64 {...@@ -19381,7 +19385,7 @@ fn regBitSize(self: *Self, ty: Type) u64 {
19381}19385}
1938219386
19383fn regExtraBits(self: *Self, ty: Type) u64 {19387fn 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);
19385}19389}
1938619390
19387fn hasFeature(self: *Self, feature: Target.x86.Feature) bool {19391fn hasFeature(self: *Self, feature: Target.x86.Feature) bool {
...@@ -19396,14 +19400,14 @@ fn hasAllFeatures(self: *Self, features: anytype) bool {...@@ -19396,14 +19400,14 @@ fn hasAllFeatures(self: *Self, features: anytype) bool {
1939619400
19397fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {19401fn typeOf(self: *Self, inst: Air.Inst.Ref) Type {
19398 const pt = self.pt;19402 const pt = self.pt;
19399 const mod = pt.zcu;19403 const zcu = pt.zcu;
19400 return self.air.typeOf(inst, &mod.intern_pool);19404 return self.air.typeOf(inst, &zcu.intern_pool);
19401}19405}
1940219406
19403fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {19407fn typeOfIndex(self: *Self, inst: Air.Inst.Index) Type {
19404 const pt = self.pt;19408 const pt = self.pt;
19405 const mod = pt.zcu;19409 const zcu = pt.zcu;
19406 return self.air.typeOfIndex(inst, &mod.intern_pool);19410 return self.air.typeOfIndex(inst, &zcu.intern_pool);
19407}19411}
1940819412
19409fn intCompilerRtAbiName(int_bits: u32) u8 {19413fn intCompilerRtAbiName(int_bits: u32) u8 {
...@@ -19455,17 +19459,17 @@ fn floatLibcAbiSuffix(ty: Type) []const u8 {...@@ -19455,17 +19459,17 @@ fn floatLibcAbiSuffix(ty: Type) []const u8 {
1945519459
19456fn promoteInt(self: *Self, ty: Type) Type {19460fn promoteInt(self: *Self, ty: Type) Type {
19457 const pt = self.pt;19461 const pt = self.pt;
19458 const mod = pt.zcu;19462 const zcu = pt.zcu;
19459 const int_info: InternPool.Key.IntType = switch (ty.toIntern()) {19463 const int_info: InternPool.Key.IntType = switch (ty.toIntern()) {
19460 .bool_type => .{ .signedness = .unsigned, .bits = 1 },19464 .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,
19462 };19466 };
19463 for ([_]Type{19467 for ([_]Type{
19464 Type.c_int, Type.c_uint,19468 Type.c_int, Type.c_uint,
19465 Type.c_long, Type.c_ulong,19469 Type.c_long, Type.c_ulong,
19466 Type.c_longlong, Type.c_ulonglong,19470 Type.c_longlong, Type.c_ulonglong,
19467 }) |promote_ty| {19471 }) |promote_ty| {
19468 const promote_info = promote_ty.intInfo(mod);19472 const promote_info = promote_ty.intInfo(zcu);
19469 if (int_info.signedness == .signed and promote_info.signedness == .unsigned) continue;19473 if (int_info.signedness == .signed and promote_info.signedness == .unsigned) continue;
19470 if (int_info.bits + @intFromBool(int_info.signedness == .unsigned and19474 if (int_info.bits + @intFromBool(int_info.signedness == .unsigned and
19471 promote_info.signedness == .signed) <= promote_info.bits) return promote_ty;19475 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 {...@@ -357,7 +357,7 @@ pub fn emitMir(emit: *Emit) Error!void {
357 } } };357 } } };
358 },358 },
359 };359 };
360 const ip = &emit.lower.bin_file.comp.module.?.intern_pool;360 const ip = &emit.lower.bin_file.comp.zcu.?.intern_pool;
361 const air_inst = emit.air.instructions.get(@intFromEnum(air_inst_index));361 const air_inst = emit.air.instructions.get(@intFromEnum(air_inst_index));
362 const name: Air.NullTerminatedString = switch (air_inst.tag) {362 const name: Air.NullTerminatedString = switch (air_inst.tag) {
363 else => unreachable,363 else => unreachable,
src/arch/x86_64/abi.zig+35-35
...@@ -44,7 +44,7 @@ pub const Class = enum {...@@ -44,7 +44,7 @@ pub const Class = enum {
44 }44 }
45};45};
4646
47pub fn classifyWindows(ty: Type, pt: Zcu.PerThread) Class {47pub fn classifyWindows(ty: Type, zcu: *Zcu) Class {
48 // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-201748 // https://docs.microsoft.com/en-gb/cpp/build/x64-calling-convention?view=vs-2017
49 // "There's a strict one-to-one correspondence between a function call's arguments49 // "There's a strict one-to-one correspondence between a function call's arguments
50 // and the registers used for those arguments. Any argument that doesn't fit in 850 // 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 {...@@ -53,7 +53,7 @@ pub fn classifyWindows(ty: Type, pt: Zcu.PerThread) Class {
53 // "All floating point operations are done using the 16 XMM registers."53 // "All floating point operations are done using the 16 XMM registers."
54 // "Structs and unions of size 8, 16, 32, or 64 bits, and __m64 types, are passed54 // "Structs and unions of size 8, 16, 32, or 64 bits, and __m64 types, are passed
55 // as if they were integers of the same size."55 // as if they were integers of the same size."
56 switch (ty.zigTypeTag(pt.zcu)) {56 switch (ty.zigTypeTag(zcu)) {
57 .Pointer,57 .Pointer,
58 .Int,58 .Int,
59 .Bool,59 .Bool,
...@@ -68,12 +68,12 @@ pub fn classifyWindows(ty: Type, pt: Zcu.PerThread) Class {...@@ -68,12 +68,12 @@ pub fn classifyWindows(ty: Type, pt: Zcu.PerThread) Class {
68 .ErrorUnion,68 .ErrorUnion,
69 .AnyFrame,69 .AnyFrame,
70 .Frame,70 .Frame,
71 => switch (ty.abiSize(pt)) {71 => switch (ty.abiSize(zcu)) {
72 0 => unreachable,72 0 => unreachable,
73 1, 2, 4, 8 => return .integer,73 1, 2, 4, 8 => return .integer,
74 else => switch (ty.zigTypeTag(pt.zcu)) {74 else => switch (ty.zigTypeTag(zcu)) {
75 .Int => return .win_i128,75 .Int => return .win_i128,
76 .Struct, .Union => if (ty.containerLayout(pt.zcu) == .@"packed") {76 .Struct, .Union => if (ty.containerLayout(zcu) == .@"packed") {
77 return .win_i128;77 return .win_i128;
78 } else {78 } else {
79 return .memory;79 return .memory;
...@@ -100,14 +100,14 @@ pub const Context = enum { ret, arg, field, other };...@@ -100,14 +100,14 @@ pub const Context = enum { ret, arg, field, other };
100100
101/// There are a maximum of 8 possible return slots. Returned values are in101/// There are a maximum of 8 possible return slots. Returned values are in
102/// the beginning of the array; unused slots are filled with .none.102/// 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 {
104 const memory_class = [_]Class{104 const memory_class = [_]Class{
105 .memory, .none, .none, .none,105 .memory, .none, .none, .none,
106 .none, .none, .none, .none,106 .none, .none, .none, .none,
107 };107 };
108 var result = [1]Class{.none} ** 8;108 var result = [1]Class{.none} ** 8;
109 switch (ty.zigTypeTag(pt.zcu)) {109 switch (ty.zigTypeTag(zcu)) {
110 .Pointer => switch (ty.ptrSize(pt.zcu)) {110 .Pointer => switch (ty.ptrSize(zcu)) {
111 .Slice => {111 .Slice => {
112 result[0] = .integer;112 result[0] = .integer;
113 result[1] = .integer;113 result[1] = .integer;
...@@ -119,7 +119,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con...@@ -119,7 +119,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
119 },119 },
120 },120 },
121 .Int, .Enum, .ErrorSet => {121 .Int, .Enum, .ErrorSet => {
122 const bits = ty.intInfo(pt.zcu).bits;122 const bits = ty.intInfo(zcu).bits;
123 if (bits <= 64) {123 if (bits <= 64) {
124 result[0] = .integer;124 result[0] = .integer;
125 return result;125 return result;
...@@ -185,8 +185,8 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con...@@ -185,8 +185,8 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
185 else => unreachable,185 else => unreachable,
186 },186 },
187 .Vector => {187 .Vector => {
188 const elem_ty = ty.childType(pt.zcu);188 const elem_ty = ty.childType(zcu);
189 const bits = elem_ty.bitSize(pt) * ty.arrayLen(pt.zcu);189 const bits = elem_ty.bitSize(zcu) * ty.arrayLen(zcu);
190 if (elem_ty.toIntern() == .bool_type) {190 if (elem_ty.toIntern() == .bool_type) {
191 if (bits <= 32) return .{191 if (bits <= 32) return .{
192 .integer, .none, .none, .none,192 .integer, .none, .none, .none,
...@@ -250,7 +250,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con...@@ -250,7 +250,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
250 return memory_class;250 return memory_class;
251 },251 },
252 .Optional => {252 .Optional => {
253 if (ty.isPtrLikeOptional(pt.zcu)) {253 if (ty.isPtrLikeOptional(zcu)) {
254 result[0] = .integer;254 result[0] = .integer;
255 return result;255 return result;
256 }256 }
...@@ -261,8 +261,8 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con...@@ -261,8 +261,8 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
261 // it contains unaligned fields, it has class MEMORY"261 // it contains unaligned fields, it has class MEMORY"
262 // "If the size of the aggregate exceeds a single eightbyte, each is classified262 // "If the size of the aggregate exceeds a single eightbyte, each is classified
263 // separately.".263 // separately.".
264 const ty_size = ty.abiSize(pt);264 const ty_size = ty.abiSize(zcu);
265 switch (ty.containerLayout(pt.zcu)) {265 switch (ty.containerLayout(zcu)) {
266 .auto, .@"extern" => {},266 .auto, .@"extern" => {},
267 .@"packed" => {267 .@"packed" => {
268 assert(ty_size <= 16);268 assert(ty_size <= 16);
...@@ -274,10 +274,10 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con...@@ -274,10 +274,10 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
274 if (ty_size > 64)274 if (ty_size > 64)
275 return memory_class;275 return memory_class;
276276
277 _ = if (pt.zcu.typeToStruct(ty)) |loaded_struct|277 _ = if (zcu.typeToStruct(ty)) |loaded_struct|
278 classifySystemVStruct(&result, 0, loaded_struct, pt, target)278 classifySystemVStruct(&result, 0, loaded_struct, zcu, target)
279 else if (pt.zcu.typeToUnion(ty)) |loaded_union|279 else if (zcu.typeToUnion(ty)) |loaded_union|
280 classifySystemVUnion(&result, 0, loaded_union, pt, target)280 classifySystemVUnion(&result, 0, loaded_union, zcu, target)
281 else281 else
282 unreachable;282 unreachable;
283283
...@@ -306,7 +306,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con...@@ -306,7 +306,7 @@ pub fn classifySystemV(ty: Type, pt: Zcu.PerThread, target: std.Target, ctx: Con
306 return result;306 return result;
307 },307 },
308 .Array => {308 .Array => {
309 const ty_size = ty.abiSize(pt);309 const ty_size = ty.abiSize(zcu);
310 if (ty_size <= 8) {310 if (ty_size <= 8) {
311 result[0] = .integer;311 result[0] = .integer;
312 return result;312 return result;
...@@ -326,10 +326,10 @@ fn classifySystemVStruct(...@@ -326,10 +326,10 @@ fn classifySystemVStruct(
326 result: *[8]Class,326 result: *[8]Class,
327 starting_byte_offset: u64,327 starting_byte_offset: u64,
328 loaded_struct: InternPool.LoadedStructType,328 loaded_struct: InternPool.LoadedStructType,
329 pt: Zcu.PerThread,329 zcu: *Zcu,
330 target: std.Target,330 target: std.Target,
331) u64 {331) u64 {
332 const ip = &pt.zcu.intern_pool;332 const ip = &zcu.intern_pool;
333 var byte_offset = starting_byte_offset;333 var byte_offset = starting_byte_offset;
334 var field_it = loaded_struct.iterateRuntimeOrder(ip);334 var field_it = loaded_struct.iterateRuntimeOrder(ip);
335 while (field_it.next()) |field_index| {335 while (field_it.next()) |field_index| {
...@@ -338,29 +338,29 @@ fn classifySystemVStruct(...@@ -338,29 +338,29 @@ fn classifySystemVStruct(
338 byte_offset = std.mem.alignForward(338 byte_offset = std.mem.alignForward(
339 u64,339 u64,
340 byte_offset,340 byte_offset,
341 field_align.toByteUnits() orelse field_ty.abiAlignment(pt).toByteUnits().?,341 field_align.toByteUnits() orelse field_ty.abiAlignment(zcu).toByteUnits().?,
342 );342 );
343 if (pt.zcu.typeToStruct(field_ty)) |field_loaded_struct| {343 if (zcu.typeToStruct(field_ty)) |field_loaded_struct| {
344 switch (field_loaded_struct.layout) {344 switch (field_loaded_struct.layout) {
345 .auto, .@"extern" => {345 .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);
347 continue;347 continue;
348 },348 },
349 .@"packed" => {},349 .@"packed" => {},
350 }350 }
351 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {351 } else if (zcu.typeToUnion(field_ty)) |field_loaded_union| {
352 switch (field_loaded_union.flagsUnordered(ip).layout) {352 switch (field_loaded_union.flagsUnordered(ip).layout) {
353 .auto, .@"extern" => {353 .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);
355 continue;355 continue;
356 },356 },
357 .@"packed" => {},357 .@"packed" => {},
358 }358 }
359 }359 }
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);
361 for (result[@intCast(byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|361 for (result[@intCast(byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
362 result_class.* = result_class.combineSystemV(field_class);362 result_class.* = result_class.combineSystemV(field_class);
363 byte_offset += field_ty.abiSize(pt);363 byte_offset += field_ty.abiSize(zcu);
364 }364 }
365 const final_byte_offset = starting_byte_offset + loaded_struct.sizeUnordered(ip);365 const final_byte_offset = starting_byte_offset + loaded_struct.sizeUnordered(ip);
366 std.debug.assert(final_byte_offset == std.mem.alignForward(366 std.debug.assert(final_byte_offset == std.mem.alignForward(
...@@ -375,30 +375,30 @@ fn classifySystemVUnion(...@@ -375,30 +375,30 @@ fn classifySystemVUnion(
375 result: *[8]Class,375 result: *[8]Class,
376 starting_byte_offset: u64,376 starting_byte_offset: u64,
377 loaded_union: InternPool.LoadedUnionType,377 loaded_union: InternPool.LoadedUnionType,
378 pt: Zcu.PerThread,378 zcu: *Zcu,
379 target: std.Target,379 target: std.Target,
380) u64 {380) u64 {
381 const ip = &pt.zcu.intern_pool;381 const ip = &zcu.intern_pool;
382 for (0..loaded_union.field_types.len) |field_index| {382 for (0..loaded_union.field_types.len) |field_index| {
383 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);383 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| {
385 switch (field_loaded_struct.layout) {385 switch (field_loaded_struct.layout) {
386 .auto, .@"extern" => {386 .auto, .@"extern" => {
387 _ = classifySystemVStruct(result, starting_byte_offset, field_loaded_struct, pt, target);387 _ = classifySystemVStruct(result, starting_byte_offset, field_loaded_struct, zcu, target);
388 continue;388 continue;
389 },389 },
390 .@"packed" => {},390 .@"packed" => {},
391 }391 }
392 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {392 } else if (zcu.typeToUnion(field_ty)) |field_loaded_union| {
393 switch (field_loaded_union.flagsUnordered(ip).layout) {393 switch (field_loaded_union.flagsUnordered(ip).layout) {
394 .auto, .@"extern" => {394 .auto, .@"extern" => {
395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, pt, target);395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, zcu, target);
396 continue;396 continue;
397 },397 },
398 .@"packed" => {},398 .@"packed" => {},
399 }399 }
400 }400 }
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);
402 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|402 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
403 result_class.* = result_class.combineSystemV(field_class);403 result_class.* = result_class.combineSystemV(field_class);
404 }404 }
src/codegen.zig+66-65
...@@ -198,17 +198,17 @@ pub fn generateSymbol(...@@ -198,17 +198,17 @@ pub fn generateSymbol(
198 const tracy = trace(@src());198 const tracy = trace(@src());
199 defer tracy.end();199 defer tracy.end();
200200
201 const mod = pt.zcu;201 const zcu = pt.zcu;
202 const ip = &mod.intern_pool;202 const ip = &zcu.intern_pool;
203 const ty = val.typeOf(mod);203 const ty = val.typeOf(zcu);
204204
205 const target = mod.getTarget();205 const target = zcu.getTarget();
206 const endian = target.cpu.arch.endian();206 const endian = target.cpu.arch.endian();
207207
208 log.debug("generateSymbol: val = {}", .{val.fmtValue(pt)});208 log.debug("generateSymbol: val = {}", .{val.fmtValue(pt)});
209209
210 if (val.isUndefDeep(mod)) {210 if (val.isUndefDeep(zcu)) {
211 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;211 const abi_size = math.cast(usize, ty.abiSize(zcu)) orelse return error.Overflow;
212 try code.appendNTimes(0xaa, abi_size);212 try code.appendNTimes(0xaa, abi_size);
213 return .ok;213 return .ok;
214 }214 }
...@@ -254,9 +254,9 @@ pub fn generateSymbol(...@@ -254,9 +254,9 @@ pub fn generateSymbol(
254 .empty_enum_value,254 .empty_enum_value,
255 => unreachable, // non-runtime values255 => unreachable, // non-runtime values
256 .int => {256 .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;
258 var space: Value.BigIntSpace = undefined;258 var space: Value.BigIntSpace = undefined;
259 const int_val = val.toBigInt(&space, pt);259 const int_val = val.toBigInt(&space, zcu);
260 int_val.writeTwosComplement(try code.addManyAsSlice(abi_size), endian);260 int_val.writeTwosComplement(try code.addManyAsSlice(abi_size), endian);
261 },261 },
262 .err => |err| {262 .err => |err| {
...@@ -264,20 +264,20 @@ pub fn generateSymbol(...@@ -264,20 +264,20 @@ pub fn generateSymbol(
264 try code.writer().writeInt(u16, @intCast(int), endian);264 try code.writer().writeInt(u16, @intCast(int), endian);
265 },265 },
266 .error_union => |error_union| {266 .error_union => |error_union| {
267 const payload_ty = ty.errorUnionPayload(mod);267 const payload_ty = ty.errorUnionPayload(zcu);
268 const err_val: u16 = switch (error_union.val) {268 const err_val: u16 = switch (error_union.val) {
269 .err_name => |err_name| @intCast(try pt.getErrorValue(err_name)),269 .err_name => |err_name| @intCast(try pt.getErrorValue(err_name)),
270 .payload => 0,270 .payload => 0,
271 };271 };
272272
273 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {273 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
274 try code.writer().writeInt(u16, err_val, endian);274 try code.writer().writeInt(u16, err_val, endian);
275 return .ok;275 return .ok;
276 }276 }
277277
278 const payload_align = payload_ty.abiAlignment(pt);278 const payload_align = payload_ty.abiAlignment(zcu);
279 const error_align = Type.anyerror.abiAlignment(pt);279 const error_align = Type.anyerror.abiAlignment(zcu);
280 const abi_align = ty.abiAlignment(pt);280 const abi_align = ty.abiAlignment(zcu);
281281
282 // error value first when its type is larger than the error union's payload282 // error value first when its type is larger than the error union's payload
283 if (error_align.order(payload_align) == .gt) {283 if (error_align.order(payload_align) == .gt) {
...@@ -317,7 +317,7 @@ pub fn generateSymbol(...@@ -317,7 +317,7 @@ pub fn generateSymbol(
317 }317 }
318 },318 },
319 .enum_tag => |enum_tag| {319 .enum_tag => |enum_tag| {
320 const int_tag_ty = ty.intTagType(mod);320 const int_tag_ty = ty.intTagType(zcu);
321 switch (try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, debug_output, reloc_info)) {321 switch (try generateSymbol(bin_file, pt, src_loc, try pt.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty), code, debug_output, reloc_info)) {
322 .ok => {},322 .ok => {},
323 .fail => |em| return .{ .fail = em },323 .fail => |em| return .{ .fail = em },
...@@ -329,7 +329,7 @@ pub fn generateSymbol(...@@ -329,7 +329,7 @@ pub fn generateSymbol(
329 .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(8)),329 .f64 => |f64_val| writeFloat(f64, f64_val, target, endian, try code.addManyAsArray(8)),
330 .f80 => |f80_val| {330 .f80 => |f80_val| {
331 writeFloat(f80, f80_val, target, endian, try code.addManyAsArray(10));331 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;
333 try code.appendNTimes(0, abi_size - 10);333 try code.appendNTimes(0, abi_size - 10);
334 },334 },
335 .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)),335 .f128 => |f128_val| writeFloat(f128, f128_val, target, endian, try code.addManyAsArray(16)),
...@@ -349,11 +349,11 @@ pub fn generateSymbol(...@@ -349,11 +349,11 @@ pub fn generateSymbol(
349 }349 }
350 },350 },
351 .opt => {351 .opt => {
352 const payload_type = ty.optionalChild(mod);352 const payload_type = ty.optionalChild(zcu);
353 const payload_val = val.optionalValue(mod);353 const payload_val = val.optionalValue(zcu);
354 const abi_size = math.cast(usize, ty.abiSize(pt)) orelse return error.Overflow;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)) {
357 if (payload_val) |value| {357 if (payload_val) |value| {
358 switch (try generateSymbol(bin_file, pt, src_loc, value, code, debug_output, reloc_info)) {358 switch (try generateSymbol(bin_file, pt, src_loc, value, code, debug_output, reloc_info)) {
359 .ok => {},359 .ok => {},
...@@ -363,8 +363,8 @@ pub fn generateSymbol(...@@ -363,8 +363,8 @@ pub fn generateSymbol(
363 try code.appendNTimes(0, abi_size);363 try code.appendNTimes(0, abi_size);
364 }364 }
365 } else {365 } else {
366 const padding = abi_size - (math.cast(usize, payload_type.abiSize(pt)) orelse return error.Overflow) - 1;366 const padding = abi_size - (math.cast(usize, payload_type.abiSize(zcu)) orelse return error.Overflow) - 1;
367 if (payload_type.hasRuntimeBits(pt)) {367 if (payload_type.hasRuntimeBits(zcu)) {
368 const value = payload_val orelse Value.fromInterned(try pt.intern(.{368 const value = payload_val orelse Value.fromInterned(try pt.intern(.{
369 .undef = payload_type.toIntern(),369 .undef = payload_type.toIntern(),
370 }));370 }));
...@@ -398,7 +398,7 @@ pub fn generateSymbol(...@@ -398,7 +398,7 @@ pub fn generateSymbol(
398 },398 },
399 },399 },
400 .vector_type => |vector_type| {400 .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;
402 if (vector_type.child == .bool_type) {402 if (vector_type.child == .bool_type) {
403 const bytes = try code.addManyAsSlice(abi_size);403 const bytes = try code.addManyAsSlice(abi_size);
404 @memset(bytes, 0xaa);404 @memset(bytes, 0xaa);
...@@ -458,7 +458,7 @@ pub fn generateSymbol(...@@ -458,7 +458,7 @@ pub fn generateSymbol(
458 }458 }
459459
460 const padding = abi_size -460 const padding = abi_size -
461 (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(pt) * vector_type.len) orelse461 (math.cast(usize, Type.fromInterned(vector_type.child).abiSize(zcu) * vector_type.len) orelse
462 return error.Overflow);462 return error.Overflow);
463 if (padding > 0) try code.appendNTimes(0, padding);463 if (padding > 0) try code.appendNTimes(0, padding);
464 }464 }
...@@ -471,7 +471,7 @@ pub fn generateSymbol(...@@ -471,7 +471,7 @@ pub fn generateSymbol(
471 0..,471 0..,
472 ) |field_ty, comptime_val, index| {472 ) |field_ty, comptime_val, index| {
473 if (comptime_val != .none) continue;473 if (comptime_val != .none) continue;
474 if (!Type.fromInterned(field_ty).hasRuntimeBits(pt)) continue;474 if (!Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
475475
476 const field_val = switch (aggregate.storage) {476 const field_val = switch (aggregate.storage) {
477 .bytes => |bytes| try pt.intern(.{ .int = .{477 .bytes => |bytes| try pt.intern(.{ .int = .{
...@@ -489,7 +489,7 @@ pub fn generateSymbol(...@@ -489,7 +489,7 @@ pub fn generateSymbol(
489 const unpadded_field_end = code.items.len - struct_begin;489 const unpadded_field_end = code.items.len - struct_begin;
490490
491 // Pad struct members if required491 // 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);
493 const padding = math.cast(usize, padded_field_end - unpadded_field_end) orelse493 const padding = math.cast(usize, padded_field_end - unpadded_field_end) orelse
494 return error.Overflow;494 return error.Overflow;
495495
...@@ -502,7 +502,7 @@ pub fn generateSymbol(...@@ -502,7 +502,7 @@ pub fn generateSymbol(
502 const struct_type = ip.loadStructType(ty.toIntern());502 const struct_type = ip.loadStructType(ty.toIntern());
503 switch (struct_type.layout) {503 switch (struct_type.layout) {
504 .@"packed" => {504 .@"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;
506 const current_pos = code.items.len;506 const current_pos = code.items.len;
507 try code.appendNTimes(0, abi_size);507 try code.appendNTimes(0, abi_size);
508 var bits: u16 = 0;508 var bits: u16 = 0;
...@@ -519,8 +519,8 @@ pub fn generateSymbol(...@@ -519,8 +519,8 @@ pub fn generateSymbol(
519519
520 // pointer may point to a decl which must be marked used520 // pointer may point to a decl which must be marked used
521 // but can also result in a relocation. Therefore we handle those separately.521 // but can also result in a relocation. Therefore we handle those separately.
522 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .Pointer) {522 if (Type.fromInterned(field_ty).zigTypeTag(zcu) == .Pointer) {
523 const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(pt)) orelse523 const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(zcu)) orelse
524 return error.Overflow;524 return error.Overflow;
525 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);525 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
526 defer tmp_list.deinit();526 defer tmp_list.deinit();
...@@ -531,7 +531,7 @@ pub fn generateSymbol(...@@ -531,7 +531,7 @@ pub fn generateSymbol(
531 } else {531 } else {
532 Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), pt, code.items[current_pos..], bits) catch unreachable;532 Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), pt, code.items[current_pos..], bits) catch unreachable;
533 }533 }
534 bits += @intCast(Type.fromInterned(field_ty).bitSize(pt));534 bits += @intCast(Type.fromInterned(field_ty).bitSize(zcu));
535 }535 }
536 },536 },
537 .auto, .@"extern" => {537 .auto, .@"extern" => {
...@@ -542,7 +542,7 @@ pub fn generateSymbol(...@@ -542,7 +542,7 @@ pub fn generateSymbol(
542 var it = struct_type.iterateRuntimeOrder(ip);542 var it = struct_type.iterateRuntimeOrder(ip);
543 while (it.next()) |field_index| {543 while (it.next()) |field_index| {
544 const field_ty = field_types[field_index];544 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
547 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {547 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
548 .bytes => |bytes| try pt.intern(.{ .int = .{548 .bytes => |bytes| try pt.intern(.{ .int = .{
...@@ -580,7 +580,7 @@ pub fn generateSymbol(...@@ -580,7 +580,7 @@ pub fn generateSymbol(
580 else => unreachable,580 else => unreachable,
581 },581 },
582 .un => |un| {582 .un => |un| {
583 const layout = ty.unionGetLayout(pt);583 const layout = ty.unionGetLayout(zcu);
584584
585 if (layout.payload_size == 0) {585 if (layout.payload_size == 0) {
586 return generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info);586 return generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.tag), code, debug_output, reloc_info);
...@@ -594,11 +594,11 @@ pub fn generateSymbol(...@@ -594,11 +594,11 @@ pub fn generateSymbol(
594 }594 }
595 }595 }
596596
597 const union_obj = mod.typeToUnion(ty).?;597 const union_obj = zcu.typeToUnion(ty).?;
598 if (un.tag != .none) {598 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).?;
600 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);600 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)) {
602 try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);602 try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);
603 } else {603 } else {
604 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) {604 switch (try generateSymbol(bin_file, pt, src_loc, Value.fromInterned(un.val), code, debug_output, reloc_info)) {
...@@ -606,7 +606,7 @@ pub fn generateSymbol(...@@ -606,7 +606,7 @@ pub fn generateSymbol(
606 .fail => |em| return Result{ .fail = em },606 .fail => |em| return Result{ .fail = em },
607 }607 }
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;
610 if (padding > 0) {610 if (padding > 0) {
611 try code.appendNTimes(0, padding);611 try code.appendNTimes(0, padding);
612 }612 }
...@@ -661,7 +661,7 @@ fn lowerPtr(...@@ -661,7 +661,7 @@ fn lowerPtr(
661 reloc_info,661 reloc_info,
662 offset + errUnionPayloadOffset(662 offset + errUnionPayloadOffset(
663 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu).errorUnionPayload(zcu),663 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu).errorUnionPayload(zcu),
664 pt,664 zcu,
665 ),665 ),
666 ),666 ),
667 .opt_payload => |opt_ptr| try lowerPtr(667 .opt_payload => |opt_ptr| try lowerPtr(
...@@ -687,7 +687,7 @@ fn lowerPtr(...@@ -687,7 +687,7 @@ fn lowerPtr(
687 };687 };
688 },688 },
689 .Struct, .Union => switch (base_ty.containerLayout(zcu)) {689 .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),
691 .@"extern", .@"packed" => unreachable,691 .@"extern", .@"packed" => unreachable,
692 },692 },
693 else => unreachable,693 else => unreachable,
...@@ -713,15 +713,16 @@ fn lowerUavRef(...@@ -713,15 +713,16 @@ fn lowerUavRef(
713 offset: u64,713 offset: u64,
714) CodeGenError!Result {714) CodeGenError!Result {
715 _ = debug_output;715 _ = debug_output;
716 const ip = &pt.zcu.intern_pool;716 const zcu = pt.zcu;
717 const ip = &zcu.intern_pool;
717 const target = lf.comp.root_mod.resolved_target.result;718 const target = lf.comp.root_mod.resolved_target.result;
718719
719 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);720 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
720 const uav_val = uav.val;721 const uav_val = uav.val;
721 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));722 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));
722 log.debug("lowerUavRef: ty = {}", .{uav_ty.fmt(pt)});723 log.debug("lowerUavRef: ty = {}", .{uav_ty.fmt(pt)});
723 const is_fn_body = uav_ty.zigTypeTag(pt.zcu) == .Fn;724 const is_fn_body = uav_ty.zigTypeTag(zcu) == .Fn;
724 if (!is_fn_body and !uav_ty.hasRuntimeBits(pt)) {725 if (!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) {
725 try code.appendNTimes(0xaa, ptr_width_bytes);726 try code.appendNTimes(0xaa, ptr_width_bytes);
726 return Result.ok;727 return Result.ok;
727 }728 }
...@@ -768,7 +769,7 @@ fn lowerNavRef(...@@ -768,7 +769,7 @@ fn lowerNavRef(
768 const ptr_width = target.ptrBitWidth();769 const ptr_width = target.ptrBitWidth();
769 const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));770 const nav_ty = Type.fromInterned(ip.getNav(nav_index).typeOf(ip));
770 const is_fn_body = nav_ty.zigTypeTag(zcu) == .Fn;771 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)) {
772 try code.appendNTimes(0xaa, @divExact(ptr_width, 8));773 try code.appendNTimes(0xaa, @divExact(ptr_width, 8));
773 return Result.ok;774 return Result.ok;
774 }775 }
...@@ -860,7 +861,7 @@ fn genNavRef(...@@ -860,7 +861,7 @@ fn genNavRef(
860 const ty = val.typeOf(zcu);861 const ty = val.typeOf(zcu);
861 log.debug("genNavRef: val = {}", .{val.fmtValue(pt)});862 log.debug("genNavRef: val = {}", .{val.fmtValue(pt)});
862863
863 if (!ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {864 if (!ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
864 const imm: u64 = switch (@divExact(target.ptrBitWidth(), 8)) {865 const imm: u64 = switch (@divExact(target.ptrBitWidth(), 8)) {
865 1 => 0xaa,866 1 => 0xaa,
866 2 => 0xaaaa,867 2 => 0xaaaa,
...@@ -877,12 +878,12 @@ fn genNavRef(...@@ -877,12 +878,12 @@ fn genNavRef(
877 // TODO this feels clunky. Perhaps we should check for it in `genTypedValue`?878 // TODO this feels clunky. Perhaps we should check for it in `genTypedValue`?
878 if (ty.castPtrToFn(zcu)) |fn_ty| {879 if (ty.castPtrToFn(zcu)) |fn_ty| {
879 if (zcu.typeToFunc(fn_ty).?.is_generic) {880 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().? } };
881 }882 }
882 } else if (ty.zigTypeTag(zcu) == .Pointer) {883 } else if (ty.zigTypeTag(zcu) == .Pointer) {
883 const elem_ty = ty.elemType2(zcu);884 const elem_ty = ty.elemType2(zcu);
884 if (!elem_ty.hasRuntimeBits(pt)) {885 if (!elem_ty.hasRuntimeBits(zcu)) {
885 return .{ .mcv = .{ .immediate = elem_ty.abiAlignment(pt).toByteUnits().? } };886 return .{ .mcv = .{ .immediate = elem_ty.abiAlignment(zcu).toByteUnits().? } };
886 }887 }
887 }888 }
888889
...@@ -963,15 +964,15 @@ pub fn genTypedValue(...@@ -963,15 +964,15 @@ pub fn genTypedValue(
963 },964 },
964 else => switch (ip.indexToKey(val.toIntern())) {965 else => switch (ip.indexToKey(val.toIntern())) {
965 .int => {966 .int => {
966 return .{ .mcv = .{ .immediate = val.toUnsignedInt(pt) } };967 return .{ .mcv = .{ .immediate = val.toUnsignedInt(zcu) } };
967 },968 },
968 .ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) {969 .ptr => |ptr| if (ptr.byte_offset == 0) switch (ptr.base_addr) {
969 .nav => |nav| return genNavRef(lf, pt, src_loc, val, nav, target),970 .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))
971 return switch (try lf.lowerUav(972 return switch (try lf.lowerUav(
972 pt,973 pt,
973 uav.val,974 uav.val,
974 Type.fromInterned(uav.orig_ty).ptrAlignment(pt),975 Type.fromInterned(uav.orig_ty).ptrAlignment(zcu),
975 src_loc,976 src_loc,
976 )) {977 )) {
977 .mcv => |mcv| return .{ .mcv = switch (mcv) {978 .mcv => |mcv| return .{ .mcv = switch (mcv) {
...@@ -982,7 +983,7 @@ pub fn genTypedValue(...@@ -982,7 +983,7 @@ pub fn genTypedValue(
982 .fail => |em| return .{ .fail = em },983 .fail => |em| return .{ .fail = em },
983 }984 }
984 else985 else
985 return .{ .mcv = .{ .immediate = Type.fromInterned(uav.orig_ty).ptrAlignment(pt)986 return .{ .mcv = .{ .immediate = Type.fromInterned(uav.orig_ty).ptrAlignment(zcu)
986 .forward(@intCast((@as(u66, 1) << @intCast(target.ptrBitWidth() | 1)) / 3)) } },987 .forward(@intCast((@as(u66, 1) << @intCast(target.ptrBitWidth() | 1)) / 3)) } },
987 else => {},988 else => {},
988 },989 },
...@@ -994,8 +995,8 @@ pub fn genTypedValue(...@@ -994,8 +995,8 @@ pub fn genTypedValue(
994 const info = ty.intInfo(zcu);995 const info = ty.intInfo(zcu);
995 if (info.bits <= target.ptrBitWidth()) {996 if (info.bits <= target.ptrBitWidth()) {
996 const unsigned: u64 = switch (info.signedness) {997 const unsigned: u64 = switch (info.signedness) {
997 .signed => @bitCast(val.toSignedInt(pt)),998 .signed => @bitCast(val.toSignedInt(zcu)),
998 .unsigned => val.toUnsignedInt(pt),999 .unsigned => val.toUnsignedInt(zcu),
999 };1000 };
1000 return .{ .mcv = .{ .immediate = unsigned } };1001 return .{ .mcv = .{ .immediate = unsigned } };
1001 }1002 }
...@@ -1012,7 +1013,7 @@ pub fn genTypedValue(...@@ -1012,7 +1013,7 @@ pub fn genTypedValue(
1012 val.optionalValue(zcu) orelse return .{ .mcv = .{ .immediate = 0 } },1013 val.optionalValue(zcu) orelse return .{ .mcv = .{ .immediate = 0 } },
1013 target,1014 target,
1014 );1015 );
1015 } else if (ty.abiSize(pt) == 1) {1016 } else if (ty.abiSize(zcu) == 1) {
1016 return .{ .mcv = .{ .immediate = @intFromBool(!val.isNull(zcu)) } };1017 return .{ .mcv = .{ .immediate = @intFromBool(!val.isNull(zcu)) } };
1017 }1018 }
1018 },1019 },
...@@ -1034,7 +1035,7 @@ pub fn genTypedValue(...@@ -1034,7 +1035,7 @@ pub fn genTypedValue(
1034 .ErrorUnion => {1035 .ErrorUnion => {
1035 const err_type = ty.errorUnionSet(zcu);1036 const err_type = ty.errorUnionSet(zcu);
1036 const payload_type = ty.errorUnionPayload(zcu);1037 const payload_type = ty.errorUnionPayload(zcu);
1037 if (!payload_type.hasRuntimeBitsIgnoreComptime(pt)) {1038 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
1038 // We use the error type directly as the type.1039 // We use the error type directly as the type.
1039 const err_int_ty = try pt.errorIntType();1040 const err_int_ty = try pt.errorIntType();
1040 switch (ip.indexToKey(val.toIntern()).error_union.val) {1041 switch (ip.indexToKey(val.toIntern()).error_union.val) {
...@@ -1074,23 +1075,23 @@ pub fn genTypedValue(...@@ -1074,23 +1075,23 @@ pub fn genTypedValue(
1074 return lf.lowerUav(pt, val.toIntern(), .none, src_loc);1075 return lf.lowerUav(pt, val.toIntern(), .none, src_loc);
1075}1076}
10761077
1077pub fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {1078pub fn errUnionPayloadOffset(payload_ty: Type, zcu: *Zcu) u64 {
1078 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;1079 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
1079 const payload_align = payload_ty.abiAlignment(pt);1080 const payload_align = payload_ty.abiAlignment(zcu);
1080 const error_align = Type.anyerror.abiAlignment(pt);1081 const error_align = Type.anyerror.abiAlignment(zcu);
1081 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {1082 if (payload_align.compare(.gte, error_align) or !payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1082 return 0;1083 return 0;
1083 } else {1084 } else {
1084 return payload_align.forward(Type.anyerror.abiSize(pt));1085 return payload_align.forward(Type.anyerror.abiSize(zcu));
1085 }1086 }
1086}1087}
10871088
1088pub fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) u64 {1089pub fn errUnionErrorOffset(payload_ty: Type, zcu: *Zcu) u64 {
1089 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return 0;1090 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return 0;
1090 const payload_align = payload_ty.abiAlignment(pt);1091 const payload_align = payload_ty.abiAlignment(zcu);
1091 const error_align = Type.anyerror.abiAlignment(pt);1092 const error_align = Type.anyerror.abiAlignment(zcu);
1092 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {1093 if (payload_align.compare(.gte, error_align) and payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1093 return error_align.forward(payload_ty.abiSize(pt));1094 return error_align.forward(payload_ty.abiSize(zcu));
1094 } else {1095 } else {
1095 return 0;1096 return 0;
1096 }1097 }
src/codegen/c.zig+123-118
...@@ -334,7 +334,7 @@ pub const Function = struct {...@@ -334,7 +334,7 @@ pub const Function = struct {
334 const writer = f.object.codeHeaderWriter();334 const writer = f.object.codeHeaderWriter();
335 const decl_c_value = try f.allocLocalValue(.{335 const decl_c_value = try f.allocLocalValue(.{
336 .ctype = try f.ctypeFromType(ty, .complete),336 .ctype = try f.ctypeFromType(ty, .complete),
337 .alignas = CType.AlignAs.fromAbiAlignment(ty.abiAlignment(pt)),337 .alignas = CType.AlignAs.fromAbiAlignment(ty.abiAlignment(pt.zcu)),
338 });338 });
339 const gpa = f.object.dg.gpa;339 const gpa = f.object.dg.gpa;
340 try f.allocs.put(gpa, decl_c_value.new_local, false);340 try f.allocs.put(gpa, decl_c_value.new_local, false);
...@@ -372,7 +372,7 @@ pub const Function = struct {...@@ -372,7 +372,7 @@ pub const Function = struct {
372 fn allocLocal(f: *Function, inst: ?Air.Inst.Index, ty: Type) !CValue {372 fn allocLocal(f: *Function, inst: ?Air.Inst.Index, ty: Type) !CValue {
373 return f.allocAlignedLocal(inst, .{373 return f.allocAlignedLocal(inst, .{
374 .ctype = try f.ctypeFromType(ty, .complete),374 .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)),
376 });376 });
377 }377 }
378378
...@@ -648,7 +648,7 @@ pub const DeclGen = struct {...@@ -648,7 +648,7 @@ pub const DeclGen = struct {
648648
649 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.649 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
650 const ptr_ty = Type.fromInterned(uav.orig_ty);650 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)) {
652 return dg.writeCValue(writer, .{ .undef = ptr_ty });652 return dg.writeCValue(writer, .{ .undef = ptr_ty });
653 }653 }
654654
...@@ -688,7 +688,7 @@ pub const DeclGen = struct {...@@ -688,7 +688,7 @@ pub const DeclGen = struct {
688 // alignment. If there is already an entry, keep the greater alignment.688 // alignment. If there is already an entry, keep the greater alignment.
689 const explicit_alignment = ptr_type.flags.alignment;689 const explicit_alignment = ptr_type.flags.alignment;
690 if (explicit_alignment != .none) {690 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);
692 if (explicit_alignment.order(abi_alignment).compare(.gt)) {692 if (explicit_alignment.order(abi_alignment).compare(.gt)) {
693 const aligned_gop = try dg.aligned_uavs.getOrPut(dg.gpa, uav.val);693 const aligned_gop = try dg.aligned_uavs.getOrPut(dg.gpa, uav.val);
694 aligned_gop.value_ptr.* = if (aligned_gop.found_existing)694 aligned_gop.value_ptr.* = if (aligned_gop.found_existing)
...@@ -722,7 +722,7 @@ pub const DeclGen = struct {...@@ -722,7 +722,7 @@ pub const DeclGen = struct {
722 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.722 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
723 const nav_ty = Type.fromInterned(ip.getNav(owner_nav).typeOf(ip));723 const nav_ty = Type.fromInterned(ip.getNav(owner_nav).typeOf(ip));
724 const ptr_ty = try pt.navPtrType(owner_nav);724 const ptr_ty = try pt.navPtrType(owner_nav);
725 if (!nav_ty.isFnOrHasRuntimeBits(pt)) {725 if (!nav_ty.isFnOrHasRuntimeBits(zcu)) {
726 return dg.writeCValue(writer, .{ .undef = ptr_ty });726 return dg.writeCValue(writer, .{ .undef = ptr_ty });
727 }727 }
728728
...@@ -805,7 +805,7 @@ pub const DeclGen = struct {...@@ -805,7 +805,7 @@ pub const DeclGen = struct {
805 }805 }
806 },806 },
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)) {
809 // Element type is zero-bit, so lowers to `void`. The index is irrelevant; just cast the pointer.809 // Element type is zero-bit, so lowers to `void`. The index is irrelevant; just cast the pointer.
810 const ptr_ctype = try dg.ctypeFromType(elem.result_ptr_ty, .complete);810 const ptr_ctype = try dg.ctypeFromType(elem.result_ptr_ty, .complete);
811 try writer.writeByte('(');811 try writer.writeByte('(');
...@@ -923,7 +923,7 @@ pub const DeclGen = struct {...@@ -923,7 +923,7 @@ pub const DeclGen = struct {
923 try writer.writeAll("((");923 try writer.writeAll("((");
924 try dg.renderCType(writer, ctype);924 try dg.renderCType(writer, ctype);
925 try writer.print("){x})", .{try dg.fmtIntLiteral(925 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)),
927 .Other,927 .Other,
928 )});928 )});
929 },929 },
...@@ -970,7 +970,7 @@ pub const DeclGen = struct {...@@ -970,7 +970,7 @@ pub const DeclGen = struct {
970 .enum_tag => |enum_tag| try dg.renderValue(writer, Value.fromInterned(enum_tag.int), location),970 .enum_tag => |enum_tag| try dg.renderValue(writer, Value.fromInterned(enum_tag.int), location),
971 .float => {971 .float => {
972 const bits = ty.floatBits(target.*);972 const bits = ty.floatBits(target.*);
973 const f128_val = val.toFloat(f128, pt);973 const f128_val = val.toFloat(f128, zcu);
974974
975 // All unsigned ints matching float types are pre-allocated.975 // All unsigned ints matching float types are pre-allocated.
976 const repr_ty = pt.intType(.unsigned, bits) catch unreachable;976 const repr_ty = pt.intType(.unsigned, bits) catch unreachable;
...@@ -984,10 +984,10 @@ pub const DeclGen = struct {...@@ -984,10 +984,10 @@ pub const DeclGen = struct {
984 };984 };
985985
986 switch (bits) {986 switch (bits) {
987 16 => repr_val_big.set(@as(u16, @bitCast(val.toFloat(f16, 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, pt)))),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, pt)))),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, pt)))),990 80 => repr_val_big.set(@as(u80, @bitCast(val.toFloat(f80, zcu)))),
991 128 => repr_val_big.set(@as(u128, @bitCast(f128_val))),991 128 => repr_val_big.set(@as(u128, @bitCast(f128_val))),
992 else => unreachable,992 else => unreachable,
993 }993 }
...@@ -998,10 +998,10 @@ pub const DeclGen = struct {...@@ -998,10 +998,10 @@ pub const DeclGen = struct {
998 try dg.renderTypeForBuiltinFnName(writer, ty);998 try dg.renderTypeForBuiltinFnName(writer, ty);
999 try writer.writeByte('(');999 try writer.writeByte('(');
1000 switch (bits) {1000 switch (bits) {
1001 16 => try writer.print("{x}", .{val.toFloat(f16, pt)}),1001 16 => try writer.print("{x}", .{val.toFloat(f16, zcu)}),
1002 32 => try writer.print("{x}", .{val.toFloat(f32, pt)}),1002 32 => try writer.print("{x}", .{val.toFloat(f32, zcu)}),
1003 64 => try writer.print("{x}", .{val.toFloat(f64, pt)}),1003 64 => try writer.print("{x}", .{val.toFloat(f64, zcu)}),
1004 80 => try writer.print("{x}", .{val.toFloat(f80, pt)}),1004 80 => try writer.print("{x}", .{val.toFloat(f80, zcu)}),
1005 128 => try writer.print("{x}", .{f128_val}),1005 128 => try writer.print("{x}", .{f128_val}),
1006 else => unreachable,1006 else => unreachable,
1007 }1007 }
...@@ -1041,10 +1041,10 @@ pub const DeclGen = struct {...@@ -1041,10 +1041,10 @@ pub const DeclGen = struct {
1041 if (std.math.isNan(f128_val)) switch (bits) {1041 if (std.math.isNan(f128_val)) switch (bits) {
1042 // We only actually need to pass the significand, but it will get1042 // We only actually need to pass the significand, but it will get
1043 // properly masked anyway, so just pass the whole value.1043 // properly masked anyway, so just pass the whole value.
1044 16 => try writer.print("\"0x{x}\"", .{@as(u16, @bitCast(val.toFloat(f16, 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, pt)))}),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, pt)))}),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, pt)))}),1047 80 => try writer.print("\"0x{x}\"", .{@as(u80, @bitCast(val.toFloat(f80, zcu)))}),
1048 128 => try writer.print("\"0x{x}\"", .{@as(u128, @bitCast(f128_val))}),1048 128 => try writer.print("\"0x{x}\"", .{@as(u128, @bitCast(f128_val))}),
1049 else => unreachable,1049 else => unreachable,
1050 };1050 };
...@@ -1167,11 +1167,11 @@ pub const DeclGen = struct {...@@ -1167,11 +1167,11 @@ pub const DeclGen = struct {
1167 const elem_val_u8: u8 = if (elem_val.isUndef(zcu))1167 const elem_val_u8: u8 = if (elem_val.isUndef(zcu))
1168 undefPattern(u8)1168 undefPattern(u8)
1169 else1169 else
1170 @intCast(elem_val.toUnsignedInt(pt));1170 @intCast(elem_val.toUnsignedInt(zcu));
1171 try literal.writeChar(elem_val_u8);1171 try literal.writeChar(elem_val_u8);
1172 }1172 }
1173 if (ai.sentinel) |s| {1173 if (ai.sentinel) |s| {
1174 const s_u8: u8 = @intCast(s.toUnsignedInt(pt));1174 const s_u8: u8 = @intCast(s.toUnsignedInt(zcu));
1175 if (s_u8 != 0) try literal.writeChar(s_u8);1175 if (s_u8 != 0) try literal.writeChar(s_u8);
1176 }1176 }
1177 try literal.end();1177 try literal.end();
...@@ -1203,7 +1203,7 @@ pub const DeclGen = struct {...@@ -1203,7 +1203,7 @@ pub const DeclGen = struct {
1203 const comptime_val = tuple.values.get(ip)[field_index];1203 const comptime_val = tuple.values.get(ip)[field_index];
1204 if (comptime_val != .none) continue;1204 if (comptime_val != .none) continue;
1205 const field_ty = Type.fromInterned(tuple.types.get(ip)[field_index]);1205 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
1208 if (!empty) try writer.writeByte(',');1208 if (!empty) try writer.writeByte(',');
12091209
...@@ -1238,7 +1238,7 @@ pub const DeclGen = struct {...@@ -1238,7 +1238,7 @@ pub const DeclGen = struct {
1238 var need_comma = false;1238 var need_comma = false;
1239 while (field_it.next()) |field_index| {1239 while (field_it.next()) |field_index| {
1240 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);1240 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
1243 if (need_comma) try writer.writeByte(',');1243 if (need_comma) try writer.writeByte(',');
1244 need_comma = true;1244 need_comma = true;
...@@ -1265,7 +1265,7 @@ pub const DeclGen = struct {...@@ -1265,7 +1265,7 @@ pub const DeclGen = struct {
12651265
1266 for (0..loaded_struct.field_types.len) |field_index| {1266 for (0..loaded_struct.field_types.len) |field_index| {
1267 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);1267 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;
1269 eff_num_fields += 1;1269 eff_num_fields += 1;
1270 }1270 }
12711271
...@@ -1273,7 +1273,7 @@ pub const DeclGen = struct {...@@ -1273,7 +1273,7 @@ pub const DeclGen = struct {
1273 try writer.writeByte('(');1273 try writer.writeByte('(');
1274 try dg.renderUndefValue(writer, ty, location);1274 try dg.renderUndefValue(writer, ty, location);
1275 try writer.writeByte(')');1275 try writer.writeByte(')');
1276 } else if (ty.bitSize(pt) > 64) {1276 } else if (ty.bitSize(zcu) > 64) {
1277 // zig_or_u128(zig_or_u128(zig_shl_u128(a, a_off), zig_shl_u128(b, b_off)), zig_shl_u128(c, c_off))1277 // zig_or_u128(zig_or_u128(zig_shl_u128(a, a_off), zig_shl_u128(b, b_off)), zig_shl_u128(c, c_off))
1278 var num_or = eff_num_fields - 1;1278 var num_or = eff_num_fields - 1;
1279 while (num_or > 0) : (num_or -= 1) {1279 while (num_or > 0) : (num_or -= 1) {
...@@ -1286,7 +1286,7 @@ pub const DeclGen = struct {...@@ -1286,7 +1286,7 @@ pub const DeclGen = struct {
1286 var needs_closing_paren = false;1286 var needs_closing_paren = false;
1287 for (0..loaded_struct.field_types.len) |field_index| {1287 for (0..loaded_struct.field_types.len) |field_index| {
1288 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);1288 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
1291 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {1291 const field_val = switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
1292 .bytes => |bytes| try pt.intern(.{ .int = .{1292 .bytes => |bytes| try pt.intern(.{ .int = .{
...@@ -1312,7 +1312,7 @@ pub const DeclGen = struct {...@@ -1312,7 +1312,7 @@ pub const DeclGen = struct {
1312 if (needs_closing_paren) try writer.writeByte(')');1312 if (needs_closing_paren) try writer.writeByte(')');
1313 if (eff_index != eff_num_fields - 1) try writer.writeAll(", ");1313 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);
1316 needs_closing_paren = true;1316 needs_closing_paren = true;
1317 eff_index += 1;1317 eff_index += 1;
1318 }1318 }
...@@ -1322,7 +1322,7 @@ pub const DeclGen = struct {...@@ -1322,7 +1322,7 @@ pub const DeclGen = struct {
1322 var empty = true;1322 var empty = true;
1323 for (0..loaded_struct.field_types.len) |field_index| {1323 for (0..loaded_struct.field_types.len) |field_index| {
1324 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);1324 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
1327 if (!empty) try writer.writeAll(" | ");1327 if (!empty) try writer.writeAll(" | ");
1328 try writer.writeByte('(');1328 try writer.writeByte('(');
...@@ -1346,7 +1346,7 @@ pub const DeclGen = struct {...@@ -1346,7 +1346,7 @@ pub const DeclGen = struct {
1346 try dg.renderValue(writer, Value.fromInterned(field_val), .Other);1346 try dg.renderValue(writer, Value.fromInterned(field_val), .Other);
1347 }1347 }
13481348
1349 bit_offset += field_ty.bitSize(pt);1349 bit_offset += field_ty.bitSize(zcu);
1350 empty = false;1350 empty = false;
1351 }1351 }
1352 try writer.writeByte(')');1352 try writer.writeByte(')');
...@@ -1396,7 +1396,7 @@ pub const DeclGen = struct {...@@ -1396,7 +1396,7 @@ pub const DeclGen = struct {
1396 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);1396 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
1397 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];1397 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
1398 if (loaded_union.flagsUnordered(ip).layout == .@"packed") {1398 if (loaded_union.flagsUnordered(ip).layout == .@"packed") {
1399 if (field_ty.hasRuntimeBits(pt)) {1399 if (field_ty.hasRuntimeBits(zcu)) {
1400 if (field_ty.isPtrAtRuntime(zcu)) {1400 if (field_ty.isPtrAtRuntime(zcu)) {
1401 try writer.writeByte('(');1401 try writer.writeByte('(');
1402 try dg.renderCType(writer, ctype);1402 try dg.renderCType(writer, ctype);
...@@ -1427,7 +1427,7 @@ pub const DeclGen = struct {...@@ -1427,7 +1427,7 @@ pub const DeclGen = struct {
1427 ),1427 ),
1428 .payload => {1428 .payload => {
1429 try writer.writeByte('{');1429 try writer.writeByte('{');
1430 if (field_ty.hasRuntimeBits(pt)) {1430 if (field_ty.hasRuntimeBits(zcu)) {
1431 try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});1431 try writer.print(" .{ } = ", .{fmtIdent(field_name.toSlice(ip))});
1432 try dg.renderValue(1432 try dg.renderValue(
1433 writer,1433 writer,
...@@ -1439,7 +1439,7 @@ pub const DeclGen = struct {...@@ -1439,7 +1439,7 @@ pub const DeclGen = struct {
1439 const inner_field_ty = Type.fromInterned(1439 const inner_field_ty = Type.fromInterned(
1440 loaded_union.field_types.get(ip)[inner_field_index],1440 loaded_union.field_types.get(ip)[inner_field_index],
1441 );1441 );
1442 if (!inner_field_ty.hasRuntimeBits(pt)) continue;1442 if (!inner_field_ty.hasRuntimeBits(zcu)) continue;
1443 try dg.renderUndefValue(writer, inner_field_ty, initializer_type);1443 try dg.renderUndefValue(writer, inner_field_ty, initializer_type);
1444 break;1444 break;
1445 }1445 }
...@@ -1588,7 +1588,7 @@ pub const DeclGen = struct {...@@ -1588,7 +1588,7 @@ pub const DeclGen = struct {
1588 var need_comma = false;1588 var need_comma = false;
1589 while (field_it.next()) |field_index| {1589 while (field_it.next()) |field_index| {
1590 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);1590 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
1593 if (need_comma) try writer.writeByte(',');1593 if (need_comma) try writer.writeByte(',');
1594 need_comma = true;1594 need_comma = true;
...@@ -1613,7 +1613,7 @@ pub const DeclGen = struct {...@@ -1613,7 +1613,7 @@ pub const DeclGen = struct {
1613 for (0..anon_struct_info.types.len) |field_index| {1613 for (0..anon_struct_info.types.len) |field_index| {
1614 if (anon_struct_info.values.get(ip)[field_index] != .none) continue;1614 if (anon_struct_info.values.get(ip)[field_index] != .none) continue;
1615 const field_ty = Type.fromInterned(anon_struct_info.types.get(ip)[field_index]);1615 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
1618 if (need_comma) try writer.writeByte(',');1618 if (need_comma) try writer.writeByte(',');
1619 need_comma = true;1619 need_comma = true;
...@@ -1651,7 +1651,7 @@ pub const DeclGen = struct {...@@ -1651,7 +1651,7 @@ pub const DeclGen = struct {
1651 const inner_field_ty = Type.fromInterned(1651 const inner_field_ty = Type.fromInterned(
1652 loaded_union.field_types.get(ip)[inner_field_index],1652 loaded_union.field_types.get(ip)[inner_field_index],
1653 );1653 );
1654 if (!inner_field_ty.hasRuntimeBits(pt)) continue;1654 if (!inner_field_ty.hasRuntimeBits(pt.zcu)) continue;
1655 try dg.renderUndefValue(1655 try dg.renderUndefValue(
1656 writer,1656 writer,
1657 inner_field_ty,1657 inner_field_ty,
...@@ -1902,7 +1902,8 @@ pub const DeclGen = struct {...@@ -1902,7 +1902,8 @@ pub const DeclGen = struct {
1902 };1902 };
1903 fn intCastIsNoop(dg: *DeclGen, dest_ty: Type, src_ty: Type) bool {1903 fn intCastIsNoop(dg: *DeclGen, dest_ty: Type, src_ty: Type) bool {
1904 const pt = dg.pt;1904 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);
1906 const dest_int_info = dest_ty.intInfo(pt.zcu);1907 const dest_int_info = dest_ty.intInfo(pt.zcu);
19071908
1908 const src_is_ptr = src_ty.isPtrAtRuntime(pt.zcu);1909 const src_is_ptr = src_ty.isPtrAtRuntime(pt.zcu);
...@@ -1911,7 +1912,7 @@ pub const DeclGen = struct {...@@ -1911,7 +1912,7 @@ pub const DeclGen = struct {
1911 .signed => Type.isize,1912 .signed => Type.isize,
1912 } else src_ty;1913 } else src_ty;
19131914
1914 const src_bits = src_eff_ty.bitSize(pt);1915 const src_bits = src_eff_ty.bitSize(zcu);
1915 const src_int_info = if (src_eff_ty.isAbiInt(pt.zcu)) src_eff_ty.intInfo(pt.zcu) else null;1916 const src_int_info = if (src_eff_ty.isAbiInt(pt.zcu)) src_eff_ty.intInfo(pt.zcu) else null;
1916 if (dest_bits <= 64 and src_bits <= 64) {1917 if (dest_bits <= 64 and src_bits <= 64) {
1917 const needs_cast = src_int_info == null or1918 const needs_cast = src_int_info == null or
...@@ -1943,7 +1944,7 @@ pub const DeclGen = struct {...@@ -1943,7 +1944,7 @@ pub const DeclGen = struct {
1943 ) !void {1944 ) !void {
1944 const pt = dg.pt;1945 const pt = dg.pt;
1945 const zcu = pt.zcu;1946 const zcu = pt.zcu;
1946 const dest_bits = dest_ty.bitSize(pt);1947 const dest_bits = dest_ty.bitSize(zcu);
1947 const dest_int_info = dest_ty.intInfo(zcu);1948 const dest_int_info = dest_ty.intInfo(zcu);
19481949
1949 const src_is_ptr = src_ty.isPtrAtRuntime(zcu);1950 const src_is_ptr = src_ty.isPtrAtRuntime(zcu);
...@@ -1952,7 +1953,7 @@ pub const DeclGen = struct {...@@ -1952,7 +1953,7 @@ pub const DeclGen = struct {
1952 .signed => Type.isize,1953 .signed => Type.isize,
1953 } else src_ty;1954 } else src_ty;
19541955
1955 const src_bits = src_eff_ty.bitSize(pt);1956 const src_bits = src_eff_ty.bitSize(zcu);
1956 const src_int_info = if (src_eff_ty.isAbiInt(zcu)) src_eff_ty.intInfo(zcu) else null;1957 const src_int_info = if (src_eff_ty.isAbiInt(zcu)) src_eff_ty.intInfo(zcu) else null;
1957 if (dest_bits <= 64 and src_bits <= 64) {1958 if (dest_bits <= 64 and src_bits <= 64) {
1958 const needs_cast = src_int_info == null or1959 const needs_cast = src_int_info == null or
...@@ -2033,7 +2034,7 @@ pub const DeclGen = struct {...@@ -2033,7 +2034,7 @@ pub const DeclGen = struct {
2033 qualifiers,2034 qualifiers,
2034 CType.AlignAs.fromAlignment(.{2035 CType.AlignAs.fromAlignment(.{
2035 .@"align" = alignment,2036 .@"align" = alignment,
2036 .abi = ty.abiAlignment(dg.pt),2037 .abi = ty.abiAlignment(dg.pt.zcu),
2037 }),2038 }),
2038 );2039 );
2039 }2040 }
...@@ -2239,9 +2240,10 @@ pub const DeclGen = struct {...@@ -2239,9 +2240,10 @@ pub const DeclGen = struct {
2239 }2240 }
22402241
2241 const pt = dg.pt;2242 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{
2243 .signedness = .unsigned,2245 .signedness = .unsigned,
2244 .bits = @as(u16, @intCast(ty.bitSize(pt))),2246 .bits = @as(u16, @intCast(ty.bitSize(zcu))),
2245 };2247 };
22462248
2247 if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});2249 if (is_big) try writer.print(", {}", .{int_info.signedness == .signed});
...@@ -2891,7 +2893,7 @@ pub fn genDecl(o: *Object) !void {...@@ -2891,7 +2893,7 @@ pub fn genDecl(o: *Object) !void {
2891 const nav = ip.getNav(o.dg.pass.nav);2893 const nav = ip.getNav(o.dg.pass.nav);
2892 const nav_ty = Type.fromInterned(nav.typeOf(ip));2894 const nav_ty = Type.fromInterned(nav.typeOf(ip));
28932895
2894 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) return;2896 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return;
2895 switch (ip.indexToKey(nav.status.resolved.val)) {2897 switch (ip.indexToKey(nav.status.resolved.val)) {
2896 .@"extern" => |@"extern"| {2898 .@"extern" => |@"extern"| {
2897 if (!ip.isFunctionType(nav_ty.toIntern())) return o.dg.renderFwdDecl(o.dg.pass.nav, .{2899 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: [...@@ -3420,10 +3422,10 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [
3420}3422}
34213423
3422fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {3424fn airPtrElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3423 const pt = f.object.dg.pt;3425 const zcu = f.object.dg.pt.zcu;
3424 const inst_ty = f.typeOfIndex(inst);3426 const inst_ty = f.typeOfIndex(inst);
3425 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3427 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3426 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {3428 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3427 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });3429 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3428 return .none;3430 return .none;
3429 }3431 }
...@@ -3453,7 +3455,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3453,7 +3455,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
34533455
3454 const inst_ty = f.typeOfIndex(inst);3456 const inst_ty = f.typeOfIndex(inst);
3455 const ptr_ty = f.typeOf(bin_op.lhs);3457 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
3458 const ptr = try f.resolveInst(bin_op.lhs);3460 const ptr = try f.resolveInst(bin_op.lhs);
3459 const index = try f.resolveInst(bin_op.rhs);3461 const index = try f.resolveInst(bin_op.rhs);
...@@ -3482,10 +3484,10 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3482,10 +3484,10 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3482}3484}
34833485
3484fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {3486fn airSliceElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3485 const pt = f.object.dg.pt;3487 const zcu = f.object.dg.pt.zcu;
3486 const inst_ty = f.typeOfIndex(inst);3488 const inst_ty = f.typeOfIndex(inst);
3487 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3489 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3488 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {3490 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3489 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });3491 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3490 return .none;3492 return .none;
3491 }3493 }
...@@ -3516,7 +3518,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3516,7 +3518,7 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3516 const inst_ty = f.typeOfIndex(inst);3518 const inst_ty = f.typeOfIndex(inst);
3517 const slice_ty = f.typeOf(bin_op.lhs);3519 const slice_ty = f.typeOf(bin_op.lhs);
3518 const elem_ty = slice_ty.elemType2(zcu);3520 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
3521 const slice = try f.resolveInst(bin_op.lhs);3523 const slice = try f.resolveInst(bin_op.lhs);
3522 const index = try f.resolveInst(bin_op.rhs);3524 const index = try f.resolveInst(bin_op.rhs);
...@@ -3539,10 +3541,10 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3539,10 +3541,10 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3539}3541}
35403542
3541fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {3543fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
3542 const pt = f.object.dg.pt;3544 const zcu = f.object.dg.pt.zcu;
3543 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3545 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
3544 const inst_ty = f.typeOfIndex(inst);3546 const inst_ty = f.typeOfIndex(inst);
3545 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {3547 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3546 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });3548 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
3547 return .none;3549 return .none;
3548 }3550 }
...@@ -3569,13 +3571,13 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3569,13 +3571,13 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {
3569 const zcu = pt.zcu;3571 const zcu = pt.zcu;
3570 const inst_ty = f.typeOfIndex(inst);3572 const inst_ty = f.typeOfIndex(inst);
3571 const elem_ty = inst_ty.childType(zcu);3573 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
3574 const local = try f.allocLocalValue(.{3576 const local = try f.allocLocalValue(.{
3575 .ctype = try f.ctypeFromType(elem_ty, .complete),3577 .ctype = try f.ctypeFromType(elem_ty, .complete),
3576 .alignas = CType.AlignAs.fromAlignment(.{3578 .alignas = CType.AlignAs.fromAlignment(.{
3577 .@"align" = inst_ty.ptrInfo(zcu).flags.alignment,3579 .@"align" = inst_ty.ptrInfo(zcu).flags.alignment,
3578 .abi = elem_ty.abiAlignment(pt),3580 .abi = elem_ty.abiAlignment(zcu),
3579 }),3581 }),
3580 });3582 });
3581 log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.new_local });3583 log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.new_local });
...@@ -3588,13 +3590,13 @@ fn airRetPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3588,13 +3590,13 @@ fn airRetPtr(f: *Function, inst: Air.Inst.Index) !CValue {
3588 const zcu = pt.zcu;3590 const zcu = pt.zcu;
3589 const inst_ty = f.typeOfIndex(inst);3591 const inst_ty = f.typeOfIndex(inst);
3590 const elem_ty = inst_ty.childType(zcu);3592 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
3593 const local = try f.allocLocalValue(.{3595 const local = try f.allocLocalValue(.{
3594 .ctype = try f.ctypeFromType(elem_ty, .complete),3596 .ctype = try f.ctypeFromType(elem_ty, .complete),
3595 .alignas = CType.AlignAs.fromAlignment(.{3597 .alignas = CType.AlignAs.fromAlignment(.{
3596 .@"align" = inst_ty.ptrInfo(zcu).flags.alignment,3598 .@"align" = inst_ty.ptrInfo(zcu).flags.alignment,
3597 .abi = elem_ty.abiAlignment(pt),3599 .abi = elem_ty.abiAlignment(zcu),
3598 }),3600 }),
3599 });3601 });
3600 log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.new_local });3602 log.debug("%{d}: allocated unfreeable t{d}", .{ inst, local.new_local });
...@@ -3636,7 +3638,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3636,7 +3638,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3636 const ptr_info = ptr_scalar_ty.ptrInfo(zcu);3638 const ptr_info = ptr_scalar_ty.ptrInfo(zcu);
3637 const src_ty = Type.fromInterned(ptr_info.child);3639 const src_ty = Type.fromInterned(ptr_info.child);
36383640
3639 if (!src_ty.hasRuntimeBitsIgnoreComptime(pt)) {3641 if (!src_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3640 try reap(f, inst, &.{ty_op.operand});3642 try reap(f, inst, &.{ty_op.operand});
3641 return .none;3643 return .none;
3642 }3644 }
...@@ -3646,7 +3648,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3646,7 +3648,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3646 try reap(f, inst, &.{ty_op.operand});3648 try reap(f, inst, &.{ty_op.operand});
36473649
3648 const is_aligned = if (ptr_info.flags.alignment != .none)3650 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)
3650 else3652 else
3651 true;3653 true;
3652 const is_array = lowersToArray(src_ty, pt);3654 const is_array = lowersToArray(src_ty, pt);
...@@ -3674,7 +3676,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3674,7 +3676,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3674 const bit_offset_ty = try pt.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));3676 const bit_offset_ty = try pt.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
3675 const bit_offset_val = try pt.intValue(bit_offset_ty, ptr_info.packed_offset.bit_offset);3677 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
3679 try f.writeCValue(writer, local, .Other);3681 try f.writeCValue(writer, local, .Other);
3680 try v.elem(f, writer);3682 try v.elem(f, writer);
...@@ -3685,9 +3687,9 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3685,9 +3687,9 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3685 try writer.writeAll("((");3687 try writer.writeAll("((");
3686 try f.renderType(writer, field_ty);3688 try f.renderType(writer, field_ty);
3687 try writer.writeByte(')');3689 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;
3689 if (cant_cast) {3691 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", .{});
3691 try writer.writeAll("zig_lo_");3693 try writer.writeAll("zig_lo_");
3692 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);3694 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);
3693 try writer.writeByte('(');3695 try writer.writeByte('(');
...@@ -3735,7 +3737,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {...@@ -3735,7 +3737,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
3735 const ret_val = if (is_array) ret_val: {3737 const ret_val = if (is_array) ret_val: {
3736 const array_local = try f.allocAlignedLocal(inst, .{3738 const array_local = try f.allocAlignedLocal(inst, .{
3737 .ctype = ret_ctype,3739 .ctype = ret_ctype,
3738 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(pt)),3740 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(zcu)),
3739 });3741 });
3740 try writer.writeAll("memcpy(");3742 try writer.writeAll("memcpy(");
3741 try f.writeCValueMember(writer, array_local, .{ .identifier = "array" });3743 try f.writeCValueMember(writer, array_local, .{ .identifier = "array" });
...@@ -3926,7 +3928,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -3926,7 +3928,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3926 }3928 }
39273929
3928 const is_aligned = if (ptr_info.flags.alignment != .none)3930 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)
3930 else3932 else
3931 true;3933 true;
3932 const is_array = lowersToArray(Type.fromInterned(ptr_info.child), pt);3934 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 {...@@ -3976,7 +3978,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3976 const bit_offset_ty = try pt.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));3978 const bit_offset_ty = try pt.intType(.unsigned, Type.smallestUnsignedBits(host_bits - 1));
3977 const bit_offset_val = try pt.intValue(bit_offset_ty, ptr_info.packed_offset.bit_offset);3979 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
3981 const ExpectedContents = [BigInt.Managed.default_capacity]BigIntLimb;3983 const ExpectedContents = [BigInt.Managed.default_capacity]BigIntLimb;
3982 var stack align(@alignOf(ExpectedContents)) =3984 var stack align(@alignOf(ExpectedContents)) =
...@@ -4006,9 +4008,9 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -4006,9 +4008,9 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
4006 try writer.print(", {x}), zig_shl_", .{try f.fmtIntLiteral(mask_val)});4008 try writer.print(", {x}), zig_shl_", .{try f.fmtIntLiteral(mask_val)});
4007 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);4009 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);
4008 try writer.writeByte('(');4010 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;
4010 if (cant_cast) {4012 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", .{});
4012 try writer.writeAll("zig_make_");4014 try writer.writeAll("zig_make_");
4013 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);4015 try f.object.dg.renderTypeForBuiltinFnName(writer, host_ty);
4014 try writer.writeAll("(0, ");4016 try writer.writeAll("(0, ");
...@@ -4130,7 +4132,7 @@ fn airBinOp(...@@ -4130,7 +4132,7 @@ fn airBinOp(
4130 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4132 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4131 const operand_ty = f.typeOf(bin_op.lhs);4133 const operand_ty = f.typeOf(bin_op.lhs);
4132 const scalar_ty = operand_ty.scalarType(zcu);4134 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())
4134 return try airBinBuiltinCall(f, inst, operation, info);4136 return try airBinBuiltinCall(f, inst, operation, info);
41354137
4136 const lhs = try f.resolveInst(bin_op.lhs);4138 const lhs = try f.resolveInst(bin_op.lhs);
...@@ -4169,7 +4171,7 @@ fn airCmpOp(...@@ -4169,7 +4171,7 @@ fn airCmpOp(
4169 const lhs_ty = f.typeOf(data.lhs);4171 const lhs_ty = f.typeOf(data.lhs);
4170 const scalar_ty = lhs_ty.scalarType(zcu);4172 const scalar_ty = lhs_ty.scalarType(zcu);
41714173
4172 const scalar_bits = scalar_ty.bitSize(pt);4174 const scalar_bits = scalar_ty.bitSize(zcu);
4173 if (scalar_ty.isInt(zcu) and scalar_bits > 64)4175 if (scalar_ty.isInt(zcu) and scalar_bits > 64)
4174 return airCmpBuiltinCall(4176 return airCmpBuiltinCall(
4175 f,4177 f,
...@@ -4219,7 +4221,7 @@ fn airEquality(...@@ -4219,7 +4221,7 @@ fn airEquality(
4219 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4221 const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
42204222
4221 const operand_ty = f.typeOf(bin_op.lhs);4223 const operand_ty = f.typeOf(bin_op.lhs);
4222 const operand_bits = operand_ty.bitSize(pt);4224 const operand_bits = operand_ty.bitSize(zcu);
4223 if (operand_ty.isAbiInt(zcu) and operand_bits > 64)4225 if (operand_ty.isAbiInt(zcu) and operand_bits > 64)
4224 return airCmpBuiltinCall(4226 return airCmpBuiltinCall(
4225 f,4227 f,
...@@ -4312,7 +4314,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {...@@ -4312,7 +4314,7 @@ fn airPtrAddSub(f: *Function, inst: Air.Inst.Index, operator: u8) !CValue {
4312 const inst_ty = f.typeOfIndex(inst);4314 const inst_ty = f.typeOfIndex(inst);
4313 const inst_scalar_ty = inst_ty.scalarType(zcu);4315 const inst_scalar_ty = inst_ty.scalarType(zcu);
4314 const elem_ty = inst_scalar_ty.elemType2(zcu);4316 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);
4316 const inst_scalar_ctype = try f.ctypeFromType(inst_scalar_ty, .complete);4318 const inst_scalar_ctype = try f.ctypeFromType(inst_scalar_ty, .complete);
43174319
4318 const local = try f.allocLocal(inst, inst_ty);4320 const local = try f.allocLocal(inst, inst_ty);
...@@ -4351,7 +4353,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons...@@ -4351,7 +4353,7 @@ fn airMinMax(f: *Function, inst: Air.Inst.Index, operator: u8, operation: []cons
4351 const inst_ty = f.typeOfIndex(inst);4353 const inst_ty = f.typeOfIndex(inst);
4352 const inst_scalar_ty = inst_ty.scalarType(zcu);4354 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())
4355 return try airBinBuiltinCall(f, inst, operation, .none);4357 return try airBinBuiltinCall(f, inst, operation, .none);
43564358
4357 const lhs = try f.resolveInst(bin_op.lhs);4359 const lhs = try f.resolveInst(bin_op.lhs);
...@@ -4446,7 +4448,7 @@ fn airCall(...@@ -4446,7 +4448,7 @@ fn airCall(
4446 if (!arg_ctype.eql(try f.ctypeFromType(arg_ty, .complete))) {4448 if (!arg_ctype.eql(try f.ctypeFromType(arg_ty, .complete))) {
4447 const array_local = try f.allocAlignedLocal(inst, .{4449 const array_local = try f.allocAlignedLocal(inst, .{
4448 .ctype = arg_ctype,4450 .ctype = arg_ctype,
4449 .alignas = CType.AlignAs.fromAbiAlignment(arg_ty.abiAlignment(pt)),4451 .alignas = CType.AlignAs.fromAbiAlignment(arg_ty.abiAlignment(zcu)),
4450 });4452 });
4451 try writer.writeAll("memcpy(");4453 try writer.writeAll("memcpy(");
4452 try f.writeCValueMember(writer, array_local, .{ .identifier = "array" });4454 try f.writeCValueMember(writer, array_local, .{ .identifier = "array" });
...@@ -4493,7 +4495,7 @@ fn airCall(...@@ -4493,7 +4495,7 @@ fn airCall(
4493 } else {4495 } else {
4494 const local = try f.allocAlignedLocal(inst, .{4496 const local = try f.allocAlignedLocal(inst, .{
4495 .ctype = ret_ctype,4497 .ctype = ret_ctype,
4496 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(pt)),4498 .alignas = CType.AlignAs.fromAbiAlignment(ret_ty.abiAlignment(zcu)),
4497 });4499 });
4498 try f.writeCValue(writer, local, .Other);4500 try f.writeCValue(writer, local, .Other);
4499 try writer.writeAll(" = ");4501 try writer.writeAll(" = ");
...@@ -4618,7 +4620,7 @@ fn lowerBlock(f: *Function, inst: Air.Inst.Index, body: []const Air.Inst.Index)...@@ -4618,7 +4620,7 @@ fn lowerBlock(f: *Function, inst: Air.Inst.Index, body: []const Air.Inst.Index)
4618 const writer = f.object.writer();4620 const writer = f.object.writer();
46194621
4620 const inst_ty = f.typeOfIndex(inst);4622 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))
4622 try f.allocLocal(inst, inst_ty)4624 try f.allocLocal(inst, inst_ty)
4623 else4625 else
4624 .none;4626 .none;
...@@ -4681,7 +4683,7 @@ fn lowerTry(...@@ -4681,7 +4683,7 @@ fn lowerTry(
4681 const liveness_condbr = f.liveness.getCondBr(inst);4683 const liveness_condbr = f.liveness.getCondBr(inst);
4682 const writer = f.object.writer();4684 const writer = f.object.writer();
4683 const payload_ty = err_union_ty.errorUnionPayload(zcu);4685 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
4686 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {4688 if (!err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
4687 try writer.writeAll("if (");4689 try writer.writeAll("if (");
...@@ -4820,7 +4822,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !CVal...@@ -4820,7 +4822,7 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !CVal
4820 try writer.writeAll(", sizeof(");4822 try writer.writeAll(", sizeof(");
4821 try f.renderType(4823 try f.renderType(
4822 writer,4824 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,
4824 );4826 );
4825 try writer.writeAll("));\n");4827 try writer.writeAll("));\n");
48264828
...@@ -5030,7 +5032,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5030,7 +5032,7 @@ fn airSwitchBr(f: *Function, inst: Air.Inst.Index) !CValue {
5030 try f.object.indent_writer.insertNewline();5032 try f.object.indent_writer.insertNewline();
5031 try writer.writeAll("case ");5033 try writer.writeAll("case ");
5032 const item_value = try f.air.value(item, pt);5034 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", .{
5034 try f.fmtIntLiteral(try pt.intValue(lowered_condition_ty, item_int)),5036 try f.fmtIntLiteral(try pt.intValue(lowered_condition_ty, item_int)),
5035 }) else {5037 }) else {
5036 if (condition_ty.isPtrAtRuntime(zcu)) {5038 if (condition_ty.isPtrAtRuntime(zcu)) {
...@@ -5112,10 +5114,10 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5112,10 +5114,10 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5112 const result = result: {5114 const result = result: {
5113 const writer = f.object.writer();5115 const writer = f.object.writer();
5114 const inst_ty = f.typeOfIndex(inst);5116 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: {
5116 const inst_local = try f.allocLocalValue(.{5118 const inst_local = try f.allocLocalValue(.{
5117 .ctype = try f.ctypeFromType(inst_ty, .complete),5119 .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)),
5119 });5121 });
5120 if (f.wantSafety()) {5122 if (f.wantSafety()) {
5121 try f.writeCValue(writer, inst_local, .Other);5123 try f.writeCValue(writer, inst_local, .Other);
...@@ -5148,7 +5150,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5148,7 +5150,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5148 try writer.writeAll("register ");5150 try writer.writeAll("register ");
5149 const output_local = try f.allocLocalValue(.{5151 const output_local = try f.allocLocalValue(.{
5150 .ctype = try f.ctypeFromType(output_ty, .complete),5152 .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)),
5152 });5154 });
5153 try f.allocs.put(gpa, output_local.new_local, false);5155 try f.allocs.put(gpa, output_local.new_local, false);
5154 try f.object.dg.renderTypeAndName(writer, output_ty, output_local, .{}, .none, .complete);5156 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 {...@@ -5183,7 +5185,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
5183 if (is_reg) try writer.writeAll("register ");5185 if (is_reg) try writer.writeAll("register ");
5184 const input_local = try f.allocLocalValue(.{5186 const input_local = try f.allocLocalValue(.{
5185 .ctype = try f.ctypeFromType(input_ty, .complete),5187 .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)),
5187 });5189 });
5188 try f.allocs.put(gpa, input_local.new_local, false);5190 try f.allocs.put(gpa, input_local.new_local, false);
5189 try f.object.dg.renderTypeAndName(writer, input_ty, input_local, Const, .none, .complete);5191 try f.object.dg.renderTypeAndName(writer, input_ty, input_local, Const, .none, .complete);
...@@ -5526,9 +5528,9 @@ fn fieldLocation(...@@ -5526,9 +5528,9 @@ fn fieldLocation(
5526 .struct_type => {5528 .struct_type => {
5527 const loaded_struct = ip.loadStructType(container_ty.toIntern());5529 const loaded_struct = ip.loadStructType(container_ty.toIntern());
5528 return switch (loaded_struct.layout) {5530 return switch (loaded_struct.layout) {
5529 .auto, .@"extern" => if (!container_ty.hasRuntimeBitsIgnoreComptime(pt))5531 .auto, .@"extern" => if (!container_ty.hasRuntimeBitsIgnoreComptime(zcu))
5530 .begin5532 .begin
5531 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(pt))5533 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))
5532 .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] }5534 .{ .byte_offset = loaded_struct.offsets.get(ip)[field_index] }
5533 else5535 else
5534 .{ .field = if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|5536 .{ .field = if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|
...@@ -5542,10 +5544,10 @@ fn fieldLocation(...@@ -5542,10 +5544,10 @@ fn fieldLocation(
5542 .begin,5544 .begin,
5543 };5545 };
5544 },5546 },
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))
5546 .begin5548 .begin
5547 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(pt))5549 else if (!field_ptr_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu))
5548 .{ .byte_offset = container_ty.structFieldOffset(field_index, pt) }5550 .{ .byte_offset = container_ty.structFieldOffset(field_index, zcu) }
5549 else5551 else
5550 .{ .field = if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|5552 .{ .field = if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|
5551 .{ .identifier = field_name.toSlice(ip) }5553 .{ .identifier = field_name.toSlice(ip) }
...@@ -5556,8 +5558,8 @@ fn fieldLocation(...@@ -5556,8 +5558,8 @@ fn fieldLocation(
5556 switch (loaded_union.flagsUnordered(ip).layout) {5558 switch (loaded_union.flagsUnordered(ip).layout) {
5557 .auto, .@"extern" => {5559 .auto, .@"extern" => {
5558 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);5560 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
5559 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt))5561 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu))
5560 return if (loaded_union.hasTag(ip) and !container_ty.unionHasAllZeroBitFieldTypes(pt))5562 return if (loaded_union.hasTag(ip) and !container_ty.unionHasAllZeroBitFieldTypes(zcu))
5561 .{ .field = .{ .identifier = "payload" } }5563 .{ .field = .{ .identifier = "payload" } }
5562 else5564 else
5563 .begin;5565 .begin;
...@@ -5706,7 +5708,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5706,7 +5708,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5706 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;5708 const extra = f.air.extraData(Air.StructField, ty_pl.payload).data;
57075709
5708 const inst_ty = f.typeOfIndex(inst);5710 const inst_ty = f.typeOfIndex(inst);
5709 if (!inst_ty.hasRuntimeBitsIgnoreComptime(pt)) {5711 if (!inst_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5710 try reap(f, inst, &.{extra.struct_operand});5712 try reap(f, inst, &.{extra.struct_operand});
5711 return .none;5713 return .none;
5712 }5714 }
...@@ -5738,7 +5740,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5738,7 +5740,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5738 inst_ty.intInfo(zcu).signedness5740 inst_ty.intInfo(zcu).signedness
5739 else5741 else
5740 .unsigned;5742 .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
5743 const temp_local = try f.allocLocal(inst, field_int_ty);5745 const temp_local = try f.allocLocal(inst, field_int_ty);
5744 try f.writeCValue(writer, temp_local, .Other);5746 try f.writeCValue(writer, temp_local, .Other);
...@@ -5749,7 +5751,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5749,7 +5751,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5749 try writer.writeByte(')');5751 try writer.writeByte(')');
5750 const cant_cast = int_info.bits > 64;5752 const cant_cast = int_info.bits > 64;
5751 if (cant_cast) {5753 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", .{});
5753 try writer.writeAll("zig_lo_");5755 try writer.writeAll("zig_lo_");
5754 try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty);5756 try f.object.dg.renderTypeForBuiltinFnName(writer, struct_ty);
5755 try writer.writeByte('(');5757 try writer.writeByte('(');
...@@ -5857,7 +5859,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5857,7 +5859,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
5857 const payload_ty = error_union_ty.errorUnionPayload(zcu);5859 const payload_ty = error_union_ty.errorUnionPayload(zcu);
5858 const local = try f.allocLocal(inst, inst_ty);5860 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) {
5861 // The store will be 'x = x'; elide it.5863 // The store will be 'x = x'; elide it.
5862 return local;5864 return local;
5863 }5865 }
...@@ -5866,7 +5868,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5866,7 +5868,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
5866 try f.writeCValue(writer, local, .Other);5868 try f.writeCValue(writer, local, .Other);
5867 try writer.writeAll(" = ");5869 try writer.writeAll(" = ");
58685870
5869 if (!payload_ty.hasRuntimeBits(pt))5871 if (!payload_ty.hasRuntimeBits(zcu))
5870 try f.writeCValue(writer, operand, .Other)5872 try f.writeCValue(writer, operand, .Other)
5871 else if (error_ty.errorSetIsEmpty(zcu))5873 else if (error_ty.errorSetIsEmpty(zcu))
5872 try writer.print("{}", .{5874 try writer.print("{}", .{
...@@ -5892,7 +5894,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu...@@ -5892,7 +5894,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
5892 const error_union_ty = if (is_ptr) operand_ty.childType(zcu) else operand_ty;5894 const error_union_ty = if (is_ptr) operand_ty.childType(zcu) else operand_ty;
58935895
5894 const writer = f.object.writer();5896 const writer = f.object.writer();
5895 if (!error_union_ty.errorUnionPayload(zcu).hasRuntimeBits(pt)) {5897 if (!error_union_ty.errorUnionPayload(zcu).hasRuntimeBits(zcu)) {
5896 if (!is_ptr) return .none;5898 if (!is_ptr) return .none;
58975899
5898 const local = try f.allocLocal(inst, inst_ty);5900 const local = try f.allocLocal(inst, inst_ty);
...@@ -5963,7 +5965,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5963,7 +5965,7 @@ fn airWrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
59635965
5964 const inst_ty = f.typeOfIndex(inst);5966 const inst_ty = f.typeOfIndex(inst);
5965 const payload_ty = inst_ty.errorUnionPayload(zcu);5967 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);
5967 const err_ty = inst_ty.errorUnionSet(zcu);5969 const err_ty = inst_ty.errorUnionSet(zcu);
5968 const err = try f.resolveInst(ty_op.operand);5970 const err = try f.resolveInst(ty_op.operand);
5969 try reap(f, inst, &.{ty_op.operand});5971 try reap(f, inst, &.{ty_op.operand});
...@@ -6012,7 +6014,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6012,7 +6014,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
6012 try reap(f, inst, &.{ty_op.operand});6014 try reap(f, inst, &.{ty_op.operand});
60136015
6014 // First, set the non-error value.6016 // First, set the non-error value.
6015 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {6017 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6016 const a = try Assignment.start(f, writer, try f.ctypeFromType(operand_ty, .complete));6018 const a = try Assignment.start(f, writer, try f.ctypeFromType(operand_ty, .complete));
6017 try f.writeCValueDeref(writer, operand);6019 try f.writeCValueDeref(writer, operand);
6018 try a.assign(f, writer);6020 try a.assign(f, writer);
...@@ -6064,7 +6066,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6064,7 +6066,7 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue {
6064 const inst_ty = f.typeOfIndex(inst);6066 const inst_ty = f.typeOfIndex(inst);
6065 const payload_ty = inst_ty.errorUnionPayload(zcu);6067 const payload_ty = inst_ty.errorUnionPayload(zcu);
6066 const payload = try f.resolveInst(ty_op.operand);6068 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);
6068 const err_ty = inst_ty.errorUnionSet(zcu);6070 const err_ty = inst_ty.errorUnionSet(zcu);
6069 try reap(f, inst, &.{ty_op.operand});6071 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...@@ -6109,7 +6111,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
6109 try a.assign(f, writer);6111 try a.assign(f, writer);
6110 const err_int_ty = try pt.errorIntType();6112 const err_int_ty = try pt.errorIntType();
6111 if (!error_ty.errorSetIsEmpty(zcu))6113 if (!error_ty.errorSetIsEmpty(zcu))
6112 if (payload_ty.hasRuntimeBits(pt))6114 if (payload_ty.hasRuntimeBits(zcu))
6113 if (is_ptr)6115 if (is_ptr)
6114 try f.writeCValueDerefMember(writer, operand, .{ .identifier = "error" })6116 try f.writeCValueDerefMember(writer, operand, .{ .identifier = "error" })
6115 else6117 else
...@@ -6430,7 +6432,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue...@@ -6430,7 +6432,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
6430 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });6432 try reap(f, inst, &.{ extra.ptr, extra.expected_value, extra.new_value });
64316433
6432 const repr_ty = if (ty.isRuntimeFloat())6434 const repr_ty = if (ty.isRuntimeFloat())
6433 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(pt) * 8))) catch unreachable6435 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(zcu) * 8))) catch unreachable
6434 else6436 else
6435 ty;6437 ty;
64366438
...@@ -6534,7 +6536,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6534,7 +6536,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
6534 const operand_mat = try Materialize.start(f, inst, ty, operand);6536 const operand_mat = try Materialize.start(f, inst, ty, operand);
6535 try reap(f, inst, &.{ pl_op.operand, extra.operand });6537 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));
6538 const is_float = ty.isRuntimeFloat();6540 const is_float = ty.isRuntimeFloat();
6539 const is_128 = repr_bits == 128;6541 const is_128 = repr_bits == 128;
6540 const repr_ty = if (is_float) pt.intType(.unsigned, repr_bits) catch unreachable else ty;6542 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 {...@@ -6585,7 +6587,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
6585 const ty = ptr_ty.childType(zcu);6587 const ty = ptr_ty.childType(zcu);
65866588
6587 const repr_ty = if (ty.isRuntimeFloat())6589 const repr_ty = if (ty.isRuntimeFloat())
6588 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(pt) * 8))) catch unreachable6590 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(zcu) * 8))) catch unreachable
6589 else6591 else
6590 ty;6592 ty;
65916593
...@@ -6626,7 +6628,7 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa...@@ -6626,7 +6628,7 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
6626 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6628 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
66276629
6628 const repr_ty = if (ty.isRuntimeFloat())6630 const repr_ty = if (ty.isRuntimeFloat())
6629 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(pt) * 8))) catch unreachable6631 pt.intType(.unsigned, @as(u16, @intCast(ty.abiSize(zcu) * 8))) catch unreachable
6630 else6632 else
6631 ty;6633 ty;
66326634
...@@ -6666,7 +6668,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6666,7 +6668,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6666 const dest_slice = try f.resolveInst(bin_op.lhs);6668 const dest_slice = try f.resolveInst(bin_op.lhs);
6667 const value = try f.resolveInst(bin_op.rhs);6669 const value = try f.resolveInst(bin_op.rhs);
6668 const elem_ty = f.typeOf(bin_op.rhs);6670 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);
6670 const val_is_undef = if (try f.air.value(bin_op.rhs, pt)) |val| val.isUndefDeep(zcu) else false;6672 const val_is_undef = if (try f.air.value(bin_op.rhs, pt)) |val| val.isUndefDeep(zcu) else false;
6671 const writer = f.object.writer();6673 const writer = f.object.writer();
66726674
...@@ -6831,7 +6833,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6831,7 +6833,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
6831 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });6833 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
68326834
6833 const union_ty = f.typeOf(bin_op.lhs).childType(zcu);6835 const union_ty = f.typeOf(bin_op.lhs).childType(zcu);
6834 const layout = union_ty.unionGetLayout(pt);6836 const layout = union_ty.unionGetLayout(zcu);
6835 if (layout.tag_size == 0) return .none;6837 if (layout.tag_size == 0) return .none;
6836 const tag_ty = union_ty.unionTagTypeSafety(zcu).?;6838 const tag_ty = union_ty.unionTagTypeSafety(zcu).?;
68376839
...@@ -6846,13 +6848,14 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6846,13 +6848,14 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
68466848
6847fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {6849fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
6848 const pt = f.object.dg.pt;6850 const pt = f.object.dg.pt;
6851 const zcu = pt.zcu;
6849 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6852 const ty_op = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
68506853
6851 const operand = try f.resolveInst(ty_op.operand);6854 const operand = try f.resolveInst(ty_op.operand);
6852 try reap(f, inst, &.{ty_op.operand});6855 try reap(f, inst, &.{ty_op.operand});
68536856
6854 const union_ty = f.typeOf(ty_op.operand);6857 const union_ty = f.typeOf(ty_op.operand);
6855 const layout = union_ty.unionGetLayout(pt);6858 const layout = union_ty.unionGetLayout(zcu);
6856 if (layout.tag_size == 0) return .none;6859 if (layout.tag_size == 0) return .none;
68576860
6858 const inst_ty = f.typeOfIndex(inst);6861 const inst_ty = f.typeOfIndex(inst);
...@@ -6960,6 +6963,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6960,6 +6963,7 @@ fn airSelect(f: *Function, inst: Air.Inst.Index) !CValue {
69606963
6961fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {6964fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
6962 const pt = f.object.dg.pt;6965 const pt = f.object.dg.pt;
6966 const zcu = pt.zcu;
6963 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6967 const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6964 const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data;6968 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 {...@@ -6978,7 +6982,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
6978 try f.object.dg.renderValue(writer, try pt.intValue(Type.usize, index), .Other);6982 try f.object.dg.renderValue(writer, try pt.intValue(Type.usize, index), .Other);
6979 try writer.writeAll("] = ");6983 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);
6982 const src_val = try pt.intValue(Type.usize, @as(u64, @intCast(mask_elem ^ mask_elem >> 63)));6986 const src_val = try pt.intValue(Type.usize, @as(u64, @intCast(mask_elem ^ mask_elem >> 63)));
69836987
6984 try f.writeCValue(writer, if (mask_elem >= 0) lhs else rhs, .Other);6988 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 {...@@ -7001,7 +7005,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
7001 const operand_ty = f.typeOf(reduce.operand);7005 const operand_ty = f.typeOf(reduce.operand);
7002 const writer = f.object.writer();7006 const writer = f.object.writer();
70037007
7004 const use_operator = scalar_ty.bitSize(pt) <= 64;7008 const use_operator = scalar_ty.bitSize(zcu) <= 64;
7005 const op: union(enum) {7009 const op: union(enum) {
7006 const Func = struct { operation: []const u8, info: BuiltinInfo = .none };7010 const Func = struct { operation: []const u8, info: BuiltinInfo = .none };
7007 builtin: Func,7011 builtin: Func,
...@@ -7178,7 +7182,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7178,7 +7182,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7178 var field_it = loaded_struct.iterateRuntimeOrder(ip);7182 var field_it = loaded_struct.iterateRuntimeOrder(ip);
7179 while (field_it.next()) |field_index| {7183 while (field_it.next()) |field_index| {
7180 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);7184 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
7183 const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));7187 const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));
7184 try f.writeCValueMember(writer, local, if (loaded_struct.fieldName(ip, field_index).unwrap()) |field_name|7188 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 {...@@ -7202,8 +7206,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7202 var empty = true;7206 var empty = true;
7203 for (0..elements.len) |field_index| {7207 for (0..elements.len) |field_index| {
7204 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;7208 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;
7205 const field_ty = inst_ty.structFieldType(field_index, zcu);7209 const field_ty = inst_ty.fieldType(field_index, zcu);
7206 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;7210 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
72077211
7208 if (!empty) {7212 if (!empty) {
7209 try writer.writeAll("zig_or_");7213 try writer.writeAll("zig_or_");
...@@ -7215,8 +7219,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7215,8 +7219,8 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7215 empty = true;7219 empty = true;
7216 for (resolved_elements, 0..) |element, field_index| {7220 for (resolved_elements, 0..) |element, field_index| {
7217 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;7221 if (inst_ty.structFieldIsComptime(field_index, zcu)) continue;
7218 const field_ty = inst_ty.structFieldType(field_index, zcu);7222 const field_ty = inst_ty.fieldType(field_index, zcu);
7219 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;7223 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
72207224
7221 if (!empty) try writer.writeAll(", ");7225 if (!empty) try writer.writeAll(", ");
7222 // TODO: Skip this entire shift if val is 0?7226 // TODO: Skip this entire shift if val is 0?
...@@ -7248,7 +7252,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7248,7 +7252,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7248 try writer.writeByte(')');7252 try writer.writeByte(')');
7249 if (!empty) try writer.writeByte(')');7253 if (!empty) try writer.writeByte(')');
72507254
7251 bit_offset += field_ty.bitSize(pt);7255 bit_offset += field_ty.bitSize(zcu);
7252 empty = false;7256 empty = false;
7253 }7257 }
7254 try writer.writeAll(";\n");7258 try writer.writeAll(";\n");
...@@ -7258,7 +7262,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7258,7 +7262,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
7258 .anon_struct_type => |anon_struct_info| for (0..anon_struct_info.types.len) |field_index| {7262 .anon_struct_type => |anon_struct_info| for (0..anon_struct_info.types.len) |field_index| {
7259 if (anon_struct_info.values.get(ip)[field_index] != .none) continue;7263 if (anon_struct_info.values.get(ip)[field_index] != .none) continue;
7260 const field_ty = Type.fromInterned(anon_struct_info.types.get(ip)[field_index]);7264 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
7263 const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));7267 const a = try Assignment.start(f, writer, try f.ctypeFromType(field_ty, .complete));
7264 try f.writeCValueMember(writer, local, if (anon_struct_info.fieldName(ip, field_index).unwrap()) |field_name|7268 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 {...@@ -7294,7 +7298,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
7294 if (loaded_union.flagsUnordered(ip).layout == .@"packed") return f.moveCValue(inst, union_ty, payload);7298 if (loaded_union.flagsUnordered(ip).layout == .@"packed") return f.moveCValue(inst, union_ty, payload);
72957299
7296 const field: CValue = if (union_ty.unionTagTypeSafety(zcu)) |tag_ty| field: {7300 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);
7298 if (layout.tag_size != 0) {7302 if (layout.tag_size != 0) {
7299 const field_index = tag_ty.enumFieldIndex(field_name, zcu).?;7303 const field_index = tag_ty.enumFieldIndex(field_name, zcu).?;
7300 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);7304 const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index);
...@@ -7818,7 +7822,7 @@ fn formatIntLiteral(...@@ -7818,7 +7822,7 @@ fn formatIntLiteral(
7818 };7822 };
7819 undef_int.truncate(undef_int.toConst(), data.int_info.signedness, data.int_info.bits);7823 undef_int.truncate(undef_int.toConst(), data.int_info.signedness, data.int_info.bits);
7820 break :blk undef_int.toConst();7824 break :blk undef_int.toConst();
7821 } else data.val.toBigInt(&int_buf, pt);7825 } else data.val.toBigInt(&int_buf, zcu);
7822 assert(int.fitsInTwosComp(data.int_info.signedness, data.int_info.bits));7826 assert(int.fitsInTwosComp(data.int_info.signedness, data.int_info.bits));
78237827
7824 const c_bits: usize = @intCast(data.ctype.byteSize(ctype_pool, data.dg.mod) * 8);7828 const c_bits: usize = @intCast(data.ctype.byteSize(ctype_pool, data.dg.mod) * 8);
...@@ -8062,9 +8066,10 @@ const Vectorize = struct {...@@ -8062,9 +8066,10 @@ const Vectorize = struct {
8062};8066};
80638067
8064fn lowersToArray(ty: Type, pt: Zcu.PerThread) bool {8068fn 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)) {
8066 .Array, .Vector => return true,8071 .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,
8068 };8073 };
8069}8074}
80708075
src/codegen/c/Type.zig+13-12
...@@ -1344,6 +1344,7 @@ pub const Pool = struct {...@@ -1344,6 +1344,7 @@ pub const Pool = struct {
1344 kind: Kind,1344 kind: Kind,
1345 ) !CType {1345 ) !CType {
1346 const ip = &pt.zcu.intern_pool;1346 const ip = &pt.zcu.intern_pool;
1347 const zcu = pt.zcu;
1347 switch (ty.toIntern()) {1348 switch (ty.toIntern()) {
1348 .u0_type,1349 .u0_type,
1349 .i0_type,1350 .i0_type,
...@@ -1476,7 +1477,7 @@ pub const Pool = struct {...@@ -1476,7 +1477,7 @@ pub const Pool = struct {
1476 ),1477 ),
1477 .alignas = AlignAs.fromAlignment(.{1478 .alignas = AlignAs.fromAlignment(.{
1478 .@"align" = ptr_info.flags.alignment,1479 .@"align" = ptr_info.flags.alignment,
1479 .abi = Type.fromInterned(ptr_info.child).abiAlignment(pt),1480 .abi = Type.fromInterned(ptr_info.child).abiAlignment(zcu),
1480 }),1481 }),
1481 };1482 };
1482 break :elem_ctype if (elem.alignas.abiOrder().compare(.gte))1483 break :elem_ctype if (elem.alignas.abiOrder().compare(.gte))
...@@ -1552,7 +1553,7 @@ pub const Pool = struct {...@@ -1552,7 +1553,7 @@ pub const Pool = struct {
1552 .{1553 .{
1553 .name = .{ .index = .array },1554 .name = .{ .index = .array },
1554 .ctype = array_ctype,1555 .ctype = array_ctype,
1555 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(pt)),1556 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(zcu)),
1556 },1557 },
1557 };1558 };
1558 return pool.fromFields(allocator, .@"struct", &fields, kind);1559 return pool.fromFields(allocator, .@"struct", &fields, kind);
...@@ -1578,7 +1579,7 @@ pub const Pool = struct {...@@ -1578,7 +1579,7 @@ pub const Pool = struct {
1578 .{1579 .{
1579 .name = .{ .index = .array },1580 .name = .{ .index = .array },
1580 .ctype = vector_ctype,1581 .ctype = vector_ctype,
1581 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(pt)),1582 .alignas = AlignAs.fromAbiAlignment(elem_type.abiAlignment(zcu)),
1582 },1583 },
1583 };1584 };
1584 return pool.fromFields(allocator, .@"struct", &fields, kind);1585 return pool.fromFields(allocator, .@"struct", &fields, kind);
...@@ -1613,7 +1614,7 @@ pub const Pool = struct {...@@ -1613,7 +1614,7 @@ pub const Pool = struct {
1613 .name = .{ .index = .payload },1614 .name = .{ .index = .payload },
1614 .ctype = payload_ctype,1615 .ctype = payload_ctype,
1615 .alignas = AlignAs.fromAbiAlignment(1616 .alignas = AlignAs.fromAbiAlignment(
1616 Type.fromInterned(payload_type).abiAlignment(pt),1617 Type.fromInterned(payload_type).abiAlignment(zcu),
1617 ),1618 ),
1618 },1619 },
1619 };1620 };
...@@ -1649,7 +1650,7 @@ pub const Pool = struct {...@@ -1649,7 +1650,7 @@ pub const Pool = struct {
1649 .{1650 .{
1650 .name = .{ .index = .payload },1651 .name = .{ .index = .payload },
1651 .ctype = payload_ctype,1652 .ctype = payload_ctype,
1652 .alignas = AlignAs.fromAbiAlignment(payload_type.abiAlignment(pt)),1653 .alignas = AlignAs.fromAbiAlignment(payload_type.abiAlignment(zcu)),
1653 },1654 },
1654 };1655 };
1655 return pool.fromFields(allocator, .@"struct", &fields, kind);1656 return pool.fromFields(allocator, .@"struct", &fields, kind);
...@@ -1663,7 +1664,7 @@ pub const Pool = struct {...@@ -1663,7 +1664,7 @@ pub const Pool = struct {
1663 .tag = .@"struct",1664 .tag = .@"struct",
1664 .name = .{ .index = ip_index },1665 .name = .{ .index = ip_index },
1665 });1666 });
1666 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(pt))1667 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
1667 fwd_decl1668 fwd_decl
1668 else1669 else
1669 CType.void;1670 CType.void;
...@@ -1696,7 +1697,7 @@ pub const Pool = struct {...@@ -1696,7 +1697,7 @@ pub const Pool = struct {
1696 String.fromUnnamed(@intCast(field_index));1697 String.fromUnnamed(@intCast(field_index));
1697 const field_alignas = AlignAs.fromAlignment(.{1698 const field_alignas = AlignAs.fromAlignment(.{
1698 .@"align" = loaded_struct.fieldAlign(ip, field_index),1699 .@"align" = loaded_struct.fieldAlign(ip, field_index),
1699 .abi = field_type.abiAlignment(pt),1700 .abi = field_type.abiAlignment(zcu),
1700 });1701 });
1701 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{1702 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
1702 .name = field_name.index,1703 .name = field_name.index,
...@@ -1758,7 +1759,7 @@ pub const Pool = struct {...@@ -1758,7 +1759,7 @@ pub const Pool = struct {
1758 .name = field_name.index,1759 .name = field_name.index,
1759 .ctype = field_ctype.index,1760 .ctype = field_ctype.index,
1760 .flags = .{ .alignas = AlignAs.fromAbiAlignment(1761 .flags = .{ .alignas = AlignAs.fromAbiAlignment(
1761 field_type.abiAlignment(pt),1762 field_type.abiAlignment(zcu),
1762 ) },1763 ) },
1763 });1764 });
1764 }1765 }
...@@ -1802,7 +1803,7 @@ pub const Pool = struct {...@@ -1802,7 +1803,7 @@ pub const Pool = struct {
1802 .tag = if (has_tag) .@"struct" else .@"union",1803 .tag = if (has_tag) .@"struct" else .@"union",
1803 .name = .{ .index = ip_index },1804 .name = .{ .index = ip_index },
1804 });1805 });
1805 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(pt))1806 if (kind.isForward()) return if (ty.hasRuntimeBitsIgnoreComptime(zcu))
1806 fwd_decl1807 fwd_decl
1807 else1808 else
1808 CType.void;1809 CType.void;
...@@ -1836,7 +1837,7 @@ pub const Pool = struct {...@@ -1836,7 +1837,7 @@ pub const Pool = struct {
1836 );1837 );
1837 const field_alignas = AlignAs.fromAlignment(.{1838 const field_alignas = AlignAs.fromAlignment(.{
1838 .@"align" = loaded_union.fieldAlign(ip, field_index),1839 .@"align" = loaded_union.fieldAlign(ip, field_index),
1839 .abi = field_type.abiAlignment(pt),1840 .abi = field_type.abiAlignment(zcu),
1840 });1841 });
1841 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{1842 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
1842 .name = field_name.index,1843 .name = field_name.index,
...@@ -1881,7 +1882,7 @@ pub const Pool = struct {...@@ -1881,7 +1882,7 @@ pub const Pool = struct {
1881 struct_fields[struct_fields_len] = .{1882 struct_fields[struct_fields_len] = .{
1882 .name = .{ .index = .tag },1883 .name = .{ .index = .tag },
1883 .ctype = tag_ctype,1884 .ctype = tag_ctype,
1884 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(pt)),1885 .alignas = AlignAs.fromAbiAlignment(tag_type.abiAlignment(zcu)),
1885 };1886 };
1886 struct_fields_len += 1;1887 struct_fields_len += 1;
1887 }1888 }
...@@ -1929,7 +1930,7 @@ pub const Pool = struct {...@@ -1929,7 +1930,7 @@ pub const Pool = struct {
1929 },1930 },
1930 .@"packed" => return pool.fromIntInfo(allocator, .{1931 .@"packed" => return pool.fromIntInfo(allocator, .{
1931 .signedness = .unsigned,1932 .signedness = .unsigned,
1932 .bits = @intCast(ty.bitSize(pt)),1933 .bits = @intCast(ty.bitSize(zcu)),
1933 }, mod, kind),1934 }, mod, kind),
1934 }1935 }
1935 },1936 },
src/codegen/llvm.zig+846-851
...@@ -864,7 +864,7 @@ pub const Object = struct {...@@ -864,7 +864,7 @@ pub const Object = struct {
864 // into the garbage can by converting into absolute paths. What864 // into the garbage can by converting into absolute paths. What
865 // a terrible tragedy.865 // a terrible tragedy.
866 const compile_unit_dir = blk: {866 const compile_unit_dir = blk: {
867 if (comp.module) |zcu| m: {867 if (comp.zcu) |zcu| m: {
868 const d = try zcu.main_mod.root.joinString(arena, "");868 const d = try zcu.main_mod.root.joinString(arena, "");
869 if (d.len == 0) break :m;869 if (d.len == 0) break :m;
870 if (std.fs.path.isAbsolute(d)) break :blk d;870 if (std.fs.path.isAbsolute(d)) break :blk d;
...@@ -955,7 +955,7 @@ pub const Object = struct {...@@ -955,7 +955,7 @@ pub const Object = struct {
955 .gpa = gpa,955 .gpa = gpa,
956 .builder = builder,956 .builder = builder,
957 .pt = .{957 .pt = .{
958 .zcu = comp.module.?,958 .zcu = comp.zcu.?,
959 .tid = .main,959 .tid = .main,
960 },960 },
961 .debug_compile_unit = debug_compile_unit,961 .debug_compile_unit = debug_compile_unit,
...@@ -1001,12 +1001,12 @@ pub const Object = struct {...@@ -1001,12 +1001,12 @@ pub const Object = struct {
1001 if (o.error_name_table == .none) return;1001 if (o.error_name_table == .none) return;
10021002
1003 const pt = o.pt;1003 const pt = o.pt;
1004 const mod = pt.zcu;1004 const zcu = pt.zcu;
1005 const ip = &mod.intern_pool;1005 const ip = &zcu.intern_pool;
10061006
1007 const error_name_list = ip.global_error_set.getNamesFromMainThread();1007 const error_name_list = ip.global_error_set.getNamesFromMainThread();
1008 const llvm_errors = try mod.gpa.alloc(Builder.Constant, 1 + error_name_list.len);1008 const llvm_errors = try zcu.gpa.alloc(Builder.Constant, 1 + error_name_list.len);
1009 defer mod.gpa.free(llvm_errors);1009 defer zcu.gpa.free(llvm_errors);
10101010
1011 // TODO: Address space1011 // TODO: Address space
1012 const slice_ty = Type.slice_const_u8_sentinel_0;1012 const slice_ty = Type.slice_const_u8_sentinel_0;
...@@ -1041,7 +1041,7 @@ pub const Object = struct {...@@ -1041,7 +1041,7 @@ pub const Object = struct {
1041 table_variable_index.setMutability(.constant, &o.builder);1041 table_variable_index.setMutability(.constant, &o.builder);
1042 table_variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);1042 table_variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
1043 table_variable_index.setAlignment(1043 table_variable_index.setAlignment(
1044 slice_ty.abiAlignment(pt).toLlvm(),1044 slice_ty.abiAlignment(zcu).toLlvm(),
1045 &o.builder,1045 &o.builder,
1046 );1046 );
10471047
...@@ -1428,7 +1428,7 @@ pub const Object = struct {...@@ -1428,7 +1428,7 @@ pub const Object = struct {
1428 var llvm_arg_i: u32 = 0;1428 var llvm_arg_i: u32 = 0;
14291429
1430 // This gets the LLVM values from the function and stores them in `ng.args`.1430 // 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);
1432 const ret_ptr: Builder.Value = if (sret) param: {1432 const ret_ptr: Builder.Value = if (sret) param: {
1433 const param = wip.arg(llvm_arg_i);1433 const param = wip.arg(llvm_arg_i);
1434 llvm_arg_i += 1;1434 llvm_arg_i += 1;
...@@ -1469,8 +1469,8 @@ pub const Object = struct {...@@ -1469,8 +1469,8 @@ pub const Object = struct {
1469 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);1469 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
1470 const param = wip.arg(llvm_arg_i);1470 const param = wip.arg(llvm_arg_i);
14711471
1472 if (isByRef(param_ty, pt)) {1472 if (isByRef(param_ty, zcu)) {
1473 const alignment = param_ty.abiAlignment(pt).toLlvm();1473 const alignment = param_ty.abiAlignment(zcu).toLlvm();
1474 const param_llvm_ty = param.typeOfWip(&wip);1474 const param_llvm_ty = param.typeOfWip(&wip);
1475 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);1475 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
1476 _ = try wip.store(.normal, param, arg_ptr, alignment);1476 _ = try wip.store(.normal, param, arg_ptr, alignment);
...@@ -1486,12 +1486,12 @@ pub const Object = struct {...@@ -1486,12 +1486,12 @@ pub const Object = struct {
1486 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1486 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1487 const param_llvm_ty = try o.lowerType(param_ty);1487 const param_llvm_ty = try o.lowerType(param_ty);
1488 const param = wip.arg(llvm_arg_i);1488 const param = wip.arg(llvm_arg_i);
1489 const alignment = param_ty.abiAlignment(pt).toLlvm();1489 const alignment = param_ty.abiAlignment(zcu).toLlvm();
14901490
1491 try o.addByRefParamAttrs(&attributes, llvm_arg_i, alignment, it.byval_attr, param_llvm_ty);1491 try o.addByRefParamAttrs(&attributes, llvm_arg_i, alignment, it.byval_attr, param_llvm_ty);
1492 llvm_arg_i += 1;1492 llvm_arg_i += 1;
14931493
1494 if (isByRef(param_ty, pt)) {1494 if (isByRef(param_ty, zcu)) {
1495 args.appendAssumeCapacity(param);1495 args.appendAssumeCapacity(param);
1496 } else {1496 } else {
1497 args.appendAssumeCapacity(try wip.load(.normal, param_llvm_ty, param, alignment, ""));1497 args.appendAssumeCapacity(try wip.load(.normal, param_llvm_ty, param, alignment, ""));
...@@ -1501,12 +1501,12 @@ pub const Object = struct {...@@ -1501,12 +1501,12 @@ pub const Object = struct {
1501 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1501 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1502 const param_llvm_ty = try o.lowerType(param_ty);1502 const param_llvm_ty = try o.lowerType(param_ty);
1503 const param = wip.arg(llvm_arg_i);1503 const param = wip.arg(llvm_arg_i);
1504 const alignment = param_ty.abiAlignment(pt).toLlvm();1504 const alignment = param_ty.abiAlignment(zcu).toLlvm();
15051505
1506 try attributes.addParamAttr(llvm_arg_i, .noundef, &o.builder);1506 try attributes.addParamAttr(llvm_arg_i, .noundef, &o.builder);
1507 llvm_arg_i += 1;1507 llvm_arg_i += 1;
15081508
1509 if (isByRef(param_ty, pt)) {1509 if (isByRef(param_ty, zcu)) {
1510 args.appendAssumeCapacity(param);1510 args.appendAssumeCapacity(param);
1511 } else {1511 } else {
1512 args.appendAssumeCapacity(try wip.load(.normal, param_llvm_ty, param, alignment, ""));1512 args.appendAssumeCapacity(try wip.load(.normal, param_llvm_ty, param, alignment, ""));
...@@ -1519,11 +1519,11 @@ pub const Object = struct {...@@ -1519,11 +1519,11 @@ pub const Object = struct {
1519 llvm_arg_i += 1;1519 llvm_arg_i += 1;
15201520
1521 const param_llvm_ty = try o.lowerType(param_ty);1521 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();
1523 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);1523 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
1524 _ = try wip.store(.normal, param, arg_ptr, alignment);1524 _ = 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))
1527 arg_ptr1527 arg_ptr
1528 else1528 else
1529 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));1529 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
...@@ -1547,7 +1547,7 @@ pub const Object = struct {...@@ -1547,7 +1547,7 @@ pub const Object = struct {
1547 const elem_align = (if (ptr_info.flags.alignment != .none)1547 const elem_align = (if (ptr_info.flags.alignment != .none)
1548 @as(InternPool.Alignment, ptr_info.flags.alignment)1548 @as(InternPool.Alignment, ptr_info.flags.alignment)
1549 else1549 else
1550 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1")).toLlvm();1550 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1")).toLlvm();
1551 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);1551 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
1552 const ptr_param = wip.arg(llvm_arg_i);1552 const ptr_param = wip.arg(llvm_arg_i);
1553 llvm_arg_i += 1;1553 llvm_arg_i += 1;
...@@ -1564,7 +1564,7 @@ pub const Object = struct {...@@ -1564,7 +1564,7 @@ pub const Object = struct {
1564 const field_types = it.types_buffer[0..it.types_len];1564 const field_types = it.types_buffer[0..it.types_len];
1565 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);1565 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
1566 const param_llvm_ty = try o.lowerType(param_ty);1566 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();
1568 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, param_alignment, target);1568 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, param_alignment, target);
1569 const llvm_ty = try o.builder.structType(.normal, field_types);1569 const llvm_ty = try o.builder.structType(.normal, field_types);
1570 for (0..field_types.len) |field_i| {1570 for (0..field_types.len) |field_i| {
...@@ -1576,7 +1576,7 @@ pub const Object = struct {...@@ -1576,7 +1576,7 @@ pub const Object = struct {
1576 _ = try wip.store(.normal, param, field_ptr, alignment);1576 _ = try wip.store(.normal, param, field_ptr, alignment);
1577 }1577 }
15781578
1579 const is_by_ref = isByRef(param_ty, pt);1579 const is_by_ref = isByRef(param_ty, zcu);
1580 args.appendAssumeCapacity(if (is_by_ref)1580 args.appendAssumeCapacity(if (is_by_ref)
1581 arg_ptr1581 arg_ptr
1582 else1582 else
...@@ -1594,11 +1594,11 @@ pub const Object = struct {...@@ -1594,11 +1594,11 @@ pub const Object = struct {
1594 const param = wip.arg(llvm_arg_i);1594 const param = wip.arg(llvm_arg_i);
1595 llvm_arg_i += 1;1595 llvm_arg_i += 1;
15961596
1597 const alignment = param_ty.abiAlignment(pt).toLlvm();1597 const alignment = param_ty.abiAlignment(zcu).toLlvm();
1598 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);1598 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
1599 _ = try wip.store(.normal, param, arg_ptr, alignment);1599 _ = 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))
1602 arg_ptr1602 arg_ptr
1603 else1603 else
1604 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));1604 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
...@@ -1609,11 +1609,11 @@ pub const Object = struct {...@@ -1609,11 +1609,11 @@ pub const Object = struct {
1609 const param = wip.arg(llvm_arg_i);1609 const param = wip.arg(llvm_arg_i);
1610 llvm_arg_i += 1;1610 llvm_arg_i += 1;
16111611
1612 const alignment = param_ty.abiAlignment(pt).toLlvm();1612 const alignment = param_ty.abiAlignment(zcu).toLlvm();
1613 const arg_ptr = try buildAllocaInner(&wip, param.typeOfWip(&wip), alignment, target);1613 const arg_ptr = try buildAllocaInner(&wip, param.typeOfWip(&wip), alignment, target);
1614 _ = try wip.store(.normal, param, arg_ptr, alignment);1614 _ = 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))
1617 arg_ptr1617 arg_ptr
1618 else1618 else
1619 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));1619 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
...@@ -1738,13 +1738,13 @@ pub const Object = struct {...@@ -1738,13 +1738,13 @@ pub const Object = struct {
17381738
1739 fn updateExportedValue(1739 fn updateExportedValue(
1740 o: *Object,1740 o: *Object,
1741 mod: *Zcu,1741 zcu: *Zcu,
1742 exported_value: InternPool.Index,1742 exported_value: InternPool.Index,
1743 export_indices: []const u32,1743 export_indices: []const u32,
1744 ) link.File.UpdateExportsError!void {1744 ) link.File.UpdateExportsError!void {
1745 const gpa = mod.gpa;1745 const gpa = zcu.gpa;
1746 const ip = &mod.intern_pool;1746 const ip = &zcu.intern_pool;
1747 const main_exp_name = try o.builder.strtabString(mod.all_exports.items[export_indices[0]].opts.name.toSlice(ip));1747 const main_exp_name = try o.builder.strtabString(zcu.all_exports.items[export_indices[0]].opts.name.toSlice(ip));
1748 const global_index = i: {1748 const global_index = i: {
1749 const gop = try o.uav_map.getOrPut(gpa, exported_value);1749 const gop = try o.uav_map.getOrPut(gpa, exported_value);
1750 if (gop.found_existing) {1750 if (gop.found_existing) {
...@@ -1768,18 +1768,18 @@ pub const Object = struct {...@@ -1768,18 +1768,18 @@ pub const Object = struct {
1768 try variable_index.setInitializer(init_val, &o.builder);1768 try variable_index.setInitializer(init_val, &o.builder);
1769 break :i global_index;1769 break :i global_index;
1770 };1770 };
1771 return updateExportedGlobal(o, mod, global_index, export_indices);1771 return updateExportedGlobal(o, zcu, global_index, export_indices);
1772 }1772 }
17731773
1774 fn updateExportedGlobal(1774 fn updateExportedGlobal(
1775 o: *Object,1775 o: *Object,
1776 mod: *Zcu,1776 zcu: *Zcu,
1777 global_index: Builder.Global.Index,1777 global_index: Builder.Global.Index,
1778 export_indices: []const u32,1778 export_indices: []const u32,
1779 ) link.File.UpdateExportsError!void {1779 ) link.File.UpdateExportsError!void {
1780 const comp = mod.comp;1780 const comp = zcu.comp;
1781 const ip = &mod.intern_pool;1781 const ip = &zcu.intern_pool;
1782 const first_export = mod.all_exports.items[export_indices[0]];1782 const first_export = zcu.all_exports.items[export_indices[0]];
17831783
1784 // We will rename this global to have a name matching `first_export`.1784 // We will rename this global to have a name matching `first_export`.
1785 // Successive exports become aliases.1785 // Successive exports become aliases.
...@@ -1836,7 +1836,7 @@ pub const Object = struct {...@@ -1836,7 +1836,7 @@ pub const Object = struct {
1836 // Until then we iterate over existing aliases and make them point1836 // Until then we iterate over existing aliases and make them point
1837 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.1837 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.
1838 for (export_indices[1..]) |export_idx| {1838 for (export_indices[1..]) |export_idx| {
1839 const exp = mod.all_exports.items[export_idx];1839 const exp = zcu.all_exports.items[export_idx];
1840 const exp_name = try o.builder.strtabString(exp.opts.name.toSlice(ip));1840 const exp_name = try o.builder.strtabString(exp.opts.name.toSlice(ip));
1841 if (o.builder.getGlobal(exp_name)) |global| {1841 if (o.builder.getGlobal(exp_name)) |global| {
1842 switch (global.ptrConst(&o.builder).kind) {1842 switch (global.ptrConst(&o.builder).kind) {
...@@ -1923,7 +1923,7 @@ pub const Object = struct {...@@ -1923,7 +1923,7 @@ pub const Object = struct {
1923 const name = try o.allocTypeName(ty);1923 const name = try o.allocTypeName(ty);
1924 defer gpa.free(name);1924 defer gpa.free(name);
1925 const builder_name = try o.builder.metadataString(name);1925 const builder_name = try o.builder.metadataString(name);
1926 const debug_bits = ty.abiSize(pt) * 8; // lldb cannot handle non-byte sized types1926 const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types
1927 const debug_int_type = switch (info.signedness) {1927 const debug_int_type = switch (info.signedness) {
1928 .signed => try o.builder.debugSignedType(builder_name, debug_bits),1928 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
1929 .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),1929 .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),
...@@ -1932,7 +1932,7 @@ pub const Object = struct {...@@ -1932,7 +1932,7 @@ pub const Object = struct {
1932 return debug_int_type;1932 return debug_int_type;
1933 },1933 },
1934 .Enum => {1934 .Enum => {
1935 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {1935 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1936 const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty);1936 const debug_enum_type = try o.makeEmptyNamespaceDebugType(ty);
1937 try o.debug_type_map.put(gpa, ty, debug_enum_type);1937 try o.debug_type_map.put(gpa, ty, debug_enum_type);
1938 return debug_enum_type;1938 return debug_enum_type;
...@@ -1949,7 +1949,7 @@ pub const Object = struct {...@@ -1949,7 +1949,7 @@ pub const Object = struct {
1949 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {1949 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
1950 var bigint_space: Value.BigIntSpace = undefined;1950 var bigint_space: Value.BigIntSpace = undefined;
1951 const bigint = if (enum_type.values.len != 0)1951 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)
1953 else1953 else
1954 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();1954 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
19551955
...@@ -1976,8 +1976,8 @@ pub const Object = struct {...@@ -1976,8 +1976,8 @@ pub const Object = struct {
1976 scope,1976 scope,
1977 ty.typeDeclSrcLine(zcu).? + 1, // Line1977 ty.typeDeclSrcLine(zcu).? + 1, // Line
1978 try o.lowerDebugType(int_ty),1978 try o.lowerDebugType(int_ty),
1979 ty.abiSize(pt) * 8,1979 ty.abiSize(zcu) * 8,
1980 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,1980 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
1981 try o.builder.debugTuple(enumerators),1981 try o.builder.debugTuple(enumerators),
1982 );1982 );
19831983
...@@ -2017,10 +2017,10 @@ pub const Object = struct {...@@ -2017,10 +2017,10 @@ pub const Object = struct {
2017 ptr_info.flags.is_const or2017 ptr_info.flags.is_const or
2018 ptr_info.flags.is_volatile or2018 ptr_info.flags.is_volatile or
2019 ptr_info.flags.size == .Many or ptr_info.flags.size == .C or2019 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))
2021 {2021 {
2022 const bland_ptr_ty = try pt.ptrType(.{2022 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))
2024 .anyopaque_type2024 .anyopaque_type
2025 else2025 else
2026 ptr_info.child,2026 ptr_info.child,
...@@ -2050,10 +2050,10 @@ pub const Object = struct {...@@ -2050,10 +2050,10 @@ pub const Object = struct {
2050 defer gpa.free(name);2050 defer gpa.free(name);
2051 const line = 0;2051 const line = 0;
20522052
2053 const ptr_size = ptr_ty.abiSize(pt);2053 const ptr_size = ptr_ty.abiSize(zcu);
2054 const ptr_align = ptr_ty.abiAlignment(pt);2054 const ptr_align = ptr_ty.abiAlignment(zcu);
2055 const len_size = len_ty.abiSize(pt);2055 const len_size = len_ty.abiSize(zcu);
2056 const len_align = len_ty.abiAlignment(pt);2056 const len_align = len_ty.abiAlignment(zcu);
20572057
2058 const len_offset = len_align.forward(ptr_size);2058 const len_offset = len_align.forward(ptr_size);
20592059
...@@ -2085,8 +2085,8 @@ pub const Object = struct {...@@ -2085,8 +2085,8 @@ pub const Object = struct {
2085 o.debug_compile_unit, // Scope2085 o.debug_compile_unit, // Scope
2086 line,2086 line,
2087 .none, // Underlying type2087 .none, // Underlying type
2088 ty.abiSize(pt) * 8,2088 ty.abiSize(zcu) * 8,
2089 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2089 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2090 try o.builder.debugTuple(&.{2090 try o.builder.debugTuple(&.{
2091 debug_ptr_type,2091 debug_ptr_type,
2092 debug_len_type,2092 debug_len_type,
...@@ -2114,7 +2114,7 @@ pub const Object = struct {...@@ -2114,7 +2114,7 @@ pub const Object = struct {
2114 0, // Line2114 0, // Line
2115 debug_elem_ty,2115 debug_elem_ty,
2116 target.ptrBitWidth(),2116 target.ptrBitWidth(),
2117 (ty.ptrAlignment(pt).toByteUnits() orelse 0) * 8,2117 (ty.ptrAlignment(zcu).toByteUnits() orelse 0) * 8,
2118 0, // Offset2118 0, // Offset
2119 );2119 );
21202120
...@@ -2165,8 +2165,8 @@ pub const Object = struct {...@@ -2165,8 +2165,8 @@ pub const Object = struct {
2165 .none, // Scope2165 .none, // Scope
2166 0, // Line2166 0, // Line
2167 try o.lowerDebugType(ty.childType(zcu)),2167 try o.lowerDebugType(ty.childType(zcu)),
2168 ty.abiSize(pt) * 8,2168 ty.abiSize(zcu) * 8,
2169 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2169 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2170 try o.builder.debugTuple(&.{2170 try o.builder.debugTuple(&.{
2171 try o.builder.debugSubrange(2171 try o.builder.debugSubrange(
2172 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),2172 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
...@@ -2208,8 +2208,8 @@ pub const Object = struct {...@@ -2208,8 +2208,8 @@ pub const Object = struct {
2208 .none, // Scope2208 .none, // Scope
2209 0, // Line2209 0, // Line
2210 debug_elem_type,2210 debug_elem_type,
2211 ty.abiSize(pt) * 8,2211 ty.abiSize(zcu) * 8,
2212 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2212 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2213 try o.builder.debugTuple(&.{2213 try o.builder.debugTuple(&.{
2214 try o.builder.debugSubrange(2214 try o.builder.debugSubrange(
2215 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),2215 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
...@@ -2225,7 +2225,7 @@ pub const Object = struct {...@@ -2225,7 +2225,7 @@ pub const Object = struct {
2225 const name = try o.allocTypeName(ty);2225 const name = try o.allocTypeName(ty);
2226 defer gpa.free(name);2226 defer gpa.free(name);
2227 const child_ty = ty.optionalChild(zcu);2227 const child_ty = ty.optionalChild(zcu);
2228 if (!child_ty.hasRuntimeBitsIgnoreComptime(pt)) {2228 if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2229 const debug_bool_type = try o.builder.debugBoolType(2229 const debug_bool_type = try o.builder.debugBoolType(
2230 try o.builder.metadataString(name),2230 try o.builder.metadataString(name),
2231 8,2231 8,
...@@ -2252,10 +2252,10 @@ pub const Object = struct {...@@ -2252,10 +2252,10 @@ pub const Object = struct {
2252 }2252 }
22532253
2254 const non_null_ty = Type.u8;2254 const non_null_ty = Type.u8;
2255 const payload_size = child_ty.abiSize(pt);2255 const payload_size = child_ty.abiSize(zcu);
2256 const payload_align = child_ty.abiAlignment(pt);2256 const payload_align = child_ty.abiAlignment(zcu);
2257 const non_null_size = non_null_ty.abiSize(pt);2257 const non_null_size = non_null_ty.abiSize(zcu);
2258 const non_null_align = non_null_ty.abiAlignment(pt);2258 const non_null_align = non_null_ty.abiAlignment(zcu);
2259 const non_null_offset = non_null_align.forward(payload_size);2259 const non_null_offset = non_null_align.forward(payload_size);
22602260
2261 const debug_data_type = try o.builder.debugMemberType(2261 const debug_data_type = try o.builder.debugMemberType(
...@@ -2286,8 +2286,8 @@ pub const Object = struct {...@@ -2286,8 +2286,8 @@ pub const Object = struct {
2286 o.debug_compile_unit, // Scope2286 o.debug_compile_unit, // Scope
2287 0, // Line2287 0, // Line
2288 .none, // Underlying type2288 .none, // Underlying type
2289 ty.abiSize(pt) * 8,2289 ty.abiSize(zcu) * 8,
2290 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2290 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2291 try o.builder.debugTuple(&.{2291 try o.builder.debugTuple(&.{
2292 debug_data_type,2292 debug_data_type,
2293 debug_some_type,2293 debug_some_type,
...@@ -2304,7 +2304,7 @@ pub const Object = struct {...@@ -2304,7 +2304,7 @@ pub const Object = struct {
2304 },2304 },
2305 .ErrorUnion => {2305 .ErrorUnion => {
2306 const payload_ty = ty.errorUnionPayload(zcu);2306 const payload_ty = ty.errorUnionPayload(zcu);
2307 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {2307 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2308 // TODO: Maybe remove?2308 // TODO: Maybe remove?
2309 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);2309 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
2310 try o.debug_type_map.put(gpa, ty, debug_error_union_type);2310 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
...@@ -2314,10 +2314,10 @@ pub const Object = struct {...@@ -2314,10 +2314,10 @@ pub const Object = struct {
2314 const name = try o.allocTypeName(ty);2314 const name = try o.allocTypeName(ty);
2315 defer gpa.free(name);2315 defer gpa.free(name);
23162316
2317 const error_size = Type.anyerror.abiSize(pt);2317 const error_size = Type.anyerror.abiSize(zcu);
2318 const error_align = Type.anyerror.abiAlignment(pt);2318 const error_align = Type.anyerror.abiAlignment(zcu);
2319 const payload_size = payload_ty.abiSize(pt);2319 const payload_size = payload_ty.abiSize(zcu);
2320 const payload_align = payload_ty.abiAlignment(pt);2320 const payload_align = payload_ty.abiAlignment(zcu);
23212321
2322 var error_index: u32 = undefined;2322 var error_index: u32 = undefined;
2323 var payload_index: u32 = undefined;2323 var payload_index: u32 = undefined;
...@@ -2365,8 +2365,8 @@ pub const Object = struct {...@@ -2365,8 +2365,8 @@ pub const Object = struct {
2365 o.debug_compile_unit, // Sope2365 o.debug_compile_unit, // Sope
2366 0, // Line2366 0, // Line
2367 .none, // Underlying type2367 .none, // Underlying type
2368 ty.abiSize(pt) * 8,2368 ty.abiSize(zcu) * 8,
2369 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2369 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2370 try o.builder.debugTuple(&fields),2370 try o.builder.debugTuple(&fields),
2371 );2371 );
23722372
...@@ -2393,8 +2393,8 @@ pub const Object = struct {...@@ -2393,8 +2393,8 @@ pub const Object = struct {
2393 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);2393 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
2394 const builder_name = try o.builder.metadataString(name);2394 const builder_name = try o.builder.metadataString(name);
2395 const debug_int_type = switch (info.signedness) {2395 const debug_int_type = switch (info.signedness) {
2396 .signed => try o.builder.debugSignedType(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(pt) * 8),2397 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8),
2398 };2398 };
2399 try o.debug_type_map.put(gpa, ty, debug_int_type);2399 try o.debug_type_map.put(gpa, ty, debug_int_type);
2400 return debug_int_type;2400 return debug_int_type;
...@@ -2414,10 +2414,10 @@ pub const Object = struct {...@@ -2414,10 +2414,10 @@ pub const Object = struct {
2414 const debug_fwd_ref = try o.builder.debugForwardReference();2414 const debug_fwd_ref = try o.builder.debugForwardReference();
24152415
2416 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {2416 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);2419 const field_size = Type.fromInterned(field_ty).abiSize(zcu);
2420 const field_align = Type.fromInterned(field_ty).abiAlignment(pt);2420 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
2421 const field_offset = field_align.forward(offset);2421 const field_offset = field_align.forward(offset);
2422 offset = field_offset + field_size;2422 offset = field_offset + field_size;
24232423
...@@ -2445,8 +2445,8 @@ pub const Object = struct {...@@ -2445,8 +2445,8 @@ pub const Object = struct {
2445 o.debug_compile_unit, // Scope2445 o.debug_compile_unit, // Scope
2446 0, // Line2446 0, // Line
2447 .none, // Underlying type2447 .none, // Underlying type
2448 ty.abiSize(pt) * 8,2448 ty.abiSize(zcu) * 8,
2449 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2449 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2450 try o.builder.debugTuple(fields.items),2450 try o.builder.debugTuple(fields.items),
2451 );2451 );
24522452
...@@ -2472,7 +2472,7 @@ pub const Object = struct {...@@ -2472,7 +2472,7 @@ pub const Object = struct {
2472 else => {},2472 else => {},
2473 }2473 }
24742474
2475 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {2475 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2476 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);2476 const debug_struct_type = try o.makeEmptyNamespaceDebugType(ty);
2477 try o.debug_type_map.put(gpa, ty, debug_struct_type);2477 try o.debug_type_map.put(gpa, ty, debug_struct_type);
2478 return debug_struct_type;2478 return debug_struct_type;
...@@ -2494,18 +2494,12 @@ pub const Object = struct {...@@ -2494,18 +2494,12 @@ pub const Object = struct {
2494 var it = struct_type.iterateRuntimeOrder(ip);2494 var it = struct_type.iterateRuntimeOrder(ip);
2495 while (it.next()) |field_index| {2495 while (it.next()) |field_index| {
2496 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);2496 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2497 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;2497 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
2498 const field_size = field_ty.abiSize(pt);2498 const field_size = field_ty.abiSize(zcu);
2499 const field_align = pt.structFieldAlignment(2499 const field_align = ty.fieldAlignment(field_index, zcu);
2500 struct_type.fieldAlign(ip, field_index),2500 const field_offset = ty.structFieldOffset(field_index, zcu);
2501 field_ty,
2502 struct_type.layout,
2503 );
2504 const field_offset = ty.structFieldOffset(field_index, pt);
2505
2506 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse2501 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
2507 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);2502 try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
2508
2509 fields.appendAssumeCapacity(try o.builder.debugMemberType(2503 fields.appendAssumeCapacity(try o.builder.debugMemberType(
2510 try o.builder.metadataString(field_name.toSlice(ip)),2504 try o.builder.metadataString(field_name.toSlice(ip)),
2511 .none, // File2505 .none, // File
...@@ -2524,8 +2518,8 @@ pub const Object = struct {...@@ -2524,8 +2518,8 @@ pub const Object = struct {
2524 o.debug_compile_unit, // Scope2518 o.debug_compile_unit, // Scope
2525 0, // Line2519 0, // Line
2526 .none, // Underlying type2520 .none, // Underlying type
2527 ty.abiSize(pt) * 8,2521 ty.abiSize(zcu) * 8,
2528 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2522 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2529 try o.builder.debugTuple(fields.items),2523 try o.builder.debugTuple(fields.items),
2530 );2524 );
25312525
...@@ -2543,7 +2537,7 @@ pub const Object = struct {...@@ -2543,7 +2537,7 @@ pub const Object = struct {
25432537
2544 const union_type = ip.loadUnionType(ty.toIntern());2538 const union_type = ip.loadUnionType(ty.toIntern());
2545 if (!union_type.haveFieldTypes(ip) or2539 if (!union_type.haveFieldTypes(ip) or
2546 !ty.hasRuntimeBitsIgnoreComptime(pt) or2540 !ty.hasRuntimeBitsIgnoreComptime(zcu) or
2547 !union_type.haveLayout(ip))2541 !union_type.haveLayout(ip))
2548 {2542 {
2549 const debug_union_type = try o.makeEmptyNamespaceDebugType(ty);2543 const debug_union_type = try o.makeEmptyNamespaceDebugType(ty);
...@@ -2551,7 +2545,7 @@ pub const Object = struct {...@@ -2551,7 +2545,7 @@ pub const Object = struct {
2551 return debug_union_type;2545 return debug_union_type;
2552 }2546 }
25532547
2554 const layout = pt.getUnionLayout(union_type);2548 const layout = Type.getUnionLayout(union_type, zcu);
25552549
2556 const debug_fwd_ref = try o.builder.debugForwardReference();2550 const debug_fwd_ref = try o.builder.debugForwardReference();
25572551
...@@ -2565,8 +2559,8 @@ pub const Object = struct {...@@ -2565,8 +2559,8 @@ pub const Object = struct {
2565 o.debug_compile_unit, // Scope2559 o.debug_compile_unit, // Scope
2566 0, // Line2560 0, // Line
2567 .none, // Underlying type2561 .none, // Underlying type
2568 ty.abiSize(pt) * 8,2562 ty.abiSize(zcu) * 8,
2569 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2563 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2570 try o.builder.debugTuple(2564 try o.builder.debugTuple(
2571 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},2565 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
2572 ),2566 ),
...@@ -2593,12 +2587,12 @@ pub const Object = struct {...@@ -2593,12 +2587,12 @@ pub const Object = struct {
25932587
2594 for (0..tag_type.names.len) |field_index| {2588 for (0..tag_type.names.len) |field_index| {
2595 const field_ty = union_type.field_types.get(ip)[field_index];2589 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);
2599 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {2593 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
2600 .@"packed" => .none,2594 .@"packed" => .none,
2601 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),2595 .auto, .@"extern" => ty.fieldAlignment(field_index, zcu),
2602 };2596 };
26032597
2604 const field_name = tag_type.names.get(ip)[field_index];2598 const field_name = tag_type.names.get(ip)[field_index];
...@@ -2627,8 +2621,8 @@ pub const Object = struct {...@@ -2627,8 +2621,8 @@ pub const Object = struct {
2627 o.debug_compile_unit, // Scope2621 o.debug_compile_unit, // Scope
2628 0, // Line2622 0, // Line
2629 .none, // Underlying type2623 .none, // Underlying type
2630 ty.abiSize(pt) * 8,2624 ty.abiSize(zcu) * 8,
2631 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2625 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2632 try o.builder.debugTuple(fields.items),2626 try o.builder.debugTuple(fields.items),
2633 );2627 );
26342628
...@@ -2686,8 +2680,8 @@ pub const Object = struct {...@@ -2686,8 +2680,8 @@ pub const Object = struct {
2686 o.debug_compile_unit, // Scope2680 o.debug_compile_unit, // Scope
2687 0, // Line2681 0, // Line
2688 .none, // Underlying type2682 .none, // Underlying type
2689 ty.abiSize(pt) * 8,2683 ty.abiSize(zcu) * 8,
2690 (ty.abiAlignment(pt).toByteUnits() orelse 0) * 8,2684 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
2691 try o.builder.debugTuple(&full_fields),2685 try o.builder.debugTuple(&full_fields),
2692 );2686 );
26932687
...@@ -2708,8 +2702,8 @@ pub const Object = struct {...@@ -2708,8 +2702,8 @@ pub const Object = struct {
2708 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);2702 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
27092703
2710 // Return type goes first.2704 // Return type goes first.
2711 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(pt)) {2705 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
2712 const sret = firstParamSRet(fn_info, pt, target);2706 const sret = firstParamSRet(fn_info, zcu, target);
2713 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);2707 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
2714 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));2708 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
27152709
...@@ -2730,9 +2724,9 @@ pub const Object = struct {...@@ -2730,9 +2724,9 @@ pub const Object = struct {
27302724
2731 for (0..fn_info.param_types.len) |i| {2725 for (0..fn_info.param_types.len) |i| {
2732 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);2726 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)) {
2736 const ptr_ty = try pt.singleMutPtrType(param_ty);2730 const ptr_ty = try pt.singleMutPtrType(param_ty);
2737 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));2731 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
2738 } else {2732 } else {
...@@ -2842,7 +2836,7 @@ pub const Object = struct {...@@ -2842,7 +2836,7 @@ pub const Object = struct {
28422836
2843 const fn_info = zcu.typeToFunc(ty).?;2837 const fn_info = zcu.typeToFunc(ty).?;
2844 const target = owner_mod.resolved_target.result;2838 const target = owner_mod.resolved_target.result;
2845 const sret = firstParamSRet(fn_info, pt, target);2839 const sret = firstParamSRet(fn_info, zcu, target);
28462840
2847 const is_extern, const lib_name = switch (ip.indexToKey(val.toIntern())) {2841 const is_extern, const lib_name = switch (ip.indexToKey(val.toIntern())) {
2848 .variable => |variable| .{ false, variable.lib_name },2842 .variable => |variable| .{ false, variable.lib_name },
...@@ -2934,14 +2928,14 @@ pub const Object = struct {...@@ -2934,14 +2928,14 @@ pub const Object = struct {
2934 .byval => {2928 .byval => {
2935 const param_index = it.zig_index - 1;2929 const param_index = it.zig_index - 1;
2936 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);2930 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)) {
2938 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);2932 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
2939 }2933 }
2940 },2934 },
2941 .byref => {2935 .byref => {
2942 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);2936 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
2943 const param_llvm_ty = try o.lowerType(param_ty);2937 const param_llvm_ty = try o.lowerType(param_ty);
2944 const alignment = param_ty.abiAlignment(pt);2938 const alignment = param_ty.abiAlignment(zcu);
2945 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);2939 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
2946 },2940 },
2947 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),2941 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
...@@ -3042,8 +3036,8 @@ pub const Object = struct {...@@ -3042,8 +3036,8 @@ pub const Object = struct {
3042 }3036 }
3043 errdefer assert(o.uav_map.remove(uav));3037 errdefer assert(o.uav_map.remove(uav));
30443038
3045 const mod = o.pt.zcu;3039 const zcu = o.pt.zcu;
3046 const decl_ty = mod.intern_pool.typeOf(uav);3040 const decl_ty = zcu.intern_pool.typeOf(uav);
30473041
3048 const variable_index = try o.builder.addVariable(3042 const variable_index = try o.builder.addVariable(
3049 try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}),3043 try o.builder.strtabStringFmt("__anon_{d}", .{@intFromEnum(uav)}),
...@@ -3106,9 +3100,9 @@ pub const Object = struct {...@@ -3106,9 +3100,9 @@ pub const Object = struct {
31063100
3107 fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type {3101 fn lowerType(o: *Object, t: Type) Allocator.Error!Builder.Type {
3108 const pt = o.pt;3102 const pt = o.pt;
3109 const mod = pt.zcu;3103 const zcu = pt.zcu;
3110 const target = mod.getTarget();3104 const target = zcu.getTarget();
3111 const ip = &mod.intern_pool;3105 const ip = &zcu.intern_pool;
3112 return switch (t.toIntern()) {3106 return switch (t.toIntern()) {
3113 .u0_type, .i0_type => unreachable,3107 .u0_type, .i0_type => unreachable,
3114 inline .u1_type,3108 inline .u1_type,
...@@ -3230,16 +3224,16 @@ pub const Object = struct {...@@ -3230,16 +3224,16 @@ pub const Object = struct {
3230 ),3224 ),
3231 .opt_type => |child_ty| {3225 .opt_type => |child_ty| {
3232 // Must stay in sync with `opt_payload` logic in `lowerPtr`.3226 // 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
3235 const payload_ty = try o.lowerType(Type.fromInterned(child_ty));3229 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
3238 comptime assert(optional_layout_version == 3);3232 comptime assert(optional_layout_version == 3);
3239 var fields: [3]Builder.Type = .{ payload_ty, .i8, undefined };3233 var fields: [3]Builder.Type = .{ payload_ty, .i8, undefined };
3240 var fields_len: usize = 2;3234 var fields_len: usize = 2;
3241 const offset = Type.fromInterned(child_ty).abiSize(pt) + 1;3235 const offset = Type.fromInterned(child_ty).abiSize(zcu) + 1;
3242 const abi_size = t.abiSize(pt);3236 const abi_size = t.abiSize(zcu);
3243 const padding_len = abi_size - offset;3237 const padding_len = abi_size - offset;
3244 if (padding_len > 0) {3238 if (padding_len > 0) {
3245 fields[2] = try o.builder.arrayType(padding_len, .i8);3239 fields[2] = try o.builder.arrayType(padding_len, .i8);
...@@ -3252,16 +3246,16 @@ pub const Object = struct {...@@ -3252,16 +3246,16 @@ pub const Object = struct {
3252 // Must stay in sync with `codegen.errUnionPayloadOffset`.3246 // Must stay in sync with `codegen.errUnionPayloadOffset`.
3253 // See logic in `lowerPtr`.3247 // See logic in `lowerPtr`.
3254 const error_type = try o.errorIntType();3248 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))
3256 return error_type;3250 return error_type;
3257 const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type));3251 const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type));
3258 const err_int_ty = try o.pt.errorIntType();3252 const err_int_ty = try o.pt.errorIntType();
32593253
3260 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(pt);3254 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(zcu);
3261 const error_align = err_int_ty.abiAlignment(pt);3255 const error_align = err_int_ty.abiAlignment(zcu);
32623256
3263 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(pt);3257 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(zcu);
3264 const error_size = err_int_ty.abiSize(pt);3258 const error_size = err_int_ty.abiSize(zcu);
32653259
3266 var fields: [3]Builder.Type = undefined;3260 var fields: [3]Builder.Type = undefined;
3267 var fields_len: usize = 2;3261 var fields_len: usize = 2;
...@@ -3315,12 +3309,8 @@ pub const Object = struct {...@@ -3315,12 +3309,8 @@ pub const Object = struct {
3315 var it = struct_type.iterateRuntimeOrder(ip);3309 var it = struct_type.iterateRuntimeOrder(ip);
3316 while (it.next()) |field_index| {3310 while (it.next()) |field_index| {
3317 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);3311 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
3318 const field_align = pt.structFieldAlignment(3312 const field_align = t.fieldAlignment(field_index, zcu);
3319 struct_type.fieldAlign(ip, field_index),3313 const field_ty_align = field_ty.abiAlignment(zcu);
3320 field_ty,
3321 struct_type.layout,
3322 );
3323 const field_ty_align = field_ty.abiAlignment(pt);
3324 if (field_align.compare(.lt, field_ty_align)) struct_kind = .@"packed";3314 if (field_align.compare(.lt, field_ty_align)) struct_kind = .@"packed";
3325 big_align = big_align.max(field_align);3315 big_align = big_align.max(field_align);
3326 const prev_offset = offset;3316 const prev_offset = offset;
...@@ -3332,7 +3322,7 @@ pub const Object = struct {...@@ -3332,7 +3322,7 @@ pub const Object = struct {
3332 try o.builder.arrayType(padding_len, .i8),3322 try o.builder.arrayType(padding_len, .i8),
3333 );3323 );
33343324
3335 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {3325 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
3336 // This is a zero-bit field. If there are runtime bits after this field,3326 // This is a zero-bit field. If there are runtime bits after this field,
3337 // map to the next LLVM field (which we know exists): otherwise, don't3327 // map to the next LLVM field (which we know exists): otherwise, don't
3338 // map the field, indicating it's at the end of the struct.3328 // map the field, indicating it's at the end of the struct.
...@@ -3351,7 +3341,7 @@ pub const Object = struct {...@@ -3351,7 +3341,7 @@ pub const Object = struct {
3351 }, @intCast(llvm_field_types.items.len));3341 }, @intCast(llvm_field_types.items.len));
3352 try llvm_field_types.append(o.gpa, try o.lowerType(field_ty));3342 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);
3355 }3345 }
3356 {3346 {
3357 const prev_offset = offset;3347 const prev_offset = offset;
...@@ -3384,7 +3374,7 @@ pub const Object = struct {...@@ -3384,7 +3374,7 @@ pub const Object = struct {
3384 var offset: u64 = 0;3374 var offset: u64 = 0;
3385 var big_align: InternPool.Alignment = .none;3375 var big_align: InternPool.Alignment = .none;
33863376
3387 const struct_size = t.abiSize(pt);3377 const struct_size = t.abiSize(zcu);
33883378
3389 for (3379 for (
3390 anon_struct_type.types.get(ip),3380 anon_struct_type.types.get(ip),
...@@ -3393,7 +3383,7 @@ pub const Object = struct {...@@ -3393,7 +3383,7 @@ pub const Object = struct {
3393 ) |field_ty, field_val, field_index| {3383 ) |field_ty, field_val, field_index| {
3394 if (field_val != .none) continue;3384 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);
3397 big_align = big_align.max(field_align);3387 big_align = big_align.max(field_align);
3398 const prev_offset = offset;3388 const prev_offset = offset;
3399 offset = field_align.forward(offset);3389 offset = field_align.forward(offset);
...@@ -3403,7 +3393,7 @@ pub const Object = struct {...@@ -3403,7 +3393,7 @@ pub const Object = struct {
3403 o.gpa,3393 o.gpa,
3404 try o.builder.arrayType(padding_len, .i8),3394 try o.builder.arrayType(padding_len, .i8),
3405 );3395 );
3406 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) {3396 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) {
3407 // This is a zero-bit field. If there are runtime bits after this field,3397 // This is a zero-bit field. If there are runtime bits after this field,
3408 // map to the next LLVM field (which we know exists): otherwise, don't3398 // map to the next LLVM field (which we know exists): otherwise, don't
3409 // map the field, indicating it's at the end of the struct.3399 // map the field, indicating it's at the end of the struct.
...@@ -3421,7 +3411,7 @@ pub const Object = struct {...@@ -3421,7 +3411,7 @@ pub const Object = struct {
3421 }, @intCast(llvm_field_types.items.len));3411 }, @intCast(llvm_field_types.items.len));
3422 try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty)));3412 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);
3425 }3415 }
3426 {3416 {
3427 const prev_offset = offset;3417 const prev_offset = offset;
...@@ -3438,10 +3428,10 @@ pub const Object = struct {...@@ -3438,10 +3428,10 @@ pub const Object = struct {
3438 if (o.type_map.get(t.toIntern())) |value| return value;3428 if (o.type_map.get(t.toIntern())) |value| return value;
34393429
3440 const union_obj = ip.loadUnionType(t.toIntern());3430 const union_obj = ip.loadUnionType(t.toIntern());
3441 const layout = pt.getUnionLayout(union_obj);3431 const layout = Type.getUnionLayout(union_obj, zcu);
34423432
3443 if (union_obj.flagsUnordered(ip).layout == .@"packed") {3433 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)));
3445 try o.type_map.put(o.gpa, t.toIntern(), int_ty);3435 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
3446 return int_ty;3436 return int_ty;
3447 }3437 }
...@@ -3547,32 +3537,32 @@ pub const Object = struct {...@@ -3547,32 +3537,32 @@ pub const Object = struct {
3547 /// There are other similar cases handled here as well.3537 /// There are other similar cases handled here as well.
3548 fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type {3538 fn lowerPtrElemTy(o: *Object, elem_ty: Type) Allocator.Error!Builder.Type {
3549 const pt = o.pt;3539 const pt = o.pt;
3550 const mod = pt.zcu;3540 const zcu = pt.zcu;
3551 const lower_elem_ty = switch (elem_ty.zigTypeTag(mod)) {3541 const lower_elem_ty = switch (elem_ty.zigTypeTag(zcu)) {
3552 .Opaque => true,3542 .Opaque => true,
3553 .Fn => !mod.typeToFunc(elem_ty).?.is_generic,3543 .Fn => !zcu.typeToFunc(elem_ty).?.is_generic,
3554 .Array => elem_ty.childType(mod).hasRuntimeBitsIgnoreComptime(pt),3544 .Array => elem_ty.childType(zcu).hasRuntimeBitsIgnoreComptime(zcu),
3555 else => elem_ty.hasRuntimeBitsIgnoreComptime(pt),3545 else => elem_ty.hasRuntimeBitsIgnoreComptime(zcu),
3556 };3546 };
3557 return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8;3547 return if (lower_elem_ty) try o.lowerType(elem_ty) else .i8;
3558 }3548 }
35593549
3560 fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {3550 fn lowerTypeFn(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
3561 const pt = o.pt;3551 const pt = o.pt;
3562 const mod = pt.zcu;3552 const zcu = pt.zcu;
3563 const ip = &mod.intern_pool;3553 const ip = &zcu.intern_pool;
3564 const target = mod.getTarget();3554 const target = zcu.getTarget();
3565 const ret_ty = try lowerFnRetTy(o, fn_info);3555 const ret_ty = try lowerFnRetTy(o, fn_info);
35663556
3567 var llvm_params = std.ArrayListUnmanaged(Builder.Type){};3557 var llvm_params = std.ArrayListUnmanaged(Builder.Type){};
3568 defer llvm_params.deinit(o.gpa);3558 defer llvm_params.deinit(o.gpa);
35693559
3570 if (firstParamSRet(fn_info, pt, target)) {3560 if (firstParamSRet(fn_info, zcu, target)) {
3571 try llvm_params.append(o.gpa, .ptr);3561 try llvm_params.append(o.gpa, .ptr);
3572 }3562 }
35733563
3574 if (Type.fromInterned(fn_info.return_type).isError(mod) and3564 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
3575 mod.comp.config.any_error_tracing)3565 zcu.comp.config.any_error_tracing)
3576 {3566 {
3577 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());3567 const ptr_ty = try pt.singleMutPtrType(try o.getStackTraceType());
3578 try llvm_params.append(o.gpa, try o.lowerType(ptr_ty));3568 try llvm_params.append(o.gpa, try o.lowerType(ptr_ty));
...@@ -3591,13 +3581,13 @@ pub const Object = struct {...@@ -3591,13 +3581,13 @@ pub const Object = struct {
3591 .abi_sized_int => {3581 .abi_sized_int => {
3592 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);3582 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
3593 try llvm_params.append(o.gpa, try o.builder.intType(3583 try llvm_params.append(o.gpa, try o.builder.intType(
3594 @intCast(param_ty.abiSize(pt) * 8),3584 @intCast(param_ty.abiSize(zcu) * 8),
3595 ));3585 ));
3596 },3586 },
3597 .slice => {3587 .slice => {
3598 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);3588 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
3599 try llvm_params.appendSlice(o.gpa, &.{3589 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)),
3601 try o.lowerType(Type.usize),3591 try o.lowerType(Type.usize),
3602 });3592 });
3603 },3593 },
...@@ -3609,7 +3599,7 @@ pub const Object = struct {...@@ -3609,7 +3599,7 @@ pub const Object = struct {
3609 },3599 },
3610 .float_array => |count| {3600 .float_array => |count| {
3611 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);3601 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).?);
3613 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));3603 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
3614 },3604 },
3615 .i32_array, .i64_array => |arr_len| {3605 .i32_array, .i64_array => |arr_len| {
...@@ -3630,14 +3620,14 @@ pub const Object = struct {...@@ -3630,14 +3620,14 @@ pub const Object = struct {
36303620
3631 fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {3621 fn lowerValueToInt(o: *Object, llvm_int_ty: Builder.Type, arg_val: InternPool.Index) Error!Builder.Constant {
3632 const pt = o.pt;3622 const pt = o.pt;
3633 const mod = pt.zcu;3623 const zcu = pt.zcu;
3634 const ip = &mod.intern_pool;3624 const ip = &zcu.intern_pool;
3635 const target = mod.getTarget();3625 const target = zcu.getTarget();
36363626
3637 const val = Value.fromInterned(arg_val);3627 const val = Value.fromInterned(arg_val);
3638 const val_key = ip.indexToKey(val.toIntern());3628 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
3642 const ty = Type.fromInterned(val_key.typeOf());3632 const ty = Type.fromInterned(val_key.typeOf());
3643 switch (val_key) {3633 switch (val_key) {
...@@ -3661,7 +3651,7 @@ pub const Object = struct {...@@ -3661,7 +3651,7 @@ pub const Object = struct {
3661 var running_int = try o.builder.intConst(llvm_int_ty, 0);3651 var running_int = try o.builder.intConst(llvm_int_ty, 0);
3662 var running_bits: u16 = 0;3652 var running_bits: u16 = 0;
3663 for (struct_type.field_types.get(ip), 0..) |field_ty, field_index| {3653 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
3666 const shift_rhs = try o.builder.intConst(llvm_int_ty, running_bits);3656 const shift_rhs = try o.builder.intConst(llvm_int_ty, running_bits);
3667 const field_val = try o.lowerValueToInt(llvm_int_ty, (try val.fieldValue(pt, field_index)).toIntern());3657 const field_val = try o.lowerValueToInt(llvm_int_ty, (try val.fieldValue(pt, field_index)).toIntern());
...@@ -3669,7 +3659,7 @@ pub const Object = struct {...@@ -3669,7 +3659,7 @@ pub const Object = struct {
36693659
3670 running_int = try o.builder.binConst(.xor, running_int, shifted);3660 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));
3673 running_bits += ty_bit_size;3663 running_bits += ty_bit_size;
3674 }3664 }
3675 return running_int;3665 return running_int;
...@@ -3678,10 +3668,10 @@ pub const Object = struct {...@@ -3678,10 +3668,10 @@ pub const Object = struct {
3678 else => unreachable,3668 else => unreachable,
3679 },3669 },
3680 .un => |un| {3670 .un => |un| {
3681 const layout = ty.unionGetLayout(pt);3671 const layout = ty.unionGetLayout(zcu);
3682 if (layout.payload_size == 0) return o.lowerValue(un.tag);3672 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).?;
3685 const container_layout = union_obj.flagsUnordered(ip).layout;3675 const container_layout = union_obj.flagsUnordered(ip).layout;
36863676
3687 assert(container_layout == .@"packed");3677 assert(container_layout == .@"packed");
...@@ -3694,9 +3684,9 @@ pub const Object = struct {...@@ -3694,9 +3684,9 @@ pub const Object = struct {
3694 need_unnamed = true;3684 need_unnamed = true;
3695 return union_val;3685 return union_val;
3696 }3686 }
3697 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;3687 const field_index = zcu.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3698 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);3688 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);
3700 return o.lowerValueToInt(llvm_int_ty, un.val);3690 return o.lowerValueToInt(llvm_int_ty, un.val);
3701 },3691 },
3702 .simple_value => |simple_value| switch (simple_value) {3692 .simple_value => |simple_value| switch (simple_value) {
...@@ -3710,7 +3700,7 @@ pub const Object = struct {...@@ -3710,7 +3700,7 @@ pub const Object = struct {
3710 .opt => {}, // pointer like optional expected3700 .opt => {}, // pointer like optional expected
3711 else => unreachable,3701 else => unreachable,
3712 }3702 }
3713 const bits = ty.bitSize(pt);3703 const bits = ty.bitSize(zcu);
3714 const bytes: usize = @intCast(std.mem.alignForward(u64, bits, 8) / 8);3704 const bytes: usize = @intCast(std.mem.alignForward(u64, bits, 8) / 8);
37153705
3716 var stack = std.heap.stackFallback(32, o.gpa);3706 var stack = std.heap.stackFallback(32, o.gpa);
...@@ -3743,14 +3733,14 @@ pub const Object = struct {...@@ -3743,14 +3733,14 @@ pub const Object = struct {
37433733
3744 fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant {3734 fn lowerValue(o: *Object, arg_val: InternPool.Index) Error!Builder.Constant {
3745 const pt = o.pt;3735 const pt = o.pt;
3746 const mod = pt.zcu;3736 const zcu = pt.zcu;
3747 const ip = &mod.intern_pool;3737 const ip = &zcu.intern_pool;
3748 const target = mod.getTarget();3738 const target = zcu.getTarget();
37493739
3750 const val = Value.fromInterned(arg_val);3740 const val = Value.fromInterned(arg_val);
3751 const val_key = ip.indexToKey(val.toIntern());3741 const val_key = ip.indexToKey(val.toIntern());
37523742
3753 if (val.isUndefDeep(mod)) {3743 if (val.isUndefDeep(zcu)) {
3754 return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf())));3744 return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf())));
3755 }3745 }
37563746
...@@ -3800,7 +3790,7 @@ pub const Object = struct {...@@ -3800,7 +3790,7 @@ pub const Object = struct {
3800 },3790 },
3801 .int => {3791 .int => {
3802 var bigint_space: Value.BigIntSpace = undefined;3792 var bigint_space: Value.BigIntSpace = undefined;
3803 const bigint = val.toBigInt(&bigint_space, pt);3793 const bigint = val.toBigInt(&bigint_space, zcu);
3804 return lowerBigInt(o, ty, bigint);3794 return lowerBigInt(o, ty, bigint);
3805 },3795 },
3806 .err => |err| {3796 .err => |err| {
...@@ -3811,20 +3801,20 @@ pub const Object = struct {...@@ -3811,20 +3801,20 @@ pub const Object = struct {
3811 .error_union => |error_union| {3801 .error_union => |error_union| {
3812 const err_val = switch (error_union.val) {3802 const err_val = switch (error_union.val) {
3813 .err_name => |err_name| try pt.intern(.{ .err = .{3803 .err_name => |err_name| try pt.intern(.{ .err = .{
3814 .ty = ty.errorUnionSet(mod).toIntern(),3804 .ty = ty.errorUnionSet(zcu).toIntern(),
3815 .name = err_name,3805 .name = err_name,
3816 } }),3806 } }),
3817 .payload => (try pt.intValue(try pt.errorIntType(), 0)).toIntern(),3807 .payload => (try pt.intValue(try pt.errorIntType(), 0)).toIntern(),
3818 };3808 };
3819 const err_int_ty = try pt.errorIntType();3809 const err_int_ty = try pt.errorIntType();
3820 const payload_type = ty.errorUnionPayload(mod);3810 const payload_type = ty.errorUnionPayload(zcu);
3821 if (!payload_type.hasRuntimeBitsIgnoreComptime(pt)) {3811 if (!payload_type.hasRuntimeBitsIgnoreComptime(zcu)) {
3822 // We use the error type directly as the type.3812 // We use the error type directly as the type.
3823 return o.lowerValue(err_val);3813 return o.lowerValue(err_val);
3824 }3814 }
38253815
3826 const payload_align = payload_type.abiAlignment(pt);3816 const payload_align = payload_type.abiAlignment(zcu);
3827 const error_align = err_int_ty.abiAlignment(pt);3817 const error_align = err_int_ty.abiAlignment(zcu);
3828 const llvm_error_value = try o.lowerValue(err_val);3818 const llvm_error_value = try o.lowerValue(err_val);
3829 const llvm_payload_value = try o.lowerValue(switch (error_union.val) {3819 const llvm_payload_value = try o.lowerValue(switch (error_union.val) {
3830 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),3820 .err_name => try pt.intern(.{ .undef = payload_type.toIntern() }),
...@@ -3858,16 +3848,16 @@ pub const Object = struct {...@@ -3858,16 +3848,16 @@ pub const Object = struct {
3858 .enum_tag => |enum_tag| o.lowerValue(enum_tag.int),3848 .enum_tag => |enum_tag| o.lowerValue(enum_tag.int),
3859 .float => switch (ty.floatBits(target)) {3849 .float => switch (ty.floatBits(target)) {
3860 16 => if (backendSupportsF16(target))3850 16 => if (backendSupportsF16(target))
3861 try o.builder.halfConst(val.toFloat(f16, pt))3851 try o.builder.halfConst(val.toFloat(f16, zcu))
3862 else3852 else
3863 try o.builder.intConst(.i16, @as(i16, @bitCast(val.toFloat(f16, pt)))),3853 try o.builder.intConst(.i16, @as(i16, @bitCast(val.toFloat(f16, zcu)))),
3864 32 => try o.builder.floatConst(val.toFloat(f32, pt)),3854 32 => try o.builder.floatConst(val.toFloat(f32, zcu)),
3865 64 => try o.builder.doubleConst(val.toFloat(f64, pt)),3855 64 => try o.builder.doubleConst(val.toFloat(f64, zcu)),
3866 80 => if (backendSupportsF80(target))3856 80 => if (backendSupportsF80(target))
3867 try o.builder.x86_fp80Const(val.toFloat(f80, pt))3857 try o.builder.x86_fp80Const(val.toFloat(f80, zcu))
3868 else3858 else
3869 try o.builder.intConst(.i80, @as(i80, @bitCast(val.toFloat(f80, pt)))),3859 try o.builder.intConst(.i80, @as(i80, @bitCast(val.toFloat(f80, zcu)))),
3870 128 => try o.builder.fp128Const(val.toFloat(f128, pt)),3860 128 => try o.builder.fp128Const(val.toFloat(f128, zcu)),
3871 else => unreachable,3861 else => unreachable,
3872 },3862 },
3873 .ptr => try o.lowerPtr(arg_val, 0),3863 .ptr => try o.lowerPtr(arg_val, 0),
...@@ -3877,14 +3867,14 @@ pub const Object = struct {...@@ -3877,14 +3867,14 @@ pub const Object = struct {
3877 }),3867 }),
3878 .opt => |opt| {3868 .opt => |opt| {
3879 comptime assert(optional_layout_version == 3);3869 comptime assert(optional_layout_version == 3);
3880 const payload_ty = ty.optionalChild(mod);3870 const payload_ty = ty.optionalChild(zcu);
38813871
3882 const non_null_bit = try o.builder.intConst(.i8, @intFromBool(opt.val != .none));3872 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)) {
3884 return non_null_bit;3874 return non_null_bit;
3885 }3875 }
3886 const llvm_ty = try o.lowerType(ty);3876 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) {
3888 .none => switch (llvm_ty.tag(&o.builder)) {3878 .none => switch (llvm_ty.tag(&o.builder)) {
3889 .integer => try o.builder.intConst(llvm_ty, 0),3879 .integer => try o.builder.intConst(llvm_ty, 0),
3890 .pointer => try o.builder.nullConst(llvm_ty),3880 .pointer => try o.builder.nullConst(llvm_ty),
...@@ -3893,7 +3883,7 @@ pub const Object = struct {...@@ -3893,7 +3883,7 @@ pub const Object = struct {
3893 },3883 },
3894 else => |payload| try o.lowerValue(payload),3884 else => |payload| try o.lowerValue(payload),
3895 };3885 };
3896 assert(payload_ty.zigTypeTag(mod) != .Fn);3886 assert(payload_ty.zigTypeTag(zcu) != .Fn);
38973887
3898 var fields: [3]Builder.Type = undefined;3888 var fields: [3]Builder.Type = undefined;
3899 var vals: [3]Builder.Constant = undefined;3889 var vals: [3]Builder.Constant = undefined;
...@@ -4047,9 +4037,9 @@ pub const Object = struct {...@@ -4047,9 +4037,9 @@ pub const Object = struct {
4047 0..,4037 0..,
4048 ) |field_ty, field_val, field_index| {4038 ) |field_ty, field_val, field_index| {
4049 if (field_val != .none) continue;4039 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);
4053 big_align = big_align.max(field_align);4043 big_align = big_align.max(field_align);
4054 const prev_offset = offset;4044 const prev_offset = offset;
4055 offset = field_align.forward(offset);4045 offset = field_align.forward(offset);
...@@ -4071,7 +4061,7 @@ pub const Object = struct {...@@ -4071,7 +4061,7 @@ pub const Object = struct {
4071 need_unnamed = true;4061 need_unnamed = true;
4072 llvm_index += 1;4062 llvm_index += 1;
40734063
4074 offset += Type.fromInterned(field_ty).abiSize(pt);4064 offset += Type.fromInterned(field_ty).abiSize(zcu);
4075 }4065 }
4076 {4066 {
4077 const prev_offset = offset;4067 const prev_offset = offset;
...@@ -4098,7 +4088,7 @@ pub const Object = struct {...@@ -4098,7 +4088,7 @@ pub const Object = struct {
4098 if (struct_type.layout == .@"packed") {4088 if (struct_type.layout == .@"packed") {
4099 comptime assert(Type.packed_struct_layout_version == 2);4089 comptime assert(Type.packed_struct_layout_version == 2);
41004090
4101 const bits = ty.bitSize(pt);4091 const bits = ty.bitSize(zcu);
4102 const llvm_int_ty = try o.builder.intType(@intCast(bits));4092 const llvm_int_ty = try o.builder.intType(@intCast(bits));
41034093
4104 return o.lowerValueToInt(llvm_int_ty, arg_val);4094 return o.lowerValueToInt(llvm_int_ty, arg_val);
...@@ -4127,11 +4117,7 @@ pub const Object = struct {...@@ -4127,11 +4117,7 @@ pub const Object = struct {
4127 var field_it = struct_type.iterateRuntimeOrder(ip);4117 var field_it = struct_type.iterateRuntimeOrder(ip);
4128 while (field_it.next()) |field_index| {4118 while (field_it.next()) |field_index| {
4129 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);4119 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
4130 const field_align = pt.structFieldAlignment(4120 const field_align = ty.fieldAlignment(field_index, zcu);
4131 struct_type.fieldAlign(ip, field_index),
4132 field_ty,
4133 struct_type.layout,
4134 );
4135 big_align = big_align.max(field_align);4121 big_align = big_align.max(field_align);
4136 const prev_offset = offset;4122 const prev_offset = offset;
4137 offset = field_align.forward(offset);4123 offset = field_align.forward(offset);
...@@ -4147,7 +4133,7 @@ pub const Object = struct {...@@ -4147,7 +4133,7 @@ pub const Object = struct {
4147 llvm_index += 1;4133 llvm_index += 1;
4148 }4134 }
41494135
4150 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {4136 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4151 // This is a zero-bit field - we only needed it for the alignment.4137 // This is a zero-bit field - we only needed it for the alignment.
4152 continue;4138 continue;
4153 }4139 }
...@@ -4160,7 +4146,7 @@ pub const Object = struct {...@@ -4160,7 +4146,7 @@ pub const Object = struct {
4160 need_unnamed = true;4146 need_unnamed = true;
4161 llvm_index += 1;4147 llvm_index += 1;
41624148
4163 offset += field_ty.abiSize(pt);4149 offset += field_ty.abiSize(zcu);
4164 }4150 }
4165 {4151 {
4166 const prev_offset = offset;4152 const prev_offset = offset;
...@@ -4184,19 +4170,19 @@ pub const Object = struct {...@@ -4184,19 +4170,19 @@ pub const Object = struct {
4184 },4170 },
4185 .un => |un| {4171 .un => |un| {
4186 const union_ty = try o.lowerType(ty);4172 const union_ty = try o.lowerType(ty);
4187 const layout = ty.unionGetLayout(pt);4173 const layout = ty.unionGetLayout(zcu);
4188 if (layout.payload_size == 0) return o.lowerValue(un.tag);4174 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).?;
4191 const container_layout = union_obj.flagsUnordered(ip).layout;4177 const container_layout = union_obj.flagsUnordered(ip).layout;
41924178
4193 var need_unnamed = false;4179 var need_unnamed = false;
4194 const payload = if (un.tag != .none) p: {4180 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)).?;
4196 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);4182 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
4197 if (container_layout == .@"packed") {4183 if (container_layout == .@"packed") {
4198 if (!field_ty.hasRuntimeBits(pt)) return o.builder.intConst(union_ty, 0);4184 if (!field_ty.hasRuntimeBits(zcu)) return o.builder.intConst(union_ty, 0);
4199 const bits = ty.bitSize(pt);4185 const bits = ty.bitSize(zcu);
4200 const llvm_int_ty = try o.builder.intType(@intCast(bits));4186 const llvm_int_ty = try o.builder.intType(@intCast(bits));
42014187
4202 return o.lowerValueToInt(llvm_int_ty, arg_val);4188 return o.lowerValueToInt(llvm_int_ty, arg_val);
...@@ -4208,7 +4194,7 @@ pub const Object = struct {...@@ -4208,7 +4194,7 @@ pub const Object = struct {
4208 // must pointer cast to the expected type before accessing the union.4194 // must pointer cast to the expected type before accessing the union.
4209 need_unnamed = layout.most_aligned_field != field_index;4195 need_unnamed = layout.most_aligned_field != field_index;
42104196
4211 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {4197 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4212 const padding_len = layout.payload_size;4198 const padding_len = layout.payload_size;
4213 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));4199 break :p try o.builder.undefConst(try o.builder.arrayType(padding_len, .i8));
4214 }4200 }
...@@ -4217,7 +4203,7 @@ pub const Object = struct {...@@ -4217,7 +4203,7 @@ pub const Object = struct {
4217 if (payload_ty != union_ty.structFields(&o.builder)[4203 if (payload_ty != union_ty.structFields(&o.builder)[
4218 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))4204 @intFromBool(layout.tag_align.compare(.gte, layout.payload_align))
4219 ]) need_unnamed = true;4205 ]) need_unnamed = true;
4220 const field_size = field_ty.abiSize(pt);4206 const field_size = field_ty.abiSize(zcu);
4221 if (field_size == layout.payload_size) break :p payload;4207 if (field_size == layout.payload_size) break :p payload;
4222 const padding_len = layout.payload_size - field_size;4208 const padding_len = layout.payload_size - field_size;
4223 const padding_ty = try o.builder.arrayType(padding_len, .i8);4209 const padding_ty = try o.builder.arrayType(padding_len, .i8);
...@@ -4228,7 +4214,7 @@ pub const Object = struct {...@@ -4228,7 +4214,7 @@ pub const Object = struct {
4228 } else p: {4214 } else p: {
4229 assert(layout.tag_size == 0);4215 assert(layout.tag_size == 0);
4230 if (container_layout == .@"packed") {4216 if (container_layout == .@"packed") {
4231 const bits = ty.bitSize(pt);4217 const bits = ty.bitSize(zcu);
4232 const llvm_int_ty = try o.builder.intType(@intCast(bits));4218 const llvm_int_ty = try o.builder.intType(@intCast(bits));
42334219
4234 return o.lowerValueToInt(llvm_int_ty, arg_val);4220 return o.lowerValueToInt(llvm_int_ty, arg_val);
...@@ -4275,8 +4261,8 @@ pub const Object = struct {...@@ -4275,8 +4261,8 @@ pub const Object = struct {
4275 ty: Type,4261 ty: Type,
4276 bigint: std.math.big.int.Const,4262 bigint: std.math.big.int.Const,
4277 ) Allocator.Error!Builder.Constant {4263 ) Allocator.Error!Builder.Constant {
4278 const mod = o.pt.zcu;4264 const zcu = o.pt.zcu;
4279 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(mod).bits), bigint);4265 return o.builder.bigIntConst(try o.builder.intType(ty.intInfo(zcu).bits), bigint);
4280 }4266 }
42814267
4282 fn lowerPtr(4268 fn lowerPtr(
...@@ -4310,7 +4296,7 @@ pub const Object = struct {...@@ -4310,7 +4296,7 @@ pub const Object = struct {
4310 eu_ptr,4296 eu_ptr,
4311 offset + @import("../codegen.zig").errUnionPayloadOffset(4297 offset + @import("../codegen.zig").errUnionPayloadOffset(
4312 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),4298 Value.fromInterned(eu_ptr).typeOf(zcu).childType(zcu),
4313 pt,4299 zcu,
4314 ),4300 ),
4315 ),4301 ),
4316 .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset),4302 .opt_payload => |opt_ptr| try o.lowerPtr(opt_ptr, offset),
...@@ -4326,7 +4312,7 @@ pub const Object = struct {...@@ -4326,7 +4312,7 @@ pub const Object = struct {
4326 };4312 };
4327 },4313 },
4328 .Struct, .Union => switch (agg_ty.containerLayout(zcu)) {4314 .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),
4330 .@"extern", .@"packed" => unreachable,4316 .@"extern", .@"packed" => unreachable,
4331 },4317 },
4332 else => unreachable,4318 else => unreachable,
...@@ -4344,11 +4330,11 @@ pub const Object = struct {...@@ -4344,11 +4330,11 @@ pub const Object = struct {
4344 uav: InternPool.Key.Ptr.BaseAddr.Uav,4330 uav: InternPool.Key.Ptr.BaseAddr.Uav,
4345 ) Error!Builder.Constant {4331 ) Error!Builder.Constant {
4346 const pt = o.pt;4332 const pt = o.pt;
4347 const mod = pt.zcu;4333 const zcu = pt.zcu;
4348 const ip = &mod.intern_pool;4334 const ip = &zcu.intern_pool;
4349 const uav_val = uav.val;4335 const uav_val = uav.val;
4350 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));4336 const uav_ty = Type.fromInterned(ip.typeOf(uav_val));
4351 const target = mod.getTarget();4337 const target = zcu.getTarget();
43524338
4353 switch (ip.indexToKey(uav_val)) {4339 switch (ip.indexToKey(uav_val)) {
4354 .func => @panic("TODO"),4340 .func => @panic("TODO"),
...@@ -4358,15 +4344,15 @@ pub const Object = struct {...@@ -4358,15 +4344,15 @@ pub const Object = struct {
43584344
4359 const ptr_ty = Type.fromInterned(uav.orig_ty);4345 const ptr_ty = Type.fromInterned(uav.orig_ty);
43604346
4361 const is_fn_body = uav_ty.zigTypeTag(mod) == .Fn;4347 const is_fn_body = uav_ty.zigTypeTag(zcu) == .Fn;
4362 if ((!is_fn_body and !uav_ty.hasRuntimeBits(pt)) or4348 if ((!is_fn_body and !uav_ty.hasRuntimeBits(zcu)) or
4363 (is_fn_body and mod.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty);4349 (is_fn_body and zcu.typeToFunc(uav_ty).?.is_generic)) return o.lowerPtrToVoid(ptr_ty);
43644350
4365 if (is_fn_body)4351 if (is_fn_body)
4366 @panic("TODO");4352 @panic("TODO");
43674353
4368 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(mod), target);4354 const llvm_addr_space = toLlvmAddressSpace(ptr_ty.ptrAddressSpace(zcu), target);
4369 const alignment = ptr_ty.ptrAlignment(pt);4355 const alignment = ptr_ty.ptrAlignment(zcu);
4370 const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;4356 const llvm_global = (try o.resolveGlobalUav(uav.val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
43714357
4372 const llvm_val = try o.builder.convConst(4358 const llvm_val = try o.builder.convConst(
...@@ -4398,7 +4384,7 @@ pub const Object = struct {...@@ -4398,7 +4384,7 @@ pub const Object = struct {
4398 const ptr_ty = try pt.navPtrType(owner_nav_index);4384 const ptr_ty = try pt.navPtrType(owner_nav_index);
43994385
4400 const is_fn_body = nav_ty.zigTypeTag(zcu) == .Fn;4386 const is_fn_body = nav_ty.zigTypeTag(zcu) == .Fn;
4401 if ((!is_fn_body and !nav_ty.hasRuntimeBits(pt)) or4387 if ((!is_fn_body and !nav_ty.hasRuntimeBits(zcu)) or
4402 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))4388 (is_fn_body and zcu.typeToFunc(nav_ty).?.is_generic))
4403 {4389 {
4404 return o.lowerPtrToVoid(ptr_ty);4390 return o.lowerPtrToVoid(ptr_ty);
...@@ -4418,19 +4404,19 @@ pub const Object = struct {...@@ -4418,19 +4404,19 @@ pub const Object = struct {
4418 }4404 }
44194405
4420 fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant {4406 fn lowerPtrToVoid(o: *Object, ptr_ty: Type) Allocator.Error!Builder.Constant {
4421 const mod = o.pt.zcu;4407 const zcu = o.pt.zcu;
4422 // Even though we are pointing at something which has zero bits (e.g. `void`),4408 // Even though we are pointing at something which has zero bits (e.g. `void`),
4423 // Pointers are defined to have bits. So we must return something here.4409 // Pointers are defined to have bits. So we must return something here.
4424 // The value cannot be undefined, because we use the `nonnull` annotation4410 // The value cannot be undefined, because we use the `nonnull` annotation
4425 // for non-optional pointers. We also need to respect the alignment, even though4411 // for non-optional pointers. We also need to respect the alignment, even though
4426 // the address will never be dereferenced.4412 // the address will never be dereferenced.
4427 const int: u64 = ptr_ty.ptrInfo(mod).flags.alignment.toByteUnits() orelse4413 const int: u64 = ptr_ty.ptrInfo(zcu).flags.alignment.toByteUnits() orelse
4428 // Note that these 0xaa values are appropriate even in release-optimized builds4414 // Note that these 0xaa values are appropriate even in release-optimized builds
4429 // because we need a well-defined value that is not null, and LLVM does not4415 // because we need a well-defined value that is not null, and LLVM does not
4430 // have an "undef_but_not_null" attribute. As an example, if this `alloc` AIR4416 // have an "undef_but_not_null" attribute. As an example, if this `alloc` AIR
4431 // instruction is followed by a `wrap_optional`, it will return this value4417 // instruction is followed by a `wrap_optional`, it will return this value
4432 // verbatim, and the result should test as non-null.4418 // verbatim, and the result should test as non-null.
4433 switch (mod.getTarget().ptrBitWidth()) {4419 switch (zcu.getTarget().ptrBitWidth()) {
4434 16 => 0xaaaa,4420 16 => 0xaaaa,
4435 32 => 0xaaaaaaaa,4421 32 => 0xaaaaaaaa,
4436 64 => 0xaaaaaaaa_aaaaaaaa,4422 64 => 0xaaaaaaaa_aaaaaaaa,
...@@ -4447,20 +4433,20 @@ pub const Object = struct {...@@ -4447,20 +4433,20 @@ pub const Object = struct {
4447 /// types to work around a LLVM deficiency when targeting ARM/AArch64.4433 /// types to work around a LLVM deficiency when targeting ARM/AArch64.
4448 fn getAtomicAbiType(o: *Object, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {4434 fn getAtomicAbiType(o: *Object, ty: Type, is_rmw_xchg: bool) Allocator.Error!Builder.Type {
4449 const pt = o.pt;4435 const pt = o.pt;
4450 const mod = pt.zcu;4436 const zcu = pt.zcu;
4451 const int_ty = switch (ty.zigTypeTag(mod)) {4437 const int_ty = switch (ty.zigTypeTag(zcu)) {
4452 .Int => ty,4438 .Int => ty,
4453 .Enum => ty.intTagType(mod),4439 .Enum => ty.intTagType(zcu),
4454 .Float => {4440 .Float => {
4455 if (!is_rmw_xchg) return .none;4441 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));
4457 },4443 },
4458 .Bool => return .i8,4444 .Bool => return .i8,
4459 else => return .none,4445 else => return .none,
4460 };4446 };
4461 const bit_count = int_ty.intInfo(mod).bits;4447 const bit_count = int_ty.intInfo(zcu).bits;
4462 if (!std.math.isPowerOfTwo(bit_count) or (bit_count % 8) != 0) {4448 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));
4464 } else {4450 } else {
4465 return .none;4451 return .none;
4466 }4452 }
...@@ -4475,15 +4461,15 @@ pub const Object = struct {...@@ -4475,15 +4461,15 @@ pub const Object = struct {
4475 llvm_arg_i: u32,4461 llvm_arg_i: u32,
4476 ) Allocator.Error!void {4462 ) Allocator.Error!void {
4477 const pt = o.pt;4463 const pt = o.pt;
4478 const mod = pt.zcu;4464 const zcu = pt.zcu;
4479 if (param_ty.isPtrAtRuntime(mod)) {4465 if (param_ty.isPtrAtRuntime(zcu)) {
4480 const ptr_info = param_ty.ptrInfo(mod);4466 const ptr_info = param_ty.ptrInfo(zcu);
4481 if (math.cast(u5, param_index)) |i| {4467 if (math.cast(u5, param_index)) |i| {
4482 if (@as(u1, @truncate(fn_info.noalias_bits >> i)) != 0) {4468 if (@as(u1, @truncate(fn_info.noalias_bits >> i)) != 0) {
4483 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);4469 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
4484 }4470 }
4485 }4471 }
4486 if (!param_ty.isPtrLikeOptional(mod) and !ptr_info.flags.is_allowzero) {4472 if (!param_ty.isPtrLikeOptional(zcu) and !ptr_info.flags.is_allowzero) {
4487 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);4473 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
4488 }4474 }
4489 if (fn_info.cc == .Interrupt) {4475 if (fn_info.cc == .Interrupt) {
...@@ -4496,9 +4482,9 @@ pub const Object = struct {...@@ -4496,9 +4482,9 @@ pub const Object = struct {
4496 const elem_align = if (ptr_info.flags.alignment != .none)4482 const elem_align = if (ptr_info.flags.alignment != .none)
4497 ptr_info.flags.alignment4483 ptr_info.flags.alignment
4498 else4484 else
4499 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1");4485 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1");
4500 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align.toLlvm() }, &o.builder);4486 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) {
4502 .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder),4488 .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder),
4503 .unsigned => try attributes.addParamAttr(llvm_arg_i, .zeroext, &o.builder),4489 .unsigned => try attributes.addParamAttr(llvm_arg_i, .zeroext, &o.builder),
4504 };4490 };
...@@ -4814,14 +4800,14 @@ pub const FuncGen = struct {...@@ -4814,14 +4800,14 @@ pub const FuncGen = struct {
48144800
4815 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {4801 fn resolveValue(self: *FuncGen, val: Value) Error!Builder.Constant {
4816 const o = self.ng.object;4802 const o = self.ng.object;
4817 const pt = o.pt;4803 const zcu = o.pt.zcu;
4818 const ty = val.typeOf(pt.zcu);4804 const ty = val.typeOf(zcu);
4819 const llvm_val = try o.lowerValue(val.toIntern());4805 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
4822 // We have an LLVM value but we need to create a global constant and4808 // We have an LLVM value but we need to create a global constant and
4823 // set the value as its initializer, and then return a pointer to the global.4809 // 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();
4825 const variable_index = try o.builder.addVariable(4811 const variable_index = try o.builder.addVariable(
4826 .empty,4812 .empty,
4827 llvm_val.typeOf(&o.builder),4813 llvm_val.typeOf(&o.builder),
...@@ -4831,7 +4817,7 @@ pub const FuncGen = struct {...@@ -4831,7 +4817,7 @@ pub const FuncGen = struct {
4831 variable_index.setLinkage(.private, &o.builder);4817 variable_index.setLinkage(.private, &o.builder);
4832 variable_index.setMutability(.constant, &o.builder);4818 variable_index.setMutability(.constant, &o.builder);
4833 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);4819 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);
4835 return o.builder.convConst(4821 return o.builder.convConst(
4836 variable_index.toConst(&o.builder),4822 variable_index.toConst(&o.builder),
4837 try o.builder.ptrType(toLlvmAddressSpace(.generic, target)),4823 try o.builder.ptrType(toLlvmAddressSpace(.generic, target)),
...@@ -4852,8 +4838,8 @@ pub const FuncGen = struct {...@@ -4852,8 +4838,8 @@ pub const FuncGen = struct {
48524838
4853 fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void {4839 fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void {
4854 const o = self.ng.object;4840 const o = self.ng.object;
4855 const mod = o.pt.zcu;4841 const zcu = o.pt.zcu;
4856 const ip = &mod.intern_pool;4842 const ip = &zcu.intern_pool;
4857 const air_tags = self.air.instructions.items(.tag);4843 const air_tags = self.air.instructions.items(.tag);
4858 for (body, 0..) |inst, i| {4844 for (body, 0..) |inst, i| {
4859 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;4845 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip)) continue;
...@@ -5200,19 +5186,19 @@ pub const FuncGen = struct {...@@ -5200,19 +5186,19 @@ pub const FuncGen = struct {
5200 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);5186 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
5201 const o = self.ng.object;5187 const o = self.ng.object;
5202 const pt = o.pt;5188 const pt = o.pt;
5203 const mod = pt.zcu;5189 const zcu = pt.zcu;
5204 const ip = &mod.intern_pool;5190 const ip = &zcu.intern_pool;
5205 const callee_ty = self.typeOf(pl_op.operand);5191 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)) {
5207 .Fn => callee_ty,5193 .Fn => callee_ty,
5208 .Pointer => callee_ty.childType(mod),5194 .Pointer => callee_ty.childType(zcu),
5209 else => unreachable,5195 else => unreachable,
5210 };5196 };
5211 const fn_info = mod.typeToFunc(zig_fn_ty).?;5197 const fn_info = zcu.typeToFunc(zig_fn_ty).?;
5212 const return_type = Type.fromInterned(fn_info.return_type);5198 const return_type = Type.fromInterned(fn_info.return_type);
5213 const llvm_fn = try self.resolveInst(pl_op.operand);5199 const llvm_fn = try self.resolveInst(pl_op.operand);
5214 const target = mod.getTarget();5200 const target = zcu.getTarget();
5215 const sret = firstParamSRet(fn_info, pt, target);5201 const sret = firstParamSRet(fn_info, zcu, target);
52165202
5217 var llvm_args = std.ArrayList(Builder.Value).init(self.gpa);5203 var llvm_args = std.ArrayList(Builder.Value).init(self.gpa);
5218 defer llvm_args.deinit();5204 defer llvm_args.deinit();
...@@ -5230,13 +5216,13 @@ pub const FuncGen = struct {...@@ -5230,13 +5216,13 @@ pub const FuncGen = struct {
5230 const llvm_ret_ty = try o.lowerType(return_type);5216 const llvm_ret_ty = try o.lowerType(return_type);
5231 try attributes.addParamAttr(0, .{ .sret = llvm_ret_ty }, &o.builder);5217 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();
5234 const ret_ptr = try self.buildAllocaWorkaround(return_type, alignment);5220 const ret_ptr = try self.buildAllocaWorkaround(return_type, alignment);
5235 try llvm_args.append(ret_ptr);5221 try llvm_args.append(ret_ptr);
5236 break :blk ret_ptr;5222 break :blk ret_ptr;
5237 };5223 };
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;
5240 if (err_return_tracing) {5226 if (err_return_tracing) {
5241 assert(self.err_ret_trace != .none);5227 assert(self.err_ret_trace != .none);
5242 try llvm_args.append(self.err_ret_trace);5228 try llvm_args.append(self.err_ret_trace);
...@@ -5250,8 +5236,8 @@ pub const FuncGen = struct {...@@ -5250,8 +5236,8 @@ pub const FuncGen = struct {
5250 const param_ty = self.typeOf(arg);5236 const param_ty = self.typeOf(arg);
5251 const llvm_arg = try self.resolveInst(arg);5237 const llvm_arg = try self.resolveInst(arg);
5252 const llvm_param_ty = try o.lowerType(param_ty);5238 const llvm_param_ty = try o.lowerType(param_ty);
5253 if (isByRef(param_ty, pt)) {5239 if (isByRef(param_ty, zcu)) {
5254 const alignment = param_ty.abiAlignment(pt).toLlvm();5240 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5255 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");5241 const loaded = try self.wip.load(.normal, llvm_param_ty, llvm_arg, alignment, "");
5256 try llvm_args.append(loaded);5242 try llvm_args.append(loaded);
5257 } else {5243 } else {
...@@ -5262,10 +5248,10 @@ pub const FuncGen = struct {...@@ -5262,10 +5248,10 @@ pub const FuncGen = struct {
5262 const arg = args[it.zig_index - 1];5248 const arg = args[it.zig_index - 1];
5263 const param_ty = self.typeOf(arg);5249 const param_ty = self.typeOf(arg);
5264 const llvm_arg = try self.resolveInst(arg);5250 const llvm_arg = try self.resolveInst(arg);
5265 if (isByRef(param_ty, pt)) {5251 if (isByRef(param_ty, zcu)) {
5266 try llvm_args.append(llvm_arg);5252 try llvm_args.append(llvm_arg);
5267 } else {5253 } else {
5268 const alignment = param_ty.abiAlignment(pt).toLlvm();5254 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5269 const param_llvm_ty = llvm_arg.typeOfWip(&self.wip);5255 const param_llvm_ty = llvm_arg.typeOfWip(&self.wip);
5270 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);5256 const arg_ptr = try self.buildAlloca(param_llvm_ty, alignment);
5271 _ = try self.wip.store(.normal, llvm_arg, arg_ptr, alignment);5257 _ = try self.wip.store(.normal, llvm_arg, arg_ptr, alignment);
...@@ -5277,10 +5263,10 @@ pub const FuncGen = struct {...@@ -5277,10 +5263,10 @@ pub const FuncGen = struct {
5277 const param_ty = self.typeOf(arg);5263 const param_ty = self.typeOf(arg);
5278 const llvm_arg = try self.resolveInst(arg);5264 const llvm_arg = try self.resolveInst(arg);
52795265
5280 const alignment = param_ty.abiAlignment(pt).toLlvm();5266 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5281 const param_llvm_ty = try o.lowerType(param_ty);5267 const param_llvm_ty = try o.lowerType(param_ty);
5282 const arg_ptr = try self.buildAllocaWorkaround(param_ty, alignment);5268 const arg_ptr = try self.buildAllocaWorkaround(param_ty, alignment);
5283 if (isByRef(param_ty, pt)) {5269 if (isByRef(param_ty, zcu)) {
5284 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");5270 const loaded = try self.wip.load(.normal, param_llvm_ty, llvm_arg, alignment, "");
5285 _ = try self.wip.store(.normal, loaded, arg_ptr, alignment);5271 _ = try self.wip.store(.normal, loaded, arg_ptr, alignment);
5286 } else {5272 } else {
...@@ -5292,16 +5278,16 @@ pub const FuncGen = struct {...@@ -5292,16 +5278,16 @@ pub const FuncGen = struct {
5292 const arg = args[it.zig_index - 1];5278 const arg = args[it.zig_index - 1];
5293 const param_ty = self.typeOf(arg);5279 const param_ty = self.typeOf(arg);
5294 const llvm_arg = try self.resolveInst(arg);5280 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)) {5283 if (isByRef(param_ty, zcu)) {
5298 const alignment = param_ty.abiAlignment(pt).toLlvm();5284 const alignment = param_ty.abiAlignment(zcu).toLlvm();
5299 const loaded = try self.wip.load(.normal, int_llvm_ty, llvm_arg, alignment, "");5285 const loaded = try self.wip.load(.normal, int_llvm_ty, llvm_arg, alignment, "");
5300 try llvm_args.append(loaded);5286 try llvm_args.append(loaded);
5301 } else {5287 } else {
5302 // LLVM does not allow bitcasting structs so we must allocate5288 // LLVM does not allow bitcasting structs so we must allocate
5303 // a local, store as one type, and then load as another type.5289 // 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();
5305 const int_ptr = try self.buildAllocaWorkaround(param_ty, alignment);5291 const int_ptr = try self.buildAllocaWorkaround(param_ty, alignment);
5306 _ = try self.wip.store(.normal, llvm_arg, int_ptr, alignment);5292 _ = try self.wip.store(.normal, llvm_arg, int_ptr, alignment);
5307 const loaded = try self.wip.load(.normal, int_llvm_ty, int_ptr, alignment, "");5293 const loaded = try self.wip.load(.normal, int_llvm_ty, int_ptr, alignment, "");
...@@ -5320,9 +5306,9 @@ pub const FuncGen = struct {...@@ -5320,9 +5306,9 @@ pub const FuncGen = struct {
5320 const param_ty = self.typeOf(arg);5306 const param_ty = self.typeOf(arg);
5321 const llvm_types = it.types_buffer[0..it.types_len];5307 const llvm_types = it.types_buffer[0..it.types_len];
5322 const llvm_arg = try self.resolveInst(arg);5308 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);
5324 const arg_ptr = if (is_by_ref) llvm_arg else ptr: {5310 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();
5326 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);5312 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
5327 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);5313 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
5328 break :ptr ptr;5314 break :ptr ptr;
...@@ -5348,14 +5334,14 @@ pub const FuncGen = struct {...@@ -5348,14 +5334,14 @@ pub const FuncGen = struct {
5348 const arg = args[it.zig_index - 1];5334 const arg = args[it.zig_index - 1];
5349 const arg_ty = self.typeOf(arg);5335 const arg_ty = self.typeOf(arg);
5350 var llvm_arg = try self.resolveInst(arg);5336 var llvm_arg = try self.resolveInst(arg);
5351 const alignment = arg_ty.abiAlignment(pt).toLlvm();5337 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
5352 if (!isByRef(arg_ty, pt)) {5338 if (!isByRef(arg_ty, zcu)) {
5353 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);5339 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
5354 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);5340 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
5355 llvm_arg = ptr;5341 llvm_arg = ptr;
5356 }5342 }
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).?);
5359 const array_ty = try o.builder.arrayType(count, float_ty);5345 const array_ty = try o.builder.arrayType(count, float_ty);
53605346
5361 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");5347 const loaded = try self.wip.load(.normal, array_ty, llvm_arg, alignment, "");
...@@ -5366,8 +5352,8 @@ pub const FuncGen = struct {...@@ -5366,8 +5352,8 @@ pub const FuncGen = struct {
5366 const arg = args[it.zig_index - 1];5352 const arg = args[it.zig_index - 1];
5367 const arg_ty = self.typeOf(arg);5353 const arg_ty = self.typeOf(arg);
5368 var llvm_arg = try self.resolveInst(arg);5354 var llvm_arg = try self.resolveInst(arg);
5369 const alignment = arg_ty.abiAlignment(pt).toLlvm();5355 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
5370 if (!isByRef(arg_ty, pt)) {5356 if (!isByRef(arg_ty, zcu)) {
5371 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);5357 const ptr = try self.buildAlloca(llvm_arg.typeOfWip(&self.wip), alignment);
5372 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);5358 _ = try self.wip.store(.normal, llvm_arg, ptr, alignment);
5373 llvm_arg = ptr;5359 llvm_arg = ptr;
...@@ -5389,7 +5375,7 @@ pub const FuncGen = struct {...@@ -5389,7 +5375,7 @@ pub const FuncGen = struct {
5389 .byval => {5375 .byval => {
5390 const param_index = it.zig_index - 1;5376 const param_index = it.zig_index - 1;
5391 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);5377 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)) {
5393 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);5379 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
5394 }5380 }
5395 },5381 },
...@@ -5397,7 +5383,7 @@ pub const FuncGen = struct {...@@ -5397,7 +5383,7 @@ pub const FuncGen = struct {
5397 const param_index = it.zig_index - 1;5383 const param_index = it.zig_index - 1;
5398 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);5384 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
5399 const param_llvm_ty = try o.lowerType(param_ty);5385 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();
5401 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);5387 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
5402 },5388 },
5403 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),5389 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
...@@ -5414,7 +5400,7 @@ pub const FuncGen = struct {...@@ -5414,7 +5400,7 @@ pub const FuncGen = struct {
5414 .slice => {5400 .slice => {
5415 assert(!it.byval_attr);5401 assert(!it.byval_attr);
5416 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);5402 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);
5418 const llvm_arg_i = it.llvm_index - 2;5404 const llvm_arg_i = it.llvm_index - 2;
54195405
5420 if (math.cast(u5, it.zig_index - 1)) |i| {5406 if (math.cast(u5, it.zig_index - 1)) |i| {
...@@ -5422,7 +5408,7 @@ pub const FuncGen = struct {...@@ -5422,7 +5408,7 @@ pub const FuncGen = struct {
5422 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);5408 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
5423 }5409 }
5424 }5410 }
5425 if (param_ty.zigTypeTag(mod) != .Optional) {5411 if (param_ty.zigTypeTag(zcu) != .Optional) {
5426 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);5412 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
5427 }5413 }
5428 if (ptr_info.flags.is_const) {5414 if (ptr_info.flags.is_const) {
...@@ -5431,7 +5417,7 @@ pub const FuncGen = struct {...@@ -5431,7 +5417,7 @@ pub const FuncGen = struct {
5431 const elem_align = (if (ptr_info.flags.alignment != .none)5417 const elem_align = (if (ptr_info.flags.alignment != .none)
5432 @as(InternPool.Alignment, ptr_info.flags.alignment)5418 @as(InternPool.Alignment, ptr_info.flags.alignment)
5433 else5419 else
5434 Type.fromInterned(ptr_info.child).abiAlignment(pt).max(.@"1")).toLlvm();5420 Type.fromInterned(ptr_info.child).abiAlignment(zcu).max(.@"1")).toLlvm();
5435 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);5421 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
5436 },5422 },
5437 };5423 };
...@@ -5456,17 +5442,17 @@ pub const FuncGen = struct {...@@ -5456,17 +5442,17 @@ pub const FuncGen = struct {
5456 return .none;5442 return .none;
5457 }5443 }
54585444
5459 if (self.liveness.isUnused(inst) or !return_type.hasRuntimeBitsIgnoreComptime(pt)) {5445 if (self.liveness.isUnused(inst) or !return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
5460 return .none;5446 return .none;
5461 }5447 }
54625448
5463 const llvm_ret_ty = try o.lowerType(return_type);5449 const llvm_ret_ty = try o.lowerType(return_type);
5464 if (ret_ptr) |rp| {5450 if (ret_ptr) |rp| {
5465 if (isByRef(return_type, pt)) {5451 if (isByRef(return_type, zcu)) {
5466 return rp;5452 return rp;
5467 } else {5453 } else {
5468 // our by-ref status disagrees with sret so we must load.5454 // 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();
5470 return self.wip.load(.normal, llvm_ret_ty, rp, return_alignment, "");5456 return self.wip.load(.normal, llvm_ret_ty, rp, return_alignment, "");
5471 }5457 }
5472 }5458 }
...@@ -5477,19 +5463,19 @@ pub const FuncGen = struct {...@@ -5477,19 +5463,19 @@ pub const FuncGen = struct {
5477 // In this case the function return type is honoring the calling convention by having5463 // In this case the function return type is honoring the calling convention by having
5478 // a different LLVM type than the usual one. We solve this here at the callsite5464 // a different LLVM type than the usual one. We solve this here at the callsite
5479 // by using our canonical type, then loading it if necessary.5465 // 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();
5481 const rp = try self.buildAlloca(abi_ret_ty, alignment);5467 const rp = try self.buildAlloca(abi_ret_ty, alignment);
5482 _ = try self.wip.store(.normal, call, rp, alignment);5468 _ = try self.wip.store(.normal, call, rp, alignment);
5483 return if (isByRef(return_type, pt))5469 return if (isByRef(return_type, zcu))
5484 rp5470 rp
5485 else5471 else
5486 try self.wip.load(.normal, llvm_ret_ty, rp, alignment, "");5472 try self.wip.load(.normal, llvm_ret_ty, rp, alignment, "");
5487 }5473 }
54885474
5489 if (isByRef(return_type, pt)) {5475 if (isByRef(return_type, zcu)) {
5490 // our by-ref status disagrees with sret so we must allocate, store,5476 // our by-ref status disagrees with sret so we must allocate, store,
5491 // and return the allocation pointer.5477 // and return the allocation pointer.
5492 const alignment = return_type.abiAlignment(pt).toLlvm();5478 const alignment = return_type.abiAlignment(zcu).toLlvm();
5493 const rp = try self.buildAlloca(llvm_ret_ty, alignment);5479 const rp = try self.buildAlloca(llvm_ret_ty, alignment);
5494 _ = try self.wip.store(.normal, call, rp, alignment);5480 _ = try self.wip.store(.normal, call, rp, alignment);
5495 return rp;5481 return rp;
...@@ -5540,8 +5526,8 @@ pub const FuncGen = struct {...@@ -5540,8 +5526,8 @@ pub const FuncGen = struct {
5540 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {5526 fn airRet(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
5541 const o = self.ng.object;5527 const o = self.ng.object;
5542 const pt = o.pt;5528 const pt = o.pt;
5543 const mod = pt.zcu;5529 const zcu = pt.zcu;
5544 const ip = &mod.intern_pool;5530 const ip = &zcu.intern_pool;
5545 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5531 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5546 const ret_ty = self.typeOf(un_op);5532 const ret_ty = self.typeOf(un_op);
55475533
...@@ -5549,9 +5535,9 @@ pub const FuncGen = struct {...@@ -5549,9 +5535,9 @@ pub const FuncGen = struct {
5549 const ptr_ty = try pt.singleMutPtrType(ret_ty);5535 const ptr_ty = try pt.singleMutPtrType(ret_ty);
55505536
5551 const operand = try self.resolveInst(un_op);5537 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;
5553 if (val_is_undef and safety) undef: {5539 if (val_is_undef and safety) undef: {
5554 const ptr_info = ptr_ty.ptrInfo(mod);5540 const ptr_info = ptr_ty.ptrInfo(zcu);
5555 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);5541 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);
5556 if (needs_bitmask) {5542 if (needs_bitmask) {
5557 // TODO: only some bits are to be undef, we cannot write with a simple memset.5543 // TODO: only some bits are to be undef, we cannot write with a simple memset.
...@@ -5559,13 +5545,13 @@ pub const FuncGen = struct {...@@ -5559,13 +5545,13 @@ pub const FuncGen = struct {
5559 // https://github.com/ziglang/zig/issues/153375545 // https://github.com/ziglang/zig/issues/15337
5560 break :undef;5546 break :undef;
5561 }5547 }
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));
5563 _ = try self.wip.callMemSet(5549 _ = try self.wip.callMemSet(
5564 self.ret_ptr,5550 self.ret_ptr,
5565 ptr_ty.ptrAlignment(pt).toLlvm(),5551 ptr_ty.ptrAlignment(zcu).toLlvm(),
5566 try o.builder.intValue(.i8, 0xaa),5552 try o.builder.intValue(.i8, 0xaa),
5567 len,5553 len,
5568 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,5554 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
5569 );5555 );
5570 const owner_mod = self.ng.ownerModule();5556 const owner_mod = self.ng.ownerModule();
5571 if (owner_mod.valgrind) {5557 if (owner_mod.valgrind) {
...@@ -5588,9 +5574,9 @@ pub const FuncGen = struct {...@@ -5588,9 +5574,9 @@ pub const FuncGen = struct {
5588 _ = try self.wip.retVoid();5574 _ = try self.wip.retVoid();
5589 return .none;5575 return .none;
5590 }5576 }
5591 const fn_info = mod.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;5577 const fn_info = zcu.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5592 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {5578 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5593 if (Type.fromInterned(fn_info.return_type).isError(mod)) {5579 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
5594 // Functions with an empty error set are emitted with an error code5580 // Functions with an empty error set are emitted with an error code
5595 // return type and return zero so they can be function pointers coerced5581 // return type and return zero so they can be function pointers coerced
5596 // to functions that return anyerror.5582 // to functions that return anyerror.
...@@ -5603,13 +5589,13 @@ pub const FuncGen = struct {...@@ -5603,13 +5589,13 @@ pub const FuncGen = struct {
56035589
5604 const abi_ret_ty = try lowerFnRetTy(o, fn_info);5590 const abi_ret_ty = try lowerFnRetTy(o, fn_info);
5605 const operand = try self.resolveInst(un_op);5591 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;5592 const val_is_undef = if (try self.air.value(un_op, pt)) |val| val.isUndefDeep(zcu) else false;
5607 const alignment = ret_ty.abiAlignment(pt).toLlvm();5593 const alignment = ret_ty.abiAlignment(zcu).toLlvm();
56085594
5609 if (val_is_undef and safety) {5595 if (val_is_undef and safety) {
5610 const llvm_ret_ty = operand.typeOfWip(&self.wip);5596 const llvm_ret_ty = operand.typeOfWip(&self.wip);
5611 const rp = try self.buildAlloca(llvm_ret_ty, alignment);5597 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));
5613 _ = try self.wip.callMemSet(5599 _ = try self.wip.callMemSet(
5614 rp,5600 rp,
5615 alignment,5601 alignment,
...@@ -5625,7 +5611,7 @@ pub const FuncGen = struct {...@@ -5625,7 +5611,7 @@ pub const FuncGen = struct {
5625 return .none;5611 return .none;
5626 }5612 }
56275613
5628 if (isByRef(ret_ty, pt)) {5614 if (isByRef(ret_ty, zcu)) {
5629 // operand is a pointer however self.ret_ptr is null so that means5615 // operand is a pointer however self.ret_ptr is null so that means
5630 // we need to return a value.5616 // we need to return a value.
5631 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, operand, alignment, ""));5617 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, operand, alignment, ""));
...@@ -5647,14 +5633,14 @@ pub const FuncGen = struct {...@@ -5647,14 +5633,14 @@ pub const FuncGen = struct {
5647 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5633 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5648 const o = self.ng.object;5634 const o = self.ng.object;
5649 const pt = o.pt;5635 const pt = o.pt;
5650 const mod = pt.zcu;5636 const zcu = pt.zcu;
5651 const ip = &mod.intern_pool;5637 const ip = &zcu.intern_pool;
5652 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5638 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5653 const ptr_ty = self.typeOf(un_op);5639 const ptr_ty = self.typeOf(un_op);
5654 const ret_ty = ptr_ty.childType(mod);5640 const ret_ty = ptr_ty.childType(zcu);
5655 const fn_info = mod.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;5641 const fn_info = zcu.typeToFunc(Type.fromInterned(ip.getNav(self.ng.nav_index).typeOf(ip))).?;
5656 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {5642 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5657 if (Type.fromInterned(fn_info.return_type).isError(mod)) {5643 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
5658 // Functions with an empty error set are emitted with an error code5644 // Functions with an empty error set are emitted with an error code
5659 // return type and return zero so they can be function pointers coerced5645 // return type and return zero so they can be function pointers coerced
5660 // to functions that return anyerror.5646 // to functions that return anyerror.
...@@ -5670,7 +5656,7 @@ pub const FuncGen = struct {...@@ -5670,7 +5656,7 @@ pub const FuncGen = struct {
5670 }5656 }
5671 const ptr = try self.resolveInst(un_op);5657 const ptr = try self.resolveInst(un_op);
5672 const abi_ret_ty = try lowerFnRetTy(o, fn_info);5658 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();
5674 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));5660 _ = try self.wip.ret(try self.wip.load(.normal, abi_ret_ty, ptr, alignment, ""));
5675 return .none;5661 return .none;
5676 }5662 }
...@@ -5688,16 +5674,17 @@ pub const FuncGen = struct {...@@ -5688,16 +5674,17 @@ pub const FuncGen = struct {
5688 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5674 fn airCVaCopy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5689 const o = self.ng.object;5675 const o = self.ng.object;
5690 const pt = o.pt;5676 const pt = o.pt;
5677 const zcu = pt.zcu;
5691 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5678 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5692 const src_list = try self.resolveInst(ty_op.operand);5679 const src_list = try self.resolveInst(ty_op.operand);
5693 const va_list_ty = ty_op.ty.toType();5680 const va_list_ty = ty_op.ty.toType();
5694 const llvm_va_list_ty = try o.lowerType(va_list_ty);5681 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();
5697 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);5684 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);
56985685
5699 _ = try self.wip.callIntrinsic(.normal, .none, .va_copy, &.{}, &.{ dest_list, src_list }, "");5686 _ = 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))
5701 dest_list5688 dest_list
5702 else5689 else
5703 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");5690 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");
...@@ -5714,14 +5701,15 @@ pub const FuncGen = struct {...@@ -5714,14 +5701,15 @@ pub const FuncGen = struct {
5714 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5701 fn airCVaStart(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5715 const o = self.ng.object;5702 const o = self.ng.object;
5716 const pt = o.pt;5703 const pt = o.pt;
5704 const zcu = pt.zcu;
5717 const va_list_ty = self.typeOfIndex(inst);5705 const va_list_ty = self.typeOfIndex(inst);
5718 const llvm_va_list_ty = try o.lowerType(va_list_ty);5706 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();
5721 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);5709 const dest_list = try self.buildAllocaWorkaround(va_list_ty, result_alignment);
57225710
5723 _ = try self.wip.callIntrinsic(.normal, .none, .va_start, &.{}, &.{dest_list}, "");5711 _ = 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))
5725 dest_list5713 dest_list
5726 else5714 else
5727 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");5715 try self.wip.load(.normal, llvm_va_list_ty, dest_list, result_alignment, "");
...@@ -5779,21 +5767,21 @@ pub const FuncGen = struct {...@@ -5779,21 +5767,21 @@ pub const FuncGen = struct {
5779 ) Allocator.Error!Builder.Value {5767 ) Allocator.Error!Builder.Value {
5780 const o = self.ng.object;5768 const o = self.ng.object;
5781 const pt = o.pt;5769 const pt = o.pt;
5782 const mod = pt.zcu;5770 const zcu = pt.zcu;
5783 const scalar_ty = operand_ty.scalarType(mod);5771 const scalar_ty = operand_ty.scalarType(zcu);
5784 const int_ty = switch (scalar_ty.zigTypeTag(mod)) {5772 const int_ty = switch (scalar_ty.zigTypeTag(zcu)) {
5785 .Enum => scalar_ty.intTagType(mod),5773 .Enum => scalar_ty.intTagType(zcu),
5786 .Int, .Bool, .Pointer, .ErrorSet => scalar_ty,5774 .Int, .Bool, .Pointer, .ErrorSet => scalar_ty,
5787 .Optional => blk: {5775 .Optional => blk: {
5788 const payload_ty = operand_ty.optionalChild(mod);5776 const payload_ty = operand_ty.optionalChild(zcu);
5789 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt) or5777 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu) or
5790 operand_ty.optionalReprIsPayload(mod))5778 operand_ty.optionalReprIsPayload(zcu))
5791 {5779 {
5792 break :blk operand_ty;5780 break :blk operand_ty;
5793 }5781 }
5794 // We need to emit instructions to check for equality/inequality5782 // We need to emit instructions to check for equality/inequality
5795 // of optionals that are not pointers.5783 // of optionals that are not pointers.
5796 const is_by_ref = isByRef(scalar_ty, pt);5784 const is_by_ref = isByRef(scalar_ty, zcu);
5797 const opt_llvm_ty = try o.lowerType(scalar_ty);5785 const opt_llvm_ty = try o.lowerType(scalar_ty);
5798 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref);5786 const lhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, lhs, is_by_ref);
5799 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref);5787 const rhs_non_null = try self.optCmpNull(.ne, opt_llvm_ty, rhs, is_by_ref);
...@@ -5860,7 +5848,7 @@ pub const FuncGen = struct {...@@ -5860,7 +5848,7 @@ pub const FuncGen = struct {
5860 .Float => return self.buildFloatCmp(fast, op, operand_ty, .{ lhs, rhs }),5848 .Float => return self.buildFloatCmp(fast, op, operand_ty, .{ lhs, rhs }),
5861 else => unreachable,5849 else => unreachable,
5862 };5850 };
5863 const is_signed = int_ty.isSignedInt(mod);5851 const is_signed = int_ty.isSignedInt(zcu);
5864 const cond: Builder.IntegerCondition = switch (op) {5852 const cond: Builder.IntegerCondition = switch (op) {
5865 .eq => .eq,5853 .eq => .eq,
5866 .neq => .ne,5854 .neq => .ne,
...@@ -5886,15 +5874,15 @@ pub const FuncGen = struct {...@@ -5886,15 +5874,15 @@ pub const FuncGen = struct {
5886 ) !Builder.Value {5874 ) !Builder.Value {
5887 const o = self.ng.object;5875 const o = self.ng.object;
5888 const pt = o.pt;5876 const pt = o.pt;
5889 const mod = pt.zcu;5877 const zcu = pt.zcu;
5890 const inst_ty = self.typeOfIndex(inst);5878 const inst_ty = self.typeOfIndex(inst);
58915879
5892 if (inst_ty.isNoReturn(mod)) {5880 if (inst_ty.isNoReturn(zcu)) {
5893 try self.genBodyDebugScope(maybe_inline_func, body);5881 try self.genBodyDebugScope(maybe_inline_func, body);
5894 return .none;5882 return .none;
5895 }5883 }
58965884
5897 const have_block_result = inst_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt);5885 const have_block_result = inst_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu);
58985886
5899 var breaks: BreakList = if (have_block_result) .{ .list = .{} } else .{ .len = 0 };5887 var breaks: BreakList = if (have_block_result) .{ .list = .{} } else .{ .len = 0 };
5900 defer if (have_block_result) breaks.list.deinit(self.gpa);5888 defer if (have_block_result) breaks.list.deinit(self.gpa);
...@@ -5918,7 +5906,7 @@ pub const FuncGen = struct {...@@ -5918,7 +5906,7 @@ pub const FuncGen = struct {
5918 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead5906 // a pointer to it. LLVM IR allows the call instruction to use function bodies instead
5919 // of function pointers, however the phi makes it a runtime value and therefore5907 // of function pointers, however the phi makes it a runtime value and therefore
5920 // the LLVM type has to be wrapped in a pointer.5908 // 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)) {
5922 break :ty .ptr;5910 break :ty .ptr;
5923 }5911 }
5924 break :ty raw_llvm_ty;5912 break :ty raw_llvm_ty;
...@@ -5936,13 +5924,13 @@ pub const FuncGen = struct {...@@ -5936,13 +5924,13 @@ pub const FuncGen = struct {
59365924
5937 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5925 fn airBr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5938 const o = self.ng.object;5926 const o = self.ng.object;
5939 const pt = o.pt;5927 const zcu = o.pt.zcu;
5940 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;5928 const branch = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
5941 const block = self.blocks.get(branch.block_inst).?;5929 const block = self.blocks.get(branch.block_inst).?;
59425930
5943 // Add the values to the lists only if the break provides a value.5931 // Add the values to the lists only if the break provides a value.
5944 const operand_ty = self.typeOf(branch.operand);5932 const operand_ty = self.typeOf(branch.operand);
5945 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {5933 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
5946 const val = try self.resolveInst(branch.operand);5934 const val = try self.resolveInst(branch.operand);
59475935
5948 // For the phi node, we need the basic blocks and the values of the5936 // For the phi node, we need the basic blocks and the values of the
...@@ -5977,6 +5965,7 @@ pub const FuncGen = struct {...@@ -5977,6 +5965,7 @@ pub const FuncGen = struct {
5977 fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {5965 fn airTry(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
5978 const o = self.ng.object;5966 const o = self.ng.object;
5979 const pt = o.pt;5967 const pt = o.pt;
5968 const zcu = pt.zcu;
5980 const inst = body_tail[0];5969 const inst = body_tail[0];
5981 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;5970 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5982 const err_union = try self.resolveInst(pl_op.operand);5971 const err_union = try self.resolveInst(pl_op.operand);
...@@ -5984,19 +5973,19 @@ pub const FuncGen = struct {...@@ -5984,19 +5973,19 @@ pub const FuncGen = struct {
5984 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);5973 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);
5985 const err_union_ty = self.typeOf(pl_op.operand);5974 const err_union_ty = self.typeOf(pl_op.operand);
5986 const payload_ty = self.typeOfIndex(inst);5975 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;
5988 const is_unused = self.liveness.isUnused(inst);5977 const is_unused = self.liveness.isUnused(inst);
5989 return lowerTry(self, err_union, body, err_union_ty, false, can_elide_load, is_unused);5978 return lowerTry(self, err_union, body, err_union_ty, false, can_elide_load, is_unused);
5990 }5979 }
59915980
5992 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {5981 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
5993 const o = self.ng.object;5982 const o = self.ng.object;
5994 const mod = o.pt.zcu;5983 const zcu = o.pt.zcu;
5995 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5984 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5996 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);5985 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
5997 const err_union_ptr = try self.resolveInst(extra.data.ptr);5986 const err_union_ptr = try self.resolveInst(extra.data.ptr);
5998 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]);5987 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);
6000 const is_unused = self.liveness.isUnused(inst);5989 const is_unused = self.liveness.isUnused(inst);
6001 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);5990 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);
6002 }5991 }
...@@ -6012,13 +6001,13 @@ pub const FuncGen = struct {...@@ -6012,13 +6001,13 @@ pub const FuncGen = struct {
6012 ) !Builder.Value {6001 ) !Builder.Value {
6013 const o = fg.ng.object;6002 const o = fg.ng.object;
6014 const pt = o.pt;6003 const pt = o.pt;
6015 const mod = pt.zcu;6004 const zcu = pt.zcu;
6016 const payload_ty = err_union_ty.errorUnionPayload(mod);6005 const payload_ty = err_union_ty.errorUnionPayload(zcu);
6017 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(pt);6006 const payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu);
6018 const err_union_llvm_ty = try o.lowerType(err_union_ty);6007 const err_union_llvm_ty = try o.lowerType(err_union_ty);
6019 const error_type = try o.errorIntType();6008 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)) {
6022 const loaded = loaded: {6011 const loaded = loaded: {
6023 if (!payload_has_bits) {6012 if (!payload_has_bits) {
6024 // TODO add alignment to this load6013 // TODO add alignment to this load
...@@ -6028,7 +6017,7 @@ pub const FuncGen = struct {...@@ -6028,7 +6017,7 @@ pub const FuncGen = struct {
6028 err_union;6017 err_union;
6029 }6018 }
6030 const err_field_index = try errUnionErrorOffset(payload_ty, pt);6019 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)) {
6032 const err_field_ptr =6021 const err_field_ptr =
6033 try fg.wip.gepStruct(err_union_llvm_ty, err_union, err_field_index, "");6022 try fg.wip.gepStruct(err_union_llvm_ty, err_union, err_field_index, "");
6034 // TODO add alignment to this load6023 // TODO add alignment to this load
...@@ -6059,10 +6048,10 @@ pub const FuncGen = struct {...@@ -6059,10 +6048,10 @@ pub const FuncGen = struct {
6059 const offset = try errUnionPayloadOffset(payload_ty, pt);6048 const offset = try errUnionPayloadOffset(payload_ty, pt);
6060 if (operand_is_ptr) {6049 if (operand_is_ptr) {
6061 return fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");6050 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)) {
6063 const payload_ptr = try fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");6052 const payload_ptr = try fg.wip.gepStruct(err_union_llvm_ty, err_union, offset, "");
6064 const payload_alignment = payload_ty.abiAlignment(pt).toLlvm();6053 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
6065 if (isByRef(payload_ty, pt)) {6054 if (isByRef(payload_ty, zcu)) {
6066 if (can_elide_load)6055 if (can_elide_load)
6067 return payload_ptr;6056 return payload_ptr;
60686057
...@@ -6140,7 +6129,7 @@ pub const FuncGen = struct {...@@ -6140,7 +6129,7 @@ pub const FuncGen = struct {
61406129
6141 fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6130 fn airLoop(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6142 const o = self.ng.object;6131 const o = self.ng.object;
6143 const mod = o.pt.zcu;6132 const zcu = o.pt.zcu;
6144 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6133 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6145 const loop = self.air.extraData(Air.Block, ty_pl.payload);6134 const loop = self.air.extraData(Air.Block, ty_pl.payload);
6146 const body: []const Air.Inst.Index = @ptrCast(self.air.extra[loop.end..][0..loop.data.body_len]);6135 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 {...@@ -6156,7 +6145,7 @@ pub const FuncGen = struct {
6156 // would have been emitted already. Also the main loop in genBody can6145 // would have been emitted already. Also the main loop in genBody can
6157 // be while(true) instead of for(body), which will eliminate 1 branch on6146 // be while(true) instead of for(body), which will eliminate 1 branch on
6158 // a hot path.6147 // 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)) {
6160 _ = try self.wip.br(loop_block);6149 _ = try self.wip.br(loop_block);
6161 }6150 }
6162 return .none;6151 return .none;
...@@ -6165,15 +6154,15 @@ pub const FuncGen = struct {...@@ -6165,15 +6154,15 @@ pub const FuncGen = struct {
6165 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6154 fn airArrayToSlice(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6166 const o = self.ng.object;6155 const o = self.ng.object;
6167 const pt = o.pt;6156 const pt = o.pt;
6168 const mod = pt.zcu;6157 const zcu = pt.zcu;
6169 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6158 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6170 const operand_ty = self.typeOf(ty_op.operand);6159 const operand_ty = self.typeOf(ty_op.operand);
6171 const array_ty = operand_ty.childType(mod);6160 const array_ty = operand_ty.childType(zcu);
6172 const llvm_usize = try o.lowerType(Type.usize);6161 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));
6174 const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst));6163 const slice_llvm_ty = try o.lowerType(self.typeOfIndex(inst));
6175 const operand = try self.resolveInst(ty_op.operand);6164 const operand = try self.resolveInst(ty_op.operand);
6176 if (!array_ty.hasRuntimeBitsIgnoreComptime(pt))6165 if (!array_ty.hasRuntimeBitsIgnoreComptime(zcu))
6177 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");6166 return self.wip.buildAggregate(slice_llvm_ty, &.{ operand, len }, "");
6178 const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{6167 const ptr = try self.wip.gep(.inbounds, try o.lowerType(array_ty), operand, &.{
6179 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),6168 try o.builder.intValue(llvm_usize, 0), try o.builder.intValue(llvm_usize, 0),
...@@ -6184,17 +6173,17 @@ pub const FuncGen = struct {...@@ -6184,17 +6173,17 @@ pub const FuncGen = struct {
6184 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6173 fn airFloatFromInt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6185 const o = self.ng.object;6174 const o = self.ng.object;
6186 const pt = o.pt;6175 const pt = o.pt;
6187 const mod = pt.zcu;6176 const zcu = pt.zcu;
6188 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6177 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
61896178
6190 const workaround_operand = try self.resolveInst(ty_op.operand);6179 const workaround_operand = try self.resolveInst(ty_op.operand);
6191 const operand_ty = self.typeOf(ty_op.operand);6180 const operand_ty = self.typeOf(ty_op.operand);
6192 const operand_scalar_ty = operand_ty.scalarType(mod);6181 const operand_scalar_ty = operand_ty.scalarType(zcu);
6193 const is_signed_int = operand_scalar_ty.isSignedInt(mod);6182 const is_signed_int = operand_scalar_ty.isSignedInt(zcu);
61946183
6195 const operand = o: {6184 const operand = o: {
6196 // Work around LLVM bug. See https://github.com/ziglang/zig/issues/17381.6185 // 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);
6198 for ([_]u8{ 8, 16, 32, 64, 128 }) |b| {6187 for ([_]u8{ 8, 16, 32, 64, 128 }) |b| {
6199 if (bit_size < b) {6188 if (bit_size < b) {
6200 break :o try self.wip.cast(6189 break :o try self.wip.cast(
...@@ -6211,9 +6200,9 @@ pub const FuncGen = struct {...@@ -6211,9 +6200,9 @@ pub const FuncGen = struct {
6211 };6200 };
62126201
6213 const dest_ty = self.typeOfIndex(inst);6202 const dest_ty = self.typeOfIndex(inst);
6214 const dest_scalar_ty = dest_ty.scalarType(mod);6203 const dest_scalar_ty = dest_ty.scalarType(zcu);
6215 const dest_llvm_ty = try o.lowerType(dest_ty);6204 const dest_llvm_ty = try o.lowerType(dest_ty);
6216 const target = mod.getTarget();6205 const target = zcu.getTarget();
62176206
6218 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(6207 if (intrinsicsAllowed(dest_scalar_ty, target)) return self.wip.conv(
6219 if (is_signed_int) .signed else .unsigned,6208 if (is_signed_int) .signed else .unsigned,
...@@ -6222,7 +6211,7 @@ pub const FuncGen = struct {...@@ -6222,7 +6211,7 @@ pub const FuncGen = struct {
6222 "",6211 "",
6223 );6212 );
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)));
6226 const rt_int_ty = try o.builder.intType(rt_int_bits);6215 const rt_int_ty = try o.builder.intType(rt_int_bits);
6227 var extended = try self.wip.conv(6216 var extended = try self.wip.conv(
6228 if (is_signed_int) .signed else .unsigned,6217 if (is_signed_int) .signed else .unsigned,
...@@ -6269,29 +6258,29 @@ pub const FuncGen = struct {...@@ -6269,29 +6258,29 @@ pub const FuncGen = struct {
62696258
6270 const o = self.ng.object;6259 const o = self.ng.object;
6271 const pt = o.pt;6260 const pt = o.pt;
6272 const mod = pt.zcu;6261 const zcu = pt.zcu;
6273 const target = mod.getTarget();6262 const target = zcu.getTarget();
6274 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6263 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
62756264
6276 const operand = try self.resolveInst(ty_op.operand);6265 const operand = try self.resolveInst(ty_op.operand);
6277 const operand_ty = self.typeOf(ty_op.operand);6266 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
6280 const dest_ty = self.typeOfIndex(inst);6269 const dest_ty = self.typeOfIndex(inst);
6281 const dest_scalar_ty = dest_ty.scalarType(mod);6270 const dest_scalar_ty = dest_ty.scalarType(zcu);
6282 const dest_llvm_ty = try o.lowerType(dest_ty);6271 const dest_llvm_ty = try o.lowerType(dest_ty);
62836272
6284 if (intrinsicsAllowed(operand_scalar_ty, target)) {6273 if (intrinsicsAllowed(operand_scalar_ty, target)) {
6285 // TODO set fast math flag6274 // TODO set fast math flag
6286 return self.wip.conv(6275 return self.wip.conv(
6287 if (dest_scalar_ty.isSignedInt(mod)) .signed else .unsigned,6276 if (dest_scalar_ty.isSignedInt(zcu)) .signed else .unsigned,
6288 operand,6277 operand,
6289 dest_llvm_ty,6278 dest_llvm_ty,
6290 "",6279 "",
6291 );6280 );
6292 }6281 }
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)));
6295 const ret_ty = try o.builder.intType(rt_int_bits);6284 const ret_ty = try o.builder.intType(rt_int_bits);
6296 const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: {6285 const libc_ret_ty = if (rt_int_bits == 128 and (target.os.tag == .windows and target.cpu.arch == .x86_64)) b: {
6297 // On Windows x86-64, "ti" functions must use Vector(2, u64) instead of the standard6286 // On Windows x86-64, "ti" functions must use Vector(2, u64) instead of the standard
...@@ -6303,7 +6292,7 @@ pub const FuncGen = struct {...@@ -6303,7 +6292,7 @@ pub const FuncGen = struct {
6303 const compiler_rt_operand_abbrev = compilerRtFloatAbbrev(operand_bits);6292 const compiler_rt_operand_abbrev = compilerRtFloatAbbrev(operand_bits);
63046293
6305 const compiler_rt_dest_abbrev = compilerRtIntAbbrev(rt_int_bits);6294 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
6308 const fn_name = try o.builder.strtabStringFmt("__fix{s}{s}f{s}i", .{6297 const fn_name = try o.builder.strtabStringFmt("__fix{s}{s}f{s}i", .{
6309 sign_prefix,6298 sign_prefix,
...@@ -6330,29 +6319,29 @@ pub const FuncGen = struct {...@@ -6330,29 +6319,29 @@ pub const FuncGen = struct {
63306319
6331 fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {6320 fn sliceOrArrayPtr(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
6332 const o = fg.ng.object;6321 const o = fg.ng.object;
6333 const mod = o.pt.zcu;6322 const zcu = o.pt.zcu;
6334 return if (ty.isSlice(mod)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;6323 return if (ty.isSlice(zcu)) fg.wip.extractValue(ptr, &.{0}, "") else ptr;
6335 }6324 }
63366325
6337 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {6326 fn sliceOrArrayLenInBytes(fg: *FuncGen, ptr: Builder.Value, ty: Type) Allocator.Error!Builder.Value {
6338 const o = fg.ng.object;6327 const o = fg.ng.object;
6339 const pt = o.pt;6328 const pt = o.pt;
6340 const mod = pt.zcu;6329 const zcu = pt.zcu;
6341 const llvm_usize = try o.lowerType(Type.usize);6330 const llvm_usize = try o.lowerType(Type.usize);
6342 switch (ty.ptrSize(mod)) {6331 switch (ty.ptrSize(zcu)) {
6343 .Slice => {6332 .Slice => {
6344 const len = try fg.wip.extractValue(ptr, &.{1}, "");6333 const len = try fg.wip.extractValue(ptr, &.{1}, "");
6345 const elem_ty = ty.childType(mod);6334 const elem_ty = ty.childType(zcu);
6346 const abi_size = elem_ty.abiSize(pt);6335 const abi_size = elem_ty.abiSize(zcu);
6347 if (abi_size == 1) return len;6336 if (abi_size == 1) return len;
6348 const abi_size_llvm_val = try o.builder.intValue(llvm_usize, abi_size);6337 const abi_size_llvm_val = try o.builder.intValue(llvm_usize, abi_size);
6349 return fg.wip.bin(.@"mul nuw", len, abi_size_llvm_val, "");6338 return fg.wip.bin(.@"mul nuw", len, abi_size_llvm_val, "");
6350 },6339 },
6351 .One => {6340 .One => {
6352 const array_ty = ty.childType(mod);6341 const array_ty = ty.childType(zcu);
6353 const elem_ty = array_ty.childType(mod);6342 const elem_ty = array_ty.childType(zcu);
6354 const abi_size = elem_ty.abiSize(pt);6343 const abi_size = elem_ty.abiSize(zcu);
6355 return o.builder.intValue(llvm_usize, array_ty.arrayLen(mod) * abi_size);6344 return o.builder.intValue(llvm_usize, array_ty.arrayLen(zcu) * abi_size);
6356 },6345 },
6357 .Many, .C => unreachable,6346 .Many, .C => unreachable,
6358 }6347 }
...@@ -6366,11 +6355,11 @@ pub const FuncGen = struct {...@@ -6366,11 +6355,11 @@ pub const FuncGen = struct {
63666355
6367 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {6356 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !Builder.Value {
6368 const o = self.ng.object;6357 const o = self.ng.object;
6369 const mod = o.pt.zcu;6358 const zcu = o.pt.zcu;
6370 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6359 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6371 const slice_ptr = try self.resolveInst(ty_op.operand);6360 const slice_ptr = try self.resolveInst(ty_op.operand);
6372 const slice_ptr_ty = self.typeOf(ty_op.operand);6361 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
6375 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");6364 return self.wip.gepStruct(slice_llvm_ty, slice_ptr, index, "");
6376 }6365 }
...@@ -6378,21 +6367,21 @@ pub const FuncGen = struct {...@@ -6378,21 +6367,21 @@ pub const FuncGen = struct {
6378 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6367 fn airSliceElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6379 const o = self.ng.object;6368 const o = self.ng.object;
6380 const pt = o.pt;6369 const pt = o.pt;
6381 const mod = pt.zcu;6370 const zcu = pt.zcu;
6382 const inst = body_tail[0];6371 const inst = body_tail[0];
6383 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6372 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6384 const slice_ty = self.typeOf(bin_op.lhs);6373 const slice_ty = self.typeOf(bin_op.lhs);
6385 const slice = try self.resolveInst(bin_op.lhs);6374 const slice = try self.resolveInst(bin_op.lhs);
6386 const index = try self.resolveInst(bin_op.rhs);6375 const index = try self.resolveInst(bin_op.rhs);
6387 const elem_ty = slice_ty.childType(mod);6376 const elem_ty = slice_ty.childType(zcu);
6388 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);6377 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6389 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");6378 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
6390 const ptr = try self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");6379 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)) {
6392 if (self.canElideLoad(body_tail))6381 if (self.canElideLoad(body_tail))
6393 return ptr;6382 return ptr;
63946383
6395 const elem_alignment = elem_ty.abiAlignment(pt).toLlvm();6384 const elem_alignment = elem_ty.abiAlignment(zcu).toLlvm();
6396 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);6385 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);
6397 }6386 }
63986387
...@@ -6401,14 +6390,14 @@ pub const FuncGen = struct {...@@ -6401,14 +6390,14 @@ pub const FuncGen = struct {
64016390
6402 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6391 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6403 const o = self.ng.object;6392 const o = self.ng.object;
6404 const mod = o.pt.zcu;6393 const zcu = o.pt.zcu;
6405 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6394 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6406 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;6395 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
6407 const slice_ty = self.typeOf(bin_op.lhs);6396 const slice_ty = self.typeOf(bin_op.lhs);
64086397
6409 const slice = try self.resolveInst(bin_op.lhs);6398 const slice = try self.resolveInst(bin_op.lhs);
6410 const index = try self.resolveInst(bin_op.rhs);6399 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));
6412 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");6401 const base_ptr = try self.wip.extractValue(slice, &.{0}, "");
6413 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");6402 return self.wip.gep(.inbounds, llvm_elem_ty, base_ptr, &.{index}, "");
6414 }6403 }
...@@ -6416,7 +6405,7 @@ pub const FuncGen = struct {...@@ -6416,7 +6405,7 @@ pub const FuncGen = struct {
6416 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6405 fn airArrayElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6417 const o = self.ng.object;6406 const o = self.ng.object;
6418 const pt = o.pt;6407 const pt = o.pt;
6419 const mod = pt.zcu;6408 const zcu = pt.zcu;
6420 const inst = body_tail[0];6409 const inst = body_tail[0];
64216410
6422 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6411 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
...@@ -6424,16 +6413,16 @@ pub const FuncGen = struct {...@@ -6424,16 +6413,16 @@ pub const FuncGen = struct {
6424 const array_llvm_val = try self.resolveInst(bin_op.lhs);6413 const array_llvm_val = try self.resolveInst(bin_op.lhs);
6425 const rhs = try self.resolveInst(bin_op.rhs);6414 const rhs = try self.resolveInst(bin_op.rhs);
6426 const array_llvm_ty = try o.lowerType(array_ty);6415 const array_llvm_ty = try o.lowerType(array_ty);
6427 const elem_ty = array_ty.childType(mod);6416 const elem_ty = array_ty.childType(zcu);
6428 if (isByRef(array_ty, pt)) {6417 if (isByRef(array_ty, zcu)) {
6429 const indices: [2]Builder.Value = .{6418 const indices: [2]Builder.Value = .{
6430 try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs,6419 try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs,
6431 };6420 };
6432 if (isByRef(elem_ty, pt)) {6421 if (isByRef(elem_ty, zcu)) {
6433 const elem_ptr =6422 const elem_ptr =
6434 try self.wip.gep(.inbounds, array_llvm_ty, array_llvm_val, &indices, "");6423 try self.wip.gep(.inbounds, array_llvm_ty, array_llvm_val, &indices, "");
6435 if (canElideLoad(self, body_tail)) return elem_ptr;6424 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();
6437 return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal);6426 return self.loadByRef(elem_ptr, elem_ty, elem_alignment, .normal);
6438 } else {6427 } else {
6439 const elem_ptr =6428 const elem_ptr =
...@@ -6449,23 +6438,23 @@ pub const FuncGen = struct {...@@ -6449,23 +6438,23 @@ pub const FuncGen = struct {
6449 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6438 fn airPtrElemVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6450 const o = self.ng.object;6439 const o = self.ng.object;
6451 const pt = o.pt;6440 const pt = o.pt;
6452 const mod = pt.zcu;6441 const zcu = pt.zcu;
6453 const inst = body_tail[0];6442 const inst = body_tail[0];
6454 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;6443 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
6455 const ptr_ty = self.typeOf(bin_op.lhs);6444 const ptr_ty = self.typeOf(bin_op.lhs);
6456 const elem_ty = ptr_ty.childType(mod);6445 const elem_ty = ptr_ty.childType(zcu);
6457 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);6446 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);
6458 const base_ptr = try self.resolveInst(bin_op.lhs);6447 const base_ptr = try self.resolveInst(bin_op.lhs);
6459 const rhs = try self.resolveInst(bin_op.rhs);6448 const rhs = try self.resolveInst(bin_op.rhs);
6460 // TODO: when we go fully opaque pointers in LLVM 16 we can remove this branch6449 // 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))
6462 // If this is a single-item pointer to an array, we need another index in the GEP.6451 // If this is a single-item pointer to an array, we need another index in the GEP.
6463 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }6452 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
6464 else6453 else
6465 &.{rhs}, "");6454 &.{rhs}, "");
6466 if (isByRef(elem_ty, pt)) {6455 if (isByRef(elem_ty, zcu)) {
6467 if (self.canElideLoad(body_tail)) return ptr;6456 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();
6469 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);6458 return self.loadByRef(ptr, elem_ty, elem_alignment, .normal);
6470 }6459 }
64716460
...@@ -6475,21 +6464,21 @@ pub const FuncGen = struct {...@@ -6475,21 +6464,21 @@ pub const FuncGen = struct {
6475 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6464 fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6476 const o = self.ng.object;6465 const o = self.ng.object;
6477 const pt = o.pt;6466 const pt = o.pt;
6478 const mod = pt.zcu;6467 const zcu = pt.zcu;
6479 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6468 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6480 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;6469 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
6481 const ptr_ty = self.typeOf(bin_op.lhs);6470 const ptr_ty = self.typeOf(bin_op.lhs);
6482 const elem_ty = ptr_ty.childType(mod);6471 const elem_ty = ptr_ty.childType(zcu);
6483 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return self.resolveInst(bin_op.lhs);6472 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return self.resolveInst(bin_op.lhs);
64846473
6485 const base_ptr = try self.resolveInst(bin_op.lhs);6474 const base_ptr = try self.resolveInst(bin_op.lhs);
6486 const rhs = try self.resolveInst(bin_op.rhs);6475 const rhs = try self.resolveInst(bin_op.rhs);
64876476
6488 const elem_ptr = ty_pl.ty.toType();6477 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
6491 const llvm_elem_ty = try o.lowerPtrElemTy(elem_ty);6480 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))
6493 // If this is a single-item pointer to an array, we need another index in the GEP.6482 // If this is a single-item pointer to an array, we need another index in the GEP.
6494 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }6483 &.{ try o.builder.intValue(try o.lowerType(Type.usize), 0), rhs }
6495 else6484 else
...@@ -6518,35 +6507,35 @@ pub const FuncGen = struct {...@@ -6518,35 +6507,35 @@ pub const FuncGen = struct {
6518 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {6507 fn airStructFieldVal(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
6519 const o = self.ng.object;6508 const o = self.ng.object;
6520 const pt = o.pt;6509 const pt = o.pt;
6521 const mod = pt.zcu;6510 const zcu = pt.zcu;
6522 const inst = body_tail[0];6511 const inst = body_tail[0];
6523 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6512 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6524 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;6513 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
6525 const struct_ty = self.typeOf(struct_field.struct_operand);6514 const struct_ty = self.typeOf(struct_field.struct_operand);
6526 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);6515 const struct_llvm_val = try self.resolveInst(struct_field.struct_operand);
6527 const field_index = struct_field.field_index;6516 const field_index = struct_field.field_index;
6528 const field_ty = struct_ty.structFieldType(field_index, mod);6517 const field_ty = struct_ty.fieldType(field_index, zcu);
6529 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;6518 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
65306519
6531 if (!isByRef(struct_ty, pt)) {6520 if (!isByRef(struct_ty, zcu)) {
6532 assert(!isByRef(field_ty, pt));6521 assert(!isByRef(field_ty, zcu));
6533 switch (struct_ty.zigTypeTag(mod)) {6522 switch (struct_ty.zigTypeTag(zcu)) {
6534 .Struct => switch (struct_ty.containerLayout(mod)) {6523 .Struct => switch (struct_ty.containerLayout(zcu)) {
6535 .@"packed" => {6524 .@"packed" => {
6536 const struct_type = mod.typeToStruct(struct_ty).?;6525 const struct_type = zcu.typeToStruct(struct_ty).?;
6537 const bit_offset = pt.structPackedFieldBitOffset(struct_type, field_index);6526 const bit_offset = pt.structPackedFieldBitOffset(struct_type, field_index);
6538 const containing_int = struct_llvm_val;6527 const containing_int = struct_llvm_val;
6539 const shift_amt =6528 const shift_amt =
6540 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);6529 try o.builder.intValue(containing_int.typeOfWip(&self.wip), bit_offset);
6541 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");6530 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
6542 const elem_llvm_ty = try o.lowerType(field_ty);6531 const elem_llvm_ty = try o.lowerType(field_ty);
6543 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {6532 if (field_ty.zigTypeTag(zcu) == .Float or field_ty.zigTypeTag(zcu) == .Vector) {
6544 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));6533 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
6545 const truncated_int =6534 const truncated_int =
6546 try self.wip.cast(.trunc, shifted_value, same_size_int, "");6535 try self.wip.cast(.trunc, shifted_value, same_size_int, "");
6547 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");6536 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");
6548 } else if (field_ty.isPtrAtRuntime(mod)) {6537 } else if (field_ty.isPtrAtRuntime(zcu)) {
6549 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));6538 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
6550 const truncated_int =6539 const truncated_int =
6551 try self.wip.cast(.trunc, shifted_value, same_size_int, "");6540 try self.wip.cast(.trunc, shifted_value, same_size_int, "");
6552 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");6541 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
...@@ -6559,16 +6548,16 @@ pub const FuncGen = struct {...@@ -6559,16 +6548,16 @@ pub const FuncGen = struct {
6559 },6548 },
6560 },6549 },
6561 .Union => {6550 .Union => {
6562 assert(struct_ty.containerLayout(mod) == .@"packed");6551 assert(struct_ty.containerLayout(zcu) == .@"packed");
6563 const containing_int = struct_llvm_val;6552 const containing_int = struct_llvm_val;
6564 const elem_llvm_ty = try o.lowerType(field_ty);6553 const elem_llvm_ty = try o.lowerType(field_ty);
6565 if (field_ty.zigTypeTag(mod) == .Float or field_ty.zigTypeTag(mod) == .Vector) {6554 if (field_ty.zigTypeTag(zcu) == .Float or field_ty.zigTypeTag(zcu) == .Vector) {
6566 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));6555 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
6567 const truncated_int =6556 const truncated_int =
6568 try self.wip.cast(.trunc, containing_int, same_size_int, "");6557 try self.wip.cast(.trunc, containing_int, same_size_int, "");
6569 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");6558 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");
6570 } else if (field_ty.isPtrAtRuntime(mod)) {6559 } else if (field_ty.isPtrAtRuntime(zcu)) {
6571 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(pt)));6560 const same_size_int = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
6572 const truncated_int =6561 const truncated_int =
6573 try self.wip.cast(.trunc, containing_int, same_size_int, "");6562 try self.wip.cast(.trunc, containing_int, same_size_int, "");
6574 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");6563 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
...@@ -6579,20 +6568,20 @@ pub const FuncGen = struct {...@@ -6579,20 +6568,20 @@ pub const FuncGen = struct {
6579 }6568 }
6580 }6569 }
65816570
6582 switch (struct_ty.zigTypeTag(mod)) {6571 switch (struct_ty.zigTypeTag(zcu)) {
6583 .Struct => {6572 .Struct => {
6584 const layout = struct_ty.containerLayout(mod);6573 const layout = struct_ty.containerLayout(zcu);
6585 assert(layout != .@"packed");6574 assert(layout != .@"packed");
6586 const struct_llvm_ty = try o.lowerType(struct_ty);6575 const struct_llvm_ty = try o.lowerType(struct_ty);
6587 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;6576 const llvm_field_index = o.llvmFieldIndex(struct_ty, field_index).?;
6588 const field_ptr =6577 const field_ptr =
6589 try self.wip.gepStruct(struct_llvm_ty, struct_llvm_val, llvm_field_index, "");6578 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);
6591 const field_ptr_ty = try pt.ptrType(.{6580 const field_ptr_ty = try pt.ptrType(.{
6592 .child = field_ty.toIntern(),6581 .child = field_ty.toIntern(),
6593 .flags = .{ .alignment = alignment },6582 .flags = .{ .alignment = alignment },
6594 });6583 });
6595 if (isByRef(field_ty, pt)) {6584 if (isByRef(field_ty, zcu)) {
6596 if (canElideLoad(self, body_tail))6585 if (canElideLoad(self, body_tail))
6597 return field_ptr;6586 return field_ptr;
65986587
...@@ -6605,12 +6594,12 @@ pub const FuncGen = struct {...@@ -6605,12 +6594,12 @@ pub const FuncGen = struct {
6605 },6594 },
6606 .Union => {6595 .Union => {
6607 const union_llvm_ty = try o.lowerType(struct_ty);6596 const union_llvm_ty = try o.lowerType(struct_ty);
6608 const layout = struct_ty.unionGetLayout(pt);6597 const layout = struct_ty.unionGetLayout(zcu);
6609 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));6598 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
6610 const field_ptr =6599 const field_ptr =
6611 try self.wip.gepStruct(union_llvm_ty, struct_llvm_val, payload_index, "");6600 try self.wip.gepStruct(union_llvm_ty, struct_llvm_val, payload_index, "");
6612 const payload_alignment = layout.payload_align.toLlvm();6601 const payload_alignment = layout.payload_align.toLlvm();
6613 if (isByRef(field_ty, pt)) {6602 if (isByRef(field_ty, zcu)) {
6614 if (canElideLoad(self, body_tail)) return field_ptr;6603 if (canElideLoad(self, body_tail)) return field_ptr;
6615 return self.loadByRef(field_ptr, field_ty, payload_alignment, .normal);6604 return self.loadByRef(field_ptr, field_ty, payload_alignment, .normal);
6616 } else {6605 } else {
...@@ -6624,14 +6613,14 @@ pub const FuncGen = struct {...@@ -6624,14 +6613,14 @@ pub const FuncGen = struct {
6624 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6613 fn airFieldParentPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6625 const o = self.ng.object;6614 const o = self.ng.object;
6626 const pt = o.pt;6615 const pt = o.pt;
6627 const mod = pt.zcu;6616 const zcu = pt.zcu;
6628 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6617 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6629 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;6618 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
66306619
6631 const field_ptr = try self.resolveInst(extra.field_ptr);6620 const field_ptr = try self.resolveInst(extra.field_ptr);
66326621
6633 const parent_ty = ty_pl.ty.toType().childType(mod);6622 const parent_ty = ty_pl.ty.toType().childType(zcu);
6634 const field_offset = parent_ty.structFieldOffset(extra.field_index, pt);6623 const field_offset = parent_ty.structFieldOffset(extra.field_index, zcu);
6635 if (field_offset == 0) return field_ptr;6624 if (field_offset == 0) return field_ptr;
66366625
6637 const res_ty = try o.lowerType(ty_pl.ty.toType());6626 const res_ty = try o.lowerType(ty_pl.ty.toType());
...@@ -6686,7 +6675,7 @@ pub const FuncGen = struct {...@@ -6686,7 +6675,7 @@ pub const FuncGen = struct {
66866675
6687 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {6676 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
6688 const o = self.ng.object;6677 const o = self.ng.object;
6689 const mod = o.pt.zcu;6678 const zcu = o.pt.zcu;
6690 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;6679 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6691 const operand = try self.resolveInst(pl_op.operand);6680 const operand = try self.resolveInst(pl_op.operand);
6692 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);6681 const name: Air.NullTerminatedString = @enumFromInt(pl_op.payload);
...@@ -6697,7 +6686,7 @@ pub const FuncGen = struct {...@@ -6697,7 +6686,7 @@ pub const FuncGen = struct {
6697 self.file,6686 self.file,
6698 self.scope,6687 self.scope,
6699 self.prev_dbg_line,6688 self.prev_dbg_line,
6700 try o.lowerDebugType(ptr_ty.childType(mod)),6689 try o.lowerDebugType(ptr_ty.childType(zcu)),
6701 );6690 );
67026691
6703 _ = try self.wip.callIntrinsic(6692 _ = try self.wip.callIntrinsic(
...@@ -6741,9 +6730,9 @@ pub const FuncGen = struct {...@@ -6741,9 +6730,9 @@ pub const FuncGen = struct {
6741 try o.lowerDebugType(operand_ty),6730 try o.lowerDebugType(operand_ty),
6742 );6731 );
67436732
6744 const pt = o.pt;6733 const zcu = o.pt.zcu;
6745 const owner_mod = self.ng.ownerModule();6734 const owner_mod = self.ng.ownerModule();
6746 if (isByRef(operand_ty, pt)) {6735 if (isByRef(operand_ty, zcu)) {
6747 _ = try self.wip.callIntrinsic(6736 _ = try self.wip.callIntrinsic(
6748 .normal,6737 .normal,
6749 .none,6738 .none,
...@@ -6760,7 +6749,7 @@ pub const FuncGen = struct {...@@ -6760,7 +6749,7 @@ pub const FuncGen = struct {
6760 // We avoid taking this path for naked functions because there's no guarantee that such6749 // We avoid taking this path for naked functions because there's no guarantee that such
6761 // functions even have a valid stack pointer, making the `alloca` + `store` unsafe.6750 // 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();
6764 const alloca = try self.buildAlloca(operand.typeOfWip(&self.wip), alignment);6753 const alloca = try self.buildAlloca(operand.typeOfWip(&self.wip), alignment);
6765 _ = try self.wip.store(.normal, operand, alloca, alignment);6754 _ = try self.wip.store(.normal, operand, alloca, alignment);
6766 _ = try self.wip.callIntrinsic(6755 _ = try self.wip.callIntrinsic(
...@@ -6832,8 +6821,8 @@ pub const FuncGen = struct {...@@ -6832,8 +6821,8 @@ pub const FuncGen = struct {
6832 // if so, the element type itself.6821 // if so, the element type itself.
6833 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);6822 const llvm_param_attrs = try arena.alloc(Builder.Type, max_param_count);
6834 const pt = o.pt;6823 const pt = o.pt;
6835 const mod = pt.zcu;6824 const zcu = pt.zcu;
6836 const target = mod.getTarget();6825 const target = zcu.getTarget();
68376826
6838 var llvm_ret_i: usize = 0;6827 var llvm_ret_i: usize = 0;
6839 var llvm_param_i: usize = 0;6828 var llvm_param_i: usize = 0;
...@@ -6860,8 +6849,8 @@ pub const FuncGen = struct {...@@ -6860,8 +6849,8 @@ pub const FuncGen = struct {
6860 if (output != .none) {6849 if (output != .none) {
6861 const output_inst = try self.resolveInst(output);6850 const output_inst = try self.resolveInst(output);
6862 const output_ty = self.typeOf(output);6851 const output_ty = self.typeOf(output);
6863 assert(output_ty.zigTypeTag(mod) == .Pointer);6852 assert(output_ty.zigTypeTag(zcu) == .Pointer);
6864 const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(mod));6853 const elem_llvm_ty = try o.lowerPtrElemTy(output_ty.childType(zcu));
68656854
6866 switch (constraint[0]) {6855 switch (constraint[0]) {
6867 '=' => {},6856 '=' => {},
...@@ -6932,13 +6921,13 @@ pub const FuncGen = struct {...@@ -6932,13 +6921,13 @@ pub const FuncGen = struct {
69326921
6933 const arg_llvm_value = try self.resolveInst(input);6922 const arg_llvm_value = try self.resolveInst(input);
6934 const arg_ty = self.typeOf(input);6923 const arg_ty = self.typeOf(input);
6935 const is_by_ref = isByRef(arg_ty, pt);6924 const is_by_ref = isByRef(arg_ty, zcu);
6936 if (is_by_ref) {6925 if (is_by_ref) {
6937 if (constraintAllowsMemory(constraint)) {6926 if (constraintAllowsMemory(constraint)) {
6938 llvm_param_values[llvm_param_i] = arg_llvm_value;6927 llvm_param_values[llvm_param_i] = arg_llvm_value;
6939 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);6928 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
6940 } else {6929 } else {
6941 const alignment = arg_ty.abiAlignment(pt).toLlvm();6930 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
6942 const arg_llvm_ty = try o.lowerType(arg_ty);6931 const arg_llvm_ty = try o.lowerType(arg_ty);
6943 const load_inst =6932 const load_inst =
6944 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");6933 try self.wip.load(.normal, arg_llvm_ty, arg_llvm_value, alignment, "");
...@@ -6950,7 +6939,7 @@ pub const FuncGen = struct {...@@ -6950,7 +6939,7 @@ pub const FuncGen = struct {
6950 llvm_param_values[llvm_param_i] = arg_llvm_value;6939 llvm_param_values[llvm_param_i] = arg_llvm_value;
6951 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);6940 llvm_param_types[llvm_param_i] = arg_llvm_value.typeOfWip(&self.wip);
6952 } else {6941 } else {
6953 const alignment = arg_ty.abiAlignment(pt).toLlvm();6942 const alignment = arg_ty.abiAlignment(zcu).toLlvm();
6954 const arg_ptr = try self.buildAlloca(arg_llvm_value.typeOfWip(&self.wip), alignment);6943 const arg_ptr = try self.buildAlloca(arg_llvm_value.typeOfWip(&self.wip), alignment);
6955 _ = try self.wip.store(.normal, arg_llvm_value, arg_ptr, alignment);6944 _ = try self.wip.store(.normal, arg_llvm_value, arg_ptr, alignment);
6956 llvm_param_values[llvm_param_i] = arg_ptr;6945 llvm_param_values[llvm_param_i] = arg_ptr;
...@@ -6978,7 +6967,7 @@ pub const FuncGen = struct {...@@ -6978,7 +6967,7 @@ pub const FuncGen = struct {
6978 // In the case of indirect inputs, LLVM requires the callsite to have6967 // In the case of indirect inputs, LLVM requires the callsite to have
6979 // an elementtype(<ty>) attribute.6968 // an elementtype(<ty>) attribute.
6980 llvm_param_attrs[llvm_param_i] = if (constraint[0] == '*')6969 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))
6982 else6971 else
6983 .none;6972 .none;
69846973
...@@ -6997,12 +6986,12 @@ pub const FuncGen = struct {...@@ -6997,12 +6986,12 @@ pub const FuncGen = struct {
6997 if (constraint[0] != '+') continue;6986 if (constraint[0] != '+') continue;
69986987
6999 const rw_ty = self.typeOf(output);6988 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));
7001 if (is_indirect) {6990 if (is_indirect) {
7002 llvm_param_values[llvm_param_i] = llvm_rw_val;6991 llvm_param_values[llvm_param_i] = llvm_rw_val;
7003 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);6992 llvm_param_types[llvm_param_i] = llvm_rw_val.typeOfWip(&self.wip);
7004 } else {6993 } else {
7005 const alignment = rw_ty.abiAlignment(pt).toLlvm();6994 const alignment = rw_ty.abiAlignment(zcu).toLlvm();
7006 const loaded = try self.wip.load(.normal, llvm_elem_ty, llvm_rw_val, alignment, "");6995 const loaded = try self.wip.load(.normal, llvm_elem_ty, llvm_rw_val, alignment, "");
7007 llvm_param_values[llvm_param_i] = loaded;6996 llvm_param_values[llvm_param_i] = loaded;
7008 llvm_param_types[llvm_param_i] = llvm_elem_ty;6997 llvm_param_types[llvm_param_i] = llvm_elem_ty;
...@@ -7163,7 +7152,7 @@ pub const FuncGen = struct {...@@ -7163,7 +7152,7 @@ pub const FuncGen = struct {
7163 const output_ptr = try self.resolveInst(output);7152 const output_ptr = try self.resolveInst(output);
7164 const output_ptr_ty = self.typeOf(output);7153 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();
7167 _ = try self.wip.store(.normal, output_value, output_ptr, alignment);7156 _ = try self.wip.store(.normal, output_value, output_ptr, alignment);
7168 } else {7157 } else {
7169 ret_val = output_value;7158 ret_val = output_value;
...@@ -7182,23 +7171,23 @@ pub const FuncGen = struct {...@@ -7182,23 +7171,23 @@ pub const FuncGen = struct {
7182 ) !Builder.Value {7171 ) !Builder.Value {
7183 const o = self.ng.object;7172 const o = self.ng.object;
7184 const pt = o.pt;7173 const pt = o.pt;
7185 const mod = pt.zcu;7174 const zcu = pt.zcu;
7186 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;7175 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7187 const operand = try self.resolveInst(un_op);7176 const operand = try self.resolveInst(un_op);
7188 const operand_ty = self.typeOf(un_op);7177 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;
7190 const optional_llvm_ty = try o.lowerType(optional_ty);7179 const optional_llvm_ty = try o.lowerType(optional_ty);
7191 const payload_ty = optional_ty.optionalChild(mod);7180 const payload_ty = optional_ty.optionalChild(zcu);
7192 if (optional_ty.optionalReprIsPayload(mod)) {7181 if (optional_ty.optionalReprIsPayload(zcu)) {
7193 const loaded = if (operand_is_ptr)7182 const loaded = if (operand_is_ptr)
7194 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")7183 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")
7195 else7184 else
7196 operand;7185 operand;
7197 if (payload_ty.isSlice(mod)) {7186 if (payload_ty.isSlice(zcu)) {
7198 const slice_ptr = try self.wip.extractValue(loaded, &.{0}, "");7187 const slice_ptr = try self.wip.extractValue(loaded, &.{0}, "");
7199 const ptr_ty = try o.builder.ptrType(toLlvmAddressSpace(7188 const ptr_ty = try o.builder.ptrType(toLlvmAddressSpace(
7200 payload_ty.ptrAddressSpace(mod),7189 payload_ty.ptrAddressSpace(zcu),
7201 mod.getTarget(),7190 zcu.getTarget(),
7202 ));7191 ));
7203 return self.wip.icmp(cond, slice_ptr, try o.builder.nullValue(ptr_ty), "");7192 return self.wip.icmp(cond, slice_ptr, try o.builder.nullValue(ptr_ty), "");
7204 }7193 }
...@@ -7207,7 +7196,7 @@ pub const FuncGen = struct {...@@ -7207,7 +7196,7 @@ pub const FuncGen = struct {
72077196
7208 comptime assert(optional_layout_version == 3);7197 comptime assert(optional_layout_version == 3);
72097198
7210 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {7199 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7211 const loaded = if (operand_is_ptr)7200 const loaded = if (operand_is_ptr)
7212 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")7201 try self.wip.load(.normal, optional_llvm_ty, operand, .default, "")
7213 else7202 else
...@@ -7215,7 +7204,7 @@ pub const FuncGen = struct {...@@ -7215,7 +7204,7 @@ pub const FuncGen = struct {
7215 return self.wip.icmp(cond, loaded, try o.builder.intValue(.i8, 0), "");7204 return self.wip.icmp(cond, loaded, try o.builder.intValue(.i8, 0), "");
7216 }7205 }
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);
7219 return self.optCmpNull(cond, optional_llvm_ty, operand, is_by_ref);7208 return self.optCmpNull(cond, optional_llvm_ty, operand, is_by_ref);
7220 }7209 }
72217210
...@@ -7227,16 +7216,16 @@ pub const FuncGen = struct {...@@ -7227,16 +7216,16 @@ pub const FuncGen = struct {
7227 ) !Builder.Value {7216 ) !Builder.Value {
7228 const o = self.ng.object;7217 const o = self.ng.object;
7229 const pt = o.pt;7218 const pt = o.pt;
7230 const mod = pt.zcu;7219 const zcu = pt.zcu;
7231 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;7220 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
7232 const operand = try self.resolveInst(un_op);7221 const operand = try self.resolveInst(un_op);
7233 const operand_ty = self.typeOf(un_op);7222 const operand_ty = self.typeOf(un_op);
7234 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;7223 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7235 const payload_ty = err_union_ty.errorUnionPayload(mod);7224 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7236 const error_type = try o.errorIntType();7225 const error_type = try o.errorIntType();
7237 const zero = try o.builder.intValue(error_type, 0);7226 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)) {
7240 const val: Builder.Constant = switch (cond) {7229 const val: Builder.Constant = switch (cond) {
7241 .eq => .true, // 0 == 07230 .eq => .true, // 0 == 0
7242 .ne => .false, // 0 != 07231 .ne => .false, // 0 != 0
...@@ -7245,7 +7234,7 @@ pub const FuncGen = struct {...@@ -7245,7 +7234,7 @@ pub const FuncGen = struct {
7245 return val.toValue();7234 return val.toValue();
7246 }7235 }
72477236
7248 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {7237 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7249 const loaded = if (operand_is_ptr)7238 const loaded = if (operand_is_ptr)
7250 try self.wip.load(.normal, try o.lowerType(err_union_ty), operand, .default, "")7239 try self.wip.load(.normal, try o.lowerType(err_union_ty), operand, .default, "")
7251 else7240 else
...@@ -7255,7 +7244,7 @@ pub const FuncGen = struct {...@@ -7255,7 +7244,7 @@ pub const FuncGen = struct {
72557244
7256 const err_field_index = try errUnionErrorOffset(payload_ty, pt);7245 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: {
7259 const err_union_llvm_ty = try o.lowerType(err_union_ty);7248 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7260 const err_field_ptr =7249 const err_field_ptr =
7261 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");7250 try self.wip.gepStruct(err_union_llvm_ty, operand, err_field_index, "");
...@@ -7267,17 +7256,17 @@ pub const FuncGen = struct {...@@ -7267,17 +7256,17 @@ pub const FuncGen = struct {
7267 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7256 fn airOptionalPayloadPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7268 const o = self.ng.object;7257 const o = self.ng.object;
7269 const pt = o.pt;7258 const pt = o.pt;
7270 const mod = pt.zcu;7259 const zcu = pt.zcu;
7271 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7260 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7272 const operand = try self.resolveInst(ty_op.operand);7261 const operand = try self.resolveInst(ty_op.operand);
7273 const optional_ty = self.typeOf(ty_op.operand).childType(mod);7262 const optional_ty = self.typeOf(ty_op.operand).childType(zcu);
7274 const payload_ty = optional_ty.optionalChild(mod);7263 const payload_ty = optional_ty.optionalChild(zcu);
7275 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {7264 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7276 // We have a pointer to a zero-bit value and we need to return7265 // We have a pointer to a zero-bit value and we need to return
7277 // a pointer to a zero-bit value.7266 // a pointer to a zero-bit value.
7278 return operand;7267 return operand;
7279 }7268 }
7280 if (optional_ty.optionalReprIsPayload(mod)) {7269 if (optional_ty.optionalReprIsPayload(zcu)) {
7281 // The payload and the optional are the same value.7270 // The payload and the optional are the same value.
7282 return operand;7271 return operand;
7283 }7272 }
...@@ -7289,18 +7278,18 @@ pub const FuncGen = struct {...@@ -7289,18 +7278,18 @@ pub const FuncGen = struct {
72897278
7290 const o = self.ng.object;7279 const o = self.ng.object;
7291 const pt = o.pt;7280 const pt = o.pt;
7292 const mod = pt.zcu;7281 const zcu = pt.zcu;
7293 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7282 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7294 const operand = try self.resolveInst(ty_op.operand);7283 const operand = try self.resolveInst(ty_op.operand);
7295 const optional_ty = self.typeOf(ty_op.operand).childType(mod);7284 const optional_ty = self.typeOf(ty_op.operand).childType(zcu);
7296 const payload_ty = optional_ty.optionalChild(mod);7285 const payload_ty = optional_ty.optionalChild(zcu);
7297 const non_null_bit = try o.builder.intValue(.i8, 1);7286 const non_null_bit = try o.builder.intValue(.i8, 1);
7298 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {7287 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7299 // We have a pointer to a i8. We need to set it to 1 and then return the same pointer.7288 // We have a pointer to a i8. We need to set it to 1 and then return the same pointer.
7300 _ = try self.wip.store(.normal, non_null_bit, operand, .default);7289 _ = try self.wip.store(.normal, non_null_bit, operand, .default);
7301 return operand;7290 return operand;
7302 }7291 }
7303 if (optional_ty.optionalReprIsPayload(mod)) {7292 if (optional_ty.optionalReprIsPayload(zcu)) {
7304 // The payload and the optional are the same value.7293 // The payload and the optional are the same value.
7305 // Setting to non-null will be done when the payload is set.7294 // Setting to non-null will be done when the payload is set.
7306 return operand;7295 return operand;
...@@ -7321,21 +7310,21 @@ pub const FuncGen = struct {...@@ -7321,21 +7310,21 @@ pub const FuncGen = struct {
7321 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {7310 fn airOptionalPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
7322 const o = self.ng.object;7311 const o = self.ng.object;
7323 const pt = o.pt;7312 const pt = o.pt;
7324 const mod = pt.zcu;7313 const zcu = pt.zcu;
7325 const inst = body_tail[0];7314 const inst = body_tail[0];
7326 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7315 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7327 const operand = try self.resolveInst(ty_op.operand);7316 const operand = try self.resolveInst(ty_op.operand);
7328 const optional_ty = self.typeOf(ty_op.operand);7317 const optional_ty = self.typeOf(ty_op.operand);
7329 const payload_ty = self.typeOfIndex(inst);7318 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)) {
7333 // Payload value is the same as the optional value.7322 // Payload value is the same as the optional value.
7334 return operand;7323 return operand;
7335 }7324 }
73367325
7337 const opt_llvm_ty = try o.lowerType(optional_ty);7326 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;
7339 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);7328 return self.optPayloadHandle(opt_llvm_ty, operand, optional_ty, can_elide_load);
7340 }7329 }
73417330
...@@ -7346,26 +7335,26 @@ pub const FuncGen = struct {...@@ -7346,26 +7335,26 @@ pub const FuncGen = struct {
7346 ) !Builder.Value {7335 ) !Builder.Value {
7347 const o = self.ng.object;7336 const o = self.ng.object;
7348 const pt = o.pt;7337 const pt = o.pt;
7349 const mod = pt.zcu;7338 const zcu = pt.zcu;
7350 const inst = body_tail[0];7339 const inst = body_tail[0];
7351 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7340 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7352 const operand = try self.resolveInst(ty_op.operand);7341 const operand = try self.resolveInst(ty_op.operand);
7353 const operand_ty = self.typeOf(ty_op.operand);7342 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;
7355 const result_ty = self.typeOfIndex(inst);7344 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)) {
7359 return if (operand_is_ptr) operand else .none;7348 return if (operand_is_ptr) operand else .none;
7360 }7349 }
7361 const offset = try errUnionPayloadOffset(payload_ty, pt);7350 const offset = try errUnionPayloadOffset(payload_ty, pt);
7362 const err_union_llvm_ty = try o.lowerType(err_union_ty);7351 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7363 if (operand_is_ptr) {7352 if (operand_is_ptr) {
7364 return self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");7353 return self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
7365 } else if (isByRef(err_union_ty, pt)) {7354 } else if (isByRef(err_union_ty, zcu)) {
7366 const payload_alignment = payload_ty.abiAlignment(pt).toLlvm();7355 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
7367 const payload_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");7356 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)) {
7369 if (self.canElideLoad(body_tail)) return payload_ptr;7358 if (self.canElideLoad(body_tail)) return payload_ptr;
7370 return self.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal);7359 return self.loadByRef(payload_ptr, payload_ty, payload_alignment, .normal);
7371 }7360 }
...@@ -7382,13 +7371,13 @@ pub const FuncGen = struct {...@@ -7382,13 +7371,13 @@ pub const FuncGen = struct {
7382 ) !Builder.Value {7371 ) !Builder.Value {
7383 const o = self.ng.object;7372 const o = self.ng.object;
7384 const pt = o.pt;7373 const pt = o.pt;
7385 const mod = pt.zcu;7374 const zcu = pt.zcu;
7386 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7375 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7387 const operand = try self.resolveInst(ty_op.operand);7376 const operand = try self.resolveInst(ty_op.operand);
7388 const operand_ty = self.typeOf(ty_op.operand);7377 const operand_ty = self.typeOf(ty_op.operand);
7389 const error_type = try o.errorIntType();7378 const error_type = try o.errorIntType();
7390 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;7379 const err_union_ty = if (operand_is_ptr) operand_ty.childType(zcu) else operand_ty;
7391 if (err_union_ty.errorUnionSet(mod).errorSetIsEmpty(mod)) {7380 if (err_union_ty.errorUnionSet(zcu).errorSetIsEmpty(zcu)) {
7392 if (operand_is_ptr) {7381 if (operand_is_ptr) {
7393 return operand;7382 return operand;
7394 } else {7383 } else {
...@@ -7396,15 +7385,15 @@ pub const FuncGen = struct {...@@ -7396,15 +7385,15 @@ pub const FuncGen = struct {
7396 }7385 }
7397 }7386 }
73987387
7399 const payload_ty = err_union_ty.errorUnionPayload(mod);7388 const payload_ty = err_union_ty.errorUnionPayload(zcu);
7400 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {7389 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7401 if (!operand_is_ptr) return operand;7390 if (!operand_is_ptr) return operand;
7402 return self.wip.load(.normal, error_type, operand, .default, "");7391 return self.wip.load(.normal, error_type, operand, .default, "");
7403 }7392 }
74047393
7405 const offset = try errUnionErrorOffset(payload_ty, pt);7394 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)) {
7408 const err_union_llvm_ty = try o.lowerType(err_union_ty);7397 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7409 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");7398 const err_field_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, offset, "");
7410 return self.wip.load(.normal, error_type, err_field_ptr, .default, "");7399 return self.wip.load(.normal, error_type, err_field_ptr, .default, "");
...@@ -7416,21 +7405,21 @@ pub const FuncGen = struct {...@@ -7416,21 +7405,21 @@ pub const FuncGen = struct {
7416 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7405 fn airErrUnionPayloadPtrSet(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7417 const o = self.ng.object;7406 const o = self.ng.object;
7418 const pt = o.pt;7407 const pt = o.pt;
7419 const mod = pt.zcu;7408 const zcu = pt.zcu;
7420 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7409 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7421 const operand = try self.resolveInst(ty_op.operand);7410 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);
7425 const non_error_val = try o.builder.intValue(try o.errorIntType(), 0);7414 const non_error_val = try o.builder.intValue(try o.errorIntType(), 0);
7426 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {7415 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7427 _ = try self.wip.store(.normal, non_error_val, operand, .default);7416 _ = try self.wip.store(.normal, non_error_val, operand, .default);
7428 return operand;7417 return operand;
7429 }7418 }
7430 const err_union_llvm_ty = try o.lowerType(err_union_ty);7419 const err_union_llvm_ty = try o.lowerType(err_union_ty);
7431 {7420 {
7432 const err_int_ty = try pt.errorIntType();7421 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();
7434 const error_offset = try errUnionErrorOffset(payload_ty, pt);7423 const error_offset = try errUnionErrorOffset(payload_ty, pt);
7435 // First set the non-error value.7424 // First set the non-error value.
7436 const non_null_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, error_offset, "");7425 const non_null_ptr = try self.wip.gepStruct(err_union_llvm_ty, operand, error_offset, "");
...@@ -7457,7 +7446,7 @@ pub const FuncGen = struct {...@@ -7457,7 +7446,7 @@ pub const FuncGen = struct {
7457 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7446 fn airSaveErrReturnTraceIndex(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7458 const o = self.ng.object;7447 const o = self.ng.object;
7459 const pt = o.pt;7448 const pt = o.pt;
7460 const mod = pt.zcu;7449 const zcu = pt.zcu;
74617450
7462 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;7451 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
7463 const struct_ty = ty_pl.ty.toType();7452 const struct_ty = ty_pl.ty.toType();
...@@ -7468,8 +7457,8 @@ pub const FuncGen = struct {...@@ -7468,8 +7457,8 @@ pub const FuncGen = struct {
7468 assert(self.err_ret_trace != .none);7457 assert(self.err_ret_trace != .none);
7469 const field_ptr =7458 const field_ptr =
7470 try self.wip.gepStruct(struct_llvm_ty, self.err_ret_trace, llvm_field_index, "");7459 try self.wip.gepStruct(struct_llvm_ty, self.err_ret_trace, llvm_field_index, "");
7471 const field_alignment = struct_ty.structFieldAlign(field_index, pt);7460 const field_alignment = struct_ty.fieldAlignment(field_index, zcu);
7472 const field_ty = struct_ty.structFieldType(field_index, mod);7461 const field_ty = struct_ty.fieldType(field_index, zcu);
7473 const field_ptr_ty = try pt.ptrType(.{7462 const field_ptr_ty = try pt.ptrType(.{
7474 .child = field_ty.toIntern(),7463 .child = field_ty.toIntern(),
7475 .flags = .{ .alignment = field_alignment },7464 .flags = .{ .alignment = field_alignment },
...@@ -7503,23 +7492,23 @@ pub const FuncGen = struct {...@@ -7503,23 +7492,23 @@ pub const FuncGen = struct {
7503 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {7492 fn airWrapOptional(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
7504 const o = self.ng.object;7493 const o = self.ng.object;
7505 const pt = o.pt;7494 const pt = o.pt;
7506 const mod = pt.zcu;7495 const zcu = pt.zcu;
7507 const inst = body_tail[0];7496 const inst = body_tail[0];
7508 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7497 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7509 const payload_ty = self.typeOf(ty_op.operand);7498 const payload_ty = self.typeOf(ty_op.operand);
7510 const non_null_bit = try o.builder.intValue(.i8, 1);7499 const non_null_bit = try o.builder.intValue(.i8, 1);
7511 comptime assert(optional_layout_version == 3);7500 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;
7513 const operand = try self.resolveInst(ty_op.operand);7502 const operand = try self.resolveInst(ty_op.operand);
7514 const optional_ty = self.typeOfIndex(inst);7503 const optional_ty = self.typeOfIndex(inst);
7515 if (optional_ty.optionalReprIsPayload(mod)) return operand;7504 if (optional_ty.optionalReprIsPayload(zcu)) return operand;
7516 const llvm_optional_ty = try o.lowerType(optional_ty);7505 const llvm_optional_ty = try o.lowerType(optional_ty);
7517 if (isByRef(optional_ty, pt)) {7506 if (isByRef(optional_ty, zcu)) {
7518 const directReturn = self.isNextRet(body_tail);7507 const directReturn = self.isNextRet(body_tail);
7519 const optional_ptr = if (directReturn)7508 const optional_ptr = if (directReturn)
7520 self.ret_ptr7509 self.ret_ptr
7521 else brk: {7510 else brk: {
7522 const alignment = optional_ty.abiAlignment(pt).toLlvm();7511 const alignment = optional_ty.abiAlignment(zcu).toLlvm();
7523 const optional_ptr = try self.buildAllocaWorkaround(optional_ty, alignment);7512 const optional_ptr = try self.buildAllocaWorkaround(optional_ty, alignment);
7524 break :brk optional_ptr;7513 break :brk optional_ptr;
7525 };7514 };
...@@ -7537,12 +7526,13 @@ pub const FuncGen = struct {...@@ -7537,12 +7526,13 @@ pub const FuncGen = struct {
7537 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {7526 fn airWrapErrUnionPayload(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
7538 const o = self.ng.object;7527 const o = self.ng.object;
7539 const pt = o.pt;7528 const pt = o.pt;
7529 const zcu = pt.zcu;
7540 const inst = body_tail[0];7530 const inst = body_tail[0];
7541 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7531 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7542 const err_un_ty = self.typeOfIndex(inst);7532 const err_un_ty = self.typeOfIndex(inst);
7543 const operand = try self.resolveInst(ty_op.operand);7533 const operand = try self.resolveInst(ty_op.operand);
7544 const payload_ty = self.typeOf(ty_op.operand);7534 const payload_ty = self.typeOf(ty_op.operand);
7545 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {7535 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
7546 return operand;7536 return operand;
7547 }7537 }
7548 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);7538 const ok_err_code = try o.builder.intValue(try o.errorIntType(), 0);
...@@ -7550,19 +7540,19 @@ pub const FuncGen = struct {...@@ -7550,19 +7540,19 @@ pub const FuncGen = struct {
75507540
7551 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);7541 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
7552 const error_offset = try errUnionErrorOffset(payload_ty, pt);7542 const error_offset = try errUnionErrorOffset(payload_ty, pt);
7553 if (isByRef(err_un_ty, pt)) {7543 if (isByRef(err_un_ty, zcu)) {
7554 const directReturn = self.isNextRet(body_tail);7544 const directReturn = self.isNextRet(body_tail);
7555 const result_ptr = if (directReturn)7545 const result_ptr = if (directReturn)
7556 self.ret_ptr7546 self.ret_ptr
7557 else brk: {7547 else brk: {
7558 const alignment = err_un_ty.abiAlignment(pt).toLlvm();7548 const alignment = err_un_ty.abiAlignment(pt.zcu).toLlvm();
7559 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);7549 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);
7560 break :brk result_ptr;7550 break :brk result_ptr;
7561 };7551 };
75627552
7563 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");7553 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");
7564 const err_int_ty = try pt.errorIntType();7554 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();
7566 _ = try self.wip.store(.normal, ok_err_code, err_ptr, error_alignment);7556 _ = try self.wip.store(.normal, ok_err_code, err_ptr, error_alignment);
7567 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");7557 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");
7568 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);7558 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);
...@@ -7578,30 +7568,30 @@ pub const FuncGen = struct {...@@ -7578,30 +7568,30 @@ pub const FuncGen = struct {
7578 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {7568 fn airWrapErrUnionErr(self: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
7579 const o = self.ng.object;7569 const o = self.ng.object;
7580 const pt = o.pt;7570 const pt = o.pt;
7581 const mod = pt.zcu;7571 const zcu = pt.zcu;
7582 const inst = body_tail[0];7572 const inst = body_tail[0];
7583 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;7573 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
7584 const err_un_ty = self.typeOfIndex(inst);7574 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);
7586 const operand = try self.resolveInst(ty_op.operand);7576 const operand = try self.resolveInst(ty_op.operand);
7587 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) return operand;7577 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) return operand;
7588 const err_un_llvm_ty = try o.lowerType(err_un_ty);7578 const err_un_llvm_ty = try o.lowerType(err_un_ty);
75897579
7590 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);7580 const payload_offset = try errUnionPayloadOffset(payload_ty, pt);
7591 const error_offset = try errUnionErrorOffset(payload_ty, pt);7581 const error_offset = try errUnionErrorOffset(payload_ty, pt);
7592 if (isByRef(err_un_ty, pt)) {7582 if (isByRef(err_un_ty, zcu)) {
7593 const directReturn = self.isNextRet(body_tail);7583 const directReturn = self.isNextRet(body_tail);
7594 const result_ptr = if (directReturn)7584 const result_ptr = if (directReturn)
7595 self.ret_ptr7585 self.ret_ptr
7596 else brk: {7586 else brk: {
7597 const alignment = err_un_ty.abiAlignment(pt).toLlvm();7587 const alignment = err_un_ty.abiAlignment(zcu).toLlvm();
7598 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);7588 const result_ptr = try self.buildAllocaWorkaround(err_un_ty, alignment);
7599 break :brk result_ptr;7589 break :brk result_ptr;
7600 };7590 };
76017591
7602 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");7592 const err_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, error_offset, "");
7603 const err_int_ty = try pt.errorIntType();7593 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();
7605 _ = try self.wip.store(.normal, operand, err_ptr, error_alignment);7595 _ = try self.wip.store(.normal, operand, err_ptr, error_alignment);
7606 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");7596 const payload_ptr = try self.wip.gepStruct(err_un_llvm_ty, result_ptr, payload_offset, "");
7607 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);7597 const payload_ptr_ty = try pt.singleMutPtrType(payload_ty);
...@@ -7639,7 +7629,7 @@ pub const FuncGen = struct {...@@ -7639,7 +7629,7 @@ pub const FuncGen = struct {
7639 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7629 fn airVectorStoreElem(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7640 const o = self.ng.object;7630 const o = self.ng.object;
7641 const pt = o.pt;7631 const pt = o.pt;
7642 const mod = pt.zcu;7632 const zcu = pt.zcu;
7643 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;7633 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
7644 const extra = self.air.extraData(Air.Bin, data.payload).data;7634 const extra = self.air.extraData(Air.Bin, data.payload).data;
76457635
...@@ -7649,9 +7639,9 @@ pub const FuncGen = struct {...@@ -7649,9 +7639,9 @@ pub const FuncGen = struct {
7649 const operand = try self.resolveInst(extra.rhs);7639 const operand = try self.resolveInst(extra.rhs);
76507640
7651 const access_kind: Builder.MemoryAccessKind =7641 const access_kind: Builder.MemoryAccessKind =
7652 if (vector_ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;7642 if (vector_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
7653 const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(mod));7643 const elem_llvm_ty = try o.lowerType(vector_ptr_ty.childType(zcu));
7654 const alignment = vector_ptr_ty.ptrAlignment(pt).toLlvm();7644 const alignment = vector_ptr_ty.ptrAlignment(zcu).toLlvm();
7655 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");7645 const loaded = try self.wip.load(access_kind, elem_llvm_ty, vector_ptr, alignment, "");
76567646
7657 const new_vector = try self.wip.insertElement(loaded, operand, index, "");7647 const new_vector = try self.wip.insertElement(loaded, operand, index, "");
...@@ -7661,18 +7651,18 @@ pub const FuncGen = struct {...@@ -7661,18 +7651,18 @@ pub const FuncGen = struct {
76617651
7662 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7652 fn airMin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7663 const o = self.ng.object;7653 const o = self.ng.object;
7664 const mod = o.pt.zcu;7654 const zcu = o.pt.zcu;
7665 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7655 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7666 const lhs = try self.resolveInst(bin_op.lhs);7656 const lhs = try self.resolveInst(bin_op.lhs);
7667 const rhs = try self.resolveInst(bin_op.rhs);7657 const rhs = try self.resolveInst(bin_op.rhs);
7668 const inst_ty = self.typeOfIndex(inst);7658 const inst_ty = self.typeOfIndex(inst);
7669 const scalar_ty = inst_ty.scalarType(mod);7659 const scalar_ty = inst_ty.scalarType(zcu);
76707660
7671 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmin, .normal, inst_ty, 2, .{ lhs, rhs });7661 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmin, .normal, inst_ty, 2, .{ lhs, rhs });
7672 return self.wip.callIntrinsic(7662 return self.wip.callIntrinsic(
7673 .normal,7663 .normal,
7674 .none,7664 .none,
7675 if (scalar_ty.isSignedInt(mod)) .smin else .umin,7665 if (scalar_ty.isSignedInt(zcu)) .smin else .umin,
7676 &.{try o.lowerType(inst_ty)},7666 &.{try o.lowerType(inst_ty)},
7677 &.{ lhs, rhs },7667 &.{ lhs, rhs },
7678 "",7668 "",
...@@ -7681,18 +7671,18 @@ pub const FuncGen = struct {...@@ -7681,18 +7671,18 @@ pub const FuncGen = struct {
76817671
7682 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7672 fn airMax(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7683 const o = self.ng.object;7673 const o = self.ng.object;
7684 const mod = o.pt.zcu;7674 const zcu = o.pt.zcu;
7685 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7675 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7686 const lhs = try self.resolveInst(bin_op.lhs);7676 const lhs = try self.resolveInst(bin_op.lhs);
7687 const rhs = try self.resolveInst(bin_op.rhs);7677 const rhs = try self.resolveInst(bin_op.rhs);
7688 const inst_ty = self.typeOfIndex(inst);7678 const inst_ty = self.typeOfIndex(inst);
7689 const scalar_ty = inst_ty.scalarType(mod);7679 const scalar_ty = inst_ty.scalarType(zcu);
76907680
7691 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmax, .normal, inst_ty, 2, .{ lhs, rhs });7681 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.fmax, .normal, inst_ty, 2, .{ lhs, rhs });
7692 return self.wip.callIntrinsic(7682 return self.wip.callIntrinsic(
7693 .normal,7683 .normal,
7694 .none,7684 .none,
7695 if (scalar_ty.isSignedInt(mod)) .smax else .umax,7685 if (scalar_ty.isSignedInt(zcu)) .smax else .umax,
7696 &.{try o.lowerType(inst_ty)},7686 &.{try o.lowerType(inst_ty)},
7697 &.{ lhs, rhs },7687 &.{ lhs, rhs },
7698 "",7688 "",
...@@ -7711,15 +7701,15 @@ pub const FuncGen = struct {...@@ -7711,15 +7701,15 @@ pub const FuncGen = struct {
77117701
7712 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7702 fn airAdd(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7713 const o = self.ng.object;7703 const o = self.ng.object;
7714 const mod = o.pt.zcu;7704 const zcu = o.pt.zcu;
7715 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7705 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7716 const lhs = try self.resolveInst(bin_op.lhs);7706 const lhs = try self.resolveInst(bin_op.lhs);
7717 const rhs = try self.resolveInst(bin_op.rhs);7707 const rhs = try self.resolveInst(bin_op.rhs);
7718 const inst_ty = self.typeOfIndex(inst);7708 const inst_ty = self.typeOfIndex(inst);
7719 const scalar_ty = inst_ty.scalarType(mod);7709 const scalar_ty = inst_ty.scalarType(zcu);
77207710
7721 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.add, fast, inst_ty, 2, .{ lhs, rhs });7711 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, "");
7723 }7713 }
77247714
7725 fn airSafeArithmetic(7715 fn airSafeArithmetic(
...@@ -7729,15 +7719,15 @@ pub const FuncGen = struct {...@@ -7729,15 +7719,15 @@ pub const FuncGen = struct {
7729 unsigned_intrinsic: Builder.Intrinsic,7719 unsigned_intrinsic: Builder.Intrinsic,
7730 ) !Builder.Value {7720 ) !Builder.Value {
7731 const o = fg.ng.object;7721 const o = fg.ng.object;
7732 const mod = o.pt.zcu;7722 const zcu = o.pt.zcu;
77337723
7734 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7724 const bin_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7735 const lhs = try fg.resolveInst(bin_op.lhs);7725 const lhs = try fg.resolveInst(bin_op.lhs);
7736 const rhs = try fg.resolveInst(bin_op.rhs);7726 const rhs = try fg.resolveInst(bin_op.rhs);
7737 const inst_ty = fg.typeOfIndex(inst);7727 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;
7741 const llvm_inst_ty = try o.lowerType(inst_ty);7731 const llvm_inst_ty = try o.lowerType(inst_ty);
7742 const results =7732 const results =
7743 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");7733 try fg.wip.callIntrinsic(.normal, .none, intrinsic, &.{llvm_inst_ty}, &.{ lhs, rhs }, "");
...@@ -7777,18 +7767,18 @@ pub const FuncGen = struct {...@@ -7777,18 +7767,18 @@ pub const FuncGen = struct {
77777767
7778 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7768 fn airAddSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7779 const o = self.ng.object;7769 const o = self.ng.object;
7780 const mod = o.pt.zcu;7770 const zcu = o.pt.zcu;
7781 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7771 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7782 const lhs = try self.resolveInst(bin_op.lhs);7772 const lhs = try self.resolveInst(bin_op.lhs);
7783 const rhs = try self.resolveInst(bin_op.rhs);7773 const rhs = try self.resolveInst(bin_op.rhs);
7784 const inst_ty = self.typeOfIndex(inst);7774 const inst_ty = self.typeOfIndex(inst);
7785 const scalar_ty = inst_ty.scalarType(mod);7775 const scalar_ty = inst_ty.scalarType(zcu);
77867776
7787 if (scalar_ty.isAnyFloat()) return self.todo("saturating float add", .{});7777 if (scalar_ty.isAnyFloat()) return self.todo("saturating float add", .{});
7788 return self.wip.callIntrinsic(7778 return self.wip.callIntrinsic(
7789 .normal,7779 .normal,
7790 .none,7780 .none,
7791 if (scalar_ty.isSignedInt(mod)) .@"sadd.sat" else .@"uadd.sat",7781 if (scalar_ty.isSignedInt(zcu)) .@"sadd.sat" else .@"uadd.sat",
7792 &.{try o.lowerType(inst_ty)},7782 &.{try o.lowerType(inst_ty)},
7793 &.{ lhs, rhs },7783 &.{ lhs, rhs },
7794 "",7784 "",
...@@ -7797,15 +7787,15 @@ pub const FuncGen = struct {...@@ -7797,15 +7787,15 @@ pub const FuncGen = struct {
77977787
7798 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7788 fn airSub(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7799 const o = self.ng.object;7789 const o = self.ng.object;
7800 const mod = o.pt.zcu;7790 const zcu = o.pt.zcu;
7801 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7791 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7802 const lhs = try self.resolveInst(bin_op.lhs);7792 const lhs = try self.resolveInst(bin_op.lhs);
7803 const rhs = try self.resolveInst(bin_op.rhs);7793 const rhs = try self.resolveInst(bin_op.rhs);
7804 const inst_ty = self.typeOfIndex(inst);7794 const inst_ty = self.typeOfIndex(inst);
7805 const scalar_ty = inst_ty.scalarType(mod);7795 const scalar_ty = inst_ty.scalarType(zcu);
78067796
7807 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.sub, fast, inst_ty, 2, .{ lhs, rhs });7797 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, "");
7809 }7799 }
78107800
7811 fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7801 fn airSubWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
...@@ -7818,18 +7808,18 @@ pub const FuncGen = struct {...@@ -7818,18 +7808,18 @@ pub const FuncGen = struct {
78187808
7819 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7809 fn airSubSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7820 const o = self.ng.object;7810 const o = self.ng.object;
7821 const mod = o.pt.zcu;7811 const zcu = o.pt.zcu;
7822 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7812 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7823 const lhs = try self.resolveInst(bin_op.lhs);7813 const lhs = try self.resolveInst(bin_op.lhs);
7824 const rhs = try self.resolveInst(bin_op.rhs);7814 const rhs = try self.resolveInst(bin_op.rhs);
7825 const inst_ty = self.typeOfIndex(inst);7815 const inst_ty = self.typeOfIndex(inst);
7826 const scalar_ty = inst_ty.scalarType(mod);7816 const scalar_ty = inst_ty.scalarType(zcu);
78277817
7828 if (scalar_ty.isAnyFloat()) return self.todo("saturating float sub", .{});7818 if (scalar_ty.isAnyFloat()) return self.todo("saturating float sub", .{});
7829 return self.wip.callIntrinsic(7819 return self.wip.callIntrinsic(
7830 .normal,7820 .normal,
7831 .none,7821 .none,
7832 if (scalar_ty.isSignedInt(mod)) .@"ssub.sat" else .@"usub.sat",7822 if (scalar_ty.isSignedInt(zcu)) .@"ssub.sat" else .@"usub.sat",
7833 &.{try o.lowerType(inst_ty)},7823 &.{try o.lowerType(inst_ty)},
7834 &.{ lhs, rhs },7824 &.{ lhs, rhs },
7835 "",7825 "",
...@@ -7838,15 +7828,15 @@ pub const FuncGen = struct {...@@ -7838,15 +7828,15 @@ pub const FuncGen = struct {
78387828
7839 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7829 fn airMul(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7840 const o = self.ng.object;7830 const o = self.ng.object;
7841 const mod = o.pt.zcu;7831 const zcu = o.pt.zcu;
7842 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7832 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7843 const lhs = try self.resolveInst(bin_op.lhs);7833 const lhs = try self.resolveInst(bin_op.lhs);
7844 const rhs = try self.resolveInst(bin_op.rhs);7834 const rhs = try self.resolveInst(bin_op.rhs);
7845 const inst_ty = self.typeOfIndex(inst);7835 const inst_ty = self.typeOfIndex(inst);
7846 const scalar_ty = inst_ty.scalarType(mod);7836 const scalar_ty = inst_ty.scalarType(zcu);
78477837
7848 if (scalar_ty.isAnyFloat()) return self.buildFloatOp(.mul, fast, inst_ty, 2, .{ lhs, rhs });7838 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, "");
7850 }7840 }
78517841
7852 fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7842 fn airMulWrap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
...@@ -7859,18 +7849,18 @@ pub const FuncGen = struct {...@@ -7859,18 +7849,18 @@ pub const FuncGen = struct {
78597849
7860 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7850 fn airMulSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
7861 const o = self.ng.object;7851 const o = self.ng.object;
7862 const mod = o.pt.zcu;7852 const zcu = o.pt.zcu;
7863 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7853 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7864 const lhs = try self.resolveInst(bin_op.lhs);7854 const lhs = try self.resolveInst(bin_op.lhs);
7865 const rhs = try self.resolveInst(bin_op.rhs);7855 const rhs = try self.resolveInst(bin_op.rhs);
7866 const inst_ty = self.typeOfIndex(inst);7856 const inst_ty = self.typeOfIndex(inst);
7867 const scalar_ty = inst_ty.scalarType(mod);7857 const scalar_ty = inst_ty.scalarType(zcu);
78687858
7869 if (scalar_ty.isAnyFloat()) return self.todo("saturating float mul", .{});7859 if (scalar_ty.isAnyFloat()) return self.todo("saturating float mul", .{});
7870 return self.wip.callIntrinsic(7860 return self.wip.callIntrinsic(
7871 .normal,7861 .normal,
7872 .none,7862 .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",
7874 &.{try o.lowerType(inst_ty)},7864 &.{try o.lowerType(inst_ty)},
7875 &.{ lhs, rhs, .@"0" },7865 &.{ lhs, rhs, .@"0" },
7876 "",7866 "",
...@@ -7888,34 +7878,34 @@ pub const FuncGen = struct {...@@ -7888,34 +7878,34 @@ pub const FuncGen = struct {
78887878
7889 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7879 fn airDivTrunc(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7890 const o = self.ng.object;7880 const o = self.ng.object;
7891 const mod = o.pt.zcu;7881 const zcu = o.pt.zcu;
7892 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7882 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7893 const lhs = try self.resolveInst(bin_op.lhs);7883 const lhs = try self.resolveInst(bin_op.lhs);
7894 const rhs = try self.resolveInst(bin_op.rhs);7884 const rhs = try self.resolveInst(bin_op.rhs);
7895 const inst_ty = self.typeOfIndex(inst);7885 const inst_ty = self.typeOfIndex(inst);
7896 const scalar_ty = inst_ty.scalarType(mod);7886 const scalar_ty = inst_ty.scalarType(zcu);
78977887
7898 if (scalar_ty.isRuntimeFloat()) {7888 if (scalar_ty.isRuntimeFloat()) {
7899 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });7889 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
7900 return self.buildFloatOp(.trunc, fast, inst_ty, 1, .{result});7890 return self.buildFloatOp(.trunc, fast, inst_ty, 1, .{result});
7901 }7891 }
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, "");
7903 }7893 }
79047894
7905 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7895 fn airDivFloor(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7906 const o = self.ng.object;7896 const o = self.ng.object;
7907 const mod = o.pt.zcu;7897 const zcu = o.pt.zcu;
7908 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7898 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7909 const lhs = try self.resolveInst(bin_op.lhs);7899 const lhs = try self.resolveInst(bin_op.lhs);
7910 const rhs = try self.resolveInst(bin_op.rhs);7900 const rhs = try self.resolveInst(bin_op.rhs);
7911 const inst_ty = self.typeOfIndex(inst);7901 const inst_ty = self.typeOfIndex(inst);
7912 const scalar_ty = inst_ty.scalarType(mod);7902 const scalar_ty = inst_ty.scalarType(zcu);
79137903
7914 if (scalar_ty.isRuntimeFloat()) {7904 if (scalar_ty.isRuntimeFloat()) {
7915 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });7905 const result = try self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
7916 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});7906 return self.buildFloatOp(.floor, fast, inst_ty, 1, .{result});
7917 }7907 }
7918 if (scalar_ty.isSignedInt(mod)) {7908 if (scalar_ty.isSignedInt(zcu)) {
7919 const inst_llvm_ty = try o.lowerType(inst_ty);7909 const inst_llvm_ty = try o.lowerType(inst_ty);
7920 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(7910 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(
7921 inst_llvm_ty.scalarType(&o.builder),7911 inst_llvm_ty.scalarType(&o.builder),
...@@ -7936,16 +7926,16 @@ pub const FuncGen = struct {...@@ -7936,16 +7926,16 @@ pub const FuncGen = struct {
79367926
7937 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7927 fn airDivExact(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7938 const o = self.ng.object;7928 const o = self.ng.object;
7939 const mod = o.pt.zcu;7929 const zcu = o.pt.zcu;
7940 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7930 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7941 const lhs = try self.resolveInst(bin_op.lhs);7931 const lhs = try self.resolveInst(bin_op.lhs);
7942 const rhs = try self.resolveInst(bin_op.rhs);7932 const rhs = try self.resolveInst(bin_op.rhs);
7943 const inst_ty = self.typeOfIndex(inst);7933 const inst_ty = self.typeOfIndex(inst);
7944 const scalar_ty = inst_ty.scalarType(mod);7934 const scalar_ty = inst_ty.scalarType(zcu);
79457935
7946 if (scalar_ty.isRuntimeFloat()) return self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });7936 if (scalar_ty.isRuntimeFloat()) return self.buildFloatOp(.div, fast, inst_ty, 2, .{ lhs, rhs });
7947 return self.wip.bin(7937 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",
7949 lhs,7939 lhs,
7950 rhs,7940 rhs,
7951 "",7941 "",
...@@ -7954,16 +7944,16 @@ pub const FuncGen = struct {...@@ -7954,16 +7944,16 @@ pub const FuncGen = struct {
79547944
7955 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7945 fn airRem(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7956 const o = self.ng.object;7946 const o = self.ng.object;
7957 const mod = o.pt.zcu;7947 const zcu = o.pt.zcu;
7958 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7948 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7959 const lhs = try self.resolveInst(bin_op.lhs);7949 const lhs = try self.resolveInst(bin_op.lhs);
7960 const rhs = try self.resolveInst(bin_op.rhs);7950 const rhs = try self.resolveInst(bin_op.rhs);
7961 const inst_ty = self.typeOfIndex(inst);7951 const inst_ty = self.typeOfIndex(inst);
7962 const scalar_ty = inst_ty.scalarType(mod);7952 const scalar_ty = inst_ty.scalarType(zcu);
79637953
7964 if (scalar_ty.isRuntimeFloat())7954 if (scalar_ty.isRuntimeFloat())
7965 return self.buildFloatOp(.fmod, fast, inst_ty, 2, .{ lhs, rhs });7955 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))
7967 .srem7957 .srem
7968 else7958 else
7969 .urem, lhs, rhs, "");7959 .urem, lhs, rhs, "");
...@@ -7971,13 +7961,13 @@ pub const FuncGen = struct {...@@ -7971,13 +7961,13 @@ pub const FuncGen = struct {
79717961
7972 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {7962 fn airMod(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
7973 const o = self.ng.object;7963 const o = self.ng.object;
7974 const mod = o.pt.zcu;7964 const zcu = o.pt.zcu;
7975 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;7965 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
7976 const lhs = try self.resolveInst(bin_op.lhs);7966 const lhs = try self.resolveInst(bin_op.lhs);
7977 const rhs = try self.resolveInst(bin_op.rhs);7967 const rhs = try self.resolveInst(bin_op.rhs);
7978 const inst_ty = self.typeOfIndex(inst);7968 const inst_ty = self.typeOfIndex(inst);
7979 const inst_llvm_ty = try o.lowerType(inst_ty);7969 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
7982 if (scalar_ty.isRuntimeFloat()) {7972 if (scalar_ty.isRuntimeFloat()) {
7983 const a = try self.buildFloatOp(.fmod, fast, inst_ty, 2, .{ lhs, rhs });7973 const a = try self.buildFloatOp(.fmod, fast, inst_ty, 2, .{ lhs, rhs });
...@@ -7987,7 +7977,7 @@ pub const FuncGen = struct {...@@ -7987,7 +7977,7 @@ pub const FuncGen = struct {
7987 const ltz = try self.buildFloatCmp(fast, .lt, inst_ty, .{ lhs, zero });7977 const ltz = try self.buildFloatCmp(fast, .lt, inst_ty, .{ lhs, zero });
7988 return self.wip.select(fast, ltz, c, a, "");7978 return self.wip.select(fast, ltz, c, a, "");
7989 }7979 }
7990 if (scalar_ty.isSignedInt(mod)) {7980 if (scalar_ty.isSignedInt(zcu)) {
7991 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(7981 const bit_size_minus_one = try o.builder.splatValue(inst_llvm_ty, try o.builder.intConst(
7992 inst_llvm_ty.scalarType(&o.builder),7982 inst_llvm_ty.scalarType(&o.builder),
7993 inst_llvm_ty.scalarBits(&o.builder) - 1,7983 inst_llvm_ty.scalarBits(&o.builder) - 1,
...@@ -8007,14 +7997,14 @@ pub const FuncGen = struct {...@@ -8007,14 +7997,14 @@ pub const FuncGen = struct {
80077997
8008 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {7998 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8009 const o = self.ng.object;7999 const o = self.ng.object;
8010 const mod = o.pt.zcu;8000 const zcu = o.pt.zcu;
8011 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8001 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8012 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;8002 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
8013 const ptr = try self.resolveInst(bin_op.lhs);8003 const ptr = try self.resolveInst(bin_op.lhs);
8014 const offset = try self.resolveInst(bin_op.rhs);8004 const offset = try self.resolveInst(bin_op.rhs);
8015 const ptr_ty = self.typeOf(bin_op.lhs);8005 const ptr_ty = self.typeOf(bin_op.lhs);
8016 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(mod));8006 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8017 switch (ptr_ty.ptrSize(mod)) {8007 switch (ptr_ty.ptrSize(zcu)) {
8018 // It's a pointer to an array, so according to LLVM we need an extra GEP index.8008 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
8019 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{8009 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
8020 try o.builder.intValue(try o.lowerType(Type.usize), 0), offset,8010 try o.builder.intValue(try o.lowerType(Type.usize), 0), offset,
...@@ -8029,15 +8019,15 @@ pub const FuncGen = struct {...@@ -8029,15 +8019,15 @@ pub const FuncGen = struct {
80298019
8030 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8020 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8031 const o = self.ng.object;8021 const o = self.ng.object;
8032 const mod = o.pt.zcu;8022 const zcu = o.pt.zcu;
8033 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8023 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8034 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;8024 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
8035 const ptr = try self.resolveInst(bin_op.lhs);8025 const ptr = try self.resolveInst(bin_op.lhs);
8036 const offset = try self.resolveInst(bin_op.rhs);8026 const offset = try self.resolveInst(bin_op.rhs);
8037 const negative_offset = try self.wip.neg(offset, "");8027 const negative_offset = try self.wip.neg(offset, "");
8038 const ptr_ty = self.typeOf(bin_op.lhs);8028 const ptr_ty = self.typeOf(bin_op.lhs);
8039 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(mod));8029 const llvm_elem_ty = try o.lowerPtrElemTy(ptr_ty.childType(zcu));
8040 switch (ptr_ty.ptrSize(mod)) {8030 switch (ptr_ty.ptrSize(zcu)) {
8041 // It's a pointer to an array, so according to LLVM we need an extra GEP index.8031 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
8042 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{8032 .One => return self.wip.gep(.inbounds, llvm_elem_ty, ptr, &.{
8043 try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset,8033 try o.builder.intValue(try o.lowerType(Type.usize), 0), negative_offset,
...@@ -8058,7 +8048,7 @@ pub const FuncGen = struct {...@@ -8058,7 +8048,7 @@ pub const FuncGen = struct {
8058 ) !Builder.Value {8048 ) !Builder.Value {
8059 const o = self.ng.object;8049 const o = self.ng.object;
8060 const pt = o.pt;8050 const pt = o.pt;
8061 const mod = pt.zcu;8051 const zcu = pt.zcu;
8062 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8052 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8063 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;8053 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
80648054
...@@ -8066,10 +8056,10 @@ pub const FuncGen = struct {...@@ -8066,10 +8056,10 @@ pub const FuncGen = struct {
8066 const rhs = try self.resolveInst(extra.rhs);8056 const rhs = try self.resolveInst(extra.rhs);
80678057
8068 const lhs_ty = self.typeOf(extra.lhs);8058 const lhs_ty = self.typeOf(extra.lhs);
8069 const scalar_ty = lhs_ty.scalarType(mod);8059 const scalar_ty = lhs_ty.scalarType(zcu);
8070 const inst_ty = self.typeOfIndex(inst);8060 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;
8073 const llvm_inst_ty = try o.lowerType(inst_ty);8063 const llvm_inst_ty = try o.lowerType(inst_ty);
8074 const llvm_lhs_ty = try o.lowerType(lhs_ty);8064 const llvm_lhs_ty = try o.lowerType(lhs_ty);
8075 const results =8065 const results =
...@@ -8081,8 +8071,8 @@ pub const FuncGen = struct {...@@ -8081,8 +8071,8 @@ pub const FuncGen = struct {
8081 const result_index = o.llvmFieldIndex(inst_ty, 0).?;8071 const result_index = o.llvmFieldIndex(inst_ty, 0).?;
8082 const overflow_index = o.llvmFieldIndex(inst_ty, 1).?;8072 const overflow_index = o.llvmFieldIndex(inst_ty, 1).?;
80838073
8084 if (isByRef(inst_ty, pt)) {8074 if (isByRef(inst_ty, zcu)) {
8085 const result_alignment = inst_ty.abiAlignment(pt).toLlvm();8075 const result_alignment = inst_ty.abiAlignment(zcu).toLlvm();
8086 const alloca_inst = try self.buildAllocaWorkaround(inst_ty, result_alignment);8076 const alloca_inst = try self.buildAllocaWorkaround(inst_ty, result_alignment);
8087 {8077 {
8088 const field_ptr = try self.wip.gepStruct(llvm_inst_ty, alloca_inst, result_index, "");8078 const field_ptr = try self.wip.gepStruct(llvm_inst_ty, alloca_inst, result_index, "");
...@@ -8165,9 +8155,9 @@ pub const FuncGen = struct {...@@ -8165,9 +8155,9 @@ pub const FuncGen = struct {
8165 params: [2]Builder.Value,8155 params: [2]Builder.Value,
8166 ) !Builder.Value {8156 ) !Builder.Value {
8167 const o = self.ng.object;8157 const o = self.ng.object;
8168 const mod = o.pt.zcu;8158 const zcu = o.pt.zcu;
8169 const target = mod.getTarget();8159 const target = zcu.getTarget();
8170 const scalar_ty = ty.scalarType(mod);8160 const scalar_ty = ty.scalarType(zcu);
8171 const scalar_llvm_ty = try o.lowerType(scalar_ty);8161 const scalar_llvm_ty = try o.lowerType(scalar_ty);
81728162
8173 if (intrinsicsAllowed(scalar_ty, target)) {8163 if (intrinsicsAllowed(scalar_ty, target)) {
...@@ -8205,8 +8195,8 @@ pub const FuncGen = struct {...@@ -8205,8 +8195,8 @@ pub const FuncGen = struct {
8205 .gte => .sge,8195 .gte => .sge,
8206 };8196 };
82078197
8208 if (ty.zigTypeTag(mod) == .Vector) {8198 if (ty.zigTypeTag(zcu) == .Vector) {
8209 const vec_len = ty.vectorLen(mod);8199 const vec_len = ty.vectorLen(zcu);
8210 const vector_result_ty = try o.builder.vectorType(.normal, vec_len, .i32);8200 const vector_result_ty = try o.builder.vectorType(.normal, vec_len, .i32);
82118201
8212 const init = try o.builder.poisonValue(vector_result_ty);8202 const init = try o.builder.poisonValue(vector_result_ty);
...@@ -8271,9 +8261,9 @@ pub const FuncGen = struct {...@@ -8271,9 +8261,9 @@ pub const FuncGen = struct {
8271 params: [params_len]Builder.Value,8261 params: [params_len]Builder.Value,
8272 ) !Builder.Value {8262 ) !Builder.Value {
8273 const o = self.ng.object;8263 const o = self.ng.object;
8274 const mod = o.pt.zcu;8264 const zcu = o.pt.zcu;
8275 const target = mod.getTarget();8265 const target = zcu.getTarget();
8276 const scalar_ty = ty.scalarType(mod);8266 const scalar_ty = ty.scalarType(zcu);
8277 const llvm_ty = try o.lowerType(ty);8267 const llvm_ty = try o.lowerType(ty);
82788268
8279 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {8269 if (op != .tan and intrinsicsAllowed(scalar_ty, target)) switch (op) {
...@@ -8382,9 +8372,9 @@ pub const FuncGen = struct {...@@ -8382,9 +8372,9 @@ pub const FuncGen = struct {
8382 ([1]Builder.Type{scalar_llvm_ty} ** 3)[0..params.len],8372 ([1]Builder.Type{scalar_llvm_ty} ** 3)[0..params.len],
8383 scalar_llvm_ty,8373 scalar_llvm_ty,
8384 );8374 );
8385 if (ty.zigTypeTag(mod) == .Vector) {8375 if (ty.zigTypeTag(zcu) == .Vector) {
8386 const result = try o.builder.poisonValue(llvm_ty);8376 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));
8388 }8378 }
83898379
8390 return self.wip.call(8380 return self.wip.call(
...@@ -8413,7 +8403,7 @@ pub const FuncGen = struct {...@@ -8413,7 +8403,7 @@ pub const FuncGen = struct {
8413 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8403 fn airShlWithOverflow(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8414 const o = self.ng.object;8404 const o = self.ng.object;
8415 const pt = o.pt;8405 const pt = o.pt;
8416 const mod = pt.zcu;8406 const zcu = pt.zcu;
8417 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;8407 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
8418 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;8408 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
84198409
...@@ -8421,7 +8411,7 @@ pub const FuncGen = struct {...@@ -8421,7 +8411,7 @@ pub const FuncGen = struct {
8421 const rhs = try self.resolveInst(extra.rhs);8411 const rhs = try self.resolveInst(extra.rhs);
84228412
8423 const lhs_ty = self.typeOf(extra.lhs);8413 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
8426 const dest_ty = self.typeOfIndex(inst);8416 const dest_ty = self.typeOfIndex(inst);
8427 const llvm_dest_ty = try o.lowerType(dest_ty);8417 const llvm_dest_ty = try o.lowerType(dest_ty);
...@@ -8429,7 +8419,7 @@ pub const FuncGen = struct {...@@ -8429,7 +8419,7 @@ pub const FuncGen = struct {
8429 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");8419 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
84308420
8431 const result = try self.wip.bin(.shl, lhs, casted_rhs, "");8421 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))
8433 .ashr8423 .ashr
8434 else8424 else
8435 .lshr, result, casted_rhs, "");8425 .lshr, result, casted_rhs, "");
...@@ -8439,8 +8429,8 @@ pub const FuncGen = struct {...@@ -8439,8 +8429,8 @@ pub const FuncGen = struct {
8439 const result_index = o.llvmFieldIndex(dest_ty, 0).?;8429 const result_index = o.llvmFieldIndex(dest_ty, 0).?;
8440 const overflow_index = o.llvmFieldIndex(dest_ty, 1).?;8430 const overflow_index = o.llvmFieldIndex(dest_ty, 1).?;
84418431
8442 if (isByRef(dest_ty, pt)) {8432 if (isByRef(dest_ty, zcu)) {
8443 const result_alignment = dest_ty.abiAlignment(pt).toLlvm();8433 const result_alignment = dest_ty.abiAlignment(zcu).toLlvm();
8444 const alloca_inst = try self.buildAllocaWorkaround(dest_ty, result_alignment);8434 const alloca_inst = try self.buildAllocaWorkaround(dest_ty, result_alignment);
8445 {8435 {
8446 const field_ptr = try self.wip.gepStruct(llvm_dest_ty, alloca_inst, result_index, "");8436 const field_ptr = try self.wip.gepStruct(llvm_dest_ty, alloca_inst, result_index, "");
...@@ -8483,17 +8473,17 @@ pub const FuncGen = struct {...@@ -8483,17 +8473,17 @@ pub const FuncGen = struct {
84838473
8484 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8474 fn airShlExact(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8485 const o = self.ng.object;8475 const o = self.ng.object;
8486 const mod = o.pt.zcu;8476 const zcu = o.pt.zcu;
8487 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8477 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
84888478
8489 const lhs = try self.resolveInst(bin_op.lhs);8479 const lhs = try self.resolveInst(bin_op.lhs);
8490 const rhs = try self.resolveInst(bin_op.rhs);8480 const rhs = try self.resolveInst(bin_op.rhs);
84918481
8492 const lhs_ty = self.typeOf(bin_op.lhs);8482 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
8495 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");8485 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))
8497 .@"shl nsw"8487 .@"shl nsw"
8498 else8488 else
8499 .@"shl nuw", lhs, casted_rhs, "");8489 .@"shl nuw", lhs, casted_rhs, "");
...@@ -8515,15 +8505,15 @@ pub const FuncGen = struct {...@@ -8515,15 +8505,15 @@ pub const FuncGen = struct {
8515 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8505 fn airShlSat(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8516 const o = self.ng.object;8506 const o = self.ng.object;
8517 const pt = o.pt;8507 const pt = o.pt;
8518 const mod = pt.zcu;8508 const zcu = pt.zcu;
8519 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8509 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85208510
8521 const lhs = try self.resolveInst(bin_op.lhs);8511 const lhs = try self.resolveInst(bin_op.lhs);
8522 const rhs = try self.resolveInst(bin_op.rhs);8512 const rhs = try self.resolveInst(bin_op.rhs);
85238513
8524 const lhs_ty = self.typeOf(bin_op.lhs);8514 const lhs_ty = self.typeOf(bin_op.lhs);
8525 const lhs_scalar_ty = lhs_ty.scalarType(mod);8515 const lhs_scalar_ty = lhs_ty.scalarType(zcu);
8526 const lhs_bits = lhs_scalar_ty.bitSize(pt);8516 const lhs_bits = lhs_scalar_ty.bitSize(zcu);
85278517
8528 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");8518 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");
85298519
...@@ -8532,7 +8522,7 @@ pub const FuncGen = struct {...@@ -8532,7 +8522,7 @@ pub const FuncGen = struct {
8532 const result = try self.wip.callIntrinsic(8522 const result = try self.wip.callIntrinsic(
8533 .normal,8523 .normal,
8534 .none,8524 .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",
8536 &.{llvm_lhs_ty},8526 &.{llvm_lhs_ty},
8537 &.{ lhs, casted_rhs },8527 &.{ lhs, casted_rhs },
8538 "",8528 "",
...@@ -8557,17 +8547,17 @@ pub const FuncGen = struct {...@@ -8557,17 +8547,17 @@ pub const FuncGen = struct {
85578547
8558 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {8548 fn airShr(self: *FuncGen, inst: Air.Inst.Index, is_exact: bool) !Builder.Value {
8559 const o = self.ng.object;8549 const o = self.ng.object;
8560 const mod = o.pt.zcu;8550 const zcu = o.pt.zcu;
8561 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8551 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
85628552
8563 const lhs = try self.resolveInst(bin_op.lhs);8553 const lhs = try self.resolveInst(bin_op.lhs);
8564 const rhs = try self.resolveInst(bin_op.rhs);8554 const rhs = try self.resolveInst(bin_op.rhs);
85658555
8566 const lhs_ty = self.typeOf(bin_op.lhs);8556 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
8569 const casted_rhs = try self.wip.conv(.unsigned, rhs, try o.lowerType(lhs_ty), "");8559 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
8572 return self.wip.bin(if (is_exact)8562 return self.wip.bin(if (is_exact)
8573 if (is_signed_int) .@"ashr exact" else .@"lshr exact"8563 if (is_signed_int) .@"ashr exact" else .@"lshr exact"
...@@ -8576,13 +8566,13 @@ pub const FuncGen = struct {...@@ -8576,13 +8566,13 @@ pub const FuncGen = struct {
85768566
8577 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8567 fn airAbs(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8578 const o = self.ng.object;8568 const o = self.ng.object;
8579 const mod = o.pt.zcu;8569 const zcu = o.pt.zcu;
8580 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;8570 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8581 const operand = try self.resolveInst(ty_op.operand);8571 const operand = try self.resolveInst(ty_op.operand);
8582 const operand_ty = self.typeOf(ty_op.operand);8572 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)) {
8586 .Int => return self.wip.callIntrinsic(8576 .Int => return self.wip.callIntrinsic(
8587 .normal,8577 .normal,
8588 .none,8578 .none,
...@@ -8598,13 +8588,13 @@ pub const FuncGen = struct {...@@ -8598,13 +8588,13 @@ pub const FuncGen = struct {
85988588
8599 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8589 fn airIntCast(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8600 const o = self.ng.object;8590 const o = self.ng.object;
8601 const mod = o.pt.zcu;8591 const zcu = o.pt.zcu;
8602 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;8592 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8603 const dest_ty = self.typeOfIndex(inst);8593 const dest_ty = self.typeOfIndex(inst);
8604 const dest_llvm_ty = try o.lowerType(dest_ty);8594 const dest_llvm_ty = try o.lowerType(dest_ty);
8605 const operand = try self.resolveInst(ty_op.operand);8595 const operand = try self.resolveInst(ty_op.operand);
8606 const operand_ty = self.typeOf(ty_op.operand);8596 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
8609 return self.wip.conv(switch (operand_info.signedness) {8599 return self.wip.conv(switch (operand_info.signedness) {
8610 .signed => .signed,8600 .signed => .signed,
...@@ -8622,12 +8612,12 @@ pub const FuncGen = struct {...@@ -8622,12 +8612,12 @@ pub const FuncGen = struct {
86228612
8623 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8613 fn airFptrunc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8624 const o = self.ng.object;8614 const o = self.ng.object;
8625 const mod = o.pt.zcu;8615 const zcu = o.pt.zcu;
8626 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;8616 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8627 const operand = try self.resolveInst(ty_op.operand);8617 const operand = try self.resolveInst(ty_op.operand);
8628 const operand_ty = self.typeOf(ty_op.operand);8618 const operand_ty = self.typeOf(ty_op.operand);
8629 const dest_ty = self.typeOfIndex(inst);8619 const dest_ty = self.typeOfIndex(inst);
8630 const target = mod.getTarget();8620 const target = zcu.getTarget();
8631 const dest_bits = dest_ty.floatBits(target);8621 const dest_bits = dest_ty.floatBits(target);
8632 const src_bits = operand_ty.floatBits(target);8622 const src_bits = operand_ty.floatBits(target);
86338623
...@@ -8656,12 +8646,12 @@ pub const FuncGen = struct {...@@ -8656,12 +8646,12 @@ pub const FuncGen = struct {
86568646
8657 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8647 fn airFpext(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8658 const o = self.ng.object;8648 const o = self.ng.object;
8659 const mod = o.pt.zcu;8649 const zcu = o.pt.zcu;
8660 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;8650 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
8661 const operand = try self.resolveInst(ty_op.operand);8651 const operand = try self.resolveInst(ty_op.operand);
8662 const operand_ty = self.typeOf(ty_op.operand);8652 const operand_ty = self.typeOf(ty_op.operand);
8663 const dest_ty = self.typeOfIndex(inst);8653 const dest_ty = self.typeOfIndex(inst);
8664 const target = mod.getTarget();8654 const target = zcu.getTarget();
86658655
8666 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {8656 if (intrinsicsAllowed(dest_ty, target) and intrinsicsAllowed(operand_ty, target)) {
8667 return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), "");8657 return self.wip.cast(.fpext, operand, try o.lowerType(dest_ty), "");
...@@ -8669,18 +8659,18 @@ pub const FuncGen = struct {...@@ -8669,18 +8659,18 @@ pub const FuncGen = struct {
8669 const operand_llvm_ty = try o.lowerType(operand_ty);8659 const operand_llvm_ty = try o.lowerType(operand_ty);
8670 const dest_llvm_ty = try o.lowerType(dest_ty);8660 const dest_llvm_ty = try o.lowerType(dest_ty);
86718661
8672 const dest_bits = dest_ty.scalarType(mod).floatBits(target);8662 const dest_bits = dest_ty.scalarType(zcu).floatBits(target);
8673 const src_bits = operand_ty.scalarType(mod).floatBits(target);8663 const src_bits = operand_ty.scalarType(zcu).floatBits(target);
8674 const fn_name = try o.builder.strtabStringFmt("__extend{s}f{s}f2", .{8664 const fn_name = try o.builder.strtabStringFmt("__extend{s}f{s}f2", .{
8675 compilerRtFloatAbbrev(src_bits), compilerRtFloatAbbrev(dest_bits),8665 compilerRtFloatAbbrev(src_bits), compilerRtFloatAbbrev(dest_bits),
8676 });8666 });
86778667
8678 const libc_fn = try self.getLibcFunction(fn_name, &.{operand_llvm_ty}, dest_llvm_ty);8668 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(
8680 libc_fn,8670 libc_fn,
8681 &.{operand},8671 &.{operand},
8682 try o.builder.poisonValue(dest_llvm_ty),8672 try o.builder.poisonValue(dest_llvm_ty),
8683 dest_ty.vectorLen(mod),8673 dest_ty.vectorLen(zcu),
8684 );8674 );
8685 return self.wip.call(8675 return self.wip.call(
8686 .normal,8676 .normal,
...@@ -8715,9 +8705,9 @@ pub const FuncGen = struct {...@@ -8715,9 +8705,9 @@ pub const FuncGen = struct {
8715 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {8705 fn bitCast(self: *FuncGen, operand: Builder.Value, operand_ty: Type, inst_ty: Type) !Builder.Value {
8716 const o = self.ng.object;8706 const o = self.ng.object;
8717 const pt = o.pt;8707 const pt = o.pt;
8718 const mod = pt.zcu;8708 const zcu = pt.zcu;
8719 const operand_is_ref = isByRef(operand_ty, pt);8709 const operand_is_ref = isByRef(operand_ty, zcu);
8720 const result_is_ref = isByRef(inst_ty, pt);8710 const result_is_ref = isByRef(inst_ty, zcu);
8721 const llvm_dest_ty = try o.lowerType(inst_ty);8711 const llvm_dest_ty = try o.lowerType(inst_ty);
87228712
8723 if (operand_is_ref and result_is_ref) {8713 if (operand_is_ref and result_is_ref) {
...@@ -8731,18 +8721,18 @@ pub const FuncGen = struct {...@@ -8731,18 +8721,18 @@ pub const FuncGen = struct {
8731 return self.wip.conv(.unsigned, operand, llvm_dest_ty, "");8721 return self.wip.conv(.unsigned, operand, llvm_dest_ty, "");
8732 }8722 }
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)) {
8735 return self.wip.cast(.inttoptr, operand, llvm_dest_ty, "");8725 return self.wip.cast(.inttoptr, operand, llvm_dest_ty, "");
8736 }8726 }
87378727
8738 if (operand_ty.zigTypeTag(mod) == .Vector and inst_ty.zigTypeTag(mod) == .Array) {8728 if (operand_ty.zigTypeTag(zcu) == .Vector and inst_ty.zigTypeTag(zcu) == .Array) {
8739 const elem_ty = operand_ty.childType(mod);8729 const elem_ty = operand_ty.childType(zcu);
8740 if (!result_is_ref) {8730 if (!result_is_ref) {
8741 return self.ng.todo("implement bitcast vector to non-ref array", .{});8731 return self.ng.todo("implement bitcast vector to non-ref array", .{});
8742 }8732 }
8743 const alignment = inst_ty.abiAlignment(pt).toLlvm();8733 const alignment = inst_ty.abiAlignment(zcu).toLlvm();
8744 const array_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);8734 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;
8746 if (bitcast_ok) {8736 if (bitcast_ok) {
8747 _ = try self.wip.store(.normal, operand, array_ptr, alignment);8737 _ = try self.wip.store(.normal, operand, array_ptr, alignment);
8748 } else {8738 } else {
...@@ -8750,7 +8740,7 @@ pub const FuncGen = struct {...@@ -8750,7 +8740,7 @@ pub const FuncGen = struct {
8750 // a simple bitcast will not work, and we fall back to extractelement.8740 // a simple bitcast will not work, and we fall back to extractelement.
8751 const llvm_usize = try o.lowerType(Type.usize);8741 const llvm_usize = try o.lowerType(Type.usize);
8752 const usize_zero = try o.builder.intValue(llvm_usize, 0);8742 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);
8754 var i: u64 = 0;8744 var i: u64 = 0;
8755 while (i < vector_len) : (i += 1) {8745 while (i < vector_len) : (i += 1) {
8756 const elem_ptr = try self.wip.gep(.inbounds, llvm_dest_ty, array_ptr, &.{8746 const elem_ptr = try self.wip.gep(.inbounds, llvm_dest_ty, array_ptr, &.{
...@@ -8762,16 +8752,16 @@ pub const FuncGen = struct {...@@ -8762,16 +8752,16 @@ pub const FuncGen = struct {
8762 }8752 }
8763 }8753 }
8764 return array_ptr;8754 return array_ptr;
8765 } else if (operand_ty.zigTypeTag(mod) == .Array and inst_ty.zigTypeTag(mod) == .Vector) {8755 } else if (operand_ty.zigTypeTag(zcu) == .Array and inst_ty.zigTypeTag(zcu) == .Vector) {
8766 const elem_ty = operand_ty.childType(mod);8756 const elem_ty = operand_ty.childType(zcu);
8767 const llvm_vector_ty = try o.lowerType(inst_ty);8757 const llvm_vector_ty = try o.lowerType(inst_ty);
8768 if (!operand_is_ref) return self.ng.todo("implement bitcast non-ref array to vector", .{});8758 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;
8771 if (bitcast_ok) {8761 if (bitcast_ok) {
8772 // The array is aligned to the element's alignment, while the vector might have a completely8762 // The array is aligned to the element's alignment, while the vector might have a completely
8773 // different alignment. This means we need to enforce the alignment of this load.8763 // 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();
8775 return self.wip.load(.normal, llvm_vector_ty, operand, alignment, "");8765 return self.wip.load(.normal, llvm_vector_ty, operand, alignment, "");
8776 } else {8766 } else {
8777 // If the ABI size of the element type is not evenly divisible by size in bits;8767 // If the ABI size of the element type is not evenly divisible by size in bits;
...@@ -8780,7 +8770,7 @@ pub const FuncGen = struct {...@@ -8780,7 +8770,7 @@ pub const FuncGen = struct {
8780 const elem_llvm_ty = try o.lowerType(elem_ty);8770 const elem_llvm_ty = try o.lowerType(elem_ty);
8781 const llvm_usize = try o.lowerType(Type.usize);8771 const llvm_usize = try o.lowerType(Type.usize);
8782 const usize_zero = try o.builder.intValue(llvm_usize, 0);8772 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);
8784 var vector = try o.builder.poisonValue(llvm_vector_ty);8774 var vector = try o.builder.poisonValue(llvm_vector_ty);
8785 var i: u64 = 0;8775 var i: u64 = 0;
8786 while (i < vector_len) : (i += 1) {8776 while (i < vector_len) : (i += 1) {
...@@ -8796,25 +8786,25 @@ pub const FuncGen = struct {...@@ -8796,25 +8786,25 @@ pub const FuncGen = struct {
8796 }8786 }
87978787
8798 if (operand_is_ref) {8788 if (operand_is_ref) {
8799 const alignment = operand_ty.abiAlignment(pt).toLlvm();8789 const alignment = operand_ty.abiAlignment(zcu).toLlvm();
8800 return self.wip.load(.normal, llvm_dest_ty, operand, alignment, "");8790 return self.wip.load(.normal, llvm_dest_ty, operand, alignment, "");
8801 }8791 }
88028792
8803 if (result_is_ref) {8793 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();
8805 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);8795 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
8806 _ = try self.wip.store(.normal, operand, result_ptr, alignment);8796 _ = try self.wip.store(.normal, operand, result_ptr, alignment);
8807 return result_ptr;8797 return result_ptr;
8808 }8798 }
88098799
8810 if (llvm_dest_ty.isStruct(&o.builder) or8800 if (llvm_dest_ty.isStruct(&o.builder) or
8811 ((operand_ty.zigTypeTag(mod) == .Vector or inst_ty.zigTypeTag(mod) == .Vector) and8801 ((operand_ty.zigTypeTag(zcu) == .Vector or inst_ty.zigTypeTag(zcu) == .Vector) and
8812 operand_ty.bitSize(pt) != inst_ty.bitSize(pt)))8802 operand_ty.bitSize(zcu) != inst_ty.bitSize(zcu)))
8813 {8803 {
8814 // Both our operand and our result are values, not pointers,8804 // Both our operand and our result are values, not pointers,
8815 // but LLVM won't let us bitcast struct values or vectors with padding bits.8805 // but LLVM won't let us bitcast struct values or vectors with padding bits.
8816 // Therefore, we store operand to alloca, then load for result.8806 // 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();
8818 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);8808 const result_ptr = try self.buildAllocaWorkaround(inst_ty, alignment);
8819 _ = try self.wip.store(.normal, operand, result_ptr, alignment);8809 _ = try self.wip.store(.normal, operand, result_ptr, alignment);
8820 return self.wip.load(.normal, llvm_dest_ty, result_ptr, alignment, "");8810 return self.wip.load(.normal, llvm_dest_ty, result_ptr, alignment, "");
...@@ -8868,7 +8858,7 @@ pub const FuncGen = struct {...@@ -8868,7 +8858,7 @@ pub const FuncGen = struct {
8868 };8858 };
88698859
8870 const mod = self.ng.ownerModule();8860 const mod = self.ng.ownerModule();
8871 if (isByRef(inst_ty, pt)) {8861 if (isByRef(inst_ty, zcu)) {
8872 _ = try self.wip.callIntrinsic(8862 _ = try self.wip.callIntrinsic(
8873 .normal,8863 .normal,
8874 .none,8864 .none,
...@@ -8882,7 +8872,7 @@ pub const FuncGen = struct {...@@ -8882,7 +8872,7 @@ pub const FuncGen = struct {
8882 "",8872 "",
8883 );8873 );
8884 } else if (mod.optimize_mode == .Debug) {8874 } else if (mod.optimize_mode == .Debug) {
8885 const alignment = inst_ty.abiAlignment(pt).toLlvm();8875 const alignment = inst_ty.abiAlignment(zcu).toLlvm();
8886 const alloca = try self.buildAlloca(arg_val.typeOfWip(&self.wip), alignment);8876 const alloca = try self.buildAlloca(arg_val.typeOfWip(&self.wip), alignment);
8887 _ = try self.wip.store(.normal, arg_val, alloca, alignment);8877 _ = try self.wip.store(.normal, arg_val, alloca, alignment);
8888 _ = try self.wip.callIntrinsic(8878 _ = try self.wip.callIntrinsic(
...@@ -8919,28 +8909,28 @@ pub const FuncGen = struct {...@@ -8919,28 +8909,28 @@ pub const FuncGen = struct {
8919 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8909 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8920 const o = self.ng.object;8910 const o = self.ng.object;
8921 const pt = o.pt;8911 const pt = o.pt;
8922 const mod = pt.zcu;8912 const zcu = pt.zcu;
8923 const ptr_ty = self.typeOfIndex(inst);8913 const ptr_ty = self.typeOfIndex(inst);
8924 const pointee_type = ptr_ty.childType(mod);8914 const pointee_type = ptr_ty.childType(zcu);
8925 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(pt))8915 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
8926 return (try o.lowerPtrToVoid(ptr_ty)).toValue();8916 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
89278917
8928 //const pointee_llvm_ty = try o.lowerType(pointee_type);8918 //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();
8930 return self.buildAllocaWorkaround(pointee_type, alignment);8920 return self.buildAllocaWorkaround(pointee_type, alignment);
8931 }8921 }
89328922
8933 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {8923 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
8934 const o = self.ng.object;8924 const o = self.ng.object;
8935 const pt = o.pt;8925 const pt = o.pt;
8936 const mod = pt.zcu;8926 const zcu = pt.zcu;
8937 const ptr_ty = self.typeOfIndex(inst);8927 const ptr_ty = self.typeOfIndex(inst);
8938 const ret_ty = ptr_ty.childType(mod);8928 const ret_ty = ptr_ty.childType(zcu);
8939 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt))8929 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu))
8940 return (try o.lowerPtrToVoid(ptr_ty)).toValue();8930 return (try o.lowerPtrToVoid(ptr_ty)).toValue();
8941 if (self.ret_ptr != .none) return self.ret_ptr;8931 if (self.ret_ptr != .none) return self.ret_ptr;
8942 //const ret_llvm_ty = try o.lowerType(ret_ty);8932 //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();
8944 return self.buildAllocaWorkaround(ret_ty, alignment);8934 return self.buildAllocaWorkaround(ret_ty, alignment);
8945 }8935 }
89468936
...@@ -8962,19 +8952,19 @@ pub const FuncGen = struct {...@@ -8962,19 +8952,19 @@ pub const FuncGen = struct {
8962 alignment: Builder.Alignment,8952 alignment: Builder.Alignment,
8963 ) Allocator.Error!Builder.Value {8953 ) Allocator.Error!Builder.Value {
8964 const o = self.ng.object;8954 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);
8966 }8956 }
89678957
8968 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {8958 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
8969 const o = self.ng.object;8959 const o = self.ng.object;
8970 const pt = o.pt;8960 const pt = o.pt;
8971 const mod = pt.zcu;8961 const zcu = pt.zcu;
8972 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;8962 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
8973 const dest_ptr = try self.resolveInst(bin_op.lhs);8963 const dest_ptr = try self.resolveInst(bin_op.lhs);
8974 const ptr_ty = self.typeOf(bin_op.lhs);8964 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;
8978 if (val_is_undef) {8968 if (val_is_undef) {
8979 const owner_mod = self.ng.ownerModule();8969 const owner_mod = self.ng.ownerModule();
89808970
...@@ -8991,7 +8981,7 @@ pub const FuncGen = struct {...@@ -8991,7 +8981,7 @@ pub const FuncGen = struct {
8991 return .none;8981 return .none;
8992 }8982 }
89938983
8994 const ptr_info = ptr_ty.ptrInfo(mod);8984 const ptr_info = ptr_ty.ptrInfo(zcu);
8995 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);8985 const needs_bitmask = (ptr_info.packed_offset.host_size != 0);
8996 if (needs_bitmask) {8986 if (needs_bitmask) {
8997 // TODO: only some bits are to be undef, we cannot write with a simple memset.8987 // TODO: only some bits are to be undef, we cannot write with a simple memset.
...@@ -9000,13 +8990,13 @@ pub const FuncGen = struct {...@@ -9000,13 +8990,13 @@ pub const FuncGen = struct {
9000 return .none;8990 return .none;
9001 }8991 }
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));
9004 _ = try self.wip.callMemSet(8994 _ = try self.wip.callMemSet(
9005 dest_ptr,8995 dest_ptr,
9006 ptr_ty.ptrAlignment(pt).toLlvm(),8996 ptr_ty.ptrAlignment(zcu).toLlvm(),
9007 if (safety) try o.builder.intValue(.i8, 0xaa) else try o.builder.undefValue(.i8),8997 if (safety) try o.builder.intValue(.i8, 0xaa) else try o.builder.undefValue(.i8),
9008 len,8998 len,
9009 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,8999 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
9010 );9000 );
9011 if (safety and owner_mod.valgrind) {9001 if (safety and owner_mod.valgrind) {
9012 try self.valgrindMarkUndef(dest_ptr, len);9002 try self.valgrindMarkUndef(dest_ptr, len);
...@@ -9027,8 +9017,8 @@ pub const FuncGen = struct {...@@ -9027,8 +9017,8 @@ pub const FuncGen = struct {
9027 /// The first instruction of `body_tail` is the one whose copy we want to elide.9017 /// The first instruction of `body_tail` is the one whose copy we want to elide.
9028 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {9018 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {
9029 const o = fg.ng.object;9019 const o = fg.ng.object;
9030 const mod = o.pt.zcu;9020 const zcu = o.pt.zcu;
9031 const ip = &mod.intern_pool;9021 const ip = &zcu.intern_pool;
9032 for (body_tail[1..]) |body_inst| {9022 for (body_tail[1..]) |body_inst| {
9033 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip)) {9023 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip)) {
9034 .none => continue,9024 .none => continue,
...@@ -9044,15 +9034,15 @@ pub const FuncGen = struct {...@@ -9044,15 +9034,15 @@ pub const FuncGen = struct {
9044 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {9034 fn airLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) !Builder.Value {
9045 const o = fg.ng.object;9035 const o = fg.ng.object;
9046 const pt = o.pt;9036 const pt = o.pt;
9047 const mod = pt.zcu;9037 const zcu = pt.zcu;
9048 const inst = body_tail[0];9038 const inst = body_tail[0];
9049 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9039 const ty_op = fg.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9050 const ptr_ty = fg.typeOf(ty_op.operand);9040 const ptr_ty = fg.typeOf(ty_op.operand);
9051 const ptr_info = ptr_ty.ptrInfo(mod);9041 const ptr_info = ptr_ty.ptrInfo(zcu);
9052 const ptr = try fg.resolveInst(ty_op.operand);9042 const ptr = try fg.resolveInst(ty_op.operand);
90539043
9054 elide: {9044 elide: {
9055 if (!isByRef(Type.fromInterned(ptr_info.child), pt)) break :elide;9045 if (!isByRef(Type.fromInterned(ptr_info.child), zcu)) break :elide;
9056 if (!canElideLoad(fg, body_tail)) break :elide;9046 if (!canElideLoad(fg, body_tail)) break :elide;
9057 return ptr;9047 return ptr;
9058 }9048 }
...@@ -9105,34 +9095,34 @@ pub const FuncGen = struct {...@@ -9105,34 +9095,34 @@ pub const FuncGen = struct {
9105 ) !Builder.Value {9095 ) !Builder.Value {
9106 const o = self.ng.object;9096 const o = self.ng.object;
9107 const pt = o.pt;9097 const pt = o.pt;
9108 const mod = pt.zcu;9098 const zcu = pt.zcu;
9109 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;9099 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
9110 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;9100 const extra = self.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
9111 const ptr = try self.resolveInst(extra.ptr);9101 const ptr = try self.resolveInst(extra.ptr);
9112 const ptr_ty = self.typeOf(extra.ptr);9102 const ptr_ty = self.typeOf(extra.ptr);
9113 var expected_value = try self.resolveInst(extra.expected_value);9103 var expected_value = try self.resolveInst(extra.expected_value);
9114 var new_value = try self.resolveInst(extra.new_value);9104 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);
9116 const llvm_operand_ty = try o.lowerType(operand_ty);9106 const llvm_operand_ty = try o.lowerType(operand_ty);
9117 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);9107 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
9118 if (llvm_abi_ty != .none) {9108 if (llvm_abi_ty != .none) {
9119 // operand needs widening and truncating9109 // operand needs widening and truncating
9120 const signedness: Builder.Function.Instruction.Cast.Signedness =9110 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;
9122 expected_value = try self.wip.conv(signedness, expected_value, llvm_abi_ty, "");9112 expected_value = try self.wip.conv(signedness, expected_value, llvm_abi_ty, "");
9123 new_value = try self.wip.conv(signedness, new_value, llvm_abi_ty, "");9113 new_value = try self.wip.conv(signedness, new_value, llvm_abi_ty, "");
9124 }9114 }
91259115
9126 const result = try self.wip.cmpxchg(9116 const result = try self.wip.cmpxchg(
9127 kind,9117 kind,
9128 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal,9118 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal,
9129 ptr,9119 ptr,
9130 expected_value,9120 expected_value,
9131 new_value,9121 new_value,
9132 self.sync_scope,9122 self.sync_scope,
9133 toLlvmAtomicOrdering(extra.successOrder()),9123 toLlvmAtomicOrdering(extra.successOrder()),
9134 toLlvmAtomicOrdering(extra.failureOrder()),9124 toLlvmAtomicOrdering(extra.failureOrder()),
9135 ptr_ty.ptrAlignment(pt).toLlvm(),9125 ptr_ty.ptrAlignment(zcu).toLlvm(),
9136 "",9126 "",
9137 );9127 );
91389128
...@@ -9142,7 +9132,7 @@ pub const FuncGen = struct {...@@ -9142,7 +9132,7 @@ pub const FuncGen = struct {
9142 if (llvm_abi_ty != .none) payload = try self.wip.cast(.trunc, payload, llvm_operand_ty, "");9132 if (llvm_abi_ty != .none) payload = try self.wip.cast(.trunc, payload, llvm_operand_ty, "");
9143 const success_bit = try self.wip.extractValue(result, &.{1}, "");9133 const success_bit = try self.wip.extractValue(result, &.{1}, "");
91449134
9145 if (optional_ty.optionalReprIsPayload(mod)) {9135 if (optional_ty.optionalReprIsPayload(zcu)) {
9146 const zero = try o.builder.zeroInitValue(payload.typeOfWip(&self.wip));9136 const zero = try o.builder.zeroInitValue(payload.typeOfWip(&self.wip));
9147 return self.wip.select(.normal, success_bit, zero, payload, "");9137 return self.wip.select(.normal, success_bit, zero, payload, "");
9148 }9138 }
...@@ -9156,14 +9146,14 @@ pub const FuncGen = struct {...@@ -9156,14 +9146,14 @@ pub const FuncGen = struct {
9156 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9146 fn airAtomicRmw(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9157 const o = self.ng.object;9147 const o = self.ng.object;
9158 const pt = o.pt;9148 const pt = o.pt;
9159 const mod = pt.zcu;9149 const zcu = pt.zcu;
9160 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;9150 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
9161 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;9151 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
9162 const ptr = try self.resolveInst(pl_op.operand);9152 const ptr = try self.resolveInst(pl_op.operand);
9163 const ptr_ty = self.typeOf(pl_op.operand);9153 const ptr_ty = self.typeOf(pl_op.operand);
9164 const operand_ty = ptr_ty.childType(mod);9154 const operand_ty = ptr_ty.childType(zcu);
9165 const operand = try self.resolveInst(extra.operand);9155 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);
9167 const is_float = operand_ty.isRuntimeFloat();9157 const is_float = operand_ty.isRuntimeFloat();
9168 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);9158 const op = toLlvmAtomicRmwBinOp(extra.op(), is_signed_int, is_float);
9169 const ordering = toLlvmAtomicOrdering(extra.ordering());9159 const ordering = toLlvmAtomicOrdering(extra.ordering());
...@@ -9171,8 +9161,8 @@ pub const FuncGen = struct {...@@ -9171,8 +9161,8 @@ pub const FuncGen = struct {
9171 const llvm_operand_ty = try o.lowerType(operand_ty);9161 const llvm_operand_ty = try o.lowerType(operand_ty);
91729162
9173 const access_kind: Builder.MemoryAccessKind =9163 const access_kind: Builder.MemoryAccessKind =
9174 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;9164 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
9175 const ptr_alignment = ptr_ty.ptrAlignment(pt).toLlvm();9165 const ptr_alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
91769166
9177 if (llvm_abi_ty != .none) {9167 if (llvm_abi_ty != .none) {
9178 // operand needs widening and truncating or bitcasting.9168 // operand needs widening and truncating or bitcasting.
...@@ -9220,19 +9210,19 @@ pub const FuncGen = struct {...@@ -9220,19 +9210,19 @@ pub const FuncGen = struct {
9220 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9210 fn airAtomicLoad(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9221 const o = self.ng.object;9211 const o = self.ng.object;
9222 const pt = o.pt;9212 const pt = o.pt;
9223 const mod = pt.zcu;9213 const zcu = pt.zcu;
9224 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;9214 const atomic_load = self.air.instructions.items(.data)[@intFromEnum(inst)].atomic_load;
9225 const ptr = try self.resolveInst(atomic_load.ptr);9215 const ptr = try self.resolveInst(atomic_load.ptr);
9226 const ptr_ty = self.typeOf(atomic_load.ptr);9216 const ptr_ty = self.typeOf(atomic_load.ptr);
9227 const info = ptr_ty.ptrInfo(mod);9217 const info = ptr_ty.ptrInfo(zcu);
9228 const elem_ty = Type.fromInterned(info.child);9218 const elem_ty = Type.fromInterned(info.child);
9229 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;9219 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
9230 const ordering = toLlvmAtomicOrdering(atomic_load.order);9220 const ordering = toLlvmAtomicOrdering(atomic_load.order);
9231 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);9221 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);
9232 const ptr_alignment = (if (info.flags.alignment != .none)9222 const ptr_alignment = (if (info.flags.alignment != .none)
9233 @as(InternPool.Alignment, info.flags.alignment)9223 @as(InternPool.Alignment, info.flags.alignment)
9234 else9224 else
9235 Type.fromInterned(info.child).abiAlignment(pt)).toLlvm();9225 Type.fromInterned(info.child).abiAlignment(zcu)).toLlvm();
9236 const access_kind: Builder.MemoryAccessKind =9226 const access_kind: Builder.MemoryAccessKind =
9237 if (info.flags.is_volatile) .@"volatile" else .normal;9227 if (info.flags.is_volatile) .@"volatile" else .normal;
9238 const elem_llvm_ty = try o.lowerType(elem_ty);9228 const elem_llvm_ty = try o.lowerType(elem_ty);
...@@ -9268,11 +9258,11 @@ pub const FuncGen = struct {...@@ -9268,11 +9258,11 @@ pub const FuncGen = struct {
9268 ) !Builder.Value {9258 ) !Builder.Value {
9269 const o = self.ng.object;9259 const o = self.ng.object;
9270 const pt = o.pt;9260 const pt = o.pt;
9271 const mod = pt.zcu;9261 const zcu = pt.zcu;
9272 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9262 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9273 const ptr_ty = self.typeOf(bin_op.lhs);9263 const ptr_ty = self.typeOf(bin_op.lhs);
9274 const operand_ty = ptr_ty.childType(mod);9264 const operand_ty = ptr_ty.childType(zcu);
9275 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) return .none;9265 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) return .none;
9276 const ptr = try self.resolveInst(bin_op.lhs);9266 const ptr = try self.resolveInst(bin_op.lhs);
9277 var element = try self.resolveInst(bin_op.rhs);9267 var element = try self.resolveInst(bin_op.rhs);
9278 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);9268 const llvm_abi_ty = try o.getAtomicAbiType(operand_ty, false);
...@@ -9280,7 +9270,7 @@ pub const FuncGen = struct {...@@ -9280,7 +9270,7 @@ pub const FuncGen = struct {
9280 if (llvm_abi_ty != .none) {9270 if (llvm_abi_ty != .none) {
9281 // operand needs widening9271 // operand needs widening
9282 element = try self.wip.conv(9272 element = try self.wip.conv(
9283 if (operand_ty.isSignedInt(mod)) .signed else .unsigned,9273 if (operand_ty.isSignedInt(zcu)) .signed else .unsigned,
9284 element,9274 element,
9285 llvm_abi_ty,9275 llvm_abi_ty,
9286 "",9276 "",
...@@ -9293,26 +9283,26 @@ pub const FuncGen = struct {...@@ -9293,26 +9283,26 @@ pub const FuncGen = struct {
9293 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {9283 fn airMemset(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !Builder.Value {
9294 const o = self.ng.object;9284 const o = self.ng.object;
9295 const pt = o.pt;9285 const pt = o.pt;
9296 const mod = pt.zcu;9286 const zcu = pt.zcu;
9297 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9287 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9298 const dest_slice = try self.resolveInst(bin_op.lhs);9288 const dest_slice = try self.resolveInst(bin_op.lhs);
9299 const ptr_ty = self.typeOf(bin_op.lhs);9289 const ptr_ty = self.typeOf(bin_op.lhs);
9300 const elem_ty = self.typeOf(bin_op.rhs);9290 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();
9302 const dest_ptr = try self.sliceOrArrayPtr(dest_slice, ptr_ty);9292 const dest_ptr = try self.sliceOrArrayPtr(dest_slice, ptr_ty);
9303 const access_kind: Builder.MemoryAccessKind =9293 const access_kind: Builder.MemoryAccessKind =
9304 if (ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;9294 if (ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
93059295
9306 // Any WebAssembly runtime will trap when the destination pointer is out-of-bounds, regardless9296 // Any WebAssembly runtime will trap when the destination pointer is out-of-bounds, regardless
9307 // of the length. This means we need to emit a check where we skip the memset when the length9297 // of the length. This means we need to emit a check where we skip the memset when the length
9308 // is 0 as we allow for undefined pointers in 0-sized slices.9298 // is 0 as we allow for undefined pointers in 0-sized slices.
9309 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.9299 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
9310 const intrinsic_len0_traps = o.target.isWasm() and9300 const intrinsic_len0_traps = o.target.isWasm() and
9311 ptr_ty.isSlice(mod) and9301 ptr_ty.isSlice(zcu) and
9312 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory);9302 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory);
93139303
9314 if (try self.air.value(bin_op.rhs, pt)) |elem_val| {9304 if (try self.air.value(bin_op.rhs, pt)) |elem_val| {
9315 if (elem_val.isUndefDeep(mod)) {9305 if (elem_val.isUndefDeep(zcu)) {
9316 // Even if safety is disabled, we still emit a memset to undefined since it conveys9306 // Even if safety is disabled, we still emit a memset to undefined since it conveys
9317 // extra information to LLVM. However, safety makes the difference between using9307 // extra information to LLVM. However, safety makes the difference between using
9318 // 0xaa or actual undefined for the fill byte.9308 // 0xaa or actual undefined for the fill byte.
...@@ -9350,7 +9340,7 @@ pub const FuncGen = struct {...@@ -9350,7 +9340,7 @@ pub const FuncGen = struct {
9350 }9340 }
93519341
9352 const value = try self.resolveInst(bin_op.rhs);9342 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
9355 if (elem_abi_size == 1) {9345 if (elem_abi_size == 1) {
9356 // In this case we can take advantage of LLVM's intrinsic.9346 // In this case we can take advantage of LLVM's intrinsic.
...@@ -9387,9 +9377,9 @@ pub const FuncGen = struct {...@@ -9387,9 +9377,9 @@ pub const FuncGen = struct {
9387 const end_block = try self.wip.block(1, "InlineMemsetEnd");9377 const end_block = try self.wip.block(1, "InlineMemsetEnd");
93889378
9389 const llvm_usize_ty = try o.lowerType(Type.usize);9379 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)) {
9391 .Slice => try self.wip.extractValue(dest_slice, &.{1}, ""),9381 .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)),
9393 .Many, .C => unreachable,9383 .Many, .C => unreachable,
9394 };9384 };
9395 const elem_llvm_ty = try o.lowerType(elem_ty);9385 const elem_llvm_ty = try o.lowerType(elem_ty);
...@@ -9402,9 +9392,9 @@ pub const FuncGen = struct {...@@ -9402,9 +9392,9 @@ pub const FuncGen = struct {
9402 _ = try self.wip.brCond(end, body_block, end_block);9392 _ = try self.wip.brCond(end, body_block, end_block);
94039393
9404 self.wip.cursor = .{ .block = body_block };9394 self.wip.cursor = .{ .block = body_block };
9405 const elem_abi_align = elem_ty.abiAlignment(pt);9395 const elem_abi_align = elem_ty.abiAlignment(zcu);
9406 const it_ptr_align = InternPool.Alignment.fromLlvm(dest_ptr_align).min(elem_abi_align).toLlvm();9396 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)) {
9408 _ = try self.wip.callMemCpy(9398 _ = try self.wip.callMemCpy(
9409 it_ptr.toValue(),9399 it_ptr.toValue(),
9410 it_ptr_align,9400 it_ptr_align,
...@@ -9447,7 +9437,7 @@ pub const FuncGen = struct {...@@ -9447,7 +9437,7 @@ pub const FuncGen = struct {
9447 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9437 fn airMemcpy(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9448 const o = self.ng.object;9438 const o = self.ng.object;
9449 const pt = o.pt;9439 const pt = o.pt;
9450 const mod = pt.zcu;9440 const zcu = pt.zcu;
9451 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9441 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9452 const dest_slice = try self.resolveInst(bin_op.lhs);9442 const dest_slice = try self.resolveInst(bin_op.lhs);
9453 const dest_ptr_ty = self.typeOf(bin_op.lhs);9443 const dest_ptr_ty = self.typeOf(bin_op.lhs);
...@@ -9456,8 +9446,8 @@ pub const FuncGen = struct {...@@ -9456,8 +9446,8 @@ pub const FuncGen = struct {
9456 const src_ptr = try self.sliceOrArrayPtr(src_slice, src_ptr_ty);9446 const src_ptr = try self.sliceOrArrayPtr(src_slice, src_ptr_ty);
9457 const len = try self.sliceOrArrayLenInBytes(dest_slice, dest_ptr_ty);9447 const len = try self.sliceOrArrayLenInBytes(dest_slice, dest_ptr_ty);
9458 const dest_ptr = try self.sliceOrArrayPtr(dest_slice, dest_ptr_ty);9448 const dest_ptr = try self.sliceOrArrayPtr(dest_slice, dest_ptr_ty);
9459 const access_kind: Builder.MemoryAccessKind = if (src_ptr_ty.isVolatilePtr(mod) or9449 const access_kind: Builder.MemoryAccessKind = if (src_ptr_ty.isVolatilePtr(zcu) or
9460 dest_ptr_ty.isVolatilePtr(mod)) .@"volatile" else .normal;9450 dest_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal;
94619451
9462 // When bulk-memory is enabled, this will be lowered to WebAssembly's memory.copy instruction.9452 // When bulk-memory is enabled, this will be lowered to WebAssembly's memory.copy instruction.
9463 // This instruction will trap on an invalid address, regardless of the length.9453 // This instruction will trap on an invalid address, regardless of the length.
...@@ -9466,7 +9456,7 @@ pub const FuncGen = struct {...@@ -9466,7 +9456,7 @@ pub const FuncGen = struct {
9466 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.9456 // This logic can be removed once https://github.com/ziglang/zig/issues/16360 is done.
9467 if (o.target.isWasm() and9457 if (o.target.isWasm() and
9468 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory) and9458 std.Target.wasm.featureSetHas(o.target.cpu.features, .bulk_memory) and
9469 dest_ptr_ty.isSlice(mod))9459 dest_ptr_ty.isSlice(zcu))
9470 {9460 {
9471 const usize_zero = try o.builder.intValue(try o.lowerType(Type.usize), 0);9461 const usize_zero = try o.builder.intValue(try o.lowerType(Type.usize), 0);
9472 const cond = try self.cmp(.normal, .neq, Type.usize, len, usize_zero);9462 const cond = try self.cmp(.normal, .neq, Type.usize, len, usize_zero);
...@@ -9476,9 +9466,9 @@ pub const FuncGen = struct {...@@ -9476,9 +9466,9 @@ pub const FuncGen = struct {
9476 self.wip.cursor = .{ .block = memcpy_block };9466 self.wip.cursor = .{ .block = memcpy_block };
9477 _ = try self.wip.callMemCpy(9467 _ = try self.wip.callMemCpy(
9478 dest_ptr,9468 dest_ptr,
9479 dest_ptr_ty.ptrAlignment(pt).toLlvm(),9469 dest_ptr_ty.ptrAlignment(zcu).toLlvm(),
9480 src_ptr,9470 src_ptr,
9481 src_ptr_ty.ptrAlignment(pt).toLlvm(),9471 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
9482 len,9472 len,
9483 access_kind,9473 access_kind,
9484 );9474 );
...@@ -9489,9 +9479,9 @@ pub const FuncGen = struct {...@@ -9489,9 +9479,9 @@ pub const FuncGen = struct {
94899479
9490 _ = try self.wip.callMemCpy(9480 _ = try self.wip.callMemCpy(
9491 dest_ptr,9481 dest_ptr,
9492 dest_ptr_ty.ptrAlignment(pt).toLlvm(),9482 dest_ptr_ty.ptrAlignment(zcu).toLlvm(),
9493 src_ptr,9483 src_ptr,
9494 src_ptr_ty.ptrAlignment(pt).toLlvm(),9484 src_ptr_ty.ptrAlignment(zcu).toLlvm(),
9495 len,9485 len,
9496 access_kind,9486 access_kind,
9497 );9487 );
...@@ -9501,10 +9491,10 @@ pub const FuncGen = struct {...@@ -9501,10 +9491,10 @@ pub const FuncGen = struct {
9501 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9491 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9502 const o = self.ng.object;9492 const o = self.ng.object;
9503 const pt = o.pt;9493 const pt = o.pt;
9504 const mod = pt.zcu;9494 const zcu = pt.zcu;
9505 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;9495 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
9506 const un_ty = self.typeOf(bin_op.lhs).childType(mod);9496 const un_ty = self.typeOf(bin_op.lhs).childType(zcu);
9507 const layout = un_ty.unionGetLayout(pt);9497 const layout = un_ty.unionGetLayout(zcu);
9508 if (layout.tag_size == 0) return .none;9498 if (layout.tag_size == 0) return .none;
9509 const union_ptr = try self.resolveInst(bin_op.lhs);9499 const union_ptr = try self.resolveInst(bin_op.lhs);
9510 const new_tag = try self.resolveInst(bin_op.rhs);9500 const new_tag = try self.resolveInst(bin_op.rhs);
...@@ -9523,12 +9513,13 @@ pub const FuncGen = struct {...@@ -9523,12 +9513,13 @@ pub const FuncGen = struct {
9523 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9513 fn airGetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9524 const o = self.ng.object;9514 const o = self.ng.object;
9525 const pt = o.pt;9515 const pt = o.pt;
9516 const zcu = pt.zcu;
9526 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9517 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9527 const un_ty = self.typeOf(ty_op.operand);9518 const un_ty = self.typeOf(ty_op.operand);
9528 const layout = un_ty.unionGetLayout(pt);9519 const layout = un_ty.unionGetLayout(zcu);
9529 if (layout.tag_size == 0) return .none;9520 if (layout.tag_size == 0) return .none;
9530 const union_handle = try self.resolveInst(ty_op.operand);9521 const union_handle = try self.resolveInst(ty_op.operand);
9531 if (isByRef(un_ty, pt)) {9522 if (isByRef(un_ty, zcu)) {
9532 const llvm_un_ty = try o.lowerType(un_ty);9523 const llvm_un_ty = try o.lowerType(un_ty);
9533 if (layout.payload_size == 0)9524 if (layout.payload_size == 0)
9534 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");9525 return self.wip.load(.normal, llvm_un_ty, union_handle, .default, "");
...@@ -9597,10 +9588,10 @@ pub const FuncGen = struct {...@@ -9597,10 +9588,10 @@ pub const FuncGen = struct {
95979588
9598 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9589 fn airByteSwap(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9599 const o = self.ng.object;9590 const o = self.ng.object;
9600 const mod = o.pt.zcu;9591 const zcu = o.pt.zcu;
9601 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9592 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9602 const operand_ty = self.typeOf(ty_op.operand);9593 const operand_ty = self.typeOf(ty_op.operand);
9603 var bits = operand_ty.intInfo(mod).bits;9594 var bits = operand_ty.intInfo(zcu).bits;
9604 assert(bits % 8 == 0);9595 assert(bits % 8 == 0);
96059596
9606 const inst_ty = self.typeOfIndex(inst);9597 const inst_ty = self.typeOfIndex(inst);
...@@ -9611,8 +9602,8 @@ pub const FuncGen = struct {...@@ -9611,8 +9602,8 @@ pub const FuncGen = struct {
9611 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte9602 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
9612 // The truncated result at the end will be the correct bswap9603 // The truncated result at the end will be the correct bswap
9613 const scalar_ty = try o.builder.intType(@intCast(bits + 8));9604 const scalar_ty = try o.builder.intType(@intCast(bits + 8));
9614 if (operand_ty.zigTypeTag(mod) == .Vector) {9605 if (operand_ty.zigTypeTag(zcu) == .Vector) {
9615 const vec_len = operand_ty.vectorLen(mod);9606 const vec_len = operand_ty.vectorLen(zcu);
9616 llvm_operand_ty = try o.builder.vectorType(.normal, vec_len, scalar_ty);9607 llvm_operand_ty = try o.builder.vectorType(.normal, vec_len, scalar_ty);
9617 } else llvm_operand_ty = scalar_ty;9608 } else llvm_operand_ty = scalar_ty;
96189609
...@@ -9631,13 +9622,13 @@ pub const FuncGen = struct {...@@ -9631,13 +9622,13 @@ pub const FuncGen = struct {
96319622
9632 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9623 fn airErrorSetHasValue(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9633 const o = self.ng.object;9624 const o = self.ng.object;
9634 const mod = o.pt.zcu;9625 const zcu = o.pt.zcu;
9635 const ip = &mod.intern_pool;9626 const ip = &zcu.intern_pool;
9636 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;9627 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
9637 const operand = try self.resolveInst(ty_op.operand);9628 const operand = try self.resolveInst(ty_op.operand);
9638 const error_set_ty = ty_op.ty.toType();9629 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);
9641 const valid_block = try self.wip.block(@intCast(names.len), "Valid");9632 const valid_block = try self.wip.block(@intCast(names.len), "Valid");
9642 const invalid_block = try self.wip.block(1, "Invalid");9633 const invalid_block = try self.wip.block(1, "Invalid");
9643 const end_block = try self.wip.block(2, "End");9634 const end_block = try self.wip.block(2, "End");
...@@ -9790,14 +9781,14 @@ pub const FuncGen = struct {...@@ -9790,14 +9781,14 @@ pub const FuncGen = struct {
9790 fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {9781 fn airShuffle(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
9791 const o = self.ng.object;9782 const o = self.ng.object;
9792 const pt = o.pt;9783 const pt = o.pt;
9793 const mod = pt.zcu;9784 const zcu = pt.zcu;
9794 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;9785 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
9795 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;9786 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
9796 const a = try self.resolveInst(extra.a);9787 const a = try self.resolveInst(extra.a);
9797 const b = try self.resolveInst(extra.b);9788 const b = try self.resolveInst(extra.b);
9798 const mask = Value.fromInterned(extra.mask);9789 const mask = Value.fromInterned(extra.mask);
9799 const mask_len = extra.mask_len;9790 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
9802 // LLVM uses integers larger than the length of the first array to9793 // LLVM uses integers larger than the length of the first array to
9803 // index into the second array. This was deemed unnecessarily fragile9794 // index into the second array. This was deemed unnecessarily fragile
...@@ -9809,10 +9800,10 @@ pub const FuncGen = struct {...@@ -9809,10 +9800,10 @@ pub const FuncGen = struct {
98099800
9810 for (values, 0..) |*val, i| {9801 for (values, 0..) |*val, i| {
9811 const elem = try mask.elemValue(pt, i);9802 const elem = try mask.elemValue(pt, i);
9812 if (elem.isUndef(mod)) {9803 if (elem.isUndef(zcu)) {
9813 val.* = try o.builder.undefConst(.i32);9804 val.* = try o.builder.undefConst(.i32);
9814 } else {9805 } else {
9815 const int = elem.toSignedInt(pt);9806 const int = elem.toSignedInt(zcu);
9816 const unsigned: u32 = @intCast(if (int >= 0) int else ~int + a_len);9807 const unsigned: u32 = @intCast(if (int >= 0) int else ~int + a_len);
9817 val.* = try o.builder.intConst(.i32, unsigned);9808 val.* = try o.builder.intConst(.i32, unsigned);
9818 }9809 }
...@@ -9899,8 +9890,8 @@ pub const FuncGen = struct {...@@ -9899,8 +9890,8 @@ pub const FuncGen = struct {
98999890
9900 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {9891 fn airReduce(self: *FuncGen, inst: Air.Inst.Index, fast: Builder.FastMathKind) !Builder.Value {
9901 const o = self.ng.object;9892 const o = self.ng.object;
9902 const mod = o.pt.zcu;9893 const zcu = o.pt.zcu;
9903 const target = mod.getTarget();9894 const target = zcu.getTarget();
99049895
9905 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;9896 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
9906 const operand = try self.resolveInst(reduce.operand);9897 const operand = try self.resolveInst(reduce.operand);
...@@ -9916,13 +9907,13 @@ pub const FuncGen = struct {...@@ -9916,13 +9907,13 @@ pub const FuncGen = struct {
9916 .Xor => .@"vector.reduce.xor",9907 .Xor => .@"vector.reduce.xor",
9917 else => unreachable,9908 else => unreachable,
9918 }, &.{llvm_operand_ty}, &.{operand}, ""),9909 }, &.{llvm_operand_ty}, &.{operand}, ""),
9919 .Min, .Max => switch (scalar_ty.zigTypeTag(mod)) {9910 .Min, .Max => switch (scalar_ty.zigTypeTag(zcu)) {
9920 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {9911 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
9921 .Min => if (scalar_ty.isSignedInt(mod))9912 .Min => if (scalar_ty.isSignedInt(zcu))
9922 .@"vector.reduce.smin"9913 .@"vector.reduce.smin"
9923 else9914 else
9924 .@"vector.reduce.umin",9915 .@"vector.reduce.umin",
9925 .Max => if (scalar_ty.isSignedInt(mod))9916 .Max => if (scalar_ty.isSignedInt(zcu))
9926 .@"vector.reduce.smax"9917 .@"vector.reduce.smax"
9927 else9918 else
9928 .@"vector.reduce.umax",9919 .@"vector.reduce.umax",
...@@ -9936,7 +9927,7 @@ pub const FuncGen = struct {...@@ -9936,7 +9927,7 @@ pub const FuncGen = struct {
9936 }, &.{llvm_operand_ty}, &.{operand}, ""),9927 }, &.{llvm_operand_ty}, &.{operand}, ""),
9937 else => unreachable,9928 else => unreachable,
9938 },9929 },
9939 .Add, .Mul => switch (scalar_ty.zigTypeTag(mod)) {9930 .Add, .Mul => switch (scalar_ty.zigTypeTag(zcu)) {
9940 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {9931 .Int => return self.wip.callIntrinsic(.normal, .none, switch (reduce.operation) {
9941 .Add => .@"vector.reduce.add",9932 .Add => .@"vector.reduce.add",
9942 .Mul => .@"vector.reduce.mul",9933 .Mul => .@"vector.reduce.mul",
...@@ -10004,21 +9995,21 @@ pub const FuncGen = struct {...@@ -10004,21 +9995,21 @@ pub const FuncGen = struct {
10004 ))),9995 ))),
10005 else => unreachable,9996 else => unreachable,
10006 };9997 };
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);
10008 }9999 }
1000910000
10010 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10001 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10011 const o = self.ng.object;10002 const o = self.ng.object;
10012 const pt = o.pt;10003 const pt = o.pt;
10013 const mod = pt.zcu;10004 const zcu = pt.zcu;
10014 const ip = &mod.intern_pool;10005 const ip = &zcu.intern_pool;
10015 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;10006 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
10016 const result_ty = self.typeOfIndex(inst);10007 const result_ty = self.typeOfIndex(inst);
10017 const len: usize = @intCast(result_ty.arrayLen(mod));10008 const len: usize = @intCast(result_ty.arrayLen(zcu));
10018 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);10009 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);
10019 const llvm_result_ty = try o.lowerType(result_ty);10010 const llvm_result_ty = try o.lowerType(result_ty);
1002010011
10021 switch (result_ty.zigTypeTag(mod)) {10012 switch (result_ty.zigTypeTag(zcu)) {
10022 .Vector => {10013 .Vector => {
10023 var vector = try o.builder.poisonValue(llvm_result_ty);10014 var vector = try o.builder.poisonValue(llvm_result_ty);
10024 for (elements, 0..) |elem, i| {10015 for (elements, 0..) |elem, i| {
...@@ -10029,21 +10020,21 @@ pub const FuncGen = struct {...@@ -10029,21 +10020,21 @@ pub const FuncGen = struct {
10029 return vector;10020 return vector;
10030 },10021 },
10031 .Struct => {10022 .Struct => {
10032 if (mod.typeToPackedStruct(result_ty)) |struct_type| {10023 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {
10033 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);10024 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
10034 assert(backing_int_ty != .none);10025 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);
10036 const int_ty = try o.builder.intType(@intCast(big_bits));10027 const int_ty = try o.builder.intType(@intCast(big_bits));
10037 comptime assert(Type.packed_struct_layout_version == 2);10028 comptime assert(Type.packed_struct_layout_version == 2);
10038 var running_int = try o.builder.intValue(int_ty, 0);10029 var running_int = try o.builder.intValue(int_ty, 0);
10039 var running_bits: u16 = 0;10030 var running_bits: u16 = 0;
10040 for (elements, struct_type.field_types.get(ip)) |elem, field_ty| {10031 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
10043 const non_int_val = try self.resolveInst(elem);10034 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));
10045 const small_int_ty = try o.builder.intType(ty_bit_size);10036 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))
10047 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")10038 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
10048 else10039 else
10049 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");10040 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
...@@ -10057,12 +10048,12 @@ pub const FuncGen = struct {...@@ -10057,12 +10048,12 @@ pub const FuncGen = struct {
10057 return running_int;10048 return running_int;
10058 }10049 }
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)) {
10063 // TODO in debug builds init to undef so that the padding will be 0xaa10054 // TODO in debug builds init to undef so that the padding will be 0xaa
10064 // even if we fully populate the fields.10055 // even if we fully populate the fields.
10065 const alignment = result_ty.abiAlignment(pt).toLlvm();10056 const alignment = result_ty.abiAlignment(zcu).toLlvm();
10066 const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment);10057 const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment);
1006710058
10068 for (elements, 0..) |elem, i| {10059 for (elements, 0..) |elem, i| {
...@@ -10075,7 +10066,7 @@ pub const FuncGen = struct {...@@ -10075,7 +10066,7 @@ pub const FuncGen = struct {
10075 const field_ptr_ty = try pt.ptrType(.{10066 const field_ptr_ty = try pt.ptrType(.{
10076 .child = self.typeOf(elem).toIntern(),10067 .child = self.typeOf(elem).toIntern(),
10077 .flags = .{10068 .flags = .{
10078 .alignment = result_ty.structFieldAlign(i, pt),10069 .alignment = result_ty.fieldAlignment(i, zcu),
10079 },10070 },
10080 });10071 });
10081 try self.store(field_ptr, field_ptr_ty, llvm_elem, .none);10072 try self.store(field_ptr, field_ptr_ty, llvm_elem, .none);
...@@ -10095,14 +10086,14 @@ pub const FuncGen = struct {...@@ -10095,14 +10086,14 @@ pub const FuncGen = struct {
10095 }10086 }
10096 },10087 },
10097 .Array => {10088 .Array => {
10098 assert(isByRef(result_ty, pt));10089 assert(isByRef(result_ty, zcu));
1009910090
10100 const llvm_usize = try o.lowerType(Type.usize);10091 const llvm_usize = try o.lowerType(Type.usize);
10101 const usize_zero = try o.builder.intValue(llvm_usize, 0);10092 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();
10103 const alloca_inst = try self.buildAllocaWorkaround(result_ty, alignment);10094 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);
10106 const elem_ptr_ty = try pt.ptrType(.{10097 const elem_ptr_ty = try pt.ptrType(.{
10107 .child = array_info.elem_type.toIntern(),10098 .child = array_info.elem_type.toIntern(),
10108 });10099 });
...@@ -10131,22 +10122,22 @@ pub const FuncGen = struct {...@@ -10131,22 +10122,22 @@ pub const FuncGen = struct {
10131 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {10122 fn airUnionInit(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value {
10132 const o = self.ng.object;10123 const o = self.ng.object;
10133 const pt = o.pt;10124 const pt = o.pt;
10134 const mod = pt.zcu;10125 const zcu = pt.zcu;
10135 const ip = &mod.intern_pool;10126 const ip = &zcu.intern_pool;
10136 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;10127 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
10137 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;10128 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
10138 const union_ty = self.typeOfIndex(inst);10129 const union_ty = self.typeOfIndex(inst);
10139 const union_llvm_ty = try o.lowerType(union_ty);10130 const union_llvm_ty = try o.lowerType(union_ty);
10140 const layout = union_ty.unionGetLayout(pt);10131 const layout = union_ty.unionGetLayout(zcu);
10141 const union_obj = mod.typeToUnion(union_ty).?;10132 const union_obj = zcu.typeToUnion(union_ty).?;
1014210133
10143 if (union_obj.flagsUnordered(ip).layout == .@"packed") {10134 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
10144 const big_bits = union_ty.bitSize(pt);10135 const big_bits = union_ty.bitSize(zcu);
10145 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));10136 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));
10146 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);10137 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
10147 const non_int_val = try self.resolveInst(extra.init);10138 const non_int_val = try self.resolveInst(extra.init);
10148 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(pt)));10139 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(zcu)));
10149 const small_int_val = if (field_ty.isPtrAtRuntime(mod))10140 const small_int_val = if (field_ty.isPtrAtRuntime(zcu))
10150 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")10141 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
10151 else10142 else
10152 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");10143 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
...@@ -10154,9 +10145,9 @@ pub const FuncGen = struct {...@@ -10154,9 +10145,9 @@ pub const FuncGen = struct {
10154 }10145 }
1015510146
10156 const tag_int_val = blk: {10147 const tag_int_val = blk: {
10157 const tag_ty = union_ty.unionTagTypeHypothetical(mod);10148 const tag_ty = union_ty.unionTagTypeHypothetical(zcu);
10158 const union_field_name = union_obj.loadTagType(ip).names.get(ip)[extra.field_index];10149 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).?;
10160 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);10151 const tag_val = try pt.enumValueFieldIndex(tag_ty, enum_field_index);
10161 break :blk try tag_val.intFromEnum(tag_ty, pt);10152 break :blk try tag_val.intFromEnum(tag_ty, pt);
10162 };10153 };
...@@ -10164,12 +10155,12 @@ pub const FuncGen = struct {...@@ -10164,12 +10155,12 @@ pub const FuncGen = struct {
10164 if (layout.tag_size == 0) {10155 if (layout.tag_size == 0) {
10165 return .none;10156 return .none;
10166 }10157 }
10167 assert(!isByRef(union_ty, pt));10158 assert(!isByRef(union_ty, zcu));
10168 var big_int_space: Value.BigIntSpace = undefined;10159 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);
10170 return try o.builder.bigIntValue(union_llvm_ty, tag_big_int);10161 return try o.builder.bigIntValue(union_llvm_ty, tag_big_int);
10171 }10162 }
10172 assert(isByRef(union_ty, pt));10163 assert(isByRef(union_ty, zcu));
10173 // The llvm type of the alloca will be the named LLVM union type, and will not10164 // The llvm type of the alloca will be the named LLVM union type, and will not
10174 // necessarily match the format that we need, depending on which tag is active.10165 // necessarily match the format that we need, depending on which tag is active.
10175 // We must construct the correct unnamed struct type here, in order to then set10166 // We must construct the correct unnamed struct type here, in order to then set
...@@ -10179,14 +10170,14 @@ pub const FuncGen = struct {...@@ -10179,14 +10170,14 @@ pub const FuncGen = struct {
10179 const llvm_payload = try self.resolveInst(extra.init);10170 const llvm_payload = try self.resolveInst(extra.init);
10180 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);10171 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
10181 const field_llvm_ty = try o.lowerType(field_ty);10172 const field_llvm_ty = try o.lowerType(field_ty);
10182 const field_size = field_ty.abiSize(pt);10173 const field_size = field_ty.abiSize(zcu);
10183 const field_align = pt.unionFieldNormalAlignment(union_obj, extra.field_index);10174 const field_align = union_ty.fieldAlignment(extra.field_index, zcu);
10184 const llvm_usize = try o.lowerType(Type.usize);10175 const llvm_usize = try o.lowerType(Type.usize);
10185 const usize_zero = try o.builder.intValue(llvm_usize, 0);10176 const usize_zero = try o.builder.intValue(llvm_usize, 0);
1018610177
10187 const llvm_union_ty = t: {10178 const llvm_union_ty = t: {
10188 const payload_ty = p: {10179 const payload_ty = p: {
10189 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) {10180 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
10190 const padding_len = layout.payload_size;10181 const padding_len = layout.payload_size;
10191 break :p try o.builder.arrayType(padding_len, .i8);10182 break :p try o.builder.arrayType(padding_len, .i8);
10192 }10183 }
...@@ -10242,9 +10233,9 @@ pub const FuncGen = struct {...@@ -10242,9 +10233,9 @@ pub const FuncGen = struct {
10242 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");10233 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");
10243 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));10234 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
10244 var big_int_space: Value.BigIntSpace = undefined;10235 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);
10246 const llvm_tag = try o.builder.bigIntValue(tag_ty, tag_big_int);10237 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();
10248 _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment);10239 _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment);
10249 }10240 }
1025010241
...@@ -10270,8 +10261,8 @@ pub const FuncGen = struct {...@@ -10270,8 +10261,8 @@ pub const FuncGen = struct {
10270 // by the target.10261 // by the target.
10271 // To work around this, don't emit llvm.prefetch in this case.10262 // To work around this, don't emit llvm.prefetch in this case.
10272 // See https://bugs.llvm.org/show_bug.cgi?id=2103710263 // See https://bugs.llvm.org/show_bug.cgi?id=21037
10273 const mod = o.pt.zcu;10264 const zcu = o.pt.zcu;
10274 const target = mod.getTarget();10265 const target = zcu.getTarget();
10275 switch (prefetch.cache) {10266 switch (prefetch.cache) {
10276 .instruction => switch (target.cpu.arch) {10267 .instruction => switch (target.cpu.arch) {
10277 .x86_64,10268 .x86_64,
...@@ -10397,7 +10388,7 @@ pub const FuncGen = struct {...@@ -10397,7 +10388,7 @@ pub const FuncGen = struct {
10397 variable_index.setMutability(.constant, &o.builder);10388 variable_index.setMutability(.constant, &o.builder);
10398 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);10389 variable_index.setUnnamedAddr(.unnamed_addr, &o.builder);
10399 variable_index.setAlignment(10390 variable_index.setAlignment(
10400 Type.slice_const_u8_sentinel_0.abiAlignment(pt).toLlvm(),10391 Type.slice_const_u8_sentinel_0.abiAlignment(pt.zcu).toLlvm(),
10401 &o.builder,10392 &o.builder,
10402 );10393 );
1040310394
...@@ -10436,15 +10427,15 @@ pub const FuncGen = struct {...@@ -10436,15 +10427,15 @@ pub const FuncGen = struct {
10436 ) !Builder.Value {10427 ) !Builder.Value {
10437 const o = fg.ng.object;10428 const o = fg.ng.object;
10438 const pt = o.pt;10429 const pt = o.pt;
10439 const mod = pt.zcu;10430 const zcu = pt.zcu;
10440 const payload_ty = opt_ty.optionalChild(mod);10431 const payload_ty = opt_ty.optionalChild(zcu);
1044110432
10442 if (isByRef(opt_ty, pt)) {10433 if (isByRef(opt_ty, zcu)) {
10443 // We have a pointer and we need to return a pointer to the first field.10434 // We have a pointer and we need to return a pointer to the first field.
10444 const payload_ptr = try fg.wip.gepStruct(opt_llvm_ty, opt_handle, 0, "");10435 const payload_ptr = try fg.wip.gepStruct(opt_llvm_ty, opt_handle, 0, "");
1044510436
10446 const payload_alignment = payload_ty.abiAlignment(pt).toLlvm();10437 const payload_alignment = payload_ty.abiAlignment(zcu).toLlvm();
10447 if (isByRef(payload_ty, pt)) {10438 if (isByRef(payload_ty, zcu)) {
10448 if (can_elide_load)10439 if (can_elide_load)
10449 return payload_ptr;10440 return payload_ptr;
1045010441
...@@ -10453,7 +10444,7 @@ pub const FuncGen = struct {...@@ -10453,7 +10444,7 @@ pub const FuncGen = struct {
10453 return fg.loadTruncate(.normal, payload_ty, payload_ptr, payload_alignment);10444 return fg.loadTruncate(.normal, payload_ty, payload_ptr, payload_alignment);
10454 }10445 }
1045510446
10456 assert(!isByRef(payload_ty, pt));10447 assert(!isByRef(payload_ty, zcu));
10457 return fg.wip.extractValue(opt_handle, &.{0}, "");10448 return fg.wip.extractValue(opt_handle, &.{0}, "");
10458 }10449 }
1045910450
...@@ -10465,11 +10456,12 @@ pub const FuncGen = struct {...@@ -10465,11 +10456,12 @@ pub const FuncGen = struct {
10465 ) !Builder.Value {10456 ) !Builder.Value {
10466 const o = self.ng.object;10457 const o = self.ng.object;
10467 const pt = o.pt;10458 const pt = o.pt;
10459 const zcu = pt.zcu;
10468 const optional_llvm_ty = try o.lowerType(optional_ty);10460 const optional_llvm_ty = try o.lowerType(optional_ty);
10469 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");10461 const non_null_field = try self.wip.cast(.zext, non_null_bit, .i8, "");
1047010462
10471 if (isByRef(optional_ty, pt)) {10463 if (isByRef(optional_ty, zcu)) {
10472 const payload_alignment = optional_ty.abiAlignment(pt).toLlvm();10464 const payload_alignment = optional_ty.abiAlignment(pt.zcu).toLlvm();
10473 const alloca_inst = try self.buildAllocaWorkaround(optional_ty, payload_alignment);10465 const alloca_inst = try self.buildAllocaWorkaround(optional_ty, payload_alignment);
1047410466
10475 {10467 {
...@@ -10497,15 +10489,15 @@ pub const FuncGen = struct {...@@ -10497,15 +10489,15 @@ pub const FuncGen = struct {
10497 ) !Builder.Value {10489 ) !Builder.Value {
10498 const o = self.ng.object;10490 const o = self.ng.object;
10499 const pt = o.pt;10491 const pt = o.pt;
10500 const mod = pt.zcu;10492 const zcu = pt.zcu;
10501 const struct_ty = struct_ptr_ty.childType(mod);10493 const struct_ty = struct_ptr_ty.childType(zcu);
10502 switch (struct_ty.zigTypeTag(mod)) {10494 switch (struct_ty.zigTypeTag(zcu)) {
10503 .Struct => switch (struct_ty.containerLayout(mod)) {10495 .Struct => switch (struct_ty.containerLayout(zcu)) {
10504 .@"packed" => {10496 .@"packed" => {
10505 const result_ty = self.typeOfIndex(inst);10497 const result_ty = self.typeOfIndex(inst);
10506 const result_ty_info = result_ty.ptrInfo(mod);10498 const result_ty_info = result_ty.ptrInfo(zcu);
10507 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(mod);10499 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(zcu);
10508 const struct_type = mod.typeToStruct(struct_ty).?;10500 const struct_type = zcu.typeToStruct(struct_ty).?;
1050910501
10510 if (result_ty_info.packed_offset.host_size != 0) {10502 if (result_ty_info.packed_offset.host_size != 0) {
10511 // From LLVM's perspective, a pointer to a packed struct and a pointer10503 // From LLVM's perspective, a pointer to a packed struct and a pointer
...@@ -10535,15 +10527,15 @@ pub const FuncGen = struct {...@@ -10535,15 +10527,15 @@ pub const FuncGen = struct {
10535 // the struct.10527 // the struct.
10536 const llvm_index = try o.builder.intValue(10528 const llvm_index = try o.builder.intValue(
10537 try o.lowerType(Type.usize),10529 try o.lowerType(Type.usize),
10538 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(pt)),10530 @intFromBool(struct_ty.hasRuntimeBitsIgnoreComptime(zcu)),
10539 );10531 );
10540 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");10532 return self.wip.gep(.inbounds, struct_llvm_ty, struct_ptr, &.{llvm_index}, "");
10541 }10533 }
10542 },10534 },
10543 },10535 },
10544 .Union => {10536 .Union => {
10545 const layout = struct_ty.unionGetLayout(pt);10537 const layout = struct_ty.unionGetLayout(zcu);
10546 if (layout.payload_size == 0 or struct_ty.containerLayout(mod) == .@"packed") return struct_ptr;10538 if (layout.payload_size == 0 or struct_ty.containerLayout(zcu) == .@"packed") return struct_ptr;
10547 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));10539 const payload_index = @intFromBool(layout.tag_align.compare(.gte, layout.payload_align));
10548 const union_llvm_ty = try o.lowerType(struct_ty);10540 const union_llvm_ty = try o.lowerType(struct_ty);
10549 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");10541 return self.wip.gepStruct(union_llvm_ty, struct_ptr, payload_index, "");
...@@ -10566,9 +10558,9 @@ pub const FuncGen = struct {...@@ -10566,9 +10558,9 @@ pub const FuncGen = struct {
1056610558
10567 const o = fg.ng.object;10559 const o = fg.ng.object;
10568 const pt = o.pt;10560 const pt = o.pt;
10569 const mod = pt.zcu;10561 const zcu = pt.zcu;
10570 const payload_llvm_ty = try o.lowerType(payload_ty);10562 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
10573 // llvm bug workarounds:10565 // llvm bug workarounds:
10574 const workaround_explicit_mask = o.target.cpu.arch == .powerpc and abi_size >= 4;10566 const workaround_explicit_mask = o.target.cpu.arch == .powerpc and abi_size >= 4;
...@@ -10580,7 +10572,7 @@ pub const FuncGen = struct {...@@ -10580,7 +10572,7 @@ pub const FuncGen = struct {
10580 return try fg.wip.load(access_kind, payload_llvm_ty, payload_ptr, payload_alignment, "");10572 return try fg.wip.load(access_kind, payload_llvm_ty, payload_ptr, payload_alignment, "");
10581 }10573 }
1058210574
10583 const load_llvm_ty = if (payload_ty.isAbiInt(mod))10575 const load_llvm_ty = if (payload_ty.isAbiInt(zcu))
10584 try o.builder.intType(@intCast(abi_size * 8))10576 try o.builder.intType(@intCast(abi_size * 8))
10585 else10577 else
10586 payload_llvm_ty;10578 payload_llvm_ty;
...@@ -10588,7 +10580,7 @@ pub const FuncGen = struct {...@@ -10588,7 +10580,7 @@ pub const FuncGen = struct {
10588 const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .big)10580 const shifted = if (payload_llvm_ty != load_llvm_ty and o.target.cpu.arch.endian() == .big)
10589 try fg.wip.bin(.lshr, loaded, try o.builder.intValue(10581 try fg.wip.bin(.lshr, loaded, try o.builder.intValue(
10590 load_llvm_ty,10582 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,
10592 ), "")10584 ), "")
10593 else10585 else
10594 loaded;10586 loaded;
...@@ -10614,9 +10606,10 @@ pub const FuncGen = struct {...@@ -10614,9 +10606,10 @@ pub const FuncGen = struct {
10614 const o = fg.ng.object;10606 const o = fg.ng.object;
10615 const pt = o.pt;10607 const pt = o.pt;
10616 //const pointee_llvm_ty = try o.lowerType(pointee_type);10608 //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();
10618 const result_ptr = try fg.buildAllocaWorkaround(pointee_type, result_align);10611 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);
10620 _ = try fg.wip.callMemCpy(10613 _ = try fg.wip.callMemCpy(
10621 result_ptr,10614 result_ptr,
10622 result_align,10615 result_align,
...@@ -10634,15 +10627,15 @@ pub const FuncGen = struct {...@@ -10634,15 +10627,15 @@ pub const FuncGen = struct {
10634 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {10627 fn load(self: *FuncGen, ptr: Builder.Value, ptr_ty: Type) !Builder.Value {
10635 const o = self.ng.object;10628 const o = self.ng.object;
10636 const pt = o.pt;10629 const pt = o.pt;
10637 const mod = pt.zcu;10630 const zcu = pt.zcu;
10638 const info = ptr_ty.ptrInfo(mod);10631 const info = ptr_ty.ptrInfo(zcu);
10639 const elem_ty = Type.fromInterned(info.child);10632 const elem_ty = Type.fromInterned(info.child);
10640 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) return .none;10633 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) return .none;
1064110634
10642 const ptr_alignment = (if (info.flags.alignment != .none)10635 const ptr_alignment = (if (info.flags.alignment != .none)
10643 @as(InternPool.Alignment, info.flags.alignment)10636 @as(InternPool.Alignment, info.flags.alignment)
10644 else10637 else
10645 elem_ty.abiAlignment(pt)).toLlvm();10638 elem_ty.abiAlignment(zcu)).toLlvm();
1064610639
10647 const access_kind: Builder.MemoryAccessKind =10640 const access_kind: Builder.MemoryAccessKind =
10648 if (info.flags.is_volatile) .@"volatile" else .normal;10641 if (info.flags.is_volatile) .@"volatile" else .normal;
...@@ -10658,7 +10651,7 @@ pub const FuncGen = struct {...@@ -10658,7 +10651,7 @@ pub const FuncGen = struct {
10658 }10651 }
1065910652
10660 if (info.packed_offset.host_size == 0) {10653 if (info.packed_offset.host_size == 0) {
10661 if (isByRef(elem_ty, pt)) {10654 if (isByRef(elem_ty, zcu)) {
10662 return self.loadByRef(ptr, elem_ty, ptr_alignment, access_kind);10655 return self.loadByRef(ptr, elem_ty, ptr_alignment, access_kind);
10663 }10656 }
10664 return self.loadTruncate(access_kind, elem_ty, ptr, ptr_alignment);10657 return self.loadTruncate(access_kind, elem_ty, ptr, ptr_alignment);
...@@ -10668,13 +10661,13 @@ pub const FuncGen = struct {...@@ -10668,13 +10661,13 @@ pub const FuncGen = struct {
10668 const containing_int =10661 const containing_int =
10669 try self.wip.load(access_kind, containing_int_ty, ptr, ptr_alignment, "");10662 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);
10672 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);10665 const shift_amt = try o.builder.intValue(containing_int_ty, info.packed_offset.bit_offset);
10673 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");10666 const shifted_value = try self.wip.bin(.lshr, containing_int, shift_amt, "");
10674 const elem_llvm_ty = try o.lowerType(elem_ty);10667 const elem_llvm_ty = try o.lowerType(elem_ty);
1067510668
10676 if (isByRef(elem_ty, pt)) {10669 if (isByRef(elem_ty, zcu)) {
10677 const result_align = elem_ty.abiAlignment(pt).toLlvm();10670 const result_align = elem_ty.abiAlignment(zcu).toLlvm();
10678 const result_ptr = try self.buildAllocaWorkaround(elem_ty, result_align);10671 const result_ptr = try self.buildAllocaWorkaround(elem_ty, result_align);
1067910672
10680 const same_size_int = try o.builder.intType(@intCast(elem_bits));10673 const same_size_int = try o.builder.intType(@intCast(elem_bits));
...@@ -10683,13 +10676,13 @@ pub const FuncGen = struct {...@@ -10683,13 +10676,13 @@ pub const FuncGen = struct {
10683 return result_ptr;10676 return result_ptr;
10684 }10677 }
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) {
10687 const same_size_int = try o.builder.intType(@intCast(elem_bits));10680 const same_size_int = try o.builder.intType(@intCast(elem_bits));
10688 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");10681 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");
10689 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");10682 return self.wip.cast(.bitcast, truncated_int, elem_llvm_ty, "");
10690 }10683 }
1069110684
10692 if (elem_ty.isPtrAtRuntime(mod)) {10685 if (elem_ty.isPtrAtRuntime(zcu)) {
10693 const same_size_int = try o.builder.intType(@intCast(elem_bits));10686 const same_size_int = try o.builder.intType(@intCast(elem_bits));
10694 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");10687 const truncated_int = try self.wip.cast(.trunc, shifted_value, same_size_int, "");
10695 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");10688 return self.wip.cast(.inttoptr, truncated_int, elem_llvm_ty, "");
...@@ -10707,13 +10700,13 @@ pub const FuncGen = struct {...@@ -10707,13 +10700,13 @@ pub const FuncGen = struct {
10707 ) !void {10700 ) !void {
10708 const o = self.ng.object;10701 const o = self.ng.object;
10709 const pt = o.pt;10702 const pt = o.pt;
10710 const mod = pt.zcu;10703 const zcu = pt.zcu;
10711 const info = ptr_ty.ptrInfo(mod);10704 const info = ptr_ty.ptrInfo(zcu);
10712 const elem_ty = Type.fromInterned(info.child);10705 const elem_ty = Type.fromInterned(info.child);
10713 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {10706 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
10714 return;10707 return;
10715 }10708 }
10716 const ptr_alignment = ptr_ty.ptrAlignment(pt).toLlvm();10709 const ptr_alignment = ptr_ty.ptrAlignment(zcu).toLlvm();
10717 const access_kind: Builder.MemoryAccessKind =10710 const access_kind: Builder.MemoryAccessKind =
10718 if (info.flags.is_volatile) .@"volatile" else .normal;10711 if (info.flags.is_volatile) .@"volatile" else .normal;
1071910712
...@@ -10737,12 +10730,12 @@ pub const FuncGen = struct {...@@ -10737,12 +10730,12 @@ pub const FuncGen = struct {
10737 assert(ordering == .none);10730 assert(ordering == .none);
10738 const containing_int =10731 const containing_int =
10739 try self.wip.load(access_kind, containing_int_ty, ptr, ptr_alignment, "");10732 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);
10741 const shift_amt = try o.builder.intConst(containing_int_ty, info.packed_offset.bit_offset);10734 const shift_amt = try o.builder.intConst(containing_int_ty, info.packed_offset.bit_offset);
10742 // Convert to equally-sized integer type in order to perform the bit10735 // Convert to equally-sized integer type in order to perform the bit
10743 // operations on the value to store10736 // operations on the value to store
10744 const value_bits_type = try o.builder.intType(@intCast(elem_bits));10737 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))
10746 try self.wip.cast(.ptrtoint, elem, value_bits_type, "")10739 try self.wip.cast(.ptrtoint, elem, value_bits_type, "")
10747 else10740 else
10748 try self.wip.cast(.bitcast, elem, value_bits_type, "");10741 try self.wip.cast(.bitcast, elem, value_bits_type, "");
...@@ -10772,7 +10765,7 @@ pub const FuncGen = struct {...@@ -10772,7 +10765,7 @@ pub const FuncGen = struct {
10772 _ = try self.wip.store(access_kind, ored_value, ptr, ptr_alignment);10765 _ = try self.wip.store(access_kind, ored_value, ptr, ptr_alignment);
10773 return;10766 return;
10774 }10767 }
10775 if (!isByRef(elem_ty, pt)) {10768 if (!isByRef(elem_ty, zcu)) {
10776 _ = try self.wip.storeAtomic(10769 _ = try self.wip.storeAtomic(
10777 access_kind,10770 access_kind,
10778 elem,10771 elem,
...@@ -10788,8 +10781,8 @@ pub const FuncGen = struct {...@@ -10788,8 +10781,8 @@ pub const FuncGen = struct {
10788 ptr,10781 ptr,
10789 ptr_alignment,10782 ptr_alignment,
10790 elem,10783 elem,
10791 elem_ty.abiAlignment(pt).toLlvm(),10784 elem_ty.abiAlignment(zcu).toLlvm(),
10792 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(pt)),10785 try o.builder.intValue(try o.lowerType(Type.usize), elem_ty.abiSize(zcu)),
10793 access_kind,10786 access_kind,
10794 );10787 );
10795 }10788 }
...@@ -10816,12 +10809,12 @@ pub const FuncGen = struct {...@@ -10816,12 +10809,12 @@ pub const FuncGen = struct {
10816 ) Allocator.Error!Builder.Value {10809 ) Allocator.Error!Builder.Value {
10817 const o = fg.ng.object;10810 const o = fg.ng.object;
10818 const pt = o.pt;10811 const pt = o.pt;
10819 const mod = pt.zcu;10812 const zcu = pt.zcu;
10820 const target = mod.getTarget();10813 const target = zcu.getTarget();
10821 if (!target_util.hasValgrindSupport(target)) return default_value;10814 if (!target_util.hasValgrindSupport(target)) return default_value;
1082210815
10823 const llvm_usize = try o.lowerType(Type.usize);10816 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
10826 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);10819 const array_llvm_ty = try o.builder.arrayType(6, llvm_usize);
10827 const array_ptr = if (fg.valgrind_client_request_array == .none) a: {10820 const array_ptr = if (fg.valgrind_client_request_array == .none) a: {
...@@ -10882,14 +10875,14 @@ pub const FuncGen = struct {...@@ -10882,14 +10875,14 @@ pub const FuncGen = struct {
1088210875
10883 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {10876 fn typeOf(fg: *FuncGen, inst: Air.Inst.Ref) Type {
10884 const o = fg.ng.object;10877 const o = fg.ng.object;
10885 const mod = o.pt.zcu;10878 const zcu = o.pt.zcu;
10886 return fg.air.typeOf(inst, &mod.intern_pool);10879 return fg.air.typeOf(inst, &zcu.intern_pool);
10887 }10880 }
1088810881
10889 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {10882 fn typeOfIndex(fg: *FuncGen, inst: Air.Inst.Index) Type {
10890 const o = fg.ng.object;10883 const o = fg.ng.object;
10891 const mod = o.pt.zcu;10884 const zcu = o.pt.zcu;
10892 return fg.air.typeOfIndex(inst, &mod.intern_pool);10885 return fg.air.typeOfIndex(inst, &zcu.intern_pool);
10893 }10886 }
10894};10887};
1089510888
...@@ -11059,12 +11052,12 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ...@@ -11059,12 +11052,12 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ
11059 };11052 };
11060}11053}
1106111054
11062fn returnTypeByRef(pt: Zcu.PerThread, target: std.Target, ty: Type) bool {11055fn returnTypeByRef(zcu: *Zcu, target: std.Target, ty: Type) bool {
11063 if (isByRef(ty, pt)) {11056 if (isByRef(ty, zcu)) {
11064 return true;11057 return true;
11065 } else if (target.cpu.arch.isX86() and11058 } else if (target.cpu.arch.isX86() and
11066 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and11059 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and
11067 ty.totalVectorBits(pt) >= 512)11060 ty.totalVectorBits(zcu) >= 512)
11068 {11061 {
11069 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns11062 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns
11070 // "512-bit vector arguments require 'evex512' for AVX512"11063 // "512-bit vector arguments require 'evex512' for AVX512"
...@@ -11074,38 +11067,38 @@ fn returnTypeByRef(pt: Zcu.PerThread, target: std.Target, ty: Type) bool {...@@ -11074,38 +11067,38 @@ fn returnTypeByRef(pt: Zcu.PerThread, target: std.Target, ty: Type) bool {
11074 }11067 }
11075}11068}
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 {
11078 const return_type = Type.fromInterned(fn_info.return_type);11071 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
11081 return switch (fn_info.cc) {11074 return switch (fn_info.cc) {
11082 .Unspecified, .Inline => returnTypeByRef(pt, target, return_type),11075 .Unspecified, .Inline => returnTypeByRef(zcu, target, return_type),
11083 .C => switch (target.cpu.arch) {11076 .C => switch (target.cpu.arch) {
11084 .mips, .mipsel => false,11077 .mips, .mipsel => false,
11085 .x86 => isByRef(return_type, pt),11078 .x86 => isByRef(return_type, zcu),
11086 .x86_64 => switch (target.os.tag) {11079 .x86_64 => switch (target.os.tag) {
11087 .windows => x86_64_abi.classifyWindows(return_type, pt) == .memory,11080 .windows => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
11088 else => firstParamSRetSystemV(return_type, pt, target),11081 else => firstParamSRetSystemV(return_type, zcu, target),
11089 },11082 },
11090 .wasm32 => wasm_c_abi.classifyType(return_type, pt)[0] == .indirect,11083 .wasm32 => wasm_c_abi.classifyType(return_type, zcu)[0] == .indirect,
11091 .aarch64, .aarch64_be => aarch64_c_abi.classifyType(return_type, pt) == .memory,11084 .aarch64, .aarch64_be => aarch64_c_abi.classifyType(return_type, zcu) == .memory,
11092 .arm, .armeb => switch (arm_c_abi.classifyType(return_type, pt, .ret)) {11085 .arm, .armeb => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
11093 .memory, .i64_array => true,11086 .memory, .i64_array => true,
11094 .i32_array => |size| size != 1,11087 .i32_array => |size| size != 1,
11095 .byval => false,11088 .byval => false,
11096 },11089 },
11097 .riscv32, .riscv64 => riscv_c_abi.classifyType(return_type, pt) == .memory,11090 .riscv32, .riscv64 => riscv_c_abi.classifyType(return_type, zcu) == .memory,
11098 else => false, // TODO investigate C ABI for other architectures11091 else => false, // TODO investigate C ABI for other architectures
11099 },11092 },
11100 .SysV => firstParamSRetSystemV(return_type, pt, target),11093 .SysV => firstParamSRetSystemV(return_type, zcu, target),
11101 .Win64 => x86_64_abi.classifyWindows(return_type, pt) == .memory,11094 .Win64 => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
11102 .Stdcall => !isScalar(pt.zcu, return_type),11095 .Stdcall => !isScalar(zcu, return_type),
11103 else => false,11096 else => false,
11104 };11097 };
11105}11098}
1110611099
11107fn firstParamSRetSystemV(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {11100fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: std.Target) bool {
11108 const class = x86_64_abi.classifySystemV(ty, pt, target, .ret);11101 const class = x86_64_abi.classifySystemV(ty, zcu, target, .ret);
11109 if (class[0] == .memory) return true;11102 if (class[0] == .memory) return true;
11110 if (class[0] == .x87 and class[2] != .none) return true;11103 if (class[0] == .x87 and class[2] != .none) return true;
11111 return false;11104 return false;
...@@ -11116,62 +11109,62 @@ fn firstParamSRetSystemV(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {...@@ -11116,62 +11109,62 @@ fn firstParamSRetSystemV(ty: Type, pt: Zcu.PerThread, target: std.Target) bool {
11116/// be effectively bitcasted to the actual return type.11109/// be effectively bitcasted to the actual return type.
11117fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {11110fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
11118 const pt = o.pt;11111 const pt = o.pt;
11119 const mod = pt.zcu;11112 const zcu = pt.zcu;
11120 const return_type = Type.fromInterned(fn_info.return_type);11113 const return_type = Type.fromInterned(fn_info.return_type);
11121 if (!return_type.hasRuntimeBitsIgnoreComptime(pt)) {11114 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) {
11122 // If the return type is an error set or an error union, then we make this11115 // If the return type is an error set or an error union, then we make this
11123 // anyerror return type instead, so that it can be coerced into a function11116 // anyerror return type instead, so that it can be coerced into a function
11124 // pointer type which has anyerror as the return type.11117 // 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;
11126 }11119 }
11127 const target = mod.getTarget();11120 const target = zcu.getTarget();
11128 switch (fn_info.cc) {11121 switch (fn_info.cc) {
11129 .Unspecified,11122 .Unspecified,
11130 .Inline,11123 .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
11133 .C => {11126 .C => {
11134 switch (target.cpu.arch) {11127 switch (target.cpu.arch) {
11135 .mips, .mipsel => return o.lowerType(return_type),11128 .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),
11137 .x86_64 => switch (target.os.tag) {11130 .x86_64 => switch (target.os.tag) {
11138 .windows => return lowerWin64FnRetTy(o, fn_info),11131 .windows => return lowerWin64FnRetTy(o, fn_info),
11139 else => return lowerSystemVFnRetTy(o, fn_info),11132 else => return lowerSystemVFnRetTy(o, fn_info),
11140 },11133 },
11141 .wasm32 => {11134 .wasm32 => {
11142 if (isScalar(mod, return_type)) {11135 if (isScalar(zcu, return_type)) {
11143 return o.lowerType(return_type);11136 return o.lowerType(return_type);
11144 }11137 }
11145 const classes = wasm_c_abi.classifyType(return_type, pt);11138 const classes = wasm_c_abi.classifyType(return_type, zcu);
11146 if (classes[0] == .indirect or classes[0] == .none) {11139 if (classes[0] == .indirect or classes[0] == .none) {
11147 return .void;11140 return .void;
11148 }11141 }
1114911142
11150 assert(classes[0] == .direct and classes[1] == .none);11143 assert(classes[0] == .direct and classes[1] == .none);
11151 const scalar_type = wasm_c_abi.scalarType(return_type, pt);11144 const scalar_type = wasm_c_abi.scalarType(return_type, zcu);
11152 return o.builder.intType(@intCast(scalar_type.abiSize(pt) * 8));11145 return o.builder.intType(@intCast(scalar_type.abiSize(zcu) * 8));
11153 },11146 },
11154 .aarch64, .aarch64_be => {11147 .aarch64, .aarch64_be => {
11155 switch (aarch64_c_abi.classifyType(return_type, pt)) {11148 switch (aarch64_c_abi.classifyType(return_type, zcu)) {
11156 .memory => return .void,11149 .memory => return .void,
11157 .float_array => return o.lowerType(return_type),11150 .float_array => return o.lowerType(return_type),
11158 .byval => return o.lowerType(return_type),11151 .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))),
11160 .double_integer => return o.builder.arrayType(2, .i64),11153 .double_integer => return o.builder.arrayType(2, .i64),
11161 }11154 }
11162 },11155 },
11163 .arm, .armeb => {11156 .arm, .armeb => {
11164 switch (arm_c_abi.classifyType(return_type, pt, .ret)) {11157 switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
11165 .memory, .i64_array => return .void,11158 .memory, .i64_array => return .void,
11166 .i32_array => |len| return if (len == 1) .i32 else .void,11159 .i32_array => |len| return if (len == 1) .i32 else .void,
11167 .byval => return o.lowerType(return_type),11160 .byval => return o.lowerType(return_type),
11168 }11161 }
11169 },11162 },
11170 .riscv32, .riscv64 => {11163 .riscv32, .riscv64 => {
11171 switch (riscv_c_abi.classifyType(return_type, pt)) {11164 switch (riscv_c_abi.classifyType(return_type, zcu)) {
11172 .memory => return .void,11165 .memory => return .void,
11173 .integer => {11166 .integer => {
11174 return o.builder.intType(@intCast(return_type.bitSize(pt)));11167 return o.builder.intType(@intCast(return_type.bitSize(zcu)));
11175 },11168 },
11176 .double_integer => {11169 .double_integer => {
11177 return o.builder.structType(.normal, &.{ .i64, .i64 });11170 return o.builder.structType(.normal, &.{ .i64, .i64 });
...@@ -11180,9 +11173,9 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu...@@ -11180,9 +11173,9 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
11180 .fields => {11173 .fields => {
11181 var types_len: usize = 0;11174 var types_len: usize = 0;
11182 var types: [8]Builder.Type = undefined;11175 var types: [8]Builder.Type = undefined;
11183 for (0..return_type.structFieldCount(mod)) |field_index| {11176 for (0..return_type.structFieldCount(zcu)) |field_index| {
11184 const field_ty = return_type.structFieldType(field_index, mod);11177 const field_ty = return_type.fieldType(field_index, zcu);
11185 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;11178 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
11186 types[types_len] = try o.lowerType(field_ty);11179 types[types_len] = try o.lowerType(field_ty);
11187 types_len += 1;11180 types_len += 1;
11188 }11181 }
...@@ -11196,20 +11189,20 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu...@@ -11196,20 +11189,20 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
11196 },11189 },
11197 .Win64 => return lowerWin64FnRetTy(o, fn_info),11190 .Win64 => return lowerWin64FnRetTy(o, fn_info),
11198 .SysV => return lowerSystemVFnRetTy(o, fn_info),11191 .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,
11200 else => return o.lowerType(return_type),11193 else => return o.lowerType(return_type),
11201 }11194 }
11202}11195}
1120311196
11204fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {11197fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
11205 const pt = o.pt;11198 const zcu = o.pt.zcu;
11206 const return_type = Type.fromInterned(fn_info.return_type);11199 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)) {
11208 .integer => {11201 .integer => {
11209 if (isScalar(pt.zcu, return_type)) {11202 if (isScalar(zcu, return_type)) {
11210 return o.lowerType(return_type);11203 return o.lowerType(return_type);
11211 } else {11204 } else {
11212 return o.builder.intType(@intCast(return_type.abiSize(pt) * 8));11205 return o.builder.intType(@intCast(return_type.abiSize(zcu) * 8));
11213 }11206 }
11214 },11207 },
11215 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),11208 .win_i128 => return o.builder.vectorType(.normal, 2, .i64),
...@@ -11221,14 +11214,14 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Err...@@ -11221,14 +11214,14 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Err
1122111214
11222fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {11215fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
11223 const pt = o.pt;11216 const pt = o.pt;
11224 const mod = pt.zcu;11217 const zcu = pt.zcu;
11225 const ip = &mod.intern_pool;11218 const ip = &zcu.intern_pool;
11226 const return_type = Type.fromInterned(fn_info.return_type);11219 const return_type = Type.fromInterned(fn_info.return_type);
11227 if (isScalar(mod, return_type)) {11220 if (isScalar(zcu, return_type)) {
11228 return o.lowerType(return_type);11221 return o.lowerType(return_type);
11229 }11222 }
11230 const target = mod.getTarget();11223 const target = zcu.getTarget();
11231 const classes = x86_64_abi.classifySystemV(return_type, pt, target, .ret);11224 const classes = x86_64_abi.classifySystemV(return_type, zcu, target, .ret);
11232 if (classes[0] == .memory) return .void;11225 if (classes[0] == .memory) return .void;
11233 var types_index: u32 = 0;11226 var types_index: u32 = 0;
11234 var types_buffer: [8]Builder.Type = undefined;11227 var types_buffer: [8]Builder.Type = undefined;
...@@ -11345,7 +11338,7 @@ const ParamTypeIterator = struct {...@@ -11345,7 +11338,7 @@ const ParamTypeIterator = struct {
11345 const zcu = pt.zcu;11338 const zcu = pt.zcu;
11346 const target = zcu.getTarget();11339 const target = zcu.getTarget();
1134711340
11348 if (!ty.hasRuntimeBitsIgnoreComptime(pt)) {11341 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
11349 it.zig_index += 1;11342 it.zig_index += 1;
11350 return .no_bits;11343 return .no_bits;
11351 }11344 }
...@@ -11358,11 +11351,11 @@ const ParamTypeIterator = struct {...@@ -11358,11 +11351,11 @@ const ParamTypeIterator = struct {
11358 {11351 {
11359 it.llvm_index += 1;11352 it.llvm_index += 1;
11360 return .slice;11353 return .slice;
11361 } else if (isByRef(ty, pt)) {11354 } else if (isByRef(ty, zcu)) {
11362 return .byref;11355 return .byref;
11363 } else if (target.cpu.arch.isX86() and11356 } else if (target.cpu.arch.isX86() and
11364 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and11357 !std.Target.x86.featureSetHas(target.cpu.features, .evex512) and
11365 ty.totalVectorBits(pt) >= 512)11358 ty.totalVectorBits(zcu) >= 512)
11366 {11359 {
11367 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns11360 // As of LLVM 18, passing a vector byval with fastcc that is 512 bits or more returns
11368 // "512-bit vector arguments require 'evex512' for AVX512"11361 // "512-bit vector arguments require 'evex512' for AVX512"
...@@ -11390,7 +11383,7 @@ const ParamTypeIterator = struct {...@@ -11390,7 +11383,7 @@ const ParamTypeIterator = struct {
11390 if (isScalar(zcu, ty)) {11383 if (isScalar(zcu, ty)) {
11391 return .byval;11384 return .byval;
11392 }11385 }
11393 const classes = wasm_c_abi.classifyType(ty, pt);11386 const classes = wasm_c_abi.classifyType(ty, zcu);
11394 if (classes[0] == .indirect) {11387 if (classes[0] == .indirect) {
11395 return .byref;11388 return .byref;
11396 }11389 }
...@@ -11399,7 +11392,7 @@ const ParamTypeIterator = struct {...@@ -11399,7 +11392,7 @@ const ParamTypeIterator = struct {
11399 .aarch64, .aarch64_be => {11392 .aarch64, .aarch64_be => {
11400 it.zig_index += 1;11393 it.zig_index += 1;
11401 it.llvm_index += 1;11394 it.llvm_index += 1;
11402 switch (aarch64_c_abi.classifyType(ty, pt)) {11395 switch (aarch64_c_abi.classifyType(ty, zcu)) {
11403 .memory => return .byref_mut,11396 .memory => return .byref_mut,
11404 .float_array => |len| return Lowering{ .float_array = len },11397 .float_array => |len| return Lowering{ .float_array = len },
11405 .byval => return .byval,11398 .byval => return .byval,
...@@ -11414,7 +11407,7 @@ const ParamTypeIterator = struct {...@@ -11414,7 +11407,7 @@ const ParamTypeIterator = struct {
11414 .arm, .armeb => {11407 .arm, .armeb => {
11415 it.zig_index += 1;11408 it.zig_index += 1;
11416 it.llvm_index += 1;11409 it.llvm_index += 1;
11417 switch (arm_c_abi.classifyType(ty, pt, .arg)) {11410 switch (arm_c_abi.classifyType(ty, zcu, .arg)) {
11418 .memory => {11411 .memory => {
11419 it.byval_attr = true;11412 it.byval_attr = true;
11420 return .byref;11413 return .byref;
...@@ -11429,7 +11422,7 @@ const ParamTypeIterator = struct {...@@ -11429,7 +11422,7 @@ const ParamTypeIterator = struct {
11429 it.llvm_index += 1;11422 it.llvm_index += 1;
11430 if (ty.toIntern() == .f16_type and11423 if (ty.toIntern() == .f16_type and
11431 !std.Target.riscv.featureSetHas(target.cpu.features, .d)) return .as_u16;11424 !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)) {
11433 .memory => return .byref_mut,11426 .memory => return .byref_mut,
11434 .byval => return .byval,11427 .byval => return .byval,
11435 .integer => return .abi_sized_int,11428 .integer => return .abi_sized_int,
...@@ -11437,8 +11430,8 @@ const ParamTypeIterator = struct {...@@ -11437,8 +11430,8 @@ const ParamTypeIterator = struct {
11437 .fields => {11430 .fields => {
11438 it.types_len = 0;11431 it.types_len = 0;
11439 for (0..ty.structFieldCount(zcu)) |field_index| {11432 for (0..ty.structFieldCount(zcu)) |field_index| {
11440 const field_ty = ty.structFieldType(field_index, zcu);11433 const field_ty = ty.fieldType(field_index, zcu);
11441 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;11434 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
11442 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);11435 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);
11443 it.types_len += 1;11436 it.types_len += 1;
11444 }11437 }
...@@ -11476,10 +11469,10 @@ const ParamTypeIterator = struct {...@@ -11476,10 +11469,10 @@ const ParamTypeIterator = struct {
11476 }11469 }
1147711470
11478 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {11471 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {
11479 const pt = it.object.pt;11472 const zcu = it.object.pt.zcu;
11480 switch (x86_64_abi.classifyWindows(ty, pt)) {11473 switch (x86_64_abi.classifyWindows(ty, zcu)) {
11481 .integer => {11474 .integer => {
11482 if (isScalar(pt.zcu, ty)) {11475 if (isScalar(zcu, ty)) {
11483 it.zig_index += 1;11476 it.zig_index += 1;
11484 it.llvm_index += 1;11477 it.llvm_index += 1;
11485 return .byval;11478 return .byval;
...@@ -11509,17 +11502,17 @@ const ParamTypeIterator = struct {...@@ -11509,17 +11502,17 @@ const ParamTypeIterator = struct {
11509 }11502 }
1151011503
11511 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {11504 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
11512 const pt = it.object.pt;11505 const zcu = it.object.pt.zcu;
11513 const ip = &pt.zcu.intern_pool;11506 const ip = &zcu.intern_pool;
11514 const target = pt.zcu.getTarget();11507 const target = zcu.getTarget();
11515 const classes = x86_64_abi.classifySystemV(ty, pt, target, .arg);11508 const classes = x86_64_abi.classifySystemV(ty, zcu, target, .arg);
11516 if (classes[0] == .memory) {11509 if (classes[0] == .memory) {
11517 it.zig_index += 1;11510 it.zig_index += 1;
11518 it.llvm_index += 1;11511 it.llvm_index += 1;
11519 it.byval_attr = true;11512 it.byval_attr = true;
11520 return .byref;11513 return .byref;
11521 }11514 }
11522 if (isScalar(pt.zcu, ty)) {11515 if (isScalar(zcu, ty)) {
11523 it.zig_index += 1;11516 it.zig_index += 1;
11524 it.llvm_index += 1;11517 it.llvm_index += 1;
11525 return .byval;11518 return .byval;
...@@ -11620,17 +11613,17 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp...@@ -11620,17 +11613,17 @@ fn iterateParamTypes(object: *Object, fn_info: InternPool.Key.FuncType) ParamTyp
1162011613
11621fn ccAbiPromoteInt(11614fn ccAbiPromoteInt(
11622 cc: std.builtin.CallingConvention,11615 cc: std.builtin.CallingConvention,
11623 mod: *Zcu,11616 zcu: *Zcu,
11624 ty: Type,11617 ty: Type,
11625) ?std.builtin.Signedness {11618) ?std.builtin.Signedness {
11626 const target = mod.getTarget();11619 const target = zcu.getTarget();
11627 switch (cc) {11620 switch (cc) {
11628 .Unspecified, .Inline, .Async => return null,11621 .Unspecified, .Inline, .Async => return null,
11629 else => {},11622 else => {},
11630 }11623 }
11631 const int_info = switch (ty.zigTypeTag(mod)) {11624 const int_info = switch (ty.zigTypeTag(zcu)) {
11632 .Bool => Type.u1.intInfo(mod),11625 .Bool => Type.u1.intInfo(zcu),
11633 .Int, .Enum, .ErrorSet => ty.intInfo(mod),11626 .Int, .Enum, .ErrorSet => ty.intInfo(zcu),
11634 else => return null,11627 else => return null,
11635 };11628 };
11636 return switch (target.os.tag) {11629 return switch (target.os.tag) {
...@@ -11668,13 +11661,13 @@ fn ccAbiPromoteInt(...@@ -11668,13 +11661,13 @@ fn ccAbiPromoteInt(
1166811661
11669/// This is the one source of truth for whether a type is passed around as an LLVM pointer,11662/// This is the one source of truth for whether a type is passed around as an LLVM pointer,
11670/// or as an LLVM value.11663/// or as an LLVM value.
11671fn isByRef(ty: Type, pt: Zcu.PerThread) bool {11664fn isByRef(ty: Type, zcu: *Zcu) bool {
11672 // For tuples and structs, if there are more than this many non-void11665 // For tuples and structs, if there are more than this many non-void
11673 // fields, then we make it byref, otherwise byval.11666 // fields, then we make it byref, otherwise byval.
11674 const max_fields_byval = 0;11667 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)) {
11678 .Type,11671 .Type,
11679 .ComptimeInt,11672 .ComptimeInt,
11680 .ComptimeFloat,11673 .ComptimeFloat,
...@@ -11697,17 +11690,17 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {...@@ -11697,17 +11690,17 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
11697 .AnyFrame,11690 .AnyFrame,
11698 => return false,11691 => return false,
1169911692
11700 .Array, .Frame => return ty.hasRuntimeBits(pt),11693 .Array, .Frame => return ty.hasRuntimeBits(zcu),
11701 .Struct => {11694 .Struct => {
11702 const struct_type = switch (ip.indexToKey(ty.toIntern())) {11695 const struct_type = switch (ip.indexToKey(ty.toIntern())) {
11703 .anon_struct_type => |tuple| {11696 .anon_struct_type => |tuple| {
11704 var count: usize = 0;11697 var count: usize = 0;
11705 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {11698 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
11708 count += 1;11701 count += 1;
11709 if (count > max_fields_byval) return true;11702 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;
11711 }11704 }
11712 return false;11705 return false;
11713 },11706 },
...@@ -11725,27 +11718,27 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {...@@ -11725,27 +11718,27 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
11725 count += 1;11718 count += 1;
11726 if (count > max_fields_byval) return true;11719 if (count > max_fields_byval) return true;
11727 const field_ty = Type.fromInterned(field_types[field_index]);11720 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;
11729 }11722 }
11730 return false;11723 return false;
11731 },11724 },
11732 .Union => switch (ty.containerLayout(pt.zcu)) {11725 .Union => switch (ty.containerLayout(zcu)) {
11733 .@"packed" => return false,11726 .@"packed" => return false,
11734 else => return ty.hasRuntimeBits(pt),11727 else => return ty.hasRuntimeBits(zcu),
11735 },11728 },
11736 .ErrorUnion => {11729 .ErrorUnion => {
11737 const payload_ty = ty.errorUnionPayload(pt.zcu);11730 const payload_ty = ty.errorUnionPayload(zcu);
11738 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {11731 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
11739 return false;11732 return false;
11740 }11733 }
11741 return true;11734 return true;
11742 },11735 },
11743 .Optional => {11736 .Optional => {
11744 const payload_ty = ty.optionalChild(pt.zcu);11737 const payload_ty = ty.optionalChild(zcu);
11745 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {11738 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
11746 return false;11739 return false;
11747 }11740 }
11748 if (ty.optionalReprIsPayload(pt.zcu)) {11741 if (ty.optionalReprIsPayload(zcu)) {
11749 return false;11742 return false;
11750 }11743 }
11751 return true;11744 return true;
...@@ -11753,8 +11746,8 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {...@@ -11753,8 +11746,8 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
11753 }11746 }
11754}11747}
1175511748
11756fn isScalar(mod: *Zcu, ty: Type) bool {11749fn isScalar(zcu: *Zcu, ty: Type) bool {
11757 return switch (ty.zigTypeTag(mod)) {11750 return switch (ty.zigTypeTag(zcu)) {
11758 .Void,11751 .Void,
11759 .Bool,11752 .Bool,
11760 .NoReturn,11753 .NoReturn,
...@@ -11768,8 +11761,8 @@ fn isScalar(mod: *Zcu, ty: Type) bool {...@@ -11768,8 +11761,8 @@ fn isScalar(mod: *Zcu, ty: Type) bool {
11768 .Vector,11761 .Vector,
11769 => true,11762 => true,
1177011763
11771 .Struct => ty.containerLayout(mod) == .@"packed",11764 .Struct => ty.containerLayout(zcu) == .@"packed",
11772 .Union => ty.containerLayout(mod) == .@"packed",11765 .Union => ty.containerLayout(zcu) == .@"packed",
11773 else => false,11766 else => false,
11774 };11767 };
11775}11768}
...@@ -11892,13 +11885,15 @@ fn buildAllocaInner(...@@ -11892,13 +11885,15 @@ fn buildAllocaInner(
11892}11885}
1189311886
11894fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {11887fn errUnionPayloadOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {
11888 const zcu = pt.zcu;
11895 const err_int_ty = try pt.errorIntType();11889 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)));
11897}11891}
1189811892
11899fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {11893fn errUnionErrorOffset(payload_ty: Type, pt: Zcu.PerThread) !u1 {
11894 const zcu = pt.zcu;
11900 const err_int_ty = try pt.errorIntType();11895 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)));
11902}11897}
1190311898
11904/// Returns true for asm constraint (e.g. "=*m", "=r") if it accepts a memory location11899/// 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 {...@@ -436,16 +436,16 @@ const NavGen = struct {
436 /// Fetch the result-id for a previously generated instruction or constant.436 /// Fetch the result-id for a previously generated instruction or constant.
437 fn resolve(self: *NavGen, inst: Air.Inst.Ref) !IdRef {437 fn resolve(self: *NavGen, inst: Air.Inst.Ref) !IdRef {
438 const pt = self.pt;438 const pt = self.pt;
439 const mod = pt.zcu;439 const zcu = pt.zcu;
440 if (try self.air.value(inst, pt)) |val| {440 if (try self.air.value(inst, pt)) |val| {
441 const ty = self.typeOf(inst);441 const ty = self.typeOf(inst);
442 if (ty.zigTypeTag(mod) == .Fn) {442 if (ty.zigTypeTag(zcu) == .Fn) {
443 const fn_nav = switch (mod.intern_pool.indexToKey(val.ip_index)) {443 const fn_nav = switch (zcu.intern_pool.indexToKey(val.ip_index)) {
444 .@"extern" => |@"extern"| @"extern".owner_nav,444 .@"extern" => |@"extern"| @"extern".owner_nav,
445 .func => |func| func.owner_nav,445 .func => |func| func.owner_nav,
446 else => unreachable,446 else => unreachable,
447 };447 };
448 const spv_decl_index = try self.object.resolveNav(mod, fn_nav);448 const spv_decl_index = try self.object.resolveNav(zcu, fn_nav);
449 try self.func.decl_deps.put(self.spv.gpa, spv_decl_index, {});449 try self.func.decl_deps.put(self.spv.gpa, spv_decl_index, {});
450 return self.spv.declPtr(spv_decl_index).result_id;450 return self.spv.declPtr(spv_decl_index).result_id;
451 }451 }
...@@ -459,8 +459,8 @@ const NavGen = struct {...@@ -459,8 +459,8 @@ const NavGen = struct {
459 fn resolveUav(self: *NavGen, val: InternPool.Index) !IdRef {459 fn resolveUav(self: *NavGen, val: InternPool.Index) !IdRef {
460 // TODO: This cannot be a function at this point, but it should probably be handled anyway.460 // TODO: This cannot be a function at this point, but it should probably be handled anyway.
461461
462 const mod = self.pt.zcu;462 const zcu = self.pt.zcu;
463 const ty = Type.fromInterned(mod.intern_pool.typeOf(val));463 const ty = Type.fromInterned(zcu.intern_pool.typeOf(val));
464 const decl_ptr_ty_id = try self.ptrType(ty, .Generic);464 const decl_ptr_ty_id = try self.ptrType(ty, .Generic);
465465
466 const spv_decl_index = blk: {466 const spv_decl_index = blk: {
...@@ -639,15 +639,15 @@ const NavGen = struct {...@@ -639,15 +639,15 @@ const NavGen = struct {
639639
640 /// Checks whether the type can be directly translated to SPIR-V vectors640 /// Checks whether the type can be directly translated to SPIR-V vectors
641 fn isSpvVector(self: *NavGen, ty: Type) bool {641 fn isSpvVector(self: *NavGen, ty: Type) bool {
642 const mod = self.pt.zcu;642 const zcu = self.pt.zcu;
643 const target = self.getTarget();643 const target = self.getTarget();
644 if (ty.zigTypeTag(mod) != .Vector) return false;644 if (ty.zigTypeTag(zcu) != .Vector) return false;
645645
646 // TODO: This check must be expanded for types that can be represented646 // TODO: This check must be expanded for types that can be represented
647 // as integers (enums / packed structs?) and types that are represented647 // as integers (enums / packed structs?) and types that are represented
648 // by multiple SPIR-V values.648 // by multiple SPIR-V values.
649 const scalar_ty = ty.scalarType(mod);649 const scalar_ty = ty.scalarType(zcu);
650 switch (scalar_ty.zigTypeTag(mod)) {650 switch (scalar_ty.zigTypeTag(zcu)) {
651 .Bool,651 .Bool,
652 .Int,652 .Int,
653 .Float,653 .Float,
...@@ -655,24 +655,24 @@ const NavGen = struct {...@@ -655,24 +655,24 @@ const NavGen = struct {
655 else => return false,655 else => return false,
656 }656 }
657657
658 const elem_ty = ty.childType(mod);658 const elem_ty = ty.childType(zcu);
659659
660 const len = ty.vectorLen(mod);660 const len = ty.vectorLen(zcu);
661 const is_scalar = elem_ty.isNumeric(mod) or elem_ty.toIntern() == .bool_type;661 const is_scalar = elem_ty.isNumeric(zcu) or elem_ty.toIntern() == .bool_type;
662 const spirv_len = len > 1 and len <= 4;662 const spirv_len = len > 1 and len <= 4;
663 const opencl_len = if (target.os.tag == .opencl) (len == 8 or len == 16) else false;663 const opencl_len = if (target.os.tag == .opencl) (len == 8 or len == 16) else false;
664 return is_scalar and (spirv_len or opencl_len);664 return is_scalar and (spirv_len or opencl_len);
665 }665 }
666666
667 fn arithmeticTypeInfo(self: *NavGen, ty: Type) ArithmeticTypeInfo {667 fn arithmeticTypeInfo(self: *NavGen, ty: Type) ArithmeticTypeInfo {
668 const mod = self.pt.zcu;668 const zcu = self.pt.zcu;
669 const target = self.getTarget();669 const target = self.getTarget();
670 var scalar_ty = ty.scalarType(mod);670 var scalar_ty = ty.scalarType(zcu);
671 if (scalar_ty.zigTypeTag(mod) == .Enum) {671 if (scalar_ty.zigTypeTag(zcu) == .Enum) {
672 scalar_ty = scalar_ty.intTagType(mod);672 scalar_ty = scalar_ty.intTagType(zcu);
673 }673 }
674 const vector_len = if (ty.isVector(mod)) ty.vectorLen(mod) else null;674 const vector_len = if (ty.isVector(zcu)) ty.vectorLen(zcu) else null;
675 return switch (scalar_ty.zigTypeTag(mod)) {675 return switch (scalar_ty.zigTypeTag(zcu)) {
676 .Bool => ArithmeticTypeInfo{676 .Bool => ArithmeticTypeInfo{
677 .bits = 1, // Doesn't matter for this class.677 .bits = 1, // Doesn't matter for this class.
678 .backing_bits = self.backingIntBits(1).?,678 .backing_bits = self.backingIntBits(1).?,
...@@ -688,7 +688,7 @@ const NavGen = struct {...@@ -688,7 +688,7 @@ const NavGen = struct {
688 .class = .float,688 .class = .float,
689 },689 },
690 .Int => blk: {690 .Int => blk: {
691 const int_info = scalar_ty.intInfo(mod);691 const int_info = scalar_ty.intInfo(zcu);
692 // TODO: Maybe it's useful to also return this value.692 // TODO: Maybe it's useful to also return this value.
693 const maybe_backing_bits = self.backingIntBits(int_info.bits);693 const maybe_backing_bits = self.backingIntBits(int_info.bits);
694 break :blk ArithmeticTypeInfo{694 break :blk ArithmeticTypeInfo{
...@@ -741,9 +741,9 @@ const NavGen = struct {...@@ -741,9 +741,9 @@ const NavGen = struct {
741 /// the value to an unsigned int first for Kernels.741 /// the value to an unsigned int first for Kernels.
742 fn constInt(self: *NavGen, ty: Type, value: anytype, repr: Repr) !IdRef {742 fn constInt(self: *NavGen, ty: Type, value: anytype, repr: Repr) !IdRef {
743 // TODO: Cache?743 // TODO: Cache?
744 const mod = self.pt.zcu;744 const zcu = self.pt.zcu;
745 const scalar_ty = ty.scalarType(mod);745 const scalar_ty = ty.scalarType(zcu);
746 const int_info = scalar_ty.intInfo(mod);746 const int_info = scalar_ty.intInfo(zcu);
747 // Use backing bits so that negatives are sign extended747 // Use backing bits so that negatives are sign extended
748 const backing_bits = self.backingIntBits(int_info.bits).?; // Assertion failure means big int748 const backing_bits = self.backingIntBits(int_info.bits).?; // Assertion failure means big int
749749
...@@ -783,11 +783,11 @@ const NavGen = struct {...@@ -783,11 +783,11 @@ const NavGen = struct {
783 else => unreachable, // TODO: Large integer constants783 else => unreachable, // TODO: Large integer constants
784 }784 }
785785
786 if (!ty.isVector(mod)) {786 if (!ty.isVector(zcu)) {
787 return result_id;787 return result_id;
788 }788 }
789789
790 const n = ty.vectorLen(mod);790 const n = ty.vectorLen(zcu);
791 const ids = try self.gpa.alloc(IdRef, n);791 const ids = try self.gpa.alloc(IdRef, n);
792 defer self.gpa.free(ids);792 defer self.gpa.free(ids);
793 @memset(ids, result_id);793 @memset(ids, result_id);
...@@ -821,8 +821,8 @@ const NavGen = struct {...@@ -821,8 +821,8 @@ const NavGen = struct {
821 /// Construct a vector at runtime.821 /// Construct a vector at runtime.
822 /// ty must be an vector type.822 /// ty must be an vector type.
823 fn constructVector(self: *NavGen, ty: Type, constituents: []const IdRef) !IdRef {823 fn constructVector(self: *NavGen, ty: Type, constituents: []const IdRef) !IdRef {
824 const mod = self.pt.zcu;824 const zcu = self.pt.zcu;
825 assert(ty.vectorLen(mod) == constituents.len);825 assert(ty.vectorLen(zcu) == constituents.len);
826826
827 // Note: older versions of the Khronos SPRIV-LLVM translator crash on this instruction827 // Note: older versions of the Khronos SPRIV-LLVM translator crash on this instruction
828 // because it cannot construct structs which' operands are not constant.828 // because it cannot construct structs which' operands are not constant.
...@@ -845,8 +845,8 @@ const NavGen = struct {...@@ -845,8 +845,8 @@ const NavGen = struct {
845 /// Construct a vector at runtime with all lanes set to the same value.845 /// Construct a vector at runtime with all lanes set to the same value.
846 /// ty must be an vector type.846 /// ty must be an vector type.
847 fn constructVectorSplat(self: *NavGen, ty: Type, constituent: IdRef) !IdRef {847 fn constructVectorSplat(self: *NavGen, ty: Type, constituent: IdRef) !IdRef {
848 const mod = self.pt.zcu;848 const zcu = self.pt.zcu;
849 const n = ty.vectorLen(mod);849 const n = ty.vectorLen(zcu);
850850
851 const constituents = try self.gpa.alloc(IdRef, n);851 const constituents = try self.gpa.alloc(IdRef, n);
852 defer self.gpa.free(constituents);852 defer self.gpa.free(constituents);
...@@ -884,13 +884,13 @@ const NavGen = struct {...@@ -884,13 +884,13 @@ const NavGen = struct {
884 }884 }
885885
886 const pt = self.pt;886 const pt = self.pt;
887 const mod = pt.zcu;887 const zcu = pt.zcu;
888 const target = self.getTarget();888 const target = self.getTarget();
889 const result_ty_id = try self.resolveType(ty, repr);889 const result_ty_id = try self.resolveType(ty, repr);
890 const ip = &mod.intern_pool;890 const ip = &zcu.intern_pool;
891891
892 log.debug("lowering constant: ty = {}, val = {}", .{ ty.fmt(pt), val.fmtValue(pt) });892 log.debug("lowering constant: ty = {}, val = {}", .{ ty.fmt(pt), val.fmtValue(pt) });
893 if (val.isUndefDeep(mod)) {893 if (val.isUndefDeep(zcu)) {
894 return self.spv.constUndef(result_ty_id);894 return self.spv.constUndef(result_ty_id);
895 }895 }
896896
...@@ -937,17 +937,17 @@ const NavGen = struct {...@@ -937,17 +937,17 @@ const NavGen = struct {
937 .false, .true => break :cache try self.constBool(val.toBool(), repr),937 .false, .true => break :cache try self.constBool(val.toBool(), repr),
938 },938 },
939 .int => {939 .int => {
940 if (ty.isSignedInt(mod)) {940 if (ty.isSignedInt(zcu)) {
941 break :cache try self.constInt(ty, val.toSignedInt(pt), repr);941 break :cache try self.constInt(ty, val.toSignedInt(zcu), repr);
942 } else {942 } else {
943 break :cache try self.constInt(ty, val.toUnsignedInt(pt), repr);943 break :cache try self.constInt(ty, val.toUnsignedInt(zcu), repr);
944 }944 }
945 },945 },
946 .float => {946 .float => {
947 const lit: spec.LiteralContextDependentNumber = switch (ty.floatBits(target)) {947 const lit: spec.LiteralContextDependentNumber = switch (ty.floatBits(target)) {
948 16 => .{ .uint32 = @as(u16, @bitCast(val.toFloat(f16, pt))) },948 16 => .{ .uint32 = @as(u16, @bitCast(val.toFloat(f16, zcu))) },
949 32 => .{ .float32 = val.toFloat(f32, pt) },949 32 => .{ .float32 = val.toFloat(f32, zcu) },
950 64 => .{ .float64 = val.toFloat(f64, pt) },950 64 => .{ .float64 = val.toFloat(f64, zcu) },
951 80, 128 => unreachable, // TODO951 80, 128 => unreachable, // TODO
952 else => unreachable,952 else => unreachable,
953 };953 };
...@@ -968,17 +968,17 @@ const NavGen = struct {...@@ -968,17 +968,17 @@ const NavGen = struct {
968 // allows it. For now, just generate it here regardless.968 // allows it. For now, just generate it here regardless.
969 const err_int_ty = try pt.errorIntType();969 const err_int_ty = try pt.errorIntType();
970 const err_ty = switch (error_union.val) {970 const err_ty = switch (error_union.val) {
971 .err_name => ty.errorUnionSet(mod),971 .err_name => ty.errorUnionSet(zcu),
972 .payload => err_int_ty,972 .payload => err_int_ty,
973 };973 };
974 const err_val = switch (error_union.val) {974 const err_val = switch (error_union.val) {
975 .err_name => |err_name| Value.fromInterned(try pt.intern(.{ .err = .{975 .err_name => |err_name| Value.fromInterned(try pt.intern(.{ .err = .{
976 .ty = ty.errorUnionSet(mod).toIntern(),976 .ty = ty.errorUnionSet(zcu).toIntern(),
977 .name = err_name,977 .name = err_name,
978 } })),978 } })),
979 .payload => try pt.intValue(err_int_ty, 0),979 .payload => try pt.intValue(err_int_ty, 0),
980 };980 };
981 const payload_ty = ty.errorUnionPayload(mod);981 const payload_ty = ty.errorUnionPayload(zcu);
982 const eu_layout = self.errorUnionLayout(payload_ty);982 const eu_layout = self.errorUnionLayout(payload_ty);
983 if (!eu_layout.payload_has_bits) {983 if (!eu_layout.payload_has_bits) {
984 // We use the error type directly as the type.984 // We use the error type directly as the type.
...@@ -1006,12 +1006,12 @@ const NavGen = struct {...@@ -1006,12 +1006,12 @@ const NavGen = struct {
1006 },1006 },
1007 .enum_tag => {1007 .enum_tag => {
1008 const int_val = try val.intFromEnum(ty, pt);1008 const int_val = try val.intFromEnum(ty, pt);
1009 const int_ty = ty.intTagType(mod);1009 const int_ty = ty.intTagType(zcu);
1010 break :cache try self.constant(int_ty, int_val, repr);1010 break :cache try self.constant(int_ty, int_val, repr);
1011 },1011 },
1012 .ptr => return self.constantPtr(val),1012 .ptr => return self.constantPtr(val),
1013 .slice => |slice| {1013 .slice => |slice| {
1014 const ptr_ty = ty.slicePtrFieldType(mod);1014 const ptr_ty = ty.slicePtrFieldType(zcu);
1015 const ptr_id = try self.constantPtr(Value.fromInterned(slice.ptr));1015 const ptr_id = try self.constantPtr(Value.fromInterned(slice.ptr));
1016 const len_id = try self.constant(Type.usize, Value.fromInterned(slice.len), .indirect);1016 const len_id = try self.constant(Type.usize, Value.fromInterned(slice.len), .indirect);
1017 return self.constructStruct(1017 return self.constructStruct(
...@@ -1021,12 +1021,12 @@ const NavGen = struct {...@@ -1021,12 +1021,12 @@ const NavGen = struct {
1021 );1021 );
1022 },1022 },
1023 .opt => {1023 .opt => {
1024 const payload_ty = ty.optionalChild(mod);1024 const payload_ty = ty.optionalChild(zcu);
1025 const maybe_payload_val = val.optionalValue(mod);1025 const maybe_payload_val = val.optionalValue(zcu);
10261026
1027 if (!payload_ty.hasRuntimeBits(pt)) {1027 if (!payload_ty.hasRuntimeBits(zcu)) {
1028 break :cache try self.constBool(maybe_payload_val != null, .indirect);1028 break :cache try self.constBool(maybe_payload_val != null, .indirect);
1029 } else if (ty.optionalReprIsPayload(mod)) {1029 } else if (ty.optionalReprIsPayload(zcu)) {
1030 // Optional representation is a nullable pointer or slice.1030 // Optional representation is a nullable pointer or slice.
1031 if (maybe_payload_val) |payload_val| {1031 if (maybe_payload_val) |payload_val| {
1032 return try self.constant(payload_ty, payload_val, .indirect);1032 return try self.constant(payload_ty, payload_val, .indirect);
...@@ -1054,7 +1054,7 @@ const NavGen = struct {...@@ -1054,7 +1054,7 @@ const NavGen = struct {
1054 inline .array_type, .vector_type => |array_type, tag| {1054 inline .array_type, .vector_type => |array_type, tag| {
1055 const elem_ty = Type.fromInterned(array_type.child);1055 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)));
1058 defer self.gpa.free(constituents);1058 defer self.gpa.free(constituents);
10591059
1060 const child_repr: Repr = switch (tag) {1060 const child_repr: Repr = switch (tag) {
...@@ -1088,7 +1088,7 @@ const NavGen = struct {...@@ -1088,7 +1088,7 @@ const NavGen = struct {
1088 }1088 }
1089 },1089 },
1090 .struct_type => {1090 .struct_type => {
1091 const struct_type = mod.typeToStruct(ty).?;1091 const struct_type = zcu.typeToStruct(ty).?;
1092 if (struct_type.layout == .@"packed") {1092 if (struct_type.layout == .@"packed") {
1093 return self.todo("packed struct constants", .{});1093 return self.todo("packed struct constants", .{});
1094 }1094 }
...@@ -1102,7 +1102,7 @@ const NavGen = struct {...@@ -1102,7 +1102,7 @@ const NavGen = struct {
1102 var it = struct_type.iterateRuntimeOrder(ip);1102 var it = struct_type.iterateRuntimeOrder(ip);
1103 while (it.next()) |field_index| {1103 while (it.next()) |field_index| {
1104 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);1104 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)) {
1106 // This is a zero-bit field - we only needed it for the alignment.1106 // This is a zero-bit field - we only needed it for the alignment.
1107 continue;1107 continue;
1108 }1108 }
...@@ -1121,10 +1121,10 @@ const NavGen = struct {...@@ -1121,10 +1121,10 @@ const NavGen = struct {
1121 else => unreachable,1121 else => unreachable,
1122 },1122 },
1123 .un => |un| {1123 .un => |un| {
1124 const active_field = ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?;1124 const active_field = ty.unionTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
1125 const union_obj = mod.typeToUnion(ty).?;1125 const union_obj = zcu.typeToUnion(ty).?;
1126 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[active_field]);1126 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))
1128 try self.constant(field_ty, Value.fromInterned(un.val), .direct)1128 try self.constant(field_ty, Value.fromInterned(un.val), .direct)
1129 else1129 else
1130 null;1130 null;
...@@ -1232,8 +1232,8 @@ const NavGen = struct {...@@ -1232,8 +1232,8 @@ const NavGen = struct {
1232 // TODO: Merge this function with constantDeclRef.1232 // TODO: Merge this function with constantDeclRef.
12331233
1234 const pt = self.pt;1234 const pt = self.pt;
1235 const mod = pt.zcu;1235 const zcu = pt.zcu;
1236 const ip = &mod.intern_pool;1236 const ip = &zcu.intern_pool;
1237 const ty_id = try self.resolveType(ty, .direct);1237 const ty_id = try self.resolveType(ty, .direct);
1238 const uav_ty = Type.fromInterned(ip.typeOf(uav.val));1238 const uav_ty = Type.fromInterned(ip.typeOf(uav.val));
12391239
...@@ -1243,14 +1243,14 @@ const NavGen = struct {...@@ -1243,14 +1243,14 @@ const NavGen = struct {
1243 else => {},1243 else => {},
1244 }1244 }
12451245
1246 // const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;1246 // const is_fn_body = decl_ty.zigTypeTag(zcu) == .Fn;
1247 if (!uav_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {1247 if (!uav_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
1248 // Pointer to nothing - return undefined1248 // Pointer to nothing - return undefined
1249 return self.spv.constUndef(ty_id);1249 return self.spv.constUndef(ty_id);
1250 }1250 }
12511251
1252 // Uav refs are always generic.1252 // Uav refs are always generic.
1253 assert(ty.ptrAddressSpace(mod) == .generic);1253 assert(ty.ptrAddressSpace(zcu) == .generic);
1254 const decl_ptr_ty_id = try self.ptrType(uav_ty, .Generic);1254 const decl_ptr_ty_id = try self.ptrType(uav_ty, .Generic);
1255 const ptr_id = try self.resolveUav(uav.val);1255 const ptr_id = try self.resolveUav(uav.val);
12561256
...@@ -1270,12 +1270,12 @@ const NavGen = struct {...@@ -1270,12 +1270,12 @@ const NavGen = struct {
12701270
1271 fn constantNavRef(self: *NavGen, ty: Type, nav_index: InternPool.Nav.Index) !IdRef {1271 fn constantNavRef(self: *NavGen, ty: Type, nav_index: InternPool.Nav.Index) !IdRef {
1272 const pt = self.pt;1272 const pt = self.pt;
1273 const mod = pt.zcu;1273 const zcu = pt.zcu;
1274 const ip = &mod.intern_pool;1274 const ip = &zcu.intern_pool;
1275 const ty_id = try self.resolveType(ty, .direct);1275 const ty_id = try self.resolveType(ty, .direct);
1276 const nav = ip.getNav(nav_index);1276 const nav = ip.getNav(nav_index);
1277 const nav_val = mod.navValue(nav_index);1277 const nav_val = zcu.navValue(nav_index);
1278 const nav_ty = nav_val.typeOf(mod);1278 const nav_ty = nav_val.typeOf(zcu);
12791279
1280 switch (ip.indexToKey(nav_val.toIntern())) {1280 switch (ip.indexToKey(nav_val.toIntern())) {
1281 .func => {1281 .func => {
...@@ -1287,12 +1287,12 @@ const NavGen = struct {...@@ -1287,12 +1287,12 @@ const NavGen = struct {
1287 else => {},1287 else => {},
1288 }1288 }
12891289
1290 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {1290 if (!nav_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
1291 // Pointer to nothing - return undefined.1291 // Pointer to nothing - return undefined.
1292 return self.spv.constUndef(ty_id);1292 return self.spv.constUndef(ty_id);
1293 }1293 }
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);
1296 const spv_decl = self.spv.declPtr(spv_decl_index);1296 const spv_decl = self.spv.declPtr(spv_decl_index);
12971297
1298 const decl_id = switch (spv_decl.kind) {1298 const decl_id = switch (spv_decl.kind) {
...@@ -1452,9 +1452,9 @@ const NavGen = struct {...@@ -1452,9 +1452,9 @@ const NavGen = struct {
1452 /// }1452 /// }
1453 /// If any of the fields' size is 0, it will be omitted.1453 /// If any of the fields' size is 0, it will be omitted.
1454 fn resolveUnionType(self: *NavGen, ty: Type) !IdRef {1454 fn resolveUnionType(self: *NavGen, ty: Type) !IdRef {
1455 const mod = self.pt.zcu;1455 const zcu = self.pt.zcu;
1456 const ip = &mod.intern_pool;1456 const ip = &zcu.intern_pool;
1457 const union_obj = mod.typeToUnion(ty).?;1457 const union_obj = zcu.typeToUnion(ty).?;
14581458
1459 if (union_obj.flagsUnordered(ip).layout == .@"packed") {1459 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1460 return self.todo("packed union types", .{});1460 return self.todo("packed union types", .{});
...@@ -1503,12 +1503,12 @@ const NavGen = struct {...@@ -1503,12 +1503,12 @@ const NavGen = struct {
1503 }1503 }
15041504
1505 fn resolveFnReturnType(self: *NavGen, ret_ty: Type) !IdRef {1505 fn resolveFnReturnType(self: *NavGen, ret_ty: Type) !IdRef {
1506 const pt = self.pt;1506 const zcu = self.pt.zcu;
1507 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {1507 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1508 // If the return type is an error set or an error union, then we make this1508 // If the return type is an error set or an error union, then we make this
1509 // anyerror return type instead, so that it can be coerced into a function1509 // anyerror return type instead, so that it can be coerced into a function
1510 // pointer type which has anyerror as the return type.1510 // pointer type which has anyerror as the return type.
1511 if (ret_ty.isError(pt.zcu)) {1511 if (ret_ty.isError(zcu)) {
1512 return self.resolveType(Type.anyerror, .direct);1512 return self.resolveType(Type.anyerror, .direct);
1513 } else {1513 } else {
1514 return self.resolveType(Type.void, .direct);1514 return self.resolveType(Type.void, .direct);
...@@ -1531,14 +1531,14 @@ const NavGen = struct {...@@ -1531,14 +1531,14 @@ const NavGen = struct {
15311531
1532 fn resolveTypeInner(self: *NavGen, ty: Type, repr: Repr) Error!IdRef {1532 fn resolveTypeInner(self: *NavGen, ty: Type, repr: Repr) Error!IdRef {
1533 const pt = self.pt;1533 const pt = self.pt;
1534 const mod = pt.zcu;1534 const zcu = pt.zcu;
1535 const ip = &mod.intern_pool;1535 const ip = &zcu.intern_pool;
1536 log.debug("resolveType: ty = {}", .{ty.fmt(pt)});1536 log.debug("resolveType: ty = {}", .{ty.fmt(pt)});
1537 const target = self.getTarget();1537 const target = self.getTarget();
15381538
1539 const section = &self.spv.sections.types_globals_constants;1539 const section = &self.spv.sections.types_globals_constants;
15401540
1541 switch (ty.zigTypeTag(mod)) {1541 switch (ty.zigTypeTag(zcu)) {
1542 .NoReturn => {1542 .NoReturn => {
1543 assert(repr == .direct);1543 assert(repr == .direct);
1544 return try self.spv.voidType();1544 return try self.spv.voidType();
...@@ -1562,7 +1562,7 @@ const NavGen = struct {...@@ -1562,7 +1562,7 @@ const NavGen = struct {
1562 .indirect => return try self.resolveType(Type.u1, .indirect),1562 .indirect => return try self.resolveType(Type.u1, .indirect),
1563 },1563 },
1564 .Int => {1564 .Int => {
1565 const int_info = ty.intInfo(mod);1565 const int_info = ty.intInfo(zcu);
1566 if (int_info.bits == 0) {1566 if (int_info.bits == 0) {
1567 // Some times, the backend will be asked to generate a pointer to i0. OpTypeInt1567 // Some times, the backend will be asked to generate a pointer to i0. OpTypeInt
1568 // with 0 bits is invalid, so return an opaque type in this case.1568 // with 0 bits is invalid, so return an opaque type in this case.
...@@ -1577,7 +1577,7 @@ const NavGen = struct {...@@ -1577,7 +1577,7 @@ const NavGen = struct {
1577 return try self.intType(int_info.signedness, int_info.bits);1577 return try self.intType(int_info.signedness, int_info.bits);
1578 },1578 },
1579 .Enum => {1579 .Enum => {
1580 const tag_ty = ty.intTagType(mod);1580 const tag_ty = ty.intTagType(zcu);
1581 return try self.resolveType(tag_ty, repr);1581 return try self.resolveType(tag_ty, repr);
1582 },1582 },
1583 .Float => {1583 .Float => {
...@@ -1599,13 +1599,13 @@ const NavGen = struct {...@@ -1599,13 +1599,13 @@ const NavGen = struct {
1599 return try self.spv.floatType(bits);1599 return try self.spv.floatType(bits);
1600 },1600 },
1601 .Array => {1601 .Array => {
1602 const elem_ty = ty.childType(mod);1602 const elem_ty = ty.childType(zcu);
1603 const elem_ty_id = try self.resolveType(elem_ty, .indirect);1603 const elem_ty_id = try self.resolveType(elem_ty, .indirect);
1604 const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse {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(mod)});1605 return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(zcu)});
1606 };1606 };
16071607
1608 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) {1608 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1609 // The size of the array would be 0, but that is not allowed in SPIR-V.1609 // The size of the array would be 0, but that is not allowed in SPIR-V.
1610 // This path can be reached when the backend is asked to generate a pointer to1610 // This path can be reached when the backend is asked to generate a pointer to
1611 // an array of some zero-bit type. This should always be an indirect path.1611 // an array of some zero-bit type. This should always be an indirect path.
...@@ -1635,7 +1635,7 @@ const NavGen = struct {...@@ -1635,7 +1635,7 @@ const NavGen = struct {
1635 },1635 },
1636 .Fn => switch (repr) {1636 .Fn => switch (repr) {
1637 .direct => {1637 .direct => {
1638 const fn_info = mod.typeToFunc(ty).?;1638 const fn_info = zcu.typeToFunc(ty).?;
16391639
1640 comptime assert(zig_call_abi_ver == 3);1640 comptime assert(zig_call_abi_ver == 3);
1641 switch (fn_info.cc) {1641 switch (fn_info.cc) {
...@@ -1653,7 +1653,7 @@ const NavGen = struct {...@@ -1653,7 +1653,7 @@ const NavGen = struct {
1653 var param_index: usize = 0;1653 var param_index: usize = 0;
1654 for (fn_info.param_types.get(ip)) |param_ty_index| {1654 for (fn_info.param_types.get(ip)) |param_ty_index| {
1655 const param_ty = Type.fromInterned(param_ty_index);1655 const param_ty = Type.fromInterned(param_ty_index);
1656 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;1656 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
16571657
1658 param_ty_ids[param_index] = try self.resolveType(param_ty, .direct);1658 param_ty_ids[param_index] = try self.resolveType(param_ty, .direct);
1659 param_index += 1;1659 param_index += 1;
...@@ -1677,7 +1677,7 @@ const NavGen = struct {...@@ -1677,7 +1677,7 @@ const NavGen = struct {
1677 },1677 },
1678 },1678 },
1679 .Pointer => {1679 .Pointer => {
1680 const ptr_info = ty.ptrInfo(mod);1680 const ptr_info = ty.ptrInfo(zcu);
16811681
1682 const storage_class = self.spvStorageClass(ptr_info.flags.address_space);1682 const storage_class = self.spvStorageClass(ptr_info.flags.address_space);
1683 const ptr_ty_id = try self.ptrType(Type.fromInterned(ptr_info.child), storage_class);1683 const ptr_ty_id = try self.ptrType(Type.fromInterned(ptr_info.child), storage_class);
...@@ -1693,9 +1693,9 @@ const NavGen = struct {...@@ -1693,9 +1693,9 @@ const NavGen = struct {
1693 );1693 );
1694 },1694 },
1695 .Vector => {1695 .Vector => {
1696 const elem_ty = ty.childType(mod);1696 const elem_ty = ty.childType(zcu);
1697 const elem_ty_id = try self.resolveType(elem_ty, repr);1697 const elem_ty_id = try self.resolveType(elem_ty, repr);
1698 const len = ty.vectorLen(mod);1698 const len = ty.vectorLen(zcu);
16991699
1700 if (self.isSpvVector(ty)) {1700 if (self.isSpvVector(ty)) {
1701 return try self.spv.vectorType(len, elem_ty_id);1701 return try self.spv.vectorType(len, elem_ty_id);
...@@ -1711,7 +1711,7 @@ const NavGen = struct {...@@ -1711,7 +1711,7 @@ const NavGen = struct {
17111711
1712 var member_index: usize = 0;1712 var member_index: usize = 0;
1713 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {1713 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
1716 member_types[member_index] = try self.resolveType(Type.fromInterned(field_ty), .indirect);1716 member_types[member_index] = try self.resolveType(Type.fromInterned(field_ty), .indirect);
1717 member_index += 1;1717 member_index += 1;
...@@ -1740,13 +1740,13 @@ const NavGen = struct {...@@ -1740,13 +1740,13 @@ const NavGen = struct {
1740 var it = struct_type.iterateRuntimeOrder(ip);1740 var it = struct_type.iterateRuntimeOrder(ip);
1741 while (it.next()) |field_index| {1741 while (it.next()) |field_index| {
1742 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);1742 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)) {
1744 // This is a zero-bit field - we only needed it for the alignment.1744 // This is a zero-bit field - we only needed it for the alignment.
1745 continue;1745 continue;
1746 }1746 }
17471747
1748 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse1748 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);
1750 try member_types.append(try self.resolveType(field_ty, .indirect));1750 try member_types.append(try self.resolveType(field_ty, .indirect));
1751 try member_names.append(field_name.toSlice(ip));1751 try member_names.append(field_name.toSlice(ip));
1752 }1752 }
...@@ -1758,8 +1758,8 @@ const NavGen = struct {...@@ -1758,8 +1758,8 @@ const NavGen = struct {
1758 return result_id;1758 return result_id;
1759 },1759 },
1760 .Optional => {1760 .Optional => {
1761 const payload_ty = ty.optionalChild(mod);1761 const payload_ty = ty.optionalChild(zcu);
1762 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {1762 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1763 // Just use a bool.1763 // Just use a bool.
1764 // Note: Always generate the bool with indirect format, to save on some sanity1764 // Note: Always generate the bool with indirect format, to save on some sanity
1765 // Perform the conversion to a direct bool when the field is extracted.1765 // Perform the conversion to a direct bool when the field is extracted.
...@@ -1767,7 +1767,7 @@ const NavGen = struct {...@@ -1767,7 +1767,7 @@ const NavGen = struct {
1767 }1767 }
17681768
1769 const payload_ty_id = try self.resolveType(payload_ty, .indirect);1769 const payload_ty_id = try self.resolveType(payload_ty, .indirect);
1770 if (ty.optionalReprIsPayload(mod)) {1770 if (ty.optionalReprIsPayload(zcu)) {
1771 // Optional is actually a pointer or a slice.1771 // Optional is actually a pointer or a slice.
1772 return payload_ty_id;1772 return payload_ty_id;
1773 }1773 }
...@@ -1782,7 +1782,7 @@ const NavGen = struct {...@@ -1782,7 +1782,7 @@ const NavGen = struct {
1782 .Union => return try self.resolveUnionType(ty),1782 .Union => return try self.resolveUnionType(ty),
1783 .ErrorSet => return try self.resolveType(Type.u16, repr),1783 .ErrorSet => return try self.resolveType(Type.u16, repr),
1784 .ErrorUnion => {1784 .ErrorUnion => {
1785 const payload_ty = ty.errorUnionPayload(mod);1785 const payload_ty = ty.errorUnionPayload(zcu);
1786 const error_ty_id = try self.resolveType(Type.anyerror, .indirect);1786 const error_ty_id = try self.resolveType(Type.anyerror, .indirect);
17871787
1788 const eu_layout = self.errorUnionLayout(payload_ty);1788 const eu_layout = self.errorUnionLayout(payload_ty);
...@@ -1877,13 +1877,14 @@ const NavGen = struct {...@@ -1877,13 +1877,14 @@ const NavGen = struct {
18771877
1878 fn errorUnionLayout(self: *NavGen, payload_ty: Type) ErrorUnionLayout {1878 fn errorUnionLayout(self: *NavGen, payload_ty: Type) ErrorUnionLayout {
1879 const pt = self.pt;1879 const pt = self.pt;
1880 const zcu = pt.zcu;
18801881
1881 const error_align = Type.anyerror.abiAlignment(pt);1882 const error_align = Type.anyerror.abiAlignment(zcu);
1882 const payload_align = payload_ty.abiAlignment(pt);1883 const payload_align = payload_ty.abiAlignment(zcu);
18831884
1884 const error_first = error_align.compare(.gt, payload_align);1885 const error_first = error_align.compare(.gt, payload_align);
1885 return .{1886 return .{
1886 .payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(pt),1887 .payload_has_bits = payload_ty.hasRuntimeBitsIgnoreComptime(zcu),
1887 .error_first = error_first,1888 .error_first = error_first,
1888 };1889 };
1889 }1890 }
...@@ -1908,10 +1909,10 @@ const NavGen = struct {...@@ -1908,10 +1909,10 @@ const NavGen = struct {
19081909
1909 fn unionLayout(self: *NavGen, ty: Type) UnionLayout {1910 fn unionLayout(self: *NavGen, ty: Type) UnionLayout {
1910 const pt = self.pt;1911 const pt = self.pt;
1911 const mod = pt.zcu;1912 const zcu = pt.zcu;
1912 const ip = &mod.intern_pool;1913 const ip = &zcu.intern_pool;
1913 const layout = ty.unionGetLayout(pt);1914 const layout = ty.unionGetLayout(zcu);
1914 const union_obj = mod.typeToUnion(ty).?;1915 const union_obj = zcu.typeToUnion(ty).?;
19151916
1916 var union_layout = UnionLayout{1917 var union_layout = UnionLayout{
1917 .has_payload = layout.payload_size != 0,1918 .has_payload = layout.payload_size != 0,
...@@ -1931,7 +1932,7 @@ const NavGen = struct {...@@ -1931,7 +1932,7 @@ const NavGen = struct {
1931 const most_aligned_field = layout.most_aligned_field;1932 const most_aligned_field = layout.most_aligned_field;
1932 const most_aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[most_aligned_field]);1933 const most_aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[most_aligned_field]);
1933 union_layout.payload_ty = most_aligned_field_ty;1934 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));
1935 } else {1936 } else {
1936 union_layout.payload_size = 0;1937 union_layout.payload_size = 0;
1937 }1938 }
...@@ -1998,12 +1999,12 @@ const NavGen = struct {...@@ -1998,12 +1999,12 @@ const NavGen = struct {
1998 }1999 }
19992000
2000 fn materialize(self: Temporary, ng: *NavGen) !IdResult {2001 fn materialize(self: Temporary, ng: *NavGen) !IdResult {
2001 const mod = ng.pt.zcu;2002 const zcu = ng.pt.zcu;
2002 switch (self.value) {2003 switch (self.value) {
2003 .singleton => |id| return id,2004 .singleton => |id| return id,
2004 .exploded_vector => |range| {2005 .exploded_vector => |range| {
2005 assert(self.ty.isVector(mod));2006 assert(self.ty.isVector(zcu));
2006 assert(self.ty.vectorLen(mod) == range.len);2007 assert(self.ty.vectorLen(zcu) == range.len);
2007 const consituents = try ng.gpa.alloc(IdRef, range.len);2008 const consituents = try ng.gpa.alloc(IdRef, range.len);
2008 defer ng.gpa.free(consituents);2009 defer ng.gpa.free(consituents);
2009 for (consituents, 0..range.len) |*id, i| {2010 for (consituents, 0..range.len) |*id, i| {
...@@ -2028,18 +2029,18 @@ const NavGen = struct {...@@ -2028,18 +2029,18 @@ const NavGen = struct {
2028 /// 'Explode' a temporary into separate elements. This turns a vector2029 /// 'Explode' a temporary into separate elements. This turns a vector
2029 /// into a bag of elements.2030 /// into a bag of elements.
2030 fn explode(self: Temporary, ng: *NavGen) !IdRange {2031 fn explode(self: Temporary, ng: *NavGen) !IdRange {
2031 const mod = ng.pt.zcu;2032 const zcu = ng.pt.zcu;
20322033
2033 // If the value is a scalar, then this is a no-op.2034 // If the value is a scalar, then this is a no-op.
2034 if (!self.ty.isVector(mod)) {2035 if (!self.ty.isVector(zcu)) {
2035 return switch (self.value) {2036 return switch (self.value) {
2036 .singleton => |id| .{ .base = @intFromEnum(id), .len = 1 },2037 .singleton => |id| .{ .base = @intFromEnum(id), .len = 1 },
2037 .exploded_vector => |range| range,2038 .exploded_vector => |range| range,
2038 };2039 };
2039 }2040 }
20402041
2041 const ty_id = try ng.resolveType(self.ty.scalarType(mod), .direct);2042 const ty_id = try ng.resolveType(self.ty.scalarType(zcu), .direct);
2042 const n = self.ty.vectorLen(mod);2043 const n = self.ty.vectorLen(zcu);
2043 const results = ng.spv.allocIds(n);2044 const results = ng.spv.allocIds(n);
20442045
2045 const id = switch (self.value) {2046 const id = switch (self.value) {
...@@ -2087,13 +2088,13 @@ const NavGen = struct {...@@ -2087,13 +2088,13 @@ const NavGen = struct {
2087 /// only checks the size, but the source-of-truth is implemented2088 /// only checks the size, but the source-of-truth is implemented
2088 /// by `isSpvVector()`.2089 /// by `isSpvVector()`.
2089 fn fromType(ty: Type, ng: *NavGen) Vectorization {2090 fn fromType(ty: Type, ng: *NavGen) Vectorization {
2090 const mod = ng.pt.zcu;2091 const zcu = ng.pt.zcu;
2091 if (!ty.isVector(mod)) {2092 if (!ty.isVector(zcu)) {
2092 return .scalar;2093 return .scalar;
2093 } else if (ng.isSpvVector(ty)) {2094 } else if (ng.isSpvVector(ty)) {
2094 return .{ .spv_vectorized = ty.vectorLen(mod) };2095 return .{ .spv_vectorized = ty.vectorLen(zcu) };
2095 } else {2096 } else {
2096 return .{ .unrolled = ty.vectorLen(mod) };2097 return .{ .unrolled = ty.vectorLen(zcu) };
2097 }2098 }
2098 }2099 }
20992100
...@@ -2339,10 +2340,10 @@ const NavGen = struct {...@@ -2339,10 +2340,10 @@ const NavGen = struct {
2339 /// This function builds an OpSConvert of OpUConvert depending on the2340 /// This function builds an OpSConvert of OpUConvert depending on the
2340 /// signedness of the types.2341 /// signedness of the types.
2341 fn buildIntConvert(self: *NavGen, dst_ty: Type, src: Temporary) !Temporary {2342 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 dst_ty_id = try self.resolveType(dst_ty.scalarType(zcu), .direct);
2345 const src_ty_id = try self.resolveType(src.ty.scalarType(mod), .direct);2346 const src_ty_id = try self.resolveType(src.ty.scalarType(zcu), .direct);
23462347
2347 const v = self.vectorization(.{ dst_ty, src });2348 const v = self.vectorization(.{ dst_ty, src });
2348 const result_ty = try v.resultType(self, dst_ty);2349 const result_ty = try v.resultType(self, dst_ty);
...@@ -2363,7 +2364,7 @@ const NavGen = struct {...@@ -2363,7 +2364,7 @@ const NavGen = struct {
2363 const op_result_ty = try v.operationType(self, dst_ty);2364 const op_result_ty = try v.operationType(self, dst_ty);
2364 const op_result_ty_id = try self.resolveType(op_result_ty, .direct);2365 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
2368 const op_src = try v.prepare(self, src);2369 const op_src = try v.prepare(self, src);
23692370
...@@ -2418,7 +2419,7 @@ const NavGen = struct {...@@ -2418,7 +2419,7 @@ const NavGen = struct {
2418 }2419 }
24192420
2420 fn buildSelect(self: *NavGen, condition: Temporary, lhs: Temporary, rhs: Temporary) !Temporary {2421 fn buildSelect(self: *NavGen, condition: Temporary, lhs: Temporary, rhs: Temporary) !Temporary {
2421 const mod = self.pt.zcu;2422 const zcu = self.pt.zcu;
24222423
2423 const v = self.vectorization(.{ condition, lhs, rhs });2424 const v = self.vectorization(.{ condition, lhs, rhs });
2424 const ops = v.operations();2425 const ops = v.operations();
...@@ -2428,7 +2429,7 @@ const NavGen = struct {...@@ -2428,7 +2429,7 @@ const NavGen = struct {
2428 const op_result_ty_id = try self.resolveType(op_result_ty, .direct);2429 const op_result_ty_id = try self.resolveType(op_result_ty, .direct);
2429 const result_ty = try v.resultType(self, lhs.ty);2430 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
2433 const cond = try v.prepare(self, condition);2434 const cond = try v.prepare(self, condition);
2434 const object_1 = try v.prepare(self, lhs);2435 const object_1 = try v.prepare(self, lhs);
...@@ -2764,9 +2765,9 @@ const NavGen = struct {...@@ -2764,9 +2765,9 @@ const NavGen = struct {
2764 rhs: Temporary,2765 rhs: Temporary,
2765 ) !struct { Temporary, Temporary } {2766 ) !struct { Temporary, Temporary } {
2766 const pt = self.pt;2767 const pt = self.pt;
2767 const mod = pt.zcu;2768 const zcu = pt.zcu;
2768 const target = self.getTarget();2769 const target = self.getTarget();
2769 const ip = &mod.intern_pool;2770 const ip = &zcu.intern_pool;
27702771
2771 const v = lhs.vectorization(self).unify(rhs.vectorization(self));2772 const v = lhs.vectorization(self).unify(rhs.vectorization(self));
2772 const ops = v.operations();2773 const ops = v.operations();
...@@ -2814,7 +2815,7 @@ const NavGen = struct {...@@ -2814,7 +2815,7 @@ const NavGen = struct {
2814 // where T is maybe vectorized.2815 // where T is maybe vectorized.
2815 const types = [2]InternPool.Index{ arith_op_ty.toIntern(), arith_op_ty.toIntern() };2816 const types = [2]InternPool.Index{ arith_op_ty.toIntern(), arith_op_ty.toIntern() };
2816 const values = [2]InternPool.Index{ .none, .none };2817 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, .{
2818 .types = &types,2819 .types = &types,
2819 .values = &values,2820 .values = &values,
2820 .names = &.{},2821 .names = &.{},
...@@ -2941,17 +2942,17 @@ const NavGen = struct {...@@ -2941,17 +2942,17 @@ const NavGen = struct {
29412942
2942 fn genNav(self: *NavGen) !void {2943 fn genNav(self: *NavGen) !void {
2943 const pt = self.pt;2944 const pt = self.pt;
2944 const mod = pt.zcu;2945 const zcu = pt.zcu;
2945 const ip = &mod.intern_pool;2946 const ip = &zcu.intern_pool;
2946 const spv_decl_index = try self.object.resolveNav(mod, self.owner_nav);2947 const spv_decl_index = try self.object.resolveNav(zcu, self.owner_nav);
2947 const result_id = self.spv.declPtr(spv_decl_index).result_id;2948 const result_id = self.spv.declPtr(spv_decl_index).result_id;
29482949
2949 const nav = ip.getNav(self.owner_nav);2950 const nav = ip.getNav(self.owner_nav);
2950 const val = mod.navValue(self.owner_nav);2951 const val = zcu.navValue(self.owner_nav);
2951 const ty = val.typeOf(mod);2952 const ty = val.typeOf(zcu);
2952 switch (self.spv.declPtr(spv_decl_index).kind) {2953 switch (self.spv.declPtr(spv_decl_index).kind) {
2953 .func => {2954 .func => {
2954 const fn_info = mod.typeToFunc(ty).?;2955 const fn_info = zcu.typeToFunc(ty).?;
2955 const return_ty_id = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));2956 const return_ty_id = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));
29562957
2957 const prototype_ty_id = try self.resolveType(ty, .direct);2958 const prototype_ty_id = try self.resolveType(ty, .direct);
...@@ -2969,7 +2970,7 @@ const NavGen = struct {...@@ -2969,7 +2970,7 @@ const NavGen = struct {
2969 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);2970 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);
2970 for (fn_info.param_types.get(ip)) |param_ty_index| {2971 for (fn_info.param_types.get(ip)) |param_ty_index| {
2971 const param_ty = Type.fromInterned(param_ty_index);2972 const param_ty = Type.fromInterned(param_ty_index);
2972 if (!param_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;2973 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
29732974
2974 const param_type_id = try self.resolveType(param_ty, .direct);2975 const param_type_id = try self.resolveType(param_ty, .direct);
2975 const arg_result_id = self.spv.allocId();2976 const arg_result_id = self.spv.allocId();
...@@ -3116,8 +3117,8 @@ const NavGen = struct {...@@ -3116,8 +3117,8 @@ const NavGen = struct {
3116 /// Convert representation from indirect (in memory) to direct (in 'register')3117 /// Convert representation from indirect (in memory) to direct (in 'register')
3117 /// This converts the argument type from resolveType(ty, .indirect) to resolveType(ty, .direct).3118 /// This converts the argument type from resolveType(ty, .indirect) to resolveType(ty, .direct).
3118 fn convertToDirect(self: *NavGen, ty: Type, operand_id: IdRef) !IdRef {3119 fn convertToDirect(self: *NavGen, ty: Type, operand_id: IdRef) !IdRef {
3119 const mod = self.pt.zcu;3120 const zcu = self.pt.zcu;
3120 switch (ty.scalarType(mod).zigTypeTag(mod)) {3121 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
3121 .Bool => {3122 .Bool => {
3122 const false_id = try self.constBool(false, .indirect);3123 const false_id = try self.constBool(false, .indirect);
3123 // The operation below requires inputs in direct representation, but the operand3124 // The operation below requires inputs in direct representation, but the operand
...@@ -3142,8 +3143,8 @@ const NavGen = struct {...@@ -3142,8 +3143,8 @@ const NavGen = struct {
3142 /// Convert representation from direct (in 'register) to direct (in memory)3143 /// Convert representation from direct (in 'register) to direct (in memory)
3143 /// This converts the argument type from resolveType(ty, .direct) to resolveType(ty, .indirect).3144 /// This converts the argument type from resolveType(ty, .direct) to resolveType(ty, .indirect).
3144 fn convertToIndirect(self: *NavGen, ty: Type, operand_id: IdRef) !IdRef {3145 fn convertToIndirect(self: *NavGen, ty: Type, operand_id: IdRef) !IdRef {
3145 const mod = self.pt.zcu;3146 const zcu = self.pt.zcu;
3146 switch (ty.scalarType(mod).zigTypeTag(mod)) {3147 switch (ty.scalarType(zcu).zigTypeTag(zcu)) {
3147 .Bool => {3148 .Bool => {
3148 const result = try self.intFromBool(Temporary.init(ty, operand_id));3149 const result = try self.intFromBool(Temporary.init(ty, operand_id));
3149 return try result.materialize(self);3150 return try result.materialize(self);
...@@ -3219,8 +3220,8 @@ const NavGen = struct {...@@ -3219,8 +3220,8 @@ const NavGen = struct {
3219 }3220 }
32203221
3221 fn genInst(self: *NavGen, inst: Air.Inst.Index) !void {3222 fn genInst(self: *NavGen, inst: Air.Inst.Index) !void {
3222 const mod = self.pt.zcu;3223 const zcu = self.pt.zcu;
3223 const ip = &mod.intern_pool;3224 const ip = &zcu.intern_pool;
3224 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))3225 if (self.liveness.isUnused(inst) and !self.air.mustLower(inst, ip))
3225 return;3226 return;
32263227
...@@ -3399,7 +3400,7 @@ const NavGen = struct {...@@ -3399,7 +3400,7 @@ const NavGen = struct {
3399 }3400 }
34003401
3401 fn airShift(self: *NavGen, inst: Air.Inst.Index, unsigned: BinaryOp, signed: BinaryOp) !?IdRef {3402 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;
3403 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;3404 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
34043405
3405 const base = try self.temporary(bin_op.lhs);3406 const base = try self.temporary(bin_op.lhs);
...@@ -3420,7 +3421,7 @@ const NavGen = struct {...@@ -3420,7 +3421,7 @@ const NavGen = struct {
3420 // Note: The sign may differ here between the shift and the base type, in case3421 // Note: The sign may differ here between the shift and the base type, in case
3421 // of an arithmetic right shift. SPIR-V still expects the same type,3422 // of an arithmetic right shift. SPIR-V still expects the same type,
3422 // so in that case we have to cast convert to signed.3423 // 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
3425 const shifted = switch (info.signedness) {3426 const shifted = switch (info.signedness) {
3426 .unsigned => try self.buildBinary(unsigned, base, casted_shift),3427 .unsigned => try self.buildBinary(unsigned, base, casted_shift),
...@@ -3477,7 +3478,7 @@ const NavGen = struct {...@@ -3477,7 +3478,7 @@ const NavGen = struct {
3477 /// All other values are returned unmodified (this makes strange integer3478 /// All other values are returned unmodified (this makes strange integer
3478 /// wrapping easier to use in generic operations).3479 /// wrapping easier to use in generic operations).
3479 fn normalize(self: *NavGen, value: Temporary, info: ArithmeticTypeInfo) !Temporary {3480 fn normalize(self: *NavGen, value: Temporary, info: ArithmeticTypeInfo) !Temporary {
3480 const mod = self.pt.zcu;3481 const zcu = self.pt.zcu;
3481 const ty = value.ty;3482 const ty = value.ty;
3482 switch (info.class) {3483 switch (info.class) {
3483 .integer, .bool, .float => return value,3484 .integer, .bool, .float => return value,
...@@ -3485,13 +3486,13 @@ const NavGen = struct {...@@ -3485,13 +3486,13 @@ const NavGen = struct {
3485 .strange_integer => switch (info.signedness) {3486 .strange_integer => switch (info.signedness) {
3486 .unsigned => {3487 .unsigned => {
3487 const mask_value = if (info.bits == 64) 0xFFFF_FFFF_FFFF_FFFF else (@as(u64, 1) << @as(u6, @intCast(info.bits))) - 1;3488 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 const mask_id = try self.constInt(ty.scalarType(zcu), mask_value, .direct);
3489 return try self.buildBinary(.bit_and, value, Temporary.init(ty.scalarType(mod), mask_id));3490 return try self.buildBinary(.bit_and, value, Temporary.init(ty.scalarType(zcu), mask_id));
3490 },3491 },
3491 .signed => {3492 .signed => {
3492 // Shift left and right so that we can copy the sight bit that way.3493 // 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_id = try self.constInt(ty.scalarType(zcu), info.backing_bits - info.bits, .direct);
3494 const shift_amt = Temporary.init(ty.scalarType(mod), shift_amt_id);3495 const shift_amt = Temporary.init(ty.scalarType(zcu), shift_amt_id);
3495 const left = try self.buildBinary(.sll, value, shift_amt);3496 const left = try self.buildBinary(.sll, value, shift_amt);
3496 return try self.buildBinary(.sra, left, shift_amt);3497 return try self.buildBinary(.sra, left, shift_amt);
3497 },3498 },
...@@ -3897,7 +3898,7 @@ const NavGen = struct {...@@ -3897,7 +3898,7 @@ const NavGen = struct {
3897 }3898 }
38983899
3899 fn airShlOverflow(self: *NavGen, inst: Air.Inst.Index) !?IdRef {3900 fn airShlOverflow(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
3900 const mod = self.pt.zcu;3901 const zcu = self.pt.zcu;
39013902
3902 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;3903 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
3903 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;3904 const extra = self.air.extraData(Air.Bin, ty_pl.payload).data;
...@@ -3916,7 +3917,7 @@ const NavGen = struct {...@@ -3916,7 +3917,7 @@ const NavGen = struct {
39163917
3917 // Sometimes Zig doesn't make both of the arguments the same types here. SPIR-V expects that,3918 // Sometimes Zig doesn't make both of the arguments the same types here. SPIR-V expects that,
3918 // so just manually upcast it if required.3919 // 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
3921 const left = try self.buildBinary(.sll, base, casted_shift);3922 const left = try self.buildBinary(.sll, base, casted_shift);
3922 const result = try self.normalize(left, info);3923 const result = try self.normalize(left, info);
...@@ -3955,12 +3956,12 @@ const NavGen = struct {...@@ -3955,12 +3956,12 @@ const NavGen = struct {
3955 fn airClzCtz(self: *NavGen, inst: Air.Inst.Index, op: UnaryOp) !?IdRef {3956 fn airClzCtz(self: *NavGen, inst: Air.Inst.Index, op: UnaryOp) !?IdRef {
3956 if (self.liveness.isUnused(inst)) return null;3957 if (self.liveness.isUnused(inst)) return null;
39573958
3958 const mod = self.pt.zcu;3959 const zcu = self.pt.zcu;
3959 const target = self.getTarget();3960 const target = self.getTarget();
3960 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;3961 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
3961 const operand = try self.temporary(ty_op.operand);3962 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
3965 const info = self.arithmeticTypeInfo(operand.ty);3966 const info = self.arithmeticTypeInfo(operand.ty);
3966 switch (info.class) {3967 switch (info.class) {
...@@ -4004,16 +4005,16 @@ const NavGen = struct {...@@ -4004,16 +4005,16 @@ const NavGen = struct {
4004 }4005 }
40054006
4006 fn airReduce(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4007 fn airReduce(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4007 const mod = self.pt.zcu;4008 const zcu = self.pt.zcu;
4008 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;4009 const reduce = self.air.instructions.items(.data)[@intFromEnum(inst)].reduce;
4009 const operand = try self.resolve(reduce.operand);4010 const operand = try self.resolve(reduce.operand);
4010 const operand_ty = self.typeOf(reduce.operand);4011 const operand_ty = self.typeOf(reduce.operand);
4011 const scalar_ty = operand_ty.scalarType(mod);4012 const scalar_ty = operand_ty.scalarType(zcu);
4012 const scalar_ty_id = try self.resolveType(scalar_ty, .direct);4013 const scalar_ty_id = try self.resolveType(scalar_ty, .direct);
40134014
4014 const info = self.arithmeticTypeInfo(operand_ty);4015 const info = self.arithmeticTypeInfo(operand_ty);
40154016
4016 const len = operand_ty.vectorLen(mod);4017 const len = operand_ty.vectorLen(zcu);
40174018
4018 const first = try self.extractVectorComponent(scalar_ty, operand, 0);4019 const first = try self.extractVectorComponent(scalar_ty, operand, 0);
40194020
...@@ -4080,7 +4081,7 @@ const NavGen = struct {...@@ -4080,7 +4081,7 @@ const NavGen = struct {
40804081
4081 fn airShuffle(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4082 fn airShuffle(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4082 const pt = self.pt;4083 const pt = self.pt;
4083 const mod = pt.zcu;4084 const zcu = pt.zcu;
4084 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4085 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4085 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;4086 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
4086 const a = try self.resolve(extra.a);4087 const a = try self.resolve(extra.a);
...@@ -4092,7 +4093,7 @@ const NavGen = struct {...@@ -4092,7 +4093,7 @@ const NavGen = struct {
4092 const a_ty = self.typeOf(extra.a);4093 const a_ty = self.typeOf(extra.a);
4093 const b_ty = self.typeOf(extra.b);4094 const b_ty = self.typeOf(extra.b);
40944095
4095 const scalar_ty = result_ty.scalarType(mod);4096 const scalar_ty = result_ty.scalarType(zcu);
4096 const scalar_ty_id = try self.resolveType(scalar_ty, .direct);4097 const scalar_ty_id = try self.resolveType(scalar_ty, .direct);
40974098
4098 // If all of the types are SPIR-V vectors, we can use OpVectorShuffle.4099 // If all of the types are SPIR-V vectors, we can use OpVectorShuffle.
...@@ -4100,20 +4101,20 @@ const NavGen = struct {...@@ -4100,20 +4101,20 @@ const NavGen = struct {
4100 // The SPIR-V shuffle instruction is similar to the Air instruction, except that the elements are4101 // The SPIR-V shuffle instruction is similar to the Air instruction, except that the elements are
4101 // numbered consecutively instead of using negatives.4102 // 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));
4104 defer self.gpa.free(components);4105 defer self.gpa.free(components);
41054106
4106 const a_len = a_ty.vectorLen(mod);4107 const a_len = a_ty.vectorLen(zcu);
41074108
4108 for (components, 0..) |*component, i| {4109 for (components, 0..) |*component, i| {
4109 const elem = try mask.elemValue(pt, i);4110 const elem = try mask.elemValue(pt, i);
4110 if (elem.isUndef(mod)) {4111 if (elem.isUndef(zcu)) {
4111 // This is explicitly valid for OpVectorShuffle, it indicates undefined.4112 // This is explicitly valid for OpVectorShuffle, it indicates undefined.
4112 component.* = 0xFFFF_FFFF;4113 component.* = 0xFFFF_FFFF;
4113 continue;4114 continue;
4114 }4115 }
41154116
4116 const index = elem.toSignedInt(pt);4117 const index = elem.toSignedInt(zcu);
4117 if (index >= 0) {4118 if (index >= 0) {
4118 component.* = @intCast(index);4119 component.* = @intCast(index);
4119 } else {4120 } else {
...@@ -4134,17 +4135,17 @@ const NavGen = struct {...@@ -4134,17 +4135,17 @@ const NavGen = struct {
41344135
4135 // Fall back to manually extracting and inserting components.4136 // 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));
4138 defer self.gpa.free(components);4139 defer self.gpa.free(components);
41394140
4140 for (components, 0..) |*id, i| {4141 for (components, 0..) |*id, i| {
4141 const elem = try mask.elemValue(pt, i);4142 const elem = try mask.elemValue(pt, i);
4142 if (elem.isUndef(mod)) {4143 if (elem.isUndef(zcu)) {
4143 id.* = try self.spv.constUndef(scalar_ty_id);4144 id.* = try self.spv.constUndef(scalar_ty_id);
4144 continue;4145 continue;
4145 }4146 }
41464147
4147 const index = elem.toSignedInt(pt);4148 const index = elem.toSignedInt(zcu);
4148 if (index >= 0) {4149 if (index >= 0) {
4149 id.* = try self.extractVectorComponent(scalar_ty, a, @intCast(index));4150 id.* = try self.extractVectorComponent(scalar_ty, a, @intCast(index));
4150 } else {4151 } else {
...@@ -4218,10 +4219,10 @@ const NavGen = struct {...@@ -4218,10 +4219,10 @@ const NavGen = struct {
4218 }4219 }
42194220
4220 fn ptrAdd(self: *NavGen, result_ty: Type, ptr_ty: Type, ptr_id: IdRef, offset_id: IdRef) !IdRef {4221 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;
4222 const result_ty_id = try self.resolveType(result_ty, .direct);4223 const result_ty_id = try self.resolveType(result_ty, .direct);
42234224
4224 switch (ptr_ty.ptrSize(mod)) {4225 switch (ptr_ty.ptrSize(zcu)) {
4225 .One => {4226 .One => {
4226 // Pointer to array4227 // Pointer to array
4227 // TODO: Is this correct?4228 // TODO: Is this correct?
...@@ -4275,15 +4276,15 @@ const NavGen = struct {...@@ -4275,15 +4276,15 @@ const NavGen = struct {
4275 rhs: Temporary,4276 rhs: Temporary,
4276 ) !Temporary {4277 ) !Temporary {
4277 const pt = self.pt;4278 const pt = self.pt;
4278 const mod = pt.zcu;4279 const zcu = pt.zcu;
4279 const scalar_ty = lhs.ty.scalarType(mod);4280 const scalar_ty = lhs.ty.scalarType(zcu);
4280 const is_vector = lhs.ty.isVector(mod);4281 const is_vector = lhs.ty.isVector(zcu);
42814282
4282 switch (scalar_ty.zigTypeTag(mod)) {4283 switch (scalar_ty.zigTypeTag(zcu)) {
4283 .Int, .Bool, .Float => {},4284 .Int, .Bool, .Float => {},
4284 .Enum => {4285 .Enum => {
4285 assert(!is_vector);4286 assert(!is_vector);
4286 const ty = lhs.ty.intTagType(mod);4287 const ty = lhs.ty.intTagType(zcu);
4287 return try self.cmp(op, lhs.pun(ty), rhs.pun(ty));4288 return try self.cmp(op, lhs.pun(ty), rhs.pun(ty));
4288 },4289 },
4289 .ErrorSet => {4290 .ErrorSet => {
...@@ -4321,10 +4322,10 @@ const NavGen = struct {...@@ -4321,10 +4322,10 @@ const NavGen = struct {
43214322
4322 const ty = lhs.ty;4323 const ty = lhs.ty;
43234324
4324 const payload_ty = ty.optionalChild(mod);4325 const payload_ty = ty.optionalChild(zcu);
4325 if (ty.optionalReprIsPayload(mod)) {4326 if (ty.optionalReprIsPayload(zcu)) {
4326 assert(payload_ty.hasRuntimeBitsIgnoreComptime(pt));4327 assert(payload_ty.hasRuntimeBitsIgnoreComptime(zcu));
4327 assert(!payload_ty.isSlice(mod));4328 assert(!payload_ty.isSlice(zcu));
43284329
4329 return try self.cmp(op, lhs.pun(payload_ty), rhs.pun(payload_ty));4330 return try self.cmp(op, lhs.pun(payload_ty), rhs.pun(payload_ty));
4330 }4331 }
...@@ -4332,12 +4333,12 @@ const NavGen = struct {...@@ -4332,12 +4333,12 @@ const NavGen = struct {
4332 const lhs_id = try lhs.materialize(self);4333 const lhs_id = try lhs.materialize(self);
4333 const rhs_id = try rhs.materialize(self);4334 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))
4336 try self.extractField(Type.bool, lhs_id, 1)4337 try self.extractField(Type.bool, lhs_id, 1)
4337 else4338 else
4338 try self.convertToDirect(Type.bool, lhs_id);4339 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))
4341 try self.extractField(Type.bool, rhs_id, 1)4342 try self.extractField(Type.bool, rhs_id, 1)
4342 else4343 else
4343 try self.convertToDirect(Type.bool, rhs_id);4344 try self.convertToDirect(Type.bool, rhs_id);
...@@ -4345,7 +4346,7 @@ const NavGen = struct {...@@ -4345,7 +4346,7 @@ const NavGen = struct {
4345 const lhs_valid = Temporary.init(Type.bool, lhs_valid_id);4346 const lhs_valid = Temporary.init(Type.bool, lhs_valid_id);
4346 const rhs_valid = Temporary.init(Type.bool, rhs_valid_id);4347 const rhs_valid = Temporary.init(Type.bool, rhs_valid_id);
43474348
4348 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {4349 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4349 return try self.cmp(op, lhs_valid, rhs_valid);4350 return try self.cmp(op, lhs_valid, rhs_valid);
4350 }4351 }
43514352
...@@ -4465,7 +4466,7 @@ const NavGen = struct {...@@ -4465,7 +4466,7 @@ const NavGen = struct {
4465 src_ty: Type,4466 src_ty: Type,
4466 src_id: IdRef,4467 src_id: IdRef,
4467 ) !IdRef {4468 ) !IdRef {
4468 const mod = self.pt.zcu;4469 const zcu = self.pt.zcu;
4469 const src_ty_id = try self.resolveType(src_ty, .direct);4470 const src_ty_id = try self.resolveType(src_ty, .direct);
4470 const dst_ty_id = try self.resolveType(dst_ty, .direct);4471 const dst_ty_id = try self.resolveType(dst_ty, .direct);
44714472
...@@ -4477,7 +4478,7 @@ const NavGen = struct {...@@ -4477,7 +4478,7 @@ const NavGen = struct {
4477 // TODO: Some more cases are missing here4478 // TODO: Some more cases are missing here
4478 // See fn bitCast in llvm.zig4479 // 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)) {
4481 const result_id = self.spv.allocId();4482 const result_id = self.spv.allocId();
4482 try self.func.body.emit(self.spv.gpa, .OpConvertUToPtr, .{4483 try self.func.body.emit(self.spv.gpa, .OpConvertUToPtr, .{
4483 .id_result_type = dst_ty_id,4484 .id_result_type = dst_ty_id,
...@@ -4490,7 +4491,7 @@ const NavGen = struct {...@@ -4490,7 +4491,7 @@ const NavGen = struct {
4490 // We can only use OpBitcast for specific conversions: between numerical types, and4491 // We can only use OpBitcast for specific conversions: between numerical types, and
4491 // between pointers. If the resolved spir-v types fall into this category then emit OpBitcast,4492 // between pointers. If the resolved spir-v types fall into this category then emit OpBitcast,
4492 // otherwise use a temporary and perform a pointer cast.4493 // 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));
4494 if (can_bitcast) {4495 if (can_bitcast) {
4495 const result_id = self.spv.allocId();4496 const result_id = self.spv.allocId();
4496 try self.func.body.emit(self.spv.gpa, .OpBitcast, .{4497 try self.func.body.emit(self.spv.gpa, .OpBitcast, .{
...@@ -4519,7 +4520,7 @@ const NavGen = struct {...@@ -4519,7 +4520,7 @@ const NavGen = struct {
4519 // the result here.4520 // the result here.
4520 // TODO: This detail could cause stuff like @as(*const i1, @ptrCast(&@as(u1, 1))) to break4521 // TODO: This detail could cause stuff like @as(*const i1, @ptrCast(&@as(u1, 1))) to break
4521 // should we change the representation of strange integers?4522 // should we change the representation of strange integers?
4522 if (dst_ty.zigTypeTag(mod) == .Int) {4523 if (dst_ty.zigTypeTag(zcu) == .Int) {
4523 const info = self.arithmeticTypeInfo(dst_ty);4524 const info = self.arithmeticTypeInfo(dst_ty);
4524 const result = try self.normalize(Temporary.init(dst_ty, result_id), info);4525 const result = try self.normalize(Temporary.init(dst_ty, result_id), info);
4525 return try result.materialize(self);4526 return try result.materialize(self);
...@@ -4675,19 +4676,19 @@ const NavGen = struct {...@@ -4675,19 +4676,19 @@ const NavGen = struct {
46754676
4676 fn airArrayToSlice(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4677 fn airArrayToSlice(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4677 const pt = self.pt;4678 const pt = self.pt;
4678 const mod = pt.zcu;4679 const zcu = pt.zcu;
4679 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;4680 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
4680 const array_ptr_ty = self.typeOf(ty_op.operand);4681 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);
4682 const slice_ty = self.typeOfIndex(inst);4683 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
4685 const elem_ptr_ty_id = try self.resolveType(elem_ptr_ty, .direct);4686 const elem_ptr_ty_id = try self.resolveType(elem_ptr_ty, .direct);
46864687
4687 const array_ptr_id = try self.resolve(ty_op.operand);4688 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))
4691 // Note: The pointer is something like *opaque{}, so we need to bitcast it to the element type.4692 // Note: The pointer is something like *opaque{}, so we need to bitcast it to the element type.
4692 try self.bitCast(elem_ptr_ty, array_ptr_ty, array_ptr_id)4693 try self.bitCast(elem_ptr_ty, array_ptr_ty, array_ptr_id)
4693 else4694 else
...@@ -4720,16 +4721,16 @@ const NavGen = struct {...@@ -4720,16 +4721,16 @@ const NavGen = struct {
47204721
4721 fn airAggregateInit(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4722 fn airAggregateInit(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4722 const pt = self.pt;4723 const pt = self.pt;
4723 const mod = pt.zcu;4724 const zcu = pt.zcu;
4724 const ip = &mod.intern_pool;4725 const ip = &zcu.intern_pool;
4725 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4726 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4726 const result_ty = self.typeOfIndex(inst);4727 const result_ty = self.typeOfIndex(inst);
4727 const len: usize = @intCast(result_ty.arrayLen(mod));4728 const len: usize = @intCast(result_ty.arrayLen(zcu));
4728 const elements: []const Air.Inst.Ref = @ptrCast(self.air.extra[ty_pl.payload..][0..len]);4729 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)) {
4731 .Struct => {4732 .Struct => {
4732 if (mod.typeToPackedStruct(result_ty)) |struct_type| {4733 if (zcu.typeToPackedStruct(result_ty)) |struct_type| {
4733 _ = struct_type;4734 _ = struct_type;
4734 unreachable; // TODO4735 unreachable; // TODO
4735 }4736 }
...@@ -4744,7 +4745,7 @@ const NavGen = struct {...@@ -4744,7 +4745,7 @@ const NavGen = struct {
4744 .anon_struct_type => |tuple| {4745 .anon_struct_type => |tuple| {
4745 for (tuple.types.get(ip), elements, 0..) |field_ty, element, i| {4746 for (tuple.types.get(ip), elements, 0..) |field_ty, element, i| {
4746 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;4747 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
4749 const id = try self.resolve(element);4750 const id = try self.resolve(element);
4750 types[index] = Type.fromInterned(field_ty);4751 types[index] = Type.fromInterned(field_ty);
...@@ -4759,7 +4760,7 @@ const NavGen = struct {...@@ -4759,7 +4760,7 @@ const NavGen = struct {
4759 const field_index = it.next().?;4760 const field_index = it.next().?;
4760 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;4761 if ((try result_ty.structFieldValueComptime(pt, i)) != null) continue;
4761 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);4762 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
4764 const id = try self.resolve(element);4765 const id = try self.resolve(element);
4765 types[index] = field_ty;4766 types[index] = field_ty;
...@@ -4777,7 +4778,7 @@ const NavGen = struct {...@@ -4777,7 +4778,7 @@ const NavGen = struct {
4777 );4778 );
4778 },4779 },
4779 .Vector => {4780 .Vector => {
4780 const n_elems = result_ty.vectorLen(mod);4781 const n_elems = result_ty.vectorLen(zcu);
4781 const elem_ids = try self.gpa.alloc(IdRef, n_elems);4782 const elem_ids = try self.gpa.alloc(IdRef, n_elems);
4782 defer self.gpa.free(elem_ids);4783 defer self.gpa.free(elem_ids);
47834784
...@@ -4788,8 +4789,8 @@ const NavGen = struct {...@@ -4788,8 +4789,8 @@ const NavGen = struct {
4788 return try self.constructVector(result_ty, elem_ids);4789 return try self.constructVector(result_ty, elem_ids);
4789 },4790 },
4790 .Array => {4791 .Array => {
4791 const array_info = result_ty.arrayInfo(mod);4792 const array_info = result_ty.arrayInfo(zcu);
4792 const n_elems: usize = @intCast(result_ty.arrayLenIncludingSentinel(mod));4793 const n_elems: usize = @intCast(result_ty.arrayLenIncludingSentinel(zcu));
4793 const elem_ids = try self.gpa.alloc(IdRef, n_elems);4794 const elem_ids = try self.gpa.alloc(IdRef, n_elems);
4794 defer self.gpa.free(elem_ids);4795 defer self.gpa.free(elem_ids);
47954796
...@@ -4810,14 +4811,14 @@ const NavGen = struct {...@@ -4810,14 +4811,14 @@ const NavGen = struct {
48104811
4811 fn sliceOrArrayLen(self: *NavGen, operand_id: IdRef, ty: Type) !IdRef {4812 fn sliceOrArrayLen(self: *NavGen, operand_id: IdRef, ty: Type) !IdRef {
4812 const pt = self.pt;4813 const pt = self.pt;
4813 const mod = pt.zcu;4814 const zcu = pt.zcu;
4814 switch (ty.ptrSize(mod)) {4815 switch (ty.ptrSize(zcu)) {
4815 .Slice => return self.extractField(Type.usize, operand_id, 1),4816 .Slice => return self.extractField(Type.usize, operand_id, 1),
4816 .One => {4817 .One => {
4817 const array_ty = ty.childType(mod);4818 const array_ty = ty.childType(zcu);
4818 const elem_ty = array_ty.childType(mod);4819 const elem_ty = array_ty.childType(zcu);
4819 const abi_size = elem_ty.abiSize(pt);4820 const abi_size = elem_ty.abiSize(zcu);
4820 const size = array_ty.arrayLenIncludingSentinel(mod) * abi_size;4821 const size = array_ty.arrayLenIncludingSentinel(zcu) * abi_size;
4821 return try self.constInt(Type.usize, size, .direct);4822 return try self.constInt(Type.usize, size, .direct);
4822 },4823 },
4823 .Many, .C => unreachable,4824 .Many, .C => unreachable,
...@@ -4825,9 +4826,9 @@ const NavGen = struct {...@@ -4825,9 +4826,9 @@ const NavGen = struct {
4825 }4826 }
48264827
4827 fn sliceOrArrayPtr(self: *NavGen, operand_id: IdRef, ty: Type) !IdRef {4828 fn sliceOrArrayPtr(self: *NavGen, operand_id: IdRef, ty: Type) !IdRef {
4828 const mod = self.pt.zcu;4829 const zcu = self.pt.zcu;
4829 if (ty.isSlice(mod)) {4830 if (ty.isSlice(zcu)) {
4830 const ptr_ty = ty.slicePtrFieldType(mod);4831 const ptr_ty = ty.slicePtrFieldType(zcu);
4831 return self.extractField(ptr_ty, operand_id, 0);4832 return self.extractField(ptr_ty, operand_id, 0);
4832 }4833 }
4833 return operand_id;4834 return operand_id;
...@@ -4857,11 +4858,11 @@ const NavGen = struct {...@@ -4857,11 +4858,11 @@ const NavGen = struct {
4857 }4858 }
48584859
4859 fn airSliceElemPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4860 fn airSliceElemPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4860 const mod = self.pt.zcu;4861 const zcu = self.pt.zcu;
4861 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4862 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4862 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;4863 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
4863 const slice_ty = self.typeOf(bin_op.lhs);4864 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
4866 const slice_id = try self.resolve(bin_op.lhs);4867 const slice_id = try self.resolve(bin_op.lhs);
4867 const index_id = try self.resolve(bin_op.rhs);4868 const index_id = try self.resolve(bin_op.rhs);
...@@ -4874,28 +4875,28 @@ const NavGen = struct {...@@ -4874,28 +4875,28 @@ const NavGen = struct {
4874 }4875 }
48754876
4876 fn airSliceElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4877 fn airSliceElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4877 const mod = self.pt.zcu;4878 const zcu = self.pt.zcu;
4878 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4879 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4879 const slice_ty = self.typeOf(bin_op.lhs);4880 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
4882 const slice_id = try self.resolve(bin_op.lhs);4883 const slice_id = try self.resolve(bin_op.lhs);
4883 const index_id = try self.resolve(bin_op.rhs);4884 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);
4886 const ptr_ty_id = try self.resolveType(ptr_ty, .direct);4887 const ptr_ty_id = try self.resolveType(ptr_ty, .direct);
48874888
4888 const slice_ptr = try self.extractField(ptr_ty, slice_id, 0);4889 const slice_ptr = try self.extractField(ptr_ty, slice_id, 0);
4889 const elem_ptr = try self.ptrAccessChain(ptr_ty_id, slice_ptr, index_id, &.{});4890 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) });
4891 }4892 }
48924893
4893 fn ptrElemPtr(self: *NavGen, ptr_ty: Type, ptr_id: IdRef, index_id: IdRef) !IdRef {4894 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;
4895 // Construct new pointer type for the resulting pointer4896 // 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_ty = ptr_ty.elemType2(zcu); // 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 const elem_ptr_ty_id = try self.ptrType(elem_ty, self.spvStorageClass(ptr_ty.ptrAddressSpace(zcu)));
4898 if (ptr_ty.isSinglePointer(mod)) {4899 if (ptr_ty.isSinglePointer(zcu)) {
4899 // Pointer-to-array. In this case, the resulting pointer is not of the same type4900 // Pointer-to-array. In this case, the resulting pointer is not of the same type
4900 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.4901 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.
4901 return try self.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id});4902 return try self.accessChainId(elem_ptr_ty_id, ptr_id, &.{index_id});
...@@ -4907,14 +4908,14 @@ const NavGen = struct {...@@ -4907,14 +4908,14 @@ const NavGen = struct {
49074908
4908 fn airPtrElemPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4909 fn airPtrElemPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4909 const pt = self.pt;4910 const pt = self.pt;
4910 const mod = pt.zcu;4911 const zcu = pt.zcu;
4911 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;4912 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
4912 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;4913 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
4913 const src_ptr_ty = self.typeOf(bin_op.lhs);4914 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);
4915 const ptr_id = try self.resolve(bin_op.lhs);4916 const ptr_id = try self.resolve(bin_op.lhs);
49164917
4917 if (!elem_ty.hasRuntimeBitsIgnoreComptime(pt)) {4918 if (!elem_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
4918 const dst_ptr_ty = self.typeOfIndex(inst);4919 const dst_ptr_ty = self.typeOfIndex(inst);
4919 return try self.bitCast(dst_ptr_ty, src_ptr_ty, ptr_id);4920 return try self.bitCast(dst_ptr_ty, src_ptr_ty, ptr_id);
4920 }4921 }
...@@ -4924,10 +4925,10 @@ const NavGen = struct {...@@ -4924,10 +4925,10 @@ const NavGen = struct {
4924 }4925 }
49254926
4926 fn airArrayElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4927 fn airArrayElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4927 const mod = self.pt.zcu;4928 const zcu = self.pt.zcu;
4928 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4929 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4929 const array_ty = self.typeOf(bin_op.lhs);4930 const array_ty = self.typeOf(bin_op.lhs);
4930 const elem_ty = array_ty.childType(mod);4931 const elem_ty = array_ty.childType(zcu);
4931 const array_id = try self.resolve(bin_op.lhs);4932 const array_id = try self.resolve(bin_op.lhs);
4932 const index_id = try self.resolve(bin_op.rhs);4933 const index_id = try self.resolve(bin_op.rhs);
49334934
...@@ -4946,7 +4947,7 @@ const NavGen = struct {...@@ -4946,7 +4947,7 @@ const NavGen = struct {
4946 // For now, just generate a temporary and use that.4947 // For now, just generate a temporary and use that.
4947 // TODO: This backend probably also should use isByRef from llvm...4948 // 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
4951 const elem_repr: Repr = if (is_vector) .direct else .indirect;4952 const elem_repr: Repr = if (is_vector) .direct else .indirect;
4952 const ptr_array_ty_id = try self.ptrType2(array_ty, .Function, .direct);4953 const ptr_array_ty_id = try self.ptrType2(array_ty, .Function, .direct);
...@@ -4985,26 +4986,26 @@ const NavGen = struct {...@@ -4985,26 +4986,26 @@ const NavGen = struct {
4985 }4986 }
49864987
4987 fn airPtrElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {4988 fn airPtrElemVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
4988 const mod = self.pt.zcu;4989 const zcu = self.pt.zcu;
4989 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;4990 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
4990 const ptr_ty = self.typeOf(bin_op.lhs);4991 const ptr_ty = self.typeOf(bin_op.lhs);
4991 const elem_ty = self.typeOfIndex(inst);4992 const elem_ty = self.typeOfIndex(inst);
4992 const ptr_id = try self.resolve(bin_op.lhs);4993 const ptr_id = try self.resolve(bin_op.lhs);
4993 const index_id = try self.resolve(bin_op.rhs);4994 const index_id = try self.resolve(bin_op.rhs);
4994 const elem_ptr_id = try self.ptrElemPtr(ptr_ty, ptr_id, index_id);4995 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) });
4996 }4997 }
49974998
4998 fn airVectorStoreElem(self: *NavGen, inst: Air.Inst.Index) !void {4999 fn airVectorStoreElem(self: *NavGen, inst: Air.Inst.Index) !void {
4999 const mod = self.pt.zcu;5000 const zcu = self.pt.zcu;
5000 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;5001 const data = self.air.instructions.items(.data)[@intFromEnum(inst)].vector_store_elem;
5001 const extra = self.air.extraData(Air.Bin, data.payload).data;5002 const extra = self.air.extraData(Air.Bin, data.payload).data;
50025003
5003 const vector_ptr_ty = self.typeOf(data.vector_ptr);5004 const vector_ptr_ty = self.typeOf(data.vector_ptr);
5004 const vector_ty = vector_ptr_ty.childType(mod);5005 const vector_ty = vector_ptr_ty.childType(zcu);
5005 const scalar_ty = vector_ty.scalarType(mod);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));
5008 const scalar_ptr_ty_id = try self.ptrType(scalar_ty, storage_class);5009 const scalar_ptr_ty_id = try self.ptrType(scalar_ty, storage_class);
50095010
5010 const vector_ptr = try self.resolve(data.vector_ptr);5011 const vector_ptr = try self.resolve(data.vector_ptr);
...@@ -5013,30 +5014,30 @@ const NavGen = struct {...@@ -5013,30 +5014,30 @@ const NavGen = struct {
50135014
5014 const elem_ptr_id = try self.accessChainId(scalar_ptr_ty_id, vector_ptr, &.{index});5015 const elem_ptr_id = try self.accessChainId(scalar_ptr_ty_id, vector_ptr, &.{index});
5015 try self.store(scalar_ty, elem_ptr_id, operand, .{5016 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),
5017 });5018 });
5018 }5019 }
50195020
5020 fn airSetUnionTag(self: *NavGen, inst: Air.Inst.Index) !void {5021 fn airSetUnionTag(self: *NavGen, inst: Air.Inst.Index) !void {
5021 const mod = self.pt.zcu;5022 const zcu = self.pt.zcu;
5022 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5023 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5023 const un_ptr_ty = self.typeOf(bin_op.lhs);5024 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);
5025 const layout = self.unionLayout(un_ty);5026 const layout = self.unionLayout(un_ty);
50265027
5027 if (layout.tag_size == 0) return;5028 if (layout.tag_size == 0) return;
50285029
5029 const tag_ty = un_ty.unionTagTypeSafety(mod).?;5030 const tag_ty = un_ty.unionTagTypeSafety(zcu).?;
5030 const tag_ptr_ty_id = try self.ptrType(tag_ty, self.spvStorageClass(un_ptr_ty.ptrAddressSpace(mod)));5031 const tag_ptr_ty_id = try self.ptrType(tag_ty, self.spvStorageClass(un_ptr_ty.ptrAddressSpace(zcu)));
50315032
5032 const union_ptr_id = try self.resolve(bin_op.lhs);5033 const union_ptr_id = try self.resolve(bin_op.lhs);
5033 const new_tag_id = try self.resolve(bin_op.rhs);5034 const new_tag_id = try self.resolve(bin_op.rhs);
50345035
5035 if (!layout.has_payload) {5036 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) });
5037 } else {5038 } else {
5038 const ptr_id = try self.accessChain(tag_ptr_ty_id, union_ptr_id, &.{layout.tag_index});5039 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) });
5040 }5041 }
5041 }5042 }
50425043
...@@ -5044,14 +5045,14 @@ const NavGen = struct {...@@ -5044,14 +5045,14 @@ const NavGen = struct {
5044 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5045 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5045 const un_ty = self.typeOf(ty_op.operand);5046 const un_ty = self.typeOf(ty_op.operand);
50465047
5047 const mod = self.pt.zcu;5048 const zcu = self.pt.zcu;
5048 const layout = self.unionLayout(un_ty);5049 const layout = self.unionLayout(un_ty);
5049 if (layout.tag_size == 0) return null;5050 if (layout.tag_size == 0) return null;
50505051
5051 const union_handle = try self.resolve(ty_op.operand);5052 const union_handle = try self.resolve(ty_op.operand);
5052 if (!layout.has_payload) return union_handle;5053 if (!layout.has_payload) return union_handle;
50535054
5054 const tag_ty = un_ty.unionTagTypeSafety(mod).?;5055 const tag_ty = un_ty.unionTagTypeSafety(zcu).?;
5055 return try self.extractField(tag_ty, union_handle, layout.tag_index);5056 return try self.extractField(tag_ty, union_handle, layout.tag_index);
5056 }5057 }
50575058
...@@ -5068,9 +5069,9 @@ const NavGen = struct {...@@ -5068,9 +5069,9 @@ const NavGen = struct {
5068 // Note: The result here is not cached, because it generates runtime code.5069 // Note: The result here is not cached, because it generates runtime code.
50695070
5070 const pt = self.pt;5071 const pt = self.pt;
5071 const mod = pt.zcu;5072 const zcu = pt.zcu;
5072 const ip = &mod.intern_pool;5073 const ip = &zcu.intern_pool;
5073 const union_ty = mod.typeToUnion(ty).?;5074 const union_ty = zcu.typeToUnion(ty).?;
5074 const tag_ty = Type.fromInterned(union_ty.enum_tag_ty);5075 const tag_ty = Type.fromInterned(union_ty.enum_tag_ty);
50755076
5076 if (union_ty.flagsUnordered(ip).layout == .@"packed") {5077 if (union_ty.flagsUnordered(ip).layout == .@"packed") {
...@@ -5082,7 +5083,7 @@ const NavGen = struct {...@@ -5082,7 +5083,7 @@ const NavGen = struct {
5082 const tag_int = if (layout.tag_size != 0) blk: {5083 const tag_int = if (layout.tag_size != 0) blk: {
5083 const tag_val = try pt.enumValueFieldIndex(tag_ty, active_field);5084 const tag_val = try pt.enumValueFieldIndex(tag_ty, active_field);
5084 const tag_int_val = try tag_val.intFromEnum(tag_ty, pt);5085 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);
5086 } else 0;5087 } else 0;
50875088
5088 if (!layout.has_payload) {5089 if (!layout.has_payload) {
...@@ -5099,7 +5100,7 @@ const NavGen = struct {...@@ -5099,7 +5100,7 @@ const NavGen = struct {
5099 }5100 }
51005101
5101 const payload_ty = Type.fromInterned(union_ty.field_types.get(ip)[active_field]);5102 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)) {
5103 const pl_ptr_ty_id = try self.ptrType(layout.payload_ty, .Function);5104 const pl_ptr_ty_id = try self.ptrType(layout.payload_ty, .Function);
5104 const pl_ptr_id = try self.accessChain(pl_ptr_ty_id, tmp_id, &.{layout.payload_index});5105 const pl_ptr_id = try self.accessChain(pl_ptr_ty_id, tmp_id, &.{layout.payload_index});
5105 const active_pl_ptr_ty_id = try self.ptrType(payload_ty, .Function);5106 const active_pl_ptr_ty_id = try self.ptrType(payload_ty, .Function);
...@@ -5123,15 +5124,15 @@ const NavGen = struct {...@@ -5123,15 +5124,15 @@ const NavGen = struct {
51235124
5124 fn airUnionInit(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5125 fn airUnionInit(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5125 const pt = self.pt;5126 const pt = self.pt;
5126 const mod = pt.zcu;5127 const zcu = pt.zcu;
5127 const ip = &mod.intern_pool;5128 const ip = &zcu.intern_pool;
5128 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5129 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5129 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;5130 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
5130 const ty = self.typeOfIndex(inst);5131 const ty = self.typeOfIndex(inst);
51315132
5132 const union_obj = mod.typeToUnion(ty).?;5133 const union_obj = zcu.typeToUnion(ty).?;
5133 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);5134 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))
5135 try self.resolve(extra.init)5136 try self.resolve(extra.init)
5136 else5137 else
5137 null;5138 null;
...@@ -5140,23 +5141,23 @@ const NavGen = struct {...@@ -5140,23 +5141,23 @@ const NavGen = struct {
51405141
5141 fn airStructFieldVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5142 fn airStructFieldVal(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5142 const pt = self.pt;5143 const pt = self.pt;
5143 const mod = pt.zcu;5144 const zcu = pt.zcu;
5144 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5145 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5145 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;5146 const struct_field = self.air.extraData(Air.StructField, ty_pl.payload).data;
51465147
5147 const object_ty = self.typeOf(struct_field.struct_operand);5148 const object_ty = self.typeOf(struct_field.struct_operand);
5148 const object_id = try self.resolve(struct_field.struct_operand);5149 const object_id = try self.resolve(struct_field.struct_operand);
5149 const field_index = struct_field.field_index;5150 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 switch (object_ty.zigTypeTag(zcu)) {
5155 .Struct => switch (object_ty.containerLayout(mod)) {5156 .Struct => switch (object_ty.containerLayout(zcu)) {
5156 .@"packed" => unreachable, // TODO5157 .@"packed" => unreachable, // TODO
5157 else => return try self.extractField(field_ty, object_id, field_index),5158 else => return try self.extractField(field_ty, object_id, field_index),
5158 },5159 },
5159 .Union => switch (object_ty.containerLayout(mod)) {5160 .Union => switch (object_ty.containerLayout(zcu)) {
5160 .@"packed" => unreachable, // TODO5161 .@"packed" => unreachable, // TODO
5161 else => {5162 else => {
5162 // Store, ptr-elem-ptr, pointer-cast, load5163 // Store, ptr-elem-ptr, pointer-cast, load
...@@ -5185,16 +5186,16 @@ const NavGen = struct {...@@ -5185,16 +5186,16 @@ const NavGen = struct {
51855186
5186 fn airFieldParentPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5187 fn airFieldParentPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5187 const pt = self.pt;5188 const pt = self.pt;
5188 const mod = pt.zcu;5189 const zcu = pt.zcu;
5189 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;5190 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
5190 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;5191 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);
5193 const result_ty_id = try self.resolveType(ty_pl.ty.toType(), .indirect);5194 const result_ty_id = try self.resolveType(ty_pl.ty.toType(), .indirect);
51945195
5195 const field_ptr = try self.resolve(extra.field_ptr);5196 const field_ptr = try self.resolve(extra.field_ptr);
5196 const field_ptr_int = try self.intFromPtr(field_ptr);5197 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
5199 const base_ptr_int = base_ptr_int: {5200 const base_ptr_int = base_ptr_int: {
5200 if (field_offset == 0) break :base_ptr_int field_ptr_int;5201 if (field_offset == 0) break :base_ptr_int field_ptr_int;
...@@ -5319,10 +5320,10 @@ const NavGen = struct {...@@ -5319,10 +5320,10 @@ const NavGen = struct {
5319 }5320 }
53205321
5321 fn airAlloc(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5322 fn airAlloc(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5322 const mod = self.pt.zcu;5323 const zcu = self.pt.zcu;
5323 const ptr_ty = self.typeOfIndex(inst);5324 const ptr_ty = self.typeOfIndex(inst);
5324 assert(ptr_ty.ptrAddressSpace(mod) == .generic);5325 assert(ptr_ty.ptrAddressSpace(zcu) == .generic);
5325 const child_ty = ptr_ty.childType(mod);5326 const child_ty = ptr_ty.childType(zcu);
5326 return try self.alloc(child_ty, .{});5327 return try self.alloc(child_ty, .{});
5327 }5328 }
53285329
...@@ -5494,9 +5495,9 @@ const NavGen = struct {...@@ -5494,9 +5495,9 @@ const NavGen = struct {
5494 // ir.Block in a different SPIR-V block.5495 // ir.Block in a different SPIR-V block.
54955496
5496 const pt = self.pt;5497 const pt = self.pt;
5497 const mod = pt.zcu;5498 const zcu = pt.zcu;
5498 const ty = self.typeOfIndex(inst);5499 const ty = self.typeOfIndex(inst);
5499 const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(pt);5500 const have_block_result = ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu);
55005501
5501 const cf = switch (self.control_flow) {5502 const cf = switch (self.control_flow) {
5502 .structured => |*cf| cf,5503 .structured => |*cf| cf,
...@@ -5570,7 +5571,7 @@ const NavGen = struct {...@@ -5570,7 +5571,7 @@ const NavGen = struct {
55705571
5571 const sblock = cf.block_stack.getLast();5572 const sblock = cf.block_stack.getLast();
55725573
5573 if (ty.isNoReturn(mod)) {5574 if (ty.isNoReturn(zcu)) {
5574 // If this block is noreturn, this instruction is the last of a block,5575 // If this block is noreturn, this instruction is the last of a block,
5575 // and we must simply jump to the block's merge unconditionally.5576 // and we must simply jump to the block's merge unconditionally.
5576 try self.structuredBreak(next_block);5577 try self.structuredBreak(next_block);
...@@ -5626,13 +5627,13 @@ const NavGen = struct {...@@ -5626,13 +5627,13 @@ const NavGen = struct {
5626 }5627 }
56275628
5628 fn airBr(self: *NavGen, inst: Air.Inst.Index) !void {5629 fn airBr(self: *NavGen, inst: Air.Inst.Index) !void {
5629 const pt = self.pt;5630 const zcu = self.pt.zcu;
5630 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;5631 const br = self.air.instructions.items(.data)[@intFromEnum(inst)].br;
5631 const operand_ty = self.typeOf(br.operand);5632 const operand_ty = self.typeOf(br.operand);
56325633
5633 switch (self.control_flow) {5634 switch (self.control_flow) {
5634 .structured => |*cf| {5635 .structured => |*cf| {
5635 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {5636 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
5636 const operand_id = try self.resolve(br.operand);5637 const operand_id = try self.resolve(br.operand);
5637 const block_result_var_id = cf.block_results.get(br.block_inst).?;5638 const block_result_var_id = cf.block_results.get(br.block_inst).?;
5638 try self.store(operand_ty, block_result_var_id, operand_id, .{});5639 try self.store(operand_ty, block_result_var_id, operand_id, .{});
...@@ -5643,7 +5644,7 @@ const NavGen = struct {...@@ -5643,7 +5644,7 @@ const NavGen = struct {
5643 },5644 },
5644 .unstructured => |cf| {5645 .unstructured => |cf| {
5645 const block = cf.blocks.get(br.block_inst).?;5646 const block = cf.blocks.get(br.block_inst).?;
5646 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(pt)) {5647 if (operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
5647 const operand_id = try self.resolve(br.operand);5648 const operand_id = try self.resolve(br.operand);
5648 // current_block_label should not be undefined here, lest there5649 // current_block_label should not be undefined here, lest there
5649 // is a br or br_void in the function's body.5650 // is a br or br_void in the function's body.
...@@ -5770,35 +5771,35 @@ const NavGen = struct {...@@ -5770,35 +5771,35 @@ const NavGen = struct {
5770 }5771 }
57715772
5772 fn airLoad(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5773 fn airLoad(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5773 const mod = self.pt.zcu;5774 const zcu = self.pt.zcu;
5774 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5775 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5775 const ptr_ty = self.typeOf(ty_op.operand);5776 const ptr_ty = self.typeOf(ty_op.operand);
5776 const elem_ty = self.typeOfIndex(inst);5777 const elem_ty = self.typeOfIndex(inst);
5777 const operand = try self.resolve(ty_op.operand);5778 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) });
5781 }5782 }
57825783
5783 fn airStore(self: *NavGen, inst: Air.Inst.Index) !void {5784 fn airStore(self: *NavGen, inst: Air.Inst.Index) !void {
5784 const mod = self.pt.zcu;5785 const zcu = self.pt.zcu;
5785 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;5786 const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
5786 const ptr_ty = self.typeOf(bin_op.lhs);5787 const ptr_ty = self.typeOf(bin_op.lhs);
5787 const elem_ty = ptr_ty.childType(mod);5788 const elem_ty = ptr_ty.childType(zcu);
5788 const ptr = try self.resolve(bin_op.lhs);5789 const ptr = try self.resolve(bin_op.lhs);
5789 const value = try self.resolve(bin_op.rhs);5790 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) });
5792 }5793 }
57935794
5794 fn airRet(self: *NavGen, inst: Air.Inst.Index) !void {5795 fn airRet(self: *NavGen, inst: Air.Inst.Index) !void {
5795 const pt = self.pt;5796 const pt = self.pt;
5796 const mod = pt.zcu;5797 const zcu = pt.zcu;
5797 const operand = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5798 const operand = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5798 const ret_ty = self.typeOf(operand);5799 const ret_ty = self.typeOf(operand);
5799 if (!ret_ty.hasRuntimeBitsIgnoreComptime(pt)) {5800 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5800 const fn_info = mod.typeToFunc(mod.navValue(self.owner_nav).typeOf(mod)).?;5801 const fn_info = zcu.typeToFunc(zcu.navValue(self.owner_nav).typeOf(zcu)).?;
5801 if (Type.fromInterned(fn_info.return_type).isError(mod)) {5802 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
5802 // Functions with an empty error set are emitted with an error code5803 // Functions with an empty error set are emitted with an error code
5803 // return type and return zero so they can be function pointers coerced5804 // return type and return zero so they can be function pointers coerced
5804 // to functions that return anyerror.5805 // to functions that return anyerror.
...@@ -5815,14 +5816,14 @@ const NavGen = struct {...@@ -5815,14 +5816,14 @@ const NavGen = struct {
58155816
5816 fn airRetLoad(self: *NavGen, inst: Air.Inst.Index) !void {5817 fn airRetLoad(self: *NavGen, inst: Air.Inst.Index) !void {
5817 const pt = self.pt;5818 const pt = self.pt;
5818 const mod = pt.zcu;5819 const zcu = pt.zcu;
5819 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;5820 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
5820 const ptr_ty = self.typeOf(un_op);5821 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 if (!ret_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
5824 const fn_info = mod.typeToFunc(mod.navValue(self.owner_nav).typeOf(mod)).?;5825 const fn_info = zcu.typeToFunc(zcu.navValue(self.owner_nav).typeOf(zcu)).?;
5825 if (Type.fromInterned(fn_info.return_type).isError(mod)) {5826 if (Type.fromInterned(fn_info.return_type).isError(zcu)) {
5826 // Functions with an empty error set are emitted with an error code5827 // Functions with an empty error set are emitted with an error code
5827 // return type and return zero so they can be function pointers coerced5828 // return type and return zero so they can be function pointers coerced
5828 // to functions that return anyerror.5829 // to functions that return anyerror.
...@@ -5834,14 +5835,14 @@ const NavGen = struct {...@@ -5834,14 +5835,14 @@ const NavGen = struct {
5834 }5835 }
58355836
5836 const ptr = try self.resolve(un_op);5837 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) });
5838 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{5839 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{
5839 .value = value,5840 .value = value,
5840 });5841 });
5841 }5842 }
58425843
5843 fn airTry(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5844 fn airTry(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5844 const mod = self.pt.zcu;5845 const zcu = self.pt.zcu;
5845 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;5846 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
5846 const err_union_id = try self.resolve(pl_op.operand);5847 const err_union_id = try self.resolve(pl_op.operand);
5847 const extra = self.air.extraData(Air.Try, pl_op.payload);5848 const extra = self.air.extraData(Air.Try, pl_op.payload);
...@@ -5854,7 +5855,7 @@ const NavGen = struct {...@@ -5854,7 +5855,7 @@ const NavGen = struct {
58545855
5855 const eu_layout = self.errorUnionLayout(payload_ty);5856 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)) {
5858 const err_id = if (eu_layout.payload_has_bits)5859 const err_id = if (eu_layout.payload_has_bits)
5859 try self.extractField(Type.anyerror, err_union_id, eu_layout.errorFieldIndex())5860 try self.extractField(Type.anyerror, err_union_id, eu_layout.errorFieldIndex())
5860 else5861 else
...@@ -5911,18 +5912,18 @@ const NavGen = struct {...@@ -5911,18 +5912,18 @@ const NavGen = struct {
5911 }5912 }
59125913
5913 fn airErrUnionErr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5914 fn airErrUnionErr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5914 const mod = self.pt.zcu;5915 const zcu = self.pt.zcu;
5915 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5916 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5916 const operand_id = try self.resolve(ty_op.operand);5917 const operand_id = try self.resolve(ty_op.operand);
5917 const err_union_ty = self.typeOf(ty_op.operand);5918 const err_union_ty = self.typeOf(ty_op.operand);
5918 const err_ty_id = try self.resolveType(Type.anyerror, .direct);5919 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)) {
5921 // No error possible, so just return undefined.5922 // No error possible, so just return undefined.
5922 return try self.spv.constUndef(err_ty_id);5923 return try self.spv.constUndef(err_ty_id);
5923 }5924 }
59245925
5925 const payload_ty = err_union_ty.errorUnionPayload(mod);5926 const payload_ty = err_union_ty.errorUnionPayload(zcu);
5926 const eu_layout = self.errorUnionLayout(payload_ty);5927 const eu_layout = self.errorUnionLayout(payload_ty);
59275928
5928 if (!eu_layout.payload_has_bits) {5929 if (!eu_layout.payload_has_bits) {
...@@ -5947,10 +5948,10 @@ const NavGen = struct {...@@ -5947,10 +5948,10 @@ const NavGen = struct {
5947 }5948 }
59485949
5949 fn airWrapErrUnionErr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {5950 fn airWrapErrUnionErr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
5950 const mod = self.pt.zcu;5951 const zcu = self.pt.zcu;
5951 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;5952 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
5952 const err_union_ty = self.typeOfIndex(inst);5953 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);
5954 const operand_id = try self.resolve(ty_op.operand);5955 const operand_id = try self.resolve(ty_op.operand);
5955 const eu_layout = self.errorUnionLayout(payload_ty);5956 const eu_layout = self.errorUnionLayout(payload_ty);
59565957
...@@ -5995,28 +5996,28 @@ const NavGen = struct {...@@ -5995,28 +5996,28 @@ const NavGen = struct {
59955996
5996 fn airIsNull(self: *NavGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum { is_null, is_non_null }) !?IdRef {5997 fn airIsNull(self: *NavGen, inst: Air.Inst.Index, is_pointer: bool, pred: enum { is_null, is_non_null }) !?IdRef {
5997 const pt = self.pt;5998 const pt = self.pt;
5998 const mod = pt.zcu;5999 const zcu = pt.zcu;
5999 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;6000 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6000 const operand_id = try self.resolve(un_op);6001 const operand_id = try self.resolve(un_op);
6001 const operand_ty = self.typeOf(un_op);6002 const operand_ty = self.typeOf(un_op);
6002 const optional_ty = if (is_pointer) operand_ty.childType(mod) else operand_ty;6003 const optional_ty = if (is_pointer) operand_ty.childType(zcu) else operand_ty;
6003 const payload_ty = optional_ty.optionalChild(mod);6004 const payload_ty = optional_ty.optionalChild(zcu);
60046005
6005 const bool_ty_id = try self.resolveType(Type.bool, .direct);6006 const bool_ty_id = try self.resolveType(Type.bool, .direct);
60066007
6007 if (optional_ty.optionalReprIsPayload(mod)) {6008 if (optional_ty.optionalReprIsPayload(zcu)) {
6008 // Pointer payload represents nullability: pointer or slice.6009 // Pointer payload represents nullability: pointer or slice.
6009 const loaded_id = if (is_pointer)6010 const loaded_id = if (is_pointer)
6010 try self.load(optional_ty, operand_id, .{})6011 try self.load(optional_ty, operand_id, .{})
6011 else6012 else
6012 operand_id;6013 operand_id;
60136014
6014 const ptr_ty = if (payload_ty.isSlice(mod))6015 const ptr_ty = if (payload_ty.isSlice(zcu))
6015 payload_ty.slicePtrFieldType(mod)6016 payload_ty.slicePtrFieldType(zcu)
6016 else6017 else
6017 payload_ty;6018 payload_ty;
60186019
6019 const ptr_id = if (payload_ty.isSlice(mod))6020 const ptr_id = if (payload_ty.isSlice(zcu))
6020 try self.extractField(ptr_ty, loaded_id, 0)6021 try self.extractField(ptr_ty, loaded_id, 0)
6021 else6022 else
6022 loaded_id;6023 loaded_id;
...@@ -6036,8 +6037,8 @@ const NavGen = struct {...@@ -6036,8 +6037,8 @@ const NavGen = struct {
60366037
6037 const is_non_null_id = blk: {6038 const is_non_null_id = blk: {
6038 if (is_pointer) {6039 if (is_pointer) {
6039 if (payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {6040 if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6040 const storage_class = self.spvStorageClass(operand_ty.ptrAddressSpace(mod));6041 const storage_class = self.spvStorageClass(operand_ty.ptrAddressSpace(zcu));
6041 const bool_ptr_ty_id = try self.ptrType(Type.bool, storage_class);6042 const bool_ptr_ty_id = try self.ptrType(Type.bool, storage_class);
6042 const tag_ptr_id = try self.accessChain(bool_ptr_ty_id, operand_id, &.{1});6043 const tag_ptr_id = try self.accessChain(bool_ptr_ty_id, operand_id, &.{1});
6043 break :blk try self.load(Type.bool, tag_ptr_id, .{});6044 break :blk try self.load(Type.bool, tag_ptr_id, .{});
...@@ -6046,7 +6047,7 @@ const NavGen = struct {...@@ -6046,7 +6047,7 @@ const NavGen = struct {
6046 break :blk try self.load(Type.bool, operand_id, .{});6047 break :blk try self.load(Type.bool, operand_id, .{});
6047 }6048 }
60486049
6049 break :blk if (payload_ty.hasRuntimeBitsIgnoreComptime(pt))6050 break :blk if (payload_ty.hasRuntimeBitsIgnoreComptime(zcu))
6050 try self.extractField(Type.bool, operand_id, 1)6051 try self.extractField(Type.bool, operand_id, 1)
6051 else6052 else
6052 // Optional representation is bool indicating whether the optional is set6053 // Optional representation is bool indicating whether the optional is set
...@@ -6071,16 +6072,16 @@ const NavGen = struct {...@@ -6071,16 +6072,16 @@ const NavGen = struct {
6071 }6072 }
60726073
6073 fn airIsErr(self: *NavGen, inst: Air.Inst.Index, pred: enum { is_err, is_non_err }) !?IdRef {6074 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;
6075 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;6076 const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
6076 const operand_id = try self.resolve(un_op);6077 const operand_id = try self.resolve(un_op);
6077 const err_union_ty = self.typeOf(un_op);6078 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)) {
6080 return try self.constBool(pred == .is_non_err, .direct);6081 return try self.constBool(pred == .is_non_err, .direct);
6081 }6082 }
60826083
6083 const payload_ty = err_union_ty.errorUnionPayload(mod);6084 const payload_ty = err_union_ty.errorUnionPayload(zcu);
6084 const eu_layout = self.errorUnionLayout(payload_ty);6085 const eu_layout = self.errorUnionLayout(payload_ty);
6085 const bool_ty_id = try self.resolveType(Type.bool, .direct);6086 const bool_ty_id = try self.resolveType(Type.bool, .direct);
60866087
...@@ -6105,15 +6106,15 @@ const NavGen = struct {...@@ -6105,15 +6106,15 @@ const NavGen = struct {
61056106
6106 fn airUnwrapOptional(self: *NavGen, inst: Air.Inst.Index) !?IdRef {6107 fn airUnwrapOptional(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
6107 const pt = self.pt;6108 const pt = self.pt;
6108 const mod = pt.zcu;6109 const zcu = pt.zcu;
6109 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6110 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6110 const operand_id = try self.resolve(ty_op.operand);6111 const operand_id = try self.resolve(ty_op.operand);
6111 const optional_ty = self.typeOf(ty_op.operand);6112 const optional_ty = self.typeOf(ty_op.operand);
6112 const payload_ty = self.typeOfIndex(inst);6113 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)) {
6117 return operand_id;6118 return operand_id;
6118 }6119 }
61196120
...@@ -6122,22 +6123,22 @@ const NavGen = struct {...@@ -6122,22 +6123,22 @@ const NavGen = struct {
61226123
6123 fn airUnwrapOptionalPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {6124 fn airUnwrapOptionalPtr(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
6124 const pt = self.pt;6125 const pt = self.pt;
6125 const mod = pt.zcu;6126 const zcu = pt.zcu;
6126 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6127 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6127 const operand_id = try self.resolve(ty_op.operand);6128 const operand_id = try self.resolve(ty_op.operand);
6128 const operand_ty = self.typeOf(ty_op.operand);6129 const operand_ty = self.typeOf(ty_op.operand);
6129 const optional_ty = operand_ty.childType(mod);6130 const optional_ty = operand_ty.childType(zcu);
6130 const payload_ty = optional_ty.optionalChild(mod);6131 const payload_ty = optional_ty.optionalChild(zcu);
6131 const result_ty = self.typeOfIndex(inst);6132 const result_ty = self.typeOfIndex(inst);
6132 const result_ty_id = try self.resolveType(result_ty, .direct);6133 const result_ty_id = try self.resolveType(result_ty, .direct);
61336134
6134 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {6135 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6135 // There is no payload, but we still need to return a valid pointer.6136 // There is no payload, but we still need to return a valid pointer.
6136 // We can just return anything here, so just return a pointer to the operand.6137 // We can just return anything here, so just return a pointer to the operand.
6137 return try self.bitCast(result_ty, operand_ty, operand_id);6138 return try self.bitCast(result_ty, operand_ty, operand_id);
6138 }6139 }
61396140
6140 if (optional_ty.optionalReprIsPayload(mod)) {6141 if (optional_ty.optionalReprIsPayload(zcu)) {
6141 // They are the same value.6142 // They are the same value.
6142 return try self.bitCast(result_ty, operand_ty, operand_id);6143 return try self.bitCast(result_ty, operand_ty, operand_id);
6143 }6144 }
...@@ -6147,18 +6148,18 @@ const NavGen = struct {...@@ -6147,18 +6148,18 @@ const NavGen = struct {
61476148
6148 fn airWrapOptional(self: *NavGen, inst: Air.Inst.Index) !?IdRef {6149 fn airWrapOptional(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
6149 const pt = self.pt;6150 const pt = self.pt;
6150 const mod = pt.zcu;6151 const zcu = pt.zcu;
6151 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;6152 const ty_op = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
6152 const payload_ty = self.typeOf(ty_op.operand);6153 const payload_ty = self.typeOf(ty_op.operand);
61536154
6154 if (!payload_ty.hasRuntimeBitsIgnoreComptime(pt)) {6155 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
6155 return try self.constBool(true, .indirect);6156 return try self.constBool(true, .indirect);
6156 }6157 }
61576158
6158 const operand_id = try self.resolve(ty_op.operand);6159 const operand_id = try self.resolve(ty_op.operand);
61596160
6160 const optional_ty = self.typeOfIndex(inst);6161 const optional_ty = self.typeOfIndex(inst);
6161 if (optional_ty.optionalReprIsPayload(mod)) {6162 if (optional_ty.optionalReprIsPayload(zcu)) {
6162 return operand_id;6163 return operand_id;
6163 }6164 }
61646165
...@@ -6170,7 +6171,7 @@ const NavGen = struct {...@@ -6170,7 +6171,7 @@ const NavGen = struct {
61706171
6171 fn airSwitchBr(self: *NavGen, inst: Air.Inst.Index) !void {6172 fn airSwitchBr(self: *NavGen, inst: Air.Inst.Index) !void {
6172 const pt = self.pt;6173 const pt = self.pt;
6173 const mod = pt.zcu;6174 const zcu = pt.zcu;
6174 const target = self.getTarget();6175 const target = self.getTarget();
6175 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;6176 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6176 const cond_ty = self.typeOf(pl_op.operand);6177 const cond_ty = self.typeOf(pl_op.operand);
...@@ -6178,18 +6179,18 @@ const NavGen = struct {...@@ -6178,18 +6179,18 @@ const NavGen = struct {
6178 var cond_indirect = try self.convertToIndirect(cond_ty, cond);6179 var cond_indirect = try self.convertToIndirect(cond_ty, cond);
6179 const switch_br = self.air.extraData(Air.SwitchBr, pl_op.payload);6180 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)) {
6182 .Bool, .ErrorSet => 1,6183 .Bool, .ErrorSet => 1,
6183 .Int => blk: {6184 .Int => blk: {
6184 const bits = cond_ty.intInfo(mod).bits;6185 const bits = cond_ty.intInfo(zcu).bits;
6185 const backing_bits = self.backingIntBits(bits) orelse {6186 const backing_bits = self.backingIntBits(bits) orelse {
6186 return self.todo("implement composite int switch", .{});6187 return self.todo("implement composite int switch", .{});
6187 };6188 };
6188 break :blk if (backing_bits <= 32) 1 else 2;6189 break :blk if (backing_bits <= 32) 1 else 2;
6189 },6190 },
6190 .Enum => blk: {6191 .Enum => blk: {
6191 const int_ty = cond_ty.intTagType(mod);6192 const int_ty = cond_ty.intTagType(zcu);
6192 const int_info = int_ty.intInfo(mod);6193 const int_info = int_ty.intInfo(zcu);
6193 const backing_bits = self.backingIntBits(int_info.bits) orelse {6194 const backing_bits = self.backingIntBits(int_info.bits) orelse {
6194 return self.todo("implement composite int switch", .{});6195 return self.todo("implement composite int switch", .{});
6195 };6196 };
...@@ -6200,7 +6201,7 @@ const NavGen = struct {...@@ -6200,7 +6201,7 @@ const NavGen = struct {
6200 break :blk target.ptrBitWidth() / 32;6201 break :blk target.ptrBitWidth() / 32;
6201 },6202 },
6202 // TODO: Figure out which types apply here, and work around them as we can only do integers.6203 // 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))}),
6204 };6205 };
62056206
6206 const num_cases = switch_br.data.cases_len;6207 const num_cases = switch_br.data.cases_len;
...@@ -6255,14 +6256,14 @@ const NavGen = struct {...@@ -6255,14 +6256,14 @@ const NavGen = struct {
62556256
6256 for (items) |item| {6257 for (items) |item| {
6257 const value = (try self.air.value(item, pt)) orelse unreachable;6258 const value = (try self.air.value(item, pt)) orelse unreachable;
6258 const int_val: u64 = switch (cond_ty.zigTypeTag(mod)) {6259 const int_val: u64 = switch (cond_ty.zigTypeTag(zcu)) {
6259 .Bool, .Int => if (cond_ty.isSignedInt(mod)) @bitCast(value.toSignedInt(pt)) else value.toUnsignedInt(pt),6260 .Bool, .Int => if (cond_ty.isSignedInt(zcu)) @bitCast(value.toSignedInt(zcu)) else value.toUnsignedInt(zcu),
6260 .Enum => blk: {6261 .Enum => blk: {
6261 // TODO: figure out of cond_ty is correct (something with enum literals)6262 // 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 constants6263 break :blk (try value.intFromEnum(cond_ty, pt)).toUnsignedInt(zcu); // TODO: composite integer constants
6263 },6264 },
6264 .ErrorSet => value.getErrorInt(mod),6265 .ErrorSet => value.getErrorInt(zcu),
6265 .Pointer => value.toUnsignedInt(pt),6266 .Pointer => value.toUnsignedInt(zcu),
6266 else => unreachable,6267 else => unreachable,
6267 };6268 };
6268 const int_lit: spec.LiteralContextDependentNumber = switch (cond_words) {6269 const int_lit: spec.LiteralContextDependentNumber = switch (cond_words) {
...@@ -6343,9 +6344,9 @@ const NavGen = struct {...@@ -6343,9 +6344,9 @@ const NavGen = struct {
63436344
6344 fn airDbgStmt(self: *NavGen, inst: Air.Inst.Index) !void {6345 fn airDbgStmt(self: *NavGen, inst: Air.Inst.Index) !void {
6345 const pt = self.pt;6346 const pt = self.pt;
6346 const mod = pt.zcu;6347 const zcu = pt.zcu;
6347 const dbg_stmt = self.air.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt;6348 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;
6349 try self.func.body.emit(self.spv.gpa, .OpLine, .{6350 try self.func.body.emit(self.spv.gpa, .OpLine, .{
6350 .file = try self.spv.resolveString(path),6351 .file = try self.spv.resolveString(path),
6351 .line = self.base_line + dbg_stmt.line + 1,6352 .line = self.base_line + dbg_stmt.line + 1,
...@@ -6354,12 +6355,12 @@ const NavGen = struct {...@@ -6354,12 +6355,12 @@ const NavGen = struct {
6354 }6355 }
63556356
6356 fn airDbgInlineBlock(self: *NavGen, inst: Air.Inst.Index) !?IdRef {6357 fn airDbgInlineBlock(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
6357 const mod = self.pt.zcu;6358 const zcu = self.pt.zcu;
6358 const inst_datas = self.air.instructions.items(.data);6359 const inst_datas = self.air.instructions.items(.data);
6359 const extra = self.air.extraData(Air.DbgInlineBlock, inst_datas[@intFromEnum(inst)].ty_pl.payload);6360 const extra = self.air.extraData(Air.DbgInlineBlock, inst_datas[@intFromEnum(inst)].ty_pl.payload);
6360 const old_base_line = self.base_line;6361 const old_base_line = self.base_line;
6361 defer self.base_line = old_base_line;6362 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);
6363 return self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));6364 return self.lowerBlock(inst, @ptrCast(self.air.extra[extra.end..][0..extra.data.body_len]));
6364 }6365 }
63656366
...@@ -6371,7 +6372,7 @@ const NavGen = struct {...@@ -6371,7 +6372,7 @@ const NavGen = struct {
6371 }6372 }
63726373
6373 fn airAssembly(self: *NavGen, inst: Air.Inst.Index) !?IdRef {6374 fn airAssembly(self: *NavGen, inst: Air.Inst.Index) !?IdRef {
6374 const mod = self.pt.zcu;6375 const zcu = self.pt.zcu;
6375 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;6376 const ty_pl = self.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
6376 const extra = self.air.extraData(Air.Asm, ty_pl.payload);6377 const extra = self.air.extraData(Air.Asm, ty_pl.payload);
63776378
...@@ -6453,20 +6454,20 @@ const NavGen = struct {...@@ -6453,20 +6454,20 @@ const NavGen = struct {
6453 // TODO: Translate proper error locations.6454 // TODO: Translate proper error locations.
6454 assert(as.errors.items.len != 0);6455 assert(as.errors.items.len != 0);
6455 assert(self.error_msg == null);6456 assert(self.error_msg == null);
6456 const src_loc = mod.navSrcLoc(self.owner_nav);6457 const src_loc = zcu.navSrcLoc(self.owner_nav);
6457 self.error_msg = try Zcu.ErrorMsg.create(mod.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});6458 self.error_msg = try Zcu.ErrorMsg.create(zcu.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
6458 const notes = try mod.gpa.alloc(Zcu.ErrorMsg, as.errors.items.len);6459 const notes = try zcu.gpa.alloc(Zcu.ErrorMsg, as.errors.items.len);
64596460
6460 // Sub-scope to prevent `return error.CodegenFail` from running the errdefers.6461 // Sub-scope to prevent `return error.CodegenFail` from running the errdefers.
6461 {6462 {
6462 errdefer mod.gpa.free(notes);6463 errdefer zcu.gpa.free(notes);
6463 var i: usize = 0;6464 var i: usize = 0;
6464 errdefer for (notes[0..i]) |*note| {6465 errdefer for (notes[0..i]) |*note| {
6465 note.deinit(mod.gpa);6466 note.deinit(zcu.gpa);
6466 };6467 };
64676468
6468 while (i < as.errors.items.len) : (i += 1) {6469 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});
6470 }6471 }
6471 }6472 }
6472 self.error_msg.?.notes = notes;6473 self.error_msg.?.notes = notes;
...@@ -6503,17 +6504,17 @@ const NavGen = struct {...@@ -6503,17 +6504,17 @@ const NavGen = struct {
6503 _ = modifier;6504 _ = modifier;
65046505
6505 const pt = self.pt;6506 const pt = self.pt;
6506 const mod = pt.zcu;6507 const zcu = pt.zcu;
6507 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;6508 const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
6508 const extra = self.air.extraData(Air.Call, pl_op.payload);6509 const extra = self.air.extraData(Air.Call, pl_op.payload);
6509 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);6510 const args: []const Air.Inst.Ref = @ptrCast(self.air.extra[extra.end..][0..extra.data.args_len]);
6510 const callee_ty = self.typeOf(pl_op.operand);6511 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)) {
6512 .Fn => callee_ty,6513 .Fn => callee_ty,
6513 .Pointer => return self.fail("cannot call function pointers", .{}),6514 .Pointer => return self.fail("cannot call function pointers", .{}),
6514 else => unreachable,6515 else => unreachable,
6515 };6516 };
6516 const fn_info = mod.typeToFunc(zig_fn_ty).?;6517 const fn_info = zcu.typeToFunc(zig_fn_ty).?;
6517 const return_type = fn_info.return_type;6518 const return_type = fn_info.return_type;
65186519
6519 const result_type_id = try self.resolveFnReturnType(Type.fromInterned(return_type));6520 const result_type_id = try self.resolveFnReturnType(Type.fromInterned(return_type));
...@@ -6529,7 +6530,7 @@ const NavGen = struct {...@@ -6529,7 +6530,7 @@ const NavGen = struct {
6529 // before starting to emit OpFunctionCall instructions. Hence the6530 // before starting to emit OpFunctionCall instructions. Hence the
6530 // temporary params buffer.6531 // temporary params buffer.
6531 const arg_ty = self.typeOf(arg);6532 const arg_ty = self.typeOf(arg);
6532 if (!arg_ty.hasRuntimeBitsIgnoreComptime(pt)) continue;6533 if (!arg_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
6533 const arg_id = try self.resolve(arg);6534 const arg_id = try self.resolve(arg);
65346535
6535 params[n_params] = arg_id;6536 params[n_params] = arg_id;
...@@ -6547,7 +6548,7 @@ const NavGen = struct {...@@ -6547,7 +6548,7 @@ const NavGen = struct {
6547 try self.func.body.emit(self.spv.gpa, .OpUnreachable, {});6548 try self.func.body.emit(self.spv.gpa, .OpUnreachable, {});
6548 }6549 }
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)) {
6551 return null;6552 return null;
6552 }6553 }
65536554
...@@ -6604,12 +6605,12 @@ const NavGen = struct {...@@ -6604,12 +6605,12 @@ const NavGen = struct {
6604 }6605 }
66056606
6606 fn typeOf(self: *NavGen, inst: Air.Inst.Ref) Type {6607 fn typeOf(self: *NavGen, inst: Air.Inst.Ref) Type {
6607 const mod = self.pt.zcu;6608 const zcu = self.pt.zcu;
6608 return self.air.typeOf(inst, &mod.intern_pool);6609 return self.air.typeOf(inst, &zcu.intern_pool);
6609 }6610 }
66106611
6611 fn typeOfIndex(self: *NavGen, inst: Air.Inst.Index) Type {6612 fn typeOfIndex(self: *NavGen, inst: Air.Inst.Index) Type {
6612 const mod = self.pt.zcu;6613 const zcu = self.pt.zcu;
6613 return self.air.typeOfIndex(inst, &mod.intern_pool);6614 return self.air.typeOfIndex(inst, &zcu.intern_pool);
6614 }6615 }
6615};6616};
src/link.zig+1-1
...@@ -755,7 +755,7 @@ pub const File = struct {...@@ -755,7 +755,7 @@ pub const File = struct {
755 const directory = base.emit.root_dir; // Just an alias to make it shorter to type.755 const directory = base.emit.root_dir; // Just an alias to make it shorter to type.
756 const full_out_path = try directory.join(arena, &[_][]const u8{base.emit.sub_path});756 const full_out_path = try directory.join(arena, &[_][]const u8{base.emit.sub_path});
757 const full_out_path_z = try arena.dupeZ(u8, full_out_path);757 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
760 // If there is no Zig code to compile, then we should skip flushing the output file760 // If there is no Zig code to compile, then we should skip flushing the output file
761 // because it will not be part of the linker line anyway.761 // 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) !...@@ -327,7 +327,7 @@ pub fn updateNav(self: *C, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !
327 .variable => |variable| variable.init,327 .variable => |variable| variable.init,
328 else => nav.status.resolved.val,328 else => nav.status.resolved.val,
329 };329 };
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
332 const gop = try self.navs.getOrPut(gpa, nav_index);332 const gop = try self.navs.getOrPut(gpa, nav_index);
333 errdefer _ = self.navs.pop();333 errdefer _ = self.navs.pop();
...@@ -418,7 +418,7 @@ pub fn flushModule(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:...@@ -418,7 +418,7 @@ pub fn flushModule(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
418418
419 const comp = self.base.comp;419 const comp = self.base.comp;
420 const gpa = comp.gpa;420 const gpa = comp.gpa;
421 const zcu = self.base.comp.module.?;421 const zcu = self.base.comp.zcu.?;
422 const ip = &zcu.intern_pool;422 const ip = &zcu.intern_pool;
423 const pt: Zcu.PerThread = .{ .zcu = zcu, .tid = tid };423 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,...@@ -1141,7 +1141,7 @@ pub fn updateFunc(self: *Coff, pt: Zcu.PerThread, func_index: InternPool.Index,
11411141
1142const LowerConstResult = union(enum) {1142const LowerConstResult = union(enum) {
1143 ok: Atom.Index,1143 ok: Atom.Index,
1144 fail: *Module.ErrorMsg,1144 fail: *Zcu.ErrorMsg,
1145};1145};
11461146
1147fn lowerConst(1147fn lowerConst(
...@@ -1151,7 +1151,7 @@ fn lowerConst(...@@ -1151,7 +1151,7 @@ fn lowerConst(
1151 val: Value,1151 val: Value,
1152 required_alignment: InternPool.Alignment,1152 required_alignment: InternPool.Alignment,
1153 sect_id: u16,1153 sect_id: u16,
1154 src_loc: Module.LazySrcLoc,1154 src_loc: Zcu.LazySrcLoc,
1155) !LowerConstResult {1155) !LowerConstResult {
1156 const gpa = self.base.comp.gpa;1156 const gpa = self.base.comp.gpa;
11571157
...@@ -1221,7 +1221,7 @@ pub fn updateNav(...@@ -1221,7 +1221,7 @@ pub fn updateNav(
1221 else => nav_val,1221 else => nav_val,
1222 };1222 };
12231223
1224 if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {1224 if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
1225 const atom_index = try self.getOrCreateAtomForNav(nav_index);1225 const atom_index = try self.getOrCreateAtomForNav(nav_index);
1226 Atom.freeRelocations(self, atom_index);1226 Atom.freeRelocations(self, atom_index);
1227 const atom = self.getAtom(atom_index);1227 const atom = self.getAtom(atom_index);
...@@ -1259,8 +1259,8 @@ fn updateLazySymbolAtom(...@@ -1259,8 +1259,8 @@ fn updateLazySymbolAtom(
1259 atom_index: Atom.Index,1259 atom_index: Atom.Index,
1260 section_index: u16,1260 section_index: u16,
1261) !void {1261) !void {
1262 const mod = pt.zcu;1262 const zcu = pt.zcu;
1263 const gpa = mod.gpa;1263 const gpa = zcu.gpa;
12641264
1265 var required_alignment: InternPool.Alignment = .none;1265 var required_alignment: InternPool.Alignment = .none;
1266 var code_buffer = std.ArrayList(u8).init(gpa);1266 var code_buffer = std.ArrayList(u8).init(gpa);
...@@ -1275,7 +1275,7 @@ fn updateLazySymbolAtom(...@@ -1275,7 +1275,7 @@ fn updateLazySymbolAtom(
1275 const atom = self.getAtomPtr(atom_index);1275 const atom = self.getAtomPtr(atom_index);
1276 const local_sym_index = atom.getSymbolIndex().?;1276 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;
1279 const res = try codegen.generateLazySymbol(1279 const res = try codegen.generateLazySymbol(
1280 &self.base,1280 &self.base,
1281 pt,1281 pt,
...@@ -1354,7 +1354,7 @@ pub fn getOrCreateAtomForNav(self: *Coff, nav_index: InternPool.Nav.Index) !Atom...@@ -1354,7 +1354,7 @@ pub fn getOrCreateAtomForNav(self: *Coff, nav_index: InternPool.Nav.Index) !Atom
1354}1354}
13551355
1356fn getNavOutputSection(self: *Coff, nav_index: InternPool.Nav.Index) u16 {1356fn getNavOutputSection(self: *Coff, nav_index: InternPool.Nav.Index) u16 {
1357 const zcu = self.base.comp.module.?;1357 const zcu = self.base.comp.zcu.?;
1358 const ip = &zcu.intern_pool;1358 const ip = &zcu.intern_pool;
1359 const nav = ip.getNav(nav_index);1359 const nav = ip.getNav(nav_index);
1360 const ty = Type.fromInterned(nav.typeOf(ip));1360 const ty = Type.fromInterned(nav.typeOf(ip));
...@@ -1462,15 +1462,15 @@ pub fn freeNav(self: *Coff, nav_index: InternPool.NavIndex) void {...@@ -1462,15 +1462,15 @@ pub fn freeNav(self: *Coff, nav_index: InternPool.NavIndex) void {
1462pub fn updateExports(1462pub fn updateExports(
1463 self: *Coff,1463 self: *Coff,
1464 pt: Zcu.PerThread,1464 pt: Zcu.PerThread,
1465 exported: Module.Exported,1465 exported: Zcu.Exported,
1466 export_indices: []const u32,1466 export_indices: []const u32,
1467) link.File.UpdateExportsError!void {1467) link.File.UpdateExportsError!void {
1468 if (build_options.skip_non_native and builtin.object_format != .coff) {1468 if (build_options.skip_non_native and builtin.object_format != .coff) {
1469 @panic("Attempted to compile for object format that was disabled by build configuration");1469 @panic("Attempted to compile for object format that was disabled by build configuration");
1470 }1470 }
14711471
1472 const mod = pt.zcu;1472 const zcu = pt.zcu;
1473 const ip = &mod.intern_pool;1473 const ip = &zcu.intern_pool;
1474 const comp = self.base.comp;1474 const comp = self.base.comp;
1475 const target = comp.root_mod.resolved_target.result;1475 const target = comp.root_mod.resolved_target.result;
14761476
...@@ -1478,7 +1478,7 @@ pub fn updateExports(...@@ -1478,7 +1478,7 @@ pub fn updateExports(
1478 // Even in the case of LLVM, we need to notice certain exported symbols in order to1478 // Even in the case of LLVM, we need to notice certain exported symbols in order to
1479 // detect the default subsystem.1479 // detect the default subsystem.
1480 for (export_indices) |export_idx| {1480 for (export_indices) |export_idx| {
1481 const exp = mod.all_exports.items[export_idx];1481 const exp = zcu.all_exports.items[export_idx];
1482 const exported_nav_index = switch (exp.exported) {1482 const exported_nav_index = switch (exp.exported) {
1483 .nav => |nav| nav,1483 .nav => |nav| nav,
1484 .uav => continue,1484 .uav => continue,
...@@ -1490,20 +1490,20 @@ pub fn updateExports(...@@ -1490,20 +1490,20 @@ pub fn updateExports(
1490 .x86 => .Stdcall,1490 .x86 => .Stdcall,
1491 else => .C,1491 else => .C,
1492 };1492 };
1493 const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(mod);1493 const exported_cc = Type.fromInterned(exported_ty).fnCallingConvention(zcu);
1494 if (exported_cc == .C and exp.opts.name.eqlSlice("main", ip) and comp.config.link_libc) {1494 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;
1496 } else if (exported_cc == winapi_cc and target.os.tag == .windows) {1496 } else if (exported_cc == winapi_cc and target.os.tag == .windows) {
1497 if (exp.opts.name.eqlSlice("WinMain", ip)) {1497 if (exp.opts.name.eqlSlice("WinMain", ip)) {
1498 mod.stage1_flags.have_winmain = true;1498 zcu.stage1_flags.have_winmain = true;
1499 } else if (exp.opts.name.eqlSlice("wWinMain", ip)) {1499 } else if (exp.opts.name.eqlSlice("wWinMain", ip)) {
1500 mod.stage1_flags.have_wwinmain = true;1500 zcu.stage1_flags.have_wwinmain = true;
1501 } else if (exp.opts.name.eqlSlice("WinMainCRTStartup", ip)) {1501 } 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;
1503 } else if (exp.opts.name.eqlSlice("wWinMainCRTStartup", ip)) {1503 } 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;
1505 } else if (exp.opts.name.eqlSlice("DllMainCRTStartup", ip)) {1505 } 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;
1507 }1507 }
1508 }1508 }
1509 }1509 }
...@@ -1519,15 +1519,15 @@ pub fn updateExports(...@@ -1519,15 +1519,15 @@ pub fn updateExports(
1519 break :blk self.navs.getPtr(nav).?;1519 break :blk self.navs.getPtr(nav).?;
1520 },1520 },
1521 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {1521 .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]];
1523 const res = try self.lowerUav(pt, uav, .none, first_exp.src);1523 const res = try self.lowerUav(pt, uav, .none, first_exp.src);
1524 switch (res) {1524 switch (res) {
1525 .mcv => {},1525 .mcv => {},
1526 .fail => |em| {1526 .fail => |em| {
1527 // TODO maybe it's enough to return an error here and let Module.processExportsInner1527 // TODO maybe it's enough to return an error here and let Module.processExportsInner
1528 // handle the error?1528 // handle the error?
1529 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1529 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1530 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);1530 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1531 return;1531 return;
1532 },1532 },
1533 }1533 }
...@@ -1538,12 +1538,12 @@ pub fn updateExports(...@@ -1538,12 +1538,12 @@ pub fn updateExports(
1538 const atom = self.getAtom(atom_index);1538 const atom = self.getAtom(atom_index);
15391539
1540 for (export_indices) |export_idx| {1540 for (export_indices) |export_idx| {
1541 const exp = mod.all_exports.items[export_idx];1541 const exp = zcu.all_exports.items[export_idx];
1542 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)});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| {
1545 if (!mem.eql(u8, section_name, ".text")) {1545 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(
1547 gpa,1547 gpa,
1548 exp.src,1548 exp.src,
1549 "Unimplemented: ExportOptions.section",1549 "Unimplemented: ExportOptions.section",
...@@ -1554,7 +1554,7 @@ pub fn updateExports(...@@ -1554,7 +1554,7 @@ pub fn updateExports(
1554 }1554 }
15551555
1556 if (exp.opts.linkage == .link_once) {1556 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(
1558 gpa,1558 gpa,
1559 exp.src,1559 exp.src,
1560 "Unimplemented: GlobalLinkage.link_once",1560 "Unimplemented: GlobalLinkage.link_once",
...@@ -1563,7 +1563,7 @@ pub fn updateExports(...@@ -1563,7 +1563,7 @@ pub fn updateExports(
1563 continue;1563 continue;
1564 }1564 }
15651565
1566 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);1566 const exp_name = exp.opts.name.toSlice(&zcu.intern_pool);
1567 const sym_index = metadata.getExport(self, exp_name) orelse blk: {1567 const sym_index = metadata.getExport(self, exp_name) orelse blk: {
1568 const sym_index = if (self.getGlobalIndex(exp_name)) |global_index| ind: {1568 const sym_index = if (self.getGlobalIndex(exp_name)) |global_index| ind: {
1569 const global = self.globals.items[global_index];1569 const global = self.globals.items[global_index];
...@@ -1609,14 +1609,14 @@ pub fn deleteExport(...@@ -1609,14 +1609,14 @@ pub fn deleteExport(
1609 .nav => |nav| self.navs.getPtr(nav),1609 .nav => |nav| self.navs.getPtr(nav),
1610 .uav => |uav| self.uavs.getPtr(uav),1610 .uav => |uav| self.uavs.getPtr(uav),
1611 } orelse return;1611 } orelse return;
1612 const mod = self.base.comp.module.?;1612 const zcu = self.base.comp.zcu.?;
1613 const name_slice = name.toSlice(&mod.intern_pool);1613 const name_slice = name.toSlice(&zcu.intern_pool);
1614 const sym_index = metadata.getExportPtr(self, name_slice) orelse return;1614 const sym_index = metadata.getExportPtr(self, name_slice) orelse return;
16151615
1616 const gpa = self.base.comp.gpa;1616 const gpa = self.base.comp.gpa;
1617 const sym_loc = SymbolWithLoc{ .sym_index = sym_index.*, .file = null };1617 const sym_loc = SymbolWithLoc{ .sym_index = sym_index.*, .file = null };
1618 const sym = self.getSymbolPtr(sym_loc);1618 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)});
1620 assert(sym.storage_class == .EXTERNAL and sym.section_number != .UNDEFINED);1620 assert(sym.storage_class == .EXTERNAL and sym.section_number != .UNDEFINED);
1621 sym.* = .{1621 sym.* = .{
1622 .name = [_]u8{0} ** 8,1622 .name = [_]u8{0} ** 8,
...@@ -1691,7 +1691,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no...@@ -1691,7 +1691,7 @@ pub fn flushModule(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
1691 defer sub_prog_node.end();1691 defer sub_prog_node.end();
16921692
1693 const pt: Zcu.PerThread = .{1693 const pt: Zcu.PerThread = .{
1694 .zcu = comp.module orelse return error.LinkingWithoutZigSourceUnimplemented,1694 .zcu = comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
1695 .tid = tid,1695 .tid = tid,
1696 };1696 };
16971697
...@@ -1843,13 +1843,13 @@ pub fn lowerUav(...@@ -1843,13 +1843,13 @@ pub fn lowerUav(
1843 pt: Zcu.PerThread,1843 pt: Zcu.PerThread,
1844 uav: InternPool.Index,1844 uav: InternPool.Index,
1845 explicit_alignment: InternPool.Alignment,1845 explicit_alignment: InternPool.Alignment,
1846 src_loc: Module.LazySrcLoc,1846 src_loc: Zcu.LazySrcLoc,
1847) !codegen.GenResult {1847) !codegen.GenResult {
1848 const zcu = pt.zcu;1848 const zcu = pt.zcu;
1849 const gpa = zcu.gpa;1849 const gpa = zcu.gpa;
1850 const val = Value.fromInterned(uav);1850 const val = Value.fromInterned(uav);
1851 const uav_alignment = switch (explicit_alignment) {1851 const uav_alignment = switch (explicit_alignment) {
1852 .none => val.typeOf(zcu).abiAlignment(pt),1852 .none => val.typeOf(zcu).abiAlignment(zcu),
1853 else => explicit_alignment,1853 else => explicit_alignment,
1854 };1854 };
1855 if (self.uavs.get(uav)) |metadata| {1855 if (self.uavs.get(uav)) |metadata| {
...@@ -1872,7 +1872,7 @@ pub fn lowerUav(...@@ -1872,7 +1872,7 @@ pub fn lowerUav(
1872 src_loc,1872 src_loc,
1873 ) catch |err| switch (err) {1873 ) catch |err| switch (err) {
1874 error.OutOfMemory => return error.OutOfMemory,1874 error.OutOfMemory => return error.OutOfMemory,
1875 else => |e| return .{ .fail = try Module.ErrorMsg.create(1875 else => |e| return .{ .fail = try Zcu.ErrorMsg.create(
1876 gpa,1876 gpa,
1877 src_loc,1877 src_loc,
1878 "lowerAnonDecl failed with error: {s}",1878 "lowerAnonDecl failed with error: {s}",
...@@ -2730,8 +2730,6 @@ const ImportTable = @import("Coff/ImportTable.zig");...@@ -2730,8 +2730,6 @@ const ImportTable = @import("Coff/ImportTable.zig");
2730const Liveness = @import("../Liveness.zig");2730const Liveness = @import("../Liveness.zig");
2731const LlvmObject = @import("../codegen/llvm.zig").Object;2731const LlvmObject = @import("../codegen/llvm.zig").Object;
2732const Zcu = @import("../Zcu.zig");2732const Zcu = @import("../Zcu.zig");
2733/// Deprecated.
2734const Module = Zcu;
2735const InternPool = @import("../InternPool.zig");2733const InternPool = @import("../InternPool.zig");
2736const Object = @import("Coff/Object.zig");2734const Object = @import("Coff/Object.zig");
2737const Relocation = @import("Coff/Relocation.zig");2735const 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...@@ -32,7 +32,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
3232
33 // If there is no Zig code to compile, then we should skip flushing the output file because it33 // If there is no Zig code to compile, then we should skip flushing the output file because it
34 // will not be part of the linker line anyway.34 // 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: {
36 try self.flushModule(arena, tid, prog_node);36 try self.flushModule(arena, tid, prog_node);
3737
38 if (fs.path.dirname(full_out_path)) |dirname| {38 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...@@ -296,7 +296,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
296 if (self.subsystem) |explicit| break :blk explicit;296 if (self.subsystem) |explicit| break :blk explicit;
297 switch (target.os.tag) {297 switch (target.os.tag) {
298 .windows => {298 .windows => {
299 if (comp.module) |module| {299 if (comp.zcu) |module| {
300 if (module.stage1_flags.have_dllmain_crt_startup or is_dyn_lib)300 if (module.stage1_flags.have_dllmain_crt_startup or is_dyn_lib)
301 break :blk null;301 break :blk null;
302 if (module.stage1_flags.have_c_main or comp.config.is_test or302 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...@@ -440,7 +440,7 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
440 } else {440 } else {
441 try argv.append("-NODEFAULTLIB");441 try argv.append("-NODEFAULTLIB");
442 if (!is_lib and entry_name == null) {442 if (!is_lib and entry_name == null) {
443 if (comp.module) |module| {443 if (comp.zcu) |module| {
444 if (module.stage1_flags.have_winmain_crt_startup) {444 if (module.stage1_flags.have_winmain_crt_startup) {
445 try argv.append("-ENTRY:WinMainCRTStartup");445 try argv.append("-ENTRY:WinMainCRTStartup");
446 } else {446 } else {
src/link/Dwarf.zig+43-43
...@@ -780,7 +780,7 @@ const Entry = struct {...@@ -780,7 +780,7 @@ const Entry = struct {
780 else780 else
781 "?", 0),781 "?", 0),
782 });782 });
783 const zcu = dwarf.bin_file.comp.module.?;783 const zcu = dwarf.bin_file.comp.zcu.?;
784 const ip = &zcu.intern_pool;784 const ip = &zcu.intern_pool;
785 for (dwarf.types.keys(), dwarf.types.values()) |ty, other_entry| {785 for (dwarf.types.keys(), dwarf.types.values()) |ty, other_entry| {
786 const ty_unit: Unit.Index = if (Type.fromInterned(ty).typeDeclInst(zcu)) |inst_index|786 const ty_unit: Unit.Index = if (Type.fromInterned(ty).typeDeclInst(zcu)) |inst_index|
...@@ -1429,7 +1429,7 @@ pub const WipNav = struct {...@@ -1429,7 +1429,7 @@ pub const WipNav = struct {
1429 }1429 }
1430 } else {1430 } else {
1431 try wip_nav.abbrevCode(abbrev_code.block);1431 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);
1433 try uleb128(diw, bytes);1433 try uleb128(diw, bytes);
1434 big_int.writeTwosComplement(try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)), wip_nav.dwarf.endian);1434 big_int.writeTwosComplement(try wip_nav.debug_info.addManyAsSlice(wip_nav.dwarf.gpa, @intCast(bytes)), wip_nav.dwarf.endian);
1435 }1435 }
...@@ -1770,7 +1770,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -1770,7 +1770,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
1770 const ty_reloc_index = try wip_nav.refForward();1770 const ty_reloc_index = try wip_nav.refForward();
1771 try wip_nav.exprloc(.{ .addr = .{ .sym = sym_index } });1771 try wip_nav.exprloc(.{ .addr = .{ .sym = sym_index } });
1772 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse1772 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
1773 ty.abiAlignment(pt).toByteUnits().?);1773 ty.abiAlignment(zcu).toByteUnits().?);
1774 try diw.writeByte(@intFromBool(false));1774 try diw.writeByte(@intFromBool(false));
1775 wip_nav.finishForward(ty_reloc_index);1775 wip_nav.finishForward(ty_reloc_index);
1776 try wip_nav.abbrevCode(.is_const);1776 try wip_nav.abbrevCode(.is_const);
...@@ -1821,7 +1821,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In...@@ -1821,7 +1821,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In
1821 const addr: Loc = .{ .addr = .{ .sym = sym_index } };1821 const addr: Loc = .{ .addr = .{ .sym = sym_index } };
1822 try wip_nav.exprloc(if (variable.is_threadlocal) .{ .form_tls_address = &addr } else addr);1822 try wip_nav.exprloc(if (variable.is_threadlocal) .{ .form_tls_address = &addr } else addr);
1823 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse1823 try uleb128(diw, nav.status.resolved.alignment.toByteUnits() orelse
1824 ty.abiAlignment(pt).toByteUnits().?);1824 ty.abiAlignment(zcu).toByteUnits().?);
1825 try diw.writeByte(@intFromBool(false));1825 try diw.writeByte(@intFromBool(false));
1826 },1826 },
1827 .func => |func| {1827 .func => |func| {
...@@ -2158,8 +2158,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2158,8 +2158,8 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2158 try diw.writeByte(accessibility);2158 try diw.writeByte(accessibility);
2159 try wip_nav.strp(nav.name.toSlice(ip));2159 try wip_nav.strp(nav.name.toSlice(ip));
2160 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {2160 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
2161 try uleb128(diw, nav_val.toType().abiSize(pt));2161 try uleb128(diw, nav_val.toType().abiSize(zcu));
2162 try uleb128(diw, nav_val.toType().abiAlignment(pt).toByteUnits().?);2162 try uleb128(diw, nav_val.toType().abiAlignment(zcu).toByteUnits().?);
2163 for (0..loaded_struct.field_types.len) |field_index| {2163 for (0..loaded_struct.field_types.len) |field_index| {
2164 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);2164 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
2165 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);2165 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...@@ -2173,7 +2173,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2173 if (!is_comptime) {2173 if (!is_comptime) {
2174 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);2174 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
2175 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse2175 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2176 field_type.abiAlignment(pt).toByteUnits().?);2176 field_type.abiAlignment(zcu).toByteUnits().?);
2177 }2177 }
2178 }2178 }
2179 try uleb128(diw, @intFromEnum(AbbrevCode.null));2179 try uleb128(diw, @intFromEnum(AbbrevCode.null));
...@@ -2195,7 +2195,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2195,7 +2195,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2195 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);2195 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
2196 try wip_nav.refType(field_type);2196 try wip_nav.refType(field_type);
2197 try uleb128(diw, field_bit_offset);2197 try uleb128(diw, field_bit_offset);
2198 field_bit_offset += @intCast(field_type.bitSize(pt));2198 field_bit_offset += @intCast(field_type.bitSize(zcu));
2199 }2199 }
2200 try uleb128(diw, @intFromEnum(AbbrevCode.null));2200 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2201 },2201 },
...@@ -2360,7 +2360,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2360,7 +2360,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2360 try uleb128(diw, loc.column + 1);2360 try uleb128(diw, loc.column + 1);
2361 try diw.writeByte(accessibility);2361 try diw.writeByte(accessibility);
2362 try wip_nav.strp(nav.name.toSlice(ip));2362 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);
2364 try uleb128(diw, union_layout.abi_size);2364 try uleb128(diw, union_layout.abi_size);
2365 try uleb128(diw, union_layout.abi_align.toByteUnits().?);2365 try uleb128(diw, union_layout.abi_align.toByteUnits().?);
2366 const loaded_tag = loaded_union.loadTagType(ip);2366 const loaded_tag = loaded_union.loadTagType(ip);
...@@ -2391,7 +2391,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2391,7 +2391,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2391 try wip_nav.refType(field_type);2391 try wip_nav.refType(field_type);
2392 try uleb128(diw, union_layout.payloadOffset());2392 try uleb128(diw, union_layout.payloadOffset());
2393 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse2393 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().?);
2395 }2395 }
2396 try uleb128(diw, @intFromEnum(AbbrevCode.null));2396 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2397 }2397 }
...@@ -2406,7 +2406,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool...@@ -2406,7 +2406,7 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool
2406 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);2406 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
2407 try wip_nav.refType(field_type);2407 try wip_nav.refType(field_type);
2408 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse2408 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
2409 field_type.abiAlignment(pt).toByteUnits().?);2409 field_type.abiAlignment(zcu).toByteUnits().?);
2410 }2410 }
2411 try uleb128(diw, @intFromEnum(AbbrevCode.null));2411 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2412 break :done;2412 break :done;
...@@ -2560,8 +2560,8 @@ fn updateType(...@@ -2560,8 +2560,8 @@ fn updateType(
2560 inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)),2560 inline .signed, .unsigned => |signedness| @field(DW.ATE, @tagName(signedness)),
2561 });2561 });
2562 try uleb128(diw, int_type.bits);2562 try uleb128(diw, int_type.bits);
2563 try uleb128(diw, ty.abiSize(pt));2563 try uleb128(diw, ty.abiSize(zcu));
2564 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);2564 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
2565 },2565 },
2566 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {2566 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
2567 .One, .Many, .C => {2567 .One, .Many, .C => {
...@@ -2569,7 +2569,7 @@ fn updateType(...@@ -2569,7 +2569,7 @@ fn updateType(
2569 try wip_nav.abbrevCode(.ptr_type);2569 try wip_nav.abbrevCode(.ptr_type);
2570 try wip_nav.strp(name);2570 try wip_nav.strp(name);
2571 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse2571 try uleb128(diw, ptr_type.flags.alignment.toByteUnits() orelse
2572 ptr_child_type.abiAlignment(pt).toByteUnits().?);2572 ptr_child_type.abiAlignment(zcu).toByteUnits().?);
2573 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));2573 try diw.writeByte(@intFromEnum(ptr_type.flags.address_space));
2574 if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset(2574 if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try wip_nav.infoSectionOffset(
2575 .debug_info,2575 .debug_info,
...@@ -2594,8 +2594,8 @@ fn updateType(...@@ -2594,8 +2594,8 @@ fn updateType(
2594 .Slice => {2594 .Slice => {
2595 try wip_nav.abbrevCode(.struct_type);2595 try wip_nav.abbrevCode(.struct_type);
2596 try wip_nav.strp(name);2596 try wip_nav.strp(name);
2597 try uleb128(diw, ty.abiSize(pt));2597 try uleb128(diw, ty.abiSize(zcu));
2598 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);2598 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
2599 try wip_nav.abbrevCode(.generated_field);2599 try wip_nav.abbrevCode(.generated_field);
2600 try wip_nav.strp("ptr");2600 try wip_nav.strp("ptr");
2601 const ptr_field_type = ty.slicePtrFieldType(zcu);2601 const ptr_field_type = ty.slicePtrFieldType(zcu);
...@@ -2605,7 +2605,7 @@ fn updateType(...@@ -2605,7 +2605,7 @@ fn updateType(
2605 try wip_nav.strp("len");2605 try wip_nav.strp("len");
2606 const len_field_type = Type.usize;2606 const len_field_type = Type.usize;
2607 try wip_nav.refType(len_field_type);2607 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)));
2609 try uleb128(diw, @intFromEnum(AbbrevCode.null));2609 try uleb128(diw, @intFromEnum(AbbrevCode.null));
2610 },2610 },
2611 },2611 },
...@@ -2623,8 +2623,8 @@ fn updateType(...@@ -2623,8 +2623,8 @@ fn updateType(
2623 const opt_child_type = Type.fromInterned(opt_child_type_index);2623 const opt_child_type = Type.fromInterned(opt_child_type_index);
2624 try wip_nav.abbrevCode(.union_type);2624 try wip_nav.abbrevCode(.union_type);
2625 try wip_nav.strp(name);2625 try wip_nav.strp(name);
2626 try uleb128(diw, ty.abiSize(pt));2626 try uleb128(diw, ty.abiSize(zcu));
2627 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);2627 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
2628 if (opt_child_type.isNoReturn(zcu)) {2628 if (opt_child_type.isNoReturn(zcu)) {
2629 try wip_nav.abbrevCode(.generated_field);2629 try wip_nav.abbrevCode(.generated_field);
2630 try wip_nav.strp("null");2630 try wip_nav.strp("null");
...@@ -2652,8 +2652,8 @@ fn updateType(...@@ -2652,8 +2652,8 @@ fn updateType(
2652 switch (repr) {2652 switch (repr) {
2653 .unpacked => {2653 .unpacked => {
2654 try wip_nav.refType(Type.bool);2654 try wip_nav.refType(Type.bool);
2655 try uleb128(diw, if (opt_child_type.hasRuntimeBits(pt))2655 try uleb128(diw, if (opt_child_type.hasRuntimeBits(zcu))
2656 opt_child_type.abiSize(pt)2656 opt_child_type.abiSize(zcu)
2657 else2657 else
2658 0);2658 0);
2659 },2659 },
...@@ -2700,8 +2700,8 @@ fn updateType(...@@ -2700,8 +2700,8 @@ fn updateType(
2700 const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) {2700 const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) {
2701 .generic_poison_type => .{ 0, 0 },2701 .generic_poison_type => .{ 0, 0 },
2702 else => .{2702 else => .{
2703 codegen.errUnionErrorOffset(error_union_payload_type, pt),2703 codegen.errUnionErrorOffset(error_union_payload_type, zcu),
2704 codegen.errUnionPayloadOffset(error_union_payload_type, pt),2704 codegen.errUnionPayloadOffset(error_union_payload_type, zcu),
2705 },2705 },
2706 };2706 };
27072707
...@@ -2710,8 +2710,8 @@ fn updateType(...@@ -2710,8 +2710,8 @@ fn updateType(
2710 if (error_union_type.error_set_type != .generic_poison_type and2710 if (error_union_type.error_set_type != .generic_poison_type and
2711 error_union_type.payload_type != .generic_poison_type)2711 error_union_type.payload_type != .generic_poison_type)
2712 {2712 {
2713 try uleb128(diw, ty.abiSize(pt));2713 try uleb128(diw, ty.abiSize(zcu));
2714 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);2714 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
2715 } else {2715 } else {
2716 try uleb128(diw, 0);2716 try uleb128(diw, 0);
2717 try uleb128(diw, 1);2717 try uleb128(diw, 1);
...@@ -2788,9 +2788,9 @@ fn updateType(...@@ -2788,9 +2788,9 @@ fn updateType(
2788 DW.ATE.unsigned2788 DW.ATE.unsigned
2789 else2789 else
2790 unreachable);2790 unreachable);
2791 try uleb128(diw, ty.bitSize(pt));2791 try uleb128(diw, ty.bitSize(zcu));
2792 try uleb128(diw, ty.abiSize(pt));2792 try uleb128(diw, ty.abiSize(zcu));
2793 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);2793 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
2794 },2794 },
2795 .anyopaque,2795 .anyopaque,
2796 .void,2796 .void,
...@@ -2820,8 +2820,8 @@ fn updateType(...@@ -2820,8 +2820,8 @@ fn updateType(
2820 } else {2820 } else {
2821 try wip_nav.abbrevCode(.struct_type);2821 try wip_nav.abbrevCode(.struct_type);
2822 try wip_nav.strp(name);2822 try wip_nav.strp(name);
2823 try uleb128(diw, ty.abiSize(pt));2823 try uleb128(diw, ty.abiSize(zcu));
2824 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);2824 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
2825 var field_byte_offset: u64 = 0;2825 var field_byte_offset: u64 = 0;
2826 for (0..anon_struct_type.types.len) |field_index| {2826 for (0..anon_struct_type.types.len) |field_index| {
2827 const comptime_value = anon_struct_type.values.get(ip)[field_index];2827 const comptime_value = anon_struct_type.values.get(ip)[field_index];
...@@ -2834,11 +2834,11 @@ fn updateType(...@@ -2834,11 +2834,11 @@ fn updateType(
2834 const field_type = Type.fromInterned(anon_struct_type.types.get(ip)[field_index]);2834 const field_type = Type.fromInterned(anon_struct_type.types.get(ip)[field_index]);
2835 try wip_nav.refType(field_type);2835 try wip_nav.refType(field_type);
2836 if (comptime_value == .none) {2836 if (comptime_value == .none) {
2837 const field_align = field_type.abiAlignment(pt);2837 const field_align = field_type.abiAlignment(zcu);
2838 field_byte_offset = field_align.forward(field_byte_offset);2838 field_byte_offset = field_align.forward(field_byte_offset);
2839 try uleb128(diw, field_byte_offset);2839 try uleb128(diw, field_byte_offset);
2840 try uleb128(diw, field_type.abiAlignment(pt).toByteUnits().?);2840 try uleb128(diw, field_type.abiAlignment(zcu).toByteUnits().?);
2841 field_byte_offset += field_type.abiSize(pt);2841 field_byte_offset += field_type.abiSize(zcu);
2842 }2842 }
2843 }2843 }
2844 try uleb128(diw, @intFromEnum(AbbrevCode.null));2844 try uleb128(diw, @intFromEnum(AbbrevCode.null));
...@@ -2976,8 +2976,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -2976,8 +2976,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
2976 try uleb128(diw, file_gop.index);2976 try uleb128(diw, file_gop.index);
2977 try wip_nav.strp(loaded_struct.name.toSlice(ip));2977 try wip_nav.strp(loaded_struct.name.toSlice(ip));
2978 if (loaded_struct.field_types.len > 0) {2978 if (loaded_struct.field_types.len > 0) {
2979 try uleb128(diw, ty.abiSize(pt));2979 try uleb128(diw, ty.abiSize(zcu));
2980 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);2980 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
2981 for (0..loaded_struct.field_types.len) |field_index| {2981 for (0..loaded_struct.field_types.len) |field_index| {
2982 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);2982 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
2983 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);2983 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...@@ -2991,7 +2991,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
2991 if (!is_comptime) {2991 if (!is_comptime) {
2992 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);2992 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
2993 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse2993 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
2994 field_type.abiAlignment(pt).toByteUnits().?);2994 field_type.abiAlignment(zcu).toByteUnits().?);
2995 }2995 }
2996 }2996 }
2997 try uleb128(diw, @intFromEnum(AbbrevCode.null));2997 try uleb128(diw, @intFromEnum(AbbrevCode.null));
...@@ -3042,8 +3042,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3042,8 +3042,8 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3042 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_struct_type else .struct_type);3042 try wip_nav.abbrevCode(if (loaded_struct.field_types.len == 0) .namespace_struct_type else .struct_type);
3043 try wip_nav.strp(name);3043 try wip_nav.strp(name);
3044 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {3044 if (loaded_struct.field_types.len == 0) try diw.writeByte(@intFromBool(false)) else {
3045 try uleb128(diw, ty.abiSize(pt));3045 try uleb128(diw, ty.abiSize(zcu));
3046 try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?);3046 try uleb128(diw, ty.abiAlignment(zcu).toByteUnits().?);
3047 for (0..loaded_struct.field_types.len) |field_index| {3047 for (0..loaded_struct.field_types.len) |field_index| {
3048 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);3048 const is_comptime = loaded_struct.fieldIsComptime(ip, field_index);
3049 try wip_nav.abbrevCode(if (is_comptime) .struct_field_comptime else .struct_field);3049 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...@@ -3057,7 +3057,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3057 if (!is_comptime) {3057 if (!is_comptime) {
3058 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);3058 try uleb128(diw, loaded_struct.offsets.get(ip)[field_index]);
3059 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse3059 try uleb128(diw, loaded_struct.fieldAlign(ip, field_index).toByteUnits() orelse
3060 field_type.abiAlignment(pt).toByteUnits().?);3060 field_type.abiAlignment(zcu).toByteUnits().?);
3061 }3061 }
3062 }3062 }
3063 try uleb128(diw, @intFromEnum(AbbrevCode.null));3063 try uleb128(diw, @intFromEnum(AbbrevCode.null));
...@@ -3074,7 +3074,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3074,7 +3074,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3074 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);3074 const field_type = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
3075 try wip_nav.refType(field_type);3075 try wip_nav.refType(field_type);
3076 try uleb128(diw, field_bit_offset);3076 try uleb128(diw, field_bit_offset);
3077 field_bit_offset += @intCast(field_type.bitSize(pt));3077 field_bit_offset += @intCast(field_type.bitSize(zcu));
3078 }3078 }
3079 if (loaded_struct.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));3079 if (loaded_struct.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
3080 },3080 },
...@@ -3099,7 +3099,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3099,7 +3099,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3099 const loaded_union = ip.loadUnionType(type_index);3099 const loaded_union = ip.loadUnionType(type_index);
3100 try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type);3100 try wip_nav.abbrevCode(if (loaded_union.field_types.len > 0) .union_type else .empty_union_type);
3101 try wip_nav.strp(name);3101 try wip_nav.strp(name);
3102 const union_layout = pt.getUnionLayout(loaded_union);3102 const union_layout = Type.getUnionLayout(loaded_union, zcu);
3103 try uleb128(diw, union_layout.abi_size);3103 try uleb128(diw, union_layout.abi_size);
3104 try uleb128(diw, union_layout.abi_align.toByteUnits().?);3104 try uleb128(diw, union_layout.abi_align.toByteUnits().?);
3105 const loaded_tag = loaded_union.loadTagType(ip);3105 const loaded_tag = loaded_union.loadTagType(ip);
...@@ -3130,7 +3130,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3130,7 +3130,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3130 try wip_nav.refType(field_type);3130 try wip_nav.refType(field_type);
3131 try uleb128(diw, union_layout.payloadOffset());3131 try uleb128(diw, union_layout.payloadOffset());
3132 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse3132 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().?);
3134 }3134 }
3135 try uleb128(diw, @intFromEnum(AbbrevCode.null));3135 try uleb128(diw, @intFromEnum(AbbrevCode.null));
3136 }3136 }
...@@ -3145,7 +3145,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP...@@ -3145,7 +3145,7 @@ pub fn updateContainerType(dwarf: *Dwarf, pt: Zcu.PerThread, type_index: InternP
3145 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);3145 const field_type = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
3146 try wip_nav.refType(field_type);3146 try wip_nav.refType(field_type);
3147 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse3147 try uleb128(diw, loaded_union.fieldAlign(ip, field_index).toByteUnits() orelse
3148 field_type.abiAlignment(pt).toByteUnits().?);3148 field_type.abiAlignment(zcu).toByteUnits().?);
3149 }3149 }
3150 if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));3150 if (loaded_union.field_types.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null));
3151 },3151 },
src/link/Elf.zig+2-2
...@@ -212,7 +212,7 @@ pub fn createEmpty(...@@ -212,7 +212,7 @@ pub fn createEmpty(
212212
213 const use_lld = build_options.have_llvm and comp.config.use_lld;213 const use_lld = build_options.have_llvm and comp.config.use_lld;
214 const use_llvm = comp.config.use_llvm;214 const use_llvm = comp.config.use_llvm;
215 const opt_zcu = comp.module;215 const opt_zcu = comp.zcu;
216 const output_mode = comp.config.output_mode;216 const output_mode = comp.config.output_mode;
217 const link_mode = comp.config.link_mode;217 const link_mode = comp.config.link_mode;
218 const optimize_mode = comp.root_mod.optimize_mode;218 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...@@ -2084,7 +2084,7 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
20842084
2085 // If there is no Zig code to compile, then we should skip flushing the output file because it2085 // If there is no Zig code to compile, then we should skip flushing the output file because it
2086 // will not be part of the linker line anyway.2086 // 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: {
2088 try self.flushModule(arena, tid, prog_node);2088 try self.flushModule(arena, tid, prog_node);
20892089
2090 if (fs.path.dirname(full_out_path)) |dirname| {2090 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 {...@@ -128,7 +128,7 @@ pub fn deinit(self: *ZigObject, allocator: Allocator) void {
128pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {128pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
129 // Handle any lazy symbols that were emitted by incremental compilation.129 // Handle any lazy symbols that were emitted by incremental compilation.
130 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {130 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
133 // Most lazy symbols can be updated on first use, but133 // Most lazy symbols can be updated on first use, but
134 // anyerror needs to wait for everything to be flushed.134 // 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...@@ -157,7 +157,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
157 }157 }
158158
159 if (build_options.enable_logging) {159 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 };
161 for (self.navs.keys(), self.navs.values()) |nav_index, meta| {161 for (self.navs.keys(), self.navs.values()) |nav_index, meta| {
162 checkNavAllocated(pt, nav_index, meta);162 checkNavAllocated(pt, nav_index, meta);
163 }163 }
...@@ -167,7 +167,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi...@@ -167,7 +167,7 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi
167 }167 }
168168
169 if (self.dwarf) |*dwarf| {169 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 };
171 try dwarf.flushModule(pt);171 try dwarf.flushModule(pt);
172172
173 const gpa = elf_file.base.comp.gpa;173 const gpa = elf_file.base.comp.gpa;
...@@ -849,7 +849,7 @@ pub fn lowerUav(...@@ -849,7 +849,7 @@ pub fn lowerUav(
849 const gpa = zcu.gpa;849 const gpa = zcu.gpa;
850 const val = Value.fromInterned(uav);850 const val = Value.fromInterned(uav);
851 const uav_alignment = switch (explicit_alignment) {851 const uav_alignment = switch (explicit_alignment) {
852 .none => val.typeOf(zcu).abiAlignment(pt),852 .none => val.typeOf(zcu).abiAlignment(zcu),
853 else => explicit_alignment,853 else => explicit_alignment,
854 };854 };
855 if (self.uavs.get(uav)) |metadata| {855 if (self.uavs.get(uav)) |metadata| {
...@@ -949,7 +949,7 @@ pub fn getOrCreateMetadataForNav(...@@ -949,7 +949,7 @@ pub fn getOrCreateMetadataForNav(
949 if (!gop.found_existing) {949 if (!gop.found_existing) {
950 const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;950 const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;
951 const symbol_index = try self.newSymbolWithAtom(gpa, 0);951 const symbol_index = try self.newSymbolWithAtom(gpa, 0);
952 const zcu = elf_file.base.comp.module.?;952 const zcu = elf_file.base.comp.zcu.?;
953 const nav_val = Value.fromInterned(zcu.intern_pool.getNav(nav_index).status.resolved.val);953 const nav_val = Value.fromInterned(zcu.intern_pool.getNav(nav_index).status.resolved.val);
954 const sym = self.symbol(symbol_index);954 const sym = self.symbol(symbol_index);
955 if (nav_val.getVariable(zcu)) |variable| {955 if (nav_val.getVariable(zcu)) |variable| {
...@@ -1306,7 +1306,7 @@ pub fn updateNav(...@@ -1306,7 +1306,7 @@ pub fn updateNav(
1306 else => nav.status.resolved.val,1306 else => nav.status.resolved.val,
1307 };1307 };
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)) {
1310 const sym_index = try self.getOrCreateMetadataForNav(elf_file, nav_index);1310 const sym_index = try self.getOrCreateMetadataForNav(elf_file, nav_index);
1311 self.symbol(sym_index).atom(elf_file).?.freeRelocs(self);1311 self.symbol(sym_index).atom(elf_file).?.freeRelocs(self);
13121312
...@@ -1382,8 +1382,8 @@ fn updateLazySymbol(...@@ -1382,8 +1382,8 @@ fn updateLazySymbol(
1382 sym: link.File.LazySymbol,1382 sym: link.File.LazySymbol,
1383 symbol_index: Symbol.Index,1383 symbol_index: Symbol.Index,
1384) !void {1384) !void {
1385 const mod = pt.zcu;1385 const zcu = pt.zcu;
1386 const gpa = mod.gpa;1386 const gpa = zcu.gpa;
13871387
1388 var required_alignment: InternPool.Alignment = .none;1388 var required_alignment: InternPool.Alignment = .none;
1389 var code_buffer = std.ArrayList(u8).init(gpa);1389 var code_buffer = std.ArrayList(u8).init(gpa);
...@@ -1398,7 +1398,7 @@ fn updateLazySymbol(...@@ -1398,7 +1398,7 @@ fn updateLazySymbol(
1398 break :blk try self.strtab.insert(gpa, name);1398 break :blk try self.strtab.insert(gpa, name);
1399 };1399 };
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;
1402 const res = try codegen.generateLazySymbol(1402 const res = try codegen.generateLazySymbol(
1403 &elf_file.base,1403 &elf_file.base,
1404 pt,1404 pt,
...@@ -1513,7 +1513,7 @@ pub fn updateExports(...@@ -1513,7 +1513,7 @@ pub fn updateExports(
1513 const tracy = trace(@src());1513 const tracy = trace(@src());
1514 defer tracy.end();1514 defer tracy.end();
15151515
1516 const mod = pt.zcu;1516 const zcu = pt.zcu;
1517 const gpa = elf_file.base.comp.gpa;1517 const gpa = elf_file.base.comp.gpa;
1518 const metadata = switch (exported) {1518 const metadata = switch (exported) {
1519 .nav => |nav| blk: {1519 .nav => |nav| blk: {
...@@ -1521,15 +1521,15 @@ pub fn updateExports(...@@ -1521,15 +1521,15 @@ pub fn updateExports(
1521 break :blk self.navs.getPtr(nav).?;1521 break :blk self.navs.getPtr(nav).?;
1522 },1522 },
1523 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {1523 .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]];
1525 const res = try self.lowerUav(elf_file, pt, uav, .none, first_exp.src);1525 const res = try self.lowerUav(elf_file, pt, uav, .none, first_exp.src);
1526 switch (res) {1526 switch (res) {
1527 .mcv => {},1527 .mcv => {},
1528 .fail => |em| {1528 .fail => |em| {
1529 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner1529 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner
1530 // handle the error?1530 // handle the error?
1531 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1531 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1532 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);1532 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1533 return;1533 return;
1534 },1534 },
1535 }1535 }
...@@ -1542,11 +1542,11 @@ pub fn updateExports(...@@ -1542,11 +1542,11 @@ pub fn updateExports(
1542 const esym_shndx = self.symtab.items(.shndx)[esym_index];1542 const esym_shndx = self.symtab.items(.shndx)[esym_index];
15431543
1544 for (export_indices) |export_idx| {1544 for (export_indices) |export_idx| {
1545 const exp = mod.all_exports.items[export_idx];1545 const exp = zcu.all_exports.items[export_idx];
1546 if (exp.opts.section.unwrap()) |section_name| {1546 if (exp.opts.section.unwrap()) |section_name| {
1547 if (!section_name.eqlSlice(".text", &mod.intern_pool)) {1547 if (!section_name.eqlSlice(".text", &zcu.intern_pool)) {
1548 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1548 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1549 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(1549 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1550 gpa,1550 gpa,
1551 exp.src,1551 exp.src,
1552 "Unimplemented: ExportOptions.section",1552 "Unimplemented: ExportOptions.section",
...@@ -1560,8 +1560,8 @@ pub fn updateExports(...@@ -1560,8 +1560,8 @@ pub fn updateExports(
1560 .strong => elf.STB_GLOBAL,1560 .strong => elf.STB_GLOBAL,
1561 .weak => elf.STB_WEAK,1561 .weak => elf.STB_WEAK,
1562 .link_once => {1562 .link_once => {
1563 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1563 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1564 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(1564 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1565 gpa,1565 gpa,
1566 exp.src,1566 exp.src,
1567 "Unimplemented: GlobalLinkage.LinkOnce",1567 "Unimplemented: GlobalLinkage.LinkOnce",
...@@ -1571,7 +1571,7 @@ pub fn updateExports(...@@ -1571,7 +1571,7 @@ pub fn updateExports(
1571 },1571 },
1572 };1572 };
1573 const stt_bits: u8 = @as(u4, @truncate(esym.st_info));1573 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);
1575 const name_off = try self.strtab.insert(gpa, exp_name);1575 const name_off = try self.strtab.insert(gpa, exp_name);
1576 const global_sym_index = if (metadata.@"export"(self, exp_name)) |exp_index|1576 const global_sym_index = if (metadata.@"export"(self, exp_name)) |exp_index|
1577 exp_index.*1577 exp_index.*
...@@ -1626,8 +1626,8 @@ pub fn deleteExport(...@@ -1626,8 +1626,8 @@ pub fn deleteExport(
1626 .nav => |nav| self.navs.getPtr(nav),1626 .nav => |nav| self.navs.getPtr(nav),
1627 .uav => |uav| self.uavs.getPtr(uav),1627 .uav => |uav| self.uavs.getPtr(uav),
1628 } orelse return;1628 } orelse return;
1629 const mod = elf_file.base.comp.module.?;1629 const zcu = elf_file.base.comp.zcu.?;
1630 const exp_name = name.toSlice(&mod.intern_pool);1630 const exp_name = name.toSlice(&zcu.intern_pool);
1631 const esym_index = metadata.@"export"(self, exp_name) orelse return;1631 const esym_index = metadata.@"export"(self, exp_name) orelse return;
1632 log.debug("deleting export '{s}'", .{exp_name});1632 log.debug("deleting export '{s}'", .{exp_name});
1633 const esym = &self.symtab.items(.elf_sym)[esym_index.*];1633 const esym = &self.symtab.items(.elf_sym)[esym_index.*];
src/link/MachO.zig+3-5
...@@ -164,7 +164,7 @@ pub fn createEmpty(...@@ -164,7 +164,7 @@ pub fn createEmpty(
164164
165 const gpa = comp.gpa;165 const gpa = comp.gpa;
166 const use_llvm = comp.config.use_llvm;166 const use_llvm = comp.config.use_llvm;
167 const opt_zcu = comp.module;167 const opt_zcu = comp.zcu;
168 const optimize_mode = comp.root_mod.optimize_mode;168 const optimize_mode = comp.root_mod.optimize_mode;
169 const output_mode = comp.config.output_mode;169 const output_mode = comp.config.output_mode;
170 const link_mode = comp.config.link_mode;170 const link_mode = comp.config.link_mode;
...@@ -3026,7 +3026,7 @@ pub fn updateNavLineNumber(self: *MachO, pt: Zcu.PerThread, nav: InternPool.NavI...@@ -3026,7 +3026,7 @@ pub fn updateNavLineNumber(self: *MachO, pt: Zcu.PerThread, nav: InternPool.NavI
3026pub fn updateExports(3026pub fn updateExports(
3027 self: *MachO,3027 self: *MachO,
3028 pt: Zcu.PerThread,3028 pt: Zcu.PerThread,
3029 exported: Module.Exported,3029 exported: Zcu.Exported,
3030 export_indices: []const u32,3030 export_indices: []const u32,
3031) link.File.UpdateExportsError!void {3031) link.File.UpdateExportsError!void {
3032 if (build_options.skip_non_native and builtin.object_format != .macho) {3032 if (build_options.skip_non_native and builtin.object_format != .macho) {
...@@ -3060,7 +3060,7 @@ pub fn lowerUav(...@@ -3060,7 +3060,7 @@ pub fn lowerUav(
3060 pt: Zcu.PerThread,3060 pt: Zcu.PerThread,
3061 uav: InternPool.Index,3061 uav: InternPool.Index,
3062 explicit_alignment: InternPool.Alignment,3062 explicit_alignment: InternPool.Alignment,
3063 src_loc: Module.LazySrcLoc,3063 src_loc: Zcu.LazySrcLoc,
3064) !codegen.GenResult {3064) !codegen.GenResult {
3065 return self.getZigObject().?.lowerUav(self, pt, uav, explicit_alignment, src_loc);3065 return self.getZigObject().?.lowerUav(self, pt, uav, explicit_alignment, src_loc);
3066}3066}
...@@ -4634,8 +4634,6 @@ const Liveness = @import("../Liveness.zig");...@@ -4634,8 +4634,6 @@ const Liveness = @import("../Liveness.zig");
4634const LlvmObject = @import("../codegen/llvm.zig").Object;4634const LlvmObject = @import("../codegen/llvm.zig").Object;
4635const Md5 = std.crypto.hash.Md5;4635const Md5 = std.crypto.hash.Md5;
4636const Zcu = @import("../Zcu.zig");4636const Zcu = @import("../Zcu.zig");
4637/// Deprecated.
4638const Module = Zcu;
4639const InternPool = @import("../InternPool.zig");4637const InternPool = @import("../InternPool.zig");
4640const Rebase = @import("MachO/dyld_info/Rebase.zig");4638const Rebase = @import("MachO/dyld_info/Rebase.zig");
4641pub const Relocation = @import("MachO/Relocation.zig");4639pub 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...@@ -566,7 +566,7 @@ pub fn getInputSection(self: ZigObject, atom: Atom, macho_file: *MachO) macho.se
566pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) !void {566pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id) !void {
567 // Handle any lazy symbols that were emitted by incremental compilation.567 // Handle any lazy symbols that were emitted by incremental compilation.
568 if (self.lazy_syms.getPtr(.anyerror_type)) |metadata| {568 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
571 // Most lazy symbols can be updated on first use, but571 // Most lazy symbols can be updated on first use, but
572 // anyerror needs to wait for everything to be flushed.572 // 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)...@@ -595,7 +595,7 @@ pub fn flushModule(self: *ZigObject, macho_file: *MachO, tid: Zcu.PerThread.Id)
595 }595 }
596596
597 if (self.dwarf) |*dwarf| {597 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 };
599 try dwarf.flushModule(pt);599 try dwarf.flushModule(pt);
600600
601 self.debug_abbrev_dirty = false;601 self.debug_abbrev_dirty = false;
...@@ -688,7 +688,7 @@ pub fn lowerUav(...@@ -688,7 +688,7 @@ pub fn lowerUav(
688 const gpa = zcu.gpa;688 const gpa = zcu.gpa;
689 const val = Value.fromInterned(uav);689 const val = Value.fromInterned(uav);
690 const uav_alignment = switch (explicit_alignment) {690 const uav_alignment = switch (explicit_alignment) {
691 .none => val.typeOf(zcu).abiAlignment(pt),691 .none => val.typeOf(zcu).abiAlignment(zcu),
692 else => explicit_alignment,692 else => explicit_alignment,
693 };693 };
694 if (self.uavs.get(uav)) |metadata| {694 if (self.uavs.get(uav)) |metadata| {
...@@ -887,7 +887,7 @@ pub fn updateNav(...@@ -887,7 +887,7 @@ pub fn updateNav(
887 else => nav.status.resolved.val,887 else => nav.status.resolved.val,
888 };888 };
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)) {
891 const sym_index = try self.getOrCreateMetadataForNav(macho_file, nav_index);891 const sym_index = try self.getOrCreateMetadataForNav(macho_file, nav_index);
892 self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file);892 self.symbols.items[sym_index].getAtom(macho_file).?.freeRelocs(macho_file);
893893
...@@ -1256,7 +1256,7 @@ pub fn updateExports(...@@ -1256,7 +1256,7 @@ pub fn updateExports(
1256 const tracy = trace(@src());1256 const tracy = trace(@src());
1257 defer tracy.end();1257 defer tracy.end();
12581258
1259 const mod = pt.zcu;1259 const zcu = pt.zcu;
1260 const gpa = macho_file.base.comp.gpa;1260 const gpa = macho_file.base.comp.gpa;
1261 const metadata = switch (exported) {1261 const metadata = switch (exported) {
1262 .nav => |nav| blk: {1262 .nav => |nav| blk: {
...@@ -1264,15 +1264,15 @@ pub fn updateExports(...@@ -1264,15 +1264,15 @@ pub fn updateExports(
1264 break :blk self.navs.getPtr(nav).?;1264 break :blk self.navs.getPtr(nav).?;
1265 },1265 },
1266 .uav => |uav| self.uavs.getPtr(uav) orelse blk: {1266 .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]];
1268 const res = try self.lowerUav(macho_file, pt, uav, .none, first_exp.src);1268 const res = try self.lowerUav(macho_file, pt, uav, .none, first_exp.src);
1269 switch (res) {1269 switch (res) {
1270 .mcv => {},1270 .mcv => {},
1271 .fail => |em| {1271 .fail => |em| {
1272 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner1272 // TODO maybe it's enough to return an error here and let Zcu.processExportsInner
1273 // handle the error?1273 // handle the error?
1274 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1274 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1275 mod.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);1275 zcu.failed_exports.putAssumeCapacityNoClobber(export_indices[0], em);
1276 return;1276 return;
1277 },1277 },
1278 }1278 }
...@@ -1284,11 +1284,11 @@ pub fn updateExports(...@@ -1284,11 +1284,11 @@ pub fn updateExports(
1284 const nlist = self.symtab.items(.nlist)[nlist_idx];1284 const nlist = self.symtab.items(.nlist)[nlist_idx];
12851285
1286 for (export_indices) |export_idx| {1286 for (export_indices) |export_idx| {
1287 const exp = mod.all_exports.items[export_idx];1287 const exp = zcu.all_exports.items[export_idx];
1288 if (exp.opts.section.unwrap()) |section_name| {1288 if (exp.opts.section.unwrap()) |section_name| {
1289 if (!section_name.eqlSlice("__text", &mod.intern_pool)) {1289 if (!section_name.eqlSlice("__text", &zcu.intern_pool)) {
1290 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1290 try zcu.failed_exports.ensureUnusedCapacity(zcu.gpa, 1);
1291 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(1291 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, try Zcu.ErrorMsg.create(
1292 gpa,1292 gpa,
1293 exp.src,1293 exp.src,
1294 "Unimplemented: ExportOptions.section",1294 "Unimplemented: ExportOptions.section",
...@@ -1298,7 +1298,7 @@ pub fn updateExports(...@@ -1298,7 +1298,7 @@ pub fn updateExports(
1298 }1298 }
1299 }1299 }
1300 if (exp.opts.linkage == .link_once) {1300 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(
1302 gpa,1302 gpa,
1303 exp.src,1303 exp.src,
1304 "Unimplemented: GlobalLinkage.link_once",1304 "Unimplemented: GlobalLinkage.link_once",
...@@ -1307,7 +1307,7 @@ pub fn updateExports(...@@ -1307,7 +1307,7 @@ pub fn updateExports(
1307 continue;1307 continue;
1308 }1308 }
13091309
1310 const exp_name = exp.opts.name.toSlice(&mod.intern_pool);1310 const exp_name = exp.opts.name.toSlice(&zcu.intern_pool);
1311 const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index|1311 const global_nlist_index = if (metadata.@"export"(self, exp_name)) |exp_index|
1312 exp_index.*1312 exp_index.*
1313 else blk: {1313 else blk: {
...@@ -1437,15 +1437,15 @@ pub fn deleteExport(...@@ -1437,15 +1437,15 @@ pub fn deleteExport(
1437 exported: Zcu.Exported,1437 exported: Zcu.Exported,
1438 name: InternPool.NullTerminatedString,1438 name: InternPool.NullTerminatedString,
1439) void {1439) void {
1440 const mod = macho_file.base.comp.module.?;1440 const zcu = macho_file.base.comp.zcu.?;
14411441
1442 const metadata = switch (exported) {1442 const metadata = switch (exported) {
1443 .nav => |nav| self.navs.getPtr(nav),1443 .nav => |nav| self.navs.getPtr(nav),
1444 .uav => |uav| self.uavs.getPtr(uav),1444 .uav => |uav| self.uavs.getPtr(uav),
1445 } orelse return;1445 } 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
1450 const nlist = &self.symtab.items(.nlist)[nlist_index.*];1450 const nlist = &self.symtab.items(.nlist)[nlist_index.*];
1451 self.symtab.items(.size)[nlist_index.*] = 0;1451 self.symtab.items(.size)[nlist_index.*] = 0;
...@@ -1545,7 +1545,7 @@ pub fn getOrCreateMetadataForLazySymbol(...@@ -1545,7 +1545,7 @@ pub fn getOrCreateMetadataForLazySymbol(
1545fn isThreadlocal(macho_file: *MachO, nav_index: InternPool.Nav.Index) bool {1545fn isThreadlocal(macho_file: *MachO, nav_index: InternPool.Nav.Index) bool {
1546 if (!macho_file.base.comp.config.any_non_single_threaded)1546 if (!macho_file.base.comp.config.any_non_single_threaded)
1547 return false;1547 return false;
1548 const ip = &macho_file.base.comp.module.?.intern_pool;1548 const ip = &macho_file.base.comp.zcu.?.intern_pool;
1549 return switch (ip.indexToKey(ip.getNav(nav_index).status.resolved.val)) {1549 return switch (ip.indexToKey(ip.getNav(nav_index).status.resolved.val)) {
1550 .variable => |variable| variable.is_threadlocal,1550 .variable => |variable| variable.is_threadlocal,
1551 .@"extern" => |@"extern"| @"extern".is_threadlocal,1551 .@"extern" => |@"extern"| @"extern".is_threadlocal,
src/link/Plan9.zig+19-19
...@@ -152,7 +152,7 @@ pub const Atom = struct {...@@ -152,7 +152,7 @@ pub const Atom = struct {
152 return .{ .code_ptr = slice.ptr, .other = .{ .code_len = slice.len } };152 return .{ .code_ptr = slice.ptr, .other = .{ .code_len = slice.len } };
153 }153 }
154 fn getCode(self: CodePtr, plan9: *const Plan9) []u8 {154 fn getCode(self: CodePtr, plan9: *const Plan9) []u8 {
155 const zcu = plan9.base.comp.module.?;155 const zcu = plan9.base.comp.zcu.?;
156 const ip = &zcu.intern_pool;156 const ip = &zcu.intern_pool;
157 return if (self.code_ptr) |p| p[0..self.other.code_len] else blk: {157 return if (self.code_ptr) |p| p[0..self.other.code_len] else blk: {
158 const nav_index = self.other.nav_index;158 const nav_index = self.other.nav_index;
...@@ -317,8 +317,8 @@ pub fn createEmpty(...@@ -317,8 +317,8 @@ pub fn createEmpty(
317317
318fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void {318fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void {
319 const gpa = self.base.comp.gpa;319 const gpa = self.base.comp.gpa;
320 const mod = self.base.comp.module.?;320 const zcu = self.base.comp.zcu.?;
321 const file_scope = mod.navFileScopeIndex(nav_index);321 const file_scope = zcu.navFileScopeIndex(nav_index);
322 const fn_map_res = try self.fn_nav_table.getOrPut(gpa, file_scope);322 const fn_map_res = try self.fn_nav_table.getOrPut(gpa, file_scope);
323 if (fn_map_res.found_existing) {323 if (fn_map_res.found_existing) {
324 if (try fn_map_res.value_ptr.functions.fetchPut(gpa, nav_index, out)) |old_entry| {324 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...@@ -326,7 +326,7 @@ fn putFn(self: *Plan9, nav_index: InternPool.Nav.Index, out: FnNavOutput) !void
326 gpa.free(old_entry.value.lineinfo);326 gpa.free(old_entry.value.lineinfo);
327 }327 }
328 } else {328 } else {
329 const file = mod.fileByIndex(file_scope);329 const file = zcu.fileByIndex(file_scope);
330 const arena = self.path_arena.allocator();330 const arena = self.path_arena.allocator();
331 // each file gets a symbol331 // each file gets a symbol
332 fn_map_res.value_ptr.* = .{332 fn_map_res.value_ptr.* = .{
...@@ -391,10 +391,10 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,...@@ -391,10 +391,10 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
391 @panic("Attempted to compile for object format that was disabled by build configuration");391 @panic("Attempted to compile for object format that was disabled by build configuration");
392 }392 }
393393
394 const mod = pt.zcu;394 const zcu = pt.zcu;
395 const gpa = mod.gpa;395 const gpa = zcu.gpa;
396 const target = self.base.comp.root_mod.resolved_target.result;396 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
399 const atom_idx = try self.seeNav(pt, func.owner_nav);399 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,...@@ -413,7 +413,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
413 const res = try codegen.generateFunction(413 const res = try codegen.generateFunction(
414 &self.base,414 &self.base,
415 pt,415 pt,
416 mod.navSrcLoc(func.owner_nav),416 zcu.navSrcLoc(func.owner_nav),
417 func_index,417 func_index,
418 air,418 air,
419 liveness,419 liveness,
...@@ -423,7 +423,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,...@@ -423,7 +423,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
423 const code = switch (res) {423 const code = switch (res) {
424 .ok => try code_buffer.toOwnedSlice(),424 .ok => try code_buffer.toOwnedSlice(),
425 .fail => |em| {425 .fail => |em| {
426 try mod.failed_codegen.put(gpa, func.owner_nav, em);426 try zcu.failed_codegen.put(gpa, func.owner_nav, em);
427 return;427 return;
428 },428 },
429 };429 };
...@@ -457,7 +457,7 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde...@@ -457,7 +457,7 @@ pub fn updateNav(self: *Plan9, pt: Zcu.PerThread, nav_index: InternPool.Nav.Inde
457 else => nav_val,457 else => nav_val,
458 };458 };
459459
460 if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {460 if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
461 const atom_idx = try self.seeNav(pt, nav_index);461 const atom_idx = try self.seeNav(pt, nav_index);
462462
463 var code_buffer = std.ArrayList(u8).init(gpa);463 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...@@ -607,7 +607,7 @@ pub fn flushModule(self: *Plan9, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
607 defer assert(self.hdr.entry != 0x0);607 defer assert(self.hdr.entry != 0x0);
608608
609 const pt: Zcu.PerThread = .{609 const pt: Zcu.PerThread = .{
610 .zcu = self.base.comp.module orelse return error.LinkingWithoutZigSourceUnimplemented,610 .zcu = self.base.comp.zcu orelse return error.LinkingWithoutZigSourceUnimplemented,
611 .tid = tid,611 .tid = tid,
612 };612 };
613613
...@@ -952,11 +952,11 @@ pub fn freeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) void {...@@ -952,11 +952,11 @@ pub fn freeDecl(self: *Plan9, decl_index: InternPool.DeclIndex) void {
952 const gpa = self.base.comp.gpa;952 const gpa = self.base.comp.gpa;
953 // TODO audit the lifetimes of decls table entries. It's possible to get953 // TODO audit the lifetimes of decls table entries. It's possible to get
954 // freeDecl without any updateDecl in between.954 // freeDecl without any updateDecl in between.
955 const mod = self.base.comp.module.?;955 const zcu = self.base.comp.zcu.?;
956 const decl = mod.declPtr(decl_index);956 const decl = zcu.declPtr(decl_index);
957 const is_fn = decl.val.isFuncBody(mod);957 const is_fn = decl.val.isFuncBody(zcu);
958 if (is_fn) {958 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)).?;
960 var submap = symidx_and_submap.functions;960 var submap = symidx_and_submap.functions;
961 if (submap.fetchSwapRemove(decl_index)) |removed_entry| {961 if (submap.fetchSwapRemove(decl_index)) |removed_entry| {
962 gpa.free(removed_entry.value.code);962 gpa.free(removed_entry.value.code);
...@@ -1256,8 +1256,8 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {...@@ -1256,8 +1256,8 @@ pub fn writeSym(self: *Plan9, w: anytype, sym: aout.Sym) !void {
1256}1256}
12571257
1258pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {1258pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1259 const mod = self.base.comp.module.?;1259 const zcu = self.base.comp.zcu.?;
1260 const ip = &mod.intern_pool;1260 const ip = &zcu.intern_pool;
1261 const writer = buf.writer();1261 const writer = buf.writer();
1262 // write __GOT1262 // write __GOT
1263 try self.writeSym(writer, self.syms.items[0]);1263 try self.writeSym(writer, self.syms.items[0]);
...@@ -1284,7 +1284,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {...@@ -1284,7 +1284,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1284 try self.writeSym(writer, sym);1284 try self.writeSym(writer, sym);
1285 if (self.nav_exports.get(nav_index)) |export_indices| {1285 if (self.nav_exports.get(nav_index)) |export_indices| {
1286 for (export_indices) |export_idx| {1286 for (export_indices) |export_idx| {
1287 const exp = mod.all_exports.items[export_idx];1287 const exp = zcu.all_exports.items[export_idx];
1288 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {1288 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {
1289 try self.writeSym(writer, self.syms.items[exp_i]);1289 try self.writeSym(writer, self.syms.items[exp_i]);
1290 }1290 }
...@@ -1323,7 +1323,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {...@@ -1323,7 +1323,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
1323 try self.writeSym(writer, sym);1323 try self.writeSym(writer, sym);
1324 if (self.nav_exports.get(nav_index)) |export_indices| {1324 if (self.nav_exports.get(nav_index)) |export_indices| {
1325 for (export_indices) |export_idx| {1325 for (export_indices) |export_idx| {
1326 const exp = mod.all_exports.items[export_idx];1326 const exp = zcu.all_exports.items[export_idx];
1327 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {1327 if (nav_metadata.getExport(self, exp.opts.name.toSlice(ip))) |exp_i| {
1328 const s = self.syms.items[exp_i];1328 const s = self.syms.items[exp_i];
1329 if (mem.eql(u8, s.name, "_start"))1329 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...@@ -229,7 +229,7 @@ pub fn flushModule(self: *SpirV, arena: Allocator, tid: Zcu.PerThread.Id, prog_n
229 defer error_info.deinit();229 defer error_info.deinit();
230230
231 try error_info.appendSlice("zig_errors:");231 try error_info.appendSlice("zig_errors:");
232 const ip = &self.base.comp.module.?.intern_pool;232 const ip = &self.base.comp.zcu.?.intern_pool;
233 for (ip.global_error_set.getNamesFromMainThread()) |name| {233 for (ip.global_error_set.getNamesFromMainThread()) |name| {
234 // Errors can contain pretty much any character - to encode them in a string we must escape234 // Errors can contain pretty much any character - to encode them in a string we must escape
235 // them somehow. Easiest here is to use some established scheme, one which also preseves the235 // 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(...@@ -556,7 +556,7 @@ pub fn createEmpty(
556 }556 }
557 }557 }
558558
559 if (comp.module) |zcu| {559 if (comp.zcu) |zcu| {
560 if (!use_llvm) {560 if (!use_llvm) {
561 const index: File.Index = @enumFromInt(wasm.files.len);561 const index: File.Index = @enumFromInt(wasm.files.len);
562 var zig_object: ZigObject = .{562 var zig_object: ZigObject = .{
...@@ -3352,7 +3352,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:...@@ -3352,7 +3352,7 @@ fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
33523352
3353 // If there is no Zig code to compile, then we should skip flushing the output file because it3353 // If there is no Zig code to compile, then we should skip flushing the output file because it
3354 // will not be part of the linker line anyway.3354 // 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: {
3356 try wasm.flushModule(arena, tid, prog_node);3356 try wasm.flushModule(arena, tid, prog_node);
33573357
3358 if (fs.path.dirname(full_out_path)) |dirname| {3358 if (fs.path.dirname(full_out_path)) |dirname| {
src/link/Wasm/ZigObject.zig+18-18
...@@ -259,7 +259,7 @@ pub fn updateNav(...@@ -259,7 +259,7 @@ pub fn updateNav(
259 else => .{ false, .none, nav_val },259 else => .{ false, .none, nav_val },
260 };260 };
261261
262 if (nav_init.typeOf(zcu).hasRuntimeBits(pt)) {262 if (nav_init.typeOf(zcu).hasRuntimeBits(zcu)) {
263 const gpa = wasm_file.base.comp.gpa;263 const gpa = wasm_file.base.comp.gpa;
264 const atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, nav_index);264 const atom_index = try zig_object.getOrCreateAtomForNav(wasm_file, pt, nav_index);
265 const atom = wasm_file.getAtomPtr(atom_index);265 const atom = wasm_file.getAtomPtr(atom_index);
...@@ -487,9 +487,9 @@ fn lowerConst(...@@ -487,9 +487,9 @@ fn lowerConst(
487 src_loc: Zcu.LazySrcLoc,487 src_loc: Zcu.LazySrcLoc,
488) !LowerConstResult {488) !LowerConstResult {
489 const gpa = wasm_file.base.comp.gpa;489 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
494 // Create and initialize a new local symbol and atom494 // Create and initialize a new local symbol and atom
495 const sym_index = try zig_object.allocateSymbol(gpa);495 const sym_index = try zig_object.allocateSymbol(gpa);
...@@ -499,7 +499,7 @@ fn lowerConst(...@@ -499,7 +499,7 @@ fn lowerConst(
499499
500 const code = code: {500 const code = code: {
501 const atom = wasm_file.getAtomPtr(atom_index);501 const atom = wasm_file.getAtomPtr(atom_index);
502 atom.alignment = ty.abiAlignment(pt);502 atom.alignment = ty.abiAlignment(zcu);
503 const segment_name = try std.mem.concat(gpa, u8, &.{ ".rodata.", name });503 const segment_name = try std.mem.concat(gpa, u8, &.{ ".rodata.", name });
504 errdefer gpa.free(segment_name);504 errdefer gpa.free(segment_name);
505 zig_object.symbol(sym_index).* = .{505 zig_object.symbol(sym_index).* = .{
...@@ -509,7 +509,7 @@ fn lowerConst(...@@ -509,7 +509,7 @@ fn lowerConst(
509 .index = try zig_object.createDataSegment(509 .index = try zig_object.createDataSegment(
510 gpa,510 gpa,
511 segment_name,511 segment_name,
512 ty.abiAlignment(pt),512 ty.abiAlignment(zcu),
513 ),513 ),
514 .virtual_address = undefined,514 .virtual_address = undefined,
515 };515 };
...@@ -555,7 +555,7 @@ pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm, pt: Zcu.Per...@@ -555,7 +555,7 @@ pub fn getErrorTableSymbol(zig_object: *ZigObject, wasm_file: *Wasm, pt: Zcu.Per
555 const atom_index = try wasm_file.createAtom(sym_index, zig_object.index);555 const atom_index = try wasm_file.createAtom(sym_index, zig_object.index);
556 const atom = wasm_file.getAtomPtr(atom_index);556 const atom = wasm_file.getAtomPtr(atom_index);
557 const slice_ty = Type.slice_const_u8_sentinel_0;557 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
560 const sym_name = try zig_object.string_table.insert(gpa, "__zig_err_name_table");560 const sym_name = try zig_object.string_table.insert(gpa, "__zig_err_name_table");
561 const segment_name = try gpa.dupe(u8, ".rodata.__zig_err_name_table");561 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...@@ -604,14 +604,14 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per
604604
605 // Addend for each relocation to the table605 // Addend for each relocation to the table
606 var addend: u32 = 0;606 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 };
608 const slice_ty = Type.slice_const_u8_sentinel_0;608 const slice_ty = Type.slice_const_u8_sentinel_0;
609 const atom = wasm_file.getAtomPtr(atom_index);609 const atom = wasm_file.getAtomPtr(atom_index);
610 {610 {
611 // TODO: remove this unreachable entry611 // TODO: remove this unreachable entry
612 try atom.code.appendNTimes(gpa, 0, 4);612 try atom.code.appendNTimes(gpa, 0, 4);
613 try atom.code.writer(gpa).writeInt(u32, 0, .little);613 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));
615 addend += 1;615 addend += 1;
616616
617 try names_atom.code.append(gpa, 0);617 try names_atom.code.append(gpa, 0);
...@@ -632,7 +632,7 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per...@@ -632,7 +632,7 @@ fn populateErrorNameTable(zig_object: *ZigObject, wasm_file: *Wasm, tid: Zcu.Per
632 .offset = offset,632 .offset = offset,
633 .addend = @intCast(addend),633 .addend = @intCast(addend),
634 });634 });
635 atom.size += @intCast(slice_ty.abiSize(pt));635 atom.size += @intCast(slice_ty.abiSize(pt.zcu));
636 addend += len;636 addend += len;
637637
638 // as we updated the error name table, we now store the actual name within the names atom638 // as we updated the error name table, we now store the actual name within the names atom
...@@ -803,9 +803,9 @@ pub fn getUavVAddr(...@@ -803,9 +803,9 @@ pub fn getUavVAddr(
803 const parent_atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;803 const parent_atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
804 const parent_atom = wasm_file.getAtomPtr(parent_atom_index);804 const parent_atom = wasm_file.getAtomPtr(parent_atom_index);
805 const is_wasm32 = target.cpu.arch == .wasm32;805 const is_wasm32 = target.cpu.arch == .wasm32;
806 const mod = wasm_file.base.comp.module.?;806 const zcu = wasm_file.base.comp.zcu.?;
807 const ty = Type.fromInterned(mod.intern_pool.typeOf(uav));807 const ty = Type.fromInterned(zcu.intern_pool.typeOf(uav));
808 if (ty.zigTypeTag(mod) == .Fn) {808 if (ty.zigTypeTag(zcu) == .Fn) {
809 std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations809 std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
810 try parent_atom.relocs.append(gpa, .{810 try parent_atom.relocs.append(gpa, .{
811 .index = target_symbol_index,811 .index = target_symbol_index,
...@@ -834,13 +834,13 @@ pub fn deleteExport(...@@ -834,13 +834,13 @@ pub fn deleteExport(
834 exported: Zcu.Exported,834 exported: Zcu.Exported,
835 name: InternPool.NullTerminatedString,835 name: InternPool.NullTerminatedString,
836) void {836) void {
837 const mod = wasm_file.base.comp.module.?;837 const zcu = wasm_file.base.comp.zcu.?;
838 const nav_index = switch (exported) {838 const nav_index = switch (exported) {
839 .nav => |nav_index| nav_index,839 .nav => |nav_index| nav_index,
840 .uav => @panic("TODO: implement Wasm linker code for exporting a constant value"),840 .uav => @panic("TODO: implement Wasm linker code for exporting a constant value"),
841 };841 };
842 const nav_info = zig_object.navs.getPtr(nav_index) orelse return;842 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| {
844 const sym = zig_object.symbol(sym_index);844 const sym = zig_object.symbol(sym_index);
845 nav_info.deleteExport(sym_index);845 nav_info.deleteExport(sym_index);
846 std.debug.assert(zig_object.global_syms.remove(sym.name));846 std.debug.assert(zig_object.global_syms.remove(sym.name));
...@@ -930,8 +930,8 @@ pub fn updateExports(...@@ -930,8 +930,8 @@ pub fn updateExports(
930930
931pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.Nav.Index) void {931pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.Nav.Index) void {
932 const gpa = wasm_file.base.comp.gpa;932 const gpa = wasm_file.base.comp.gpa;
933 const mod = wasm_file.base.comp.module.?;933 const zcu = wasm_file.base.comp.zcu.?;
934 const ip = &mod.intern_pool;934 const ip = &zcu.intern_pool;
935 const nav_info = zig_object.navs.getPtr(nav_index).?;935 const nav_info = zig_object.navs.getPtr(nav_index).?;
936 const atom_index = nav_info.atom;936 const atom_index = nav_info.atom;
937 const atom = wasm_file.getAtomPtr(atom_index);937 const atom = wasm_file.getAtomPtr(atom_index);
...@@ -956,7 +956,7 @@ pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.N...@@ -956,7 +956,7 @@ pub fn freeNav(zig_object: *ZigObject, wasm_file: *Wasm, nav_index: InternPool.N
956 segment.name = &.{}; // Ensure no accidental double free956 segment.name = &.{}; // Ensure no accidental double free
957 }957 }
958958
959 const nav_val = mod.navValue(nav_index).toIntern();959 const nav_val = zcu.navValue(nav_index).toIntern();
960 if (ip.indexToKey(nav_val) == .@"extern") {960 if (ip.indexToKey(nav_val) == .@"extern") {
961 std.debug.assert(zig_object.imports.remove(atom.sym_index));961 std.debug.assert(zig_object.imports.remove(atom.sym_index));
962 }962 }
...@@ -1016,7 +1016,7 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {...@@ -1016,7 +1016,7 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {
1016 const gpa = wasm_file.base.comp.gpa;1016 const gpa = wasm_file.base.comp.gpa;
1017 const sym_index = zig_object.findGlobalSymbol("__zig_errors_len") orelse return;1017 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;
1020 // overwrite existing atom if it already exists (maybe the error set has increased)1020 // overwrite existing atom if it already exists (maybe the error set has increased)
1021 // if not, allocate a new atom.1021 // if not, allocate a new atom.
1022 const atom_index = if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index })) |index| blk: {1022 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) {...@@ -223,7 +223,7 @@ pub const MutableValue = union(enum) {
223 @memset(elems[0..@intCast(len_no_sent)], .{ .interned = undef_elem });223 @memset(elems[0..@intCast(len_no_sent)], .{ .interned = undef_elem });
224 },224 },
225 .Struct => for (elems[0..@intCast(len_no_sent)], 0..) |*mut_elem, i| {225 .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();
227 mut_elem.* = .{ .interned = try pt.intern(.{ .undef = field_ty }) };227 mut_elem.* = .{ .interned = try pt.intern(.{ .undef = field_ty }) };
228 },228 },
229 else => unreachable,229 else => unreachable,
...@@ -369,7 +369,7 @@ pub const MutableValue = union(enum) {...@@ -369,7 +369,7 @@ pub const MutableValue = union(enum) {
369 .bytes => |b| {369 .bytes => |b| {
370 assert(is_trivial_int);370 assert(is_trivial_int);
371 assert(field_val.typeOf(zcu).toIntern() == .u8_type);371 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));
373 },373 },
374 .repeated => |r| {374 .repeated => |r| {
375 if (field_val.eqlTrivial(r.child.*)) return;375 if (field_val.eqlTrivial(r.child.*)) return;
...@@ -382,9 +382,9 @@ pub const MutableValue = union(enum) {...@@ -382,9 +382,9 @@ pub const MutableValue = union(enum) {
382 {382 {
383 // We can use the `bytes` representation.383 // We can use the `bytes` representation.
384 const bytes = try arena.alloc(u8, @intCast(len_inc_sent));384 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);
386 @memset(bytes, @intCast(repeated_byte));386 @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));
388 mv.* = .{ .bytes = .{388 mv.* = .{ .bytes = .{
389 .ty = r.ty,389 .ty = r.ty,
390 .data = bytes,390 .data = bytes,
...@@ -431,7 +431,7 @@ pub const MutableValue = union(enum) {...@@ -431,7 +431,7 @@ pub const MutableValue = union(enum) {
431 } else {431 } else {
432 const bytes = try arena.alloc(u8, a.elems.len);432 const bytes = try arena.alloc(u8, a.elems.len);
433 for (a.elems, bytes) |elem_val, *b| {433 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));
435 }435 }
436 mv.* = .{ .bytes = .{436 mv.* = .{ .bytes = .{
437 .ty = a.ty,437 .ty = a.ty,
src/print_air.zig+6-6
...@@ -428,10 +428,10 @@ const Writer = struct {...@@ -428,10 +428,10 @@ const Writer = struct {
428 }428 }
429429
430 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {430 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;
432 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;432 const ty_pl = w.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
433 const vector_ty = ty_pl.ty.toType();433 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)));
435 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));435 const elements = @as([]const Air.Inst.Ref, @ptrCast(w.air.extra[ty_pl.payload..][0..len]));
436436
437 try w.writeType(s, vector_ty);437 try w.writeType(s, vector_ty);
...@@ -508,11 +508,11 @@ const Writer = struct {...@@ -508,11 +508,11 @@ const Writer = struct {
508 }508 }
509509
510 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {510 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;
512 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;512 const pl_op = w.air.instructions.items(.data)[@intFromEnum(inst)].pl_op;
513 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;513 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);
516 try w.writeType(s, elem_ty);516 try w.writeType(s, elem_ty);
517 try s.writeAll(", ");517 try s.writeAll(", ");
518 try w.writeOperand(s, inst, 0, pl_op.operand);518 try w.writeOperand(s, inst, 0, pl_op.operand);
...@@ -974,7 +974,7 @@ const Writer = struct {...@@ -974,7 +974,7 @@ const Writer = struct {
974 }974 }
975975
976 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {976 fn typeOfIndex(w: *Writer, inst: Air.Inst.Index) Type {
977 const mod = w.pt.zcu;977 const zcu = w.pt.zcu;
978 return w.air.typeOfIndex(inst, &mod.intern_pool);978 return w.air.typeOfIndex(inst, &zcu.intern_pool);
979 }979 }
980};980};
src/print_value.zig+7-7
...@@ -62,8 +62,8 @@ pub fn print(...@@ -62,8 +62,8 @@ pub fn print(
62 comptime have_sema: bool,62 comptime have_sema: bool,
63 sema: if (have_sema) *Sema else void,63 sema: if (have_sema) *Sema else void,
64) (@TypeOf(writer).Error || Zcu.CompileError)!void {64) (@TypeOf(writer).Error || Zcu.CompileError)!void {
65 const mod = pt.zcu;65 const zcu = pt.zcu;
66 const ip = &mod.intern_pool;66 const ip = &zcu.intern_pool;
67 switch (ip.indexToKey(val.toIntern())) {67 switch (ip.indexToKey(val.toIntern())) {
68 .int_type,68 .int_type,
69 .ptr_type,69 .ptr_type,
...@@ -95,11 +95,11 @@ pub fn print(...@@ -95,11 +95,11 @@ pub fn print(
95 .int => |int| switch (int.storage) {95 .int => |int| switch (int.storage) {
96 inline .u64, .i64, .big_int => |x| try writer.print("{}", .{x}),96 inline .u64, .i64, .big_int => |x| try writer.print("{}", .{x}),
97 .lazy_align => |ty| if (have_sema) {97 .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);
99 try writer.print("{}", .{a.toByteUnits() orelse 0});99 try writer.print("{}", .{a.toByteUnits() orelse 0});
100 } else try writer.print("@alignOf({})", .{Type.fromInterned(ty).fmt(pt)}),100 } else try writer.print("@alignOf({})", .{Type.fromInterned(ty).fmt(pt)}),
101 .lazy_size => |ty| if (have_sema) {101 .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);
103 try writer.print("{}", .{s});103 try writer.print("{}", .{s});
104 } else try writer.print("@sizeOf({})", .{Type.fromInterned(ty).fmt(pt)}),104 } else try writer.print("@sizeOf({})", .{Type.fromInterned(ty).fmt(pt)}),
105 },105 },
...@@ -116,7 +116,7 @@ pub fn print(...@@ -116,7 +116,7 @@ pub fn print(
116 enum_literal.fmt(ip),116 enum_literal.fmt(ip),
117 }),117 }),
118 .enum_tag => |enum_tag| {118 .enum_tag => |enum_tag| {
119 const enum_type = ip.loadEnumType(val.typeOf(mod).toIntern());119 const enum_type = ip.loadEnumType(val.typeOf(zcu).toIntern());
120 if (enum_type.tagValueIndex(ip, val.toIntern())) |tag_index| {120 if (enum_type.tagValueIndex(ip, val.toIntern())) |tag_index| {
121 return writer.print(".{i}", .{enum_type.names.get(ip)[tag_index].fmt(ip)});121 return writer.print(".{i}", .{enum_type.names.get(ip)[tag_index].fmt(ip)});
122 }122 }
...@@ -173,7 +173,7 @@ pub fn print(...@@ -173,7 +173,7 @@ pub fn print(
173 return;173 return;
174 }174 }
175 if (un.tag == .none) {175 if (un.tag == .none) {
176 const backing_ty = try val.typeOf(mod).unionBackingType(pt);176 const backing_ty = try val.typeOf(zcu).unionBackingType(pt);
177 try writer.print("@bitCast(@as({}, ", .{backing_ty.fmt(pt)});177 try writer.print("@bitCast(@as({}, ", .{backing_ty.fmt(pt)});
178 try print(Value.fromInterned(un.val), writer, level - 1, pt, have_sema, sema);178 try print(Value.fromInterned(un.val), writer, level - 1, pt, have_sema, sema);
179 try writer.writeAll("))");179 try writer.writeAll("))");
...@@ -245,7 +245,7 @@ fn printAggregate(...@@ -245,7 +245,7 @@ fn printAggregate(
245 if (ty.childType(zcu).toIntern() != .u8_type) break :one_byte_str;245 if (ty.childType(zcu).toIntern() != .u8_type) break :one_byte_str;
246 const elem_val = Value.fromInterned(aggregate.storage.values()[0]);246 const elem_val = Value.fromInterned(aggregate.storage.values()[0]);
247 if (elem_val.isUndef(zcu)) break :one_byte_str;247 if (elem_val.isUndef(zcu)) break :one_byte_str;
248 const byte = elem_val.toUnsignedInt(pt);248 const byte = elem_val.toUnsignedInt(zcu);
249 try writer.print("\"{}\"", .{std.zig.fmtEscapes(&.{@intCast(byte)})});249 try writer.print("\"{}\"", .{std.zig.fmtEscapes(&.{@intCast(byte)})});
250 if (!is_ref) try writer.writeAll(".*");250 if (!is_ref) try writer.writeAll(".*");
251 return;251 return;
src/target.zig+5-1
...@@ -526,7 +526,11 @@ pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBacken...@@ -526,7 +526,11 @@ pub fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBacken
526pub inline fn backendSupportsFeature(backend: std.builtin.CompilerBackend, comptime feature: Feature) bool {526pub inline fn backendSupportsFeature(backend: std.builtin.CompilerBackend, comptime feature: Feature) bool {
527 return switch (feature) {527 return switch (feature) {
528 .panic_fn => switch (backend) {528 .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,
530 else => false,534 else => false,
531 },535 },
532 .panic_unwrap_error => switch (backend) {536 .panic_unwrap_error => switch (backend) {