authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-12 01:44:12-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-11 23:45:09-07:00
logd37ebfcf231c68a0430840c4fbe649dd0076ae1e
treed9f67acedf38600487a2d2ed08e1e202dfad5667
parent54460e39ace2140e6bfcb0bf4ae1709d128f9e8d

InternPool: avoid as many slices pointing to `string_bytes` as possible

These are frequently invalidated whenever a string is interned, so avoid creating pointers to `string_bytes` wherever possible. This is an attempt to fix random CI failures.

16 files changed, 572 insertions(+), 638 deletions(-)

src/InternPool.zig+38-8
......@@ -156,6 +156,35 @@ pub const NullTerminatedString = enum(u32) {
156156 _ = ctx;
157157 return @enumToInt(a) < @enumToInt(b);
158158 }
159
160 pub fn toUnsigned(self: NullTerminatedString, ip: *const InternPool) ?u32 {
161 const s = ip.stringToSlice(self);
162 if (s.len > 1 and s[0] == '0') return null;
163 if (std.mem.indexOfScalar(u8, s, '_')) |_| return null;
164 return std.fmt.parseUnsigned(u32, s, 10) catch null;
165 }
166
167 const FormatData = struct {
168 string: NullTerminatedString,
169 ip: *const InternPool,
170 };
171 fn format(
172 data: FormatData,
173 comptime specifier: []const u8,
174 _: std.fmt.FormatOptions,
175 writer: anytype,
176 ) @TypeOf(writer).Error!void {
177 const s = data.ip.stringToSlice(data.string);
178 if (comptime std.mem.eql(u8, specifier, "")) {
179 try writer.writeAll(s);
180 } else if (comptime std.mem.eql(u8, specifier, "i")) {
181 try writer.print("{}", .{std.zig.fmtId(s)});
182 } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");
183 }
184
185 pub fn fmt(self: NullTerminatedString, ip: *const InternPool) std.fmt.Formatter(format) {
186 return .{ .data = .{ .string = self, .ip = ip } };
187 }
159188};
160189
161190/// An index into `string_bytes` which might be `none`.
......@@ -5252,10 +5281,9 @@ pub fn getOrPutString(
52525281 gpa: Allocator,
52535282 s: []const u8,
52545283) Allocator.Error!NullTerminatedString {
5255 const string_bytes = &ip.string_bytes;
5256 try string_bytes.ensureUnusedCapacity(gpa, s.len + 1);
5257 string_bytes.appendSliceAssumeCapacity(s);
5258 string_bytes.appendAssumeCapacity(0);
5284 try ip.string_bytes.ensureUnusedCapacity(gpa, s.len + 1);
5285 ip.string_bytes.appendSliceAssumeCapacity(s);
5286 ip.string_bytes.appendAssumeCapacity(0);
52595287 return ip.getOrPutTrailingString(gpa, s.len + 1);
52605288}
52615289
......@@ -5265,10 +5293,12 @@ pub fn getOrPutStringFmt(
52655293 comptime format: []const u8,
52665294 args: anytype,
52675295) Allocator.Error!NullTerminatedString {
5268 const start = ip.string_bytes.items.len;
5269 try ip.string_bytes.writer(gpa).print(format, args);
5270 try ip.string_bytes.append(gpa, 0);
5271 return ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);
5296 // ensure that references to string_bytes in args do not get invalidated
5297 const len = std.fmt.count(format, args) + 1;
5298 try ip.string_bytes.ensureUnusedCapacity(gpa, len);
5299 ip.string_bytes.writer(undefined).print(format, args) catch unreachable;
5300 ip.string_bytes.appendAssumeCapacity(0);
5301 return ip.getOrPutTrailingString(gpa, len);
52725302}
52735303
52745304pub fn getOrPutStringOpt(
src/Module.zig+46-76
......@@ -270,11 +270,7 @@ pub const GlobalEmitH = struct {
270270pub const ErrorInt = u32;
271271
272272pub const Export = struct {
273 name: InternPool.NullTerminatedString,
274 linkage: std.builtin.GlobalLinkage,
275 section: InternPool.OptionalNullTerminatedString,
276 visibility: std.builtin.SymbolVisibility,
277
273 opts: Options,
278274 src: LazySrcLoc,
279275 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
280276 owner_decl: Decl.Index,
......@@ -292,6 +288,13 @@ pub const Export = struct {
292288 complete,
293289 },
294290
291 pub const Options = struct {
292 name: InternPool.NullTerminatedString,
293 linkage: std.builtin.GlobalLinkage = .Strong,
294 section: InternPool.OptionalNullTerminatedString = .none,
295 visibility: std.builtin.SymbolVisibility = .default,
296 };
297
295298 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
296299 const src_decl = mod.declPtr(exp.src_decl);
297300 return .{
......@@ -691,16 +694,15 @@ pub const Decl = struct {
691694 }
692695
693696 pub fn renderFullyQualifiedName(decl: Decl, mod: *Module, writer: anytype) !void {
694 const unqualified_name = mod.intern_pool.stringToSlice(decl.name);
695697 if (decl.name_fully_qualified) {
696 return writer.writeAll(unqualified_name);
698 try writer.print("{}", .{decl.name.fmt(&mod.intern_pool)});
699 } else {
700 try mod.namespacePtr(decl.src_namespace).renderFullyQualifiedName(mod, decl.name, writer);
697701 }
698 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedName(mod, unqualified_name, writer);
699702 }
700703
701704 pub fn renderFullyQualifiedDebugName(decl: Decl, mod: *Module, writer: anytype) !void {
702 const unqualified_name = mod.intern_pool.stringToSlice(decl.name);
703 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(mod, unqualified_name, writer);
705 return mod.namespacePtr(decl.src_namespace).renderFullyQualifiedDebugName(mod, decl.name, writer);
704706 }
705707
706708 pub fn getFullyQualifiedName(decl: Decl, mod: *Module) !InternPool.NullTerminatedString {
......@@ -712,8 +714,7 @@ pub const Decl = struct {
712714 var ns: Namespace.Index = decl.src_namespace;
713715 while (true) {
714716 const namespace = mod.namespacePtr(ns);
715 const ns_decl_index = namespace.getDeclIndex(mod);
716 const ns_decl = mod.declPtr(ns_decl_index);
717 const ns_decl = mod.declPtr(namespace.getDeclIndex(mod));
717718 count += ip.stringToSlice(ns_decl.name).len + 1;
718719 ns = namespace.parent.unwrap() orelse {
719720 count += namespace.file_scope.sub_file_path.len;
......@@ -1722,44 +1723,34 @@ pub const Namespace = struct {
17221723 pub fn renderFullyQualifiedName(
17231724 ns: Namespace,
17241725 mod: *Module,
1725 name: []const u8,
1726 name: InternPool.NullTerminatedString,
17261727 writer: anytype,
17271728 ) @TypeOf(writer).Error!void {
17281729 if (ns.parent.unwrap()) |parent| {
1729 const decl_index = ns.getDeclIndex(mod);
1730 const decl = mod.declPtr(decl_index);
1731 const decl_name = mod.intern_pool.stringToSlice(decl.name);
1732 try mod.namespacePtr(parent).renderFullyQualifiedName(mod, decl_name, writer);
1730 const decl = mod.declPtr(ns.getDeclIndex(mod));
1731 try mod.namespacePtr(parent).renderFullyQualifiedName(mod, decl.name, writer);
17331732 } else {
17341733 try ns.file_scope.renderFullyQualifiedName(writer);
17351734 }
1736 if (name.len != 0) {
1737 try writer.writeAll(".");
1738 try writer.writeAll(name);
1739 }
1735 if (name != .empty) try writer.print(".{}", .{name.fmt(&mod.intern_pool)});
17401736 }
17411737
17421738 /// This renders e.g. "std/fs.zig:Dir.OpenOptions"
17431739 pub fn renderFullyQualifiedDebugName(
17441740 ns: Namespace,
17451741 mod: *Module,
1746 name: []const u8,
1742 name: InternPool.NullTerminatedString,
17471743 writer: anytype,
17481744 ) @TypeOf(writer).Error!void {
1749 var separator_char: u8 = '.';
1750 if (ns.parent.unwrap()) |parent| {
1751 const decl_index = ns.getDeclIndex(mod);
1752 const decl = mod.declPtr(decl_index);
1753 const decl_name = mod.intern_pool.stringToSlice(decl.name);
1754 try mod.namespacePtr(parent).renderFullyQualifiedDebugName(mod, decl_name, writer);
1755 } else {
1745 const separator_char: u8 = if (ns.parent.unwrap()) |parent| sep: {
1746 const decl = mod.declPtr(ns.getDeclIndex(mod));
1747 try mod.namespacePtr(parent).renderFullyQualifiedDebugName(mod, decl.name, writer);
1748 break :sep '.';
1749 } else sep: {
17561750 try ns.file_scope.renderFullyQualifiedDebugName(writer);
1757 separator_char = ':';
1758 }
1759 if (name.len != 0) {
1760 try writer.writeByte(separator_char);
1761 try writer.writeAll(name);
1762 }
1751 break :sep ':';
1752 };
1753 if (name != .empty) try writer.print("{c}{}", .{ separator_char, name.fmt(&mod.intern_pool) });
17631754 }
17641755
17651756 pub fn getDeclIndex(ns: Namespace, mod: *Module) Decl.Index {
......@@ -4185,10 +4176,10 @@ pub fn ensureFuncBodyAnalyzed(mod: *Module, func_index: Fn.Index) SemaError!void
41854176 defer liveness.deinit(gpa);
41864177
41874178 if (dump_air) {
4188 const fqn = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod));
4189 std.debug.print("# Begin Function AIR: {s}:\n", .{fqn});
4179 const fqn = try decl.getFullyQualifiedName(mod);
4180 std.debug.print("# Begin Function AIR: {}:\n", .{fqn.fmt(&mod.intern_pool)});
41904181 @import("print_air.zig").dump(mod, air, liveness);
4191 std.debug.print("# End Function AIR: {s}\n\n", .{fqn});
4182 std.debug.print("# End Function AIR: {}\n\n", .{fqn.fmt(&mod.intern_pool)});
41924183 }
41934184
41944185 if (std.debug.runtime_safety) {
......@@ -4620,10 +4611,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
46204611 return sema.fail(&block_scope, export_src, "export of inline function", .{});
46214612 }
46224613 // The scope needs to have the decl in it.
4623 const options: std.builtin.ExportOptions = .{
4624 .name = mod.intern_pool.stringToSlice(decl.name),
4625 };
4626 try sema.analyzeExport(&block_scope, export_src, options, decl_index);
4614 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);
46274615 }
46284616 return type_changed or is_inline != prev_is_inline;
46294617 }
......@@ -4720,10 +4708,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
47204708 if (decl.is_exported) {
47214709 const export_src: LazySrcLoc = .{ .token_offset = @boolToInt(decl.is_pub) };
47224710 // The scope needs to have the decl in it.
4723 const options: std.builtin.ExportOptions = .{
4724 .name = mod.intern_pool.stringToSlice(decl.name),
4725 };
4726 try sema.analyzeExport(&block_scope, export_src, options, decl_index);
4711 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);
47274712 }
47284713
47294714 return type_changed;
......@@ -5222,12 +5207,9 @@ fn scanDecl(iter: *ScanDeclIter, decl_sub_index: usize, flags: u4) Allocator.Err
52225207 .parent_decl_node = decl.src_node,
52235208 .lazy = .{ .token_offset = 1 },
52245209 };
5225 const msg = try ErrorMsg.create(
5226 gpa,
5227 src_loc,
5228 "duplicate test name: {s}",
5229 .{ip.stringToSlice(decl_name)},
5230 );
5210 const msg = try ErrorMsg.create(gpa, src_loc, "duplicate test name: {}", .{
5211 decl_name.fmt(&mod.intern_pool),
5212 });
52315213 errdefer msg.destroy(gpa);
52325214 try mod.failed_decls.putNoClobber(gpa, decl_index, msg);
52335215 const other_src_loc = SrcLoc{
......@@ -5417,16 +5399,16 @@ fn deleteDeclExports(mod: *Module, decl_index: Decl.Index) Allocator.Error!void
54175399 }
54185400 }
54195401 if (mod.comp.bin_file.cast(link.File.Elf)) |elf| {
5420 elf.deleteDeclExport(decl_index, exp.name);
5402 elf.deleteDeclExport(decl_index, exp.opts.name);
54215403 }
54225404 if (mod.comp.bin_file.cast(link.File.MachO)) |macho| {
5423 try macho.deleteDeclExport(decl_index, exp.name);
5405 try macho.deleteDeclExport(decl_index, exp.opts.name);
54245406 }
54255407 if (mod.comp.bin_file.cast(link.File.Wasm)) |wasm| {
54265408 wasm.deleteDeclExport(decl_index);
54275409 }
54285410 if (mod.comp.bin_file.cast(link.File.Coff)) |coff| {
5429 coff.deleteDeclExport(decl_index, exp.name);
5411 coff.deleteDeclExport(decl_index, exp.opts.name);
54305412 }
54315413 if (mod.failed_exports.fetchSwapRemove(exp)) |failed_kv| {
54325414 failed_kv.value.destroy(mod.gpa);
......@@ -5810,12 +5792,9 @@ pub fn createAnonymousDeclFromDecl(
58105792) !Decl.Index {
58115793 const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope);
58125794 errdefer mod.destroyDecl(new_decl_index);
5813 const ip = &mod.intern_pool;
5814 // This protects the getOrPutStringFmt from reallocating src decl name while reading it.
5815 try ip.string_bytes.ensureUnusedCapacity(mod.gpa, ip.stringToSlice(src_decl.name).len + 20);
5816 const name = ip.getOrPutStringFmt(mod.gpa, "{s}__anon_{d}", .{
5817 ip.stringToSlice(src_decl.name), @enumToInt(new_decl_index),
5818 }) catch unreachable;
5795 const name = try mod.intern_pool.getOrPutStringFmt(mod.gpa, "{}__anon_{d}", .{
5796 src_decl.name.fmt(&mod.intern_pool), @enumToInt(new_decl_index),
5797 });
58195798 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, tv, name);
58205799 return new_decl_index;
58215800}
......@@ -6301,13 +6280,13 @@ pub fn processExports(mod: *Module) !void {
63016280 const exported_decl = entry.key_ptr.*;
63026281 const exports = entry.value_ptr.items;
63036282 for (exports) |new_export| {
6304 const gop = try symbol_exports.getOrPut(gpa, new_export.name);
6283 const gop = try symbol_exports.getOrPut(gpa, new_export.opts.name);
63056284 if (gop.found_existing) {
63066285 new_export.status = .failed_retryable;
63076286 try mod.failed_exports.ensureUnusedCapacity(gpa, 1);
63086287 const src_loc = new_export.getSrcLoc(mod);
6309 const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {s}", .{
6310 mod.intern_pool.stringToSlice(new_export.name),
6288 const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {}", .{
6289 new_export.opts.name.fmt(&mod.intern_pool),
63116290 });
63126291 errdefer msg.destroy(gpa);
63136292 const other_export = gop.value_ptr.*;
......@@ -6752,18 +6731,9 @@ pub fn errorUnionType(mod: *Module, error_set_ty: Type, payload_ty: Type) Alloca
67526731 } })).toType();
67536732}
67546733
6755pub fn singleErrorSetType(mod: *Module, name: []const u8) Allocator.Error!Type {
6756 const gpa = mod.gpa;
6757 const ip = &mod.intern_pool;
6758 return singleErrorSetTypeNts(mod, try ip.getOrPutString(gpa, name));
6759}
6760
6761pub fn singleErrorSetTypeNts(mod: *Module, name: InternPool.NullTerminatedString) Allocator.Error!Type {
6762 const gpa = mod.gpa;
6763 const ip = &mod.intern_pool;
6764 const names = [1]InternPool.NullTerminatedString{name};
6765 const i = try ip.get(gpa, .{ .error_set_type = .{ .names = &names } });
6766 return i.toType();
6734pub fn singleErrorSetType(mod: *Module, name: InternPool.NullTerminatedString) Allocator.Error!Type {
6735 const names: *const [1]InternPool.NullTerminatedString = &name;
6736 return (try mod.intern_pool.get(mod.gpa, .{ .error_set_type = .{ .names = names } })).toType();
67676737}
67686738
67696739/// Sorts `names` in place.
src/Sema.zig+386-416
......@@ -309,17 +309,17 @@ pub const Block = struct {
309309 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };
310310 break :blk src_loc;
311311 } else blk: {
312 const src_decl = sema.mod.declPtr(rt.block.src_decl);
312 const src_decl = mod.declPtr(rt.block.src_decl);
313313 break :blk rt.func_src.toSrcLoc(src_decl, mod);
314314 };
315315 if (rt.return_ty.isGenericPoison()) {
316 return sema.mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
316 return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
317317 }
318 try sema.mod.errNoteNonLazy(
318 try mod.errNoteNonLazy(
319319 src_loc,
320320 parent,
321321 prefix ++ "the function returns a comptime-only type '{}'",
322 .{rt.return_ty.fmt(sema.mod)},
322 .{rt.return_ty.fmt(mod)},
323323 );
324324 try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty);
325325 },
......@@ -2825,7 +2825,6 @@ fn createAnonymousDeclTypeNamed(
28252825) !Decl.Index {
28262826 const mod = sema.mod;
28272827 const gpa = sema.gpa;
2828 const ip = &mod.intern_pool;
28292828 const namespace = block.namespace;
28302829 const src_scope = block.wip_capture_scope;
28312830 const src_decl = mod.declPtr(block.src_decl);
......@@ -2842,12 +2841,8 @@ fn createAnonymousDeclTypeNamed(
28422841 // This name is also used as the key in the parent namespace so it cannot be
28432842 // renamed.
28442843
2845 // This ensureUnusedCapacity protects against the src_decl slice from being
2846 // reallocated during the call to `getOrPutStringFmt`.
2847 try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(src_decl.name).len +
2848 anon_prefix.len + 20);
2849 const name = ip.getOrPutStringFmt(gpa, "{s}__{s}_{d}", .{
2850 ip.stringToSlice(src_decl.name), anon_prefix, @enumToInt(new_decl_index),
2844 const name = mod.intern_pool.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{
2845 src_decl.name.fmt(&mod.intern_pool), anon_prefix, @enumToInt(new_decl_index),
28512846 }) catch unreachable;
28522847 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);
28532848 return new_decl_index;
......@@ -2863,8 +2858,9 @@ fn createAnonymousDeclTypeNamed(
28632858
28642859 var buf = std.ArrayList(u8).init(gpa);
28652860 defer buf.deinit();
2866 try buf.appendSlice(ip.stringToSlice(mod.declPtr(block.src_decl).name));
2867 try buf.appendSlice("(");
2861
2862 const writer = buf.writer();
2863 try writer.print("{}(", .{mod.declPtr(block.src_decl).name.fmt(&mod.intern_pool)});
28682864
28692865 var arg_i: usize = 0;
28702866 for (fn_info.param_body) |zir_inst| switch (zir_tags[zir_inst]) {
......@@ -2878,8 +2874,8 @@ fn createAnonymousDeclTypeNamed(
28782874 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch
28792875 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);
28802876
2881 if (arg_i != 0) try buf.appendSlice(",");
2882 try buf.writer().print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)});
2877 if (arg_i != 0) try writer.writeByte(',');
2878 try writer.print("{}", .{arg_val.fmtValue(sema.typeOf(arg), sema.mod)});
28832879
28842880 arg_i += 1;
28852881 continue;
......@@ -2887,8 +2883,8 @@ fn createAnonymousDeclTypeNamed(
28872883 else => continue,
28882884 };
28892885
2890 try buf.appendSlice(")");
2891 const name = try ip.getOrPutString(gpa, buf.items);
2886 try writer.writeByte(')');
2887 const name = try mod.intern_pool.getOrPutString(gpa, buf.items);
28922888 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);
28932889 return new_decl_index;
28942890 },
......@@ -2901,17 +2897,9 @@ fn createAnonymousDeclTypeNamed(
29012897 .dbg_var_ptr, .dbg_var_val => {
29022898 if (zir_data[i].str_op.operand != ref) continue;
29032899
2904 // This ensureUnusedCapacity protects against the src_decl
2905 // slice from being reallocated during the call to
2906 // `getOrPutStringFmt`.
2907 const zir_str = zir_data[i].str_op.getStr(sema.code);
2908 try ip.string_bytes.ensureUnusedCapacity(
2909 gpa,
2910 ip.stringToSlice(src_decl.name).len + zir_str.len + 10,
2911 );
2912 const name = ip.getOrPutStringFmt(gpa, "{s}.{s}", .{
2913 ip.stringToSlice(src_decl.name), zir_str,
2914 }) catch unreachable;
2900 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}.{s}", .{
2901 src_decl.name.fmt(&mod.intern_pool), zir_data[i].str_op.getStr(sema.code),
2902 });
29152903
29162904 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name);
29172905 return new_decl_index;
......@@ -4538,8 +4526,8 @@ fn validateStructInit(
45384526 continue;
45394527 }
45404528 const field_name = struct_ty.structFieldName(i, mod);
4541 const template = "missing struct field: {s}";
4542 const args = .{ip.stringToSlice(field_name)};
4529 const template = "missing struct field: {}";
4530 const args = .{field_name.fmt(ip)};
45434531 if (root_msg) |msg| {
45444532 try sema.errNote(block, init_src, msg, template, args);
45454533 } else {
......@@ -4560,12 +4548,12 @@ fn validateStructInit(
45604548
45614549 if (root_msg) |msg| {
45624550 if (mod.typeToStruct(struct_ty)) |struct_obj| {
4563 const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod));
4551 const fqn = try struct_obj.getFullyQualifiedName(mod);
45644552 try mod.errNoteNonLazy(
45654553 struct_obj.srcLoc(mod),
45664554 msg,
4567 "struct '{s}' declared here",
4568 .{fqn},
4555 "struct '{}' declared here",
4556 .{fqn.fmt(ip)},
45694557 );
45704558 }
45714559 root_msg = null;
......@@ -4682,8 +4670,8 @@ fn validateStructInit(
46824670 continue;
46834671 }
46844672 const field_name = struct_ty.structFieldName(i, mod);
4685 const template = "missing struct field: {s}";
4686 const args = .{ip.stringToSlice(field_name)};
4673 const template = "missing struct field: {}";
4674 const args = .{field_name.fmt(ip)};
46874675 if (root_msg) |msg| {
46884676 try sema.errNote(block, init_src, msg, template, args);
46894677 } else {
......@@ -4696,12 +4684,12 @@ fn validateStructInit(
46964684
46974685 if (root_msg) |msg| {
46984686 if (mod.typeToStruct(struct_ty)) |struct_obj| {
4699 const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod));
4700 try sema.mod.errNoteNonLazy(
4687 const fqn = try struct_obj.getFullyQualifiedName(mod);
4688 try mod.errNoteNonLazy(
47014689 struct_obj.srcLoc(mod),
47024690 msg,
4703 "struct '{s}' declared here",
4704 .{fqn},
4691 "struct '{}' declared here",
4692 .{fqn.fmt(ip)},
47054693 );
47064694 }
47074695 root_msg = null;
......@@ -4942,11 +4930,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
49424930 const operand_ty = sema.typeOf(operand);
49434931
49444932 if (operand_ty.zigTypeTag(mod) != .Pointer) {
4945 return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(sema.mod)});
4933 return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(mod)});
49464934 } else switch (operand_ty.ptrSize(mod)) {
49474935 .One, .C => {},
4948 .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(sema.mod)}),
4949 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}),
4936 .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(mod)}),
4937 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(mod)}),
49504938 }
49514939
49524940 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) {
......@@ -4965,11 +4953,11 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
49654953 block,
49664954 src,
49674955 "values of type '{}' must be comptime-known, but operand value is runtime-known",
4968 .{elem_ty.fmt(sema.mod)},
4956 .{elem_ty.fmt(mod)},
49694957 );
49704958 errdefer msg.destroy(sema.gpa);
49714959
4972 const src_decl = sema.mod.declPtr(block.src_decl);
4960 const src_decl = mod.declPtr(block.src_decl);
49734961 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty);
49744962 break :msg msg;
49754963 };
......@@ -4982,7 +4970,7 @@ fn failWithBadMemberAccess(
49824970 block: *Block,
49834971 agg_ty: Type,
49844972 field_src: LazySrcLoc,
4985 field_name_nts: InternPool.NullTerminatedString,
4973 field_name: InternPool.NullTerminatedString,
49864974) CompileError {
49874975 const mod = sema.mod;
49884976 const kw_name = switch (agg_ty.zigTypeTag(mod)) {
......@@ -4992,15 +4980,14 @@ fn failWithBadMemberAccess(
49924980 .Enum => "enum",
49934981 else => unreachable,
49944982 };
4995 const field_name = mod.intern_pool.stringToSlice(field_name_nts);
4996 if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (sema.mod.declIsRoot(some)) {
4997 return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{
4998 agg_ty.fmt(sema.mod), field_name,
4983 if (agg_ty.getOwnerDeclOrNull(mod)) |some| if (mod.declIsRoot(some)) {
4984 return sema.fail(block, field_src, "root struct of file '{}' has no member named '{}'", .{
4985 agg_ty.fmt(mod), field_name.fmt(&mod.intern_pool),
49994986 });
50004987 };
50014988 const msg = msg: {
5002 const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{s}'", .{
5003 kw_name, agg_ty.fmt(sema.mod), field_name,
4989 const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{}'", .{
4990 kw_name, agg_ty.fmt(mod), field_name.fmt(&mod.intern_pool),
50044991 });
50054992 errdefer msg.destroy(sema.gpa);
50064993 try sema.addDeclaredHereNote(msg, agg_ty);
......@@ -5018,16 +5005,15 @@ fn failWithBadStructFieldAccess(
50185005) CompileError {
50195006 const mod = sema.mod;
50205007 const gpa = sema.gpa;
5021 const ip = &mod.intern_pool;
50225008
5023 const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod));
5009 const fqn = try struct_obj.getFullyQualifiedName(mod);
50245010
50255011 const msg = msg: {
50265012 const msg = try sema.errMsg(
50275013 block,
50285014 field_src,
5029 "no field named '{s}' in struct '{s}'",
5030 .{ ip.stringToSlice(field_name), fqn },
5015 "no field named '{}' in struct '{}'",
5016 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
50315017 );
50325018 errdefer msg.destroy(gpa);
50335019 try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{});
......@@ -5045,16 +5031,15 @@ fn failWithBadUnionFieldAccess(
50455031) CompileError {
50465032 const mod = sema.mod;
50475033 const gpa = sema.gpa;
5048 const ip = &mod.intern_pool;
50495034
5050 const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod));
5035 const fqn = try union_obj.getFullyQualifiedName(mod);
50515036
50525037 const msg = msg: {
50535038 const msg = try sema.errMsg(
50545039 block,
50555040 field_src,
5056 "no field named '{s}' in union '{s}'",
5057 .{ ip.stringToSlice(field_name), fqn },
5041 "no field named '{}' in union '{}'",
5042 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
50585043 );
50595044 errdefer msg.destroy(gpa);
50605045 try mod.errNoteNonLazy(union_obj.srcLoc(mod), msg, "union declared here", .{});
......@@ -5334,7 +5319,9 @@ fn zirCompileLog(
53345319 sema: *Sema,
53355320 extended: Zir.Inst.Extended.InstData,
53365321) CompileError!Air.Inst.Ref {
5337 var managed = sema.mod.compile_log_text.toManaged(sema.gpa);
5322 const mod = sema.mod;
5323
5324 var managed = mod.compile_log_text.toManaged(sema.gpa);
53385325 defer sema.mod.compile_log_text = managed.moveToUnmanaged();
53395326 const writer = managed.writer();
53405327
......@@ -5349,16 +5336,16 @@ fn zirCompileLog(
53495336 const arg_ty = sema.typeOf(arg);
53505337 if (try sema.resolveMaybeUndefLazyVal(arg)) |val| {
53515338 try writer.print("@as({}, {})", .{
5352 arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod),
5339 arg_ty.fmt(mod), val.fmtValue(arg_ty, mod),
53535340 });
53545341 } else {
5355 try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(sema.mod)});
5342 try writer.print("@as({}, [runtime value])", .{arg_ty.fmt(mod)});
53565343 }
53575344 }
53585345 try writer.print("\n", .{});
53595346
53605347 const decl_index = if (sema.func) |some| some.owner_decl else sema.owner_decl_index;
5361 const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
5348 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
53625349 if (!gop.found_existing) {
53635350 gop.value_ptr.* = src_node;
53645351 }
......@@ -5509,7 +5496,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
55095496 if (!mod.comp.bin_file.options.link_libc)
55105497 try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{});
55115498
5512 const gop = try sema.mod.cimport_errors.getOrPut(sema.gpa, sema.owner_decl_index);
5499 const gop = try mod.cimport_errors.getOrPut(sema.gpa, sema.owner_decl_index);
55135500 if (!gop.found_existing) {
55145501 var errs = try std.ArrayListUnmanaged(Module.CImportError).initCapacity(sema.gpa, c_import_res.errors.len);
55155502 errdefer {
......@@ -5869,13 +5856,13 @@ pub fn analyzeExport(
58695856 sema: *Sema,
58705857 block: *Block,
58715858 src: LazySrcLoc,
5872 borrowed_options: std.builtin.ExportOptions,
5859 options: Module.Export.Options,
58735860 exported_decl_index: Decl.Index,
58745861) !void {
58755862 const Export = Module.Export;
58765863 const mod = sema.mod;
58775864
5878 if (borrowed_options.linkage == .Internal) {
5865 if (options.linkage == .Internal) {
58795866 return;
58805867 }
58815868
......@@ -5884,10 +5871,10 @@ pub fn analyzeExport(
58845871
58855872 if (!try sema.validateExternType(exported_decl.ty, .other)) {
58865873 const msg = msg: {
5887 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(sema.mod)});
5874 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(mod)});
58885875 errdefer msg.destroy(sema.gpa);
58895876
5890 const src_decl = sema.mod.declPtr(block.src_decl);
5877 const src_decl = mod.declPtr(block.src_decl);
58915878 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), exported_decl.ty, .other);
58925879
58935880 try sema.addDeclaredHereNote(msg, exported_decl.ty);
......@@ -5913,14 +5900,8 @@ pub fn analyzeExport(
59135900 const new_export = try gpa.create(Export);
59145901 errdefer gpa.destroy(new_export);
59155902
5916 const symbol_name = try mod.intern_pool.getOrPutString(gpa, borrowed_options.name);
5917 const section = try mod.intern_pool.getOrPutStringOpt(gpa, borrowed_options.section);
5918
59195903 new_export.* = .{
5920 .name = symbol_name,
5921 .linkage = borrowed_options.linkage,
5922 .section = section,
5923 .visibility = borrowed_options.visibility,
5904 .opts = options,
59245905 .src = src,
59255906 .owner_decl = sema.owner_decl_index,
59265907 .src_decl = block.src_decl,
......@@ -6198,7 +6179,7 @@ fn lookupInNamespace(
61986179
61996180 const namespace = mod.namespacePtr(namespace_index);
62006181 const namespace_decl_index = namespace.getDeclIndex(mod);
6201 const namespace_decl = sema.mod.declPtr(namespace_decl_index);
6182 const namespace_decl = mod.declPtr(namespace_decl_index);
62026183 if (namespace_decl.analysis == .file_failure) {
62036184 try mod.declareDeclDependency(sema.owner_decl_index, namespace_decl_index);
62046185 return error.AnalysisFail;
......@@ -6531,7 +6512,7 @@ fn zirCall(
65316512 // AstGen ensures that a call instruction is always preceded by a dbg_stmt instruction.
65326513 const call_dbg_node = inst - 1;
65336514
6534 if (sema.mod.backendSupportsFeature(.error_return_trace) and sema.mod.comp.bin_file.options.error_return_tracing and
6515 if (mod.backendSupportsFeature(.error_return_trace) and mod.comp.bin_file.options.error_return_tracing and
65356516 !block.is_comptime and !block.is_typeof and (input_is_error or pop_error_return_trace))
65366517 {
65376518 const call_inst: Air.Inst.Ref = if (modifier == .always_tail) undefined else b: {
......@@ -6599,7 +6580,7 @@ fn checkCallArgumentCount(
65996580 {
66006581 const msg = msg: {
66016582 const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{
6602 callee_ty.fmt(sema.mod),
6583 callee_ty.fmt(mod),
66036584 });
66046585 errdefer msg.destroy(sema.gpa);
66056586 try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
......@@ -6610,7 +6591,7 @@ fn checkCallArgumentCount(
66106591 },
66116592 else => {},
66126593 }
6613 return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(sema.mod)});
6594 return sema.fail(block, func_src, "type '{}' not a function", .{callee_ty.fmt(mod)});
66146595 };
66156596
66166597 const func_ty_info = mod.typeToFunc(func_ty).?;
......@@ -6640,7 +6621,7 @@ fn checkCallArgumentCount(
66406621 );
66416622 errdefer msg.destroy(sema.gpa);
66426623
6643 if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
6624 if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
66446625 break :msg msg;
66456626 };
66466627 return sema.failWithOwnedErrorMsg(msg);
......@@ -6666,7 +6647,7 @@ fn callBuiltin(
66666647 },
66676648 else => {},
66686649 }
6669 std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(sema.mod)});
6650 std.debug.panic("type '{}' is not a function calling builtin fn", .{callee_ty.fmt(mod)});
66706651 };
66716652
66726653 const func_ty_info = mod.typeToFunc(func_ty).?;
......@@ -6942,7 +6923,7 @@ fn analyzeCall(
69426923 ) catch |err| switch (err) {
69436924 error.NeededSourceLocation => {
69446925 _ = sema.inst_map.remove(inst);
6945 const decl = sema.mod.declPtr(block.src_decl);
6926 const decl = mod.declPtr(block.src_decl);
69466927 try sema.analyzeInlineCallArg(
69476928 block,
69486929 &child_block,
......@@ -7111,7 +7092,7 @@ fn analyzeCall(
71117092 opts,
71127093 ) catch |err| switch (err) {
71137094 error.NeededSourceLocation => {
7114 const decl = sema.mod.declPtr(block.src_decl);
7095 const decl = mod.declPtr(block.src_decl);
71157096 _ = try sema.analyzeCallArg(
71167097 block,
71177098 mod.argSrc(call_src.node_offset.x, decl, i, bound_arg_src),
......@@ -7126,7 +7107,7 @@ fn analyzeCall(
71267107 } else {
71277108 args[i] = sema.coerceVarArgParam(block, uncasted_arg, .unneeded) catch |err| switch (err) {
71287109 error.NeededSourceLocation => {
7129 const decl = sema.mod.declPtr(block.src_decl);
7110 const decl = mod.declPtr(block.src_decl);
71307111 _ = try sema.coerceVarArgParam(
71317112 block,
71327113 uncasted_arg,
......@@ -7148,7 +7129,7 @@ fn analyzeCall(
71487129
71497130 if (try sema.resolveMaybeUndefVal(func)) |func_val| {
71507131 if (mod.intern_pool.indexToFunc(func_val.toIntern()).unwrap()) |func_index| {
7151 try sema.mod.ensureFuncBodyAnalysisQueued(func_index);
7132 try mod.ensureFuncBodyAnalysisQueued(func_index);
71527133 }
71537134 }
71547135
......@@ -7201,17 +7182,18 @@ fn analyzeCall(
72017182}
72027183
72037184fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Type, result: Air.Inst.Ref) !Air.Inst.Ref {
7204 const target = sema.mod.getTarget();
7205 const backend = sema.mod.comp.getZigBackend();
7185 const mod = sema.mod;
7186 const target = mod.getTarget();
7187 const backend = mod.comp.getZigBackend();
72067188 if (!target_util.supportsTailCall(target, backend)) {
72077189 return sema.fail(block, call_src, "unable to perform tail call: compiler backend '{s}' does not support tail calls on target architecture '{s}' with the selected CPU feature flags", .{
72087190 @tagName(backend), @tagName(target.cpu.arch),
72097191 });
72107192 }
7211 const func_decl = sema.mod.declPtr(sema.owner_func.?.owner_decl);
7212 if (!func_ty.eql(func_decl.ty, sema.mod)) {
7193 const func_decl = mod.declPtr(sema.owner_func.?.owner_decl);
7194 if (!func_ty.eql(func_decl.ty, mod)) {
72137195 return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{
7214 func_ty.fmt(sema.mod), func_decl.ty.fmt(sema.mod),
7196 func_ty.fmt(mod), func_decl.ty.fmt(mod),
72157197 });
72167198 }
72177199 _ = try block.addUnOp(.ret, result);
......@@ -7404,10 +7386,9 @@ fn instantiateGenericCall(
74047386) CompileError!Air.Inst.Ref {
74057387 const mod = sema.mod;
74067388 const gpa = sema.gpa;
7407 const ip = &mod.intern_pool;
74087389
74097390 const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known");
7410 const module_fn_index = switch (ip.indexToKey(func_val.toIntern())) {
7391 const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
74117392 .func => |function| function.index,
74127393 .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.getFunctionIndex(mod).unwrap().?,
74137394 else => unreachable,
......@@ -7467,7 +7448,7 @@ fn instantiateGenericCall(
74677448 if (is_comptime) {
74687449 const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[arg_i]) catch |err| switch (err) {
74697450 error.NeededSourceLocation => {
7470 const decl = sema.mod.declPtr(block.src_decl);
7451 const decl = mod.declPtr(block.src_decl);
74717452 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
74727453 _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[arg_i]);
74737454 unreachable;
......@@ -7491,7 +7472,7 @@ fn instantiateGenericCall(
74917472 };
74927473 const casted_arg = sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], .unneeded) catch |err| switch (err) {
74937474 error.NeededSourceLocation => {
7494 const decl = sema.mod.declPtr(block.src_decl);
7475 const decl = mod.declPtr(block.src_decl);
74957476 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
74967477 _ = try sema.coerce(block, final_arg_ty.toType(), uncasted_args[arg_i], arg_src);
74977478 unreachable;
......@@ -7500,7 +7481,7 @@ fn instantiateGenericCall(
75007481 };
75017482 const casted_arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, casted_arg) catch |err| switch (err) {
75027483 error.NeededSourceLocation => {
7503 const decl = sema.mod.declPtr(block.src_decl);
7484 const decl = mod.declPtr(block.src_decl);
75047485 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
75057486 _ = try sema.analyzeGenericCallArgVal(block, arg_src, casted_arg);
75067487 unreachable;
......@@ -7540,12 +7521,9 @@ fn instantiateGenericCall(
75407521 const new_decl_index = try mod.allocateNewDecl(namespace_index, fn_owner_decl.src_node, src_decl.src_scope);
75417522 const new_decl = mod.declPtr(new_decl_index);
75427523 // TODO better names for generic function instantiations
7543 // The ensureUnusedCapacity here protects against fn_owner_decl.name slice being
7544 // reallocated during getOrPutStringFmt.
7545 try ip.string_bytes.ensureUnusedCapacity(gpa, ip.stringToSlice(fn_owner_decl.name).len + 20);
7546 const decl_name = ip.getOrPutStringFmt(gpa, "{s}__anon_{d}", .{
7547 ip.stringToSlice(fn_owner_decl.name), @enumToInt(new_decl_index),
7548 }) catch unreachable;
7524 const decl_name = try mod.intern_pool.getOrPutStringFmt(gpa, "{}__anon_{d}", .{
7525 fn_owner_decl.name.fmt(&mod.intern_pool), @enumToInt(new_decl_index),
7526 });
75497527 new_decl.name = decl_name;
75507528 new_decl.src_line = fn_owner_decl.src_line;
75517529 new_decl.is_pub = fn_owner_decl.is_pub;
......@@ -7634,7 +7612,7 @@ fn instantiateGenericCall(
76347612 &runtime_i,
76357613 ) catch |err| switch (err) {
76367614 error.NeededSourceLocation => {
7637 const decl = sema.mod.declPtr(block.src_decl);
7615 const decl = mod.declPtr(block.src_decl);
76387616 _ = try sema.analyzeGenericCallArg(
76397617 block,
76407618 mod.argSrc(call_src.node_offset.x, decl, total_i, bound_arg_src),
......@@ -7660,7 +7638,7 @@ fn instantiateGenericCall(
76607638 sema.owner_func.?.calls_or_awaits_errorable_fn = true;
76617639 }
76627640
7663 try sema.mod.ensureFuncBodyAnalysisQueued(callee_index);
7641 try mod.ensureFuncBodyAnalysisQueued(callee_index);
76647642
76657643 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len +
76667644 runtime_args_len);
......@@ -7788,7 +7766,7 @@ fn resolveGenericInstantiationType(
77887766 if (try sema.typeRequiresComptime(arg_ty)) {
77897767 const arg_val = sema.resolveConstValue(block, .unneeded, arg, "") catch |err| switch (err) {
77907768 error.NeededSourceLocation => {
7791 const decl = sema.mod.declPtr(block.src_decl);
7769 const decl = mod.declPtr(block.src_decl);
77927770 const arg_src = mod.argSrc(call_src.node_offset.x, decl, arg_i, bound_arg_src);
77937771 _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known");
77947772 unreachable;
......@@ -7981,9 +7959,9 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
79817959 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
79827960 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
79837961 if (child_type.zigTypeTag(mod) == .Opaque) {
7984 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(sema.mod)});
7962 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)});
79857963 } else if (child_type.zigTypeTag(mod) == .Null) {
7986 return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(sema.mod)});
7964 return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(mod)});
79877965 }
79887966 const opt_type = try Type.optional(sema.arena, child_type, mod);
79897967
......@@ -8059,7 +8037,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
80598037fn validateArrayElemType(sema: *Sema, block: *Block, elem_type: Type, elem_src: LazySrcLoc) !void {
80608038 const mod = sema.mod;
80618039 if (elem_type.zigTypeTag(mod) == .Opaque) {
8062 return sema.fail(block, elem_src, "array of opaque type '{}' not allowed", .{elem_type.fmt(sema.mod)});
8040 return sema.fail(block, elem_src, "array of opaque type '{}' not allowed", .{elem_type.fmt(mod)});
80638041 } else if (elem_type.zigTypeTag(mod) == .NoReturn) {
80648042 return sema.fail(block, elem_src, "array of 'noreturn' not allowed", .{});
80658043 }
......@@ -8095,7 +8073,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
80958073
80968074 if (error_set.zigTypeTag(mod) != .ErrorSet) {
80978075 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{
8098 error_set.fmt(sema.mod),
8076 error_set.fmt(mod),
80998077 });
81008078 }
81018079 try sema.validateErrorUnionPayloadType(block, payload, rhs_src);
......@@ -8107,11 +8085,11 @@ fn validateErrorUnionPayloadType(sema: *Sema, block: *Block, payload_ty: Type, p
81078085 const mod = sema.mod;
81088086 if (payload_ty.zigTypeTag(mod) == .Opaque) {
81098087 return sema.fail(block, payload_src, "error union with payload of opaque type '{}' not allowed", .{
8110 payload_ty.fmt(sema.mod),
8088 payload_ty.fmt(mod),
81118089 });
81128090 } else if (payload_ty.zigTypeTag(mod) == .ErrorSet) {
81138091 return sema.fail(block, payload_src, "error union with payload of error set type '{}' not allowed", .{
8114 payload_ty.fmt(sema.mod),
8092 payload_ty.fmt(mod),
81158093 });
81168094 }
81178095}
......@@ -8123,7 +8101,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
81238101 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
81248102 _ = try mod.getErrorValue(name);
81258103 // Create an error set type with only this error value, and return the value.
8126 const error_set_type = try mod.singleErrorSetTypeNts(name);
8104 const error_set_type = try mod.singleErrorSetType(name);
81278105 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
81288106 .ty = error_set_type.toIntern(),
81298107 .name = name,
......@@ -8231,9 +8209,9 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
82318209 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);
82328210 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);
82338211 if (lhs_ty.zigTypeTag(mod) != .ErrorSet)
8234 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{lhs_ty.fmt(sema.mod)});
8212 return sema.fail(block, lhs_src, "expected error set type, found '{}'", .{lhs_ty.fmt(mod)});
82358213 if (rhs_ty.zigTypeTag(mod) != .ErrorSet)
8236 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(sema.mod)});
8214 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(mod)});
82378215
82388216 // Anything merged with anyerror is anyerror.
82398217 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {
......@@ -8296,7 +8274,7 @@ fn zirEnumToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
82968274 },
82978275 else => {
82988276 return sema.fail(block, operand_src, "expected enum or tagged union, found '{}'", .{
8299 operand_ty.fmt(sema.mod),
8277 operand_ty.fmt(mod),
83008278 });
83018279 },
83028280 };
......@@ -8328,7 +8306,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
83288306 const operand = try sema.resolveInst(extra.rhs);
83298307
83308308 if (dest_ty.zigTypeTag(mod) != .Enum) {
8331 return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(sema.mod)});
8309 return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(mod)});
83328310 }
83338311 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
83348312
......@@ -8343,7 +8321,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
83438321 block,
83448322 src,
83458323 "int value '{}' out of range of non-exhaustive enum '{}'",
8346 .{ int_val.fmtValue(sema.typeOf(operand), sema.mod), dest_ty.fmt(sema.mod) },
8324 .{ int_val.fmtValue(sema.typeOf(operand), mod), dest_ty.fmt(mod) },
83478325 );
83488326 errdefer msg.destroy(sema.gpa);
83498327 try sema.addDeclaredHereNote(msg, dest_ty);
......@@ -8360,7 +8338,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
83608338 block,
83618339 src,
83628340 "enum '{}' has no tag with value '{}'",
8363 .{ dest_ty.fmt(sema.mod), int_val.fmtValue(sema.typeOf(operand), sema.mod) },
8341 .{ dest_ty.fmt(mod), int_val.fmtValue(sema.typeOf(operand), mod) },
83648342 );
83658343 errdefer msg.destroy(sema.gpa);
83668344 try sema.addDeclaredHereNote(msg, dest_ty);
......@@ -8383,7 +8361,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
83838361 try sema.requireRuntimeBlock(block, src, operand_src);
83848362 const result = try block.addTyOp(.intcast, dest_ty, operand);
83858363 if (block.wantSafety() and !dest_ty.isNonexhaustiveEnum(mod) and
8386 sema.mod.backendSupportsFeature(.is_named_enum_value))
8364 mod.backendSupportsFeature(.is_named_enum_value))
83878365 {
83888366 const ok = try block.addUnOp(.is_named_enum_value, result);
83898367 try sema.addSafetyCheck(block, ok, .invalid_enum_value);
......@@ -8422,11 +8400,11 @@ fn analyzeOptionalPayloadPtr(
84228400
84238401 const opt_type = optional_ptr_ty.childType(mod);
84248402 if (opt_type.zigTypeTag(mod) != .Optional) {
8425 return sema.fail(block, src, "expected optional type, found '{}'", .{opt_type.fmt(sema.mod)});
8403 return sema.fail(block, src, "expected optional type, found '{}'", .{opt_type.fmt(mod)});
84268404 }
84278405
84288406 const child_type = opt_type.optionalChild(mod);
8429 const child_pointer = try Type.ptr(sema.arena, sema.mod, .{
8407 const child_pointer = try Type.ptr(sema.arena, mod, .{
84308408 .pointee_type = child_type,
84318409 .mutable = !optional_ptr_ty.isConstPtr(mod),
84328410 .@"addrspace" = optional_ptr_ty.ptrAddressSpace(mod),
......@@ -8493,7 +8471,7 @@ fn zirOptionalPayload(
84938471 // TODO https://github.com/ziglang/zig/issues/6597
84948472 if (true) break :t operand_ty;
84958473 const ptr_info = operand_ty.ptrInfo(mod);
8496 break :t try Type.ptr(sema.arena, sema.mod, .{
8474 break :t try Type.ptr(sema.arena, mod, .{
84978475 .pointee_type = ptr_info.pointee_type,
84988476 .@"align" = ptr_info.@"align",
84998477 .@"addrspace" = ptr_info.@"addrspace",
......@@ -8538,7 +8516,7 @@ fn zirErrUnionPayload(
85388516 const err_union_ty = sema.typeOf(operand);
85398517 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
85408518 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{
8541 err_union_ty.fmt(sema.mod),
8519 err_union_ty.fmt(mod),
85428520 });
85438521 }
85448522 return sema.analyzeErrUnionPayload(block, src, err_union_ty, operand, operand_src, false);
......@@ -8556,8 +8534,8 @@ fn analyzeErrUnionPayload(
85568534 const mod = sema.mod;
85578535 const payload_ty = err_union_ty.errorUnionPayload(mod);
85588536 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
8559 if (val.getError(mod)) |name| {
8560 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
8537 if (val.getErrorName(mod).unwrap()) |name| {
8538 return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
85618539 }
85628540 return sema.addConstant(
85638541 payload_ty,
......@@ -8607,13 +8585,13 @@ fn analyzeErrUnionPayloadPtr(
86078585
86088586 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {
86098587 return sema.fail(block, src, "expected error union type, found '{}'", .{
8610 operand_ty.childType(mod).fmt(sema.mod),
8588 operand_ty.childType(mod).fmt(mod),
86118589 });
86128590 }
86138591
86148592 const err_union_ty = operand_ty.childType(mod);
86158593 const payload_ty = err_union_ty.errorUnionPayload(mod);
8616 const operand_pointer_ty = try Type.ptr(sema.arena, sema.mod, .{
8594 const operand_pointer_ty = try Type.ptr(sema.arena, mod, .{
86178595 .pointee_type = payload_ty,
86188596 .mutable = !operand_ty.isConstPtr(mod),
86198597 .@"addrspace" = operand_ty.ptrAddressSpace(mod),
......@@ -8634,8 +8612,8 @@ fn analyzeErrUnionPayloadPtr(
86348612 } })).toValue());
86358613 }
86368614 if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| {
8637 if (val.getError(mod)) |name| {
8638 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
8615 if (val.getErrorName(mod).unwrap()) |name| {
8616 return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
86398617 }
86408618 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{
86418619 .ty = operand_pointer_ty.toIntern(),
......@@ -8676,7 +8654,7 @@ fn analyzeErrUnionCode(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air
86768654 const operand_ty = sema.typeOf(operand);
86778655 if (operand_ty.zigTypeTag(mod) != .ErrorUnion) {
86788656 return sema.fail(block, src, "expected error union type, found '{}'", .{
8679 operand_ty.fmt(sema.mod),
8657 operand_ty.fmt(mod),
86808658 });
86818659 }
86828660
......@@ -8707,7 +8685,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
87078685
87088686 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {
87098687 return sema.fail(block, src, "expected error union type, found '{}'", .{
8710 operand_ty.childType(mod).fmt(sema.mod),
8688 operand_ty.childType(mod).fmt(mod),
87118689 });
87128690 }
87138691
......@@ -8715,7 +8693,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
87158693
87168694 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
87178695 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {
8718 assert(val.getError(mod) != null);
8696 assert(val.getErrorName(mod) != .none);
87198697 return sema.addConstant(result_ty, val);
87208698 }
87218699 }
......@@ -8968,7 +8946,7 @@ fn funcCommon(
89688946 };
89698947 errdefer if (destroy_fn_on_error) mod.destroyFunc(new_func_index);
89708948
8971 const target = sema.mod.getTarget();
8949 const target = mod.getTarget();
89728950 const fn_ty: Type = fn_ty: {
89738951 // In the case of generic calling convention, or generic alignment, we use
89748952 // default values which are only meaningful for the generic function, *not*
......@@ -8995,7 +8973,7 @@ fn funcCommon(
89958973 is_noalias,
89968974 ) catch |err| switch (err) {
89978975 error.NeededSourceLocation => {
8998 const decl = sema.mod.declPtr(block.src_decl);
8976 const decl = mod.declPtr(block.src_decl);
89998977 try sema.analyzeParameter(
90008978 block,
90018979 Module.paramSrc(src_node_offset, mod, decl, i),
......@@ -9040,7 +9018,7 @@ fn funcCommon(
90409018 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";
90419019 const msg = msg: {
90429020 const msg = try sema.errMsg(block, ret_ty_src, "{s}return type '{}' not allowed", .{
9043 opaque_str, return_type.fmt(sema.mod),
9021 opaque_str, return_type.fmt(mod),
90449022 });
90459023 errdefer msg.destroy(gpa);
90469024
......@@ -9054,11 +9032,11 @@ fn funcCommon(
90549032 {
90559033 const msg = msg: {
90569034 const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
9057 return_type.fmt(sema.mod), @tagName(cc_resolved),
9035 return_type.fmt(mod), @tagName(cc_resolved),
90589036 });
90599037 errdefer msg.destroy(gpa);
90609038
9061 const src_decl = sema.mod.declPtr(block.src_decl);
9039 const src_decl = mod.declPtr(block.src_decl);
90629040 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src.toSrcLoc(src_decl, mod), return_type, .ret_ty);
90639041
90649042 try sema.addDeclaredHereNote(msg, return_type);
......@@ -9077,7 +9055,7 @@ fn funcCommon(
90779055 block,
90789056 ret_ty_src,
90799057 "function with comptime-only return type '{}' requires all parameters to be comptime",
9080 .{return_type.fmt(sema.mod)},
9058 .{return_type.fmt(mod)},
90819059 );
90829060 try sema.explainWhyTypeIsComptime(msg, ret_ty_src.toSrcLoc(sema.owner_decl, mod), return_type);
90839061
......@@ -9102,7 +9080,7 @@ fn funcCommon(
91029080 return sema.failWithOwnedErrorMsg(msg);
91039081 }
91049082
9105 const arch = sema.mod.getTarget().cpu.arch;
9083 const arch = mod.getTarget().cpu.arch;
91069084 if (switch (cc_resolved) {
91079085 .Unspecified, .C, .Naked, .Async, .Inline => null,
91089086 .Interrupt => switch (arch) {
......@@ -9542,7 +9520,7 @@ fn zirPtrToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
95429520 const ptr = try sema.resolveInst(inst_data.operand);
95439521 const ptr_ty = sema.typeOf(ptr);
95449522 if (!ptr_ty.isPtrAtRuntime(mod)) {
9545 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)});
9523 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(mod)});
95469524 }
95479525 if (try sema.resolveMaybeUndefValIntable(ptr)) |ptr_val| {
95489526 return sema.addConstant(
......@@ -9797,14 +9775,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
97979775 .Type,
97989776 .Undefined,
97999777 .Void,
9800 => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)}),
9778 => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}),
98019779
98029780 .Enum => {
98039781 const msg = msg: {
9804 const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)});
9782 const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
98059783 errdefer msg.destroy(sema.gpa);
98069784 switch (operand_ty.zigTypeTag(mod)) {
9807 .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToEnum to cast from '{}'", .{operand_ty.fmt(sema.mod)}),
9785 .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToEnum to cast from '{}'", .{operand_ty.fmt(mod)}),
98089786 else => {},
98099787 }
98109788
......@@ -9815,11 +9793,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
98159793
98169794 .Pointer => {
98179795 const msg = msg: {
9818 const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)});
9796 const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
98199797 errdefer msg.destroy(sema.gpa);
98209798 switch (operand_ty.zigTypeTag(mod)) {
9821 .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToPtr to cast from '{}'", .{operand_ty.fmt(sema.mod)}),
9822 .Pointer => try sema.errNote(block, dest_ty_src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(sema.mod)}),
9799 .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToPtr to cast from '{}'", .{operand_ty.fmt(mod)}),
9800 .Pointer => try sema.errNote(block, dest_ty_src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
98239801 else => {},
98249802 }
98259803
......@@ -9834,7 +9812,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
98349812 else => unreachable,
98359813 };
98369814 return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'; {s} does not have a guaranteed in-memory layout", .{
9837 dest_ty.fmt(sema.mod), container,
9815 dest_ty.fmt(mod), container,
98389816 });
98399817 },
98409818
......@@ -9861,14 +9839,14 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
98619839 .Type,
98629840 .Undefined,
98639841 .Void,
9864 => return sema.fail(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(sema.mod)}),
9842 => return sema.fail(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}),
98659843
98669844 .Enum => {
98679845 const msg = msg: {
9868 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(sema.mod)});
9846 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
98699847 errdefer msg.destroy(sema.gpa);
98709848 switch (dest_ty.zigTypeTag(mod)) {
9871 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @enumToInt to cast to '{}'", .{dest_ty.fmt(sema.mod)}),
9849 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @enumToInt to cast to '{}'", .{dest_ty.fmt(mod)}),
98729850 else => {},
98739851 }
98749852
......@@ -9878,11 +9856,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
98789856 },
98799857 .Pointer => {
98809858 const msg = msg: {
9881 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(sema.mod)});
9859 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
98829860 errdefer msg.destroy(sema.gpa);
98839861 switch (dest_ty.zigTypeTag(mod)) {
9884 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @ptrToInt to cast to '{}'", .{dest_ty.fmt(sema.mod)}),
9885 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(sema.mod)}),
9862 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @ptrToInt to cast to '{}'", .{dest_ty.fmt(mod)}),
9863 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
98869864 else => {},
98879865 }
98889866
......@@ -9897,7 +9875,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
98979875 else => unreachable,
98989876 };
98999877 return sema.fail(block, operand_src, "cannot @bitCast from '{}'; {s} does not have a guaranteed in-memory layout", .{
9900 operand_ty.fmt(sema.mod), container,
9878 operand_ty.fmt(mod), container,
99019879 });
99029880 },
99039881
......@@ -9924,7 +9902,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
99249902 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
99259903 const operand = try sema.resolveInst(extra.rhs);
99269904
9927 const target = sema.mod.getTarget();
9905 const target = mod.getTarget();
99289906 const dest_is_comptime_float = switch (dest_ty.zigTypeTag(mod)) {
99299907 .ComptimeFloat => true,
99309908 .Float => false,
......@@ -9932,7 +9910,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
99329910 block,
99339911 dest_ty_src,
99349912 "expected float type, found '{}'",
9935 .{dest_ty.fmt(sema.mod)},
9913 .{dest_ty.fmt(mod)},
99369914 ),
99379915 };
99389916
......@@ -9943,7 +9921,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
99439921 block,
99449922 operand_src,
99459923 "expected float type, found '{}'",
9946 .{operand_ty.fmt(sema.mod)},
9924 .{operand_ty.fmt(mod)},
99479925 ),
99489926 }
99499927
......@@ -10002,7 +9980,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
100029980 const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node };
100039981 const msg = msg: {
100049982 const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{
10005 indexable_ty.fmt(sema.mod),
9983 indexable_ty.fmt(mod),
100069984 });
100079985 errdefer msg.destroy(sema.gpa);
100089986 if (indexable_ty.zigTypeTag(mod) == .Array) {
......@@ -10143,12 +10121,12 @@ fn zirSwitchCapture(
1014310121 const item_val = sema.resolveConstValue(block, .unneeded, block.inline_case_capture, undefined) catch unreachable;
1014410122 const resolved_item_val = try sema.resolveLazyValue(item_val);
1014510123 if (operand_ty.zigTypeTag(mod) == .Union) {
10146 const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(resolved_item_val, sema.mod).?);
10124 const field_index = @intCast(u32, operand_ty.unionTagFieldIndex(resolved_item_val, mod).?);
1014710125 const union_obj = mod.typeToUnion(operand_ty).?;
1014810126 const field_ty = union_obj.fields.values()[field_index].ty;
1014910127 if (try sema.resolveDefinedValue(block, sema.src, operand_ptr)) |union_val| {
1015010128 if (is_ref) {
10151 const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{
10129 const ptr_field_ty = try Type.ptr(sema.arena, mod, .{
1015210130 .pointee_type = field_ty,
1015310131 .mutable = operand_ptr_ty.ptrIsMutable(mod),
1015410132 .@"volatile" = operand_ptr_ty.isVolatilePtr(mod),
......@@ -10168,7 +10146,7 @@ fn zirSwitchCapture(
1016810146 );
1016910147 }
1017010148 if (is_ref) {
10171 const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{
10149 const ptr_field_ty = try Type.ptr(sema.arena, mod, .{
1017210150 .pointee_type = field_ty,
1017310151 .mutable = operand_ptr_ty.ptrIsMutable(mod),
1017410152 .@"volatile" = operand_ptr_ty.isVolatilePtr(mod),
......@@ -10221,7 +10199,7 @@ fn zirSwitchCapture(
1022110199 // Previous switch validation ensured this will succeed
1022210200 const first_item_val = sema.resolveConstValue(block, .unneeded, first_item, "") catch unreachable;
1022310201
10224 const first_field_index = @intCast(u32, operand_ty.unionTagFieldIndex(first_item_val, sema.mod).?);
10202 const first_field_index = @intCast(u32, operand_ty.unionTagFieldIndex(first_item_val, mod).?);
1022510203 const first_field = union_obj.fields.values()[first_field_index];
1022610204
1022710205 for (items[1..], 0..) |item, i| {
......@@ -10229,22 +10207,22 @@ fn zirSwitchCapture(
1022910207 // Previous switch validation ensured this will succeed
1023010208 const item_val = sema.resolveConstValue(block, .unneeded, item_ref, "") catch unreachable;
1023110209
10232 const field_index = operand_ty.unionTagFieldIndex(item_val, sema.mod).?;
10210 const field_index = operand_ty.unionTagFieldIndex(item_val, mod).?;
1023310211 const field = union_obj.fields.values()[field_index];
10234 if (!field.ty.eql(first_field.ty, sema.mod)) {
10212 if (!field.ty.eql(first_field.ty, mod)) {
1023510213 const msg = msg: {
1023610214 const raw_capture_src = Module.SwitchProngSrc{ .multi_capture = capture_info.prong_index };
10237 const capture_src = raw_capture_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
10215 const capture_src = raw_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_info.src_node, .first);
1023810216
1023910217 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});
1024010218 errdefer msg.destroy(gpa);
1024110219
1024210220 const raw_first_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 0 } };
10243 const first_item_src = raw_first_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
10221 const first_item_src = raw_first_item_src.resolve(mod, mod.declPtr(block.src_decl), switch_info.src_node, .first);
1024410222 const raw_item_src = Module.SwitchProngSrc{ .multi = .{ .prong = capture_info.prong_index, .item = 1 + @intCast(u32, i) } };
10245 const item_src = raw_item_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_info.src_node, .first);
10246 try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(sema.mod)});
10247 try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(sema.mod)});
10223 const item_src = raw_item_src.resolve(mod, mod.declPtr(block.src_decl), switch_info.src_node, .first);
10224 try sema.errNote(block, first_item_src, msg, "type '{}' here", .{first_field.ty.fmt(mod)});
10225 try sema.errNote(block, item_src, msg, "type '{}' here", .{field.ty.fmt(mod)});
1024810226 break :msg msg;
1024910227 };
1025010228 return sema.failWithOwnedErrorMsg(msg);
......@@ -10252,7 +10230,7 @@ fn zirSwitchCapture(
1025210230 }
1025310231
1025410232 if (is_ref) {
10255 const field_ty_ptr = try Type.ptr(sema.arena, sema.mod, .{
10233 const field_ty_ptr = try Type.ptr(sema.arena, mod, .{
1025610234 .pointee_type = first_field.ty,
1025710235 .@"addrspace" = .generic,
1025810236 .mutable = operand_ptr_ty.ptrIsMutable(mod),
......@@ -10288,8 +10266,7 @@ fn zirSwitchCapture(
1028810266 const item_ref = try sema.resolveInst(item);
1028910267 // Previous switch validation ensured this will succeed
1029010268 const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable;
10291 const name_ip = try mod.intern_pool.getOrPutString(gpa, item_val.getError(mod).?);
10292 names.putAssumeCapacityNoClobber(name_ip, {});
10269 names.putAssumeCapacityNoClobber(item_val.getErrorName(mod).unwrap().?, {});
1029310270 }
1029410271 const else_error_ty = try mod.errorSetFromUnsortedNames(names.keys());
1029510272
......@@ -10299,7 +10276,7 @@ fn zirSwitchCapture(
1029910276 // Previous switch validation ensured this will succeed
1030010277 const item_val = sema.resolveConstLazyValue(block, .unneeded, item_ref, "") catch unreachable;
1030110278
10302 const item_ty = try mod.singleErrorSetType(item_val.getError(mod).?);
10279 const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?);
1030310280 return sema.bitCast(block, item_ty, operand, operand_src, null);
1030410281 }
1030510282 },
......@@ -10331,7 +10308,7 @@ fn zirSwitchCaptureTag(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
1033110308 if (operand_ty.zigTypeTag(mod) != .Union) {
1033210309 const msg = msg: {
1033310310 const msg = try sema.errMsg(block, src, "cannot capture tag of non-union type '{}'", .{
10334 operand_ty.fmt(sema.mod),
10311 operand_ty.fmt(mod),
1033510312 });
1033610313 errdefer msg.destroy(sema.gpa);
1033710314 try sema.addDeclaredHereNote(msg, operand_ty);
......@@ -10375,7 +10352,7 @@ fn zirSwitchCond(
1037510352 .Enum,
1037610353 => {
1037710354 if (operand_ty.isSlice(mod)) {
10378 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)});
10355 return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(mod)});
1037910356 }
1038010357 if ((try sema.typeHasOnePossibleValue(operand_ty))) |opv| {
1038110358 return sema.addConstant(operand_ty, opv);
......@@ -10389,8 +10366,8 @@ fn zirSwitchCond(
1038910366 const msg = msg: {
1039010367 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});
1039110368 errdefer msg.destroy(sema.gpa);
10392 if (union_ty.declSrcLocOrNull(sema.mod)) |union_src| {
10393 try sema.mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});
10369 if (union_ty.declSrcLocOrNull(mod)) |union_src| {
10370 try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});
1039410371 }
1039510372 break :msg msg;
1039610373 };
......@@ -10410,11 +10387,11 @@ fn zirSwitchCond(
1041010387 .Vector,
1041110388 .Frame,
1041210389 .AnyFrame,
10413 => return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(sema.mod)}),
10390 => return sema.fail(block, src, "switch on type '{}'", .{operand_ty.fmt(mod)}),
1041410391 }
1041510392}
1041610393
10417const SwitchErrorSet = std.StringHashMap(Module.SwitchProngSrc);
10394const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc);
1041810395
1041910396fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1042010397 const tracy = trace(@src());
......@@ -10593,8 +10570,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1059310570 operand_ty,
1059410571 i,
1059510572 msg,
10596 "unhandled enumeration value: '{s}'",
10597 .{ip.stringToSlice(field_name)},
10573 "unhandled enumeration value: '{}'",
10574 .{field_name.fmt(&mod.intern_pool)},
1059810575 );
1059910576 }
1060010577 try mod.errNoteNonLazy(
......@@ -10677,8 +10654,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1067710654 var maybe_msg: ?*Module.ErrorMsg = null;
1067810655 errdefer if (maybe_msg) |msg| msg.destroy(sema.gpa);
1067910656
10680 for (operand_ty.errorSetNames(mod)) |error_name_ip| {
10681 const error_name = ip.stringToSlice(error_name_ip);
10657 for (operand_ty.errorSetNames(mod)) |error_name| {
1068210658 if (!seen_errors.contains(error_name) and special_prong != .@"else") {
1068310659 const msg = maybe_msg orelse blk: {
1068410660 maybe_msg = try sema.errMsg(
......@@ -10694,8 +10670,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1069410670 block,
1069510671 src,
1069610672 msg,
10697 "unhandled error value: 'error.{s}'",
10698 .{error_name},
10673 "unhandled error value: 'error.{}'",
10674 .{error_name.fmt(ip)},
1069910675 );
1070010676 }
1070110677 }
......@@ -10746,11 +10722,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1074610722 const error_names = operand_ty.errorSetNames(mod);
1074710723 var names: Module.Fn.InferredErrorSet.NameMap = .{};
1074810724 try names.ensureUnusedCapacity(sema.arena, error_names.len);
10749 for (error_names) |error_name_ip| {
10750 const error_name = ip.stringToSlice(error_name_ip);
10725 for (error_names) |error_name| {
1075110726 if (seen_errors.contains(error_name)) continue;
1075210727
10753 names.putAssumeCapacityNoClobber(error_name_ip, {});
10728 names.putAssumeCapacityNoClobber(error_name, {});
1075410729 }
1075510730 // No need to keep the hash map metadata correct; here we
1075610731 // extract the (sorted) keys only.
......@@ -11500,14 +11475,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1150011475 });
1150111476 }
1150211477 for (0..operand_ty.errorSetNames(mod).len) |i| {
11503 const error_name_ip = operand_ty.errorSetNames(mod)[i];
11504 const error_name = mod.intern_pool.stringToSlice(error_name_ip);
11478 const error_name = operand_ty.errorSetNames(mod)[i];
1150511479 if (seen_errors.contains(error_name)) continue;
1150611480 cases_len += 1;
1150711481
1150811482 const item_val = try mod.intern(.{ .err = .{
1150911483 .ty = operand_ty.toIntern(),
11510 .name = error_name_ip,
11484 .name = error_name,
1151111485 } });
1151211486 const item_ref = try sema.addConstant(operand_ty, item_val.toValue());
1151311487 case_block.inline_case_capture = item_ref;
......@@ -11754,7 +11728,7 @@ fn resolveSwitchItemVal(
1175411728 return val.toIntern();
1175511729 } else |err| switch (err) {
1175611730 error.NeededSourceLocation => {
11757 const src = switch_prong_src.resolve(mod, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand);
11731 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
1175811732 _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known");
1175911733 unreachable;
1176011734 },
......@@ -11827,7 +11801,7 @@ fn validateSwitchItemError(
1182711801 const ip = &sema.mod.intern_pool;
1182811802 const item = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none);
1182911803 // TODO: Do i need to typecheck here?
11830 const error_name = ip.stringToSlice(ip.indexToKey(item).err.name);
11804 const error_name = ip.indexToKey(item).err.name;
1183111805 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|
1183211806 prev.value
1183311807 else
......@@ -11844,7 +11818,7 @@ fn validateSwitchDupe(
1184411818) CompileError!void {
1184511819 const prev_prong_src = maybe_prev_src orelse return;
1184611820 const mod = sema.mod;
11847 const block_src_decl = sema.mod.declPtr(block.src_decl);
11821 const block_src_decl = mod.declPtr(block.src_decl);
1184811822 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
1184911823 const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
1185011824 const msg = msg: {
......@@ -11884,7 +11858,7 @@ fn validateSwitchItemBool(
1188411858 false_count.* += 1;
1188511859 }
1188611860 if (true_count.* + false_count.* > 2) {
11887 const block_src_decl = sema.mod.declPtr(block.src_decl);
11861 const block_src_decl = mod.declPtr(block.src_decl);
1188811862 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
1188911863 return sema.fail(block, src, "duplicate switch value", .{});
1189011864 }
......@@ -12020,7 +11994,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind
1202011994 }
1202111995 if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| {
1202211996 if (!operand_ty.isError(mod)) return;
12023 if (val.getError(mod) == null) return;
11997 if (val.getErrorName(mod) == .none) return;
1202411998 try sema.maybeErrorUnwrapComptime(block, body, err_operand);
1202511999 }
1202612000}
......@@ -12042,8 +12016,8 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I
1204212016 const src = inst_data.src();
1204312017
1204412018 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
12045 if (val.getError(sema.mod)) |name| {
12046 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
12019 if (val.getErrorName(sema.mod).unwrap()) |name| {
12020 return sema.fail(block, src, "caught unexpected error '{}'", .{name.fmt(&sema.mod.intern_pool)});
1204712021 }
1204812022 }
1204912023}
......@@ -12073,7 +12047,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1207312047 if (anon_struct.names.len != 0) {
1207412048 break :hf mem.indexOfScalar(InternPool.NullTerminatedString, anon_struct.names, field_name) != null;
1207512049 } else {
12076 const field_index = std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10) catch break :hf false;
12050 const field_index = field_name.toUnsigned(ip) orelse break :hf false;
1207712051 break :hf field_index < ty.structFieldCount(mod);
1207812052 }
1207912053 },
......@@ -12094,7 +12068,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1209412068 else => {},
1209512069 }
1209612070 return sema.fail(block, ty_src, "type '{}' does not support '@hasField'", .{
12097 ty.fmt(sema.mod),
12071 ty.fmt(mod),
1209812072 });
1209912073 };
1210012074 if (has_field) {
......@@ -12209,7 +12183,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R
1220912183 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
1221012184 const name = try mod.intern_pool.getOrPutString(sema.gpa, inst_data.get(sema.code));
1221112185 _ = try mod.getErrorValue(name);
12212 const error_set_type = try mod.singleErrorSetTypeNts(name);
12186 const error_set_type = try mod.singleErrorSetType(name);
1221312187 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
1221412188 .ty = error_set_type.toIntern(),
1221512189 .name = name,
......@@ -12260,36 +12234,36 @@ fn zirShl(
1226012234 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1226112235 var i: usize = 0;
1226212236 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12263 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
12237 const rhs_elem = try rhs_val.elemValue(mod, i);
1226412238 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
1226512239 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
12266 rhs_elem.fmtValue(scalar_ty, sema.mod),
12240 rhs_elem.fmtValue(scalar_ty, mod),
1226712241 i,
12268 scalar_ty.fmt(sema.mod),
12242 scalar_ty.fmt(mod),
1226912243 });
1227012244 }
1227112245 }
1227212246 } else if (rhs_val.compareHetero(.gte, bit_value, mod)) {
1227312247 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
12274 rhs_val.fmtValue(scalar_ty, sema.mod),
12275 scalar_ty.fmt(sema.mod),
12248 rhs_val.fmtValue(scalar_ty, mod),
12249 scalar_ty.fmt(mod),
1227612250 });
1227712251 }
1227812252 }
1227912253 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1228012254 var i: usize = 0;
1228112255 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12282 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
12256 const rhs_elem = try rhs_val.elemValue(mod, i);
1228312257 if (rhs_elem.compareHetero(.lt, try mod.intValue(scalar_rhs_ty, 0), mod)) {
1228412258 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
12285 rhs_elem.fmtValue(scalar_ty, sema.mod),
12259 rhs_elem.fmtValue(scalar_ty, mod),
1228612260 i,
1228712261 });
1228812262 }
1228912263 }
1229012264 } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) {
1229112265 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
12292 rhs_val.fmtValue(scalar_ty, sema.mod),
12266 rhs_val.fmtValue(scalar_ty, mod),
1229312267 });
1229412268 }
1229512269 }
......@@ -12305,25 +12279,25 @@ fn zirShl(
1230512279
1230612280 const val = switch (air_tag) {
1230712281 .shl_exact => val: {
12308 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, sema.mod);
12282 const shifted = try lhs_val.shlWithOverflow(rhs_val, lhs_ty, sema.arena, mod);
1230912283 if (scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
1231012284 break :val shifted.wrapped_result;
1231112285 }
12312 if (shifted.overflow_bit.compareAllWithZero(.eq, sema.mod)) {
12286 if (shifted.overflow_bit.compareAllWithZero(.eq, mod)) {
1231312287 break :val shifted.wrapped_result;
1231412288 }
1231512289 return sema.fail(block, src, "operation caused overflow", .{});
1231612290 },
1231712291
1231812292 .shl_sat => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt)
12319 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod)
12293 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, mod)
1232012294 else
12321 try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, sema.mod),
12295 try lhs_val.shlSat(rhs_val, lhs_ty, sema.arena, mod),
1232212296
1232312297 .shl => if (scalar_ty.zigTypeTag(mod) == .ComptimeInt)
12324 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, sema.mod)
12298 try lhs_val.shl(rhs_val, lhs_ty, sema.arena, mod)
1232512299 else
12326 try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, sema.mod),
12300 try lhs_val.shlTrunc(rhs_val, lhs_ty, sema.arena, mod),
1232712301
1232812302 else => unreachable,
1232912303 };
......@@ -12441,36 +12415,36 @@ fn zirShr(
1244112415 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1244212416 var i: usize = 0;
1244312417 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12444 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
12418 const rhs_elem = try rhs_val.elemValue(mod, i);
1244512419 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
1244612420 return sema.fail(block, rhs_src, "shift amount '{}' at index '{d}' is too large for operand type '{}'", .{
12447 rhs_elem.fmtValue(scalar_ty, sema.mod),
12421 rhs_elem.fmtValue(scalar_ty, mod),
1244812422 i,
12449 scalar_ty.fmt(sema.mod),
12423 scalar_ty.fmt(mod),
1245012424 });
1245112425 }
1245212426 }
1245312427 } else if (rhs_val.compareHetero(.gte, bit_value, mod)) {
1245412428 return sema.fail(block, rhs_src, "shift amount '{}' is too large for operand type '{}'", .{
12455 rhs_val.fmtValue(scalar_ty, sema.mod),
12456 scalar_ty.fmt(sema.mod),
12429 rhs_val.fmtValue(scalar_ty, mod),
12430 scalar_ty.fmt(mod),
1245712431 });
1245812432 }
1245912433 }
1246012434 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1246112435 var i: usize = 0;
1246212436 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
12463 const rhs_elem = try rhs_val.elemValue(sema.mod, i);
12437 const rhs_elem = try rhs_val.elemValue(mod, i);
1246412438 if (rhs_elem.compareHetero(.lt, try mod.intValue(rhs_ty.childType(mod), 0), mod)) {
1246512439 return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{
12466 rhs_elem.fmtValue(scalar_ty, sema.mod),
12440 rhs_elem.fmtValue(scalar_ty, mod),
1246712441 i,
1246812442 });
1246912443 }
1247012444 }
1247112445 } else if (rhs_val.compareHetero(.lt, try mod.intValue(rhs_ty, 0), mod)) {
1247212446 return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{
12473 rhs_val.fmtValue(scalar_ty, sema.mod),
12447 rhs_val.fmtValue(scalar_ty, mod),
1247412448 });
1247512449 }
1247612450 if (maybe_lhs_val) |lhs_val| {
......@@ -12479,12 +12453,12 @@ fn zirShr(
1247912453 }
1248012454 if (air_tag == .shr_exact) {
1248112455 // Detect if any ones would be shifted out.
12482 const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, sema.mod);
12456 const truncated = try lhs_val.intTruncBitsAsValue(lhs_ty, sema.arena, .unsigned, rhs_val, mod);
1248312457 if (!(try truncated.compareAllWithZeroAdvanced(.eq, sema))) {
1248412458 return sema.fail(block, src, "exact shift shifted out 1 bits", .{});
1248512459 }
1248612460 }
12487 const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, sema.mod);
12461 const val = try lhs_val.shr(rhs_val, lhs_ty, sema.arena, mod);
1248812462 return sema.addConstant(lhs_ty, val);
1248912463 } else {
1249012464 break :rs lhs_src;
......@@ -12580,9 +12554,9 @@ fn zirBitwise(
1258012554 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
1258112555 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
1258212556 const result_val = switch (air_tag) {
12583 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, sema.mod),
12584 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, sema.mod),
12585 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, sema.mod),
12557 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, mod),
12558 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, mod),
12559 .xor => try lhs_val.bitwiseXor(rhs_val, resolved_type, sema.arena, mod),
1258612560 else => unreachable,
1258712561 };
1258812562 return sema.addConstant(resolved_type, result_val);
......@@ -12613,7 +12587,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1261312587
1261412588 if (scalar_type.zigTypeTag(mod) != .Int) {
1261512589 return sema.fail(block, src, "unable to perform binary not operation on type '{}'", .{
12616 operand_type.fmt(sema.mod),
12590 operand_type.fmt(mod),
1261712591 });
1261812592 }
1261912593
......@@ -12624,15 +12598,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1262412598 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));
1262512599 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
1262612600 for (elems, 0..) |*elem, i| {
12627 const elem_val = try val.elemValue(sema.mod, i);
12628 elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod)).intern(scalar_type, mod);
12601 const elem_val = try val.elemValue(mod, i);
12602 elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, mod)).intern(scalar_type, mod);
1262912603 }
1263012604 return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{
1263112605 .ty = operand_type.toIntern(),
1263212606 .storage = .{ .elems = elems },
1263312607 } })).toValue());
1263412608 } else {
12635 const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod);
12609 const result_val = try val.bitwiseNot(operand_type, sema.arena, mod);
1263612610 return sema.addConstant(operand_type, result_val);
1263712611 }
1263812612 }
......@@ -12949,7 +12923,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1294912923 return Type.ArrayInfo{
1295012924 .elem_type = ptr_info.pointee_type,
1295112925 .sentinel = ptr_info.sentinel,
12952 .len = val.sliceLen(sema.mod),
12926 .len = val.sliceLen(mod),
1295312927 };
1295412928 },
1295512929 .One => {
......@@ -13195,14 +13169,14 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1319513169 .Int, .ComptimeInt, .Float, .ComptimeFloat => false,
1319613170 else => true,
1319713171 }) {
13198 return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(sema.mod)});
13172 return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(mod)});
1319913173 }
1320013174
1320113175 if (rhs_scalar_ty.isAnyFloat()) {
1320213176 // We handle float negation here to ensure negative zero is represented in the bits.
1320313177 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
1320413178 if (rhs_val.isUndef(mod)) return sema.addConstUndef(rhs_ty);
13205 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, sema.mod));
13179 return sema.addConstant(rhs_ty, try rhs_val.floatNeg(rhs_ty, sema.arena, mod));
1320613180 }
1320713181 try sema.requireRuntimeBlock(block, src, null);
1320813182 return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs);
......@@ -13225,7 +13199,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1322513199
1322613200 switch (rhs_scalar_ty.zigTypeTag(mod)) {
1322713201 .Int, .ComptimeInt, .Float, .ComptimeFloat => {},
13228 else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(sema.mod)}),
13202 else => return sema.fail(block, src, "negation of type '{}'", .{rhs_ty.fmt(mod)}),
1322913203 }
1323013204
1323113205 const lhs = try sema.addConstant(rhs_ty, try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0)));
......@@ -14099,8 +14073,8 @@ fn intRem(
1409914073 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
1410014074 const scalar_ty = ty.scalarType(mod);
1410114075 for (result_data, 0..) |*scalar, i| {
14102 const lhs_elem = try lhs.elemValue(sema.mod, i);
14103 const rhs_elem = try rhs.elemValue(sema.mod, i);
14076 const lhs_elem = try lhs.elemValue(mod, i);
14077 const rhs_elem = try rhs.elemValue(mod, i);
1410414078 scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);
1410514079 }
1410614080 return (try mod.intern(.{ .aggregate = .{
......@@ -14499,7 +14473,7 @@ fn zirOverflowArithmetic(
1449914473 break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef };
1450014474 }
1450114475
14502 const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, sema.mod);
14476 const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, mod);
1450314477 break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result };
1450414478 }
1450514479 }
......@@ -14917,7 +14891,7 @@ fn analyzeArithmetic(
1491714891 }
1491814892 if (is_int) {
1491914893 var overflow_idx: ?usize = null;
14920 const product = try lhs_val.intMul(rhs_val, resolved_type, &overflow_idx, sema.arena, sema.mod);
14894 const product = try lhs_val.intMul(rhs_val, resolved_type, &overflow_idx, sema.arena, mod);
1492114895 if (overflow_idx) |vec_idx| {
1492214896 return sema.failWithIntegerOverflow(block, src, resolved_type, product, vec_idx);
1492314897 }
......@@ -14925,7 +14899,7 @@ fn analyzeArithmetic(
1492514899 } else {
1492614900 return sema.addConstant(
1492714901 resolved_type,
14928 try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, sema.mod),
14902 try lhs_val.floatMul(rhs_val, resolved_type, sema.arena, mod),
1492914903 );
1493014904 }
1493114905 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
......@@ -14975,7 +14949,7 @@ fn analyzeArithmetic(
1497514949 }
1497614950 return sema.addConstant(
1497714951 resolved_type,
14978 try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, sema.mod),
14952 try lhs_val.numberMulWrap(rhs_val, resolved_type, sema.arena, mod),
1497914953 );
1498014954 } else break :rs .{ .src = lhs_src, .air_tag = air_tag };
1498114955 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
......@@ -15023,9 +14997,9 @@ fn analyzeArithmetic(
1502314997 }
1502414998
1502514999 const val = if (scalar_tag == .ComptimeInt)
15026 try lhs_val.intMul(rhs_val, resolved_type, undefined, sema.arena, sema.mod)
15000 try lhs_val.intMul(rhs_val, resolved_type, undefined, sema.arena, mod)
1502715001 else
15028 try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, sema.mod);
15002 try lhs_val.intMulSat(rhs_val, resolved_type, sema.arena, mod);
1502915003
1503015004 return sema.addConstant(resolved_type, val);
1503115005 } else break :rs .{ .src = lhs_src, .air_tag = .mul_sat };
......@@ -15118,7 +15092,7 @@ fn analyzePtrArithmetic(
1511815092 // non zero).
1511915093 const new_align = @as(u32, 1) << @intCast(u5, @ctz(addend | ptr_info.@"align"));
1512015094
15121 break :t try Type.ptr(sema.arena, sema.mod, .{
15095 break :t try Type.ptr(sema.arena, mod, .{
1512215096 .pointee_type = ptr_info.pointee_type,
1512315097 .sentinel = ptr_info.sentinel,
1512415098 .@"align" = new_align,
......@@ -15150,7 +15124,7 @@ fn analyzePtrArithmetic(
1515015124 if (air_tag == .ptr_sub) {
1515115125 return sema.fail(block, op_src, "TODO implement Sema comptime pointer subtraction", .{});
1515215126 }
15153 const new_ptr_val = try ptr_val.elemPtr(new_ptr_ty, offset_int, sema.mod);
15127 const new_ptr_val = try ptr_val.elemPtr(new_ptr_ty, offset_int, mod);
1515415128 return sema.addConstant(new_ptr_ty, new_ptr_val);
1515515129 } else break :rs offset_src;
1515615130 } else break :rs ptr_src;
......@@ -15382,7 +15356,7 @@ fn zirCmpEq(
1538215356
1538315357 if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) {
1538415358 const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty;
15385 return sema.fail(block, src, "comparison of '{}' with null", .{non_null_type.fmt(sema.mod)});
15359 return sema.fail(block, src, "comparison of '{}' with null", .{non_null_type.fmt(mod)});
1538615360 }
1538715361
1538815362 if (lhs_ty_tag == .Union and (rhs_ty_tag == .EnumLiteral or rhs_ty_tag == .Enum)) {
......@@ -15419,7 +15393,7 @@ fn zirCmpEq(
1541915393 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {
1542015394 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);
1542115395 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs);
15422 if (lhs_as_type.eql(rhs_as_type, sema.mod) == (op == .eq)) {
15396 if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) {
1542315397 return Air.Inst.Ref.bool_true;
1542415398 } else {
1542515399 return Air.Inst.Ref.bool_false;
......@@ -15444,7 +15418,7 @@ fn analyzeCmpUnionTag(
1544415418 const msg = msg: {
1544515419 const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
1544615420 errdefer msg.destroy(sema.gpa);
15447 try sema.mod.errNoteNonLazy(union_ty.declSrcLoc(sema.mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(sema.mod)});
15421 try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});
1544815422 break :msg msg;
1544915423 };
1545015424 return sema.failWithOwnedErrorMsg(msg);
......@@ -15456,7 +15430,7 @@ fn analyzeCmpUnionTag(
1545615430
1545715431 if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| {
1545815432 if (enum_val.isUndef(mod)) return sema.addConstUndef(Type.bool);
15459 const field_ty = union_ty.unionFieldType(enum_val, sema.mod);
15433 const field_ty = union_ty.unionFieldType(enum_val, mod);
1546015434 if (field_ty.zigTypeTag(mod) == .NoReturn) {
1546115435 return Air.Inst.Ref.bool_false;
1546215436 }
......@@ -15524,7 +15498,7 @@ fn analyzeCmp(
1552415498 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]?LazySrcLoc{ lhs_src, rhs_src } });
1552515499 if (!resolved_type.isSelfComparable(mod, is_equality_cmp)) {
1552615500 return sema.fail(block, src, "operator {s} not allowed for type '{}'", .{
15527 compareOperatorName(op), resolved_type.fmt(sema.mod),
15501 compareOperatorName(op), resolved_type.fmt(mod),
1552815502 });
1552915503 }
1553015504 const casted_lhs = try sema.coerce(block, resolved_type, lhs, lhs_src);
......@@ -15634,7 +15608,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1563415608 .Undefined,
1563515609 .Null,
1563615610 .Opaque,
15637 => return sema.fail(block, operand_src, "no size available for type '{}'", .{ty.fmt(sema.mod)}),
15611 => return sema.fail(block, operand_src, "no size available for type '{}'", .{ty.fmt(mod)}),
1563815612
1563915613 .Type,
1564015614 .EnumLiteral,
......@@ -15677,7 +15651,7 @@ fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1567715651 .Undefined,
1567815652 .Null,
1567915653 .Opaque,
15680 => return sema.fail(block, operand_src, "no size available for type '{}'", .{operand_ty.fmt(sema.mod)}),
15654 => return sema.fail(block, operand_src, "no size available for type '{}'", .{operand_ty.fmt(mod)}),
1568115655
1568215656 .Type,
1568315657 .EnumLiteral,
......@@ -17163,7 +17137,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1716317137 block,
1716417138 src,
1716517139 "bit shifting operation expected integer type, found '{}'",
17166 .{operand.fmt(sema.mod)},
17140 .{operand.fmt(mod)},
1716717141 );
1716817142}
1716917143
......@@ -17395,7 +17369,7 @@ fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
1739517369 switch (ty.zigTypeTag(mod)) {
1739617370 .ErrorSet, .ErrorUnion, .Undefined => return,
1739717371 else => return sema.fail(block, src, "expected error union type, found '{}'", .{
17398 ty.fmt(sema.mod),
17372 ty.fmt(mod),
1739917373 }),
1740017374 }
1740117375}
......@@ -17521,7 +17495,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1752117495 const mod = sema.mod;
1752217496 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
1752317497 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
17524 err_union_ty.fmt(sema.mod),
17498 err_union_ty.fmt(mod),
1752517499 });
1752617500 }
1752717501 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union);
......@@ -17568,7 +17542,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1756817542 const mod = sema.mod;
1756917543 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) {
1757017544 return sema.fail(parent_block, operand_src, "expected error union type, found '{}'", .{
17571 err_union_ty.fmt(sema.mod),
17545 err_union_ty.fmt(mod),
1757217546 });
1757317547 }
1757417548 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union);
......@@ -17590,7 +17564,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1759017564
1759117565 const operand_ty = sema.typeOf(operand);
1759217566 const ptr_info = operand_ty.ptrInfo(mod);
17593 const res_ty = try Type.ptr(sema.arena, sema.mod, .{
17567 const res_ty = try Type.ptr(sema.arena, mod, .{
1759417568 .pointee_type = err_union_ty.errorUnionPayload(mod),
1759517569 .@"addrspace" = ptr_info.@"addrspace",
1759617570 .mutable = ptr_info.mutable,
......@@ -17693,7 +17667,7 @@ fn zirRetErrValue(
1769317667 _ = try mod.getErrorValue(err_name);
1769417668 const src = inst_data.src();
1769517669 // Return the error code from the function.
17696 const error_set_type = try mod.singleErrorSetTypeNts(err_name);
17670 const error_set_type = try mod.singleErrorSetType(err_name);
1769717671 const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
1769817672 .ty = error_set_type.toIntern(),
1769917673 .name = err_name,
......@@ -18003,7 +17977,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1800317977 if (elem_ty.zigTypeTag(mod) == .NoReturn)
1800417978 return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});
1800517979
18006 const target = sema.mod.getTarget();
17980 const target = mod.getTarget();
1800717981
1800817982 var extra_i = extra.end;
1800917983
......@@ -18073,10 +18047,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1807318047 } else if (inst_data.size == .C) {
1807418048 if (!try sema.validateExternType(elem_ty, .other)) {
1807518049 const msg = msg: {
18076 const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(sema.mod)});
18050 const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
1807718051 errdefer msg.destroy(sema.gpa);
1807818052
18079 const src_decl = sema.mod.declPtr(block.src_decl);
18053 const src_decl = mod.declPtr(block.src_decl);
1808018054 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src.toSrcLoc(src_decl, mod), elem_ty, .other);
1808118055
1808218056 try sema.addDeclaredHereNote(msg, elem_ty);
......@@ -18273,7 +18247,7 @@ fn zirStructInit(
1827318247 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
1827418248 };
1827518249
18276 if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), sema.mod)) {
18250 if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) {
1827718251 return sema.failWithInvalidComptimeFieldStore(block, field_src, resolved_ty, field_index);
1827818252 }
1827918253 };
......@@ -18307,8 +18281,8 @@ fn zirStructInit(
1830718281 }
1830818282
1830918283 if (is_ref) {
18310 const target = sema.mod.getTarget();
18311 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
18284 const target = mod.getTarget();
18285 const alloc_ty = try Type.ptr(sema.arena, mod, .{
1831218286 .pointee_type = resolved_ty,
1831318287 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
1831418288 });
......@@ -18359,8 +18333,8 @@ fn finishStructInit(
1835918333 }
1836018334 } else {
1836118335 const field_name = anon_struct.names[i];
18362 const template = "missing struct field: {s}";
18363 const args = .{ip.stringToSlice(field_name)};
18336 const template = "missing struct field: {}";
18337 const args = .{field_name.fmt(ip)};
1836418338 if (root_msg) |msg| {
1836518339 try sema.errNote(block, init_src, msg, template, args);
1836618340 } else {
......@@ -18379,8 +18353,8 @@ fn finishStructInit(
1837918353
1838018354 if (field.default_val == .none) {
1838118355 const field_name = struct_obj.fields.keys()[i];
18382 const template = "missing struct field: {s}";
18383 const args = .{ip.stringToSlice(field_name)};
18356 const template = "missing struct field: {}";
18357 const args = .{field_name.fmt(ip)};
1838418358 if (root_msg) |msg| {
1838518359 try sema.errNote(block, init_src, msg, template, args);
1838618360 } else {
......@@ -18396,12 +18370,12 @@ fn finishStructInit(
1839618370
1839718371 if (root_msg) |msg| {
1839818372 if (mod.typeToStruct(struct_ty)) |struct_obj| {
18399 const fqn = ip.stringToSlice(try struct_obj.getFullyQualifiedName(mod));
18373 const fqn = try struct_obj.getFullyQualifiedName(mod);
1840018374 try mod.errNoteNonLazy(
1840118375 struct_obj.srcLoc(mod),
1840218376 msg,
18403 "struct '{s}' declared here",
18404 .{fqn},
18377 "struct '{}' declared here",
18378 .{fqn.fmt(ip)},
1840518379 );
1840618380 }
1840718381 root_msg = null;
......@@ -18431,7 +18405,7 @@ fn finishStructInit(
1843118405 if (is_ref) {
1843218406 try sema.resolveStructLayout(struct_ty);
1843318407 const target = sema.mod.getTarget();
18434 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
18408 const alloc_ty = try Type.ptr(sema.arena, mod, .{
1843518409 .pointee_type = struct_ty,
1843618410 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
1843718411 });
......@@ -18489,7 +18463,7 @@ fn zirStructInitAnon(
1848918463 const gop = fields.getOrPutAssumeCapacity(name_ip);
1849018464 if (gop.found_existing) {
1849118465 const msg = msg: {
18492 const decl = sema.mod.declPtr(block.src_decl);
18466 const decl = mod.declPtr(block.src_decl);
1849318467 const field_src = mod.initSrc(src.node_offset.x, decl, i);
1849418468 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
1849518469 errdefer msg.destroy(gpa);
......@@ -18506,7 +18480,7 @@ fn zirStructInitAnon(
1850618480 field_ty.* = sema.typeOf(init).toIntern();
1850718481 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {
1850818482 const msg = msg: {
18509 const decl = sema.mod.declPtr(block.src_decl);
18483 const decl = mod.declPtr(block.src_decl);
1851018484 const field_src = mod.initSrc(src.node_offset.x, decl, i);
1851118485 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
1851218486 errdefer msg.destroy(sema.gpa);
......@@ -18542,7 +18516,7 @@ fn zirStructInitAnon(
1854218516
1854318517 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
1854418518 error.NeededSourceLocation => {
18545 const decl = sema.mod.declPtr(block.src_decl);
18519 const decl = mod.declPtr(block.src_decl);
1854618520 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
1854718521 try sema.requireRuntimeBlock(block, src, field_src);
1854818522 unreachable;
......@@ -18551,8 +18525,8 @@ fn zirStructInitAnon(
1855118525 };
1855218526
1855318527 if (is_ref) {
18554 const target = sema.mod.getTarget();
18555 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
18528 const target = mod.getTarget();
18529 const alloc_ty = try Type.ptr(sema.arena, mod, .{
1855618530 .pointee_type = tuple_ty.toType(),
1855718531 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
1855818532 });
......@@ -18563,7 +18537,7 @@ fn zirStructInitAnon(
1856318537 const item = sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index);
1856418538 extra_index = item.end;
1856518539
18566 const field_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{
18540 const field_ptr_ty = try Type.ptr(sema.arena, mod, .{
1856718541 .mutable = true,
1856818542 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
1856918543 .pointee_type = field_ty.toType(),
......@@ -18617,7 +18591,7 @@ fn zirArrayInit(
1861718591 array_ty.elemType2(mod);
1861818592 resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {
1861918593 error.NeededSourceLocation => {
18620 const decl = sema.mod.declPtr(block.src_decl);
18594 const decl = mod.declPtr(block.src_decl);
1862118595 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
1862218596 _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
1862318597 unreachable;
......@@ -18653,7 +18627,7 @@ fn zirArrayInit(
1865318627
1865418628 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
1865518629 error.NeededSourceLocation => {
18656 const decl = sema.mod.declPtr(block.src_decl);
18630 const decl = mod.declPtr(block.src_decl);
1865718631 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
1865818632 try sema.requireRuntimeBlock(block, src, elem_src);
1865918633 unreachable;
......@@ -18663,8 +18637,8 @@ fn zirArrayInit(
1866318637 try sema.queueFullTypeResolution(array_ty);
1866418638
1866518639 if (is_ref) {
18666 const target = sema.mod.getTarget();
18667 const alloc_ty = try Type.ptr(sema.arena, sema.mod, .{
18640 const target = mod.getTarget();
18641 const alloc_ty = try Type.ptr(sema.arena, mod, .{
1866818642 .pointee_type = array_ty,
1866918643 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
1867018644 });
......@@ -18672,7 +18646,7 @@ fn zirArrayInit(
1867218646
1867318647 if (array_ty.isTuple(mod)) {
1867418648 for (resolved_args, 0..) |arg, i| {
18675 const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{
18649 const elem_ptr_ty = try Type.ptr(sema.arena, mod, .{
1867618650 .mutable = true,
1867718651 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
1867818652 .pointee_type = array_ty.structFieldType(i, mod),
......@@ -18686,7 +18660,7 @@ fn zirArrayInit(
1868618660 return sema.makePtrConst(block, alloc);
1868718661 }
1868818662
18689 const elem_ptr_ty = try Type.ptr(sema.arena, sema.mod, .{
18663 const elem_ptr_ty = try Type.ptr(sema.arena, mod, .{
1869018664 .mutable = true,
1869118665 .@"addrspace" = target_util.defaultAddressSpace(target, .local),
1869218666 .pointee_type = array_ty.elemType2(mod),
......@@ -18959,8 +18933,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1895918933
1896018934 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
1896118935 const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name;
18962 const bytes = sema.mod.intern_pool.stringToSlice(err_name);
18963 return sema.addStrLit(block, bytes);
18936 return sema.addStrLit(block, sema.mod.intern_pool.stringToSlice(err_name));
1896418937 }
1896518938
1896618939 // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass
......@@ -19051,8 +19024,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1905119024 .EnumLiteral => {
1905219025 const val = try sema.resolveConstValue(block, .unneeded, operand, "");
1905319026 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
19054 const bytes = ip.stringToSlice(tag_name);
19055 return sema.addStrLit(block, bytes);
19027 return sema.addStrLit(block, ip.stringToSlice(tag_name));
1905619028 },
1905719029 .Enum => operand_ty,
1905819030 .Union => operand_ty.unionTagType(mod) orelse {
......@@ -19083,8 +19055,8 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1908319055 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
1908419056 const enum_decl = mod.declPtr(enum_decl_index);
1908519057 const msg = msg: {
19086 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{s}'", .{
19087 val.fmtValue(enum_ty, sema.mod), ip.stringToSlice(enum_decl.name),
19058 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{
19059 val.fmtValue(enum_ty, sema.mod), enum_decl.name.fmt(ip),
1908819060 });
1908919061 errdefer msg.destroy(sema.gpa);
1909019062 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});
......@@ -19374,8 +19346,8 @@ fn zirReify(
1937419346 _ = try mod.getErrorValue(name);
1937519347 const gop = names.getOrPutAssumeCapacity(name);
1937619348 if (gop.found_existing) {
19377 return sema.fail(block, src, "duplicate error '{s}'", .{
19378 ip.stringToSlice(name),
19349 return sema.fail(block, src, "duplicate error '{}'", .{
19350 name.fmt(ip),
1937919351 });
1938019352 }
1938119353 }
......@@ -19487,8 +19459,8 @@ fn zirReify(
1948719459
1948819460 if (!try sema.intFitsInType(value_val, int_tag_ty, null)) {
1948919461 // TODO: better source location
19490 return sema.fail(block, src, "field '{s}' with enumeration value '{}' is too large for backing int type '{}'", .{
19491 ip.stringToSlice(field_name),
19462 return sema.fail(block, src, "field '{}' with enumeration value '{}' is too large for backing int type '{}'", .{
19463 field_name.fmt(ip),
1949219464 value_val.fmtValue(Type.comptime_int, mod),
1949319465 int_tag_ty.fmt(mod),
1949419466 });
......@@ -19496,8 +19468,8 @@ fn zirReify(
1949619468
1949719469 if (try incomplete_enum.addFieldName(ip, gpa, field_name)) |other_index| {
1949819470 const msg = msg: {
19499 const msg = try sema.errMsg(block, src, "duplicate enum field '{s}'", .{
19500 ip.stringToSlice(field_name),
19471 const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{
19472 field_name.fmt(ip),
1950119473 });
1950219474 errdefer msg.destroy(gpa);
1950319475 _ = other_index; // TODO: this note is incorrect
......@@ -19690,7 +19662,10 @@ fn zirReify(
1969019662 const tag_info = ip.indexToKey(union_obj.tag_ty.toIntern()).enum_type;
1969119663 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
1969219664 const msg = msg: {
19693 const msg = try sema.errMsg(block, src, "no field named '{s}' in enum '{}'", .{ ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod) });
19665 const msg = try sema.errMsg(block, src, "no field named '{}' in enum '{}'", .{
19666 field_name.fmt(ip),
19667 union_obj.tag_ty.fmt(mod),
19668 });
1969419669 errdefer msg.destroy(gpa);
1969519670 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
1969619671 break :msg msg;
......@@ -19706,7 +19681,7 @@ fn zirReify(
1970619681 const gop = union_obj.fields.getOrPutAssumeCapacity(field_name);
1970719682 if (gop.found_existing) {
1970819683 // TODO: better source location
19709 return sema.fail(block, src, "duplicate union field {s}", .{ip.stringToSlice(field_name)});
19684 return sema.fail(block, src, "duplicate union field {}", .{field_name.fmt(ip)});
1971019685 }
1971119686
1971219687 const field_ty = type_val.toType();
......@@ -19762,8 +19737,8 @@ fn zirReify(
1976219737 const enum_ty = union_obj.tag_ty;
1976319738 for (tag_info.names, 0..) |field_name, field_index| {
1976419739 if (explicit_tags_seen[field_index]) continue;
19765 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{
19766 ip.stringToSlice(field_name),
19740 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{}' missing, declared here", .{
19741 field_name.fmt(ip),
1976719742 });
1976819743 }
1976919744 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
......@@ -19981,14 +19956,12 @@ fn reifyStruct(
1998119956 const field_name = try name_val.toIpString(Type.slice_const_u8, mod);
1998219957
1998319958 if (is_tuple) {
19984 const field_index = std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10) catch {
19985 return sema.fail(
19986 block,
19987 src,
19988 "tuple cannot have non-numeric field '{s}'",
19989 .{ip.stringToSlice(field_name)},
19990 );
19991 };
19959 const field_index = field_name.toUnsigned(ip) orelse return sema.fail(
19960 block,
19961 src,
19962 "tuple cannot have non-numeric field '{}'",
19963 .{field_name.fmt(ip)},
19964 );
1999219965
1999319966 if (field_index >= fields_len) {
1999419967 return sema.fail(
......@@ -20002,7 +19975,7 @@ fn reifyStruct(
2000219975 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);
2000319976 if (gop.found_existing) {
2000419977 // TODO: better source location
20005 return sema.fail(block, src, "duplicate struct field {s}", .{ip.stringToSlice(field_name)});
19978 return sema.fail(block, src, "duplicate struct field {}", .{field_name.fmt(ip)});
2000619979 }
2000719980
2000819981 const field_ty = type_val.toType();
......@@ -20443,14 +20416,14 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2044320416
2044420417 if (maybe_operand_val) |val| {
2044520418 if (!dest_ty.isAnyError(mod)) {
20446 const error_name = mod.intern_pool.stringToSlice(mod.intern_pool.indexToKey(val.toIntern()).err.name);
20447 if (!dest_ty.errorSetHasField(error_name, mod)) {
20419 const error_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
20420 if (!Type.errorSetHasFieldIp(ip, dest_ty.toIntern(), error_name)) {
2044820421 const msg = msg: {
2044920422 const msg = try sema.errMsg(
2045020423 block,
2045120424 src,
20452 "'error.{s}' not a member of error set '{}'",
20453 .{ error_name, dest_ty.fmt(sema.mod) },
20425 "'error.{}' not a member of error set '{}'",
20426 .{ error_name.fmt(ip), dest_ty.fmt(sema.mod) },
2045420427 );
2045520428 errdefer msg.destroy(sema.gpa);
2045620429 try sema.addDeclaredHereNote(msg, dest_ty);
......@@ -21448,7 +21421,7 @@ fn resolveExportOptions(
2144821421 block: *Block,
2144921422 src: LazySrcLoc,
2145021423 zir_ref: Zir.Inst.Ref,
21451) CompileError!std.builtin.ExportOptions {
21424) CompileError!Module.Export.Options {
2145221425 const mod = sema.mod;
2145321426 const gpa = sema.gpa;
2145421427 const ip = &mod.intern_pool;
......@@ -21492,10 +21465,10 @@ fn resolveExportOptions(
2149221465 });
2149321466 }
2149421467
21495 return std.builtin.ExportOptions{
21496 .name = name,
21468 return .{
21469 .name = try ip.getOrPutString(gpa, name),
2149721470 .linkage = linkage,
21498 .section = section,
21471 .section = try ip.getOrPutStringOpt(gpa, section),
2149921472 .visibility = visibility,
2150021473 };
2150121474}
......@@ -22391,9 +22364,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2239122364 const msg = try sema.errMsg(
2239222365 block,
2239322366 src,
22394 "field '{s}' has index '{d}' but pointer value is index '{d}' of struct '{}'",
22367 "field '{}' has index '{d}' but pointer value is index '{d}' of struct '{}'",
2239522368 .{
22396 ip.stringToSlice(field_name),
22369 field_name.fmt(ip),
2239722370 field_index,
2239822371 field.index,
2239922372 parent_ty.fmt(sema.mod),
......@@ -23440,7 +23413,12 @@ fn resolveExternOptions(
2344023413 block: *Block,
2344123414 src: LazySrcLoc,
2344223415 zir_ref: Zir.Inst.Ref,
23443) CompileError!std.builtin.ExternOptions {
23416) CompileError!struct {
23417 name: InternPool.NullTerminatedString,
23418 library_name: InternPool.OptionalNullTerminatedString = .none,
23419 linkage: std.builtin.GlobalLinkage = .Strong,
23420 is_thread_local: bool = false,
23421} {
2344423422 const mod = sema.mod;
2344523423 const gpa = sema.gpa;
2344623424 const ip = &mod.intern_pool;
......@@ -23483,9 +23461,9 @@ fn resolveExternOptions(
2348323461 return sema.fail(block, linkage_src, "extern symbol must use strong or weak linkage", .{});
2348423462 }
2348523463
23486 return std.builtin.ExternOptions{
23487 .name = name,
23488 .library_name = library_name,
23464 return .{
23465 .name = try ip.getOrPutString(gpa, name),
23466 .library_name = try ip.getOrPutStringOpt(gpa, library_name),
2348923467 .linkage = linkage,
2349023468 .is_thread_local = is_thread_local_val.toBool(),
2349123469 };
......@@ -23533,7 +23511,7 @@ fn zirBuiltinExtern(
2353323511 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null);
2353423512 errdefer mod.destroyDecl(new_decl_index);
2353523513 const new_decl = mod.declPtr(new_decl_index);
23536 new_decl.name = try mod.intern_pool.getOrPutString(sema.gpa, options.name);
23514 new_decl.name = options.name;
2353723515
2353823516 {
2353923517 const new_var = try mod.intern(.{ .variable = .{
......@@ -24459,8 +24437,8 @@ fn fieldVal(
2445924437 return sema.fail(
2446024438 block,
2446124439 field_name_src,
24462 "no member named '{s}' in '{}'",
24463 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },
24440 "no member named '{}' in '{}'",
24441 .{ field_name.fmt(ip), object_ty.fmt(mod) },
2446424442 );
2446524443 }
2446624444 },
......@@ -24483,8 +24461,8 @@ fn fieldVal(
2448324461 return sema.fail(
2448424462 block,
2448524463 field_name_src,
24486 "no member named '{s}' in '{}'",
24487 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },
24464 "no member named '{}' in '{}'",
24465 .{ field_name.fmt(ip), object_ty.fmt(mod) },
2448824466 );
2448924467 }
2449024468 }
......@@ -24504,8 +24482,8 @@ fn fieldVal(
2450424482 .error_set_type => |error_set_type| blk: {
2450524483 if (error_set_type.nameIndex(ip, field_name) != null) break :blk;
2450624484 const msg = msg: {
24507 const msg = try sema.errMsg(block, src, "no error named '{s}' in '{}'", .{
24508 ip.stringToSlice(field_name), child_type.fmt(mod),
24485 const msg = try sema.errMsg(block, src, "no error named '{}' in '{}'", .{
24486 field_name.fmt(ip), child_type.fmt(mod),
2450924487 });
2451024488 errdefer msg.destroy(sema.gpa);
2451124489 try sema.addDeclaredHereNote(msg, child_type);
......@@ -24526,7 +24504,7 @@ fn fieldVal(
2452624504 const error_set_type = if (!child_type.isAnyError(mod))
2452724505 child_type
2452824506 else
24529 try mod.singleErrorSetTypeNts(field_name);
24507 try mod.singleErrorSetType(field_name);
2453024508 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
2453124509 .ty = error_set_type.toIntern(),
2453224510 .name = field_name,
......@@ -24646,8 +24624,8 @@ fn fieldPtr(
2464624624 return sema.fail(
2464724625 block,
2464824626 field_name_src,
24649 "no member named '{s}' in '{}'",
24650 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },
24627 "no member named '{}' in '{}'",
24628 .{ field_name.fmt(ip), object_ty.fmt(mod) },
2465124629 );
2465224630 }
2465324631 },
......@@ -24705,8 +24683,8 @@ fn fieldPtr(
2470524683 return sema.fail(
2470624684 block,
2470724685 field_name_src,
24708 "no member named '{s}' in '{}'",
24709 .{ ip.stringToSlice(field_name), object_ty.fmt(mod) },
24686 "no member named '{}' in '{}'",
24687 .{ field_name.fmt(ip), object_ty.fmt(mod) },
2471024688 );
2471124689 }
2471224690 },
......@@ -24728,8 +24706,8 @@ fn fieldPtr(
2472824706 if (error_set_type.nameIndex(ip, field_name) != null) {
2472924707 break :blk;
2473024708 }
24731 return sema.fail(block, src, "no error named '{s}' in '{}'", .{
24732 ip.stringToSlice(field_name), child_type.fmt(mod),
24709 return sema.fail(block, src, "no error named '{}' in '{}'", .{
24710 field_name.fmt(ip), child_type.fmt(mod),
2473324711 });
2473424712 },
2473524713 .inferred_error_set_type => {
......@@ -24747,7 +24725,7 @@ fn fieldPtr(
2474724725 const error_set_type = if (!child_type.isAnyError(mod))
2474824726 child_type
2474924727 else
24750 try mod.singleErrorSetTypeNts(field_name);
24728 try mod.singleErrorSetType(field_name);
2475124729 return sema.analyzeDeclRef(try anon_decl.finish(
2475224730 error_set_type,
2475324731 (try mod.intern(.{ .err = .{
......@@ -24880,10 +24858,10 @@ fn fieldCallBind(
2488024858 if (ip.stringEqlSlice(field_name, "len")) {
2488124859 return .{ .direct = try sema.addIntUnsigned(Type.usize, struct_ty.structFieldCount(mod)) };
2488224860 }
24883 if (std.fmt.parseUnsigned(u32, ip.stringToSlice(field_name), 10)) |field_index| {
24861 if (field_name.toUnsigned(ip)) |field_index| {
2488424862 if (field_index >= struct_ty.structFieldCount(mod)) break :find_field;
2488524863 return sema.finishFieldCallBind(block, src, ptr_ty, struct_ty.structFieldType(field_index, mod), field_index, object_ptr);
24886 } else |_| {}
24864 }
2488724865 } else {
2488824866 const max = struct_ty.structFieldCount(mod);
2488924867 for (0..max) |i_usize| {
......@@ -24982,12 +24960,15 @@ fn fieldCallBind(
2498224960 };
2498324961
2498424962 const msg = msg: {
24985 const msg = try sema.errMsg(block, src, "no field or member function named '{s}' in '{}'", .{ ip.stringToSlice(field_name), concrete_ty.fmt(mod) });
24963 const msg = try sema.errMsg(block, src, "no field or member function named '{}' in '{}'", .{
24964 field_name.fmt(ip),
24965 concrete_ty.fmt(mod),
24966 });
2498624967 errdefer msg.destroy(sema.gpa);
2498724968 try sema.addDeclaredHereNote(msg, concrete_ty);
2498824969 if (found_decl) |decl_idx| {
2498924970 const decl = mod.declPtr(decl_idx);
24990 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{s}' is not a member function", .{ip.stringToSlice(field_name)});
24971 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)});
2499124972 }
2499224973 break :msg msg;
2499324974 };
......@@ -25047,8 +25028,8 @@ fn namespaceLookup(
2504725028 const decl = mod.declPtr(decl_index);
2504825029 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {
2504925030 const msg = msg: {
25050 const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{
25051 mod.intern_pool.stringToSlice(decl_name),
25031 const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{
25032 decl_name.fmt(&mod.intern_pool),
2505225033 });
2505325034 errdefer msg.destroy(gpa);
2505425035 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});
......@@ -25299,21 +25280,20 @@ fn tupleFieldIndex(
2529925280 sema: *Sema,
2530025281 block: *Block,
2530125282 tuple_ty: Type,
25302 field_name_ip: InternPool.NullTerminatedString,
25283 field_name: InternPool.NullTerminatedString,
2530325284 field_name_src: LazySrcLoc,
2530425285) CompileError!u32 {
2530525286 const mod = sema.mod;
25306 const field_name = mod.intern_pool.stringToSlice(field_name_ip);
25307 assert(!std.mem.eql(u8, field_name, "len"));
25308 if (std.fmt.parseUnsigned(u32, field_name, 10)) |field_index| {
25287 assert(!mod.intern_pool.stringEqlSlice(field_name, "len"));
25288 if (field_name.toUnsigned(&mod.intern_pool)) |field_index| {
2530925289 if (field_index < tuple_ty.structFieldCount(mod)) return field_index;
25310 return sema.fail(block, field_name_src, "index '{s}' out of bounds of tuple '{}'", .{
25311 field_name, tuple_ty.fmt(mod),
25290 return sema.fail(block, field_name_src, "index '{}' out of bounds of tuple '{}'", .{
25291 field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod),
2531225292 });
25313 } else |_| {}
25293 }
2531425294
25315 return sema.fail(block, field_name_src, "no field named '{s}' in tuple '{}'", .{
25316 field_name, tuple_ty.fmt(mod),
25295 return sema.fail(block, field_name_src, "no field named '{}' in tuple '{}'", .{
25296 field_name.fmt(&mod.intern_pool), tuple_ty.fmt(mod),
2531725297 });
2531825298}
2531925299
......@@ -25389,8 +25369,8 @@ fn unionFieldPtr(
2538925369 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});
2539025370 errdefer msg.destroy(sema.gpa);
2539125371
25392 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{
25393 ip.stringToSlice(field_name),
25372 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
25373 field_name.fmt(ip),
2539425374 });
2539525375 try sema.addDeclaredHereNote(msg, union_ty);
2539625376 break :msg msg;
......@@ -25413,9 +25393,9 @@ fn unionFieldPtr(
2541325393 const msg = msg: {
2541425394 const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?;
2541525395 const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod);
25416 const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{
25417 ip.stringToSlice(field_name),
25418 ip.stringToSlice(active_field_name),
25396 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
25397 field_name.fmt(ip),
25398 active_field_name.fmt(ip),
2541925399 });
2542025400 errdefer msg.destroy(sema.gpa);
2542125401 try sema.addDeclaredHereNote(msg, union_ty);
......@@ -25486,8 +25466,8 @@ fn unionFieldVal(
2548625466 const msg = msg: {
2548725467 const active_index = union_obj.tag_ty.enumTagFieldIndex(un.tag.toValue(), mod).?;
2548825468 const active_field_name = union_obj.tag_ty.enumFieldName(active_index, mod);
25489 const msg = try sema.errMsg(block, src, "access of union field '{s}' while field '{s}' is active", .{
25490 ip.stringToSlice(field_name), ip.stringToSlice(active_field_name),
25469 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
25470 field_name.fmt(ip), active_field_name.fmt(ip),
2549125471 });
2549225472 errdefer msg.destroy(sema.gpa);
2549325473 try sema.addDeclaredHereNote(msg, union_ty);
......@@ -26595,8 +26575,8 @@ fn coerceExtra(
2659526575 const msg = try sema.errMsg(
2659626576 block,
2659726577 inst_src,
26598 "no field named '{s}' in enum '{}'",
26599 .{ mod.intern_pool.stringToSlice(string), dest_ty.fmt(mod) },
26578 "no field named '{}' in enum '{}'",
26579 .{ string.fmt(&mod.intern_pool), dest_ty.fmt(mod) },
2660026580 );
2660126581 errdefer msg.destroy(sema.gpa);
2660226582 try sema.addDeclaredHereNote(msg, dest_ty);
......@@ -27051,9 +27031,8 @@ const InMemoryCoercionResult = union(enum) {
2705127031 break;
2705227032 },
2705327033 .missing_error => |missing_errors| {
27054 for (missing_errors) |err_index| {
27055 const err = mod.intern_pool.stringToSlice(err_index);
27056 try sema.errNote(block, src, msg, "'error.{s}' not a member of destination error set", .{err});
27034 for (missing_errors) |err| {
27035 try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});
2705727036 }
2705827037 break;
2705927038 },
......@@ -28016,7 +27995,12 @@ fn storePtrVal(
2801627995 .bad_decl_ty, .bad_ptr_ty => {
2801727996 // TODO show the decl declaration site in a note and explain whether the decl
2801827997 // or the pointer is the problematic type
28019 return sema.fail(block, src, "comptime mutation of a reinterpreted pointer requires type '{}' to have a well-defined memory layout", .{mut_kit.ty.fmt(mod)});
27998 return sema.fail(
27999 block,
28000 src,
28001 "comptime mutation of a reinterpreted pointer requires type '{}' to have a well-defined memory layout",
28002 .{mut_kit.ty.fmt(mod)},
28003 );
2802028004 },
2802128005 }
2802228006}
......@@ -28678,7 +28662,12 @@ fn beginComptimePtrLoad(
2867828662 .null_value => return sema.fail(block, src, "attempt to use null value", .{}),
2867928663 else => switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
2868028664 .error_union => |error_union| switch (error_union.val) {
28681 .err_name => |err_name| return sema.fail(block, src, "attempt to unwrap error: {s}", .{mod.intern_pool.stringToSlice(err_name)}),
28665 .err_name => |err_name| return sema.fail(
28666 block,
28667 src,
28668 "attempt to unwrap error: {}",
28669 .{err_name.fmt(&mod.intern_pool)},
28670 ),
2868228671 .payload => |payload| payload,
2868328672 },
2868428673 .opt => |opt| switch (opt.val) {
......@@ -29077,8 +29066,8 @@ fn coerceEnumToUnion(
2907729066 errdefer msg.destroy(sema.gpa);
2907829067
2907929068 const field_name = union_obj.fields.keys()[field_index];
29080 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{
29081 ip.stringToSlice(field_name),
29069 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
29070 field_name.fmt(ip),
2908229071 });
2908329072 try sema.addDeclaredHereNote(msg, union_ty);
2908429073 break :msg msg;
......@@ -29088,14 +29077,14 @@ fn coerceEnumToUnion(
2908829077 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
2908929078 const msg = msg: {
2909029079 const field_name = union_obj.fields.keys()[field_index];
29091 const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{s}'", .{
29080 const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{
2909229081 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),
29093 field_ty.fmt(sema.mod), ip.stringToSlice(field_name),
29082 field_ty.fmt(sema.mod), field_name.fmt(ip),
2909429083 });
2909529084 errdefer msg.destroy(sema.gpa);
2909629085
29097 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' declared here", .{
29098 ip.stringToSlice(field_name),
29086 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
29087 field_name.fmt(ip),
2909929088 });
2910029089 try sema.addDeclaredHereNote(msg, union_ty);
2910129090 break :msg msg;
......@@ -29165,8 +29154,8 @@ fn coerceEnumToUnion(
2916529154 const field_name = field.key_ptr.*;
2916629155 const field_ty = field.value_ptr.ty;
2916729156 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
29168 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{s}' has type '{}'", .{
29169 ip.stringToSlice(field_name),
29157 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
29158 field_name.fmt(ip),
2917029159 field_ty.fmt(sema.mod),
2917129160 });
2917229161 }
......@@ -29522,8 +29511,8 @@ fn coerceTupleToStruct(
2952229511 const field = fields.values()[i];
2952329512 const field_src = inst_src; // TODO better source location
2952429513 if (field.default_val == .none) {
29525 const template = "missing struct field: {s}";
29526 const args = .{ip.stringToSlice(field_name)};
29514 const template = "missing struct field: {}";
29515 const args = .{field_name.fmt(ip)};
2952729516 if (root_msg) |msg| {
2952829517 try sema.errNote(block, field_src, msg, template, args);
2952929518 } else {
......@@ -29666,8 +29655,8 @@ fn coerceTupleToTuple(
2966629655 }
2966729656 continue;
2966829657 }
29669 const template = "missing struct field: {s}";
29670 const args = .{ip.stringToSlice(tuple_ty.structFieldName(i, mod))};
29658 const template = "missing struct field: {}";
29659 const args = .{tuple_ty.structFieldName(i, mod).fmt(ip)};
2967129660 if (root_msg) |msg| {
2967229661 try sema.errNote(block, field_src, msg, template, args);
2967329662 } else {
......@@ -30097,7 +30086,7 @@ fn analyzeIsNonErrComptimeOnly(
3009730086 if (err_union.isUndef(mod)) {
3009830087 return sema.addConstUndef(Type.bool);
3009930088 }
30100 if (err_union.getError(mod) == null) {
30089 if (err_union.getErrorName(mod) == .none) {
3010130090 return Air.Inst.Ref.bool_true;
3010230091 } else {
3010330092 return Air.Inst.Ref.bool_false;
......@@ -32824,15 +32813,16 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3282432813 extra_index += 1;
3282532814
3282632815 // This string needs to outlive the ZIR code.
32827 const field_name = try ip.getOrPutString(gpa, if (field_name_zir) |s| s else try std.fmt.allocPrint(sema.arena, "{d}", .{
32828 field_i,
32829 }));
32816 const field_name = try ip.getOrPutString(gpa, if (field_name_zir) |s|
32817 s
32818 else
32819 try std.fmt.allocPrint(sema.arena, "{d}", .{field_i}));
3283032820
3283132821 const gop = struct_obj.fields.getOrPutAssumeCapacity(field_name);
3283232822 if (gop.found_existing) {
3283332823 const msg = msg: {
3283432824 const field_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{ .index = field_i }).lazy;
32835 const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{s}'", .{ip.stringToSlice(field_name)});
32825 const msg = try sema.errMsg(&block_scope, field_src, "duplicate struct field: '{}'", .{field_name.fmt(ip)});
3283632826 errdefer msg.destroy(gpa);
3283732827
3283832828 const prev_field_index = struct_obj.fields.getIndex(field_name).?;
......@@ -33297,8 +33287,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3329733287 if (gop.found_existing) {
3329833288 const msg = msg: {
3329933289 const field_src = mod.fieldSrcLoc(union_obj.owner_decl, .{ .index = field_i }).lazy;
33300 const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{s}'", .{
33301 ip.stringToSlice(field_name),
33290 const msg = try sema.errMsg(&block_scope, field_src, "duplicate union field: '{}'", .{
33291 field_name.fmt(ip),
3330233292 });
3330333293 errdefer msg.destroy(gpa);
3330433294
......@@ -33319,8 +33309,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3331933309 .index = field_i,
3332033310 .range = .type,
3332133311 }).lazy;
33322 const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{s}' in enum '{}'", .{
33323 ip.stringToSlice(field_name), union_obj.tag_ty.fmt(mod),
33312 const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
33313 field_name.fmt(ip), union_obj.tag_ty.fmt(mod),
3332433314 });
3332533315 errdefer msg.destroy(sema.gpa);
3332633316 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
......@@ -33412,8 +33402,8 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3341233402 const enum_ty = union_obj.tag_ty;
3341333403 for (tag_info.names, 0..) |field_name, field_index| {
3341433404 if (explicit_tags_seen[field_index]) continue;
33415 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{s}' missing, declared here", .{
33416 ip.stringToSlice(field_name),
33405 try sema.addFieldErrNote(enum_ty, field_index, msg, "field '{}' missing, declared here", .{
33406 field_name.fmt(ip),
3341733407 });
3341833408 }
3341933409 try sema.addDeclaredHereNote(msg, union_obj.tag_ty);
......@@ -33442,22 +33432,12 @@ fn generateUnionTagTypeNumbered(
3344233432) !Type {
3344333433 const mod = sema.mod;
3344433434 const gpa = sema.gpa;
33445 const ip = &mod.intern_pool;
3344633435
3344733436 const src_decl = mod.declPtr(block.src_decl);
3344833437 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope);
3344933438 errdefer mod.destroyDecl(new_decl_index);
33450 const name = name: {
33451 const prefix = "@typeInfo(";
33452 const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod));
33453 const suffix = ").Union.tag_type.?";
33454 const start = ip.string_bytes.items.len;
33455 try ip.string_bytes.ensureUnusedCapacity(gpa, prefix.len + suffix.len + fqn.len);
33456 ip.string_bytes.appendSliceAssumeCapacity(prefix);
33457 ip.string_bytes.appendSliceAssumeCapacity(fqn);
33458 ip.string_bytes.appendSliceAssumeCapacity(suffix);
33459 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);
33460 };
33439 const fqn = try union_obj.getFullyQualifiedName(mod);
33440 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(&mod.intern_pool)});
3346133441 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
3346233442 .ty = Type.noreturn,
3346333443 .val = Value.@"unreachable",
......@@ -33496,7 +33476,6 @@ fn generateUnionTagTypeSimple(
3349633476) !Type {
3349733477 const mod = sema.mod;
3349833478 const gpa = sema.gpa;
33499 const ip = &mod.intern_pool;
3350033479
3350133480 const new_decl_index = new_decl_index: {
3350233481 const union_obj = maybe_union_obj orelse {
......@@ -33508,17 +33487,8 @@ fn generateUnionTagTypeSimple(
3350833487 const src_decl = mod.declPtr(block.src_decl);
3350933488 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node, block.wip_capture_scope);
3351033489 errdefer mod.destroyDecl(new_decl_index);
33511 const name = name: {
33512 const prefix = "@typeInfo(";
33513 const fqn = ip.stringToSlice(try union_obj.getFullyQualifiedName(mod));
33514 const suffix = ").Union.tag_type.?";
33515 const start = ip.string_bytes.items.len;
33516 try ip.string_bytes.ensureUnusedCapacity(gpa, prefix.len + suffix.len + fqn.len);
33517 ip.string_bytes.appendSliceAssumeCapacity(prefix);
33518 ip.string_bytes.appendSliceAssumeCapacity(fqn);
33519 ip.string_bytes.appendSliceAssumeCapacity(suffix);
33520 break :name try ip.getOrPutTrailingString(gpa, ip.string_bytes.items.len - start);
33521 };
33490 const fqn = try union_obj.getFullyQualifiedName(mod);
33491 const name = try mod.intern_pool.getOrPutStringFmt(gpa, "@typeInfo({}).Union.tag_type.?", .{fqn.fmt(&mod.intern_pool)});
3352233492 try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, block.namespace, .{
3352333493 .ty = Type.noreturn,
3352433494 .val = Value.@"unreachable",
......@@ -34456,8 +34426,8 @@ fn anonStructFieldIndex(
3445634426 },
3445734427 else => unreachable,
3445834428 }
34459 return sema.fail(block, field_src, "no field named '{s}' in anonymous struct '{}'", .{
34460 mod.intern_pool.stringToSlice(field_name), struct_ty.fmt(sema.mod),
34429 return sema.fail(block, field_src, "no field named '{}' in anonymous struct '{}'", .{
34430 field_name.fmt(&mod.intern_pool), struct_ty.fmt(sema.mod),
3446134431 });
3446234432}
3446334433
src/TypedValue.zig+31-35
......@@ -76,6 +76,7 @@ pub fn print(
7676) (@TypeOf(writer).Error || Allocator.Error)!void {
7777 var val = tv.val;
7878 var ty = tv.ty;
79 const ip = &mod.intern_pool;
7980 while (true) switch (val.ip_index) {
8081 .none => switch (val.tag()) {
8182 .aggregate => return printAggregate(ty, val, writer, level, mod),
......@@ -87,7 +88,7 @@ pub fn print(
8788 try writer.writeAll(".{ ");
8889
8990 try print(.{
90 .ty = mod.unionPtr(mod.intern_pool.indexToKey(ty.toIntern()).union_type.index).tag_ty,
91 .ty = mod.unionPtr(ip.indexToKey(ty.toIntern()).union_type.index).tag_ty,
9192 .val = union_val.tag,
9293 }, writer, level - 1, mod);
9394 try writer.writeAll(" = ");
......@@ -174,7 +175,7 @@ pub fn print(
174175 ty = ty.optionalChild(mod);
175176 },
176177 },
177 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
178 else => switch (ip.indexToKey(val.toIntern())) {
178179 .int_type,
179180 .ptr_type,
180181 .array_type,
......@@ -200,11 +201,11 @@ pub fn print(
200201 else => return writer.writeAll(@tagName(simple_value)),
201202 },
202203 .variable => return writer.writeAll("(variable)"),
203 .extern_func => |extern_func| return writer.print("(extern function '{s}')", .{
204 mod.intern_pool.stringToSlice(mod.declPtr(extern_func.decl).name),
204 .extern_func => |extern_func| return writer.print("(extern function '{}')", .{
205 mod.declPtr(extern_func.decl).name.fmt(ip),
205206 }),
206 .func => |func| return writer.print("(function '{s}')", .{
207 mod.intern_pool.stringToSlice(mod.declPtr(mod.funcPtr(func.index).owner_decl).name),
207 .func => |func| return writer.print("(function '{}')", .{
208 mod.declPtr(mod.funcPtr(func.index).owner_decl).name.fmt(ip),
208209 }),
209210 .int => |int| switch (int.storage) {
210211 inline .u64, .i64, .big_int => |x| return writer.print("{}", .{x}),
......@@ -215,29 +216,28 @@ pub fn print(
215216 lazy_ty.toType().abiSize(mod),
216217 }),
217218 },
218 .err => |err| return writer.print("error.{s}", .{
219 mod.intern_pool.stringToSlice(err.name),
219 .err => |err| return writer.print("error.{}", .{
220 err.name.fmt(ip),
220221 }),
221222 .error_union => |error_union| switch (error_union.val) {
222 .err_name => |err_name| return writer.print("error.{s}", .{
223 mod.intern_pool.stringToSlice(err_name),
223 .err_name => |err_name| return writer.print("error.{}", .{
224 err_name.fmt(ip),
224225 }),
225226 .payload => |payload| {
226227 val = payload.toValue();
227228 ty = ty.errorUnionPayload(mod);
228229 },
229230 },
230 .enum_literal => |enum_literal| return writer.print(".{s}", .{
231 mod.intern_pool.stringToSlice(enum_literal),
231 .enum_literal => |enum_literal| return writer.print(".{}", .{
232 enum_literal.fmt(ip),
232233 }),
233234 .enum_tag => |enum_tag| {
234235 if (level == 0) {
235236 return writer.writeAll("(enum)");
236237 }
237 const enum_type = mod.intern_pool.indexToKey(ty.toIntern()).enum_type;
238 if (enum_type.tagValueIndex(&mod.intern_pool, val.toIntern())) |tag_index| {
239 const tag_name = mod.intern_pool.stringToSlice(enum_type.names[tag_index]);
240 try writer.print(".{}", .{std.zig.fmtId(tag_name)});
238 const enum_type = ip.indexToKey(ty.toIntern()).enum_type;
239 if (enum_type.tagValueIndex(ip, val.toIntern())) |tag_index| {
240 try writer.print(".{i}", .{enum_type.names[tag_index].fmt(ip)});
241241 return;
242242 }
243243 try writer.writeAll("@intToEnum(");
......@@ -247,7 +247,7 @@ pub fn print(
247247 }, writer, level - 1, mod);
248248 try writer.writeAll(", ");
249249 try print(.{
250 .ty = mod.intern_pool.typeOf(enum_tag.int).toType(),
250 .ty = ip.typeOf(enum_tag.int).toType(),
251251 .val = enum_tag.int.toValue(),
252252 }, writer, level - 1, mod);
253253 try writer.writeAll(")");
......@@ -259,13 +259,13 @@ pub fn print(
259259 },
260260 .ptr => |ptr| {
261261 if (ptr.addr == .int) {
262 const i = mod.intern_pool.indexToKey(ptr.addr.int).int;
262 const i = ip.indexToKey(ptr.addr.int).int;
263263 switch (i.storage) {
264264 inline else => |addr| return writer.print("{x:0>8}", .{addr}),
265265 }
266266 }
267267
268 const ptr_ty = mod.intern_pool.indexToKey(ty.toIntern()).ptr_type;
268 const ptr_ty = ip.indexToKey(ty.toIntern()).ptr_type;
269269 if (ptr_ty.flags.size == .Slice) {
270270 if (level == 0) {
271271 return writer.writeAll(".{ ... }");
......@@ -301,7 +301,7 @@ pub fn print(
301301 switch (ptr.addr) {
302302 .decl => |decl_index| {
303303 const decl = mod.declPtr(decl_index);
304 if (level == 0) return writer.print("(decl '{s}')", .{mod.intern_pool.stringToSlice(decl.name)});
304 if (level == 0) return writer.print("(decl '{}')", .{decl.name.fmt(ip)});
305305 return print(.{
306306 .ty = decl.ty,
307307 .val = decl.val,
......@@ -309,7 +309,7 @@ pub fn print(
309309 },
310310 .mut_decl => |mut_decl| {
311311 const decl = mod.declPtr(mut_decl.decl);
312 if (level == 0) return writer.print("(mut decl '{s}')", .{mod.intern_pool.stringToSlice(decl.name)});
312 if (level == 0) return writer.print("(mut decl '{}')", .{decl.name.fmt(ip)});
313313 return print(.{
314314 .ty = decl.ty,
315315 .val = decl.val,
......@@ -317,7 +317,7 @@ pub fn print(
317317 },
318318 .comptime_field => |field_val_ip| {
319319 return print(.{
320 .ty = mod.intern_pool.typeOf(field_val_ip).toType(),
320 .ty = ip.typeOf(field_val_ip).toType(),
321321 .val = field_val_ip.toValue(),
322322 }, writer, level - 1, mod);
323323 },
......@@ -325,27 +325,27 @@ pub fn print(
325325 .eu_payload => |eu_ip| {
326326 try writer.writeAll("(payload of ");
327327 try print(.{
328 .ty = mod.intern_pool.typeOf(eu_ip).toType(),
328 .ty = ip.typeOf(eu_ip).toType(),
329329 .val = eu_ip.toValue(),
330330 }, writer, level - 1, mod);
331331 try writer.writeAll(")");
332332 },
333333 .opt_payload => |opt_ip| {
334334 try print(.{
335 .ty = mod.intern_pool.typeOf(opt_ip).toType(),
335 .ty = ip.typeOf(opt_ip).toType(),
336336 .val = opt_ip.toValue(),
337337 }, writer, level - 1, mod);
338338 try writer.writeAll(".?");
339339 },
340340 .elem => |elem| {
341341 try print(.{
342 .ty = mod.intern_pool.typeOf(elem.base).toType(),
342 .ty = ip.typeOf(elem.base).toType(),
343343 .val = elem.base.toValue(),
344344 }, writer, level - 1, mod);
345345 try writer.print("[{}]", .{elem.index});
346346 },
347347 .field => |field| {
348 const container_ty = mod.intern_pool.typeOf(field.base).toType();
348 const container_ty = ip.typeOf(field.base).toType();
349349 try print(.{
350350 .ty = container_ty,
351351 .val = field.base.toValue(),
......@@ -356,14 +356,12 @@ pub fn print(
356356 if (container_ty.isTuple(mod)) {
357357 try writer.print("[{d}]", .{field.index});
358358 }
359 const field_name_ip = container_ty.structFieldName(@intCast(usize, field.index), mod);
360 const field_name = mod.intern_pool.stringToSlice(field_name_ip);
361 try writer.print(".{}", .{std.zig.fmtId(field_name)});
359 const field_name = container_ty.structFieldName(@intCast(usize, field.index), mod);
360 try writer.print(".{i}", .{field_name.fmt(ip)});
362361 },
363362 .Union => {
364 const field_name_ip = container_ty.unionFields(mod).keys()[@intCast(usize, field.index)];
365 const field_name = mod.intern_pool.stringToSlice(field_name_ip);
366 try writer.print(".{}", .{std.zig.fmtId(field_name)});
363 const field_name = container_ty.unionFields(mod).keys()[@intCast(usize, field.index)];
364 try writer.print(".{i}", .{field_name.fmt(ip)});
367365 },
368366 .Pointer => {
369367 std.debug.assert(container_ty.isSlice(mod));
......@@ -440,9 +438,7 @@ fn printAggregate(
440438 else => unreachable,
441439 };
442440
443 if (field_name.unwrap()) |name_ip| try writer.print(".{s} = ", .{
444 mod.intern_pool.stringToSlice(name_ip),
445 });
441 if (field_name.unwrap()) |name| try writer.print(".{} = ", .{name.fmt(&mod.intern_pool)});
446442 try print(.{
447443 .ty = ty.structFieldType(i, mod),
448444 .val = try val.fieldValue(mod, i),
src/codegen/c.zig+4-4
......@@ -1850,9 +1850,9 @@ pub const DeclGen = struct {
18501850 try mod.markDeclAlive(decl);
18511851
18521852 if (mod.decl_exports.get(decl_index)) |exports| {
1853 try writer.writeAll(mod.intern_pool.stringToSlice(exports.items[export_index].name));
1853 try writer.print("{}", .{exports.items[export_index].opts.name.fmt(&mod.intern_pool)});
18541854 } else if (decl.isExtern(mod)) {
1855 try writer.writeAll(mod.intern_pool.stringToSlice(decl.name));
1855 try writer.print("{}", .{decl.name.fmt(&mod.intern_pool)});
18561856 } else {
18571857 // MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
18581858 // expand to 3x the length of its input, but let's cut it off at a much shorter limit.
......@@ -2481,8 +2481,8 @@ fn genExports(o: *Object) !void {
24812481 try fwd_decl_writer.writeAll("zig_export(");
24822482 try o.dg.renderFunctionSignature(fwd_decl_writer, o.dg.decl_index.unwrap().?, .forward, .{ .export_index = @intCast(u32, i) });
24832483 try fwd_decl_writer.print(", {s}, {s});\n", .{
2484 fmtStringLiteral(ip.stringToSlice(exports.items[0].name), null),
2485 fmtStringLiteral(ip.stringToSlice(@"export".name), null),
2484 fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),
2485 fmtStringLiteral(ip.stringToSlice(@"export".opts.name), null),
24862486 });
24872487 }
24882488 }
src/codegen/llvm.zig+18-19
......@@ -687,11 +687,9 @@ pub const Object = struct {
687687 for (export_list.items) |exp| {
688688 // Detect if the LLVM global has already been created as an extern. In such
689689 // case, we need to replace all uses of it with this exported global.
690 // TODO update std.builtin.ExportOptions to have the name be a
691 // null-terminated slice.
692 const exp_name_z = mod.intern_pool.stringToSlice(exp.name);
690 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
693691
694 const other_global = object.getLlvmGlobal(exp_name_z.ptr) orelse continue;
692 const other_global = object.getLlvmGlobal(exp_name.ptr) orelse continue;
695693 if (other_global == llvm_global) continue;
696694
697695 other_global.replaceAllUsesWith(llvm_global);
......@@ -1320,7 +1318,7 @@ pub const Object = struct {
13201318 }
13211319 }
13221320 } else if (exports.len != 0) {
1323 const exp_name = mod.intern_pool.stringToSlice(exports[0].name);
1321 const exp_name = mod.intern_pool.stringToSlice(exports[0].opts.name);
13241322 llvm_global.setValueName2(exp_name.ptr, exp_name.len);
13251323 llvm_global.setUnnamedAddr(.False);
13261324 if (mod.wantDllExports()) llvm_global.setDLLStorageClass(.DLLExport);
......@@ -1335,18 +1333,18 @@ pub const Object = struct {
13351333 di_global.replaceLinkageName(linkage_name);
13361334 }
13371335 }
1338 switch (exports[0].linkage) {
1336 switch (exports[0].opts.linkage) {
13391337 .Internal => unreachable,
13401338 .Strong => llvm_global.setLinkage(.External),
13411339 .Weak => llvm_global.setLinkage(.WeakODR),
13421340 .LinkOnce => llvm_global.setLinkage(.LinkOnceODR),
13431341 }
1344 switch (exports[0].visibility) {
1342 switch (exports[0].opts.visibility) {
13451343 .default => llvm_global.setVisibility(.Default),
13461344 .hidden => llvm_global.setVisibility(.Hidden),
13471345 .protected => llvm_global.setVisibility(.Protected),
13481346 }
1349 if (mod.intern_pool.stringToSliceUnwrap(exports[0].section)) |section| {
1347 if (mod.intern_pool.stringToSliceUnwrap(exports[0].opts.section)) |section| {
13501348 llvm_global.setSection(section);
13511349 }
13521350 if (decl.val.getVariable(mod)) |variable| {
......@@ -1362,7 +1360,7 @@ pub const Object = struct {
13621360 // Until then we iterate over existing aliases and make them point
13631361 // to the correct decl, or otherwise add a new alias. Old aliases are leaked.
13641362 for (exports[1..]) |exp| {
1365 const exp_name_z = mod.intern_pool.stringToSlice(exp.name);
1363 const exp_name_z = mod.intern_pool.stringToSlice(exp.opts.name);
13661364
13671365 if (self.llvm_module.getNamedGlobalAlias(exp_name_z.ptr, exp_name_z.len)) |alias| {
13681366 alias.setAliasee(llvm_global);
......@@ -2539,10 +2537,10 @@ pub const DeclGen = struct {
25392537
25402538 const fn_type = try dg.lowerType(zig_fn_type);
25412539
2542 const fqn = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod));
2540 const fqn = try decl.getFullyQualifiedName(mod);
25432541
25442542 const llvm_addrspace = toLlvmAddressSpace(decl.@"addrspace", target);
2545 const llvm_fn = dg.llvmModule().addFunctionInAddressSpace(fqn, fn_type, llvm_addrspace);
2543 const llvm_fn = dg.llvmModule().addFunctionInAddressSpace(mod.intern_pool.stringToSlice(fqn), fn_type, llvm_addrspace);
25462544 gop.value_ptr.* = llvm_fn;
25472545
25482546 const is_extern = decl.isExtern(mod);
......@@ -2693,7 +2691,7 @@ pub const DeclGen = struct {
26932691
26942692 const mod = dg.module;
26952693 const decl = mod.declPtr(decl_index);
2696 const fqn = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod));
2694 const fqn = try decl.getFullyQualifiedName(mod);
26972695
26982696 const target = mod.getTarget();
26992697
......@@ -2702,7 +2700,7 @@ pub const DeclGen = struct {
27022700
27032701 const llvm_global = dg.object.llvm_module.addGlobalInAddressSpace(
27042702 llvm_type,
2705 fqn,
2703 mod.intern_pool.stringToSlice(fqn),
27062704 llvm_actual_addrspace,
27072705 );
27082706 gop.value_ptr.* = llvm_global;
......@@ -5942,6 +5940,8 @@ pub const FuncGen = struct {
59425940 .base_line = self.base_line,
59435941 });
59445942
5943 const fqn = try decl.getFullyQualifiedName(mod);
5944
59455945 const is_internal_linkage = !mod.decl_exports.contains(decl_index);
59465946 const fn_ty = try mod.funcType(.{
59475947 .param_types = &.{},
......@@ -5959,11 +5959,10 @@ pub const FuncGen = struct {
59595959 .addrspace_is_generic = false,
59605960 });
59615961 const fn_di_ty = try self.dg.object.lowerDebugType(fn_ty, .full);
5962 const fqn = mod.intern_pool.stringToSlice(try decl.getFullyQualifiedName(mod));
59635962 const subprogram = dib.createFunction(
59645963 di_file.toScope(),
59655964 mod.intern_pool.stringToSlice(decl.name),
5966 fqn,
5965 mod.intern_pool.stringToSlice(fqn),
59675966 di_file,
59685967 line_number,
59695968 fn_di_ty,
......@@ -8661,8 +8660,8 @@ pub const FuncGen = struct {
86618660 defer arena_allocator.deinit();
86628661 const arena = arena_allocator.allocator();
86638662
8664 const fqn = mod.intern_pool.stringToSlice(try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod));
8665 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_is_named_enum_value_{s}", .{fqn});
8663 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);
8664 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_is_named_enum_value_{}", .{fqn.fmt(&mod.intern_pool)});
86668665
86678666 const param_types = [_]*llvm.Type{try self.dg.lowerType(enum_type.tag_ty.toType())};
86688667
......@@ -8733,8 +8732,8 @@ pub const FuncGen = struct {
87338732 defer arena_allocator.deinit();
87348733 const arena = arena_allocator.allocator();
87358734
8736 const fqn = mod.intern_pool.stringToSlice(try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod));
8737 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn});
8735 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);
8736 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{}", .{fqn.fmt(&mod.intern_pool)});
87388737
87398738 const slice_ty = Type.slice_const_u8_sentinel_0;
87408739 const llvm_ret_ty = try self.dg.lowerType(slice_ty);
src/link/C.zig+1-1
......@@ -294,7 +294,7 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo
294294 defer export_names.deinit(gpa);
295295 try export_names.ensureTotalCapacity(gpa, @intCast(u32, module.decl_exports.entries.len));
296296 for (module.decl_exports.values()) |exports| for (exports.items) |@"export"|
297 try export_names.put(gpa, @"export".name, {});
297 try export_names.put(gpa, @"export".opts.name, {});
298298
299299 while (f.remaining_decls.popOrNull()) |kv| {
300300 const decl_index = kv.key;
src/link/Coff.zig+12-13
......@@ -1430,20 +1430,20 @@ pub fn updateDeclExports(
14301430 else => std.builtin.CallingConvention.C,
14311431 };
14321432 const decl_cc = exported_decl.ty.fnCallingConvention(mod);
1433 if (decl_cc == .C and ip.stringEqlSlice(exp.name, "main") and
1433 if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and
14341434 self.base.options.link_libc)
14351435 {
14361436 mod.stage1_flags.have_c_main = true;
14371437 } else if (decl_cc == winapi_cc and self.base.options.target.os.tag == .windows) {
1438 if (ip.stringEqlSlice(exp.name, "WinMain")) {
1438 if (ip.stringEqlSlice(exp.opts.name, "WinMain")) {
14391439 mod.stage1_flags.have_winmain = true;
1440 } else if (ip.stringEqlSlice(exp.name, "wWinMain")) {
1440 } else if (ip.stringEqlSlice(exp.opts.name, "wWinMain")) {
14411441 mod.stage1_flags.have_wwinmain = true;
1442 } else if (ip.stringEqlSlice(exp.name, "WinMainCRTStartup")) {
1442 } else if (ip.stringEqlSlice(exp.opts.name, "WinMainCRTStartup")) {
14431443 mod.stage1_flags.have_winmain_crt_startup = true;
1444 } else if (ip.stringEqlSlice(exp.name, "wWinMainCRTStartup")) {
1444 } else if (ip.stringEqlSlice(exp.opts.name, "wWinMainCRTStartup")) {
14451445 mod.stage1_flags.have_wwinmain_crt_startup = true;
1446 } else if (ip.stringEqlSlice(exp.name, "DllMainCRTStartup")) {
1446 } else if (ip.stringEqlSlice(exp.opts.name, "DllMainCRTStartup")) {
14471447 mod.stage1_flags.have_dllmain_crt_startup = true;
14481448 }
14491449 }
......@@ -1461,10 +1461,9 @@ pub fn updateDeclExports(
14611461 const decl_metadata = self.decls.getPtr(decl_index).?;
14621462
14631463 for (exports) |exp| {
1464 const exp_name = mod.intern_pool.stringToSlice(exp.name);
1465 log.debug("adding new export '{s}'", .{exp_name});
1464 log.debug("adding new export '{}'", .{exp.opts.name.fmt(&mod.intern_pool)});
14661465
1467 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {
1466 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section_name| {
14681467 if (!mem.eql(u8, section_name, ".text")) {
14691468 try mod.failed_exports.putNoClobber(
14701469 gpa,
......@@ -1480,7 +1479,7 @@ pub fn updateDeclExports(
14801479 }
14811480 }
14821481
1483 if (exp.linkage == .LinkOnce) {
1482 if (exp.opts.linkage == .LinkOnce) {
14841483 try mod.failed_exports.putNoClobber(
14851484 gpa,
14861485 exp,
......@@ -1494,19 +1493,19 @@ pub fn updateDeclExports(
14941493 continue;
14951494 }
14961495
1497 const sym_index = decl_metadata.getExport(self, exp_name) orelse blk: {
1496 const sym_index = decl_metadata.getExport(self, mod.intern_pool.stringToSlice(exp.opts.name)) orelse blk: {
14981497 const sym_index = try self.allocateSymbol();
14991498 try decl_metadata.exports.append(gpa, sym_index);
15001499 break :blk sym_index;
15011500 };
15021501 const sym_loc = SymbolWithLoc{ .sym_index = sym_index, .file = null };
15031502 const sym = self.getSymbolPtr(sym_loc);
1504 try self.setSymbolName(sym, exp_name);
1503 try self.setSymbolName(sym, mod.intern_pool.stringToSlice(exp.opts.name));
15051504 sym.value = decl_sym.value;
15061505 sym.section_number = @intToEnum(coff.SectionNumber, self.text_section_index.? + 1);
15071506 sym.type = .{ .complex_type = .FUNCTION, .base_type = .NULL };
15081507
1509 switch (exp.linkage) {
1508 switch (exp.opts.linkage) {
15101509 .Strong => {
15111510 sym.storage_class = .EXTERNAL;
15121511 },
src/link/Elf.zig+4-4
......@@ -2879,9 +2879,9 @@ pub fn updateDeclExports(
28792879 try self.global_symbols.ensureUnusedCapacity(gpa, exports.len);
28802880
28812881 for (exports) |exp| {
2882 const exp_name = mod.intern_pool.stringToSlice(exp.name);
2883 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {
2884 if (!mem.eql(u8, section_name, ".text")) {
2882 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
2883 if (exp.opts.section.unwrap()) |section_name| {
2884 if (!mod.intern_pool.stringEqlSlice(section_name, ".text")) {
28852885 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
28862886 mod.failed_exports.putAssumeCapacityNoClobber(
28872887 exp,
......@@ -2890,7 +2890,7 @@ pub fn updateDeclExports(
28902890 continue;
28912891 }
28922892 }
2893 const stb_bits: u8 = switch (exp.linkage) {
2893 const stb_bits: u8 = switch (exp.opts.linkage) {
28942894 .Internal => elf.STB_LOCAL,
28952895 .Strong => blk: {
28962896 const entry_name = self.base.options.entry orelse "_start";
src/link/MachO.zig+6-6
......@@ -2401,15 +2401,15 @@ pub fn updateDeclExports(
24012401 const decl_metadata = self.decls.getPtr(decl_index).?;
24022402
24032403 for (exports) |exp| {
2404 const exp_name = try std.fmt.allocPrint(gpa, "_{s}", .{
2405 mod.intern_pool.stringToSlice(exp.name),
2404 const exp_name = try std.fmt.allocPrint(gpa, "_{}", .{
2405 exp.opts.name.fmt(&mod.intern_pool),
24062406 });
24072407 defer gpa.free(exp_name);
24082408
24092409 log.debug("adding new export '{s}'", .{exp_name});
24102410
2411 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {
2412 if (!mem.eql(u8, section_name, "__text")) {
2411 if (exp.opts.section.unwrap()) |section_name| {
2412 if (!mod.intern_pool.stringEqlSlice(section_name, "__text")) {
24132413 try mod.failed_exports.putNoClobber(
24142414 mod.gpa,
24152415 exp,
......@@ -2424,7 +2424,7 @@ pub fn updateDeclExports(
24242424 }
24252425 }
24262426
2427 if (exp.linkage == .LinkOnce) {
2427 if (exp.opts.linkage == .LinkOnce) {
24282428 try mod.failed_exports.putNoClobber(
24292429 mod.gpa,
24302430 exp,
......@@ -2453,7 +2453,7 @@ pub fn updateDeclExports(
24532453 .n_value = decl_sym.n_value,
24542454 };
24552455
2456 switch (exp.linkage) {
2456 switch (exp.opts.linkage) {
24572457 .Internal => {
24582458 // Symbol should be hidden, or in MachO lingo, private extern.
24592459 // We should also mark the symbol as Weak: n_desc == N_WEAK_DEF.
src/link/Plan9.zig+5-5
......@@ -725,10 +725,10 @@ fn addDeclExports(
725725 const decl_block = self.getDeclBlock(metadata.index);
726726
727727 for (exports) |exp| {
728 const exp_name = mod.intern_pool.stringToSlice(exp.name);
728 const exp_name = mod.intern_pool.stringToSlice(exp.opts.name);
729729 // plan9 does not support custom sections
730 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section_name| {
731 if (!mem.eql(u8, section_name, ".text") or !mem.eql(u8, section_name, ".data")) {
730 if (exp.opts.section.unwrap()) |section_name| {
731 if (!mod.intern_pool.stringEqlSlice(section_name, ".text") and !mod.intern_pool.stringEqlSlice(section_name, ".data")) {
732732 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
733733 self.base.allocator,
734734 mod.declPtr(decl_index).srcLoc(mod),
......@@ -972,7 +972,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
972972 const sym = self.syms.items[decl_block.sym_index.?];
973973 try self.writeSym(writer, sym);
974974 if (self.base.options.module.?.decl_exports.get(decl_index)) |exports| {
975 for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.name))) |exp_i| {
975 for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.opts.name))) |exp_i| {
976976 try self.writeSym(writer, self.syms.items[exp_i]);
977977 };
978978 }
......@@ -998,7 +998,7 @@ pub fn writeSyms(self: *Plan9, buf: *std.ArrayList(u8)) !void {
998998 const sym = self.syms.items[decl_block.sym_index.?];
999999 try self.writeSym(writer, sym);
10001000 if (self.base.options.module.?.decl_exports.get(decl_index)) |exports| {
1001 for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.name))) |exp_i| {
1001 for (exports.items) |e| if (decl_metadata.getExport(self, ip.stringToSlice(e.opts.name))) |exp_i| {
10021002 const s = self.syms.items[exp_i];
10031003 if (mem.eql(u8, s.name, "_start"))
10041004 self.entry_val = s.value;
src/link/SpirV.zig+1-1
......@@ -147,7 +147,7 @@ pub fn updateDeclExports(
147147 const spv_decl_index = entry.value_ptr.*;
148148
149149 for (exports) |exp| {
150 try self.spv.declareEntryPoint(spv_decl_index, mod.intern_pool.stringToSlice(exp.name));
150 try self.spv.declareEntryPoint(spv_decl_index, mod.intern_pool.stringToSlice(exp.opts.name));
151151 }
152152 }
153153
src/link/Wasm.zig+7-7
......@@ -1706,7 +1706,7 @@ pub fn updateDeclExports(
17061706 const gpa = mod.gpa;
17071707
17081708 for (exports) |exp| {
1709 if (mod.intern_pool.stringToSliceUnwrap(exp.section)) |section| {
1709 if (mod.intern_pool.stringToSliceUnwrap(exp.opts.section)) |section| {
17101710 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
17111711 gpa,
17121712 decl.srcLoc(mod),
......@@ -1716,12 +1716,12 @@ pub fn updateDeclExports(
17161716 continue;
17171717 }
17181718
1719 const export_name = try wasm.string_table.put(wasm.base.allocator, mod.intern_pool.stringToSlice(exp.name));
1719 const export_name = try wasm.string_table.put(wasm.base.allocator, mod.intern_pool.stringToSlice(exp.opts.name));
17201720 if (wasm.globals.getPtr(export_name)) |existing_loc| {
17211721 if (existing_loc.index == atom.sym_index) continue;
17221722 const existing_sym: Symbol = existing_loc.getSymbol(wasm).*;
17231723
1724 const exp_is_weak = exp.linkage == .Internal or exp.linkage == .Weak;
1724 const exp_is_weak = exp.opts.linkage == .Internal or exp.opts.linkage == .Weak;
17251725 // When both the to-be-exported symbol and the already existing symbol
17261726 // are strong symbols, we have a linker error.
17271727 // In the other case we replace one with the other.
......@@ -1729,11 +1729,11 @@ pub fn updateDeclExports(
17291729 try mod.failed_exports.put(gpa, exp, try Module.ErrorMsg.create(
17301730 gpa,
17311731 decl.srcLoc(mod),
1732 \\LinkError: symbol '{s}' defined multiple times
1732 \\LinkError: symbol '{}' defined multiple times
17331733 \\ first definition in '{s}'
17341734 \\ next definition in '{s}'
17351735 ,
1736 .{ mod.intern_pool.stringToSlice(exp.name), wasm.name, wasm.name },
1736 .{ exp.opts.name.fmt(&mod.intern_pool), wasm.name, wasm.name },
17371737 ));
17381738 continue;
17391739 } else if (exp_is_weak) {
......@@ -1750,7 +1750,7 @@ pub fn updateDeclExports(
17501750 const exported_atom = wasm.getAtom(exported_atom_index);
17511751 const sym_loc = exported_atom.symbolLoc();
17521752 const symbol = sym_loc.getSymbol(wasm);
1753 switch (exp.linkage) {
1753 switch (exp.opts.linkage) {
17541754 .Internal => {
17551755 symbol.setFlag(.WASM_SYM_VISIBILITY_HIDDEN);
17561756 },
......@@ -1769,7 +1769,7 @@ pub fn updateDeclExports(
17691769 },
17701770 }
17711771 // Ensure the symbol will be exported using the given name
1772 if (!mod.intern_pool.stringEqlSlice(exp.name, sym_loc.getName(wasm))) {
1772 if (!mod.intern_pool.stringEqlSlice(exp.opts.name, sym_loc.getName(wasm))) {
17731773 try wasm.export_names.put(wasm.base.allocator, sym_loc, export_name);
17741774 }
17751775
src/print_air.zig+1-2
......@@ -685,9 +685,8 @@ const Writer = struct {
685685 fn writeDbgInline(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
686686 const ty_fn = w.air.instructions.items(.data)[inst].ty_fn;
687687 const func_index = ty_fn.func;
688 const ip = &w.module.intern_pool;
689688 const owner_decl = w.module.declPtr(w.module.funcPtr(func_index).owner_decl);
690 try s.print("{s}", .{ip.stringToSlice(owner_decl.name)});
689 try s.print("{}", .{owner_decl.name.fmt(&w.module.intern_pool)});
691690 }
692691
693692 fn writeDbgVar(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
src/type.zig+3-5
......@@ -284,7 +284,7 @@ pub const Type = struct {
284284 try writer.writeAll("error{");
285285 for (names, 0..) |name, i| {
286286 if (i != 0) try writer.writeByte(',');
287 try writer.writeAll(mod.intern_pool.stringToSlice(name));
287 try writer.print("{}", .{name.fmt(&mod.intern_pool)});
288288 }
289289 try writer.writeAll("}");
290290 },
......@@ -341,7 +341,7 @@ pub const Type = struct {
341341 try decl.renderFullyQualifiedName(mod, writer);
342342 } else if (struct_type.namespace.unwrap()) |namespace_index| {
343343 const namespace = mod.namespacePtr(namespace_index);
344 try namespace.renderFullyQualifiedName(mod, "", writer);
344 try namespace.renderFullyQualifiedName(mod, .empty, writer);
345345 } else {
346346 try writer.writeAll("@TypeOf(.{})");
347347 }
......@@ -357,9 +357,7 @@ pub const Type = struct {
357357 try writer.writeAll("comptime ");
358358 }
359359 if (anon_struct.names.len != 0) {
360 const name = mod.intern_pool.stringToSlice(anon_struct.names[i]);
361 try writer.writeAll(name);
362 try writer.writeAll(": ");
360 try writer.print("{}: ", .{anon_struct.names[i].fmt(&mod.intern_pool)});
363361 }
364362
365363 try print(field_ty.toType(), writer, mod);
src/value.zig+9-36
......@@ -525,23 +525,6 @@ pub const Value = struct {
525525 };
526526 }
527527
528 pub fn tagName(val: Value, mod: *Module) []const u8 {
529 const ip = &mod.intern_pool;
530 const enum_tag = switch (ip.indexToKey(val.toIntern())) {
531 .un => |un| ip.indexToKey(un.tag).enum_tag,
532 .enum_tag => |x| x,
533 .enum_literal => |name| return ip.stringToSlice(name),
534 else => unreachable,
535 };
536 const enum_type = ip.indexToKey(enum_tag.ty).enum_type;
537 const field_index = field_index: {
538 const field_index = enum_type.tagValueIndex(ip, val.toIntern()).?;
539 break :field_index @intCast(u32, field_index);
540 };
541 const field_name = enum_type.names[field_index];
542 return ip.stringToSlice(field_name);
543 }
544
545528 /// Asserts the value is an integer.
546529 pub fn toBigInt(val: Value, space: *BigIntSpace, mod: *Module) BigIntConst {
547530 return val.toBigIntAdvanced(space, mod, null) catch unreachable;
......@@ -2092,33 +2075,23 @@ pub const Value = struct {
20922075 };
20932076 }
20942077
2095 /// Valid only for error (union) types. Asserts the value is not undefined and not
2096 /// unreachable. For error unions, prefer `errorUnionIsPayload` to find out whether
2097 /// something is an error or not because it works without having to figure out the
2098 /// string.
2099 pub fn getError(val: Value, mod: *const Module) ?[]const u8 {
2100 return switch (getErrorName(val, mod)) {
2101 .empty => null,
2102 else => |s| mod.intern_pool.stringToSlice(s),
2103 };
2104 }
2105
2106 pub fn getErrorName(val: Value, mod: *const Module) InternPool.NullTerminatedString {
2078 /// Valid only for error (union) types. Asserts the value is not undefined and not unreachable.
2079 pub fn getErrorName(val: Value, mod: *const Module) InternPool.OptionalNullTerminatedString {
21072080 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2108 .err => |err| err.name,
2081 .err => |err| err.name.toOptional(),
21092082 .error_union => |error_union| switch (error_union.val) {
2110 .err_name => |err_name| err_name,
2111 .payload => .empty,
2083 .err_name => |err_name| err_name.toOptional(),
2084 .payload => .none,
21122085 },
21132086 else => unreachable,
21142087 };
21152088 }
21162089
21172090 pub fn getErrorInt(val: Value, mod: *const Module) Module.ErrorInt {
2118 return switch (getErrorName(val, mod)) {
2119 .empty => 0,
2120 else => |s| @intCast(Module.ErrorInt, mod.global_error_set.getIndex(s).?),
2121 };
2091 return if (getErrorName(val, mod).unwrap()) |err_name|
2092 @intCast(Module.ErrorInt, mod.global_error_set.getIndex(err_name).?)
2093 else
2094 0;
21222095 }
21232096
21242097 /// Assumes the type is an error union. Returns true if and only if the value is